@builder.io/sdk-react-native 1.0.31-0 → 1.0.31

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 (261) hide show
  1. package/lib/browser/commonjs/blocks/symbol/symbol.js +1 -0
  2. package/lib/browser/commonjs/blocks/symbol/symbol.js.map +1 -1
  3. package/lib/browser/commonjs/components/content/content.js +1 -0
  4. package/lib/browser/commonjs/components/content/content.js.map +1 -1
  5. package/lib/browser/commonjs/constants/sdk-version.js +1 -1
  6. package/lib/browser/module/blocks/symbol/symbol.js +1 -0
  7. package/lib/browser/module/blocks/symbol/symbol.js.map +1 -1
  8. package/lib/browser/module/components/content/content.js +1 -0
  9. package/lib/browser/module/components/content/content.js.map +1 -1
  10. package/lib/browser/module/constants/sdk-version.js +1 -1
  11. package/lib/browser/typescript/blocks/symbol/symbol.d.ts.map +1 -1
  12. package/lib/browser/typescript/components/content/content.d.ts.map +1 -1
  13. package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
  14. package/lib/browser/typescript/context/types.d.ts +1 -0
  15. package/lib/browser/typescript/context/types.d.ts.map +1 -1
  16. package/lib/edge/commonjs/blocks/symbol/symbol.js +1 -0
  17. package/lib/edge/commonjs/blocks/symbol/symbol.js.map +1 -1
  18. package/lib/edge/commonjs/components/content/content.js +1 -0
  19. package/lib/edge/commonjs/components/content/content.js.map +1 -1
  20. package/lib/edge/commonjs/constants/sdk-version.js +1 -1
  21. package/lib/edge/module/blocks/symbol/symbol.js +1 -0
  22. package/lib/edge/module/blocks/symbol/symbol.js.map +1 -1
  23. package/lib/edge/module/components/content/content.js +1 -0
  24. package/lib/edge/module/components/content/content.js.map +1 -1
  25. package/lib/edge/module/constants/sdk-version.js +1 -1
  26. package/lib/edge/typescript/blocks/symbol/symbol.d.ts.map +1 -1
  27. package/lib/edge/typescript/components/content/content.d.ts.map +1 -1
  28. package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
  29. package/lib/edge/typescript/context/types.d.ts +1 -0
  30. package/lib/edge/typescript/context/types.d.ts.map +1 -1
  31. package/lib/node/commonjs/blocks/symbol/symbol.js +1 -0
  32. package/lib/node/commonjs/blocks/symbol/symbol.js.map +1 -1
  33. package/lib/node/commonjs/components/content/content.js +1 -0
  34. package/lib/node/commonjs/components/content/content.js.map +1 -1
  35. package/lib/node/commonjs/constants/sdk-version.js +1 -1
  36. package/lib/node/module/blocks/symbol/symbol.js +1 -0
  37. package/lib/node/module/blocks/symbol/symbol.js.map +1 -1
  38. package/lib/node/module/components/content/content.js +1 -0
  39. package/lib/node/module/components/content/content.js.map +1 -1
  40. package/lib/node/module/constants/sdk-version.js +1 -1
  41. package/lib/node/typescript/blocks/symbol/symbol.d.ts.map +1 -1
  42. package/lib/node/typescript/components/content/content.d.ts.map +1 -1
  43. package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
  44. package/lib/node/typescript/context/types.d.ts +1 -0
  45. package/lib/node/typescript/context/types.d.ts.map +1 -1
  46. package/package.json +5 -9
  47. package/lib/node/index.cjs +0 -6910
  48. package/lib/node/index.mjs +0 -7477
  49. package/src/blocks/BaseText.tsx +0 -17
  50. package/src/blocks/accordion/accordion.tsx +0 -181
  51. package/src/blocks/accordion/accordion.types.ts +0 -12
  52. package/src/blocks/accordion/component-info.ts +0 -124
  53. package/src/blocks/accordion/helpers.ts +0 -3
  54. package/src/blocks/accordion/index.ts +0 -1
  55. package/src/blocks/button/button.tsx +0 -56
  56. package/src/blocks/button/button.types.ts +0 -7
  57. package/src/blocks/button/component-info.ts +0 -35
  58. package/src/blocks/button/index.ts +0 -1
  59. package/src/blocks/columns/columns.tsx +0 -199
  60. package/src/blocks/columns/columns.types.ts +0 -14
  61. package/src/blocks/columns/component-info.ts +0 -219
  62. package/src/blocks/columns/helpers.ts +0 -3
  63. package/src/blocks/columns/index.ts +0 -1
  64. package/src/blocks/custom-code/component-info.ts +0 -24
  65. package/src/blocks/custom-code/custom-code.tsx +0 -71
  66. package/src/blocks/custom-code/index.ts +0 -1
  67. package/src/blocks/embed/component-info.ts +0 -38
  68. package/src/blocks/embed/embed.tsx +0 -62
  69. package/src/blocks/embed/helpers.ts +0 -2
  70. package/src/blocks/embed/index.ts +0 -1
  71. package/src/blocks/form/form/component-info.ts +0 -233
  72. package/src/blocks/form/form/form.tsx +0 -324
  73. package/src/blocks/form/form/index.ts +0 -1
  74. package/src/blocks/form/input/component-info.ts +0 -47
  75. package/src/blocks/form/input/index.ts +0 -1
  76. package/src/blocks/form/input/input.tsx +0 -49
  77. package/src/blocks/form/select/component-info.ts +0 -44
  78. package/src/blocks/form/select/index.ts +0 -1
  79. package/src/blocks/form/select/select.tsx +0 -54
  80. package/src/blocks/form/submit-button/component-info.ts +0 -27
  81. package/src/blocks/form/submit-button/index.ts +0 -1
  82. package/src/blocks/form/submit-button/submit-button.tsx +0 -34
  83. package/src/blocks/fragment/component-info.ts +0 -8
  84. package/src/blocks/fragment/fragment.tsx +0 -18
  85. package/src/blocks/fragment/fragment.types.ts +0 -5
  86. package/src/blocks/fragment/index.ts +0 -1
  87. package/src/blocks/helpers.ts +0 -43
  88. package/src/blocks/image/component-info.ts +0 -124
  89. package/src/blocks/image/image.helpers.ts +0 -47
  90. package/src/blocks/image/image.tsx +0 -65
  91. package/src/blocks/image/image.types.ts +0 -19
  92. package/src/blocks/image/index.ts +0 -1
  93. package/src/blocks/img/component-info.ts +0 -16
  94. package/src/blocks/img/img.tsx +0 -55
  95. package/src/blocks/img/index.ts +0 -1
  96. package/src/blocks/raw-text/component-info.ts +0 -11
  97. package/src/blocks/raw-text/index.ts +0 -1
  98. package/src/blocks/raw-text/raw-text.tsx +0 -1
  99. package/src/blocks/section/component-info.ts +0 -41
  100. package/src/blocks/section/index.ts +0 -1
  101. package/src/blocks/section/section.tsx +0 -39
  102. package/src/blocks/section/section.types.ts +0 -6
  103. package/src/blocks/slot/component-info.ts +0 -15
  104. package/src/blocks/slot/index.ts +0 -1
  105. package/src/blocks/slot/slot.tsx +0 -42
  106. package/src/blocks/symbol/component-info.ts +0 -35
  107. package/src/blocks/symbol/index.ts +0 -1
  108. package/src/blocks/symbol/symbol.helpers.ts +0 -47
  109. package/src/blocks/symbol/symbol.tsx +0 -99
  110. package/src/blocks/symbol/symbol.types.ts +0 -17
  111. package/src/blocks/tabs/component-info.ts +0 -139
  112. package/src/blocks/tabs/index.ts +0 -1
  113. package/src/blocks/tabs/tabs.tsx +0 -79
  114. package/src/blocks/tabs/tabs.types.ts +0 -13
  115. package/src/blocks/text/component-info.ts +0 -20
  116. package/src/blocks/text/index.ts +0 -1
  117. package/src/blocks/text/text.tsx +0 -105
  118. package/src/blocks/text/text.types.ts +0 -4
  119. package/src/blocks/textarea/component-info.ts +0 -38
  120. package/src/blocks/textarea/index.ts +0 -1
  121. package/src/blocks/textarea/textarea.tsx +0 -41
  122. package/src/blocks/video/component-info.ts +0 -83
  123. package/src/blocks/video/index.ts +0 -1
  124. package/src/blocks/video/video.tsx +0 -70
  125. package/src/blocks/video/video.types.ts +0 -21
  126. package/src/components/block/animator.ts +0 -220
  127. package/src/components/block/block.helpers.ts +0 -106
  128. package/src/components/block/block.tsx +0 -235
  129. package/src/components/block/components/block-styles.tsx +0 -136
  130. package/src/components/block/components/block-wrapper.tsx +0 -53
  131. package/src/components/block/components/component-ref/component-ref.helpers.ts +0 -55
  132. package/src/components/block/components/component-ref/component-ref.tsx +0 -66
  133. package/src/components/block/components/interactive-element.tsx +0 -53
  134. package/src/components/block/components/repeated-block.tsx +0 -37
  135. package/src/components/block/types.ts +0 -6
  136. package/src/components/blocks/blocks-wrapper.tsx +0 -93
  137. package/src/components/blocks/blocks.tsx +0 -57
  138. package/src/components/blocks/blocks.types.ts +0 -7
  139. package/src/components/blocks/index.ts +0 -1
  140. package/src/components/content/components/enable-editor.tsx +0 -471
  141. package/src/components/content/components/styles.helpers.ts +0 -101
  142. package/src/components/content/components/styles.tsx +0 -42
  143. package/src/components/content/content.helpers.ts +0 -40
  144. package/src/components/content/content.tsx +0 -150
  145. package/src/components/content/content.types.ts +0 -13
  146. package/src/components/content/contentProps.types.ts +0 -17
  147. package/src/components/content/index.ts +0 -1
  148. package/src/components/content/wrap-component-ref.ts +0 -6
  149. package/src/components/content-variants/content-variants.tsx +0 -146
  150. package/src/components/content-variants/content-variants.types.ts +0 -84
  151. package/src/components/content-variants/helpers.ts +0 -72
  152. package/src/components/content-variants/index.ts +0 -1
  153. package/src/components/content-variants/inlined-fns.ts +0 -22
  154. package/src/components/dynamic-div.tsx +0 -30
  155. package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +0 -7
  156. package/src/components/dynamic-renderer/dynamic-renderer.tsx +0 -47
  157. package/src/components/error-boundary.tsx +0 -38
  158. package/src/components/inlined-script.tsx +0 -10
  159. package/src/components/inlined-styles.tsx +0 -10
  160. package/src/constants/builder-registered-components.ts +0 -59
  161. package/src/constants/device-sizes.ts +0 -59
  162. package/src/constants/extra-components.ts +0 -1
  163. package/src/constants/sdk-version.ts +0 -1
  164. package/src/constants/target.ts +0 -3
  165. package/src/context/builder.context.ts +0 -15
  166. package/src/context/components.context.ts +0 -3
  167. package/src/context/index.ts +0 -1
  168. package/src/context/types.ts +0 -37
  169. package/src/functions/apply-patch-with-mutation.ts +0 -61
  170. package/src/functions/camel-to-kebab-case.ts +0 -1
  171. package/src/functions/deopt.ts +0 -6
  172. package/src/functions/evaluate/browser-runtime/browser.ts +0 -61
  173. package/src/functions/evaluate/browser-runtime/index.ts +0 -1
  174. package/src/functions/evaluate/choose-eval.ts +0 -23
  175. package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +0 -2891
  176. package/src/functions/evaluate/edge-runtime/edge-runtime.ts +0 -96
  177. package/src/functions/evaluate/edge-runtime/index.ts +0 -1
  178. package/src/functions/evaluate/evaluate.ts +0 -76
  179. package/src/functions/evaluate/helpers.ts +0 -56
  180. package/src/functions/evaluate/index.ts +0 -1
  181. package/src/functions/evaluate/node-runtime/index.ts +0 -1
  182. package/src/functions/evaluate/node-runtime/init.ts +0 -33
  183. package/src/functions/evaluate/node-runtime/node-runtime.ts +0 -176
  184. package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +0 -24
  185. package/src/functions/evaluate/placeholder-runtime.ts +0 -4
  186. package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +0 -16
  187. package/src/functions/event-handler-name.ts +0 -4
  188. package/src/functions/extract-text-styles.ts +0 -24
  189. package/src/functions/fast-clone.ts +0 -4
  190. package/src/functions/fetch-builder-props.ts +0 -75
  191. package/src/functions/get-block-actions-handler.ts +0 -17
  192. package/src/functions/get-block-actions.ts +0 -35
  193. package/src/functions/get-block-component-options.ts +0 -11
  194. package/src/functions/get-block-properties.ts +0 -62
  195. package/src/functions/get-builder-search-params/index.ts +0 -33
  196. package/src/functions/get-class-prop-name.ts +0 -15
  197. package/src/functions/get-content/generate-content-url.ts +0 -88
  198. package/src/functions/get-content/index.ts +0 -99
  199. package/src/functions/get-content/types.ts +0 -157
  200. package/src/functions/get-env.ts +0 -5
  201. package/src/functions/get-fetch.ts +0 -11
  202. package/src/functions/get-global-this.ts +0 -16
  203. package/src/functions/get-processed-block.ts +0 -70
  204. package/src/functions/get-style.ts +0 -38
  205. package/src/functions/get.ts +0 -4
  206. package/src/functions/is-browser.ts +0 -3
  207. package/src/functions/is-edge-runtime.ts +0 -9
  208. package/src/functions/is-editing.ts +0 -8
  209. package/src/functions/is-from-trusted-host.ts +0 -8
  210. package/src/functions/is-iframe.ts +0 -4
  211. package/src/functions/is-node-runtime.ts +0 -8
  212. package/src/functions/is-previewing.ts +0 -16
  213. package/src/functions/on-change.ts +0 -29
  214. package/src/functions/register-component.ts +0 -30
  215. package/src/functions/register.ts +0 -44
  216. package/src/functions/set-editor-settings.ts +0 -15
  217. package/src/functions/set.ts +0 -14
  218. package/src/functions/track/helpers.ts +0 -51
  219. package/src/functions/track/index.ts +0 -131
  220. package/src/functions/track/interaction.ts +0 -63
  221. package/src/functions/transform-block-properties.ts +0 -33
  222. package/src/functions/transform-block.ts +0 -30
  223. package/src/functions/transform-style-property.ts +0 -296
  224. package/src/helpers/ab-tests.ts +0 -166
  225. package/src/helpers/canTrack.ts +0 -2
  226. package/src/helpers/cookie.ts +0 -97
  227. package/src/helpers/css.ts +0 -33
  228. package/src/helpers/flatten.ts +0 -41
  229. package/src/helpers/localStorage.ts +0 -36
  230. package/src/helpers/logger.ts +0 -7
  231. package/src/helpers/nullable.ts +0 -2
  232. package/src/helpers/omit.ts +0 -7
  233. package/src/helpers/preview-lru-cache/get.ts +0 -4
  234. package/src/helpers/preview-lru-cache/helpers.ts +0 -1
  235. package/src/helpers/preview-lru-cache/init.ts +0 -7
  236. package/src/helpers/preview-lru-cache/set.ts +0 -12
  237. package/src/helpers/preview-lru-cache/types.ts +0 -1
  238. package/src/helpers/search/search.ts +0 -18
  239. package/src/helpers/sessionId.ts +0 -37
  240. package/src/helpers/subscribe-to-editor.ts +0 -95
  241. package/src/helpers/time.ts +0 -2
  242. package/src/helpers/url.ts +0 -15
  243. package/src/helpers/uuid.ts +0 -17
  244. package/src/helpers/visitorId.ts +0 -37
  245. package/src/index-helpers/blocks-exports.ts +0 -16
  246. package/src/index-helpers/top-of-file.ts +0 -2
  247. package/src/index.ts +0 -15
  248. package/src/scripts/init-editing.ts +0 -119
  249. package/src/server-index.ts +0 -43
  250. package/src/types/api-version.ts +0 -2
  251. package/src/types/builder-block.ts +0 -89
  252. package/src/types/builder-content.ts +0 -47
  253. package/src/types/builder-props.ts +0 -12
  254. package/src/types/can-track.ts +0 -3
  255. package/src/types/components.ts +0 -119
  256. package/src/types/deep-partial.ts +0 -1
  257. package/src/types/element.ts +0 -57
  258. package/src/types/enforced-partials.ts +0 -19
  259. package/src/types/input.ts +0 -123
  260. package/src/types/targets.ts +0 -1
  261. package/src/types/typescript.ts +0 -9
