@builder.io/sdk-react-native 0.0.6-1 → 0.0.6-3
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 +4 -1
- package/src/blocks/button/button.js +34 -0
- package/src/blocks/button/component-info.js +41 -0
- package/src/blocks/columns/columns.js +62 -0
- package/src/blocks/columns/component-info.js +242 -0
- package/src/blocks/custom-code/component-info.js +31 -0
- package/src/blocks/custom-code/custom-code.js +50 -0
- package/src/blocks/embed/component-info.js +44 -0
- package/src/blocks/embed/embed.js +43 -0
- package/src/blocks/embed/helpers.js +9 -0
- package/src/blocks/form/component-info.js +262 -0
- package/src/blocks/form/form.js +224 -0
- package/src/blocks/fragment/component-info.js +11 -0
- package/src/blocks/fragment/fragment.js +8 -0
- package/src/blocks/image/component-info.js +151 -0
- package/src/blocks/image/image.helpers.js +48 -0
- package/src/blocks/image/image.js +41 -0
- package/src/blocks/img/component-info.js +20 -0
- package/src/blocks/img/img.js +36 -0
- package/src/blocks/input/component-info.js +74 -0
- package/src/blocks/input/input.js +36 -0
- package/src/blocks/raw-text/component-info.js +16 -0
- package/src/blocks/raw-text/raw-text.js +10 -0
- package/src/blocks/section/component-info.js +49 -0
- package/src/blocks/section/section.js +31 -0
- package/src/blocks/select/component-info.js +59 -0
- package/src/blocks/select/select.js +36 -0
- package/src/blocks/submit-button/component-info.js +28 -0
- package/src/blocks/submit-button/submit-button.js +29 -0
- package/src/blocks/symbol/component-info.js +43 -0
- package/src/blocks/symbol/symbol.js +65 -0
- package/src/blocks/text/component-info.js +24 -0
- package/src/blocks/text/text.js +65 -0
- package/src/blocks/textarea/component-info.js +47 -0
- package/src/blocks/textarea/textarea.js +32 -0
- package/src/blocks/util.js +7 -0
- package/src/blocks/video/component-info.js +106 -0
- package/src/blocks/video/video.js +52 -0
- package/src/components/render-block/block-styles.js +37 -0
- package/src/components/render-block/render-block.helpers.js +23 -0
- package/src/components/render-block/render-block.js +171 -0
- package/src/components/render-block/render-component.js +36 -0
- package/src/components/render-block/render-repeated-block.js +30 -0
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.js +63 -0
- package/src/components/render-content/components/render-styles.js +58 -0
- package/src/components/render-content/index.js +4 -0
- package/src/components/render-content/render-content.js +262 -0
- package/src/components/render-inlined-styles.js +18 -0
- package/src/constants/builder-registered-components.js +42 -0
- package/src/constants/device-sizes.js +21 -0
- package/src/constants/target.js +4 -0
- package/src/context/builder.context.js +11 -0
- package/src/context/types.js +0 -0
- package/src/functions/camel-to-kebab-case.js +4 -0
- package/src/functions/convert-style-object.js +6 -0
- package/src/functions/evaluate.js +28 -0
- package/src/functions/event-handler-name.js +7 -0
- package/src/functions/get-block-actions.js +23 -0
- package/src/functions/get-block-component-options.js +28 -0
- package/src/functions/get-block-properties.js +41 -0
- package/src/functions/get-block-styles.js +44 -0
- package/src/functions/get-block-tag.js +7 -0
- package/src/functions/get-builder-search-params/fn.test.js +13 -0
- package/src/functions/get-builder-search-params/index.js +37 -0
- package/src/functions/get-content/ab-testing.js +98 -0
- package/src/functions/get-content/fn.test.js +31 -0
- package/src/functions/get-content/index.js +96 -0
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +34 -0
- package/src/functions/get-global-this.js +18 -0
- package/src/functions/get-processed-block.js +57 -0
- package/src/functions/get-processed-block.test.js +32 -0
- package/src/functions/if-target.js +15 -0
- package/src/functions/is-browser.js +6 -0
- package/src/functions/is-editing.js +7 -0
- package/src/functions/is-iframe.js +7 -0
- package/src/functions/is-previewing.js +14 -0
- package/src/functions/mark-mutable.js +10 -0
- package/src/functions/on-change.js +27 -0
- package/src/functions/on-change.test.js +19 -0
- package/src/functions/register-component.js +72 -0
- package/src/functions/register.js +29 -0
- package/src/functions/sanitize-styles.js +61 -0
- package/src/functions/set-editor-settings.js +15 -0
- package/src/functions/set.js +11 -0
- package/src/functions/set.test.js +16 -0
- package/src/functions/track.js +117 -0
- package/src/functions/transform-block.js +37 -0
- package/src/helpers/ab-tests.js +16 -0
- package/src/helpers/cookie.js +72 -0
- package/src/helpers/css.js +12 -0
- package/src/helpers/flatten.js +34 -0
- package/src/helpers/localStorage.js +34 -0
- package/src/helpers/nullable.js +4 -0
- package/src/helpers/sessionId.js +49 -0
- package/src/helpers/time.js +5 -0
- package/src/helpers/url.js +10 -0
- package/src/helpers/url.test.js +15 -0
- package/src/helpers/uuid.js +13 -0
- package/src/helpers/visitorId.js +33 -0
- package/src/index-helpers/blocks-exports.js +18 -0
- package/src/index-helpers/top-of-file.js +1 -0
- package/src/index.js +10 -0
- package/src/scripts/init-editing.js +79 -0
- package/src/types/builder-block.js +0 -0
- package/src/types/builder-content.js +0 -0
- package/src/types/can-track.js +0 -0
- package/src/types/components.js +0 -0
- package/src/types/deep-partial.js +0 -0
- package/src/types/element.js +0 -0
- package/src/types/targets.js +0 -0
- package/src/types/typescript.js +0 -0
- package/CHANGELOG.md +0 -42
|
@@ -0,0 +1,262 @@
|
|
|
1
|
+
const componentInfo = {
|
|
2
|
+
name: "Form:Form",
|
|
3
|
+
builtIn: true,
|
|
4
|
+
defaults: {
|
|
5
|
+
responsiveStyles: {
|
|
6
|
+
large: {
|
|
7
|
+
marginTop: "15px",
|
|
8
|
+
paddingBottom: "15px"
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
},
|
|
12
|
+
image: "https://cdn.builder.io/api/v1/image/assets%2FIsxPKMo2gPRRKeakUztj1D6uqed2%2Fef36d2a846134910b64b88e6d18c5ca5",
|
|
13
|
+
inputs: [
|
|
14
|
+
{
|
|
15
|
+
name: "sendSubmissionsTo",
|
|
16
|
+
type: "string",
|
|
17
|
+
enum: [
|
|
18
|
+
{
|
|
19
|
+
label: "Send to email",
|
|
20
|
+
value: "email",
|
|
21
|
+
helperText: "Send form submissions to the email address of your choosing"
|
|
22
|
+
},
|
|
23
|
+
{
|
|
24
|
+
label: "Custom",
|
|
25
|
+
value: "custom",
|
|
26
|
+
helperText: "Handle where the form requests go manually with a little code, e.g. to your own custom backend"
|
|
27
|
+
}
|
|
28
|
+
],
|
|
29
|
+
defaultValue: "email"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
name: "sendSubmissionsToEmail",
|
|
33
|
+
type: "string",
|
|
34
|
+
required: true,
|
|
35
|
+
defaultValue: "your@email.com",
|
|
36
|
+
showIf: 'options.get("sendSubmissionsTo") === "email"'
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
name: "sendWithJs",
|
|
40
|
+
type: "boolean",
|
|
41
|
+
helperText: "Set to false to use basic html form action",
|
|
42
|
+
defaultValue: true,
|
|
43
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"'
|
|
44
|
+
},
|
|
45
|
+
{
|
|
46
|
+
name: "name",
|
|
47
|
+
type: "string",
|
|
48
|
+
defaultValue: "My form"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
name: "action",
|
|
52
|
+
type: "string",
|
|
53
|
+
helperText: "URL to send the form data to",
|
|
54
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"'
|
|
55
|
+
},
|
|
56
|
+
{
|
|
57
|
+
name: "contentType",
|
|
58
|
+
type: "string",
|
|
59
|
+
defaultValue: "application/json",
|
|
60
|
+
advanced: true,
|
|
61
|
+
enum: [
|
|
62
|
+
"application/json",
|
|
63
|
+
"multipart/form-data",
|
|
64
|
+
"application/x-www-form-urlencoded"
|
|
65
|
+
],
|
|
66
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'
|
|
67
|
+
},
|
|
68
|
+
{
|
|
69
|
+
name: "method",
|
|
70
|
+
type: "string",
|
|
71
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom"',
|
|
72
|
+
defaultValue: "POST",
|
|
73
|
+
advanced: true
|
|
74
|
+
},
|
|
75
|
+
{
|
|
76
|
+
name: "previewState",
|
|
77
|
+
type: "string",
|
|
78
|
+
enum: ["unsubmitted", "sending", "success", "error"],
|
|
79
|
+
defaultValue: "unsubmitted",
|
|
80
|
+
helperText: 'Choose a state to edit, e.g. choose "success" to show what users see on success and edit the message',
|
|
81
|
+
showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'
|
|
82
|
+
},
|
|
83
|
+
{
|
|
84
|
+
name: "successUrl",
|
|
85
|
+
type: "url",
|
|
86
|
+
helperText: "Optional URL to redirect the user to on form submission success",
|
|
87
|
+
showIf: 'options.get("sendSubmissionsTo") !== "zapier" && options.get("sendWithJs") === true'
|
|
88
|
+
},
|
|
89
|
+
{
|
|
90
|
+
name: "resetFormOnSubmit",
|
|
91
|
+
type: "boolean",
|
|
92
|
+
showIf: "options.get('sendSubmissionsTo') === 'custom' && options.get('sendWithJs') === true",
|
|
93
|
+
advanced: true
|
|
94
|
+
},
|
|
95
|
+
{
|
|
96
|
+
name: "successMessage",
|
|
97
|
+
type: "uiBlocks",
|
|
98
|
+
hideFromUI: true,
|
|
99
|
+
defaultValue: [
|
|
100
|
+
{
|
|
101
|
+
"@type": "@builder.io/sdk:Element",
|
|
102
|
+
responsiveStyles: {
|
|
103
|
+
large: {
|
|
104
|
+
marginTop: "10px"
|
|
105
|
+
}
|
|
106
|
+
},
|
|
107
|
+
component: {
|
|
108
|
+
name: "Text",
|
|
109
|
+
options: {
|
|
110
|
+
text: "<span>Thanks!</span>"
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
]
|
|
115
|
+
},
|
|
116
|
+
{
|
|
117
|
+
name: "validate",
|
|
118
|
+
type: "boolean",
|
|
119
|
+
defaultValue: true,
|
|
120
|
+
advanced: true
|
|
121
|
+
},
|
|
122
|
+
{
|
|
123
|
+
name: "errorMessagePath",
|
|
124
|
+
type: "text",
|
|
125
|
+
advanced: true,
|
|
126
|
+
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" }}'
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "errorMessage",
|
|
130
|
+
type: "uiBlocks",
|
|
131
|
+
hideFromUI: true,
|
|
132
|
+
defaultValue: [
|
|
133
|
+
{
|
|
134
|
+
"@type": "@builder.io/sdk:Element",
|
|
135
|
+
responsiveStyles: {
|
|
136
|
+
large: {
|
|
137
|
+
marginTop: "10px"
|
|
138
|
+
}
|
|
139
|
+
},
|
|
140
|
+
bindings: {
|
|
141
|
+
"component.options.text": "state.formErrorMessage || block.component.options.text"
|
|
142
|
+
},
|
|
143
|
+
component: {
|
|
144
|
+
name: "Text",
|
|
145
|
+
options: {
|
|
146
|
+
text: "<span>Form submission error :( Please check your answers and try again</span>"
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
]
|
|
151
|
+
},
|
|
152
|
+
{
|
|
153
|
+
name: "sendingMessage",
|
|
154
|
+
type: "uiBlocks",
|
|
155
|
+
hideFromUI: true,
|
|
156
|
+
defaultValue: [
|
|
157
|
+
{
|
|
158
|
+
"@type": "@builder.io/sdk:Element",
|
|
159
|
+
responsiveStyles: {
|
|
160
|
+
large: {
|
|
161
|
+
marginTop: "10px"
|
|
162
|
+
}
|
|
163
|
+
},
|
|
164
|
+
component: {
|
|
165
|
+
name: "Text",
|
|
166
|
+
options: {
|
|
167
|
+
text: "<span>Sending...</span>"
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
}
|
|
171
|
+
]
|
|
172
|
+
},
|
|
173
|
+
{
|
|
174
|
+
name: "customHeaders",
|
|
175
|
+
type: "map",
|
|
176
|
+
valueType: {
|
|
177
|
+
type: "string"
|
|
178
|
+
},
|
|
179
|
+
advanced: true,
|
|
180
|
+
showIf: 'options.get("sendSubmissionsTo") === "custom" && options.get("sendWithJs") === true'
|
|
181
|
+
}
|
|
182
|
+
],
|
|
183
|
+
noWrap: true,
|
|
184
|
+
canHaveChildren: true,
|
|
185
|
+
defaultChildren: [
|
|
186
|
+
{
|
|
187
|
+
"@type": "@builder.io/sdk:Element",
|
|
188
|
+
responsiveStyles: {
|
|
189
|
+
large: {
|
|
190
|
+
marginTop: "10px"
|
|
191
|
+
}
|
|
192
|
+
},
|
|
193
|
+
component: {
|
|
194
|
+
name: "Text",
|
|
195
|
+
options: {
|
|
196
|
+
text: "<span>Enter your name</span>"
|
|
197
|
+
}
|
|
198
|
+
}
|
|
199
|
+
},
|
|
200
|
+
{
|
|
201
|
+
"@type": "@builder.io/sdk:Element",
|
|
202
|
+
responsiveStyles: {
|
|
203
|
+
large: {
|
|
204
|
+
marginTop: "10px"
|
|
205
|
+
}
|
|
206
|
+
},
|
|
207
|
+
component: {
|
|
208
|
+
name: "Form:Input",
|
|
209
|
+
options: {
|
|
210
|
+
name: "name",
|
|
211
|
+
placeholder: "Jane Doe"
|
|
212
|
+
}
|
|
213
|
+
}
|
|
214
|
+
},
|
|
215
|
+
{
|
|
216
|
+
"@type": "@builder.io/sdk:Element",
|
|
217
|
+
responsiveStyles: {
|
|
218
|
+
large: {
|
|
219
|
+
marginTop: "10px"
|
|
220
|
+
}
|
|
221
|
+
},
|
|
222
|
+
component: {
|
|
223
|
+
name: "Text",
|
|
224
|
+
options: {
|
|
225
|
+
text: "<span>Enter your email</span>"
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
},
|
|
229
|
+
{
|
|
230
|
+
"@type": "@builder.io/sdk:Element",
|
|
231
|
+
responsiveStyles: {
|
|
232
|
+
large: {
|
|
233
|
+
marginTop: "10px"
|
|
234
|
+
}
|
|
235
|
+
},
|
|
236
|
+
component: {
|
|
237
|
+
name: "Form:Input",
|
|
238
|
+
options: {
|
|
239
|
+
name: "email",
|
|
240
|
+
placeholder: "jane@doe.com"
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
},
|
|
244
|
+
{
|
|
245
|
+
"@type": "@builder.io/sdk:Element",
|
|
246
|
+
responsiveStyles: {
|
|
247
|
+
large: {
|
|
248
|
+
marginTop: "10px"
|
|
249
|
+
}
|
|
250
|
+
},
|
|
251
|
+
component: {
|
|
252
|
+
name: "Form:SubmitButton",
|
|
253
|
+
options: {
|
|
254
|
+
text: "Submit"
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
]
|
|
259
|
+
};
|
|
260
|
+
export {
|
|
261
|
+
componentInfo
|
|
262
|
+
};
|
|
@@ -0,0 +1,224 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __async = (__this, __arguments, generator) => {
|
|
21
|
+
return new Promise((resolve, reject) => {
|
|
22
|
+
var fulfilled = (value) => {
|
|
23
|
+
try {
|
|
24
|
+
step(generator.next(value));
|
|
25
|
+
} catch (e) {
|
|
26
|
+
reject(e);
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
var rejected = (value) => {
|
|
30
|
+
try {
|
|
31
|
+
step(generator.throw(value));
|
|
32
|
+
} catch (e) {
|
|
33
|
+
reject(e);
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
var step = (x) => x.done ? resolve(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
|
|
37
|
+
step((generator = generator.apply(__this, __arguments)).next());
|
|
38
|
+
});
|
|
39
|
+
};
|
|
40
|
+
import * as React from "react";
|
|
41
|
+
import { View, StyleSheet, Text } from "react-native";
|
|
42
|
+
import { useState, useContext, useRef } from "react";
|
|
43
|
+
import RenderBlock from "../../components/render-block/render-block.js";
|
|
44
|
+
import BuilderBlocks from "../../components/render-blocks.js";
|
|
45
|
+
import { isEditing } from "../../functions/is-editing.js";
|
|
46
|
+
function FormComponent(props) {
|
|
47
|
+
var _a, _b;
|
|
48
|
+
const formRef = useRef(null);
|
|
49
|
+
const [formState, setFormState] = useState(() => "unsubmitted");
|
|
50
|
+
const [responseData, setResponseData] = useState(() => null);
|
|
51
|
+
const [formErrorMessage, setFormErrorMessage] = useState(() => "");
|
|
52
|
+
function submissionState() {
|
|
53
|
+
return isEditing() && props.previewState || formState;
|
|
54
|
+
}
|
|
55
|
+
function onSubmit(event) {
|
|
56
|
+
var _a2;
|
|
57
|
+
const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === "email";
|
|
58
|
+
if (props.sendSubmissionsTo === "zapier") {
|
|
59
|
+
event.preventDefault();
|
|
60
|
+
} else if (sendWithJs) {
|
|
61
|
+
if (!(props.action || props.sendSubmissionsTo === "email")) {
|
|
62
|
+
event.preventDefault();
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
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")).filter((el2) => !!el2.name).map((el2) => {
|
|
71
|
+
let value;
|
|
72
|
+
const key = el2.name;
|
|
73
|
+
if (el2 instanceof HTMLInputElement) {
|
|
74
|
+
if (el2.type === "radio") {
|
|
75
|
+
if (el2.checked) {
|
|
76
|
+
value = el2.name;
|
|
77
|
+
return {
|
|
78
|
+
key,
|
|
79
|
+
value
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
} else if (el2.type === "checkbox") {
|
|
83
|
+
value = el2.checked;
|
|
84
|
+
} else if (el2.type === "number" || el2.type === "range") {
|
|
85
|
+
const num = el2.valueAsNumber;
|
|
86
|
+
if (!isNaN(num)) {
|
|
87
|
+
value = num;
|
|
88
|
+
}
|
|
89
|
+
} else if (el2.type === "file") {
|
|
90
|
+
value = el2.files;
|
|
91
|
+
} else {
|
|
92
|
+
value = el2.value;
|
|
93
|
+
}
|
|
94
|
+
} else {
|
|
95
|
+
value = el2.value;
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
key,
|
|
99
|
+
value
|
|
100
|
+
};
|
|
101
|
+
});
|
|
102
|
+
let contentType = props.contentType;
|
|
103
|
+
if (props.sendSubmissionsTo === "email") {
|
|
104
|
+
contentType = "multipart/form-data";
|
|
105
|
+
}
|
|
106
|
+
Array.from(formPairs).forEach(({ value }) => {
|
|
107
|
+
if (value instanceof File || Array.isArray(value) && value[0] instanceof File || value instanceof FileList) {
|
|
108
|
+
contentType = "multipart/form-data";
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
if (contentType !== "application/json") {
|
|
112
|
+
body = formData;
|
|
113
|
+
} else {
|
|
114
|
+
const json = {};
|
|
115
|
+
Array.from(formPairs).forEach(({ value, key }) => {
|
|
116
|
+
set(json, key, value);
|
|
117
|
+
});
|
|
118
|
+
body = JSON.stringify(json);
|
|
119
|
+
}
|
|
120
|
+
if (contentType && contentType !== "multipart/form-data") {
|
|
121
|
+
if (!(sendWithJs && ((_a2 = props.action) == null ? void 0 : _a2.includes("zapier.com")))) {
|
|
122
|
+
headers["content-type"] = contentType;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
const presubmitEvent = new CustomEvent("presubmit", { detail: { body } });
|
|
126
|
+
if (formRef.current) {
|
|
127
|
+
formRef.current.dispatchEvent(presubmitEvent);
|
|
128
|
+
if (presubmitEvent.defaultPrevented) {
|
|
129
|
+
return;
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
setFormState("sending");
|
|
133
|
+
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 || "")}`;
|
|
134
|
+
fetch(props.sendSubmissionsTo === "email" ? formUrl : props.action, { body, headers, method: props.method || "post" }).then((res) => __async(this, null, function* () {
|
|
135
|
+
let body2;
|
|
136
|
+
const contentType2 = res.headers.get("content-type");
|
|
137
|
+
if (contentType2 && contentType2.indexOf("application/json") !== -1) {
|
|
138
|
+
body2 = yield res.json();
|
|
139
|
+
} else {
|
|
140
|
+
body2 = yield res.text();
|
|
141
|
+
}
|
|
142
|
+
if (!res.ok && props.errorMessagePath) {
|
|
143
|
+
let message = get(body2, props.errorMessagePath);
|
|
144
|
+
if (message) {
|
|
145
|
+
if (typeof message !== "string") {
|
|
146
|
+
message = JSON.stringify(message);
|
|
147
|
+
}
|
|
148
|
+
setFormErrorMessage(message);
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
setResponseData(body2);
|
|
152
|
+
setFormState(res.ok ? "success" : "error");
|
|
153
|
+
if (res.ok) {
|
|
154
|
+
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
155
|
+
detail: { res, body: body2 }
|
|
156
|
+
});
|
|
157
|
+
if (formRef.current) {
|
|
158
|
+
formRef.current.dispatchEvent(submitSuccessEvent);
|
|
159
|
+
if (submitSuccessEvent.defaultPrevented) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (props.resetFormOnSubmit !== false) {
|
|
163
|
+
formRef.current.reset();
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
if (props.successUrl) {
|
|
167
|
+
if (formRef.current) {
|
|
168
|
+
const event2 = new CustomEvent("route", {
|
|
169
|
+
detail: { url: props.successUrl }
|
|
170
|
+
});
|
|
171
|
+
formRef.current.dispatchEvent(event2);
|
|
172
|
+
if (!event2.defaultPrevented) {
|
|
173
|
+
location.href = props.successUrl;
|
|
174
|
+
}
|
|
175
|
+
} else {
|
|
176
|
+
location.href = props.successUrl;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
}), (err) => {
|
|
181
|
+
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
182
|
+
detail: { error: err }
|
|
183
|
+
});
|
|
184
|
+
if (formRef.current) {
|
|
185
|
+
formRef.current.dispatchEvent(submitErrorEvent);
|
|
186
|
+
if (submitErrorEvent.defaultPrevented) {
|
|
187
|
+
return;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
setResponseData(err);
|
|
191
|
+
setFormState("error");
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
const builderContext = useContext(BuilderContext);
|
|
196
|
+
return /* @__PURE__ */ React.createElement(View, __spreadProps(__spreadValues({}, props.attributes), {
|
|
197
|
+
validate: props.validate,
|
|
198
|
+
ref: formRef,
|
|
199
|
+
action: !props.sendWithJs && props.action,
|
|
200
|
+
method: props.method,
|
|
201
|
+
name: props.name,
|
|
202
|
+
onSubmit: (event) => onSubmit(event)
|
|
203
|
+
}), " ", 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, {
|
|
204
|
+
block,
|
|
205
|
+
context: builderContext
|
|
206
|
+
}))) : null, " ", submissionState() === "error" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
|
|
207
|
+
dataPath: "errorMessage",
|
|
208
|
+
blocks: props.errorMessage
|
|
209
|
+
})) : null, " ", submissionState() === "sending" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
|
|
210
|
+
dataPath: "sendingMessage",
|
|
211
|
+
blocks: props.sendingMessage
|
|
212
|
+
})) : null, " ", submissionState() === "error" && responseData ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(View, {
|
|
213
|
+
style: styles.view1
|
|
214
|
+
}, " ", /* @__PURE__ */ React.createElement(Text, null, JSON.stringify(responseData, null, 2)), " ")) : null, " ", submissionState() === "success" ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(BuilderBlocks, {
|
|
215
|
+
dataPath: "successMessage",
|
|
216
|
+
blocks: props.successMessage
|
|
217
|
+
})) : null, " ");
|
|
218
|
+
}
|
|
219
|
+
const styles = StyleSheet.create({
|
|
220
|
+
view1: { padding: 10, color: "red", textAlign: "center" }
|
|
221
|
+
});
|
|
222
|
+
export {
|
|
223
|
+
FormComponent as default
|
|
224
|
+
};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { View, Text } from "react-native";
|
|
3
|
+
function FragmentComponent(props) {
|
|
4
|
+
return /* @__PURE__ */ React.createElement(View, null, /* @__PURE__ */ React.createElement(Text, null, props.children));
|
|
5
|
+
}
|
|
6
|
+
export {
|
|
7
|
+
FragmentComponent as default
|
|
8
|
+
};
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import { markSerializable } from "../util.js";
|
|
2
|
+
const componentInfo = {
|
|
3
|
+
name: "Image",
|
|
4
|
+
static: true,
|
|
5
|
+
builtIn: true,
|
|
6
|
+
image: "https://firebasestorage.googleapis.com/v0/b/builder-3b0a2.appspot.com/o/images%2Fbaseline-insert_photo-24px.svg?alt=media&token=4e5d0ef4-f5e8-4e57-b3a9-38d63a9b9dc4",
|
|
7
|
+
defaultStyles: {
|
|
8
|
+
position: "relative",
|
|
9
|
+
minHeight: "20px",
|
|
10
|
+
minWidth: "20px",
|
|
11
|
+
overflow: "hidden"
|
|
12
|
+
},
|
|
13
|
+
canHaveChildren: true,
|
|
14
|
+
inputs: [
|
|
15
|
+
{
|
|
16
|
+
name: "image",
|
|
17
|
+
type: "file",
|
|
18
|
+
bubble: true,
|
|
19
|
+
allowedFileTypes: ["jpeg", "jpg", "png", "svg"],
|
|
20
|
+
required: true,
|
|
21
|
+
defaultValue: "https://cdn.builder.io/api/v1/image/assets%2Fpwgjf0RoYWbdnJSbpBAjXNRMe9F2%2Ffb27a7c790324294af8be1c35fe30f4d",
|
|
22
|
+
onChange: markSerializable((options) => {
|
|
23
|
+
const DEFAULT_ASPECT_RATIO = 0.7041;
|
|
24
|
+
options.delete("srcset");
|
|
25
|
+
options.delete("noWebp");
|
|
26
|
+
function loadImage(url, timeout = 6e4) {
|
|
27
|
+
return new Promise((resolve, reject) => {
|
|
28
|
+
const img = document.createElement("img");
|
|
29
|
+
let loaded = false;
|
|
30
|
+
img.onload = () => {
|
|
31
|
+
loaded = true;
|
|
32
|
+
resolve(img);
|
|
33
|
+
};
|
|
34
|
+
img.addEventListener("error", (event) => {
|
|
35
|
+
console.warn("Image load failed", event.error);
|
|
36
|
+
reject(event.error);
|
|
37
|
+
});
|
|
38
|
+
img.src = url;
|
|
39
|
+
setTimeout(() => {
|
|
40
|
+
if (!loaded) {
|
|
41
|
+
reject(new Error("Image load timed out"));
|
|
42
|
+
}
|
|
43
|
+
}, timeout);
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
function round(num) {
|
|
47
|
+
return Math.round(num * 1e3) / 1e3;
|
|
48
|
+
}
|
|
49
|
+
const value = options.get("image");
|
|
50
|
+
const aspectRatio = options.get("aspectRatio");
|
|
51
|
+
fetch(value).then((res) => res.blob()).then((blob) => {
|
|
52
|
+
if (blob.type.includes("svg")) {
|
|
53
|
+
options.set("noWebp", true);
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
if (value && (!aspectRatio || aspectRatio === DEFAULT_ASPECT_RATIO)) {
|
|
57
|
+
return loadImage(value).then((img) => {
|
|
58
|
+
const possiblyUpdatedAspectRatio = options.get("aspectRatio");
|
|
59
|
+
if (options.get("image") === value && (!possiblyUpdatedAspectRatio || possiblyUpdatedAspectRatio === DEFAULT_ASPECT_RATIO)) {
|
|
60
|
+
if (img.width && img.height) {
|
|
61
|
+
options.set("aspectRatio", round(img.height / img.width));
|
|
62
|
+
options.set("height", img.height);
|
|
63
|
+
options.set("width", img.width);
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
}
|
|
68
|
+
})
|
|
69
|
+
},
|
|
70
|
+
{
|
|
71
|
+
name: "backgroundSize",
|
|
72
|
+
type: "text",
|
|
73
|
+
defaultValue: "cover",
|
|
74
|
+
enum: [
|
|
75
|
+
{
|
|
76
|
+
label: "contain",
|
|
77
|
+
value: "contain",
|
|
78
|
+
helperText: "The image should never get cropped"
|
|
79
|
+
},
|
|
80
|
+
{
|
|
81
|
+
label: "cover",
|
|
82
|
+
value: "cover",
|
|
83
|
+
helperText: "The image should fill it's box, cropping when needed"
|
|
84
|
+
}
|
|
85
|
+
]
|
|
86
|
+
},
|
|
87
|
+
{
|
|
88
|
+
name: "backgroundPosition",
|
|
89
|
+
type: "text",
|
|
90
|
+
defaultValue: "center",
|
|
91
|
+
enum: [
|
|
92
|
+
"center",
|
|
93
|
+
"top",
|
|
94
|
+
"left",
|
|
95
|
+
"right",
|
|
96
|
+
"bottom",
|
|
97
|
+
"top left",
|
|
98
|
+
"top right",
|
|
99
|
+
"bottom left",
|
|
100
|
+
"bottom right"
|
|
101
|
+
]
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
name: "altText",
|
|
105
|
+
type: "string",
|
|
106
|
+
helperText: "Text to display when the user has images off"
|
|
107
|
+
},
|
|
108
|
+
{
|
|
109
|
+
name: "height",
|
|
110
|
+
type: "number",
|
|
111
|
+
hideFromUI: true
|
|
112
|
+
},
|
|
113
|
+
{
|
|
114
|
+
name: "width",
|
|
115
|
+
type: "number",
|
|
116
|
+
hideFromUI: true
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
name: "sizes",
|
|
120
|
+
type: "string",
|
|
121
|
+
hideFromUI: true
|
|
122
|
+
},
|
|
123
|
+
{
|
|
124
|
+
name: "srcset",
|
|
125
|
+
type: "string",
|
|
126
|
+
hideFromUI: true
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: "lazy",
|
|
130
|
+
type: "boolean",
|
|
131
|
+
defaultValue: true,
|
|
132
|
+
hideFromUI: true
|
|
133
|
+
},
|
|
134
|
+
{
|
|
135
|
+
name: "fitContent",
|
|
136
|
+
type: "boolean",
|
|
137
|
+
helperText: "When child blocks are provided, fit to them instead of using the image's aspect ratio",
|
|
138
|
+
defaultValue: true
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: "aspectRatio",
|
|
142
|
+
type: "number",
|
|
143
|
+
helperText: "This is the ratio of height/width, e.g. set to 1.5 for a 300px wide and 200px tall photo. Set to 0 to not force the image to maintain it's aspect ratio",
|
|
144
|
+
advanced: true,
|
|
145
|
+
defaultValue: 0.7041
|
|
146
|
+
}
|
|
147
|
+
]
|
|
148
|
+
};
|
|
149
|
+
export {
|
|
150
|
+
componentInfo
|
|
151
|
+
};
|