@builder.io/sdk-react 4.0.8 → 4.0.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/lib/browser/blocks-exports.cjs +92 -64
  2. package/lib/browser/blocks-exports.mjs +1753 -1653
  3. package/lib/browser/index.cjs +1 -1
  4. package/lib/browser/index.mjs +1 -1
  5. package/lib/browser/{server-entry-d0b98fb0.js → server-entry-231f8ecd.js} +1 -1
  6. package/lib/browser/{server-entry-8ea5d047.cjs → server-entry-bdbd3c0d.cjs} +1 -1
  7. package/lib/browser/server-entry.cjs +1 -1
  8. package/lib/browser/server-entry.mjs +1 -1
  9. package/lib/edge/{accordion-8ef468e5.js → accordion-b551e135.js} +1 -1
  10. package/lib/edge/{accordion-94839d7d.cjs → accordion-e3f81e74.cjs} +1 -1
  11. package/lib/edge/{blocks-548ec8c2.js → blocks-cd1feef2.js} +179 -176
  12. package/lib/edge/{blocks-7e8837dc.cjs → blocks-eb6fa21f.cjs} +3 -3
  13. package/lib/edge/blocks-exports.cjs +1 -1
  14. package/lib/edge/blocks-exports.mjs +2 -2
  15. package/lib/edge/{button-66c37b9c.cjs → button-5c6a9392.cjs} +1 -1
  16. package/lib/edge/{button-09f38c2e.js → button-f390f723.js} +2 -2
  17. package/lib/edge/{columns-42cbe467.js → columns-7018a027.js} +9 -9
  18. package/lib/edge/{columns-67ded4b4.cjs → columns-ad17139e.cjs} +3 -3
  19. package/lib/edge/content-variants-c72ca81f.cjs +302 -0
  20. package/lib/edge/{content-variants-5a4eecaf.js → content-variants-dc54ce4f.js} +650 -367
  21. package/lib/edge/{custom-code-cf216b27.js → custom-code-0daf1c91.js} +1 -1
  22. package/lib/edge/{custom-code-ea534e98.cjs → custom-code-e87af7b1.cjs} +1 -1
  23. package/lib/edge/{embed-12b85639.js → embed-1dfcba43.js} +1 -1
  24. package/lib/edge/{embed-7ca4af6e.cjs → embed-c695c98e.cjs} +1 -1
  25. package/lib/edge/{form-f1188ad2.js → form-5a0c89d9.js} +5 -5
  26. package/lib/edge/{form-85ea06df.cjs → form-ba54942c.cjs} +1 -1
  27. package/lib/edge/{get-class-prop-name-90df5962.js → get-class-prop-name-5edacc3b.js} +1 -1
  28. package/lib/edge/{get-class-prop-name-316a93c9.cjs → get-class-prop-name-c479656a.cjs} +1 -1
  29. package/lib/edge/{image-e38bd9e0.cjs → image-cce92f6c.cjs} +2 -2
  30. package/lib/edge/{image-acc1c00c.js → image-d87761af.js} +18 -18
  31. package/lib/edge/{img-81a7f4d7.cjs → img-6982d6eb.cjs} +1 -1
  32. package/lib/edge/{img-ee2838af.js → img-882c7222.js} +1 -1
  33. package/lib/edge/index.cjs +1 -1
  34. package/lib/edge/index.mjs +1 -1
  35. package/lib/edge/{input-b8907c7d.js → input-3d4f956b.js} +1 -1
  36. package/lib/edge/{input-231ec63f.cjs → input-8c7008b5.cjs} +1 -1
  37. package/lib/edge/personalization-container-3a8dc18a.js +205 -0
  38. package/lib/edge/personalization-container-4557a50b.cjs +1 -0
  39. package/lib/edge/{select-ffee7a69.js → select-153586f8.js} +1 -1
  40. package/lib/edge/{select-b1650a75.cjs → select-2efc7503.cjs} +1 -1
  41. package/lib/edge/{server-entry-e9974799.js → server-entry-8dc3478a.js} +1 -1
  42. package/lib/edge/{server-entry-1b560ddb.cjs → server-entry-9d269960.cjs} +1 -1
  43. package/lib/edge/server-entry.cjs +1 -1
  44. package/lib/edge/server-entry.mjs +1 -1
  45. package/lib/edge/{slot-fe93ec42.js → slot-d268693c.js} +3 -3
  46. package/lib/edge/{slot-ddddba8d.cjs → slot-f1f7513c.cjs} +1 -1
  47. package/lib/edge/{symbol-d9175a66.cjs → symbol-0344516c.cjs} +1 -1
  48. package/lib/edge/{symbol-c266ba83.js → symbol-378e19ee.js} +2 -2
  49. package/lib/edge/{tabs-3481a6f6.js → tabs-29ff78a0.js} +3 -3
  50. package/lib/edge/{tabs-f76f757a.cjs → tabs-4e931765.cjs} +1 -1
  51. package/lib/node/blocks-exports.cjs +92 -64
  52. package/lib/node/blocks-exports.mjs +1682 -1582
  53. package/lib/node/index.cjs +1 -1
  54. package/lib/node/index.mjs +3 -3
  55. package/lib/node/init.cjs +1 -1
  56. package/lib/node/init.mjs +3 -3
  57. package/lib/node/{server-entry-03fc1c6d.cjs → server-entry-916c726c.cjs} +1 -1
  58. package/lib/node/{server-entry-2b91f2d9.js → server-entry-f03c1146.js} +1 -1
  59. package/lib/node/server-entry.cjs +1 -1
  60. package/lib/node/server-entry.mjs +1 -1
  61. package/lib/node/{setIvm-419a94e0.js → setIvm-044ce9e7.js} +1 -1
  62. package/lib/node/{setIvm-26e766c5.cjs → setIvm-3761bb10.cjs} +1 -1
  63. package/lib/node/setIvm.cjs +1 -1
  64. package/lib/node/setIvm.mjs +2 -2
  65. package/lib/node/{should-force-browser-runtime-in-node-fe3d9cb0.cjs → should-force-browser-runtime-in-node-e760d4f2.cjs} +1 -1
  66. package/lib/node/{should-force-browser-runtime-in-node-67506521.js → should-force-browser-runtime-in-node-f620dcdc.js} +1 -1
  67. package/package.json +2 -2
  68. package/types/blocks/personalization-container/helpers/inlined-fns.d.ts +4 -1
  69. package/types/blocks/personalization-container/helpers.d.ts +24 -4
  70. package/types/blocks/personalization-container/personalization-container.types.d.ts +2 -2
  71. package/types/components/blocks/blocks-wrapper.d.ts +13 -1
  72. package/types/components/blocks/blocks.types.d.ts +1 -1
  73. package/types/constants/sdk-version.d.ts +1 -1
  74. package/lib/edge/content-variants-cf107f82.cjs +0 -137
  75. package/lib/edge/personalization-container-896a298a.js +0 -384
  76. package/lib/edge/personalization-container-95cba946.cjs +0 -138
