@builder.io/sdk-svelte 4.0.7 → 4.0.9
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/personalization-container/component-info.js +2 -1
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.js +45 -1
- package/lib/browser/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/browser/blocks/personalization-container/helpers.js +50 -19
- package/lib/browser/blocks/personalization-container/personalization-container.svelte +86 -38
- package/lib/browser/blocks/personalization-container/personalization-container.svelte.d.ts +2 -1
- package/lib/browser/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/browser/blocks/symbol/symbol.svelte +3 -1
- package/lib/browser/components/block/components/interactive-element.svelte +5 -2
- package/lib/browser/components/blocks/blocks.svelte +6 -4
- package/lib/browser/components/blocks/blocks.svelte.d.ts +5 -2
- package/lib/browser/components/blocks/blocks.types.d.ts +1 -1
- package/lib/browser/components/content-variants/content-variants.svelte +9 -0
- package/lib/browser/constants/builder-registered-components.js +2 -1
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/edge/blocks/personalization-container/component-info.js +2 -1
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.js +45 -1
- package/lib/edge/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/edge/blocks/personalization-container/helpers.js +50 -19
- package/lib/edge/blocks/personalization-container/personalization-container.svelte +86 -38
- package/lib/edge/blocks/personalization-container/personalization-container.svelte.d.ts +2 -1
- package/lib/edge/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/edge/blocks/symbol/symbol.svelte +3 -1
- package/lib/edge/components/block/components/interactive-element.svelte +5 -2
- package/lib/edge/components/blocks/blocks.svelte +6 -4
- package/lib/edge/components/blocks/blocks.svelte.d.ts +5 -2
- package/lib/edge/components/blocks/blocks.types.d.ts +1 -1
- package/lib/edge/components/content-variants/content-variants.svelte +9 -0
- package/lib/edge/constants/builder-registered-components.js +2 -1
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/node/blocks/personalization-container/component-info.js +2 -1
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.js +45 -1
- package/lib/node/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/node/blocks/personalization-container/helpers.js +50 -19
- package/lib/node/blocks/personalization-container/personalization-container.svelte +86 -38
- package/lib/node/blocks/personalization-container/personalization-container.svelte.d.ts +2 -1
- package/lib/node/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/node/blocks/symbol/symbol.svelte +3 -1
- package/lib/node/components/block/components/interactive-element.svelte +5 -2
- package/lib/node/components/blocks/blocks.svelte +6 -4
- package/lib/node/components/blocks/blocks.svelte.d.ts +5 -2
- package/lib/node/components/blocks/blocks.types.d.ts +1 -1
- package/lib/node/components/content-variants/content-variants.svelte +9 -0
- package/lib/node/constants/builder-registered-components.js +2 -1
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/package.json +2 -2
- package/src/blocks/personalization-container/component-info.ts +2 -1
- package/src/blocks/personalization-container/helpers/inlined-fns.ts +42 -2
- package/src/blocks/personalization-container/helpers.ts +60 -24
- package/src/blocks/personalization-container/personalization-container.svelte +95 -38
- package/src/blocks/personalization-container/personalization-container.types.ts +2 -2
- package/src/blocks/symbol/symbol.svelte +3 -1
- package/src/components/block/components/interactive-element.svelte +8 -2
- package/src/components/blocks/blocks-wrapper.svelte +13 -1
- package/src/components/blocks/blocks.svelte +7 -4
- package/src/components/blocks/blocks.types.ts +1 -1
- package/src/components/content-variants/content-variants.svelte +12 -0
- package/src/constants/builder-registered-components.ts +2 -1
- package/src/constants/sdk-version.ts +1 -1
|
@@ -84,5 +84,45 @@ export function filterWithCustomTargeting(userAttributes: UserAttributes, query:
|
|
|
84
84
|
return objectMatchesQuery(userAttributes, filter);
|
|
85
85
|
});
|
|
86
86
|
}
|
|
87
|
-
export
|
|
88
|
-
|
|
87
|
+
export function updateVisibilityStylesScript(variants: PersonalizationContainerProps['variants'], blockId: string, isHydrationTarget: boolean, locale?: string) {
|
|
88
|
+
function getCookie(name: string) {
|
|
89
|
+
const nameEQ = name + '=';
|
|
90
|
+
const ca = document.cookie.split(';');
|
|
91
|
+
for (let i = 0; i < ca.length; i++) {
|
|
92
|
+
let c = ca[i];
|
|
93
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
94
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
95
|
+
}
|
|
96
|
+
return null;
|
|
97
|
+
}
|
|
98
|
+
const visibilityStylesEl = (document.currentScript?.previousElementSibling as HTMLStyleElement);
|
|
99
|
+
if (!visibilityStylesEl) {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
102
|
+
if (isHydrationTarget) {
|
|
103
|
+
visibilityStylesEl.remove();
|
|
104
|
+
const currentScript = document.currentScript;
|
|
105
|
+
if (currentScript) {
|
|
106
|
+
currentScript.remove();
|
|
107
|
+
}
|
|
108
|
+
} else {
|
|
109
|
+
const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
|
|
110
|
+
if (locale) {
|
|
111
|
+
attributes.locale = locale;
|
|
112
|
+
}
|
|
113
|
+
const winningVariantIndex = variants?.findIndex(function (variant) {
|
|
114
|
+
return (window as any).filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
|
|
115
|
+
});
|
|
116
|
+
if (winningVariantIndex !== -1) {
|
|
117
|
+
let newStyleStr = variants?.map((_, index) => {
|
|
118
|
+
if (index === winningVariantIndex) return '';
|
|
119
|
+
return `div[data-variant-id="${blockId}-${index}"] { display: none !important; } `;
|
|
120
|
+
}).join('') || '';
|
|
121
|
+
newStyleStr += `div[data-variant-id="${blockId}-default"] { display: none !important; } `;
|
|
122
|
+
visibilityStylesEl.innerHTML = newStyleStr;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export const PERSONALIZATION_SCRIPT = "function getPersonalizedVariant(variants, blockId, isHydrationTarget, locale) {\n if (!navigator.cookieEnabled) {\n return;\n }\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n const parentDiv = document.currentScript?.parentElement;\n const variantId = parentDiv?.getAttribute('data-variant-id');\n const isDefaultVariant = variantId === `${blockId}-default`;\n const isWinningVariant = winningVariantIndex !== -1 && variantId === `${blockId}-${winningVariantIndex}` || winningVariantIndex === -1 && isDefaultVariant;\n if (isWinningVariant && !isDefaultVariant) {\n parentDiv?.removeAttribute('hidden');\n parentDiv?.removeAttribute('aria-hidden');\n } else if (!isWinningVariant && isDefaultVariant) {\n parentDiv?.setAttribute('hidden', 'true');\n parentDiv?.setAttribute('aria-hidden', 'true');\n }\n if (isHydrationTarget) {\n if (!isWinningVariant) {\n const itsStyleEl = parentDiv?.previousElementSibling;\n if (itsStyleEl) {\n itsStyleEl.remove();\n }\n parentDiv?.remove();\n }\n const thisScript = document.currentScript;\n if (thisScript) {\n thisScript.remove();\n }\n }\n}";
|
|
127
|
+
export const FILTER_WITH_CUSTOM_TARGETING_SCRIPT = "function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {\n function isString(val) {\n return typeof val === 'string';\n }\n function isNumber(val) {\n return typeof val === 'number';\n }\n function objectMatchesQuery(userattr, query) {\n const result = (() => {\n const property = query.property;\n const operator = query.operator;\n let testValue = query.value;\n if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {\n testValue = query.value.slice(0, -1);\n }\n if (!(property && operator)) {\n return true;\n }\n if (Array.isArray(testValue)) {\n if (operator === 'isNot') {\n return testValue.every(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n return !!testValue.find(val => objectMatchesQuery(userattr, {\n property,\n operator,\n value: val\n }));\n }\n const value = userattr[property];\n if (Array.isArray(value)) {\n return value.includes(testValue);\n }\n switch (operator) {\n case 'is':\n return value === testValue;\n case 'isNot':\n return value !== testValue;\n case 'contains':\n return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));\n case 'startsWith':\n return isString(value) && value.startsWith(String(testValue));\n case 'endsWith':\n return isString(value) && value.endsWith(String(testValue));\n case 'greaterThan':\n return isNumber(value) && isNumber(testValue) && value > testValue;\n case 'lessThan':\n return isNumber(value) && isNumber(testValue) && value < testValue;\n case 'greaterThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value >= testValue;\n case 'lessThanOrEqualTo':\n return isNumber(value) && isNumber(testValue) && value <= testValue;\n default:\n return false;\n }\n })();\n return result;\n }\n const item = {\n query,\n startDate,\n endDate\n };\n const now = userAttributes.date && new Date(userAttributes.date) || new Date();\n if (item.startDate && new Date(item.startDate) > now) {\n return false;\n } else if (item.endDate && new Date(item.endDate) < now) {\n return false;\n }\n if (!item.query || !item.query.length) {\n return true;\n }\n return item.query.every(filter => {\n return objectMatchesQuery(userAttributes, filter);\n });\n}";
|
|
128
|
+
export const UPDATE_VISIBILITY_STYLES_SCRIPT = "function updateVisibilityStylesScript(variants, blockId, isHydrationTarget, locale) {\n function getCookie(name) {\n const nameEQ = name + '=';\n const ca = document.cookie.split(';');\n for (let i = 0; i < ca.length; i++) {\n let c = ca[i];\n while (c.charAt(0) == ' ') c = c.substring(1, c.length);\n if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);\n }\n return null;\n }\n const visibilityStylesEl = document.currentScript?.previousElementSibling;\n if (!visibilityStylesEl) {\n return;\n }\n if (isHydrationTarget) {\n visibilityStylesEl.remove();\n const currentScript = document.currentScript;\n if (currentScript) {\n currentScript.remove();\n }\n } else {\n const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');\n if (locale) {\n attributes.locale = locale;\n }\n const winningVariantIndex = variants?.findIndex(function (variant) {\n return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);\n });\n if (winningVariantIndex !== -1) {\n let newStyleStr = variants?.map((_, index) => {\n if (index === winningVariantIndex) return '';\n return `div[data-variant-id=\"${blockId}-${index}\"] { display: none !important; } `;\n }).join('') || '';\n newStyleStr += `div[data-variant-id=\"${blockId}-default\"] { display: none !important; } `;\n visibilityStylesEl.innerHTML = newStyleStr;\n }\n }\n}";
|
|
@@ -2,8 +2,13 @@ import { TARGET } from '../../constants/target';
|
|
|
2
2
|
import { isBrowser } from '../../functions/is-browser';
|
|
3
3
|
import { isEditing } from '../../functions/is-editing';
|
|
4
4
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
5
|
-
import {
|
|
5
|
+
import type { Target } from '../../types/targets';
|
|
6
|
+
import { FILTER_WITH_CUSTOM_TARGETING_SCRIPT, PERSONALIZATION_SCRIPT, UPDATE_VISIBILITY_STYLES_SCRIPT } from './helpers/inlined-fns';
|
|
6
7
|
import type { PersonalizationContainerProps } from './personalization-container.types';
|
|
8
|
+
export const DEFAULT_INDEX = 'default';
|
|
9
|
+
const FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME = 'filterWithCustomTargeting';
|
|
10
|
+
const BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME = 'builderIoPersonalization';
|
|
11
|
+
const UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME = 'updateVisibilityStylesScript';
|
|
7
12
|
export type UserAttributes = {
|
|
8
13
|
date?: string | Date;
|
|
9
14
|
urlPath?: string;
|
|
@@ -16,12 +21,33 @@ export type Query = {
|
|
|
16
21
|
operator: QueryOperator;
|
|
17
22
|
value: QueryValue;
|
|
18
23
|
};
|
|
24
|
+
type BlocksToRenderReturnType = {
|
|
25
|
+
blocks: BuilderBlock[];
|
|
26
|
+
path: string;
|
|
27
|
+
index: number | typeof DEFAULT_INDEX;
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* SDKs that support Variant Containers
|
|
32
|
+
*/
|
|
33
|
+
export const SDKS_SUPPORTING_PERSONALIZATION = (['react', 'vue', 'svelte'] as Target[]);
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* After hydration, we reset the tree
|
|
37
|
+
* These SDKs handle Personalization Container in a special way:
|
|
38
|
+
* - first, the inlined script will help us add `display: none`, `aria-hidden: true` and `hidden: true` to the non-winning variants
|
|
39
|
+
* - then, on mount / when the component is hydrated - we reset the tree with only the winning variant and deleting the entire tree
|
|
40
|
+
*
|
|
41
|
+
* This helps us to avoid flicker and show the correct / winning variant initially and then once we've hydrated we show the winning variant
|
|
42
|
+
* and keep a track of the cookies to update to the correct variant dynamically when the cookie updates.
|
|
43
|
+
*/
|
|
44
|
+
export const SDKS_REQUIRING_RESET_APPROACH = (['vue', 'svelte'] as Target[]);
|
|
19
45
|
export function checkShouldRenderVariants(variants: PersonalizationContainerProps['variants'], canTrack: boolean) {
|
|
20
46
|
const hasVariants = variants && variants.length > 0;
|
|
21
47
|
if (TARGET === 'reactNative') return false;
|
|
22
48
|
if (!hasVariants) return false;
|
|
23
49
|
if (!canTrack) return false;
|
|
24
|
-
if (TARGET
|
|
50
|
+
if (SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)) return true;
|
|
25
51
|
if (isBrowser()) return false;
|
|
26
52
|
return true;
|
|
27
53
|
}
|
|
@@ -37,22 +63,23 @@ export function getBlocksToRender({
|
|
|
37
63
|
isHydrated: boolean;
|
|
38
64
|
filteredVariants: PersonalizationContainerProps['variants'];
|
|
39
65
|
fallbackBlocks?: BuilderBlock[];
|
|
40
|
-
}): {
|
|
41
|
-
|
|
42
|
-
path: string | undefined;
|
|
43
|
-
} {
|
|
44
|
-
const fallback = {
|
|
66
|
+
}): BlocksToRenderReturnType {
|
|
67
|
+
const fallback: BlocksToRenderReturnType = {
|
|
45
68
|
blocks: fallbackBlocks ?? [],
|
|
46
|
-
path: 'this.children'
|
|
69
|
+
path: 'this.children',
|
|
70
|
+
index: DEFAULT_INDEX
|
|
47
71
|
};
|
|
48
72
|
if (isHydrated && isEditing()) {
|
|
49
73
|
// If editing a specific variant
|
|
50
74
|
if (typeof previewingIndex === 'number' && previewingIndex < (variants?.length ?? 0)) {
|
|
51
|
-
const variant = variants
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
75
|
+
const variant = variants?.[previewingIndex];
|
|
76
|
+
if (variant) {
|
|
77
|
+
return {
|
|
78
|
+
blocks: variant.blocks,
|
|
79
|
+
path: `variants.${previewingIndex}.blocks`,
|
|
80
|
+
index: previewingIndex
|
|
81
|
+
};
|
|
82
|
+
}
|
|
56
83
|
}
|
|
57
84
|
// Otherwise we're editing the default variant
|
|
58
85
|
return fallback;
|
|
@@ -61,24 +88,33 @@ export function getBlocksToRender({
|
|
|
61
88
|
// If we're on the browser, check if there's a winning variant
|
|
62
89
|
if (isBrowser()) {
|
|
63
90
|
const winningVariant = filteredVariants?.[0];
|
|
64
|
-
if (winningVariant) {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
91
|
+
if (winningVariant && variants) {
|
|
92
|
+
const variantIndex = variants.indexOf(winningVariant);
|
|
93
|
+
if (variantIndex !== -1) {
|
|
94
|
+
return {
|
|
95
|
+
blocks: winningVariant.blocks,
|
|
96
|
+
path: `variants.${variantIndex}.blocks`,
|
|
97
|
+
index: variantIndex
|
|
98
|
+
};
|
|
99
|
+
}
|
|
69
100
|
}
|
|
70
101
|
}
|
|
71
102
|
|
|
72
103
|
// If no winning variant or we are on the server, return the default variant
|
|
73
104
|
return fallback;
|
|
74
105
|
}
|
|
75
|
-
export const
|
|
106
|
+
export const getInitPersonalizationVariantsFnsScriptString = () => {
|
|
76
107
|
return `
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
getPersonalizedVariant(${JSON.stringify(variants)}, "${blockId}"${locale ? `, "${locale}"` : ''})
|
|
81
|
-
})();
|
|
108
|
+
window.${FILTER_WITH_CUSTOM_TARGETING_SCRIPT_FN_NAME} = ${FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
|
|
109
|
+
window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME} = ${PERSONALIZATION_SCRIPT}
|
|
110
|
+
window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME} = ${UPDATE_VISIBILITY_STYLES_SCRIPT}
|
|
82
111
|
`;
|
|
83
112
|
};
|
|
113
|
+
const isHydrationTarget = TARGET === 'react';
|
|
114
|
+
export const getPersonalizationScript = (variants: PersonalizationContainerProps['variants'], blockId: string, locale?: string) => {
|
|
115
|
+
return `window.${BUILDER_IO_PERSONALIZATION_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ''})`;
|
|
116
|
+
};
|
|
117
|
+
export const getUpdateVisibilityStylesScript = (variants: PersonalizationContainerProps['variants'], blockId: string, locale?: string) => {
|
|
118
|
+
return `window.${UPDATE_VARIANT_VISIBILITY_SCRIPT_FN_NAME}(${JSON.stringify(variants)}, "${blockId}", ${isHydrationTarget}${locale ? `, "${locale}"` : ''})`;
|
|
119
|
+
};
|
|
84
120
|
export { filterWithCustomTargeting } from './helpers/inlined-fns'
|
|
@@ -4,26 +4,43 @@
|
|
|
4
4
|
import Blocks from "../../components/blocks/blocks.svelte";
|
|
5
5
|
import InlinedScript from "../../components/inlined-script.svelte";
|
|
6
6
|
import InlinedStyles from "../../components/inlined-styles.svelte";
|
|
7
|
+
import { TARGET } from "../../constants/target";
|
|
8
|
+
import { getClassPropName } from "../../functions/get-class-prop-name";
|
|
7
9
|
import { isEditing } from "../../functions/is-editing";
|
|
8
10
|
import { isPreviewing } from "../../functions/is-previewing";
|
|
9
11
|
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
10
12
|
import { userAttributesService } from "../../helpers/user-attributes";
|
|
13
|
+
import { filterAttrs } from "../helpers";
|
|
11
14
|
import {
|
|
12
15
|
checkShouldRenderVariants,
|
|
16
|
+
DEFAULT_INDEX,
|
|
13
17
|
filterWithCustomTargeting,
|
|
14
18
|
getBlocksToRender,
|
|
15
19
|
getPersonalizationScript,
|
|
20
|
+
getUpdateVisibilityStylesScript,
|
|
21
|
+
SDKS_REQUIRING_RESET_APPROACH,
|
|
16
22
|
} from "./helpers";
|
|
17
23
|
import type { PersonalizationContainerProps } from "./personalization-container.types";
|
|
24
|
+
import { setAttrs } from "../helpers";
|
|
18
25
|
|
|
19
26
|
export let builderContext: PersonalizationContainerProps["builderContext"];
|
|
20
27
|
export let variants: PersonalizationContainerProps["variants"] = undefined;
|
|
21
28
|
export let builderBlock: PersonalizationContainerProps["builderBlock"];
|
|
22
|
-
export let previewingIndex: PersonalizationContainerProps["previewingIndex"] =
|
|
23
|
-
undefined;
|
|
24
29
|
export let attributes: PersonalizationContainerProps["attributes"] =
|
|
25
30
|
undefined;
|
|
31
|
+
export let previewingIndex: PersonalizationContainerProps["previewingIndex"] =
|
|
32
|
+
undefined;
|
|
33
|
+
export let builderComponents: PersonalizationContainerProps["builderComponents"];
|
|
26
34
|
|
|
35
|
+
$: attrs = () => {
|
|
36
|
+
return {
|
|
37
|
+
...filterAttrs(attributes, "on:", false),
|
|
38
|
+
...filterAttrs(attributes, "on:", true),
|
|
39
|
+
[getClassPropName()]: `builder-personalization-container ${
|
|
40
|
+
attributes[getClassPropName()] || ""
|
|
41
|
+
}`,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
27
44
|
$: filteredVariants = () => {
|
|
28
45
|
return (variants || []).filter((variant) => {
|
|
29
46
|
return filterWithCustomTargeting(
|
|
@@ -45,7 +62,7 @@
|
|
|
45
62
|
return getBlocksToRender({
|
|
46
63
|
variants: variants,
|
|
47
64
|
fallbackBlocks: builderBlock?.children,
|
|
48
|
-
isHydrated:
|
|
65
|
+
isHydrated: shouldResetVariants,
|
|
49
66
|
filteredVariants: filteredVariants(),
|
|
50
67
|
previewingIndex: previewingIndex,
|
|
51
68
|
});
|
|
@@ -54,7 +71,7 @@
|
|
|
54
71
|
return (variants || [])
|
|
55
72
|
.map(
|
|
56
73
|
(_, index) =>
|
|
57
|
-
`[data-variant-id="${builderBlock?.id}-${index}"] { display: none; } `
|
|
74
|
+
`div[data-variant-id="${builderBlock?.id}-${index}"] { display: none !important; } `
|
|
58
75
|
)
|
|
59
76
|
.join("");
|
|
60
77
|
};
|
|
@@ -67,15 +84,20 @@
|
|
|
67
84
|
builderBlock?.id || "none",
|
|
68
85
|
$builderContext?.rootState?.locale as string | undefined
|
|
69
86
|
);
|
|
87
|
+
let updateVisibilityStylesScript = getUpdateVisibilityStylesScript(
|
|
88
|
+
variants,
|
|
89
|
+
builderBlock?.id || "none",
|
|
90
|
+
$builderContext?.rootState?.locale as string | undefined
|
|
91
|
+
);
|
|
70
92
|
let unsubscribers = [];
|
|
71
93
|
let shouldRenderVariants = checkShouldRenderVariants(
|
|
72
94
|
variants,
|
|
73
95
|
getDefaultCanTrack($builderContext?.canTrack)
|
|
74
96
|
);
|
|
75
|
-
let
|
|
97
|
+
let shouldResetVariants = false;
|
|
76
98
|
|
|
77
99
|
onMount(() => {
|
|
78
|
-
|
|
100
|
+
shouldResetVariants = true;
|
|
79
101
|
const unsub = userAttributesService.subscribeOnUserAttributesChange(
|
|
80
102
|
(attrs) => {
|
|
81
103
|
userAttributes = attrs;
|
|
@@ -87,7 +109,7 @@
|
|
|
87
109
|
rootRef.dispatchEvent(
|
|
88
110
|
new CustomEvent("builder.variantLoaded", {
|
|
89
111
|
detail: {
|
|
90
|
-
variant: variant ||
|
|
112
|
+
variant: variant || DEFAULT_INDEX,
|
|
91
113
|
content: $builderContext?.content,
|
|
92
114
|
},
|
|
93
115
|
bubbles: true,
|
|
@@ -99,7 +121,7 @@
|
|
|
99
121
|
rootRef.dispatchEvent(
|
|
100
122
|
new CustomEvent("builder.variantDisplayed", {
|
|
101
123
|
detail: {
|
|
102
|
-
variant: variant ||
|
|
124
|
+
variant: variant || DEFAULT_INDEX,
|
|
103
125
|
content: $builderContext?.content,
|
|
104
126
|
},
|
|
105
127
|
bubbles: true,
|
|
@@ -119,37 +141,72 @@
|
|
|
119
141
|
});
|
|
120
142
|
</script>
|
|
121
143
|
|
|
122
|
-
<div
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
144
|
+
<div bind:this={rootRef} {...attrs()}>
|
|
145
|
+
{#if shouldResetVariants && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
|
|
146
|
+
<Blocks
|
|
147
|
+
blocks={blocksToRender().blocks}
|
|
148
|
+
parent={builderBlock?.id}
|
|
149
|
+
path={blocksToRender().path}
|
|
150
|
+
context={builderContext}
|
|
151
|
+
registeredComponents={builderComponents}
|
|
152
|
+
BlocksWrapperProps={{
|
|
153
|
+
...$builderContext?.BlocksWrapperProps,
|
|
154
|
+
"data-variant-id": `${builderBlock?.id}-${blocksToRender().index}`,
|
|
155
|
+
}}
|
|
156
|
+
/>
|
|
157
|
+
{/if}
|
|
158
|
+
{#if (!shouldResetVariants && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
|
|
159
|
+
{#if shouldRenderVariants}
|
|
160
|
+
<InlinedStyles
|
|
161
|
+
nonce={$builderContext?.nonce || ""}
|
|
162
|
+
styles={hideVariantsStyleString()}
|
|
163
|
+
id={`variants-styles-${builderBlock?.id}`}
|
|
164
|
+
/>
|
|
165
|
+
<InlinedScript
|
|
166
|
+
nonce={$builderContext?.nonce || ""}
|
|
167
|
+
scriptStr={updateVisibilityStylesScript}
|
|
168
|
+
id={`variants-visibility-script-${builderBlock?.id}`}
|
|
169
|
+
/>
|
|
170
|
+
|
|
171
|
+
{#each variants as variant, index (`${builderBlock?.id}-${index}`)}
|
|
172
|
+
<Blocks
|
|
173
|
+
BlocksWrapperProps={{
|
|
174
|
+
...$builderContext?.BlocksWrapperProps,
|
|
175
|
+
"aria-hidden": true,
|
|
176
|
+
hidden: true,
|
|
177
|
+
"data-variant-id": `${builderBlock?.id}-${index}`,
|
|
178
|
+
}}
|
|
133
179
|
blocks={variant.blocks}
|
|
134
180
|
parent={builderBlock?.id}
|
|
135
181
|
path={`component.options.variants.${index}.blocks`}
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
{
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
182
|
+
context={builderContext}
|
|
183
|
+
registeredComponents={builderComponents}
|
|
184
|
+
><InlinedScript
|
|
185
|
+
nonce={$builderContext?.nonce || ""}
|
|
186
|
+
{scriptStr}
|
|
187
|
+
id={`variants-script-${builderBlock?.id}-${index}`}
|
|
188
|
+
/></Blocks
|
|
189
|
+
>
|
|
190
|
+
{/each}
|
|
191
|
+
{/if}
|
|
192
|
+
<Blocks
|
|
193
|
+
blocks={blocksToRender().blocks}
|
|
194
|
+
parent={builderBlock?.id}
|
|
195
|
+
path={blocksToRender().path}
|
|
196
|
+
context={builderContext}
|
|
197
|
+
registeredComponents={builderComponents}
|
|
198
|
+
BlocksWrapperProps={{
|
|
199
|
+
...$builderContext?.BlocksWrapperProps,
|
|
200
|
+
"data-variant-id": `${builderBlock?.id}-${blocksToRender().index}`,
|
|
201
|
+
}}
|
|
202
|
+
>
|
|
203
|
+
{#if shouldRenderVariants}
|
|
204
|
+
<InlinedScript
|
|
205
|
+
nonce={$builderContext?.nonce || ""}
|
|
206
|
+
{scriptStr}
|
|
207
|
+
id={`variants-script-${builderBlock?.id}-${DEFAULT_INDEX}`}
|
|
208
|
+
/>
|
|
209
|
+
{/if}</Blocks
|
|
210
|
+
>
|
|
211
|
+
{/if}
|
|
155
212
|
</div>
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
2
|
-
import type { BuilderDataProps } from '../../types/builder-props';
|
|
2
|
+
import type { BuilderComponentsProp, BuilderDataProps } from '../../types/builder-props';
|
|
3
3
|
import type { Query } from './helpers';
|
|
4
4
|
export type PersonalizationContainerProps = {
|
|
5
5
|
children?: any;
|
|
@@ -11,4 +11,4 @@ export type PersonalizationContainerProps = {
|
|
|
11
11
|
startDate?: string;
|
|
12
12
|
endDate?: string;
|
|
13
13
|
}>;
|
|
14
|
-
} & BuilderDataProps
|
|
14
|
+
} & BuilderDataProps & BuilderComponentsProp
|
|
@@ -21,13 +21,14 @@
|
|
|
21
21
|
undefined;
|
|
22
22
|
|
|
23
23
|
function setContent() {
|
|
24
|
-
if (contentToUse) return;
|
|
24
|
+
if (contentToUse && symbolEntry === symbol?.entry) return;
|
|
25
25
|
fetchSymbolContent({
|
|
26
26
|
symbol: symbol,
|
|
27
27
|
builderContextValue: $builderContext,
|
|
28
28
|
}).then((newContent) => {
|
|
29
29
|
if (newContent) {
|
|
30
30
|
contentToUse = newContent;
|
|
31
|
+
symbolEntry = symbol?.entry;
|
|
31
32
|
}
|
|
32
33
|
});
|
|
33
34
|
}
|
|
@@ -49,6 +50,7 @@
|
|
|
49
50
|
};
|
|
50
51
|
|
|
51
52
|
let contentToUse = symbol?.content;
|
|
53
|
+
let symbolEntry = symbol?.entry;
|
|
52
54
|
|
|
53
55
|
onMount(() => {
|
|
54
56
|
setContent();
|
|
@@ -18,10 +18,10 @@
|
|
|
18
18
|
import Awaiter from "../../awaiter.svelte";
|
|
19
19
|
import type { Writable } from "svelte/store";
|
|
20
20
|
|
|
21
|
-
export let
|
|
21
|
+
export let wrapperProps: InteractiveElementProps["wrapperProps"];
|
|
22
22
|
export let block: InteractiveElementProps["block"];
|
|
23
|
+
export let includeBlockProps: InteractiveElementProps["includeBlockProps"];
|
|
23
24
|
export let context: InteractiveElementProps["context"];
|
|
24
|
-
export let wrapperProps: InteractiveElementProps["wrapperProps"];
|
|
25
25
|
export let Wrapper: InteractiveElementProps["Wrapper"];
|
|
26
26
|
|
|
27
27
|
$: attributes = () => {
|
|
@@ -44,6 +44,12 @@
|
|
|
44
44
|
$: targetWrapperProps = () => {
|
|
45
45
|
return wrapperProps;
|
|
46
46
|
};
|
|
47
|
+
|
|
48
|
+
let forceRenderCount = 0;
|
|
49
|
+
|
|
50
|
+
function onUpdateFn_0(..._args: any[]) {}
|
|
51
|
+
|
|
52
|
+
$: onUpdateFn_0(...[wrapperProps, block?.component?.options]);
|
|
47
53
|
</script>
|
|
48
54
|
|
|
49
55
|
{#if Wrapper.load}
|
|
@@ -9,7 +9,19 @@
|
|
|
9
9
|
*/
|
|
10
10
|
BlocksWrapper: any;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Props to be applied to the wrapping element of blocks. Can be set in two ways:
|
|
13
|
+
* 1. Globally via `<Content blocksWrapperProps={{...}}/>` - applies to all blocks wrappers in the Content
|
|
14
|
+
* 2. Locally via `<Blocks BlocksWrapperProps={{...}}/>` - applies only to this specific blocks instance and overrides global props
|
|
15
|
+
*
|
|
16
|
+
* For merging both global and local props, spread the context props before adding your own:
|
|
17
|
+
* ```
|
|
18
|
+
* <Blocks
|
|
19
|
+
* BlocksWrapperProps={{
|
|
20
|
+
* ...builderContext.BlocksWrapperProps,
|
|
21
|
+
* 'data-test-id': 'my-test-id'
|
|
22
|
+
* }}
|
|
23
|
+
* />
|
|
24
|
+
* ```
|
|
13
25
|
*/
|
|
14
26
|
BlocksWrapperProps: any;
|
|
15
27
|
children?: any;
|
|
@@ -11,8 +11,10 @@
|
|
|
11
11
|
export let parent: BlocksProps["parent"];
|
|
12
12
|
export let path: BlocksProps["path"];
|
|
13
13
|
export let styleProp: BlocksProps["styleProp"];
|
|
14
|
-
export let
|
|
14
|
+
export let BlocksWrapperProps: BlocksProps["BlocksWrapperProps"];
|
|
15
15
|
export let context: BlocksProps["context"] = undefined;
|
|
16
|
+
export let className: BlocksProps["className"] = undefined;
|
|
17
|
+
|
|
16
18
|
export let linkComponent: BlocksProps["linkComponent"] = undefined;
|
|
17
19
|
export let registeredComponents: BlocksProps["registeredComponents"] =
|
|
18
20
|
undefined;
|
|
@@ -26,11 +28,12 @@
|
|
|
26
28
|
{parent}
|
|
27
29
|
{path}
|
|
28
30
|
{styleProp}
|
|
31
|
+
BlocksWrapperProps={BlocksWrapperProps ||
|
|
32
|
+
$context?.BlocksWrapperProps ||
|
|
33
|
+
$builderContext?.BlocksWrapperProps}
|
|
29
34
|
classNameProp={className}
|
|
30
35
|
BlocksWrapper={$context?.BlocksWrapper || $builderContext?.BlocksWrapper}
|
|
31
|
-
|
|
32
|
-
$builderContext?.BlocksWrapperProps}
|
|
33
|
-
>
|
|
36
|
+
><slot />
|
|
34
37
|
{#if blocks}
|
|
35
38
|
{#each blocks as block (block.id)}
|
|
36
39
|
<Block
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { Writable } from "svelte/store";
|
|
2
2
|
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
3
3
|
import type { BlocksWrapperProps } from './blocks-wrapper.svelte';
|
|
4
|
-
export type BlocksProps = Partial<Omit<BlocksWrapperProps, 'BlocksWrapper' | '
|
|
4
|
+
export type BlocksProps = Partial<Omit<BlocksWrapperProps, 'BlocksWrapper' | 'classNameProp'>> & {
|
|
5
5
|
context?: Writable<BuilderContextInterface>;
|
|
6
6
|
registeredComponents?: RegisteredComponents;
|
|
7
7
|
linkComponent?: any;
|
|
@@ -10,6 +10,10 @@
|
|
|
10
10
|
<script lang="ts">
|
|
11
11
|
import { onMount } from "svelte";
|
|
12
12
|
|
|
13
|
+
import {
|
|
14
|
+
SDKS_SUPPORTING_PERSONALIZATION,
|
|
15
|
+
getInitPersonalizationVariantsFnsScriptString,
|
|
16
|
+
} from "../../blocks/personalization-container/helpers";
|
|
13
17
|
import { TARGET } from "../../constants/target";
|
|
14
18
|
import { handleABTestingSync } from "../../helpers/ab-tests";
|
|
15
19
|
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
@@ -94,6 +98,14 @@
|
|
|
94
98
|
scriptStr={getInitVariantsFnsScriptString()}
|
|
95
99
|
nonce={nonce || ""}
|
|
96
100
|
/>
|
|
101
|
+
|
|
102
|
+
{#if SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}
|
|
103
|
+
<InlinedScript
|
|
104
|
+
id="builderio-init-personalization-variants-fns"
|
|
105
|
+
nonce={nonce || ""}
|
|
106
|
+
scriptStr={getInitPersonalizationVariantsFnsScriptString()}
|
|
107
|
+
/>
|
|
108
|
+
{/if}
|
|
97
109
|
{/if}
|
|
98
110
|
|
|
99
111
|
{#if shouldRenderVariants}
|
|
@@ -9,6 +9,7 @@ import { default as Fragment } from '../blocks/fragment/index';
|
|
|
9
9
|
import { componentInfo as imageComponentInfo } from '../blocks/image/component-info';
|
|
10
10
|
import { default as Image } from '../blocks/image/index';
|
|
11
11
|
import { componentInfo as personalizationContainerComponentInfo } from '../blocks/personalization-container/component-info';
|
|
12
|
+
import { SDKS_SUPPORTING_PERSONALIZATION } from '../blocks/personalization-container/helpers';
|
|
12
13
|
import { default as PersonalizationContainer } from '../blocks/personalization-container/index';
|
|
13
14
|
import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info';
|
|
14
15
|
import { default as Section } from '../blocks/section/index';
|
|
@@ -52,7 +53,7 @@ export const getDefaultRegisteredComponents: () => RegisteredComponent[] = () =>
|
|
|
52
53
|
}, {
|
|
53
54
|
component: Text,
|
|
54
55
|
...textComponentInfo
|
|
55
|
-
}, ...(TARGET
|
|
56
|
+
}, ...(SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
|
|
56
57
|
component: PersonalizationContainer,
|
|
57
58
|
...personalizationContainerComponentInfo
|
|
58
59
|
}] : []), ...(TARGET === 'rsc' ? [] : [{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "4.0.
|
|
1
|
+
export const SDK_VERSION = "4.0.9"
|