@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,8 +1,35 @@
1
1
  <template lang="pug">
2
- .k-data-iterator(role="region" :aria-label="t('Data Iterator')")
2
+ .k-data-iterator(
3
+ role="region"
4
+ :aria-label="t('Data Iterator')"
5
+ :class="{ 'is-virtual-scroll': props.virtualScroll }"
6
+ )
3
7
  KLoader(:loading="isLoading" overlay)
4
8
  KGrid(v-if="hasData" direction="column" gap="10px" align="stretch")
5
- KGrid(direction="column" gap="10px" align="stretch")
9
+ //- Virtual scrolling mode
10
+ .k-data-iterator-virtual-container(
11
+ v-if="props.virtualScroll"
12
+ ref="containerRef"
13
+ tabindex="0"
14
+ role="feed"
15
+ aria-busy="false"
16
+ :style="containerCssVars"
17
+ @scroll.passive="onScroll"
18
+ @keydown.down.prevent="onKeyDownDown"
19
+ @keydown.up.prevent="onKeyDownUp"
20
+ )
21
+ .k-virtual-spacer.is-top(aria-hidden="true")
22
+ .k-data-iterator-item(
23
+ v-for="(row, index) in displayRows"
24
+ :key="getRowKey(row, startIndex + index)"
25
+ :data-index="startIndex + index"
26
+ )
27
+ slot(name="row" :row="row" :index="startIndex + index" :rowActions="props.rowActions")
28
+ slot(:row="row" :index="startIndex + index" :rowActions="props.rowActions")
29
+ .k-virtual-spacer.is-bottom(aria-hidden="true")
30
+
31
+ //- Traditional paginated mode
32
+ KGrid(v-else direction="column" gap="10px" align="stretch")
6
33
  .k-data-iterator-item(v-for="(row, index) in pageRows" :key="getRowKey(row, index)")
7
34
  slot(name="row" :row="row" :index="index" :rowActions="props.rowActions")
8
35
  slot(:row="row" :index="index" :rowActions="props.rowActions")
@@ -14,7 +41,7 @@
14
41
  :selectedRows="selectedRows"
15
42
  :selectAll="selectAll"
16
43
  )
17
- KPagination(:dataProvider="props.dataProvider")
44
+ KPagination(v-if="!props.virtualScroll" :dataProvider="props.dataProvider")
18
45
  span.no-record(v-if="showNoRecord") {{ t('No record') }}
19
46
  </template>
20
47
 
@@ -24,10 +51,11 @@ import { ADataProvider } from '@katlux/providers'
24
51
  import type { IKDatatableAction } from '@katlux/providers'
25
52
  import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
26
53
  import { useDataProvider } from '#toolkit/composables/useDataProvider'
54
+ import { useVirtualScroll } from '#toolkit/composables/useVirtualScroll'
27
55
 
28
56
  const { t } = useKatluxI18n()
29
57
 
