@builder.io/sdk-solid 0.5.8 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +0 -4
  2. package/dist/index.d.ts +51 -0
  3. package/lib/browser/dev.js +4790 -0
  4. package/lib/browser/dev.jsx +4392 -0
  5. package/lib/browser/index.js +4767 -0
  6. package/lib/browser/index.jsx +4374 -0
  7. package/lib/edge/dev.js +7921 -0
  8. package/lib/edge/dev.jsx +7525 -0
  9. package/lib/edge/index.js +7898 -0
  10. package/lib/edge/index.jsx +7507 -0
  11. package/lib/node/dev.js +4790 -0
  12. package/lib/node/dev.jsx +4392 -0
  13. package/lib/node/index.js +4767 -0
  14. package/lib/node/index.jsx +4374 -0
  15. package/package.json +86 -14
  16. package/CHANGELOG.md +0 -98
  17. package/solid-index.jsx +0 -5
  18. package/src/blocks/BaseText.jsx +0 -11
  19. package/src/blocks/button/button.jsx +0 -41
  20. package/src/blocks/button/component-info.js +0 -34
  21. package/src/blocks/columns/columns.jsx +0 -174
  22. package/src/blocks/columns/component-info.js +0 -218
  23. package/src/blocks/custom-code/component-info.js +0 -24
  24. package/src/blocks/custom-code/custom-code.jsx +0 -62
  25. package/src/blocks/embed/component-info.js +0 -37
  26. package/src/blocks/embed/embed.jsx +0 -50
  27. package/src/blocks/embed/helpers.js +0 -3
  28. package/src/blocks/form/component-info.js +0 -223
  29. package/src/blocks/form/form.jsx +0 -5
  30. package/src/blocks/fragment/component-info.js +0 -8
  31. package/src/blocks/fragment/fragment.jsx +0 -5
  32. package/src/blocks/helpers.js +0 -27
  33. package/src/blocks/image/component-info.js +0 -122
  34. package/src/blocks/image/image.helpers.js +0 -46
  35. package/src/blocks/image/image.jsx +0 -122
  36. package/src/blocks/img/component-info.js +0 -15
  37. package/src/blocks/img/img.jsx +0 -20
  38. package/src/blocks/input/component-info.js +0 -45
  39. package/src/blocks/input/input.jsx +0 -22
  40. package/src/blocks/raw-text/component-info.js +0 -11
  41. package/src/blocks/raw-text/raw-text.jsx +0 -10
  42. package/src/blocks/section/component-info.js +0 -41
  43. package/src/blocks/section/section.jsx +0 -26
  44. package/src/blocks/select/component-info.js +0 -44
  45. package/src/blocks/select/select.jsx +0 -30
  46. package/src/blocks/submit-button/component-info.js +0 -23
  47. package/src/blocks/submit-button/submit-button.jsx +0 -11
  48. package/src/blocks/symbol/component-info.js +0 -35
  49. package/src/blocks/symbol/symbol.helpers.js +0 -60
  50. package/src/blocks/symbol/symbol.jsx +0 -64
  51. package/src/blocks/text/component-info.js +0 -20
  52. package/src/blocks/text/text.jsx +0 -14
  53. package/src/blocks/textarea/component-info.js +0 -38
  54. package/src/blocks/textarea/textarea.jsx +0 -16
  55. package/src/blocks/video/component-info.js +0 -83
  56. package/src/blocks/video/video.jsx +0 -61
  57. package/src/components/block/block.helpers.js +0 -99
  58. package/src/components/block/block.jsx +0 -167
  59. package/src/components/block/components/block-styles.jsx +0 -85
  60. package/src/components/block/components/block-wrapper.jsx +0 -50
  61. package/src/components/block/components/component-ref/component-ref.helpers.js +0 -41
  62. package/src/components/block/components/component-ref/component-ref.jsx +0 -58
  63. package/src/components/block/components/interactive-element.jsx +0 -30
  64. package/src/components/block/components/repeated-block.jsx +0 -20
  65. package/src/components/block/types.js +0 -0
  66. package/src/components/blocks/blocks-wrapper.jsx +0 -66
  67. package/src/components/blocks/blocks.jsx +0 -57
  68. package/src/components/content/components/enable-editor.jsx +0 -347
  69. package/src/components/content/components/styles.helpers.js +0 -56
  70. package/src/components/content/components/styles.jsx +0 -36
  71. package/src/components/content/content.helpers.js +0 -48
  72. package/src/components/content/content.jsx +0 -136
  73. package/src/components/content/content.types.js +0 -0
  74. package/src/components/content/index.js +0 -2
  75. package/src/components/content/wrap-component-ref.js +0 -2
  76. package/src/components/content-variants/content-variants.jsx +0 -115
  77. package/src/components/content-variants/content-variants.types.js +0 -0
  78. package/src/components/content-variants/helpers.js +0 -158
  79. package/src/components/inlined-script.jsx +0 -5
  80. package/src/components/inlined-styles.jsx +0 -5
  81. package/src/constants/builder-registered-components.js +0 -63
  82. package/src/constants/device-sizes.js +0 -48
  83. package/src/constants/sdk-version.js +0 -1
  84. package/src/constants/target.js +0 -4
  85. package/src/context/builder.context.js +0 -16
  86. package/src/context/components.context.js +0 -5
  87. package/src/context/types.js +0 -0
  88. package/src/functions/apply-patch-with-mutation.js +0 -66
  89. package/src/functions/camel-to-kebab-case.js +0 -2
  90. package/src/functions/evaluate/acorn-interpreter.js +0 -2876
  91. package/src/functions/evaluate/evaluate.js +0 -79
  92. package/src/functions/evaluate/index.js +0 -2
  93. package/src/functions/evaluate/non-node-runtime/index.js +0 -18
  94. package/src/functions/evaluate/non-node-runtime/non-node-runtime.js +0 -92
  95. package/src/functions/evaluate/types.js +0 -0
  96. package/src/functions/event-handler-name.js +0 -5
  97. package/src/functions/extract-text-styles.js +0 -14
  98. package/src/functions/fast-clone.js +0 -2
  99. package/src/functions/fetch-builder-props.js +0 -60
  100. package/src/functions/get-block-actions-handler.js +0 -11
  101. package/src/functions/get-block-actions.js +0 -29
  102. package/src/functions/get-block-component-options.js +0 -27
  103. package/src/functions/get-block-properties.js +0 -63
  104. package/src/functions/get-builder-search-params/index.js +0 -33
  105. package/src/functions/get-content/generate-content-url.js +0 -59
  106. package/src/functions/get-content/index.js +0 -116
  107. package/src/functions/get-content/types.js +0 -0
  108. package/src/functions/get-fetch.js +0 -12
  109. package/src/functions/get-global-this.js +0 -16
  110. package/src/functions/get-processed-block.js +0 -74
  111. package/src/functions/get-react-native-block-styles.js +0 -32
  112. package/src/functions/is-browser.js +0 -4
  113. package/src/functions/is-editing.js +0 -6
  114. package/src/functions/is-iframe.js +0 -5
  115. package/src/functions/is-non-node-server.js +0 -9
  116. package/src/functions/is-previewing.js +0 -12
  117. package/src/functions/on-change.js +0 -24
  118. package/src/functions/register-component.js +0 -60
  119. package/src/functions/register.js +0 -27
  120. package/src/functions/sanitize-react-native-block-styles.js +0 -71
  121. package/src/functions/set-editor-settings.js +0 -13
  122. package/src/functions/set.js +0 -9
  123. package/src/functions/track/helpers.js +0 -48
  124. package/src/functions/track/index.js +0 -131
  125. package/src/functions/track/interaction.js +0 -57
  126. package/src/functions/transform-block-properties.js +0 -4
  127. package/src/functions/transform-block.js +0 -4
  128. package/src/helpers/ab-tests.js +0 -158
  129. package/src/helpers/canTrack.js +0 -3
  130. package/src/helpers/cookie.js +0 -77
  131. package/src/helpers/css.js +0 -30
  132. package/src/helpers/flatten.js +0 -31
  133. package/src/helpers/localStorage.js +0 -32
  134. package/src/helpers/logger.js +0 -8
  135. package/src/helpers/nullable.js +0 -2
  136. package/src/helpers/preview-lru-cache/get.js +0 -4
  137. package/src/helpers/preview-lru-cache/helpers.js +0 -0
  138. package/src/helpers/preview-lru-cache/init.js +0 -2
  139. package/src/helpers/preview-lru-cache/set.js +0 -31
  140. package/src/helpers/preview-lru-cache/types.js +0 -0
  141. package/src/helpers/sessionId.js +0 -55
  142. package/src/helpers/time.js +0 -3
  143. package/src/helpers/url.js +0 -11
  144. package/src/helpers/uuid.js +0 -11
  145. package/src/helpers/visitorId.js +0 -35
  146. package/src/index-helpers/blocks-exports.js +0 -13
  147. package/src/index-helpers/top-of-file.js +0 -2
  148. package/src/index.js +0 -12
  149. package/src/scripts/init-editing.js +0 -109
  150. package/src/types/api-version.js +0 -2
  151. package/src/types/builder-block.js +0 -0
  152. package/src/types/builder-content.js +0 -0
  153. package/src/types/builder-props.js +0 -0
  154. package/src/types/can-track.js +0 -0
  155. package/src/types/components.js +0 -0
  156. package/src/types/deep-partial.js +0 -0
  157. package/src/types/element.js +0 -0
  158. package/src/types/enforced-partials.js +0 -0
  159. package/src/types/input.js +0 -0
  160. package/src/types/targets.js +0 -0
  161. package/src/types/typescript.js +0 -0
  162. package/vite.config.ts +0 -18
