@builder.io/sdk-svelte 3.0.1 → 3.0.2
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/blocks/text/text.svelte +2 -15
- package/lib/browser/blocks/text/text.svelte.d.ts +0 -1
- package/lib/browser/components/block/block.svelte +1 -2
- package/lib/browser/components/content/components/enable-editor.svelte +13 -5
- package/lib/browser/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/functions/evaluate/edge-runtime/edge-runtime.js +1 -4
- package/lib/browser/functions/get-block-component-options.d.ts +2 -1
- package/lib/browser/functions/get-block-component-options.js +18 -2
- package/lib/browser/functions/get-content/generate-content-url.js +28 -3
- package/lib/browser/functions/get-processed-block.d.ts +1 -6
- package/lib/browser/functions/get-processed-block.js +8 -13
- package/lib/browser/helpers/flatten.d.ts +6 -0
- package/lib/browser/helpers/flatten.js +23 -0
- package/lib/browser/server-index.d.ts +1 -1
- package/lib/edge/blocks/text/text.svelte +2 -15
- package/lib/edge/blocks/text/text.svelte.d.ts +0 -1
- package/lib/edge/components/block/block.svelte +1 -2
- package/lib/edge/components/content/components/enable-editor.svelte +13 -5
- package/lib/edge/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/functions/evaluate/edge-runtime/edge-runtime.js +1 -4
- package/lib/edge/functions/get-block-component-options.d.ts +2 -1
- package/lib/edge/functions/get-block-component-options.js +18 -2
- package/lib/edge/functions/get-content/generate-content-url.js +28 -3
- package/lib/edge/functions/get-processed-block.d.ts +1 -6
- package/lib/edge/functions/get-processed-block.js +8 -13
- package/lib/edge/helpers/flatten.d.ts +6 -0
- package/lib/edge/helpers/flatten.js +23 -0
- package/lib/edge/server-index.d.ts +1 -1
- package/lib/node/blocks/text/text.svelte +2 -15
- package/lib/node/blocks/text/text.svelte.d.ts +0 -1
- package/lib/node/components/block/block.svelte +1 -2
- package/lib/node/components/content/components/enable-editor.svelte +13 -5
- package/lib/node/components/content/components/enable-editor.svelte.d.ts +1 -1
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/functions/evaluate/edge-runtime/edge-runtime.js +1 -4
- package/lib/node/functions/get-block-component-options.d.ts +2 -1
- package/lib/node/functions/get-block-component-options.js +18 -2
- package/lib/node/functions/get-content/generate-content-url.js +28 -3
- package/lib/node/functions/get-processed-block.d.ts +1 -6
- package/lib/node/functions/get-processed-block.js +8 -13
- package/lib/node/helpers/flatten.d.ts +6 -0
- package/lib/node/helpers/flatten.js +23 -0
- package/lib/node/server-index.d.ts +1 -1
- package/package.json +1 -1
- package/src/blocks/text/text.svelte +1 -24
- package/src/components/block/block.svelte +1 -2
- package/src/components/content/components/enable-editor.svelte +13 -5
- package/src/constants/sdk-version.ts +1 -1
- package/src/functions/evaluate/edge-runtime/edge-runtime.ts +1 -5
- package/src/functions/get-block-component-options.ts +19 -2
- package/src/functions/get-content/generate-content-url.ts +30 -3
- package/src/functions/get-processed-block.ts +7 -17
- package/src/helpers/flatten.ts +23 -0
- package/src/server-index.ts +1 -1
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
<script>
|
|
2
|
-
export let builderContext;
|
|
3
|
-
export let text = undefined;
|
|
1
|
+
<script>export let text = undefined;
|
|
4
2
|
function stringifyStyles(stylesObj) {
|
|
5
3
|
let styles = "";
|
|
6
4
|
for (let key in stylesObj) {
|
|
@@ -11,17 +9,6 @@ function stringifyStyles(stylesObj) {
|
|
|
11
9
|
}
|
|
12
10
|
return styles;
|
|
13
11
|
}
|
|
14
|
-
$: processedText = () => {
|
|
15
|
-
const context = $builderContext;
|
|
16
|
-
const { context: contextContext, localState, rootState, rootSetState, } = context;
|
|
17
|
-
return String(text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
|
|
18
|
-
code: group,
|
|
19
|
-
context: contextContext,
|
|
20
|
-
localState,
|
|
21
|
-
rootState,
|
|
22
|
-
rootSetState,
|
|
23
|
-
}));
|
|
24
|
-
};
|
|
25
12
|
</script>
|
|
26
13
|
|
|
27
14
|
<div
|
|
@@ -30,5 +17,5 @@ $: processedText = () => {
|
|
|
30
17
|
})}
|
|
31
18
|
class="builder-text"
|
|
32
19
|
>
|
|
33
|
-
{@html
|
|
20
|
+
{@html text?.toString() || ""}
|
|
34
21
|
</div>
|
|
@@ -31,7 +31,6 @@ $: processedBlock = () => {
|
|
|
31
31
|
rootState: $context.rootState,
|
|
32
32
|
rootSetState: $context.rootSetState,
|
|
33
33
|
context: $context.context,
|
|
34
|
-
shouldEvaluateBindings: true,
|
|
35
34
|
});
|
|
36
35
|
return blockToUse;
|
|
37
36
|
};
|
|
@@ -78,7 +77,7 @@ $: componentRefProps = () => {
|
|
|
78
77
|
blockChildren: processedBlock().children ?? [],
|
|
79
78
|
componentRef: blockComponent?.()?.component,
|
|
80
79
|
componentOptions: {
|
|
81
|
-
...getBlockComponentOptions(processedBlock()),
|
|
80
|
+
...getBlockComponentOptions(processedBlock(), $context),
|
|
82
81
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
83
82
|
...provideBuilderContext(blockComponent(), context),
|
|
84
83
|
...provideLinkComponent(blockComponent(), linkComponent),
|
|
@@ -30,10 +30,10 @@ export let enrich = undefined;
|
|
|
30
30
|
export let trustedHosts = undefined;
|
|
31
31
|
export let model = undefined;
|
|
32
32
|
export let content = undefined;
|
|
33
|
+
export let context = undefined;
|
|
33
34
|
export let data = undefined;
|
|
34
35
|
export let showContent;
|
|
35
36
|
export let contentWrapper = undefined;
|
|
36
|
-
export let context = undefined;
|
|
37
37
|
export let contentWrapperProps = undefined;
|
|
38
38
|
function stringifyStyles(stylesObj) {
|
|
39
39
|
let styles = "";
|
|
@@ -212,13 +212,21 @@ function elementRef_onInitpreviewingbldr(event) {
|
|
|
212
212
|
*
|
|
213
213
|
* TO-DO: should we only update the state when there is a change?
|
|
214
214
|
**/
|
|
215
|
-
if (searchParamPreviewModel ===
|
|
216
|
-
|
|
217
|
-
|
|
215
|
+
if (searchParamPreviewModel === "BUILDER_STUDIO" ||
|
|
216
|
+
(searchParamPreviewModel === model &&
|
|
217
|
+
previewApiKey === apiKey &&
|
|
218
|
+
(!content || searchParamPreviewId === content.id))) {
|
|
218
219
|
fetchOneEntry({
|
|
219
|
-
model: model,
|
|
220
|
+
model: model || "",
|
|
220
221
|
apiKey: apiKey,
|
|
221
222
|
apiVersion: $builderContextSignal.apiVersion,
|
|
223
|
+
...(searchParamPreviewModel === "BUILDER_STUDIO" && context?.symbolId
|
|
224
|
+
? {
|
|
225
|
+
query: {
|
|
226
|
+
id: context.symbolId,
|
|
227
|
+
},
|
|
228
|
+
}
|
|
229
|
+
: {}),
|
|
222
230
|
}).then((content) => {
|
|
223
231
|
if (content) {
|
|
224
232
|
mergeNewContent(content);
|
|
@@ -19,10 +19,10 @@ declare const __propDef: {
|
|
|
19
19
|
trustedHosts?: BuilderEditorProps["trustedHosts"];
|
|
20
20
|
model?: BuilderEditorProps["model"];
|
|
21
21
|
content?: BuilderEditorProps["content"];
|
|
22
|
+
context?: BuilderEditorProps["context"];
|
|
22
23
|
data?: BuilderEditorProps["data"];
|
|
23
24
|
showContent: BuilderEditorProps["showContent"];
|
|
24
25
|
contentWrapper?: BuilderEditorProps["contentWrapper"];
|
|
25
|
-
context?: BuilderEditorProps["context"];
|
|
26
26
|
contentWrapperProps?: BuilderEditorProps["contentWrapperProps"];
|
|
27
27
|
};
|
|
28
28
|
events: {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "3.0.
|
|
1
|
+
export declare const SDK_VERSION = "3.0.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "3.0.
|
|
1
|
+
export const SDK_VERSION = "3.0.2";
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '../../../helpers/logger';
|
|
2
1
|
import { flattenState, getFunctionArguments } from '../helpers';
|
|
3
2
|
import Interpreter from './acorn-interpreter';
|
|
4
3
|
/**
|
|
@@ -84,10 +83,8 @@ export const runInEdge = ({ builder, context, event, rootState, localState, root
|
|
|
84
83
|
return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
|
|
85
84
|
}).join('\n');
|
|
86
85
|
const cleanedCode = processCode(code);
|
|
87
|
-
if (cleanedCode === '')
|
|
88
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
86
|
+
if (cleanedCode === '')
|
|
89
87
|
return;
|
|
90
|
-
}
|
|
91
88
|
const transformed = `
|
|
92
89
|
function theFunction() {
|
|
93
90
|
${prependedCode}
|
|
@@ -1,2 +1,3 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../context/types';
|
|
1
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
2
|
-
export declare function getBlockComponentOptions(block: BuilderBlock): any;
|
|
3
|
+
export declare function getBlockComponentOptions(block: BuilderBlock, context: Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): any;
|
|
@@ -1,6 +1,22 @@
|
|
|
1
|
-
|
|
1
|
+
import { evaluate } from './evaluate/evaluate';
|
|
2
|
+
export function getBlockComponentOptions(block, context) {
|
|
2
3
|
return {
|
|
3
4
|
...block.component?.options,
|
|
4
|
-
...block.options
|
|
5
|
+
...block.options,
|
|
6
|
+
...evaluateTextComponentTextOption(block, context)
|
|
5
7
|
};
|
|
6
8
|
}
|
|
9
|
+
const evaluateTextComponentTextOption = (block, context) => {
|
|
10
|
+
if (block.component?.name === 'Text' && block.component.options?.text && typeof block.component.options.text === 'string') {
|
|
11
|
+
return {
|
|
12
|
+
...block.component.options,
|
|
13
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
14
|
+
code: group,
|
|
15
|
+
context,
|
|
16
|
+
localState: context.localState,
|
|
17
|
+
rootState: context.rootState,
|
|
18
|
+
rootSetState: context.rootSetState
|
|
19
|
+
}))
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
};
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { flatten, flattenMongoQuery } from '../../helpers/flatten';
|
|
1
|
+
import { flatten, flattenMongoQuery, unflatten } from '../../helpers/flatten';
|
|
2
2
|
import { normalizeSearchParams } from '../../helpers/search/search';
|
|
3
3
|
import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
|
|
5
|
+
import { isBrowser } from '../is-browser';
|
|
5
6
|
const isPositiveNumber = (thing) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
6
7
|
export const generateContentUrl = (options) => {
|
|
7
8
|
const { limit = 30, userAttributes, query, model, apiKey, enrich, locale, apiVersion = DEFAULT_API_VERSION, fields, omit, offset, cacheSeconds, staleCacheSeconds, sort, includeUnpublished, apiHost } = options;
|
|
@@ -20,7 +21,7 @@ export const generateContentUrl = (options) => {
|
|
|
20
21
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
21
22
|
url.searchParams.set('includeRefs', String(true));
|
|
22
23
|
const finalLocale = locale || userAttributes?.locale;
|
|
23
|
-
let finalUserAttributes = userAttributes;
|
|
24
|
+
let finalUserAttributes = userAttributes || {};
|
|
24
25
|
if (finalLocale) {
|
|
25
26
|
url.searchParams.set('locale', finalLocale);
|
|
26
27
|
finalUserAttributes = {
|
|
@@ -59,11 +60,15 @@ export const generateContentUrl = (options) => {
|
|
|
59
60
|
...getBuilderSearchParamsFromWindow(),
|
|
60
61
|
...normalizeSearchParams(options.options || {})
|
|
61
62
|
};
|
|
63
|
+
finalUserAttributes = {
|
|
64
|
+
...finalUserAttributes,
|
|
65
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
66
|
+
};
|
|
62
67
|
const flattened = flatten(queryOptions);
|
|
63
68
|
for (const key in flattened) {
|
|
64
69
|
url.searchParams.set(key, String(flattened[key]));
|
|
65
70
|
}
|
|
66
|
-
if (finalUserAttributes) {
|
|
71
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
67
72
|
url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
|
|
68
73
|
}
|
|
69
74
|
if (query) {
|
|
@@ -76,3 +81,23 @@ export const generateContentUrl = (options) => {
|
|
|
76
81
|
}
|
|
77
82
|
return url;
|
|
78
83
|
};
|
|
84
|
+
const getUserAttributesFromQueryOptions = (queryOptions) => {
|
|
85
|
+
const newUserAttributes = {};
|
|
86
|
+
for (const key in queryOptions) {
|
|
87
|
+
if (key.startsWith('userAttributes.')) {
|
|
88
|
+
newUserAttributes[key] = queryOptions[key];
|
|
89
|
+
delete queryOptions[key];
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return newUserAttributes;
|
|
93
|
+
};
|
|
94
|
+
const getUserAttributesAsJSON = (queryOptions) => {
|
|
95
|
+
if (isBrowser() && queryOptions['preview'] === 'BUILDER_STUDIO') {
|
|
96
|
+
queryOptions['userAttributes.urlPath'] = window.location.pathname;
|
|
97
|
+
queryOptions['userAttributes.host'] = window.location.host;
|
|
98
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
99
|
+
const { userAttributes } = unflatten(queryOptionsForUserAttributes);
|
|
100
|
+
return userAttributes;
|
|
101
|
+
}
|
|
102
|
+
return {};
|
|
103
|
+
};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface } from '../context/types';
|
|
2
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
3
3
|
export declare function deepCloneWithConditions<T = any>(obj: T): T;
|
|
4
|
-
export declare function getProcessedBlock({ block, context,
|
|
4
|
+
export declare function getProcessedBlock({ block, context, localState, rootState, rootSetState }: {
|
|
5
5
|
block: BuilderBlock;
|
|
6
|
-
/**
|
|
7
|
-
* In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
|
|
8
|
-
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
9
|
-
*/
|
|
10
|
-
shouldEvaluateBindings: boolean;
|
|
11
6
|
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock;
|
|
@@ -72,19 +72,14 @@ const evaluateBindings = ({ block, context, localState, rootState, rootSetState
|
|
|
72
72
|
}
|
|
73
73
|
return copied;
|
|
74
74
|
};
|
|
75
|
-
export function getProcessedBlock({ block, context,
|
|
75
|
+
export function getProcessedBlock({ block, context, localState, rootState, rootSetState }) {
|
|
76
76
|
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
77
77
|
transformedBlock = transformBlock(transformedBlock);
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
}
|
|
87
|
-
else {
|
|
88
|
-
return transformedBlock;
|
|
89
|
-
}
|
|
78
|
+
return evaluateBindings({
|
|
79
|
+
block: transformedBlock,
|
|
80
|
+
localState,
|
|
81
|
+
rootState,
|
|
82
|
+
rootSetState,
|
|
83
|
+
context
|
|
84
|
+
});
|
|
90
85
|
}
|
|
@@ -14,3 +14,9 @@ export declare function flatten<T extends Record<string, any>>(object: T, path?:
|
|
|
14
14
|
export declare function flattenMongoQuery(obj: any, _current?: any, _res?: any): {
|
|
15
15
|
[key: string]: string;
|
|
16
16
|
};
|
|
17
|
+
/**
|
|
18
|
+
* Unflatten a flat object with dot-separated keys back into a nested object.
|
|
19
|
+
*
|
|
20
|
+
* { 'foo.bar': 'baz' } -> { foo: { bar: 'baz' }}
|
|
21
|
+
*/
|
|
22
|
+
export declare function unflatten(obj: any): any;
|
|
@@ -37,3 +37,26 @@ export function flattenMongoQuery(obj, _current, _res = {}) {
|
|
|
37
37
|
}
|
|
38
38
|
return _res;
|
|
39
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Unflatten a flat object with dot-separated keys back into a nested object.
|
|
42
|
+
*
|
|
43
|
+
* { 'foo.bar': 'baz' } -> { foo: { bar: 'baz' }}
|
|
44
|
+
*/
|
|
45
|
+
export function unflatten(obj) {
|
|
46
|
+
const result = {};
|
|
47
|
+
for (const key in obj) {
|
|
48
|
+
const parts = key.split('.');
|
|
49
|
+
let current = result;
|
|
50
|
+
for (let i = 0; i < parts.length; i++) {
|
|
51
|
+
const part = parts[i];
|
|
52
|
+
if (i === parts.length - 1) {
|
|
53
|
+
current[part] = obj[key];
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
current[part] = current[part] || {};
|
|
57
|
+
current = current[part];
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
return result;
|
|
62
|
+
}
|
|
@@ -15,7 +15,7 @@ export type { ContentVariantsPrps as ContentProps } from './components/content-v
|
|
|
15
15
|
/**
|
|
16
16
|
* General Builder types
|
|
17
17
|
*/
|
|
18
|
-
export type { RegisteredComponent } from './context/types';
|
|
18
|
+
export type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from './context/types';
|
|
19
19
|
export type { BuilderBlock } from './types/builder-block';
|
|
20
20
|
export type { BuilderContent } from './types/builder-content';
|
|
21
21
|
export type { ComponentInfo } from './types/components';
|
package/package.json
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
<script lang="ts">
|
|
2
|
-
import { evaluate } from "../../functions/evaluate/index";
|
|
3
2
|
import type { TextProps } from "./text.types";
|
|
4
3
|
|
|
5
|
-
export let builderContext: TextProps["builderContext"];
|
|
6
4
|
export let text: TextProps["text"] = undefined;
|
|
7
5
|
function stringifyStyles(stylesObj) {
|
|
8
6
|
let styles = "";
|
|
@@ -14,27 +12,6 @@
|
|
|
14
12
|
}
|
|
15
13
|
return styles;
|
|
16
14
|
}
|
|
17
|
-
|
|
18
|
-
$: processedText = () => {
|
|
19
|
-
const context = $builderContext;
|
|
20
|
-
const {
|
|
21
|
-
context: contextContext,
|
|
22
|
-
localState,
|
|
23
|
-
rootState,
|
|
24
|
-
rootSetState,
|
|
25
|
-
} = context;
|
|
26
|
-
return String(text?.toString() || "").replace(
|
|
27
|
-
/{{([^}]+)}}/g,
|
|
28
|
-
(match, group) =>
|
|
29
|
-
evaluate({
|
|
30
|
-
code: group,
|
|
31
|
-
context: contextContext,
|
|
32
|
-
localState,
|
|
33
|
-
rootState,
|
|
34
|
-
rootSetState,
|
|
35
|
-
}) as string
|
|
36
|
-
);
|
|
37
|
-
};
|
|
38
15
|
</script>
|
|
39
16
|
|
|
40
17
|
<div
|
|
@@ -43,5 +20,5 @@
|
|
|
43
20
|
})}
|
|
44
21
|
class="builder-text"
|
|
45
22
|
>
|
|
46
|
-
{@html
|
|
23
|
+
{@html text?.toString() || ""}
|
|
47
24
|
</div>
|
|
@@ -57,7 +57,6 @@
|
|
|
57
57
|
rootState: $context.rootState,
|
|
58
58
|
rootSetState: $context.rootSetState,
|
|
59
59
|
context: $context.context,
|
|
60
|
-
shouldEvaluateBindings: true,
|
|
61
60
|
});
|
|
62
61
|
return blockToUse;
|
|
63
62
|
};
|
|
@@ -107,7 +106,7 @@
|
|
|
107
106
|
blockChildren: processedBlock().children ?? [],
|
|
108
107
|
componentRef: blockComponent?.()?.component,
|
|
109
108
|
componentOptions: {
|
|
110
|
-
...getBlockComponentOptions(processedBlock()),
|
|
109
|
+
...getBlockComponentOptions(processedBlock(), $context),
|
|
111
110
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
112
111
|
...provideBuilderContext(blockComponent(), context),
|
|
113
112
|
...provideLinkComponent(blockComponent(), linkComponent),
|
|
@@ -59,10 +59,10 @@
|
|
|
59
59
|
export let trustedHosts: BuilderEditorProps["trustedHosts"] = undefined;
|
|
60
60
|
export let model: BuilderEditorProps["model"] = undefined;
|
|
61
61
|
export let content: BuilderEditorProps["content"] = undefined;
|
|
62
|
+
export let context: BuilderEditorProps["context"] = undefined;
|
|
62
63
|
export let data: BuilderEditorProps["data"] = undefined;
|
|
63
64
|
export let showContent: BuilderEditorProps["showContent"];
|
|
64
65
|
export let contentWrapper: BuilderEditorProps["contentWrapper"] = undefined;
|
|
65
|
-
export let context: BuilderEditorProps["context"] = undefined;
|
|
66
66
|
export let contentWrapperProps: BuilderEditorProps["contentWrapperProps"] =
|
|
67
67
|
undefined;
|
|
68
68
|
|
|
@@ -266,14 +266,22 @@
|
|
|
266
266
|
* TO-DO: should we only update the state when there is a change?
|
|
267
267
|
**/
|
|
268
268
|
if (
|
|
269
|
-
searchParamPreviewModel ===
|
|
270
|
-
|
|
271
|
-
|
|
269
|
+
searchParamPreviewModel === "BUILDER_STUDIO" ||
|
|
270
|
+
(searchParamPreviewModel === model &&
|
|
271
|
+
previewApiKey === apiKey &&
|
|
272
|
+
(!content || searchParamPreviewId === content.id))
|
|
272
273
|
) {
|
|
273
274
|
fetchOneEntry({
|
|
274
|
-
model: model,
|
|
275
|
+
model: model || "",
|
|
275
276
|
apiKey: apiKey,
|
|
276
277
|
apiVersion: $builderContextSignal.apiVersion,
|
|
278
|
+
...(searchParamPreviewModel === "BUILDER_STUDIO" && context?.symbolId
|
|
279
|
+
? {
|
|
280
|
+
query: {
|
|
281
|
+
id: context.symbolId,
|
|
282
|
+
},
|
|
283
|
+
}
|
|
284
|
+
: {}),
|
|
277
285
|
}).then((content) => {
|
|
278
286
|
if (content) {
|
|
279
287
|
mergeNewContent(content);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "3.0.
|
|
1
|
+
export const SDK_VERSION = "3.0.2"
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { logger } from '../../../helpers/logger';
|
|
2
1
|
import type { ExecutorArgs } from '../helpers';
|
|
3
2
|
import { flattenState, getFunctionArguments } from '../helpers';
|
|
4
3
|
import Interpreter from './acorn-interpreter';
|
|
@@ -95,10 +94,7 @@ export const runInEdge = ({
|
|
|
95
94
|
return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
|
|
96
95
|
}).join('\n');
|
|
97
96
|
const cleanedCode = processCode(code);
|
|
98
|
-
if (cleanedCode === '')
|
|
99
|
-
logger.warn('Skipping evaluation of empty code block.');
|
|
100
|
-
return;
|
|
101
|
-
}
|
|
97
|
+
if (cleanedCode === '') return;
|
|
102
98
|
const transformed = `
|
|
103
99
|
function theFunction() {
|
|
104
100
|
${prependedCode}
|
|
@@ -1,7 +1,24 @@
|
|
|
1
|
+
import type { BuilderContextInterface } from '../context/types';
|
|
1
2
|
import type { BuilderBlock } from '../types/builder-block';
|
|
2
|
-
|
|
3
|
+
import { evaluate } from './evaluate/evaluate';
|
|
4
|
+
export function getBlockComponentOptions(block: BuilderBlock, context: Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>) {
|
|
3
5
|
return {
|
|
4
6
|
...block.component?.options,
|
|
5
|
-
...(block as any).options
|
|
7
|
+
...(block as any).options,
|
|
8
|
+
...evaluateTextComponentTextOption(block, context)
|
|
6
9
|
};
|
|
10
|
+
}
|
|
11
|
+
const evaluateTextComponentTextOption = (block: BuilderBlock, context: Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>) => {
|
|
12
|
+
if (block.component?.name === 'Text' && block.component.options?.text && typeof block.component.options.text === 'string') {
|
|
13
|
+
return {
|
|
14
|
+
...block.component.options,
|
|
15
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match: string, group: string) => (evaluate({
|
|
16
|
+
code: group,
|
|
17
|
+
context,
|
|
18
|
+
localState: context.localState,
|
|
19
|
+
rootState: context.rootState,
|
|
20
|
+
rootSetState: context.rootSetState
|
|
21
|
+
}) as string))
|
|
22
|
+
};
|
|
23
|
+
}
|
|
7
24
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
|
-
import { flatten, flattenMongoQuery } from '../../helpers/flatten';
|
|
1
|
+
import { flatten, flattenMongoQuery, unflatten } from '../../helpers/flatten';
|
|
2
2
|
import { normalizeSearchParams } from '../../helpers/search/search';
|
|
3
3
|
import { DEFAULT_API_VERSION } from '../../types/api-version';
|
|
4
4
|
import { getBuilderSearchParamsFromWindow } from '../get-builder-search-params/index';
|
|
5
|
+
import { isBrowser } from '../is-browser';
|
|
5
6
|
import type { GetContentOptions } from './types';
|
|
6
7
|
const isPositiveNumber = (thing: unknown) => typeof thing === 'number' && !isNaN(thing) && thing >= 0;
|
|
7
8
|
export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
@@ -39,7 +40,7 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
39
40
|
url.searchParams.set('noTraverse', String(noTraverse));
|
|
40
41
|
url.searchParams.set('includeRefs', String(true));
|
|
41
42
|
const finalLocale = locale || userAttributes?.locale;
|
|
42
|
-
let finalUserAttributes = userAttributes;
|
|
43
|
+
let finalUserAttributes: Record<string, any> = userAttributes || {};
|
|
43
44
|
if (finalLocale) {
|
|
44
45
|
url.searchParams.set('locale', finalLocale);
|
|
45
46
|
finalUserAttributes = {
|
|
@@ -79,11 +80,15 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
79
80
|
...getBuilderSearchParamsFromWindow(),
|
|
80
81
|
...normalizeSearchParams(options.options || {})
|
|
81
82
|
};
|
|
83
|
+
finalUserAttributes = {
|
|
84
|
+
...finalUserAttributes,
|
|
85
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
86
|
+
};
|
|
82
87
|
const flattened = flatten(queryOptions);
|
|
83
88
|
for (const key in flattened) {
|
|
84
89
|
url.searchParams.set(key, String(flattened[key]));
|
|
85
90
|
}
|
|
86
|
-
if (finalUserAttributes) {
|
|
91
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
87
92
|
url.searchParams.set('userAttributes', JSON.stringify(finalUserAttributes));
|
|
88
93
|
}
|
|
89
94
|
if (query) {
|
|
@@ -95,4 +100,26 @@ export const generateContentUrl = (options: GetContentOptions): URL => {
|
|
|
95
100
|
}
|
|
96
101
|
}
|
|
97
102
|
return url;
|
|
103
|
+
};
|
|
104
|
+
const getUserAttributesFromQueryOptions = (queryOptions: any) => {
|
|
105
|
+
const newUserAttributes: any = {};
|
|
106
|
+
for (const key in queryOptions) {
|
|
107
|
+
if (key.startsWith('userAttributes.')) {
|
|
108
|
+
newUserAttributes[key] = queryOptions[key];
|
|
109
|
+
delete queryOptions[key];
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
return newUserAttributes;
|
|
113
|
+
};
|
|
114
|
+
const getUserAttributesAsJSON = (queryOptions: any) => {
|
|
115
|
+
if (isBrowser() && queryOptions['preview'] === 'BUILDER_STUDIO') {
|
|
116
|
+
queryOptions['userAttributes.urlPath'] = window.location.pathname;
|
|
117
|
+
queryOptions['userAttributes.host'] = window.location.host;
|
|
118
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
119
|
+
const {
|
|
120
|
+
userAttributes
|
|
121
|
+
} = unflatten(queryOptionsForUserAttributes);
|
|
122
|
+
return userAttributes;
|
|
123
|
+
}
|
|
124
|
+
return {};
|
|
98
125
|
}
|
|
@@ -85,29 +85,19 @@ const evaluateBindings = ({
|
|
|
85
85
|
export function getProcessedBlock({
|
|
86
86
|
block,
|
|
87
87
|
context,
|
|
88
|
-
shouldEvaluateBindings,
|
|
89
88
|
localState,
|
|
90
89
|
rootState,
|
|
91
90
|
rootSetState
|
|
92
91
|
}: {
|
|
93
92
|
block: BuilderBlock;
|
|
94
|
-
/**
|
|
95
|
-
* In some cases, we want to avoid evaluating bindings and only want framework-specific block transformation. It is
|
|
96
|
-
* also sometimes too early to consider bindings, e.g. when we might be looking at a repeated block.
|
|
97
|
-
*/
|
|
98
|
-
shouldEvaluateBindings: boolean;
|
|
99
93
|
} & Pick<BuilderContextInterface, 'localState' | 'context' | 'rootState' | 'rootSetState'>): BuilderBlock {
|
|
100
94
|
let transformedBlock = resolveLocalizedValues(block, (rootState.locale as string | undefined));
|
|
101
95
|
transformedBlock = transformBlock(transformedBlock);
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
});
|
|
110
|
-
} else {
|
|
111
|
-
return transformedBlock;
|
|
112
|
-
}
|
|
96
|
+
return evaluateBindings({
|
|
97
|
+
block: transformedBlock,
|
|
98
|
+
localState,
|
|
99
|
+
rootState,
|
|
100
|
+
rootSetState,
|
|
101
|
+
context
|
|
102
|
+
});
|
|
113
103
|
}
|
package/src/helpers/flatten.ts
CHANGED
|
@@ -38,4 +38,27 @@ export function flattenMongoQuery(obj: any, _current?: any, _res: any = {}): {
|
|
|
38
38
|
}
|
|
39
39
|
}
|
|
40
40
|
return _res;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Unflatten a flat object with dot-separated keys back into a nested object.
|
|
45
|
+
*
|
|
46
|
+
* { 'foo.bar': 'baz' } -> { foo: { bar: 'baz' }}
|
|
47
|
+
*/
|
|
48
|
+
export function unflatten(obj: any): any {
|
|
49
|
+
const result: any = {};
|
|
50
|
+
for (const key in obj) {
|
|
51
|
+
const parts = key.split('.');
|
|
52
|
+
let current = result;
|
|
53
|
+
for (let i = 0; i < parts.length; i++) {
|
|
54
|
+
const part = parts[i];
|
|
55
|
+
if (i === parts.length - 1) {
|
|
56
|
+
current[part] = obj[key];
|
|
57
|
+
} else {
|
|
58
|
+
current[part] = current[part] || {};
|
|
59
|
+
current = current[part];
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return result;
|
|
41
64
|
}
|
package/src/server-index.ts
CHANGED
|
@@ -17,7 +17,7 @@ export type { ContentVariantsPrps as ContentProps } from './components/content-v
|
|
|
17
17
|
/**
|
|
18
18
|
* General Builder types
|
|
19
19
|
*/
|
|
20
|
-
export type { RegisteredComponent } from './context/types';
|
|
20
|
+
export type { BuilderContextInterface, RegisteredComponent, RegisteredComponents } from './context/types';
|
|
21
21
|
export type { BuilderBlock } from './types/builder-block';
|
|
22
22
|
export type { BuilderContent } from './types/builder-content';
|
|
23
23
|
export type { ComponentInfo } from './types/components';
|