fuma 1.0.21 → 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.
- package/README.md +1 -1
- package/dist/action/list/handlers.d.ts +2 -2
- package/dist/action/list/index.d.ts +2 -0
- package/dist/action/list/index.js +1 -0
- package/dist/action/list/trigger.d.ts +7 -1
- package/dist/action/list/trigger.js +2 -2
- package/dist/private/Meta.svelte +32 -27
- package/dist/private/Meta.svelte.d.ts +29 -17
- package/dist/private/api.d.ts +1 -1
- package/dist/private/store.d.ts +0 -1
- package/dist/server/parseFormData.d.ts +1 -1
- package/dist/server/parseQuery.d.ts +1 -1
- package/dist/server/sse.d.ts +0 -1
- package/dist/store/isSmallScreen.d.ts +0 -1
- package/dist/store/param.d.ts +0 -2
- package/dist/store/session.d.ts +0 -1
- package/dist/ui/badge/Badge.svelte +4 -3
- package/dist/ui/badge/Badge.svelte.d.ts +19 -15
- package/dist/ui/button/ButtonCopy.svelte +35 -32
- package/dist/ui/button/ButtonCopy.svelte.d.ts +23 -21
- package/dist/ui/button/ButtonDelete.svelte +23 -21
- package/dist/ui/button/ButtonDelete.svelte.d.ts +32 -20
- package/dist/ui/card/Card.svelte +13 -10
- package/dist/ui/card/Card.svelte.d.ts +39 -24
- package/dist/ui/card/CardBasic.svelte +5 -4
- package/dist/ui/card/CardBasic.svelte.d.ts +29 -18
- package/dist/ui/card/CardCollapse.svelte +35 -31
- package/dist/ui/card/CardCollapse.svelte.d.ts +37 -23
- package/dist/ui/card/CardFullScreen.svelte +8 -6
- package/dist/ui/card/CardFullScreen.svelte.d.ts +35 -20
- package/dist/ui/card/CardLink.svelte +5 -4
- package/dist/ui/card/CardLink.svelte.d.ts +29 -18
- package/dist/ui/dialog/Dialog.svelte +41 -34
- package/dist/ui/dialog/Dialog.svelte.d.ts +36 -23
- package/dist/ui/dialog/DialogConfirm.svelte +6 -4
- package/dist/ui/dialog/DialogConfirm.svelte.d.ts +33 -19
- package/dist/ui/drawer/Drawer.svelte +47 -38
- package/dist/ui/drawer/Drawer.svelte.d.ts +81 -46
- package/dist/ui/drawer/drawerFly.d.ts +0 -1
- package/dist/ui/drawer/layers.d.ts +0 -1
- package/dist/ui/form/Form.svelte +106 -87
- package/dist/ui/form/Form.svelte.d.ts +29 -16
- package/dist/ui/form/FormInput.svelte +12 -6
- package/dist/ui/form/FormSection.svelte +24 -17
- package/dist/ui/form/FormSection.svelte.d.ts +37 -25
- package/dist/ui/icon/Icon.svelte +35 -32
- package/dist/ui/icon/Icon.svelte.d.ts +25 -21
- package/dist/ui/index.d.ts +0 -1
- package/dist/ui/index.js +0 -1
- package/dist/ui/input/FormControl.svelte +48 -36
- package/dist/ui/input/FormControl.svelte.d.ts +32 -30
- package/dist/ui/input/InputBoolean.svelte +29 -22
- package/dist/ui/input/InputBoolean.svelte.d.ts +43 -35
- package/dist/ui/input/InputCheckboxs.svelte +37 -34
- package/dist/ui/input/InputCheckboxs.svelte.d.ts +54 -39
- package/dist/ui/input/InputCheckboxsMenu.svelte +64 -47
- package/dist/ui/input/InputCheckboxsMenu.svelte.d.ts +56 -41
- package/dist/ui/input/InputCheckboxsTree.svelte +9 -6
- package/dist/ui/input/InputCheckboxsTree.svelte.d.ts +22 -18
- package/dist/ui/input/InputCheckboxsTreeNodes.svelte +36 -28
- package/dist/ui/input/InputCheckboxsTreeNodes.svelte.d.ts +20 -16
- package/dist/ui/input/InputCombo.svelte +76 -65
- package/dist/ui/input/InputCombo.svelte.d.ts +55 -39
- package/dist/ui/input/InputDate.svelte +36 -29
- package/dist/ui/input/InputDate.svelte.d.ts +20 -16
- package/dist/ui/input/InputDateTime.svelte +37 -30
- package/dist/ui/input/InputDateTime.svelte.d.ts +20 -16
- package/dist/ui/input/InputImage.svelte +52 -45
- package/dist/ui/input/InputImage.svelte.d.ts +40 -27
- package/dist/ui/input/InputImagePreview.svelte +24 -20
- package/dist/ui/input/InputImagePreview.svelte.d.ts +25 -21
- package/dist/ui/input/InputNumber.svelte +28 -22
- package/dist/ui/input/InputNumber.svelte.d.ts +20 -20
- package/dist/ui/input/InputOptionInParam.svelte +12 -10
- package/dist/ui/input/InputOptionInParam.svelte.d.ts +21 -17
- package/dist/ui/input/InputOptions.svelte +40 -34
- package/dist/ui/input/InputOptions.svelte.d.ts +19 -15
- package/dist/ui/input/InputPassword.svelte +22 -18
- package/dist/ui/input/InputPassword.svelte.d.ts +43 -35
- package/dist/ui/input/InputRadio.svelte +51 -46
- package/dist/ui/input/InputRadio.svelte.d.ts +53 -38
- package/dist/ui/input/InputRelation.svelte +129 -112
- package/dist/ui/input/InputRelation.svelte.d.ts +39 -53
- package/dist/ui/input/InputRelations.svelte +96 -90
- package/dist/ui/input/InputRelations.svelte.d.ts +35 -37
- package/dist/ui/input/InputSearch.svelte +14 -11
- package/dist/ui/input/InputSearch.svelte.d.ts +25 -21
- package/dist/ui/input/InputSelect.svelte +59 -46
- package/dist/ui/input/InputSelect.svelte.d.ts +23 -19
- package/dist/ui/input/InputText.svelte +29 -28
- package/dist/ui/input/InputText.svelte.d.ts +41 -28
- package/dist/ui/input/InputTextarea.svelte +20 -19
- package/dist/ui/input/InputTextarea.svelte.d.ts +20 -20
- package/dist/ui/input/InputTime.svelte +43 -36
- package/dist/ui/input/InputTime.svelte.d.ts +21 -36
- package/dist/ui/input/RelationAfter.svelte +13 -9
- package/dist/ui/input/RelationAfter.svelte.d.ts +24 -20
- package/dist/ui/input/SelectorList.svelte +16 -12
- package/dist/ui/input/SelectorList.svelte.d.ts +29 -20
- package/dist/ui/input/textRich/InputTextRich.svelte +63 -59
- package/dist/ui/input/textRich/InputTextRich.svelte.d.ts +36 -38
- package/dist/ui/input/textRich/SuggesionList.svelte +13 -9
- package/dist/ui/input/textRich/SuggesionList.svelte.d.ts +19 -15
- package/dist/ui/input/textRich/ToolMark.svelte +12 -9
- package/dist/ui/input/textRich/ToolMark.svelte.d.ts +22 -18
- package/dist/ui/input/textRich/ToolMarkColor.svelte +16 -12
- package/dist/ui/input/textRich/ToolMarkColor.svelte.d.ts +21 -17
- package/dist/ui/input/textRich/ToolMarkLink.svelte +46 -38
- package/dist/ui/input/textRich/ToolMarkLink.svelte.d.ts +18 -14
- package/dist/ui/input/textRich/ToolMenu.svelte +34 -19
- package/dist/ui/input/textRich/ToolMenu.svelte.d.ts +30 -26
- package/dist/ui/input/textRich/ToolMenuAlign.svelte +13 -9
- package/dist/ui/input/textRich/ToolMenuAlign.svelte.d.ts +18 -14
- package/dist/ui/input/textRich/ToolMenuInsert.svelte +12 -7
- package/dist/ui/input/textRich/ToolMenuInsert.svelte.d.ts +20 -16
- package/dist/ui/input/textRich/ToolMenuNode.svelte +14 -10
- package/dist/ui/input/textRich/ToolMenuNode.svelte.d.ts +18 -14
- package/dist/ui/input/textRich/ToolsBar.svelte +21 -14
- package/dist/ui/input/textRich/ToolsBar.svelte.d.ts +19 -17
- package/dist/ui/input/textRich/suggestion.d.ts +0 -1
- package/dist/ui/login/Login.svelte +37 -31
- package/dist/ui/login/Login.svelte.d.ts +18 -14
- package/dist/ui/menu/ContextMenu.svelte +37 -31
- package/dist/ui/menu/ContextMenu.svelte.d.ts +38 -25
- package/dist/ui/menu/DropDown.svelte +92 -83
- package/dist/ui/menu/DropDown.svelte.d.ts +46 -33
- package/dist/ui/menu/DropDownMenu.svelte +25 -18
- package/dist/ui/menu/DropDownMenu.svelte.d.ts +30 -19
- package/dist/ui/mode/ToggleMode.svelte +28 -16
- package/dist/ui/mode/ToggleMode.svelte.d.ts +34 -17
- package/dist/ui/pagination/Pagination.svelte +9 -8
- package/dist/ui/pagination/Pagination.svelte.d.ts +18 -14
- package/dist/ui/placeholder/Placeholder.svelte +4 -3
- package/dist/ui/placeholder/Placeholder.svelte.d.ts +28 -17
- package/dist/ui/placeholder/PlaceholderImage.svelte +6 -4
- package/dist/ui/placeholder/PlaceholderImage.svelte.d.ts +28 -17
- package/dist/ui/range/RangePicker.svelte +76 -63
- package/dist/ui/range/RangePicker.svelte.d.ts +29 -24
- package/dist/ui/range/RangePickerButton.svelte +45 -40
- package/dist/ui/range/RangePickerButton.svelte.d.ts +21 -19
- package/dist/ui/table/Table.svelte +35 -28
- package/dist/ui/table/Table.svelte.d.ts +24 -19
- package/dist/ui/table/TableBody.svelte +18 -12
- package/dist/ui/table/TableBody.svelte.d.ts +20 -15
- package/dist/ui/table/TableCell.svelte +13 -10
- package/dist/ui/table/TableCell.svelte.d.ts +19 -14
- package/dist/ui/table/TableFieldsEdition.svelte +58 -52
- package/dist/ui/table/TableFieldsEdition.svelte.d.ts +20 -15
- package/dist/ui/table/TableHead.svelte +20 -21
- package/dist/ui/table/TableHead.svelte.d.ts +19 -14
- package/dist/ui/table/TableViewSelect.svelte +50 -37
- package/dist/ui/table/TableViewSelect.svelte.d.ts +27 -23
- package/dist/ui/table/cell/TableCellArray.svelte +5 -3
- package/dist/ui/table/cell/TableCellArray.svelte.d.ts +18 -14
- package/dist/ui/table/cell/TableCellBoolean.svelte +4 -3
- package/dist/ui/table/cell/TableCellBoolean.svelte.d.ts +18 -14
- package/dist/ui/table/cell/TableCellNumber.svelte +2 -1
- package/dist/ui/table/cell/TableCellNumber.svelte.d.ts +18 -14
- package/dist/ui/table/cell/TableCellString.svelte +5 -2
- package/dist/ui/table/cell/TableCellString.svelte.d.ts +19 -25
- package/dist/ui/table/field.d.ts +32 -40
- package/dist/ui/table/field.js +1 -1
- package/dist/ui/table/head/TableHeadBoolean.svelte +6 -3
- package/dist/ui/table/head/TableHeadBoolean.svelte.d.ts +18 -24
- package/dist/ui/table/head/TableHeadDate.svelte +61 -113
- package/dist/ui/table/head/TableHeadDate.svelte.d.ts +18 -24
- package/dist/ui/table/head/TableHeadDefault.svelte +5 -2
- package/dist/ui/table/head/TableHeadDefault.svelte.d.ts +18 -24
- package/dist/ui/table/head/TableHeadNumber.svelte +67 -76
- package/dist/ui/table/head/TableHeadNumber.svelte.d.ts +18 -24
- package/dist/ui/table/head/TableHeadSelect.svelte +47 -41
- package/dist/ui/table/head/TableHeadSelect.svelte.d.ts +21 -27
- package/dist/ui/table/head/TableHeadString.svelte +14 -8
- package/dist/ui/table/head/TableHeadString.svelte.d.ts +18 -24
- package/dist/ui/tabs/Tabs.svelte +8 -5
- package/dist/ui/tabs/Tabs.svelte.d.ts +19 -15
- package/dist/ui/tabs/TabsIcon.svelte +31 -28
- package/dist/ui/tabs/TabsIcon.svelte.d.ts +21 -17
- package/dist/utils/eventEmitter.d.ts +4 -4
- package/dist/utils/tippy.d.ts +1 -1
- package/dist/validation/form.d.ts +0 -1
- package/dist/validation/zod.d.ts +96 -162
- package/dist/validation/zod.js +2 -4
- package/package.json +134 -138
- package/dist/ui/form/FormInput.svelte.d.ts +0 -152
- package/dist/ui/form/formInput.d.ts +0 -90
- package/dist/ui/slot/Slot.svelte +0 -35
- package/dist/ui/slot/Slot.svelte.d.ts +0 -22
- package/dist/ui/slot/Span.svelte +0 -4
- package/dist/ui/slot/Span.svelte.d.ts +0 -16
- package/dist/ui/slot/index.d.ts +0 -1
- package/dist/ui/slot/index.js +0 -1
- package/dist/ui/table/head/OrderButtons.svelte +0 -37
- package/dist/ui/table/head/OrderButtons.svelte.d.ts +0 -20
- package/dist/ui/table/head/index.d.ts +0 -19
|
@@ -1,116 +1,137 @@
|
|
|
1
|
-
<script generics="RelationItem extends {id: string
|
|
2
|
-
import
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
export let
|
|
16
|
-
export let
|
|
17
|
-
let
|
|
18
|
-
export
|
|
19
|
-
export let
|
|
20
|
-
export let
|
|
21
|
-
|
|
22
|
-
export
|
|
23
|
-
export let
|
|
24
|
-
export let
|
|
25
|
-
export let
|
|
26
|
-
export let
|
|
27
|
-
let
|
|
28
|
-
export
|
|
29
|
-
export let
|
|
30
|
-
let
|
|
31
|
-
let
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
}
|
|
1
|
+
<script lang="ts" generics="RelationItem extends {id: string | number}">
|
|
2
|
+
import { createEventDispatcher, tick, type ComponentProps, type Snippet } from 'svelte'
|
|
3
|
+
import type { HTMLInputAttributes } from 'svelte/elements'
|
|
4
|
+
import debounce from 'debounce'
|
|
5
|
+
import { toast } from 'svelte-sonner'
|
|
6
|
+
import { mdiClose } from '@mdi/js'
|
|
7
|
+
|
|
8
|
+
import { USE_COERCE_JSON } from '../../utils/constant.js'
|
|
9
|
+
import { Icon } from '../icon/index.js'
|
|
10
|
+
import { DropDown } from '../menu/index.js'
|
|
11
|
+
import { FormControl, SelectorList } from './index.js'
|
|
12
|
+
import type { TippyProps } from '../../utils/tippy.js'
|
|
13
|
+
import RelationAfter from './RelationAfter.svelte'
|
|
14
|
+
|
|
15
|
+
export let key = Math.random().toString()
|
|
16
|
+
export let label = ''
|
|
17
|
+
export let search: (q: string) => Promise<RelationItem[]>
|
|
18
|
+
export let createUrl = ''
|
|
19
|
+
export let createTitle = 'Nouveau'
|
|
20
|
+
export let createIcon: string | undefined = undefined
|
|
21
|
+
let item: RelationItem | null = null
|
|
22
|
+
export { item as value }
|
|
23
|
+
export let error = ''
|
|
24
|
+
export let placeholder = ''
|
|
25
|
+
export let tippyProps: Partial<TippyProps> = {}
|
|
26
|
+
export let dropdownProps: ComponentProps<DropDown> = {}
|
|
27
|
+
export let flatMode = false
|
|
28
|
+
export let noSlotItemWrapper = false
|
|
29
|
+
export let slotItem: Snippet<[RelationItem]>
|
|
30
|
+
export let slotSuggestion: Snippet<[RelationItem]> = slotItem
|
|
31
|
+
export let input: HTMLInputAttributes | undefined = undefined
|
|
32
|
+
export let append: Snippet | undefined = undefined
|
|
33
|
+
|
|
34
|
+
let klass = ''
|
|
35
|
+
export { klass as class }
|
|
36
|
+
export let classList = ''
|
|
37
|
+
|
|
38
|
+
let inputElement: HTMLInputElement
|
|
39
|
+
|
|
40
|
+
let proposedItems: RelationItem[] = []
|
|
41
|
+
|
|
42
|
+
let isLoading = false
|
|
43
|
+
let isError = false
|
|
44
|
+
let focusIndex = 0
|
|
45
|
+
let searchValue = ''
|
|
46
|
+
|
|
47
|
+
const dispatch = createEventDispatcher<{ input: { value: RelationItem } }>()
|
|
48
|
+
|
|
49
|
+
export async function clear() {
|
|
50
|
+
searchValue = ''
|
|
51
|
+
item = null
|
|
52
|
+
await tick()
|
|
53
|
+
inputElement.focus()
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
async function select(index = focusIndex) {
|
|
57
|
+
item = proposedItems[index]
|
|
58
|
+
dispatch('input', { value: item })
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
async function searchItems(searchValue = '') {
|
|
62
|
+
try {
|
|
63
|
+
isLoading = true
|
|
64
|
+
isError = false
|
|
65
|
+
focusIndex = 0
|
|
66
|
+
proposedItems = await search(searchValue)
|
|
67
|
+
} catch (error) {
|
|
68
|
+
toast.error('Erreur')
|
|
69
|
+
isError = true
|
|
70
|
+
console.error(error)
|
|
71
|
+
} finally {
|
|
72
|
+
isLoading = false
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const searchItemsDebounce = debounce(searchItems, 150)
|
|
77
|
+
|
|
78
|
+
function handleFocus() {
|
|
79
|
+
searchItems()
|
|
80
|
+
}
|
|
81
|
+
async function handleBlur() {
|
|
82
|
+
searchValue = ''
|
|
83
|
+
}
|
|
68
84
|
</script>
|
|
69
85
|
|
|
70
86
|
<DropDown {tippyProps} disable={flatMode} {...dropdownProps}>
|
|
71
87
|
<div class="contents" slot="activator">
|
|
72
|
-
<FormControl {key} {label} {error} class={klass}
|
|
73
|
-
|
|
74
|
-
<div class="
|
|
75
|
-
<input
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
</div>
|
|
92
|
-
<slot name="append" />
|
|
93
|
-
</div>
|
|
94
|
-
|
|
95
|
-
{#if item}
|
|
96
|
-
<div class="flex h-12 items-center gap-2 rounded-lg border bg-base-100 pl-4 pr-2">
|
|
97
|
-
<div class="grow">
|
|
98
|
-
<slot name="item" {item}>
|
|
99
|
-
<Slot slot={slotItem} args={item}>
|
|
100
|
-
{item.id}
|
|
101
|
-
</Slot>
|
|
102
|
-
</slot>
|
|
88
|
+
<FormControl {key} {label} {error} class={klass}>
|
|
89
|
+
{#snippet children({ key })}
|
|
90
|
+
<div class="flex grow gap-2" class:hidden={item}>
|
|
91
|
+
<div class="input input-bordered flex grow items-center pr-2">
|
|
92
|
+
<input
|
|
93
|
+
type="text"
|
|
94
|
+
id={key}
|
|
95
|
+
bind:this={inputElement}
|
|
96
|
+
bind:value={searchValue}
|
|
97
|
+
on:input={(e) => searchItemsDebounce(e.currentTarget.value)}
|
|
98
|
+
on:focus={handleFocus}
|
|
99
|
+
on:blur={handleBlur}
|
|
100
|
+
autocomplete="off"
|
|
101
|
+
{placeholder}
|
|
102
|
+
class="grow"
|
|
103
|
+
size={8}
|
|
104
|
+
{...input}
|
|
105
|
+
/>
|
|
106
|
+
<RelationAfter {isLoading} {createUrl} {createTitle} {createIcon} />
|
|
103
107
|
</div>
|
|
104
|
-
|
|
105
|
-
<Icon path={mdiClose} />
|
|
106
|
-
</button>
|
|
108
|
+
{@render append?.()}
|
|
107
109
|
</div>
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
110
|
+
|
|
111
|
+
{#if item}
|
|
112
|
+
{#if noSlotItemWrapper}
|
|
113
|
+
{@render slotItem(item)}
|
|
114
|
+
{:else}
|
|
115
|
+
<div class="flex h-12 items-center gap-2 rounded-lg border bg-base-100 pl-4 pr-2">
|
|
116
|
+
<div class="grow">
|
|
117
|
+
{@render slotItem(item)}
|
|
118
|
+
</div>
|
|
119
|
+
<button
|
|
120
|
+
type="button"
|
|
121
|
+
on:click|stopPropagation={() => clear()}
|
|
122
|
+
class="btn btn-square btn-sm"
|
|
123
|
+
>
|
|
124
|
+
<Icon path={mdiClose} />
|
|
125
|
+
</button>
|
|
126
|
+
</div>
|
|
127
|
+
{/if}
|
|
128
|
+
<input
|
|
129
|
+
type="hidden"
|
|
130
|
+
name={key}
|
|
131
|
+
value="{USE_COERCE_JSON}{JSON.stringify({ id: item.id })}"
|
|
132
|
+
/>
|
|
133
|
+
{/if}
|
|
134
|
+
{/snippet}
|
|
114
135
|
</FormControl>
|
|
115
136
|
</div>
|
|
116
137
|
|
|
@@ -124,10 +145,6 @@ async function handleBlur() {
|
|
|
124
145
|
class="w-full min-w-40 {classList}"
|
|
125
146
|
on:select={({ detail }) => select(detail)}
|
|
126
147
|
>
|
|
127
|
-
|
|
128
|
-
<Slot slot={slotSuggestion} args={proposedItems[index]}>
|
|
129
|
-
{proposedItems[index].id}
|
|
130
|
-
</Slot>
|
|
131
|
-
</slot>
|
|
148
|
+
{@render slotSuggestion(proposedItems[index])}
|
|
132
149
|
</SelectorList>
|
|
133
150
|
</DropDown>
|
|
@@ -1,43 +1,30 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { type ComponentProps, type Snippet } from 'svelte';
|
|
2
2
|
import type { HTMLInputAttributes } from 'svelte/elements';
|
|
3
|
+
import { DropDown } from '../menu/index.js';
|
|
3
4
|
import type { TippyProps } from '../../utils/tippy.js';
|
|
4
|
-
import type { ComponentAndProps } from '../../utils/component.js';
|
|
5
5
|
declare class __sveltets_Render<RelationItem extends {
|
|
6
|
-
id: string;
|
|
6
|
+
id: string | number;
|
|
7
7
|
}> {
|
|
8
8
|
props(): {
|
|
9
|
-
key?: string
|
|
10
|
-
label?: string
|
|
9
|
+
key?: string;
|
|
10
|
+
label?: string;
|
|
11
11
|
search: (q: string) => Promise<RelationItem[]>;
|
|
12
|
-
createUrl?: string
|
|
13
|
-
createTitle?: string
|
|
12
|
+
createUrl?: string;
|
|
13
|
+
createTitle?: string;
|
|
14
14
|
createIcon?: string | undefined;
|
|
15
15
|
value?: RelationItem | null | undefined;
|
|
16
|
-
error?: string
|
|
17
|
-
placeholder?: string
|
|
18
|
-
tippyProps?: Partial<TippyProps
|
|
19
|
-
dropdownProps?:
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
useSingleton?: boolean | undefined;
|
|
25
|
-
autofocus?: boolean | undefined;
|
|
26
|
-
hideOnBlur?: boolean | undefined;
|
|
27
|
-
hideOnNav?: boolean | undefined;
|
|
28
|
-
tip?: import("tippy.js").Instance<TippyProps> | undefined;
|
|
29
|
-
disable?: boolean | undefined;
|
|
30
|
-
content?: HTMLDivElement | undefined;
|
|
31
|
-
hide?: (() => void) | undefined;
|
|
32
|
-
show?: (() => void) | undefined;
|
|
33
|
-
setTippyProps?: ((props: Partial<TippyProps>) => void) | undefined;
|
|
34
|
-
} | undefined;
|
|
35
|
-
flatMode?: boolean | undefined;
|
|
36
|
-
slotItem?: ((item: RelationItem) => string | ComponentAndProps) | null | undefined;
|
|
37
|
-
slotSuggestion?: ((item: RelationItem) => string | ComponentAndProps) | null | undefined;
|
|
16
|
+
error?: string;
|
|
17
|
+
placeholder?: string;
|
|
18
|
+
tippyProps?: Partial<TippyProps>;
|
|
19
|
+
dropdownProps?: ComponentProps<DropDown>;
|
|
20
|
+
flatMode?: boolean;
|
|
21
|
+
noSlotItemWrapper?: boolean;
|
|
22
|
+
slotItem: Snippet<[RelationItem]>;
|
|
23
|
+
slotSuggestion?: Snippet<[RelationItem]> | undefined;
|
|
38
24
|
input?: HTMLInputAttributes | undefined;
|
|
39
|
-
|
|
40
|
-
|
|
25
|
+
append?: Snippet | undefined;
|
|
26
|
+
class?: string;
|
|
27
|
+
classList?: string;
|
|
41
28
|
clear?: (() => Promise<void>) | undefined;
|
|
42
29
|
};
|
|
43
30
|
events(): {
|
|
@@ -47,28 +34,27 @@ declare class __sveltets_Render<RelationItem extends {
|
|
|
47
34
|
} & {
|
|
48
35
|
[evt: string]: CustomEvent<any>;
|
|
49
36
|
};
|
|
50
|
-
slots(): {
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
suggestion: {
|
|
56
|
-
item: RelationItem;
|
|
57
|
-
};
|
|
37
|
+
slots(): {};
|
|
38
|
+
bindings(): string;
|
|
39
|
+
exports(): {
|
|
40
|
+
clear: () => Promise<void>;
|
|
58
41
|
};
|
|
59
42
|
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
}>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
get clear(): () => Promise<void>;
|
|
43
|
+
interface $$IsomorphicComponent {
|
|
44
|
+
new <RelationItem extends {
|
|
45
|
+
id: string | number;
|
|
46
|
+
}>(options: import('svelte').ComponentConstructorOptions<ReturnType<__sveltets_Render<RelationItem>['props']>>): import('svelte').SvelteComponent<ReturnType<__sveltets_Render<RelationItem>['props']>, ReturnType<__sveltets_Render<RelationItem>['events']>, ReturnType<__sveltets_Render<RelationItem>['slots']>> & {
|
|
47
|
+
$$bindings?: ReturnType<__sveltets_Render<RelationItem>['bindings']>;
|
|
48
|
+
} & ReturnType<__sveltets_Render<RelationItem>['exports']>;
|
|
49
|
+
<RelationItem extends {
|
|
50
|
+
id: string | number;
|
|
51
|
+
}>(internal: unknown, props: ReturnType<__sveltets_Render<RelationItem>['props']> & {
|
|
52
|
+
$$events?: ReturnType<__sveltets_Render<RelationItem>['events']>;
|
|
53
|
+
}): ReturnType<__sveltets_Render<RelationItem>['exports']>;
|
|
54
|
+
z_$$bindings?: ReturnType<__sveltets_Render<any>['bindings']>;
|
|
73
55
|
}
|
|
74
|
-
|
|
56
|
+
declare const InputRelation: $$IsomorphicComponent;
|
|
57
|
+
type InputRelation<RelationItem extends {
|
|
58
|
+
id: string | number;
|
|
59
|
+
}> = InstanceType<typeof InputRelation<RelationItem>>;
|
|
60
|
+
export default InputRelation;
|
|
@@ -1,82 +1,96 @@
|
|
|
1
|
-
<script generics="RelationItem extends {id: string
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
import
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import
|
|
9
|
-
|
|
10
|
-
import {
|
|
11
|
-
import
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export let
|
|
17
|
-
export let
|
|
18
|
-
export let
|
|
19
|
-
export let
|
|
20
|
-
export let
|
|
21
|
-
export let
|
|
22
|
-
export let
|
|
23
|
-
export let
|
|
24
|
-
let
|
|
25
|
-
export
|
|
26
|
-
export let
|
|
27
|
-
let
|
|
28
|
-
let
|
|
29
|
-
|
|
30
|
-
let
|
|
31
|
-
|
|
32
|
-
let
|
|
33
|
-
|
|
34
|
-
let
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
const
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
}
|
|
1
|
+
<script lang="ts" generics="RelationItem extends {id: string | number}">
|
|
2
|
+
import type { HTMLInputAttributes } from 'svelte/elements'
|
|
3
|
+
|
|
4
|
+
import { createEventDispatcher, tick, type Snippet } from 'svelte'
|
|
5
|
+
import { slide } from 'svelte/transition'
|
|
6
|
+
import { toast } from 'svelte-sonner'
|
|
7
|
+
import { mdiClose } from '@mdi/js'
|
|
8
|
+
import debounce from 'debounce'
|
|
9
|
+
|
|
10
|
+
import { USE_COERCE_JSON } from '../../utils/constant.js'
|
|
11
|
+
import { Icon } from '../icon/index.js'
|
|
12
|
+
import { FormControl, SelectorList } from './index.js'
|
|
13
|
+
import { DropDown } from '../menu/index.js'
|
|
14
|
+
import RelationAfter from './RelationAfter.svelte'
|
|
15
|
+
|
|
16
|
+
export let key = ''
|
|
17
|
+
export let label = ''
|
|
18
|
+
export let search: (q: string) => Promise<RelationItem[]>
|
|
19
|
+
export let createUrl = ''
|
|
20
|
+
export let createTitle = ''
|
|
21
|
+
export let createIcon: string | undefined = undefined
|
|
22
|
+
export let error = ''
|
|
23
|
+
export let placeholder = ''
|
|
24
|
+
export let flatMode = false
|
|
25
|
+
export let slotItem: Snippet<[RelationItem]>
|
|
26
|
+
export let slotSuggestion: Snippet<[RelationItem]> = slotItem
|
|
27
|
+
export let input: HTMLInputAttributes | undefined = undefined
|
|
28
|
+
export let append: Snippet | undefined = undefined
|
|
29
|
+
|
|
30
|
+
let klass = ''
|
|
31
|
+
export { klass as class }
|
|
32
|
+
export let classList = ''
|
|
33
|
+
|
|
34
|
+
let proposedItems: RelationItem[] = []
|
|
35
|
+
let items: RelationItem[] | null = null
|
|
36
|
+
export { items as value }
|
|
37
|
+
|
|
38
|
+
let isLoading = false
|
|
39
|
+
let isError = false
|
|
40
|
+
let focusIndex = 0
|
|
41
|
+
let searchValue = ''
|
|
42
|
+
|
|
43
|
+
let dropdown: DropDown
|
|
44
|
+
const dispatch = createEventDispatcher<{
|
|
45
|
+
input: { value: (string | number)[]; items: RelationItem[] }
|
|
46
|
+
}>()
|
|
47
|
+
let inputSearch: HTMLInputElement
|
|
48
|
+
|
|
49
|
+
async function select(index = focusIndex) {
|
|
50
|
+
const proposedItem = proposedItems[index]
|
|
51
|
+
if (!proposedItem) return
|
|
52
|
+
if (!items) items = [proposedItem]
|
|
53
|
+
else items = [...items, proposedItem]
|
|
54
|
+
dropdown.hide()
|
|
55
|
+
inputSearch.select()
|
|
56
|
+
proposedItems = [...proposedItems.slice(0, index), ...proposedItems.slice(index + 1)]
|
|
57
|
+
dispatch('input', { value: items.map(({ id }) => id), items })
|
|
58
|
+
await tick()
|
|
59
|
+
setTimeout(() => dropdown.show(), 200)
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
function remove(index: number) {
|
|
63
|
+
if (!items?.length) return
|
|
64
|
+
items = [...items.slice(0, index), ...items.slice(index + 1)]
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
async function searchItems(searchValue = '') {
|
|
68
|
+
try {
|
|
69
|
+
isLoading = true
|
|
70
|
+
isError = false
|
|
71
|
+
focusIndex = 0
|
|
72
|
+
const res = await search(searchValue)
|
|
73
|
+
const currentIds = items?.map(({ id }) => id) || []
|
|
74
|
+
proposedItems = res.filter(({ id }) => !currentIds.includes(id))
|
|
75
|
+
} catch (error) {
|
|
76
|
+
toast.error('Erreur')
|
|
77
|
+
isError = true
|
|
78
|
+
console.error(error)
|
|
79
|
+
} finally {
|
|
80
|
+
isLoading = false
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
const searchItemsDebounce = debounce(searchItems, 150)
|
|
85
|
+
|
|
86
|
+
function handleFocus() {
|
|
87
|
+
searchItems()
|
|
88
|
+
// dropdown.show()
|
|
89
|
+
}
|
|
90
|
+
async function handleBlur() {
|
|
91
|
+
// dropdown.hide()
|
|
92
|
+
searchValue = ''
|
|
93
|
+
}
|
|
80
94
|
</script>
|
|
81
95
|
|
|
82
96
|
<DropDown bind:this={dropdown} disable={flatMode}>
|
|
@@ -90,11 +104,7 @@ async function handleBlur() {
|
|
|
90
104
|
transition:slide|local={{ axis: 'x', duration: 200 }}
|
|
91
105
|
class="badge badge-outline badge-lg items-center whitespace-nowrap pr-0 text-right"
|
|
92
106
|
>
|
|
93
|
-
|
|
94
|
-
<Slot slot={slotItem} args={item}>
|
|
95
|
-
{item.id}
|
|
96
|
-
</Slot>
|
|
97
|
-
</slot>
|
|
107
|
+
{@render slotItem(item)}
|
|
98
108
|
<div
|
|
99
109
|
class="btn btn-circle btn-ghost btn-xs ml-1 mr-[2px] h-[18px] min-h-[18px] w-[18px]"
|
|
100
110
|
role="button"
|
|
@@ -127,7 +137,7 @@ async function handleBlur() {
|
|
|
127
137
|
|
|
128
138
|
<RelationAfter {isLoading} {createUrl} {createTitle} {createIcon} />
|
|
129
139
|
</div>
|
|
130
|
-
|
|
140
|
+
{@render append?.()}
|
|
131
141
|
</div>
|
|
132
142
|
</div>
|
|
133
143
|
|
|
@@ -149,10 +159,6 @@ async function handleBlur() {
|
|
|
149
159
|
class="w-full min-w-40 {classList}"
|
|
150
160
|
on:select={({ detail }) => select(detail)}
|
|
151
161
|
>
|
|
152
|
-
|
|
153
|
-
<Slot slot={slotSuggestion} args={proposedItems[index]}>
|
|
154
|
-
{proposedItems[index].id}
|
|
155
|
-
</Slot>
|
|
156
|
-
</slot>
|
|
162
|
+
{@render slotSuggestion(proposedItems[index])}
|
|
157
163
|
</SelectorList>
|
|
158
164
|
</DropDown>
|