@katlux/toolkit 0.1.1-alpha.118 → 0.1.1-alpha.120

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 (139) hide show
  1. package/bin/create-preset.mjs +5 -4
  2. package/dist/compiled/composables/useDataProvider.mjs +20 -0
  3. package/dist/compiled/composables/useKatluxContext.mjs +6 -3
  4. package/dist/compiled/composables/useKatluxForm.mjs +311 -0
  5. package/dist/compiled/composables/useToast.mjs +164 -0
  6. package/dist/compiled/composables/useVirtualScroll.mjs +246 -0
  7. package/dist/module.cjs +1 -0
  8. package/dist/module.json +1 -1
  9. package/dist/module.mjs +1 -0
  10. package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
  11. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
  12. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
  13. package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +21 -6
  14. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +12 -0
  15. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue +4 -2
  16. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +12 -0
  17. package/dist/runtime/components/KCheckbox/KCheckbox.logic.d.ts +5 -0
  18. package/dist/runtime/components/KCheckbox/KCheckbox.logic.js +4 -0
  19. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +11 -0
  20. package/dist/runtime/components/KCombobox/KCombobox.global.vue +4 -3
  21. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +11 -0
  22. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +6 -0
  23. package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
  24. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
  25. package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
  26. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
  27. package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
  28. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
  29. package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
  30. package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
  31. package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
  32. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
  33. package/dist/runtime/components/KDatatable/KDatatable.logic.js +28 -5
  34. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +4 -0
  35. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +6 -1
  36. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +4 -0
  37. package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
  38. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
  39. package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
  40. package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
  41. package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
  42. package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
  43. package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
  44. package/dist/runtime/components/KGantt/KGantt.logic.js +5 -3
  45. package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +2 -0
  46. package/dist/runtime/components/KPagination/KPagination.global.vue +1 -1
  47. package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +2 -0
  48. package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -0
  49. package/dist/runtime/components/KPagination/KPagination.logic.js +11 -3
  50. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
  51. package/dist/runtime/components/KToast/KToast.global.vue +12 -2
  52. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
  53. package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
  54. package/dist/runtime/components/KToast/KToast.logic.js +45 -5
  55. package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
  56. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
  57. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
  58. package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
  59. package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
  60. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +39 -1
  61. package/dist/runtime/components/KTree/KTree.global.vue +7 -4
  62. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +39 -1
  63. package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
  64. package/dist/runtime/components/KTree/KTree.logic.js +17 -0
  65. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +53 -2
  66. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
  67. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +53 -2
  68. package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
  69. package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
  70. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +37 -1
  71. package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
  72. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +37 -1
  73. package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
  74. package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
  75. package/dist/runtime/composables/useDataProvider.d.ts +1 -0
  76. package/dist/runtime/composables/useDataProvider.js +20 -0
  77. package/dist/runtime/composables/useKatluxContext.js +6 -3
  78. package/dist/runtime/composables/useKatluxForm.d.ts +145 -0
  79. package/dist/runtime/composables/useKatluxForm.js +311 -0
  80. package/dist/runtime/composables/useToast.d.ts +49 -0
  81. package/dist/runtime/composables/useToast.js +164 -0
  82. package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
  83. package/dist/runtime/composables/useVirtualScroll.js +246 -0
  84. package/dist/runtime/plugins/PresetPlugin.js +9 -1
  85. package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
  86. package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
  87. package/dist/runtime/plugins/toastPlugin.client.js +16 -0
  88. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
  89. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +3 -0
  90. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +43 -7
  91. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +3 -0
  92. package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +3 -0
  93. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +12 -4
  94. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +3 -0
  95. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
  96. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
  97. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
  98. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +12 -1
  99. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +143 -7
  100. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +12 -1
  101. package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
  102. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +228 -32
  103. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
  104. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.d.vue.ts +3 -1
  105. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue +3 -1
  106. package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue.d.ts +3 -1
  107. package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
  108. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
  109. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
  110. package/dist/runtime/presets/default/components/KLayout/KLayout.d.vue.ts +6 -1
  111. package/dist/runtime/presets/default/components/KLayout/KLayout.vue +37 -3
  112. package/dist/runtime/presets/default/components/KLayout/KLayout.vue.d.ts +6 -1
  113. package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
  114. package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
  115. package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
  116. package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
  117. package/dist/runtime/presets/default/components/KToast/KToast.vue +21 -4
  118. package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
  119. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
  120. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +206 -0
  121. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
  122. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -6
  123. package/dist/runtime/presets/default/components/KTree/KTree.vue +235 -14
  124. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -6
  125. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
  126. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
  127. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
  128. package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
  129. package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
  130. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
  131. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
  132. package/dist/runtime/server/middleware/session.js +1 -1
  133. package/package.json +3 -4
  134. package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
  135. package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
  136. package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
  137. package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
  138. package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
  139. package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
