@builder.io/sdk-qwik 0.0.9 → 0.0.10

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.
@@ -9,78 +9,3 @@ export const BuilderBlocks = component$((props) => {
9
9
  );
10
10
  });
11
11
  export default BuilderBlocks;
12
- export const COMPONENT = {
13
- "@type": "@builder.io/mitosis/component",
14
- imports: [],
15
- exports: {},
16
- inputs: [],
17
- meta: {},
18
- refs: {},
19
- state: {},
20
- children: [
21
- {
22
- "@type": "@builder.io/mitosis/node",
23
- name: "Fragment",
24
- meta: {},
25
- scope: {},
26
- properties: {},
27
- bindings: {},
28
- children: [
29
- {
30
- "@type": "@builder.io/mitosis/node",
31
- name: "div",
32
- meta: {},
33
- scope: {},
34
- properties: {
35
- _text: "\n NOT YET IMPLEMENTED: ",
36
- },
37
- bindings: {},
38
- children: [],
39
- },
40
- {
41
- "@type": "@builder.io/mitosis/node",
42
- name: "code",
43
- meta: {},
44
- scope: {},
45
- properties: {},
46
- bindings: {},
47
- children: [
48
- {
49
- "@type": "@builder.io/mitosis/node",
50
- name: "div",
51
- meta: {},
52
- scope: {},
53
- properties: {
54
- _text: "BuilderBlocks",
55
- },
56
- bindings: {},
57
- children: [],
58
- },
59
- ],
60
- },
61
- {
62
- "@type": "@builder.io/mitosis/node",
63
- name: "div",
64
- meta: {},
65
- scope: {},
66
- properties: {
67
- _text: "\n ",
68
- },
69
- bindings: {},
70
- children: [],
71
- },
72
- ],
73
- },
74
- ],
75
- hooks: {},
76
- context: {
77
- get: {},
78
- set: {},
79
- },
80
- name: "BuilderBlocks",
81
- subComponents: [],
82
- interfaces: [
83
- "export interface BuilderBlocksProps {\n dataPath: string;\n blocks: any;\n}",
84
- ],
85
- propsTypeRef: "BuilderBlocksProps",
86
- };
@@ -5,7 +5,6 @@ import { isEditing } from "../../functions/is-editing.js";
5
5
  import BuilderBlocks from "./builder-blocks";
6
6
  import {
7
7
  Fragment,
8
- Host,
9
8
  component$,
10
9
  h,
11
10
  useContext,
@@ -240,543 +239,65 @@ export const onSubmit = function onSubmit(
240
239
  );
241
240
  }
242
241
  };