@@ -1,296 +0,0 @@
1
- import cssToStyleSheet from 'css-to-react-native';
2
- import type { ImageStyle, TextStyle, ViewStyle } from 'react-native';
3
- import type { BuilderContextInterface } from '../context/types';
4
- import type { BuilderBlock } from '../types/builder-block';
5
- import type { Dictionary } from '../types/typescript';
6
-
7
- const cssToReactNative: typeof cssToStyleSheet = (cssToStyleSheet as any)
8
- .default
9
- ? (cssToStyleSheet as any).default
10
- : cssToStyleSheet;
11
-
12
- type StyleSheetProperties = ImageStyle & TextStyle & ViewStyle;
13
-
14
- /**
15
- * @description List of allowed css properties.
16
- * We use this to filter out web CSS from Builder.io that would crash RN.
17
- */
18
- const ALLOWED_CSS_PROPERTIES: Array<keyof StyleSheetProperties> = [
19
- // img props
20
- 'backfaceVisibility',
21
- 'backgroundColor',
22
- 'borderBottomLeftRadius',
23
- 'borderBottomRightRadius',
24
- 'borderColor',
25
- 'borderRadius',
26
- 'borderTopLeftRadius',
27
- 'borderTopRightRadius',
28
- 'borderWidth',
29
- 'opacity',
30
- 'overflow',
31
- 'overlayColor',
32
- 'resizeMode',
33
- 'objectFit',
34
- 'tintColor',
35
- // layout props
36
- 'alignContent',
37
- 'alignItems',
38
- 'alignSelf',
39
- 'aspectRatio',
40
- 'borderBottomWidth',
41
- 'borderEndWidth',
42
- 'borderLeftWidth',
43
- 'borderRightWidth',
44
- 'borderStartWidth',
45
- 'borderTopWidth',
46
- 'borderWidth',
47
- 'bottom',
48
- 'columnGap',
49
- 'direction',
50
- 'display',
51
- 'end',
52
- 'flex',
53
- 'flexBasis',
54
- 'flexDirection',
55
- 'flexGrow',
56
- 'flexShrink',
57
- 'flexWrap',
58
- 'gap',
59
- 'height',
60
- 'width',
61
- 'justifyContent',
62
- 'left',
63
- 'margin',
64
- 'marginBottom',
65
- 'marginEnd',
66
- 'marginHorizontal',
67
- 'marginLeft',
68
- 'marginRight',
69
- 'marginStart',
70
- 'marginTop',
71
- 'marginVertical',
72
- 'maxHeight',
73
- 'maxWidth',
74
- 'minHeight',
75
- 'minWidth',
76
- 'overflow',
77
- 'padding',
78
- 'paddingBottom',
79
- 'paddingEnd',
80
- 'paddingHorizontal',
81
- 'paddingLeft',
82
- 'paddingRight',
83
- 'paddingStart',
84
- 'paddingTop',
85
- 'paddingVertical',
86
- 'position',
87
- 'right',
88
- 'rowGap',
89
- 'start',
90
- 'top',
91
- // shadow
92
- 'shadowColor',
93
- 'shadowOffset',
94
- 'shadowOpacity',
95
- 'shadowRadius',
96
- // text props
97
- 'color',
98
- 'fontFamily',
99
- 'fontSize',
100
- 'fontStyle',
101
- 'fontWeight',
102
- 'includeFontPadding',
103
- 'fontVariant',
104
- 'letterSpacing',
105
- 'lineHeight',
106
- 'textAlign',
107
- 'textAlignVertical',
108
- 'textDecorationColor',
109
- 'textDecorationLine',
110
- 'textDecorationStyle',
111
- 'textShadowColor',
112
- 'textShadowOffset',
113
- 'textShadowRadius',
114
- 'textTransform',
115
- 'verticalAlign',
116
- 'writingDirection',
117
- // TO-DO: type is missing until v73.2: https://github.com/facebook/react-native/issues/39015
118
- 'userSelect' as any,
119
- // view style props
120
- 'backfaceVisibility',
121
- 'backgroundColor',
122
- 'borderBottomColor',
123
- 'borderBottomEndRadius',
124
- 'borderBottomLeftRadius',
125
- 'borderBottomRightRadius',
126
- 'borderBottomStartRadius',
127
- 'borderStartEndRadius',
128
- 'borderStartStartRadius',
129
- 'borderEndEndRadius',
130
- 'borderEndStartRadius',
131
- 'borderBottomWidth',
132
- 'borderColor',
133
- 'borderCurve',
134
- 'borderEndColor',
135
- 'borderLeftColor',
136
- 'borderLeftWidth',
137
- 'borderRadius',
138
- 'borderRightColor',
139
- 'borderRightWidth',
140
- 'borderStartColor',
141
- 'borderStyle',
142
- 'borderTopColor',
143
- 'borderTopEndRadius',
144
- 'borderTopLeftRadius',
145
- 'borderTopRightRadius',
146
- 'borderTopStartRadius',
147
- 'borderTopWidth',
148
- 'borderWidth',
149
- 'elevation',
150
- 'opacity',
151
- 'pointerEvents',
152
- ];
153
-
154
- const DISPLAY_VALUES = ['flex', 'none'];
155
-
156
- const BORDERSTYLE_VALUES = ['solid', 'dotted', 'dashed'];
157
-
158
- function omit<T extends object>(obj: T, ...values: (keyof T)[]): Partial<T> {
159
- const newObject = Object.assign({}, obj);
160
- for (const key of values) {
161
- delete (newObject as any)[key];
162
- }
163
- return newObject;
164
- }
165
-
166
- const inRange = (value: number, min: number, max: number) =>
167
- value >= min && value <= max;
168
-
169
- const processValue = (
170
- styles: { [key: string]: string },
171
- [key, value]: [string, unknown]
172
- ): string | undefined => {
173
- if (typeof value !== 'string' || value === '') return undefined;
174
- if (!ALLOWED_CSS_PROPERTIES.includes(key as any)) return undefined;
175
- if (value.includes('calc')) return undefined;
176
- if (value.includes('inherit')) return undefined;
177
- if (value === 'px') return undefined;
178
- if (key === 'display' && !DISPLAY_VALUES.includes(value)) return undefined;
179
-
180
- if (key === 'borderStyle' && !BORDERSTYLE_VALUES.includes(value))
181
- return undefined;
182
-
183
- if (key === 'maxWidth' && value === 'none') {
184
- return '100%';
185
- }
186
-
187
- if (key === 'lineHeight' && !value.includes('px')) {
188
- const fontSize = parseFloat(styles.fontSize);
189
- const lineHeight = parseFloat(styles.lineHeight);
190
-
191
- if (!isNaN(fontSize) && !isNaN(lineHeight) && inRange(lineHeight, 1, 2)) {
192
- return `${Math.round(fontSize * lineHeight)}px`;
193
- }
194
-
195
- return undefined;
196
- }
197
-
198
- if (key === 'fontFamily') {
199
- return value.replace(/["]/g, '').split(',')[0];
200
- }
201
-
202
- const numericValue = parseFloat(value);
203
- const isNumeric = !isNaN(numericValue);
204
-
205
- if (isNumeric) {
206
- const processSuffix = (numAsStr: string) => {
207
- if (numAsStr.includes('em')) {
208
- if (key === 'letterSpacing') return numAsStr.replace('em', 'px');
209
-
210
- return numAsStr.replace('em', '');
211
- }
212
-
213
- if (numAsStr.includes('pt')) return numAsStr.replace('pt', '');
214
- if (numAsStr.includes('vw')) return numAsStr.replace('vw', '%');
215
- if (numAsStr.includes('vh')) return numAsStr.replace('vh', '%');
216
-
217
- return numAsStr;
218
- };
219
-
220
- return processSuffix(value);
221
- }
222
-
223
- return value;
224
- };
225
-
226
- /**
227
- * @description Cleans styles that RN can't handle and css-to-react-native doesn't fix
228
- */
229
- const cleanCssStyleProps = (styles: {
230
- [key: string]: string;
231
- }): { [key: string]: string } =>
232
- Object.entries(styles).reduce((acc, [key, value]) => {
233
- const processedValue = processValue(styles, [key, value]);
234
- if (processedValue === undefined) return acc;
235
- return { ...acc, [key]: processedValue };
236
- }, {});
237
-
238
- /**
239
- * We ignore any `display: none` coming from med/large styles, as that would
240
- * inadvertedly hide our content on mobile.
241
- */
242
- const removeDisplayNone = (styles: Dictionary<any>) =>
243
- styles.display === 'none' ? omit(styles, 'display') : styles;
244
-
245
- function getReactNativeBlockStyles({
246
- block,
247
- context,
248
- blockStyles,
249
- }: {
250
- block: BuilderBlock;
251
- context: BuilderContextInterface;
252
- blockStyles: any;
253
- }): CSSStyleDeclaration | Record<string, string | undefined> {
254
- const responsiveStyles = block.responsiveStyles;
255
- if (!responsiveStyles) {
256
- return {};
257
- }
258
-
259
- const largeAndMediumStyles = removeDisplayNone({
260
- ...(responsiveStyles.large || {}),
261
- ...(responsiveStyles.medium || {}),
262
- });
263
-
264
- const styles = {
265
- // recursively apply inherited styles so that they can be passed down to children `Text` blocks
266
- ...context.inheritedStyles,
267
- ...largeAndMediumStyles,
268
- ...(responsiveStyles.small || {}),
269
- ...blockStyles,
270
- } as Record<string, string | number>;
271
-
272
- const cleanedCSS = cleanCssStyleProps(styles as any);
273
-
274
- const newStyles = cssToReactNative(
275
- Object.entries(cleanedCSS)
276
- ) as any as CSSStyleDeclaration;
277
-
278
- return newStyles;
279
- }
280
-
281
- export function transformStyleProperty({
282
- block,
283
- context,
284
- style,
285
- }: {
286
- block: BuilderBlock;
287
- context: BuilderContextInterface;
288
- style: any;
289
- }) {
290
- const newStyles = getReactNativeBlockStyles({
291
- block,
292
- context,
293
- blockStyles: style,
294
- });
295
- return newStyles;
296
- }
@@ -1,166 +0,0 @@
1
- import { TARGET } from '../constants/target';
2
- import { checkIsDefined } from '../helpers/nullable';
3
- import type { BuilderContent, BuilderContentVariation } from '../types/builder-content';
4
- import type { CanTrack } from '../types/can-track';
5
- import type { Nullable, Overwrite } from '../types/typescript';
6
- import { getCookie, getCookieSync, setCookie } from './cookie';
7
- import { logger } from './logger';
8
- const BUILDER_STORE_PREFIX = 'builder.tests';
9
- const getContentTestKey = (id: string) => `${BUILDER_STORE_PREFIX}.${id}`;
10
- const getContentVariationCookie = ({
11
- contentId
12
- }: {
13
- contentId: string;
14
- }) => getCookie({
15
- name: getContentTestKey(contentId),
16
- canTrack: true
17
- });
18
- const getContentVariationCookieSync = ({
19
- contentId
20
- }: {
21
- contentId: string;
22
- }) => getCookieSync({
23
- name: getContentTestKey(contentId),
24
- canTrack: true
25
- });
26
- const setContentVariationCookie = ({
27
- contentId,
28
- value
29
- }: {
30
- contentId: string;
31
- value: string;
32
- }) => setCookie({
33
- name: getContentTestKey(contentId),
34
- value,
35
- canTrack: true
36
- });
37
- type BuilderContentWithVariations = Overwrite<BuilderContent, Required<Pick<BuilderContent, 'variations' | 'id'>>>;
38
- const checkIsBuilderContentWithVariations = (item: BuilderContent): item is BuilderContentWithVariations => checkIsDefined(item.id) && checkIsDefined(item.variations) && Object.keys(item.variations).length > 0;
39
-
40
- /**
41
- * Randomly assign a variation to a user
42
- */
43
- const getRandomVariationId = ({
44
- id,
45
- variations
46
- }: BuilderContentWithVariations) => {
47
- let n = 0;
48
- const random = Math.random();
49
-
50
- // loop over variations test ratios, incrementing a counter,
51
- // until we find the variation that this user should be assigned to
52
- for (const id in variations) {
53
- const testRatio = variations[id]?.testRatio;
54
- n += testRatio!;
55
- if (random < n) {
56
- return id;
57
- }
58
- }
59
-
60
- // the variations array does not include the default variation.
61
- // if we arrive here, then it means that the random number fits in the default variation bucket.
62
- return id;
63
- };
64
- const getAndSetVariantId = (args: BuilderContentWithVariations) => {
65
- // if variation not found in storage, assign a random variation to this user
66
- const randomVariationId = getRandomVariationId(args);
67
-
68
- // store variation in cookies/storage
69
- setContentVariationCookie({
70
- contentId: args.id,
71
- value: randomVariationId
72
- }).catch(err => {
73
- logger.error('could not store A/B test variation: ', err);
74
- });
75
- return randomVariationId;
76
- };
77
- type TestFields = {
78
- data?: BuilderContentVariation['data'];
79
- testVariationId?: string;
80
- testVariationName: string;
81
- };
82
- const getTestFields = ({
83
- item,
84
- testGroupId
85
- }: {
86
- item: BuilderContentWithVariations;
87
- testGroupId: string;
88
- }): TestFields => {
89
- const variationValue = item.variations[testGroupId];
90
- if (testGroupId === item.id ||
91
- // handle edge-case where `testGroupId` points to non-existing variation
92
- !variationValue) {
93
- return {
94
- testVariationId: item.id,
95
- testVariationName: 'Default'
96
- };
97
- } else {
98
- return {
99
- data: variationValue.data,
100
- testVariationId: variationValue.id,
101
- testVariationName: variationValue.name || (variationValue.id === item.id ? 'Default' : '')
102
- };
103
- }
104
- };
105
- export const handleABTestingSync = ({
106
- item,
107
- canTrack
108
- }: {
109
- item: Nullable<BuilderContent>;
110
- } & CanTrack): Nullable<BuilderContent> => {
111
- /**
112
- * We cannot SSR in React-Native.
113
- */
114
- if (TARGET === 'reactNative') return item;
115
- if (!canTrack) {
116
- return item;
117
- }
118
- if (!item) {
119
- return undefined;
120
- }
121
- if (!checkIsBuilderContentWithVariations(item)) {
122
- return item;
123
- }
124
- const testGroupId = getContentVariationCookieSync({
125
- contentId: item.id
126
- }) || getAndSetVariantId({
127
- variations: item.variations,
128
- id: item.id
129
- });
130
- const variationValue = getTestFields({
131
- item,
132
- testGroupId
133
- });
134
- return {
135
- ...item,
136
- ...variationValue
137
- };
138
- };
139
- export const handleABTesting = async ({
140
- item,
141
- canTrack
142
- }: {
143
- item: BuilderContent;
144
- } & CanTrack): Promise<BuilderContent> => {
145
- if (!canTrack) {
146
- return item;
147
- }
148
- if (!checkIsBuilderContentWithVariations(item)) {
149
- return item;
150
- }
151
- const cookieValue = await getContentVariationCookie({
152
- contentId: item.id
153
- });
154
- const testGroupId = cookieValue || getAndSetVariantId({
155
- variations: item.variations,
156
- id: item.id
157
- });
158
- const variationValue = getTestFields({
159
- item,
160
- testGroupId
161
- });
162
- return {
163
- ...item,
164
- ...variationValue
165
- };
166
- }
@@ -1,2 +0,0 @@
1
- import { checkIsDefined } from './nullable';
2
- export const getDefaultCanTrack = (canTrack?: boolean) => checkIsDefined(canTrack) ? canTrack : true
@@ -1,97 +0,0 @@
1
- import type { CanTrack } from '../types/can-track';
2
- import { logger } from './logger';
3
-
4
- import AsyncStorage from '@react-native-async-storage/async-storage';
5
- import Storage from 'react-native-storage';
6
- import { isBrowser } from '../functions/is-browser';
7
-
8
- const ONE_DAY = 1000 * 60 * 60 * 24;
9
-
10
- const initStorage = () => {
11
- const backend = isBrowser() ? window.localStorage : AsyncStorage;
12
- const storage = new Storage({
13
- // maximum capacity, default 1000 key-ids
14
- size: 1000,
15
-
16
- // Use AsyncStorage for RN apps, or window.localStorage for web apps.
17
- // If storageBackend is not set, data will be lost after reload.
18
- storageBackend: backend,
19
-
20
- // expire time, default: 1 day (1000 * 3600 * 24 milliseconds).
21
- // can be null, which means never expire.
22
- defaultExpires: ONE_DAY * 30,
23
-
24
- // cache data in the memory. default is true.
25
- enableCache: true,
26
- });
27
-
28
- return storage;
29
- };
30
-
31
- const storage = initStorage();
32
-
33
- const getStorageName = (name: string) => `builderio.${name}`;
34
-
35
- // stub, never called, but needed to fix bundling.
36
- export const getCookieSync = (
37
- _: {
38
- name: string;
39
- } & CanTrack
40
- ): any => {};
41
-
42
- export const getCookie = async ({
43
- name,
44
- canTrack,
45
- }: {
46
- name: string;
47
- } & CanTrack) => {
48
- try {
49
- if (!canTrack) {
50
- return undefined;
51
- }
52
-
53
- // react-native does not support underscores in names
54
- const parsedName = name.replace(/_/g, '.');
55
-
56
- const data = await storage.load({ key: getStorageName(parsedName) });
57
-
58
- return data.value;
59
- } catch (err) {
60
- if (err?.name !== 'NotFoundError') {
61
- logger.warn('[COOKIE] GET error: ', err?.message || err);
62
- }
63
- return undefined;
64
- }
65
- };
66
-
67
- export const setCookie = async ({
68
- name,
69
- value,
70
- expires,
71
- canTrack,
72
- }: {
73
- name: string;
74
- value: string;
75
- expires?: Date;
76
- } & CanTrack) => {
77
- try {
78
- if (!canTrack) {
79
- return undefined;
80
- }
81
- // convert `expires` date to number representing milliseconds from now until the date
82
- const expiresAsNumber = expires
83
- ? expires.getTime() - Date.now()
84
- : undefined;
85
-
86
- await storage.save({
87
- key: getStorageName(name),
88
- data: { value },
89
- expires: expiresAsNumber,
90
- });
91
- } catch (err) {
92
- if (err?.name !== 'NotFoundError') {
93
- logger.warn('[COOKIE] SET error: ', err?.message || err);
94
- }
95
- return undefined;
96
- }
97
- };
@@ -1,33 +0,0 @@
1
- import { camelToKebabCase } from '../functions/camel-to-kebab-case';
2
- import { checkIsDefined } from './nullable';
3
- export const convertStyleMapToCSSArray = (style: Partial<CSSStyleDeclaration>): string[] => {
4
- const cssProps = Object.entries(style).map(([key, value]) => {
5
- if (typeof value === 'string') {
6
- return `${camelToKebabCase(key)}: ${value};`;
7
- } else {
8
- return undefined;
9
- }
10
- });
11
- return cssProps.filter(checkIsDefined);
12
- };
13
- export const convertStyleMapToCSS = (style: Partial<CSSStyleDeclaration>): string => convertStyleMapToCSSArray(style).join('\n');
14
- export const createCssClass = ({
15
- mediaQuery,
16
- className,
17
- styles
18
- }: {
19
- mediaQuery?: string;
20
- className: string;
21
- styles: Partial<CSSStyleDeclaration>;
22
- }) => {
23
- const cssClass = `.${className} {
24
- ${convertStyleMapToCSS(styles)}
25
- }`;
26
- if (mediaQuery) {
27
- return `${mediaQuery} {
28
- ${cssClass}
29
- }`;
30
- } else {
31
- return cssClass;
32
- }
33
- }
@@ -1,41 +0,0 @@
1
- /**
2
- * Convert deep object to a flat object with dots
3
- *
4
- * { foo: { bar: 'baz' }} -> { 'foo.bar': 'baz' }
5
- */
6
- export function flatten<T extends Record<string, any>>(object: T, path: string | null = null, separator = '.'): T {
7
- return Object.keys(object).reduce((acc: T, key: string): T => {
8
- const value = object[key];
9
- const newPath = [path, key].filter(Boolean).join(separator);
10
- const isObject = [typeof value === 'object', value !== null, !(Array.isArray(value) && value.length === 0)].every(Boolean);
11
- return isObject ? {
12
- ...acc,
13
- ...flatten(value, newPath, separator)
14
- } : {
15
- ...acc,
16
- [newPath]: value
17
- };
18
- }, ({} as T));
19
- }
20
-
21
- /**
22
- * Flatten a nested MongoDB query object into a flat object with dot-separated keys.
23
- * $ keys are not flattened and are left as is.
24
- *
25
- * { foo: { bar: { $gt: 5 }}} -> { 'foo.bar': { '$gt': 5 }}
26
- * { foo: {'bar.id': { $elemMatch: { 'baz.id': { $in: ['abc', 'bcd'] }}}}} -> { 'foo.bar.id': { '$elemMatch': { 'baz.id': { '$in': ['abc', 'bcd'] }}}}
27
- */
28
- export function flattenMongoQuery(obj: any, _current?: any, _res: any = {}): {
29
- [key: string]: string;
30
- } {
31
- for (const key in obj) {
32
- const value = obj[key];
33
- const newKey = _current ? _current + '.' + key : key;
34
- if (value && typeof value === 'object' && !Array.isArray(value) && !Object.keys(value).find(item => item.startsWith('$'))) {
35
- flattenMongoQuery(value, newKey, _res);
36
- } else {
37
- _res[newKey] = value;
38
- }
39
- }
40
- return _res;
41
- }
@@ -1,36 +0,0 @@
1
- import { isBrowser } from '../functions/is-browser';
2
- import type { CanTrack } from '../types/can-track';
3
- import type { Nullable } from './nullable';
4
- const getLocalStorage = () => isBrowser() && typeof localStorage !== 'undefined' ? localStorage : undefined;
5
- export const getLocalStorageItem = ({
6
- key,
7
- canTrack
8
- }: {
9
- key: string;
10
- } & CanTrack): Nullable<string> => {
11
- try {
12
- if (canTrack) {
13
- return getLocalStorage()?.getItem(key);
14
- }
15
- return undefined;
16
- } catch (err) {
17
- console.debug('[LocalStorage] GET error: ', err);
18
- return undefined;
19
- }
20
- };
21
- export const setLocalStorageItem = ({
22
- key,
23
- canTrack,
24
- value
25
- }: {
26
- key: string;
27
- value: string;
28
- } & CanTrack) => {
29
- try {
30
- if (canTrack) {
31
- getLocalStorage()?.setItem(key, value);
32
- }
33
- } catch (err) {
34
- console.debug('[LocalStorage] SET error: ', err);
35
- }
36
- }
@@ -1,7 +0,0 @@
1
- export const MSG_PREFIX = '[Builder.io]: ';
2
- export const logger = {
3
- log: (...message: any[]) => console.log(MSG_PREFIX, ...message),
4
- error: (...message: any[]) => console.error(MSG_PREFIX, ...message),
5
- warn: (...message: any[]) => console.warn(MSG_PREFIX, ...message),
6
- debug: (...message: any[]) => console.debug(MSG_PREFIX, ...message)
7
- }
@@ -1,2 +0,0 @@
1
- export type Nullable<T> = T | null | undefined;
2
- export const checkIsDefined = <T,>(maybeT: Nullable<T>): maybeT is T => maybeT !== null && maybeT !== undefined
@@ -1,7 +0,0 @@
1
- export function omit<T extends object>(obj: T, ...values: (keyof T)[]): Partial<T> {
2
- const newObject = Object.assign({}, obj);
3
- for (const key of values) {
4
- delete (newObject as any)[key];
5
- }
6
- return newObject;
7
- }
@@ -1,4 +0,0 @@
1
- import type { BuilderContent } from '../../types/builder-content';
2
- export function getPreviewContent(_searchParams: URLSearchParams): BuilderContent | undefined {
3
- return undefined;
4
- }
@@ -1 +0,0 @@
1
- export {}