@builder.io/sdk-solid 0.1.2 → 0.1.3-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 (34) hide show
  1. package/dist/sdk-solid.cjs +34 -0
  2. package/dist/sdk-solid.js +3863 -0
  3. package/package.json +5 -6
  4. package/src/blocks/BaseText.jsx +5 -1
  5. package/src/blocks/button/button.jsx +25 -7
  6. package/src/blocks/columns/columns.jsx +84 -38
  7. package/src/blocks/custom-code/custom-code.jsx +25 -3
  8. package/src/blocks/embed/embed.jsx +14 -2
  9. package/src/blocks/form/form.jsx +175 -121
  10. package/src/blocks/fragment/fragment.jsx +2 -1
  11. package/src/blocks/image/image.jsx +75 -38
  12. package/src/blocks/img/img.jsx +15 -5
  13. package/src/blocks/input/input.jsx +17 -2
  14. package/src/blocks/raw-text/raw-text.jsx +8 -2
  15. package/src/blocks/section/section.jsx +24 -14
  16. package/src/blocks/select/select.jsx +21 -6
  17. package/src/blocks/submit-button/submit-button.jsx +6 -3
  18. package/src/blocks/symbol/symbol.jsx +54 -15
  19. package/src/blocks/text/text.jsx +2 -1
  20. package/src/blocks/textarea/textarea.jsx +11 -2
  21. package/src/blocks/video/video.jsx +49 -27
  22. package/src/components/render-block/block-styles.jsx +45 -21
  23. package/src/components/render-block/render-block.helpers.js +90 -0
  24. package/src/components/render-block/render-block.jsx +110 -131
  25. package/src/components/render-block/render-component.jsx +26 -9
  26. package/src/components/render-block/render-repeated-block.jsx +20 -24
  27. package/src/components/render-blocks.jsx +70 -30
  28. package/src/components/render-content/builder-editing.jsx +2 -1
  29. package/src/components/render-content/components/render-styles.jsx +17 -8
  30. package/src/components/render-content/render-content.jsx +224 -146
  31. package/src/components/render-inlined-styles.jsx +14 -4
  32. package/vite.config.ts +18 -0
  33. package/solid-index.jsx +0 -5
  34. package/src/components/render-block/render-component-with-context.jsx +0 -28
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.1.2",
3
+ "version": "0.1.3-0",
4
4
  "description": "",
5
5
  "type": "module",
6
- "main": "./solid-index.jsx",
7
- "module": "./solid-index.jsx",
6
+ "main": "./dist/sdk-solid.js",
7
+ "module": "./dist/sdk-solid.js",
8
8
  "exports": {
9
- ".": "./solid-index.jsx"
9
+ ".": "./dist/sdk-solid.js"
10
10
  },
11
11
  "scripts": {
12
- "build": "echo 'no need to build solid SDK'",
12
+ "build": "vite build",
13
13
  "release:patch": "yarn run build && npm version patch && npm publish",
14
14
  "release:minor": "yarn run build && npm version minor && npm publish",
15
15
  "release:dev": "yarn run build && npm version prerelease && npm publish --tag dev"
@@ -21,7 +21,6 @@
21
21
  "solid-js": "^1.5.7"
22
22
  },
