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.
Files changed (72) hide show
  1. package/dist/api/client.d.ts +3 -0
  2. package/dist/api/client.js +24 -0
  3. package/dist/api/config.d.ts +46 -0
  4. package/dist/api/config.js +7 -0
  5. package/dist/api/index.d.ts +3 -0
  6. package/dist/api/index.js +3 -0
  7. package/dist/api/server.d.ts +11 -0
  8. package/dist/api/server.js +17 -0
  9. package/dist/{Meta.svelte → private/Meta.svelte} +4 -4
  10. package/dist/private/api.d.ts +61 -0
  11. package/dist/private/api.js +10 -0
  12. package/dist/private/constant.d.ts +14 -0
  13. package/dist/private/constant.js +6 -0
  14. package/dist/private/model.d.ts +78 -0
  15. package/dist/private/model.js +25 -0
  16. package/dist/server/auth.js +1 -1
  17. package/dist/server/parseFormData.js +21 -1
  18. package/dist/server/parseQuery.d.ts +1 -10
  19. package/dist/server/parseQuery.js +4 -5
  20. package/dist/server/try.js +0 -1
  21. package/dist/ui/drawer/Drawer.svelte +19 -11
  22. package/dist/ui/drawer/Drawer.svelte.d.ts +42 -7
  23. package/dist/ui/drawer/layers.d.ts +2 -1
  24. package/dist/ui/drawer/layers.js +5 -4
  25. package/dist/ui/form/Form.svelte +43 -24
  26. package/dist/ui/form/Form.svelte.d.ts +20 -12
  27. package/dist/ui/form/FormInput.svelte.d.ts +4 -0
  28. package/dist/ui/form/form.d.ts +20 -12
  29. package/dist/ui/form/form.js +34 -26
  30. package/dist/ui/form/formInput.d.ts +3 -1
  31. package/dist/ui/input/FormControl.svelte.d.ts +1 -1
  32. package/dist/ui/input/InputBoolean.svelte +4 -2
  33. package/dist/ui/input/InputBoolean.svelte.d.ts +2 -2
  34. package/dist/ui/input/InputCheckboxs.svelte.d.ts +2 -2
  35. package/dist/ui/input/InputCheckboxsMenu.svelte +5 -5
  36. package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +2 -2
  37. package/dist/ui/input/InputCombo.svelte.d.ts +2 -2
  38. package/dist/ui/input/InputDate.svelte +10 -7
  39. package/dist/ui/input/InputDate.svelte.d.ts +1 -1
  40. package/dist/ui/input/InputDatetime.svelte +24 -12
  41. package/dist/ui/input/InputDatetime.svelte.d.ts +2 -2
  42. package/dist/ui/input/InputNumber.svelte +12 -11
  43. package/dist/ui/input/InputNumber.svelte.d.ts +1 -1
  44. package/dist/ui/input/InputPassword.svelte.d.ts +2 -2
  45. package/dist/ui/input/InputRadio.svelte.d.ts +2 -2
  46. package/dist/ui/input/InputRelation.svelte +10 -3
  47. package/dist/ui/input/InputRelation.svelte.d.ts +2 -0
  48. package/dist/ui/input/InputRelations.svelte +10 -3
  49. package/dist/ui/input/InputRelations.svelte.d.ts +2 -0
  50. package/dist/ui/input/InputSelect.svelte +4 -2
  51. package/dist/ui/input/InputText.svelte.d.ts +2 -2
  52. package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +1 -1
  53. package/dist/ui/input/textRich/extensions.js +1 -1
  54. package/dist/ui/input/types.d.ts +2 -2
  55. package/dist/ui/login/Login.svelte +7 -3
  56. package/dist/ui/table/field.d.ts +1 -1
  57. package/dist/ui/table/head/TableHeadNumber.svelte +1 -1
  58. package/dist/utils/constant.d.ts +4 -0
  59. package/dist/utils/constant.js +4 -0
  60. package/dist/utils/index.d.ts +1 -0
  61. package/dist/utils/index.js +1 -0
  62. package/dist/utils/jsonParse.d.ts +1 -1
  63. package/dist/utils/jsonParse.js +5 -3
  64. package/dist/utils/options.d.ts +2 -1
  65. package/dist/validation/form.d.ts +6 -5
  66. package/dist/validation/form.js +8 -8
  67. package/dist/validation/zod.d.ts +109 -55
  68. package/dist/validation/zod.js +11 -31
  69. package/package.json +13 -3
  70. /package/dist/{Meta.svelte.d.ts → private/Meta.svelte.d.ts} +0 -0
  71. /package/dist/{server → private}/prisma.d.ts +0 -0
  72. /package/dist/{server → private}/prisma.js +0 -0
