@builder.io/sdk-solid 0.0.8-21 → 0.0.8-24

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 (38) hide show
  1. package/package.json +1 -1
  2. package/src/blocks/button/button.jsx +6 -1
  3. package/src/blocks/columns/columns.jsx +44 -47
  4. package/src/blocks/columns/component-info.js +3 -2
  5. package/src/blocks/custom-code/custom-code.jsx +34 -37
  6. package/src/blocks/embed/component-info.js +3 -2
  7. package/src/blocks/embed/embed.jsx +28 -31
  8. package/src/blocks/form/form.jsx +172 -173
  9. package/src/blocks/image/component-info.js +3 -2
  10. package/src/blocks/image/image.jsx +26 -29
  11. package/src/blocks/img/img.jsx +1 -1
  12. package/src/blocks/symbol/symbol.jsx +10 -13
  13. package/src/blocks/util.js +7 -0
  14. package/src/blocks/video/video.jsx +19 -23
  15. package/src/components/render-block/block-styles.jsx +22 -27
  16. package/src/components/render-block/render-block.jsx +155 -159
  17. package/src/components/render-block/render-component.jsx +2 -2
  18. package/src/components/render-block/render-repeated-block.jsx +1 -1
  19. package/src/components/render-blocks.jsx +32 -33
  20. package/src/components/render-content/components/render-styles.jsx +38 -41
  21. package/src/components/render-content/render-content.jsx +170 -156
  22. package/src/components/render-inlined-styles.jsx +10 -13
  23. package/src/constants/builder-registered-components.js +3 -0
  24. package/src/functions/get-fetch.js +2 -2
  25. package/src/functions/get-processed-block.js +10 -6
  26. package/src/functions/get-processed-block.test.js +1 -1
  27. package/src/functions/track.js +71 -2
  28. package/src/helpers/cookie.js +59 -0
  29. package/src/helpers/localStorage.js +34 -0
  30. package/src/helpers/nullable.js +4 -0
  31. package/src/helpers/sessionId.js +26 -0
  32. package/src/helpers/time.js +5 -0
  33. package/src/helpers/url.js +10 -0
  34. package/src/helpers/url.test.js +15 -0
  35. package/src/helpers/uuid.js +13 -0
  36. package/src/helpers/visitorId.js +33 -0
  37. package/src/scripts/init-editing.js +4 -5
  38. package/src/types/can-track.js +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.8-21",
3
+ "version": "0.0.8-24",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./src/solid-index.jsx",
@@ -1,8 +1,13 @@
1
1
  import { Show } from "solid-js";
2
+ import { css } from "solid-styled-components";
2
3
 
3
4
  function Button(props) {
4
5
  return <>
5
- <Show fallback={<span {...props.attributes}>{props.text}</span>} when={props.link}>
6
+ <Show fallback={<button class={css({
7
+ all: "unset"
8
+ })} {...props.attributes}>
9
+ {props.text}
10
+ </button>} when={props.link}>
6
11
  <a {...props.attributes} role="button" href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
7
12
  {props.text}
8
13
  </a>
@@ -1,74 +1,71 @@
1
1
  import { For } from "solid-js";
2
- import { createMutable } from "solid-js/store";
3
2
  import { css } from "solid-styled-components";
4
3
  import RenderBlocks from "../../components/render-blocks.jsx";
5
4
 
6
5
  function Columns(props) {
7
- const state = createMutable({
8
- getGutterSize() {
9
- return typeof props.space === "number" ? props.space || 0 : 20;
10
- },
6
+ function getGutterSize() {
7
+ return typeof props.space === "number" ? props.space || 0 : 20;
8
+ }
11
9
 
12
- getColumns() {
13
- return props.columns || [];
14
- },
10
+ function getColumns() {
11
+ return props.columns || [];
12
+ }
15
13
 
16
- getWidth(index) {
17
- const columns = this.getColumns();
18
- return columns[index]?.width || 100 / columns.length;
19
- },
14
+ function getWidth(index) {
15
+ const columns = getColumns();
16
+ return columns[index]?.width || 100 / columns.length;
17
+ }
20
18
 
21
- getColumnCssWidth(index) {
22
- const columns = this.getColumns();
23
- const gutterSize = this.getGutterSize();
24
- const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
25
- return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
26
- },
19
+ function getColumnCssWidth(index) {
20
+ const columns = getColumns();
21
+ const gutterSize = getGutterSize();
22
+ const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
23
+ return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
24
+ }
27
25
 
28
- maybeApplyForTablet(prop) {
29
- const _stackColumnsAt = props.stackColumnsAt || "tablet";
26
+ function maybeApplyForTablet(prop) {
27
+ const _stackColumnsAt = props.stackColumnsAt || "tablet";
30
28
 
31
- return _stackColumnsAt === "tablet" ? prop : "inherit";
32
- },
29
+ return _stackColumnsAt === "tablet" ? prop : "inherit";
30
+ }
33
31
 
34
- get columnsCssVars() {
35
- const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
36
- return {
37
- "--flex-dir": flexDir,
38
- "--flex-dir-tablet": this.maybeApplyForTablet(flexDir)
39
- };
40
- },
32
+ function columnsCssVars() {
33
+ const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
34
+ return {
35
+ "--flex-dir": flexDir,
36
+ "--flex-dir-tablet": maybeApplyForTablet(flexDir)
37
+ };
38
+ }
41
39
 
42
- get columnCssVars() {
43
- const width = "100%";
44
- const marginLeft = "0";
45
- return {
46
- "--column-width": width,
47
- "--column-margin-left": marginLeft,
48
- "--column-width-tablet": this.maybeApplyForTablet(width),
49
- "--column-margin-left-tablet": this.maybeApplyForTablet(marginLeft)
50
- };
51
- }
40
+ function columnCssVars() {
41
+ const width = "100%";
42
+ const marginLeft = "0";
43
+ return {
44
+ "--column-width": width,
45
+ "--column-margin-left": marginLeft,
46
+ "--column-width-tablet": maybeApplyForTablet(width),
47
+ "--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
48
+ };
49
+ }
52
50
 
53
- });
54
51
  return <div class={"builder-columns " + css({
55
52
  display: "flex",
56
53
  alignItems: "stretch",
57
54
  lineHeight: "normal",
58
- "@media (max-width: 999px)": {
55
+ "@media (max-width: 991px)": {
59
56
  flexDirection: "var(--flex-dir-tablet)"
60
57
  },
61
58
  "@media (max-width: 639px)": {
62
59
  flexDirection: "var(--flex-dir)"
63
60
  }
64
- })} style={state.columnsCssVars}>
61
+ })} style={columnsCssVars()}>
65
62
  <For each={props.columns}>
