@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/dev.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 = {
|
|
@@ -583,6 +567,109 @@ function evaluate({
|
|
|
583
567
|
}
|
|
584
568
|
}
|
|
585
569
|
|
|
570
|
+
// src/functions/get-block-component-options.ts
|
|
571
|
+
function getBlockComponentOptions(block, context) {
|
|
572
|
+
return {
|
|
573
|
+
...block.component?.options,
|
|
574
|
+
...block.options,
|
|
575
|
+
...evaluateTextComponentTextOption(block, context)
|
|
576
|
+
};
|
|
577
|
+
}
|
|
578
|
+
var evaluateTextComponentTextOption = (block, context) => {
|
|
579
|
+
if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
|
|
580
|
+
return {
|
|
581
|
+
...block.component.options,
|
|
582
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
583
|
+
code: group,
|
|
584
|
+
context,
|
|
585
|
+
localState: context.localState,
|
|
586
|
+
rootState: context.rootState,
|
|
587
|
+
rootSetState: context.rootSetState
|
|
588
|
+
}))
|
|
589
|
+
};
|
|
590
|
+
}
|
|
591
|
+
};
|
|
592
|
+
|
|
593
|
+
// src/helpers/omit.ts
|
|
594
|
+
function omit(obj, ...values) {
|
|
595
|
+
const newObject = Object.assign({}, obj);
|
|
596
|
+
for (const key of values) {
|
|
597
|
+
delete newObject[key];
|
|
598
|
+
}
|
|
599
|
+
return newObject;
|
|
600
|
+
}
|
|
601
|
+
|
|
602
|
+
// src/functions/traverse.ts
|
|
603
|
+
function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
604
|
+
if (obj == null || typeof obj !== "object") {
|
|
605
|
+
callback(obj, (newValue) => {
|
|
606
|
+
if (parent2 !== null && key !== null) {
|
|
607
|
+
parent2[key] = newValue;
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
if (visited.has(obj)) {
|
|
613
|
+
return;
|
|
614
|
+
}
|
|
615
|
+
visited.add(obj);
|
|
616
|
+
if (Array.isArray(obj)) {
|
|
617
|
+
obj.forEach((item, index) => {
|
|
618
|
+
const update = (newValue) => {
|
|
619
|
+
obj[index] = newValue;
|
|
620
|
+
};
|
|
621
|
+
callback(item, update);
|
|
622
|
+
traverse(item, callback, obj, index, visited);
|
|
623
|
+
});
|
|
624
|
+
} else {
|
|
625
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
626
|
+
const update = (newValue) => {
|
|
627
|
+
obj[key2] = newValue;
|
|
628
|
+
};
|
|
629
|
+
callback(value, update);
|
|
630
|
+
traverse(value, callback, obj, key2, visited);
|
|
631
|
+
});
|
|
632
|
+
}
|
|
633
|
+
}
|
|
634
|
+
|
|
635
|
+
// src/functions/extract-localized-values.ts
|
|
636
|
+
function isLocalizedField(value) {
|
|
637
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
638
|
+
}
|
|
639
|
+
function containsLocalizedValues(data) {
|
|
640
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
641
|
+
return false;
|
|
642
|
+
}
|
|
643
|
+
let hasLocalizedValues = false;
|
|
644
|
+
traverse(data, (value) => {
|
|
645
|
+
if (isLocalizedField(value)) {
|
|
646
|
+
hasLocalizedValues = true;
|
|
647
|
+
return;
|
|
648
|
+
}
|
|
649
|
+
});
|
|
650
|
+
return hasLocalizedValues;
|
|
651
|
+
}
|
|
652
|
+
function extractLocalizedValues(data, locale) {
|
|
653
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
654
|
+
return {};
|
|
655
|
+
}
|
|
656
|
+
traverse(data, (value, update) => {
|
|
657
|
+
if (isLocalizedField(value)) {
|
|
658
|
+
update(value[locale] ?? void 0);
|
|
659
|
+
}
|
|
660
|
+
});
|
|
661
|
+
return data;
|
|
662
|
+
}
|
|
663
|
+
function resolveLocalizedValues(block, locale) {
|
|
664
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
665
|
+
if (!locale) {
|
|
666
|
+
console.warn("[Builder.io] In order to use localized fields in Builder, you must pass a locale prop to the BuilderComponent or to options object while fetching the content to resolve localized fields. Learn more: https://www.builder.io/c/docs/localization-inline#targeting-and-inline-localization");
|
|
667
|
+
}
|
|
668
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
669
|
+
}
|
|
670
|
+
return block;
|
|
671
|
+
}
|
|
672
|
+
|
|
586
673
|
// src/functions/transform-block.ts
|
|
587
674
|
function transformBlock(block) {
|
|
588
675
|
return block;
|
|
@@ -663,23 +750,19 @@ var evaluateBindings = ({
|
|
|
663
750
|
function getProcessedBlock({
|
|
664
751
|
block,
|
|
665
752
|
context,
|
|
666
|
-
shouldEvaluateBindings,
|
|
667
753
|
localState,
|
|
668
754
|
rootState,
|
|
669
755
|
rootSetState
|
|
670
756
|
}) {
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
} else {
|
|
681
|
-
return transformedBlock;
|
|
682
|
-
}
|
|
757
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
758
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
759
|
+
return evaluateBindings({
|
|
760
|
+
block: transformedBlock,
|
|
761
|
+
localState,
|
|
762
|
+
rootState,
|
|
763
|
+
rootSetState,
|
|
764
|
+
context
|
|
765
|
+
});
|
|
683
766
|
}
|
|
684
767
|
|
|
685
768
|
// src/functions/camel-to-kebab-case.ts
|
|
@@ -926,16 +1009,24 @@ function mapStyleObjToStrIfNeeded(style) {
|
|
|
926
1009
|
}
|
|
927
1010
|
|
|
928
1011
|
// src/components/block/block.helpers.ts
|
|
1012
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
1013
|
+
if (!component)
|
|
1014
|
+
return true;
|
|
1015
|
+
if (!model)
|
|
1016
|
+
return false;
|
|
1017
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
1018
|
+
};
|
|
929
1019
|
var getComponent = ({
|
|
930
1020
|
block,
|
|
931
|
-
registeredComponents
|
|
1021
|
+
registeredComponents,
|
|
1022
|
+
model
|
|
932
1023
|
}) => {
|
|
933
1024
|
const componentName = block.component?.name;
|
|
934
1025
|
if (!componentName) {
|
|
935
1026
|
return null;
|
|
936
1027
|
}
|
|
937
1028
|
const ref = registeredComponents[componentName];
|
|
938
|
-
if (!ref) {
|
|
1029
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
939
1030
|
console.warn(`
|
|
940
1031
|
Could not find a registered component named "${componentName}".
|
|
941
1032
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
@@ -989,11 +1080,15 @@ var provideLinkComponent = (block, linkComponent) => {
|
|
|
989
1080
|
};
|
|
990
1081
|
return {};
|
|
991
1082
|
};
|
|
992
|
-
var provideRegisteredComponents = (block, registeredComponents) => {
|
|
993
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
1083
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
1084
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
1085
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
1086
|
+
return !checkIsComponentRestricted(component, model);
|
|
1087
|
+
}));
|
|
994
1088
|
return {
|
|
995
|
-
builderComponents:
|
|
1089
|
+
builderComponents: filteredRegisteredComponents
|
|
996
1090
|
};
|
|
1091
|
+
}
|
|
997
1092
|
return {};
|
|
998
1093
|
};
|
|
999
1094
|
var provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -1447,15 +1542,15 @@ function Block(props) {
|
|
|
1447
1542
|
localState: props.context.localState,
|
|
1448
1543
|
rootState: props.context.rootState,
|
|
1449
1544
|
rootSetState: props.context.rootSetState,
|
|
1450
|
-
context: props.context.context
|
|
1451
|
-
shouldEvaluateBindings: true
|
|
1545
|
+
context: props.context.context
|
|
1452
1546
|
});
|
|
1453
1547
|
return blockToUse;
|
|
1454
1548
|
});
|
|
1455
1549
|
const blockComponent = createMemo(() => {
|
|
1456
1550
|
return getComponent({
|
|
1457
1551
|
block: processedBlock(),
|
|
1458
|
-
registeredComponents: props.registeredComponents
|
|
1552
|
+
registeredComponents: props.registeredComponents,
|
|
1553
|
+
model: props.context.model
|
|
1459
1554
|
});
|
|
1460
1555
|
});
|
|
1461
1556
|
const Tag = createMemo(() => {
|
|
@@ -1484,11 +1579,11 @@ function Block(props) {
|
|
|
1484
1579
|
blockChildren: processedBlock().children ?? [],
|
|
1485
1580
|
componentRef: blockComponent()?.component,
|
|
1486
1581
|
componentOptions: {
|
|
1487
|
-
...getBlockComponentOptions(processedBlock()),
|
|
1582
|
+
...getBlockComponentOptions(processedBlock(), props.context),
|
|
1488
1583
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
1489
1584
|
...provideBuilderContext(blockComponent(), props.context),
|
|
1490
1585
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
1491
|
-
...provideRegisteredComponents(blockComponent(), props.registeredComponents)
|
|
1586
|
+
...provideRegisteredComponents(blockComponent(), props.registeredComponents, props.context.model)
|
|
1492
1587
|
},
|
|
1493
1588
|
context: props.context,
|
|
1494
1589
|
linkComponent: props.linkComponent,
|
|
@@ -2086,16 +2181,16 @@ function getSrcSet(url) {
|
|
|
2086
2181
|
// src/blocks/image/image.tsx
|
|
2087
2182
|
var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
|
|
2088
2183
|
var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
|
|
2089
|
-
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-
|
|
2090
|
-
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-
|
|
2091
|
-
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-
|
|
2184
|
+
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-070d7e88">`);
|
|
2185
|
+
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-070d7e88-2>`);
|
|
2186
|
+
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-070d7e88 {
|
|
2092
2187
|
opacity: 1;
|
|
2093
2188
|
transition: opacity 0.2s ease-in-out;
|
|
2094
|
-
}.div-
|
|
2189
|
+
}.div-070d7e88 {
|
|
2095
2190
|
width: 100%;
|
|
2096
2191
|
pointer-events: none;
|
|
2097
2192
|
font-size: 0;
|
|
2098
|
-
}.div-
|
|
2193
|
+
}.div-070d7e88-2 {
|
|
2099
2194
|
display: flex;
|
|
2100
2195
|
flex-direction: column;
|
|
2101
2196
|
align-items: stretch;
|
|
@@ -2111,7 +2206,7 @@ function Image(props) {
|
|
|
2111
2206
|
const url = imageToUse;
|
|
2112
2207
|
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
2113
2208
|
// images, otherwise you can supply this prop manually
|
|
2114
|
-
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
2209
|
+
!(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
2115
2210
|
return props.srcset;
|
|
2116
2211
|
}
|
|
2117
2212
|
if (props.noWebp) {
|
|
@@ -2160,7 +2255,7 @@ function Image(props) {
|
|
|
2160
2255
|
}
|
|
2161
2256
|
}), _el$3);
|
|
2162
2257
|
effect((_p$) => {
|
|
2163
|
-
const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-
|
|
2258
|
+
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 = {
|
|
2164
2259
|
"object-position": props.backgroundPosition || "center",
|
|
2165
2260
|
"object-fit": props.backgroundSize || "cover",
|
|
2166
2261
|
...aspectRatioCss()
|
|
@@ -3026,6 +3121,10 @@ var componentInfo4 = {
|
|
|
3026
3121
|
noWrap: true
|
|
3027
3122
|
};
|
|
3028
3123
|
|
|
3124
|
+
// src/constants/file-types.ts
|
|
3125
|
+
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"];
|
|
3126
|
+
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"];
|
|
3127
|
+
|
|
3029
3128
|
// src/blocks/image/component-info.ts
|
|
3030
3129
|
var componentInfo5 = {
|
|
3031
3130
|
name: "Image",
|
|
@@ -3042,7 +3141,7 @@ var componentInfo5 = {
|
|
|
3042
3141
|
name: "image",
|
|
3043
3142
|
type: "file",
|
|
3044
3143
|
bubble: true,
|
|
3045
|
-
allowedFileTypes:
|
|
3144
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
3046
3145
|
required: true,
|
|
3047
3146
|
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
|
|
3048
3147
|
onChange: (options) => {
|
|
@@ -3560,26 +3659,10 @@ var componentInfo10 = {
|
|
|
3560
3659
|
};
|
|
3561
3660
|
var _tmpl$10 = /* @__PURE__ */ template(`<div class=builder-text>`);
|
|
3562
3661
|
function Text(props) {
|
|
3563
|
-
const processedText = createMemo(() => {
|
|
3564
|
-
const context = props.builderContext;
|
|
3565
|
-
const {
|
|
3566
|
-
context: contextContext,
|
|
3567
|
-
localState,
|
|
3568
|
-
rootState,
|
|
3569
|
-
rootSetState
|
|
3570
|
-
} = context;
|
|
3571
|
-
return String(props.text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
|
|
3572
|
-
code: group,
|
|
3573
|
-
context: contextContext,
|
|
3574
|
-
localState,
|
|
3575
|
-
rootState,
|
|
3576
|
-
rootSetState
|
|
3577
|
-
}));
|
|
3578
|
-
});
|
|
3579
3662
|
return (() => {
|
|
3580
3663
|
const _el$ = _tmpl$10();
|
|
3581
3664
|
_el$.style.setProperty("outline", "none");
|
|
3582
|
-
effect(() => _el$.innerHTML =
|
|
3665
|
+
effect(() => _el$.innerHTML = props.text?.toString() || "");
|
|
3583
3666
|
return _el$;
|
|
3584
3667
|
})();
|
|
3585
3668
|
}
|
|
@@ -4574,7 +4657,7 @@ var componentInfo18 = {
|
|
|
4574
4657
|
name: "image",
|
|
4575
4658
|
bubble: true,
|
|
4576
4659
|
type: "file",
|
|
4577
|
-
allowedFileTypes:
|
|
4660
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4578
4661
|
required: true
|
|
4579
4662
|
}],
|
|
4580
4663
|
noWrap: true,
|
|
@@ -4618,14 +4701,14 @@ var componentInfo19 = {
|
|
|
4618
4701
|
inputs: [{
|
|
4619
4702
|
name: "video",
|
|
4620
4703
|
type: "file",
|
|
4621
|
-
allowedFileTypes:
|
|
4704
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
4622
4705
|
bubble: true,
|
|
4623
4706
|
defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
|
|
4624
4707
|
required: true
|
|
4625
4708
|
}, {
|
|
4626
4709
|
name: "posterImage",
|
|
4627
4710
|
type: "file",
|
|
4628
|
-
allowedFileTypes:
|
|
4711
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4629
4712
|
helperText: "Image to show before the video plays"
|
|
4630
4713
|
}, {
|
|
4631
4714
|
name: "autoPlay",
|
|
@@ -4881,7 +4964,7 @@ var createRegisterComponentMessage = (info) => ({
|
|
|
4881
4964
|
var serializeFn = (fnValue) => {
|
|
4882
4965
|
const fnStr = fnValue.toString().trim();
|
|
4883
4966
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
4884
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4967
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4885
4968
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
4886
4969
|
};
|
|
4887
4970
|
function serializeIncludingFunctions(info) {
|
|
@@ -4964,7 +5047,7 @@ function getPreviewContent(_searchParams) {
|
|
|
4964
5047
|
}
|
|
4965
5048
|
|
|
4966
5049
|
// src/constants/sdk-version.ts
|
|
4967
|
-
var SDK_VERSION = "3.0.
|
|
5050
|
+
var SDK_VERSION = "3.0.2";
|
|
4968
5051
|
|
|
4969
5052
|
// src/helpers/sdk-headers.ts
|
|
4970
5053
|
var getSdkHeaders = () => ({
|
|
@@ -5029,6 +5112,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
|
|
|
5029
5112
|
}
|
|
5030
5113
|
return _res;
|
|
5031
5114
|
}
|
|
5115
|
+
function unflatten(obj) {
|
|
5116
|
+
const result = {};
|
|
5117
|
+
for (const key in obj) {
|
|
5118
|
+
const parts = key.split(".");
|
|
5119
|
+
let current = result;
|
|
5120
|
+
for (let i = 0; i < parts.length; i++) {
|
|
5121
|
+
const part = parts[i];
|
|
5122
|
+
if (i === parts.length - 1) {
|
|
5123
|
+
current[part] = obj[key];
|
|
5124
|
+
} else {
|
|
5125
|
+
current[part] = current[part] || {};
|
|
5126
|
+
current = current[part];
|
|
5127
|
+
}
|
|
5128
|
+
}
|
|
5129
|
+
}
|
|
5130
|
+
return result;
|
|
5131
|
+
}
|
|
5032
5132
|
|
|
5033
5133
|
// src/types/api-version.ts
|
|
5034
5134
|
var DEFAULT_API_VERSION = "v3";
|
|
@@ -5093,7 +5193,7 @@ var generateContentUrl = (options) => {
|
|
|
5093
5193
|
url.searchParams.set("noTraverse", String(noTraverse));
|
|
5094
5194
|
url.searchParams.set("includeRefs", String(true));
|
|
5095
5195
|
const finalLocale = locale || userAttributes?.locale;
|
|
5096
|
-
let finalUserAttributes = userAttributes;
|
|
5196
|
+
let finalUserAttributes = userAttributes || {};
|
|
5097
5197
|
if (finalLocale) {
|
|
5098
5198
|
url.searchParams.set("locale", finalLocale);
|
|
5099
5199
|
finalUserAttributes = {
|
|
@@ -5131,11 +5231,15 @@ var generateContentUrl = (options) => {
|
|
|
5131
5231
|
...getBuilderSearchParamsFromWindow(),
|
|
5132
5232
|
...normalizeSearchParams(options.options || {})
|
|
5133
5233
|
};
|
|
5234
|
+
finalUserAttributes = {
|
|
5235
|
+
...finalUserAttributes,
|
|
5236
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
5237
|
+
};
|
|
5134
5238
|
const flattened = flatten(queryOptions);
|
|
5135
5239
|
for (const key in flattened) {
|
|
5136
5240
|
url.searchParams.set(key, String(flattened[key]));
|
|
5137
5241
|
}
|
|
5138
|
-
if (finalUserAttributes) {
|
|
5242
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
5139
5243
|
url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
|
|
5140
5244
|
}
|
|
5141
5245
|
if (query) {
|
|
@@ -5148,6 +5252,28 @@ var generateContentUrl = (options) => {
|
|
|
5148
5252
|
}
|
|
5149
5253
|
return url;
|
|
5150
5254
|
};
|
|
5255
|
+
var getUserAttributesFromQueryOptions = (queryOptions) => {
|
|
5256
|
+
const newUserAttributes = {};
|
|
5257
|
+
for (const key in queryOptions) {
|
|
5258
|
+
if (key.startsWith("userAttributes.")) {
|
|
5259
|
+
newUserAttributes[key] = queryOptions[key];
|
|
5260
|
+
delete queryOptions[key];
|
|
5261
|
+
}
|
|
5262
|
+
}
|
|
5263
|
+
return newUserAttributes;
|
|
5264
|
+
};
|
|
5265
|
+
var getUserAttributesAsJSON = (queryOptions) => {
|
|
5266
|
+
if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
|
|
5267
|
+
queryOptions["userAttributes.urlPath"] = window.location.pathname;
|
|
5268
|
+
queryOptions["userAttributes.host"] = window.location.host;
|
|
5269
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
5270
|
+
const {
|
|
5271
|
+
userAttributes
|
|
5272
|
+
} = unflatten(queryOptionsForUserAttributes);
|
|
5273
|
+
return userAttributes;
|
|
5274
|
+
}
|
|
5275
|
+
return {};
|
|
5276
|
+
};
|
|
5151
5277
|
|
|
5152
5278
|
// src/functions/get-content/index.ts
|
|
5153
5279
|
var checkContentHasResults = (content) => "results" in content;
|
|
@@ -5682,6 +5808,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
5682
5808
|
};
|
|
5683
5809
|
};
|
|
5684
5810
|
|
|
5811
|
+
// src/components/content/components/enable-editor.helpers.ts
|
|
5812
|
+
var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
|
|
5813
|
+
var needsElementRefDivForEditing = () => {
|
|
5814
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
5815
|
+
};
|
|
5816
|
+
|
|
5685
5817
|
// src/components/content/components/styles.helpers.ts
|
|
5686
5818
|
var getCssFromFont = (font) => {
|
|
5687
5819
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -5917,8 +6049,10 @@ function EnableEditor(props) {
|
|
|
5917
6049
|
} : {}
|
|
5918
6050
|
});
|
|
5919
6051
|
Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
5920
|
-
|
|
5921
|
-
|
|
6052
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
6053
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
6054
|
+
window.parent?.postMessage(message, "*");
|
|
6055
|
+
}
|
|
5922
6056
|
});
|
|
5923
6057
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
5924
6058
|
}
|
|
@@ -5941,11 +6075,16 @@ function EnableEditor(props) {
|
|
|
5941
6075
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
5942
6076
|
const searchParamPreviewId = searchParams.get(`builder.overrides.${searchParamPreviewModel}`);
|
|
5943
6077
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
5944
|
-
if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
6078
|
+
if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
5945
6079
|
fetchOneEntry({
|
|
5946
|
-
model: props.model,
|
|
6080
|
+
model: props.model || "",
|
|
5947
6081
|
apiKey: props.apiKey,
|
|
5948
|
-
apiVersion: props.builderContextSignal.apiVersion
|
|
6082
|
+
apiVersion: props.builderContextSignal.apiVersion,
|
|
6083
|
+
...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
|
|
6084
|
+
query: {
|
|
6085
|
+
id: props.context.symbolId
|
|
6086
|
+
}
|
|
6087
|
+
} : {}
|
|
5949
6088
|
}).then((content) => {
|
|
5950
6089
|
if (content) {
|
|
5951
6090
|
mergeNewContent(content);
|
|
@@ -5990,7 +6129,7 @@ function EnableEditor(props) {
|
|
|
5990
6129
|
get children() {
|
|
5991
6130
|
return createComponent(Show, {
|
|
5992
6131
|
get when() {
|
|
5993
|
-
return props.builderContextSignal.content;
|
|
6132
|
+
return props.builderContextSignal.content || needsElementRefDivForEditing();
|
|
5994
6133
|
},
|
|
5995
6134
|
get children() {
|
|
5996
6135
|
return createComponent(Dynamic, mergeProps({
|
|
@@ -6008,6 +6147,11 @@ function EnableEditor(props) {
|
|
|
6008
6147
|
},
|
|
6009
6148
|
get ["builder-model"]() {
|
|
6010
6149
|
return props.model;
|
|
6150
|
+
},
|
|
6151
|
+
get style() {
|
|
6152
|
+
return {
|
|
6153
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
6154
|
+
};
|
|
6011
6155
|
}
|
|
6012
6156
|
}, {}, showContentProps, () => props.contentWrapperProps, {
|
|
6013
6157
|
get component() {
|
|
@@ -6090,15 +6234,7 @@ function ContentComponent(props) {
|
|
|
6090
6234
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
6091
6235
|
contentId: props.content?.id
|
|
6092
6236
|
}));
|
|
6093
|
-
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents
|
|
6094
|
-
models
|
|
6095
|
-
}) => {
|
|
6096
|
-
if (!models?.length)
|
|
6097
|
-
return true;
|
|
6098
|
-
if (!props.model)
|
|
6099
|
-
return true;
|
|
6100
|
-
return models.includes(props.model);
|
|
6101
|
-
}) || []].reduce((acc, {
|
|
6237
|
+
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
6102
6238
|
component,
|
|
6103
6239
|
...info
|
|
6104
6240
|
}) => ({
|
|
@@ -6124,15 +6260,7 @@ function ContentComponent(props) {
|
|
|
6124
6260
|
canTrack: props.canTrack,
|
|
6125
6261
|
apiKey: props.apiKey,
|
|
6126
6262
|
apiVersion: props.apiVersion,
|
|
6127
|
-
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents
|
|
6128
|
-
models
|
|
6129
|
-
}) => {
|
|
6130
|
-
if (!models?.length)
|
|
6131
|
-
return true;
|
|
6132
|
-
if (!props.model)
|
|
6133
|
-
return true;
|
|
6134
|
-
return models.includes(props.model);
|
|
6135
|
-
}) || []].reduce((acc, {
|
|
6263
|
+
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
6136
6264
|
component: _,
|
|
6137
6265
|
...info
|
|
6138
6266
|
}) => ({
|
|
@@ -6142,7 +6270,8 @@ function ContentComponent(props) {
|
|
|
6142
6270
|
inheritedStyles: {},
|
|
6143
6271
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
6144
6272
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
6145
|
-
nonce: props.nonce || ""
|
|
6273
|
+
nonce: props.nonce || "",
|
|
6274
|
+
model: props.model || ""
|
|
6146
6275
|
});
|
|
6147
6276
|
function contentSetState(newRootState) {
|
|
6148
6277
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|