@builder.io/sdk-react-native 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/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 +81 -38
- package/lib/browser/commonjs/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/browser/commonjs/blocks/symbol/symbol.js +11 -4
- package/lib/browser/commonjs/blocks/symbol/symbol.js.map +1 -1
- package/lib/browser/commonjs/components/block/components/interactive-element.js +5 -1
- package/lib/browser/commonjs/components/block/components/interactive-element.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/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 +82 -39
- package/lib/browser/module/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/browser/module/blocks/symbol/symbol.js +11 -4
- package/lib/browser/module/blocks/symbol/symbol.js.map +1 -1
- package/lib/browser/module/components/block/components/interactive-element.js +4 -0
- package/lib/browser/module/components/block/components/interactive-element.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/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/blocks/symbol/symbol.d.ts.map +1 -1
- package/lib/browser/typescript/components/block/components/interactive-element.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/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 +81 -38
- package/lib/edge/commonjs/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/edge/commonjs/blocks/symbol/symbol.js +11 -4
- package/lib/edge/commonjs/blocks/symbol/symbol.js.map +1 -1
- package/lib/edge/commonjs/components/block/components/interactive-element.js +5 -1
- package/lib/edge/commonjs/components/block/components/interactive-element.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/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 +82 -39
- package/lib/edge/module/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/edge/module/blocks/symbol/symbol.js +11 -4
- package/lib/edge/module/blocks/symbol/symbol.js.map +1 -1
- package/lib/edge/module/components/block/components/interactive-element.js +4 -0
- package/lib/edge/module/components/block/components/interactive-element.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/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/blocks/symbol/symbol.d.ts.map +1 -1
- package/lib/edge/typescript/components/block/components/interactive-element.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/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 +81 -38
- package/lib/node/commonjs/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/node/commonjs/blocks/symbol/symbol.js +11 -4
- package/lib/node/commonjs/blocks/symbol/symbol.js.map +1 -1
- package/lib/node/commonjs/components/block/components/interactive-element.js +5 -1
- package/lib/node/commonjs/components/block/components/interactive-element.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/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 +82 -39
- package/lib/node/module/blocks/personalization-container/personalization-container.js.map +1 -1
- package/lib/node/module/blocks/symbol/symbol.js +11 -4
- package/lib/node/module/blocks/symbol/symbol.js.map +1 -1
- package/lib/node/module/components/block/components/interactive-element.js +4 -0
- package/lib/node/module/components/block/components/interactive-element.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/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/blocks/symbol/symbol.d.ts.map +1 -1
- package/lib/node/typescript/components/block/components/interactive-element.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/package.json +1 -1
- 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 +107 -34
- package/src/blocks/personalization-container/personalization-container.types.ts +2 -2
- package/src/blocks/symbol/symbol.tsx +4 -1
- package/src/components/block/components/interactive-element.tsx +5 -0
- 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
|
@@ -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'
|
|
@@ -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,13 +111,13 @@ 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);
|
|
@@ -103,7 +129,7 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
103
129
|
rootRef.current.dispatchEvent(
|
|
104
130
|
new CustomEvent("builder.variantLoaded", {
|
|
105
131
|
detail: {
|
|
106
|
-
variant: variant ||
|
|
132
|
+
variant: variant || DEFAULT_INDEX,
|
|
107
133
|
content: props.builderContext?.content,
|
|
108
134
|
},
|
|
109
135
|
bubbles: true,
|
|
@@ -115,7 +141,7 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
115
141
|
rootRef.current.dispatchEvent(
|
|
116
142
|
new CustomEvent("builder.variantDisplayed", {
|
|
117
143
|
detail: {
|
|
118
|
-
variant: variant ||
|
|
144
|
+
variant: variant || DEFAULT_INDEX,
|
|
119
145
|
content: props.builderContext?.content,
|
|
120
146
|
},
|
|
121
147
|
bubbles: true,
|
|
@@ -137,38 +163,85 @@ function PersonalizationContainer(props: PersonalizationContainerProps) {
|
|
|
137
163
|
}, []);
|
|
138
164
|
|
|
139
165
|
return (
|
|
140
|
-
<View ref={rootRef} {...
|
|
141
|
-
{
|
|
166
|
+
<View ref={rootRef} {...attrs()}>
|
|
167
|
+
{shouldResetVariants && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) ? (
|
|
168
|
+
<Blocks
|
|
169
|
+
blocks={blocksToRender().blocks}
|
|
170
|
+
parent={props.builderBlock?.id}
|
|
171
|
+
path={blocksToRender().path}
|
|
172
|
+
context={props.builderContext}
|
|
173
|
+
registeredComponents={props.builderComponents}
|
|
174
|
+
BlocksWrapperProps={{
|
|
175
|
+
...props.builderContext?.BlocksWrapperProps,
|
|
176
|
+
"data-variant-id": `${props.builderBlock?.id}-${
|
|
177
|
+
blocksToRender().index
|
|
178
|
+
}`,
|
|
179
|
+
}}
|
|
180
|
+
/>
|
|
181
|
+
) : null}
|
|
182
|
+
{(!shouldResetVariants &&
|
|
183
|
+
SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)) ||
|
|
184
|
+
!SDKS_REQUIRING_RESET_APPROACH.includes(TARGET) ? (
|
|
142
185
|
<>
|
|
143
|
-
{
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
186
|
+
{shouldRenderVariants ? (
|
|
187
|
+
<>
|
|
188
|
+
<InlinedStyles
|
|
189
|
+
nonce={props.builderContext?.nonce || ""}
|
|
190
|
+
styles={hideVariantsStyleString()}
|
|
191
|
+
id={`variants-styles-${props.builderBlock?.id}`}
|
|
192
|
+
/>
|
|
193
|
+
<InlinedScript
|
|
194
|
+
nonce={props.builderContext?.nonce || ""}
|
|
195
|
+
scriptStr={updateVisibilityStylesScript}
|
|
196
|
+
id={`variants-visibility-script-${props.builderBlock?.id}`}
|
|
197
|
+
/>
|
|
198
|
+
{props.variants?.map((variant, index) => (
|
|
199
|
+
<Blocks
|
|
200
|
+
key={`${props.builderBlock?.id}-${index}`}
|
|
201
|
+
BlocksWrapperProps={{
|
|
202
|
+
...props.builderContext?.BlocksWrapperProps,
|
|
203
|
+
"aria-hidden": true,
|
|
204
|
+
hidden: true,
|
|
205
|
+
"data-variant-id": `${props.builderBlock?.id}-${index}`,
|
|
206
|
+
}}
|
|
207
|
+
blocks={variant.blocks}
|
|
208
|
+
parent={props.builderBlock?.id}
|
|
209
|
+
path={`component.options.variants.${index}.blocks`}
|
|
210
|
+
context={props.builderContext}
|
|
211
|
+
registeredComponents={props.builderComponents}
|
|
212
|
+
>
|
|
213
|
+
<InlinedScript
|
|
214
|
+
nonce={props.builderContext?.nonce || ""}
|
|
215
|
+
scriptStr={scriptStr}
|
|
216
|
+
id={`variants-script-${props.builderBlock?.id}-${index}`}
|
|
217
|
+
/>
|
|
218
|
+
</Blocks>
|
|
219
|
+
))}
|
|
220
|
+
</>
|
|
221
|
+
) : null}
|
|
222
|
+
<Blocks
|
|
223
|
+
blocks={blocksToRender().blocks}
|
|
224
|
+
parent={props.builderBlock?.id}
|
|
225
|
+
path={blocksToRender().path}
|
|
226
|
+
context={props.builderContext}
|
|
227
|
+
registeredComponents={props.builderComponents}
|
|
228
|
+
BlocksWrapperProps={{
|
|
229
|
+
...props.builderContext?.BlocksWrapperProps,
|
|
230
|
+
"data-variant-id": `${props.builderBlock?.id}-${
|
|
231
|
+
blocksToRender().index
|
|
232
|
+
}`,
|
|
233
|
+
}}
|
|
234
|
+
>
|
|
235
|
+
{shouldRenderVariants ? (
|
|
236
|
+
<InlinedScript
|
|
237
|
+
nonce={props.builderContext?.nonce || ""}
|
|
238
|
+
scriptStr={scriptStr}
|
|
239
|
+
id={`variants-script-${props.builderBlock?.id}-${DEFAULT_INDEX}`}
|
|
152
240
|
/>
|
|
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
|
-
/>
|
|
241
|
+
) : null}
|
|
242
|
+
</Blocks>
|
|
165
243
|
</>
|
|
166
244
|
) : null}
|
|
167
|
-
<Blocks
|
|
168
|
-
blocks={blocksToRender().blocks}
|
|
169
|
-
parent={props.builderBlock?.id}
|
|
170
|
-
path={blocksToRender().path}
|
|
171
|
-
/>
|
|
172
245
|
</View>
|
|
173
246
|
);
|
|
174
247
|
}
|
|
@@ -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
|
|
@@ -47,14 +47,17 @@ function Symbol(props: SymbolProps) {
|
|
|
47
47
|
|
|
48
48
|
const [contentToUse, setContentToUse] = useState(() => props.symbol?.content);
|
|
49
49
|
|
|
50
|
+
const [symbolEntry, setSymbolEntry] = useState(() => props.symbol?.entry);
|
|
51
|
+
|
|
50
52
|
function setContent() {
|
|
51
|
-
if (contentToUse) return;
|
|
53
|
+
if (contentToUse && symbolEntry === props.symbol?.entry) return;
|
|
52
54
|
fetchSymbolContent({
|
|
53
55
|
symbol: props.symbol,
|
|
54
56
|
builderContextValue: props.builderContext,
|
|
55
57
|
}).then((newContent) => {
|
|
56
58
|
if (newContent) {
|
|
57
59
|
setContentToUse(newContent);
|
|
60
|
+
setSymbolEntry(props.symbol?.entry);
|
|
58
61
|
}
|
|
59
62
|
});
|
|
60
63
|
}
|
|
@@ -12,6 +12,7 @@ import {
|
|
|
12
12
|
Button,
|
|
13
13
|
Linking,
|
|
14
14
|
} from "react-native";
|
|
15
|
+
import { useState, useEffect } from "react";
|
|
15
16
|
|
|
16
17
|
export type InteractiveElementProps = {
|
|
17
18
|
Wrapper: any;
|
|
@@ -29,6 +30,8 @@ import type { Dictionary } from "../../../types/typescript";
|
|
|
29
30
|
import Awaiter from "../../awaiter";
|
|
30
31
|
|
|
31
32
|
function InteractiveElement(props: InteractiveElementProps) {
|
|
33
|
+
const [forceRenderCount, setForceRenderCount] = useState(() => 0);
|
|
34
|
+
|
|
32
35
|
function attributes() {
|
|
33
36
|
return props.includeBlockProps
|
|
34
37
|
? {
|
|
@@ -51,6 +54,8 @@ function InteractiveElement(props: InteractiveElementProps) {
|
|
|
51
54
|
return props.wrapperProps;
|
|
52
55
|
}
|
|
53
56
|
|
|
57
|
+
useEffect(() => {}, [props.wrapperProps, props.block?.component?.options]);
|
|
58
|
+
|
|
54
59
|
return (
|
|
55
60
|
<>
|
|
56
61
|
{props.Wrapper.load ? (
|
|
@@ -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.9"
|