@builder.io/sdk-solid 0.0.8-1 → 0.0.8-10

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 (53) hide show
  1. package/package.json +11 -7
  2. package/src/blocks/button/button.jsx +1 -1
  3. package/src/blocks/button/button.lite.tsx +4 -1
  4. package/src/blocks/columns/columns.jsx +3 -3
  5. package/src/blocks/columns/columns.lite.tsx +30 -23
  6. package/src/blocks/custom-code/custom-code.jsx +1 -0
  7. package/src/blocks/custom-code/custom-code.lite.tsx +2 -0
  8. package/src/blocks/embed/embed.jsx +2 -1
  9. package/src/blocks/embed/embed.lite.tsx +3 -1
  10. package/src/blocks/form/form.jsx +1 -1
  11. package/src/blocks/form/form.lite.tsx +8 -5
  12. package/src/blocks/image/image.jsx +3 -3
  13. package/src/blocks/image/image.lite.tsx +10 -7
  14. package/src/blocks/symbol/component-info.js +1 -0
  15. package/src/blocks/symbol/symbol.jsx +2 -1
  16. package/src/blocks/symbol/symbol.lite.tsx +3 -1
  17. package/src/blocks/text/text.jsx +1 -1
  18. package/src/blocks/text/text.lite.tsx +1 -1
  19. package/src/components/render-block/render-block.helpers.js +23 -0
  20. package/src/components/render-block/render-block.jsx +28 -11
  21. package/src/components/render-block/render-block.lite.tsx +46 -11
  22. package/src/components/render-content/index.js +4 -0
  23. package/src/components/render-content/render-content.jsx +32 -7
  24. package/src/components/render-content/render-content.lite.tsx +45 -15
  25. package/src/components/render-inlined-styles.jsx +2 -1
  26. package/src/components/render-inlined-styles.lite.tsx +4 -1
  27. package/src/constants/builder-registered-components.js +45 -0
  28. package/src/context/builder.context.js +2 -1
  29. package/src/functions/fast-clone.js +4 -0
  30. package/src/functions/get-block-styles.js +2 -2
  31. package/src/functions/register-component.js +30 -13
  32. package/src/index-helpers/blocks-exports.js +9 -9
  33. package/src/solid-index.jsx +5 -0
  34. package/src/types/components.js +0 -0
  35. package/src/types/element.js +0 -0
  36. package/src/blocks/button/index.js +0 -7
  37. package/src/blocks/columns/index.js +0 -7
  38. package/src/blocks/custom-code/index.js +0 -7
  39. package/src/blocks/embed/index.js +0 -7
  40. package/src/blocks/form/index.js +0 -7
  41. package/src/blocks/fragment/index.js +0 -7
  42. package/src/blocks/image/index.js +0 -7
  43. package/src/blocks/img/index.js +0 -7
  44. package/src/blocks/input/index.js +0 -7
  45. package/src/blocks/raw-text/index.js +0 -7
  46. package/src/blocks/section/index.js +0 -7
  47. package/src/blocks/select/index.js +0 -7
  48. package/src/blocks/submit-button/index.js +0 -7
  49. package/src/blocks/symbol/index.js +0 -7
  50. package/src/blocks/text/index.js +0 -7
  51. package/src/blocks/textarea/index.js +0 -7
  52. package/src/blocks/video/index.js +0 -7
  53. package/src/functions/macro-eval.js +0 -5
package/package.json CHANGED
@@ -1,23 +1,27 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.0.8-1",
4
- "type": "module",
3
+ "version": "0.0.8-10",
5
4
  "description": "",
6
- "module": "src/index.js",
7
- "main": "src/index.js",
5
+ "type": "module",
6
+ "main": "./src/solid-index.jsx",
7
+ "module": "./src/solid-index.jsx",
8
8
  "exports": {
9
- ".": "./src/index.js"
9
+ ".": "./src/solid-index.jsx"
10
10
  },
11
11
  "scripts": {
12
12
  "release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
13
13
  },
14
14
  "dependencies": {
15
+ "node-fetch": "^2.6.7",
15
16
  "solid-styled-components": "^0.27.6"
16
17
  },
17
18
  "peerDependencies": {
18
- "solid-js": "^1.3.15"
19
+ "solid-js": "^1.4.3"
19
20
  },
20
21
  "devDependencies": {
21
- "solid-js": "^1.3.15"
22
+ "babel-preset-solid": "^1.3.17",
23
+ "solid-js": "^1.4.3",
24
+ "vite": "^2.9.8",
25
+ "vite-plugin-solid": "^2.2.6"
22
26
  }
23
27
  }
@@ -2,7 +2,7 @@ import { Show } from "solid-js";
2
2
 
