@builder.io/sdk-react-native 0.0.1-22 → 0.0.1-26

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 (77) hide show
  1. package/package.json +3 -2
  2. package/src/blocks/button.js +66 -24
  3. package/src/blocks/button.lite.tsx +9 -13
  4. package/src/blocks/columns.js +247 -36
  5. package/src/blocks/columns.lite.tsx +7 -7
  6. package/src/blocks/custom-code.js +73 -47
  7. package/src/blocks/custom-code.lite.tsx +12 -16
  8. package/src/blocks/embed.js +66 -47
  9. package/src/blocks/embed.lite.tsx +11 -13
  10. package/src/blocks/form.js +436 -198
  11. package/src/blocks/form.lite.tsx +67 -78
  12. package/src/blocks/fragment.js +16 -11
  13. package/src/blocks/fragment.lite.tsx +8 -5
  14. package/src/blocks/image.js +89 -80
  15. package/src/blocks/image.lite.tsx +44 -13
  16. package/src/blocks/img.js +45 -28
  17. package/src/blocks/img.lite.tsx +7 -7
  18. package/src/blocks/input.js +93 -28
  19. package/src/blocks/input.lite.tsx +5 -9
  20. package/src/blocks/raw-text.js +16 -12
  21. package/src/blocks/raw-text.lite.tsx +3 -3
  22. package/src/blocks/section.js +66 -23
  23. package/src/blocks/section.lite.tsx +4 -4
  24. package/src/blocks/select.js +67 -28
  25. package/src/blocks/select.lite.tsx +6 -10
  26. package/src/blocks/submit-button.js +41 -21
  27. package/src/blocks/submit-button.lite.tsx +3 -3
  28. package/src/blocks/symbol.js +18 -16
  29. package/src/blocks/symbol.lite.tsx +5 -5
  30. package/src/blocks/text.js +29 -27
  31. package/src/blocks/text.lite.tsx +4 -9
  32. package/src/blocks/textarea.js +53 -24
  33. package/src/blocks/textarea.lite.tsx +3 -3
  34. package/src/blocks/video.js +112 -46
  35. package/src/blocks/video.lite.tsx +6 -6
  36. package/src/components/block-styles.js +2 -4
  37. package/src/components/block-styles.lite.tsx +3 -3
  38. package/src/components/error-boundary.js +11 -9
  39. package/src/components/error-boundary.lite.tsx +3 -3
  40. package/src/components/render-block.js +89 -36
  41. package/src/components/render-block.lite.tsx +47 -32
  42. package/src/components/render-blocks.js +56 -32
  43. package/src/components/render-blocks.lite.tsx +16 -16
  44. package/src/components/render-content.js +160 -36
  45. package/src/components/render-content.lite.tsx +139 -39
  46. package/src/constants/device-sizes.js +8 -11
  47. package/src/context/builder.context.js +2 -4
  48. package/src/functions/evaluate.js +17 -9
  49. package/src/functions/get-block-actions.js +9 -10
  50. package/src/functions/get-block-component-options.js +11 -10
  51. package/src/functions/get-block-properties.js +15 -17
  52. package/src/functions/get-block-styles.js +25 -17
  53. package/src/functions/get-block-tag.js +2 -4
  54. package/src/functions/get-content.js +54 -27
  55. package/src/functions/get-fetch.js +11 -0
  56. package/src/functions/get-global-this.js +17 -0
  57. package/src/functions/get-processed-block.js +11 -13
  58. package/src/functions/get-processed-block.test.js +14 -14
  59. package/src/functions/get-target.js +3 -5
  60. package/src/functions/if-target.js +1 -3
  61. package/src/functions/is-browser.js +3 -5
  62. package/src/functions/is-editing.js +3 -5
  63. package/src/functions/is-iframe.js +2 -4
  64. package/src/functions/is-previewing.js +13 -0
  65. package/src/functions/is-react-native.js +2 -4
  66. package/src/functions/macro-eval.js +2 -5
  67. package/src/functions/on-change.js +4 -7
  68. package/src/functions/on-change.test.js +10 -10
  69. package/src/functions/previewing-model-name.js +10 -0
  70. package/src/functions/register-component.js +34 -28
  71. package/src/functions/register.js +8 -10
  72. package/src/functions/set-editor-settings.js +5 -7
  73. package/src/functions/set.js +10 -4
  74. package/src/functions/set.test.js +14 -14
  75. package/src/functions/track.js +6 -8
  76. package/src/index.js +18 -20
  77. package/src/scripts/init-editing.js +65 -31
@@ -1,11 +1,11 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext } from "react";
4
- import RenderBlocks from "../components/render-blocks.lite";
1
+ import * as React from 'react';
2
+ import { View, StyleSheet, Image, Text } from 'react-native';
3
+ import { useState, useContext } from 'react';
4
+ import RenderBlocks from '../components/render-blocks.lite';
5
5
 