@@ -1,18 +1,85 @@
1
1
  <template lang="pug">
2
- .KTree(role="tree" :aria-label="t('Hierarchical Tree')")
2
+ .KTree(
3
+ ref="treeRootRef"
4
+ role="tree"
5
+ :aria-label="t('Hierarchical Tree')"
6
+ :class="{ 'is-virtual-scroll': props.virtualScroll }"
7
+ )
3
8
  KLoader(:loading="isLoading" overlay)
4
- .tree-list
9
+ //- Virtual scrolling mode
10
+ .k-tree-virtual-container(
11
+ v-if="props.virtualScroll"
12
+ ref="containerRef"
13
+ tabindex="0"
14
+ role="region"
15
+ :style="containerCssVars"
16
+ @scroll.passive="onScroll"
17
+ @keydown.down.prevent="onKeyDownDown"
18
+ @keydown.up.prevent="onKeyDownUp"
19
+ )
20
+ .k-virtual-spacer.is-top(aria-hidden="true")
21
+ .tree-list
22
+ .tree-node(
23
+ v-for="(row, idx) in displayRows"
24
+ :key="row[idKey] || row.id || (startIndex + idx)"
25
+ :class="{ 'has-children': (row.__treeNode?.hasChildren || row.hasChildren) }"
26
+ :style="{ '--tree-depth': (row.__treeNode?.depth ?? row.depth ?? 0) }"
27
+ role="treeitem"
28
+ :aria-expanded="(row.__treeNode?.hasChildren || row.hasChildren) ? (row.__treeNode?.isExpanded ?? row.isExpanded) : undefined"
29
+ :aria-level="((row.__treeNode?.depth ?? row.depth ?? 0) + 1)"
30
+ :tabindex="isNodeFocused(row, idx) ? 0 : -1"
31
+ @focus="onNodeFocus(row, idx)"
32
+ @keydown.enter.prevent="onNodeClick(row)"
33
+ @keydown.space.prevent="(row.__treeNode?.hasChildren || row.hasChildren) ? toggleNode(row.__treeNode?.id ?? row.id) : onNodeClick(row)"
34
+ @keydown.down.prevent="focusNextNode(idx)"
35
+ @keydown.up.prevent="focusPrevNode(idx)"
36
+ )
37
+ .node-content
38
+ // Toggle
39
+ .tree-toggle(
40
+ v-if="(row.__treeNode?.hasChildren || row.hasChildren)"
41
+ @click="toggleNode(row.__treeNode?.id ?? row.id)"
42
+ :class="{ expanded: (row.__treeNode?.isExpanded ?? row.isExpanded) }"
43
+ role="button"
44
+ :aria-label="t('Toggle node')"
45
+ tabindex="-1"
46
+ )
47
+ KIcon(iconname="chevron" :width="12" :height="12" :rotate="(row.__treeNode?.isExpanded ?? row.isExpanded) ? '90' : '0'")
48
+
49
+ .tree-spacer(v-else)
50
+
51
+ // Content
52
+ .node-label(@click="onNodeClick(row)")
53
+ .selection-control(v-if="selectable")
54
+ KCheckbox(
55
+ :modelValue="isNodeSelected(row)"
56
+ @update:modelValue="onNodeClick(row)"
57
+ @click.stop
58
+ )
59
+
60
+ slot(name="item" :node="row.__treeNode || row" :data="row")
61
+ slot(name="default" :node="row.__treeNode || row" :data="row")
62
+ .default-item
63
+ KIcon(v-if="iconField && row[iconField]" :iconname="row[iconField]" :width="16" :height="16")
64
+ span {{ row[labelField] }}
65
+ .k-virtual-spacer.is-bottom(aria-hidden="true")
66
+
67
+ //- Traditional standard tree list
68
+ .tree-list(v-else)
5
69
  .tree-node(
6
- v-for="row in visibleRows"
70
+ v-for="(row, idx) in visibleRows"
7
71
  :key="row[idKey] || row.id"
8
72
  :class="{ 'has-children': row.__treeNode?.hasChildren }"
9
73
  :style="{ '--tree-depth': row.__treeNode?.depth || 0 }"
10
74
  role="treeitem"
11
75
  :aria-expanded="row.__treeNode?.hasChildren ? row.__treeNode?.isExpanded : undefined"
12
76
  :aria-level="(row.__treeNode?.depth || 0) + 1"
13
- tabindex="0"
77
+ :tabindex="isNodeFocused(row, idx) ? 0 : -1"
78
+ @focus="onNodeFocus(row, idx)"
14
79
  @keydown.enter.prevent="onNodeClick(row)"
15
80
  @keydown.space.prevent="row.__treeNode?.hasChildren && row.__treeNode?.id !== undefined ? toggleNode(row.__treeNode.id) : onNodeClick(row)"
81
+ @keydown.down.prevent="focusNextNode(idx)"
82
+ @keydown.up.prevent="focusPrevNode(idx)"
16
83
  )
