@builder.io/sdk-solid 0.0.21 → 0.0.23
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/package.json +2 -1
- package/src/blocks/columns/columns.jsx +73 -20
- package/src/blocks/image/image.jsx +15 -8
- package/src/blocks/section/section.jsx +12 -3
- package/src/blocks/symbol/symbol.jsx +4 -1
- package/src/components/render-block/render-block.jsx +21 -12
- package/src/components/render-content/render-content.jsx +37 -4
- package/src/functions/evaluate.js +4 -3
- package/src/functions/get-block-actions-handler.js +8 -9
- package/src/functions/get-block-actions.js +2 -2
- package/src/functions/get-block-properties.js +22 -1
- package/src/functions/get-builder-search-params/index.js +2 -1
- package/src/functions/get-content/index.js +4 -3
- package/src/functions/get-react-native-block-styles.js +3 -2
- package/src/functions/track.js +4 -0
- package/src/functions/transform-block-properties.js +6 -0
- package/src/helpers/css.js +9 -3
- package/src/scripts/init-editing.js +10 -4
- package/src/functions/mark-mutable.js +0 -10
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-solid",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.23",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./solid-index.jsx",
|
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
".": "./solid-index.jsx"
|
|
10
10
|
},
|
|
11
11
|
"scripts": {
|
|
12
|
+
"build": "echo 'no need to build solid SDK'",
|
|
12
13
|
"release:patch": "npm version patch --no-git-tag-version && npm publish --access public",
|
|
13
14
|
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
14
15
|
},
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
-
import { For } from "solid-js";
|
|
1
|
+
import { Show, For } from "solid-js";
|
|
2
2
|
import { css } from "solid-styled-components";
|
|
3
3
|
import RenderBlocks from "../../components/render-blocks.jsx";
|
|
4
|
+
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
5
|
+
import RenderInlinedStyles from "../../components/render-inlined-styles.jsx";
|
|
6
|
+
import { TARGET } from "../../constants/target.js";
|
|
7
|
+
import { convertStyleMapToCSS } from "../../helpers/css";
|
|
4
8
|
function Columns(props) {
|
|
5
9
|
function getGutterSize() {
|
|
6
10
|
return typeof props.space === "number" ? props.space || 0 : 20;
|
|
@@ -39,35 +43,84 @@ function Columns(props) {
|
|
|
39
43
|
"--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
|
|
40
44
|
};
|
|
41
45
|
}
|
|
42
|
-
|
|
46
|
+
function getWidthForBreakpointSize(size) {
|
|
47
|
+
const breakpointSizes = getSizesForBreakpoints(props.customBreakpoints || {});
|
|
48
|
+
return breakpointSizes[size].max;
|
|
49
|
+
}
|
|
50
|
+
function columnStyleObjects() {
|
|
51
|
+
return {
|
|
52
|
+
columns: {
|
|
53
|
+
small: {
|
|
54
|
+
flexDirection: "var(--flex-dir)",
|
|
55
|
+
alignItems: "stretch"
|
|
56
|
+
},
|
|
57
|
+
medium: {
|
|
58
|
+
flexDirection: "var(--flex-dir-tablet)",
|
|
59
|
+
alignItems: "stretch"
|
|
60
|
+
}
|
|
61
|
+
},
|
|
62
|
+
column: {
|
|
63
|
+
small: {
|
|
64
|
+
width: "var(--column-width) !important",
|
|
65
|
+
marginLeft: "var(--column-margin-left) !important"
|
|
66
|
+
},
|
|
67
|
+
medium: {
|
|
68
|
+
width: "var(--column-width-tablet) !important",
|
|
69
|
+
marginLeft: "var(--column-margin-left-tablet) !important"
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
function columnsStyles() {
|
|
75
|
+
return `
|
|
76
|
+
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
77
|
+
.${props.builderBlock.id}-breakpoints {
|
|
78
|
+
${convertStyleMapToCSS(columnStyleObjects().columns.medium)}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
82
|
+
${convertStyleMapToCSS(columnStyleObjects().column.medium)}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
87
|
+
.${props.builderBlock.id}-breakpoints {
|
|
88
|
+
${convertStyleMapToCSS(columnStyleObjects().columns.small)}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
92
|
+
${convertStyleMapToCSS(columnStyleObjects().column.small)}
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
`;
|
|
96
|
+
}
|
|
97
|
+
function reactNativeColumnsStyles() {
|
|
98
|
+
return this.columnStyleObjects.columns.small;
|
|
99
|
+
}
|
|
100
|
+
function reactNativeColumnStyles() {
|
|
101
|
+
return this.columnStyleObjects.column.small;
|
|
102
|
+
}
|
|
103
|
+
return <div class={`builder-columns ${props.builderBlock.id}-breakpoints` + " " + css({
|
|
43
104
|
display: "flex",
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
"
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
})} style={columnsCssVars()}>
|
|
105
|
+
lineHeight: "normal"
|
|
106
|
+
})} style={{
|
|
107
|
+
...(TARGET === "reactNative" ? reactNativeColumnsStyles() : {}),
|
|
108
|
+
...columnsCssVars()
|
|
109
|
+
}}>
|
|
110
|
+
<Show when={TARGET !== "reactNative"}>
|
|
111
|
+
<RenderInlinedStyles styles={columnsStyles()}></RenderInlinedStyles>
|
|
112
|
+
</Show>
|
|
53
113
|
<For each={props.columns}>
|
|
54
114
|
{(column, _index) => {
|
|
55
115
|
const index = _index();
|
|
56
116
|
return <div class={"builder-column " + css({
|
|
57
117
|
display: "flex",
|
|
58
118
|
flexDirection: "column",
|
|
59
|
-
alignItems: "stretch"
|
|
60
|
-
"@media (max-width: 991px)": {
|
|
61
|
-
width: "var(--column-width-tablet) !important",
|
|
62
|
-
marginLeft: "var(--column-margin-left-tablet) !important"
|
|
63
|
-
},
|
|
64
|
-
"@media (max-width: 639px)": {
|
|
65
|
-
width: "var(--column-width) !important",
|
|
66
|
-
marginLeft: "var(--column-margin-left) !important"
|
|
67
|
-
}
|
|
119
|
+
alignItems: "stretch"
|
|
68
120
|
})} style={{
|
|
69
121
|
width: getColumnCssWidth(index),
|
|
70
122
|
"margin-left": `${index === 0 ? 0 : getGutterSize()}px`,
|
|
123
|
+
...(TARGET === "reactNative" ? reactNativeColumnStyles() : {}),
|
|
71
124
|
...columnCssVars()
|
|
72
125
|
}} key={index}>
|
|
73
126
|
<RenderBlocks blocks={column.blocks} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id} styleProp={{
|
|
@@ -28,6 +28,17 @@ function Image(props) {
|
|
|
28
28
|
return "";
|
|
29
29
|
}
|
|
30
30
|
}
|
|
31
|
+
function aspectRatioCss() {
|
|
32
|
+
const aspectRatioStyles = {
|
|
33
|
+
position: "absolute",
|
|
34
|
+
height: "100%",
|
|
35
|
+
width: "100%",
|
|
36
|
+
left: "0px",
|
|
37
|
+
top: "0px"
|
|
38
|
+
};
|
|
39
|
+
const out = props.aspectRatio ? aspectRatioStyles : undefined;
|
|
40
|
+
return out;
|
|
41
|
+
}
|
|
31
42
|
return <>
|
|
32
43
|
<picture>
|
|
33
44
|
<Show when={webpSrcSet()}>
|
|
@@ -35,15 +46,11 @@ function Image(props) {
|
|
|
35
46
|
</Show>
|
|
36
47
|
<img class={"builder-image" + (props.className ? " " + props.className : "") + " " + css({
|
|
37
48
|
opacity: "1",
|
|
38
|
-
transition: "opacity 0.2s ease-in-out"
|
|
39
|
-
position: "absolute",
|
|
40
|
-
height: "100%",
|
|
41
|
-
width: "100%",
|
|
42
|
-
top: "0px",
|
|
43
|
-
left: "0px"
|
|
49
|
+
transition: "opacity 0.2s ease-in-out"
|
|
44
50
|
})} loading="lazy" alt={props.altText} role={props.altText ? "presentation" : undefined} style={{
|
|
45
|
-
"object-position": props.
|
|
46
|
-
"object-fit": props.backgroundSize || "cover"
|
|
51
|
+
"object-position": props.backgroundPosition || "center",
|
|
52
|
+
"object-fit": props.backgroundSize || "cover",
|
|
53
|
+
...aspectRatioCss()
|
|
47
54
|
}} src={props.image} srcset={srcSetToUse()} sizes={props.sizes} />
|
|
48
55
|
<source srcset={srcSetToUse()} />
|
|
49
56
|
</picture>
|
|
@@ -1,7 +1,16 @@
|
|
|
1
1
|
function SectionComponent(props) {
|
|
2
|
-
return <section {...props.attributes} style={
|
|
3
|
-
|
|
4
|
-
|
|
2
|
+
return <section {...props.attributes} style={{
|
|
3
|
+
width: "100%",
|
|
4
|
+
"align-self": "stretch",
|
|
5
|
+
"flex-grow": "1",
|
|
6
|
+
"box-sizing": "border-box",
|
|
7
|
+
"max-width": `${props.maxWidth && typeof props.maxWidth === "number" ? props.maxWidth : 1200}px`,
|
|
8
|
+
display: "flex",
|
|
9
|
+
"flex-direction": "column",
|
|
10
|
+
"align-items": "stretch",
|
|
11
|
+
"margin-left": "auto",
|
|
12
|
+
"margin-right": "auto"
|
|
13
|
+
}}>
|
|
5
14
|
{props.children}
|
|
6
15
|
</section>;
|
|
7
16
|
}
|
|
@@ -2,9 +2,12 @@ import { useContext, on, createEffect, createSignal } from "solid-js";
|
|
|
2
2
|
import RenderContent from "../../components/render-content/render-content.jsx";
|
|
3
3
|
import BuilderContext from "../../context/builder.context.js";
|
|
4
4
|
import { getContent } from "../../functions/get-content/index.js";
|
|
5
|
+
import { TARGET } from "../../constants/target";
|
|
5
6
|
function Symbol(props) {
|
|
6
|
-
const [className, setClassName] = createSignal("builder-symbol");
|
|
7
7
|
const [fetchedContent, setFetchedContent] = createSignal(null);
|
|
8
|
+
function className() {
|
|
9
|
+
return [...(TARGET === "vue2" || TARGET === "vue3" ? Object.keys(props.attributes.class) : [props.attributes.class]), "builder-symbol", props.symbol?.inline ? "builder-inline-symbol" : undefined, props.symbol?.dynamic || props.dynamic ? "builder-dynamic-symbol" : undefined].filter(Boolean).join(" ");
|
|
10
|
+
}
|
|
8
11
|
function contentToUse() {
|
|
9
12
|
return props.symbol?.content || fetchedContent();
|
|
10
13
|
}
|
|
@@ -47,18 +47,22 @@ function RenderBlock(props) {
|
|
|
47
47
|
shouldEvaluateBindings: true
|
|
48
48
|
});
|
|
49
49
|
}
|
|
50
|
+
function actions() {
|
|
51
|
+
return getBlockActions({
|
|
52
|
+
block: useBlock(),
|
|
53
|
+
state: props.context.state,
|
|
54
|
+
context: props.context.context
|
|
55
|
+
});
|
|
56
|
+
}
|
|
50
57
|
function attributes() {
|
|
58
|
+
const blockProperties = getBlockProperties(useBlock());
|
|
51
59
|
return {
|
|
52
|
-
...
|
|
53
|
-
...getBlockActions({
|
|
54
|
-
block: useBlock(),
|
|
55
|
-
state: props.context.state,
|
|
56
|
-
context: props.context.context
|
|
57
|
-
}),
|
|
60
|
+
...blockProperties,
|
|
58
61
|
...(TARGET === "reactNative" ? {
|
|
59
62
|
style: getReactNativeBlockStyles({
|
|
60
63
|
block: useBlock(),
|
|
61
|
-
context: props.context
|
|
64
|
+
context: props.context,
|
|
65
|
+
blockStyles: blockProperties.style
|
|
62
66
|
})
|
|
63
67
|
} : {})
|
|
64
68
|
};
|
|
@@ -77,8 +81,12 @@ function RenderBlock(props) {
|
|
|
77
81
|
* they are provided to the component itself directly.
|
|
78
82
|
*/
|
|
79
83
|
...(shouldWrap() ? {} : {
|
|
80
|
-
attributes:
|
|
81
|
-
|
|
84
|
+
attributes: {
|
|
85
|
+
...attributes(),
|
|
86
|
+
...actions()
|
|
87
|
+
}
|
|
88
|
+
}),
|
|
89
|
+
customBreakpoints: childrenContext()?.content?.meta?.breakpoints
|
|
82
90
|
},
|
|
83
91
|
context: childrenContext()
|
|
84
92
|
};
|
|
@@ -143,7 +151,8 @@ function RenderBlock(props) {
|
|
|
143
151
|
}
|
|
144
152
|
const styles = getReactNativeBlockStyles({
|
|
145
153
|
block: useBlock(),
|
|
146
|
-
context: props.context
|
|
154
|
+
context: props.context,
|
|
155
|
+
blockStyles: attributes().style
|
|
147
156
|
});
|
|
148
157
|
return extractTextStyles(styles);
|
|
149
158
|
}
|
|
@@ -169,7 +178,7 @@ function RenderBlock(props) {
|
|
|
169
178
|
}
|
|
170
179
|
return <Show fallback={<Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>} when={shouldWrap()}>
|
|
171
180
|
<Show when={isEmptyHtmlElement(tag())}>
|
|
172
|
-
<Dynamic {...attributes()} component={tag()}></Dynamic>
|
|
181
|
+
<Dynamic {...attributes()} {...actions()} component={tag()}></Dynamic>
|
|
173
182
|
</Show>
|
|
174
183
|
<Show when={!isEmptyHtmlElement(tag()) && repeatItemData()}>
|
|
175
184
|
<For each={repeatItemData()}>
|
|
@@ -180,7 +189,7 @@ function RenderBlock(props) {
|
|
|
180
189
|
</For>
|
|
181
190
|
</Show>
|
|
182
191
|
<Show when={!isEmptyHtmlElement(tag()) && !repeatItemData()}>
|
|
183
|
-
<Dynamic {...attributes()} component={tag()}>
|
|
192
|
+
<Dynamic {...attributes()} {...actions()} component={tag()}>
|
|
184
193
|
<Dynamic {...renderComponentProps()} component={renderComponentTag()}></Dynamic>
|
|
185
194
|
<For each={childrenWithoutParentComponent()}>
|
|
186
195
|
{(child, _index) => {
|
|
@@ -3,7 +3,6 @@ import { Dynamic } from "solid-js/web";
|
|
|
3
3
|
import { createStore, reconcile } from "solid-js/store";
|
|
4
4
|
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
5
|
import { TARGET } from "../../constants/target.js";
|
|
6
|
-
import BuilderContext from "../../context/builder.context.js";
|
|
7
6
|
import { evaluate } from "../../functions/evaluate.js";
|
|
8
7
|
import { getContent } from "../../functions/get-content/index.js";
|
|
9
8
|
import { getFetch } from "../../functions/get-fetch.js";
|
|
@@ -14,11 +13,13 @@ import { components, createRegisterComponentMessage } from "../../functions/regi
|
|
|
14
13
|
import { _track } from "../../functions/track.js";
|
|
15
14
|
import RenderBlocks from "../render-blocks.jsx";
|
|
16
15
|
import RenderContentStyles from "./components/render-styles.jsx";
|
|
16
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
17
17
|
import { registerInsertMenu, setupBrowserForEditing } from "../../scripts/init-editing.js";
|
|
18
18
|
function RenderContent(props) {
|
|
19
19
|
const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
|
|
20
20
|
const [overrideContent, setOverrideContent] = createSignal(null);
|
|
21
21
|
const [update, setUpdate] = createSignal(0);
|
|
22
|
+
const [useBreakpoints, setUseBreakpoints] = createSignal(null);
|
|
22
23
|
const [overrideState, setOverrideState] = createSignal({});
|
|
23
24
|
function canTrackToUse() {
|
|
24
25
|
return props.canTrack || true;
|
|
@@ -27,6 +28,9 @@ function RenderContent(props) {
|
|
|
27
28
|
return {
|
|
28
29
|
...props.content?.data?.state,
|
|
29
30
|
...props.data,
|
|
31
|
+
...(props.locale ? {
|
|
32
|
+
locale: props.locale
|
|
33
|
+
} : {}),
|
|
30
34
|
...overrideState()
|
|
31
35
|
};
|
|
32
36
|
}
|
|
@@ -53,6 +57,20 @@ function RenderContent(props) {
|
|
|
53
57
|
} = event;
|
|
54
58
|
if (data) {
|
|
55
59
|
switch (data.type) {
|
|
60
|
+
case "builder.configureSdk":
|
|
61
|
+
{
|
|
62
|
+
const messageContent = data.data;
|
|
63
|
+
const {
|
|
64
|
+
breakpoints,
|
|
65
|
+
contentId
|
|
66
|
+
} = messageContent;
|
|
67
|
+
if (!contentId || contentId !== useContent?.id) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
setUseBreakpoints(breakpoints);
|
|
71
|
+
setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
|
|
72
|
+
break;
|
|
73
|
+
}
|
|
56
74
|
case "builder.contentUpdate":
|
|
57
75
|
{
|
|
58
76
|
const messageContent = data.data;
|
|
@@ -159,19 +177,34 @@ function RenderContent(props) {
|
|
|
159
177
|
...props.content?.data,
|
|
160
178
|
...props.data,
|
|
161
179
|
...overrideContent()?.data
|
|
180
|
+
},
|
|
181
|
+
meta: {
|
|
182
|
+
...props.content?.meta,
|
|
183
|
+
...overrideContent()?.meta,
|
|
184
|
+
breakpoints: useBreakpoints() || overrideContent()?.meta?.breakpoints || props.content?.meta?.breakpoints
|
|
162
185
|
}
|
|
163
186
|
};
|
|
164
187
|
return mergedContent;
|
|
165
188
|
};
|
|
166
189
|
const [useContent, setUseContent] = createStore(updateUseContent());
|
|
167
|
-
createEffect(on(() => [overrideContent(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
|
|
190
|
+
createEffect(on(() => [overrideContent(), useBreakpoints(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
|
|
168
191
|
let elementRef;
|
|
169
192
|
onMount(() => {
|
|
193
|
+
if (!props.apiKey) {
|
|
194
|
+
console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
195
|
+
}
|
|
170
196
|
if (isBrowser()) {
|
|
171
197
|
if (isEditing()) {
|
|
172
198
|
setForceReRenderCount(forceReRenderCount() + 1);
|
|
173
199
|
registerInsertMenu();
|
|
174
|
-
setupBrowserForEditing(
|
|
200
|
+
setupBrowserForEditing({
|
|
201
|
+
...(props.locale ? {
|
|
202
|
+
locale: props.locale
|
|
203
|
+
} : {}),
|
|
204
|
+
...(props.includeRefs ? {
|
|
205
|
+
includeRefs: props.includeRefs
|
|
206
|
+
} : {})
|
|
207
|
+
});
|
|
175
208
|
Object.values(allRegisteredComponents()).forEach(registeredComponent => {
|
|
176
209
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
177
210
|
window.parent?.postMessage(message, "*");
|
|
@@ -216,7 +249,7 @@ function RenderContent(props) {
|
|
|
216
249
|
function onUpdateFn_0() {
|
|
217
250
|
evaluateJsCode();
|
|
218
251
|
}
|
|
219
|
-
createEffect(on(() => [useContent?.data?.jsCode], onUpdateFn_0));
|
|
252
|
+
createEffect(on(() => [useContent?.data?.jsCode, contentState()], onUpdateFn_0));
|
|
220
253
|
function onUpdateFn_1() {
|
|
221
254
|
runHttpRequests();
|
|
222
255
|
}
|
|
@@ -4,7 +4,8 @@ function evaluate({
|
|
|
4
4
|
code,
|
|
5
5
|
context,
|
|
6
6
|
state,
|
|
7
|
-
event
|
|
7
|
+
event,
|
|
8
|
+
isExpression = true
|
|
8
9
|
}) {
|
|
9
10
|
if (code === "") {
|
|
10
11
|
console.warn("Skipping evaluation of empty code block.");
|
|
@@ -15,12 +16,12 @@ function evaluate({
|
|
|
15
16
|
isBrowser: isBrowser(),
|
|
16
17
|
isServer: !isBrowser()
|
|
17
18
|
};
|
|
18
|
-
const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
19
|
+
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
19
20
|
const useCode = useReturn ? `return (${code});` : code;
|
|
20
21
|
try {
|
|
21
22
|
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
|
|
22
23
|
} catch (e) {
|
|
23
|
-
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e
|
|
24
|
+
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
export {
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { evaluate } from "./evaluate.js";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}
|
|
2
|
+
const createEventHandler = (value, options) => (event) => evaluate({
|
|
3
|
+
code: value,
|
|
4
|
+
context: options.context,
|
|
5
|
+
state: options.state,
|
|
6
|
+
event,
|
|
7
|
+
isExpression: false
|
|
8
|
+
});
|
|
10
9
|
export {
|
|
11
|
-
|
|
10
|
+
createEventHandler
|
|
12
11
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { getEventHandlerName } from "./event-handler-name.js";
|
|
2
|
-
import {
|
|
2
|
+
import { createEventHandler } from "./get-block-actions-handler.js";
|
|
3
3
|
function getBlockActions(options) {
|
|
4
4
|
var _a;
|
|
5
5
|
const obj = {};
|
|
@@ -9,7 +9,7 @@ function getBlockActions(options) {
|
|
|
9
9
|
continue;
|
|
10
10
|
}
|
|
11
11
|
const value = optionActions[key];
|
|
12
|
-
obj[getEventHandlerName(key)] =
|
|
12
|
+
obj[getEventHandlerName(key)] = createEventHandler(value, options);
|
|
13
13
|
}
|
|
14
14
|
return obj;
|
|
15
15
|
}
|
|
@@ -17,12 +17,33 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
return a;
|
|
18
18
|
};
|
|
19
19
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { TARGET } from "../constants/target.js";
|
|
21
|
+
import { convertStyleMapToCSSArray } from "../helpers/css.js";
|
|
22
|
+
import { transformBlockProperties } from "./transform-block-properties.js";
|
|
20
23
|
function getBlockProperties(block) {
|
|
21
24
|
var _a;
|
|
22
|
-
|
|
25
|
+
const properties = __spreadProps(__spreadValues({}, block.properties), {
|
|
23
26
|
"builder-id": block.id,
|
|
27
|
+
style: getStyleAttribute(block.style),
|
|
24
28
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
25
29
|
});
|
|
30
|
+
return transformBlockProperties(properties);
|
|
31
|
+
}
|
|
32
|
+
function getStyleAttribute(style) {
|
|
33
|
+
if (!style) {
|
|
34
|
+
return void 0;
|
|
35
|
+
}
|
|
36
|
+
switch (TARGET) {
|
|
37
|
+
case "svelte":
|
|
38
|
+
case "vue2":
|
|
39
|
+
case "vue3":
|
|
40
|
+
case "solid":
|
|
41
|
+
return convertStyleMapToCSSArray(style).join(" ");
|
|
42
|
+
case "qwik":
|
|
43
|
+
case "reactNative":
|
|
44
|
+
case "react":
|
|
45
|
+
return style;
|
|
46
|
+
}
|
|
26
47
|
}
|
|
27
48
|
export {
|
|
28
49
|
getBlockProperties
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { isBrowser } from "../is-browser.js";
|
|
2
2
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
3
|
+
const BUILDER_OPTIONS_PREFIX = "options.";
|
|
3
4
|
const convertSearchParamsToQueryObject = (searchParams) => {
|
|
4
5
|
const options = {};
|
|
5
6
|
searchParams.forEach((value, key) => {
|
|
@@ -15,7 +16,7 @@ const getBuilderSearchParams = (_options) => {
|
|
|
15
16
|
const newOptions = {};
|
|
16
17
|
Object.keys(options).forEach((key) => {
|
|
17
18
|
if (key.startsWith(BUILDER_SEARCHPARAMS_PREFIX)) {
|
|
18
|
-
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "");
|
|
19
|
+
const trimmedKey = key.replace(BUILDER_SEARCHPARAMS_PREFIX, "").replace(BUILDER_OPTIONS_PREFIX, "");
|
|
19
20
|
newOptions[trimmedKey] = options[key];
|
|
20
21
|
}
|
|
21
22
|
});
|
|
@@ -57,12 +57,13 @@ const generateContentUrl = (options) => {
|
|
|
57
57
|
noTraverse = false,
|
|
58
58
|
model,
|
|
59
59
|
apiKey,
|
|
60
|
-
includeRefs = true
|
|
60
|
+
includeRefs = true,
|
|
61
|
+
locale
|
|
61
62
|
} = options;
|
|
62
63
|
if (!apiKey) {
|
|
63
64
|
throw new Error("Missing API key");
|
|
64
65
|
}
|
|
65
|
-
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`);
|
|
66
|
+
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
|
|
66
67
|
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
67
68
|
const flattened = flatten(queryOptions);
|
|
68
69
|
for (const key in flattened) {
|
|
@@ -85,7 +86,7 @@ function getAllContent(options) {
|
|
|
85
86
|
const fetch = yield getFetch();
|
|
86
87
|
const content = yield fetch(url.href).then((res) => res.json());
|
|
87
88
|
const canTrack = options.canTrack !== false;
|
|
88
|
-
if (canTrack) {
|
|
89
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
89
90
|
for (const item of content.results) {
|
|
90
91
|
yield handleABTesting({ item, canTrack });
|
|
91
92
|
}
|
|
@@ -17,13 +17,14 @@ var __spreadValues = (a, b) => {
|
|
|
17
17
|
import { sanitizeReactNativeBlockStyles } from "./sanitize-react-native-block-styles.js";
|
|
18
18
|
function getReactNativeBlockStyles({
|
|
19
19
|
block,
|
|
20
|
-
context
|
|
20
|
+
context,
|
|
21
|
+
blockStyles
|
|
21
22
|
}) {
|
|
22
23
|
const responsiveStyles = block.responsiveStyles;
|
|
23
24
|
if (!responsiveStyles) {
|
|
24
25
|
return {};
|
|
25
26
|
}
|
|
26
|
-
const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {});
|
|
27
|
+
const styles = __spreadValues(__spreadValues(__spreadValues(__spreadValues(__spreadValues({}, context.inheritedStyles), responsiveStyles.large || {}), responsiveStyles.medium || {}), responsiveStyles.small || {}), blockStyles);
|
|
27
28
|
const newStyles = sanitizeReactNativeBlockStyles(styles);
|
|
28
29
|
return newStyles;
|
|
29
30
|
}
|
package/src/functions/track.js
CHANGED
|
@@ -90,6 +90,10 @@ const createEvent = (_a) => __async(void 0, null, function* () {
|
|
|
90
90
|
});
|
|
91
91
|
function _track(eventProps) {
|
|
92
92
|
return __async(this, null, function* () {
|
|
93
|
+
if (!eventProps.apiKey) {
|
|
94
|
+
console.error("[Builder.io]: Missing API key for track call. Please provide your API key.");
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
93
97
|
if (!eventProps.canTrack) {
|
|
94
98
|
return;
|
|
95
99
|
}
|
package/src/helpers/css.js
CHANGED
|
@@ -1,19 +1,23 @@
|
|
|
1
1
|
import { camelToKebabCase } from "../functions/camel-to-kebab-case.js";
|
|
2
|
-
|
|
2
|
+
import { checkIsDefined } from "./nullable.js";
|
|
3
|
+
const convertStyleMapToCSSArray = (style) => {
|
|
3
4
|
const cssProps = Object.entries(style).map(([key, value]) => {
|
|
4
5
|
if (typeof value === "string") {
|
|
5
6
|
return `${camelToKebabCase(key)}: ${value};`;
|
|
7
|
+
} else {
|
|
8
|
+
return void 0;
|
|
6
9
|
}
|
|
7
10
|
});
|
|
8
|
-
return cssProps.
|
|
11
|
+
return cssProps.filter(checkIsDefined);
|
|
9
12
|
};
|
|
13
|
+
const convertStyleMapToCSS = (style) => convertStyleMapToCSSArray(style).join("\n");
|
|
10
14
|
const createCssClass = ({
|
|
11
15
|
mediaQuery,
|
|
12
16
|
className,
|
|
13
17
|
styles
|
|
14
18
|
}) => {
|
|
15
19
|
const cssClass = `.${className} {
|
|
16
|
-
${
|
|
20
|
+
${convertStyleMapToCSS(styles)}
|
|
17
21
|
}`;
|
|
18
22
|
if (mediaQuery) {
|
|
19
23
|
return `${mediaQuery} {
|
|
@@ -24,5 +28,7 @@ const createCssClass = ({
|
|
|
24
28
|
}
|
|
25
29
|
};
|
|
26
30
|
export {
|
|
31
|
+
convertStyleMapToCSS,
|
|
32
|
+
convertStyleMapToCSSArray,
|
|
27
33
|
createCssClass
|
|
28
34
|
};
|
|
@@ -20,8 +20,8 @@ const registerInsertMenu = () => {
|
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
22
|
let isSetupForEditing = false;
|
|
23
|
-
const setupBrowserForEditing = () => {
|
|
24
|
-
var _a;
|
|
23
|
+
const setupBrowserForEditing = (options = {}) => {
|
|
24
|
+
var _a, _b;
|
|
25
25
|
if (isSetupForEditing) {
|
|
26
26
|
return;
|
|
27
27
|
}
|
|
@@ -36,8 +36,14 @@ const setupBrowserForEditing = () => {
|
|
|
36
36
|
supportsCustomBreakpoints: true
|
|
37
37
|
}
|
|
38
38
|
}, "*");
|
|
39
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
40
|
+
type: "builder.updateContent",
|
|
41
|
+
data: {
|
|
42
|
+
options
|
|
43
|
+
}
|
|
44
|
+
}, "*");
|
|
39
45
|
window.addEventListener("message", ({ data }) => {
|
|
40
|
-
var _a2,
|
|
46
|
+
var _a2, _b2;
|
|
41
47
|
if (!(data == null ? void 0 : data.type)) {
|
|
42
48
|
return;
|
|
43
49
|
}
|
|
@@ -69,7 +75,7 @@ const setupBrowserForEditing = () => {
|
|
|
69
75
|
}, "*");
|
|
70
76
|
}).catch(console.error);
|
|
71
77
|
} else {
|
|
72
|
-
(
|
|
78
|
+
(_b2 = window.parent) == null ? void 0 : _b2.postMessage({
|
|
73
79
|
type: "builder.evaluateResult",
|
|
74
80
|
data: { result, id }
|
|
75
81
|
}, "*");
|