@builder.io/sdk-react-native 0.0.1-49 → 0.0.1-51

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (142) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/package.json +1 -1
  3. package/src/blocks/button/button.js +31 -0
  4. package/src/blocks/{button.lite.tsx → button/button.lite.tsx} +3 -3
  5. package/src/blocks/button/component-info.js +42 -0
  6. package/src/blocks/columns/columns.js +59 -0
  7. package/src/blocks/{columns.lite.tsx → columns/columns.lite.tsx} +22 -21
  8. package/src/blocks/columns/component-info.js +218 -0
  9. package/src/blocks/custom-code/component-info.js +32 -0
  10. package/src/blocks/custom-code/custom-code.js +50 -0
  11. package/src/blocks/{custom-code.lite.tsx → custom-code/custom-code.lite.tsx} +11 -11
  12. package/src/blocks/embed/component-info.js +25 -0
  13. package/src/blocks/embed/embed.js +50 -0
  14. package/src/blocks/{embed.lite.tsx → embed/embed.lite.tsx} +11 -11
  15. package/src/blocks/form/component-info.js +263 -0
  16. package/src/blocks/form/form.js +221 -0
  17. package/src/blocks/{form.lite.tsx → form/form.lite.tsx} +51 -50
  18. package/src/blocks/fragment/component-info.js +12 -0
  19. package/src/blocks/fragment/fragment.js +8 -0
  20. package/src/blocks/{fragment.lite.tsx → fragment/fragment.lite.tsx} +2 -2
  21. package/src/blocks/image/component-info.js +105 -0
  22. package/src/blocks/image/image.js +41 -0
  23. package/src/blocks/{image.lite.tsx → image/image.lite.tsx} +11 -11
  24. package/src/blocks/img/component-info.js +21 -0
  25. package/src/blocks/img/img.js +36 -0
  26. package/src/blocks/img/img.lite.tsx +18 -0
  27. package/src/blocks/input/component-info.js +75 -0
  28. package/src/blocks/input/input.js +36 -0
  29. package/src/blocks/{input.lite.tsx → input/input.lite.tsx} +4 -4
  30. package/src/blocks/raw-text/component-info.js +17 -0
  31. package/src/blocks/raw-text/raw-text.js +10 -0
  32. package/src/blocks/raw-text/raw-text.lite.tsx +6 -0
  33. package/src/blocks/section/component-info.js +50 -0
  34. package/src/blocks/section/section.js +31 -0
  35. package/src/blocks/{section.lite.tsx → section/section.lite.tsx} +3 -3
  36. package/src/blocks/select/component-info.js +60 -0
  37. package/src/blocks/select/select.js +36 -0
  38. package/src/blocks/{select.lite.tsx → select/select.lite.tsx} +4 -4
  39. package/src/blocks/submit-button/component-info.js +29 -0
  40. package/src/blocks/submit-button/submit-button.js +29 -0
  41. package/src/blocks/{submit-button.lite.tsx → submit-button/submit-button.lite.tsx} +2 -2
  42. package/src/blocks/symbol/component-info.js +43 -0
  43. package/src/blocks/symbol/symbol.js +68 -0
  44. package/src/blocks/symbol/symbol.lite.tsx +60 -0
  45. package/src/blocks/text/component-info.js +25 -0
  46. package/src/blocks/text/text.js +65 -0
  47. package/src/blocks/text/text.lite.tsx +6 -0
  48. package/src/blocks/textarea/component-info.js +48 -0
  49. package/src/blocks/textarea/textarea.js +32 -0
  50. package/src/blocks/{textarea.lite.tsx → textarea/textarea.lite.tsx} +2 -2
  51. package/src/blocks/video/component-info.js +107 -0
  52. package/src/blocks/video/video.js +33 -0
  53. package/src/blocks/{video.lite.tsx → video/video.lite.tsx} +5 -5
  54. package/src/components/error-boundary.js +9 -11
  55. package/src/components/error-boundary.lite.tsx +2 -2
  56. package/src/components/render-block/block-styles.js +29 -0
  57. package/src/components/render-block/block-styles.lite.tsx +35 -0
  58. package/src/components/render-block/render-block.helpers.js +24 -0
  59. package/src/components/render-block/render-block.js +116 -0
  60. package/src/components/render-block/render-block.lite.tsx +139 -0
  61. package/src/components/render-blocks.js +35 -61
  62. package/src/components/render-blocks.lite.tsx +11 -11
  63. package/src/components/render-content/components/render-styles.js +58 -0
  64. package/src/components/render-content/components/render-styles.lite.tsx +70 -0
  65. package/src/components/render-content/index.js +5 -0
  66. package/src/components/render-content/render-content.js +254 -0
  67. package/src/components/render-content/render-content.lite.tsx +283 -0
  68. package/src/components/render-inlined-styles.js +18 -0
  69. package/src/components/render-inlined-styles.lite.tsx +31 -0
  70. package/src/constants/builder-registered-components.js +27 -0
  71. package/src/constants/device-sizes.js +11 -8
  72. package/src/constants/target.js +5 -0
  73. package/src/context/builder.context.js +11 -3
  74. package/src/functions/evaluate.js +20 -20
  75. package/src/functions/event-handler-name.js +3 -1
  76. package/src/functions/fast-clone.js +5 -0
  77. package/src/functions/get-block-actions.js +17 -16
  78. package/src/functions/get-block-component-options.js +9 -16
  79. package/src/functions/get-block-properties.js +14 -18
  80. package/src/functions/get-block-styles.js +17 -34
  81. package/src/functions/get-block-tag.js +4 -2
  82. package/src/functions/get-builder-search-params/fn.test.js +6 -10
  83. package/src/functions/get-builder-search-params/index.js +6 -3
  84. package/src/functions/get-content/fn.test.js +15 -17
  85. package/src/functions/get-content/index.js +25 -42
  86. package/src/functions/get-fetch.js +32 -8
  87. package/src/functions/get-global-this.js +7 -5
  88. package/src/functions/get-processed-block.js +13 -17
  89. package/src/functions/get-processed-block.test.js +16 -27
  90. package/src/functions/if-target.js +14 -3
  91. package/src/functions/is-browser.js +4 -2
  92. package/src/functions/is-editing.js +5 -5
  93. package/src/functions/is-iframe.js +4 -2
  94. package/src/functions/is-previewing.js +6 -4
  95. package/src/functions/is-react-native.js +3 -1
  96. package/src/functions/macro-eval.js +5 -2
  97. package/src/functions/on-change.js +7 -4
  98. package/src/functions/on-change.test.js +9 -10
  99. package/src/functions/previewing-model-name.js +5 -3
  100. package/src/functions/register-component.js +33 -44
  101. package/src/functions/register.js +10 -8
  102. package/src/functions/set-editor-settings.js +7 -5
  103. package/src/functions/set.js +5 -14
  104. package/src/functions/set.test.js +13 -14
  105. package/src/functions/track.js +13 -7
  106. package/src/functions/transform-block.js +13 -17
  107. package/src/index-helpers/blocks-exports.js +9 -9
  108. package/src/index-helpers/top-of-file.js +1 -1
  109. package/src/index.js +10 -12
  110. package/src/scripts/init-editing.js +74 -88
  111. package/src/types/components.js +1 -0
  112. package/src/types/element.js +1 -0
  113. package/src/types/targets.js +1 -0
  114. package/src/types/typescript.js +1 -0
  115. package/src/blocks/button.js +0 -86
  116. package/src/blocks/columns.js +0 -293
  117. package/src/blocks/custom-code.js +0 -83
  118. package/src/blocks/embed.js +0 -77
  119. package/src/blocks/form.js +0 -521
  120. package/src/blocks/fragment.js +0 -21
  121. package/src/blocks/image.js +0 -165
  122. package/src/blocks/img.js +0 -64
  123. package/src/blocks/img.lite.tsx +0 -18
  124. package/src/blocks/input.js +0 -113
  125. package/src/blocks/raw-text.js +0 -17
  126. package/src/blocks/raw-text.lite.tsx +0 -6
  127. package/src/blocks/section.js +0 -84
  128. package/src/blocks/select.js +0 -91
  129. package/src/blocks/submit-button.js +0 -60
  130. package/src/blocks/symbol.js +0 -20
  131. package/src/blocks/symbol.lite.tsx +0 -20
  132. package/src/blocks/text.js +0 -100
  133. package/src/blocks/text.lite.tsx +0 -6
  134. package/src/blocks/textarea.js +0 -73
  135. package/src/blocks/video.js +0 -100
  136. package/src/components/block-styles.js +0 -5
  137. package/src/components/block-styles.lite.tsx +0 -6
  138. package/src/components/render-block.js +0 -164
  139. package/src/components/render-block.lite.tsx +0 -132
  140. package/src/components/render-content.js +0 -220
  141. package/src/components/render-content.lite.tsx +0 -206
  142. package/src/functions/get-target.js +0 -5
