@builder.io/sdk-qwik 0.0.37 → 0.0.39-0
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/README.md +4 -0
- package/lib/index.qwik.cjs +252 -178
- package/lib/index.qwik.mjs +253 -178
- package/package.json +11 -4
- package/types/blocks/columns/columns.d.ts +36 -1
- package/types/blocks/symbol/symbol.d.ts +1 -0
- package/types/components/render-block/render-block.d.ts +1 -1
- package/types/components/render-block/render-component.d.ts +2 -0
- package/types/functions/get-block-properties.d.ts +1 -0
- package/types/functions/get-content/generate-content-url.d.ts +2 -0
- package/types/functions/get-content/generate-content-url.test.d.ts +1 -0
- package/types/functions/get-content/index.d.ts +1 -2
- package/types/functions/get-fetch.d.ts +1 -1
- package/types/functions/get-global-this.d.ts +3 -1
- package/types/functions/get-react-native-block-styles.d.ts +2 -1
- package/types/functions/transform-block-properties.d.ts +1 -0
- package/types/helpers/css.d.ts +2 -0
- package/types/types/builder-block.d.ts +1 -0
- package/types/types/builder-content.d.ts +6 -4
- package/types/types/targets.d.ts +1 -1
package/README.md
CHANGED
|
@@ -9,6 +9,10 @@ Installing the Qwik SDK is done in two steps:
|
|
|
9
9
|
1. Set up Qwik-city project.
|
|
10
10
|
2. Install the Qwik SDK into your Qwik-city project.
|
|
11
11
|
|
|
12
|
+
### Fetch
|
|
13
|
+
|
|
14
|
+
This Package uses fetch. See [these docs](https://github.com/BuilderIO/this-package-uses-fetch/blob/main/README.md) for more information.
|
|
15
|
+
|
|
12
16
|
### Set up Qwik-city project
|
|
13
17
|
|
|
14
18
|
1. Follow the instructions on [Qwik-city](https://qwik.builder.io/qwikcity/overview)
|
package/lib/index.qwik.cjs
CHANGED
|
@@ -50,7 +50,7 @@ const registerInsertMenu = ()=>{
|
|
|
50
50
|
{
|
|
51
51
|
name: 'Columns'
|
|
52
52
|
},
|
|
53
|
-
...
|
|
53
|
+
...[
|
|
54
54
|
{
|
|
55
55
|
name: 'Core:Section'
|
|
56
56
|
},
|
|
@@ -270,15 +270,19 @@ function getProcessedBlock({ block , context , shouldEvaluateBindings , state }
|
|
|
270
270
|
|
|
271
271
|
const camelToKebabCase = (string)=>string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
|
|
272
272
|
|
|
273
|
-
const
|
|
273
|
+
const checkIsDefined = (maybeT)=>maybeT !== null && maybeT !== undefined;
|
|
274
|
+
|
|
275
|
+
const convertStyleMapToCSSArray = (style)=>{
|
|
274
276
|
const cssProps = Object.entries(style).map(([key, value])=>{
|
|
275
277
|
if (typeof value === 'string') return `${camelToKebabCase(key)}: ${value};`;
|
|
278
|
+
else return undefined;
|
|
276
279
|
});
|
|
277
|
-
return cssProps.
|
|
280
|
+
return cssProps.filter(checkIsDefined);
|
|
278
281
|
};
|
|
282
|
+
const convertStyleMapToCSS = (style)=>convertStyleMapToCSSArray(style).join('\n');
|
|
279
283
|
const createCssClass = ({ mediaQuery , className , styles })=>{
|
|
280
284
|
const cssClass = `.${className} {
|
|
281
|
-
${
|
|
285
|
+
${convertStyleMapToCSS(styles)}
|
|
282
286
|
}`;
|
|
283
287
|
if (mediaQuery) return `${mediaQuery} {
|
|
284
288
|
${cssClass}
|
|
@@ -342,7 +346,7 @@ const css = function css(props, state) {
|
|
|
342
346
|
};
|
|
343
347
|
const BlockStyles = (props)=>{
|
|
344
348
|
return /*#__PURE__*/ jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
345
|
-
children:
|
|
349
|
+
children: css(props) ? /*#__PURE__*/ jsxRuntime.jsx(RenderInlinedStyles$1, {
|
|
346
350
|
styles: css(props)
|
|
347
351
|
}) : null
|
|
348
352
|
});
|
|
@@ -391,10 +395,15 @@ function getBlockComponentOptions(block) {
|
|
|
391
395
|
};
|
|
392
396
|
}
|
|
393
397
|
|
|
398
|
+
function transformBlockProperties(properties) {
|
|
399
|
+
return properties;
|
|
400
|
+
}
|
|
401
|
+
|
|
394
402
|
function getBlockProperties(block) {
|
|
395
|
-
|
|
403
|
+
const properties = {
|
|
396
404
|
...block.properties,
|
|
397
405
|
'builder-id': block.id,
|
|
406
|
+
style: getStyleAttribute(block.style),
|
|
398
407
|
class: [
|
|
399
408
|
block.id,
|
|
400
409
|
'builder-block',
|
|
@@ -402,6 +411,25 @@ function getBlockProperties(block) {
|
|
|
402
411
|
block.properties?.class
|
|
403
412
|
].filter(Boolean).join(' ')
|
|
404
413
|
};
|
|
414
|
+
return transformBlockProperties(properties);
|
|
415
|
+
}
|
|
416
|
+
/**
|
|
417
|
+
* Svelte does not support style attribute as an object so we need to flatten it.
|
|
418
|
+
*
|
|
419
|
+
* Additionally, Svelte, Vue and other frameworks use kebab-case styles, so we need to convert them.
|
|
420
|
+
*/ function getStyleAttribute(style) {
|
|
421
|
+
if (!style) return undefined;
|
|
422
|
+
switch(TARGET){
|
|
423
|
+
case 'svelte':
|
|
424
|
+
case 'vue2':
|
|
425
|
+
case 'vue3':
|
|
426
|
+
case 'solid':
|
|
427
|
+
return convertStyleMapToCSSArray(style).join(' ');
|
|
428
|
+
case 'qwik':
|
|
429
|
+
case 'reactNative':
|
|
430
|
+
case 'react':
|
|
431
|
+
return style;
|
|
432
|
+
}
|
|
405
433
|
}
|
|
406
434
|
|
|
407
435
|
function getBlockTag(block) {
|
|
@@ -465,51 +493,6 @@ const RenderComponent = (props)=>{
|
|
|
465
493
|
};
|
|
466
494
|
const RenderComponent$1 = RenderComponent;
|
|
467
495
|
|
|
468
|
-
// GENERATED BY MITOSIS
|
|
469
|
-
const RenderComponentWithContext = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
470
|
-
qwik.useContextProvider(BuilderContext, qwik.useStore({
|
|
471
|
-
content: (()=>{
|
|
472
|
-
return props.context.content;
|
|
473
|
-
})(),
|
|
474
|
-
state: (()=>{
|
|
475
|
-
return props.context.state;
|
|
476
|
-
})(),
|
|
477
|
-
context: (()=>{
|
|
478
|
-
return props.context.context;
|
|
479
|
-
})(),
|
|
480
|
-
apiKey: (()=>{
|
|
481
|
-
return props.context.apiKey;
|
|
482
|
-
})(),
|
|
483
|
-
registeredComponents: (()=>{
|
|
484
|
-
return props.context.registeredComponents;
|
|
485
|
-
})(),
|
|
486
|
-
inheritedStyles: (()=>{
|
|
487
|
-
return props.context.inheritedStyles;
|
|
488
|
-
})()
|
|
489
|
-
}));
|
|
490
|
-
return /*#__PURE__*/ jsxRuntime.jsx(RenderComponent$1, {
|
|
491
|
-
get componentRef () {
|
|
492
|
-
return props.componentRef;
|
|
493
|
-
},
|
|
494
|
-
get componentOptions () {
|
|
495
|
-
return props.componentOptions;
|
|
496
|
-
},
|
|
497
|
-
get blockChildren () {
|
|
498
|
-
return props.blockChildren;
|
|
499
|
-
},
|
|
500
|
-
get context () {
|
|
501
|
-
return props.context;
|
|
502
|
-
},
|
|
503
|
-
[qwik._IMMUTABLE]: {
|
|
504
|
-
componentRef: qwik._wrapSignal(props, "componentRef"),
|
|
505
|
-
componentOptions: qwik._wrapSignal(props, "componentOptions"),
|
|
506
|
-
blockChildren: qwik._wrapSignal(props, "blockChildren"),
|
|
507
|
-
context: qwik._wrapSignal(props, "context")
|
|
508
|
-
}
|
|
509
|
-
});
|
|
510
|
-
}, "RenderComponentWithContext_component_nXOUbUnjTAo"));
|
|
511
|
-
const RenderComponentWithContext$1 = RenderComponentWithContext;
|
|
512
|
-
|
|
513
496
|
// GENERATED BY MITOSIS
|
|
514
497
|
/**
|
|
515
498
|
* We can't make this a generic `ProvideContext` function because Vue 2 won't support root slots, e.g.
|
|
@@ -592,8 +575,9 @@ const actions = function actions(props, state) {
|
|
|
592
575
|
});
|
|
593
576
|
};
|
|
594
577
|
const attributes = function attributes(props, state) {
|
|
578
|
+
const blockProperties = getBlockProperties(useBlock(props));
|
|
595
579
|
return {
|
|
596
|
-
...
|
|
580
|
+
...blockProperties,
|
|
597
581
|
...{}
|
|
598
582
|
};
|
|
599
583
|
};
|
|
@@ -614,7 +598,8 @@ const renderComponentProps = function renderComponentProps(props, state) {
|
|
|
614
598
|
...attributes(props),
|
|
615
599
|
...actions(props)
|
|
616
600
|
}
|
|
617
|
-
}
|
|
601
|
+
},
|
|
602
|
+
customBreakpoints: childrenContext(props)?.content?.meta?.breakpoints
|
|
618
603
|
},
|
|
619
604
|
context: childrenContext(props)
|
|
620
605
|
};
|
|
@@ -678,8 +663,7 @@ const childrenContext = function childrenContext(props, state) {
|
|
|
678
663
|
};
|
|
679
664
|
};
|
|
680
665
|
const renderComponentTag = function renderComponentTag(props, state) {
|
|
681
|
-
|
|
682
|
-
else return RenderComponent$1;
|
|
666
|
+
return RenderComponent$1;
|
|
683
667
|
};
|
|
684
668
|
const RenderBlock = (props)=>{
|
|
685
669
|
const state = {};
|
|
@@ -736,7 +720,7 @@ const RenderBlock = (props)=>{
|
|
|
736
720
|
const RenderBlock$1 = RenderBlock;
|
|
737
721
|
|
|
738
722
|
// GENERATED BY MITOSIS
|
|
739
|
-
const className = function className(props, state, builderContext) {
|
|
723
|
+
const className$1 = function className(props, state, builderContext) {
|
|
740
724
|
return "builder-blocks" + (!props.blocks?.length ? " no-blocks" : "");
|
|
741
725
|
};
|
|
742
726
|
const onClick$1 = function onClick(props, state, builderContext) {
|
|
@@ -762,7 +746,7 @@ const RenderBlocks = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
|
762
746
|
const builderContext = qwik.useContext(BuilderContext);
|
|
763
747
|
const state = {};
|
|
764
748
|
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
765
|
-
class: className(props) + " div-RenderBlocks",
|
|
749
|
+
class: className$1(props) + " div-RenderBlocks",
|
|
766
750
|
get "builder-path" () {
|
|
767
751
|
return props.path;
|
|
768
752
|
},
|
|
@@ -853,54 +837,113 @@ const columnCssVars = function columnCssVars(props, state) {
|
|
|
853
837
|
"--column-margin-left-tablet": maybeApplyForTablet(props, state, marginLeft)
|
|
854
838
|
};
|
|
855
839
|
};
|
|
840
|
+
const getWidthForBreakpointSize = function getWidthForBreakpointSize(props, state, size) {
|
|
841
|
+
const breakpointSizes = getSizesForBreakpoints(props.customBreakpoints || {});
|
|
842
|
+
return breakpointSizes[size].max;
|
|
843
|
+
};
|
|
844
|
+
const columnStyleObjects = function columnStyleObjects(props, state) {
|
|
845
|
+
return {
|
|
846
|
+
columns: {
|
|
847
|
+
small: {
|
|
848
|
+
flexDirection: "var(--flex-dir)",
|
|
849
|
+
alignItems: "stretch"
|
|
850
|
+
},
|
|
851
|
+
medium: {
|
|
852
|
+
flexDirection: "var(--flex-dir-tablet)",
|
|
853
|
+
alignItems: "stretch"
|
|
854
|
+
}
|
|
855
|
+
},
|
|
856
|
+
column: {
|
|
857
|
+
small: {
|
|
858
|
+
width: "var(--column-width) !important",
|
|
859
|
+
marginLeft: "var(--column-margin-left) !important"
|
|
860
|
+
},
|
|
861
|
+
medium: {
|
|
862
|
+
width: "var(--column-width-tablet) !important",
|
|
863
|
+
marginLeft: "var(--column-margin-left-tablet) !important"
|
|
864
|
+
}
|
|
865
|
+
}
|
|
866
|
+
};
|
|
867
|
+
};
|
|
868
|
+
const columnsStyles = function columnsStyles(props, state) {
|
|
869
|
+
return `
|
|
870
|
+
@media (max-width: ${getWidthForBreakpointSize(props, state, "medium")}px) {
|
|
871
|
+
.${props.builderBlock.id}-breakpoints {
|
|
872
|
+
${convertStyleMapToCSS(columnStyleObjects().columns.medium)}
|
|
873
|
+
}
|
|
874
|
+
|
|
875
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
876
|
+
${convertStyleMapToCSS(columnStyleObjects().column.medium)}
|
|
877
|
+
}
|
|
878
|
+
}
|
|
879
|
+
|
|
880
|
+
@media (max-width: ${getWidthForBreakpointSize(props, state, "small")}px) {
|
|
881
|
+
.${props.builderBlock.id}-breakpoints {
|
|
882
|
+
${convertStyleMapToCSS(columnStyleObjects().columns.small)}
|
|
883
|
+
}
|
|
884
|
+
|
|
885
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
886
|
+
${convertStyleMapToCSS(columnStyleObjects().column.small)}
|
|
887
|
+
}
|
|
888
|
+
},
|
|
889
|
+
`;
|
|
890
|
+
};
|
|
891
|
+
const reactNativeColumnsStyles = function reactNativeColumnsStyles(props, state) {
|
|
892
|
+
return columnStyleObjects().columns.small;
|
|
893
|
+
};
|
|
894
|
+
const reactNativeColumnStyles = function reactNativeColumnStyles(props, state) {
|
|
895
|
+
return columnStyleObjects().column.small;
|
|
896
|
+
};
|
|
856
897
|
const Columns = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
857
898
|
qwik.useStylesScopedQrl(qwik.inlinedQrl(STYLES$2, "Columns_component_useStylesScoped_s7JLZz7MCCQ"));
|
|
858
899
|
const state = {};
|
|
859
|
-
return /*#__PURE__*/ jsxRuntime.
|
|
860
|
-
class:
|
|
861
|
-
style:
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
|
|
872
|
-
|
|
873
|
-
|
|
874
|
-
|
|
875
|
-
|
|
876
|
-
|
|
877
|
-
},
|
|
878
|
-
styleProp: {
|
|
879
|
-
flexGrow: "1"
|
|
900
|
+
return /*#__PURE__*/ jsxRuntime.jsxs("div", {
|
|
901
|
+
class: `builder-columns ${props.builderBlock.id}-breakpoints` + " div-Columns",
|
|
902
|
+
style: {
|
|
903
|
+
...TARGET === "reactNative" ? reactNativeColumnsStyles() : {},
|
|
904
|
+
...columnsCssVars(props, state)
|
|
905
|
+
},
|
|
906
|
+
children: [
|
|
907
|
+
TARGET !== "reactNative" ? /*#__PURE__*/ jsxRuntime.jsx(RenderInlinedStyles$1, {
|
|
908
|
+
styles: columnsStyles(props, state)
|
|
909
|
+
}) : null,
|
|
910
|
+
(props.columns || []).map(function(column, index) {
|
|
911
|
+
return /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
912
|
+
class: "builder-column div-Columns-2",
|
|
913
|
+
style: {
|
|
914
|
+
width: getColumnCssWidth(props, state, index),
|
|
915
|
+
marginLeft: `${index === 0 ? 0 : getGutterSize(props)}px`,
|
|
916
|
+
...TARGET === "reactNative" ? reactNativeColumnStyles() : {},
|
|
917
|
+
...columnCssVars(props, state)
|
|
880
918
|
},
|
|
881
|
-
|
|
882
|
-
blocks
|
|
883
|
-
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
919
|
+
children: /*#__PURE__*/ jsxRuntime.jsx(RenderBlocks$1, {
|
|
920
|
+
get blocks () {
|
|
921
|
+
return column.blocks;
|
|
922
|
+
},
|
|
923
|
+
path: `component.options.columns.${index}.blocks`,
|
|
924
|
+
get parent () {
|
|
925
|
+
return props.builderBlock.id;
|
|
926
|
+
},
|
|
927
|
+
styleProp: {
|
|
928
|
+
flexGrow: "1"
|
|
929
|
+
},
|
|
930
|
+
[qwik._IMMUTABLE]: {
|
|
931
|
+
blocks: qwik._wrapSignal(column, "blocks"),
|
|
932
|
+
parent: qwik._wrapSignal(props.builderBlock, "id")
|
|
933
|
+
}
|
|
934
|
+
})
|
|
935
|
+
}, index);
|
|
936
|
+
})
|
|
937
|
+
]
|
|
888
938
|
});
|
|
889
939
|
}, "Columns_component_7yLj4bxdI6c"));
|
|
890
940
|
const Columns$1 = Columns;
|
|
891
941
|
const STYLES$2 = `.div-Columns {
|
|
892
942
|
display: flex;
|
|
893
|
-
|
|
894
|
-
line-height: normal; }@media (max-width: 991px) { .div-Columns {
|
|
895
|
-
flex-direction: var(--flex-dir-tablet); } }@media (max-width: 639px) { .div-Columns {
|
|
896
|
-
flex-direction: var(--flex-dir); } }.div-Columns-2 {
|
|
943
|
+
line-height: normal; }.div-Columns-2 {
|
|
897
944
|
display: flex;
|
|
898
945
|
flex-direction: column;
|
|
899
|
-
align-items: stretch; }
|
|
900
|
-
width: var(--column-width-tablet) !important;
|
|
901
|
-
margin-left: var(--column-margin-left-tablet) !important; } }@media (max-width: 639px) { .div-Columns-2 {
|
|
902
|
-
width: var(--column-width) !important;
|
|
903
|
-
margin-left: var(--column-margin-left) !important; } }`;
|
|
946
|
+
align-items: stretch; }`;
|
|
904
947
|
|
|
905
948
|
// Taken from (and modified) the shopify theme script repo
|
|
906
949
|
// https://github.com/Shopify/theme-scripts/blob/bcfb471f2a57d439e2f964a1bb65b67708cc90c3/packages/theme-images/images.js#L59
|
|
@@ -1654,9 +1697,18 @@ const componentInfo$6 = {
|
|
|
1654
1697
|
const SectionComponent = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
1655
1698
|
return /*#__PURE__*/ jsxRuntime.jsx("section", {
|
|
1656
1699
|
...props.attributes,
|
|
1657
|
-
style:
|
|
1658
|
-
|
|
1659
|
-
|
|
1700
|
+
style: {
|
|
1701
|
+
width: "100%",
|
|
1702
|
+
alignSelf: "stretch",
|
|
1703
|
+
flexGrow: "1",
|
|
1704
|
+
boxSizing: "border-box",
|
|
1705
|
+
maxWidth: `${props.maxWidth && typeof props.maxWidth === "number" ? props.maxWidth : 1200}px`,
|
|
1706
|
+
display: "flex",
|
|
1707
|
+
flexDirection: "column",
|
|
1708
|
+
alignItems: "stretch",
|
|
1709
|
+
marginLeft: "auto",
|
|
1710
|
+
marginRight: "auto"
|
|
1711
|
+
},
|
|
1660
1712
|
children: /*#__PURE__*/ jsxRuntime.jsx(qwik.Slot, {})
|
|
1661
1713
|
});
|
|
1662
1714
|
}, "SectionComponent_component_ZWF9iD5WeLg"));
|
|
@@ -2116,73 +2168,24 @@ const componentInfo = {
|
|
|
2116
2168
|
}
|
|
2117
2169
|
];
|
|
2118
2170
|
|
|
2119
|
-
/**
|
|
2120
|
-
* Convert deep object to a flat object with dots
|
|
2121
|
-
*
|
|
2122
|
-
* { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
|
|
2123
|
-
*/ function flatten(object, path = null, separator = '.') {
|
|
2124
|
-
return Object.keys(object).reduce((acc, key)=>{
|
|
2125
|
-
const value = object[key];
|
|
2126
|
-
const newPath = [
|
|
2127
|
-
path,
|
|
2128
|
-
key
|
|
2129
|
-
].filter(Boolean).join(separator);
|
|
2130
|
-
const isObject = [
|
|
2131
|
-
typeof value === 'object',
|
|
2132
|
-
value !== null,
|
|
2133
|
-
!(Array.isArray(value) && value.length === 0)
|
|
2134
|
-
].every(Boolean);
|
|
2135
|
-
return isObject ? {
|
|
2136
|
-
...acc,
|
|
2137
|
-
...flatten(value, newPath, separator)
|
|
2138
|
-
} : {
|
|
2139
|
-
...acc,
|
|
2140
|
-
[newPath]: value
|
|
2141
|
-
};
|
|
2142
|
-
}, {});
|
|
2143
|
-
}
|
|
2144
|
-
|
|
2145
|
-
const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
|
|
2146
|
-
const BUILDER_OPTIONS_PREFIX = 'options.';
|
|
2147
|
-
const convertSearchParamsToQueryObject = (searchParams)=>{
|
|
2148
|
-
const options = {};
|
|
2149
|
-
searchParams.forEach((value, key)=>{
|
|
2150
|
-
options[key] = value;
|
|
2151
|
-
});
|
|
2152
|
-
return options;
|
|
2153
|
-
};
|
|
2154
|
-
const getBuilderSearchParams = (_options)=>{
|
|
2155
|
-
if (!_options) return {};
|
|
2156
|
-
const options = normalizeSearchParams(_options);
|
|
2157
|
-
const newOptions = {};
|
|
2158
|
-
Object.keys(options).forEach((key)=>{
|
|
2159
|
-
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
2160
|
-
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
|
|
2161
|
-
newOptions[trimmedKey] = options[key];
|
|
2162
|
-
}
|
|
2163
|
-
});
|
|
2164
|
-
return newOptions;
|
|
2165
|
-
};
|
|
2166
|
-
const getBuilderSearchParamsFromWindow = ()=>{
|
|
2167
|
-
if (!isBrowser()) return {};
|
|
2168
|
-
const searchParams = new URLSearchParams(window.location.search);
|
|
2169
|
-
return getBuilderSearchParams(searchParams);
|
|
2170
|
-
};
|
|
2171
|
-
const normalizeSearchParams = (searchParams)=>searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
2172
|
-
|
|
2173
2171
|
function getGlobalThis() {
|
|
2174
2172
|
if (typeof globalThis !== 'undefined') return globalThis;
|
|
2175
2173
|
if (typeof window !== 'undefined') return window;
|
|
2176
2174
|
if (typeof global !== 'undefined') return global;
|
|
2177
2175
|
if (typeof self !== 'undefined') return self;
|
|
2178
|
-
return
|
|
2176
|
+
return globalThis;
|
|
2179
2177
|
}
|
|
2180
2178
|
|
|
2181
|
-
|
|
2179
|
+
function getFetch() {
|
|
2182
2180
|
const globalFetch = getGlobalThis().fetch;
|
|
2183
|
-
if (typeof globalFetch === 'undefined'
|
|
2184
|
-
|
|
2181
|
+
if (typeof globalFetch === 'undefined') {
|
|
2182
|
+
console.warn(`Builder SDK could not find a global fetch function. Make sure you have a polyfill for fetch in your project.
|
|
2183
|
+
For more information, read https://github.com/BuilderIO/this-package-uses-fetch`);
|
|
2184
|
+
throw new Error('Builder SDK could not find a global `fetch` function');
|
|
2185
|
+
}
|
|
2186
|
+
return globalFetch;
|
|
2185
2187
|
}
|
|
2188
|
+
const fetch$1 = getFetch();
|
|
2186
2189
|
|
|
2187
2190
|
/**
|
|
2188
2191
|
* Only gets one level up from hostname
|
|
@@ -2279,8 +2282,6 @@ const setContentVariationCookie = ({ contentId , canTrack , value })=>setCookie
|
|
|
2279
2282
|
canTrack
|
|
2280
2283
|
});
|
|
2281
2284
|
|
|
2282
|
-
const checkIsDefined = (maybeT)=>maybeT !== null && maybeT !== undefined;
|
|
2283
|
-
|
|
2284
2285
|
const checkIsBuilderContentWithVariations = (item)=>checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
|
|
2285
2286
|
/**
|
|
2286
2287
|
* Randomly assign a variation to this user and store it in cookies/storage
|
|
@@ -2351,12 +2352,60 @@ const handleABTesting = async ({ item , canTrack })=>{
|
|
|
2351
2352
|
Object.assign(item, variationValue);
|
|
2352
2353
|
};
|
|
2353
2354
|
|
|
2354
|
-
|
|
2355
|
-
|
|
2356
|
-
|
|
2357
|
-
|
|
2358
|
-
|
|
2355
|
+
/**
|
|
2356
|
+
* Convert deep object to a flat object with dots
|
|
2357
|
+
*
|
|
2358
|
+
* { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
|
|
2359
|
+
*/ function flatten(object, path = null, separator = '.') {
|
|
2360
|
+
return Object.keys(object).reduce((acc, key)=>{
|
|
2361
|
+
const value = object[key];
|
|
2362
|
+
const newPath = [
|
|
2363
|
+
path,
|
|
2364
|
+
key
|
|
2365
|
+
].filter(Boolean).join(separator);
|
|
2366
|
+
const isObject = [
|
|
2367
|
+
typeof value === 'object',
|
|
2368
|
+
value !== null,
|
|
2369
|
+
!(Array.isArray(value) && value.length === 0)
|
|
2370
|
+
].every(Boolean);
|
|
2371
|
+
return isObject ? {
|
|
2372
|
+
...acc,
|
|
2373
|
+
...flatten(value, newPath, separator)
|
|
2374
|
+
} : {
|
|
2375
|
+
...acc,
|
|
2376
|
+
[newPath]: value
|
|
2377
|
+
};
|
|
2378
|
+
}, {});
|
|
2359
2379
|
}
|
|
2380
|
+
|
|
2381
|
+
const BUILDER_SEARCHPARAMS_PREFIX = 'builder.';
|
|
2382
|
+
const BUILDER_OPTIONS_PREFIX = 'options.';
|
|
2383
|
+
const convertSearchParamsToQueryObject = (searchParams)=>{
|
|
2384
|
+
const options = {};
|
|
2385
|
+
searchParams.forEach((value, key)=>{
|
|
2386
|
+
options[key] = value;
|
|
2387
|
+
});
|
|
2388
|
+
return options;
|
|
2389
|
+
};
|
|
2390
|
+
const getBuilderSearchParams = (_options)=>{
|
|
2391
|
+
if (!_options) return {};
|
|
2392
|
+
const options = normalizeSearchParams(_options);
|
|
2393
|
+
const newOptions = {};
|
|
2394
|
+
Object.keys(options).forEach((key)=>{
|
|
2395
|
+
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
2396
|
+
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, '').replace(BUILDER_OPTIONS_PREFIX, '');
|
|
2397
|
+
newOptions[trimmedKey] = options[key];
|
|
2398
|
+
}
|
|
2399
|
+
});
|
|
2400
|
+
return newOptions;
|
|
2401
|
+
};
|
|
2402
|
+
const getBuilderSearchParamsFromWindow = ()=>{
|
|
2403
|
+
if (!isBrowser()) return {};
|
|
2404
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
2405
|
+
return getBuilderSearchParams(searchParams);
|
|
2406
|
+
};
|
|
2407
|
+
const normalizeSearchParams = (searchParams)=>searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
2408
|
+
|
|
2360
2409
|
const generateContentUrl = (options)=>{
|
|
2361
2410
|
const { limit =30 , userAttributes , query , noTraverse =false , model , apiKey , includeRefs =true , locale , } = options;
|
|
2362
2411
|
if (!apiKey) throw new Error('Missing API key');
|
|
@@ -2376,10 +2425,17 @@ const generateContentUrl = (options)=>{
|
|
|
2376
2425
|
}
|
|
2377
2426
|
return url;
|
|
2378
2427
|
};
|
|
2428
|
+
|
|
2429
|
+
async function getContent(options) {
|
|
2430
|
+
return (await getAllContent({
|
|
2431
|
+
...options,
|
|
2432
|
+
limit: 1
|
|
2433
|
+
})).results[0] || null;
|
|
2434
|
+
}
|
|
2379
2435
|
async function getAllContent(options) {
|
|
2380
2436
|
const url = generateContentUrl(options);
|
|
2381
|
-
const
|
|
2382
|
-
const content = await
|
|
2437
|
+
const res = await fetch$1(url.href);
|
|
2438
|
+
const content = await res.json();
|
|
2383
2439
|
const canTrack = options.canTrack !== false;
|
|
2384
2440
|
if (canTrack && // This makes sure we have a non-error response with the results array.
|
|
2385
2441
|
Array.isArray(content.results)) for (const item of content.results)await handleABTesting({
|
|
@@ -2617,6 +2673,11 @@ const useContent = function useContent(props, state, elementRef) {
|
|
|
2617
2673
|
...props.content?.data,
|
|
2618
2674
|
...props.data,
|
|
2619
2675
|
...state.overrideContent?.data
|
|
2676
|
+
},
|
|
2677
|
+
meta: {
|
|
2678
|
+
...props.content?.meta,
|
|
2679
|
+
...state.overrideContent?.meta,
|
|
2680
|
+
breakpoints: state.useBreakpoints || state.overrideContent?.meta?.breakpoints || props.content?.meta?.breakpoints
|
|
2620
2681
|
}
|
|
2621
2682
|
};
|
|
2622
2683
|
return mergedContent;
|
|
@@ -2657,11 +2718,20 @@ const allRegisteredComponents = function allRegisteredComponents(props, state, e
|
|
|
2657
2718
|
const processMessage = function processMessage(props, state, elementRef, event) {
|
|
2658
2719
|
const { data } = event;
|
|
2659
2720
|
if (data) switch(data.type){
|
|
2660
|
-
case "builder.
|
|
2721
|
+
case "builder.configureSdk":
|
|
2661
2722
|
{
|
|
2662
2723
|
const messageContent = data.data;
|
|
2663
|
-
const
|
|
2664
|
-
|
|
2724
|
+
const { breakpoints , contentId } = messageContent;
|
|
2725
|
+
if (!contentId || contentId !== useContent(props, state)?.id) return;
|
|
2726
|
+
state.useBreakpoints = breakpoints;
|
|
2727
|
+
state.forceReRenderCount = state.forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
2728
|
+
break;
|
|
2729
|
+
}
|
|
2730
|
+
case "builder.contentUpdate":
|
|
2731
|
+
{
|
|
2732
|
+
const messageContent1 = data.data;
|
|
2733
|
+
const key = messageContent1.key || messageContent1.alias || messageContent1.entry || messageContent1.modelName;
|
|
2734
|
+
const contentData = messageContent1.data;
|
|
2665
2735
|
if (key === props.model) {
|
|
2666
2736
|
state.overrideContent = contentData;
|
|
2667
2737
|
state.forceReRenderCount = state.forceReRenderCount + 1; // This is a hack to force Qwik to re-render.
|
|
@@ -2703,7 +2773,7 @@ const evalExpression = function evalExpression(props, state, elementRef, express
|
|
|
2703
2773
|
}));
|
|
2704
2774
|
};
|
|
2705
2775
|
const handleRequest = function handleRequest(props, state, elementRef, { url , key }) {
|
|
2706
|
-
|
|
2776
|
+
fetch$1(url).then((response)=>response.json()).then((json)=>{
|
|
2707
2777
|
const newOverrideState = {
|
|
2708
2778
|
...state.overrideState,
|
|
2709
2779
|
[key]: json
|
|
@@ -2744,7 +2814,8 @@ const RenderContent = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
|
2744
2814
|
forceReRenderCount: 0,
|
|
2745
2815
|
overrideContent: null,
|
|
2746
2816
|
overrideState: {},
|
|
2747
|
-
update: 0
|
|
2817
|
+
update: 0,
|
|
2818
|
+
useBreakpoints: null
|
|
2748
2819
|
});
|
|
2749
2820
|
qwik.useContextProvider(BuilderContext, qwik.useStore({
|
|
2750
2821
|
content: (()=>{
|
|
@@ -2890,13 +2961,22 @@ const RenderContent = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
|
2890
2961
|
const RenderContent$1 = RenderContent;
|
|
2891
2962
|
|
|
2892
2963
|
// GENERATED BY MITOSIS
|
|
2964
|
+
const className = function className(props, state, builderContext) {
|
|
2965
|
+
return [
|
|
2966
|
+
...[
|
|
2967
|
+
props.attributes.class
|
|
2968
|
+
],
|
|
2969
|
+
"builder-symbol",
|
|
2970
|
+
props.symbol?.inline ? "builder-inline-symbol" : undefined,
|
|
2971
|
+
props.symbol?.dynamic || props.dynamic ? "builder-dynamic-symbol" : undefined
|
|
2972
|
+
].filter(Boolean).join(" ");
|
|
2973
|
+
};
|
|
2893
2974
|
const contentToUse = function contentToUse(props, state, builderContext) {
|
|
2894
2975
|
return props.symbol?.content || state.fetchedContent;
|
|
2895
2976
|
};
|
|
2896
2977
|
const Symbol$1 = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
2897
2978
|
const builderContext = qwik.useContext(BuilderContext);
|
|
2898
2979
|
const state = qwik.useStore({
|
|
2899
|
-
className: "builder-symbol",
|
|
2900
2980
|
fetchedContent: null
|
|
2901
2981
|
});
|
|
2902
2982
|
qwik.useWatchQrl(qwik.inlinedQrl(({ track })=>{
|
|
@@ -2928,9 +3008,7 @@ const Symbol$1 = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
|
2928
3008
|
]));
|
|
2929
3009
|
return /*#__PURE__*/ jsxRuntime.jsx("div", {
|
|
2930
3010
|
...props.attributes,
|
|
2931
|
-
|
|
2932
|
-
return state.className;
|
|
2933
|
-
},
|
|
3011
|
+
class: className(props),
|
|
2934
3012
|
children: /*#__PURE__*/ jsxRuntime.jsx(RenderContent$1, {
|
|
2935
3013
|
get apiKey () {
|
|
2936
3014
|
return builderContext.apiKey;
|
|
@@ -2950,10 +3028,7 @@ const Symbol$1 = /*#__PURE__*/ qwik.componentQrl(qwik.inlinedQrl((props)=>{
|
|
|
2950
3028
|
apiKey: qwik._wrapSignal(builderContext, "apiKey"),
|
|
2951
3029
|
context: qwik._wrapSignal(builderContext, "context")
|
|
2952
3030
|
}
|
|
2953
|
-
})
|
|
2954
|
-
[qwik._IMMUTABLE]: {
|
|
2955
|
-
class: qwik._wrapSignal(state, "className")
|
|
2956
|
-
}
|
|
3031
|
+
})
|
|
2957
3032
|
});
|
|
2958
3033
|
}, "Symbol_component_WVvggdkUPdk"));
|
|
2959
3034
|
const Symbol$2 = Symbol$1;
|
|
@@ -2983,7 +3058,6 @@ exports.Video = Video$1;
|
|
|
2983
3058
|
exports.components = components;
|
|
2984
3059
|
exports.convertSearchParamsToQueryObject = convertSearchParamsToQueryObject;
|
|
2985
3060
|
exports.createRegisterComponentMessage = createRegisterComponentMessage;
|
|
2986
|
-
exports.generateContentUrl = generateContentUrl;
|
|
2987
3061
|
exports.getAllContent = getAllContent;
|
|
2988
3062
|
exports.getBuilderSearchParams = getBuilderSearchParams;
|
|
2989
3063
|
exports.getBuilderSearchParamsFromWindow = getBuilderSearchParamsFromWindow;
|