@builder.io/sdk-solid 0.4.1 → 0.4.3

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/CHANGELOG.md CHANGED
@@ -1,3 +1,10 @@
1
+ ### 0.4.3
2
+ - Fix: SSR A/B test environment check (`isHydrationTarget`) now accurately checks current environment.
3
+
4
+ ### 0.4.2
5
+
6
+ - No external changes.
7
+
1
8
  ### 0.4.1
2
9
 
3
10
  - Fix: bring back `getBuilderSearchParams` export that was accidentally removed.
@@ -5,6 +12,8 @@
5
12
  ### 0.4.0
6
13
 
7
14
  - Feature: A/B tests are now rendered correctly during server-side rendering (SSR) when applicable. This behaviour is backwards compatible with previous versions.
15
+ - Feature: Add support for `enrich` API flag.
16
+ - Mark `noTraverse` and `includeRefs` as deprecated.
8
17
 
9
18
  ### 0.3.1
10
19
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -7,7 +7,7 @@ const componentInfo = {
7
7
  name: "image",
8
8
  bubble: true,
9
9
  type: "file",
10
- allowedFileTypes: ["jpeg", "jpg", "png", "svg"],
10
+ allowedFileTypes: ["jpeg", "jpg", "png", "svg", "gif", "webp"],
11
11
  required: true
12
12
  }
13
13
  ],