@@ -1,100 +0,0 @@
1
- import * as React from 'react';
2
- import { View } from 'react-native';
3
- import ReactVideo from 'react-native-video';
4
- import { registerComponent } from '../functions/register-component';
5
- function Video(props) {
6
- return /* @__PURE__ */ React.createElement(
7
- View,
8
- {
9
- style: { position: 'relative' },
10
- },
11
- /* @__PURE__ */ React.createElement(ReactVideo, {
12
- paused: !props.autoPlay,
13
- controls: props.controls,
14
- muted: props.muted,
15
- repeat: props.loop,
16
- poster: props.posterImage,
17
- posterResizeMode: props.fit || 'contain',
18
- resizeMode: props.fit || 'contain',
19
- style: {
20
- position: 'absolute',
21
- top: 0,
22
- bottom: 0,
23
- left: 0,
24
- right: 0,
25
- zIndex: 1,
26
- },
27
- source: { uri: props.video },
28
- }),
29
- /* @__PURE__ */ React.createElement(View, {
30
- style: {
31
- width: '100%',
32
- paddingTop: `${props.aspectRatio * 100}%`,
33
- },
34
- })
35
- );
36
- }
37
- registerComponent(Video, {
38
- name: 'Video',
39
- static: true,
40
- builtIn: true,
41
- image:
42
- 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4',
43
- defaultStyles: {
44
- position: 'relative',
45
- minHeight: '20px',
46
- minWidth: '20px',
47
- overflow: 'hidden',
48
- },
49
- canHaveChildren: true,
50
- inputs: [
51
- {
52
- name: 'video',
53
- type: 'file',
54
- allowedFileTypes: ['mp4'],
55
- bubble: true,
56
- defaultValue:
57
- 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/assets%2FKQlEmWDxA0coC3PK6UvkrjwkIGI2%2F28cb070609f546cdbe5efa20e931aa4b?alt=media&token=912e9551-7a7c-4dfb-86b6-3da1537d1a7f',
58
- required: true,
59
- },
60
- {
61
- name: 'posterImage',
62
- type: 'file',
63
- allowedFileTypes: ['jpeg', 'png'],
64
- helperText: 'Image to show before the video plays',
65
- },
66
- {
67
- name: 'autoPlay',
68
- type: 'boolean',
69
- defaultValue: true,
70
- },
71
- {
72
- name: 'controls',
73
- type: 'boolean',
74
- defaultValue: false,
75
- },
76
- {
77
- name: 'muted',
78
- type: 'boolean',
79
- defaultValue: true,
80
- },
81
- {
82
- name: 'loop',
83
- type: 'boolean',
84
- defaultValue: true,
85
- },
86
- {
87
- name: 'fit',
88
- type: 'text',
89
- defaultValue: 'cover',
90
- enum: ['contain', 'cover', 'stretch'],
91
- },
92
- {
93
- name: 'aspectRatio',
94
- type: 'number',
95
- advanced: true,
96
- defaultValue: 0.7004048582995948,
97
- },
98
- ],
99
- });
100
- export { Video as default };
@@ -1,5 +0,0 @@
1
- import * as React from 'react';
2
- function BlockStyles(props) {
3
- return /* @__PURE__ */ React.createElement(React.Fragment, null);
4
- }
5
- export { BlockStyles as default };
@@ -1,6 +0,0 @@
1
- import * as React from 'react';
2
- import { View, StyleSheet, Image, Text } from 'react-native';
3
-
4
- export default function BlockStyles(props) {
5
- return <></>;
6
- }
@@ -1,164 +0,0 @@
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) =>
8
- key in obj
9
- ? __defProp(obj, key, {
10
- enumerable: true,
11
- configurable: true,
12
- writable: true,
13
- value,
14
- })
15
- : (obj[key] = value);
16
- var __spreadValues = (a, b) => {
17
- for (var prop in b || (b = {}))
18
- if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
19
- if (__getOwnPropSymbols)
20
- for (var prop of __getOwnPropSymbols(b)) {
21
- if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
22
- }
23
- return a;
24
- };
25
- var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
26
- import * as React from 'react';
27
- import { useContext } from 'react';
28
- import { getBlockComponentOptions } from '../functions/get-block-component-options';
29
- import { getBlockProperties } from '../functions/get-block-properties';
30
- import { getBlockStyles } from '../functions/get-block-styles';
31
- import { getBlockTag } from '../functions/get-block-tag';
32
- import { components } from '../functions/register-component';
33
- import BuilderContext from '../context/builder.context';
34
- import { getBlockActions } from '../functions/get-block-actions';
35
- import { getProcessedBlock } from '../functions/get-processed-block';
36
- import BlockStyles from './block-styles';
37
- function RenderBlock(props) {
38
- var _a, _b, _c, _d;
39
- function component() {
40
- var _a2, _b2;
41
- const componentName =
42
- (_a2 = useBlock().component) == null ? void 0 : _a2.name;
43
- if (!componentName) {
44
- return null;
45
- }
46
- const ref =
47
- components[(_b2 = useBlock().component) == null ? void 0 : _b2.name];
48
- if (componentName && !ref) {
49
- console.warn(`
50
- Could not find a registered component named "${componentName}".
51
- If you registered it, is the file that registered it imported by the file that needs to render it?`);
52
- }
53
- return ref;
54
- }
55
- function componentInfo() {
56
- var _a2;
57
- return (_a2 = component == null ? void 0 : component()) == null
58
- ? void 0
59
- : _a2.info;
60
- }
61
- function componentRef() {
62
- var _a2;
63
- return (_a2 = component == null ? void 0 : component()) == null
64
- ? void 0
65
- : _a2.component;
66
- }
67
- function tagName() {
68
- return getBlockTag(useBlock());
69
- }
70
- function properties() {
71
- return getBlockProperties(useBlock());
72
- }
73
- function useBlock() {
74
- return getProcessedBlock({
75
- block: props.block,
76
- state: builderContext.state,
77
- context: builderContext.context,
78
- });
79
- }
80
- function propertiesAndActions() {
81
- return __spreadValues(__spreadValues({}, properties()), actions());
82
- }
83
- function actions() {
84
- return getBlockActions({
85
- block: useBlock(),
86
- state: builderContext.state,
87
- context: builderContext.context,
88
- });
89
- }
90
- function css() {
91
- return getBlockStyles(useBlock());
92
- }
93
- function componentOptions() {
94
- return getBlockComponentOptions(useBlock());
95
- }
96
- function children() {
97
- var _a2;
98
- return (_a2 = useBlock().children) != null ? _a2 : [];
99
- }
100
- function noCompRefChildren() {
101
- return componentRef() ? [] : children();
102
- }
103
- const builderContext = useContext(BuilderContext);
104
- const ComponentRefRef = componentRef();
105
- const TagNameRef = tagName();
106
- return /* @__PURE__ */ React.createElement(
107
- React.Fragment,
108
- null,
109
- !((_a = componentInfo == null ? void 0 : componentInfo()) == null
110
- ? void 0
111
- : _a.noWrap)
112
- ? /* @__PURE__ */ React.createElement(
113
- React.Fragment,
114
- null,
115
- /* @__PURE__ */ React.createElement(
116
- TagNameRef,
117
- __spreadProps(__spreadValues({}, propertiesAndActions()), {
118
- style: css(),
119
- }),
120
- /* @__PURE__ */ React.createElement(BlockStyles, {
121
- block: useBlock(),
122
- }),
123
- componentRef()
124
- ? /* @__PURE__ */ React.createElement(
125
- ComponentRefRef,
126
- __spreadProps(__spreadValues({}, componentOptions()), {
127
- builderBlock: useBlock(),
128
- }),
129
- (_b = children()) == null
130
- ? void 0
131
- : _b.map((child) =>
132
- /* @__PURE__ */ React.createElement(RenderBlock, {
133
- block: child,
134
- })
135
- )
136
- )
137
- : null,
138
- (_c = noCompRefChildren()) == null
139
- ? void 0
140
- : _c.map((child) =>
141
- /* @__PURE__ */ React.createElement(RenderBlock, {
142
- block: child,
143
- })
144
- )
145
- )
146
- )
147
- : /* @__PURE__ */ React.createElement(
148
- ComponentRefRef,
149
- __spreadProps(__spreadValues({}, componentOptions()), {
150
- attributes: propertiesAndActions(),
151
- builderBlock: useBlock(),
152
- style: css(),
153
- }),
154
- (_d = children()) == null
155
- ? void 0
156
- : _d.map((child) =>
157
- /* @__PURE__ */ React.createElement(RenderBlock, {
158
- block: child,
159
- })
160
- )
161
- )
162
- );
163
- }
164
- export { RenderBlock as default };
@@ -1,132 +0,0 @@
1
- import * as React from 'react';
2
- import { View, StyleSheet, Image, Text } from 'react-native';
3
- import { useContext } from 'react';
4
- import { getBlockComponentOptions } from '../functions/get-block-component-options';
5
- import { getBlockProperties } from '../functions/get-block-properties';
6
- import { getBlockStyles } from '../functions/get-block-styles';
7
- import { getBlockTag } from '../functions/get-block-tag';
8
- import { components } from '../functions/register-component';
9
- import BuilderContext from '../context/builder.context.lite';
10
- import { getBlockActions } from '../functions/get-block-actions';
11
- import { getProcessedBlock } from '../functions/get-processed-block';
12
- import BlockStyles from './block-styles.lite';
13
-
14
- export default function RenderBlock(props) {
15
- function component() {
16
- const componentName = useBlock().component?.name;
17
-
18
- if (!componentName) {
19
- return null;
20
- }
21
-
22
- const ref = components[useBlock().component?.name];
23
-
24
- if (componentName && !ref) {
25
- // TODO: Public doc page with more info about this message
26
- console.warn(`
27
- Could not find a registered component named "${componentName}".
28
- If you registered it, is the file that registered it imported by the file that needs to render it?`);
29
- }
30
-
31
- return ref;
32
- }
33
-
34
- function componentInfo() {
35
- return component?.()?.info;
36
- }
37
-
38
- function componentRef() {
39
- return component?.()?.component;
40
- }
41
-
42
- function tagName() {
43
- return getBlockTag(useBlock());
44
- }
45
-
46
- function properties() {
47
- return getBlockProperties(useBlock());
48
- }
49
-
50
- function useBlock() {
51
- return getProcessedBlock({
52
- block: props.block,
53
- state: builderContext.state,
54
- context: builderContext.context,
55
- });
56
- }
57
-
58
- function propertiesAndActions() {
59
- return { ...properties(), ...actions() };
60
- }
61
-
62
- function actions() {
63
- return getBlockActions({
64
- block: useBlock(),
65
- state: builderContext.state,
66
- context: builderContext.context,
67
- });
68
- }
69
-
70
- function css() {
71
- return getBlockStyles(useBlock());
72
- }
73
-
74
- function componentOptions() {
75
- return getBlockComponentOptions(useBlock());
76
- }
77
-
78
- function children() {
79
- // TO-DO: When should `canHaveChildren` dictate rendering?
80
- // This is currently commented out because some Builder components (e.g. Box) do not have `canHaveChildren: true`,
81
- // but still receive and need to render children.
82
- // return componentInfo?.()?.canHaveChildren ? useBlock().children : [];
83
- return useBlock().children ?? [];
84
- }
85
-
86
- function noCompRefChildren() {
87
- return componentRef() ? [] : children();
88
- }
89
-
90
- const builderContext = useContext(BuilderContext);
91
-
92
- const ComponentRefRef = componentRef();
93
- const TagNameRef = tagName();
94
-
95
- return (
96
- <>
97
- {!componentInfo?.()?.noWrap ? (
98
- <>
99
- <TagNameRef {...propertiesAndActions()} style={css()}>
100
- <BlockStyles block={useBlock()} />
101
-
102
- {componentRef() ? (
103
- <ComponentRefRef
104
- {...componentOptions()}
105
- builderBlock={useBlock()}
106
- >
107
- {children()?.map((child) => (
108
- <RenderBlock block={child} />
109
- ))}
110
- </ComponentRefRef>
111
- ) : null}
112
-
113
- {noCompRefChildren()?.map((child) => (
114
- <RenderBlock block={child} />
115
- ))}
116
- </TagNameRef>
117
- </>
118
- ) : (
119
- <ComponentRefRef
120
- {...componentOptions()}
121
- attributes={propertiesAndActions()}
122
- builderBlock={useBlock()}
123
- style={css()}
124
- >
125
- {children()?.map((child) => (
126
- <RenderBlock block={child} />
127
- ))}
128
- </ComponentRefRef>
129
- )}
130
- </>
131
- );
132
- }
@@ -1,220 +0,0 @@
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 BuilderContext from '../context/builder.context';
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';
17
- function RenderContent(props) {
18
- var _a, _b, _c, _d, _e, _f, _g, _h;
19
- function useContent() {
20
- return overrideContent || props.content;
21
- }
22
- const [update, setUpdate] = useState(() => 0);
23
- const [state, setState] = useState(() => ({}));
24
- const [context, setContext] = useState(() => ({}));
25
- const [overrideContent, setOverrideContent] = useState(() => null);
26
- function getCssFromFont(font, data) {
27
- var _a2, _b2;
28
- const family =
29
- font.family +
30
- (font.kind && !font.kind.includes('#') ? ', ' + font.kind : '');
31
- const name = family.split(',')[0];
32
- const url =
33
- (_b2 = font.fileUrl) != null
34
- ? _b2
35
- : (_a2 = font == null ? void 0 : font.files) == null
36
- ? void 0
37
- : _a2.regular;
38
- let str = '';
39
- if (url && family && name) {
40
- str += `
41
- @font-face {
42
- font-family: "${family}";
43
- src: local("${name}"), url('${url}') format('woff2');
44
- font-display: fallback;
45
- font-weight: 400;
46
- }
47
- `.trim();
48
- }
49
- if (font.files) {
50
- for (const weight in font.files) {
51
- const isNumber = String(Number(weight)) === weight;
52
- if (!isNumber) {
53
- continue;
54
- }
55
- const weightUrl = font.files[weight];
56
- if (weightUrl && weightUrl !== url) {
57
- str += `
58
- @font-face {
59
- font-family: "${family}";
60
- src: url('${weightUrl}') format('woff2');
61
- font-display: fallback;
62
- font-weight: ${weight};
63
- }
64
- `.trim();
65
- }
66
- }
67
- }
68
- return str;
69
- }
70
- function getFontCss(data) {
71
- var _a2, _b2;
72
- return (
73
- ((_b2 =
74
- (_a2 = data == null ? void 0 : data.customFonts) == null
75
- ? void 0
76
- : _a2.map((font) => getCssFromFont(font, data))) == null
77
- ? void 0
78
- : _b2.join(' ')) || ''
79
- );
80
- }
81
- function processMessage(event) {
82
- const { data } = event;
83
- if (data) {
84
- switch (data.type) {
85
- case 'builder.contentUpdate': {
86
- const key =
87
- data.data.key ||
88
- data.data.alias ||
89
- data.data.entry ||
90
- data.data.modelName;
91
- const contentData = data.data.data;
92
- if (key === props.model) {
93
- setOverrideContent(contentData);
94
- }
95
- break;
96
- }
97
- case 'builder.patchUpdates': {
98
- break;
99
- }
100
- }
101
- }
102
- }
103
- useEffect(() => {
104
- if (isBrowser()) {
105
- if (isEditing()) {
106
- window.addEventListener('message', processMessage);
107
- }
108
- if (useContent() && !isEditing()) {
109
- track('impression', {
110
- contentId: useContent().id,
111
- });
112
- }
113
- if (isPreviewing()) {
114
- if (props.model && previewingModelName() === props.model) {
115
- const currentUrl = new URL(location.href);
116
- const apiKey = currentUrl.searchParams.get('apiKey');
117
- if (apiKey) {
118
- getContent({
119
- model: props.model,
120
- apiKey,
121
- options: getBuilderSearchParams(
122
- convertSearchParamsToQueryObject(currentUrl.searchParams)
123
- ),
124
- }).then((content) => {
125
- if (content) {
126
- setOverrideContent(content);
127
- }
128
- });
129
- }
130
- }
131
- }
132
- }
133
- }, []);
134
- useEffect(() => {
135
- return () => {
136
- if (isBrowser()) {
137
- window.removeEventListener('message', processMessage);
138
- }
139
- };
140
- }, []);
141
- return /* @__PURE__ */ React.createElement(
142
- BuilderContext.Provider,
143
- {
144
- value: {
145
- get content() {
146
- return useContent();
147
- },
148
- get state() {
149
- return state;
150
- },
151
- get context() {
152
- return context;
153
- },
154
- },
155
- },
156
- useContent()
157
- ? /* @__PURE__ */ React.createElement(
158
- React.Fragment,
159
- null,
160
- /* @__PURE__ */ React.createElement(
161
- View,
162
- {
163
- onClick: (event) => {
164
- if (!isEditing()) {
165
- track('click', {
166
- contentId: useContent().id,
167
- });
168
- }
169
- },
170
- 'data-builder-content-id':
171
- (_a = useContent == null ? void 0 : useContent()) == null
172
- ? void 0
173
- : _a.id,
174
- },
175
- (((_c =
176
- (_b = useContent == null ? void 0 : useContent()) == null
177
- ? void 0
178
- : _b.data) == null
179
- ? void 0
180
- : _c.cssCode) ||
181
- ((_f =
182
- (_e =
183
- (_d = useContent == null ? void 0 : useContent()) == null
184
- ? void 0
185
- : _d.data) == null
186
- ? void 0
187
- : _e.customFonts) == null
188
- ? void 0
189
- : _f.length)) &&
190
- !isReactNative()
191
- ? /* @__PURE__ */ React.createElement(
192
- View,
193
- null,
194
- /* @__PURE__ */ React.createElement(
195
- Text,
196
- null,
197
- useContent().data.cssCode
198
- ),
199
- /* @__PURE__ */ React.createElement(
200
- Text,
201
- null,
202
- getFontCss(useContent().data)
203
- )
204
- )
205
- : null,
206
- /* @__PURE__ */ React.createElement(RenderBlocks, {
207
- blocks:
208
- (_h =
209
- (_g = useContent == null ? void 0 : useContent()) == null
210
- ? void 0
211
- : _g.data) == null
212
- ? void 0
213
- : _h.blocks,
214
- })
215
- )
216
- )
217
- : null
218
- );
219
- }
220
- export { RenderContent as default };