@builder.io/sdk-react-native 0.1.6 → 0.1.8
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/dist/blocks/columns/columns.js +5 -1
- package/dist/components/render-block/block-styles.js +12 -1
- package/dist/components/render-block/render-block.js +13 -4
- package/package.json +1 -2
- package/src/blocks/columns/columns.jsx +5 -1
- package/src/components/render-block/block-styles.jsx +13 -1
- package/src/components/render-block/render-block.jsx +54 -40
|
@@ -28,11 +28,13 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
28
28
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
29
29
|
const React = __importStar(require("react"));
|
|
30
30
|
const react_native_1 = require("react-native");
|
|
31
|
+
const react_1 = require("react");
|
|
31
32
|
const render_blocks_1 = __importDefault(require("../../components/render-blocks"));
|
|
32
33
|
const device_sizes_1 = require("../../constants/device-sizes");
|
|
33
34
|
const render_inlined_styles_1 = __importDefault(require("../../components/render-inlined-styles"));
|
|
34
35
|
const target_js_1 = require("../../constants/target.js");
|
|
35
36
|
const css_1 = require("../../helpers/css");
|
|
37
|
+
const builder_context_js_1 = __importDefault(require("../../context/builder.context.js"));
|
|
36
38
|
function Columns(props) {
|
|
37
39
|
var _a;
|
|
38
40
|
function getGutterSize() {
|
|
@@ -78,7 +80,8 @@ function Columns(props) {
|
|
|
78
80
|
};
|
|
79
81
|
}
|
|
80
82
|
function getWidthForBreakpointSize(size) {
|
|
81
|
-
|
|
83
|
+
var _a, _b;
|
|
84
|
+
const breakpointSizes = (0, device_sizes_1.getSizesForBreakpoints)(((_b = (_a = builderContext.content) === null || _a === void 0 ? void 0 : _a.meta) === null || _b === void 0 ? void 0 : _b.breakpoints) || {});
|
|
82
85
|
return breakpointSizes[size].max;
|
|
83
86
|
}
|
|
84
87
|
function columnStyleObjects() {
|
|
@@ -134,6 +137,7 @@ function Columns(props) {
|
|
|
134
137
|
function reactNativeColumnStyles() {
|
|
135
138
|
return columnStyleObjects.column.small;
|
|
136
139
|
}
|
|
140
|
+
const builderContext = (0, react_1.useContext)(builder_context_js_1.default);
|
|
137
141
|
return (React.createElement(react_native_1.View, { style: styles.view1 },
|
|
138
142
|
target_js_1.TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
139
143
|
React.createElement(render_inlined_styles_1.default, { styles: columnsStyles() }))) : null, (_a = props.columns) === null || _a === void 0 ? void 0 :
|
|
@@ -32,6 +32,7 @@ const device_sizes_js_1 = require("../../constants/device-sizes.js");
|
|
|
32
32
|
const target_js_1 = require("../../constants/target.js");
|
|
33
33
|
const get_processed_block_js_1 = require("../../functions/get-processed-block.js");
|
|
34
34
|
const css_js_1 = require("../../helpers/css.js");
|
|
35
|
+
const nullable_js_1 = require("../../helpers/nullable.js");
|
|
35
36
|
const render_inlined_styles_1 = __importDefault(require("../render-inlined-styles"));
|
|
36
37
|
function BlockStyles(props) {
|
|
37
38
|
function useBlock() {
|
|
@@ -42,6 +43,16 @@ function BlockStyles(props) {
|
|
|
42
43
|
shouldEvaluateBindings: true,
|
|
43
44
|
});
|
|
44
45
|
}
|
|
46
|
+
function canShowBlock() {
|
|
47
|
+
// only render styles for blocks that are visible
|
|
48
|
+
if ((0, nullable_js_1.checkIsDefined)(useBlock().hide)) {
|
|
49
|
+
return !useBlock().hide;
|
|
50
|
+
}
|
|
51
|
+
if ((0, nullable_js_1.checkIsDefined)(useBlock().show)) {
|
|
52
|
+
return useBlock().show;
|
|
53
|
+
}
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
45
56
|
function css() {
|
|
46
57
|
var _a;
|
|
47
58
|
const styles = useBlock().responsiveStyles;
|
|
@@ -73,7 +84,7 @@ function BlockStyles(props) {
|
|
|
73
84
|
: "";
|
|
74
85
|
return [largeStylesClass, mediumStylesClass, smallStylesClass].join(" ");
|
|
75
86
|
}
|
|
76
|
-
return (React.createElement(React.Fragment, null, target_js_1.TARGET !== "reactNative" && css() ? (React.createElement(React.Fragment, null,
|
|
87
|
+
return (React.createElement(React.Fragment, null, target_js_1.TARGET !== "reactNative" && css() && canShowBlock() ? (React.createElement(React.Fragment, null,
|
|
77
88
|
React.createElement(render_inlined_styles_1.default, { styles: css() }))) : null));
|
|
78
89
|
}
|
|
79
90
|
exports.default = BlockStyles;
|
|
@@ -41,6 +41,7 @@ const target_js_1 = require("../../constants/target.js");
|
|
|
41
41
|
const extract_text_styles_js_1 = require("../../functions/extract-text-styles.js");
|
|
42
42
|
const render_component_1 = __importDefault(require("./render-component"));
|
|
43
43
|
const get_react_native_block_styles_js_1 = require("../../functions/get-react-native-block-styles.js");
|
|
44
|
+
const nullable_js_1 = require("../../helpers/nullable.js");
|
|
44
45
|
function RenderBlock(props) {
|
|
45
46
|
var _a, _b;
|
|
46
47
|
const [component, setComponent] = (0, react_1.useState)(() => (0, render_block_helpers_js_1.getComponent)({
|
|
@@ -60,6 +61,15 @@ function RenderBlock(props) {
|
|
|
60
61
|
shouldEvaluateBindings: true,
|
|
61
62
|
});
|
|
62
63
|
}
|
|
64
|
+
function canShowBlock() {
|
|
65
|
+
if ((0, nullable_js_1.checkIsDefined)(useBlock().hide)) {
|
|
66
|
+
return !useBlock().hide;
|
|
67
|
+
}
|
|
68
|
+
if ((0, nullable_js_1.checkIsDefined)(useBlock().show)) {
|
|
69
|
+
return useBlock().show;
|
|
70
|
+
}
|
|
71
|
+
return true;
|
|
72
|
+
}
|
|
63
73
|
function proxyState() {
|
|
64
74
|
if (typeof Proxy === "undefined") {
|
|
65
75
|
console.error("no Proxy available in this environment, cannot proxy state.");
|
|
@@ -100,7 +110,7 @@ function RenderBlock(props) {
|
|
|
100
110
|
};
|
|
101
111
|
}
|
|
102
112
|
function renderComponentProps() {
|
|
103
|
-
var _a
|
|
113
|
+
var _a;
|
|
104
114
|
return {
|
|
105
115
|
blockChildren: (_a = useBlock().children) !== null && _a !== void 0 ? _a : [],
|
|
106
116
|
componentRef: component === null || component === void 0 ? void 0 : component.component,
|
|
@@ -118,7 +128,6 @@ function RenderBlock(props) {
|
|
|
118
128
|
...actions(),
|
|
119
129
|
},
|
|
120
130
|
}),
|
|
121
|
-
customBreakpoints: (_d = (_c = (_b = childrenContext === null || childrenContext === void 0 ? void 0 : childrenContext()) === null || _b === void 0 ? void 0 : _b.content) === null || _c === void 0 ? void 0 : _c.meta) === null || _d === void 0 ? void 0 : _d.breakpoints,
|
|
122
131
|
},
|
|
123
132
|
context: childrenContext(),
|
|
124
133
|
};
|
|
@@ -159,7 +168,7 @@ function RenderBlock(props) {
|
|
|
159
168
|
inheritedStyles: getInheritedTextStyles(),
|
|
160
169
|
};
|
|
161
170
|
}
|
|
162
|
-
return (React.createElement(React.Fragment, null, !(component === null || component === void 0 ? void 0 : component.noWrap) ? (React.createElement(React.Fragment, null,
|
|
171
|
+
return (React.createElement(React.Fragment, null, canShowBlock() ? (React.createElement(React.Fragment, null, !(component === null || component === void 0 ? void 0 : component.noWrap) ? (React.createElement(React.Fragment, null,
|
|
163
172
|
(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag()) ? (React.createElement(React.Fragment, null,
|
|
164
173
|
React.createElement(react_native_1.View, { ...attributes(), ...actions() }))) : null,
|
|
165
174
|
!(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag()) && repeatItemData ? (React.createElement(React.Fragment, null, repeatItemData === null || repeatItemData === void 0 ? void 0 : repeatItemData.map((data, index) => (React.createElement(render_repeated_block_1.default, { key: index, repeatContext: data.context, block: data.block }))))) : null,
|
|
@@ -167,6 +176,6 @@ function RenderBlock(props) {
|
|
|
167
176
|
React.createElement(react_native_1.View, { ...attributes(), ...actions() },
|
|
168
177
|
React.createElement(render_component_1.default, { ...renderComponentProps() }), (_a = childrenWithoutParentComponent()) === null || _a === void 0 ? void 0 :
|
|
169
178
|
_a.map((child) => (React.createElement(RenderBlock, { key: "render-block-" + child.id, block: child, context: childrenContext() }))), (_b = childrenWithoutParentComponent()) === null || _b === void 0 ? void 0 :
|
|
170
|
-
_b.map((child) => (React.createElement(block_styles_1.default, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(render_component_1.default, { ...renderComponentProps() }))));
|
|
179
|
+
_b.map((child) => (React.createElement(block_styles_1.default, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(render_component_1.default, { ...renderComponentProps() })))) : null));
|
|
171
180
|
}
|
|
172
181
|
exports.default = RenderBlock;
|
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.1.
|
|
4
|
+
"version": "0.1.8",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -31,7 +31,6 @@
|
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"@tsconfig/react-native": "^2.0.3",
|
|
33
33
|
"@types/react-native-video": "^5.0.9",
|
|
34
|
-
"react-native": "^0.64.3",
|
|
35
34
|
"react-native-url-polyfill": "^1.3.0",
|
|
36
35
|
"typescript": "^4.9.4"
|
|
37
36
|
}
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import { useContext } from "react";
|
|
3
4
|
import RenderBlocks from "../../components/render-blocks";
|
|
4
5
|
import { getSizesForBreakpoints } from "../../constants/device-sizes";
|
|
5
6
|
import RenderInlinedStyles from "../../components/render-inlined-styles";
|
|
6
7
|
import { TARGET } from "../../constants/target.js";
|
|
7
8
|
import { convertStyleMapToCSS } from "../../helpers/css";
|
|
9
|
+
import BuilderContext from "../../context/builder.context.js";
|
|
8
10
|
|
|
9
11
|
export default function Columns(props) {
|
|
10
12
|
function getGutterSize() {
|
|
@@ -58,7 +60,7 @@ export default function Columns(props) {
|
|
|
58
60
|
|
|
59
61
|
function getWidthForBreakpointSize(size) {
|
|
60
62
|
const breakpointSizes = getSizesForBreakpoints(
|
|
61
|
-
|
|
63
|
+
builderContext.content?.meta?.breakpoints || {}
|
|
62
64
|
);
|
|
63
65
|
return breakpointSizes[size].max;
|
|
64
66
|
}
|
|
@@ -120,6 +122,8 @@ export default function Columns(props) {
|
|
|
120
122
|
return columnStyleObjects.column.small;
|
|
121
123
|
}
|
|
122
124
|
|
|
125
|
+
const builderContext = useContext(BuilderContext);
|
|
126
|
+
|
|
123
127
|
return (
|
|
124
128
|
<View style={styles.view1}>
|
|
125
129
|
{TARGET !== "reactNative" ? (
|
|
@@ -7,6 +7,7 @@ import {
|
|
|
7
7
|
import { TARGET } from "../../constants/target.js";
|
|
8
8
|
import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
9
9
|
import { createCssClass } from "../../helpers/css.js";
|
|
10
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
10
11
|
import RenderInlinedStyles from "../render-inlined-styles";
|
|
11
12
|
|
|
12
13
|
export default function BlockStyles(props) {
|
|
@@ -19,6 +20,17 @@ export default function BlockStyles(props) {
|
|
|
19
20
|
});
|
|
20
21
|
}
|
|
21
22
|
|
|
23
|
+
function canShowBlock() {
|
|
24
|
+
// only render styles for blocks that are visible
|
|
25
|
+
if (checkIsDefined(useBlock().hide)) {
|
|
26
|
+
return !useBlock().hide;
|
|
27
|
+
}
|
|
28
|
+
if (checkIsDefined(useBlock().show)) {
|
|
29
|
+
return useBlock().show;
|
|
30
|
+
}
|
|
31
|
+
return true;
|
|
32
|
+
}
|
|
33
|
+
|
|
22
34
|
function css() {
|
|
23
35
|
const styles = useBlock().responsiveStyles;
|
|
24
36
|
const content = props.context.content;
|
|
@@ -60,7 +72,7 @@ export default function BlockStyles(props) {
|
|
|
60
72
|
|
|
61
73
|
return (
|
|
62
74
|
<>
|
|
63
|
-
{TARGET !== "reactNative" && css() ? (
|
|
75
|
+
{TARGET !== "reactNative" && css() && canShowBlock() ? (
|
|
64
76
|
<>
|
|
65
77
|
<RenderInlinedStyles styles={css()} />
|
|
66
78
|
</>
|
|
@@ -17,6 +17,7 @@ import { TARGET } from "../../constants/target.js";
|
|
|
17
17
|
import { extractTextStyles } from "../../functions/extract-text-styles.js";
|
|
18
18
|
import RenderComponent from "./render-component";
|
|
19
19
|
import { getReactNativeBlockStyles } from "../../functions/get-react-native-block-styles.js";
|
|
20
|
+
import { checkIsDefined } from "../../helpers/nullable.js";
|
|
20
21
|
|
|
21
22
|
export default function RenderBlock(props) {
|
|
22
23
|
const [component, setComponent] = useState(() =>
|
|
@@ -41,6 +42,16 @@ export default function RenderBlock(props) {
|
|
|
41
42
|
});
|
|
42
43
|
}
|
|
43
44
|
|
|
45
|
+
function canShowBlock() {
|
|
46
|
+
if (checkIsDefined(useBlock().hide)) {
|
|
47
|
+
return !useBlock().hide;
|
|
48
|
+
}
|
|
49
|
+
if (checkIsDefined(useBlock().show)) {
|
|
50
|
+
return useBlock().show;
|
|
51
|
+
}
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
|
|
44
55
|
function proxyState() {
|
|
45
56
|
if (typeof Proxy === "undefined") {
|
|
46
57
|
console.error(
|
|
@@ -103,7 +114,6 @@ export default function RenderBlock(props) {
|
|
|
103
114
|
...actions(),
|
|
104
115
|
},
|
|
105
116
|
}),
|
|
106
|
-
customBreakpoints: childrenContext?.()?.content?.meta?.breakpoints,
|
|
107
117
|
},
|
|
108
118
|
context: childrenContext(),
|
|
109
119
|
};
|
|
@@ -154,51 +164,55 @@ export default function RenderBlock(props) {
|
|
|
154
164
|
|
|
155
165
|
return (
|
|
156
166
|
<>
|
|
157
|
-
{
|
|
167
|
+
{canShowBlock() ? (
|
|
158
168
|
<>
|
|
159
|
-
{
|
|
160
|
-
<>
|
|
161
|
-
<View {...attributes()} {...actions()} />
|
|
162
|
-
</>
|
|
163
|
-
) : null}
|
|
164
|
-
{!isEmptyHtmlElement(tag()) && repeatItemData ? (
|
|
165
|
-
<>
|
|
166
|
-
{repeatItemData?.map((data, index) => (
|
|
167
|
-
<RenderRepeatedBlock
|
|
168
|
-
key={index}
|
|
169
|
-
repeatContext={data.context}
|
|
170
|
-
block={data.block}
|
|
171
|
-
/>
|
|
172
|
-
))}
|
|
173
|
-
</>
|
|
174
|
-
) : null}
|
|
175
|
-
{!isEmptyHtmlElement(tag()) && !repeatItemData ? (
|
|
169
|
+
{!component?.noWrap ? (
|
|
176
170
|
<>
|
|
177
|
-
|
|
178
|
-
|
|
171
|
+
{isEmptyHtmlElement(tag()) ? (
|
|
172
|
+
<>
|
|
173
|
+
<View {...attributes()} {...actions()} />
|
|
174
|
+
</>
|
|
175
|
+
) : null}
|
|
176
|
+
{!isEmptyHtmlElement(tag()) && repeatItemData ? (
|
|
177
|
+
<>
|
|
178
|
+
{repeatItemData?.map((data, index) => (
|
|
179
|
+
<RenderRepeatedBlock
|
|
180
|
+
key={index}
|
|
181
|
+
repeatContext={data.context}
|
|
182
|
+
block={data.block}
|
|
183
|
+
/>
|
|
184
|
+
))}
|
|
185
|
+
</>
|
|
186
|
+
) : null}
|
|
187
|
+
{!isEmptyHtmlElement(tag()) && !repeatItemData ? (
|
|
188
|
+
<>
|
|
189
|
+
<View {...attributes()} {...actions()}>
|
|
190
|
+
<RenderComponent {...renderComponentProps()} />
|
|
179
191
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
192
|
+
{childrenWithoutParentComponent()?.map((child) => (
|
|
193
|
+
<RenderBlock
|
|
194
|
+
key={"render-block-" + child.id}
|
|
195
|
+
block={child}
|
|
196
|
+
context={childrenContext()}
|
|
197
|
+
/>
|
|
198
|
+
))}
|
|
187
199
|
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
200
|
+
{childrenWithoutParentComponent()?.map((child) => (
|
|
201
|
+
<BlockStyles
|
|
202
|
+
key={"block-style-" + child.id}
|
|
203
|
+
block={child}
|
|
204
|
+
context={childrenContext()}
|
|
205
|
+
/>
|
|
206
|
+
))}
|
|
207
|
+
</View>
|
|
208
|
+
</>
|
|
209
|
+
) : null}
|
|
196
210
|
</>
|
|
197
|
-
) :
|
|
211
|
+
) : (
|
|
212
|
+
<RenderComponent {...renderComponentProps()} />
|
|
213
|
+
)}
|
|
198
214
|
</>
|
|
199
|
-
) :
|
|
200
|
-
<RenderComponent {...renderComponentProps()} />
|
|
201
|
-
)}
|
|
215
|
+
) : null}
|
|
202
216
|
</>
|
|
203
217
|
);
|
|
204
218
|
}
|