fuma 1.0.20 → 2.0.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.
Files changed (195) hide show
  1. package/README.md +1 -1
  2. package/dist/action/list/handlers.d.ts +2 -2
  3. package/dist/action/list/index.d.ts +2 -0
  4. package/dist/action/list/index.js +1 -0
  5. package/dist/action/list/trigger.d.ts +7 -1
  6. package/dist/action/list/trigger.js +2 -2
  7. package/dist/private/Meta.svelte +32 -27
  8. package/dist/private/Meta.svelte.d.ts +29 -17
  9. package/dist/private/api.d.ts +1 -1
  10. package/dist/private/store.d.ts +0 -1
  11. package/dist/server/parseFormData.d.ts +1 -1
  12. package/dist/server/parseQuery.d.ts +1 -1
  13. package/dist/server/sse.d.ts +0 -1
  14. package/dist/store/isSmallScreen.d.ts +0 -1
  15. package/dist/store/param.d.ts +0 -2
  16. package/dist/store/session.d.ts +0 -1
  17. package/dist/ui/badge/Badge.svelte +4 -3
  18. package/dist/ui/badge/Badge.svelte.d.ts +19 -15
  19. package/dist/ui/button/ButtonCopy.svelte +35 -32
  20. package/dist/ui/button/ButtonCopy.svelte.d.ts +23 -21
  21. package/dist/ui/button/ButtonDelete.svelte +23 -21
  22. package/dist/ui/button/ButtonDelete.svelte.d.ts +32 -20
  23. package/dist/ui/card/Card.svelte +13 -10
  24. package/dist/ui/card/Card.svelte.d.ts +39 -24
  25. package/dist/ui/card/CardBasic.svelte +5 -4
  26. package/dist/ui/card/CardBasic.svelte.d.ts +29 -18
  27. package/dist/ui/card/CardCollapse.svelte +35 -31
  28. package/dist/ui/card/CardCollapse.svelte.d.ts +37 -23
  29. package/dist/ui/card/CardFullScreen.svelte +8 -6
  30. package/dist/ui/card/CardFullScreen.svelte.d.ts +35 -20
  31. package/dist/ui/card/CardLink.svelte +5 -4
  32. package/dist/ui/card/CardLink.svelte.d.ts +29 -18
  33. package/dist/ui/dialog/Dialog.svelte +41 -34
  34. package/dist/ui/dialog/Dialog.svelte.d.ts +36 -23
  35. package/dist/ui/dialog/DialogConfirm.svelte +6 -4
  36. package/dist/ui/dialog/DialogConfirm.svelte.d.ts +33 -19
  37. package/dist/ui/drawer/Drawer.svelte +47 -38
  38. package/dist/ui/drawer/Drawer.svelte.d.ts +81 -46
  39. package/dist/ui/drawer/drawerFly.d.ts +0 -1
  40. package/dist/ui/drawer/layers.d.ts +0 -1
  41. package/dist/ui/form/Form.svelte +106 -87
  42. package/dist/ui/form/Form.svelte.d.ts +29 -16
  43. package/dist/ui/form/FormInput.svelte +12 -6
  44. package/dist/ui/form/FormSection.svelte +24 -17
  45. package/dist/ui/form/FormSection.svelte.d.ts +37 -25
  46. package/dist/ui/icon/Icon.svelte +35 -32
  47. package/dist/ui/icon/Icon.svelte.d.ts +25 -21
  48. package/dist/ui/index.d.ts +0 -1
  49. package/dist/ui/index.js +0 -1
  50. package/dist/ui/input/FormControl.svelte +48 -36
  51. package/dist/ui/input/FormControl.svelte.d.ts +32 -30
  52. package/dist/ui/input/InputBoolean.svelte +29 -22
  53. package/dist/ui/input/InputBoolean.svelte.d.ts +43 -35
  54. package/dist/ui/input/InputCheckboxs.svelte +37 -34
  55. package/dist/ui/input/InputCheckboxs.svelte.d.ts +54 -39
  56. package/dist/ui/input/InputCheckboxsMenu.svelte +64 -47
  57. package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +56 -41
  58. package/dist/ui/input/InputCheckboxsTree.svelte +9 -6
  59. package/dist/ui/input/InputCheckboxsTree.svelte.d.ts +22 -18
  60. package/dist/ui/input/InputCheckboxsTreeNodes.svelte +36 -28
  61. package/dist/ui/input/InputCheckboxsTreeNodes.svelte.d.ts +20 -16
  62. package/dist/ui/input/InputCombo.svelte +76 -65
  63. package/dist/ui/input/InputCombo.svelte.d.ts +55 -39
  64. package/dist/ui/input/InputDate.svelte +36 -29
  65. package/dist/ui/input/InputDate.svelte.d.ts +20 -16
  66. package/dist/ui/input/InputDateTime.svelte +37 -30
  67. package/dist/ui/input/InputDateTime.svelte.d.ts +20 -16
  68. package/dist/ui/input/InputImage.svelte +52 -45
  69. package/dist/ui/input/InputImage.svelte.d.ts +40 -27
  70. package/dist/ui/input/InputImagePreview.svelte +24 -20
  71. package/dist/ui/input/InputImagePreview.svelte.d.ts +25 -21
  72. package/dist/ui/input/InputNumber.svelte +28 -22
  73. package/dist/ui/input/InputNumber.svelte.d.ts +20 -20
  74. package/dist/ui/input/InputOptionInParam.svelte +12 -10
  75. package/dist/ui/input/InputOptionInParam.svelte.d.ts +21 -17
  76. package/dist/ui/input/InputOptions.svelte +40 -34
  77. package/dist/ui/input/InputOptions.svelte.d.ts +19 -15
  78. package/dist/ui/input/InputPassword.svelte +22 -18
  79. package/dist/ui/input/InputPassword.svelte.d.ts +43 -35
  80. package/dist/ui/input/InputRadio.svelte +51 -46
  81. package/dist/ui/input/InputRadio.svelte.d.ts +53 -38
  82. package/dist/ui/input/InputRelation.svelte +129 -112
  83. package/dist/ui/input/InputRelation.svelte.d.ts +39 -53
  84. package/dist/ui/input/InputRelations.svelte +96 -90
  85. package/dist/ui/input/InputRelations.svelte.d.ts +35 -37
  86. package/dist/ui/input/InputSearch.svelte +14 -11
  87. package/dist/ui/input/InputSearch.svelte.d.ts +25 -21
  88. package/dist/ui/input/InputSelect.svelte +59 -46
  89. package/dist/ui/input/InputSelect.svelte.d.ts +23 -19
  90. package/dist/ui/input/InputText.svelte +29 -28
  91. package/dist/ui/input/InputText.svelte.d.ts +41 -28
  92. package/dist/ui/input/InputTextarea.svelte +20 -19
  93. package/dist/ui/input/InputTextarea.svelte.d.ts +20 -20
  94. package/dist/ui/input/InputTime.svelte +43 -36
  95. package/dist/ui/input/InputTime.svelte.d.ts +21 -36
  96. package/dist/ui/input/RelationAfter.svelte +13 -9
  97. package/dist/ui/input/RelationAfter.svelte.d.ts +24 -20
  98. package/dist/ui/input/SelectorList.svelte +16 -12
  99. package/dist/ui/input/SelectorList.svelte.d.ts +29 -20
  100. package/dist/ui/input/textRich/InputTextRich.svelte +63 -59
  101. package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +36 -38
  102. package/dist/ui/input/textRich/SuggesionList.svelte +13 -9
  103. package/dist/ui/input/textRich/SuggesionList.svelte.d.ts +19 -15
  104. package/dist/ui/input/textRich/ToolMark.svelte +12 -9
  105. package/dist/ui/input/textRich/ToolMark.svelte.d.ts +22 -18
  106. package/dist/ui/input/textRich/ToolMarkColor.svelte +16 -12
  107. package/dist/ui/input/textRich/ToolMarkColor.svelte.d.ts +21 -17
  108. package/dist/ui/input/textRich/ToolMarkLink.svelte +46 -38
  109. package/dist/ui/input/textRich/ToolMarkLink.svelte.d.ts +18 -14
  110. package/dist/ui/input/textRich/ToolMenu.svelte +34 -19
  111. package/dist/ui/input/textRich/ToolMenu.svelte.d.ts +30 -26
  112. package/dist/ui/input/textRich/ToolMenuAlign.svelte +13 -9
  113. package/dist/ui/input/textRich/ToolMenuAlign.svelte.d.ts +18 -14
  114. package/dist/ui/input/textRich/ToolMenuInsert.svelte +12 -7
  115. package/dist/ui/input/textRich/ToolMenuInsert.svelte.d.ts +20 -16
  116. package/dist/ui/input/textRich/ToolMenuNode.svelte +14 -10
  117. package/dist/ui/input/textRich/ToolMenuNode.svelte.d.ts +18 -14
  118. package/dist/ui/input/textRich/ToolsBar.svelte +21 -14
  119. package/dist/ui/input/textRich/ToolsBar.svelte.d.ts +19 -17
  120. package/dist/ui/input/textRich/suggestion.d.ts +0 -1
  121. package/dist/ui/login/Login.svelte +37 -31
  122. package/dist/ui/login/Login.svelte.d.ts +18 -14
  123. package/dist/ui/menu/ContextMenu.svelte +37 -31
  124. package/dist/ui/menu/ContextMenu.svelte.d.ts +38 -25
  125. package/dist/ui/menu/DropDown.svelte +92 -83
  126. package/dist/ui/menu/DropDown.svelte.d.ts +46 -33
  127. package/dist/ui/menu/DropDownMenu.svelte +25 -18
  128. package/dist/ui/menu/DropDownMenu.svelte.d.ts +30 -19
  129. package/dist/ui/mode/ToggleMode.svelte +28 -16
  130. package/dist/ui/mode/ToggleMode.svelte.d.ts +34 -17
  131. package/dist/ui/pagination/Pagination.svelte +9 -8
  132. package/dist/ui/pagination/Pagination.svelte.d.ts +18 -14
  133. package/dist/ui/placeholder/Placeholder.svelte +4 -3
  134. package/dist/ui/placeholder/Placeholder.svelte.d.ts +28 -17
  135. package/dist/ui/placeholder/PlaceholderImage.svelte +6 -4
  136. package/dist/ui/placeholder/PlaceholderImage.svelte.d.ts +28 -17
  137. package/dist/ui/range/RangePicker.svelte +76 -63
  138. package/dist/ui/range/RangePicker.svelte.d.ts +29 -24
  139. package/dist/ui/range/RangePickerButton.svelte +43 -35
  140. package/dist/ui/range/RangePickerButton.svelte.d.ts +21 -17
  141. package/dist/ui/table/Table.svelte +35 -28
  142. package/dist/ui/table/Table.svelte.d.ts +24 -19
  143. package/dist/ui/table/TableBody.svelte +18 -12
  144. package/dist/ui/table/TableBody.svelte.d.ts +20 -15
  145. package/dist/ui/table/TableCell.svelte +13 -10
  146. package/dist/ui/table/TableCell.svelte.d.ts +19 -14
  147. package/dist/ui/table/TableFieldsEdition.svelte +58 -52
  148. package/dist/ui/table/TableFieldsEdition.svelte.d.ts +20 -15
  149. package/dist/ui/table/TableHead.svelte +20 -21
  150. package/dist/ui/table/TableHead.svelte.d.ts +19 -14
  151. package/dist/ui/table/TableViewSelect.svelte +50 -37
  152. package/dist/ui/table/TableViewSelect.svelte.d.ts +27 -23
  153. package/dist/ui/table/cell/TableCellArray.svelte +5 -3
  154. package/dist/ui/table/cell/TableCellArray.svelte.d.ts +18 -14
  155. package/dist/ui/table/cell/TableCellBoolean.svelte +4 -3
  156. package/dist/ui/table/cell/TableCellBoolean.svelte.d.ts +18 -14
  157. package/dist/ui/table/cell/TableCellNumber.svelte +2 -1
  158. package/dist/ui/table/cell/TableCellNumber.svelte.d.ts +18 -14
  159. package/dist/ui/table/cell/TableCellString.svelte +5 -2
  160. package/dist/ui/table/cell/TableCellString.svelte.d.ts +19 -25
  161. package/dist/ui/table/field.d.ts +32 -40
  162. package/dist/ui/table/field.js +1 -1
  163. package/dist/ui/table/head/TableHeadBoolean.svelte +6 -3
  164. package/dist/ui/table/head/TableHeadBoolean.svelte.d.ts +18 -24
  165. package/dist/ui/table/head/TableHeadDate.svelte +61 -113
  166. package/dist/ui/table/head/TableHeadDate.svelte.d.ts +18 -24
  167. package/dist/ui/table/head/TableHeadDefault.svelte +5 -2
  168. package/dist/ui/table/head/TableHeadDefault.svelte.d.ts +18 -24
  169. package/dist/ui/table/head/TableHeadNumber.svelte +67 -76
  170. package/dist/ui/table/head/TableHeadNumber.svelte.d.ts +18 -24
  171. package/dist/ui/table/head/TableHeadSelect.svelte +47 -41
  172. package/dist/ui/table/head/TableHeadSelect.svelte.d.ts +21 -27
  173. package/dist/ui/table/head/TableHeadString.svelte +14 -8
  174. package/dist/ui/table/head/TableHeadString.svelte.d.ts +18 -24
  175. package/dist/ui/tabs/Tabs.svelte +8 -5
  176. package/dist/ui/tabs/Tabs.svelte.d.ts +19 -15
  177. package/dist/ui/tabs/TabsIcon.svelte +31 -28
  178. package/dist/ui/tabs/TabsIcon.svelte.d.ts +21 -17
  179. package/dist/utils/eventEmitter.d.ts +4 -4
  180. package/dist/utils/tippy.d.ts +1 -1
  181. package/dist/validation/form.d.ts +0 -1
  182. package/dist/validation/zod.d.ts +96 -162
  183. package/dist/validation/zod.js +2 -4
  184. package/package.json +134 -138
  185. package/dist/ui/form/FormInput.svelte.d.ts +0 -152
  186. package/dist/ui/form/formInput.d.ts +0 -90
  187. package/dist/ui/slot/Slot.svelte +0 -35
  188. package/dist/ui/slot/Slot.svelte.d.ts +0 -22
  189. package/dist/ui/slot/Span.svelte +0 -4
  190. package/dist/ui/slot/Span.svelte.d.ts +0 -16
  191. package/dist/ui/slot/index.d.ts +0 -1
  192. package/dist/ui/slot/index.js +0 -1
  193. package/dist/ui/table/head/OrderButtons.svelte +0 -37
  194. package/dist/ui/table/head/OrderButtons.svelte.d.ts +0 -20
  195. package/dist/ui/table/head/index.d.ts +0 -19
