@builder.io/sdk-react 3.0.5 → 3.0.6
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 +166 -29
- package/lib/browser/blocks-exports.mjs +1179 -765
- package/lib/browser/index.cjs +1 -1
- package/lib/browser/index.mjs +17 -16
- package/lib/browser/server-entry-a1c64831.cjs +2 -0
- package/lib/browser/{server-entry-785c0408.js → server-entry-df5e89e5.js} +279 -237
- package/lib/browser/server-entry.cjs +1 -1
- package/lib/browser/server-entry.mjs +1 -1
- package/lib/edge/{accordion-cd6e0363.js → accordion-289f3464.js} +1 -1
- package/lib/edge/{accordion-190c4426.cjs → accordion-fbfb71f4.cjs} +1 -1
- package/lib/edge/{blocks-766e8d45.cjs → blocks-459a090b.cjs} +10 -10
- package/lib/edge/{blocks-fe2d7c1a.js → blocks-582a7fd7.js} +87 -87
- package/lib/edge/blocks-exports.cjs +1 -1
- package/lib/edge/blocks-exports.mjs +13 -12
- package/lib/edge/{button-6a27481c.js → button-9b112da6.js} +2 -2
- package/lib/edge/{button-694fcd4f.cjs → button-da357144.cjs} +1 -1
- package/lib/edge/{columns-b38bf0f7.cjs → columns-a211113f.cjs} +1 -1
- package/lib/edge/{columns-90e6407e.js → columns-aba58dda.js} +3 -3
- package/lib/edge/{content-variants-cbb89349.js → content-variants-08f4371c.js} +165 -124
- package/lib/edge/content-variants-4b5899b5.cjs +134 -0
- package/lib/edge/dynamic-blocks-exports.cjs +3 -1
- package/lib/edge/dynamic-blocks-exports.mjs +5 -2
- package/lib/edge/{form-16bbf874.js → form-4d4553c2.js} +3 -3
- package/lib/edge/{form-547645eb.cjs → form-e3a3afd4.cjs} +1 -1
- package/lib/edge/{get-class-prop-name-8b719c6b.js → get-class-prop-name-38c2baca.js} +1 -1
- package/lib/edge/{get-class-prop-name-58770197.cjs → get-class-prop-name-fbe244e3.cjs} +1 -1
- package/lib/edge/{img-8859c851.cjs → img-8d549af8.cjs} +1 -1
- package/lib/edge/{img-d3351743.js → img-c49066fa.js} +1 -1
- package/lib/edge/index.cjs +1 -1
- package/lib/edge/index.mjs +18 -17
- package/lib/edge/{input-4fe0fc6d.cjs → input-1ae3842f.cjs} +1 -1
- package/lib/edge/{input-24c601b4.js → input-e7301f4e.js} +1 -1
- package/lib/edge/personalization-container-035be6ba.js +384 -0
- package/lib/edge/personalization-container-25cd8b5e.cjs +138 -0
- package/lib/edge/{select-af05377b.js → select-4187b229.js} +1 -1
- package/lib/edge/{select-c73bd418.cjs → select-64fdaa79.cjs} +1 -1
- package/lib/edge/server-entry-2ef4e66a.cjs +2 -0
- package/lib/edge/{server-entry-67bfc740.js → server-entry-61fca4f7.js} +322 -280
- package/lib/edge/server-entry.cjs +1 -1
- package/lib/edge/server-entry.mjs +1 -1
- package/lib/edge/{slot-759c8dd9.cjs → slot-995f63c2.cjs} +1 -1
- package/lib/edge/{slot-32a4df0c.js → slot-d6c46a42.js} +3 -3
- package/lib/edge/{symbol-8d63aa7d.cjs → symbol-498daa97.cjs} +1 -1
- package/lib/edge/{symbol-50360a37.js → symbol-623dc717.js} +2 -2
- package/lib/edge/{tabs-6535c934.js → tabs-12ba41b1.js} +3 -3
- package/lib/edge/{tabs-fc6c1700.cjs → tabs-d39499cd.cjs} +1 -1
- package/lib/node/blocks-exports.cjs +168 -31
- package/lib/node/blocks-exports.mjs +1292 -878
- 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-ffc70868.js → server-entry-27d9d31e.js} +279 -237
- package/lib/node/server-entry-98ebff74.cjs +2 -0
- package/lib/node/server-entry.cjs +1 -1
- package/lib/node/server-entry.mjs +1 -1
- package/lib/node/{setIvm-2cea7252.js → setIvm-2dde9074.js} +1 -1
- package/lib/node/{setIvm-4ce0db03.cjs → setIvm-784fe19f.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-c0d50009.js → should-force-browser-runtime-in-node-80f081c8.js} +1 -1
- package/lib/node/{should-force-browser-runtime-in-node-d3e6df07.cjs → should-force-browser-runtime-in-node-cd6baa94.cjs} +1 -1
- package/package.json +1 -1
- package/types/blocks/personalization-container/component-info.d.ts +2 -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/constants/sdk-version.d.ts +1 -1
- package/types/helpers/user-attributes.d.ts +17 -0
- package/types/index-helpers/blocks-exports.d.ts +1 -0
- package/types/types/input.d.ts +1 -0
- package/lib/browser/server-entry-101d66b8.cjs +0 -2
- package/lib/edge/content-variants-4e385c19.cjs +0 -134
- package/lib/edge/server-entry-3c7fa63a.cjs +0 -2
- package/lib/node/server-entry-95273908.cjs +0 -2
|
@@ -0,0 +1,384 @@
|
|
|
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-582a7fd7.js";
|
|
4
|
+
import { InlinedScript as Q } from "./content-variants-08f4371c.js";
|
|
5
|
+
import { isBrowser as $, isEditing as W, userAttributesService as P, getDefaultCanTrack as z, isPreviewing as _ } from "./server-entry-61fca4f7.js";
|
|
6
|
+
import "./blocks-exports.mjs";
|
|
7
|
+
import "./get-class-prop-name-38c2baca.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
|
+
};
|
|
@@ -0,0 +1,138 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const h=require("react/jsx-runtime"),g=require("react"),D=require("./blocks-459a090b.cjs"),P=require("./content-variants-4b5899b5.cjs"),y=require("./server-entry-2ef4e66a.cjs");require("./blocks-exports.cjs");require("./get-class-prop-name-fbe244e3.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;
|
|
@@ -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-61fca4f7.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-2ef4e66a.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;
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
"use strict";function c(){return typeof window!="undefined"&&typeof document!="undefined"}const E="[Builder.io]: ",d={log:(...t)=>console.log(E,...t),error:(...t)=>console.error(E,...t),warn:(...t)=>console.warn(E,...t),debug:(...t)=>console.debug(E,...t)},p=t=>t!=null,mt=t=>{if(t==="localhost"||t==="127.0.0.1")return t;const e=t.split(".");return e.length>2?e.slice(1).join("."):t},O=({name:t,canTrack:e})=>{var n;try{return e?(n=document.cookie.split("; ").find(r=>r.startsWith(`${t}=`)))==null?void 0:n.split("=")[1]:void 0}catch(r){d.warn("[COOKIE] GET error: ",(r==null?void 0:r.message)||r);return}},j=async t=>O(t),bt=t=>t.map(([e,n])=>n?`${e}=${n}`:e).filter(p).join("; "),yt=[["secure",""],["SameSite","None"]],St=({name:t,value:e,expires:n})=>{const s=(c()?location.protocol==="https:":!0)?yt:[[]],o=n?[["expires",n.toUTCString()]]:[[]],i=[[t,e],...o,["path","/"],["domain",mt(window.location.hostname)],...s];return bt(i)},C=async({name:t,value:e,expires:n,canTrack:r})=>{try{if(!r)return;const s=St({name:t,value:e,expires:n});document.cookie=s}catch(s){d.warn("[COOKIE] SET error: ",(s==null?void 0:s.message)||s)}},V="builder.userAttributes";function wt(){let t=!0;const e=new Set;return{setUserAttributes(n){if(!c())return;const r={...this.getUserAttributes(),...n};C({name:V,value:JSON.stringify(r),canTrack:t}),e.forEach(s=>s(r))},getUserAttributes(){return c()?JSON.parse(O({name:V,canTrack:t})||"{}"):{}},subscribeOnUserAttributesChange(n){return e.add(n),()=>{e.delete(n)}},setCanTrack(n){t=n}}}const P=wt(),vt=t=>{P.setUserAttributes(t)},y="react",Et=t=>{const e={};return t.forEach((n,r)=>{e[r]=n}),e},W=t=>t instanceof URLSearchParams?Et(t):t,$=t=>typeof t=="string"?t:t instanceof URLSearchParams?t.toString():new URLSearchParams(t).toString();function It(){return c()&&window.self!==window.top}function G(t){return It()&&$(t||window.location.search).indexOf("builder.frameEditing=")!==-1}function kt(t){const e=t||(c()?window.location.search:void 0);return e?$(e).indexOf("builder.preview=")!==-1:!1}const At=t=>({type:"builder.registerComponent",data:T(t)}),Ot=t=>{const e=t.toString().trim(),n=/^[a-zA-Z0-9_]+\s*=>/i.test(e);return`return (${!e.startsWith("function")&&!e.startsWith("async")&&!e.startsWith("(")&&!n?"function ":""}${e}).apply(this, arguments)`};function T(t){return JSON.parse(JSON.stringify(t,(e,n)=>typeof n=="function"?Ot(n):n))}const N={};function J(t,e){t==="plugin"&&(e=T(e));let n=N[t];if(n||(n=N[t]=[]),n.push(e),c()){const r={type:"builder.register",data:{type:t,info:e}};try{parent.postMessage(r,"*"),parent!==window&&window.postMessage(r,"*")}catch(s){console.debug("Could not postmessage",s)}}}const D={};function Ct(t){if(c()){Object.assign(D,t);const e={type:"builder.settingsChange",data:D};parent.postMessage(e,"*")}}const M="builder.",Pt="options.",U=t=>{if(!t)return{};const e=W(t),n={};return Object.keys(e).forEach(r=>{if(r.startsWith(M)){const s=r.replace(M,"").replace(Pt,"");n[s]=e[r]}}),n},Tt=()=>{if(!c())return{};const t=new URLSearchParams(window.location.search);return U(t)},z="3.0.6",H=()=>({"X-Builder-SDK":y,"X-Builder-SDK-GEN":"2","X-Builder-SDK-Version":z});function Ut(){return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,function(t){const e=Math.random()*16|0;return(t=="x"?e:e&3|8).toString(16)})}function X(){return Ut().replace(/-/g,"")}const Q="builderSessionId",Bt=async({canTrack:t})=>{if(!t)return;const e=await j({name:Q,canTrack:t});if(p(e))return e;{const n=xt();return Rt({id:n,canTrack:t}),n}},xt=()=>X(),Rt=({id:t,canTrack:e})=>C({name:Q,value:t,canTrack:e}),Y=()=>c()&&typeof localStorage!="undefined"?localStorage:void 0,Lt=({key:t,canTrack:e})=>{var n;try{return e?(n=Y())==null?void 0:n.getItem(t):void 0}catch(r){console.debug("[LocalStorage] GET error: ",r);return}},Ft=({key:t,canTrack:e,value:n})=>{var r;try{e&&((r=Y())==null||r.setItem(t,n))}catch(s){console.debug("[LocalStorage] SET error: ",s)}},Z="builderVisitorId",Vt=({canTrack:t})=>{if(!t)return;const e=Lt({key:Z,canTrack:t});if(p(e))return e;{const n=Nt();return Dt({id:n,canTrack:t}),n}},Nt=()=>X(),Dt=({id:t,canTrack:e})=>Ft({key:Z,value:t,canTrack:e});function q(t){var e;typeof process!="undefined"&&((e=process.env)!=null&&e.DEBUG)&&String(process.env.DEBUG)=="true"&&d.log(t)}const Mt=()=>{if(c()){const t=new URL(location.href);return t.pathname===""&&(t.pathname="/"),t}else return console.warn("Cannot get location for tracking in non-browser environment"),null},Kt=()=>typeof navigator=="object"&&navigator.userAgent||"",tt=()=>{const t=Kt(),e={Android(){return t.match(/Android/i)},BlackBerry(){return t.match(/BlackBerry/i)},iOS(){return t.match(/iPhone|iPod/i)},Opera(){return t.match(/Opera Mini/i)},Windows(){return t.match(/IEMobile/i)||t.match(/WPDesktop/i)},any(){return e.Android()||e.BlackBerry()||e.iOS()||e.Opera()||e.Windows()||y==="reactNative"}},n=t.match(/Tablet|iPad/i),r=Mt();return{urlPath:r==null?void 0:r.pathname,host:(r==null?void 0:r.host)||(r==null?void 0:r.hostname),device:n?"tablet":e.any()?"mobile":"desktop"}},_t=async({canTrack:t})=>{if(!t)return{visitorId:void 0,sessionId:void 0};const e=await Bt({canTrack:t}),n=Vt({canTrack:t});return{sessionId:e,visitorId:n}},jt=async({type:t,canTrack:e,apiKey:n,metadata:r,...s})=>({type:t,data:{...s,metadata:{url:location.href,...r},...await _t({canTrack:e}),userAttributes:tt(),ownerId:n}});async function et({apiHost:t,...e}){if(!e.apiKey){d.error("Missing API key for track call. Please provide your API key.");return}if(!e.canTrack||G()||!(c()||y==="reactNative"))return;const r=`${t||"https://cdn.builder.io"}/api/v1/track`;return q(r),fetch(r,{method:"POST",body:JSON.stringify({events:[await jt(e)]}),headers:{"content-type":"application/json",...H()},mode:"cors"}).catch(s=>{console.error("Failed to track: ",s)})}const Wt=t=>et({...t,canTrack:!0}),$t=["*.beta.builder.io","beta.builder.io","builder.io","localhost","qa.builder.io"];function nt(t,e){if(!e.origin.startsWith("http")&&!e.origin.startsWith("https"))return!1;const n=new URL(e.origin),r=n.hostname;return(t||$t).findIndex(s=>s.startsWith("*.")?r.endsWith(s.slice(1)):s===r)>-1}const Gt=()=>{J("insertMenu",{name:"_default",default:!0,items:[{name:"Box"},{name:"Text"},{name:"Image"},{name:"Columns"},{name:"Core:Section"},{name:"Core:Button"},{name:"Embed"},{name:"Custom Code"}]})};let K=!1;const rt=(t={})=>{var e,n;K||(K=!0,c()&&((e=window.parent)==null||e.postMessage({type:"builder.sdkInfo",data:{target:y,version:z,supportsPatchUpdates:!1,supportsAddBlockScoping:!0,supportsCustomBreakpoints:!0,blockLevelPersonalization:!0}},"*"),(n=window.parent)==null||n.postMessage({type:"builder.updateContent",data:{options:t}},"*"),window.addEventListener("message",r=>{var o,i;if(!nt(t.trustedHosts,r))return;const{data:s}=r;if(s!=null&&s.type)switch(s.type){case"builder.evaluate":{const u=s.data.text,S=s.data.arguments||[],m=s.data.id,I=new Function(u);let l,g=null;try{l=I.apply(null,S)}catch(h){g=h}g?(o=window.parent)==null||o.postMessage({type:"builder.evaluateError",data:{id:m,error:g.message}},"*"):l&&typeof l.then=="function"?l.then(h=>{var w;(w=window.parent)==null||w.postMessage({type:"builder.evaluateResult",data:{id:m,result:h}},"*")}).catch(console.error):(i=window.parent)==null||i.postMessage({type:"builder.evaluateResult",data:{result:l,id:m}},"*");break}}})))},st=({model:t,trustedHosts:e,callbacks:n})=>r=>{if(!nt(e,r))return;const{data:s}=r;if(s)switch(s.type){case"builder.configureSdk":{n.configureSdk(s.data);break}case"builder.triggerAnimation":{n.animation(s.data);break}case"builder.contentUpdate":{const o=s.data,i=o.key||o.alias||o.entry||o.modelName,u=o.data;i===t&&n.contentUpdate(u);break}}},Jt=(t,e,n)=>{if(!c)return d.warn("`subscribeToEditor` only works in the browser. It currently seems to be running on the server."),()=>{};rt();const r=st({callbacks:{contentUpdate:e,animation:()=>{},configureSdk:()=>{}},model:t,trustedHosts:n==null?void 0:n.trustedHosts});return window.addEventListener("message",r),()=>{window.removeEventListener("message",r)}},zt="builder.tests",B=t=>`${zt}.${t}`,Ht=({contentId:t})=>j({name:B(t),canTrack:!0}),Xt=({contentId:t})=>O({name:B(t),canTrack:!0}),Qt=({contentId:t,value:e})=>C({name:B(t),value:e,canTrack:!0}),ot=t=>p(t.id)&&p(t.variations)&&Object.keys(t.variations).length>0,Yt=({id:t,variations:e})=>{var s;let n=0;const r=Math.random();for(const o in e){const i=(s=e[o])==null?void 0:s.testRatio;if(n+=i,r<n)return o}return t},it=t=>{const e=Yt(t);return Qt({contentId:t.id,value:e}).catch(n=>{d.error("could not store A/B test variation: ",n)}),e},at=({item:t,testGroupId:e})=>{const n=t.variations[e];return e===t.id||!n?{testVariationId:t.id,testVariationName:"Default"}:{data:n.data,testVariationId:n.id,testVariationName:n.name||(n.id===t.id?"Default":"")}},Zt=({item:t,canTrack:e})=>{if(!e)return t;if(!t)return;if(!ot(t))return t;const n=Xt({contentId:t.id})||it({variations:t.variations,id:t.id}),r=at({item:t,testGroupId:n});return{...t,...r}},qt=async({item:t,canTrack:e})=>{if(!e||!ot(t))return t;const r=await Ht({contentId:t.id})||it({variations:t.variations,id:t.id}),s=at({item:t,testGroupId:r});return{...t,...s}},ct=t=>{const e=p(t)?t:!0;return P.setCanTrack(e),e};function te(){return typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:globalThis}function ee(){const t=te().fetch;if(typeof t=="undefined")throw console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
2
|
+
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`),new Error("Builder SDK could not find a global `fetch` function");return t}const ne=ee();function A(t,e=null,n="."){return Object.keys(t).reduce((r,s)=>{const o=t[s],i=[e,s].filter(Boolean).join(n);return[typeof o=="object",o!==null,!(Array.isArray(o)&&o.length===0)].every(Boolean)?{...r,...A(o,i,n)}:{...r,[i]:o}},{})}function ut(t,e,n={}){for(const r in t){const s=t[r],o=e?e+"."+r:r;s&&typeof s=="object"&&!Array.isArray(s)&&!Object.keys(s).find(i=>i.startsWith("$"))?ut(s,o,n):n[o]=s}return n}function re(t){const e={};for(const n in t){const r=n.split(".");let s=e;for(let o=0;o<r.length;o++){const i=r[o];o===r.length-1?s[i]=t[n]:(s[i]=s[i]||{},s=s[i])}}return e}const se="v3",_=t=>typeof t=="number"&&!isNaN(t)&&t>=0,x=t=>{const{limit:e=30,userAttributes:n,query:r,model:s,apiKey:o,enrich:i,locale:u,apiVersion:S=se,fields:m,omit:I,offset:l,cacheSeconds:g,staleCacheSeconds:h,sort:w,includeUnpublished:R,apiHost:gt}=t;if(!o)throw new Error("Missing API key");if(!["v3"].includes(S))throw new Error(`Invalid apiVersion: expected 'v3', received '${S}'`);const ht=e!==1,pt=gt||"https://cdn.builder.io",a=new URL(`${pt}/api/${S}/content/${s}`);a.searchParams.set("apiKey",o),a.searchParams.set("limit",String(e)),a.searchParams.set("noTraverse",String(ht)),a.searchParams.set("includeRefs",String(!0));const k=u||(n==null?void 0:n.locale);let b=n||{};if(k&&(a.searchParams.set("locale",k),b={locale:k,...b}),i&&a.searchParams.set("enrich",String(i)),a.searchParams.set("omit",I||"meta.componentsUsed"),m&&a.searchParams.set("fields",m),Number.isFinite(l)&&l>-1&&a.searchParams.set("offset",String(Math.floor(l))),typeof R=="boolean"&&a.searchParams.set("includeUnpublished",String(R)),g&&_(g)&&a.searchParams.set("cacheSeconds",String(g)),h&&_(h)&&a.searchParams.set("staleCacheSeconds",String(h)),w){const f=A({sort:w});for(const v in f)a.searchParams.set(v,JSON.stringify(f[v]))}const L={...Tt(),...W(t.options||{})};b={...b,...ie(L)};const F=A(L);for(const f in F)a.searchParams.set(f,String(F[f]));if(Object.keys(b).length>0&&a.searchParams.set("userAttributes",JSON.stringify(b)),r){const f=ut({query:r});for(const v in f)a.searchParams.set(v,JSON.stringify(f[v]))}return a},oe=t=>{const e={};for(const n in t)n.startsWith("userAttributes.")&&(e[n]=t[n],delete t[n]);return e},ie=t=>{if(c()&&t.preview==="BUILDER_STUDIO"){t["userAttributes.urlPath"]=window.location.pathname,t["userAttributes.host"]=window.location.host;const e=oe(t),{userAttributes:n}=re(e);return n}return{}},ae=t=>"results"in t;async function lt(t){const e=await ft({...t,limit:1});return e&&e[0]||null}const ce=async t=>{var i,u;const e=x(t),n=(i=t.fetch)!=null?i:ne,r={...t.fetchOptions,headers:{...(u=t.fetchOptions)==null?void 0:u.headers,...H()}};return await(await n(e.href,r)).json()},dt=async(t,e,n=x(t))=>{const r=ct(t.canTrack);if(n.search.includes("preview="),!r||!(c()||y==="reactNative"))return e.results;try{const s=[];for(const o of e.results)s.push(await qt({item:o,canTrack:r}));e.results=s}catch(s){d.error("Could not process A/B tests. ",s)}return e.results};async function ft(t){const e=x(t),n=await ce(t);if(!ae(n))throw d.error("Error fetching data. ",{url:e,content:n,options:t}),n;return dt(t,n)}const ue=async t=>{var r,s,o;const e=t.path||((r=t.url)==null?void 0:r.pathname)||((s=t.userAttributes)==null?void 0:s.urlPath),n={...t,apiKey:t.apiKey,model:t.model||"page",userAttributes:{...t.userAttributes,...e?{urlPath:e}:{}},options:U(t.searchParams||((o=t.url)==null?void 0:o.searchParams)||t.options)};return{apiKey:n.apiKey,model:n.model,content:await lt(n)}};exports.TARGET=y;exports._processContentResult=dt;exports._track=et;exports.checkIsDefined=p;exports.createEditorListener=st;exports.createRegisterComponentMessage=At;exports.fetchBuilderProps=ue;exports.fetchEntries=ft;exports.fetchOneEntry=lt;exports.getBuilderSearchParams=U;exports.getDefaultCanTrack=ct;exports.getUserAttributes=tt;exports.handleABTestingSync=Zt;exports.isBrowser=c;exports.isEditing=G;exports.isPreviewing=kt;exports.logFetch=q;exports.logger=d;exports.register=J;exports.registerInsertMenu=Gt;exports.serializeIncludingFunctions=T;exports.setClientUserAttributes=vt;exports.setEditorSettings=Ct;exports.setupBrowserForEditing=rt;exports.subscribeToEditor=Jt;exports.track=Wt;exports.userAttributesService=P;
|