@katlux/toolkit 0.1.1-alpha.123 → 0.1.1-alpha.125
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/cli.mjs +0 -0
- package/bin/create-preset.mjs +0 -0
- package/dist/compiled/composables/useDataProvider.mjs +7 -59
- package/dist/compiled/composables/useKatluxForm.mjs +23 -4
- package/dist/compiled/composables/usePresetComponent.mjs +1 -1
- package/dist/compiled/composables/useVirtualScroll.mjs +24 -11
- package/dist/compiled/utils/sanitize.mjs +39 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +3 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +2 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +3 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.d.ts +2 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +22 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +11 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue +4 -3
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +11 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.logic.d.ts +5 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.logic.js +4 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +3 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +3 -41
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +9 -1
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +17 -1
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +9 -1
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +7 -1
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +58 -54
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KGantt/KGantt.logic.js +2 -4
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.logic.js +2 -0
- package/dist/runtime/components/KRadiobox/KRadiobox.global.vue +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.vue +1 -1
- package/dist/runtime/components/KTextarea/KTextarea.global.vue +1 -1
- 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 +1 -1
- package/dist/runtime/components/KTree/KTree.global.vue +2 -0
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.logic.js +38 -12
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +1 -1
- package/dist/runtime/composables/useDataProvider.d.ts +1 -5
- package/dist/runtime/composables/useDataProvider.js +7 -59
- package/dist/runtime/composables/useKatluxForm.js +23 -4
- package/dist/runtime/composables/usePresetComponent.js +1 -1
- package/dist/runtime/composables/useVirtualScroll.js +24 -11
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +2 -1
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +9 -3
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +35 -12
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +9 -3
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +8 -0
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +183 -31
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +8 -0
- package/dist/runtime/presets/default/components/KIcon/KIcon.vue +5 -2
- package/dist/runtime/presets/default/components/KRadiobox/KRadiobox.vue +1 -0
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +3 -3
- package/dist/runtime/presets/default/components/KTree/KTree.vue +245 -115
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +3 -3
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.d.vue.ts +27 -0
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue +179 -0
- package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue.d.ts +27 -0
- package/dist/runtime/utils/sanitize.d.ts +5 -0
- package/dist/runtime/utils/sanitize.js +39 -0
- package/package.json +6 -3
|
@@ -6,39 +6,36 @@
|
|
|
6
6
|
:class="{ 'is-virtual-scroll': props.virtualScroll }"
|
|
7
7
|
)
|
|
8
8
|
KLoader(:loading="isLoading" overlay)
|
|
9
|
-
//- Virtual scrolling mode
|
|
9
|
+
//- Virtual scrolling mode: flat list with aria-level, aria-setsize, aria-posinset (no double tab stop)
|
|
10
10
|
.k-tree-virtual-container(
|
|
11
11
|
v-if="props.virtualScroll"
|
|
12
12
|
ref="containerRef"
|
|
13
|
-
tabindex="0"
|
|
14
|
-
role="region"
|
|
15
13
|
:style="containerCssVars"
|
|
16
14
|
@scroll.passive="onScroll"
|
|
17
|
-
@keydown.down.prevent="onKeyDownDown"
|
|
18
|
-
@keydown.up.prevent="onKeyDownUp"
|
|
19
15
|
)
|
|
20
16
|
.k-virtual-spacer.is-top(aria-hidden="true")
|
|
21
17
|
.tree-list
|
|
22
18
|
.tree-node(
|
|
23
19
|
v-for="(row, idx) in displayRows"
|
|
24
|
-
:key="row
|
|
25
|
-
:
|
|
20
|
+
:key="getNodeKey(row, startIndex + idx)"
|
|
21
|
+
:data-node-id="getNodeKey(row, startIndex + idx)"
|
|
22
|
+
:class="{ 'has-children': (row.__treeNode?.hasChildren || row.hasChildren), 'is-selected': isSelected(row) }"
|
|
26
23
|
:style="{ '--tree-depth': (row.__treeNode?.depth ?? row.depth ?? 0) }"
|
|
27
24
|
role="treeitem"
|
|
28
25
|
:aria-expanded="(row.__treeNode?.hasChildren || row.hasChildren) ? (row.__treeNode?.isExpanded ?? row.isExpanded) : undefined"
|
|
29
26
|
:aria-level="((row.__treeNode?.depth ?? row.depth ?? 0) + 1)"
|
|
30
|
-
:
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
@
|
|
35
|
-
@keydown
|
|
27
|
+
:aria-setsize="getNodeSetSize(row)"
|
|
28
|
+
:aria-posinset="getNodePosInSet(row)"
|
|
29
|
+
:aria-selected="isSelected(row)"
|
|
30
|
+
:tabindex="isNodeFocused(row, startIndex + idx) ? 0 : -1"
|
|
31
|
+
@focus="onNodeFocus(row, getNodeKey(row, startIndex + idx))"
|
|
32
|
+
@keydown="handleKeyDown($event, row)"
|
|
36
33
|
)
|
|
37
34
|
.node-content
|
|
38
35
|
// Toggle
|
|
39
36
|
.tree-toggle(
|
|
40
37
|
v-if="(row.__treeNode?.hasChildren || row.hasChildren)"
|
|
41
|
-
@click="toggleNode(row.__treeNode?.id ?? row.id)"
|
|
38
|
+
@click.stop="toggleNode(row.__treeNode?.id ?? row.id)"
|
|
42
39
|
:class="{ expanded: (row.__treeNode?.isExpanded ?? row.isExpanded) }"
|
|
43
40
|
role="button"
|
|
44
41
|
:aria-label="t('Toggle node')"
|
|
@@ -52,71 +49,45 @@
|
|
|
52
49
|
.node-label(@click="onNodeClick(row)")
|
|
53
50
|
.selection-control(v-if="selectable")
|
|
54
51
|
KCheckbox(
|
|
55
|
-
:modelValue="
|
|
52
|
+
:modelValue="isSelected(row)"
|
|
56
53
|
@update:modelValue="onNodeClick(row)"
|
|
57
54
|
@click.stop
|
|
58
55
|
)
|
|
59
56
|
|
|
60
|
-
slot(name="
|
|
61
|
-
slot(name="
|
|
62
|
-
.
|
|
63
|
-
|
|
64
|
-
|
|
57
|
+
slot(name="node" :node="row.__treeNode || row" :data="row")
|
|
58
|
+
slot(name="item" :node="row.__treeNode || row" :data="row")
|
|
59
|
+
slot(name="default" :node="row.__treeNode || row" :data="row")
|
|
60
|
+
.default-item
|
|
61
|
+
KIcon(v-if="iconField && row[iconField]" :iconname="row[iconField]" :width="16" :height="16")
|
|
62
|
+
span {{ row[labelField] }}
|
|
65
63
|
.k-virtual-spacer.is-bottom(aria-hidden="true")
|
|
66
64
|
|
|
67
|
-
//- Traditional standard tree list
|
|
65
|
+
//- Traditional standard tree list: hierarchical with role="group" wrapping child nodes
|
|
68
66
|
.tree-list(v-else)
|
|
69
|
-
|
|
70
|
-
v-for="
|
|
71
|
-
:key="
|
|
72
|
-
:
|
|
73
|
-
:
|
|
74
|
-
|
|
75
|
-
:
|
|
76
|
-
:
|
|
77
|
-
:
|
|
78
|
-
@focus="onNodeFocus
|
|
79
|
-
@
|
|
80
|
-
@
|
|
81
|
-
@keydown
|
|
82
|
-
@keydown.up.prevent="focusPrevNode(idx)"
|
|
67
|
+
KTreeNodeItem(
|
|
68
|
+
v-for="rootNode in visibleTree"
|
|
69
|
+
:key="rootNode.key"
|
|
70
|
+
:node="rootNode"
|
|
71
|
+
:labelField="labelField"
|
|
72
|
+
:iconField="iconField"
|
|
73
|
+
:selectable="selectable"
|
|
74
|
+
:focusedNodeId="effectiveFocusedNodeId"
|
|
75
|
+
:isSelected="isSelected"
|
|
76
|
+
@focus="onNodeFocus"
|
|
77
|
+
@click="onNodeClick"
|
|
78
|
+
@toggle="toggleNode"
|
|
79
|
+
@keydown="handleKeyDown"
|
|
83
80
|
)
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
.tree-toggle(
|
|
87
|
-
v-if="row.__treeNode?.hasChildren && row.__treeNode?.id !== undefined"
|
|
88
|
-
@click="toggleNode(row.__treeNode.id)"
|
|
89
|
-
:class="{ expanded: row.__treeNode?.isExpanded }"
|
|
90
|
-
role="button"
|
|
91
|
-
:aria-label="t('Toggle node')"
|
|
92
|
-
tabindex="-1"
|
|
93
|
-
)
|
|
94
|
-
KIcon(iconname="chevron" :width="12" :height="12" :rotate="row.__treeNode?.isExpanded ? '90' : '0'")
|
|
95
|
-
|
|
96
|
-
.tree-spacer(v-else)
|
|
97
|
-
|
|
98
|
-
// Content
|
|
99
|
-
.node-label(@click="onNodeClick(row)")
|
|
100
|
-
.selection-control(v-if="selectable")
|
|
101
|
-
KCheckbox(
|
|
102
|
-
:modelValue="isNodeSelected(row)"
|
|
103
|
-
@update:modelValue="onNodeClick(row)"
|
|
104
|
-
@click.stop
|
|
105
|
-
)
|
|
106
|
-
|
|
107
|
-
slot(name="item" :node="row.__treeNode" :data="row")
|
|
108
|
-
slot(name="default" :node="row.__treeNode" :data="row")
|
|
109
|
-
.default-item
|
|
110
|
-
KIcon(v-if="iconField && row[iconField]" :iconname="row[iconField]" :width="16" :height="16")
|
|
111
|
-
span {{ row[labelField] }}
|
|
112
|
-
|
|
81
|
+
template(v-for="(_, slot) in $slots" #[slot]="scope")
|
|
82
|
+
slot(:name="slot" v-bind="scope")
|
|
113
83
|
</template>
|
|
114
84
|
|
|
115
85
|
<script lang="ts" setup>
|
|
116
|
-
import { ref, computed, watch, nextTick, isRef
|
|
86
|
+
import { ref, computed, watch, nextTick, isRef } from 'vue'
|
|
117
87
|
import type { TTreeRow } from '@katlux/providers'
|
|
118
88
|
import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
|
|
119
89
|
import { useVirtualScroll } from '#toolkit/composables/useVirtualScroll'
|
|
90
|
+
import KTreeNodeItem, { type ITreeRenderNode } from './KTreeNodeItem.vue'
|
|
120
91
|
|
|
121
92
|
const { t } = useKatluxI18n()
|
|
122
93
|
|
|
@@ -135,6 +106,8 @@ const props = withDefaults(
|
|
|
135
106
|
selectable?: boolean
|
|
136
107
|
dataProvider?: any
|
|
137
108
|
searchtext?: string
|
|
109
|
+
modelValue?: any
|
|
110
|
+
selectedNode?: any
|
|
138
111
|
virtualScroll?: boolean
|
|
139
112
|
itemHeight?: number
|
|
140
113
|
viewportHeight?: number
|
|
@@ -158,12 +131,10 @@ const props = withDefaults(
|
|
|
158
131
|
|
|
159
132
|
const emit = defineEmits<{
|
|
160
133
|
(e: 'select', row: TTreeRow): void
|
|
161
|
-
(e: 'node-toggle', id: string | number): void
|
|
162
134
|
}>()
|
|
163
135
|
|
|
164
136
|
function toggleNode(id: string | number) {
|
|
165
137
|
props.toggleNode(id)
|
|
166
|
-
emit('node-toggle', id)
|
|
167
138
|
}
|
|
168
139
|
|
|
169
140
|
function onNodeClick(row: TTreeRow) {
|
|
@@ -172,6 +143,21 @@ function onNodeClick(row: TTreeRow) {
|
|
|
172
143
|
}
|
|
173
144
|
}
|
|
174
145
|
|
|
146
|
+
const isSelected = (row: TTreeRow): boolean => {
|
|
147
|
+
if (typeof props.isNodeSelected === 'function' && props.isNodeSelected(row)) {
|
|
148
|
+
return true
|
|
149
|
+
}
|
|
150
|
+
const node = row.__treeNode || row
|
|
151
|
+
const id = row[props.idKey] ?? row.id ?? node.id
|
|
152
|
+
const target = props.selectedNode || props.modelValue
|
|
153
|
+
if (target) {
|
|
154
|
+
if (target === row || target === node) return true
|
|
155
|
+
if (typeof target === 'object' && (target.id === id || target[props.idKey] === id)) return true
|
|
156
|
+
if (target === id) return true
|
|
157
|
+
}
|
|
158
|
+
return false
|
|
159
|
+
}
|
|
160
|
+
|
|
175
161
|
const isLoading = computed(() => {
|
|
176
162
|
const l = props.dataProvider?.loading
|
|
177
163
|
const init = props.dataProvider?.initialLoad
|
|
@@ -182,7 +168,6 @@ const isLoading = computed(() => {
|
|
|
182
168
|
|
|
183
169
|
// Virtual scrolling data source
|
|
184
170
|
const treeRows = computed<TTreeRow[]>(() => {
|
|
185
|
-
const _search = props.searchtext
|
|
186
171
|
const currentVisible = props.visibleRows || []
|
|
187
172
|
const dp = props.dataProvider as any
|
|
188
173
|
if (props.virtualScroll) {
|
|
@@ -204,6 +189,7 @@ const {
|
|
|
204
189
|
bottomSpacerHeight,
|
|
205
190
|
containerRef,
|
|
206
191
|
onScroll,
|
|
192
|
+
scrollToIndex,
|
|
207
193
|
containerCssVars
|
|
208
194
|
} = useVirtualScroll({
|
|
209
195
|
items: treeRows,
|
|
@@ -226,61 +212,200 @@ const displayRows = computed(() => {
|
|
|
226
212
|
return props.visibleRows || []
|
|
227
213
|
})
|
|
228
214
|
|
|
229
|
-
|
|
215
|
+
// Build hierarchical structure for non-virtual WAI-ARIA role="group" nesting
|
|
216
|
+
function buildVisibleTree(rows: TTreeRow[]): ITreeRenderNode[] {
|
|
217
|
+
const rootNodes: ITreeRenderNode[] = []
|
|
218
|
+
const stack: { depth: number; node: ITreeRenderNode }[] = []
|
|
230
219
|
|
|
231
|
-
const
|
|
232
|
-
|
|
233
|
-
|
|
220
|
+
for (const row of rows) {
|
|
221
|
+
const depth = row.__treeNode?.depth ?? row.depth ?? 0
|
|
222
|
+
const key = getNodeKey(row)
|
|
223
|
+
const renderNode: ITreeRenderNode = { key, row, children: [] }
|
|
234
224
|
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
225
|
+
while (stack.length > 0 && stack[stack.length - 1].depth >= depth) {
|
|
226
|
+
stack.pop()
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
if (stack.length === 0) {
|
|
230
|
+
rootNodes.push(renderNode)
|
|
231
|
+
} else {
|
|
232
|
+
stack[stack.length - 1].node.children.push(renderNode)
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
stack.push({ depth, node: renderNode })
|
|
239
236
|
}
|
|
240
|
-
return focusedNodeId.value === key
|
|
241
|
-
}
|
|
242
237
|
|
|
243
|
-
|
|
244
|
-
focusedNodeId.value = getNodeKey(row, idx)
|
|
238
|
+
return rootNodes
|
|
245
239
|
}
|
|
246
240
|
|
|
247
|
-
const
|
|
241
|
+
const visibleTree = computed(() => {
|
|
242
|
+
return buildVisibleTree(props.visibleRows || [])
|
|
243
|
+
})
|
|
248
244
|
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
245
|
+
// Precalculate sibling setsize and posinset for virtual WAI-ARIA compliance
|
|
246
|
+
const nodeSiblingMeta = computed(() => {
|
|
247
|
+
const rows = props.virtualScroll ? treeRows.value : (props.visibleRows || [])
|
|
248
|
+
const groups = new Map<string | number | null, (string | number)[]>()
|
|
249
|
+
for (const r of rows) {
|
|
250
|
+
const pid = r.__treeNode?.parentId ?? r.parentId ?? null
|
|
251
|
+
const id = r[props.idKey] ?? r.id ?? r.__treeNode?.id
|
|
252
|
+
if (!groups.has(pid)) {
|
|
253
|
+
groups.set(pid, [])
|
|
254
|
+
}
|
|
255
|
+
groups.get(pid)!.push(id)
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
const meta = new Map<string | number, { posInSet: number; setSize: number }>()
|
|
259
|
+
for (const [, ids] of groups) {
|
|
260
|
+
const setSize = ids.length
|
|
261
|
+
ids.forEach((id, idx) => {
|
|
262
|
+
meta.set(id, { posInSet: idx + 1, setSize })
|
|
257
263
|
})
|
|
258
264
|
}
|
|
259
|
-
|
|
265
|
+
return meta
|
|
266
|
+
})
|
|
267
|
+
|
|
268
|
+
const getNodeSetSize = (row: TTreeRow): number => {
|
|
269
|
+
const id = row[props.idKey] ?? row.id ?? row.__treeNode?.id
|
|
270
|
+
return nodeSiblingMeta.value.get(id)?.setSize ?? 1
|
|
260
271
|
}
|
|
261
272
|
|
|
262
|
-
const
|
|
263
|
-
const
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
273
|
+
const getNodePosInSet = (row: TTreeRow): number => {
|
|
274
|
+
const id = row[props.idKey] ?? row.id ?? row.__treeNode?.id
|
|
275
|
+
return nodeSiblingMeta.value.get(id)?.posInSet ?? 1
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
const focusedNodeId = ref<string | number | null>(null)
|
|
279
|
+
|
|
280
|
+
const getNodeKey = (row: TTreeRow, idx?: number): string | number => {
|
|
281
|
+
return row[props.idKey] ?? row.id ?? row.__treeNode?.id ?? (idx !== undefined ? idx : 0)
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
const effectiveFocusedNodeId = computed<string | number | null>(() => {
|
|
285
|
+
if (focusedNodeId.value !== null) return focusedNodeId.value
|
|
286
|
+
const visibleList = props.virtualScroll ? treeRows.value : (props.visibleRows || [])
|
|
287
|
+
if (visibleList.length > 0) {
|
|
288
|
+
return getNodeKey(visibleList[0], 0)
|
|
271
289
|
}
|
|
272
|
-
|
|
290
|
+
return null
|
|
291
|
+
})
|
|
292
|
+
|
|
293
|
+
const isNodeFocused = (row: TTreeRow, idx?: number): boolean => {
|
|
294
|
+
const key = getNodeKey(row, idx)
|
|
295
|
+
return effectiveFocusedNodeId.value === key
|
|
273
296
|
}
|
|
274
297
|
|
|
275
|
-
const
|
|
276
|
-
|
|
277
|
-
|
|
298
|
+
const onNodeFocus = (row: TTreeRow, key?: string | number) => {
|
|
299
|
+
focusedNodeId.value = key ?? getNodeKey(row)
|
|
300
|
+
}
|
|
301
|
+
|
|
302
|
+
const treeRootRef = ref<HTMLElement | null>(null)
|
|
303
|
+
|
|
304
|
+
const setFocusToNode = (row: TTreeRow, idx?: number) => {
|
|
305
|
+
const key = getNodeKey(row, idx)
|
|
306
|
+
focusedNodeId.value = key
|
|
307
|
+
if (props.virtualScroll && idx !== undefined) {
|
|
308
|
+
const itemH = props.itemHeight || 32
|
|
309
|
+
const vpH = props.viewportHeight || 400
|
|
310
|
+
const targetTop = idx * itemH
|
|
311
|
+
if (containerRef.value) {
|
|
312
|
+
const currentScroll = containerRef.value.scrollTop
|
|
313
|
+
if (targetTop < currentScroll) {
|
|
314
|
+
scrollToIndex(idx)
|
|
315
|
+
} else if (targetTop + itemH > currentScroll + vpH) {
|
|
316
|
+
const offset = Math.max(0, vpH - itemH)
|
|
317
|
+
scrollToIndex(idx, 'auto', offset)
|
|
318
|
+
}
|
|
319
|
+
}
|
|
278
320
|
}
|
|
321
|
+
nextTick(() => {
|
|
322
|
+
const root = containerRef.value || treeRootRef.value
|
|
323
|
+
if (!root) return
|
|
324
|
+
const targetEl = root.querySelector<HTMLElement>(`.tree-node[data-node-id="${key}"]`)
|
|
325
|
+
|| root.querySelector<HTMLElement>(`.tree-node[tabindex="0"]`)
|
|
326
|
+
targetEl?.focus()
|
|
327
|
+
})
|
|
279
328
|
}
|
|
280
329
|
|
|
281
|
-
const
|
|
282
|
-
|
|
283
|
-
|
|
330
|
+
const handleKeyDown = (e: KeyboardEvent, row: TTreeRow) => {
|
|
331
|
+
e.stopPropagation()
|
|
332
|
+
const visibleList = props.virtualScroll ? treeRows.value : (props.visibleRows || [])
|
|
333
|
+
if (visibleList.length === 0) return
|
|
334
|
+
|
|
335
|
+
const currentKey = getNodeKey(row)
|
|
336
|
+
const currentIdx = visibleList.findIndex(r => getNodeKey(r) === currentKey)
|
|
337
|
+
const currentRow = currentIdx !== -1 ? visibleList[currentIdx] : row
|
|
338
|
+
|
|
339
|
+
const k = e.key
|
|
340
|
+
const isDown = k === 'ArrowDown' || k === 'down' || k === 'Down'
|
|
341
|
+
const isUp = k === 'ArrowUp' || k === 'up' || k === 'Up'
|
|
342
|
+
const isRight = k === 'ArrowRight' || k === 'right' || k === 'Right'
|
|
343
|
+
const isLeft = k === 'ArrowLeft' || k === 'left' || k === 'Left'
|
|
344
|
+
const isHome = k === 'Home' || k === 'home'
|
|
345
|
+
const isEnd = k === 'End' || k === 'end'
|
|
346
|
+
const isEnter = k === 'Enter' || k === 'enter'
|
|
347
|
+
const isSpace = k === ' ' || k === 'Space' || k === 'space'
|
|
348
|
+
|
|
349
|
+
if (isDown) {
|
|
350
|
+
e.preventDefault()
|
|
351
|
+
if (currentIdx < visibleList.length - 1) {
|
|
352
|
+
setFocusToNode(visibleList[currentIdx + 1], currentIdx + 1)
|
|
353
|
+
}
|
|
354
|
+
} else if (isUp) {
|
|
355
|
+
e.preventDefault()
|
|
356
|
+
if (currentIdx > 0) {
|
|
357
|
+
setFocusToNode(visibleList[currentIdx - 1], currentIdx - 1)
|
|
358
|
+
}
|
|
359
|
+
} else if (isRight) {
|
|
360
|
+
e.preventDefault()
|
|
361
|
+
const hasChildren = Boolean(currentRow.__treeNode?.hasChildren ?? currentRow.hasChildren)
|
|
362
|
+
const isExpanded = Boolean(currentRow.__treeNode?.isExpanded ?? currentRow.isExpanded)
|
|
363
|
+
if (hasChildren) {
|
|
364
|
+
if (!isExpanded) {
|
|
365
|
+
toggleNode(currentRow.__treeNode?.id ?? currentRow.id)
|
|
366
|
+
} else if (currentIdx < visibleList.length - 1) {
|
|
367
|
+
setFocusToNode(visibleList[currentIdx + 1], currentIdx + 1)
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
} else if (isLeft) {
|
|
371
|
+
e.preventDefault()
|
|
372
|
+
const hasChildren = Boolean(currentRow.__treeNode?.hasChildren ?? currentRow.hasChildren)
|
|
373
|
+
const isExpanded = Boolean(currentRow.__treeNode?.isExpanded ?? currentRow.isExpanded)
|
|
374
|
+
if (hasChildren && isExpanded) {
|
|
375
|
+
toggleNode(currentRow.__treeNode?.id ?? currentRow.id)
|
|
376
|
+
} else {
|
|
377
|
+
const parentId = currentRow.__treeNode?.parentId ?? currentRow.parentId
|
|
378
|
+
if (parentId !== null && parentId !== undefined) {
|
|
379
|
+
const parentIdx = visibleList.findIndex(r => getNodeKey(r) === parentId)
|
|
380
|
+
if (parentIdx !== -1) {
|
|
381
|
+
setFocusToNode(visibleList[parentIdx], parentIdx)
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
} else if (isHome) {
|
|
386
|
+
e.preventDefault()
|
|
387
|
+
if (visibleList.length > 0) {
|
|
388
|
+
if (props.virtualScroll) scrollToIndex(0)
|
|
389
|
+
setFocusToNode(visibleList[0], 0)
|
|
390
|
+
}
|
|
391
|
+
} else if (isEnd) {
|
|
392
|
+
e.preventDefault()
|
|
393
|
+
if (visibleList.length > 0) {
|
|
394
|
+
const lastIdx = visibleList.length - 1
|
|
395
|
+
if (props.virtualScroll) scrollToIndex(lastIdx)
|
|
396
|
+
setFocusToNode(visibleList[lastIdx], lastIdx)
|
|
397
|
+
}
|
|
398
|
+
} else if (isEnter) {
|
|
399
|
+
e.preventDefault()
|
|
400
|
+
onNodeClick(currentRow)
|
|
401
|
+
} else if (isSpace) {
|
|
402
|
+
e.preventDefault()
|
|
403
|
+
const hasChildren = Boolean(currentRow.__treeNode?.hasChildren ?? currentRow.hasChildren)
|
|
404
|
+
if (hasChildren) {
|
|
405
|
+
toggleNode(currentRow.__treeNode?.id ?? currentRow.id)
|
|
406
|
+
} else {
|
|
407
|
+
onNodeClick(currentRow)
|
|
408
|
+
}
|
|
284
409
|
}
|
|
285
410
|
}
|
|
286
411
|
|
|
@@ -328,20 +453,27 @@ watch(() => props.searchtext, () => {
|
|
|
328
453
|
|
|
329
454
|
.tree-node {
|
|
330
455
|
display: flex;
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
min-height: 32px;
|
|
456
|
+
flex-direction: column;
|
|
457
|
+
width: 100%;
|
|
334
458
|
transition: background-color 0.2s;
|
|
335
459
|
|
|
336
|
-
&:
|
|
337
|
-
|
|
460
|
+
&:focus-visible {
|
|
461
|
+
outline: 2px solid var(--primary-color, #3b82f6);
|
|
462
|
+
outline-offset: -2px;
|
|
338
463
|
}
|
|
339
|
-
|
|
464
|
+
|
|
340
465
|
.node-content {
|
|
341
466
|
display: flex;
|
|
342
467
|
align-items: center;
|
|
468
|
+
padding: 4px 8px 4px calc(8px + var(--tree-depth, 0) * var(--tree-indent, 20px));
|
|
469
|
+
min-height: 32px;
|
|
343
470
|
width: 100%;
|
|
344
471
|
gap: 4px;
|
|
472
|
+
cursor: pointer;
|
|
473
|
+
|
|
474
|
+
&:hover {
|
|
475
|
+
background-color: var(--border-color-light, rgba(0, 0, 0, 0.04));
|
|
476
|
+
}
|
|
345
477
|
}
|
|
346
478
|
|
|
347
479
|
.tree-toggle {
|
|
@@ -355,7 +487,7 @@ watch(() => props.searchtext, () => {
|
|
|
355
487
|
flex-shrink: 0;
|
|
356
488
|
|
|
357
489
|
&:hover {
|
|
358
|
-
background-color: var(--neutral-300);
|
|
490
|
+
background-color: var(--neutral-300, #e2e8f0);
|
|
359
491
|
}
|
|
360
492
|
}
|
|
361
493
|
|
|
@@ -384,9 +516,7 @@ watch(() => props.searchtext, () => {
|
|
|
384
516
|
display: flex;
|
|
385
517
|
align-items: center;
|
|
386
518
|
gap: 6px;
|
|
387
|
-
cursor: pointer;
|
|
388
519
|
}
|
|
389
520
|
}
|
|
390
521
|
}
|
|
391
522
|
</style>
|
|
392
|
-
|
|
@@ -13,6 +13,8 @@ type __VLS_Props = {
|
|
|
13
13
|
selectable?: boolean;
|
|
14
14
|
dataProvider?: any;
|
|
15
15
|
searchtext?: string;
|
|
16
|
+
modelValue?: any;
|
|
17
|
+
selectedNode?: any;
|
|
16
18
|
virtualScroll?: boolean;
|
|
17
19
|
itemHeight?: number;
|
|
18
20
|
viewportHeight?: number;
|
|
@@ -20,10 +22,8 @@ type __VLS_Props = {
|
|
|
20
22
|
};
|
|
21
23
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
22
24
|
select: (row: TTreeRow) => any;
|
|
23
|
-
"node-toggle": (id: string | number) => any;
|
|
24
25
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
25
26
|
onSelect?: ((row: TTreeRow) => any) | undefined;
|
|
26
|
-
"onNode-toggle"?: ((id: string | number) => any) | undefined;
|
|
27
27
|
}>, {
|
|
28
28
|
disabled: boolean;
|
|
29
29
|
idKey: string;
|
|
@@ -35,8 +35,8 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
35
35
|
multiSelect: boolean;
|
|
36
36
|
viewportHeight: number;
|
|
37
37
|
iconField: string;
|
|
38
|
-
isNodeSelected: (node: any) => boolean;
|
|
39
38
|
selectable: boolean;
|
|
39
|
+
isNodeSelected: (node: any) => boolean;
|
|
40
40
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
41
41
|
declare const _default: typeof __VLS_export;
|
|
42
42
|
export default _default;
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import type { TTreeRow } from '@katlux/providers';
|
|
2
|
+
export interface ITreeRenderNode {
|
|
3
|
+
key: string | number;
|
|
4
|
+
row: TTreeRow;
|
|
5
|
+
children: ITreeRenderNode[];
|
|
6
|
+
}
|
|
7
|
+
type __VLS_Props = {
|
|
8
|
+
node: ITreeRenderNode;
|
|
9
|
+
labelField: string;
|
|
10
|
+
iconField: string;
|
|
11
|
+
selectable: boolean;
|
|
12
|
+
focusedNodeId: string | number | null;
|
|
13
|
+
isSelected: (row: TTreeRow) => boolean;
|
|
14
|
+
};
|
|
15
|
+
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
16
|
+
click: (row: TTreeRow) => any;
|
|
17
|
+
focus: (row: TTreeRow, key: string | number) => any;
|
|
18
|
+
keydown: (event: KeyboardEvent, row: TTreeRow) => any;
|
|
19
|
+
toggle: (id: string | number) => any;
|
|
20
|
+
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
21
|
+
onClick?: ((row: TTreeRow) => any) | undefined;
|
|
22
|
+
onFocus?: ((row: TTreeRow, key: string | number) => any) | undefined;
|
|
23
|
+
onKeydown?: ((event: KeyboardEvent, row: TTreeRow) => any) | undefined;
|
|
24
|
+
onToggle?: ((id: string | number) => any) | undefined;
|
|
25
|
+
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
26
|
+
declare const _default: typeof __VLS_export;
|
|
27
|
+
export default _default;
|