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