@builder.io/sdk-qwik 0.0.5 → 0.0.8
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/README.md +2 -65
- package/lib/index.97024df8.js +80165 -0
- package/lib/index.d8c1e37f.cjs +80165 -0
- package/lib/index.qwik.cjs +2424 -0
- package/lib/index.qwik.mjs +2424 -0
- package/package.json +3 -4
- package/tsconfig.json +1 -1
- package/types.d.ts +12 -7
- package/src/blocks/button/button.jsx +0 -211
- package/src/blocks/button/component-info.js +0 -41
- package/src/blocks/columns/columns.jsx +0 -267
- package/src/blocks/columns/component-info.js +0 -242
- package/src/blocks/custom-code/component-info.js +0 -31
- package/src/blocks/custom-code/custom-code.jsx +0 -130
- package/src/blocks/embed/component-info.js +0 -44
- package/src/blocks/embed/embed.jsx +0 -130
- package/src/blocks/embed/helpers.js +0 -9
- package/src/blocks/form/builder-blocks.jsx +0 -100
- package/src/blocks/form/component-info.js +0 -262
- package/src/blocks/form/form.jsx +0 -789
- package/src/blocks/fragment/component-info.js +0 -11
- package/src/blocks/fragment/fragment.jsx +0 -59
- package/src/blocks/image/component-info.js +0 -151
- package/src/blocks/image/image.helpers.js +0 -48
- package/src/blocks/image/image.jsx +0 -554
- package/src/blocks/img/component-info.js +0 -20
- package/src/blocks/img/img.jsx +0 -76
- package/src/blocks/input/component-info.js +0 -74
- package/src/blocks/input/input.jsx +0 -87
- package/src/blocks/raw-text/component-info.js +0 -16
- package/src/blocks/raw-text/raw-text.jsx +0 -53
- package/src/blocks/section/component-info.js +0 -49
- package/src/blocks/section/section.jsx +0 -97
- package/src/blocks/select/component-info.js +0 -59
- package/src/blocks/select/select.jsx +0 -149
- package/src/blocks/submit-button/component-info.js +0 -28
- package/src/blocks/submit-button/submit-button.jsx +0 -87
- package/src/blocks/symbol/component-info.js +0 -43
- package/src/blocks/symbol/symbol.jsx +0 -230
- package/src/blocks/text/component-info.js +0 -24
- package/src/blocks/text/text.jsx +0 -46
- package/src/blocks/textarea/component-info.js +0 -47
- package/src/blocks/textarea/textarea.jsx +0 -65
- package/src/blocks/util.js +0 -12
- package/src/blocks/video/component-info.js +0 -106
- package/src/blocks/video/video.jsx +0 -103
- package/src/components/render-block/block-styles.jsx +0 -186
- package/src/components/render-block/render-block.helpers.js +0 -23
- package/src/components/render-block/render-block.jsx +0 -749
- package/src/components/render-block/render-component.jsx +0 -257
- package/src/components/render-block/render-repeated-block.jsx +0 -119
- package/src/components/render-block/types.js +0 -0
- package/src/components/render-blocks.jsx +0 -387
- package/src/components/render-content/components/render-styles.jsx +0 -140
- package/src/components/render-content/index.js +0 -4
- package/src/components/render-content/render-content.jsx +0 -636
- package/src/components/render-inlined-styles.jsx +0 -153
- package/src/constants/builder-registered-components.js +0 -48
- package/src/constants/device-sizes.js +0 -21
- package/src/constants/target.js +0 -4
- package/src/context/builder.context.js +0 -5
- package/src/functions/camel-to-kebab-case.js +0 -4
- package/src/functions/convert-style-object.js +0 -6
- package/src/functions/evaluate.js +0 -28
- package/src/functions/event-handler-name.js +0 -7
- package/src/functions/get-block-actions.js +0 -23
- package/src/functions/get-block-component-options.js +0 -28
- package/src/functions/get-block-properties.js +0 -29
- package/src/functions/get-block-styles.js +0 -34
- package/src/functions/get-block-tag.js +0 -6
- package/src/functions/get-builder-search-params/fn.test.js +0 -13
- package/src/functions/get-builder-search-params/index.js +0 -33
- package/src/functions/get-content/ab-testing.js +0 -38
- package/src/functions/get-content/fn.test.js +0 -31
- package/src/functions/get-content/index.js +0 -99
- package/src/functions/get-content/types.js +0 -0
- package/src/functions/get-fetch.js +0 -33
- package/src/functions/get-global-this.js +0 -18
- package/src/functions/get-processed-block.js +0 -53
- package/src/functions/get-processed-block.test.js +0 -32
- package/src/functions/if-target.js +0 -15
- package/src/functions/is-browser.js +0 -6
- package/src/functions/is-editing.js +0 -7
- package/src/functions/is-iframe.js +0 -7
- package/src/functions/is-previewing.js +0 -14
- package/src/functions/on-change.js +0 -27
- package/src/functions/on-change.test.js +0 -19
- package/src/functions/register-component.js +0 -72
- package/src/functions/register.js +0 -29
- package/src/functions/sanitize-styles.js +0 -5
- package/src/functions/set-editor-settings.js +0 -15
- package/src/functions/set.js +0 -11
- package/src/functions/set.test.js +0 -16
- package/src/functions/track.js +0 -22
- package/src/functions/transform-block.js +0 -6
- package/src/helpers/css.js +0 -12
- package/src/helpers/flatten.js +0 -34
- package/src/index-helpers/blocks-exports.js +0 -22
- package/src/index-helpers/top-of-file.js +0 -4
- package/src/index.js +0 -10
- package/src/scripts/init-editing.js +0 -79
- package/src/types/builder-block.js +0 -0
- package/src/types/builder-content.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/src/blocks/form/form.jsx
DELETED
|
@@ -1,789 +0,0 @@
|
|
|
1
|
-
// GENERATED BY MITOSIS
|
|
2
|
-
|
|
3
|
-
import RenderBlock from "../../components/render-block/render-block";
|
|
4
|
-
import BuilderContext from "../../context/builder.context";
|
|
5
|
-
import { isEditing } from "../../functions/is-editing.js";
|
|
6
|
-
import BuilderBlocks from "./builder-blocks";
|
|
7
|
-
import {
|
|
8
|
-
Fragment,
|
|
9
|
-
Host,
|
|
10
|
-
component$,
|
|
11
|
-
h,
|
|
12
|
-
useContext,
|
|
13
|
-
useRef,
|
|
14
|
-
useStore,
|
|
15
|
-
useStylesScoped$,
|
|
16
|
-
} from "@builder.io/qwik";
|
|
17
|
-
export const submissionState = function submissionState(
|
|
18
|
-
props,
|
|
19
|
-
state,
|
|
20
|
-
formRef,
|
|
21
|
-
builderContext
|
|
22
|
-
) {
|
|
23
|
-
return (isEditing() && props.previewState) || state.formState;
|
|
24
|
-
};
|
|
25
|
-
export const onSubmit = function onSubmit(
|
|
26
|
-
props,
|
|
27
|
-
state,
|
|
28
|
-
formRef,
|
|
29
|
-
builderContext,
|
|
30
|
-
event
|
|
31
|
-
) {
|
|
32
|
-
const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === "email";
|
|
33
|
-
|
|
34
|
-
if (props.sendSubmissionsTo === "zapier") {
|
|
35
|
-
event.preventDefault();
|
|
36
|
-
} else if (sendWithJs) {
|
|
37
|
-
if (!(props.action || props.sendSubmissionsTo === "email")) {
|
|
38
|
-
event.preventDefault();
|
|
39
|
-
return;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
event.preventDefault();
|
|
43
|
-
const el = event.currentTarget;
|
|
44
|
-
const headers = props.customHeaders || {};
|
|
45
|
-
let body;
|
|
46
|
-
const formData = new FormData(el); // TODO: maybe support null
|
|
47
|
-
|
|
48
|
-
const formPairs = Array.from(
|
|
49
|
-
event.currentTarget.querySelectorAll("input,select,textarea")
|
|
50
|
-
)
|
|
51
|
-
.filter((el) => !!el.name)
|
|
52
|
-
.map((el) => {
|
|
53
|
-
let value;
|
|
54
|
-
const key = el.name;
|
|
55
|
-
|
|
56
|
-
if (el instanceof HTMLInputElement) {
|
|
57
|
-
if (el.type === "radio") {
|
|
58
|
-
if (el.checked) {
|
|
59
|
-
value = el.name;
|
|
60
|
-
return {
|
|
61
|
-
key,
|
|
62
|
-
value,
|
|
63
|
-
};
|
|
64
|
-
}
|
|
65
|
-
} else if (el.type === "checkbox") {
|
|
66
|
-
value = el.checked;
|
|
67
|
-
} else if (el.type === "number" || el.type === "range") {
|
|
68
|
-
const num = el.valueAsNumber;
|
|
69
|
-
|
|
70
|
-
if (!isNaN(num)) {
|
|
71
|
-
value = num;
|
|
72
|
-
}
|
|
73
|
-
} else if (el.type === "file") {
|
|
74
|
-
// TODO: one vs multiple files
|
|
75
|
-
value = el.files;
|
|
76
|
-
} else {
|
|
77
|
-
value = el.value;
|
|
78
|
-
}
|
|
79
|
-
} else {
|
|
80
|
-
value = el.value;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
return {
|
|
84
|
-
key,
|
|
85
|
-
value,
|
|
86
|
-
};
|
|
87
|
-
});
|
|
88
|
-
let contentType = props.contentType;
|
|
89
|
-
|
|
90
|
-
if (props.sendSubmissionsTo === "email") {
|
|
91
|
-
contentType = "multipart/form-data";
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
Array.from(formPairs).forEach(({ value }) => {
|
|
95
|
-
if (
|
|
96
|
-
value instanceof File ||
|
|
97
|
-
(Array.isArray(value) && value[0] instanceof File) ||
|
|
98
|
-
value instanceof FileList
|
|
99
|
-
) {
|
|
100
|
-
contentType = "multipart/form-data";
|
|
101
|
-
}
|
|
102
|
-
}); // TODO: send as urlEncoded or multipart by default
|
|
103
|
-
// because of ease of use and reliability in browser API
|
|
104
|
-
// for encoding the form?
|
|
105
|
-
|
|
106
|
-
if (contentType !== "application/json") {
|
|
107
|
-
body = formData;
|
|
108
|
-
} else {
|
|
109
|
-
// Json
|
|
110
|
-
const json = {};
|
|
111
|
-
Array.from(formPairs).forEach(({ value, key }) => {
|
|
112
|
-
set(json, key, value);
|
|
113
|
-
});
|
|
114
|
-
body = JSON.stringify(json);
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
if (contentType && contentType !== "multipart/form-data") {
|
|
118
|
-
if (
|
|
119
|
-
/* Zapier doesn't allow content-type header to be sent from browsers */
|
|
120
|
-
!(sendWithJs && props.action?.includes("zapier.com"))
|
|
121
|
-
) {
|
|
122
|
-
headers["content-type"] = contentType;
|
|
123
|
-
}
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
const presubmitEvent = new CustomEvent("presubmit", {
|
|
127
|
-
detail: {
|
|
128
|
-
body,
|
|
129
|
-
},
|
|
130
|
-
});
|
|
131
|
-
|
|
132
|
-
if (formRef) {
|
|
133
|
-
formRef.dispatchEvent(presubmitEvent);
|
|
134
|
-
|
|
135
|
-
if (presubmitEvent.defaultPrevented) {
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
state.formState = "sending";
|
|
141
|
-
const formUrl = `${
|
|
142
|
-
builder.env === "dev" ? "http://localhost:5000" : "https://builder.io"
|
|
143
|
-
}/api/v1/form-submit?apiKey=${builder.apiKey}&to=${btoa(
|
|
144
|
-
props.sendSubmissionsToEmail || ""
|
|
145
|
-
)}&name=${encodeURIComponent(props.name || "")}`;
|
|
146
|
-
fetch(
|
|
147
|
-
props.sendSubmissionsTo === "email" ? formUrl : props.action,
|
|
148
|
-
/* TODO: throw error if no action URL */
|
|
149
|
-
{
|
|
150
|
-
body,
|
|
151
|
-
headers,
|
|
152
|
-
method: props.method || "post",
|
|
153
|
-
}
|
|
154
|
-
).then(
|
|
155
|
-
async (res) => {
|
|
156
|
-
let body;
|
|
157
|
-
const contentType = res.headers.get("content-type");
|
|
158
|
-
|
|
159
|
-
if (contentType && contentType.indexOf("application/json") !== -1) {
|
|
160
|
-
body = await res.json();
|
|
161
|
-
} else {
|
|
162
|
-
body = await res.text();
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
if (!res.ok && props.errorMessagePath) {
|
|
166
|
-
/* TODO: allow supplying an error formatter function */
|
|
167
|
-
let message = get(body, props.errorMessagePath);
|
|
168
|
-
|
|
169
|
-
if (message) {
|
|
170
|
-
if (typeof message !== "string") {
|
|
171
|
-
/* TODO: ideally convert json to yaml so it woul dbe like
|
|
172
|
-
error: - email has been taken */
|
|
173
|
-
message = JSON.stringify(message);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
state.formErrorMessage = message;
|
|
177
|
-
}
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
state.responseData = body;
|
|
181
|
-
state.formState = res.ok ? "success" : "error";
|
|
182
|
-
|
|
183
|
-
if (res.ok) {
|
|
184
|
-
const submitSuccessEvent = new CustomEvent("submit:success", {
|
|
185
|
-
detail: {
|
|
186
|
-
res,
|
|
187
|
-
body,
|
|
188
|
-
},
|
|
189
|
-
});
|
|
190
|
-
|
|
191
|
-
if (formRef) {
|
|
192
|
-
formRef.dispatchEvent(submitSuccessEvent);
|
|
193
|
-
|
|
194
|
-
if (submitSuccessEvent.defaultPrevented) {
|
|
195
|
-
return;
|
|
196
|
-
}
|
|
197
|
-
/* TODO: option to turn this on/off? */
|
|
198
|
-
|
|
199
|
-
if (props.resetFormOnSubmit !== false) {
|
|
200
|
-
formRef.reset();
|
|
201
|
-
}
|
|
202
|
-
}
|
|
203
|
-
/* TODO: client side route event first that can be preventDefaulted */
|
|
204
|
-
|
|
205
|
-
if (props.successUrl) {
|
|
206
|
-
if (formRef) {
|
|
207
|
-
const event = new CustomEvent("route", {
|
|
208
|
-
detail: {
|
|
209
|
-
url: props.successUrl,
|
|
210
|
-
},
|
|
211
|
-
});
|
|
212
|
-
formRef.dispatchEvent(event);
|
|
213
|
-
|
|
214
|
-
if (!event.defaultPrevented) {
|
|
215
|
-
location.href = props.successUrl;
|
|
216
|
-
}
|
|
217
|
-
} else {
|
|
218
|
-
location.href = props.successUrl;
|
|
219
|
-
}
|
|
220
|
-
}
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
(err) => {
|
|
224
|
-
const submitErrorEvent = new CustomEvent("submit:error", {
|
|
225
|
-
detail: {
|
|
226
|
-
error: err,
|
|
227
|
-
},
|
|
228
|
-
});
|
|
229
|
-
|
|
230
|
-
if (formRef) {
|
|
231
|
-
formRef.dispatchEvent(submitErrorEvent);
|
|
232
|
-
|
|
233
|
-
if (submitErrorEvent.defaultPrevented) {
|
|
234
|
-
return;
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
|
|
238
|
-
state.responseData = err;
|
|
239
|
-
state.formState = "error";
|
|
240
|
-
}
|
|
241
|
-
);
|
|
242
|
-
}
|
|
243
|
-
};
|
|
244
|
-
export const FormComponent = component$(
|
|
245
|
-
(props) => {
|
|
246
|
-
useStylesScoped$(STYLES);
|
|
247
|
-
const builderContext = useContext(BuilderContext);
|
|
248
|
-
const formRef = useRef();
|
|
249
|
-
const state = useStore({
|
|
250
|
-
formState: "unsubmitted",
|
|
251
|
-
responseData: null,
|
|
252
|
-
formErrorMessage: "",
|
|
253
|
-
});
|
|
254
|
-
return (
|
|
255
|
-
<Host
|
|
256
|
-
validate={props.validate}
|
|
257
|
-
ref={formRef}
|
|
258
|
-
action={(() => {
|
|
259
|
-
!props.sendWithJs && props.action;
|
|
260
|
-
})()}
|
|
261
|
-
method={props.method}
|
|
262
|
-
name={props.name}
|
|
263
|
-
onSubmit$={(event) =>
|
|
264
|
-
onSubmit(props, state, formRef, builderContext, event)
|
|
265
|
-
}
|
|
266
|
-
{...props.attributes}
|
|
267
|
-
>
|
|
268
|
-
<>
|
|
269
|
-
{props.builderBlock && props.builderBlock.children
|
|
270
|
-
? (props.builderBlock?.children || []).map((block) => {
|
|
271
|
-
return (
|
|
272
|
-
<RenderBlock
|
|
273
|
-
block={block}
|
|
274
|
-
context={builderContext}
|
|
275
|
-
></RenderBlock>
|
|
276
|
-
);
|
|
277
|
-
})
|
|
278
|
-
: null}
|
|
279
|
-
{submissionState(props, state, formRef, builderContext) ===
|
|
280
|
-
"error" ? (
|
|
281
|
-
<BuilderBlocks
|
|
282
|
-
dataPath="errorMessage"
|
|
283
|
-
blocks={props.errorMessage}
|
|
284
|
-
></BuilderBlocks>
|
|
285
|
-
) : null}
|
|
286
|
-
{submissionState(props, state, formRef, builderContext) ===
|
|
287
|
-
"sending" ? (
|
|
288
|
-
<BuilderBlocks
|
|
289
|
-
dataPath="sendingMessage"
|
|
290
|
-
blocks={props.sendingMessage}
|
|
291
|
-
></BuilderBlocks>
|
|
292
|
-
) : null}
|
|
293
|
-
{submissionState(props, state, formRef, builderContext) === "error" &&
|
|
294
|
-
state.responseData ? (
|
|
295
|
-
<pre class="builder-form-error-text pre-FormComponent">
|
|
296
|
-
{JSON.stringify(state.responseData, null, 2)}
|
|
297
|
-
</pre>
|
|
298
|
-
) : null}
|
|
299
|
-
{submissionState(props, state, formRef, builderContext) ===
|
|
300
|
-
"success" ? (
|
|
301
|
-
<BuilderBlocks
|
|
302
|
-
dataPath="successMessage"
|
|
303
|
-
blocks={props.successMessage}
|
|
304
|
-
></BuilderBlocks>
|
|
305
|
-
) : null}
|
|
306
|
-
</>
|
|
307
|
-
</Host>
|
|
308
|
-
);
|
|
309
|
-
},
|
|
310
|
-
{ tagName: "form" }
|
|
311
|
-
);
|
|
312
|
-
export default FormComponent;
|
|
313
|
-
export const STYLES = `.pre-FormComponent {
|
|
314
|
-
padding: 10px;
|
|
315
|
-
color: red;
|
|
316
|
-
text-align: center; }`;
|
|
317
|
-
export const COMPONENT = {
|
|
318
|
-
"@type": "@builder.io/mitosis/component",
|
|
319
|
-
imports: [
|
|
320
|
-
{
|
|
321
|
-
imports: {
|
|
322
|
-
RenderBlock: "default",
|
|
323
|
-
},
|
|
324
|
-
path: "../../components/render-block/render-block.lite",
|
|
325
|
-
},
|
|
326
|
-
{
|
|
327
|
-
imports: {
|
|
328
|
-
isEditing: "isEditing",
|
|
329
|
-
},
|
|
330
|
-
path: "../../functions/is-editing.js",
|
|
331
|
-
},
|
|
332
|
-
{
|
|
333
|
-
imports: {
|
|
334
|
-
BuilderBlocks: "default",
|
|
335
|
-
},
|
|
336
|
-
path: "./builder-blocks.lite",
|
|
337
|
-
},
|
|
338
|
-
{
|
|
339
|
-
imports: {
|
|
340
|
-
BuilderContext: "default",
|
|
341
|
-
},
|
|
342
|
-
path: "../../context/builder.context.lite",
|
|
343
|
-
},
|
|
344
|
-
],
|
|
345
|
-
exports: {},
|
|
346
|
-
inputs: [],
|
|
347
|
-
meta: {},
|
|
348
|
-
refs: {
|
|
349
|
-
formRef: {
|
|
350
|
-
argument: "",
|
|
351
|
-
},
|
|
352
|
-
},
|
|
353
|
-
state: {
|
|
354
|
-
formState: "unsubmitted",
|
|
355
|
-
responseData: null,
|
|
356
|
-
formErrorMessage: "",
|
|
357
|
-
submissionState:
|
|
358
|
-
"@builder.io/mitosis/method:get submissionState() {\n return isEditing() && props.previewState || state.formState;\n}",
|
|
359
|
-
onSubmit:
|
|
360
|
-
"@builder.io/mitosis/method:onSubmit(event: Event & {\n currentTarget: HTMLFormElement;\n}) {\n const sendWithJs = props.sendWithJs || props.sendSubmissionsTo === 'email';\n\n if (props.sendSubmissionsTo === 'zapier') {\n event.preventDefault();\n } else if (sendWithJs) {\n if (!(props.action || props.sendSubmissionsTo === 'email')) {\n event.preventDefault();\n return;\n }\n\n event.preventDefault();\n const el = event.currentTarget;\n const headers = props.customHeaders || {};\n let body: any;\n const formData = new FormData(el); // TODO: maybe support null\n\n const formPairs: {\n key: string;\n value: File | boolean | number | string | FileList;\n }[] = Array.from(event.currentTarget.querySelectorAll('input,select,textarea')).filter(el => !!(el as HTMLInputElement).name).map(el => {\n let value: any;\n const key = (el as HTMLImageElement).name;\n\n if (el instanceof HTMLInputElement) {\n if (el.type === 'radio') {\n if (el.checked) {\n value = el.name;\n return {\n key,\n value\n };\n }\n } else if (el.type === 'checkbox') {\n value = el.checked;\n } else if (el.type === 'number' || el.type === 'range') {\n const num = el.valueAsNumber;\n\n if (!isNaN(num)) {\n value = num;\n }\n } else if (el.type === 'file') {\n // TODO: one vs multiple files\n value = el.files;\n } else {\n value = el.value;\n }\n } else {\n value = (el as HTMLInputElement).value;\n }\n\n return {\n key,\n value\n };\n });\n let contentType = props.contentType;\n\n if (props.sendSubmissionsTo === 'email') {\n contentType = 'multipart/form-data';\n }\n\n Array.from(formPairs).forEach(({\n value\n }) => {\n if (value instanceof File || Array.isArray(value) && value[0] instanceof File || value instanceof FileList) {\n contentType = 'multipart/form-data';\n }\n }); // TODO: send as urlEncoded or multipart by default\n // because of ease of use and reliability in browser API\n // for encoding the form?\n\n if (contentType !== 'application/json') {\n body = formData;\n } else {\n // Json\n const json = {};\n Array.from(formPairs).forEach(({\n value,\n key\n }) => {\n set(json, key, value);\n });\n body = JSON.stringify(json);\n }\n\n if (contentType && contentType !== 'multipart/form-data') {\n if (\n /* Zapier doesn't allow content-type header to be sent from browsers */\n !(sendWithJs && props.action?.includes('zapier.com'))) {\n headers['content-type'] = contentType;\n }\n }\n\n const presubmitEvent = new CustomEvent('presubmit', {\n detail: {\n body\n }\n });\n\n if (formRef) {\n formRef.dispatchEvent(presubmitEvent);\n\n if (presubmitEvent.defaultPrevented) {\n return;\n }\n }\n\n state.formState = 'sending';\n 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 || '')}`;\n fetch(props.sendSubmissionsTo === 'email' ? formUrl : props.action!\n /* TODO: throw error if no action URL */\n , {\n body,\n headers,\n method: props.method || 'post'\n }).then(async res => {\n let body;\n const contentType = res.headers.get('content-type');\n\n if (contentType && contentType.indexOf('application/json') !== -1) {\n body = await res.json();\n } else {\n body = await res.text();\n }\n\n if (!res.ok && props.errorMessagePath) {\n /* TODO: allow supplying an error formatter function */\n let message = get(body, props.errorMessagePath);\n\n if (message) {\n if (typeof message !== 'string') {\n /* TODO: ideally convert json to yaml so it woul dbe like\n error: - email has been taken */\n message = JSON.stringify(message);\n }\n\n state.formErrorMessage = message;\n }\n }\n\n state.responseData = body;\n state.formState = res.ok ? 'success' : 'error';\n\n if (res.ok) {\n const submitSuccessEvent = new CustomEvent('submit:success', {\n detail: {\n res,\n body\n }\n });\n\n if (formRef) {\n formRef.dispatchEvent(submitSuccessEvent);\n\n if (submitSuccessEvent.defaultPrevented) {\n return;\n }\n /* TODO: option to turn this on/off? */\n\n\n if (props.resetFormOnSubmit !== false) {\n formRef.reset();\n }\n }\n /* TODO: client side route event first that can be preventDefaulted */\n\n\n if (props.successUrl) {\n if (formRef) {\n const event = new CustomEvent('route', {\n detail: {\n url: props.successUrl\n }\n });\n formRef.dispatchEvent(event);\n\n if (!event.defaultPrevented) {\n location.href = props.successUrl;\n }\n } else {\n location.href = props.successUrl;\n }\n }\n }\n }, err => {\n const submitErrorEvent = new CustomEvent('submit:error', {\n detail: {\n error: err\n }\n });\n\n if (formRef) {\n formRef.dispatchEvent(submitErrorEvent);\n\n if (submitErrorEvent.defaultPrevented) {\n return;\n }\n }\n\n state.responseData = err;\n state.formState = 'error';\n });\n }\n}",
|
|
361
|
-
},
|
|
362
|
-
children: [
|
|
363
|
-
{
|
|
364
|
-
"@type": "@builder.io/mitosis/node",
|
|
365
|
-
name: "Host",
|
|
366
|
-
meta: {},
|
|
367
|
-
scope: {},
|
|
368
|
-
properties: {},
|
|
369
|
-
bindings: {
|
|
370
|
-
validate: {
|
|
371
|
-
code: "props.validate",
|
|
372
|
-
},
|
|
373
|
-
ref: {
|
|
374
|
-
code: "formRef",
|
|
375
|
-
},
|
|
376
|
-
action: {
|
|
377
|
-
code: "!props.sendWithJs && props.action",
|
|
378
|
-
},
|
|
379
|
-
method: {
|
|
380
|
-
code: "props.method",
|
|
381
|
-
},
|
|
382
|
-
name: {
|
|
383
|
-
code: "props.name",
|
|
384
|
-
},
|
|
385
|
-
onSubmit: {
|
|
386
|
-
code: "onSubmit(props,state,formRef,builderContext,event)",
|
|
387
|
-
arguments: ["event"],
|
|
388
|
-
},
|
|
389
|
-
_spread: {
|
|
390
|
-
code: "props.attributes",
|
|
391
|
-
},
|
|
392
|
-
},
|
|
393
|
-
children: [
|
|
394
|
-
{
|
|
395
|
-
"@type": "@builder.io/mitosis/node",
|
|
396
|
-
name: "div",
|
|
397
|
-
meta: {},
|
|
398
|
-
scope: {},
|
|
399
|
-
properties: {
|
|
400
|
-
_text: "\n ",
|
|
401
|
-
},
|
|
402
|
-
bindings: {},
|
|
403
|
-
children: [],
|
|
404
|
-
},
|
|
405
|
-
{
|
|
406
|
-
"@type": "@builder.io/mitosis/node",
|
|
407
|
-
name: "Show",
|
|
408
|
-
meta: {},
|
|
409
|
-
scope: {},
|
|
410
|
-
properties: {},
|
|
411
|
-
bindings: {
|
|
412
|
-
when: {
|
|
413
|
-
code: "props.builderBlock && props.builderBlock.children",
|
|
414
|
-
},
|
|
415
|
-
},
|
|
416
|
-
children: [
|
|
417
|
-
{
|
|
418
|
-
"@type": "@builder.io/mitosis/node",
|
|
419
|
-
name: "div",
|
|
420
|
-
meta: {},
|
|
421
|
-
scope: {},
|
|
422
|
-
properties: {
|
|
423
|
-
_text: "\n ",
|
|
424
|
-
},
|
|
425
|
-
bindings: {},
|
|
426
|
-
children: [],
|
|
427
|
-
},
|
|
428
|
-
{
|
|
429
|
-
"@type": "@builder.io/mitosis/node",
|
|
430
|
-
name: "For",
|
|
431
|
-
meta: {},
|
|
432
|
-
scope: {
|
|
433
|
-
For: ["block"],
|
|
434
|
-
},
|
|
435
|
-
properties: {
|
|
436
|
-
_forName: "block",
|
|
437
|
-
},
|
|
438
|
-
bindings: {
|
|
439
|
-
each: {
|
|
440
|
-
code: "props.builderBlock?.children",
|
|
441
|
-
},
|
|
442
|
-
},
|
|
443
|
-
children: [
|
|
444
|
-
{
|
|
445
|
-
"@type": "@builder.io/mitosis/node",
|
|
446
|
-
name: "RenderBlock",
|
|
447
|
-
meta: {},
|
|
448
|
-
scope: {},
|
|
449
|
-
properties: {},
|
|
450
|
-
bindings: {
|
|
451
|
-
block: {
|
|
452
|
-
code: "block",
|
|
453
|
-
},
|
|
454
|
-
context: {
|
|
455
|
-
code: "builderContext",
|
|
456
|
-
},
|
|
457
|
-
},
|
|
458
|
-
children: [],
|
|
459
|
-
},
|
|
460
|
-
],
|
|
461
|
-
},
|
|
462
|
-
{
|
|
463
|
-
"@type": "@builder.io/mitosis/node",
|
|
464
|
-
name: "div",
|
|
465
|
-
meta: {},
|
|
466
|
-
scope: {},
|
|
467
|
-
properties: {
|
|
468
|
-
_text: "\n ",
|
|
469
|
-
},
|
|
470
|
-
bindings: {},
|
|
471
|
-
children: [],
|
|
472
|
-
},
|
|
473
|
-
],
|
|
474
|
-
},
|
|
475
|
-
{
|
|
476
|
-
"@type": "@builder.io/mitosis/node",
|
|
477
|
-
name: "div",
|
|
478
|
-
meta: {},
|
|
479
|
-
scope: {},
|
|
480
|
-
properties: {
|
|
481
|
-
_text: "\n\n ",
|
|
482
|
-
},
|
|
483
|
-
bindings: {},
|
|
484
|
-
children: [],
|
|
485
|
-
},
|
|
486
|
-
{
|
|
487
|
-
"@type": "@builder.io/mitosis/node",
|
|
488
|
-
name: "Show",
|
|
489
|
-
meta: {},
|
|
490
|
-
scope: {},
|
|
491
|
-
properties: {},
|
|
492
|
-
bindings: {
|
|
493
|
-
when: {
|
|
494
|
-
code: "submissionState(props,state,formRef,builderContext) === 'error'",
|
|
495
|
-
},
|
|
496
|
-
},
|
|
497
|
-
children: [
|
|
498
|
-
{
|
|
499
|
-
"@type": "@builder.io/mitosis/node",
|
|
500
|
-
name: "div",
|
|
501
|
-
meta: {},
|
|
502
|
-
scope: {},
|
|
503
|
-
properties: {
|
|
504
|
-
_text: "\n ",
|
|
505
|
-
},
|
|
506
|
-
bindings: {},
|
|
507
|
-
children: [],
|
|
508
|
-
},
|
|
509
|
-
{
|
|
510
|
-
"@type": "@builder.io/mitosis/node",
|
|
511
|
-
name: "BuilderBlocks",
|
|
512
|
-
meta: {},
|
|
513
|
-
scope: {},
|
|
514
|
-
properties: {
|
|
515
|
-
dataPath: "errorMessage",
|
|
516
|
-
},
|
|
517
|
-
bindings: {
|
|
518
|
-
blocks: {
|
|
519
|
-
code: "props.errorMessage",
|
|
520
|
-
},
|
|
521
|
-
},
|
|
522
|
-
children: [],
|
|
523
|
-
},
|
|
524
|
-
{
|
|
525
|
-
"@type": "@builder.io/mitosis/node",
|
|
526
|
-
name: "div",
|
|
527
|
-
meta: {},
|
|
528
|
-
scope: {},
|
|
529
|
-
properties: {
|
|
530
|
-
_text: "\n ",
|
|
531
|
-
},
|
|
532
|
-
bindings: {},
|
|
533
|
-
children: [],
|
|
534
|
-
},
|
|
535
|
-
],
|
|
536
|
-
},
|
|
537
|
-
{
|
|
538
|
-
"@type": "@builder.io/mitosis/node",
|
|
539
|
-
name: "div",
|
|
540
|
-
meta: {},
|
|
541
|
-
scope: {},
|
|
542
|
-
properties: {
|
|
543
|
-
_text: "\n\n ",
|
|
544
|
-
},
|
|
545
|
-
bindings: {},
|
|
546
|
-
children: [],
|
|
547
|
-
},
|
|
548
|
-
{
|
|
549
|
-
"@type": "@builder.io/mitosis/node",
|
|
550
|
-
name: "Show",
|
|
551
|
-
meta: {},
|
|
552
|
-
scope: {},
|
|
553
|
-
properties: {},
|
|
554
|
-
bindings: {
|
|
555
|
-
when: {
|
|
556
|
-
code: "submissionState(props,state,formRef,builderContext) === 'sending'",
|
|
557
|
-
},
|
|
558
|
-
},
|
|
559
|
-
children: [
|
|
560
|
-
{
|
|
561
|
-
"@type": "@builder.io/mitosis/node",
|
|
562
|
-
name: "div",
|
|
563
|
-
meta: {},
|
|
564
|
-
scope: {},
|
|
565
|
-
properties: {
|
|
566
|
-
_text: "\n ",
|
|
567
|
-
},
|
|
568
|
-
bindings: {},
|
|
569
|
-
children: [],
|
|
570
|
-
},
|
|
571
|
-
{
|
|
572
|
-
"@type": "@builder.io/mitosis/node",
|
|
573
|
-
name: "BuilderBlocks",
|
|
574
|
-
meta: {},
|
|
575
|
-
scope: {},
|
|
576
|
-
properties: {
|
|
577
|
-
dataPath: "sendingMessage",
|
|
578
|
-
},
|
|
579
|
-
bindings: {
|
|
580
|
-
blocks: {
|
|
581
|
-
code: "props.sendingMessage",
|
|
582
|
-
},
|
|
583
|
-
},
|
|
584
|
-
children: [],
|
|
585
|
-
},
|
|
586
|
-
{
|
|
587
|
-
"@type": "@builder.io/mitosis/node",
|
|
588
|
-
name: "div",
|
|
589
|
-
meta: {},
|
|
590
|
-
scope: {},
|
|
591
|
-
properties: {
|
|
592
|
-
_text: "\n ",
|
|
593
|
-
},
|
|
594
|
-
bindings: {},
|
|
595
|
-
children: [],
|
|
596
|
-
},
|
|
597
|
-
],
|
|
598
|
-
},
|
|
599
|
-
{
|
|
600
|
-
"@type": "@builder.io/mitosis/node",
|
|
601
|
-
name: "div",
|
|
602
|
-
meta: {},
|
|
603
|
-
scope: {},
|
|
604
|
-
properties: {
|
|
605
|
-
_text: "\n\n ",
|
|
606
|
-
},
|
|
607
|
-
bindings: {},
|
|
608
|
-
children: [],
|
|
609
|
-
},
|
|
610
|
-
{
|
|
611
|
-
"@type": "@builder.io/mitosis/node",
|
|
612
|
-
name: "Show",
|
|
613
|
-
meta: {},
|
|
614
|
-
scope: {},
|
|
615
|
-
properties: {},
|
|
616
|
-
bindings: {
|
|
617
|
-
when: {
|
|
618
|
-
code: "submissionState(props,state,formRef,builderContext) === 'error' && state.responseData",
|
|
619
|
-
},
|
|
620
|
-
},
|
|
621
|
-
children: [
|
|
622
|
-
{
|
|
623
|
-
"@type": "@builder.io/mitosis/node",
|
|
624
|
-
name: "div",
|
|
625
|
-
meta: {},
|
|
626
|
-
scope: {},
|
|
627
|
-
properties: {
|
|
628
|
-
_text: "\n ",
|
|
629
|
-
},
|
|
630
|
-
bindings: {},
|
|
631
|
-
children: [],
|
|
632
|
-
},
|
|
633
|
-
{
|
|
634
|
-
"@type": "@builder.io/mitosis/node",
|
|
635
|
-
name: "pre",
|
|
636
|
-
meta: {},
|
|
637
|
-
scope: {},
|
|
638
|
-
properties: {
|
|
639
|
-
class: "builder-form-error-text pre-FormComponent",
|
|
640
|
-
},
|
|
641
|
-
bindings: {},
|
|
642
|
-
children: [
|
|
643
|
-
{
|
|
644
|
-
"@type": "@builder.io/mitosis/node",
|
|
645
|
-
name: "div",
|
|
646
|
-
meta: {},
|
|
647
|
-
scope: {},
|
|
648
|
-
properties: {
|
|
649
|
-
_text: "\n ",
|
|
650
|
-
},
|
|
651
|
-
bindings: {},
|
|
652
|
-
children: [],
|
|
653
|
-
},
|
|
654
|
-
{
|
|
655
|
-
"@type": "@builder.io/mitosis/node",
|
|
656
|
-
name: "div",
|
|
657
|
-
meta: {},
|
|
658
|
-
scope: {},
|
|
659
|
-
properties: {},
|
|
660
|
-
bindings: {
|
|
661
|
-
_text: {
|
|
662
|
-
code: "JSON.stringify(state.responseData, null, 2)",
|
|
663
|
-
},
|
|
664
|
-
},
|
|
665
|
-
children: [],
|
|
666
|
-
},
|
|
667
|
-
{
|
|
668
|
-
"@type": "@builder.io/mitosis/node",
|
|
669
|
-
name: "div",
|
|
670
|
-
meta: {},
|
|
671
|
-
scope: {},
|
|
672
|
-
properties: {
|
|
673
|
-
_text: "\n ",
|
|
674
|
-
},
|
|
675
|
-
bindings: {},
|
|
676
|
-
children: [],
|
|
677
|
-
},
|
|
678
|
-
],
|
|
679
|
-
},
|
|
680
|
-
{
|
|
681
|
-
"@type": "@builder.io/mitosis/node",
|
|
682
|
-
name: "div",
|
|
683
|
-
meta: {},
|
|
684
|
-
scope: {},
|
|
685
|
-
properties: {
|
|
686
|
-
_text: "\n ",
|
|
687
|
-
},
|
|
688
|
-
bindings: {},
|
|
689
|
-
children: [],
|
|
690
|
-
},
|
|
691
|
-
],
|
|
692
|
-
},
|
|
693
|
-
{
|
|
694
|
-
"@type": "@builder.io/mitosis/node",
|
|
695
|
-
name: "div",
|
|
696
|
-
meta: {},
|
|
697
|
-
scope: {},
|
|
698
|
-
properties: {
|
|
699
|
-
_text: "\n\n ",
|
|
700
|
-
},
|
|
701
|
-
bindings: {},
|
|
702
|
-
children: [],
|
|
703
|
-
},
|
|
704
|
-
{
|
|
705
|
-
"@type": "@builder.io/mitosis/node",
|
|
706
|
-
name: "Show",
|
|
707
|
-
meta: {},
|
|
708
|
-
scope: {},
|
|
709
|
-
properties: {},
|
|
710
|
-
bindings: {
|
|
711
|
-
when: {
|
|
712
|
-
code: "submissionState(props,state,formRef,builderContext) === 'success'",
|
|
713
|
-
},
|
|
714
|
-
},
|
|
715
|
-
children: [
|
|
716
|
-
{
|
|
717
|
-
"@type": "@builder.io/mitosis/node",
|
|
718
|
-
name: "div",
|
|
719
|
-
meta: {},
|
|
720
|
-
scope: {},
|
|
721
|
-
properties: {
|
|
722
|
-
_text: "\n ",
|
|
723
|
-
},
|
|
724
|
-
bindings: {},
|
|
725
|
-
children: [],
|
|
726
|
-
},
|
|
727
|
-
{
|
|
728
|
-
"@type": "@builder.io/mitosis/node",
|
|
729
|
-
name: "BuilderBlocks",
|
|
730
|
-
meta: {},
|
|
731
|
-
scope: {},
|
|
732
|
-
properties: {
|
|
733
|
-
dataPath: "successMessage",
|
|
734
|
-
},
|
|
735
|
-
bindings: {
|
|
736
|
-
blocks: {
|
|
737
|
-
code: "props.successMessage",
|
|
738
|
-
},
|
|
739
|
-
},
|
|
740
|
-
children: [],
|
|
741
|
-
},
|
|
742
|
-
{
|
|
743
|
-
"@type": "@builder.io/mitosis/node",
|
|
744
|
-
name: "div",
|
|
745
|
-
meta: {},
|
|
746
|
-
scope: {},
|
|
747
|
-
properties: {
|
|
748
|
-
_text: "\n ",
|
|
749
|
-
},
|
|
750
|
-
bindings: {},
|
|
751
|
-
children: [],
|
|
752
|
-
},
|
|
753
|
-
],
|
|
754
|
-
},
|
|
755
|
-
{
|
|
756
|
-
"@type": "@builder.io/mitosis/node",
|
|
757
|
-
name: "div",
|
|
758
|
-
meta: {},
|
|
759
|
-
scope: {},
|
|
760
|
-
properties: {
|
|
761
|
-
_text: "\n ",
|
|
762
|
-
},
|
|
763
|
-
bindings: {},
|
|
764
|
-
children: [],
|
|
765
|
-
},
|
|
766
|
-
],
|
|
767
|
-
},
|
|
768
|
-
],
|
|
769
|
-
hooks: {},
|
|
770
|
-
context: {
|
|
771
|
-
get: {
|
|
772
|
-
builderContext: {
|
|
773
|
-
name: "BuilderContext",
|
|
774
|
-
path: "../../context/builder.context.lite:default",
|
|
775
|
-
},
|
|
776
|
-
},
|
|
777
|
-
set: {},
|
|
778
|
-
},
|
|
779
|
-
name: "FormComponent",
|
|
780
|
-
subComponents: [],
|
|
781
|
-
interfaces: [
|
|
782
|
-
"// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\n/* eslint-disable */\n\n/**\n * This component was copied over from the old SDKs and has a lot of code pointing to invalid functions/env vars. It needs\n * to be cleaned up before the component can actually be usable.\n */\ninterface BuilderElement {}",
|
|
783
|
-
"// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\n/* eslint-disable */\n\n/**\n * This component was copied over from the old SDKs and has a lot of code pointing to invalid functions/env vars. It needs\n * to be cleaned up before the component can actually be usable.\n */\nexport interface FormProps {\n attributes?: any;\n name?: string;\n action?: string;\n validate?: boolean;\n method?: string;\n builderBlock?: BuilderElement;\n sendSubmissionsTo?: string;\n sendSubmissionsToEmail?: string;\n sendWithJs?: boolean;\n contentType?: string;\n customHeaders?: {\n [key: string]: string;\n };\n successUrl?: string;\n previewState?: FormState;\n successMessage?: BuilderElement[];\n errorMessage?: BuilderElement[];\n sendingMessage?: BuilderElement[];\n resetFormOnSubmit?: boolean;\n errorMessagePath?: string;\n}",
|
|
784
|
-
],
|
|
785
|
-
types: [
|
|
786
|
-
"// eslint-disable-next-line @typescript-eslint/ban-ts-comment\n// @ts-nocheck\n\n/* eslint-disable */\n\n/**\n * This component was copied over from the old SDKs and has a lot of code pointing to invalid functions/env vars. It needs\n * to be cleaned up before the component can actually be usable.\n */\nexport type FormState = 'unsubmitted' | 'sending' | 'success' | 'error';",
|
|
787
|
-
],
|
|
788
|
-
propsTypeRef: "FormProps",
|
|
789
|
-
};
|