@builder.io/sdk-solid 0.0.2 → 0.0.5

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 CHANGED
@@ -1,10 +1,15 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.2",
3
+ "version": "0.0.5",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "dependencies": {
7
- "solid-js": "^1.3.15",
8
7
  "solid-styled-components": "^0.27.6"
8
+ },
9
+ "peerDependencies": {
10
+ "solid-js": "^1.3.15"
11
+ },
12
+ "devDependencies": {
13
+ "solid-js": "^1.3.15"
9
14
  }
10
15
  }
@@ -1,5 +1,4 @@
1
1
  import { template as _$template } from "solid-js/web";
2
- import { createComponent as _$createComponent } from "solid-js/web";
3
2
  import { setAttribute as _$setAttribute } from "solid-js/web";
4
3
  import { effect as _$effect } from "solid-js/web";
5
4
  import { insert as _$insert } from "solid-js/web";
@@ -7,35 +6,27 @@ import { spread as _$spread } from "solid-js/web";
7
6
 
8
7
  const _tmpl$ = /*#__PURE__*/_$template(`<a role="button"></a>`, 2);
9
8
 
10
- import { Show } from "solid-js";
11
9
  export default function Button(props) {
12
- return _$createComponent(Show, {
13
- get when() {
14
- return props.link;
15
- },
10
+ return (() => {
11
+ const _el$ = _tmpl$.cloneNode(true);
16
12
 
17
- get children() {
18
- const _el$ = _tmpl$.cloneNode(true);
13
+ _$spread(_el$, () => props.attributes, false, true);
19
14
 
20
- _$spread(_el$, () => props.attributes, false, true);
15
+ _$insert(_el$, () => props.text);
21
16
 
22
- _$insert(_el$, () => props.text);
17
+ _$effect(_p$ => {
18
+ const _v$ = props.link,
19
+ _v$2 = props.openLinkInNewTab ? "_blank" : undefined;
23
20
 
24
- _$effect(_p$ => {
25
- const _v$ = props.link,
26
- _v$2 = props.openLinkInNewTab ? "_blank" : undefined;
21
+ _v$ !== _p$._v$ && _$setAttribute(_el$, "href", _p$._v$ = _v$);
22
+ _v$2 !== _p$._v$2 && _$setAttribute(_el$, "target", _p$._v$2 = _v$2);
23
+ return _p$;
24
+ }, {
25
+ _v$: undefined,
26
+ _v$2: undefined
27
+ });
27
28
 
28
- _v$ !== _p$._v$ && _$setAttribute(_el$, "href", _p$._v$ = _v$);
29
- _v$2 !== _p$._v$2 && _$setAttribute(_el$, "target", _p$._v$2 = _v$2);
30
- return _p$;
31
- }, {
32
- _v$: undefined,
33
- _v$2: undefined
34
- });
35
-
36
- return _el$;
37
- }
38
-
39
- });
29
+ return _el$;
30
+ })();
40
31
  }import { registerComponent } from '../functions/register-component';
41
32
  registerComponent(Button, {name:'Core:Button',builtIn:true,image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F81a15681c3e74df09677dfc57a615b13',defaultStyles:{appearance:'none',paddingTop:'15px',paddingBottom:'15px',paddingLeft:'25px',paddingRight:'25px',backgroundColor:'#000000',color:'white',borderRadius:'4px',textAlign:'center',cursor:'pointer'},inputs:[{name:'text',type:'text',defaultValue:'Click me!',bubble:true},{name:'link',type:'url',bubble:true},{name:'openLinkInNewTab',type:'boolean',defaultValue:false,friendlyName:'Open link in new tab'}],static:true,noWrap:true});
@@ -1,18 +1,12 @@
1
- import { Show } from "solid-js";
2
-
3
1
  export default function Button(props) {
4
2
  return (
5
- <>
6
- <Show when={props.link}>
7
- <a
8
- {...props.attributes}
9
- role="button"
10
- href={props.link}
11
- target={props.openLinkInNewTab ? "_blank" : undefined}
12
- >
13
- {props.text}
14
- </a>
15
- </Show>
16
- </>
3
+ <a
4
+ {...props.attributes}
5
+ role="button"
6
+ href={props.link}
7
+ target={props.openLinkInNewTab ? "_blank" : undefined}
8
+ >
9
+ {props.text}
10
+ </a>
17
11
  );
18
12
  }
@@ -89,7 +89,7 @@ export default function Columns(props) {
89
89
  }),
90
90
  _v$4 = {
91
91
  width: state.getColumnCssWidth(index),
92
- marginLeft: `${index === 0 ? 0 : state.getGutterSize()}px`,
92
+ "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
93
93
  ...state.columnCssVars
94
94
  };
95
95
 
@@ -83,7 +83,7 @@ export default function Columns(props) {
83
83
  })}
84
84
  style={{
85
85
  width: state.getColumnCssWidth(index),
86
- marginLeft: `${index === 0 ? 0 : state.getGutterSize()}px`,
86
+ "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
87
87
  ...state.columnCssVars,
88
88
  }}
89
89
  >
