@builder.io/sdk-solid 5.0.1 → 5.1.1
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/dev.js +409 -377
- package/lib/browser/dev.jsx +1097 -1065
- package/lib/browser/index.js +772 -740
- package/lib/browser/index.jsx +773 -741
- package/lib/edge/dev.js +409 -377
- package/lib/edge/dev.jsx +895 -863
- package/lib/edge/index.js +1170 -1138
- package/lib/edge/index.jsx +1172 -1140
- package/lib/node/dev.js +463 -433
- package/lib/node/dev.jsx +1007 -977
- package/lib/node/index.js +828 -798
- package/lib/node/index.jsx +829 -799
- package/package.json +1 -1
package/lib/node/index.js
CHANGED
|
@@ -215,145 +215,433 @@ var getUserAttributes = () => {
|
|
|
215
215
|
};
|
|
216
216
|
};
|
|
217
217
|
|
|
218
|
-
// src/
|
|
219
|
-
var
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
218
|
+
// src/constants/sdk-version.ts
|
|
219
|
+
var SDK_VERSION = "5.1.1";
|
|
220
|
+
|
|
221
|
+
// src/helpers/sdk-headers.ts
|
|
222
|
+
var getSdkHeaders = () => ({
|
|
223
|
+
"X-Builder-SDK": TARGET,
|
|
224
|
+
"X-Builder-SDK-GEN": "2",
|
|
225
|
+
"X-Builder-SDK-Version": SDK_VERSION
|
|
226
|
+
});
|
|
227
|
+
|
|
228
|
+
// src/helpers/nullable.ts
|
|
229
|
+
var checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
|
|
230
|
+
|
|
231
|
+
// src/helpers/url.ts
|
|
232
|
+
var getTopLevelDomain = (host) => {
|
|
233
|
+
if (host === "localhost" || host === "127.0.0.1") {
|
|
234
|
+
return host;
|
|
235
|
+
}
|
|
236
|
+
const parts = host.split(".");
|
|
237
|
+
if (parts.length > 2) {
|
|
238
|
+
return parts.slice(1).join(".");
|
|
239
|
+
}
|
|
240
|
+
return host;
|
|
241
|
+
};
|
|
242
|
+
|
|
243
|
+
// src/helpers/cookie.ts
|
|
244
|
+
var getCookieSync = ({
|
|
245
|
+
name,
|
|
246
|
+
canTrack
|
|
224
247
|
}) => {
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
248
|
+
try {
|
|
249
|
+
if (!canTrack) {
|
|
250
|
+
return void 0;
|
|
251
|
+
}
|
|
252
|
+
return document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))?.split("=")[1];
|
|
253
|
+
} catch (err) {
|
|
254
|
+
logger.warn("[COOKIE] GET error: ", err?.message || err);
|
|
255
|
+
return void 0;
|
|
256
|
+
}
|
|
233
257
|
};
|
|
234
|
-
var
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
isExpression = true
|
|
258
|
+
var getCookie = async (args) => getCookieSync(args);
|
|
259
|
+
var stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join("; ");
|
|
260
|
+
var SECURE_CONFIG = [["secure", ""], ["SameSite", "None"]];
|
|
261
|
+
var createCookieString = ({
|
|
262
|
+
name,
|
|
263
|
+
value,
|
|
264
|
+
expires
|
|
242
265
|
}) => {
|
|
243
|
-
const
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
);
|
|
247
|
-
const
|
|
248
|
-
return
|
|
266
|
+
const secure = isBrowser() ? location.protocol === "https:" : true;
|
|
267
|
+
const secureObj = secure ? SECURE_CONFIG : [[]];
|
|
268
|
+
const expiresObj = expires ? [["expires", expires.toUTCString()]] : [[]];
|
|
269
|
+
const cookieValue = [[name, value], ...expiresObj, ["path", "/"], ["domain", getTopLevelDomain(window.location.hostname)], ...secureObj];
|
|
270
|
+
const cookie = stringifyCookie(cookieValue);
|
|
271
|
+
return cookie;
|
|
249
272
|
};
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
}
|
|
260
|
-
const val = target[prop];
|
|
261
|
-
if (typeof val === "object" && val !== null) {
|
|
262
|
-
return flattenState({
|
|
263
|
-
rootState: val,
|
|
264
|
-
localState: void 0,
|
|
265
|
-
rootSetState: rootSetState ? (subState) => {
|
|
266
|
-
target[prop] = subState;
|
|
267
|
-
rootSetState(target);
|
|
268
|
-
} : void 0
|
|
269
|
-
});
|
|
270
|
-
}
|
|
271
|
-
return val;
|
|
272
|
-
},
|
|
273
|
-
set: (target, prop, value) => {
|
|
274
|
-
if (localState && prop in localState) {
|
|
275
|
-
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
276
|
-
}
|
|
277
|
-
target[prop] = value;
|
|
278
|
-
rootSetState?.(target);
|
|
279
|
-
return true;
|
|
273
|
+
var setCookie = async ({
|
|
274
|
+
name,
|
|
275
|
+
value,
|
|
276
|
+
expires,
|
|
277
|
+
canTrack
|
|
278
|
+
}) => {
|
|
279
|
+
try {
|
|
280
|
+
if (!canTrack) {
|
|
281
|
+
return;
|
|
280
282
|
}
|
|
283
|
+
const cookie = createCookieString({
|
|
284
|
+
name,
|
|
285
|
+
value,
|
|
286
|
+
expires
|
|
287
|
+
});
|
|
288
|
+
document.cookie = cookie;
|
|
289
|
+
} catch (err) {
|
|
290
|
+
logger.warn("[COOKIE] SET error: ", err?.message || err);
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
|
|
294
|
+
// src/helpers/uuid.ts
|
|
295
|
+
function uuidv4() {
|
|
296
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
297
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
298
|
+
return v.toString(16);
|
|
281
299
|
});
|
|
282
300
|
}
|
|
301
|
+
function uuid() {
|
|
302
|
+
return uuidv4().replace(/-/g, "");
|
|
303
|
+
}
|
|
283
304
|
|
|
284
|
-
// src/
|
|
285
|
-
var
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
context,
|
|
289
|
-
event,
|
|
290
|
-
localState,
|
|
291
|
-
rootSetState,
|
|
292
|
-
rootState
|
|
305
|
+
// src/helpers/sessionId.ts
|
|
306
|
+
var SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
|
|
307
|
+
var getSessionId = async ({
|
|
308
|
+
canTrack
|
|
293
309
|
}) => {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
localState,
|
|
301
|
-
rootSetState
|
|
302
|
-
})
|
|
310
|
+
if (!canTrack) {
|
|
311
|
+
return void 0;
|
|
312
|
+
}
|
|
313
|
+
const sessionId = await getCookie({
|
|
314
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
315
|
+
canTrack
|
|
303
316
|
});
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
return "react-native";
|
|
314
|
-
default:
|
|
315
|
-
return TARGET;
|
|
317
|
+
if (checkIsDefined(sessionId)) {
|
|
318
|
+
return sessionId;
|
|
319
|
+
} else {
|
|
320
|
+
const newSessionId = createSessionId();
|
|
321
|
+
setSessionId({
|
|
322
|
+
id: newSessionId,
|
|
323
|
+
canTrack
|
|
324
|
+
});
|
|
325
|
+
return newSessionId;
|
|
316
326
|
}
|
|
317
|
-
}
|
|
318
|
-
var
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
327
|
+
};
|
|
328
|
+
var createSessionId = () => uuid();
|
|
329
|
+
var setSessionId = ({
|
|
330
|
+
id,
|
|
331
|
+
canTrack
|
|
332
|
+
}) => setCookie({
|
|
333
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
334
|
+
value: id,
|
|
335
|
+
canTrack
|
|
336
|
+
});
|
|
322
337
|
|
|
323
|
-
// src/
|
|
324
|
-
var
|
|
325
|
-
|
|
326
|
-
|
|
338
|
+
// src/helpers/localStorage.ts
|
|
339
|
+
var getLocalStorage = () => isBrowser() && typeof localStorage !== "undefined" ? localStorage : void 0;
|
|
340
|
+
var getLocalStorageItem = ({
|
|
341
|
+
key,
|
|
342
|
+
canTrack
|
|
343
|
+
}) => {
|
|
344
|
+
try {
|
|
345
|
+
if (canTrack) {
|
|
346
|
+
return getLocalStorage()?.getItem(key);
|
|
347
|
+
}
|
|
348
|
+
return void 0;
|
|
349
|
+
} catch (err) {
|
|
350
|
+
return void 0;
|
|
327
351
|
}
|
|
328
|
-
const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
|
|
329
|
-
path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
|
|
330
|
-
return obj;
|
|
331
|
-
};
|
|
332
|
-
var noop = () => {
|
|
333
352
|
};
|
|
334
|
-
var
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
353
|
+
var setLocalStorageItem = ({
|
|
354
|
+
key,
|
|
355
|
+
canTrack,
|
|
356
|
+
value
|
|
357
|
+
}) => {
|
|
338
358
|
try {
|
|
339
|
-
|
|
340
|
-
|
|
359
|
+
if (canTrack) {
|
|
360
|
+
getLocalStorage()?.setItem(key, value);
|
|
361
|
+
}
|
|
362
|
+
} catch (err) {
|
|
341
363
|
}
|
|
342
|
-
}
|
|
364
|
+
};
|
|
343
365
|
|
|
344
|
-
// src/
|
|
345
|
-
var
|
|
346
|
-
var
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
return obj;
|
|
366
|
+
// src/helpers/visitorId.ts
|
|
367
|
+
var VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
|
|
368
|
+
var getVisitorId = ({
|
|
369
|
+
canTrack
|
|
370
|
+
}) => {
|
|
371
|
+
if (!canTrack) {
|
|
372
|
+
return void 0;
|
|
352
373
|
}
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
374
|
+
const visitorId = getLocalStorageItem({
|
|
375
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
376
|
+
canTrack
|
|
377
|
+
});
|
|
378
|
+
if (checkIsDefined(visitorId)) {
|
|
379
|
+
return visitorId;
|
|
380
|
+
} else {
|
|
381
|
+
const newVisitorId = createVisitorId();
|
|
382
|
+
setVisitorId({
|
|
383
|
+
id: newVisitorId,
|
|
384
|
+
canTrack
|
|
385
|
+
});
|
|
386
|
+
return newVisitorId;
|
|
387
|
+
}
|
|
388
|
+
};
|
|
389
|
+
var createVisitorId = () => uuid();
|
|
390
|
+
var setVisitorId = ({
|
|
391
|
+
id,
|
|
392
|
+
canTrack
|
|
393
|
+
}) => setLocalStorageItem({
|
|
394
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
395
|
+
value: id,
|
|
396
|
+
canTrack
|
|
397
|
+
});
|
|
398
|
+
|
|
399
|
+
// src/functions/log-fetch.ts
|
|
400
|
+
function logFetch(url) {
|
|
401
|
+
if (typeof process !== "undefined" && process.env?.DEBUG) {
|
|
402
|
+
if (String(process.env.DEBUG) == "true") {
|
|
403
|
+
logger.log(url);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
|
|
408
|
+
// src/functions/track/index.ts
|
|
409
|
+
var getTrackingEventData = async ({
|
|
410
|
+
canTrack
|
|
411
|
+
}) => {
|
|
412
|
+
if (!canTrack) {
|
|
413
|
+
return {
|
|
414
|
+
visitorId: void 0,
|
|
415
|
+
sessionId: void 0
|
|
416
|
+
};
|
|
417
|
+
}
|
|
418
|
+
const sessionId = await getSessionId({
|
|
419
|
+
canTrack
|
|
420
|
+
});
|
|
421
|
+
const visitorId = getVisitorId({
|
|
422
|
+
canTrack
|
|
423
|
+
});
|
|
424
|
+
return {
|
|
425
|
+
sessionId,
|
|
426
|
+
visitorId
|
|
427
|
+
};
|
|
428
|
+
};
|
|
429
|
+
var createEvent = async ({
|
|
430
|
+
type: eventType,
|
|
431
|
+
canTrack,
|
|
432
|
+
apiKey,
|
|
433
|
+
metadata,
|
|
434
|
+
...properties
|
|
435
|
+
}) => ({
|
|
436
|
+
type: eventType,
|
|
437
|
+
data: {
|
|
438
|
+
...properties,
|
|
439
|
+
metadata: {
|
|
440
|
+
url: location.href,
|
|
441
|
+
...metadata
|
|
442
|
+
},
|
|
443
|
+
...await getTrackingEventData({
|
|
444
|
+
canTrack
|
|
445
|
+
}),
|
|
446
|
+
userAttributes: getUserAttributes(),
|
|
447
|
+
ownerId: apiKey
|
|
448
|
+
}
|
|
449
|
+
});
|
|
450
|
+
async function _track({
|
|
451
|
+
apiHost,
|
|
452
|
+
...eventProps
|
|
453
|
+
}) {
|
|
454
|
+
if (!eventProps.apiKey) {
|
|
455
|
+
logger.error("Missing API key for track call. Please provide your API key.");
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
if (!eventProps.canTrack) {
|
|
459
|
+
return;
|
|
460
|
+
}
|
|
461
|
+
if (isEditing()) {
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
if (!(isBrowser() || TARGET === "reactNative")) {
|
|
465
|
+
return;
|
|
466
|
+
}
|
|
467
|
+
const baseUrl = apiHost || "https://cdn.builder.io";
|
|
468
|
+
const url = `${baseUrl}/api/v1/track`;
|
|
469
|
+
logFetch(url);
|
|
470
|
+
return fetch(url, {
|
|
471
|
+
method: "POST",
|
|
472
|
+
body: JSON.stringify({
|
|
473
|
+
events: [await createEvent(eventProps)]
|
|
474
|
+
}),
|
|
475
|
+
headers: {
|
|
476
|
+
"content-type": "application/json",
|
|
477
|
+
...getSdkHeaders()
|
|
478
|
+
},
|
|
479
|
+
mode: "cors"
|
|
480
|
+
}).catch((err) => {
|
|
481
|
+
});
|
|
482
|
+
}
|
|
483
|
+
var track = (args) => _track({
|
|
484
|
+
...args,
|
|
485
|
+
canTrack: true
|
|
486
|
+
});
|
|
487
|
+
|
|
488
|
+
// src/functions/evaluate/helpers.ts
|
|
489
|
+
var getFunctionArguments = ({
|
|
490
|
+
builder,
|
|
491
|
+
context,
|
|
492
|
+
event,
|
|
493
|
+
state
|
|
494
|
+
}) => {
|
|
495
|
+
return Object.entries({
|
|
496
|
+
state,
|
|
497
|
+
Builder: builder,
|
|
498
|
+
// legacy
|
|
499
|
+
builder,
|
|
500
|
+
context,
|
|
501
|
+
event
|
|
502
|
+
});
|
|
503
|
+
};
|
|
504
|
+
var getBuilderGlobals = (trackingContext) => ({
|
|
505
|
+
isEditing: isEditing(),
|
|
506
|
+
isBrowser: isBrowser(),
|
|
507
|
+
isServer: !isBrowser(),
|
|
508
|
+
getUserAttributes: () => getUserAttributes(),
|
|
509
|
+
trackConversion: (amount, customProperties) => {
|
|
510
|
+
if (!trackingContext?.apiKey || trackingContext?.canTrack === false) {
|
|
511
|
+
return;
|
|
512
|
+
}
|
|
513
|
+
_track({
|
|
514
|
+
type: "conversion",
|
|
515
|
+
apiKey: trackingContext.apiKey,
|
|
516
|
+
canTrack: trackingContext.canTrack ?? true,
|
|
517
|
+
contentId: trackingContext.contentId,
|
|
518
|
+
variationId: trackingContext.variationId !== trackingContext.contentId ? trackingContext.variationId : void 0,
|
|
519
|
+
metadata: {
|
|
520
|
+
...customProperties || {},
|
|
521
|
+
...amount !== void 0 ? {
|
|
522
|
+
amount
|
|
523
|
+
} : {}
|
|
524
|
+
}
|
|
525
|
+
});
|
|
526
|
+
}
|
|
527
|
+
});
|
|
528
|
+
var parseCode = (code, {
|
|
529
|
+
isExpression = true
|
|
530
|
+
}) => {
|
|
531
|
+
const useReturn = (
|
|
532
|
+
// we disable this for cases where we definitely don't want a return
|
|
533
|
+
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
534
|
+
);
|
|
535
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
536
|
+
return useCode;
|
|
537
|
+
};
|
|
538
|
+
function flattenState({
|
|
539
|
+
rootState,
|
|
540
|
+
localState,
|
|
541
|
+
rootSetState
|
|
542
|
+
}) {
|
|
543
|
+
return new Proxy(rootState, {
|
|
544
|
+
get: (target, prop) => {
|
|
545
|
+
if (localState && prop in localState) {
|
|
546
|
+
return localState[prop];
|
|
547
|
+
}
|
|
548
|
+
const val = target[prop];
|
|
549
|
+
if (typeof val === "object" && val !== null) {
|
|
550
|
+
return flattenState({
|
|
551
|
+
rootState: val,
|
|
552
|
+
localState: void 0,
|
|
553
|
+
rootSetState: rootSetState ? (subState) => {
|
|
554
|
+
target[prop] = subState;
|
|
555
|
+
rootSetState(target);
|
|
556
|
+
} : void 0
|
|
557
|
+
});
|
|
558
|
+
}
|
|
559
|
+
return val;
|
|
560
|
+
},
|
|
561
|
+
set: (target, prop, value) => {
|
|
562
|
+
if (localState && prop in localState) {
|
|
563
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
564
|
+
}
|
|
565
|
+
target[prop] = value;
|
|
566
|
+
rootSetState?.(target);
|
|
567
|
+
return true;
|
|
568
|
+
}
|
|
569
|
+
});
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
// src/functions/evaluate/browser-runtime/browser.ts
|
|
573
|
+
var runInBrowser = ({
|
|
574
|
+
code,
|
|
575
|
+
builder,
|
|
576
|
+
context,
|
|
577
|
+
event,
|
|
578
|
+
localState,
|
|
579
|
+
rootSetState,
|
|
580
|
+
rootState
|
|
581
|
+
}) => {
|
|
582
|
+
const functionArgs = getFunctionArguments({
|
|
583
|
+
builder,
|
|
584
|
+
context,
|
|
585
|
+
event,
|
|
586
|
+
state: flattenState({
|
|
587
|
+
rootState,
|
|
588
|
+
localState,
|
|
589
|
+
rootSetState
|
|
590
|
+
})
|
|
591
|
+
});
|
|
592
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
593
|
+
};
|
|
594
|
+
|
|
595
|
+
// src/constants/sdk-name.ts
|
|
596
|
+
var SDK_NAME_FOR_TARGET = (() => {
|
|
597
|
+
switch (TARGET) {
|
|
598
|
+
case "rsc":
|
|
599
|
+
return "react-nextjs";
|
|
600
|
+
case "reactNative":
|
|
601
|
+
return "react-native";
|
|
602
|
+
default:
|
|
603
|
+
return TARGET;
|
|
604
|
+
}
|
|
605
|
+
})();
|
|
606
|
+
var SDK_NAME = `@builder.io/sdk-${SDK_NAME_FOR_TARGET}`;
|
|
607
|
+
|
|
608
|
+
// src/functions/fast-clone.ts
|
|
609
|
+
var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
610
|
+
|
|
611
|
+
// src/functions/set.ts
|
|
612
|
+
var set = (obj, _path, value) => {
|
|
613
|
+
if (Object(obj) !== obj) {
|
|
614
|
+
return obj;
|
|
615
|
+
}
|
|
616
|
+
const path = Array.isArray(_path) ? _path : _path.toString().match(/[^.[\]]+/g);
|
|
617
|
+
path.slice(0, -1).reduce((a, c, i) => Object(a[c]) === a[c] ? a[c] : a[c] = Math.abs(Number(path[i + 1])) >> 0 === +path[i + 1] ? [] : {}, obj)[path[path.length - 1]] = value;
|
|
618
|
+
return obj;
|
|
619
|
+
};
|
|
620
|
+
var noop = () => {
|
|
621
|
+
};
|
|
622
|
+
var safeDynamicRequire = noop;
|
|
623
|
+
try {
|
|
624
|
+
safeDynamicRequire = createRequire(import.meta.url);
|
|
625
|
+
} catch (error) {
|
|
626
|
+
try {
|
|
627
|
+
safeDynamicRequire = eval("require");
|
|
628
|
+
} catch (error2) {
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// src/functions/evaluate/node-runtime/node-runtime.ts
|
|
633
|
+
var getSyncValName = (key) => `bldr_${key}_sync`;
|
|
634
|
+
var BUILDER_SET_STATE_NAME = "BUILDER_SET_STATE";
|
|
635
|
+
var INJECTED_IVM_GLOBAL = "BUILDER_IVM";
|
|
636
|
+
var REF_TO_PROXY_FN = `
|
|
637
|
+
var refToProxy = (obj) => {
|
|
638
|
+
if (typeof obj !== 'object' || obj === null) {
|
|
639
|
+
return obj;
|
|
640
|
+
}
|
|
641
|
+
return new Proxy({}, {
|
|
642
|
+
get(target, key) {
|
|
643
|
+
if (key === 'copySync') {
|
|
644
|
+
return () => obj.copySync();
|
|
357
645
|
}
|
|
358
646
|
const val = obj.getSync(key);
|
|
359
647
|
if (typeof val?.getSync === 'function') {
|
|
@@ -394,7 +682,9 @@ if (typeof output === 'object' && output !== null) {
|
|
|
394
682
|
`;
|
|
395
683
|
};
|
|
396
684
|
var IVM_INSTANCE = null;
|
|
397
|
-
var
|
|
685
|
+
var IVM_OPTIONS = {
|
|
686
|
+
memoryLimit: 128
|
|
687
|
+
};
|
|
398
688
|
var SHOULD_MENTION_INITIALIZE_SCRIPT = SDK_NAME === "@builder.io/sdk-react-nextjs" || SDK_NAME === "@builder.io/sdk-react" || SDK_NAME === "@builder.io/sdk-qwik" || SDK_NAME === "@builder.io/sdk-vue";
|
|
399
689
|
var getIvm = () => {
|
|
400
690
|
try {
|
|
@@ -416,25 +706,6 @@ var getIvm = () => {
|
|
|
416
706
|
For more information, visit https://builder.io/c/docs/integration-tips#enabling-data-bindings-in-node-environments`;
|
|
417
707
|
throw new Error(ERROR_MESSAGE);
|
|
418
708
|
};
|
|
419
|
-
function setIsolateContext(options = {
|
|
420
|
-
memoryLimit: 128
|
|
421
|
-
}) {
|
|
422
|
-
if (IVM_CONTEXT)
|
|
423
|
-
return IVM_CONTEXT;
|
|
424
|
-
const ivm = getIvm();
|
|
425
|
-
const isolate = new ivm.Isolate(options);
|
|
426
|
-
const context = isolate.createContextSync();
|
|
427
|
-
const jail = context.global;
|
|
428
|
-
jail.setSync("global", jail.derefInto());
|
|
429
|
-
jail.setSync("log", function(...logArgs) {
|
|
430
|
-
});
|
|
431
|
-
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
432
|
-
IVM_CONTEXT = context;
|
|
433
|
-
return context;
|
|
434
|
-
}
|
|
435
|
-
var getIsolateContext = () => {
|
|
436
|
-
return setIsolateContext();
|
|
437
|
-
};
|
|
438
709
|
var runInNode = ({
|
|
439
710
|
code,
|
|
440
711
|
builder,
|
|
@@ -445,48 +716,60 @@ var runInNode = ({
|
|
|
445
716
|
rootState
|
|
446
717
|
}) => {
|
|
447
718
|
const ivm = getIvm();
|
|
448
|
-
|
|
449
|
-
...rootState,
|
|
450
|
-
...localState
|
|
451
|
-
});
|
|
452
|
-
const args = getFunctionArguments({
|
|
453
|
-
builder,
|
|
454
|
-
context,
|
|
455
|
-
event,
|
|
456
|
-
state
|
|
457
|
-
});
|
|
458
|
-
const isolateContext = getIsolateContext();
|
|
459
|
-
const jail = isolateContext.global;
|
|
460
|
-
jail.setSync(BUILDER_SET_STATE_NAME, function(key, value) {
|
|
461
|
-
set(rootState, key, value);
|
|
462
|
-
rootSetState?.(rootState);
|
|
463
|
-
});
|
|
464
|
-
args.forEach(([key, arg]) => {
|
|
465
|
-
const val = typeof arg === "object" ? new ivm.Reference(
|
|
466
|
-
// workaround: methods with default values for arguments is not being cloned over
|
|
467
|
-
key === "builder" ? {
|
|
468
|
-
...arg,
|
|
469
|
-
getUserAttributes: () => arg.getUserAttributes()
|
|
470
|
-
} : arg
|
|
471
|
-
) : null;
|
|
472
|
-
jail.setSync(getSyncValName(key), val);
|
|
473
|
-
});
|
|
474
|
-
const evalStr = processCode({
|
|
475
|
-
code,
|
|
476
|
-
args
|
|
477
|
-
});
|
|
478
|
-
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
719
|
+
let isolate;
|
|
479
720
|
try {
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
721
|
+
isolate = new ivm.Isolate(IVM_OPTIONS);
|
|
722
|
+
const isolateContext = isolate.createContextSync();
|
|
723
|
+
const jail = isolateContext.global;
|
|
724
|
+
jail.setSync("global", jail.derefInto());
|
|
725
|
+
jail.setSync("log", function(...logArgs) {
|
|
726
|
+
});
|
|
727
|
+
jail.setSync(INJECTED_IVM_GLOBAL, ivm);
|
|
728
|
+
const state = fastClone({
|
|
729
|
+
...rootState,
|
|
730
|
+
...localState
|
|
731
|
+
});
|
|
732
|
+
const args = getFunctionArguments({
|
|
733
|
+
builder,
|
|
734
|
+
context,
|
|
735
|
+
event,
|
|
736
|
+
state
|
|
737
|
+
});
|
|
738
|
+
jail.setSync(BUILDER_SET_STATE_NAME, function(key, value) {
|
|
739
|
+
set(rootState, key, value);
|
|
740
|
+
rootSetState?.(rootState);
|
|
741
|
+
});
|
|
742
|
+
args.forEach(([key, arg]) => {
|
|
743
|
+
const val = typeof arg === "object" ? new ivm.Reference(
|
|
744
|
+
// workaround: methods with default values for arguments is not being cloned over
|
|
745
|
+
key === "builder" ? {
|
|
746
|
+
...arg,
|
|
747
|
+
getUserAttributes: () => arg.getUserAttributes()
|
|
748
|
+
} : arg
|
|
749
|
+
) : null;
|
|
750
|
+
jail.setSync(getSyncValName(key), val);
|
|
751
|
+
});
|
|
752
|
+
const evalStr = processCode({
|
|
753
|
+
code,
|
|
754
|
+
args
|
|
755
|
+
});
|
|
756
|
+
const resultStr = isolateContext.evalClosureSync(evalStr);
|
|
757
|
+
try {
|
|
758
|
+
const res = JSON.parse(resultStr);
|
|
759
|
+
return res;
|
|
760
|
+
} catch (_error) {
|
|
761
|
+
return resultStr;
|
|
762
|
+
}
|
|
763
|
+
} finally {
|
|
764
|
+
if (isolate) {
|
|
765
|
+
try {
|
|
766
|
+
isolate.dispose();
|
|
767
|
+
} catch (e) {
|
|
768
|
+
}
|
|
769
|
+
}
|
|
484
770
|
}
|
|
485
771
|
};
|
|
486
772
|
|
|
487
|
-
// src/helpers/nullable.ts
|
|
488
|
-
var checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
|
|
489
|
-
|
|
490
773
|
// src/functions/is-node-runtime.ts
|
|
491
774
|
function isNodeRuntime() {
|
|
492
775
|
return typeof process !== "undefined" && checkIsDefined(process?.versions?.node);
|
|
@@ -531,7 +814,8 @@ function evaluate({
|
|
|
531
814
|
rootState,
|
|
532
815
|
rootSetState,
|
|
533
816
|
event,
|
|
534
|
-
isExpression = true
|
|
817
|
+
isExpression = true,
|
|
818
|
+
trackingContext
|
|
535
819
|
}) {
|
|
536
820
|
if (code.trim() === "") {
|
|
537
821
|
return void 0;
|
|
@@ -547,7 +831,7 @@ function evaluate({
|
|
|
547
831
|
code: parseCode(code, {
|
|
548
832
|
isExpression
|
|
549
833
|
}),
|
|
550
|
-
builder: getBuilderGlobals(),
|
|
834
|
+
builder: getBuilderGlobals(trackingContext),
|
|
551
835
|
context,
|
|
552
836
|
event,
|
|
553
837
|
rootSetState,
|
|
@@ -927,660 +1211,400 @@ function bindScrollInViewAnimation(animation) {
|
|
|
927
1211
|
assign(element.style, defaultState);
|
|
928
1212
|
}
|
|
929
1213
|
attachDefaultState();
|
|
930
|
-
setTimeout(() => {
|
|
931
|
-
element.style.transition = `all ${animation.duration}s ${camelToKebabCase(animation.easing)}`;
|
|
932
|
-
if (animation.delay) {
|
|
933
|
-
element.style.transitionDelay = animation.delay + "s";
|
|
934
|
-
}
|
|
935
|
-
});
|
|
936
|
-
document.addEventListener("scroll", onScroll, {
|
|
937
|
-
capture: true,
|
|
938
|
-
passive: true
|
|
939
|
-
});
|
|
940
|
-
immediateOnScroll();
|
|
941
|
-
});
|
|
942
|
-
}
|
|
943
|
-
|
|
944
|
-
// src/helpers/css.ts
|
|
945
|
-
var convertStyleMapToCSSArray = (style) => {
|
|
946
|
-
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
947
|
-
if (typeof value === "string") {
|
|
948
|
-
return `${camelToKebabCase(key)}: ${value};`;
|
|
949
|
-
} else {
|
|
950
|
-
return void 0;
|
|
951
|
-
}
|
|
952
|
-
});
|
|
953
|
-
return cssProps.filter(checkIsDefined);
|
|
954
|
-
};
|
|
955
|
-
var convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
|
|
956
|
-
var createCssClass = ({
|
|
957
|
-
mediaQuery,
|
|
958
|
-
className,
|
|
959
|
-
styles
|
|
960
|
-
}) => {
|
|
961
|
-
const cssClass = `.${className} {
|
|
962
|
-
${convertStyleMapToCSS(styles)}
|
|
963
|
-
}`;
|
|
964
|
-
if (mediaQuery) {
|
|
965
|
-
return `${mediaQuery} {
|
|
966
|
-
${cssClass}
|
|
967
|
-
}`;
|
|
968
|
-
} else {
|
|
969
|
-
return cssClass;
|
|
970
|
-
}
|
|
971
|
-
};
|
|
972
|
-
|
|
973
|
-
// src/functions/transform-style-property.ts
|
|
974
|
-
function transformStyleProperty({
|
|
975
|
-
style
|
|
976
|
-
}) {
|
|
977
|
-
return style;
|
|
978
|
-
}
|
|
979
|
-
|
|
980
|
-
// src/functions/get-style.ts
|
|
981
|
-
var getStyle = ({
|
|
982
|
-
block,
|
|
983
|
-
context
|
|
984
|
-
}) => {
|
|
985
|
-
return mapStyleObjToStrIfNeeded(transformStyleProperty({
|
|
986
|
-
style: block.style || {},
|
|
987
|
-
context,
|
|
988
|
-
block
|
|
989
|
-
}));
|
|
990
|
-
};
|
|
991
|
-
function mapStyleObjToStrIfNeeded(style) {
|
|
992
|
-
switch (TARGET) {
|
|
993
|
-
case "svelte":
|
|
994
|
-
case "vue":
|
|
995
|
-
case "solid":
|
|
996
|
-
case "angular":
|
|
997
|
-
return convertStyleMapToCSSArray(style).join(" ");
|
|
998
|
-
case "qwik":
|
|
999
|
-
case "reactNative":
|
|
1000
|
-
case "react":
|
|
1001
|
-
case "rsc":
|
|
1002
|
-
return style;
|
|
1003
|
-
}
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
// src/components/block/block.helpers.ts
|
|
1007
|
-
var checkIsComponentRestricted = (component, model) => {
|
|
1008
|
-
if (!component)
|
|
1009
|
-
return true;
|
|
1010
|
-
if (!model)
|
|
1011
|
-
return false;
|
|
1012
|
-
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
1013
|
-
};
|
|
1014
|
-
var getComponent = ({
|
|
1015
|
-
block,
|
|
1016
|
-
registeredComponents,
|
|
1017
|
-
model
|
|
1018
|
-
}) => {
|
|
1019
|
-
const componentName = block.component?.name;
|
|
1020
|
-
if (!componentName) {
|
|
1021
|
-
return null;
|
|
1022
|
-
}
|
|
1023
|
-
const ref = registeredComponents[componentName];
|
|
1024
|
-
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
1025
|
-
return void 0;
|
|
1026
|
-
} else {
|
|
1027
|
-
return ref;
|
|
1028
|
-
}
|
|
1029
|
-
};
|
|
1030
|
-
var getRepeatItemData = ({
|
|
1031
|
-
block,
|
|
1032
|
-
context
|
|
1033
|
-
}) => {
|
|
1034
|
-
const {
|
|
1035
|
-
repeat,
|
|
1036
|
-
...blockWithoutRepeat
|
|
1037
|
-
} = block;
|
|
1038
|
-
if (!repeat?.collection) {
|
|
1039
|
-
return void 0;
|
|
1040
|
-
}
|
|
1041
|
-
const itemsArray = evaluate({
|
|
1042
|
-
code: repeat.collection,
|
|
1043
|
-
localState: context.localState,
|
|
1044
|
-
rootState: context.rootState,
|
|
1045
|
-
rootSetState: context.rootSetState,
|
|
1046
|
-
context: context.context
|
|
1047
|
-
});
|
|
1048
|
-
if (!Array.isArray(itemsArray)) {
|
|
1049
|
-
return void 0;
|
|
1050
|
-
}
|
|
1051
|
-
const collectionName = repeat.collection.split(".").pop();
|
|
1052
|
-
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
1053
|
-
const repeatArray = itemsArray.map((item, index) => ({
|
|
1054
|
-
context: {
|
|
1055
|
-
...context,
|
|
1056
|
-
localState: {
|
|
1057
|
-
...context.localState,
|
|
1058
|
-
$index: index,
|
|
1059
|
-
$item: item,
|
|
1060
|
-
[itemNameToUse]: item,
|
|
1061
|
-
[`$${itemNameToUse}Index`]: index
|
|
1062
|
-
}
|
|
1063
|
-
},
|
|
1064
|
-
block: blockWithoutRepeat
|
|
1065
|
-
}));
|
|
1066
|
-
return repeatArray;
|
|
1067
|
-
};
|
|
1068
|
-
var provideLinkComponent = (block, linkComponent) => {
|
|
1069
|
-
if (block?.shouldReceiveBuilderProps?.builderLinkComponent)
|
|
1070
|
-
return {
|
|
1071
|
-
builderLinkComponent: linkComponent
|
|
1072
|
-
};
|
|
1073
|
-
return {};
|
|
1074
|
-
};
|
|
1075
|
-
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
1076
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
1077
|
-
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
1078
|
-
return !checkIsComponentRestricted(component, model);
|
|
1079
|
-
}));
|
|
1080
|
-
return {
|
|
1081
|
-
builderComponents: filteredRegisteredComponents
|
|
1082
|
-
};
|
|
1083
|
-
}
|
|
1084
|
-
return {};
|
|
1085
|
-
};
|
|
1086
|
-
var provideBuilderBlock = (block, builderBlock) => {
|
|
1087
|
-
if (block?.shouldReceiveBuilderProps?.builderBlock)
|
|
1088
|
-
return {
|
|
1089
|
-
builderBlock
|
|
1090
|
-
};
|
|
1091
|
-
return {};
|
|
1092
|
-
};
|
|
1093
|
-
var provideBuilderContext = (block, context) => {
|
|
1094
|
-
if (block?.shouldReceiveBuilderProps?.builderContext)
|
|
1095
|
-
return {
|
|
1096
|
-
builderContext: context
|
|
1097
|
-
};
|
|
1098
|
-
return {};
|
|
1099
|
-
};
|
|
1100
|
-
var generateKey = (index) => {
|
|
1101
|
-
return index.toString();
|
|
1102
|
-
};
|
|
1103
|
-
|
|
1104
|
-
// src/functions/event-handler-name.ts
|
|
1105
|
-
function capitalizeFirstLetter(string) {
|
|
1106
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1107
|
-
}
|
|
1108
|
-
var getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
|
|
1109
|
-
|
|
1110
|
-
// src/functions/get-block-actions-handler.ts
|
|
1111
|
-
var createEventHandler = (value, options) => (event) => evaluate({
|
|
1112
|
-
code: value,
|
|
1113
|
-
context: options.context,
|
|
1114
|
-
localState: options.localState,
|
|
1115
|
-
rootState: options.rootState,
|
|
1116
|
-
rootSetState: options.rootSetState,
|
|
1117
|
-
event,
|
|
1118
|
-
isExpression: false
|
|
1119
|
-
});
|
|
1120
|
-
|
|
1121
|
-
// src/functions/get-block-actions.ts
|
|
1122
|
-
function getBlockActions(options) {
|
|
1123
|
-
const obj = {};
|
|
1124
|
-
const optionActions = options.block.actions ?? {};
|
|
1125
|
-
for (const key in optionActions) {
|
|
1126
|
-
if (!optionActions.hasOwnProperty(key)) {
|
|
1127
|
-
continue;
|
|
1128
|
-
}
|
|
1129
|
-
const value = optionActions[key];
|
|
1130
|
-
let eventHandlerName = getEventHandlerName(key);
|
|
1131
|
-
if (options.stripPrefix) {
|
|
1132
|
-
switch (TARGET) {
|
|
1133
|
-
case "vue":
|
|
1134
|
-
eventHandlerName = eventHandlerName.replace("v-on:", "");
|
|
1135
|
-
break;
|
|
1136
|
-
case "svelte":
|
|
1137
|
-
eventHandlerName = eventHandlerName.replace("on:", "");
|
|
1138
|
-
break;
|
|
1139
|
-
}
|
|
1140
|
-
}
|
|
1141
|
-
obj[eventHandlerName] = createEventHandler(value, options);
|
|
1142
|
-
}
|
|
1143
|
-
return obj;
|
|
1144
|
-
}
|
|
1145
|
-
|
|
1146
|
-
// src/functions/transform-block-properties.ts
|
|
1147
|
-
function transformBlockProperties({
|
|
1148
|
-
properties
|
|
1149
|
-
}) {
|
|
1150
|
-
return properties;
|
|
1151
|
-
}
|
|
1152
|
-
|
|
1153
|
-
// src/functions/get-block-properties.ts
|
|
1154
|
-
var extractRelevantRootBlockProperties = (block) => {
|
|
1155
|
-
return {
|
|
1156
|
-
href: block.href
|
|
1157
|
-
};
|
|
1158
|
-
};
|
|
1159
|
-
function getBlockProperties({
|
|
1160
|
-
block,
|
|
1161
|
-
context
|
|
1162
|
-
}) {
|
|
1163
|
-
const properties = {
|
|
1164
|
-
...extractRelevantRootBlockProperties(block),
|
|
1165
|
-
...block.properties,
|
|
1166
|
-
"builder-id": block.id,
|
|
1167
|
-
style: getStyle({
|
|
1168
|
-
block,
|
|
1169
|
-
context
|
|
1170
|
-
}),
|
|
1171
|
-
[getClassPropName()]: [block.id, "builder-block", block.class, block.properties?.class].filter(Boolean).join(" ")
|
|
1172
|
-
};
|
|
1173
|
-
return transformBlockProperties({
|
|
1174
|
-
properties,
|
|
1175
|
-
context,
|
|
1176
|
-
block
|
|
1177
|
-
});
|
|
1178
|
-
}
|
|
1179
|
-
|
|
1180
|
-
// src/components/block/components/block-wrapper.tsx
|
|
1181
|
-
function BlockWrapper(props) {
|
|
1182
|
-
return createComponent(dynamic_renderer_default, {
|
|
1183
|
-
get TagName() {
|
|
1184
|
-
return props.Wrapper;
|
|
1185
|
-
},
|
|
1186
|
-
get attributes() {
|
|
1187
|
-
return getBlockProperties({
|
|
1188
|
-
block: props.block,
|
|
1189
|
-
context: props.context
|
|
1190
|
-
});
|
|
1191
|
-
},
|
|
1192
|
-
get actionAttributes() {
|
|
1193
|
-
return getBlockActions({
|
|
1194
|
-
block: props.block,
|
|
1195
|
-
rootState: props.context.rootState,
|
|
1196
|
-
rootSetState: props.context.rootSetState,
|
|
1197
|
-
localState: props.context.localState,
|
|
1198
|
-
context: props.context.context,
|
|
1199
|
-
stripPrefix: true
|
|
1200
|
-
});
|
|
1201
|
-
},
|
|
1202
|
-
get children() {
|
|
1203
|
-
return props.children;
|
|
1204
|
-
}
|
|
1205
|
-
});
|
|
1206
|
-
}
|
|
1207
|
-
var block_wrapper_default = BlockWrapper;
|
|
1208
|
-
|
|
1209
|
-
// src/functions/is-previewing.ts
|
|
1210
|
-
function isPreviewing(search) {
|
|
1211
|
-
const searchToUse = search || (isBrowser() ? window.location.search : void 0);
|
|
1212
|
-
if (!searchToUse) {
|
|
1213
|
-
return false;
|
|
1214
|
-
}
|
|
1215
|
-
const normalizedSearch = getSearchString(searchToUse);
|
|
1216
|
-
return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
|
|
1217
|
-
}
|
|
1218
|
-
|
|
1219
|
-
// src/functions/register-component.ts
|
|
1220
|
-
var createRegisterComponentMessage = (info) => ({
|
|
1221
|
-
type: "builder.registerComponent",
|
|
1222
|
-
data: serializeIncludingFunctions(info)
|
|
1223
|
-
});
|
|
1224
|
-
var serializeFn = (fnValue) => {
|
|
1225
|
-
const fnStr = fnValue.toString().trim();
|
|
1226
|
-
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
1227
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
1228
|
-
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
1229
|
-
};
|
|
1230
|
-
function serializeIncludingFunctions(info) {
|
|
1231
|
-
return JSON.parse(JSON.stringify(info, (key, value) => {
|
|
1232
|
-
if (typeof value === "function") {
|
|
1233
|
-
return serializeFn(value);
|
|
1234
|
-
}
|
|
1235
|
-
return value;
|
|
1236
|
-
}));
|
|
1237
|
-
}
|
|
1238
|
-
|
|
1239
|
-
// src/functions/register.ts
|
|
1240
|
-
var registry = {};
|
|
1241
|
-
function register(type, info) {
|
|
1242
|
-
if (type === "plugin") {
|
|
1243
|
-
info = serializeIncludingFunctions(info);
|
|
1244
|
-
}
|
|
1245
|
-
let typeList = registry[type];
|
|
1246
|
-
if (!typeList) {
|
|
1247
|
-
typeList = registry[type] = [];
|
|
1248
|
-
}
|
|
1249
|
-
typeList.push(info);
|
|
1250
|
-
if (isBrowser()) {
|
|
1251
|
-
const message = {
|
|
1252
|
-
type: "builder.register",
|
|
1253
|
-
data: {
|
|
1254
|
-
type,
|
|
1255
|
-
info
|
|
1256
|
-
}
|
|
1257
|
-
};
|
|
1258
|
-
try {
|
|
1259
|
-
parent.postMessage(message, "*");
|
|
1260
|
-
if (parent !== window) {
|
|
1261
|
-
window.postMessage(message, "*");
|
|
1262
|
-
}
|
|
1263
|
-
} catch (err) {
|
|
1264
|
-
}
|
|
1265
|
-
}
|
|
1266
|
-
}
|
|
1267
|
-
function registerAction(action) {
|
|
1268
|
-
if (isBrowser()) {
|
|
1269
|
-
const actionClone = JSON.parse(JSON.stringify(action));
|
|
1270
|
-
if (action.action) {
|
|
1271
|
-
actionClone.action = action.action.toString();
|
|
1272
|
-
}
|
|
1273
|
-
window.parent?.postMessage({
|
|
1274
|
-
type: "builder.registerAction",
|
|
1275
|
-
data: actionClone
|
|
1276
|
-
}, "*");
|
|
1277
|
-
}
|
|
1278
|
-
}
|
|
1279
|
-
|
|
1280
|
-
// src/functions/set-editor-settings.ts
|
|
1281
|
-
var settings = {};
|
|
1282
|
-
function setEditorSettings(newSettings) {
|
|
1283
|
-
if (isBrowser()) {
|
|
1284
|
-
Object.assign(settings, newSettings);
|
|
1285
|
-
const message = {
|
|
1286
|
-
type: "builder.settingsChange",
|
|
1287
|
-
data: settings
|
|
1288
|
-
};
|
|
1289
|
-
parent.postMessage(message, "*");
|
|
1290
|
-
}
|
|
1291
|
-
}
|
|
1292
|
-
|
|
1293
|
-
// src/functions/get-builder-search-params/index.ts
|
|
1294
|
-
var BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
1295
|
-
var BUILDER_OPTIONS_PREFIX = "options.";
|
|
1296
|
-
var getBuilderSearchParams = (_options) => {
|
|
1297
|
-
if (!_options) {
|
|
1298
|
-
return {};
|
|
1299
|
-
}
|
|
1300
|
-
const options = normalizeSearchParams(_options);
|
|
1301
|
-
const newOptions = {};
|
|
1302
|
-
Object.keys(options).forEach((key) => {
|
|
1303
|
-
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
1304
|
-
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
1305
|
-
newOptions[trimmedKey] = options[key];
|
|
1306
|
-
}
|
|
1307
|
-
});
|
|
1308
|
-
return newOptions;
|
|
1309
|
-
};
|
|
1310
|
-
var getBuilderSearchParamsFromWindow = () => {
|
|
1311
|
-
if (!isBrowser()) {
|
|
1312
|
-
return {};
|
|
1313
|
-
}
|
|
1314
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
1315
|
-
return getBuilderSearchParams(searchParams);
|
|
1316
|
-
};
|
|
1317
|
-
|
|
1318
|
-
// src/constants/sdk-version.ts
|
|
1319
|
-
var SDK_VERSION = "5.0.1";
|
|
1320
|
-
|
|
1321
|
-
// src/helpers/sdk-headers.ts
|
|
1322
|
-
var getSdkHeaders = () => ({
|
|
1323
|
-
"X-Builder-SDK": TARGET,
|
|
1324
|
-
"X-Builder-SDK-GEN": "2",
|
|
1325
|
-
"X-Builder-SDK-Version": SDK_VERSION
|
|
1326
|
-
});
|
|
1327
|
-
|
|
1328
|
-
// src/helpers/url.ts
|
|
1329
|
-
var getTopLevelDomain = (host) => {
|
|
1330
|
-
if (host === "localhost" || host === "127.0.0.1") {
|
|
1331
|
-
return host;
|
|
1332
|
-
}
|
|
1333
|
-
const parts = host.split(".");
|
|
1334
|
-
if (parts.length > 2) {
|
|
1335
|
-
return parts.slice(1).join(".");
|
|
1336
|
-
}
|
|
1337
|
-
return host;
|
|
1338
|
-
};
|
|
1339
|
-
|
|
1340
|
-
// src/helpers/cookie.ts
|
|
1341
|
-
var getCookieSync = ({
|
|
1342
|
-
name,
|
|
1343
|
-
canTrack
|
|
1344
|
-
}) => {
|
|
1345
|
-
try {
|
|
1346
|
-
if (!canTrack) {
|
|
1347
|
-
return void 0;
|
|
1348
|
-
}
|
|
1349
|
-
return document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))?.split("=")[1];
|
|
1350
|
-
} catch (err) {
|
|
1351
|
-
logger.warn("[COOKIE] GET error: ", err?.message || err);
|
|
1352
|
-
return void 0;
|
|
1353
|
-
}
|
|
1354
|
-
};
|
|
1355
|
-
var getCookie = async (args) => getCookieSync(args);
|
|
1356
|
-
var stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join("; ");
|
|
1357
|
-
var SECURE_CONFIG = [["secure", ""], ["SameSite", "None"]];
|
|
1358
|
-
var createCookieString = ({
|
|
1359
|
-
name,
|
|
1360
|
-
value,
|
|
1361
|
-
expires
|
|
1362
|
-
}) => {
|
|
1363
|
-
const secure = isBrowser() ? location.protocol === "https:" : true;
|
|
1364
|
-
const secureObj = secure ? SECURE_CONFIG : [[]];
|
|
1365
|
-
const expiresObj = expires ? [["expires", expires.toUTCString()]] : [[]];
|
|
1366
|
-
const cookieValue = [[name, value], ...expiresObj, ["path", "/"], ["domain", getTopLevelDomain(window.location.hostname)], ...secureObj];
|
|
1367
|
-
const cookie = stringifyCookie(cookieValue);
|
|
1368
|
-
return cookie;
|
|
1369
|
-
};
|
|
1370
|
-
var setCookie = async ({
|
|
1371
|
-
name,
|
|
1372
|
-
value,
|
|
1373
|
-
expires,
|
|
1374
|
-
canTrack
|
|
1375
|
-
}) => {
|
|
1376
|
-
try {
|
|
1377
|
-
if (!canTrack) {
|
|
1378
|
-
return;
|
|
1379
|
-
}
|
|
1380
|
-
const cookie = createCookieString({
|
|
1381
|
-
name,
|
|
1382
|
-
value,
|
|
1383
|
-
expires
|
|
1214
|
+
setTimeout(() => {
|
|
1215
|
+
element.style.transition = `all ${animation.duration}s ${camelToKebabCase(animation.easing)}`;
|
|
1216
|
+
if (animation.delay) {
|
|
1217
|
+
element.style.transitionDelay = animation.delay + "s";
|
|
1218
|
+
}
|
|
1384
1219
|
});
|
|
1385
|
-
document.
|
|
1386
|
-
|
|
1387
|
-
|
|
1388
|
-
|
|
1389
|
-
|
|
1390
|
-
|
|
1391
|
-
// src/helpers/uuid.ts
|
|
1392
|
-
function uuidv4() {
|
|
1393
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
1394
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
1395
|
-
return v.toString(16);
|
|
1220
|
+
document.addEventListener("scroll", onScroll, {
|
|
1221
|
+
capture: true,
|
|
1222
|
+
passive: true
|
|
1223
|
+
});
|
|
1224
|
+
immediateOnScroll();
|
|
1396
1225
|
});
|
|
1397
1226
|
}
|
|
1398
|
-
function uuid() {
|
|
1399
|
-
return uuidv4().replace(/-/g, "");
|
|
1400
|
-
}
|
|
1401
1227
|
|
|
1402
|
-
// src/helpers/
|
|
1403
|
-
var
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
}
|
|
1407
|
-
|
|
1408
|
-
|
|
1409
|
-
|
|
1410
|
-
const sessionId = await getCookie({
|
|
1411
|
-
name: SESSION_LOCAL_STORAGE_KEY,
|
|
1412
|
-
canTrack
|
|
1228
|
+
// src/helpers/css.ts
|
|
1229
|
+
var convertStyleMapToCSSArray = (style) => {
|
|
1230
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
1231
|
+
if (typeof value === "string") {
|
|
1232
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
1233
|
+
} else {
|
|
1234
|
+
return void 0;
|
|
1235
|
+
}
|
|
1413
1236
|
});
|
|
1414
|
-
|
|
1415
|
-
|
|
1237
|
+
return cssProps.filter(checkIsDefined);
|
|
1238
|
+
};
|
|
1239
|
+
var convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
|
|
1240
|
+
var createCssClass = ({
|
|
1241
|
+
mediaQuery,
|
|
1242
|
+
className,
|
|
1243
|
+
styles
|
|
1244
|
+
}) => {
|
|
1245
|
+
const cssClass = `.${className} {
|
|
1246
|
+
${convertStyleMapToCSS(styles)}
|
|
1247
|
+
}`;
|
|
1248
|
+
if (mediaQuery) {
|
|
1249
|
+
return `${mediaQuery} {
|
|
1250
|
+
${cssClass}
|
|
1251
|
+
}`;
|
|
1416
1252
|
} else {
|
|
1417
|
-
|
|
1418
|
-
setSessionId({
|
|
1419
|
-
id: newSessionId,
|
|
1420
|
-
canTrack
|
|
1421
|
-
});
|
|
1422
|
-
return newSessionId;
|
|
1253
|
+
return cssClass;
|
|
1423
1254
|
}
|
|
1424
1255
|
};
|
|
1425
|
-
var createSessionId = () => uuid();
|
|
1426
|
-
var setSessionId = ({
|
|
1427
|
-
id,
|
|
1428
|
-
canTrack
|
|
1429
|
-
}) => setCookie({
|
|
1430
|
-
name: SESSION_LOCAL_STORAGE_KEY,
|
|
1431
|
-
value: id,
|
|
1432
|
-
canTrack
|
|
1433
|
-
});
|
|
1434
1256
|
|
|
1435
|
-
// src/
|
|
1436
|
-
|
|
1437
|
-
|
|
1438
|
-
|
|
1439
|
-
|
|
1257
|
+
// src/functions/transform-style-property.ts
|
|
1258
|
+
function transformStyleProperty({
|
|
1259
|
+
style
|
|
1260
|
+
}) {
|
|
1261
|
+
return style;
|
|
1262
|
+
}
|
|
1263
|
+
|
|
1264
|
+
// src/functions/get-style.ts
|
|
1265
|
+
var getStyle = ({
|
|
1266
|
+
block,
|
|
1267
|
+
context
|
|
1440
1268
|
}) => {
|
|
1441
|
-
|
|
1442
|
-
|
|
1443
|
-
|
|
1444
|
-
|
|
1445
|
-
|
|
1446
|
-
|
|
1447
|
-
|
|
1269
|
+
return mapStyleObjToStrIfNeeded(transformStyleProperty({
|
|
1270
|
+
style: block.style || {},
|
|
1271
|
+
context,
|
|
1272
|
+
block
|
|
1273
|
+
}));
|
|
1274
|
+
};
|
|
1275
|
+
function mapStyleObjToStrIfNeeded(style) {
|
|
1276
|
+
switch (TARGET) {
|
|
1277
|
+
case "svelte":
|
|
1278
|
+
case "vue":
|
|
1279
|
+
case "solid":
|
|
1280
|
+
case "angular":
|
|
1281
|
+
return convertStyleMapToCSSArray(style).join(" ");
|
|
1282
|
+
case "qwik":
|
|
1283
|
+
case "reactNative":
|
|
1284
|
+
case "react":
|
|
1285
|
+
case "rsc":
|
|
1286
|
+
return style;
|
|
1448
1287
|
}
|
|
1288
|
+
}
|
|
1289
|
+
|
|
1290
|
+
// src/components/block/block.helpers.ts
|
|
1291
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
1292
|
+
if (!component)
|
|
1293
|
+
return true;
|
|
1294
|
+
if (!model)
|
|
1295
|
+
return false;
|
|
1296
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
1449
1297
|
};
|
|
1450
|
-
var
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1298
|
+
var getComponent = ({
|
|
1299
|
+
block,
|
|
1300
|
+
registeredComponents,
|
|
1301
|
+
model
|
|
1454
1302
|
}) => {
|
|
1455
|
-
|
|
1456
|
-
|
|
1457
|
-
|
|
1458
|
-
|
|
1459
|
-
|
|
1303
|
+
const componentName = block.component?.name;
|
|
1304
|
+
if (!componentName) {
|
|
1305
|
+
return null;
|
|
1306
|
+
}
|
|
1307
|
+
const ref = registeredComponents[componentName];
|
|
1308
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
1309
|
+
return void 0;
|
|
1310
|
+
} else {
|
|
1311
|
+
return ref;
|
|
1460
1312
|
}
|
|
1461
1313
|
};
|
|
1462
|
-
|
|
1463
|
-
|
|
1464
|
-
|
|
1465
|
-
var getVisitorId = ({
|
|
1466
|
-
canTrack
|
|
1314
|
+
var getRepeatItemData = ({
|
|
1315
|
+
block,
|
|
1316
|
+
context
|
|
1467
1317
|
}) => {
|
|
1468
|
-
|
|
1318
|
+
const {
|
|
1319
|
+
repeat,
|
|
1320
|
+
...blockWithoutRepeat
|
|
1321
|
+
} = block;
|
|
1322
|
+
if (!repeat?.collection) {
|
|
1469
1323
|
return void 0;
|
|
1470
1324
|
}
|
|
1471
|
-
const
|
|
1472
|
-
|
|
1473
|
-
|
|
1325
|
+
const itemsArray = evaluate({
|
|
1326
|
+
code: repeat.collection,
|
|
1327
|
+
localState: context.localState,
|
|
1328
|
+
rootState: context.rootState,
|
|
1329
|
+
rootSetState: context.rootSetState,
|
|
1330
|
+
context: context.context
|
|
1474
1331
|
});
|
|
1475
|
-
if (
|
|
1476
|
-
return
|
|
1477
|
-
}
|
|
1478
|
-
|
|
1479
|
-
|
|
1480
|
-
|
|
1481
|
-
|
|
1482
|
-
|
|
1483
|
-
|
|
1332
|
+
if (!Array.isArray(itemsArray)) {
|
|
1333
|
+
return void 0;
|
|
1334
|
+
}
|
|
1335
|
+
const collectionName = repeat.collection.split(".").pop();
|
|
1336
|
+
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
1337
|
+
const repeatArray = itemsArray.map((item, index) => ({
|
|
1338
|
+
context: {
|
|
1339
|
+
...context,
|
|
1340
|
+
localState: {
|
|
1341
|
+
...context.localState,
|
|
1342
|
+
$index: index,
|
|
1343
|
+
$item: item,
|
|
1344
|
+
[itemNameToUse]: item,
|
|
1345
|
+
[`$${itemNameToUse}Index`]: index
|
|
1346
|
+
}
|
|
1347
|
+
},
|
|
1348
|
+
block: blockWithoutRepeat
|
|
1349
|
+
}));
|
|
1350
|
+
return repeatArray;
|
|
1351
|
+
};
|
|
1352
|
+
var provideLinkComponent = (block, linkComponent) => {
|
|
1353
|
+
if (block?.shouldReceiveBuilderProps?.builderLinkComponent)
|
|
1354
|
+
return {
|
|
1355
|
+
builderLinkComponent: linkComponent
|
|
1356
|
+
};
|
|
1357
|
+
return {};
|
|
1358
|
+
};
|
|
1359
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
1360
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
1361
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
1362
|
+
return !checkIsComponentRestricted(component, model);
|
|
1363
|
+
}));
|
|
1364
|
+
return {
|
|
1365
|
+
builderComponents: filteredRegisteredComponents
|
|
1366
|
+
};
|
|
1484
1367
|
}
|
|
1368
|
+
return {};
|
|
1485
1369
|
};
|
|
1486
|
-
var
|
|
1487
|
-
|
|
1488
|
-
|
|
1489
|
-
|
|
1490
|
-
}
|
|
1491
|
-
|
|
1492
|
-
|
|
1493
|
-
|
|
1370
|
+
var provideBuilderBlock = (block, builderBlock) => {
|
|
1371
|
+
if (block?.shouldReceiveBuilderProps?.builderBlock)
|
|
1372
|
+
return {
|
|
1373
|
+
builderBlock
|
|
1374
|
+
};
|
|
1375
|
+
return {};
|
|
1376
|
+
};
|
|
1377
|
+
var provideBuilderContext = (block, context) => {
|
|
1378
|
+
if (block?.shouldReceiveBuilderProps?.builderContext)
|
|
1379
|
+
return {
|
|
1380
|
+
builderContext: context
|
|
1381
|
+
};
|
|
1382
|
+
return {};
|
|
1383
|
+
};
|
|
1384
|
+
var generateKey = (index) => {
|
|
1385
|
+
return index.toString();
|
|
1386
|
+
};
|
|
1387
|
+
|
|
1388
|
+
// src/functions/event-handler-name.ts
|
|
1389
|
+
function capitalizeFirstLetter(string) {
|
|
1390
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1391
|
+
}
|
|
1392
|
+
var getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
|
|
1393
|
+
|
|
1394
|
+
// src/functions/get-block-actions-handler.ts
|
|
1395
|
+
var createEventHandler = (value, options) => (event) => evaluate({
|
|
1396
|
+
code: value,
|
|
1397
|
+
context: options.context,
|
|
1398
|
+
localState: options.localState,
|
|
1399
|
+
rootState: options.rootState,
|
|
1400
|
+
rootSetState: options.rootSetState,
|
|
1401
|
+
event,
|
|
1402
|
+
isExpression: false,
|
|
1403
|
+
trackingContext: options.trackingContext
|
|
1494
1404
|
});
|
|
1495
1405
|
|
|
1496
|
-
// src/functions/
|
|
1497
|
-
function
|
|
1498
|
-
|
|
1499
|
-
|
|
1500
|
-
|
|
1406
|
+
// src/functions/get-block-actions.ts
|
|
1407
|
+
function getBlockActions(options) {
|
|
1408
|
+
const obj = {};
|
|
1409
|
+
const optionActions = options.block.actions ?? {};
|
|
1410
|
+
for (const key in optionActions) {
|
|
1411
|
+
if (!optionActions.hasOwnProperty(key)) {
|
|
1412
|
+
continue;
|
|
1413
|
+
}
|
|
1414
|
+
const value = optionActions[key];
|
|
1415
|
+
let eventHandlerName = getEventHandlerName(key);
|
|
1416
|
+
if (options.stripPrefix) {
|
|
1417
|
+
switch (TARGET) {
|
|
1418
|
+
case "vue":
|
|
1419
|
+
eventHandlerName = eventHandlerName.replace("v-on:", "");
|
|
1420
|
+
break;
|
|
1421
|
+
case "svelte":
|
|
1422
|
+
eventHandlerName = eventHandlerName.replace("on:", "");
|
|
1423
|
+
break;
|
|
1424
|
+
}
|
|
1501
1425
|
}
|
|
1426
|
+
obj[eventHandlerName] = createEventHandler(value, options);
|
|
1502
1427
|
}
|
|
1428
|
+
return obj;
|
|
1503
1429
|
}
|
|
1504
1430
|
|
|
1505
|
-
// src/functions/
|
|
1506
|
-
|
|
1507
|
-
|
|
1508
|
-
})
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1514
|
-
}
|
|
1515
|
-
const sessionId = await getSessionId({
|
|
1516
|
-
canTrack
|
|
1517
|
-
});
|
|
1518
|
-
const visitorId = getVisitorId({
|
|
1519
|
-
canTrack
|
|
1520
|
-
});
|
|
1431
|
+
// src/functions/transform-block-properties.ts
|
|
1432
|
+
function transformBlockProperties({
|
|
1433
|
+
properties
|
|
1434
|
+
}) {
|
|
1435
|
+
return properties;
|
|
1436
|
+
}
|
|
1437
|
+
|
|
1438
|
+
// src/functions/get-block-properties.ts
|
|
1439
|
+
var extractRelevantRootBlockProperties = (block) => {
|
|
1521
1440
|
return {
|
|
1522
|
-
|
|
1523
|
-
visitorId
|
|
1441
|
+
href: block.href
|
|
1524
1442
|
};
|
|
1525
1443
|
};
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
url: location.href,
|
|
1538
|
-
...metadata
|
|
1539
|
-
},
|
|
1540
|
-
...await getTrackingEventData({
|
|
1541
|
-
canTrack
|
|
1444
|
+
function getBlockProperties({
|
|
1445
|
+
block,
|
|
1446
|
+
context
|
|
1447
|
+
}) {
|
|
1448
|
+
const properties = {
|
|
1449
|
+
...extractRelevantRootBlockProperties(block),
|
|
1450
|
+
...block.properties,
|
|
1451
|
+
"builder-id": block.id,
|
|
1452
|
+
style: getStyle({
|
|
1453
|
+
block,
|
|
1454
|
+
context
|
|
1542
1455
|
}),
|
|
1543
|
-
|
|
1544
|
-
|
|
1456
|
+
[getClassPropName()]: [block.id, "builder-block", block.class, block.properties?.class].filter(Boolean).join(" ")
|
|
1457
|
+
};
|
|
1458
|
+
return transformBlockProperties({
|
|
1459
|
+
properties,
|
|
1460
|
+
context,
|
|
1461
|
+
block
|
|
1462
|
+
});
|
|
1463
|
+
}
|
|
1464
|
+
|
|
1465
|
+
// src/components/block/components/block-wrapper.tsx
|
|
1466
|
+
function BlockWrapper(props) {
|
|
1467
|
+
return createComponent(dynamic_renderer_default, {
|
|
1468
|
+
get TagName() {
|
|
1469
|
+
return props.Wrapper;
|
|
1470
|
+
},
|
|
1471
|
+
get attributes() {
|
|
1472
|
+
return getBlockProperties({
|
|
1473
|
+
block: props.block,
|
|
1474
|
+
context: props.context
|
|
1475
|
+
});
|
|
1476
|
+
},
|
|
1477
|
+
get actionAttributes() {
|
|
1478
|
+
return getBlockActions({
|
|
1479
|
+
block: props.block,
|
|
1480
|
+
rootState: props.context.rootState,
|
|
1481
|
+
rootSetState: props.context.rootSetState,
|
|
1482
|
+
localState: props.context.localState,
|
|
1483
|
+
context: props.context.context,
|
|
1484
|
+
stripPrefix: true,
|
|
1485
|
+
trackingContext: {
|
|
1486
|
+
apiKey: props.context.apiKey,
|
|
1487
|
+
canTrack: props.context.canTrack ?? true,
|
|
1488
|
+
contentId: props.context.content?.id,
|
|
1489
|
+
variationId: props.context.content?.testVariationId
|
|
1490
|
+
}
|
|
1491
|
+
});
|
|
1492
|
+
},
|
|
1493
|
+
get children() {
|
|
1494
|
+
return props.children;
|
|
1495
|
+
}
|
|
1496
|
+
});
|
|
1497
|
+
}
|
|
1498
|
+
var block_wrapper_default = BlockWrapper;
|
|
1499
|
+
|
|
1500
|
+
// src/functions/is-previewing.ts
|
|
1501
|
+
function isPreviewing(search) {
|
|
1502
|
+
const searchToUse = search || (isBrowser() ? window.location.search : void 0);
|
|
1503
|
+
if (!searchToUse) {
|
|
1504
|
+
return false;
|
|
1545
1505
|
}
|
|
1506
|
+
const normalizedSearch = getSearchString(searchToUse);
|
|
1507
|
+
return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
|
|
1508
|
+
}
|
|
1509
|
+
|
|
1510
|
+
// src/functions/register-component.ts
|
|
1511
|
+
var createRegisterComponentMessage = (info) => ({
|
|
1512
|
+
type: "builder.registerComponent",
|
|
1513
|
+
data: serializeIncludingFunctions(info)
|
|
1546
1514
|
});
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1515
|
+
var serializeFn = (fnValue) => {
|
|
1516
|
+
const fnStr = fnValue.toString().trim();
|
|
1517
|
+
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
1518
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
1519
|
+
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
1520
|
+
};
|
|
1521
|
+
function serializeIncludingFunctions(info) {
|
|
1522
|
+
return JSON.parse(JSON.stringify(info, (key, value) => {
|
|
1523
|
+
if (typeof value === "function") {
|
|
1524
|
+
return serializeFn(value);
|
|
1525
|
+
}
|
|
1526
|
+
return value;
|
|
1527
|
+
}));
|
|
1528
|
+
}
|
|
1529
|
+
|
|
1530
|
+
// src/functions/register.ts
|
|
1531
|
+
var registry = {};
|
|
1532
|
+
function register(type, info) {
|
|
1533
|
+
if (type === "plugin") {
|
|
1534
|
+
info = serializeIncludingFunctions(info);
|
|
1554
1535
|
}
|
|
1555
|
-
|
|
1556
|
-
|
|
1536
|
+
let typeList = registry[type];
|
|
1537
|
+
if (!typeList) {
|
|
1538
|
+
typeList = registry[type] = [];
|
|
1557
1539
|
}
|
|
1558
|
-
|
|
1559
|
-
|
|
1540
|
+
typeList.push(info);
|
|
1541
|
+
if (isBrowser()) {
|
|
1542
|
+
const message = {
|
|
1543
|
+
type: "builder.register",
|
|
1544
|
+
data: {
|
|
1545
|
+
type,
|
|
1546
|
+
info
|
|
1547
|
+
}
|
|
1548
|
+
};
|
|
1549
|
+
try {
|
|
1550
|
+
parent.postMessage(message, "*");
|
|
1551
|
+
if (parent !== window) {
|
|
1552
|
+
window.postMessage(message, "*");
|
|
1553
|
+
}
|
|
1554
|
+
} catch (err) {
|
|
1555
|
+
}
|
|
1560
1556
|
}
|
|
1561
|
-
|
|
1562
|
-
|
|
1557
|
+
}
|
|
1558
|
+
function registerAction(action) {
|
|
1559
|
+
if (isBrowser()) {
|
|
1560
|
+
const actionClone = JSON.parse(JSON.stringify(action));
|
|
1561
|
+
if (action.action) {
|
|
1562
|
+
actionClone.action = action.action.toString();
|
|
1563
|
+
}
|
|
1564
|
+
window.parent?.postMessage({
|
|
1565
|
+
type: "builder.registerAction",
|
|
1566
|
+
data: actionClone
|
|
1567
|
+
}, "*");
|
|
1563
1568
|
}
|
|
1564
|
-
const baseUrl = apiHost || "https://cdn.builder.io";
|
|
1565
|
-
const url = `${baseUrl}/api/v1/track`;
|
|
1566
|
-
logFetch(url);
|
|
1567
|
-
return fetch(url, {
|
|
1568
|
-
method: "POST",
|
|
1569
|
-
body: JSON.stringify({
|
|
1570
|
-
events: [await createEvent(eventProps)]
|
|
1571
|
-
}),
|
|
1572
|
-
headers: {
|
|
1573
|
-
"content-type": "application/json",
|
|
1574
|
-
...getSdkHeaders()
|
|
1575
|
-
},
|
|
1576
|
-
mode: "cors"
|
|
1577
|
-
}).catch((err) => {
|
|
1578
|
-
});
|
|
1579
1569
|
}
|
|
1580
|
-
|
|
1581
|
-
|
|
1582
|
-
|
|
1583
|
-
|
|
1570
|
+
|
|
1571
|
+
// src/functions/set-editor-settings.ts
|
|
1572
|
+
var settings = {};
|
|
1573
|
+
function setEditorSettings(newSettings) {
|
|
1574
|
+
if (isBrowser()) {
|
|
1575
|
+
Object.assign(settings, newSettings);
|
|
1576
|
+
const message = {
|
|
1577
|
+
type: "builder.settingsChange",
|
|
1578
|
+
data: settings
|
|
1579
|
+
};
|
|
1580
|
+
parent.postMessage(message, "*");
|
|
1581
|
+
}
|
|
1582
|
+
}
|
|
1583
|
+
|
|
1584
|
+
// src/functions/get-builder-search-params/index.ts
|
|
1585
|
+
var BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
1586
|
+
var BUILDER_OPTIONS_PREFIX = "options.";
|
|
1587
|
+
var getBuilderSearchParams = (_options) => {
|
|
1588
|
+
if (!_options) {
|
|
1589
|
+
return {};
|
|
1590
|
+
}
|
|
1591
|
+
const options = normalizeSearchParams(_options);
|
|
1592
|
+
const newOptions = {};
|
|
1593
|
+
Object.keys(options).forEach((key) => {
|
|
1594
|
+
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
1595
|
+
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
1596
|
+
newOptions[trimmedKey] = options[key];
|
|
1597
|
+
}
|
|
1598
|
+
});
|
|
1599
|
+
return newOptions;
|
|
1600
|
+
};
|
|
1601
|
+
var getBuilderSearchParamsFromWindow = () => {
|
|
1602
|
+
if (!isBrowser()) {
|
|
1603
|
+
return {};
|
|
1604
|
+
}
|
|
1605
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
1606
|
+
return getBuilderSearchParams(searchParams);
|
|
1607
|
+
};
|
|
1584
1608
|
|
|
1585
1609
|
// src/functions/is-from-trusted-host.ts
|
|
1586
1610
|
var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
@@ -2321,7 +2345,13 @@ function InteractiveElement(props) {
|
|
|
2321
2345
|
rootState: props.context.rootState,
|
|
2322
2346
|
rootSetState: props.context.rootSetState,
|
|
2323
2347
|
localState: props.context.localState,
|
|
2324
|
-
context: props.context.context
|
|
2348
|
+
context: props.context.context,
|
|
2349
|
+
trackingContext: {
|
|
2350
|
+
apiKey: props.context.apiKey,
|
|
2351
|
+
canTrack: props.context.canTrack ?? true,
|
|
2352
|
+
contentId: props.context.content?.id,
|
|
2353
|
+
variationId: props.context.content?.testVariationId
|
|
2354
|
+
}
|
|
2325
2355
|
})
|
|
2326
2356
|
} : {};
|
|
2327
2357
|
});
|