23
23
  "devDependencies": {
24
- "babel-preset-solid": "^1.3.17",
25
24
  "solid-js": "^1.5.7",
26
25
  "vite": "^3.0.4",
27
26
  "vite-plugin-solid": "^2.2.6"
@@ -1,7 +1,11 @@
1
1
  import { useContext } from "solid-js";
2
+
2
3
  import BuilderContext from "../context/builder.context.js";
4
+
3
5
  function BaseText(props) {
4
6
  const builderContext = useContext(BuilderContext);
7
+
5
8
  return <span style={builderContext.inheritedStyles}>{props.text}</span>;
6
9
  }
7
- export default BaseText;
10
+
11
+ export default BaseText;
@@ -1,14 +1,32 @@
1
1
  import { Show } from "solid-js";
2
+
2
3
  import { css } from "solid-styled-components";
4
+
3
5
  function Button(props) {
4
- return <Show fallback={<button class={css({
5
- all: "unset"
6
- })} {...props.attributes}>
6
+ return (
7
+ <Show
8
+ fallback={
9
+ <button
10
+ class={css({
11
+ all: "unset",
12
+ })}
13
+ {...props.attributes}
14
+ >
7
15
  {props.text}
8
- </button>} when={props.link}>
9
- <a role="button" {...props.attributes} href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
16
+ </button>
17
+ }
18
+ when={props.link}
19
+ >
20
+ <a
21
+ role="button"
22
+ {...props.attributes}
23
+ href={props.link}
24
+ target={props.openLinkInNewTab ? "_blank" : undefined}
25
+ >
10
26
  {props.text}
11
27
  </a>
12
- </Show>;
28
+ </Show>
29
+ );
13
30
  }
14
- export default Button;
31
+
32
+ export default Button;
@@ -1,38 +1,52 @@
1
- import { Show, For } from "solid-js";
1
+ import { Show, For, createSignal } from "solid-js";
2
+
2
3
  import { css } from "solid-styled-components";
4
+
3
5
  import RenderBlocks from "../../components/render-blocks.jsx";
4
6
  import { getSizesForBreakpoints } from "../../constants/device-sizes";
5
7
  import RenderInlinedStyles from "../../components/render-inlined-styles.jsx";
6
8
  import { TARGET } from "../../constants/target.js";
7
9
  import { convertStyleMapToCSS } from "../../helpers/css";
10
+
8
11
  function Columns(props) {
9
12
  function getGutterSize() {
10
13
  return typeof props.space === "number" ? props.space || 0 : 20;
11
14
  }
15
+
12
16
  function getColumns() {
13
17
  return props.columns || [];
14
18
  }
19
+
15
20
  function getWidth(index) {
16
21
  const columns = getColumns();
17
22
  return columns[index]?.width || 100 / columns.length;
18
23
  }
24
+
19
25
  function getColumnCssWidth(index) {
20
26
  const columns = getColumns();
21
27
  const gutterSize = getGutterSize();
22
- const subtractWidth = gutterSize * (columns.length - 1) / columns.length;
28
+ const subtractWidth = (gutterSize * (columns.length - 1)) / columns.length;
23
29
  return `calc(${getWidth(index)}% - ${subtractWidth}px)`;
24
30
  }
31
+
25
32
  function maybeApplyForTablet(prop) {
26
33
  const _stackColumnsAt = props.stackColumnsAt || "tablet";
27
34
  return _stackColumnsAt === "tablet" ? prop : "inherit";
28
35
  }
36
+
29
37
  function columnsCssVars() {
30
- const flexDir = props.stackColumnsAt === "never" ? "inherit" : props.reverseColumnsWhenStacked ? "column-reverse" : "column";
38
+ const flexDir =
39
+ props.stackColumnsAt === "never"
40
+ ? "inherit"
41
+ : props.reverseColumnsWhenStacked
42
+ ? "column-reverse"
43
+ : "column";
31
44
  return {
32
45
  "--flex-dir": flexDir,
33
- "--flex-dir-tablet": maybeApplyForTablet(flexDir)
46
+ "--flex-dir-tablet": maybeApplyForTablet(flexDir),
34
47
  };
35
48
  }
49
+
36
50
  function columnCssVars() {
37
51
  const width = "100%";
38
52
  const marginLeft = "0";
@@ -40,37 +54,42 @@ function Columns(props) {
40
54
  "--column-width": width,
41
55
  "--column-margin-left": marginLeft,
42
56
  "--column-width-tablet": maybeApplyForTablet(width),
43
- "--column-margin-left-tablet": maybeApplyForTablet(marginLeft)
57
+ "--column-margin-left-tablet": maybeApplyForTablet(marginLeft),
44
58
  };
45
59
  }
60
+
46
61
  function getWidthForBreakpointSize(size) {
47
- const breakpointSizes = getSizesForBreakpoints(props.customBreakpoints || {});
62
+ const breakpointSizes = getSizesForBreakpoints(
63
+ props.customBreakpoints || {}
64
+ );
48
65
  return breakpointSizes[size].max;
49
66
  }
67
+
50
68
  function columnStyleObjects() {
51
69
  return {
52
70
  columns: {
53
71
  small: {
54
72
  flexDirection: "var(--flex-dir)",
55
- alignItems: "stretch"
73
+ alignItems: "stretch",
56
74
  },
57
75
  medium: {
58
76
  flexDirection: "var(--flex-dir-tablet)",
59
- alignItems: "stretch"
60
- }
77
+ alignItems: "stretch",
78
+ },
61
79
  },
62
80
  column: {
63
81
  small: {
64
82
  width: "var(--column-width) !important",
65
- marginLeft: "var(--column-margin-left) !important"
83
+ marginLeft: "var(--column-margin-left) !important",
66
84
  },
67
85
  medium: {
68
86
  width: "var(--column-width-tablet) !important",
69
- marginLeft: "var(--column-margin-left-tablet) !important"
70
- }
71
- }
87
+ marginLeft: "var(--column-margin-left-tablet) !important",
88
+ },
89
+ },
72
90
  };
