@builder.io/sdk-react-native 0.0.1-44 → 0.0.1-50
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.js +23 -73
- package/src/blocks/button.lite.tsx +3 -3
- package/src/blocks/columns.js +56 -288
- package/src/blocks/columns.lite.tsx +22 -22
- package/src/blocks/custom-code.js +46 -76
- package/src/blocks/custom-code.lite.tsx +11 -19
- package/src/blocks/embed.js +46 -69
- package/src/blocks/embed.lite.tsx +11 -15
- package/src/blocks/form.js +194 -491
- package/src/blocks/form.lite.tsx +51 -51
- package/src/blocks/fragment.js +8 -16
- package/src/blocks/fragment.lite.tsx +2 -2
- package/src/blocks/image.js +91 -113
- package/src/blocks/image.lite.tsx +12 -13
- package/src/blocks/img.js +28 -51
- package/src/blocks/img.lite.tsx +6 -6
- package/src/blocks/input.js +28 -100
- package/src/blocks/input.lite.tsx +4 -4
- package/src/blocks/raw-text.js +10 -16
- package/src/blocks/raw-text.lite.tsx +3 -8
- package/src/blocks/section.js +23 -71
- package/src/blocks/section.lite.tsx +3 -3
- package/src/blocks/select.js +28 -78
- package/src/blocks/select.lite.tsx +5 -5
- package/src/blocks/submit-button.js +21 -47
- package/src/blocks/submit-button.lite.tsx +2 -2
- package/src/blocks/symbol.js +71 -20
- package/src/blocks/symbol.lite.tsx +48 -8
- package/src/blocks/text.js +27 -40
- package/src/blocks/text.lite.tsx +3 -8
- package/src/blocks/textarea.js +24 -60
- package/src/blocks/textarea.lite.tsx +2 -2
- package/src/blocks/video.js +66 -71
- package/src/blocks/video.lite.tsx +5 -5
- package/src/components/block-styles.js +4 -2
- package/src/components/block-styles.lite.tsx +2 -2
- package/src/components/error-boundary.js +9 -11
- package/src/components/error-boundary.lite.tsx +2 -2
- package/src/components/render-block.js +44 -100
- package/src/components/render-block.lite.tsx +23 -28
- package/src/components/render-blocks.js +41 -60
- package/src/components/render-blocks.lite.tsx +20 -14
- package/src/components/render-content.js +189 -142
- package/src/components/render-content.lite.tsx +166 -60
- package/src/constants/device-sizes.js +11 -8
- package/src/context/builder.context.js +10 -3
- package/src/functions/evaluate.js +20 -20
- package/src/functions/event-handler-name.js +3 -1
- 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 +14 -0
- package/src/functions/get-builder-search-params/index.js +23 -0
- package/src/functions/get-content/fn.test.js +32 -0
- package/src/functions/get-content/index.js +138 -0
- package/src/functions/get-fetch.js +7 -5
- 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 +17 -16
- package/src/functions/get-target.js +4 -2
- package/src/functions/if-target.js +3 -1
- 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 +27 -38
- 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 +12 -6
- package/src/functions/transform-block.js +13 -17
- package/src/index-helpers/blocks-exports.js +19 -0
- package/src/index-helpers/top-of-file.js +2 -0
- package/src/index.js +11 -26
- package/src/scripts/init-editing.js +40 -64
- package/src/types/typescript.js +1 -0
- package/src/functions/get-content.js +0 -152
- package/src/functions/get-content.test.js +0 -58
|
@@ -1,37 +1,85 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import * as React from "react";
|
|
41
|
+
import { View, Text } from "react-native";
|
|
42
|
+
import { useState, useEffect } from "react";
|
|
43
|
+
import { isBrowser } from "../functions/is-browser";
|
|
44
|
+
import BuilderContext from "../context/builder.context";
|
|
45
|
+
import { track } from "../functions/track";
|
|
46
|
+
import { isReactNative } from "../functions/is-react-native";
|
|
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";
|
|
51
|
+
import {
|
|
52
|
+
convertSearchParamsToQueryObject,
|
|
53
|
+
getBuilderSearchParams
|
|
54
|
+
} from "../functions/get-builder-search-params";
|
|
55
|
+
import RenderBlocks from "./render-blocks";
|
|
56
|
+
import { evaluate } from "../functions/evaluate";
|
|
57
|
+
import { getFetch } from "../functions/get-fetch";
|
|
13
58
|
function RenderContent(props) {
|
|
14
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
59
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
15
60
|
function useContent() {
|
|
16
|
-
|
|
61
|
+
var _a2;
|
|
62
|
+
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)
|
|
64
|
+
});
|
|
65
|
+
return mergedContent;
|
|
17
66
|
}
|
|
18
|
-
const [update, setUpdate] = useState(() => 0);
|
|
19
|
-
const [state, setState] = useState(() => ({}));
|
|
20
|
-
const [context, setContext] = useState(() => ({}));
|
|
21
67
|
const [overrideContent, setOverrideContent] = useState(() => null);
|
|
68
|
+
const [update, setUpdate] = useState(() => 0);
|
|
69
|
+
const [overrideState, setOverrideState] = useState(() => ({}));
|
|
70
|
+
function state() {
|
|
71
|
+
var _a2, _b2;
|
|
72
|
+
return __spreadValues(__spreadValues({}, (_b2 = (_a2 = props.content) == null ? void 0 : _a2.data) == null ? void 0 : _b2.state), overrideState);
|
|
73
|
+
}
|
|
74
|
+
function context() {
|
|
75
|
+
return {};
|
|
76
|
+
}
|
|
22
77
|
function getCssFromFont(font, data) {
|
|
23
78
|
var _a2, _b2;
|
|
24
|
-
const family =
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const url =
|
|
29
|
-
(_b2 = font.fileUrl) != null
|
|
30
|
-
? _b2
|
|
31
|
-
: (_a2 = font == null ? void 0 : font.files) == null
|
|
32
|
-
? void 0
|
|
33
|
-
: _a2.regular;
|
|
34
|
-
let str = '';
|
|
79
|
+
const family = font.family + (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
|
|
80
|
+
const name = family.split(",")[0];
|
|
81
|
+
const url = (_b2 = font.fileUrl) != null ? _b2 : (_a2 = font == null ? void 0 : font.files) == null ? void 0 : _a2.regular;
|
|
82
|
+
let str = "";
|
|
35
83
|
if (url && family && name) {
|
|
36
84
|
str += `
|
|
37
85
|
@font-face {
|
|
@@ -65,63 +113,100 @@ function RenderContent(props) {
|
|
|
65
113
|
}
|
|
66
114
|
function getFontCss(data) {
|
|
67
115
|
var _a2, _b2;
|
|
68
|
-
return (
|
|
69
|
-
((_b2 =
|
|
70
|
-
(_a2 = data == null ? void 0 : data.customFonts) == null
|
|
71
|
-
? void 0
|
|
72
|
-
: _a2.map((font) => getCssFromFont(font, data))) == null
|
|
73
|
-
? void 0
|
|
74
|
-
: _b2.join(' ')) || ''
|
|
75
|
-
);
|
|
116
|
+
return ((_b2 = (_a2 = data == null ? void 0 : data.customFonts) == null ? void 0 : _a2.map((font) => getCssFromFont(font, data))) == null ? void 0 : _b2.join(" ")) || "";
|
|
76
117
|
}
|
|
77
118
|
function processMessage(event) {
|
|
78
119
|
const { data } = event;
|
|
79
120
|
if (data) {
|
|
80
121
|
switch (data.type) {
|
|
81
|
-
case
|
|
82
|
-
const
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
data.data.entry ||
|
|
86
|
-
data.data.modelName;
|
|
87
|
-
const contentData = data.data.data;
|
|
122
|
+
case "builder.contentUpdate": {
|
|
123
|
+
const messageContent = data.data;
|
|
124
|
+
const key = messageContent.key || messageContent.alias || messageContent.entry || messageContent.modelName;
|
|
125
|
+
const contentData = messageContent.data;
|
|
88
126
|
if (key === props.model) {
|
|
89
127
|
setOverrideContent(contentData);
|
|
90
128
|
}
|
|
91
129
|
break;
|
|
92
130
|
}
|
|
93
|
-
case
|
|
131
|
+
case "builder.patchUpdates": {
|
|
94
132
|
break;
|
|
95
133
|
}
|
|
96
134
|
}
|
|
97
135
|
}
|
|
98
136
|
}
|
|
137
|
+
function evaluateJsCode() {
|
|
138
|
+
var _a2, _b2;
|
|
139
|
+
const jsCode = (_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.jsCode;
|
|
140
|
+
if (jsCode) {
|
|
141
|
+
evaluate({
|
|
142
|
+
code: jsCode,
|
|
143
|
+
context: context(),
|
|
144
|
+
state: state()
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
function httpReqsData() {
|
|
149
|
+
return {};
|
|
150
|
+
}
|
|
151
|
+
function evalExpression(expression) {
|
|
152
|
+
return expression.replace(/{{([^}]+)}}/g, (_match, group) => evaluate({
|
|
153
|
+
code: group,
|
|
154
|
+
context: context(),
|
|
155
|
+
state: state()
|
|
156
|
+
}));
|
|
157
|
+
}
|
|
158
|
+
function handleRequest({ url, key }) {
|
|
159
|
+
const fetchAndSetState = () => __async(this, null, function* () {
|
|
160
|
+
const response = yield getFetch()(url);
|
|
161
|
+
const json = yield response.json();
|
|
162
|
+
const newOverrideState = __spreadProps(__spreadValues({}, overrideState), { [key]: json });
|
|
163
|
+
setOverrideState(newOverrideState);
|
|
164
|
+
});
|
|
165
|
+
fetchAndSetState();
|
|
166
|
+
}
|
|
167
|
+
function runHttpRequests() {
|
|
168
|
+
var _a2, _b2, _c2;
|
|
169
|
+
const requests = (_c2 = (_b2 = (_a2 = useContent == null ? void 0 : useContent()) == null ? void 0 : _a2.data) == null ? void 0 : _b2.httpRequests) != null ? _c2 : {};
|
|
170
|
+
Object.entries(requests).forEach(([key, url]) => {
|
|
171
|
+
if (url && (!httpReqsData()[key] || isEditing())) {
|
|
172
|
+
const evaluatedUrl = evalExpression(url);
|
|
173
|
+
handleRequest({
|
|
174
|
+
url: evaluatedUrl,
|
|
175
|
+
key
|
|
176
|
+
});
|
|
177
|
+
}
|
|
178
|
+
});
|
|
179
|
+
}
|
|
180
|
+
function emitStateUpdate() {
|
|
181
|
+
window.dispatchEvent(new CustomEvent("builder:component:stateChange", {
|
|
182
|
+
detail: {
|
|
183
|
+
state: state(),
|
|
184
|
+
ref: {
|
|
185
|
+
name: props.model
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}));
|
|
189
|
+
}
|
|
99
190
|
useEffect(() => {
|
|
100
191
|
if (isBrowser()) {
|
|
101
192
|
if (isEditing()) {
|
|
102
|
-
window.addEventListener(
|
|
193
|
+
window.addEventListener("message", processMessage);
|
|
194
|
+
window.addEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
103
195
|
}
|
|
104
|
-
if (useContent()
|
|
105
|
-
track(
|
|
106
|
-
contentId: useContent().id
|
|
196
|
+
if (useContent()) {
|
|
197
|
+
track("impression", {
|
|
198
|
+
contentId: useContent().id
|
|
107
199
|
});
|
|
108
200
|
}
|
|
109
201
|
if (isPreviewing()) {
|
|
110
202
|
if (props.model && previewingModelName() === props.model) {
|
|
111
|
-
const options = {};
|
|
112
203
|
const currentUrl = new URL(location.href);
|
|
113
|
-
const
|
|
114
|
-
if (
|
|
115
|
-
const builderPrefix = 'builder.';
|
|
116
|
-
currentUrl.searchParams.forEach((value, key) => {
|
|
117
|
-
if (key.startsWith(builderPrefix)) {
|
|
118
|
-
options[key.replace(builderPrefix, '')] = value;
|
|
119
|
-
}
|
|
120
|
-
});
|
|
204
|
+
const previewApiKey = currentUrl.searchParams.get("apiKey");
|
|
205
|
+
if (previewApiKey) {
|
|
121
206
|
getContent({
|
|
122
207
|
model: props.model,
|
|
123
|
-
apiKey,
|
|
124
|
-
options
|
|
208
|
+
apiKey: previewApiKey,
|
|
209
|
+
options: getBuilderSearchParams(convertSearchParamsToQueryObject(currentUrl.searchParams))
|
|
125
210
|
}).then((content) => {
|
|
126
211
|
if (content) {
|
|
127
212
|
setOverrideContent(content);
|
|
@@ -130,90 +215,52 @@ function RenderContent(props) {
|
|
|
130
215
|
}
|
|
131
216
|
}
|
|
132
217
|
}
|
|
218
|
+
evaluateJsCode();
|
|
219
|
+
runHttpRequests();
|
|
220
|
+
emitStateUpdate();
|
|
133
221
|
}
|
|
134
222
|
}, []);
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
223
|
+
useEffect(() => {
|
|
224
|
+
evaluateJsCode();
|
|
225
|
+
}, [(_b = (_a = useContent == null ? void 0 : useContent()) == null ? void 0 : _a.data) == null ? void 0 : _b.jsCode]);
|
|
226
|
+
useEffect(() => {
|
|
227
|
+
runHttpRequests();
|
|
228
|
+
}, [(_d = (_c = useContent == null ? void 0 : useContent()) == null ? void 0 : _c.data) == null ? void 0 : _d.httpRequests]);
|
|
229
|
+
useEffect(() => {
|
|
230
|
+
emitStateUpdate();
|
|
231
|
+
}, [state()]);
|
|
232
|
+
useEffect(() => {
|
|
233
|
+
return () => {
|
|
234
|
+
if (isBrowser()) {
|
|
235
|
+
window.removeEventListener("message", processMessage);
|
|
236
|
+
window.removeEventListener("builder:component:stateChangeListenerActivated", emitStateUpdate);
|
|
237
|
+
}
|
|
238
|
+
};
|
|
239
|
+
}, []);
|
|
240
|
+
return /* @__PURE__ */ React.createElement(BuilderContext.Provider, {
|
|
241
|
+
value: {
|
|
242
|
+
get content() {
|
|
243
|
+
return useContent();
|
|
148
244
|
},
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
: _a.id,
|
|
168
|
-
},
|
|
169
|
-
(((_c =
|
|
170
|
-
(_b = useContent == null ? void 0 : useContent()) == null
|
|
171
|
-
? void 0
|
|
172
|
-
: _b.data) == null
|
|
173
|
-
? void 0
|
|
174
|
-
: _c.cssCode) ||
|
|
175
|
-
((_f =
|
|
176
|
-
(_e =
|
|
177
|
-
(_d = useContent == null ? void 0 : useContent()) == null
|
|
178
|
-
? void 0
|
|
179
|
-
: _d.data) == null
|
|
180
|
-
? void 0
|
|
181
|
-
: _e.customFonts) == null
|
|
182
|
-
? void 0
|
|
183
|
-
: _f.length)) &&
|
|
184
|
-
!isReactNative()
|
|
185
|
-
? /* @__PURE__ */ React.createElement(
|
|
186
|
-
View,
|
|
187
|
-
null,
|
|
188
|
-
/* @__PURE__ */ React.createElement(
|
|
189
|
-
Text,
|
|
190
|
-
null,
|
|
191
|
-
useContent().data.cssCode
|
|
192
|
-
),
|
|
193
|
-
/* @__PURE__ */ React.createElement(
|
|
194
|
-
Text,
|
|
195
|
-
null,
|
|
196
|
-
getFontCss(useContent().data)
|
|
197
|
-
)
|
|
198
|
-
)
|
|
199
|
-
: null,
|
|
200
|
-
(_i =
|
|
201
|
-
(_h =
|
|
202
|
-
(_g = useContent == null ? void 0 : useContent()) == null
|
|
203
|
-
? void 0
|
|
204
|
-
: _g.data) == null
|
|
205
|
-
? void 0
|
|
206
|
-
: _h.blocks) == null
|
|
207
|
-
? void 0
|
|
208
|
-
: _i.map((block) =>
|
|
209
|
-
/* @__PURE__ */ React.createElement(RenderBlock, {
|
|
210
|
-
key: block.id,
|
|
211
|
-
block,
|
|
212
|
-
})
|
|
213
|
-
)
|
|
214
|
-
)
|
|
215
|
-
)
|
|
216
|
-
: null
|
|
217
|
-
);
|
|
245
|
+
get state() {
|
|
246
|
+
return state();
|
|
247
|
+
},
|
|
248
|
+
get context() {
|
|
249
|
+
return context();
|
|
250
|
+
},
|
|
251
|
+
get apiKey() {
|
|
252
|
+
return props.apiKey;
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
}, useContent() ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
256
|
+
onClick: (event) => track("click", {
|
|
257
|
+
contentId: useContent().id
|
|
258
|
+
}),
|
|
259
|
+
"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)) && !isReactNative() ? /* @__PURE__ */ React.createElement(View, null, /* @__PURE__ */ React.createElement(Text, null, useContent().data.cssCode), /* @__PURE__ */ React.createElement(Text, null, state().getFontCss(useContent().data))) : null, /* @__PURE__ */ React.createElement(RenderBlocks, {
|
|
261
|
+
blocks: (_l = (_k = useContent == null ? void 0 : useContent()) == null ? void 0 : _k.data) == null ? void 0 : _l.blocks
|
|
262
|
+
}))) : null);
|
|
218
263
|
}
|
|
219
|
-
export {
|
|
264
|
+
export {
|
|
265
|
+
RenderContent as default
|
|
266
|
+
};
|