@builder.io/sdk-solid 0.0.20 → 0.0.21
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 +1 -1
- package/src/blocks/BaseText.jsx +0 -2
- package/src/blocks/button/button.jsx +1 -3
- package/src/blocks/columns/columns.jsx +1 -13
- package/src/blocks/columns/component-info.js +2 -2
- package/src/blocks/custom-code/custom-code.jsx +0 -8
- package/src/blocks/embed/component-info.js +2 -2
- package/src/blocks/embed/embed.jsx +0 -8
- package/src/blocks/form/form.jsx +9 -43
- package/src/blocks/fragment/fragment.jsx +0 -1
- package/src/blocks/image/component-info.js +2 -2
- package/src/blocks/image/image.jsx +4 -9
- package/src/blocks/img/img.jsx +2 -4
- package/src/blocks/input/input.jsx +0 -2
- package/src/blocks/raw-text/raw-text.jsx +0 -1
- package/src/blocks/section/section.jsx +0 -1
- package/src/blocks/select/select.jsx +0 -3
- package/src/blocks/submit-button/submit-button.jsx +1 -2
- package/src/blocks/symbol/symbol.jsx +4 -10
- package/src/blocks/text/text.jsx +0 -1
- package/src/blocks/textarea/textarea.jsx +0 -1
- package/src/blocks/util.js +6 -5
- package/src/blocks/video/video.jsx +4 -5
- package/src/components/render-block/block-styles.jsx +5 -7
- package/src/components/render-block/render-block.jsx +17 -39
- package/src/components/render-block/render-component-with-context.jsx +0 -8
- package/src/components/render-block/render-component.jsx +1 -6
- package/src/components/render-block/render-repeated-block.jsx +0 -8
- package/src/components/render-blocks.jsx +0 -7
- package/src/components/render-content/builder-editing.jsx +4 -0
- package/src/components/render-content/components/render-styles.jsx +2 -13
- package/src/components/render-content/render-content.jsx +16 -51
- package/src/components/render-inlined-styles.jsx +3 -7
- package/src/constants/device-sizes.js +29 -2
- package/src/functions/get-content/index.js +6 -2
- package/src/functions/register-component.js +1 -5
- package/src/index.js +1 -1
- package/src/scripts/init-editing.js +7 -1
|
@@ -15,47 +15,42 @@ import { _track } from "../../functions/track.js";
|
|
|
15
15
|
import RenderBlocks from "../render-blocks.jsx";
|
|
16
16
|
import RenderContentStyles from "./components/render-styles.jsx";
|
|
17
17
|
import { registerInsertMenu, setupBrowserForEditing } from "../../scripts/init-editing.js";
|
|
18
|
-
import { markMutable } from "../../functions/mark-mutable.js";
|
|
19
|
-
|
|
20
18
|
function RenderContent(props) {
|
|
21
19
|
const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
|
|
22
20
|
const [overrideContent, setOverrideContent] = createSignal(null);
|
|
23
21
|
const [update, setUpdate] = createSignal(0);
|
|
24
22
|
const [overrideState, setOverrideState] = createSignal({});
|
|
25
|
-
|
|
26
23
|
function canTrackToUse() {
|
|
27
24
|
return props.canTrack || true;
|
|
28
25
|
}
|
|
29
|
-
|
|
30
26
|
function contentState() {
|
|
31
|
-
return {
|
|
27
|
+
return {
|
|
28
|
+
...props.content?.data?.state,
|
|
32
29
|
...props.data,
|
|
33
30
|
...overrideState()
|
|
34
31
|
};
|
|
35
32
|
}
|
|
36
|
-
|
|
37
33
|
function contextContext() {
|
|
38
34
|
return props.context || {};
|
|
39
35
|
}
|
|
40
|
-
|
|
41
36
|
function allRegisteredComponents() {
|
|
42
|
-
const allComponentsArray = [...getDefaultRegisteredComponents(),
|
|
37
|
+
const allComponentsArray = [...getDefaultRegisteredComponents(),
|
|
38
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
43
39
|
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
44
40
|
// existing usage.
|
|
45
41
|
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
46
42
|
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
47
43
|
...components, ...(props.customComponents || [])];
|
|
48
|
-
const allComponents = allComponentsArray.reduce((acc, curr) => ({
|
|
44
|
+
const allComponents = allComponentsArray.reduce((acc, curr) => ({
|
|
45
|
+
...acc,
|
|
49
46
|
[curr.name]: curr
|
|
50
47
|
}), {});
|
|
51
48
|
return allComponents;
|
|
52
49
|
}
|
|
53
|
-
|
|
54
50
|
function processMessage(event) {
|
|
55
51
|
const {
|
|
56
52
|
data
|
|
57
53
|
} = event;
|
|
58
|
-
|
|
59
54
|
if (data) {
|
|
60
55
|
switch (data.type) {
|
|
61
56
|
case "builder.contentUpdate":
|
|
@@ -63,7 +58,6 @@ function RenderContent(props) {
|
|
|
63
58
|
const messageContent = data.data;
|
|
64
59
|
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
65
60
|
const contentData = messageContent.data;
|
|
66
|
-
|
|
67
61
|
if (key === props.model) {
|
|
68
62
|
setOverrideContent(contentData);
|
|
69
63
|
setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
|
|
@@ -71,7 +65,6 @@ function RenderContent(props) {
|
|
|
71
65
|
|
|
72
66
|
break;
|
|
73
67
|
}
|
|
74
|
-
|
|
75
68
|
case "builder.patchUpdates":
|
|
76
69
|
{
|
|
77
70
|
// TODO
|
|
@@ -80,11 +73,9 @@ function RenderContent(props) {
|
|
|
80
73
|
}
|
|
81
74
|
}
|
|
82
75
|
}
|
|
83
|
-
|
|
84
76
|
function evaluateJsCode() {
|
|
85
77
|
// run any dynamic JS code attached to content
|
|
86
78
|
const jsCode = useContent?.data?.jsCode;
|
|
87
|
-
|
|
88
79
|
if (jsCode) {
|
|
89
80
|
evaluate({
|
|
90
81
|
code: jsCode,
|
|
@@ -93,16 +84,13 @@ function RenderContent(props) {
|
|
|
93
84
|
});
|
|
94
85
|
}
|
|
95
86
|
}
|
|
96
|
-
|
|
97
87
|
function httpReqsData() {
|
|
98
88
|
return {};
|
|
99
89
|
}
|
|
100
|
-
|
|
101
90
|
function onClick(_event) {
|
|
102
91
|
if (useContent) {
|
|
103
92
|
const variationId = useContent?.testVariationId;
|
|
104
93
|
const contentId = useContent?.id;
|
|
105
|
-
|
|
106
94
|
_track({
|
|
107
95
|
type: "click",
|
|
108
96
|
canTrack: canTrackToUse(),
|
|
@@ -112,7 +100,6 @@ function RenderContent(props) {
|
|
|
112
100
|
});
|
|
113
101
|
}
|
|
114
102
|
}
|
|
115
|
-
|
|
116
103
|
function evalExpression(expression) {
|
|
117
104
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
118
105
|
code: group,
|
|
@@ -120,13 +107,13 @@ function RenderContent(props) {
|
|
|
120
107
|
state: contentState()
|
|
121
108
|
}));
|
|
122
109
|
}
|
|
123
|
-
|
|
124
110
|
function handleRequest({
|
|
125
111
|
url,
|
|
126
112
|
key
|
|
127
113
|
}) {
|
|
128
114
|
getFetch().then(fetch => fetch(url)).then(response => response.json()).then(json => {
|
|
129
|
-
const newOverrideState = {
|
|
115
|
+
const newOverrideState = {
|
|
116
|
+
...overrideState(),
|
|
130
117
|
[key]: json
|
|
131
118
|
};
|
|
132
119
|
setOverrideState(newOverrideState);
|
|
@@ -134,7 +121,6 @@ function RenderContent(props) {
|
|
|
134
121
|
console.log("error fetching dynamic data", url, err);
|
|
135
122
|
});
|
|
136
123
|
}
|
|
137
|
-
|
|
138
124
|
function runHttpRequests() {
|
|
139
125
|
const requests = useContent?.data?.httpRequests ?? {};
|
|
140
126
|
Object.entries(requests).forEach(([key, url]) => {
|
|
@@ -147,7 +133,6 @@ function RenderContent(props) {
|
|
|
147
133
|
}
|
|
148
134
|
});
|
|
149
135
|
}
|
|
150
|
-
|
|
151
136
|
function emitStateUpdate() {
|
|
152
137
|
if (isEditing()) {
|
|
153
138
|
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
@@ -160,34 +145,31 @@ function RenderContent(props) {
|
|
|
160
145
|
}));
|
|
161
146
|
}
|
|
162
147
|
}
|
|
163
|
-
|
|
164
148
|
function shouldRenderContentStyles() {
|
|
165
149
|
return Boolean((useContent?.data?.cssCode || useContent?.data?.customFonts?.length) && TARGET !== "reactNative");
|
|
166
150
|
}
|
|
167
|
-
|
|
168
151
|
const updateUseContent = function useContent() {
|
|
169
152
|
if (!props.content && !overrideContent()) {
|
|
170
153
|
return undefined;
|
|
171
154
|
}
|
|
172
|
-
|
|
173
|
-
|
|
155
|
+
const mergedContent = {
|
|
156
|
+
...props.content,
|
|
174
157
|
...overrideContent(),
|
|
175
|
-
data: {
|
|
158
|
+
data: {
|
|
159
|
+
...props.content?.data,
|
|
176
160
|
...props.data,
|
|
177
161
|
...overrideContent()?.data
|
|
178
162
|
}
|
|
179
163
|
};
|
|
180
164
|
return mergedContent;
|
|
181
165
|
};
|
|
182
|
-
|
|
183
166
|
const [useContent, setUseContent] = createStore(updateUseContent());
|
|
184
167
|
createEffect(on(() => [overrideContent(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
|
|
185
168
|
let elementRef;
|
|
186
169
|
onMount(() => {
|
|
187
170
|
if (isBrowser()) {
|
|
188
171
|
if (isEditing()) {
|
|
189
|
-
setForceReRenderCount(forceReRenderCount() + 1);
|
|
190
|
-
|
|
172
|
+
setForceReRenderCount(forceReRenderCount() + 1);
|
|
191
173
|
registerInsertMenu();
|
|
192
174
|
setupBrowserForEditing();
|
|
193
175
|
Object.values(allRegisteredComponents()).forEach(registeredComponent => {
|
|
@@ -197,11 +179,9 @@ function RenderContent(props) {
|
|
|
197
179
|
window.addEventListener("message", processMessage);
|
|
198
180
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
199
181
|
}
|
|
200
|
-
|
|
201
182
|
if (useContent) {
|
|
202
183
|
const variationId = useContent?.testVariationId;
|
|
203
184
|
const contentId = useContent?.id;
|
|
204
|
-
|
|
205
185
|
_track({
|
|
206
186
|
type: "impression",
|
|
207
187
|
canTrack: canTrackToUse(),
|
|
@@ -209,15 +189,13 @@ function RenderContent(props) {
|
|
|
209
189
|
apiKey: props.apiKey,
|
|
210
190
|
variationId: variationId !== contentId ? variationId : undefined
|
|
211
191
|
});
|
|
212
|
-
}
|
|
213
|
-
|
|
192
|
+
}
|
|
214
193
|
|
|
194
|
+
// override normal content in preview mode
|
|
215
195
|
if (isPreviewing()) {
|
|
216
196
|
const searchParams = new URL(location.href).searchParams;
|
|
217
|
-
|
|
218
197
|
if (props.model && searchParams.get("builder.preview") === props.model) {
|
|
219
198
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
220
|
-
|
|
221
199
|
if (previewApiKey) {
|
|
222
200
|
getContent({
|
|
223
201
|
model: props.model,
|
|
@@ -230,61 +208,48 @@ function RenderContent(props) {
|
|
|
230
208
|
}
|
|
231
209
|
}
|
|
232
210
|
}
|
|
233
|
-
|
|
234
211
|
evaluateJsCode();
|
|
235
212
|
runHttpRequests();
|
|
236
213
|
emitStateUpdate();
|
|
237
214
|
}
|
|
238
215
|
});
|
|
239
|
-
|
|
240
216
|
function onUpdateFn_0() {
|
|
241
217
|
evaluateJsCode();
|
|
242
218
|
}
|
|
243
|
-
|
|
244
219
|
createEffect(on(() => [useContent?.data?.jsCode], onUpdateFn_0));
|
|
245
|
-
|
|
246
220
|
function onUpdateFn_1() {
|
|
247
221
|
runHttpRequests();
|
|
248
222
|
}
|
|
249
|
-
|
|
250
223
|
createEffect(on(() => [useContent?.data?.httpRequests], onUpdateFn_1));
|
|
251
|
-
|
|
252
224
|
function onUpdateFn_2() {
|
|
253
225
|
emitStateUpdate();
|
|
254
226
|
}
|
|
255
|
-
|
|
256
227
|
createEffect(on(() => [contentState()], onUpdateFn_2));
|
|
257
228
|
return <Dynamic value={{
|
|
258
229
|
get content() {
|
|
259
230
|
return useContent;
|
|
260
231
|
},
|
|
261
|
-
|
|
262
232
|
get state() {
|
|
263
233
|
return contentState();
|
|
264
234
|
},
|
|
265
|
-
|
|
266
235
|
get context() {
|
|
267
236
|
return contextContext();
|
|
268
237
|
},
|
|
269
|
-
|
|
270
238
|
get apiKey() {
|
|
271
239
|
return props.apiKey;
|
|
272
240
|
},
|
|
273
|
-
|
|
274
241
|
get registeredComponents() {
|
|
275
242
|
return allRegisteredComponents();
|
|
276
243
|
}
|
|
277
|
-
|
|
278
244
|
}} component={BuilderContext.Provider}>
|
|
279
245
|
<Show when={useContent}>
|
|
280
246
|
<div ref={elementRef} onClick={event => onClick(event)} builder-content-id={useContent?.id} builder-model={props.model}>
|
|
281
247
|
<Show when={shouldRenderContentStyles()}>
|
|
282
248
|
<RenderContentStyles cssCode={useContent?.data?.cssCode} customFonts={useContent?.data?.customFonts}></RenderContentStyles>
|
|
283
249
|
</Show>
|
|
284
|
-
<RenderBlocks blocks={
|
|
250
|
+
<RenderBlocks blocks={useContent?.data?.blocks} key={forceReRenderCount()}></RenderBlocks>
|
|
285
251
|
</div>
|
|
286
252
|
</Show>
|
|
287
253
|
</Dynamic>;
|
|
288
254
|
}
|
|
289
|
-
|
|
290
255
|
export default RenderContent;
|
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
import { Show } from "solid-js";
|
|
2
2
|
import { Dynamic } from "solid-js/web";
|
|
3
3
|
import { TARGET } from "../constants/target.js";
|
|
4
|
-
|
|
5
4
|
function RenderInlinedStyles(props) {
|
|
6
5
|
function injectedStyleScript() {
|
|
7
|
-
return `<${
|
|
6
|
+
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
8
7
|
}
|
|
9
|
-
|
|
10
|
-
function tagName() {
|
|
8
|
+
function tag() {
|
|
11
9
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
12
10
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
13
11
|
return "sty" + "le";
|
|
14
12
|
}
|
|
15
|
-
|
|
16
|
-
return <Show fallback={<Dynamic component={tagName()}>{props.styles}</Dynamic>} when={TARGET === "svelte"}>
|
|
13
|
+
return <Show fallback={<Dynamic component={tag()}>{props.styles}</Dynamic>} when={TARGET === "svelte"}>
|
|
17
14
|
<div innerHTML={injectedStyleScript()}></div>
|
|
18
15
|
</Show>;
|
|
19
16
|
}
|
|
20
|
-
|
|
21
17
|
export default RenderInlinedStyles;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { fastClone } from "../functions/fast-clone";
|
|
1
2
|
const SIZES = {
|
|
2
3
|
small: {
|
|
3
4
|
min: 320,
|
|
@@ -15,7 +16,33 @@ const SIZES = {
|
|
|
15
16
|
max: 1200
|
|
16
17
|
}
|
|
17
18
|
};
|
|
18
|
-
const getMaxWidthQueryForSize = (size) => `@media (max-width: ${
|
|
19
|
+
const getMaxWidthQueryForSize = (size, sizeValues = SIZES) => `@media (max-width: ${sizeValues[size].max}px)`;
|
|
20
|
+
const getSizesForBreakpoints = ({ small, medium }) => {
|
|
21
|
+
const newSizes = fastClone(SIZES);
|
|
22
|
+
if (!small || !medium) {
|
|
23
|
+
return newSizes;
|
|
24
|
+
}
|
|
25
|
+
const smallMin = Math.floor(small / 2);
|
|
26
|
+
newSizes.small = {
|
|
27
|
+
max: small,
|
|
28
|
+
min: smallMin,
|
|
29
|
+
default: smallMin + 1
|
|
30
|
+
};
|
|
31
|
+
const mediumMin = newSizes.small.max + 1;
|
|
32
|
+
newSizes.medium = {
|
|
33
|
+
max: medium,
|
|
34
|
+
min: mediumMin,
|
|
35
|
+
default: mediumMin + 1
|
|
36
|
+
};
|
|
37
|
+
const largeMin = newSizes.medium.max + 1;
|
|
38
|
+
newSizes.large = {
|
|
39
|
+
max: 2e3,
|
|
40
|
+
min: largeMin,
|
|
41
|
+
default: largeMin + 1
|
|
42
|
+
};
|
|
43
|
+
return newSizes;
|
|
44
|
+
};
|
|
19
45
|
export {
|
|
20
|
-
getMaxWidthQueryForSize
|
|
46
|
+
getMaxWidthQueryForSize,
|
|
47
|
+
getSizesForBreakpoints
|
|
21
48
|
};
|
|
@@ -56,9 +56,13 @@ const generateContentUrl = (options) => {
|
|
|
56
56
|
query,
|
|
57
57
|
noTraverse = false,
|
|
58
58
|
model,
|
|
59
|
-
apiKey
|
|
59
|
+
apiKey,
|
|
60
|
+
includeRefs = true
|
|
60
61
|
} = options;
|
|
61
|
-
|
|
62
|
+
if (!apiKey) {
|
|
63
|
+
throw new Error("Missing API key");
|
|
64
|
+
}
|
|
65
|
+
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}`);
|
|
62
66
|
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
63
67
|
const flattened = flatten(queryOptions);
|
|
64
68
|
for (const key in flattened) {
|
|
@@ -29,6 +29,7 @@ var __objRest = (source, exclude) => {
|
|
|
29
29
|
}
|
|
30
30
|
return target;
|
|
31
31
|
};
|
|
32
|
+
import { serializeFn } from "../blocks/util.js";
|
|
32
33
|
import { fastClone } from "./fast-clone.js";
|
|
33
34
|
const components = [];
|
|
34
35
|
function registerComponent(component, info) {
|
|
@@ -48,11 +49,6 @@ const createRegisterComponentMessage = (_a) => {
|
|
|
48
49
|
};
|
|
49
50
|
};
|
|
50
51
|
const serializeValue = (value) => typeof value === "function" ? serializeFn(value) : fastClone(value);
|
|
51
|
-
const serializeFn = (fnValue) => {
|
|
52
|
-
const fnStr = fnValue.toString().trim();
|
|
53
|
-
const appendFunction = !fnStr.startsWith("function") && !fnStr.startsWith("(");
|
|
54
|
-
return `return (${appendFunction ? "function " : ""}${fnStr}).apply(this, arguments)`;
|
|
55
|
-
};
|
|
56
52
|
const prepareComponentInfoToSend = (_c) => {
|
|
57
53
|
var _d = _c, {
|
|
58
54
|
inputs
|
package/src/index.js
CHANGED
|
@@ -19,15 +19,21 @@ const registerInsertMenu = () => {
|
|
|
19
19
|
]
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
+
let isSetupForEditing = false;
|
|
22
23
|
const setupBrowserForEditing = () => {
|
|
23
24
|
var _a;
|
|
25
|
+
if (isSetupForEditing) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
isSetupForEditing = true;
|
|
24
29
|
if (isBrowser()) {
|
|
25
30
|
(_a = window.parent) == null ? void 0 : _a.postMessage({
|
|
26
31
|
type: "builder.sdkInfo",
|
|
27
32
|
data: {
|
|
28
33
|
target: TARGET,
|
|
29
34
|
supportsPatchUpdates: false,
|
|
30
|
-
supportsAddBlockScoping: true
|
|
35
|
+
supportsAddBlockScoping: true,
|
|
36
|
+
supportsCustomBreakpoints: true
|
|
31
37
|
}
|
|
32
38
|
}, "*");
|
|
33
39
|
window.addEventListener("message", ({ data }) => {
|