@builder.io/sdk-react-nextjs 0.4.6-0 → 0.5.1
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/README.md +32 -44
- package/dist/blocks/button/button.d.ts +1 -2
- package/dist/blocks/button/button.js +2 -2
- package/dist/blocks/columns/columns.js +6 -6
- package/dist/blocks/embed/component-info.js +2 -1
- package/dist/blocks/image/component-info.js +2 -1
- package/dist/blocks/image/image.js +8 -7
- package/dist/blocks/img/img.d.ts +1 -2
- package/dist/blocks/section/section.d.ts +1 -2
- package/dist/blocks/symbol/symbol.d.ts +2 -4
- package/dist/blocks/symbol/symbol.helpers.js +2 -1
- package/dist/blocks/symbol/symbol.js +3 -3
- package/dist/blocks/video/video.js +4 -1
- package/dist/components/block/block.helpers.js +5 -3
- package/dist/components/block/block.js +4 -4
- package/dist/components/block/components/block-styles.js +1 -1
- package/dist/components/block/components/block-wrapper.d.ts +1 -2
- package/dist/components/block/components/component-ref/component-ref.helpers.d.ts +1 -1
- package/dist/components/block/components/component-ref/component-ref.helpers.js +2 -1
- package/dist/components/block/components/component-ref/component-ref.js +3 -3
- package/dist/components/block/components/repeated-block.js +1 -1
- package/dist/components/blocks/blocks.d.ts +3 -3
- package/dist/components/blocks/blocks.js +3 -3
- package/dist/components/content/components/enable-editor.js +1 -1
- package/dist/components/content/components/styles.helpers.js +4 -2
- package/dist/components/content/components/styles.js +1 -1
- package/dist/components/content/content.helpers.js +10 -5
- package/dist/components/content/content.js +6 -4
- package/dist/components/content-variants/content-variants.js +3 -3
- package/dist/components/content-variants/helpers.js +2 -1
- package/dist/constants/builder-registered-components.js +11 -11
- package/dist/constants/sdk-version.d.ts +1 -1
- package/dist/constants/sdk-version.js +1 -1
- package/dist/context/components.context.d.ts +3 -0
- package/dist/context/components.context.js +2 -0
- package/dist/functions/evaluate/evaluate.d.ts +10 -0
- package/dist/functions/evaluate/evaluate.js +70 -0
- package/dist/functions/evaluate/index.d.ts +1 -0
- package/dist/functions/evaluate/index.js +1 -0
- package/dist/functions/evaluate/interpreter.d.ts +2 -0
- package/dist/functions/evaluate/interpreter.js +3853 -0
- package/dist/functions/evaluate/non-node-runtime.d.ts +2 -0
- package/dist/functions/evaluate/non-node-runtime.js +84 -0
- package/dist/functions/evaluate/types.d.ts +10 -0
- package/dist/functions/evaluate/types.js +1 -0
- package/dist/functions/extract-text-styles.js +2 -1
- package/dist/functions/get-block-actions-handler.js +1 -1
- package/dist/functions/get-block-component-options.js +4 -2
- package/dist/functions/get-block-properties.js +2 -1
- package/dist/functions/get-content/generate-content-url.js +2 -1
- package/dist/functions/get-content/index.d.ts +1 -5
- package/dist/functions/get-content/index.js +4 -3
- package/dist/functions/get-processed-block.js +7 -4
- package/dist/functions/get-react-native-block-styles.js +1 -0
- package/dist/functions/is-non-node-server.d.ts +4 -0
- package/dist/functions/is-non-node-server.js +8 -0
- package/dist/functions/register-component.js +8 -4
- package/dist/functions/sanitize-react-native-block-styles.js +6 -3
- package/dist/functions/track/helpers.js +2 -1
- package/dist/functions/track/index.js +4 -2
- package/dist/functions/transform-block.js +1 -0
- package/dist/helpers/ab-tests.js +12 -6
- package/dist/helpers/cookie.js +2 -1
- package/dist/helpers/flatten.js +4 -2
- package/dist/helpers/preview-lru-cache/init.d.ts +5 -0
- package/dist/helpers/preview-lru-cache/types.js +5 -0
- package/dist/index-helpers/blocks-exports.d.ts +10 -10
- package/dist/index-helpers/blocks-exports.js +10 -10
- package/dist/scripts/init-editing.js +2 -1
- package/package.json +1 -1
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { BuilderContextInterface, BuilderRenderState } from '../../context/types.js';
|
|
2
|
+
import type { ExecutorArgs } from './types.js';
|
|
3
|
+
export declare function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression }: {
|
|
4
|
+
code: string;
|
|
5
|
+
event?: Event;
|
|
6
|
+
isExpression?: boolean;
|
|
7
|
+
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
|
|
8
|
+
export declare const runInBrowser: ({ useCode, builder, context, event, localState, rootSetState, rootState }: ExecutorArgs) => any;
|
|
9
|
+
export declare const runInNode: (args: ExecutorArgs) => any;
|
|
10
|
+
export declare function flattenState(rootState: Record<string | symbol, any>, localState: Record<string | symbol, any> | undefined, rootSetState: ((rootState: BuilderRenderState) => void) | undefined): BuilderRenderState;
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import { logger } from '../../helpers/logger.js';
|
|
2
|
+
import { isBrowser } from '../is-browser.js';
|
|
3
|
+
import { isEditing } from '../is-editing.js';
|
|
4
|
+
import { isNonNodeServer } from '../is-non-node-server.js';
|
|
5
|
+
import { runInNonNode } from './non-node-runtime.js';
|
|
6
|
+
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
7
|
+
if (code === '') {
|
|
8
|
+
logger.warn('Skipping evaluation of empty code block.');
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
const builder = {
|
|
12
|
+
isEditing: isEditing(),
|
|
13
|
+
isBrowser: isBrowser(),
|
|
14
|
+
isServer: !isBrowser()
|
|
15
|
+
};
|
|
16
|
+
// Be able to handle simple expressions like "state.foo" or "1 + 1"
|
|
17
|
+
// as well as full blocks like "var foo = "bar"; return foo"
|
|
18
|
+
const useReturn =
|
|
19
|
+
// we disable this for cases where we definitely don't want a return
|
|
20
|
+
isExpression && !(code.includes(';') || code.includes(' return ') || code.trim().startsWith('return '));
|
|
21
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
22
|
+
const args = {
|
|
23
|
+
useCode,
|
|
24
|
+
builder,
|
|
25
|
+
context,
|
|
26
|
+
event,
|
|
27
|
+
rootSetState,
|
|
28
|
+
rootState,
|
|
29
|
+
localState
|
|
30
|
+
};
|
|
31
|
+
if (isBrowser())
|
|
32
|
+
return runInBrowser(args);
|
|
33
|
+
if (isNonNodeServer())
|
|
34
|
+
return runInNonNode(args);
|
|
35
|
+
return runInNode(args);
|
|
36
|
+
}
|
|
37
|
+
export const runInBrowser = ({ useCode, builder, context, event, localState, rootSetState, rootState }) => {
|
|
38
|
+
const state = flattenState(rootState, localState, rootSetState);
|
|
39
|
+
try {
|
|
40
|
+
return new Function('builder', 'Builder' /* <- legacy */, 'state', 'context', 'event', useCode)(builder, builder, state, context, event);
|
|
41
|
+
}
|
|
42
|
+
catch (e) {
|
|
43
|
+
logger.warn('Builder custom code error: \n While Evaluating: \n ', useCode, '\n', e);
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
export const runInNode = (args) => {
|
|
47
|
+
// TO-DO: use vm-isolate
|
|
48
|
+
return runInBrowser(args);
|
|
49
|
+
};
|
|
50
|
+
export function flattenState(rootState, localState, rootSetState) {
|
|
51
|
+
if (rootState === localState) {
|
|
52
|
+
throw new Error('rootState === localState');
|
|
53
|
+
}
|
|
54
|
+
return new Proxy(rootState, {
|
|
55
|
+
get: (_, prop) => {
|
|
56
|
+
if (localState && prop in localState) {
|
|
57
|
+
return localState[prop];
|
|
58
|
+
}
|
|
59
|
+
return rootState[prop];
|
|
60
|
+
},
|
|
61
|
+
set: (_, prop, value) => {
|
|
62
|
+
if (localState && prop in localState) {
|
|
63
|
+
throw new Error('Writing to local state is not allowed as it is read-only.');
|
|
64
|
+
}
|
|
65
|
+
rootState[prop] = value;
|
|
66
|
+
rootSetState?.(rootState);
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { evaluate } from './evaluate';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { evaluate } from './evaluate';
|