@builder.io/sdk-react-native 0.0.1-34 → 0.0.1-38

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 (83) hide show
  1. package/package.json +1 -1
  2. package/src/blocks/button.js +86 -0
  3. package/src/blocks/button.lite.tsx +25 -0
  4. package/src/blocks/columns.js +265 -0
  5. package/src/blocks/columns.lite.tsx +40 -0
  6. package/src/blocks/custom-code.js +85 -0
  7. package/src/blocks/custom-code.lite.tsx +67 -0
  8. package/src/blocks/embed.js +78 -0
  9. package/src/blocks/embed.lite.tsx +65 -0
  10. package/src/blocks/form.js +522 -0
  11. package/src/blocks/form.lite.tsx +253 -0
  12. package/src/blocks/fragment.js +21 -0
  13. package/src/blocks/fragment.lite.tsx +10 -0
  14. package/src/blocks/image.js +129 -0
  15. package/src/blocks/image.lite.tsx +68 -0
  16. package/src/blocks/img.js +64 -0
  17. package/src/blocks/img.lite.tsx +18 -0
  18. package/src/blocks/input.js +113 -0
  19. package/src/blocks/input.lite.tsx +20 -0
  20. package/src/blocks/raw-text.js +21 -0
  21. package/src/blocks/raw-text.lite.tsx +11 -0
  22. package/src/blocks/section.js +84 -0
  23. package/src/blocks/section.lite.tsx +19 -0
  24. package/src/blocks/select.js +91 -0
  25. package/src/blocks/select.lite.tsx +23 -0
  26. package/src/blocks/submit-button.js +60 -0
  27. package/src/blocks/submit-button.lite.tsx +10 -0
  28. package/src/blocks/symbol.js +22 -0
  29. package/src/blocks/symbol.lite.tsx +20 -0
  30. package/src/blocks/text.js +100 -0
  31. package/src/blocks/text.lite.tsx +11 -0
  32. package/src/blocks/textarea.js +73 -0
  33. package/src/blocks/textarea.lite.tsx +14 -0
  34. package/src/blocks/video.js +100 -0
  35. package/src/blocks/video.lite.tsx +27 -0
  36. package/src/components/block-styles.js +5 -0
  37. package/src/components/block-styles.lite.tsx +6 -0
  38. package/src/components/error-boundary.js +27 -0
  39. package/src/components/error-boundary.lite.tsx +6 -0
  40. package/src/components/render-block.js +169 -0
  41. package/src/components/render-block.lite.tsx +129 -0
  42. package/src/components/render-blocks.js +73 -0
  43. package/src/components/render-blocks.lite.tsx +59 -0
  44. package/src/components/render-content.js +215 -0
  45. package/src/components/render-content.lite.tsx +207 -0
  46. package/src/constants/device-sizes.js +37 -0
  47. package/src/context/builder.context.js +3 -0
  48. package/src/functions/evaluate.js +29 -0
  49. package/src/functions/event-handler-name.js +6 -0
  50. package/src/functions/get-block-actions.js +23 -0
  51. package/src/functions/get-block-component-options.js +31 -0
  52. package/src/functions/get-block-properties.js +47 -0
  53. package/src/functions/get-block-styles.js +78 -0
  54. package/src/functions/get-block-tag.js +6 -0
  55. package/src/functions/get-content.js +150 -0
  56. package/src/functions/get-content.test.js +58 -0
  57. package/src/functions/get-fetch.js +11 -0
  58. package/src/functions/get-global-this.js +17 -0
  59. package/src/functions/get-processed-block.js +51 -0
  60. package/src/functions/get-processed-block.test.js +31 -0
  61. package/src/functions/get-target.js +5 -0
  62. package/src/functions/if-target.js +5 -0
  63. package/src/functions/is-browser.js +10 -0
  64. package/src/functions/is-editing.js +8 -0
  65. package/src/functions/is-iframe.js +6 -0
  66. package/src/functions/is-previewing.js +13 -0
  67. package/src/functions/is-react-native.js +5 -0
  68. package/src/functions/macro-eval.js +3 -0
  69. package/src/functions/on-change.js +25 -0
  70. package/src/functions/on-change.test.js +21 -0
  71. package/src/functions/previewing-model-name.js +10 -0
  72. package/src/functions/register-component.js +65 -0
  73. package/src/functions/register.js +28 -0
  74. package/src/functions/set-editor-settings.js +14 -0
  75. package/src/functions/set.js +21 -0
  76. package/src/functions/set.test.js +18 -0
  77. package/src/functions/track.js +17 -0
  78. package/src/functions/transform-block.js +40 -0
  79. package/src/index.js +30 -0
  80. package/src/scripts/init-editing.js +95 -0
  81. package/src/types/builder-block.js +1 -0
  82. package/src/types/builder-content.js +1 -0
  83. package/src/types/deep-partial.js +1 -0
