@builder.io/sdk-solid 3.0.0 → 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 +132 -44
- package/lib/browser/dev.jsx +133 -40
- package/lib/browser/index.js +129 -44
- package/lib/browser/index.jsx +132 -40
- package/lib/edge/dev.js +132 -44
- package/lib/edge/dev.jsx +133 -40
- package/lib/edge/index.js +129 -44
- package/lib/edge/index.jsx +132 -40
- package/lib/node/dev.js +132 -44
- package/lib/node/dev.jsx +133 -40
- package/lib/node/index.js +129 -44
- package/lib/node/index.jsx +132 -40
- 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 = "3.0.
|
|
4875
|
+
var SDK_VERSION = "3.0.1";
|
|
4789
4876
|
|
|
4790
4877
|
// src/helpers/sdk-headers.ts
|
|
4791
4878
|
var getSdkHeaders = () => ({
|
|
@@ -5497,6 +5584,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
5497
5584
|
};
|
|
5498
5585
|
};
|
|
5499
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
|
+
|
|
5500
5593
|
// src/components/content/components/styles.helpers.ts
|
|
5501
5594
|
var getCssFromFont = (font) => {
|
|
5502
5595
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -5731,8 +5824,10 @@ function EnableEditor(props) {
|
|
|
5731
5824
|
} : {}
|
|
5732
5825
|
});
|
|
5733
5826
|
Object.values(props.builderContextSignal.componentInfos).forEach((registeredComponent) => {
|
|
5734
|
-
|
|
5735
|
-
|
|
5827
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
5828
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
5829
|
+
window.parent?.postMessage(message, "*");
|
|
5830
|
+
}
|
|
5736
5831
|
});
|
|
5737
5832
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
5738
5833
|
}
|
|
@@ -5804,7 +5899,7 @@ function EnableEditor(props) {
|
|
|
5804
5899
|
get children() {
|
|
5805
5900
|
return createComponent(Show, {
|
|
5806
5901
|
get when() {
|
|
5807
|
-
return props.builderContextSignal.content;
|
|
5902
|
+
return props.builderContextSignal.content || needsElementRefDivForEditing();
|
|
5808
5903
|
},
|
|
5809
5904
|
get children() {
|
|
5810
5905
|
return createComponent(Dynamic, mergeProps({
|
|
@@ -5822,6 +5917,11 @@ function EnableEditor(props) {
|
|
|
5822
5917
|
},
|
|
5823
5918
|
get ["builder-model"]() {
|
|
5824
5919
|
return props.model;
|
|
5920
|
+
},
|
|
5921
|
+
get style() {
|
|
5922
|
+
return {
|
|
5923
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
5924
|
+
};
|
|
5825
5925
|
}
|
|
5826
5926
|
}, {}, showContentProps, () => props.contentWrapperProps, {
|
|
5827
5927
|
get component() {
|
|
@@ -5904,15 +6004,7 @@ function ContentComponent(props) {
|
|
|
5904
6004
|
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
|
|
5905
6005
|
contentId: props.content?.id
|
|
5906
6006
|
}));
|
|
5907
|
-
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents
|
|
5908
|
-
models
|
|
5909
|
-
}) => {
|
|
5910
|
-
if (!models?.length)
|
|
5911
|
-
return true;
|
|
5912
|
-
if (!props.model)
|
|
5913
|
-
return true;
|
|
5914
|
-
return models.includes(props.model);
|
|
5915
|
-
}) || []].reduce((acc, {
|
|
6007
|
+
const [registeredComponents, setRegisteredComponents] = createSignal([...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
5916
6008
|
component,
|
|
5917
6009
|
...info
|
|
5918
6010
|
}) => ({
|
|
@@ -5938,15 +6030,7 @@ function ContentComponent(props) {
|
|
|
5938
6030
|
canTrack: props.canTrack,
|
|
5939
6031
|
apiKey: props.apiKey,
|
|
5940
6032
|
apiVersion: props.apiVersion,
|
|
5941
|
-
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents
|
|
5942
|
-
models
|
|
5943
|
-
}) => {
|
|
5944
|
-
if (!models?.length)
|
|
5945
|
-
return true;
|
|
5946
|
-
if (!props.model)
|
|
5947
|
-
return true;
|
|
5948
|
-
return models.includes(props.model);
|
|
5949
|
-
}) || []].reduce((acc, {
|
|
6033
|
+
componentInfos: [...getDefaultRegisteredComponents(), ...props.customComponents || []].reduce((acc, {
|
|
5950
6034
|
component: _,
|
|
5951
6035
|
...info
|
|
5952
6036
|
}) => ({
|
|
@@ -5956,7 +6040,8 @@ function ContentComponent(props) {
|
|
|
5956
6040
|
inheritedStyles: {},
|
|
5957
6041
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
5958
6042
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
5959
|
-
nonce: props.nonce || ""
|
|
6043
|
+
nonce: props.nonce || "",
|
|
6044
|
+
model: props.model || ""
|
|
5960
6045
|
});
|
|
5961
6046
|
function contentSetState(newRootState) {
|
|
5962
6047
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|