@builder.io/sdk-react-native 4.0.8 → 4.0.10
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/commonjs/blocks/form/form/form.js +33 -9
- package/lib/browser/commonjs/blocks/form/form/form.js.map +1 -1
- package/lib/browser/commonjs/blocks/personalization-container/component-info.js +2 -1
- package/lib/browser/commonjs/blocks/personalization-container/component-info.js.map +1 -1
- package/lib/browser/commonjs/blocks/personalization-container/helpers/inlined-fns.js +44 -2
- package/lib/browser/commonjs/blocks/personalization-container/helpers/inlined-fns.js.map +1 -1
- package/lib/browser/commonjs/blocks/personalization-container/helpers.js +54 -19
- package/lib/browser/commonjs/blocks/personalization-container/helpers.js.map +1 -1
- package/lib/browser/commonjs/blocks/personalization-container/personalization-container.js +83 -38
- package/lib/browser/commonjs/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/browser/commonjs/components/blocks/blocks-wrapper.js.map +1 -1
- package/lib/browser/commonjs/components/blocks/blocks.js +3 -3
- package/lib/browser/commonjs/components/blocks/blocks.js.map +1 -1
- package/lib/browser/commonjs/components/content-variants/content-variants.js +13 -8
- package/lib/browser/commonjs/components/content-variants/content-variants.js.map +1 -1
- package/lib/browser/commonjs/constants/builder-registered-components.js +2 -1
- package/lib/browser/commonjs/constants/builder-registered-components.js.map +1 -1
- package/lib/browser/commonjs/constants/sdk-version.js +1 -1
- package/lib/browser/commonjs/constants/sdk-version.js.map +1 -1
- package/lib/browser/commonjs/helpers/no-serialize-wrapper.js +10 -0
- package/lib/browser/commonjs/helpers/no-serialize-wrapper.js.map +1 -0
- package/lib/browser/commonjs/helpers/user-attributes.js +20 -4
- package/lib/browser/commonjs/helpers/user-attributes.js.map +1 -1
- package/lib/browser/module/blocks/form/form/form.js +33 -9
- package/lib/browser/module/blocks/form/form/form.js.map +1 -1
- package/lib/browser/module/blocks/personalization-container/component-info.js +2 -1
- package/lib/browser/module/blocks/personalization-container/component-info.js.map +1 -1
- package/lib/browser/module/blocks/personalization-container/helpers/inlined-fns.js +42 -1
- package/lib/browser/module/blocks/personalization-container/helpers/inlined-fns.js.map +1 -1
- package/lib/browser/module/blocks/personalization-container/helpers.js +51 -19
- package/lib/browser/module/blocks/personalization-container/helpers.js.map +1 -1
- package/lib/browser/module/blocks/personalization-container/personalization-container.js +84 -39
- package/lib/browser/module/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/browser/module/components/blocks/blocks-wrapper.js.map +1 -1
- package/lib/browser/module/components/blocks/blocks.js +3 -3
- package/lib/browser/module/components/blocks/blocks.js.map +1 -1
- package/lib/browser/module/components/content-variants/content-variants.js +7 -2
- package/lib/browser/module/components/content-variants/content-variants.js.map +1 -1
- package/lib/browser/module/constants/builder-registered-components.js +2 -1
- package/lib/browser/module/constants/builder-registered-components.js.map +1 -1
- package/lib/browser/module/constants/sdk-version.js +1 -1
- package/lib/browser/module/constants/sdk-version.js.map +1 -1
- package/lib/browser/module/helpers/no-serialize-wrapper.js +4 -0
- package/lib/browser/module/helpers/no-serialize-wrapper.js.map +1 -0
- package/lib/browser/module/helpers/user-attributes.js +20 -4
- package/lib/browser/module/helpers/user-attributes.js.map +1 -1
- package/lib/browser/typescript/blocks/personalization-container/component-info.d.ts.map +1 -1
- package/lib/browser/typescript/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/browser/typescript/blocks/personalization-container/helpers/inlined-fns.d.ts.map +1 -1
- package/lib/browser/typescript/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/browser/typescript/blocks/personalization-container/helpers.d.ts.map +1 -1
- package/lib/browser/typescript/blocks/personalization-container/personalization-container.d.ts.map +1 -1
- package/lib/browser/typescript/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/browser/typescript/blocks/personalization-container/personalization-container.types.d.ts.map +1 -1
- package/lib/browser/typescript/components/blocks/blocks-wrapper.d.ts +13 -1
- package/lib/browser/typescript/components/blocks/blocks-wrapper.d.ts.map +1 -1
- package/lib/browser/typescript/components/blocks/blocks.d.ts.map +1 -1
- package/lib/browser/typescript/components/blocks/blocks.types.d.ts +1 -1
- package/lib/browser/typescript/components/blocks/blocks.types.d.ts.map +1 -1
- package/lib/browser/typescript/components/content-variants/content-variants.d.ts.map +1 -1
- package/lib/browser/typescript/constants/builder-registered-components.d.ts.map +1 -1
- package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/browser/typescript/constants/sdk-version.d.ts.map +1 -1
- package/lib/browser/typescript/helpers/no-serialize-wrapper.d.ts +2 -0
- package/lib/browser/typescript/helpers/no-serialize-wrapper.d.ts.map +1 -0
- package/lib/browser/typescript/helpers/user-attributes.d.ts +6 -2
- package/lib/browser/typescript/helpers/user-attributes.d.ts.map +1 -1
- package/lib/edge/commonjs/blocks/form/form/form.js +33 -9
- package/lib/edge/commonjs/blocks/form/form/form.js.map +1 -1
- package/lib/edge/commonjs/blocks/personalization-container/component-info.js +2 -1
- package/lib/edge/commonjs/blocks/personalization-container/component-info.js.map +1 -1
- package/lib/edge/commonjs/blocks/personalization-container/helpers/inlined-fns.js +44 -2
- package/lib/edge/commonjs/blocks/personalization-container/helpers/inlined-fns.js.map +1 -1
- package/lib/edge/commonjs/blocks/personalization-container/helpers.js +54 -19
- package/lib/edge/commonjs/blocks/personalization-container/helpers.js.map +1 -1
- package/lib/edge/commonjs/blocks/personalization-container/personalization-container.js +83 -38
- package/lib/edge/commonjs/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/edge/commonjs/components/blocks/blocks-wrapper.js.map +1 -1
- package/lib/edge/commonjs/components/blocks/blocks.js +3 -3
- package/lib/edge/commonjs/components/blocks/blocks.js.map +1 -1
- package/lib/edge/commonjs/components/content-variants/content-variants.js +13 -8
- package/lib/edge/commonjs/components/content-variants/content-variants.js.map +1 -1
- package/lib/edge/commonjs/constants/builder-registered-components.js +2 -1
- package/lib/edge/commonjs/constants/builder-registered-components.js.map +1 -1
- package/lib/edge/commonjs/constants/sdk-version.js +1 -1
- package/lib/edge/commonjs/constants/sdk-version.js.map +1 -1
- package/lib/edge/commonjs/helpers/no-serialize-wrapper.js +10 -0
- package/lib/edge/commonjs/helpers/no-serialize-wrapper.js.map +1 -0
- package/lib/edge/commonjs/helpers/user-attributes.js +20 -4
- package/lib/edge/commonjs/helpers/user-attributes.js.map +1 -1
- package/lib/edge/module/blocks/form/form/form.js +33 -9
- package/lib/edge/module/blocks/form/form/form.js.map +1 -1
- package/lib/edge/module/blocks/personalization-container/component-info.js +2 -1
- package/lib/edge/module/blocks/personalization-container/component-info.js.map +1 -1
- package/lib/edge/module/blocks/personalization-container/helpers/inlined-fns.js +42 -1
- package/lib/edge/module/blocks/personalization-container/helpers/inlined-fns.js.map +1 -1
- package/lib/edge/module/blocks/personalization-container/helpers.js +51 -19
- package/lib/edge/module/blocks/personalization-container/helpers.js.map +1 -1
- package/lib/edge/module/blocks/personalization-container/personalization-container.js +84 -39
- package/lib/edge/module/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/edge/module/components/blocks/blocks-wrapper.js.map +1 -1
- package/lib/edge/module/components/blocks/blocks.js +3 -3
- package/lib/edge/module/components/blocks/blocks.js.map +1 -1
- package/lib/edge/module/components/content-variants/content-variants.js +7 -2
- package/lib/edge/module/components/content-variants/content-variants.js.map +1 -1
- package/lib/edge/module/constants/builder-registered-components.js +2 -1
- package/lib/edge/module/constants/builder-registered-components.js.map +1 -1
- package/lib/edge/module/constants/sdk-version.js +1 -1
- package/lib/edge/module/constants/sdk-version.js.map +1 -1
- package/lib/edge/module/helpers/no-serialize-wrapper.js +4 -0
- package/lib/edge/module/helpers/no-serialize-wrapper.js.map +1 -0
- package/lib/edge/module/helpers/user-attributes.js +20 -4
- package/lib/edge/module/helpers/user-attributes.js.map +1 -1
- package/lib/edge/typescript/blocks/personalization-container/component-info.d.ts.map +1 -1
- package/lib/edge/typescript/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/edge/typescript/blocks/personalization-container/helpers/inlined-fns.d.ts.map +1 -1
- package/lib/edge/typescript/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/edge/typescript/blocks/personalization-container/helpers.d.ts.map +1 -1
- package/lib/edge/typescript/blocks/personalization-container/personalization-container.d.ts.map +1 -1
- package/lib/edge/typescript/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/edge/typescript/blocks/personalization-container/personalization-container.types.d.ts.map +1 -1
- package/lib/edge/typescript/components/blocks/blocks-wrapper.d.ts +13 -1
- package/lib/edge/typescript/components/blocks/blocks-wrapper.d.ts.map +1 -1
- package/lib/edge/typescript/components/blocks/blocks.d.ts.map +1 -1
- package/lib/edge/typescript/components/blocks/blocks.types.d.ts +1 -1
- package/lib/edge/typescript/components/blocks/blocks.types.d.ts.map +1 -1
- package/lib/edge/typescript/components/content-variants/content-variants.d.ts.map +1 -1
- package/lib/edge/typescript/constants/builder-registered-components.d.ts.map +1 -1
- package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/edge/typescript/constants/sdk-version.d.ts.map +1 -1
- package/lib/edge/typescript/helpers/no-serialize-wrapper.d.ts +2 -0
- package/lib/edge/typescript/helpers/no-serialize-wrapper.d.ts.map +1 -0
- package/lib/edge/typescript/helpers/user-attributes.d.ts +6 -2
- package/lib/edge/typescript/helpers/user-attributes.d.ts.map +1 -1
- package/lib/node/commonjs/blocks/form/form/form.js +33 -9
- package/lib/node/commonjs/blocks/form/form/form.js.map +1 -1
- package/lib/node/commonjs/blocks/personalization-container/component-info.js +2 -1
- package/lib/node/commonjs/blocks/personalization-container/component-info.js.map +1 -1
- package/lib/node/commonjs/blocks/personalization-container/helpers/inlined-fns.js +44 -2
- package/lib/node/commonjs/blocks/personalization-container/helpers/inlined-fns.js.map +1 -1
- package/lib/node/commonjs/blocks/personalization-container/helpers.js +54 -19
- package/lib/node/commonjs/blocks/personalization-container/helpers.js.map +1 -1
- package/lib/node/commonjs/blocks/personalization-container/personalization-container.js +83 -38
- package/lib/node/commonjs/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/node/commonjs/components/blocks/blocks-wrapper.js.map +1 -1
- package/lib/node/commonjs/components/blocks/blocks.js +3 -3
- package/lib/node/commonjs/components/blocks/blocks.js.map +1 -1
- package/lib/node/commonjs/components/content-variants/content-variants.js +13 -8
- package/lib/node/commonjs/components/content-variants/content-variants.js.map +1 -1
- package/lib/node/commonjs/constants/builder-registered-components.js +2 -1
- package/lib/node/commonjs/constants/builder-registered-components.js.map +1 -1
- package/lib/node/commonjs/constants/sdk-version.js +1 -1
- package/lib/node/commonjs/constants/sdk-version.js.map +1 -1
- package/lib/node/commonjs/helpers/no-serialize-wrapper.js +10 -0
- package/lib/node/commonjs/helpers/no-serialize-wrapper.js.map +1 -0
- package/lib/node/commonjs/helpers/user-attributes.js +20 -4
- package/lib/node/commonjs/helpers/user-attributes.js.map +1 -1
- package/lib/node/module/blocks/form/form/form.js +33 -9
- package/lib/node/module/blocks/form/form/form.js.map +1 -1
- package/lib/node/module/blocks/personalization-container/component-info.js +2 -1
- package/lib/node/module/blocks/personalization-container/component-info.js.map +1 -1
- package/lib/node/module/blocks/personalization-container/helpers/inlined-fns.js +42 -1
- package/lib/node/module/blocks/personalization-container/helpers/inlined-fns.js.map +1 -1
- package/lib/node/module/blocks/personalization-container/helpers.js +51 -19
- package/lib/node/module/blocks/personalization-container/helpers.js.map +1 -1
- package/lib/node/module/blocks/personalization-container/personalization-container.js +84 -39
- package/lib/node/module/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/node/module/components/blocks/blocks-wrapper.js.map +1 -1
- package/lib/node/module/components/blocks/blocks.js +3 -3
- package/lib/node/module/components/blocks/blocks.js.map +1 -1
- package/lib/node/module/components/content-variants/content-variants.js +7 -2
- package/lib/node/module/components/content-variants/content-variants.js.map +1 -1
- package/lib/node/module/constants/builder-registered-components.js +2 -1
- package/lib/node/module/constants/builder-registered-components.js.map +1 -1
- package/lib/node/module/constants/sdk-version.js +1 -1
- package/lib/node/module/constants/sdk-version.js.map +1 -1
- package/lib/node/module/helpers/no-serialize-wrapper.js +4 -0
- package/lib/node/module/helpers/no-serialize-wrapper.js.map +1 -0
- package/lib/node/module/helpers/user-attributes.js +20 -4
- package/lib/node/module/helpers/user-attributes.js.map +1 -1
- package/lib/node/typescript/blocks/personalization-container/component-info.d.ts.map +1 -1
- package/lib/node/typescript/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/node/typescript/blocks/personalization-container/helpers/inlined-fns.d.ts.map +1 -1
- package/lib/node/typescript/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/node/typescript/blocks/personalization-container/helpers.d.ts.map +1 -1
- package/lib/node/typescript/blocks/personalization-container/personalization-container.d.ts.map +1 -1
- package/lib/node/typescript/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/node/typescript/blocks/personalization-container/personalization-container.types.d.ts.map +1 -1
- package/lib/node/typescript/components/blocks/blocks-wrapper.d.ts +13 -1
- package/lib/node/typescript/components/blocks/blocks-wrapper.d.ts.map +1 -1
- package/lib/node/typescript/components/blocks/blocks.d.ts.map +1 -1
- package/lib/node/typescript/components/blocks/blocks.types.d.ts +1 -1
- package/lib/node/typescript/components/blocks/blocks.types.d.ts.map +1 -1
- package/lib/node/typescript/components/content-variants/content-variants.d.ts.map +1 -1
- package/lib/node/typescript/constants/builder-registered-components.d.ts.map +1 -1
- package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
- package/lib/node/typescript/constants/sdk-version.d.ts.map +1 -1
- package/lib/node/typescript/helpers/no-serialize-wrapper.d.ts +2 -0
- package/lib/node/typescript/helpers/no-serialize-wrapper.d.ts.map +1 -0
- package/lib/node/typescript/helpers/user-attributes.d.ts +6 -2
- package/lib/node/typescript/helpers/user-attributes.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/blocks/form/form/form.tsx +31 -9
- 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.tsx +110 -34
- package/src/blocks/personalization-container/personalization-container.types.ts +2 -2
- package/src/components/blocks/blocks-wrapper.tsx +13 -1
- package/src/components/blocks/blocks.tsx +6 -3
- package/src/components/blocks/blocks.types.ts +1 -1
- package/src/components/content-variants/content-variants.tsx +18 -5
- package/src/constants/builder-registered-components.ts +2 -1
- package/src/constants/sdk-version.ts +1 -1
- package/src/helpers/no-serialize-wrapper.ts +3 -0
- package/src/helpers/user-attributes.ts +22 -4
|
@@ -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', 'qwik'] 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', 'qwik'] 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'
|
|
@@ -16,17 +16,24 @@ import { useState, useRef, useEffect } from "react";
|
|
|
16
16
|
import Blocks from "../../components/blocks/blocks";
|
|
17
17
|
import InlinedScript from "../../components/inlined-script";
|
|
18
18
|
import InlinedStyles from "../../components/inlined-styles";
|
|
19
|
+
import { TARGET } from "../../constants/target";
|
|
20
|
+
import { getClassPropName } from "../../functions/get-class-prop-name";
|
|
19
21
|
import { isEditing } from "../../functions/is-editing";
|
|
20
22
|
import { isPreviewing } from "../../functions/is-previewing";
|
|
21
23
|
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
22
24
|
import { userAttributesService } from "../../helpers/user-attributes";
|
|
25
|
+
import { filterAttrs } from "../helpers";
|
|
23
26
|
import {
|
|
24
27
|
checkShouldRenderVariants,
|
|
28
|
+
DEFAULT_INDEX,
|
|
25
29
|
filterWithCustomTargeting,
|
|
26
30
|
getBlocksToRender,
|
|
27
31
|
getPersonalizationScript,
|
|
32
|
+
getUpdateVisibilityStylesScript,
|
|
33
|
+
SDKS_REQUIRING_RESET_APPROACH,
|
|
28
34
|
} from "./helpers";
|
|
29
35
|
import type { PersonalizationContainerProps } from "./personalization-container.types";
|
|
36
|
+
import { setAttrs } from "../helpers";
|
|
30
37
|
|
|
31
38
|
function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
32
39
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
@@ -42,6 +49,15 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
42
49
|
)
|
|
43
50
|
);
|
|
44
51
|
|
|
52
|
+
const [updateVisibilityStylesScript, setUpdateVisibilityStylesScript] =
|
|
53
|
+
useState(() =>
|
|
54
|
+
getUpdateVisibilityStylesScript(
|
|
55
|
+
props.variants,
|
|
56
|
+
props.builderBlock?.id || "none",
|
|
57
|
+
props.builderContext?.rootState?.locale as string | undefined
|
|
58
|
+
)
|
|
59
|
+
);
|
|
60
|
+
|
|
45
61
|
const [unsubscribers, setUnsubscribers] = useState(() => []);
|
|
46
62
|
|
|
47
63
|
const [shouldRenderVariants, setShouldRenderVariants] = useState(() =>
|
|
@@ -51,7 +67,17 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
51
67
|
)
|
|
52
68
|
);
|
|
53
69
|
|
|
54
|
-
const [
|
|
70
|
+
const [shouldResetVariants, setShouldResetVariants] = useState(() => false);
|
|
71
|
+
|
|
72
|
+
function attrs() {
|
|
73
|
+
return {
|
|
74
|
+
...props.attributes,
|
|
75
|
+
...{},
|
|
76
|
+
[getClassPropName()]: `builder-personalization-container ${
|
|
77
|
+
props.attributes[getClassPropName()] || ""
|
|
78
|
+
}`,
|
|
79
|
+
};
|
|
80
|
+
}
|
|
55
81
|
|
|
56
82
|
function filteredVariants() {
|
|
57
83
|
return (props.variants || []).filter((variant) => {
|
|
@@ -75,7 +101,7 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
75
101
|
return getBlocksToRender({
|
|
76
102
|
variants: props.variants,
|
|
77
103
|
fallbackBlocks: props.builderBlock?.children,
|
|
78
|
-
isHydrated:
|
|
104
|
+
isHydrated: shouldResetVariants,
|
|
79
105
|
filteredVariants: filteredVariants(),
|
|
80
106
|
previewingIndex: props.previewingIndex,
|
|
81
107
|
});
|
|
@@ -85,16 +111,19 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
85
111
|
return (props.variants || [])
|
|
86
112
|
.map(
|
|
87
113
|
(_, index) =>
|
|
88
|
-
`[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none; } `
|
|
114
|
+
`div[data-variant-id="${props.builderBlock?.id}-${index}"] { display: none !important; } `
|
|
89
115
|
)
|
|
90
116
|
.join("");
|
|
91
117
|
}
|
|
92
118
|
|
|
93
119
|
useEffect(() => {
|
|
94
|
-
|
|
120
|
+
setShouldResetVariants(true);
|
|
95
121
|
const unsub = userAttributesService.subscribeOnUserAttributesChange(
|
|
96
122
|
(attrs) => {
|
|
97
123
|
setUserAttributes(attrs);
|
|
124
|
+
},
|
|
125
|
+
{
|
|
126
|
+
fireImmediately: TARGET === "qwik",
|
|
98
127
|
}
|
|
99
128
|
);
|
|
100
129
|
if (!(isEditing() || isPreviewing())) {
|
|
@@ -103,7 +132,7 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
103
132
|
rootRef.current.dispatchEvent(
|
|
104
133
|
new CustomEvent("builder.variantLoaded", {
|
|
105
134
|
detail: {
|
|
106
|
-
variant: variant ||
|
|
135
|
+
variant: variant || DEFAULT_INDEX,
|
|
107
136
|
content: props.builderContext?.content,
|
|
108
137
|
},
|
|
109
138
|
bubbles: true,
|
|
@@ -115,7 +144,7 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
115
144
|
rootRef.current.dispatchEvent(
|
|
116
145
|
new CustomEvent("builder.variantDisplayed", {
|
|
117
146
|
detail: {
|
|
118
|
-
variant: variant ||
|
|
147
|
+
variant: variant || DEFAULT_INDEX,
|
|
119
148
|
content: props.builderContext?.content,
|
|
120
149
|
},
|
|
121
150
|
bubbles: true,
|
|
@@ -137,38 +166,85 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
137
166
|
}, []);
|
|
138
167
|
|
|
139
168
|
return (
|
|
140
|
-
<View ref={rootRef} {...
|
|
141
|
-
{
|
|
169
|
+
<View ref={rootRef} {...attrs()}>
|
|
170
|
+
{shouldResetVariants && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) ? (
|
|
171
|
+
<Blocks
|
|
172
|
+
blocks={blocksToRender().blocks}
|
|
173
|
+
parent={props.builderBlock?.id}
|
|
174
|
+
path={blocksToRender().path}
|
|
175
|
+
context={props.builderContext}
|
|
176
|
+
registeredComponents={props.builderComponents}
|
|
177
|
+
BlocksWrapperProps={{
|
|
178
|
+
...props.builderContext?.BlocksWrapperProps,
|
|
179
|
+
"data-variant-id": `${props.builderBlock?.id}-${
|
|
180
|
+
blocksToRender().index
|
|
181
|
+
}`,
|
|
182
|
+
}}
|
|
183
|
+
/>
|
|
184
|
+
) : null}
|
|
185
|
+
{(!shouldResetVariants &&
|
|
186
|
+
SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)) ||
|
|
187
|
+
!SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) ? (
|
|
142
188
|
<>
|
|
143
|
-
{
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
189
|
+
{shouldRenderVariants ? (
|
|
190
|
+
<>
|
|
191
|
+
<InlinedStyles
|
|
192
|
+
nonce={props.builderContext?.nonce || ""}
|
|
193
|
+
styles={hideVariantsStyleString()}
|
|
194
|
+
id={`variants-styles-${props.builderBlock?.id}`}
|
|
195
|
+
/>
|
|
196
|
+
<InlinedScript
|
|
197
|
+
nonce={props.builderContext?.nonce || ""}
|
|
198
|
+
scriptStr={updateVisibilityStylesScript}
|
|
199
|
+
id={`variants-visibility-script-${props.builderBlock?.id}`}
|
|
200
|
+
/>
|
|
201
|
+
{props.variants?.map((variant, index) => (
|
|
202
|
+
<Blocks
|
|
203
|
+
key={`${props.builderBlock?.id}-${index}`}
|
|
204
|
+
BlocksWrapperProps={{
|
|
205
|
+
...props.builderContext?.BlocksWrapperProps,
|
|
206
|
+
"aria-hidden": true,
|
|
207
|
+
hidden: true,
|
|
208
|
+
"data-variant-id": `${props.builderBlock?.id}-${index}`,
|
|
209
|
+
}}
|
|
210
|
+
blocks={variant.blocks}
|
|
211
|
+
parent={props.builderBlock?.id}
|
|
212
|
+
path={`component.options.variants.${index}.blocks`}
|
|
213
|
+
context={props.builderContext}
|
|
214
|
+
registeredComponents={props.builderComponents}
|
|
215
|
+
>
|
|
216
|
+
<InlinedScript
|
|
217
|
+
nonce={props.builderContext?.nonce || ""}
|
|
218
|
+
scriptStr={scriptStr}
|
|
219
|
+
id={`variants-script-${props.builderBlock?.id}-${index}`}
|
|
220
|
+
/>
|
|
221
|
+
</Blocks>
|
|
222
|
+
))}
|
|
223
|
+
</>
|
|
224
|
+
) : null}
|
|
225
|
+
<Blocks
|
|
226
|
+
blocks={blocksToRender().blocks}
|
|
227
|
+
parent={props.builderBlock?.id}
|
|
228
|
+
path={blocksToRender().path}
|
|
229
|
+
context={props.builderContext}
|
|
230
|
+
registeredComponents={props.builderComponents}
|
|
231
|
+
BlocksWrapperProps={{
|
|
232
|
+
...props.builderContext?.BlocksWrapperProps,
|
|
233
|
+
"data-variant-id": `${props.builderBlock?.id}-${
|
|
234
|
+
blocksToRender().index
|
|
235
|
+
}`,
|
|
236
|
+
}}
|
|
237
|
+
>
|
|
238
|
+
{shouldRenderVariants ? (
|
|
239
|
+
<InlinedScript
|
|
240
|
+
nonce={props.builderContext?.nonce || ""}
|
|
241
|
+
scriptStr={scriptStr}
|
|
242
|
+
id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
|
|
152
243
|
/>
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
<InlinedStyles
|
|
156
|
-
nonce={props.builderContext?.nonce || ""}
|
|
157
|
-
styles={hideVariantsStyleString()}
|
|
158
|
-
id={`variants-styles-${props.builderBlock?.id}`}
|
|
159
|
-
/>
|
|
160
|
-
<InlinedScript
|
|
161
|
-
nonce={props.builderContext?.nonce || ""}
|
|
162
|
-
scriptStr={scriptStr}
|
|
163
|
-
id={`variants-script-${props.builderBlock?.id}`}
|
|
164
|
-
/>
|
|
244
|
+
) : null}
|
|
245
|
+
</Blocks>
|
|
165
246
|
</>
|
|
166
247
|
) : null}
|
|
167
|
-
<Blocks
|
|
168
|
-
blocks={blocksToRender().blocks}
|
|
169
|
-
parent={props.builderBlock?.id}
|
|
170
|
-
path={blocksToRender().path}
|
|
171
|
-
/>
|
|
172
248
|
</View>
|
|
173
249
|
);
|
|
174
250
|
}
|
|
@@ -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
|
|
@@ -24,7 +24,19 @@ export type BlocksWrapperProps = {
|
|
|
24
24
|
*/
|
|
25
25
|
BlocksWrapper: any;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* Props to be applied to the wrapping element of blocks. Can be set in two ways:
|
|
28
|
+
* 1. Globally via `<Content blocksWrapperProps={{...}}/>` - applies to all blocks wrappers in the Content
|
|
29
|
+
* 2. Locally via `<Blocks BlocksWrapperProps={{...}}/>` - applies only to this specific blocks instance and overrides global props
|
|
30
|
+
*
|
|
31
|
+
* For merging both global and local props, spread the context props before adding your own:
|
|
32
|
+
* ```
|
|
33
|
+
* <Blocks
|
|
34
|
+
* BlocksWrapperProps={{
|
|
35
|
+
* ...builderContext.BlocksWrapperProps,
|
|
36
|
+
* 'data-test-id': 'my-test-id'
|
|
37
|
+
* }}
|
|
38
|
+
* />
|
|
39
|
+
* ```
|
|
28
40
|
*/
|
|
29
41
|
BlocksWrapperProps: any;
|
|
30
42
|
children?: any;
|
|
@@ -54,14 +54,17 @@ function Blocks(props: BlocksProps) {
|
|
|
54
54
|
parent={props.parent}
|
|
55
55
|
path={props.path}
|
|
56
56
|
styleProp={props.styleProp}
|
|
57
|
+
BlocksWrapperProps={
|
|
58
|
+
props.BlocksWrapperProps ||
|
|
59
|
+
props.context?.BlocksWrapperProps ||
|
|
60
|
+
builderContext?.BlocksWrapperProps
|
|
61
|
+
}
|
|
57
62
|
classNameProp={props.className}
|
|
58
63
|
BlocksWrapper={
|
|
59
64
|
props.context?.BlocksWrapper || builderContext?.BlocksWrapper
|
|
60
65
|
}
|
|
61
|
-
BlocksWrapperProps={
|
|
62
|
-
props.context?.BlocksWrapperProps || builderContext?.BlocksWrapperProps
|
|
63
|
-
}
|
|
64
66
|
>
|
|
67
|
+
{props.children}
|
|
65
68
|
{props.blocks ? (
|
|
66
69
|
<FlatList
|
|
67
70
|
data={props.blocks}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
2
2
|
import type { BlocksWrapperProps } from './blocks-wrapper';
|
|
3
|
-
export type BlocksProps = Partial<Omit<BlocksWrapperProps, 'BlocksWrapper' | '
|
|
3
|
+
export type BlocksProps = Partial<Omit<BlocksWrapperProps, 'BlocksWrapper' | 'classNameProp'>> & {
|
|
4
4
|
context?: BuilderContextInterface;
|
|
5
5
|
registeredComponents?: RegisteredComponents;
|
|
6
6
|
linkComponent?: any;
|
|
@@ -20,6 +20,10 @@ type VariantsProviderProps = ContentVariantsPrps & {
|
|
|
20
20
|
*/
|
|
21
21
|
isNestedRender?: boolean;
|
|
22
22
|
};
|
|
23
|
+
import {
|
|
24
|
+
SDKS_SUPPORTING_PERSONALIZATION,
|
|
25
|
+
getInitPersonalizationVariantsFnsScriptString,
|
|
26
|
+
} from "../../blocks/personalization-container/helpers";
|
|
23
27
|
import { TARGET } from "../../constants/target";
|
|
24
28
|
import { handleABTestingSync } from "../../helpers/ab-tests";
|
|
25
29
|
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
@@ -79,11 +83,20 @@ function ContentVariants(props: VariantsProviderProps) {
|
|
|
79
83
|
return (
|
|
80
84
|
<>
|
|
81
85
|
{!props.isNestedRender && TARGET !== "reactNative" ? (
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
86
|
+
<>
|
|
87
|
+
<InlinedScript
|
|
88
|
+
id="builderio-init-variants-fns"
|
|
89
|
+
scriptStr={getInitVariantsFnsScriptString()}
|
|
90
|
+
nonce={props.nonce || ""}
|
|
91
|
+
/>
|
|
92
|
+
{SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? (
|
|
93
|
+
<InlinedScript
|
|
94
|
+
id="builderio-init-personalization-variants-fns"
|
|
95
|
+
nonce={props.nonce || ""}
|
|
96
|
+
scriptStr={getInitPersonalizationVariantsFnsScriptString()}
|
|
97
|
+
/>
|
|
98
|
+
) : null}
|
|
99
|
+
</>
|
|
87
100
|
) : null}
|
|
88
101
|
{shouldRenderVariants ? (
|
|
89
102
|
<>
|
|
@@ -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.10"
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
+
import { TARGET } from '../constants/target';
|
|
1
2
|
import { isBrowser } from '../functions/is-browser';
|
|
2
3
|
import { getCookieSync, setCookie } from './cookie';
|
|
4
|
+
import { noSerializeWrapper } from './no-serialize-wrapper';
|
|
3
5
|
export interface UserAttributes {
|
|
4
6
|
[key: string]: any;
|
|
5
7
|
}
|
|
@@ -32,18 +34,34 @@ export function createUserAttributesService() {
|
|
|
32
34
|
canTrack
|
|
33
35
|
}) || '{}');
|
|
34
36
|
},
|
|
35
|
-
subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void
|
|
37
|
+
subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void, {
|
|
38
|
+
fireImmediately
|
|
39
|
+
}: {
|
|
40
|
+
fireImmediately?: boolean;
|
|
41
|
+
} = {}) {
|
|
36
42
|
subscribers.add(callback);
|
|
37
|
-
|
|
43
|
+
if (fireImmediately) {
|
|
44
|
+
callback(this.getUserAttributes());
|
|
45
|
+
}
|
|
46
|
+
return noSerializeWrapper(function () {
|
|
38
47
|
subscribers.delete(callback);
|
|
39
|
-
};
|
|
48
|
+
});
|
|
40
49
|
},
|
|
41
50
|
setCanTrack(value: boolean) {
|
|
42
51
|
canTrack = value;
|
|
43
52
|
}
|
|
44
53
|
};
|
|
45
54
|
}
|
|
46
|
-
|
|
55
|
+
let _userAttributesService: ReturnType<typeof createUserAttributesService>;
|
|
56
|
+
if (isBrowser() && TARGET === 'qwik') {
|
|
57
|
+
if (!(window as any).__BUILDER_USER_ATTRIBUTES_SERVICE__) {
|
|
58
|
+
(window as any).__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
|
|
59
|
+
}
|
|
60
|
+
_userAttributesService = (window as any).__BUILDER_USER_ATTRIBUTES_SERVICE__;
|
|
61
|
+
} else {
|
|
62
|
+
_userAttributesService = createUserAttributesService();
|
|
63
|
+
}
|
|
64
|
+
export const userAttributesService = _userAttributesService;
|
|
47
65
|
export const setClientUserAttributes = (attributes: UserAttributes) => {
|
|
48
66
|
userAttributesService.setUserAttributes(attributes);
|
|
49
67
|
}
|