@@ -2,7 +2,11 @@
2
2
 
3
3
  <script
4
4
 
5
- generics="Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>"
5
+ generics="
6
+ Shape extends z.ZodRawShape,
7
+ ReturnData extends Record<string, unknown> = FormDataInput<Shape>,
8
+ Data extends FormDataInput<Shape> = FormDataInput<Shape>
9
+ "
6
10
  >import { createEventDispatcher, onMount } from "svelte";
7
11
  import { fade } from "svelte/transition";
8
12
  import { page } from "$app/stores";
@@ -12,8 +16,9 @@ import {
12
16
  getFieldType,
13
17
  useHandleInput
14
18
  } from "./form.js";
19
+ import ButtonDelete from "../button/ButtonDelete.svelte";
15
20
  import { useForm } from "../../validation/form.js";
16
- import Input from "./FormInput.svelte";
21
+ import FormInput from "./FormInput.svelte";
17
22
  import FormSection from "./FormSection.svelte";
18
23
  let klass = "";
19
24
  export { klass as class };
@@ -22,32 +27,50 @@ export let classAction = "";
22
27
  export let model = void 0;
23
28
  export let fields = [];
24
29
  export let sections = [{}];
25
- export let data = initData(fields);
26
30
  export let action = "";
27
- export let actionDelete = "";
28
- export let actionPrefix = "";
31
+ export let actionCreate = "_create";
32
+ export let actionDelete = "_delete";
33
+ export let actionUpdate = "_update";
29
34
  export let options = {};
35
+ let dataInput = initData(fields);
36
+ export { dataInput as data };
37
+ let data = dataInput;
38
+ $:
39
+ $isDirty ? dataInput = data : data = dataInput;
30
40
  export function set(key, value) {
41
+ isDirty.set(true);
31
42
  data[key] = value;
32
43
  }
44
+ export function update(updater) {
45
+ isDirty.set(true);
46
+ data = updater(data);
47
+ }
33
48
  const dispatch = createEventDispatcher();
