@builder.io/sdk-react-native 0.2.2 → 0.3.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/blocks/button/button.js +3 -2
- package/dist/blocks/columns/columns.js +22 -22
- package/dist/blocks/symbol/symbol.js +1 -1
- package/dist/components/render-block/block-styles.js +3 -1
- package/dist/components/render-block/render-block.helpers.js +8 -20
- package/dist/components/render-block/render-block.js +24 -17
- package/dist/components/render-block/render-component.js +2 -1
- package/dist/components/render-block/render-repeated-block.js +4 -2
- package/dist/components/render-content/components/render-styles.js +8 -8
- package/dist/components/render-content/render-content.js +13 -7
- package/dist/components/render-inlined-styles.js +1 -1
- package/dist/constants/sdk-version.js +4 -0
- package/dist/context/builder.context.js +3 -2
- package/dist/functions/evaluate.js +25 -3
- package/dist/functions/evaluate.test.js +19 -0
- package/dist/functions/get-block-actions-handler.js +3 -1
- package/dist/functions/get-content/index.js +1 -1
- package/dist/functions/get-processed-block.js +16 -4
- package/dist/functions/get-processed-block.test.js +3 -1
- package/dist/scripts/init-editing.js +2 -0
- package/package.json +2 -5
- package/src/blocks/button/button.jsx +5 -3
- package/src/blocks/columns/columns.jsx +25 -25
- package/src/blocks/symbol/symbol.jsx +1 -1
- package/src/components/render-block/block-styles.jsx +3 -1
- package/src/components/render-block/render-block.helpers.js +7 -19
- package/src/components/render-block/render-block.jsx +21 -19
- package/src/components/render-block/render-component.jsx +2 -1
- package/src/components/render-block/render-repeated-block.jsx +4 -2
- package/src/components/render-content/components/render-styles.jsx +8 -8
- package/src/components/render-content/render-content.jsx +13 -7
- package/src/components/render-inlined-styles.jsx +1 -1
- package/src/constants/sdk-version.js +1 -0
- package/src/context/builder.context.js +3 -2
- package/src/functions/evaluate.js +27 -3
- package/src/functions/evaluate.test.js +17 -0
- package/src/functions/get-block-actions-handler.js +3 -1
- package/src/functions/get-content/index.js +1 -1
- package/src/functions/get-processed-block.js +20 -4
- package/src/functions/get-processed-block.test.js +3 -1
- package/src/scripts/init-editing.js +2 -0
|
@@ -32,8 +32,9 @@ const react_native_1 = require("react-native");
|
|
|
32
32
|
function Button(props) {
|
|
33
33
|
return (React.createElement(React.Fragment, null, props.link ? (React.createElement(React.Fragment, null,
|
|
34
34
|
React.createElement(react_native_1.View, { role: "button", ...props.attributes, href: props.link, target: props.openLinkInNewTab ? "_blank" : undefined },
|
|
35
|
-
React.createElement(BaseText_1.default, null, props.text)))) : (React.createElement(
|
|
36
|
-
React.createElement(
|
|
35
|
+
React.createElement(BaseText_1.default, null, props.text)))) : (React.createElement(React.Fragment, null,
|
|
36
|
+
React.createElement(react_native_1.View, { ...props.attributes, style: styles.view1 },
|
|
37
|
+
React.createElement(BaseText_1.default, null, props.text))))));
|
|
37
38
|
}
|
|
38
39
|
const styles = react_native_1.StyleSheet.create({ view1: { all: "unset" } });
|
|
39
40
|
exports.default = Button;
|
|
@@ -80,7 +80,7 @@ function Columns(props) {
|
|
|
80
80
|
};
|
|
81
81
|
}
|
|
82
82
|
const width = getColumnCssWidth(index);
|
|
83
|
-
const gutterPixels = `${
|
|
83
|
+
const gutterPixels = `${gutter}px`;
|
|
84
84
|
const mobileWidth = "100%";
|
|
85
85
|
const mobileMarginLeft = 0;
|
|
86
86
|
return {
|
|
@@ -111,30 +111,30 @@ function Columns(props) {
|
|
|
111
111
|
}
|
|
112
112
|
function columnsStyles() {
|
|
113
113
|
return `
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
114
|
+
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
115
|
+
.${props.builderBlock.id}-breakpoints {
|
|
116
|
+
flex-direction: var(--flex-dir-tablet);
|
|
117
|
+
align-items: stretch;
|
|
118
|
+
}
|
|
119
119
|
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
120
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
121
|
+
width: var(--column-width-tablet) !important;
|
|
122
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
125
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
126
|
+
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
127
|
+
.${props.builderBlock.id}-breakpoints {
|
|
128
|
+
flex-direction: var(--flex-dir);
|
|
129
|
+
align-items: stretch;
|
|
130
|
+
}
|
|
131
131
|
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
132
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
133
|
+
width: var(--column-width-mobile) !important;
|
|
134
|
+
margin-left: var(--column-margin-left-mobile) !important;
|
|
135
|
+
}
|
|
136
|
+
},
|
|
137
|
+
`;
|
|
138
138
|
}
|
|
139
139
|
const builderContext = (0, react_1.useContext)(builder_context_js_1.default);
|
|
140
140
|
return (React.createElement(react_native_1.View, { style: columnsCssVars(), dataSet: {
|
|
@@ -98,7 +98,7 @@ function Symbol(props) {
|
|
|
98
98
|
} },
|
|
99
99
|
React.createElement(render_content_1.default, { apiVersion: builderContext.apiVersion, apiKey: builderContext.apiKey, context: builderContext.context, customComponents: Object.values(builderContext.registeredComponents), data: {
|
|
100
100
|
...(_a = props.symbol) === null || _a === void 0 ? void 0 : _a.data,
|
|
101
|
-
...builderContext.
|
|
101
|
+
...builderContext.localState,
|
|
102
102
|
...(_b = contentToUse === null || contentToUse === void 0 ? void 0 : contentToUse.data) === null || _b === void 0 ? void 0 : _b.state,
|
|
103
103
|
}, model: (_c = props.symbol) === null || _c === void 0 ? void 0 : _c.model, content: contentToUse })));
|
|
104
104
|
}
|
|
@@ -38,7 +38,9 @@ function BlockStyles(props) {
|
|
|
38
38
|
function useBlock() {
|
|
39
39
|
return (0, get_processed_block_js_1.getProcessedBlock)({
|
|
40
40
|
block: props.block,
|
|
41
|
-
|
|
41
|
+
localState: props.context.localState,
|
|
42
|
+
rootState: props.context.rootState,
|
|
43
|
+
rootSetState: props.context.rootSetState,
|
|
42
44
|
context: props.context.context,
|
|
43
45
|
shouldEvaluateBindings: true,
|
|
44
46
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.isEmptyHtmlElement = exports.getRepeatItemData = exports.
|
|
3
|
+
exports.isEmptyHtmlElement = exports.getRepeatItemData = exports.getComponent = void 0;
|
|
4
4
|
var __defProp = Object.defineProperty;
|
|
5
5
|
var __defProps = Object.defineProperties;
|
|
6
6
|
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
@@ -59,7 +59,9 @@ const getComponent = ({ block, context }) => {
|
|
|
59
59
|
var _a;
|
|
60
60
|
const componentName = (_a = (0, get_processed_block_1.getProcessedBlock)({
|
|
61
61
|
block,
|
|
62
|
-
|
|
62
|
+
localState: context.localState,
|
|
63
|
+
rootState: context.rootState,
|
|
64
|
+
rootSetState: context.rootSetState,
|
|
63
65
|
context: context.context,
|
|
64
66
|
shouldEvaluateBindings: false
|
|
65
67
|
}).component) == null ? void 0 : _a.name;
|
|
@@ -85,7 +87,9 @@ const getRepeatItemData = ({ block, context }) => {
|
|
|
85
87
|
}
|
|
86
88
|
const itemsArray = (0, evaluate_1.evaluate)({
|
|
87
89
|
code: repeat.collection,
|
|
88
|
-
|
|
90
|
+
localState: context.localState,
|
|
91
|
+
rootState: context.rootState,
|
|
92
|
+
rootSetState: context.rootSetState,
|
|
89
93
|
context: context.context
|
|
90
94
|
});
|
|
91
95
|
if (!Array.isArray(itemsArray)) {
|
|
@@ -95,7 +99,7 @@ const getRepeatItemData = ({ block, context }) => {
|
|
|
95
99
|
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
96
100
|
const repeatArray = itemsArray.map((item, index) => ({
|
|
97
101
|
context: __spreadProps(__spreadValues({}, context), {
|
|
98
|
-
|
|
102
|
+
localState: __spreadProps(__spreadValues({}, context.localState), {
|
|
99
103
|
$index: index,
|
|
100
104
|
$item: item,
|
|
101
105
|
[itemNameToUse]: item,
|
|
@@ -107,19 +111,3 @@ const getRepeatItemData = ({ block, context }) => {
|
|
|
107
111
|
return repeatArray;
|
|
108
112
|
};
|
|
109
113
|
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;
|
|
@@ -41,21 +41,25 @@ const extract_text_styles_js_1 = require("../../functions/extract-text-styles.js
|
|
|
41
41
|
const render_component_1 = __importDefault(require("./render-component"));
|
|
42
42
|
const get_react_native_block_styles_js_1 = require("../../functions/get-react-native-block-styles.js");
|
|
43
43
|
function RenderBlock(props) {
|
|
44
|
-
var _a, _b;
|
|
44
|
+
var _a, _b, _c;
|
|
45
45
|
const [component, setComponent] = (0, react_1.useState)(() => (0, render_block_helpers_js_1.getComponent)({
|
|
46
46
|
block: props.block,
|
|
47
47
|
context: props.context,
|
|
48
48
|
}));
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
49
|
+
function repeatItem() {
|
|
50
|
+
return (0, render_block_helpers_js_1.getRepeatItemData)({
|
|
51
|
+
block: props.block,
|
|
52
|
+
context: props.context,
|
|
53
|
+
});
|
|
54
|
+
}
|
|
53
55
|
function useBlock() {
|
|
54
|
-
return
|
|
56
|
+
return repeatItem()
|
|
55
57
|
? props.block
|
|
56
58
|
: (0, get_processed_block_js_1.getProcessedBlock)({
|
|
57
59
|
block: props.block,
|
|
58
|
-
|
|
60
|
+
localState: props.context.localState,
|
|
61
|
+
rootState: props.context.rootState,
|
|
62
|
+
rootSetState: props.context.rootSetState,
|
|
59
63
|
context: props.context.context,
|
|
60
64
|
shouldEvaluateBindings: true,
|
|
61
65
|
});
|
|
@@ -70,11 +74,12 @@ function RenderBlock(props) {
|
|
|
70
74
|
}
|
|
71
75
|
return true;
|
|
72
76
|
}
|
|
73
|
-
const [proxyState, setProxyState] = (0, react_1.useState)(() => (0, render_block_helpers_js_1.getProxyState)(props.context));
|
|
74
77
|
function actions() {
|
|
75
78
|
return (0, get_block_actions_js_1.getBlockActions)({
|
|
76
79
|
block: useBlock(),
|
|
77
|
-
|
|
80
|
+
rootState: props.context.rootState,
|
|
81
|
+
rootSetState: props.context.rootSetState,
|
|
82
|
+
localState: props.context.localState,
|
|
78
83
|
context: props.context.context,
|
|
79
84
|
});
|
|
80
85
|
}
|
|
@@ -101,7 +106,7 @@ function RenderBlock(props) {
|
|
|
101
106
|
* NOTE: We make sure not to render this if `repeatItemData` is non-null, because that means we are rendering an array of
|
|
102
107
|
* blocks, and the children will be repeated within those blocks.
|
|
103
108
|
*/
|
|
104
|
-
const shouldRenderChildrenOutsideRef = !(component === null || component === void 0 ? void 0 : component.component) && !
|
|
109
|
+
const shouldRenderChildrenOutsideRef = !(component === null || component === void 0 ? void 0 : component.component) && !repeatItem();
|
|
105
110
|
return shouldRenderChildrenOutsideRef ? (_a = useBlock().children) !== null && _a !== void 0 ? _a : [] : [];
|
|
106
111
|
}
|
|
107
112
|
function childrenContext() {
|
|
@@ -118,10 +123,11 @@ function RenderBlock(props) {
|
|
|
118
123
|
return {
|
|
119
124
|
apiKey: props.context.apiKey,
|
|
120
125
|
apiVersion: props.context.apiVersion,
|
|
121
|
-
|
|
126
|
+
localState: props.context.localState,
|
|
127
|
+
rootState: props.context.rootState,
|
|
128
|
+
rootSetState: props.context.rootSetState,
|
|
122
129
|
content: props.context.content,
|
|
123
130
|
context: props.context.context,
|
|
124
|
-
setState: props.context.setState,
|
|
125
131
|
registeredComponents: props.context.registeredComponents,
|
|
126
132
|
inheritedStyles: getInheritedTextStyles(),
|
|
127
133
|
};
|
|
@@ -152,11 +158,12 @@ function RenderBlock(props) {
|
|
|
152
158
|
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,
|
|
153
159
|
(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag) ? (React.createElement(React.Fragment, null,
|
|
154
160
|
React.createElement(react_native_1.View, { ...attributes(), ...actions() }))) : null,
|
|
155
|
-
!(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag) &&
|
|
156
|
-
!(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag) && !
|
|
161
|
+
!(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag) && repeatItem() ? (React.createElement(React.Fragment, null, (_a = repeatItem()) === null || _a === void 0 ? void 0 : _a.map((data, index) => (React.createElement(render_repeated_block_1.default, { key: index, repeatContext: data.context, block: data.block }))))) : null,
|
|
162
|
+
!(0, render_block_helpers_js_1.isEmptyHtmlElement)(tag) && !repeatItem() ? (React.createElement(React.Fragment, null,
|
|
157
163
|
React.createElement(react_native_1.View, { ...attributes(), ...actions() },
|
|
158
|
-
React.createElement(render_component_1.default, { ...renderComponentProps() }), (
|
|
159
|
-
|
|
160
|
-
|
|
164
|
+
React.createElement(render_component_1.default, { ...renderComponentProps() }), (_b = childrenWithoutParentComponent()) === null || _b === void 0 ? void 0 :
|
|
165
|
+
_b.map((child) => (React.createElement(RenderBlock, { key: "render-block-" + child.id, block: child, context: childrenContext() }))), (_c = childrenWithoutParentComponent()) === null || _c === void 0 ? void 0 :
|
|
166
|
+
_c.map((child) => (React.createElement(block_styles_1.default, { key: "block-style-" + child.id, block: child, context: childrenContext() })))))) : null)) : (React.createElement(React.Fragment, null,
|
|
167
|
+
React.createElement(render_component_1.default, { ...renderComponentProps() }))))) : null));
|
|
161
168
|
}
|
|
162
169
|
exports.default = RenderBlock;
|
|
@@ -37,7 +37,8 @@ function RenderComponent(props) {
|
|
|
37
37
|
const ComponentRefRef = props.componentRef;
|
|
38
38
|
return (React.createElement(builder_context_js_1.default.Provider, { value: {
|
|
39
39
|
content: props.context.content,
|
|
40
|
-
|
|
40
|
+
rootState: props.context.rootState,
|
|
41
|
+
localState: props.context.localState,
|
|
41
42
|
context: props.context.context,
|
|
42
43
|
apiKey: props.context.apiKey,
|
|
43
44
|
registeredComponents: props.context.registeredComponents,
|
|
@@ -34,12 +34,14 @@ const render_block_1 = __importDefault(require("./render-block"));
|
|
|
34
34
|
function RenderRepeatedBlock(props) {
|
|
35
35
|
return (React.createElement(builder_context_js_1.default.Provider, { value: {
|
|
36
36
|
content: props.repeatContext.content,
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
localState: props.repeatContext.localState,
|
|
38
|
+
rootState: props.repeatContext.rootState,
|
|
39
|
+
rootSetState: props.repeatContext.rootSetState,
|
|
39
40
|
context: props.repeatContext.context,
|
|
40
41
|
apiKey: props.repeatContext.apiKey,
|
|
41
42
|
registeredComponents: props.repeatContext.registeredComponents,
|
|
42
43
|
inheritedStyles: props.repeatContext.inheritedStyles,
|
|
44
|
+
apiVersion: props.repeatContext.apiVersion,
|
|
43
45
|
} },
|
|
44
46
|
React.createElement(render_block_1.default, { block: props.block, context: props.repeatContext })));
|
|
45
47
|
}
|
|
@@ -43,16 +43,16 @@ ${(0, render_styles_helpers_2.getFontCss)({
|
|
|
43
43
|
})}
|
|
44
44
|
|
|
45
45
|
.builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
|
|
46
|
-
margin: 0;
|
|
46
|
+
margin: 0;
|
|
47
47
|
}
|
|
48
48
|
.builder-text > p, .builder-text > .builder-paragraph {
|
|
49
|
-
color: inherit;
|
|
50
|
-
line-height: inherit;
|
|
51
|
-
letter-spacing: inherit;
|
|
52
|
-
font-weight: inherit;
|
|
53
|
-
font-size: inherit;
|
|
54
|
-
text-align: inherit;
|
|
55
|
-
font-family: inherit;
|
|
49
|
+
color: inherit;
|
|
50
|
+
line-height: inherit;
|
|
51
|
+
letter-spacing: inherit;
|
|
52
|
+
font-weight: inherit;
|
|
53
|
+
font-size: inherit;
|
|
54
|
+
text-align: inherit;
|
|
55
|
+
font-family: inherit;
|
|
56
56
|
}
|
|
57
57
|
`);
|
|
58
58
|
return React.createElement(render_inlined_styles_1.default, { styles: injectedStyles });
|
|
@@ -88,8 +88,8 @@ function RenderContent(props) {
|
|
|
88
88
|
data: props.data,
|
|
89
89
|
locale: props.locale,
|
|
90
90
|
}));
|
|
91
|
-
function
|
|
92
|
-
setContentState(
|
|
91
|
+
function contentSetState(newRootState) {
|
|
92
|
+
setContentState(newRootState);
|
|
93
93
|
}
|
|
94
94
|
const [allRegisteredComponents, setAllRegisteredComponents] = (0, react_1.useState)(() => [
|
|
95
95
|
...(0, builder_registered_components_js_1.getDefaultRegisteredComponents)(),
|
|
@@ -148,7 +148,9 @@ function RenderContent(props) {
|
|
|
148
148
|
(0, evaluate_js_1.evaluate)({
|
|
149
149
|
code: jsCode,
|
|
150
150
|
context: props.context || {},
|
|
151
|
-
|
|
151
|
+
localState: undefined,
|
|
152
|
+
rootState: contentState,
|
|
153
|
+
rootSetState: contentSetState,
|
|
152
154
|
});
|
|
153
155
|
}
|
|
154
156
|
}
|
|
@@ -176,7 +178,9 @@ function RenderContent(props) {
|
|
|
176
178
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => (0, evaluate_js_1.evaluate)({
|
|
177
179
|
code: group,
|
|
178
180
|
context: props.context || {},
|
|
179
|
-
|
|
181
|
+
localState: undefined,
|
|
182
|
+
rootState: contentState,
|
|
183
|
+
rootSetState: contentSetState,
|
|
180
184
|
}));
|
|
181
185
|
}
|
|
182
186
|
function handleRequest({ url, key }) {
|
|
@@ -187,7 +191,7 @@ function RenderContent(props) {
|
|
|
187
191
|
...contentState,
|
|
188
192
|
[key]: json,
|
|
189
193
|
};
|
|
190
|
-
|
|
194
|
+
contentSetState(newState);
|
|
191
195
|
})
|
|
192
196
|
.catch((err) => {
|
|
193
197
|
console.error("error fetching dynamic data", url, err);
|
|
@@ -313,12 +317,14 @@ function RenderContent(props) {
|
|
|
313
317
|
}, []);
|
|
314
318
|
return (React.createElement(builder_context_js_1.default.Provider, { value: {
|
|
315
319
|
content: useContent,
|
|
316
|
-
|
|
317
|
-
|
|
320
|
+
localState: undefined,
|
|
321
|
+
rootState: contentState,
|
|
322
|
+
rootSetState: target_js_1.TARGET === "qwik" ? undefined : contentSetState,
|
|
318
323
|
context: props.context || {},
|
|
319
324
|
apiKey: props.apiKey,
|
|
320
325
|
apiVersion: props.apiVersion,
|
|
321
326
|
registeredComponents: allRegisteredComponents,
|
|
327
|
+
inheritedStyles: {},
|
|
322
328
|
} }, useContent ? (React.createElement(React.Fragment, null,
|
|
323
329
|
React.createElement(react_native_1.ScrollView, { ref: elementRef, onClick: (event) => onClick(event), "builder-content-id": useContent === null || useContent === void 0 ? void 0 : useContent.id, "builder-model": props.model },
|
|
324
330
|
target_js_1.TARGET !== "reactNative" ? (React.createElement(React.Fragment, null,
|
|
@@ -28,7 +28,7 @@ const react_native_1 = require("react-native");
|
|
|
28
28
|
const target_js_1 = require("../constants/target.js");
|
|
29
29
|
function RenderInlinedStyles(props) {
|
|
30
30
|
function tag() {
|
|
31
|
-
// NOTE: we have to
|
|
31
|
+
// NOTE: we have to obfuscate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
32
32
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
33
33
|
return "sty" + "le";
|
|
34
34
|
}
|
|
@@ -5,9 +5,10 @@ const react_1 = require("react");
|
|
|
5
5
|
var stdin_default = (0, react_1.createContext)({
|
|
6
6
|
content: null,
|
|
7
7
|
context: {},
|
|
8
|
-
|
|
9
|
-
|
|
8
|
+
localState: void 0,
|
|
9
|
+
rootSetState() {
|
|
10
10
|
},
|
|
11
|
+
rootState: {},
|
|
11
12
|
apiKey: null,
|
|
12
13
|
apiVersion: void 0,
|
|
13
14
|
registeredComponents: {},
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.evaluate = void 0;
|
|
3
|
+
exports.flattenState = exports.evaluate = void 0;
|
|
4
4
|
const is_browser_js_1 = require("./is-browser.js");
|
|
5
5
|
const is_editing_js_1 = require("./is-editing.js");
|
|
6
|
-
function evaluate({ code, context,
|
|
6
|
+
function evaluate({ code, context, localState, rootState, rootSetState, event, isExpression = true }) {
|
|
7
7
|
if (code === "") {
|
|
8
8
|
console.warn("Skipping evaluation of empty code block.");
|
|
9
9
|
return;
|
|
@@ -16,10 +16,32 @@ function evaluate({ code, context, state, event, isExpression = true }) {
|
|
|
16
16
|
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
17
17
|
const useCode = useReturn ? `return (${code});` : code;
|
|
18
18
|
try {
|
|
19
|
-
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder,
|
|
19
|
+
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
|
|
20
20
|
}
|
|
21
21
|
catch (e) {
|
|
22
22
|
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
|
|
23
23
|
}
|
|
24
24
|
}
|
|
25
25
|
exports.evaluate = evaluate;
|
|
26
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
27
|
+
if (rootState === localState) {
|
|
28
|
+
throw new Error("rootState === localState");
|
|
29
|
+
}
|
|
30
|
+
return new Proxy(rootState, {
|
|
31
|
+
get: (_, prop) => {
|
|
32
|
+
if (localState && prop in localState) {
|
|
33
|
+
return localState[prop];
|
|
34
|
+
}
|
|
35
|
+
return rootState[prop];
|
|
36
|
+
},
|
|
37
|
+
set: (_, prop, value) => {
|
|
38
|
+
if (localState && prop in localState) {
|
|
39
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
40
|
+
}
|
|
41
|
+
rootState[prop] = value;
|
|
42
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
43
|
+
return true;
|
|
44
|
+
}
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
exports.flattenState = flattenState;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const evaluate_1 = require("./evaluate");
|
|
4
|
+
describe("flatten state", () => {
|
|
5
|
+
it("should behave normally when no PROTO_STATE", () => {
|
|
6
|
+
const localState = {};
|
|
7
|
+
const rootState = { foo: "bar" };
|
|
8
|
+
const flattened = (0, evaluate_1.flattenState)(rootState, localState, void 0);
|
|
9
|
+
expect(flattened.foo).toEqual("bar");
|
|
10
|
+
flattened.foo = "baz";
|
|
11
|
+
expect(rootState.foo).toEqual("baz");
|
|
12
|
+
});
|
|
13
|
+
it("should shadow write ", () => {
|
|
14
|
+
const rootState = { foo: "foo" };
|
|
15
|
+
const localState = { foo: "baz" };
|
|
16
|
+
const flattened = (0, evaluate_1.flattenState)(rootState, localState, void 0);
|
|
17
|
+
expect(() => flattened.foo = "bar").toThrow("Writing to local state is not allowed as it is read-only.");
|
|
18
|
+
});
|
|
19
|
+
});
|
|
@@ -5,7 +5,9 @@ const evaluate_js_1 = require("./evaluate.js");
|
|
|
5
5
|
const createEventHandler = (value, options) => (event) => (0, evaluate_js_1.evaluate)({
|
|
6
6
|
code: value,
|
|
7
7
|
context: options.context,
|
|
8
|
-
|
|
8
|
+
localState: options.localState,
|
|
9
|
+
rootState: options.rootState,
|
|
10
|
+
rootSetState: options.rootSetState,
|
|
9
11
|
event,
|
|
10
12
|
isExpression: false
|
|
11
13
|
});
|
|
@@ -63,7 +63,7 @@ function getAllContent(options) {
|
|
|
63
63
|
const res = yield (0, get_fetch_js_1.fetch)(url.href);
|
|
64
64
|
const content = yield res.json();
|
|
65
65
|
if ("status" in content && !("results" in content)) {
|
|
66
|
-
logger_js_1.logger.error("Error fetching data. ", content, options);
|
|
66
|
+
logger_js_1.logger.error("Error fetching data. ", { url, content, options });
|
|
67
67
|
return content;
|
|
68
68
|
}
|
|
69
69
|
const canTrack = options.canTrack !== false;
|
|
@@ -24,7 +24,7 @@ const evaluate_js_1 = require("./evaluate.js");
|
|
|
24
24
|
const fast_clone_js_1 = require("./fast-clone.js");
|
|
25
25
|
const set_js_1 = require("./set.js");
|
|
26
26
|
const transform_block_js_1 = require("./transform-block.js");
|
|
27
|
-
const evaluateBindings = ({ block, context,
|
|
27
|
+
const evaluateBindings = ({ block, context, localState, rootState, rootSetState }) => {
|
|
28
28
|
if (!block.bindings) {
|
|
29
29
|
return block;
|
|
30
30
|
}
|
|
@@ -35,15 +35,27 @@ const evaluateBindings = ({ block, context, state }) => {
|
|
|
35
35
|
});
|
|
36
36
|
for (const binding in block.bindings) {
|
|
37
37
|
const expression = block.bindings[binding];
|
|
38
|
-
const value = (0, evaluate_js_1.evaluate)({
|
|
38
|
+
const value = (0, evaluate_js_1.evaluate)({
|
|
39
|
+
code: expression,
|
|
40
|
+
localState,
|
|
41
|
+
rootState,
|
|
42
|
+
rootSetState,
|
|
43
|
+
context
|
|
44
|
+
});
|
|
39
45
|
(0, set_js_1.set)(copied, binding, value);
|
|
40
46
|
}
|
|
41
47
|
return copied;
|
|
42
48
|
};
|
|
43
|
-
function getProcessedBlock({ block, context, shouldEvaluateBindings,
|
|
49
|
+
function getProcessedBlock({ block, context, shouldEvaluateBindings, localState, rootState, rootSetState }) {
|
|
44
50
|
const transformedBlock = (0, transform_block_js_1.transformBlock)(block);
|
|
45
51
|
if (shouldEvaluateBindings) {
|
|
46
|
-
return evaluateBindings({
|
|
52
|
+
return evaluateBindings({
|
|
53
|
+
block: transformedBlock,
|
|
54
|
+
localState,
|
|
55
|
+
rootState,
|
|
56
|
+
rootSetState,
|
|
57
|
+
context
|
|
58
|
+
});
|
|
47
59
|
}
|
|
48
60
|
else {
|
|
49
61
|
return transformedBlock;
|
|
@@ -22,7 +22,9 @@ test("Can process bindings", () => {
|
|
|
22
22
|
const processed = (0, get_processed_block_js_1.getProcessedBlock)({
|
|
23
23
|
block,
|
|
24
24
|
context: {},
|
|
25
|
-
|
|
25
|
+
rootState: { test: "hello" },
|
|
26
|
+
rootSetState: void 0,
|
|
27
|
+
localState: void 0,
|
|
26
28
|
shouldEvaluateBindings: true
|
|
27
29
|
});
|
|
28
30
|
expect(processed).not.toEqual(block);
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setupBrowserForEditing = exports.registerInsertMenu = void 0;
|
|
4
|
+
const sdk_version_js_1 = require("../constants/sdk-version.js");
|
|
4
5
|
const target_js_1 = require("../constants/target.js");
|
|
5
6
|
const is_browser_js_1 = require("../functions/is-browser.js");
|
|
6
7
|
const register_js_1 = require("../functions/register.js");
|
|
@@ -35,6 +36,7 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
35
36
|
type: "builder.sdkInfo",
|
|
36
37
|
data: {
|
|
37
38
|
target: target_js_1.TARGET,
|
|
39
|
+
version: sdk_version_js_1.SDK_VERSION,
|
|
38
40
|
supportsPatchUpdates: false,
|
|
39
41
|
supportsAddBlockScoping: true,
|
|
40
42
|
supportsCustomBreakpoints: true
|
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.
|
|
4
|
+
"version": "0.3.1",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
7
7
|
"module": "./dist/index.js",
|
|
@@ -13,10 +13,7 @@
|
|
|
13
13
|
"dist"
|
|
14
14
|
],
|
|
15
15
|
"scripts": {
|
|
16
|
-
"build": "tsc"
|
|
17
|
-
"release:patch": "yarn run build && npm version patch && npm publish",
|
|
18
|
-
"release:minor": "yarn run build && npm version minor && npm publish",
|
|
19
|
-
"release:dev": "yarn run build && npm version prerelease && npm publish --tag dev"
|
|
16
|
+
"build": "tsc"
|
|
20
17
|
},
|
|
21
18
|
"dependencies": {
|
|
22
19
|
"@react-native-async-storage/async-storage": "^1.17.10",
|
|
@@ -24,9 +24,11 @@ function Button(props) {
|
|
|
24
24
|
</View>
|
|
25
25
|
</>
|
|
26
26
|
) : (
|
|
27
|
-
|
|
28
|
-
<
|
|
29
|
-
|
|
27
|
+
<>
|
|
28
|
+
<View {...props.attributes} style={styles.view1}>
|
|
29
|
+
<BaseText>{props.text}</BaseText>
|
|
30
|
+
</View>
|
|
31
|
+
</>
|
|
30
32
|
)}
|
|
31
33
|
</>
|
|
32
34
|
);
|
|
@@ -73,7 +73,7 @@ function Columns(props) {
|
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
75
|
const width = getColumnCssWidth(index);
|
|
76
|
-
const gutterPixels = `${
|
|
76
|
+
const gutterPixels = `${gutter}px`;
|
|
77
77
|
const mobileWidth = "100%";
|
|
78
78
|
const mobileMarginLeft = 0;
|
|
79
79
|
return {
|
|
@@ -107,30 +107,30 @@ function Columns(props) {
|
|
|
107
107
|
|
|
108
108
|
function columnsStyles() {
|
|
109
109
|
return `
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
110
|
+
@media (max-width: ${getWidthForBreakpointSize("medium")}px) {
|
|
111
|
+
.${props.builderBlock.id}-breakpoints {
|
|
112
|
+
flex-direction: var(--flex-dir-tablet);
|
|
113
|
+
align-items: stretch;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
117
|
+
width: var(--column-width-tablet) !important;
|
|
118
|
+
margin-left: var(--column-margin-left-tablet) !important;
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
@media (max-width: ${getWidthForBreakpointSize("small")}px) {
|
|
123
|
+
.${props.builderBlock.id}-breakpoints {
|
|
124
|
+
flex-direction: var(--flex-dir);
|
|
125
|
+
align-items: stretch;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
.${props.builderBlock.id}-breakpoints > .builder-column {
|
|
129
|
+
width: var(--column-width-mobile) !important;
|
|
130
|
+
margin-left: var(--column-margin-left-mobile) !important;
|
|
131
|
+
}
|
|
132
|
+
},
|
|
133
|
+
`;
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
const builderContext = useContext(BuilderContext);
|
|
@@ -91,7 +91,7 @@ function Symbol(props) {
|
|
|
91
91
|
customComponents={Object.values(builderContext.registeredComponents)}
|
|
92
92
|
data={{
|
|
93
93
|
...props.symbol?.data,
|
|
94
|
-
...builderContext.
|
|
94
|
+
...builderContext.localState,
|
|
95
95
|
...contentToUse?.data?.state,
|
|
96
96
|
}}
|
|
97
97
|
model={props.symbol?.model}
|
|
@@ -21,7 +21,9 @@ function BlockStyles(props) {
|
|
|
21
21
|
function useBlock() {
|
|
22
22
|
return getProcessedBlock({
|
|
23
23
|
block: props.block,
|
|
24
|
-
|
|
24
|
+
localState: props.context.localState,
|
|
25
|
+
rootState: props.context.rootState,
|
|
26
|
+
rootSetState: props.context.rootSetState,
|
|
25
27
|
context: props.context.context,
|
|
26
28
|
shouldEvaluateBindings: true,
|
|
27
29
|
});
|
|
@@ -58,7 +58,9 @@ const getComponent = ({
|
|
|
58
58
|
var _a;
|
|
59
59
|
const componentName = (_a = getProcessedBlock({
|
|
60
60
|
block,
|
|
61
|
-
|
|
61
|
+
localState: context.localState,
|
|
62
|
+
rootState: context.rootState,
|
|
63
|
+
rootSetState: context.rootSetState,
|
|
62
64
|
context: context.context,
|
|
63
65
|
shouldEvaluateBindings: false
|
|
64
66
|
}).component) == null ? void 0 : _a.name;
|
|
@@ -85,7 +87,9 @@ const getRepeatItemData = ({
|
|
|
85
87
|
}
|
|
86
88
|
const itemsArray = evaluate({
|
|
87
89
|
code: repeat.collection,
|
|
88
|
-
|
|
90
|
+
localState: context.localState,
|
|
91
|
+
rootState: context.rootState,
|
|
92
|
+
rootSetState: context.rootSetState,
|
|
89
93
|
context: context.context
|
|
90
94
|
});
|
|
91
95
|
if (!Array.isArray(itemsArray)) {
|
|
@@ -95,7 +99,7 @@ const getRepeatItemData = ({
|
|
|
95
99
|
const itemNameToUse = repeat.itemName || (collectionName ? collectionName + "Item" : "item");
|
|
96
100
|
const repeatArray = itemsArray.map((item, index) => ({
|
|
97
101
|
context: __spreadProps(__spreadValues({}, context), {
|
|
98
|
-
|
|
102
|
+
localState: __spreadProps(__spreadValues({}, context.localState), {
|
|
99
103
|
$index: index,
|
|
100
104
|
$item: item,
|
|
101
105
|
[itemNameToUse]: item,
|
|
@@ -106,24 +110,8 @@ const getRepeatItemData = ({
|
|
|
106
110
|
}));
|
|
107
111
|
return repeatArray;
|
|
108
112
|
};
|
|
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
|
-
};
|
|
124
113
|
export {
|
|
125
114
|
getComponent,
|
|
126
|
-
getProxyState,
|
|
127
115
|
getRepeatItemData,
|
|
128
116
|
isEmptyHtmlElement
|
|
129
117
|
};
|
|
@@ -15,7 +15,6 @@ import { getProcessedBlock } from "../../functions/get-processed-block.js";
|
|
|
15
15
|
import BlockStyles from "./block-styles";
|
|
16
16
|
import {
|
|
17
17
|
getComponent,
|
|
18
|
-
getProxyState,
|
|
19
18
|
getRepeatItemData,
|
|
20
19
|
isEmptyHtmlElement,
|
|
21
20
|
} from "./render-block.helpers.js";
|
|
@@ -33,19 +32,21 @@ function RenderBlock(props) {
|
|
|
33
32
|
})
|
|
34
33
|
);
|
|
35
34
|
|
|
36
|
-
|
|
37
|
-
getRepeatItemData({
|
|
35
|
+
function repeatItem() {
|
|
36
|
+
return getRepeatItemData({
|
|
38
37
|
block: props.block,
|
|
39
38
|
context: props.context,
|
|
40
|
-
})
|
|
41
|
-
|
|
39
|
+
});
|
|
40
|
+
}
|
|
42
41
|
|
|
43
42
|
function useBlock() {
|
|
44
|
-
return
|
|
43
|
+
return repeatItem()
|
|
45
44
|
? props.block
|
|
46
45
|
: getProcessedBlock({
|
|
47
46
|
block: props.block,
|
|
48
|
-
|
|
47
|
+
localState: props.context.localState,
|
|
48
|
+
rootState: props.context.rootState,
|
|
49
|
+
rootSetState: props.context.rootSetState,
|
|
49
50
|
context: props.context.context,
|
|
50
51
|
shouldEvaluateBindings: true,
|
|
51
52
|
});
|
|
@@ -63,14 +64,12 @@ function RenderBlock(props) {
|
|
|
63
64
|
return true;
|
|
64
65
|
}
|
|
65
66
|
|
|
66
|
-
const [proxyState, setProxyState] = useState(() =>
|
|
67
|
-
getProxyState(props.context)
|
|
68
|
-
);
|
|
69
|
-
|
|
70
67
|
function actions() {
|
|
71
68
|
return getBlockActions({
|
|
72
69
|
block: useBlock(),
|
|
73
|
-
|
|
70
|
+
rootState: props.context.rootState,
|
|
71
|
+
rootSetState: props.context.rootSetState,
|
|
72
|
+
localState: props.context.localState,
|
|
74
73
|
context: props.context.context,
|
|
75
74
|
});
|
|
76
75
|
}
|
|
@@ -99,7 +98,7 @@ function RenderBlock(props) {
|
|
|
99
98
|
* blocks, and the children will be repeated within those blocks.
|
|
100
99
|
*/
|
|
101
100
|
const shouldRenderChildrenOutsideRef =
|
|
102
|
-
!component?.component && !
|
|
101
|
+
!component?.component && !repeatItem();
|
|
103
102
|
return shouldRenderChildrenOutsideRef ? useBlock().children ?? [] : [];
|
|
104
103
|
}
|
|
105
104
|
|
|
@@ -119,10 +118,11 @@ function RenderBlock(props) {
|
|
|
119
118
|
return {
|
|
120
119
|
apiKey: props.context.apiKey,
|
|
121
120
|
apiVersion: props.context.apiVersion,
|
|
122
|
-
|
|
121
|
+
localState: props.context.localState,
|
|
122
|
+
rootState: props.context.rootState,
|
|
123
|
+
rootSetState: props.context.rootSetState,
|
|
123
124
|
content: props.context.content,
|
|
124
125
|
context: props.context.context,
|
|
125
|
-
setState: props.context.setState,
|
|
126
126
|
registeredComponents: props.context.registeredComponents,
|
|
127
127
|
inheritedStyles: getInheritedTextStyles(),
|
|
128
128
|
};
|
|
@@ -162,9 +162,9 @@ function RenderBlock(props) {
|
|
|
162
162
|
<View {...attributes()} {...actions()} />
|
|
163
163
|
</>
|
|
164
164
|
) : null}
|
|
165
|
-
{!isEmptyHtmlElement(tag) &&
|
|
165
|
+
{!isEmptyHtmlElement(tag) && repeatItem() ? (
|
|
166
166
|
<>
|
|
167
|
-
{
|
|
167
|
+
{repeatItem()?.map((data, index) => (
|
|
168
168
|
<RenderRepeatedBlock
|
|
169
169
|
key={index}
|
|
170
170
|
repeatContext={data.context}
|
|
@@ -173,7 +173,7 @@ function RenderBlock(props) {
|
|
|
173
173
|
))}
|
|
174
174
|
</>
|
|
175
175
|
) : null}
|
|
176
|
-
{!isEmptyHtmlElement(tag) && !
|
|
176
|
+
{!isEmptyHtmlElement(tag) && !repeatItem() ? (
|
|
177
177
|
<>
|
|
178
178
|
<View {...attributes()} {...actions()}>
|
|
179
179
|
<RenderComponent {...renderComponentProps()} />
|
|
@@ -198,7 +198,9 @@ function RenderBlock(props) {
|
|
|
198
198
|
) : null}
|
|
199
199
|
</>
|
|
200
200
|
) : (
|
|
201
|
-
|
|
201
|
+
<>
|
|
202
|
+
<RenderComponent {...renderComponentProps()} />
|
|
203
|
+
</>
|
|
202
204
|
)}
|
|
203
205
|
</>
|
|
204
206
|
) : null}
|
|
@@ -19,7 +19,8 @@ function RenderComponent(props) {
|
|
|
19
19
|
<BuilderContext.Provider
|
|
20
20
|
value={{
|
|
21
21
|
content: props.context.content,
|
|
22
|
-
|
|
22
|
+
rootState: props.context.rootState,
|
|
23
|
+
localState: props.context.localState,
|
|
23
24
|
context: props.context.context,
|
|
24
25
|
apiKey: props.context.apiKey,
|
|
25
26
|
registeredComponents: props.context.registeredComponents,
|
|
@@ -16,12 +16,14 @@ function RenderRepeatedBlock(props) {
|
|
|
16
16
|
<BuilderContext.Provider
|
|
17
17
|
value={{
|
|
18
18
|
content: props.repeatContext.content,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
localState: props.repeatContext.localState,
|
|
20
|
+
rootState: props.repeatContext.rootState,
|
|
21
|
+
rootSetState: props.repeatContext.rootSetState,
|
|
21
22
|
context: props.repeatContext.context,
|
|
22
23
|
apiKey: props.repeatContext.apiKey,
|
|
23
24
|
registeredComponents: props.repeatContext.registeredComponents,
|
|
24
25
|
inheritedStyles: props.repeatContext.inheritedStyles,
|
|
26
|
+
apiVersion: props.repeatContext.apiVersion,
|
|
25
27
|
}}
|
|
26
28
|
>
|
|
27
29
|
<RenderBlock block={props.block} context={props.repeatContext} />
|
|
@@ -24,16 +24,16 @@ ${getFontCss({
|
|
|
24
24
|
})}
|
|
25
25
|
|
|
26
26
|
.builder-text > p:first-of-type, .builder-text > .builder-paragraph:first-of-type {
|
|
27
|
-
margin: 0;
|
|
27
|
+
margin: 0;
|
|
28
28
|
}
|
|
29
29
|
.builder-text > p, .builder-text > .builder-paragraph {
|
|
30
|
-
color: inherit;
|
|
31
|
-
line-height: inherit;
|
|
32
|
-
letter-spacing: inherit;
|
|
33
|
-
font-weight: inherit;
|
|
34
|
-
font-size: inherit;
|
|
35
|
-
text-align: inherit;
|
|
36
|
-
font-family: inherit;
|
|
30
|
+
color: inherit;
|
|
31
|
+
line-height: inherit;
|
|
32
|
+
letter-spacing: inherit;
|
|
33
|
+
font-weight: inherit;
|
|
34
|
+
font-size: inherit;
|
|
35
|
+
text-align: inherit;
|
|
36
|
+
font-family: inherit;
|
|
37
37
|
}
|
|
38
38
|
`
|
|
39
39
|
);
|
|
@@ -90,8 +90,8 @@ function RenderContent(props) {
|
|
|
90
90
|
})
|
|
91
91
|
);
|
|
92
92
|
|
|
93
|
-
function
|
|
94
|
-
setContentState(
|
|
93
|
+
function contentSetState(newRootState) {
|
|
94
|
+
setContentState(newRootState);
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
const [allRegisteredComponents, setAllRegisteredComponents] = useState(() =>
|
|
@@ -159,7 +159,9 @@ function RenderContent(props) {
|
|
|
159
159
|
evaluate({
|
|
160
160
|
code: jsCode,
|
|
161
161
|
context: props.context || {},
|
|
162
|
-
|
|
162
|
+
localState: undefined,
|
|
163
|
+
rootState: contentState,
|
|
164
|
+
rootSetState: contentSetState,
|
|
163
165
|
});
|
|
164
166
|
}
|
|
165
167
|
}
|
|
@@ -192,7 +194,9 @@ function RenderContent(props) {
|
|
|
192
194
|
evaluate({
|
|
193
195
|
code: group,
|
|
194
196
|
context: props.context || {},
|
|
195
|
-
|
|
197
|
+
localState: undefined,
|
|
198
|
+
rootState: contentState,
|
|
199
|
+
rootSetState: contentSetState,
|
|
196
200
|
})
|
|
197
201
|
);
|
|
198
202
|
}
|
|
@@ -205,7 +209,7 @@ function RenderContent(props) {
|
|
|
205
209
|
...contentState,
|
|
206
210
|
[key]: json,
|
|
207
211
|
};
|
|
208
|
-
|
|
212
|
+
contentSetState(newState);
|
|
209
213
|
})
|
|
210
214
|
.catch((err) => {
|
|
211
215
|
console.error("error fetching dynamic data", url, err);
|
|
@@ -356,12 +360,14 @@ function RenderContent(props) {
|
|
|
356
360
|
<builderContext.Provider
|
|
357
361
|
value={{
|
|
358
362
|
content: useContent,
|
|
359
|
-
|
|
360
|
-
|
|
363
|
+
localState: undefined,
|
|
364
|
+
rootState: contentState,
|
|
365
|
+
rootSetState: TARGET === "qwik" ? undefined : contentSetState,
|
|
361
366
|
context: props.context || {},
|
|
362
367
|
apiKey: props.apiKey,
|
|
363
368
|
apiVersion: props.apiVersion,
|
|
364
369
|
registeredComponents: allRegisteredComponents,
|
|
370
|
+
inheritedStyles: {},
|
|
365
371
|
}}
|
|
366
372
|
>
|
|
367
373
|
{useContent ? (
|
|
@@ -11,7 +11,7 @@ import { TARGET } from "../constants/target.js";
|
|
|
11
11
|
|
|
12
12
|
function RenderInlinedStyles(props) {
|
|
13
13
|
function tag() {
|
|
14
|
-
// NOTE: we have to
|
|
14
|
+
// NOTE: we have to obfuscate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
15
15
|
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
16
16
|
return "sty" + "le";
|
|
17
17
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const SDK_VERSION = "0.3.1"
|
|
@@ -2,9 +2,10 @@ import { createContext } from "react";
|
|
|
2
2
|
var stdin_default = createContext({
|
|
3
3
|
content: null,
|
|
4
4
|
context: {},
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
localState: void 0,
|
|
6
|
+
rootSetState() {
|
|
7
7
|
},
|
|
8
|
+
rootState: {},
|
|
8
9
|
apiKey: null,
|
|
9
10
|
apiVersion: void 0,
|
|
10
11
|
registeredComponents: {},
|
|
@@ -3,7 +3,9 @@ import { isEditing } from "./is-editing.js";
|
|
|
3
3
|
function evaluate({
|
|
4
4
|
code,
|
|
5
5
|
context,
|
|
6
|
-
|
|
6
|
+
localState,
|
|
7
|
+
rootState,
|
|
8
|
+
rootSetState,
|
|
7
9
|
event,
|
|
8
10
|
isExpression = true
|
|
9
11
|
}) {
|
|
@@ -19,11 +21,33 @@ function evaluate({
|
|
|
19
21
|
const useReturn = isExpression && !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
20
22
|
const useCode = useReturn ? `return (${code});` : code;
|
|
21
23
|
try {
|
|
22
|
-
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder,
|
|
24
|
+
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, flattenState(rootState, localState, rootSetState), context, event);
|
|
23
25
|
} catch (e) {
|
|
24
26
|
console.warn("Builder custom code error: \n While Evaluating: \n ", useCode, "\n", e);
|
|
25
27
|
}
|
|
26
28
|
}
|
|
29
|
+
function flattenState(rootState, localState, rootSetState) {
|
|
30
|
+
if (rootState === localState) {
|
|
31
|
+
throw new Error("rootState === localState");
|
|
32
|
+
}
|
|
33
|
+
return new Proxy(rootState, {
|
|
34
|
+
get: (_, prop) => {
|
|
35
|
+
if (localState && prop in localState) {
|
|
36
|
+
return localState[prop];
|
|
37
|
+
}
|
|
38
|
+
return rootState[prop];
|
|
39
|
+
},
|
|
40
|
+
set: (_, prop, value) => {
|
|
41
|
+
if (localState && prop in localState) {
|
|
42
|
+
throw new Error("Writing to local state is not allowed as it is read-only.");
|
|
43
|
+
}
|
|
44
|
+
rootState[prop] = value;
|
|
45
|
+
rootSetState == null ? void 0 : rootSetState(rootState);
|
|
46
|
+
return true;
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
}
|
|
27
50
|
export {
|
|
28
|
-
evaluate
|
|
51
|
+
evaluate,
|
|
52
|
+
flattenState
|
|
29
53
|
};
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { flattenState } from "./evaluate";
|
|
2
|
+
describe("flatten state", () => {
|
|
3
|
+
it("should behave normally when no PROTO_STATE", () => {
|
|
4
|
+
const localState = {};
|
|
5
|
+
const rootState = { foo: "bar" };
|
|
6
|
+
const flattened = flattenState(rootState, localState, void 0);
|
|
7
|
+
expect(flattened.foo).toEqual("bar");
|
|
8
|
+
flattened.foo = "baz";
|
|
9
|
+
expect(rootState.foo).toEqual("baz");
|
|
10
|
+
});
|
|
11
|
+
it("should shadow write ", () => {
|
|
12
|
+
const rootState = { foo: "foo" };
|
|
13
|
+
const localState = { foo: "baz" };
|
|
14
|
+
const flattened = flattenState(rootState, localState, void 0);
|
|
15
|
+
expect(() => flattened.foo = "bar").toThrow("Writing to local state is not allowed as it is read-only.");
|
|
16
|
+
});
|
|
17
|
+
});
|
|
@@ -2,7 +2,9 @@ import { evaluate } from "./evaluate.js";
|
|
|
2
2
|
const createEventHandler = (value, options) => (event) => evaluate({
|
|
3
3
|
code: value,
|
|
4
4
|
context: options.context,
|
|
5
|
-
|
|
5
|
+
localState: options.localState,
|
|
6
|
+
rootState: options.rootState,
|
|
7
|
+
rootSetState: options.rootSetState,
|
|
6
8
|
event,
|
|
7
9
|
isExpression: false
|
|
8
10
|
});
|
|
@@ -57,7 +57,7 @@ function getAllContent(options) {
|
|
|
57
57
|
const res = yield fetch(url.href);
|
|
58
58
|
const content = yield res.json();
|
|
59
59
|
if ("status" in content && !("results" in content)) {
|
|
60
|
-
logger.error("Error fetching data. ", content, options);
|
|
60
|
+
logger.error("Error fetching data. ", { url, content, options });
|
|
61
61
|
return content;
|
|
62
62
|
}
|
|
63
63
|
const canTrack = options.canTrack !== false;
|
|
@@ -24,7 +24,9 @@ import { transformBlock } from "./transform-block.js";
|
|
|
24
24
|
const evaluateBindings = ({
|
|
25
25
|
block,
|
|
26
26
|
context,
|
|
27
|
-
|
|
27
|
+
localState,
|
|
28
|
+
rootState,
|
|
29
|
+
rootSetState
|
|
28
30
|
}) => {
|
|
29
31
|
if (!block.bindings) {
|
|
30
32
|
return block;
|
|
@@ -36,7 +38,13 @@ const evaluateBindings = ({
|
|
|
36
38
|
});
|
|
37
39
|
for (const binding in block.bindings) {
|
|
38
40
|
const expression = block.bindings[binding];
|
|
39
|
-
const value = evaluate({
|
|
41
|
+
const value = evaluate({
|
|
42
|
+
code: expression,
|
|
43
|
+
localState,
|
|
44
|
+
rootState,
|
|
45
|
+
rootSetState,
|
|
46
|
+
context
|
|
47
|
+
});
|
|
40
48
|
set(copied, binding, value);
|
|
41
49
|
}
|
|
42
50
|
return copied;
|
|
@@ -45,11 +53,19 @@ function getProcessedBlock({
|
|
|
45
53
|
block,
|
|
46
54
|
context,
|
|
47
55
|
shouldEvaluateBindings,
|
|
48
|
-
|
|
56
|
+
localState,
|
|
57
|
+
rootState,
|
|
58
|
+
rootSetState
|
|
49
59
|
}) {
|
|
50
60
|
const transformedBlock = transformBlock(block);
|
|
51
61
|
if (shouldEvaluateBindings) {
|
|
52
|
-
return evaluateBindings({
|
|
62
|
+
return evaluateBindings({
|
|
63
|
+
block: transformedBlock,
|
|
64
|
+
localState,
|
|
65
|
+
rootState,
|
|
66
|
+
rootSetState,
|
|
67
|
+
context
|
|
68
|
+
});
|
|
53
69
|
} else {
|
|
54
70
|
return transformedBlock;
|
|
55
71
|
}
|
|
@@ -20,7 +20,9 @@ test("Can process bindings", () => {
|
|
|
20
20
|
const processed = getProcessedBlock({
|
|
21
21
|
block,
|
|
22
22
|
context: {},
|
|
23
|
-
|
|
23
|
+
rootState: { test: "hello" },
|
|
24
|
+
rootSetState: void 0,
|
|
25
|
+
localState: void 0,
|
|
24
26
|
shouldEvaluateBindings: true
|
|
25
27
|
});
|
|
26
28
|
expect(processed).not.toEqual(block);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { SDK_VERSION } from "../constants/sdk-version.js";
|
|
1
2
|
import { TARGET } from "../constants/target.js";
|
|
2
3
|
import { isBrowser } from "../functions/is-browser.js";
|
|
3
4
|
import { register } from "../functions/register.js";
|
|
@@ -31,6 +32,7 @@ const setupBrowserForEditing = (options = {}) => {
|
|
|
31
32
|
type: "builder.sdkInfo",
|
|
32
33
|
data: {
|
|
33
34
|
target: TARGET,
|
|
35
|
+
version: SDK_VERSION,
|
|
34
36
|
supportsPatchUpdates: false,
|
|
35
37
|
supportsAddBlockScoping: true,
|
|
36
38
|
supportsCustomBreakpoints: true
|