@katlux/toolkit 0.1.1-alpha.118 → 0.1.1-alpha.119
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/bin/create-preset.mjs +5 -4
- package/dist/compiled/composables/useKatluxContext.mjs +6 -3
- package/dist/compiled/composables/useKatluxForm.mjs +268 -0
- package/dist/compiled/composables/useToast.mjs +164 -0
- package/dist/compiled/composables/useVirtualScroll.mjs +176 -0
- package/dist/module.cjs +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +9 -0
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +9 -0
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +2 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +9 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +5 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +11 -3
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +2 -0
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +5 -1
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +2 -0
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
- package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
- package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
- package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
- package/dist/runtime/components/KGantt/KGantt.logic.js +11 -4
- package/dist/runtime/components/KPagination/KPagination.logic.js +7 -4
- package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
- package/dist/runtime/components/KToast/KToast.global.vue +12 -2
- package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
- package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
- package/dist/runtime/components/KToast/KToast.logic.js +45 -5
- package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
- package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
- package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
- package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +38 -0
- package/dist/runtime/components/KTree/KTree.global.vue +7 -3
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +38 -0
- package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
- package/dist/runtime/components/KTree/KTree.logic.js +17 -0
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +52 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +52 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +36 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +36 -0
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
- package/dist/runtime/composables/useKatluxContext.js +6 -3
- package/dist/runtime/composables/useKatluxForm.d.ts +143 -0
- package/dist/runtime/composables/useKatluxForm.js +268 -0
- package/dist/runtime/composables/useToast.d.ts +49 -0
- package/dist/runtime/composables/useToast.js +164 -0
- package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
- package/dist/runtime/composables/useVirtualScroll.js +176 -0
- package/dist/runtime/plugins/PresetPlugin.js +9 -1
- package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
- package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
- package/dist/runtime/plugins/toastPlugin.client.js +16 -0
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +36 -7
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +10 -4
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +10 -1
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +128 -6
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +10 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +206 -27
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KLayout/KLayout.vue +4 -2
- package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
- package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
- package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
- package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
- package/dist/runtime/presets/default/components/KToast/KToast.vue +22 -4
- package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +207 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -5
- package/dist/runtime/presets/default/components/KTree/KTree.vue +232 -13
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -5
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
- package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
- package/dist/runtime/server/middleware/session.js +1 -1
- package/package.json +3 -4
- package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
- package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
- package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
- package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
- package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
- package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
<template lang="pug">
|
|
2
|
+
Teleport(to="body" :disabled="!teleport")
|
|
3
|
+
.k-toast-portal-host#katlux-toast-portal
|
|
4
|
+
.k-toast-container(
|
|
5
|
+
v-for="pos in activePositions"
|
|
6
|
+
:key="pos"
|
|
7
|
+
:class="[`pos-${pos}`]"
|
|
8
|
+
role="region"
|
|
9
|
+
aria-label="Notifications"
|
|
10
|
+
aria-live="polite"
|
|
11
|
+
@mouseenter="handleMouseEnter"
|
|
12
|
+
@mouseleave="handleMouseLeave"
|
|
13
|
+
)
|
|
14
|
+
TransitionGroup(name="k-toast-stack" tag="div" class="k-toast-stack")
|
|
15
|
+
.k-toast-item(
|
|
16
|
+
v-for="item in getToastsForPosition(pos)"
|
|
17
|
+
:key="item.id"
|
|
18
|
+
@mouseenter="handleMouseEnter"
|
|
19
|
+
@mouseleave="handleMouseLeave"
|
|
20
|
+
)
|
|
21
|
+
KToast(
|
|
22
|
+
:modelValue="true"
|
|
23
|
+
:text="item.text"
|
|
24
|
+
:title="item.title"
|
|
25
|
+
:type="item.type"
|
|
26
|
+
:teleport="false"
|
|
27
|
+
:timeout="0"
|
|
28
|
+
@close="dismiss(item.id)"
|
|
29
|
+
)
|
|
30
|
+
</template>
|
|
31
|
+
|
|
32
|
+
<script lang="ts" setup>
|
|
33
|
+
import { computed, onBeforeUnmount } from 'vue'
|
|
34
|
+
import { useToast, type KToastPosition } from '#toolkit/composables/useToast'
|
|
35
|
+
import KToast from '#toolkit/components/KToast/KToast.global.vue'
|
|
36
|
+
|
|
37
|
+
const props = withDefaults(defineProps<{
|
|
38
|
+
position?: KToastPosition
|
|
39
|
+
teleport?: boolean
|
|
40
|
+
maxToasts?: number
|
|
41
|
+
}>(), {
|
|
42
|
+
teleport: true
|
|
43
|
+
})
|
|
44
|
+
|
|
45
|
+
const { toasts, dismiss, pause, resume } = useToast()
|
|
46
|
+
|
|
47
|
+
let leaveDebounceTimer: any = null
|
|
48
|
+
|
|
49
|
+
const handleMouseEnter = () => {
|
|
50
|
+
if (leaveDebounceTimer) {
|
|
51
|
+
clearTimeout(leaveDebounceTimer)
|
|
52
|
+
leaveDebounceTimer = null
|
|
53
|
+
}
|
|
54
|
+
pause()
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
const handleMouseLeave = () => {
|
|
58
|
+
if (leaveDebounceTimer) {
|
|
59
|
+
clearTimeout(leaveDebounceTimer)
|
|
60
|
+
}
|
|
61
|
+
leaveDebounceTimer = setTimeout(() => {
|
|
62
|
+
resume()
|
|
63
|
+
leaveDebounceTimer = null
|
|
64
|
+
}, 150)
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
onBeforeUnmount(() => {
|
|
68
|
+
if (leaveDebounceTimer) {
|
|
69
|
+
clearTimeout(leaveDebounceTimer)
|
|
70
|
+
leaveDebounceTimer = null
|
|
71
|
+
}
|
|
72
|
+
})
|
|
73
|
+
|
|
74
|
+
const ALL_POSITIONS: KToastPosition[] = [
|
|
75
|
+
'top-right',
|
|
76
|
+
'top-left',
|
|
77
|
+
'top-center',
|
|
78
|
+
'bottom-right',
|
|
79
|
+
'bottom-left',
|
|
80
|
+
'bottom-center'
|
|
81
|
+
]
|
|
82
|
+
|
|
83
|
+
const getToastsForPosition = (pos: KToastPosition) => {
|
|
84
|
+
const list = toasts.value.filter(item => item.position === pos)
|
|
85
|
+
if (props.maxToasts && props.maxToasts > 0) {
|
|
86
|
+
return list.slice(-props.maxToasts)
|
|
87
|
+
}
|
|
88
|
+
return list
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
const activePositions = computed(() => {
|
|
92
|
+
if (props.position) {
|
|
93
|
+
return getToastsForPosition(props.position).length > 0 ? [props.position] : []
|
|
94
|
+
}
|
|
95
|
+
return ALL_POSITIONS.filter(pos => getToastsForPosition(pos).length > 0)
|
|
96
|
+
})
|
|
97
|
+
</script>
|
|
98
|
+
|
|
99
|
+
<style lang="scss" scoped>
|
|
100
|
+
.k-toast-portal-host {
|
|
101
|
+
pointer-events: none;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
.k-toast-container {
|
|
105
|
+
position: fixed;
|
|
106
|
+
z-index: 10000;
|
|
107
|
+
display: flex;
|
|
108
|
+
flex-direction: column;
|
|
109
|
+
gap: var(--gap-sm, 10px);
|
|
110
|
+
pointer-events: none;
|
|
111
|
+
padding: var(--gap-lg, 20px);
|
|
112
|
+
box-sizing: border-box;
|
|
113
|
+
max-width: 100vw;
|
|
114
|
+
|
|
115
|
+
&.pos-top-right {
|
|
116
|
+
top: 0;
|
|
117
|
+
right: 0;
|
|
118
|
+
align-items: flex-end;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
&.pos-top-left {
|
|
122
|
+
top: 0;
|
|
123
|
+
left: 0;
|
|
124
|
+
align-items: flex-start;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
&.pos-top-center {
|
|
128
|
+
top: 0;
|
|
129
|
+
left: 50%;
|
|
130
|
+
transform: translateX(-50%);
|
|
131
|
+
align-items: center;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
&.pos-bottom-right {
|
|
135
|
+
bottom: 0;
|
|
136
|
+
right: 0;
|
|
137
|
+
align-items: flex-end;
|
|
138
|
+
flex-direction: column-reverse;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
&.pos-bottom-left {
|
|
142
|
+
bottom: 0;
|
|
143
|
+
left: 0;
|
|
144
|
+
align-items: flex-start;
|
|
145
|
+
flex-direction: column-reverse;
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
&.pos-bottom-center {
|
|
149
|
+
bottom: 0;
|
|
150
|
+
left: 50%;
|
|
151
|
+
transform: translateX(-50%);
|
|
152
|
+
align-items: center;
|
|
153
|
+
flex-direction: column-reverse;
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.k-toast-stack {
|
|
158
|
+
display: flex;
|
|
159
|
+
flex-direction: inherit;
|
|
160
|
+
gap: inherit;
|
|
161
|
+
align-items: inherit;
|
|
162
|
+
position: relative;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
.k-toast-item {
|
|
166
|
+
pointer-events: auto;
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
/* Animations */
|
|
170
|
+
.k-toast-stack-enter-active,
|
|
171
|
+
.k-toast-stack-leave-active {
|
|
172
|
+
transition: all 0.28s cubic-bezier(0.16, 1, 0.3, 1);
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
.k-toast-stack-enter-from {
|
|
176
|
+
opacity: 0;
|
|
177
|
+
transform: translateY(-16px) scale(0.96);
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
.k-toast-stack-leave-to {
|
|
181
|
+
opacity: 0;
|
|
182
|
+
transform: translateY(-16px) scale(0.96);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
.k-toast-stack-leave-active {
|
|
186
|
+
position: absolute;
|
|
187
|
+
width: 100%;
|
|
188
|
+
pointer-events: none;
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
.k-toast-stack-move {
|
|
192
|
+
transition: transform 0.28s ease;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.pos-bottom-right,
|
|
196
|
+
.pos-bottom-left,
|
|
197
|
+
.pos-bottom-center {
|
|
198
|
+
.k-toast-stack-enter-from {
|
|
199
|
+
opacity: 0;
|
|
200
|
+
transform: translateY(16px) scale(0.96);
|
|
201
|
+
}
|
|
202
|
+
.k-toast-stack-leave-to {
|
|
203
|
+
opacity: 0;
|
|
204
|
+
transform: translateY(16px) scale(0.96);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
</style>
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { type KToastPosition } from '#toolkit/composables/useToast';
|
|
2
|
+
type __VLS_Props = {
|
|
3
|
+
position?: KToastPosition;
|
|
4
|
+
teleport?: boolean;
|
|
5
|
+
maxToasts?: number;
|
|
6
|
+
};
|
|
7
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{}>, {
|
|
8
|
+
teleport: boolean;
|
|
9
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
10
|
+
declare const _default: typeof __VLS_export;
|
|
11
|
+
export default _default;
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type Ref } from 'vue';
|
|
2
1
|
import type { TTreeRow } from '@katlux/providers';
|
|
3
2
|
type __VLS_Props = {
|
|
4
3
|
visibleRows: TTreeRow[];
|
|
@@ -11,19 +10,30 @@ type __VLS_Props = {
|
|
|
11
10
|
isNodeSelected?: (node: any) => boolean;
|
|
12
11
|
toggleNode: (id: string | number) => void;
|
|
13
12
|
selectable?: boolean;
|
|
14
|
-
dataProvider?:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
dataProvider?: any;
|
|
14
|
+
searchtext?: string;
|
|
15
|
+
virtualScroll?: boolean;
|
|
16
|
+
itemHeight?: number;
|
|
17
|
+
viewportHeight?: number;
|
|
18
|
+
buffer?: number;
|
|
18
19
|
};
|
|
19
20
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
20
21
|
select: (row: TTreeRow) => any;
|
|
22
|
+
"node-toggle": (id: string | number) => any;
|
|
23
|
+
"node-click": (row: TTreeRow) => any;
|
|
21
24
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
22
25
|
onSelect?: ((row: TTreeRow) => any) | undefined;
|
|
26
|
+
"onNode-toggle"?: ((id: string | number) => any) | undefined;
|
|
27
|
+
"onNode-click"?: ((row: TTreeRow) => any) | undefined;
|
|
23
28
|
}>, {
|
|
24
29
|
disabled: boolean;
|
|
30
|
+
searchtext: string;
|
|
31
|
+
virtualScroll: boolean;
|
|
32
|
+
itemHeight: number;
|
|
33
|
+
buffer: number;
|
|
25
34
|
labelField: string;
|
|
26
35
|
multiSelect: boolean;
|
|
36
|
+
viewportHeight: number;
|
|
27
37
|
iconField: string;
|
|
28
38
|
idKey: string;
|
|
29
39
|
isNodeSelected: (node: any) => boolean;
|
|
@@ -1,7 +1,70 @@
|
|
|
1
1
|
<template lang="pug">
|
|
2
|
-
.KTree(
|
|
2
|
+
.KTree(
|
|
3
|
+
role="tree"
|
|
4
|
+
:aria-label="t('Hierarchical Tree')"
|
|
5
|
+
:class="{ 'is-virtual-scroll': props.virtualScroll }"
|
|
6
|
+
)
|
|
3
7
|
KLoader(:loading="isLoading" overlay)
|
|
4
|
-
|
|
8
|
+
//- Virtual scrolling mode
|
|
9
|
+
.k-tree-virtual-container(
|
|
10
|
+
v-if="props.virtualScroll"
|
|
11
|
+
ref="containerRef"
|
|
12
|
+
tabindex="0"
|
|
13
|
+
role="region"
|
|
14
|
+
:style="containerCssVars"
|
|
15
|
+
@scroll.passive="onScroll"
|
|
16
|
+
@keydown.down.prevent="onKeyDownDown"
|
|
17
|
+
@keydown.up.prevent="onKeyDownUp"
|
|
18
|
+
)
|
|
19
|
+
.k-virtual-spacer.is-top(aria-hidden="true")
|
|
20
|
+
.tree-list
|
|
21
|
+
.tree-node(
|
|
22
|
+
v-for="(row, idx) in displayRows"
|
|
23
|
+
:key="row[idKey] || row.id || (startIndex + idx)"
|
|
24
|
+
:class="{ 'has-children': (row.__treeNode?.hasChildren || row.hasChildren) }"
|
|
25
|
+
:style="{ '--tree-depth': (row.__treeNode?.depth ?? row.depth ?? 0) }"
|
|
26
|
+
role="treeitem"
|
|
27
|
+
:aria-expanded="(row.__treeNode?.hasChildren || row.hasChildren) ? (row.__treeNode?.isExpanded ?? row.isExpanded) : undefined"
|
|
28
|
+
:aria-level="((row.__treeNode?.depth ?? row.depth ?? 0) + 1)"
|
|
29
|
+
:tabindex="isNodeFocused(row, idx) ? 0 : -1"
|
|
30
|
+
@focus="onNodeFocus(row, idx)"
|
|
31
|
+
@keydown.enter.prevent="onNodeClick(row)"
|
|
32
|
+
@keydown.space.prevent="(row.__treeNode?.hasChildren || row.hasChildren) ? toggleNode(row.__treeNode?.id ?? row.id) : onNodeClick(row)"
|
|
33
|
+
@keydown.down.prevent="focusNextNode(idx)"
|
|
34
|
+
@keydown.up.prevent="focusPrevNode(idx)"
|
|
35
|
+
)
|
|
36
|
+
.node-content
|
|
37
|
+
// Toggle
|
|
38
|
+
.tree-toggle(
|
|
39
|
+
v-if="(row.__treeNode?.hasChildren || row.hasChildren)"
|
|
40
|
+
@click="toggleNode(row.__treeNode?.id ?? row.id)"
|
|
41
|
+
:class="{ expanded: (row.__treeNode?.isExpanded ?? row.isExpanded) }"
|
|
42
|
+
role="button"
|
|
43
|
+
:aria-label="t('Toggle node')"
|
|
44
|
+
tabindex="-1"
|
|
45
|
+
)
|
|
46
|
+
KIcon(iconname="chevron" :width="12" :height="12" :rotate="(row.__treeNode?.isExpanded ?? row.isExpanded) ? '90' : '0'")
|
|
47
|
+
|
|
48
|
+
.tree-spacer(v-else)
|
|
49
|
+
|
|
50
|
+
// Content
|
|
51
|
+
.node-label(@click="onNodeClick(row)")
|
|
52
|
+
.selection-control(v-if="selectable")
|
|
53
|
+
KCheckbox(
|
|
54
|
+
:modelValue="isNodeSelected(row)"
|
|
55
|
+
@update:modelValue="onNodeClick(row)"
|
|
56
|
+
@click.stop
|
|
57
|
+
)
|
|
58
|
+
|
|
59
|
+
slot(name="item" :node="row.__treeNode || row" :data="row")
|
|
60
|
+
slot(name="default" :node="row.__treeNode || row" :data="row")
|
|
61
|
+
.default-item
|
|
62
|
+
KIcon(v-if="iconField && row[iconField]" :iconname="row[iconField]" :width="16" :height="16")
|
|
63
|
+
span {{ row[labelField] }}
|
|
64
|
+
.k-virtual-spacer.is-bottom(aria-hidden="true")
|
|
65
|
+
|
|
66
|
+
//- Traditional standard tree list
|
|
67
|
+
.tree-list(v-else)
|
|
5
68
|
.tree-node(
|
|
6
69
|
v-for="row in visibleRows"
|
|
7
70
|
:key="row[idKey] || row.id"
|
|
@@ -10,9 +73,12 @@
|
|
|
10
73
|
role="treeitem"
|
|
11
74
|
:aria-expanded="row.__treeNode?.hasChildren ? row.__treeNode?.isExpanded : undefined"
|
|
12
75
|
:aria-level="(row.__treeNode?.depth || 0) + 1"
|
|
13
|
-
tabindex="0"
|
|
76
|
+
:tabindex="isNodeFocused(row, idx) ? 0 : -1"
|
|
77
|
+
@focus="onNodeFocus(row, idx)"
|
|
14
78
|
@keydown.enter.prevent="onNodeClick(row)"
|
|
15
79
|
@keydown.space.prevent="row.__treeNode?.hasChildren && row.__treeNode?.id !== undefined ? toggleNode(row.__treeNode.id) : onNodeClick(row)"
|
|
80
|
+
@keydown.down.prevent="focusNextNode(idx)"
|
|
81
|
+
@keydown.up.prevent="focusPrevNode(idx)"
|
|
16
82
|
)
|
|
17
83
|
.node-content
|
|
18
84
|
// Toggle
|
|
@@ -31,8 +97,6 @@
|
|
|
31
97
|
// Content
|
|
32
98
|
.node-label(@click="onNodeClick(row)")
|
|
33
99
|
.selection-control(v-if="selectable")
|
|
34
|
-
// Always show selection control if selectable (implied by usage in picker)
|
|
35
|
-
// In future we might want a 'selectable' prop on row or tree
|
|
36
100
|
KCheckbox(
|
|
37
101
|
:modelValue="isNodeSelected(row)"
|
|
38
102
|
@update:modelValue="onNodeClick(row)"
|
|
@@ -41,7 +105,6 @@
|
|
|
41
105
|
|
|
42
106
|
slot(name="item" :node="row.__treeNode" :data="row")
|
|
43
107
|
slot(name="default" :node="row.__treeNode" :data="row")
|
|
44
|
-
// Default content
|
|
45
108
|
.default-item
|
|
46
109
|
KIcon(v-if="iconField && row[iconField]" :iconname="row[iconField]" :width="16" :height="16")
|
|
47
110
|
span {{ row[labelField] }}
|
|
@@ -49,9 +112,10 @@
|
|
|
49
112
|
</template>
|
|
50
113
|
|
|
51
114
|
<script lang="ts" setup>
|
|
52
|
-
import { computed, type Ref } from 'vue'
|
|
115
|
+
import { ref, computed, watch, nextTick, isRef, type Ref } from 'vue'
|
|
53
116
|
import type { TTreeRow } from '@katlux/providers'
|
|
54
117
|
import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
|
|
118
|
+
import { useVirtualScroll } from '#toolkit/composables/useVirtualScroll'
|
|
55
119
|
|
|
56
120
|
const { t } = useKatluxI18n()
|
|
57
121
|
|
|
@@ -67,10 +131,12 @@ const props = withDefaults(
|
|
|
67
131
|
isNodeSelected?: (node: any) => boolean
|
|
68
132
|
toggleNode: (id: string | number) => void
|
|
69
133
|
selectable?: boolean
|
|
70
|
-
dataProvider?:
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
134
|
+
dataProvider?: any
|
|
135
|
+
searchtext?: string
|
|
136
|
+
virtualScroll?: boolean
|
|
137
|
+
itemHeight?: number
|
|
138
|
+
viewportHeight?: number
|
|
139
|
+
buffer?: number
|
|
74
140
|
}>(),
|
|
75
141
|
{
|
|
76
142
|
labelField: 'name',
|
|
@@ -80,27 +146,179 @@ const props = withDefaults(
|
|
|
80
146
|
multiSelect: false,
|
|
81
147
|
selectable: false,
|
|
82
148
|
isNodeSelected: () => false,
|
|
149
|
+
searchtext: '',
|
|
150
|
+
virtualScroll: false,
|
|
151
|
+
itemHeight: 32,
|
|
152
|
+
viewportHeight: 400,
|
|
153
|
+
buffer: 5,
|
|
83
154
|
}
|
|
84
155
|
)
|
|
85
156
|
|
|
86
157
|
const emit = defineEmits<{
|
|
87
158
|
(e: 'select', row: TTreeRow): void
|
|
159
|
+
(e: 'node-click', row: TTreeRow): void
|
|
160
|
+
(e: 'node-toggle', id: string | number): void
|
|
88
161
|
}>()
|
|
89
162
|
|
|
163
|
+
function toggleNode(id: string | number) {
|
|
164
|
+
props.toggleNode(id)
|
|
165
|
+
emit('node-toggle', id)
|
|
166
|
+
}
|
|
167
|
+
|
|
90
168
|
function onNodeClick(row: TTreeRow) {
|
|
91
169
|
if (!props.disabled) {
|
|
92
170
|
emit('select', row)
|
|
171
|
+
emit('node-click', row)
|
|
93
172
|
}
|
|
94
173
|
}
|
|
95
174
|
|
|
96
|
-
const isLoading = computed(() =>
|
|
175
|
+
const isLoading = computed(() => {
|
|
176
|
+
const l = props.dataProvider?.loading
|
|
177
|
+
const init = props.dataProvider?.initialLoad
|
|
178
|
+
const loadingVal = isRef(l) ? l.value : (l?.value ?? l ?? false)
|
|
179
|
+
const initVal = isRef(init) ? init.value : (init?.value ?? init ?? false)
|
|
180
|
+
return Boolean(loadingVal || initVal)
|
|
181
|
+
})
|
|
182
|
+
|
|
183
|
+
// Virtual scrolling data source
|
|
184
|
+
const treeRows = computed<TTreeRow[]>(() => {
|
|
185
|
+
const _search = props.searchtext
|
|
186
|
+
const currentVisible = props.visibleRows || []
|
|
187
|
+
const dp = props.dataProvider as any
|
|
188
|
+
if (props.virtualScroll) {
|
|
189
|
+
if (Array.isArray(dp?.allVisibleRows)) return dp.allVisibleRows
|
|
190
|
+
if (Array.isArray(dp?.allVisibleRows?.value)) return dp.allVisibleRows.value
|
|
191
|
+
if (Array.isArray(dp?.allVisibleNodes)) return dp.allVisibleNodes
|
|
192
|
+
if (Array.isArray(dp?.allVisibleNodes?.value)) return dp.allVisibleNodes.value
|
|
193
|
+
if (Array.isArray(dp?.visibleRows)) return dp.visibleRows
|
|
194
|
+
if (Array.isArray(dp?.visibleRows?.value)) return dp.visibleRows.value
|
|
195
|
+
}
|
|
196
|
+
return currentVisible
|
|
197
|
+
})
|
|
198
|
+
|
|
199
|
+
const {
|
|
200
|
+
visibleItems,
|
|
201
|
+
startIndex,
|
|
202
|
+
endIndex,
|
|
203
|
+
topSpacerHeight,
|
|
204
|
+
bottomSpacerHeight,
|
|
205
|
+
containerRef,
|
|
206
|
+
onScroll,
|
|
207
|
+
containerCssVars
|
|
208
|
+
} = useVirtualScroll({
|
|
209
|
+
items: treeRows,
|
|
210
|
+
itemHeight: props.itemHeight || 32,
|
|
211
|
+
containerHeight: computed(() => props.viewportHeight || 400),
|
|
212
|
+
buffer: props.buffer ?? 5,
|
|
213
|
+
virtualScroll: computed(() => !!props.virtualScroll),
|
|
214
|
+
onThresholdReach: () => {
|
|
215
|
+
const dp = props.dataProvider as any
|
|
216
|
+
if (typeof dp?.loadMore === 'function') {
|
|
217
|
+
dp.loadMore()
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
})
|
|
221
|
+
|
|
222
|
+
const displayRows = computed(() => {
|
|
223
|
+
if (props.virtualScroll) {
|
|
224
|
+
return visibleItems.value
|
|
225
|
+
}
|
|
226
|
+
return props.visibleRows || []
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
const focusedNodeId = ref<string | number | null>(null)
|
|
230
|
+
|
|
231
|
+
const getNodeKey = (row: TTreeRow, idx: number): string | number => {
|
|
232
|
+
return row[props.idKey] ?? row.id ?? row.__treeNode?.id ?? idx
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const isNodeFocused = (row: TTreeRow, idx: number): boolean => {
|
|
236
|
+
const key = getNodeKey(row, idx)
|
|
237
|
+
if (focusedNodeId.value === null) {
|
|
238
|
+
return idx === 0
|
|
239
|
+
}
|
|
240
|
+
return focusedNodeId.value === key
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const onNodeFocus = (row: TTreeRow, idx: number) => {
|
|
244
|
+
focusedNodeId.value = getNodeKey(row, idx)
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
const focusNextNode = (currentIdx: number) => {
|
|
248
|
+
const rows = props.virtualScroll ? displayRows.value : (props.visibleRows || [])
|
|
249
|
+
if (currentIdx < rows.length - 1) {
|
|
250
|
+
const nextRow = rows[currentIdx + 1]
|
|
251
|
+
focusedNodeId.value = getNodeKey(nextRow, currentIdx + 1)
|
|
252
|
+
nextTick(() => {
|
|
253
|
+
const activeEl = document.querySelector<HTMLElement>(`.KTree .tree-node[tabindex="0"]`)
|
|
254
|
+
activeEl?.focus()
|
|
255
|
+
})
|
|
256
|
+
}
|
|
257
|
+
onKeyDownDown()
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
const focusPrevNode = (currentIdx: number) => {
|
|
261
|
+
const rows = props.virtualScroll ? displayRows.value : (props.visibleRows || [])
|
|
262
|
+
if (currentIdx > 0) {
|
|
263
|
+
const prevRow = rows[currentIdx - 1]
|
|
264
|
+
focusedNodeId.value = getNodeKey(prevRow, currentIdx - 1)
|
|
265
|
+
nextTick(() => {
|
|
266
|
+
const activeEl = document.querySelector<HTMLElement>(`.KTree .tree-node[tabindex="0"]`)
|
|
267
|
+
activeEl?.focus()
|
|
268
|
+
})
|
|
269
|
+
}
|
|
270
|
+
onKeyDownUp()
|
|
271
|
+
}
|
|
272
|
+
|
|
273
|
+
const onKeyDownDown = () => {
|
|
274
|
+
if (containerRef.value) {
|
|
275
|
+
containerRef.value.scrollTop += (props.itemHeight || 32)
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
const onKeyDownUp = () => {
|
|
280
|
+
if (containerRef.value) {
|
|
281
|
+
containerRef.value.scrollTop = Math.max(0, containerRef.value.scrollTop - (props.itemHeight || 32))
|
|
282
|
+
}
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
watch(() => props.searchtext, () => {
|
|
286
|
+
if (containerRef.value) {
|
|
287
|
+
containerRef.value.scrollTop = 0
|
|
288
|
+
}
|
|
289
|
+
})
|
|
97
290
|
</script>
|
|
98
291
|
|
|
99
292
|
<style lang="scss" scoped>
|
|
100
293
|
.KTree {
|
|
101
294
|
width: 100%;
|
|
102
|
-
position: relative;
|
|
295
|
+
position: relative;
|
|
103
296
|
|
|
297
|
+
.k-tree-virtual-container {
|
|
298
|
+
overflow-y: auto;
|
|
299
|
+
max-height: var(--virtual-container-height, 400px);
|
|
300
|
+
position: relative;
|
|
301
|
+
width: 100%;
|
|
302
|
+
|
|
303
|
+
&:focus-visible {
|
|
304
|
+
outline: 2px solid var(--primary-color, #3b82f6);
|
|
305
|
+
outline-offset: -2px;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
.k-virtual-spacer {
|
|
309
|
+
width: 100%;
|
|
310
|
+
flex-shrink: 0;
|
|
311
|
+
|
|
312
|
+
&.is-top {
|
|
313
|
+
height: var(--virtual-spacer-top, 0px);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
&.is-bottom {
|
|
317
|
+
height: var(--virtual-spacer-bottom, 0px);
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
}
|
|
321
|
+
|
|
104
322
|
.tree-list {
|
|
105
323
|
display: flex;
|
|
106
324
|
flex-direction: column;
|
|
@@ -169,3 +387,4 @@ const isLoading = computed(() => props.dataProvider?.loading?.value || props.dat
|
|
|
169
387
|
}
|
|
170
388
|
}
|
|
171
389
|
</style>
|
|
390
|
+
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { type Ref } from 'vue';
|
|
2
1
|
import type { TTreeRow } from '@katlux/providers';
|
|
3
2
|
type __VLS_Props = {
|
|
4
3
|
visibleRows: TTreeRow[];
|
|
@@ -11,19 +10,30 @@ type __VLS_Props = {
|
|
|
11
10
|
isNodeSelected?: (node: any) => boolean;
|
|
12
11
|
toggleNode: (id: string | number) => void;
|
|
13
12
|
selectable?: boolean;
|
|
14
|
-
dataProvider?:
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
dataProvider?: any;
|
|
14
|
+
searchtext?: string;
|
|
15
|
+
virtualScroll?: boolean;
|
|
16
|
+
itemHeight?: number;
|
|
17
|
+
viewportHeight?: number;
|
|
18
|
+
buffer?: number;
|
|
18
19
|
};
|
|
19
20
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
20
21
|
select: (row: TTreeRow) => any;
|
|
22
|
+
"node-toggle": (id: string | number) => any;
|
|
23
|
+
"node-click": (row: TTreeRow) => any;
|
|
21
24
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
22
25
|
onSelect?: ((row: TTreeRow) => any) | undefined;
|
|
26
|
+
"onNode-toggle"?: ((id: string | number) => any) | undefined;
|
|
27
|
+
"onNode-click"?: ((row: TTreeRow) => any) | undefined;
|
|
23
28
|
}>, {
|
|
24
29
|
disabled: boolean;
|
|
30
|
+
searchtext: string;
|
|
31
|
+
virtualScroll: boolean;
|
|
32
|
+
itemHeight: number;
|
|
33
|
+
buffer: number;
|
|
25
34
|
labelField: string;
|
|
26
35
|
multiSelect: boolean;
|
|
36
|
+
viewportHeight: number;
|
|
27
37
|
iconField: string;
|
|
28
38
|
idKey: string;
|
|
29
39
|
isNodeSelected: (node: any) => boolean;
|
|
@@ -23,13 +23,26 @@ type __VLS_Props = {
|
|
|
23
23
|
fullWidth: boolean;
|
|
24
24
|
validation?: 'success' | 'warning' | 'error' | null;
|
|
25
25
|
validationText?: string;
|
|
26
|
+
virtualScroll?: boolean;
|
|
27
|
+
itemHeight?: number;
|
|
28
|
+
viewportHeight?: number;
|
|
29
|
+
buffer?: number;
|
|
26
30
|
};
|
|
27
|
-
declare
|
|
31
|
+
declare function recalculateHeight(): void;
|
|
32
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {
|
|
33
|
+
recalculateHeight: typeof recalculateHeight;
|
|
34
|
+
calculatedHeight: import("vue").Ref<number, number>;
|
|
35
|
+
treeViewportHeight: import("vue").ComputedRef<number>;
|
|
36
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
28
37
|
"update:isOptionsOpen": (value: boolean) => any;
|
|
29
38
|
"update:searchtext": (value: string) => any;
|
|
39
|
+
"update:expandedNodes": (value: any) => any;
|
|
40
|
+
"node-toggle": (nodeId: string | number) => any;
|
|
30
41
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
31
42
|
"onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
|
|
32
43
|
"onUpdate:searchtext"?: ((value: string) => any) | undefined;
|
|
44
|
+
"onUpdate:expandedNodes"?: ((value: any) => any) | undefined;
|
|
45
|
+
"onNode-toggle"?: ((nodeId: string | number) => any) | undefined;
|
|
33
46
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
34
47
|
declare const _default: typeof __VLS_export;
|
|
35
48
|
export default _default;
|