@builder.io/sdk-svelte 3.0.1 → 3.0.3
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/accordion/accordion.svelte +1 -1
- 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/browser/types/builder-content.d.ts +1 -0
- package/lib/browser/types/input.d.ts +10 -0
- package/lib/edge/blocks/accordion/accordion.svelte +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/edge/types/builder-content.d.ts +1 -0
- package/lib/edge/types/input.d.ts +10 -0
- package/lib/node/blocks/accordion/accordion.svelte +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/lib/node/types/builder-content.d.ts +1 -0
- package/lib/node/types/input.d.ts +10 -0
- package/package.json +1 -1
- package/src/blocks/accordion/accordion.svelte +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
- package/src/types/builder-content.ts +1 -0
- package/src/types/input.ts +10 -0
|
@@ -113,7 +113,7 @@ let open = [];
|
|
|
113
113
|
</script>
|
|
114
114
|
|
|
115
115
|
<div style={stringifyStyles(accordionStyles())} class="builder-accordion">
|
|
116
|
-
{#each items as item, index}
|
|
116
|
+
{#each items as item, index (index)}
|
|
117
117
|
<div
|
|
118
118
|
style={stringifyStyles({
|
|
119
119
|
...accordionTitleStyles(),
|
|
@@ -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.3";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "3.0.
|
|
1
|
+
export const SDK_VERSION = "3.0.3";
|
|
@@ -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';
|
|
@@ -19,6 +19,16 @@ export interface Input {
|
|
|
19
19
|
/** @hidden */
|
|
20
20
|
autoFocus?: boolean;
|
|
21
21
|
subFields?: Input[];
|
|
22
|
+
/**
|
|
23
|
+
* When input is of `type` `object`, use this field to collapse multiple inputs
|
|
24
|
+
* in the Visual Editor by default and preserve screen space.
|
|
25
|
+
*/
|
|
26
|
+
folded?: boolean;
|
|
27
|
+
/**
|
|
28
|
+
* When input is of `type` `object`, provide guidance in the Visual Editor
|
|
29
|
+
* on how to edit this object's contents.
|
|
30
|
+
*/
|
|
31
|
+
keysHelperText?: string;
|
|
22
32
|
/**
|
|
23
33
|
* Additional text to render in the UI to give guidance on how to use this
|
|
24
34
|
*
|
|
@@ -113,7 +113,7 @@ let open = [];
|
|
|
113
113
|
</script>
|
|
114
114
|
|
|
115
115
|
<div style={stringifyStyles(accordionStyles())} class="builder-accordion">
|
|
116
|
-
{#each items as item, index}
|
|
116
|
+
{#each items as item, index (index)}
|
|
117
117
|
<div
|
|
118
118
|
style={stringifyStyles({
|
|
119
119
|
...accordionTitleStyles(),
|
|
@@ -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.3";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "3.0.
|
|
1
|
+
export const SDK_VERSION = "3.0.3";
|
|
@@ -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;
|