@@ -1,70 +1,105 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- title?: string | undefined;
5
- /** Key used in url query params */ key: string;
6
- class?: string | undefined;
7
- maxWidth?: string | undefined;
8
- classHeader?: string | undefined;
9
- classBody?: string | undefined;
10
- duration?: number | undefined;
11
- noOverlay?: boolean | undefined;
12
- transitionX?: number | undefined;
13
- zIndex?: number | undefined;
14
- open?: ((value?: number, options?: {
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: Props & {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
11
+ };
12
+ z_$$bindings?: Bindings;
13
+ }
14
+ type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
15
+ default: any;
16
+ } ? Props extends Record<string, never> ? any : {
17
+ children?: any;
18
+ } : {});
19
+ declare const Drawer: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
20
+ title?: string;
21
+ /** Key used in url query params */ key: string;
22
+ class?: string;
23
+ maxWidth?: string;
24
+ classHeader?: string;
25
+ classBody?: string;
26
+ duration?: number;
27
+ noOverlay?: boolean;
28
+ transitionX?: number;
29
+ zIndex?: number;
30
+ open?: (value?: number, options?: {
31
+ replaceState?: boolean | undefined;
32
+ noScroll?: boolean | undefined;
33
+ keepFocus?: boolean | undefined;
34
+ invalidateAll?: boolean | undefined;
35
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
36
+ state?: App.PageState | undefined;
37
+ } | undefined) => Promise<void>;
38
+ close?: (options?: {
39
+ replaceState?: boolean | undefined;
40
+ noScroll?: boolean | undefined;
41
+ keepFocus?: boolean | undefined;
42
+ invalidateAll?: boolean | undefined;
43
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
44
+ state?: App.PageState | undefined;
45
+ } | undefined) => Promise<void>;
46
+ }, {
47
+ default: {
48
+ open: (value?: number, options?: {
15
49
  replaceState?: boolean | undefined;
16
50
  noScroll?: boolean | undefined;
17
51
  keepFocus?: boolean | undefined;
18
52
  invalidateAll?: boolean | undefined;
53
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
19
54
  state?: App.PageState | undefined;
20
- } | undefined) => Promise<void>) | undefined;
21
- close?: ((options?: {
55
+ } | undefined) => Promise<void>;
56
+ close: (options?: {
22
57
  replaceState?: boolean | undefined;
23
58
  noScroll?: boolean | undefined;
24
59
  keepFocus?: boolean | undefined;
25
60
  invalidateAll?: boolean | undefined;
61
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
26
62
  state?: App.PageState | undefined;
27
- } | undefined) => Promise<void>) | undefined;
28
- };
29
- events: {
30
- [evt: string]: CustomEvent<any>;
63
+ } | undefined) => Promise<void>;
31
64
  };
