@builder.io/sdk-react-native 0.0.1-49 → 0.0.1-51
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 +11 -2
- package/package.json +1 -1
- package/src/blocks/button/button.js +31 -0
- package/src/blocks/{button.lite.tsx → button/button.lite.tsx} +3 -3
- package/src/blocks/button/component-info.js +42 -0
- package/src/blocks/columns/columns.js +59 -0
- package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +22 -21
- package/src/blocks/columns/component-info.js +218 -0
- package/src/blocks/custom-code/component-info.js +32 -0
- package/src/blocks/custom-code/custom-code.js +50 -0
- package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +11 -11
- package/src/blocks/embed/component-info.js +25 -0
- package/src/blocks/embed/embed.js +50 -0
- package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +11 -11
- package/src/blocks/form/component-info.js +263 -0
- package/src/blocks/form/form.js +221 -0
- package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +51 -50
- package/src/blocks/fragment/component-info.js +12 -0
- package/src/blocks/fragment/fragment.js +8 -0
- package/src/blocks/{fragment.lite.tsx → fragment/fragment.lite.tsx} +2 -2
- package/src/blocks/image/component-info.js +105 -0
- package/src/blocks/image/image.js +41 -0
- package/src/blocks/{image.lite.tsx → image/image.lite.tsx} +11 -11
- package/src/blocks/img/component-info.js +21 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/img/img.lite.tsx +18 -0
- package/src/blocks/input/component-info.js +75 -0
- package/src/blocks/input/input.js +36 -0
- package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +4 -4
- package/src/blocks/raw-text/component-info.js +17 -0
- package/src/blocks/raw-text/raw-text.js +10 -0
- package/src/blocks/raw-text/raw-text.lite.tsx +6 -0
- package/src/blocks/section/component-info.js +50 -0
- package/src/blocks/section/section.js +31 -0
- package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +3 -3
- package/src/blocks/select/component-info.js +60 -0
- package/src/blocks/select/select.js +36 -0
- package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +4 -4
- package/src/blocks/submit-button/component-info.js +29 -0
- package/src/blocks/submit-button/submit-button.js +29 -0
- package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +2 -2
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.js +68 -0
- package/src/blocks/symbol/symbol.lite.tsx +60 -0
- package/src/blocks/text/component-info.js +25 -0
- package/src/blocks/text/text.js +65 -0
- package/src/blocks/text/text.lite.tsx +6 -0
- package/src/blocks/textarea/component-info.js +48 -0
- package/src/blocks/textarea/textarea.js +32 -0
- package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +2 -2
- package/src/blocks/video/component-info.js +107 -0
- package/src/blocks/video/video.js +33 -0
- package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +5 -5
- package/src/components/error-boundary.js +9 -11
- package/src/components/error-boundary.lite.tsx +2 -2
- package/src/components/render-block/block-styles.js +29 -0
- package/src/components/render-block/block-styles.lite.tsx +35 -0
- package/src/components/render-block/render-block.helpers.js +24 -0
- package/src/components/render-block/render-block.js +116 -0
- package/src/components/render-block/render-block.lite.tsx +139 -0
- package/src/components/render-blocks.js +35 -61
- package/src/components/render-blocks.lite.tsx +11 -11
- package/src/components/render-content/components/render-styles.js +58 -0
- package/src/components/render-content/components/render-styles.lite.tsx +70 -0
- package/src/components/render-content/index.js +5 -0
- package/src/components/render-content/render-content.js +254 -0
- package/src/components/render-content/render-content.lite.tsx +283 -0
- package/src/components/render-inlined-styles.js +18 -0
- package/src/components/render-inlined-styles.lite.tsx +31 -0
- package/src/constants/builder-registered-components.js +27 -0
- package/src/constants/device-sizes.js +11 -8
- package/src/constants/target.js +5 -0
- package/src/context/builder.context.js +11 -3
- package/src/functions/evaluate.js +20 -20
- package/src/functions/event-handler-name.js +3 -1
- package/src/functions/fast-clone.js +5 -0
- package/src/functions/get-block-actions.js +17 -16
- package/src/functions/get-block-component-options.js +9 -16
- package/src/functions/get-block-properties.js +14 -18
- package/src/functions/get-block-styles.js +17 -34
- package/src/functions/get-block-tag.js +4 -2
- package/src/functions/get-builder-search-params/fn.test.js +6 -10
- package/src/functions/get-builder-search-params/index.js +6 -3
- package/src/functions/get-content/fn.test.js +15 -17
- package/src/functions/get-content/index.js +25 -42
- package/src/functions/get-fetch.js +32 -8
- package/src/functions/get-global-this.js +7 -5
- package/src/functions/get-processed-block.js +13 -17
- package/src/functions/get-processed-block.test.js +16 -27
- package/src/functions/if-target.js +14 -3
- package/src/functions/is-browser.js +4 -2
- package/src/functions/is-editing.js +5 -5
- package/src/functions/is-iframe.js +4 -2
- package/src/functions/is-previewing.js +6 -4
- package/src/functions/is-react-native.js +3 -1
- package/src/functions/macro-eval.js +5 -2
- package/src/functions/on-change.js +7 -4
- package/src/functions/on-change.test.js +9 -10
- package/src/functions/previewing-model-name.js +5 -3
- package/src/functions/register-component.js +33 -44
- package/src/functions/register.js +10 -8
- package/src/functions/set-editor-settings.js +7 -5
- package/src/functions/set.js +5 -14
- package/src/functions/set.test.js +13 -14
- package/src/functions/track.js +13 -7
- package/src/functions/transform-block.js +13 -17
- package/src/index-helpers/blocks-exports.js +9 -9
- package/src/index-helpers/top-of-file.js +1 -1
- package/src/index.js +10 -12
- package/src/scripts/init-editing.js +74 -88
- package/src/types/components.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/src/blocks/button.js +0 -86
- package/src/blocks/columns.js +0 -293
- package/src/blocks/custom-code.js +0 -83
- package/src/blocks/embed.js +0 -77
- package/src/blocks/form.js +0 -521
- package/src/blocks/fragment.js +0 -21
- package/src/blocks/image.js +0 -165
- package/src/blocks/img.js +0 -64
- package/src/blocks/img.lite.tsx +0 -18
- package/src/blocks/input.js +0 -113
- package/src/blocks/raw-text.js +0 -17
- package/src/blocks/raw-text.lite.tsx +0 -6
- package/src/blocks/section.js +0 -84
- package/src/blocks/select.js +0 -91
- package/src/blocks/submit-button.js +0 -60
- package/src/blocks/symbol.js +0 -20
- package/src/blocks/symbol.lite.tsx +0 -20
- package/src/blocks/text.js +0 -100
- package/src/blocks/text.lite.tsx +0 -6
- package/src/blocks/textarea.js +0 -73
- package/src/blocks/video.js +0 -100
- package/src/components/block-styles.js +0 -5
- package/src/components/block-styles.lite.tsx +0 -6
- package/src/components/render-block.js +0 -164
- package/src/components/render-block.lite.tsx +0 -132
- package/src/components/render-content.js +0 -220
- package/src/components/render-content.lite.tsx +0 -206
- package/src/functions/get-target.js +0 -5
|
@@ -0,0 +1,283 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import { useState, useContext, useEffect } from "react";
|
|
4
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
5
|
+
import { TARGET } from "../../constants/target.js";
|
|
6
|
+
import BuilderContext from "../../context/builder.context";
|
|
7
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
8
|
+
import {
|
|
9
|
+
convertSearchParamsToQueryObject,
|
|
10
|
+
getBuilderSearchParams,
|
|
11
|
+
} from "../../functions/get-builder-search-params/index.js";
|
|
12
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
13
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
14
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
15
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
16
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
17
|
+
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
18
|
+
import {
|
|
19
|
+
components,
|
|
20
|
+
createRegisterComponentMessage,
|
|
21
|
+
} from "../../functions/register-component.js";
|
|
22
|
+
import { track } from "../../functions/track.js";
|
|
23
|
+
import RenderBlocks from "../render-blocks.lite";
|
|
24
|
+
import RenderContentStyles from "./components/render-styles.lite";
|
|
25
|
+
|
|
26
|
+
export default function RenderContent(props) {
|
|
27
|
+
function useContent() {
|
|
28
|
+
const mergedContent = {
|
|
29
|
+
...props.content,
|
|
30
|
+
...overrideContent,
|
|
31
|
+
data: { ...props.content?.data, ...props.data, ...overrideContent?.data },
|
|
32
|
+
};
|
|
33
|
+
return mergedContent;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
37
|
+
|
|
38
|
+
const [update, setUpdate] = useState(() => 0);
|
|
39
|
+
|
|
40
|
+
const [overrideState, setOverrideState] = useState(() => ({}));
|
|
41
|
+
|
|
42
|
+
function contentState() {
|
|
43
|
+
return { ...props.content?.data?.state, ...props.data, ...overrideState };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function context() {
|
|
47
|
+
return {};
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
function allRegisteredComponents() {
|
|
51
|
+
const allComponentsArray = [
|
|
52
|
+
...getDefaultRegisteredComponents(), // While this `components` object is deprecated, we must maintain support for it.
|
|
53
|
+
// Since users are able to override our default components, we need to make sure that we do not break such
|
|
54
|
+
// existing usage.
|
|
55
|
+
// This is why we spread `components` after the default Builder.io components, but before the `props.customComponents`,
|
|
56
|
+
// which is the new standard way of providing custom components, and must therefore take precedence.
|
|
57
|
+
...components,
|
|
58
|
+
...(props.customComponents || []),
|
|
59
|
+
];
|
|
60
|
+
const allComponents = allComponentsArray.reduce(
|
|
61
|
+
(acc, curr) => ({ ...acc, [curr.info.name]: curr }),
|
|
62
|
+
{}
|
|
63
|
+
);
|
|
64
|
+
return allComponents;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
function processMessage(event) {
|
|
68
|
+
const { data } = event;
|
|
69
|
+
|
|
70
|
+
if (data) {
|
|
71
|
+
switch (data.type) {
|
|
72
|
+
case "builder.contentUpdate": {
|
|
73
|
+
const messageContent = data.data;
|
|
74
|
+
const key =
|
|
75
|
+
messageContent.key ||
|
|
76
|
+
messageContent.alias ||
|
|
77
|
+
messageContent.entry ||
|
|
78
|
+
messageContent.modelName;
|
|
79
|
+
const contentData = messageContent.data;
|
|
80
|
+
|
|
81
|
+
if (key === props.model) {
|
|
82
|
+
setOverrideContent(contentData);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
break;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
case "builder.patchUpdates": {
|
|
89
|
+
// TODO
|
|
90
|
+
break;
|
|
91
|
+
}
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
function evaluateJsCode() {
|
|
97
|
+
// run any dynamic JS code attached to content
|
|
98
|
+
const jsCode = useContent?.()?.data?.jsCode;
|
|
99
|
+
|
|
100
|
+
if (jsCode) {
|
|
101
|
+
evaluate({
|
|
102
|
+
code: jsCode,
|
|
103
|
+
context: context(),
|
|
104
|
+
state: contentState(),
|
|
105
|
+
});
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
function httpReqsData() {
|
|
110
|
+
return {};
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
function evalExpression(expression) {
|
|
114
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
|
|
115
|
+
evaluate({
|
|
116
|
+
code: group,
|
|
117
|
+
context: context(),
|
|
118
|
+
state: contentState(),
|
|
119
|
+
})
|
|
120
|
+
);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function handleRequest({ url, key }) {
|
|
124
|
+
const fetchAndSetState = async () => {
|
|
125
|
+
const fetch = await getFetch();
|
|
126
|
+
const response = await fetch(url);
|
|
127
|
+
const json = await response.json();
|
|
128
|
+
const newOverrideState = { ...overrideState, [key]: json };
|
|
129
|
+
setOverrideState(newOverrideState);
|
|
130
|
+
};
|
|
131
|
+
|
|
132
|
+
fetchAndSetState();
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
function runHttpRequests() {
|
|
136
|
+
const requests = useContent?.()?.data?.httpRequests ?? {};
|
|
137
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
138
|
+
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
139
|
+
const evaluatedUrl = evalExpression(url);
|
|
140
|
+
handleRequest({
|
|
141
|
+
url: evaluatedUrl,
|
|
142
|
+
key,
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
function emitStateUpdate() {
|
|
149
|
+
if (isEditing()) {
|
|
150
|
+
window.dispatchEvent(
|
|
151
|
+
new CustomEvent("builder:component:stateChange", {
|
|
152
|
+
detail: {
|
|
153
|
+
state: contentState(),
|
|
154
|
+
ref: {
|
|
155
|
+
name: props.model,
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
useEffect(() => {
|
|
164
|
+
if (isBrowser()) {
|
|
165
|
+
if (isEditing()) {
|
|
166
|
+
Object.values(allRegisteredComponents()).forEach(
|
|
167
|
+
(registeredComponent) => {
|
|
168
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
169
|
+
window.parent?.postMessage(message, "*");
|
|
170
|
+
}
|
|
171
|
+
);
|
|
172
|
+
window.addEventListener("message", processMessage);
|
|
173
|
+
window.addEventListener(
|
|
174
|
+
"builder:component:stateChangeListenerActivated",
|
|
175
|
+
emitStateUpdate
|
|
176
|
+
);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
if (useContent()) {
|
|
180
|
+
track("impression", {
|
|
181
|
+
contentId: useContent().id,
|
|
182
|
+
});
|
|
183
|
+
} // override normal content in preview mode
|
|
184
|
+
|
|
185
|
+
if (isPreviewing()) {
|
|
186
|
+
if (props.model && previewingModelName() === props.model) {
|
|
187
|
+
const currentUrl = new URL(location.href);
|
|
188
|
+
const previewApiKey = currentUrl.searchParams.get("apiKey");
|
|
189
|
+
|
|
190
|
+
if (previewApiKey) {
|
|
191
|
+
getContent({
|
|
192
|
+
model: props.model,
|
|
193
|
+
apiKey: previewApiKey,
|
|
194
|
+
options: getBuilderSearchParams(
|
|
195
|
+
convertSearchParamsToQueryObject(currentUrl.searchParams)
|
|
196
|
+
),
|
|
197
|
+
}).then((content) => {
|
|
198
|
+
if (content) {
|
|
199
|
+
setOverrideContent(content);
|
|
200
|
+
}
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
evaluateJsCode();
|
|
207
|
+
runHttpRequests();
|
|
208
|
+
emitStateUpdate();
|
|
209
|
+
}
|
|
210
|
+
}, []);
|
|
211
|
+
|
|
212
|
+
useEffect(() => {
|
|
213
|
+
evaluateJsCode();
|
|
214
|
+
}, [useContent?.()?.data?.jsCode]);
|
|
215
|
+
useEffect(() => {
|
|
216
|
+
runHttpRequests();
|
|
217
|
+
}, [useContent?.()?.data?.httpRequests]);
|
|
218
|
+
useEffect(() => {
|
|
219
|
+
emitStateUpdate();
|
|
220
|
+
}, [contentState()]);
|
|
221
|
+
|
|
222
|
+
useEffect(() => {
|
|
223
|
+
return () => {
|
|
224
|
+
if (isBrowser()) {
|
|
225
|
+
window.removeEventListener("message", processMessage);
|
|
226
|
+
window.removeEventListener(
|
|
227
|
+
"builder:component:stateChangeListenerActivated",
|
|
228
|
+
emitStateUpdate
|
|
229
|
+
);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
}, []);
|
|
233
|
+
|
|
234
|
+
return (
|
|
235
|
+
<BuilderContext.Provider
|
|
236
|
+
value={{
|
|
237
|
+
get content() {
|
|
238
|
+
return useContent();
|
|
239
|
+
},
|
|
240
|
+
|
|
241
|
+
get state() {
|
|
242
|
+
return contentState();
|
|
243
|
+
},
|
|
244
|
+
|
|
245
|
+
get context() {
|
|
246
|
+
return context();
|
|
247
|
+
},
|
|
248
|
+
|
|
249
|
+
get apiKey() {
|
|
250
|
+
return props.apiKey;
|
|
251
|
+
},
|
|
252
|
+
|
|
253
|
+
get registeredComponents() {
|
|
254
|
+
return allRegisteredComponents();
|
|
255
|
+
},
|
|
256
|
+
}}
|
|
257
|
+
>
|
|
258
|
+
{useContent() ? (
|
|
259
|
+
<>
|
|
260
|
+
<View
|
|
261
|
+
onClick={(event) =>
|
|
262
|
+
track("click", {
|
|
263
|
+
contentId: useContent().id,
|
|
264
|
+
})
|
|
265
|
+
}
|
|
266
|
+
data-builder-content-id={useContent?.()?.id}
|
|
267
|
+
>
|
|
268
|
+
{(useContent?.()?.data?.cssCode ||
|
|
269
|
+
useContent?.()?.data?.customFonts?.length) &&
|
|
270
|
+
TARGET !== "reactNative" ? (
|
|
271
|
+
<RenderContentStyles
|
|
272
|
+
cssCode={useContent().data.cssCode}
|
|
273
|
+
customFonts={useContent().data.customFonts}
|
|
274
|
+
/>
|
|
275
|
+
) : null}
|
|
276
|
+
|
|
277
|
+
<RenderBlocks blocks={useContent?.()?.data?.blocks} />
|
|
278
|
+
</View>
|
|
279
|
+
</>
|
|
280
|
+
) : null}
|
|
281
|
+
</BuilderContext.Provider>
|
|
282
|
+
);
|
|
283
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, Text } from "react-native";
|
|
3
|
+
import { TARGET } from "../constants/target.js";
|
|
4
|
+
function RenderInlinedStyles(props) {
|
|
5
|
+
function injectedStyleScript() {
|
|
6
|
+
return `<${tagName()}>${props.styles}</${tagName()}>`;
|
|
7
|
+
}
|
|
8
|
+
function tagName() {
|
|
9
|
+
return "style";
|
|
10
|
+
}
|
|
11
|
+
const TagNameRef = tagName();
|
|
12
|
+
return /* @__PURE__ */ React.createElement(React.Fragment, null, TARGET === "svelte" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
13
|
+
dangerouslySetInnerHTML: { __html: injectedStyleScript() }
|
|
14
|
+
})) : /* @__PURE__ */ React.createElement(TagNameRef, null, /* @__PURE__ */ React.createElement(Text, null, props.styles)));
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
RenderInlinedStyles as default
|
|
18
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import { TARGET } from "../constants/target.js";
|
|
4
|
+
|
|
5
|
+
export default function RenderInlinedStyles(props) {
|
|
6
|
+
function injectedStyleScript() {
|
|
7
|
+
return `<${tagName()}>${props.styles}</${tagName()}>`;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
function tagName() {
|
|
11
|
+
// NOTE: we have to obfusctate the name of the tag due to a limitation in the svelte-preprocessor plugin.
|
|
12
|
+
// https://github.com/sveltejs/vite-plugin-svelte/issues/315#issuecomment-1109000027
|
|
13
|
+
return "sty" + "le";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const TagNameRef = tagName();
|
|
17
|
+
|
|
18
|
+
return (
|
|
19
|
+
<>
|
|
20
|
+
{TARGET === "svelte" ? (
|
|
21
|
+
<>
|
|
22
|
+
<View dangerouslySetInnerHTML={{ __html: injectedStyleScript() }} />
|
|
23
|
+
</>
|
|
24
|
+
) : (
|
|
25
|
+
<TagNameRef>
|
|
26
|
+
<Text>{props.styles}</Text>
|
|
27
|
+
</TagNameRef>
|
|
28
|
+
)}
|
|
29
|
+
</>
|
|
30
|
+
);
|
|
31
|
+
}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { default as Button } from "../blocks/button/button.js";
|
|
3
|
+
import { componentInfo as buttonComponentInfo } from "../blocks/button/component-info";
|
|
4
|
+
import { default as Columns } from "../blocks/columns/columns.js";
|
|
5
|
+
import { componentInfo as columnsComponentInfo } from "../blocks/columns/component-info";
|
|
6
|
+
import { componentInfo as fragmentComponentInfo } from "../blocks/fragment/component-info";
|
|
7
|
+
import { default as Fragment } from "../blocks/fragment/fragment.js";
|
|
8
|
+
import { componentInfo as imageComponentInfo } from "../blocks/image/component-info";
|
|
9
|
+
import { default as Image } from "../blocks/image/image.js";
|
|
10
|
+
import { componentInfo as sectionComponentInfo } from "../blocks/section/component-info";
|
|
11
|
+
import { default as Section } from "../blocks/section/section.js";
|
|
12
|
+
import { componentInfo as symbolComponentInfo } from "../blocks/symbol/component-info";
|
|
13
|
+
import { default as Symbol } from "../blocks/symbol/symbol.js";
|
|
14
|
+
import { componentInfo as textComponentInfo } from "../blocks/text/component-info";
|
|
15
|
+
import { default as Text } from "../blocks/text/text.js";
|
|
16
|
+
const getDefaultRegisteredComponents = () => [
|
|
17
|
+
{ component: Columns, info: columnsComponentInfo },
|
|
18
|
+
{ component: Image, info: imageComponentInfo },
|
|
19
|
+
{ component: Text, info: textComponentInfo },
|
|
20
|
+
{ component: Symbol, info: symbolComponentInfo },
|
|
21
|
+
{ component: Button, info: buttonComponentInfo },
|
|
22
|
+
{ component: Section, info: sectionComponentInfo },
|
|
23
|
+
{ component: Fragment, info: fragmentComponentInfo }
|
|
24
|
+
];
|
|
25
|
+
export {
|
|
26
|
+
getDefaultRegisteredComponents
|
|
27
|
+
};
|
|
@@ -1,25 +1,25 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
const sizeNames = [
|
|
2
|
+
const sizeNames = ["xsmall", "small", "medium", "large"];
|
|
3
3
|
const sizes = {
|
|
4
4
|
xsmall: {
|
|
5
5
|
min: 0,
|
|
6
6
|
default: 0,
|
|
7
|
-
max: 0
|
|
7
|
+
max: 0
|
|
8
8
|
},
|
|
9
9
|
small: {
|
|
10
10
|
min: 320,
|
|
11
11
|
default: 321,
|
|
12
|
-
max: 640
|
|
12
|
+
max: 640
|
|
13
13
|
},
|
|
14
14
|
medium: {
|
|
15
15
|
min: 641,
|
|
16
16
|
default: 642,
|
|
17
|
-
max: 991
|
|
17
|
+
max: 991
|
|
18
18
|
},
|
|
19
19
|
large: {
|
|
20
20
|
min: 990,
|
|
21
21
|
default: 991,
|
|
22
|
-
max: 1200
|
|
22
|
+
max: 1200
|
|
23
23
|
},
|
|
24
24
|
getWidthForSize(size) {
|
|
25
25
|
return this[size].default;
|
|
@@ -31,7 +31,10 @@ const sizes = {
|
|
|
31
31
|
return size;
|
|
32
32
|
}
|
|
33
33
|
}
|
|
34
|
-
return
|
|
35
|
-
}
|
|
34
|
+
return "large";
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
export {
|
|
38
|
+
sizeNames,
|
|
39
|
+
sizes
|
|
36
40
|
};
|
|
37
|
-
export { sizeNames, sizes };
|
|
@@ -1,3 +1,11 @@
|
|
|
1
|
-
import { createContext } from
|
|
2
|
-
var stdin_default = createContext({
|
|
3
|
-
|
|
1
|
+
import { createContext } from "react";
|
|
2
|
+
var stdin_default = createContext({
|
|
3
|
+
content: null,
|
|
4
|
+
context: {},
|
|
5
|
+
state: {},
|
|
6
|
+
apiKey: null,
|
|
7
|
+
registeredComponents: {}
|
|
8
|
+
});
|
|
9
|
+
export {
|
|
10
|
+
stdin_default as default
|
|
11
|
+
};
|
|
@@ -1,29 +1,29 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { isBrowser } from
|
|
3
|
-
import { isEditing } from
|
|
4
|
-
function evaluate(
|
|
5
|
-
|
|
2
|
+
import { isBrowser } from "./is-browser.js";
|
|
3
|
+
import { isEditing } from "./is-editing.js";
|
|
4
|
+
function evaluate({
|
|
5
|
+
code,
|
|
6
|
+
context,
|
|
7
|
+
state,
|
|
8
|
+
event
|
|
9
|
+
}) {
|
|
10
|
+
if (code === "") {
|
|
11
|
+
console.warn("Skipping evaluation of empty code block.");
|
|
12
|
+
return;
|
|
13
|
+
}
|
|
6
14
|
const builder = {
|
|
7
15
|
isEditing: isEditing(),
|
|
8
16
|
isBrowser: isBrowser(),
|
|
17
|
+
isServer: !isBrowser()
|
|
9
18
|
};
|
|
10
|
-
const useReturn = !(
|
|
11
|
-
|
|
12
|
-
code.includes(' return ') ||
|
|
13
|
-
code.trim().startsWith('return ')
|
|
14
|
-
);
|
|
15
|
-
const useCode = `${useReturn ? `return (${code});` : code}`;
|
|
19
|
+
const useReturn = !(code.includes(";") || code.includes(" return ") || code.trim().startsWith("return "));
|
|
20
|
+
const useCode = useReturn ? `return (${code});` : code;
|
|
16
21
|
try {
|
|
17
|
-
return new Function(
|
|
18
|
-
'builder',
|
|
19
|
-
'Builder',
|
|
20
|
-
'state',
|
|
21
|
-
'context',
|
|
22
|
-
'event',
|
|
23
|
-
useCode
|
|
24
|
-
)(builder, builder, options.state, options.context, options.event);
|
|
22
|
+
return new Function("builder", "Builder", "state", "context", "event", useCode)(builder, builder, state, context, event);
|
|
25
23
|
} catch (e) {
|
|
26
|
-
console.warn(
|
|
24
|
+
console.warn("Builder custom code error: ", e);
|
|
27
25
|
}
|
|
28
26
|
}
|
|
29
|
-
export {
|
|
27
|
+
export {
|
|
28
|
+
evaluate
|
|
29
|
+
};
|
|
@@ -1,23 +1,24 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { evaluate } from
|
|
3
|
-
import { getEventHandlerName } from
|
|
2
|
+
import { evaluate } from "./evaluate.js";
|
|
3
|
+
import { getEventHandlerName } from "./event-handler-name.js";
|
|
4
4
|
function getBlockActions(options) {
|
|
5
|
+
var _a;
|
|
5
6
|
const obj = {};
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
const value = options.block.actions[key];
|
|
12
|
-
obj[getEventHandlerName(key)] = (event) =>
|
|
13
|
-
evaluate({
|
|
14
|
-
code: value,
|
|
15
|
-
context: options.context,
|
|
16
|
-
state: options.state,
|
|
17
|
-
event,
|
|
18
|
-
});
|
|
7
|
+
const optionActions = (_a = options.block.actions) != null ? _a : {};
|
|
8
|
+
for (const key in optionActions) {
|
|
9
|
+
if (!optionActions.hasOwnProperty(key)) {
|
|
10
|
+
continue;
|
|
19
11
|
}
|
|
12
|
+
const value = optionActions[key];
|
|
13
|
+
obj[getEventHandlerName(key)] = (event) => evaluate({
|
|
14
|
+
code: value,
|
|
15
|
+
context: options.context,
|
|
16
|
+
state: options.state,
|
|
17
|
+
event
|
|
18
|
+
});
|
|
20
19
|
}
|
|
21
20
|
return obj;
|
|
22
21
|
}
|
|
23
|
-
export {
|
|
22
|
+
export {
|
|
23
|
+
getBlockActions
|
|
24
|
+
};
|
|
@@ -3,29 +3,22 @@ var __defProp = Object.defineProperty;
|
|
|
3
3
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
4
4
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
5
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
6
|
-
var __defNormalProp = (obj, key, value) =>
|
|
7
|
-
key in obj
|
|
8
|
-
? __defProp(obj, key, {
|
|
9
|
-
enumerable: true,
|
|
10
|
-
configurable: true,
|
|
11
|
-
writable: true,
|
|
12
|
-
value,
|
|
13
|
-
})
|
|
14
|
-
: (obj[key] = value);
|
|
6
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
15
7
|
var __spreadValues = (a, b) => {
|
|
16
8
|
for (var prop in b || (b = {}))
|
|
17
|
-
if (__hasOwnProp.call(b, prop))
|
|
9
|
+
if (__hasOwnProp.call(b, prop))
|
|
10
|
+
__defNormalProp(a, prop, b[prop]);
|
|
18
11
|
if (__getOwnPropSymbols)
|
|
19
12
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
20
|
-
if (__propIsEnum.call(b, prop))
|
|
13
|
+
if (__propIsEnum.call(b, prop))
|
|
14
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
15
|
}
|
|
22
16
|
return a;
|
|
23
17
|
};
|
|
24
18
|
function getBlockComponentOptions(block) {
|
|
25
19
|
var _a;
|
|
26
|
-
return __spreadValues(
|
|
27
|
-
__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options),
|
|
28
|
-
block.options
|
|
29
|
-
);
|
|
20
|
+
return __spreadValues(__spreadValues({}, (_a = block.component) == null ? void 0 : _a.options), block.options);
|
|
30
21
|
}
|
|
31
|
-
export {
|
|
22
|
+
export {
|
|
23
|
+
getBlockComponentOptions
|
|
24
|
+
};
|
|
@@ -5,42 +5,38 @@ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
|
5
5
|
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
6
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
7
|
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
8
|
-
var __defNormalProp = (obj, key, value) =>
|
|
9
|
-
key in obj
|
|
10
|
-
? __defProp(obj, key, {
|
|
11
|
-
enumerable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
writable: true,
|
|
14
|
-
value,
|
|
15
|
-
})
|
|
16
|
-
: (obj[key] = value);
|
|
8
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
17
9
|
var __spreadValues = (a, b) => {
|
|
18
10
|
for (var prop in b || (b = {}))
|
|
19
|
-
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
if (__hasOwnProp.call(b, prop))
|
|
12
|
+
__defNormalProp(a, prop, b[prop]);
|
|
20
13
|
if (__getOwnPropSymbols)
|
|
21
14
|
for (var prop of __getOwnPropSymbols(b)) {
|
|
22
|
-
if (__propIsEnum.call(b, prop))
|
|
15
|
+
if (__propIsEnum.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
23
17
|
}
|
|
24
18
|
return a;
|
|
25
19
|
};
|
|
26
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
27
|
-
import {
|
|
28
|
-
import {
|
|
21
|
+
import { isEditing } from "./is-editing";
|
|
22
|
+
import { findDOMNode } from "react-dom";
|
|
29
23
|
function getBlockProperties(block) {
|
|
30
24
|
return __spreadProps(__spreadValues({}, block.properties), {
|
|
31
25
|
ref: (ref) => {
|
|
32
26
|
if (isEditing()) {
|
|
33
27
|
const el = findDOMNode(ref);
|
|
34
28
|
if (el) {
|
|
35
|
-
el.setAttribute(
|
|
29
|
+
el.setAttribute("builder-id", block.id);
|
|
36
30
|
el.classList.add(block.id);
|
|
37
31
|
}
|
|
38
32
|
}
|
|
39
33
|
},
|
|
40
34
|
dataSet: {
|
|
41
|
-
|
|
42
|
-
class: [block.id,
|
|
43
|
-
}
|
|
35
|
+
"builder-id": block.id,
|
|
36
|
+
class: [block.id, "builder-block", block.class].filter(Boolean).join(" ")
|
|
37
|
+
}
|
|
44
38
|
});
|
|
45
39
|
}
|
|
46
|
-
export {
|
|
40
|
+
export {
|
|
41
|
+
getBlockProperties
|
|
42
|
+
};
|