@builder.io/sdk-react-native 0.0.1-62 → 0.0.1-65
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/components/render-block/render-block.js +1 -1
- package/src/components/render-block/types.js +1 -0
- package/src/components/render-content/render-content.js +13 -15
- package/src/functions/get-builder-search-params/index.js +12 -1
- package/src/functions/get-content/index.js +11 -8
- package/src/functions/previewing-model-name.js +0 -12
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@builder.io/sdk-react-native",
|
|
3
3
|
"description": "Builder.io SDK for React Native",
|
|
4
|
-
"version": "0.0.1-
|
|
4
|
+
"version": "0.0.1-65",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
@@ -156,7 +156,7 @@ function RenderBlock(props) {
|
|
|
156
156
|
key: index,
|
|
157
157
|
repeatContext: data.context,
|
|
158
158
|
block: data.block
|
|
159
|
-
}))) : /* @__PURE__ */ React.createElement(RenderComponent, __spreadValues({}, renderComponentProps())), (_b = childrenWithoutParentComponent()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
|
|
159
|
+
}))) : null, !repeatItemData() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(RenderComponent, __spreadValues({}, renderComponentProps()))) : null, (_b = childrenWithoutParentComponent()) == null ? void 0 : _b.map((child) => /* @__PURE__ */ React.createElement(RenderBlock, {
|
|
160
160
|
key: "render-block-" + child.id,
|
|
161
161
|
block: child
|
|
162
162
|
})), (_c = childrenWithoutParentComponent()) == null ? void 0 : _c.map((child) => /* @__PURE__ */ React.createElement(BlockStyles, {
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
@@ -44,16 +44,11 @@ import { getDefaultRegisteredComponents } from "../../constants/builder-register
|
|
|
44
44
|
import { TARGET } from "../../constants/target.js";
|
|
45
45
|
import BuilderContext from "../../context/builder.context";
|
|
46
46
|
import { evaluate } from "../../functions/evaluate.js";
|
|
47
|
-
import {
|
|
48
|
-
convertSearchParamsToQueryObject,
|
|
49
|
-
getBuilderSearchParams
|
|
50
|
-
} from "../../functions/get-builder-search-params/index.js";
|
|
51
47
|
import { getContent } from "../../functions/get-content/index.js";
|
|
52
48
|
import { getFetch } from "../../functions/get-fetch.js";
|
|
53
49
|
import { isBrowser } from "../../functions/is-browser.js";
|
|
54
50
|
import { isEditing } from "../../functions/is-editing.js";
|
|
55
51
|
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
56
|
-
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
57
52
|
import {
|
|
58
53
|
components,
|
|
59
54
|
createRegisterComponentMessage
|
|
@@ -62,7 +57,7 @@ import { track } from "../../functions/track.js";
|
|
|
62
57
|
import RenderBlocks from "../render-blocks.js";
|
|
63
58
|
import RenderContentStyles from "./components/render-styles.js";
|
|
64
59
|
function RenderContent(props) {
|
|
65
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k
|
|
60
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
|
|
66
61
|
function useContent() {
|
|
67
62
|
var _a2;
|
|
68
63
|
const mergedContent = __spreadProps(__spreadValues(__spreadValues({}, props.content), overrideContent), {
|
|
@@ -164,6 +159,10 @@ function RenderContent(props) {
|
|
|
164
159
|
}));
|
|
165
160
|
}
|
|
166
161
|
}
|
|
162
|
+
function shouldRenderContentStyles() {
|
|
163
|
+
var _a2, _b2, _c2, _d2, _e2;
|
|
164
|
+
return Boolean((((_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.cssCode) || ((_e2 = (_d2 = (_c2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _c2.data) == null ? void 0 : _d2.customFonts) == null ? void 0 : _e2.length)) && TARGET !== "reactNative");
|
|
165
|
+
}
|
|
167
166
|
useEffect(() => {
|
|
168
167
|
if (isBrowser()) {
|
|
169
168
|
if (isEditing()) {
|
|
@@ -181,14 +180,13 @@ function RenderContent(props) {
|
|
|
181
180
|
});
|
|
182
181
|
}
|
|
183
182
|
if (isPreviewing()) {
|
|
184
|
-
|
|
185
|
-
|
|
183
|
+
const searchParams = new URL(location.href).searchParams;
|
|
184
|
+
if (props.model && searchParams.get("builder.preview") === props.model) {
|
|
186
185
|
const previewApiKey = searchParams.get("apiKey") || searchParams.get("builder.space");
|
|
187
186
|
if (previewApiKey) {
|
|
188
187
|
getContent({
|
|
189
188
|
model: props.model,
|
|
190
|
-
apiKey: previewApiKey
|
|
191
|
-
options: getBuilderSearchParams(convertSearchParamsToQueryObject(searchParams))
|
|
189
|
+
apiKey: previewApiKey
|
|
192
190
|
}).then((content) => {
|
|
193
191
|
if (content) {
|
|
194
192
|
setOverrideContent(content);
|
|
@@ -241,12 +239,12 @@ function RenderContent(props) {
|
|
|
241
239
|
onClick: (event) => track("click", {
|
|
242
240
|
contentId: useContent().id
|
|
243
241
|
}),
|
|
244
|
-
"
|
|
245
|
-
}, (
|
|
246
|
-
cssCode: useContent().data.cssCode,
|
|
247
|
-
customFonts: useContent().data.customFonts
|
|
242
|
+
"builder-content-id": (_e = useContent == null ? void 0 : useContent()) == null ? void 0 : _e.id
|
|
243
|
+
}, shouldRenderContentStyles() ? /* @__PURE__ */ React.createElement(RenderContentStyles, {
|
|
244
|
+
cssCode: (_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode,
|
|
245
|
+
customFonts: (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts
|
|
248
246
|
}) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
|
|
249
|
-
blocks: (
|
|
247
|
+
blocks: (_k = (_j = useContent == null ? void 0 : useContent()) == null ? void 0 : _j.data) == null ? void 0 : _k.blocks
|
|
250
248
|
}))) : null);
|
|
251
249
|
}
|
|
252
250
|
export {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
+
import { isBrowser } from "../is-browser";
|
|
2
3
|
const BUILDER_SEARCHPARAMS_PREFIX = "builder.";
|
|
3
4
|
const convertSearchParamsToQueryObject = (searchParams) => {
|
|
4
5
|
const options = {};
|
|
@@ -17,7 +18,17 @@ const getBuilderSearchParams = (options) => {
|
|
|
17
18
|
});
|
|
18
19
|
return newOptions;
|
|
19
20
|
};
|
|
21
|
+
const getBuilderSearchParamsFromWindow = () => {
|
|
22
|
+
if (!isBrowser()) {
|
|
23
|
+
return {};
|
|
24
|
+
}
|
|
25
|
+
const searchParams = new URLSearchParams(window.location.search);
|
|
26
|
+
return getBuilderSearchParams(convertSearchParamsToQueryObject(searchParams));
|
|
27
|
+
};
|
|
28
|
+
const normalizeSearchParams = (searchParams) => searchParams instanceof URLSearchParams ? convertSearchParamsToQueryObject(searchParams) : searchParams;
|
|
20
29
|
export {
|
|
21
30
|
convertSearchParamsToQueryObject,
|
|
22
|
-
getBuilderSearchParams
|
|
31
|
+
getBuilderSearchParams,
|
|
32
|
+
getBuilderSearchParamsFromWindow,
|
|
33
|
+
normalizeSearchParams
|
|
23
34
|
};
|
|
@@ -39,6 +39,10 @@ var __async = (__this, __arguments, generator) => {
|
|
|
39
39
|
});
|
|
40
40
|
};
|
|
41
41
|
import { flatten } from "../../helpers/flatten.js";
|
|
42
|
+
import {
|
|
43
|
+
getBuilderSearchParamsFromWindow,
|
|
44
|
+
normalizeSearchParams
|
|
45
|
+
} from "../get-builder-search-params/index.js";
|
|
42
46
|
import { getFetch } from "../get-fetch.js";
|
|
43
47
|
import { handleABTesting } from "./ab-testing.js";
|
|
44
48
|
const fetch$ = getFetch();
|
|
@@ -57,19 +61,18 @@ const generateContentUrl = (options) => {
|
|
|
57
61
|
apiKey
|
|
58
62
|
} = options;
|
|
59
63
|
const url = new URL(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&noTraverse=${noTraverse}`);
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
}
|
|
64
|
+
const queryOptions = __spreadValues(__spreadValues({}, getBuilderSearchParamsFromWindow()), normalizeSearchParams(options.options || {}));
|
|
65
|
+
const flattened = flatten(queryOptions);
|
|
66
|
+
for (const key in flattened) {
|
|
67
|
+
url.searchParams.set(key, String(flattened[key]));
|
|
65
68
|
}
|
|
66
69
|
if (userAttributes) {
|
|
67
70
|
url.searchParams.set("userAttributes", JSON.stringify(userAttributes));
|
|
68
71
|
}
|
|
69
72
|
if (query) {
|
|
70
|
-
const
|
|
71
|
-
for (const key in
|
|
72
|
-
url.searchParams.set(key, JSON.stringify(
|
|
73
|
+
const flattened2 = flatten({ query });
|
|
74
|
+
for (const key in flattened2) {
|
|
75
|
+
url.searchParams.set(key, JSON.stringify(flattened2[key]));
|
|
73
76
|
}
|
|
74
77
|
}
|
|
75
78
|
return url;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { isPreviewing } from "./is-previewing.js";
|
|
3
|
-
function previewingModelName() {
|
|
4
|
-
if (!isPreviewing()) {
|
|
5
|
-
return null;
|
|
6
|
-
}
|
|
7
|
-
const url = new URL(location.href);
|
|
8
|
-
return url.searchParams.get("builder.preview");
|
|
9
|
-
}
|
|
10
|
-
export {
|
|
11
|
-
previewingModelName
|
|
12
|
-
};
|