fuma 0.5.1 → 1.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 (123) hide show
  1. package/dist/private/Meta.svelte +32 -27
  2. package/dist/private/Meta.svelte.d.ts +1 -0
  3. package/dist/private/api.d.ts +1 -1
  4. package/dist/ui/badge/Badge.svelte +4 -3
  5. package/dist/ui/button/ButtonCopy.svelte +32 -26
  6. package/dist/ui/button/ButtonDelete.svelte +23 -21
  7. package/dist/ui/button/ButtonDelete.svelte.d.ts +1 -0
  8. package/dist/ui/card/Card.svelte +13 -10
  9. package/dist/ui/card/Card.svelte.d.ts +1 -0
  10. package/dist/ui/card/CardBasic.svelte +5 -4
  11. package/dist/ui/card/CardBasic.svelte.d.ts +1 -0
  12. package/dist/ui/card/CardCollapse.svelte +35 -31
  13. package/dist/ui/card/CardCollapse.svelte.d.ts +1 -0
  14. package/dist/ui/card/CardFullScreen.svelte +8 -6
  15. package/dist/ui/card/CardFullScreen.svelte.d.ts +3 -0
  16. package/dist/ui/card/CardLink.svelte +5 -4
  17. package/dist/ui/card/CardLink.svelte.d.ts +1 -0
  18. package/dist/ui/dialog/Dialog.svelte +41 -34
  19. package/dist/ui/dialog/Dialog.svelte.d.ts +1 -0
  20. package/dist/ui/dialog/DialogConfirm.svelte +6 -4
  21. package/dist/ui/dialog/DialogConfirm.svelte.d.ts +1 -0
  22. package/dist/ui/drawer/Drawer.svelte +47 -38
  23. package/dist/ui/drawer/Drawer.svelte.d.ts +16 -0
  24. package/dist/ui/form/Form.svelte +101 -83
  25. package/dist/ui/form/Form.svelte.d.ts +1 -0
  26. package/dist/ui/form/FormInput.svelte +12 -6
  27. package/dist/ui/form/FormInput.svelte.d.ts +30 -8
  28. package/dist/ui/form/FormSection.svelte +24 -17
  29. package/dist/ui/form/formInput.d.ts +7 -4
  30. package/dist/ui/icon/Icon.svelte +35 -32
  31. package/dist/ui/index.d.ts +0 -1
  32. package/dist/ui/index.js +0 -1
  33. package/dist/ui/input/FormControl.svelte +48 -36
  34. package/dist/ui/input/FormControl.svelte.d.ts +7 -9
  35. package/dist/ui/input/InputBoolean.svelte +29 -22
  36. package/dist/ui/input/InputBoolean.svelte.d.ts +5 -1
  37. package/dist/ui/input/InputCheckboxs.svelte +37 -34
  38. package/dist/ui/input/InputCheckboxs.svelte.d.ts +5 -1
  39. package/dist/ui/input/InputCheckboxsMenu.svelte +64 -47
  40. package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +5 -1
  41. package/dist/ui/input/InputCheckboxsTree.svelte +9 -6
  42. package/dist/ui/input/InputCheckboxsTreeNodes.svelte +36 -28
  43. package/dist/ui/input/InputCombo.svelte +76 -65
  44. package/dist/ui/input/InputCombo.svelte.d.ts +5 -1
  45. package/dist/ui/input/InputDate.svelte +36 -29
  46. package/dist/ui/input/InputDateTime.svelte +37 -30
  47. package/dist/ui/input/InputImage.svelte +52 -45
  48. package/dist/ui/input/InputImage.svelte.d.ts +1 -0
  49. package/dist/ui/input/InputImagePreview.svelte +24 -20
  50. package/dist/ui/input/InputNumber.svelte +28 -22
  51. package/dist/ui/input/InputNumber.svelte.d.ts +1 -5
  52. package/dist/ui/input/InputOptionInParam.svelte +12 -10
  53. package/dist/ui/input/InputOptions.svelte +40 -34
  54. package/dist/ui/input/InputPassword.svelte +22 -18
  55. package/dist/ui/input/InputPassword.svelte.d.ts +5 -1
  56. package/dist/ui/input/InputRadio.svelte +51 -46
  57. package/dist/ui/input/InputRadio.svelte.d.ts +5 -1
  58. package/dist/ui/input/InputRelation.svelte +119 -111
  59. package/dist/ui/input/InputRelation.svelte.d.ts +6 -12
  60. package/dist/ui/input/InputRelations.svelte +94 -90
  61. package/dist/ui/input/InputRelations.svelte.d.ts +5 -12
  62. package/dist/ui/input/InputSearch.svelte +13 -10
  63. package/dist/ui/input/InputSelect.svelte +59 -46
  64. package/dist/ui/input/InputText.svelte +29 -28
  65. package/dist/ui/input/InputText.svelte.d.ts +0 -3
  66. package/dist/ui/input/InputTextarea.svelte +20 -19
  67. package/dist/ui/input/InputTextarea.svelte.d.ts +1 -5
  68. package/dist/ui/input/InputTime.svelte +43 -35
  69. package/dist/ui/input/RelationAfter.svelte +13 -9
  70. package/dist/ui/input/SelectorList.svelte +16 -12
  71. package/dist/ui/input/SelectorList.svelte.d.ts +4 -0
  72. package/dist/ui/input/textRich/InputTextRich.svelte +63 -54
  73. package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +5 -1
  74. package/dist/ui/input/textRich/SuggesionList.svelte +13 -9
  75. package/dist/ui/input/textRich/ToolMark.svelte +12 -9
  76. package/dist/ui/input/textRich/ToolMarkColor.svelte +16 -12
  77. package/dist/ui/input/textRich/ToolMarkLink.svelte +46 -38
  78. package/dist/ui/input/textRich/ToolMenu.svelte +34 -19
  79. package/dist/ui/input/textRich/ToolMenuAlign.svelte +13 -9
  80. package/dist/ui/input/textRich/ToolMenuInsert.svelte +12 -7
  81. package/dist/ui/input/textRich/ToolMenuNode.svelte +14 -10
  82. package/dist/ui/input/textRich/ToolsBar.svelte +17 -13
  83. package/dist/ui/login/Login.svelte +37 -31
  84. package/dist/ui/menu/ContextMenu.svelte +37 -31
  85. package/dist/ui/menu/ContextMenu.svelte.d.ts +1 -0
  86. package/dist/ui/menu/DropDown.svelte +92 -83
  87. package/dist/ui/menu/DropDown.svelte.d.ts +1 -0
  88. package/dist/ui/menu/DropDownMenu.svelte +25 -18
  89. package/dist/ui/menu/DropDownMenu.svelte.d.ts +1 -0
  90. package/dist/ui/mode/ToggleMode.svelte +15 -14
  91. package/dist/ui/mode/ToggleMode.svelte.d.ts +6 -1
  92. package/dist/ui/pagination/Pagination.svelte +9 -8
  93. package/dist/ui/placeholder/Placeholder.svelte +4 -3
  94. package/dist/ui/placeholder/Placeholder.svelte.d.ts +1 -0
  95. package/dist/ui/placeholder/PlaceholderImage.svelte +6 -4
  96. package/dist/ui/placeholder/PlaceholderImage.svelte.d.ts +1 -0
  97. package/dist/ui/range/RangePicker.svelte +76 -63
  98. package/dist/ui/range/RangePickerButton.svelte +43 -35
  99. package/dist/ui/table/Table.svelte +35 -28
  100. package/dist/ui/table/TableBody.svelte +18 -12
  101. package/dist/ui/table/TableCell.svelte +13 -10
  102. package/dist/ui/table/TableFieldsEdition.svelte +57 -51
  103. package/dist/ui/table/TableHead.svelte +19 -20
  104. package/dist/ui/table/TableViewSelect.svelte +50 -37
  105. package/dist/ui/table/cell/TableCellArray.svelte +5 -3
  106. package/dist/ui/table/cell/TableCellBoolean.svelte +4 -3
  107. package/dist/ui/table/cell/TableCellNumber.svelte +2 -1
  108. package/dist/ui/table/cell/TableCellString.svelte +5 -2
  109. package/dist/ui/table/head/TableHeadBoolean.svelte +6 -3
  110. package/dist/ui/table/head/TableHeadDate.svelte +54 -47
  111. package/dist/ui/table/head/TableHeadDefault.svelte +5 -2
  112. package/dist/ui/table/head/TableHeadNumber.svelte +65 -53
  113. package/dist/ui/table/head/TableHeadSelect.svelte +47 -41
  114. package/dist/ui/table/head/TableHeadString.svelte +14 -8
  115. package/dist/ui/tabs/Tabs.svelte +8 -5
  116. package/dist/ui/tabs/TabsIcon.svelte +31 -28
  117. package/package.json +32 -33
  118. package/dist/ui/slot/Slot.svelte +0 -35
  119. package/dist/ui/slot/Slot.svelte.d.ts +0 -22
  120. package/dist/ui/slot/Span.svelte +0 -4
  121. package/dist/ui/slot/Span.svelte.d.ts +0 -16
  122. package/dist/ui/slot/index.d.ts +0 -1
  123. package/dist/ui/slot/index.js +0 -1