@@ -231,7 +231,7 @@ export default function FormComponent(props) {
231
231
  return (() => {
232
232
  const _el$ = _tmpl$2.cloneNode(true);
233
233
 
234
- _el$.addEventListener("submit", event => state.state.onSubmit(event));
234
+ _el$.addEventListener("submit", event => state.onSubmit(event));
235
235
 
236
236
  formRef(_el$);
237
237
 
@@ -258,7 +258,7 @@ export default function FormComponent(props) {
258
258
 
259
259
  _$insert(_el$, _$createComponent(Show, {
260
260
  get when() {
261
- return state.state.submissionState === "error";
261
+ return state.submissionState === "error";
262
262
  },
263
263
 
264
264
  get children() {
@@ -276,7 +276,7 @@ export default function FormComponent(props) {
276
276
 
277
277
  _$insert(_el$, _$createComponent(Show, {
278
278
  get when() {
279
- return state.state.submissionState === "sending";
279
+ return state.submissionState === "sending";
280
280
  },
281
281
 
282
282
  get children() {
@@ -294,13 +294,13 @@ export default function FormComponent(props) {
294
294
 
295
295
  _$insert(_el$, _$createComponent(Show, {
296
296
  get when() {
297
- return state.state.submissionState === "error" && state.state.responseData;
297
+ return state.submissionState === "error" && state.responseData;
298
298
  },
299
299
 
300
300
  get children() {
301
301
  const _el$2 = _tmpl$.cloneNode(true);
302
302
 
303
- _$insert(_el$2, () => JSON.stringify(state.state.responseData, null, 2));
303
+ _$insert(_el$2, () => JSON.stringify(state.responseData, null, 2));
304
304
 
305
305
  _$effect(() => _el$2.className = css({
306
306
  padding: "10px",
@@ -315,7 +315,7 @@ export default function FormComponent(props) {
315
315
 
316
316
  _$insert(_el$, _$createComponent(Show, {
317
317
  get when() {
318
- return state.state.submissionState === "success";
318
+ return state.submissionState === "success";
319
319
  },
320
320
 
321
321
  get children() {
@@ -246,30 +246,26 @@ export default function FormComponent(props) {
246
246
  action={!props.sendWithJs && props.action}
247
247
  method={props.method}
248
248
  name={props.name}
249
- onSubmit={(event) => state.state.onSubmit(event)}
249
+ onSubmit={(event) => state.onSubmit(event)}
250
250
  >
251
251
  <Show when={props.builderBlock && props.builderBlock.children}>
252
252
  <For each={props.builderBlock?.children}>
253
253
  {(block, index) => <RenderBlock block={block}></RenderBlock>}
254
254
  </For>
255
255
  </Show>
256
- <Show when={state.state.submissionState === "error"}>
256
+ <Show when={state.submissionState === "error"}>
257
257
  <BuilderBlocks
258
258
  dataPath="errorMessage"
259
259
  blocks={props.errorMessage}
260
260
  ></BuilderBlocks>
261
261
  </Show>
262
- <Show when={state.state.submissionState === "sending"}>
262
+ <Show when={state.submissionState === "sending"}>
263
263
  <BuilderBlocks
264
264
  dataPath="sendingMessage"
265
265
  blocks={props.sendingMessage}
266
266
  ></BuilderBlocks>
267
267
  </Show>
268
- <Show
269
- when={
270
- state.state.submissionState === "error" && state.state.responseData
271
- }
272
- >
268
+ <Show when={state.submissionState === "error" && state.responseData}>
273
269
  <pre
274
270
  class={css({
275
271
  padding: "10px",
@@ -277,10 +273,10 @@ export default function FormComponent(props) {
277
273
  textAlign: "center",
278
274
  })}
279
275
  >
280
- {JSON.stringify(state.state.responseData, null, 2)}
276
+ {JSON.stringify(state.responseData, null, 2)}
281
277
  </pre>
282
278
  </Show>
283
- <Show when={state.state.submissionState === "success"}>
279
+ <Show when={state.submissionState === "success"}>
284
280
  <BuilderBlocks
285
281
  dataPath="successMessage"
286
282
  blocks={props.successMessage}
@@ -1,22 +1,100 @@
1
1
  import { template as _$template } from "solid-js/web";
2
- import { setAttribute as _$setAttribute } from "solid-js/web";
3
2
  import { insert as _$insert } from "solid-js/web";
4
3
  import { createComponent as _$createComponent } from "solid-js/web";
4
+ import { setAttribute as _$setAttribute } from "solid-js/web";
5
5
  import { effect as _$effect } from "solid-js/web";
6
6
  import { memo as _$memo } from "solid-js/web";
7
7
 
8
- const _tmpl$ = /*#__PURE__*/_$template(`<div> </div>`, 2),
9
- _tmpl$2 = /*#__PURE__*/_$template(`<div></div>`, 2),
10
- _tmpl$3 = /*#__PURE__*/_$template(`<div><picture><img loading="lazy"><source></picture></div>`, 6);
8
+ const _tmpl$ = /*#__PURE__*/_$template(`<source type="image/webp">`, 1),
9
+ _tmpl$2 = /*#__PURE__*/_$template(`<div> </div>`, 2),
10
+ _tmpl$3 = /*#__PURE__*/_$template(`<div></div>`, 2),
11
+ _tmpl$4 = /*#__PURE__*/_$template(`<div><picture><img loading="lazy"></picture></div>`, 5);
11
12
 
12
13
  import { Show } from "solid-js";
14
+ import { createMutable } from "solid-js/store";
13
15
  import { css } from "solid-styled-components";
14
16
  export default function Image(props) {
17
+ const state = createMutable({
18
+ updateQueryParam: function updateQueryParam(uri = "", key, value) {
19
+ const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
20
+ const separator = uri.indexOf("?") !== -1 ? "&" : "?";
21
+
22
+ if (uri.match(re)) {
23
+ return uri.replace(re, "$1" + key + "=" + encodeURIComponent(value) + "$2");
24
+ }
25
+
26
+ return uri + separator + key + "=" + encodeURIComponent(value);
27
+ },
28
+ removeProtocol: function removeProtocol(path) {
29
+ return path.replace(/http(s)?:/, "");
30
+ },
31
+ getShopifyImageUrl: function getShopifyImageUrl(src, size) {
32
+ if (!src || !src?.match(/cdn\.shopify\.com/) || !size) {
33
+ return src;
34
+ }
35
+
36
+ if (size === "master") {
37
+ return state.removeProtocol(src);
38
+ }
39
+
40
+ const match = src.match(/(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i);
41
+
42
+ if (match) {
43
+ const prefix = src.split(match[0]);
44
+ const suffix = match[3];
45
+ const useSize = size.match("x") ? size : `${size}x`;
46
+ return state.removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
47
+ }
48
+
49
+ return null;
50
+ },
51
+ getSrcSet: function getSrcSet(url) {
52
+ if (!url) {
53
+ return url;
54
+ }
55
+
56
+ const sizes = [100, 200, 400, 800, 1200, 1600, 2000];
57
+
58
+ if (url.match(/builder\.io/)) {
59
+ let srcUrl = url;
60
+ const widthInSrc = Number(url.split("?width=")[1]);
61
+
62
+ if (!isNaN(widthInSrc)) {
63
+ srcUrl = `${srcUrl} ${widthInSrc}w`;
64
+ }
65
+
66
+ return sizes.filter(size => size !== widthInSrc).map(size => `${state.updateQueryParam(url, "width", size)} ${size}w`).concat([srcUrl]).join(", ");
67
+ }
68
+
69
+ if (url.match(/cdn\.shopify\.com/)) {
70
+ return sizes.map(size => [state.getShopifyImageUrl(url, `${size}x${size}`), size]).filter(([sizeUrl]) => !!sizeUrl).map(([sizeUrl, size]) => `${sizeUrl} ${size}w`).concat([url]).join(", ");
71
+ }
72
+
73
+ return url;
74
+ },
75
+ useSrcSet: function useSrcSet() {
76
+ return props.srcset || state.getSrcSet(props.image) || "";
77
+ }
78
+ });
15
79
  return (() => {
16
- const _el$ = _tmpl$3.cloneNode(true),
80
+ const _el$ = _tmpl$4.cloneNode(true),
17
81
  _el$2 = _el$.firstChild,
18
- _el$3 = _el$2.firstChild,
19
- _el$4 = _el$3.nextSibling;
82
+ _el$3 = _el$2.firstChild;
83
+
84
+ _$insert(_el$2, _$createComponent(Show, {
85
+ get when() {
86
+ return _$memo(() => !!!props.noWebp, true)() && state.useSrcSet().includes("builder.io");
87
+ },
88
+
89
+ get children() {
90
+ const _el$4 = _tmpl$.cloneNode(true);
91
+
92
+ _$effect(() => _$setAttribute(_el$4, "srcset", state.useSrcSet().replace(/\?/g, "?format=webp&")));
93
+
94
+ return _el$4;
95
+ }
96
+
97
+ }), null);
20
98
 
21
99
  _$insert(_el$, _$createComponent(Show, {
22
100
  get when() {
@@ -24,7 +102,7 @@ export default function Image(props) {
24
102
  },
25
103
 
26
104
  get children() {
27
- const _el$5 = _tmpl$.cloneNode(true);
105
+ const _el$5 = _tmpl$2.cloneNode(true);
28
106
 
29
107
  _$effect(_p$ => {
30
108
  const _v$ = css({
@@ -35,7 +113,7 @@ export default function Image(props) {
35
113
  _v$2 = props.aspectRatio * 100 + "%";
36
114
 
37
115
  _v$ !== _p$._v$ && (_el$5.className = _p$._v$ = _v$);
38
- _v$2 !== _p$._v$2 && _el$5.style.setProperty("paddingTop", _p$._v$2 = _v$2);
116
+ _v$2 !== _p$._v$2 && _el$5.style.setProperty("padding-top", _p$._v$2 = _v$2);
39
117
  return _p$;
40
118
  }, {
41
119
  _v$: undefined,
@@ -64,7 +142,7 @@ export default function Image(props) {
64
142
  },
65
143
 
66
144
  get children() {
67
- const _el$6 = _tmpl$2.cloneNode(true);
145
+ const _el$6 = _tmpl$3.cloneNode(true);
68
146
 
69
147
  _$insert(_el$6, () => props.children);
70
148
 
@@ -102,20 +180,18 @@ export default function Image(props) {
102
180
  _v$7 = props.backgroundSize || "center",
103
181
  _v$8 = props.backgroundSize || "cover",
104
182
  _v$9 = props.image,
105
- _v$10 = props.srcset,
106
- _v$11 = props.sizes,
107
- _v$12 = props.srcset;
183
+ _v$10 = props.srcset || state.getSrcSet(props.image),
184
+ _v$11 = props.sizes;
108
185
 
109
186
  _v$3 !== _p$._v$3 && (_el$.className = _p$._v$3 = _v$3);
110
187
  _v$4 !== _p$._v$4 && (_el$3.className = _p$._v$4 = _v$4);
111
188
  _v$5 !== _p$._v$5 && _$setAttribute(_el$3, "alt", _p$._v$5 = _v$5);
112
189
  _v$6 !== _p$._v$6 && _$setAttribute(_el$3, "aria-role", _p$._v$6 = _v$6);
113
- _v$7 !== _p$._v$7 && _el$3.style.setProperty("objectPosition", _p$._v$7 = _v$7);
114
- _v$8 !== _p$._v$8 && _el$3.style.setProperty("objectFit", _p$._v$8 = _v$8);
190
+ _v$7 !== _p$._v$7 && _el$3.style.setProperty("object-position", _p$._v$7 = _v$7);
191
+ _v$8 !== _p$._v$8 && _el$3.style.setProperty("object-fit", _p$._v$8 = _v$8);
115
192
  _v$9 !== _p$._v$9 && _$setAttribute(_el$3, "src", _p$._v$9 = _v$9);
116
193
  _v$10 !== _p$._v$10 && _$setAttribute(_el$3, "srcset", _p$._v$10 = _v$10);
117
194
  _v$11 !== _p$._v$11 && _$setAttribute(_el$3, "sizes", _p$._v$11 = _v$11);
118
- _v$12 !== _p$._v$12 && _$setAttribute(_el$4, "srcset", _p$._v$12 = _v$12);
119
195
  return _p$;
120
196
  }, {
121
197
  _v$3: undefined,
@@ -126,8 +202,7 @@ export default function Image(props) {
126
202
  _v$8: undefined,
127
203
  _v$9: undefined,
128
204
  _v$10: undefined,
129
- _v$11: undefined,
130
- _v$12: undefined
205
+ _v$11: undefined
131
206
  });
132
207
 
133
208
  return _el$;
@@ -1,8 +1,91 @@
1
1
  import { Show } from "solid-js";
2
2
 
3
+ import { createMutable } from "solid-js/store";
3
4
  import { css } from "solid-styled-components";
4
5
 
5
6
  export default function Image(props) {
7
+ const state = createMutable({
8
+ updateQueryParam: function updateQueryParam(uri = "", key, value) {
9
+ const re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
10
+ const separator = uri.indexOf("?") !== -1 ? "&" : "?";
11
+
12
+ if (uri.match(re)) {
13
+ return uri.replace(
14
+ re,
15
+ "$1" + key + "=" + encodeURIComponent(value) + "$2"
16
+ );
17
+ }
18
+
19
+ return uri + separator + key + "=" + encodeURIComponent(value);
20
+ },
21
+ removeProtocol: function removeProtocol(path) {
22
+ return path.replace(/http(s)?:/, "");
23
+ },
24
+ getShopifyImageUrl: function getShopifyImageUrl(src, size) {
25
+ if (!src || !src?.match(/cdn\.shopify\.com/) || !size) {
26
+ return src;
27
+ }
28
+
29
+ if (size === "master") {
30
+ return state.removeProtocol(src);
31
+ }
32
+
33
+ const match = src.match(
34
+ /(_\d+x(\d+)?)?(\.(jpg|jpeg|gif|png|bmp|bitmap|tiff|tif)(\?v=\d+)?)/i
35
+ );
36
+
37
+ if (match) {
38
+ const prefix = src.split(match[0]);
39
+ const suffix = match[3];
40
+ const useSize = size.match("x") ? size : `${size}x`;
41
+ return state.removeProtocol(`${prefix[0]}_${useSize}${suffix}`);
42
+ }
43
+
44
+ return null;
45
+ },
46
+ getSrcSet: function getSrcSet(url) {
47
+ if (!url) {
48
+ return url;
49
+ }
50
+
51
+ const sizes = [100, 200, 400, 800, 1200, 1600, 2000];
52
+
53
+ if (url.match(/builder\.io/)) {
54
+ let srcUrl = url;
55
+ const widthInSrc = Number(url.split("?width=")[1]);
56
+
57
+ if (!isNaN(widthInSrc)) {
58
+ srcUrl = `${srcUrl} ${widthInSrc}w`;
59
+ }
60
+
61
+ return sizes
62
+ .filter((size) => size !== widthInSrc)
63
+ .map(
64
+ (size) => `${state.updateQueryParam(url, "width", size)} ${size}w`
65
+ )
66
+ .concat([srcUrl])
67
+ .join(", ");
68
+ }
69
+
70
+ if (url.match(/cdn\.shopify\.com/)) {
71
+ return sizes
72
+ .map((size) => [
73
+ state.getShopifyImageUrl(url, `${size}x${size}`),
74
+ size,
75
+ ])
76
+ .filter(([sizeUrl]) => !!sizeUrl)
77
+ .map(([sizeUrl, size]) => `${sizeUrl} ${size}w`)
78
+ .concat([url])
79
+ .join(", ");
80
+ }
81
+
82
+ return url;
83
+ },
84
+ useSrcSet: function useSrcSet() {
85
+ return props.srcset || state.getSrcSet(props.image) || "";
86
+ },
87
+ });
88
+
6
89
  return (
7
90
  <div
8
91
  class={css({
@@ -29,14 +112,19 @@ export default function Image(props) {
29
112
  alt={props.altText}
30
113
  aria-role={props.altText ? "presentation" : undefined}
31
114
  style={{
32
- objectPosition: props.backgroundSize || "center",
33
- objectFit: props.backgroundSize || "cover",
115
+ "object-position": props.backgroundSize || "center",
116
+ "object-fit": props.backgroundSize || "cover",
34
117
  }}
35
118
  src={props.image}
36
- srcset={props.srcset}
119
+ srcset={props.srcset || state.getSrcSet(props.image)}
37
120
  sizes={props.sizes}
38
121
  />
39
- <source srcSet={props.srcset} />
122
+ <Show when={!props.noWebp && state.useSrcSet().includes("builder.io")}>
123
+ <source
124
+ type="image/webp"
125
+ srcSet={state.useSrcSet().replace(/\?/g, "?format=webp&")}
126
+ />
127
+ </Show>
40
128
  </picture>
41
129
  <Show
42
130
  when={
@@ -51,7 +139,7 @@ export default function Image(props) {
51
139
  fontSize: "0",
52
140
  })}
53
141
  style={{
54
- paddingTop: props.aspectRatio * 100 + "%",
142
+ "padding-top": props.aspectRatio * 100 + "%",
55
143
  }}
56
144
  >
57
145
  {" "}
package/src/blocks/img.js CHANGED
@@ -19,8 +19,8 @@ export default function ImgComponent(props) {
19
19
  _v$4 = props.altText,
20
20
  _v$5 = props.imgSrc;
21
21
 
22
- _v$ !== _p$._v$ && _el$.style.setProperty("objectFit", _p$._v$ = _v$);
23
- _v$2 !== _p$._v$2 && _el$.style.setProperty("objectPosition", _p$._v$2 = _v$2);
22
+ _v$ !== _p$._v$ && _el$.style.setProperty("object-fit", _p$._v$ = _v$);
23
+ _v$2 !== _p$._v$2 && _el$.style.setProperty("object-position", _p$._v$2 = _v$2);
24
24
  _v$3 !== _p$._v$3 && _$setAttribute(_el$, "key", _p$._v$3 = _v$3);
25
25
  _v$4 !== _p$._v$4 && _$setAttribute(_el$, "alt", _p$._v$4 = _v$4);
26
26
  _v$5 !== _p$._v$5 && _$setAttribute(_el$, "src", _p$._v$5 = _v$5);
@@ -5,8 +5,8 @@ export default function ImgComponent(props) {
5
5
  <img
6
6
  {...props.attributes}
7
7
  style={{
8
- objectFit: props.backgroundSize || "cover",
9
- objectPosition: props.backgroundPosition || "center",
8
+ "object-fit": props.backgroundSize || "cover",
9
+ "object-position": props.backgroundPosition || "center",
10
10
  }}
11
11
  key={(isEditing() && props.imgSrc) || "default-key"}
12
12
  alt={props.altText}
@@ -15,7 +15,7 @@ export default function SectionComponent(props) {
15
15
  _$insert(_el$, () => props.children);
16
16
 
17
17
  _$effect(_$p => _$style(_el$, props.maxWidth && typeof props.maxWidth === "number" ? {
18
- maxWidth: props.maxWidth
18
+ "max-width": props.maxWidth
19
19
  } : undefined, _$p));
20
20
 
21
21
  return _el$;
@@ -5,7 +5,7 @@ export default function SectionComponent(props) {
5
5
  style={
6
6
  props.maxWidth && typeof props.maxWidth === "number"
7
7
  ? {
8
- maxWidth: props.maxWidth,
8
+ "max-width": props.maxWidth,
9
9
  }
10
10
  : undefined
11
11
  }
@@ -8,7 +8,7 @@ import { spread as _$spread } from "solid-js/web";
8
8
  const _tmpl$ = /*#__PURE__*/_$template(`<div></div>`, 2);
9
9
 
10
10
  import { createMutable } from "solid-js/store";
11
- import RenderContent from "../components/render-content";
11
+ import RenderContent from "../components/render-content/render-content";
12
12
  import BuilderContext from "../context/builder.context";
13
13
  export default function Symbol(props) {
14
14
  const state = createMutable({
@@ -1,6 +1,6 @@
1
1
  import { createMutable } from "solid-js/store";
2
2
 
3
- import RenderContent from "../components/render-content.lite";
3
+ import RenderContent from "../components/render-content/render-content.lite";
4
4
  import BuilderContext from "../context/builder.context";
5
5
  import { getContent } from "../functions/get-content";
6
6
 
@@ -17,11 +17,11 @@ export default function Video(props) {
17
17
  width: "100%",
18
18
  height: "100%",
19
19
  ...props.attributes?.style,
20
- objectFit: props.fit,
21
- objectPosition: props.position,
20
+ "object-fit": props.fit,
21
+ "object-position": props.position,
22
22
  // Hack to get object fit to work as expected and
23
23
  // not have the video overflow
24
- borderRadius: 1
24
+ "border-radius": 1
25
25
  },
26
26
  _v$2 = props.video || "no-src",
27
27
  _v$3 = props.posterImage,
@@ -7,11 +7,11 @@ export default function Video(props) {
7
7
  width: "100%",
8
8
  height: "100%",
9
9
  ...props.attributes?.style,
10
- objectFit: props.fit,
11
- objectPosition: props.position,
10
+ "object-fit": props.fit,
11
+ "object-position": props.position,
12
12
  // Hack to get object fit to work as expected and
13
13
  // not have the video overflow
14
- borderRadius: 1,
14
+ "border-radius": 1,
15
15
  }}
16
16
  key={props.video || "no-src"}
17
17
  poster={props.posterImage}
@@ -1,6 +1,6 @@
1
1
  import { mergeProps as _$mergeProps } from "solid-js/web";
2
2
  import { createComponent as _$createComponent } from "solid-js/web";
3
- import { Show, For } from "solid-js";
3
+ import { useContext, Show, For } from "solid-js";
4
4
  import { Dynamic } from "solid-js/web";
5
5
  import { createMutable } from "solid-js/store";
6
6
  import { getBlockComponentOptions } from "../functions/get-block-component-options";
@@ -1,4 +1,4 @@
1
- import { Show, For } from "solid-js";
1
+ import { useContext, Show, For } from "solid-js";
2
2
  import { Dynamic } from "solid-js/web";
3
3
  import { createMutable } from "solid-js/store";
4
4
 
@@ -0,0 +1,81 @@
1
+ import { template as _$template } from "solid-js/web";
2
+ import { insert as _$insert } from "solid-js/web";
3
+
4
+ const _tmpl$ = /*#__PURE__*/_$template(`<style></style>`, 2);
5
+
6
+ import { createMutable } from "solid-js/store";
7
+ export default function RenderStyles(props) {
8
+ const state = createMutable({
9
+ getCssFromFont(font) {
10
+ // TODO: compute what font sizes are used and only load those.......
11
+ const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
12
+ const name = family.split(",")[0];
13
+ const url = font.fileUrl ?? font?.files?.regular;
14
+ let str = "";
15
+
16
+ if (url && family && name) {
17
+ str += `
18
+ @font-face {
19
+ font-family: "${family}";
20
+ src: local("${name}"), url('${url}') format('woff2');
21
+ font-display: fallback;
22
+ font-weight: 400;
23
+ }
24
+ `.trim();
25
+ }
26
+
27
+ if (font.files) {
28
+ for (const weight in font.files) {
29
+ const isNumber = String(Number(weight)) === weight;
30
+
31
+ if (!isNumber) {
32
+ continue;
33
+ } // TODO: maybe limit number loaded
34
+
35
+
36
+ const weightUrl = font.files[weight];
37
+
38
+ if (weightUrl && weightUrl !== url) {
39
+ str += `
40
+ @font-face {
41
+ font-family: "${family}";
42
+ src: url('${weightUrl}') format('woff2');
43
+ font-display: fallback;
44
+ font-weight: ${weight};
45
+ }
46
+ `.trim();
47
+ }
48
+ }
49
+ }
50
+
51
+ return str;
52
+ },
53
+
54
+ getFontCss({
55
+ customFonts
56
+ }) {
57
+ // TODO: flag for this
58
+ // if (!this.builder.allowCustomFonts) {
59
+ // return '';
60
+ // }
61
+ // TODO: separate internal data from external
62
+ return customFonts?.map(font => this.getCssFromFont(font))?.join(" ") || "";
63
+ },
64
+
65
+ getInjectedStyles() {
66
+ return `
67
+ ${props.cssCode}
68
+ ${state.getFontCss({
69
+ customFonts: props.customFonts
70
+ })}`;
71
+ }
72
+
73
+ });
74
+ return (() => {
75
+ const _el$ = _tmpl$.cloneNode(true);
76
+
77
+ _$insert(_el$, () => state.getInjectedStyles());
78
+
79
+ return _el$;
80
+ })();
81
+ }
@@ -0,0 +1,70 @@
1
+ import { createMutable } from "solid-js/store";
2
+
3
+ export default function RenderStyles(props) {
4
+ const state = createMutable({
5
+ getCssFromFont(font: CustomFont) {
6
+ // TODO: compute what font sizes are used and only load those.......
7
+ const family =
8
+ font.family +
9
+ (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
10
+ const name = family.split(",")[0];
11
+ const url = font.fileUrl ?? font?.files?.regular;
12
+ let str = "";
13
+
14
+ if (url && family && name) {
15
+ str += `
16
+ @font-face {
17
+ font-family: "${family}";
18
+ src: local("${name}"), url('${url}') format('woff2');
19
+ font-display: fallback;
20
+ font-weight: 400;
21
+ }
22
+ `.trim();
23
+ }
24
+
25
+ if (font.files) {
26
+ for (const weight in font.files) {
27
+ const isNumber = String(Number(weight)) === weight;
28
+
29
+ if (!isNumber) {
30
+ continue;
31
+ } // TODO: maybe limit number loaded
32
+
33
+ const weightUrl = font.files[weight];
34
+
35
+ if (weightUrl && weightUrl !== url) {
36
+ str += `
37
+ @font-face {
38
+ font-family: "${family}";
39
+ src: url('${weightUrl}') format('woff2');
40
+ font-display: fallback;
41
+ font-weight: ${weight};
42
+ }
43
+ `.trim();
44
+ }
45
+ }
46
+ }
47
+
48
+ return str;
49
+ },
50
+ getFontCss({ customFonts }: { customFonts?: CustomFont[] }) {
51
+ // TODO: flag for this
52
+ // if (!this.builder.allowCustomFonts) {
53
+ // return '';
54
+ // }
55
+ // TODO: separate internal data from external
56
+ return (
57
+ customFonts?.map((font) => this.getCssFromFont(font))?.join(" ") || ""
58
+ );
59
+ },
60
+ getInjectedStyles() {
61
+ return `
62
+ ${props.cssCode}
63
+ ${state.getFontCss({
64
+ customFonts: props.customFonts,
65
+ })}`;
66
+ },
67
+ });
68
+
69
+ return <style>{state.getInjectedStyles()}</style>;
70
+ }
@@ -2,28 +2,28 @@ import { template as _$template } from "solid-js/web";
2
2
  import { delegateEvents as _$delegateEvents } from "solid-js/web";
3
3
  import { setAttribute as _$setAttribute } from "solid-js/web";
4
4
  import { effect as _$effect } from "solid-js/web";
5
- import { createComponent as _$createComponent } from "solid-js/web";
6
5
  import { insert as _$insert } from "solid-js/web";
6
+ import { createComponent as _$createComponent } from "solid-js/web";
7
7
  import { memo as _$memo } from "solid-js/web";
8
8
 
9
- const _tmpl$ = /*#__PURE__*/_$template(`<style></style>`, 2),
10
- _tmpl$2 = /*#__PURE__*/_$template(`<div></div>`, 2);
9
+ const _tmpl$ = /*#__PURE__*/_$template(`<div></div>`, 2);
11
10
 
12
11
  import { Show, onMount } from "solid-js";
13
12
  import { Dynamic } from "solid-js/web";
14
13
  import { createMutable } from "solid-js/store";
15
- import { isBrowser } from "../functions/is-browser";
16
- import BuilderContext from "../context/builder.context";
17
- import { track } from "../functions/track";
18
- import { isReactNative } from "../functions/is-react-native";
19
- import { isEditing } from "../functions/is-editing";
20
- import { isPreviewing } from "../functions/is-previewing";
21
- import { previewingModelName } from "../functions/previewing-model-name";
22
- import { getContent } from "../functions/get-content";
23
- import { convertSearchParamsToQueryObject, getBuilderSearchParams } from "../functions/get-builder-search-params";
24
- import RenderBlocks from "./render-blocks";
25
- import { evaluate } from "../functions/evaluate";
26
- import { getFetch } from "../functions/get-fetch";
14
+ import { isBrowser } from "../../functions/is-browser";
15
+ import BuilderContext from "../../context/builder.context";
16
+ import { track } from "../../functions/track";
17
+ import { isEditing } from "../../functions/is-editing";
18
+ import { isPreviewing } from "../../functions/is-previewing";
19
+ import { previewingModelName } from "../../functions/previewing-model-name";
20
+ import { getContent } from "../../functions/get-content";
21
+ import { convertSearchParamsToQueryObject, getBuilderSearchParams } from "../../functions/get-builder-search-params";
22
+ import RenderBlocks from "../render-blocks";
23
+ import { evaluate } from "../../functions/evaluate";
24
+ import { getFetch } from "../../functions/get-fetch";
25
+ import { TARGET } from "../../constants/target";
26
+ import RenderStyles from "./components/render-styles";
27
27
  export default function RenderContent(props) {
28
28
  const state = createMutable({
29
29
  get useContent() {
@@ -52,60 +52,6 @@ export default function RenderContent(props) {
52
52
  return {};
53
53
  },
54
54
 
55
- getCssFromFont(font, data) {
56
- // TODO: compute what font sizes are used and only load those.......
57
- const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
58
- const name = family.split(",")[0];
59
- const url = font.fileUrl ?? font?.files?.regular;
60
- let str = "";
61
-
62
- if (url && family && name) {
63
- str += `
64
- @font-face {
65
- font-family: "${family}";
66
- src: local("${name}"), url('${url}') format('woff2');
67
- font-display: fallback;
68
- font-weight: 400;
69
- }
70
- `.trim();
71
- }
72
-
73
- if (font.files) {
74
- for (const weight in font.files) {
75
- const isNumber = String(Number(weight)) === weight;
76
-
77
- if (!isNumber) {
78
- continue;
79
- } // TODO: maybe limit number loaded
80
-
81
-
82
- const weightUrl = font.files[weight];
83
-
84
- if (weightUrl && weightUrl !== url) {
85
- str += `
86
- @font-face {
87
- font-family: "${family}";
88
- src: url('${weightUrl}') format('woff2');
89
- font-display: fallback;
90
- font-weight: ${weight};
91
- }
92
- `.trim();
93
- }
94
- }
95
- }
96
-
97
- return str;
98
- },
99
-
100
- getFontCss(data) {
101
- // TODO: flag for this
102
- // if (!this.builder.allowCustomFonts) {
103
- // return '';
104
- // }
105
- // TODO: separate internal data from external
106
- return data?.customFonts?.map(font => this.getCssFromFont(font, data))?.join(" ") || "";
107
- },
108
-
109
55
  processMessage(event) {
110
56
  const {
111
57
  data
@@ -266,41 +212,44 @@ export default function RenderContent(props) {
266
212
  get children() {
267
213
  return _$createComponent(Show, {
268
214
  get when() {
269
- return state.state.useContent;
215
+ return state.useContent;
270
216
  },
271
217
 
272
218
  get children() {
273
- const _el$ = _tmpl$2.cloneNode(true);
219
+ const _el$ = _tmpl$.cloneNode(true);
274
220
 
275
221
  _el$.$$click = event => track("click", {
276
- contentId: state.state.useContent.id
222
+ contentId: state.useContent.id
277
223
  });
278
224
 
279
225
  _$insert(_el$, _$createComponent(Show, {
280
226
  get when() {
281
- return _$memo(() => !!(state.state.useContent?.data?.cssCode || state.state.useContent?.data?.customFonts?.length), true)() && !isReactNative();
227
+ return (state.useContent?.data?.cssCode || state.useContent?.data?.customFonts?.length) && TARGET !== "reactNative";
282
228
  },
283
229
 
284
230
  get children() {
285
- const _el$2 = _tmpl$.cloneNode(true);
286
-
287
- _$insert(_el$2, () => state.state.useContent.data.cssCode, null);
231
+ return _$createComponent(RenderStyles, {
232
+ get cssCode() {
233
+ return state.useContent.data.cssCode;
234
+ },
288
235
 
289
- _$insert(_el$2, () => state.state.getFontCss(state.state.useContent.data), null);
236
+ get customFonts() {
237
+ return state.useContent.data.customFonts;
238
+ }
290
239
 
291
- return _el$2;
240
+ });
292
241
  }
293
242
 
294
243
  }), null);
295
244
 
296
245
  _$insert(_el$, _$createComponent(RenderBlocks, {
297
246
  get blocks() {
298
- return state.state.useContent?.data?.blocks;
247
+ return state.useContent?.data?.blocks;
299
248
  }
300
249
 
301
250
  }), null);
302
251
 
303
- _$effect(() => _$setAttribute(_el$, "data-builder-content-id", state.state.useContent?.id));
252
+ _$effect(() => _$setAttribute(_el$, "data-builder-content-id", state.useContent?.id));
304
253
 
305
254
  return _el$;
306
255
  }
@@ -1,24 +1,23 @@
1
- import { Show, onMount } from "solid-js";
1
+ import { useContext, Show, onMount } from "solid-js";
2
2
  import { Dynamic } from "solid-js/web";
3
3
  import { createMutable } from "solid-js/store";
4
4
 
5
- import { isBrowser } from "../functions/is-browser";
6
- import BuilderContext from "../context/builder.context";
7
- import { track } from "../functions/track";
8
- import { isReactNative } from "../functions/is-react-native";
9
- import { isEditing } from "../functions/is-editing";
10
- import { isPreviewing } from "../functions/is-previewing";
11
- import { previewingModelName } from "../functions/previewing-model-name";
12
- import { getContent } from "../functions/get-content";
5
+ import { isBrowser } from "../../functions/is-browser";
6
+ import BuilderContext from "../../context/builder.context";
7
+ import { track } from "../../functions/track";
8
+ import { isEditing } from "../../functions/is-editing";
9
+ import { isPreviewing } from "../../functions/is-previewing";
10
+ import { previewingModelName } from "../../functions/previewing-model-name";
11
+ import { getContent } from "../../functions/get-content";
13
12
  import {
14
13
  convertSearchParamsToQueryObject,
15
14
  getBuilderSearchParams,
16
- } from "../functions/get-builder-search-params";
17
- import RenderBlocks from "./render-blocks.lite";
18
- import { evaluate } from "../functions/evaluate";
19
- import { getFetch } from "../functions/get-fetch";
20
- import { onChange } from "../functions/on-change";
21
- import { ifTarget } from "../functions/if-target";
15
+ } from "../../functions/get-builder-search-params";
16
+ import RenderBlocks from "../render-blocks.lite";
17
+ import { evaluate } from "../../functions/evaluate";
18
+ import { getFetch } from "../../functions/get-fetch";
19
+ import { TARGET } from "../../constants/target";
20
+ import RenderStyles from "./components/render-styles.lite";
22
21
 
23
22
  export default function RenderContent(props) {
24
23
  const state = createMutable({
@@ -49,63 +48,6 @@ export default function RenderContent(props) {
49
48
  [index: string]: any;
50
49
  };
51
50
  },
52
- getCssFromFont(font: any, data?: any) {
53
- // TODO: compute what font sizes are used and only load those.......
54
- const family =
55
- font.family +
56
- (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
57
- const name = family.split(",")[0];
58
- const url = font.fileUrl ?? font?.files?.regular;
59
- let str = "";
60
-
61
- if (url && family && name) {
62
- str += `
63
- @font-face {
64
- font-family: "${family}";
65
- src: local("${name}"), url('${url}') format('woff2');
66
- font-display: fallback;
67
- font-weight: 400;
68
- }
69
- `.trim();
70
- }
71
-
72
- if (font.files) {
73
- for (const weight in font.files) {
74
- const isNumber = String(Number(weight)) === weight;
75
-
76
- if (!isNumber) {
77
- continue;
78
- } // TODO: maybe limit number loaded
79
-
80
- const weightUrl = font.files[weight];
81
-
82
- if (weightUrl && weightUrl !== url) {
83
- str += `
84
- @font-face {
85
- font-family: "${family}";
86
- src: url('${weightUrl}') format('woff2');
87
- font-display: fallback;
88
- font-weight: ${weight};
89
- }
90
- `.trim();
91
- }
92
- }
93
- }
94
-
95
- return str;
96
- },
97
- getFontCss(data?: any) {
98
- // TODO: flag for this
99
- // if (!this.builder.allowCustomFonts) {
100
- // return '';
101
- // }
102
- // TODO: separate internal data from external
103
- return (
104
- data?.customFonts
105
- ?.map((font: any) => this.getCssFromFont(font, data))
106
- ?.join(" ") || ""
107
- );
108
- },
109
51
  processMessage(event: MessageEvent) {
110
52
  const { data } = event;
111
53
 
@@ -258,30 +200,28 @@ export default function RenderContent(props) {
258
200
  }}
259
201
  component={BuilderContext.Provider}
260
202
  >
261
- <Show when={state.state.useContent}>
203
+ <Show when={state.useContent}>
262
204
  <div
263
205
  onClick={(event) =>
264
206
  track("click", {
265
- contentId: state.state.useContent.id,
207
+ contentId: state.useContent.id,
266
208
  })
267
209
  }
268
- data-builder-content-id={state.state.useContent?.id}
210
+ data-builder-content-id={state.useContent?.id}
269
211
  >
270
212
  <Show
271
213
  when={
272
- (state.state.useContent?.data?.cssCode ||
273
- state.state.useContent?.data?.customFonts?.length) &&
274
- !isReactNative()
214
+ (state.useContent?.data?.cssCode ||
215
+ state.useContent?.data?.customFonts?.length) &&
216
+ TARGET !== "reactNative"
275
217
  }
276
218
  >
277
- <style>
278
- {state.state.useContent.data.cssCode}
279
- {state.state.getFontCss(state.state.useContent.data)}
280
- </style>
219
+ <RenderStyles
220
+ cssCode={state.useContent.data.cssCode}
221
+ customFonts={state.useContent.data.customFonts}
222
+ ></RenderStyles>
281
223
  </Show>
282
- <RenderBlocks
283
- blocks={state.state.useContent?.data?.blocks}
284
- ></RenderBlocks>
224
+ <RenderBlocks blocks={state.useContent?.data?.blocks}></RenderBlocks>
285
225
  </div>
286
226
  </Show>
287
227
  </Dynamic>
@@ -0,0 +1,4 @@
1
+ const TARGET = "solid";
2
+ export {
3
+ TARGET
4
+ };
@@ -1,5 +1,14 @@
1
- function ifTarget(target, doThing, elseThing) {
2
- return doThing();
1
+ import { TARGET } from "../constants/target";
2
+ function ifTarget({
3
+ targets,
4
+ doThing,
5
+ elseThing
6
+ }) {
7
+ if (TARGET && targets.includes(TARGET)) {
8
+ return doThing();
9
+ } else {
10
+ return elseThing == null ? void 0 : elseThing();
11
+ }
3
12
  }
4
13
  export {
5
14
  ifTarget
@@ -1,11 +1,11 @@
1
+ import { TARGET } from "../constants/target";
1
2
  import { isBrowser } from "./is-browser";
2
3
  import { isEditing } from "./is-editing";
3
- import { isReactNative } from "./is-react-native";
4
4
  function track(event, properties) {
5
5
  if (isEditing()) {
6
6
  return;
7
7
  }
8
- if (!(isBrowser() || isReactNative())) {
8
+ if (!(isBrowser() || TARGET === "reactNative")) {
9
9
  return;
10
10
  }
11
11
  return fetch(`https://builder.io/api/v1/track`, {
@@ -6,7 +6,7 @@ import { default as default6 } from "../blocks/symbol";
6
6
  import { default as default7 } from "../blocks/button";
7
7
  import { default as default8 } from "../blocks/section";
8
8
  import { default as default9 } from "../blocks/fragment";
9
- import { default as default10 } from "../components/render-content";
9
+ import { default as default10 } from "../components/render-content/render-content";
10
10
  export {
11
11
  default7 as Button,
12
12
  default2 as Columns,
@@ -1,4 +1,5 @@
1
1
  var _a;
2
+ import { TARGET } from "../constants/target";
2
3
  import { isBrowser } from "../functions/is-browser";
3
4
  import { register } from "../functions/register";
4
5
  register("insertMenu", {
@@ -9,7 +10,7 @@ register("insertMenu", {
9
10
  { name: "Text" },
10
11
  { name: "Image" },
11
12
  { name: "Columns" },
12
- ...false ? [] : [
13
+ ...TARGET === "reactNative" ? [] : [
13
14
  { name: "Core:Section" },
14
15
  { name: "Core:Button" },
15
16
  { name: "Embed" },
@@ -21,7 +22,7 @@ if (isBrowser()) {
21
22
  (_a = window.parent) == null ? void 0 : _a.postMessage({
22
23
  type: "builder.sdkInfo",
23
24
  data: {
24
- target: "solid",
25
+ target: TARGET,
25
26
  supportsPatchUpdates: false
26
27
  }
27
28
  }, "*");
File without changes
@@ -1,6 +0,0 @@
1
- function getTarget(_) {
2
- return "reactNative";
3
- }
4
- export {
5
- getTarget
6
- };
@@ -1,6 +0,0 @@
1
- function isReactNative() {
2
- return false;
3
- }
4
- export {
5
- isReactNative
6
- };