@builder.io/sdk-solid 0.2.0 → 0.2.2
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 +13 -1
- package/package.json +1 -1
- package/src/blocks/symbol/symbol.jsx +2 -1
- package/src/components/render-block/block-styles.jsx +3 -0
- package/src/components/render-block/render-block.helpers.js +16 -0
- package/src/components/render-block/render-block.jsx +32 -51
- package/src/components/render-content/render-content.jsx +11 -8
- package/src/components/render-inlined-styles.jsx +4 -4
- package/src/functions/get-block-properties.js +4 -1
- package/src/functions/get-content/index.js +21 -15
- package/src/functions/track/index.js +2 -1
- package/src/helpers/logger.js +9 -0
- package/src/functions/get-block-tag.js +0 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,4 +1,15 @@
|
|
|
1
|
+
### 0.2.2
|
|
2
|
+
|
|
3
|
+
- Fix: dynamic bindings for Link URLs.
|
|
4
|
+
- Fix: previewing content that includes a symbol whose `model` property is a `page`.
|
|
5
|
+
- Fix: "Show If"/"Hide If" bindings when the initial value is `undefined`.
|
|
6
|
+
|
|
7
|
+
### 0.2.1
|
|
8
|
+
|
|
9
|
+
- No Changes.
|
|
10
|
+
|
|
1
11
|
### 0.2.0
|
|
12
|
+
|
|
2
13
|
- Sets the default `apiVersion` to `v3`.
|
|
3
14
|
|
|
4
15
|
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 +19,7 @@ In case you feel the need to use our older API Version `v2`, reach out to us at
|
|
|
8
19
|
```
|
|
9
20
|
|
|
10
21
|
```js
|
|
11
|
-
getContent({ apiVersion:
|
|
22
|
+
getContent({ apiVersion: 'v2' });
|
|
12
23
|
```
|
|
24
|
+
|
|
13
25
|
More details on the Builder API Versions visit [this link](https://www.builder.io/c/docs/content-api-versions).
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ import RenderContent from "../../components/render-content/render-content.jsx";
|
|
|
4
4
|
import BuilderContext from "../../context/builder.context.js";
|
|
5
5
|
import { getContent } from "../../functions/get-content/index.js";
|
|
6
6
|
import { TARGET } from "../../constants/target";
|
|
7
|
+
import { logger } from "../../helpers/logger";
|
|
7
8
|
|
|
8
9
|
function Symbol(props) {
|
|
9
10
|
const [className, setClassName] = createSignal(
|
|
@@ -53,7 +54,7 @@ function Symbol(props) {
|
|
|
53
54
|
}
|
|
54
55
|
})
|
|
55
56
|
.catch((err) => {
|
|
56
|
-
|
|
57
|
+
logger.error("Could not fetch symbol content: ", err);
|
|
57
58
|
});
|
|
58
59
|
}
|
|
59
60
|
}
|
|
@@ -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";
|
|
@@ -17,7 +17,6 @@ import { TARGET } from "../../constants/target.js";
|
|
|
17
17
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
18
18
|
import RenderComponent from "./render-component.jsx";
|
|
19
19
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
20
|
-
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
21
20
|
|
|
22
21
|
function RenderBlock(props) {
|
|
23
22
|
const [component, setComponent] = createSignal(
|
|
@@ -34,9 +33,11 @@ function RenderBlock(props) {
|
|
|
34
33
|
})
|
|
35
34
|
);
|
|
36
35
|
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
36
|
+
const [tag, setTag] = createSignal(props.block.tagName || "div");
|
|
37
|
+
|
|
38
|
+
const [proxyState, setProxyState] = createSignal(
|
|
39
|
+
getProxyState(props.context)
|
|
40
|
+
);
|
|
40
41
|
|
|
41
42
|
function useBlock() {
|
|
42
43
|
return repeatItemData()
|
|
@@ -50,39 +51,19 @@ function RenderBlock(props) {
|
|
|
50
51
|
}
|
|
51
52
|
|
|
52
53
|
function canShowBlock() {
|
|
53
|
-
if (
|
|
54
|
+
if ("hide" in useBlock()) {
|
|
54
55
|
return !useBlock().hide;
|
|
55
56
|
}
|
|
56
|
-
if (
|
|
57
|
+
if ("show" in useBlock()) {
|
|
57
58
|
return useBlock().show;
|
|
58
59
|
}
|
|
59
60
|
return true;
|
|
60
61
|
}
|
|
61
62
|
|
|
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
63
|
function actions() {
|
|
83
64
|
return getBlockActions({
|
|
84
65
|
block: useBlock(),
|
|
85
|
-
state: proxyState(),
|
|
66
|
+
state: TARGET === "qwik" ? props.context.state : proxyState(),
|
|
86
67
|
context: props.context.context,
|
|
87
68
|
});
|
|
88
69
|
}
|
|
@@ -103,29 +84,6 @@ function RenderBlock(props) {
|
|
|
103
84
|
};
|
|
104
85
|
}
|
|
105
86
|
|
|
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
87
|
function childrenWithoutParentComponent() {
|
|
130
88
|
/**
|
|
131
89
|
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
@@ -163,6 +121,29 @@ function RenderBlock(props) {
|
|
|
163
121
|
};
|
|
164
122
|
}
|
|
165
123
|
|
|
124
|
+
function renderComponentProps() {
|
|
125
|
+
return {
|
|
126
|
+
blockChildren: useBlock().children ?? [],
|
|
127
|
+
componentRef: component()?.component,
|
|
128
|
+
componentOptions: {
|
|
129
|
+
...getBlockComponentOptions(useBlock()),
|
|
130
|
+
/**
|
|
131
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
132
|
+
* they are provided to the component itself directly.
|
|
133
|
+
*/
|
|
134
|
+
...(!component()?.noWrap
|
|
135
|
+
? {}
|
|
136
|
+
: {
|
|
137
|
+
attributes: {
|
|
138
|
+
...attributes(),
|
|
139
|
+
...actions(),
|
|
140
|
+
},
|
|
141
|
+
}),
|
|
142
|
+
},
|
|
143
|
+
context: childrenContext(),
|
|
144
|
+
};
|
|
145
|
+
}
|
|
146
|
+
|
|
166
147
|
return (
|
|
167
148
|
<Show when={canShowBlock()}>
|
|
168
149
|
<Show
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
getContextStateInitialValue,
|
|
29
29
|
} from "./render-content.helpers.js";
|
|
30
30
|
import { TARGET } from "../../constants/target.js";
|
|
31
|
+
import { logger } from "../../helpers/logger.js";
|
|
31
32
|
|
|
32
33
|
function RenderContent(props) {
|
|
33
34
|
const [forceReRenderCount, setForceReRenderCount] = createSignal(0);
|
|
@@ -235,8 +236,8 @@ function RenderContent(props) {
|
|
|
235
236
|
|
|
236
237
|
onMount(() => {
|
|
237
238
|
if (!props.apiKey) {
|
|
238
|
-
|
|
239
|
-
"
|
|
239
|
+
logger.error(
|
|
240
|
+
"No API key provided to `RenderContent` component. This can cause issues. Please provide an API key using the `apiKey` prop."
|
|
240
241
|
);
|
|
241
242
|
}
|
|
242
243
|
if (isBrowser()) {
|
|
@@ -282,7 +283,10 @@ function RenderContent(props) {
|
|
|
282
283
|
// override normal content in preview mode
|
|
283
284
|
if (isPreviewing()) {
|
|
284
285
|
const searchParams = new URL(location.href).searchParams;
|
|
285
|
-
const
|
|
286
|
+
const searchParamPreviewModel = searchParams.get("builder.preview");
|
|
287
|
+
const searchParamPreviewId = searchParams.get(
|
|
288
|
+
`builder.preview.${searchParamPreviewModel}`
|
|
289
|
+
);
|
|
286
290
|
const previewApiKey =
|
|
287
291
|
searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
288
292
|
|
|
@@ -291,15 +295,14 @@ function RenderContent(props) {
|
|
|
291
295
|
* - the preview model name is the same as the one we're rendering, since there can be multiple models rendered
|
|
292
296
|
* at the same time, e.g. header/page/footer.
|
|
293
297
|
* - the API key is the same, since we don't want to preview content from other organizations.
|
|
294
|
-
*
|
|
295
|
-
* TO-DO: should we check that the preview item ID is the same as the initial one being rendered? Or would
|
|
296
|
-
* this break scenarios where the item is not published yet?
|
|
298
|
+
* - if there is content, that the preview ID is the same as that of the one we receive.
|
|
297
299
|
*
|
|
298
300
|
* TO-DO: should we only update the state when there is a change?
|
|
299
301
|
**/
|
|
300
302
|
if (
|
|
301
|
-
|
|
302
|
-
previewApiKey === props.apiKey
|
|
303
|
+
searchParamPreviewModel === props.model &&
|
|
304
|
+
previewApiKey === props.apiKey &&
|
|
305
|
+
(!props.content || searchParamPreviewId === props.content.id)
|
|
303
306
|
) {
|
|
304
307
|
getContent({
|
|
305
308
|
model: props.model,
|
|
@@ -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>}
|
|
@@ -20,9 +20,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
|
20
20
|
import { TARGET } from "../constants/target.js";
|
|
21
21
|
import { convertStyleMapToCSSArray } from "../helpers/css.js";
|
|
22
22
|
import { transformBlockProperties } from "./transform-block-properties.js";
|
|
23
|
+
const extractRelevantRootBlockProperties = (block) => {
|
|
24
|
+
return { href: block.href };
|
|
25
|
+
};
|
|
23
26
|
function getBlockProperties(block) {
|
|
24
27
|
var _a;
|
|
25
|
-
const properties = __spreadProps(__spreadValues({}, block.properties), {
|
|
28
|
+
const properties = __spreadProps(__spreadValues(__spreadValues({}, extractRelevantRootBlockProperties(block)), block.properties), {
|
|
26
29
|
"builder-id": block.id,
|
|
27
30
|
style: getStyleAttribute(block.style),
|
|
28
31
|
class: [block.id, "builder-block", block.class, (_a = block.properties) == null ? void 0 : _a.class].filter(Boolean).join(" ")
|
|
@@ -37,13 +37,14 @@ var __async = (__this, __arguments, generator) => {
|
|
|
37
37
|
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
|
+
import { logger } from "../../helpers/logger.js";
|
|
40
41
|
import { fetch } from "../get-fetch.js";
|
|
41
42
|
import { handleABTesting } from "./ab-testing.js";
|
|
42
43
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
43
44
|
function getContent(options) {
|
|
44
45
|
return __async(this, null, function* () {
|
|
45
46
|
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
46
|
-
if ("results" in allContent) {
|
|
47
|
+
if (allContent && "results" in allContent) {
|
|
47
48
|
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
48
49
|
}
|
|
49
50
|
return null;
|
|
@@ -51,24 +52,29 @@ function getContent(options) {
|
|
|
51
52
|
}
|
|
52
53
|
function getAllContent(options) {
|
|
53
54
|
return __async(this, null, function* () {
|
|
54
|
-
const url = generateContentUrl(options);
|
|
55
|
-
const res = yield fetch(url.href);
|
|
56
|
-
const content = yield res.json();
|
|
57
|
-
if ("status" in content && !("results" in content)) {
|
|
58
|
-
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
59
|
-
return content;
|
|
60
|
-
}
|
|
61
|
-
const canTrack = options.canTrack !== false;
|
|
62
55
|
try {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
const url = generateContentUrl(options);
|
|
57
|
+
const res = yield fetch(url.href);
|
|
58
|
+
const content = yield res.json();
|
|
59
|
+
if ("status" in content && !("results" in content)) {
|
|
60
|
+
logger.error("Error fetching data. ", content, options);
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
63
|
+
const canTrack = options.canTrack !== false;
|
|
64
|
+
try {
|
|
65
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
66
|
+
for (const item of content.results) {
|
|
67
|
+
yield handleABTesting({ item, canTrack });
|
|
68
|
+
}
|
|
66
69
|
}
|
|
70
|
+
} catch (e) {
|
|
71
|
+
logger.error("Could not setup A/B testing. ", e);
|
|
67
72
|
}
|
|
68
|
-
|
|
69
|
-
|
|
73
|
+
return content;
|
|
74
|
+
} catch (error) {
|
|
75
|
+
logger.error("Error fetching data. ", error);
|
|
76
|
+
return null;
|
|
70
77
|
}
|
|
71
|
-
return content;
|
|
72
78
|
});
|
|
73
79
|
}
|
|
74
80
|
export {
|
|
@@ -50,6 +50,7 @@ var __async = (__this, __arguments, generator) => {
|
|
|
50
50
|
});
|
|
51
51
|
};
|
|
52
52
|
import { TARGET } from "../../constants/target.js";
|
|
53
|
+
import { logger } from "../../helpers/logger.js";
|
|
53
54
|
import { getSessionId } from "../../helpers/sessionId.js";
|
|
54
55
|
import { getVisitorId } from "../../helpers/visitorId.js";
|
|
55
56
|
import { isBrowser } from "../is-browser.js";
|
|
@@ -95,7 +96,7 @@ const createEvent = (_a) => __async(void 0, null, function* () {
|
|
|
95
96
|
function _track(eventProps) {
|
|
96
97
|
return __async(this, null, function* () {
|
|
97
98
|
if (!eventProps.apiKey) {
|
|
98
|
-
|
|
99
|
+
logger.error("Missing API key for track call. Please provide your API key.");
|
|
99
100
|
return;
|
|
100
101
|
}
|
|
101
102
|
if (!eventProps.canTrack) {
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
const MSG_PREFIX = "[Builder.io]: ";
|
|
2
|
+
const logger = {
|
|
3
|
+
log: (...message) => console.log(MSG_PREFIX, ...message),
|
|
4
|
+
error: (...message) => console.error(MSG_PREFIX, ...message),
|
|
5
|
+
warn: (...message) => console.warn(MSG_PREFIX, ...message)
|
|
6
|
+
};
|
|
7
|
+
export {
|
|
8
|
+
logger
|
|
9
|
+
};
|