@builder.io/sdk-solid 3.0.0 → 3.0.2
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/dist/index.d.ts +6 -1
- package/lib/browser/dev.js +227 -98
- package/lib/browser/dev.jsx +272 -142
- package/lib/browser/index.js +224 -98
- package/lib/browser/index.jsx +271 -142
- package/lib/edge/dev.js +228 -101
- package/lib/edge/dev.jsx +273 -145
- package/lib/edge/index.js +225 -101
- package/lib/edge/index.jsx +272 -145
- package/lib/node/dev.js +227 -98
- package/lib/node/dev.jsx +272 -142
- package/lib/node/index.js +224 -98
- package/lib/node/index.jsx +271 -142
- package/package.json +1 -1
package/lib/browser/index.js
CHANGED
|
@@ -114,27 +114,11 @@ var builder_context_default = createContext({
|
|
|
114
114
|
inheritedStyles: {},
|
|
115
115
|
BlocksWrapper: "div",
|
|
116
116
|
BlocksWrapperProps: {},
|
|
117
|
-
nonce: ""
|
|
117
|
+
nonce: "",
|
|
118
|
+
model: ""
|
|
118
119
|
});
|
|
119
120
|
var components_context_default = createContext({ registeredComponents: {} });
|
|
120
121
|
|
|
121
|
-
// src/functions/get-block-component-options.ts
|
|
122
|
-
function getBlockComponentOptions(block) {
|
|
123
|
-
return {
|
|
124
|
-
...block.component?.options,
|
|
125
|
-
...block.options
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
|
|
129
|
-
// src/helpers/omit.ts
|
|
130
|
-
function omit(obj, ...values) {
|
|
131
|
-
const newObject = Object.assign({}, obj);
|
|
132
|
-
for (const key of values) {
|
|
133
|
-
delete newObject[key];
|
|
134
|
-
}
|
|
135
|
-
return newObject;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
122
|
// src/helpers/logger.ts
|
|
139
123
|
var logger = {
|
|
140
124
|
log: (...message) => void 0,
|
|
@@ -399,6 +383,106 @@ function evaluate({
|
|
|
399
383
|
}
|
|
400
384
|
}
|
|
401
385
|
|
|
386
|
+
// src/functions/get-block-component-options.ts
|
|
387
|
+
function getBlockComponentOptions(block, context) {
|
|
388
|
+
return {
|
|
389
|
+
...block.component?.options,
|
|
390
|
+
...block.options,
|
|
391
|
+
...evaluateTextComponentTextOption(block, context)
|
|
392
|
+
};
|
|
393
|
+
}
|
|
394
|
+
var evaluateTextComponentTextOption = (block, context) => {
|
|
395
|
+
if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
|
|
396
|
+
return {
|
|
397
|
+
...block.component.options,
|
|
398
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
399
|
+
code: group,
|
|
400
|
+
context,
|
|
401
|
+
localState: context.localState,
|
|
402
|
+
rootState: context.rootState,
|
|
403
|
+
rootSetState: context.rootSetState
|
|
404
|
+
}))
|
|
405
|
+
};
|
|
406
|
+
}
|
|
407
|
+
};
|
|
408
|
+
|
|
409
|
+
// src/helpers/omit.ts
|
|
410
|
+
function omit(obj, ...values) {
|
|
411
|
+
const newObject = Object.assign({}, obj);
|
|
412
|
+
for (const key of values) {
|
|
413
|
+
delete newObject[key];
|
|
414
|
+
}
|
|
415
|
+
return newObject;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
// src/functions/traverse.ts
|
|
419
|
+
function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
420
|
+
if (obj == null || typeof obj !== "object") {
|
|
421
|
+
callback(obj, (newValue) => {
|
|
422
|
+
if (parent2 !== null && key !== null) {
|
|
423
|
+
parent2[key] = newValue;
|
|
424
|
+
}
|
|
425
|
+
});
|
|
426
|
+
return;
|
|
427
|
+
}
|
|
428
|
+
if (visited.has(obj)) {
|
|
429
|
+
return;
|
|
430
|
+
}
|
|
431
|
+
visited.add(obj);
|
|
432
|
+
if (Array.isArray(obj)) {
|
|
433
|
+
obj.forEach((item, index) => {
|
|
434
|
+
const update = (newValue) => {
|
|
435
|
+
obj[index] = newValue;
|
|
436
|
+
};
|
|
437
|
+
callback(item, update);
|
|
438
|
+
traverse(item, callback, obj, index, visited);
|
|
439
|
+
});
|
|
440
|
+
} else {
|
|
441
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
442
|
+
const update = (newValue) => {
|
|
443
|
+
obj[key2] = newValue;
|
|
444
|
+
};
|
|
445
|
+
callback(value, update);
|
|
446
|
+
traverse(value, callback, obj, key2, visited);
|
|
447
|
+
});
|
|
448
|
+
}
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
// src/functions/extract-localized-values.ts
|
|
452
|
+
function isLocalizedField(value) {
|
|
453
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
454
|
+
}
|
|
455
|
+
function containsLocalizedValues(data) {
|
|
456
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
457
|
+
return false;
|
|
458
|
+
}
|
|
459
|
+
let hasLocalizedValues = false;
|
|
460
|
+
traverse(data, (value) => {
|
|
461
|
+
if (isLocalizedField(value)) {
|
|
462
|
+
hasLocalizedValues = true;
|
|
463
|
+
return;
|
|
464
|
+
}
|
|
465
|
+
});
|
|
466
|
+
return hasLocalizedValues;
|
|
467
|
+
}
|
|
468
|
+
function extractLocalizedValues(data, locale) {
|
|
469
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
470
|
+
return {};
|
|
471
|
+
}
|
|
472
|
+
traverse(data, (value, update) => {
|
|
473
|
+
if (isLocalizedField(value)) {
|
|
474
|
+
update(value[locale] ?? void 0);
|
|
475
|
+
}
|
|
476
|
+
});
|
|
477
|
+
return data;
|
|
478
|
+
}
|
|
479
|
+
function resolveLocalizedValues(block, locale) {
|
|
480
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
481
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
482
|
+
}
|
|
483
|
+
return block;
|
|
484
|
+
}
|
|
485
|
+
|
|
402
486
|
// src/functions/fast-clone.ts
|
|
403
487
|
var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
404
488
|
|
|
@@ -492,23 +576,19 @@ var evaluateBindings = ({
|
|
|
492
576
|
function getProcessedBlock({
|
|
493
577
|
block,
|
|
494
578
|
context,
|
|
495
|
-
shouldEvaluateBindings,
|
|
496
579
|
localState,
|
|
497
580
|
rootState,
|
|
498
581
|
rootSetState
|
|
499
582
|
}) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
} else {
|
|
510
|
-
return transformedBlock;
|
|
511
|
-
}
|
|
583
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
584
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
585
|
+
return evaluateBindings({
|
|
586
|
+
block: transformedBlock,
|
|
587
|
+
localState,
|
|
588
|
+
rootState,
|
|
589
|
+
rootSetState,
|
|
590
|
+
context
|
|
591
|
+
});
|
|
512
592
|
}
|
|
513
593
|
|
|
514
594
|
// src/functions/camel-to-kebab-case.ts
|
|
@@ -754,16 +834,24 @@ function mapStyleObjToStrIfNeeded(style) {
|
|
|
754
834
|
}
|
|
755
835
|
|
|
756
836
|
// src/components/block/block.helpers.ts
|
|
837
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
838
|
+
if (!component)
|
|
839
|
+
return true;
|
|
840
|
+
if (!model)
|
|
841
|
+
return false;
|
|
842
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
843
|
+
};
|
|
757
844
|
var getComponent = ({
|
|
758
845
|
block,
|
|
759
|
-
registeredComponents
|
|
846
|
+
registeredComponents,
|
|
847
|
+
model
|
|
760
848
|
}) => {
|
|
761
849
|
const componentName = block.component?.name;
|
|
762
850
|
if (!componentName) {
|
|
763
851
|
return null;
|
|
764
852
|
}
|
|
765
853
|
const ref = registeredComponents[componentName];
|
|
766
|
-
if (!ref) {
|
|
854
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
767
855
|
return void 0;
|
|
768
856
|
} else {
|
|
769
857
|
return ref;
|
|
@@ -814,11 +902,15 @@ var provideLinkComponent = (block, linkComponent) => {
|
|
|
814
902
|
};
|
|
815
903
|
return {};
|
|
816
904
|
};
|
|
817
|
-
var provideRegisteredComponents = (block, registeredComponents) => {
|
|
818
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
905
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
906
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
907
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
908
|
+
return !checkIsComponentRestricted(component, model);
|
|
909
|
+
}));
|
|
819
910
|
return {
|
|
820
|
-
builderComponents:
|
|
911
|
+
builderComponents: filteredRegisteredComponents
|
|
821
912
|
};
|
|
913
|
+
}
|
|
822
914
|
return {};
|
|
823
915
|
};
|
|
824
916
|
var provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -1272,15 +1364,15 @@ function Block(props) {
|
|
|
1272
1364
|
localState: props.context.localState,
|
|
1273
1365
|
rootState: props.context.rootState,
|
|
1274
1366
|
rootSetState: props.context.rootSetState,
|
|
1275
|
-
context: props.context.context
|
|
1276
|
-
shouldEvaluateBindings: true
|
|
1367
|
+
context: props.context.context
|
|
1277
1368
|
});
|
|
1278
1369
|
return blockToUse;
|
|
1279
1370
|
});
|
|
1280
1371
|
const blockComponent = createMemo(() => {
|
|
1281
1372
|
return getComponent({
|
|
1282
1373
|
block: processedBlock(),
|
|
1283
|
-
registeredComponents: props.registeredComponents
|
|
1374
|
+
registeredComponents: props.registeredComponents,
|
|
1375
|
+
model: props.context.model
|
|
1284
1376
|
});
|
|
1285
1377
|
});
|
|
1286
1378
|
const Tag = createMemo(() => {
|
|
@@ -1309,11 +1401,11 @@ function Block(props) {
|
|
|
1309
1401
|
blockChildren: processedBlock().children ?? [],
|
|
1310
1402
|
componentRef: blockComponent()?.component,
|
|
1311
1403
|
componentOptions: {
|
|
1312
|
-
...getBlockComponentOptions(processedBlock()),
|
|
1404
|
+
...getBlockComponentOptions(processedBlock(), props.context),
|
|
1313
1405
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
1314
1406
|
...provideBuilderContext(blockComponent(), props.context),
|
|
1315
1407
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
1316
|
-
...provideRegisteredComponents(blockComponent(), props.registeredComponents)
|
|
1408
|
+
...provideRegisteredComponents(blockComponent(), props.registeredComponents, props.context.model)
|
|
1317
1409
|
},
|
|
1318
1410
|
context: props.context,
|
|
1319
1411
|
linkComponent: props.linkComponent,
|
|
@@ -1911,16 +2003,16 @@ function getSrcSet(url) {
|
|
|
1911
2003
|
// src/blocks/image/image.tsx
|
|
1912
2004
|
var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
|
|
1913
2005
|
var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
|
|
1914
|
-
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-
|
|
1915
|
-
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-
|
|
1916
|
-
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-
|
|
2006
|
+
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-070d7e88">`);
|
|
2007
|
+
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-070d7e88-2>`);
|
|
2008
|
+
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-070d7e88 {
|
|
1917
2009
|
opacity: 1;
|
|
1918
2010
|
transition: opacity 0.2s ease-in-out;
|
|
1919
|
-
}.div-
|
|
2011
|
+
}.div-070d7e88 {
|
|
1920
2012
|
width: 100%;
|
|
1921
2013
|
pointer-events: none;
|
|
1922
2014
|
font-size: 0;
|
|
1923
|
-
}.div-
|
|
2015
|
+
}.div-070d7e88-2 {
|
|
1924
2016
|
display: flex;
|
|
1925
2017
|
flex-direction: column;
|
|
1926
2018
|
align-items: stretch;
|
|
@@ -1936,7 +2028,7 @@ function Image(props) {
|
|
|
1936
2028
|
const url = imageToUse;
|
|
1937
2029
|
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
1938
2030
|
// images, otherwise you can supply this prop manually
|
|
1939
|
-
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
2031
|
+
!(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
1940
2032
|
return props.srcset;
|
|
1941
2033
|
}
|
|
1942
2034
|
if (props.noWebp) {
|
|
@@ -1984,7 +2076,7 @@ function Image(props) {
|
|
|
1984
2076
|
}
|
|
1985
2077
|
}), _el$3);
|
|
1986
2078
|
effect((_p$) => {
|
|
1987
|
-
const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-
|
|
2079
|
+
const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88", _v$2 = props.highPriority ? "eager" : "lazy", _v$3 = props.highPriority ? "high" : "auto", _v$4 = props.altText, _v$5 = props.altText ? void 0 : "presentation", _v$6 = {
|
|
1988
2080
|
"object-position": props.backgroundPosition || "center",
|
|
1989
2081
|
"object-fit": props.backgroundSize || "cover",
|
|
1990
2082
|
...aspectRatioCss()
|
|
@@ -2850,6 +2942,10 @@ var componentInfo4 = {
|
|
|
2850
2942
|
noWrap: true
|
|
2851
2943
|
};
|
|
2852
2944
|
|
|
2945
|
+
// src/constants/file-types.ts
|
|
2946
|
+
var IMAGE_FILE_TYPES = ["jpeg", "jpg", "png", "svg", "webp", "gif", "jfif", "pjpeg", "pjp", "apng", "avif", "tif", "tiff", "heif", "bmp", "eps", "raw", "cr2", "nef", "orf", "sr2", "psd", "heic", "dib", "ai"];
|
|
2947
|
+
var VIDEO_FILE_TYPES = ["mp4", "webm", "mkv", "flv", "vob", "ogv", "ogg", "drc", "gif", "gifv", "mng", "avi", "mov", "qt", "mts", "m2ts", "ts", "wmv", "yuv", "rm", "rmvb", "viv", "asf", "amv", "m4p", "mpeg", "mpe", "m2v", "m4v", "svi", "3gp", "3g2", "mxf", "roq", "nsv", "f4v", "f4p", "f4a", "f4b"];
|
|
2948
|
+
|
|
2853
2949
|
// src/blocks/image/component-info.ts
|
|
2854
2950
|
var componentInfo5 = {
|
|
2855
2951
|
name: "Image",
|
|
@@ -2866,7 +2962,7 @@ var componentInfo5 = {
|
|
|
2866
2962
|
name: "image",
|
|
2867
2963
|
type: "file",
|
|
2868
2964
|
bubble: true,
|
|
2869
|
-
allowedFileTypes:
|
|
2965
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
2870
2966
|
required: true,
|
|
2871
2967
|
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
|
|
2872
2968
|
onChange: (options) => {
|
|
@@ -3383,26 +3479,10 @@ var componentInfo10 = {
|
|
|
3383
3479
|
};
|
|
3384
3480
|
var _tmpl$10 = /* @__PURE__ */ template(`<div class=builder-text>`);
|
|
3385
3481
|
function Text(props) {
|
|
3386
|
-
const processedText = createMemo(() => {
|
|
3387
|
-
const context = props.builderContext;
|
|
3388
|
-
const {
|
|
3389
|
-
context: contextContext,
|
|
3390
|
-
localState,
|
|
3391
|
-
rootState,
|
|
3392
|
-
rootSetState
|
|
3393
|
-
} = context;
|
|
3394
|
-
return String(props.text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
|
|
3395
|
-
code: group,
|
|
3396
|
-
context: contextContext,
|
|
3397
|
-
localState,
|
|
3398
|
-
rootState,
|
|
3399
|
-
rootSetState
|
|
3400
|
-
}));
|
|
3401
|
-
});
|
|
3402
3482
|
return (() => {
|
|
3403
3483
|
const _el$ = _tmpl$10();
|
|
3404
3484
|
_el$.style.setProperty("outline", "none");
|
|
3405
|
-
effect(() => _el$.innerHTML =
|
|
3485
|
+
effect(() => _el$.innerHTML = props.text?.toString() || "");
|
|
3406
3486
|
return _el$;
|
|
3407
3487
|
})();
|
|
3408
3488
|
}
|
|
@@ -4395,7 +4475,7 @@ var componentInfo18 = {
|
|
|
4395
4475
|
name: "image",
|
|
4396
4476
|
bubble: true,
|
|
4397
4477
|
type: "file",
|
|
4398
|
-
allowedFileTypes:
|
|
4478
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4399
4479
|
required: true
|
|
4400
4480
|
}],
|
|
4401
4481
|
noWrap: true,
|
|
@@ -4439,14 +4519,14 @@ var componentInfo19 = {
|
|
|
4439
4519
|
inputs: [{
|
|
4440
4520
|
name: "video",
|
|
4441
4521
|
type: "file",
|
|
4442
|
-
allowedFileTypes:
|
|
4522
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
4443
4523
|
bubble: true,
|
|
4444
4524
|
defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
|
|
4445
4525
|
required: true
|
|
4446
4526
|
}, {
|
|
4447
4527
|
name: "posterImage",
|
|
4448
4528
|
type: "file",
|
|
4449
|
-
allowedFileTypes:
|
|
4529
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4450
4530
|
helperText: "Image to show before the video plays"
|
|
4451
4531
|
}, {
|
|
4452
4532
|
name: "autoPlay",
|
|
@@ -4702,7 +4782,7 @@ var createRegisterComponentMessage = (info) => ({
|
|
|
4702
4782
|
var serializeFn = (fnValue) => {
|
|
4703
4783
|
const fnStr = fnValue.toString().trim();
|
|
4704
4784
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
4705
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4785
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4706
4786
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
4707
4787
|
};
|
|
4708
4788
|
function serializeIncludingFunctions(info) {
|
|
@@ -4785,7 +4865,7 @@ function getPreviewContent(_searchParams) {
|
|
|
4785
4865
|
}
|
|
4786
4866
|
|
|
4787
4867
|
// src/constants/sdk-version.ts
|
|
4788
|
-
var SDK_VERSION = "3.0.
|
|
4868
|
+
var SDK_VERSION = "3.0.2";
|
|
4789
4869
|
|
|
4790
4870
|
// src/helpers/sdk-headers.ts
|
|
4791
4871
|
var getSdkHeaders = () => ({
|
|
@@ -4848,6 +4928,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
|
|
|
4848
4928
|
}
|
|
4849
4929
|
return _res;
|
|
4850
4930
|
}
|
|
4931
|
+
function unflatten(obj) {
|
|
4932
|
+
const result = {};
|
|
4933
|
+
for (const key in obj) {
|
|
4934
|
+
const parts = key.split(".");
|
|
4935
|
+
let current = result;
|
|
4936
|
+
for (let i = 0; i < parts.length; i++) {
|
|
4937
|
+
const part = parts[i];
|
|
4938
|
+
if (i === parts.length - 1) {
|
|
4939
|
+
current[part] = obj[key];
|
|
4940
|
+
} else {
|
|
4941
|
+
current[part] = current[part] || {};
|
|
4942
|
+
current = current[part];
|
|
4943
|
+
}
|
|
4944
|
+
}
|
|
4945
|
+
}
|
|
4946
|
+
return result;
|
|
4947
|
+
}
|
|
4851
4948
|
|
|
4852
4949
|
// src/types/api-version.ts
|
|
4853
4950
|
var DEFAULT_API_VERSION = "v3";
|
|
@@ -4912,7 +5009,7 @@ var generateContentUrl = (options) => {
|
|
|
4912
5009
|
url.searchParams.set("noTraverse", String(noTraverse));
|
|
4913
5010
|
url.searchParams.set("includeRefs", String(true));
|
|
4914
5011
|
const finalLocale = locale || userAttributes?.locale;
|
|
4915
|
-
let finalUserAttributes = userAttributes;
|
|
5012
|
+
let finalUserAttributes = userAttributes || {};
|
|
4916
5013
|
if (finalLocale) {
|
|
4917
5014
|
url.searchParams.set("locale", finalLocale);
|
|
4918
5015
|
finalUserAttributes = {
|
|
@@ -4950,11 +5047,15 @@ var generateContentUrl = (options) => {
|
|
|
4950
5047
|
...getBuilderSearchParamsFromWindow(),
|
|
4951
5048
|
...normalizeSearchParams(options.options || {})
|
|
4952
5049
|
};
|
|
5050
|
+
finalUserAttributes = {
|
|
5051
|
+
...finalUserAttributes,
|
|
5052
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
5053
|
+
};
|
|
4953
5054
|
const flattened = flatten(queryOptions);
|
|
4954
5055
|
for (const key in flattened) {
|
|
4955
5056
|
url.searchParams.set(key, String(flattened[key]));
|
|
4956
5057
|
}
|
|
4957
|
-
if (finalUserAttributes) {
|
|
5058
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
4958
5059
|
url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
|
|
4959
5060
|
}
|
|
4960
5061
|
if (query) {
|
|
@@ -4967,6 +5068,28 @@ var generateContentUrl = (options) => {
|
|
|
4967
5068
|
}
|
|
4968
5069
|
return url;
|
|
4969
5070
|
};
|
|
5071
|
+
var getUserAttributesFromQueryOptions = (queryOptions) => {
|
|
5072
|
+
const newUserAttributes = {};
|
|
5073
|
+
for (const key in queryOptions) {
|
|
5074
|
+
if (key.startsWith("userAttributes.")) {
|
|
5075
|
+
newUserAttributes[key] = queryOptions[key];
|
|
5076
|
+
delete queryOptions[key];
|
|
5077
|
+
}
|
|
5078
|
+
}
|
|
5079
|
+
return newUserAttributes;
|
|
5080
|
+
};
|
|
5081
|
+
var getUserAttributesAsJSON = (queryOptions) => {
|
|
5082
|
+
if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
|
|
5083
|
+
queryOptions["userAttributes.urlPath"] = window.location.pathname;
|
|
5084
|
+
queryOptions["userAttributes.host"] = window.location.host;
|
|
5085
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
5086
|
+
const {
|
|
5087
|
+
userAttributes
|
|
5088
|
+
} = unflatten(queryOptionsForUserAttributes);
|
|
5089
|
+
return userAttributes;
|
|
5090
|
+
}
|
|
5091
|
+
return {};
|
|
5092
|
+
};
|
|
4970
5093
|
|
|
4971
5094
|
// src/functions/get-content/index.ts
|
|
4972
5095
|
var checkContentHasResults = (content) => "results" in content;
|
|
@@ -5497,6 +5620,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
5497
5620
|
};
|
|
5498
5621
|
};
|
|
5499
5622
|
|
|
5623
|
+
// src/components/content/components/enable-editor.helpers.ts
|
|
5624
|
+
var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
|
|
5625
|
+
var needsElementRefDivForEditing = () => {
|
|
5626
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
5627
|
+
};
|
|
5628
|
+
|
|
5500
5629
|
// src/components/content/components/styles.helpers.ts
|
|
5501
5630
|
var getCssFromFont = (font) => {
|
|
5502
5631
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -5731,8 +5860,10 @@ function EnableEditor(props) {
|
|
|
5731
5860
|
} : {}
|
|
5732
5861
|
});
|
|
5733
5862
|
Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
5734
|
-
|
|
5735
|
-
|
|
5863
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
5864
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
5865
|
+
window.parent?.postMessage(message, "*");
|
|
5866
|
+
}
|
|
5736
5867
|
});
|
|
5737
5868
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
5738
5869
|
}
|
|
@@ -5755,11 +5886,16 @@ function EnableEditor(props) {
|
|
|
5755
5886
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
5756
5887
|
const searchParamPreviewId = searchParams.get(`builder.overrides.${searchParamPreviewModel}`);
|
|
5757
5888
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
5758
|
-
if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
5889
|
+
if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
5759
5890
|
fetchOneEntry({
|
|
5760
|
-
model: props.model,
|
|
5891
|
+
model: props.model || "",
|
|
5761
5892
|
apiKey: props.apiKey,
|
|
5762
|
-
apiVersion: props.builderContextSignal.apiVersion
|
|
5893
|
+
apiVersion: props.builderContextSignal.apiVersion,
|
|
5894
|
+
...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
|
|
5895
|
+
query: {
|
|
5896
|
+
id: props.context.symbolId
|
|
5897
|
+
}
|
|
5898
|
+
} : {}
|
|
5763
5899
|
}).then((content) => {
|
|
5764
5900
|
if (content) {
|
|
5765
5901
|
mergeNewContent(content);
|
|
@@ -5804,7 +5940,7 @@ function EnableEditor(props) {
|
|
|
5804
5940
|
get children() {
|
|
5805
5941
|
return createComponent(Show, {
|
|
5806
5942
|
get when() {
|
|
5807
|
-
return props.builderContextSignal.content;
|
|
5943
|
+
return props.builderContextSignal.content || needsElementRefDivForEditing();
|
|
5808
5944
|
},
|
|
5809
5945
|
get children() {
|
|
5810
5946
|
return createComponent(Dynamic, mergeProps({
|
|
@@ -5822,6 +5958,11 @@ function EnableEditor(props) {
|
|
|
5822
5958
|
},
|
|
5823
5959
|
get ["builder-model"]() {
|
|
5824
5960
|
return props.model;
|
|
5961
|
+
},
|
|
5962
|
+
get style() {
|
|
5963
|
+
return {
|
|
5964
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
5965
|
+
};
|
|
5825
5966
|
}
|
|
5826
5967
|
}, {}, showContentProps, () => props.contentWrapperProps, {
|
|
5827
5968
|
get component() {
|
|
@@ -5904,15 +6045,7 @@ function ContentComponent(props) {
|
|
|
5904
6045
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
5905
6046
|
contentId: props.content?.id
|
|
5906
6047
|
}));
|
|
5907
|
-
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents
|
|
5908
|
-
models
|
|
5909
|
-
}) => {
|
|
5910
|
-
if (!models?.length)
|
|
5911
|
-
return true;
|
|
5912
|
-
if (!props.model)
|
|
5913
|
-
return true;
|
|
5914
|
-
return models.includes(props.model);
|
|
5915
|
-
}) || []].reduce((acc, {
|
|
6048
|
+
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
5916
6049
|
component,
|
|
5917
6050
|
...info
|
|
5918
6051
|
}) => ({
|
|
@@ -5938,15 +6071,7 @@ function ContentComponent(props) {
|
|
|
5938
6071
|
canTrack: props.canTrack,
|
|
5939
6072
|
apiKey: props.apiKey,
|
|
5940
6073
|
apiVersion: props.apiVersion,
|
|
5941
|
-
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents
|
|
5942
|
-
models
|
|
5943
|
-
}) => {
|
|
5944
|
-
if (!models?.length)
|
|
5945
|
-
return true;
|
|
5946
|
-
if (!props.model)
|
|
5947
|
-
return true;
|
|
5948
|
-
return models.includes(props.model);
|
|
5949
|
-
}) || []].reduce((acc, {
|
|
6074
|
+
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
5950
6075
|
component: _,
|
|
5951
6076
|
...info
|
|
5952
6077
|
}) => ({
|
|
@@ -5956,7 +6081,8 @@ function ContentComponent(props) {
|
|
|
5956
6081
|
inheritedStyles: {},
|
|
5957
6082
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
5958
6083
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
5959
|
-
nonce: props.nonce || ""
|
|
6084
|
+
nonce: props.nonce || "",
|
|
6085
|
+
model: props.model || ""
|
|
5960
6086
|
});
|
|
5961
6087
|
function contentSetState(newRootState) {
|
|
5962
6088
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|