@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.
Files changed (88) hide show
  1. package/CHANGELOG.md +14 -0
  2. package/package.json +1 -1
  3. package/src/blocks/button.js +23 -73
  4. package/src/blocks/button.lite.tsx +3 -3
  5. package/src/blocks/columns.js +56 -288
  6. package/src/blocks/columns.lite.tsx +22 -22
  7. package/src/blocks/custom-code.js +46 -76
  8. package/src/blocks/custom-code.lite.tsx +11 -19
  9. package/src/blocks/embed.js +46 -69
  10. package/src/blocks/embed.lite.tsx +11 -15
  11. package/src/blocks/form.js +194 -491
  12. package/src/blocks/form.lite.tsx +51 -51
  13. package/src/blocks/fragment.js +8 -16
  14. package/src/blocks/fragment.lite.tsx +2 -2
  15. package/src/blocks/image.js +91 -113
  16. package/src/blocks/image.lite.tsx +12 -13
  17. package/src/blocks/img.js +28 -51
  18. package/src/blocks/img.lite.tsx +6 -6
  19. package/src/blocks/input.js +28 -100
  20. package/src/blocks/input.lite.tsx +4 -4
  21. package/src/blocks/raw-text.js +10 -16
  22. package/src/blocks/raw-text.lite.tsx +3 -8
  23. package/src/blocks/section.js +23 -71
  24. package/src/blocks/section.lite.tsx +3 -3
  25. package/src/blocks/select.js +28 -78
  26. package/src/blocks/select.lite.tsx +5 -5
  27. package/src/blocks/submit-button.js +21 -47
  28. package/src/blocks/submit-button.lite.tsx +2 -2
  29. package/src/blocks/symbol.js +71 -20
  30. package/src/blocks/symbol.lite.tsx +48 -8
  31. package/src/blocks/text.js +27 -40
  32. package/src/blocks/text.lite.tsx +3 -8
  33. package/src/blocks/textarea.js +24 -60
  34. package/src/blocks/textarea.lite.tsx +2 -2
  35. package/src/blocks/video.js +66 -71
  36. package/src/blocks/video.lite.tsx +5 -5
  37. package/src/components/block-styles.js +4 -2
  38. package/src/components/block-styles.lite.tsx +2 -2
  39. package/src/components/error-boundary.js +9 -11
  40. package/src/components/error-boundary.lite.tsx +2 -2
  41. package/src/components/render-block.js +44 -100
  42. package/src/components/render-block.lite.tsx +23 -28
  43. package/src/components/render-blocks.js +41 -60
  44. package/src/components/render-blocks.lite.tsx +20 -14
  45. package/src/components/render-content.js +189 -142
  46. package/src/components/render-content.lite.tsx +166 -60
  47. package/src/constants/device-sizes.js +11 -8
  48. package/src/context/builder.context.js +10 -3
  49. package/src/functions/evaluate.js +20 -20
  50. package/src/functions/event-handler-name.js +3 -1
  51. package/src/functions/get-block-actions.js +17 -16
  52. package/src/functions/get-block-component-options.js +9 -16
  53. package/src/functions/get-block-properties.js +14 -18
  54. package/src/functions/get-block-styles.js +17 -34
  55. package/src/functions/get-block-tag.js +4 -2
  56. package/src/functions/get-builder-search-params/fn.test.js +14 -0
  57. package/src/functions/get-builder-search-params/index.js +23 -0
  58. package/src/functions/get-content/fn.test.js +32 -0
  59. package/src/functions/get-content/index.js +138 -0
  60. package/src/functions/get-fetch.js +7 -5
  61. package/src/functions/get-global-this.js +7 -5
  62. package/src/functions/get-processed-block.js +13 -17
  63. package/src/functions/get-processed-block.test.js +17 -16
  64. package/src/functions/get-target.js +4 -2
  65. package/src/functions/if-target.js +3 -1
  66. package/src/functions/is-browser.js +4 -2
  67. package/src/functions/is-editing.js +5 -5
  68. package/src/functions/is-iframe.js +4 -2
  69. package/src/functions/is-previewing.js +6 -4
  70. package/src/functions/is-react-native.js +3 -1
  71. package/src/functions/macro-eval.js +5 -2
  72. package/src/functions/on-change.js +7 -4
  73. package/src/functions/on-change.test.js +9 -10
  74. package/src/functions/previewing-model-name.js +5 -3
  75. package/src/functions/register-component.js +27 -38
  76. package/src/functions/register.js +10 -8
  77. package/src/functions/set-editor-settings.js +7 -5
  78. package/src/functions/set.js +5 -14
  79. package/src/functions/set.test.js +13 -14
  80. package/src/functions/track.js +12 -6
  81. package/src/functions/transform-block.js +13 -17
  82. package/src/index-helpers/blocks-exports.js +19 -0
  83. package/src/index-helpers/top-of-file.js +2 -0
  84. package/src/index.js +11 -26
  85. package/src/scripts/init-editing.js +40 -64
  86. package/src/types/typescript.js +1 -0
  87. package/src/functions/get-content.js +0 -152
  88. package/src/functions/get-content.test.js +0 -58