73
91
  }
92
+
74
93
  function columnsStyles() {
75
94
  return `
76
95
  @media (max-width: ${getWidthForBreakpointSize("medium")}px) {
@@ -94,41 +113,68 @@ function Columns(props) {
94
113
  },
95
114
  `;
96
115
  }
116
+
97
117
  function reactNativeColumnsStyles() {
98
118
  return this.columnStyleObjects.columns.small;
99
119
  }
120
+
100
121
  function reactNativeColumnStyles() {
101
122
  return this.columnStyleObjects.column.small;
102
123
  }
103
- return <div class={`builder-columns ${props.builderBlock.id}-breakpoints` + " " + css({
104
- display: "flex",
105
- lineHeight: "normal"
106
- })} style={{
107
- ...(TARGET === "reactNative" ? reactNativeColumnsStyles() : {}),
108
- ...columnsCssVars()
109
- }}>
124
+
125
+ return (
126
+ <div
127
+ class={
128
+ `builder-columns ${props.builderBlock.id}-breakpoints` +
129
+ " " +
130
+ css({
131
+ display: "flex",
132
+ lineHeight: "normal",
133
+ })
134
+ }
135
+ style={{
136
+ ...(TARGET === "reactNative" ? reactNativeColumnsStyles() : {}),
137
+ ...columnsCssVars(),
138
+ }}
139
+ >
110
140
  <Show when={TARGET !== "reactNative"}>
111
141
  <RenderInlinedStyles styles={columnsStyles()}></RenderInlinedStyles>
112
142
  </Show>
113
143
  <For each={props.columns}>
114
144
  {(column, _index) => {
115
- const index = _index();
116
- return <div class={"builder-column " + css({
117
- display: "flex",
118
- flexDirection: "column",
119
- alignItems: "stretch"
120
- })} style={{
121
- width: getColumnCssWidth(index),
122
- "margin-left": `${index === 0 ? 0 : getGutterSize()}px`,
123
- ...(TARGET === "reactNative" ? reactNativeColumnStyles() : {}),
124
- ...columnCssVars()
125
- }} key={index}>
126
- <RenderBlocks blocks={column.blocks} path={`component.options.columns.${index}.blocks`} parent={props.builderBlock.id} styleProp={{
127
- flexGrow: "1"
128
- }}></RenderBlocks>
129
- </div>;
130
- }}
145
+ const index = _index();
146
+ return (
147
+ <div
148
+ class={
149
+ "builder-column " +
150
+ css({
151
+ display: "flex",
152
+ flexDirection: "column",
153
+ alignItems: "stretch",
154
+ })
155
+ }
156
+ style={{
157
+ width: getColumnCssWidth(index),
158
+ "margin-left": `${index === 0 ? 0 : getGutterSize()}px`,
159
+ ...(TARGET === "reactNative" ? reactNativeColumnStyles() : {}),
160
+ ...columnCssVars(),
161
+ }}
162
+ key={index}
163
+ >
164
+ <RenderBlocks
165
+ blocks={column.blocks}
166
+ path={`component.options.columns.${index}.blocks`}
167
+ parent={props.builderBlock.id}
168
+ styleProp={{
169
+ flexGrow: "1",
170
+ }}
171
+ ></RenderBlocks>
172
+ </div>
173
+ );
174
+ }}
131
175
  </For>
