@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.
- package/bin/create-preset.mjs +5 -4
- package/dist/compiled/composables/useDataProvider.mjs +20 -0
- package/dist/compiled/composables/useKatluxContext.mjs +6 -3
- package/dist/compiled/composables/useKatluxForm.mjs +311 -0
- package/dist/compiled/composables/useToast.mjs +164 -0
- package/dist/compiled/composables/useVirtualScroll.mjs +246 -0
- package/dist/module.cjs +1 -0
- package/dist/module.json +1 -1
- package/dist/module.mjs +1 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +6 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +3 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +6 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +21 -6
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +12 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue +4 -2
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +12 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.logic.d.ts +5 -0
- package/dist/runtime/components/KCheckbox/KCheckbox.logic.js +4 -0
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +11 -0
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +4 -3
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +11 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +6 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +22 -3
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +10 -2
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +10 -2
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +12 -4
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +8 -0
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +28 -5
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +4 -0
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +6 -1
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +4 -0
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +7 -6
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.js +7 -6
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +9 -0
- package/dist/runtime/components/KDropdown/KDropdown.global.vue +2 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +9 -0
- package/dist/runtime/components/KDropdown/KDropdown.logic.d.ts +5 -0
- package/dist/runtime/components/KDropdown/KDropdown.logic.js +10 -7
- package/dist/runtime/components/KGantt/KGantt.logic.js +5 -3
- package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +2 -0
- package/dist/runtime/components/KPagination/KPagination.global.vue +1 -1
- package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +2 -0
- package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -0
- package/dist/runtime/components/KPagination/KPagination.logic.js +11 -3
- package/dist/runtime/components/KToast/KToast.global.d.vue.ts +24 -1
- package/dist/runtime/components/KToast/KToast.global.vue +12 -2
- package/dist/runtime/components/KToast/KToast.global.vue.d.ts +24 -1
- package/dist/runtime/components/KToast/KToast.logic.d.ts +13 -0
- package/dist/runtime/components/KToast/KToast.logic.js +45 -5
- package/dist/runtime/components/KToastContainer/KToastContainer.global.d.vue.ts +3 -0
- package/dist/runtime/components/KToastContainer/KToastContainer.global.vue +11 -0
- package/dist/runtime/components/KToastContainer/KToastContainer.global.vue.d.ts +3 -0
- package/dist/runtime/components/KTooltip/KTooltip.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTooltip/KTooltip.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +39 -1
- package/dist/runtime/components/KTree/KTree.global.vue +7 -4
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +39 -1
- package/dist/runtime/components/KTree/KTree.logic.d.ts +21 -0
- package/dist/runtime/components/KTree/KTree.logic.js +17 -0
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +53 -2
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +30 -3
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +53 -2
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +20 -0
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +16 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +37 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +37 -1
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +20 -0
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +16 -0
- package/dist/runtime/composables/useDataProvider.d.ts +1 -0
- package/dist/runtime/composables/useDataProvider.js +20 -0
- package/dist/runtime/composables/useKatluxContext.js +6 -3
- package/dist/runtime/composables/useKatluxForm.d.ts +145 -0
- package/dist/runtime/composables/useKatluxForm.js +311 -0
- package/dist/runtime/composables/useToast.d.ts +49 -0
- package/dist/runtime/composables/useToast.js +164 -0
- package/dist/runtime/composables/useVirtualScroll.d.ts +34 -0
- package/dist/runtime/composables/useVirtualScroll.js +246 -0
- package/dist/runtime/plugins/PresetPlugin.js +9 -1
- package/dist/runtime/plugins/nuxtCompatPlugin.js +0 -1
- package/dist/runtime/plugins/toastPlugin.client.d.ts +2 -0
- package/dist/runtime/plugins/toastPlugin.client.js +16 -0
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +1 -0
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +3 -0
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue +43 -7
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +3 -0
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +3 -0
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +12 -4
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +3 -0
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +7 -2
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +12 -1
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +143 -7
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +12 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +12 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +228 -32
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +12 -1
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.d.vue.ts +3 -1
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue +3 -1
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue.d.ts +3 -1
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.d.vue.ts +1 -0
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue +23 -2
- package/dist/runtime/presets/default/components/KDropdown/KDropdown.vue.d.ts +1 -0
- package/dist/runtime/presets/default/components/KLayout/KLayout.d.vue.ts +6 -1
- package/dist/runtime/presets/default/components/KLayout/KLayout.vue +37 -3
- package/dist/runtime/presets/default/components/KLayout/KLayout.vue.d.ts +6 -1
- package/dist/runtime/presets/default/components/KModal/KModal.vue +8 -1
- package/dist/runtime/presets/default/components/KTabs/KTabItem.vue +1 -1
- package/dist/runtime/presets/default/components/KTextbox/KTextbox.vue +6 -4
- package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +6 -0
- package/dist/runtime/presets/default/components/KToast/KToast.vue +21 -4
- package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +6 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.d.vue.ts +11 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue +206 -0
- package/dist/runtime/presets/default/components/KToastContainer/KToastContainer.vue.d.ts +11 -0
- package/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +15 -6
- package/dist/runtime/presets/default/components/KTree/KTree.vue +235 -14
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +15 -6
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.d.vue.ts +14 -1
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue +118 -13
- package/dist/runtime/presets/default/components/KTreePicker/KTreePicker.vue.d.ts +14 -1
- package/dist/runtime/presets/default/components/KTreeView/KTreeCell.vue +12 -3
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +4 -0
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +8 -0
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +4 -0
- package/dist/runtime/server/middleware/session.js +1 -1
- package/package.json +3 -4
- package/dist/compiled/composables/useDataProvider.spec.mjs +0 -157
- package/dist/compiled/composables/useKatluxContext.spec.mjs +0 -63
- package/dist/compiled/composables/useKatluxI18n.spec.mjs +0 -10
- package/dist/compiled/composables/usePresetComponent.spec.mjs +0 -106
- package/dist/compiled/composables/useTemplate.spec.mjs +0 -30
- package/dist/compiled/utils/PresetResolver.spec.mjs +0 -68
|
@@ -0,0 +1,246 @@
|
|
|
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 configuredContainerHeight = computed(() => resolveContainerHeight());
|
|
46
|
+
const viewportHeight = ref(resolveContainerHeight());
|
|
47
|
+
watch(
|
|
48
|
+
() => resolveContainerHeight(),
|
|
49
|
+
(newH) => {
|
|
50
|
+
if (typeof newH === "number" && newH > 0) {
|
|
51
|
+
viewportHeight.value = newH;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
);
|
|
55
|
+
watch([containerRef, isVirtual], ([el, virtual], [oldEl]) => {
|
|
56
|
+
if (typeof window === "undefined" || typeof ResizeObserver === "undefined") return;
|
|
57
|
+
if (oldEl && oldEl.__vsObserver) {
|
|
58
|
+
oldEl.__vsObserver.disconnect();
|
|
59
|
+
delete oldEl.__vsObserver;
|
|
60
|
+
}
|
|
61
|
+
if (el && virtual) {
|
|
62
|
+
const ro = new ResizeObserver((entries) => {
|
|
63
|
+
for (const entry of entries) {
|
|
64
|
+
const h = Math.round(entry.contentRect.height || el.clientHeight);
|
|
65
|
+
if (h > 0 && h !== viewportHeight.value) {
|
|
66
|
+
viewportHeight.value = h;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
ro.observe(el);
|
|
71
|
+
el.__vsObserver = ro;
|
|
72
|
+
}
|
|
73
|
+
});
|
|
74
|
+
if (getCurrentScope()) {
|
|
75
|
+
onScopeDispose(() => {
|
|
76
|
+
if (containerRef.value && containerRef.value.__vsObserver) {
|
|
77
|
+
containerRef.value.__vsObserver.disconnect();
|
|
78
|
+
delete containerRef.value.__vsObserver;
|
|
79
|
+
}
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
const isDynamicHeight = computed(() => typeof options.itemHeight === "function");
|
|
83
|
+
const rowOffsets = computed(() => {
|
|
84
|
+
if (!isDynamicHeight.value || colCount.value > 1) return [];
|
|
85
|
+
const items = allItems.value;
|
|
86
|
+
const offsets = new Array(items.length + 1);
|
|
87
|
+
offsets[0] = 0;
|
|
88
|
+
let current = 0;
|
|
89
|
+
for (let i = 0; i < items.length; i++) {
|
|
90
|
+
current += getItemHeight(items[i], i);
|
|
91
|
+
offsets[i + 1] = current;
|
|
92
|
+
}
|
|
93
|
+
return offsets;
|
|
94
|
+
});
|
|
95
|
+
const totalRows = computed(() => {
|
|
96
|
+
if (colCount.value <= 1) return totalCount.value;
|
|
97
|
+
return Math.ceil(totalCount.value / colCount.value);
|
|
98
|
+
});
|
|
99
|
+
const startRowIndex = computed(() => {
|
|
100
|
+
if (!isVirtual.value) return 0;
|
|
101
|
+
if (isDynamicHeight.value && colCount.value <= 1) {
|
|
102
|
+
const offsets = rowOffsets.value;
|
|
103
|
+
const top = Math.max(0, scrollTop.value);
|
|
104
|
+
let low = 0;
|
|
105
|
+
let high = totalRows.value - 1;
|
|
106
|
+
let idx = 0;
|
|
107
|
+
while (low <= high) {
|
|
108
|
+
const mid = low + high >> 1;
|
|
109
|
+
if (offsets[mid + 1] > top) {
|
|
110
|
+
idx = mid;
|
|
111
|
+
high = mid - 1;
|
|
112
|
+
} else {
|
|
113
|
+
low = mid + 1;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
return Math.max(0, idx - buf.value);
|
|
117
|
+
}
|
|
118
|
+
const rawRow = Math.floor(scrollTop.value / baseItemHeight.value);
|
|
119
|
+
return Math.max(0, rawRow - buf.value);
|
|
120
|
+
});
|
|
121
|
+
const visibleRowsCount = computed(() => {
|
|
122
|
+
if (!isVirtual.value) return totalRows.value;
|
|
123
|
+
const rowsInView = Math.ceil(viewportHeight.value / baseItemHeight.value);
|
|
124
|
+
return rowsInView + 2 * buf.value + 1;
|
|
125
|
+
});
|
|
126
|
+
const endRowIndex = computed(() => {
|
|
127
|
+
if (!isVirtual.value) return totalRows.value;
|
|
128
|
+
if (isDynamicHeight.value && colCount.value <= 1) {
|
|
129
|
+
const offsets = rowOffsets.value;
|
|
130
|
+
const bottom = scrollTop.value + viewportHeight.value;
|
|
131
|
+
let low = startRowIndex.value;
|
|
132
|
+
let high = totalRows.value - 1;
|
|
133
|
+
let idx = totalRows.value;
|
|
134
|
+
while (low <= high) {
|
|
135
|
+
const mid = low + high >> 1;
|
|
136
|
+
if (offsets[mid] >= bottom) {
|
|
137
|
+
idx = mid;
|
|
138
|
+
high = mid - 1;
|
|
139
|
+
} else {
|
|
140
|
+
low = mid + 1;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return Math.min(totalRows.value, idx + buf.value);
|
|
144
|
+
}
|
|
145
|
+
return Math.min(totalRows.value, startRowIndex.value + visibleRowsCount.value);
|
|
146
|
+
});
|
|
147
|
+
const startIndex = computed(() => {
|
|
148
|
+
if (!isVirtual.value) return 0;
|
|
149
|
+
return Math.max(0, startRowIndex.value * colCount.value);
|
|
150
|
+
});
|
|
151
|
+
const endIndex = computed(() => {
|
|
152
|
+
if (!isVirtual.value) return totalCount.value;
|
|
153
|
+
return Math.min(totalCount.value, endRowIndex.value * colCount.value);
|
|
154
|
+
});
|
|
155
|
+
const visibleItems = computed(() => {
|
|
156
|
+
if (!isVirtual.value) return allItems.value;
|
|
157
|
+
return allItems.value.slice(startIndex.value, endIndex.value);
|
|
158
|
+
});
|
|
159
|
+
const topSpacerHeight = computed(() => {
|
|
160
|
+
if (!isVirtual.value) return 0;
|
|
161
|
+
if (isDynamicHeight.value && colCount.value <= 1) {
|
|
162
|
+
return rowOffsets.value[startRowIndex.value] || 0;
|
|
163
|
+
}
|
|
164
|
+
return Math.max(0, startRowIndex.value * baseItemHeight.value);
|
|
165
|
+
});
|
|
166
|
+
const totalHeight = computed(() => {
|
|
167
|
+
if (isDynamicHeight.value && colCount.value <= 1) {
|
|
168
|
+
const offsets = rowOffsets.value;
|
|
169
|
+
return offsets.length > 0 ? offsets[offsets.length - 1] : 0;
|
|
170
|
+
}
|
|
171
|
+
return totalRows.value * baseItemHeight.value;
|
|
172
|
+
});
|
|
173
|
+
const bottomSpacerHeight = computed(() => {
|
|
174
|
+
if (!isVirtual.value) return 0;
|
|
175
|
+
if (isDynamicHeight.value && colCount.value <= 1) {
|
|
176
|
+
const endOffset = rowOffsets.value[endRowIndex.value] || totalHeight.value;
|
|
177
|
+
return Math.max(0, totalHeight.value - endOffset);
|
|
178
|
+
}
|
|
179
|
+
const remainingRows = Math.max(0, totalRows.value - endRowIndex.value);
|
|
180
|
+
return remainingRows * baseItemHeight.value;
|
|
181
|
+
});
|
|
182
|
+
watch(totalHeight, (newTotal) => {
|
|
183
|
+
if (scrollTop.value > newTotal) {
|
|
184
|
+
scrollTop.value = Math.max(0, newTotal - viewportHeight.value);
|
|
185
|
+
if (containerRef.value) {
|
|
186
|
+
containerRef.value.scrollTop = scrollTop.value;
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
});
|
|
190
|
+
const containerCssVars = computed(() => ({
|
|
191
|
+
"--virtual-spacer-top": `${topSpacerHeight.value}px`,
|
|
192
|
+
"--virtual-spacer-bottom": `${bottomSpacerHeight.value}px`,
|
|
193
|
+
"--virtual-total-height": `${totalHeight.value}px`,
|
|
194
|
+
"--virtual-item-height": `${baseItemHeight.value}px`,
|
|
195
|
+
"--virtual-container-height": `${configuredContainerHeight.value}px`
|
|
196
|
+
}));
|
|
197
|
+
const scrollThreshold = options.scrollThreshold ?? 100;
|
|
198
|
+
const onScroll = (e) => {
|
|
199
|
+
const target = e.target;
|
|
200
|
+
if (!target) return;
|
|
201
|
+
scrollTop.value = target.scrollTop;
|
|
202
|
+
if (target.clientHeight && target.clientHeight !== viewportHeight.value) {
|
|
203
|
+
viewportHeight.value = target.clientHeight;
|
|
204
|
+
}
|
|
205
|
+
const distanceToBottom = target.scrollHeight - (target.scrollTop + target.clientHeight);
|
|
206
|
+
if (distanceToBottom <= scrollThreshold && typeof options.onThresholdReach === "function") {
|
|
207
|
+
options.onThresholdReach();
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const scrollToIndex = (index, behavior = "auto", offset = 0) => {
|
|
211
|
+
if (isDynamicHeight.value && colCount.value <= 1) {
|
|
212
|
+
const targetScrollTop2 = Math.max(0, (rowOffsets.value[index] || 0) - offset);
|
|
213
|
+
scrollTop.value = targetScrollTop2;
|
|
214
|
+
if (containerRef.value) {
|
|
215
|
+
containerRef.value.scrollTo({
|
|
216
|
+
top: targetScrollTop2,
|
|
217
|
+
behavior
|
|
218
|
+
});
|
|
219
|
+
}
|
|
220
|
+
return;
|
|
221
|
+
}
|
|
222
|
+
const targetRow = colCount.value <= 1 ? index : Math.floor(index / colCount.value);
|
|
223
|
+
const targetScrollTop = Math.max(0, targetRow * baseItemHeight.value - offset);
|
|
224
|
+
scrollTop.value = targetScrollTop;
|
|
225
|
+
if (containerRef.value) {
|
|
226
|
+
containerRef.value.scrollTo({
|
|
227
|
+
top: targetScrollTop,
|
|
228
|
+
behavior
|
|
229
|
+
});
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
return {
|
|
233
|
+
startIndex,
|
|
234
|
+
endIndex,
|
|
235
|
+
visibleItems,
|
|
236
|
+
topSpacerHeight,
|
|
237
|
+
bottomSpacerHeight,
|
|
238
|
+
totalHeight,
|
|
239
|
+
scrollTop,
|
|
240
|
+
viewportHeight,
|
|
241
|
+
containerRef,
|
|
242
|
+
onScroll,
|
|
243
|
+
scrollToIndex,
|
|
244
|
+
containerCssVars
|
|
245
|
+
};
|
|
246
|
+
}
|
|
@@ -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) =>
|
|
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,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
|
+
});
|
|
@@ -5,10 +5,13 @@ type __VLS_Props = {
|
|
|
5
5
|
label?: string;
|
|
6
6
|
validation?: 'success' | 'warning' | 'error' | null;
|
|
7
7
|
validationText?: string;
|
|
8
|
+
idKey?: string;
|
|
8
9
|
};
|
|
9
10
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
11
|
+
blur: (event: FocusEvent) => any;
|
|
10
12
|
"update:model": (value: any) => any;
|
|
11
13
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
14
|
+
onBlur?: ((event: FocusEvent) => any) | undefined;
|
|
12
15
|
"onUpdate:model"?: ((value: any) => any) | undefined;
|
|
13
16
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
17
|
declare const _default: typeof __VLS_export;
|
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
:aria-disabled="isDisabled"
|
|
7
7
|
tabindex="0"
|
|
8
8
|
@keydown.space.prevent="handleSpaceKey"
|
|
9
|
+
@blur="emit('blur', $event)"
|
|
9
10
|
)
|
|
10
|
-
input(type="checkbox"
|
|
11
|
+
input(type="checkbox" :checked="isChecked" :disabled="isDisabled" tabindex="-1" @change="toggleCheckbox")
|
|
11
12
|
.icon-container(:class="validation ? `is-${validation}` : ''")
|
|
12
13
|
KIcon.icon(iconname="check")
|
|
13
14
|
span
|
|
@@ -28,10 +29,12 @@ const props = defineProps<{
|
|
|
28
29
|
label?: string
|
|
29
30
|
validation?: 'success' | 'warning' | 'error' | null
|
|
30
31
|
validationText?: string
|
|
32
|
+
idKey?: string
|
|
31
33
|
}>()
|
|
32
34
|
|
|
33
35
|
const emit = defineEmits<{
|
|
34
36
|
(e: 'update:model', value: any): void
|
|
37
|
+
(e: 'blur', event: FocusEvent): void
|
|
35
38
|
}>()
|
|
36
39
|
|
|
37
40
|
const internalModel = computed({
|
|
@@ -39,27 +42,60 @@ const internalModel = computed({
|
|
|
39
42
|
set: (value) => emit('update:model', value)
|
|
40
43
|
})
|
|
41
44
|
|
|
45
|
+
const getId = (item: any) => {
|
|
46
|
+
if (item && typeof item === 'object') {
|
|
47
|
+
const key = props.idKey
|
|
48
|
+
if (key && item[key] !== undefined && item[key] !== null) {
|
|
49
|
+
return item[key]
|
|
50
|
+
}
|
|
51
|
+
return item.id ?? item._id ?? item
|
|
52
|
+
}
|
|
53
|
+
return item
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
const findItemIndex = (arr: any[], target: any): number => {
|
|
57
|
+
const targetId = getId(target)
|
|
58
|
+
return arr.findIndex(item => {
|
|
59
|
+
if (item === target) return true
|
|
60
|
+
if (targetId !== undefined && targetId !== null) {
|
|
61
|
+
const itemId = getId(item)
|
|
62
|
+
if (itemId !== undefined && itemId !== null && itemId === targetId) {
|
|
63
|
+
return true
|
|
64
|
+
}
|
|
65
|
+
}
|
|
66
|
+
return false
|
|
67
|
+
})
|
|
68
|
+
}
|
|
69
|
+
|
|
42
70
|
// Correctly compute checked state for both boolean and array models
|
|
43
71
|
const isChecked = computed(() => {
|
|
44
72
|
if (Array.isArray(internalModel.value)) {
|
|
45
|
-
return internalModel.value
|
|
73
|
+
return findItemIndex(internalModel.value, props.checkboxValue) !== -1
|
|
46
74
|
}
|
|
47
75
|
return !!internalModel.value
|
|
48
76
|
})
|
|
49
77
|
|
|
50
|
-
|
|
51
|
-
|
|
78
|
+
function toggleCheckbox() {
|
|
79
|
+
if (props.isDisabled) return
|
|
52
80
|
if (Array.isArray(internalModel.value)) {
|
|
53
81
|
const val = props.checkboxValue
|
|
54
82
|
const arr = [...internalModel.value]
|
|
55
|
-
const idx = arr
|
|
56
|
-
if (idx === -1)
|
|
57
|
-
|
|
83
|
+
const idx = findItemIndex(arr, val)
|
|
84
|
+
if (idx === -1) {
|
|
85
|
+
arr.push(val)
|
|
86
|
+
} else {
|
|
87
|
+
arr.splice(idx, 1)
|
|
88
|
+
}
|
|
58
89
|
internalModel.value = arr
|
|
59
90
|
} else {
|
|
60
91
|
internalModel.value = !internalModel.value
|
|
61
92
|
}
|
|
62
93
|
}
|
|
94
|
+
|
|
95
|
+
// Handle Space key correctly for both boolean and array models
|
|
96
|
+
function handleSpaceKey() {
|
|
97
|
+
toggleCheckbox()
|
|
98
|
+
}
|
|
63
99
|
</script>
|
|
64
100
|
|
|
65
101
|
<style lang="scss" scoped>
|
|
@@ -5,10 +5,13 @@ type __VLS_Props = {
|
|
|
5
5
|
label?: string;
|
|
6
6
|
validation?: 'success' | 'warning' | 'error' | null;
|
|
7
7
|
validationText?: string;
|
|
8
|
+
idKey?: string;
|
|
8
9
|
};
|
|
9
10
|
declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
11
|
+
blur: (event: FocusEvent) => any;
|
|
10
12
|
"update:model": (value: any) => any;
|
|
11
13
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
14
|
+
onBlur?: ((event: FocusEvent) => any) | undefined;
|
|
12
15
|
"onUpdate:model"?: ((value: any) => any) | undefined;
|
|
13
16
|
}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
14
17
|
declare const _default: typeof __VLS_export;
|
|
@@ -29,11 +29,14 @@ 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, {} & {
|
|
35
|
+
blur: (event: FocusEvent) => any;
|
|
34
36
|
"update:isOptionsOpen": (value: boolean) => any;
|
|
35
37
|
"update:searchtext": (value: string) => any;
|
|
36
38
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
39
|
+
onBlur?: ((event: FocusEvent) => any) | undefined;
|
|
37
40
|
"onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
|
|
38
41
|
"onUpdate:searchtext"?: ((value: string) => any) | undefined;
|
|
39
42
|
}>, {
|
|
@@ -1,14 +1,17 @@
|
|
|
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"
|
|
9
|
+
@blur="emit('blur', $event)"
|
|
8
10
|
role="combobox"
|
|
9
11
|
:aria-expanded="isOptionsOpen"
|
|
10
12
|
aria-haspopup="listbox"
|
|
11
|
-
:aria-
|
|
13
|
+
:aria-controls="listboxId"
|
|
14
|
+
:aria-activedescendant="highlightedIndex !== undefined && highlightedIndex >= 0 ? `${listboxId}-opt-${highlightedIndex}` : undefined"
|
|
12
15
|
:aria-disabled="disabled"
|
|
13
16
|
:tabindex="disabled ? -1 : 0"
|
|
14
17
|
align="center"
|
|
@@ -22,11 +25,12 @@
|
|
|
22
25
|
) {{ item[labelField] }}
|
|
23
26
|
.KCombobox__selected-content-placeholder(v-else) {{placeholder}}
|
|
24
27
|
KIcon(iconname="chevron" width="20" height="20").chevron
|
|
25
|
-
KDropdown(v-model:isOpen="isOptionsOpenModel" :anchorEl="activatorRef" :fullWidth="fullWidth" :teleportTo="teleportTo").KCombobox__options
|
|
28
|
+
KDropdown(v-model:isOpen="isOptionsOpenModel" :anchorEl="activatorRef" :fullWidth="fullWidth" :teleportTo="teleportTo" :maxHeight="maxHeight").KCombobox__options
|
|
26
29
|
template(v-if="slots.default")
|
|
27
30
|
slot(name="default")
|
|
28
31
|
KComboboxList(
|
|
29
32
|
v-else
|
|
33
|
+
:listboxId="listboxId"
|
|
30
34
|
:searchbox="searchbox"
|
|
31
35
|
:searchPlaceholder="searchPlaceholder"
|
|
32
36
|
v-model:searchtext="searchtextModel"
|
|
@@ -50,9 +54,11 @@
|
|
|
50
54
|
</template>
|
|
51
55
|
|
|
52
56
|
<script lang="ts" setup>
|
|
53
|
-
import { computed, ref, useSlots, watch } from 'vue'
|
|
57
|
+
import { computed, ref, useSlots, watch, useId } from 'vue'
|
|
54
58
|
const activatorRef = ref<HTMLElement | null>(null)
|
|
55
59
|
const slots = useSlots()
|
|
60
|
+
const comboboxId = useId()
|
|
61
|
+
const listboxId = `${comboboxId}-listbox`
|
|
56
62
|
import KComboboxList from './KComboboxList.vue'
|
|
57
63
|
import type { ComboboxItem } from '#toolkit/components/KCombobox/KCombobox.logic'
|
|
58
64
|
|
|
@@ -86,6 +92,7 @@ const props = withDefaults(defineProps<{
|
|
|
86
92
|
setHighlightedIndex?: (idx: number) => void
|
|
87
93
|
validation?: 'success' | 'warning' | 'error' | null
|
|
88
94
|
validationText?: string
|
|
95
|
+
maxHeight?: number
|
|
89
96
|
}>(), {
|
|
90
97
|
virtualScroll: true,
|
|
91
98
|
itemHeight: 40,
|
|
@@ -98,6 +105,7 @@ const props = withDefaults(defineProps<{
|
|
|
98
105
|
const emit = defineEmits<{
|
|
99
106
|
(e: 'update:searchtext', value: string): void
|
|
100
107
|
(e: 'update:isOptionsOpen', value: boolean): void
|
|
108
|
+
(e: 'blur', event: FocusEvent): void
|
|
101
109
|
}>()
|
|
102
110
|
|
|
103
111
|
const searchtextModel = computed({
|
|
@@ -29,11 +29,14 @@ 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, {} & {
|
|
35
|
+
blur: (event: FocusEvent) => any;
|
|
34
36
|
"update:isOptionsOpen": (value: boolean) => any;
|
|
35
37
|
"update:searchtext": (value: string) => any;
|
|
36
38
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
39
|
+
onBlur?: ((event: FocusEvent) => any) | undefined;
|
|
37
40
|
"onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
|
|
38
41
|
"onUpdate:searchtext"?: ((value: string) => any) | undefined;
|
|
39
42
|
}>, {
|
|
@@ -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="
|
|
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)
|
|
@@ -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
|
-
}>, {
|
|
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;
|