@builder.io/sdk-svelte 5.1.1 → 5.2.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/symbol/symbol.helpers.d.ts +2 -0
- package/lib/browser/blocks/symbol/symbol.helpers.js +1 -1
- package/lib/browser/blocks/symbol/symbol.svelte +3 -1
- package/lib/browser/blocks/symbol/symbol.types.d.ts +2 -0
- package/lib/browser/components/block/components/component-ref/component-ref.svelte +8 -7
- package/lib/browser/components/block/components/component-ref/component-ref.svelte.d.ts +1 -1
- package/lib/browser/components/content-variants/content-variants.svelte +15 -9
- package/lib/browser/components/content-variants/helpers.d.ts +1 -0
- package/lib/browser/components/content-variants/helpers.js +31 -0
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/edge/blocks/symbol/symbol.helpers.d.ts +2 -0
- package/lib/edge/blocks/symbol/symbol.helpers.js +1 -1
- package/lib/edge/blocks/symbol/symbol.svelte +3 -1
- package/lib/edge/blocks/symbol/symbol.types.d.ts +2 -0
- package/lib/edge/components/block/components/component-ref/component-ref.svelte +8 -7
- package/lib/edge/components/block/components/component-ref/component-ref.svelte.d.ts +1 -1
- package/lib/edge/components/content-variants/content-variants.svelte +15 -9
- package/lib/edge/components/content-variants/helpers.d.ts +1 -0
- package/lib/edge/components/content-variants/helpers.js +31 -0
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/node/blocks/symbol/symbol.helpers.d.ts +2 -0
- package/lib/node/blocks/symbol/symbol.helpers.js +1 -1
- package/lib/node/blocks/symbol/symbol.svelte +3 -1
- package/lib/node/blocks/symbol/symbol.types.d.ts +2 -0
- package/lib/node/components/block/components/component-ref/component-ref.svelte +8 -7
- package/lib/node/components/block/components/component-ref/component-ref.svelte.d.ts +1 -1
- package/lib/node/components/content-variants/content-variants.svelte +15 -9
- package/lib/node/components/content-variants/helpers.d.ts +1 -0
- package/lib/node/components/content-variants/helpers.js +31 -0
- 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/symbol/symbol.helpers.ts +3 -1
- package/src/blocks/symbol/symbol.svelte +3 -1
- package/src/blocks/symbol/symbol.types.ts +2 -0
- package/src/components/block/components/component-ref/component-ref.svelte +9 -7
- package/src/components/content-variants/content-variants.svelte +15 -8
- package/src/components/content-variants/helpers.ts +31 -0
- package/src/constants/sdk-version.ts +1 -1
|
@@ -15,7 +15,7 @@ export const fetchSymbolContent = async ({ builderContextValue, symbol }) => {
|
|
|
15
15
|
builderContextValue?.apiKey) {
|
|
16
16
|
return fetchOneEntry({
|
|
17
17
|
model: symbol.model,
|
|
18
|
-
apiKey: builderContextValue.apiKey,
|
|
18
|
+
apiKey: symbol.global && symbol.ownerId ? symbol.ownerId : builderContextValue.apiKey,
|
|
19
19
|
apiVersion: builderContextValue.apiVersion,
|
|
20
20
|
...(symbol?.entry && {
|
|
21
21
|
query: {
|
|
@@ -65,7 +65,9 @@ $: onUpdateFn_0(...[symbol]);
|
|
|
65
65
|
nonce={$builderContext.nonce}
|
|
66
66
|
isNestedRender={true}
|
|
67
67
|
apiVersion={$builderContext.apiVersion}
|
|
68
|
-
apiKey={
|
|
68
|
+
apiKey={symbol?.global && symbol?.ownerId
|
|
69
|
+
? symbol.ownerId
|
|
70
|
+
: $builderContext.apiKey}
|
|
69
71
|
context={{
|
|
70
72
|
...$builderContext.context,
|
|
71
73
|
symbolId: builderBlock?.id,
|
|
@@ -7,6 +7,8 @@ export interface SymbolInfo {
|
|
|
7
7
|
content?: BuilderContent;
|
|
8
8
|
inline?: boolean;
|
|
9
9
|
dynamic?: boolean;
|
|
10
|
+
ownerId?: string;
|
|
11
|
+
global?: boolean;
|
|
10
12
|
}
|
|
11
13
|
export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp {
|
|
12
14
|
symbol?: SymbolInfo;
|
|
@@ -4,13 +4,16 @@ import InteractiveElement from "../interactive-element.svelte";
|
|
|
4
4
|
import { getWrapperProps } from "./component-ref.helpers";
|
|
5
5
|
export let isInteractive;
|
|
6
6
|
export let componentRef;
|
|
7
|
+
export let blockChildren;
|
|
7
8
|
export let componentOptions;
|
|
8
9
|
export let builderBlock;
|
|
9
10
|
export let context;
|
|
10
11
|
export let linkComponent;
|
|
11
12
|
export let includeBlockProps;
|
|
12
|
-
export let blockChildren;
|
|
13
13
|
export let registeredComponents;
|
|
14
|
+
$: blockChildrenToRender = () => {
|
|
15
|
+
return componentRef ? blockChildren : [];
|
|
16
|
+
};
|
|
14
17
|
let shouldUpdate = false;
|
|
15
18
|
let Wrapper = isInteractive ? InteractiveElement : componentRef;
|
|
16
19
|
</script>
|
|
@@ -29,10 +32,8 @@ let Wrapper = isInteractive ? InteractiveElement : componentRef;
|
|
|
29
32
|
contextValue: $context,
|
|
30
33
|
})}
|
|
31
34
|
>
|
|
32
|
-
{#
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{/if}</svelte:component
|
|
37
|
-
>
|
|
35
|
+
{#each blockChildrenToRender() as child (child.id)}
|
|
36
|
+
<Block block={child} {context} {registeredComponents} {linkComponent} />
|
|
37
|
+
{/each}
|
|
38
|
+
</svelte:component>
|
|
38
39
|
{/if}
|
|
@@ -4,12 +4,12 @@ declare const __propDef: {
|
|
|
4
4
|
props: {
|
|
5
5
|
isInteractive: ComponentProps["isInteractive"];
|
|
6
6
|
componentRef: ComponentProps["componentRef"];
|
|
7
|
+
blockChildren: ComponentProps["blockChildren"];
|
|
7
8
|
componentOptions: ComponentProps["componentOptions"];
|
|
8
9
|
builderBlock: ComponentProps["builderBlock"];
|
|
9
10
|
context: ComponentProps["context"];
|
|
10
11
|
linkComponent: ComponentProps["linkComponent"];
|
|
11
12
|
includeBlockProps: ComponentProps["includeBlockProps"];
|
|
12
|
-
blockChildren: ComponentProps["blockChildren"];
|
|
13
13
|
registeredComponents: ComponentProps["registeredComponents"];
|
|
14
14
|
};
|
|
15
15
|
events: {
|
|
@@ -8,7 +8,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
|
8
8
|
import ContentComponent from "../content/content.svelte";
|
|
9
9
|
import InlinedScript from "../inlined-script.svelte";
|
|
10
10
|
import InlinedStyles from "../inlined-styles.svelte";
|
|
11
|
-
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers";
|
|
11
|
+
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, removeDuplicateScript, } from "./helpers";
|
|
12
12
|
export let canTrack = undefined;
|
|
13
13
|
export let content;
|
|
14
14
|
export let isNestedRender = undefined;
|
|
@@ -65,17 +65,23 @@ onMount(() => {
|
|
|
65
65
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
66
66
|
<InlinedScript
|
|
67
67
|
id="builderio-init-variants-fns"
|
|
68
|
-
scriptStr={
|
|
68
|
+
scriptStr={removeDuplicateScript(
|
|
69
|
+
"builderio-init-variants-fns",
|
|
70
|
+
getInitVariantsFnsScriptString()
|
|
71
|
+
)}
|
|
69
72
|
nonce={nonce || ""}
|
|
70
73
|
/>
|
|
74
|
+
{/if}
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
{#if !isNestedRender && TARGET !== "reactNative" && SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}
|
|
77
|
+
<InlinedScript
|
|
78
|
+
id="builderio-init-personalization-variants-fns"
|
|
79
|
+
nonce={nonce || ""}
|
|
80
|
+
scriptStr={removeDuplicateScript(
|
|
81
|
+
"builderio-init-personalization-variants-fns",
|
|
82
|
+
getInitPersonalizationVariantsFnsScriptString()
|
|
83
|
+
)}
|
|
84
|
+
/>
|
|
79
85
|
{/if}
|
|
80
86
|
|
|
81
87
|
{#if shouldRenderVariants}
|
|
@@ -32,6 +32,7 @@ type VariantData = {
|
|
|
32
32
|
id: string;
|
|
33
33
|
testRatio?: number;
|
|
34
34
|
};
|
|
35
|
+
export declare const removeDuplicateScript: (id: string, scriptStr: string) => string;
|
|
35
36
|
export declare const getInitVariantsFnsScriptString: () => string;
|
|
36
37
|
export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
|
|
37
38
|
export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
|
|
@@ -43,6 +43,37 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
|
|
|
43
43
|
const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
|
|
44
44
|
const isAngularSDK = TARGET === 'angular';
|
|
45
45
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
46
|
+
export const removeDuplicateScript = (id, scriptStr) => `
|
|
47
|
+
(function() {
|
|
48
|
+
var selector = 'script[data-id="${id}"]';
|
|
49
|
+
var scriptKey = '__builderioScriptInitialized_${id}';
|
|
50
|
+
var observerKey = '__builderioScriptObserver_${id}';
|
|
51
|
+
|
|
52
|
+
// Synchronously remove any duplicates already in the DOM
|
|
53
|
+
var existing = document.querySelectorAll(selector);
|
|
54
|
+
existing.forEach(function(script, index) {
|
|
55
|
+
if (index > 0) {
|
|
56
|
+
script.parentNode && script.parentNode.removeChild(script);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Watch for duplicates added later (e.g. RSC streaming chunks)
|
|
61
|
+
if (!window[observerKey] && typeof MutationObserver !== 'undefined') {
|
|
62
|
+
window[observerKey] = new MutationObserver(function() {
|
|
63
|
+
var all = document.querySelectorAll(selector);
|
|
64
|
+
for (var i = 1; i < all.length; i++) {
|
|
65
|
+
all[i].parentNode && all[i].parentNode.removeChild(all[i]);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
window[observerKey].observe(document.documentElement, { childList: true, subtree: true });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!window[scriptKey]) {
|
|
72
|
+
window[scriptKey] = true;
|
|
73
|
+
${scriptStr}
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
`;
|
|
46
77
|
export const getInitVariantsFnsScriptString = () => `
|
|
47
78
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
48
79
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "5.
|
|
1
|
+
export declare const SDK_VERSION = "5.2.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "5.
|
|
1
|
+
export const SDK_VERSION = "5.2.2";
|
|
@@ -15,7 +15,7 @@ export const fetchSymbolContent = async ({ builderContextValue, symbol }) => {
|
|
|
15
15
|
builderContextValue?.apiKey) {
|
|
16
16
|
return fetchOneEntry({
|
|
17
17
|
model: symbol.model,
|
|
18
|
-
apiKey: builderContextValue.apiKey,
|
|
18
|
+
apiKey: symbol.global && symbol.ownerId ? symbol.ownerId : builderContextValue.apiKey,
|
|
19
19
|
apiVersion: builderContextValue.apiVersion,
|
|
20
20
|
...(symbol?.entry && {
|
|
21
21
|
query: {
|
|
@@ -65,7 +65,9 @@ $: onUpdateFn_0(...[symbol]);
|
|
|
65
65
|
nonce={$builderContext.nonce}
|
|
66
66
|
isNestedRender={true}
|
|
67
67
|
apiVersion={$builderContext.apiVersion}
|
|
68
|
-
apiKey={
|
|
68
|
+
apiKey={symbol?.global && symbol?.ownerId
|
|
69
|
+
? symbol.ownerId
|
|
70
|
+
: $builderContext.apiKey}
|
|
69
71
|
context={{
|
|
70
72
|
...$builderContext.context,
|
|
71
73
|
symbolId: builderBlock?.id,
|
|
@@ -7,6 +7,8 @@ export interface SymbolInfo {
|
|
|
7
7
|
content?: BuilderContent;
|
|
8
8
|
inline?: boolean;
|
|
9
9
|
dynamic?: boolean;
|
|
10
|
+
ownerId?: string;
|
|
11
|
+
global?: boolean;
|
|
10
12
|
}
|
|
11
13
|
export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp {
|
|
12
14
|
symbol?: SymbolInfo;
|
|
@@ -4,13 +4,16 @@ import InteractiveElement from "../interactive-element.svelte";
|
|
|
4
4
|
import { getWrapperProps } from "./component-ref.helpers";
|
|
5
5
|
export let isInteractive;
|
|
6
6
|
export let componentRef;
|
|
7
|
+
export let blockChildren;
|
|
7
8
|
export let componentOptions;
|
|
8
9
|
export let builderBlock;
|
|
9
10
|
export let context;
|
|
10
11
|
export let linkComponent;
|
|
11
12
|
export let includeBlockProps;
|
|
12
|
-
export let blockChildren;
|
|
13
13
|
export let registeredComponents;
|
|
14
|
+
$: blockChildrenToRender = () => {
|
|
15
|
+
return componentRef ? blockChildren : [];
|
|
16
|
+
};
|
|
14
17
|
let shouldUpdate = false;
|
|
15
18
|
let Wrapper = isInteractive ? InteractiveElement : componentRef;
|
|
16
19
|
</script>
|
|
@@ -29,10 +32,8 @@ let Wrapper = isInteractive ? InteractiveElement : componentRef;
|
|
|
29
32
|
contextValue: $context,
|
|
30
33
|
})}
|
|
31
34
|
>
|
|
32
|
-
{#
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{/if}</svelte:component
|
|
37
|
-
>
|
|
35
|
+
{#each blockChildrenToRender() as child (child.id)}
|
|
36
|
+
<Block block={child} {context} {registeredComponents} {linkComponent} />
|
|
37
|
+
{/each}
|
|
38
|
+
</svelte:component>
|
|
38
39
|
{/if}
|
|
@@ -4,12 +4,12 @@ declare const __propDef: {
|
|
|
4
4
|
props: {
|
|
5
5
|
isInteractive: ComponentProps["isInteractive"];
|
|
6
6
|
componentRef: ComponentProps["componentRef"];
|
|
7
|
+
blockChildren: ComponentProps["blockChildren"];
|
|
7
8
|
componentOptions: ComponentProps["componentOptions"];
|
|
8
9
|
builderBlock: ComponentProps["builderBlock"];
|
|
9
10
|
context: ComponentProps["context"];
|
|
10
11
|
linkComponent: ComponentProps["linkComponent"];
|
|
11
12
|
includeBlockProps: ComponentProps["includeBlockProps"];
|
|
12
|
-
blockChildren: ComponentProps["blockChildren"];
|
|
13
13
|
registeredComponents: ComponentProps["registeredComponents"];
|
|
14
14
|
};
|
|
15
15
|
events: {
|
|
@@ -8,7 +8,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
|
8
8
|
import ContentComponent from "../content/content.svelte";
|
|
9
9
|
import InlinedScript from "../inlined-script.svelte";
|
|
10
10
|
import InlinedStyles from "../inlined-styles.svelte";
|
|
11
|
-
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers";
|
|
11
|
+
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, removeDuplicateScript, } from "./helpers";
|
|
12
12
|
export let canTrack = undefined;
|
|
13
13
|
export let content;
|
|
14
14
|
export let isNestedRender = undefined;
|
|
@@ -65,17 +65,23 @@ onMount(() => {
|
|
|
65
65
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
66
66
|
<InlinedScript
|
|
67
67
|
id="builderio-init-variants-fns"
|
|
68
|
-
scriptStr={
|
|
68
|
+
scriptStr={removeDuplicateScript(
|
|
69
|
+
"builderio-init-variants-fns",
|
|
70
|
+
getInitVariantsFnsScriptString()
|
|
71
|
+
)}
|
|
69
72
|
nonce={nonce || ""}
|
|
70
73
|
/>
|
|
74
|
+
{/if}
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
{#if !isNestedRender && TARGET !== "reactNative" && SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}
|
|
77
|
+
<InlinedScript
|
|
78
|
+
id="builderio-init-personalization-variants-fns"
|
|
79
|
+
nonce={nonce || ""}
|
|
80
|
+
scriptStr={removeDuplicateScript(
|
|
81
|
+
"builderio-init-personalization-variants-fns",
|
|
82
|
+
getInitPersonalizationVariantsFnsScriptString()
|
|
83
|
+
)}
|
|
84
|
+
/>
|
|
79
85
|
{/if}
|
|
80
86
|
|
|
81
87
|
{#if shouldRenderVariants}
|
|
@@ -32,6 +32,7 @@ type VariantData = {
|
|
|
32
32
|
id: string;
|
|
33
33
|
testRatio?: number;
|
|
34
34
|
};
|
|
35
|
+
export declare const removeDuplicateScript: (id: string, scriptStr: string) => string;
|
|
35
36
|
export declare const getInitVariantsFnsScriptString: () => string;
|
|
36
37
|
export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
|
|
37
38
|
export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
|
|
@@ -43,6 +43,37 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
|
|
|
43
43
|
const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
|
|
44
44
|
const isAngularSDK = TARGET === 'angular';
|
|
45
45
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
46
|
+
export const removeDuplicateScript = (id, scriptStr) => `
|
|
47
|
+
(function() {
|
|
48
|
+
var selector = 'script[data-id="${id}"]';
|
|
49
|
+
var scriptKey = '__builderioScriptInitialized_${id}';
|
|
50
|
+
var observerKey = '__builderioScriptObserver_${id}';
|
|
51
|
+
|
|
52
|
+
// Synchronously remove any duplicates already in the DOM
|
|
53
|
+
var existing = document.querySelectorAll(selector);
|
|
54
|
+
existing.forEach(function(script, index) {
|
|
55
|
+
if (index > 0) {
|
|
56
|
+
script.parentNode && script.parentNode.removeChild(script);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Watch for duplicates added later (e.g. RSC streaming chunks)
|
|
61
|
+
if (!window[observerKey] && typeof MutationObserver !== 'undefined') {
|
|
62
|
+
window[observerKey] = new MutationObserver(function() {
|
|
63
|
+
var all = document.querySelectorAll(selector);
|
|
64
|
+
for (var i = 1; i < all.length; i++) {
|
|
65
|
+
all[i].parentNode && all[i].parentNode.removeChild(all[i]);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
window[observerKey].observe(document.documentElement, { childList: true, subtree: true });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!window[scriptKey]) {
|
|
72
|
+
window[scriptKey] = true;
|
|
73
|
+
${scriptStr}
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
`;
|
|
46
77
|
export const getInitVariantsFnsScriptString = () => `
|
|
47
78
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
48
79
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "5.
|
|
1
|
+
export declare const SDK_VERSION = "5.2.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "5.
|
|
1
|
+
export const SDK_VERSION = "5.2.2";
|
|
@@ -15,7 +15,7 @@ export const fetchSymbolContent = async ({ builderContextValue, symbol }) => {
|
|
|
15
15
|
builderContextValue?.apiKey) {
|
|
16
16
|
return fetchOneEntry({
|
|
17
17
|
model: symbol.model,
|
|
18
|
-
apiKey: builderContextValue.apiKey,
|
|
18
|
+
apiKey: symbol.global && symbol.ownerId ? symbol.ownerId : builderContextValue.apiKey,
|
|
19
19
|
apiVersion: builderContextValue.apiVersion,
|
|
20
20
|
...(symbol?.entry && {
|
|
21
21
|
query: {
|
|
@@ -65,7 +65,9 @@ $: onUpdateFn_0(...[symbol]);
|
|
|
65
65
|
nonce={$builderContext.nonce}
|
|
66
66
|
isNestedRender={true}
|
|
67
67
|
apiVersion={$builderContext.apiVersion}
|
|
68
|
-
apiKey={
|
|
68
|
+
apiKey={symbol?.global && symbol?.ownerId
|
|
69
|
+
? symbol.ownerId
|
|
70
|
+
: $builderContext.apiKey}
|
|
69
71
|
context={{
|
|
70
72
|
...$builderContext.context,
|
|
71
73
|
symbolId: builderBlock?.id,
|
|
@@ -7,6 +7,8 @@ export interface SymbolInfo {
|
|
|
7
7
|
content?: BuilderContent;
|
|
8
8
|
inline?: boolean;
|
|
9
9
|
dynamic?: boolean;
|
|
10
|
+
ownerId?: string;
|
|
11
|
+
global?: boolean;
|
|
10
12
|
}
|
|
11
13
|
export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp {
|
|
12
14
|
symbol?: SymbolInfo;
|
|
@@ -4,13 +4,16 @@ import InteractiveElement from "../interactive-element.svelte";
|
|
|
4
4
|
import { getWrapperProps } from "./component-ref.helpers";
|
|
5
5
|
export let isInteractive;
|
|
6
6
|
export let componentRef;
|
|
7
|
+
export let blockChildren;
|
|
7
8
|
export let componentOptions;
|
|
8
9
|
export let builderBlock;
|
|
9
10
|
export let context;
|
|
10
11
|
export let linkComponent;
|
|
11
12
|
export let includeBlockProps;
|
|
12
|
-
export let blockChildren;
|
|
13
13
|
export let registeredComponents;
|
|
14
|
+
$: blockChildrenToRender = () => {
|
|
15
|
+
return componentRef ? blockChildren : [];
|
|
16
|
+
};
|
|
14
17
|
let shouldUpdate = false;
|
|
15
18
|
let Wrapper = isInteractive ? InteractiveElement : componentRef;
|
|
16
19
|
</script>
|
|
@@ -29,10 +32,8 @@ let Wrapper = isInteractive ? InteractiveElement : componentRef;
|
|
|
29
32
|
contextValue: $context,
|
|
30
33
|
})}
|
|
31
34
|
>
|
|
32
|
-
{#
|
|
33
|
-
{
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
{/if}</svelte:component
|
|
37
|
-
>
|
|
35
|
+
{#each blockChildrenToRender() as child (child.id)}
|
|
36
|
+
<Block block={child} {context} {registeredComponents} {linkComponent} />
|
|
37
|
+
{/each}
|
|
38
|
+
</svelte:component>
|
|
38
39
|
{/if}
|
|
@@ -4,12 +4,12 @@ declare const __propDef: {
|
|
|
4
4
|
props: {
|
|
5
5
|
isInteractive: ComponentProps["isInteractive"];
|
|
6
6
|
componentRef: ComponentProps["componentRef"];
|
|
7
|
+
blockChildren: ComponentProps["blockChildren"];
|
|
7
8
|
componentOptions: ComponentProps["componentOptions"];
|
|
8
9
|
builderBlock: ComponentProps["builderBlock"];
|
|
9
10
|
context: ComponentProps["context"];
|
|
10
11
|
linkComponent: ComponentProps["linkComponent"];
|
|
11
12
|
includeBlockProps: ComponentProps["includeBlockProps"];
|
|
12
|
-
blockChildren: ComponentProps["blockChildren"];
|
|
13
13
|
registeredComponents: ComponentProps["registeredComponents"];
|
|
14
14
|
};
|
|
15
15
|
events: {
|
|
@@ -8,7 +8,7 @@ import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
|
8
8
|
import ContentComponent from "../content/content.svelte";
|
|
9
9
|
import InlinedScript from "../inlined-script.svelte";
|
|
10
10
|
import InlinedStyles from "../inlined-styles.svelte";
|
|
11
|
-
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, } from "./helpers";
|
|
11
|
+
import { checkShouldRenderVariants, getInitVariantsFnsScriptString, getUpdateCookieAndStylesScript, getVariants, removeDuplicateScript, } from "./helpers";
|
|
12
12
|
export let canTrack = undefined;
|
|
13
13
|
export let content;
|
|
14
14
|
export let isNestedRender = undefined;
|
|
@@ -65,17 +65,23 @@ onMount(() => {
|
|
|
65
65
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
66
66
|
<InlinedScript
|
|
67
67
|
id="builderio-init-variants-fns"
|
|
68
|
-
scriptStr={
|
|
68
|
+
scriptStr={removeDuplicateScript(
|
|
69
|
+
"builderio-init-variants-fns",
|
|
70
|
+
getInitVariantsFnsScriptString()
|
|
71
|
+
)}
|
|
69
72
|
nonce={nonce || ""}
|
|
70
73
|
/>
|
|
74
|
+
{/if}
|
|
71
75
|
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
76
|
+
{#if !isNestedRender && TARGET !== "reactNative" && SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}
|
|
77
|
+
<InlinedScript
|
|
78
|
+
id="builderio-init-personalization-variants-fns"
|
|
79
|
+
nonce={nonce || ""}
|
|
80
|
+
scriptStr={removeDuplicateScript(
|
|
81
|
+
"builderio-init-personalization-variants-fns",
|
|
82
|
+
getInitPersonalizationVariantsFnsScriptString()
|
|
83
|
+
)}
|
|
84
|
+
/>
|
|
79
85
|
{/if}
|
|
80
86
|
|
|
81
87
|
{#if shouldRenderVariants}
|
|
@@ -32,6 +32,7 @@ type VariantData = {
|
|
|
32
32
|
id: string;
|
|
33
33
|
testRatio?: number;
|
|
34
34
|
};
|
|
35
|
+
export declare const removeDuplicateScript: (id: string, scriptStr: string) => string;
|
|
35
36
|
export declare const getInitVariantsFnsScriptString: () => string;
|
|
36
37
|
export declare const getUpdateCookieAndStylesScript: (variants: VariantData[], contentId: string) => string;
|
|
37
38
|
export declare const getUpdateVariantVisibilityScript: ({ contentId, variationId }: {
|
|
@@ -43,6 +43,37 @@ export const checkShouldRenderVariants = ({ canTrack, content }) => {
|
|
|
43
43
|
const getIsHydrationTarget = (target) => target === 'react' || target === 'reactNative';
|
|
44
44
|
const isAngularSDK = TARGET === 'angular';
|
|
45
45
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
46
|
+
export const removeDuplicateScript = (id, scriptStr) => `
|
|
47
|
+
(function() {
|
|
48
|
+
var selector = 'script[data-id="${id}"]';
|
|
49
|
+
var scriptKey = '__builderioScriptInitialized_${id}';
|
|
50
|
+
var observerKey = '__builderioScriptObserver_${id}';
|
|
51
|
+
|
|
52
|
+
// Synchronously remove any duplicates already in the DOM
|
|
53
|
+
var existing = document.querySelectorAll(selector);
|
|
54
|
+
existing.forEach(function(script, index) {
|
|
55
|
+
if (index > 0) {
|
|
56
|
+
script.parentNode && script.parentNode.removeChild(script);
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
// Watch for duplicates added later (e.g. RSC streaming chunks)
|
|
61
|
+
if (!window[observerKey] && typeof MutationObserver !== 'undefined') {
|
|
62
|
+
window[observerKey] = new MutationObserver(function() {
|
|
63
|
+
var all = document.querySelectorAll(selector);
|
|
64
|
+
for (var i = 1; i < all.length; i++) {
|
|
65
|
+
all[i].parentNode && all[i].parentNode.removeChild(all[i]);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
window[observerKey].observe(document.documentElement, { childList: true, subtree: true });
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
if (!window[scriptKey]) {
|
|
72
|
+
window[scriptKey] = true;
|
|
73
|
+
${scriptStr}
|
|
74
|
+
}
|
|
75
|
+
})();
|
|
76
|
+
`;
|
|
46
77
|
export const getInitVariantsFnsScriptString = () => `
|
|
47
78
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
48
79
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "5.
|
|
1
|
+
export declare const SDK_VERSION = "5.2.2";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "5.
|
|
1
|
+
export const SDK_VERSION = "5.2.2";
|
package/package.json
CHANGED
|
@@ -9,6 +9,8 @@ export interface SymbolInfo {
|
|
|
9
9
|
content?: BuilderContent;
|
|
10
10
|
inline?: boolean;
|
|
11
11
|
dynamic?: boolean;
|
|
12
|
+
ownerId?: string;
|
|
13
|
+
global?: boolean;
|
|
12
14
|
}
|
|
13
15
|
export const fetchSymbolContent = async ({
|
|
14
16
|
builderContextValue,
|
|
@@ -31,7 +33,7 @@ export const fetchSymbolContent = async ({
|
|
|
31
33
|
builderContextValue?.apiKey) {
|
|
32
34
|
return fetchOneEntry({
|
|
33
35
|
model: symbol.model,
|
|
34
|
-
apiKey: builderContextValue.apiKey,
|
|
36
|
+
apiKey: symbol.global && symbol.ownerId ? symbol.ownerId : builderContextValue.apiKey,
|
|
35
37
|
apiVersion: builderContextValue.apiVersion,
|
|
36
38
|
...(symbol?.entry && {
|
|
37
39
|
query: {
|
|
@@ -76,7 +76,9 @@
|
|
|
76
76
|
nonce={$builderContext.nonce}
|
|
77
77
|
isNestedRender={true}
|
|
78
78
|
apiVersion={$builderContext.apiVersion}
|
|
79
|
-
apiKey={
|
|
79
|
+
apiKey={symbol?.global && symbol?.ownerId
|
|
80
|
+
? symbol.ownerId
|
|
81
|
+
: $builderContext.apiKey}
|
|
80
82
|
context={{
|
|
81
83
|
...$builderContext.context,
|
|
82
84
|
symbolId: builderBlock?.id,
|
|
@@ -7,6 +7,8 @@ export interface SymbolInfo {
|
|
|
7
7
|
content?: BuilderContent;
|
|
8
8
|
inline?: boolean;
|
|
9
9
|
dynamic?: boolean;
|
|
10
|
+
ownerId?: string;
|
|
11
|
+
global?: boolean;
|
|
10
12
|
}
|
|
11
13
|
export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp {
|
|
12
14
|
symbol?: SymbolInfo;
|
|
@@ -7,14 +7,18 @@
|
|
|
7
7
|
|
|
8
8
|
export let isInteractive: ComponentProps["isInteractive"];
|
|
9
9
|
export let componentRef: ComponentProps["componentRef"];
|
|
10
|
+
export let blockChildren: ComponentProps["blockChildren"];
|
|
10
11
|
export let componentOptions: ComponentProps["componentOptions"];
|
|
11
12
|
export let builderBlock: ComponentProps["builderBlock"];
|
|
12
13
|
export let context: ComponentProps["context"];
|
|
13
14
|
export let linkComponent: ComponentProps["linkComponent"];
|
|
14
15
|
export let includeBlockProps: ComponentProps["includeBlockProps"];
|
|
15
|
-
export let blockChildren: ComponentProps["blockChildren"];
|
|
16
16
|
export let registeredComponents: ComponentProps["registeredComponents"];
|
|
17
17
|
|
|
18
|
+
$: blockChildrenToRender = () => {
|
|
19
|
+
return componentRef ? blockChildren : [];
|
|
20
|
+
};
|
|
21
|
+
|
|
18
22
|
let shouldUpdate = false;
|
|
19
23
|
let Wrapper = isInteractive ? InteractiveElement : componentRef;
|
|
20
24
|
</script>
|
|
@@ -33,10 +37,8 @@
|
|
|
33
37
|
contextValue: $context,
|
|
34
38
|
})}
|
|
35
39
|
>
|
|
36
|
-
{#
|
|
37
|
-
{
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
{/if}</svelte:component
|
|
41
|
-
>
|
|
40
|
+
{#each blockChildrenToRender() as child (child.id)}
|
|
41
|
+
<Block block={child} {context} {registeredComponents} {linkComponent} />
|
|
42
|
+
{/each}
|
|
43
|
+
</svelte:component>
|
|
42
44
|
{/if}
|
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
getInitVariantsFnsScriptString,
|
|
27
27
|
getUpdateCookieAndStylesScript,
|
|
28
28
|
getVariants,
|
|
29
|
+
removeDuplicateScript,
|
|
29
30
|
} from "./helpers";
|
|
30
31
|
|
|
31
32
|
export let canTrack: VariantsProviderProps["canTrack"] = undefined;
|
|
@@ -95,17 +96,23 @@
|
|
|
95
96
|
{#if !isNestedRender && TARGET !== "reactNative"}
|
|
96
97
|
<InlinedScript
|
|
97
98
|
id="builderio-init-variants-fns"
|
|
98
|
-
scriptStr={
|
|
99
|
+
scriptStr={removeDuplicateScript(
|
|
100
|
+
"builderio-init-variants-fns",
|
|
101
|
+
getInitVariantsFnsScriptString()
|
|
102
|
+
)}
|
|
99
103
|
nonce={nonce || ""}
|
|
100
104
|
/>
|
|
105
|
+
{/if}
|
|
101
106
|
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
107
|
+
{#if !isNestedRender && TARGET !== "reactNative" && SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}
|
|
108
|
+
<InlinedScript
|
|
109
|
+
id="builderio-init-personalization-variants-fns"
|
|
110
|
+
nonce={nonce || ""}
|
|
111
|
+
scriptStr={removeDuplicateScript(
|
|
112
|
+
"builderio-init-personalization-variants-fns",
|
|
113
|
+
getInitPersonalizationVariantsFnsScriptString()
|
|
114
|
+
)}
|
|
115
|
+
/>
|
|
109
116
|
{/if}
|
|
110
117
|
|
|
111
118
|
{#if shouldRenderVariants}
|
|
@@ -54,6 +54,37 @@ type VariantData = {
|
|
|
54
54
|
const getIsHydrationTarget = (target: Target) => target === 'react' || target === 'reactNative';
|
|
55
55
|
const isAngularSDK = TARGET === 'angular';
|
|
56
56
|
const isHydrationTarget = getIsHydrationTarget(TARGET);
|
|
57
|
+
export const removeDuplicateScript = (id: string, scriptStr: string) => `
|
|
58
|
+
(function() {
|
|
59
|
+
var selector = 'script[data-id="${id}"]';
|
|
60
|
+
var scriptKey = '__builderioScriptInitialized_${id}';
|
|
61
|
+
var observerKey = '__builderioScriptObserver_${id}';
|
|
62
|
+
|
|
63
|
+
// Synchronously remove any duplicates already in the DOM
|
|
64
|
+
var existing = document.querySelectorAll(selector);
|
|
65
|
+
existing.forEach(function(script, index) {
|
|
66
|
+
if (index > 0) {
|
|
67
|
+
script.parentNode && script.parentNode.removeChild(script);
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
// Watch for duplicates added later (e.g. RSC streaming chunks)
|
|
72
|
+
if (!window[observerKey] && typeof MutationObserver !== 'undefined') {
|
|
73
|
+
window[observerKey] = new MutationObserver(function() {
|
|
74
|
+
var all = document.querySelectorAll(selector);
|
|
75
|
+
for (var i = 1; i < all.length; i++) {
|
|
76
|
+
all[i].parentNode && all[i].parentNode.removeChild(all[i]);
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
window[observerKey].observe(document.documentElement, { childList: true, subtree: true });
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (!window[scriptKey]) {
|
|
83
|
+
window[scriptKey] = true;
|
|
84
|
+
${scriptStr}
|
|
85
|
+
}
|
|
86
|
+
})();
|
|
87
|
+
`;
|
|
57
88
|
export const getInitVariantsFnsScriptString = () => `
|
|
58
89
|
window.${UPDATE_COOKIES_AND_STYLES_SCRIPT_NAME} = ${UPDATE_COOKIES_AND_STYLES_SCRIPT}
|
|
59
90
|
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VARIANT_VISIBILITY_SCRIPT}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "5.
|
|
1
|
+
export const SDK_VERSION = "5.2.2"
|