@builder.io/sdk-qwik 0.0.8 → 0.0.9
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 +65 -2
- package/lib/index.qwik.cjs +104 -7
- package/lib/index.qwik.mjs +104 -7
- package/package.json +1 -1
- package/src/blocks/button/button.jsx +197 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/columns/columns.jsx +267 -0
- package/src/blocks/columns/component-info.js +242 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/custom-code/custom-code.jsx +130 -0
- package/src/blocks/embed/component-info.js +44 -0
- package/src/blocks/embed/embed.jsx +130 -0
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/builder-blocks.jsx +86 -0
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/form/form.jsx +782 -0
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.jsx +59 -0
- package/src/blocks/image/component-info.js +151 -0
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.jsx +554 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.jsx +76 -0
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/input.jsx +87 -0
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/raw-text.jsx +53 -0
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/section.jsx +97 -0
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/select.jsx +149 -0
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/submit-button.jsx +87 -0
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.jsx +211 -0
- package/src/blocks/text/component-info.js +24 -0
- package/src/blocks/text/text.jsx +46 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/textarea.jsx +65 -0
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/video.jsx +103 -0
- package/src/components/render-block/block-styles.jsx +174 -0
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.jsx +733 -0
- package/src/components/render-block/render-component.jsx +245 -0
- package/src/components/render-block/render-repeated-block.jsx +104 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +387 -0
- package/src/components/render-content/components/render-styles.jsx +126 -0
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.jsx +650 -0
- package/src/components/render-inlined-styles.jsx +141 -0
- package/src/constants/builder-registered-components.js +48 -0
- package/src/constants/device-sizes.js +21 -0
- package/src/constants/target.js +4 -0
- package/src/context/builder.context.js +5 -0
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/evaluate.js +28 -0
- package/src/functions/event-handler-name.js +7 -0
- package/src/functions/get-block-actions.js +23 -0
- package/src/functions/get-block-component-options.js +28 -0
- package/src/functions/get-block-properties.js +29 -0
- package/src/functions/get-block-styles.js +34 -0
- package/src/functions/get-block-tag.js +6 -0
- package/src/functions/get-builder-search-params/fn.test.js +13 -0
- package/src/functions/get-builder-search-params/index.js +33 -0
- package/src/functions/get-content/ab-testing.js +38 -0
- package/src/functions/get-content/fn.test.js +31 -0
- package/src/functions/get-content/index.js +96 -0
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +34 -0
- package/src/functions/get-global-this.js +18 -0
- package/src/functions/get-processed-block.js +53 -0
- package/src/functions/get-processed-block.test.js +32 -0
- package/src/functions/if-target.js +15 -0
- package/src/functions/is-browser.js +6 -0
- package/src/functions/is-editing.js +7 -0
- package/src/functions/is-iframe.js +7 -0
- package/src/functions/is-previewing.js +14 -0
- package/src/functions/on-change.js +27 -0
- package/src/functions/on-change.test.js +19 -0
- package/src/functions/register-component.js +72 -0
- package/src/functions/register.js +29 -0
- package/src/functions/sanitize-styles.js +5 -0
- package/src/functions/set-editor-settings.js +15 -0
- package/src/functions/set.js +11 -0
- package/src/functions/set.test.js +16 -0
- package/src/functions/track.js +22 -0
- package/src/functions/transform-block.js +6 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- package/src/index-helpers/blocks-exports.js +22 -0
- package/src/index-helpers/top-of-file.js +4 -0
- package/src/index.js +10 -0
- package/src/scripts/init-editing.js +79 -0
- package/src/types/builder-block.js +0 -0
- package/src/types/builder-content.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/deep-partial.js +0 -0
- package/src/types/element.js +0 -0
- package/src/types/targets.js +0 -0
- package/src/types/typescript.js +0 -0
- package/types.d.ts +7 -12
- package/root.json +0 -1176
|
@@ -0,0 +1,650 @@
|
|
|
1
|
+
// GENERATED BY MITOSIS
|
|
2
|
+
|
|
3
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
4
|
+
import { TARGET } from "../../constants/target.js";
|
|
5
|
+
import BuilderContext from "../../context/builder.context";
|
|
6
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
7
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
8
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
9
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
10
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
11
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
12
|
+
import {
|
|
13
|
+
components,
|
|
14
|
+
createRegisterComponentMessage,
|
|
15
|
+
} from "../../functions/register-component.js";
|
|
16
|
+
import { track } from "../../functions/track.js";
|
|
17
|
+
import {
|
|
18
|
+
registerInsertMenu,
|
|
19
|
+
setupBrowserForEditing,
|
|
20
|
+
} from "../../scripts/init-editing.js";
|
|
21
|
+
import RenderBlocks from "../render-blocks";
|
|
22
|
+
import RenderContentStyles from "./components/render-styles";
|
|
23
|
+
import {
|
|
24
|
+
Fragment,
|
|
25
|
+
_useMutableProps,
|
|
26
|
+
component$,
|
|
27
|
+
h,
|
|
28
|
+
useCleanup$,
|
|
29
|
+
useClientEffect$,
|
|
30
|
+
useContextProvider,
|
|
31
|
+
useHostElement,
|
|
32
|
+
useStore,
|
|
33
|
+
useWatch$,
|
|
34
|
+
} from "@builder.io/qwik";
|
|
35
|
+
export const useContent = function useContent(props, state) {
|
|
36
|
+
const mergedContent = {
|
|
37
|
+
...props.content,
|
|
38
|
+
...state.overrideContent,
|
|
39
|
+
data: {
|
|
40
|
+
...props.content?.data,
|
|
41
|
+
...props.data,
|
|
42
|
+
...state.overrideContent?.data,
|
|
43
|
+
},
|
|
44
|
+
};
|
|
45
|
+
return mergedContent;
|
|
46
|
+
};
|
|
47
|
+
export const contentState = function contentState(props, state) {
|
|
48
|
+
return {
|
|
49
|
+
...props.content?.data?.state,
|
|
50
|
+
...props.data,
|
|
51
|
+
...state.overrideState,
|
|
52
|
+
};
|
|
53
|
+
};
|
|
54
|
+
export const contextContext = function contextContext(props, state) {
|
|
55
|
+
return props.context || {};
|
|
56
|
+
};
|
|
57
|
+
export const allRegisteredComponents = function allRegisteredComponents(
|
|
58
|
+
props,
|
|
59
|
+
state
|
|
60
|
+
) {
|
|
61
|
+
const allComponentsArray = [
|
|
62
|
+
...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
63
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
64
|
+
// existing usage.
|
|
65
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
66
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
67
|
+
...components,
|
|
68
|
+
...(props.customComponents || []),
|
|
69
|
+
];
|
|
70
|
+
const allComponents = allComponentsArray.reduce(
|
|
71
|
+
(acc, curr) => ({ ...acc, [curr.name]: curr }),
|
|
72
|
+
{}
|
|
73
|
+
);
|
|
74
|
+
return allComponents;
|
|
75
|
+
};
|
|
76
|
+
export const processMessage = function processMessage(props, state, event) {
|
|
77
|
+
const { data } = event;
|
|
78
|
+
|
|
79
|
+
if (data) {
|
|
80
|
+
switch (data.type) {
|
|
81
|
+
case "builder.contentUpdate": {
|
|
82
|
+
const messageContent = data.data;
|
|
83
|
+
const key =
|
|
84
|
+
messageContent.key ||
|
|
85
|
+
messageContent.alias ||
|
|
86
|
+
messageContent.entry ||
|
|
87
|
+
messageContent.modelName;
|
|
88
|
+
const contentData = messageContent.data;
|
|
89
|
+
|
|
90
|
+
if (key === props.model) {
|
|
91
|
+
state.overrideContent = contentData;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
break;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
case "builder.patchUpdates": {
|
|
98
|
+
// TODO
|
|
99
|
+
break;
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
};
|
|
104
|
+
export const evaluateJsCode = function evaluateJsCode(props, state) {
|
|
105
|
+
// run any dynamic JS code attached to content
|
|
106
|
+
const jsCode = useContent(props, state)?.data?.jsCode;
|
|
107
|
+
|
|
108
|
+
if (jsCode) {
|
|
109
|
+
evaluate({
|
|
110
|
+
code: jsCode,
|
|
111
|
+
context: contextContext(props, state),
|
|
112
|
+
state: contentState(props, state),
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
export const httpReqsData = function httpReqsData(props, state) {
|
|
117
|
+
return {};
|
|
118
|
+
};
|
|
119
|
+
export const onClick = function onClick(props, state, _event) {
|
|
120
|
+
if (useContent(props, state) && props.canTrack !== false) {
|
|
121
|
+
track("click", {
|
|
122
|
+
contentId: useContent(props, state).id,
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
};
|
|
126
|
+
export const evalExpression = function evalExpression(
|
|
127
|
+
props,
|
|
128
|
+
state,
|
|
129
|
+
expression
|
|
130
|
+
) {
|
|
131
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
132
|
+
evaluate({
|
|
133
|
+
code: group,
|
|
134
|
+
context: contextContext(props, state),
|
|
135
|
+
state: contentState(props, state),
|
|
136
|
+
})
|
|
137
|
+
);
|
|
138
|
+
};
|
|
139
|
+
export const handleRequest = function handleRequest(
|
|
140
|
+
props,
|
|
141
|
+
state,
|
|
142
|
+
{ url, key }
|
|
143
|
+
) {
|
|
144
|
+
const fetchAndSetState = async () => {
|
|
145
|
+
const fetch = await getFetch();
|
|
146
|
+
const response = await fetch(url);
|
|
147
|
+
const json = await response.json();
|
|
148
|
+
const newOverrideState = { ...state.overrideState, [key]: json };
|
|
149
|
+
state.overrideState = newOverrideState;
|
|
150
|
+
};
|
|
151
|
+
|
|
152
|
+
fetchAndSetState();
|
|
153
|
+
};
|
|
154
|
+
export const runHttpRequests = function runHttpRequests(props, state) {
|
|
155
|
+
const requests = useContent(props, state)?.data?.httpRequests ?? {};
|
|
156
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
157
|
+
if (url && (!httpReqsData(props, state)[key] || isEditing())) {
|
|
158
|
+
const evaluatedUrl = evalExpression(props, state, url);
|
|
159
|
+
handleRequest(props, state, {
|
|
160
|
+
url: evaluatedUrl,
|
|
161
|
+
key,
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
});
|
|
165
|
+
};
|
|
166
|
+
export const emitStateUpdate = function emitStateUpdate(props, state) {
|
|
167
|
+
if (isEditing()) {
|
|
168
|
+
window.dispatchEvent(
|
|
169
|
+
new CustomEvent("builder:component:stateChange", {
|
|
170
|
+
detail: {
|
|
171
|
+
state: contentState(props, state),
|
|
172
|
+
ref: {
|
|
173
|
+
name: props.model,
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
})
|
|
177
|
+
);
|
|
178
|
+
}
|
|
179
|
+
};
|
|
180
|
+
export const shouldRenderContentStyles = function shouldRenderContentStyles(
|
|
181
|
+
props,
|
|
182
|
+
state
|
|
183
|
+
) {
|
|
184
|
+
return Boolean(
|
|
185
|
+
(useContent(props, state)?.data?.cssCode ||
|
|
186
|
+
useContent(props, state)?.data?.customFonts?.length) &&
|
|
187
|
+
TARGET !== "reactNative"
|
|
188
|
+
);
|
|
189
|
+
};
|
|
190
|
+
export const RenderContent = component$((props) => {
|
|
191
|
+
const hostElement = useHostElement();
|
|
192
|
+
const state = useStore({
|
|
193
|
+
forceReRenderCount: 0,
|
|
194
|
+
overrideContent: null,
|
|
195
|
+
update: 0,
|
|
196
|
+
overrideState: {},
|
|
197
|
+
});
|
|
198
|
+
useContextProvider(
|
|
199
|
+
BuilderContext,
|
|
200
|
+
useStore({
|
|
201
|
+
content: (() => {
|
|
202
|
+
return useContent(props, state);
|
|
203
|
+
})(),
|
|
204
|
+
state: (() => {
|
|
205
|
+
return contentState(props, state);
|
|
206
|
+
})(),
|
|
207
|
+
context: (() => {
|
|
208
|
+
return contextContext(props, state);
|
|
209
|
+
})(),
|
|
210
|
+
apiKey: (() => {
|
|
211
|
+
return props.apiKey;
|
|
212
|
+
})(),
|
|
213
|
+
registeredComponents: (() => {
|
|
214
|
+
return allRegisteredComponents(props, state);
|
|
215
|
+
})(),
|
|
216
|
+
})
|
|
217
|
+
);
|
|
218
|
+
useClientEffect$(() => {
|
|
219
|
+
if (isBrowser()) {
|
|
220
|
+
if (isEditing()) {
|
|
221
|
+
state.forceReRenderCount++;
|
|
222
|
+
_useMutableProps(hostElement, true);
|
|
223
|
+
|
|
224
|
+
registerInsertMenu();
|
|
225
|
+
setupBrowserForEditing();
|
|
226
|
+
Object.values(allRegisteredComponents(props, state)).forEach(
|
|
227
|
+
(registeredComponent) => {
|
|
228
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
229
|
+
window.parent?.postMessage(message, "*");
|
|
230
|
+
}
|
|
231
|
+
);
|
|
232
|
+
window.addEventListener(
|
|
233
|
+
"message",
|
|
234
|
+
processMessage.bind(null, props, state)
|
|
235
|
+
);
|
|
236
|
+
window.addEventListener(
|
|
237
|
+
"builder:component:stateChangeListenerActivated",
|
|
238
|
+
emitStateUpdate.bind(null, props, state)
|
|
239
|
+
);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
if (useContent(props, state) && props.canTrack !== false) {
|
|
243
|
+
track("impression", {
|
|
244
|
+
contentId: useContent(props, state).id,
|
|
245
|
+
});
|
|
246
|
+
} // override normal content in preview mode
|
|
247
|
+
|
|
248
|
+
if (isPreviewing()) {
|
|
249
|
+
const searchParams = new URL(location.href).searchParams;
|
|
250
|
+
|
|
251
|
+
if (
|
|
252
|
+
props.model &&
|
|
253
|
+
searchParams.get("builder.preview") === props.model
|
|
254
|
+
) {
|
|
255
|
+
const previewApiKey =
|
|
256
|
+
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
257
|
+
|
|
258
|
+
if (previewApiKey) {
|
|
259
|
+
getContent({
|
|
260
|
+
model: props.model,
|
|
261
|
+
apiKey: previewApiKey,
|
|
262
|
+
}).then((content) => {
|
|
263
|
+
if (content) {
|
|
264
|
+
state.overrideContent = content;
|
|
265
|
+
}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
evaluateJsCode(props, state);
|
|
272
|
+
runHttpRequests(props, state);
|
|
273
|
+
emitStateUpdate(props, state);
|
|
274
|
+
}
|
|
275
|
+
});
|
|
276
|
+
useWatch$(({ track }) => {
|
|
277
|
+
state.useContent?.data && track(state.useContent?.data, "jsCode");
|
|
278
|
+
evaluateJsCode(props, state);
|
|
279
|
+
});
|
|
280
|
+
useWatch$(({ track }) => {
|
|
281
|
+
state.useContent?.data && track(state.useContent?.data, "httpRequests");
|
|
282
|
+
runHttpRequests(props, state);
|
|
283
|
+
});
|
|
284
|
+
useWatch$(({ track }) => {
|
|
285
|
+
state && track(state, "contentState");
|
|
286
|
+
emitStateUpdate(props, state);
|
|
287
|
+
});
|
|
288
|
+
useCleanup$(() => {
|
|
289
|
+
if (isBrowser()) {
|
|
290
|
+
window.removeEventListener(
|
|
291
|
+
"message",
|
|
292
|
+
processMessage.bind(null, props, state)
|
|
293
|
+
);
|
|
294
|
+
window.removeEventListener(
|
|
295
|
+
"builder:component:stateChangeListenerActivated",
|
|
296
|
+
emitStateUpdate.bind(null, props, state)
|
|
297
|
+
);
|
|
298
|
+
}
|
|
299
|
+
});
|
|
300
|
+
return (
|
|
301
|
+
<>
|
|
302
|
+
{useContent(props, state) ? (
|
|
303
|
+
<div
|
|
304
|
+
onClick$={(event) => onClick(props, state, event)}
|
|
305
|
+
builder-content-id={useContent(props, state)?.id}
|
|
306
|
+
>
|
|
307
|
+
{shouldRenderContentStyles(props, state) ? (
|
|
308
|
+
<RenderContentStyles
|
|
309
|
+
cssCode={useContent(props, state)?.data?.cssCode}
|
|
310
|
+
customFonts={useContent(props, state)?.data?.customFonts}
|
|
311
|
+
></RenderContentStyles>
|
|
312
|
+
) : null}
|
|
313
|
+
<RenderBlocks
|
|
314
|
+
blocks={useContent(props, state)?.data?.blocks}
|
|
315
|
+
key={state.forceReRenderCount}
|
|
316
|
+
></RenderBlocks>
|
|
317
|
+
</div>
|
|
318
|
+
) : null}
|
|
319
|
+
</>
|
|
320
|
+
);
|
|
321
|
+
});
|
|
322
|
+
export default RenderContent;
|
|
323
|
+
export const COMPONENT = {
|
|
324
|
+
"@type": "@builder.io/mitosis/component",
|
|
325
|
+
imports: [
|
|
326
|
+
{
|
|
327
|
+
imports: {
|
|
328
|
+
getDefaultRegisteredComponents: "getDefaultRegisteredComponents",
|
|
329
|
+
},
|
|
330
|
+
path: "../../constants/builder-registered-components.js",
|
|
331
|
+
},
|
|
332
|
+
{
|
|
333
|
+
imports: {
|
|
334
|
+
TARGET: "TARGET",
|
|
335
|
+
},
|
|
336
|
+
path: "../../constants/target.js",
|
|
337
|
+
},
|
|
338
|
+
{
|
|
339
|
+
imports: {
|
|
340
|
+
BuilderContext: "default",
|
|
341
|
+
},
|
|
342
|
+
path: "../../context/builder.context.lite",
|
|
343
|
+
},
|
|
344
|
+
{
|
|
345
|
+
imports: {
|
|
346
|
+
evaluate: "evaluate",
|
|
347
|
+
},
|
|
348
|
+
path: "../../functions/evaluate.js",
|
|
349
|
+
},
|
|
350
|
+
{
|
|
351
|
+
imports: {
|
|
352
|
+
getContent: "getContent",
|
|
353
|
+
},
|
|
354
|
+
path: "../../functions/get-content/index.js",
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
imports: {
|
|
358
|
+
getFetch: "getFetch",
|
|
359
|
+
},
|
|
360
|
+
path: "../../functions/get-fetch.js",
|
|
361
|
+
},
|
|
362
|
+
{
|
|
363
|
+
imports: {
|
|
364
|
+
isBrowser: "isBrowser",
|
|
365
|
+
},
|
|
366
|
+
path: "../../functions/is-browser.js",
|
|
367
|
+
},
|
|
368
|
+
{
|
|
369
|
+
imports: {
|
|
370
|
+
isEditing: "isEditing",
|
|
371
|
+
},
|
|
372
|
+
path: "../../functions/is-editing.js",
|
|
373
|
+
},
|
|
374
|
+
{
|
|
375
|
+
imports: {
|
|
376
|
+
isPreviewing: "isPreviewing",
|
|
377
|
+
},
|
|
378
|
+
path: "../../functions/is-previewing.js",
|
|
379
|
+
},
|
|
380
|
+
{
|
|
381
|
+
imports: {
|
|
382
|
+
components: "components",
|
|
383
|
+
createRegisterComponentMessage: "createRegisterComponentMessage",
|
|
384
|
+
},
|
|
385
|
+
path: "../../functions/register-component.js",
|
|
386
|
+
},
|
|
387
|
+
{
|
|
388
|
+
imports: {
|
|
389
|
+
track: "track",
|
|
390
|
+
},
|
|
391
|
+
path: "../../functions/track.js",
|
|
392
|
+
},
|
|
393
|
+
{
|
|
394
|
+
imports: {
|
|
395
|
+
RenderBlocks: "default",
|
|
396
|
+
},
|
|
397
|
+
path: "../render-blocks.lite",
|
|
398
|
+
},
|
|
399
|
+
{
|
|
400
|
+
imports: {
|
|
401
|
+
RenderContentStyles: "default",
|
|
402
|
+
},
|
|
403
|
+
path: "./components/render-styles.lite",
|
|
404
|
+
},
|
|
405
|
+
{
|
|
406
|
+
imports: {
|
|
407
|
+
registerInsertMenu: "registerInsertMenu",
|
|
408
|
+
setupBrowserForEditing: "setupBrowserForEditing",
|
|
409
|
+
},
|
|
410
|
+
path: "../../scripts/init-editing.js",
|
|
411
|
+
},
|
|
412
|
+
],
|
|
413
|
+
exports: {},
|
|
414
|
+
inputs: [],
|
|
415
|
+
meta: {
|
|
416
|
+
useMetadata: {
|
|
417
|
+
qwik: {
|
|
418
|
+
component: {
|
|
419
|
+
useHostElement: true,
|
|
420
|
+
},
|
|
421
|
+
replace: {
|
|
422
|
+
"// QWIK-REPLACE: _useMutableProps":
|
|
423
|
+
"_useMutableProps(hostElement, true);",
|
|
424
|
+
},
|
|
425
|
+
imports: {
|
|
426
|
+
_useMutableProps: "@builder.io/qwik",
|
|
427
|
+
},
|
|
428
|
+
},
|
|
429
|
+
},
|
|
430
|
+
},
|
|
431
|
+
refs: {},
|
|
432
|
+
state: {
|
|
433
|
+
forceReRenderCount: 0,
|
|
434
|
+
useContent:
|
|
435
|
+
"@builder.io/mitosis/method:get useContent() {\n const mergedContent: BuilderContent = { ...props.content,\n ...state.overrideContent,\n data: { ...props.content?.data,\n ...props.data,\n ...state.overrideContent?.data\n }\n };\n return mergedContent;\n}",
|
|
436
|
+
overrideContent: null,
|
|
437
|
+
update: 0,
|
|
438
|
+
overrideState: {},
|
|
439
|
+
contentState:
|
|
440
|
+
"@builder.io/mitosis/method:get contentState() {\n return { ...props.content?.data?.state,\n ...props.data,\n ...state.overrideState\n };\n}",
|
|
441
|
+
contextContext:
|
|
442
|
+
"@builder.io/mitosis/method:get contextContext() {\n return props.context || {};\n}",
|
|
443
|
+
allRegisteredComponents:
|
|
444
|
+
"@builder.io/mitosis/method:get allRegisteredComponents() {\n const allComponentsArray = [...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.\n // Since users are able to override our default components, we need to make sure that we do not break such\n // existing usage.\n // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,\n // which is the new standard way of providing custom components, and must therefore take precedence.\n ...components, ...(props.customComponents || [])];\n const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc,\n [curr.name]: curr\n }), ({} as RegisteredComponents));\n return allComponents;\n}",
|
|
445
|
+
processMessage:
|
|
446
|
+
"@builder.io/mitosis/method:processMessage(event: MessageEvent) {\n const {\n data\n } = event;\n\n if (data) {\n switch (data.type) {\n case 'builder.contentUpdate':\n {\n const messageContent = data.data;\n const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;\n const contentData = messageContent.data;\n\n if (key === props.model) {\n state.overrideContent = contentData;\n }\n\n break;\n }\n\n case 'builder.patchUpdates':\n {\n // TODO\n break;\n }\n }\n }\n}",
|
|
447
|
+
evaluateJsCode:
|
|
448
|
+
"@builder.io/mitosis/method:evaluateJsCode() {\n // run any dynamic JS code attached to content\n const jsCode = useContent(props,state)?.data?.jsCode;\n\n if (jsCode) {\n evaluate({\n code: jsCode,\n context: contextContext(props,state),\n state: contentState(props,state)\n });\n }\n}",
|
|
449
|
+
httpReqsData:
|
|
450
|
+
"@builder.io/mitosis/method:get httpReqsData() {\n return {};\n}",
|
|
451
|
+
onClick:
|
|
452
|
+
"@builder.io/mitosis/method:onClick(_event: MouseEvent) {\n if (useContent(props,state) && props.canTrack !== false) {\n track('click', {\n contentId: useContent(props,state).id\n });\n }\n}",
|
|
453
|
+
evalExpression:
|
|
454
|
+
"@builder.io/mitosis/method:evalExpression(expression: string) {\n return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({\n code: group,\n context: contextContext(props,state),\n state: contentState(props,state)\n }));\n}",
|
|
455
|
+
handleRequest:
|
|
456
|
+
"@builder.io/mitosis/method:handleRequest({\n url,\n key\n}: {\n key: string;\n url: string;\n}) {\n const fetchAndSetState = async () => {\n const fetch = await getFetch();\n const response = await fetch(url);\n const json = await response.json();\n const newOverrideState = { ...state.overrideState,\n [key]: json\n };\n state.overrideState = newOverrideState;\n };\n\n fetchAndSetState();\n}",
|
|
457
|
+
runHttpRequests:
|
|
458
|
+
"@builder.io/mitosis/method:runHttpRequests() {\n const requests = useContent(props,state)?.data?.httpRequests ?? {};\n Object.entries(requests).forEach(([key, url]) => {\n if (url && (!httpReqsData(props,state)[key] || isEditing())) {\n const evaluatedUrl = evalExpression(props,state,url);\n handleRequest(props,state,{\n url: evaluatedUrl,\n key\n });\n }\n });\n}",
|
|
459
|
+
emitStateUpdate:
|
|
460
|
+
"@builder.io/mitosis/method:emitStateUpdate() {\n if (isEditing()) {\n window.dispatchEvent(new CustomEvent<BuilderComponentStateChange>('builder:component:stateChange', {\n detail: {\n state: contentState(props,state),\n ref: {\n name: props.model\n }\n }\n }));\n }\n}",
|
|
461
|
+
shouldRenderContentStyles:
|
|
462
|
+
"@builder.io/mitosis/method:get shouldRenderContentStyles() {\n return Boolean((useContent(props,state)?.data?.cssCode || useContent(props,state)?.data?.customFonts?.length) && TARGET !== 'reactNative');\n}",
|
|
463
|
+
},
|
|
464
|
+
children: [
|
|
465
|
+
{
|
|
466
|
+
"@type": "@builder.io/mitosis/node",
|
|
467
|
+
name: "Show",
|
|
468
|
+
meta: {},
|
|
469
|
+
scope: {},
|
|
470
|
+
properties: {},
|
|
471
|
+
bindings: {
|
|
472
|
+
when: {
|
|
473
|
+
code: "useContent(props,state)",
|
|
474
|
+
},
|
|
475
|
+
},
|
|
476
|
+
children: [
|
|
477
|
+
{
|
|
478
|
+
"@type": "@builder.io/mitosis/node",
|
|
479
|
+
name: "div",
|
|
480
|
+
meta: {},
|
|
481
|
+
scope: {},
|
|
482
|
+
properties: {
|
|
483
|
+
_text: "\n ",
|
|
484
|
+
},
|
|
485
|
+
bindings: {},
|
|
486
|
+
children: [],
|
|
487
|
+
},
|
|
488
|
+
{
|
|
489
|
+
"@type": "@builder.io/mitosis/node",
|
|
490
|
+
name: "div",
|
|
491
|
+
meta: {},
|
|
492
|
+
scope: {},
|
|
493
|
+
properties: {},
|
|
494
|
+
bindings: {
|
|
495
|
+
onClick: {
|
|
496
|
+
code: "onClick(props,state,event)",
|
|
497
|
+
arguments: ["event"],
|
|
498
|
+
},
|
|
499
|
+
"builder-content-id": {
|
|
500
|
+
code: "useContent(props,state)?.id",
|
|
501
|
+
},
|
|
502
|
+
},
|
|
503
|
+
children: [
|
|
504
|
+
{
|
|
505
|
+
"@type": "@builder.io/mitosis/node",
|
|
506
|
+
name: "div",
|
|
507
|
+
meta: {},
|
|
508
|
+
scope: {},
|
|
509
|
+
properties: {
|
|
510
|
+
_text: "\n ",
|
|
511
|
+
},
|
|
512
|
+
bindings: {},
|
|
513
|
+
children: [],
|
|
514
|
+
},
|
|
515
|
+
{
|
|
516
|
+
"@type": "@builder.io/mitosis/node",
|
|
517
|
+
name: "Show",
|
|
518
|
+
meta: {},
|
|
519
|
+
scope: {},
|
|
520
|
+
properties: {},
|
|
521
|
+
bindings: {
|
|
522
|
+
when: {
|
|
523
|
+
code: "shouldRenderContentStyles(props,state)",
|
|
524
|
+
},
|
|
525
|
+
},
|
|
526
|
+
children: [
|
|
527
|
+
{
|
|
528
|
+
"@type": "@builder.io/mitosis/node",
|
|
529
|
+
name: "RenderContentStyles",
|
|
530
|
+
meta: {},
|
|
531
|
+
scope: {},
|
|
532
|
+
properties: {},
|
|
533
|
+
bindings: {
|
|
534
|
+
cssCode: {
|
|
535
|
+
code: "useContent(props,state)?.data?.cssCode",
|
|
536
|
+
},
|
|
537
|
+
customFonts: {
|
|
538
|
+
code: "useContent(props,state)?.data?.customFonts",
|
|
539
|
+
},
|
|
540
|
+
},
|
|
541
|
+
children: [],
|
|
542
|
+
},
|
|
543
|
+
],
|
|
544
|
+
},
|
|
545
|
+
{
|
|
546
|
+
"@type": "@builder.io/mitosis/node",
|
|
547
|
+
name: "div",
|
|
548
|
+
meta: {},
|
|
549
|
+
scope: {},
|
|
550
|
+
properties: {
|
|
551
|
+
_text: "\n ",
|
|
552
|
+
},
|
|
553
|
+
bindings: {},
|
|
554
|
+
children: [],
|
|
555
|
+
},
|
|
556
|
+
{
|
|
557
|
+
"@type": "@builder.io/mitosis/node",
|
|
558
|
+
name: "RenderBlocks",
|
|
559
|
+
meta: {},
|
|
560
|
+
scope: {},
|
|
561
|
+
properties: {},
|
|
562
|
+
bindings: {
|
|
563
|
+
blocks: {
|
|
564
|
+
code: "useContent(props,state)?.data?.blocks",
|
|
565
|
+
},
|
|
566
|
+
key: {
|
|
567
|
+
code: "state.forceReRenderCount",
|
|
568
|
+
},
|
|
569
|
+
},
|
|
570
|
+
children: [],
|
|
571
|
+
},
|
|
572
|
+
{
|
|
573
|
+
"@type": "@builder.io/mitosis/node",
|
|
574
|
+
name: "div",
|
|
575
|
+
meta: {},
|
|
576
|
+
scope: {},
|
|
577
|
+
properties: {
|
|
578
|
+
_text: "\n ",
|
|
579
|
+
},
|
|
580
|
+
bindings: {},
|
|
581
|
+
children: [],
|
|
582
|
+
},
|
|
583
|
+
],
|
|
584
|
+
},
|
|
585
|
+
{
|
|
586
|
+
"@type": "@builder.io/mitosis/node",
|
|
587
|
+
name: "div",
|
|
588
|
+
meta: {},
|
|
589
|
+
scope: {},
|
|
590
|
+
properties: {
|
|
591
|
+
_text: "\n ",
|
|
592
|
+
},
|
|
593
|
+
bindings: {},
|
|
594
|
+
children: [],
|
|
595
|
+
},
|
|
596
|
+
],
|
|
597
|
+
},
|
|
598
|
+
],
|
|
599
|
+
hooks: {
|
|
600
|
+
onMount: {
|
|
601
|
+
code: "\n if (isBrowser()) {\n if (isEditing()) {\n state.forceReRenderCount++; _useMutableProps(hostElement, true);\n\n registerInsertMenu();\n setupBrowserForEditing();\n Object.values(allRegisteredComponents(props,state)).forEach(registeredComponent => {\n const message = createRegisterComponentMessage(registeredComponent);\n window.parent?.postMessage(message, '*');\n });\n window.addEventListener('message', processMessage.bind(null,props,state));\n window.addEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate.bind(null,props,state));\n }\n\n if (useContent(props,state) && props.canTrack !== false) {\n track('impression', {\n contentId: useContent(props,state).id\n });\n } // override normal content in preview mode\n\n\n if (isPreviewing()) {\n const searchParams = new URL(location.href).searchParams;\n\n if (props.model && searchParams.get('builder.preview') === props.model) {\n const previewApiKey = searchParams.get('apiKey') || searchParams.get('builder.space');\n\n if (previewApiKey) {\n getContent({\n model: props.model,\n apiKey: previewApiKey\n }).then(content => {\n if (content) {\n state.overrideContent = content;\n }\n });\n }\n }\n }\n\n evaluateJsCode(props,state,);\n runHttpRequests(props,state,);\n emitStateUpdate(props,state,);\n }\n",
|
|
602
|
+
},
|
|
603
|
+
onUpdate: [
|
|
604
|
+
{
|
|
605
|
+
code: "\n evaluateJsCode(props,state,);\n",
|
|
606
|
+
deps: "[state.useContent?.data?.jsCode]",
|
|
607
|
+
},
|
|
608
|
+
{
|
|
609
|
+
code: "\n runHttpRequests(props,state,);\n",
|
|
610
|
+
deps: "[state.useContent?.data?.httpRequests]",
|
|
611
|
+
},
|
|
612
|
+
{
|
|
613
|
+
code: "\n emitStateUpdate(props,state,);\n",
|
|
614
|
+
deps: "[state.contentState]",
|
|
615
|
+
},
|
|
616
|
+
],
|
|
617
|
+
onUnMount: {
|
|
618
|
+
code: "\n if (isBrowser()) {\n window.removeEventListener('message', processMessage.bind(null,props,state));\n window.removeEventListener('builder:component:stateChangeListenerActivated', emitStateUpdate.bind(null,props,state));\n }\n",
|
|
619
|
+
},
|
|
620
|
+
},
|
|
621
|
+
context: {
|
|
622
|
+
get: {},
|
|
623
|
+
set: {
|
|
624
|
+
"../../context/builder.context.lite:default": {
|
|
625
|
+
name: "BuilderContext",
|
|
626
|
+
value: {
|
|
627
|
+
content:
|
|
628
|
+
"@builder.io/mitosis/method:get content() {\n return useContent(props,state);\n}",
|
|
629
|
+
state:
|
|
630
|
+
"@builder.io/mitosis/method:get state() {\n return contentState(props,state);\n}",
|
|
631
|
+
context:
|
|
632
|
+
"@builder.io/mitosis/method:get context() {\n return contextContext(props,state);\n}",
|
|
633
|
+
apiKey:
|
|
634
|
+
"@builder.io/mitosis/method:get apiKey() {\n return props.apiKey;\n}",
|
|
635
|
+
registeredComponents:
|
|
636
|
+
"@builder.io/mitosis/method:get registeredComponents() {\n return allRegisteredComponents(props,state);\n}",
|
|
637
|
+
},
|
|
638
|
+
},
|
|
639
|
+
},
|
|
640
|
+
},
|
|
641
|
+
name: "RenderContent",
|
|
642
|
+
subComponents: [],
|
|
643
|
+
types: [
|
|
644
|
+
"export type RenderContentProps = {\n content?: Nullable<BuilderContent>;\n model?: string;\n data?: {\n [key: string]: any;\n };\n context?: BuilderRenderContext;\n apiKey: string;\n customComponents?: RegisteredComponent[];\n canTrack?: boolean;\n};",
|
|
645
|
+
],
|
|
646
|
+
interfaces: [
|
|
647
|
+
"interface BuilderComponentStateChange {\n state: BuilderRenderState;\n ref: {\n name?: string;\n props?: {\n builderBlock?: {\n id?: string;\n };\n };\n };\n}",
|
|
648
|
+
],
|
|
649
|
+
propsTypeRef: "RenderContentProps",
|
|
650
|
+
};
|