@builder.io/sdk-react-nextjs 0.18.11 → 0.18.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/browser/blocks/personalization-container/component-info.cjs +1 -0
- package/lib/browser/blocks/personalization-container/component-info.mjs +40 -0
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.cjs +162 -0
- package/lib/browser/blocks/personalization-container/helpers/inlined-fns.mjs +225 -0
- package/lib/browser/blocks/personalization-container/helpers.cjs +5 -0
- package/lib/browser/blocks/personalization-container/helpers.mjs +64 -0
- package/lib/browser/blocks/personalization-container/personalization-container.cjs +1 -0
- package/lib/browser/blocks/personalization-container/personalization-container.mjs +211 -0
- package/lib/browser/blocks/symbol/symbol.cjs +1 -1
- package/lib/browser/blocks/symbol/symbol.mjs +23 -23
- package/lib/browser/components/block/components/interactive-element.cjs +1 -1
- package/lib/browser/components/block/components/interactive-element.mjs +16 -12
- package/lib/browser/components/blocks/blocks-wrapper.cjs +1 -1
- package/lib/browser/components/blocks/blocks-wrapper.mjs +2 -2
- package/lib/browser/components/blocks/blocks.cjs +1 -1
- package/lib/browser/components/blocks/blocks.mjs +21 -18
- package/lib/browser/components/content-variants/content-variants.cjs +1 -1
- package/lib/browser/components/content-variants/content-variants.mjs +51 -40
- package/lib/browser/constants/builder-registered-components.cjs +1 -1
- package/lib/browser/constants/builder-registered-components.mjs +43 -36
- package/lib/browser/constants/sdk-version.cjs +1 -1
- package/lib/browser/constants/sdk-version.mjs +1 -1
- package/lib/edge/blocks/personalization-container/component-info.cjs +1 -0
- package/lib/edge/blocks/personalization-container/component-info.mjs +40 -0
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.cjs +162 -0
- package/lib/edge/blocks/personalization-container/helpers/inlined-fns.mjs +225 -0
- package/lib/edge/blocks/personalization-container/helpers.cjs +5 -0
- package/lib/edge/blocks/personalization-container/helpers.mjs +64 -0
- package/lib/edge/blocks/personalization-container/personalization-container.cjs +1 -0
- package/lib/edge/blocks/personalization-container/personalization-container.mjs +211 -0
- package/lib/edge/blocks/symbol/symbol.cjs +1 -1
- package/lib/edge/blocks/symbol/symbol.mjs +23 -23
- package/lib/edge/components/block/components/interactive-element.cjs +1 -1
- package/lib/edge/components/block/components/interactive-element.mjs +16 -12
- package/lib/edge/components/blocks/blocks-wrapper.cjs +1 -1
- package/lib/edge/components/blocks/blocks-wrapper.mjs +2 -2
- package/lib/edge/components/blocks/blocks.cjs +1 -1
- package/lib/edge/components/blocks/blocks.mjs +21 -18
- package/lib/edge/components/content-variants/content-variants.cjs +1 -1
- package/lib/edge/components/content-variants/content-variants.mjs +51 -40
- package/lib/edge/constants/builder-registered-components.cjs +1 -1
- package/lib/edge/constants/builder-registered-components.mjs +41 -34
- package/lib/edge/constants/sdk-version.cjs +1 -1
- package/lib/edge/constants/sdk-version.mjs +1 -1
- package/lib/node/blocks/personalization-container/component-info.cjs +1 -0
- package/lib/node/blocks/personalization-container/component-info.mjs +40 -0
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.cjs +162 -0
- package/lib/node/blocks/personalization-container/helpers/inlined-fns.mjs +225 -0
- package/lib/node/blocks/personalization-container/helpers.cjs +5 -0
- package/lib/node/blocks/personalization-container/helpers.mjs +64 -0
- package/lib/node/blocks/personalization-container/personalization-container.cjs +1 -0
- package/lib/node/blocks/personalization-container/personalization-container.mjs +211 -0
- package/lib/node/blocks/symbol/symbol.cjs +1 -1
- package/lib/node/blocks/symbol/symbol.mjs +23 -23
- package/lib/node/components/block/components/interactive-element.cjs +1 -1
- package/lib/node/components/block/components/interactive-element.mjs +16 -12
- package/lib/node/components/blocks/blocks-wrapper.cjs +1 -1
- package/lib/node/components/blocks/blocks-wrapper.mjs +2 -2
- package/lib/node/components/blocks/blocks.cjs +1 -1
- package/lib/node/components/blocks/blocks.mjs +21 -18
- package/lib/node/components/content-variants/content-variants.cjs +1 -1
- package/lib/node/components/content-variants/content-variants.mjs +51 -40
- package/lib/node/constants/builder-registered-components.cjs +1 -1
- package/lib/node/constants/builder-registered-components.mjs +41 -34
- package/lib/node/constants/sdk-version.cjs +1 -1
- package/lib/node/constants/sdk-version.mjs +1 -1
- package/package.json +2 -2
- package/types/cjs/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/types/cjs/blocks/personalization-container/helpers.d.ts +24 -4
- package/types/cjs/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/types/cjs/components/blocks/blocks-wrapper.d.ts +13 -1
- package/types/cjs/components/blocks/blocks.types.d.ts +1 -1
- package/types/cjs/constants/sdk-version.d.ts +1 -1
- package/types/esm/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
- package/types/esm/blocks/personalization-container/helpers.d.ts +24 -4
- package/types/esm/blocks/personalization-container/personalization-container.types.d.ts +2 -2
- package/types/esm/components/blocks/blocks-wrapper.d.ts +13 -1
- package/types/esm/components/blocks/blocks.types.d.ts +1 -1
- package/types/esm/constants/sdk-version.d.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e={name:"PersonalizationContainer",shouldReceiveBuilderProps:{builderBlock:!0,builderContext:!0,builderComponents:!0},noWrap:!0,image:"https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",canHaveChildren:!0,inputs:[{name:"variants",defaultValue:[],behavior:"personalizationVariantList",type:"list",subFields:[{name:"name",type:"text"},{name:"query",friendlyName:"Targeting rules",type:"BuilderQuery",defaultValue:[]},{name:"startDate",type:"date"},{name:"endDate",type:"date"},{name:"blocks",type:"uiBlocks",hideFromUI:!0,defaultValue:[]}]}]};exports.componentInfo=e;
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
const e = {
|
|
2
|
+
name: "PersonalizationContainer",
|
|
3
|
+
shouldReceiveBuilderProps: {
|
|
4
|
+
builderBlock: !0,
|
|
5
|
+
builderContext: !0,
|
|
6
|
+
builderComponents: !0
|
|
7
|
+
},
|
|
8
|
+
noWrap: !0,
|
|
9
|
+
image: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F37229ed30d8c41dfb10b8cca1992053a",
|
|
10
|
+
canHaveChildren: !0,
|
|
11
|
+
inputs: [{
|
|
12
|
+
name: "variants",
|
|
13
|
+
defaultValue: [],
|
|
14
|
+
behavior: "personalizationVariantList",
|
|
15
|
+
type: "list",
|
|
16
|
+
subFields: [{
|
|
17
|
+
name: "name",
|
|
18
|
+
type: "text"
|
|
19
|
+
}, {
|
|
20
|
+
name: "query",
|
|
21
|
+
friendlyName: "Targeting rules",
|
|
22
|
+
type: "BuilderQuery",
|
|
23
|
+
defaultValue: []
|
|
24
|
+
}, {
|
|
25
|
+
name: "startDate",
|
|
26
|
+
type: "date"
|
|
27
|
+
}, {
|
|
28
|
+
name: "endDate",
|
|
29
|
+
type: "date"
|
|
30
|
+
}, {
|
|
31
|
+
name: "blocks",
|
|
32
|
+
type: "uiBlocks",
|
|
33
|
+
hideFromUI: !0,
|
|
34
|
+
defaultValue: []
|
|
35
|
+
}]
|
|
36
|
+
}]
|
|
37
|
+
};
|
|
38
|
+
export {
|
|
39
|
+
e as componentInfo
|
|
40
|
+
};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});function p(l,f,y,g){function o(r){return typeof r=="string"}function a(r){return typeof r=="number"}function c(r,n){return(()=>{const s=n.property,u=n.operator;let e=n.value;if(n&&n.property==="urlPath"&&n.value&&typeof n.value=="string"&&n.value!=="/"&&n.value.endsWith("/")&&(e=n.value.slice(0,-1)),!(s&&u))return!0;if(Array.isArray(e))return u==="isNot"?e.every(v=>c(r,{property:s,operator:u,value:v})):!!e.find(v=>c(r,{property:s,operator:u,value:v}));const t=r[s];if(Array.isArray(t))return t.includes(e);switch(u){case"is":return t===e;case"isNot":return t!==e;case"contains":return(o(t)||Array.isArray(t))&&t.includes(String(e));case"startsWith":return o(t)&&t.startsWith(String(e));case"endsWith":return o(t)&&t.endsWith(String(e));case"greaterThan":return a(t)&&a(e)&&t>e;case"lessThan":return a(t)&&a(e)&&t<e;case"greaterThanOrEqualTo":return a(t)&&a(e)&&t>=e;case"lessThanOrEqualTo":return a(t)&&a(e)&&t<=e;default:return!1}})()}const i={query:f,startDate:y,endDate:g},d=l.date&&new Date(l.date)||new Date;return i.startDate&&new Date(i.startDate)>d||i.endDate&&new Date(i.endDate)<d?!1:!i.query||!i.query.length?!0:i.query.every(r=>c(l,r))}const S=`function getPersonalizedVariant(variants, blockId, isHydrationTarget, locale) {
|
|
2
|
+
if (!navigator.cookieEnabled) {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
function getCookie(name) {
|
|
6
|
+
const nameEQ = name + '=';
|
|
7
|
+
const ca = document.cookie.split(';');
|
|
8
|
+
for (let i = 0; i < ca.length; i++) {
|
|
9
|
+
let c = ca[i];
|
|
10
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
11
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
12
|
+
}
|
|
13
|
+
return null;
|
|
14
|
+
}
|
|
15
|
+
const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
|
|
16
|
+
if (locale) {
|
|
17
|
+
attributes.locale = locale;
|
|
18
|
+
}
|
|
19
|
+
const winningVariantIndex = variants?.findIndex(function (variant) {
|
|
20
|
+
return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
|
|
21
|
+
});
|
|
22
|
+
const parentDiv = document.currentScript?.parentElement;
|
|
23
|
+
const variantId = parentDiv?.getAttribute('data-variant-id');
|
|
24
|
+
const isDefaultVariant = variantId === \`\${blockId}-default\`;
|
|
25
|
+
const isWinningVariant = winningVariantIndex !== -1 && variantId === \`\${blockId}-\${winningVariantIndex}\` || winningVariantIndex === -1 && isDefaultVariant;
|
|
26
|
+
if (isWinningVariant && !isDefaultVariant) {
|
|
27
|
+
parentDiv?.removeAttribute('hidden');
|
|
28
|
+
parentDiv?.removeAttribute('aria-hidden');
|
|
29
|
+
} else if (!isWinningVariant && isDefaultVariant) {
|
|
30
|
+
parentDiv?.setAttribute('hidden', 'true');
|
|
31
|
+
parentDiv?.setAttribute('aria-hidden', 'true');
|
|
32
|
+
}
|
|
33
|
+
if (isHydrationTarget) {
|
|
34
|
+
if (!isWinningVariant) {
|
|
35
|
+
const itsStyleEl = parentDiv?.previousElementSibling;
|
|
36
|
+
if (itsStyleEl) {
|
|
37
|
+
itsStyleEl.remove();
|
|
38
|
+
}
|
|
39
|
+
parentDiv?.remove();
|
|
40
|
+
}
|
|
41
|
+
const thisScript = document.currentScript;
|
|
42
|
+
if (thisScript) {
|
|
43
|
+
thisScript.remove();
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
}`,m=`function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
|
|
47
|
+
function isString(val) {
|
|
48
|
+
return typeof val === 'string';
|
|
49
|
+
}
|
|
50
|
+
function isNumber(val) {
|
|
51
|
+
return typeof val === 'number';
|
|
52
|
+
}
|
|
53
|
+
function objectMatchesQuery(userattr, query) {
|
|
54
|
+
const result = (() => {
|
|
55
|
+
const property = query.property;
|
|
56
|
+
const operator = query.operator;
|
|
57
|
+
let testValue = query.value;
|
|
58
|
+
if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {
|
|
59
|
+
testValue = query.value.slice(0, -1);
|
|
60
|
+
}
|
|
61
|
+
if (!(property && operator)) {
|
|
62
|
+
return true;
|
|
63
|
+
}
|
|
64
|
+
if (Array.isArray(testValue)) {
|
|
65
|
+
if (operator === 'isNot') {
|
|
66
|
+
return testValue.every(val => objectMatchesQuery(userattr, {
|
|
67
|
+
property,
|
|
68
|
+
operator,
|
|
69
|
+
value: val
|
|
70
|
+
}));
|
|
71
|
+
}
|
|
72
|
+
return !!testValue.find(val => objectMatchesQuery(userattr, {
|
|
73
|
+
property,
|
|
74
|
+
operator,
|
|
75
|
+
value: val
|
|
76
|
+
}));
|
|
77
|
+
}
|
|
78
|
+
const value = userattr[property];
|
|
79
|
+
if (Array.isArray(value)) {
|
|
80
|
+
return value.includes(testValue);
|
|
81
|
+
}
|
|
82
|
+
switch (operator) {
|
|
83
|
+
case 'is':
|
|
84
|
+
return value === testValue;
|
|
85
|
+
case 'isNot':
|
|
86
|
+
return value !== testValue;
|
|
87
|
+
case 'contains':
|
|
88
|
+
return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
|
|
89
|
+
case 'startsWith':
|
|
90
|
+
return isString(value) && value.startsWith(String(testValue));
|
|
91
|
+
case 'endsWith':
|
|
92
|
+
return isString(value) && value.endsWith(String(testValue));
|
|
93
|
+
case 'greaterThan':
|
|
94
|
+
return isNumber(value) && isNumber(testValue) && value > testValue;
|
|
95
|
+
case 'lessThan':
|
|
96
|
+
return isNumber(value) && isNumber(testValue) && value < testValue;
|
|
97
|
+
case 'greaterThanOrEqualTo':
|
|
98
|
+
return isNumber(value) && isNumber(testValue) && value >= testValue;
|
|
99
|
+
case 'lessThanOrEqualTo':
|
|
100
|
+
return isNumber(value) && isNumber(testValue) && value <= testValue;
|
|
101
|
+
default:
|
|
102
|
+
return false;
|
|
103
|
+
}
|
|
104
|
+
})();
|
|
105
|
+
return result;
|
|
106
|
+
}
|
|
107
|
+
const item = {
|
|
108
|
+
query,
|
|
109
|
+
startDate,
|
|
110
|
+
endDate
|
|
111
|
+
};
|
|
112
|
+
const now = userAttributes.date && new Date(userAttributes.date) || new Date();
|
|
113
|
+
if (item.startDate && new Date(item.startDate) > now) {
|
|
114
|
+
return false;
|
|
115
|
+
} else if (item.endDate && new Date(item.endDate) < now) {
|
|
116
|
+
return false;
|
|
117
|
+
}
|
|
118
|
+
if (!item.query || !item.query.length) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
return item.query.every(filter => {
|
|
122
|
+
return objectMatchesQuery(userAttributes, filter);
|
|
123
|
+
});
|
|
124
|
+
}`,b=`function updateVisibilityStylesScript(variants, blockId, isHydrationTarget, locale) {
|
|
125
|
+
function getCookie(name) {
|
|
126
|
+
const nameEQ = name + '=';
|
|
127
|
+
const ca = document.cookie.split(';');
|
|
128
|
+
for (let i = 0; i < ca.length; i++) {
|
|
129
|
+
let c = ca[i];
|
|
130
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
131
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
132
|
+
}
|
|
133
|
+
return null;
|
|
134
|
+
}
|
|
135
|
+
const visibilityStylesEl = document.currentScript?.previousElementSibling;
|
|
136
|
+
if (!visibilityStylesEl) {
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
if (isHydrationTarget) {
|
|
140
|
+
visibilityStylesEl.remove();
|
|
141
|
+
const currentScript = document.currentScript;
|
|
142
|
+
if (currentScript) {
|
|
143
|
+
currentScript.remove();
|
|
144
|
+
}
|
|
145
|
+
} else {
|
|
146
|
+
const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
|
|
147
|
+
if (locale) {
|
|
148
|
+
attributes.locale = locale;
|
|
149
|
+
}
|
|
150
|
+
const winningVariantIndex = variants?.findIndex(function (variant) {
|
|
151
|
+
return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
|
|
152
|
+
});
|
|
153
|
+
if (winningVariantIndex !== -1) {
|
|
154
|
+
let newStyleStr = variants?.map((_, index) => {
|
|
155
|
+
if (index === winningVariantIndex) return '';
|
|
156
|
+
return \`div[data-variant-id="\${blockId}-\${index}"] { display: none !important; } \`;
|
|
157
|
+
}).join('') || '';
|
|
158
|
+
newStyleStr += \`div[data-variant-id="\${blockId}-default"] { display: none !important; } \`;
|
|
159
|
+
visibilityStylesEl.innerHTML = newStyleStr;
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}`;exports.FILTER_WITH_CUSTOM_TARGETING_SCRIPT=m;exports.PERSONALIZATION_SCRIPT=S;exports.UPDATE_VISIBILITY_STYLES_SCRIPT=b;exports.filterWithCustomTargeting=p;
|
|
@@ -0,0 +1,225 @@
|
|
|
1
|
+
function m(l, f, y, p) {
|
|
2
|
+
function o(r) {
|
|
3
|
+
return typeof r == "string";
|
|
4
|
+
}
|
|
5
|
+
function a(r) {
|
|
6
|
+
return typeof r == "number";
|
|
7
|
+
}
|
|
8
|
+
function c(r, n) {
|
|
9
|
+
return (() => {
|
|
10
|
+
const u = n.property, s = n.operator;
|
|
11
|
+
let e = n.value;
|
|
12
|
+
if (n && n.property === "urlPath" && n.value && typeof n.value == "string" && n.value !== "/" && n.value.endsWith("/") && (e = n.value.slice(0, -1)), !(u && s))
|
|
13
|
+
return !0;
|
|
14
|
+
if (Array.isArray(e))
|
|
15
|
+
return s === "isNot" ? e.every((v) => c(r, {
|
|
16
|
+
property: u,
|
|
17
|
+
operator: s,
|
|
18
|
+
value: v
|
|
19
|
+
})) : !!e.find((v) => c(r, {
|
|
20
|
+
property: u,
|
|
21
|
+
operator: s,
|
|
22
|
+
value: v
|
|
23
|
+
}));
|
|
24
|
+
const t = r[u];
|
|
25
|
+
if (Array.isArray(t))
|
|
26
|
+
return t.includes(e);
|
|
27
|
+
switch (s) {
|
|
28
|
+
case "is":
|
|
29
|
+
return t === e;
|
|
30
|
+
case "isNot":
|
|
31
|
+
return t !== e;
|
|
32
|
+
case "contains":
|
|
33
|
+
return (o(t) || Array.isArray(t)) && t.includes(String(e));
|
|
34
|
+
case "startsWith":
|
|
35
|
+
return o(t) && t.startsWith(String(e));
|
|
36
|
+
case "endsWith":
|
|
37
|
+
return o(t) && t.endsWith(String(e));
|
|
38
|
+
case "greaterThan":
|
|
39
|
+
return a(t) && a(e) && t > e;
|
|
40
|
+
case "lessThan":
|
|
41
|
+
return a(t) && a(e) && t < e;
|
|
42
|
+
case "greaterThanOrEqualTo":
|
|
43
|
+
return a(t) && a(e) && t >= e;
|
|
44
|
+
case "lessThanOrEqualTo":
|
|
45
|
+
return a(t) && a(e) && t <= e;
|
|
46
|
+
default:
|
|
47
|
+
return !1;
|
|
48
|
+
}
|
|
49
|
+
})();
|
|
50
|
+
}
|
|
51
|
+
const i = {
|
|
52
|
+
query: f,
|
|
53
|
+
startDate: y,
|
|
54
|
+
endDate: p
|
|
55
|
+
}, d = l.date && new Date(l.date) || /* @__PURE__ */ new Date();
|
|
56
|
+
return i.startDate && new Date(i.startDate) > d || i.endDate && new Date(i.endDate) < d ? !1 : !i.query || !i.query.length ? !0 : i.query.every((r) => c(l, r));
|
|
57
|
+
}
|
|
58
|
+
const b = `function getPersonalizedVariant(variants, blockId, isHydrationTarget, locale) {
|
|
59
|
+
if (!navigator.cookieEnabled) {
|
|
60
|
+
return;
|
|
61
|
+
}
|
|
62
|
+
function getCookie(name) {
|
|
63
|
+
const nameEQ = name + '=';
|
|
64
|
+
const ca = document.cookie.split(';');
|
|
65
|
+
for (let i = 0; i < ca.length; i++) {
|
|
66
|
+
let c = ca[i];
|
|
67
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
68
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
69
|
+
}
|
|
70
|
+
return null;
|
|
71
|
+
}
|
|
72
|
+
const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
|
|
73
|
+
if (locale) {
|
|
74
|
+
attributes.locale = locale;
|
|
75
|
+
}
|
|
76
|
+
const winningVariantIndex = variants?.findIndex(function (variant) {
|
|
77
|
+
return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
|
|
78
|
+
});
|
|
79
|
+
const parentDiv = document.currentScript?.parentElement;
|
|
80
|
+
const variantId = parentDiv?.getAttribute('data-variant-id');
|
|
81
|
+
const isDefaultVariant = variantId === \`\${blockId}-default\`;
|
|
82
|
+
const isWinningVariant = winningVariantIndex !== -1 && variantId === \`\${blockId}-\${winningVariantIndex}\` || winningVariantIndex === -1 && isDefaultVariant;
|
|
83
|
+
if (isWinningVariant && !isDefaultVariant) {
|
|
84
|
+
parentDiv?.removeAttribute('hidden');
|
|
85
|
+
parentDiv?.removeAttribute('aria-hidden');
|
|
86
|
+
} else if (!isWinningVariant && isDefaultVariant) {
|
|
87
|
+
parentDiv?.setAttribute('hidden', 'true');
|
|
88
|
+
parentDiv?.setAttribute('aria-hidden', 'true');
|
|
89
|
+
}
|
|
90
|
+
if (isHydrationTarget) {
|
|
91
|
+
if (!isWinningVariant) {
|
|
92
|
+
const itsStyleEl = parentDiv?.previousElementSibling;
|
|
93
|
+
if (itsStyleEl) {
|
|
94
|
+
itsStyleEl.remove();
|
|
95
|
+
}
|
|
96
|
+
parentDiv?.remove();
|
|
97
|
+
}
|
|
98
|
+
const thisScript = document.currentScript;
|
|
99
|
+
if (thisScript) {
|
|
100
|
+
thisScript.remove();
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
}`, h = `function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
|
|
104
|
+
function isString(val) {
|
|
105
|
+
return typeof val === 'string';
|
|
106
|
+
}
|
|
107
|
+
function isNumber(val) {
|
|
108
|
+
return typeof val === 'number';
|
|
109
|
+
}
|
|
110
|
+
function objectMatchesQuery(userattr, query) {
|
|
111
|
+
const result = (() => {
|
|
112
|
+
const property = query.property;
|
|
113
|
+
const operator = query.operator;
|
|
114
|
+
let testValue = query.value;
|
|
115
|
+
if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {
|
|
116
|
+
testValue = query.value.slice(0, -1);
|
|
117
|
+
}
|
|
118
|
+
if (!(property && operator)) {
|
|
119
|
+
return true;
|
|
120
|
+
}
|
|
121
|
+
if (Array.isArray(testValue)) {
|
|
122
|
+
if (operator === 'isNot') {
|
|
123
|
+
return testValue.every(val => objectMatchesQuery(userattr, {
|
|
124
|
+
property,
|
|
125
|
+
operator,
|
|
126
|
+
value: val
|
|
127
|
+
}));
|
|
128
|
+
}
|
|
129
|
+
return !!testValue.find(val => objectMatchesQuery(userattr, {
|
|
130
|
+
property,
|
|
131
|
+
operator,
|
|
132
|
+
value: val
|
|
133
|
+
}));
|
|
134
|
+
}
|
|
135
|
+
const value = userattr[property];
|
|
136
|
+
if (Array.isArray(value)) {
|
|
137
|
+
return value.includes(testValue);
|
|
138
|
+
}
|
|
139
|
+
switch (operator) {
|
|
140
|
+
case 'is':
|
|
141
|
+
return value === testValue;
|
|
142
|
+
case 'isNot':
|
|
143
|
+
return value !== testValue;
|
|
144
|
+
case 'contains':
|
|
145
|
+
return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
|
|
146
|
+
case 'startsWith':
|
|
147
|
+
return isString(value) && value.startsWith(String(testValue));
|
|
148
|
+
case 'endsWith':
|
|
149
|
+
return isString(value) && value.endsWith(String(testValue));
|
|
150
|
+
case 'greaterThan':
|
|
151
|
+
return isNumber(value) && isNumber(testValue) && value > testValue;
|
|
152
|
+
case 'lessThan':
|
|
153
|
+
return isNumber(value) && isNumber(testValue) && value < testValue;
|
|
154
|
+
case 'greaterThanOrEqualTo':
|
|
155
|
+
return isNumber(value) && isNumber(testValue) && value >= testValue;
|
|
156
|
+
case 'lessThanOrEqualTo':
|
|
157
|
+
return isNumber(value) && isNumber(testValue) && value <= testValue;
|
|
158
|
+
default:
|
|
159
|
+
return false;
|
|
160
|
+
}
|
|
161
|
+
})();
|
|
162
|
+
return result;
|
|
163
|
+
}
|
|
164
|
+
const item = {
|
|
165
|
+
query,
|
|
166
|
+
startDate,
|
|
167
|
+
endDate
|
|
168
|
+
};
|
|
169
|
+
const now = userAttributes.date && new Date(userAttributes.date) || new Date();
|
|
170
|
+
if (item.startDate && new Date(item.startDate) > now) {
|
|
171
|
+
return false;
|
|
172
|
+
} else if (item.endDate && new Date(item.endDate) < now) {
|
|
173
|
+
return false;
|
|
174
|
+
}
|
|
175
|
+
if (!item.query || !item.query.length) {
|
|
176
|
+
return true;
|
|
177
|
+
}
|
|
178
|
+
return item.query.every(filter => {
|
|
179
|
+
return objectMatchesQuery(userAttributes, filter);
|
|
180
|
+
});
|
|
181
|
+
}`, S = `function updateVisibilityStylesScript(variants, blockId, isHydrationTarget, locale) {
|
|
182
|
+
function getCookie(name) {
|
|
183
|
+
const nameEQ = name + '=';
|
|
184
|
+
const ca = document.cookie.split(';');
|
|
185
|
+
for (let i = 0; i < ca.length; i++) {
|
|
186
|
+
let c = ca[i];
|
|
187
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
188
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
189
|
+
}
|
|
190
|
+
return null;
|
|
191
|
+
}
|
|
192
|
+
const visibilityStylesEl = document.currentScript?.previousElementSibling;
|
|
193
|
+
if (!visibilityStylesEl) {
|
|
194
|
+
return;
|
|
195
|
+
}
|
|
196
|
+
if (isHydrationTarget) {
|
|
197
|
+
visibilityStylesEl.remove();
|
|
198
|
+
const currentScript = document.currentScript;
|
|
199
|
+
if (currentScript) {
|
|
200
|
+
currentScript.remove();
|
|
201
|
+
}
|
|
202
|
+
} else {
|
|
203
|
+
const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
|
|
204
|
+
if (locale) {
|
|
205
|
+
attributes.locale = locale;
|
|
206
|
+
}
|
|
207
|
+
const winningVariantIndex = variants?.findIndex(function (variant) {
|
|
208
|
+
return window.filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
|
|
209
|
+
});
|
|
210
|
+
if (winningVariantIndex !== -1) {
|
|
211
|
+
let newStyleStr = variants?.map((_, index) => {
|
|
212
|
+
if (index === winningVariantIndex) return '';
|
|
213
|
+
return \`div[data-variant-id="\${blockId}-\${index}"] { display: none !important; } \`;
|
|
214
|
+
}).join('') || '';
|
|
215
|
+
newStyleStr += \`div[data-variant-id="\${blockId}-default"] { display: none !important; } \`;
|
|
216
|
+
visibilityStylesEl.innerHTML = newStyleStr;
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
}`;
|
|
220
|
+
export {
|
|
221
|
+
h as FILTER_WITH_CUSTOM_TARGETING_SCRIPT,
|
|
222
|
+
b as PERSONALIZATION_SCRIPT,
|
|
223
|
+
S as UPDATE_VISIBILITY_STYLES_SCRIPT,
|
|
224
|
+
m as filterWithCustomTargeting
|
|
225
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const c=require("../../constants/target.cjs"),_=require("../../functions/is-browser.cjs"),N=require("../../functions/is-editing.cjs"),r=require("./helpers/inlined-fns.cjs"),u="default",g="filterWithCustomTargeting",R="builderIoPersonalization",E="updateVisibilityStylesScript",l=["react","vue","svelte"],P=["vue","svelte"];function d(t,i){return!(t&&t.length>0)||!i?!1:P.includes(c.TARGET)?!0:!_.isBrowser()}function $({variants:t,previewingIndex:i,isHydrated:n,filteredVariants:o,fallbackBlocks:s}){var I;const T={blocks:s!=null?s:[],path:"this.children",index:u};if(n&&N.isEditing()){if(typeof i=="number"&&i<((I=t==null?void 0:t.length)!=null?I:0)){const e=t==null?void 0:t[i];if(e)return{blocks:e.blocks,path:`variants.${i}.blocks`,index:i}}return T}if(_.isBrowser()){const e=o==null?void 0:o[0];if(e&&t){const S=t.indexOf(e);if(S!==-1)return{blocks:e.blocks,path:`variants.${S}.blocks`,index:S}}}return T}const O=()=>`
|
|
2
|
+
window.${g} = ${r.FILTER_WITH_CUSTOM_TARGETING_SCRIPT}
|
|
3
|
+
window.${R} = ${r.PERSONALIZATION_SCRIPT}
|
|
4
|
+
window.${E} = ${r.UPDATE_VISIBILITY_STYLES_SCRIPT}
|
|
5
|
+
`,A=c.TARGET==="react",f=(t,i,n)=>`window.${R}(${JSON.stringify(t)}, "${i}", ${A}${n?`, "${n}"`:""})`,h=(t,i,n)=>`window.${E}(${JSON.stringify(t)}, "${i}", ${A}${n?`, "${n}"`:""})`;exports.filterWithCustomTargeting=r.filterWithCustomTargeting;exports.DEFAULT_INDEX=u;exports.SDKS_REQUIRING_RESET_APPROACH=P;exports.SDKS_SUPPORTING_PERSONALIZATION=l;exports.checkShouldRenderVariants=d;exports.getBlocksToRender=$;exports.getInitPersonalizationVariantsFnsScriptString=O;exports.getPersonalizationScript=f;exports.getUpdateVisibilityStylesScript=h;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { TARGET as S } from "../../constants/target.mjs";
|
|
2
|
+
import { isBrowser as _ } from "../../functions/is-browser.mjs";
|
|
3
|
+
import { isEditing as E } from "../../functions/is-editing.mjs";
|
|
4
|
+
import { FILTER_WITH_CUSTOM_TARGETING_SCRIPT as f, PERSONALIZATION_SCRIPT as N, UPDATE_VISIBILITY_STYLES_SCRIPT as $ } from "./helpers/inlined-fns.mjs";
|
|
5
|
+
import { filterWithCustomTargeting as D } from "./helpers/inlined-fns.mjs";
|
|
6
|
+
const A = "default", P = "filterWithCustomTargeting", c = "builderIoPersonalization", u = "updateVisibilityStylesScript", p = ["react", "vue", "svelte"], O = ["vue", "svelte"];
|
|
7
|
+
function l(t, n) {
|
|
8
|
+
return !(t && t.length > 0) || !n ? !1 : O.includes(S) ? !0 : !_();
|
|
9
|
+
}
|
|
10
|
+
function C({
|
|
11
|
+
variants: t,
|
|
12
|
+
previewingIndex: n,
|
|
13
|
+
isHydrated: o,
|
|
14
|
+
filteredVariants: r,
|
|
15
|
+
fallbackBlocks: e
|
|
16
|
+
}) {
|
|
17
|
+
var I;
|
|
18
|
+
const T = {
|
|
19
|
+
blocks: e != null ? e : [],
|
|
20
|
+
path: "this.children",
|
|
21
|
+
index: A
|
|
22
|
+
};
|
|
23
|
+
if (o && E()) {
|
|
24
|
+
if (typeof n == "number" && n < ((I = t == null ? void 0 : t.length) != null ? I : 0)) {
|
|
25
|
+
const i = t == null ? void 0 : t[n];
|
|
26
|
+
if (i)
|
|
27
|
+
return {
|
|
28
|
+
blocks: i.blocks,
|
|
29
|
+
path: `variants.${n}.blocks`,
|
|
30
|
+
index: n
|
|
31
|
+
};
|
|
32
|
+
}
|
|
33
|
+
return T;
|
|
34
|
+
}
|
|
35
|
+
if (_()) {
|
|
36
|
+
const i = r == null ? void 0 : r[0];
|
|
37
|
+
if (i && t) {
|
|
38
|
+
const s = t.indexOf(i);
|
|
39
|
+
if (s !== -1)
|
|
40
|
+
return {
|
|
41
|
+
blocks: i.blocks,
|
|
42
|
+
path: `variants.${s}.blocks`,
|
|
43
|
+
index: s
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
return T;
|
|
48
|
+
}
|
|
49
|
+
const L = () => `
|
|
50
|
+
window.${P} = ${f}
|
|
51
|
+
window.${c} = ${N}
|
|
52
|
+
window.${u} = ${$}
|
|
53
|
+
`, R = S === "react", U = (t, n, o) => `window.${c}(${JSON.stringify(t)}, "${n}", ${R}${o ? `, "${o}"` : ""})`, b = (t, n, o) => `window.${u}(${JSON.stringify(t)}, "${n}", ${R}${o ? `, "${o}"` : ""})`;
|
|
54
|
+
export {
|
|
55
|
+
A as DEFAULT_INDEX,
|
|
56
|
+
O as SDKS_REQUIRING_RESET_APPROACH,
|
|
57
|
+
p as SDKS_SUPPORTING_PERSONALIZATION,
|
|
58
|
+
l as checkShouldRenderVariants,
|
|
59
|
+
D as filterWithCustomTargeting,
|
|
60
|
+
C as getBlocksToRender,
|
|
61
|
+
L as getInitPersonalizationVariantsFnsScriptString,
|
|
62
|
+
U as getPersonalizationScript,
|
|
63
|
+
b as getUpdateVisibilityStylesScript
|
|
64
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"use client";"use strict";const r=require("react/jsx-runtime"),a=require("react"),k=require("../../components/blocks/blocks.cjs"),v=require("../../components/inlined-script.cjs"),H=require("../../components/inlined-styles.cjs"),C=require("../../constants/target.cjs"),U=require("../../functions/get-class-prop-name.cjs"),L=require("../../functions/is-editing.cjs"),z=require("../../functions/is-previewing.cjs"),K=require("../../helpers/canTrack.cjs"),V=require("../../helpers/user-attributes.cjs"),s=require("./helpers.cjs"),Q=require("./helpers/inlined-fns.cjs");function X(e){var g,f,B,m,A,P,$,T,y,q,D,I,_;const c=a.useRef(null),[N,w]=a.useState(()=>V.userAttributesService.getUserAttributes()),[x,J]=a.useState(()=>{var t,n,i;return s.getPersonalizationScript(e.variants,((t=e.builderBlock)==null?void 0:t.id)||"none",(i=(n=e.builderContext)==null?void 0:n.rootState)==null?void 0:i.locale)}),[W,M]=a.useState(()=>{var t,n,i;return s.getUpdateVisibilityStylesScript(e.variants,((t=e.builderBlock)==null?void 0:t.id)||"none",(i=(n=e.builderContext)==null?void 0:n.rootState)==null?void 0:i.locale)}),[h,Y]=a.useState(()=>[]),[E,Z]=a.useState(()=>{var t;return s.checkShouldRenderVariants(e.variants,K.getDefaultCanTrack((t=e.builderContext)==null?void 0:t.canTrack))}),[S,F]=a.useState(()=>!1);function G(){return{...e.attributes,[U.getClassPropName()]:`builder-personalization-container ${e.attributes[U.getClassPropName()]||""}`}}function R(){return(e.variants||[]).filter(t=>{var n,i,o,l;return Q.filterWithCustomTargeting({...(i=(n=e.builderContext)==null?void 0:n.rootState)!=null&&i.locale?{locale:(l=(o=e.builderContext)==null?void 0:o.rootState)==null?void 0:l.locale}:{},...N},t.query,t.startDate,t.endDate)})}function u(){var t;return s.getBlocksToRender({variants:e.variants,fallbackBlocks:(t=e.builderBlock)==null?void 0:t.children,isHydrated:S,filteredVariants:R(),previewingIndex:e.previewingIndex})}function O(){return(e.variants||[]).map((t,n)=>{var i;return`div[data-variant-id="${(i=e.builderBlock)==null?void 0:i.id}-${n}"] { display: none !important; } `}).join("")}return a.useEffect(()=>{var n;F(!0);const t=V.userAttributesService.subscribeOnUserAttributesChange(i=>{w(i)});if(!(L.isEditing()||z.isPreviewing())){const i=R()[0];c.current&&(c.current.dispatchEvent(new CustomEvent("builder.variantLoaded",{detail:{variant:i||s.DEFAULT_INDEX,content:(n=e.builderContext)==null?void 0:n.content},bubbles:!0})),new IntersectionObserver(l=>{l.forEach(b=>{var d;b.isIntersecting&&c.current&&c.current.dispatchEvent(new CustomEvent("builder.variantDisplayed",{detail:{variant:i||s.DEFAULT_INDEX,content:(d=e.builderContext)==null?void 0:d.content},bubbles:!0}))})}).observe(c.current))}h.push(t)},[]),a.useEffect(()=>()=>{h.forEach(t=>t())},[]),r.jsxs("div",{ref:c,...G(),children:[S&&s.SDKS_REQUIRING_RESET_APPROACH.includes(C.TARGET)?r.jsx(k,{blocks:u().blocks,parent:(g=e.builderBlock)==null?void 0:g.id,path:u().path,context:e.builderContext,registeredComponents:e.builderComponents,BlocksWrapperProps:{...(f=e.builderContext)==null?void 0:f.BlocksWrapperProps,"data-variant-id":`${(B=e.builderBlock)==null?void 0:B.id}-${u().index}`}}):null,!S&&s.SDKS_REQUIRING_RESET_APPROACH.includes(C.TARGET)||!s.SDKS_REQUIRING_RESET_APPROACH.includes(C.TARGET)?r.jsxs(r.Fragment,{children:[E?r.jsxs(r.Fragment,{children:[r.jsx(H,{nonce:((m=e.builderContext)==null?void 0:m.nonce)||"",styles:O(),id:`variants-styles-${(A=e.builderBlock)==null?void 0:A.id}`}),r.jsx(v,{nonce:((P=e.builderContext)==null?void 0:P.nonce)||"",scriptStr:W,id:`variants-visibility-script-${($=e.builderBlock)==null?void 0:$.id}`}),(T=e.variants)==null?void 0:T.map((t,n)=>{var i,o,l,b,d,j;return r.jsx(k,{BlocksWrapperProps:{...(i=e.builderContext)==null?void 0:i.BlocksWrapperProps,"aria-hidden":!0,hidden:!0,"data-variant-id":`${(o=e.builderBlock)==null?void 0:o.id}-${n}`},blocks:t.blocks,parent:(l=e.builderBlock)==null?void 0:l.id,path:`component.options.variants.${n}.blocks`,context:e.builderContext,registeredComponents:e.builderComponents,children:r.jsx(v,{nonce:((b=e.builderContext)==null?void 0:b.nonce)||"",scriptStr:x,id:`variants-script-${(d=e.builderBlock)==null?void 0:d.id}-${n}`})},`${(j=e.builderBlock)==null?void 0:j.id}-${n}`)})]}):null,r.jsx(k,{blocks:u().blocks,parent:(y=e.builderBlock)==null?void 0:y.id,path:u().path,context:e.builderContext,registeredComponents:e.builderComponents,BlocksWrapperProps:{...(q=e.builderContext)==null?void 0:q.BlocksWrapperProps,"data-variant-id":`${(D=e.builderBlock)==null?void 0:D.id}-${u().index}`},children:E?r.jsx(v,{nonce:((I=e.builderContext)==null?void 0:I.nonce)||"",scriptStr:x,id:`variants-script-${(_=e.builderBlock)==null?void 0:_.id}-${s.DEFAULT_INDEX}`}):null})]}):null]})}module.exports=X;
|