@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/node/dev.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
|
|
@@ -578,6 +579,77 @@ function evaluate({
|
|
|
578
579
|
}
|
|
579
580
|
}
|
|
580
581
|
|
|
582
|
+
// src/functions/traverse.ts
|
|
583
|
+
function traverse(obj, callback, parent2 = null, key = null, visited = /* @__PURE__ */ new WeakSet()) {
|
|
584
|
+
if (obj == null || typeof obj !== "object") {
|
|
585
|
+
callback(obj, (newValue) => {
|
|
586
|
+
if (parent2 !== null && key !== null) {
|
|
587
|
+
parent2[key] = newValue;
|
|
588
|
+
}
|
|
589
|
+
});
|
|
590
|
+
return;
|
|
591
|
+
}
|
|
592
|
+
if (visited.has(obj)) {
|
|
593
|
+
return;
|
|
594
|
+
}
|
|
595
|
+
visited.add(obj);
|
|
596
|
+
if (Array.isArray(obj)) {
|
|
597
|
+
obj.forEach((item, index) => {
|
|
598
|
+
const update = (newValue) => {
|
|
599
|
+
obj[index] = newValue;
|
|
600
|
+
};
|
|
601
|
+
callback(item, update);
|
|
602
|
+
traverse(item, callback, obj, index, visited);
|
|
603
|
+
});
|
|
604
|
+
} else {
|
|
605
|
+
Object.entries(obj).forEach(([key2, value]) => {
|
|
606
|
+
const update = (newValue) => {
|
|
607
|
+
obj[key2] = newValue;
|
|
608
|
+
};
|
|
609
|
+
callback(value, update);
|
|
610
|
+
traverse(value, callback, obj, key2, visited);
|
|
611
|
+
});
|
|
612
|
+
}
|
|
613
|
+
}
|
|
614
|
+
|
|
615
|
+
// src/functions/extract-localized-values.ts
|
|
616
|
+
function isLocalizedField(value) {
|
|
617
|
+
return value && typeof value === "object" && value["@type"] === "@builder.io/core:LocalizedValue";
|
|
618
|
+
}
|
|
619
|
+
function containsLocalizedValues(data) {
|
|
620
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
621
|
+
return false;
|
|
622
|
+
}
|
|
623
|
+
let hasLocalizedValues = false;
|
|
624
|
+
traverse(data, (value) => {
|
|
625
|
+
if (isLocalizedField(value)) {
|
|
626
|
+
hasLocalizedValues = true;
|
|
627
|
+
return;
|
|
628
|
+
}
|
|
629
|
+
});
|
|
630
|
+
return hasLocalizedValues;
|
|
631
|
+
}
|
|
632
|
+
function extractLocalizedValues(data, locale) {
|
|
633
|
+
if (!data || !Object.getOwnPropertyNames(data).length) {
|
|
634
|
+
return {};
|
|
635
|
+
}
|
|
636
|
+
traverse(data, (value, update) => {
|
|
637
|
+
if (isLocalizedField(value)) {
|
|
638
|
+
update(value[locale] ?? void 0);
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
return data;
|
|
642
|
+
}
|
|
643
|
+
function resolveLocalizedValues(block, locale) {
|
|
644
|
+
if (block.component?.options && containsLocalizedValues(block.component?.options)) {
|
|
645
|
+
if (!locale) {
|
|
646
|
+
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");
|
|
647
|
+
}
|
|
648
|
+
block.component.options = extractLocalizedValues(block.component.options, locale ?? "Default");
|
|
649
|
+
}
|
|
650
|
+
return block;
|
|
651
|
+
}
|
|
652
|
+
|
|
581
653
|
// src/functions/transform-block.ts
|
|
582
654
|
function transformBlock(block) {
|
|
583
655
|
return block;
|
|
@@ -663,7 +735,8 @@ function getProcessedBlock({
|
|
|
663
735
|
rootState,
|
|
664
736
|
rootSetState
|
|
665
737
|
}) {
|
|
666
|
-
|
|
738
|
+
let transformedBlock = resolveLocalizedValues(block, rootState.locale);
|
|
739
|
+
transformedBlock = transformBlock(transformedBlock);
|
|
667
740
|
if (shouldEvaluateBindings) {
|
|
668
741
|
return evaluateBindings({
|
|
669
742
|
block: transformedBlock,
|
|
@@ -921,16 +994,24 @@ function mapStyleObjToStrIfNeeded(style) {
|
|
|
921
994
|
}
|
|
922
995
|
|
|
923
996
|
// src/components/block/block.helpers.ts
|
|
997
|
+
var checkIsComponentRestricted = (component, model) => {
|
|
998
|
+
if (!component)
|
|
999
|
+
return true;
|
|
1000
|
+
if (!model)
|
|
1001
|
+
return false;
|
|
1002
|
+
return component.models && component.models.length > 0 && !component.models.includes(model);
|
|
1003
|
+
};
|
|
924
1004
|
var getComponent = ({
|
|
925
1005
|
block,
|
|
926
|
-
registeredComponents
|
|
1006
|
+
registeredComponents,
|
|
1007
|
+
model
|
|
927
1008
|
}) => {
|
|
928
1009
|
const componentName = block.component?.name;
|
|
929
1010
|
if (!componentName) {
|
|
930
1011
|
return null;
|
|
931
1012
|
}
|
|
932
1013
|
const ref = registeredComponents[componentName];
|
|
933
|
-
if (!ref) {
|
|
1014
|
+
if (!ref || checkIsComponentRestricted(ref, model)) {
|
|
934
1015
|
console.warn(`
|
|
935
1016
|
Could not find a registered component named "${componentName}".
|
|
936
1017
|
If you registered it, is the file that registered it imported by the file that needs to render it?`);
|
|
@@ -984,11 +1065,15 @@ var provideLinkComponent = (block, linkComponent) => {
|
|
|
984
1065
|
};
|
|
985
1066
|
return {};
|
|
986
1067
|
};
|
|
987
|
-
var provideRegisteredComponents = (block, registeredComponents) => {
|
|
988
|
-
if (block?.shouldReceiveBuilderProps?.builderComponents)
|
|
1068
|
+
var provideRegisteredComponents = (block, registeredComponents, model) => {
|
|
1069
|
+
if (block?.shouldReceiveBuilderProps?.builderComponents) {
|
|
1070
|
+
const filteredRegisteredComponents = Object.fromEntries(Object.entries(registeredComponents).filter(([_, component]) => {
|
|
1071
|
+
return !checkIsComponentRestricted(component, model);
|
|
1072
|
+
}));
|
|
989
1073
|
return {
|
|
990
|
-
builderComponents:
|
|
1074
|
+
builderComponents: filteredRegisteredComponents
|
|
991
1075
|
};
|
|
1076
|
+
}
|
|
992
1077
|
return {};
|
|
993
1078
|
};
|
|
994
1079
|
var provideBuilderBlock = (block, builderBlock) => {
|
|
@@ -1392,7 +1477,8 @@ function Block(props) {
|
|
|
1392
1477
|
const blockComponent = createMemo5(() => {
|
|
1393
1478
|
return getComponent({
|
|
1394
1479
|
block: processedBlock(),
|
|
1395
|
-
registeredComponents: props.registeredComponents
|
|
1480
|
+
registeredComponents: props.registeredComponents,
|
|
1481
|
+
model: props.context.model
|
|
1396
1482
|
});
|
|
1397
1483
|
});
|
|
1398
1484
|
const Tag = createMemo5(() => {
|
|
@@ -1427,7 +1513,8 @@ function Block(props) {
|
|
|
1427
1513
|
...provideLinkComponent(blockComponent(), props.linkComponent),
|
|
1428
1514
|
...provideRegisteredComponents(
|
|
1429
1515
|
blockComponent(),
|
|
1430
|
-
props.registeredComponents
|
|
1516
|
+
props.registeredComponents,
|
|
1517
|
+
props.context.model
|
|
1431
1518
|
)
|
|
1432
1519
|
},
|
|
1433
1520
|
context: props.context,
|
|
@@ -1851,7 +1938,7 @@ function Image(props) {
|
|
|
1851
1938
|
const url = imageToUse;
|
|
1852
1939
|
if (!url || // We can auto add srcset for cdn.builder.io and shopify
|
|
1853
1940
|
// images, otherwise you can supply this prop manually
|
|
1854
|
-
!(url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/))) {
|
|
1941
|
+
!(typeof url === "string" && (url.match(/builder\.io/) || url.match(/cdn\.shopify\.com/)))) {
|
|
1855
1942
|
return props.srcset;
|
|
1856
1943
|
}
|
|
1857
1944
|
if (props.noWebp) {
|
|
@@ -1892,7 +1979,7 @@ function Image(props) {
|
|
|
1892
1979
|
<picture>
|
|
1893
1980
|
<Show8 when={webpSrcSet()}><source type="image/webp" srcset={webpSrcSet()} /></Show8>
|
|
1894
1981
|
<img
|
|
1895
|
-
class={"builder-image" + (props.className ? " " + props.className : "") + " img-
|
|
1982
|
+
class={"builder-image" + (props.className ? " " + props.className : "") + " img-070d7e88"}
|
|
1896
1983
|
loading={props.highPriority ? "eager" : "lazy"}
|
|
1897
1984
|
fetchpriority={props.highPriority ? "high" : "auto"}
|
|
1898
1985
|
alt={props.altText}
|
|
@@ -1910,22 +1997,22 @@ function Image(props) {
|
|
|
1910
1997
|
<Show8
|
|
1911
1998
|
when={props.aspectRatio && !(props.builderBlock?.children?.length && props.fitContent)}
|
|
1912
1999
|
><div
|
|
1913
|
-
class="builder-image-sizer div-
|
|
2000
|
+
class="builder-image-sizer div-070d7e88"
|
|
1914
2001
|
style={{
|
|
1915
2002
|
"padding-top": props.aspectRatio * 100 + "%"
|
|
1916
2003
|
}}
|
|
1917
2004
|
/></Show8>
|
|
1918
2005
|
<Show8 when={props.builderBlock?.children?.length && props.fitContent}>{props.children}</Show8>
|
|
1919
|
-
<Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-
|
|
2006
|
+
<Show8 when={!props.fitContent && props.builderBlock?.children?.length}><div class="div-070d7e88-2">{props.children}</div></Show8>
|
|
1920
2007
|
</>
|
|
1921
|
-
<style>{`.img-
|
|
2008
|
+
<style>{`.img-070d7e88 {
|
|
1922
2009
|
opacity: 1;
|
|
1923
2010
|
transition: opacity 0.2s ease-in-out;
|
|
1924
|
-
}.div-
|
|
2011
|
+
}.div-070d7e88 {
|
|
1925
2012
|
width: 100%;
|
|
1926
2013
|
pointer-events: none;
|
|
1927
2014
|
font-size: 0;
|
|
1928
|
-
}.div-
|
|
2015
|
+
}.div-070d7e88-2 {
|
|
1929
2016
|
display: flex;
|
|
1930
2017
|
flex-direction: column;
|
|
1931
2018
|
align-items: stretch;
|
|
@@ -2718,6 +2805,10 @@ var componentInfo4 = {
|
|
|
2718
2805
|
noWrap: true
|
|
2719
2806
|
};
|
|
2720
2807
|
|
|
2808
|
+
// src/constants/file-types.ts
|
|
2809
|
+
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"];
|
|
2810
|
+
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"];
|
|
2811
|
+
|
|
2721
2812
|
// src/blocks/image/component-info.ts
|
|
2722
2813
|
var componentInfo5 = {
|
|
2723
2814
|
name: "Image",
|
|
@@ -2734,7 +2825,7 @@ var componentInfo5 = {
|
|
|
2734
2825
|
name: "image",
|
|
2735
2826
|
type: "file",
|
|
2736
2827
|
bubble: true,
|
|
2737
|
-
allowedFileTypes:
|
|
2828
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
2738
2829
|
required: true,
|
|
2739
2830
|
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2FYJIGb4i01jvw0SRdL5Bt%2F72c80f114dc149019051b6852a9e3b7a",
|
|
2740
2831
|
onChange: (options) => {
|
|
@@ -4094,7 +4185,7 @@ var componentInfo18 = {
|
|
|
4094
4185
|
name: "image",
|
|
4095
4186
|
bubble: true,
|
|
4096
4187
|
type: "file",
|
|
4097
|
-
allowedFileTypes:
|
|
4188
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4098
4189
|
required: true
|
|
4099
4190
|
}],
|
|
4100
4191
|
noWrap: true,
|
|
@@ -4129,14 +4220,14 @@ var componentInfo19 = {
|
|
|
4129
4220
|
inputs: [{
|
|
4130
4221
|
name: "video",
|
|
4131
4222
|
type: "file",
|
|
4132
|
-
allowedFileTypes:
|
|
4223
|
+
allowedFileTypes: VIDEO_FILE_TYPES,
|
|
4133
4224
|
bubble: true,
|
|
4134
4225
|
defaultValue: "https://cdn.builder.io/o/assets%2FYJIGb4i01jvw0SRdL5Bt%2Fd27731a526464deba0016216f5f9e570%2Fcompressed?apiKey=YJIGb4i01jvw0SRdL5Bt&token=d27731a526464deba0016216f5f9e570&alt=media&optimized=true",
|
|
4135
4226
|
required: true
|
|
4136
4227
|
}, {
|
|
4137
4228
|
name: "posterImage",
|
|
4138
4229
|
type: "file",
|
|
4139
|
-
allowedFileTypes:
|
|
4230
|
+
allowedFileTypes: IMAGE_FILE_TYPES,
|
|
4140
4231
|
helperText: "Image to show before the video plays"
|
|
4141
4232
|
}, {
|
|
4142
4233
|
name: "autoPlay",
|
|
@@ -4362,7 +4453,7 @@ var createRegisterComponentMessage = (info) => ({
|
|
|
4362
4453
|
var serializeFn = (fnValue) => {
|
|
4363
4454
|
const fnStr = fnValue.toString().trim();
|
|
4364
4455
|
const isArrowWithoutParens = /^[a-zA-Z0-9_]+\s*=>/i.test(fnStr);
|
|
4365
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4456
|
+
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("async") && !fnStr.startsWith("(") && !isArrowWithoutParens;
|
|
4366
4457
|
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
4367
4458
|
};
|
|
4368
4459
|
function serializeIncludingFunctions(info) {
|
|
@@ -4447,7 +4538,7 @@ function getPreviewContent(_searchParams) {
|
|
|
4447
4538
|
}
|
|
4448
4539
|
|
|
4449
4540
|
// src/constants/sdk-version.ts
|
|
4450
|
-
var SDK_VERSION = "
|
|
4541
|
+
var SDK_VERSION = "3.0.1";
|
|
4451
4542
|
|
|
4452
4543
|
// src/helpers/sdk-headers.ts
|
|
4453
4544
|
var getSdkHeaders = () => ({
|
|
@@ -4688,22 +4779,17 @@ var _processContentResult = async (options, content, url = generateContentUrl(op
|
|
|
4688
4779
|
return content.results;
|
|
4689
4780
|
};
|
|
4690
4781
|
async function fetchEntries(options) {
|
|
4691
|
-
|
|
4692
|
-
|
|
4693
|
-
|
|
4694
|
-
|
|
4695
|
-
|
|
4696
|
-
|
|
4697
|
-
|
|
4698
|
-
|
|
4699
|
-
|
|
4700
|
-
return null;
|
|
4701
|
-
}
|
|
4702
|
-
return _processContentResult(options, content);
|
|
4703
|
-
} catch (error2) {
|
|
4704
|
-
logger.error("Error fetching data. ", error2);
|
|
4705
|
-
return null;
|
|
4782
|
+
const url = generateContentUrl(options);
|
|
4783
|
+
const content = await _fetchContent(options);
|
|
4784
|
+
if (!checkContentHasResults(content)) {
|
|
4785
|
+
logger.error("Error fetching data. ", {
|
|
4786
|
+
url,
|
|
4787
|
+
content,
|
|
4788
|
+
options
|
|
4789
|
+
});
|
|
4790
|
+
throw content;
|
|
4706
4791
|
}
|
|
4792
|
+
return _processContentResult(options, content);
|
|
4707
4793
|
}
|
|
4708
4794
|
|
|
4709
4795
|
// src/functions/is-previewing.ts
|
|
@@ -5170,6 +5256,12 @@ var subscribeToEditor = (model, callback, options) => {
|
|
|
5170
5256
|
};
|
|
5171
5257
|
};
|
|
5172
5258
|
|
|
5259
|
+
// src/components/content/components/enable-editor.helpers.ts
|
|
5260
|
+
var SDKS_USING_ELEMENT_REF_APPROACH = ["svelte", "qwik", "vue"];
|
|
5261
|
+
var needsElementRefDivForEditing = () => {
|
|
5262
|
+
return SDKS_USING_ELEMENT_REF_APPROACH.includes(TARGET) && (isEditing() || isPreviewing());
|
|
5263
|
+
};
|
|
5264
|
+
|
|
5173
5265
|
// src/components/content/components/styles.helpers.ts
|
|
5174
5266
|
var getCssFromFont = (font) => {
|
|
5175
5267
|
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
@@ -5416,8 +5508,10 @@ function EnableEditor(props) {
|
|
|
5416
5508
|
Object.values(
|
|
5417
5509
|
props.builderContextSignal.componentInfos
|
|
5418
5510
|
).forEach((registeredComponent) => {
|
|
5419
|
-
|
|
5420
|
-
|
|
5511
|
+
if (!props.model || !registeredComponent.models?.length || registeredComponent.models.includes(props.model)) {
|
|
5512
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
5513
|
+
window.parent?.postMessage(message, "*");
|
|
5514
|
+
}
|
|
5421
5515
|
});
|
|
5422
5516
|
window.addEventListener(
|
|
5423
5517
|
"builder:component:stateChangeListenerActivated",
|
|
@@ -5494,7 +5588,9 @@ function EnableEditor(props) {
|
|
|
5494
5588
|
}
|
|
5495
5589
|
}
|
|
5496
5590
|
createEffect3(on3(() => [onUpdateFn_3_props_locale()], onUpdateFn_3));
|
|
5497
|
-
return <><builder_context_default.Provider value={props.builderContextSignal}><Show13
|
|
5591
|
+
return <><builder_context_default.Provider value={props.builderContextSignal}><Show13
|
|
5592
|
+
when={props.builderContextSignal.content || needsElementRefDivForEditing()}
|
|
5593
|
+
><Dynamic5
|
|
5498
5594
|
class={getWrapperClassName(
|
|
5499
5595
|
props.content?.testVariationId || props.content?.id
|
|
5500
5596
|
)}
|
|
@@ -5503,6 +5599,9 @@ function EnableEditor(props) {
|
|
|
5503
5599
|
onClick={(event) => onClick(event)}
|
|
5504
5600
|
builder-content-id={props.builderContextSignal.content?.id}
|
|
5505
5601
|
builder-model={props.model}
|
|
5602
|
+
style={{
|
|
5603
|
+
display: !props.builderContextSignal.content && needsElementRefDivForEditing() ? "none" : void 0
|
|
5604
|
+
}}
|
|
5506
5605
|
{...{}}
|
|
5507
5606
|
{...showContentProps()}
|
|
5508
5607
|
{...props.contentWrapperProps}
|
|
@@ -5583,13 +5682,7 @@ function ContentComponent(props) {
|
|
|
5583
5682
|
const [registeredComponents, setRegisteredComponents] = createSignal18(
|
|
5584
5683
|
[
|
|
5585
5684
|
...getDefaultRegisteredComponents(),
|
|
5586
|
-
...props.customComponents
|
|
5587
|
-
if (!models?.length)
|
|
5588
|
-
return true;
|
|
5589
|
-
if (!props.model)
|
|
5590
|
-
return true;
|
|
5591
|
-
return models.includes(props.model);
|
|
5592
|
-
}) || []
|
|
5685
|
+
...props.customComponents || []
|
|
5593
5686
|
].reduce(
|
|
5594
5687
|
(acc, { component, ...info }) => ({
|
|
5595
5688
|
...acc,
|
|
@@ -5619,13 +5712,7 @@ function ContentComponent(props) {
|
|
|
5619
5712
|
apiVersion: props.apiVersion,
|
|
5620
5713
|
componentInfos: [
|
|
5621
5714
|
...getDefaultRegisteredComponents(),
|
|
5622
|
-
...props.customComponents
|
|
5623
|
-
if (!models?.length)
|
|
5624
|
-
return true;
|
|
5625
|
-
if (!props.model)
|
|
5626
|
-
return true;
|
|
5627
|
-
return models.includes(props.model);
|
|
5628
|
-
}) || []
|
|
5715
|
+
...props.customComponents || []
|
|
5629
5716
|
].reduce(
|
|
5630
5717
|
(acc, { component: _, ...info }) => ({
|
|
5631
5718
|
...acc,
|
|
@@ -5636,7 +5723,8 @@ function ContentComponent(props) {
|
|
|
5636
5723
|
inheritedStyles: {},
|
|
5637
5724
|
BlocksWrapper: props.blocksWrapper || "div",
|
|
5638
5725
|
BlocksWrapperProps: props.blocksWrapperProps || {},
|
|
5639
|
-
nonce: props.nonce || ""
|
|
5726
|
+
nonce: props.nonce || "",
|
|
5727
|
+
model: props.model || ""
|
|
5640
5728
|
});
|
|
5641
5729
|
function contentSetState(newRootState) {
|
|
5642
5730
|
setBuilderContextSignal((PREVIOUS_VALUE) => ({
|