3
3
  function Button(props) {
4
4
  return <>
5
- <Show when={props.link}>
5
+ <Show fallback={<span {...props.attributes}>{props.text}</span>} when={props.link}>
6
6
  <a {...props.attributes} role="button" href={props.link} target={props.openLinkInNewTab ? "_blank" : undefined}>
7
7
  {props.text}
8
8
  </a>
@@ -3,7 +3,10 @@ import { Show } from "solid-js";
3
3
  function Button(props) {
4
4
  return (
5
5
  <>
6
- <Show when={props.link}>
6
+ <Show
7
+ fallback={<span {...props.attributes}>{props.text}</span>}
8
+ when={props.link}
9
+ >
7
10
  <a
8
11
  {...props.attributes}
9
12
  role="button"
@@ -51,7 +51,7 @@ function Columns(props) {
51
51
  }
52
52
 
53
53
  });
54
- return <div class={css({
54
+ return <div class={"builder-columns " + css({
55
55
  display: "flex",
56
56
  alignItems: "stretch",
57
57
  lineHeight: "normal",
@@ -66,7 +66,7 @@ function Columns(props) {
66
66
  {(column, _index) => {
67
67
  const index = _index();
68
68
 
69
- return <div class={css({
69
+ return <div class={"builder-column " + css({
70
70
  flexGrow: "1",
71
71
  "@media (max-width: 999px)": {
72
72
  width: "var(--column-width-tablet) !important",
@@ -80,7 +80,7 @@ function Columns(props) {
80
80
  width: state.getColumnCssWidth(index),
81
81
  "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
82
82
  ...state.columnCssVars
83
- }}>
83
+ }} key={index}>
84
84
  <RenderBlocks blocks={column.blocks}></RenderBlocks>
85
85
  </div>;
86
86
  }}
@@ -24,7 +24,7 @@ function Columns(props) {
24
24
  (gutterSize * (columns.length - 1)) / columns.length;
25
25
  return `calc(${this.getWidth(index)}% - ${subtractWidth}px)`;
26
26
  },
27
- maybeApplyForTablet(prop: string) {
27
+ maybeApplyForTablet(prop: CSSProperties["flexDirection"]) {
28
28
  const _stackColumnsAt = props.stackColumnsAt || "tablet";
29
29
 
30
30
  return _stackColumnsAt === "tablet" ? prop : "inherit";
@@ -55,17 +55,20 @@ function Columns(props) {
55
55
 
56
56
  return (
57
57
  <div
58
- class={css({
59
- display: "flex",
60
- alignItems: "stretch",
61
- lineHeight: "normal",
62
- "@media (max-width: 999px)": {
63
- flexDirection: "var(--flex-dir-tablet)",
64
- },
65
- "@media (max-width: 639px)": {
66
- flexDirection: "var(--flex-dir)",
67
- },
68
- })}
58
+ class={
59
+ "builder-columns " +
60
+ css({
61
+ display: "flex",
62
+ alignItems: "stretch",
63
+ lineHeight: "normal",
64
+ "@media (max-width: 999px)": {
65
+ flexDirection: "var(--flex-dir-tablet)",
66
+ },
67
+ "@media (max-width: 639px)": {
68
+ flexDirection: "var(--flex-dir)",
69
+ },
70
+ })
71
+ }
69
72
  style={state.columnsCssVars}
70
73
  >
71
74
  <For each={props.columns}>
@@ -73,22 +76,26 @@ function Columns(props) {
73
76
  const index = _index();
74
77
  return (
75
78
  <div
76
- class={css({
77
- flexGrow: "1",
78
- "@media (max-width: 999px)": {
79
- width: "var(--column-width-tablet) !important",
80
- marginLeft: "var(--column-margin-left-tablet) !important",
81
- },
82
- "@media (max-width: 639px)": {
83
- width: "var(--column-width) !important",
84
- marginLeft: "var(--column-margin-left) !important",
85
- },
86
- })}
79
+ class={
80
+ "builder-column " +
81
+ css({
82
+ flexGrow: "1",
83
+ "@media (max-width: 999px)": {
84
+ width: "var(--column-width-tablet) !important",
85
+ marginLeft: "var(--column-margin-left-tablet) !important",
86
+ },
87
+ "@media (max-width: 639px)": {
88
+ width: "var(--column-width) !important",
89
+ marginLeft: "var(--column-margin-left) !important",
90
+ },
91
+ })
92
+ }
87
93
  style={{
88
94
  width: state.getColumnCssWidth(index),
89
95
  "margin-left": `${index === 0 ? 0 : state.getGutterSize()}px`,
90
96
  ...state.columnCssVars,
91
97
  }}
98
+ key={index}
92
99
  >
93
100
  <RenderBlocks blocks={column.blocks}></RenderBlocks>
94
101
  </div>
@@ -1,3 +1,4 @@
1
+ import { onMount } from "solid-js";
1
2
  import { createMutable } from "solid-js/store";
2
3
 
3
4
  function CustomCode(props) {
@@ -1,3 +1,5 @@
1
+ import { onMount } from "solid-js";
2
+
1
3
  import { createMutable } from "solid-js/store";
2
4
 
3
5
  function CustomCode(props) {
@@ -1,3 +1,4 @@
1
+ import { onMount } from "solid-js";
1
2
  import { createMutable } from "solid-js/store";
2
3
 
3
4
  function Embed(props) {
@@ -45,7 +46,7 @@ function Embed(props) {
45
46
  onMount(() => {
46
47
  state.findAndRunScripts();
47
48
  });
48
- return <div ref={elem} innerHTML={props.content}></div>;
49
+ return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
49
50
  }
50
51
 
51
52
  export default Embed;
@@ -1,3 +1,5 @@
1
+ import { onMount } from "solid-js";
2
+
1
3
  import { createMutable } from "solid-js/store";
2
4
 
3
5
  function Embed(props) {
@@ -53,7 +55,7 @@ function Embed(props) {
53
55
  state.findAndRunScripts();
54
56
  });
55
57
 
56
- return <div ref={elem} innerHTML={props.content}></div>;
58
+ return <div class="builder-embed" ref={elem} innerHTML={props.content}></div>;
57
59
  }
58
60
 
59
61
  export default Embed;
@@ -236,7 +236,7 @@ function FormComponent(props) {
236
236
  <BuilderBlocks dataPath="sendingMessage" blocks={props.sendingMessage}></BuilderBlocks>
237
237
  </Show>
238
238
  <Show when={state.submissionState === "error" && state.responseData}>
239
- <pre class={css({
239
+ <pre class={"builder-form-error-text " + css({
240
240
  padding: "10px",
241
241
  color: "red",
242
242
  textAlign: "center"
@@ -271,11 +271,14 @@ function FormComponent(props) {
271
271
  </Show>
272
272
  <Show when={state.submissionState === "error" && state.responseData}>
273
273
  <pre
274
- class={css({
275
- padding: "10px",
276
- color: "red",
277
- textAlign: "center",
278
- })}
274
+ class={
275
+ "builder-form-error-text " +
276
+ css({
277
+ padding: "10px",
278
+ color: "red",
279
+ textAlign: "center",
280
+ })
281
+ }
279
282
  >
280
283
  {JSON.stringify(state.responseData, null, 2)}
281
284
  </pre>
@@ -14,14 +14,14 @@ function Image(props) {
14
14
  width: "100%",
15
15
  top: "0px",
16
16
  left: "0px"
17
- })} loading="lazy" alt={props.altText} aria-role={props.altText ? "presentation" : undefined} style={{
17
+ })} loading="lazy" alt={props.altText} role={props.altText ? "presentation" : undefined} style={{
18
18
  "object-position": props.backgroundSize || "center",
19
19
  "object-fit": props.backgroundSize || "cover"
20
- }} src={props.image} srcset={props.srcset} sizes={props.sizes} />
20
+ }} src={props.image} srcSet={props.srcset} sizes={props.sizes} />
21
21
  <source srcSet={props.srcset} />
22
22
  </picture>
23
23
  <Show when={props.aspectRatio && !(props.fitContent && props.builderBlock?.children?.length)}>
24
- <div class={css({
24
+ <div class={"builder-image-sizer " + css({
25
25
  width: "100%",
26
26
  pointerEvents: "none",
27
27
  fontSize: "0"
@@ -27,13 +27,13 @@ function Image(props) {
27
27
  }
28
28
  loading="lazy"
29
29
  alt={props.altText}
30
- aria-role={props.altText ? "presentation" : undefined}
30
+ role={props.altText ? "presentation" : undefined}
31
31
  style={{
32
32
  "object-position": props.backgroundSize || "center",
33
33
  "object-fit": props.backgroundSize || "cover",
34
34
  }}
35
35
  src={props.image}
36
- srcset={props.srcset}
36
+ srcSet={props.srcset}
37
37
  sizes={props.sizes}
38
38
  />
39
39
  <source srcSet={props.srcset} />
@@ -45,11 +45,14 @@ function Image(props) {
45
45
  }
46
46
  >
47
47
  <div
48
- class={css({
49
- width: "100%",
50
- pointerEvents: "none",
51
- fontSize: "0",
52
- })}
48
+ class={
49
+ "builder-image-sizer " +
50
+ css({
51
+ width: "100%",
52
+ pointerEvents: "none",
53
+ fontSize: "0",
54
+ })
55
+ }
53
56
  style={{
54
57
  "padding-top": props.aspectRatio * 100 + "%",
55
58
  }}
@@ -2,6 +2,7 @@ const componentInfo = {
2
2
  name: "Symbol",
3
3
  noWrap: true,
4
4
  static: true,
5
+ builtIn: true,
5
6
  inputs: [
6
7
  {
7
8
  name: "symbol",
@@ -1,3 +1,4 @@
1
+ import { useContext, onMount } from "solid-js";
1
2
  import { createMutable } from "solid-js/store";
2
3
  import RenderContent from "../../components/render-content/render-content";
3
4
  import BuilderContext from "../../context/builder.context";
@@ -16,7 +17,7 @@ function Symbol(props) {
16
17
  }}>
17
18
  <RenderContent apiKey={builderContext.apiKey} context={builderContext.context} data={{ ...props.symbol?.data,
18
19
  ...builderContext.state,
19
- ...props.symbol?.state.content?.data?.state
20
+ ...props.symbol?.content?.data?.state
20
21
  }} model={props.symbol?.model} content={state.content}></RenderContent>
21
22
  </div>;
22
23
  }
@@ -1,3 +1,5 @@
1
+ import { useContext, onMount } from "solid-js";
2
+
1
3
  import { createMutable } from "solid-js/store";
2
4
 
3
5
  import RenderContent from "../../components/render-content/render-content.lite";
@@ -27,7 +29,7 @@ function Symbol(props) {
27
29
  data={{
28
30
  ...props.symbol?.data,
29
31
  ...builderContext.state,
30
- ...props.symbol?.state.content?.data?.state,
32
+ ...props.symbol?.content?.data?.state,
31
33
  }}
32
34
  model={props.symbol?.model}
33
35
  content={state.content}
@@ -1,5 +1,5 @@
1
1
  function Text(props) {
2
- return <div innerHTML={props.text}></div>;
2
+ return <div class="builder-text" innerHTML={props.text}></div>;
3
3
  }
4
4
 
5
5
  export default Text;
@@ -1,5 +1,5 @@
1
1
  function Text(props) {
2
- return <div innerHTML={props.text}></div>;
2
+ return <div class="builder-text" innerHTML={props.text}></div>;
3
3
  }
4
4
 
5
5
  export default Text;
@@ -0,0 +1,23 @@
1
+ const EMPTY_HTML_ELEMENTS = [
2
+ "area",
3
+ "base",
4
+ "br",
5
+ "col",
6
+ "embed",
7
+ "hr",
8
+ "img",
9
+ "input",
10
+ "keygen",
11
+ "link",
12
+ "meta",
13
+ "param",
14
+ "source",
15
+ "track",
16
+ "wbr"
17
+ ];
18
+ const isEmptyHtmlElement = (tagName) => {
19
+ return typeof tagName === "string" && EMPTY_HTML_ELEMENTS.includes(tagName.toLowerCase());
20
+ };
21
+ export {
22
+ isEmptyHtmlElement
23
+ };
@@ -9,8 +9,8 @@ import { getBlockProperties } from "../../functions/get-block-properties.js";
9
9
  import { getBlockStyles } from "../../functions/get-block-styles.js";
10
10
  import { getBlockTag } from "../../functions/get-block-tag.js";
11
11
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
12
- import { components } from "../../functions/register-component.js";
13
12
  import BlockStyles from "./block-styles";
13
+ import { isEmptyHtmlElement } from "./render-block.helpers.js";
14
14
 
15
15
  function RenderBlock(props) {
16
16
  const state = createMutable({
@@ -21,20 +21,29 @@ function RenderBlock(props) {
21
21
  return null;
22
22
  }
23
23
 
24
- const ref = components[componentName];
24
+ const ref = builderContext.registeredComponents[componentName];
25
25
 
26
- if (componentName && !ref) {
26
+ if (!ref) {
27
27
  // TODO: Public doc page with more info about this message
28
28
  console.warn(`
29
29
  Could not find a registered component named "${componentName}".
30
30
  If you registered it, is the file that registered it imported by the file that needs to render it?`);
31
+ return undefined;
32
+ } else {
33
+ return ref;
31
34
  }
32
-
33
- return ref;
34
35
  },
35
36
 
36
37
  get componentInfo() {
37
- return state.component?.info;
38
+ if (state.component) {
39
+ const {
40
+ component: _,
41
+ ...info
42
+ } = state.component;
43
+ return info;
44
+ } else {
45
+ return undefined;
46
+ }
38
47
  },
39
48
 
40
49
  get componentRef() {
@@ -85,8 +94,16 @@ function RenderBlock(props) {
85
94
 
86
95
  });
87
96
  const builderContext = useContext(BuilderContext);
88
- return <>
89
- <Show when={!state.componentInfo?.noWrap}>
97
+ return <Show fallback={<Dynamic {...state.componentOptions} attributes={state.propertiesAndActions} builderBlock={state.useBlock} style={state.css} component={state.componentRef}>
98
+ <For each={state.children}>
99
+ {(child, _index) => {
100
+ const index = _index();
101
+
102
+ return <RenderBlock key={child.id} block={child}></RenderBlock>;
103
+ }}
104
+ </For>
105
+ </Dynamic>} when={!state.componentInfo?.noWrap}>
106
+ <Show fallback={<Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
90
107
  <Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}>
91
108
  <Show when={TARGET === "vue" || TARGET === "svelte"}>
92
109
  <BlockStyles block={state.useBlock}></BlockStyles>
@@ -97,7 +114,7 @@ function RenderBlock(props) {
97
114
  {(child, _index) => {
98
115
  const index = _index();
99
116
 
100
- return <RenderBlock block={child}></RenderBlock>;
117
+ return <RenderBlock key={child.id} block={child}></RenderBlock>;
101
118
  }}
102
119
  </For>
103
120
  </Dynamic>
@@ -106,12 +123,12 @@ function RenderBlock(props) {
106
123
  {(child, _index) => {
107
124
  const index = _index();
108
125
 
109
- return <RenderBlock block={child}></RenderBlock>;
126
+ return <RenderBlock key={child.id} block={child}></RenderBlock>;
110
127
  }}
111
128
  </For>
112
129
  </Dynamic>
113
130
  </Show>
114
- </>;
131
+ </Show>;
115
132
  }
116
133
 
117
134
  export default RenderBlock;
@@ -10,8 +10,8 @@ import { getBlockProperties } from "../../functions/get-block-properties.js";
10
10
  import { getBlockStyles } from "../../functions/get-block-styles.js";
11
11
  import { getBlockTag } from "../../functions/get-block-tag.js";
12
12
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
13
- import { components } from "../../functions/register-component.js";
14
13
  import BlockStyles from "./block-styles.lite";
14
+ import { isEmptyHtmlElement } from "./render-block.helpers.js";
15
15
 
16
16
  function RenderBlock(props) {
17
17
  const state = createMutable({
@@ -22,19 +22,25 @@ function RenderBlock(props) {
22
22
  return null;
23
23
  }
24
24
 
25
- const ref = components[componentName];
25
+ const ref = builderContext.registeredComponents[componentName];
26
26
 
27
- if (componentName && !ref) {
27
+ if (!ref) {
28
28
  // TODO: Public doc page with more info about this message
29
29
  console.warn(`
30
30
  Could not find a registered component named "${componentName}".
31
31
  If you registered it, is the file that registered it imported by the file that needs to render it?`);
32
+ return undefined;
33
+ } else {
34
+ return ref;
32
35
  }
33
-
34
- return ref;
35
36
  },
36
37
  get componentInfo() {
37
- return state.component?.info;
38
+ if (state.component) {
39
+ const { component: _, ...info } = state.component;
40
+ return info;
41
+ } else {
42
+ return undefined;
43
+ }
38
44
  },
39
45
  get componentRef() {
40
46
  return state.component?.component;
@@ -80,8 +86,35 @@ function RenderBlock(props) {
80
86
  const builderContext = useContext(BuilderContext);
81
87
 
82
88
  return (
83
- <>
84
- <Show when={!state.componentInfo?.noWrap}>
89
+ <Show
90
+ fallback={
91
+ <Dynamic
92
+ {...state.componentOptions}
93
+ attributes={state.propertiesAndActions}
94
+ builderBlock={state.useBlock}
95
+ style={state.css}
96
+ component={state.componentRef}
97
+ >
98
+ <For each={state.children}>
99
+ {(child, _index) => {
100
+ const index = _index();
101
+ return <RenderBlock key={child.id} block={child}></RenderBlock>;
102
+ }}
103
+ </For>
104
+ </Dynamic>
105
+ }
106
+ when={!state.componentInfo?.noWrap}
107
+ >
108
+ <Show
109
+ fallback={
110
+ <Dynamic
111
+ {...state.propertiesAndActions}
112
+ style={state.css}
113
+ component={state.tagName}
114
+ ></Dynamic>
115
+ }
116
+ when={!isEmptyHtmlElement(state.tagName)}
117
+ >
85
118
  <Dynamic
86
119
  {...state.propertiesAndActions}
87
120
  style={state.css}
@@ -99,7 +132,9 @@ function RenderBlock(props) {
99
132
  <For each={state.children}>
100
133
  {(child, _index) => {
101
134
  const index = _index();
102
- return <RenderBlock block={child}></RenderBlock>;
135
+ return (
136
+ <RenderBlock key={child.id} block={child}></RenderBlock>
137
+ );
103
138
  }}
104
139
  </For>
105
140
  </Dynamic>
@@ -107,12 +142,12 @@ function RenderBlock(props) {
107
142
  <For each={state.noCompRefChildren}>
108
143
  {(child, _index) => {
109
144
  const index = _index();
110
- return <RenderBlock block={child}></RenderBlock>;
145
+ return <RenderBlock key={child.id} block={child}></RenderBlock>;
111
146
  }}
112
147
  </For>
113
148
  </Dynamic>
114
149
  </Show>
115
- </>
150
+ </Show>
116
151
  );
117
152
  }
118
153
 
@@ -0,0 +1,4 @@
1
+ import { default as default2 } from "./render-content.jsx";
2
+ export {
3
+ default2 as default
4
+ };
@@ -1,6 +1,7 @@
1
1
  import { Show, onMount } from "solid-js";
2
2
  import { Dynamic } from "solid-js/web";
3
3
  import { createMutable } from "solid-js/store";
4
+ import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
4
5
  import { TARGET } from "../../constants/target.js";
5
6
  import BuilderContext from "../../context/builder.context";
6
7
  import { evaluate } from "../../functions/evaluate.js";
@@ -11,6 +12,7 @@ import { isBrowser } from "../../functions/is-browser.js";
11
12
  import { isEditing } from "../../functions/is-editing.js";
12
13
  import { isPreviewing } from "../../functions/is-previewing.js";
13
14
  import { previewingModelName } from "../../functions/previewing-model-name.js";
15
+ import { components, createRegisterComponentMessage } from "../../functions/register-component.js";
14
16
  import { track } from "../../functions/track.js";
15
17
  import RenderBlocks from "../render-blocks";
16
18
  import RenderContentStyles from "./components/render-styles";
@@ -43,6 +45,19 @@ function RenderContent(props) {
43
45
  return {};
44
46
  },
45
47
 
48
+ get allRegisteredComponents() {
49
+ const allComponentsArray = [...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
50
+ // Since users are able to override our default components, we need to make sure that we do not break such
51
+ // existing usage.
52
+ // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
53
+ // which is the new standard way of providing custom components, and must therefore take precedence.
54
+ ...components, ...(props.customComponents || [])];
55
+ const allComponents = allComponentsArray.reduce((acc, curr) => ({ ...acc,
56
+ [curr.name]: curr
57
+ }), {});
58
+ return allComponents;
59
+ },
60
+
46
61
  processMessage(event) {
47
62
  const {
48
63
  data
@@ -128,20 +143,26 @@ function RenderContent(props) {
128
143
  },
129
144
 
130
145
  emitStateUpdate() {
131
- window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
132
- detail: {
133
- state: state.contentState,
134
- ref: {
135
- name: props.model
146
+ if (isEditing()) {
147
+ window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
148
+ detail: {
149
+ state: state.contentState,
150
+ ref: {
151
+ name: props.model
152
+ }
136
153
  }
137
- }
138
- }));
154
+ }));
155
+ }
139
156
  }
140
157
 
141
158
  });
142
159
  onMount(() => {
143
160
  if (isBrowser()) {
144
161
  if (isEditing()) {
162
+ Object.values(state.allRegisteredComponents).forEach(registeredComponent => {
163
+ const message = createRegisterComponentMessage(registeredComponent);
164
+ window.parent?.postMessage(message, "*");
165
+ });
145
166
  window.addEventListener("message", state.processMessage);
146
167
  window.addEventListener("builder:component:stateChangeListenerActivated", state.emitStateUpdate);
147
168
  }
@@ -192,6 +213,10 @@ function RenderContent(props) {
192
213
 
193
214
  get apiKey() {
194
215
  return props.apiKey;
216
+ },
217
+
218
+ get registeredComponents() {
219
+ return state.allRegisteredComponents;
195
220
  }
196
221
 
197
222
  }} component={BuilderContext.Provider}>
@@ -2,6 +2,7 @@ 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 { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
5
6
  import { TARGET } from "../../constants/target.js";
6
7
  import BuilderContext from "../../context/builder.context";
7
8
  import { evaluate } from "../../functions/evaluate.js";
@@ -15,6 +16,10 @@ import { isBrowser } from "../../functions/is-browser.js";
15
16
  import { isEditing } from "../../functions/is-editing.js";
16
17
  import { isPreviewing } from "../../functions/is-previewing.js";
17
18
  import { previewingModelName } from "../../functions/previewing-model-name.js";
19
+ import {
20
+ components,
21
+ createRegisterComponentMessage,
22
+ } from "../../functions/register-component.js";
18
23
  import { track } from "../../functions/track.js";
19
24
  import RenderBlocks from "../render-blocks.lite";
20
25
  import RenderContentStyles from "./components/render-styles.lite";
@@ -44,9 +49,23 @@ function RenderContent(props) {
44
49
  };
45
50
  },
46
51
  get context() {
47
- return {} as {
48
- [index: string]: any;
49
- };
52
+ return {} as Dictionary<any>;
53
+ },
54
+ get allRegisteredComponents() {
55
+ const allComponentsArray = [
56
+ ...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
57
+ // Since users are able to override our default components, we need to make sure that we do not break such
58
+ // existing usage.
59
+ // This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
60
+ // which is the new standard way of providing custom components, and must therefore take precedence.
61
+ ...components,
62
+ ...(props.customComponents || []),
63
+ ];
64
+ const allComponents = allComponentsArray.reduce(
65
+ (acc, curr) => ({ ...acc, [curr.name]: curr }),
66
+ {} as RegisteredComponents
67
+ );
68
+ return allComponents;
50
69
  },
51
70
  processMessage(event: MessageEvent) {
52
71
  const { data } = event;
@@ -124,25 +143,33 @@ function RenderContent(props) {
124
143
  });
125
144
  },
126
145
  emitStateUpdate() {
127
- window.dispatchEvent(
128
- new CustomEvent<BuilderComponentStateChange>(
129
- "builder:component:stateChange",
130
- {
131
- detail: {
132
- state: state.contentState,
133
- ref: {
134
- name: props.model,
146
+ if (isEditing()) {
147
+ window.dispatchEvent(
148
+ new CustomEvent<BuilderComponentStateChange>(
149
+ "builder:component:stateChange",
150
+ {
151
+ detail: {
152
+ state: state.contentState,
153
+ ref: {
154
+ name: props.model,
155
+ },
135
156
  },
136
- },
137
- }
138
- )
139
- );
157
+ }
158
+ )
159
+ );
160
+ }
140
161
  },
141
162
  });
142
163
 
143
164
  onMount(() => {
144
165
  if (isBrowser()) {
145
166
  if (isEditing()) {
167
+ Object.values(state.allRegisteredComponents).forEach(
168
+ (registeredComponent) => {
169
+ const message = createRegisterComponentMessage(registeredComponent);
170
+ window.parent?.postMessage(message, "*");
171
+ }
172
+ );
146
173
  window.addEventListener("message", state.processMessage);
147
174
  window.addEventListener(
148
175
  "builder:component:stateChangeListenerActivated",
@@ -198,6 +225,9 @@ function RenderContent(props) {
198
225
  get apiKey() {
199
226
  return props.apiKey;
200
227
  },
228
+ get registeredComponents() {
229
+ return state.allRegisteredComponents;
230
+ },
201
231
  }}
202
232
  component={BuilderContext.Provider}
203
233
  >
@@ -1,4 +1,5 @@
1
1
  import { Show } from "solid-js";
2
+ import { Dynamic } from "solid-js/web";
2
3
  import { createMutable } from "solid-js/store";
3
4
  import { TARGET } from "../constants/target.js";
4
5
 
@@ -15,7 +16,7 @@ function RenderInlinedStyles(props) {
15
16
  }
16
17
 
17
18
  });
18
- return <Show when={TARGET === "svelte"}>
19
+ return <Show fallback={<Dynamic component={state.tagName}>{props.styles}</Dynamic>} when={TARGET === "svelte"}>
19
20
  <div innerHTML={state.injectedStyleScript}></div>
20
21
  </Show>;
21
22
  }
@@ -17,7 +17,10 @@ function RenderInlinedStyles(props) {
17
17
  });
18
18
 
19
19
  return (
20
- <Show when={TARGET === "svelte"}>
20
+ <Show
21
+ fallback={<Dynamic component={state.tagName}>{props.styles}</Dynamic>}
22
+ when={TARGET === "svelte"}
23
+ >
21
24
  <div innerHTML={state.injectedStyleScript}></div>
22
25
  </Show>
23
26
  );
@@ -0,0 +1,45 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
6
+ var __spreadValues = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ import { default as Button } from "../blocks/button/button.jsx";
18
+ import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
19
+ import { default as Columns } from "../blocks/columns/columns.jsx";
20
+ import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info";
21
+ import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info";
22
+ import { default as Fragment } from "../blocks/fragment/fragment.jsx";
23
+ import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
24
+ import { default as Image } from "../blocks/image/image.jsx";
25
+ import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
26
+ import { default as Section } from "../blocks/section/section.jsx";
27
+ import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
28
+ import { default as Symbol } from "../blocks/symbol/symbol.jsx";
29
+ import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
30
+ import { default as Text } from "../blocks/text/text.jsx";
31
+ import { componentInfo as videoComponentInfo } from "../blocks/video/component-info";
32
+ import { default as Video } from "../blocks/video/video.jsx";
33
+ const getDefaultRegisteredComponents = () => [
34
+ __spreadValues({ component: Columns }, columnsComponentInfo),
35
+ __spreadValues({ component: Image }, imageComponentInfo),
36
+ __spreadValues({ component: Text }, textComponentInfo),
37
+ __spreadValues({ component: Video }, videoComponentInfo),
38
+ __spreadValues({ component: Symbol }, symbolComponentInfo),
39
+ __spreadValues({ component: Button }, buttonComponentInfo),
40
+ __spreadValues({ component: Section }, sectionComponentInfo),
41
+ __spreadValues({ component: Fragment }, fragmentComponentInfo)
42
+ ];
43
+ export {
44
+ getDefaultRegisteredComponents
45
+ };
@@ -3,7 +3,8 @@ var stdin_default = createContext({
3
3
  content: null,
4
4
  context: {},
5
5
  state: {},
6
- apiKey: null
6
+ apiKey: null,
7
+ registeredComponents: {}
7
8
  });
8
9
  export {
9
10
  stdin_default as default
@@ -0,0 +1,4 @@
1
+ const fastClone = (obj) => JSON.parse(JSON.stringify(obj));
2
+ export {
3
+ fastClone
4
+ };
@@ -30,10 +30,10 @@ function getBlockStyles(block) {
30
30
  var _a, _b, _c, _d, _e;
31
31
  const styles = __spreadValues({}, convertStyleObject((_a = block.responsiveStyles) == null ? void 0 : _a.large));
32
32
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
33
- styles[`@media (max-width: ${sizes.medium})`] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
33
+ styles[`@media (max-width: ${sizes.medium.max})`] = convertStyleObject((_c = block.responsiveStyles) == null ? void 0 : _c.medium);
34
34
  }
35
35
  if ((_d = block.responsiveStyles) == null ? void 0 : _d.small) {
36
- styles[`@media (max-width: ${sizes.small})`] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
36
+ styles[`@media (max-width: ${sizes.small.max})`] = convertStyleObject((_e = block.responsiveStyles) == null ? void 0 : _e.small);
37
37
  }
38
38
  return styles;
39
39
  }
@@ -17,27 +17,43 @@ var __spreadValues = (a, b) => {
17
17
  return a;
18
18
  };
19
19
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
20
- import { isBrowser } from "./is-browser.js";
21
- const components = {};
20
+ var __objRest = (source, exclude) => {
21
+ var target = {};
22
+ for (var prop in source)
23
+ if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
24
+ target[prop] = source[prop];
25
+ if (source != null && __getOwnPropSymbols)
26
+ for (var prop of __getOwnPropSymbols(source)) {
27
+ if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
28
+ target[prop] = source[prop];
29
+ }
30
+ return target;
31
+ };
32
+ import { fastClone } from "./fast-clone.js";
33
+ const components = [];
22
34
  function registerComponent(component, info) {
23
- var _a;
24
- components[info.name] = { component, info };
25
- if (isBrowser()) {
26
- const sendInfo = prepareComponentInfoToSend(info);
27
- (_a = window.parent) == null ? void 0 : _a.postMessage({
28
- type: "builder.registerComponent",
29
- data: sendInfo
30
- }, "*");
31
- }
35
+ components.push(__spreadValues({ component }, info));
36
+ console.warn("registerComponent is deprecated. Use the `customComponents` prop in RenderContent instead to provide your custom components to the builder SDK.");
32
37
  return component;
33
38
  }
39
+ const createRegisterComponentMessage = (_a) => {
40
+ var _b = _a, {
41
+ component
42
+ } = _b, info = __objRest(_b, [
43
+ "component"
44
+ ]);
45
+ return {
46
+ type: "builder.registerComponent",
47
+ data: prepareComponentInfoToSend(fastClone(info))
48
+ };
49
+ };
34
50
  function prepareComponentInfoToSend(info) {
35
51
  return __spreadValues(__spreadValues({}, info), info.inputs && {
36
52
  inputs: info.inputs.map((input) => {
37
53
  const keysToConvertFnToString = ["onChange", "showIf"];
38
54
  for (const key of keysToConvertFnToString) {
39
- if (input[key] && typeof input[key] === "function") {
40
- const fn = input[key];
55
+ const fn = input[key];
56
+ if (fn && typeof fn === "function") {
41
57
  input = __spreadProps(__spreadValues({}, input), {
42
58
  [key]: `return (${fn.toString()}).apply(this, arguments)`
43
59
  });
@@ -49,5 +65,6 @@ function prepareComponentInfoToSend(info) {
49
65
  }
50
66
  export {
51
67
  components,
68
+ createRegisterComponentMessage,
52
69
  registerComponent
53
70
  };
@@ -1,12 +1,12 @@
1
- import { default as default2 } from "../blocks/columns/index.js";
2
- import { default as default3 } from "../blocks/image/index.js";
3
- import { default as default4 } from "../blocks/text/index.js";
4
- import { default as default5 } from "../blocks/video/index.js";
5
- import { default as default6 } from "../blocks/symbol/index.js";
6
- import { default as default7 } from "../blocks/button/index.js";
7
- import { default as default8 } from "../blocks/section/index.js";
8
- import { default as default9 } from "../blocks/fragment/index.js";
9
- import { default as default10 } from "../components/render-content/render-content";
1
+ import { default as default2 } from "../blocks/columns/columns.jsx";
2
+ import { default as default3 } from "../blocks/image/image.jsx";
3
+ import { default as default4 } from "../blocks/text/text.jsx";
4
+ import { default as default5 } from "../blocks/video/video.jsx";
5
+ import { default as default6 } from "../blocks/symbol/symbol.jsx";
6
+ import { default as default7 } from "../blocks/button/button.jsx";
7
+ import { default as default8 } from "../blocks/section/section.jsx";
8
+ import { default as default9 } from "../blocks/fragment/fragment.jsx";
9
+ import { default as default10 } from "../components/render-content/render-content.jsx";
10
10
  export {
11
11
  default7 as Button,
12
12
  default2 as Columns,
@@ -0,0 +1,5 @@
1
+ /**
2
+ * We need to have a `.jsx` entry point for our SolidJS SDK. To avoid enforcing this to all other frameworks,
3
+ * we add this file and use it to re-export the index.js file from the Mitosis-generated code.
4
+ */
5
+ export * from '../src/index.js';
File without changes
File without changes
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import component from "./button";
3
- import { componentInfo } from "./component-info.js";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import component from "./columns";
3
- import { componentInfo } from "./component-info.js";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./custom-code";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./embed";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./form";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./fragment";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./image";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./img";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./input";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./raw-text";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./section";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./select";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./submit-button";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./symbol";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./text";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./textarea";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,7 +0,0 @@
1
- import { registerComponent } from "../../functions/register-component.js";
2
- import { componentInfo } from "./component-info.js";
3
- import component from "./video";
4
- var stdin_default = registerComponent(component, componentInfo);
5
- export {
6
- stdin_default as default
7
- };
@@ -1,5 +0,0 @@
1
- function macroEval(items, string) {
2
- }
3
- export {
4
- macroEval
5
- };