@builder.io/sdk-react 0.1.15 → 0.2.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.
- package/CHANGELOG.md +13 -0
- package/dist/react/blocks/button/button.js +4 -2
- package/dist/react/blocks/columns/columns.js +4 -4
- package/dist/react/blocks/form/form.js +2 -2
- package/dist/react/blocks/image/image.js +7 -9
- package/dist/react/components/render-block/render-block.js +1 -0
- package/dist/react/components/render-blocks.js +2 -2
- package/dist/react/components/render-content/render-content.js +1 -1
- package/dist/react/functions/get-content/generate-content-url.js +2 -1
- package/dist/react/functions/get-content/generate-content-url.test.js +9 -0
- package/dist/react/functions/get-content/index.js +17 -4
- package/dist/react/types/api-version.js +2 -1
- package/dist/rsc/blocks/button/button.js +4 -2
- package/dist/rsc/blocks/columns/columns.js +4 -4
- package/dist/rsc/blocks/form/form.js +2 -2
- package/dist/rsc/blocks/image/image.js +7 -9
- package/dist/rsc/components/render-block/render-block.js +1 -0
- package/dist/rsc/components/render-blocks.js +2 -2
- package/dist/rsc/components/render-content/render-content.js +1 -1
- package/dist/rsc/functions/get-content/generate-content-url.js +2 -1
- package/dist/rsc/functions/get-content/generate-content-url.test.js +9 -0
- package/dist/rsc/functions/get-content/index.js +17 -4
- package/dist/rsc/types/api-version.js +2 -1
- package/package.json +1 -1
- package/packages/react/src/blocks/button/button.jsx +8 -2
- package/packages/react/src/blocks/columns/columns.jsx +4 -4
- package/packages/react/src/blocks/form/form.jsx +2 -2
- package/packages/react/src/blocks/image/image.jsx +7 -9
- package/packages/react/src/components/render-block/render-block.jsx +1 -0
- package/packages/react/src/components/render-blocks.jsx +2 -2
- package/packages/react/src/components/render-content/render-content.jsx +1 -1
- package/packages/react/src/functions/get-content/generate-content-url.js +2 -1
- package/packages/react/src/functions/get-content/generate-content-url.test.js +9 -0
- package/packages/react/src/functions/get-content/index.js +16 -4
- package/packages/react/src/types/api-version.js +4 -0
- package/packages/rsc/src/blocks/button/button.jsx +8 -2
- package/packages/rsc/src/blocks/columns/columns.jsx +4 -4
- package/packages/rsc/src/blocks/form/form.jsx +2 -2
- package/packages/rsc/src/blocks/image/image.jsx +7 -9
- package/packages/rsc/src/components/render-block/render-block.jsx +1 -0
- package/packages/rsc/src/components/render-blocks.jsx +2 -2
- package/packages/rsc/src/components/render-content/render-content.jsx +1 -1
- package/packages/rsc/src/functions/get-content/generate-content-url.js +2 -1
- package/packages/rsc/src/functions/get-content/generate-content-url.test.js +9 -0
- package/packages/rsc/src/functions/get-content/index.js +16 -4
- package/packages/rsc/src/types/api-version.js +4 -0
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
### 0.2.0
|
|
2
|
+
- Sets the default `apiVersion` to `v3`.
|
|
3
|
+
|
|
4
|
+
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:
|
|
5
|
+
|
|
6
|
+
```jsx
|
|
7
|
+
<RenderContent apiVersion="v2" />
|
|
8
|
+
```
|
|
9
|
+
|
|
10
|
+
```js
|
|
11
|
+
getContent({ apiVersion: "v2" })
|
|
12
|
+
```
|
|
13
|
+
More details on the Builder API Versions visit [this link](https://www.builder.io/c/docs/content-api-versions).
|
|
@@ -2,8 +2,10 @@ import * as React from "react";
|
|
|
2
2
|
function Button(props) {
|
|
3
3
|
return (React.createElement(React.Fragment, null,
|
|
4
4
|
props.link ? (React.createElement(React.Fragment, null,
|
|
5
|
-
React.createElement("a", { role: "button", ...props.attributes, href: props.link, target: props.openLinkInNewTab ? "_blank" : undefined }, props.text))) : (React.createElement("button", { className:
|
|
6
|
-
|
|
5
|
+
React.createElement("a", { role: "button", ...props.attributes, href: props.link, target: props.openLinkInNewTab ? "_blank" : undefined }, props.text))) : (React.createElement("button", { className:
|
|
6
|
+
/** * We have to explicitly provide `class` so that Mitosis knows to merge it with `css`. */
|
|
7
|
+
props.attributes.class + " button-5050ef15", ...props.attributes }, props.text)),
|
|
8
|
+
React.createElement("style", null, `.button-5050ef15 {
|
|
7
9
|
all: unset;
|
|
8
10
|
}`)));
|
|
9
11
|
}
|
|
@@ -107,21 +107,21 @@ function Columns(props) {
|
|
|
107
107
|
const builderContext = useContext(BuilderContext);
|
|
108
108
|
return (React.createElement(React.Fragment, null,
|
|
109
109
|
React.createElement("div", { className: `builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
110
|
-
" div-
|
|
110
|
+
" div-f0aded1c", style: columnsCssVars(), dataSet: {
|
|
111
111
|
"builder-block-name": "builder-columns",
|
|
112
112
|
} },
|
|
113
113
|
TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
114
114
|
React.createElement(RenderInlinedStyles, { styles: columnsStyles() }))) : null,
|
|
115
|
-
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-
|
|
115
|
+
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-f0aded1c-2", style: columnCssVars(index), dataSet: {
|
|
116
116
|
"builder-block-name": "builder-column",
|
|
117
117
|
}, key: index },
|
|
118
118
|
React.createElement(RenderBlocks, { blocks: column.blocks, path: `component.options.columns.${index}.blocks`, parent: props.builderBlock.id, styleProp: {
|
|
119
119
|
flexGrow: "1",
|
|
120
120
|
} }))))),
|
|
121
|
-
React.createElement("style", null, `.div-
|
|
121
|
+
React.createElement("style", null, `.div-f0aded1c {
|
|
122
122
|
display: flex;
|
|
123
123
|
line-height: normal;
|
|
124
|
-
}.div-
|
|
124
|
+
}.div-f0aded1c-2 {
|
|
125
125
|
display: flex;
|
|
126
126
|
flex-direction: column;
|
|
127
127
|
align-items: stretch;
|
|
@@ -187,7 +187,7 @@ function FormComponent(props) {
|
|
|
187
187
|
React.createElement(BuilderBlocks, { dataPath: "sendingMessage", blocks: props.sendingMessage }))) : null,
|
|
188
188
|
" ",
|
|
189
189
|
submissionState() === "error" && responseData ? (React.createElement(React.Fragment, null,
|
|
190
|
-
React.createElement("pre", { className: "builder-form-error-text pre-
|
|
190
|
+
React.createElement("pre", { className: "builder-form-error-text pre-8b05da54" },
|
|
191
191
|
" ",
|
|
192
192
|
JSON.stringify(responseData, null, 2),
|
|
193
193
|
" "))) : null,
|
|
@@ -196,7 +196,7 @@ function FormComponent(props) {
|
|
|
196
196
|
React.createElement(BuilderBlocks, { dataPath: "successMessage", blocks: props.successMessage }))) : null,
|
|
197
197
|
" "),
|
|
198
198
|
" ",
|
|
199
|
-
React.createElement("style", null, `.pre-
|
|
199
|
+
React.createElement("style", null, `.pre-8b05da54 { padding: 10px; color: red; text-align: center; }`),
|
|
200
200
|
" "));
|
|
201
201
|
}
|
|
202
202
|
export default FormComponent;
|
|
@@ -51,25 +51,23 @@ function Image(props) {
|
|
|
51
51
|
...aspectRatioCss(),
|
|
52
52
|
}, className: "builder-image" +
|
|
53
53
|
(props.className ? " " + props.className : "") +
|
|
54
|
-
" img-
|
|
54
|
+
" img-23384452", src: props.image, srcSet: srcSetToUse(), sizes: props.sizes })),
|
|
55
55
|
props.aspectRatio &&
|
|
56
56
|
!(props.builderBlock?.children?.length && props.fitContent) ? (React.createElement(React.Fragment, null,
|
|
57
|
-
React.createElement("div", { className: "builder-image-sizer div-
|
|
58
|
-
paddingTop:
|
|
59
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
60
|
-
props.aspectRatio * 100 + "%",
|
|
57
|
+
React.createElement("div", { className: "builder-image-sizer div-23384452", style: {
|
|
58
|
+
paddingTop: props.aspectRatio * 100 + "%",
|
|
61
59
|
} }))) : null,
|
|
62
60
|
props.builderBlock?.children?.length && props.fitContent ? (React.createElement(React.Fragment, null, props.children)) : null,
|
|
63
61
|
!props.fitContent && props.children ? (React.createElement(React.Fragment, null,
|
|
64
|
-
React.createElement("div", { className: "div-
|
|
65
|
-
React.createElement("style", null, `.img-
|
|
62
|
+
React.createElement("div", { className: "div-23384452-2" }, props.children))) : null),
|
|
63
|
+
React.createElement("style", null, `.img-23384452 {
|
|
66
64
|
opacity: 1;
|
|
67
65
|
transition: opacity 0.2s ease-in-out;
|
|
68
|
-
}.div-
|
|
66
|
+
}.div-23384452 {
|
|
69
67
|
width: 100%;
|
|
70
68
|
pointer-events: none;
|
|
71
69
|
font-size: 0;
|
|
72
|
-
}.div-
|
|
70
|
+
}.div-23384452-2 {
|
|
73
71
|
display: flex;
|
|
74
72
|
flex-direction: column;
|
|
75
73
|
align-items: stretch;
|
|
@@ -32,12 +32,12 @@ function RenderBlocks(props) {
|
|
|
32
32
|
}
|
|
33
33
|
const builderContext = useContext(BuilderContext);
|
|
34
34
|
return (React.createElement(React.Fragment, null,
|
|
35
|
-
React.createElement("div", { className: className() + " div-
|
|
35
|
+
React.createElement("div", { className: className() + " div-1fdf6196", "builder-path": props.path, "builder-parent-id": props.parent, dataSet: {
|
|
36
36
|
class: className(),
|
|
37
37
|
}, style: props.styleProp, onClick: (event) => onClick(), onMouseEnter: (event) => onMouseEnter() },
|
|
38
38
|
props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(RenderBlock, { key: "render-block-" + block.id, block: block, context: builderContext }))))) : null,
|
|
39
39
|
props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(BlockStyles, { key: "block-style-" + block.id, block: block, context: builderContext }))))) : null),
|
|
40
|
-
React.createElement("style", null, `.div-
|
|
40
|
+
React.createElement("style", null, `.div-1fdf6196 {
|
|
41
41
|
display: flex;
|
|
42
42
|
flex-direction: column;
|
|
43
43
|
align-items: stretch;
|
|
@@ -157,7 +157,7 @@ function RenderContent(props) {
|
|
|
157
157
|
setContextState(newState);
|
|
158
158
|
})
|
|
159
159
|
.catch((err) => {
|
|
160
|
-
console.
|
|
160
|
+
console.error("error fetching dynamic data", url, err);
|
|
161
161
|
});
|
|
162
162
|
}
|
|
163
163
|
function runHttpRequests() {
|
|
@@ -16,8 +16,9 @@ var __spreadValues = (a, b) => {
|
|
|
16
16
|
};
|
|
17
17
|
import { flatten } from "../../helpers/flatten.js";
|
|
18
18
|
import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from "../get-builder-search-params/index.js";
|
|
19
|
+
import { DEFAULT_API_VERSION } from "../../types/api-version";
|
|
19
20
|
const generateContentUrl = (options) => {
|
|
20
|
-
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, apiVersion =
|
|
21
|
+
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, apiVersion = DEFAULT_API_VERSION } = options;
|
|
21
22
|
if (!apiKey) {
|
|
22
23
|
throw new Error("Missing API key");
|
|
23
24
|
}
|
|
@@ -28,6 +28,15 @@ describe("Generate Content URL", () => {
|
|
|
28
28
|
});
|
|
29
29
|
expect(output).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
|
+
test("generate content url with apiVersion as default", () => {
|
|
32
|
+
const output = generateContentUrl({
|
|
33
|
+
apiKey: testKey,
|
|
34
|
+
model: testModel,
|
|
35
|
+
query: { id: testId },
|
|
36
|
+
options
|
|
37
|
+
});
|
|
38
|
+
expect(output).toMatchSnapshot();
|
|
39
|
+
});
|
|
31
40
|
test("generate content url with apiVersion as v2", () => {
|
|
32
41
|
const output = generateContentUrl({
|
|
33
42
|
apiKey: testKey,
|
|
@@ -44,7 +44,11 @@ import { handleABTesting } from "./ab-testing.js";
|
|
|
44
44
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
45
45
|
function getContent(options) {
|
|
46
46
|
return __async(this, null, function* () {
|
|
47
|
-
|
|
47
|
+
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
48
|
+
if ("results" in allContent) {
|
|
49
|
+
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
48
52
|
});
|
|
49
53
|
}
|
|
50
54
|
function getAllContent(options) {
|
|
@@ -52,12 +56,21 @@ function getAllContent(options) {
|
|
|
52
56
|
const url = generateContentUrl(options);
|
|
53
57
|
const res = yield fetch(url.href);
|
|
54
58
|
const content = yield res.json();
|
|
59
|
+
if ("status" in content && !("results" in content)) {
|
|
60
|
+
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
55
63
|
const canTrack = options.canTrack !== false;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
try {
|
|
65
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
66
|
+
for (const item of content.results) {
|
|
67
|
+
yield handleABTesting({ item, canTrack });
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error("[Builder.io]: Could not setup A/B testing. ", e);
|
|
73
|
+
}
|
|
61
74
|
return content;
|
|
62
75
|
});
|
|
63
76
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const DEFAULT_API_VERSION = "v3";
|
|
2
|
+
export { DEFAULT_API_VERSION };
|
|
@@ -3,8 +3,10 @@ function Button(props) {
|
|
|
3
3
|
const _context = { ...props["_context"] };
|
|
4
4
|
return (React.createElement(React.Fragment, null,
|
|
5
5
|
props.link ? (React.createElement(React.Fragment, null,
|
|
6
|
-
React.createElement("a", { role: "button", ...props.attributes, href: props.link, target: props.openLinkInNewTab ? "_blank" : undefined }, props.text))) : (React.createElement("button", { className:
|
|
7
|
-
|
|
6
|
+
React.createElement("a", { role: "button", ...props.attributes, href: props.link, target: props.openLinkInNewTab ? "_blank" : undefined }, props.text))) : (React.createElement("button", { className:
|
|
7
|
+
/** * We have to explicitly provide `class` so that Mitosis knows to merge it with `css`. */
|
|
8
|
+
props.attributes.class + " button-3083674c", ...props.attributes }, props.text)),
|
|
9
|
+
React.createElement("style", null, `.button-3083674c {
|
|
8
10
|
all: unset;
|
|
9
11
|
}`)));
|
|
10
12
|
}
|
|
@@ -109,21 +109,21 @@ function Columns(props) {
|
|
|
109
109
|
const builderContext = _context["BuilderContext"];
|
|
110
110
|
return (React.createElement(React.Fragment, null,
|
|
111
111
|
React.createElement("div", { className: `builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
112
|
-
" div-
|
|
112
|
+
" div-38093a46", style: state.columnsCssVars, dataSet: {
|
|
113
113
|
"builder-block-name": "builder-columns",
|
|
114
114
|
} },
|
|
115
115
|
TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
116
116
|
React.createElement(RenderInlinedStyles, { styles: state.columnsStyles, _context: _context }))) : null,
|
|
117
|
-
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-
|
|
117
|
+
props.columns?.map((column, index) => (React.createElement("div", { className: "builder-column div-38093a46-2", style: state.columnCssVars(index), dataSet: {
|
|
118
118
|
"builder-block-name": "builder-column",
|
|
119
119
|
}, key: index },
|
|
120
120
|
React.createElement(RenderBlocks, { blocks: column.blocks, path: `component.options.columns.${index}.blocks`, parent: props.builderBlock.id, styleProp: {
|
|
121
121
|
flexGrow: "1",
|
|
122
122
|
}, _context: _context }))))),
|
|
123
|
-
React.createElement("style", null, `.div-
|
|
123
|
+
React.createElement("style", null, `.div-38093a46 {
|
|
124
124
|
display: flex;
|
|
125
125
|
line-height: normal;
|
|
126
|
-
}.div-
|
|
126
|
+
}.div-38093a46-2 {
|
|
127
127
|
display: flex;
|
|
128
128
|
flex-direction: column;
|
|
129
129
|
align-items: stretch;
|
|
@@ -190,7 +190,7 @@ function FormComponent(props) {
|
|
|
190
190
|
React.createElement(BuilderBlocks, { dataPath: "sendingMessage", blocks: props.sendingMessage, _context: _context }))) : null,
|
|
191
191
|
" ",
|
|
192
192
|
state.submissionState === "error" && state.responseData ? (React.createElement(React.Fragment, null,
|
|
193
|
-
React.createElement("pre", { className: "builder-form-error-text pre-
|
|
193
|
+
React.createElement("pre", { className: "builder-form-error-text pre-1adaf299" },
|
|
194
194
|
" ",
|
|
195
195
|
JSON.stringify(state.responseData, null, 2),
|
|
196
196
|
" "))) : null,
|
|
@@ -199,7 +199,7 @@ function FormComponent(props) {
|
|
|
199
199
|
React.createElement(BuilderBlocks, { dataPath: "successMessage", blocks: props.successMessage, _context: _context }))) : null,
|
|
200
200
|
" "),
|
|
201
201
|
" ",
|
|
202
|
-
React.createElement("style", null, `.pre-
|
|
202
|
+
React.createElement("style", null, `.pre-1adaf299 { padding: 10px; color: red; text-align: center; }`),
|
|
203
203
|
" "));
|
|
204
204
|
}
|
|
205
205
|
export default FormComponent;
|
|
@@ -54,25 +54,23 @@ function Image(props) {
|
|
|
54
54
|
...state.aspectRatioCss,
|
|
55
55
|
}, className: "builder-image" +
|
|
56
56
|
(props.className ? " " + props.className : "") +
|
|
57
|
-
" img-
|
|
57
|
+
" img-2029f6ee", src: props.image, srcSet: state.srcSetToUse, sizes: props.sizes })),
|
|
58
58
|
props.aspectRatio &&
|
|
59
59
|
!(props.builderBlock?.children?.length && props.fitContent) ? (React.createElement(React.Fragment, null,
|
|
60
|
-
React.createElement("div", { className: "builder-image-sizer div-
|
|
61
|
-
paddingTop:
|
|
62
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
63
|
-
props.aspectRatio * 100 + "%",
|
|
60
|
+
React.createElement("div", { className: "builder-image-sizer div-2029f6ee", style: {
|
|
61
|
+
paddingTop: props.aspectRatio * 100 + "%",
|
|
64
62
|
} }))) : null,
|
|
65
63
|
props.builderBlock?.children?.length && props.fitContent ? (React.createElement(React.Fragment, null, props.children)) : null,
|
|
66
64
|
!props.fitContent && props.children ? (React.createElement(React.Fragment, null,
|
|
67
|
-
React.createElement("div", { className: "div-
|
|
68
|
-
React.createElement("style", null, `.img-
|
|
65
|
+
React.createElement("div", { className: "div-2029f6ee-2" }, props.children))) : null),
|
|
66
|
+
React.createElement("style", null, `.img-2029f6ee {
|
|
69
67
|
opacity: 1;
|
|
70
68
|
transition: opacity 0.2s ease-in-out;
|
|
71
|
-
}.div-
|
|
69
|
+
}.div-2029f6ee {
|
|
72
70
|
width: 100%;
|
|
73
71
|
pointer-events: none;
|
|
74
72
|
font-size: 0;
|
|
75
|
-
}.div-
|
|
73
|
+
}.div-2029f6ee-2 {
|
|
76
74
|
display: flex;
|
|
77
75
|
flex-direction: column;
|
|
78
76
|
align-items: stretch;
|
|
@@ -34,12 +34,12 @@ function RenderBlocks(props) {
|
|
|
34
34
|
};
|
|
35
35
|
const builderContext = _context["BuilderContext"];
|
|
36
36
|
return (React.createElement(React.Fragment, null,
|
|
37
|
-
React.createElement("div", { className: state.className + " div-
|
|
37
|
+
React.createElement("div", { className: state.className + " div-7a14f25c", "builder-path": props.path, "builder-parent-id": props.parent, dataSet: {
|
|
38
38
|
class: state.className,
|
|
39
39
|
}, style: props.styleProp },
|
|
40
40
|
props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(RenderBlock, { key: "render-block-" + block.id, block: block, context: builderContext, _context: _context }))))) : null,
|
|
41
41
|
props.blocks ? (React.createElement(React.Fragment, null, props.blocks?.map((block) => (React.createElement(BlockStyles, { key: "block-style-" + block.id, block: block, context: builderContext, _context: _context }))))) : null),
|
|
42
|
-
React.createElement("style", null, `.div-
|
|
42
|
+
React.createElement("style", null, `.div-7a14f25c {
|
|
43
43
|
display: flex;
|
|
44
44
|
flex-direction: column;
|
|
45
45
|
align-items: stretch;
|
|
@@ -158,7 +158,7 @@ function RenderContent(props) {
|
|
|
158
158
|
state.setContextState(newState);
|
|
159
159
|
})
|
|
160
160
|
.catch((err) => {
|
|
161
|
-
console.
|
|
161
|
+
console.error("error fetching dynamic data", url, err);
|
|
162
162
|
});
|
|
163
163
|
},
|
|
164
164
|
runHttpRequests() {
|
|
@@ -16,8 +16,9 @@ var __spreadValues = (a, b) => {
|
|
|
16
16
|
};
|
|
17
17
|
import { flatten } from "../../helpers/flatten.js";
|
|
18
18
|
import { getBuilderSearchParamsFromWindow, normalizeSearchParams } from "../get-builder-search-params/index.js";
|
|
19
|
+
import { DEFAULT_API_VERSION } from "../../types/api-version";
|
|
19
20
|
const generateContentUrl = (options) => {
|
|
20
|
-
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, apiVersion =
|
|
21
|
+
const { limit = 30, userAttributes, query, noTraverse = false, model, apiKey, includeRefs = true, locale, apiVersion = DEFAULT_API_VERSION } = options;
|
|
21
22
|
if (!apiKey) {
|
|
22
23
|
throw new Error("Missing API key");
|
|
23
24
|
}
|
|
@@ -28,6 +28,15 @@ describe("Generate Content URL", () => {
|
|
|
28
28
|
});
|
|
29
29
|
expect(output).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
|
+
test("generate content url with apiVersion as default", () => {
|
|
32
|
+
const output = generateContentUrl({
|
|
33
|
+
apiKey: testKey,
|
|
34
|
+
model: testModel,
|
|
35
|
+
query: { id: testId },
|
|
36
|
+
options
|
|
37
|
+
});
|
|
38
|
+
expect(output).toMatchSnapshot();
|
|
39
|
+
});
|
|
31
40
|
test("generate content url with apiVersion as v2", () => {
|
|
32
41
|
const output = generateContentUrl({
|
|
33
42
|
apiKey: testKey,
|
|
@@ -44,7 +44,11 @@ import { handleABTesting } from "./ab-testing.js";
|
|
|
44
44
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
45
45
|
function getContent(options) {
|
|
46
46
|
return __async(this, null, function* () {
|
|
47
|
-
|
|
47
|
+
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
48
|
+
if ("results" in allContent) {
|
|
49
|
+
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
50
|
+
}
|
|
51
|
+
return null;
|
|
48
52
|
});
|
|
49
53
|
}
|
|
50
54
|
function getAllContent(options) {
|
|
@@ -52,12 +56,21 @@ function getAllContent(options) {
|
|
|
52
56
|
const url = generateContentUrl(options);
|
|
53
57
|
const res = yield fetch(url.href);
|
|
54
58
|
const content = yield res.json();
|
|
59
|
+
if ("status" in content && !("results" in content)) {
|
|
60
|
+
console.error("[Builder.io]: Error fetching data. ", content, options);
|
|
61
|
+
return content;
|
|
62
|
+
}
|
|
55
63
|
const canTrack = options.canTrack !== false;
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
64
|
+
try {
|
|
65
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
66
|
+
for (const item of content.results) {
|
|
67
|
+
yield handleABTesting({ item, canTrack });
|
|
68
|
+
}
|
|
59
69
|
}
|
|
60
70
|
}
|
|
71
|
+
catch (e) {
|
|
72
|
+
console.error("[Builder.io]: Could not setup A/B testing. ", e);
|
|
73
|
+
}
|
|
61
74
|
return content;
|
|
62
75
|
});
|
|
63
76
|
}
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const DEFAULT_API_VERSION = "v3";
|
|
2
|
+
export { DEFAULT_API_VERSION };
|
package/package.json
CHANGED
|
@@ -15,11 +15,17 @@ function Button(props) {
|
|
|
15
15
|
</a>
|
|
16
16
|
</>
|
|
17
17
|
) : (
|
|
18
|
-
<button
|
|
18
|
+
<button
|
|
19
|
+
className={
|
|
20
|
+
/** * We have to explicitly provide `class` so that Mitosis knows to merge it with `css`. */
|
|
21
|
+
props.attributes.class + " button-5050ef15"
|
|
22
|
+
}
|
|
23
|
+
{...props.attributes}
|
|
24
|
+
>
|
|
19
25
|
{props.text}
|
|
20
26
|
</button>
|
|
21
27
|
)}
|
|
22
|
-
<style>{`.button-
|
|
28
|
+
<style>{`.button-5050ef15 {
|
|
23
29
|
all: unset;
|
|
24
30
|
}`}</style>
|
|
25
31
|
</>
|
|
@@ -132,7 +132,7 @@ function Columns(props) {
|
|
|
132
132
|
<div
|
|
133
133
|
className={
|
|
134
134
|
`builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
135
|
-
" div-
|
|
135
|
+
" div-f0aded1c"
|
|
136
136
|
}
|
|
137
137
|
style={columnsCssVars()}
|
|
138
138
|
dataSet={{
|
|
@@ -147,7 +147,7 @@ function Columns(props) {
|
|
|
147
147
|
|
|
148
148
|
{props.columns?.map((column, index) => (
|
|
149
149
|
<div
|
|
150
|
-
className="builder-column div-
|
|
150
|
+
className="builder-column div-f0aded1c-2"
|
|
151
151
|
style={columnCssVars(index)}
|
|
152
152
|
dataSet={{
|
|
153
153
|
"builder-block-name": "builder-column",
|
|
@@ -165,10 +165,10 @@ function Columns(props) {
|
|
|
165
165
|
</div>
|
|
166
166
|
))}
|
|
167
167
|
</div>
|
|
168
|
-
<style>{`.div-
|
|
168
|
+
<style>{`.div-f0aded1c {
|
|
169
169
|
display: flex;
|
|
170
170
|
line-height: normal;
|
|
171
|
-
}.div-
|
|
171
|
+
}.div-f0aded1c-2 {
|
|
172
172
|
display: flex;
|
|
173
173
|
flex-direction: column;
|
|
174
174
|
align-items: stretch;
|
|
@@ -232,7 +232,7 @@ function FormComponent(props) {
|
|
|
232
232
|
) : null}{" "}
|
|
233
233
|
{submissionState() === "error" && responseData ? (
|
|
234
234
|
<>
|
|
235
|
-
<pre className="builder-form-error-text pre-
|
|
235
|
+
<pre className="builder-form-error-text pre-8b05da54">
|
|
236
236
|
{" "}
|
|
237
237
|
{JSON.stringify(responseData, null, 2)}{" "}
|
|
238
238
|
</pre>
|
|
@@ -247,7 +247,7 @@ function FormComponent(props) {
|
|
|
247
247
|
</>
|
|
248
248
|
) : null}{" "}
|
|
249
249
|
</form>{" "}
|
|
250
|
-
<style>{`.pre-
|
|
250
|
+
<style>{`.pre-8b05da54 { padding: 10px; color: red; text-align: center; }`}</style>{" "}
|
|
251
251
|
</>
|
|
252
252
|
);
|
|
253
253
|
}
|
|
@@ -66,7 +66,7 @@ function Image(props) {
|
|
|
66
66
|
className={
|
|
67
67
|
"builder-image" +
|
|
68
68
|
(props.className ? " " + props.className : "") +
|
|
69
|
-
" img-
|
|
69
|
+
" img-23384452"
|
|
70
70
|
}
|
|
71
71
|
src={props.image}
|
|
72
72
|
srcSet={srcSetToUse()}
|
|
@@ -78,11 +78,9 @@ function Image(props) {
|
|
|
78
78
|
!(props.builderBlock?.children?.length && props.fitContent) ? (
|
|
79
79
|
<>
|
|
80
80
|
<div
|
|
81
|
-
className="builder-image-sizer div-
|
|
81
|
+
className="builder-image-sizer div-23384452"
|
|
82
82
|
style={{
|
|
83
|
-
paddingTop:
|
|
84
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
85
|
-
props.aspectRatio * 100 + "%",
|
|
83
|
+
paddingTop: props.aspectRatio * 100 + "%",
|
|
86
84
|
}}
|
|
87
85
|
/>
|
|
88
86
|
</>
|
|
@@ -94,18 +92,18 @@ function Image(props) {
|
|
|
94
92
|
|
|
95
93
|
{!props.fitContent && props.children ? (
|
|
96
94
|
<>
|
|
97
|
-
<div className="div-
|
|
95
|
+
<div className="div-23384452-2">{props.children}</div>
|
|
98
96
|
</>
|
|
99
97
|
) : null}
|
|
100
98
|
</>
|
|
101
|
-
<style>{`.img-
|
|
99
|
+
<style>{`.img-23384452 {
|
|
102
100
|
opacity: 1;
|
|
103
101
|
transition: opacity 0.2s ease-in-out;
|
|
104
|
-
}.div-
|
|
102
|
+
}.div-23384452 {
|
|
105
103
|
width: 100%;
|
|
106
104
|
pointer-events: none;
|
|
107
105
|
font-size: 0;
|
|
108
|
-
}.div-
|
|
106
|
+
}.div-23384452-2 {
|
|
109
107
|
display: flex;
|
|
110
108
|
flex-direction: column;
|
|
111
109
|
align-items: stretch;
|
|
@@ -45,7 +45,7 @@ function RenderBlocks(props) {
|
|
|
45
45
|
return (
|
|
46
46
|
<>
|
|
47
47
|
<div
|
|
48
|
-
className={className() + " div-
|
|
48
|
+
className={className() + " div-1fdf6196"}
|
|
49
49
|
builder-path={props.path}
|
|
50
50
|
builder-parent-id={props.parent}
|
|
51
51
|
dataSet={{
|
|
@@ -79,7 +79,7 @@ function RenderBlocks(props) {
|
|
|
79
79
|
</>
|
|
80
80
|
) : null}
|
|
81
81
|
</div>
|
|
82
|
-
<style>{`.div-
|
|
82
|
+
<style>{`.div-1fdf6196 {
|
|
83
83
|
display: flex;
|
|
84
84
|
flex-direction: column;
|
|
85
85
|
align-items: stretch;
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getBuilderSearchParamsFromWindow,
|
|
20
20
|
normalizeSearchParams
|
|
21
21
|
} from "../get-builder-search-params/index.js";
|
|
22
|
+
import { DEFAULT_API_VERSION } from "../../types/api-version";
|
|
22
23
|
const generateContentUrl = (options) => {
|
|
23
24
|
const {
|
|
24
25
|
limit = 30,
|
|
@@ -29,7 +30,7 @@ const generateContentUrl = (options) => {
|
|
|
29
30
|
apiKey,
|
|
30
31
|
includeRefs = true,
|
|
31
32
|
locale,
|
|
32
|
-
apiVersion =
|
|
33
|
+
apiVersion = DEFAULT_API_VERSION
|
|
33
34
|
} = options;
|
|
34
35
|
if (!apiKey) {
|
|
35
36
|
throw new Error("Missing API key");
|
|
@@ -28,6 +28,15 @@ describe("Generate Content URL", () => {
|
|
|
28
28
|
});
|
|
29
29
|
expect(output).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
|
+
test("generate content url with apiVersion as default", () => {
|
|
32
|
+
const output = generateContentUrl({
|
|
33
|
+
apiKey: testKey,
|
|
34
|
+
model: testModel,
|
|
35
|
+
query: { id: testId },
|
|
36
|
+
options
|
|
37
|
+
});
|
|
38
|
+
expect(output).toMatchSnapshot();
|
|
39
|
+
});
|
|
31
40
|
test("generate content url with apiVersion as v2", () => {
|
|
32
41
|
const output = generateContentUrl({
|
|
33
42
|
apiKey: testKey,
|
|
@@ -42,7 +42,11 @@ import { handleABTesting } from "./ab-testing.js";
|
|
|
42
42
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
43
43
|
function getContent(options) {
|
|
44
44
|
return __async(this, null, function* () {
|
|
45
|
-
|
|
45
|
+
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
46
|
+
if ("results" in allContent) {
|
|
47
|
+
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
function getAllContent(options) {
|
|
@@ -50,11 +54,19 @@ function getAllContent(options) {
|
|
|
50
54
|
const url = generateContentUrl(options);
|
|
51
55
|
const res = yield fetch(url.href);
|
|
52
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
|
+
}
|
|
53
61
|
const canTrack = options.canTrack !== false;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
try {
|
|
63
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
64
|
+
for (const item of content.results) {
|
|
65
|
+
yield handleABTesting({ item, canTrack });
|
|
66
|
+
}
|
|
57
67
|
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error("[Builder.io]: Could not setup A/B testing. ", e);
|
|
58
70
|
}
|
|
59
71
|
return content;
|
|
60
72
|
});
|
|
@@ -17,11 +17,17 @@ function Button(props) {
|
|
|
17
17
|
</a>
|
|
18
18
|
</>
|
|
19
19
|
) : (
|
|
20
|
-
<button
|
|
20
|
+
<button
|
|
21
|
+
className={
|
|
22
|
+
/** * We have to explicitly provide `class` so that Mitosis knows to merge it with `css`. */
|
|
23
|
+
props.attributes.class + " button-3083674c"
|
|
24
|
+
}
|
|
25
|
+
{...props.attributes}
|
|
26
|
+
>
|
|
21
27
|
{props.text}
|
|
22
28
|
</button>
|
|
23
29
|
)}
|
|
24
|
-
<style>{`.button-
|
|
30
|
+
<style>{`.button-3083674c {
|
|
25
31
|
all: unset;
|
|
26
32
|
}`}</style>
|
|
27
33
|
</>
|
|
@@ -120,7 +120,7 @@ function Columns(props) {
|
|
|
120
120
|
<div
|
|
121
121
|
className={
|
|
122
122
|
`builder-columns ${props.builderBlock.id}-breakpoints` +
|
|
123
|
-
" div-
|
|
123
|
+
" div-38093a46"
|
|
124
124
|
}
|
|
125
125
|
style={state.columnsCssVars}
|
|
126
126
|
dataSet={{
|
|
@@ -138,7 +138,7 @@ function Columns(props) {
|
|
|
138
138
|
|
|
139
139
|
{props.columns?.map((column, index) => (
|
|
140
140
|
<div
|
|
141
|
-
className="builder-column div-
|
|
141
|
+
className="builder-column div-38093a46-2"
|
|
142
142
|
style={state.columnCssVars(index)}
|
|
143
143
|
dataSet={{
|
|
144
144
|
"builder-block-name": "builder-column",
|
|
@@ -157,10 +157,10 @@ function Columns(props) {
|
|
|
157
157
|
</div>
|
|
158
158
|
))}
|
|
159
159
|
</div>
|
|
160
|
-
<style>{`.div-
|
|
160
|
+
<style>{`.div-38093a46 {
|
|
161
161
|
display: flex;
|
|
162
162
|
line-height: normal;
|
|
163
|
-
}.div-
|
|
163
|
+
}.div-38093a46-2 {
|
|
164
164
|
display: flex;
|
|
165
165
|
flex-direction: column;
|
|
166
166
|
align-items: stretch;
|
|
@@ -237,7 +237,7 @@ function FormComponent(props) {
|
|
|
237
237
|
) : null}{" "}
|
|
238
238
|
{state.submissionState === "error" && state.responseData ? (
|
|
239
239
|
<>
|
|
240
|
-
<pre className="builder-form-error-text pre-
|
|
240
|
+
<pre className="builder-form-error-text pre-1adaf299">
|
|
241
241
|
{" "}
|
|
242
242
|
{JSON.stringify(state.responseData, null, 2)}{" "}
|
|
243
243
|
</pre>
|
|
@@ -253,7 +253,7 @@ function FormComponent(props) {
|
|
|
253
253
|
</>
|
|
254
254
|
) : null}{" "}
|
|
255
255
|
</form>{" "}
|
|
256
|
-
<style>{`.pre-
|
|
256
|
+
<style>{`.pre-1adaf299 { padding: 10px; color: red; text-align: center; }`}</style>{" "}
|
|
257
257
|
</>
|
|
258
258
|
);
|
|
259
259
|
}
|
|
@@ -68,7 +68,7 @@ function Image(props) {
|
|
|
68
68
|
className={
|
|
69
69
|
"builder-image" +
|
|
70
70
|
(props.className ? " " + props.className : "") +
|
|
71
|
-
" img-
|
|
71
|
+
" img-2029f6ee"
|
|
72
72
|
}
|
|
73
73
|
src={props.image}
|
|
74
74
|
srcSet={state.srcSetToUse}
|
|
@@ -80,11 +80,9 @@ function Image(props) {
|
|
|
80
80
|
!(props.builderBlock?.children?.length && props.fitContent) ? (
|
|
81
81
|
<>
|
|
82
82
|
<div
|
|
83
|
-
className="builder-image-sizer div-
|
|
83
|
+
className="builder-image-sizer div-2029f6ee"
|
|
84
84
|
style={{
|
|
85
|
-
paddingTop:
|
|
86
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
87
|
-
props.aspectRatio * 100 + "%",
|
|
85
|
+
paddingTop: props.aspectRatio * 100 + "%",
|
|
88
86
|
}}
|
|
89
87
|
/>
|
|
90
88
|
</>
|
|
@@ -96,18 +94,18 @@ function Image(props) {
|
|
|
96
94
|
|
|
97
95
|
{!props.fitContent && props.children ? (
|
|
98
96
|
<>
|
|
99
|
-
<div className="div-
|
|
97
|
+
<div className="div-2029f6ee-2">{props.children}</div>
|
|
100
98
|
</>
|
|
101
99
|
) : null}
|
|
102
100
|
</>
|
|
103
|
-
<style>{`.img-
|
|
101
|
+
<style>{`.img-2029f6ee {
|
|
104
102
|
opacity: 1;
|
|
105
103
|
transition: opacity 0.2s ease-in-out;
|
|
106
|
-
}.div-
|
|
104
|
+
}.div-2029f6ee {
|
|
107
105
|
width: 100%;
|
|
108
106
|
pointer-events: none;
|
|
109
107
|
font-size: 0;
|
|
110
|
-
}.div-
|
|
108
|
+
}.div-2029f6ee-2 {
|
|
111
109
|
display: flex;
|
|
112
110
|
flex-direction: column;
|
|
113
111
|
align-items: stretch;
|
|
@@ -46,7 +46,7 @@ function RenderBlocks(props) {
|
|
|
46
46
|
return (
|
|
47
47
|
<>
|
|
48
48
|
<div
|
|
49
|
-
className={state.className + " div-
|
|
49
|
+
className={state.className + " div-7a14f25c"}
|
|
50
50
|
builder-path={props.path}
|
|
51
51
|
builder-parent-id={props.parent}
|
|
52
52
|
dataSet={{
|
|
@@ -80,7 +80,7 @@ function RenderBlocks(props) {
|
|
|
80
80
|
</>
|
|
81
81
|
) : null}
|
|
82
82
|
</div>
|
|
83
|
-
<style>{`.div-
|
|
83
|
+
<style>{`.div-7a14f25c {
|
|
84
84
|
display: flex;
|
|
85
85
|
flex-direction: column;
|
|
86
86
|
align-items: stretch;
|
|
@@ -177,7 +177,7 @@ function RenderContent(props) {
|
|
|
177
177
|
state.setContextState(newState);
|
|
178
178
|
})
|
|
179
179
|
.catch((err) => {
|
|
180
|
-
console.
|
|
180
|
+
console.error("error fetching dynamic data", url, err);
|
|
181
181
|
});
|
|
182
182
|
},
|
|
183
183
|
runHttpRequests() {
|
|
@@ -19,6 +19,7 @@ import {
|
|
|
19
19
|
getBuilderSearchParamsFromWindow,
|
|
20
20
|
normalizeSearchParams
|
|
21
21
|
} from "../get-builder-search-params/index.js";
|
|
22
|
+
import { DEFAULT_API_VERSION } from "../../types/api-version";
|
|
22
23
|
const generateContentUrl = (options) => {
|
|
23
24
|
const {
|
|
24
25
|
limit = 30,
|
|
@@ -29,7 +30,7 @@ const generateContentUrl = (options) => {
|
|
|
29
30
|
apiKey,
|
|
30
31
|
includeRefs = true,
|
|
31
32
|
locale,
|
|
32
|
-
apiVersion =
|
|
33
|
+
apiVersion = DEFAULT_API_VERSION
|
|
33
34
|
} = options;
|
|
34
35
|
if (!apiKey) {
|
|
35
36
|
throw new Error("Missing API key");
|
|
@@ -28,6 +28,15 @@ describe("Generate Content URL", () => {
|
|
|
28
28
|
});
|
|
29
29
|
expect(output).toMatchSnapshot();
|
|
30
30
|
});
|
|
31
|
+
test("generate content url with apiVersion as default", () => {
|
|
32
|
+
const output = generateContentUrl({
|
|
33
|
+
apiKey: testKey,
|
|
34
|
+
model: testModel,
|
|
35
|
+
query: { id: testId },
|
|
36
|
+
options
|
|
37
|
+
});
|
|
38
|
+
expect(output).toMatchSnapshot();
|
|
39
|
+
});
|
|
31
40
|
test("generate content url with apiVersion as v2", () => {
|
|
32
41
|
const output = generateContentUrl({
|
|
33
42
|
apiKey: testKey,
|
|
@@ -42,7 +42,11 @@ import { handleABTesting } from "./ab-testing.js";
|
|
|
42
42
|
import { generateContentUrl } from "./generate-content-url.js";
|
|
43
43
|
function getContent(options) {
|
|
44
44
|
return __async(this, null, function* () {
|
|
45
|
-
|
|
45
|
+
const allContent = yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }));
|
|
46
|
+
if ("results" in allContent) {
|
|
47
|
+
return (allContent == null ? void 0 : allContent.results[0]) || null;
|
|
48
|
+
}
|
|
49
|
+
return null;
|
|
46
50
|
});
|
|
47
51
|
}
|
|
48
52
|
function getAllContent(options) {
|
|
@@ -50,11 +54,19 @@ function getAllContent(options) {
|
|
|
50
54
|
const url = generateContentUrl(options);
|
|
51
55
|
const res = yield fetch(url.href);
|
|
52
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
|
+
}
|
|
53
61
|
const canTrack = options.canTrack !== false;
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
62
|
+
try {
|
|
63
|
+
if (canTrack && Array.isArray(content.results)) {
|
|
64
|
+
for (const item of content.results) {
|
|
65
|
+
yield handleABTesting({ item, canTrack });
|
|
66
|
+
}
|
|
57
67
|
}
|
|
68
|
+
} catch (e) {
|
|
69
|
+
console.error("[Builder.io]: Could not setup A/B testing. ", e);
|
|
58
70
|
}
|
|
59
71
|
return content;
|
|
60
72
|
});
|