@builder.io/sdk-solid 0.0.20 → 0.0.22
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/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 +19 -17
- 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 +28 -45
- 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 +32 -54
- package/src/components/render-inlined-styles.jsx +3 -7
- package/src/constants/device-sizes.js +29 -2
- 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-builder-search-params/index.js +2 -1
- package/src/functions/get-content/index.js +8 -3
- package/src/functions/register-component.js +1 -5
- package/src/functions/track.js +4 -0
- package/src/index.js +1 -1
- package/src/scripts/init-editing.js +17 -5
- package/src/functions/mark-mutable.js +0 -10
|
@@ -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,48 +13,47 @@ 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
|
-
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,
|
|
30
|
+
...(props.locale ? {
|
|
31
|
+
locale: props.locale
|
|
32
|
+
} : {}),
|
|
33
33
|
...overrideState()
|
|
34
34
|
};
|
|
35
35
|
}
|
|
36
|
-
|
|
37
36
|
function contextContext() {
|
|
38
37
|
return props.context || {};
|
|
39
38
|
}
|
|
40
|
-
|
|
41
39
|
function allRegisteredComponents() {
|
|
42
|
-
const allComponentsArray = [...getDefaultRegisteredComponents(),
|
|
40
|
+
const allComponentsArray = [...getDefaultRegisteredComponents(),
|
|
41
|
+
// While this `components` object is deprecated, we must maintain support for it.
|
|
43
42
|
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
44
43
|
// existing usage.
|
|
45
44
|
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
46
45
|
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
47
46
|
...components, ...(props.customComponents || [])];
|
|
48
|
-
const allComponents = allComponentsArray.reduce((acc, curr) => ({
|
|
47
|
+
const allComponents = allComponentsArray.reduce((acc, curr) => ({
|
|
48
|
+
...acc,
|
|
49
49
|
[curr.name]: curr
|
|
50
50
|
}), {});
|
|
51
51
|
return allComponents;
|
|
52
52
|
}
|
|
53
|
-
|
|
54
53
|
function processMessage(event) {
|
|
55
54
|
const {
|
|
56
55
|
data
|
|
57
56
|
} = event;
|
|
58
|
-
|
|
59
57
|
if (data) {
|
|
60
58
|
switch (data.type) {
|
|
61
59
|
case "builder.contentUpdate":
|
|
@@ -63,7 +61,6 @@ function RenderContent(props) {
|
|
|
63
61
|
const messageContent = data.data;
|
|
64
62
|
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
65
63
|
const contentData = messageContent.data;
|
|
66
|
-
|
|
67
64
|
if (key === props.model) {
|
|
68
65
|
setOverrideContent(contentData);
|
|
69
66
|
setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
|
|
@@ -71,7 +68,6 @@ function RenderContent(props) {
|
|
|
71
68
|
|
|
72
69
|
break;
|
|
73
70
|
}
|
|
74
|
-
|
|
75
71
|
case "builder.patchUpdates":
|
|
76
72
|
{
|
|
77
73
|
// TODO
|
|
@@ -80,11 +76,9 @@ function RenderContent(props) {
|
|
|
80
76
|
}
|
|
81
77
|
}
|
|
82
78
|
}
|
|
83
|
-
|
|
84
79
|
function evaluateJsCode() {
|
|
85
80
|
// run any dynamic JS code attached to content
|
|
86
81
|
const jsCode = useContent?.data?.jsCode;
|
|
87
|
-
|
|
88
82
|
if (jsCode) {
|
|
89
83
|
evaluate({
|
|
90
84
|
code: jsCode,
|
|
@@ -93,16 +87,13 @@ function RenderContent(props) {
|
|
|
93
87
|
});
|
|
94
88
|
}
|
|
95
89
|
}
|
|
96
|
-
|
|
97
90
|
function httpReqsData() {
|
|
98
91
|
return {};
|
|
99
92
|
}
|
|
100
|
-
|
|
101
93
|
function onClick(_event) {
|
|
102
94
|
if (useContent) {
|
|
103
95
|
const variationId = useContent?.testVariationId;
|
|
104
96
|
const contentId = useContent?.id;
|
|
105
|
-
|
|
106
97
|
_track({
|
|
107
98
|
type: "click",
|
|
108
99
|
canTrack: canTrackToUse(),
|
|
@@ -112,7 +103,6 @@ function RenderContent(props) {
|
|
|
112
103
|
});
|
|
113
104
|
}
|
|
114
105
|
}
|
|
115
|
-
|
|
116
106
|
function evalExpression(expression) {
|
|
117
107
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
118
108
|
code: group,
|
|
@@ -120,13 +110,13 @@ function RenderContent(props) {
|
|
|
120
110
|
state: contentState()
|
|
121
111
|
}));
|
|
122
112
|
}
|
|
123
|
-
|
|
124
113
|
function handleRequest({
|
|
125
114
|
url,
|
|
126
115
|
key
|
|
127
116
|
}) {
|
|
128
117
|
getFetch().then(fetch => fetch(url)).then(response => response.json()).then(json => {
|
|
129
|
-
const newOverrideState = {
|
|
118
|
+
const newOverrideState = {
|
|
119
|
+
...overrideState(),
|
|
130
120
|
[key]: json
|
|
131
121
|
};
|
|
132
122
|
setOverrideState(newOverrideState);
|
|
@@ -134,7 +124,6 @@ function RenderContent(props) {
|
|
|
134
124
|
console.log("error fetching dynamic data", url, err);
|
|
135
125
|
});
|
|
136
126
|
}
|
|
137
|
-
|
|
138
127
|
function runHttpRequests() {
|
|
139
128
|
const requests = useContent?.data?.httpRequests ?? {};
|
|
140
129
|
Object.entries(requests).forEach(([key, url]) => {
|
|
@@ -147,7 +136,6 @@ function RenderContent(props) {
|
|
|
147
136
|
}
|
|
148
137
|
});
|
|
149
138
|
}
|
|
150
|
-
|
|
151
139
|
function emitStateUpdate() {
|
|
152
140
|
if (isEditing()) {
|
|
153
141
|
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
@@ -160,36 +148,43 @@ function RenderContent(props) {
|
|
|
160
148
|
}));
|
|
161
149
|
}
|
|
162
150
|
}
|
|
163
|
-
|
|
164
151
|
function shouldRenderContentStyles() {
|
|
165
152
|
return Boolean((useContent?.data?.cssCode || useContent?.data?.customFonts?.length) && TARGET !== "reactNative");
|
|
166
153
|
}
|
|
167
|
-
|
|
168
154
|
const updateUseContent = function useContent() {
|
|
169
155
|
if (!props.content && !overrideContent()) {
|
|
170
156
|
return undefined;
|
|
171
157
|
}
|
|
172
|
-
|
|
173
|
-
|
|
158
|
+
const mergedContent = {
|
|
159
|
+
...props.content,
|
|
174
160
|
...overrideContent(),
|
|
175
|
-
data: {
|
|
161
|
+
data: {
|
|
162
|
+
...props.content?.data,
|
|
176
163
|
...props.data,
|
|
177
164
|
...overrideContent()?.data
|
|
178
165
|
}
|
|
179
166
|
};
|
|
180
167
|
return mergedContent;
|
|
181
168
|
};
|
|
182
|
-
|
|
183
169
|
const [useContent, setUseContent] = createStore(updateUseContent());
|
|
184
170
|
createEffect(on(() => [overrideContent(), props.content, props.data], () => setUseContent(reconcile(updateUseContent()))));
|
|
185
171
|
let elementRef;
|
|
186
172
|
onMount(() => {
|
|
173
|
+
if (!props.apiKey) {
|
|
174
|
+
console.error("[Builder.io]: No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop.");
|
|
175
|
+
}
|
|
187
176
|
if (isBrowser()) {
|
|
188
177
|
if (isEditing()) {
|
|
189
|
-
setForceReRenderCount(forceReRenderCount() + 1);
|
|
190
|
-
|
|
178
|
+
setForceReRenderCount(forceReRenderCount() + 1);
|
|
191
179
|
registerInsertMenu();
|
|
192
|
-
setupBrowserForEditing(
|
|
180
|
+
setupBrowserForEditing({
|
|
181
|
+
...(props.locale ? {
|
|
182
|
+
locale: props.locale
|
|
183
|
+
} : {}),
|
|
184
|
+
...(props.includeRefs ? {
|
|
185
|
+
includeRefs: props.includeRefs
|
|
186
|
+
} : {})
|
|
187
|
+
});
|
|
193
188
|
Object.values(allRegisteredComponents()).forEach(registeredComponent => {
|
|
194
189
|
const message = createRegisterComponentMessage(registeredComponent);
|
|
195
190
|
window.parent?.postMessage(message, "*");
|
|
@@ -197,11 +192,9 @@ function RenderContent(props) {
|
|
|
197
192
|
window.addEventListener("message", processMessage);
|
|
198
193
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
199
194
|
}
|
|
200
|
-
|
|
201
195
|
if (useContent) {
|
|
202
196
|
const variationId = useContent?.testVariationId;
|
|
203
197
|
const contentId = useContent?.id;
|
|
204
|
-
|
|
205
198
|
_track({
|
|
206
199
|
type: "impression",
|
|
207
200
|
canTrack: canTrackToUse(),
|
|
@@ -209,15 +202,13 @@ function RenderContent(props) {
|
|
|
209
202
|
apiKey: props.apiKey,
|
|
210
203
|
variationId: variationId !== contentId ? variationId : undefined
|
|
211
204
|
});
|
|
212
|
-
}
|
|
213
|
-
|
|
205
|
+
}
|
|
214
206
|
|
|
207
|
+
// override normal content in preview mode
|
|
215
208
|
if (isPreviewing()) {
|
|
216
209
|
const searchParams = new URL(location.href).searchParams;
|
|
217
|
-
|
|
218
210
|
if (props.model && searchParams.get("builder.preview") === props.model) {
|
|
219
211
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
220
|
-
|
|
221
212
|
if (previewApiKey) {
|
|
222
213
|
getContent({
|
|
223
214
|
model: props.model,
|
|
@@ -230,61 +221,48 @@ function RenderContent(props) {
|
|
|
230
221
|
}
|
|
231
222
|
}
|
|
232
223
|
}
|
|
233
|
-
|
|
234
224
|
evaluateJsCode();
|
|
235
225
|
runHttpRequests();
|
|
236
226
|
emitStateUpdate();
|
|
237
227
|
}
|
|
238
228
|
});
|
|
239
|
-
|
|
240
229
|
function onUpdateFn_0() {
|
|
241
230
|
evaluateJsCode();
|
|
242
231
|
}
|
|
243
|
-
|
|
244
|
-
createEffect(on(() => [useContent?.data?.jsCode], onUpdateFn_0));
|
|
245
|
-
|
|
232
|
+
createEffect(on(() => [useContent?.data?.jsCode, contentState()], onUpdateFn_0));
|
|
246
233
|
function onUpdateFn_1() {
|
|
247
234
|
runHttpRequests();
|
|
248
235
|
}
|
|
249
|
-
|
|
250
236
|
createEffect(on(() => [useContent?.data?.httpRequests], onUpdateFn_1));
|
|
251
|
-
|
|
252
237
|
function onUpdateFn_2() {
|
|
253
238
|
emitStateUpdate();
|
|
254
239
|
}
|
|
255
|
-
|
|
256
240
|
createEffect(on(() => [contentState()], onUpdateFn_2));
|
|
257
241
|
return <Dynamic value={{
|
|
258
242
|
get content() {
|
|
259
243
|
return useContent;
|
|
260
244
|
},
|
|
261
|
-
|
|
262
245
|
get state() {
|
|
263
246
|
return contentState();
|
|
264
247
|
},
|
|
265
|
-
|
|
266
248
|
get context() {
|
|
267
249
|
return contextContext();
|
|
268
250
|
},
|
|
269
|
-
|
|
270
251
|
get apiKey() {
|
|
271
252
|
return props.apiKey;
|
|
272
253
|
},
|
|
273
|
-
|
|
274
254
|
get registeredComponents() {
|
|
275
255
|
return allRegisteredComponents();
|
|
276
256
|
}
|
|
277
|
-
|
|
278
257
|
}} component={BuilderContext.Provider}>
|
|
279
258
|
<Show when={useContent}>
|
|
280
259
|
<div ref={elementRef} onClick={event => onClick(event)} builder-content-id={useContent?.id} builder-model={props.model}>
|
|
281
260
|
<Show when={shouldRenderContentStyles()}>
|
|
282
261
|
<RenderContentStyles cssCode={useContent?.data?.cssCode} customFonts={useContent?.data?.customFonts}></RenderContentStyles>
|
|
283
262
|
</Show>
|
|
284
|
-
<RenderBlocks blocks={
|
|
263
|
+
<RenderBlocks blocks={useContent?.data?.blocks} key={forceReRenderCount()}></RenderBlocks>
|
|
285
264
|
</div>
|
|
286
265
|
</Show>
|
|
287
266
|
</Dynamic>;
|
|
288
267
|
}
|
|
289
|
-
|
|
290
268
|
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
|
};
|
|
@@ -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
|
}
|
|
@@ -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
|
});
|
|
@@ -56,9 +56,14 @@ const generateContentUrl = (options) => {
|
|
|
56
56
|
query,
|
|
57
57
|
noTraverse = false,
|
|
58
58
|
model,
|
|
59
|
-
apiKey
|
|
59
|
+
apiKey,
|
|
60
|
+
includeRefs = true,
|
|
61
|
+
locale
|
|
60
62
|
} = options;
|
|
61
|
-
|
|
63
|
+
if (!apiKey) {
|
|
64
|
+
throw new Error("Missing API key");
|
|
65
|
+
}
|
|
66
|
+
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}&includeRefs=${includeRefs}${locale ? `&locale=${locale}` : ""}`);
|
|
62
67
|
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
63
68
|
const flattened = flatten(queryOptions);
|
|
64
69
|
for (const key in flattened) {
|
|
@@ -81,7 +86,7 @@ function getAllContent(options) {
|
|
|
81
86
|
const fetch = yield getFetch();
|
|
82
87
|
const content = yield fetch(url.href).then((res) => res.json());
|
|
83
88
|
const canTrack = options.canTrack !== false;
|
|
84
|
-
if (canTrack) {
|
|
89
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
85
90
|
for (const item of content.results) {
|
|
86
91
|
yield handleABTesting({ item, canTrack });
|
|
87
92
|
}
|
|
@@ -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/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/index.js
CHANGED
|
@@ -19,19 +19,31 @@ const registerInsertMenu = () => {
|
|
|
19
19
|
]
|
|
20
20
|
});
|
|
21
21
|
};
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
let isSetupForEditing = false;
|
|
23
|
+
const setupBrowserForEditing = (options = {}) => {
|
|
24
|
+
var _a, _b;
|
|
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
|
|
37
|
+
}
|
|
38
|
+
}, "*");
|
|
39
|
+
(_b = window.parent) == null ? void 0 : _b.postMessage({
|
|
40
|
+
type: "builder.updateContent",
|
|
41
|
+
data: {
|
|
42
|
+
options
|
|
31
43
|
}
|
|
32
44
|
}, "*");
|
|
33
45
|
window.addEventListener("message", ({ data }) => {
|
|
34
|
-
var _a2,
|
|
46
|
+
var _a2, _b2;
|
|
35
47
|
if (!(data == null ? void 0 : data.type)) {
|
|
36
48
|
return;
|
|
37
49
|
}
|
|
@@ -63,7 +75,7 @@ const setupBrowserForEditing = () => {
|
|
|
63
75
|
}, "*");
|
|
64
76
|
}).catch(console.error);
|
|
65
77
|
} else {
|
|
66
|
-
(
|
|
78
|
+
(_b2 = window.parent) == null ? void 0 : _b2.postMessage({
|
|
67
79
|
type: "builder.evaluateResult",
|
|
68
80
|
data: { result, id }
|
|
69
81
|
}, "*");
|