@builder.io/sdk-solid 5.1.0 → 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 +409 -377
- package/lib/node/dev.jsx +974 -942
- package/lib/node/index.js +775 -743
- package/lib/node/index.jsx +776 -744
- package/package.json +1 -1
package/lib/browser/index.jsx
CHANGED
|
@@ -206,145 +206,431 @@ var getUserAttributes = () => {
|
|
|
206
206
|
};
|
|
207
207
|
};
|
|
208
208
|
|
|
209
|
-
// src/
|
|
210
|
-
var
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
209
|
+
// src/constants/sdk-version.ts
|
|
210
|
+
var SDK_VERSION = "5.1.1";
|
|
211
|
+
|
|
212
|
+
// src/helpers/sdk-headers.ts
|
|
213
|
+
var getSdkHeaders = () => ({
|
|
214
|
+
"X-Builder-SDK": TARGET,
|
|
215
|
+
"X-Builder-SDK-GEN": "2",
|
|
216
|
+
"X-Builder-SDK-Version": SDK_VERSION
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
// src/helpers/nullable.ts
|
|
220
|
+
var checkIsDefined = (maybeT) => maybeT !== null && maybeT !== void 0;
|
|
221
|
+
|
|
222
|
+
// src/helpers/url.ts
|
|
223
|
+
var getTopLevelDomain = (host) => {
|
|
224
|
+
if (host === "localhost" || host === "127.0.0.1") {
|
|
225
|
+
return host;
|
|
226
|
+
}
|
|
227
|
+
const parts = host.split(".");
|
|
228
|
+
if (parts.length > 2) {
|
|
229
|
+
return parts.slice(1).join(".");
|
|
230
|
+
}
|
|
231
|
+
return host;
|
|
232
|
+
};
|
|
233
|
+
|
|
234
|
+
// src/helpers/cookie.ts
|
|
235
|
+
var getCookieSync = ({
|
|
236
|
+
name,
|
|
237
|
+
canTrack
|
|
215
238
|
}) => {
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
239
|
+
try {
|
|
240
|
+
if (!canTrack) {
|
|
241
|
+
return void 0;
|
|
242
|
+
}
|
|
243
|
+
return document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))?.split("=")[1];
|
|
244
|
+
} catch (err) {
|
|
245
|
+
logger.warn("[COOKIE] GET error: ", err?.message || err);
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
224
248
|
};
|
|
225
|
-
var
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
isExpression = true
|
|
249
|
+
var getCookie = async (args) => getCookieSync(args);
|
|
250
|
+
var stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join("; ");
|
|
251
|
+
var SECURE_CONFIG = [["secure", ""], ["SameSite", "None"]];
|
|
252
|
+
var createCookieString = ({
|
|
253
|
+
name,
|
|
254
|
+
value,
|
|
255
|
+
expires
|
|
233
256
|
}) => {
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
);
|
|
238
|
-
const
|
|
239
|
-
return
|
|
257
|
+
const secure = isBrowser() ? location.protocol === "https:" : true;
|
|
258
|
+
const secureObj = secure ? SECURE_CONFIG : [[]];
|
|
259
|
+
const expiresObj = expires ? [["expires", expires.toUTCString()]] : [[]];
|
|
260
|
+
const cookieValue = [[name, value], ...expiresObj, ["path", "/"], ["domain", getTopLevelDomain(window.location.hostname)], ...secureObj];
|
|
261
|
+
const cookie = stringifyCookie(cookieValue);
|
|
262
|
+
return cookie;
|
|
240
263
|
};
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
}
|
|
251
|
-
const val = target[prop];
|
|
252
|
-
if (typeof val === "object" && val !== null) {
|
|
253
|
-
return flattenState({
|
|
254
|
-
rootState: val,
|
|
255
|
-
localState: void 0,
|
|
256
|
-
rootSetState: rootSetState ? (subState) => {
|
|
257
|
-
target[prop] = subState;
|
|
258
|
-
rootSetState(target);
|
|
259
|
-
} : void 0
|
|
260
|
-
});
|
|
261
|
-
}
|
|
262
|
-
return val;
|
|
263
|
-
},
|
|
264
|
-
set: (target, prop, value) => {
|
|
265
|
-
if (localState && prop in localState) {
|
|
266
|
-
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
267
|
-
}
|
|
268
|
-
target[prop] = value;
|
|
269
|
-
rootSetState?.(target);
|
|
270
|
-
return true;
|
|
264
|
+
var setCookie = async ({
|
|
265
|
+
name,
|
|
266
|
+
value,
|
|
267
|
+
expires,
|
|
268
|
+
canTrack
|
|
269
|
+
}) => {
|
|
270
|
+
try {
|
|
271
|
+
if (!canTrack) {
|
|
272
|
+
return;
|
|
271
273
|
}
|
|
274
|
+
const cookie = createCookieString({
|
|
275
|
+
name,
|
|
276
|
+
value,
|
|
277
|
+
expires
|
|
278
|
+
});
|
|
279
|
+
document.cookie = cookie;
|
|
280
|
+
} catch (err) {
|
|
281
|
+
logger.warn("[COOKIE] SET error: ", err?.message || err);
|
|
282
|
+
}
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
// src/helpers/uuid.ts
|
|
286
|
+
function uuidv4() {
|
|
287
|
+
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
288
|
+
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
289
|
+
return v.toString(16);
|
|
272
290
|
});
|
|
273
291
|
}
|
|
292
|
+
function uuid() {
|
|
293
|
+
return uuidv4().replace(/-/g, "");
|
|
294
|
+
}
|
|
274
295
|
|
|
275
|
-
// src/
|
|
276
|
-
var
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
context,
|
|
280
|
-
event,
|
|
281
|
-
localState,
|
|
282
|
-
rootSetState,
|
|
283
|
-
rootState
|
|
296
|
+
// src/helpers/sessionId.ts
|
|
297
|
+
var SESSION_LOCAL_STORAGE_KEY = "builderSessionId";
|
|
298
|
+
var getSessionId = async ({
|
|
299
|
+
canTrack
|
|
284
300
|
}) => {
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
localState,
|
|
292
|
-
rootSetState
|
|
293
|
-
})
|
|
301
|
+
if (!canTrack) {
|
|
302
|
+
return void 0;
|
|
303
|
+
}
|
|
304
|
+
const sessionId = await getCookie({
|
|
305
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
306
|
+
canTrack
|
|
294
307
|
});
|
|
295
|
-
|
|
308
|
+
if (checkIsDefined(sessionId)) {
|
|
309
|
+
return sessionId;
|
|
310
|
+
} else {
|
|
311
|
+
const newSessionId = createSessionId();
|
|
312
|
+
setSessionId({
|
|
313
|
+
id: newSessionId,
|
|
314
|
+
canTrack
|
|
315
|
+
});
|
|
316
|
+
return newSessionId;
|
|
317
|
+
}
|
|
296
318
|
};
|
|
319
|
+
var createSessionId = () => uuid();
|
|
320
|
+
var setSessionId = ({
|
|
321
|
+
id,
|
|
322
|
+
canTrack
|
|
323
|
+
}) => setCookie({
|
|
324
|
+
name: SESSION_LOCAL_STORAGE_KEY,
|
|
325
|
+
value: id,
|
|
326
|
+
canTrack
|
|
327
|
+
});
|
|
297
328
|
|
|
298
|
-
// src/helpers/
|
|
299
|
-
var
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
return typeof process !== "undefined" && checkIsDefined(process?.versions?.node);
|
|
304
|
-
}
|
|
305
|
-
|
|
306
|
-
// src/functions/evaluate/should-force-browser-runtime-in-node.ts
|
|
307
|
-
var shouldForceBrowserRuntimeInNode = ({
|
|
308
|
-
shouldLogWarning
|
|
329
|
+
// src/helpers/localStorage.ts
|
|
330
|
+
var getLocalStorage = () => isBrowser() && typeof localStorage !== "undefined" ? localStorage : void 0;
|
|
331
|
+
var getLocalStorageItem = ({
|
|
332
|
+
key,
|
|
333
|
+
canTrack
|
|
309
334
|
}) => {
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
const isNode20 = process.version.startsWith("v20");
|
|
314
|
-
const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes("--no-node-snapshot");
|
|
315
|
-
if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
|
|
316
|
-
if (shouldLogWarning) {
|
|
317
|
-
logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
|
|
318
|
-
If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
|
|
319
|
-
See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
|
|
320
|
-
`);
|
|
335
|
+
try {
|
|
336
|
+
if (canTrack) {
|
|
337
|
+
return getLocalStorage()?.getItem(key);
|
|
321
338
|
}
|
|
322
|
-
return
|
|
339
|
+
return void 0;
|
|
340
|
+
} catch (err) {
|
|
341
|
+
return void 0;
|
|
323
342
|
}
|
|
324
|
-
return false;
|
|
325
343
|
};
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
})
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
344
|
+
var setLocalStorageItem = ({
|
|
345
|
+
key,
|
|
346
|
+
canTrack,
|
|
347
|
+
value
|
|
348
|
+
}) => {
|
|
349
|
+
try {
|
|
350
|
+
if (canTrack) {
|
|
351
|
+
getLocalStorage()?.setItem(key, value);
|
|
352
|
+
}
|
|
353
|
+
} catch (err) {
|
|
354
|
+
}
|
|
337
355
|
};
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
}
|
|
347
|
-
|
|
356
|
+
|
|
357
|
+
// src/helpers/visitorId.ts
|
|
358
|
+
var VISITOR_LOCAL_STORAGE_KEY = "builderVisitorId";
|
|
359
|
+
var getVisitorId = ({
|
|
360
|
+
canTrack
|
|
361
|
+
}) => {
|
|
362
|
+
if (!canTrack) {
|
|
363
|
+
return void 0;
|
|
364
|
+
}
|
|
365
|
+
const visitorId = getLocalStorageItem({
|
|
366
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
367
|
+
canTrack
|
|
368
|
+
});
|
|
369
|
+
if (checkIsDefined(visitorId)) {
|
|
370
|
+
return visitorId;
|
|
371
|
+
} else {
|
|
372
|
+
const newVisitorId = createVisitorId();
|
|
373
|
+
setVisitorId({
|
|
374
|
+
id: newVisitorId,
|
|
375
|
+
canTrack
|
|
376
|
+
});
|
|
377
|
+
return newVisitorId;
|
|
378
|
+
}
|
|
379
|
+
};
|
|
380
|
+
var createVisitorId = () => uuid();
|
|
381
|
+
var setVisitorId = ({
|
|
382
|
+
id,
|
|
383
|
+
canTrack
|
|
384
|
+
}) => setLocalStorageItem({
|
|
385
|
+
key: VISITOR_LOCAL_STORAGE_KEY,
|
|
386
|
+
value: id,
|
|
387
|
+
canTrack
|
|
388
|
+
});
|
|
389
|
+
|
|
390
|
+
// src/functions/log-fetch.ts
|
|
391
|
+
function logFetch(url) {
|
|
392
|
+
if (typeof process !== "undefined" && process.env?.DEBUG) {
|
|
393
|
+
if (String(process.env.DEBUG) == "true") {
|
|
394
|
+
logger.log(url);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
|
|
399
|
+
// src/functions/track/index.ts
|
|
400
|
+
var getTrackingEventData = async ({
|
|
401
|
+
canTrack
|
|
402
|
+
}) => {
|
|
403
|
+
if (!canTrack) {
|
|
404
|
+
return {
|
|
405
|
+
visitorId: void 0,
|
|
406
|
+
sessionId: void 0
|
|
407
|
+
};
|
|
408
|
+
}
|
|
409
|
+
const sessionId = await getSessionId({
|
|
410
|
+
canTrack
|
|
411
|
+
});
|
|
412
|
+
const visitorId = getVisitorId({
|
|
413
|
+
canTrack
|
|
414
|
+
});
|
|
415
|
+
return {
|
|
416
|
+
sessionId,
|
|
417
|
+
visitorId
|
|
418
|
+
};
|
|
419
|
+
};
|
|
420
|
+
var createEvent = async ({
|
|
421
|
+
type: eventType,
|
|
422
|
+
canTrack,
|
|
423
|
+
apiKey,
|
|
424
|
+
metadata,
|
|
425
|
+
...properties
|
|
426
|
+
}) => ({
|
|
427
|
+
type: eventType,
|
|
428
|
+
data: {
|
|
429
|
+
...properties,
|
|
430
|
+
metadata: {
|
|
431
|
+
url: location.href,
|
|
432
|
+
...metadata
|
|
433
|
+
},
|
|
434
|
+
...await getTrackingEventData({
|
|
435
|
+
canTrack
|
|
436
|
+
}),
|
|
437
|
+
userAttributes: getUserAttributes(),
|
|
438
|
+
ownerId: apiKey
|
|
439
|
+
}
|
|
440
|
+
});
|
|
441
|
+
async function _track({
|
|
442
|
+
apiHost,
|
|
443
|
+
...eventProps
|
|
444
|
+
}) {
|
|
445
|
+
if (!eventProps.apiKey) {
|
|
446
|
+
logger.error("Missing API key for track call. Please provide your API key.");
|
|
447
|
+
return;
|
|
448
|
+
}
|
|
449
|
+
if (!eventProps.canTrack) {
|
|
450
|
+
return;
|
|
451
|
+
}
|
|
452
|
+
if (isEditing()) {
|
|
453
|
+
return;
|
|
454
|
+
}
|
|
455
|
+
if (!(isBrowser() || TARGET === "reactNative")) {
|
|
456
|
+
return;
|
|
457
|
+
}
|
|
458
|
+
const baseUrl = apiHost || "https://cdn.builder.io";
|
|
459
|
+
const url = `${baseUrl}/api/v1/track`;
|
|
460
|
+
logFetch(url);
|
|
461
|
+
return fetch(url, {
|
|
462
|
+
method: "POST",
|
|
463
|
+
body: JSON.stringify({
|
|
464
|
+
events: [await createEvent(eventProps)]
|
|
465
|
+
}),
|
|
466
|
+
headers: {
|
|
467
|
+
"content-type": "application/json",
|
|
468
|
+
...getSdkHeaders()
|
|
469
|
+
},
|
|
470
|
+
mode: "cors"
|
|
471
|
+
}).catch((err) => {
|
|
472
|
+
});
|
|
473
|
+
}
|
|
474
|
+
var track = (args) => _track({
|
|
475
|
+
...args,
|
|
476
|
+
canTrack: true
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
// src/functions/evaluate/helpers.ts
|
|
480
|
+
var getFunctionArguments = ({
|
|
481
|
+
builder,
|
|
482
|
+
context,
|
|
483
|
+
event,
|
|
484
|
+
state
|
|
485
|
+
}) => {
|
|
486
|
+
return Object.entries({
|
|
487
|
+
state,
|
|
488
|
+
Builder: builder,
|
|
489
|
+
// legacy
|
|
490
|
+
builder,
|
|
491
|
+
context,
|
|
492
|
+
event
|
|
493
|
+
});
|
|
494
|
+
};
|
|
495
|
+
var getBuilderGlobals = (trackingContext) => ({
|
|
496
|
+
isEditing: isEditing(),
|
|
497
|
+
isBrowser: isBrowser(),
|
|
498
|
+
isServer: !isBrowser(),
|
|
499
|
+
getUserAttributes: () => getUserAttributes(),
|
|
500
|
+
trackConversion: (amount, customProperties) => {
|
|
501
|
+
if (!trackingContext?.apiKey || trackingContext?.canTrack === false) {
|
|
502
|
+
return;
|
|
503
|
+
}
|
|
504
|
+
_track({
|
|
505
|
+
type: "conversion",
|
|
506
|
+
apiKey: trackingContext.apiKey,
|
|
507
|
+
canTrack: trackingContext.canTrack ?? true,
|
|
508
|
+
contentId: trackingContext.contentId,
|
|
509
|
+
variationId: trackingContext.variationId !== trackingContext.contentId ? trackingContext.variationId : void 0,
|
|
510
|
+
metadata: {
|
|
511
|
+
...customProperties || {},
|
|
512
|
+
...amount !== void 0 ? {
|
|
513
|
+
amount
|
|
514
|
+
} : {}
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
});
|
|
519
|
+
var parseCode = (code, {
|
|
520
|
+
isExpression = true
|
|
521
|
+
}) => {
|
|
522
|
+
const useReturn = (
|
|
523
|
+
// we disable this for cases where we definitely don't want a return
|
|
524
|
+
isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "))
|
|
525
|
+
);
|
|
526
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
527
|
+
return useCode;
|
|
528
|
+
};
|
|
529
|
+
function flattenState({
|
|
530
|
+
rootState,
|
|
531
|
+
localState,
|
|
532
|
+
rootSetState
|
|
533
|
+
}) {
|
|
534
|
+
return new Proxy(rootState, {
|
|
535
|
+
get: (target, prop) => {
|
|
536
|
+
if (localState && prop in localState) {
|
|
537
|
+
return localState[prop];
|
|
538
|
+
}
|
|
539
|
+
const val = target[prop];
|
|
540
|
+
if (typeof val === "object" && val !== null) {
|
|
541
|
+
return flattenState({
|
|
542
|
+
rootState: val,
|
|
543
|
+
localState: void 0,
|
|
544
|
+
rootSetState: rootSetState ? (subState) => {
|
|
545
|
+
target[prop] = subState;
|
|
546
|
+
rootSetState(target);
|
|
547
|
+
} : void 0
|
|
548
|
+
});
|
|
549
|
+
}
|
|
550
|
+
return val;
|
|
551
|
+
},
|
|
552
|
+
set: (target, prop, value) => {
|
|
553
|
+
if (localState && prop in localState) {
|
|
554
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
555
|
+
}
|
|
556
|
+
target[prop] = value;
|
|
557
|
+
rootSetState?.(target);
|
|
558
|
+
return true;
|
|
559
|
+
}
|
|
560
|
+
});
|
|
561
|
+
}
|
|
562
|
+
|
|
563
|
+
// src/functions/evaluate/browser-runtime/browser.ts
|
|
564
|
+
var runInBrowser = ({
|
|
565
|
+
code,
|
|
566
|
+
builder,
|
|
567
|
+
context,
|
|
568
|
+
event,
|
|
569
|
+
localState,
|
|
570
|
+
rootSetState,
|
|
571
|
+
rootState
|
|
572
|
+
}) => {
|
|
573
|
+
const functionArgs = getFunctionArguments({
|
|
574
|
+
builder,
|
|
575
|
+
context,
|
|
576
|
+
event,
|
|
577
|
+
state: flattenState({
|
|
578
|
+
rootState,
|
|
579
|
+
localState,
|
|
580
|
+
rootSetState
|
|
581
|
+
})
|
|
582
|
+
});
|
|
583
|
+
return new Function(...functionArgs.map(([name]) => name), code)(...functionArgs.map(([, value]) => value));
|
|
584
|
+
};
|
|
585
|
+
|
|
586
|
+
// src/functions/is-node-runtime.ts
|
|
587
|
+
function isNodeRuntime() {
|
|
588
|
+
return typeof process !== "undefined" && checkIsDefined(process?.versions?.node);
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
// src/functions/evaluate/should-force-browser-runtime-in-node.ts
|
|
592
|
+
var shouldForceBrowserRuntimeInNode = ({
|
|
593
|
+
shouldLogWarning
|
|
594
|
+
}) => {
|
|
595
|
+
if (!isNodeRuntime())
|
|
596
|
+
return false;
|
|
597
|
+
const isArm64 = process.arch === "arm64";
|
|
598
|
+
const isNode20 = process.version.startsWith("v20");
|
|
599
|
+
const hasNoNodeSnapshotNodeOption = process.env.NODE_OPTIONS?.includes("--no-node-snapshot");
|
|
600
|
+
if (isArm64 && isNode20 && !hasNoNodeSnapshotNodeOption) {
|
|
601
|
+
if (shouldLogWarning) {
|
|
602
|
+
logger.log(`Skipping usage of \`isolated-vm\` to avoid crashes in Node v20 on an arm64 machine.
|
|
603
|
+
If you would like to use the \`isolated-vm\` package on this machine, please provide the \`NODE_OPTIONS=--no-node-snapshot\` config to your Node process.
|
|
604
|
+
See https://github.com/BuilderIO/builder/blob/main/packages/sdks/README.md#node-v20--m1-macs-apple-silicon-support for more information.
|
|
605
|
+
`);
|
|
606
|
+
}
|
|
607
|
+
return true;
|
|
608
|
+
}
|
|
609
|
+
return false;
|
|
610
|
+
};
|
|
611
|
+
|
|
612
|
+
// src/functions/evaluate/choose-eval.ts
|
|
613
|
+
var chooseBrowserOrServerEval = (args) => isBrowser() || shouldForceBrowserRuntimeInNode({
|
|
614
|
+
shouldLogWarning: true
|
|
615
|
+
}) ? runInBrowser(args) : runInBrowser(args);
|
|
616
|
+
|
|
617
|
+
// src/functions/evaluate/evaluate.ts
|
|
618
|
+
var STATE_GETTER_REGEX = /^(return )?(\s*)?state(?<getPath>(\.\w+)+)(\s*);?$/;
|
|
619
|
+
var VIRTUAL_INDEX_REGEX = /(\s)*var(\s)+_virtual_index(\s)*=(\s)*state(?<getPath>(\.\w+)+)(\s*);?(\s)*return(\s)*_virtual_index(\s)*/;
|
|
620
|
+
var getSimpleExpressionGetPath = (code) => {
|
|
621
|
+
return STATE_GETTER_REGEX.exec(code.trim())?.groups?.getPath?.slice(1) || VIRTUAL_INDEX_REGEX.exec(code.trim())?.groups?.getPath?.slice(1);
|
|
622
|
+
};
|
|
623
|
+
function evaluate({
|
|
624
|
+
code,
|
|
625
|
+
context,
|
|
626
|
+
localState,
|
|
627
|
+
rootState,
|
|
628
|
+
rootSetState,
|
|
629
|
+
event,
|
|
630
|
+
isExpression = true,
|
|
631
|
+
trackingContext
|
|
632
|
+
}) {
|
|
633
|
+
if (code.trim() === "") {
|
|
348
634
|
return void 0;
|
|
349
635
|
}
|
|
350
636
|
const getPath = getSimpleExpressionGetPath(code.trim());
|
|
@@ -358,7 +644,7 @@ function evaluate({
|
|
|
358
644
|
code: parseCode(code, {
|
|
359
645
|
isExpression
|
|
360
646
|
}),
|
|
361
|
-
builder: getBuilderGlobals(),
|
|
647
|
+
builder: getBuilderGlobals(trackingContext),
|
|
362
648
|
context,
|
|
363
649
|
event,
|
|
364
650
|
rootSetState,
|
|
@@ -751,661 +1037,401 @@ function bindScrollInViewAnimation(animation) {
|
|
|
751
1037
|
const defaultState = animation.steps[0].styles;
|
|
752
1038
|
function attachDefaultState() {
|
|
753
1039
|
assign(element.style, defaultState);
|
|
754
|
-
}
|
|
755
|
-
attachDefaultState();
|
|
756
|
-
setTimeout(() => {
|
|
757
|
-
element.style.transition = `all ${animation.duration}s ${camelToKebabCase(animation.easing)}`;
|
|
758
|
-
if (animation.delay) {
|
|
759
|
-
element.style.transitionDelay = animation.delay + "s";
|
|
760
|
-
}
|
|
761
|
-
});
|
|
762
|
-
document.addEventListener("scroll", onScroll, {
|
|
763
|
-
capture: true,
|
|
764
|
-
passive: true
|
|
765
|
-
});
|
|
766
|
-
immediateOnScroll();
|
|
767
|
-
});
|
|
768
|
-
}
|
|
769
|
-
|
|
770
|
-
// src/helpers/css.ts
|
|
771
|
-
var convertStyleMapToCSSArray = (style) => {
|
|
772
|
-
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
773
|
-
if (typeof value === "string") {
|
|
774
|
-
return `${camelToKebabCase(key)}: ${value};`;
|
|
775
|
-
} else {
|
|
776
|
-
return void 0;
|
|
777
|
-
}
|
|
778
|
-
});
|
|
779
|
-
return cssProps.filter(checkIsDefined);
|
|
780
|
-
};
|
|
781
|
-
var convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
|
|
782
|
-
var createCssClass = ({
|
|
783
|
-
mediaQuery,
|
|
784
|
-
className,
|
|
785
|
-
styles
|
|
786
|
-
}) => {
|
|
787
|
-
const cssClass = `.${className} {
|
|
788
|
-
${convertStyleMapToCSS(styles)}
|
|
789
|
-
}`;
|
|
790
|
-
if (mediaQuery) {
|
|
791
|
-
return `${mediaQuery} {
|
|
792
|
-
${cssClass}
|
|
793
|
-
}`;
|
|
794
|
-
} else {
|
|
795
|
-
return cssClass;
|
|
796
|
-
}
|
|
797
|
-
};
|
|
798
|
-
|
|
799
|
-
// src/functions/transform-style-property.ts
|
|
800
|
-
function transformStyleProperty({
|
|
801
|
-
style
|
|
802
|
-
}) {
|
|
803
|
-
return style;
|
|
804
|
-
}
|
|
805
|
-
|
|
806
|
-
// src/functions/get-style.ts
|
|
807
|
-
var getStyle = ({
|
|
808
|
-
block,
|
|
809
|
-
context
|
|
810
|
-
}) => {
|
|
811
|
-
return mapStyleObjToStrIfNeeded(transformStyleProperty({
|
|
812
|
-
style: block.style || {},
|
|
813
|
-
context,
|
|
814
|
-
block
|
|
815
|
-
}));
|
|
816
|
-
};
|
|
817
|
-
function mapStyleObjToStrIfNeeded(style) {
|
|
818
|
-
switch (TARGET) {
|
|
819
|
-
case "svelte":
|
|
820
|
-
case "vue":
|
|
821
|
-
case "solid":
|
|
822
|
-
case "angular":
|
|
823
|
-
return convertStyleMapToCSSArray(style).join(" ");
|
|
824
|
-
case "qwik":
|
|
825
|
-
case "reactNative":
|
|
826
|
-
case "react":
|
|
827
|
-
case "rsc":
|
|
828
|
-
return style;
|
|
829
|
-
}
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
// src/components/block/block.helpers.ts
|
|
833
|
-
var checkIsComponentRestricted = (component, model) => {
|
|
834
|
-
if (!component)
|
|
835
|
-
return true;
|
|
836
|
-
if (!model)
|
|
837
|
-
return false;
|
|
838
|
-
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
839
|
-
};
|
|
840
|
-
var getComponent = ({
|
|
841
|
-
block,
|
|
842
|
-
registeredComponents,
|
|
843
|
-
model
|
|
844
|
-
}) => {
|
|
845
|
-
const componentName = block.component?.name;
|
|
846
|
-
if (!componentName) {
|
|
847
|
-
return null;
|
|
848
|
-
}
|
|
849
|
-
const ref = registeredComponents[componentName];
|
|
850
|
-
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
851
|
-
return void 0;
|
|
852
|
-
} else {
|
|
853
|
-
return ref;
|
|
854
|
-
}
|
|
855
|
-
};
|
|
856
|
-
var getRepeatItemData = ({
|
|
857
|
-
block,
|
|
858
|
-
context
|
|
859
|
-
}) => {
|
|
860
|
-
const {
|
|
861
|
-
repeat,
|
|
862
|
-
...blockWithoutRepeat
|
|
863
|
-
} = block;
|
|
864
|
-
if (!repeat?.collection) {
|
|
865
|
-
return void 0;
|
|
866
|
-
}
|
|
867
|
-
const itemsArray = evaluate({
|
|
868
|
-
code: repeat.collection,
|
|
869
|
-
localState: context.localState,
|
|
870
|
-
rootState: context.rootState,
|
|
871
|
-
rootSetState: context.rootSetState,
|
|
872
|
-
context: context.context
|
|
873
|
-
});
|
|
874
|
-
if (!Array.isArray(itemsArray)) {
|
|
875
|
-
return void 0;
|
|
876
|
-
}
|
|
877
|
-
const collectionName = repeat.collection.split(".").pop();
|
|
878
|
-
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
879
|
-
const repeatArray = itemsArray.map((item, index) => ({
|
|
880
|
-
context: {
|
|
881
|
-
...context,
|
|
882
|
-
localState: {
|
|
883
|
-
...context.localState,
|
|
884
|
-
$index: index,
|
|
885
|
-
$item: item,
|
|
886
|
-
[itemNameToUse]: item,
|
|
887
|
-
[`$${itemNameToUse}Index`]: index
|
|
888
|
-
}
|
|
889
|
-
},
|
|
890
|
-
block: blockWithoutRepeat
|
|
891
|
-
}));
|
|
892
|
-
return repeatArray;
|
|
893
|
-
};
|
|
894
|
-
var provideLinkComponent = (block, linkComponent) => {
|
|
895
|
-
if (block?.shouldReceiveBuilderProps?.builderLinkComponent)
|
|
896
|
-
return {
|
|
897
|
-
builderLinkComponent: linkComponent
|
|
898
|
-
};
|
|
899
|
-
return {};
|
|
900
|
-
};
|
|
901
|
-
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
902
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
903
|
-
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
904
|
-
return !checkIsComponentRestricted(component, model);
|
|
905
|
-
}));
|
|
906
|
-
return {
|
|
907
|
-
builderComponents: filteredRegisteredComponents
|
|
908
|
-
};
|
|
909
|
-
}
|
|
910
|
-
return {};
|
|
911
|
-
};
|
|
912
|
-
var provideBuilderBlock = (block, builderBlock) => {
|
|
913
|
-
if (block?.shouldReceiveBuilderProps?.builderBlock)
|
|
914
|
-
return {
|
|
915
|
-
builderBlock
|
|
916
|
-
};
|
|
917
|
-
return {};
|
|
918
|
-
};
|
|
919
|
-
var provideBuilderContext = (block, context) => {
|
|
920
|
-
if (block?.shouldReceiveBuilderProps?.builderContext)
|
|
921
|
-
return {
|
|
922
|
-
builderContext: context
|
|
923
|
-
};
|
|
924
|
-
return {};
|
|
925
|
-
};
|
|
926
|
-
var generateKey = (index) => {
|
|
927
|
-
return index.toString();
|
|
928
|
-
};
|
|
929
|
-
|
|
930
|
-
// src/functions/event-handler-name.ts
|
|
931
|
-
function capitalizeFirstLetter(string) {
|
|
932
|
-
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
933
|
-
}
|
|
934
|
-
var getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
|
|
935
|
-
|
|
936
|
-
// src/functions/get-block-actions-handler.ts
|
|
937
|
-
var createEventHandler = (value, options) => (event) => evaluate({
|
|
938
|
-
code: value,
|
|
939
|
-
context: options.context,
|
|
940
|
-
localState: options.localState,
|
|
941
|
-
rootState: options.rootState,
|
|
942
|
-
rootSetState: options.rootSetState,
|
|
943
|
-
event,
|
|
944
|
-
isExpression: false
|
|
945
|
-
});
|
|
946
|
-
|
|
947
|
-
// src/functions/get-block-actions.ts
|
|
948
|
-
function getBlockActions(options) {
|
|
949
|
-
const obj = {};
|
|
950
|
-
const optionActions = options.block.actions ?? {};
|
|
951
|
-
for (const key in optionActions) {
|
|
952
|
-
if (!optionActions.hasOwnProperty(key)) {
|
|
953
|
-
continue;
|
|
954
|
-
}
|
|
955
|
-
const value = optionActions[key];
|
|
956
|
-
let eventHandlerName = getEventHandlerName(key);
|
|
957
|
-
if (options.stripPrefix) {
|
|
958
|
-
switch (TARGET) {
|
|
959
|
-
case "vue":
|
|
960
|
-
eventHandlerName = eventHandlerName.replace("v-on:", "");
|
|
961
|
-
break;
|
|
962
|
-
case "svelte":
|
|
963
|
-
eventHandlerName = eventHandlerName.replace("on:", "");
|
|
964
|
-
break;
|
|
965
|
-
}
|
|
966
|
-
}
|
|
967
|
-
obj[eventHandlerName] = createEventHandler(value, options);
|
|
968
|
-
}
|
|
969
|
-
return obj;
|
|
970
|
-
}
|
|
971
|
-
|
|
972
|
-
// src/functions/transform-block-properties.ts
|
|
973
|
-
function transformBlockProperties({
|
|
974
|
-
properties
|
|
975
|
-
}) {
|
|
976
|
-
return properties;
|
|
977
|
-
}
|
|
978
|
-
|
|
979
|
-
// src/functions/get-block-properties.ts
|
|
980
|
-
var extractRelevantRootBlockProperties = (block) => {
|
|
981
|
-
return {
|
|
982
|
-
href: block.href
|
|
983
|
-
};
|
|
984
|
-
};
|
|
985
|
-
function getBlockProperties({
|
|
986
|
-
block,
|
|
987
|
-
context
|
|
988
|
-
}) {
|
|
989
|
-
const properties = {
|
|
990
|
-
...extractRelevantRootBlockProperties(block),
|
|
991
|
-
...block.properties,
|
|
992
|
-
"builder-id": block.id,
|
|
993
|
-
style: getStyle({
|
|
994
|
-
block,
|
|
995
|
-
context
|
|
996
|
-
}),
|
|
997
|
-
[getClassPropName()]: [block.id, "builder-block", block.class, block.properties?.class].filter(Boolean).join(" ")
|
|
998
|
-
};
|
|
999
|
-
return transformBlockProperties({
|
|
1000
|
-
properties,
|
|
1001
|
-
context,
|
|
1002
|
-
block
|
|
1003
|
-
});
|
|
1004
|
-
}
|
|
1005
|
-
|
|
1006
|
-
// src/components/block/components/block-wrapper.tsx
|
|
1007
|
-
function BlockWrapper(props) {
|
|
1008
|
-
return <><Dynamic_renderer_default
|
|
1009
|
-
TagName={props.Wrapper}
|
|
1010
|
-
attributes={getBlockProperties({
|
|
1011
|
-
block: props.block,
|
|
1012
|
-
context: props.context
|
|
1013
|
-
})}
|
|
1014
|
-
actionAttributes={getBlockActions({
|
|
1015
|
-
block: props.block,
|
|
1016
|
-
rootState: props.context.rootState,
|
|
1017
|
-
rootSetState: props.context.rootSetState,
|
|
1018
|
-
localState: props.context.localState,
|
|
1019
|
-
context: props.context.context,
|
|
1020
|
-
stripPrefix: true
|
|
1021
|
-
})}
|
|
1022
|
-
>{props.children}</Dynamic_renderer_default></>;
|
|
1023
|
-
}
|
|
1024
|
-
var Block_wrapper_default = BlockWrapper;
|
|
1025
|
-
|
|
1026
|
-
// src/components/block/components/component-ref/component-ref.tsx
|
|
1027
|
-
import { Show as Show3, For, createSignal as createSignal3 } from "solid-js";
|
|
1028
|
-
import { Dynamic as Dynamic4 } from "solid-js/web";
|
|
1029
|
-
|
|
1030
|
-
// src/components/block/components/interactive-element.tsx
|
|
1031
|
-
import { Show as Show2, on, createEffect, createMemo as createMemo2, createSignal as createSignal2 } from "solid-js";
|
|
1032
|
-
import { Dynamic as Dynamic3 } from "solid-js/web";
|
|
1033
|
-
|
|
1034
|
-
// src/functions/is-previewing.ts
|
|
1035
|
-
function isPreviewing(search) {
|
|
1036
|
-
const searchToUse = search || (isBrowser() ? window.location.search : void 0);
|
|
1037
|
-
if (!searchToUse) {
|
|
1038
|
-
return false;
|
|
1039
|
-
}
|
|
1040
|
-
const normalizedSearch = getSearchString(searchToUse);
|
|
1041
|
-
return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
|
|
1042
|
-
}
|
|
1043
|
-
|
|
1044
|
-
// src/functions/register-component.ts
|
|
1045
|
-
var createRegisterComponentMessage = (info) => ({
|
|
1046
|
-
type: "builder.registerComponent",
|
|
1047
|
-
data: serializeIncludingFunctions(info)
|
|
1048
|
-
});
|
|
1049
|
-
var serializeFn = (fnValue) => {
|
|
1050
|
-
const fnStr = fnValue.toString().trim();
|
|
1051
|
-
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
1052
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
1053
|
-
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
1054
|
-
};
|
|
1055
|
-
function serializeIncludingFunctions(info) {
|
|
1056
|
-
return JSON.parse(JSON.stringify(info, (key, value) => {
|
|
1057
|
-
if (typeof value === "function") {
|
|
1058
|
-
return serializeFn(value);
|
|
1059
|
-
}
|
|
1060
|
-
return value;
|
|
1061
|
-
}));
|
|
1062
|
-
}
|
|
1063
|
-
|
|
1064
|
-
// src/functions/register.ts
|
|
1065
|
-
var registry = {};
|
|
1066
|
-
function register(type, info) {
|
|
1067
|
-
if (type === "plugin") {
|
|
1068
|
-
info = serializeIncludingFunctions(info);
|
|
1069
|
-
}
|
|
1070
|
-
let typeList = registry[type];
|
|
1071
|
-
if (!typeList) {
|
|
1072
|
-
typeList = registry[type] = [];
|
|
1073
|
-
}
|
|
1074
|
-
typeList.push(info);
|
|
1075
|
-
if (isBrowser()) {
|
|
1076
|
-
const message = {
|
|
1077
|
-
type: "builder.register",
|
|
1078
|
-
data: {
|
|
1079
|
-
type,
|
|
1080
|
-
info
|
|
1081
|
-
}
|
|
1082
|
-
};
|
|
1083
|
-
try {
|
|
1084
|
-
parent.postMessage(message, "*");
|
|
1085
|
-
if (parent !== window) {
|
|
1086
|
-
window.postMessage(message, "*");
|
|
1087
|
-
}
|
|
1088
|
-
} catch (err) {
|
|
1089
|
-
}
|
|
1090
|
-
}
|
|
1091
|
-
}
|
|
1092
|
-
function registerAction(action) {
|
|
1093
|
-
if (isBrowser()) {
|
|
1094
|
-
const actionClone = JSON.parse(JSON.stringify(action));
|
|
1095
|
-
if (action.action) {
|
|
1096
|
-
actionClone.action = action.action.toString();
|
|
1097
|
-
}
|
|
1098
|
-
window.parent?.postMessage({
|
|
1099
|
-
type: "builder.registerAction",
|
|
1100
|
-
data: actionClone
|
|
1101
|
-
}, "*");
|
|
1102
|
-
}
|
|
1103
|
-
}
|
|
1104
|
-
|
|
1105
|
-
// src/functions/set-editor-settings.ts
|
|
1106
|
-
var settings = {};
|
|
1107
|
-
function setEditorSettings(newSettings) {
|
|
1108
|
-
if (isBrowser()) {
|
|
1109
|
-
Object.assign(settings, newSettings);
|
|
1110
|
-
const message = {
|
|
1111
|
-
type: "builder.settingsChange",
|
|
1112
|
-
data: settings
|
|
1113
|
-
};
|
|
1114
|
-
parent.postMessage(message, "*");
|
|
1115
|
-
}
|
|
1116
|
-
}
|
|
1117
|
-
|
|
1118
|
-
// src/functions/get-builder-search-params/index.ts
|
|
1119
|
-
var BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
1120
|
-
var BUILDER_OPTIONS_PREFIX = "options.";
|
|
1121
|
-
var getBuilderSearchParams = (_options) => {
|
|
1122
|
-
if (!_options) {
|
|
1123
|
-
return {};
|
|
1124
|
-
}
|
|
1125
|
-
const options = normalizeSearchParams(_options);
|
|
1126
|
-
const newOptions = {};
|
|
1127
|
-
Object.keys(options).forEach((key) => {
|
|
1128
|
-
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
1129
|
-
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
1130
|
-
newOptions[trimmedKey] = options[key];
|
|
1131
|
-
}
|
|
1132
|
-
});
|
|
1133
|
-
return newOptions;
|
|
1134
|
-
};
|
|
1135
|
-
var getBuilderSearchParamsFromWindow = () => {
|
|
1136
|
-
if (!isBrowser()) {
|
|
1137
|
-
return {};
|
|
1138
|
-
}
|
|
1139
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
1140
|
-
return getBuilderSearchParams(searchParams);
|
|
1141
|
-
};
|
|
1142
|
-
|
|
1143
|
-
// src/constants/sdk-version.ts
|
|
1144
|
-
var SDK_VERSION = "5.1.0";
|
|
1145
|
-
|
|
1146
|
-
// src/helpers/sdk-headers.ts
|
|
1147
|
-
var getSdkHeaders = () => ({
|
|
1148
|
-
"X-Builder-SDK": TARGET,
|
|
1149
|
-
"X-Builder-SDK-GEN": "2",
|
|
1150
|
-
"X-Builder-SDK-Version": SDK_VERSION
|
|
1151
|
-
});
|
|
1152
|
-
|
|
1153
|
-
// src/helpers/url.ts
|
|
1154
|
-
var getTopLevelDomain = (host) => {
|
|
1155
|
-
if (host === "localhost" || host === "127.0.0.1") {
|
|
1156
|
-
return host;
|
|
1157
|
-
}
|
|
1158
|
-
const parts = host.split(".");
|
|
1159
|
-
if (parts.length > 2) {
|
|
1160
|
-
return parts.slice(1).join(".");
|
|
1161
|
-
}
|
|
1162
|
-
return host;
|
|
1163
|
-
};
|
|
1164
|
-
|
|
1165
|
-
// src/helpers/cookie.ts
|
|
1166
|
-
var getCookieSync = ({
|
|
1167
|
-
name,
|
|
1168
|
-
canTrack
|
|
1169
|
-
}) => {
|
|
1170
|
-
try {
|
|
1171
|
-
if (!canTrack) {
|
|
1172
|
-
return void 0;
|
|
1173
|
-
}
|
|
1174
|
-
return document.cookie.split("; ").find((row) => row.startsWith(`${name}=`))?.split("=")[1];
|
|
1175
|
-
} catch (err) {
|
|
1176
|
-
logger.warn("[COOKIE] GET error: ", err?.message || err);
|
|
1177
|
-
return void 0;
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
1180
|
-
var getCookie = async (args) => getCookieSync(args);
|
|
1181
|
-
var stringifyCookie = (cookie) => cookie.map(([key, value]) => value ? `${key}=${value}` : key).filter(checkIsDefined).join("; ");
|
|
1182
|
-
var SECURE_CONFIG = [["secure", ""], ["SameSite", "None"]];
|
|
1183
|
-
var createCookieString = ({
|
|
1184
|
-
name,
|
|
1185
|
-
value,
|
|
1186
|
-
expires
|
|
1187
|
-
}) => {
|
|
1188
|
-
const secure = isBrowser() ? location.protocol === "https:" : true;
|
|
1189
|
-
const secureObj = secure ? SECURE_CONFIG : [[]];
|
|
1190
|
-
const expiresObj = expires ? [["expires", expires.toUTCString()]] : [[]];
|
|
1191
|
-
const cookieValue = [[name, value], ...expiresObj, ["path", "/"], ["domain", getTopLevelDomain(window.location.hostname)], ...secureObj];
|
|
1192
|
-
const cookie = stringifyCookie(cookieValue);
|
|
1193
|
-
return cookie;
|
|
1194
|
-
};
|
|
1195
|
-
var setCookie = async ({
|
|
1196
|
-
name,
|
|
1197
|
-
value,
|
|
1198
|
-
expires,
|
|
1199
|
-
canTrack
|
|
1200
|
-
}) => {
|
|
1201
|
-
try {
|
|
1202
|
-
if (!canTrack) {
|
|
1203
|
-
return;
|
|
1204
|
-
}
|
|
1205
|
-
const cookie = createCookieString({
|
|
1206
|
-
name,
|
|
1207
|
-
value,
|
|
1208
|
-
expires
|
|
1040
|
+
}
|
|
1041
|
+
attachDefaultState();
|
|
1042
|
+
setTimeout(() => {
|
|
1043
|
+
element.style.transition = `all ${animation.duration}s ${camelToKebabCase(animation.easing)}`;
|
|
1044
|
+
if (animation.delay) {
|
|
1045
|
+
element.style.transitionDelay = animation.delay + "s";
|
|
1046
|
+
}
|
|
1209
1047
|
});
|
|
1210
|
-
document.
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
// src/helpers/uuid.ts
|
|
1217
|
-
function uuidv4() {
|
|
1218
|
-
return "xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g, function(c) {
|
|
1219
|
-
const r = Math.random() * 16 | 0, v = c == "x" ? r : r & 3 | 8;
|
|
1220
|
-
return v.toString(16);
|
|
1048
|
+
document.addEventListener("scroll", onScroll, {
|
|
1049
|
+
capture: true,
|
|
1050
|
+
passive: true
|
|
1051
|
+
});
|
|
1052
|
+
immediateOnScroll();
|
|
1221
1053
|
});
|
|
1222
1054
|
}
|
|
1223
|
-
function uuid() {
|
|
1224
|
-
return uuidv4().replace(/-/g, "");
|
|
1225
|
-
}
|
|
1226
1055
|
|
|
1227
|
-
// src/helpers/
|
|
1228
|
-
var
|
|
1229
|
-
|
|
1230
|
-
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
const sessionId = await getCookie({
|
|
1236
|
-
name: SESSION_LOCAL_STORAGE_KEY,
|
|
1237
|
-
canTrack
|
|
1056
|
+
// src/helpers/css.ts
|
|
1057
|
+
var convertStyleMapToCSSArray = (style) => {
|
|
1058
|
+
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
1059
|
+
if (typeof value === "string") {
|
|
1060
|
+
return `${camelToKebabCase(key)}: ${value};`;
|
|
1061
|
+
} else {
|
|
1062
|
+
return void 0;
|
|
1063
|
+
}
|
|
1238
1064
|
});
|
|
1239
|
-
|
|
1240
|
-
|
|
1065
|
+
return cssProps.filter(checkIsDefined);
|
|
1066
|
+
};
|
|
1067
|
+
var convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
|
|
1068
|
+
var createCssClass = ({
|
|
1069
|
+
mediaQuery,
|
|
1070
|
+
className,
|
|
1071
|
+
styles
|
|
1072
|
+
}) => {
|
|
1073
|
+
const cssClass = `.${className} {
|
|
1074
|
+
${convertStyleMapToCSS(styles)}
|
|
1075
|
+
}`;
|
|
1076
|
+
if (mediaQuery) {
|
|
1077
|
+
return `${mediaQuery} {
|
|
1078
|
+
${cssClass}
|
|
1079
|
+
}`;
|
|
1241
1080
|
} else {
|
|
1242
|
-
|
|
1243
|
-
setSessionId({
|
|
1244
|
-
id: newSessionId,
|
|
1245
|
-
canTrack
|
|
1246
|
-
});
|
|
1247
|
-
return newSessionId;
|
|
1081
|
+
return cssClass;
|
|
1248
1082
|
}
|
|
1249
1083
|
};
|
|
1250
|
-
var createSessionId = () => uuid();
|
|
1251
|
-
var setSessionId = ({
|
|
1252
|
-
id,
|
|
1253
|
-
canTrack
|
|
1254
|
-
}) => setCookie({
|
|
1255
|
-
name: SESSION_LOCAL_STORAGE_KEY,
|
|
1256
|
-
value: id,
|
|
1257
|
-
canTrack
|
|
1258
|
-
});
|
|
1259
1084
|
|
|
1260
|
-
// src/
|
|
1261
|
-
|
|
1262
|
-
|
|
1263
|
-
|
|
1264
|
-
|
|
1085
|
+
// src/functions/transform-style-property.ts
|
|
1086
|
+
function transformStyleProperty({
|
|
1087
|
+
style
|
|
1088
|
+
}) {
|
|
1089
|
+
return style;
|
|
1090
|
+
}
|
|
1091
|
+
|
|
1092
|
+
// src/functions/get-style.ts
|
|
1093
|
+
var getStyle = ({
|
|
1094
|
+
block,
|
|
1095
|
+
context
|
|
1265
1096
|
}) => {
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1097
|
+
return mapStyleObjToStrIfNeeded(transformStyleProperty({
|
|
1098
|
+
style: block.style || {},
|
|
1099
|
+
context,
|
|
1100
|
+
block
|
|
1101
|
+
}));
|
|
1102
|
+
};
|
|
1103
|
+
function mapStyleObjToStrIfNeeded(style) {
|
|
1104
|
+
switch (TARGET) {
|
|
1105
|
+
case "svelte":
|
|
1106
|
+
case "vue":
|
|
1107
|
+
case "solid":
|
|
1108
|
+
case "angular":
|
|
1109
|
+
return convertStyleMapToCSSArray(style).join(" ");
|
|
1110
|
+
case "qwik":
|
|
1111
|
+
case "reactNative":
|
|
1112
|
+
case "react":
|
|
1113
|
+
case "rsc":
|
|
1114
|
+
return style;
|
|
1273
1115
|
}
|
|
1116
|
+
}
|
|
1117
|
+
|
|
1118
|
+
// src/components/block/block.helpers.ts
|
|
1119
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
1120
|
+
if (!component)
|
|
1121
|
+
return true;
|
|
1122
|
+
if (!model)
|
|
1123
|
+
return false;
|
|
1124
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
1274
1125
|
};
|
|
1275
|
-
var
|
|
1276
|
-
|
|
1277
|
-
|
|
1278
|
-
|
|
1126
|
+
var getComponent = ({
|
|
1127
|
+
block,
|
|
1128
|
+
registeredComponents,
|
|
1129
|
+
model
|
|
1279
1130
|
}) => {
|
|
1280
|
-
|
|
1281
|
-
|
|
1282
|
-
|
|
1283
|
-
|
|
1284
|
-
|
|
1131
|
+
const componentName = block.component?.name;
|
|
1132
|
+
if (!componentName) {
|
|
1133
|
+
return null;
|
|
1134
|
+
}
|
|
1135
|
+
const ref = registeredComponents[componentName];
|
|
1136
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
1137
|
+
return void 0;
|
|
1138
|
+
} else {
|
|
1139
|
+
return ref;
|
|
1285
1140
|
}
|
|
1286
1141
|
};
|
|
1287
|
-
|
|
1288
|
-
|
|
1289
|
-
|
|
1290
|
-
var getVisitorId = ({
|
|
1291
|
-
canTrack
|
|
1142
|
+
var getRepeatItemData = ({
|
|
1143
|
+
block,
|
|
1144
|
+
context
|
|
1292
1145
|
}) => {
|
|
1293
|
-
|
|
1146
|
+
const {
|
|
1147
|
+
repeat,
|
|
1148
|
+
...blockWithoutRepeat
|
|
1149
|
+
} = block;
|
|
1150
|
+
if (!repeat?.collection) {
|
|
1294
1151
|
return void 0;
|
|
1295
1152
|
}
|
|
1296
|
-
const
|
|
1297
|
-
|
|
1298
|
-
|
|
1153
|
+
const itemsArray = evaluate({
|
|
1154
|
+
code: repeat.collection,
|
|
1155
|
+
localState: context.localState,
|
|
1156
|
+
rootState: context.rootState,
|
|
1157
|
+
rootSetState: context.rootSetState,
|
|
1158
|
+
context: context.context
|
|
1299
1159
|
});
|
|
1300
|
-
if (
|
|
1301
|
-
return
|
|
1302
|
-
}
|
|
1303
|
-
|
|
1304
|
-
|
|
1305
|
-
|
|
1306
|
-
|
|
1307
|
-
|
|
1308
|
-
|
|
1160
|
+
if (!Array.isArray(itemsArray)) {
|
|
1161
|
+
return void 0;
|
|
1162
|
+
}
|
|
1163
|
+
const collectionName = repeat.collection.split(".").pop();
|
|
1164
|
+
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
1165
|
+
const repeatArray = itemsArray.map((item, index) => ({
|
|
1166
|
+
context: {
|
|
1167
|
+
...context,
|
|
1168
|
+
localState: {
|
|
1169
|
+
...context.localState,
|
|
1170
|
+
$index: index,
|
|
1171
|
+
$item: item,
|
|
1172
|
+
[itemNameToUse]: item,
|
|
1173
|
+
[`$${itemNameToUse}Index`]: index
|
|
1174
|
+
}
|
|
1175
|
+
},
|
|
1176
|
+
block: blockWithoutRepeat
|
|
1177
|
+
}));
|
|
1178
|
+
return repeatArray;
|
|
1179
|
+
};
|
|
1180
|
+
var provideLinkComponent = (block, linkComponent) => {
|
|
1181
|
+
if (block?.shouldReceiveBuilderProps?.builderLinkComponent)
|
|
1182
|
+
return {
|
|
1183
|
+
builderLinkComponent: linkComponent
|
|
1184
|
+
};
|
|
1185
|
+
return {};
|
|
1186
|
+
};
|
|
1187
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
1188
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
1189
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
1190
|
+
return !checkIsComponentRestricted(component, model);
|
|
1191
|
+
}));
|
|
1192
|
+
return {
|
|
1193
|
+
builderComponents: filteredRegisteredComponents
|
|
1194
|
+
};
|
|
1309
1195
|
}
|
|
1196
|
+
return {};
|
|
1310
1197
|
};
|
|
1311
|
-
var
|
|
1312
|
-
|
|
1313
|
-
|
|
1314
|
-
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
|
-
|
|
1318
|
-
|
|
1198
|
+
var provideBuilderBlock = (block, builderBlock) => {
|
|
1199
|
+
if (block?.shouldReceiveBuilderProps?.builderBlock)
|
|
1200
|
+
return {
|
|
1201
|
+
builderBlock
|
|
1202
|
+
};
|
|
1203
|
+
return {};
|
|
1204
|
+
};
|
|
1205
|
+
var provideBuilderContext = (block, context) => {
|
|
1206
|
+
if (block?.shouldReceiveBuilderProps?.builderContext)
|
|
1207
|
+
return {
|
|
1208
|
+
builderContext: context
|
|
1209
|
+
};
|
|
1210
|
+
return {};
|
|
1211
|
+
};
|
|
1212
|
+
var generateKey = (index) => {
|
|
1213
|
+
return index.toString();
|
|
1214
|
+
};
|
|
1215
|
+
|
|
1216
|
+
// src/functions/event-handler-name.ts
|
|
1217
|
+
function capitalizeFirstLetter(string) {
|
|
1218
|
+
return string.charAt(0).toUpperCase() + string.slice(1);
|
|
1219
|
+
}
|
|
1220
|
+
var getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
|
|
1221
|
+
|
|
1222
|
+
// src/functions/get-block-actions-handler.ts
|
|
1223
|
+
var createEventHandler = (value, options) => (event) => evaluate({
|
|
1224
|
+
code: value,
|
|
1225
|
+
context: options.context,
|
|
1226
|
+
localState: options.localState,
|
|
1227
|
+
rootState: options.rootState,
|
|
1228
|
+
rootSetState: options.rootSetState,
|
|
1229
|
+
event,
|
|
1230
|
+
isExpression: false,
|
|
1231
|
+
trackingContext: options.trackingContext
|
|
1319
1232
|
});
|
|
1320
1233
|
|
|
1321
|
-
// src/functions/
|
|
1322
|
-
function
|
|
1323
|
-
|
|
1324
|
-
|
|
1325
|
-
|
|
1234
|
+
// src/functions/get-block-actions.ts
|
|
1235
|
+
function getBlockActions(options) {
|
|
1236
|
+
const obj = {};
|
|
1237
|
+
const optionActions = options.block.actions ?? {};
|
|
1238
|
+
for (const key in optionActions) {
|
|
1239
|
+
if (!optionActions.hasOwnProperty(key)) {
|
|
1240
|
+
continue;
|
|
1241
|
+
}
|
|
1242
|
+
const value = optionActions[key];
|
|
1243
|
+
let eventHandlerName = getEventHandlerName(key);
|
|
1244
|
+
if (options.stripPrefix) {
|
|
1245
|
+
switch (TARGET) {
|
|
1246
|
+
case "vue":
|
|
1247
|
+
eventHandlerName = eventHandlerName.replace("v-on:", "");
|
|
1248
|
+
break;
|
|
1249
|
+
case "svelte":
|
|
1250
|
+
eventHandlerName = eventHandlerName.replace("on:", "");
|
|
1251
|
+
break;
|
|
1252
|
+
}
|
|
1326
1253
|
}
|
|
1254
|
+
obj[eventHandlerName] = createEventHandler(value, options);
|
|
1327
1255
|
}
|
|
1256
|
+
return obj;
|
|
1328
1257
|
}
|
|
1329
1258
|
|
|
1330
|
-
// src/functions/
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
})
|
|
1334
|
-
|
|
1335
|
-
|
|
1336
|
-
|
|
1337
|
-
|
|
1338
|
-
|
|
1339
|
-
}
|
|
1340
|
-
const sessionId = await getSessionId({
|
|
1341
|
-
canTrack
|
|
1342
|
-
});
|
|
1343
|
-
const visitorId = getVisitorId({
|
|
1344
|
-
canTrack
|
|
1345
|
-
});
|
|
1259
|
+
// src/functions/transform-block-properties.ts
|
|
1260
|
+
function transformBlockProperties({
|
|
1261
|
+
properties
|
|
1262
|
+
}) {
|
|
1263
|
+
return properties;
|
|
1264
|
+
}
|
|
1265
|
+
|
|
1266
|
+
// src/functions/get-block-properties.ts
|
|
1267
|
+
var extractRelevantRootBlockProperties = (block) => {
|
|
1346
1268
|
return {
|
|
1347
|
-
|
|
1348
|
-
visitorId
|
|
1269
|
+
href: block.href
|
|
1349
1270
|
};
|
|
1350
1271
|
};
|
|
1351
|
-
|
|
1352
|
-
|
|
1353
|
-
|
|
1354
|
-
|
|
1355
|
-
|
|
1356
|
-
|
|
1357
|
-
|
|
1358
|
-
|
|
1359
|
-
|
|
1360
|
-
|
|
1361
|
-
|
|
1362
|
-
url: location.href,
|
|
1363
|
-
...metadata
|
|
1364
|
-
},
|
|
1365
|
-
...await getTrackingEventData({
|
|
1366
|
-
canTrack
|
|
1272
|
+
function getBlockProperties({
|
|
1273
|
+
block,
|
|
1274
|
+
context
|
|
1275
|
+
}) {
|
|
1276
|
+
const properties = {
|
|
1277
|
+
...extractRelevantRootBlockProperties(block),
|
|
1278
|
+
...block.properties,
|
|
1279
|
+
"builder-id": block.id,
|
|
1280
|
+
style: getStyle({
|
|
1281
|
+
block,
|
|
1282
|
+
context
|
|
1367
1283
|
}),
|
|
1368
|
-
|
|
1369
|
-
|
|
1284
|
+
[getClassPropName()]: [block.id, "builder-block", block.class, block.properties?.class].filter(Boolean).join(" ")
|
|
1285
|
+
};
|
|
1286
|
+
return transformBlockProperties({
|
|
1287
|
+
properties,
|
|
1288
|
+
context,
|
|
1289
|
+
block
|
|
1290
|
+
});
|
|
1291
|
+
}
|
|
1292
|
+
|
|
1293
|
+
// src/components/block/components/block-wrapper.tsx
|
|
1294
|
+
function BlockWrapper(props) {
|
|
1295
|
+
return <><Dynamic_renderer_default
|
|
1296
|
+
TagName={props.Wrapper}
|
|
1297
|
+
attributes={getBlockProperties({
|
|
1298
|
+
block: props.block,
|
|
1299
|
+
context: props.context
|
|
1300
|
+
})}
|
|
1301
|
+
actionAttributes={getBlockActions({
|
|
1302
|
+
block: props.block,
|
|
1303
|
+
rootState: props.context.rootState,
|
|
1304
|
+
rootSetState: props.context.rootSetState,
|
|
1305
|
+
localState: props.context.localState,
|
|
1306
|
+
context: props.context.context,
|
|
1307
|
+
stripPrefix: true,
|
|
1308
|
+
trackingContext: {
|
|
1309
|
+
apiKey: props.context.apiKey,
|
|
1310
|
+
canTrack: props.context.canTrack ?? true,
|
|
1311
|
+
contentId: props.context.content?.id,
|
|
1312
|
+
variationId: props.context.content?.testVariationId
|
|
1313
|
+
}
|
|
1314
|
+
})}
|
|
1315
|
+
>{props.children}</Dynamic_renderer_default></>;
|
|
1316
|
+
}
|
|
1317
|
+
var Block_wrapper_default = BlockWrapper;
|
|
1318
|
+
|
|
1319
|
+
// src/components/block/components/component-ref/component-ref.tsx
|
|
1320
|
+
import { Show as Show3, For, createSignal as createSignal3 } from "solid-js";
|
|
1321
|
+
import { Dynamic as Dynamic4 } from "solid-js/web";
|
|
1322
|
+
|
|
1323
|
+
// src/components/block/components/interactive-element.tsx
|
|
1324
|
+
import { Show as Show2, on, createEffect, createMemo as createMemo2, createSignal as createSignal2 } from "solid-js";
|
|
1325
|
+
import { Dynamic as Dynamic3 } from "solid-js/web";
|
|
1326
|
+
|
|
1327
|
+
// src/functions/is-previewing.ts
|
|
1328
|
+
function isPreviewing(search) {
|
|
1329
|
+
const searchToUse = search || (isBrowser() ? window.location.search : void 0);
|
|
1330
|
+
if (!searchToUse) {
|
|
1331
|
+
return false;
|
|
1370
1332
|
}
|
|
1333
|
+
const normalizedSearch = getSearchString(searchToUse);
|
|
1334
|
+
return Boolean(normalizedSearch.indexOf("builder.preview=") !== -1);
|
|
1335
|
+
}
|
|
1336
|
+
|
|
1337
|
+
// src/functions/register-component.ts
|
|
1338
|
+
var createRegisterComponentMessage = (info) => ({
|
|
1339
|
+
type: "builder.registerComponent",
|
|
1340
|
+
data: serializeIncludingFunctions(info)
|
|
1371
1341
|
});
|
|
1372
|
-
|
|
1373
|
-
|
|
1374
|
-
|
|
1375
|
-
|
|
1376
|
-
|
|
1377
|
-
|
|
1378
|
-
|
|
1342
|
+
var serializeFn = (fnValue) => {
|
|
1343
|
+
const fnStr = fnValue.toString().trim();
|
|
1344
|
+
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
1345
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
1346
|
+
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
1347
|
+
};
|
|
1348
|
+
function serializeIncludingFunctions(info) {
|
|
1349
|
+
return JSON.parse(JSON.stringify(info, (key, value) => {
|
|
1350
|
+
if (typeof value === "function") {
|
|
1351
|
+
return serializeFn(value);
|
|
1352
|
+
}
|
|
1353
|
+
return value;
|
|
1354
|
+
}));
|
|
1355
|
+
}
|
|
1356
|
+
|
|
1357
|
+
// src/functions/register.ts
|
|
1358
|
+
var registry = {};
|
|
1359
|
+
function register(type, info) {
|
|
1360
|
+
if (type === "plugin") {
|
|
1361
|
+
info = serializeIncludingFunctions(info);
|
|
1379
1362
|
}
|
|
1380
|
-
|
|
1381
|
-
|
|
1363
|
+
let typeList = registry[type];
|
|
1364
|
+
if (!typeList) {
|
|
1365
|
+
typeList = registry[type] = [];
|
|
1382
1366
|
}
|
|
1383
|
-
|
|
1384
|
-
|
|
1367
|
+
typeList.push(info);
|
|
1368
|
+
if (isBrowser()) {
|
|
1369
|
+
const message = {
|
|
1370
|
+
type: "builder.register",
|
|
1371
|
+
data: {
|
|
1372
|
+
type,
|
|
1373
|
+
info
|
|
1374
|
+
}
|
|
1375
|
+
};
|
|
1376
|
+
try {
|
|
1377
|
+
parent.postMessage(message, "*");
|
|
1378
|
+
if (parent !== window) {
|
|
1379
|
+
window.postMessage(message, "*");
|
|
1380
|
+
}
|
|
1381
|
+
} catch (err) {
|
|
1382
|
+
}
|
|
1385
1383
|
}
|
|
1386
|
-
|
|
1387
|
-
|
|
1384
|
+
}
|
|
1385
|
+
function registerAction(action) {
|
|
1386
|
+
if (isBrowser()) {
|
|
1387
|
+
const actionClone = JSON.parse(JSON.stringify(action));
|
|
1388
|
+
if (action.action) {
|
|
1389
|
+
actionClone.action = action.action.toString();
|
|
1390
|
+
}
|
|
1391
|
+
window.parent?.postMessage({
|
|
1392
|
+
type: "builder.registerAction",
|
|
1393
|
+
data: actionClone
|
|
1394
|
+
}, "*");
|
|
1388
1395
|
}
|
|
1389
|
-
const baseUrl = apiHost || "https://cdn.builder.io";
|
|
1390
|
-
const url = `${baseUrl}/api/v1/track`;
|
|
1391
|
-
logFetch(url);
|
|
1392
|
-
return fetch(url, {
|
|
1393
|
-
method: "POST",
|
|
1394
|
-
body: JSON.stringify({
|
|
1395
|
-
events: [await createEvent(eventProps)]
|
|
1396
|
-
}),
|
|
1397
|
-
headers: {
|
|
1398
|
-
"content-type": "application/json",
|
|
1399
|
-
...getSdkHeaders()
|
|
1400
|
-
},
|
|
1401
|
-
mode: "cors"
|
|
1402
|
-
}).catch((err) => {
|
|
1403
|
-
});
|
|
1404
1396
|
}
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
|
|
1408
|
-
|
|
1397
|
+
|
|
1398
|
+
// src/functions/set-editor-settings.ts
|
|
1399
|
+
var settings = {};
|
|
1400
|
+
function setEditorSettings(newSettings) {
|
|
1401
|
+
if (isBrowser()) {
|
|
1402
|
+
Object.assign(settings, newSettings);
|
|
1403
|
+
const message = {
|
|
1404
|
+
type: "builder.settingsChange",
|
|
1405
|
+
data: settings
|
|
1406
|
+
};
|
|
1407
|
+
parent.postMessage(message, "*");
|
|
1408
|
+
}
|
|
1409
|
+
}
|
|
1410
|
+
|
|
1411
|
+
// src/functions/get-builder-search-params/index.ts
|
|
1412
|
+
var BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
1413
|
+
var BUILDER_OPTIONS_PREFIX = "options.";
|
|
1414
|
+
var getBuilderSearchParams = (_options) => {
|
|
1415
|
+
if (!_options) {
|
|
1416
|
+
return {};
|
|
1417
|
+
}
|
|
1418
|
+
const options = normalizeSearchParams(_options);
|
|
1419
|
+
const newOptions = {};
|
|
1420
|
+
Object.keys(options).forEach((key) => {
|
|
1421
|
+
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
1422
|
+
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
1423
|
+
newOptions[trimmedKey] = options[key];
|
|
1424
|
+
}
|
|
1425
|
+
});
|
|
1426
|
+
return newOptions;
|
|
1427
|
+
};
|
|
1428
|
+
var getBuilderSearchParamsFromWindow = () => {
|
|
1429
|
+
if (!isBrowser()) {
|
|
1430
|
+
return {};
|
|
1431
|
+
}
|
|
1432
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
1433
|
+
return getBuilderSearchParams(searchParams);
|
|
1434
|
+
};
|
|
1409
1435
|
|
|
1410
1436
|
// src/functions/is-from-trusted-host.ts
|
|
1411
1437
|
var DEFAULT_TRUSTED_HOSTS = ["*.beta.builder.io", "beta.builder.io", "builder.io", "localhost", "qa.builder.io"];
|
|
@@ -2147,7 +2173,13 @@ function InteractiveElement(props) {
|
|
|
2147
2173
|
rootState: props.context.rootState,
|
|
2148
2174
|
rootSetState: props.context.rootSetState,
|
|
2149
2175
|
localState: props.context.localState,
|
|
2150
|
-
context: props.context.context
|
|
2176
|
+
context: props.context.context,
|
|
2177
|
+
trackingContext: {
|
|
2178
|
+
apiKey: props.context.apiKey,
|
|
2179
|
+
canTrack: props.context.canTrack ?? true,
|
|
2180
|
+
contentId: props.context.content?.id,
|
|
2181
|
+
variationId: props.context.content?.testVariationId
|
|
2182
|
+
}
|
|
2151
2183
|
})
|
|
2152
2184
|
} : {};
|
|
2153
2185
|
});
|