@@ -1,39 +1,56 @@
1
- import * as React from 'react';
2
- import { View, StyleSheet, Image, Text } from 'react-native';
3
- import { useState, useContext, useEffect } from 'react';
4
- import { isBrowser } from '../functions/is-browser';
5
- import RenderBlock from './render-block.lite';
6
- import BuilderContext from '../context/builder.context.lite';
7
- import { track } from '../functions/track';
8
- import { ifTarget } from '../functions/if-target';
9
- import { onChange } from '../functions/on-change';
10
- import { isReactNative } from '../functions/is-react-native';
11
- import { isEditing } from '../functions/is-editing';
12
- import { isPreviewing } from '../functions/is-previewing';
13
- import { previewingModelName } from '../functions/previewing-model-name';
14
- import { getContent } from '../functions/get-content';
1
+ import * as React from "react";
2
+ import { View, StyleSheet, Image, Text } from "react-native";
3
+ import { useState, useContext, useEffect } from "react";
4
+ import { isBrowser } from "../functions/is-browser";
5
+ import BuilderContext from "../context/builder.context.lite";
6
+ import { track } from "../functions/track";
7
+ import { isReactNative } from "../functions/is-react-native";
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";
12
+ import {
13
+ convertSearchParamsToQueryObject,
14
+ getBuilderSearchParams,
15
+ } from "../functions/get-builder-search-params";
16
+ import RenderBlocks from "./render-blocks.lite";
17
+ import { evaluate } from "../functions/evaluate";
18
+ import { getFetch } from "../functions/get-fetch";
19
+ import { onChange } from "../functions/on-change";
20
+ import { ifTarget } from "../functions/if-target";
15
21
 
