@katlux/toolkit 0.1.1-alpha.122 → 0.1.1-alpha.124

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 (55) hide show
  1. package/bin/cli.mjs +0 -0
  2. package/bin/create-preset.d.ts +17 -0
  3. package/bin/create-preset.mjs +0 -0
  4. package/dist/compiled/composables/useDataProvider.mjs +6 -6
  5. package/dist/compiled/composables/useKatluxForm.mjs +23 -4
  6. package/dist/compiled/composables/usePresetComponent.mjs +1 -1
  7. package/dist/compiled/composables/useVirtualScroll.mjs +24 -11
  8. package/dist/compiled/utils/sanitize.mjs +39 -0
  9. package/dist/module.json +1 -1
  10. package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +2 -0
  11. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -1
  12. package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +2 -0
  13. package/dist/runtime/components/KBulkActions/KBulkActions.logic.d.ts +1 -0
  14. package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +1 -1
  15. package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +11 -0
  16. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue +4 -3
  17. package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +11 -0
  18. package/dist/runtime/components/KCheckbox/KCheckbox.logic.d.ts +5 -0
  19. package/dist/runtime/components/KCheckbox/KCheckbox.logic.js +4 -0
  20. package/dist/runtime/components/KCombobox/KCombobox.logic.js +3 -1
  21. package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +1 -1
  22. package/dist/runtime/components/KMaskTextbox/KMaskTextbox.logic.js +2 -0
  23. package/dist/runtime/components/KRadiobox/KRadiobox.global.vue +1 -1
  24. package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue +1 -1
  25. package/dist/runtime/components/KSlider/KSlider.global.vue +1 -1
  26. package/dist/runtime/components/KTextarea/KTextarea.global.vue +1 -1
  27. package/dist/runtime/components/KToast/KToast.global.d.vue.ts +1 -1
  28. package/dist/runtime/components/KToast/KToast.global.vue.d.ts +1 -1
  29. package/dist/runtime/components/KTree/KTree.global.d.vue.ts +1 -1
  30. package/dist/runtime/components/KTree/KTree.global.vue +2 -0
  31. package/dist/runtime/components/KTree/KTree.global.vue.d.ts +1 -1
  32. package/dist/runtime/components/KTree/KTree.logic.js +38 -12
  33. package/dist/runtime/composables/useDataProvider.d.ts +1 -1
  34. package/dist/runtime/composables/useDataProvider.js +6 -6
  35. package/dist/runtime/composables/useKatluxForm.js +23 -4
  36. package/dist/runtime/composables/usePresetComponent.js +1 -1
  37. package/dist/runtime/composables/useVirtualScroll.js +24 -11
  38. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.d.vue.ts +1 -0
  39. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +2 -1
  40. package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue.d.ts +1 -0
  41. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +9 -3
  42. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +35 -12
  43. package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +9 -3
  44. package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +111 -21
  45. package/dist/runtime/presets/default/components/KIcon/KIcon.vue +5 -2
  46. package/dist/runtime/presets/default/components/KRadiobox/KRadiobox.vue +1 -0
  47. package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +3 -3
  48. package/dist/runtime/presets/default/components/KTree/KTree.vue +245 -115
  49. package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +3 -3
  50. package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.d.vue.ts +27 -0
  51. package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue +179 -0
  52. package/dist/runtime/presets/default/components/KTree/KTreeNodeItem.vue.d.ts +27 -0
  53. package/dist/runtime/utils/sanitize.d.ts +5 -0
  54. package/dist/runtime/utils/sanitize.js +39 -0
  55. package/package.json +17 -4
