@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/node/index.js
CHANGED
|
@@ -115,27 +115,11 @@ var builder_context_default = createContext({
|
|
|
115
115
|
inheritedStyles: {},
|
|
116
116
|
BlocksWrapper: "div",
|
|
117
117
|
BlocksWrapperProps: {},
|
|
118
|
-
nonce: ""
|
|
118
|
+
nonce: "",
|
|
119
|
+
model: ""
|
|
119
120
|
});
|
|
120
121
|
var components_context_default = createContext({ registeredComponents: {} });
|
|
121
122
|
|
|
122
|
-
// src/functions/get-block-component-options.ts
|
|
123
|
-
function getBlockComponentOptions(block) {
|
|
124
|
-
return {
|
|
125
|
-
...block.component?.options,
|
|
126
|
-
...block.options
|
|
127
|
-
};
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
// src/helpers/omit.ts
|
|
131
|
-
function omit(obj, ...values) {
|
|
132
|
-
const newObject = Object.assign({}, obj);
|
|
133
|
-
for (const key of values) {
|
|
134
|
-
delete newObject[key];
|
|
135
|
-
}
|
|
136
|
-
return newObject;
|
|
137
|
-
}
|
|
138
|
-
|
|
139
123
|
// src/helpers/logger.ts
|
|
140
124
|
var MSG_PREFIX = "[Builder.io]: ";
|
|
141
125
|
var logger = {
|
|
@@ -581,6 +565,106 @@ function evaluate({
|
|
|
581
565
|
}
|
|
582
566
|
}
|
|
583
567
|
|
|
568
|
+
// src/functions/get-block-component-options.ts
|
|
569
|
+
function getBlockComponentOptions(block, context) {
|
|
570
|
+
return {
|
|
571
|
+
...block.component?.options,
|
|
572
|
+
...block.options,
|
|
573
|
+
...evaluateTextComponentTextOption(block, context)
|
|
574
|
+
};
|
|
575
|
+
}
|
|
576
|
+
var evaluateTextComponentTextOption = (block, context) => {
|
|
577
|
+
if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
|
|
578
|
+
return {
|
|
579
|
+
...block.component.options,
|
|
580
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
581
|
+
code: group,
|
|
582
|
+
context,
|
|
583
|
+
localState: context.localState,
|
|
584
|
+
rootState: context.rootState,
|
|
585
|
+
rootSetState: context.rootSetState
|
|
586
|
+
}))
|
|
587
|
+
};
|
|
588
|
+
}
|
|
589
|
+
};
|
|
590
|
+
|
|
591
|
+
// src/helpers/omit.ts
|
|
592
|
+
function omit(obj, ...values) {
|
|
593
|
+
const newObject = Object.assign({}, obj);
|
|
594
|
+
for (const key of values) {
|
|
595
|
+
delete newObject[key];
|
|
596
|
+
}
|
|
597
|
+
return newObject;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
// src/functions/traverse.ts
|
|
601
|
+
function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
602
|
+
if (obj == null || typeof obj !== "object") {
|
|
603
|
+
callback(obj, (newValue) => {
|
|
604
|
+
if (parent2 !== null && key !== null) {
|
|
605
|
+
parent2[key] = newValue;
|
|
606
|
+
}
|
|
607
|
+
});
|
|
608
|
+
return;
|
|
609
|
+
}
|
|
610
|
+
if (visited.has(obj)) {
|
|
611
|
+
return;
|
|
612
|
+
}
|
|
613
|
+
visited.add(obj);
|
|
614
|
+
if (Array.isArray(obj)) {
|
|
615
|
+
obj.forEach((item, index) => {
|
|
616
|
+
const update = (newValue) => {
|
|
617
|
+
obj[index] = newValue;
|
|
618
|
+
};
|
|
619
|
+
callback(item, update);
|
|
620
|
+
traverse(item, callback, obj, index, visited);
|
|
621
|
+
});
|
|
622
|
+
} else {
|
|
623
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
624
|
+
const update = (newValue) => {
|
|
625
|
+
obj[key2] = newValue;
|
|
626
|
+
};
|
|
627
|
+
callback(value, update);
|
|
628
|
+
traverse(value, callback, obj, key2, visited);
|
|
629
|
+
});
|
|
630
|
+
}
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
// src/functions/extract-localized-values.ts
|
|
634
|
+
function isLocalizedField(value) {
|
|
635
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
636
|
+
}
|
|
637
|
+
function containsLocalizedValues(data) {
|
|
638
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
639
|
+
return false;
|
|
640
|
+
}
|
|
641
|
+
let hasLocalizedValues = false;
|
|
642
|
+
traverse(data, (value) => {
|
|
643
|
+
if (isLocalizedField(value)) {
|
|
644
|
+
hasLocalizedValues = true;
|
|
645
|
+
return;
|
|
646
|
+
}
|
|
647
|
+
});
|
|
648
|
+
return hasLocalizedValues;
|
|
649
|
+
}
|
|
650
|
+
function extractLocalizedValues(data, locale) {
|
|
651
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
652
|
+
return {};
|
|
653
|
+
}
|
|
654
|
+
traverse(data, (value, update) => {
|
|
655
|
+
if (isLocalizedField(value)) {
|
|
656
|
+
update(value[locale] ?? void 0);
|
|
657
|
+
}
|
|
658
|
+
});
|
|
659
|
+
return data;
|
|
660
|
+
}
|
|
661
|
+
function resolveLocalizedValues(block, locale) {
|
|
662
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
663
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
664
|
+
}
|
|
665
|
+
return block;
|
|
666
|
+
}
|
|
667
|
+
|
|
584
668
|
// src/functions/transform-block.ts
|
|
585
669
|
function transformBlock(block) {
|
|
586
670
|
return block;
|
|
@@ -661,23 +745,19 @@ var evaluateBindings = ({
|
|
|
661
745
|
function getProcessedBlock({
|
|
662
746
|
block,
|
|
663
747
|
context,
|
|
664
|
-
shouldEvaluateBindings,
|
|
665
748
|
localState,
|
|
666
749
|
rootState,
|
|
667
750
|
rootSetState
|
|
668
751
|
}) {
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
} else {
|
|
679
|
-
return transformedBlock;
|
|
680
|
-
}
|
|
752
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
753
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
754
|
+
return evaluateBindings({
|
|
755
|
+
block: transformedBlock,
|
|
756
|
+
localState,
|
|
757
|
+
rootState,
|
|
758
|
+
rootSetState,
|
|
759
|
+
context
|
|
760
|
+
});
|
|
681
761
|
}
|
|
682
762
|
|
|
683
763
|
// src/functions/camel-to-kebab-case.ts
|
|
@@ -923,16 +1003,24 @@ function mapStyleObjToStrIfNeeded(style) {
|
|
|
923
1003
|
}
|
|
924
1004
|
|
|
925
1005
|
// src/components/block/block.helpers.ts
|
|
1006
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
1007
|
+
if (!component)
|
|
1008
|
+
return true;
|
|
1009
|
+
if (!model)
|
|
1010
|
+
return false;
|
|
1011
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
1012
|
+
};
|
|
926
1013
|
var getComponent = ({
|
|
927
1014
|
block,
|
|
928
|
-
registeredComponents
|
|
1015
|
+
registeredComponents,
|
|
1016
|
+
model
|
|
929
1017
|
}) => {
|
|
930
1018
|
const componentName = block.component?.name;
|
|
931
1019
|
if (!componentName) {
|
|
932
1020
|
return null;
|
|
933
1021
|
}
|
|
934
1022
|
const ref = registeredComponents[componentName];
|
|
935
|
-
if (!ref) {
|
|
1023
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
936
1024
|
return void 0;
|
|
937
1025
|
} else {
|
|
938
1026
|
return ref;
|
|
@@ -983,11 +1071,15 @@ var provideLinkComponent = (block, linkComponent) => {
|
|
|
983
1071
|
};
|
|
984
1072
|
return {};
|
|
985
1073
|
};
|
|
986
|
-
var provideRegisteredComponents = (block, registeredComponents) => {
|
|
987
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
1074
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
1075
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
1076
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
1077
|
+
return !checkIsComponentRestricted(component, model);
|
|
1078
|
+
}));
|
|
988
1079
|
return {
|
|
989
|
-
builderComponents:
|
|
1080
|
+
builderComponents: filteredRegisteredComponents
|
|
990
1081
|
};
|
|
1082
|
+
}
|
|
991
1083
|
return {};
|
|
992
1084
|
};
|
|
993
1085
|
var provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -1441,15 +1533,15 @@ function Block(props) {
|
|
|
1441
1533
|
localState: props.context.localState,
|
|
1442
1534
|
rootState: props.context.rootState,
|
|
1443
1535
|
rootSetState: props.context.rootSetState,
|
|
1444
|
-
context: props.context.context
|
|
1445
|
-
shouldEvaluateBindings: true
|
|
1536
|
+
context: props.context.context
|
|
1446
1537
|
});
|
|
1447
1538
|
return blockToUse;
|
|
1448
1539
|
});
|
|
1449
1540
|
const blockComponent = createMemo(() => {
|
|
1450
1541
|
return getComponent({
|
|
1451
1542
|
block: processedBlock(),
|
|
1452
|
-
registeredComponents: props.registeredComponents
|
|
1543
|
+
registeredComponents: props.registeredComponents,
|
|
1544
|
+
model: props.context.model
|
|
1453
1545
|
});
|
|
1454
1546
|
});
|
|
1455
1547
|
const Tag = createMemo(() => {
|
|
@@ -1478,11 +1570,11 @@ function Block(props) {
|
|
|
1478
1570
|
blockChildren: processedBlock().children ?? [],
|
|
1479
1571
|
componentRef: blockComponent()?.component,
|
|
1480
1572
|
componentOptions: {
|
|
1481
|
-
...getBlockComponentOptions(processedBlock()),
|
|
1573
|
+
...getBlockComponentOptions(processedBlock(), props.context),
|
|
1482
1574
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
1483
1575
|
...provideBuilderContext(blockComponent(), props.context),
|
|
1484
1576
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
1485
|
-
...provideRegisteredComponents(blockComponent(), props.registeredComponents)
|
|
1577
|
+
...provideRegisteredComponents(blockComponent(), props.registeredComponents, props.context.model)
|
|
1486
1578
|
},
|
|
1487
1579
|
context: props.context,
|
|
1488
1580
|
linkComponent: props.linkComponent,
|
|
@@ -2080,16 +2172,16 @@ function getSrcSet(url) {
|
|
|
2080
2172
|
// src/blocks/image/image.tsx
|
|
2081
2173
|
var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
|
|
2082
2174
|
var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
|
|
2083
|
-
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-
|
|
2084
|
-
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-
|
|
2085
|
-
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-
|
|
2175
|
+
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-070d7e88">`);
|
|
2176
|
+
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-070d7e88-2>`);
|
|
2177
|
+
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-070d7e88 {
|
|
2086
2178
|
opacity: 1;
|
|
2087
2179
|
transition: opacity 0.2s ease-in-out;
|
|
2088
|
-
}.div-
|
|
2180
|
+
}.div-070d7e88 {
|
|
2089
2181
|
width: 100%;
|
|
2090
2182
|
pointer-events: none;
|
|
2091
2183
|
font-size: 0;
|
|
2092
|
-
}.div-
|
|
2184
|
+
}.div-070d7e88-2 {
|
|
2093
2185
|
display: flex;
|
|
2094
2186
|
flex-direction: column;
|
|
2095
2187
|
align-items: stretch;
|
|
@@ -2105,7 +2197,7 @@ function Image(props) {
|
|
|
2105
2197
|
const url = imageToUse;
|
|
2106
2198
|
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
2107
2199
|
// images, otherwise you can supply this prop manually
|
|
2108
|
-
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
2200
|
+
!(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
2109
2201
|
return props.srcset;
|
|
2110
2202
|
}
|
|
2111
2203
|
if (props.noWebp) {
|
|
@@ -2153,7 +2245,7 @@ function Image(props) {
|
|
|
2153
2245
|
}
|
|
2154
2246
|
}), _el$3);
|
|
2155
2247
|
effect((_p$) => {
|
|
2156
|
-
const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-
|
|
2248
|
+
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 = {
|
|
2157
2249
|
"object-position": props.backgroundPosition || "center",
|
|
2158
2250
|
"object-fit": props.backgroundSize || "cover",
|
|
2159
2251
|
...aspectRatioCss()
|
|
@@ -3019,6 +3111,10 @@ var componentInfo4 = {
|
|
|
3019
3111
|
noWrap: true
|
|
3020
3112
|
};
|
|
3021
3113
|
|
|
3114
|
+
// src/constants/file-types.ts
|
|
3115
|
+
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"];
|
|
3116
|
+
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"];
|
|
3117
|
+
|
|
3022
3118
|
// src/blocks/image/component-info.ts
|
|
3023
3119
|
var componentInfo5 = {
|
|
3024
3120
|
name: "Image",
|
|
@@ -3035,7 +3131,7 @@ var componentInfo5 = {
|
|
|
3035
3131
|
name: "image",
|
|
3036
3132
|
type: "file",
|
|
3037
3133
|
bubble: true,
|
|
3038
|
-
allowedFileTypes:
|
|
3134
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
3039
3135
|
required: true,
|
|
3040
3136
|
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
|
|
3041
3137
|
onChange: (options) => {
|
|
@@ -3552,26 +3648,10 @@ var componentInfo10 = {
|
|
|
3552
3648
|
};
|
|
3553
3649
|
var _tmpl$10 = /* @__PURE__ */ template(`<div class=builder-text>`);
|
|
3554
3650
|
function Text(props) {
|
|
3555
|
-
const processedText = createMemo(() => {
|
|
3556
|
-
const context = props.builderContext;
|
|
3557
|
-
const {
|
|
3558
|
-
context: contextContext,
|
|
3559
|
-
localState,
|
|
3560
|
-
rootState,
|
|
3561
|
-
rootSetState
|
|
3562
|
-
} = context;
|
|
3563
|
-
return String(props.text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
|
|
3564
|
-
code: group,
|
|
3565
|
-
context: contextContext,
|
|
3566
|
-
localState,
|
|
3567
|
-
rootState,
|
|
3568
|
-
rootSetState
|
|
3569
|
-
}));
|
|
3570
|
-
});
|
|
3571
3651
|
return (() => {
|
|
3572
3652
|
const _el$ = _tmpl$10();
|
|
3573
3653
|
_el$.style.setProperty("outline", "none");
|
|
3574
|
-
effect(() => _el$.innerHTML =
|
|
3654
|
+
effect(() => _el$.innerHTML = props.text?.toString() || "");
|
|
3575
3655
|
return _el$;
|
|
3576
3656
|
})();
|
|
3577
3657
|
}
|
|
@@ -4564,7 +4644,7 @@ var componentInfo18 = {
|
|
|
4564
4644
|
name: "image",
|
|
4565
4645
|
bubble: true,
|
|
4566
4646
|
type: "file",
|
|
4567
|
-
allowedFileTypes:
|
|
4647
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4568
4648
|
required: true
|
|
4569
4649
|
}],
|
|
4570
4650
|
noWrap: true,
|
|
@@ -4608,14 +4688,14 @@ var componentInfo19 = {
|
|
|
4608
4688
|
inputs: [{
|
|
4609
4689
|
name: "video",
|
|
4610
4690
|
type: "file",
|
|
4611
|
-
allowedFileTypes:
|
|
4691
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
4612
4692
|
bubble: true,
|
|
4613
4693
|
defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
|
|
4614
4694
|
required: true
|
|
4615
4695
|
}, {
|
|
4616
4696
|
name: "posterImage",
|
|
4617
4697
|
type: "file",
|
|
4618
|
-
allowedFileTypes:
|
|
4698
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4619
4699
|
helperText: "Image to show before the video plays"
|
|
4620
4700
|
}, {
|
|
4621
4701
|
name: "autoPlay",
|
|
@@ -4871,7 +4951,7 @@ var createRegisterComponentMessage = (info) => ({
|
|
|
4871
4951
|
var serializeFn = (fnValue) => {
|
|
4872
4952
|
const fnStr = fnValue.toString().trim();
|
|
4873
4953
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
4874
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4954
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4875
4955
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
4876
4956
|
};
|
|
4877
4957
|
function serializeIncludingFunctions(info) {
|
|
@@ -4954,7 +5034,7 @@ function getPreviewContent(_searchParams) {
|
|
|
4954
5034
|
}
|
|
4955
5035
|
|
|
4956
5036
|
// src/constants/sdk-version.ts
|
|
4957
|
-
var SDK_VERSION = "3.0.
|
|
5037
|
+
var SDK_VERSION = "3.0.2";
|
|
4958
5038
|
|
|
4959
5039
|
// src/helpers/sdk-headers.ts
|
|
4960
5040
|
var getSdkHeaders = () => ({
|
|
@@ -5017,6 +5097,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
|
|
|
5017
5097
|
}
|
|
5018
5098
|
return _res;
|
|
5019
5099
|
}
|
|
5100
|
+
function unflatten(obj) {
|
|
5101
|
+
const result = {};
|
|
5102
|
+
for (const key in obj) {
|
|
5103
|
+
const parts = key.split(".");
|
|
5104
|
+
let current = result;
|
|
5105
|
+
for (let i = 0; i < parts.length; i++) {
|
|
5106
|
+
const part = parts[i];
|
|
5107
|
+
if (i === parts.length - 1) {
|
|
5108
|
+
current[part] = obj[key];
|
|
5109
|
+
} else {
|
|
5110
|
+
current[part] = current[part] || {};
|
|
5111
|
+
current = current[part];
|
|
5112
|
+
}
|
|
5113
|
+
}
|
|
5114
|
+
}
|
|
5115
|
+
return result;
|
|
5116
|
+
}
|
|
5020
5117
|
|
|
5021
5118
|
// src/types/api-version.ts
|
|
5022
5119
|
var DEFAULT_API_VERSION = "v3";
|
|
@@ -5081,7 +5178,7 @@ var generateContentUrl = (options) => {
|
|
|
5081
5178
|
url.searchParams.set("noTraverse", String(noTraverse));
|
|
5082
5179
|
url.searchParams.set("includeRefs", String(true));
|
|
5083
5180
|
const finalLocale = locale || userAttributes?.locale;
|
|
5084
|
-
let finalUserAttributes = userAttributes;
|
|
5181
|
+
let finalUserAttributes = userAttributes || {};
|
|
5085
5182
|
if (finalLocale) {
|
|
5086
5183
|
url.searchParams.set("locale", finalLocale);
|
|
5087
5184
|
finalUserAttributes = {
|
|
@@ -5119,11 +5216,15 @@ var generateContentUrl = (options) => {
|
|
|
5119
5216
|
...getBuilderSearchParamsFromWindow(),
|
|
5120
5217
|
...normalizeSearchParams(options.options || {})
|
|
5121
5218
|
};
|
|
5219
|
+
finalUserAttributes = {
|
|
5220
|
+
...finalUserAttributes,
|
|
5221
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
5222
|
+
};
|
|
5122
5223
|
const flattened = flatten(queryOptions);
|
|
5123
5224
|
for (const key in flattened) {
|
|
5124
5225
|
url.searchParams.set(key, String(flattened[key]));
|
|
5125
5226
|
}
|
|
5126
|
-
if (finalUserAttributes) {
|
|
5227
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
5127
5228
|
url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
|
|
5128
5229
|
}
|
|
5129
5230
|
if (query) {
|
|
@@ -5136,6 +5237,28 @@ var generateContentUrl = (options) => {
|
|
|
5136
5237
|
}
|
|
5137
5238
|
return url;
|
|
5138
5239
|
};
|
|
5240
|
+
var getUserAttributesFromQueryOptions = (queryOptions) => {
|
|
5241
|
+
const newUserAttributes = {};
|
|
5242
|
+
for (const key in queryOptions) {
|
|
5243
|
+
if (key.startsWith("userAttributes.")) {
|
|
5244
|
+
newUserAttributes[key] = queryOptions[key];
|
|
5245
|
+
delete queryOptions[key];
|
|
5246
|
+
}
|
|
5247
|
+
}
|
|
5248
|
+
return newUserAttributes;
|
|
5249
|
+
};
|
|
5250
|
+
var getUserAttributesAsJSON = (queryOptions) => {
|
|
5251
|
+
if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
|
|
5252
|
+
queryOptions["userAttributes.urlPath"] = window.location.pathname;
|
|
5253
|
+
queryOptions["userAttributes.host"] = window.location.host;
|
|
5254
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
5255
|
+
const {
|
|
5256
|
+
userAttributes
|
|
5257
|
+
} = unflatten(queryOptionsForUserAttributes);
|
|
5258
|
+
return userAttributes;
|
|
5259
|
+
}
|
|
5260
|
+
return {};
|
|
5261
|
+
};
|
|
5139
5262
|
|
|
5140
5263
|
// src/functions/get-content/index.ts
|
|
5141
5264
|
var checkContentHasResults = (content) => "results" in content;
|
|
@@ -5666,6 +5789,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
5666
5789
|
};
|
|
5667
5790
|
};
|
|
5668
5791
|
|
|
5792
|
+
// src/components/content/components/enable-editor.helpers.ts
|
|
5793
|
+
var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
|
|
5794
|
+
var needsElementRefDivForEditing = () => {
|
|
5795
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
5796
|
+
};
|
|
5797
|
+
|
|
5669
5798
|
// src/components/content/components/styles.helpers.ts
|
|
5670
5799
|
var getCssFromFont = (font) => {
|
|
5671
5800
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -5900,8 +6029,10 @@ function EnableEditor(props) {
|
|
|
5900
6029
|
} : {}
|
|
5901
6030
|
});
|
|
5902
6031
|
Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
5903
|
-
|
|
5904
|
-
|
|
6032
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
6033
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
6034
|
+
window.parent?.postMessage(message, "*");
|
|
6035
|
+
}
|
|
5905
6036
|
});
|
|
5906
6037
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
5907
6038
|
}
|
|
@@ -5924,11 +6055,16 @@ function EnableEditor(props) {
|
|
|
5924
6055
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
5925
6056
|
const searchParamPreviewId = searchParams.get(`builder.overrides.${searchParamPreviewModel}`);
|
|
5926
6057
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
5927
|
-
if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
6058
|
+
if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
5928
6059
|
fetchOneEntry({
|
|
5929
|
-
model: props.model,
|
|
6060
|
+
model: props.model || "",
|
|
5930
6061
|
apiKey: props.apiKey,
|
|
5931
|
-
apiVersion: props.builderContextSignal.apiVersion
|
|
6062
|
+
apiVersion: props.builderContextSignal.apiVersion,
|
|
6063
|
+
...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
|
|
6064
|
+
query: {
|
|
6065
|
+
id: props.context.symbolId
|
|
6066
|
+
}
|
|
6067
|
+
} : {}
|
|
5932
6068
|
}).then((content) => {
|
|
5933
6069
|
if (content) {
|
|
5934
6070
|
mergeNewContent(content);
|
|
@@ -5973,7 +6109,7 @@ function EnableEditor(props) {
|
|
|
5973
6109
|
get children() {
|
|
5974
6110
|
return createComponent(Show, {
|
|
5975
6111
|
get when() {
|
|
5976
|
-
return props.builderContextSignal.content;
|
|
6112
|
+
return props.builderContextSignal.content || needsElementRefDivForEditing();
|
|
5977
6113
|
},
|
|
5978
6114
|
get children() {
|
|
5979
6115
|
return createComponent(Dynamic, mergeProps({
|
|
@@ -5991,6 +6127,11 @@ function EnableEditor(props) {
|
|
|
5991
6127
|
},
|
|
5992
6128
|
get ["builder-model"]() {
|
|
5993
6129
|
return props.model;
|
|
6130
|
+
},
|
|
6131
|
+
get style() {
|
|
6132
|
+
return {
|
|
6133
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
6134
|
+
};
|
|
5994
6135
|
}
|
|
5995
6136
|
}, {}, showContentProps, () => props.contentWrapperProps, {
|
|
5996
6137
|
get component() {
|
|
@@ -6073,15 +6214,7 @@ function ContentComponent(props) {
|
|
|
6073
6214
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
6074
6215
|
contentId: props.content?.id
|
|
6075
6216
|
}));
|
|
6076
|
-
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents
|
|
6077
|
-
models
|
|
6078
|
-
}) => {
|
|
6079
|
-
if (!models?.length)
|
|
6080
|
-
return true;
|
|
6081
|
-
if (!props.model)
|
|
6082
|
-
return true;
|
|
6083
|
-
return models.includes(props.model);
|
|
6084
|
-
}) || []].reduce((acc, {
|
|
6217
|
+
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
6085
6218
|
component,
|
|
6086
6219
|
...info
|
|
6087
6220
|
}) => ({
|
|
@@ -6107,15 +6240,7 @@ function ContentComponent(props) {
|
|
|
6107
6240
|
canTrack: props.canTrack,
|
|
6108
6241
|
apiKey: props.apiKey,
|
|
6109
6242
|
apiVersion: props.apiVersion,
|
|
6110
|
-
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents
|
|
6111
|
-
models
|
|
6112
|
-
}) => {
|
|
6113
|
-
if (!models?.length)
|
|
6114
|
-
return true;
|
|
6115
|
-
if (!props.model)
|
|
6116
|
-
return true;
|
|
6117
|
-
return models.includes(props.model);
|
|
6118
|
-
}) || []].reduce((acc, {
|
|
6243
|
+
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
6119
6244
|
component: _,
|
|
6120
6245
|
...info
|
|
6121
6246
|
}) => ({
|
|
@@ -6125,7 +6250,8 @@ function ContentComponent(props) {
|
|
|
6125
6250
|
inheritedStyles: {},
|
|
6126
6251
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
6127
6252
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
6128
|
-
nonce: props.nonce || ""
|
|
6253
|
+
nonce: props.nonce || "",
|
|
6254
|
+
model: props.model || ""
|
|
6129
6255
|
});
|
|
6130
6256
|
function contentSetState(newRootState) {
|
|
6131
6257
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|