6
6
  export default function Columns(props) {
7
7
  function getGutterSize() {
8
- return typeof props.space === "number" ? props.space || 0 : 20;
8
+ return typeof props.space === 'number' ? props.space || 0 : 20;
9
9
  }
10
10
 
11
11
  function getColumns() {
@@ -26,7 +26,7 @@ export default function Columns(props) {
26
26
 
27
27
  return (
28
28
  <View className="builder-columns" style={styles.view1}>
29
- {props.columns?.map((column) => (
29
+ {props.columns?.map(column => (
30
30
  <View className="builder-column" style={styles.view2}>
31
31
  <RenderBlocks blocks={column.blocks} />
32
32
  </View>
@@ -36,6 +36,6 @@ export default function Columns(props) {
36
36
  }
37
37
 
38
38
  const styles = StyleSheet.create({
39
- view1: { display: "flex", alignItems: "stretch" },
39
+ view1: { display: 'flex', alignItems: 'stretch' },
40
40
  view2: { flexGrow: 1 },
41
41
  });
@@ -1,56 +1,82 @@
1
1
  import { registerComponent } from '../functions/register-component';
2
2
 
3
- import * as React from "react";
4
- import { View } from "react-native";
5
- import { useState, useRef, useEffect } from "react";
3
+ import * as React from 'react';
4
+ import { View } from 'react-native';
5
+ import { useState, useRef, useEffect } from 'react';
6
6
  function CustomCode(props) {
7
- const [scriptsInserted, setScriptsInserted] = useState(() => []);
8
- const [scriptsRun, setScriptsRun] = useState(() => []);
9
- function findAndRunScripts() {
10
- if (elem.current && typeof window !== "undefined") {
11
- const scripts = elem.current.getElementsByTagName("script");
12
- for (let i = 0; i < scripts.length; i++) {
13
- const script = scripts[i];
14
- if (script.src) {
15
- if (scriptsInserted.includes(script.src)) {
16
- continue;
17
- }
18
- scriptsInserted.push(script.src);
19
- const newScript = document.createElement("script");
20
- newScript.async = true;
21
- newScript.src = script.src;
22
- document.head.appendChild(newScript);
23
- } else if (!script.type || [
24
- "text/javascript",
25
- "application/javascript",
26
- "application/ecmascript"
27
- ].includes(script.type)) {
28
- if (scriptsRun.includes(script.innerText)) {
29
- continue;
30
- }
31
- try {
32
- scriptsRun.push(script.innerText);
33
- new Function(script.innerText)();
34
- } catch (error) {
35
- console.warn("`CustomCode`: Error running script:", error);
7
+ const [scriptsInserted, setScriptsInserted] = useState(() => []);
8
+ const [scriptsRun, setScriptsRun] = useState(() => []);
9
+ function findAndRunScripts() {
10
+ if (elem.current && typeof window !== 'undefined') {
11
+ const scripts = elem.current.getElementsByTagName('script');
12
+ for (let i = 0; i < scripts.length; i++) {
13
+ const script = scripts[i];
14
+ if (script.src) {
15
+ if (scriptsInserted.includes(script.src)) {
16
+ continue;
17
+ }
18
+ scriptsInserted.push(script.src);
19
+ const newScript = document.createElement('script');
20
+ newScript.async = true;
21
+ newScript.src = script.src;
22
+ document.head.appendChild(newScript);
23
+ } else if (
24
+ !script.type ||
25
+ ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(
26
+ script.type
27
+ )
28
+ ) {
29
+ if (scriptsRun.includes(script.innerText)) {
30
+ continue;
31
+ }
32
+ try {
33
+ scriptsRun.push(script.innerText);
34
+ new Function(script.innerText)();
35
+ } catch (error) {
36
+ console.warn('`CustomCode`: Error running script:', error);
37
+ }
36
38
  }
37
39
  }
38
40
  }
39
41
  }
42
+ const elem = useRef();
43
+ useEffect(() => {
44
+ findAndRunScripts();
45
+ }, []);
46
+ return /* @__PURE__ */ React.createElement(View, {
47
+ ref: elem,
48
+ className: 'builder-custom-code' + (props.replaceNodes ? ' replace-nodes' : ''),
49
+ dangerouslySetInnerHTML: { __html: 'props.code' },
50
+ });
40
51
  }
41
- const elem = useRef();
42
- useEffect(() => {
43
- findAndRunScripts();
44
- }, []);
45
- return /* @__PURE__ */ React.createElement(View, {
46
- ref: elem,
47
- className: "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : ""),
48
- dangerouslySetInnerHTML: { __html: "props.code" }
49
- });
50
- }
51
- export {
52
- CustomCode as default
53
- };
54
-
52
+ export { CustomCode as default };
55
53
 
56
- registerComponent(CustomCode, {name:'Custom Code',static:true,requiredPermissions:['editCode'],inputs:[{name:'code',type:'html',required:true,defaultValue:'<p>Hello there, I am custom HTML code!</p>',code:true},{name:'replaceNodes',type:'boolean',helperText:'Preserve server rendered dom nodes',advanced:true},{name:'scriptsClientOnly',type:'boolean',defaultValue:false,helperText:'Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads',advanced:true}]});
54
+ registerComponent(CustomCode, {
55
+ name: 'Custom Code',
56
+ static: true,
57
+ builtIn: true,
58
+ requiredPermissions: ['editCode'],
59
+ inputs: [
60
+ {
61
+ name: 'code',
62
+ type: 'html',
63
+ required: true,
64
+ defaultValue: '<p>Hello there, I am custom HTML code!</p>',
65
+ code: true,
66
+ },
67
+ {
68
+ name: 'replaceNodes',
69
+ type: 'boolean',
70
+ helperText: 'Preserve server rendered dom nodes',
71
+ advanced: true,
72
+ },
73
+ {
74
+ name: 'scriptsClientOnly',
75
+ type: 'boolean',
76
+ defaultValue: false,
77
+ helperText:
78
+ 'Only print and run scripts on the client. Important when scripts influence DOM that could be replaced when client loads',
79
+ advanced: true,
80
+ },
81
+ ],
82
+ });
@@ -1,6 +1,6 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext, useRef, useEffect } from "react";
1
+ import * as React from 'react';
2
+ import { View, StyleSheet, Image, Text } from 'react-native';
3
+ import { useState, useContext, useRef, useEffect } from 'react';
4
4
 
5
5
  export default function CustomCode(props) {
6
6
  const [scriptsInserted, setScriptsInserted] = useState(() => []);
@@ -9,9 +9,9 @@ export default function CustomCode(props) {
9
9
 
10
10
  function findAndRunScripts() {
11
11
  // TODO: Move this function to standalone one in '@builder.io/utils'
12
- if (elem.current && typeof window !== "undefined") {
12
+ if (elem.current && typeof window !== 'undefined') {
13
13
  /** @type {HTMLScriptElement[]} */
14
- const scripts = elem.current.getElementsByTagName("script");
14
+ const scripts = elem.current.getElementsByTagName('script');
15
15
 
16
16
  for (let i = 0; i < scripts.length; i++) {
17
17
  const script = scripts[i];
@@ -22,17 +22,15 @@ export default function CustomCode(props) {
22
22
  }
23
23
 
24
24
  scriptsInserted.push(script.src);
25
- const newScript = document.createElement("script");
25
+ const newScript = document.createElement('script');
26
26
  newScript.async = true;
27
27
  newScript.src = script.src;
28
28
  document.head.appendChild(newScript);
29
29
  } else if (
30
30
  !script.type ||
31
- [
32
- "text/javascript",
33
- "application/javascript",
34
- "application/ecmascript",
35
- ].includes(script.type)
31
+ ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(
32
+ script.type
33
+ )
36
34
  ) {
37
35
  if (scriptsRun.includes(script.innerText)) {
38
36
  continue;
@@ -42,7 +40,7 @@ export default function CustomCode(props) {
42
40
  scriptsRun.push(script.innerText);
43
41
  new Function(script.innerText)();
44
42
  } catch (error) {
45
- console.warn("`CustomCode`: Error running script:", error);
43
+ console.warn('`CustomCode`: Error running script:', error);
46
44
  }
47
45
  }
48
46
  }
@@ -58,10 +56,8 @@ export default function CustomCode(props) {
58
56
  return (
59
57
  <View
60
58
  ref={elem}
61
- className={
62
- "builder-custom-code" + (props.replaceNodes ? " replace-nodes" : "")
63
- }
64
- dangerouslySetInnerHTML={{ __html: "props.code" }}
59
+ className={'builder-custom-code' + (props.replaceNodes ? ' replace-nodes' : '')}
60
+ dangerouslySetInnerHTML={{ __html: 'props.code' }}
65
61
  />
66
62
  );
67
63
  }
@@ -1,56 +1,75 @@
1
1
  import { registerComponent } from '../functions/register-component';
2
2
 
3
- import * as React from "react";
4
- import { View } from "react-native";
5
- import { useState, useRef, useEffect } from "react";
3
+ import * as React from 'react';
4
+ import { View } from 'react-native';
5
+ import { useState, useRef, useEffect } from 'react';
6
6
  function Embed(props) {
7
- const [scriptsInserted, setScriptsInserted] = useState(() => []);
8
- const [scriptsRun, setScriptsRun] = useState(() => []);
9
- function findAndRunScripts() {
10
- if (elem.current && typeof window !== "undefined") {
11
- const scripts = elem.current.getElementsByTagName("script");
12
- for (let i = 0; i < scripts.length; i++) {
13
- const script = scripts[i];
14
- if (script.src) {
15
- if (scriptsInserted.includes(script.src)) {
16
- continue;
17
- }
18
- scriptsInserted.push(script.src);
19
- const newScript = document.createElement("script");
20
- newScript.async = true;
21
- newScript.src = script.src;
22
- document.head.appendChild(newScript);
23
- } else if (!script.type || [
24
- "text/javascript",
25
- "application/javascript",
26
- "application/ecmascript"
27
- ].includes(script.type)) {
28
- if (scriptsRun.includes(script.innerText)) {
29
- continue;
30
- }
31
- try {
32
- scriptsRun.push(script.innerText);
33
- new Function(script.innerText)();
34
- } catch (error) {
35
- console.warn("`Embed`: Error running script:", error);
7
+ const [scriptsInserted, setScriptsInserted] = useState(() => []);
8
+ const [scriptsRun, setScriptsRun] = useState(() => []);
9
+ function findAndRunScripts() {
10
+ if (elem.current && typeof window !== 'undefined') {
11
+ const scripts = elem.current.getElementsByTagName('script');
12
+ for (let i = 0; i < scripts.length; i++) {
13
+ const script = scripts[i];
14
+ if (script.src) {
15
+ if (scriptsInserted.includes(script.src)) {
16
+ continue;
17
+ }
18
+ scriptsInserted.push(script.src);
19
+ const newScript = document.createElement('script');
20
+ newScript.async = true;
21
+ newScript.src = script.src;
22
+ document.head.appendChild(newScript);
23
+ } else if (
24
+ !script.type ||
25
+ ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(
26
+ script.type
27
+ )
28
+ ) {
29
+ if (scriptsRun.includes(script.innerText)) {
30
+ continue;
31
+ }
32
+ try {
33
+ scriptsRun.push(script.innerText);
34
+ new Function(script.innerText)();
35
+ } catch (error) {
36
+ console.warn('`Embed`: Error running script:', error);
37
+ }
36
38
  }
37
39
  }
38
40
  }
39
41
  }
42
+ const elem = useRef();
43
+ useEffect(() => {
44
+ findAndRunScripts();
45
+ }, []);
46
+ return /* @__PURE__ */ React.createElement(View, {
47
+ className: 'builder-embed',
48
+ ref: elem,
49
+ dangerouslySetInnerHTML: { __html: 'props.content' },
50
+ });
40
51
  }
41
- const elem = useRef();
42
- useEffect(() => {
43
- findAndRunScripts();
44
- }, []);
45
- return /* @__PURE__ */ React.createElement(View, {
46
- className: "builder-embed",
47
- ref: elem,
48
- dangerouslySetInnerHTML: { __html: "props.content" }
49
- });
50
- }
51
- export {
52
- Embed as default
53
- };
54
-
52
+ export { Embed as default };
55
53
 
56
- registerComponent(Embed, {name:'Embed',static:true,inputs:[{name:'url',type:'url',required:true,defaultValue:'',helperText:'e.g. enter a youtube url, google map, etc',onChange:" const url = options.get('url'); if (url) { options.set('content', 'Loading...'); // TODO: get this out of here! const apiKey = 'ae0e60e78201a3f2b0de4b'; return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`) .then(res => res.json()) .then(data => { if (options.get('url') === url) { if (data.html) { options.set('content', data.html); } else { options.set('content', 'Invalid url, please try another'); } } }) .catch(err => { options.set( 'content', 'There was an error embedding this URL, please try again or another URL' ); }); } else { options.delete('content'); } "},{name:'content',type:'html',defaultValue:'<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',hideFromUI:true}]});
54
+ registerComponent(Embed, {
55
+ name: 'Embed',
56
+ static: true,
57
+ builtIn: true,
58
+ inputs: [
59
+ {
60
+ name: 'url',
61
+ type: 'url',
62
+ required: true,
63
+ defaultValue: '',
64
+ helperText: 'e.g. enter a youtube url, google map, etc',
65
+ onChange:
66
+ " const url = options.get('url'); if (url) { options.set('content', 'Loading...'); // TODO: get this out of here! const apiKey = 'ae0e60e78201a3f2b0de4b'; return fetch(`https://iframe.ly/api/iframely?url=${url}&api_key=${apiKey}`) .then(res => res.json()) .then(data => { if (options.get('url') === url) { if (data.html) { options.set('content', data.html); } else { options.set('content', 'Invalid url, please try another'); } } }) .catch(err => { options.set( 'content', 'There was an error embedding this URL, please try again or another URL' ); }); } else { options.delete('content'); } ",
67
+ },
68
+ {
69
+ name: 'content',
70
+ type: 'html',
71
+ defaultValue: '<div style="padding: 20px; text-align: center">(Choose an embed URL)<div>',
72
+ hideFromUI: true,
73
+ },
74
+ ],
75
+ });
@@ -1,6 +1,6 @@
1
- import * as React from "react";
2
- import { View, StyleSheet, Image, Text } from "react-native";
3
- import { useState, useContext, useRef, useEffect } from "react";
1
+ import * as React from 'react';
2
+ import { View, StyleSheet, Image, Text } from 'react-native';
3
+ import { useState, useContext, useRef, useEffect } from 'react';
4
4
 
5
5
  export default function Embed(props) {
6
6
  const [scriptsInserted, setScriptsInserted] = useState(() => []);
@@ -9,9 +9,9 @@ export default function Embed(props) {
9
9
 
10
10
  function findAndRunScripts() {
11
11
  // TODO: Move this function to standalone one in '@builder.io/utils'
12
- if (elem.current && typeof window !== "undefined") {
12
+ if (elem.current && typeof window !== 'undefined') {
13
13
  /** @type {HTMLScriptElement[]} */
14
- const scripts = elem.current.getElementsByTagName("script");
14
+ const scripts = elem.current.getElementsByTagName('script');
15
15
 
16
16
  for (let i = 0; i < scripts.length; i++) {
17
17
  const script = scripts[i];
@@ -22,17 +22,15 @@ export default function Embed(props) {
22
22
  }
23
23
 
24
24
  scriptsInserted.push(script.src);
25
- const newScript = document.createElement("script");
25
+ const newScript = document.createElement('script');
26
26
  newScript.async = true;
27
27
  newScript.src = script.src;
28
28
  document.head.appendChild(newScript);
29
29
  } else if (
30
30
  !script.type ||
31
- [
32
- "text/javascript",
33
- "application/javascript",
34
- "application/ecmascript",
35
- ].includes(script.type)
31
+ ['text/javascript', 'application/javascript', 'application/ecmascript'].includes(
32
+ script.type
33
+ )
36
34
  ) {
37
35
  if (scriptsRun.includes(script.innerText)) {
38
36
  continue;
@@ -42,7 +40,7 @@ export default function Embed(props) {
42
40
  scriptsRun.push(script.innerText);
43
41
  new Function(script.innerText)();
44
42
  } catch (error) {
45
- console.warn("`Embed`: Error running script:", error);
43
+ console.warn('`Embed`: Error running script:', error);
46
44
  }
47
45
  }
48
46
  }
@@ -59,7 +57,7 @@ export default function Embed(props) {
59
57
  <View
60
58
  className="builder-embed"
61
59
  ref={elem}
62
- dangerouslySetInnerHTML={{ __html: "props.content" }}
60
+ dangerouslySetInnerHTML={{ __html: 'props.content' }}
63
61
  />
64
62
  );
65
63
  }
@@ -1,229 +1,467 @@
1
1
  import { registerComponent } from '../functions/register-component';
2
2
 
3
- var __defProp = Object.defineProperty;
3
+ var __defProp = Object.defineProperty;
4
4
  var __defProps = Object.defineProperties;
5
5
  var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
6
6
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
7
7
  var __hasOwnProp = Object.prototype.hasOwnProperty;
8
8
  var __propIsEnum = Object.prototype.propertyIsEnumerable;
9
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
9
+ var __defNormalProp = (obj, key, value) =>
10
+ key in obj
11
+ ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value })
12
+ : (obj[key] = value);
10
13
  var __spreadValues = (a, b) => {
11
- for (var prop in b || (b = {}))
12
- if (__hasOwnProp.call(b, prop))
13
- __defNormalProp(a, prop, b[prop]);
14
- if (__getOwnPropSymbols)
15
- for (var prop of __getOwnPropSymbols(b)) {
16
- if (__propIsEnum.call(b, prop))
17
- __defNormalProp(a, prop, b[prop]);
18
- }
19
- return a;
14
+ for (var prop in b || (b = {})) if (__hasOwnProp.call(b, prop)) __defNormalProp(a, prop, b[prop]);
15
+ if (__getOwnPropSymbols)
16
+ for (var prop of __getOwnPropSymbols(b)) {
17
+ if (__propIsEnum.call(b, prop)) __defNormalProp(a, prop, b[prop]);
18
+ }
19
+ return a;
20
20
  };
21
21
  var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
22
22
  var __async = (__this, __arguments, generator) => {
23
- return new Promise((resolve, reject) => {
24
- var fulfilled = (value) => {
25
- try {
26
- step(generator.next(value));
27
- } catch (e) {
28
- reject(e);
29
- }
30
- };
31
- var rejected = (value) => {
32
- try {
33
- step(generator.throw(value));
34
- } catch (e) {
35
- reject(e);
36
- }
37
- };
38
- var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
39
- step((generator = generator.apply(__this, __arguments)).next());
40
- });
23
+ return new Promise((resolve, reject) => {
24
+ var fulfilled = value => {
25
+ try {
26
+ step(generator.next(value));
27
+ } catch (e) {
28
+ reject(e);
29
+ }
30
+ };
31
+ var rejected = value => {
32
+ try {
33
+ step(generator.throw(value));
34
+ } catch (e) {
35
+ reject(e);
36
+ }
37
+ };
38
+ var step = x =>
39
+ x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
40
+ step((generator = generator.apply(__this, __arguments)).next());
41
+ });
41
42
  };
42
- import * as React from "react";
43
- import { View, StyleSheet, Text } from "react-native";
44
- import { useState, useRef } from "react";
45
- import { Builder, builder } from "@builder.io/sdk";
46
- import { BuilderBlocks } from "@dummy";
47
- import { set } from "@dummy";
48
- import { get } from "@dummy";
43
+ import * as React from 'react';
44
+ import { View, StyleSheet, Text } from 'react-native';
45
+ import { useState, useRef } from 'react';
46
+ import RenderBlock from '../components/render-block';
49
47
  function FormComponent(props) {
50
- var _a, _b;
51
- const [state, setState] = useState(() => "unsubmitted");
52
- const [responseData, setResponseData] = useState(() => null);
53
- const [formErrorMessage, setFormErrorMessage] = useState(() => "");
54
- function submissionState() {
55
- return Builder.isEditing && props.previewState || state;
56
- }
57
- function onSubmit(event) {
58
- var _a2;
59
- const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === "email";
60
- if (props.sendSubmissionsTo === "zapier") {
61
- event.preventDefault();
62
- } else if (sendWithJs) {
63
- if (!(props.action || props.sendSubmissionsTo === "email")) {
48
+ var _a, _b;
49
+ const [state, setState] = useState(() => 'unsubmitted');
50
+ const [responseData, setResponseData] = useState(() => null);
51
+ const [formErrorMessage, setFormErrorMessage] = useState(() => '');
52
+ function submissionState() {
53
+ return (Builder.isEditing && props.previewState) || state;
54
+ }
55
+ function onSubmit(event) {
56
+ var _a2;
57
+ const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === 'email';
58
+ if (props.sendSubmissionsTo === 'zapier') {
64
59
  event.preventDefault();
65
- return;
66
- }
67
- event.preventDefault();
68
- const el = event.currentTarget;
69
- const headers = props.customHeaders || {};
70
- let body;
71
- const formData = new FormData(el);
72
- const formPairs = Array.from(event.currentTarget.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).map((el2) => {
73
- let value;
74
- const key = el2.name;
75
- if (el2 instanceof HTMLInputElement) {
76
- if (el2.type === "radio") {
77
- if (el2.checked) {
78
- value = el2.name;
79
- return {
80
- key,
81
- value
82
- };
83
- }
84
- } else if (el2.type === "checkbox") {
85
- value = el2.checked;
86
- } else if (el2.type === "number" || el2.type === "range") {
87
- const num = el2.valueAsNumber;
88
- if (!isNaN(num)) {
89
- value = num;
90
- }
91
- } else if (el2.type === "file") {
92
- value = el2.files;
93
- } else {
94
- value = el2.value;
95
- }
96
- } else {
97
- value = el2.value;
60
+ } else if (sendWithJs) {
61
+ if (!(props.action || props.sendSubmissionsTo === 'email')) {
62
+ event.preventDefault();
63
+ return;
98
64
  }
99
- return {
100
- key,
101
- value
102
- };
103
- });
104
- let contentType = props.contentType;
105
- if (props.sendSubmissionsTo === "email") {
106
- contentType = "multipart/form-data";
107
- }
108
- Array.from(formPairs).forEach(({ value }) => {
109
- if (value instanceof File || Array.isArray(value) && value[0] instanceof File || value instanceof FileList) {
110
- contentType = "multipart/form-data";
65
+ event.preventDefault();
66
+ const el = event.currentTarget;
67
+ const headers = props.customHeaders || {};
68
+ let body;
69
+ const formData = new FormData(el);
70
+ const formPairs = Array.from(event.currentTarget.querySelectorAll('input,select,textarea'))
71
+ .filter(el2 => !!el2.name)
72
+ .map(el2 => {
73
+ let value;
74
+ const key = el2.name;
75
+ if (el2 instanceof HTMLInputElement) {
76
+ if (el2.type === 'radio') {
77
+ if (el2.checked) {
78
+ value = el2.name;
79
+ return {
80
+ key,
81
+ value,
82
+ };
83
+ }
84
+ } else if (el2.type === 'checkbox') {
85
+ value = el2.checked;
86
+ } else if (el2.type === 'number' || el2.type === 'range') {
87
+ const num = el2.valueAsNumber;
88
+ if (!isNaN(num)) {
89
+ value = num;
90
+ }
91
+ } else if (el2.type === 'file') {
92
+ value = el2.files;
93
+ } else {
94
+ value = el2.value;
95
+ }
96
+ } else {
97
+ value = el2.value;
98
+ }
99
+ return {
100
+ key,
101
+ value,
102
+ };
103
+ });
104
+ let contentType = props.contentType;
105
+ if (props.sendSubmissionsTo === 'email') {
106
+ contentType = 'multipart/form-data';
111
107
  }
112
- });
113
- if (contentType !== "application/json") {
114
- body = formData;
115
- } else {
116
- const json = {};
117
- Array.from(formPairs).forEach(({ value, key }) => {
118
- set(json, key, value);
108
+ Array.from(formPairs).forEach(({ value }) => {
109
+ if (
110
+ value instanceof File ||
111
+ (Array.isArray(value) && value[0] instanceof File) ||
112
+ value instanceof FileList
113
+ ) {
114
+ contentType = 'multipart/form-data';
115
+ }
119
116
  });
120
- body = JSON.stringify(json);
121
- }
122
- if (contentType && contentType !== "multipart/form-data") {
123
- if (!(sendWithJs && ((_a2 = props.action) == null ? void 0 : _a2.includes("zapier.com")))) {
124
- headers["content-type"] = contentType;
125
- }
126
- }
127
- const presubmitEvent = new CustomEvent("presubmit", { detail: { body } });
128
- if (formRef.current) {
129
- formRef.current.dispatchEvent(presubmitEvent);
130
- if (presubmitEvent.defaultPrevented) {
131
- return;
132
- }
133
- }
134
- setState("sending");
135
- const formUrl = `${builder.env === "dev" ? "http://localhost:5000" : "https://builder.io"}/api/v1/form-submit?apiKey=${builder.apiKey}&to=${btoa(props.sendSubmissionsToEmail || "")}&name=${encodeURIComponent(props.name || "")}`;
136
- fetch(props.sendSubmissionsTo === "email" ? formUrl : props.action, { body, headers, method: props.method || "post" }).then((res) => __async(this, null, function* () {
137
- let body2;
138
- const contentType2 = res.headers.get("content-type");
139
- if (contentType2 && contentType2.indexOf("application/json") !== -1) {
140
- body2 = yield res.json();
117
+ if (contentType !== 'application/json') {
118
+ body = formData;
141
119
  } else {
142
- body2 = yield res.text();
120
+ const json = {};
121
+ Array.from(formPairs).forEach(({ value, key }) => {
122
+ set(json, key, value);
123
+ });
124
+ body = JSON.stringify(json);
143
125
  }
144
- if (!res.ok && props.errorMessagePath) {
145
- let message = get(body2, props.errorMessagePath);
146
- if (message) {
147
- if (typeof message !== "string") {
148
- message = JSON.stringify(message);
149
- }
150
- setFormErrorMessage(message);
126
+ if (contentType && contentType !== 'multipart/form-data') {
127
+ if (!(sendWithJs && ((_a2 = props.action) == null ? void 0 : _a2.includes('zapier.com')))) {
128
+ headers['content-type'] = contentType;
151
129
  }
152
130
  }
153
- setResponseData(body2);
154
- setState(res.ok ? "success" : "error");
155
- if (res.ok) {
156
- const submitSuccessEvent = new CustomEvent("submit:success", {
157
- detail: { res, body: body2 }
158
- });
159
- if (formRef.current) {
160
- formRef.current.dispatchEvent(submitSuccessEvent);
161
- if (submitSuccessEvent.defaultPrevented) {
162
- return;
163
- }
164
- if (props.resetFormOnSubmit !== false) {
165
- formRef.current.reset();
166
- }
131
+ const presubmitEvent = new CustomEvent('presubmit', { detail: { body } });
132
+ if (formRef.current) {
133
+ formRef.current.dispatchEvent(presubmitEvent);
134
+ if (presubmitEvent.defaultPrevented) {
135
+ return;
167
136
  }
168
- if (props.successUrl) {
137
+ }
138
+ setState('sending');
139
+ const formUrl = `${
140
+ builder.env === 'dev' ? 'http://localhost:5000' : 'https://builder.io'
141
+ }/api/v1/form-submit?apiKey=${builder.apiKey}&to=${btoa(
142
+ props.sendSubmissionsToEmail || ''
143
+ )}&name=${encodeURIComponent(props.name || '')}`;
144
+ fetch(props.sendSubmissionsTo === 'email' ? formUrl : props.action, {
145
+ body,
146
+ headers,
147
+ method: props.method || 'post',
148
+ }).then(
149
+ res =>
150
+ __async(this, null, function* () {
151
+ let body2;
152
+ const contentType2 = res.headers.get('content-type');
153
+ if (contentType2 && contentType2.indexOf('application/json') !== -1) {
154
+ body2 = yield res.json();
155
+ } else {
156
+ body2 = yield res.text();
157
+ }
158
+ if (!res.ok && props.errorMessagePath) {
159
+ let message = get(body2, props.errorMessagePath);
160
+ if (message) {
161
+ if (typeof message !== 'string') {
162
+ message = JSON.stringify(message);
163
+ }
164
+ setFormErrorMessage(message);
165
+ }
166
+ }
167
+ setResponseData(body2);
168
+ setState(res.ok ? 'success' : 'error');
169
+ if (res.ok) {
170
+ const submitSuccessEvent = new CustomEvent('submit:success', {
171
+ detail: { res, body: body2 },
172
+ });
173
+ if (formRef.current) {
174
+ formRef.current.dispatchEvent(submitSuccessEvent);
175
+ if (submitSuccessEvent.defaultPrevented) {
176
+ return;
177
+ }
178
+ if (props.resetFormOnSubmit !== false) {
179
+ formRef.current.reset();
180
+ }
181
+ }
182
+ if (props.successUrl) {
183
+ if (formRef.current) {
184
+ const event2 = new CustomEvent('route', {
185
+ detail: { url: props.successUrl },
186
+ });
187
+ formRef.current.dispatchEvent(event2);
188
+ if (!event2.defaultPrevented) {
189
+ location.href = props.successUrl;
190
+ }
191
+ } else {
192
+ location.href = props.successUrl;
193
+ }
194
+ }
195
+ }
196
+ }),
197
+ err => {
198
+ const submitErrorEvent = new CustomEvent('submit:error', {
199
+ detail: { error: err },
200
+ });
169
201
  if (formRef.current) {
170
- const event2 = new CustomEvent("route", {
171
- detail: { url: props.successUrl }
172
- });
173
- formRef.current.dispatchEvent(event2);
174
- if (!event2.defaultPrevented) {
175
- location.href = props.successUrl;
202
+ formRef.current.dispatchEvent(submitErrorEvent);
203
+ if (submitErrorEvent.defaultPrevented) {
204
+ return;
176
205
  }
177
- } else {
178
- location.href = props.successUrl;
179
206
  }
207
+ setResponseData(err);
208
+ setState('error');
180
209
  }
181
- }
182
- }), (err) => {
183
- const submitErrorEvent = new CustomEvent("submit:error", {
184
- detail: { error: err }
185
- });
186
- if (formRef.current) {
187
- formRef.current.dispatchEvent(submitErrorEvent);
188
- if (submitErrorEvent.defaultPrevented) {
189
- return;
190
- }
191
- }
192
- setResponseData(err);
193
- setState("error");
194
- });
210
+ );
211
+ }
195
212
  }
196
- }
197
- const formRef = useRef();
198
- return /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
199
- validate: props.validate,
200
- ref: formRef,
201
- action: !props.sendWithJs && props.action,
202
- method: props.method,
203
- name: props.name,
204
- onSubmit: (event) => onSubmit(event)
205
- }), " ", props.builderBlock && props.builderBlock.children && /* @__PURE__ */ React.createElement(React.Fragment, null, (_b = (_a = props.builderBlock) == null ? void 0 : _a.children) == null ? void 0 : _b.map((block) => /* @__PURE__ */ React.createElement(BuilderBlockComponent, {
206
- block
207
- }))), " ", submissionState() === "error" && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
208
- dataPath: "errorMessage",
209
- blocks: props.errorMessage
210
- })), " ", submissionState() === "sending" && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
211
- dataPath: "sendingMessage",
212
- blocks: props.sendingMessage
213
- })), " ", submissionState() === "error" && responseData && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
214
- className: "builder-form-error-text",
215
- style: styles.view1
216
- }, " ", /* @__PURE__ */ React.createElement(Text, null, JSON.stringify(responseData, null, 2)), " ")), " ", submissionState() === "success" && /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
217
- dataPath: "successMessage",
218
- blocks: props.successMessage
219
- })), " ");
213
+ const formRef = useRef();
214
+ return /* @__PURE__ */ React.createElement(
215
+ View,
216
+ __spreadProps(__spreadValues({}, props.attributes), {
217
+ validate: props.validate,
218
+ ref: formRef,
219
+ action: !props.sendWithJs && props.action,
220
+ method: props.method,
221
+ name: props.name,
222
+ onSubmit: event => onSubmit(event),
223
+ }),
224
+ ' ',
225
+ props.builderBlock && props.builderBlock.children
226
+ ? /* @__PURE__ */ React.createElement(
227
+ React.Fragment,
228
+ null,
229
+ (_b = (_a = props.builderBlock) == null ? void 0 : _a.children) == null
230
+ ? void 0
231
+ : _b.map(block =>
232
+ /* @__PURE__ */ React.createElement(RenderBlock, {
233
+ block,
234
+ })
235
+ )
236
+ )
237
+ : null,
238
+ ' ',
239
+ submissionState() === 'error'
240
+ ? /* @__PURE__ */ React.createElement(
241
+ React.Fragment,
242
+ null,
243
+ /* @__PURE__ */ React.createElement(BuilderBlocks, {
244
+ dataPath: 'errorMessage',
245
+ blocks: props.errorMessage,
246
+ })
247
+ )
248
+ : null,
249
+ ' ',
250
+ submissionState() === 'sending'
251
+ ? /* @__PURE__ */ React.createElement(
252
+ React.Fragment,
253
+ null,
254
+ /* @__PURE__ */ React.createElement(BuilderBlocks, {
255
+ dataPath: 'sendingMessage',
256
+ blocks: props.sendingMessage,
257
+ })
258
+ )
259
+ : null,
260
+ ' ',
261
+ submissionState() === 'error' && responseData
262
+ ? /* @__PURE__ */ React.createElement(
263
+ React.Fragment,
264
+ null,
265
+ /* @__PURE__ */ React.createElement(
266
+ View,
267
+ {
268
+ className: 'builder-form-error-text',
269
+ style: styles.view1,
270
+ },
271
+ ' ',
272
+ /* @__PURE__ */ React.createElement(Text, null, JSON.stringify(responseData, null, 2)),
273
+ ' '
274
+ )
275
+ )
276
+ : null,
277
+ ' ',
278
+ submissionState() === 'success'
279
+ ? /* @__PURE__ */ React.createElement(
280
+ React.Fragment,
281
+ null,
282
+ /* @__PURE__ */ React.createElement(BuilderBlocks, {
283
+ dataPath: 'successMessage',
284
+ blocks: props.successMessage,
285
+ })
286
+ )
287
+ : null,
288
+ ' '
289
+ );
220
290
  }
221
291
  const styles = StyleSheet.create({
222
- view1: { padding: 10, color: "red", textAlign: "center" }
292
+ view1: { padding: 10, color: 'red', textAlign: 'center' },
223
293
  });
224
- export {
225
- FormComponent as default
226
- };
227
-
294
+ export { FormComponent as default };
228
295
 
229
- registerComponent(FormComponent, {name:'Form:Form',defaults:{responsiveStyles:{large:{marginTop:'15px',paddingBottom:'15px'}}},image:'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fef36d2a846134910b64b88e6d18c5ca5',inputs:[{name:'sendSubmissionsTo',type:'string',enum:[{label:'Send to email',value:'email',helperText:'Send form submissions to the email address of your choosing'},{label:'Custom',value:'custom',helperText:'Handle where the form requests go manually with a little code, e.g. to your own custom backend'}],defaultValue:'email'},{name:'sendSubmissionsToEmail',type:'string',required:true,defaultValue:'your@email.com',showIf:'options.get("sendSubmissionsTo") === "email"'},{name:'sendWithJs',type:'boolean',helperText:'Set to false to use basic html form action',defaultValue:true,showIf:'options.get("sendSubmissionsTo") === "custom"'},{name:'name',type:'string',defaultValue:'My form'},{name:'action',type:'string',helperText:'URL to send the form data to',showIf:'options.get("sendSubmissionsTo") === "custom"'},{name:'contentType',type:'string',defaultValue:'application/json',advanced:true,enum:['application/json','multipart/form-data','application/x-www-form-urlencoded'],showIf:'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'},{name:'method',type:'string',showIf:'options.get("sendSubmissionsTo") === "custom"',defaultValue:'POST',advanced:true},{name:'previewState',type:'string',enum:['unsubmitted','sending','success','error'],defaultValue:'unsubmitted',helperText:'Choose a state to edit, e.g. choose "success" to show what users see on success and edit the message',showIf:'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'},{name:'successUrl',type:'url',helperText:'Optional URL to redirect the user to on form submission success',showIf:'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'},{name:'resetFormOnSubmit',type:'boolean',showIf:"options.get('sendSubmissionsTo') === 'custom' && options.get('sendWithJs') === true",advanced:true},{name:'successMessage',type:'uiBlocks',hideFromUI:true,defaultValue:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},component:{name:'Text',options:{text:'<span>Thanks!</span>'}}}]},{name:'validate',type:'boolean',defaultValue:true,advanced:true},{name:'errorMessagePath',type:'text',advanced:true,helperText:'Path to where to get the error message from in a JSON response to display to the user, e.g. "error.message" for a response like { "error": { "message": "this username is taken" }}'},{name:'errorMessage',type:'uiBlocks',hideFromUI:true,defaultValue:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},bindings:{'component.options.text':'state.formErrorMessage || block.component.options.text'},component:{name:'Text',options:{text:'<span>Form submission error :( Please check your answers and try again</span>'}}}]},{name:'sendingMessage',type:'uiBlocks',hideFromUI:true,defaultValue:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},component:{name:'Text',options:{text:'<span>Sending...</span>'}}}]},{name:'customHeaders',type:'map',valueType:{type:'string'},advanced:true,showIf:'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'}],noWrap:true,canHaveChildren:true,defaultChildren:[{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},component:{name:'Text',options:{text:'<span>Enter your name</span>'}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},component:{name:'Form:Input',options:{name:'name',placeholder:'Jane Doe'}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},component:{name:'Text',options:{text:'<span>Enter your email</span>'}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},component:{name:'Form:Input',options:{name:'email',placeholder:'jane@doe.com'}}},{'@type':'@builder.io/sdk:Element',responsiveStyles:{large:{marginTop:'10px'}},component:{name:'Form:SubmitButton',options:{text:'Submit'}}}]});
296
+ registerComponent(FormComponent, {
297
+ name: 'Form:Form',
298
+ builtIn: true,
299
+ defaults: { responsiveStyles: { large: { marginTop: '15px', paddingBottom: '15px' } } },
300
+ image:
301
+ 'https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fef36d2a846134910b64b88e6d18c5ca5',
302
+ inputs: [
303
+ {
304
+ name: 'sendSubmissionsTo',
305
+ type: 'string',
306
+ enum: [
307
+ {
308
+ label: 'Send to email',
309
+ value: 'email',
310
+ helperText: 'Send form submissions to the email address of your choosing',
311
+ },
312
+ {
313
+ label: 'Custom',
314
+ value: 'custom',
315
+ helperText:
316
+ 'Handle where the form requests go manually with a little code, e.g. to your own custom backend',
317
+ },
318
+ ],
319
+ defaultValue: 'email',
320
+ },
321
+ {
322
+ name: 'sendSubmissionsToEmail',
323
+ type: 'string',
324
+ required: true,
325
+ defaultValue: 'your@email.com',
326
+ showIf: 'options.get("sendSubmissionsTo") === "email"',
327
+ },
328
+ {
329
+ name: 'sendWithJs',
330
+ type: 'boolean',
331
+ helperText: 'Set to false to use basic html form action',
332
+ defaultValue: true,
333
+ showIf: 'options.get("sendSubmissionsTo") === "custom"',
334
+ },
335
+ { name: 'name', type: 'string', defaultValue: 'My form' },
336
+ {
337
+ name: 'action',
338
+ type: 'string',
339
+ helperText: 'URL to send the form data to',
340
+ showIf: 'options.get("sendSubmissionsTo") === "custom"',
341
+ },
342
+ {
343
+ name: 'contentType',
344
+ type: 'string',
345
+ defaultValue: 'application/json',
346
+ advanced: true,
347
+ enum: ['application/json', 'multipart/form-data', 'application/x-www-form-urlencoded'],
348
+ showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true',
349
+ },
350
+ {
351
+ name: 'method',
352
+ type: 'string',
353
+ showIf: 'options.get("sendSubmissionsTo") === "custom"',
354
+ defaultValue: 'POST',
355
+ advanced: true,
356
+ },
357
+ {
358
+ name: 'previewState',
359
+ type: 'string',
360
+ enum: ['unsubmitted', 'sending', 'success', 'error'],
361
+ defaultValue: 'unsubmitted',
362
+ helperText:
363
+ 'Choose a state to edit, e.g. choose "success" to show what users see on success and edit the message',
364
+ showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true',
365
+ },
366
+ {
367
+ name: 'successUrl',
368
+ type: 'url',
369
+ helperText: 'Optional URL to redirect the user to on form submission success',
370
+ showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true',
371
+ },
372
+ {
373
+ name: 'resetFormOnSubmit',
374
+ type: 'boolean',
375
+ showIf: "options.get('sendSubmissionsTo') === 'custom' && options.get('sendWithJs') === true",
376
+ advanced: true,
377
+ },
378
+ {
379
+ name: 'successMessage',
380
+ type: 'uiBlocks',
381
+ hideFromUI: true,
382
+ defaultValue: [
383
+ {
384
+ '@type': '@builder.io/sdk:Element',
385
+ responsiveStyles: { large: { marginTop: '10px' } },
386
+ component: { name: 'Text', options: { text: '<span>Thanks!</span>' } },
387
+ },
388
+ ],
389
+ },
390
+ { name: 'validate', type: 'boolean', defaultValue: true, advanced: true },
391
+ {
392
+ name: 'errorMessagePath',
393
+ type: 'text',
394
+ advanced: true,
395
+ helperText:
396
+ 'Path to where to get the error message from in a JSON response to display to the user, e.g. "error.message" for a response like { "error": { "message": "this username is taken" }}',
397
+ },
398
+ {
399
+ name: 'errorMessage',
400
+ type: 'uiBlocks',
401
+ hideFromUI: true,
402
+ defaultValue: [
403
+ {
404
+ '@type': '@builder.io/sdk:Element',
405
+ responsiveStyles: { large: { marginTop: '10px' } },
406
+ bindings: {
407
+ 'component.options.text': 'state.formErrorMessage || block.component.options.text',
408
+ },
409
+ component: {
410
+ name: 'Text',
411
+ options: {
412
+ text: '<span>Form submission error :( Please check your answers and try again</span>',
413
+ },
414
+ },
415
+ },
416
+ ],
417
+ },
418
+ {
419
+ name: 'sendingMessage',
420
+ type: 'uiBlocks',
421
+ hideFromUI: true,
422
+ defaultValue: [
423
+ {
424
+ '@type': '@builder.io/sdk:Element',
425
+ responsiveStyles: { large: { marginTop: '10px' } },
426
+ component: { name: 'Text', options: { text: '<span>Sending...</span>' } },
427
+ },
428
+ ],
429
+ },
430
+ {
431
+ name: 'customHeaders',
432
+ type: 'map',
433
+ valueType: { type: 'string' },
434
+ advanced: true,
435
+ showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true',
436
+ },
437
+ ],
438
+ noWrap: true,
439
+ canHaveChildren: true,
440
+ defaultChildren: [
441
+ {
442
+ '@type': '@builder.io/sdk:Element',
443
+ responsiveStyles: { large: { marginTop: '10px' } },
444
+ component: { name: 'Text', options: { text: '<span>Enter your name</span>' } },
445
+ },
446
+ {
447
+ '@type': '@builder.io/sdk:Element',
448
+ responsiveStyles: { large: { marginTop: '10px' } },
449
+ component: { name: 'Form:Input', options: { name: 'name', placeholder: 'Jane Doe' } },
450
+ },
451
+ {
452
+ '@type': '@builder.io/sdk:Element',
453
+ responsiveStyles: { large: { marginTop: '10px' } },
454
+ component: { name: 'Text', options: { text: '<span>Enter your email</span>' } },
455
+ },
456
+ {
457
+ '@type': '@builder.io/sdk:Element',
458
+ responsiveStyles: { large: { marginTop: '10px' } },
459
+ component: { name: 'Form:Input', options: { name: 'email', placeholder: 'jane@doe.com' } },
460
+ },
461
+ {
462
+ '@type': '@builder.io/sdk:Element',
463
+ responsiveStyles: { large: { marginTop: '10px' } },
464
+ component: { name: 'Form:SubmitButton', options: { text: 'Submit' } },
465
+ },
466
+ ],
467
+ });