@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,324 +0,0 @@
1
- import * as React from "react";
2
- import BaseText from "../../blocks/BaseText";
3
- import {
4
- FlatList,
5
- ScrollView,
6
- View,
7
- StyleSheet,
8
- Image,
9
- Text,
10
- Pressable,
11
- TextInput,
12
- } from "react-native";
13
- import { useState, useRef } from "react";
14
-
15
- /**
16
- * This import is used by the Svelte SDK. Do not remove.
17
- */
18
-
19
- export type FormProps = BuilderDataProps &
20
- BuilderComponentsProp &
21
- BuilderLinkComponentProp & {
22
- attributes?: any;
23
- name?: string;
24
- action?: string;
25
- validate?: boolean;
26
- method?: string;
27
- sendSubmissionsTo?: string;
28
- sendSubmissionsToEmail?: string;
29
- sendWithJs?: boolean;
30
- contentType?: string;
31
- customHeaders?: {
32
- [key: string]: string;
33
- };
34
- successUrl?: string;
35
- previewState?: FormState;
36
- successMessage?: BuilderBlock[];
37
- errorMessage?: BuilderBlock[];
38
- sendingMessage?: BuilderBlock[];
39
- resetFormOnSubmit?: boolean;
40
- errorMessagePath?: string;
41
- };
42
- /**
43
- * This import is used by the Svelte SDK. Do not remove.
44
- */
45
-
46
- export type FormState = "unsubmitted" | "sending" | "success" | "error";
47
- import Block from "../../../components/block/block";
48
- import Blocks from "../../../components/blocks/blocks";
49
- import { getEnv } from "../../../functions/get-env";
50
- import { get } from "../../../functions/get";
51
- import { isEditing } from "../../../functions/is-editing";
52
- import { set } from "../../../functions/set";
53
- import type { BuilderBlock } from "../../../types/builder-block";
54
- import type {
55
- BuilderComponentsProp,
56
- BuilderDataProps,
57
- BuilderLinkComponentProp,
58
- } from "../../../types/builder-props";
59
- import type { Dictionary } from "../../../types/typescript";
60
- import { filterAttrs } from "../../helpers";
61
- import { setAttrs } from "../../helpers";
62
-
63
- function FormComponent(props: FormProps) {
64
- const formRef = useRef<HTMLFormElement>(null);
65
- const [formState, setFormState] = useState(() => "unsubmitted");
66
-
67
- const [responseData, setResponseData] = useState(() => null);
68
-
69
- const [formErrorMessage, setFormErrorMessage] = useState(() => "");
70
-
71
- function mergeNewRootState(newData: Dictionary<any>) {
72
- const combinedState = {
73
- ...props.builderContext.rootState,
74
- ...newData,
75
- };
76
- if (props.builderContext.rootSetState) {
77
- props.builderContext.rootSetState?.(combinedState);
78
- } else {
79
- props.builderContext.rootState = combinedState;
80
- }
81
- }
82
-
83
- function submissionState() {
84
- return (isEditing() && props.previewState) || formState;
85
- }
86
-
87
- function onSubmit(event: any) {
88
- const sendWithJsProp =
89
- props.sendWithJs || props.sendSubmissionsTo === "email";
90
- if (props.sendSubmissionsTo === "zapier") {
91
- event.preventDefault();
92
- } else if (sendWithJsProp) {
93
- if (!(props.action || props.sendSubmissionsTo === "email")) {
94
- event.preventDefault();
95
- return;
96
- }
97
- event.preventDefault();
98
- const el = event.currentTarget || event.target;
99
- const headers = props.customHeaders || {};
100
- let body: any;
101
- const formData = new FormData(el);
102
-
103
- // TODO: maybe support null
104
- const formPairs: {
105
- key: string;
106
- value: File | boolean | number | string | FileList;
107
- }[] = Array.from(el.querySelectorAll("input,select,textarea"))
108
- .filter((el) => !!(el as HTMLInputElement).name)
109
- .map((el) => {
110
- let value: any;
111
- const key = (el as HTMLImageElement).name;
112
- if (el instanceof HTMLInputElement) {
113
- if (el.type === "radio") {
114
- if (el.checked) {
115
- value = el.name;
116
- return {
117
- key,
118
- value,
119
- };
120
- }
121
- } else if (el.type === "checkbox") {
122
- value = el.checked;
123
- } else if (el.type === "number" || el.type === "range") {
124
- const num = el.valueAsNumber;
125
- if (!isNaN(num)) {
126
- value = num;
127
- }
128
- } else if (el.type === "file") {
129
- // TODO: one vs multiple files
130
- value = el.files;
131
- } else {
132
- value = el.value;
133
- }
134
- } else {
135
- value = (el as HTMLInputElement).value;
136
- }
137
- return {
138
- key,
139
- value,
140
- };
141
- });
142
- let formContentType = props.contentType;
143
- if (props.sendSubmissionsTo === "email") {
144
- formContentType = "multipart/form-data";
145
- }
146
- Array.from(formPairs).forEach(({ value }) => {
147
- if (
148
- value instanceof File ||
149
- (Array.isArray(value) && value[0] instanceof File) ||
150
- value instanceof FileList
151
- ) {
152
- formContentType = "multipart/form-data";
153
- }
154
- });
155
-
156
- // TODO: send as urlEncoded or multipart by default
157
- // because of ease of use and reliability in browser API
158
- // for encoding the form?
159
- if (formContentType !== "application/json") {
160
- body = formData;
161
- } else {
162
- // Json
163
- const json = {};
164
- Array.from(formPairs).forEach(({ value, key }) => {
165
- set(json, key, value);
166
- });
167
- body = JSON.stringify(json);
168
- }
169
- if (formContentType && formContentType !== "multipart/form-data") {
170
- if (
171
- /* Zapier doesn't allow content-type header to be sent from browsers */ !(
172
- sendWithJsProp && props.action?.includes("zapier.com")
173
- )
174
- ) {
175
- headers["content-type"] = formContentType;
176
- }
177
- }
178
- const presubmitEvent = new CustomEvent("presubmit", { detail: { body } });
179
- if (formRef.current) {
180
- formRef.current.dispatchEvent(presubmitEvent);
181
- if (presubmitEvent.defaultPrevented) {
182
- return;
183
- }
184
- }
185
- setFormState("sending");
186
- const formUrl = `${
187
- getEnv() === "dev" ? "http://localhost:5000" : "https://builder.io"
188
- }/api/v1/form-submit?apiKey=${props.builderContext.apiKey}&to=${btoa(
189
- props.sendSubmissionsToEmail || ""
190
- )}&name=${encodeURIComponent(props.name || "")}`;
191
- fetch(
192
- props.sendSubmissionsTo === "email"
193
- ? formUrl
194
- : props.action! /* TODO: throw error if no action URL */,
195
- { body, headers, method: props.method || "post" }
196
- ).then(
197
- async (res) => {
198
- let body;
199
- const contentType = res.headers.get("content-type");
200
- if (contentType && contentType.indexOf("application/json") !== -1) {
201
- body = await res.json();
202
- } else {
203
- body = await res.text();
204
- }
205
- if (!res.ok && props.errorMessagePath) {
206
- /* TODO: allow supplying an error formatter function */ let message =
207
- get(body, props.errorMessagePath);
208
- if (message) {
209
- if (typeof message !== "string") {
210
- /* TODO: ideally convert json to yaml so it woul dbe like error: - email has been taken */ message =
211
- JSON.stringify(message);
212
- }
213
- setFormErrorMessage(message);
214
- mergeNewRootState({ formErrorMessage: message });
215
- }
216
- }
217
- setResponseData(body);
218
- setFormState(res.ok ? "success" : "error");
219
- if (res.ok) {
220
- const submitSuccessEvent = new CustomEvent("submit:success", {
221
- detail: { res, body },
222
- });
223
- if (formRef.current) {
224
- formRef.current.dispatchEvent(submitSuccessEvent);
225
- if (submitSuccessEvent.defaultPrevented) {
226
- return;
227
- }
228
- /* TODO: option to turn this on/off? */ if (
229
- props.resetFormOnSubmit !== false
230
- ) {
231
- formRef.current.reset();
232
- }
233
- }
234
- /* TODO: client side route event first that can be preventDefaulted */ if (
235
- props.successUrl
236
- ) {
237
- if (formRef.current) {
238
- const event = new CustomEvent("route", {
239
- detail: { url: props.successUrl },
240
- });
241
- formRef.current.dispatchEvent(event);
242
- if (!event.defaultPrevented) {
243
- location.href = props.successUrl;
244
- }
245
- } else {
246
- location.href = props.successUrl;
247
- }
248
- }
249
- }
250
- },
251
- (err) => {
252
- const submitErrorEvent = new CustomEvent("submit:error", {
253
- detail: { error: err },
254
- });
255
- if (formRef.current) {
256
- formRef.current.dispatchEvent(submitErrorEvent);
257
- if (submitErrorEvent.defaultPrevented) {
258
- return;
259
- }
260
- }
261
- setResponseData(err);
262
- setFormState("error");
263
- }
264
- );
265
- }
266
- }
267
- return (
268
- <View
269
- validate={props.validate}
270
- ref={formRef}
271
- action={!props.sendWithJs && props.action}
272
- method={props.method}
273
- name={props.name}
274
- onSubmit={(event) => onSubmit(event)}
275
- {...{}}
276
- {...{}}
277
- {...props.attributes}
278
- >
279
- {props.builderBlock && props.builderBlock.children ? (
280
- <>
281
- {props.builderBlock?.children?.map((block, idx) => (
282
- <Block
283
- key={`form-block-${idx}`}
284
- block={block}
285
- context={props.builderContext}
286
- registeredComponents={props.builderComponents}
287
- linkComponent={props.builderLinkComponent}
288
- />
289
- ))}
290
- </>
291
- ) : null}
292
- {submissionState() === "error" ? (
293
- <Blocks
294
- path="errorMessage"
295
- blocks={props.errorMessage!}
296
- context={props.builderContext}
297
- />
298
- ) : null}
299
- {submissionState() === "sending" ? (
300
- <Blocks
301
- path="sendingMessage"
302
- blocks={props.sendingMessage!}
303
- context={props.builderContext}
304
- />
305
- ) : null}
306
- {submissionState() === "error" && responseData ? (
307
- <View style={styles.view1}>
308
- <BaseText>{JSON.stringify(responseData, null, 2)}</BaseText>
309
- </View>
310
- ) : null}
311
- {submissionState() === "success" ? (
312
- <Blocks
313
- path="successMessage"
314
- blocks={props.successMessage!}
315
- context={props.builderContext}
316
- />
317
- ) : null}
318
- </View>
319
- );
320
- }
321
- const styles = StyleSheet.create({
322
- view1: { padding: 10, color: "red", textAlign: "center" },
323
- });
324
- export default FormComponent;
@@ -1 +0,0 @@
1
- export { default } from './form'
@@ -1,47 +0,0 @@
1
- import type { ComponentInfo } from '../../../types/components';
2
- export const componentInfo: ComponentInfo = {
3
- name: 'Form:Input',
4
- image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fad6f37889d9e40bbbbc72cdb5875d6ca',
5
- inputs: [{
6
- name: 'type',
7
- type: 'text',
8
- enum: ['text', 'number', 'email', 'url', 'checkbox', 'radio', 'range', 'date', 'datetime-local', 'search', 'tel', 'time', 'file', 'month', 'week', 'password', 'color', 'hidden'],
9
- defaultValue: 'text'
10
- }, {
11
- name: 'name',
12
- type: 'string',
13
- required: true,
14
- helperText: 'Every input in a form needs a unique name describing what it takes, e.g. "email"'
15
- }, {
16
- name: 'placeholder',
17
- type: 'string',
18
- defaultValue: 'Hello there',
19
- helperText: 'Text to display when there is no value'
20
- },
21
- // TODO: handle value vs default value automatically like ng-model
22
- {
23
- name: 'defaultValue',
24
- type: 'string'
25
- }, {
26
- name: 'value',
27
- type: 'string',
28
- advanced: true
29
- }, {
30
- name: 'required',
31
- type: 'boolean',
32
- helperText: 'Is this input required to be filled out to submit a form',
33
- defaultValue: false
34
- }],
35
- noWrap: true,
36
- static: true,
37
- defaultStyles: {
38
- paddingTop: '10px',
39
- paddingBottom: '10px',
40
- paddingLeft: '10px',
41
- paddingRight: '10px',
42
- borderRadius: '3px',
43
- borderWidth: '1px',
44
- borderStyle: 'solid',
45
- borderColor: '#ccc'
46
- }
47
- }
@@ -1 +0,0 @@
1
- export { default } from './input'
@@ -1,49 +0,0 @@
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 FormInputProps {
18
- type?: string;
19
- attributes?: any;
20
- name?: string;
21
- value?: string;
22
- placeholder?: string;
23
- defaultValue?: string;
24
- required?: boolean;
25
- }
26
-
27
- import { isEditing } from "../../../functions/is-editing";
28
- import { filterAttrs } from "../../helpers";
29
- import { setAttrs } from "../../helpers";
30
-
31
- function FormInputComponent(props: FormInputProps) {
32
- return (
33
- <TextInput
34
- {...{}}
35
- {...props.attributes}
36
- key={
37
- isEditing() && props.defaultValue ? props.defaultValue : "default-key"
38
- }
39
- placeholder={props.placeholder}
40
- type={props.type}
41
- name={props.name}
42
- value={props.value}
43
- defaultValue={props.defaultValue}
44
- required={props.required}
45
- />
46
- );
47
- }
48
-
49
- export default FormInputComponent;
@@ -1,44 +0,0 @@
1
- import type { ComponentInfo } from '../../../types/components';
2
- export const componentInfo: ComponentInfo = {
3
- name: 'Form:Select',
4
- image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2F83acca093fb24aaf94dee136e9a4b045',
5
- defaultStyles: {
6
- alignSelf: 'flex-start'
7
- },
8
- inputs: [{
9
- name: 'options',
10
- type: 'list',
11
- required: true,
12
- subFields: [{
13
- name: 'value',
14
- type: 'text',
15
- required: true
16
- }, {
17
- name: 'name',
18
- type: 'text'
19
- }],
20
- defaultValue: [{
21
- value: 'option 1'
22
- }, {
23
- value: 'option 2'
24
- }]
25
- }, {
26
- name: 'name',
27
- type: 'string',
28
- required: true,
29
- helperText: 'Every select in a form needs a unique name describing what it gets, e.g. "email"'
30
- }, {
31
- name: 'defaultValue',
32
- type: 'string'
33
- }, {
34
- name: 'value',
35
- type: 'string',
36
- advanced: true
37
- }, {
38
- name: 'required',
39
- type: 'boolean',
40
- defaultValue: false
41
- }],
42
- static: true,
43
- noWrap: true
44
- }
@@ -1 +0,0 @@
1
- export { default } from './select'
@@ -1,54 +0,0 @@
1
- import * as React from "react";
2
- import BaseText from "../../blocks/BaseText";
3
- import {
4
- FlatList,
5
- ScrollView,
6
- View,
7
- StyleSheet,
8
- Image,
9
- Text,
10
- Pressable,
11
- TextInput,
12
- } from "react-native";
13
-
14
- /**
15
- * This import is used by the Svelte SDK. Do not remove.
16
- */
17
-
18
- export interface FormSelectProps {
19
- options?: {
20
- name?: string;
21
- value: string;
22
- }[];
23
- attributes?: any;
24
- name?: string;
25
- value?: string;
26
- defaultValue?: string;
27
- }
28
-
29
- import { isEditing } from "../../../functions/is-editing";
30
- import { filterAttrs } from "../../helpers";
31
- import { setAttrs } from "../../helpers";
32
-
33
- function SelectComponent(props: FormSelectProps) {
34
- return (
35
- <View
36
- {...{}}
37
- {...props.attributes}
38
- value={props.value}
39
- key={
40
- isEditing() && props.defaultValue ? props.defaultValue : "default-key"
41
- }
42
- defaultValue={props.defaultValue}
43
- name={props.name}
44
- >
45
- {props.options?.map((option, index) => (
46
- <View key={`${option.name}-${index}`} value={option.value}>
47
- <BaseText>{option.name || option.value}</BaseText>
48
- </View>
49
- ))}
50
- </View>
51
- );
52
- }
53
-
54
- export default SelectComponent;
@@ -1,27 +0,0 @@
1
- import type { ComponentInfo } from '../../../types/components';
2
- export const componentInfo: ComponentInfo = {
3
- name: 'Form:SubmitButton',
4
- image: 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fdf2820ffed1f4349a94c40b3221f5b98',
5
- defaultStyles: {
6
- appearance: 'none',
7
- paddingTop: '15px',
8
- paddingBottom: '15px',
9
- paddingLeft: '25px',
10
- paddingRight: '25px',
11
- backgroundColor: '#3898EC',
12
- color: 'white',
13
- borderRadius: '4px',
14
- cursor: 'pointer'
15
- },
16
- inputs: [{
17
- name: 'text',
18
- type: 'text',
19
- defaultValue: 'Click me'
20
- }],
21
- static: true,
22
- noWrap: true
23
- // TODO: optional children? maybe as optional form input
24
- // that only shows if advanced setting is flipped
25
- // TODO: defaultChildren
26
- // canHaveChildren: true,
27
- }
@@ -1 +0,0 @@
1
- export { default } from './submit-button'
@@ -1,34 +0,0 @@
1
- import * as React from "react";
2
- import BaseText from "../../blocks/BaseText";
3
- import {
4
- FlatList,
5
- ScrollView,
6
- View,
7
- StyleSheet,
8
- Image,
9
- Text,
10
- Pressable,
11
- TextInput,
12
- } from "react-native";
13
-
14
- /**
15
- * This import is used by the Svelte SDK. Do not remove.
16
- */
17
-
18
- export interface ButtonProps {
19
- attributes?: any;
20
- text?: string;
21
- }
22
-
23
- import { filterAttrs } from "../../helpers";
24
- import { setAttrs } from "../../helpers";
25
-
26
- function SubmitButton(props: ButtonProps) {
27
- return (
28
- <View type="submit" {...{}} {...props.attributes}>
29
- <BaseText>{props.text}</BaseText>
30
- </View>
31
- );
32
- }
33
-
34
- export default SubmitButton;
@@ -1,8 +0,0 @@
1
- import type { ComponentInfo } from '../../types/components';
2
- export const componentInfo: ComponentInfo = {
3
- name: 'Fragment',
4
- static: true,
5
- hidden: true,
6
- canHaveChildren: true,
7
- noWrap: true
8
- }
@@ -1,18 +0,0 @@
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 type { FragmentProps } from "./fragment.types";
13
-
14
- function FragmentComponent(props: FragmentProps) {
15
- return <View>{props.children}</View>;
16
- }
17
-
18
- export default FragmentComponent;
@@ -1,5 +0,0 @@
1
- export interface FragmentProps {
2
- maxWidth?: number;
3
- attributes?: any;
4
- children?: any;
5
- }
@@ -1 +0,0 @@
1
- export { default } from './fragment'
@@ -1,43 +0,0 @@
1
- export function filterAttrs(attrs: {
2
- [index: string]: any;
3
- } = {}, prefix: string, isEvent: boolean) {
4
- const result: typeof attrs = {};
5
- for (const attr in attrs) {
6
- if (!attrs[attr]) continue;
7
- if (isEvent && !attr.startsWith(prefix)) continue;
8
- const eventName = isEvent ? attr.replace(prefix, '') : attr;
9
- result[eventName] = attrs[attr];
10
- }
11
- return result;
12
- }
13
-
14
- /**
15
- * Svelte SDK: workaround to dynamically provide event handlers to components/elements.
16
- * https://svelte.dev/repl/1246699e266f41218a8eeb45b9b58b54?version=3.24.1
17
- */
18
- export function setAttrs(node: HTMLElement, attrs: Record<string, (event: Event) => void> = {}) {
19
- const attrKeys = Object.keys(attrs);
20
-
21
- /**
22
- *
23
- * @param {string} attr
24
- */
25
- const setup = (attr: string) => node.addEventListener(attr, attrs[attr]);
26
-
27
- /**
28
- *
29
- * @param {string} attr
30
- */
31
- const teardown = (attr: string) => node.removeEventListener(attr, attrs[attr]);
32
- attrKeys.forEach(setup);
33
- return {
34
- update(attrs = {}) {
35
- const attrKeys = Object.keys(attrs);
36
- attrKeys.forEach(teardown);
37
- attrKeys.forEach(setup);
38
- },
39
- destroy() {
40
- attrKeys.forEach(teardown);
41
- }
42
- };
43
- }