243
- export const FormComponent = component$(
244
- (props) => {
245
- useStylesScoped$(STYLES);
246
- const builderContext = useContext(BuilderContext);
247
- const formRef = useRef();
248
- const state = useStore({
249
- formState: "unsubmitted",
250
- responseData: null,
251
- formErrorMessage: "",
252
- });
253
- return (
254
- <Host
255
- validate={props.validate}
256
- ref={formRef}
257
- action={(() => {
258
- !props.sendWithJs && props.action;
259
- })()}
260
- method={props.method}
261
- name={props.name}
262
- onSubmit$={(event) =>
263
- onSubmit(props, state, formRef, builderContext, event)
264
- }
265
- {...props.attributes}
266
- >
267
- <>
268
- {props.builderBlock && props.builderBlock.children
269
- ? (props.builderBlock?.children || []).map((block) => {
270
- return (
271
- <RenderBlock
272
- block={block}
273
- context={builderContext}
274
- ></RenderBlock>
275
- );
276
- })
277
- : null}
278
- {submissionState(props, state, formRef, builderContext) ===
279
- "error" ? (
280
- <BuilderBlocks
281
- dataPath="errorMessage"
282
- blocks={props.errorMessage}
283
- ></BuilderBlocks>
284
- ) : null}
285
- {submissionState(props, state, formRef, builderContext) ===
286
- "sending" ? (
287
- <BuilderBlocks
288
- dataPath="sendingMessage"
289
- blocks={props.sendingMessage}
290
- ></BuilderBlocks>
291
- ) : null}
292
- {submissionState(props, state, formRef, builderContext) === "error" &&
293
- state.responseData ? (
294
- <pre class="builder-form-error-text pre-FormComponent">
295
- {JSON.stringify(state.responseData, null, 2)}
296
- </pre>
297
- ) : null}
298
- {submissionState(props, state, formRef, builderContext) ===
299
- "success" ? (
300
- <BuilderBlocks
301
- dataPath="successMessage"
302
- blocks={props.successMessage}
303
- ></BuilderBlocks>
304
- ) : null}
305
- </>
306
- </Host>
307
- );
308
- },
309
- { tagName: "form" }
310
- );
242
+ export const FormComponent = component$((props) => {
243
+ useStylesScoped$(STYLES);
244
+ const builderContext = useContext(BuilderContext);
245
+ const formRef = useRef();
246
+ const state = useStore({
247
+ formState: "unsubmitted",
248
+ responseData: null,
249
+ formErrorMessage: "",
250
+ });
251
+ return (
252
+ <form
253
+ validate={props.validate}
254
+ ref={formRef}
255
+ action={(() => {
256
+ !props.sendWithJs && props.action;
257
+ })()}
258
+ method={props.method}
259
+ name={props.name}
260
+ onSubmit$={(event) =>
261
+ onSubmit(props, state, formRef, builderContext, event)
262
+ }
263
+ {...props.attributes}
264
+ >
265
+ {props.builderBlock && props.builderBlock.children
266
+ ? (props.builderBlock?.children || []).map((block) => {
267
+ return (
268
+ <RenderBlock block={block} context={builderContext}></RenderBlock>
269
+ );
270
+ })
271
+ : null}
272
+ {submissionState(props, state, formRef, builderContext) === "error" ? (
273
+ <BuilderBlocks
274
+ dataPath="errorMessage"
275
+ blocks={props.errorMessage}
276
+ ></BuilderBlocks>
277
+ ) : null}
278
+ {submissionState(props, state, formRef, builderContext) === "sending" ? (
279
+ <BuilderBlocks
280
+ dataPath="sendingMessage"
281
+ blocks={props.sendingMessage}
282
+ ></BuilderBlocks>
283
+ ) : null}
284
+ {submissionState(props, state, formRef, builderContext) === "error" &&
285
+ state.responseData ? (
286
+ <pre class="builder-form-error-text pre-FormComponent">
287
+ {JSON.stringify(state.responseData, null, 2)}
288
+ </pre>
289
+ ) : null}
290
+ {submissionState(props, state, formRef, builderContext) === "success" ? (
291
+ <BuilderBlocks
292
+ dataPath="successMessage"
293
+ blocks={props.successMessage}
294
+ ></BuilderBlocks>
295
+ ) : null}
296
+ </form>
297
+ );
298
+ });
311
299
  export default FormComponent;
312
300
  export const STYLES = `.pre-FormComponent {
313
301
  padding: 10px;
314
302
  color: red;
315
303
  text-align: center; }`;
