@builder.io/sdk-solid 0.0.3 → 0.0.4

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,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "",
5
5
  "main": "src/index.js",
6
6
  "dependencies": {
@@ -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
 
@@ -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
@@ -270,7 +216,7 @@ export default function RenderContent(props) {
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
222
  contentId: state.useContent.id
@@ -278,17 +224,20 @@ export default function RenderContent(props) {
278
224
 
279
225
  _$insert(_el$, _$createComponent(Show, {
280
226
  get when() {
281
- return _$memo(() => !!(state.useContent?.data?.cssCode || 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.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.getFontCss(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);
@@ -2,23 +2,22 @@ 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
 
@@ -271,13 +213,13 @@ export default function RenderContent(props) {
271
213
  when={
272
214
  (state.useContent?.data?.cssCode ||
273
215
  state.useContent?.data?.customFonts?.length) &&
274
- !isReactNative()
216
+ TARGET !== "reactNative"
275
217
  }
276
218
  >
277
- <style>
278
- {state.useContent.data.cssCode}
279
- {state.getFontCss(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
224
  <RenderBlocks blocks={state.useContent?.data?.blocks}></RenderBlocks>
283
225
  </div>
@@ -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
- };