@builder.io/sdk-react-native 1.0.31-0 → 1.0.31
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/commonjs/blocks/symbol/symbol.js +1 -0
- package/lib/browser/commonjs/blocks/symbol/symbol.js.map +1 -1
- package/lib/browser/commonjs/components/content/content.js +1 -0
- package/lib/browser/commonjs/components/content/content.js.map +1 -1
- package/lib/browser/commonjs/constants/sdk-version.js +1 -1
- package/lib/browser/module/blocks/symbol/symbol.js +1 -0
- package/lib/browser/module/blocks/symbol/symbol.js.map +1 -1
- package/lib/browser/module/components/content/content.js +1 -0
- package/lib/browser/module/components/content/content.js.map +1 -1
- package/lib/browser/module/constants/sdk-version.js +1 -1
- package/lib/browser/typescript/blocks/symbol/symbol.d.ts.map +1 -1
- package/lib/browser/typescript/components/content/content.d.ts.map +1 -1
- package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/browser/typescript/context/types.d.ts +1 -0
- package/lib/browser/typescript/context/types.d.ts.map +1 -1
- package/lib/edge/commonjs/blocks/symbol/symbol.js +1 -0
- package/lib/edge/commonjs/blocks/symbol/symbol.js.map +1 -1
- package/lib/edge/commonjs/components/content/content.js +1 -0
- package/lib/edge/commonjs/components/content/content.js.map +1 -1
- package/lib/edge/commonjs/constants/sdk-version.js +1 -1
- package/lib/edge/module/blocks/symbol/symbol.js +1 -0
- package/lib/edge/module/blocks/symbol/symbol.js.map +1 -1
- package/lib/edge/module/components/content/content.js +1 -0
- package/lib/edge/module/components/content/content.js.map +1 -1
- package/lib/edge/module/constants/sdk-version.js +1 -1
- package/lib/edge/typescript/blocks/symbol/symbol.d.ts.map +1 -1
- package/lib/edge/typescript/components/content/content.d.ts.map +1 -1
- package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/edge/typescript/context/types.d.ts +1 -0
- package/lib/edge/typescript/context/types.d.ts.map +1 -1
- package/lib/node/commonjs/blocks/symbol/symbol.js +1 -0
- package/lib/node/commonjs/blocks/symbol/symbol.js.map +1 -1
- package/lib/node/commonjs/components/content/content.js +1 -0
- package/lib/node/commonjs/components/content/content.js.map +1 -1
- package/lib/node/commonjs/constants/sdk-version.js +1 -1
- package/lib/node/module/blocks/symbol/symbol.js +1 -0
- package/lib/node/module/blocks/symbol/symbol.js.map +1 -1
- package/lib/node/module/components/content/content.js +1 -0
- package/lib/node/module/components/content/content.js.map +1 -1
- package/lib/node/module/constants/sdk-version.js +1 -1
- package/lib/node/typescript/blocks/symbol/symbol.d.ts.map +1 -1
- package/lib/node/typescript/components/content/content.d.ts.map +1 -1
- package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/node/typescript/context/types.d.ts +1 -0
- package/lib/node/typescript/context/types.d.ts.map +1 -1
- package/package.json +5 -9
- package/lib/node/index.cjs +0 -6910
- package/lib/node/index.mjs +0 -7477
- package/src/blocks/BaseText.tsx +0 -17
- package/src/blocks/accordion/accordion.tsx +0 -181
- package/src/blocks/accordion/accordion.types.ts +0 -12
- package/src/blocks/accordion/component-info.ts +0 -124
- package/src/blocks/accordion/helpers.ts +0 -3
- package/src/blocks/accordion/index.ts +0 -1
- package/src/blocks/button/button.tsx +0 -56
- package/src/blocks/button/button.types.ts +0 -7
- package/src/blocks/button/component-info.ts +0 -35
- package/src/blocks/button/index.ts +0 -1
- package/src/blocks/columns/columns.tsx +0 -199
- package/src/blocks/columns/columns.types.ts +0 -14
- package/src/blocks/columns/component-info.ts +0 -219
- package/src/blocks/columns/helpers.ts +0 -3
- package/src/blocks/columns/index.ts +0 -1
- package/src/blocks/custom-code/component-info.ts +0 -24
- package/src/blocks/custom-code/custom-code.tsx +0 -71
- package/src/blocks/custom-code/index.ts +0 -1
- package/src/blocks/embed/component-info.ts +0 -38
- package/src/blocks/embed/embed.tsx +0 -62
- package/src/blocks/embed/helpers.ts +0 -2
- package/src/blocks/embed/index.ts +0 -1
- package/src/blocks/form/form/component-info.ts +0 -233
- package/src/blocks/form/form/form.tsx +0 -324
- package/src/blocks/form/form/index.ts +0 -1
- package/src/blocks/form/input/component-info.ts +0 -47
- package/src/blocks/form/input/index.ts +0 -1
- package/src/blocks/form/input/input.tsx +0 -49
- package/src/blocks/form/select/component-info.ts +0 -44
- package/src/blocks/form/select/index.ts +0 -1
- package/src/blocks/form/select/select.tsx +0 -54
- package/src/blocks/form/submit-button/component-info.ts +0 -27
- package/src/blocks/form/submit-button/index.ts +0 -1
- package/src/blocks/form/submit-button/submit-button.tsx +0 -34
- package/src/blocks/fragment/component-info.ts +0 -8
- package/src/blocks/fragment/fragment.tsx +0 -18
- package/src/blocks/fragment/fragment.types.ts +0 -5
- package/src/blocks/fragment/index.ts +0 -1
- package/src/blocks/helpers.ts +0 -43
- package/src/blocks/image/component-info.ts +0 -124
- package/src/blocks/image/image.helpers.ts +0 -47
- package/src/blocks/image/image.tsx +0 -65
- package/src/blocks/image/image.types.ts +0 -19
- package/src/blocks/image/index.ts +0 -1
- package/src/blocks/img/component-info.ts +0 -16
- package/src/blocks/img/img.tsx +0 -55
- package/src/blocks/img/index.ts +0 -1
- package/src/blocks/raw-text/component-info.ts +0 -11
- package/src/blocks/raw-text/index.ts +0 -1
- package/src/blocks/raw-text/raw-text.tsx +0 -1
- package/src/blocks/section/component-info.ts +0 -41
- package/src/blocks/section/index.ts +0 -1
- package/src/blocks/section/section.tsx +0 -39
- package/src/blocks/section/section.types.ts +0 -6
- package/src/blocks/slot/component-info.ts +0 -15
- package/src/blocks/slot/index.ts +0 -1
- package/src/blocks/slot/slot.tsx +0 -42
- package/src/blocks/symbol/component-info.ts +0 -35
- package/src/blocks/symbol/index.ts +0 -1
- package/src/blocks/symbol/symbol.helpers.ts +0 -47
- package/src/blocks/symbol/symbol.tsx +0 -99
- package/src/blocks/symbol/symbol.types.ts +0 -17
- package/src/blocks/tabs/component-info.ts +0 -139
- package/src/blocks/tabs/index.ts +0 -1
- package/src/blocks/tabs/tabs.tsx +0 -79
- package/src/blocks/tabs/tabs.types.ts +0 -13
- package/src/blocks/text/component-info.ts +0 -20
- package/src/blocks/text/index.ts +0 -1
- package/src/blocks/text/text.tsx +0 -105
- package/src/blocks/text/text.types.ts +0 -4
- package/src/blocks/textarea/component-info.ts +0 -38
- package/src/blocks/textarea/index.ts +0 -1
- package/src/blocks/textarea/textarea.tsx +0 -41
- package/src/blocks/video/component-info.ts +0 -83
- package/src/blocks/video/index.ts +0 -1
- package/src/blocks/video/video.tsx +0 -70
- package/src/blocks/video/video.types.ts +0 -21
- package/src/components/block/animator.ts +0 -220
- package/src/components/block/block.helpers.ts +0 -106
- package/src/components/block/block.tsx +0 -235
- package/src/components/block/components/block-styles.tsx +0 -136
- package/src/components/block/components/block-wrapper.tsx +0 -53
- package/src/components/block/components/component-ref/component-ref.helpers.ts +0 -55
- package/src/components/block/components/component-ref/component-ref.tsx +0 -66
- package/src/components/block/components/interactive-element.tsx +0 -53
- package/src/components/block/components/repeated-block.tsx +0 -37
- package/src/components/block/types.ts +0 -6
- package/src/components/blocks/blocks-wrapper.tsx +0 -93
- package/src/components/blocks/blocks.tsx +0 -57
- package/src/components/blocks/blocks.types.ts +0 -7
- package/src/components/blocks/index.ts +0 -1
- package/src/components/content/components/enable-editor.tsx +0 -471
- package/src/components/content/components/styles.helpers.ts +0 -101
- package/src/components/content/components/styles.tsx +0 -42
- package/src/components/content/content.helpers.ts +0 -40
- package/src/components/content/content.tsx +0 -150
- package/src/components/content/content.types.ts +0 -13
- package/src/components/content/contentProps.types.ts +0 -17
- package/src/components/content/index.ts +0 -1
- package/src/components/content/wrap-component-ref.ts +0 -6
- package/src/components/content-variants/content-variants.tsx +0 -146
- package/src/components/content-variants/content-variants.types.ts +0 -84
- package/src/components/content-variants/helpers.ts +0 -72
- package/src/components/content-variants/index.ts +0 -1
- package/src/components/content-variants/inlined-fns.ts +0 -22
- package/src/components/dynamic-div.tsx +0 -30
- package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +0 -7
- package/src/components/dynamic-renderer/dynamic-renderer.tsx +0 -47
- package/src/components/error-boundary.tsx +0 -38
- package/src/components/inlined-script.tsx +0 -10
- package/src/components/inlined-styles.tsx +0 -10
- package/src/constants/builder-registered-components.ts +0 -59
- package/src/constants/device-sizes.ts +0 -59
- package/src/constants/extra-components.ts +0 -1
- package/src/constants/sdk-version.ts +0 -1
- package/src/constants/target.ts +0 -3
- package/src/context/builder.context.ts +0 -15
- package/src/context/components.context.ts +0 -3
- package/src/context/index.ts +0 -1
- package/src/context/types.ts +0 -37
- package/src/functions/apply-patch-with-mutation.ts +0 -61
- package/src/functions/camel-to-kebab-case.ts +0 -1
- package/src/functions/deopt.ts +0 -6
- package/src/functions/evaluate/browser-runtime/browser.ts +0 -61
- package/src/functions/evaluate/browser-runtime/index.ts +0 -1
- package/src/functions/evaluate/choose-eval.ts +0 -23
- package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +0 -2891
- package/src/functions/evaluate/edge-runtime/edge-runtime.ts +0 -96
- package/src/functions/evaluate/edge-runtime/index.ts +0 -1
- package/src/functions/evaluate/evaluate.ts +0 -76
- package/src/functions/evaluate/helpers.ts +0 -56
- package/src/functions/evaluate/index.ts +0 -1
- package/src/functions/evaluate/node-runtime/index.ts +0 -1
- package/src/functions/evaluate/node-runtime/init.ts +0 -33
- package/src/functions/evaluate/node-runtime/node-runtime.ts +0 -176
- package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +0 -24
- package/src/functions/evaluate/placeholder-runtime.ts +0 -4
- package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +0 -16
- package/src/functions/event-handler-name.ts +0 -4
- package/src/functions/extract-text-styles.ts +0 -24
- package/src/functions/fast-clone.ts +0 -4
- package/src/functions/fetch-builder-props.ts +0 -75
- package/src/functions/get-block-actions-handler.ts +0 -17
- package/src/functions/get-block-actions.ts +0 -35
- package/src/functions/get-block-component-options.ts +0 -11
- package/src/functions/get-block-properties.ts +0 -62
- package/src/functions/get-builder-search-params/index.ts +0 -33
- package/src/functions/get-class-prop-name.ts +0 -15
- package/src/functions/get-content/generate-content-url.ts +0 -88
- package/src/functions/get-content/index.ts +0 -99
- package/src/functions/get-content/types.ts +0 -157
- package/src/functions/get-env.ts +0 -5
- package/src/functions/get-fetch.ts +0 -11
- package/src/functions/get-global-this.ts +0 -16
- package/src/functions/get-processed-block.ts +0 -70
- package/src/functions/get-style.ts +0 -38
- package/src/functions/get.ts +0 -4
- package/src/functions/is-browser.ts +0 -3
- package/src/functions/is-edge-runtime.ts +0 -9
- package/src/functions/is-editing.ts +0 -8
- package/src/functions/is-from-trusted-host.ts +0 -8
- package/src/functions/is-iframe.ts +0 -4
- package/src/functions/is-node-runtime.ts +0 -8
- package/src/functions/is-previewing.ts +0 -16
- package/src/functions/on-change.ts +0 -29
- package/src/functions/register-component.ts +0 -30
- package/src/functions/register.ts +0 -44
- package/src/functions/set-editor-settings.ts +0 -15
- package/src/functions/set.ts +0 -14
- package/src/functions/track/helpers.ts +0 -51
- package/src/functions/track/index.ts +0 -131
- package/src/functions/track/interaction.ts +0 -63
- package/src/functions/transform-block-properties.ts +0 -33
- package/src/functions/transform-block.ts +0 -30
- package/src/functions/transform-style-property.ts +0 -296
- package/src/helpers/ab-tests.ts +0 -166
- package/src/helpers/canTrack.ts +0 -2
- package/src/helpers/cookie.ts +0 -97
- package/src/helpers/css.ts +0 -33
- package/src/helpers/flatten.ts +0 -41
- package/src/helpers/localStorage.ts +0 -36
- package/src/helpers/logger.ts +0 -7
- package/src/helpers/nullable.ts +0 -2
- package/src/helpers/omit.ts +0 -7
- package/src/helpers/preview-lru-cache/get.ts +0 -4
- package/src/helpers/preview-lru-cache/helpers.ts +0 -1
- package/src/helpers/preview-lru-cache/init.ts +0 -7
- package/src/helpers/preview-lru-cache/set.ts +0 -12
- package/src/helpers/preview-lru-cache/types.ts +0 -1
- package/src/helpers/search/search.ts +0 -18
- package/src/helpers/sessionId.ts +0 -37
- package/src/helpers/subscribe-to-editor.ts +0 -95
- package/src/helpers/time.ts +0 -2
- package/src/helpers/url.ts +0 -15
- package/src/helpers/uuid.ts +0 -17
- package/src/helpers/visitorId.ts +0 -37
- package/src/index-helpers/blocks-exports.ts +0 -16
- package/src/index-helpers/top-of-file.ts +0 -2
- package/src/index.ts +0 -15
- package/src/scripts/init-editing.ts +0 -119
- package/src/server-index.ts +0 -43
- package/src/types/api-version.ts +0 -2
- package/src/types/builder-block.ts +0 -89
- package/src/types/builder-content.ts +0 -47
- package/src/types/builder-props.ts +0 -12
- package/src/types/can-track.ts +0 -3
- package/src/types/components.ts +0 -119
- package/src/types/deep-partial.ts +0 -1
- package/src/types/element.ts +0 -57
- package/src/types/enforced-partials.ts +0 -19
- package/src/types/input.ts +0 -123
- package/src/types/targets.ts +0 -1
- package/src/types/typescript.ts +0 -9
|
@@ -1,96 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../../helpers/logger';
|
|
2
|
-
import { set } from '../../set';
|
|
3
|
-
import type { ExecutorArgs } from '../helpers';
|
|
4
|
-
import { getFunctionArguments } from '../helpers';
|
|
5
|
-
import Interpreter from './acorn-interpreter';
|
|
6
|
-
const processCode = (code: string) => {
|
|
7
|
-
return code.split('\n').map(line => {
|
|
8
|
-
const trimmed = line.trim();
|
|
9
|
-
|
|
10
|
-
// this async wrapper doesn't work in JS-interpreter, so we drop it.
|
|
11
|
-
if (line.includes('__awaiter')) return undefined;
|
|
12
|
-
|
|
13
|
-
// we find all state setter expressions and append a call to setRootState afterwards
|
|
14
|
-
const isStateSetter = trimmed.startsWith('state.');
|
|
15
|
-
if (!isStateSetter) return line;
|
|
16
|
-
const [lhs, rhs] = trimmed.split('=');
|
|
17
|
-
const setStr = lhs.replace('state.', '').trim();
|
|
18
|
-
const setExpr = `setRootState('${setStr}', ${rhs.trim()})`;
|
|
19
|
-
return `
|
|
20
|
-
${line}
|
|
21
|
-
${setExpr}
|
|
22
|
-
`;
|
|
23
|
-
}).filter(Boolean).join('\n');
|
|
24
|
-
};
|
|
25
|
-
const getJSONValName = (val: string) => val + 'JSON';
|
|
26
|
-
export const runInEdge = ({
|
|
27
|
-
builder,
|
|
28
|
-
context,
|
|
29
|
-
event,
|
|
30
|
-
rootState,
|
|
31
|
-
localState,
|
|
32
|
-
rootSetState,
|
|
33
|
-
code
|
|
34
|
-
}: ExecutorArgs) => {
|
|
35
|
-
const state = {
|
|
36
|
-
...rootState,
|
|
37
|
-
...localState
|
|
38
|
-
};
|
|
39
|
-
const properties = getFunctionArguments({
|
|
40
|
-
builder,
|
|
41
|
-
context,
|
|
42
|
-
event,
|
|
43
|
-
state
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Deserialize all properties from JSON strings to JS objects
|
|
48
|
-
*/
|
|
49
|
-
const prependedCode = properties.map(([key]) => {
|
|
50
|
-
const jsonValName = getJSONValName(key);
|
|
51
|
-
return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
|
|
52
|
-
}).join('\n');
|
|
53
|
-
const cleanedCode = processCode(code);
|
|
54
|
-
if (cleanedCode === '') {
|
|
55
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
56
|
-
return;
|
|
57
|
-
}
|
|
58
|
-
const transformed = `
|
|
59
|
-
function theFunction() {
|
|
60
|
-
${prependedCode}
|
|
61
|
-
|
|
62
|
-
${cleanedCode}
|
|
63
|
-
}
|
|
64
|
-
theFunction();
|
|
65
|
-
`;
|
|
66
|
-
const setRootState = (prop: string, value: any) => {
|
|
67
|
-
const newState = set(state, prop, value);
|
|
68
|
-
rootSetState?.(newState);
|
|
69
|
-
};
|
|
70
|
-
const initFunc = function (interpreter: any, globalObject: any) {
|
|
71
|
-
/**
|
|
72
|
-
* serialize all function args to JSON strings
|
|
73
|
-
*/
|
|
74
|
-
properties.forEach(([key, val]) => {
|
|
75
|
-
const jsonVal = JSON.stringify(val);
|
|
76
|
-
interpreter.setProperty(globalObject, getJSONValName(key), jsonVal);
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* Add a JavaScript function "setRootState" to the interpreter's global object, that will be called whenever a
|
|
81
|
-
* state property is set. This function will update the state object.
|
|
82
|
-
*/
|
|
83
|
-
interpreter.setProperty(globalObject, 'setRootState', interpreter.createNativeFunction(setRootState));
|
|
84
|
-
};
|
|
85
|
-
try {
|
|
86
|
-
const myInterpreter = new Interpreter(transformed, initFunc);
|
|
87
|
-
myInterpreter.run();
|
|
88
|
-
const output = myInterpreter.pseudoToNative(myInterpreter.value);
|
|
89
|
-
return output;
|
|
90
|
-
} catch (e) {
|
|
91
|
-
logger.warn('Custom code error in edge runtime. NOTE: your code must be ES5 JavaScript.', {
|
|
92
|
-
e
|
|
93
|
-
});
|
|
94
|
-
return;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { runInEdge as evaluator } from './edge-runtime'
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../helpers/logger';
|
|
2
|
-
import { chooseBrowserOrServerEval } from './choose-eval';
|
|
3
|
-
import type { EvaluatorArgs, ExecutorArgs } from './helpers';
|
|
4
|
-
import { getBuilderGlobals, parseCode } from './helpers';
|
|
5
|
-
type EvalValue = unknown;
|
|
6
|
-
class EvalCache {
|
|
7
|
-
static cacheLimit = 20;
|
|
8
|
-
static cache = new Map<string, {
|
|
9
|
-
value: EvalValue;
|
|
10
|
-
} | undefined>();
|
|
11
|
-
static getCacheKey(args: ExecutorArgs) {
|
|
12
|
-
return JSON.stringify({
|
|
13
|
-
...args,
|
|
14
|
-
// replace the event with a random number to break cache
|
|
15
|
-
// thats because we can't serialize the event object due to circular refs in DOM node refs.
|
|
16
|
-
event: args.event ? Math.random() : undefined
|
|
17
|
-
});
|
|
18
|
-
}
|
|
19
|
-
static getCachedValue(key: string) {
|
|
20
|
-
const cachedVal = EvalCache.cache.get(key);
|
|
21
|
-
return cachedVal;
|
|
22
|
-
}
|
|
23
|
-
static setCachedValue(key: string, value: EvalValue) {
|
|
24
|
-
if (EvalCache.cache.size > 20) {
|
|
25
|
-
EvalCache.cache.delete(EvalCache.cache.keys().next().value);
|
|
26
|
-
}
|
|
27
|
-
EvalCache.cache.set(key, {
|
|
28
|
-
value
|
|
29
|
-
});
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
export function evaluate({
|
|
33
|
-
code,
|
|
34
|
-
context,
|
|
35
|
-
localState,
|
|
36
|
-
rootState,
|
|
37
|
-
rootSetState,
|
|
38
|
-
event,
|
|
39
|
-
isExpression = true,
|
|
40
|
-
enableCache
|
|
41
|
-
}: EvaluatorArgs): EvalValue {
|
|
42
|
-
if (code === '') {
|
|
43
|
-
return undefined;
|
|
44
|
-
}
|
|
45
|
-
const args: ExecutorArgs = {
|
|
46
|
-
code: parseCode(code, {
|
|
47
|
-
isExpression
|
|
48
|
-
}),
|
|
49
|
-
builder: getBuilderGlobals(),
|
|
50
|
-
context,
|
|
51
|
-
event,
|
|
52
|
-
rootSetState,
|
|
53
|
-
rootState,
|
|
54
|
-
localState
|
|
55
|
-
};
|
|
56
|
-
if (enableCache) {
|
|
57
|
-
const cacheKey = EvalCache.getCacheKey(args);
|
|
58
|
-
const cachedValue = EvalCache.getCachedValue(cacheKey);
|
|
59
|
-
if (cachedValue) {
|
|
60
|
-
return cachedValue.value;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
try {
|
|
64
|
-
const newEval = chooseBrowserOrServerEval(args);
|
|
65
|
-
if (enableCache) {
|
|
66
|
-
const cacheKey = EvalCache.getCacheKey(args);
|
|
67
|
-
EvalCache.setCachedValue(cacheKey, newEval);
|
|
68
|
-
}
|
|
69
|
-
return newEval;
|
|
70
|
-
} catch (e: any) {
|
|
71
|
-
logger.error('Failed code evaluation: ' + e.message, {
|
|
72
|
-
code
|
|
73
|
-
});
|
|
74
|
-
return undefined;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import type { BuilderContextInterface, BuilderRenderState } from '../../context/types';
|
|
2
|
-
import { isBrowser } from '../is-browser';
|
|
3
|
-
import { isEditing } from '../is-editing';
|
|
4
|
-
import { getUserAttributes } from '../track/helpers';
|
|
5
|
-
export type EvaluatorArgs = Omit<ExecutorArgs, 'builder' | 'event'> & {
|
|
6
|
-
event?: Event;
|
|
7
|
-
isExpression?: boolean;
|
|
8
|
-
enableCache: boolean;
|
|
9
|
-
};
|
|
10
|
-
export type BuilderGlobals = {
|
|
11
|
-
isEditing: boolean | undefined;
|
|
12
|
-
isBrowser: boolean | undefined;
|
|
13
|
-
isServer: boolean | undefined;
|
|
14
|
-
getUserAttributes: typeof getUserAttributes;
|
|
15
|
-
};
|
|
16
|
-
export type ExecutorArgs = Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'> & {
|
|
17
|
-
code: string;
|
|
18
|
-
builder: BuilderGlobals;
|
|
19
|
-
event: Event | undefined;
|
|
20
|
-
};
|
|
21
|
-
export type Executor = (args: ExecutorArgs) => any;
|
|
22
|
-
export type FunctionArguments = ReturnType<typeof getFunctionArguments>;
|
|
23
|
-
export const getFunctionArguments = ({
|
|
24
|
-
builder,
|
|
25
|
-
context,
|
|
26
|
-
event,
|
|
27
|
-
state
|
|
28
|
-
}: Pick<ExecutorArgs, 'builder' | 'context' | 'event'> & {
|
|
29
|
-
state: BuilderRenderState;
|
|
30
|
-
}) => {
|
|
31
|
-
return Object.entries({
|
|
32
|
-
state,
|
|
33
|
-
Builder: builder,
|
|
34
|
-
// legacy
|
|
35
|
-
builder,
|
|
36
|
-
context,
|
|
37
|
-
event
|
|
38
|
-
});
|
|
39
|
-
};
|
|
40
|
-
export const getBuilderGlobals = (): BuilderGlobals => ({
|
|
41
|
-
isEditing: isEditing(),
|
|
42
|
-
isBrowser: isBrowser(),
|
|
43
|
-
isServer: !isBrowser(),
|
|
44
|
-
getUserAttributes: () => getUserAttributes()
|
|
45
|
-
});
|
|
46
|
-
export const parseCode = (code: string, {
|
|
47
|
-
isExpression = true
|
|
48
|
-
}: Pick<EvaluatorArgs, 'isExpression'>) => {
|
|
49
|
-
// Be able to handle simple expressions like "state.foo" or "1 + 1"
|
|
50
|
-
// as well as full blocks like "var foo = "bar"; return foo"
|
|
51
|
-
const useReturn =
|
|
52
|
-
// we disable this for cases where we definitely don't want a return
|
|
53
|
-
isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
|
|
54
|
-
const useCode = useReturn ? `return (${code});` : code;
|
|
55
|
-
return useCode;
|
|
56
|
-
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { evaluate } from './evaluate'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export { runInNode as evaluator } from './node-runtime'
|
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file:
|
|
3
|
-
* - imports `isolated-vm`, which can only be made from a file that never runs
|
|
4
|
-
* on the client (e.g. Next's `_document.tsx`)
|
|
5
|
-
* - stores the ivm instance in a global variable using `setIvm`
|
|
6
|
-
*
|
|
7
|
-
* This is needed for when bundlers/meta-frameworks are not able to reliably
|
|
8
|
-
* import the `isolated-vm` package using our `safeDynamicRequire` trick.
|
|
9
|
-
*
|
|
10
|
-
* The `isolated-vm` import must exist in this separate file, or it will end up
|
|
11
|
-
* in the SDK's main entry point, causing errors for users.
|
|
12
|
-
*/
|
|
13
|
-
import ivm from 'isolated-vm';
|
|
14
|
-
import { setIvm } from './node-runtime';
|
|
15
|
-
import type { IsolateOptions } from 'isolated-vm';
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* This function initializes the SDK on a Node server. It handles importing the
|
|
19
|
-
* `isolated-vm` package which is needed for dynamic bindings.
|
|
20
|
-
*
|
|
21
|
-
* NOTE: this function cannot be called on the client. You must call this function
|
|
22
|
-
* from a server-only location, such as:
|
|
23
|
-
* - The NextJS Pages router's `_document.tsx`
|
|
24
|
-
* - Your Remix route's `loader`
|
|
25
|
-
*/
|
|
26
|
-
export const initializeNodeRuntime = (args?: {
|
|
27
|
-
ivmIsolateOptions?: IsolateOptions;
|
|
28
|
-
}) => {
|
|
29
|
-
const {
|
|
30
|
-
ivmIsolateOptions
|
|
31
|
-
} = args || {};
|
|
32
|
-
setIvm(ivm, ivmIsolateOptions);
|
|
33
|
-
}
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import type { Context, IsolateOptions } from 'isolated-vm';
|
|
2
|
-
import { MSG_PREFIX, logger } from '../../../helpers/logger';
|
|
3
|
-
import { fastClone } from '../../fast-clone';
|
|
4
|
-
import { set } from '../../set';
|
|
5
|
-
import type { BuilderGlobals, ExecutorArgs, FunctionArguments } from '../helpers';
|
|
6
|
-
import { getFunctionArguments } from '../helpers';
|
|
7
|
-
import { safeDynamicRequire } from './safeDynamicRequire';
|
|
8
|
-
const getSyncValName = (key: string) => `bldr_${key}_sync`;
|
|
9
|
-
const BUILDER_SET_STATE_NAME = 'BUILDER_SET_STATE';
|
|
10
|
-
const INJECTED_IVM_GLOBAL = 'BUILDER_IVM';
|
|
11
|
-
|
|
12
|
-
// Convert all argument references to proxies, and pass `copySync` method to target object, to return a copy of the original JS object
|
|
13
|
-
// https://github.com/laverdet/isolated-vm#referencecopysync
|
|
14
|
-
const REF_TO_PROXY_FN = `
|
|
15
|
-
var refToProxy = (obj) => {
|
|
16
|
-
if (typeof obj !== 'object' || obj === null) {
|
|
17
|
-
return obj;
|
|
18
|
-
}
|
|
19
|
-
return new Proxy({}, {
|
|
20
|
-
get(target, key) {
|
|
21
|
-
if (key === 'copySync') {
|
|
22
|
-
return () => obj.copySync();
|
|
23
|
-
}
|
|
24
|
-
const val = obj.getSync(key);
|
|
25
|
-
if (typeof val?.getSync === 'function') {
|
|
26
|
-
return refToProxy(val);
|
|
27
|
-
}
|
|
28
|
-
return val;
|
|
29
|
-
},
|
|
30
|
-
set(target, key, value) {
|
|
31
|
-
const v = typeof value === 'object' ? new ${INJECTED_IVM_GLOBAL}.Reference(value) : value;
|
|
32
|
-
obj.setSync(key, v);
|
|
33
|
-
${BUILDER_SET_STATE_NAME}(key, value)
|
|
34
|
-
},
|
|
35
|
-
deleteProperty(target, key) {
|
|
36
|
-
obj.deleteSync(key);
|
|
37
|
-
}
|
|
38
|
-
})
|
|
39
|
-
}
|
|
40
|
-
`;
|
|
41
|
-
const processCode = ({
|
|
42
|
-
code,
|
|
43
|
-
args
|
|
44
|
-
}: {
|
|
45
|
-
code: string;
|
|
46
|
-
args: FunctionArguments;
|
|
47
|
-
}) => {
|
|
48
|
-
const fnArgs = args.map(([name]) => `var ${name} = refToProxy(${getSyncValName(name)}); `).join('');
|
|
49
|
-
|
|
50
|
-
// the output is stringified and parsed back to the parent isolate if needed (when it's an `object`)
|
|
51
|
-
return `
|
|
52
|
-
${REF_TO_PROXY_FN}
|
|
53
|
-
${fnArgs}
|
|
54
|
-
function theFunction() {
|
|
55
|
-
${code}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const output = theFunction()
|
|
59
|
-
|
|
60
|
-
if (typeof output === 'object' && output !== null) {
|
|
61
|
-
return JSON.stringify(output.copySync ? output.copySync() : output);
|
|
62
|
-
} else {
|
|
63
|
-
return output;
|
|
64
|
-
}
|
|
65
|
-
`;
|
|
66
|
-
};
|
|
67
|
-
type IsolatedVMImport = typeof import('isolated-vm');
|
|
68
|
-
let IVM_INSTANCE: IsolatedVMImport | null = null;
|
|
69
|
-
let IVM_CONTEXT: Context | null = null;
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Set the `isolated-vm` instance to be used by the node runtime.
|
|
73
|
-
* This is useful for environments that are not able to rely on our
|
|
74
|
-
* `safeDynamicRequire` trick to import the `isolated-vm` package.
|
|
75
|
-
*/
|
|
76
|
-
export const setIvm = (ivm: IsolatedVMImport, options: IsolateOptions = {}) => {
|
|
77
|
-
IVM_INSTANCE = ivm;
|
|
78
|
-
setIsolateContext(options);
|
|
79
|
-
};
|
|
80
|
-
const getIvm = (): IsolatedVMImport => {
|
|
81
|
-
try {
|
|
82
|
-
if (IVM_INSTANCE) return IVM_INSTANCE;
|
|
83
|
-
const dynRequiredIvm = safeDynamicRequire('isolated-vm');
|
|
84
|
-
if (dynRequiredIvm) return dynRequiredIvm;
|
|
85
|
-
} catch (error) {
|
|
86
|
-
logger.error('isolated-vm import error.', error);
|
|
87
|
-
}
|
|
88
|
-
throw new Error(`${MSG_PREFIX}could not import \`isolated-vm\` module for safe script execution on Node server.
|
|
89
|
-
|
|
90
|
-
In certain Node environments, the SDK requires additional initialization steps. This can be achieved by
|
|
91
|
-
importing and calling \`initializeNodeRuntime()\` from "@builder.io/sdk-react/node/init". This must be done in
|
|
92
|
-
a server-only execution path within your application.
|
|
93
|
-
|
|
94
|
-
Please see the documentation for more information: https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments
|
|
95
|
-
`);
|
|
96
|
-
};
|
|
97
|
-
function setIsolateContext(options: IsolateOptions = {
|
|
98
|
-
memoryLimit: 128
|
|
99
|
-
}) {
|
|
100
|
-
const ivm = getIvm();
|
|
101
|
-
const isolate = new ivm.Isolate(options);
|
|
102
|
-
const context = isolate.createContextSync();
|
|
103
|
-
const jail = context.global;
|
|
104
|
-
|
|
105
|
-
// This makes the global object available in the context as `global`. We use `derefInto()` here
|
|
106
|
-
// because otherwise `global` would actually be a Reference{} object in the new isolate.
|
|
107
|
-
jail.setSync('global', jail.derefInto());
|
|
108
|
-
|
|
109
|
-
// We will create a basic `log` function for the new isolate to use.
|
|
110
|
-
jail.setSync('log', function (...logArgs: any[]) {
|
|
111
|
-
console.log(...logArgs);
|
|
112
|
-
});
|
|
113
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
114
|
-
IVM_CONTEXT = context;
|
|
115
|
-
return context;
|
|
116
|
-
}
|
|
117
|
-
const getIsolateContext = () => {
|
|
118
|
-
if (IVM_CONTEXT) return IVM_CONTEXT;
|
|
119
|
-
const context = setIsolateContext();
|
|
120
|
-
return context;
|
|
121
|
-
};
|
|
122
|
-
export const runInNode = ({
|
|
123
|
-
code,
|
|
124
|
-
builder,
|
|
125
|
-
context,
|
|
126
|
-
event,
|
|
127
|
-
localState,
|
|
128
|
-
rootSetState,
|
|
129
|
-
rootState
|
|
130
|
-
}: ExecutorArgs) => {
|
|
131
|
-
const ivm = getIvm();
|
|
132
|
-
const state = fastClone({
|
|
133
|
-
...rootState,
|
|
134
|
-
...localState
|
|
135
|
-
});
|
|
136
|
-
const args = getFunctionArguments({
|
|
137
|
-
builder,
|
|
138
|
-
context,
|
|
139
|
-
event,
|
|
140
|
-
state
|
|
141
|
-
});
|
|
142
|
-
const isolateContext = getIsolateContext();
|
|
143
|
-
const jail = isolateContext.global;
|
|
144
|
-
|
|
145
|
-
/**
|
|
146
|
-
* Propagate state changes back to the reactive root state.
|
|
147
|
-
*/
|
|
148
|
-
jail.setSync(BUILDER_SET_STATE_NAME, function (key: string, value: any) {
|
|
149
|
-
// mutate the `rootState` object itself. Important for cases where we do not have `rootSetState`
|
|
150
|
-
// like Qwik.
|
|
151
|
-
set(rootState, key, value);
|
|
152
|
-
// call the `rootSetState` function if it exists
|
|
153
|
-
rootSetState?.(rootState);
|
|
154
|
-
});
|
|
155
|
-
args.forEach(([key, arg]) => {
|
|
156
|
-
const val = typeof arg === 'object' ? new ivm.Reference(
|
|
157
|
-
// workaround: methods with default values for arguments is not being cloned over
|
|
158
|
-
key === 'builder' ? {
|
|
159
|
-
...arg,
|
|
160
|
-
getUserAttributes: () => (arg as BuilderGlobals).getUserAttributes()
|
|
161
|
-
} : arg) : null;
|
|
162
|
-
jail.setSync(getSyncValName(key), val);
|
|
163
|
-
});
|
|
164
|
-
const evalStr = processCode({
|
|
165
|
-
code,
|
|
166
|
-
args
|
|
167
|
-
});
|
|
168
|
-
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
169
|
-
try {
|
|
170
|
-
// returning objects throw errors in isolated vm, so we stringify it and parse it back
|
|
171
|
-
const res = JSON.parse(resultStr);
|
|
172
|
-
return res;
|
|
173
|
-
} catch (_error: any) {
|
|
174
|
-
return resultStr;
|
|
175
|
-
}
|
|
176
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const noop = () => {};
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Allows us to require node-specific code safely within bundlers.
|
|
5
|
-
*
|
|
6
|
-
* https://github.com/laverdet/isolated-vm/issues/423
|
|
7
|
-
*
|
|
8
|
-
* NOTE: this code should only ever run in `node`, and never in an `edge` runtime.
|
|
9
|
-
* This is guaranteed by the fact that each SDK has separate bundles for each runtime.
|
|
10
|
-
* However, it might still end up running in the `browser` if the `node` bundle is loaded in the
|
|
11
|
-
* browser (which happens in many apps' dev mode, and certain other scenarios like Qwik's prod mode).
|
|
12
|
-
* This is why we catch and ignore the error at the very end.
|
|
13
|
-
*/
|
|
14
|
-
import { createRequire } from 'node:module';
|
|
15
|
-
export let safeDynamicRequire: typeof require = ((noop as unknown) as typeof require);
|
|
16
|
-
try {
|
|
17
|
-
safeDynamicRequire = createRequire(import.meta.url);
|
|
18
|
-
} catch (error) {
|
|
19
|
-
try {
|
|
20
|
-
safeDynamicRequire = eval('require');
|
|
21
|
-
} catch (error) {
|
|
22
|
-
/* empty */
|
|
23
|
-
}
|
|
24
|
-
}
|
|
@@ -1,4 +0,0 @@
|
|
|
1
|
-
import type { ExecutorArgs } from './helpers';
|
|
2
|
-
export const evaluator = (_args: ExecutorArgs) => {
|
|
3
|
-
throw new Error('Placeholder evaluator not implemented. Make sure the SDK is properly replacing the import to the evaluator with one of edge/node/browser runtime evaluators.');
|
|
4
|
-
}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
import { logger } from '../../helpers/logger';
|
|
2
|
-
import { isNodeRuntime } from '../is-node-runtime';
|
|
3
|
-
export const shouldForceBrowserRuntimeInNode = () => {
|
|
4
|
-
if (!isNodeRuntime()) return false;
|
|
5
|
-
const isArm64 = process.arch === 'arm64';
|
|
6
|
-
const isNode20 = process.version.startsWith('v20');
|
|
7
|
-
const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes('--no-node-snapshot');
|
|
8
|
-
if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
|
|
9
|
-
logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
|
|
10
|
-
If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
|
|
11
|
-
See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
|
|
12
|
-
`);
|
|
13
|
-
return true;
|
|
14
|
-
}
|
|
15
|
-
return false;
|
|
16
|
-
}
|
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
const TEXT_STYLE_KEYS = ['color', 'whiteSpace', 'direction', 'hyphens', 'overflowWrap'];
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* Check if the key represent a CSS style property that applies to text
|
|
5
|
-
* See MDN docs for refrence of what properties apply to text.
|
|
6
|
-
* https://developer.mozilla.org/en-US/docs/Learn/CSS/Styling_text/Fundamentals#summary
|
|
7
|
-
*/
|
|
8
|
-
const isTextStyle = (key: string) => {
|
|
9
|
-
return TEXT_STYLE_KEYS.includes(key) || key.startsWith('font') || key.startsWith('text') || key.startsWith('letter') || key.startsWith('line') || key.startsWith('word') || key.startsWith('writing');
|
|
10
|
-
};
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Extract styles that apply to text from a style object.
|
|
14
|
-
*/
|
|
15
|
-
export const extractTextStyles = (styles: Partial<CSSStyleDeclaration>) => {
|
|
16
|
-
const textStyles: Partial<CSSStyleDeclaration> = {};
|
|
17
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
-
Object.entries(styles).forEach(([key, value]: [any, any]) => {
|
|
19
|
-
if (isTextStyle(key)) {
|
|
20
|
-
textStyles[key] = value;
|
|
21
|
-
}
|
|
22
|
-
});
|
|
23
|
-
return textStyles;
|
|
24
|
-
}
|
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import type { ContentVariantsPrps } from '../components/content-variants/content-variants.types';
|
|
2
|
-
import type { Dictionary } from '../types/typescript';
|
|
3
|
-
import { getBuilderSearchParams } from './get-builder-search-params/index';
|
|
4
|
-
import { fetchOneEntry } from './get-content/index';
|
|
5
|
-
import type { GetContentOptions } from './get-content/types';
|
|
6
|
-
type GetBuilderPropsOptions = (Omit<GetContentOptions, 'model'> & {
|
|
7
|
-
model?: string;
|
|
8
|
-
}) & ({
|
|
9
|
-
/**
|
|
10
|
-
* The current URL path. Used to determine the `urlPath` for targeting content.
|
|
11
|
-
*
|
|
12
|
-
* Cannot be used with `url`.
|
|
13
|
-
*/
|
|
14
|
-
path: string;
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* The current URL search params. Used to parse the `searchParams` for targeting content.
|
|
18
|
-
*
|
|
19
|
-
* Cannot be used with `url`.
|
|
20
|
-
*/
|
|
21
|
-
searchParams?: URLSearchParams | Dictionary<string | string[]>;
|
|
22
|
-
url?: undefined;
|
|
23
|
-
} | {
|
|
24
|
-
/**
|
|
25
|
-
* The current URL. Used to determine the `urlPath` for targeting content and
|
|
26
|
-
* to parse the `searchParams` for targeting content.
|
|
27
|
-
*
|
|
28
|
-
* Cannot be used with `path` or `searchParams`.
|
|
29
|
-
*/
|
|
30
|
-
url: URL;
|
|
31
|
-
path?: undefined;
|
|
32
|
-
searchParams?: undefined;
|
|
33
|
-
} | {
|
|
34
|
-
url?: undefined;
|
|
35
|
-
path?: undefined;
|
|
36
|
-
searchParams?: undefined;
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Given an `apiKey` and `url` (or `path` + `searchParams`), provides all props that `Content` needs to render Builder Content.
|
|
41
|
-
*
|
|
42
|
-
* @example
|
|
43
|
-
* ```jsx
|
|
44
|
-
* const builderProps = await fetchBuilderProps({
|
|
45
|
-
* apiKey: 'API_KEY',
|
|
46
|
-
* // provide `url`
|
|
47
|
-
* url: yourPageUrl,
|
|
48
|
-
* // OR provide `path` + `searchParams`
|
|
49
|
-
* path: yourPath,
|
|
50
|
-
* searchParams: yourSearchParams,
|
|
51
|
-
* });
|
|
52
|
-
*
|
|
53
|
-
* return <Content {...builderProps} />;
|
|
54
|
-
* ```
|
|
55
|
-
*/
|
|
56
|
-
export const fetchBuilderProps = async (_args: GetBuilderPropsOptions): Promise<ContentVariantsPrps> => {
|
|
57
|
-
const urlPath = _args.path || _args.url?.pathname || _args.userAttributes?.urlPath;
|
|
58
|
-
const getContentArgs: GetContentOptions = {
|
|
59
|
-
..._args,
|
|
60
|
-
apiKey: _args.apiKey,
|
|
61
|
-
model: _args.model || 'page',
|
|
62
|
-
userAttributes: {
|
|
63
|
-
..._args.userAttributes,
|
|
64
|
-
...(urlPath ? {
|
|
65
|
-
urlPath
|
|
66
|
-
} : {})
|
|
67
|
-
},
|
|
68
|
-
options: getBuilderSearchParams(_args.searchParams || _args.url?.searchParams || _args.options)
|
|
69
|
-
};
|
|
70
|
-
return {
|
|
71
|
-
apiKey: getContentArgs.apiKey,
|
|
72
|
-
model: getContentArgs.model,
|
|
73
|
-
content: await fetchOneEntry(getContentArgs)
|
|
74
|
-
};
|
|
75
|
-
}
|
|
@@ -1,17 +0,0 @@
|
|
|
1
|
-
import type { BuilderContextInterface } from '../context/types';
|
|
2
|
-
import type { BuilderBlock } from '../types/builder-block';
|
|
3
|
-
import { evaluate } from './evaluate/index';
|
|
4
|
-
type Options = {
|
|
5
|
-
block: BuilderBlock;
|
|
6
|
-
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>;
|
|
7
|
-
type EventHandler = (event: Event) => any;
|
|
8
|
-
export const createEventHandler = (value: string, options: Options): EventHandler => event => evaluate({
|
|
9
|
-
code: value,
|
|
10
|
-
context: options.context,
|
|
11
|
-
localState: options.localState,
|
|
12
|
-
rootState: options.rootState,
|
|
13
|
-
rootSetState: options.rootSetState,
|
|
14
|
-
event,
|
|
15
|
-
isExpression: false,
|
|
16
|
-
enableCache: true
|
|
17
|
-
})
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { TARGET } from '../constants/target';
|
|
2
|
-
import type { BuilderContextInterface } from '../context/types';
|
|
3
|
-
import type { BuilderBlock } from '../types/builder-block';
|
|
4
|
-
import { getEventHandlerName } from './event-handler-name';
|
|
5
|
-
import { createEventHandler } from './get-block-actions-handler';
|
|
6
|
-
type Actions = {
|
|
7
|
-
[index: string]: (event: Event) => any;
|
|
8
|
-
};
|
|
9
|
-
export function getBlockActions(options: {
|
|
10
|
-
block: BuilderBlock;
|
|
11
|
-
stripPrefix?: boolean;
|
|
12
|
-
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): Actions {
|
|
13
|
-
const obj: Actions = {};
|
|
14
|
-
const optionActions = options.block.actions ?? {};
|
|
15
|
-
for (const key in optionActions) {
|
|
16
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
17
|
-
if (!optionActions.hasOwnProperty(key)) {
|
|
18
|
-
continue;
|
|
19
|
-
}
|
|
20
|
-
const value = optionActions[key];
|
|
21
|
-
let eventHandlerName = getEventHandlerName(key);
|
|
22
|
-
if (options.stripPrefix) {
|
|
23
|
-
switch (TARGET) {
|
|
24
|
-
case 'vue':
|
|
25
|
-
eventHandlerName = eventHandlerName.replace('v-on:', '');
|
|
26
|
-
break;
|
|
27
|
-
case 'svelte':
|
|
28
|
-
eventHandlerName = eventHandlerName.replace('on:', '');
|
|
29
|
-
break;
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
obj[eventHandlerName] = createEventHandler(value, options);
|
|
33
|
-
}
|
|
34
|
-
return obj;
|
|
35
|
-
}
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import type { BuilderBlock } from '../types/builder-block';
|
|
2
|
-
export function getBlockComponentOptions(block: BuilderBlock) {
|
|
3
|
-
return {
|
|
4
|
-
...block.component?.options,
|
|
5
|
-
...(block as any).options,
|
|
6
|
-
/**
|
|
7
|
-
* Our built-in components frequently make use of the block, so we provide all of it under `builderBlock`
|
|
8
|
-
*/
|
|
9
|
-
builderBlock: block
|
|
10
|
-
};
|
|
11
|
-
}
|