@@ -27,6 +27,8 @@ function RenderBlock(props) {
27
27
 
28
28
  const [Tag, setTag] = createSignal(props.block.tagName || "div");
29
29
 
30
+ const [childrenContext, setChildrenContext] = createSignal(props.context);
31
+
30
32
  function repeatItem() {
31
33
  return getRepeatItemData({
32
34
  block: props.block,
@@ -95,32 +97,6 @@ function RenderBlock(props) {
95
97
  return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
96
98
  }
97
99
 
98
- function childrenContext() {
99
- const getInheritedTextStyles = () => {
100
- if (TARGET !== "reactNative") {
101
- return {};
102
- }
103
- return extractTextStyles(
104
- getReactNativeBlockStyles({
105
- block: useBlock(),
106
- context: props.context,
107
- blockStyles: attributes().style,
108
- })
109
- );
110
- };
111
- return {
112
- apiKey: props.context.apiKey,
113
- apiVersion: props.context.apiVersion,
114
- localState: props.context.localState,
115
- rootState: props.context.rootState,
116
- rootSetState: props.context.rootSetState,
117
- content: props.context.content,
118
- context: props.context.context,
119
- registeredComponents: props.context.registeredComponents,
120
- inheritedStyles: getInheritedTextStyles(),
121
- };
122
- }
123
-
124
100
  function renderComponentProps() {
125
101
  return {
126
102
  blockChildren: useBlock().children ?? [],
@@ -1,25 +1,14 @@
1
+ import { createSignal } from "solid-js";
2
+
1
3
  import BuilderContext from "../../context/builder.context.js";
2
4
  import RenderBlock from "./render-block.jsx";
3
5
 
4
6
  function RenderRepeatedBlock(props) {
7
+ const [store, setStore] = createSignal(props.repeatContext);
8
+
5
9
  return (
6
- <BuilderContext.Provider
7
- value={{
8
- content: props.repeatContext.content,
9
- localState: props.repeatContext.localState,
10
- rootState: props.repeatContext.rootState,
11
- rootSetState: props.repeatContext.rootSetState,
12
- context: props.repeatContext.context,
13
- apiKey: props.repeatContext.apiKey,
14
- registeredComponents: props.repeatContext.registeredComponents,
15
- inheritedStyles: props.repeatContext.inheritedStyles,
16
- apiVersion: props.repeatContext.apiVersion,
17
- }}
18
- >
19
- <RenderBlock
20
- block={props.block}
21
- context={props.repeatContext}
22
- ></RenderBlock>
10
+ <BuilderContext.Provider value={store()}>
11
+ <RenderBlock block={props.block} context={store()}></RenderBlock>
23
12
  </BuilderContext.Provider>
24
13
  );
25
14
  }
@@ -63,6 +63,7 @@ function RenderBlocks(props) {
63
63
  style={props.styleProp}
64
64
  onClick={(event) => onClick()}
65
65
  onMouseEnter={(event) => onMouseEnter()}
66
+ onKeyPress={(event) => onClick()}
66
67
  >
67
68
  <Show when={props.blocks}>
68
69
  <For each={props.blocks}>
@@ -1,7 +1,5 @@
1
1
  import { Show, onMount, on, createEffect, createSignal } from "solid-js";
2
2
 
3
- import { createStore, reconcile } from "solid-js/store";
4
-
5
3
  import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
6
4
  import { evaluate } from "../../functions/evaluate.js";
7
5
  import { getContent } from "../../functions/get-content/index.js";
@@ -43,16 +41,34 @@ function RenderContent(props) {
43
41
  checkIsDefined(props.canTrack) ? props.canTrack : true
44
42
  );
45
43
 
46
- const [contentState, setContentState] = createSignal(
47
- getContextStateInitialValue({
48
- content: props.content,
49
- data: props.data,
50
- locale: props.locale,
44
+ const [httpReqsData, setHttpReqsData] = createSignal({});
45
+
46
+ const [clicked, setClicked] = createSignal(false);
47
+
48
+ const [scriptStr, setScriptStr] = createSignal(
49
+ getRenderContentScriptString({
50
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
51
+ contentId: props.content?.id,
52
+ parentContentId: props.parentContentId,
51
53
  })
52
54
  );
53
55
 
54
- const [allRegisteredComponents, setAllRegisteredComponents] = createSignal(
55
- [
56
+ const [builderContextSignal, setBuilderContextSignal] = createSignal({
57
+ content: getContentInitialValue({
58
+ content: props.content,
59
+ data: props.data,
60
+ }),
61
+ localState: undefined,
62
+ rootState: getContextStateInitialValue({
63
+ content: props.content,
64
+ data: props.data,
65
+ locale: props.locale,
66
+ }),
67
+ rootSetState: contentSetState,
68
+ context: props.context || {},
69
+ apiKey: props.apiKey,
70
+ apiVersion: props.apiVersion,
71
+ registeredComponents: [
56
72
  ...getDefaultRegisteredComponents(),
57
73
  // While this `components` object is deprecated, we must maintain support for it.
58
74
  // Since users are able to override our default components, we need to make sure that we do not break such
@@ -71,50 +87,49 @@ function RenderContent(props) {
71
87
  },
72
88
  }),
73
89
  {}
74
- )
75
- );
76
-
77
- const [httpReqsData, setHttpReqsData] = createSignal({});
78
-
79
- const [clicked, setClicked] = createSignal(false);
80
-
81
- const [scriptStr, setScriptStr] = createSignal(
82
- getRenderContentScriptString({
83
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion, @typescript-eslint/no-non-null-asserted-optional-chain
84
- contentId: props.content?.id,
85
- parentContentId: props.parentContentId,
86
- })
87
- );
90
+ ),
91
+ inheritedStyles: {},
92
+ });
88
93
 
89
94
  function mergeNewContent(newContent) {
90
- setUseContent({
91
- ...useContent,
92
- ...newContent,
93
- data: {
94
- ...useContent?.data,
95
- ...newContent?.data,
96
- },
97
- meta: {
98
- ...useContent?.meta,
99
- ...newContent?.meta,
100
- breakpoints:
101
- newContent?.meta?.breakpoints || useContent?.meta?.breakpoints,
95
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
96
+ ...PREVIOUS_VALUE,
97
+ content: {
98
+ ...builderContextSignal().content,
99
+ ...newContent,
100
+ data: {
101
+ ...builderContextSignal().content?.data,
102
+ ...newContent?.data,
103
+ },
104
+ meta: {
105
+ ...builderContextSignal().content?.meta,
106
+ ...newContent?.meta,
107
+ breakpoints:
108
+ newContent?.meta?.breakpoints ||
109
+ builderContextSignal().content?.meta?.breakpoints,
110
+ },
102
111
  },
103
- });
112
+ }));
104
113
  }
105
114
 
106
115
  function setBreakpoints(breakpoints) {
107
- setUseContent({
108
- ...useContent,
109
- meta: {
110
- ...useContent?.meta,
111
- breakpoints,
116
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
117
+ ...PREVIOUS_VALUE,
118
+ content: {
119
+ ...builderContextSignal().content,
120
+ meta: {
121
+ ...builderContextSignal().content?.meta,
122
+ breakpoints,
123
+ },
112
124
  },
113
- });
125
+ }));
114
126
  }
115
127
 
116
128
  function contentSetState(newRootState) {
117
- setContentState(newRootState);
129
+ setBuilderContextSignal((PREVIOUS_VALUE) => ({
130
+ ...PREVIOUS_VALUE,
131
+ rootState: newRootState,
132
+ }));
118
133
  }
119
134
 
120
135
  function processMessage(event) {
@@ -124,7 +139,7 @@ function RenderContent(props) {
124
139
  case "builder.configureSdk": {
125
140
  const messageContent = data.data;
126
141
  const { breakpoints, contentId } = messageContent;
127
- if (!contentId || contentId !== useContent?.id) {
142
+ if (!contentId || contentId !== builderContextSignal().content?.id) {
128
143
  return;
129
144
  }
130
145
  if (breakpoints) {
@@ -158,22 +173,22 @@ function RenderContent(props) {
158
173
 
159
174
  function evaluateJsCode() {
160
175
  // run any dynamic JS code attached to content
161
- const jsCode = useContent?.data?.jsCode;
176
+ const jsCode = builderContextSignal().content?.data?.jsCode;
162
177
  if (jsCode) {
163
178
  evaluate({
164
179
  code: jsCode,
165
180
  context: props.context || {},
166
181
  localState: undefined,
167
- rootState: contentState(),
182
+ rootState: builderContextSignal().rootState,
168
183
  rootSetState: contentSetState,
169
184
  });
170
185
  }
171
186
  }
172
187
 
173
188
  function onClick(event) {
174
- if (useContent) {
175
- const variationId = useContent?.testVariationId;
176
- const contentId = useContent?.id;
189
+ if (builderContextSignal().content) {
190
+ const variationId = builderContextSignal().content?.testVariationId;
191
+ const contentId = builderContextSignal().content?.id;
177
192
  _track({
178
193
  type: "click",
179
194
  canTrack: canTrackToUse(),
@@ -195,7 +210,7 @@ function RenderContent(props) {
195
210
  code: group,
196
211
  context: props.context || {},
197
212
  localState: undefined,
198
- rootState: contentState(),
213
+ rootState: builderContextSignal().rootState,
199
214
  rootSetState: contentSetState,
200
215
  })
201
216
  );
@@ -206,7 +221,7 @@ function RenderContent(props) {
206
221
  .then((response) => response.json())
207
222
  .then((json) => {
208
223
  const newState = {
209
- ...contentState(),
224
+ ...builderContextSignal().rootState,
210
225
  [key]: json,
211
226
  };
212
227
  contentSetState(newState);
@@ -217,7 +232,7 @@ function RenderContent(props) {
217
232
  }
218
233
 
219
234
  function runHttpRequests() {
220
- const requests = useContent?.data?.httpRequests ?? {};
235
+ const requests = builderContextSignal().content?.data?.httpRequests ?? {};
221
236
  Object.entries(requests).forEach(([key, url]) => {
222
237
  if (url && (!httpReqsData()[key] || isEditing())) {
223
238
  const evaluatedUrl = evalExpression(url);
@@ -234,7 +249,7 @@ function RenderContent(props) {
234
249
  window.dispatchEvent(
235
250
  new CustomEvent("builder:component:stateChange", {
236
251
  detail: {
237
- state: contentState(),
252
+ state: builderContextSignal().rootState,
238
253
  ref: {
239
254
  name: props.model,
240
255
  },
@@ -243,12 +258,6 @@ function RenderContent(props) {
243
258
  );
244
259
  }
245
260
  }
246
- const [useContent, setUseContent] = createStore(
247
- getContentInitialValue({
248
- content: props.content,
249
- data: props.data,
250
- })
251
- );
252
261
 
253
262
  let elementRef;
254
263
 
@@ -279,7 +288,7 @@ function RenderContent(props) {
279
288
  }
280
289
  : {}),
281
290
  });
282
- Object.values(allRegisteredComponents()).forEach(
291
+ Object.values(builderContextSignal().registeredComponents).forEach(
283
292
  (registeredComponent) => {
284
293
  const message = createRegisterComponentMessage(registeredComponent);
285
294
  window.parent?.postMessage(message, "*");
@@ -291,9 +300,9 @@ function RenderContent(props) {
291
300
  emitStateUpdate
292
301
  );
293
302
  }
294
- if (useContent) {
295
- const variationId = useContent?.testVariationId;
296
- const contentId = useContent?.id;
303
+ if (builderContextSignal().content) {
304
+ const variationId = builderContextSignal().content?.testVariationId;
305
+ const contentId = builderContextSignal().content?.id;
297
306
  _track({
298
307
  type: "impression",
299
308
  canTrack: canTrackToUse(),
@@ -355,39 +364,35 @@ function RenderContent(props) {
355
364
  evaluateJsCode();
356
365
  }
357
366
  createEffect(
358
- on(() => [useContent?.data?.jsCode, contentState()], onUpdateFn_1)
367
+ on(
368
+ () => [
369
+ builderContextSignal().content?.data?.jsCode,
370
+ builderContextSignal().rootState,
371
+ ],
372
+ onUpdateFn_1
373
+ )
359
374
  );
360
375
 
361
376
  function onUpdateFn_2() {
362
377
  runHttpRequests();
363
378
  }
364
- createEffect(on(() => [useContent?.data?.httpRequests], onUpdateFn_2));
379
+ createEffect(
380
+ on(() => [builderContextSignal().content?.data?.httpRequests], onUpdateFn_2)
381
+ );
365
382
 
366
383
  function onUpdateFn_3() {
367
384
  emitStateUpdate();
368
385
  }
369
- createEffect(on(() => [contentState()], onUpdateFn_3));
386
+ createEffect(on(() => [builderContextSignal().rootState], onUpdateFn_3));
370
387
 
371
388
  return (
372
- <builderContext.Provider
373
- value={{
374
- content: useContent,
375
- localState: undefined,
376
- rootState: contentState(),
377
- rootSetState: TARGET === "qwik" ? undefined : contentSetState,
378
- context: props.context || {},
379
- apiKey: props.apiKey,
380
- apiVersion: props.apiVersion,
381
- registeredComponents: allRegisteredComponents(),
382
- inheritedStyles: {},
383
- }}
384
- >
385
- <Show when={useContent}>
389
+ <builderContext.Provider value={builderContextSignal()}>
390
+ <Show when={builderContextSignal().content}>
386
391
  <div
387
392
  class={props.classNameProp}
388
393
  ref={elementRef}
389
394
  onClick={(event) => onClick(event)}
390
- builder-content-id={useContent?.id}
395
+ builder-content-id={builderContextSignal().content?.id}
391
396
  builder-model={props.model}
392
397
  {...(TARGET === "reactNative"
393
398
  ? {
@@ -410,13 +415,13 @@ function RenderContent(props) {
410
415
  </Show>
411
416
  <Show when={TARGET !== "reactNative"}>
412
417
  <RenderContentStyles
413
- contentId={useContent?.id}
414
- cssCode={useContent?.data?.cssCode}
415
- customFonts={useContent?.data?.customFonts}
418
+ contentId={builderContextSignal().content?.id}
419
+ cssCode={builderContextSignal().content?.data?.cssCode}
420
+ customFonts={builderContextSignal().content?.data?.customFonts}
416
421
  ></RenderContentStyles>
417
422
  </Show>
418
423
  <RenderBlocks
419
- blocks={useContent?.data?.blocks}
424
+ blocks={builderContextSignal().content?.data?.blocks}
420
425
  key={forceReRenderCount()}
421
426
  ></RenderBlocks>
422
427
  </div>
@@ -1,3 +1,4 @@
1
+ import { TARGET } from "../../constants/target";
1
2
  import { isBrowser } from "../../functions/is-browser";
2
3
  const getVariants = (content) => Object.values((content == null ? void 0 : content.variations) || {});
3
4
  const checkShouldRunVariants = ({
@@ -112,7 +113,8 @@ function bldrCntntScrpt(variantContentId, defaultContentId, isHydrationTarget2)
112
113
  }
113
114
  return;
114
115
  }
115
- const isHydrationTarget = (target) => target === "react" || target === "reactNative" || target === "vue3" || target === "vue2";
116
+ const getIsHydrationTarget = (target) => target === "react" || target === "reactNative" || target === "vue3" || target === "vue2";
117
+ const isHydrationTarget = getIsHydrationTarget(TARGET);
116
118
  const AB_TEST_FN_NAME = "bldrAbTest";
117
119
  const CONTENT_FN_NAME = "bldrCntntScrpt";
118
120
  const getVariantsScriptString = (variants, contentId) => {
@@ -1 +1 @@
1
- export const SDK_VERSION = "0.4.1"
1
+ export const SDK_VERSION = "0.4.3"