132
- </div>;
176
+ </div>
177
+ );
133
178
  }
134
- export default Columns;
179
+
180
+ export default Columns;
@@ -1,7 +1,10 @@
1
1
  import { onMount, createSignal } from "solid-js";
2
+
2
3
  function CustomCode(props) {
3
4
  const [scriptsInserted, setScriptsInserted] = createSignal([]);
5
+
4
6
  const [scriptsRun, setScriptsRun] = createSignal([]);
7
+
5
8
  function findAndRunScripts() {
6
9
  // TODO: Move this function to standalone one in '@builder.io/utils'
7
10
  if (elem && elem.getElementsByTagName && typeof window !== "undefined") {
@@ -17,7 +20,14 @@ function CustomCode(props) {
17
20
  newScript.async = true;
18
21
  newScript.src = script.src;
19
22
  document.head.appendChild(newScript);
20
- } else if (!script.type || ["text/javascript", "application/javascript", "application/ecmascript"].includes(script.type)) {
23
+ } else if (
24
+ !script.type ||
25
+ [
26
+ "text/javascript",
27
+ "application/javascript",
28
+ "application/ecmascript",
29
+ ].includes(script.type)
30
+ ) {
21
31
  if (scriptsRun().includes(script.innerText)) {
22
32
  continue;
23
33
  }
@@ -31,10 +41,22 @@ function CustomCode(props) {
31
41
  }
32
42
  }
33
43
  }
44
+
34
45
  let elem;
46
+
35
47
  onMount(() => {
36
48
  findAndRunScripts();
37
49
  });
38
- return <div class={"builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")} ref={elem} innerHTML={props.code}></div>;
50
+
51
+ return (
52
+ <div
53
+ class={
54
+ "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")
55
+ }
56
+ ref={elem}
57
+ innerHTML={props.code}
58
+ ></div>
59
+ );
39
60
  }
40
- export default CustomCode;
61
+
62
+ export default CustomCode;
@@ -1,9 +1,14 @@
1
1
  import { on, createEffect, createSignal } from "solid-js";
2
+
2
3
  import { isJsScript } from "./helpers.js";
4
+
3
5
  function Embed(props) {
4
6
  const [scriptsInserted, setScriptsInserted] = createSignal([]);
7
+
5
8
  const [scriptsRun, setScriptsRun] = createSignal([]);
9
+
6
10
  const [ranInitFn, setRanInitFn] = createSignal(false);
11
+
7
12
  function findAndRunScripts() {
8
13
  if (!elem || !elem.getElementsByTagName) return;
9
14
  const scripts = elem.getElementsByTagName("script");
@@ -15,7 +20,10 @@ function Embed(props) {
15
20
  newScript.async = true;
16
21
  newScript.src = script.src;
17
22
  document.head.appendChild(newScript);
18
- } else if (isJsScript(script) && !scriptsRun().includes(script.innerText)) {
23
+ } else if (
24
+ isJsScript(script) &&
25
+ !scriptsRun().includes(script.innerText)
26
+ ) {
19
27
  try {
20
28
  scriptsRun().push(script.innerText);
21
29
  new Function(script.innerText)();
@@ -25,7 +33,9 @@ function Embed(props) {
25
33
  }
26
34
  }
27
35
  }
36
+
28
37
  let elem;
38
+
29
39
  function onUpdateFn_0() {
30
40
  if (elem && !ranInitFn()) {
31
41
  setRanInitFn(true);
@@ -33,6 +43,8 @@ function Embed(props) {
33
43
  }
34
44
  }
35
45
  createEffect(on(() => [elem, ranInitFn()], onUpdateFn_0));
46
+
36
47
  return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
37
48
  }
38
- export default Embed;
49
+
50
+ export default Embed;