17
84
  .node-content
18
85
  // Toggle
@@ -31,8 +98,6 @@
31
98
  // Content
32
99
  .node-label(@click="onNodeClick(row)")
33
100
  .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
101
  KCheckbox(
37
102
  :modelValue="isNodeSelected(row)"
38
103
  @update:modelValue="onNodeClick(row)"
@@ -41,7 +106,6 @@
41
106
 
42
107
  slot(name="item" :node="row.__treeNode" :data="row")
43
108
  slot(name="default" :node="row.__treeNode" :data="row")
44
- // Default content
45
109
  .default-item
46
110
  KIcon(v-if="iconField && row[iconField]" :iconname="row[iconField]" :width="16" :height="16")
47
111
  span {{ row[labelField] }}
@@ -49,9 +113,10 @@
49
113
  </template>
50
114
 
51
115
  <script lang="ts" setup>
52
- import { computed, type Ref } from 'vue'
116
+ import { ref, computed, watch, nextTick, isRef, type Ref } from 'vue'
53
117
  import type { TTreeRow } from '@katlux/providers'
54
118
  import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
119
+ import { useVirtualScroll } from '#toolkit/composables/useVirtualScroll'
55
120
 
56
121
  const { t } = useKatluxI18n()
57
122
 
@@ -66,11 +131,14 @@ const props = withDefaults(
66
131
  multiSelect?: boolean
67
132
  isNodeSelected?: (node: any) => boolean
68
133
  toggleNode: (id: string | number) => void
134
+ selectNode?: (node: any) => void
69
135
  selectable?: boolean
70
- dataProvider?: {
71
- loading: Ref<boolean>
72
- initialLoad?: Ref<boolean>
73
- }
136
+ dataProvider?: any
137
+ searchtext?: string
138
+ virtualScroll?: boolean
139
+ itemHeight?: number
140
+ viewportHeight?: number
141
+ buffer?: number
74
142
  }>(),
75
143
  {
76
144
  labelField: 'name',
@@ -80,27 +148,179 @@ const props = withDefaults(
80
148
  multiSelect: false,
81
149
  selectable: false,
82
150
  isNodeSelected: () => false,
151
+ searchtext: '',
152
+ virtualScroll: false,
153
+ itemHeight: 32,
154
+ viewportHeight: 400,
155
+ buffer: 5,
83
156
  }
84
157
  )
85
158
 
86
159
  const emit = defineEmits<{
87
160
  (e: 'select', row: TTreeRow): void
161
+ (e: 'node-toggle', id: string | number): void
88
162
  }>()
89
163
 
164
+ function toggleNode(id: string | number) {
165
+ props.toggleNode(id)
166
+ emit('node-toggle', id)
167
+ }
168
+
90
169
  function onNodeClick(row: TTreeRow) {
91
170
  if (!props.disabled) {
92
171
  emit('select', row)
93
172
  }
94
173
  }
95
174
 
96
- const isLoading = computed(() => props.dataProvider?.loading?.value || props.dataProvider?.initialLoad?.value || false)
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 treeRootRef = ref<HTMLElement | null>(null)
248
+
249
+ const focusNextNode = (currentIdx: number) => {
250
+ const rows = props.virtualScroll ? displayRows.value : (props.visibleRows || [])
251
+ if (currentIdx < rows.length - 1) {
252
+ const nextRow = rows[currentIdx + 1]
253
+ focusedNodeId.value = getNodeKey(nextRow, currentIdx + 1)
254
+ nextTick(() => {
255
+ const activeEl = (treeRootRef.value || containerRef.value)?.querySelector<HTMLElement>(`.tree-node[tabindex="0"]`)
256
+ activeEl?.focus()
257
+ })
258
+ }
259
+ onKeyDownDown()
260
+ }
261
+
262
+ const focusPrevNode = (currentIdx: number) => {
263
+ const rows = props.virtualScroll ? displayRows.value : (props.visibleRows || [])
264
+ if (currentIdx > 0) {
265
+ const prevRow = rows[currentIdx - 1]
266
+ focusedNodeId.value = getNodeKey(prevRow, currentIdx - 1)
267
+ nextTick(() => {
268
+ const activeEl = (treeRootRef.value || containerRef.value)?.querySelector<HTMLElement>(`.tree-node[tabindex="0"]`)
269
+ activeEl?.focus()
270
+ })
271
+ }
272
+ onKeyDownUp()
273
+ }
274
+
275
+ const onKeyDownDown = () => {
276
+ if (containerRef.value) {
277
+ containerRef.value.scrollTop += (props.itemHeight || 32)
278
+ }
279
+ }
280
+
281
+ const onKeyDownUp = () => {
282
+ if (containerRef.value) {
283
+ containerRef.value.scrollTop = Math.max(0, containerRef.value.scrollTop - (props.itemHeight || 32))
284
+ }
285
+ }
286
+
287
+ watch(() => props.searchtext, () => {
288
+ if (containerRef.value) {
289
+ containerRef.value.scrollTop = 0
290
+ }
291
+ })
97
292
  </script>
98
293
 
99
294
  <style lang="scss" scoped>
100
295
  .KTree {
101
296
  width: 100%;
102
- position: relative; // Ensure loader overlay is contained
297
+ position: relative;
103
298
 
299
+ .k-tree-virtual-container {
300
+ overflow-y: auto;
301
+ max-height: var(--virtual-container-height, 400px);
302
+ position: relative;
303
+ width: 100%;
304
+
305
+ &:focus-visible {
306
+ outline: 2px solid var(--primary-color, #3b82f6);
307
+ outline-offset: -2px;
308
+ }
309
+
310
+ .k-virtual-spacer {
311
+ width: 100%;
312
+ flex-shrink: 0;
313
+
314
+ &.is-top {
315
+ height: var(--virtual-spacer-top, 0px);
316
+ }
317
+
318
+ &.is-bottom {
319
+ height: var(--virtual-spacer-bottom, 0px);
320
+ }
321
+ }
322
+ }
323
+
104
324
  .tree-list {
105
325
  display: flex;
106
326
  flex-direction: column;
@@ -169,3 +389,4 @@ const isLoading = computed(() => props.dataProvider?.loading?.value || props.dat
169
389
  }
170
390
  }
171
391
  </style>
392
+
@@ -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[];
@@ -10,22 +9,32 @@ type __VLS_Props = {
10
9
  multiSelect?: boolean;
11
10
  isNodeSelected?: (node: any) => boolean;
12
11
  toggleNode: (id: string | number) => void;
12
+ selectNode?: (node: any) => void;
13
13
  selectable?: boolean;
14
- dataProvider?: {
15
- loading: Ref<boolean>;
16
- initialLoad?: Ref<boolean>;
17
- };
14
+ dataProvider?: any;
15
+ searchtext?: string;
16
+ virtualScroll?: boolean;
17
+ itemHeight?: number;
18
+ viewportHeight?: number;
19
+ buffer?: number;
18
20
  };
19
21
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
22
  select: (row: TTreeRow) => any;
23
+ "node-toggle": (id: string | number) => 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;
23
27
  }>, {
24
28
  disabled: boolean;
29
+ idKey: string;
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
- idKey: string;
29
38
  isNodeSelected: (node: any) => boolean;
30
39
  selectable: boolean;
31
40
  }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
@@ -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 const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
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;
@@ -18,8 +18,12 @@ KCombobox(
18
18
  :fullWidth="fullWidth"
19
19
  :validation="validation"
20
20
  :validationText="validationText"
21
+ :maxHeight="dropdownMaxHeight"
21
22
  )
22
- .KTreePicker__tree-container
23
+ .KTreePicker__tree-container(
24
+ :class="{ 'is-virtual': virtualScroll }"
25
+ :style="containerStyle"
26
+ )
23
27
  .KTreePicker__search(v-if="searchbox")
24
28
  KTextbox(
25
29
  v-model="searchtextModel"
@@ -37,12 +41,19 @@ KCombobox(
37
41
  :isNodeSelected="isSelected"
38
42
  :searchtext="searchtext"
39
43
  :selectable="true"
44
+ :virtualScroll="virtualScroll"
45
+ :itemHeight="itemHeight"
46
+ :viewportHeight="treeViewportHeight"
47
+ :buffer="buffer"
40
48
  @select="onTreeSelect"
49
+ @node-toggle="onNodeToggle"
50
+ @update:expandedNodes="onExpandedNodesUpdate"
41
51
  )
42
52
  </template>
43
53
 
44
54
  <script lang="ts" setup>
45
- import { computed } from 'vue'
55
+ import { computed, ref, watch, onMounted, onBeforeUnmount, nextTick } from 'vue'
56
+
46
57
  // Props passed from global component (which handles the logic)
47
58
  const props = defineProps<{
48
59
  label?: string
@@ -72,11 +83,17 @@ const props = defineProps<{
72
83
  fullWidth: boolean
73
84
  validation?: 'success' | 'warning' | 'error' | null
74
85
  validationText?: string
86
+ virtualScroll?: boolean
87
+ itemHeight?: number
88
+ viewportHeight?: number
89
+ buffer?: number
75
90
  }>()
76
91
 
77
92
  const emit = defineEmits<{
78
93
  (e: 'update:searchtext', value: string): void
79
94
  (e: 'update:isOptionsOpen', value: boolean): void
95
+ (e: 'node-toggle', nodeId: string | number): void
96
+ (e: 'update:expandedNodes', value: any): void
80
97
  }>()
81
98
 
82
99
  const searchtextModel = computed({
@@ -90,17 +107,103 @@ const isOptionsOpenModel = computed({
90
107
  })
91
108
 
92
109
  function onTreeSelect(node: any) {
93
- // Call the selectItem method from logic
94
110
  props.selectItem(node)
95
-
96
- // If closeOnSelect is true, we should close the dropdown
97
- // but selectItem might have already toggled it if it was a distinct action?
98
- // In KCombobox.logic.ts: selectItem sets isOptionsOpen = !closeOnSelect
99
- // So it should be handled there!
100
-
101
- // However, selectItem expects a ComboboxItem (TDataRow).
102
- // KTree returns a node object which should be compatible.
103
111
  }
112
+
113
+ function getVisibleCount(): number {
114
+ const dp = props.dataProvider as any
115
+ if (!dp) return 0
116
+ if (Array.isArray(dp.allVisibleRows)) return dp.allVisibleRows.length
117
+ if (Array.isArray(dp.allVisibleRows?.value)) return dp.allVisibleRows.value.length
118
+ if (Array.isArray(dp.allVisibleNodes)) return dp.allVisibleNodes.length
119
+ if (Array.isArray(dp.allVisibleNodes?.value)) return dp.allVisibleNodes.value.length
120
+ if (Array.isArray(dp.visibleRows)) return dp.visibleRows.length
121
+ if (Array.isArray(dp.visibleRows?.value)) return dp.visibleRows.value.length
122
+ if (Array.isArray(dp.pageData)) return dp.pageData.length
123
+ if (Array.isArray(dp.pageData?.value)) return dp.pageData.value.length
124
+ return 0
125
+ }
126
+
127
+ const calculatedHeight = ref<number>(props.viewportHeight || 300)
128
+
129
+ function recalculateHeight() {
130
+ const count = getVisibleCount()
131
+ const itemH = props.itemHeight || 32
132
+ const maxH = props.viewportHeight || 300
133
+
134
+ if (count <= 0) {
135
+ calculatedHeight.value = Math.min(maxH, itemH * 2)
136
+ return
137
+ }
138
+
139
+ const rawHeight = count * itemH
140
+ calculatedHeight.value = Math.min(maxH, rawHeight)
141
+ }
142
+
143
+ const treeViewportHeight = computed(() => calculatedHeight.value)
144
+
145
+ const containerStyle = computed(() => {
146
+ const searchH = props.searchbox ? 44 : 0
147
+ const padding = 20
148
+ const totalH = calculatedHeight.value + searchH + padding
149
+ return {
150
+ maxHeight: `${totalH}px`,
151
+ height: props.virtualScroll ? `${totalH}px` : 'auto'
152
+ }
153
+ })
154
+
155
+ const dropdownMaxHeight = computed(() => {
156
+ return (props.viewportHeight || 300) + (props.searchbox ? 44 : 0) + 40
157
+ })
158
+
159
+ function onNodeToggle(nodeId: string | number) {
160
+ recalculateHeight()
161
+ nextTick(() => recalculateHeight())
162
+ emit('node-toggle', nodeId)
163
+ }
164
+
165
+ function onExpandedNodesUpdate(val: any) {
166
+ recalculateHeight()
167
+ nextTick(() => recalculateHeight())
168
+ emit('update:expandedNodes', val)
169
+ }
170
+
171
+ let unsubscribe: (() => void) | null = null
172
+
173
+ onMounted(() => {
174
+ recalculateHeight()
175
+ if (props.dataProvider?.subscribe) {
176
+ unsubscribe = props.dataProvider.subscribe(() => {
177
+ recalculateHeight()
178
+ })
179
+ }
180
+ })
181
+
182
+ onBeforeUnmount(() => {
183
+ if (typeof unsubscribe === 'function') {
184
+ unsubscribe()
185
+ }
186
+ })
187
+
188
+ watch(() => props.isOptionsOpen, (open) => {
189
+ if (open) {
190
+ nextTick(recalculateHeight)
191
+ }
192
+ })
193
+
194
+ watch(() => props.searchtext, () => {
195
+ nextTick(recalculateHeight)
196
+ })
197
+
198
+ watch(() => props.viewportHeight, () => {
199
+ recalculateHeight()
200
+ })
201
+
202
+ defineExpose({
203
+ recalculateHeight,
204
+ calculatedHeight,
205
+ treeViewportHeight
206
+ })
104
207
  </script>
105
208
 
106
209
  <style lang="scss" scoped>
@@ -115,7 +218,9 @@ function onTreeSelect(node: any) {
115
218
  min-width: 250px;
116
219
  background-color: var(--panel-bg-default);
117
220
  color: var(--font-color-primary);
118
- }
119
-
120
221
 
222
+ &.is-virtual {
223
+ overflow-y: hidden;
224
+ }
225
+ }
121
226
  </style>
@@ -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 const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
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;
@@ -1,6 +1,15 @@
1
1
  <template lang="pug">
2
- .tree-cell(:style="{ '--tree-depth': depth }")
3
- .tree-toggle(v-if="hasChildren" @click.stop="toggle")
2
+ .tree-cell(:style="{ '--tree-node-depth': depth, '--tree-depth': depth }")
3
+ .tree-toggle(
4
+ v-if="hasChildren"
5
+ role="button"
6
+ tabindex="0"
7
+ :aria-expanded="isExpanded"
8
+ aria-label="Toggle node"
9
+ @click.stop="toggle"
10
+ @keydown.enter.prevent.stop="toggle"
11
+ @keydown.space.prevent.stop="toggle"
12
+ )
4
13
  KIcon(iconname="chevron" :width="12" :height="12" :rotate="isExpanded ? '90' : '0'")
5
14
  .tree-spacer(v-else)
6
15
  span.tree-content {{ value }}
@@ -21,7 +30,7 @@ defineProps<{
21
30
  display: flex;
22
31
  align-items: center;
23
32
  gap: 4px;
24
- padding-left: calc(var(--tree-depth, 0) * var(--tree-indent, 24px));
33
+ padding-left: calc(var(--tree-node-depth, var(--tree-depth, 0)) * var(--tree-indent, 24px));
25
34
  }
26
35
 
27
36
  .tree-toggle {
@@ -18,6 +18,10 @@ type __VLS_Props = {
18
18
  headerSlots?: Record<string, any>;
19
19
  columnHeaders?: Record<string, string>;
20
20
  columnWidths?: Record<string, string>;
21
+ virtualScroll?: boolean;
22
+ itemHeight?: number;
23
+ viewportHeight?: number;
24
+ buffer?: number;
21
25
  };
22
26
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
23
27
  "update:selectedRows": (value: any[]) => any;
@@ -11,6 +11,10 @@
11
11
  :columnWidths="columnWidths"
12
12
  :selectedRows="selectedRows"
13
13
  :selectAll="selectAll"
14
+ :virtualScroll="virtualScroll"
15
+ :itemHeight="itemHeight"
16
+ :viewportHeight="viewportHeight"
17
+ :buffer="buffer"
14
18
  @update:selectedRows="$emit('update:selectedRows', $event)"
15
19
  @update:selectAll="$emit('update:selectAll', $event)"
16
20
  )
@@ -50,6 +54,10 @@ const props = defineProps<{
50
54
  headerSlots?: Record<string, any>
51
55
  columnHeaders?: Record<string, string>
52
56
  columnWidths?: Record<string, string>
57
+ virtualScroll?: boolean
58
+ itemHeight?: number
59
+ viewportHeight?: number
60
+ buffer?: number
53
61
  }>()
54
62
 
55
63
  const emit = defineEmits<{
@@ -18,6 +18,10 @@ type __VLS_Props = {
18
18
  headerSlots?: Record<string, any>;
19
19
  columnHeaders?: Record<string, string>;
20
20
  columnWidths?: Record<string, string>;
21
+ virtualScroll?: boolean;
22
+ itemHeight?: number;
23
+ viewportHeight?: number;
24
+ buffer?: number;
21
25
  };
22
26
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
23
27
  "update:selectedRows": (value: any[]) => any;
@@ -27,7 +27,7 @@ export default defineEventHandler((event) => {
27
27
  path: "/",
28
28
  maxAge: 365 * 24 * 60 * 60,
29
29
  sameSite: "lax",
30
- httpOnly: false
30
+ httpOnly: true
31
31
  });
32
32
  } catch {
33
33
  }