@@ -1,54 +1,60 @@
1
- <script generics="Item extends {id: string}">import {
2
- mdiCheck,
3
- mdiCheckCircleOutline,
4
- mdiCircleSmall,
5
- mdiDotsHorizontal,
6
- mdiDrag,
7
- mdiPlus
8
- } from "@mdi/js";
9
- import { goto } from "$app/navigation";
10
- import { page } from "$app/stores";
11
- import { urlParam } from "../../store/param.js";
12
- import { listEditable } from "../../action/list/index.js";
13
- import { jsonParse } from "../../utils/jsonParse.js";
14
- import { context } from "./context.js";
15
- import { Icon } from "../icon/index.js";
16
- import { DropDown } from "../menu/index.js";
17
- export let fields;
18
- export let key;
19
- export let onCreateField = void 0;
20
- let tip;
21
- const { KEY_FIELDS_VISIBLE, KEY_FIELDS_HIDDEN, KEY_FIELDS_ORDER } = context.get(key);
22
- function getFieldHref(field) {
23
- if (field.locked)
24
- return;
25
- const url = toggleParam(field.visible ? KEY_FIELDS_HIDDEN : KEY_FIELDS_VISIBLE, field.key);
26
- if (url.searchParams.has(field.key)) {
27
- url.searchParams.delete(field.key);
28
- url.searchParams.delete("skip");
29
- url.searchParams.delete("take");
30
- }
31
- return url.pathname + url.search;
32
- }
33
- function toggleParam(paramKey, fieldKey) {
34
- const url = new URL($page.url);
35
- const fieldsKeys = jsonParse($page.url.searchParams.get(paramKey), []);
36
- if (!fieldsKeys.includes(fieldKey))
37
- fieldsKeys.push(fieldKey);
38
- else
39
- fieldsKeys.splice(fieldsKeys.indexOf(fieldKey), 1);
40
- if (fieldsKeys.length)
41
- url.searchParams.set(paramKey, JSON.stringify(fieldsKeys));
42
- else
43
- url.searchParams.delete(paramKey);
44
- return url;
45
- }
46
- function handleReorder(newFieldsOrder) {
47
- fields = newFieldsOrder;
48
- const fieldsOrder = fields.map((f) => f.key);
49
- const newUrl = $urlParam.with({ [KEY_FIELDS_ORDER]: JSON.stringify(fieldsOrder) });
50
- goto(newUrl, { replaceState: true, noScroll: true, keepFocus: true });
51
- }
1
+ <script lang="ts" generics="Item extends {id: string}">
2
+ import {
3
+ mdiCheck,
4
+ mdiCheckCircleOutline,
5
+ mdiCircleSmall,
6
+ mdiDotsHorizontal,
7
+ mdiDrag,
8
+ mdiPlus
9
+ } from '@mdi/js'
10
+ import type { TippyInstance } from '../../utils/tippy.js'
11
+ import { goto } from '$app/navigation'
12
+ import { page } from '$app/stores'
13
+ import { urlParam } from '../../store/param.js'
14
+ import { listEditable } from '../../action/list/index.js'
15
+ import { jsonParse } from '../../utils/jsonParse.js'
16
+ import { context } from './context.js'
17
+ import { Icon } from '../icon/index.js'
18
+ import { DropDown } from '../menu/index.js'
19
+ import type { TableField } from './index.js'
20
+
21
+ export let fields: TableField<Item>[]
22
+ export let key: string
23
+ export let onCreateField: (() => void) | undefined = undefined
24
+
25
+ let tip: TippyInstance
26
+
27
+ const { KEY_FIELDS_VISIBLE, KEY_FIELDS_HIDDEN, KEY_FIELDS_ORDER } = context.get(key)
28
+
29
+ function getFieldHref(field: TableField) {
30
+ if (field.locked) return
31
+ const url = toggleParam(field.visible ? KEY_FIELDS_HIDDEN : KEY_FIELDS_VISIBLE, field.key)
32
+ if (url.searchParams.has(field.key)) {
33
+ url.searchParams.delete(field.key)
34
+ url.searchParams.delete('skip')
35
+ url.searchParams.delete('take')
36
+ }
37
+ return url.pathname + url.search
38
+ }
39
+
40
+ function toggleParam(paramKey: string, fieldKey: string): URL {
41
+ const url = new URL($page.url)
42
+ const fieldsKeys = jsonParse<string[]>($page.url.searchParams.get(paramKey), [])
43
+ if (!fieldsKeys.includes(fieldKey)) fieldsKeys.push(fieldKey)
44
+ else fieldsKeys.splice(fieldsKeys.indexOf(fieldKey), 1)
45
+
46
+ if (fieldsKeys.length) url.searchParams.set(paramKey, JSON.stringify(fieldsKeys))
47
+ else url.searchParams.delete(paramKey)
48
+
49
+ return url
50
+ }
51
+
52
+ function handleReorder(newFieldsOrder: TableField<Item>[]) {
53
+ fields = newFieldsOrder
54
+ const fieldsOrder = fields.map((f) => f.key)
55
+ const newUrl = $urlParam.with({ [KEY_FIELDS_ORDER]: JSON.stringify(fieldsOrder) })
56
+ goto(newUrl, { replaceState: true, noScroll: true, keepFocus: true })
57
+ }
52
58
  </script>
