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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (120) hide show
  1. package/bin/create-preset.mjs +5 -4
  2. package/dist/compiled/composables/useKatluxContext.mjs +6 -3
  3. package/dist/compiled/composables/useKatluxForm.mjs +268 -0
  4. package/dist/compiled/composables/useToast.mjs +164 -0
  5. package/dist/compiled/composables/useVirtualScroll.mjs +176 -0
  6. package/dist/module.cjs +1 -0
  7. package/dist/module.json +1 -1
  8. package/dist/module.mjs +1 -0
  9. package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
  10. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
  11. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
  12. package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +9 -0
  13. package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +9 -0
  14. package/dist/runtime/components/KCombobox/KCombobox.global.vue +2 -1
  15. package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +9 -0
  16. package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +5 -0
  17. package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
  18. package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
  19. package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
  20. package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
  21. package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
  22. package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
  23. package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
  24. package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
  25. package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
  26. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
  27. package/dist/runtime/components/KDatatable/KDatatable.logic.js +11 -3
  28. package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +2 -0
  29. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +5 -1
  30. package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +2 -0
  31. package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
  32. package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
  33. package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
  34. package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
  35. package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
  36. package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
  37. package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
  38. package/dist/runtime/components/KGantt/KGantt.logic.js +11 -4
  39. package/dist/runtime/components/KPagination/KPagination.logic.js +7 -4
  40. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
  41. package/dist/runtime/components/KToast/KToast.global.vue +12 -2
  42. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
  43. package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
  44. package/dist/runtime/components/KToast/KToast.logic.js +45 -5
  45. package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
  46. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
  47. package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
  48. package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
  49. package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
  50. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +38 -0
  51. package/dist/runtime/components/KTree/KTree.global.vue +7 -3
  52. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +38 -0
  53. package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
  54. package/dist/runtime/components/KTree/KTree.logic.js +17 -0
  55. package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +52 -1
  56. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
  57. package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +52 -1
  58. package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
  59. package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
  60. package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +36 -0
  61. package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
  62. package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +36 -0
  63. package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
  64. package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
  65. package/dist/runtime/composables/useKatluxContext.js +6 -3
  66. package/dist/runtime/composables/useKatluxForm.d.ts +143 -0
  67. package/dist/runtime/composables/useKatluxForm.js +268 -0
  68. package/dist/runtime/composables/useToast.d.ts +49 -0
  69. package/dist/runtime/composables/useToast.js +164 -0
  70. package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
  71. package/dist/runtime/composables/useVirtualScroll.js +176 -0
  72. package/dist/runtime/plugins/PresetPlugin.js +9 -1
  73. package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
  74. package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
  75. package/dist/runtime/plugins/toastPlugin.client.js +16 -0
  76. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
  77. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +36 -7
  78. package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +1 -0
  79. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +10 -4
  80. package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +1 -0
  81. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
  82. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
  83. package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
  84. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +10 -1
  85. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +128 -6
  86. package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +10 -1
  87. package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
  88. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +206 -27
  89. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
  90. package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
  91. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
  92. package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
  93. package/dist/runtime/presets/default/components/KLayout/KLayout.vue +4 -2
  94. package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
  95. package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
  96. package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
  97. package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
  98. package/dist/runtime/presets/default/components/KToast/KToast.vue +22 -4
  99. package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
  100. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
  101. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +207 -0
  102. package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
  103. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -5
  104. package/dist/runtime/presets/default/components/KTree/KTree.vue +232 -13
  105. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -5
  106. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
  107. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
  108. package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
  109. package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
  110. package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
  111. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
  112. package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
  113. package/dist/runtime/server/middleware/session.js +1 -1
  114. package/package.json +3 -4
  115. package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
  116. package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
  117. package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
  118. package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
  119. package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
  120. package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
