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