30
- const props = defineProps<{
58
+ const props = withDefaults(defineProps<{
31
59
  dataProvider: ADataProvider
32
60
  visibleFields?: Array<string> | null
33
61
  rowActions?: Array<IKDatatableAction>
@@ -39,7 +67,18 @@ const props = defineProps<{
39
67
  itemsPerPage?: number
40
68
  page?: number
41
69
  slots?: any
42
- }>()
70
+ virtualScroll?: boolean
71
+ itemHeight?: number
72
+ viewportHeight?: number
73
+ buffer?: number
74
+ gap?: number
75
+ }>(), {
76
+ virtualScroll: false,
77
+ itemHeight: 60,
78
+ viewportHeight: 500,
79
+ buffer: 5,
80
+ gap: 10
81
+ })
43
82
 
44
83
  const emit = defineEmits<{
45
84
  (e: 'update:selectedRows', value: any[]): void
@@ -56,11 +95,76 @@ const selectAll = computed({
56
95
  set: (val) => emit('update:selectAll', val)
57
96
  })
58
97
 
59
- const { pageData, loading: dpLoading, initialLoad: dpInitialLoad } = useDataProvider(props.dataProvider)
98
+ const { pageData, virtualRows, loading: dpLoading, initialLoad: dpInitialLoad } = useDataProvider(props.dataProvider)
60
99
  const pageRows = computed(() => pageData.value || [])
61
100
 
101
+ // Virtual scroll data source
102
+ const iteratorItems = computed(() => {
103
+ const currentRows = pageRows.value
104
+ const dp = props.dataProvider as any
105
+ if (props.virtualScroll) {
106
+ if (Array.isArray(dp?.rowMap)) return dp.rowMap
107
+ if (Array.isArray(dp?.rowMap?.value)) return dp.rowMap.value
108
+ if (Array.isArray(virtualRows?.value) && virtualRows.value.length > 0) return virtualRows.value
109
+ if (Array.isArray(dp?.allVisibleRows)) return dp.allVisibleRows
110
+ if (Array.isArray(dp?.allVisibleRows?.value)) return dp.allVisibleRows.value
111
+ if (Array.isArray(dp?.allData?.value)) return dp.allData.value
112
+ if (Array.isArray(dp?.allData)) return dp.allData
113
+ if (Array.isArray(dp?.data)) return dp.data
114
+ }
115
+ return currentRows
116
+ })
117
+
118
+ // Pitch height includes gap between items
119
+ const effectivePitchHeight = computed(() => (props.itemHeight || 60) + (props.gap ?? 10))
120
+
121
+ const {
122
+ visibleItems,
123
+ startIndex,
124
+ endIndex,
125
+ topSpacerHeight,
126
+ bottomSpacerHeight,
127
+ containerRef,
128
+ onScroll,
129
+ scrollToIndex,
130
+ containerCssVars
131
+ } = useVirtualScroll({
132
+ items: iteratorItems,
133
+ itemHeight: effectivePitchHeight,
134
+ containerHeight: props.viewportHeight || 500,
135
+ buffer: props.buffer ?? 5,
136
+ virtualScroll: computed(() => !!props.virtualScroll),
137
+ onThresholdReach: () => {
138
+ const dp = props.dataProvider as any
139
+ if (typeof dp?.loadMore === 'function') {
140
+ dp.loadMore()
141
+ } else if (typeof dp?.nextPage === 'function' && dp.hasMore) {
142
+ dp.nextPage()
143
+ }
144
+ }
145
+ })
146
+
147
+ const displayRows = computed(() => {
148
+ if (props.virtualScroll) {
149
+ return visibleItems.value
150
+ }
151
+ return pageRows.value
152
+ })
153
+
154
+ const onKeyDownDown = () => {
155
+ if (containerRef.value) {
156
+ containerRef.value.scrollTop += effectivePitchHeight.value
157
+ }
158
+ }
159
+
160
+ const onKeyDownUp = () => {
161
+ if (containerRef.value) {
162
+ containerRef.value.scrollTop = Math.max(0, containerRef.value.scrollTop - effectivePitchHeight.value)
163
+ }
164
+ }
165
+
62
166
  const isLoading = computed(() => props.loading || dpLoading.value || dpInitialLoad.value || false)
63
- const hasData = computed(() => pageRows.value.length > 0)
167
+ const hasData = computed(() => (props.virtualScroll ? iteratorItems.value.length > 0 : pageRows.value.length > 0))
64
168
  const showNoRecord = computed(() => !isLoading.value && !hasData.value)
65
169
 
66
170
  const getRowKey = (row: any, index: number): string | number => {
@@ -82,11 +186,43 @@ const getRowKey = (row: any, index: number): string | number => {
82
186
  .k-data-iterator {
83
187
  position: relative;
84
188
  width: 100%;
189
+
85
190
  .no-record {
86
191
  display: block;
87
192
  padding: 1rem;
88
193
  text-align: center;
89
194
  color: var(--font-color-secondary, #6b7280);
90
195
  }
196
+
197
+ .k-data-iterator-virtual-container {
198
+ overflow-y: auto;
199
+ max-height: var(--virtual-container-height, 500px);
200
+ position: relative;
201
+ display: flex;
202
+ flex-direction: column;
203
+ gap: 0;
204
+
205
+ &:focus-visible {
206
+ outline: 2px solid var(--primary-color, #3b82f6);
207
+ outline-offset: -2px;
208
+ }
209
+
210
+ .k-data-iterator-item {
211
+ margin-bottom: 10px;
212
+ }
213
+
214
+ .k-virtual-spacer {
215
+ width: 100%;
216
+ flex-shrink: 0;
217
+
218
+ &.is-top {
219
+ height: var(--virtual-spacer-top, 0px);
220
+ }
221
+
222
+ &.is-bottom {
223
+ height: var(--virtual-spacer-bottom, 0px);
224
+ }
225
+ }
226
+ }
91
227
  }
92
228
  </style>
@@ -12,6 +12,11 @@ type __VLS_Props = {
12
12
  itemsPerPage?: number;
13
13
  page?: number;
14
14
  slots?: any;
15
+ virtualScroll?: boolean;
16
+ itemHeight?: number;
17
+ viewportHeight?: number;
18
+ buffer?: number;
19
+ gap?: number;
15
20
  };
16
21
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
17
22
  "update:selectedRows": (value: any[]) => any;
@@ -19,6 +24,12 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
19
24
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
20
25
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
21
26
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
22
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
27
+ }>, {
28
+ virtualScroll: boolean;
29
+ itemHeight: number;
30
+ buffer: number;
31
+ viewportHeight: number;
32
+ gap: number;
33
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
23
34
  declare const _default: typeof __VLS_export;
24
35
  export default _default;
@@ -15,6 +15,10 @@ type __VLS_Props = {
15
15
  columnWidths?: Record<string, string>;
16
16
  emptyStateText?: string;
17
17
  emptyFilterStateText?: string;
18
+ virtualScroll?: boolean;
19
+ itemHeight?: number;
20
+ viewportHeight?: number;
21
+ buffer?: number;
18
22
  };
19
23
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
24
  "update:currentPage": (value: number) => any;
@@ -26,6 +30,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
26
30
  "onUpdate:pageSize"?: ((value: number) => any) | undefined;
27
31
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
28
32
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
29
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
33
+ }>, {
34
+ virtualScroll: boolean;
35
+ itemHeight: number;
36
+ buffer: number;
37
+ viewportHeight: number;
38
+ emptyStateText: string;
39
+ emptyFilterStateText: string;
40
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
30
41
  declare const _default: typeof __VLS_export;
31
42
  export default _default;
@@ -1,12 +1,22 @@
1
1
  <template lang="pug">
2
- .k-datatable(:style="{ '--page-size': props.dataProvider?.pageSize?.value || 10 }" role="region" :aria-label="t('Data Table')")
2
+ .k-datatable(
3
+ :class="{ 'is-virtual-scroll': props.virtualScroll }"
4
+ :style="props.virtualScroll ? { ...containerCssVars, '--k-datatable-viewport-height': (props.viewportHeight || 500) + 'px' } : { '--page-size': effectivePageSize }"
5
+ role="region"
6
+ :aria-label="t('Data Table')"
7
+ )
3
8
  KGrid(:flex-child="true" align="stretch" direction="column")
4
- .datatable-container
9
+ .datatable-container(
10
+ ref="containerRef"
11
+ @scroll="props.virtualScroll ? onScroll($event) : undefined"
12
+ @keydown="handleKeyDown"
13
+ :tabindex="props.virtualScroll ? 0 : undefined"
14
+ )
5
15
  KLoader(:loading="isLoading" overlay)
6
16
  table(role="grid" :aria-busy="isLoading")
7
17
  thead
8
18
  tr
9
- th.check(v-if="props.bulkActions && props.bulkActions.length>0")
19
+ th.check(v-if="props.bulkActions && props.bulkActions.length > 0")
10
20
  KCheckbox(v-model="selectAll")
11
21
  th(
12
22
  v-for="field in visibleFields || props.dataProvider.fields"
@@ -16,16 +26,26 @@
16
26
  )
17
27
  component(v-if="getHeaderSlot(field)" :is="getHeaderSlot(field)" :field="field")
18
28
  span(v-else) {{ columnHeaders?.[field] ?? field }}
19
- th(v-if="props.rowActions && props.rowActions.length>0")
29
+ th(v-if="props.rowActions && props.rowActions.length > 0")
20
30
 
21
31
  tbody
22
- tr.empty-row(v-if="!isLoading && (!pageRows || pageRows.length === 0)")
23
- td.empty-state(:colspan="(visibleFields || props.dataProvider.fields || []).length + (props.bulkActions && props.bulkActions.length > 0 ? 1 : 0) + (props.rowActions && props.rowActions.length > 0 ? 1 : 0)")
32
+ tr.empty-row(v-if="!isLoading && (!datatableItems || datatableItems.length === 0)")
33
+ td.empty-state(:colspan="totalColspan")
24
34
  span(v-if="dpFilter?.active || props.dataProvider.filter?.value?.active") {{ props.emptyFilterStateText || t('No result found for filter') }}
25
35
  span(v-else) {{ props.emptyStateText || t('No result') }}
26
- tr(v-for="(row, index) in pageRows" :key="getRowKey(row, index)")
27
- td.check(v-if="props.bulkActions && props.bulkActions.length>0")
28
- KCheckbox(:value="row" v-model="selectedRows")
36
+ tr.k-virtual-spacer.is-top(
37
+ v-if="props.virtualScroll && topSpacerHeight > 0"
38
+ :style="{ '--spacer-height': topSpacerHeight + 'px' }"
39
+ role="presentation"
40
+ )
41
+ td(:colspan="totalColspan")
42
+ tr(
43
+ v-for="(row, index) in displayRows"
44
+ :key="getRowKey(row, index)"
45
+ :class="{ 'selected': isRowSelected(row), 'active-focus': focusedIndex === (props.virtualScroll ? startIndex + index : index), 'alt-row': (props.virtualScroll ? (startIndex + index) % 2 === 1 : index % 2 === 1) }"
46
+ )
47
+ td.check(v-if="props.bulkActions && props.bulkActions.length > 0")
48
+ KCheckbox(:value="row" v-model="selectedRows" :idKey="rowIdKey")
29
49
  td(
30
50
  v-for="visibleField in visibleFields || props.dataProvider.fields"
31
51
  :key="visibleField"
@@ -34,7 +54,7 @@
34
54
  )
35
55
  component(v-if="getCellSlot(visibleField)" :is="getCellSlot(visibleField)" :row="row" :field="visibleField" :value="row[visibleField]")
36
56
  span(v-else) {{ row[visibleField] }}
37
- td.rowAction(v-if="props.rowActions && props.rowActions.length>0")
57
+ td.rowAction(v-if="props.rowActions && props.rowActions.length > 0")
38
58
  template(v-for="rowAction in props.rowActions" :key="rowAction.label")
39
59
  KTooltip(
40
60
  v-if="!rowAction.visible || rowAction.visible(row)"
@@ -51,21 +71,30 @@
51
71
  template(#icon v-if="rowAction.icon")
52
72
  KIcon(:iconname="rowAction.icon" :width="16" :height="16")
53
73
  template(#default v-if="!rowAction.iconOnly && !rowAction.icon") {{rowAction.label}}
54
- .footer
55
- KBulkActions.bulk-actions(v-if="props.bulkActions && props.bulkActions.length>0" :bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll")
56
- KPagination.pagination(:dataProvider="props.dataProvider" :currentPage="props.currentPage" :pageSize="props.pageSize" @update:currentPage="emit('update:currentPage', $event)" @update:pageSize="emit('update:pageSize', $event)")
74
+ tr.k-virtual-spacer.is-bottom(
75
+ v-if="props.virtualScroll && bottomSpacerHeight > 0"
76
+ :style="{ '--spacer-height': bottomSpacerHeight + 'px' }"
77
+ role="presentation"
78
+ )
79
+ td(:colspan="totalColspan")
80
+ .footer(v-if="!props.virtualScroll")
81
+ KBulkActions.bulk-actions(v-if="props.bulkActions && props.bulkActions.length > 0" :bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll")
82
+ KPagination.pagination(:dataProvider="props.dataProvider" @update:currentPage="emit('update:currentPage', $event)" @update:pageSize="emit('update:pageSize', $event)")
83
+ .footer.virtual-footer(v-else-if="props.bulkActions && props.bulkActions.length > 0")
84
+ KBulkActions.bulk-actions(:bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll")
57
85
  </template>
58
86
 
59
87
  <script setup lang="ts">
60
- import { computed } from 'vue'
88
+ import { ref, computed, isRef } from 'vue'
61
89
  import { ADataProvider } from '@katlux/providers'
62
90
  import type { IKDatatableAction } from '@katlux/providers'
63
91
  import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
64
92
  import { useDataProvider } from '#toolkit/composables/useDataProvider'
93
+ import { useVirtualScroll } from '#toolkit/composables/useVirtualScroll'
65
94
 
66
95
  const { t } = useKatluxI18n()
67
96
 
68
- const props = defineProps<{
97
+ const props = withDefaults(defineProps<{
69
98
  dataProvider: ADataProvider
70
99
  visibleFields: Array<string> | null
71
100
  rowActions: Array<IKDatatableAction>
@@ -80,7 +109,18 @@ const props = defineProps<{
80
109
  columnWidths?: Record<string, string>
81
110
  emptyStateText?: string
82
111
  emptyFilterStateText?: string
83
- }>()
112
+ virtualScroll?: boolean
113
+ itemHeight?: number
114
+ viewportHeight?: number
115
+ buffer?: number
116
+ }>(), {
117
+ virtualScroll: false,
118
+ itemHeight: 40,
119
+ viewportHeight: 500,
120
+ buffer: 5,
121
+ emptyStateText: 'no result',
122
+ emptyFilterStateText: 'no result found for filter',
123
+ })
84
124
 
85
125
  const emit = defineEmits<{
86
126
  (e: 'update:selectedRows', value: any[]): void
@@ -100,6 +140,8 @@ const selectAll = computed({
100
140
  set: (val) => emit('update:selectAll', val)
101
141
  })
102
142
 
143
+ const rowIdKey = computed(() => (props.dataProvider as any)?.idKey || 'id')
144
+
103
145
  const getRowKey = (row: any, index: number): string | number => {
104
146
  const idKey = (props.dataProvider as any)?.idKey || 'id'
105
147
  if (row && row[idKey] !== undefined && row[idKey] !== null) {
@@ -111,7 +153,24 @@ const getRowKey = (row: any, index: number): string | number => {
111
153
  if (row && row._id !== undefined && row._id !== null) {
112
154
  return row._id
113
155
  }
114
- return index
156
+ return props.virtualScroll ? startIndex.value + index : index
157
+ }
158
+
159
+ const selectedRowIds = computed(() => {
160
+ const idKey = (props.dataProvider as any)?.idKey || 'id'
161
+ const set = new Set<any>()
162
+ for (const r of selectedRows.value || []) {
163
+ const id = r?.[idKey] ?? r?.id ?? r?._id ?? r
164
+ set.add(id)
165
+ set.add(r)
166
+ }
167
+ return set
168
+ })
169
+
170
+ const isRowSelected = (row: any) => {
171
+ const idKey = (props.dataProvider as any)?.idKey || 'id'
172
+ const rowId = row?.[idKey] ?? row?.id ?? row?._id ?? row
173
+ return selectedRowIds.value.has(rowId) || selectedRowIds.value.has(row)
115
174
  }
116
175
 
117
176
  const getCellSlot = (fieldName: string) => {
@@ -130,12 +189,112 @@ const getColumnStyle = (field: string) => {
130
189
  return { width: w, whiteSpace: 'nowrap' as const }
131
190
  }
132
191
 
133
- const { pageData, filter: dpFilter, loading: dpLoading, initialLoad: dpInitialLoad } = useDataProvider(props.dataProvider)
192
+ const { pageData, virtualRows, filter: dpFilter, loading: dpLoading, initialLoad: dpInitialLoad } = useDataProvider(props.dataProvider)
134
193
  const pageRows = computed(() => pageData.value || [])
135
194
 
195
+ const effectivePageSize = computed(() => {
196
+ const ps = props.pageSize ?? props.dataProvider?.pageSize
197
+ return isRef(ps) ? ps.value : ((ps as any)?.value ?? ps ?? 10)
198
+ })
199
+
136
200
  const isLoading = computed(() => {
137
201
  return dpLoading.value || dpInitialLoad.value || false
138
202
  })
203
+
204
+ // Data source for virtualization: full items array when virtualScroll is true
205
+ const datatableItems = computed(() => {
206
+ const currentRows = pageRows.value
207
+ const dp = props.dataProvider as any
208
+ if (props.virtualScroll) {
209
+ if (Array.isArray(dp?.rowMap)) return dp.rowMap
210
+ if (Array.isArray(dp?.rowMap?.value)) return dp.rowMap.value
211
+ if (Array.isArray(virtualRows?.value) && virtualRows.value.length > 0) return virtualRows.value
212
+ if (Array.isArray(dp?.allVisibleRows)) return dp.allVisibleRows
213
+ if (Array.isArray(dp?.allVisibleRows?.value)) return dp.allVisibleRows.value
214
+ if (Array.isArray(dp?.allVisibleNodes)) return dp.allVisibleNodes
215
+ if (Array.isArray(dp?.allVisibleNodes?.value)) return dp.allVisibleNodes.value
216
+ if (Array.isArray(dp?.allData?.value)) return dp.allData.value
217
+ if (Array.isArray(dp?.allData)) return dp.allData
218
+ if (Array.isArray(dp?.data)) return dp.data
219
+ }
220
+ return currentRows
221
+ })
222
+
223
+ const {
224
+ visibleItems,
225
+ startIndex,
226
+ endIndex,
227
+ topSpacerHeight,
228
+ bottomSpacerHeight,
229
+ containerRef,
230
+ onScroll,
231
+ scrollToIndex,
232
+ containerCssVars
233
+ } = useVirtualScroll({
234
+ items: datatableItems,
235
+ itemHeight: props.itemHeight || 40,
236
+ containerHeight: props.viewportHeight || 500,
237
+ buffer: props.buffer ?? 5,
238
+ virtualScroll: computed(() => !!props.virtualScroll),
239
+ onThresholdReach: () => {
240
+ const dp = props.dataProvider as any
241
+ if (typeof dp?.loadMore === 'function') {
242
+ dp.loadMore()
243
+ } else if (typeof dp?.nextPage === 'function' && dp.hasMore) {
244
+ dp.nextPage()
245
+ }
246
+ }
247
+ })
248
+
249
+ const displayRows = computed(() => {
250
+ if (props.virtualScroll) {
251
+ return visibleItems.value
252
+ }
253
+ return pageRows.value
254
+ })
255
+
256
+ const totalColspan = computed(() => {
257
+ const fieldsCount = (props.visibleFields || (props.dataProvider as any)?.fields || []).length
258
+ const checkCount = props.bulkActions && props.bulkActions.length > 0 ? 1 : 0
259
+ const actionCount = props.rowActions && props.rowActions.length > 0 ? 1 : 0
260
+ return fieldsCount + checkCount + actionCount
261
+ })
262
+
263
+ const focusedIndex = ref<number>(-1)
264
+ const theadStickyOffset = 40
265
+ const handleKeyDown = (e: KeyboardEvent) => {
266
+ if (!props.virtualScroll) return
267
+ const total = datatableItems.value.length
268
+ if (total === 0) return
269
+
270
+ if (e.key === 'ArrowDown') {
271
+ e.preventDefault()
272
+ focusedIndex.value = Math.min(total - 1, focusedIndex.value + 1)
273
+ scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
274
+ } else if (e.key === 'ArrowUp') {
275
+ e.preventDefault()
276
+ focusedIndex.value = Math.max(0, focusedIndex.value - 1)
277
+ scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
278
+ } else if (e.key === 'PageDown') {
279
+ e.preventDefault()
280
+ const step = Math.floor((props.viewportHeight || 500) / (props.itemHeight || 40))
281
+ focusedIndex.value = Math.min(total - 1, focusedIndex.value + step)
282
+ scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
283
+ } else if (e.key === 'PageUp') {
284
+ e.preventDefault()
285
+ const step = Math.floor((props.viewportHeight || 500) / (props.itemHeight || 40))
286
+ focusedIndex.value = Math.max(0, focusedIndex.value - step)
287
+ scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
288
+ } else if (e.key === 'Home') {
289
+ e.preventDefault()
290
+ focusedIndex.value = 0
291
+ scrollToIndex(0)
292
+ } else if (e.key === 'End') {
293
+ e.preventDefault()
294
+ focusedIndex.value = total - 1
295
+ scrollToIndex(total - 1, 'auto', theadStickyOffset)
296
+ }
297
+ }
139
298
  </script>
140
299
 
141
300
  <style lang="scss" scoped>
@@ -149,15 +308,15 @@ const isLoading = computed(() => {
149
308
  table {
150
309
  width: 100%;
151
310
  border-collapse: collapse;
152
- border: 1px solid var(--table-border-color);
311
+ border: 1px solid var(--table-border-color, #e2e8f0);
153
312
  thead {
154
313
  tr {
155
- background-color: var(--table-header-bg);
314
+ background-color: var(--table-header-bg, #f8fafc);
156
315
  height: var(--page-height);
157
316
  th {
158
- color: var(--table-header-color);
159
- border-bottom: 1px solid var(--table-border-color);
160
- border-left: 1px solid var(--table-border-color);
317
+ color: var(--table-header-color, #334155);
318
+ border-bottom: 1px solid var(--table-border-color, #e2e8f0);
319
+ border-left: 1px solid var(--table-border-color, #e2e8f0);
161
320
  padding: 5px;
162
321
  &:first-child {
163
322
  border-left: none;
@@ -167,19 +326,23 @@ const isLoading = computed(() => {
167
326
  }
168
327
  tbody {
169
328
  tr {
170
- height: 40px;
171
- background-color: var(--table-row-bg);
172
- color: var(--table-row-text-color);
173
- &:nth-child(2n + 1) {
174
- background-color: var(--table-row-alt-bg);
329
+ height: var(--virtual-item-height, 40px);
330
+ background-color: var(--table-row-bg, #ffffff);
331
+ color: var(--table-row-text-color, #1e293b);
332
+ &.alt-row {
333
+ background-color: var(--table-row-alt-bg, #f8fafc);
175
334
  }
176
335
  &:hover {
177
- background-color: var(--table-row-hover-bg);
336
+ background-color: var(--table-row-hover-bg, #f1f5f9);
337
+ }
338
+ &.active-focus {
339
+ outline: 2px solid var(--color-primary, #3b82f6);
340
+ outline-offset: -2px;
178
341
  }
179
342
  td {
180
343
  padding: 5px;
181
- border-bottom: 1px solid var(--table-border-color);
182
- border-left: 1px solid var(--table-border-color);
344
+ border-bottom: 1px solid var(--table-border-color, #e2e8f0);
345
+ border-left: 1px solid var(--table-border-color, #e2e8f0);
183
346
  &:first-child {
184
347
  border-left: none;
185
348
  }
@@ -187,7 +350,7 @@ const isLoading = computed(() => {
187
350
  td.empty-state {
188
351
  text-align: center;
189
352
  padding: 20px;
190
- color: var(--font-color-secondary);
353
+ color: var(--font-color-secondary, #64748b);
191
354
  }
192
355
  }
193
356
  }
@@ -217,5 +380,38 @@ const isLoading = computed(() => {
217
380
  flex: 1;
218
381
  }
219
382
  }
383
+
384
+ &.is-virtual-scroll {
385
+ .datatable-container {
386
+ overflow-y: auto;
387
+ max-height: var(--k-datatable-viewport-height, 500px);
388
+ min-height: 0;
389
+ position: relative;
390
+ outline: none;
391
+ }
392
+ table thead {
393
+ position: sticky;
394
+ top: 0;
395
+ z-index: 2;
396
+ background-color: var(--table-header-bg, #f8fafc);
397
+ tr {
398
+ background-color: var(--table-header-bg, #f8fafc);
399
+ }
400
+ }
401
+ tr.k-virtual-spacer {
402
+ height: var(--spacer-height, 0px);
403
+ border: none;
404
+ padding: 0;
405
+ margin: 0;
406
+ background: transparent !important;
407
+ td {
408
+ height: var(--spacer-height, 0px);
409
+ border: none;
410
+ padding: 0;
411
+ margin: 0;
412
+ background: transparent !important;
413
+ }
414
+ }
415
+ }
220
416
  }
221
417
  </style>
@@ -15,6 +15,10 @@ type __VLS_Props = {
15
15
  columnWidths?: Record<string, string>;
16
16
  emptyStateText?: string;
17
17
  emptyFilterStateText?: string;
18
+ virtualScroll?: boolean;
19
+ itemHeight?: number;
20
+ viewportHeight?: number;
21
+ buffer?: number;
18
22
  };
19
23
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
20
24
  "update:currentPage": (value: number) => any;
@@ -26,6 +30,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
26
30
  "onUpdate:pageSize"?: ((value: number) => any) | undefined;
27
31
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
28
32
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
29
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
33
+ }>, {
34
+ virtualScroll: boolean;
35
+ itemHeight: number;
36
+ buffer: number;
37
+ viewportHeight: number;
38
+ emptyStateText: string;
39
+ emptyFilterStateText: string;
40
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
30
41
  declare const _default: typeof __VLS_export;
31
42
  export default _default;
@@ -14,14 +14,16 @@ type __VLS_Props = {
14
14
  dateSelected: (date: Date) => void;
15
15
  teleportTo?: string;
16
16
  placeholder?: string;
17
- validation?: 'success' | 'warning' | 'error' | null;
17
+ validation?: 'success' | 'warning' | null | 'error';
18
18
  validationText?: string;
19
19
  align?: 'left' | 'right';
20
20
  };
21
21
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
22
+ blur: (event: FocusEvent) => any;
22
23
  "update:maskedModel": (value: string) => any;
23
24
  "update:calendarShow": (value: boolean) => any;
24
25
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
26
+ onBlur?: ((event: FocusEvent) => any) | undefined;
25
27
  "onUpdate:maskedModel"?: ((value: string) => any) | undefined;
26
28
  "onUpdate:calendarShow"?: ((value: boolean) => any) | undefined;
27
29
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;