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

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.8-10",
3
+ "version": "0.0.8-11",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./src/solid-index.jsx",
@@ -1,21 +1,33 @@
1
+ import { useContext, Show } from "solid-js";
1
2
  import { createMutable } from "solid-js/store";
3
+ import { TARGET } from "../../constants/target.js";
4
+ import BuilderContext from "../../context/builder.context";
5
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
2
6
  import RenderInlinedStyles from "../render-inlined-styles";
3
7
 
4
8
  function BlockStyles(props) {
5
9
  const state = createMutable({
10
+ get useBlock() {
11
+ return getProcessedBlock({
12
+ block: props.block,
13
+ state: builderContext.state,
14
+ context: builderContext.context
15
+ });
16
+ },
17
+
6
18
  camelToKebabCase(string) {
7
19
  return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2").toLowerCase();
8
20
  },
9
21
 
10
22
  get css() {
11
23
  // TODO: media queries
12
- const styleObject = props.block.responsiveStyles?.large;
24
+ const styleObject = state.useBlock.responsiveStyles?.large;
13
25
 
14
26
  if (!styleObject) {
15
27
  return "";
16
28
  }
17
29
 
18
- let str = `.${props.block.id} {`;
30
+ let str = `.${state.useBlock.id} {`;
19
31
 
20
32
  for (const key in styleObject) {
21
33
  const value = styleObject[key];
@@ -30,7 +42,10 @@ function BlockStyles(props) {
30
42
  }
31
43
 
32
44
  });
33
- return <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>;
45
+ const builderContext = useContext(BuilderContext);
46
+ return <Show when={TARGET === "vue" || TARGET === "svelte"}>
47
+ <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
48
+ </Show>;
34
49
  }
35
50
 
36
51
  export default BlockStyles;
@@ -1,9 +1,21 @@
1
+ import { useContext, Show } from "solid-js";
2
+
1
3
  import { createMutable } from "solid-js/store";
2
4
 
5
+ import { TARGET } from "../../constants/target.js";
6
+ import BuilderContext from "../../context/builder.context";
7
+ import { getProcessedBlock } from "../../functions/get-processed-block.js";
3
8
  import RenderInlinedStyles from "../render-inlined-styles.lite";
4
9
 
5
10
  function BlockStyles(props) {
6
11
  const state = createMutable({
12
+ get useBlock() {
13
+ return getProcessedBlock({
14
+ block: props.block,
15
+ state: builderContext.state,
16
+ context: builderContext.context,
17
+ });
18
+ },
7
19
  camelToKebabCase(string: string) {
8
20
  return string
9
21
  .replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, "$1-$2")
@@ -11,13 +23,13 @@ function BlockStyles(props) {
11
23
  },
12
24
  get css() {
13
25
  // TODO: media queries
14
- const styleObject = props.block.responsiveStyles?.large;
26
+ const styleObject = state.useBlock.responsiveStyles?.large;
15
27
 
16
28
  if (!styleObject) {
17
29
  return "";
18
30
  }
19
31
 
20
- let str = `.${props.block.id} {`;
32
+ let str = `.${state.useBlock.id} {`;
21
33
 
22
34
  for (const key in styleObject) {
23
35
  const value = styleObject[key];
@@ -32,7 +44,13 @@ function BlockStyles(props) {
32
44
  },
33
45
  });
34
46
 
35
- return <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>;
47
+ const builderContext = useContext(BuilderContext);
48
+
49
+ return (
50
+ <Show when={TARGET === "vue" || TARGET === "svelte"}>
51
+ <RenderInlinedStyles styles={state.css}></RenderInlinedStyles>
52
+ </Show>
53
+ );
36
54
  }
37
55
 
38
56
  export default BlockStyles;
@@ -1,7 +1,6 @@
1
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
- import { TARGET } from "../../constants/target.js";
5
4
  import BuilderContext from "../../context/builder.context";
6
5
  import { getBlockActions } from "../../functions/get-block-actions.js";
7
6
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
@@ -11,6 +10,7 @@ import { getBlockTag } from "../../functions/get-block-tag.js";
11
10
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
12
11
  import BlockStyles from "./block-styles";
13
12
  import { isEmptyHtmlElement } from "./render-block.helpers.js";
13
+ import RenderComponent from "./render-component";
14
14
 
15
15
  function RenderBlock(props) {
16
16
  const state = createMutable({
@@ -62,22 +62,32 @@ function RenderBlock(props) {
62
62
  });
63
63
  },
64
64
 
65
- get propertiesAndActions() {
65
+ get attributes() {
66
66
  return { ...getBlockProperties(state.useBlock),
67
67
  ...getBlockActions({
68
68
  block: state.useBlock,
69
69
  state: builderContext.state,
70
70
  context: builderContext.context
71
- })
71
+ }),
72
+ style: getBlockStyles(state.useBlock)
72
73
  };
73
74
  },
74
75
 
75
- get css() {
76
- return getBlockStyles(state.useBlock);
76
+ get shouldWrap() {
77
+ return !state.componentInfo?.noWrap;
77
78
  },
78
79
 
79
80
  get componentOptions() {
80
- return getBlockComponentOptions(state.useBlock);
81
+ return { ...getBlockComponentOptions(state.useBlock),
82
+
83
+ /**
84
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
85
+ * they are provided to the component itself directly.
86
+ */
87
+ ...(state.shouldWrap ? {} : {
88
+ attributes: state.attributes
89
+ })
90
+ };
81
91
  },
82
92
 
83
93
  get children() {
@@ -89,41 +99,31 @@ function RenderBlock(props) {
89
99
  },
90
100
 
91
101
  get noCompRefChildren() {
102
+ /**
103
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
104
+ * we render them outside of `componentRef`
105
+ */
92
106
  return state.componentRef ? [] : state.children;
93
107
  }
94
108
 
95
109
  });
96
110
  const builderContext = useContext(BuilderContext);
97
- return <Show fallback={<Dynamic {...state.componentOptions} attributes={state.propertiesAndActions} builderBlock={state.useBlock} style={state.css} component={state.componentRef}>
98
- <For each={state.children}>
111
+ return <Show fallback={<RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>} when={state.shouldWrap}>
112
+ <Show fallback={<Dynamic {...state.attributes} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
113
+ <Dynamic {...state.attributes} component={state.tagName}>
114
+ <RenderComponent blockChildren={state.children} componentRef={state.componentRef} componentOptions={state.componentOptions}></RenderComponent>
115
+ <For each={state.noCompRefChildren}>
99
116
  {(child, _index) => {
100
- const index = _index();
117
+ const index = _index();
101
118
 
102
- return <RenderBlock key={child.id} block={child}></RenderBlock>;
103
- }}
119
+ return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
120
+ }}
104
121
  </For>
105
- </Dynamic>} when={!state.componentInfo?.noWrap}>
106
- <Show fallback={<Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}></Dynamic>} when={!isEmptyHtmlElement(state.tagName)}>
107
- <Dynamic {...state.propertiesAndActions} style={state.css} component={state.tagName}>
108
- <Show when={TARGET === "vue" || TARGET === "svelte"}>
109
- <BlockStyles block={state.useBlock}></BlockStyles>
110
- </Show>
111
- <Show when={state.componentRef}>
112
- <Dynamic {...state.componentOptions} builderBlock={state.useBlock} component={state.componentRef}>
113
- <For each={state.children}>
114
- {(child, _index) => {
115
- const index = _index();
116
-
117
- return <RenderBlock key={child.id} block={child}></RenderBlock>;
118
- }}
119
- </For>
120
- </Dynamic>
121
- </Show>
122
122
  <For each={state.noCompRefChildren}>
123
123
  {(child, _index) => {
124
124
  const index = _index();
125
125
 
126
- return <RenderBlock key={child.id} block={child}></RenderBlock>;
126
+ return <BlockStyles key={"block-style-" + child.id} block={child}></BlockStyles>;
127
127
  }}
128
128
  </For>
129
129
  </Dynamic>
@@ -2,7 +2,6 @@ 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
 
5
- import { TARGET } from "../../constants/target.js";
6
5
  import BuilderContext from "../../context/builder.context";
7
6
  import { getBlockActions } from "../../functions/get-block-actions.js";
8
7
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
@@ -12,6 +11,7 @@ import { getBlockTag } from "../../functions/get-block-tag.js";
12
11
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
13
12
  import BlockStyles from "./block-styles.lite";
14
13
  import { isEmptyHtmlElement } from "./render-block.helpers.js";
14
+ import RenderComponent from "./render-component.lite";
15
15
 
16
16
  function RenderBlock(props) {
17
17
  const state = createMutable({
@@ -55,7 +55,7 @@ function RenderBlock(props) {
55
55
  context: builderContext.context,
56
56
  });
57
57
  },
58
- get propertiesAndActions() {
58
+ get attributes() {
59
59
  return {
60
60
  ...getBlockProperties(state.useBlock),
61
61
  ...getBlockActions({
@@ -63,13 +63,26 @@ function RenderBlock(props) {
63
63
  state: builderContext.state,
64
64
  context: builderContext.context,
65
65
  }),
66
+ style: getBlockStyles(state.useBlock),
66
67
  };
67
68
  },
68
- get css() {
69
- return getBlockStyles(state.useBlock);
69
+ get shouldWrap() {
70
+ return !state.componentInfo?.noWrap;
70
71
  },
71
72
  get componentOptions() {
72
- return getBlockComponentOptions(state.useBlock);
73
+ return {
74
+ ...getBlockComponentOptions(state.useBlock),
75
+
76
+ /**
77
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
78
+ * they are provided to the component itself directly.
79
+ */
80
+ ...(state.shouldWrap
81
+ ? {}
82
+ : {
83
+ attributes: state.attributes,
84
+ }),
85
+ };
73
86
  },
74
87
  get children() {
75
88
  // TO-DO: When should `canHaveChildren` dictate rendering?
@@ -79,6 +92,10 @@ function RenderBlock(props) {
79
92
  return state.useBlock.children ?? [];
80
93
  },
81
94
  get noCompRefChildren() {
95
+ /**
96
+ * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
97
+ * we render them outside of `componentRef`
98
+ */
82
99
  return state.componentRef ? [] : state.children;
83
100
  },
84
101
  });
@@ -88,61 +105,46 @@ function RenderBlock(props) {
88
105
  return (
89
106
  <Show
90
107
  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>
108
+ <RenderComponent
109
+ blockChildren={state.children}
110
+ componentRef={state.componentRef}
111
+ componentOptions={state.componentOptions}
112
+ ></RenderComponent>
105
113
  }
106
- when={!state.componentInfo?.noWrap}
114
+ when={state.shouldWrap}
107
115
  >
108
116
  <Show
109
117
  fallback={
110
- <Dynamic
111
- {...state.propertiesAndActions}
112
- style={state.css}
113
- component={state.tagName}
114
- ></Dynamic>
118
+ <Dynamic {...state.attributes} component={state.tagName}></Dynamic>
115
119
  }
116
120
  when={!isEmptyHtmlElement(state.tagName)}
117
121
  >
118
- <Dynamic
119
- {...state.propertiesAndActions}
120
- style={state.css}
121
- component={state.tagName}
122
- >
123
- <Show when={TARGET === "vue" || TARGET === "svelte"}>
124
- <BlockStyles block={state.useBlock}></BlockStyles>
125
- </Show>
126
- <Show when={state.componentRef}>
127
- <Dynamic
128
- {...state.componentOptions}
129
- builderBlock={state.useBlock}
130
- component={state.componentRef}
131
- >
132
- <For each={state.children}>
133
- {(child, _index) => {
134
- const index = _index();
135
- return (
136
- <RenderBlock key={child.id} block={child}></RenderBlock>
137
- );
138
- }}
139
- </For>
140
- </Dynamic>
141
- </Show>
122
+ <Dynamic {...state.attributes} component={state.tagName}>
123
+ <RenderComponent
124
+ blockChildren={state.children}
125
+ componentRef={state.componentRef}
126
+ componentOptions={state.componentOptions}
127
+ ></RenderComponent>
128
+ <For each={state.noCompRefChildren}>
129
+ {(child, _index) => {
130
+ const index = _index();
131
+ return (
132
+ <RenderBlock
133
+ key={"render-block-" + child.id}
134
+ block={child}
135
+ ></RenderBlock>
136
+ );
137
+ }}
138
+ </For>
142
139
  <For each={state.noCompRefChildren}>
143
140
  {(child, _index) => {
144
141
  const index = _index();
145
- return <RenderBlock key={child.id} block={child}></RenderBlock>;
142
+ return (
143
+ <BlockStyles
144
+ key={"block-style-" + child.id}
145
+ block={child}
146
+ ></BlockStyles>
147
+ );
146
148
  }}
147
149
  </For>
148
150
  </Dynamic>
@@ -0,0 +1,27 @@
1
+ import { Show, For } from "solid-js";
2
+ import { Dynamic } from "solid-js/web";
3
+ import BlockStyles from "./block-styles";
4
+ import RenderBlock from "./render-block";
5
+
6
+ function RenderComponent(props) {
7
+ return <Show when={props.componentRef}>
8
+ <Dynamic {...props.componentOptions} component={props.componentRef}>
9
+ <For each={props.blockChildren}>
10
+ {(child, _index) => {
11
+ const index = _index();
12
+
13
+ return <RenderBlock key={"render-block-" + child.id} block={child}></RenderBlock>;
14
+ }}
15
+ </For>
16
+ <For each={props.blockChildren}>
17
+ {(child, _index) => {
18
+ const index = _index();
19
+
20
+ return <BlockStyles key={"block-style-" + child.id} block={child}></BlockStyles>;
21
+ }}
22
+ </For>
23
+ </Dynamic>
24
+ </Show>;
25
+ }
26
+
27
+ export default RenderComponent;
@@ -0,0 +1,38 @@
1
+ import { Show, For } from "solid-js";
2
+ import { Dynamic } from "solid-js/web";
3
+
4
+ import BlockStyles from "./block-styles.lite";
5
+ import RenderBlock from "./render-block.lite";
6
+
7
+ function RenderComponent(props) {
8
+ return (
9
+ <Show when={props.componentRef}>
10
+ <Dynamic {...props.componentOptions} component={props.componentRef}>
11
+ <For each={props.blockChildren}>
12
+ {(child, _index) => {
13
+ const index = _index();
14
+ return (
15
+ <RenderBlock
16
+ key={"render-block-" + child.id}
17
+ block={child}
18
+ ></RenderBlock>
19
+ );
20
+ }}
21
+ </For>
22
+ <For each={props.blockChildren}>
23
+ {(child, _index) => {
24
+ const index = _index();
25
+ return (
26
+ <BlockStyles
27
+ key={"block-style-" + child.id}
28
+ block={child}
29
+ ></BlockStyles>
30
+ );
31
+ }}
32
+ </For>
33
+ </Dynamic>
34
+ </Show>
35
+ );
36
+ }
37
+
38
+ export default RenderComponent;
@@ -2,6 +2,7 @@ import { Show, For } from "solid-js";
2
2
  import { createMutable } from "solid-js/store";
3
3
  import { css } from "solid-styled-components";
4
4
  import { isEditing } from "../functions/is-editing.js";
5
+ import BlockStyles from "./render-block/block-styles";
5
6
  import RenderBlock from "./render-block/render-block";
6
7
 
7
8
  function RenderBlocks(props) {
@@ -47,7 +48,16 @@ function RenderBlocks(props) {
47
48
  {(block, _index) => {
48
49
  const index = _index();
49
50
 
50
- return <RenderBlock key={block.id} block={block}></RenderBlock>;
51
+ return <RenderBlock key={"render-block-" + block.id} block={block}></RenderBlock>;
52
+ }}
53
+ </For>
54
+ </Show>
55
+ <Show when={props.blocks}>
56
+ <For each={props.blocks}>
57
+ {(block, _index) => {
58
+ const index = _index();
59
+
60
+ return <BlockStyles key={"block-style-" + block.id} block={block}></BlockStyles>;
51
61
  }}
52
62
  </For>
53
63
  </Show>
@@ -4,6 +4,7 @@ import { createMutable } from "solid-js/store";
4
4
  import { css } from "solid-styled-components";
5
5
 
6
6
  import { isEditing } from "../functions/is-editing.js";
7
+ import BlockStyles from "./render-block/block-styles.lite";
7
8
  import RenderBlock from "./render-block/render-block.lite";
8
9
 
9
10
  function RenderBlocks(props) {
@@ -64,7 +65,25 @@ function RenderBlocks(props) {
64
65
  <For each={props.blocks}>
65
66
  {(block, _index) => {
66
67
  const index = _index();
67
- return <RenderBlock key={block.id} block={block}></RenderBlock>;
68
+ return (
69
+ <RenderBlock
70
+ key={"render-block-" + block.id}
71
+ block={block}
72
+ ></RenderBlock>
73
+ );
74
+ }}
75
+ </For>
76
+ </Show>
77
+ <Show when={props.blocks}>
78
+ <For each={props.blocks}>
79
+ {(block, _index) => {
80
+ const index = _index();
81
+ return (
82
+ <BlockStyles
83
+ key={"block-style-" + block.id}
84
+ block={block}
85
+ ></BlockStyles>
86
+ );
68
87
  }}
69
88
  </For>
70
89
  </Show>
@@ -1,4 +1,6 @@
1
1
  var __defProp = Object.defineProperty;
2
+ var __defProps = Object.defineProperties;
3
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
2
4
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
3
5
  var __hasOwnProp = Object.prototype.hasOwnProperty;
4
6
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
@@ -14,9 +16,12 @@ var __spreadValues = (a, b) => {
14
16
  }
15
17
  return a;
16
18
  };
19
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
17
20
  function getBlockComponentOptions(block) {
18
21
  var _a;
19
- return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
22
+ return __spreadProps(__spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options), {
23
+ builderBlock: block
24
+ });
20
25
  }
21
26
  export {
22
27
  getBlockComponentOptions