@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.js
CHANGED
|
@@ -114,7 +114,8 @@ var builder_context_default = createContext({
|
|
|
114
114
|
inheritedStyles: {},
|
|
115
115
|
BlocksWrapper: "div",
|
|
116
116
|
BlocksWrapperProps: {},
|
|
117
|
-
nonce: ""
|
|
117
|
+
nonce: "",
|
|
118
|
+
model: ""
|
|
118
119
|
});
|
|
119
120
|
var components_context_default = createContext({ registeredComponents: {} });
|
|
120
121
|
|
|
@@ -399,6 +400,74 @@ function evaluate({
|
|
|
399
400
|
}
|
|
400
401
|
}
|
|
401
402
|
|
|
403
|
+
// src/functions/traverse.ts
|
|
404
|
+
function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
405
|
+
if (obj == null || typeof obj !== "object") {
|
|
406
|
+
callback(obj, (newValue) => {
|
|
407
|
+
if (parent2 !== null && key !== null) {
|
|
408
|
+
parent2[key] = newValue;
|
|
409
|
+
}
|
|
410
|
+
});
|
|
411
|
+
return;
|
|
412
|
+
}
|
|
413
|
+
if (visited.has(obj)) {
|
|
414
|
+
return;
|
|
415
|
+
}
|
|
416
|
+
visited.add(obj);
|
|
417
|
+
if (Array.isArray(obj)) {
|
|
418
|
+
obj.forEach((item, index) => {
|
|
419
|
+
const update = (newValue) => {
|
|
420
|
+
obj[index] = newValue;
|
|
421
|
+
};
|
|
422
|
+
callback(item, update);
|
|
423
|
+
traverse(item, callback, obj, index, visited);
|
|
424
|
+
});
|
|
425
|
+
} else {
|
|
426
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
427
|
+
const update = (newValue) => {
|
|
428
|
+
obj[key2] = newValue;
|
|
429
|
+
};
|
|
430
|
+
callback(value, update);
|
|
431
|
+
traverse(value, callback, obj, key2, visited);
|
|
432
|
+
});
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
|
|
436
|
+
// src/functions/extract-localized-values.ts
|
|
437
|
+
function isLocalizedField(value) {
|
|
438
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
439
|
+
}
|
|
440
|
+
function containsLocalizedValues(data) {
|
|
441
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
442
|
+
return false;
|
|
443
|
+
}
|
|
444
|
+
let hasLocalizedValues = false;
|
|
445
|
+
traverse(data, (value) => {
|
|
446
|
+
if (isLocalizedField(value)) {
|
|
447
|
+
hasLocalizedValues = true;
|
|
448
|
+
return;
|
|
449
|
+
}
|
|
450
|
+
});
|
|
451
|
+
return hasLocalizedValues;
|
|
452
|
+
}
|
|
453
|
+
function extractLocalizedValues(data, locale) {
|
|
454
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
455
|
+
return {};
|
|
456
|
+
}
|
|
457
|
+
traverse(data, (value, update) => {
|
|
458
|
+
if (isLocalizedField(value)) {
|
|
459
|
+
update(value[locale] ?? void 0);
|
|
460
|
+
}
|
|
461
|
+
});
|
|
462
|
+
return data;
|
|
463
|
+
}
|
|
464
|
+
function resolveLocalizedValues(block, locale) {
|
|
465
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
466
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
467
|
+
}
|
|
468
|
+
return block;
|
|
469
|
+
}
|
|
470
|
+
|
|
402
471
|
// src/functions/fast-clone.ts
|
|
403
472
|
var fastClone = (obj) => JSON.parse(JSON.stringify(obj));
|
|
404
473
|
|
|
@@ -497,7 +566,8 @@ function getProcessedBlock({
|
|
|
497
566
|
rootState,
|
|
498
567
|
rootSetState
|
|
499
568
|
}) {
|
|
500
|
-
|
|
569
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
570
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
501
571
|
if (shouldEvaluateBindings) {
|
|
502
572
|
return evaluateBindings({
|
|
503
573
|
block: transformedBlock,
|
|
@@ -754,16 +824,24 @@ function mapStyleObjToStrIfNeeded(style) {
|
|
|
754
824
|
}
|
|
755
825
|
|
|
756
826
|
// src/components/block/block.helpers.ts
|
|
827
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
828
|
+
if (!component)
|
|
829
|
+
return true;
|
|
830
|
+
if (!model)
|
|
831
|
+
return false;
|
|
832
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
833
|
+
};
|
|
757
834
|
var getComponent = ({
|
|
758
835
|
block,
|
|
759
|
-
registeredComponents
|
|
836
|
+
registeredComponents,
|
|
837
|
+
model
|
|
760
838
|
}) => {
|
|
761
839
|
const componentName = block.component?.name;
|
|
762
840
|
if (!componentName) {
|
|
763
841
|
return null;
|
|
764
842
|
}
|
|
765
843
|
const ref = registeredComponents[componentName];
|
|
766
|
-
if (!ref) {
|
|
844
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
767
845
|
return void 0;
|
|
768
846
|
} else {
|
|
769
847
|
return ref;
|
|
@@ -814,11 +892,15 @@ var provideLinkComponent = (block, linkComponent) => {
|
|
|
814
892
|
};
|
|
815
893
|
return {};
|
|
816
894
|
};
|
|
817
|
-
var provideRegisteredComponents = (block, registeredComponents) => {
|
|
818
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
895
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
896
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
897
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
898
|
+
return !checkIsComponentRestricted(component, model);
|
|
899
|
+
}));
|
|
819
900
|
return {
|
|
820
|
-
builderComponents:
|
|
901
|
+
builderComponents: filteredRegisteredComponents
|
|
821
902
|
};
|
|
903
|
+
}
|
|
822
904
|
return {};
|
|
823
905
|
};
|
|
824
906
|
var provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -1280,7 +1362,8 @@ function Block(props) {
|
|
|
1280
1362
|
const blockComponent = createMemo(() => {
|
|
1281
1363
|
return getComponent({
|
|
1282
1364
|
block: processedBlock(),
|
|
1283
|
-
registeredComponents: props.registeredComponents
|
|
1365
|
+
registeredComponents: props.registeredComponents,
|
|
1366
|
+
model: props.context.model
|
|
1284
1367
|
});
|
|
1285
1368
|
});
|
|
1286
1369
|
const Tag = createMemo(() => {
|
|
@@ -1313,7 +1396,7 @@ function Block(props) {
|
|
|
1313
1396
|
...provideBuilderBlock(blockComponent(), processedBlock()),
|
|
1314
1397
|
...provideBuilderContext(blockComponent(), props.context),
|
|
1315
1398
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
1316
|
-
...provideRegisteredComponents(blockComponent(), props.registeredComponents)
|
|
1399
|
+
...provideRegisteredComponents(blockComponent(), props.registeredComponents, props.context.model)
|
|
1317
1400
|
},
|
|
1318
1401
|
context: props.context,
|
|
1319
1402
|
linkComponent: props.linkComponent,
|
|
@@ -1911,16 +1994,16 @@ function getSrcSet(url) {
|
|
|
1911
1994
|
// src/blocks/image/image.tsx
|
|
1912
1995
|
var _tmpl$5 = /* @__PURE__ */ template(`<source type=image/webp>`);
|
|
1913
1996
|
var _tmpl$23 = /* @__PURE__ */ template(`<picture><img>`);
|
|
1914
|
-
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-
|
|
1915
|
-
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-
|
|
1916
|
-
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-
|
|
1997
|
+
var _tmpl$32 = /* @__PURE__ */ template(`<div class="builder-image-sizer div-070d7e88">`);
|
|
1998
|
+
var _tmpl$42 = /* @__PURE__ */ template(`<div class=div-070d7e88-2>`);
|
|
1999
|
+
var _tmpl$52 = /* @__PURE__ */ template(`<style>.img-070d7e88 {
|
|
1917
2000
|
opacity: 1;
|
|
1918
2001
|
transition: opacity 0.2s ease-in-out;
|
|
1919
|
-
}.div-
|
|
2002
|
+
}.div-070d7e88 {
|
|
1920
2003
|
width: 100%;
|
|
1921
2004
|
pointer-events: none;
|
|
1922
2005
|
font-size: 0;
|
|
1923
|
-
}.div-
|
|
2006
|
+
}.div-070d7e88-2 {
|
|
1924
2007
|
display: flex;
|
|
1925
2008
|
flex-direction: column;
|
|
1926
2009
|
align-items: stretch;
|
|
@@ -1936,7 +2019,7 @@ function Image(props) {
|
|
|
1936
2019
|
const url = imageToUse;
|
|
1937
2020
|
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
1938
2021
|
// images, otherwise you can supply this prop manually
|
|
1939
|
-
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
2022
|
+
!(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
1940
2023
|
return props.srcset;
|
|
1941
2024
|
}
|
|
1942
2025
|
if (props.noWebp) {
|
|
@@ -1984,7 +2067,7 @@ function Image(props) {
|
|
|
1984
2067
|
}
|
|
1985
2068
|
}), _el$3);
|
|
1986
2069
|
effect((_p$) => {
|
|
1987
|
-
const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-
|
|
2070
|
+
const _v$ = "builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88", _v$2 = props.highPriority ? "eager" : "lazy", _v$3 = props.highPriority ? "high" : "auto", _v$4 = props.altText, _v$5 = props.altText ? void 0 : "presentation", _v$6 = {
|
|
1988
2071
|
"object-position": props.backgroundPosition || "center",
|
|
1989
2072
|
"object-fit": props.backgroundSize || "cover",
|
|
1990
2073
|
...aspectRatioCss()
|
|
@@ -2850,6 +2933,10 @@ var componentInfo4 = {
|
|
|
2850
2933
|
noWrap: true
|
|
2851
2934
|
};
|
|
2852
2935
|
|
|
2936
|
+
// src/constants/file-types.ts
|
|
2937
|
+
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"];
|
|
2938
|
+
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"];
|
|
2939
|
+
|
|
2853
2940
|
// src/blocks/image/component-info.ts
|
|
2854
2941
|
var componentInfo5 = {
|
|
2855
2942
|
name: "Image",
|
|
@@ -2866,7 +2953,7 @@ var componentInfo5 = {
|
|
|
2866
2953
|
name: "image",
|
|
2867
2954
|
type: "file",
|
|
2868
2955
|
bubble: true,
|
|
2869
|
-
allowedFileTypes:
|
|
2956
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
2870
2957
|
required: true,
|
|
2871
2958
|
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
|
|
2872
2959
|
onChange: (options) => {
|
|
@@ -4395,7 +4482,7 @@ var componentInfo18 = {
|
|
|
4395
4482
|
name: "image",
|
|
4396
4483
|
bubble: true,
|
|
4397
4484
|
type: "file",
|
|
4398
|
-
allowedFileTypes:
|
|
4485
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4399
4486
|
required: true
|
|
4400
4487
|
}],
|
|
4401
4488
|
noWrap: true,
|
|
@@ -4439,14 +4526,14 @@ var componentInfo19 = {
|
|
|
4439
4526
|
inputs: [{
|
|
4440
4527
|
name: "video",
|
|
4441
4528
|
type: "file",
|
|
4442
|
-
allowedFileTypes:
|
|
4529
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
4443
4530
|
bubble: true,
|
|
4444
4531
|
defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
|
|
4445
4532
|
required: true
|
|
4446
4533
|
}, {
|
|
4447
4534
|
name: "posterImage",
|
|
4448
4535
|
type: "file",
|
|
4449
|
-
allowedFileTypes:
|
|
4536
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4450
4537
|
helperText: "Image to show before the video plays"
|
|
4451
4538
|
}, {
|
|
4452
4539
|
name: "autoPlay",
|
|
@@ -4702,7 +4789,7 @@ var createRegisterComponentMessage = (info) => ({
|
|
|
4702
4789
|
var serializeFn = (fnValue) => {
|
|
4703
4790
|
const fnStr = fnValue.toString().trim();
|
|
4704
4791
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
4705
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4792
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4706
4793
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
4707
4794
|
};
|
|
4708
4795
|
function serializeIncludingFunctions(info) {
|
|
@@ -4785,7 +4872,7 @@ function getPreviewContent(_searchParams) {
|
|
|
4785
4872
|
}
|
|
4786
4873
|
|
|
4787
4874
|
// src/constants/sdk-version.ts
|
|
4788
|
-
var SDK_VERSION = "
|
|
4875
|
+
var SDK_VERSION = "3.0.1";
|
|
4789
4876
|
|
|
4790
4877
|
// src/helpers/sdk-headers.ts
|
|
4791
4878
|
var getSdkHeaders = () => ({
|
|
@@ -5024,22 +5111,17 @@ var _processContentResult = async (options, content, url = generateContentUrl(op
|
|
|
5024
5111
|
return content.results;
|
|
5025
5112
|
};
|
|
5026
5113
|
async function fetchEntries(options) {
|
|
5027
|
-
|
|
5028
|
-
|
|
5029
|
-
|
|
5030
|
-
|
|
5031
|
-
|
|
5032
|
-
|
|
5033
|
-
|
|
5034
|
-
|
|
5035
|
-
|
|
5036
|
-
return null;
|
|
5037
|
-
}
|
|
5038
|
-
return _processContentResult(options, content);
|
|
5039
|
-
} catch (error) {
|
|
5040
|
-
logger.error("Error fetching data. ", error);
|
|
5041
|
-
return null;
|
|
5114
|
+
const url = generateContentUrl(options);
|
|
5115
|
+
const content = await _fetchContent(options);
|
|
5116
|
+
if (!checkContentHasResults(content)) {
|
|
5117
|
+
logger.error("Error fetching data. ", {
|
|
5118
|
+
url,
|
|
5119
|
+
content,
|
|
5120
|
+
options
|
|
5121
|
+
});
|
|
5122
|
+
throw content;
|
|
5042
5123
|
}
|
|
5124
|
+
return _processContentResult(options, content);
|
|
5043
5125
|
}
|
|
5044
5126
|
|
|
5045
5127
|
// src/functions/is-previewing.ts
|
|
@@ -5502,6 +5584,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
5502
5584
|
};
|
|
5503
5585
|
};
|
|
5504
5586
|
|
|
5587
|
+
// src/components/content/components/enable-editor.helpers.ts
|
|
5588
|
+
var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
|
|
5589
|
+
var needsElementRefDivForEditing = () => {
|
|
5590
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
5591
|
+
};
|
|
5592
|
+
|
|
5505
5593
|
// src/components/content/components/styles.helpers.ts
|
|
5506
5594
|
var getCssFromFont = (font) => {
|
|
5507
5595
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -5736,8 +5824,10 @@ function EnableEditor(props) {
|
|
|
5736
5824
|
} : {}
|
|
5737
5825
|
});
|
|
5738
5826
|
Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
5739
|
-
|
|
5740
|
-
|
|
5827
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
5828
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
5829
|
+
window.parent?.postMessage(message, "*");
|
|
5830
|
+
}
|
|
5741
5831
|
});
|
|
5742
5832
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
5743
5833
|
}
|
|
@@ -5809,7 +5899,7 @@ function EnableEditor(props) {
|
|
|
5809
5899
|
get children() {
|
|
5810
5900
|
return createComponent(Show, {
|
|
5811
5901
|
get when() {
|
|
5812
|
-
return props.builderContextSignal.content;
|
|
5902
|
+
return props.builderContextSignal.content || needsElementRefDivForEditing();
|
|
5813
5903
|
},
|
|
5814
5904
|
get children() {
|
|
5815
5905
|
return createComponent(Dynamic, mergeProps({
|
|
@@ -5827,6 +5917,11 @@ function EnableEditor(props) {
|
|
|
5827
5917
|
},
|
|
5828
5918
|
get ["builder-model"]() {
|
|
5829
5919
|
return props.model;
|
|
5920
|
+
},
|
|
5921
|
+
get style() {
|
|
5922
|
+
return {
|
|
5923
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
5924
|
+
};
|
|
5830
5925
|
}
|
|
5831
5926
|
}, {}, showContentProps, () => props.contentWrapperProps, {
|
|
5832
5927
|
get component() {
|
|
@@ -5909,15 +6004,7 @@ function ContentComponent(props) {
|
|
|
5909
6004
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
5910
6005
|
contentId: props.content?.id
|
|
5911
6006
|
}));
|
|
5912
|
-
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents
|
|
5913
|
-
models
|
|
5914
|
-
}) => {
|
|
5915
|
-
if (!models?.length)
|
|
5916
|
-
return true;
|
|
5917
|
-
if (!props.model)
|
|
5918
|
-
return true;
|
|
5919
|
-
return models.includes(props.model);
|
|
5920
|
-
}) || []].reduce((acc, {
|
|
6007
|
+
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
5921
6008
|
component,
|
|
5922
6009
|
...info
|
|
5923
6010
|
}) => ({
|
|
@@ -5943,15 +6030,7 @@ function ContentComponent(props) {
|
|
|
5943
6030
|
canTrack: props.canTrack,
|
|
5944
6031
|
apiKey: props.apiKey,
|
|
5945
6032
|
apiVersion: props.apiVersion,
|
|
5946
|
-
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents
|
|
5947
|
-
models
|
|
5948
|
-
}) => {
|
|
5949
|
-
if (!models?.length)
|
|
5950
|
-
return true;
|
|
5951
|
-
if (!props.model)
|
|
5952
|
-
return true;
|
|
5953
|
-
return models.includes(props.model);
|
|
5954
|
-
}) || []].reduce((acc, {
|
|
6033
|
+
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
5955
6034
|
component: _,
|
|
5956
6035
|
...info
|
|
5957
6036
|
}) => ({
|
|
@@ -5961,7 +6040,8 @@ function ContentComponent(props) {
|
|
|
5961
6040
|
inheritedStyles: {},
|
|
5962
6041
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
5963
6042
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
5964
|
-
nonce: props.nonce || ""
|
|
6043
|
+
nonce: props.nonce || "",
|
|
6044
|
+
model: props.model || ""
|
|
5965
6045
|
});
|
|
5966
6046
|
function contentSetState(newRootState) {
|
|
5967
6047
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|