@builder.io/sdk-react-native 0.0.1-25 → 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.
- package/package.json +3 -2
- package/src/blocks/button.js +66 -22
- package/src/blocks/button.lite.tsx +4 -4
- package/src/blocks/columns.js +247 -36
- package/src/blocks/columns.lite.tsx +7 -7
- package/src/blocks/custom-code.js +73 -47
- package/src/blocks/custom-code.lite.tsx +12 -16
- package/src/blocks/embed.js +66 -47
- package/src/blocks/embed.lite.tsx +11 -13
- package/src/blocks/form.js +436 -195
- package/src/blocks/form.lite.tsx +65 -72
- package/src/blocks/fragment.js +16 -8
- package/src/blocks/fragment.lite.tsx +3 -3
- package/src/blocks/image.js +88 -80
- package/src/blocks/image.lite.tsx +14 -15
- package/src/blocks/img.js +45 -28
- package/src/blocks/img.lite.tsx +7 -7
- package/src/blocks/input.js +93 -28
- package/src/blocks/input.lite.tsx +5 -7
- package/src/blocks/raw-text.js +16 -12
- package/src/blocks/raw-text.lite.tsx +3 -3
- package/src/blocks/section.js +66 -23
- package/src/blocks/section.lite.tsx +4 -4
- package/src/blocks/select.js +67 -28
- package/src/blocks/select.lite.tsx +6 -8
- package/src/blocks/submit-button.js +41 -21
- package/src/blocks/submit-button.lite.tsx +3 -3
- package/src/blocks/symbol.js +18 -16
- package/src/blocks/symbol.lite.tsx +5 -5
- package/src/blocks/text.js +29 -27
- package/src/blocks/text.lite.tsx +4 -9
- package/src/blocks/textarea.js +53 -24
- package/src/blocks/textarea.lite.tsx +3 -3
- package/src/blocks/video.js +112 -46
- package/src/blocks/video.lite.tsx +6 -6
- package/src/components/block-styles.js +2 -4
- package/src/components/block-styles.lite.tsx +3 -3
- package/src/components/error-boundary.js +11 -9
- package/src/components/error-boundary.lite.tsx +3 -3
- package/src/components/render-block.js +85 -40
- package/src/components/render-block.lite.tsx +17 -25
- package/src/components/render-blocks.js +56 -32
- package/src/components/render-blocks.lite.tsx +14 -14
- package/src/components/render-content.js +100 -52
- package/src/components/render-content.lite.tsx +32 -41
- package/src/constants/device-sizes.js +8 -11
- package/src/context/builder.context.js +2 -4
- package/src/functions/evaluate.js +17 -9
- package/src/functions/get-block-actions.js +9 -10
- package/src/functions/get-block-component-options.js +11 -10
- package/src/functions/get-block-properties.js +15 -17
- package/src/functions/get-block-styles.js +19 -16
- package/src/functions/get-block-tag.js +2 -4
- package/src/functions/get-content.js +40 -29
- package/src/functions/get-fetch.js +5 -7
- package/src/functions/get-global-this.js +5 -7
- package/src/functions/get-processed-block.js +11 -13
- package/src/functions/get-processed-block.test.js +14 -14
- package/src/functions/get-target.js +2 -4
- package/src/functions/if-target.js +1 -3
- package/src/functions/is-browser.js +3 -5
- package/src/functions/is-editing.js +3 -5
- package/src/functions/is-iframe.js +2 -4
- package/src/functions/is-previewing.js +4 -6
- package/src/functions/is-react-native.js +2 -4
- package/src/functions/macro-eval.js +2 -5
- package/src/functions/on-change.js +4 -7
- package/src/functions/on-change.test.js +10 -10
- package/src/functions/previewing-model-name.js +3 -5
- package/src/functions/register-component.js +33 -28
- package/src/functions/register.js +8 -10
- package/src/functions/set-editor-settings.js +5 -7
- package/src/functions/set.js +10 -4
- package/src/functions/set.test.js +14 -14
- package/src/functions/track.js +6 -8
- package/src/index.js +20 -18
- package/src/scripts/init-editing.js +64 -40
|
@@ -1,56 +1,82 @@
|
|
|
1
1
|
import { registerComponent } from '../functions/register-component';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import { View } from
|
|
5
|
-
import { useState, useRef, useEffect } from
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import { View, StyleSheet, Image, Text } from
|
|
3
|
-
import { useState, useContext, useRef, useEffect } from
|
|
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 !==
|
|
12
|
+
if (elem.current && typeof window !== 'undefined') {
|
|
13
13
|
/** @type {HTMLScriptElement[]} */
|
|
14
|
-
const scripts = elem.current.getElementsByTagName(
|
|
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(
|
|
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
|
-
|
|
33
|
-
|
|
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(
|
|
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
|
-
|
|
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
|
}
|
package/src/blocks/embed.js
CHANGED
|
@@ -1,56 +1,75 @@
|
|
|
1
1
|
import { registerComponent } from '../functions/register-component';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
import { View } from
|
|
5
|
-
import { useState, useRef, useEffect } from
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
2
|
-
import { View, StyleSheet, Image, Text } from
|
|
3
|
-
import { useState, useContext, useRef, useEffect } from
|
|
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 !==
|
|
12
|
+
if (elem.current && typeof window !== 'undefined') {
|
|
13
13
|
/** @type {HTMLScriptElement[]} */
|
|
14
|
-
const scripts = elem.current.getElementsByTagName(
|
|
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(
|
|
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
|
-
|
|
33
|
-
|
|
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(
|
|
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:
|
|
60
|
+
dangerouslySetInnerHTML={{ __html: 'props.content' }}
|
|
63
61
|
/>
|
|
64
62
|
);
|
|
65
63
|
}
|
package/src/blocks/form.js
CHANGED
|
@@ -1,226 +1,467 @@
|
|
|
1
1
|
import { registerComponent } from '../functions/register-component';
|
|
2
2
|
|
|
3
|
-
|
|
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) =>
|
|
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 (
|
|
13
|
-
|
|
14
|
-
if (
|
|
15
|
-
|
|
16
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
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
|
|
43
|
-
import { View, StyleSheet, Text } from
|
|
44
|
-
import { useState, useRef } from
|
|
45
|
-
import RenderBlock from
|
|
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';
|
|
46
47
|
function FormComponent(props) {
|
|
47
|
-
var _a, _b;
|
|
48
|
-
const [state, setState] = useState(() =>
|
|
49
|
-
const [responseData, setResponseData] = useState(() => null);
|
|
50
|
-
const [formErrorMessage, setFormErrorMessage] = useState(() =>
|
|
51
|
-
function submissionState() {
|
|
52
|
-
|
|
53
|
-
}
|
|
54
|
-
function onSubmit(event) {
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
event.preventDefault();
|
|
59
|
-
} else if (sendWithJs) {
|
|
60
|
-
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') {
|
|
61
59
|
event.preventDefault();
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
const headers = props.customHeaders || {};
|
|
67
|
-
let body;
|
|
68
|
-
const formData = new FormData(el);
|
|
69
|
-
const formPairs = Array.from(event.currentTarget.querySelectorAll("input,select,textarea")).filter((el2) => !!el2.name).map((el2) => {
|
|
70
|
-
let value;
|
|
71
|
-
const key = el2.name;
|
|
72
|
-
if (el2 instanceof HTMLInputElement) {
|
|
73
|
-
if (el2.type === "radio") {
|
|
74
|
-
if (el2.checked) {
|
|
75
|
-
value = el2.name;
|
|
76
|
-
return {
|
|
77
|
-
key,
|
|
78
|
-
value
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
} else if (el2.type === "checkbox") {
|
|
82
|
-
value = el2.checked;
|
|
83
|
-
} else if (el2.type === "number" || el2.type === "range") {
|
|
84
|
-
const num = el2.valueAsNumber;
|
|
85
|
-
if (!isNaN(num)) {
|
|
86
|
-
value = num;
|
|
87
|
-
}
|
|
88
|
-
} else if (el2.type === "file") {
|
|
89
|
-
value = el2.files;
|
|
90
|
-
} else {
|
|
91
|
-
value = el2.value;
|
|
92
|
-
}
|
|
93
|
-
} else {
|
|
94
|
-
value = el2.value;
|
|
60
|
+
} else if (sendWithJs) {
|
|
61
|
+
if (!(props.action || props.sendSubmissionsTo === 'email')) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
return;
|
|
95
64
|
}
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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';
|
|
108
107
|
}
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
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
|
+
}
|
|
116
116
|
});
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
if (contentType && contentType !== "multipart/form-data") {
|
|
120
|
-
if (!(sendWithJs && ((_a2 = props.action) == null ? void 0 : _a2.includes("zapier.com")))) {
|
|
121
|
-
headers["content-type"] = contentType;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
const presubmitEvent = new CustomEvent("presubmit", { detail: { body } });
|
|
125
|
-
if (formRef.current) {
|
|
126
|
-
formRef.current.dispatchEvent(presubmitEvent);
|
|
127
|
-
if (presubmitEvent.defaultPrevented) {
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
}
|
|
131
|
-
setState("sending");
|
|
132
|
-
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 || "")}`;
|
|
133
|
-
fetch(props.sendSubmissionsTo === "email" ? formUrl : props.action, { body, headers, method: props.method || "post" }).then((res) => __async(this, null, function* () {
|
|
134
|
-
let body2;
|
|
135
|
-
const contentType2 = res.headers.get("content-type");
|
|
136
|
-
if (contentType2 && contentType2.indexOf("application/json") !== -1) {
|
|
137
|
-
body2 = yield res.json();
|
|
117
|
+
if (contentType !== 'application/json') {
|
|
118
|
+
body = formData;
|
|
138
119
|
} else {
|
|
139
|
-
|
|
120
|
+
const json = {};
|
|
121
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
122
|
+
set(json, key, value);
|
|
123
|
+
});
|
|
124
|
+
body = JSON.stringify(json);
|
|
140
125
|
}
|
|
141
|
-
if (
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (typeof message !== "string") {
|
|
145
|
-
message = JSON.stringify(message);
|
|
146
|
-
}
|
|
147
|
-
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;
|
|
148
129
|
}
|
|
149
130
|
}
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
});
|
|
156
|
-
if (formRef.current) {
|
|
157
|
-
formRef.current.dispatchEvent(submitSuccessEvent);
|
|
158
|
-
if (submitSuccessEvent.defaultPrevented) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
if (props.resetFormOnSubmit !== false) {
|
|
162
|
-
formRef.current.reset();
|
|
163
|
-
}
|
|
131
|
+
const presubmitEvent = new CustomEvent('presubmit', { detail: { body } });
|
|
132
|
+
if (formRef.current) {
|
|
133
|
+
formRef.current.dispatchEvent(presubmitEvent);
|
|
134
|
+
if (presubmitEvent.defaultPrevented) {
|
|
135
|
+
return;
|
|
164
136
|
}
|
|
165
|
-
|
|
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
|
+
});
|
|
166
201
|
if (formRef.current) {
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
formRef.current.dispatchEvent(event2);
|
|
171
|
-
if (!event2.defaultPrevented) {
|
|
172
|
-
location.href = props.successUrl;
|
|
202
|
+
formRef.current.dispatchEvent(submitErrorEvent);
|
|
203
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
204
|
+
return;
|
|
173
205
|
}
|
|
174
|
-
} else {
|
|
175
|
-
location.href = props.successUrl;
|
|
176
206
|
}
|
|
207
|
+
setResponseData(err);
|
|
208
|
+
setState('error');
|
|
177
209
|
}
|
|
178
|
-
|
|
179
|
-
}
|
|
180
|
-
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
181
|
-
detail: { error: err }
|
|
182
|
-
});
|
|
183
|
-
if (formRef.current) {
|
|
184
|
-
formRef.current.dispatchEvent(submitErrorEvent);
|
|
185
|
-
if (submitErrorEvent.defaultPrevented) {
|
|
186
|
-
return;
|
|
187
|
-
}
|
|
188
|
-
}
|
|
189
|
-
setResponseData(err);
|
|
190
|
-
setState("error");
|
|
191
|
-
});
|
|
210
|
+
);
|
|
211
|
+
}
|
|
192
212
|
}
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
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
|
+
);
|
|
217
290
|
}
|
|
218
291
|
const styles = StyleSheet.create({
|
|
219
|
-
view1: { padding: 10, color:
|
|
292
|
+
view1: { padding: 10, color: 'red', textAlign: 'center' },
|
|
220
293
|
});
|
|
221
|
-
export {
|
|
222
|
-
FormComponent as default
|
|
223
|
-
};
|
|
224
|
-
|
|
294
|
+
export { FormComponent as default };
|
|
225
295
|
|
|
226
|
-
|
|
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
|
+
});
|