fuma 0.2.6 → 0.3.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.
- 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 +47 -0
- package/dist/private/api.js +9 -0
- package/dist/private/model.d.ts +40 -0
- package/dist/private/model.js +17 -0
- package/dist/server/auth.js +1 -1
- package/dist/server/parseFormData.js +7 -1
- package/dist/server/parseQuery.d.ts +1 -10
- package/dist/server/parseQuery.js +4 -5
- 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 +39 -24
- package/dist/ui/form/Form.svelte.d.ts +22 -14
- package/dist/ui/form/form.d.ts +20 -12
- package/dist/ui/form/form.js +34 -26
- package/dist/ui/form/formInput.d.ts +1 -1
- package/dist/ui/input/FormControl.svelte.d.ts +1 -1
- 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/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 +7 -2
- package/dist/ui/input/InputRelations.svelte +7 -3
- 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/types.d.ts +2 -2
- package/dist/ui/login/Login.svelte +7 -3
- package/dist/ui/table/field.d.ts +1 -1
- package/dist/utils/constant.d.ts +1 -0
- package/dist/utils/constant.js +1 -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/validation/form.d.ts +6 -5
- package/dist/validation/form.js +8 -8
- package/dist/validation/zod.d.ts +77 -19
- package/dist/validation/zod.js +12 -14
- package/package.json +7 -2
- /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,9 +1,9 @@
|
|
|
1
1
|
import { SvelteComponent } from "svelte";
|
|
2
2
|
import type { z } from 'zod';
|
|
3
|
-
import type {
|
|
4
|
-
import { type FormField, type FormSectionProps } from './form.js';
|
|
3
|
+
import type { FormDataInput } from './form.js';
|
|
4
|
+
import { type FormField, type FormSectionProps, type Nullable } from './form.js';
|
|
5
5
|
import { type UseFormOptions } from '../../validation/form.js';
|
|
6
|
-
declare class __sveltets_Render<Shape extends z.ZodRawShape,
|
|
6
|
+
declare class __sveltets_Render<Shape extends z.ZodRawShape, Data extends FormDataInput<Shape> = FormDataInput<Shape>> {
|
|
7
7
|
props(): {
|
|
8
8
|
class?: string | undefined;
|
|
9
9
|
classSection?: string | undefined;
|
|
@@ -11,27 +11,35 @@ declare class __sveltets_Render<Shape extends z.ZodRawShape, ReturnData extends
|
|
|
11
11
|
model?: Shape | undefined;
|
|
12
12
|
fields?: FormField<Shape>[][] | undefined;
|
|
13
13
|
sections?: FormSectionProps<Shape>[] | undefined;
|
|
14
|
-
data?: Partial<z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]> extends infer T ? { [k in keyof T]: z.objectUtil.addQuestionMarks<z.baseObjectOutputType<Shape>, { [k_1 in keyof z.baseObjectOutputType<Shape>]: undefined extends z.baseObjectOutputType<Shape>[k_1] ? never : k_1; }[keyof Shape]>[k]; } : never> | undefined;
|
|
15
14
|
action?: string | undefined;
|
|
15
|
+
actionCreate?: string | undefined;
|
|
16
16
|
actionDelete?: string | undefined;
|
|
17
|
-
|
|
18
|
-
options?: UseFormOptions<
|
|
19
|
-
|
|
17
|
+
actionUpdate?: string | undefined;
|
|
18
|
+
options?: UseFormOptions<Data> | undefined;
|
|
19
|
+
data?: Nullable<Data> | undefined;
|
|
20
|
+
set?: (<K extends keyof Shape>(key: K, value: Nullable<Data>[K]) => void) | undefined;
|
|
21
|
+
update?: ((updater: (currentData: Nullable<Data>) => Nullable<Data>) => void) | undefined;
|
|
20
22
|
};
|
|
21
23
|
events(): {
|
|
22
24
|
success: CustomEvent<{
|
|
23
25
|
action: URL;
|
|
24
|
-
data?:
|
|
26
|
+
data?: Data | undefined;
|
|
25
27
|
}>;
|
|
28
|
+
created: CustomEvent<Data>;
|
|
29
|
+
updated: CustomEvent<Data>;
|
|
30
|
+
deleted: CustomEvent<void>;
|
|
26
31
|
} & {
|
|
27
32
|
[evt: string]: CustomEvent<any>;
|
|
28
33
|
};
|
|
29
|
-
slots(): {
|
|
34
|
+
slots(): {
|
|
35
|
+
default: {};
|
|
36
|
+
};
|
|
30
37
|
}
|
|
31
|
-
export type FormProps<Shape extends z.ZodRawShape,
|
|
32
|
-
export type FormEvents<Shape extends z.ZodRawShape,
|
|
33
|
-
export type FormSlots<Shape extends z.ZodRawShape,
|
|
34
|
-
export default class Form<Shape extends z.ZodRawShape,
|
|
35
|
-
get set(): <K extends keyof Shape>(key: K, value:
|
|
38
|
+
export type FormProps<Shape extends z.ZodRawShape, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = ReturnType<__sveltets_Render<Shape, Data>['props']>;
|
|
39
|
+
export type FormEvents<Shape extends z.ZodRawShape, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = ReturnType<__sveltets_Render<Shape, Data>['events']>;
|
|
40
|
+
export type FormSlots<Shape extends z.ZodRawShape, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = ReturnType<__sveltets_Render<Shape, Data>['slots']>;
|
|
41
|
+
export default class Form<Shape extends z.ZodRawShape, Data extends FormDataInput<Shape> = FormDataInput<Shape>> extends SvelteComponent<FormProps<Shape, Data>, FormEvents<Shape, Data>, FormSlots<Shape, Data>> {
|
|
42
|
+
get set(): <K extends keyof Shape>(key: K, value: Nullable<Data>[K]) => void;
|
|
43
|
+
get update(): (updater: (currentData: Nullable<Data>) => Nullable<Data>) => void;
|
|
36
44
|
}
|
|
37
45
|
export {};
|
package/dist/ui/form/form.d.ts
CHANGED
|
@@ -1,29 +1,37 @@
|
|
|
1
1
|
import type { z } from 'zod';
|
|
2
2
|
import type { ComponentProps } from 'svelte';
|
|
3
|
+
import { type Writable } from 'svelte/store';
|
|
4
|
+
import type { FormEventHandler } from 'svelte/elements';
|
|
3
5
|
import { type FormInputsProps, type FormInputsType } from './formInput.js';
|
|
4
6
|
import type FormSection from './FormSection.svelte';
|
|
5
|
-
import type { FormEventHandler } from 'svelte/elements';
|
|
6
7
|
type Shape = z.ZodRawShape;
|
|
7
8
|
type PickOne<T> = {
|
|
8
9
|
[P in keyof T]: Record<P, T[P]> & Partial<Record<Exclude<keyof T, P>, undefined>>;
|
|
9
10
|
}[keyof T];
|
|
10
|
-
export type
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
11
|
+
export type Nullable<T> = {
|
|
12
|
+
[P in keyof T]?: T[P] | null;
|
|
13
|
+
};
|
|
14
|
+
export type BoolOrFunction<S extends Shape> = boolean | ((data: Nullable<FormDataInput<S>>) => unknown);
|
|
15
|
+
export type FormDataInput<S extends Shape> = z.ZodObject<S>['_input'];
|
|
16
|
+
export type FormField<S extends Shape> = {
|
|
17
|
+
key: string & keyof S;
|
|
14
18
|
/** number col used by field */
|
|
15
19
|
colSpan?: number;
|
|
16
20
|
/** hide field if true */
|
|
17
|
-
hide?: BoolOrFunction<
|
|
21
|
+
hide?: BoolOrFunction<S>;
|
|
18
22
|
} & PickOne<FormInputsProps>;
|
|
19
|
-
export type FormSectionProps<
|
|
23
|
+
export type FormSectionProps<S extends Shape> = ComponentProps<FormSection> & {
|
|
20
24
|
/** hide group if true */
|
|
21
|
-
hide?: BoolOrFunction<
|
|
25
|
+
hide?: BoolOrFunction<S>;
|
|
22
26
|
};
|
|
23
|
-
export declare function initData<
|
|
24
|
-
export declare function getFieldType<
|
|
25
|
-
type HandleInputOptions = {
|
|
27
|
+
export declare function initData<S extends Shape, Data extends FormDataInput<S> = FormDataInput<S>>(fields: FormField<S>[][]): Data;
|
|
28
|
+
export declare function getFieldType<S extends Shape>(field: FormField<S>): FormInputsType;
|
|
29
|
+
type HandleInputOptions<S extends Shape> = {
|
|
30
|
+
model?: S;
|
|
26
31
|
setError: (key: string, value: string) => void;
|
|
27
32
|
};
|
|
28
|
-
export declare function useHandleInput(model
|
|
33
|
+
export declare function useHandleInput<S extends Shape>({ model, setError }: HandleInputOptions<S>): {
|
|
34
|
+
isDirty: Writable<boolean>;
|
|
35
|
+
handleInput: FormEventHandler<HTMLFormElement>;
|
|
36
|
+
};
|
|
29
37
|
export {};
|
package/dist/ui/form/form.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { formInputsType } from './formInput.js';
|
|
2
1
|
import debounce from 'debounce';
|
|
2
|
+
import { writable } from 'svelte/store';
|
|
3
|
+
import { formInputsType } from './formInput.js';
|
|
3
4
|
export function initData(fields) {
|
|
4
5
|
// @ts-ignore
|
|
5
6
|
return fields.flat().reduce((acc, cur) => {
|
|
@@ -14,32 +15,39 @@ export function getFieldType(field) {
|
|
|
14
15
|
return 'text';
|
|
15
16
|
return inputType;
|
|
16
17
|
}
|
|
17
|
-
export function useHandleInput(model,
|
|
18
|
+
export function useHandleInput({ model, setError }) {
|
|
19
|
+
const isDirty = writable(false);
|
|
18
20
|
const setErrorDebounced = debounce(setError, 1500);
|
|
19
|
-
return
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
21
|
+
return {
|
|
22
|
+
isDirty,
|
|
23
|
+
handleInput: ({ target }) => {
|
|
24
|
+
if (!target)
|
|
25
|
+
return;
|
|
26
|
+
isDirty.set(true);
|
|
27
|
+
if (!model)
|
|
28
|
+
return;
|
|
29
|
+
const { name, type, value, valueAsNumber, valueAsDate, checked } = target;
|
|
30
|
+
const typeMapValue = {
|
|
31
|
+
number: valueAsNumber,
|
|
32
|
+
date: valueAsDate,
|
|
33
|
+
text: value,
|
|
34
|
+
checkbox: checked
|
|
35
|
+
};
|
|
36
|
+
const v = typeMapValue[type] ?? value;
|
|
37
|
+
if (v === undefined || name === undefined)
|
|
38
|
+
return;
|
|
39
|
+
if (name === undefined)
|
|
40
|
+
return;
|
|
41
|
+
if (!model[name])
|
|
42
|
+
return;
|
|
43
|
+
const res = model[name].safeParse(v);
|
|
44
|
+
if (res.success) {
|
|
45
|
+
setErrorDebounced.clear();
|
|
46
|
+
setError(name, '');
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
setErrorDebounced(name, res.error.issues[0].message);
|
|
50
|
+
}
|
|
43
51
|
}
|
|
44
52
|
};
|
|
45
53
|
}
|
|
@@ -31,7 +31,7 @@ export type FormInputProps<T extends FormInputsType> = ComponentProps<InstanceTy
|
|
|
31
31
|
export type FormInputsProps = {
|
|
32
32
|
[T in FormInputsType]: FormInputProps<T>;
|
|
33
33
|
};
|
|
34
|
-
export declare const formInputsType: ("number" | "boolean" | "select" | "
|
|
34
|
+
export declare const formInputsType: ("number" | "boolean" | "select" | "date" | "textarea" | "text" | "password" | "radio" | "textrich" | "datetime" | "relation" | "relations")[];
|
|
35
35
|
export declare function relationProps<Item extends {
|
|
36
36
|
id: string;
|
|
37
37
|
}>(props: ComponentProps<InstanceType<typeof InputRelation<Item>>>): {
|
|
@@ -12,7 +12,7 @@ declare const __propDef: {
|
|
|
12
12
|
prefix?: string | number | undefined;
|
|
13
13
|
prefixFor?: string | number | undefined;
|
|
14
14
|
enhanceDisabled?: boolean | undefined;
|
|
15
|
-
labelPosition?: ("top" | "
|
|
15
|
+
labelPosition?: ("top" | "left" | "right") | undefined;
|
|
16
16
|
};
|
|
17
17
|
events: {
|
|
18
18
|
[evt: string]: CustomEvent<any>;
|
|
@@ -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?: HTMLInputAttributes | undefined;
|
|
17
17
|
inputElement?: HTMLInputElement | undefined;
|
|
18
18
|
wrapperClass?: string | undefined;
|
|
19
|
-
value?: boolean | undefined;
|
|
19
|
+
value?: boolean | null | undefined;
|
|
20
20
|
bindWithParams?: boolean | undefined;
|
|
21
21
|
} & {
|
|
22
22
|
isRow?: boolean | 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;
|
|
@@ -27,7 +27,7 @@ $:
|
|
|
27
27
|
function handleSubmit() {
|
|
28
28
|
if (!dropdown)
|
|
29
29
|
return;
|
|
30
|
-
if (!value
|
|
30
|
+
if (!value?.length) {
|
|
31
31
|
goto($urlParam.without(key), { replaceState: true, noScroll: true });
|
|
32
32
|
return;
|
|
33
33
|
}
|
|
@@ -43,23 +43,23 @@ function handleReset() {
|
|
|
43
43
|
<input type="hidden" name={key} value={JSON.stringify(value)} />
|
|
44
44
|
|
|
45
45
|
<DropDown bind:this={dropdown} tippyProps={{ onHide: handleSubmit }} wrapperClass="mb-[-2px]">
|
|
46
|
-
<div class="join" class:ml-2={value
|
|
46
|
+
<div class="join" class:ml-2={value?.length} slot="activator">
|
|
47
47
|
<button class="btn indicator join-item btn-sm {btnClass || ''}">
|
|
48
48
|
<slot name="label">
|
|
49
49
|
<span>{label}</span>
|
|
50
50
|
</slot>
|
|
51
|
-
{#if value
|
|
51
|
+
{#if !!value?.length}
|
|
52
52
|
<span
|
|
53
53
|
class="
|
|
54
54
|
badge indicator-item badge-sm indicator-start
|
|
55
55
|
{badgePrimary ? 'badge-primary' : 'badge-outline bg-base-100'}
|
|
56
56
|
"
|
|
57
57
|
>
|
|
58
|
-
{value
|
|
58
|
+
{value?.length}
|
|
59
59
|
</span>
|
|
60
60
|
{/if}
|
|
61
61
|
</button>
|
|
62
|
-
{#if value
|
|
62
|
+
{#if !!value?.length}
|
|
63
63
|
<button class="btn btn-square join-item btn-sm" on:click={handleReset}>
|
|
64
64
|
<Icon path={mdiClose} class="fill-base-content" />
|
|
65
65
|
</button>
|
|
@@ -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
|
key: string;
|
|
@@ -14,12 +14,12 @@ declare const __propDef: {
|
|
|
14
14
|
prefix?: string | number | undefined;
|
|
15
15
|
prefixFor?: string | number | undefined;
|
|
16
16
|
enhanceDisabled?: boolean | undefined;
|
|
17
|
-
labelPosition?: ("top" | "
|
|
17
|
+
labelPosition?: ("top" | "left" | "right") | undefined;
|
|
18
18
|
} & {
|
|
19
19
|
input?: import("svelte/elements").HTMLInputAttributes | undefined;
|
|
20
20
|
inputElement?: HTMLInputElement | undefined;
|
|
21
21
|
wrapperClass?: string | undefined;
|
|
22
|
-
value?: string | undefined;
|
|
22
|
+
value?: string | null | undefined;
|
|
23
23
|
bindWithParams?: boolean | undefined;
|
|
24
24
|
} & {
|
|
25
25
|
options: Options;
|
|
@@ -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_JSON_PARSER } 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";
|
|
@@ -101,7 +102,11 @@ async function handleBlur() {
|
|
|
101
102
|
<Icon path={mdiClose} />
|
|
102
103
|
</button>
|
|
103
104
|
</div>
|
|
104
|
-
<input
|
|
105
|
+
<input
|
|
106
|
+
type="hidden"
|
|
107
|
+
name={key}
|
|
108
|
+
value="{USE_JSON_PARSER}{JSON.stringify({ id: item.id })}"
|
|
109
|
+
/>
|
|
105
110
|
{/if}
|
|
106
111
|
</FormControl>
|
|
107
112
|
</div>
|
|
@@ -113,7 +118,7 @@ async function handleBlur() {
|
|
|
113
118
|
{isLoading}
|
|
114
119
|
{focusIndex}
|
|
115
120
|
let:index
|
|
116
|
-
class="w-full {classList}"
|
|
121
|
+
class="w-full min-w-40 {classList}"
|
|
117
122
|
on:select={({ detail }) => select(detail)}
|
|
118
123
|
>
|
|
119
124
|
<slot name="suggestion" item={proposedItems[index]}>
|
|
@@ -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_JSON_PARSER } 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";
|
|
@@ -111,7 +112,6 @@ async function handleBlur() {
|
|
|
111
112
|
<input
|
|
112
113
|
type="text"
|
|
113
114
|
id={key}
|
|
114
|
-
name={key}
|
|
115
115
|
bind:this={inputSearch}
|
|
116
116
|
bind:value={searchValue}
|
|
117
117
|
on:input={(e) => searchItemsDebounce(e.currentTarget.value)}
|
|
@@ -128,7 +128,11 @@ async function handleBlur() {
|
|
|
128
128
|
</div>
|
|
129
129
|
</div>
|
|
130
130
|
|
|
131
|
-
<input
|
|
131
|
+
<input
|
|
132
|
+
type="hidden"
|
|
133
|
+
name={key}
|
|
134
|
+
value="{USE_JSON_PARSER}{JSON.stringify(items?.map(({ id }) => ({ id })) || [])}"
|
|
135
|
+
/>
|
|
132
136
|
</FormControl>
|
|
133
137
|
</div>
|
|
134
138
|
|
|
@@ -139,7 +143,7 @@ async function handleBlur() {
|
|
|
139
143
|
{isLoading}
|
|
140
144
|
{focusIndex}
|
|
141
145
|
let:index
|
|
142
|
-
class="w-full {classList}"
|
|
146
|
+
class="w-full min-w-40 {classList}"
|
|
143
147
|
on:select={({ detail }) => select(detail)}
|
|
144
148
|
>
|
|
145
149
|
<slot name="suggestion" item={proposedItems[index]}>
|
|
@@ -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;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const USE_JSON_PARSER = "USE_JSON_PARSER_nXFVwk03nRbmhFukfyZLuzkEd43LXIKs_";
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const USE_JSON_PARSER = 'USE_JSON_PARSER_nXFVwk03nRbmhFukfyZLuzkEd43LXIKs_';
|
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;
|
|
@@ -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
|
};
|