@katlux/toolkit 0.1.1-alpha.109 → 0.1.1-alpha.111
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/dist/compiled/composables/useDataProvider.mjs +26 -10
- package/dist/compiled/composables/useRequestQueue.mjs +35 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.d.ts +2 -0
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +46 -3
- package/dist/runtime/components/KButton/KButton.global.d.vue.ts +1 -1
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +1 -1
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +28 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +12 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +28 -1
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +22 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +115 -10
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +5 -5
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +5 -5
- package/dist/runtime/components/KContextMenu/KContextMenu.global.d.vue.ts +1 -1
- package/dist/runtime/components/KContextMenu/KContextMenu.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +1 -1
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +6 -5
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +37 -15
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +4 -3
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +45 -12
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +2 -2
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +2 -2
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +3 -3
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +3 -3
- package/dist/runtime/components/KGrid/KGrid.global.d.vue.ts +1 -1
- package/dist/runtime/components/KGrid/KGrid.global.vue.d.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +1 -1
- package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +1 -1
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KPagination/KPagination.logic.js +9 -5
- package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +2 -2
- package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +2 -2
- package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KToast/KToast.global.d.vue.ts +1 -1
- package/dist/runtime/components/KToast/KToast.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.logic.d.ts +1 -1
- package/dist/runtime/components/KTree/KTree.logic.js +7 -4
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +4 -4
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +4 -4
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +7 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +3 -3
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +3 -3
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +1 -1
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +4 -1
- package/dist/runtime/composables/useDataProvider.js +26 -10
- package/dist/runtime/composables/useRequestQueue.d.ts +25 -0
- package/dist/runtime/composables/useRequestQueue.js +35 -0
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.d.vue.ts +15 -1
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue +23 -2
- package/dist/runtime/presets/default/components/KCombobox/KCombobox.vue.d.ts +15 -1
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.d.vue.ts +15 -1
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue +170 -7
- package/dist/runtime/presets/default/components/KCombobox/KComboboxList.vue.d.ts +15 -1
- package/package.json +1 -1
|
@@ -164,23 +164,23 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
164
164
|
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
165
165
|
"onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
|
|
166
166
|
}>, {
|
|
167
|
+
parentKey: string;
|
|
168
|
+
loading: boolean;
|
|
169
|
+
idKey: string;
|
|
167
170
|
label: string;
|
|
168
171
|
disabled: boolean;
|
|
169
|
-
loading: boolean;
|
|
170
172
|
validation: "error" | "success" | "warning" | null | undefined;
|
|
171
|
-
validationText: string;
|
|
172
173
|
modelValue: any;
|
|
173
174
|
valueField: string;
|
|
174
175
|
placeholder: string;
|
|
175
176
|
searchbox: boolean;
|
|
177
|
+
validationText: string;
|
|
176
178
|
searchPlaceholder: string;
|
|
177
179
|
isOptionsOpen: boolean;
|
|
178
180
|
fullWidth: boolean;
|
|
179
181
|
closeOnSelect: boolean;
|
|
180
182
|
multiSelect: boolean;
|
|
181
183
|
iconField: string;
|
|
182
|
-
idKey: string;
|
|
183
|
-
parentKey: string;
|
|
184
184
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
185
185
|
declare const _default: typeof __VLS_export;
|
|
186
186
|
export default _default;
|
|
@@ -111,4 +111,11 @@ export declare function useKTreePickerLogic(props: KTreePickerProps, emit: any):
|
|
|
111
111
|
closeDropdown: () => void;
|
|
112
112
|
filteredOptions: import("vue").ComputedRef<import("@katlux/providers").TDataRow[]>;
|
|
113
113
|
loading: import("vue").Ref<boolean, boolean>;
|
|
114
|
+
loadingMore: import("vue").ComputedRef<boolean>;
|
|
115
|
+
initialLoading: import("vue").ComputedRef<boolean>;
|
|
116
|
+
canLoadMore: import("vue").ComputedRef<boolean>;
|
|
117
|
+
loadMore: () => void;
|
|
118
|
+
virtualScroll: boolean;
|
|
119
|
+
itemHeight: number;
|
|
120
|
+
buffer: number;
|
|
114
121
|
};
|
|
@@ -81,14 +81,14 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
81
81
|
default: () => {};
|
|
82
82
|
};
|
|
83
83
|
}>> & Readonly<{}>, {
|
|
84
|
+
parentKey: string;
|
|
85
|
+
idKey: string;
|
|
86
|
+
expandedByDefault: boolean;
|
|
84
87
|
bulkActions: import("@katlux/providers").IKDatatableAction[];
|
|
85
88
|
rowActions: import("@katlux/providers").IKDatatableAction[];
|
|
86
89
|
cellSlots: Record<string, any>;
|
|
87
90
|
headerSlots: Record<string, any>;
|
|
88
91
|
treeColumnIndex: number;
|
|
89
|
-
idKey: string;
|
|
90
|
-
parentKey: string;
|
|
91
|
-
expandedByDefault: boolean;
|
|
92
92
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
93
93
|
declare const _default: typeof __VLS_export;
|
|
94
94
|
export default _default;
|
|
@@ -81,14 +81,14 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
81
81
|
default: () => {};
|
|
82
82
|
};
|
|
83
83
|
}>> & Readonly<{}>, {
|
|
84
|
+
parentKey: string;
|
|
85
|
+
idKey: string;
|
|
86
|
+
expandedByDefault: boolean;
|
|
84
87
|
bulkActions: import("@katlux/providers").IKDatatableAction[];
|
|
85
88
|
rowActions: import("@katlux/providers").IKDatatableAction[];
|
|
86
89
|
cellSlots: Record<string, any>;
|
|
87
90
|
headerSlots: Record<string, any>;
|
|
88
91
|
treeColumnIndex: number;
|
|
89
|
-
idKey: string;
|
|
90
|
-
parentKey: string;
|
|
91
|
-
expandedByDefault: boolean;
|
|
92
92
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
93
93
|
declare const _default: typeof __VLS_export;
|
|
94
94
|
export default _default;
|
|
@@ -63,7 +63,7 @@ export declare const KTreeViewDefaultProps: {
|
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
export declare function useKTreeViewLogic(props: KTreeViewProps): {
|
|
66
|
-
visibleRows: import("vue").ComputedRef<
|
|
66
|
+
visibleRows: import("vue").ComputedRef<any>;
|
|
67
67
|
expandedNodes: any;
|
|
68
68
|
selectedRows: import("vue").Ref<any[], any[]>;
|
|
69
69
|
selectAll: import("vue").Ref<boolean, boolean>;
|
|
@@ -41,11 +41,14 @@ export const KTreeViewDefaultProps = {
|
|
|
41
41
|
default: () => ({})
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
+
import { useDataProvider } from "../../composables/useDataProvider.js";
|
|
44
45
|
export function useKTreeViewLogic(props) {
|
|
46
|
+
const { pageData } = useDataProvider(props.dataProvider);
|
|
45
47
|
const selectedRows = ref([]);
|
|
46
48
|
const selectAll = ref(false);
|
|
47
49
|
const visibleRows = computed(() => {
|
|
48
|
-
|
|
50
|
+
const raw = props.dataProvider?.pageData?.value ?? props.dataProvider?.pageData ?? pageData.value;
|
|
51
|
+
return raw || [];
|
|
49
52
|
});
|
|
50
53
|
const toggleNode = (nodeId) => {
|
|
51
54
|
if (typeof props.dataProvider.toggleNode === "function") {
|
|
@@ -37,7 +37,7 @@ export function useDataProvider(provider) {
|
|
|
37
37
|
return prop;
|
|
38
38
|
};
|
|
39
39
|
const pageData = shallowRef(
|
|
40
|
-
Array.isArray(provider.pageData) ?
|
|
40
|
+
provider.pageData?.value !== void 0 ? provider.pageData.value : Array.isArray(provider.pageData) ? provider.pageData : extractVal(provider.pageData, [])
|
|
41
41
|
);
|
|
42
42
|
const rowCount = ref(extractVal(provider.rowCount, 0));
|
|
43
43
|
const currentPage = ref(extractVal(provider.currentPage, 1));
|
|
@@ -50,7 +50,7 @@ export function useDataProvider(provider) {
|
|
|
50
50
|
const selectedRows = ref(extractVal(provider.selectedRows, []));
|
|
51
51
|
const selectAll = ref(extractVal(provider.selectAll, false));
|
|
52
52
|
const syncFromProvider = () => {
|
|
53
|
-
pageData.value = Array.isArray(provider.pageData) ?
|
|
53
|
+
pageData.value = provider.pageData?.value !== void 0 ? provider.pageData.value : Array.isArray(provider.pageData) ? provider.pageData : extractVal(provider.pageData, []);
|
|
54
54
|
rowCount.value = extractVal(provider.rowCount, 0);
|
|
55
55
|
currentPage.value = extractVal(provider.currentPage, 1);
|
|
56
56
|
pageSize.value = extractVal(provider.pageSize, 10);
|
|
@@ -74,32 +74,48 @@ export function useDataProvider(provider) {
|
|
|
74
74
|
const setCurrentPage = (page) => {
|
|
75
75
|
if (typeof provider.setCurrentPage === "function") {
|
|
76
76
|
provider.setCurrentPage(page);
|
|
77
|
-
} else if (provider
|
|
78
|
-
provider.currentPage.value
|
|
77
|
+
} else if ("currentPage" in provider) {
|
|
78
|
+
if (isRef(provider.currentPage) || typeof provider.currentPage === "object" && provider.currentPage !== null && "value" in provider.currentPage) {
|
|
79
|
+
provider.currentPage.value = page;
|
|
80
|
+
} else {
|
|
81
|
+
provider.currentPage = page;
|
|
82
|
+
}
|
|
79
83
|
}
|
|
80
84
|
currentPage.value = page;
|
|
81
85
|
};
|
|
82
86
|
const setPageSize = (size) => {
|
|
83
87
|
if (typeof provider.setPageSize === "function") {
|
|
84
88
|
provider.setPageSize(size);
|
|
85
|
-
} else if (provider
|
|
86
|
-
provider.pageSize.value
|
|
89
|
+
} else if ("pageSize" in provider) {
|
|
90
|
+
if (isRef(provider.pageSize) || typeof provider.pageSize === "object" && provider.pageSize !== null && "value" in provider.pageSize) {
|
|
91
|
+
provider.pageSize.value = size;
|
|
92
|
+
} else {
|
|
93
|
+
provider.pageSize = size;
|
|
94
|
+
}
|
|
87
95
|
}
|
|
88
96
|
pageSize.value = size;
|
|
89
97
|
};
|
|
90
98
|
const setFilter = (f) => {
|
|
91
99
|
if (typeof provider.setFilter === "function") {
|
|
92
100
|
provider.setFilter(f);
|
|
93
|
-
} else if (provider
|
|
94
|
-
provider.filter.value
|
|
101
|
+
} else if ("filter" in provider) {
|
|
102
|
+
if (isRef(provider.filter) || typeof provider.filter === "object" && provider.filter !== null && "value" in provider.filter) {
|
|
103
|
+
provider.filter.value = f;
|
|
104
|
+
} else {
|
|
105
|
+
provider.filter = f;
|
|
106
|
+
}
|
|
95
107
|
}
|
|
96
108
|
filter.value = f;
|
|
97
109
|
};
|
|
98
110
|
const setSortList = (s) => {
|
|
99
111
|
if (typeof provider.setSortList === "function") {
|
|
100
112
|
provider.setSortList(s);
|
|
101
|
-
} else if (provider
|
|
102
|
-
provider.sortList.value
|
|
113
|
+
} else if ("sortList" in provider) {
|
|
114
|
+
if (isRef(provider.sortList) || typeof provider.sortList === "object" && provider.sortList !== null && "value" in provider.sortList) {
|
|
115
|
+
provider.sortList.value = s;
|
|
116
|
+
} else {
|
|
117
|
+
provider.sortList = s;
|
|
118
|
+
}
|
|
103
119
|
}
|
|
104
120
|
sortList.value = s;
|
|
105
121
|
};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { RequestQueue, type IQueuedOperation, type IDeadLetterItem } from '@katlux/providers';
|
|
2
|
+
/**
|
|
3
|
+
* useRequestQueue
|
|
4
|
+
*
|
|
5
|
+
* Idiomatic Vue 3 composable bridge for Katlux RequestQueue.
|
|
6
|
+
* Connects the pure framework-agnostic RequestQueue state to Vue 3 reactive refs.
|
|
7
|
+
*/
|
|
8
|
+
export declare function useRequestQueue(): {
|
|
9
|
+
queue: import("vue").ShallowRef<IQueuedOperation[], IQueuedOperation[]>;
|
|
10
|
+
deadLetterQueue: import("vue").ShallowRef<IDeadLetterItem[], IDeadLetterItem[]>;
|
|
11
|
+
isFlushing: import("vue").Ref<boolean, boolean>;
|
|
12
|
+
init: typeof RequestQueue.init;
|
|
13
|
+
setStorageBackend: typeof RequestQueue.setStorageBackend;
|
|
14
|
+
enqueue: typeof RequestQueue.enqueue;
|
|
15
|
+
flushAll: typeof RequestQueue.flushAll;
|
|
16
|
+
flushOne: typeof RequestQueue.flushOne;
|
|
17
|
+
retryOne: typeof RequestQueue.retryOne;
|
|
18
|
+
discard: typeof RequestQueue.discard;
|
|
19
|
+
reorder: typeof RequestQueue.reorder;
|
|
20
|
+
getQueue: typeof RequestQueue.getQueue;
|
|
21
|
+
getDeadLetterQueue: typeof RequestQueue.getDeadLetterQueue;
|
|
22
|
+
onDeadLetter: typeof RequestQueue.onDeadLetter;
|
|
23
|
+
onFlushComplete: typeof RequestQueue.onFlushComplete;
|
|
24
|
+
onNetworkError: typeof RequestQueue.onNetworkError;
|
|
25
|
+
};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { shallowRef, ref, onScopeDispose } from "vue";
|
|
2
|
+
import { RequestQueue } from "@katlux/providers";
|
|
3
|
+
export function useRequestQueue() {
|
|
4
|
+
const queue = shallowRef([...RequestQueue.queue]);
|
|
5
|
+
const deadLetterQueue = shallowRef([...RequestQueue.deadLetterQueue]);
|
|
6
|
+
const isFlushing = ref(RequestQueue.isFlushing);
|
|
7
|
+
const sync = () => {
|
|
8
|
+
queue.value = [...RequestQueue.queue];
|
|
9
|
+
deadLetterQueue.value = [...RequestQueue.deadLetterQueue];
|
|
10
|
+
isFlushing.value = RequestQueue.isFlushing;
|
|
11
|
+
};
|
|
12
|
+
const unsubscribe = RequestQueue.subscribe(sync);
|
|
13
|
+
try {
|
|
14
|
+
onScopeDispose(unsubscribe);
|
|
15
|
+
} catch {
|
|
16
|
+
}
|
|
17
|
+
return {
|
|
18
|
+
queue,
|
|
19
|
+
deadLetterQueue,
|
|
20
|
+
isFlushing,
|
|
21
|
+
init: RequestQueue.init.bind(RequestQueue),
|
|
22
|
+
setStorageBackend: RequestQueue.setStorageBackend.bind(RequestQueue),
|
|
23
|
+
enqueue: RequestQueue.enqueue.bind(RequestQueue),
|
|
24
|
+
flushAll: RequestQueue.flushAll.bind(RequestQueue),
|
|
25
|
+
flushOne: RequestQueue.flushOne.bind(RequestQueue),
|
|
26
|
+
retryOne: RequestQueue.retryOne.bind(RequestQueue),
|
|
27
|
+
discard: RequestQueue.discard.bind(RequestQueue),
|
|
28
|
+
reorder: RequestQueue.reorder.bind(RequestQueue),
|
|
29
|
+
getQueue: RequestQueue.getQueue.bind(RequestQueue),
|
|
30
|
+
getDeadLetterQueue: RequestQueue.getDeadLetterQueue.bind(RequestQueue),
|
|
31
|
+
onDeadLetter: RequestQueue.onDeadLetter.bind(RequestQueue),
|
|
32
|
+
onFlushComplete: RequestQueue.onFlushComplete.bind(RequestQueue),
|
|
33
|
+
onNetworkError: RequestQueue.onNetworkError.bind(RequestQueue)
|
|
34
|
+
};
|
|
35
|
+
}
|
|
@@ -15,6 +15,13 @@ type __VLS_Props = {
|
|
|
15
15
|
selectItem: (option: ComboboxItem) => void;
|
|
16
16
|
isSelected: (option: ComboboxItem) => boolean;
|
|
17
17
|
loading: boolean;
|
|
18
|
+
loadingMore?: boolean;
|
|
19
|
+
initialLoading?: boolean;
|
|
20
|
+
canLoadMore?: boolean;
|
|
21
|
+
loadMore?: () => void;
|
|
22
|
+
virtualScroll?: boolean;
|
|
23
|
+
itemHeight?: number;
|
|
24
|
+
buffer?: number;
|
|
18
25
|
teleportTo?: string;
|
|
19
26
|
fullWidth: boolean;
|
|
20
27
|
validation?: 'success' | 'warning' | 'error' | null;
|
|
@@ -26,6 +33,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
26
33
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
27
34
|
"onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
|
|
28
35
|
"onUpdate:searchtext"?: ((value: string) => any) | undefined;
|
|
29
|
-
}>, {
|
|
36
|
+
}>, {
|
|
37
|
+
loadingMore: boolean;
|
|
38
|
+
initialLoading: boolean;
|
|
39
|
+
canLoadMore: boolean;
|
|
40
|
+
virtualScroll: boolean;
|
|
41
|
+
itemHeight: number;
|
|
42
|
+
buffer: number;
|
|
43
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
30
44
|
declare const _default: typeof __VLS_export;
|
|
31
45
|
export default _default;
|
|
@@ -31,6 +31,13 @@
|
|
|
31
31
|
:searchPlaceholder="searchPlaceholder"
|
|
32
32
|
v-model:searchtext="searchtextModel"
|
|
33
33
|
:loading="loading"
|
|
34
|
+
:loadingMore="loadingMore"
|
|
35
|
+
:initialLoading="initialLoading"
|
|
36
|
+
:canLoadMore="canLoadMore"
|
|
37
|
+
:loadMore="loadMore"
|
|
38
|
+
:virtualScroll="virtualScroll"
|
|
39
|
+
:itemHeight="itemHeight"
|
|
40
|
+
:buffer="buffer"
|
|
34
41
|
:filteredOptions="filteredOptions"
|
|
35
42
|
:labelField="labelField"
|
|
36
43
|
:selectItem="selectItem"
|
|
@@ -46,7 +53,7 @@ const slots = useSlots()
|
|
|
46
53
|
import KComboboxList from './KComboboxList.vue'
|
|
47
54
|
import type { ComboboxItem } from '../../../../components/KCombobox/KCombobox.logic'
|
|
48
55
|
|
|
49
|
-
const props = defineProps<{
|
|
56
|
+
const props = withDefaults(defineProps<{
|
|
50
57
|
label?: string
|
|
51
58
|
disabled: boolean
|
|
52
59
|
isOptionsOpen: boolean
|
|
@@ -62,11 +69,25 @@ const props = defineProps<{
|
|
|
62
69
|
selectItem: (option: ComboboxItem) => void
|
|
63
70
|
isSelected: (option: ComboboxItem) => boolean
|
|
64
71
|
loading: boolean
|
|
72
|
+
loadingMore?: boolean
|
|
73
|
+
initialLoading?: boolean
|
|
74
|
+
canLoadMore?: boolean
|
|
75
|
+
loadMore?: () => void
|
|
76
|
+
virtualScroll?: boolean
|
|
77
|
+
itemHeight?: number
|
|
78
|
+
buffer?: number
|
|
65
79
|
teleportTo?: string
|
|
66
80
|
fullWidth: boolean
|
|
67
81
|
validation?: 'success' | 'warning' | 'error' | null
|
|
68
82
|
validationText?: string
|
|
69
|
-
}>()
|
|
83
|
+
}>(), {
|
|
84
|
+
virtualScroll: true,
|
|
85
|
+
itemHeight: 40,
|
|
86
|
+
buffer: 5,
|
|
87
|
+
loadingMore: false,
|
|
88
|
+
initialLoading: false,
|
|
89
|
+
canLoadMore: false,
|
|
90
|
+
})
|
|
70
91
|
|
|
71
92
|
const emit = defineEmits<{
|
|
72
93
|
(e: 'update:searchtext', value: string): void
|
|
@@ -15,6 +15,13 @@ type __VLS_Props = {
|
|
|
15
15
|
selectItem: (option: ComboboxItem) => void;
|
|
16
16
|
isSelected: (option: ComboboxItem) => boolean;
|
|
17
17
|
loading: boolean;
|
|
18
|
+
loadingMore?: boolean;
|
|
19
|
+
initialLoading?: boolean;
|
|
20
|
+
canLoadMore?: boolean;
|
|
21
|
+
loadMore?: () => void;
|
|
22
|
+
virtualScroll?: boolean;
|
|
23
|
+
itemHeight?: number;
|
|
24
|
+
buffer?: number;
|
|
18
25
|
teleportTo?: string;
|
|
19
26
|
fullWidth: boolean;
|
|
20
27
|
validation?: 'success' | 'warning' | 'error' | null;
|
|
@@ -26,6 +33,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
26
33
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
27
34
|
"onUpdate:isOptionsOpen"?: ((value: boolean) => any) | undefined;
|
|
28
35
|
"onUpdate:searchtext"?: ((value: string) => any) | undefined;
|
|
29
|
-
}>, {
|
|
36
|
+
}>, {
|
|
37
|
+
loadingMore: boolean;
|
|
38
|
+
initialLoading: boolean;
|
|
39
|
+
canLoadMore: boolean;
|
|
40
|
+
virtualScroll: boolean;
|
|
41
|
+
itemHeight: number;
|
|
42
|
+
buffer: number;
|
|
43
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
30
44
|
declare const _default: typeof __VLS_export;
|
|
31
45
|
export default _default;
|
|
@@ -4,6 +4,13 @@ type __VLS_Props = {
|
|
|
4
4
|
searchtext: string;
|
|
5
5
|
searchPlaceholder: string;
|
|
6
6
|
loading: boolean;
|
|
7
|
+
loadingMore?: boolean;
|
|
8
|
+
initialLoading?: boolean;
|
|
9
|
+
canLoadMore?: boolean;
|
|
10
|
+
loadMore?: () => void;
|
|
11
|
+
virtualScroll?: boolean;
|
|
12
|
+
itemHeight?: number;
|
|
13
|
+
buffer?: number;
|
|
7
14
|
filteredOptions: any[];
|
|
8
15
|
labelField: string;
|
|
9
16
|
selectItem: (option: ComboboxItem) => void;
|
|
@@ -13,6 +20,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
13
20
|
"update:searchtext": (value: string) => any;
|
|
14
21
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
15
22
|
"onUpdate:searchtext"?: ((value: string) => any) | undefined;
|
|
16
|
-
}>, {
|
|
23
|
+
}>, {
|
|
24
|
+
loadingMore: boolean;
|
|
25
|
+
initialLoading: boolean;
|
|
26
|
+
canLoadMore: boolean;
|
|
27
|
+
virtualScroll: boolean;
|
|
28
|
+
itemHeight: number;
|
|
29
|
+
buffer: number;
|
|
30
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
31
|
declare const _default: typeof __VLS_export;
|
|
18
32
|
export default _default;
|
|
@@ -1,33 +1,64 @@
|
|
|
1
1
|
<template lang="pug">
|
|
2
2
|
.KCombobox__options-content
|
|
3
3
|
KTextbox(v-if="searchbox" v-model="searchtextModel" :placeholder="searchPlaceholder" :showClear="true")
|
|
4
|
-
.KCombobox__loading(v-if="loading")
|
|
4
|
+
.KCombobox__loading(v-if="initialLoading || (loading && filteredOptions.length === 0)")
|
|
5
5
|
.KCombobox__loading-spinner
|
|
6
|
-
|
|
6
|
+
.KCombobox__empty(v-else-if="filteredOptions.length === 0")
|
|
7
|
+
span.KCombobox__empty-text {{ t('No result') }}
|
|
8
|
+
ul.KCombobox__options-list(
|
|
9
|
+
v-else
|
|
10
|
+
ref="listRef"
|
|
11
|
+
role="listbox"
|
|
12
|
+
:style="{ '--top-spacer': `${topSpacerHeight}px`, '--bottom-spacer': `${bottomSpacerHeight}px` }"
|
|
13
|
+
@scroll.passive="onScroll"
|
|
14
|
+
)
|
|
15
|
+
li.KCombobox__virtual-spacer.is-top(v-if="topSpacerHeight > 0" role="presentation")
|
|
7
16
|
li.KCombobox__options-list-item(
|
|
8
|
-
v-for="option in
|
|
9
|
-
:key="option
|
|
17
|
+
v-for="(option, index) in visibleOptions"
|
|
18
|
+
:key="getItemKey(option, startIndex + index)"
|
|
19
|
+
role="option"
|
|
20
|
+
:aria-selected="isSelected(option)"
|
|
10
21
|
@click.stop="selectItem(option)"
|
|
11
22
|
)
|
|
12
23
|
KGrid(align="center" justify="space-between" wrap="nowrap")
|
|
13
24
|
span.KCombobox__options-list-item__text {{ option[labelField] }}
|
|
14
25
|
KIcon(iconname="check" width="12" height="12" :class="{'visible': isSelected(option)}")
|
|
26
|
+
li.KCombobox__virtual-spacer.is-bottom(v-if="bottomSpacerHeight > 0" role="presentation")
|
|
27
|
+
li.KCombobox__loading-more(v-if="loadingMore" role="status")
|
|
28
|
+
.KCombobox__loading-spinner.is-small
|
|
15
29
|
</template>
|
|
16
30
|
|
|
17
31
|
<script lang="ts" setup>
|
|
18
|
-
import { computed } from 'vue'
|
|
32
|
+
import { computed, ref, onMounted, onBeforeUnmount, watch } from 'vue'
|
|
33
|
+
import { useKatluxI18n } from '#toolkit/composables/useKatluxI18n'
|
|
19
34
|
import type { ComboboxItem } from '../../../../components/KCombobox/KCombobox.logic'
|
|
20
35
|
|
|
21
|
-
const
|
|
36
|
+
const { t } = useKatluxI18n()
|
|
37
|
+
|
|
38
|
+
const props = withDefaults(defineProps<{
|
|
22
39
|
searchbox: boolean
|
|
23
40
|
searchtext: string
|
|
24
41
|
searchPlaceholder: string
|
|
25
42
|
loading: boolean
|
|
43
|
+
loadingMore?: boolean
|
|
44
|
+
initialLoading?: boolean
|
|
45
|
+
canLoadMore?: boolean
|
|
46
|
+
loadMore?: () => void
|
|
47
|
+
virtualScroll?: boolean
|
|
48
|
+
itemHeight?: number
|
|
49
|
+
buffer?: number
|
|
26
50
|
filteredOptions: any[]
|
|
27
51
|
labelField: string
|
|
28
52
|
selectItem: (option: ComboboxItem) => void
|
|
29
53
|
isSelected: (option: ComboboxItem) => boolean
|
|
30
|
-
}>()
|
|
54
|
+
}>(), {
|
|
55
|
+
virtualScroll: true,
|
|
56
|
+
itemHeight: 40,
|
|
57
|
+
buffer: 5,
|
|
58
|
+
loadingMore: false,
|
|
59
|
+
initialLoading: false,
|
|
60
|
+
canLoadMore: false,
|
|
61
|
+
})
|
|
31
62
|
|
|
32
63
|
const emit = defineEmits<{
|
|
33
64
|
(e: 'update:searchtext', value: string): void
|
|
@@ -37,6 +68,99 @@ const searchtextModel = computed({
|
|
|
37
68
|
get: () => props.searchtext,
|
|
38
69
|
set: (value) => emit('update:searchtext', value)
|
|
39
70
|
})
|
|
71
|
+
|
|
72
|
+
const listRef = ref<HTMLElement | null>(null)
|
|
73
|
+
const scrollTop = ref(0)
|
|
74
|
+
const containerHeight = ref(200)
|
|
75
|
+
|
|
76
|
+
const totalCount = computed(() => props.filteredOptions?.length || 0)
|
|
77
|
+
const itemH = computed(() => props.itemHeight || 40)
|
|
78
|
+
const buf = computed(() => props.buffer ?? 5)
|
|
79
|
+
|
|
80
|
+
const startIndex = computed(() => {
|
|
81
|
+
if (!props.virtualScroll) return 0
|
|
82
|
+
return Math.max(0, Math.floor(scrollTop.value / itemH.value) - buf.value)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
const visibleCount = computed(() => {
|
|
86
|
+
if (!props.virtualScroll) return totalCount.value
|
|
87
|
+
return Math.ceil(containerHeight.value / itemH.value) + 2 * buf.value
|
|
88
|
+
})
|
|
89
|
+
|
|
90
|
+
const endIndex = computed(() => {
|
|
91
|
+
if (!props.virtualScroll) return totalCount.value
|
|
92
|
+
return Math.min(totalCount.value, startIndex.value + visibleCount.value)
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
const visibleOptions = computed(() => {
|
|
96
|
+
if (!props.filteredOptions || props.filteredOptions.length === 0) return []
|
|
97
|
+
if (!props.virtualScroll) return props.filteredOptions
|
|
98
|
+
return props.filteredOptions.slice(startIndex.value, endIndex.value)
|
|
99
|
+
})
|
|
100
|
+
|
|
101
|
+
const topSpacerHeight = computed(() => {
|
|
102
|
+
if (!props.virtualScroll) return 0
|
|
103
|
+
return startIndex.value * itemH.value
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
const bottomSpacerHeight = computed(() => {
|
|
107
|
+
if (!props.virtualScroll) return 0
|
|
108
|
+
return Math.max(0, (totalCount.value - endIndex.value) * itemH.value)
|
|
109
|
+
})
|
|
110
|
+
|
|
111
|
+
function getItemKey(option: any, fallbackIndex: number): any {
|
|
112
|
+
if (!option) return fallbackIndex
|
|
113
|
+
if (option.id !== undefined) return option.id
|
|
114
|
+
if (option.value !== undefined) return option.value
|
|
115
|
+
if (props.labelField && option[props.labelField] !== undefined) {
|
|
116
|
+
return `${option[props.labelField]}-${fallbackIndex}`
|
|
117
|
+
}
|
|
118
|
+
return fallbackIndex
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
function onScroll(e: Event) {
|
|
122
|
+
const target = e.target as HTMLElement
|
|
123
|
+
if (!target) return
|
|
124
|
+
scrollTop.value = target.scrollTop
|
|
125
|
+
|
|
126
|
+
const threshold = 60
|
|
127
|
+
const distanceToBottom = target.scrollHeight - (target.scrollTop + target.clientHeight)
|
|
128
|
+
if (distanceToBottom <= threshold && props.canLoadMore && typeof props.loadMore === 'function') {
|
|
129
|
+
props.loadMore()
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
watch(() => props.searchtext, () => {
|
|
134
|
+
if (listRef.value) {
|
|
135
|
+
listRef.value.scrollTop = 0
|
|
136
|
+
scrollTop.value = 0
|
|
137
|
+
}
|
|
138
|
+
})
|
|
139
|
+
|
|
140
|
+
let resizeObserver: ResizeObserver | null = null
|
|
141
|
+
|
|
142
|
+
onMounted(() => {
|
|
143
|
+
if (listRef.value) {
|
|
144
|
+
containerHeight.value = listRef.value.clientHeight || 200
|
|
145
|
+
if (typeof ResizeObserver !== 'undefined') {
|
|
146
|
+
resizeObserver = new ResizeObserver((entries) => {
|
|
147
|
+
for (const entry of entries) {
|
|
148
|
+
if (entry.contentRect.height > 0) {
|
|
149
|
+
containerHeight.value = entry.contentRect.height
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
})
|
|
153
|
+
resizeObserver.observe(listRef.value)
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
})
|
|
157
|
+
|
|
158
|
+
onBeforeUnmount(() => {
|
|
159
|
+
if (resizeObserver) {
|
|
160
|
+
resizeObserver.disconnect()
|
|
161
|
+
resizeObserver = null
|
|
162
|
+
}
|
|
163
|
+
})
|
|
40
164
|
</script>
|
|
41
165
|
|
|
42
166
|
<style lang="scss" scoped>
|
|
@@ -53,6 +177,10 @@ const searchtextModel = computed({
|
|
|
53
177
|
overflow-y: auto;
|
|
54
178
|
flex: 1;
|
|
55
179
|
min-height: 0;
|
|
180
|
+
margin: 0;
|
|
181
|
+
padding: 0;
|
|
182
|
+
list-style: none;
|
|
183
|
+
|
|
56
184
|
&-item {
|
|
57
185
|
cursor: pointer;
|
|
58
186
|
height: 40px;
|
|
@@ -83,6 +211,27 @@ const searchtextModel = computed({
|
|
|
83
211
|
}
|
|
84
212
|
}
|
|
85
213
|
|
|
214
|
+
.KCombobox__virtual-spacer {
|
|
215
|
+
list-style: none;
|
|
216
|
+
padding: 0;
|
|
217
|
+
margin: 0;
|
|
218
|
+
pointer-events: none;
|
|
219
|
+
border: none;
|
|
220
|
+
&.is-top {
|
|
221
|
+
height: var(--top-spacer, 0px);
|
|
222
|
+
}
|
|
223
|
+
&.is-bottom {
|
|
224
|
+
height: var(--bottom-spacer, 0px);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.KCombobox__empty {
|
|
229
|
+
padding: var(--component-gap);
|
|
230
|
+
text-align: center;
|
|
231
|
+
color: var(--font-color-secondary);
|
|
232
|
+
font-size: var(--font-size-sm, 0.875rem);
|
|
233
|
+
}
|
|
234
|
+
|
|
86
235
|
.KCombobox__loading {
|
|
87
236
|
padding: 10px;
|
|
88
237
|
display: flex;
|
|
@@ -96,6 +245,12 @@ const searchtextModel = computed({
|
|
|
96
245
|
border-top-color: var(--primary-color-500);
|
|
97
246
|
border-radius: 50%;
|
|
98
247
|
animation: spin 0.8s linear infinite;
|
|
248
|
+
|
|
249
|
+
&.is-small {
|
|
250
|
+
width: 16px;
|
|
251
|
+
height: 16px;
|
|
252
|
+
border-width: 2px;
|
|
253
|
+
}
|
|
99
254
|
}
|
|
100
255
|
|
|
101
256
|
@keyframes spin {
|
|
@@ -104,4 +259,12 @@ const searchtextModel = computed({
|
|
|
104
259
|
}
|
|
105
260
|
}
|
|
106
261
|
}
|
|
262
|
+
|
|
263
|
+
.KCombobox__loading-more {
|
|
264
|
+
list-style: none;
|
|
265
|
+
padding: calc(var(--component-gap) / 2);
|
|
266
|
+
display: flex;
|
|
267
|
+
justify-content: center;
|
|
268
|
+
align-items: center;
|
|
269
|
+
}
|
|
107
270
|
</style>
|
|
@@ -4,6 +4,13 @@ type __VLS_Props = {
|
|
|
4
4
|
searchtext: string;
|
|
5
5
|
searchPlaceholder: string;
|
|
6
6
|
loading: boolean;
|
|
7
|
+
loadingMore?: boolean;
|
|
8
|
+
initialLoading?: boolean;
|
|
9
|
+
canLoadMore?: boolean;
|
|
10
|
+
loadMore?: () => void;
|
|
11
|
+
virtualScroll?: boolean;
|
|
12
|
+
itemHeight?: number;
|
|
13
|
+
buffer?: number;
|
|
7
14
|
filteredOptions: any[];
|
|
8
15
|
labelField: string;
|
|
9
16
|
selectItem: (option: ComboboxItem) => void;
|
|
@@ -13,6 +20,13 @@ declare const __VLS_export: import("vue").DefineComponent<__VLS_Props, {}, {}, {
|
|
|
13
20
|
"update:searchtext": (value: string) => any;
|
|
14
21
|
}, string, import("vue").PublicProps, Readonly<__VLS_Props> & Readonly<{
|
|
15
22
|
"onUpdate:searchtext"?: ((value: string) => any) | undefined;
|
|
16
|
-
}>, {
|
|
23
|
+
}>, {
|
|
24
|
+
loadingMore: boolean;
|
|
25
|
+
initialLoading: boolean;
|
|
26
|
+
canLoadMore: boolean;
|
|
27
|
+
virtualScroll: boolean;
|
|
28
|
+
itemHeight: number;
|
|
29
|
+
buffer: number;
|
|
30
|
+
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
|
|
17
31
|
declare const _default: typeof __VLS_export;
|
|
18
32
|
export default _default;
|