16
22
  export default function RenderContent(props) {
17
23
  function useContent() {
18
- return overrideContent || props.content;
24
+ const mergedContent = {
25
+ ...props.content,
26
+ ...overrideContent,
27
+ data: { ...props.content?.data, ...overrideContent?.data },
28
+ };
29
+ return mergedContent;
19
30
  }
20
31
 
32
+ const [overrideContent, setOverrideContent] = useState(() => null);
33
+
21
34
  const [update, setUpdate] = useState(() => 0);
22
35
 
23
- const [state, setState] = useState(() => ({}));
36
+ const [overrideState, setOverrideState] = useState(() => ({}));
24
37
 
25
- const [context, setContext] = useState(() => ({}));
38
+ function state() {
39
+ return { ...props.content?.data?.state, ...overrideState };
40
+ }
26
41
 
27
- const [overrideContent, setOverrideContent] = useState(() => null);
42
+ function context() {
43
+ return {};
44
+ }
28
45
 
29
46
  function getCssFromFont(font, data) {
30
47
  // TODO: compute what font sizes are used and only load those.......
31
48
  const family =
32
49
  font.family +
33
- (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
34
- const name = family.split(',')[0];
50
+ (font.kind && !font.kind.includes("#") ? ", " + font.kind : "");
51
+ const name = family.split(",")[0];
35
52
  const url = font.fileUrl ?? font?.files?.regular;
36
- let str = '';
53
+ let str = "";
37
54
 
38
55
  if (url && family && name) {
39
56
  str += `
@@ -79,8 +96,8 @@ export default function RenderContent(props) {
79
96
  // }
80
97
  // TODO: separate internal data from external
81
98
  return (
82
- data?.customFonts?.map((font) => getCssFromFont(font, data))?.join(' ') ||
83
- ''
99
+ data?.customFonts?.map((font) => getCssFromFont(font, data))?.join(" ") ||
100
+ ""
84
101
  );
85
102
  }
86
103
 
@@ -89,13 +106,14 @@ export default function RenderContent(props) {
89
106
 
90
107
  if (data) {
91
108
  switch (data.type) {
92
- case 'builder.contentUpdate': {
109
+ case "builder.contentUpdate": {
110
+ const messageContent = data.data;
93
111
  const key =
94
- data.data.key ||
95
- data.data.alias ||
96
- data.data.entry ||
97
- data.data.modelName;
98
- const contentData = data.data.data; // oof
112
+ messageContent.key ||
113
+ messageContent.alias ||
114
+ messageContent.entry ||
115
+ messageContent.modelName;
116
+ const contentData = messageContent.data;
99
117
 
100
118
  if (key === props.model) {
101
119
  setOverrideContent(contentData);
@@ -104,7 +122,7 @@ export default function RenderContent(props) {
104
122
  break;
105
123
  }
106
124
 
107
- case 'builder.patchUpdates': {
125
+ case "builder.patchUpdates": {
108
126
  // TODO
109
127
  break;
110
128
  }
@@ -112,47 +130,135 @@ export default function RenderContent(props) {
112
130
  }
113
131
  }
114
132
 
133
+ function evaluateJsCode() {
134
+ // run any dynamic JS code attached to content
135
+ const jsCode = useContent?.()?.data?.jsCode;
136
+
137
+ if (jsCode) {
138
+ evaluate({
139
+ code: jsCode,
140
+ context: context(),
141
+ state: state(),
142
+ });
143
+ }
144
+ }
145
+
146
+ function httpReqsData() {
147
+ return {};
148
+ }
149
+
150
+ function evalExpression(expression) {
151
+ return expression.replace(/{{([^}]+)}}/g, (_match, group) =>
152
+ evaluate({
153
+ code: group,
154
+ context: context(),
155
+ state: state(),
156
+ })
157
+ );
158
+ }
159
+
160
+ function handleRequest({ url, key }) {
161
+ const fetchAndSetState = async () => {
162
+ const response = await getFetch()(url);
163
+ const json = await response.json();
164
+ const newOverrideState = { ...overrideState, [key]: json };
165
+ setOverrideState(newOverrideState);
166
+ };
167
+
168
+ fetchAndSetState();
169
+ }
170
+
171
+ function runHttpRequests() {
172
+ const requests = useContent?.()?.data?.httpRequests ?? {};
173
+ Object.entries(requests).forEach(([key, url]) => {
174
+ if (url && (!httpReqsData()[key] || isEditing())) {
175
+ const evaluatedUrl = evalExpression(url);
176
+ handleRequest({
177
+ url: evaluatedUrl,
178
+ key,
179
+ });
180
+ }
181
+ });
182
+ }
183
+
184
+ function emitStateUpdate() {
185
+ window.dispatchEvent(
186
+ new CustomEvent("builder:component:stateChange", {
187
+ detail: {
188
+ state: state(),
189
+ ref: {
190
+ name: props.model,
191
+ },
192
+ },
193
+ })
194
+ );
195
+ }
196
+
115
197
  useEffect(() => {
116
198
  if (isBrowser()) {
117
199
  if (isEditing()) {
118
- window.addEventListener('message', processMessage);
200
+ window.addEventListener("message", processMessage);
201
+ window.addEventListener(
202
+ "builder:component:stateChangeListenerActivated",
203
+ emitStateUpdate
204
+ );
119
205
  }
120
206
 
121
- if (useContent() && !isEditing()) {
122
- track('impression', {
207
+ if (useContent()) {
208
+ track("impression", {
123
209
  contentId: useContent().id,
124
210
  });
125
- }
211
+ } // override normal content in preview mode
126
212
 
127
213
  if (isPreviewing()) {
128
214
  if (props.model && previewingModelName() === props.model) {
129
- const options = {};
130
215
  const currentUrl = new URL(location.href);
131
- const apiKey = currentUrl.searchParams.get('apiKey');
132
-
133
- if (apiKey) {
134
- const builderPrefix = 'builder.';
135
- currentUrl.searchParams.forEach((value, key) => {
136
- if (key.startsWith(builderPrefix)) {
137
- options[key.replace(builderPrefix, '')] = value;
138
- }
139
- }); // TODO: need access to API key
216
+ const previewApiKey = currentUrl.searchParams.get("apiKey");
140
217
 
218
+ if (previewApiKey) {
141
219
  getContent({
142
220
  model: props.model,
143
- apiKey,
144
- options,
221
+ apiKey: previewApiKey,
222
+ options: getBuilderSearchParams(
223
+ convertSearchParamsToQueryObject(currentUrl.searchParams)
224
+ ),
145
225
  }).then((content) => {
146
226
  if (content) {
147
227
  setOverrideContent(content);
148
228
  }
149
229
  });
150
- } // TODO: fetch content and override. Forward all builder.* params
230
+ }
151
231
  }
152
232
  }
233
+
234
+ evaluateJsCode();
235
+ runHttpRequests();
236
+ emitStateUpdate();
153
237
  }
154
238
  }, []);
155
239
 
240
+ useEffect(() => {
241
+ evaluateJsCode();
242
+ }, [useContent?.()?.data?.jsCode]);
243
+ useEffect(() => {
244
+ runHttpRequests();
245
+ }, [useContent?.()?.data?.httpRequests]);
246
+ useEffect(() => {
247
+ emitStateUpdate();
248
+ }, [state()]);
249
+
250
+ useEffect(() => {
251
+ return () => {
252
+ if (isBrowser()) {
253
+ window.removeEventListener("message", processMessage);
254
+ window.removeEventListener(
255
+ "builder:component:stateChangeListenerActivated",
256
+ emitStateUpdate
257
+ );
258
+ }
259
+ };
260
+ }, []);
261
+
156
262
  return (
157
263
  <BuilderContext.Provider
158
264
  value={{
@@ -161,24 +267,26 @@ export default function RenderContent(props) {
161
267
  },
162
268
 
163
269
  get state() {
164
- return state;
270
+ return state();
165
271
  },
166
272
 
167
273
  get context() {
168
- return context;
274
+ return context();
275
+ },
276
+
277
+ get apiKey() {
278
+ return props.apiKey;
169
279
  },
170
280
  }}
171
281
  >
172
282
  {useContent() ? (
173
283
  <>
174
284
  <View
175
- onClick={(event) => {
176
- if (!isEditing()) {
177
- track('click', {
178
- contentId: useContent().id,
179
- });
180
- }
181
- }}
285
+ onClick={(event) =>
286
+ track("click", {
287
+ contentId: useContent().id,
288
+ })
289
+ }
182
290
  data-builder-content-id={useContent?.()?.id}
183
291
  >
184
292
  {(useContent?.()?.data?.cssCode ||
@@ -187,13 +295,11 @@ export default function RenderContent(props) {
187
295
  <View>
188
296
  <Text>{useContent().data.cssCode}</Text>
189
297
 
190
- <Text>{getFontCss(useContent().data)}</Text>
298
+ <Text>{state().getFontCss(useContent().data)}</Text>
191
299
  </View>
192
300
  ) : null}
193
301
 
194
- {useContent?.()?.data?.blocks?.map((block) => (
195
- <RenderBlock key={block.id} block={block} />
196
- ))}
302
+ <RenderBlocks blocks={useContent?.()?.data?.blocks} />
197
303
  </View>
198
304
  </>
199
305
  ) : null}
@@ -1,25 +1,25 @@
1
1
  import * as React from 'react';
2
- const sizeNames = ['xsmall', 'small', 'medium', 'large'];
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 'large';
35
- },
34
+ return "large";
35
+ }
36
+ };
37
+ export {
38
+ sizeNames,
39
+ sizes
36
40
  };
37
- export { sizeNames, sizes };
@@ -1,3 +1,10 @@
1
- import { createContext } from 'react';
2
- var stdin_default = createContext({ content: null, context: {}, state: {} });
3
- export { stdin_default as default };
1
+ import { createContext } from "react";
2
+ var stdin_default = createContext({
3
+ content: null,
4
+ context: {},
5
+ state: {},
6
+ apiKey: null
7
+ });
8
+ export {
9
+ stdin_default as default
10
+ };
@@ -1,29 +1,29 @@
1
1
  import * as React from 'react';
2
- import { isBrowser } from './is-browser';
3
- import { isEditing } from './is-editing';
4
- function evaluate(options) {
5
- const { code } = options;
2
+ import { isBrowser } from "./is-browser";
3
+ import { isEditing } from "./is-editing";
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
- code.includes(';') ||
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('Builder custom code error: ', e);
24
+ console.warn("Builder custom code error: ", e);
27
25
  }
28
26
  }
29
- export { evaluate };
27
+ export {
28
+ evaluate
29
+ };
@@ -3,4 +3,6 @@ function capitalizeFirstLetter(string) {
3
3
  return string.charAt(0).toUpperCase() + string.slice(1);
4
4
  }
5
5
  const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
6
- export { getEventHandlerName };
6
+ export {
7
+ getEventHandlerName
8
+ };
@@ -1,23 +1,24 @@
1
1
  import * as React from 'react';
2
- import { evaluate } from './evaluate';
3
- import { getEventHandlerName } from './event-handler-name';
2
+ import { evaluate } from "./evaluate";
3
+ import { getEventHandlerName } from "./event-handler-name";
4
4
  function getBlockActions(options) {
5
+ var _a;
5
6
  const obj = {};
6
- if (options.block.actions) {
7
- for (const key in options.block.actions) {
8
- if (!options.block.actions.hasOwnProperty(key)) {
9
- continue;
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 { getBlockActions };
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)) __defNormalProp(a, prop, 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)) __defNormalProp(a, prop, 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 { getBlockComponentOptions };
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)) __defNormalProp(a, prop, 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)) __defNormalProp(a, prop, 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 { findDOMNode } from 'react-dom';
28
- import { isEditing } from './is-editing';
21
+ import { findDOMNode } from "react-dom";
22
+ import { isEditing } from "./is-editing";
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('builder-id', block.id);
29
+ el.setAttribute("builder-id", block.id);
36
30
  el.classList.add(block.id);
37
31
  }
38
32
  }
39
33
  },
40
34
  dataSet: {
41
- 'builder-id': block.id,
42
- class: [block.id, 'builder-block', block.class].filter(Boolean).join(' '),
43
- },
35
+ "builder-id": block.id,
36
+ class: [block.id, "builder-block", block.class].filter(Boolean).join(" ")
37
+ }
44
38
  });
45
39
  }
46
- export { getBlockProperties };
40
+ export {
41
+ getBlockProperties
42
+ };
@@ -3,55 +3,42 @@ 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)) __defNormalProp(a, prop, 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)) __defNormalProp(a, prop, b[prop]);
13
+ if (__propIsEnum.call(b, prop))
14
+ __defNormalProp(a, prop, b[prop]);
21
15
  }
22
16
  return a;
23
17
  };
24
- const propertiesThatMustBeNumber = new Set(['lineHeight']);
25
- const displayValues = new Set(['flex', 'none']);
18
+ const propertiesThatMustBeNumber = new Set(["lineHeight"]);
19
+ const displayValues = new Set(["flex", "none"]);
26
20
  const SHOW_WARNINGS = false;
27
21
  function validateReactNativeStyles(styles) {
28
22
  for (const key in styles) {
29
23
  const propertyValue = styles[key];
30
- if (key === 'display' && !displayValues.has(propertyValue)) {
24
+ if (key === "display" && !displayValues.has(propertyValue)) {
31
25
  if (SHOW_WARNINGS) {
32
- console.warn(
33
- `Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
34
- );
26
+ console.warn(`Style value for key "display" must be "flex" or "none" but had ${propertyValue}`);
35
27
  }
36
28
  delete styles[key];
37
29
  }
38
- if (typeof propertyValue === 'string' && propertyValue.match(/^\-?\d/)) {
30
+ if (typeof propertyValue === "string" && propertyValue.match(/^\-?\d/)) {
39
31
  const newValue = parseFloat(propertyValue);
40
32
  if (!isNaN(newValue)) {
41
33
  styles[key] = newValue;
42
34
  }
43
- if (typeof newValue === 'number' && newValue < 0) {
35
+ if (typeof newValue === "number" && newValue < 0) {
44
36
  styles[key] = 0;
45
37
  }
46
38
  }
47
- if (
48
- propertiesThatMustBeNumber.has(key) &&
49
- typeof styles[key] !== 'number'
50
- ) {
39
+ if (propertiesThatMustBeNumber.has(key) && typeof styles[key] !== "number") {
51
40
  if (SHOW_WARNINGS) {
52
- console.warn(
53
- `Style key ${key} must be a number, but had value \`${styles[key]}\``
54
- );
41
+ console.warn(`Style key ${key} must be a number, but had value \`${styles[key]}\``);
55
42
  }
56
43
  delete styles[key];
57
44
  }
@@ -59,13 +46,7 @@ function validateReactNativeStyles(styles) {
59
46
  }
60
47
  function getBlockStyles(block) {
61
48
  var _a, _b, _c;
62
- const styles = __spreadValues(
63
- __spreadValues(
64
- {},
65
- (_a = block.responsiveStyles) == null ? void 0 : _a.large
66
- ),
67
- block.styles
68
- );
49
+ const styles = __spreadValues(__spreadValues({}, (_a = block.responsiveStyles) == null ? void 0 : _a.large), block.styles);
69
50
  if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
70
51
  Object.assign(styles, block.responsiveStyles.medium);
71
52
  }
@@ -75,4 +56,6 @@ function getBlockStyles(block) {
75
56
  validateReactNativeStyles(styles);
76
57
  return styles;
77
58
  }
78
- export { getBlockStyles };
59
+ export {
60
+ getBlockStyles
61
+ };
@@ -1,6 +1,8 @@
1
1
  import * as React from 'react';
2
- import { View } from 'react-native';
2
+ import { View } from "react-native";
3
3
  function getBlockTag(block) {
4
4
  return View;
5
5
  }
6
- export { getBlockTag };
6
+ export {
7
+ getBlockTag
8
+ };