@@ -0,0 +1,176 @@
1
+ import { ref, computed, unref, watch, getCurrentScope, onScopeDispose } from "vue";
2
+ export function useVirtualScroll(options) {
3
+ const containerRef = ref(null);
4
+ const scrollTop = ref(0);
5
+ const resolveItems = () => {
6
+ if (typeof options.items === "function") {
7
+ return options.items();
8
+ }
9
+ return unref(options.items) || [];
10
+ };
11
+ const allItems = computed(() => resolveItems());
12
+ const totalCount = computed(() => allItems.value.length);
13
+ const isVirtual = computed(() => {
14
+ if (options.virtualScroll === void 0) return false;
15
+ return unref(options.virtualScroll) === true;
16
+ });
17
+ const colCount = computed(() => {
18
+ const c = unref(options.columns);
19
+ return typeof c === "number" && c > 1 ? c : 1;
20
+ });
21
+ const buf = computed(() => {
22
+ const b = unref(options.buffer);
23
+ return typeof b === "number" ? b : 5;
24
+ });
25
+ const defaultHeight = 40;
26
+ const getItemHeight = (item, index) => {
27
+ if (typeof options.itemHeight === "function") {
28
+ return options.itemHeight(item, index);
29
+ }
30
+ const h = unref(options.itemHeight);
31
+ return typeof h === "number" && h > 0 ? h : defaultHeight;
32
+ };
33
+ const baseItemHeight = computed(() => {
34
+ const h = unref(options.itemHeight);
35
+ if (typeof h === "number" && h > 0) return h;
36
+ return defaultHeight;
37
+ });
38
+ const resolveContainerHeight = () => {
39
+ if (typeof options.containerHeight === "function") {
40
+ return options.containerHeight() || 400;
41
+ }
42
+ const val = unref(options.containerHeight);
43
+ return typeof val === "number" && val > 0 ? val : 400;
44
+ };
45
+ const viewportHeight = ref(resolveContainerHeight());
46
+ watch(
47
+ () => resolveContainerHeight(),
48
+ (newH) => {
49
+ if (typeof newH === "number" && newH > 0) {
50
+ viewportHeight.value = newH;
51
+ }
52
+ }
53
+ );
54
+ watch(containerRef, (el, oldEl) => {
55
+ if (typeof window === "undefined" || typeof ResizeObserver === "undefined") return;
56
+ if (oldEl && oldEl.__vsObserver) {
57
+ oldEl.__vsObserver.disconnect();
58
+ delete oldEl.__vsObserver;
59
+ }
60
+ if (el) {
61
+ const ro = new ResizeObserver((entries) => {
62
+ for (const entry of entries) {
63
+ const h = Math.round(entry.contentRect.height || el.clientHeight);
64
+ if (h > 0 && h !== viewportHeight.value) {
65
+ viewportHeight.value = h;
66
+ }
67
+ }
68
+ });
69
+ ro.observe(el);
70
+ el.__vsObserver = ro;
71
+ }
72
+ });
73
+ if (getCurrentScope()) {
74
+ onScopeDispose(() => {
75
+ if (containerRef.value && containerRef.value.__vsObserver) {
76
+ containerRef.value.__vsObserver.disconnect();
77
+ delete containerRef.value.__vsObserver;
78
+ }
79
+ });
80
+ }
81
+ const totalRows = computed(() => {
82
+ if (colCount.value <= 1) return totalCount.value;
83
+ return Math.ceil(totalCount.value / colCount.value);
84
+ });
85
+ const startRowIndex = computed(() => {
86
+ if (!isVirtual.value) return 0;
87
+ const rawRow = Math.floor(scrollTop.value / baseItemHeight.value);
88
+ return Math.max(0, rawRow - buf.value);
89
+ });
90
+ const visibleRowsCount = computed(() => {
91
+ if (!isVirtual.value) return totalRows.value;
92
+ const rowsInView = Math.ceil(viewportHeight.value / baseItemHeight.value);
93
+ return rowsInView + 2 * buf.value + 1;
94
+ });
95
+ const endRowIndex = computed(() => {
96
+ if (!isVirtual.value) return totalRows.value;
97
+ return Math.min(totalRows.value, startRowIndex.value + visibleRowsCount.value);
98
+ });
99
+ const startIndex = computed(() => {
100
+ if (!isVirtual.value) return 0;
101
+ return Math.max(0, startRowIndex.value * colCount.value);
102
+ });
103
+ const endIndex = computed(() => {
104
+ if (!isVirtual.value) return totalCount.value;
105
+ return Math.min(totalCount.value, endRowIndex.value * colCount.value);
106
+ });
107
+ const visibleItems = computed(() => {
108
+ if (!isVirtual.value) return allItems.value;
109
+ return allItems.value.slice(startIndex.value, endIndex.value);
110
+ });
111
+ const topSpacerHeight = computed(() => {
112
+ if (!isVirtual.value) return 0;
113
+ return Math.max(0, startRowIndex.value * baseItemHeight.value);
114
+ });
115
+ const bottomSpacerHeight = computed(() => {
116
+ if (!isVirtual.value) return 0;
117
+ const remainingRows = Math.max(0, totalRows.value - endRowIndex.value);
118
+ return remainingRows * baseItemHeight.value;
119
+ });
120
+ const totalHeight = computed(() => {
121
+ return totalRows.value * baseItemHeight.value;
122
+ });
123
+ watch(totalHeight, (newTotal) => {
124
+ if (scrollTop.value > newTotal) {
125
+ scrollTop.value = Math.max(0, newTotal - viewportHeight.value);
126
+ if (containerRef.value) {
127
+ containerRef.value.scrollTop = scrollTop.value;
128
+ }
129
+ }
130
+ });
131
+ const containerCssVars = computed(() => ({
132
+ "--virtual-spacer-top": `${topSpacerHeight.value}px`,
133
+ "--virtual-spacer-bottom": `${bottomSpacerHeight.value}px`,
134
+ "--virtual-total-height": `${totalHeight.value}px`,
135
+ "--virtual-item-height": `${baseItemHeight.value}px`,
136
+ "--virtual-container-height": `${viewportHeight.value}px`
137
+ }));
138
+ const scrollThreshold = options.scrollThreshold ?? 100;
139
+ const onScroll = (e) => {
140
+ const target = e.target;
141
+ if (!target) return;
142
+ scrollTop.value = target.scrollTop;
143
+ if (target.clientHeight && target.clientHeight !== viewportHeight.value) {
144
+ viewportHeight.value = target.clientHeight;
145
+ }
146
+ const distanceToBottom = target.scrollHeight - (target.scrollTop + target.clientHeight);
147
+ if (distanceToBottom <= scrollThreshold && typeof options.onThresholdReach === "function") {
148
+ options.onThresholdReach();
149
+ }
150
+ };
151
+ const scrollToIndex = (index, behavior = "auto") => {
152
+ const targetRow = colCount.value <= 1 ? index : Math.floor(index / colCount.value);
153
+ const targetScrollTop = targetRow * baseItemHeight.value;
154
+ scrollTop.value = targetScrollTop;
155
+ if (containerRef.value) {
156
+ containerRef.value.scrollTo({
157
+ top: targetScrollTop,
158
+ behavior
159
+ });
160
+ }
161
+ };
162
+ return {
163
+ startIndex,
164
+ endIndex,
165
+ visibleItems,
166
+ topSpacerHeight,
167
+ bottomSpacerHeight,
168
+ totalHeight,
169
+ scrollTop,
170
+ viewportHeight,
171
+ containerRef,
172
+ onScroll,
173
+ scrollToIndex,
174
+ containerCssVars
175
+ };
176
+ }
@@ -8,7 +8,15 @@ export default defineNuxtPlugin((nuxtApp) => {
8
8
  if (appConfig?.katluxToolkit && activePresetState.value) {
9
9
  appConfig.katluxToolkit.activePreset = activePresetState.value;
10
10
  }
11
- const resolvePresetString = (val) => Array.isArray(val) ? val[0] ?? "default" : val;
11
+ const resolvePresetString = (val) => {
12
+ const list = Array.isArray(val) ? val : val ? [val] : [];
13
+ const set = /* @__PURE__ */ new Set();
14
+ set.add("default");
15
+ for (const item of list) {
16
+ if (item) set.add(item);
17
+ }
18
+ return Array.from(set).join(" ");
19
+ };
12
20
  const currentPreset = ref(resolvePresetString(activePresetState.value));
13
21
  useHead({
14
22
  htmlAttrs: {
@@ -4,7 +4,6 @@ import { NuxtHydrationAdapter } from "../hydration/NuxtHydrationAdapter.js";
4
4
  export default defineNuxtPlugin((nuxtApp) => {
5
5
  setHydrationAdapter(new NuxtHydrationAdapter());
6
6
  const _global = globalThis;
7
- _global.__KATLUX_APP__ = nuxtApp;
8
7
  _global.useNuxtApp = useNuxtApp;
9
8
  _global.useAsyncData = useAsyncData;
10
9
  _global.useNuxtData = useNuxtData;
@@ -0,0 +1,2 @@
1
+ declare const _default: import("#app").Plugin<Record<string, unknown>> & import("#app").ObjectPlugin<Record<string, unknown>>;
2
+ export default _default;
@@ -0,0 +1,16 @@
1
+ import { defineNuxtPlugin, onNuxtReady } from "#app";
2
+ import { createVNode, render } from "vue";
3
+ import KToastContainer from "../components/KToastContainer/KToastContainer.global.vue";
4
+ export default defineNuxtPlugin((nuxtApp) => {
5
+ if (typeof document === "undefined") return;
6
+ onNuxtReady(() => {
7
+ if (!document.getElementById("katlux-toast-portal")) {
8
+ const portal = document.createElement("div");
9
+ portal.id = "katlux-toast-portal";
10
+ document.body.appendChild(portal);
11
+ const vnode = createVNode(KToastContainer);
12
+ vnode.appContext = nuxtApp.vueApp._context;
13
+ render(vnode, portal);
14
+ }
15
+ });
16
+ });
@@ -13,6 +13,7 @@
13
13
  size="small"
14
14
  :type="action.type || 'default'"
15
15
  :iconOnly="action.iconOnly || !!action.icon"
16
+ :aria-label="action.label"
16
17
  :disabled="props.selectedRows.length === 0"
17
18
  )
18
19
  template(#icon v-if="action.icon")
@@ -7,7 +7,7 @@
7
7
  tabindex="0"
8
8
  @keydown.space.prevent="handleSpaceKey"
9
9
  )
10
- input(type="checkbox" v-model="internalModel" :value="checkboxValue" :disabled="isDisabled" tabindex="-1")
10
+ input(type="checkbox" :checked="isChecked" :disabled="isDisabled" tabindex="-1" @change="toggleCheckbox")
11
11
  .icon-container(:class="validation ? `is-${validation}` : ''")
12
12
  KIcon.icon(iconname="check")
13
13
  span
@@ -39,27 +39,56 @@ const internalModel = computed({
39
39
  set: (value) => emit('update:model', value)
40
40
  })
41
41
 
42
+ const getId = (item: any) => {
43
+ if (item && typeof item === 'object') {
44
+ return item.id ?? item._id ?? item
45
+ }
46
+ return item
47
+ }
48
+
49
+ const findItemIndex = (arr: any[], target: any): number => {
50
+ const targetId = getId(target)
51
+ return arr.findIndex(item => {
52
+ if (item === target) return true
53
+ if (targetId !== undefined && targetId !== null) {
54
+ const itemId = getId(item)
55
+ if (itemId !== undefined && itemId !== null && itemId === targetId) {
56
+ return true
57
+ }
58
+ }
59
+ return false
60
+ })
61
+ }
62
+
42
63
  // Correctly compute checked state for both boolean and array models
43
64
  const isChecked = computed(() => {
44
65
  if (Array.isArray(internalModel.value)) {
45
- return internalModel.value.includes(props.checkboxValue)
66
+ return findItemIndex(internalModel.value, props.checkboxValue) !== -1
46
67
  }
47
68
  return !!internalModel.value
48
69
  })
49
70
 
50
- // Handle Space key correctly for both boolean and array models
51
- function handleSpaceKey() {
71
+ function toggleCheckbox() {
72
+ if (props.isDisabled) return
52
73
  if (Array.isArray(internalModel.value)) {
53
74
  const val = props.checkboxValue
54
75
  const arr = [...internalModel.value]
55
- const idx = arr.indexOf(val)
56
- if (idx === -1) arr.push(val)
57
- else arr.splice(idx, 1)
76
+ const idx = findItemIndex(arr, val)
77
+ if (idx === -1) {
78
+ arr.push(val)
79
+ } else {
80
+ arr.splice(idx, 1)
81
+ }
58
82
  internalModel.value = arr
59
83
  } else {
60
84
  internalModel.value = !internalModel.value
61
85
  }
62
86
  }
87
+
88
+ // Handle Space key correctly for both boolean and array models
89
+ function handleSpaceKey() {
90
+ toggleCheckbox()
91
+ }
63
92
  </script>
64
93
 
65
94
  <style lang="scss" scoped>
@@ -29,6 +29,7 @@ type __VLS_Props = {
29
29
  setHighlightedIndex?: (idx: number) => void;
30
30
  validation?: 'success' | 'warning' | 'error' | null;
31
31
  validationText?: string;
32
+ maxHeight?: number;
32
33
  };
33
34
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
34
35
  "update:isOptionsOpen": (value: boolean) => any;
@@ -1,14 +1,16 @@
1
1
  <template lang="pug">
2
2
  .KCombobox-wrapper
3
- label.k-input-label(v-if="label") {{ label }}
3
+ label.k-input-label(v-if="label" :for="comboboxId") {{ label }}
4
4
  .KCombobox(ref="activatorRef" :class="{ disabled: disabled, open: isOptionsOpen, ... (validation ? { [`is-${validation}`]: true } : {}) }")
5
5
  KGrid(
6
+ :id="comboboxId"
6
7
  @click.stop="toggleDropdown"
7
8
  @keydown="onKeyDown"
8
9
  role="combobox"
9
10
  :aria-expanded="isOptionsOpen"
10
11
  aria-haspopup="listbox"
11
- :aria-activedescendant="highlightedIndex !== undefined && highlightedIndex >= 0 ? `k-combobox-opt-${highlightedIndex}` : undefined"
12
+ :aria-controls="listboxId"
13
+ :aria-activedescendant="highlightedIndex !== undefined && highlightedIndex >= 0 ? `${listboxId}-opt-${highlightedIndex}` : undefined"
12
14
  :aria-disabled="disabled"
13
15
  :tabindex="disabled ? -1 : 0"
14
16
  align="center"
@@ -22,11 +24,12 @@
22
24
  ) {{ item[labelField] }}
23
25
  .KCombobox__selected-content-placeholder(v-else) {{placeholder}}
24
26
  KIcon(iconname="chevron" width="20" height="20").chevron
25
- KDropdown(v-model:isOpen="isOptionsOpenModel" :anchorEl="activatorRef" :fullWidth="fullWidth" :teleportTo="teleportTo").KCombobox__options
27
+ KDropdown(v-model:isOpen="isOptionsOpenModel" :anchorEl="activatorRef" :fullWidth="fullWidth" :teleportTo="teleportTo" :maxHeight="maxHeight").KCombobox__options
26
28
  template(v-if="slots.default")
27
29
  slot(name="default")
28
30
  KComboboxList(
29
31
  v-else
32
+ :listboxId="listboxId"
30
33
  :searchbox="searchbox"
31
34
  :searchPlaceholder="searchPlaceholder"
32
35
  v-model:searchtext="searchtextModel"
@@ -50,9 +53,11 @@
50
53
  </template>
51
54
 
52
55
  <script lang="ts" setup>
53
- import { computed, ref, useSlots, watch } from 'vue'
56
+ import { computed, ref, useSlots, watch, useId } from 'vue'
54
57
  const activatorRef = ref<HTMLElement | null>(null)
55
58
  const slots = useSlots()
59
+ const comboboxId = useId()
60
+ const listboxId = `${comboboxId}-listbox`
56
61
  import KComboboxList from './KComboboxList.vue'
57
62
  import type { ComboboxItem } from '#toolkit/components/KCombobox/KCombobox.logic'
58
63
 
@@ -86,6 +91,7 @@ const props = withDefaults(defineProps<{
86
91
  setHighlightedIndex?: (idx: number) => void
87
92
  validation?: 'success' | 'warning' | 'error' | null
88
93
  validationText?: string
94
+ maxHeight?: number
89
95
  }>(), {
90
96
  virtualScroll: true,
91
97
  itemHeight: 40,
@@ -29,6 +29,7 @@ type __VLS_Props = {
29
29
  setHighlightedIndex?: (idx: number) => void;
30
30
  validation?: 'success' | 'warning' | 'error' | null;
31
31
  validationText?: string;
32
+ maxHeight?: number;
32
33
  };
33
34
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
34
35
  "update:isOptionsOpen": (value: boolean) => any;
@@ -1,5 +1,6 @@
1
1
  import type { ComboboxItem } from '#toolkit/components/KCombobox/KCombobox.logic';
2
2
  type __VLS_Props = {
3
+ listboxId?: string;
3
4
  searchbox: boolean;
4
5
  searchtext: string;
5
6
  searchPlaceholder: string;
@@ -9,6 +9,7 @@
9
9
  v-else
10
10
  ref="listRef"
11
11
  role="listbox"
12
+ :id="effectiveListboxId"
12
13
  :style="{ '--top-spacer': `${topSpacerHeight}px`, '--bottom-spacer': `${bottomSpacerHeight}px`, '--k-combobox-item-height': `${itemH}px` }"
13
14
  @scroll.passive="onScroll"
14
15
  )
@@ -16,7 +17,7 @@
16
17
  li.KCombobox__options-list-item(
17
18
  v-for="(option, index) in visibleOptions"
18
19
  :key="getItemKey(option, startIndex + index)"
19
- :id="'k-combobox-opt-' + (startIndex + index)"
20
+ :id="`${effectiveListboxId}-opt-${startIndex + index}`"
20
21
  role="option"
21
22
  :aria-selected="isSelected(option) ? 'true' : 'false'"
22
23
  :class="{ 'is-highlighted': (startIndex + index) === highlightedIndex }"
@@ -32,13 +33,14 @@
32
33
  </template>
33
34
 
34
35
  <script lang="ts" setup>
35
- import { computed, ref, onMounted, onBeforeUnmount, watch } from 'vue'
36
+ import { computed, ref, onMounted, onBeforeUnmount, watch, useId } from 'vue'
36
37
  import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
37
38
  import type { ComboboxItem } from '#toolkit/components/KCombobox/KCombobox.logic'
38
39
 
39
40
  const { t } = useKatluxI18n()
40
41
 
41
42
  const props = withDefaults(defineProps<{
43
+ listboxId?: string
42
44
  searchbox: boolean
43
45
  searchtext: string
44
46
  searchPlaceholder: string
@@ -70,6 +72,9 @@ const emit = defineEmits<{
70
72
  (e: 'update:searchtext', value: string): void
71
73
  }>()
72
74
 
75
+ const generatedListboxId = useId()
76
+ const effectiveListboxId = computed(() => props.listboxId || generatedListboxId)
77
+
73
78
  const searchtextModel = computed({
74
79
  get: () => props.searchtext,
75
80
  set: (value) => emit('update:searchtext', value)
@@ -1,5 +1,6 @@
1
1
  import type { ComboboxItem } from '#toolkit/components/KCombobox/KCombobox.logic';
2
2
  type __VLS_Props = {
3
+ listboxId?: string;
3
4
  searchbox: boolean;
4
5
  searchtext: string;
5
6
  searchPlaceholder: string;
@@ -12,6 +12,10 @@ 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;
15
19
  };
16
20
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
17
21
  "update:selectedRows": (value: any[]) => any;
@@ -19,6 +23,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
19
23
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
20
24
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
21
25
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
22
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
26
+ }>, {
27
+ virtualScroll: boolean;
28
+ itemHeight: number;
29
+ buffer: number;
30
+ viewportHeight: number;
31
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
23
32
  declare const _default: typeof __VLS_export;
24
33
  export default _default;
@@ -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,16 @@ 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
+ }>(), {
75
+ virtualScroll: false,
76
+ itemHeight: 60,
77
+ viewportHeight: 500,
78
+ buffer: 5
79
+ })
43
80
 
44
81
  const emit = defineEmits<{
45
82
  (e: 'update:selectedRows', value: any[]): void
@@ -59,8 +96,65 @@ const selectAll = computed({
59
96
  const { pageData, loading: dpLoading, initialLoad: dpInitialLoad } = useDataProvider(props.dataProvider)
60
97
  const pageRows = computed(() => pageData.value || [])
61
98
 
99
+ // Virtual scroll data source
100
+ const iteratorItems = computed(() => {
101
+ const currentRows = pageRows.value
102
+ const dp = props.dataProvider as any
103
+ if (props.virtualScroll) {
104
+ if (Array.isArray(dp?.allData?.value)) return dp.allData.value
105
+ if (Array.isArray(dp?.allData)) return dp.allData
106
+ if (Array.isArray(dp?.data)) return dp.data
107
+ }
108
+ return currentRows
109
+ })
110
+
111
+ const {
112
+ visibleItems,
113
+ startIndex,
114
+ endIndex,
115
+ topSpacerHeight,
116
+ bottomSpacerHeight,
117
+ containerRef,
118
+ onScroll,
119
+ scrollToIndex,
120
+ containerCssVars
121
+ } = useVirtualScroll({
122
+ items: iteratorItems,
123
+ itemHeight: props.itemHeight || 60,
124
+ containerHeight: props.viewportHeight || 500,
125
+ buffer: props.buffer ?? 5,
126
+ virtualScroll: computed(() => !!props.virtualScroll),
127
+ onThresholdReach: () => {
128
+ const dp = props.dataProvider as any
129
+ if (typeof dp?.loadMore === 'function') {
130
+ dp.loadMore()
131
+ } else if (typeof dp?.nextPage === 'function' && dp.hasMore) {
132
+ dp.nextPage()
133
+ }
134
+ }
135
+ })
136
+
137
+ const displayRows = computed(() => {
138
+ if (props.virtualScroll) {
139
+ return visibleItems.value
140
+ }
141
+ return pageRows.value
142
+ })
143
+
144
+ const onKeyDownDown = () => {
145
+ if (containerRef.value) {
146
+ containerRef.value.scrollTop += (props.itemHeight || 60)
147
+ }
148
+ }
149
+
150
+ const onKeyDownUp = () => {
151
+ if (containerRef.value) {
152
+ containerRef.value.scrollTop = Math.max(0, containerRef.value.scrollTop - (props.itemHeight || 60))
153
+ }
154
+ }
155
+
62
156
  const isLoading = computed(() => props.loading || dpLoading.value || dpInitialLoad.value || false)
63
- const hasData = computed(() => pageRows.value.length > 0)
157
+ const hasData = computed(() => (props.virtualScroll ? iteratorItems.value.length > 0 : pageRows.value.length > 0))
64
158
  const showNoRecord = computed(() => !isLoading.value && !hasData.value)
65
159
 
66
160
  const getRowKey = (row: any, index: number): string | number => {
@@ -82,11 +176,39 @@ const getRowKey = (row: any, index: number): string | number => {
82
176
  .k-data-iterator {
83
177
  position: relative;
84
178
  width: 100%;
179
+
85
180
  .no-record {
86
181
  display: block;
87
182
  padding: 1rem;
88
183
  text-align: center;
89
184
  color: var(--font-color-secondary, #6b7280);
90
185
  }
186
+
187
+ .k-data-iterator-virtual-container {
188
+ overflow-y: auto;
189
+ max-height: var(--virtual-container-height, 500px);
190
+ position: relative;
191
+ display: flex;
192
+ flex-direction: column;
193
+ gap: 10px;
194
+
195
+ &:focus-visible {
196
+ outline: 2px solid var(--primary-color, #3b82f6);
197
+ outline-offset: -2px;
198
+ }
199
+
200
+ .k-virtual-spacer {
201
+ width: 100%;
202
+ flex-shrink: 0;
203
+
204
+ &.is-top {
205
+ height: var(--virtual-spacer-top, 0px);
206
+ }
207
+
208
+ &.is-bottom {
209
+ height: var(--virtual-spacer-bottom, 0px);
210
+ }
211
+ }
212
+ }
91
213
  }
92
214
  </style>
@@ -12,6 +12,10 @@ 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;
15
19
  };
16
20
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
17
21
  "update:selectedRows": (value: any[]) => any;
@@ -19,6 +23,11 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
19
23
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
20
24
  "onUpdate:selectedRows"?: ((value: any[]) => any) | undefined;
21
25
  "onUpdate:selectAll"?: ((value: boolean) => any) | undefined;
22
- }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
26
+ }>, {
27
+ virtualScroll: boolean;
28
+ itemHeight: number;
29
+ buffer: number;
30
+ viewportHeight: number;
31
+ }, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
23
32
  declare const _default: typeof __VLS_export;
24
33
  export default _default;