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

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 (225) hide show
  1. package/lib/browser/commonjs/constants/sdk-version.js +1 -1
  2. package/lib/browser/module/constants/sdk-version.js +1 -1
  3. package/lib/browser/typescript/constants/sdk-version.d.ts +1 -1
  4. package/lib/edge/commonjs/constants/sdk-version.js +1 -1
  5. package/lib/edge/module/constants/sdk-version.js +1 -1
  6. package/lib/edge/typescript/constants/sdk-version.d.ts +1 -1
  7. package/lib/node/commonjs/constants/sdk-version.js +1 -1
  8. package/lib/node/index.cjs +6910 -0
  9. package/lib/node/index.mjs +7477 -0
  10. package/lib/node/module/constants/sdk-version.js +1 -1
  11. package/lib/node/typescript/constants/sdk-version.d.ts +1 -1
  12. package/package.json +9 -5
  13. package/src/blocks/BaseText.tsx +17 -0
  14. package/src/blocks/accordion/accordion.tsx +181 -0
  15. package/src/blocks/accordion/accordion.types.ts +12 -0
  16. package/src/blocks/accordion/component-info.ts +124 -0
  17. package/src/blocks/accordion/helpers.ts +3 -0
  18. package/src/blocks/accordion/index.ts +1 -0
  19. package/src/blocks/button/button.tsx +56 -0
  20. package/src/blocks/button/button.types.ts +7 -0
  21. package/src/blocks/button/component-info.ts +35 -0
  22. package/src/blocks/button/index.ts +1 -0
  23. package/src/blocks/columns/columns.tsx +199 -0
  24. package/src/blocks/columns/columns.types.ts +14 -0
  25. package/src/blocks/columns/component-info.ts +219 -0
  26. package/src/blocks/columns/helpers.ts +3 -0
  27. package/src/blocks/columns/index.ts +1 -0
  28. package/src/blocks/custom-code/component-info.ts +24 -0
  29. package/src/blocks/custom-code/custom-code.tsx +71 -0
  30. package/src/blocks/custom-code/index.ts +1 -0
  31. package/src/blocks/embed/component-info.ts +38 -0
  32. package/src/blocks/embed/embed.tsx +62 -0
  33. package/src/blocks/embed/helpers.ts +2 -0
  34. package/src/blocks/embed/index.ts +1 -0
  35. package/src/blocks/form/form/component-info.ts +233 -0
  36. package/src/blocks/form/form/form.tsx +324 -0
  37. package/src/blocks/form/form/index.ts +1 -0
  38. package/src/blocks/form/input/component-info.ts +47 -0
  39. package/src/blocks/form/input/index.ts +1 -0
  40. package/src/blocks/form/input/input.tsx +49 -0
  41. package/src/blocks/form/select/component-info.ts +44 -0
  42. package/src/blocks/form/select/index.ts +1 -0
  43. package/src/blocks/form/select/select.tsx +54 -0
  44. package/src/blocks/form/submit-button/component-info.ts +27 -0
  45. package/src/blocks/form/submit-button/index.ts +1 -0
  46. package/src/blocks/form/submit-button/submit-button.tsx +34 -0
  47. package/src/blocks/fragment/component-info.ts +8 -0
  48. package/src/blocks/fragment/fragment.tsx +18 -0
  49. package/src/blocks/fragment/fragment.types.ts +5 -0
  50. package/src/blocks/fragment/index.ts +1 -0
  51. package/src/blocks/helpers.ts +43 -0
  52. package/src/blocks/image/component-info.ts +124 -0
  53. package/src/blocks/image/image.helpers.ts +47 -0
  54. package/src/blocks/image/image.tsx +65 -0
  55. package/src/blocks/image/image.types.ts +19 -0
  56. package/src/blocks/image/index.ts +1 -0
  57. package/src/blocks/img/component-info.ts +16 -0
  58. package/src/blocks/img/img.tsx +55 -0
  59. package/src/blocks/img/index.ts +1 -0
  60. package/src/blocks/raw-text/component-info.ts +11 -0
  61. package/src/blocks/raw-text/index.ts +1 -0
  62. package/src/blocks/raw-text/raw-text.tsx +1 -0
  63. package/src/blocks/section/component-info.ts +41 -0
  64. package/src/blocks/section/index.ts +1 -0
  65. package/src/blocks/section/section.tsx +39 -0
  66. package/src/blocks/section/section.types.ts +6 -0
  67. package/src/blocks/slot/component-info.ts +15 -0
  68. package/src/blocks/slot/index.ts +1 -0
  69. package/src/blocks/slot/slot.tsx +42 -0
  70. package/src/blocks/symbol/component-info.ts +35 -0
  71. package/src/blocks/symbol/index.ts +1 -0
  72. package/src/blocks/symbol/symbol.helpers.ts +47 -0
  73. package/src/blocks/symbol/symbol.tsx +99 -0
  74. package/src/blocks/symbol/symbol.types.ts +17 -0
  75. package/src/blocks/tabs/component-info.ts +139 -0
  76. package/src/blocks/tabs/index.ts +1 -0
  77. package/src/blocks/tabs/tabs.tsx +79 -0
  78. package/src/blocks/tabs/tabs.types.ts +13 -0
  79. package/src/blocks/text/component-info.ts +20 -0
  80. package/src/blocks/text/index.ts +1 -0
  81. package/src/blocks/text/text.tsx +105 -0
  82. package/src/blocks/text/text.types.ts +4 -0
  83. package/src/blocks/textarea/component-info.ts +38 -0
  84. package/src/blocks/textarea/index.ts +1 -0
  85. package/src/blocks/textarea/textarea.tsx +41 -0
  86. package/src/blocks/video/component-info.ts +83 -0
  87. package/src/blocks/video/index.ts +1 -0
  88. package/src/blocks/video/video.tsx +70 -0
  89. package/src/blocks/video/video.types.ts +21 -0
  90. package/src/components/block/animator.ts +220 -0
  91. package/src/components/block/block.helpers.ts +106 -0
  92. package/src/components/block/block.tsx +235 -0
  93. package/src/components/block/components/block-styles.tsx +136 -0
  94. package/src/components/block/components/block-wrapper.tsx +53 -0
  95. package/src/components/block/components/component-ref/component-ref.helpers.ts +55 -0
  96. package/src/components/block/components/component-ref/component-ref.tsx +66 -0
  97. package/src/components/block/components/interactive-element.tsx +53 -0
  98. package/src/components/block/components/repeated-block.tsx +37 -0
  99. package/src/components/block/types.ts +6 -0
  100. package/src/components/blocks/blocks-wrapper.tsx +93 -0
  101. package/src/components/blocks/blocks.tsx +57 -0
  102. package/src/components/blocks/blocks.types.ts +7 -0
  103. package/src/components/blocks/index.ts +1 -0
  104. package/src/components/content/components/enable-editor.tsx +471 -0
  105. package/src/components/content/components/styles.helpers.ts +101 -0
  106. package/src/components/content/components/styles.tsx +42 -0
  107. package/src/components/content/content.helpers.ts +40 -0
  108. package/src/components/content/content.tsx +150 -0
  109. package/src/components/content/content.types.ts +13 -0
  110. package/src/components/content/contentProps.types.ts +17 -0
  111. package/src/components/content/index.ts +1 -0
  112. package/src/components/content/wrap-component-ref.ts +6 -0
  113. package/src/components/content-variants/content-variants.tsx +146 -0
  114. package/src/components/content-variants/content-variants.types.ts +84 -0
  115. package/src/components/content-variants/helpers.ts +72 -0
  116. package/src/components/content-variants/index.ts +1 -0
  117. package/src/components/content-variants/inlined-fns.ts +22 -0
  118. package/src/components/dynamic-div.tsx +30 -0
  119. package/src/components/dynamic-renderer/dynamic-renderer.helpers.ts +7 -0
  120. package/src/components/dynamic-renderer/dynamic-renderer.tsx +47 -0
  121. package/src/components/error-boundary.tsx +38 -0
  122. package/src/components/inlined-script.tsx +10 -0
  123. package/src/components/inlined-styles.tsx +10 -0
  124. package/src/constants/builder-registered-components.ts +59 -0
  125. package/src/constants/device-sizes.ts +59 -0
  126. package/src/constants/extra-components.ts +1 -0
  127. package/src/constants/sdk-version.ts +1 -0
  128. package/src/constants/target.ts +3 -0
  129. package/src/context/builder.context.ts +15 -0
  130. package/src/context/components.context.ts +3 -0
  131. package/src/context/index.ts +1 -0
  132. package/src/context/types.ts +37 -0
  133. package/src/functions/apply-patch-with-mutation.ts +61 -0
  134. package/src/functions/camel-to-kebab-case.ts +1 -0
  135. package/src/functions/deopt.ts +6 -0
  136. package/src/functions/evaluate/browser-runtime/browser.ts +61 -0
  137. package/src/functions/evaluate/browser-runtime/index.ts +1 -0
  138. package/src/functions/evaluate/choose-eval.ts +23 -0
  139. package/src/functions/evaluate/edge-runtime/acorn-interpreter.ts +2891 -0
  140. package/src/functions/evaluate/edge-runtime/edge-runtime.ts +96 -0
  141. package/src/functions/evaluate/edge-runtime/index.ts +1 -0
  142. package/src/functions/evaluate/evaluate.ts +76 -0
  143. package/src/functions/evaluate/helpers.ts +56 -0
  144. package/src/functions/evaluate/index.ts +1 -0
  145. package/src/functions/evaluate/node-runtime/index.ts +1 -0
  146. package/src/functions/evaluate/node-runtime/init.ts +33 -0
  147. package/src/functions/evaluate/node-runtime/node-runtime.ts +176 -0
  148. package/src/functions/evaluate/node-runtime/safeDynamicRequire.ts +24 -0
  149. package/src/functions/evaluate/placeholder-runtime.ts +4 -0
  150. package/src/functions/evaluate/should-force-browser-runtime-in-node.ts +16 -0
  151. package/src/functions/event-handler-name.ts +4 -0
  152. package/src/functions/extract-text-styles.ts +24 -0
  153. package/src/functions/fast-clone.ts +4 -0
  154. package/src/functions/fetch-builder-props.ts +75 -0
  155. package/src/functions/get-block-actions-handler.ts +17 -0
  156. package/src/functions/get-block-actions.ts +35 -0
  157. package/src/functions/get-block-component-options.ts +11 -0
  158. package/src/functions/get-block-properties.ts +62 -0
  159. package/src/functions/get-builder-search-params/index.ts +33 -0
  160. package/src/functions/get-class-prop-name.ts +15 -0
  161. package/src/functions/get-content/generate-content-url.ts +88 -0
  162. package/src/functions/get-content/index.ts +99 -0
  163. package/src/functions/get-content/types.ts +157 -0
  164. package/src/functions/get-env.ts +5 -0
  165. package/src/functions/get-fetch.ts +11 -0
  166. package/src/functions/get-global-this.ts +16 -0
  167. package/src/functions/get-processed-block.ts +70 -0
  168. package/src/functions/get-style.ts +38 -0
  169. package/src/functions/get.ts +4 -0
  170. package/src/functions/is-browser.ts +3 -0
  171. package/src/functions/is-edge-runtime.ts +9 -0
  172. package/src/functions/is-editing.ts +8 -0
  173. package/src/functions/is-from-trusted-host.ts +8 -0
  174. package/src/functions/is-iframe.ts +4 -0
  175. package/src/functions/is-node-runtime.ts +8 -0
  176. package/src/functions/is-previewing.ts +16 -0
  177. package/src/functions/on-change.ts +29 -0
  178. package/src/functions/register-component.ts +30 -0
  179. package/src/functions/register.ts +44 -0
  180. package/src/functions/set-editor-settings.ts +15 -0
  181. package/src/functions/set.ts +14 -0
  182. package/src/functions/track/helpers.ts +51 -0
  183. package/src/functions/track/index.ts +131 -0
  184. package/src/functions/track/interaction.ts +63 -0
  185. package/src/functions/transform-block-properties.ts +33 -0
  186. package/src/functions/transform-block.ts +30 -0
  187. package/src/functions/transform-style-property.ts +296 -0
  188. package/src/helpers/ab-tests.ts +166 -0
  189. package/src/helpers/canTrack.ts +2 -0
  190. package/src/helpers/cookie.ts +97 -0
  191. package/src/helpers/css.ts +33 -0
  192. package/src/helpers/flatten.ts +41 -0
  193. package/src/helpers/localStorage.ts +36 -0
  194. package/src/helpers/logger.ts +7 -0
  195. package/src/helpers/nullable.ts +2 -0
  196. package/src/helpers/omit.ts +7 -0
  197. package/src/helpers/preview-lru-cache/get.ts +4 -0
  198. package/src/helpers/preview-lru-cache/helpers.ts +1 -0
  199. package/src/helpers/preview-lru-cache/init.ts +7 -0
  200. package/src/helpers/preview-lru-cache/set.ts +12 -0
  201. package/src/helpers/preview-lru-cache/types.ts +1 -0
  202. package/src/helpers/search/search.ts +18 -0
  203. package/src/helpers/sessionId.ts +37 -0
  204. package/src/helpers/subscribe-to-editor.ts +95 -0
  205. package/src/helpers/time.ts +2 -0
  206. package/src/helpers/url.ts +15 -0
  207. package/src/helpers/uuid.ts +17 -0
  208. package/src/helpers/visitorId.ts +37 -0
  209. package/src/index-helpers/blocks-exports.ts +16 -0
  210. package/src/index-helpers/top-of-file.ts +2 -0
  211. package/src/index.ts +15 -0
  212. package/src/scripts/init-editing.ts +119 -0
  213. package/src/server-index.ts +43 -0
  214. package/src/types/api-version.ts +2 -0
  215. package/src/types/builder-block.ts +89 -0
  216. package/src/types/builder-content.ts +47 -0
  217. package/src/types/builder-props.ts +12 -0
  218. package/src/types/can-track.ts +3 -0
  219. package/src/types/components.ts +119 -0
  220. package/src/types/deep-partial.ts +1 -0
  221. package/src/types/element.ts +57 -0
  222. package/src/types/enforced-partials.ts +19 -0
  223. package/src/types/input.ts +123 -0
  224. package/src/types/targets.ts +1 -0
  225. package/src/types/typescript.ts +9 -0
