Add supporting themes required for Lotusdocs
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
import { generateEvaluatorFromFunction, runIfTypeOfFunction } from 'alpinejs/src/evaluator'
|
||||
import { closestDataStack, mergeProxies } from 'alpinejs/src/scope'
|
||||
import { tryCatch } from 'alpinejs/src/utils/error'
|
||||
import { injectMagics } from 'alpinejs/src/magics'
|
||||
|
||||
export function cspEvaluator(el, expression) {
|
||||
let dataStack = generateDataStack(el)
|
||||
|
||||
// Return if the provided expression is already a function...
|
||||
if (typeof expression === 'function') {
|
||||
return generateEvaluatorFromFunction(dataStack, expression)
|
||||
}
|
||||
|
||||
let evaluator = generateEvaluator(el, expression, dataStack)
|
||||
|
||||
return tryCatch.bind(null, el, expression, evaluator)
|
||||
}
|
||||
|
||||
function generateDataStack(el) {
|
||||
let overriddenMagics = {}
|
||||
|
||||
injectMagics(overriddenMagics, el)
|
||||
|
||||
return [overriddenMagics, ...closestDataStack(el)]
|
||||
}
|
||||
|
||||
function generateEvaluator(el, expression, dataStack) {
|
||||
return (receiver = () => {}, { scope = {}, params = [] } = {}) => {
|
||||
let completeScope = mergeProxies([scope, ...dataStack])
|
||||
|
||||
if (completeScope[expression] === undefined) {
|
||||
throwExpressionError(el, expression)
|
||||
}
|
||||
|
||||
runIfTypeOfFunction(receiver, completeScope[expression], completeScope, params)
|
||||
}
|
||||
}
|
||||
|
||||
function throwExpressionError(el, expression) {
|
||||
console.warn(
|
||||
`Alpine Error: Alpine is unable to interpret the following expression using the CSP-friendly build:
|
||||
|
||||
"${expression}"
|
||||
|
||||
Read more about the Alpine's CSP-friendly build restrictions here: https://alpinejs.dev/advanced/csp
|
||||
|
||||
`,
|
||||
el
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
/**
|
||||
* Alpine CSP Build.
|
||||
*
|
||||
* Alpine allows you to use JavaScript directly inside your HTML. This is an
|
||||
* incredibly powerful features. However, it violates the "unsafe-eval"
|
||||
* Content Security Policy. This alternate Alpine build provides a
|
||||
* more constrained API for Alpine that is also CSP-friendly...
|
||||
*/
|
||||
import Alpine from 'alpinejs/src/alpine'
|
||||
|
||||
/**
|
||||
* _______________________________________________________
|
||||
* The Evaluator
|
||||
* -------------------------------------------------------
|
||||
*
|
||||
* By default, Alpine's evaluator "eval"-like utilties to
|
||||
* interpret strings as runtime JS. We're going to use
|
||||
* a more CSP-friendly evaluator for this instead.
|
||||
*/
|
||||
import { cspEvaluator } from './evaluator'
|
||||
|
||||
Alpine.setEvaluator(cspEvaluator)
|
||||
|
||||
/**
|
||||
* The rest of this file bootstraps Alpine the way it is
|
||||
* normally bootstrapped in the default build. We will
|
||||
* set and define it's directives, magics, etc...
|
||||
*/
|
||||
import { reactive, effect, stop, toRaw } from '@vue/reactivity'
|
||||
|
||||
Alpine.setReactivityEngine({ reactive, effect, release: stop, raw: toRaw })
|
||||
|
||||
import 'alpinejs/src/magics/index'
|
||||
|
||||
import 'alpinejs/src/directives/index'
|
||||
|
||||
export default Alpine
|
||||
Reference in New Issue
Block a user