@builder.io/sdk-svelte 5.2.15 → 5.3.0
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 +4 -0
- package/lib/browser/components/block/block.helpers.d.ts +1 -3
- package/lib/browser/components/block/block.helpers.js +31 -4
- package/lib/browser/components/block/block.svelte +14 -1
- package/lib/browser/components/content/components/styles.helpers.d.ts +1 -1
- package/lib/browser/components/content/components/styles.helpers.js +1 -1
- package/lib/browser/components/content/content.helpers.d.ts +5 -1
- package/lib/browser/components/content/content.helpers.js +39 -2
- package/lib/browser/components/content/content.svelte +4 -17
- package/lib/browser/constants/builder-registered-components.d.ts +1 -0
- package/lib/browser/constants/builder-registered-components.js +40 -33
- package/lib/browser/constants/device-sizes.js +14 -2
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/evaluate/browser-runtime/browser.js +13 -1
- package/lib/browser/functions/evaluate/evaluate.js +21 -5
- package/lib/browser/functions/evaluate/node-runtime/node-runtime.js +114 -23
- package/lib/browser/functions/evaluate/safe-state-expression.d.ts +33 -0
- package/lib/browser/functions/evaluate/safe-state-expression.js +236 -0
- package/lib/browser/functions/evaluate/should-force-browser-runtime-in-node.js +3 -1
- package/lib/browser/functions/extract-localized-values.d.ts +4 -0
- package/lib/browser/functions/extract-localized-values.js +65 -26
- package/lib/browser/functions/get-block-properties.js +2 -1
- package/lib/browser/functions/get-processed-block.d.ts +0 -1
- package/lib/browser/functions/get-processed-block.js +45 -57
- package/lib/browser/functions/is-editing-or-previewing.d.ts +1 -0
- package/lib/browser/functions/is-editing-or-previewing.js +3 -0
- package/lib/browser/functions/set.d.ts +29 -1
- package/lib/browser/functions/set.js +87 -3
- package/lib/browser/helpers/bounded-cache.d.ts +4 -0
- package/lib/browser/helpers/bounded-cache.js +12 -0
- package/lib/browser/helpers/copy-plain-data.d.ts +6 -0
- package/lib/browser/helpers/copy-plain-data.js +40 -0
- package/lib/edge/components/block/block.helpers.d.ts +1 -3
- package/lib/edge/components/block/block.helpers.js +31 -4
- package/lib/edge/components/block/block.svelte +14 -1
- package/lib/edge/components/content/components/styles.helpers.d.ts +1 -1
- package/lib/edge/components/content/components/styles.helpers.js +1 -1
- package/lib/edge/components/content/content.helpers.d.ts +5 -1
- package/lib/edge/components/content/content.helpers.js +39 -2
- package/lib/edge/components/content/content.svelte +4 -17
- package/lib/edge/constants/builder-registered-components.d.ts +1 -0
- package/lib/edge/constants/builder-registered-components.js +40 -33
- package/lib/edge/constants/device-sizes.js +14 -2
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/evaluate/browser-runtime/browser.js +13 -1
- package/lib/edge/functions/evaluate/evaluate.js +21 -5
- package/lib/edge/functions/evaluate/node-runtime/node-runtime.js +114 -23
- package/lib/edge/functions/evaluate/safe-state-expression.d.ts +33 -0
- package/lib/edge/functions/evaluate/safe-state-expression.js +236 -0
- package/lib/edge/functions/evaluate/should-force-browser-runtime-in-node.js +3 -1
- package/lib/edge/functions/extract-localized-values.d.ts +4 -0
- package/lib/edge/functions/extract-localized-values.js +65 -26
- package/lib/edge/functions/get-block-properties.js +2 -1
- package/lib/edge/functions/get-processed-block.d.ts +0 -1
- package/lib/edge/functions/get-processed-block.js +45 -57
- package/lib/edge/functions/is-editing-or-previewing.d.ts +1 -0
- package/lib/edge/functions/is-editing-or-previewing.js +3 -0
- package/lib/edge/functions/set.d.ts +29 -1
- package/lib/edge/functions/set.js +87 -3
- package/lib/edge/helpers/bounded-cache.d.ts +4 -0
- package/lib/edge/helpers/bounded-cache.js +12 -0
- package/lib/edge/helpers/copy-plain-data.d.ts +6 -0
- package/lib/edge/helpers/copy-plain-data.js +40 -0
- package/lib/node/components/block/block.helpers.d.ts +1 -3
- package/lib/node/components/block/block.helpers.js +31 -4
- package/lib/node/components/block/block.svelte +14 -1
- package/lib/node/components/content/components/styles.helpers.d.ts +1 -1
- package/lib/node/components/content/components/styles.helpers.js +1 -1
- package/lib/node/components/content/content.helpers.d.ts +5 -1
- package/lib/node/components/content/content.helpers.js +39 -2
- package/lib/node/components/content/content.svelte +4 -17
- package/lib/node/constants/builder-registered-components.d.ts +1 -0
- package/lib/node/constants/builder-registered-components.js +40 -33
- package/lib/node/constants/device-sizes.js +14 -2
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/evaluate/browser-runtime/browser.js +13 -1
- package/lib/node/functions/evaluate/evaluate.js +21 -5
- package/lib/node/functions/evaluate/node-runtime/node-runtime.js +114 -23
- package/lib/node/functions/evaluate/safe-state-expression.d.ts +33 -0
- package/lib/node/functions/evaluate/safe-state-expression.js +236 -0
- package/lib/node/functions/evaluate/should-force-browser-runtime-in-node.js +3 -1
- package/lib/node/functions/extract-localized-values.d.ts +4 -0
- package/lib/node/functions/extract-localized-values.js +65 -26
- package/lib/node/functions/get-block-properties.js +2 -1
- package/lib/node/functions/get-processed-block.d.ts +0 -1
- package/lib/node/functions/get-processed-block.js +45 -57
- package/lib/node/functions/is-editing-or-previewing.d.ts +1 -0
- package/lib/node/functions/is-editing-or-previewing.js +3 -0
- package/lib/node/functions/set.d.ts +29 -1
- package/lib/node/functions/set.js +87 -3
- package/lib/node/helpers/bounded-cache.d.ts +4 -0
- package/lib/node/helpers/bounded-cache.js +12 -0
- package/lib/node/helpers/copy-plain-data.d.ts +6 -0
- package/lib/node/helpers/copy-plain-data.js +40 -0
- package/package.json +1 -1
- package/src/components/block/block.helpers.ts +38 -5
- package/src/components/block/block.svelte +14 -1
- package/src/components/content/components/styles.helpers.ts +1 -1
- package/src/components/content/content.helpers.ts +45 -4
- package/src/components/content/content.svelte +7 -24
- package/src/constants/builder-registered-components.ts +40 -34
- package/src/constants/device-sizes.ts +14 -3
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/evaluate/browser-runtime/browser.ts +14 -1
- package/src/functions/evaluate/evaluate.ts +22 -5
- package/src/functions/evaluate/node-runtime/node-runtime.ts +116 -25
- package/src/functions/evaluate/safe-state-expression.ts +224 -0
- package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +3 -1
- package/src/functions/extract-localized-values.ts +61 -27
- package/src/functions/get-block-properties.ts +5 -1
- package/src/functions/get-processed-block.ts +46 -57
- package/src/functions/is-editing-or-previewing.ts +3 -0
- package/src/functions/set.ts +91 -3
- package/src/helpers/bounded-cache.ts +12 -0
- package/src/helpers/copy-plain-data.ts +36 -0
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
This is Builder's Svelte SDK.
|
|
4
4
|
|
|
5
|
+
## Minimum supported version
|
|
6
|
+
|
|
7
|
+
The [`peerDependencies`](./package.json) permit **Svelte 4.1.2 through 4.x** (`^4.1.2`, not Svelte 5). This installation range does not establish an actively supported minimum; see the [framework version matrix](../../README.md#framework-version-guidance).
|
|
8
|
+
|
|
5
9
|
## Mitosis
|
|
6
10
|
|
|
7
11
|
This SDK is generated by [Mitosis](https://github.com/BuilderIO/mitosis). To see the Mitosis source-code, go [here](../../).
|
|
@@ -22,9 +22,7 @@ export declare const provideLinkComponent: (block: RegisteredComponent | null |
|
|
|
22
22
|
builderLinkComponent?: undefined;
|
|
23
23
|
};
|
|
24
24
|
export declare const provideRegisteredComponents: (block: RegisteredComponent | null | undefined, registeredComponents: RegisteredComponents, model: string) => {
|
|
25
|
-
builderComponents:
|
|
26
|
-
[k: string]: RegisteredComponent;
|
|
27
|
-
};
|
|
25
|
+
builderComponents: RegisteredComponents;
|
|
28
26
|
} | {
|
|
29
27
|
builderComponents?: undefined;
|
|
30
28
|
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { evaluate } from '../../functions/evaluate/index';
|
|
2
2
|
import { extractTextStyles } from '../../functions/extract-text-styles';
|
|
3
3
|
import { getStyle } from '../../functions/get-style';
|
|
4
|
+
import { isEditingOrPreviewing } from '../../functions/is-editing-or-previewing';
|
|
4
5
|
const checkIsComponentRestricted = (component, model) => {
|
|
5
6
|
if (!component)
|
|
6
7
|
return true;
|
|
@@ -25,12 +26,27 @@ export const getComponent = ({ block, registeredComponents, model }) => {
|
|
|
25
26
|
return ref;
|
|
26
27
|
}
|
|
27
28
|
};
|
|
29
|
+
// Reused per block so repeated items keep a stable block identity across renders.
|
|
30
|
+
const BLOCKS_WITHOUT_REPEAT = new WeakMap();
|
|
31
|
+
const getBlockWithoutRepeat = (block) => {
|
|
32
|
+
if (isEditingOrPreviewing()) {
|
|
33
|
+
const { repeat: _repeat, ...rest } = block;
|
|
34
|
+
return rest;
|
|
35
|
+
}
|
|
36
|
+
let blockWithoutRepeat = BLOCKS_WITHOUT_REPEAT.get(block);
|
|
37
|
+
if (!blockWithoutRepeat) {
|
|
38
|
+
const { repeat: _repeat, ...rest } = block;
|
|
39
|
+
blockWithoutRepeat = rest;
|
|
40
|
+
BLOCKS_WITHOUT_REPEAT.set(block, blockWithoutRepeat);
|
|
41
|
+
}
|
|
42
|
+
return blockWithoutRepeat;
|
|
43
|
+
};
|
|
28
44
|
export const getRepeatItemData = ({ block, context }) => {
|
|
29
45
|
/**
|
|
30
46
|
* we don't use `state.processedBlock` here because the processing done within its logic includes evaluating the block's bindings,
|
|
31
47
|
* which will not work if there is a repeat.
|
|
32
48
|
*/
|
|
33
|
-
const { repeat
|
|
49
|
+
const { repeat } = block;
|
|
34
50
|
if (!repeat?.collection) {
|
|
35
51
|
return undefined;
|
|
36
52
|
}
|
|
@@ -46,6 +62,7 @@ export const getRepeatItemData = ({ block, context }) => {
|
|
|
46
62
|
}
|
|
47
63
|
const collectionName = repeat.collection.split('.').pop();
|
|
48
64
|
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + 'Item' : 'item');
|
|
65
|
+
const blockWithoutRepeat = getBlockWithoutRepeat(block);
|
|
49
66
|
const repeatArray = itemsArray.map((item, index) => ({
|
|
50
67
|
context: {
|
|
51
68
|
...context,
|
|
@@ -78,11 +95,21 @@ export const provideLinkComponent = (block, linkComponent) => {
|
|
|
78
95
|
};
|
|
79
96
|
return {};
|
|
80
97
|
};
|
|
98
|
+
const FILTERED_REGISTERED_COMPONENTS = new WeakMap();
|
|
81
99
|
export const provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
82
100
|
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
101
|
+
let byModel = FILTERED_REGISTERED_COMPONENTS.get(registeredComponents);
|
|
102
|
+
if (!byModel) {
|
|
103
|
+
byModel = new Map();
|
|
104
|
+
FILTERED_REGISTERED_COMPONENTS.set(registeredComponents, byModel);
|
|
105
|
+
}
|
|
106
|
+
let filteredRegisteredComponents = byModel.get(model);
|
|
107
|
+
if (!filteredRegisteredComponents) {
|
|
108
|
+
filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
109
|
+
return !checkIsComponentRestricted(component, model);
|
|
110
|
+
}));
|
|
111
|
+
byModel.set(model, filteredRegisteredComponents);
|
|
112
|
+
}
|
|
86
113
|
return {
|
|
87
114
|
builderComponents: filteredRegisteredComponents
|
|
88
115
|
};
|
|
@@ -73,7 +73,15 @@ $: childrenWithoutParentComponent = () => {
|
|
|
73
73
|
: [];
|
|
74
74
|
};
|
|
75
75
|
$: componentRefProps = () => {
|
|
76
|
-
|
|
76
|
+
const deps = [
|
|
77
|
+
processedBlock(),
|
|
78
|
+
$context,
|
|
79
|
+
$context.rootState,
|
|
80
|
+
$context.localState,
|
|
81
|
+
registeredComponents,
|
|
82
|
+
linkComponent,
|
|
83
|
+
];
|
|
84
|
+
const componentRefProps = {
|
|
77
85
|
blockChildren: processedBlock().children ?? [],
|
|
78
86
|
componentRef: blockComponent?.()?.component,
|
|
79
87
|
componentOptions: {
|
|
@@ -90,11 +98,16 @@ $: componentRefProps = () => {
|
|
|
90
98
|
includeBlockProps: blockComponent?.()?.noWrap === true,
|
|
91
99
|
isInteractive: !(blockComponent?.()?.isRSC && TARGET === "rsc"),
|
|
92
100
|
};
|
|
101
|
+
return componentRefProps;
|
|
93
102
|
};
|
|
94
103
|
let _processedBlock = {
|
|
95
104
|
value: null,
|
|
96
105
|
update: false,
|
|
97
106
|
};
|
|
107
|
+
let _componentRefProps = {
|
|
108
|
+
value: null,
|
|
109
|
+
deps: [],
|
|
110
|
+
};
|
|
98
111
|
onMount(() => {
|
|
99
112
|
const blockId = processedBlock().id;
|
|
100
113
|
const animations = processedBlock().animations;
|
|
@@ -13,5 +13,5 @@ export declare const getCss: ({ cssCode, contentId }: {
|
|
|
13
13
|
cssCode?: string | undefined;
|
|
14
14
|
contentId?: string | undefined;
|
|
15
15
|
}) => string;
|
|
16
|
-
export declare const getDefaultStyles: (isNested: boolean | undefined) => "" | "\n.builder-button {\n all: unset;\n}\n\n.builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {\n margin: 0;\n}\n.builder-text > p, .builder-text > .builder-paragraph {\n color: inherit;\n line-height: inherit;\n letter-spacing: inherit;\n font-weight: inherit;\n font-size: inherit;\n text-align: inherit;\n font-family: inherit;\n}\n";
|
|
16
|
+
export declare const getDefaultStyles: (isNested: boolean | undefined) => "" | "\n:where(.builder-button) {\n all: unset;\n}\n\n.builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {\n margin: 0;\n}\n.builder-text > p, .builder-text > .builder-paragraph {\n color: inherit;\n line-height: inherit;\n letter-spacing: inherit;\n font-weight: inherit;\n font-size: inherit;\n text-align: inherit;\n font-family: inherit;\n}\n";
|
|
17
17
|
export declare const getWrapperClassName: (variationId?: string) => string;
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
import type { RegisteredComponent, RegisteredComponents } from '../../context/types';
|
|
1
2
|
import type { BuilderContent } from '../../types/builder-content';
|
|
2
|
-
import type {
|
|
3
|
+
import type { ComponentInfo } from '../../types/components';
|
|
4
|
+
import type { Dictionary, Nullable } from '../../types/typescript';
|
|
3
5
|
import type { ContentProps } from './content.types';
|
|
6
|
+
export declare const getRegisteredComponents: (registrations: RegisteredComponent[], wrapComponent: (component: any) => any) => RegisteredComponents;
|
|
7
|
+
export declare const getComponentInfos: (registrations: RegisteredComponent[]) => Dictionary<ComponentInfo>;
|
|
4
8
|
export declare const getRootStateInitialValue: ({ content, data, locale }: Pick<ContentProps, 'content' | 'data' | 'locale'>) => {
|
|
5
9
|
locale?: string | undefined;
|
|
6
10
|
};
|
|
@@ -1,10 +1,47 @@
|
|
|
1
|
+
import { serializeIncludingFunctions } from '../../functions/register-component';
|
|
2
|
+
import { copyPlainData } from '../../helpers/copy-plain-data';
|
|
3
|
+
// Registrations are usually module constants, so their derived forms are built once per object.
|
|
4
|
+
const SERIALIZED_COMPONENT_INFOS = new WeakMap();
|
|
5
|
+
const REGISTERED_COMPONENT_ENTRIES = new WeakMap();
|
|
6
|
+
const getSerializedComponentInfo = (registration) => {
|
|
7
|
+
const cached = SERIALIZED_COMPONENT_INFOS.get(registration);
|
|
8
|
+
if (cached)
|
|
9
|
+
return cached;
|
|
10
|
+
const { component: _, ...rest } = registration;
|
|
11
|
+
const info = serializeIncludingFunctions(rest);
|
|
12
|
+
SERIALIZED_COMPONENT_INFOS.set(registration, info);
|
|
13
|
+
return info;
|
|
14
|
+
};
|
|
15
|
+
export const getRegisteredComponents = (registrations, wrapComponent) => {
|
|
16
|
+
const registeredComponents = {};
|
|
17
|
+
for (const registration of registrations) {
|
|
18
|
+
let entry = REGISTERED_COMPONENT_ENTRIES.get(registration);
|
|
19
|
+
if (!entry) {
|
|
20
|
+
entry = {
|
|
21
|
+
component: wrapComponent(registration.component),
|
|
22
|
+
...getSerializedComponentInfo(registration)
|
|
23
|
+
};
|
|
24
|
+
REGISTERED_COMPONENT_ENTRIES.set(registration, entry);
|
|
25
|
+
}
|
|
26
|
+
registeredComponents[registration.name] = entry;
|
|
27
|
+
}
|
|
28
|
+
return registeredComponents;
|
|
29
|
+
};
|
|
30
|
+
export const getComponentInfos = (registrations) => {
|
|
31
|
+
const componentInfos = {};
|
|
32
|
+
for (const registration of registrations) {
|
|
33
|
+
componentInfos[registration.name] = getSerializedComponentInfo(registration);
|
|
34
|
+
}
|
|
35
|
+
return componentInfos;
|
|
36
|
+
};
|
|
1
37
|
export const getRootStateInitialValue = ({ content, data, locale }) => {
|
|
2
38
|
const defaultValues = {};
|
|
3
|
-
const
|
|
39
|
+
const seen = new WeakMap();
|
|
40
|
+
const initialState = copyPlainData(content?.data?.state || {}, seen);
|
|
4
41
|
// set default values for content state inputs
|
|
5
42
|
content?.data?.inputs?.forEach(input => {
|
|
6
43
|
if (input.name && input.defaultValue !== undefined) {
|
|
7
|
-
defaultValues[input.name] = input.defaultValue;
|
|
44
|
+
defaultValues[input.name] = copyPlainData(input.defaultValue, seen);
|
|
8
45
|
}
|
|
9
46
|
});
|
|
10
47
|
return {
|
|
@@ -4,7 +4,6 @@ import { getDefaultRegisteredComponents } from "../../constants/builder-register
|
|
|
4
4
|
import { TARGET } from "../../constants/target";
|
|
5
5
|
import ComponentsContext from "../../context/components.context";
|
|
6
6
|
import { evaluate } from "../../functions/evaluate/evaluate";
|
|
7
|
-
import { serializeIncludingFunctions } from "../../functions/register-component";
|
|
8
7
|
import { logger } from "../../helpers/logger";
|
|
9
8
|
import Blocks from "../blocks/blocks.svelte";
|
|
10
9
|
import { getUpdateVariantVisibilityScript } from "../content-variants/helpers";
|
|
@@ -12,7 +11,7 @@ import "../dynamic-div.svelte";
|
|
|
12
11
|
import InlinedScript from "../inlined-script.svelte";
|
|
13
12
|
import EnableEditor from "./components/enable-editor.svelte";
|
|
14
13
|
import ContentStyles from "./components/styles.svelte";
|
|
15
|
-
import { getContentInitialValue, getRootStateInitialValue, } from "./content.helpers";
|
|
14
|
+
import { getComponentInfos, getContentInitialValue, getRegisteredComponents, getRootStateInitialValue, } from "./content.helpers";
|
|
16
15
|
import "./wrap-component-ref";
|
|
17
16
|
export let content;
|
|
18
17
|
export let data = undefined;
|
|
@@ -45,16 +44,7 @@ let scriptStr = getUpdateVariantVisibilityScript({
|
|
|
45
44
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
46
45
|
contentId: content?.id,
|
|
47
46
|
});
|
|
48
|
-
let registeredComponents = [
|
|
49
|
-
...getDefaultRegisteredComponents(),
|
|
50
|
-
...(customComponents || []),
|
|
51
|
-
].reduce((acc, { component, ...info }) => ({
|
|
52
|
-
...acc,
|
|
53
|
-
[info.name]: {
|
|
54
|
-
component: component,
|
|
55
|
-
...serializeIncludingFunctions(info),
|
|
56
|
-
},
|
|
57
|
-
}), {});
|
|
47
|
+
let registeredComponents = getRegisteredComponents([...getDefaultRegisteredComponents(), ...(customComponents || [])], (component) => component);
|
|
58
48
|
let builderContextSignal = writable({
|
|
59
49
|
content: getContentInitialValue({
|
|
60
50
|
content: content,
|
|
@@ -71,13 +61,10 @@ let builderContextSignal = writable({
|
|
|
71
61
|
canTrack: canTrack,
|
|
72
62
|
apiKey: apiKey,
|
|
73
63
|
apiVersion: apiVersion,
|
|
74
|
-
componentInfos: [
|
|
64
|
+
componentInfos: getComponentInfos([
|
|
75
65
|
...getDefaultRegisteredComponents(),
|
|
76
66
|
...(customComponents || []),
|
|
77
|
-
]
|
|
78
|
-
...acc,
|
|
79
|
-
[info.name]: serializeIncludingFunctions(info),
|
|
80
|
-
}), {}),
|
|
67
|
+
]),
|
|
81
68
|
inheritedStyles: {},
|
|
82
69
|
BlocksWrapper: blocksWrapper || "div",
|
|
83
70
|
BlocksWrapperProps: blocksWrapperProps || {},
|
|
@@ -2,5 +2,6 @@ import type { RegisteredComponent } from '../context/types';
|
|
|
2
2
|
/**
|
|
3
3
|
* Returns a list of all registered components.
|
|
4
4
|
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
5
|
+
* The list is built once, on first use, so its entries keep a stable identity.
|
|
5
6
|
*/
|
|
6
7
|
export declare const getDefaultRegisteredComponents: () => RegisteredComponent[];
|
|
@@ -23,41 +23,48 @@ import { componentInfo as textComponentInfo } from '../blocks/text/component-inf
|
|
|
23
23
|
import { default as Text } from '../blocks/text/index';
|
|
24
24
|
import { getExtraComponents } from './extra-components';
|
|
25
25
|
import { TARGET } from './target';
|
|
26
|
+
let DEFAULT_REGISTERED_COMPONENTS;
|
|
26
27
|
/**
|
|
27
28
|
* Returns a list of all registered components.
|
|
28
29
|
* NOTE: This needs to be a function to work around ESM circular dependencies.
|
|
30
|
+
* The list is built once, on first use, so its entries keep a stable identity.
|
|
29
31
|
*/
|
|
30
|
-
export const getDefaultRegisteredComponents = () =>
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
}, {
|
|
37
|
-
component: Fragment,
|
|
38
|
-
...fragmentComponentInfo
|
|
39
|
-
}, {
|
|
40
|
-
component: Image,
|
|
41
|
-
...imageComponentInfo
|
|
42
|
-
}, {
|
|
43
|
-
component: Section,
|
|
44
|
-
...sectionComponentInfo
|
|
45
|
-
}, {
|
|
46
|
-
component: Slot,
|
|
47
|
-
...slotComponentInfo
|
|
48
|
-
}, {
|
|
49
|
-
component: Symbol,
|
|
50
|
-
...symbolComponentInfo
|
|
51
|
-
}, {
|
|
52
|
-
component: Text,
|
|
53
|
-
...textComponentInfo
|
|
54
|
-
}, ...(SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
|
|
55
|
-
component: PersonalizationContainer,
|
|
56
|
-
...personalizationContainerComponentInfo
|
|
57
|
-
}] : []), ...(TARGET === 'rsc' ? [] : [{
|
|
58
|
-
component: Tabs,
|
|
59
|
-
...tabsComponentInfo
|
|
32
|
+
export const getDefaultRegisteredComponents = () => {
|
|
33
|
+
if (DEFAULT_REGISTERED_COMPONENTS)
|
|
34
|
+
return DEFAULT_REGISTERED_COMPONENTS;
|
|
35
|
+
DEFAULT_REGISTERED_COMPONENTS = [{
|
|
36
|
+
component: Button,
|
|
37
|
+
...buttonComponentInfo
|
|
60
38
|
}, {
|
|
61
|
-
component:
|
|
62
|
-
...
|
|
63
|
-
}
|
|
39
|
+
component: Columns,
|
|
40
|
+
...columnsComponentInfo
|
|
41
|
+
}, {
|
|
42
|
+
component: Fragment,
|
|
43
|
+
...fragmentComponentInfo
|
|
44
|
+
}, {
|
|
45
|
+
component: Image,
|
|
46
|
+
...imageComponentInfo
|
|
47
|
+
}, {
|
|
48
|
+
component: Section,
|
|
49
|
+
...sectionComponentInfo
|
|
50
|
+
}, {
|
|
51
|
+
component: Slot,
|
|
52
|
+
...slotComponentInfo
|
|
53
|
+
}, {
|
|
54
|
+
component: Symbol,
|
|
55
|
+
...symbolComponentInfo
|
|
56
|
+
}, {
|
|
57
|
+
component: Text,
|
|
58
|
+
...textComponentInfo
|
|
59
|
+
}, ...(SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
|
|
60
|
+
component: PersonalizationContainer,
|
|
61
|
+
...personalizationContainerComponentInfo
|
|
62
|
+
}] : []), ...(TARGET === 'rsc' ? [] : [{
|
|
63
|
+
component: Tabs,
|
|
64
|
+
...tabsComponentInfo
|
|
65
|
+
}, {
|
|
66
|
+
component: Accordion,
|
|
67
|
+
...accordionComponentInfo
|
|
68
|
+
}]), ...getExtraComponents()];
|
|
69
|
+
return DEFAULT_REGISTERED_COMPONENTS;
|
|
70
|
+
};
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { fastClone } from '../functions/fast-clone';
|
|
2
1
|
const SIZES = {
|
|
3
2
|
xsmall: {
|
|
4
3
|
min: 0,
|
|
@@ -23,7 +22,20 @@ const SIZES = {
|
|
|
23
22
|
};
|
|
24
23
|
export const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
|
|
25
24
|
export const getSizesForBreakpoints = (breakpoints) => {
|
|
26
|
-
const newSizes =
|
|
25
|
+
const newSizes = {
|
|
26
|
+
xsmall: {
|
|
27
|
+
...SIZES.xsmall
|
|
28
|
+
},
|
|
29
|
+
small: {
|
|
30
|
+
...SIZES.small
|
|
31
|
+
},
|
|
32
|
+
medium: {
|
|
33
|
+
...SIZES.medium
|
|
34
|
+
},
|
|
35
|
+
large: {
|
|
36
|
+
...SIZES.large
|
|
37
|
+
}
|
|
38
|
+
};
|
|
27
39
|
if (!breakpoints) {
|
|
28
40
|
return newSizes;
|
|
29
41
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "5.
|
|
1
|
+
export declare const SDK_VERSION = "5.3.0";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "5.
|
|
1
|
+
export const SDK_VERSION = "5.3.0";
|
|
@@ -1,4 +1,16 @@
|
|
|
1
|
+
import { createBoundedCache } from '../../../helpers/bounded-cache';
|
|
1
2
|
import { flattenState, getFunctionArguments } from '../helpers';
|
|
3
|
+
const MAX_CACHED_FUNCTIONS = 5000;
|
|
4
|
+
const FUNCTION_CACHE = createBoundedCache(MAX_CACHED_FUNCTIONS);
|
|
5
|
+
// `getFunctionArguments` always returns the same argument names, so `code` alone is the key.
|
|
6
|
+
const getCompiledFunction = (argNames, code) => {
|
|
7
|
+
let fn = FUNCTION_CACHE.get(code);
|
|
8
|
+
if (!fn) {
|
|
9
|
+
fn = new Function(...argNames, code);
|
|
10
|
+
FUNCTION_CACHE.set(code, fn);
|
|
11
|
+
}
|
|
12
|
+
return fn;
|
|
13
|
+
};
|
|
2
14
|
export const runInBrowser = ({ code, builder, context, event, localState, rootSetState, rootState }) => {
|
|
3
15
|
const functionArgs = getFunctionArguments({
|
|
4
16
|
builder,
|
|
@@ -10,5 +22,5 @@ export const runInBrowser = ({ code, builder, context, event, localState, rootSe
|
|
|
10
22
|
rootSetState
|
|
11
23
|
})
|
|
12
24
|
});
|
|
13
|
-
return
|
|
25
|
+
return getCompiledFunction(functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
14
26
|
};
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { createBoundedCache } from '../../helpers/bounded-cache';
|
|
1
2
|
import { logger } from '../../helpers/logger';
|
|
2
3
|
import { get } from '../get';
|
|
3
4
|
import { chooseBrowserOrServerEval } from './choose-eval';
|
|
@@ -16,6 +17,24 @@ const VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPa
|
|
|
16
17
|
export const getSimpleExpressionGetPath = (code) => {
|
|
17
18
|
return STATE_GETTER_REGEX.exec(code.trim())?.groups?.getPath?.slice(1) || VIRTUAL_INDEX_REGEX.exec(code.trim())?.groups?.getPath?.slice(1);
|
|
18
19
|
};
|
|
20
|
+
const MAX_CACHED_CODE_STRINGS = 5000;
|
|
21
|
+
const SIMPLE_GET_PATH_CACHE = createBoundedCache(MAX_CACHED_CODE_STRINGS);
|
|
22
|
+
const getCachedSimpleExpressionGetPath = (code) => {
|
|
23
|
+
let getPath = SIMPLE_GET_PATH_CACHE.get(code);
|
|
24
|
+
if (getPath === undefined) {
|
|
25
|
+
getPath = getSimpleExpressionGetPath(code) || null;
|
|
26
|
+
SIMPLE_GET_PATH_CACHE.set(code, getPath);
|
|
27
|
+
}
|
|
28
|
+
return getPath;
|
|
29
|
+
};
|
|
30
|
+
/**
|
|
31
|
+
* Same result as `get({ ...rootState, ...localState }, getPath)`, without copying every state key.
|
|
32
|
+
*/
|
|
33
|
+
const getSimpleStateValue = (rootState, localState, getPath) => {
|
|
34
|
+
const firstKey = getPath.split('.')[0];
|
|
35
|
+
const source = localState && Object.prototype.hasOwnProperty.call(localState, firstKey) ? localState : rootState;
|
|
36
|
+
return get(source, getPath);
|
|
37
|
+
};
|
|
19
38
|
export function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true, trackingContext }) {
|
|
20
39
|
if (code.trim() === '') {
|
|
21
40
|
return undefined;
|
|
@@ -26,12 +45,9 @@ export function evaluate({ code, context, localState, rootState, rootSetState, e
|
|
|
26
45
|
* We try not to take many risks with this optimizations, so we only do it for
|
|
27
46
|
* `state.{path}` expressions.
|
|
28
47
|
*/
|
|
29
|
-
const getPath =
|
|
48
|
+
const getPath = getCachedSimpleExpressionGetPath(code.trim());
|
|
30
49
|
if (getPath) {
|
|
31
|
-
return
|
|
32
|
-
...rootState,
|
|
33
|
-
...localState
|
|
34
|
-
}, getPath);
|
|
50
|
+
return getSimpleStateValue(rootState, localState, getPath);
|
|
35
51
|
}
|
|
36
52
|
const args = {
|
|
37
53
|
code: parseCode(code, {
|