53
59
 
54
60
  <th class="sticky right-0 z-10 p-0 px-1" align="right">
@@ -1,23 +1,22 @@
1
- <script generics="Item extends {id: string}">import { component } from "../../utils/component.js";
2
- import { TableFieldsEdition } from "./index.js";
3
- import { tableHeadComponent } from "./head/index.js";
4
- import TableHeadDefault from "./head/TableHeadDefault.svelte";
5
- export let fields;
6
- export let key;
7
- export let onCreateField = void 0;
8
- function getComponent(field) {
9
- if (field.type === "select" || field.type === "multiselect")
10
- return tableHeadComponent(field.type, { options: field.options || [] })(field);
11
- if (field.type)
12
- return tableHeadComponent(field.type, {})(field);
13
- if (!field.head)
14
- return component(TableHeadDefault, { field });
15
- if (typeof field.head === "function")
16
- return field.head(field);
17
- if (typeof field.head === "string")
18
- return tableHeadComponent(field.head, {})(field);
19
- return field.head;
20
- }
1
+ <script lang="ts" generics="Item extends {id: string}">
2
+ import { component, type ComponentAndProps } from '../../utils/component.js'
3
+ import { type TableField, TableFieldsEdition } from './index.js'
4
+ import { tableHeadComponent } from './head/index.js'
5
+ import TableHeadDefault from './head/TableHeadDefault.svelte'
6
+
7
+ export let fields: TableField<Item>[]
8
+ export let key: string
9
+ export let onCreateField: (() => void) | undefined = undefined
10
+
11
+ function getComponent(field: TableField): ComponentAndProps {
12
+ if (field.type === 'select' || field.type === 'multiselect')
13
+ return tableHeadComponent(field.type, { options: field.options || [] })(field)
14
+ if (field.type) return tableHeadComponent(field.type, {})(field)
15
+ if (!field.head) return component(TableHeadDefault, { field })
16
+ if (typeof field.head === 'function') return field.head(field)
17
+ if (typeof field.head === 'string') return tableHeadComponent(field.head, {})(field)
18
+ return field.head
19
+ }
21
20
  </script>
