fuma 0.2.6 → 0.3.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/dist/api/client.d.ts +3 -0
- package/dist/api/client.js +24 -0
- package/dist/api/config.d.ts +46 -0
- package/dist/api/config.js +7 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.js +3 -0
- package/dist/api/server.d.ts +11 -0
- package/dist/api/server.js +17 -0
- package/dist/{Meta.svelte → private/Meta.svelte} +4 -4
- package/dist/private/api.d.ts +61 -0
- package/dist/private/api.js +10 -0
- package/dist/private/constant.d.ts +14 -0
- package/dist/private/constant.js +6 -0
- package/dist/private/model.d.ts +78 -0
- package/dist/private/model.js +25 -0
- package/dist/server/auth.js +1 -1
- package/dist/server/parseFormData.js +21 -1
- package/dist/server/parseQuery.d.ts +1 -10
- package/dist/server/parseQuery.js +4 -5
- package/dist/server/try.js +0 -1
- package/dist/ui/drawer/Drawer.svelte +19 -11
- package/dist/ui/drawer/Drawer.svelte.d.ts +42 -7
- package/dist/ui/drawer/layers.d.ts +2 -1
- package/dist/ui/drawer/layers.js +5 -4
- package/dist/ui/form/Form.svelte +43 -24
- package/dist/ui/form/Form.svelte.d.ts +20 -12
- package/dist/ui/form/FormInput.svelte.d.ts +4 -0
- package/dist/ui/form/form.d.ts +20 -12
- package/dist/ui/form/form.js +34 -26
- package/dist/ui/form/formInput.d.ts +3 -1
- package/dist/ui/input/FormControl.svelte.d.ts +1 -1
- package/dist/ui/input/InputBoolean.svelte +4 -2
- package/dist/ui/input/InputBoolean.svelte.d.ts +2 -2
- package/dist/ui/input/InputCheckboxs.svelte.d.ts +2 -2
- package/dist/ui/input/InputCheckboxsMenu.svelte +5 -5
- package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +2 -2
- package/dist/ui/input/InputCombo.svelte.d.ts +2 -2
- package/dist/ui/input/InputDate.svelte +10 -7
- package/dist/ui/input/InputDate.svelte.d.ts +1 -1
- package/dist/ui/input/InputDatetime.svelte +24 -12
- package/dist/ui/input/InputDatetime.svelte.d.ts +2 -2
- package/dist/ui/input/InputNumber.svelte +12 -11
- package/dist/ui/input/InputNumber.svelte.d.ts +1 -1
- package/dist/ui/input/InputPassword.svelte.d.ts +2 -2
- package/dist/ui/input/InputRadio.svelte.d.ts +2 -2
- package/dist/ui/input/InputRelation.svelte +10 -3
- package/dist/ui/input/InputRelation.svelte.d.ts +2 -0
- package/dist/ui/input/InputRelations.svelte +10 -3
- package/dist/ui/input/InputRelations.svelte.d.ts +2 -0
- package/dist/ui/input/InputSelect.svelte +4 -2
- package/dist/ui/input/InputText.svelte.d.ts +2 -2
- package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +1 -1
- package/dist/ui/input/textRich/extensions.js +1 -1
- package/dist/ui/input/types.d.ts +2 -2
- package/dist/ui/login/Login.svelte +7 -3
- package/dist/ui/table/field.d.ts +1 -1
- package/dist/ui/table/head/TableHeadNumber.svelte +1 -1
- package/dist/utils/constant.d.ts +4 -0
- package/dist/utils/constant.js +4 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.js +1 -0
- package/dist/utils/jsonParse.d.ts +1 -1
- package/dist/utils/jsonParse.js +5 -3
- package/dist/utils/options.d.ts +2 -1
- package/dist/validation/form.d.ts +6 -5
- package/dist/validation/form.js +8 -8
- package/dist/validation/zod.d.ts +109 -55
- package/dist/validation/zod.js +11 -31
- package/package.json +13 -3
- /package/dist/{Meta.svelte.d.ts → private/Meta.svelte.d.ts} +0 -0
- /package/dist/{server → private}/prisma.d.ts +0 -0
- /package/dist/{server → private}/prisma.js +0 -0
|
@@ -1,24 +1,25 @@
|
|
|
1
|
-
<script>import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
export let value = _value;
|
|
1
|
+
<script>import { USE_COERCE_NUMBER } from "../../utils/constant.js";
|
|
2
|
+
import { FormControl } from "./index.js";
|
|
3
|
+
export let value = void 0;
|
|
4
|
+
export let input = void 0;
|
|
5
|
+
export let inputElement = void 0;
|
|
7
6
|
</script>
|
|
8
7
|
|
|
9
|
-
<FormControl {
|
|
8
|
+
<FormControl {...$$restProps} let:key>
|
|
10
9
|
<slot name="label_append" slot="label_append" />
|
|
11
10
|
<input
|
|
12
11
|
bind:value
|
|
13
|
-
bind:this={
|
|
12
|
+
bind:this={inputElement}
|
|
14
13
|
on:input
|
|
15
14
|
on:focus
|
|
16
15
|
on:blur
|
|
17
16
|
type="number"
|
|
18
|
-
name={key}
|
|
19
17
|
id={key}
|
|
20
18
|
inputmode="numeric"
|
|
21
|
-
class="input input-bordered
|
|
22
|
-
{...
|
|
19
|
+
class="input input-bordered"
|
|
20
|
+
{...input}
|
|
23
21
|
/>
|
|
22
|
+
{#if value !== undefined}
|
|
23
|
+
<input type="hidden" name={key} value="{USE_COERCE_NUMBER}{value}" />
|
|
24
|
+
{/if}
|
|
24
25
|
</FormControl>
|
|
@@ -10,12 +10,12 @@ declare const __propDef: {
|
|
|
10
10
|
prefix?: string | number | undefined;
|
|
11
11
|
prefixFor?: string | number | undefined;
|
|
12
12
|
enhanceDisabled?: boolean | undefined;
|
|
13
|
-
labelPosition?: ("top" | "
|
|
13
|
+
labelPosition?: ("top" | "left" | "right") | undefined;
|
|
14
14
|
} & {
|
|
15
15
|
input?: import("svelte/elements.js").HTMLInputAttributes | undefined;
|
|
16
16
|
inputElement?: HTMLInputElement | undefined;
|
|
17
17
|
wrapperClass?: string | undefined;
|
|
18
|
-
value?: string | undefined;
|
|
18
|
+
value?: string | null | undefined;
|
|
19
19
|
bindWithParams?: boolean | undefined;
|
|
20
20
|
} & {
|
|
21
21
|
autocomplete?: string | undefined;
|
|
@@ -11,12 +11,12 @@ declare const __propDef: {
|
|
|
11
11
|
prefix?: string | number | undefined;
|
|
12
12
|
prefixFor?: string | number | undefined;
|
|
13
13
|
enhanceDisabled?: boolean | undefined;
|
|
14
|
-
labelPosition?: ("top" | "
|
|
14
|
+
labelPosition?: ("top" | "left" | "right") | undefined;
|
|
15
15
|
} & {
|
|
16
16
|
input?: import("svelte/elements.js").HTMLInputAttributes | undefined;
|
|
17
17
|
inputElement?: HTMLInputElement | undefined;
|
|
18
18
|
wrapperClass?: string | undefined;
|
|
19
|
-
value?: string | undefined;
|
|
19
|
+
value?: string | null | undefined;
|
|
20
20
|
bindWithParams?: boolean | undefined;
|
|
21
21
|
} & {
|
|
22
22
|
options: Options;
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
import debounce from "debounce";
|
|
3
3
|
import { toast } from "svelte-sonner";
|
|
4
4
|
import { mdiClose } from "@mdi/js";
|
|
5
|
+
import { USE_COERCE_JSON } from "../../utils/constant.js";
|
|
5
6
|
import { Icon } from "../icon/index.js";
|
|
6
7
|
import { Slot } from "../slot/index.js";
|
|
7
8
|
import { DropDown } from "../menu/index.js";
|
|
@@ -21,6 +22,7 @@ export let tippyProps = {};
|
|
|
21
22
|
export let flatMode = false;
|
|
22
23
|
export let slotItem = null;
|
|
23
24
|
export let slotSuggestion = slotItem;
|
|
25
|
+
export let input = void 0;
|
|
24
26
|
let klass = "";
|
|
25
27
|
export { klass as class };
|
|
26
28
|
export let classList = "";
|
|
@@ -71,7 +73,6 @@ async function handleBlur() {
|
|
|
71
73
|
<div class="input input-bordered flex grow items-center pr-2">
|
|
72
74
|
<input
|
|
73
75
|
type="text"
|
|
74
|
-
name={key}
|
|
75
76
|
id={key}
|
|
76
77
|
bind:this={inputElement}
|
|
77
78
|
bind:value={searchValue}
|
|
@@ -81,6 +82,8 @@ async function handleBlur() {
|
|
|
81
82
|
autocomplete="off"
|
|
82
83
|
{placeholder}
|
|
83
84
|
class="grow"
|
|
85
|
+
size={8}
|
|
86
|
+
{...input}
|
|
84
87
|
/>
|
|
85
88
|
|
|
86
89
|
<RelationAfter {isLoading} {createUrl} {createTitle} {createIcon} />
|
|
@@ -101,7 +104,11 @@ async function handleBlur() {
|
|
|
101
104
|
<Icon path={mdiClose} />
|
|
102
105
|
</button>
|
|
103
106
|
</div>
|
|
104
|
-
<input
|
|
107
|
+
<input
|
|
108
|
+
type="hidden"
|
|
109
|
+
name={key}
|
|
110
|
+
value="{USE_COERCE_JSON}{JSON.stringify({ id: item.id })}"
|
|
111
|
+
/>
|
|
105
112
|
{/if}
|
|
106
113
|
</FormControl>
|
|
107
114
|
</div>
|
|
@@ -113,7 +120,7 @@ async function handleBlur() {
|
|
|
113
120
|
{isLoading}
|
|
114
121
|
{focusIndex}
|
|
115
122
|
let:index
|
|
116
|
-
class="w-full {classList}"
|
|
123
|
+
class="w-full min-w-40 {classList}"
|
|
117
124
|
on:select={({ detail }) => select(detail)}
|
|
118
125
|
>
|
|
119
126
|
<slot name="suggestion" item={proposedItems[index]}>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
2
3
|
import type { TippyProps } from '../../utils/tippy.js';
|
|
3
4
|
import type { ComponentAndProps } from '../../utils/component.js';
|
|
4
5
|
declare class __sveltets_Render<RelationItem extends {
|
|
@@ -18,6 +19,7 @@ declare class __sveltets_Render<RelationItem extends {
|
|
|
18
19
|
flatMode?: boolean | undefined;
|
|
19
20
|
slotItem?: ((item: RelationItem) => string | ComponentAndProps) | null | undefined;
|
|
20
21
|
slotSuggestion?: ((item: RelationItem) => string | ComponentAndProps) | null | undefined;
|
|
22
|
+
input?: HTMLInputAttributes | undefined;
|
|
21
23
|
class?: string | undefined;
|
|
22
24
|
classList?: string | undefined;
|
|
23
25
|
clear?: (() => Promise<void>) | undefined;
|
|
@@ -3,6 +3,7 @@ import { slide } from "svelte/transition";
|
|
|
3
3
|
import { toast } from "svelte-sonner";
|
|
4
4
|
import { mdiClose } from "@mdi/js";
|
|
5
5
|
import debounce from "debounce";
|
|
6
|
+
import { USE_COERCE_JSON } from "../../utils/constant.js";
|
|
6
7
|
import { Icon } from "../icon/index.js";
|
|
7
8
|
import { Slot } from "../slot/index.js";
|
|
8
9
|
import { FormControl, SelectorList } from "./index.js";
|
|
@@ -19,6 +20,7 @@ export let placeholder = "";
|
|
|
19
20
|
export let flatMode = false;
|
|
20
21
|
export let slotItem = null;
|
|
21
22
|
export let slotSuggestion = slotItem;
|
|
23
|
+
export let input = void 0;
|
|
22
24
|
let klass = "";
|
|
23
25
|
export { klass as class };
|
|
24
26
|
export let classList = "";
|
|
@@ -111,7 +113,6 @@ async function handleBlur() {
|
|
|
111
113
|
<input
|
|
112
114
|
type="text"
|
|
113
115
|
id={key}
|
|
114
|
-
name={key}
|
|
115
116
|
bind:this={inputSearch}
|
|
116
117
|
bind:value={searchValue}
|
|
117
118
|
on:input={(e) => searchItemsDebounce(e.currentTarget.value)}
|
|
@@ -120,6 +121,8 @@ async function handleBlur() {
|
|
|
120
121
|
autocomplete="off"
|
|
121
122
|
{placeholder}
|
|
122
123
|
class="grow"
|
|
124
|
+
size={8}
|
|
125
|
+
{...input}
|
|
123
126
|
/>
|
|
124
127
|
|
|
125
128
|
<RelationAfter {isLoading} {createUrl} {createTitle} {createIcon} />
|
|
@@ -128,7 +131,11 @@ async function handleBlur() {
|
|
|
128
131
|
</div>
|
|
129
132
|
</div>
|
|
130
133
|
|
|
131
|
-
<input
|
|
134
|
+
<input
|
|
135
|
+
type="hidden"
|
|
136
|
+
name={key}
|
|
137
|
+
value="{USE_COERCE_JSON}{JSON.stringify(items?.map(({ id }) => ({ id })) || [])}"
|
|
138
|
+
/>
|
|
132
139
|
</FormControl>
|
|
133
140
|
</div>
|
|
134
141
|
|
|
@@ -139,7 +146,7 @@ async function handleBlur() {
|
|
|
139
146
|
{isLoading}
|
|
140
147
|
{focusIndex}
|
|
141
148
|
let:index
|
|
142
|
-
class="w-full {classList}"
|
|
149
|
+
class="w-full min-w-40 {classList}"
|
|
143
150
|
on:select={({ detail }) => select(detail)}
|
|
144
151
|
>
|
|
145
152
|
<slot name="suggestion" item={proposedItems[index]}>
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
|
+
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
2
3
|
import type { ComponentAndProps } from '../../utils/component.js';
|
|
3
4
|
declare class __sveltets_Render<RelationItem extends {
|
|
4
5
|
id: string;
|
|
@@ -15,6 +16,7 @@ declare class __sveltets_Render<RelationItem extends {
|
|
|
15
16
|
flatMode?: boolean | undefined;
|
|
16
17
|
slotItem?: ((item: RelationItem) => string | ComponentAndProps) | null | undefined;
|
|
17
18
|
slotSuggestion?: ((item: RelationItem) => string | ComponentAndProps) | null | undefined;
|
|
19
|
+
input?: HTMLInputAttributes | undefined;
|
|
18
20
|
class?: string | undefined;
|
|
19
21
|
classList?: string | undefined;
|
|
20
22
|
value?: RelationItem[] | null | undefined;
|
|
@@ -34,7 +34,7 @@ function onSelect(index) {
|
|
|
34
34
|
bind:this={button}
|
|
35
35
|
id={key}
|
|
36
36
|
type="button"
|
|
37
|
-
class="flex h-12 items-center gap-2 rounded-lg border pl-4 pr-2"
|
|
37
|
+
class="input-bordered flex h-12 items-center gap-2 rounded-lg border pl-4 pr-2 hover:bg-base-200/50"
|
|
38
38
|
>
|
|
39
39
|
{#if selectedOption}
|
|
40
40
|
{#if selectedOption.icon}
|
|
@@ -46,7 +46,9 @@ function onSelect(index) {
|
|
|
46
46
|
{/if}
|
|
47
47
|
<Icon class="ml-auto" path={mdiUnfoldMoreHorizontal} size={18} />
|
|
48
48
|
</button>
|
|
49
|
-
|
|
49
|
+
{#if value !== undefined}
|
|
50
|
+
<input type="hidden" name={key} {value} />
|
|
51
|
+
{/if}
|
|
50
52
|
</FormControl>
|
|
51
53
|
</svelte:fragment>
|
|
52
54
|
|
|
@@ -10,7 +10,7 @@ declare const __propDef: {
|
|
|
10
10
|
prefix?: string | number | undefined;
|
|
11
11
|
prefixFor?: string | number | undefined;
|
|
12
12
|
enhanceDisabled?: boolean | undefined;
|
|
13
|
-
labelPosition?: ("top" | "
|
|
13
|
+
labelPosition?: ("top" | "left" | "right") | undefined;
|
|
14
14
|
} & {
|
|
15
15
|
value?: string | undefined;
|
|
16
16
|
classToolbar?: string | undefined;
|
package/dist/ui/input/types.d.ts
CHANGED
|
@@ -5,11 +5,11 @@ export type InputProps<T = string> = ComponentProps<FormControl> & {
|
|
|
5
5
|
input?: HTMLInputAttributes;
|
|
6
6
|
inputElement?: HTMLInputElement;
|
|
7
7
|
wrapperClass?: string;
|
|
8
|
-
value?: T;
|
|
8
|
+
value?: T | null;
|
|
9
9
|
bindWithParams?: boolean;
|
|
10
10
|
};
|
|
11
11
|
export type TextareaProps = ComponentProps<FormControl> & {
|
|
12
12
|
textarea?: HTMLTextareaAttributes;
|
|
13
|
-
value?: string;
|
|
13
|
+
value?: string | null;
|
|
14
14
|
bindWithParams?: boolean;
|
|
15
15
|
};
|
|
@@ -36,7 +36,7 @@ let recorverDialog;
|
|
|
36
36
|
<span
|
|
37
37
|
role="button"
|
|
38
38
|
tabindex="0"
|
|
39
|
-
class="tab-lg tab grow
|
|
39
|
+
class="tab-lg tab h-10 grow"
|
|
40
40
|
class:tab-active={state === 'login'}
|
|
41
41
|
on:click={() => (state = 'login')}
|
|
42
42
|
on:keyup={() => (state = 'login')}
|
|
@@ -46,7 +46,7 @@ let recorverDialog;
|
|
|
46
46
|
<span
|
|
47
47
|
role="button"
|
|
48
48
|
tabindex="0"
|
|
49
|
-
class="tab-lg tab-
|
|
49
|
+
class="tab-lg tab h-10 grow"
|
|
50
50
|
class:tab-active={state === 'register'}
|
|
51
51
|
on:click={() => (state = 'register')}
|
|
52
52
|
on:keyup={() => (state = 'register')}
|
|
@@ -55,7 +55,11 @@ let recorverDialog;
|
|
|
55
55
|
</span>
|
|
56
56
|
</div>
|
|
57
57
|
|
|
58
|
-
<form
|
|
58
|
+
<form
|
|
59
|
+
class="card-body rounded-b-lg border border-t-0 border-base-300 bg-base-100"
|
|
60
|
+
method="post"
|
|
61
|
+
use:enhance
|
|
62
|
+
>
|
|
59
63
|
<InputText key="username" label="Nom d'utilisateur" input={{ autocomplete: 'username' }} />
|
|
60
64
|
|
|
61
65
|
{#if state === 'register'}
|
package/dist/ui/table/field.d.ts
CHANGED
|
@@ -49,7 +49,7 @@ export declare function syncFieldsWithParams(tablekey: string, fields: TableFiel
|
|
|
49
49
|
$visible: boolean;
|
|
50
50
|
key: string;
|
|
51
51
|
label: string;
|
|
52
|
-
type: "string" | "number" | "boolean" | "
|
|
52
|
+
type: "string" | "number" | "boolean" | "date" | "textarea";
|
|
53
53
|
options?: Options | undefined;
|
|
54
54
|
hint?: string | undefined;
|
|
55
55
|
locked?: boolean | undefined;
|
|
@@ -33,7 +33,7 @@ function handleReset() {
|
|
|
33
33
|
goto($urlParam.without(field.key, "skip", "take"), { noScroll: true, keepFocus: true });
|
|
34
34
|
}
|
|
35
35
|
function isDefined(v) {
|
|
36
|
-
return
|
|
36
|
+
return typeof v === "number";
|
|
37
37
|
}
|
|
38
38
|
$:
|
|
39
39
|
isNegatifRange = isDefined(min) && isDefined(max) && max < min;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const USE_COERCE_JSON = "I_LOVE_YOU_nXFVwk03nRbmhFukfyZLuzkddEd43LXIKs_";
|
|
2
|
+
export declare const USE_COERCE_DATE = "I_LOVE_YOU_TOO_nXFVwk03nRbmhFuskfyZLuzkEd43LXIKs_";
|
|
3
|
+
export declare const USE_COERCE_NUMBER = "HOHO_nXFVwk03nRbmhFukfyZaaLuzkEd43LXIKs_";
|
|
4
|
+
export declare const USE_COERCE_BOOLEAN = "YEP_nXFVwk04nRbmhFukfyZbaLuzkEd43LXIKs_";
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export const USE_COERCE_JSON = 'I_LOVE_YOU_nXFVwk03nRbmhFukfyZLuzkddEd43LXIKs_';
|
|
2
|
+
export const USE_COERCE_DATE = 'I_LOVE_YOU_TOO_nXFVwk03nRbmhFuskfyZLuzkEd43LXIKs_';
|
|
3
|
+
export const USE_COERCE_NUMBER = 'HOHO_nXFVwk03nRbmhFukfyZaaLuzkEd43LXIKs_';
|
|
4
|
+
export const USE_COERCE_BOOLEAN = 'YEP_nXFVwk04nRbmhFukfyZbaLuzkEd43LXIKs_';
|
package/dist/utils/index.d.ts
CHANGED
package/dist/utils/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare function jsonParse<Type>(
|
|
1
|
+
export declare function jsonParse<Type>(content: string | null | undefined | Type, defaultValue: Type): Type;
|
package/dist/utils/jsonParse.js
CHANGED
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
export function jsonParse(
|
|
1
|
+
export function jsonParse(content, defaultValue) {
|
|
2
2
|
try {
|
|
3
|
-
if (!
|
|
3
|
+
if (!content)
|
|
4
4
|
return defaultValue;
|
|
5
|
-
|
|
5
|
+
if (typeof content !== 'string')
|
|
6
|
+
return content;
|
|
7
|
+
return JSON.parse(content);
|
|
6
8
|
}
|
|
7
9
|
catch {
|
|
8
10
|
return defaultValue;
|
package/dist/utils/options.d.ts
CHANGED
|
@@ -3,5 +3,6 @@ export type Option = {
|
|
|
3
3
|
label: string;
|
|
4
4
|
icon?: string;
|
|
5
5
|
};
|
|
6
|
-
export type
|
|
6
|
+
export type OptionRecord<Values extends string> = Record<Values, Omit<Option, 'value'>>;
|
|
7
|
+
export type Options = string | string[] | Option[] | Record<string, string> | OptionRecord<string>;
|
|
7
8
|
export declare function parseOptions(options: Options): Option[];
|
|
@@ -8,14 +8,15 @@ export type FormContext = {
|
|
|
8
8
|
export declare const formContext: {
|
|
9
9
|
get: () => FormContext;
|
|
10
10
|
};
|
|
11
|
+
type MaybePromise<T> = T | Promise<T>;
|
|
11
12
|
type SuccessMessage = false | string | ((action: URL) => string);
|
|
12
13
|
type BooleanOrFunction = boolean | ((action: URL) => boolean);
|
|
13
14
|
export type UseFormOptions<ReturnData> = {
|
|
14
|
-
onSubmit?: (...args: Parameters<SubmitFunction>) => any
|
|
15
|
-
onSuccess?: (action: URL, data?: ReturnData) => any
|
|
15
|
+
onSubmit?: (...args: Parameters<SubmitFunction>) => MaybePromise<any>;
|
|
16
|
+
onSuccess?: (action: URL, data?: ReturnData) => MaybePromise<any>;
|
|
16
17
|
onResetError?: () => unknown;
|
|
17
|
-
onError?: (err: any) => unknown
|
|
18
|
-
onFail?: (failure: Record<string, any> | undefined) => unknown
|
|
18
|
+
onError?: (err: any) => MaybePromise<unknown>;
|
|
19
|
+
onFail?: (failure: Record<string, any> | undefined) => MaybePromise<unknown>;
|
|
19
20
|
successUpdate?: BooleanOrFunction;
|
|
20
21
|
successReset?: BooleanOrFunction;
|
|
21
22
|
successMessage?: SuccessMessage;
|
|
@@ -25,7 +26,7 @@ export declare function useForm<ReturnData extends Record<string, unknown>>({ on
|
|
|
25
26
|
destroy(): void;
|
|
26
27
|
};
|
|
27
28
|
submit: SubmitFunction<ReturnData>;
|
|
28
|
-
resetErrors: () => void
|
|
29
|
+
resetErrors: () => Promise<void>;
|
|
29
30
|
setError(key: string, value: string): void;
|
|
30
31
|
};
|
|
31
32
|
export {};
|
package/dist/validation/form.js
CHANGED
|
@@ -12,7 +12,7 @@ export const formContext = {
|
|
|
12
12
|
};
|
|
13
13
|
export function useForm({ onSubmit, onSuccess, onResetError, onError, onFail, successUpdate = true, successReset = true, successMessage = 'Succès' } = {}) {
|
|
14
14
|
const { setError } = formContext.get();
|
|
15
|
-
function resetErrors() {
|
|
15
|
+
async function resetErrors() {
|
|
16
16
|
for (const key in setError)
|
|
17
17
|
setError[key]('');
|
|
18
18
|
if (onResetError)
|
|
@@ -48,14 +48,14 @@ export function useForm({ onSubmit, onSuccess, onResetError, onError, onFail, su
|
|
|
48
48
|
event.submitter?.classList.remove('btn-disabled');
|
|
49
49
|
if (result.type === 'error') {
|
|
50
50
|
if (onError)
|
|
51
|
-
onError(result.error.message);
|
|
51
|
+
await onError(result.error.message);
|
|
52
52
|
const { message } = result.error;
|
|
53
53
|
toast.error(message || 'Erreur');
|
|
54
54
|
return;
|
|
55
55
|
}
|
|
56
56
|
if (result.type === 'failure') {
|
|
57
57
|
if (onFail)
|
|
58
|
-
onFail(result.data);
|
|
58
|
+
await onFail(result.data);
|
|
59
59
|
if (result.data)
|
|
60
60
|
handleFailure(result.data);
|
|
61
61
|
return;
|
|
@@ -68,18 +68,18 @@ export function useForm({ onSubmit, onSuccess, onResetError, onError, onFail, su
|
|
|
68
68
|
if (result.type === 'success') {
|
|
69
69
|
if (successMessage !== false)
|
|
70
70
|
toast.success(tryToRun(successMessage));
|
|
71
|
-
if (onSuccess)
|
|
72
|
-
onSuccess(action, result.data);
|
|
73
71
|
if (successUpdate)
|
|
74
|
-
update({ reset: tryToRun(successReset) });
|
|
72
|
+
await update({ reset: tryToRun(successReset) });
|
|
73
|
+
if (onSuccess)
|
|
74
|
+
await onSuccess(action, result.data);
|
|
75
75
|
return;
|
|
76
76
|
}
|
|
77
77
|
if (result.type === 'redirect') {
|
|
78
78
|
if (successMessage !== false)
|
|
79
79
|
toast.success(tryToRun(successMessage));
|
|
80
|
+
await goto(result.location, { replaceState: true, invalidateAll: tryToRun(successUpdate) });
|
|
80
81
|
if (onSuccess)
|
|
81
|
-
onSuccess(action);
|
|
82
|
-
return goto(result.location, { replaceState: true, invalidateAll: tryToRun(successUpdate) });
|
|
82
|
+
await onSuccess(action);
|
|
83
83
|
}
|
|
84
84
|
};
|
|
85
85
|
};
|