@builder.io/sdk-react 3.0.2 → 3.0.3-0
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-exports.cjs +169 -32
- package/lib/browser/blocks-exports.mjs +1297 -887
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +17 -16
- package/lib/browser/server-entry-c7bda8b5.cjs +2 -0
- package/lib/browser/{server-entry-a2495a20.js → server-entry-da1754bd.js} +279 -237
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/accordion-388f5e60.cjs +1 -0
- package/lib/edge/{accordion-c020e15b.js → accordion-50de133c.js} +17 -16
- package/lib/edge/{blocks-27ac5b23.js → blocks-5e476ddc.js} +4 -4
- package/lib/edge/{blocks-cd946d16.cjs → blocks-a5193d52.cjs} +8 -8
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +13 -12
- package/lib/edge/{button-5cdb4f26.js → button-4261ae64.js} +2 -2
- package/lib/edge/{button-8572fca5.cjs → button-c6ec3aea.cjs} +1 -1
- package/lib/edge/{columns-3ac1fa96.js → columns-28e9fb0a.js} +12 -12
- package/lib/edge/{columns-c8a9cb89.cjs → columns-8c831c02.cjs} +2 -2
- package/lib/edge/{content-variants-23c8eec6.js → content-variants-36ca4fe5.js} +165 -124
- package/lib/edge/content-variants-81713434.cjs +134 -0
- package/lib/edge/{custom-code-6d9730ff.cjs → custom-code-8119ea3f.cjs} +1 -1
- package/lib/edge/dynamic-blocks-exports.cjs +3 -1
- package/lib/edge/dynamic-blocks-exports.mjs +5 -2
- package/lib/edge/{form-7fc5691b.js → form-039fb5ff.js} +13 -13
- package/lib/edge/{form-3d9bf265.cjs → form-e7a1dec9.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-a4845b04.js → get-class-prop-name-65d6824c.js} +1 -1
- package/lib/edge/{get-class-prop-name-29fd576a.cjs → get-class-prop-name-a86a3e60.cjs} +1 -1
- package/lib/edge/{image-5c9e156f.js → image-2a2b26d2.js} +6 -6
- package/lib/edge/{image-94922c87.cjs → image-4db81d72.cjs} +3 -3
- package/lib/edge/{img-388698cb.js → img-61d29fb3.js} +1 -1
- package/lib/edge/{img-102acaa2.cjs → img-7de3a3de.cjs} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +18 -17
- package/lib/edge/{input-10e350a9.cjs → input-bd5387a6.cjs} +1 -1
- package/lib/edge/{input-5484e9e7.js → input-c8539054.js} +1 -1
- package/lib/edge/personalization-container-3fda6014.cjs +138 -0
- package/lib/edge/personalization-container-c76e4fef.js +379 -0
- package/lib/edge/{select-b8406bcf.js → select-6b5cda00.js} +1 -1
- package/lib/edge/{select-f11be7a7.cjs → select-73accaf4.cjs} +1 -1
- package/lib/edge/{server-entry-7ce03a4e.js → server-entry-838c1f06.js} +322 -280
- package/lib/edge/server-entry-ea2a8b0e.cjs +2 -0
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-4ab390ec.cjs → slot-099112f1.cjs} +1 -1
- package/lib/edge/{slot-23f75377.js → slot-403c77da.js} +3 -3
- package/lib/edge/{symbol-2eafb4e0.js → symbol-97f456f4.js} +2 -2
- package/lib/edge/{symbol-fa343d77.cjs → symbol-ffa6e6cd.cjs} +1 -1
- package/lib/edge/{tabs-4c9c64f6.js → tabs-a7c94ead.js} +3 -3
- package/lib/edge/{tabs-7d258d82.cjs → tabs-ad55c6a7.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +168 -31
- package/lib/node/blocks-exports.mjs +1403 -993
- package/lib/node/index.cjs +1 -1
- package/lib/node/index.mjs +17 -16
- package/lib/node/init.cjs +1 -1
- package/lib/node/init.mjs +3 -3
- package/lib/node/{server-entry-2b263dde.js → server-entry-51bc0b1d.js} +279 -237
- package/lib/node/server-entry-d7316893.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{setIvm-7eb67cd6.js → setIvm-575cf1f1.js} +1 -1
- package/lib/node/{setIvm-1e6f0b60.cjs → setIvm-d912cf4d.cjs} +1 -1
- package/lib/node/setIvm.cjs +1 -1
- package/lib/node/setIvm.mjs +2 -2
- package/lib/node/{should-force-browser-runtime-in-node-23218b19.cjs → should-force-browser-runtime-in-node-23225980.cjs} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-cdae9360.js → should-force-browser-runtime-in-node-66df4856.js} +1 -1
- package/package.json +1 -1
- package/types/blocks/index.d.ts +4 -0
- package/types/blocks/personalization-container/component-info.d.ts +2 -0
- package/types/blocks/personalization-container/helpers/index.d.ts +15 -0
- package/types/blocks/personalization-container/helpers/inlined-fns.d.ts +8 -0
- package/types/blocks/personalization-container/helpers.d.ts +27 -0
- package/types/blocks/personalization-container/index.d.ts +1 -0
- package/types/blocks/personalization-container/personalization-container.d.ts +4 -0
- package/types/blocks/personalization-container/personalization-container.types.d.ts +14 -0
- package/types/blocks/textarea/component-info.d.ts +2 -0
- package/types/blocks/textarea/index.d.ts +1 -0
- package/types/blocks/textarea/textarea.d.ts +14 -0
- package/types/constants/sdk-version.d.ts +1 -1
- package/types/functions/filter-with-custom-targeting.d.ts +15 -0
- package/types/helpers/user-attributes.d.ts +17 -0
- package/types/index-helpers/blocks-exports.d.ts +1 -0
- package/types/types/builder-content.d.ts +1 -0
- package/types/types/input.d.ts +11 -0
- package/lib/browser/server-entry-75ce8600.cjs +0 -2
- package/lib/edge/accordion-1c16f65e.cjs +0 -1
- package/lib/edge/content-variants-caa23bf7.cjs +0 -134
- package/lib/edge/server-entry-1879cbc4.cjs +0 -2
- package/lib/node/server-entry-ec330556.cjs +0 -2
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const b=require("react/jsx-runtime"),g=require("react"),D=require("./blocks-a5193d52.cjs"),P=require("./content-variants-81713434.cjs"),m=require("./server-entry-ea2a8b0e.cjs");require("./blocks-exports.cjs");require("./get-class-prop-name-a86a3e60.cjs");require("./dynamic-renderer-b29b45ca.cjs");function $(e,n,u,k){function l(v){return typeof v=="string"}function d(v){return typeof v=="number"}function h(v,c){return(()=>{const y=c.property,f=c.operator;let r=c.value;if(c&&c.property==="urlPath"&&c.value&&typeof c.value=="string"&&c.value!=="/"&&c.value.endsWith("/")&&(r=c.value.slice(0,-1)),!(y&&f))return!0;if(Array.isArray(r))return f==="isNot"?r.every(S=>h(v,{property:y,operator:f,value:S})):!!r.find(S=>h(v,{property:y,operator:f,value:S}));const t=v[y];if(Array.isArray(t))return t.includes(r);switch(f){case"is":return t===r;case"isNot":return t!==r;case"contains":return(l(t)||Array.isArray(t))&&t.includes(String(r));case"startsWith":return l(t)&&t.startsWith(String(r));case"endsWith":return l(t)&&t.endsWith(String(r));case"greaterThan":return d(t)&&d(r)&&t>r;case"lessThan":return d(t)&&d(r)&&t<r;case"greaterThanOrEqualTo":return d(t)&&d(r)&&t>=r;case"lessThanOrEqualTo":return d(t)&&d(r)&&t<=r;default:return!1}})()}const o={query:n,startDate:u,endDate:k},w=e.date&&new Date(e.date)||new Date;return o.startDate&&new Date(o.startDate)>w||o.endDate&&new Date(o.endDate)<w?!1:!o.query||!o.query.length?!0:o.query.every(v=>h(e,v))}const j=`function getPersonalizedVariant(variants, blockId, 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
|
+
function removeVariants() {
|
|
16
|
+
variants?.forEach(function (_, index) {
|
|
17
|
+
document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
|
|
18
|
+
});
|
|
19
|
+
document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
|
|
20
|
+
document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
|
|
21
|
+
}
|
|
22
|
+
const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
|
|
23
|
+
if (locale) {
|
|
24
|
+
attributes.locale = locale;
|
|
25
|
+
}
|
|
26
|
+
const winningVariantIndex = variants?.findIndex(function (variant) {
|
|
27
|
+
return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
|
|
28
|
+
});
|
|
29
|
+
const isDebug = location.href.includes('builder.debug=true');
|
|
30
|
+
if (isDebug) {
|
|
31
|
+
console.debug('PersonalizationContainer', {
|
|
32
|
+
attributes,
|
|
33
|
+
variants,
|
|
34
|
+
winningVariantIndex
|
|
35
|
+
});
|
|
36
|
+
}
|
|
37
|
+
if (winningVariantIndex !== -1) {
|
|
38
|
+
const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
|
|
39
|
+
if (winningVariant) {
|
|
40
|
+
const parentNode = winningVariant.parentNode;
|
|
41
|
+
if (parentNode) {
|
|
42
|
+
const newParent = parentNode.cloneNode(false);
|
|
43
|
+
newParent.appendChild(winningVariant.content.firstChild);
|
|
44
|
+
newParent.appendChild(winningVariant.content.lastChild);
|
|
45
|
+
parentNode.parentNode?.replaceChild(newParent, parentNode);
|
|
46
|
+
}
|
|
47
|
+
if (isDebug) {
|
|
48
|
+
console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
} else if (variants && variants.length > 0) {
|
|
52
|
+
removeVariants();
|
|
53
|
+
}
|
|
54
|
+
}`,R=`function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
|
|
55
|
+
function isString(val) {
|
|
56
|
+
return typeof val === 'string';
|
|
57
|
+
}
|
|
58
|
+
function isNumber(val) {
|
|
59
|
+
return typeof val === 'number';
|
|
60
|
+
}
|
|
61
|
+
function objectMatchesQuery(userattr, query) {
|
|
62
|
+
const result = (() => {
|
|
63
|
+
const property = query.property;
|
|
64
|
+
const operator = query.operator;
|
|
65
|
+
let testValue = query.value;
|
|
66
|
+
if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {
|
|
67
|
+
testValue = query.value.slice(0, -1);
|
|
68
|
+
}
|
|
69
|
+
if (!(property && operator)) {
|
|
70
|
+
return true;
|
|
71
|
+
}
|
|
72
|
+
if (Array.isArray(testValue)) {
|
|
73
|
+
if (operator === 'isNot') {
|
|
74
|
+
return testValue.every(val => objectMatchesQuery(userattr, {
|
|
75
|
+
property,
|
|
76
|
+
operator,
|
|
77
|
+
value: val
|
|
78
|
+
}));
|
|
79
|
+
}
|
|
80
|
+
return !!testValue.find(val => objectMatchesQuery(userattr, {
|
|
81
|
+
property,
|
|
82
|
+
operator,
|
|
83
|
+
value: val
|
|
84
|
+
}));
|
|
85
|
+
}
|
|
86
|
+
const value = userattr[property];
|
|
87
|
+
if (Array.isArray(value)) {
|
|
88
|
+
return value.includes(testValue);
|
|
89
|
+
}
|
|
90
|
+
switch (operator) {
|
|
91
|
+
case 'is':
|
|
92
|
+
return value === testValue;
|
|
93
|
+
case 'isNot':
|
|
94
|
+
return value !== testValue;
|
|
95
|
+
case 'contains':
|
|
96
|
+
return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
|
|
97
|
+
case 'startsWith':
|
|
98
|
+
return isString(value) && value.startsWith(String(testValue));
|
|
99
|
+
case 'endsWith':
|
|
100
|
+
return isString(value) && value.endsWith(String(testValue));
|
|
101
|
+
case 'greaterThan':
|
|
102
|
+
return isNumber(value) && isNumber(testValue) && value > testValue;
|
|
103
|
+
case 'lessThan':
|
|
104
|
+
return isNumber(value) && isNumber(testValue) && value < testValue;
|
|
105
|
+
case 'greaterThanOrEqualTo':
|
|
106
|
+
return isNumber(value) && isNumber(testValue) && value >= testValue;
|
|
107
|
+
case 'lessThanOrEqualTo':
|
|
108
|
+
return isNumber(value) && isNumber(testValue) && value <= testValue;
|
|
109
|
+
default:
|
|
110
|
+
return false;
|
|
111
|
+
}
|
|
112
|
+
})();
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
const item = {
|
|
116
|
+
query,
|
|
117
|
+
startDate,
|
|
118
|
+
endDate
|
|
119
|
+
};
|
|
120
|
+
const now = userAttributes.date && new Date(userAttributes.date) || new Date();
|
|
121
|
+
if (item.startDate && new Date(item.startDate) > now) {
|
|
122
|
+
return false;
|
|
123
|
+
} else if (item.endDate && new Date(item.endDate) < now) {
|
|
124
|
+
return false;
|
|
125
|
+
}
|
|
126
|
+
if (!item.query || !item.query.length) {
|
|
127
|
+
return true;
|
|
128
|
+
}
|
|
129
|
+
return item.query.every(filter => {
|
|
130
|
+
return objectMatchesQuery(userAttributes, filter);
|
|
131
|
+
});
|
|
132
|
+
}`;function W(e,n){return!(!(e&&e.length>0)||!n||m.isBrowser())}function B(e){const{variants:n,previewingIndex:u,isHydrated:k,filteredVariants:l,fallbackBlocks:d}=e;if(k&&m.isEditing()&&typeof u=="number"&&u<((n==null?void 0:n.length)||0)&&!(l!=null&&l.length))return{blocks:n[u].blocks,path:`component.options.variants.${u}.blocks`};const o=l==null?void 0:l[0];return o?{blocks:o.blocks,path:`component.options.variants.${n==null?void 0:n.indexOf(o)}.blocks`}:{blocks:d||[],path:void 0}}const O=(e,n,u)=>`
|
|
133
|
+
(function() {
|
|
134
|
+
${R}
|
|
135
|
+
${j}
|
|
136
|
+
getPersonalizedVariant(${JSON.stringify(e)}, "${n}"${u?`, "${u}"`:""})
|
|
137
|
+
})();
|
|
138
|
+
`;function Q(e){var t,S,C,N,T,x,A;const n=g.useRef(null),[u,k]=g.useState(()=>m.userAttributesService.getUserAttributes()),[l,d]=g.useState(()=>{var a,s,i;return O(e.variants,((a=e.builderBlock)==null?void 0:a.id)||"none",(i=(s=e.builderContext)==null?void 0:s.rootState)==null?void 0:i.locale)}),[h,o]=g.useState(()=>[]),[w,v]=g.useState(()=>{var a;return W(e.variants,m.getDefaultCanTrack((a=e.builderContext)==null?void 0:a.canTrack))}),[c,q]=g.useState(()=>!1);function y(){return(e.variants||[]).filter(a=>{var s,i,V,p;return $({...(i=(s=e.builderContext)==null?void 0:s.rootState)!=null&&i.locale?{locale:(p=(V=e.builderContext)==null?void 0:V.rootState)==null?void 0:p.locale}:{},...u},a.query,a.startDate,a.endDate)})}function f(){var a;return B({variants:e.variants,fallbackBlocks:(a=e.builderBlock)==null?void 0:a.children,isHydrated:c,filteredVariants:y(),previewingIndex:e.previewingIndex})}function r(){return(e.variants||[]).map((a,s)=>{var i;return`[data-variant-id="${(i=e.builderBlock)==null?void 0:i.id}-${s}"] { display: none; } `}).join("")}return g.useEffect(()=>{var s;q(!0);const a=m.userAttributesService.subscribeOnUserAttributesChange(i=>{k(i)});if(!(m.isEditing()||m.isPreviewing())){const i=y()[0];n.current&&(n.current.dispatchEvent(new CustomEvent("builder.variantLoaded",{detail:{variant:i||"default",content:(s=e.builderContext)==null?void 0:s.content},bubbles:!0})),new IntersectionObserver(p=>{p.forEach(E=>{var I;E.isIntersecting&&n.current&&n.current.dispatchEvent(new CustomEvent("builder.variantDisplayed",{detail:{variant:i||"default",content:(I=e.builderContext)==null?void 0:I.content},bubbles:!0}))})}).observe(n.current))}h.push(a)},[]),g.useEffect(()=>()=>{h.forEach(a=>a())},[]),b.jsxs("div",{ref:n,...e.attributes,className:`builder-personalization-container ${((t=e.attributes)==null?void 0:t.class)||""}`,children:[w?b.jsxs(b.Fragment,{children:[(S=e.variants)==null?void 0:S.map((a,s)=>{var i,V;return b.jsx("template",{"data-variant-id":`${(i=e.builderBlock)==null?void 0:i.id}-${s}`,children:b.jsx(D.Blocks,{blocks:a.blocks,parent:(V=e.builderBlock)==null?void 0:V.id,path:`component.options.variants.${s}.blocks`})},s)}),b.jsx(D.InlinedStyles,{nonce:((C=e.builderContext)==null?void 0:C.nonce)||"",styles:r(),id:`variants-styles-${(N=e.builderBlock)==null?void 0:N.id}`}),b.jsx(P.InlinedScript,{nonce:((T=e.builderContext)==null?void 0:T.nonce)||"",scriptStr:l,id:`variants-script-${(x=e.builderBlock)==null?void 0:x.id}`})]}):null,b.jsx(D.Blocks,{blocks:f().blocks,parent:(A=e.builderBlock)==null?void 0:A.id,path:f().path})]})}exports.default=Q;
|
|
@@ -0,0 +1,379 @@
|
|
|
1
|
+
import { jsxs as x, Fragment as B, jsx as V } from "react/jsx-runtime";
|
|
2
|
+
import { useRef as O, useState as w, useEffect as q } from "react";
|
|
3
|
+
import { Blocks as E, InlinedStyles as R } from "./blocks-5e476ddc.js";
|
|
4
|
+
import { InlinedScript as j } from "./content-variants-36ca4fe5.js";
|
|
5
|
+
import { isBrowser as Q, isEditing as $, userAttributesService as P, getDefaultCanTrack as z, isPreviewing as _ } from "./server-entry-838c1f06.js";
|
|
6
|
+
import "./blocks-exports.mjs";
|
|
7
|
+
import "./get-class-prop-name-65d6824c.js";
|
|
8
|
+
import "./dynamic-renderer-8b343325.js";
|
|
9
|
+
function M(e, n, u, m) {
|
|
10
|
+
function o(f) {
|
|
11
|
+
return typeof f == "string";
|
|
12
|
+
}
|
|
13
|
+
function d(f) {
|
|
14
|
+
return typeof f == "number";
|
|
15
|
+
}
|
|
16
|
+
function b(f, c) {
|
|
17
|
+
return (() => {
|
|
18
|
+
const g = c.property, v = c.operator;
|
|
19
|
+
let r = c.value;
|
|
20
|
+
if (c && c.property === "urlPath" && c.value && typeof c.value == "string" && c.value !== "/" && c.value.endsWith("/") && (r = c.value.slice(0, -1)), !(g && v))
|
|
21
|
+
return !0;
|
|
22
|
+
if (Array.isArray(r))
|
|
23
|
+
return v === "isNot" ? r.every((h) => b(f, {
|
|
24
|
+
property: g,
|
|
25
|
+
operator: v,
|
|
26
|
+
value: h
|
|
27
|
+
})) : !!r.find((h) => b(f, {
|
|
28
|
+
property: g,
|
|
29
|
+
operator: v,
|
|
30
|
+
value: h
|
|
31
|
+
}));
|
|
32
|
+
const t = f[g];
|
|
33
|
+
if (Array.isArray(t))
|
|
34
|
+
return t.includes(r);
|
|
35
|
+
switch (v) {
|
|
36
|
+
case "is":
|
|
37
|
+
return t === r;
|
|
38
|
+
case "isNot":
|
|
39
|
+
return t !== r;
|
|
40
|
+
case "contains":
|
|
41
|
+
return (o(t) || Array.isArray(t)) && t.includes(String(r));
|
|
42
|
+
case "startsWith":
|
|
43
|
+
return o(t) && t.startsWith(String(r));
|
|
44
|
+
case "endsWith":
|
|
45
|
+
return o(t) && t.endsWith(String(r));
|
|
46
|
+
case "greaterThan":
|
|
47
|
+
return d(t) && d(r) && t > r;
|
|
48
|
+
case "lessThan":
|
|
49
|
+
return d(t) && d(r) && t < r;
|
|
50
|
+
case "greaterThanOrEqualTo":
|
|
51
|
+
return d(t) && d(r) && t >= r;
|
|
52
|
+
case "lessThanOrEqualTo":
|
|
53
|
+
return d(t) && d(r) && t <= r;
|
|
54
|
+
default:
|
|
55
|
+
return !1;
|
|
56
|
+
}
|
|
57
|
+
})();
|
|
58
|
+
}
|
|
59
|
+
const l = {
|
|
60
|
+
query: n,
|
|
61
|
+
startDate: u,
|
|
62
|
+
endDate: m
|
|
63
|
+
}, p = e.date && new Date(e.date) || /* @__PURE__ */ new Date();
|
|
64
|
+
return l.startDate && new Date(l.startDate) > p || l.endDate && new Date(l.endDate) < p ? !1 : !l.query || !l.query.length ? !0 : l.query.every((f) => b(e, f));
|
|
65
|
+
}
|
|
66
|
+
const U = `function getPersonalizedVariant(variants, blockId, locale) {
|
|
67
|
+
if (!navigator.cookieEnabled) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
function getCookie(name) {
|
|
71
|
+
const nameEQ = name + '=';
|
|
72
|
+
const ca = document.cookie.split(';');
|
|
73
|
+
for (let i = 0; i < ca.length; i++) {
|
|
74
|
+
let c = ca[i];
|
|
75
|
+
while (c.charAt(0) == ' ') c = c.substring(1, c.length);
|
|
76
|
+
if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length, c.length);
|
|
77
|
+
}
|
|
78
|
+
return null;
|
|
79
|
+
}
|
|
80
|
+
function removeVariants() {
|
|
81
|
+
variants?.forEach(function (_, index) {
|
|
82
|
+
document.querySelector('template[data-variant-id="' + blockId + '-' + index + '"]')?.remove();
|
|
83
|
+
});
|
|
84
|
+
document.querySelector('script[data-id="variants-script-' + blockId + '"]')?.remove();
|
|
85
|
+
document.querySelector('style[data-id="variants-styles-' + blockId + '"]')?.remove();
|
|
86
|
+
}
|
|
87
|
+
const attributes = JSON.parse(getCookie('builder.userAttributes') || '{}');
|
|
88
|
+
if (locale) {
|
|
89
|
+
attributes.locale = locale;
|
|
90
|
+
}
|
|
91
|
+
const winningVariantIndex = variants?.findIndex(function (variant) {
|
|
92
|
+
return filterWithCustomTargeting(attributes, variant.query, variant.startDate, variant.endDate);
|
|
93
|
+
});
|
|
94
|
+
const isDebug = location.href.includes('builder.debug=true');
|
|
95
|
+
if (isDebug) {
|
|
96
|
+
console.debug('PersonalizationContainer', {
|
|
97
|
+
attributes,
|
|
98
|
+
variants,
|
|
99
|
+
winningVariantIndex
|
|
100
|
+
});
|
|
101
|
+
}
|
|
102
|
+
if (winningVariantIndex !== -1) {
|
|
103
|
+
const winningVariant = document.querySelector('template[data-variant-id="' + blockId + '-' + winningVariantIndex + '"]');
|
|
104
|
+
if (winningVariant) {
|
|
105
|
+
const parentNode = winningVariant.parentNode;
|
|
106
|
+
if (parentNode) {
|
|
107
|
+
const newParent = parentNode.cloneNode(false);
|
|
108
|
+
newParent.appendChild(winningVariant.content.firstChild);
|
|
109
|
+
newParent.appendChild(winningVariant.content.lastChild);
|
|
110
|
+
parentNode.parentNode?.replaceChild(newParent, parentNode);
|
|
111
|
+
}
|
|
112
|
+
if (isDebug) {
|
|
113
|
+
console.debug('PersonalizationContainer', 'Winning variant Replaced:', winningVariant);
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
} else if (variants && variants.length > 0) {
|
|
117
|
+
removeVariants();
|
|
118
|
+
}
|
|
119
|
+
}`, H = `function filterWithCustomTargeting(userAttributes, query, startDate, endDate) {
|
|
120
|
+
function isString(val) {
|
|
121
|
+
return typeof val === 'string';
|
|
122
|
+
}
|
|
123
|
+
function isNumber(val) {
|
|
124
|
+
return typeof val === 'number';
|
|
125
|
+
}
|
|
126
|
+
function objectMatchesQuery(userattr, query) {
|
|
127
|
+
const result = (() => {
|
|
128
|
+
const property = query.property;
|
|
129
|
+
const operator = query.operator;
|
|
130
|
+
let testValue = query.value;
|
|
131
|
+
if (query && query.property === 'urlPath' && query.value && typeof query.value === 'string' && query.value !== '/' && query.value.endsWith('/')) {
|
|
132
|
+
testValue = query.value.slice(0, -1);
|
|
133
|
+
}
|
|
134
|
+
if (!(property && operator)) {
|
|
135
|
+
return true;
|
|
136
|
+
}
|
|
137
|
+
if (Array.isArray(testValue)) {
|
|
138
|
+
if (operator === 'isNot') {
|
|
139
|
+
return testValue.every(val => objectMatchesQuery(userattr, {
|
|
140
|
+
property,
|
|
141
|
+
operator,
|
|
142
|
+
value: val
|
|
143
|
+
}));
|
|
144
|
+
}
|
|
145
|
+
return !!testValue.find(val => objectMatchesQuery(userattr, {
|
|
146
|
+
property,
|
|
147
|
+
operator,
|
|
148
|
+
value: val
|
|
149
|
+
}));
|
|
150
|
+
}
|
|
151
|
+
const value = userattr[property];
|
|
152
|
+
if (Array.isArray(value)) {
|
|
153
|
+
return value.includes(testValue);
|
|
154
|
+
}
|
|
155
|
+
switch (operator) {
|
|
156
|
+
case 'is':
|
|
157
|
+
return value === testValue;
|
|
158
|
+
case 'isNot':
|
|
159
|
+
return value !== testValue;
|
|
160
|
+
case 'contains':
|
|
161
|
+
return (isString(value) || Array.isArray(value)) && value.includes(String(testValue));
|
|
162
|
+
case 'startsWith':
|
|
163
|
+
return isString(value) && value.startsWith(String(testValue));
|
|
164
|
+
case 'endsWith':
|
|
165
|
+
return isString(value) && value.endsWith(String(testValue));
|
|
166
|
+
case 'greaterThan':
|
|
167
|
+
return isNumber(value) && isNumber(testValue) && value > testValue;
|
|
168
|
+
case 'lessThan':
|
|
169
|
+
return isNumber(value) && isNumber(testValue) && value < testValue;
|
|
170
|
+
case 'greaterThanOrEqualTo':
|
|
171
|
+
return isNumber(value) && isNumber(testValue) && value >= testValue;
|
|
172
|
+
case 'lessThanOrEqualTo':
|
|
173
|
+
return isNumber(value) && isNumber(testValue) && value <= testValue;
|
|
174
|
+
default:
|
|
175
|
+
return false;
|
|
176
|
+
}
|
|
177
|
+
})();
|
|
178
|
+
return result;
|
|
179
|
+
}
|
|
180
|
+
const item = {
|
|
181
|
+
query,
|
|
182
|
+
startDate,
|
|
183
|
+
endDate
|
|
184
|
+
};
|
|
185
|
+
const now = userAttributes.date && new Date(userAttributes.date) || new Date();
|
|
186
|
+
if (item.startDate && new Date(item.startDate) > now) {
|
|
187
|
+
return false;
|
|
188
|
+
} else if (item.endDate && new Date(item.endDate) < now) {
|
|
189
|
+
return false;
|
|
190
|
+
}
|
|
191
|
+
if (!item.query || !item.query.length) {
|
|
192
|
+
return true;
|
|
193
|
+
}
|
|
194
|
+
return item.query.every(filter => {
|
|
195
|
+
return objectMatchesQuery(userAttributes, filter);
|
|
196
|
+
});
|
|
197
|
+
}`;
|
|
198
|
+
function L(e, n) {
|
|
199
|
+
return !(!(e && e.length > 0) || !n || Q());
|
|
200
|
+
}
|
|
201
|
+
function F(e) {
|
|
202
|
+
const {
|
|
203
|
+
variants: n,
|
|
204
|
+
previewingIndex: u,
|
|
205
|
+
isHydrated: m,
|
|
206
|
+
filteredVariants: o,
|
|
207
|
+
fallbackBlocks: d
|
|
208
|
+
} = e;
|
|
209
|
+
if (m && $() && typeof u == "number" && u < ((n == null ? void 0 : n.length) || 0) && !(o != null && o.length))
|
|
210
|
+
return {
|
|
211
|
+
blocks: n[u].blocks,
|
|
212
|
+
path: `component.options.variants.${u}.blocks`
|
|
213
|
+
};
|
|
214
|
+
const l = o == null ? void 0 : o[0];
|
|
215
|
+
return l ? {
|
|
216
|
+
blocks: l.blocks,
|
|
217
|
+
path: `component.options.variants.${n == null ? void 0 : n.indexOf(l)}.blocks`
|
|
218
|
+
} : {
|
|
219
|
+
blocks: d || [],
|
|
220
|
+
path: void 0
|
|
221
|
+
};
|
|
222
|
+
}
|
|
223
|
+
const G = (e, n, u) => `
|
|
224
|
+
(function() {
|
|
225
|
+
${H}
|
|
226
|
+
${U}
|
|
227
|
+
getPersonalizedVariant(${JSON.stringify(e)}, "${n}"${u ? `, "${u}"` : ""})
|
|
228
|
+
})();
|
|
229
|
+
`;
|
|
230
|
+
function re(e) {
|
|
231
|
+
var t, h, D, C, N, T, I;
|
|
232
|
+
const n = O(null), [u, m] = w(
|
|
233
|
+
() => P.getUserAttributes()
|
|
234
|
+
), [o, d] = w(
|
|
235
|
+
() => {
|
|
236
|
+
var a, s, i;
|
|
237
|
+
return G(
|
|
238
|
+
e.variants,
|
|
239
|
+
((a = e.builderBlock) == null ? void 0 : a.id) || "none",
|
|
240
|
+
(i = (s = e.builderContext) == null ? void 0 : s.rootState) == null ? void 0 : i.locale
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
), [b, l] = w(() => []), [p, f] = w(
|
|
244
|
+
() => {
|
|
245
|
+
var a;
|
|
246
|
+
return L(
|
|
247
|
+
e.variants,
|
|
248
|
+
z((a = e.builderContext) == null ? void 0 : a.canTrack)
|
|
249
|
+
);
|
|
250
|
+
}
|
|
251
|
+
), [c, S] = w(() => !1);
|
|
252
|
+
function g() {
|
|
253
|
+
return (e.variants || []).filter((a) => {
|
|
254
|
+
var s, i, y, k;
|
|
255
|
+
return M(
|
|
256
|
+
{
|
|
257
|
+
...(i = (s = e.builderContext) == null ? void 0 : s.rootState) != null && i.locale ? {
|
|
258
|
+
locale: (k = (y = e.builderContext) == null ? void 0 : y.rootState) == null ? void 0 : k.locale
|
|
259
|
+
} : {},
|
|
260
|
+
...u
|
|
261
|
+
},
|
|
262
|
+
a.query,
|
|
263
|
+
a.startDate,
|
|
264
|
+
a.endDate
|
|
265
|
+
);
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
function v() {
|
|
269
|
+
var a;
|
|
270
|
+
return F({
|
|
271
|
+
variants: e.variants,
|
|
272
|
+
fallbackBlocks: (a = e.builderBlock) == null ? void 0 : a.children,
|
|
273
|
+
isHydrated: c,
|
|
274
|
+
filteredVariants: g(),
|
|
275
|
+
previewingIndex: e.previewingIndex
|
|
276
|
+
});
|
|
277
|
+
}
|
|
278
|
+
function r() {
|
|
279
|
+
return (e.variants || []).map(
|
|
280
|
+
(a, s) => {
|
|
281
|
+
var i;
|
|
282
|
+
return `[data-variant-id="${(i = e.builderBlock) == null ? void 0 : i.id}-${s}"] { display: none; } `;
|
|
283
|
+
}
|
|
284
|
+
).join("");
|
|
285
|
+
}
|
|
286
|
+
return q(() => {
|
|
287
|
+
var s;
|
|
288
|
+
S(!0);
|
|
289
|
+
const a = P.subscribeOnUserAttributesChange(
|
|
290
|
+
(i) => {
|
|
291
|
+
m(i);
|
|
292
|
+
}
|
|
293
|
+
);
|
|
294
|
+
if (!($() || _())) {
|
|
295
|
+
const i = g()[0];
|
|
296
|
+
n.current && (n.current.dispatchEvent(
|
|
297
|
+
new CustomEvent("builder.variantLoaded", {
|
|
298
|
+
detail: {
|
|
299
|
+
variant: i || "default",
|
|
300
|
+
content: (s = e.builderContext) == null ? void 0 : s.content
|
|
301
|
+
},
|
|
302
|
+
bubbles: !0
|
|
303
|
+
})
|
|
304
|
+
), new IntersectionObserver((k) => {
|
|
305
|
+
k.forEach((W) => {
|
|
306
|
+
var A;
|
|
307
|
+
W.isIntersecting && n.current && n.current.dispatchEvent(
|
|
308
|
+
new CustomEvent("builder.variantDisplayed", {
|
|
309
|
+
detail: {
|
|
310
|
+
variant: i || "default",
|
|
311
|
+
content: (A = e.builderContext) == null ? void 0 : A.content
|
|
312
|
+
},
|
|
313
|
+
bubbles: !0
|
|
314
|
+
})
|
|
315
|
+
);
|
|
316
|
+
});
|
|
317
|
+
}).observe(n.current));
|
|
318
|
+
}
|
|
319
|
+
b.push(a);
|
|
320
|
+
}, []), q(() => () => {
|
|
321
|
+
b.forEach((a) => a());
|
|
322
|
+
}, []), /* @__PURE__ */ x(
|
|
323
|
+
"div",
|
|
324
|
+
{
|
|
325
|
+
ref: n,
|
|
326
|
+
...e.attributes,
|
|
327
|
+
className: `builder-personalization-container ${((t = e.attributes) == null ? void 0 : t.class) || ""}`,
|
|
328
|
+
children: [
|
|
329
|
+
p ? /* @__PURE__ */ x(B, { children: [
|
|
330
|
+
(h = e.variants) == null ? void 0 : h.map((a, s) => {
|
|
331
|
+
var i, y;
|
|
332
|
+
return /* @__PURE__ */ V(
|
|
333
|
+
"template",
|
|
334
|
+
{
|
|
335
|
+
"data-variant-id": `${(i = e.builderBlock) == null ? void 0 : i.id}-${s}`,
|
|
336
|
+
children: /* @__PURE__ */ V(
|
|
337
|
+
E,
|
|
338
|
+
{
|
|
339
|
+
blocks: a.blocks,
|
|
340
|
+
parent: (y = e.builderBlock) == null ? void 0 : y.id,
|
|
341
|
+
path: `component.options.variants.${s}.blocks`
|
|
342
|
+
}
|
|
343
|
+
)
|
|
344
|
+
},
|
|
345
|
+
s
|
|
346
|
+
);
|
|
347
|
+
}),
|
|
348
|
+
/* @__PURE__ */ V(
|
|
349
|
+
R,
|
|
350
|
+
{
|
|
351
|
+
nonce: ((D = e.builderContext) == null ? void 0 : D.nonce) || "",
|
|
352
|
+
styles: r(),
|
|
353
|
+
id: `variants-styles-${(C = e.builderBlock) == null ? void 0 : C.id}`
|
|
354
|
+
}
|
|
355
|
+
),
|
|
356
|
+
/* @__PURE__ */ V(
|
|
357
|
+
j,
|
|
358
|
+
{
|
|
359
|
+
nonce: ((N = e.builderContext) == null ? void 0 : N.nonce) || "",
|
|
360
|
+
scriptStr: o,
|
|
361
|
+
id: `variants-script-${(T = e.builderBlock) == null ? void 0 : T.id}`
|
|
362
|
+
}
|
|
363
|
+
)
|
|
364
|
+
] }) : null,
|
|
365
|
+
/* @__PURE__ */ V(
|
|
366
|
+
E,
|
|
367
|
+
{
|
|
368
|
+
blocks: v().blocks,
|
|
369
|
+
parent: (I = e.builderBlock) == null ? void 0 : I.id,
|
|
370
|
+
path: v().path
|
|
371
|
+
}
|
|
372
|
+
)
|
|
373
|
+
]
|
|
374
|
+
}
|
|
375
|
+
);
|
|
376
|
+
}
|
|
377
|
+
export {
|
|
378
|
+
re as default
|
|
379
|
+
};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { jsx as l } from "react/jsx-runtime";
|
|
2
2
|
import { createElement as m } from "react";
|
|
3
|
-
import { isEditing as n } from "./server-entry-
|
|
3
|
+
import { isEditing as n } from "./server-entry-838c1f06.js";
|
|
4
4
|
function r(e) {
|
|
5
5
|
var t;
|
|
6
6
|
return /* @__PURE__ */ m(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),n=require("react"),r=require("./server-entry-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const l=require("react/jsx-runtime"),n=require("react"),r=require("./server-entry-ea2a8b0e.cjs");function i(e){var u;return n.createElement("select",{...e.attributes,value:e.value,key:r.isEditing()&&e.defaultValue?e.defaultValue:"default-key",defaultValue:e.defaultValue,name:e.name,required:e.required},(u=e.options)==null?void 0:u.map((t,a)=>l.jsx("option",{value:t.value,children:t.name||t.value},`${t.name}-${a}`)))}exports.default=i;
|