22
21
 
23
22
  <thead>
@@ -1,40 +1,53 @@
1
- <script>import { onMount } from "svelte";
2
- import { mdiChevronDown, mdiContentSaveEditOutline, mdiPlus } from "@mdi/js";
3
- import { page } from "$app/stores";
4
- import { enhance } from "$app/forms";
5
- import { Icon } from "../icon/index.js";
6
- import { Dialog } from "../dialog/index.js";
7
- import { DropDown } from "../menu/index.js";
8
- import { InputText } from "../input/index.js";
9
- import { useForm } from "../../validation/form.js";
10
- export let key;
11
- export let views;
12
- export let action = "";
13
- export let actionCreate = "?/view_create";
14
- export let actionUpdate = "?/view_update";
15
- export let actionDelete = "?/view_delete";
16
- let dialog;
17
- const form = useForm({
18
- onSuccess() {
19
- dialog.close();
20
- }
21
- });
22
- let query = getQuery($page.url);
23
- let selectedView = views.find((v) => v.query === query);
24
- let isNewView = !!query && !selectedView;
25
- onMount(
26
- () => page.subscribe(({ url }) => {
27
- query = getQuery(url);
28
- selectedView = views.find((v) => v.query === query);
29
- isNewView = !!query && !selectedView;
30
- })
31
- );
32
- function getQuery({ searchParams }) {
33
- const searchParam = new URLSearchParams(searchParams);
34
- searchParam.delete("skip");
35
- searchParam.delete("take");
36
- return searchParam.toString();
37
- }
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte'
3
+ import { mdiChevronDown, mdiContentSaveEditOutline, mdiPlus } from '@mdi/js'
4
+ import { page } from '$app/stores'
5
+ import { enhance } from '$app/forms'
6
+
7
+ import { Icon } from '../icon/index.js'
8
+ import { Dialog } from '../dialog/index.js'
9
+ import { DropDown } from '../menu/index.js'
10
+ import { InputText } from '../input/index.js'
11
+ import { useForm } from '../../validation/form.js'
12
+
13
+ type View = {
14
+ id: string
15
+ name: string
16
+ query: string
17
+ }
18
+
19
+ export let key: string
20
+ export let views: View[]
21
+ export let action = ''
22
+ export let actionCreate = '?/view_create'
23
+ export let actionUpdate = '?/view_update'
24
+ export let actionDelete = '?/view_delete'
25
+
26
+ let dialog: HTMLDialogElement
27
+ const form = useForm({
28
+ onSuccess() {
29
+ dialog.close()
30
+ }
31
+ })
32
+
33
+ let query = getQuery($page.url)
34
+ let selectedView = views.find((v) => v.query === query)
35
+ let isNewView = !!query && !selectedView
36
+
37
+ onMount(() =>
38
+ page.subscribe(({ url }) => {
39
+ query = getQuery(url)
40
+ selectedView = views.find((v) => v.query === query)
41
+ isNewView = !!query && !selectedView
42
+ })
43
+ )
44
+
45
+ function getQuery({ searchParams }: URL) {
46
+ const searchParam = new URLSearchParams(searchParams)
47
+ searchParam.delete('skip')
48
+ searchParam.delete('take')
49
+ return searchParam.toString()
50
+ }
38
51
  </script>
