@functionalcms/svelte-components 4.25.0 → 4.26.0

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.
@@ -4,7 +4,7 @@
4
4
  import { fade } from 'svelte/transition';
5
5
 
6
6
  interface Props {
7
- action: string;
7
+ action?: string;
8
8
  css?: string;
9
9
  successMessage?: string;
10
10
  submitButonText?: string;
@@ -17,8 +17,8 @@
17
17
  fields = [],
18
18
  css = '',
19
19
  submitButonText = 'Submit',
20
- successMessage = 'Your message has been delivered',
21
- onMessageSubmitted = (result: SubmitResult) => {},
20
+ successMessage,
21
+ onMessageSubmitted,
22
22
  }: Props = $props();
23
23
 
24
24
  let form: any;
@@ -27,13 +27,15 @@
27
27
 
28
28
  const submitContactForm = async (event: Event) => {
29
29
  try {
30
+ debugger
30
31
  if (isSendingMessage) {
31
32
  return;
32
33
  }
33
34
  isSendingMessage = true;
34
35
  event.preventDefault();
35
36
  const formData = new FormData(form);
36
- const response = await fetch(action, {
37
+ const formAction = action || window.location.pathname;
38
+ const response = await fetch(formAction, {
37
39
  method: 'POST',
38
40
  body: formData
39
41
  });
@@ -1,6 +1,6 @@
1
1
  import { type Field, SubmitResult } from './form.js';
2
2
  interface Props {
3
- action: string;
3
+ action?: string;
4
4
  css?: string;
5
5
  successMessage?: string;
6
6
  submitButonText?: string;
@@ -43,3 +43,4 @@ export declare enum SubmitResult {
43
43
  Success = "success",
44
44
  Error = "error"
45
45
  }
46
+ export declare const readForm: (request: Request, fields: Array<Field>) => Promise<any>;
@@ -33,3 +33,11 @@ export var SubmitResult;
33
33
  SubmitResult["Success"] = "success";
34
34
  SubmitResult["Error"] = "error";
35
35
  })(SubmitResult || (SubmitResult = {}));
36
+ export const readForm = async (request, fields) => {
37
+ const formData = await request.formData();
38
+ let response = {};
39
+ fields.forEach(field => {
40
+ response[field.name] = formData.get(field.name);
41
+ });
42
+ return response;
43
+ };
package/dist/index.d.ts CHANGED
@@ -29,7 +29,7 @@ export { default as Button } from './components/form/Button.svelte';
29
29
  export { default as Input } from './components/form/Input.svelte';
30
30
  export { default as Switch } from './components/form/Switch.svelte';
31
31
  export { default as ChoiceInput } from './components/form/ChoiceInput.svelte';
32
- export { InputType, FieldType, LabelSize, type Field, SubmitResult } from './components/form/form.js';
32
+ export { InputType, FieldType, LabelSize, type Field, SubmitResult, readForm } from './components/form/form.js';
33
33
  export { default as AntiBot } from './components/form/AntiBot.svelte';
34
34
  export { default as Dropzone } from './components/form/Dropzone.svelte';
35
35
  export { default as Select } from './components/form/Select.svelte';
package/dist/index.js CHANGED
@@ -42,7 +42,7 @@ export { default as Button } from './components/form/Button.svelte';
42
42
  export { default as Input } from './components/form/Input.svelte';
43
43
  export { default as Switch } from './components/form/Switch.svelte';
44
44
  export { default as ChoiceInput } from './components/form/ChoiceInput.svelte';
45
- export { InputType, FieldType, LabelSize, SubmitResult } from './components/form/form.js';
45
+ export { InputType, FieldType, LabelSize, SubmitResult, readForm } from './components/form/form.js';
46
46
  export { default as AntiBot } from './components/form/AntiBot.svelte';
47
47
  export { default as Dropzone } from './components/form/Dropzone.svelte';
48
48
  export { default as Select } from './components/form/Select.svelte';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@functionalcms/svelte-components",
3
- "version": "4.25.0",
3
+ "version": "4.26.0",
4
4
  "license": "MIT",
5
5
  "watch": {
6
6
  "build": {