@builder.io/sdk-solid 2.0.31 → 3.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +5 -0
- package/lib/browser/dev.js +142 -59
- package/lib/browser/dev.jsx +143 -55
- package/lib/browser/index.js +139 -59
- package/lib/browser/index.jsx +142 -55
- package/lib/edge/dev.js +142 -59
- package/lib/edge/dev.jsx +143 -55
- package/lib/edge/index.js +139 -59
- package/lib/edge/index.jsx +142 -55
- package/lib/node/dev.js +142 -59
- package/lib/node/dev.jsx +143 -55
- package/lib/node/index.js +139 -59
- package/lib/node/index.jsx +142 -55
- package/package.json +1 -1
package/lib/browser/index.jsx
CHANGED
|
@@ -95,7 +95,8 @@ var builder_context_default = createContext({
|
|
|
95
95
|
inheritedStyles: {},
|
|
96
96
|
BlocksWrapper: "div",
|
|
97
97
|
BlocksWrapperProps: {},
|
|
98
|
-
nonce: ""
|
|
98
|
+
nonce: "",
|
|
99
|
+
model: ""
|
|
99
100
|
});
|
|
100
101
|
|
|
101
102
|
// src/context/components.context.ts
|
|
@@ -392,6 +393,76 @@ function evaluate({
|
|
|
392
393
|
}
|
|
393
394
|
}
|
|
394
395
|
|
|
396
|
+
// src/functions/traverse.ts
|
|
397
|
+
function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
398
|
+
if (obj == null || typeof obj !== "object") {
|
|
399
|
+
callback(obj, (newValue) => {
|
|
400
|
+
if (parent2 !== null && key !== null) {
|
|
401
|
+
parent2[key] = newValue;
|
|
402
|
+
}
|
|
403
|
+
});
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
if (visited.has(obj)) {
|
|
407
|
+
return;
|
|
408
|
+
}
|
|
409
|
+
visited.add(obj);
|
|
410
|
+
if (Array.isArray(obj)) {
|
|
411
|
+
obj.forEach((item, index) => {
|
|
412
|
+
const update = (newValue) => {
|
|
413
|
+
obj[index] = newValue;
|
|
414
|
+
};
|
|
415
|
+
callback(item, update);
|
|
416
|
+
traverse(item, callback, obj, index, visited);
|
|
417
|
+
});
|
|
418
|
+
} else {
|
|
419
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
420
|
+
const update = (newValue) => {
|
|
421
|
+
obj[key2] = newValue;
|
|
422
|
+
};
|
|
423
|
+
callback(value, update);
|
|
424
|
+
traverse(value, callback, obj, key2, visited);
|
|
425
|
+
});
|
|
426
|
+
}
|
|
427
|
+
}
|
|
428
|
+
|
|
429
|
+
// src/functions/extract-localized-values.ts
|
|
430
|
+
function isLocalizedField(value) {
|
|
431
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
432
|
+
}
|
|
433
|
+
function containsLocalizedValues(data) {
|
|
434
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
435
|
+
return false;
|
|
436
|
+
}
|
|
437
|
+
let hasLocalizedValues = false;
|
|
438
|
+
traverse(data, (value) => {
|
|
439
|
+
if (isLocalizedField(value)) {
|
|
440
|
+
hasLocalizedValues = true;
|
|
441
|
+
return;
|
|
442
|
+
}
|
|
443
|
+
});
|
|
444
|
+
return hasLocalizedValues;
|
|
445
|
+
}
|
|
446
|
+
function extractLocalizedValues(data, locale) {
|
|
447
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
448
|
+
return {};
|
|
449
|
+
}
|
|
450
|
+
traverse(data, (value, update) => {
|
|
451
|
+
if (isLocalizedField(value)) {
|
|
452
|
+
update(value[locale] ?? void 0);
|
|
453
|
+
}
|
|
454
|
+
});
|
|
455
|
+
return data;
|
|
456
|
+
}
|
|
457
|
+
function resolveLocalizedValues(block, locale) {
|
|
458
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
459
|
+
if (!locale) {
|
|
460
|
+
}
|
|
461
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
462
|
+
}
|
|
463
|
+
return block;
|
|
464
|
+
}
|
|
465
|
+
|
|
395
466
|
// src/functions/fast-clone.ts
|
|
396
467
|
var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
397
468
|
|
|
@@ -490,7 +561,8 @@ function getProcessedBlock({
|
|
|
490
561
|
rootState,
|
|
491
562
|
rootSetState
|
|
492
563
|
}) {
|
|
493
|
-
|
|
564
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
565
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
494
566
|
if (shouldEvaluateBindings) {
|
|
495
567
|
return evaluateBindings({
|
|
496
568
|
block: transformedBlock,
|
|
@@ -747,16 +819,24 @@ function mapStyleObjToStrIfNeeded(style) {
|
|
|
747
819
|
}
|
|
748
820
|
|
|
749
821
|
// src/components/block/block.helpers.ts
|
|
822
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
823
|
+
if (!component)
|
|
824
|
+
return true;
|
|
825
|
+
if (!model)
|
|
826
|
+
return false;
|
|
827
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
828
|
+
};
|
|
750
829
|
var getComponent = ({
|
|
751
830
|
block,
|
|
752
|
-
registeredComponents
|
|
831
|
+
registeredComponents,
|
|
832
|
+
model
|
|
753
833
|
}) => {
|
|
754
834
|
const componentName = block.component?.name;
|
|
755
835
|
if (!componentName) {
|
|
756
836
|
return null;
|
|
757
837
|
}
|
|
758
838
|
const ref = registeredComponents[componentName];
|
|
759
|
-
if (!ref) {
|
|
839
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
760
840
|
return void 0;
|
|
761
841
|
} else {
|
|
762
842
|
return ref;
|
|
@@ -807,11 +887,15 @@ var provideLinkComponent = (block, linkComponent) => {
|
|
|
807
887
|
};
|
|
808
888
|
return {};
|
|
809
889
|
};
|
|
810
|
-
var provideRegisteredComponents = (block, registeredComponents) => {
|
|
811
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
890
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
891
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
892
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
893
|
+
return !checkIsComponentRestricted(component, model);
|
|
894
|
+
}));
|
|
812
895
|
return {
|
|
813
|
-
builderComponents:
|
|
896
|
+
builderComponents: filteredRegisteredComponents
|
|
814
897
|
};
|
|
898
|
+
}
|
|
815
899
|
return {};
|
|
816
900
|
};
|
|
817
901
|
var provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -1215,7 +1299,8 @@ function Block(props) {
|
|
|
1215
1299
|
const blockComponent = createMemo5(() => {
|
|
1216
1300
|
return getComponent({
|
|
1217
1301
|
block: processedBlock(),
|
|
1218
|
-
registeredComponents: props.registeredComponents
|
|
1302
|
+
registeredComponents: props.registeredComponents,
|
|
1303
|
+
model: props.context.model
|
|
1219
1304
|
});
|
|
1220
1305
|
});
|
|
1221
1306
|
const Tag = createMemo5(() => {
|
|
@@ -1250,7 +1335,8 @@ function Block(props) {
|
|
|
1250
1335
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
1251
1336
|
...provideRegisteredComponents(
|
|
1252
1337
|
blockComponent(),
|
|
1253
|
-
props.registeredComponents
|
|
1338
|
+
props.registeredComponents,
|
|
1339
|
+
props.context.model
|
|
1254
1340
|
)
|
|
1255
1341
|
},
|
|
1256
1342
|
context: props.context,
|
|
@@ -1674,7 +1760,7 @@ function Image(props) {
|
|
|
1674
1760
|
const url = imageToUse;
|
|
1675
1761
|
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
1676
1762
|
// images, otherwise you can supply this prop manually
|
|
1677
|
-
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
1763
|
+
!(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
1678
1764
|
return props.srcset;
|
|
1679
1765
|
}
|
|
1680
1766
|
if (props.noWebp) {
|
|
@@ -1714,7 +1800,7 @@ function Image(props) {
|
|
|
1714
1800
|
<picture>
|
|
1715
1801
|
<Show8 when={webpSrcSet()}><source type="image/webp" srcset={webpSrcSet()} /></Show8>
|
|
1716
1802
|
<img
|
|
1717
|
-
class={"builder-image" + (props.className ? " " + props.className : "") + " img-
|
|
1803
|
+
class={"builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88"}
|
|
1718
1804
|
loading={props.highPriority ? "eager" : "lazy"}
|
|
1719
1805
|
fetchpriority={props.highPriority ? "high" : "auto"}
|
|
1720
1806
|
alt={props.altText}
|
|
@@ -1732,22 +1818,22 @@ function Image(props) {
|
|
|
1732
1818
|
<Show8
|
|
1733
1819
|
when={props.aspectRatio && !(props.builderBlock?.children?.length && props.fitContent)}
|
|
1734
1820
|
><div
|
|
1735
|
-
class="builder-image-sizer div-
|
|
1821
|
+
class="builder-image-sizer div-070d7e88"
|
|
1736
1822
|
style={{
|
|
1737
1823
|
"padding-top": props.aspectRatio * 100 + "%"
|
|
1738
1824
|
}}
|
|
1739
1825
|
/></Show8>
|
|
1740
1826
|
<Show8 when={props.builderBlock?.children?.length && props.fitContent}>{props.children}</Show8>
|
|
1741
|
-
<Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-
|
|
1827
|
+
<Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-070d7e88-2">{props.children}</div></Show8>
|
|
1742
1828
|
</>
|
|
1743
|
-
<style>{`.img-
|
|
1829
|
+
<style>{`.img-070d7e88 {
|
|
1744
1830
|
opacity: 1;
|
|
1745
1831
|
transition: opacity 0.2s ease-in-out;
|
|
1746
|
-
}.div-
|
|
1832
|
+
}.div-070d7e88 {
|
|
1747
1833
|
width: 100%;
|
|
1748
1834
|
pointer-events: none;
|
|
1749
1835
|
font-size: 0;
|
|
1750
|
-
}.div-
|
|
1836
|
+
}.div-070d7e88-2 {
|
|
1751
1837
|
display: flex;
|
|
1752
1838
|
flex-direction: column;
|
|
1753
1839
|
align-items: stretch;
|
|
@@ -2540,6 +2626,10 @@ var componentInfo4 = {
|
|
|
2540
2626
|
noWrap: true
|
|
2541
2627
|
};
|
|
2542
2628
|
|
|
2629
|
+
// src/constants/file-types.ts
|
|
2630
|
+
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"];
|
|
2631
|
+
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"];
|
|
2632
|
+
|
|
2543
2633
|
// src/blocks/image/component-info.ts
|
|
2544
2634
|
var componentInfo5 = {
|
|
2545
2635
|
name: "Image",
|
|
@@ -2556,7 +2646,7 @@ var componentInfo5 = {
|
|
|
2556
2646
|
name: "image",
|
|
2557
2647
|
type: "file",
|
|
2558
2648
|
bubble: true,
|
|
2559
|
-
allowedFileTypes:
|
|
2649
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
2560
2650
|
required: true,
|
|
2561
2651
|
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
|
|
2562
2652
|
onChange: (options) => {
|
|
@@ -3913,7 +4003,7 @@ var componentInfo18 = {
|
|
|
3913
4003
|
name: "image",
|
|
3914
4004
|
bubble: true,
|
|
3915
4005
|
type: "file",
|
|
3916
|
-
allowedFileTypes:
|
|
4006
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
3917
4007
|
required: true
|
|
3918
4008
|
}],
|
|
3919
4009
|
noWrap: true,
|
|
@@ -3948,14 +4038,14 @@ var componentInfo19 = {
|
|
|
3948
4038
|
inputs: [{
|
|
3949
4039
|
name: "video",
|
|
3950
4040
|
type: "file",
|
|
3951
|
-
allowedFileTypes:
|
|
4041
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
3952
4042
|
bubble: true,
|
|
3953
4043
|
defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
|
|
3954
4044
|
required: true
|
|
3955
4045
|
}, {
|
|
3956
4046
|
name: "posterImage",
|
|
3957
4047
|
type: "file",
|
|
3958
|
-
allowedFileTypes:
|
|
4048
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
3959
4049
|
helperText: "Image to show before the video plays"
|
|
3960
4050
|
}, {
|
|
3961
4051
|
name: "autoPlay",
|
|
@@ -4181,7 +4271,7 @@ var createRegisterComponentMessage = (info) => ({
|
|
|
4181
4271
|
var serializeFn = (fnValue) => {
|
|
4182
4272
|
const fnStr = fnValue.toString().trim();
|
|
4183
4273
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
4184
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4274
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4185
4275
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
4186
4276
|
};
|
|
4187
4277
|
function serializeIncludingFunctions(info) {
|
|
@@ -4266,7 +4356,7 @@ function getPreviewContent(_searchParams) {
|
|
|
4266
4356
|
}
|
|
4267
4357
|
|
|
4268
4358
|
// src/constants/sdk-version.ts
|
|
4269
|
-
var SDK_VERSION = "
|
|
4359
|
+
var SDK_VERSION = "3.0.1";
|
|
4270
4360
|
|
|
4271
4361
|
// src/helpers/sdk-headers.ts
|
|
4272
4362
|
var getSdkHeaders = () => ({
|
|
@@ -4505,22 +4595,17 @@ var _processContentResult = async (options, content, url = generateContentUrl(op
|
|
|
4505
4595
|
return content.results;
|
|
4506
4596
|
};
|
|
4507
4597
|
async function fetchEntries(options) {
|
|
4508
|
-
|
|
4509
|
-
|
|
4510
|
-
|
|
4511
|
-
|
|
4512
|
-
|
|
4513
|
-
|
|
4514
|
-
|
|
4515
|
-
|
|
4516
|
-
|
|
4517
|
-
return null;
|
|
4518
|
-
}
|
|
4519
|
-
return _processContentResult(options, content);
|
|
4520
|
-
} catch (error) {
|
|
4521
|
-
logger.error("Error fetching data. ", error);
|
|
4522
|
-
return null;
|
|
4598
|
+
const url = generateContentUrl(options);
|
|
4599
|
+
const content = await _fetchContent(options);
|
|
4600
|
+
if (!checkContentHasResults(content)) {
|
|
4601
|
+
logger.error("Error fetching data. ", {
|
|
4602
|
+
url,
|
|
4603
|
+
content,
|
|
4604
|
+
options
|
|
4605
|
+
});
|
|
4606
|
+
throw content;
|
|
4523
4607
|
}
|
|
4608
|
+
return _processContentResult(options, content);
|
|
4524
4609
|
}
|
|
4525
4610
|
|
|
4526
4611
|
// src/functions/is-previewing.ts
|
|
@@ -4983,6 +5068,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
4983
5068
|
};
|
|
4984
5069
|
};
|
|
4985
5070
|
|
|
5071
|
+
// src/components/content/components/enable-editor.helpers.ts
|
|
5072
|
+
var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
|
|
5073
|
+
var needsElementRefDivForEditing = () => {
|
|
5074
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
5075
|
+
};
|
|
5076
|
+
|
|
4986
5077
|
// src/components/content/components/styles.helpers.ts
|
|
4987
5078
|
var getCssFromFont = (font) => {
|
|
4988
5079
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -5228,8 +5319,10 @@ function EnableEditor(props) {
|
|
|
5228
5319
|
Object.values(
|
|
5229
5320
|
props.builderContextSignal.componentInfos
|
|
5230
5321
|
).forEach((registeredComponent) => {
|
|
5231
|
-
|
|
5232
|
-
|
|
5322
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
5323
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
5324
|
+
window.parent?.postMessage(message, "*");
|
|
5325
|
+
}
|
|
5233
5326
|
});
|
|
5234
5327
|
window.addEventListener(
|
|
5235
5328
|
"builder:component:stateChangeListenerActivated",
|
|
@@ -5306,7 +5399,9 @@ function EnableEditor(props) {
|
|
|
5306
5399
|
}
|
|
5307
5400
|
}
|
|
5308
5401
|
createEffect3(on3(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
|
|
5309
|
-
return <><builder_context_default.Provider value={props.builderContextSignal}><Show13
|
|
5402
|
+
return <><builder_context_default.Provider value={props.builderContextSignal}><Show13
|
|
5403
|
+
when={props.builderContextSignal.content || needsElementRefDivForEditing()}
|
|
5404
|
+
><Dynamic5
|
|
5310
5405
|
class={getWrapperClassName(
|
|
5311
5406
|
props.content?.testVariationId || props.content?.id
|
|
5312
5407
|
)}
|
|
@@ -5315,6 +5410,9 @@ function EnableEditor(props) {
|
|
|
5315
5410
|
onClick={(event) => onClick(event)}
|
|
5316
5411
|
builder-content-id={props.builderContextSignal.content?.id}
|
|
5317
5412
|
builder-model={props.model}
|
|
5413
|
+
style={{
|
|
5414
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
5415
|
+
}}
|
|
5318
5416
|
{...{}}
|
|
5319
5417
|
{...showContentProps()}
|
|
5320
5418
|
{...props.contentWrapperProps}
|
|
@@ -5395,13 +5493,7 @@ function ContentComponent(props) {
|
|
|
5395
5493
|
const [registeredComponents, setRegisteredComponents] = createSignal18(
|
|
5396
5494
|
[
|
|
5397
5495
|
...getDefaultRegisteredComponents(),
|
|
5398
|
-
...props.customComponents
|
|
5399
|
-
if (!models?.length)
|
|
5400
|
-
return true;
|
|
5401
|
-
if (!props.model)
|
|
5402
|
-
return true;
|
|
5403
|
-
return models.includes(props.model);
|
|
5404
|
-
}) || []
|
|
5496
|
+
...props.customComponents || []
|
|
5405
5497
|
].reduce(
|
|
5406
5498
|
(acc, { component, ...info }) => ({
|
|
5407
5499
|
...acc,
|
|
@@ -5431,13 +5523,7 @@ function ContentComponent(props) {
|
|
|
5431
5523
|
apiVersion: props.apiVersion,
|
|
5432
5524
|
componentInfos: [
|
|
5433
5525
|
...getDefaultRegisteredComponents(),
|
|
5434
|
-
...props.customComponents
|
|
5435
|
-
if (!models?.length)
|
|
5436
|
-
return true;
|
|
5437
|
-
if (!props.model)
|
|
5438
|
-
return true;
|
|
5439
|
-
return models.includes(props.model);
|
|
5440
|
-
}) || []
|
|
5526
|
+
...props.customComponents || []
|
|
5441
5527
|
].reduce(
|
|
5442
5528
|
(acc, { component: _, ...info }) => ({
|
|
5443
5529
|
...acc,
|
|
@@ -5448,7 +5534,8 @@ function ContentComponent(props) {
|
|
|
5448
5534
|
inheritedStyles: {},
|
|
5449
5535
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
5450
5536
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
5451
|
-
nonce: props.nonce || ""
|
|
5537
|
+
nonce: props.nonce || "",
|
|
5538
|
+
model: props.model || ""
|
|
5452
5539
|
});
|
|
5453
5540
|
function contentSetState(newRootState) {
|
|
5454
5541
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|