39
52
 
40
53
  <DropDown>
@@ -1,6 +1,8 @@
1
- <script>import { Badge } from "../../badge/index.js";
2
- import { component } from "../../../utils/component.js";
3
- export let value;
1
+ <script lang="ts">
2
+ import { Badge } from '../../badge/index.js'
3
+ import { component, type ComponentAndProps } from '../../../utils/component.js'
4
+
5
+ export let value: (ComponentAndProps | string | number | boolean)[]
4
6
  </script>
5
7
 
6
8
  <td>
@@ -1,6 +1,7 @@
1
- <script>import { mdiCheck, mdiClose } from "@mdi/js";
2
- import { Icon } from "../../icon/index.js";
3
- export let value;
1
+ <script lang="ts">
2
+ import { mdiCheck, mdiClose } from '@mdi/js'
3
+ import { Icon } from '../../icon/index.js'
4
+ export let value: boolean
4
5
  </script>
5
6
 
6
7
  <td>
@@ -1,4 +1,5 @@
1
- <script>export let value;
1
+ <script lang="ts">
2
+ export let value: number
2
3
  </script>
3
4
 
4
5
  <td>
@@ -1,5 +1,8 @@
1
- <script>export let value;
2
- export let field;
1
+ <script lang="ts">
2
+ import type { TableField } from '../index.js'
3
+
4
+ export let value: string
5
+ export let field: TableField
3
6
  </script>
