@builder.io/sdk-solid 0.2.0 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,4 +1,9 @@
1
+ ### 0.2.1
2
+
3
+ - No Changes.
4
+
1
5
  ### 0.2.0
6
+
2
7
  - Sets the default `apiVersion` to `v3`.
3
8
 
4
9
  In case you feel the need to use our older API Version `v2`, reach out to us at support@builder.io first. But you can override the default by setting `apiVersion` explicitly to `v2` as follows:
@@ -8,6 +13,7 @@ In case you feel the need to use our older API Version `v2`, reach out to us at
8
13
  ```
9
14
 
10
15
  ```js
11
- getContent({ apiVersion: "v2" })
16
+ getContent({ apiVersion: 'v2' });
12
17
  ```
18
+
13
19
  More details on the Builder API Versions visit [this link](https://www.builder.io/c/docs/content-api-versions).
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@builder.io/sdk-solid",
3
- "version": "0.2.0",
3
+ "version": "0.2.1",
4
4
  "description": "",
5
5
  "type": "module",
6
6
  "main": "./solid-index.jsx",
@@ -41,6 +41,9 @@ function BlockStyles(props) {
41
41
  const mediumStyles = styles?.medium;
42
42
  const smallStyles = styles?.small;
43
43
  const className = useBlock().id;
44
+ if (!className) {
45
+ return "";
46
+ }
44
47
  const largeStylesClass = largeStyles
45
48
  ? createCssClass({
46
49
  className,
@@ -106,8 +106,24 @@ const getRepeatItemData = ({
106
106
  }));
107
107
  return repeatArray;
108
108
  };
109
+ const getProxyState = (context) => {
110
+ if (typeof Proxy === "undefined") {
111
+ console.error("no Proxy available in this environment, cannot proxy state.");
112
+ return context.state;
113
+ }
114
+ const useState = new Proxy(context.state, {
115
+ set: (obj, prop, value) => {
116
+ var _a;
117
+ obj[prop] = value;
118
+ (_a = context.setState) == null ? void 0 : _a.call(context, obj);
119
+ return true;
120
+ }
121
+ });
122
+ return useState;
123
+ };
109
124
  export {
110
125
  getComponent,
126
+ getProxyState,
111
127
  getRepeatItemData,
112
128
  isEmptyHtmlElement
113
129
  };
@@ -4,11 +4,11 @@ import { Dynamic } from "solid-js/web";
4
4
  import { getBlockActions } from "../../functions/get-block-actions.js";
5
5
  import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
6
6
  import { getBlockProperties } from "../../functions/get-block-properties.js";
7
- import { getBlockTag } from "../../functions/get-block-tag.js";
8
7
  import { getProcessedBlock } from "../../functions/get-processed-block.js";
9
8
  import BlockStyles from "./block-styles.jsx";
10
9
  import {
11
10
  getComponent,
11
+ getProxyState,
12
12
  getRepeatItemData,
13
13
  isEmptyHtmlElement,
14
14
  } from "./render-block.helpers.js";
@@ -34,9 +34,11 @@ function RenderBlock(props) {
34
34
  })
35
35
  );
36
36
 
37
- function tag() {
38
- return getBlockTag(useBlock());
39
- }
37
+ const [tag, setTag] = createSignal(props.block.tagName || "div");
38
+
39
+ const [proxyState, setProxyState] = createSignal(
40
+ getProxyState(props.context)
41
+ );
40
42
 
41
43
  function useBlock() {
42
44
  return repeatItemData()
@@ -59,30 +61,10 @@ function RenderBlock(props) {
59
61
  return true;
60
62
  }
61
63
 
62
- function proxyState() {
63
- if (typeof Proxy === "undefined") {
64
- console.error(
65
- "no Proxy available in this environment, cannot proxy state."
66
- );
67
- return props.context.state;
68
- }
69
- const useState = new Proxy(props.context.state, {
70
- set: (obj, prop, value) => {
71
- // set the value on the state object, so that the event handler instantly gets the update.
72
- obj[prop] = value;
73
-
74
- // set the value in the context, so that the rest of the app gets the update.
75
- props.context.setState?.(obj);
76
- return true;
77
- },
78
- });
79
- return useState;
80
- }
81
-
82
64
  function actions() {
83
65
  return getBlockActions({
84
66
  block: useBlock(),
85
- state: proxyState(),
67
+ state: TARGET === "qwik" ? props.context.state : proxyState(),
86
68
  context: props.context.context,
87
69
  });
88
70
  }
@@ -103,29 +85,6 @@ function RenderBlock(props) {
103
85
  };
104
86
  }
105
87
 
106
- function renderComponentProps() {
107
- return {
108
- blockChildren: useBlock().children ?? [],
109
- componentRef: component()?.component,
110
- componentOptions: {
111
- ...getBlockComponentOptions(useBlock()),
112
- /**
113
- * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
114
- * they are provided to the component itself directly.
115
- */
116
- ...(!component()?.noWrap
117
- ? {}
118
- : {
119
- attributes: {
120
- ...attributes(),
121
- ...actions(),
122
- },
123
- }),
124
- },
125
- context: childrenContext(),
126
- };
127
- }
128
-
129
88
  function childrenWithoutParentComponent() {
130
89
  /**
131
90
  * When there is no `componentRef`, there might still be children that need to be rendered. In this case,
@@ -163,6 +122,29 @@ function RenderBlock(props) {
163
122
  };
164
123
  }
165
124
 
125
+ function renderComponentProps() {
126
+ return {
127
+ blockChildren: useBlock().children ?? [],
128
+ componentRef: component()?.component,
129
+ componentOptions: {
130
+ ...getBlockComponentOptions(useBlock()),
131
+ /**
132
+ * These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
133
+ * they are provided to the component itself directly.
134
+ */
135
+ ...(!component()?.noWrap
136
+ ? {}
137
+ : {
138
+ attributes: {
139
+ ...attributes(),
140
+ ...actions(),
141
+ },
142
+ }),
143
+ },
144
+ context: childrenContext(),
145
+ };
146
+ }
147
+
166
148
  return (
167
149
  <Show when={canShowBlock()}>
168
150
  <Show
@@ -4,16 +4,16 @@ import { Dynamic } from "solid-js/web";
4
4
  import { TARGET } from "../constants/target.js";
5
5
 
6
6
  function RenderInlinedStyles(props) {
7
- function injectedStyleScript() {
8
- return `<${tag()}>${props.styles}</${tag()}>`;
9
- }
10
-
11
7
  function tag() {
12
8
  // NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
13
9
  // https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
14
10
  return "sty" + "le";
15
11
  }
16
12
 
13
+ function injectedStyleScript() {
14
+ return `<${tag()}>${props.styles}</${tag()}>`;
15
+ }
16
+
17
17
  return (
18
18
  <Show
19
19
  fallback={<Dynamic component={tag()}>{props.styles}</Dynamic>}
@@ -1,6 +0,0 @@
1
- function getBlockTag(block) {
2
- return block.tagName || "div";
3
- }
4
- export {
5
- getBlockTag
6
- };