@@ -0,0 +1,215 @@
1
+ import * as React from 'react';
2
+ import { View, Text } from 'react-native';
3
+ import { useState, useEffect } from 'react';
4
+ import { isBrowser } from '../functions/is-browser';
5
+ import RenderBlock from './render-block';
6
+ import BuilderContext from '../context/builder.context';
7
+ import { track } from '../functions/track';
8
+ import { isReactNative } from '../functions/is-react-native';
9
+ import { isEditing } from '../functions/is-editing';
10
+ import { isPreviewing } from '../functions/is-previewing';
11
+ import { previewingModelName } from '../functions/previewing-model-name';
12
+ import { getContent } from '../functions/get-content';
13
+ function RenderContent(props) {
14
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
15
+ function useContent() {
16
+ return overrideContent || props.content;
17
+ }
18
+ const [update, setUpdate] = useState(() => 0);
19
+ const [state, setState] = useState(() => ({}));
20
+ const [context, setContext] = useState(() => ({}));
21
+ const [overrideContent, setOverrideContent] = useState(() => null);
22
+ function getCssFromFont(font, data) {
23
+ const family =
24
+ font.family +
25
+ (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
26
+ const name = family.split(',')[0];
27
+ const url = font.fileUrl ? font.fileUrl : font.files && font.files.regular;
28
+ let str = '';
29
+ if (url && family && name) {
30
+ str += `
31
+ @font-face {
32
+ font-family: "${family}";
33
+ src: local("${name}"), url('${url}') format('woff2');
34
+ font-display: fallback;
35
+ font-weight: 400;
36
+ }
37
+ `.trim();
38
+ }
39
+ if (font.files) {
40
+ for (const weight in font.files) {
41
+ const isNumber = String(Number(weight)) === weight;
42
+ if (!isNumber) {
43
+ continue;
44
+ }
45
+ const weightUrl = font.files[weight];
46
+ if (weightUrl && weightUrl !== url) {
47
+ str += `
48
+ @font-face {
49
+ font-family: "${family}";
50
+ src: url('${weightUrl}') format('woff2');
51
+ font-display: fallback;
52
+ font-weight: ${weight};
53
+ }
54
+ `.trim();
55
+ }
56
+ }
57
+ }
58
+ return str;
59
+ }
60
+ function getFontCss(data) {
61
+ return (
62
+ ((data == null ? void 0 : data.customFonts) &&
63
+ data.customFonts.length &&
64
+ data.customFonts
65
+ .map((font) => this.getCssFromFont(font, data))
66
+ .join(' ')) ||
67
+ ''
68
+ );
69
+ }
70
+ function processMessage(event) {
71
+ const { data } = event;
72
+ if (data) {
73
+ switch (data.type) {
74
+ case 'builder.contentUpdate': {
75
+ const key =
76
+ data.data.key ||
77
+ data.data.alias ||
78
+ data.data.entry ||
79
+ data.data.modelName;
80
+ const contentData = data.data.data;
81
+ if (key === props.model) {
82
+ setOverrideContent(contentData);
83
+ }
84
+ break;
85
+ }
86
+ case 'builder.patchUpdates': {
87
+ break;
88
+ }
89
+ }
90
+ }
91
+ }
92
+ useEffect(() => {
93
+ if (isBrowser()) {
94
+ if (isEditing()) {
95
+ window.addEventListener('message', processMessage);
96
+ }
97
+ if (useContent() && !isEditing()) {
98
+ track('impression', {
99
+ contentId: useContent().id,
100
+ });
101
+ }
102
+ if (isPreviewing()) {
103
+ if (props.model && previewingModelName() === props.model) {
104
+ const options = {};
105
+ const currentUrl = new URL(location.href);
106
+ const apiKey = currentUrl.searchParams.get('apiKey');
107
+ if (apiKey) {
108
+ const builderPrefix = 'builder.';
109
+ currentUrl.searchParams.forEach((value, key) => {
110
+ if (key.startsWith(builderPrefix)) {
111
+ options[key.replace(builderPrefix, '')] = value;
112
+ }
113
+ });
114
+ getContent({
115
+ model: props.model,
116
+ apiKey,
117
+ options,
118
+ }).then((content) => {
119
+ if (content) {
120
+ setOverrideContent(content);
121
+ }
122
+ });
123
+ }
124
+ }
125
+ }
126
+ }
127
+ }, []);
128
+ return /* @__PURE__ */ React.createElement(
129
+ BuilderContext.Provider,
130
+ {
131
+ value: {
132
+ get content() {
133
+ return useContent();
134
+ },
135
+ get state() {
136
+ return state;
137
+ },
138
+ get context() {
139
+ return context;
140
+ },
141
+ },
142
+ },
143
+ useContent()
144
+ ? /* @__PURE__ */ React.createElement(
145
+ React.Fragment,
146
+ null,
147
+ /* @__PURE__ */ React.createElement(
148
+ View,
149
+ {
150
+ onClick: (event) => {
151
+ if (!isEditing()) {
152
+ track('click', {
153
+ contentId: useContent().id,
154
+ });
155
+ }
156
+ },
157
+ 'data-builder-content-id':
158
+ (_a = useContent == null ? void 0 : useContent()) == null
159
+ ? void 0
160
+ : _a.id,
161
+ },
162
+ (((_c =
163
+ (_b = useContent == null ? void 0 : useContent()) == null
164
+ ? void 0
165
+ : _b.data) == null
166
+ ? void 0
167
+ : _c.cssCode) ||
168
+ (((_e =
169
+ (_d = useContent == null ? void 0 : useContent()) == null
170
+ ? void 0
171
+ : _d.data) == null
172
+ ? void 0
173
+ : _e.customFonts) &&
174
+ ((_g =
175
+ (_f = useContent == null ? void 0 : useContent()) == null
176
+ ? void 0
177
+ : _f.data) == null
178
+ ? void 0
179
+ : _g.customFonts.length))) &&
180
+ !isReactNative()
181
+ ? /* @__PURE__ */ React.createElement(
182
+ View,
183
+ null,
184
+ /* @__PURE__ */ React.createElement(
185
+ Text,
186
+ null,
187
+ useContent().data.cssCode
188
+ ),
189
+ /* @__PURE__ */ React.createElement(
190
+ Text,
191
+ null,
192
+ getFontCss(useContent().data)
193
+ )
194
+ )
195
+ : null,
196
+ (_j =
197
+ (_i =
198
+ (_h = useContent == null ? void 0 : useContent()) == null
199
+ ? void 0
200
+ : _h.data) == null
201
+ ? void 0
202
+ : _i.blocks) == null
203
+ ? void 0
204
+ : _j.map((block) =>
205
+ /* @__PURE__ */ React.createElement(RenderBlock, {
206
+ key: block.id,
207
+ block,
208
+ })
209
+ )
210
+ )
211
+ )
212
+ : null
213
+ );
214
+ }
215
+ export { RenderContent as default };
@@ -0,0 +1,207 @@
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';
15
+
16
+ export default function RenderContent(props) {
17
+ function useContent() {
18
+ return overrideContent || props.content;
19
+ }
20
+
21
+ const [update, setUpdate] = useState(() => 0);
22
+
23
+ const [state, setState] = useState(() => ({}));
24
+
25
+ const [context, setContext] = useState(() => ({}));
26
+
27
+ const [overrideContent, setOverrideContent] = useState(() => null);
28
+
29
+ function getCssFromFont(font, data) {
30
+ // TODO: compute what font sizes are used and only load those.......
31
+ const family =
32
+ font.family +
33
+ (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
34
+ const name = family.split(',')[0];
35
+ const url = font.fileUrl ? font.fileUrl : font.files && font.files.regular;
36
+ let str = '';
37
+
38
+ if (url && family && name) {
39
+ str += `
40
+ @font-face {
41
+ font-family: "${family}";
42
+ src: local("${name}"), url('${url}') format('woff2');
43
+ font-display: fallback;
44
+ font-weight: 400;
45
+ }
46
+ `.trim();
47
+ }
48
+
49
+ if (font.files) {
50
+ for (const weight in font.files) {
51
+ const isNumber = String(Number(weight)) === weight;
52
+
53
+ if (!isNumber) {
54
+ continue;
55
+ } // TODO: maybe limit number loaded
56
+
57
+ const weightUrl = font.files[weight];
58
+
59
+ if (weightUrl && weightUrl !== url) {
60
+ str += `
61
+ @font-face {
62
+ font-family: "${family}";
63
+ src: url('${weightUrl}') format('woff2');
64
+ font-display: fallback;
65
+ font-weight: ${weight};
66
+ }
67
+ `.trim();
68
+ }
69
+ }
70
+ }
71
+
72
+ return str;
73
+ }
74
+
75
+ function getFontCss(data) {
76
+ // TODO: flag for this
77
+ // if (!this.builder.allowCustomFonts) {
78
+ // return '';
79
+ // }
80
+ // TODO: separate internal data from external
81
+ return (
82
+ (data?.customFonts &&
83
+ data.customFonts.length &&
84
+ data.customFonts
85
+ .map((font) => this.getCssFromFont(font, data))
86
+ .join(' ')) ||
87
+ ''
88
+ );
89
+ }
90
+
91
+ function processMessage(event) {
92
+ const { data } = event;
93
+
94
+ if (data) {
95
+ switch (data.type) {
96
+ case 'builder.contentUpdate': {
97
+ const key =
98
+ data.data.key ||
99
+ data.data.alias ||
100
+ data.data.entry ||
101
+ data.data.modelName;
102
+ const contentData = data.data.data; // oof
103
+
104
+ if (key === props.model) {
105
+ setOverrideContent(contentData);
106
+ }
107
+
108
+ break;
109
+ }
110
+
111
+ case 'builder.patchUpdates': {
112
+ // TODO
113
+ break;
114
+ }
115
+ }
116
+ }
117
+ }
118
+
119
+ useEffect(() => {
120
+ if (isBrowser()) {
121
+ if (isEditing()) {
122
+ window.addEventListener('message', processMessage);
123
+ }
124
+
125
+ if (useContent() && !isEditing()) {
126
+ track('impression', {
127
+ contentId: useContent().id,
128
+ });
129
+ }
130
+
131
+ if (isPreviewing()) {
132
+ if (props.model && previewingModelName() === props.model) {
133
+ const options = {};
134
+ const currentUrl = new URL(location.href);
135
+ const apiKey = currentUrl.searchParams.get('apiKey');
136
+
137
+ if (apiKey) {
138
+ const builderPrefix = 'builder.';
139
+ currentUrl.searchParams.forEach((value, key) => {
140
+ if (key.startsWith(builderPrefix)) {
141
+ options[key.replace(builderPrefix, '')] = value;
142
+ }
143
+ }); // TODO: need access to API key
144
+
145
+ getContent({
146
+ model: props.model,
147
+ apiKey,
148
+ options,
149
+ }).then((content) => {
150
+ if (content) {
151
+ setOverrideContent(content);
152
+ }
153
+ });
154
+ } // TODO: fetch content and override. Forward all builder.* params
155
+ }
156
+ }
157
+ }
158
+ }, []);
159
+
160
+ return (
161
+ <BuilderContext.Provider
162
+ value={{
163
+ get content() {
164
+ return useContent();
165
+ },
166
+
167
+ get state() {
168
+ return state;
169
+ },
170
+
171
+ get context() {
172
+ return context;
173
+ },
174
+ }}
175
+ >
176
+ {useContent() ? (
177
+ <>
178
+ <View
179
+ onClick={(event) => {
180
+ if (!isEditing()) {
181
+ track('click', {
182
+ contentId: useContent().id,
183
+ });
184
+ }
185
+ }}
186
+ data-builder-content-id={useContent?.()?.id}
187
+ >
188
+ {(useContent?.()?.data?.cssCode ||
189
+ (useContent?.()?.data?.customFonts &&
190
+ useContent?.()?.data?.customFonts.length)) &&
191
+ !isReactNative() ? (
192
+ <View>
193
+ <Text>{useContent().data.cssCode}</Text>
194
+
195
+ <Text>{getFontCss(useContent().data)}</Text>
196
+ </View>
197
+ ) : null}
198
+
199
+ {useContent?.()?.data?.blocks?.map((block) => (
200
+ <RenderBlock key={block.id} block={block} />
201
+ ))}
202
+ </View>
203
+ </>
204
+ ) : null}
205
+ </BuilderContext.Provider>
206
+ );
207
+ }
@@ -0,0 +1,37 @@
1
+ import * as React from 'react';
2
+ const sizeNames = ['xsmall', 'small', 'medium', 'large'];
3
+ const sizes = {
4
+ xsmall: {
5
+ min: 0,
6
+ default: 0,
7
+ max: 0,
8
+ },
9
+ small: {
10
+ min: 320,
11
+ default: 321,
12
+ max: 640,
13
+ },
14
+ medium: {
15
+ min: 641,
16
+ default: 642,
17
+ max: 991,
18
+ },
19
+ large: {
20
+ min: 990,
21
+ default: 991,
22
+ max: 1200,
23
+ },
24
+ getWidthForSize(size) {
25
+ return this[size].default;
26
+ },
27
+ getSizeForWidth(width) {
28
+ for (const size of sizeNames) {
29
+ const value = this[size];
30
+ if (width <= value.max) {
31
+ return size;
32
+ }
33
+ }
34
+ return 'large';
35
+ },
36
+ };
37
+ export { sizeNames, sizes };
@@ -0,0 +1,3 @@
1
+ import { createContext } from 'react';
2
+ var stdin_default = createContext({ content: null, context: {}, state: {} });
3
+ export { stdin_default as default };
@@ -0,0 +1,29 @@
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;
6
+ const builder = {
7
+ isEditing: isEditing(),
8
+ isBrowser: isBrowser(),
9
+ };
10
+ const useReturn = !(
11
+ code.includes(';') ||
12
+ code.includes(' return ') ||
13
+ code.trim().startsWith('return ')
14
+ );
15
+ const useCode = `${useReturn ? `return (${code});` : code}`;
16
+ 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);
25
+ } catch (e) {
26
+ console.warn('Builder custom code error: ', e);
27
+ }
28
+ }
29
+ export { evaluate };
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ function capitalizeFirstLetter(string) {
3
+ return string.charAt(0).toUpperCase() + string.slice(1);
4
+ }
5
+ const getEventHandlerName = (key) => `on${capitalizeFirstLetter(key)}`;
6
+ export { getEventHandlerName };
@@ -0,0 +1,23 @@
1
+ import * as React from 'react';
2
+ import { evaluate } from './evaluate';
3
+ import { getEventHandlerName } from './name-event-handlers';
4
+ function getBlockActions(options) {
5
+ 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
+ });
19
+ }
20
+ }
21
+ return obj;
22
+ }
23
+ export { getBlockActions };
@@ -0,0 +1,31 @@
1
+ import * as React from 'react';
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
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);
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ function getBlockComponentOptions(block) {
25
+ var _a;
26
+ return __spreadValues(
27
+ __spreadValues({}, (_a = block.component) == null ? void 0 : _a.options),
28
+ block.options
29
+ );
30
+ }
31
+ export { getBlockComponentOptions };
@@ -0,0 +1,47 @@
1
+ import * as React from 'react';
2
+ var __defProp = Object.defineProperty;
3
+ var __defProps = Object.defineProperties;
4
+ var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
5
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
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);
17
+ var __spreadValues = (a, b) => {
18
+ for (var prop in b || (b = {}))
19
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
20
+ if (__getOwnPropSymbols)
21
+ for (var prop of __getOwnPropSymbols(b)) {
22
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
23
+ }
24
+ return a;
25
+ };
26
+ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27
+ import { findDOMNode } from 'react-dom';
28
+ import { isBrowser } from './is-browser';
29
+ import { isReactNative } from './is-react-native';
30
+ function getBlockProperties(block) {
31
+ return __spreadProps(__spreadValues({}, block.properties), {
32
+ ref: (ref) => {
33
+ if (isBrowser() && !isReactNative()) {
34
+ const el = findDOMNode(ref);
35
+ if (el) {
36
+ el.setAttribute('builder-id', block.id);
37
+ el.classList.add(block.id);
38
+ }
39
+ }
40
+ },
41
+ dataSet: {
42
+ 'builder-id': block.id,
43
+ class: [block.id, 'builder-block', block.class].filter(Boolean).join(' '),
44
+ },
45
+ });
46
+ }
47
+ export { getBlockProperties };
@@ -0,0 +1,78 @@
1
+ import * as React from 'react';
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
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);
15
+ var __spreadValues = (a, b) => {
16
+ for (var prop in b || (b = {}))
17
+ if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
18
+ if (__getOwnPropSymbols)
19
+ for (var prop of __getOwnPropSymbols(b)) {
20
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
21
+ }
22
+ return a;
23
+ };
24
+ const propertiesThatMustBeNumber = new Set(['lineHeight']);
25
+ const displayValues = new Set(['flex', 'none']);
26
+ const SHOW_WARNINGS = false;
27
+ function validateReactNativeStyles(styles) {
28
+ for (const key in styles) {
29
+ const propertyValue = styles[key];
30
+ if (key === 'display' && !displayValues.has(propertyValue)) {
31
+ if (SHOW_WARNINGS) {
32
+ console.warn(
33
+ `Style value for key "display" must be "flex" or "none" but had ${propertyValue}`
34
+ );
35
+ }
36
+ delete styles[key];
37
+ }
38
+ if (typeof propertyValue === 'string' && propertyValue.match(/^\-?\d/)) {
39
+ const newValue = parseFloat(propertyValue);
40
+ if (!isNaN(newValue)) {
41
+ styles[key] = newValue;
42
+ }
43
+ if (typeof newValue === 'number' && newValue < 0) {
44
+ styles[key] = 0;
45
+ }
46
+ }
47
+ if (
48
+ propertiesThatMustBeNumber.has(key) &&
49
+ typeof styles[key] !== 'number'
50
+ ) {
51
+ if (SHOW_WARNINGS) {
52
+ console.warn(
53
+ `Style key ${key} must be a number, but had value \`${styles[key]}\``
54
+ );
55
+ }
56
+ delete styles[key];
57
+ }
58
+ }
59
+ }
60
+ function getBlockStyles(block) {
61
+ 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
+ );
69
+ if ((_b = block.responsiveStyles) == null ? void 0 : _b.medium) {
70
+ Object.assign(styles, block.responsiveStyles.medium);
71
+ }
72
+ if ((_c = block.responsiveStyles) == null ? void 0 : _c.small) {
73
+ Object.assign(styles, block.responsiveStyles.small);
74
+ }
75
+ validateReactNativeStyles(styles);
76
+ return styles;
77
+ }
78
+ export { getBlockStyles };
@@ -0,0 +1,6 @@
1
+ import * as React from 'react';
2
+ import { View } from 'react-native';
3
+ function getBlockTag(block) {
4
+ return View;
5
+ }
6
+ export { getBlockTag };