32
- slots: {
33
- default: {
34
- open: (value?: number, options?: {
35
- replaceState?: boolean | undefined;
36
- noScroll?: boolean | undefined;
37
- keepFocus?: boolean | undefined;
38
- invalidateAll?: boolean | undefined;
39
- state?: App.PageState | undefined;
40
- } | undefined) => Promise<void>;
41
- close: (options?: {
42
- replaceState?: boolean | undefined;
43
- noScroll?: boolean | undefined;
44
- keepFocus?: boolean | undefined;
45
- invalidateAll?: boolean | undefined;
46
- state?: App.PageState | undefined;
47
- } | undefined) => Promise<void>;
48
- };
65
+ }>, {
66
+ [evt: string]: CustomEvent<any>;
67
+ }, {
68
+ default: {
69
+ open: (value?: number, options?: {
70
+ replaceState?: boolean | undefined;
71
+ noScroll?: boolean | undefined;
72
+ keepFocus?: boolean | undefined;
73
+ invalidateAll?: boolean | undefined;
74
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
75
+ state?: App.PageState | undefined;
76
+ } | undefined) => Promise<void>;
77
+ close: (options?: {
78
+ replaceState?: boolean | undefined;
79
+ noScroll?: boolean | undefined;
80
+ keepFocus?: boolean | undefined;
81
+ invalidateAll?: boolean | undefined;
82
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
83
+ state?: App.PageState | undefined;
84
+ } | undefined) => Promise<void>;
49
85
  };
50
- };
51
- export type DrawerProps = typeof __propDef.props;
52
- export type DrawerEvents = typeof __propDef.events;
53
- export type DrawerSlots = typeof __propDef.slots;
54
- export default class Drawer extends SvelteComponent<DrawerProps, DrawerEvents, DrawerSlots> {
55
- get open(): (value?: number, options?: {
86
+ }, {
87
+ open: (value?: number, options?: {
56
88
  replaceState?: boolean | undefined;
57
89
  noScroll?: boolean | undefined;
58
90
  keepFocus?: boolean | undefined;
59
91
  invalidateAll?: boolean | undefined;
92
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
60
93
  state?: App.PageState | undefined;
61
94
  } | undefined) => Promise<void>;
62
- get close(): (options?: {
95
+ close: (options?: {
63
96
  replaceState?: boolean | undefined;
64
97
  noScroll?: boolean | undefined;
65
98
  keepFocus?: boolean | undefined;
66
99
  invalidateAll?: boolean | undefined;
100
+ invalidate?: (string | URL | ((url: URL) => boolean))[] | undefined;
67
101
  state?: App.PageState | undefined;
68
102
  } | undefined) => Promise<void>;
69
- }
70
- export {};
103
+ }, string>;
104
+ type Drawer = InstanceType<typeof Drawer>;
105
+ export default Drawer;
@@ -1,4 +1,3 @@
1
- /// <reference types="svelte" />
2
1
  import type { FlyParams, TransitionConfig } from 'svelte/transition';
3
2
  export type DrawerFlyParams = FlyParams & {
4
3
  onTransition?: (pos: {
@@ -1,4 +1,3 @@
1
- /// <reference types="svelte" />
2
1
  import { type Readable } from 'svelte/store';
3
2
  export declare function subscibeDrawerLayers(key: string): {
4
3
  isActive: Readable<boolean>;
@@ -1,92 +1,111 @@
1
- <script context="module"></script>
1
+ <script lang="ts" context="module">
2
+ import type { z } from 'zod'
3
+ import type { FormDataInput } from './form.js'
4
+ </script>
2
5
 
3
6
  <script
4
-
7
+ lang="ts"
5
8
  generics="
6
9
  Shape extends z.ZodRawShape,
7
10
  ReturnData extends Record<string, unknown> = FormDataInput<Shape>,
8
11
  Data extends FormDataInput<Shape> = FormDataInput<Shape>
9
12
  "
10
- >import { createEventDispatcher, onMount } from "svelte";
11
- import { fade } from "svelte/transition";
12
- import { page } from "$app/stores";
13
- import { contextContainer } from "../context.js";
14
- import {
15
- initData,
16
- getFieldType,
17
- useHandleInput
18
- } from "./form.js";
19
- import ButtonDelete from "../button/ButtonDelete.svelte";
20
- import { useForm } from "../../validation/form.js";
21
- import FormInput from "./FormInput.svelte";
22
- import FormSection from "./FormSection.svelte";
23
- let klass = "";
24
- export { klass as class };
25
- export let classSection = "";
26
- export let classAction = "";
27
- export let model = void 0;
28
- export let fields = [];
29
- export let sections = [{}];
30
- export let action = "";
31
- export let actionCreate = "_create";
32
- export let actionDelete = "_delete";
33
- export let actionUpdate = "_update";
34
- export let simpleAction = false;
35
- export let options = {};
36
- let dataInput = initData(fields);
37
- export { dataInput as data };
38
- let data = dataInput;
39
- export function set(key, value) {
40
- isDirty.set(true);
41
- data[key] = value;
42
- }
43
- export function update(updater) {
44
- isDirty.set(true);
45
- data = updater(data);
46
- }
47
- const dispatch = createEventDispatcher();
48
- const { enhance, setError } = useForm({
49
- ...options,
50
- async onSuccess(url, data2) {
51
- if (options.onSuccess)
52
- await options.onSuccess(url, data2);
53
- dispatch("success", { action: url, data: data2 });
54
- const actionPath = url.pathname + url.search;
55
- if (actionPath.includes(action + actionDelete))
56
- dispatch("deleted");
57
- if (!data2)
58
- return;
59
- if (actionPath.includes(action + actionCreate))
60
- dispatch("created", data2);
61
- if (actionPath.includes(action + actionUpdate))
62
- dispatch("updated", data2);
63
- }
64
- });
65
- const { handleInput, isDirty } = useHandleInput({ model, setError });
66
- onMount(lookupValueFromParams);
67
- $:
68
- $isDirty ? dataInput = data : data = dataInput;
69
- function lookupValueFromParams() {
70
- fields.flat().forEach(({ key }) => {
71
- if (data[key])
72
- return;
73
- const value = $page.url.searchParams.get(key);
74
- if (value && key in data)
75
- data[key] = value;
76
- });
77
- }
78
- const actionPadding = getActionPadding();
79
- function getActionPadding() {
80
- const container = contextContainer.get();
81
- if (container === "drawer")
82
- return "bottom-0 -ml-8 -mr-4 pl-8 pr-4";
83
- if (container === "card")
84
- return "bottom-0 -mx-2 sm:-mx-8 px-2 sm:px-8";
85
- if (container === "dialog")
86
- return "-bottom-4 -mx-4 px-4";
87
- return "bottom-0";
88
- }
89
- const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === void 0 ? !!bool : !!bool(_data);
13
+ >
14
+ import { createEventDispatcher, onMount } from 'svelte'
15
+ import { fade } from 'svelte/transition'
16
+ import { page } from '$app/stores'
17
+ import { contextContainer } from '../context.js'
18
+ import {
19
+ initData,
20
+ type FormField,
21
+ type FormSectionProps,
22
+ type BoolOrFunction,
23
+ type Nullable,
24
+ getFieldType,
25
+ useHandleInput
26
+ } from './form.js'
27
+ import ButtonDelete from '../button/ButtonDelete.svelte'
28
+
29
+ import { useForm, type UseFormOptions } from '../../validation/form.js'
30
+ import FormInput from './FormInput.svelte'
31
+ import FormSection from './FormSection.svelte'
32
+
33
+ let klass = ''
34
+ export { klass as class }
35
+ export let classSection = ''
36
+ export let classAction = ''
37
+ export let model: Shape | undefined = undefined
38
+ export let fields: FormField<Shape>[][] = []
39
+ export let sections: FormSectionProps<Shape>[] = [{}]
40
+ export let action = ''
41
+ export let actionCreate = '_create'
42
+ export let actionDelete = '_delete'
43
+ export let actionUpdate = '_update'
44
+ export let disabled = false
45
+
46
+ /** Ignore actionCreate, actionDelete and actionUpdate */
47
+ export let simpleAction = false
48
+
49
+ export let options: UseFormOptions<ReturnData> = {}
50
+ let dataInput: Nullable<Data> = initData<Shape, Data>(fields)
51
+ export { dataInput as data }
52
+
53
+ let data = dataInput
54
+
55
+ export function set<K extends keyof Shape>(key: K, value: Nullable<Data>[K]) {
56
+ isDirty.set(true)
57
+ data[key] = value
58
+ }
59
+ export function update(updater: (currentData: Nullable<Data>) => Nullable<Data>) {
60
+ isDirty.set(true)
61
+ data = updater(data)
62
+ }
63
+
64
+ const dispatch = createEventDispatcher<{
65
+ success: { action: URL; data?: ReturnData }
66
+ created: ReturnData
67
+ updated: ReturnData
68
+ deleted: void
69
+ }>()
70
+
71
+ const { enhance, setError } = useForm<ReturnData>({
72
+ ...options,
73
+ async onSuccess(url, data) {
74
+ if (options.onSuccess) await options.onSuccess(url, data)
75
+ dispatch('success', { action: url, data })
76
+ const actionPath = url.pathname + url.search
77
+ if (actionPath.includes(action + actionDelete)) dispatch('deleted')
78
+ if (!data) return
79
+ if (actionPath.includes(action + actionCreate)) dispatch('created', data)
80
+ if (actionPath.includes(action + actionUpdate)) dispatch('updated', data)
81
+ }
82
+ })
83
+ const { handleInput, isDirty } = useHandleInput({ model, setError })
84
+
85
+ onMount(lookupValueFromParams)
86
+ $: $isDirty ? (dataInput = data) : (data = dataInput)
87
+
88
+ function lookupValueFromParams() {
89
+ fields.flat().forEach(({ key }) => {
90
+ if (data[key]) return
91
+ const value = $page.url.searchParams.get(key)
92
+ // TODO: fix data[key] type
93
+ // @ts-ignore
94
+ if (value && key in data) data[key] = value
95
+ })
96
+ }
97
+
98
+ const actionPadding = getActionPadding()
99
+ function getActionPadding(): string {
100
+ const container = contextContainer.get()
101
+ if (container === 'drawer') return 'bottom-0 -ml-8 -mr-4 pl-8 pr-4'
102
+ if (container === 'card') return 'bottom-0 -mx-2 sm:-mx-8 px-2 sm:px-8'
103
+ if (container === 'dialog') return '-bottom-4 -mx-4 px-4'
104
+ return 'bottom-0'
105
+ }
106
+
107
+ const getBoolean = (bool?: BoolOrFunction<Shape>) => (_data: Nullable<Data>) =>
108
+ typeof bool === 'boolean' || bool === undefined ? !!bool : !!bool(_data)
90
109
  </script>
91
110
 
92
111
  <form
@@ -97,12 +116,12 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
97
116
  use:enhance
98
117
  on:input={handleInput}
99
118
  >
119
+ <slot />
120
+
100
121
  {#if data?.id}
101
122
  <input type="hidden" name="id" value={data.id} />
102
123
  {/if}
103
124
 
104
- <slot />
105
-
106
125
  {#each fields as groupFields, groupIndex}
107
126
  {@const section = sections[groupIndex] || {}}
108
127
  {#if !getBoolean(section?.hide)(data)}
@@ -137,12 +156,12 @@ const getBoolean = (bool) => (_data) => typeof bool === "boolean" || bool === vo
137
156
  sticky col-span-full mt-2 flex flex-row-reverse gap-2 border-t py-4 backdrop-blur-sm
138
157
  "
139
158
  >
140
- <button class="btn btn-primary"> Valider </button>
141
- <div class="grow" />
159
+ <button class="btn btn-primary" {disabled}> Valider </button>
160
+ <div class="grow"></div>
142
161
  {#if !simpleAction && data.id && actionDelete}
143
162
  {@const formaction = `${action}${actionDelete}`}
144
163
  <slot name="delete" {formaction}>
145
- <ButtonDelete {formaction}>Supprimer</ButtonDelete>
164
+ <ButtonDelete {formaction} {disabled}>Supprimer</ButtonDelete>
146
165
  </slot>
147
166
  {/if}
148
167
  </div>
@@ -1,21 +1,21 @@
1
- import { SvelteComponent } from "svelte";
2
1
  import type { z } from 'zod';
3
2
  import type { FormDataInput } from './form.js';
4
3
  import { type FormField, type FormSectionProps, type Nullable } from './form.js';
5
4
  import { type UseFormOptions } from '../../validation/form.js';
6
5
  declare class __sveltets_Render<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>> {
7
6
  props(): {
8
- class?: string | undefined;
9
- classSection?: string | undefined;
10
- classAction?: string | undefined;
7
+ class?: string;
8
+ classSection?: string;
9
+ classAction?: string;
11
10
  model?: Shape | undefined;
12
11
  fields?: FormField<Shape>[][] | undefined;
13
12
  sections?: FormSectionProps<Shape>[] | undefined;
14
- action?: string | undefined;
15
- actionCreate?: string | undefined;
16
- actionDelete?: string | undefined;
17
- actionUpdate?: string | undefined;
18
- /** Ignore actionCreate, actionDelete and actionUpdate */ simpleAction?: boolean | undefined;
13
+ action?: string;
14
+ actionCreate?: string;
15
+ actionDelete?: string;
16
+ actionUpdate?: string;
17
+ disabled?: boolean;
18
+ /** Ignore actionCreate, actionDelete and actionUpdate */ simpleAction?: boolean;
19
19
  options?: UseFormOptions<ReturnData> | undefined;
20
20
  data?: Nullable<Data> | undefined;
21
21
  set?: (<K extends keyof Shape>(key: K, value: Nullable<Data>[K]) => void) | undefined;
@@ -38,12 +38,25 @@ declare class __sveltets_Render<Shape extends z.ZodRawShape, ReturnData extends
38
38
  formaction: any;
39
39
  };
40
40
  };
41
+ bindings(): string;
42
+ exports(): {
43
+ set: <K extends keyof Shape>(key: K, value: Nullable<Data>[K]) => void;
44
+ update: (updater: (currentData: Nullable<Data>) => Nullable<Data>) => void;
45
+ };
41
46
  }
42
- 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']>;
43
- 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']>;
44
- 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']>;
45
- 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>> {
46
- get set(): <K extends keyof Shape>(key: K, value: Nullable<Data>[K]) => void;
47
- get update(): (updater: (currentData: Nullable<Data>) => Nullable<Data>) => void;
47
+ interface $$IsomorphicComponent {
48
+ new <Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<Shape, ReturnData, Data>['props']> & {
49
+ children?: any;
50
+ }>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<Shape, ReturnData, Data>['props']>, ReturnType<__sveltets_Render<Shape, ReturnData, Data>['events']>, ReturnType<__sveltets_Render<Shape, ReturnData, Data>['slots']>> & {
51
+ $$bindings?: ReturnType<__sveltets_Render<Shape, ReturnData, Data>['bindings']>;
52
+ } & ReturnType<__sveltets_Render<Shape, ReturnData, Data>['exports']>;
53
+ <Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>>(internal: unknown, props: ReturnType<__sveltets_Render<Shape, ReturnData, Data>['props']> & {
54
+ $$events?: ReturnType<__sveltets_Render<Shape, ReturnData, Data>['events']>;
55
+ $$slots?: ReturnType<__sveltets_Render<Shape, ReturnData, Data>['slots']>;
56
+ children?: any;
57
+ }): ReturnType<__sveltets_Render<Shape, ReturnData, Data>['exports']>;
58
+ z_$$bindings?: ReturnType<__sveltets_Render<any, any, any>['bindings']>;
48
59
  }
49
- export {};
60
+ declare const Form: $$IsomorphicComponent;
61
+ type Form<Shape extends z.ZodRawShape, ReturnData extends Record<string, unknown> = FormDataInput<Shape>, Data extends FormDataInput<Shape> = FormDataInput<Shape>> = InstanceType<typeof Form<Shape, ReturnData, Data>>;
62
+ export default Form;
@@ -1,9 +1,15 @@
1
- <script generics="InputType extends FormInputsType">import { formInputs } from "./formInput.js";
2
- let inputType;
3
- export { inputType as type };
4
- export let value;
5
- $:
6
- component = formInputs[inputType];
1
+ <script lang="ts" generics="InputType extends FormInputsType">
2
+ import { formInputs, type FormInputProps, type FormInputsType } from './formInput.js'
3
+
4
+ type $$Props = FormInputProps<InputType> & {
5
+ type: InputType
6
+ value: FormInputProps<InputType>['value']
7
+ }
8
+
9
+ let inputType: InputType
10
+ export { inputType as type }
11
+ export let value: FormInputProps<InputType>['value']
12
+ $: component = formInputs[inputType] as any
7
13
  </script>
8
14
 
9
15
  <svelte:component this={component} bind:value {...$$restProps} />
@@ -1,19 +1,26 @@
1
- <script>import { slide } from "svelte/transition";
2
- import { mdiChevronRight } from "@mdi/js";
3
- import { Icon } from "../icon/index.js";
4
- export let title = "";
5
- export let isActive = false;
6
- export let isReducible = false;
7
- let klass = "";
8
- export { klass as class };
9
- export let contentClass = "";
10
- function open() {
11
- isActive = true;
12
- }
13
- function toggle(event) {
14
- event.stopPropagation();
15
- isActive = !isActive;
16
- }
1
+ <script lang="ts">
2
+ import { slide } from 'svelte/transition'
3
+ import { mdiChevronRight } from '@mdi/js'
4
+ import { Icon } from '../icon/index.js'
5
+ type Props = { isActive?: boolean; class?: string; contentClass?: string }
6
+ type $$Props = Props &
7
+ ({ isReducible: true; title: string } | { isReducible?: false; title?: string })
8
+
9
+ export let title = ''
10
+ export let isActive = false
11
+ export let isReducible = false
12
+
13
+ let klass = ''
14
+ export { klass as class }
15
+ export let contentClass = ''
16
+
17
+ function open() {
18
+ isActive = true
19
+ }
20
+ function toggle(event: Event) {
21
+ event.stopPropagation()
22
+ isActive = !isActive
23
+ }
17
24
  </script>
18
25
 
19
26
  <div>
@@ -44,7 +51,7 @@ function toggle(event) {
44
51
  {/if}
45
52
  </slot>
46
53
  {#if isReducible}
47
- <div class="grow" />
54
+ <div class="grow"></div>
48
55
  <button
49
56
  type="button"
50
57
  on:click={toggle}
@@ -1,27 +1,39 @@
1
- import { SvelteComponent } from "svelte";
2
- declare const __propDef: {
3
- props: {
4
- isActive?: boolean | undefined;
5
- class?: string | undefined;
6
- contentClass?: string | undefined;
7
- } & ({
8
- isReducible: true;
9
- title: string;
10
- } | {
11
- isReducible?: false | undefined;
12
- title?: string | undefined;
13
- });
14
- events: {
15
- [evt: string]: CustomEvent<any>;
1
+ interface $$__sveltets_2_IsomorphicComponent<Props extends Record<string, any> = any, Events extends Record<string, any> = any, Slots extends Record<string, any> = any, Exports = {}, Bindings = string> {
2
+ new (options: import('svelte').ComponentConstructorOptions<Props>): import('svelte').SvelteComponent<Props, Events, Slots> & {
3
+ $$bindings?: Bindings;
4
+ } & Exports;
5
+ (internal: unknown, props: Props & {
6
+ $$events?: Events;
7
+ $$slots?: Slots;
8
+ }): Exports & {
9
+ $set?: any;
10
+ $on?: any;
16
11
  };
17
- slots: {
18
- title: {};
19
- default: {};
20
- };
21
- };
22
- export type FormSectionProps = typeof __propDef.props;
23
- export type FormSectionEvents = typeof __propDef.events;
24
- export type FormSectionSlots = typeof __propDef.slots;
25
- export default class FormSection extends SvelteComponent<FormSectionProps, FormSectionEvents, FormSectionSlots> {
12
+ z_$$bindings?: Bindings;
26
13
  }
27
- export {};
14
+ type $$__sveltets_2_PropsWithChildren<Props, Slots> = Props & (Slots extends {
15
+ default: any;
16
+ } ? Props extends Record<string, never> ? any : {
17
+ children?: any;
18
+ } : {});
19
+ declare const FormSection: $$__sveltets_2_IsomorphicComponent<$$__sveltets_2_PropsWithChildren<{
20
+ isActive?: boolean;
21
+ class?: string;
22
+ contentClass?: string;
23
+ } & ({
24
+ isReducible: true;
25
+ title: string;
26
+ } | {
27
+ isReducible?: false;
28
+ title?: string;
29
+ }), {
30
+ title: {};
31
+ default: {};
32
+ }>, {
33
+ [evt: string]: CustomEvent<any>;
34
+ }, {
35
+ title: {};
36
+ default: {};
37
+ }, {}, string>;
38
+ type FormSection = InstanceType<typeof FormSection>;
39
+ export default FormSection;