34
49
  const { enhance, setError } = useForm({
35
50
  ...options,
36
- onSuccess(action2, data2) {
37
- dispatch("success", { action: action2, data: data2 });
51
+ async onSuccess(url, data2) {
38
52
  if (options.onSuccess)
39
- options.onSuccess(action2, data2);
53
+ await options.onSuccess(url, data2);
54
+ dispatch("success", { action: url, data: data2 });
55
+ const actionPath = url.pathname + url.search;
56
+ if (actionPath.includes(action + actionDelete))
57
+ dispatch("deleted");
58
+ if (!data2)
59
+ return;
60
+ if (actionPath.includes(action + actionCreate))
61
+ dispatch("created", data2);
62
+ if (actionPath.includes(action + actionUpdate))
63
+ dispatch("updated", data2);
40
64
  }
41
65
  });
42
- const handleInput = model ? useHandleInput(model, { setError }) : () => {
43
- };
66
+ const { handleInput, isDirty } = useHandleInput({ model, setError });
44
67
  onMount(lookupValueFromParams);
45
68
  function lookupValueFromParams() {
46
69
  fields.flat().forEach(({ key }) => {
47
70
  if (data[key])
48
71
  return;
49
72
  const value = $page.url.searchParams.get(key);
50
- if (value)
73
+ if (value && key in data)
51
74
  data[key] = value;
52
75
  });
53
76
  }
@@ -65,12 +88,14 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
65
88
 
66
89
  <form
67
90
  method="post"
68
- action="{actionPrefix}{action}"
91
+ action="{action}{data.id ? actionUpdate : actionCreate}"
69
92
  enctype="multipart/form-data"
70
93
  class="{klass} flex flex-col gap-4"
71
94
  use:enhance
72
95
  on:input={handleInput}
73
96
  >
97
+ <slot />
98
+
74
99
  {#if data.id}
75
100
  <input type="hidden" name="id" value={data.id} />
76
101
  {/if}
@@ -88,7 +113,7 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
88
113
  style={`grid-column: span ${field.colSpan || 2};`}
89
114
  in:fade|local={{ duration: 200 }}
90
115
  >
91
- <Input
116
+ <FormInput
92
117
  key={field.key}
93
118
  type={inputType}
94
119
  bind:value={data[field.key]}
@@ -106,19 +131,13 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
106
131
  <div
107
132
  class="
108
133
  {classAction} {actionPadding}
109
- sticky bottom-0 col-span-full mt-2 flex gap-2 border-t py-4 backdrop-blur-sm
134
+ sticky bottom-0 col-span-full mt-2 flex flex-row-reverse gap-2 border-t py-4 backdrop-blur-sm
110
135
  "
111
136
  >
112
- {#if actionDelete}
113
- <button
114
- class="btn-ghos btn text-error"
115
- type="button"
116
- formaction="{actionPrefix}{actionDelete}"
117
- >
118
- Supprimer
119
- </button>
120
- {/if}
121
- <div class="grow" />
122
137
  <button class="btn btn-primary"> Valider </button>
138
+ <div class="grow" />
139
+ {#if data.id && actionDelete}
140
+ <ButtonDelete formaction="{action}{actionDelete}">Supprimer</ButtonDelete>
141
+ {/if}
123
142
  </div>
124
143
  </form>
@@ -1,9 +1,9 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import type { z } from 'zod';
3
- import type { FormData } from './form.js';
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, ReturnData extends Record<string, unknown> = FormData<Shape>> {
6
+ declare class __sveltets_Render<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, 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
- actionPrefix?: string | undefined;
17
+ actionUpdate?: string | undefined;
18
18
  options?: UseFormOptions<ReturnData> | undefined;
19
- set?: (<K extends keyof Shape>(key: K, value: 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_1 ? { [k in keyof T_1]: 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>[K]) => void) | 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
26
  data?: ReturnData | undefined;
25
27
  }>;
28
+ created: CustomEvent<ReturnData>;
29
+ updated: CustomEvent<ReturnData>;
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, ReturnData extends Record<string, unknown> = FormData<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData>['props']>;
32
- export type FormEvents<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData>['events']>;
33
- export type FormSlots<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData>['slots']>;
34
- export default class Form<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormData<Shape>> extends SvelteComponent<FormProps<Shape, ReturnData>, FormEvents<Shape, ReturnData>, FormSlots<Shape, ReturnData>> {
35
- get set(): <K extends keyof Shape>(key: K, value: 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>[K]) => void;
38
+ export type FormProps<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData, Data>['props']>;
39
+ export type FormEvents<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData, Data>['events']>;
40
+ export type FormSlots<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = ReturnType<__sveltets_Render<Shape, ReturnData, Data>['slots']>;
41
+ export default class Form<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>> extends SvelteComponent<FormProps<Shape, ReturnData, Data>, FormEvents<Shape, ReturnData, Data>, FormSlots<Shape, ReturnData, 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 {};
@@ -27,6 +27,7 @@ declare class __sveltets_Render<InputType extends FormInputsType> {
27
27
  flatMode?: boolean | undefined;
28
28
  slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
29
29
  slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
30
+ input?: import("svelte/elements.js").HTMLInputAttributes | undefined;
30
31
  class?: string | undefined;
31
32
  classList?: string | undefined;
32
33
  clear?: (() => Promise<void>) | undefined;
@@ -45,6 +46,7 @@ declare class __sveltets_Render<InputType extends FormInputsType> {
45
46
  flatMode?: boolean | undefined;
46
47
  slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
47
48
  slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
49
+ input?: import("svelte/elements.js").HTMLInputAttributes | undefined;
48
50
  class?: string | undefined;
49
51
  classList?: string | undefined;
50
52
  value?: any[] | null | undefined;
@@ -78,6 +80,7 @@ declare class __sveltets_Render<InputType extends FormInputsType> {
78
80
  flatMode?: boolean | undefined;
79
81
  slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
80
82
  slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
83
+ input?: import("svelte/elements.js").HTMLInputAttributes | undefined;
81
84
  class?: string | undefined;
82
85
  classList?: string | undefined;
83
86
  clear?: (() => Promise<void>) | undefined;
@@ -96,6 +99,7 @@ declare class __sveltets_Render<InputType extends FormInputsType> {
96
99
  flatMode?: boolean | undefined;
97
100
  slotItem?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
98
101
  slotSuggestion?: ((item: any) => string | import("../../index.js").ComponentAndProps) | null | undefined;
102
+ input?: import("svelte/elements.js").HTMLInputAttributes | undefined;
99
103
  class?: string | undefined;
100
104
  classList?: string | undefined;
101
105
  value?: any[] | null | undefined;
@@ -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 BoolOrFunction<M extends Shape> = boolean | ((data: Partial<FormData<M>>) => unknown);
11
- export type FormData<M extends Shape> = z.infer<z.ZodObject<M>>;
12
- export type FormField<M extends Shape> = {
13
- key: string & keyof M;
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<M>;
21
+ hide?: BoolOrFunction<S>;
18
22
  } & PickOne<FormInputsProps>;
19
- export type FormSectionProps<M extends Shape> = ComponentProps<FormSection> & {
23
+ export type FormSectionProps<S extends Shape> = ComponentProps<FormSection> & {
20
24
  /** hide group if true */
21
- hide?: BoolOrFunction<M>;
25
+ hide?: BoolOrFunction<S>;
22
26
  };
23
- export declare function initData<M extends Shape>(fields: FormField<M>[][]): Partial<FormData<M>>;
24
- export declare function getFieldType<M extends Shape>(field: FormField<M>): FormInputsType;
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: Shape, { setError }: HandleInputOptions): FormEventHandler<HTMLFormElement>;
33
+ export declare function useHandleInput<S extends Shape>({ model, setError }: HandleInputOptions<S>): {
34
+ isDirty: Writable<boolean>;
35
+ handleInput: FormEventHandler<HTMLFormElement>;
36
+ };
29
37
  export {};
@@ -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, { setError }) {
18
+ export function useHandleInput({ model, setError }) {
19
+ const isDirty = writable(false);
18
20
  const setErrorDebounced = debounce(setError, 1500);
19
- return ({ target }) => {
20
- if (!target)
21
- return;
22
- const { name, type, value, valueAsNumber, valueAsDate, checked } = target;
23
- const typeMapValue = {
24
- number: valueAsNumber,
25
- date: valueAsDate,
26
- text: value,
27
- checkbox: checked
28
- };
29
- const v = typeMapValue[type] ?? value;
30
- if (v === undefined || name === undefined)
31
- return;
32
- if (name === undefined)
33
- return;
34
- if (!model[name])
35
- return;
36
- const res = model[name].safeParse(v);
37
- if (res.success) {
38
- setErrorDebounced.clear();
39
- setError(name, '');
40
- }
41
- else {
42
- setErrorDebounced(name, res.error.issues[0].message);
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" | "textarea" | "date" | "text" | "password" | "radio" | "textrich" | "datetime" | "relation" | "relations")[];
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>>>): {
@@ -48,6 +48,7 @@ export declare function relationProps<Item extends {
48
48
  flatMode?: boolean | undefined;
49
49
  slotItem?: ((item: Item) => string | import("../..").ComponentAndProps) | null | undefined;
50
50
  slotSuggestion?: ((item: Item) => string | import("../..").ComponentAndProps) | null | undefined;
51
+ input?: import("svelte/elements").HTMLInputAttributes | undefined;
51
52
  class?: string | undefined;
52
53
  classList?: string | undefined;
53
54
  clear?: (() => Promise<void>) | undefined;
@@ -66,6 +67,7 @@ export declare function relationsProps<Item extends {
66
67
  flatMode?: boolean | undefined;
67
68
  slotItem?: ((item: Item) => string | import("../..").ComponentAndProps) | null | undefined;
68
69
  slotSuggestion?: ((item: Item) => string | import("../..").ComponentAndProps) | null | undefined;
70
+ input?: import("svelte/elements").HTMLInputAttributes | undefined;
69
71
  class?: string | undefined;
70
72
  classList?: string | undefined;
71
73
  value?: Item[] | null | undefined;
@@ -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" | "right" | "left") | undefined;
15
+ labelPosition?: ("top" | "left" | "right") | undefined;
16
16
  };
17
17
  events: {
18
18
  [evt: string]: CustomEvent<any>;
@@ -1,5 +1,6 @@
1
1
  <script>import { createEventDispatcher } from "svelte";
2
2
  import { FormControl, bindCheckedWithParams } from "./index.js";
3
+ import { USE_COERCE_BOOLEAN } from "../../utils/constant.js";
3
4
  export let value = false;
4
5
  export let input = {};
5
6
  export let inputElement = void 0;
@@ -20,6 +21,7 @@ const dispatch = createEventDispatcher();
20
21
  class="checkbox ml-1"
21
22
  {...input}
22
23
  />
23
-
24
- <input type="hidden" name={key} value={value ? 'true' : ''} />
24
+ {#if value !== undefined}
25
+ <input type="hidden" name={key} value="{USE_COERCE_BOOLEAN}{value}" />
26
+ {/if}
25
27
  </FormControl>
@@ -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" | "right" | "left") | undefined;
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" | "right" | "left") | undefined;
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.length) {
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.length} slot="activator">
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.length > 0}
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.length}
58
+ {value?.length}
59
59
  </span>
60
60
  {/if}
61
61
  </button>
62
- {#if value.length}
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" | "right" | "left") | undefined;
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" | "right" | "left") | undefined;
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;
@@ -1,11 +1,11 @@
1
1
  <script>import { createEventDispatcher } from "svelte";
2
2
  import dayjs from "dayjs";
3
3
  import { FormControl } from "./index.js";
4
+ import { USE_COERCE_DATE } from "../../utils/constant.js";
5
+ export let value = void 0;
6
+ export let input = {};
4
7
  $:
5
- ({ input, value: _value, ...props } = $$props);
6
- $:
7
- ({ class: inputClass, ...inputProps } = input || {});
8
- export let value = _value;
8
+ ({ class: inputClass = "", ...inputProps } = input);
9
9
  const dispatch = createEventDispatcher();
10
10
  const handleInput = ({ currentTarget }) => {
11
11
  value = currentTarget.valueAsDate || null;
@@ -13,16 +13,19 @@ const handleInput = ({ currentTarget }) => {
13
13
  };
14
14
  </script>
15
15
 
16
- <FormControl {...props} let:key>
16
+ <FormControl {...$$restProps} let:key>
17
17
  <input
18
18
  value={value && dayjs(value).format('YYYY-MM-DD')}
19
19
  on:input={handleInput}
20
20
  on:focus
21
21
  on:blur
22
22
  type="date"
23
- name={key}
24
23
  id={key}
25
- class="input input-bordered {inputClass || {}}"
24
+ class="input input-bordered {inputClass}"
26
25
  {...inputProps}
27
26
  />
27
+
28
+ {#if value !== undefined}
29
+ <input type="hidden" name={key} value="{USE_COERCE_DATE}{value?.toJSON()}" />
30
+ {/if}
28
31
  </FormControl>
@@ -1,7 +1,7 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import { type InputProps } from './index.js';
3
3
  declare const __propDef: {
4
- props: InputProps<Date | null>;
4
+ props: InputProps<Date | null | undefined>;
5
5
  events: {
6
6
  focus: FocusEvent;
7
7
  blur: FocusEvent;
@@ -1,23 +1,35 @@
1
- <script>import { FormControl } from "./index.js";
1
+ <script>import { USE_COERCE_DATE } from "../../utils/constant.js";
2
+ import { FormControl } from "./index.js";
3
+ import { createEventDispatcher } from "svelte";
4
+ import dayjs from "dayjs";
5
+ export let value = void 0;
6
+ export let input = {};
2
7
  $:
3
- ({ input, value: _value, ...props } = $$props);
4
- $:
5
- ({ class: inputClass, ...inputProps } = input || {});
6
- export let value = _value;
8
+ ({ class: inputClass = "", ...inputProps } = input);
9
+ const dispatch = createEventDispatcher();
10
+ const handleInput = ({ currentTarget }) => {
11
+ value = getDateTime(currentTarget.value);
12
+ dispatch("input", value);
13
+ };
14
+ function getDateTime(v) {
15
+ if (typeof v !== "string")
16
+ return null;
17
+ return new Date(v);
18
+ }
7
19
  </script>
8
20
 
9
- <FormControl {...props} let:key>
10
- {#if value}
11
- <input type="hidden" name={key} value={new Date(value).toJSON()} />
12
- {/if}
21
+ <FormControl {...$$restProps} let:key>
13
22
  <input
14
- bind:value
15
- on:input
23
+ value={value && dayjs(value).format('YYYY-MM-DDThh:mm')}
24
+ on:input={handleInput}
16
25
  on:focus
17
26
  on:blur
18
27
  type="datetime-local"
19
28
  id={key}
20
- class="input input-bordered {inputClass || {}}"
29
+ class="input input-bordered {inputClass}"
21
30
  {...inputProps}
22
31
  />
32
+ {#if value !== undefined}
33
+ <input type="hidden" name={key} value="{USE_COERCE_DATE}{value?.toJSON()}" />
34
+ {/if}
23
35
  </FormControl>
@@ -1,11 +1,11 @@
1
1
  import { SvelteComponent } from "svelte";
2
2
  import { type InputProps } from './index.js';
3
3
  declare const __propDef: {
4
- props: InputProps;
4
+ props: InputProps<Date | null | undefined>;
5
5
  events: {
6
- input: Event;
7
6
  focus: FocusEvent;
8
7
  blur: FocusEvent;
8
+ input: CustomEvent<Date | null>;
9
9
  } & {
10
10
  [evt: string]: CustomEvent<any>;
11
11
  };