@builder.io/sdk-react-native 4.0.8 → 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/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/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/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/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/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/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/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/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/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/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
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import type { BuilderBlock } from '../../types/builder-block';
|
|
2
|
+
import type { Target } from '../../types/targets';
|
|
2
3
|
import type { PersonalizationContainerProps } from './personalization-container.types';
|
|
4
|
+
export declare const DEFAULT_INDEX = "default";
|
|
3
5
|
export type UserAttributes = {
|
|
4
6
|
date?: string | Date;
|
|
5
7
|
urlPath?: string;
|
|
@@ -12,6 +14,25 @@ export type Query = {
|
|
|
12
14
|
operator: QueryOperator;
|
|
13
15
|
value: QueryValue;
|
|
14
16
|
};
|
|
17
|
+
type BlocksToRenderReturnType = {
|
|
18
|
+
blocks: BuilderBlock[];
|
|
19
|
+
path: string;
|
|
20
|
+
index: number | typeof DEFAULT_INDEX;
|
|
21
|
+
};
|
|
22
|
+
/**
|
|
23
|
+
* SDKs that support Variant Containers
|
|
24
|
+
*/
|
|
25
|
+
export declare const SDKS_SUPPORTING_PERSONALIZATION: Target[];
|
|
26
|
+
/**
|
|
27
|
+
* After hydration, we reset the tree
|
|
28
|
+
* These SDKs handle Personalization Container in a special way:
|
|
29
|
+
* - first, the inlined script will help us add `display: none`, `aria-hidden: true` and `hidden: true` to the non-winning variants
|
|
30
|
+
* - then, on mount / when the component is hydrated - we reset the tree with only the winning variant and deleting the entire tree
|
|
31
|
+
*
|
|
32
|
+
* This helps us to avoid flicker and show the correct / winning variant initially and then once we've hydrated we show the winning variant
|
|
33
|
+
* and keep a track of the cookies to update to the correct variant dynamically when the cookie updates.
|
|
34
|
+
*/
|
|
35
|
+
export declare const SDKS_REQUIRING_RESET_APPROACH: Target[];
|
|
15
36
|
export declare function checkShouldRenderVariants(variants: PersonalizationContainerProps['variants'], canTrack: boolean): boolean;
|
|
16
37
|
export declare function getBlocksToRender({ variants, previewingIndex, isHydrated, filteredVariants, fallbackBlocks }: {
|
|
17
38
|
variants: PersonalizationContainerProps['variants'];
|
|
@@ -19,10 +40,9 @@ export declare function getBlocksToRender({ variants, previewingIndex, isHydrate
|
|
|
19
40
|
isHydrated: boolean;
|
|
20
41
|
filteredVariants: PersonalizationContainerProps['variants'];
|
|
21
42
|
fallbackBlocks?: BuilderBlock[];
|
|
22
|
-
}):
|
|
23
|
-
|
|
24
|
-
path: string | undefined;
|
|
25
|
-
};
|
|
43
|
+
}): BlocksToRenderReturnType;
|
|
44
|
+
export declare const getInitPersonalizationVariantsFnsScriptString: () => string;
|
|
26
45
|
export declare const getPersonalizationScript: (variants: PersonalizationContainerProps['variants'], blockId: string, locale?: string) => string;
|
|
46
|
+
export declare const getUpdateVisibilityStylesScript: (variants: PersonalizationContainerProps['variants'], blockId: string, locale?: string) => string;
|
|
27
47
|
export { filterWithCustomTargeting } from './helpers/inlined-fns';
|
|
28
48
|
//# sourceMappingURL=helpers.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/blocks/personalization-container/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"helpers.d.ts","sourceRoot":"","sources":["../../../../../src/blocks/personalization-container/helpers.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAC;AAElD,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AACvF,eAAO,MAAM,aAAa,YAAY,CAAC;AAIvC,MAAM,MAAM,cAAc,GAAG;IAC3B,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAC;CACpB,CAAC;AACF,KAAK,aAAa,GAAG,IAAI,GAAG,OAAO,GAAG,UAAU,GAAG,YAAY,GAAG,UAAU,GAAG,aAAa,GAAG,UAAU,GAAG,sBAAsB,GAAG,mBAAmB,CAAC;AACzJ,KAAK,UAAU,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,KAAK,CAAC,MAAM,GAAG,MAAM,GAAG,OAAO,CAAC,CAAC;AAC/E,MAAM,MAAM,KAAK,GAAG;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,QAAQ,EAAE,aAAa,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC;CACnB,CAAC;AACF,KAAK,wBAAwB,GAAG;IAC9B,MAAM,EAAE,YAAY,EAAE,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,GAAG,OAAO,aAAa,CAAC;CACtC,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,+BAA+B,UAA2C,CAAC;AAExF;;;;;;;;GAQG;AACH,eAAO,MAAM,6BAA6B,UAAkC,CAAC;AAC7E,wBAAgB,yBAAyB,CAAC,QAAQ,EAAE,6BAA6B,CAAC,UAAU,CAAC,EAAE,QAAQ,EAAE,OAAO,WAQ/G;AACD,wBAAgB,iBAAiB,CAAC,EAChC,QAAQ,EACR,eAAe,EACf,UAAU,EACV,gBAAgB,EAChB,cAAc,EACf,EAAE;IACD,QAAQ,EAAE,6BAA6B,CAAC,UAAU,CAAC,CAAC;IACpD,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,UAAU,EAAE,OAAO,CAAC;IACpB,gBAAgB,EAAE,6BAA6B,CAAC,UAAU,CAAC,CAAC;IAC5D,cAAc,CAAC,EAAE,YAAY,EAAE,CAAC;CACjC,GAAG,wBAAwB,CAuC3B;AACD,eAAO,MAAM,6CAA6C,cAMzD,CAAC;AAEF,eAAO,MAAM,wBAAwB,aAAc,6BAA6B,CAAC,UAAU,CAAC,WAAW,MAAM,WAAW,MAAM,WAE7H,CAAC;AACF,eAAO,MAAM,+BAA+B,aAAc,6BAA6B,CAAC,UAAU,CAAC,WAAW,MAAM,WAAW,MAAM,WAEpI,CAAC;AACF,OAAO,EAAE,yBAAyB,EAAE,MAAM,uBAAuB,CAAA"}
|
package/lib/node/typescript/blocks/personalization-container/personalization-container.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"personalization-container.d.ts","sourceRoot":"","sources":["../../../../../src/blocks/personalization-container/personalization-container.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"personalization-container.d.ts","sourceRoot":"","sources":["../../../../../src/blocks/personalization-container/personalization-container.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAkC/B,OAAO,KAAK,EAAE,6BAA6B,EAAE,MAAM,mCAAmC,CAAC;AAGvF,iBAAS,wBAAwB,CAAC,KAAK,EAAE,6BAA6B,qBAiNrE;AAED,eAAe,wBAAwB,CAAC"}
|
package/lib/node/typescript/blocks/personalization-container/personalization-container.types.d.ts
CHANGED
|
@@ -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,5 +11,5 @@ export type PersonalizationContainerProps = {
|
|
|
11
11
|
startDate?: string;
|
|
12
12
|
endDate?: string;
|
|
13
13
|
}>;
|
|
14
|
-
} & BuilderDataProps;
|
|
14
|
+
} & BuilderDataProps & BuilderComponentsProp;
|
|
15
15
|
//# sourceMappingURL=personalization-container.types.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"personalization-container.types.d.ts","sourceRoot":"","sources":["../../../../../src/blocks/personalization-container/personalization-container.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"personalization-container.types.d.ts","sourceRoot":"","sources":["../../../../../src/blocks/personalization-container/personalization-container.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,KAAK,EAAE,qBAAqB,EAAE,gBAAgB,EAAE,MAAM,2BAA2B,CAAC;AACzF,OAAO,KAAK,EAAE,KAAK,EAAE,MAAM,WAAW,CAAC;AACvC,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,UAAU,CAAC,EAAE,GAAG,CAAC;IACjB,eAAe,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,EAAE,KAAK,CAAC;QACf,MAAM,EAAE,YAAY,EAAE,CAAC;QACvB,KAAK,EAAE,KAAK,EAAE,CAAC;QACf,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,OAAO,CAAC,EAAE,MAAM,CAAC;KAClB,CAAC,CAAC;CACJ,GAAG,gBAAgB,GAAG,qBAAqB,CAAA"}
|
|
@@ -9,7 +9,19 @@ export type BlocksWrapperProps = {
|
|
|
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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks-wrapper.d.ts","sourceRoot":"","sources":["../../../../../src/components/blocks/blocks-wrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAgB/B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3C;;OAEG;IACH,aAAa,EAAE,GAAG,CAAC;IACnB
|
|
1
|
+
{"version":3,"file":"blocks-wrapper.d.ts","sourceRoot":"","sources":["../../../../../src/components/blocks/blocks-wrapper.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAgB/B,MAAM,MAAM,kBAAkB,GAAG;IAC/B,MAAM,EAAE,YAAY,EAAE,GAAG,SAAS,CAAC;IACnC,MAAM,EAAE,MAAM,GAAG,SAAS,CAAC;IAC3B,IAAI,EAAE,MAAM,GAAG,SAAS,CAAC;IACzB,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,SAAS,CAAC;IAC3C;;OAEG;IACH,aAAa,EAAE,GAAG,CAAC;IACnB;;;;;;;;;;;;;;OAcG;IACH,kBAAkB,EAAE,GAAG,CAAC;IACxB,QAAQ,CAAC,EAAE,GAAG,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;CACxB,CAAC;AAEF,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAE9D,iBAAS,aAAa,CAAC,KAAK,EAAE,kBAAkB,qBAkG/C;AAMD,eAAe,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../../../src/components/blocks/blocks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAmB/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,iBAAS,MAAM,CAAC,KAAK,EAAE,WAAW,
|
|
1
|
+
{"version":3,"file":"blocks.d.ts","sourceRoot":"","sources":["../../../../../src/components/blocks/blocks.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAmB/B,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAGlD,iBAAS,MAAM,CAAC,KAAK,EAAE,WAAW,qBA0DjC;;AAED,wBAA4B"}
|
|
@@ -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;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"blocks.types.d.ts","sourceRoot":"","sources":["../../../../../src/components/blocks/blocks.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,eAAe,GAAG,
|
|
1
|
+
{"version":3,"file":"blocks.types.d.ts","sourceRoot":"","sources":["../../../../../src/components/blocks/blocks.types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,qBAAqB,CAAC;AACzF,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,kBAAkB,CAAC;AAC3D,MAAM,MAAM,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC,kBAAkB,EAAE,eAAe,GAAG,eAAe,CAAC,CAAC,GAAG;IAC/F,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;IAC5C,aAAa,CAAC,EAAE,GAAG,CAAC;IACpB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB,CAAA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"content-variants.d.ts","sourceRoot":"","sources":["../../../../../src/components/content-variants/content-variants.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAgB/B,KAAK,qBAAqB,GAAG,mBAAmB,GAAG;IACjD;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;
|
|
1
|
+
{"version":3,"file":"content-variants.d.ts","sourceRoot":"","sources":["../../../../../src/components/content-variants/content-variants.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAgB/B,KAAK,qBAAqB,GAAG,mBAAmB,GAAG;IACjD;;OAEG;IACH,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B,CAAC;AAWF,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAQpE,iBAAS,eAAe,CAAC,KAAK,EAAE,qBAAqB,qBAmIpD;AAED,eAAe,eAAe,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"builder-registered-components.d.ts","sourceRoot":"","sources":["../../../../src/constants/builder-registered-components.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"builder-registered-components.d.ts","sourceRoot":"","sources":["../../../../src/constants/builder-registered-components.ts"],"names":[],"mappings":"AAuBA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAI5D;;;GAGG;AACH,eAAO,MAAM,8BAA8B,EAAE,MAAM,mBAAmB,EAiCzC,CAAA"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.0.
|
|
1
|
+
export declare const SDK_VERSION = "4.0.9";
|
|
2
2
|
//# sourceMappingURL=sdk-version.d.ts.map
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react-native",
|
|
3
3
|
"description": "Builder.io SDK for React Native",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.9",
|
|
5
5
|
"homepage": "https://github.com/BuilderIO/builder/tree/main/packages/sdks/output/react-native",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
@@ -3,7 +3,8 @@ export const componentInfo: ComponentInfo = {
|
|
|
3
3
|
name: 'PersonalizationContainer',
|
|
4
4
|
shouldReceiveBuilderProps: {
|
|
5
5
|
builderBlock: true,
|
|
6
|
-
builderContext: true
|
|
6
|
+
builderContext: true,
|
|
7
|
+
builderComponents: true
|
|
7
8
|
},
|
|
8
9
|
noWrap: true,
|
|
9
10
|
image: 'https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a',
|
|
@@ -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'
|
|
@@ -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
|
|
@@ -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;
|