66
63
  {(column, _index) => {
67
64
  const index = _index();
68
65
 
69
66
  return <div class={"builder-column " + css({
70
67
  flexGrow: "1",
71
- "@media (max-width: 999px)": {
68
+ "@media (max-width: 991px)": {
72
69
  width: "var(--column-width-tablet) !important",
73
70
  marginLeft: "var(--column-margin-left-tablet) !important"
74
71
  },
@@ -77,11 +74,11 @@ function Columns(props) {
77
74
  marginLeft: "var(--column-margin-left) !important"
78
75
  }
79
76
  })} style={{
80
- width: state.getColumnCssWidth(index),
81
- "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
82
- ...state.columnCssVars
77
+ width: getColumnCssWidth(index),
78
+ "margin-left": `${index === 0 ? 0 : getGutterSize()}px`,
79
+ ...columnCssVars()
83
80
  }} key={index}>
84
- <RenderBlocks blocks={column.blocks}></RenderBlocks>
81
+ <RenderBlocks blocks={column.blocks} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id}></RenderBlocks>
85
82
  </div>;
86
83
  }}
87
84
  </For>
@@ -1,3 +1,4 @@
1
+ import { markSerializable } from "../util";
1
2
  const componentInfo = {
2
3
  name: "Columns",
3
4
  builtIn: true,
@@ -186,7 +187,7 @@ const componentInfo = {
186
187
  ]
187
188
  }
188
189
  ],
189
- onChange(options) {
190
+ onChange: markSerializable((options) => {
190
191
  function clearWidths() {
191
192
  columns.forEach((col) => {
192
193
  col.delete("width");
@@ -210,7 +211,7 @@ const componentInfo = {
210
211
  }
211
212
  }
212
213
  }
213
- }
214
+ })
214
215
  },