@@ -1,384 +0,0 @@
1
- import { jsxs as q, Fragment as R, jsx as p } from "react/jsx-runtime";
2
- import { useRef as j, useState as V, useEffect as E } from "react";
3
- import { Blocks as x, InlinedStyles as B } from "./blocks-548ec8c2.js";
4
- import { InlinedScript as Q } from "./content-variants-5a4eecaf.js";
5
- import { isBrowser as $, isEditing as W, userAttributesService as P, getDefaultCanTrack as z, isPreviewing as _ } from "./server-entry-e9974799.js";
6
- import "./blocks-exports.mjs";
7
- import "./get-class-prop-name-90df5962.js";
8
- import "./dynamic-renderer-8b343325.js";
9
- function M(e, a, d, h) {
10
- function f(c) {
11
- return typeof c == "string";
12
- }
13
- function o(c) {
14
- return typeof c == "number";
15
- }
16
- function b(c, l) {
17
- return (() => {
18
- const g = l.property, v = l.operator;
19
- let n = l.value;
20
- if (l && l.property === "urlPath" && l.value && typeof l.value == "string" && l.value !== "/" && l.value.endsWith("/") && (n = l.value.slice(0, -1)), !(g && v))
21
- return !0;
22
- if (Array.isArray(n))
23
- return v === "isNot" ? n.every((m) => b(c, {
24
- property: g,
25
- operator: v,
26
- value: m
27
- })) : !!n.find((m) => b(c, {
28
- property: g,
29
- operator: v,
30
- value: m
31
- }));
32
- const t = c[g];
33
- if (Array.isArray(t))
34
- return t.includes(n);
35
- switch (v) {
36
- case "is":
37
- return t === n;
38
- case "isNot":
39
- return t !== n;
40
- case "contains":
41
- return (f(t) || Array.isArray(t)) && t.includes(String(n));
42
- case "startsWith":
43
- return f(t) && t.startsWith(String(n));
44
- case "endsWith":
45
- return f(t) && t.endsWith(String(n));
46
- case "greaterThan":
47
- return o(t) && o(n) && t > n;
48
- case "lessThan":
49
- return o(t) && o(n) && t < n;
50
- case "greaterThanOrEqualTo":
51
- return o(t) && o(n) && t >= n;
52
- case "lessThanOrEqualTo":
53
- return o(t) && o(n) && t <= n;
54
- default:
55
- return !1;
56
- }
57
- })();
58
- }
59
- const s = {
60
- query: a,
61
- startDate: d,
62
- endDate: h
63
- }, S = e.date && new Date(e.date) || /* @__PURE__ */ new Date();
64
- return s.startDate && new Date(s.startDate) > S || s.endDate && new Date(s.endDate) < S ? !1 : !s.query || !s.query.length ? !0 : s.query.every((c) => b(e, c));
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, a) {
199
- return !(!(e && e.length > 0) || !a || $());
200
- }
201
- function F({
202
- variants: e,
203
- previewingIndex: a,
204
- isHydrated: d,
205
- filteredVariants: h,
206
- fallbackBlocks: f
207
- }) {
208
- var b;
209
- const o = {
210
- blocks: f != null ? f : [],
211
- path: "this.children"
212
- };
213
- if (d && W())
214
- return typeof a == "number" && a < ((b = e == null ? void 0 : e.length) != null ? b : 0) ? {
215
- blocks: e[a].blocks,
216
- path: `component.options.variants.${a}.blocks`
217
- } : o;
218
- if ($()) {
219
- const s = h == null ? void 0 : h[0];
220
- if (s)
221
- return {
222
- blocks: s.blocks,
223
- path: `component.options.variants.${e == null ? void 0 : e.indexOf(s)}.blocks`
224
- };
225
- }
226
- return o;
227
- }
228
- const G = (e, a, d) => `
229
- (function() {
230
- ${H}
231
- ${U}
232
- getPersonalizedVariant(${JSON.stringify(e)}, "${a}"${d ? `, "${d}"` : ""})
233
- })();
234
- `;
235
- function re(e) {
236
- var t, m, D, N, C, T, A;
237
- const a = j(null), [d, h] = V(
238
- () => P.getUserAttributes()
239
- ), [f, o] = V(
240
- () => {
241
- var r, u, i;
242
- return G(
243
- e.variants,
244
- ((r = e.builderBlock) == null ? void 0 : r.id) || "none",
245
- (i = (u = e.builderContext) == null ? void 0 : u.rootState) == null ? void 0 : i.locale
246
- );
247
- }
248
- ), [b, s] = V(() => []), [S, c] = V(
249
- () => {
250
- var r;
251
- return L(
252
- e.variants,
253
- z((r = e.builderContext) == null ? void 0 : r.canTrack)
254
- );
255
- }
256
- ), [l, k] = V(() => !1);
257
- function g() {
258
- return (e.variants || []).filter((r) => {
259
- var u, i, y, w;
260
- return M(
261
- {
262
- ...(i = (u = e.builderContext) == null ? void 0 : u.rootState) != null && i.locale ? {
263
- locale: (w = (y = e.builderContext) == null ? void 0 : y.rootState) == null ? void 0 : w.locale
264
- } : {},
265
- ...d
266
- },
267
- r.query,
268
- r.startDate,
269
- r.endDate
270
- );
271
- });
272
- }
273
- function v() {
274
- var r;
275
- return F({
276
- variants: e.variants,
277
- fallbackBlocks: (r = e.builderBlock) == null ? void 0 : r.children,
278
- isHydrated: l,
279
- filteredVariants: g(),
280
- previewingIndex: e.previewingIndex
281
- });
282
- }
283
- function n() {
284
- return (e.variants || []).map(
285
- (r, u) => {
286
- var i;
287
- return `[data-variant-id="${(i = e.builderBlock) == null ? void 0 : i.id}-${u}"] { display: none; } `;
288
- }
289
- ).join("");
290
- }
291
- return E(() => {
292
- var u;
293
- k(!0);
294
- const r = P.subscribeOnUserAttributesChange(
295
- (i) => {
296
- h(i);
297
- }
298
- );
299
- if (!(W() || _())) {
300
- const i = g()[0];
301
- a.current && (a.current.dispatchEvent(
302
- new CustomEvent("builder.variantLoaded", {
303
- detail: {
304
- variant: i || "default",
305
- content: (u = e.builderContext) == null ? void 0 : u.content
306
- },
307
- bubbles: !0
308
- })
309
- ), new IntersectionObserver((w) => {
310
- w.forEach((O) => {
311
- var I;
312
- O.isIntersecting && a.current && a.current.dispatchEvent(
313
- new CustomEvent("builder.variantDisplayed", {
314
- detail: {
315
- variant: i || "default",
316
- content: (I = e.builderContext) == null ? void 0 : I.content
317
- },
318
- bubbles: !0
319
- })
320
- );
321
- });
322
- }).observe(a.current));
323
- }
324
- b.push(r);
325
- }, []), E(() => () => {
326
- b.forEach((r) => r());
327
- }, []), /* @__PURE__ */ q(
328
- "div",
329
- {
330
- ref: a,
331
- ...e.attributes,
332
- className: `builder-personalization-container ${((t = e.attributes) == null ? void 0 : t.className) || ""}`,
333
- children: [
334
- S ? /* @__PURE__ */ q(R, { children: [
335
- (m = e.variants) == null ? void 0 : m.map((r, u) => {
336
- var i, y;
337
- return /* @__PURE__ */ p(
338
- "template",
339
- {
340
- "data-variant-id": `${(i = e.builderBlock) == null ? void 0 : i.id}-${u}`,
341
- children: /* @__PURE__ */ p(
342
- x,
343
- {
344
- blocks: r.blocks,
345
- parent: (y = e.builderBlock) == null ? void 0 : y.id,
346
- path: `component.options.variants.${u}.blocks`
347
- }
348
- )
349
- },
350
- u
351
- );
352
- }),
353
- /* @__PURE__ */ p(
354
- B,
355
- {
356
- nonce: ((D = e.builderContext) == null ? void 0 : D.nonce) || "",
357
- styles: n(),
358
- id: `variants-styles-${(N = e.builderBlock) == null ? void 0 : N.id}`
359
- }
360
- ),
361
- /* @__PURE__ */ p(
362
- Q,
363
- {
364
- nonce: ((C = e.builderContext) == null ? void 0 : C.nonce) || "",
365
- scriptStr: f,
366
- id: `variants-script-${(T = e.builderBlock) == null ? void 0 : T.id}`
367
- }
368
- )
369
- ] }) : null,
370
- /* @__PURE__ */ p(
371
- x,
372
- {
373
- blocks: v().blocks,
374
- parent: (A = e.builderBlock) == null ? void 0 : A.id,
375
- path: v().path
376
- }
377
- )
378
- ]
379
- }
380
- );
381
- }
382
- export {
383
- re as default
384
- };
@@ -1,138 +0,0 @@
1
- "use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),g=require("react"),D=require("./blocks-7e8837dc.cjs"),P=require("./content-variants-cf107f82.cjs"),y=require("./server-entry-1b560ddb.cjs");require("./blocks-exports.cjs");require("./get-class-prop-name-316a93c9.cjs");require("./dynamic-renderer-b29b45ca.cjs");function $(e,a,d,m){function f(c){return typeof c=="string"}function o(c){return typeof c=="number"}function b(c,l){return(()=>{const S=l.property,v=l.operator;let n=l.value;if(l&&l.property==="urlPath"&&l.value&&typeof l.value=="string"&&l.value!=="/"&&l.value.endsWith("/")&&(n=l.value.slice(0,-1)),!(S&&v))return!0;if(Array.isArray(n))return v==="isNot"?n.every(V=>b(c,{property:S,operator:v,value:V})):!!n.find(V=>b(c,{property:S,operator:v,value:V}));const t=c[S];if(Array.isArray(t))return t.includes(n);switch(v){case"is":return t===n;case"isNot":return t!==n;case"contains":return(f(t)||Array.isArray(t))&&t.includes(String(n));case"startsWith":return f(t)&&t.startsWith(String(n));case"endsWith":return f(t)&&t.endsWith(String(n));case"greaterThan":return o(t)&&o(n)&&t>n;case"lessThan":return o(t)&&o(n)&&t<n;case"greaterThanOrEqualTo":return o(t)&&o(n)&&t>=n;case"lessThanOrEqualTo":return o(t)&&o(n)&&t<=n;default:return!1}})()}const u={query:a,startDate:d,endDate:m},w=e.date&&new Date(e.date)||new Date;return u.startDate&&new Date(u.startDate)>w||u.endDate&&new Date(u.endDate)<w?!1:!u.query||!u.query.length?!0:u.query.every(c=>b(e,c))}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,a){return!(!(e&&e.length>0)||!a||y.isBrowser())}function O({variants:e,previewingIndex:a,isHydrated:d,filteredVariants:m,fallbackBlocks:f}){var b;const o={blocks:f!=null?f:[],path:"this.children"};if(d&&y.isEditing())return typeof a=="number"&&a<((b=e==null?void 0:e.length)!=null?b:0)?{blocks:e[a].blocks,path:`component.options.variants.${a}.blocks`}:o;if(y.isBrowser()){const u=m==null?void 0:m[0];if(u)return{blocks:u.blocks,path:`component.options.variants.${e==null?void 0:e.indexOf(u)}.blocks`}}return o}const B=(e,a,d)=>`
133
- (function() {
134
- ${R}
135
- ${j}
136
- getPersonalizedVariant(${JSON.stringify(e)}, "${a}"${d?`, "${d}"`:""})
137
- })();
138
- `;function Q(e){var t,V,q,C,T,A,E;const a=g.useRef(null),[d,m]=g.useState(()=>y.userAttributesService.getUserAttributes()),[f,o]=g.useState(()=>{var r,s,i;return B(e.variants,((r=e.builderBlock)==null?void 0:r.id)||"none",(i=(s=e.builderContext)==null?void 0:s.rootState)==null?void 0:i.locale)}),[b,u]=g.useState(()=>[]),[w,c]=g.useState(()=>{var r;return W(e.variants,y.getDefaultCanTrack((r=e.builderContext)==null?void 0:r.canTrack))}),[l,N]=g.useState(()=>!1);function S(){return(e.variants||[]).filter(r=>{var s,i,p,k;return $({...(i=(s=e.builderContext)==null?void 0:s.rootState)!=null&&i.locale?{locale:(k=(p=e.builderContext)==null?void 0:p.rootState)==null?void 0:k.locale}:{},...d},r.query,r.startDate,r.endDate)})}function v(){var r;return O({variants:e.variants,fallbackBlocks:(r=e.builderBlock)==null?void 0:r.children,isHydrated:l,filteredVariants:S(),previewingIndex:e.previewingIndex})}function n(){return(e.variants||[]).map((r,s)=>{var i;return`[data-variant-id="${(i=e.builderBlock)==null?void 0:i.id}-${s}"] { display: none; } `}).join("")}return g.useEffect(()=>{var s;N(!0);const r=y.userAttributesService.subscribeOnUserAttributesChange(i=>{m(i)});if(!(y.isEditing()||y.isPreviewing())){const i=S()[0];a.current&&(a.current.dispatchEvent(new CustomEvent("builder.variantLoaded",{detail:{variant:i||"default",content:(s=e.builderContext)==null?void 0:s.content},bubbles:!0})),new IntersectionObserver(k=>{k.forEach(I=>{var x;I.isIntersecting&&a.current&&a.current.dispatchEvent(new CustomEvent("builder.variantDisplayed",{detail:{variant:i||"default",content:(x=e.builderContext)==null?void 0:x.content},bubbles:!0}))})}).observe(a.current))}b.push(r)},[]),g.useEffect(()=>()=>{b.forEach(r=>r())},[]),h.jsxs("div",{ref:a,...e.attributes,className:`builder-personalization-container ${((t=e.attributes)==null?void 0:t.className)||""}`,children:[w?h.jsxs(h.Fragment,{children:[(V=e.variants)==null?void 0:V.map((r,s)=>{var i,p;return h.jsx("template",{"data-variant-id":`${(i=e.builderBlock)==null?void 0:i.id}-${s}`,children:h.jsx(D.Blocks,{blocks:r.blocks,parent:(p=e.builderBlock)==null?void 0:p.id,path:`component.options.variants.${s}.blocks`})},s)}),h.jsx(D.InlinedStyles,{nonce:((q=e.builderContext)==null?void 0:q.nonce)||"",styles:n(),id:`variants-styles-${(C=e.builderBlock)==null?void 0:C.id}`}),h.jsx(P.InlinedScript,{nonce:((T=e.builderContext)==null?void 0:T.nonce)||"",scriptStr:f,id:`variants-script-${(A=e.builderBlock)==null?void 0:A.id}`})]}):null,h.jsx(D.Blocks,{blocks:v().blocks,parent:(E=e.builderBlock)==null?void 0:E.id,path:v().path})]})}exports.default=Q;