@builder.io/sdk-react 4.0.8 → 4.0.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (83) hide show
  1. package/lib/browser/blocks-exports.cjs +92 -64
  2. package/lib/browser/blocks-exports.mjs +1765 -1650
  3. package/lib/browser/index.cjs +1 -1
  4. package/lib/browser/index.mjs +1 -1
  5. package/lib/browser/server-entry-6a0d3985.cjs +2 -0
  6. package/lib/{edge/server-entry-e9974799.js → browser/server-entry-a97b474c.js} +272 -265
  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-39aaa10f.js} +1 -1
  10. package/lib/edge/{accordion-94839d7d.cjs → accordion-f19408f1.cjs} +1 -1
  11. package/lib/edge/{blocks-548ec8c2.js → blocks-204bcb03.js} +179 -176
  12. package/lib/edge/{blocks-7e8837dc.cjs → blocks-bd4d19a4.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-39adadab.cjs} +1 -1
  16. package/lib/edge/{button-09f38c2e.js → button-eb4a1fce.js} +2 -2
  17. package/lib/edge/{columns-67ded4b4.cjs → columns-3954e4e2.cjs} +3 -3
  18. package/lib/edge/{columns-42cbe467.js → columns-d3cef236.js} +9 -9
  19. package/lib/edge/content-variants-0c41aa3b.cjs +302 -0
  20. package/lib/edge/{content-variants-5a4eecaf.js → content-variants-68bbb30c.js} +650 -367
  21. package/lib/edge/{custom-code-ea534e98.cjs → custom-code-eded3b35.cjs} +1 -1
  22. package/lib/edge/{custom-code-cf216b27.js → custom-code-f8374f7b.js} +1 -1
  23. package/lib/edge/{embed-12b85639.js → embed-2b4ce9d5.js} +1 -1
  24. package/lib/edge/{embed-7ca4af6e.cjs → embed-44dee332.cjs} +1 -1
  25. package/lib/edge/form-1493caf1.cjs +1 -0
  26. package/lib/edge/form-9faf63c9.js +178 -0
  27. package/lib/edge/{get-class-prop-name-316a93c9.cjs → get-class-prop-name-a9265175.cjs} +1 -1
  28. package/lib/edge/{get-class-prop-name-90df5962.js → get-class-prop-name-cc48fc17.js} +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-ee2838af.js → img-58c08dd4.js} +1 -1
  32. package/lib/edge/{img-81a7f4d7.cjs → img-b8d85bad.cjs} +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-a7c01b3a.js} +1 -1
  36. package/lib/edge/{input-231ec63f.cjs → input-d988f887.cjs} +1 -1
  37. package/lib/edge/personalization-container-2f2bfa1b.cjs +1 -0
  38. package/lib/edge/personalization-container-9ae00624.js +208 -0
  39. package/lib/edge/{select-b1650a75.cjs → select-03b307f2.cjs} +1 -1
  40. package/lib/edge/{select-ffee7a69.js → select-4f03decc.js} +1 -1
  41. package/lib/{node/server-entry-2b91f2d9.js → edge/server-entry-0fe1fd76.js} +306 -303
  42. package/lib/edge/server-entry-e13b9b35.cjs +2 -0
  43. package/lib/edge/server-entry.cjs +1 -1
  44. package/lib/edge/server-entry.mjs +1 -1
  45. package/lib/edge/{slot-ddddba8d.cjs → slot-125b0593.cjs} +1 -1
  46. package/lib/edge/{slot-fe93ec42.js → slot-ff90c844.js} +3 -3
  47. package/lib/edge/{symbol-c266ba83.js → symbol-7558aa24.js} +2 -2
  48. package/lib/edge/{symbol-d9175a66.cjs → symbol-da3ec542.cjs} +1 -1
  49. package/lib/edge/{tabs-f76f757a.cjs → tabs-3cf7cfd3.cjs} +1 -1
  50. package/lib/edge/{tabs-3481a6f6.js → tabs-a9e56d82.js} +3 -3
  51. package/lib/node/blocks-exports.cjs +92 -64
  52. package/lib/node/blocks-exports.mjs +1675 -1560
  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/{browser/server-entry-d0b98fb0.js → node/server-entry-23f9b44b.js} +205 -199
  58. package/lib/node/server-entry-ceef853b.cjs +2 -0
  59. package/lib/node/server-entry.cjs +1 -1
  60. package/lib/node/server-entry.mjs +1 -1
  61. package/lib/node/{setIvm-26e766c5.cjs → setIvm-71bce8c3.cjs} +1 -1
  62. package/lib/node/{setIvm-419a94e0.js → setIvm-b29cbc40.js} +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-67506521.js → should-force-browser-runtime-in-node-5a2ea9eb.js} +1 -1
  66. package/lib/node/{should-force-browser-runtime-in-node-fe3d9cb0.cjs → should-force-browser-runtime-in-node-e0147364.cjs} +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/types/helpers/no-serialize-wrapper.d.ts +1 -0
  75. package/types/helpers/user-attributes.d.ts +6 -2
  76. package/lib/browser/server-entry-8ea5d047.cjs +0 -2
  77. package/lib/edge/content-variants-cf107f82.cjs +0 -137
  78. package/lib/edge/form-85ea06df.cjs +0 -1
  79. package/lib/edge/form-f1188ad2.js +0 -166
  80. package/lib/edge/personalization-container-896a298a.js +0 -384
  81. package/lib/edge/personalization-container-95cba946.cjs +0 -138
  82. package/lib/edge/server-entry-1b560ddb.cjs +0 -2
  83. package/lib/node/server-entry-03fc1c6d.cjs +0 -2