@@ -0,0 +1,42 @@
1
+ import * as React from "react";
2
+ import {
3
+ FlatList,
4
+ ScrollView,
5
+ View,
6
+ StyleSheet,
7
+ Image,
8
+ Text,
9
+ Pressable,
10
+ TextInput,
11
+ } from "react-native";
12
+
13
+ export type DropzoneProps = BuilderDataProps & {
14
+ name: string;
15
+ attributes: any;
16
+ };
17
+ import Blocks from "../../components/blocks/blocks";
18
+ import { deoptSignal } from "../../functions/deopt";
19
+ import type { BuilderBlock } from "../../types/builder-block";
20
+ import type { BuilderDataProps } from "../../types/builder-props";
21
+
22
+ function Slot(props: DropzoneProps) {
23
+ return (
24
+ <View
25
+ style={{
26
+ pointerEvents: "auto",
27
+ }}
28
+ {...(!props.builderContext.context?.symbolId && {
29
+ "builder-slot": props.name,
30
+ })}
31
+ >
32
+ <Blocks
33
+ parent={props.builderContext.context?.symbolId as string}
34
+ path={`symbol.data.${props.name}`}
35
+ context={props.builderContext}
36
+ blocks={props.builderContext.rootState?.[props.name] as BuilderBlock[]}
37
+ />
38
+ </View>
39
+ );
40
+ }
41
+
42
+ export default Slot;
@@ -0,0 +1,35 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+ export const componentInfo: ComponentInfo = {
3
+ name: 'Symbol',
4
+ noWrap: true,
5
+ static: true,
6
+ isRSC: true,
7
+ inputs: [{
8
+ name: 'symbol',
9
+ type: 'uiSymbol'
10
+ }, {
11
+ name: 'dataOnly',
12
+ helperText: "Make this a data symbol that doesn't display any UI",
13
+ type: 'boolean',
14
+ defaultValue: false,
15
+ advanced: true,
16
+ hideFromUI: true
17
+ }, {
18
+ name: 'inheritState',
19
+ helperText: 'Inherit the parent component state and data',
20
+ type: 'boolean',
21
+ defaultValue: false,
22
+ advanced: true
23
+ }, {
24
+ name: 'renderToLiquid',
25
+ helperText: 'Render this symbols contents to liquid. Turn off to fetch with javascript and use custom targeting',
26
+ type: 'boolean',
27
+ defaultValue: false,
28
+ advanced: true,
29
+ hideFromUI: true
30
+ }, {
31
+ name: 'useChildren',
32
+ hideFromUI: true,
33
+ type: 'boolean'
34
+ }]
35
+ }
@@ -0,0 +1 @@
1
+ export { default } from './symbol'
@@ -0,0 +1,47 @@
1
+ import type { BuilderContextInterface } from '../../context/types';
2
+ import { fetchOneEntry } from '../../functions/get-content/index';
3
+ import { logger } from '../../helpers/logger';
4
+ import type { BuilderContent } from '../../types/builder-content';
5
+ export interface SymbolInfo {
6
+ model?: string;
7
+ entry?: string;
8
+ data?: any;
9
+ content?: BuilderContent;
10
+ inline?: boolean;
11
+ dynamic?: boolean;
12
+ }
13
+ export const fetchSymbolContent = async ({
14
+ builderContextValue,
15
+ symbol
16
+ }: {
17
+ symbol: SymbolInfo | undefined;
18
+ builderContextValue: BuilderContextInterface;
19
+ }) => {
20
+ /**
21
+ * If:
22
+ * - we have a symbol prop
23
+ * - yet it does not have any content
24
+ * - and we have not already stored content from before
25
+ * - and it has a model name
26
+ *
27
+ * then we want to re-fetch the symbol content.
28
+ */
29
+ if (symbol?.model &&
30
+ // This is a hack, we should not need to check for this, but it is needed for Svelte.
31
+ builderContextValue?.apiKey) {
32
+ return fetchOneEntry({
33
+ model: symbol.model,
34
+ apiKey: builderContextValue.apiKey,
35
+ apiVersion: builderContextValue.apiVersion,
36
+ ...(symbol?.entry && {
37
+ query: {
38
+ id: symbol.entry
39
+ }
40
+ })
41
+ }).catch(err => {
42
+ logger.error('Could not fetch symbol content: ', err);
43
+ return undefined;
44
+ });
45
+ }
46
+ return undefined;
47
+ }
@@ -0,0 +1,99 @@
1
+ import * as React from "react";
2
+ import {
3
+ FlatList,
4
+ ScrollView,
5
+ View,
6
+ StyleSheet,
7
+ Image,
8
+ Text,
9
+ Pressable,
10
+ TextInput,
11
+ } from "react-native";
12
+ import { useState, useEffect } from "react";
13
+ import ContentVariants from "../../components/content-variants/index";
14
+ import type { BuilderContent } from "../../types/builder-content";
15
+ import { filterAttrs } from "../helpers";
16
+ import DynamicDiv from "../../components/dynamic-div";
17
+ import { getClassPropName } from "../../functions/get-class-prop-name";
18
+ import type { Nullable } from "../../types/typescript";
19
+ import { setAttrs } from "../helpers";
20
+ import { fetchSymbolContent } from "./symbol.helpers";
21
+ import type { SymbolProps } from "./symbol.types";
22
+
23
+ function Symbol(props: SymbolProps) {
24
+ function blocksWrapper() {
25
+ return View;
26
+ }
27
+
28
+ function contentWrapper() {
29
+ return View;
30
+ }
31
+
32
+ function className() {
33
+ return [
34
+ ...[],
35
+ "builder-symbol",
36
+ props.symbol?.inline ? "builder-inline-symbol" : undefined,
37
+ props.symbol?.dynamic || props.dynamic
38
+ ? "builder-dynamic-symbol"
39
+ : undefined,
40
+ ]
41
+ .filter(Boolean)
42
+ .join(" ");
43
+ }
44
+
45
+ const [contentToUse, setContentToUse] = useState(() => props.symbol?.content);
46
+
47
+ function setContent() {
48
+ if (contentToUse) return;
49
+ fetchSymbolContent({
50
+ symbol: props.symbol,
51
+ builderContextValue: props.builderContext,
52
+ }).then((newContent) => {
53
+ if (newContent) {
54
+ setContentToUse(newContent);
55
+ }
56
+ });
57
+ }
58
+
59
+ useEffect(() => {}, []);
60
+
61
+ useEffect(() => {
62
+ setContent();
63
+ }, [props.symbol]);
64
+
65
+ return (
66
+ <View
67
+ {...{}}
68
+ {...props.attributes}
69
+ {...{
70
+ dataSet: {
71
+ class: className(),
72
+ },
73
+ }}
74
+ >
75
+ <ContentVariants
76
+ isNestedRender
77
+ apiVersion={props.builderContext.apiVersion}
78
+ apiKey={props.builderContext.apiKey!}
79
+ context={{
80
+ ...props.builderContext.context,
81
+ symbolId: props.builderBlock?.id,
82
+ }}
83
+ customComponents={Object.values(props.builderComponents)}
84
+ data={{
85
+ ...props.symbol?.data,
86
+ ...props.builderContext.localState,
87
+ ...contentToUse?.data?.state,
88
+ }}
89
+ model={props.symbol?.model}
90
+ content={contentToUse}
91
+ linkComponent={props.builderLinkComponent}
92
+ blocksWrapper={blocksWrapper()}
93
+ contentWrapper={contentWrapper()}
94
+ />
95
+ </View>
96
+ );
97
+ }
98
+
99
+ export default Symbol;
@@ -0,0 +1,17 @@
1
+ import type { BuilderContent } from '../../types/builder-content';
2
+ import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props';
3
+ interface SymbolInfo {
4
+ model?: string;
5
+ entry?: string;
6
+ data?: any;
7
+ content?: BuilderContent;
8
+ inline?: boolean;
9
+ dynamic?: boolean;
10
+ }
11
+ export interface SymbolProps extends BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp {
12
+ symbol?: SymbolInfo;
13
+ dataOnly?: boolean;
14
+ dynamic?: boolean;
15
+ attributes?: any;
16
+ inheritState?: boolean;
17
+ }
@@ -0,0 +1,139 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+ const defaultTab = {
3
+ '@type': '@builder.io/sdk:Element',
4
+ responsiveStyles: {
5
+ large: {
6
+ paddingLeft: '20px',
7
+ paddingRight: '20px',
8
+ paddingTop: '10px',
9
+ paddingBottom: '10px',
10
+ minWidth: '100px',
11
+ textAlign: 'center',
12
+ display: 'flex',
13
+ flexDirection: 'column',
14
+ cursor: 'pointer',
15
+ userSelect: 'none'
16
+ }
17
+ },
18
+ component: {
19
+ name: 'Text',
20
+ options: {
21
+ text: 'New tab'
22
+ }
23
+ }
24
+ };
25
+ const defaultElement = {
26
+ '@type': '@builder.io/sdk:Element',
27
+ responsiveStyles: {
28
+ large: {
29
+ height: '200px',
30
+ display: 'flex',
31
+ marginTop: '20px',
32
+ flexDirection: 'column'
33
+ }
34
+ },
35
+ component: {
36
+ name: 'Text',
37
+ options: {
38
+ text: 'New tab content '
39
+ }
40
+ }
41
+ };
42
+ export const componentInfo: ComponentInfo = {
43
+ name: 'Builder: Tabs',
44
+ inputs: [{
45
+ name: 'tabs',
46
+ type: 'list',
47
+ broadcast: true,
48
+ subFields: [{
49
+ name: 'label',
50
+ type: 'uiBlocks',
51
+ hideFromUI: true,
52
+ defaultValue: [defaultTab]
53
+ }, {
54
+ name: 'content',
55
+ type: 'uiBlocks',
56
+ hideFromUI: true,
57
+ defaultValue: [defaultElement]
58
+ }],
59
+ defaultValue: [{
60
+ label: [{
61
+ ...defaultTab,
62
+ component: {
63
+ name: 'Text',
64
+ options: {
65
+ text: 'Tab 1'
66
+ }
67
+ }
68
+ }],
69
+ content: [{
70
+ ...defaultElement,
71
+ component: {
72
+ name: 'Text',
73
+ options: {
74
+ text: 'Tab 1 content'
75
+ }
76
+ }
77
+ }]
78
+ }, {
79
+ label: [{
80
+ ...defaultTab,
81
+ component: {
82
+ name: 'Text',
83
+ options: {
84
+ text: 'Tab 2'
85
+ }
86
+ }
87
+ }],
88
+ content: [{
89
+ ...defaultElement,
90
+ component: {
91
+ name: 'Text',
92
+ options: {
93
+ text: 'Tab 2 content'
94
+ }
95
+ }
96
+ }]
97
+ }]
98
+ }, {
99
+ name: 'activeTabStyle',
100
+ type: 'uiStyle',
101
+ helperText: 'CSS styles for the active tab',
102
+ defaultValue: {
103
+ backgroundColor: 'rgba(0, 0, 0, 0.1)'
104
+ }
105
+ }, {
106
+ name: 'defaultActiveTab',
107
+ type: 'number',
108
+ helperText: 'Default tab to open to. Set to "1" for the first tab, "2" for the second, or choose "0" for none',
109
+ defaultValue: 1,
110
+ advanced: true
111
+ }, {
112
+ name: 'collapsible',
113
+ type: 'boolean',
114
+ helperText: 'If on, clicking an open tab closes it so no tabs are active',
115
+ defaultValue: false,
116
+ advanced: true
117
+ }, {
118
+ name: 'tabHeaderLayout',
119
+ type: 'enum',
120
+ helperText: 'Change the layout of the tab headers (uses justify-content)',
121
+ defaultValue: 'flex-start',
122
+ enum: [{
123
+ label: 'Center',
124
+ value: 'center'
125
+ }, {
126
+ label: 'Space between',
127
+ value: 'space-between'
128
+ }, {
129
+ label: 'Space around',
130
+ value: 'space-around'
131
+ }, {
132
+ label: 'Left',
133
+ value: 'flex-start'
134
+ }, {
135
+ label: 'Right',
136
+ value: 'flex-end'
137
+ }]
138
+ }]
139
+ }
@@ -0,0 +1 @@
1
+ export { default } from './tabs'
@@ -0,0 +1,79 @@
1
+ import * as React from "react";
2
+ import {
3
+ FlatList,
4
+ ScrollView,
5
+ View,
6
+ StyleSheet,
7
+ Image,
8
+ Text,
9
+ Pressable,
10
+ TextInput,
11
+ } from "react-native";
12
+ import { useState } from "react";
13
+ import Blocks from "../../components/blocks/blocks";
14
+ import type { BuilderBlock } from "../../types/builder-block";
15
+ import type { TabsProps } from "./tabs.types";
16
+
17
+ function Tabs(props: TabsProps) {
18
+ const [activeTab, setActiveTab] = useState(() =>
19
+ props.defaultActiveTab ? props.defaultActiveTab - 1 : 0
20
+ );
21
+
22
+ function activeTabContent(active: number) {
23
+ return props.tabs && props.tabs[active].content;
24
+ }
25
+
26
+ function onClick(index: number) {
27
+ if (index === activeTab && props.collapsible) {
28
+ setActiveTab(-1);
29
+ } else {
30
+ setActiveTab(index);
31
+ }
32
+ }
33
+
34
+ return (
35
+ <View>
36
+ <View
37
+ style={{
38
+ display: "flex",
39
+ flexDirection: "row" as "row" | "column" | "column-reverse",
40
+ justifyContent: props.tabHeaderLayout || "flex-start",
41
+ overflow: "scroll" as "scroll" | "visible" | "hidden",
42
+ }}
43
+ >
44
+ {props.tabs?.map((tab, index) => (
45
+ <Pressable
46
+ key={index}
47
+ style={{
48
+ ...(activeTab === index ? props.activeTabStyle : {}),
49
+ }}
50
+ onPress={(event) => onClick(index)}
51
+ >
52
+ <Blocks
53
+ parent={props.builderBlock.id}
54
+ path={`component.options.tabs.${index}.label`}
55
+ blocks={tab.label}
56
+ context={props.builderContext}
57
+ registeredComponents={props.builderComponents}
58
+ linkComponent={props.builderLinkComponent}
59
+ />
60
+ </Pressable>
61
+ ))}
62
+ </View>
63
+ {activeTabContent(activeTab) ? (
64
+ <View>
65
+ <Blocks
66
+ parent={props.builderBlock.id}
67
+ path={`component.options.tabs.${activeTab}.content`}
68
+ blocks={activeTabContent(activeTab)}
69
+ context={props.builderContext}
70
+ registeredComponents={props.builderComponents}
71
+ linkComponent={props.builderLinkComponent}
72
+ />
73
+ </View>
74
+ ) : null}
75
+ </View>
76
+ );
77
+ }
78
+
79
+ export default Tabs;
@@ -0,0 +1,13 @@
1
+ import type { BuilderBlock } from '../../types/builder-block';
2
+ import type { BuilderComponentsProp, BuilderDataProps, BuilderLinkComponentProp } from '../../types/builder-props';
3
+ export interface TabsProps extends BuilderComponentsProp, BuilderLinkComponentProp, BuilderDataProps {
4
+ tabs: {
5
+ label: BuilderBlock[];
6
+ content: BuilderBlock[];
7
+ }[];
8
+ builderBlock: BuilderBlock;
9
+ defaultActiveTab?: number;
10
+ collapsible?: boolean;
11
+ tabHeaderLayout?: 'center' | 'flex-start' | 'flex-end' | 'space-between' | 'space-around' | 'space-evenly';
12
+ activeTabStyle?: any;
13
+ }
@@ -0,0 +1,20 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+ export const componentInfo: ComponentInfo = {
3
+ name: 'Text',
4
+ static: true,
5
+ isRSC: true,
6
+ image: 'https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-text_fields-24px%20(1).svg?alt=media&token=12177b73-0ee3-42ca-98c6-0dd003de1929',
7
+ inputs: [{
8
+ name: 'text',
9
+ type: 'html',
10
+ required: true,
11
+ autoFocus: true,
12
+ bubble: true,
13
+ defaultValue: 'Enter some text...'
14
+ }],
15
+ defaultStyles: {
16
+ lineHeight: 'normal',
17
+ height: 'auto',
18
+ textAlign: 'center'
19
+ }
20
+ }
@@ -0,0 +1 @@
1
+ export { default } from './text'
@@ -0,0 +1,105 @@
1
+ import * as React from 'react';
2
+ import { useWindowDimensions } from 'react-native';
3
+ import { RenderHTML } from 'react-native-render-html';
4
+ import BuilderContext from '../../context/builder.context';
5
+ import { checkIsDefined } from '../../helpers/nullable';
6
+ /**
7
+ * @typedef {{}} BuilderBlock
8
+ */
9
+
10
+ /**
11
+ *
12
+ * @param {string} string
13
+ * @returns {string}
14
+ */
15
+ function camelToKebabCase(string) {
16
+ return string.replace(/([a-z0-9]|(?=[A-Z]))([A-Z])/g, '$1-$2').toLowerCase();
17
+ }
18
+
19
+ /**
20
+ *
21
+ * @param {object} object
22
+ * @param {string[]} keys
23
+ * @returns {object}
24
+ */
25
+ function pick(object, keys) {
26
+ return keys.reduce((obj, key) => {
27
+ // eslint-disable-next-line no-prototype-builtins
28
+ if (object && object.hasOwnProperty(key)) {
29
+ obj[key] = object[key];
30
+ }
31
+ return obj;
32
+ }, {});
33
+ }
34
+
35
+ const PICK_STYLES = ['textAlign'];
36
+
37
+ /**
38
+ * @param {BuilderBlock} block
39
+ * @returns
40
+ */
41
+ function getBlockStyles(block) {
42
+ // TODO: responsive CSS using react native viewport width hooks
43
+ const styles = {
44
+ ...block.responsiveStyles?.large,
45
+ ...block.styles,
46
+ };
47
+
48
+ if (block.responsiveStyles?.medium) {
49
+ Object.assign(styles, block.responsiveStyles.medium);
50
+ }
51
+ if (block.responsiveStyles?.small) {
52
+ Object.assign(styles, block.responsiveStyles.small);
53
+ }
54
+
55
+ return styles;
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @param {BuilderBlock} block
61
+ * @param {any} inheritedStyles
62
+ * @returns
63
+ */
64
+ function getCss(block, inheritedStyles) {
65
+ const styleObject = {
66
+ ...inheritedStyles,
67
+ ...pick(getBlockStyles(block), PICK_STYLES),
68
+ };
69
+ if (!styleObject) {
70
+ return '';
71
+ }
72
+
73
+ let str = ``;
74
+
75
+ for (const key in styleObject) {
76
+ const value = styleObject[key];
77
+ if (typeof value === 'string') {
78
+ str += `${camelToKebabCase(key)}: ${value};`;
79
+ }
80
+ }
81
+
82
+ return str;
83
+ }
84
+
85
+ /**
86
+ *
87
+ * @param {{ text: string; builderBlock: BuilderBlock}} props
88
+ * @returns
89
+ */
90
+ export default function Text(props) {
91
+ const { width } = useWindowDimensions();
92
+ const builderContext = React.useContext(BuilderContext);
93
+
94
+ return (
95
+ <RenderHTML
96
+ contentWidth={width}
97
+ source={{
98
+ html: `<div style="${getCss(
99
+ props.builderBlock,
100
+ builderContext.inheritedStyles
101
+ )}">${checkIsDefined(props.text) ? String(props.text) : ''}</div>`,
102
+ }}
103
+ />
104
+ );
105
+ }
@@ -0,0 +1,4 @@
1
+ import type { BuilderDataProps } from '../../types/builder-props';
2
+ export type TextProps = {
3
+ text?: string;
4
+ } & BuilderDataProps
@@ -0,0 +1,38 @@
1
+ import type { ComponentInfo } from '../../types/components';
2
+ export const componentInfo: ComponentInfo = {
3
+ name: 'Form:TextArea',
4
+ image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Ff74a2f3de58c4c3e939204e5b6b8f6c3',
5
+ inputs: [{
6
+ advanced: true,
7
+ name: 'value',
8
+ type: 'string'
9
+ }, {
10
+ name: 'name',
11
+ type: 'string',
12
+ required: true,
13
+ helperText: 'Every input in a form needs a unique name describing what it gets, e.g. "email"'
14
+ }, {
15
+ name: 'defaultValue',
16
+ type: 'string'
17
+ }, {
18
+ name: 'placeholder',
19
+ type: 'string',
20
+ defaultValue: 'Hello there'
21
+ }, {
22
+ name: 'required',
23
+ type: 'boolean',
24
+ defaultValue: false
25
+ }],
26
+ defaultStyles: {
27
+ paddingTop: '10px',
28
+ paddingBottom: '10px',
29
+ paddingLeft: '10px',
30
+ paddingRight: '10px',
31
+ borderRadius: '3px',
32
+ borderWidth: '1px',
33
+ borderStyle: 'solid',
34
+ borderColor: '#ccc'
35
+ },
36
+ static: true,
37
+ noWrap: true
38
+ }
@@ -0,0 +1 @@
1
+ export { default } from './textarea'
@@ -0,0 +1,41 @@
1
+ import * as React from "react";
2
+ import {
3
+ FlatList,
4
+ ScrollView,
5
+ View,
6
+ StyleSheet,
7
+ Image,
8
+ Text,
9
+ Pressable,
10
+ TextInput,
11
+ } from "react-native";
12
+
13
+ /**
14
+ * This import is used by the Svelte SDK. Do not remove.
15
+ */
16
+
17
+ export interface TextareaProps {
18
+ attributes?: any;
19
+ name?: string;
20
+ value?: string;
21
+ defaultValue?: string;
22
+ placeholder?: string;
23
+ }
24
+
25
+ import { filterAttrs } from "../helpers";
26
+ import { setAttrs } from "../helpers";
27
+
28
+ function Textarea(props: TextareaProps) {
29
+ return (
30
+ <View
31
+ {...{}}
32
+ {...props.attributes}
33
+ placeholder={props.placeholder}
34
+ name={props.name}
35
+ value={props.value}
36
+ defaultValue={props.defaultValue}
37
+ />
38
+ );
39
+ }
40
+
41
+ export default Textarea;