@builder.io/sdk-react-native 0.0.1-31 → 0.0.1-35
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 +1 -1
- package/src/blocks/button.js +22 -66
- package/src/blocks/button.lite.tsx +4 -4
- package/src/blocks/columns.js +36 -247
- package/src/blocks/columns.lite.tsx +7 -7
- package/src/blocks/custom-code.js +47 -73
- package/src/blocks/custom-code.lite.tsx +16 -12
- package/src/blocks/embed.js +47 -66
- package/src/blocks/embed.lite.tsx +13 -11
- package/src/blocks/form.js +195 -436
- package/src/blocks/form.lite.tsx +72 -65
- package/src/blocks/fragment.js +8 -16
- package/src/blocks/fragment.lite.tsx +3 -3
- package/src/blocks/image.js +80 -88
- package/src/blocks/image.lite.tsx +16 -17
- package/src/blocks/img.js +28 -45
- package/src/blocks/img.lite.tsx +7 -7
- package/src/blocks/input.js +28 -93
- package/src/blocks/input.lite.tsx +7 -5
- package/src/blocks/raw-text.js +12 -16
- package/src/blocks/raw-text.lite.tsx +3 -3
- package/src/blocks/section.js +23 -66
- package/src/blocks/section.lite.tsx +4 -4
- package/src/blocks/select.js +28 -67
- package/src/blocks/select.lite.tsx +8 -6
- package/src/blocks/submit-button.js +21 -41
- package/src/blocks/submit-button.lite.tsx +3 -3
- package/src/blocks/symbol.js +16 -18
- package/src/blocks/symbol.lite.tsx +5 -5
- package/src/blocks/text.js +27 -29
- package/src/blocks/text.lite.tsx +9 -4
- package/src/blocks/textarea.js +24 -53
- package/src/blocks/textarea.lite.tsx +3 -3
- package/src/blocks/video.js +60 -81
- package/src/blocks/video.lite.tsx +6 -6
- package/src/components/block-styles.js +4 -2
- package/src/components/block-styles.lite.tsx +3 -3
- package/src/components/error-boundary.js +9 -11
- package/src/components/error-boundary.lite.tsx +3 -3
- package/src/components/render-block.js +40 -85
- package/src/components/render-block.lite.tsx +25 -17
- package/src/components/render-blocks.js +32 -56
- package/src/components/render-blocks.lite.tsx +14 -14
- package/src/components/render-content.js +52 -100
- package/src/components/render-content.lite.tsx +41 -32
- package/src/constants/device-sizes.js +11 -8
- package/src/context/builder.context.js +4 -2
- package/src/functions/evaluate.js +9 -17
- package/src/functions/get-block-actions.js +10 -9
- package/src/functions/get-block-component-options.js +10 -11
- package/src/functions/get-block-properties.js +17 -15
- package/src/functions/get-block-styles.js +17 -20
- package/src/functions/get-block-tag.js +4 -2
- package/src/functions/get-content.js +30 -39
- package/src/functions/get-content.test.js +28 -37
- package/src/functions/get-fetch.js +7 -5
- package/src/functions/get-global-this.js +7 -5
- package/src/functions/get-processed-block.js +13 -11
- package/src/functions/get-processed-block.test.js +14 -14
- package/src/functions/get-target.js +4 -2
- package/src/functions/if-target.js +3 -1
- package/src/functions/is-browser.js +5 -3
- package/src/functions/is-editing.js +5 -3
- package/src/functions/is-iframe.js +4 -2
- package/src/functions/is-previewing.js +6 -4
- package/src/functions/is-react-native.js +4 -2
- package/src/functions/macro-eval.js +5 -2
- package/src/functions/on-change.js +7 -4
- package/src/functions/on-change.test.js +10 -10
- package/src/functions/previewing-model-name.js +5 -3
- package/src/functions/register-component.js +28 -33
- package/src/functions/register.js +10 -8
- package/src/functions/set-editor-settings.js +7 -5
- package/src/functions/set.js +4 -10
- package/src/functions/set.test.js +14 -14
- package/src/functions/track.js +8 -6
- package/src/index.js +18 -20
- package/src/scripts/init-editing.js +40 -64
package/src/blocks/form.js
CHANGED
|
@@ -1,467 +1,226 @@
|
|
|
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) =>
|
|
10
|
-
key in obj
|
|
11
|
-
? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value })
|
|
12
|
-
: (obj[key] = value);
|
|
9
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
10
|
var __spreadValues = (a, b) => {
|
|
14
|
-
|
|
15
|
-
if (
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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;
|
|
20
20
|
};
|
|
21
21
|
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
22
22
|
var __async = (__this, __arguments, generator) => {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
});
|
|
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
|
+
});
|
|
42
41
|
};
|
|
43
|
-
import * as React from
|
|
44
|
-
import { View, StyleSheet, Text } from
|
|
45
|
-
import { useState, useRef } from
|
|
46
|
-
import RenderBlock from
|
|
42
|
+
import * as React from "react";
|
|
43
|
+
import { View, StyleSheet, Text } from "react-native";
|
|
44
|
+
import { useState, useRef } from "react";
|
|
45
|
+
import RenderBlock from "../components/render-block";
|
|
47
46
|
function FormComponent(props) {
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
event.preventDefault();
|
|
63
|
-
return;
|
|
64
|
-
}
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const [state, setState] = useState(() => "unsubmitted");
|
|
49
|
+
const [responseData, setResponseData] = useState(() => null);
|
|
50
|
+
const [formErrorMessage, setFormErrorMessage] = useState(() => "");
|
|
51
|
+
function submissionState() {
|
|
52
|
+
return Builder.isEditing && props.previewState || state;
|
|
53
|
+
}
|
|
54
|
+
function onSubmit(event) {
|
|
55
|
+
var _a2;
|
|
56
|
+
const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === "email";
|
|
57
|
+
if (props.sendSubmissionsTo === "zapier") {
|
|
58
|
+
event.preventDefault();
|
|
59
|
+
} else if (sendWithJs) {
|
|
60
|
+
if (!(props.action || props.sendSubmissionsTo === "email")) {
|
|
65
61
|
event.preventDefault();
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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;
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
event.preventDefault();
|
|
65
|
+
const el = event.currentTarget;
|
|
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
|
+
};
|
|
98
80
|
}
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
value instanceof File ||
|
|
111
|
-
(Array.isArray(value) && value[0] instanceof File) ||
|
|
112
|
-
value instanceof FileList
|
|
113
|
-
) {
|
|
114
|
-
contentType = 'multipart/form-data';
|
|
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;
|
|
115
92
|
}
|
|
93
|
+
} else {
|
|
94
|
+
value = el2.value;
|
|
95
|
+
}
|
|
96
|
+
return {
|
|
97
|
+
key,
|
|
98
|
+
value
|
|
99
|
+
};
|
|
100
|
+
});
|
|
101
|
+
let contentType = props.contentType;
|
|
102
|
+
if (props.sendSubmissionsTo === "email") {
|
|
103
|
+
contentType = "multipart/form-data";
|
|
104
|
+
}
|
|
105
|
+
Array.from(formPairs).forEach(({ value }) => {
|
|
106
|
+
if (value instanceof File || Array.isArray(value) && value[0] instanceof File || value instanceof FileList) {
|
|
107
|
+
contentType = "multipart/form-data";
|
|
108
|
+
}
|
|
109
|
+
});
|
|
110
|
+
if (contentType !== "application/json") {
|
|
111
|
+
body = formData;
|
|
112
|
+
} else {
|
|
113
|
+
const json = {};
|
|
114
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
115
|
+
set(json, key, value);
|
|
116
116
|
});
|
|
117
|
-
|
|
118
|
-
|
|
117
|
+
body = JSON.stringify(json);
|
|
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();
|
|
119
138
|
} else {
|
|
120
|
-
|
|
121
|
-
Array.from(formPairs).forEach(({ value, key }) => {
|
|
122
|
-
set(json, key, value);
|
|
123
|
-
});
|
|
124
|
-
body = JSON.stringify(json);
|
|
139
|
+
body2 = yield res.text();
|
|
125
140
|
}
|
|
126
|
-
if (
|
|
127
|
-
|
|
128
|
-
|
|
141
|
+
if (!res.ok && props.errorMessagePath) {
|
|
142
|
+
let message = get(body2, props.errorMessagePath);
|
|
143
|
+
if (message) {
|
|
144
|
+
if (typeof message !== "string") {
|
|
145
|
+
message = JSON.stringify(message);
|
|
146
|
+
}
|
|
147
|
+
setFormErrorMessage(message);
|
|
129
148
|
}
|
|
130
149
|
}
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
150
|
+
setResponseData(body2);
|
|
151
|
+
setState(res.ok ? "success" : "error");
|
|
152
|
+
if (res.ok) {
|
|
153
|
+
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
154
|
+
detail: { res, body: body2 }
|
|
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
|
+
}
|
|
136
164
|
}
|
|
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
|
-
});
|
|
165
|
+
if (props.successUrl) {
|
|
201
166
|
if (formRef.current) {
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
167
|
+
const event2 = new CustomEvent("route", {
|
|
168
|
+
detail: { url: props.successUrl }
|
|
169
|
+
});
|
|
170
|
+
formRef.current.dispatchEvent(event2);
|
|
171
|
+
if (!event2.defaultPrevented) {
|
|
172
|
+
location.href = props.successUrl;
|
|
205
173
|
}
|
|
174
|
+
} else {
|
|
175
|
+
location.href = props.successUrl;
|
|
206
176
|
}
|
|
207
|
-
setResponseData(err);
|
|
208
|
-
setState('error');
|
|
209
177
|
}
|
|
210
|
-
|
|
211
|
-
}
|
|
178
|
+
}
|
|
179
|
+
}), (err) => {
|
|
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
|
+
});
|
|
212
192
|
}
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
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
|
-
);
|
|
193
|
+
}
|
|
194
|
+
const formRef = useRef();
|
|
195
|
+
return /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
|
|
196
|
+
validate: props.validate,
|
|
197
|
+
ref: formRef,
|
|
198
|
+
action: !props.sendWithJs && props.action,
|
|
199
|
+
method: props.method,
|
|
200
|
+
name: props.name,
|
|
201
|
+
onSubmit: (event) => onSubmit(event)
|
|
202
|
+
}), " ", 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(RenderBlock, {
|
|
203
|
+
block
|
|
204
|
+
}))) : null, " ", submissionState() === "error" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
|
|
205
|
+
dataPath: "errorMessage",
|
|
206
|
+
blocks: props.errorMessage
|
|
207
|
+
})) : null, " ", submissionState() === "sending" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
|
|
208
|
+
dataPath: "sendingMessage",
|
|
209
|
+
blocks: props.sendingMessage
|
|
210
|
+
})) : null, " ", submissionState() === "error" && responseData ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
211
|
+
className: "builder-form-error-text",
|
|
212
|
+
style: styles.view1
|
|
213
|
+
}, " ", /* @__PURE__ */ React.createElement(Text, null, JSON.stringify(responseData, null, 2)), " ")) : null, " ", submissionState() === "success" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
|
|
214
|
+
dataPath: "successMessage",
|
|
215
|
+
blocks: props.successMessage
|
|
216
|
+
})) : null, " ");
|
|
290
217
|
}
|
|
291
218
|
const styles = StyleSheet.create({
|
|
292
|
-
|
|
219
|
+
view1: { padding: 10, color: "red", textAlign: "center" }
|
|
293
220
|
});
|
|
294
|
-
export {
|
|
221
|
+
export {
|
|
222
|
+
FormComponent as default
|
|
223
|
+
};
|
|
295
224
|
|
|
296
|
-
|
|
297
|
-
|
|
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
|
-
});
|
|
225
|
+
|
|
226
|
+
registerComponent(FormComponent, {name:'Form:Form',builtIn:true,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'}}}]});
|