4
7
 
5
8
  <td data-field-key={field.key} data-field-type={field.type === 'textarea' ? 'textarea' : 'string'}>
@@ -1,6 +1,9 @@
1
- <script>import { mdiCheck, mdiClose } from "@mdi/js";
2
- import TableHeadSelect from "./TableHeadSelect.svelte";
3
- export let field;
1
+ <script lang="ts">
2
+ import { mdiCheck, mdiClose } from '@mdi/js'
3
+ import type { TableField } from '../index.js'
4
+ import TableHeadSelect from './TableHeadSelect.svelte'
5
+
6
+ export let field: TableField
4
7
  </script>
5
8
 
6
9
  <TableHeadSelect
@@ -1,50 +1,57 @@
1
- <script>import { goto } from "$app/navigation";
2
- import { page } from "$app/stores";
3
- import { mdiCalendarFilterOutline } from "@mdi/js";
4
- import { DropDown } from "../../menu/index.js";
5
- import { InputTime } from "../../input/index.js";
6
- import { formatRange } from "../../range/format.js";
7
- import { RangePicker } from "../../range/index.js";
8
- import { urlParam } from "../../../store/param.js";
9
- import { jsonParse } from "../../../utils/jsonParse.js";
10
- import { Icon } from "../../icon/index.js";
11
- export let field;
12
- let dropDown;
13
- let rangePicker;
14
- const initialValue = jsonParse(
15
- $page.url.searchParams.get(field.key),
16
- {}
17
- );
18
- let range = {
19
- start: initialValue.start ? new Date(initialValue.start) : null,
20
- end: initialValue.end ? new Date(initialValue.end) : null
21
- };
22
- $:
23
- isValidPeriod = !!range.start && !!range.end;
24
- function handleSubmit() {
25
- dropDown.hide();
26
- if (!isValidPeriod)
27
- return;
28
- goto(
29
- $urlParam.with(
30
- {
31
- [field.key]: JSON.stringify({
32
- start: range.start?.toJSON(),
33
- end: range.end?.toJSON()
34
- })
35
- },
36
- "skip",
37
- "take"
38
- ),
39
- { replaceState: true, noScroll: true }
40
- );
41
- }
42
- function handleReset() {
43
- dropDown.hide();
44
- range = { start: null, end: null };
45
- rangePicker.clear();
46
- goto($urlParam.without(field.key, "skip", "take"), { replaceState: true, noScroll: true });
47
- }
1
+ <script lang="ts">
2
+ import { goto } from '$app/navigation'
3
+ import { page } from '$app/stores'
4
+ import { mdiCalendarFilterOutline } from '@mdi/js'
5
+
6
+ import { DropDown } from '../../menu/index.js'
7
+ import { InputTime } from '../../input/index.js'
8
+ import type { TableField } from '../index.js'
9
+ import { formatRange } from '../../range/format.js'
10
+ import { RangePicker } from '../../range/index.js'
11
+ import { urlParam } from '../../../store/param.js'
12
+ import { jsonParse } from '../../../utils/jsonParse.js'
13
+ import { Icon } from '../../icon/index.js'
14
+
15
+ export let field: Omit<TableField, 'getCell' | 'type'>
16
+
17
+ let dropDown: DropDown
18
+ let rangePicker: RangePicker
19
+ const initialValue = jsonParse<{ start?: string; end?: string }>(
20
+ $page.url.searchParams.get(field.key),
21
+ {}
22
+ )
23
+
24
+ let range = {
25
+ start: initialValue.start ? new Date(initialValue.start) : null,
26
+ end: initialValue.end ? new Date(initialValue.end) : null
27
+ }
28
+
29
+ $: isValidPeriod = !!range.start && !!range.end
30
+
31
+ function handleSubmit() {
32
+ dropDown.hide()
33
+ if (!isValidPeriod) return
34
+ goto(
35
+ $urlParam.with(
36
+ {
37
+ [field.key]: JSON.stringify({
38
+ start: range.start?.toJSON(),
39
+ end: range.end?.toJSON()
40
+ })
41
+ },
42
+ 'skip',
43
+ 'take'
44
+ ),
45
+ { replaceState: true, noScroll: true }
46
+ )
47
+ }
48
+
49
+ function handleReset() {
50
+ dropDown.hide()
51
+ range = { start: null, end: null }
52
+ rangePicker.clear()
53
+ goto($urlParam.without(field.key, 'skip', 'take'), { replaceState: true, noScroll: true })
54
+ }
48
55
  </script>