@@ -1,166 +0,0 @@
1
- import { jsxs as k, Fragment as A, jsx as m } from "react/jsx-runtime";
2
- import { useRef as j, useState as h } from "react";
3
- import { Blocks as g, set as J, get as O } from "./blocks-548ec8c2.js";
4
- import { isEditing as U, logFetch as R } from "./server-entry-e9974799.js";
5
- import "./blocks-exports.mjs";
6
- import "./get-class-prop-name-90df5962.js";
7
- import "./dynamic-renderer-8b343325.js";
8
- const $ = ["production", "qa", "test", "development", "dev", "cdn-qa", "cloud", "fast", "cdn2", "cdn-prod"], q = () => {
9
- const e = process.env.NODE_ENV || "production";
10
- return $.includes(e) ? e : "production";
11
- };
12
- function _(e) {
13
- const r = j(null), [T, b] = h(() => "unsubmitted"), [v, y] = h(() => null), [L, F] = h(() => "");
14
- function N(s) {
15
- var u, l;
16
- const c = {
17
- ...e.builderContext.rootState,
18
- ...s
19
- };
20
- e.builderContext.rootSetState ? (l = (u = e.builderContext).rootSetState) == null || l.call(u, c) : e.builderContext.rootState = c;
21
- }
22
- function f() {
23
- return U() && e.previewState || T;
24
- }
25
- function w(s) {
26
- var u;
27
- const c = e.sendWithJs || e.sendSubmissionsTo === "email";
28
- if (e.sendSubmissionsTo === "zapier")
29
- s.preventDefault();
30
- else if (c) {
31
- if (!(e.action || e.sendSubmissionsTo === "email")) {
32
- s.preventDefault();
33
- return;
34
- }
35
- s.preventDefault();
36
- const l = s.currentTarget || s.target, S = e.customHeaders || {};
37
- let d;
38
- const D = new FormData(l), E = Array.from(l.querySelectorAll("input,select,textarea")).filter((t) => !!t.name).map((t) => {
39
- let n;
40
- const o = t.name;
41
- if (t instanceof HTMLInputElement)
42
- if (t.type === "radio") {
43
- if (t.checked)
44
- return n = t.name, {
45
- key: o,
46
- value: n
47
- };
48
- } else if (t.type === "checkbox")
49
- n = t.checked;
50
- else if (t.type === "number" || t.type === "range") {
51
- const i = t.valueAsNumber;
52
- isNaN(i) || (n = i);
53
- } else
54
- t.type === "file" ? n = t.files : n = t.value;
55
- else
56
- n = t.value;
57
- return {
58
- key: o,
59
- value: n
60
- };
61
- });
62
- let a = e.contentType;
63
- if (e.sendSubmissionsTo === "email" && (a = "multipart/form-data"), Array.from(E).forEach(({ value: t }) => {
64
- (t instanceof File || Array.isArray(t) && t[0] instanceof File || t instanceof FileList) && (a = "multipart/form-data");
65
- }), a !== "application/json")
66
- d = D;
67
- else {
68
- const t = {};
69
- Array.from(E).forEach(({ value: n, key: o }) => {
70
- J(t, o, n);
71
- }), d = JSON.stringify(t);
72
- }
73
- a && a !== "multipart/form-data" && (c && ((u = e.action) != null && u.includes("zapier.com")) || (S["content-type"] = a));
74
- const x = new CustomEvent("presubmit", { detail: { body: d } });
75
- if (r.current && (r.current.dispatchEvent(x), x.defaultPrevented))
76
- return;
77
- b("sending");
78
- const P = `${q() === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${e.builderContext.apiKey}&to=${btoa(
79
- e.sendSubmissionsToEmail || ""
80
- )}&name=${encodeURIComponent(e.name || "")}`, C = e.sendSubmissionsTo === "email" ? P : e.action;
81
- R(C), fetch(C, { body: d, headers: S, method: e.method || "post" }).then(
82
- async (t) => {
83
- let n;
84
- const o = t.headers.get("content-type");
85
- if (o && o.indexOf("application/json") !== -1 ? n = await t.json() : n = await t.text(), !t.ok && e.errorMessagePath) {
86
- let i = O(n, e.errorMessagePath);
87
- i && (typeof i != "string" && (i = JSON.stringify(i)), F(i), N({ formErrorMessage: i }));
88
- }
89
- if (y(n), b(t.ok ? "success" : "error"), t.ok) {
90
- const i = new CustomEvent("submit:success", {
91
- detail: { res: t, body: n }
92
- });
93
- if (r.current) {
94
- if (r.current.dispatchEvent(i), i.defaultPrevented)
95
- return;
96
- e.resetFormOnSubmit !== !1 && r.current.reset();
97
- }
98
- if (e.successUrl)
99
- if (r.current) {
100
- const M = new CustomEvent("route", {
101
- detail: { url: e.successUrl }
102
- });
103
- r.current.dispatchEvent(M), M.defaultPrevented || (location.href = e.successUrl);
104
- } else
105
- location.href = e.successUrl;
106
- }
107
- },
108
- (t) => {
109
- const n = new CustomEvent("submit:error", {
110
- detail: { error: t }
111
- });
112
- r.current && (r.current.dispatchEvent(n), n.defaultPrevented) || (y(t), b("error"));
113
- }
114
- );
115
- }
116
- }
117
- return /* @__PURE__ */ k(A, { children: [
118
- " ",
119
- /* @__PURE__ */ k(
120
- "form",
121
- {
122
- validate: e.validate,
123
- ref: r,
124
- action: !e.sendWithJs && e.action,
125
- method: e.method,
126
- name: e.name,
127
- onSubmit: (s) => w(s),
128
- ...e.attributes,
129
- children: [
130
- e.children,
131
- f() === "error" ? /* @__PURE__ */ m(
132
- g,
133
- {
134
- path: "errorMessage",
135
- blocks: e.errorMessage,
136
- context: e.builderContext
137
- }
138
- ) : null,
139
- f() === "sending" ? /* @__PURE__ */ m(
140
- g,
141
- {
142
- path: "sendingMessage",
143
- blocks: e.sendingMessage,
144
- context: e.builderContext
145
- }
146
- ) : null,
147
- f() === "error" && v ? /* @__PURE__ */ m("pre", { className: "builder-form-error-text pre-7acc3b46", children: JSON.stringify(v, null, 2) }) : null,
148
- f() === "success" ? /* @__PURE__ */ m(
149
- g,
150
- {
151
- path: "successMessage",
152
- blocks: e.successMessage,
153
- context: e.builderContext
154
- }
155
- ) : null
156
- ]
157
- }
158
- ),
159
- " ",
160
- /* @__PURE__ */ m("style", { children: ".pre-7acc3b46 { padding: 10px; color: red; text-align: center; }" }),
161
- " "
162
- ] });
163
- }
164
- export {
165
- _ as default
166
- };
@@ -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;