215
216
  {
216
217
  name: "space",
@@ -1,49 +1,46 @@
1
- import { onMount } from "solid-js";
2
- import { createMutable } from "solid-js/store";
1
+ import { onMount, createSignal } from "solid-js";
3
2
 
4
3
  function CustomCode(props) {
5
- const state = createMutable({
6
- scriptsInserted: [],
7
- scriptsRun: [],
8
-
9
- findAndRunScripts() {
10
- // TODO: Move this function to standalone one in '@builder.io/utils'
11
- if (elem && typeof window !== "undefined") {
12
- const scripts = elem.getElementsByTagName("script");
13
-
14
- for (let i = 0; i < scripts.length; i++) {
15
- const script = scripts[i];
16
-
17
- if (script.src) {
18
- if (state.scriptsInserted.includes(script.src)) {
19
- continue;
20
- }
21
-
22
- state.scriptsInserted.push(script.src);
23
- const newScript = document.createElement("script");
24
- newScript.async = true;
25
- newScript.src = script.src;
26
- document.head.appendChild(newScript);
27
- } else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
28
- if (state.scriptsRun.includes(script.innerText)) {
29
- continue;
30
- }
31
-
32
- try {
33
- state.scriptsRun.push(script.innerText);
34
- new Function(script.innerText)();
35
- } catch (error) {
36
- console.warn("`CustomCode`: Error running script:", error);
37
- }
4
+ const [scriptsInserted, setScriptsInserted] = createSignal([]);
5
+ const [scriptsRun, setScriptsRun] = createSignal([]);
6
+
7
+ function findAndRunScripts() {
8
+ // TODO: Move this function to standalone one in '@builder.io/utils'
9
+ if (elem && typeof window !== "undefined") {
10
+ const scripts = elem.getElementsByTagName("script");
11
+
12
+ for (let i = 0; i < scripts.length; i++) {
13
+ const script = scripts[i];
14
+
15
+ if (script.src) {
16
+ if (scriptsInserted().includes(script.src)) {
17
+ continue;
18
+ }
19
+
20
+ scriptsInserted().push(script.src);
21
+ const newScript = document.createElement("script");
22
+ newScript.async = true;
23
+ newScript.src = script.src;
24
+ document.head.appendChild(newScript);
25
+ } else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
26
+ if (scriptsRun().includes(script.innerText)) {
27
+ continue;
28
+ }
29
+
30
+ try {
31
+ scriptsRun().push(script.innerText);
32
+ new Function(script.innerText)();
33
+ } catch (error) {
34
+ console.warn("`CustomCode`: Error running script:", error);
38
35
  }
39
36
  }
40
37
  }
41
38
  }
39
+ }
42
40
 
43
- });
44
41
  let elem;
45
42
  onMount(() => {
46
- state.findAndRunScripts();
43
+ findAndRunScripts();
47
44
  });
48
45
  return <div class={"builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")} ref={elem} innerHTML={props.code}></div>;
49
46
  }
@@ -1,3 +1,4 @@
1
+ import { markSerializable } from "../util";
1
2
  const componentInfo = {
2
3
  name: "Embed",
3
4
  static: true,
@@ -9,7 +10,7 @@ const componentInfo = {
9
10
  required: true,
10
11
  defaultValue: "",
11
12
  helperText: "e.g. enter a youtube url, google map, etc",
12
- onChange(options) {
13
+ onChange: markSerializable((options) => {
13
14
  const url = options.get("url");
14
15
  if (url) {
15
16
  options.set("content", "Loading...");
@@ -28,7 +29,7 @@ const componentInfo = {
28
29
  } else {
29
30
  options.delete("content");
30
31
  }
31
- }
32
+ })
32
33
  },
33
34
  {
34
35
  name: "content",
@@ -1,47 +1,44 @@
1
- import { on, createEffect } from "solid-js";
2
- import { createMutable } from "solid-js/store";
1
+ import { on, createEffect, createSignal } from "solid-js";
3
2
  import { isJsScript } from "./helpers";
4
3
 
5
4
  function Embed(props) {
6
- const state = createMutable({
7
- scriptsInserted: [],
8
- scriptsRun: [],
9
- ranInitFn: false,
10
-
11
- findAndRunScripts() {
12
- const scripts = elem.getElementsByTagName("script");
13
-
14
- for (let i = 0; i < scripts.length; i++) {
15
- const script = scripts[i];
16
-
17
- if (script.src && !state.scriptsInserted.includes(script.src)) {
18
- state.scriptsInserted.push(script.src);
19
- const newScript = document.createElement("script");
20
- newScript.async = true;
21
- newScript.src = script.src;
22
- document.head.appendChild(newScript);
23
- } else if (isJsScript(script) && !state.scriptsRun.includes(script.innerText)) {
24
- try {
25
- state.scriptsRun.push(script.innerText);
26
- new Function(script.innerText)();
27
- } catch (error) {
28
- console.warn("`Embed`: Error running script:", error);
29
- }
5
+ const [scriptsInserted, setScriptsInserted] = createSignal([]);
6
+ const [scriptsRun, setScriptsRun] = createSignal([]);
7
+ const [ranInitFn, setRanInitFn] = createSignal(false);
8
+
9
+ function findAndRunScripts() {
10
+ const scripts = elem.getElementsByTagName("script");
11
+
12
+ for (let i = 0; i < scripts.length; i++) {
13
+ const script = scripts[i];
14
+
15
+ if (script.src && !scriptsInserted().includes(script.src)) {
16
+ scriptsInserted().push(script.src);
17
+ const newScript = document.createElement("script");
18
+ newScript.async = true;
19
+ newScript.src = script.src;
20
+ document.head.appendChild(newScript);
21
+ } else if (isJsScript(script) && !scriptsRun().includes(script.innerText)) {
22
+ try {
23
+ scriptsRun().push(script.innerText);
24
+ new Function(script.innerText)();
25
+ } catch (error) {
26
+ console.warn("`Embed`: Error running script:", error);
30
27
  }
31
28
  }
32
29
  }
30
+ }
33
31
 
34
- });
35
32
  let elem;
36
33
 
37
34
  function onUpdateFn_0() {
38
- if (elem && !state.ranInitFn) {
39
- state.ranInitFn = true;
40
- state.findAndRunScripts();
35
+ if (elem && !ranInitFn()) {
36
+ setRanInitFn(true);
37
+ findAndRunScripts();
41
38
  }
42
39
  }
43
40
 
44
- createEffect(on(() => [elem, state.ranInitFn], onUpdateFn_0));
41
+ createEffect(on(() => [elem, ranInitFn()], onUpdateFn_0));
45
42
  return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
46
43
  }
47
44