49
56
 
50
57
  <th class="p-1">
@@ -1,5 +1,8 @@
1
- <script>import { tip } from "../../../action/tip.js";
2
- export let field;
1
+ <script lang="ts">
2
+ import type { TableField } from '../index.js'
3
+ import { tip } from '../../../action/tip.js'
4
+
5
+ export let field: TableField
3
6
  </script>
4
7
 
5
8
  <th use:tip={{ disable: !field.hint, content: field.hint }}>
@@ -1,56 +1,68 @@
1
- <script>import { onMount } from "svelte";
2
- import debounce from "debounce";
3
- import { goto } from "$app/navigation";
4
- import { page } from "$app/stores";
5
- import { DropDown } from "../../menu/index.js";
6
- import { InputNumber } from "../../input/index.js";
7
- import { urlParam } from "../../../store/param.js";
8
- import { jsonParse } from "../../../utils/jsonParse.js";
9
- import { mdiFilterMultipleOutline } from "@mdi/js";
10
- import { Icon } from "../../icon/index.js";
11
- export let field;
12
- let tip;
13
- let { min, max } = initRange($page.url);
14
- onMount(() => page.subscribe(({ url }) => ({ min, max } = initRange(url))));
15
- function initRange({ searchParams }) {
16
- return jsonParse(searchParams.get(field.key), {
17
- min: void 0,
18
- max: void 0
19
- });
20
- }
21
- const udpateUrl = debounce(() => {
22
- if (isDefined(min) || isDefined(max)) {
23
- goto(
24
- $urlParam.with(
25
- {
26
- [field.key]: JSON.stringify({
27
- ...isDefined(min) ? { min } : {},
28
- ...isDefined(max) ? { max } : {}
29
- })
30
- },
31
- "skip",
32
- "take"
33
- ),
34
- {
35
- noScroll: true,
36
- keepFocus: true
37
- }
38
- );
39
- return;
40
- }
41
- goto($urlParam.without(field.key, "skip", "take"), { noScroll: true, keepFocus: true });
42
- }, 250);
43
- function handleReset() {
44
- min = void 0;
45
- max = void 0;
46
- tip.hide();
47
- goto($urlParam.without(field.key, "skip", "take"), { noScroll: true, keepFocus: true });
48
- }
49
- function isDefined(v) {
50
- return typeof v === "number";
51
- }
52
- $:
53
- isNegatifRange = isDefined(min) && isDefined(max) && max < min;
1
+ <script lang="ts">
2
+ import { onMount } from 'svelte'
3
+ import type { TippyInstance } from '../../../utils/tippy.js'
4
+ import debounce from 'debounce'
5
+ import { goto } from '$app/navigation'
6
+ import { page } from '$app/stores'
7
+
8
+ import { DropDown } from '../../menu/index.js'
9
+ import { InputNumber } from '../../input/index.js'
10
+ import { urlParam } from '../../../store/param.js'
11
+ import { jsonParse } from '../../../utils/jsonParse.js'
12
+ import type { TableField } from '../field.js'
13
+ import { mdiFilterMultipleOutline } from '@mdi/js'
14
+ import { Icon } from '../../icon/index.js'
15
+
16
+ export let field: TableField
17
+
18
+ let tip: TippyInstance
19
+ type Range = { min: number | undefined; max: number | undefined }
20
+
21
+ let { min, max } = initRange($page.url)
22
+ onMount(() => page.subscribe(({ url }) => ({ min, max } = initRange(url))))
23
+
24
+ function initRange({ searchParams }: URL) {
25
+ return jsonParse<Range>(searchParams.get(field.key), {
26
+ min: undefined,
27
+ max: undefined
28
+ })
29
+ }
30
+
31
+ const udpateUrl = debounce(() => {
32
+ if (isDefined(min) || isDefined(max)) {
33
+ goto(
34
+ $urlParam.with(
35
+ {
36
+ [field.key]: JSON.stringify({
37
+ ...(isDefined(min) ? { min } : {}),
38
+ ...(isDefined(max) ? { max } : {})
39
+ })
40
+ },
41
+ 'skip',
42
+ 'take'
43
+ ),
44
+ {
45
+ noScroll: true,
46
+ keepFocus: true
47
+ }
48
+ )
49
+ return
50
+ }
51
+ goto($urlParam.without(field.key, 'skip', 'take'), { noScroll: true, keepFocus: true })
52
+ }, 250)
53
+
54
+ function handleReset() {
55
+ min = undefined
56
+ max = undefined
57
+ tip.hide()
58
+ goto($urlParam.without(field.key, 'skip', 'take'), { noScroll: true, keepFocus: true })
59
+ }
60
+
61
+ function isDefined(v: number | undefined | null): v is number {
62
+ return typeof v === 'number'
63
+ }
64
+
65
+ $: isNegatifRange = isDefined(min) && isDefined(max) && max < min
54
66
  </script>
55
67
 
56
68
  <th class="p-1">