@@ -1,347 +0,0 @@
1
- import { Show, onMount, on, createEffect, createSignal } from "solid-js";
2
-
3
- import { evaluate } from "../../../functions/evaluate/index.js";
4
- import { fetch } from "../../../functions/get-fetch.js";
5
- import { isBrowser } from "../../../functions/is-browser.js";
6
- import { isEditing } from "../../../functions/is-editing.js";
7
- import { createRegisterComponentMessage } from "../../../functions/register-component.js";
8
- import { _track } from "../../../functions/track/index.js";
9
- import builderContext from "../../../context/builder.context.js";
10
- import {
11
- registerInsertMenu,
12
- setupBrowserForEditing,
13
- } from "../../../scripts/init-editing.js";
14
- import { checkIsDefined } from "../../../helpers/nullable.js";
15
- import { getInteractionPropertiesForEvent } from "../../../functions/track/interaction.js";
16
- import { logger } from "../../../helpers/logger.js";
17
- import { fetchOneEntry } from "../../../functions/get-content/index.js";
18
- import { isPreviewing } from "../../../functions/is-previewing.js";
19
- import { postPreviewContent } from "../../../helpers/preview-lru-cache/set.js";
20
- import { fastClone } from "../../../functions/fast-clone.js";
21
-
22
- function EnableEditor(props) {
23
- const [canTrackToUse, setCanTrackToUse] = createSignal(
24
- checkIsDefined(props.canTrack) ? props.canTrack : true
25
- );
26
-
27
- const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
28
-
29
- const [lastUpdated, setLastUpdated] = createSignal(0);
30
-
31
- const [shouldSendResetCookie, setShouldSendResetCookie] = createSignal(false);
32
-
33
- const [httpReqsData, setHttpReqsData] = createSignal({});
34
-
35
- const [clicked, setClicked] = createSignal(false);
36
-
37
- function mergeNewContent(newContent) {
38
- const newContentValue = {
39
- ...props.builderContextSignal.content,
40
- ...newContent,
41
- data: {
42
- ...props.builderContextSignal.content?.data,
43
- ...newContent?.data,
44
- },
45
- meta: {
46
- ...props.builderContextSignal.content?.meta,
47
- ...newContent?.meta,
48
- breakpoints:
49
- newContent?.meta?.breakpoints ||
50
- props.builderContextSignal.content?.meta?.breakpoints,
51
- },
52
- };
53
- props.setBuilderContextSignal((PREVIOUS_VALUE) => ({
54
- ...PREVIOUS_VALUE,
55
- content: newContentValue,
56
- }));
57
- }
58
-
59
- function processMessage(event) {
60
- const { data } = event;
61
- if (data) {
62
- switch (data.type) {
63
- case "builder.configureSdk": {
64
- const messageContent = data.data;
65
- const { breakpoints, contentId } = messageContent;
66
- if (
67
- !contentId ||
68
- contentId !== props.builderContextSignal.content?.id
69
- ) {
70
- return;
71
- }
72
- if (breakpoints) {
73
- mergeNewContent({
74
- meta: {
75
- breakpoints,
76
- },
77
- });
78
- }
79
- setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
80
- break;
81
- }
82
- case "builder.contentUpdate": {
83
- const messageContent = data.data;
84
- const key =
85
- messageContent.key ||
86
- messageContent.alias ||
87
- messageContent.entry ||
88
- messageContent.modelName;
89
- const contentData = messageContent.data;
90
- if (key === props.model) {
91
- mergeNewContent(contentData);
92
- setForceReRenderCount(forceReRenderCount() + 1); // This is a hack to force Qwik to re-render.
93
- }
94
-
95
- break;
96
- }
97
- }
98
- }
99
- }
100
-
101
- function evaluateJsCode() {
102
- // run any dynamic JS code attached to content
103
- const jsCode = props.builderContextSignal.content?.data?.jsCode;
104
- if (jsCode) {
105
- evaluate({
106
- code: jsCode,
107
- context: props.context || {},
108
- localState: undefined,
109
- rootState: props.builderContextSignal.rootState,
110
- rootSetState: props.builderContextSignal.rootSetState,
111
- });
112
- }
113
- }
114
-
115
- function onClick(event) {
116
- if (props.builderContextSignal.content) {
117
- const variationId = props.builderContextSignal.content?.testVariationId;
118
- const contentId = props.builderContextSignal.content?.id;
119
- _track({
120
- type: "click",
121
- canTrack: canTrackToUse(),
122
- contentId,
123
- apiKey: props.apiKey,
124
- variationId: variationId !== contentId ? variationId : undefined,
125
- ...getInteractionPropertiesForEvent(event),
126
- unique: !clicked(),
127
- });
128
- }
129
- if (!clicked()) {
130
- setClicked(true);
131
- }
132
- }
133
-
134
- function evalExpression(expression) {
135
- return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
136
- evaluate({
137
- code: group,
138
- context: props.context || {},
139
- localState: undefined,
140
- rootState: props.builderContextSignal.rootState,
141
- rootSetState: props.builderContextSignal.rootSetState,
142
- })
143
- );
144
- }
145
-
146
- function handleRequest({ url, key }) {
147
- fetch(url)
148
- .then((response) => response.json())
149
- .then((json) => {
150
- const newState = {
151
- ...props.builderContextSignal.rootState,
152
- [key]: json,
153
- };
154
- props.builderContextSignal.rootSetState?.(newState);
155
- httpReqsData()[key] = true;
156
- })
157
- .catch((err) => {
158
- console.error("error fetching dynamic data", url, err);
159
- });
160
- }
161
-
162
- function runHttpRequests() {
163
- const requests =
164
- props.builderContextSignal.content?.data?.httpRequests ?? {};
165
- Object.entries(requests).forEach(([key, url]) => {
166
- if (url && (!httpReqsData()[key] || isEditing())) {
167
- const evaluatedUrl = evalExpression(url);
168
- handleRequest({
169
- url: evaluatedUrl,
170
- key,
171
- });
172
- }
173
- });
174
- }
175
-
176
- function emitStateUpdate() {
177
- if (isEditing()) {
178
- window.dispatchEvent(
179
- new CustomEvent("builder:component:stateChange", {
180
- detail: {
181
- state: fastClone(props.builderContextSignal.rootState),
182
- ref: {
183
- name: props.model,
184
- },
185
- },
186
- })
187
- );
188
- }
189
- }
190
-
191
- let elementRef;
192
-
193
- onMount(() => {
194
- if (!props.apiKey) {
195
- logger.error(
196
- "No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
197
- );
198
- }
199
- if (isBrowser()) {
200
- if (isEditing()) {
201
- setForceReRenderCount(forceReRenderCount() + 1);
202
- window.addEventListener("message", processMessage);
203
- registerInsertMenu();
204
- setupBrowserForEditing({
205
- ...(props.locale
206
- ? {
207
- locale: props.locale,
208
- }
209
- : {}),
210
- ...(props.includeRefs
211
- ? {
212
- includeRefs: props.includeRefs,
213
- }
214
- : {}),
215
- ...(props.enrich
216
- ? {
217
- enrich: props.enrich,
218
- }
219
- : {}),
220
- });
221
- Object.values(props.builderContextSignal.componentInfos).forEach(
222
- (registeredComponent) => {
223
- const message = createRegisterComponentMessage(registeredComponent);
224
- window.parent?.postMessage(message, "*");
225
- }
226
- );
227
- window.addEventListener(
228
- "builder:component:stateChangeListenerActivated",
229
- emitStateUpdate
230
- );
231
- }
232
- if (props.builderContextSignal.content) {
233
- const variationId = props.builderContextSignal.content?.testVariationId;
234
- const contentId = props.builderContextSignal.content?.id;
235
- _track({
236
- type: "impression",
237
- canTrack: canTrackToUse(),
238
- contentId,
239
- apiKey: props.apiKey,
240
- variationId: variationId !== contentId ? variationId : undefined,
241
- });
242
- }
243
- // override normal content in preview mode
244
- if (isPreviewing()) {
245
- const searchParams = new URL(location.href).searchParams;
246
- const searchParamPreviewModel = searchParams.get("builder.preview");
247
- const searchParamPreviewId = searchParams.get(
248
- `builder.preview.${searchParamPreviewModel}`
249
- );
250
- const previewApiKey =
251
- searchParams.get("apiKey") || searchParams.get("builder.space");
252
-
253
- /**
254
- * Make sure that:
255
- * - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
256
- * at the same time, e.g. header/page/footer.
257
- * - the API key is the same, since we don't want to preview content from other organizations.
258
- * - if there is content, that the preview ID is the same as that of the one we receive.
259
- *
260
- * TO-DO: should we only update the state when there is a change?
261
- **/
262
- if (
263
- searchParamPreviewModel === props.model &&
264
- previewApiKey === props.apiKey &&
265
- (!props.content || searchParamPreviewId === props.content.id)
266
- ) {
267
- fetchOneEntry({
268
- model: props.model,
269
- apiKey: props.apiKey,
270
- apiVersion: props.builderContextSignal.apiVersion,
271
- }).then((content) => {
272
- if (content) {
273
- mergeNewContent(content);
274
- }
275
- });
276
- }
277
- }
278
- evaluateJsCode();
279
- runHttpRequests();
280
- emitStateUpdate();
281
- }
282
- });
283
-
284
- function onUpdateFn_0() {
285
- if (props.content) {
286
- mergeNewContent(props.content);
287
- }
288
- }
289
- createEffect(on(() => [props.content], onUpdateFn_0));
290
-
291
- function onUpdateFn_1() {}
292
- createEffect(on(() => [shouldSendResetCookie()], onUpdateFn_1));
293
-
294
- function onUpdateFn_2() {
295
- evaluateJsCode();
296
- }
297
- createEffect(
298
- on(
299
- () => [
300
- props.builderContextSignal.content?.data?.jsCode,
301
- props.builderContextSignal.rootState,
302
- ],
303
- onUpdateFn_2
304
- )
305
- );
306
-
307
- function onUpdateFn_3() {
308
- runHttpRequests();
309
- }
310
- createEffect(
311
- on(
312
- () => [props.builderContextSignal.content?.data?.httpRequests],
313
- onUpdateFn_3
314
- )
315
- );
316
-
317
- function onUpdateFn_4() {
318
- emitStateUpdate();
319
- }
320
- createEffect(on(() => [props.builderContextSignal.rootState], onUpdateFn_4));
321
-
322
- return (
323
- <builderContext.Provider value={props.builderContextSignal}>
324
- <Show when={props.builderContextSignal.content}>
325
- <div
326
- class={props.classNameProp}
327
- key={forceReRenderCount()}
328
- ref={elementRef}
329
- onClick={(event) => onClick(event)}
330
- builder-content-id={props.builderContextSignal.content?.id}
331
- builder-model={props.model}
332
- {...{}}
333
- {...(props.showContent
334
- ? {}
335
- : {
336
- hidden: true,
337
- "aria-hidden": true,
338
- })}
339
- >
340
- {props.children}
341
- </div>
342
- </Show>
343
- </builderContext.Provider>
344
- );
345
- }
346
-
347
- export default EnableEditor;
@@ -1,56 +0,0 @@
1
- const getCssFromFont = font => {
2
- var _a, _b;
3
- const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
4
- const name = family.split(",")[0];
5
- const url = (_b = font.fileUrl) != null ? _b : (_a = font == null ? void 0 : font.files) == null ? void 0 : _a.regular;
6
- let str = "";
7
- if (url && family && name) {
8
- str += `
9
- @font-face {
10
- font-family: "${family}";
11
- src: local("${name}"), url('${url}') format('woff2');
12
- font-display: fallback;
13
- font-weight: 400;
14
- }
15
- `.trim();
16
- }
17
- if (font.files) {
18
- for (const weight in font.files) {
19
- const isNumber = String(Number(weight)) === weight;
20
- if (!isNumber) {
21
- continue;
22
- }
23
- const weightUrl = font.files[weight];
24
- if (weightUrl && weightUrl !== url) {
25
- str += `
26
- @font-face {
27
- font-family: "${family}";
28
- src: url('${weightUrl}') format('woff2');
29
- font-display: fallback;
30
- font-weight: ${weight};
31
- }
32
- `.trim();
33
- }
34
- }
35
- }
36
- return str;
37
- };
38
- const getFontCss = ({
39
- customFonts
40
- }) => {
41
- var _a;
42
- return ((_a = customFonts == null ? void 0 : customFonts.map(font => getCssFromFont(font))) == null ? void 0 : _a.join(" ")) || "";
43
- };
44
- const getCss = ({
45
- cssCode,
46
- contentId
47
- }) => {
48
- if (!cssCode) {
49
- return "";
50
- }
51
- if (!contentId) {
52
- return cssCode;
53
- }
54
- return (cssCode == null ? void 0 : cssCode.replace(/&/g, `div[builder-content-id="${contentId}"]`)) || "";
55
- };
56
- export { getCss, getFontCss }
@@ -1,36 +0,0 @@
1
- import { createSignal } from "solid-js";
2
-
3
- import InlinedStyles from "../../inlined-styles";
4
- import { getCss } from "./styles.helpers.js";
5
- import { getFontCss } from "./styles.helpers.js";
6
-
7
- function ContentStyles(props) {
8
- const [injectedStyles, setInjectedStyles] = createSignal(
9
- `
10
- ${getCss({
11
- cssCode: props.cssCode,
12
- contentId: props.contentId,
13
- })}
14
- ${getFontCss({
15
- customFonts: props.customFonts,
16
- })}
17
-
18
- .builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
19
- margin: 0;
20
- }
21
- .builder-text > p, .builder-text > .builder-paragraph {
22
- color: inherit;
23
- line-height: inherit;
24
- letter-spacing: inherit;
25
- font-weight: inherit;
26
- font-size: inherit;
27
- text-align: inherit;
28
- font-family: inherit;
29
- }
30
- `.trim()
31
- );
32
-
33
- return <InlinedStyles styles={injectedStyles()}></InlinedStyles>;
34
- }
35
-
36
- export default ContentStyles;
@@ -1,48 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defProps = Object.defineProperties;
3
- var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
4
- var __getOwnPropSymbols = Object.getOwnPropertySymbols;
5
- var __hasOwnProp = Object.prototype.hasOwnProperty;
6
- var __propIsEnum = Object.prototype.propertyIsEnumerable;
7
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {
8
- enumerable: true,
9
- configurable: true,
10
- writable: true,
11
- value
12
- }) : obj[key] = value;
13
- var __spreadValues = (a, b) => {
14
- for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
- if (__getOwnPropSymbols) for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
17
- }
18
- return a;
19
- };
20
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21
- const getContextStateInitialValue = ({
22
- content,
23
- data,
24
- locale
25
- }) => {
26
- var _a, _b, _c;
27
- const defaultValues = {};
28
- (_b = (_a = content == null ? void 0 : content.data) == null ? void 0 : _a.inputs) == null ? void 0 : _b.forEach(input => {
29
- var _a2;
30
- if (input.name && input.defaultValue !== void 0 && ((_a2 = content == null ? void 0 : content.data) == null ? void 0 : _a2.state) && content.data.state[input.name] === void 0) {
31
- defaultValues[input.name] = input.defaultValue;
32
- }
33
- });
34
- const stateToUse = __spreadValues(__spreadValues(__spreadValues({}, (_c = content == null ? void 0 : content.data) == null ? void 0 : _c.state), data), locale ? {
35
- locale
36
- } : {});
37
- return __spreadValues(__spreadValues({}, defaultValues), stateToUse);
38
- };
39
- const getContentInitialValue = ({
40
- content,
41
- data
42
- }) => {
43
- return !content ? void 0 : __spreadProps(__spreadValues({}, content), {
44
- data: __spreadValues(__spreadValues({}, content == null ? void 0 : content.data), data),
45
- meta: content == null ? void 0 : content.meta
46
- });
47
- };
48
- export { getContentInitialValue, getContextStateInitialValue }
@@ -1,136 +0,0 @@
1
- import { Show, createSignal } from "solid-js";
2
-
3
- import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
4
- import {
5
- components,
6
- serializeComponentInfo,
7
- } from "../../functions/register-component.js";
8
- import Blocks from "../blocks/blocks";
9
- import ContentStyles from "./components/styles";
10
- import {
11
- getContentInitialValue,
12
- getContextStateInitialValue,
13
- } from "./content.helpers.js";
14
- import { TARGET } from "../../constants/target.js";
15
- import { getRenderContentScriptString } from "../content-variants/helpers.js";
16
- import EnableEditor from "./components/enable-editor";
17
- import InlinedScript from "../inlined-script";
18
- import { wrapComponentRef } from "./wrap-component-ref.js";
19
- import ComponentsContext from "../../context/components.context.js";
20
-
21
- function ContentComponent(props) {
22
- const [scriptStr, setScriptStr] = createSignal(
23
- getRenderContentScriptString({
24
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
25
- variationId: props.content?.testVariationId,
26
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
27
- contentId: props.content?.id,
28
- })
29
- );
30
-
31
- const [registeredComponents, setRegisteredComponents] = createSignal(
32
- [
33
- ...getDefaultRegisteredComponents(),
34
- // While this `components` object is deprecated, we must maintain support for it.
35
- // Since users are able to override our default components, we need to make sure that we do not break such
36
- // existing usage.
37
- // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
38
- // which is the new standard way of providing custom components, and must therefore take precedence.
39
- ...components,
40
- ...(props.customComponents || []),
41
- ].reduce(
42
- (acc, { component, ...info }) => ({
43
- ...acc,
44
- [info.name]: {
45
- component: component,
46
- ...serializeComponentInfo(info),
47
- },
48
- }),
49
- {}
50
- )
51
- );
52
-
53
- const [builderContextSignal, setBuilderContextSignal] = createSignal({
54
- content: getContentInitialValue({
55
- content: props.content,
56
- data: props.data,
57
- }),
58
- localState: undefined,
59
- rootState: getContextStateInitialValue({
60
- content: props.content,
61
- data: props.data,
62
- locale: props.locale,
63
- }),
64
- rootSetState: contentSetState,
65
- context: props.context || {},
66
- apiKey: props.apiKey,
67
- apiVersion: props.apiVersion,
68
- componentInfos: [
69
- ...getDefaultRegisteredComponents(),
70
- // While this `components` object is deprecated, we must maintain support for it.
71
- // Since users are able to override our default components, we need to make sure that we do not break such
72
- // existing usage.
73
- // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
74
- // which is the new standard way of providing custom components, and must therefore take precedence.
75
- ...components,
76
- ...(props.customComponents || []),
77
- ].reduce(
78
- (acc, { component: _, ...info }) => ({
79
- ...acc,
80
- [info.name]: serializeComponentInfo(info),
81
- }),
82
- {}
83
- ),
84
- inheritedStyles: {},
85
- });
86
-
87
- function contentSetState(newRootState) {
88
- setBuilderContextSignal((PREVIOUS_VALUE) => ({
89
- ...PREVIOUS_VALUE,
90
- rootState: newRootState,
91
- }));
92
- }
93
-
94
- return (
95
- <ComponentsContext.Provider
96
- value={{
97
- registeredComponents: registeredComponents(),
98
- }}
99
- >
100
- <EnableEditor
101
- content={props.content}
102
- model={props.model}
103
- context={props.context}
104
- apiKey={props.apiKey}
105
- canTrack={props.canTrack}
106
- locale={props.locale}
107
- includeRefs={props.includeRefs}
108
- enrich={props.enrich}
109
- classNameProp={props.classNameProp}
110
- showContent={props.showContent}
111
- builderContextSignal={builderContextSignal()}
112
- {...{
113
- setBuilderContextSignal: setBuilderContextSignal,
114
- }}
115
- >
116
- <Show when={props.isSsrAbTest}>
117
- <InlinedScript scriptStr={scriptStr()}></InlinedScript>
118
- </Show>
119
- <Show when={TARGET !== "reactNative"}>
120
- <ContentStyles
121
- contentId={builderContextSignal().content?.id}
122
- cssCode={builderContextSignal().content?.data?.cssCode}
123
- customFonts={builderContextSignal().content?.data?.customFonts}
124
- ></ContentStyles>
125
- </Show>
126
- <Blocks
127
- blocks={builderContextSignal().content?.data?.blocks}
128
- context={builderContextSignal()}
129
- registeredComponents={registeredComponents()}
130
- ></Blocks>
131
- </EnableEditor>
132
- </ComponentsContext.Provider>
133
- );
134
- }
135
-
136
- export default ContentComponent;
File without changes
@@ -1,2 +0,0 @@
1
- import { default as default2 } from "./content";
2
- export { default2 as default }
@@ -1,2 +0,0 @@
1
- const wrapComponentRef = component => component;
2
- export { wrapComponentRef }