@builder.io/sdk-svelte 0.4.1 → 0.4.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/package/--package.json +1 -1
- package/package/CHANGELOG.md +9 -0
- package/package/blocks/BaseText.svelte +3 -1
- package/package/blocks/columns/columns.svelte +1 -1
- package/package/blocks/embed/embed.svelte +1 -1
- package/package/blocks/img/component-info.js +1 -1
- package/package/blocks/symbol/symbol.svelte +9 -9
- package/package/components/render-block/render-block.svelte +18 -39
- package/package/components/render-block/render-block.svelte.d.ts +2 -1
- package/package/components/render-block/render-component.svelte +1 -1
- package/package/components/render-block/render-component.svelte.d.ts +2 -1
- package/package/components/render-block/render-repeated-block.svelte +6 -23
- package/package/components/render-block/render-repeated-block.svelte.d.ts +1 -1
- package/package/components/render-blocks.svelte +4 -1
- package/package/components/render-content/render-content.svelte +83 -95
- package/package/components/render-content/render-content.svelte.d.ts +5 -5
- package/package/components/render-content-variants/helpers.js +3 -1
- package/package/constants/sdk-version.d.ts +1 -1
- package/package/constants/sdk-version.js +1 -1
- package/package/context/builder.context.d.ts +2 -2
- package/package/context/builder.context.js +3 -2
- package/package.json +1 -1
- package/src/blocks/BaseText.svelte +3 -1
- package/src/blocks/columns/columns.svelte +1 -1
- package/src/blocks/embed/embed.svelte +1 -1
- package/src/blocks/img/component-info.ts +1 -1
- package/src/blocks/symbol/symbol.svelte +9 -9
- package/src/components/render-block/render-block.svelte +19 -40
- package/src/components/render-block/render-component.svelte +3 -2
- package/src/components/render-block/render-repeated-block.svelte +6 -23
- package/src/components/render-blocks.svelte +4 -1
- package/src/components/render-content/render-content.svelte +94 -103
- package/src/components/render-content-variants/helpers.ts +4 -1
- package/src/constants/sdk-version.ts +1 -1
- package/src/context/builder.context.ts +3 -2
package/package/--package.json
CHANGED
package/package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
### 0.4.3
|
|
2
|
+
- Fix: SSR A/B test environment check (`isHydrationTarget`) now accurately checks current environment.
|
|
3
|
+
|
|
4
|
+
### 0.4.2
|
|
5
|
+
|
|
6
|
+
- Feature: Added support for mutating Builder's `state` in custom element events and custom user code.
|
|
7
|
+
|
|
1
8
|
### 0.4.1
|
|
2
9
|
|
|
3
10
|
- Fix: bring back `getBuilderSearchParams` export that was accidentally removed.
|
|
@@ -5,6 +12,8 @@
|
|
|
5
12
|
### 0.4.0
|
|
6
13
|
|
|
7
14
|
- Feature: A/B tests are now rendered correctly during server-side rendering (SSR) when applicable. This behaviour is backwards compatible with previous versions.
|
|
15
|
+
- Feature: Add support for `enrich` API flag.
|
|
16
|
+
- Mark `noTraverse` and `includeRefs` as deprecated.
|
|
8
17
|
|
|
9
18
|
### 0.3.1
|
|
10
19
|
|
|
@@ -16,4 +16,6 @@ function mitosis_styling(node, vars) {
|
|
|
16
16
|
let builderContext = getContext(BuilderContext.key);
|
|
17
17
|
</script>
|
|
18
18
|
|
|
19
|
-
<span use:mitosis_styling={builderContext.inheritedStyles}>
|
|
19
|
+
<span use:mitosis_styling={$builderContext.inheritedStyles}>
|
|
20
|
+
{text}
|
|
21
|
+
</span>
|
|
@@ -68,7 +68,7 @@ function columnCssVars(index) {
|
|
|
68
68
|
};
|
|
69
69
|
}
|
|
70
70
|
function getWidthForBreakpointSize(size) {
|
|
71
|
-
const breakpointSizes = getSizesForBreakpoints(builderContext.content?.meta?.breakpoints || {});
|
|
71
|
+
const breakpointSizes = getSizesForBreakpoints($builderContext.content?.meta?.breakpoints || {});
|
|
72
72
|
return breakpointSizes[size].max;
|
|
73
73
|
}
|
|
74
74
|
$: columnsCssVars = () => {
|
|
@@ -50,11 +50,11 @@ function fetchContent() {
|
|
|
50
50
|
if (!contentToUse &&
|
|
51
51
|
symbol?.model &&
|
|
52
52
|
// This is a hack, we should not need to check for this, but it is needed for Svelte.
|
|
53
|
-
builderContext?.apiKey) {
|
|
53
|
+
$builderContext?.apiKey) {
|
|
54
54
|
getContent({
|
|
55
55
|
model: symbol.model,
|
|
56
|
-
apiKey: builderContext.apiKey,
|
|
57
|
-
apiVersion: builderContext.apiVersion,
|
|
56
|
+
apiKey: $builderContext.apiKey,
|
|
57
|
+
apiVersion: $builderContext.apiVersion,
|
|
58
58
|
query: {
|
|
59
59
|
id: symbol.entry,
|
|
60
60
|
},
|
|
@@ -83,7 +83,7 @@ let contentToUse = symbol?.content;
|
|
|
83
83
|
onMount(() => {
|
|
84
84
|
fetchContent();
|
|
85
85
|
});
|
|
86
|
-
function onUpdateFn_0() {
|
|
86
|
+
function onUpdateFn_0(..._args) {
|
|
87
87
|
fetchContent();
|
|
88
88
|
}
|
|
89
89
|
$: onUpdateFn_0(...[symbol]);
|
|
@@ -98,13 +98,13 @@ $: onUpdateFn_0(...[symbol]);
|
|
|
98
98
|
use:setAttrs={filterAttrs(attributes, isEvent)}
|
|
99
99
|
>
|
|
100
100
|
<RenderContent
|
|
101
|
-
apiVersion={builderContext.apiVersion}
|
|
102
|
-
apiKey={builderContext.apiKey}
|
|
103
|
-
context={builderContext.context}
|
|
104
|
-
customComponents={Object.values(builderContext.registeredComponents)}
|
|
101
|
+
apiVersion={$builderContext.apiVersion}
|
|
102
|
+
apiKey={$builderContext.apiKey}
|
|
103
|
+
context={$builderContext.context}
|
|
104
|
+
customComponents={Object.values($builderContext.registeredComponents)}
|
|
105
105
|
data={{
|
|
106
106
|
...symbol?.data,
|
|
107
|
-
|
|
107
|
+
...$builderContext.localState,
|
|
108
108
|
...contentToUse?.data?.state,
|
|
109
109
|
}}
|
|
110
110
|
model={symbol?.model}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
|
-
<script>import {
|
|
3
|
+
<script>import { writable } from "svelte/store";
|
|
4
|
+
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
4
5
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
5
6
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
6
7
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
@@ -8,7 +9,7 @@ import BlockStyles from "./block-styles.svelte";
|
|
|
8
9
|
import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./render-block.helpers.js";
|
|
9
10
|
import RenderRepeatedBlock from "./render-repeated-block.svelte";
|
|
10
11
|
import { TARGET } from "../../constants/target.js";
|
|
11
|
-
import
|
|
12
|
+
import "../../functions/extract-text-styles.js";
|
|
12
13
|
import RenderComponent from "./render-component.svelte";
|
|
13
14
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
14
15
|
const setAttrs = (node, attrs = {}) => {
|
|
@@ -32,7 +33,7 @@ export let context;
|
|
|
32
33
|
$: repeatItem = () => {
|
|
33
34
|
return getRepeatItemData({
|
|
34
35
|
block: block,
|
|
35
|
-
context: context,
|
|
36
|
+
context: $context,
|
|
36
37
|
});
|
|
37
38
|
};
|
|
38
39
|
$: useBlock = () => {
|
|
@@ -40,10 +41,10 @@ $: useBlock = () => {
|
|
|
40
41
|
? block
|
|
41
42
|
: getProcessedBlock({
|
|
42
43
|
block: block,
|
|
43
|
-
localState: context.localState,
|
|
44
|
-
rootState: context.rootState,
|
|
45
|
-
rootSetState: context.rootSetState,
|
|
46
|
-
context: context.context,
|
|
44
|
+
localState: $context.localState,
|
|
45
|
+
rootState: $context.rootState,
|
|
46
|
+
rootSetState: $context.rootSetState,
|
|
47
|
+
context: $context.context,
|
|
47
48
|
shouldEvaluateBindings: true,
|
|
48
49
|
});
|
|
49
50
|
};
|
|
@@ -59,10 +60,10 @@ $: canShowBlock = () => {
|
|
|
59
60
|
$: actions = () => {
|
|
60
61
|
return getBlockActions({
|
|
61
62
|
block: useBlock(),
|
|
62
|
-
rootState: context.rootState,
|
|
63
|
-
rootSetState: context.rootSetState,
|
|
64
|
-
localState: context.localState,
|
|
65
|
-
context: context.context,
|
|
63
|
+
rootState: $context.rootState,
|
|
64
|
+
rootSetState: $context.rootSetState,
|
|
65
|
+
localState: $context.localState,
|
|
66
|
+
context: $context.context,
|
|
66
67
|
});
|
|
67
68
|
};
|
|
68
69
|
$: attributes = () => {
|
|
@@ -73,7 +74,7 @@ $: attributes = () => {
|
|
|
73
74
|
? {
|
|
74
75
|
style: getReactNativeBlockStyles({
|
|
75
76
|
block: useBlock(),
|
|
76
|
-
context: context,
|
|
77
|
+
context: $context,
|
|
77
78
|
blockStyles: blockProperties.style,
|
|
78
79
|
}),
|
|
79
80
|
}
|
|
@@ -90,29 +91,6 @@ $: childrenWithoutParentComponent = () => {
|
|
|
90
91
|
const shouldRenderChildrenOutsideRef = !component?.component && !repeatItem();
|
|
91
92
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
92
93
|
};
|
|
93
|
-
$: childrenContext = () => {
|
|
94
|
-
const getInheritedTextStyles = () => {
|
|
95
|
-
if (TARGET !== "reactNative") {
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
return extractTextStyles(getReactNativeBlockStyles({
|
|
99
|
-
block: useBlock(),
|
|
100
|
-
context: context,
|
|
101
|
-
blockStyles: attributes().style,
|
|
102
|
-
}));
|
|
103
|
-
};
|
|
104
|
-
return {
|
|
105
|
-
apiKey: context.apiKey,
|
|
106
|
-
apiVersion: context.apiVersion,
|
|
107
|
-
localState: context.localState,
|
|
108
|
-
rootState: context.rootState,
|
|
109
|
-
rootSetState: context.rootSetState,
|
|
110
|
-
content: context.content,
|
|
111
|
-
context: context.context,
|
|
112
|
-
registeredComponents: context.registeredComponents,
|
|
113
|
-
inheritedStyles: getInheritedTextStyles(),
|
|
114
|
-
};
|
|
115
|
-
};
|
|
116
94
|
$: renderComponentProps = () => {
|
|
117
95
|
return {
|
|
118
96
|
blockChildren: useBlock().children ?? [],
|
|
@@ -132,14 +110,15 @@ $: renderComponentProps = () => {
|
|
|
132
110
|
},
|
|
133
111
|
}),
|
|
134
112
|
},
|
|
135
|
-
context: childrenContext
|
|
113
|
+
context: childrenContext,
|
|
136
114
|
};
|
|
137
115
|
};
|
|
138
116
|
let component = getComponent({
|
|
139
117
|
block: block,
|
|
140
|
-
context: context,
|
|
118
|
+
context: $context,
|
|
141
119
|
});
|
|
142
120
|
let Tag = block.tagName || "div";
|
|
121
|
+
let childrenContext = writable($context);
|
|
143
122
|
</script>
|
|
144
123
|
|
|
145
124
|
{#if canShowBlock()}
|
|
@@ -159,11 +138,11 @@ let Tag = block.tagName || "div";
|
|
|
159
138
|
<RenderComponent {...renderComponentProps()} />
|
|
160
139
|
|
|
161
140
|
{#each childrenWithoutParentComponent() as child ("render-block-" + child.id)}
|
|
162
|
-
<svelte:self block={child} context={childrenContext
|
|
141
|
+
<svelte:self block={child} context={childrenContext} />
|
|
163
142
|
{/each}
|
|
164
143
|
|
|
165
144
|
{#each childrenWithoutParentComponent() as child ("block-style-" + child.id)}
|
|
166
|
-
<BlockStyles block={child} context={childrenContext
|
|
145
|
+
<BlockStyles block={child} context={$childrenContext} />
|
|
167
146
|
{/each}
|
|
168
147
|
</svelte:element>
|
|
169
148
|
{/if}
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
export type RenderBlockProps = {
|
|
3
3
|
block: BuilderBlock;
|
|
4
|
-
context: BuilderContextInterface
|
|
4
|
+
context: Writable<BuilderContextInterface>;
|
|
5
5
|
};
|
|
6
6
|
import type { BuilderContextInterface } from "../../context/types.js";
|
|
7
7
|
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
8
|
+
import type { Writable } from "svelte/store";
|
|
8
9
|
declare const __propDef: {
|
|
9
10
|
props: {
|
|
10
11
|
block: RenderBlockProps["block"];
|
|
@@ -9,10 +9,11 @@ export interface RenderComponentProps {
|
|
|
9
9
|
componentRef: any;
|
|
10
10
|
componentOptions: ComponentOptions;
|
|
11
11
|
blockChildren: BuilderBlock[];
|
|
12
|
-
context: BuilderContextInterface
|
|
12
|
+
context: Writable<BuilderContextInterface>;
|
|
13
13
|
}
|
|
14
14
|
import type { BuilderBlock } from "../../types/builder-block.js";
|
|
15
15
|
import type { BuilderContextInterface } from "../../context/types.js";
|
|
16
|
+
import type { Writable } from "svelte/store";
|
|
16
17
|
declare const __propDef: {
|
|
17
18
|
props: {
|
|
18
19
|
componentRef: RenderComponentProps["componentRef"];
|
|
@@ -1,30 +1,13 @@
|
|
|
1
|
-
<script context="module"
|
|
2
|
-
* We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
|
|
3
|
-
*
|
|
4
|
-
* ```vue
|
|
5
|
-
*
|
|
6
|
-
* <slot></slot>
|
|
7
|
-
*
|
|
8
|
-
* ```
|
|
9
|
-
*/
|
|
10
|
-
</script>
|
|
1
|
+
<script context="module"></script>
|
|
11
2
|
|
|
12
3
|
<script>import { setContext } from "svelte";
|
|
4
|
+
import { writable } from "svelte/store";
|
|
13
5
|
import BuilderContext from "../../context/builder.context.js";
|
|
14
6
|
import RenderBlock from "./render-block.svelte";
|
|
15
|
-
export let block;
|
|
16
7
|
export let repeatContext;
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
rootState: repeatContext.rootState,
|
|
21
|
-
rootSetState: repeatContext.rootSetState,
|
|
22
|
-
context: repeatContext.context,
|
|
23
|
-
apiKey: repeatContext.apiKey,
|
|
24
|
-
registeredComponents: repeatContext.registeredComponents,
|
|
25
|
-
inheritedStyles: repeatContext.inheritedStyles,
|
|
26
|
-
apiVersion: repeatContext.apiVersion,
|
|
27
|
-
});
|
|
8
|
+
export let block;
|
|
9
|
+
let store = writable(repeatContext);
|
|
10
|
+
setContext(BuilderContext.key, store);
|
|
28
11
|
</script>
|
|
29
12
|
|
|
30
|
-
<RenderBlock {block} context={
|
|
13
|
+
<RenderBlock {block} context={store} />
|
|
@@ -7,8 +7,8 @@ import type { BuilderContextInterface } from "../../context/types.js";
|
|
|
7
7
|
import type { BuilderBlock } from "../../types/builder-block";
|
|
8
8
|
declare const __propDef: {
|
|
9
9
|
props: {
|
|
10
|
-
block: Props["block"];
|
|
11
10
|
repeatContext: Props["repeatContext"];
|
|
11
|
+
block: Props["block"];
|
|
12
12
|
};
|
|
13
13
|
events: {
|
|
14
14
|
[evt: string]: CustomEvent<any>;
|
|
@@ -61,6 +61,9 @@ $: className = () => {
|
|
|
61
61
|
on:mouseenter={(event) => {
|
|
62
62
|
onMouseEnter();
|
|
63
63
|
}}
|
|
64
|
+
on:keypress={(event) => {
|
|
65
|
+
onClick();
|
|
66
|
+
}}
|
|
64
67
|
>
|
|
65
68
|
{#if blocks}
|
|
66
69
|
{#each blocks as block ("render-block-" + block.id)}
|
|
@@ -70,7 +73,7 @@ $: className = () => {
|
|
|
70
73
|
|
|
71
74
|
{#if blocks}
|
|
72
75
|
{#each blocks as block ("block-style-" + block.id)}
|
|
73
|
-
<BlockStyles {block} context={builderContext} />
|
|
76
|
+
<BlockStyles {block} context={$builderContext} />
|
|
74
77
|
{/each}
|
|
75
78
|
{/if}
|
|
76
79
|
</div>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
<script>import { onDestroy, onMount, setContext } from "svelte";
|
|
2
|
+
import { writable } from "svelte/store";
|
|
2
3
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
3
4
|
import { evaluate } from "../../functions/evaluate.js";
|
|
4
5
|
import { getContent } from "../../functions/get-content/index.js";
|
|
@@ -46,47 +47,48 @@ const setAttrs = (node, attrs = {}) => {
|
|
|
46
47
|
},
|
|
47
48
|
};
|
|
48
49
|
};
|
|
49
|
-
export let content;
|
|
50
|
-
export let data;
|
|
51
50
|
export let canTrack;
|
|
52
|
-
export let locale;
|
|
53
|
-
export let customComponents;
|
|
54
51
|
export let model;
|
|
55
52
|
export let context;
|
|
56
53
|
export let apiKey;
|
|
54
|
+
export let content;
|
|
57
55
|
export let parentContentId;
|
|
56
|
+
export let data;
|
|
57
|
+
export let locale;
|
|
58
|
+
export let apiVersion;
|
|
59
|
+
export let customComponents;
|
|
58
60
|
export let hideContent;
|
|
59
61
|
export let classNameProp;
|
|
60
62
|
export let isSsrAbTest;
|
|
61
63
|
export let includeRefs;
|
|
62
64
|
export let enrich;
|
|
63
|
-
export let apiVersion;
|
|
64
65
|
function mergeNewContent(newContent) {
|
|
65
|
-
|
|
66
|
-
|
|
66
|
+
$builderContextSignal.content = {
|
|
67
|
+
...$builderContextSignal.content,
|
|
67
68
|
...newContent,
|
|
68
69
|
data: {
|
|
69
|
-
|
|
70
|
+
...$builderContextSignal.content?.data,
|
|
70
71
|
...newContent?.data,
|
|
71
72
|
},
|
|
72
73
|
meta: {
|
|
73
|
-
|
|
74
|
+
...$builderContextSignal.content?.meta,
|
|
74
75
|
...newContent?.meta,
|
|
75
|
-
breakpoints: newContent?.meta?.breakpoints ||
|
|
76
|
+
breakpoints: newContent?.meta?.breakpoints ||
|
|
77
|
+
$builderContextSignal.content?.meta?.breakpoints,
|
|
76
78
|
},
|
|
77
79
|
};
|
|
78
80
|
}
|
|
79
81
|
function setBreakpoints(breakpoints) {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
+
$builderContextSignal.content = {
|
|
83
|
+
...$builderContextSignal.content,
|
|
82
84
|
meta: {
|
|
83
|
-
|
|
85
|
+
...$builderContextSignal.content?.meta,
|
|
84
86
|
breakpoints,
|
|
85
87
|
},
|
|
86
88
|
};
|
|
87
89
|
}
|
|
88
90
|
function contentSetState(newRootState) {
|
|
89
|
-
|
|
91
|
+
$builderContextSignal.rootState = newRootState;
|
|
90
92
|
}
|
|
91
93
|
function processMessage(event) {
|
|
92
94
|
const { data } = event;
|
|
@@ -95,7 +97,7 @@ function processMessage(event) {
|
|
|
95
97
|
case "builder.configureSdk": {
|
|
96
98
|
const messageContent = data.data;
|
|
97
99
|
const { breakpoints, contentId } = messageContent;
|
|
98
|
-
if (!contentId || contentId !==
|
|
100
|
+
if (!contentId || contentId !== $builderContextSignal.content?.id) {
|
|
99
101
|
return;
|
|
100
102
|
}
|
|
101
103
|
if (breakpoints) {
|
|
@@ -126,21 +128,21 @@ function processMessage(event) {
|
|
|
126
128
|
}
|
|
127
129
|
function evaluateJsCode() {
|
|
128
130
|
// run any dynamic JS code attached to content
|
|
129
|
-
const jsCode =
|
|
131
|
+
const jsCode = $builderContextSignal.content?.data?.jsCode;
|
|
130
132
|
if (jsCode) {
|
|
131
133
|
evaluate({
|
|
132
134
|
code: jsCode,
|
|
133
135
|
context: context || {},
|
|
134
136
|
localState: undefined,
|
|
135
|
-
rootState:
|
|
137
|
+
rootState: $builderContextSignal.rootState,
|
|
136
138
|
rootSetState: contentSetState,
|
|
137
139
|
});
|
|
138
140
|
}
|
|
139
141
|
}
|
|
140
142
|
function onClick(event) {
|
|
141
|
-
if (
|
|
142
|
-
const variationId =
|
|
143
|
-
const contentId =
|
|
143
|
+
if ($builderContextSignal.content) {
|
|
144
|
+
const variationId = $builderContextSignal.content?.testVariationId;
|
|
145
|
+
const contentId = $builderContextSignal.content?.id;
|
|
144
146
|
_track({
|
|
145
147
|
type: "click",
|
|
146
148
|
canTrack: canTrackToUse,
|
|
@@ -160,7 +162,7 @@ function evalExpression(expression) {
|
|
|
160
162
|
code: group,
|
|
161
163
|
context: context || {},
|
|
162
164
|
localState: undefined,
|
|
163
|
-
rootState:
|
|
165
|
+
rootState: $builderContextSignal.rootState,
|
|
164
166
|
rootSetState: contentSetState,
|
|
165
167
|
}));
|
|
166
168
|
}
|
|
@@ -169,7 +171,7 @@ function handleRequest({ url, key }) {
|
|
|
169
171
|
.then((response) => response.json())
|
|
170
172
|
.then((json) => {
|
|
171
173
|
const newState = {
|
|
172
|
-
|
|
174
|
+
...$builderContextSignal.rootState,
|
|
173
175
|
[key]: json,
|
|
174
176
|
};
|
|
175
177
|
contentSetState(newState);
|
|
@@ -179,7 +181,7 @@ function handleRequest({ url, key }) {
|
|
|
179
181
|
});
|
|
180
182
|
}
|
|
181
183
|
function runHttpRequests() {
|
|
182
|
-
const requests =
|
|
184
|
+
const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
|
|
183
185
|
Object.entries(requests).forEach(([key, url]) => {
|
|
184
186
|
if (url && (!httpReqsData[key] || isEditing())) {
|
|
185
187
|
const evaluatedUrl = evalExpression(url);
|
|
@@ -194,7 +196,7 @@ function emitStateUpdate() {
|
|
|
194
196
|
if (isEditing()) {
|
|
195
197
|
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
196
198
|
detail: {
|
|
197
|
-
state:
|
|
199
|
+
state: $builderContextSignal.rootState,
|
|
198
200
|
ref: {
|
|
199
201
|
name: model,
|
|
200
202
|
},
|
|
@@ -205,33 +207,8 @@ function emitStateUpdate() {
|
|
|
205
207
|
let elementRef;
|
|
206
208
|
let forceReRenderCount = 0;
|
|
207
209
|
let overrideContent = null;
|
|
208
|
-
let useContent = getContentInitialValue({
|
|
209
|
-
content: content,
|
|
210
|
-
data: data,
|
|
211
|
-
});
|
|
212
210
|
let update = 0;
|
|
213
211
|
let canTrackToUse = checkIsDefined(canTrack) ? canTrack : true;
|
|
214
|
-
let contentState = getContextStateInitialValue({
|
|
215
|
-
content: content,
|
|
216
|
-
data: data,
|
|
217
|
-
locale: locale,
|
|
218
|
-
});
|
|
219
|
-
let allRegisteredComponents = [
|
|
220
|
-
...getDefaultRegisteredComponents(),
|
|
221
|
-
// While this `components` object is deprecated, we must maintain support for it.
|
|
222
|
-
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
223
|
-
// existing usage.
|
|
224
|
-
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
225
|
-
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
226
|
-
...components,
|
|
227
|
-
...(customComponents || []),
|
|
228
|
-
].reduce((acc, { component, ...curr }) => ({
|
|
229
|
-
...acc,
|
|
230
|
-
[curr.name]: {
|
|
231
|
-
component: TARGET === "vue3" ? wrapComponentRef(component) : component,
|
|
232
|
-
...curr,
|
|
233
|
-
},
|
|
234
|
-
}), {});
|
|
235
212
|
let httpReqsData = {};
|
|
236
213
|
let clicked = false;
|
|
237
214
|
let scriptStr = getRenderContentScriptString({
|
|
@@ -239,6 +216,39 @@ let scriptStr = getRenderContentScriptString({
|
|
|
239
216
|
contentId: content?.id,
|
|
240
217
|
parentContentId: parentContentId,
|
|
241
218
|
});
|
|
219
|
+
let builderContextSignal = writable({
|
|
220
|
+
content: getContentInitialValue({
|
|
221
|
+
content: content,
|
|
222
|
+
data: data,
|
|
223
|
+
}),
|
|
224
|
+
localState: undefined,
|
|
225
|
+
rootState: getContextStateInitialValue({
|
|
226
|
+
content: content,
|
|
227
|
+
data: data,
|
|
228
|
+
locale: locale,
|
|
229
|
+
}),
|
|
230
|
+
rootSetState: contentSetState,
|
|
231
|
+
context: context || {},
|
|
232
|
+
apiKey: apiKey,
|
|
233
|
+
apiVersion: apiVersion,
|
|
234
|
+
registeredComponents: [
|
|
235
|
+
...getDefaultRegisteredComponents(),
|
|
236
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
237
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
238
|
+
// existing usage.
|
|
239
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
240
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
241
|
+
...components,
|
|
242
|
+
...(customComponents || []),
|
|
243
|
+
].reduce((acc, { component, ...curr }) => ({
|
|
244
|
+
...acc,
|
|
245
|
+
[curr.name]: {
|
|
246
|
+
component: TARGET === "vue3" ? wrapComponentRef(component) : component,
|
|
247
|
+
...curr,
|
|
248
|
+
},
|
|
249
|
+
}), {}),
|
|
250
|
+
inheritedStyles: {},
|
|
251
|
+
});
|
|
242
252
|
onMount(() => {
|
|
243
253
|
if (!apiKey) {
|
|
244
254
|
logger.error("No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
@@ -264,16 +274,16 @@ onMount(() => {
|
|
|
264
274
|
}
|
|
265
275
|
: {}),
|
|
266
276
|
});
|
|
267
|
-
Object.values(
|
|
277
|
+
Object.values($builderContextSignal.registeredComponents).forEach((registeredComponent) => {
|
|
268
278
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
269
279
|
window.parent?.postMessage(message, "*");
|
|
270
280
|
});
|
|
271
281
|
window.addEventListener("message", processMessage);
|
|
272
282
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
273
283
|
}
|
|
274
|
-
if (
|
|
275
|
-
const variationId =
|
|
276
|
-
const contentId =
|
|
284
|
+
if ($builderContextSignal.content) {
|
|
285
|
+
const variationId = $builderContextSignal.content?.testVariationId;
|
|
286
|
+
const contentId = $builderContextSignal.content?.id;
|
|
277
287
|
_track({
|
|
278
288
|
type: "impression",
|
|
279
289
|
canTrack: canTrackToUse,
|
|
@@ -316,53 +326,28 @@ onMount(() => {
|
|
|
316
326
|
emitStateUpdate();
|
|
317
327
|
}
|
|
318
328
|
});
|
|
319
|
-
function onUpdateFn_0() {
|
|
329
|
+
function onUpdateFn_0(..._args) {
|
|
320
330
|
if (content) {
|
|
321
331
|
mergeNewContent(content);
|
|
322
332
|
}
|
|
323
333
|
}
|
|
324
334
|
$: onUpdateFn_0(...[content]);
|
|
325
|
-
function onUpdateFn_1() {
|
|
335
|
+
function onUpdateFn_1(..._args) {
|
|
326
336
|
evaluateJsCode();
|
|
327
337
|
}
|
|
328
|
-
$: onUpdateFn_1(...[
|
|
329
|
-
|
|
338
|
+
$: onUpdateFn_1(...[
|
|
339
|
+
$builderContextSignal.content?.data?.jsCode,
|
|
340
|
+
$builderContextSignal.rootState,
|
|
341
|
+
]);
|
|
342
|
+
function onUpdateFn_2(..._args) {
|
|
330
343
|
runHttpRequests();
|
|
331
344
|
}
|
|
332
|
-
$: onUpdateFn_2(...[
|
|
333
|
-
function onUpdateFn_3() {
|
|
345
|
+
$: onUpdateFn_2(...[$builderContextSignal.content?.data?.httpRequests]);
|
|
346
|
+
function onUpdateFn_3(..._args) {
|
|
334
347
|
emitStateUpdate();
|
|
335
348
|
}
|
|
336
|
-
$: onUpdateFn_3(...[
|
|
337
|
-
setContext(builderContext.key,
|
|
338
|
-
get content() {
|
|
339
|
-
return useContent;
|
|
340
|
-
},
|
|
341
|
-
get localState() {
|
|
342
|
-
return undefined;
|
|
343
|
-
},
|
|
344
|
-
get rootState() {
|
|
345
|
-
return contentState;
|
|
346
|
-
},
|
|
347
|
-
get rootSetState() {
|
|
348
|
-
return TARGET === "qwik" ? undefined : contentSetState;
|
|
349
|
-
},
|
|
350
|
-
get context() {
|
|
351
|
-
return context || {};
|
|
352
|
-
},
|
|
353
|
-
get apiKey() {
|
|
354
|
-
return apiKey;
|
|
355
|
-
},
|
|
356
|
-
get apiVersion() {
|
|
357
|
-
return apiVersion;
|
|
358
|
-
},
|
|
359
|
-
get registeredComponents() {
|
|
360
|
-
return allRegisteredComponents;
|
|
361
|
-
},
|
|
362
|
-
get inheritedStyles() {
|
|
363
|
-
return {};
|
|
364
|
-
},
|
|
365
|
-
});
|
|
349
|
+
$: onUpdateFn_3(...[$builderContextSignal.rootState]);
|
|
350
|
+
setContext(builderContext.key, builderContextSignal);
|
|
366
351
|
onDestroy(() => {
|
|
367
352
|
if (isBrowser()) {
|
|
368
353
|
window.removeEventListener("message", processMessage);
|
|
@@ -371,13 +356,13 @@ onDestroy(() => {
|
|
|
371
356
|
});
|
|
372
357
|
</script>
|
|
373
358
|
|
|
374
|
-
{#if
|
|
359
|
+
{#if $builderContextSignal.content}
|
|
375
360
|
<div
|
|
376
361
|
bind:this={elementRef}
|
|
377
362
|
on:click={(event) => {
|
|
378
363
|
onClick(event);
|
|
379
364
|
}}
|
|
380
|
-
builder-content-id={
|
|
365
|
+
builder-content-id={$builderContextSignal.content?.id}
|
|
381
366
|
builder-model={model}
|
|
382
367
|
{...filterAttrs(
|
|
383
368
|
TARGET === "reactNative"
|
|
@@ -417,11 +402,14 @@ onDestroy(() => {
|
|
|
417
402
|
|
|
418
403
|
{#if TARGET !== "reactNative"}
|
|
419
404
|
<RenderContentStyles
|
|
420
|
-
contentId={
|
|
421
|
-
cssCode={
|
|
422
|
-
customFonts={
|
|
405
|
+
contentId={$builderContextSignal.content?.id}
|
|
406
|
+
cssCode={$builderContextSignal.content?.data?.cssCode}
|
|
407
|
+
customFonts={$builderContextSignal.content?.data?.customFonts}
|
|
423
408
|
/>
|
|
424
409
|
{/if}
|
|
425
|
-
<RenderBlocks
|
|
410
|
+
<RenderBlocks
|
|
411
|
+
blocks={$builderContextSignal.content?.data?.blocks}
|
|
412
|
+
key={forceReRenderCount}
|
|
413
|
+
/>
|
|
426
414
|
</div>
|
|
427
415
|
{/if}
|