@builder.io/sdk-react-native 0.0.1-50 → 0.0.1-53
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 +14 -0
- package/package.json +1 -1
- package/src/blocks/button/button.js +31 -0
- package/src/blocks/{button.lite.tsx → button/button.lite.tsx} +0 -0
- 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} +5 -4
- 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} +1 -1
- 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} +1 -1
- 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} +8 -7
- 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} +0 -0
- package/src/blocks/{image.js → image/component-info.js} +4 -42
- package/src/blocks/image/image.js +41 -0
- package/src/blocks/{image.lite.tsx → image/image.lite.tsx} +1 -1
- package/src/blocks/img/component-info.js +21 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/{img.lite.tsx → img/img.lite.tsx} +1 -1
- 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} +1 -1
- 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.lite.tsx → raw-text/raw-text.lite.tsx} +1 -1
- 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} +0 -0
- 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} +2 -2
- 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} +0 -0
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.js +68 -0
- package/src/blocks/{symbol.lite.tsx → symbol/symbol.lite.tsx} +7 -7
- package/src/blocks/text/component-info.js +25 -0
- package/src/blocks/{text.js → text/text.js} +0 -22
- package/src/blocks/{text.lite.tsx → text/text.lite.tsx} +1 -1
- 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} +0 -0
- package/src/blocks/{video.js → video/component-info.js} +52 -40
- package/src/blocks/video/video.js +33 -0
- package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +0 -0
- 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.js → render-block/render-block.js} +28 -20
- package/src/components/{render-block.lite.tsx → render-block/render-block.lite.tsx} +43 -31
- package/src/components/render-blocks.js +3 -3
- package/src/components/render-blocks.lite.tsx +3 -3
- 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.js → render-content/render-content.js} +57 -69
- package/src/components/{render-content.lite.tsx → render-content/render-content.lite.tsx} +67 -92
- 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/target.js +5 -0
- package/src/context/builder.context.js +2 -1
- package/src/functions/evaluate.js +2 -2
- package/src/functions/fast-clone.js +5 -0
- package/src/functions/get-block-actions.js +2 -2
- package/src/functions/get-block-properties.js +1 -1
- package/src/functions/get-builder-search-params/fn.test.js +1 -1
- package/src/functions/get-content/index.js +3 -2
- package/src/functions/get-fetch.js +29 -7
- package/src/functions/get-processed-block.js +3 -3
- package/src/functions/get-processed-block.test.js +1 -1
- package/src/functions/if-target.js +11 -2
- package/src/functions/is-editing.js +1 -1
- package/src/functions/is-iframe.js +1 -1
- package/src/functions/is-previewing.js +2 -2
- package/src/functions/on-change.test.js +1 -1
- package/src/functions/previewing-model-name.js +1 -1
- package/src/functions/register-component.js +30 -13
- package/src/functions/register.js +1 -1
- package/src/functions/set-editor-settings.js +1 -1
- package/src/functions/set.test.js +1 -1
- package/src/functions/track.js +4 -4
- package/src/index-helpers/blocks-exports.js +8 -8
- package/src/index.js +10 -13
- package/src/scripts/init-editing.js +72 -62
- package/src/types/components.js +1 -0
- package/src/types/element.js +1 -0
- package/src/types/targets.js +1 -0
- package/src/blocks/button.js +0 -36
- package/src/blocks/columns.js +0 -63
- package/src/blocks/custom-code.js +0 -55
- package/src/blocks/embed.js +0 -55
- package/src/blocks/form.js +0 -225
- package/src/blocks/fragment.js +0 -13
- package/src/blocks/img.js +0 -41
- package/src/blocks/input.js +0 -41
- package/src/blocks/raw-text.js +0 -15
- package/src/blocks/section.js +0 -36
- package/src/blocks/select.js +0 -41
- package/src/blocks/submit-button.js +0 -34
- package/src/blocks/symbol.js +0 -73
- package/src/blocks/textarea.js +0 -37
- package/src/components/block-styles.js +0 -7
- package/src/components/block-styles.lite.tsx +0 -6
- package/src/functions/get-target.js +0 -7
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
|
+
import RenderInlinedStyles from "../../render-inlined-styles.lite";
|
|
4
|
+
|
|
5
|
+
export default function RenderContentStyles(props) {
|
|
6
|
+
function getCssFromFont(font) {
|
|
7
|
+
// TODO: compute what font sizes are used and only load those.......
|
|
8
|
+
const family =
|
|
9
|
+
font.family +
|
|
10
|
+
(font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
11
|
+
const name = family.split(",")[0];
|
|
12
|
+
const url = font.fileUrl ?? font?.files?.regular;
|
|
13
|
+
let str = "";
|
|
14
|
+
|
|
15
|
+
if (url && family && name) {
|
|
16
|
+
str += `
|
|
17
|
+
@font-face {
|
|
18
|
+
font-family: "${family}";
|
|
19
|
+
src: local("${name}"), url('${url}') format('woff2');
|
|
20
|
+
font-display: fallback;
|
|
21
|
+
font-weight: 400;
|
|
22
|
+
}
|
|
23
|
+
`.trim();
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
if (font.files) {
|
|
27
|
+
for (const weight in font.files) {
|
|
28
|
+
const isNumber = String(Number(weight)) === weight;
|
|
29
|
+
|
|
30
|
+
if (!isNumber) {
|
|
31
|
+
continue;
|
|
32
|
+
} // TODO: maybe limit number loaded
|
|
33
|
+
|
|
34
|
+
const weightUrl = font.files[weight];
|
|
35
|
+
|
|
36
|
+
if (weightUrl && weightUrl !== url) {
|
|
37
|
+
str += `
|
|
38
|
+
@font-face {
|
|
39
|
+
font-family: "${family}";
|
|
40
|
+
src: url('${weightUrl}') format('woff2');
|
|
41
|
+
font-display: fallback;
|
|
42
|
+
font-weight: ${weight};
|
|
43
|
+
}
|
|
44
|
+
`.trim();
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
return str;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
function getFontCss({ customFonts }) {
|
|
53
|
+
// TODO: flag for this
|
|
54
|
+
// if (!builder.allowCustomFonts) {
|
|
55
|
+
// return '';
|
|
56
|
+
// }
|
|
57
|
+
// TODO: separate internal data from external
|
|
58
|
+
return customFonts?.map((font) => getCssFromFont(font))?.join(" ") || "";
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function injectedStyles() {
|
|
62
|
+
return `
|
|
63
|
+
${props.cssCode || ""}
|
|
64
|
+
${getFontCss({
|
|
65
|
+
customFonts: props.customFonts,
|
|
66
|
+
})}`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return <RenderInlinedStyles styles={injectedStyles()} />;
|
|
70
|
+
}
|
|
@@ -38,82 +38,56 @@ var __async = (__this, __arguments, generator) => {
|
|
|
38
38
|
});
|
|
39
39
|
};
|
|
40
40
|
import * as React from "react";
|
|
41
|
-
import { View
|
|
41
|
+
import { View } from "react-native";
|
|
42
42
|
import { useState, useEffect } from "react";
|
|
43
|
-
import {
|
|
44
|
-
import
|
|
45
|
-
import
|
|
46
|
-
import {
|
|
47
|
-
import { isEditing } from "../functions/is-editing";
|
|
48
|
-
import { isPreviewing } from "../functions/is-previewing";
|
|
49
|
-
import { previewingModelName } from "../functions/previewing-model-name";
|
|
50
|
-
import { getContent } from "../functions/get-content";
|
|
43
|
+
import { getDefaultRegisteredComponents } from "../../constants/builder-registered-components.js";
|
|
44
|
+
import { TARGET } from "../../constants/target.js";
|
|
45
|
+
import BuilderContext from "../../context/builder.context";
|
|
46
|
+
import { evaluate } from "../../functions/evaluate.js";
|
|
51
47
|
import {
|
|
52
48
|
convertSearchParamsToQueryObject,
|
|
53
49
|
getBuilderSearchParams
|
|
54
|
-
} from "
|
|
55
|
-
import
|
|
56
|
-
import {
|
|
57
|
-
import {
|
|
50
|
+
} from "../../functions/get-builder-search-params/index.js";
|
|
51
|
+
import { getContent } from "../../functions/get-content/index.js";
|
|
52
|
+
import { getFetch } from "../../functions/get-fetch.js";
|
|
53
|
+
import { isBrowser } from "../../functions/is-browser.js";
|
|
54
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
55
|
+
import { isPreviewing } from "../../functions/is-previewing.js";
|
|
56
|
+
import { previewingModelName } from "../../functions/previewing-model-name.js";
|
|
57
|
+
import {
|
|
58
|
+
components,
|
|
59
|
+
createRegisterComponentMessage
|
|
60
|
+
} from "../../functions/register-component.js";
|
|
61
|
+
import { track } from "../../functions/track.js";
|
|
62
|
+
import RenderBlocks from "../render-blocks.js";
|
|
63
|
+
import RenderContentStyles from "./components/render-styles.js";
|
|
58
64
|
function RenderContent(props) {
|
|
59
65
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
60
66
|
function useContent() {
|
|
61
67
|
var _a2;
|
|
62
68
|
const mergedContent = __spreadProps(__spreadValues(__spreadValues({}, props.content), overrideContent), {
|
|
63
|
-
data: __spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), overrideContent == null ? void 0 : overrideContent.data)
|
|
69
|
+
data: __spreadValues(__spreadValues(__spreadValues({}, (_a2 = props.content) == null ? void 0 : _a2.data), props.data), overrideContent == null ? void 0 : overrideContent.data)
|
|
64
70
|
});
|
|
65
71
|
return mergedContent;
|
|
66
72
|
}
|
|
67
73
|
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
68
74
|
const [update, setUpdate] = useState(() => 0);
|
|
69
75
|
const [overrideState, setOverrideState] = useState(() => ({}));
|
|
70
|
-
function
|
|
76
|
+
function contentState() {
|
|
71
77
|
var _a2, _b2;
|
|
72
|
-
return __spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), overrideState);
|
|
78
|
+
return __spreadValues(__spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), props.data), overrideState);
|
|
73
79
|
}
|
|
74
80
|
function context() {
|
|
75
81
|
return {};
|
|
76
82
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
@font-face {
|
|
86
|
-
font-family: "${family}";
|
|
87
|
-
src: local("${name}"), url('${url}') format('woff2');
|
|
88
|
-
font-display: fallback;
|
|
89
|
-
font-weight: 400;
|
|
90
|
-
}
|
|
91
|
-
`.trim();
|
|
92
|
-
}
|
|
93
|
-
if (font.files) {
|
|
94
|
-
for (const weight in font.files) {
|
|
95
|
-
const isNumber = String(Number(weight)) === weight;
|
|
96
|
-
if (!isNumber) {
|
|
97
|
-
continue;
|
|
98
|
-
}
|
|
99
|
-
const weightUrl = font.files[weight];
|
|
100
|
-
if (weightUrl && weightUrl !== url) {
|
|
101
|
-
str += `
|
|
102
|
-
@font-face {
|
|
103
|
-
font-family: "${family}";
|
|
104
|
-
src: url('${weightUrl}') format('woff2');
|
|
105
|
-
font-display: fallback;
|
|
106
|
-
font-weight: ${weight};
|
|
107
|
-
}
|
|
108
|
-
`.trim();
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
return str;
|
|
113
|
-
}
|
|
114
|
-
function getFontCss(data) {
|
|
115
|
-
var _a2, _b2;
|
|
116
|
-
return ((_b2 = (_a2 = data == null ? void 0 : data.customFonts) == null ? void 0 : _a2.map((font) => getCssFromFont(font, data))) == null ? void 0 : _b2.join(" ")) || "";
|
|
83
|
+
function allRegisteredComponents() {
|
|
84
|
+
const allComponentsArray = [
|
|
85
|
+
...getDefaultRegisteredComponents(),
|
|
86
|
+
...components,
|
|
87
|
+
...props.customComponents || []
|
|
88
|
+
];
|
|
89
|
+
const allComponents = allComponentsArray.reduce((acc, curr) => __spreadProps(__spreadValues({}, acc), { [curr.name]: curr }), {});
|
|
90
|
+
return allComponents;
|
|
117
91
|
}
|
|
118
92
|
function processMessage(event) {
|
|
119
93
|
const { data } = event;
|
|
@@ -141,7 +115,7 @@ function RenderContent(props) {
|
|
|
141
115
|
evaluate({
|
|
142
116
|
code: jsCode,
|
|
143
117
|
context: context(),
|
|
144
|
-
state:
|
|
118
|
+
state: contentState()
|
|
145
119
|
});
|
|
146
120
|
}
|
|
147
121
|
}
|
|
@@ -152,12 +126,13 @@ function RenderContent(props) {
|
|
|
152
126
|
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
153
127
|
code: group,
|
|
154
128
|
context: context(),
|
|
155
|
-
state:
|
|
129
|
+
state: contentState()
|
|
156
130
|
}));
|
|
157
131
|
}
|
|
158
132
|
function handleRequest({ url, key }) {
|
|
159
133
|
const fetchAndSetState = () => __async(this, null, function* () {
|
|
160
|
-
const
|
|
134
|
+
const fetch = yield getFetch();
|
|
135
|
+
const response = yield fetch(url);
|
|
161
136
|
const json = yield response.json();
|
|
162
137
|
const newOverrideState = __spreadProps(__spreadValues({}, overrideState), { [key]: json });
|
|
163
138
|
setOverrideState(newOverrideState);
|
|
@@ -178,18 +153,25 @@ function RenderContent(props) {
|
|
|
178
153
|
});
|
|
179
154
|
}
|
|
180
155
|
function emitStateUpdate() {
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
156
|
+
if (isEditing()) {
|
|
157
|
+
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
158
|
+
detail: {
|
|
159
|
+
state: contentState(),
|
|
160
|
+
ref: {
|
|
161
|
+
name: props.model
|
|
162
|
+
}
|
|
186
163
|
}
|
|
187
|
-
}
|
|
188
|
-
}
|
|
164
|
+
}));
|
|
165
|
+
}
|
|
189
166
|
}
|
|
190
167
|
useEffect(() => {
|
|
191
168
|
if (isBrowser()) {
|
|
192
169
|
if (isEditing()) {
|
|
170
|
+
Object.values(allRegisteredComponents()).forEach((registeredComponent) => {
|
|
171
|
+
var _a2;
|
|
172
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
173
|
+
(_a2 = window.parent) == null ? void 0 : _a2.postMessage(message, "*");
|
|
174
|
+
});
|
|
193
175
|
window.addEventListener("message", processMessage);
|
|
194
176
|
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
195
177
|
}
|
|
@@ -228,7 +210,7 @@ function RenderContent(props) {
|
|
|
228
210
|
}, [(_d = (_c = useContent == null ? void 0 : useContent()) == null ? void 0 : _c.data) == null ? void 0 : _d.httpRequests]);
|
|
229
211
|
useEffect(() => {
|
|
230
212
|
emitStateUpdate();
|
|
231
|
-
}, [
|
|
213
|
+
}, [contentState()]);
|
|
232
214
|
useEffect(() => {
|
|
233
215
|
return () => {
|
|
234
216
|
if (isBrowser()) {
|
|
@@ -243,13 +225,16 @@ function RenderContent(props) {
|
|
|
243
225
|
return useContent();
|
|
244
226
|
},
|
|
245
227
|
get state() {
|
|
246
|
-
return
|
|
228
|
+
return contentState();
|
|
247
229
|
},
|
|
248
230
|
get context() {
|
|
249
231
|
return context();
|
|
250
232
|
},
|
|
251
233
|
get apiKey() {
|
|
252
234
|
return props.apiKey;
|
|
235
|
+
},
|
|
236
|
+
get registeredComponents() {
|
|
237
|
+
return allRegisteredComponents();
|
|
253
238
|
}
|
|
254
239
|
}
|
|
255
240
|
}, useContent() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
@@ -257,7 +242,10 @@ function RenderContent(props) {
|
|
|
257
242
|
contentId: useContent().id
|
|
258
243
|
}),
|
|
259
244
|
"data-builder-content-id": (_e = useContent == null ? void 0 : useContent()) == null ? void 0 : _e.id
|
|
260
|
-
}, (((_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode) || ((_j = (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts) == null ? void 0 : _j.length)) &&
|
|
245
|
+
}, (((_g = (_f = useContent == null ? void 0 : useContent()) == null ? void 0 : _f.data) == null ? void 0 : _g.cssCode) || ((_j = (_i = (_h = useContent == null ? void 0 : useContent()) == null ? void 0 : _h.data) == null ? void 0 : _i.customFonts) == null ? void 0 : _j.length)) && TARGET !== "reactNative" ? /* @__PURE__ */ React.createElement(RenderContentStyles, {
|
|
246
|
+
cssCode: useContent().data.cssCode,
|
|
247
|
+
customFonts: useContent().data.customFonts
|
|
248
|
+
}) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
|
|
261
249
|
blocks: (_l = (_k = useContent == null ? void 0 : useContent()) == null ? void 0 : _k.data) == null ? void 0 : _l.blocks
|
|
262
250
|
}))) : null);
|
|
263
251
|
}
|
|
@@ -1,30 +1,34 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import { View, StyleSheet, Image, Text } from "react-native";
|
|
3
3
|
import { useState, useContext, useEffect } from "react";
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import
|
|
7
|
-
import {
|
|
8
|
-
import { isEditing } from "../functions/is-editing";
|
|
9
|
-
import { isPreviewing } from "../functions/is-previewing";
|
|
10
|
-
import { previewingModelName } from "../functions/previewing-model-name";
|
|
11
|
-
import { getContent } from "../functions/get-content";
|
|
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";
|
|
12
8
|
import {
|
|
13
9
|
convertSearchParamsToQueryObject,
|
|
14
10
|
getBuilderSearchParams,
|
|
15
|
-
} from "
|
|
16
|
-
import
|
|
17
|
-
import {
|
|
18
|
-
import {
|
|
19
|
-
import {
|
|
20
|
-
import {
|
|
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";
|
|
21
25
|
|
|
22
26
|
export default function RenderContent(props) {
|
|
23
27
|
function useContent() {
|
|
24
28
|
const mergedContent = {
|
|
25
29
|
...props.content,
|
|
26
30
|
...overrideContent,
|
|
27
|
-
data: { ...props.content?.data, ...overrideContent?.data },
|
|
31
|
+
data: { ...props.content?.data, ...props.data, ...overrideContent?.data },
|
|
28
32
|
};
|
|
29
33
|
return mergedContent;
|
|
30
34
|
}
|
|
@@ -35,70 +39,29 @@ export default function RenderContent(props) {
|
|
|
35
39
|
|
|
36
40
|
const [overrideState, setOverrideState] = useState(() => ({}));
|
|
37
41
|
|
|
38
|
-
function
|
|
39
|
-
return { ...props.content?.data?.state, ...overrideState };
|
|
42
|
+
function contentState() {
|
|
43
|
+
return { ...props.content?.data?.state, ...props.data, ...overrideState };
|
|
40
44
|
}
|
|
41
45
|
|
|
42
46
|
function context() {
|
|
43
47
|
return {};
|
|
44
48
|
}
|
|
45
49
|
|
|
46
|
-
function
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
src: local("${name}"), url('${url}') format('woff2');
|
|
60
|
-
font-display: fallback;
|
|
61
|
-
font-weight: 400;
|
|
62
|
-
}
|
|
63
|
-
`.trim();
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
if (font.files) {
|
|
67
|
-
for (const weight in font.files) {
|
|
68
|
-
const isNumber = String(Number(weight)) === weight;
|
|
69
|
-
|
|
70
|
-
if (!isNumber) {
|
|
71
|
-
continue;
|
|
72
|
-
} // TODO: maybe limit number loaded
|
|
73
|
-
|
|
74
|
-
const weightUrl = font.files[weight];
|
|
75
|
-
|
|
76
|
-
if (weightUrl && weightUrl !== url) {
|
|
77
|
-
str += `
|
|
78
|
-
@font-face {
|
|
79
|
-
font-family: "${family}";
|
|
80
|
-
src: url('${weightUrl}') format('woff2');
|
|
81
|
-
font-display: fallback;
|
|
82
|
-
font-weight: ${weight};
|
|
83
|
-
}
|
|
84
|
-
`.trim();
|
|
85
|
-
}
|
|
86
|
-
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return str;
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
function getFontCss(data) {
|
|
93
|
-
// TODO: flag for this
|
|
94
|
-
// if (!builder.allowCustomFonts) {
|
|
95
|
-
// return '';
|
|
96
|
-
// }
|
|
97
|
-
// TODO: separate internal data from external
|
|
98
|
-
return (
|
|
99
|
-
data?.customFonts?.map((font) => getCssFromFont(font, data))?.join(" ") ||
|
|
100
|
-
""
|
|
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.name]: curr }),
|
|
62
|
+
{}
|
|
101
63
|
);
|
|
64
|
+
return allComponents;
|
|
102
65
|
}
|
|
103
66
|
|
|
104
67
|
function processMessage(event) {
|
|
@@ -138,7 +101,7 @@ export default function RenderContent(props) {
|
|
|
138
101
|
evaluate({
|
|
139
102
|
code: jsCode,
|
|
140
103
|
context: context(),
|
|
141
|
-
state:
|
|
104
|
+
state: contentState(),
|
|
142
105
|
});
|
|
143
106
|
}
|
|
144
107
|
}
|
|
@@ -152,14 +115,15 @@ export default function RenderContent(props) {
|
|
|
152
115
|
evaluate({
|
|
153
116
|
code: group,
|
|
154
117
|
context: context(),
|
|
155
|
-
state:
|
|
118
|
+
state: contentState(),
|
|
156
119
|
})
|
|
157
120
|
);
|
|
158
121
|
}
|
|
159
122
|
|
|
160
123
|
function handleRequest({ url, key }) {
|
|
161
124
|
const fetchAndSetState = async () => {
|
|
162
|
-
const
|
|
125
|
+
const fetch = await getFetch();
|
|
126
|
+
const response = await fetch(url);
|
|
163
127
|
const json = await response.json();
|
|
164
128
|
const newOverrideState = { ...overrideState, [key]: json };
|
|
165
129
|
setOverrideState(newOverrideState);
|
|
@@ -182,21 +146,29 @@ export default function RenderContent(props) {
|
|
|
182
146
|
}
|
|
183
147
|
|
|
184
148
|
function emitStateUpdate() {
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
149
|
+
if (isEditing()) {
|
|
150
|
+
window.dispatchEvent(
|
|
151
|
+
new CustomEvent("builder:component:stateChange", {
|
|
152
|
+
detail: {
|
|
153
|
+
state: contentState(),
|
|
154
|
+
ref: {
|
|
155
|
+
name: props.model,
|
|
156
|
+
},
|
|
191
157
|
},
|
|
192
|
-
}
|
|
193
|
-
|
|
194
|
-
|
|
158
|
+
})
|
|
159
|
+
);
|
|
160
|
+
}
|
|
195
161
|
}
|
|
196
162
|
|
|
197
163
|
useEffect(() => {
|
|
198
164
|
if (isBrowser()) {
|
|
199
165
|
if (isEditing()) {
|
|
166
|
+
Object.values(allRegisteredComponents()).forEach(
|
|
167
|
+
(registeredComponent) => {
|
|
168
|
+
const message = createRegisterComponentMessage(registeredComponent);
|
|
169
|
+
window.parent?.postMessage(message, "*");
|
|
170
|
+
}
|
|
171
|
+
);
|
|
200
172
|
window.addEventListener("message", processMessage);
|
|
201
173
|
window.addEventListener(
|
|
202
174
|
"builder:component:stateChangeListenerActivated",
|
|
@@ -245,7 +217,7 @@ export default function RenderContent(props) {
|
|
|
245
217
|
}, [useContent?.()?.data?.httpRequests]);
|
|
246
218
|
useEffect(() => {
|
|
247
219
|
emitStateUpdate();
|
|
248
|
-
}, [
|
|
220
|
+
}, [contentState()]);
|
|
249
221
|
|
|
250
222
|
useEffect(() => {
|
|
251
223
|
return () => {
|
|
@@ -267,7 +239,7 @@ export default function RenderContent(props) {
|
|
|
267
239
|
},
|
|
268
240
|
|
|
269
241
|
get state() {
|
|
270
|
-
return
|
|
242
|
+
return contentState();
|
|
271
243
|
},
|
|
272
244
|
|
|
273
245
|
get context() {
|
|
@@ -277,6 +249,10 @@ export default function RenderContent(props) {
|
|
|
277
249
|
get apiKey() {
|
|
278
250
|
return props.apiKey;
|
|
279
251
|
},
|
|
252
|
+
|
|
253
|
+
get registeredComponents() {
|
|
254
|
+
return allRegisteredComponents();
|
|
255
|
+
},
|
|
280
256
|
}}
|
|
281
257
|
>
|
|
282
258
|
{useContent() ? (
|
|
@@ -291,12 +267,11 @@ export default function RenderContent(props) {
|
|
|
291
267
|
>
|
|
292
268
|
{(useContent?.()?.data?.cssCode ||
|
|
293
269
|
useContent?.()?.data?.customFonts?.length) &&
|
|
294
|
-
|
|
295
|
-
<
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
</View>
|
|
270
|
+
TARGET !== "reactNative" ? (
|
|
271
|
+
<RenderContentStyles
|
|
272
|
+
cssCode={useContent().data.cssCode}
|
|
273
|
+
customFonts={useContent().data.customFonts}
|
|
274
|
+
/>
|
|
300
275
|
) : null}
|
|
301
276
|
|
|
302
277
|
<RenderBlocks blocks={useContent?.()?.data?.blocks} />
|
|
@@ -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,6 +1,6 @@
|
|
|
1
1
|
import * as React from 'react';
|
|
2
|
-
import { evaluate } from "./evaluate";
|
|
3
|
-
import { getEventHandlerName } from "./event-handler-name";
|
|
2
|
+
import { evaluate } from "./evaluate.js";
|
|
3
|
+
import { getEventHandlerName } from "./event-handler-name.js";
|
|
4
4
|
function getBlockActions(options) {
|
|
5
5
|
var _a;
|
|
6
6
|
const obj = {};
|
|
@@ -18,8 +18,8 @@ var __spreadValues = (a, b) => {
|
|
|
18
18
|
return a;
|
|
19
19
|
};
|
|
20
20
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
21
|
-
import { findDOMNode } from "react-dom";
|
|
22
21
|
import { isEditing } from "./is-editing";
|
|
22
|
+
import { findDOMNode } from "react-dom";
|
|
23
23
|
function getBlockProperties(block) {
|
|
24
24
|
return __spreadProps(__spreadValues({}, block.properties), {
|
|
25
25
|
ref: (ref) => {
|