@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/edge/dev.js
CHANGED
|
@@ -120,27 +120,11 @@ var builder_context_default = createContext({
|
|
|
120
120
|
inheritedStyles: {},
|
|
121
121
|
BlocksWrapper: "div",
|
|
122
122
|
BlocksWrapperProps: {},
|
|
123
|
-
nonce: ""
|
|
123
|
+
nonce: "",
|
|
124
|
+
model: ""
|
|
124
125
|
});
|
|
125
126
|
var components_context_default = createContext({ registeredComponents: {} });
|
|
126
127
|
|
|
127
|
-
// src/functions/get-block-component-options.ts
|
|
128
|
-
function getBlockComponentOptions(block) {
|
|
129
|
-
return {
|
|
130
|
-
...block.component?.options,
|
|
131
|
-
...block.options
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// src/helpers/omit.ts
|
|
136
|
-
function omit(obj, ...values) {
|
|
137
|
-
const newObject = Object.assign({}, obj);
|
|
138
|
-
for (const key of values) {
|
|
139
|
-
delete newObject[key];
|
|
140
|
-
}
|
|
141
|
-
return newObject;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
128
|
// src/helpers/logger.ts
|
|
145
129
|
var MSG_PREFIX = "[Builder.io]: ";
|
|
146
130
|
var logger = {
|
|
@@ -3475,10 +3459,8 @@ var runInEdge = ({
|
|
|
3475
3459
|
return `var ${key} = ${jsonValName} === undefined ? undefined : JSON.parse(${jsonValName});`;
|
|
3476
3460
|
}).join("\n");
|
|
3477
3461
|
const cleanedCode = processCode(code);
|
|
3478
|
-
if (cleanedCode === "")
|
|
3479
|
-
logger.warn("Skipping evaluation of empty code block.");
|
|
3462
|
+
if (cleanedCode === "")
|
|
3480
3463
|
return;
|
|
3481
|
-
}
|
|
3482
3464
|
const transformed = `
|
|
3483
3465
|
function theFunction() {
|
|
3484
3466
|
${prependedCode}
|
|
@@ -3584,6 +3566,109 @@ function evaluate({
|
|
|
3584
3566
|
}
|
|
3585
3567
|
}
|
|
3586
3568
|
|
|
3569
|
+
// src/functions/get-block-component-options.ts
|
|
3570
|
+
function getBlockComponentOptions(block, context) {
|
|
3571
|
+
return {
|
|
3572
|
+
...block.component?.options,
|
|
3573
|
+
...block.options,
|
|
3574
|
+
...evaluateTextComponentTextOption(block, context)
|
|
3575
|
+
};
|
|
3576
|
+
}
|
|
3577
|
+
var evaluateTextComponentTextOption = (block, context) => {
|
|
3578
|
+
if (block.component?.name === "Text" && block.component.options?.text && typeof block.component.options.text === "string") {
|
|
3579
|
+
return {
|
|
3580
|
+
...block.component.options,
|
|
3581
|
+
text: block.component.options.text.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
3582
|
+
code: group,
|
|
3583
|
+
context,
|
|
3584
|
+
localState: context.localState,
|
|
3585
|
+
rootState: context.rootState,
|
|
3586
|
+
rootSetState: context.rootSetState
|
|
3587
|
+
}))
|
|
3588
|
+
};
|
|
3589
|
+
}
|
|
3590
|
+
};
|
|
3591
|
+
|
|
3592
|
+
// src/helpers/omit.ts
|
|
3593
|
+
function omit(obj, ...values) {
|
|
3594
|
+
const newObject = Object.assign({}, obj);
|
|
3595
|
+
for (const key of values) {
|
|
3596
|
+
delete newObject[key];
|
|
3597
|
+
}
|
|
3598
|
+
return newObject;
|
|
3599
|
+
}
|
|
3600
|
+
|
|
3601
|
+
// src/functions/traverse.ts
|
|
3602
|
+
function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
3603
|
+
if (obj == null || typeof obj !== "object") {
|
|
3604
|
+
callback(obj, (newValue) => {
|
|
3605
|
+
if (parent2 !== null && key !== null) {
|
|
3606
|
+
parent2[key] = newValue;
|
|
3607
|
+
}
|
|
3608
|
+
});
|
|
3609
|
+
return;
|
|
3610
|
+
}
|
|
3611
|
+
if (visited.has(obj)) {
|
|
3612
|
+
return;
|
|
3613
|
+
}
|
|
3614
|
+
visited.add(obj);
|
|
3615
|
+
if (Array.isArray(obj)) {
|
|
3616
|
+
obj.forEach((item, index) => {
|
|
3617
|
+
const update = (newValue) => {
|
|
3618
|
+
obj[index] = newValue;
|
|
3619
|
+
};
|
|
3620
|
+
callback(item, update);
|
|
3621
|
+
traverse(item, callback, obj, index, visited);
|
|
3622
|
+
});
|
|
3623
|
+
} else {
|
|
3624
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
3625
|
+
const update = (newValue) => {
|
|
3626
|
+
obj[key2] = newValue;
|
|
3627
|
+
};
|
|
3628
|
+
callback(value, update);
|
|
3629
|
+
traverse(value, callback, obj, key2, visited);
|
|
3630
|
+
});
|
|
3631
|
+
}
|
|
3632
|
+
}
|
|
3633
|
+
|
|
3634
|
+
// src/functions/extract-localized-values.ts
|
|
3635
|
+
function isLocalizedField(value) {
|
|
3636
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
3637
|
+
}
|
|
3638
|
+
function containsLocalizedValues(data) {
|
|
3639
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
3640
|
+
return false;
|
|
3641
|
+
}
|
|
3642
|
+
let hasLocalizedValues = false;
|
|
3643
|
+
traverse(data, (value) => {
|
|
3644
|
+
if (isLocalizedField(value)) {
|
|
3645
|
+
hasLocalizedValues = true;
|
|
3646
|
+
return;
|
|
3647
|
+
}
|
|
3648
|
+
});
|
|
3649
|
+
return hasLocalizedValues;
|
|
3650
|
+
}
|
|
3651
|
+
function extractLocalizedValues(data, locale) {
|
|
3652
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
3653
|
+
return {};
|
|
3654
|
+
}
|
|
3655
|
+
traverse(data, (value, update) => {
|
|
3656
|
+
if (isLocalizedField(value)) {
|
|
3657
|
+
update(value[locale] ?? void 0);
|
|
3658
|
+
}
|
|
3659
|
+
});
|
|
3660
|
+
return data;
|
|
3661
|
+
}
|
|
3662
|
+
function resolveLocalizedValues(block, locale) {
|
|
3663
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
3664
|
+
if (!locale) {
|
|
3665
|
+
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");
|
|
3666
|
+
}
|
|
3667
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
3668
|
+
}
|
|
3669
|
+
return block;
|
|
3670
|
+
}
|
|
3671
|
+
|
|
3587
3672
|
// src/functions/fast-clone.ts
|
|
3588
3673
|
var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
3589
3674
|
|
|
@@ -3677,23 +3762,19 @@ var evaluateBindings = ({
|
|
|
3677
3762
|
function getProcessedBlock({
|
|
3678
3763
|
block,
|
|
3679
3764
|
context,
|
|
3680
|
-
shouldEvaluateBindings,
|
|
3681
3765
|
localState,
|
|
3682
3766
|
rootState,
|
|
3683
3767
|
rootSetState
|
|
3684
3768
|
}) {
|
|
3685
|
-
|
|
3686
|
-
|
|
3687
|
-
|
|
3688
|
-
|
|
3689
|
-
|
|
3690
|
-
|
|
3691
|
-
|
|
3692
|
-
|
|
3693
|
-
|
|
3694
|
-
} else {
|
|
3695
|
-
return transformedBlock;
|
|
3696
|
-
}
|
|
3769
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
3770
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
3771
|
+
return evaluateBindings({
|
|
3772
|
+
block: transformedBlock,
|
|
3773
|
+
localState,
|
|
3774
|
+
rootState,
|
|
3775
|
+
rootSetState,
|
|
3776
|
+
context
|
|
3777
|
+
});
|
|
3697
3778
|
}
|
|
3698
3779
|
|
|
3699
3780
|
// src/functions/camel-to-kebab-case.ts
|
|
@@ -3940,16 +4021,24 @@ function mapStyleObjToStrIfNeeded(style) {
|
|
|
3940
4021
|
}
|
|
3941
4022
|
|
|
3942
4023
|
// src/components/block/block.helpers.ts
|
|
4024
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
4025
|
+
if (!component)
|
|
4026
|
+
return true;
|
|
4027
|
+
if (!model)
|
|
4028
|
+
return false;
|
|
4029
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
4030
|
+
};
|
|
3943
4031
|
var getComponent = ({
|
|
3944
4032
|
block,
|
|
3945
|
-
registeredComponents
|
|
4033
|
+
registeredComponents,
|
|
4034
|
+
model
|
|
3946
4035
|
}) => {
|
|
3947
4036
|
const componentName = block.component?.name;
|
|
3948
4037
|
if (!componentName) {
|
|
3949
4038
|
return null;
|
|
3950
4039
|
}
|
|
3951
4040
|
const ref = registeredComponents[componentName];
|
|
3952
|
-
if (!ref) {
|
|
4041
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
3953
4042
|
console.warn(`
|
|
3954
4043
|
Could not find a registered component named "${componentName}".
|
|
3955
4044
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
@@ -4003,11 +4092,15 @@ var provideLinkComponent = (block, linkComponent) => {
|
|
|
4003
4092
|
};
|
|
4004
4093
|
return {};
|
|
4005
4094
|
};
|
|
4006
|
-
var provideRegisteredComponents = (block, registeredComponents) => {
|
|
4007
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
4095
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
4096
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
4097
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
4098
|
+
return !checkIsComponentRestricted(component, model);
|
|
4099
|
+
}));
|
|
4008
4100
|
return {
|
|
4009
|
-
builderComponents:
|
|
4101
|
+
builderComponents: filteredRegisteredComponents
|
|
4010
4102
|
};
|
|
4103
|
+
}
|
|
4011
4104
|
return {};
|
|
4012
4105
|
};
|
|
4013
4106
|
var provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -4461,15 +4554,15 @@ function Block(props) {
|
|
|
4461
4554
|
localState: props.context.localState,
|
|
4462
4555
|
rootState: props.context.rootState,
|
|
4463
4556
|
rootSetState: props.context.rootSetState,
|
|
4464
|
-
context: props.context.context
|
|
4465
|
-
shouldEvaluateBindings: true
|
|
4557
|
+
context: props.context.context
|
|
4466
4558
|
});
|
|
4467
4559
|
return blockToUse;
|
|
4468
4560
|
});
|
|
4469
4561
|
const blockComponent = createMemo(() => {
|
|
4470
4562
|
return getComponent({
|
|
4471
4563
|
block: processedBlock(),
|
|
4472
|
-
registeredComponents: props.registeredComponents
|
|
4564
|
+
registeredComponents: props.registeredComponents,
|
|
4565
|
+
model: props.context.model
|
|
4473
4566
|
});
|
|
4474
4567
|
});
|
|
4475
4568
|
const Tag = createMemo(() => {
|
|
@@ -4498,11 +4591,11 @@ function Block(props) {
|
|
|
4498
4591
|
blockChildren: processedBlock().children ?? [],
|
|
4499
4592
|
componentRef: blockComponent()?.component,
|
|
4500
4593
|
componentOptions: {
|
|
4501
|
-
...getBlockComponentOptions(processedBlock()),
|
|
4594
|
+
...getBlockComponentOptions(processedBlock(), props.context),
|
|
4502
4595
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
4503
4596
|
...provideBuilderContext(blockComponent(), props.context),
|
|
4504
4597
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
4505
|
-
...provideRegisteredComponents(blockComponent(), props.registeredComponents)
|
|
4598
|
+
...provideRegisteredComponents(blockComponent(), props.registeredComponents, props.context.model)
|
|
4506
4599
|
},
|
|
4507
4600
|
context: props.context,
|
|
4508
4601
|
linkComponent: props.linkComponent,
|
|
@@ -5100,16 +5193,16 @@ function getSrcSet(url) {
|
|
|
5100
5193
|
// src/blocks/image/image.tsx
|
|
5101
5194
|
var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
|
|
5102
5195
|
var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
|
|
5103
|
-
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-
|
|
5104
|
-
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-
|
|
5105
|
-
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-
|
|
5196
|
+
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-070d7e88">`);
|
|
5197
|
+
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-070d7e88-2>`);
|
|
5198
|
+
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-070d7e88 {
|
|
5106
5199
|
opacity: 1;
|
|
5107
5200
|
transition: opacity 0.2s ease-in-out;
|
|
5108
|
-
}.div-
|
|
5201
|
+
}.div-070d7e88 {
|
|
5109
5202
|
width: 100%;
|
|
5110
5203
|
pointer-events: none;
|
|
5111
5204
|
font-size: 0;
|
|
5112
|
-
}.div-
|
|
5205
|
+
}.div-070d7e88-2 {
|
|
5113
5206
|
display: flex;
|
|
5114
5207
|
flex-direction: column;
|
|
5115
5208
|
align-items: stretch;
|
|
@@ -5125,7 +5218,7 @@ function Image(props) {
|
|
|
5125
5218
|
const url = imageToUse;
|
|
5126
5219
|
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
5127
5220
|
// images, otherwise you can supply this prop manually
|
|
5128
|
-
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
5221
|
+
!(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
5129
5222
|
return props.srcset;
|
|
5130
5223
|
}
|
|
5131
5224
|
if (props.noWebp) {
|
|
@@ -5174,7 +5267,7 @@ function Image(props) {
|
|
|
5174
5267
|
}
|
|
5175
5268
|
}), _el$3);
|
|
5176
5269
|
effect((_p$) => {
|
|
5177
|
-
const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-
|
|
5270
|
+
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 = {
|
|
5178
5271
|
"object-position": props.backgroundPosition || "center",
|
|
5179
5272
|
"object-fit": props.backgroundSize || "cover",
|
|
5180
5273
|
...aspectRatioCss()
|
|
@@ -6040,6 +6133,10 @@ var componentInfo4 = {
|
|
|
6040
6133
|
noWrap: true
|
|
6041
6134
|
};
|
|
6042
6135
|
|
|
6136
|
+
// src/constants/file-types.ts
|
|
6137
|
+
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"];
|
|
6138
|
+
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"];
|
|
6139
|
+
|
|
6043
6140
|
// src/blocks/image/component-info.ts
|
|
6044
6141
|
var componentInfo5 = {
|
|
6045
6142
|
name: "Image",
|
|
@@ -6056,7 +6153,7 @@ var componentInfo5 = {
|
|
|
6056
6153
|
name: "image",
|
|
6057
6154
|
type: "file",
|
|
6058
6155
|
bubble: true,
|
|
6059
|
-
allowedFileTypes:
|
|
6156
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
6060
6157
|
required: true,
|
|
6061
6158
|
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
|
|
6062
6159
|
onChange: (options) => {
|
|
@@ -6574,26 +6671,10 @@ var componentInfo10 = {
|
|
|
6574
6671
|
};
|
|
6575
6672
|
var _tmpl$10 = /* @__PURE__ */ template(`<div class=builder-text>`);
|
|
6576
6673
|
function Text(props) {
|
|
6577
|
-
const processedText = createMemo(() => {
|
|
6578
|
-
const context = props.builderContext;
|
|
6579
|
-
const {
|
|
6580
|
-
context: contextContext,
|
|
6581
|
-
localState,
|
|
6582
|
-
rootState,
|
|
6583
|
-
rootSetState
|
|
6584
|
-
} = context;
|
|
6585
|
-
return String(props.text?.toString() || "").replace(/{{([^}]+)}}/g, (match, group) => evaluate({
|
|
6586
|
-
code: group,
|
|
6587
|
-
context: contextContext,
|
|
6588
|
-
localState,
|
|
6589
|
-
rootState,
|
|
6590
|
-
rootSetState
|
|
6591
|
-
}));
|
|
6592
|
-
});
|
|
6593
6674
|
return (() => {
|
|
6594
6675
|
const _el$ = _tmpl$10();
|
|
6595
6676
|
_el$.style.setProperty("outline", "none");
|
|
6596
|
-
effect(() => _el$.innerHTML =
|
|
6677
|
+
effect(() => _el$.innerHTML = props.text?.toString() || "");
|
|
6597
6678
|
return _el$;
|
|
6598
6679
|
})();
|
|
6599
6680
|
}
|
|
@@ -7588,7 +7669,7 @@ var componentInfo18 = {
|
|
|
7588
7669
|
name: "image",
|
|
7589
7670
|
bubble: true,
|
|
7590
7671
|
type: "file",
|
|
7591
|
-
allowedFileTypes:
|
|
7672
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
7592
7673
|
required: true
|
|
7593
7674
|
}],
|
|
7594
7675
|
noWrap: true,
|
|
@@ -7632,14 +7713,14 @@ var componentInfo19 = {
|
|
|
7632
7713
|
inputs: [{
|
|
7633
7714
|
name: "video",
|
|
7634
7715
|
type: "file",
|
|
7635
|
-
allowedFileTypes:
|
|
7716
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
7636
7717
|
bubble: true,
|
|
7637
7718
|
defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
|
|
7638
7719
|
required: true
|
|
7639
7720
|
}, {
|
|
7640
7721
|
name: "posterImage",
|
|
7641
7722
|
type: "file",
|
|
7642
|
-
allowedFileTypes:
|
|
7723
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
7643
7724
|
helperText: "Image to show before the video plays"
|
|
7644
7725
|
}, {
|
|
7645
7726
|
name: "autoPlay",
|
|
@@ -7895,7 +7976,7 @@ var createRegisterComponentMessage = (info) => ({
|
|
|
7895
7976
|
var serializeFn = (fnValue) => {
|
|
7896
7977
|
const fnStr = fnValue.toString().trim();
|
|
7897
7978
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
7898
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
7979
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
7899
7980
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
7900
7981
|
};
|
|
7901
7982
|
function serializeIncludingFunctions(info) {
|
|
@@ -7978,7 +8059,7 @@ function getPreviewContent(_searchParams) {
|
|
|
7978
8059
|
}
|
|
7979
8060
|
|
|
7980
8061
|
// src/constants/sdk-version.ts
|
|
7981
|
-
var SDK_VERSION = "3.0.
|
|
8062
|
+
var SDK_VERSION = "3.0.2";
|
|
7982
8063
|
|
|
7983
8064
|
// src/helpers/sdk-headers.ts
|
|
7984
8065
|
var getSdkHeaders = () => ({
|
|
@@ -8043,6 +8124,23 @@ function flattenMongoQuery(obj, _current, _res = {}) {
|
|
|
8043
8124
|
}
|
|
8044
8125
|
return _res;
|
|
8045
8126
|
}
|
|
8127
|
+
function unflatten(obj) {
|
|
8128
|
+
const result = {};
|
|
8129
|
+
for (const key in obj) {
|
|
8130
|
+
const parts = key.split(".");
|
|
8131
|
+
let current = result;
|
|
8132
|
+
for (let i = 0; i < parts.length; i++) {
|
|
8133
|
+
const part = parts[i];
|
|
8134
|
+
if (i === parts.length - 1) {
|
|
8135
|
+
current[part] = obj[key];
|
|
8136
|
+
} else {
|
|
8137
|
+
current[part] = current[part] || {};
|
|
8138
|
+
current = current[part];
|
|
8139
|
+
}
|
|
8140
|
+
}
|
|
8141
|
+
}
|
|
8142
|
+
return result;
|
|
8143
|
+
}
|
|
8046
8144
|
|
|
8047
8145
|
// src/types/api-version.ts
|
|
8048
8146
|
var DEFAULT_API_VERSION = "v3";
|
|
@@ -8107,7 +8205,7 @@ var generateContentUrl = (options) => {
|
|
|
8107
8205
|
url.searchParams.set("noTraverse", String(noTraverse));
|
|
8108
8206
|
url.searchParams.set("includeRefs", String(true));
|
|
8109
8207
|
const finalLocale = locale || userAttributes?.locale;
|
|
8110
|
-
let finalUserAttributes = userAttributes;
|
|
8208
|
+
let finalUserAttributes = userAttributes || {};
|
|
8111
8209
|
if (finalLocale) {
|
|
8112
8210
|
url.searchParams.set("locale", finalLocale);
|
|
8113
8211
|
finalUserAttributes = {
|
|
@@ -8145,11 +8243,15 @@ var generateContentUrl = (options) => {
|
|
|
8145
8243
|
...getBuilderSearchParamsFromWindow(),
|
|
8146
8244
|
...normalizeSearchParams(options.options || {})
|
|
8147
8245
|
};
|
|
8246
|
+
finalUserAttributes = {
|
|
8247
|
+
...finalUserAttributes,
|
|
8248
|
+
...getUserAttributesAsJSON(queryOptions)
|
|
8249
|
+
};
|
|
8148
8250
|
const flattened = flatten(queryOptions);
|
|
8149
8251
|
for (const key in flattened) {
|
|
8150
8252
|
url.searchParams.set(key, String(flattened[key]));
|
|
8151
8253
|
}
|
|
8152
|
-
if (finalUserAttributes) {
|
|
8254
|
+
if (Object.keys(finalUserAttributes).length > 0) {
|
|
8153
8255
|
url.searchParams.set("userAttributes", JSON.stringify(finalUserAttributes));
|
|
8154
8256
|
}
|
|
8155
8257
|
if (query) {
|
|
@@ -8162,6 +8264,28 @@ var generateContentUrl = (options) => {
|
|
|
8162
8264
|
}
|
|
8163
8265
|
return url;
|
|
8164
8266
|
};
|
|
8267
|
+
var getUserAttributesFromQueryOptions = (queryOptions) => {
|
|
8268
|
+
const newUserAttributes = {};
|
|
8269
|
+
for (const key in queryOptions) {
|
|
8270
|
+
if (key.startsWith("userAttributes.")) {
|
|
8271
|
+
newUserAttributes[key] = queryOptions[key];
|
|
8272
|
+
delete queryOptions[key];
|
|
8273
|
+
}
|
|
8274
|
+
}
|
|
8275
|
+
return newUserAttributes;
|
|
8276
|
+
};
|
|
8277
|
+
var getUserAttributesAsJSON = (queryOptions) => {
|
|
8278
|
+
if (isBrowser() && queryOptions["preview"] === "BUILDER_STUDIO") {
|
|
8279
|
+
queryOptions["userAttributes.urlPath"] = window.location.pathname;
|
|
8280
|
+
queryOptions["userAttributes.host"] = window.location.host;
|
|
8281
|
+
const queryOptionsForUserAttributes = getUserAttributesFromQueryOptions(queryOptions);
|
|
8282
|
+
const {
|
|
8283
|
+
userAttributes
|
|
8284
|
+
} = unflatten(queryOptionsForUserAttributes);
|
|
8285
|
+
return userAttributes;
|
|
8286
|
+
}
|
|
8287
|
+
return {};
|
|
8288
|
+
};
|
|
8165
8289
|
|
|
8166
8290
|
// src/functions/get-content/index.ts
|
|
8167
8291
|
var checkContentHasResults = (content) => "results" in content;
|
|
@@ -8696,6 +8820,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
8696
8820
|
};
|
|
8697
8821
|
};
|
|
8698
8822
|
|
|
8823
|
+
// src/components/content/components/enable-editor.helpers.ts
|
|
8824
|
+
var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
|
|
8825
|
+
var needsElementRefDivForEditing = () => {
|
|
8826
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
8827
|
+
};
|
|
8828
|
+
|
|
8699
8829
|
// src/components/content/components/styles.helpers.ts
|
|
8700
8830
|
var getCssFromFont = (font) => {
|
|
8701
8831
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -8931,8 +9061,10 @@ function EnableEditor(props) {
|
|
|
8931
9061
|
} : {}
|
|
8932
9062
|
});
|
|
8933
9063
|
Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
8934
|
-
|
|
8935
|
-
|
|
9064
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
9065
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
9066
|
+
window.parent?.postMessage(message, "*");
|
|
9067
|
+
}
|
|
8936
9068
|
});
|
|
8937
9069
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
8938
9070
|
}
|
|
@@ -8955,11 +9087,16 @@ function EnableEditor(props) {
|
|
|
8955
9087
|
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
8956
9088
|
const searchParamPreviewId = searchParams.get(`builder.overrides.${searchParamPreviewModel}`);
|
|
8957
9089
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
8958
|
-
if (searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
9090
|
+
if (searchParamPreviewModel === "BUILDER_STUDIO" || searchParamPreviewModel === props.model && previewApiKey === props.apiKey && (!props.content || searchParamPreviewId === props.content.id)) {
|
|
8959
9091
|
fetchOneEntry({
|
|
8960
|
-
model: props.model,
|
|
9092
|
+
model: props.model || "",
|
|
8961
9093
|
apiKey: props.apiKey,
|
|
8962
|
-
apiVersion: props.builderContextSignal.apiVersion
|
|
9094
|
+
apiVersion: props.builderContextSignal.apiVersion,
|
|
9095
|
+
...searchParamPreviewModel === "BUILDER_STUDIO" && props.context?.symbolId ? {
|
|
9096
|
+
query: {
|
|
9097
|
+
id: props.context.symbolId
|
|
9098
|
+
}
|
|
9099
|
+
} : {}
|
|
8963
9100
|
}).then((content) => {
|
|
8964
9101
|
if (content) {
|
|
8965
9102
|
mergeNewContent(content);
|
|
@@ -9004,7 +9141,7 @@ function EnableEditor(props) {
|
|
|
9004
9141
|
get children() {
|
|
9005
9142
|
return createComponent(Show, {
|
|
9006
9143
|
get when() {
|
|
9007
|
-
return props.builderContextSignal.content;
|
|
9144
|
+
return props.builderContextSignal.content || needsElementRefDivForEditing();
|
|
9008
9145
|
},
|
|
9009
9146
|
get children() {
|
|
9010
9147
|
return createComponent(Dynamic, mergeProps({
|
|
@@ -9022,6 +9159,11 @@ function EnableEditor(props) {
|
|
|
9022
9159
|
},
|
|
9023
9160
|
get ["builder-model"]() {
|
|
9024
9161
|
return props.model;
|
|
9162
|
+
},
|
|
9163
|
+
get style() {
|
|
9164
|
+
return {
|
|
9165
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
9166
|
+
};
|
|
9025
9167
|
}
|
|
9026
9168
|
}, {}, showContentProps, () => props.contentWrapperProps, {
|
|
9027
9169
|
get component() {
|
|
@@ -9104,15 +9246,7 @@ function ContentComponent(props) {
|
|
|
9104
9246
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
9105
9247
|
contentId: props.content?.id
|
|
9106
9248
|
}));
|
|
9107
|
-
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents
|
|
9108
|
-
models
|
|
9109
|
-
}) => {
|
|
9110
|
-
if (!models?.length)
|
|
9111
|
-
return true;
|
|
9112
|
-
if (!props.model)
|
|
9113
|
-
return true;
|
|
9114
|
-
return models.includes(props.model);
|
|
9115
|
-
}) || []].reduce((acc, {
|
|
9249
|
+
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
9116
9250
|
component,
|
|
9117
9251
|
...info
|
|
9118
9252
|
}) => ({
|
|
@@ -9138,15 +9272,7 @@ function ContentComponent(props) {
|
|
|
9138
9272
|
canTrack: props.canTrack,
|
|
9139
9273
|
apiKey: props.apiKey,
|
|
9140
9274
|
apiVersion: props.apiVersion,
|
|
9141
|
-
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents
|
|
9142
|
-
models
|
|
9143
|
-
}) => {
|
|
9144
|
-
if (!models?.length)
|
|
9145
|
-
return true;
|
|
9146
|
-
if (!props.model)
|
|
9147
|
-
return true;
|
|
9148
|
-
return models.includes(props.model);
|
|
9149
|
-
}) || []].reduce((acc, {
|
|
9275
|
+
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
9150
9276
|
component: _,
|
|
9151
9277
|
...info
|
|
9152
9278
|
}) => ({
|
|
@@ -9156,7 +9282,8 @@ function ContentComponent(props) {
|
|
|
9156
9282
|
inheritedStyles: {},
|
|
9157
9283
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
9158
9284
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
9159
|
-
nonce: props.nonce || ""
|
|
9285
|
+
nonce: props.nonce || "",
|
|
9286
|
+
model: props.model || ""
|
|
9160
9287
|
});
|
|
9161
9288
|
function contentSetState(newRootState) {
|
|
9162
9289
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|