@builder.io/sdk-react 0.1.16 → 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 +19 -0
- package/dist/react/components/render-block/block-styles.js +3 -0
- package/dist/react/components/render-block/render-block.helpers.js +16 -1
- package/dist/react/components/render-block/render-block.js +34 -52
- package/dist/react/components/render-inlined-styles.js +3 -3
- 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/types/api-version.js +2 -1
- package/dist/rsc/components/render-block/block-styles.js +3 -0
- package/dist/rsc/components/render-block/render-block.helpers.js +16 -1
- package/dist/rsc/components/render-block/render-block.js +30 -48
- package/dist/rsc/components/render-inlined-styles.js +3 -3
- 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/types/api-version.js +2 -1
- package/package.json +1 -1
- package/packages/react/src/components/render-block/block-styles.jsx +3 -0
- package/packages/react/src/components/render-block/render-block.helpers.js +16 -0
- package/packages/react/src/components/render-block/render-block.jsx +40 -58
- package/packages/react/src/components/render-inlined-styles.jsx +4 -4
- 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/types/api-version.js +4 -0
- package/packages/rsc/src/components/render-block/block-styles.jsx +3 -0
- package/packages/rsc/src/components/render-block/render-block.helpers.js +16 -0
- package/packages/rsc/src/components/render-block/render-block.jsx +30 -50
- package/packages/rsc/src/components/render-inlined-styles.jsx +3 -3
- 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/types/api-version.js +4 -0
- package/packages/react/src/functions/get-block-tag.js +0 -6
- package/packages/rsc/src/functions/get-block-tag.js +0 -6
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
### 0.2.1
|
|
2
|
+
|
|
3
|
+
- No Changes.
|
|
4
|
+
|
|
5
|
+
### 0.2.0
|
|
6
|
+
|
|
7
|
+
- Sets the default `apiVersion` to `v3`.
|
|
8
|
+
|
|
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:
|
|
10
|
+
|
|
11
|
+
```jsx
|
|
12
|
+
<RenderContent apiVersion="v2" />
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
getContent({ apiVersion: 'v2' });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
More details on the Builder API Versions visit [this link](https://www.builder.io/c/docs/content-api-versions).
|
|
@@ -32,6 +32,9 @@ function BlockStyles(props) {
|
|
|
32
32
|
const mediumStyles = styles?.medium;
|
|
33
33
|
const smallStyles = styles?.small;
|
|
34
34
|
const className = useBlock().id;
|
|
35
|
+
if (!className) {
|
|
36
|
+
return "";
|
|
37
|
+
}
|
|
35
38
|
const largeStylesClass = largeStyles
|
|
36
39
|
? createCssClass({
|
|
37
40
|
className,
|
|
@@ -101,4 +101,19 @@ const getRepeatItemData = ({ block, context }) => {
|
|
|
101
101
|
}));
|
|
102
102
|
return repeatArray;
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
const getProxyState = (context) => {
|
|
105
|
+
if (typeof Proxy === "undefined") {
|
|
106
|
+
console.error("no Proxy available in this environment, cannot proxy state.");
|
|
107
|
+
return context.state;
|
|
108
|
+
}
|
|
109
|
+
const useState = new Proxy(context.state, {
|
|
110
|
+
set: (obj, prop, value) => {
|
|
111
|
+
var _a;
|
|
112
|
+
obj[prop] = value;
|
|
113
|
+
(_a = context.setState) == null ? void 0 : _a.call(context, obj);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return useState;
|
|
118
|
+
};
|
|
119
|
+
export { getComponent, getProxyState, getRepeatItemData, isEmptyHtmlElement };
|
|
@@ -3,10 +3,9 @@ import { useState } from "react";
|
|
|
3
3
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
4
4
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
5
5
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
6
|
-
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
7
6
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
8
7
|
import BlockStyles from "./block-styles";
|
|
9
|
-
import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./render-block.helpers.js";
|
|
8
|
+
import { getComponent, getProxyState, getRepeatItemData, isEmptyHtmlElement, } from "./render-block.helpers.js";
|
|
10
9
|
import RenderRepeatedBlock from "./render-repeated-block";
|
|
11
10
|
import { TARGET } from "../../constants/target.js";
|
|
12
11
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
@@ -18,9 +17,10 @@ function RenderBlock(props) {
|
|
|
18
17
|
block: props.block,
|
|
19
18
|
context: props.context,
|
|
20
19
|
}));
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const [repeatItemData, setRepeatItemData] = useState(() => getRepeatItemData({
|
|
21
|
+
block: props.block,
|
|
22
|
+
context: props.context,
|
|
23
|
+
}));
|
|
24
24
|
function useBlock() {
|
|
25
25
|
return repeatItemData
|
|
26
26
|
? props.block
|
|
@@ -31,6 +31,7 @@ function RenderBlock(props) {
|
|
|
31
31
|
shouldEvaluateBindings: true,
|
|
32
32
|
});
|
|
33
33
|
}
|
|
34
|
+
const [tag, setTag] = useState(() => props.block.tagName || "div");
|
|
34
35
|
function canShowBlock() {
|
|
35
36
|
if (checkIsDefined(useBlock().hide)) {
|
|
36
37
|
return !useBlock().hide;
|
|
@@ -40,26 +41,11 @@ function RenderBlock(props) {
|
|
|
40
41
|
}
|
|
41
42
|
return true;
|
|
42
43
|
}
|
|
43
|
-
|
|
44
|
-
if (typeof Proxy === "undefined") {
|
|
45
|
-
console.error("no Proxy available in this environment, cannot proxy state.");
|
|
46
|
-
return props.context.state;
|
|
47
|
-
}
|
|
48
|
-
const useState = new Proxy(props.context.state, {
|
|
49
|
-
set: (obj, prop, value) => {
|
|
50
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
51
|
-
obj[prop] = value;
|
|
52
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
53
|
-
props.context.setState?.(obj);
|
|
54
|
-
return true;
|
|
55
|
-
},
|
|
56
|
-
});
|
|
57
|
-
return useState;
|
|
58
|
-
}
|
|
44
|
+
const [proxyState, setProxyState] = useState(() => getProxyState(props.context));
|
|
59
45
|
function actions() {
|
|
60
46
|
return getBlockActions({
|
|
61
47
|
block: useBlock(),
|
|
62
|
-
state: proxyState
|
|
48
|
+
state: TARGET === "qwik" ? props.context.state : proxyState,
|
|
63
49
|
context: props.context.context,
|
|
64
50
|
});
|
|
65
51
|
}
|
|
@@ -78,28 +64,6 @@ function RenderBlock(props) {
|
|
|
78
64
|
: {}),
|
|
79
65
|
};
|
|
80
66
|
}
|
|
81
|
-
function renderComponentProps() {
|
|
82
|
-
return {
|
|
83
|
-
blockChildren: useBlock().children ?? [],
|
|
84
|
-
componentRef: component?.component,
|
|
85
|
-
componentOptions: {
|
|
86
|
-
...getBlockComponentOptions(useBlock()),
|
|
87
|
-
/**
|
|
88
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
89
|
-
* they are provided to the component itself directly.
|
|
90
|
-
*/
|
|
91
|
-
...(!component?.noWrap
|
|
92
|
-
? {}
|
|
93
|
-
: {
|
|
94
|
-
attributes: {
|
|
95
|
-
...attributes(),
|
|
96
|
-
...actions(),
|
|
97
|
-
},
|
|
98
|
-
}),
|
|
99
|
-
},
|
|
100
|
-
context: childrenContext(),
|
|
101
|
-
};
|
|
102
|
-
}
|
|
103
67
|
function childrenWithoutParentComponent() {
|
|
104
68
|
/**
|
|
105
69
|
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
@@ -110,10 +74,6 @@ function RenderBlock(props) {
|
|
|
110
74
|
const shouldRenderChildrenOutsideRef = !component?.component && !repeatItemData;
|
|
111
75
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
112
76
|
}
|
|
113
|
-
const [repeatItemData, setRepeatItemData] = useState(() => getRepeatItemData({
|
|
114
|
-
block: props.block,
|
|
115
|
-
context: props.context,
|
|
116
|
-
}));
|
|
117
77
|
function childrenContext() {
|
|
118
78
|
const getInheritedTextStyles = () => {
|
|
119
79
|
if (TARGET !== "reactNative") {
|
|
@@ -136,12 +96,34 @@ function RenderBlock(props) {
|
|
|
136
96
|
inheritedStyles: getInheritedTextStyles(),
|
|
137
97
|
};
|
|
138
98
|
}
|
|
139
|
-
|
|
99
|
+
function renderComponentProps() {
|
|
100
|
+
return {
|
|
101
|
+
blockChildren: useBlock().children ?? [],
|
|
102
|
+
componentRef: component?.component,
|
|
103
|
+
componentOptions: {
|
|
104
|
+
...getBlockComponentOptions(useBlock()),
|
|
105
|
+
/**
|
|
106
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
107
|
+
* they are provided to the component itself directly.
|
|
108
|
+
*/
|
|
109
|
+
...(!component?.noWrap
|
|
110
|
+
? {}
|
|
111
|
+
: {
|
|
112
|
+
attributes: {
|
|
113
|
+
...attributes(),
|
|
114
|
+
...actions(),
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
context: childrenContext(),
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
const TagRef = tag;
|
|
140
122
|
return (React.createElement(React.Fragment, null, canShowBlock() ? (React.createElement(React.Fragment, null, !component?.noWrap ? (React.createElement(React.Fragment, null,
|
|
141
|
-
isEmptyHtmlElement(tag
|
|
123
|
+
isEmptyHtmlElement(tag) ? (React.createElement(React.Fragment, null,
|
|
142
124
|
React.createElement(TagRef, { ...attributes(), ...actions() }))) : null,
|
|
143
|
-
!isEmptyHtmlElement(tag
|
|
144
|
-
!isEmptyHtmlElement(tag
|
|
125
|
+
!isEmptyHtmlElement(tag) && repeatItemData ? (React.createElement(React.Fragment, null, repeatItemData?.map((data, index) => (React.createElement(RenderRepeatedBlock, { key: index, repeatContext: data.context, block: data.block }))))) : null,
|
|
126
|
+
!isEmptyHtmlElement(tag) && !repeatItemData ? (React.createElement(React.Fragment, null,
|
|
145
127
|
React.createElement(TagRef, { ...attributes(), ...actions() },
|
|
146
128
|
React.createElement(RenderComponent, { ...renderComponentProps() }),
|
|
147
129
|
childrenWithoutParentComponent()?.map((child) => (React.createElement(RenderBlock, { key: "render-block-" + child.id, block: child, context: childrenContext() }))),
|
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { TARGET } from "../constants/target.js";
|
|
3
3
|
function RenderInlinedStyles(props) {
|
|
4
|
-
function injectedStyleScript() {
|
|
5
|
-
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
6
|
-
}
|
|
7
4
|
function tag() {
|
|
8
5
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
9
6
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
10
7
|
return "sty" + "le";
|
|
11
8
|
}
|
|
9
|
+
function injectedStyleScript() {
|
|
10
|
+
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
11
|
+
}
|
|
12
12
|
const TagRef = tag();
|
|
13
13
|
return (React.createElement(React.Fragment, null, TARGET === "svelte" || TARGET === "qwik" ? (React.createElement(React.Fragment, null,
|
|
14
14
|
React.createElement(TagRef, { dangerouslySetInnerHTML: { __html: props.styles } }))) : (React.createElement(TagRef, null, props.styles))));
|
|
@@ -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,
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const DEFAULT_API_VERSION = "v3";
|
|
2
|
+
export { DEFAULT_API_VERSION };
|
|
@@ -34,6 +34,9 @@ function BlockStyles(props) {
|
|
|
34
34
|
const mediumStyles = styles?.medium;
|
|
35
35
|
const smallStyles = styles?.small;
|
|
36
36
|
const className = state.useBlock.id;
|
|
37
|
+
if (!className) {
|
|
38
|
+
return "";
|
|
39
|
+
}
|
|
37
40
|
const largeStylesClass = largeStyles
|
|
38
41
|
? createCssClass({
|
|
39
42
|
className,
|
|
@@ -101,4 +101,19 @@ const getRepeatItemData = ({ block, context }) => {
|
|
|
101
101
|
}));
|
|
102
102
|
return repeatArray;
|
|
103
103
|
};
|
|
104
|
-
|
|
104
|
+
const getProxyState = (context) => {
|
|
105
|
+
if (typeof Proxy === "undefined") {
|
|
106
|
+
console.error("no Proxy available in this environment, cannot proxy state.");
|
|
107
|
+
return context.state;
|
|
108
|
+
}
|
|
109
|
+
const useState = new Proxy(context.state, {
|
|
110
|
+
set: (obj, prop, value) => {
|
|
111
|
+
var _a;
|
|
112
|
+
obj[prop] = value;
|
|
113
|
+
(_a = context.setState) == null ? void 0 : _a.call(context, obj);
|
|
114
|
+
return true;
|
|
115
|
+
}
|
|
116
|
+
});
|
|
117
|
+
return useState;
|
|
118
|
+
};
|
|
119
|
+
export { getComponent, getProxyState, getRepeatItemData, isEmptyHtmlElement };
|
|
@@ -2,10 +2,9 @@ import * as React from "react";
|
|
|
2
2
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
3
3
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
4
4
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
5
|
-
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
6
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
7
6
|
import BlockStyles from "./block-styles";
|
|
8
|
-
import { getComponent, getRepeatItemData, isEmptyHtmlElement, } from "./render-block.helpers.js";
|
|
7
|
+
import { getComponent, getProxyState, getRepeatItemData, isEmptyHtmlElement, } from "./render-block.helpers.js";
|
|
9
8
|
import RenderRepeatedBlock from "./render-repeated-block";
|
|
10
9
|
import { TARGET } from "../../constants/target.js";
|
|
11
10
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
@@ -19,9 +18,10 @@ function RenderBlock(props) {
|
|
|
19
18
|
block: props.block,
|
|
20
19
|
context: props.context,
|
|
21
20
|
}),
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
21
|
+
repeatItemData: getRepeatItemData({
|
|
22
|
+
block: props.block,
|
|
23
|
+
context: props.context,
|
|
24
|
+
}),
|
|
25
25
|
get useBlock() {
|
|
26
26
|
return state.repeatItemData
|
|
27
27
|
? props.block
|
|
@@ -32,6 +32,7 @@ function RenderBlock(props) {
|
|
|
32
32
|
shouldEvaluateBindings: true,
|
|
33
33
|
});
|
|
34
34
|
},
|
|
35
|
+
tag: props.block.tagName || "div",
|
|
35
36
|
get canShowBlock() {
|
|
36
37
|
if (checkIsDefined(state.useBlock.hide)) {
|
|
37
38
|
return !state.useBlock.hide;
|
|
@@ -41,26 +42,11 @@ function RenderBlock(props) {
|
|
|
41
42
|
}
|
|
42
43
|
return true;
|
|
43
44
|
},
|
|
44
|
-
|
|
45
|
-
if (typeof Proxy === "undefined") {
|
|
46
|
-
console.error("no Proxy available in this environment, cannot proxy state.");
|
|
47
|
-
return props.context.state;
|
|
48
|
-
}
|
|
49
|
-
const useState = new Proxy(props.context.state, {
|
|
50
|
-
set: (obj, prop, value) => {
|
|
51
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
52
|
-
obj[prop] = value;
|
|
53
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
54
|
-
props.context.setState?.(obj);
|
|
55
|
-
return true;
|
|
56
|
-
},
|
|
57
|
-
});
|
|
58
|
-
return useState;
|
|
59
|
-
},
|
|
45
|
+
proxyState: getProxyState(props.context),
|
|
60
46
|
get actions() {
|
|
61
47
|
return getBlockActions({
|
|
62
48
|
block: state.useBlock,
|
|
63
|
-
state: state.proxyState,
|
|
49
|
+
state: TARGET === "qwik" ? props.context.state : state.proxyState,
|
|
64
50
|
context: props.context.context,
|
|
65
51
|
});
|
|
66
52
|
},
|
|
@@ -79,28 +65,6 @@ function RenderBlock(props) {
|
|
|
79
65
|
: {}),
|
|
80
66
|
};
|
|
81
67
|
},
|
|
82
|
-
get renderComponentProps() {
|
|
83
|
-
return {
|
|
84
|
-
blockChildren: state.useBlock.children ?? [],
|
|
85
|
-
componentRef: state.component?.component,
|
|
86
|
-
componentOptions: {
|
|
87
|
-
...getBlockComponentOptions(state.useBlock),
|
|
88
|
-
/**
|
|
89
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
90
|
-
* they are provided to the component itself directly.
|
|
91
|
-
*/
|
|
92
|
-
...(!state.component?.noWrap
|
|
93
|
-
? {}
|
|
94
|
-
: {
|
|
95
|
-
attributes: {
|
|
96
|
-
...state.attributes,
|
|
97
|
-
...state.actions,
|
|
98
|
-
},
|
|
99
|
-
}),
|
|
100
|
-
},
|
|
101
|
-
context: state.childrenContext,
|
|
102
|
-
};
|
|
103
|
-
},
|
|
104
68
|
get childrenWithoutParentComponent() {
|
|
105
69
|
/**
|
|
106
70
|
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
@@ -113,10 +77,6 @@ function RenderBlock(props) {
|
|
|
113
77
|
? state.useBlock.children ?? []
|
|
114
78
|
: [];
|
|
115
79
|
},
|
|
116
|
-
repeatItemData: getRepeatItemData({
|
|
117
|
-
block: props.block,
|
|
118
|
-
context: props.context,
|
|
119
|
-
}),
|
|
120
80
|
get childrenContext() {
|
|
121
81
|
const getInheritedTextStyles = () => {
|
|
122
82
|
if (TARGET !== "reactNative") {
|
|
@@ -139,6 +99,28 @@ function RenderBlock(props) {
|
|
|
139
99
|
inheritedStyles: getInheritedTextStyles(),
|
|
140
100
|
};
|
|
141
101
|
},
|
|
102
|
+
get renderComponentProps() {
|
|
103
|
+
return {
|
|
104
|
+
blockChildren: state.useBlock.children ?? [],
|
|
105
|
+
componentRef: state.component?.component,
|
|
106
|
+
componentOptions: {
|
|
107
|
+
...getBlockComponentOptions(state.useBlock),
|
|
108
|
+
/**
|
|
109
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
110
|
+
* they are provided to the component itself directly.
|
|
111
|
+
*/
|
|
112
|
+
...(!state.component?.noWrap
|
|
113
|
+
? {}
|
|
114
|
+
: {
|
|
115
|
+
attributes: {
|
|
116
|
+
...state.attributes,
|
|
117
|
+
...state.actions,
|
|
118
|
+
},
|
|
119
|
+
}),
|
|
120
|
+
},
|
|
121
|
+
context: state.childrenContext,
|
|
122
|
+
};
|
|
123
|
+
},
|
|
142
124
|
};
|
|
143
125
|
const TagRef = state.tag;
|
|
144
126
|
return (React.createElement(React.Fragment, null, state.canShowBlock ? (React.createElement(React.Fragment, null, !state.component?.noWrap ? (React.createElement(React.Fragment, null,
|
|
@@ -3,14 +3,14 @@ import { TARGET } from "../constants/target.js";
|
|
|
3
3
|
function RenderInlinedStyles(props) {
|
|
4
4
|
const _context = { ...props["_context"] };
|
|
5
5
|
const state = {
|
|
6
|
-
get injectedStyleScript() {
|
|
7
|
-
return `<${state.tag}>${props.styles}</${state.tag}>`;
|
|
8
|
-
},
|
|
9
6
|
get tag() {
|
|
10
7
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
11
8
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
12
9
|
return "sty" + "le";
|
|
13
10
|
},
|
|
11
|
+
get injectedStyleScript() {
|
|
12
|
+
return `<${state.tag}>${props.styles}</${state.tag}>`;
|
|
13
|
+
},
|
|
14
14
|
};
|
|
15
15
|
const TagRef = state.tag;
|
|
16
16
|
return (React.createElement(React.Fragment, null, TARGET === "svelte" || TARGET === "qwik" ? (React.createElement(React.Fragment, null,
|
|
@@ -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,
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
const DEFAULT_API_VERSION = "v3";
|
|
2
|
+
export { DEFAULT_API_VERSION };
|
package/package.json
CHANGED
|
@@ -40,6 +40,9 @@ function BlockStyles(props) {
|
|
|
40
40
|
const mediumStyles = styles?.medium;
|
|
41
41
|
const smallStyles = styles?.small;
|
|
42
42
|
const className = useBlock().id;
|
|
43
|
+
if (!className) {
|
|
44
|
+
return "";
|
|
45
|
+
}
|
|
43
46
|
const largeStylesClass = largeStyles
|
|
44
47
|
? createCssClass({
|
|
45
48
|
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
|
};
|
|
@@ -3,11 +3,11 @@ import { useState } from "react";
|
|
|
3
3
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
4
4
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
5
5
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
6
|
-
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
7
6
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
8
7
|
import BlockStyles from "./block-styles";
|
|
9
8
|
import {
|
|
10
9
|
getComponent,
|
|
10
|
+
getProxyState,
|
|
11
11
|
getRepeatItemData,
|
|
12
12
|
isEmptyHtmlElement,
|
|
13
13
|
} from "./render-block.helpers.js";
|
|
@@ -26,9 +26,12 @@ function RenderBlock(props) {
|
|
|
26
26
|
})
|
|
27
27
|
);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
29
|
+
const [repeatItemData, setRepeatItemData] = useState(() =>
|
|
30
|
+
getRepeatItemData({
|
|
31
|
+
block: props.block,
|
|
32
|
+
context: props.context,
|
|
33
|
+
})
|
|
34
|
+
);
|
|
32
35
|
|
|
33
36
|
function useBlock() {
|
|
34
37
|
return repeatItemData
|
|
@@ -41,6 +44,8 @@ function RenderBlock(props) {
|
|
|
41
44
|
});
|
|
42
45
|
}
|
|
43
46
|
|
|
47
|
+
const [tag, setTag] = useState(() => props.block.tagName || "div");
|
|
48
|
+
|
|
44
49
|
function canShowBlock() {
|
|
45
50
|
if (checkIsDefined(useBlock().hide)) {
|
|
46
51
|
return !useBlock().hide;
|
|
@@ -51,30 +56,14 @@ function RenderBlock(props) {
|
|
|
51
56
|
return true;
|
|
52
57
|
}
|
|
53
58
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
"no Proxy available in this environment, cannot proxy state."
|
|
58
|
-
);
|
|
59
|
-
return props.context.state;
|
|
60
|
-
}
|
|
61
|
-
const useState = new Proxy(props.context.state, {
|
|
62
|
-
set: (obj, prop, value) => {
|
|
63
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
64
|
-
obj[prop] = value;
|
|
65
|
-
|
|
66
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
67
|
-
props.context.setState?.(obj);
|
|
68
|
-
return true;
|
|
69
|
-
},
|
|
70
|
-
});
|
|
71
|
-
return useState;
|
|
72
|
-
}
|
|
59
|
+
const [proxyState, setProxyState] = useState(() =>
|
|
60
|
+
getProxyState(props.context)
|
|
61
|
+
);
|
|
73
62
|
|
|
74
63
|
function actions() {
|
|
75
64
|
return getBlockActions({
|
|
76
65
|
block: useBlock(),
|
|
77
|
-
state: proxyState
|
|
66
|
+
state: TARGET === "qwik" ? props.context.state : proxyState,
|
|
78
67
|
context: props.context.context,
|
|
79
68
|
});
|
|
80
69
|
}
|
|
@@ -95,29 +84,6 @@ function RenderBlock(props) {
|
|
|
95
84
|
};
|
|
96
85
|
}
|
|
97
86
|
|
|
98
|
-
function renderComponentProps() {
|
|
99
|
-
return {
|
|
100
|
-
blockChildren: useBlock().children ?? [],
|
|
101
|
-
componentRef: component?.component,
|
|
102
|
-
componentOptions: {
|
|
103
|
-
...getBlockComponentOptions(useBlock()),
|
|
104
|
-
/**
|
|
105
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
106
|
-
* they are provided to the component itself directly.
|
|
107
|
-
*/
|
|
108
|
-
...(!component?.noWrap
|
|
109
|
-
? {}
|
|
110
|
-
: {
|
|
111
|
-
attributes: {
|
|
112
|
-
...attributes(),
|
|
113
|
-
...actions(),
|
|
114
|
-
},
|
|
115
|
-
}),
|
|
116
|
-
},
|
|
117
|
-
context: childrenContext(),
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
|
|
121
87
|
function childrenWithoutParentComponent() {
|
|
122
88
|
/**
|
|
123
89
|
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
@@ -130,13 +96,6 @@ function RenderBlock(props) {
|
|
|
130
96
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
131
97
|
}
|
|
132
98
|
|
|
133
|
-
const [repeatItemData, setRepeatItemData] = useState(() =>
|
|
134
|
-
getRepeatItemData({
|
|
135
|
-
block: props.block,
|
|
136
|
-
context: props.context,
|
|
137
|
-
})
|
|
138
|
-
);
|
|
139
|
-
|
|
140
99
|
function childrenContext() {
|
|
141
100
|
const getInheritedTextStyles = () => {
|
|
142
101
|
if (TARGET !== "reactNative") {
|
|
@@ -162,7 +121,30 @@ function RenderBlock(props) {
|
|
|
162
121
|
};
|
|
163
122
|
}
|
|
164
123
|
|
|
165
|
-
|
|
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
|
+
|
|
147
|
+
const TagRef = tag;
|
|
166
148
|
|
|
167
149
|
return (
|
|
168
150
|
<>
|
|
@@ -170,12 +152,12 @@ function RenderBlock(props) {
|
|
|
170
152
|
<>
|
|
171
153
|
{!component?.noWrap ? (
|
|
172
154
|
<>
|
|
173
|
-
{isEmptyHtmlElement(tag
|
|
155
|
+
{isEmptyHtmlElement(tag) ? (
|
|
174
156
|
<>
|
|
175
157
|
<TagRef {...attributes()} {...actions()} />
|
|
176
158
|
</>
|
|
177
159
|
) : null}
|
|
178
|
-
{!isEmptyHtmlElement(tag
|
|
160
|
+
{!isEmptyHtmlElement(tag) && repeatItemData ? (
|
|
179
161
|
<>
|
|
180
162
|
{repeatItemData?.map((data, index) => (
|
|
181
163
|
<RenderRepeatedBlock
|
|
@@ -186,7 +168,7 @@ function RenderBlock(props) {
|
|
|
186
168
|
))}
|
|
187
169
|
</>
|
|
188
170
|
) : null}
|
|
189
|
-
{!isEmptyHtmlElement(tag
|
|
171
|
+
{!isEmptyHtmlElement(tag) && !repeatItemData ? (
|
|
190
172
|
<>
|
|
191
173
|
<TagRef {...attributes()} {...actions()}>
|
|
192
174
|
<RenderComponent {...renderComponentProps()} />
|
|
@@ -2,16 +2,16 @@ import * as React from "react";
|
|
|
2
2
|
import { TARGET } from "../constants/target.js";
|
|
3
3
|
|
|
4
4
|
function RenderInlinedStyles(props) {
|
|
5
|
-
function injectedStyleScript() {
|
|
6
|
-
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
5
|
function tag() {
|
|
10
6
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
11
7
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
12
8
|
return "sty" + "le";
|
|
13
9
|
}
|
|
14
10
|
|
|
11
|
+
function injectedStyleScript() {
|
|
12
|
+
return `<${tag()}>${props.styles}</${tag()}>`;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
15
|
const TagRef = tag();
|
|
16
16
|
|
|
17
17
|
return (
|
|
@@ -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,
|
|
@@ -41,6 +41,9 @@ function BlockStyles(props) {
|
|
|
41
41
|
const mediumStyles = styles?.medium;
|
|
42
42
|
const smallStyles = styles?.small;
|
|
43
43
|
const className = state.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
|
};
|
|
@@ -2,11 +2,11 @@ import * as React from "react";
|
|
|
2
2
|
import { getBlockActions } from "../../functions/get-block-actions.js";
|
|
3
3
|
import { getBlockComponentOptions } from "../../functions/get-block-component-options.js";
|
|
4
4
|
import { getBlockProperties } from "../../functions/get-block-properties.js";
|
|
5
|
-
import { getBlockTag } from "../../functions/get-block-tag.js";
|
|
6
5
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
7
6
|
import BlockStyles from "./block-styles";
|
|
8
7
|
import {
|
|
9
8
|
getComponent,
|
|
9
|
+
getProxyState,
|
|
10
10
|
getRepeatItemData,
|
|
11
11
|
isEmptyHtmlElement,
|
|
12
12
|
} from "./render-block.helpers.js";
|
|
@@ -25,9 +25,10 @@ function RenderBlock(props) {
|
|
|
25
25
|
block: props.block,
|
|
26
26
|
context: props.context,
|
|
27
27
|
}),
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
repeatItemData: getRepeatItemData({
|
|
29
|
+
block: props.block,
|
|
30
|
+
context: props.context,
|
|
31
|
+
}),
|
|
31
32
|
get useBlock() {
|
|
32
33
|
return state.repeatItemData
|
|
33
34
|
? props.block
|
|
@@ -38,6 +39,7 @@ function RenderBlock(props) {
|
|
|
38
39
|
shouldEvaluateBindings: true,
|
|
39
40
|
});
|
|
40
41
|
},
|
|
42
|
+
tag: props.block.tagName || "div",
|
|
41
43
|
get canShowBlock() {
|
|
42
44
|
if (checkIsDefined(state.useBlock.hide)) {
|
|
43
45
|
return !state.useBlock.hide;
|
|
@@ -47,29 +49,11 @@ function RenderBlock(props) {
|
|
|
47
49
|
}
|
|
48
50
|
return true;
|
|
49
51
|
},
|
|
50
|
-
|
|
51
|
-
if (typeof Proxy === "undefined") {
|
|
52
|
-
console.error(
|
|
53
|
-
"no Proxy available in this environment, cannot proxy state."
|
|
54
|
-
);
|
|
55
|
-
return props.context.state;
|
|
56
|
-
}
|
|
57
|
-
const useState = new Proxy(props.context.state, {
|
|
58
|
-
set: (obj, prop, value) => {
|
|
59
|
-
// set the value on the state object, so that the event handler instantly gets the update.
|
|
60
|
-
obj[prop] = value;
|
|
61
|
-
|
|
62
|
-
// set the value in the context, so that the rest of the app gets the update.
|
|
63
|
-
props.context.setState?.(obj);
|
|
64
|
-
return true;
|
|
65
|
-
},
|
|
66
|
-
});
|
|
67
|
-
return useState;
|
|
68
|
-
},
|
|
52
|
+
proxyState: getProxyState(props.context),
|
|
69
53
|
get actions() {
|
|
70
54
|
return getBlockActions({
|
|
71
55
|
block: state.useBlock,
|
|
72
|
-
state: state.proxyState,
|
|
56
|
+
state: TARGET === "qwik" ? props.context.state : state.proxyState,
|
|
73
57
|
context: props.context.context,
|
|
74
58
|
});
|
|
75
59
|
},
|
|
@@ -88,28 +72,6 @@ function RenderBlock(props) {
|
|
|
88
72
|
: {}),
|
|
89
73
|
};
|
|
90
74
|
},
|
|
91
|
-
get renderComponentProps() {
|
|
92
|
-
return {
|
|
93
|
-
blockChildren: state.useBlock.children ?? [],
|
|
94
|
-
componentRef: state.component?.component,
|
|
95
|
-
componentOptions: {
|
|
96
|
-
...getBlockComponentOptions(state.useBlock),
|
|
97
|
-
/**
|
|
98
|
-
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
99
|
-
* they are provided to the component itself directly.
|
|
100
|
-
*/
|
|
101
|
-
...(!state.component?.noWrap
|
|
102
|
-
? {}
|
|
103
|
-
: {
|
|
104
|
-
attributes: {
|
|
105
|
-
...state.attributes,
|
|
106
|
-
...state.actions,
|
|
107
|
-
},
|
|
108
|
-
}),
|
|
109
|
-
},
|
|
110
|
-
context: state.childrenContext,
|
|
111
|
-
};
|
|
112
|
-
},
|
|
113
75
|
get childrenWithoutParentComponent() {
|
|
114
76
|
/**
|
|
115
77
|
* When there is no `componentRef`, there might still be children that need to be rendered. In this case,
|
|
@@ -123,10 +85,6 @@ function RenderBlock(props) {
|
|
|
123
85
|
? state.useBlock.children ?? []
|
|
124
86
|
: [];
|
|
125
87
|
},
|
|
126
|
-
repeatItemData: getRepeatItemData({
|
|
127
|
-
block: props.block,
|
|
128
|
-
context: props.context,
|
|
129
|
-
}),
|
|
130
88
|
get childrenContext() {
|
|
131
89
|
const getInheritedTextStyles = () => {
|
|
132
90
|
if (TARGET !== "reactNative") {
|
|
@@ -151,6 +109,28 @@ function RenderBlock(props) {
|
|
|
151
109
|
inheritedStyles: getInheritedTextStyles(),
|
|
152
110
|
};
|
|
153
111
|
},
|
|
112
|
+
get renderComponentProps() {
|
|
113
|
+
return {
|
|
114
|
+
blockChildren: state.useBlock.children ?? [],
|
|
115
|
+
componentRef: state.component?.component,
|
|
116
|
+
componentOptions: {
|
|
117
|
+
...getBlockComponentOptions(state.useBlock),
|
|
118
|
+
/**
|
|
119
|
+
* These attributes are passed to the wrapper element when there is one. If `noWrap` is set to true, then
|
|
120
|
+
* they are provided to the component itself directly.
|
|
121
|
+
*/
|
|
122
|
+
...(!state.component?.noWrap
|
|
123
|
+
? {}
|
|
124
|
+
: {
|
|
125
|
+
attributes: {
|
|
126
|
+
...state.attributes,
|
|
127
|
+
...state.actions,
|
|
128
|
+
},
|
|
129
|
+
}),
|
|
130
|
+
},
|
|
131
|
+
context: state.childrenContext,
|
|
132
|
+
};
|
|
133
|
+
},
|
|
154
134
|
};
|
|
155
135
|
|
|
156
136
|
const TagRef = state.tag;
|
|
@@ -5,14 +5,14 @@ function RenderInlinedStyles(props) {
|
|
|
5
5
|
const _context = { ...props["_context"] };
|
|
6
6
|
|
|
7
7
|
const state = {
|
|
8
|
-
get injectedStyleScript() {
|
|
9
|
-
return `<${state.tag}>${props.styles}</${state.tag}>`;
|
|
10
|
-
},
|
|
11
8
|
get tag() {
|
|
12
9
|
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
13
10
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
14
11
|
return "sty" + "le";
|
|
15
12
|
},
|
|
13
|
+
get injectedStyleScript() {
|
|
14
|
+
return `<${state.tag}>${props.styles}</${state.tag}>`;
|
|
15
|
+
},
|
|
16
16
|
};
|
|
17
17
|
|
|
18
18
|
const TagRef = state.tag;
|
|
@@ -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,
|