@builder.io/sdk-svelte 1.0.15 → 1.0.17
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/columns/columns.svelte +1 -1
- package/lib/browser/components/block/components/block-styles.svelte +1 -1
- package/lib/browser/components/content/components/enable-editor.svelte +31 -31
- package/lib/browser/components/content/components/styles.svelte +1 -1
- package/lib/browser/components/content/content.svelte +1 -1
- package/lib/browser/components/content-variants/content-variants.svelte +9 -6
- package/lib/browser/components/content-variants/helpers.d.ts +1 -1
- package/lib/browser/components/content-variants/helpers.js +1 -1
- package/lib/browser/components/inlined-script.svelte +2 -2
- package/lib/browser/components/inlined-script.svelte.d.ts +2 -2
- package/lib/browser/components/inlined-styles.svelte +2 -2
- package/lib/browser/components/inlined-styles.svelte.d.ts +2 -2
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/edge/blocks/columns/columns.svelte +1 -1
- package/lib/edge/components/block/components/block-styles.svelte +1 -1
- package/lib/edge/components/content/components/enable-editor.svelte +31 -31
- package/lib/edge/components/content/components/styles.svelte +1 -1
- package/lib/edge/components/content/content.svelte +1 -1
- package/lib/edge/components/content-variants/content-variants.svelte +9 -6
- package/lib/edge/components/content-variants/helpers.d.ts +1 -1
- package/lib/edge/components/content-variants/helpers.js +1 -1
- package/lib/edge/components/inlined-script.svelte +2 -2
- package/lib/edge/components/inlined-script.svelte.d.ts +2 -2
- package/lib/edge/components/inlined-styles.svelte +2 -2
- package/lib/edge/components/inlined-styles.svelte.d.ts +2 -2
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/node/blocks/columns/columns.svelte +1 -1
- package/lib/node/components/block/components/block-styles.svelte +1 -1
- package/lib/node/components/content/components/enable-editor.svelte +31 -31
- package/lib/node/components/content/components/styles.svelte +1 -1
- package/lib/node/components/content/content.svelte +1 -1
- package/lib/node/components/content-variants/content-variants.svelte +9 -6
- package/lib/node/components/content-variants/helpers.d.ts +1 -1
- package/lib/node/components/content-variants/helpers.js +1 -1
- package/lib/node/components/inlined-script.svelte +2 -2
- package/lib/node/components/inlined-script.svelte.d.ts +2 -2
- package/lib/node/components/inlined-styles.svelte +2 -2
- package/lib/node/components/inlined-styles.svelte.d.ts +2 -2
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/package.json +1 -1
- package/src/blocks/columns/columns.svelte +1 -1
- package/src/components/block/components/block-styles.svelte +1 -1
- package/src/components/content/components/enable-editor.svelte +34 -35
- package/src/components/content/components/styles.svelte +1 -1
- package/src/components/content/content.svelte +1 -1
- package/src/components/content-variants/content-variants.svelte +9 -6
- package/src/components/content-variants/helpers.ts +1 -1
- package/src/components/inlined-script.svelte +3 -3
- package/src/components/inlined-styles.svelte +3 -3
- package/src/constants/sdk-version.ts +1 -1
|
@@ -129,7 +129,7 @@ let flexDir = stackColumnsAt === "never"
|
|
|
129
129
|
{...{}}
|
|
130
130
|
>
|
|
131
131
|
{#if TARGET !== "reactNative"}
|
|
132
|
-
<InlinedStyles styles={columnsStyles()} />
|
|
132
|
+
<InlinedStyles id="builderio-columns" styles={columnsStyles()} />
|
|
133
133
|
{/if}
|
|
134
134
|
{#each columns as column, index (index)}
|
|
135
135
|
<DynamicRenderer
|
|
@@ -122,41 +122,40 @@ function onClick(event) {
|
|
|
122
122
|
clicked = true;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function evalExpression(expression) {
|
|
126
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
|
|
127
|
-
code: group,
|
|
128
|
-
context: context || {},
|
|
129
|
-
localState: undefined,
|
|
130
|
-
rootState: $builderContextSignal.rootState,
|
|
131
|
-
rootSetState: $builderContextSignal.rootSetState,
|
|
132
|
-
enableCache: true,
|
|
133
|
-
})));
|
|
134
|
-
}
|
|
135
|
-
function handleRequest({ url, key }) {
|
|
136
|
-
fetch(url)
|
|
137
|
-
.then((response) => response.json())
|
|
138
|
-
.then((json) => {
|
|
139
|
-
const newState = {
|
|
140
|
-
...$builderContextSignal.rootState,
|
|
141
|
-
[key]: json,
|
|
142
|
-
};
|
|
143
|
-
$builderContextSignal.rootSetState?.(newState);
|
|
144
|
-
httpReqsData[key] = true;
|
|
145
|
-
})
|
|
146
|
-
.catch((err) => {
|
|
147
|
-
console.error("error fetching dynamic data", url, err);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
125
|
function runHttpRequests() {
|
|
151
126
|
const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
|
|
152
127
|
Object.entries(requests).forEach(([key, url]) => {
|
|
153
|
-
if (url
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
128
|
+
if (!url)
|
|
129
|
+
return;
|
|
130
|
+
// request already in progress
|
|
131
|
+
if (httpReqsPending[key])
|
|
132
|
+
return;
|
|
133
|
+
// request already completed, and not in edit mode
|
|
134
|
+
if (httpReqsData[key] && !isEditing())
|
|
135
|
+
return;
|
|
136
|
+
httpReqsPending[key] = true;
|
|
137
|
+
const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
|
|
138
|
+
code: group,
|
|
139
|
+
context: context || {},
|
|
140
|
+
localState: undefined,
|
|
141
|
+
rootState: $builderContextSignal.rootState,
|
|
142
|
+
rootSetState: $builderContextSignal.rootSetState,
|
|
143
|
+
enableCache: true,
|
|
144
|
+
})));
|
|
145
|
+
fetch(evaluatedUrl)
|
|
146
|
+
.then((response) => response.json())
|
|
147
|
+
.then((json) => {
|
|
148
|
+
mergeNewRootState({
|
|
149
|
+
[key]: json,
|
|
158
150
|
});
|
|
159
|
-
|
|
151
|
+
httpReqsData[key] = true;
|
|
152
|
+
})
|
|
153
|
+
.catch((err) => {
|
|
154
|
+
console.error("error fetching dynamic data", url, err);
|
|
155
|
+
})
|
|
156
|
+
.finally(() => {
|
|
157
|
+
httpReqsPending[key] = false;
|
|
158
|
+
});
|
|
160
159
|
});
|
|
161
160
|
}
|
|
162
161
|
function emitStateUpdate() {
|
|
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
|
|
|
228
227
|
let elementRef;
|
|
229
228
|
let ContentWrapper = contentWrapper || "div";
|
|
230
229
|
let httpReqsData = {};
|
|
230
|
+
let httpReqsPending = {};
|
|
231
231
|
let clicked = false;
|
|
232
232
|
onMount(() => {
|
|
233
233
|
if (isBrowser()) {
|
|
@@ -7,7 +7,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
|
7
7
|
import ContentComponent from "../content/content.svelte";
|
|
8
8
|
import InlinedScript from "../inlined-script.svelte";
|
|
9
9
|
import InlinedStyles from "../inlined-styles.svelte";
|
|
10
|
-
import { checkShouldRenderVariants,
|
|
10
|
+
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
|
|
11
11
|
export let canTrack = undefined;
|
|
12
12
|
export let content = undefined;
|
|
13
13
|
export let isNestedRender = undefined;
|
|
@@ -60,15 +60,18 @@ onMount(() => {
|
|
|
60
60
|
</script>
|
|
61
61
|
|
|
62
62
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
63
|
-
<InlinedScript
|
|
63
|
+
<InlinedScript
|
|
64
|
+
id="builderio-init-variants-fns"
|
|
65
|
+
scriptStr={getInitVariantsFnsScriptString()}
|
|
66
|
+
/>
|
|
64
67
|
{/if}
|
|
65
68
|
|
|
66
69
|
{#if shouldRenderVariants}
|
|
67
|
-
<InlinedStyles
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
<InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
|
|
71
|
+
<InlinedScript
|
|
72
|
+
id="builderio-variants-visibility"
|
|
73
|
+
scriptStr={updateCookieAndStylesScriptStr()}
|
|
70
74
|
/>
|
|
71
|
-
<InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
|
|
72
75
|
|
|
73
76
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
74
77
|
<ContentComponent
|
|
@@ -32,7 +32,7 @@ type VariantData = {
|
|
|
32
32
|
id: string;
|
|
33
33
|
testRatio?: number;
|
|
34
34
|
};
|
|
35
|
-
export declare const
|
|
35
|
+
export declare const getInitVariantsFnsScriptString: () => string;
|
|
36
36
|
export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
|
|
37
37
|
export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
|
|
38
38
|
variationId: string;
|
|
@@ -41,7 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
|
|
|
41
41
|
};
|
|
42
42
|
const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
|
|
43
43
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
44
|
-
export const
|
|
44
|
+
export const getInitVariantsFnsScriptString = () => `
|
|
45
45
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
46
46
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
47
47
|
`;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
interface Props {
|
|
3
3
|
scriptStr: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
declare const __propDef: {
|
|
7
7
|
props: {
|
|
8
8
|
scriptStr: Props["scriptStr"];
|
|
9
|
-
id
|
|
9
|
+
id: Props["id"];
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
12
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
interface Props {
|
|
3
3
|
styles: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
declare const __propDef: {
|
|
7
7
|
props: {
|
|
8
8
|
styles: Props["styles"];
|
|
9
|
-
id
|
|
9
|
+
id: Props["id"];
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
12
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.17";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.17";
|
|
@@ -129,7 +129,7 @@ let flexDir = stackColumnsAt === "never"
|
|
|
129
129
|
{...{}}
|
|
130
130
|
>
|
|
131
131
|
{#if TARGET !== "reactNative"}
|
|
132
|
-
<InlinedStyles styles={columnsStyles()} />
|
|
132
|
+
<InlinedStyles id="builderio-columns" styles={columnsStyles()} />
|
|
133
133
|
{/if}
|
|
134
134
|
{#each columns as column, index (index)}
|
|
135
135
|
<DynamicRenderer
|
|
@@ -122,41 +122,40 @@ function onClick(event) {
|
|
|
122
122
|
clicked = true;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function evalExpression(expression) {
|
|
126
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
|
|
127
|
-
code: group,
|
|
128
|
-
context: context || {},
|
|
129
|
-
localState: undefined,
|
|
130
|
-
rootState: $builderContextSignal.rootState,
|
|
131
|
-
rootSetState: $builderContextSignal.rootSetState,
|
|
132
|
-
enableCache: true,
|
|
133
|
-
})));
|
|
134
|
-
}
|
|
135
|
-
function handleRequest({ url, key }) {
|
|
136
|
-
fetch(url)
|
|
137
|
-
.then((response) => response.json())
|
|
138
|
-
.then((json) => {
|
|
139
|
-
const newState = {
|
|
140
|
-
...$builderContextSignal.rootState,
|
|
141
|
-
[key]: json,
|
|
142
|
-
};
|
|
143
|
-
$builderContextSignal.rootSetState?.(newState);
|
|
144
|
-
httpReqsData[key] = true;
|
|
145
|
-
})
|
|
146
|
-
.catch((err) => {
|
|
147
|
-
console.error("error fetching dynamic data", url, err);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
125
|
function runHttpRequests() {
|
|
151
126
|
const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
|
|
152
127
|
Object.entries(requests).forEach(([key, url]) => {
|
|
153
|
-
if (url
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
128
|
+
if (!url)
|
|
129
|
+
return;
|
|
130
|
+
// request already in progress
|
|
131
|
+
if (httpReqsPending[key])
|
|
132
|
+
return;
|
|
133
|
+
// request already completed, and not in edit mode
|
|
134
|
+
if (httpReqsData[key] && !isEditing())
|
|
135
|
+
return;
|
|
136
|
+
httpReqsPending[key] = true;
|
|
137
|
+
const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
|
|
138
|
+
code: group,
|
|
139
|
+
context: context || {},
|
|
140
|
+
localState: undefined,
|
|
141
|
+
rootState: $builderContextSignal.rootState,
|
|
142
|
+
rootSetState: $builderContextSignal.rootSetState,
|
|
143
|
+
enableCache: true,
|
|
144
|
+
})));
|
|
145
|
+
fetch(evaluatedUrl)
|
|
146
|
+
.then((response) => response.json())
|
|
147
|
+
.then((json) => {
|
|
148
|
+
mergeNewRootState({
|
|
149
|
+
[key]: json,
|
|
158
150
|
});
|
|
159
|
-
|
|
151
|
+
httpReqsData[key] = true;
|
|
152
|
+
})
|
|
153
|
+
.catch((err) => {
|
|
154
|
+
console.error("error fetching dynamic data", url, err);
|
|
155
|
+
})
|
|
156
|
+
.finally(() => {
|
|
157
|
+
httpReqsPending[key] = false;
|
|
158
|
+
});
|
|
160
159
|
});
|
|
161
160
|
}
|
|
162
161
|
function emitStateUpdate() {
|
|
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
|
|
|
228
227
|
let elementRef;
|
|
229
228
|
let ContentWrapper = contentWrapper || "div";
|
|
230
229
|
let httpReqsData = {};
|
|
230
|
+
let httpReqsPending = {};
|
|
231
231
|
let clicked = false;
|
|
232
232
|
onMount(() => {
|
|
233
233
|
if (isBrowser()) {
|
|
@@ -7,7 +7,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
|
7
7
|
import ContentComponent from "../content/content.svelte";
|
|
8
8
|
import InlinedScript from "../inlined-script.svelte";
|
|
9
9
|
import InlinedStyles from "../inlined-styles.svelte";
|
|
10
|
-
import { checkShouldRenderVariants,
|
|
10
|
+
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
|
|
11
11
|
export let canTrack = undefined;
|
|
12
12
|
export let content = undefined;
|
|
13
13
|
export let isNestedRender = undefined;
|
|
@@ -60,15 +60,18 @@ onMount(() => {
|
|
|
60
60
|
</script>
|
|
61
61
|
|
|
62
62
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
63
|
-
<InlinedScript
|
|
63
|
+
<InlinedScript
|
|
64
|
+
id="builderio-init-variants-fns"
|
|
65
|
+
scriptStr={getInitVariantsFnsScriptString()}
|
|
66
|
+
/>
|
|
64
67
|
{/if}
|
|
65
68
|
|
|
66
69
|
{#if shouldRenderVariants}
|
|
67
|
-
<InlinedStyles
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
<InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
|
|
71
|
+
<InlinedScript
|
|
72
|
+
id="builderio-variants-visibility"
|
|
73
|
+
scriptStr={updateCookieAndStylesScriptStr()}
|
|
70
74
|
/>
|
|
71
|
-
<InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
|
|
72
75
|
|
|
73
76
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
74
77
|
<ContentComponent
|
|
@@ -32,7 +32,7 @@ type VariantData = {
|
|
|
32
32
|
id: string;
|
|
33
33
|
testRatio?: number;
|
|
34
34
|
};
|
|
35
|
-
export declare const
|
|
35
|
+
export declare const getInitVariantsFnsScriptString: () => string;
|
|
36
36
|
export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
|
|
37
37
|
export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
|
|
38
38
|
variationId: string;
|
|
@@ -41,7 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
|
|
|
41
41
|
};
|
|
42
42
|
const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
|
|
43
43
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
44
|
-
export const
|
|
44
|
+
export const getInitVariantsFnsScriptString = () => `
|
|
45
45
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
46
46
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
47
47
|
`;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
interface Props {
|
|
3
3
|
scriptStr: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
declare const __propDef: {
|
|
7
7
|
props: {
|
|
8
8
|
scriptStr: Props["scriptStr"];
|
|
9
|
-
id
|
|
9
|
+
id: Props["id"];
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
12
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
interface Props {
|
|
3
3
|
styles: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
declare const __propDef: {
|
|
7
7
|
props: {
|
|
8
8
|
styles: Props["styles"];
|
|
9
|
-
id
|
|
9
|
+
id: Props["id"];
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
12
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.17";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.17";
|
|
@@ -129,7 +129,7 @@ let flexDir = stackColumnsAt === "never"
|
|
|
129
129
|
{...{}}
|
|
130
130
|
>
|
|
131
131
|
{#if TARGET !== "reactNative"}
|
|
132
|
-
<InlinedStyles styles={columnsStyles()} />
|
|
132
|
+
<InlinedStyles id="builderio-columns" styles={columnsStyles()} />
|
|
133
133
|
{/if}
|
|
134
134
|
{#each columns as column, index (index)}
|
|
135
135
|
<DynamicRenderer
|
|
@@ -122,41 +122,40 @@ function onClick(event) {
|
|
|
122
122
|
clicked = true;
|
|
123
123
|
}
|
|
124
124
|
}
|
|
125
|
-
function evalExpression(expression) {
|
|
126
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
|
|
127
|
-
code: group,
|
|
128
|
-
context: context || {},
|
|
129
|
-
localState: undefined,
|
|
130
|
-
rootState: $builderContextSignal.rootState,
|
|
131
|
-
rootSetState: $builderContextSignal.rootSetState,
|
|
132
|
-
enableCache: true,
|
|
133
|
-
})));
|
|
134
|
-
}
|
|
135
|
-
function handleRequest({ url, key }) {
|
|
136
|
-
fetch(url)
|
|
137
|
-
.then((response) => response.json())
|
|
138
|
-
.then((json) => {
|
|
139
|
-
const newState = {
|
|
140
|
-
...$builderContextSignal.rootState,
|
|
141
|
-
[key]: json,
|
|
142
|
-
};
|
|
143
|
-
$builderContextSignal.rootSetState?.(newState);
|
|
144
|
-
httpReqsData[key] = true;
|
|
145
|
-
})
|
|
146
|
-
.catch((err) => {
|
|
147
|
-
console.error("error fetching dynamic data", url, err);
|
|
148
|
-
});
|
|
149
|
-
}
|
|
150
125
|
function runHttpRequests() {
|
|
151
126
|
const requests = $builderContextSignal.content?.data?.httpRequests ?? {};
|
|
152
127
|
Object.entries(requests).forEach(([key, url]) => {
|
|
153
|
-
if (url
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
128
|
+
if (!url)
|
|
129
|
+
return;
|
|
130
|
+
// request already in progress
|
|
131
|
+
if (httpReqsPending[key])
|
|
132
|
+
return;
|
|
133
|
+
// request already completed, and not in edit mode
|
|
134
|
+
if (httpReqsData[key] && !isEditing())
|
|
135
|
+
return;
|
|
136
|
+
httpReqsPending[key] = true;
|
|
137
|
+
const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) => String(evaluate({
|
|
138
|
+
code: group,
|
|
139
|
+
context: context || {},
|
|
140
|
+
localState: undefined,
|
|
141
|
+
rootState: $builderContextSignal.rootState,
|
|
142
|
+
rootSetState: $builderContextSignal.rootSetState,
|
|
143
|
+
enableCache: true,
|
|
144
|
+
})));
|
|
145
|
+
fetch(evaluatedUrl)
|
|
146
|
+
.then((response) => response.json())
|
|
147
|
+
.then((json) => {
|
|
148
|
+
mergeNewRootState({
|
|
149
|
+
[key]: json,
|
|
158
150
|
});
|
|
159
|
-
|
|
151
|
+
httpReqsData[key] = true;
|
|
152
|
+
})
|
|
153
|
+
.catch((err) => {
|
|
154
|
+
console.error("error fetching dynamic data", url, err);
|
|
155
|
+
})
|
|
156
|
+
.finally(() => {
|
|
157
|
+
httpReqsPending[key] = false;
|
|
158
|
+
});
|
|
160
159
|
});
|
|
161
160
|
}
|
|
162
161
|
function emitStateUpdate() {
|
|
@@ -228,6 +227,7 @@ function elementRef_onInitpreviewingbldr(event) {
|
|
|
228
227
|
let elementRef;
|
|
229
228
|
let ContentWrapper = contentWrapper || "div";
|
|
230
229
|
let httpReqsData = {};
|
|
230
|
+
let httpReqsPending = {};
|
|
231
231
|
let clicked = false;
|
|
232
232
|
onMount(() => {
|
|
233
233
|
if (isBrowser()) {
|
|
@@ -7,7 +7,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack.js";
|
|
|
7
7
|
import ContentComponent from "../content/content.svelte";
|
|
8
8
|
import InlinedScript from "../inlined-script.svelte";
|
|
9
9
|
import InlinedStyles from "../inlined-styles.svelte";
|
|
10
|
-
import { checkShouldRenderVariants,
|
|
10
|
+
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers.js";
|
|
11
11
|
export let canTrack = undefined;
|
|
12
12
|
export let content = undefined;
|
|
13
13
|
export let isNestedRender = undefined;
|
|
@@ -60,15 +60,18 @@ onMount(() => {
|
|
|
60
60
|
</script>
|
|
61
61
|
|
|
62
62
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
63
|
-
<InlinedScript
|
|
63
|
+
<InlinedScript
|
|
64
|
+
id="builderio-init-variants-fns"
|
|
65
|
+
scriptStr={getInitVariantsFnsScriptString()}
|
|
66
|
+
/>
|
|
64
67
|
{/if}
|
|
65
68
|
|
|
66
69
|
{#if shouldRenderVariants}
|
|
67
|
-
<InlinedStyles
|
|
68
|
-
|
|
69
|
-
|
|
70
|
+
<InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
|
|
71
|
+
<InlinedScript
|
|
72
|
+
id="builderio-variants-visibility"
|
|
73
|
+
scriptStr={updateCookieAndStylesScriptStr()}
|
|
70
74
|
/>
|
|
71
|
-
<InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
|
|
72
75
|
|
|
73
76
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
74
77
|
<ContentComponent
|
|
@@ -32,7 +32,7 @@ type VariantData = {
|
|
|
32
32
|
id: string;
|
|
33
33
|
testRatio?: number;
|
|
34
34
|
};
|
|
35
|
-
export declare const
|
|
35
|
+
export declare const getInitVariantsFnsScriptString: () => string;
|
|
36
36
|
export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
|
|
37
37
|
export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
|
|
38
38
|
variationId: string;
|
|
@@ -41,7 +41,7 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
|
|
|
41
41
|
};
|
|
42
42
|
const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
|
|
43
43
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
44
|
-
export const
|
|
44
|
+
export const getInitVariantsFnsScriptString = () => `
|
|
45
45
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
46
46
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
47
47
|
`;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
interface Props {
|
|
3
3
|
scriptStr: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
declare const __propDef: {
|
|
7
7
|
props: {
|
|
8
8
|
scriptStr: Props["scriptStr"];
|
|
9
|
-
id
|
|
9
|
+
id: Props["id"];
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
12
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
interface Props {
|
|
3
3
|
styles: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
declare const __propDef: {
|
|
7
7
|
props: {
|
|
8
8
|
styles: Props["styles"];
|
|
9
|
-
id
|
|
9
|
+
id: Props["id"];
|
|
10
10
|
};
|
|
11
11
|
events: {
|
|
12
12
|
[evt: string]: CustomEvent<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "1.0.
|
|
1
|
+
export declare const SDK_VERSION = "1.0.17";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.17";
|
package/package.json
CHANGED
|
@@ -154,47 +154,45 @@
|
|
|
154
154
|
clicked = true;
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
|
-
function evalExpression(expression: string) {
|
|
158
|
-
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
159
|
-
String(
|
|
160
|
-
evaluate({
|
|
161
|
-
code: group,
|
|
162
|
-
context: context || {},
|
|
163
|
-
localState: undefined,
|
|
164
|
-
rootState: $builderContextSignal.rootState,
|
|
165
|
-
rootSetState: $builderContextSignal.rootSetState,
|
|
166
|
-
enableCache: true,
|
|
167
|
-
})
|
|
168
|
-
)
|
|
169
|
-
);
|
|
170
|
-
}
|
|
171
|
-
function handleRequest({ url, key }: { key: string; url: string }) {
|
|
172
|
-
fetch(url)
|
|
173
|
-
.then((response) => response.json())
|
|
174
|
-
.then((json) => {
|
|
175
|
-
const newState = {
|
|
176
|
-
...$builderContextSignal.rootState,
|
|
177
|
-
[key]: json,
|
|
178
|
-
};
|
|
179
|
-
$builderContextSignal.rootSetState?.(newState);
|
|
180
|
-
httpReqsData[key] = true;
|
|
181
|
-
})
|
|
182
|
-
.catch((err) => {
|
|
183
|
-
console.error("error fetching dynamic data", url, err);
|
|
184
|
-
});
|
|
185
|
-
}
|
|
186
157
|
function runHttpRequests() {
|
|
187
158
|
const requests: {
|
|
188
159
|
[key: string]: string;
|
|
189
160
|
} = $builderContextSignal.content?.data?.httpRequests ?? {};
|
|
190
161
|
Object.entries(requests).forEach(([key, url]) => {
|
|
191
|
-
if (url
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
162
|
+
if (!url) return;
|
|
163
|
+
|
|
164
|
+
// request already in progress
|
|
165
|
+
if (httpReqsPending[key]) return;
|
|
166
|
+
|
|
167
|
+
// request already completed, and not in edit mode
|
|
168
|
+
if (httpReqsData[key] && !isEditing()) return;
|
|
169
|
+
httpReqsPending[key] = true;
|
|
170
|
+
const evaluatedUrl = url.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
171
|
+
String(
|
|
172
|
+
evaluate({
|
|
173
|
+
code: group,
|
|
174
|
+
context: context || {},
|
|
175
|
+
localState: undefined,
|
|
176
|
+
rootState: $builderContextSignal.rootState,
|
|
177
|
+
rootSetState: $builderContextSignal.rootSetState,
|
|
178
|
+
enableCache: true,
|
|
179
|
+
})
|
|
180
|
+
)
|
|
181
|
+
);
|
|
182
|
+
fetch(evaluatedUrl)
|
|
183
|
+
.then((response) => response.json())
|
|
184
|
+
.then((json) => {
|
|
185
|
+
mergeNewRootState({
|
|
186
|
+
[key]: json,
|
|
187
|
+
});
|
|
188
|
+
httpReqsData[key] = true;
|
|
189
|
+
})
|
|
190
|
+
.catch((err) => {
|
|
191
|
+
console.error("error fetching dynamic data", url, err);
|
|
192
|
+
})
|
|
193
|
+
.finally(() => {
|
|
194
|
+
httpReqsPending[key] = false;
|
|
196
195
|
});
|
|
197
|
-
}
|
|
198
196
|
});
|
|
199
197
|
}
|
|
200
198
|
function emitStateUpdate() {
|
|
@@ -284,6 +282,7 @@
|
|
|
284
282
|
|
|
285
283
|
let ContentWrapper = contentWrapper || "div";
|
|
286
284
|
let httpReqsData = {};
|
|
285
|
+
let httpReqsPending = {};
|
|
287
286
|
let clicked = false;
|
|
288
287
|
|
|
289
288
|
onMount(() => {
|
|
@@ -19,7 +19,7 @@
|
|
|
19
19
|
import type { ContentVariantsPrps } from "./content-variants.types.js";
|
|
20
20
|
import {
|
|
21
21
|
checkShouldRenderVariants,
|
|
22
|
-
|
|
22
|
+
getInitVariantsFnsScriptString,
|
|
23
23
|
getUpdateCookieAndStylesScript,
|
|
24
24
|
getVariants,
|
|
25
25
|
} from "./helpers.js";
|
|
@@ -87,15 +87,18 @@
|
|
|
87
87
|
</script>
|
|
88
88
|
|
|
89
89
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
90
|
-
<InlinedScript
|
|
90
|
+
<InlinedScript
|
|
91
|
+
id="builderio-init-variants-fns"
|
|
92
|
+
scriptStr={getInitVariantsFnsScriptString()}
|
|
93
|
+
/>
|
|
91
94
|
{/if}
|
|
92
95
|
|
|
93
96
|
{#if shouldRenderVariants}
|
|
94
|
-
<InlinedStyles
|
|
95
|
-
|
|
96
|
-
|
|
97
|
+
<InlinedStyles id="builderio-variants" styles={hideVariantsStyleString()} />
|
|
98
|
+
<InlinedScript
|
|
99
|
+
id="builderio-variants-visibility"
|
|
100
|
+
scriptStr={updateCookieAndStylesScriptStr()}
|
|
97
101
|
/>
|
|
98
|
-
<InlinedScript scriptStr={updateCookieAndStylesScriptStr()} />
|
|
99
102
|
|
|
100
103
|
{#each getVariants(content) as variant (variant.testVariationId)}
|
|
101
104
|
<ContentComponent
|
|
@@ -52,7 +52,7 @@ type VariantData = {
|
|
|
52
52
|
};
|
|
53
53
|
const getIsHydrationTarget = (target: Target) => target === 'react' || target === 'reactNative';
|
|
54
54
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
55
|
-
export const
|
|
55
|
+
export const getInitVariantsFnsScriptString = () => `
|
|
56
56
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
57
57
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
58
58
|
`;
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
2
|
interface Props {
|
|
3
3
|
scriptStr: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script lang="ts">
|
|
9
9
|
export let scriptStr: Props["scriptStr"];
|
|
10
|
-
export let id: Props["id"]
|
|
10
|
+
export let id: Props["id"];
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
|
-
{@html `<script id=${id
|
|
13
|
+
{@html `<script data-id=${id}>${scriptStr}</script>`}
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
<script context="module" lang="ts">
|
|
2
2
|
interface Props {
|
|
3
3
|
styles: string;
|
|
4
|
-
id
|
|
4
|
+
id: string;
|
|
5
5
|
}
|
|
6
6
|
</script>
|
|
7
7
|
|
|
8
8
|
<script lang="ts">
|
|
9
9
|
export let styles: Props["styles"];
|
|
10
|
-
export let id: Props["id"]
|
|
10
|
+
export let id: Props["id"];
|
|
11
11
|
</script>
|
|
12
12
|
|
|
13
|
-
{@html `<${"style"} id=${id} >${styles}<${"/style"}>`}
|
|
13
|
+
{@html `<${"style"} data-id=${id} >${styles}<${"/style"}>`}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "1.0.
|
|
1
|
+
export const SDK_VERSION = "1.0.17"
|