@builder.io/sdk-react-native 0.0.1-6 → 0.0.1-62
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 +42 -0
- package/README.md +19 -0
- package/package.json +6 -4
- package/src/blocks/button/button.js +31 -0
- package/src/blocks/button/component-info.js +42 -0
- package/src/blocks/columns/columns.js +59 -0
- package/src/blocks/columns/component-info.js +242 -0
- package/src/blocks/custom-code/component-info.js +32 -0
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.js} +16 -33
- package/src/blocks/embed/component-info.js +44 -0
- package/src/blocks/embed/embed.js +43 -0
- package/src/blocks/embed/helpers.js +10 -0
- package/src/blocks/form/component-info.js +263 -0
- package/src/blocks/form/form.js +221 -0
- package/src/blocks/fragment/component-info.js +12 -0
- package/src/blocks/fragment/fragment.js +8 -0
- package/src/blocks/image/component-info.js +151 -0
- package/src/blocks/image/image.helpers.js +49 -0
- package/src/blocks/image/image.js +41 -0
- package/src/blocks/img/component-info.js +21 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/input/component-info.js +75 -0
- package/src/blocks/input/input.js +36 -0
- package/src/blocks/raw-text/component-info.js +17 -0
- package/src/blocks/raw-text/raw-text.js +10 -0
- package/src/blocks/section/component-info.js +50 -0
- package/src/blocks/section/section.js +31 -0
- package/src/blocks/select/component-info.js +60 -0
- package/src/blocks/select/select.js +36 -0
- package/src/blocks/submit-button/component-info.js +29 -0
- package/src/blocks/submit-button/submit-button.js +29 -0
- package/src/blocks/symbol/component-info.js +44 -0
- package/src/blocks/symbol/symbol.js +69 -0
- package/src/blocks/{text.js → text/component-info.js} +4 -10
- package/src/blocks/text/text.js +65 -0
- package/src/blocks/textarea/component-info.js +48 -0
- package/src/blocks/textarea/textarea.js +32 -0
- package/src/blocks/video/component-info.js +107 -0
- package/src/blocks/video/video.js +33 -0
- package/src/components/render-block/block-styles.js +40 -0
- package/src/components/render-block/render-block.helpers.js +24 -0
- package/src/components/render-block/render-block.js +169 -0
- package/src/components/render-block/render-component.js +33 -0
- package/src/components/render-block/render-repeated-block.js +29 -0
- package/src/components/render-blocks.js +23 -12
- package/src/components/render-content/components/render-styles.js +58 -0
- package/src/components/render-content/index.js +5 -0
- package/src/components/render-content/render-content.js +254 -0
- package/src/components/render-inlined-styles.js +18 -0
- package/src/constants/builder-registered-components.js +43 -0
- package/src/constants/device-sizes.js +3 -21
- package/src/constants/target.js +5 -0
- package/src/context/builder.context.js +7 -1
- package/src/functions/camel-to-kebab-case.js +5 -0
- package/src/functions/convert-style-object.js +7 -0
- package/src/functions/evaluate.js +17 -8
- package/src/functions/event-handler-name.js +8 -0
- package/src/functions/get-block-actions.js +14 -13
- package/src/functions/get-block-component-options.js +22 -1
- package/src/functions/get-block-properties.js +2 -3
- package/src/functions/get-block-styles.js +9 -19
- package/src/functions/get-block-tag.js +1 -1
- package/src/functions/get-builder-search-params/fn.test.js +14 -0
- package/src/functions/get-builder-search-params/index.js +23 -0
- package/src/functions/get-content/ab-testing.js +39 -0
- package/src/functions/get-content/fn.test.js +32 -0
- package/src/functions/get-content/index.js +94 -0
- package/src/functions/get-content/types.js +1 -0
- package/src/functions/get-fetch.js +35 -0
- package/src/functions/get-global-this.js +19 -0
- package/src/functions/get-processed-block.js +18 -9
- package/src/functions/get-processed-block.test.js +14 -8
- package/src/functions/if-target.js +11 -2
- package/src/functions/is-browser.js +1 -2
- package/src/functions/is-editing.js +1 -1
- package/src/functions/is-iframe.js +1 -1
- package/src/functions/is-previewing.js +15 -0
- package/src/functions/is-react-native.js +1 -1
- package/src/functions/on-change.test.js +1 -2
- package/src/functions/previewing-model-name.js +12 -0
- package/src/functions/register-component.js +46 -26
- package/src/functions/register.js +30 -0
- package/src/functions/sanitize-styles.js +33 -0
- package/src/functions/set-editor-settings.js +16 -0
- package/src/functions/set.test.js +1 -2
- package/src/functions/track.js +7 -3
- package/src/functions/transform-block.js +38 -0
- package/src/helpers/css.js +13 -0
- package/src/helpers/flatten.js +35 -0
- package/src/index-helpers/blocks-exports.js +19 -0
- package/src/index-helpers/top-of-file.js +2 -0
- package/src/index.js +10 -23
- package/src/scripts/init-editing.js +73 -49
- package/src/types/components.js +1 -0
- package/src/types/deep-partial.js +1 -0
- package/src/types/element.js +1 -0
- package/src/types/targets.js +1 -0
- package/src/types/typescript.js +1 -0
- package/index.js +0 -11
- package/src/blocks/button.js +0 -37
- package/src/blocks/button.lite.tsx +0 -29
- package/src/blocks/columns.js +0 -42
- package/src/blocks/columns.lite.tsx +0 -41
- package/src/blocks/custom-code.js +0 -56
- package/src/blocks/embed.js +0 -56
- package/src/blocks/embed.lite.tsx +0 -65
- package/src/blocks/form.js +0 -229
- package/src/blocks/form.lite.tsx +0 -257
- package/src/blocks/image.js +0 -123
- package/src/blocks/image.lite.tsx +0 -35
- package/src/blocks/img.js +0 -41
- package/src/blocks/img.lite.tsx +0 -19
- package/src/blocks/input.js +0 -41
- package/src/blocks/input.lite.tsx +0 -23
- package/src/blocks/raw-text.js +0 -17
- package/src/blocks/raw-text.lite.tsx +0 -12
- package/src/blocks/section.js +0 -36
- package/src/blocks/section.lite.tsx +0 -20
- package/src/blocks/select.js +0 -40
- package/src/blocks/select.lite.tsx +0 -24
- package/src/blocks/submit-button.js +0 -34
- package/src/blocks/submit-button.lite.tsx +0 -11
- package/src/blocks/symbol.js +0 -20
- package/src/blocks/symbol.lite.tsx +0 -20
- package/src/blocks/text.lite.tsx +0 -12
- package/src/blocks/textarea.js +0 -37
- package/src/blocks/textarea.lite.tsx +0 -15
- package/src/blocks/video.js +0 -49
- package/src/blocks/video.lite.tsx +0 -28
- package/src/components/render-block.js +0 -84
- package/src/components/render-block.lite.tsx +0 -92
- package/src/components/render-blocks.lite.tsx +0 -56
- package/src/components/render-content.js +0 -66
- package/src/components/render-content.lite.tsx +0 -95
- package/src/functions/get-content.js +0 -103
- package/src/functions/get-target.js +0 -7
- package/src/functions/macro-eval.js +0 -6
- package/src/package.json +0 -18
|
@@ -1,92 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
-
import { useState, useContext } from "react";
|
|
4
|
-
import { getBlockComponentOptions } from "../functions/get-block-component-options";
|
|
5
|
-
import { getBlockProperties } from "../functions/get-block-properties";
|
|
6
|
-
import { getBlockStyles } from "../functions/get-block-styles";
|
|
7
|
-
import { getBlockTag } from "../functions/get-block-tag";
|
|
8
|
-
import { components } from "../functions/register-component";
|
|
9
|
-
import BuilderContext from "../context/builder.context.lite";
|
|
10
|
-
import { getBlockActions } from "../functions/get-block-actions";
|
|
11
|
-
import { getProcessedBlock } from "../functions/get-processed-block";
|
|
12
|
-
|
|
13
|
-
export default function RenderBlock(props) {
|
|
14
|
-
function component() {
|
|
15
|
-
return components[block().component?.name];
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
function componentInfo() {
|
|
19
|
-
return component?.()?.info;
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
function componentRef() {
|
|
23
|
-
return component?.()?.component;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
function tagName() {
|
|
27
|
-
return getBlockTag(block());
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
function properties() {
|
|
31
|
-
return getBlockProperties(block());
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
function block() {
|
|
35
|
-
return getProcessedBlock({
|
|
36
|
-
block: props.block,
|
|
37
|
-
state: builderContext.state,
|
|
38
|
-
context: builderContext.context,
|
|
39
|
-
});
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
function actions() {
|
|
43
|
-
return getBlockActions({
|
|
44
|
-
block: block(),
|
|
45
|
-
state: builderContext.state,
|
|
46
|
-
context: builderContext.context,
|
|
47
|
-
});
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
function css() {
|
|
51
|
-
return getBlockStyles(block());
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
function componentOptions() {
|
|
55
|
-
return getBlockComponentOptions(block());
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const builderContext = useContext(BuilderContext);
|
|
59
|
-
|
|
60
|
-
const ComponentRefRef = componentRef();
|
|
61
|
-
const TagNameRef = tagName();
|
|
62
|
-
|
|
63
|
-
return (
|
|
64
|
-
<>
|
|
65
|
-
{componentInfo?.()?.noWrap && (
|
|
66
|
-
<>
|
|
67
|
-
<ComponentRefRef
|
|
68
|
-
{...componentInfo?.()?.options}
|
|
69
|
-
attributes={properties()}
|
|
70
|
-
style={css()}
|
|
71
|
-
/>
|
|
72
|
-
</>
|
|
73
|
-
)}
|
|
74
|
-
|
|
75
|
-
{!componentInfo?.()?.noWrap && (
|
|
76
|
-
<>
|
|
77
|
-
<TagNameRef {...properties()} style={css()}>
|
|
78
|
-
{componentRef() && <ComponentRefRef {...componentOptions()} />}
|
|
79
|
-
|
|
80
|
-
{!componentRef() && block().children && block().children.length && (
|
|
81
|
-
<>
|
|
82
|
-
{block().children.map((child) => (
|
|
83
|
-
<RenderBlock block={child} />
|
|
84
|
-
))}
|
|
85
|
-
</>
|
|
86
|
-
)}
|
|
87
|
-
</TagNameRef>
|
|
88
|
-
</>
|
|
89
|
-
)}
|
|
90
|
-
</>
|
|
91
|
-
);
|
|
92
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
-
import { useState, useContext } from "react";
|
|
4
|
-
import { isEditing } from "../functions/is-editing";
|
|
5
|
-
import RenderBlock from "./render-block.lite";
|
|
6
|
-
|
|
7
|
-
export default function RenderBlocks(props) {
|
|
8
|
-
function onClick() {
|
|
9
|
-
if (isEditing() && !props.blocks?.length) {
|
|
10
|
-
window.parent?.postMessage(
|
|
11
|
-
{
|
|
12
|
-
type: "builder.clickEmptyBlocks",
|
|
13
|
-
data: {
|
|
14
|
-
parentElementId: props.parent,
|
|
15
|
-
dataPath: props.path,
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
"*"
|
|
19
|
-
);
|
|
20
|
-
}
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
function onMouseEnter() {
|
|
24
|
-
if (isEditing() && !props.blocks?.length) {
|
|
25
|
-
window.parent?.postMessage(
|
|
26
|
-
{
|
|
27
|
-
type: "builder.hoverEmptyBlocks",
|
|
28
|
-
data: {
|
|
29
|
-
parentElementId: props.parent,
|
|
30
|
-
dataPath: props.path,
|
|
31
|
-
},
|
|
32
|
-
},
|
|
33
|
-
"*"
|
|
34
|
-
);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
return (
|
|
39
|
-
<View
|
|
40
|
-
className={"builder-blocks" + (!props.blocks?.length ? " no-blocks" : "")}
|
|
41
|
-
builder-path={props.path}
|
|
42
|
-
builder-parent-id={props.parent}
|
|
43
|
-
onClick={(event) => onClick}
|
|
44
|
-
onMouseEnter={(event) => onMouseEnter}
|
|
45
|
-
style={styles.view1}
|
|
46
|
-
>
|
|
47
|
-
{props.blocks.map((block) => (
|
|
48
|
-
<RenderBlock block={block} />
|
|
49
|
-
))}
|
|
50
|
-
</View>
|
|
51
|
-
);
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
const styles = StyleSheet.create({
|
|
55
|
-
view1: { display: "flex", flexDirection: "column", alignItems: "stretch" },
|
|
56
|
-
});
|
|
@@ -1,66 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View } from "react-native";
|
|
3
|
-
import { useState, useEffect } from "react";
|
|
4
|
-
import { isBrowser } from "../functions/is-browser";
|
|
5
|
-
import RenderBlock from "./render-block";
|
|
6
|
-
import BuilderContext from "../context/builder.context";
|
|
7
|
-
import { track } from "../functions/track";
|
|
8
|
-
function RenderContent(props) {
|
|
9
|
-
var _a, _b, _c, _d, _e;
|
|
10
|
-
function useContent() {
|
|
11
|
-
return overrideContent || props.content;
|
|
12
|
-
}
|
|
13
|
-
const [update, setUpdate] = useState(() => 0);
|
|
14
|
-
const [state, setState] = useState(() => ({}));
|
|
15
|
-
const [context, setContext] = useState(() => ({}));
|
|
16
|
-
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
17
|
-
function processMessage(event) {
|
|
18
|
-
const { data } = event;
|
|
19
|
-
if (data) {
|
|
20
|
-
switch (data.type) {
|
|
21
|
-
case "builder.contentUpdate": {
|
|
22
|
-
const key = data.data.key || data.data.alias || data.data.entry || data.data.modelName;
|
|
23
|
-
const contentData = data.data.data;
|
|
24
|
-
if (key === props.model) {
|
|
25
|
-
setOverrideContent(contentData);
|
|
26
|
-
}
|
|
27
|
-
break;
|
|
28
|
-
}
|
|
29
|
-
case "builder.patchUpdates": {
|
|
30
|
-
break;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
useEffect(() => {
|
|
36
|
-
if (isBrowser()) {
|
|
37
|
-
window.addEventListener("message", processMessage);
|
|
38
|
-
}
|
|
39
|
-
}, []);
|
|
40
|
-
return /* @__PURE__ */ React.createElement(BuilderContext.Provider, {
|
|
41
|
-
value: {
|
|
42
|
-
get content() {
|
|
43
|
-
return props.content;
|
|
44
|
-
},
|
|
45
|
-
get state() {
|
|
46
|
-
return state;
|
|
47
|
-
},
|
|
48
|
-
get context() {
|
|
49
|
-
return context;
|
|
50
|
-
}
|
|
51
|
-
}
|
|
52
|
-
}, /* @__PURE__ */ React.createElement(View, {
|
|
53
|
-
onClick: (event) => {
|
|
54
|
-
track("click", {
|
|
55
|
-
contentId: props.content.id
|
|
56
|
-
});
|
|
57
|
-
},
|
|
58
|
-
"data-builder-content-id": (_a = props.content) == null ? void 0 : _a.id
|
|
59
|
-
}, ((_c = (_b = useContent == null ? void 0 : useContent()) == null ? void 0 : _b.data) == null ? void 0 : _c.cssCode) && /* @__PURE__ */ React.createElement(View, null, useContent().data.cssCode), (_e = (_d = useContent == null ? void 0 : useContent()) == null ? void 0 : _d.data) == null ? void 0 : _e.blocks.map((block) => /* @__PURE__ */ React.createElement(RenderBlock, {
|
|
60
|
-
key: block.id,
|
|
61
|
-
block
|
|
62
|
-
}))));
|
|
63
|
-
}
|
|
64
|
-
export {
|
|
65
|
-
RenderContent as default
|
|
66
|
-
};
|
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
-
import { useState, useContext, useEffect } from "react";
|
|
4
|
-
import { isBrowser } from "../functions/is-browser";
|
|
5
|
-
import RenderBlock from "./render-block.lite";
|
|
6
|
-
import BuilderContext from "../context/builder.context.lite";
|
|
7
|
-
import { track } from "../functions/track";
|
|
8
|
-
import { ifTarget } from "../functions/if-target";
|
|
9
|
-
import { onChange } from "../functions/on-change";
|
|
10
|
-
|
|
11
|
-
export default function RenderContent(props) {
|
|
12
|
-
function useContent() {
|
|
13
|
-
return overrideContent || props.content;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const [update, setUpdate] = useState(() => 0);
|
|
17
|
-
|
|
18
|
-
const [state, setState] = useState(() => ({}));
|
|
19
|
-
|
|
20
|
-
const [context, setContext] = useState(() => ({}));
|
|
21
|
-
|
|
22
|
-
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
23
|
-
|
|
24
|
-
function processMessage(event) {
|
|
25
|
-
const { data } = event;
|
|
26
|
-
|
|
27
|
-
if (data) {
|
|
28
|
-
switch (data.type) {
|
|
29
|
-
case "builder.contentUpdate": {
|
|
30
|
-
const key =
|
|
31
|
-
data.data.key ||
|
|
32
|
-
data.data.alias ||
|
|
33
|
-
data.data.entry ||
|
|
34
|
-
data.data.modelName;
|
|
35
|
-
const contentData = data.data.data; // oof
|
|
36
|
-
|
|
37
|
-
if (key === props.model) {
|
|
38
|
-
setOverrideContent(contentData);
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
break;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
case "builder.patchUpdates": {
|
|
45
|
-
// TODO
|
|
46
|
-
break;
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
useEffect(() => {
|
|
53
|
-
if (isBrowser()) {
|
|
54
|
-
window.addEventListener("message", processMessage); // TODO: run this when content is defined
|
|
55
|
-
// track('impression', {
|
|
56
|
-
// contentId: props.content!.id,
|
|
57
|
-
// });
|
|
58
|
-
}
|
|
59
|
-
}, []);
|
|
60
|
-
|
|
61
|
-
return (
|
|
62
|
-
<BuilderContext.Provider
|
|
63
|
-
value={{
|
|
64
|
-
get content() {
|
|
65
|
-
return props.content;
|
|
66
|
-
},
|
|
67
|
-
|
|
68
|
-
get state() {
|
|
69
|
-
return state;
|
|
70
|
-
},
|
|
71
|
-
|
|
72
|
-
get context() {
|
|
73
|
-
return context;
|
|
74
|
-
},
|
|
75
|
-
}}
|
|
76
|
-
>
|
|
77
|
-
<View
|
|
78
|
-
onClick={(event) => {
|
|
79
|
-
track("click", {
|
|
80
|
-
contentId: props.content.id,
|
|
81
|
-
});
|
|
82
|
-
}}
|
|
83
|
-
data-builder-content-id={props.content?.id}
|
|
84
|
-
>
|
|
85
|
-
{useContent?.()?.data?.cssCode && (
|
|
86
|
-
<View>{useContent().data.cssCode}</View>
|
|
87
|
-
)}
|
|
88
|
-
|
|
89
|
-
{useContent?.()?.data?.blocks.map((block) => (
|
|
90
|
-
<RenderBlock key={block.id} block={block} />
|
|
91
|
-
))}
|
|
92
|
-
</View>
|
|
93
|
-
</BuilderContext.Provider>
|
|
94
|
-
);
|
|
95
|
-
}
|
|
@@ -1,103 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
var __defProp = Object.defineProperty;
|
|
3
|
-
var __defProps = Object.defineProperties;
|
|
4
|
-
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
5
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
-
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
9
|
-
var __spreadValues = (a, b) => {
|
|
10
|
-
for (var prop in b || (b = {}))
|
|
11
|
-
if (__hasOwnProp.call(b, prop))
|
|
12
|
-
__defNormalProp(a, prop, b[prop]);
|
|
13
|
-
if (__getOwnPropSymbols)
|
|
14
|
-
for (var prop of __getOwnPropSymbols(b)) {
|
|
15
|
-
if (__propIsEnum.call(b, prop))
|
|
16
|
-
__defNormalProp(a, prop, b[prop]);
|
|
17
|
-
}
|
|
18
|
-
return a;
|
|
19
|
-
};
|
|
20
|
-
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
var __async = (__this, __arguments, generator) => {
|
|
22
|
-
return new Promise((resolve, reject) => {
|
|
23
|
-
var fulfilled = (value) => {
|
|
24
|
-
try {
|
|
25
|
-
step(generator.next(value));
|
|
26
|
-
} catch (e) {
|
|
27
|
-
reject(e);
|
|
28
|
-
}
|
|
29
|
-
};
|
|
30
|
-
var rejected = (value) => {
|
|
31
|
-
try {
|
|
32
|
-
step(generator.throw(value));
|
|
33
|
-
} catch (e) {
|
|
34
|
-
reject(e);
|
|
35
|
-
}
|
|
36
|
-
};
|
|
37
|
-
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
38
|
-
step((generator = generator.apply(__this, __arguments)).next());
|
|
39
|
-
});
|
|
40
|
-
};
|
|
41
|
-
import { isBrowser } from "./is-browser";
|
|
42
|
-
import { isReactNative } from "./is-react-native";
|
|
43
|
-
if (!(isBrowser() || isReactNative())) {
|
|
44
|
-
import("node-fetch");
|
|
45
|
-
}
|
|
46
|
-
function getContent(options) {
|
|
47
|
-
return __async(this, null, function* () {
|
|
48
|
-
return (yield getAllContent(__spreadProps(__spreadValues({}, options), { limit: 1 }))).results[0] || null;
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
function getAllContent(options) {
|
|
52
|
-
return __async(this, null, function* () {
|
|
53
|
-
const { model, apiKey } = options;
|
|
54
|
-
const { limit, testGroups, userAttributes } = __spreadValues({
|
|
55
|
-
limit: 1,
|
|
56
|
-
userAttributes: null,
|
|
57
|
-
testGroups: null
|
|
58
|
-
}, options);
|
|
59
|
-
const content = yield fetch(`https://cdn.builder.io/api/v2/content/${model}?apiKey=${apiKey}&limit=${limit}&userAttributes=${JSON.stringify(userAttributes)}`).then((res) => res.json());
|
|
60
|
-
if (testGroups) {
|
|
61
|
-
for (const item of content) {
|
|
62
|
-
if (item.variations && Object.keys(item.variations).length) {
|
|
63
|
-
const testGroup = testGroups[item.id];
|
|
64
|
-
const variationValue = item.variations[testGroup];
|
|
65
|
-
if (testGroup && variationValue) {
|
|
66
|
-
item.data = variationValue.data;
|
|
67
|
-
item.testVariationId = variationValue.id;
|
|
68
|
-
item.testVariationName = variationValue.name;
|
|
69
|
-
} else {
|
|
70
|
-
let n = 0;
|
|
71
|
-
const random = Math.random();
|
|
72
|
-
let set = false;
|
|
73
|
-
for (const id in item.variations) {
|
|
74
|
-
const variation = item.variations[id];
|
|
75
|
-
const testRatio = variation.testRatio;
|
|
76
|
-
n += testRatio;
|
|
77
|
-
if (random < n) {
|
|
78
|
-
const variationName = variation.name || (variation.id === item.id ? "Default variation" : "");
|
|
79
|
-
set = true;
|
|
80
|
-
Object.assign(item, {
|
|
81
|
-
data: variation.data,
|
|
82
|
-
testVariationId: variation.id,
|
|
83
|
-
testVariationName: variationName
|
|
84
|
-
});
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
if (!set) {
|
|
88
|
-
Object.assign(item, {
|
|
89
|
-
testVariationId: item.id,
|
|
90
|
-
testVariationName: "Default"
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return content;
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
export {
|
|
101
|
-
getAllContent,
|
|
102
|
-
getContent
|
|
103
|
-
};
|
package/src/package.json
DELETED
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@builder.io/sdk-react-native",
|
|
3
|
-
"description": "Builder.io SDK for React Native",
|
|
4
|
-
"version": "0.0.1-1",
|
|
5
|
-
"main": "src/index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"release:dev": "npm version prerelease --no-git-tag-version && npm publish --tag dev --access public"
|
|
8
|
-
},
|
|
9
|
-
"dependencies": {
|
|
10
|
-
"react-native-render-html": "^5.1.1"
|
|
11
|
-
},
|
|
12
|
-
"peerDependencies": {
|
|
13
|
-
"react-native": "^0.64.2"
|
|
14
|
-
},
|
|
15
|
-
"devDependencies": {
|
|
16
|
-
"react-native": "^0.64.2"
|
|
17
|
-
}
|
|
18
|
-
}
|