@builder.io/sdk-svelte 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/blocks/form/form/form.svelte +34 -12
- package/lib/browser/blocks/personalization-container/component-info.js +2 -1
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.js +45 -1
- package/lib/browser/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/browser/blocks/personalization-container/helpers.js +50 -19
- package/lib/browser/blocks/personalization-container/personalization-container.svelte +88 -38
- package/lib/browser/blocks/personalization-container/personalization-container.svelte.d.ts +2 -1
- package/lib/browser/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/browser/components/blocks/blocks.svelte +6 -4
- package/lib/browser/components/blocks/blocks.svelte.d.ts +5 -2
- package/lib/browser/components/blocks/blocks.types.d.ts +1 -1
- package/lib/browser/components/content-variants/content-variants.svelte +9 -0
- package/lib/browser/constants/builder-registered-components.js +2 -1
- package/lib/browser/constants/sdk-version.d.ts +1 -1
- package/lib/browser/constants/sdk-version.js +1 -1
- package/lib/browser/helpers/no-serialize-wrapper.d.ts +1 -0
- package/lib/browser/helpers/no-serialize-wrapper.js +3 -0
- package/lib/browser/helpers/user-attributes.d.ts +6 -2
- package/lib/browser/helpers/user-attributes.js +19 -4
- package/lib/edge/blocks/form/form/form.svelte +34 -12
- package/lib/edge/blocks/personalization-container/component-info.js +2 -1
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.js +45 -1
- package/lib/edge/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/edge/blocks/personalization-container/helpers.js +50 -19
- package/lib/edge/blocks/personalization-container/personalization-container.svelte +88 -38
- package/lib/edge/blocks/personalization-container/personalization-container.svelte.d.ts +2 -1
- package/lib/edge/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/edge/components/blocks/blocks.svelte +6 -4
- package/lib/edge/components/blocks/blocks.svelte.d.ts +5 -2
- package/lib/edge/components/blocks/blocks.types.d.ts +1 -1
- package/lib/edge/components/content-variants/content-variants.svelte +9 -0
- package/lib/edge/constants/builder-registered-components.js +2 -1
- package/lib/edge/constants/sdk-version.d.ts +1 -1
- package/lib/edge/constants/sdk-version.js +1 -1
- package/lib/edge/helpers/no-serialize-wrapper.d.ts +1 -0
- package/lib/edge/helpers/no-serialize-wrapper.js +3 -0
- package/lib/edge/helpers/user-attributes.d.ts +6 -2
- package/lib/edge/helpers/user-attributes.js +19 -4
- package/lib/node/blocks/form/form/form.svelte +34 -12
- package/lib/node/blocks/personalization-container/component-info.js +2 -1
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.js +45 -1
- package/lib/node/blocks/personalization-container/helpers.d.ts +24 -4
- package/lib/node/blocks/personalization-container/helpers.js +50 -19
- package/lib/node/blocks/personalization-container/personalization-container.svelte +88 -38
- package/lib/node/blocks/personalization-container/personalization-container.svelte.d.ts +2 -1
- package/lib/node/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/lib/node/components/blocks/blocks.svelte +6 -4
- package/lib/node/components/blocks/blocks.svelte.d.ts +5 -2
- package/lib/node/components/blocks/blocks.types.d.ts +1 -1
- package/lib/node/components/content-variants/content-variants.svelte +9 -0
- package/lib/node/constants/builder-registered-components.js +2 -1
- package/lib/node/constants/sdk-version.d.ts +1 -1
- package/lib/node/constants/sdk-version.js +1 -1
- package/lib/node/helpers/no-serialize-wrapper.d.ts +1 -0
- package/lib/node/helpers/no-serialize-wrapper.js +3 -0
- package/lib/node/helpers/user-attributes.d.ts +6 -2
- package/lib/node/helpers/user-attributes.js +19 -4
- package/package.json +2 -2
- package/src/blocks/form/form/form.svelte +37 -12
- package/src/blocks/personalization-container/component-info.ts +2 -1
- package/src/blocks/personalization-container/helpers/inlined-fns.ts +42 -2
- package/src/blocks/personalization-container/helpers.ts +60 -24
- package/src/blocks/personalization-container/personalization-container.svelte +98 -38
- package/src/blocks/personalization-container/personalization-container.types.ts +2 -2
- package/src/components/blocks/blocks-wrapper.svelte +13 -1
- package/src/components/blocks/blocks.svelte +7 -4
- package/src/components/blocks/blocks.types.ts +1 -1
- package/src/components/content-variants/content-variants.svelte +12 -0
- package/src/constants/builder-registered-components.ts +2 -1
- package/src/constants/sdk-version.ts +1 -1
- package/src/helpers/no-serialize-wrapper.ts +3 -0
- package/src/helpers/user-attributes.ts +22 -4
|
@@ -2,16 +2,28 @@
|
|
|
2
2
|
import Blocks from "../../components/blocks/blocks.svelte";
|
|
3
3
|
import InlinedScript from "../../components/inlined-script.svelte";
|
|
4
4
|
import InlinedStyles from "../../components/inlined-styles.svelte";
|
|
5
|
+
import { TARGET } from "../../constants/target";
|
|
6
|
+
import { getClassPropName } from "../../functions/get-class-prop-name";
|
|
5
7
|
import { isEditing } from "../../functions/is-editing";
|
|
6
8
|
import { isPreviewing } from "../../functions/is-previewing";
|
|
7
9
|
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
8
10
|
import { userAttributesService } from "../../helpers/user-attributes";
|
|
9
|
-
import {
|
|
11
|
+
import { filterAttrs } from "../helpers";
|
|
12
|
+
import { checkShouldRenderVariants, DEFAULT_INDEX, filterWithCustomTargeting, getBlocksToRender, getPersonalizationScript, getUpdateVisibilityStylesScript, SDKS_REQUIRING_RESET_APPROACH, } from "./helpers";
|
|
13
|
+
import "../helpers";
|
|
10
14
|
export let builderContext;
|
|
11
15
|
export let variants = undefined;
|
|
12
16
|
export let builderBlock;
|
|
13
|
-
export let previewingIndex = undefined;
|
|
14
17
|
export let attributes = undefined;
|
|
18
|
+
export let previewingIndex = undefined;
|
|
19
|
+
export let builderComponents;
|
|
20
|
+
$: attrs = () => {
|
|
21
|
+
return {
|
|
22
|
+
...filterAttrs(attributes, "on:", false),
|
|
23
|
+
...filterAttrs(attributes, "on:", true),
|
|
24
|
+
[getClassPropName()]: `builder-personalization-container ${attributes[getClassPropName()] || ""}`,
|
|
25
|
+
};
|
|
26
|
+
};
|
|
15
27
|
$: filteredVariants = () => {
|
|
16
28
|
return (variants || []).filter((variant) => {
|
|
17
29
|
return filterWithCustomTargeting({
|
|
@@ -28,33 +40,36 @@ $: blocksToRender = () => {
|
|
|
28
40
|
return getBlocksToRender({
|
|
29
41
|
variants: variants,
|
|
30
42
|
fallbackBlocks: builderBlock?.children,
|
|
31
|
-
isHydrated:
|
|
43
|
+
isHydrated: shouldResetVariants,
|
|
32
44
|
filteredVariants: filteredVariants(),
|
|
33
45
|
previewingIndex: previewingIndex,
|
|
34
46
|
});
|
|
35
47
|
};
|
|
36
48
|
$: hideVariantsStyleString = () => {
|
|
37
49
|
return (variants || [])
|
|
38
|
-
.map((_, index) => `[data-variant-id="${builderBlock?.id}-${index}"] { display: none; } `)
|
|
50
|
+
.map((_, index) => `div[data-variant-id="${builderBlock?.id}-${index}"] { display: none !important; } `)
|
|
39
51
|
.join("");
|
|
40
52
|
};
|
|
41
53
|
let rootRef;
|
|
42
54
|
let userAttributes = userAttributesService.getUserAttributes();
|
|
43
55
|
let scriptStr = getPersonalizationScript(variants, builderBlock?.id || "none", $builderContext?.rootState?.locale);
|
|
56
|
+
let updateVisibilityStylesScript = getUpdateVisibilityStylesScript(variants, builderBlock?.id || "none", $builderContext?.rootState?.locale);
|
|
44
57
|
let unsubscribers = [];
|
|
45
58
|
let shouldRenderVariants = checkShouldRenderVariants(variants, getDefaultCanTrack($builderContext?.canTrack));
|
|
46
|
-
let
|
|
59
|
+
let shouldResetVariants = false;
|
|
47
60
|
onMount(() => {
|
|
48
|
-
|
|
61
|
+
shouldResetVariants = true;
|
|
49
62
|
const unsub = userAttributesService.subscribeOnUserAttributesChange((attrs) => {
|
|
50
63
|
userAttributes = attrs;
|
|
64
|
+
}, {
|
|
65
|
+
fireImmediately: TARGET === "qwik",
|
|
51
66
|
});
|
|
52
67
|
if (!(isEditing() || isPreviewing())) {
|
|
53
68
|
const variant = filteredVariants()[0];
|
|
54
69
|
if (rootRef) {
|
|
55
70
|
rootRef.dispatchEvent(new CustomEvent("builder.variantLoaded", {
|
|
56
71
|
detail: {
|
|
57
|
-
variant: variant ||
|
|
72
|
+
variant: variant || DEFAULT_INDEX,
|
|
58
73
|
content: $builderContext?.content,
|
|
59
74
|
},
|
|
60
75
|
bubbles: true,
|
|
@@ -64,7 +79,7 @@ onMount(() => {
|
|
|
64
79
|
if (entry.isIntersecting && rootRef) {
|
|
65
80
|
rootRef.dispatchEvent(new CustomEvent("builder.variantDisplayed", {
|
|
66
81
|
detail: {
|
|
67
|
-
variant: variant ||
|
|
82
|
+
variant: variant || DEFAULT_INDEX,
|
|
68
83
|
content: $builderContext?.content,
|
|
69
84
|
},
|
|
70
85
|
bubbles: true,
|
|
@@ -82,37 +97,72 @@ onDestroy(() => {
|
|
|
82
97
|
});
|
|
83
98
|
</script>
|
|
84
99
|
|
|
85
|
-
<div
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
100
|
+
<div bind:this={rootRef} {...attrs()}>
|
|
101
|
+
{#if shouldResetVariants && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
|
|
102
|
+
<Blocks
|
|
103
|
+
blocks={blocksToRender().blocks}
|
|
104
|
+
parent={builderBlock?.id}
|
|
105
|
+
path={blocksToRender().path}
|
|
106
|
+
context={builderContext}
|
|
107
|
+
registeredComponents={builderComponents}
|
|
108
|
+
BlocksWrapperProps={{
|
|
109
|
+
...$builderContext?.BlocksWrapperProps,
|
|
110
|
+
"data-variant-id": `${builderBlock?.id}-${blocksToRender().index}`,
|
|
111
|
+
}}
|
|
112
|
+
/>
|
|
113
|
+
{/if}
|
|
114
|
+
{#if (!shouldResetVariants && SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)) || !SDKS_REQUIRING_RESET_APPROACH.includes(TARGET)}
|
|
115
|
+
{#if shouldRenderVariants}
|
|
116
|
+
<InlinedStyles
|
|
117
|
+
nonce={$builderContext?.nonce || ""}
|
|
118
|
+
styles={hideVariantsStyleString()}
|
|
119
|
+
id={`variants-styles-${builderBlock?.id}`}
|
|
120
|
+
/>
|
|
121
|
+
<InlinedScript
|
|
122
|
+
nonce={$builderContext?.nonce || ""}
|
|
123
|
+
scriptStr={updateVisibilityStylesScript}
|
|
124
|
+
id={`variants-visibility-script-${builderBlock?.id}`}
|
|
125
|
+
/>
|
|
126
|
+
|
|
127
|
+
{#each variants as variant, index (`${builderBlock?.id}-${index}`)}
|
|
128
|
+
<Blocks
|
|
129
|
+
BlocksWrapperProps={{
|
|
130
|
+
...$builderContext?.BlocksWrapperProps,
|
|
131
|
+
"aria-hidden": true,
|
|
132
|
+
hidden: true,
|
|
133
|
+
"data-variant-id": `${builderBlock?.id}-${index}`,
|
|
134
|
+
}}
|
|
96
135
|
blocks={variant.blocks}
|
|
97
136
|
parent={builderBlock?.id}
|
|
98
137
|
path={`component.options.variants.${index}.blocks`}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
{
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
138
|
+
context={builderContext}
|
|
139
|
+
registeredComponents={builderComponents}
|
|
140
|
+
><InlinedScript
|
|
141
|
+
nonce={$builderContext?.nonce || ""}
|
|
142
|
+
{scriptStr}
|
|
143
|
+
id={`variants-script-${builderBlock?.id}-${index}`}
|
|
144
|
+
/></Blocks
|
|
145
|
+
>
|
|
146
|
+
{/each}
|
|
147
|
+
{/if}
|
|
148
|
+
<Blocks
|
|
149
|
+
blocks={blocksToRender().blocks}
|
|
150
|
+
parent={builderBlock?.id}
|
|
151
|
+
path={blocksToRender().path}
|
|
152
|
+
context={builderContext}
|
|
153
|
+
registeredComponents={builderComponents}
|
|
154
|
+
BlocksWrapperProps={{
|
|
155
|
+
...$builderContext?.BlocksWrapperProps,
|
|
156
|
+
"data-variant-id": `${builderBlock?.id}-${blocksToRender().index}`,
|
|
157
|
+
}}
|
|
158
|
+
>
|
|
159
|
+
{#if shouldRenderVariants}
|
|
160
|
+
<InlinedScript
|
|
161
|
+
nonce={$builderContext?.nonce || ""}
|
|
162
|
+
{scriptStr}
|
|
163
|
+
id={`variants-script-${builderBlock?.id}-${DEFAULT_INDEX}`}
|
|
164
|
+
/>
|
|
165
|
+
{/if}</Blocks
|
|
166
|
+
>
|
|
167
|
+
{/if}
|
|
118
168
|
</div>
|
|
@@ -5,8 +5,9 @@ declare const __propDef: {
|
|
|
5
5
|
builderContext: PersonalizationContainerProps["builderContext"];
|
|
6
6
|
variants?: PersonalizationContainerProps["variants"];
|
|
7
7
|
builderBlock: PersonalizationContainerProps["builderBlock"];
|
|
8
|
-
previewingIndex?: PersonalizationContainerProps["previewingIndex"];
|
|
9
8
|
attributes?: PersonalizationContainerProps["attributes"];
|
|
9
|
+
previewingIndex?: PersonalizationContainerProps["previewingIndex"];
|
|
10
|
+
builderComponents: PersonalizationContainerProps["builderComponents"];
|
|
10
11
|
};
|
|
11
12
|
events: {
|
|
12
13
|
[evt: string]: CustomEvent<any>;
|
|
@@ -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;
|
|
@@ -7,8 +7,9 @@ export let blocks;
|
|
|
7
7
|
export let parent;
|
|
8
8
|
export let path;
|
|
9
9
|
export let styleProp;
|
|
10
|
-
export let
|
|
10
|
+
export let BlocksWrapperProps;
|
|
11
11
|
export let context = undefined;
|
|
12
|
+
export let className = undefined;
|
|
12
13
|
export let linkComponent = undefined;
|
|
13
14
|
export let registeredComponents = undefined;
|
|
14
15
|
let builderContext = getContext(BuilderContext.key);
|
|
@@ -20,11 +21,12 @@ let componentsContext = getContext(ComponentsContext.key);
|
|
|
20
21
|
{parent}
|
|
21
22
|
{path}
|
|
22
23
|
{styleProp}
|
|
24
|
+
BlocksWrapperProps={BlocksWrapperProps ||
|
|
25
|
+
$context?.BlocksWrapperProps ||
|
|
26
|
+
$builderContext?.BlocksWrapperProps}
|
|
23
27
|
classNameProp={className}
|
|
24
28
|
BlocksWrapper={$context?.BlocksWrapper || $builderContext?.BlocksWrapper}
|
|
25
|
-
|
|
26
|
-
$builderContext?.BlocksWrapperProps}
|
|
27
|
-
>
|
|
29
|
+
><slot />
|
|
28
30
|
{#if blocks}
|
|
29
31
|
{#each blocks as block (block.id)}
|
|
30
32
|
<Block
|
|
@@ -6,15 +6,18 @@ declare const __propDef: {
|
|
|
6
6
|
parent: BlocksProps["parent"];
|
|
7
7
|
path: BlocksProps["path"];
|
|
8
8
|
styleProp: BlocksProps["styleProp"];
|
|
9
|
-
|
|
9
|
+
BlocksWrapperProps: BlocksProps["BlocksWrapperProps"];
|
|
10
10
|
context?: BlocksProps["context"];
|
|
11
|
+
className?: BlocksProps["className"];
|
|
11
12
|
linkComponent?: BlocksProps["linkComponent"];
|
|
12
13
|
registeredComponents?: BlocksProps["registeredComponents"];
|
|
13
14
|
};
|
|
14
15
|
events: {
|
|
15
16
|
[evt: string]: CustomEvent<any>;
|
|
16
17
|
};
|
|
17
|
-
slots: {
|
|
18
|
+
slots: {
|
|
19
|
+
default: {};
|
|
20
|
+
};
|
|
18
21
|
};
|
|
19
22
|
type BlocksProps_ = typeof __propDef.props;
|
|
20
23
|
export { BlocksProps_ as BlocksProps };
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import type { Writable } from "svelte/store";
|
|
3
3
|
import type { BuilderContextInterface, RegisteredComponents } from '../../context/types';
|
|
4
4
|
import type { BlocksWrapperProps } from './blocks-wrapper.svelte';
|
|
5
|
-
export type BlocksProps = Partial<Omit<BlocksWrapperProps, 'BlocksWrapper' | '
|
|
5
|
+
export type BlocksProps = Partial<Omit<BlocksWrapperProps, 'BlocksWrapper' | 'classNameProp'>> & {
|
|
6
6
|
context?: Writable<BuilderContextInterface>;
|
|
7
7
|
registeredComponents?: RegisteredComponents;
|
|
8
8
|
linkComponent?: any;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<script context="module"></script>
|
|
2
2
|
|
|
3
3
|
<script>import { onMount } from "svelte";
|
|
4
|
+
import { SDKS_SUPPORTING_PERSONALIZATION, getInitPersonalizationVariantsFnsScriptString, } from "../../blocks/personalization-container/helpers";
|
|
4
5
|
import { TARGET } from "../../constants/target";
|
|
5
6
|
import { handleABTestingSync } from "../../helpers/ab-tests";
|
|
6
7
|
import { getDefaultCanTrack } from "../../helpers/canTrack";
|
|
@@ -67,6 +68,14 @@ onMount(() => {
|
|
|
67
68
|
scriptStr={getInitVariantsFnsScriptString()}
|
|
68
69
|
nonce={nonce || ""}
|
|
69
70
|
/>
|
|
71
|
+
|
|
72
|
+
{#if SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET)}
|
|
73
|
+
<InlinedScript
|
|
74
|
+
id="builderio-init-personalization-variants-fns"
|
|
75
|
+
nonce={nonce || ""}
|
|
76
|
+
scriptStr={getInitPersonalizationVariantsFnsScriptString()}
|
|
77
|
+
/>
|
|
78
|
+
{/if}
|
|
70
79
|
{/if}
|
|
71
80
|
|
|
72
81
|
{#if shouldRenderVariants}
|
|
@@ -9,6 +9,7 @@ import { default as Fragment } from '../blocks/fragment/index';
|
|
|
9
9
|
import { componentInfo as imageComponentInfo } from '../blocks/image/component-info';
|
|
10
10
|
import { default as Image } from '../blocks/image/index';
|
|
11
11
|
import { componentInfo as personalizationContainerComponentInfo } from '../blocks/personalization-container/component-info';
|
|
12
|
+
import { SDKS_SUPPORTING_PERSONALIZATION } from '../blocks/personalization-container/helpers';
|
|
12
13
|
import { default as PersonalizationContainer } from '../blocks/personalization-container/index';
|
|
13
14
|
import { componentInfo as sectionComponentInfo } from '../blocks/section/component-info';
|
|
14
15
|
import { default as Section } from '../blocks/section/index';
|
|
@@ -50,7 +51,7 @@ export const getDefaultRegisteredComponents = () => [{
|
|
|
50
51
|
}, {
|
|
51
52
|
component: Text,
|
|
52
53
|
...textComponentInfo
|
|
53
|
-
}, ...(TARGET
|
|
54
|
+
}, ...(SDKS_SUPPORTING_PERSONALIZATION.includes(TARGET) ? [{
|
|
54
55
|
component: PersonalizationContainer,
|
|
55
56
|
...personalizationContainerComponentInfo
|
|
56
57
|
}] : []), ...(TARGET === 'rsc' ? [] : [{
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const SDK_VERSION = "4.0.
|
|
1
|
+
export declare const SDK_VERSION = "4.0.10";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export const SDK_VERSION = "4.0.
|
|
1
|
+
export const SDK_VERSION = "4.0.10";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function noSerializeWrapper(fn: () => void): () => void;
|
|
@@ -5,13 +5,17 @@ export declare const USER_ATTRIBUTES_COOKIE_NAME = "builder.userAttributes";
|
|
|
5
5
|
export declare function createUserAttributesService(): {
|
|
6
6
|
setUserAttributes(newAttrs: UserAttributes): void;
|
|
7
7
|
getUserAttributes(): any;
|
|
8
|
-
subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void
|
|
8
|
+
subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void, { fireImmediately }?: {
|
|
9
|
+
fireImmediately?: boolean | undefined;
|
|
10
|
+
}): () => void;
|
|
9
11
|
setCanTrack(value: boolean): void;
|
|
10
12
|
};
|
|
11
13
|
export declare const userAttributesService: {
|
|
12
14
|
setUserAttributes(newAttrs: UserAttributes): void;
|
|
13
15
|
getUserAttributes(): any;
|
|
14
|
-
subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void
|
|
16
|
+
subscribeOnUserAttributesChange(callback: (attrs: UserAttributes) => void, { fireImmediately }?: {
|
|
17
|
+
fireImmediately?: boolean | undefined;
|
|
18
|
+
}): () => void;
|
|
15
19
|
setCanTrack(value: boolean): void;
|
|
16
20
|
};
|
|
17
21
|
export declare const setClientUserAttributes: (attributes: UserAttributes) => void;
|
|
@@ -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 const USER_ATTRIBUTES_COOKIE_NAME = 'builder.userAttributes';
|
|
4
6
|
export function createUserAttributesService() {
|
|
5
7
|
let canTrack = true;
|
|
@@ -29,18 +31,31 @@ export function createUserAttributesService() {
|
|
|
29
31
|
canTrack
|
|
30
32
|
}) || '{}');
|
|
31
33
|
},
|
|
32
|
-
subscribeOnUserAttributesChange(callback) {
|
|
34
|
+
subscribeOnUserAttributesChange(callback, { fireImmediately } = {}) {
|
|
33
35
|
subscribers.add(callback);
|
|
34
|
-
|
|
36
|
+
if (fireImmediately) {
|
|
37
|
+
callback(this.getUserAttributes());
|
|
38
|
+
}
|
|
39
|
+
return noSerializeWrapper(function () {
|
|
35
40
|
subscribers.delete(callback);
|
|
36
|
-
};
|
|
41
|
+
});
|
|
37
42
|
},
|
|
38
43
|
setCanTrack(value) {
|
|
39
44
|
canTrack = value;
|
|
40
45
|
}
|
|
41
46
|
};
|
|
42
47
|
}
|
|
43
|
-
|
|
48
|
+
let _userAttributesService;
|
|
49
|
+
if (isBrowser() && TARGET === 'qwik') {
|
|
50
|
+
if (!window.__BUILDER_USER_ATTRIBUTES_SERVICE__) {
|
|
51
|
+
window.__BUILDER_USER_ATTRIBUTES_SERVICE__ = createUserAttributesService();
|
|
52
|
+
}
|
|
53
|
+
_userAttributesService = window.__BUILDER_USER_ATTRIBUTES_SERVICE__;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
_userAttributesService = createUserAttributesService();
|
|
57
|
+
}
|
|
58
|
+
export const userAttributesService = _userAttributesService;
|
|
44
59
|
export const setClientUserAttributes = (attributes) => {
|
|
45
60
|
userAttributesService.setUserAttributes(attributes);
|
|
46
61
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-svelte",
|
|
3
3
|
"description": "Builder.io SDK for Svelte",
|
|
4
|
-
"version": "4.0.
|
|
4
|
+
"version": "4.0.10",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"files": [
|
|
7
7
|
"lib",
|
|
@@ -60,7 +60,7 @@
|
|
|
60
60
|
"svelte-preprocess": "^5.0.4",
|
|
61
61
|
"tslib": "^2.3.1",
|
|
62
62
|
"typescript": "^5.1.6",
|
|
63
|
-
"vite": "^4.5.
|
|
63
|
+
"vite": "^4.5.11"
|
|
64
64
|
},
|
|
65
65
|
"nx": {
|
|
66
66
|
"targets": {
|
|
@@ -188,6 +188,19 @@
|
|
|
188
188
|
}
|
|
189
189
|
}
|
|
190
190
|
formState = "sending";
|
|
191
|
+
if (
|
|
192
|
+
sendSubmissionsTo === "email" &&
|
|
193
|
+
(sendSubmissionsToEmail === "your@email.com" || !sendSubmissionsToEmail)
|
|
194
|
+
) {
|
|
195
|
+
const message =
|
|
196
|
+
"SubmissionsToEmail is required when sendSubmissionsTo is set to email";
|
|
197
|
+
console.error(message);
|
|
198
|
+
formState = "error";
|
|
199
|
+
mergeNewRootState({
|
|
200
|
+
formErrorMessage: message,
|
|
201
|
+
});
|
|
202
|
+
return;
|
|
203
|
+
}
|
|
191
204
|
const formUrl = `${
|
|
192
205
|
getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"
|
|
193
206
|
}/api/v1/form-submit?apiKey=${$builderContext.apiKey}&to=${btoa(
|
|
@@ -212,20 +225,32 @@
|
|
|
212
225
|
} else {
|
|
213
226
|
body = await res.text();
|
|
214
227
|
}
|
|
215
|
-
if (!res.ok
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
228
|
+
if (!res.ok) {
|
|
229
|
+
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
230
|
+
detail: {
|
|
231
|
+
error: body,
|
|
232
|
+
status: res.status,
|
|
233
|
+
},
|
|
234
|
+
});
|
|
235
|
+
if (formRef?.nativeElement) {
|
|
236
|
+
formRef?.nativeElement.dispatchEvent(submitErrorEvent);
|
|
237
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
238
|
+
return;
|
|
223
239
|
}
|
|
224
|
-
formErrorMessage = message;
|
|
225
|
-
mergeNewRootState({
|
|
226
|
-
formErrorMessage: message,
|
|
227
|
-
});
|
|
228
240
|
}
|
|
241
|
+
responseData = body;
|
|
242
|
+
formState = "error";
|
|
243
|
+
let message = errorMessagePath
|
|
244
|
+
? get(body, errorMessagePath)
|
|
245
|
+
: body.message || body.error || body;
|
|
246
|
+
if (typeof message !== "string") {
|
|
247
|
+
message = JSON.stringify(message);
|
|
248
|
+
}
|
|
249
|
+
formErrorMessage = message;
|
|
250
|
+
mergeNewRootState({
|
|
251
|
+
formErrorMessage: message,
|
|
252
|
+
});
|
|
253
|
+
return;
|
|
229
254
|
}
|
|
230
255
|
responseData = body;
|
|
231
256
|
formState = res.ok ? "success" : "error";
|
|
@@ -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}";
|