@@ -70,33 +70,58 @@ export const KTreeDefaultProps = {
70
70
  export function useKTreeLogic(props, emit) {
71
71
  const { pageData, setFilter } = useDataProvider(props.dataProvider);
72
72
  const visibleRows = computed(() => pageData.value || []);
73
+ let isFirstSearchRun = true;
73
74
  watch(() => props.searchtext, (newVal) => {
74
- if (newVal) {
75
- setFilter({
76
- operator: EDataFilterOperator.In,
77
- field: { [props.labelField || "name"]: newVal },
78
- active: true
79
- });
75
+ const filterObj = newVal ? {
76
+ operator: EDataFilterOperator.In,
77
+ field: { [props.labelField || "name"]: newVal },
78
+ active: true
79
+ } : null;
80
+ if (typeof props.dataProvider?.setFilter === "function") {
81
+ props.dataProvider.setFilter(filterObj, true);
80
82
  } else {
81
- setFilter(null);
83
+ setFilter(filterObj, true);
82
84
  }
83
- if (newVal !== void 0) {
85
+ if (!isFirstSearchRun && newVal !== void 0) {
84
86
  emit?.("update:searchtext", newVal);
85
87
  }
86
- });
88
+ isFirstSearchRun = false;
89
+ }, { immediate: true });
90
+ const syncProviderExpanded = (nodes) => {
91
+ if (props.dataProvider) {
92
+ props.dataProvider.expandedNodes = nodes;
93
+ if ("_allVisibleRowsCache" in props.dataProvider) {
94
+ props.dataProvider._allVisibleRowsCache = null;
95
+ }
96
+ if (typeof props.dataProvider.updatePageData === "function") {
97
+ props.dataProvider.updatePageData();
98
+ }
99
+ if (typeof props.dataProvider.notify === "function") {
100
+ props.dataProvider.notify();
101
+ }
102
+ }
103
+ };
87
104
  const rawExpanded = props.dataProvider?.expandedNodes;
88
105
  const expandedNodes = ref(
89
106
  props.expandedNodes ? props.expandedNodes instanceof Set ? props.expandedNodes : new Set(props.expandedNodes) : rawExpanded ? "value" in rawExpanded ? rawExpanded.value : rawExpanded : /* @__PURE__ */ new Set()
90
107
  );
108
+ if (props.expandedNodes) {
109
+ syncProviderExpanded(expandedNodes.value);
110
+ }
91
111
  watch(() => props.expandedNodes, (val) => {
92
112
  if (val !== void 0) {
93
- expandedNodes.value = val instanceof Set ? val : new Set(val);
113
+ const setVal = val instanceof Set ? val : new Set(val);
114
+ expandedNodes.value = setVal;
115
+ syncProviderExpanded(setVal);
94
116
  }
95
117
  }, { deep: true });
96
118
  const toggleNode = (nodeId) => {
97
119
  if (props.disabled) return;
98
120
  if (typeof props.dataProvider?.toggleNode === "function") {
99
121
  props.dataProvider.toggleNode(nodeId);
122
+ const raw = props.dataProvider.expandedNodes;
123
+ const current = raw ? "value" in raw ? raw.value : raw : [];
124
+ expandedNodes.value = new Set(current);
100
125
  } else {
101
126
  if (expandedNodes.value.has(nodeId)) {
102
127
  expandedNodes.value.delete(nodeId);
@@ -104,11 +129,12 @@ export function useKTreeLogic(props, emit) {
104
129
  expandedNodes.value.add(nodeId);
105
130
  }
106
131
  }
132
+ const emitted = Array.isArray(props.expandedNodes) ? Array.from(expandedNodes.value) : expandedNodes.value;
107
133
  emit?.("node-toggle", nodeId);
108
- emit?.("update:expandedNodes", expandedNodes.value);
134
+ emit?.("update:expandedNodes", emitted);
109
135
  };
110
136
  const selectNode = (node) => {
111
- if (props.disabled || !props.selectable) return;
137
+ if (props.disabled) return;
112
138
  emit?.("update:modelValue", node);
113
139
  emit?.("update:selectedNode", node);
114
140
  emit?.("select", node);
@@ -24,7 +24,7 @@ export interface IUseDataProviderReturn<T = TDataRow> {
24
24
  selectAll: Ref<boolean>;
25
25
  setCurrentPage: (page: number) => void;
26
26
  setPageSize: (size: number) => void;
27
- setFilter: (filter: IDataFilter | null) => void;
27
+ setFilter: (filter: IDataFilter | null, immediate?: boolean) => void;
28
28
  setSortList: (sortList: IDataSort[]) => void;
29
29
  refresh: (hardRefresh?: boolean) => Promise<void>;
30
30
  loadPageData: (options?: {
@@ -19,10 +19,10 @@ export function useDataProvider(provider, options) {
19
19
  if (!activeProvider) return [];
20
20
  if (Array.isArray(activeProvider.allVisibleRows) && activeProvider.allVisibleRows.length > 0) return activeProvider.allVisibleRows;
21
21
  if (Array.isArray(activeProvider.allVisibleRows?.value) && activeProvider.allVisibleRows.value.length > 0) return activeProvider.allVisibleRows.value;
22
- if (Array.isArray(activeProvider.rowMap) && activeProvider.rowMap.length > 0) return activeProvider.rowMap;
23
- if (Array.isArray(activeProvider.rowMap?.value) && activeProvider.rowMap.value.length > 0) return activeProvider.rowMap.value;
24
- if (Array.isArray(activeProvider.allVisibleNodes) && activeProvider.allVisibleNodes.length > 0) return activeProvider.allVisibleNodes;
25
- if (Array.isArray(activeProvider.allVisibleNodes?.value) && activeProvider.allVisibleNodes.value.length > 0) return activeProvider.allVisibleNodes.value;
22
+ if (Array.isArray(activeProvider.rowMap)) return activeProvider.rowMap;
23
+ if (Array.isArray(activeProvider.rowMap?.value)) return activeProvider.rowMap.value;
24
+ if (Array.isArray(activeProvider.allVisibleNodes)) return activeProvider.allVisibleNodes;
25
+ if (Array.isArray(activeProvider.allVisibleNodes?.value)) return activeProvider.allVisibleNodes.value;
26
26
  if (Array.isArray(activeProvider.allData) && activeProvider.allData.length > 0) return activeProvider.allData;
27
27
  if (Array.isArray(activeProvider.allData?.value) && activeProvider.allData.value.length > 0) return activeProvider.allData.value;
28
28
  if (Array.isArray(activeProvider.data) && activeProvider.data.length > 0) return activeProvider.data;
@@ -164,10 +164,10 @@ export function useDataProvider(provider, options) {
164
164
  }
165
165
  pageSize.value = size;
166
166
  };
167
- const setFilter = (f) => {
167
+ const setFilter = (f, immediate = false) => {
168
168
  if (!activeProvider) return;
169
169
  if (typeof activeProvider.setFilter === "function") {
170
- activeProvider.setFilter(f);
170
+ activeProvider.setFilter(f, immediate);
171
171
  } else if ("filter" in activeProvider) {
172
172
  if (isRef(activeProvider.filter) || typeof activeProvider.filter === "object" && activeProvider.filter !== null && "value" in activeProvider.filter) {
173
173
  activeProvider.filter.value = f;
@@ -144,6 +144,7 @@ export function useKatluxForm(options = {}) {
144
144
  }
145
145
  }
146
146
  let validationSeq = 0;
147
+ let submitSeq = 0;
147
148
  function validate(targetPath) {
148
149
  const seq = ++validationSeq;
149
150
  const result = runValidation(values);
@@ -195,6 +196,8 @@ export function useKatluxForm(options = {}) {
195
196
  dirtyFields.value = {};
196
197
  submitCount.value = 0;
197
198
  isSubmitting.value = false;
199
+ submitSeq++;
200
+ validationSeq++;
198
201
  }
199
202
  function register(path, regOptions = {}) {
200
203
  return {
@@ -267,25 +270,41 @@ export function useKatluxForm(options = {}) {
267
270
  if (event && typeof event.preventDefault === "function") {
268
271
  event.preventDefault();
269
272
  }
273
+ const currentSubmitId = ++submitSeq;
270
274
  submitCount.value += 1;
271
275
  isSubmitting.value = true;
272
276
  try {
273
- const res = await runValidation(values);
277
+ const snapshotValues = deepClone(values);
278
+ const res = await runValidation(snapshotValues);
279
+ if (currentSubmitId !== submitSeq) {
280
+ return;
281
+ }
274
282
  const { valid, output, errors: newErrors } = res;
275
- errors.value = newErrors;
276
283
  if (!valid) {
284
+ const errorsToApply = {};
285
+ for (const [errPath, errMsg] of Object.entries(newErrors)) {
286
+ const currentVal = getByPath(values, errPath);
287
+ const snapVal = getByPath(snapshotValues, errPath);
288
+ if (JSON.stringify(currentVal) === JSON.stringify(snapVal)) {
289
+ errorsToApply[errPath] = errMsg;
290
+ }
291
+ }
292
+ errors.value = errorsToApply;
277
293
  const firstErrorKey = Object.keys(newErrors)[0];
278
294
  if (focusOnError && firstErrorKey) {
279
295
  focusFirstInvalid(firstErrorKey);
280
296
  }
281
297
  if (onInvalid) {
282
- await onInvalid(newErrors, values);
298
+ await onInvalid(newErrors, snapshotValues);
283
299
  }
284
300
  return;
285
301
  }
302
+ errors.value = {};
286
303
  await onValid(output, event);
287
304
  } finally {
288
- isSubmitting.value = false;
305
+ if (currentSubmitId === submitSeq) {
306
+ isSubmitting.value = false;
307
+ }
289
308
  }
290
309
  };
291
310
  }
@@ -48,7 +48,7 @@ export function usePresetComponent(componentBaseName, defaultComponent) {
48
48
  const externalLoaders = _loadersRegistry[presetName];
49
49
  if (externalLoaders) {
50
50
  const key = `./components/${componentBaseName}/${componentBaseName}.vue`;
51
- const candidate = externalLoaders[key];
51
+ const candidate = externalLoaders[key] || externalLoaders[componentBaseName] || externalLoaders[`${componentBaseName}.vue`];
52
52
  if (candidate) {
53
53
  if (isDirectComponent(candidate)) {
54
54
  return candidate;
@@ -179,9 +179,10 @@ export function useVirtualScroll(options) {
179
179
  const remainingRows = Math.max(0, totalRows.value - endRowIndex.value);
180
180
  return remainingRows * baseItemHeight.value;
181
181
  });
182
- watch(totalHeight, (newTotal) => {
183
- if (scrollTop.value > newTotal) {
184
- scrollTop.value = Math.max(0, newTotal - viewportHeight.value);
182
+ watch([totalHeight, viewportHeight], ([newTotal, newVp]) => {
183
+ const maxScroll = Math.max(0, newTotal - newVp);
184
+ if (scrollTop.value > maxScroll) {
185
+ scrollTop.value = maxScroll;
185
186
  if (containerRef.value) {
186
187
  containerRef.value.scrollTop = scrollTop.value;
187
188
  }
@@ -212,10 +213,16 @@ export function useVirtualScroll(options) {
212
213
  const targetScrollTop2 = Math.max(0, (rowOffsets.value[index] || 0) - offset);
213
214
  scrollTop.value = targetScrollTop2;
214
215
  if (containerRef.value) {
215
- containerRef.value.scrollTo({
216
- top: targetScrollTop2,
217
- behavior
218
- });
216
+ containerRef.value.scrollTop = targetScrollTop2;
217
+ if (typeof containerRef.value.scrollTo === "function") {
218
+ try {
219
+ containerRef.value.scrollTo({
220
+ top: targetScrollTop2,
221
+ behavior
222
+ });
223
+ } catch {
224
+ }
225
+ }
219
226
  }
220
227
  return;
221
228
  }
@@ -223,10 +230,16 @@ export function useVirtualScroll(options) {
223
230
  const targetScrollTop = Math.max(0, targetRow * baseItemHeight.value - offset);
224
231
  scrollTop.value = targetScrollTop;
225
232
  if (containerRef.value) {
226
- containerRef.value.scrollTo({
227
- top: targetScrollTop,
228
- behavior
229
- });
233
+ containerRef.value.scrollTop = targetScrollTop;
234
+ if (typeof containerRef.value.scrollTo === "function") {
235
+ try {
236
+ containerRef.value.scrollTo({
237
+ top: targetScrollTop,
238
+ behavior
239
+ });
240
+ } catch {
241
+ }
242
+ }
230
243
  }
231
244
  };
232
245
  return {
@@ -4,6 +4,7 @@ type __VLS_Props = {
4
4
  bulkActions: IKDatatableAction[];
5
5
  selectedRows: any[];
6
6
  selectAll: boolean;
7
+ filter?: any;
7
8
  selected: any;
8
9
  dp: CFlatClientDataProvider;
9
10
  doAction: (action: any) => void;
@@ -19,7 +19,7 @@
19
19
  template(#icon v-if="action.icon")
20
20
  KIcon(:iconname="action.icon" :width="16" :height="16")
21
21
  template(#default v-if="!action.iconOnly && !action.icon") {{action.label}}
22
- .info {{ props.selectAll ? t('All items selected') : t('Selected {count} items').replace('{count}', props.selectedRows.length.toString()) }}
22
+ .info {{ props.selectAll ? (props.filter?.active ? t('All filtered items selected') : t('All items selected')) : t('Selected {count} items').replace('{count}', props.selectedRows.length.toString()) }}
23
23
  </template>
24
24
 
25
25
  <script setup lang="ts">
@@ -34,6 +34,7 @@ const props = defineProps<{
34
34
  bulkActions: IKDatatableAction[]
35
35
  selectedRows: any[]
36
36
  selectAll: boolean
37
+ filter?: any
37
38
  selected: any
38
39
  dp: CFlatClientDataProvider
39
40
  doAction: (action: any) => void
@@ -4,6 +4,7 @@ type __VLS_Props = {
4
4
  bulkActions: IKDatatableAction[];
5
5
  selectedRows: any[];
6
6
  selectAll: boolean;
7
+ filter?: any;
7
8
  selected: any;
8
9
  dp: CFlatClientDataProvider;
9
10
  doAction: (action: any) => void;
@@ -1,18 +1,24 @@
1
1
  type __VLS_Props = {
2
- model: any;
3
- checkboxValue: any;
4
- isDisabled: boolean;
2
+ model?: any;
3
+ modelValue?: any;
4
+ checkboxValue?: any;
5
+ isDisabled?: boolean;
5
6
  label?: string;
6
7
  validation?: 'success' | 'warning' | 'error' | null;
7
8
  validationText?: string;
8
9
  idKey?: string;
10
+ indeterminate?: boolean;
9
11
  };
10
12
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
13
+ "update:modelValue": (value: any) => any;
11
14
  blur: (event: FocusEvent) => any;
12
15
  "update:model": (value: any) => any;
16
+ "update:indeterminate": (value: boolean) => any;
13
17
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
18
+ "onUpdate:modelValue"?: ((value: any) => any) | undefined;
14
19
  onBlur?: ((event: FocusEvent) => any) | undefined;
15
20
  "onUpdate:model"?: ((value: any) => any) | undefined;
21
+ "onUpdate:indeterminate"?: ((value: boolean) => any) | undefined;
16
22
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
23
  declare const _default: typeof __VLS_export;
18
24
  export default _default;
@@ -2,15 +2,15 @@
2
2
  .KCheckbox-wrapper
3
3
  label.KCheckbox(
4
4
  role="checkbox"
5
- :aria-checked="isChecked"
5
+ :aria-checked="props.indeterminate ? 'mixed' : isChecked"
6
6
  :aria-disabled="isDisabled"
7
7
  tabindex="0"
8
8
  @keydown.space.prevent="handleSpaceKey"
9
9
  @blur="emit('blur', $event)"
10
10
  )
11
- input(type="checkbox" :checked="isChecked" :disabled="isDisabled" tabindex="-1" @change="toggleCheckbox")
12
- .icon-container(:class="validation ? `is-${validation}` : ''")
13
- KIcon.icon(iconname="check")
11
+ input(ref="inputRef" type="checkbox" :checked="isChecked" :indeterminate.prop="props.indeterminate" :disabled="isDisabled" tabindex="-1" @change="toggleCheckbox")
12
+ .icon-container(:class="[validation ? `is-${validation}` : '', { 'is-indeterminate': props.indeterminate }]")
13
+ KIcon.icon(:iconname="props.indeterminate ? 'minus' : 'check'")
14
14
  span
15
15
  slot(name="label")
16
16
  slot
@@ -19,29 +19,43 @@
19
19
  </template>
20
20
 
21
21
  <script lang="ts" setup>
22
- import { computed } from 'vue'
22
+ import { ref, computed, watch } from 'vue'
23
23
 
24
24
  // Default template for KCheckbox
25
25
  const props = defineProps<{
26
- model: any
27
- checkboxValue: any
28
- isDisabled: boolean
26
+ model?: any
27
+ modelValue?: any
28
+ checkboxValue?: any
29
+ isDisabled?: boolean
29
30
  label?: string
30
31
  validation?: 'success' | 'warning' | 'error' | null
31
32
  validationText?: string
32
33
  idKey?: string
34
+ indeterminate?: boolean
33
35
  }>()
34
36
 
35
37
  const emit = defineEmits<{
36
38
  (e: 'update:model', value: any): void
39
+ (e: 'update:modelValue', value: any): void
40
+ (e: 'update:indeterminate', value: boolean): void
37
41
  (e: 'blur', event: FocusEvent): void
38
42
  }>()
39
43
 
40
44
  const internalModel = computed({
41
- get: () => props.model,
42
- set: (value) => emit('update:model', value)
45
+ get: () => (props.modelValue !== undefined ? props.modelValue : props.model),
46
+ set: (value) => {
47
+ emit('update:model', value)
48
+ emit('update:modelValue', value)
49
+ }
43
50
  })
44
51
 
52
+ const inputRef = ref<HTMLInputElement | null>(null)
53
+ watch(() => props.indeterminate, (val) => {
54
+ if (inputRef.value) {
55
+ inputRef.value.indeterminate = !!val
56
+ }
57
+ }, { immediate: true, flush: 'post' })
58
+
45
59
  const getId = (item: any) => {
46
60
  if (item && typeof item === 'object') {
47
61
  const key = props.idKey
@@ -77,6 +91,9 @@ const isChecked = computed(() => {
77
91
 
78
92
  function toggleCheckbox() {
79
93
  if (props.isDisabled) return
94
+ if (props.indeterminate) {
95
+ emit('update:indeterminate', false)
96
+ }
80
97
  if (Array.isArray(internalModel.value)) {
81
98
  const val = props.checkboxValue
82
99
  const arr = [...internalModel.value]
@@ -88,7 +105,11 @@ function toggleCheckbox() {
88
105
  }
89
106
  internalModel.value = arr
90
107
  } else {
91
- internalModel.value = !internalModel.value
108
+ if (props.indeterminate) {
109
+ internalModel.value = true
110
+ } else {
111
+ internalModel.value = !internalModel.value
112
+ }
92
113
  }
93
114
  }
94
115
 
@@ -131,7 +152,9 @@ function handleSpaceKey() {
131
152
  display: none;
132
153
  }
133
154
 
134
- :checked + .icon-container > .icon {
155
+ :checked + .icon-container > .icon,
156
+ :indeterminate + .icon-container > .icon,
157
+ .icon-container.is-indeterminate > .icon {
135
158
  display: block;
136
159
  }
137
160
  }
@@ -1,18 +1,24 @@
1
1
  type __VLS_Props = {
2
- model: any;
3
- checkboxValue: any;
4
- isDisabled: boolean;
2
+ model?: any;
3
+ modelValue?: any;
4
+ checkboxValue?: any;
5
+ isDisabled?: boolean;
5
6
  label?: string;
6
7
  validation?: 'success' | 'warning' | 'error' | null;
7
8
  validationText?: string;
8
9
  idKey?: string;
10
+ indeterminate?: boolean;
9
11
  };
10
12
  declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
13
+ "update:modelValue": (value: any) => any;
11
14
  blur: (event: FocusEvent) => any;
12
15
  "update:model": (value: any) => any;
16
+ "update:indeterminate": (value: boolean) => any;
13
17
  }, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
18
+ "onUpdate:modelValue"?: ((value: any) => any) | undefined;
14
19
  onBlur?: ((event: FocusEvent) => any) | undefined;
15
20
  "onUpdate:model"?: ((value: any) => any) | undefined;
21
+ "onUpdate:indeterminate"?: ((value: boolean) => any) | undefined;
16
22
  }>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
17
23
  declare const _default: typeof __VLS_export;
18
24
  export default _default;
@@ -17,7 +17,11 @@
17
17
  thead
18
18
  tr
19
19
  th.check(v-if="props.bulkActions && props.bulkActions.length > 0")
20
- KCheckbox(v-model="selectAll")
20
+ KCheckbox(
21
+ :model-value="isAllSelected"
22
+ :indeterminate="isIndeterminate"
23
+ @update:model-value="handleSelectAll"
24
+ )
21
25
  th(
22
26
  v-for="field in visibleFields || props.dataProvider.fields"
23
27
  :key="field"
@@ -78,10 +82,10 @@
78
82
  )
79
83
  td(:colspan="totalColspan")
80
84
  .footer(v-if="!props.virtualScroll")
81
- KBulkActions.bulk-actions(v-if="props.bulkActions && props.bulkActions.length > 0" :bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll")
85
+ KBulkActions.bulk-actions(v-if="props.bulkActions && props.bulkActions.length > 0" :bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll" :filter="props.dataProvider.filter")
82
86
  KPagination.pagination(:dataProvider="props.dataProvider" @update:currentPage="emit('update:currentPage', $event)" @update:pageSize="emit('update:pageSize', $event)")
83
87
  .footer.virtual-footer(v-else-if="props.bulkActions && props.bulkActions.length > 0")
84
- KBulkActions.bulk-actions(:bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll")
88
+ KBulkActions.bulk-actions(:bulkActions="props.bulkActions" :selectedRows="selectedRows" :selectAll="selectAll" :filter="props.dataProvider.filter")
85
89
  </template>
86
90
 
87
91
  <script setup lang="ts">
@@ -174,12 +178,57 @@ const isRowSelected = (row: any) => {
174
178
  return selectedRowIds.value.has(rowId) || selectedRowIds.value.has(row)
175
179
  }
176
180
 
181
+ const selectedCount = computed(() => {
182
+ if (selectAll.value) return datatableItems.value.length
183
+ let count = 0
184
+ const ids = selectedRowIds.value
185
+ const idKey = (props.dataProvider as any)?.idKey || 'id'
186
+ for (const r of datatableItems.value) {
187
+ const id = r?.[idKey] ?? r?.id ?? r?._id ?? r
188
+ if (ids.has(id) || ids.has(r)) count++
189
+ }
190
+ return count
191
+ })
192
+
193
+ const isAllSelected = computed(() => {
194
+ const total = datatableItems.value.length
195
+ if (total === 0) return false
196
+ if (selectAll.value) return true
197
+ return selectedCount.value === total
198
+ })
199
+
200
+ const isIndeterminate = computed(() => {
201
+ const total = datatableItems.value.length
202
+ if (total === 0) return false
203
+ if (isAllSelected.value) return false
204
+ return selectedCount.value > 0 || (selectedRows.value && selectedRows.value.length > 0)
205
+ })
206
+
207
+ const handleSelectAll = () => {
208
+ const total = datatableItems.value.length
209
+ if (total === 0) return
210
+
211
+ if (isAllSelected.value) {
212
+ selectAll.value = false
213
+ selectedRows.value = []
214
+ } else {
215
+ const isFiltered = !!((dpFilter as any)?.active || (dpFilter as any)?.value?.active || (props.dataProvider as any)?.filter?.active || (props.dataProvider as any)?.filter?.value?.active)
216
+ if (isFiltered) {
217
+ selectAll.value = false
218
+ selectedRows.value = [...datatableItems.value]
219
+ } else {
220
+ selectAll.value = true
221
+ selectedRows.value = [...datatableItems.value]
222
+ }
223
+ }
224
+ }
225
+
177
226
  const toggleRow = (row: any) => {
178
227
  const idKey = (props.dataProvider as any)?.idKey || 'id'
179
228
  const rowId = row?.[idKey] ?? row?.id ?? row?._id ?? row
180
229
  if (selectAll.value) {
181
230
  selectAll.value = false
182
- const activeRows = displayRows.value || pageRows.value
231
+ const activeRows = datatableItems.value
183
232
  selectedRows.value = activeRows.filter((r: any) => {
184
233
  const rId = r?.[idKey] ?? r?.id ?? r?._id ?? r
185
234
  return rId !== rowId && r !== row
@@ -187,12 +236,17 @@ const toggleRow = (row: any) => {
187
236
  } else {
188
237
  const isSelected = isRowSelected(row)
189
238
  if (isSelected) {
190
- selectedRows.value = (selectedRows.value || []).filter((r: any) => {
239
+ const next = (selectedRows.value || []).filter((r: any) => {
191
240
  const rId = r?.[idKey] ?? r?.id ?? r?._id ?? r
192
241
  return rId !== rowId && r !== row
193
242
  })
243
+ selectedRows.value = next
194
244
  } else {
195
- selectedRows.value = [...(selectedRows.value || []), row]
245
+ const next = [...(selectedRows.value || []), row]
246
+ selectedRows.value = next
247
+ if (next.length === datatableItems.value.length && datatableItems.value.length > 0) {
248
+ selectAll.value = true
249
+ }
196
250
  }
197
251
  }
198
252
  }
@@ -234,9 +288,9 @@ const datatableItems = computed(() => {
234
288
  const currentRows = pageRows.value
235
289
  const dp = props.dataProvider as any
236
290
  if (props.virtualScroll) {
291
+ if (Array.isArray(virtualRows?.value)) return virtualRows.value
237
292
  if (Array.isArray(dp?.rowMap)) return dp.rowMap
238
293
  if (Array.isArray(dp?.rowMap?.value)) return dp.rowMap.value
239
- if (Array.isArray(virtualRows?.value) && virtualRows.value.length > 0) return virtualRows.value
240
294
  if (Array.isArray(dp?.allVisibleRows)) return dp.allVisibleRows
241
295
  if (Array.isArray(dp?.allVisibleRows?.value)) return dp.allVisibleRows.value
242
296
  if (Array.isArray(dp?.allVisibleNodes)) return dp.allVisibleNodes
@@ -257,12 +311,13 @@ const {
257
311
  containerRef,
258
312
  onScroll,
259
313
  scrollToIndex,
260
- containerCssVars
314
+ containerCssVars,
315
+ scrollTop
261
316
  } = useVirtualScroll({
262
317
  items: datatableItems,
263
- itemHeight: props.itemHeight || 40,
264
- containerHeight: props.viewportHeight || 500,
265
- buffer: props.buffer ?? 5,
318
+ itemHeight: computed(() => props.itemHeight || 40),
319
+ containerHeight: computed(() => props.viewportHeight || 500),
320
+ buffer: computed(() => props.buffer ?? 5),
266
321
  virtualScroll: computed(() => !!props.virtualScroll),
267
322
  onThresholdReach: () => {
268
323
  const dp = props.dataProvider as any
@@ -295,24 +350,59 @@ const handleKeyDown = (e: KeyboardEvent) => {
295
350
  const total = datatableItems.value.length
296
351
  if (total === 0) return
297
352
 
353
+ const itemH = props.itemHeight || 40
354
+ const vpH = props.viewportHeight || 500
355
+ const firstInView = Math.floor(scrollTop.value / itemH)
356
+ const lastInView = Math.min(total - 1, Math.floor((scrollTop.value + vpH) / itemH) - 1)
357
+
358
+ const ensureVisible = (index: number) => {
359
+ const rowTop = index * itemH
360
+ const rowBottom = rowTop + itemH
361
+ if (rowTop < scrollTop.value) {
362
+ scrollToIndex(index, 'auto', index > 0 ? theadStickyOffset : 0)
363
+ } else if (rowBottom > scrollTop.value + vpH) {
364
+ const targetScroll = Math.max(0, rowBottom - vpH)
365
+ scrollTop.value = targetScroll
366
+ if (containerRef.value) {
367
+ containerRef.value.scrollTop = targetScroll
368
+ }
369
+ }
370
+ }
371
+
298
372
  if (e.key === 'ArrowDown') {
299
373
  e.preventDefault()
300
- focusedIndex.value = Math.min(total - 1, focusedIndex.value + 1)
301
- scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
374
+ if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
375
+ focusedIndex.value = Math.min(total - 1, firstInView)
376
+ } else {
377
+ focusedIndex.value = Math.min(total - 1, focusedIndex.value + 1)
378
+ }
379
+ ensureVisible(focusedIndex.value)
302
380
  } else if (e.key === 'ArrowUp') {
303
381
  e.preventDefault()
304
- focusedIndex.value = Math.max(0, focusedIndex.value - 1)
305
- scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
382
+ if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
383
+ focusedIndex.value = Math.max(0, lastInView)
384
+ } else {
385
+ focusedIndex.value = Math.max(0, focusedIndex.value - 1)
386
+ }
387
+ ensureVisible(focusedIndex.value)
306
388
  } else if (e.key === 'PageDown') {
307
389
  e.preventDefault()
308
- const step = Math.floor((props.viewportHeight || 500) / (props.itemHeight || 40))
309
- focusedIndex.value = Math.min(total - 1, focusedIndex.value + step)
310
- scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
390
+ const step = Math.max(1, Math.floor(vpH / itemH))
391
+ if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
392
+ focusedIndex.value = Math.min(total - 1, firstInView + step)
393
+ } else {
394
+ focusedIndex.value = Math.min(total - 1, focusedIndex.value + step)
395
+ }
396
+ ensureVisible(focusedIndex.value)
311
397
  } else if (e.key === 'PageUp') {
312
398
  e.preventDefault()
313
- const step = Math.floor((props.viewportHeight || 500) / (props.itemHeight || 40))
314
- focusedIndex.value = Math.max(0, focusedIndex.value - step)
315
- scrollToIndex(focusedIndex.value, 'auto', focusedIndex.value > 0 ? theadStickyOffset : 0)
399
+ const step = Math.max(1, Math.floor(vpH / itemH))
400
+ if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
401
+ focusedIndex.value = Math.max(0, lastInView - step)
402
+ } else {
403
+ focusedIndex.value = Math.max(0, focusedIndex.value - step)
404
+ }
405
+ ensureVisible(focusedIndex.value)
316
406
  } else if (e.key === 'Home') {
317
407
  e.preventDefault()
318
408
  focusedIndex.value = 0