316
- export const COMPONENT = {
317
- "@type": "@builder.io/mitosis/component",
318
- imports: [
319
- {
320
- imports: {
321
- RenderBlock: "default",
322
- },
323
- path: "../../components/render-block/render-block.lite",
324
- },
325
- {
326
- imports: {
327
- isEditing: "isEditing",
328
- },
329
- path: "../../functions/is-editing.js",
330
- },
331
- {
332
- imports: {
333
- BuilderBlocks: "default",
334
- },
335
- path: "./builder-blocks.lite",
336
- },
337
- ],
338
- exports: {},
339
- inputs: [],
340
- meta: {},
341
- refs: {
342
- formRef: {
343
- argument: "",
344
- },
345
- },
346
- state: {
347
- formState: "unsubmitted",
348
- responseData: null,
349
- formErrorMessage: "",
350
- submissionState:
351
- "@builder.io/mitosis/method:get submissionState() {\n return isEditing() && props.previewState || state.formState;\n}",
352
- onSubmit:
353
- "@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}",
354
- },
355
- children: [
356
- {
357
- "@type": "@builder.io/mitosis/node",
358
- name: "Host",
359
- meta: {},
360
- scope: {},
361
- properties: {},
362
- bindings: {
363
- validate: {
364
- code: "props.validate",
365
- },
366
- ref: {
367
- code: "formRef",
368
- },
369
- action: {
370
- code: "!props.sendWithJs && props.action",
371
- },
372
- method: {
373
- code: "props.method",
374
- },
375
- name: {
376
- code: "props.name",
377
- },
378
- onSubmit: {
379
- code: "onSubmit(props,state,formRef,builderContext,event)",
380
- arguments: ["event"],
381
- },
382
- _spread: {
383
- code: "props.attributes",
384
- },
385
- },
386
- children: [
387
- {
388
- "@type": "@builder.io/mitosis/node",
389
- name: "div",
390
- meta: {},
391
- scope: {},
392
- properties: {
393
- _text: "\n ",
394
- },
395
- bindings: {},
396
- children: [],
397
- },
398
- {
399
- "@type": "@builder.io/mitosis/node",
400
- name: "Show",
401
- meta: {},
402
- scope: {},
403
- properties: {},
404
- bindings: {
405
- when: {
406
- code: "props.builderBlock && props.builderBlock.children",
407
- },
408
- },
409
- children: [
410
- {
411
- "@type": "@builder.io/mitosis/node",
412
- name: "div",
413
- meta: {},
414
- scope: {},
415
- properties: {
416
- _text: "\n ",
417
- },
418
- bindings: {},
419
- children: [],
420
- },
421
- {
422
- "@type": "@builder.io/mitosis/node",
423
- name: "For",
424
- meta: {},
425
- scope: {
426
- For: ["block"],
427
- },
428
- properties: {
429
- _forName: "block",
430
- },
431
- bindings: {
432
- each: {
433
- code: "props.builderBlock?.children",
434
- },
435
- },
436
- children: [
437
- {
438
- "@type": "@builder.io/mitosis/node",
439
- name: "RenderBlock",
440
- meta: {},
441
- scope: {},
442
- properties: {},
443
- bindings: {
444
- block: {
445
- code: "block",
446
- },
447
- context: {
448
- code: "builderContext",
449
- },
450
- },
451
- children: [],
452
- },
453
- ],
454
- },
455
- {
456
- "@type": "@builder.io/mitosis/node",
457
- name: "div",
458
- meta: {},
459
- scope: {},
460
- properties: {
461
- _text: "\n ",
462
- },
463
- bindings: {},
464
- children: [],
465
- },
466
- ],
467
- },
468
- {
469
- "@type": "@builder.io/mitosis/node",
470
- name: "div",
471
- meta: {},
472
- scope: {},
473
- properties: {
474
- _text: "\n\n ",
475
- },
476
- bindings: {},
477
- children: [],
478
- },
479
- {
480
- "@type": "@builder.io/mitosis/node",
481
- name: "Show",
482
- meta: {},
483
- scope: {},
484
- properties: {},
485
- bindings: {
486
- when: {
487
- code: "submissionState(props,state,formRef,builderContext) === 'error'",
488
- },
489
- },
490
- children: [
491
- {
492
- "@type": "@builder.io/mitosis/node",
493
- name: "div",
494
- meta: {},
495
- scope: {},
496
- properties: {
497
- _text: "\n ",
498
- },
499
- bindings: {},
500
- children: [],
501
- },
502
- {
503
- "@type": "@builder.io/mitosis/node",
504
- name: "BuilderBlocks",
505
- meta: {},
506
- scope: {},
507
- properties: {
508
- dataPath: "errorMessage",
509
- },
510
- bindings: {
511
- blocks: {
512
- code: "props.errorMessage",
513
- },
514
- },
515
- children: [],
516
- },
517
- {
518
- "@type": "@builder.io/mitosis/node",
519
- name: "div",
520
- meta: {},
521
- scope: {},
522
- properties: {
523
- _text: "\n ",
524
- },
525
- bindings: {},
526
- children: [],
527
- },
528
- ],
529
- },
530
- {
531
- "@type": "@builder.io/mitosis/node",
532
- name: "div",
533
- meta: {},
534
- scope: {},
535
- properties: {
536
- _text: "\n\n ",
537
- },
538
- bindings: {},
539
- children: [],
540
- },
541
- {
542
- "@type": "@builder.io/mitosis/node",
543
- name: "Show",
544
- meta: {},
545
- scope: {},
546
- properties: {},
547
- bindings: {
548
- when: {
549
- code: "submissionState(props,state,formRef,builderContext) === 'sending'",
550
- },
551
- },
552
- children: [
553
- {
554
- "@type": "@builder.io/mitosis/node",
555
- name: "div",
556
- meta: {},
557
- scope: {},
558
- properties: {
559
- _text: "\n ",
560
- },
561
- bindings: {},
562
- children: [],
563
- },
564
- {
565
- "@type": "@builder.io/mitosis/node",
566
- name: "BuilderBlocks",
567
- meta: {},
568
- scope: {},
569
- properties: {
570
- dataPath: "sendingMessage",
571
- },
572
- bindings: {
573
- blocks: {
574
- code: "props.sendingMessage",
575
- },
576
- },
577
- children: [],
578
- },
579
- {
580
- "@type": "@builder.io/mitosis/node",
581
- name: "div",
582
- meta: {},
583
- scope: {},
584
- properties: {
585
- _text: "\n ",
586
- },
587
- bindings: {},
588
- children: [],
589
- },
590
- ],
591
- },
592
- {
593
- "@type": "@builder.io/mitosis/node",
594
- name: "div",
595
- meta: {},
596
- scope: {},
597
- properties: {
598
- _text: "\n\n ",
599
- },
600
- bindings: {},
601
- children: [],
602
- },
603
- {
604
- "@type": "@builder.io/mitosis/node",
605
- name: "Show",
606
- meta: {},
607
- scope: {},
608
- properties: {},
609
- bindings: {
610
- when: {
611
- code: "submissionState(props,state,formRef,builderContext) === 'error' && state.responseData",
612
- },
613
- },
614
- children: [
615
- {
616
- "@type": "@builder.io/mitosis/node",
617
- name: "div",
618
- meta: {},
619
- scope: {},
620
- properties: {
621
- _text: "\n ",
622
- },
623
- bindings: {},
624
- children: [],
625
- },
626
- {
627
- "@type": "@builder.io/mitosis/node",
628
- name: "pre",
629
- meta: {},
630
- scope: {},
631
- properties: {
632
- class: "builder-form-error-text pre-FormComponent",
633
- },
634
- bindings: {},
635
- children: [
636
- {
637
- "@type": "@builder.io/mitosis/node",
638
- name: "div",
639
- meta: {},
640
- scope: {},
641
- properties: {
642
- _text: "\n ",
643
- },
644
- bindings: {},
645
- children: [],
646
- },
647
- {
648
- "@type": "@builder.io/mitosis/node",
649
- name: "div",
650
- meta: {},
651
- scope: {},
652
- properties: {},
653
- bindings: {
654
- _text: {
655
- code: "JSON.stringify(state.responseData, null, 2)",
656
- },
657
- },
658
- children: [],
659
- },
660
- {
661
- "@type": "@builder.io/mitosis/node",
662
- name: "div",
663
- meta: {},
664
- scope: {},
665
- properties: {
666
- _text: "\n ",
667
- },
668
- bindings: {},
669
- children: [],
670
- },
671
- ],
672
- },
673
- {
674
- "@type": "@builder.io/mitosis/node",
675
- name: "div",
676
- meta: {},
677
- scope: {},
678
- properties: {
679
- _text: "\n ",
680
- },
681
- bindings: {},
682
- children: [],
683
- },
684
- ],
685
- },
686
- {
687
- "@type": "@builder.io/mitosis/node",
688
- name: "div",
689
- meta: {},
690
- scope: {},
691
- properties: {
692
- _text: "\n\n ",
693
- },
694
- bindings: {},
695
- children: [],
696
- },
697
- {
698
- "@type": "@builder.io/mitosis/node",
699
- name: "Show",
700
- meta: {},
701
- scope: {},
702
- properties: {},
703
- bindings: {
704
- when: {
705
- code: "submissionState(props,state,formRef,builderContext) === 'success'",
706
- },
707
- },
708
- children: [
709
- {
710
- "@type": "@builder.io/mitosis/node",
711
- name: "div",
712
- meta: {},
713
- scope: {},
714
- properties: {
715
- _text: "\n ",
716
- },
717
- bindings: {},
718
- children: [],
719
- },
720
- {
721
- "@type": "@builder.io/mitosis/node",
722
- name: "BuilderBlocks",
723
- meta: {},
724
- scope: {},
725
- properties: {
726
- dataPath: "successMessage",
727
- },
728
- bindings: {
729
- blocks: {
730
- code: "props.successMessage",
731
- },
732
- },
733
- children: [],
734
- },
735
- {
736
- "@type": "@builder.io/mitosis/node",
737
- name: "div",
738
- meta: {},
739
- scope: {},
740
- properties: {
741
- _text: "\n ",
742
- },
743
- bindings: {},
744
- children: [],
745
- },
746
- ],
747
- },
748
- {
749
- "@type": "@builder.io/mitosis/node",
750
- name: "div",
751
- meta: {},
752
- scope: {},
753
- properties: {
754
- _text: "\n ",
755
- },
756
- bindings: {},
757
- children: [],
758
- },
759
- ],
760
- },
761
- ],
762
- hooks: {},
763
- context: {
764
- get: {
765
- builderContext: {
766
- name: "BuilderContext",
767
- path: null,
768
- },
769
- },
770
- set: {},
771
- },
772
- name: "FormComponent",
773
- subComponents: [],
774
- interfaces: [
775
- "// 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 {}",
776
- "// 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}",
777
- ],
778
- types: [
779
- "// 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';",
780
- ],
781
- propsTypeRef: "FormProps",
782
- };