@builder.io/sdk-react-native 0.0.1-34 → 0.0.1-38
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 +86 -0
- package/src/blocks/button.lite.tsx +25 -0
- package/src/blocks/columns.js +265 -0
- package/src/blocks/columns.lite.tsx +40 -0
- package/src/blocks/custom-code.js +85 -0
- package/src/blocks/custom-code.lite.tsx +67 -0
- package/src/blocks/embed.js +78 -0
- package/src/blocks/embed.lite.tsx +65 -0
- package/src/blocks/form.js +522 -0
- package/src/blocks/form.lite.tsx +253 -0
- package/src/blocks/fragment.js +21 -0
- package/src/blocks/fragment.lite.tsx +10 -0
- package/src/blocks/image.js +129 -0
- package/src/blocks/image.lite.tsx +68 -0
- package/src/blocks/img.js +64 -0
- package/src/blocks/img.lite.tsx +18 -0
- package/src/blocks/input.js +113 -0
- package/src/blocks/input.lite.tsx +20 -0
- package/src/blocks/raw-text.js +21 -0
- package/src/blocks/raw-text.lite.tsx +11 -0
- package/src/blocks/section.js +84 -0
- package/src/blocks/section.lite.tsx +19 -0
- package/src/blocks/select.js +91 -0
- package/src/blocks/select.lite.tsx +23 -0
- package/src/blocks/submit-button.js +60 -0
- package/src/blocks/submit-button.lite.tsx +10 -0
- package/src/blocks/symbol.js +22 -0
- package/src/blocks/symbol.lite.tsx +20 -0
- package/src/blocks/text.js +100 -0
- package/src/blocks/text.lite.tsx +11 -0
- package/src/blocks/textarea.js +73 -0
- package/src/blocks/textarea.lite.tsx +14 -0
- package/src/blocks/video.js +100 -0
- package/src/blocks/video.lite.tsx +27 -0
- 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 +169 -0
- package/src/components/render-block.lite.tsx +129 -0
- package/src/components/render-blocks.js +73 -0
- package/src/components/render-blocks.lite.tsx +59 -0
- package/src/components/render-content.js +215 -0
- package/src/components/render-content.lite.tsx +207 -0
- package/src/constants/device-sizes.js +37 -0
- package/src/context/builder.context.js +3 -0
- package/src/functions/evaluate.js +29 -0
- package/src/functions/event-handler-name.js +6 -0
- package/src/functions/get-block-actions.js +23 -0
- package/src/functions/get-block-component-options.js +31 -0
- package/src/functions/get-block-properties.js +47 -0
- package/src/functions/get-block-styles.js +78 -0
- package/src/functions/get-block-tag.js +6 -0
- package/src/functions/get-content.js +150 -0
- 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 +51 -0
- package/src/functions/get-processed-block.test.js +31 -0
- package/src/functions/get-target.js +5 -0
- package/src/functions/if-target.js +5 -0
- package/src/functions/is-browser.js +10 -0
- package/src/functions/is-editing.js +8 -0
- package/src/functions/is-iframe.js +6 -0
- package/src/functions/is-previewing.js +13 -0
- package/src/functions/is-react-native.js +5 -0
- package/src/functions/macro-eval.js +3 -0
- package/src/functions/on-change.js +25 -0
- package/src/functions/on-change.test.js +21 -0
- package/src/functions/previewing-model-name.js +10 -0
- package/src/functions/register-component.js +65 -0
- package/src/functions/register.js +28 -0
- package/src/functions/set-editor-settings.js +14 -0
- package/src/functions/set.js +21 -0
- package/src/functions/set.test.js +18 -0
- package/src/functions/track.js +17 -0
- package/src/functions/transform-block.js +40 -0
- package/src/index.js +30 -0
- package/src/scripts/init-editing.js +95 -0
- package/src/types/builder-block.js +1 -0
- package/src/types/builder-content.js +1 -0
- package/src/types/deep-partial.js +1 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { View, StyleSheet, Image, Text } from 'react-native';
|
|
3
|
+
import { useState, useRef, useEffect } from 'react';
|
|
4
|
+
|
|
5
|
+
export default function Embed(props) {
|
|
6
|
+
const [scriptsInserted, setScriptsInserted] = useState(() => []);
|
|
7
|
+
|
|
8
|
+
const [scriptsRun, setScriptsRun] = useState(() => []);
|
|
9
|
+
|
|
10
|
+
function findAndRunScripts() {
|
|
11
|
+
// TODO: Move this function to standalone one in '@builder.io/utils'
|
|
12
|
+
if (elem.current && typeof window !== 'undefined') {
|
|
13
|
+
/** @type {HTMLScriptElement[]} */
|
|
14
|
+
const scripts = elem.current.getElementsByTagName('script');
|
|
15
|
+
|
|
16
|
+
for (let i = 0; i < scripts.length; i++) {
|
|
17
|
+
const script = scripts[i];
|
|
18
|
+
|
|
19
|
+
if (script.src) {
|
|
20
|
+
if (scriptsInserted.includes(script.src)) {
|
|
21
|
+
continue;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
scriptsInserted.push(script.src);
|
|
25
|
+
const newScript = document.createElement('script');
|
|
26
|
+
newScript.async = true;
|
|
27
|
+
newScript.src = script.src;
|
|
28
|
+
document.head.appendChild(newScript);
|
|
29
|
+
} else if (
|
|
30
|
+
!script.type ||
|
|
31
|
+
[
|
|
32
|
+
'text/javascript',
|
|
33
|
+
'application/javascript',
|
|
34
|
+
'application/ecmascript',
|
|
35
|
+
].includes(script.type)
|
|
36
|
+
) {
|
|
37
|
+
if (scriptsRun.includes(script.innerText)) {
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
try {
|
|
42
|
+
scriptsRun.push(script.innerText);
|
|
43
|
+
new Function(script.innerText)();
|
|
44
|
+
} catch (error) {
|
|
45
|
+
console.warn('`Embed`: Error running script:', error);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const elem = useRef();
|
|
53
|
+
|
|
54
|
+
useEffect(() => {
|
|
55
|
+
findAndRunScripts();
|
|
56
|
+
}, []);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<View
|
|
60
|
+
className="builder-embed"
|
|
61
|
+
ref={elem}
|
|
62
|
+
dangerouslySetInnerHTML={{ __html: 'props.content' }}
|
|
63
|
+
/>
|
|
64
|
+
);
|
|
65
|
+
}
|
|
@@ -0,0 +1,522 @@
|
|
|
1
|
+
import { registerComponent } from '../functions/register-component';
|
|
2
|
+
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
6
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
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);
|
|
18
|
+
var __spreadValues = (a, b) => {
|
|
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;
|
|
26
|
+
};
|
|
27
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
28
|
+
var __async = (__this, __arguments, generator) => {
|
|
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
|
+
});
|
|
50
|
+
};
|
|
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';
|
|
55
|
+
function FormComponent(props) {
|
|
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') {
|
|
67
|
+
event.preventDefault();
|
|
68
|
+
} else if (sendWithJs) {
|
|
69
|
+
if (!(props.action || props.sendSubmissionsTo === 'email')) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
return;
|
|
72
|
+
}
|
|
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';
|
|
117
|
+
}
|
|
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
|
+
}
|
|
126
|
+
});
|
|
127
|
+
if (contentType !== 'application/json') {
|
|
128
|
+
body = formData;
|
|
129
|
+
} else {
|
|
130
|
+
const json = {};
|
|
131
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
132
|
+
set(json, key, value);
|
|
133
|
+
});
|
|
134
|
+
body = JSON.stringify(json);
|
|
135
|
+
}
|
|
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;
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
const presubmitEvent = new CustomEvent('presubmit', { detail: { body } });
|
|
147
|
+
if (formRef.current) {
|
|
148
|
+
formRef.current.dispatchEvent(presubmitEvent);
|
|
149
|
+
if (presubmitEvent.defaultPrevented) {
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
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
|
+
});
|
|
219
|
+
if (formRef.current) {
|
|
220
|
+
formRef.current.dispatchEvent(submitErrorEvent);
|
|
221
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
setResponseData(err);
|
|
226
|
+
setState('error');
|
|
227
|
+
}
|
|
228
|
+
);
|
|
229
|
+
}
|
|
230
|
+
}
|
|
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
|
+
);
|
|
313
|
+
}
|
|
314
|
+
const styles = StyleSheet.create({
|
|
315
|
+
view1: { padding: 10, color: 'red', textAlign: 'center' },
|
|
316
|
+
});
|
|
317
|
+
export { FormComponent as default };
|
|
318
|
+
|
|
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
|
+
});
|