@katlux/toolkit 0.1.1-alpha.114 → 0.1.1-alpha.116
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 +176 -21
- package/dist/compiled/composables/useDataProvider.spec.mjs +52 -0
- package/dist/module.json +1 -1
- package/dist/runtime/components/KAccordion/KAccordion.global.d.vue.ts +23 -2
- package/dist/runtime/components/KAccordion/KAccordion.global.vue +7 -1
- package/dist/runtime/components/KAccordion/KAccordion.global.vue.d.ts +23 -2
- package/dist/runtime/components/KAccordion/KAccordion.logic.d.ts +12 -1
- package/dist/runtime/components/KAccordion/KAccordion.logic.js +32 -4
- package/dist/runtime/components/KAlert/KAlert.global.d.vue.ts +4 -1
- package/dist/runtime/components/KAlert/KAlert.global.vue +8 -2
- package/dist/runtime/components/KAlert/KAlert.global.vue.d.ts +4 -1
- package/dist/runtime/components/KAlert/KAlert.logic.d.ts +6 -1
- package/dist/runtime/components/KAlert/KAlert.logic.js +12 -2
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCalendar/KCalendar.global.d.vue.ts +11 -0
- package/dist/runtime/components/KCalendar/KCalendar.global.vue +1 -1
- package/dist/runtime/components/KCalendar/KCalendar.global.vue.d.ts +11 -0
- package/dist/runtime/components/KCalendar/KCalendar.logic.d.ts +6 -0
- package/dist/runtime/components/KCalendar/KCalendar.logic.js +13 -4
- 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 +38 -3
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +11 -2
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +38 -3
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +18 -0
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +24 -2
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +7 -7
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +7 -7
- package/dist/runtime/components/KCompositeInput/KCompositeInput.logic.d.ts +3 -3
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +29 -1
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +29 -4
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +29 -1
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +21 -2
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +66 -31
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +35 -3
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +44 -4
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +35 -3
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +27 -2
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +77 -5
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +6 -6
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +6 -6
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +2 -2
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.d.vue.ts +6 -6
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.global.vue.d.ts +6 -6
- package/dist/runtime/components/KDateTimePicker/KDateTimePicker.logic.d.ts +2 -2
- package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +8 -8
- package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +8 -8
- package/dist/runtime/components/KGantt/KGantt.logic.d.ts +4 -4
- package/dist/runtime/components/KHourPicker/KHourPicker.global.d.vue.ts +2 -2
- package/dist/runtime/components/KHourPicker/KHourPicker.global.vue.d.ts +2 -2
- package/dist/runtime/components/KHourSelect/KHourSelect.global.d.vue.ts +1 -1
- package/dist/runtime/components/KHourSelect/KHourSelect.global.vue.d.ts +1 -1
- package/dist/runtime/components/KLayout/KLayout.global.d.vue.ts +3 -0
- package/dist/runtime/components/KLayout/KLayout.global.vue +11 -0
- package/dist/runtime/components/KLayout/KLayout.global.vue.d.ts +3 -0
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.d.vue.ts +2 -2
- package/dist/runtime/components/KMaskTextbox/KMaskTextbox.global.vue.d.ts +2 -2
- package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +24 -2
- package/dist/runtime/components/KPagination/KPagination.global.vue +8 -2
- package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +24 -2
- package/dist/runtime/components/KPagination/KPagination.logic.d.ts +18 -4
- package/dist/runtime/components/KPagination/KPagination.logic.js +59 -10
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +15 -4
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue +22 -4
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +15 -4
- package/dist/runtime/components/KRangeSlider/KRangeSlider.logic.d.ts +6 -0
- package/dist/runtime/components/KRangeSlider/KRangeSlider.logic.js +12 -6
- package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +13 -2
- package/dist/runtime/components/KSlider/KSlider.global.vue +9 -3
- package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +13 -2
- package/dist/runtime/components/KSlider/KSlider.logic.d.ts +5 -0
- package/dist/runtime/components/KSlider/KSlider.logic.js +5 -1
- package/dist/runtime/components/KTabs/KTabItem.global.d.vue.ts +18 -0
- package/dist/runtime/components/KTabs/KTabItem.global.vue.d.ts +18 -0
- package/dist/runtime/components/KTabs/KTabItem.logic.d.ts +11 -0
- package/dist/runtime/components/KTabs/KTabItem.logic.js +10 -1
- package/dist/runtime/components/KTabs/KTabs.global.d.vue.ts +34 -1
- package/dist/runtime/components/KTabs/KTabs.global.vue +10 -1
- package/dist/runtime/components/KTabs/KTabs.global.vue.d.ts +34 -1
- package/dist/runtime/components/KTabs/KTabs.logic.d.ts +21 -2
- package/dist/runtime/components/KTabs/KTabs.logic.js +86 -3
- package/dist/runtime/components/KTextarea/KTextarea.global.d.vue.ts +1 -1
- package/dist/runtime/components/KTextarea/KTextarea.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTextbox/KTextbox.global.d.vue.ts +3 -3
- package/dist/runtime/components/KTextbox/KTextbox.global.vue.d.ts +3 -3
- package/dist/runtime/components/KToast/KToast.global.d.vue.ts +3 -3
- package/dist/runtime/components/KToast/KToast.global.vue.d.ts +3 -3
- package/dist/runtime/components/KTree/KTree.global.d.vue.ts +48 -2
- package/dist/runtime/components/KTree/KTree.global.vue +13 -2
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +48 -2
- package/dist/runtime/components/KTree/KTree.logic.d.ts +26 -2
- package/dist/runtime/components/KTree/KTree.logic.js +41 -6
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +26 -4
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +1 -1
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +26 -4
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.d.ts +16 -0
- package/dist/runtime/components/KTreePicker/KTreePicker.logic.js +8 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +4 -0
- package/dist/runtime/components/KTreeView/KTreeView.global.vue +5 -2
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +4 -0
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +4 -1
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +7 -1
- package/dist/runtime/composables/useDataProvider.d.ts +15 -4
- package/dist/runtime/composables/useDataProvider.js +176 -21
- package/dist/runtime/presets/default/assets/scss/css-variables.css +1 -0
- package/dist/runtime/presets/default/assets/scss/css-variables.scss +1 -0
- package/dist/runtime/presets/default/assets/scss/index.css +5 -3
- package/dist/runtime/presets/default/assets/scss/index.scss +4 -3
- package/dist/runtime/presets/default/components/KAlert/KAlert.d.vue.ts +3 -1
- package/dist/runtime/presets/default/components/KAlert/KAlert.vue +3 -3
- package/dist/runtime/presets/default/components/KAlert/KAlert.vue.d.ts +3 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +6 -0
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +5 -1
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +6 -0
- package/dist/runtime/presets/default/components/KLayout/KLayout.d.vue.ts +3 -0
- package/dist/runtime/presets/default/components/KLayout/KLayout.vue +66 -0
- package/dist/runtime/presets/default/components/KLayout/KLayout.vue.d.ts +3 -0
- package/dist/runtime/presets/default/components/KRangeSlider/KRangeSlider.vue +9 -0
- package/dist/runtime/presets/default/components/KSlider/KSlider.vue +9 -0
- package/dist/runtime/presets/default/components/KToast/KToast.d.vue.ts +2 -2
- package/dist/runtime/presets/default/components/KToast/KToast.vue.d.ts +2 -2
- package/package.json +1 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ref, shallowRef, onScopeDispose, isRef, watch } from "vue";
|
|
2
|
-
export function useDataProvider(provider) {
|
|
2
|
+
export function useDataProvider(provider, options) {
|
|
3
3
|
const resolveProvider = () => {
|
|
4
4
|
if (typeof provider === "function") return provider();
|
|
5
5
|
return isRef(provider) ? provider.value : provider;
|
|
@@ -16,15 +16,17 @@ export function useDataProvider(provider) {
|
|
|
16
16
|
activeProvider ? activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []) : []
|
|
17
17
|
);
|
|
18
18
|
const rowCount = ref(activeProvider ? extractVal(activeProvider.rowCount, 0) : 0);
|
|
19
|
-
const currentPage = ref(activeProvider ? extractVal(activeProvider.currentPage, 1) : 1);
|
|
20
|
-
const pageSize = ref(activeProvider ? extractVal(activeProvider.pageSize, 10) : 10);
|
|
19
|
+
const currentPage = options?.currentPage || ref(activeProvider ? extractVal(activeProvider.currentPage, 1) : 1);
|
|
20
|
+
const pageSize = options?.pageSize || ref(activeProvider ? extractVal(activeProvider.pageSize, 10) : 10);
|
|
21
21
|
const loading = ref(activeProvider ? extractVal(activeProvider.loading, false) : false);
|
|
22
22
|
const initialLoad = ref(activeProvider ? extractVal(activeProvider.initialLoad, false) : false);
|
|
23
23
|
const error = ref(activeProvider ? extractVal(activeProvider.error, null) : null);
|
|
24
|
-
const filter = ref(activeProvider ? extractVal(activeProvider.filter, null) : null);
|
|
25
|
-
const sortList = ref(activeProvider ? extractVal(activeProvider.sortList, []) : []);
|
|
26
|
-
const selectedRows = ref(activeProvider ? extractVal(activeProvider.selectedRows, []) : []);
|
|
27
|
-
const selectAll = ref(activeProvider ? extractVal(activeProvider.selectAll, false) : false);
|
|
24
|
+
const filter = options?.filter || ref(activeProvider ? extractVal(activeProvider.filter, null) : null);
|
|
25
|
+
const sortList = options?.sortList || ref(activeProvider ? extractVal(activeProvider.sortList, []) : []);
|
|
26
|
+
const selectedRows = options?.selectedRows || ref(activeProvider ? extractVal(activeProvider.selectedRows, []) : []);
|
|
27
|
+
const selectAll = options?.selectAll || ref(activeProvider ? extractVal(activeProvider.selectAll, false) : false);
|
|
28
|
+
let isSyncingFromProvider = false;
|
|
29
|
+
let isSyncingToProvider = false;
|
|
28
30
|
const syncFromProvider = () => {
|
|
29
31
|
if (!activeProvider) {
|
|
30
32
|
pageData.value = [];
|
|
@@ -40,17 +42,40 @@ export function useDataProvider(provider) {
|
|
|
40
42
|
selectAll.value = false;
|
|
41
43
|
return;
|
|
42
44
|
}
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
45
|
+
isSyncingFromProvider = true;
|
|
46
|
+
try {
|
|
47
|
+
pageData.value = activeProvider.pageData?.value !== void 0 ? activeProvider.pageData.value : Array.isArray(activeProvider.pageData) ? activeProvider.pageData : extractVal(activeProvider.pageData, []);
|
|
48
|
+
rowCount.value = extractVal(activeProvider.rowCount, 0);
|
|
49
|
+
const newPage = extractVal(activeProvider.currentPage, 1);
|
|
50
|
+
if (currentPage.value !== newPage) {
|
|
51
|
+
currentPage.value = newPage;
|
|
52
|
+
}
|
|
53
|
+
const newSize = extractVal(activeProvider.pageSize, 10);
|
|
54
|
+
if (pageSize.value !== newSize) {
|
|
55
|
+
pageSize.value = newSize;
|
|
56
|
+
}
|
|
57
|
+
loading.value = extractVal(activeProvider.loading, false);
|
|
58
|
+
initialLoad.value = extractVal(activeProvider.initialLoad, false);
|
|
59
|
+
error.value = extractVal(activeProvider.error, null);
|
|
60
|
+
const newFilter = extractVal(activeProvider.filter, null);
|
|
61
|
+
if (JSON.stringify(filter.value) !== JSON.stringify(newFilter)) {
|
|
62
|
+
filter.value = newFilter;
|
|
63
|
+
}
|
|
64
|
+
const newSort = extractVal(activeProvider.sortList, []);
|
|
65
|
+
if (JSON.stringify(sortList.value) !== JSON.stringify(newSort)) {
|
|
66
|
+
sortList.value = newSort;
|
|
67
|
+
}
|
|
68
|
+
const newSelected = extractVal(activeProvider.selectedRows, []);
|
|
69
|
+
if (selectedRows.value !== newSelected) {
|
|
70
|
+
selectedRows.value = newSelected;
|
|
71
|
+
}
|
|
72
|
+
const newSelectAll = extractVal(activeProvider.selectAll, false);
|
|
73
|
+
if (selectAll.value !== newSelectAll) {
|
|
74
|
+
selectAll.value = newSelectAll;
|
|
75
|
+
}
|
|
76
|
+
} finally {
|
|
77
|
+
isSyncingFromProvider = false;
|
|
78
|
+
}
|
|
54
79
|
};
|
|
55
80
|
let unsubscribe = null;
|
|
56
81
|
const attachListener = () => {
|
|
@@ -146,6 +171,104 @@ export function useDataProvider(provider) {
|
|
|
146
171
|
}
|
|
147
172
|
sortList.value = s;
|
|
148
173
|
};
|
|
174
|
+
if (options?.currentPage) {
|
|
175
|
+
if (options.currentPage.value !== void 0 && options.currentPage.value !== extractVal(activeProvider?.currentPage, 1)) {
|
|
176
|
+
setCurrentPage(options.currentPage.value);
|
|
177
|
+
}
|
|
178
|
+
watch(options.currentPage, (newVal) => {
|
|
179
|
+
if (isSyncingFromProvider || isSyncingToProvider) return;
|
|
180
|
+
if (activeProvider && extractVal(activeProvider.currentPage, 1) !== newVal) {
|
|
181
|
+
isSyncingToProvider = true;
|
|
182
|
+
try {
|
|
183
|
+
setCurrentPage(newVal);
|
|
184
|
+
} finally {
|
|
185
|
+
isSyncingToProvider = false;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
if (options?.pageSize) {
|
|
191
|
+
if (options.pageSize.value !== void 0 && options.pageSize.value !== extractVal(activeProvider?.pageSize, 10)) {
|
|
192
|
+
setPageSize(options.pageSize.value);
|
|
193
|
+
}
|
|
194
|
+
watch(options.pageSize, (newVal) => {
|
|
195
|
+
if (isSyncingFromProvider || isSyncingToProvider) return;
|
|
196
|
+
if (activeProvider && extractVal(activeProvider.pageSize, 10) !== newVal) {
|
|
197
|
+
isSyncingToProvider = true;
|
|
198
|
+
try {
|
|
199
|
+
setPageSize(newVal);
|
|
200
|
+
} finally {
|
|
201
|
+
isSyncingToProvider = false;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
});
|
|
205
|
+
}
|
|
206
|
+
if (options?.filter) {
|
|
207
|
+
if (options.filter.value !== void 0 && options.filter.value !== null) {
|
|
208
|
+
setFilter(options.filter.value);
|
|
209
|
+
}
|
|
210
|
+
watch(options.filter, (newVal) => {
|
|
211
|
+
if (isSyncingFromProvider || isSyncingToProvider) return;
|
|
212
|
+
if (activeProvider && JSON.stringify(extractVal(activeProvider.filter, null)) !== JSON.stringify(newVal)) {
|
|
213
|
+
isSyncingToProvider = true;
|
|
214
|
+
try {
|
|
215
|
+
setFilter(newVal);
|
|
216
|
+
} finally {
|
|
217
|
+
isSyncingToProvider = false;
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}, { deep: true });
|
|
221
|
+
}
|
|
222
|
+
if (options?.sortList) {
|
|
223
|
+
if (options.sortList.value !== void 0 && options.sortList.value.length > 0) {
|
|
224
|
+
setSortList(options.sortList.value);
|
|
225
|
+
}
|
|
226
|
+
watch(options.sortList, (newVal) => {
|
|
227
|
+
if (isSyncingFromProvider || isSyncingToProvider) return;
|
|
228
|
+
if (activeProvider && JSON.stringify(extractVal(activeProvider.sortList, [])) !== JSON.stringify(newVal)) {
|
|
229
|
+
isSyncingToProvider = true;
|
|
230
|
+
try {
|
|
231
|
+
setSortList(newVal);
|
|
232
|
+
} finally {
|
|
233
|
+
isSyncingToProvider = false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}, { deep: true });
|
|
237
|
+
}
|
|
238
|
+
if (options?.selectedRows) {
|
|
239
|
+
watch(options.selectedRows, (newVal) => {
|
|
240
|
+
if (isSyncingFromProvider || isSyncingToProvider) return;
|
|
241
|
+
if (activeProvider) {
|
|
242
|
+
isSyncingToProvider = true;
|
|
243
|
+
try {
|
|
244
|
+
if (typeof activeProvider.setSelectedRows === "function") {
|
|
245
|
+
activeProvider.setSelectedRows(newVal);
|
|
246
|
+
} else {
|
|
247
|
+
activeProvider.selectedRows = newVal;
|
|
248
|
+
}
|
|
249
|
+
} finally {
|
|
250
|
+
isSyncingToProvider = false;
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
}, { deep: true });
|
|
254
|
+
}
|
|
255
|
+
if (options?.selectAll) {
|
|
256
|
+
watch(options.selectAll, (newVal) => {
|
|
257
|
+
if (isSyncingFromProvider || isSyncingToProvider) return;
|
|
258
|
+
if (activeProvider && extractVal(activeProvider.selectAll, false) !== newVal) {
|
|
259
|
+
isSyncingToProvider = true;
|
|
260
|
+
try {
|
|
261
|
+
if (typeof activeProvider.setSelectAll === "function") {
|
|
262
|
+
activeProvider.setSelectAll(newVal);
|
|
263
|
+
} else {
|
|
264
|
+
activeProvider.selectAll = newVal;
|
|
265
|
+
}
|
|
266
|
+
} finally {
|
|
267
|
+
isSyncingToProvider = false;
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
});
|
|
271
|
+
}
|
|
149
272
|
const refresh = async (hardRefresh = false) => {
|
|
150
273
|
if (!activeProvider) return;
|
|
151
274
|
if (typeof activeProvider.refresh === "function") {
|
|
@@ -155,13 +278,43 @@ export function useDataProvider(provider) {
|
|
|
155
278
|
}
|
|
156
279
|
syncFromProvider();
|
|
157
280
|
};
|
|
158
|
-
const loadPageData = (
|
|
281
|
+
const loadPageData = (options2) => {
|
|
159
282
|
if (!activeProvider) return;
|
|
160
283
|
if (typeof activeProvider.loadPageData === "function") {
|
|
161
|
-
activeProvider.loadPageData(
|
|
284
|
+
activeProvider.loadPageData(options2);
|
|
162
285
|
}
|
|
163
286
|
syncFromProvider();
|
|
164
287
|
};
|
|
288
|
+
const getState = () => {
|
|
289
|
+
if (activeProvider && typeof activeProvider.getState === "function") {
|
|
290
|
+
return activeProvider.getState();
|
|
291
|
+
}
|
|
292
|
+
return {
|
|
293
|
+
pageData: pageData.value,
|
|
294
|
+
rowCount: rowCount.value,
|
|
295
|
+
currentPage: currentPage.value,
|
|
296
|
+
pageSize: pageSize.value,
|
|
297
|
+
loading: loading.value,
|
|
298
|
+
initialLoad: initialLoad.value,
|
|
299
|
+
error: error.value,
|
|
300
|
+
filter: filter.value,
|
|
301
|
+
sortList: sortList.value,
|
|
302
|
+
selectedRows: selectedRows.value,
|
|
303
|
+
selectAll: selectAll.value
|
|
304
|
+
};
|
|
305
|
+
};
|
|
306
|
+
const setState = (partial) => {
|
|
307
|
+
if (activeProvider && typeof activeProvider.setState === "function") {
|
|
308
|
+
activeProvider.setState(partial);
|
|
309
|
+
} else {
|
|
310
|
+
if (partial.currentPage !== void 0) setCurrentPage(partial.currentPage);
|
|
311
|
+
if (partial.pageSize !== void 0) setPageSize(partial.pageSize);
|
|
312
|
+
if (partial.filter !== void 0) setFilter(partial.filter);
|
|
313
|
+
if (partial.sortList !== void 0) setSortList(partial.sortList);
|
|
314
|
+
if (partial.selectedRows !== void 0) selectedRows.value = partial.selectedRows;
|
|
315
|
+
if (partial.selectAll !== void 0) selectAll.value = partial.selectAll;
|
|
316
|
+
}
|
|
317
|
+
};
|
|
165
318
|
return {
|
|
166
319
|
get rawProvider() {
|
|
167
320
|
return activeProvider;
|
|
@@ -182,6 +335,8 @@ export function useDataProvider(provider) {
|
|
|
182
335
|
setFilter,
|
|
183
336
|
setSortList,
|
|
184
337
|
refresh,
|
|
185
|
-
loadPageData
|
|
338
|
+
loadPageData,
|
|
339
|
+
getState,
|
|
340
|
+
setState
|
|
186
341
|
};
|
|
187
342
|
}
|
|
@@ -102,4 +102,56 @@ describe("useDataProvider Composable Adapter", () => {
|
|
|
102
102
|
});
|
|
103
103
|
scope.stop();
|
|
104
104
|
});
|
|
105
|
+
it("should support two-way binding with external reactive refs (Pinia-ready pattern)", async () => {
|
|
106
|
+
const provider = new CFlatClientDataProvider({ pageSize: 2 });
|
|
107
|
+
provider.setData([
|
|
108
|
+
{ id: 1, name: "Item 1" },
|
|
109
|
+
{ id: 2, name: "Item 2" },
|
|
110
|
+
{ id: 3, name: "Item 3" },
|
|
111
|
+
{ id: 4, name: "Item 4" }
|
|
112
|
+
]);
|
|
113
|
+
const externalPage = ref(1);
|
|
114
|
+
const externalPageSize = ref(2);
|
|
115
|
+
const externalSelected = ref([]);
|
|
116
|
+
const scope = effectScope();
|
|
117
|
+
await scope.run(async () => {
|
|
118
|
+
const { pageData, currentPage, pageSize } = useDataProvider(provider, {
|
|
119
|
+
currentPage: externalPage,
|
|
120
|
+
pageSize: externalPageSize,
|
|
121
|
+
selectedRows: externalSelected
|
|
122
|
+
});
|
|
123
|
+
expect(currentPage.value).toBe(1);
|
|
124
|
+
expect(pageData.value[0].id).toBe(1);
|
|
125
|
+
externalPage.value = 2;
|
|
126
|
+
await nextTick();
|
|
127
|
+
expect(provider.currentPage).toBe(2);
|
|
128
|
+
expect(pageData.value[0].id).toBe(3);
|
|
129
|
+
provider.setCurrentPage(1);
|
|
130
|
+
await nextTick();
|
|
131
|
+
expect(externalPage.value).toBe(1);
|
|
132
|
+
expect(pageData.value[0].id).toBe(1);
|
|
133
|
+
externalSelected.value = [{ id: 1, name: "Item 1" }];
|
|
134
|
+
await nextTick();
|
|
135
|
+
expect(provider.selectedRows).toEqual([{ id: 1, name: "Item 1" }]);
|
|
136
|
+
externalPageSize.value = 4;
|
|
137
|
+
await nextTick();
|
|
138
|
+
expect(provider.pageSize).toBe(4);
|
|
139
|
+
expect(pageData.value.length).toBe(4);
|
|
140
|
+
});
|
|
141
|
+
scope.stop();
|
|
142
|
+
});
|
|
143
|
+
it("should expose getState() and setState() helpers", () => {
|
|
144
|
+
const provider = new CFlatClientDataProvider({ pageSize: 5 });
|
|
145
|
+
provider.setData([{ id: 10 }, { id: 20 }, { id: 30 }]);
|
|
146
|
+
const scope = effectScope();
|
|
147
|
+
scope.run(() => {
|
|
148
|
+
const { getState, setState, currentPage, pageSize } = useDataProvider(provider);
|
|
149
|
+
expect(getState().rowCount).toBe(3);
|
|
150
|
+
expect(getState().currentPage).toBe(1);
|
|
151
|
+
setState({ currentPage: 2, pageSize: 2 });
|
|
152
|
+
expect(currentPage.value).toBe(2);
|
|
153
|
+
expect(pageSize.value).toBe(2);
|
|
154
|
+
});
|
|
155
|
+
scope.stop();
|
|
156
|
+
});
|
|
105
157
|
});
|
package/dist/module.json
CHANGED
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
2
|
multiOpen: {
|
|
3
3
|
type: BooleanConstructor;
|
|
4
|
+
default: boolean;
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
modelValue: {
|
|
7
|
+
type: import("vue").PropType<string | string[] | number | number[]>;
|
|
8
|
+
default: undefined;
|
|
9
|
+
};
|
|
10
|
+
}>, {
|
|
11
|
+
openIds: import("vue").Ref<string[], string[]>;
|
|
12
|
+
toggleItem: (id: string) => void;
|
|
13
|
+
isOpen: (id: string) => boolean;
|
|
14
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
15
|
+
"update:modelValue": (value: any) => any;
|
|
16
|
+
change: (value: any) => any;
|
|
17
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
6
18
|
multiOpen: {
|
|
7
19
|
type: BooleanConstructor;
|
|
20
|
+
default: boolean;
|
|
21
|
+
};
|
|
22
|
+
modelValue: {
|
|
23
|
+
type: import("vue").PropType<string | string[] | number | number[]>;
|
|
24
|
+
default: undefined;
|
|
8
25
|
};
|
|
9
|
-
}>> & Readonly<{
|
|
26
|
+
}>> & Readonly<{
|
|
27
|
+
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
28
|
+
onChange?: ((value: any) => any) | undefined;
|
|
29
|
+
}>, {
|
|
10
30
|
multiOpen: boolean;
|
|
31
|
+
modelValue: string | number | string[] | number[];
|
|
11
32
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
12
33
|
declare const _default: typeof __VLS_export;
|
|
13
34
|
export default _default;
|
|
@@ -4,7 +4,13 @@ import { usePresetComponent } from "../../composables/usePresetComponent";
|
|
|
4
4
|
import { computed } from "vue";
|
|
5
5
|
import KAccordionDefault from "../../presets/default/components/KAccordion/KAccordion.vue";
|
|
6
6
|
const props = defineProps(KAccordionDefaultProps);
|
|
7
|
-
|
|
7
|
+
const emit = defineEmits(["update:modelValue", "change"]);
|
|
8
|
+
const { openIds, toggleItem, isOpen } = useKAccordionLogic(props, emit);
|
|
9
|
+
defineExpose({
|
|
10
|
+
openIds,
|
|
11
|
+
toggleItem,
|
|
12
|
+
isOpen
|
|
13
|
+
});
|
|
8
14
|
const presetComponent = usePresetComponent("KAccordion", KAccordionDefault);
|
|
9
15
|
</script>
|
|
10
16
|
|
|
@@ -1,13 +1,34 @@
|
|
|
1
1
|
declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractPropTypes<{
|
|
2
2
|
multiOpen: {
|
|
3
3
|
type: BooleanConstructor;
|
|
4
|
+
default: boolean;
|
|
4
5
|
};
|
|
5
|
-
|
|
6
|
+
modelValue: {
|
|
7
|
+
type: import("vue").PropType<string | string[] | number | number[]>;
|
|
8
|
+
default: undefined;
|
|
9
|
+
};
|
|
10
|
+
}>, {
|
|
11
|
+
openIds: import("vue").Ref<string[], string[]>;
|
|
12
|
+
toggleItem: (id: string) => void;
|
|
13
|
+
isOpen: (id: string) => boolean;
|
|
14
|
+
}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
15
|
+
"update:modelValue": (value: any) => any;
|
|
16
|
+
change: (value: any) => any;
|
|
17
|
+
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
6
18
|
multiOpen: {
|
|
7
19
|
type: BooleanConstructor;
|
|
20
|
+
default: boolean;
|
|
21
|
+
};
|
|
22
|
+
modelValue: {
|
|
23
|
+
type: import("vue").PropType<string | string[] | number | number[]>;
|
|
24
|
+
default: undefined;
|
|
8
25
|
};
|
|
9
|
-
}>> & Readonly<{
|
|
26
|
+
}>> & Readonly<{
|
|
27
|
+
"onUpdate:modelValue"?: ((value: any) => any) | undefined;
|
|
28
|
+
onChange?: ((value: any) => any) | undefined;
|
|
29
|
+
}>, {
|
|
10
30
|
multiOpen: boolean;
|
|
31
|
+
modelValue: string | number | string[] | number[];
|
|
11
32
|
}, {}, {}, {}, string, import("vue").ComponentProvideOptions, true, {}, any>;
|
|
12
33
|
declare const _default: typeof __VLS_export;
|
|
13
34
|
export default _default;
|
|
@@ -1,12 +1,23 @@
|
|
|
1
|
+
import { type PropType } from 'vue';
|
|
1
2
|
export interface KAccordionProps {
|
|
2
3
|
multiOpen?: boolean;
|
|
4
|
+
modelValue?: string | string[] | number | number[];
|
|
3
5
|
}
|
|
4
6
|
export declare const KAccordionDefaultProps: {
|
|
5
7
|
multiOpen: {
|
|
6
8
|
type: BooleanConstructor;
|
|
9
|
+
default: boolean;
|
|
10
|
+
};
|
|
11
|
+
modelValue: {
|
|
12
|
+
type: PropType<string | string[] | number | number[]>;
|
|
13
|
+
default: undefined;
|
|
7
14
|
};
|
|
8
15
|
};
|
|
9
|
-
export
|
|
16
|
+
export interface KAccordionEmits {
|
|
17
|
+
(e: 'update:modelValue', value: any): void;
|
|
18
|
+
(e: 'change', value: any): void;
|
|
19
|
+
}
|
|
20
|
+
export declare function useKAccordionLogic(props?: KAccordionProps, emit?: KAccordionEmits): {
|
|
10
21
|
openIds: import("vue").Ref<string[], string[]>;
|
|
11
22
|
toggleItem: (id: string) => void;
|
|
12
23
|
isOpen: (id: string) => boolean;
|
|
@@ -1,12 +1,34 @@
|
|
|
1
|
-
import { ref, provide } from "vue";
|
|
1
|
+
import { ref, provide, watch } from "vue";
|
|
2
2
|
export const KAccordionDefaultProps = {
|
|
3
3
|
multiOpen: {
|
|
4
|
-
type: Boolean
|
|
4
|
+
type: Boolean,
|
|
5
|
+
default: false
|
|
6
|
+
},
|
|
7
|
+
modelValue: {
|
|
8
|
+
type: [String, Number, Array],
|
|
9
|
+
default: void 0
|
|
5
10
|
}
|
|
6
11
|
};
|
|
7
|
-
export function useKAccordionLogic(props) {
|
|
8
|
-
|
|
12
|
+
export function useKAccordionLogic(props = {}, emit) {
|
|
13
|
+
function parseModelValue(val) {
|
|
14
|
+
if (val === void 0 || val === null) return [];
|
|
15
|
+
if (Array.isArray(val)) return val.map(String);
|
|
16
|
+
return [String(val)];
|
|
17
|
+
}
|
|
18
|
+
const openIds = ref(parseModelValue(props.modelValue));
|
|
9
19
|
const items = ref(/* @__PURE__ */ new Map());
|
|
20
|
+
watch(
|
|
21
|
+
() => props.modelValue,
|
|
22
|
+
(newVal) => {
|
|
23
|
+
if (newVal !== void 0) {
|
|
24
|
+
const parsed = parseModelValue(newVal);
|
|
25
|
+
if (JSON.stringify(parsed) !== JSON.stringify(openIds.value)) {
|
|
26
|
+
openIds.value = parsed;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
{ deep: true }
|
|
31
|
+
);
|
|
10
32
|
function registerItem(id, item) {
|
|
11
33
|
items.value.set(id, item);
|
|
12
34
|
return () => {
|
|
@@ -20,12 +42,18 @@ export function useKAccordionLogic(props) {
|
|
|
20
42
|
} else {
|
|
21
43
|
openIds.value.push(id);
|
|
22
44
|
}
|
|
45
|
+
const emitted = Array.isArray(props.modelValue) ? [...openIds.value] : openIds.value;
|
|
46
|
+
emit?.("update:modelValue", emitted);
|
|
47
|
+
emit?.("change", emitted);
|
|
23
48
|
} else {
|
|
24
49
|
if (openIds.value[0] === id) {
|
|
25
50
|
openIds.value = [];
|
|
26
51
|
} else {
|
|
27
52
|
openIds.value = [id];
|
|
28
53
|
}
|
|
54
|
+
const emitted = Array.isArray(props.modelValue) ? [...openIds.value] : openIds.value[0] ?? null;
|
|
55
|
+
emit?.("update:modelValue", emitted);
|
|
56
|
+
emit?.("change", emitted);
|
|
29
57
|
}
|
|
30
58
|
}
|
|
31
59
|
function isOpen(id) {
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { KAlertProps } from './KAlert.logic.js';
|
|
2
|
-
declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
2
|
+
declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
3
|
+
"update:modelValue": (value: boolean) => any;
|
|
3
4
|
dismiss: () => any;
|
|
4
5
|
}, string, import("vue").PublicProps, Readonly<KAlertProps> & Readonly<{
|
|
6
|
+
"onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
|
|
5
7
|
onDismiss?: (() => any) | undefined;
|
|
6
8
|
}>, {
|
|
9
|
+
modelValue: boolean;
|
|
7
10
|
type: import("./KAlert.logic.js").KAlertType;
|
|
8
11
|
dismissible: boolean;
|
|
9
12
|
hideIcon: boolean;
|
|
@@ -3,17 +3,23 @@ import { usePresetComponent } from "../../composables/usePresetComponent";
|
|
|
3
3
|
import KAlertDefault from "../../presets/default/components/KAlert/KAlert.vue";
|
|
4
4
|
import { KAlertDefaultProps } from "./KAlert.logic";
|
|
5
5
|
const props = defineProps({
|
|
6
|
+
modelValue: { type: Boolean, required: false, default: true },
|
|
6
7
|
type: { type: String, required: false, default: "info" },
|
|
7
8
|
title: { type: String, required: false },
|
|
8
9
|
dismissible: { type: Boolean, required: false, default: false },
|
|
9
10
|
icon: { type: String, required: false },
|
|
10
11
|
hideIcon: { type: Boolean, required: false, default: false }
|
|
11
12
|
});
|
|
12
|
-
const emit = defineEmits(["dismiss"]);
|
|
13
|
+
const emit = defineEmits(["update:modelValue", "dismiss"]);
|
|
13
14
|
const presetComponent = usePresetComponent("KAlert", KAlertDefault);
|
|
14
15
|
</script>
|
|
15
16
|
|
|
16
17
|
<template lang="pug">
|
|
17
|
-
component(
|
|
18
|
+
component(
|
|
19
|
+
:is="presetComponent"
|
|
20
|
+
v-bind="props"
|
|
21
|
+
@update:modelValue="emit('update:modelValue', $event)"
|
|
22
|
+
@dismiss="emit('dismiss')"
|
|
23
|
+
)
|
|
18
24
|
slot
|
|
19
25
|
</template>
|
|
@@ -1,9 +1,12 @@
|
|
|
1
1
|
import type { KAlertProps } from './KAlert.logic.js';
|
|
2
|
-
declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {
|
|
2
|
+
declare const __VLS_export: import("vue").DefineComponent<KAlertProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
3
|
+
"update:modelValue": (value: boolean) => any;
|
|
3
4
|
dismiss: () => any;
|
|
4
5
|
}, string, import("vue").PublicProps, Readonly<KAlertProps> & Readonly<{
|
|
6
|
+
"onUpdate:modelValue"?: ((value: boolean) => any) | undefined;
|
|
5
7
|
onDismiss?: (() => any) | undefined;
|
|
6
8
|
}>, {
|
|
9
|
+
modelValue: boolean;
|
|
7
10
|
type: import("./KAlert.logic.js").KAlertType;
|
|
8
11
|
dismissible: boolean;
|
|
9
12
|
hideIcon: boolean;
|
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
export type KAlertType = 'info' | 'success' | 'warning' | 'danger';
|
|
2
2
|
export interface KAlertProps {
|
|
3
|
+
modelValue?: boolean;
|
|
3
4
|
type?: KAlertType;
|
|
4
5
|
title?: string;
|
|
5
6
|
dismissible?: boolean;
|
|
6
7
|
icon?: string;
|
|
7
8
|
hideIcon?: boolean;
|
|
8
9
|
}
|
|
10
|
+
export interface KAlertEmits {
|
|
11
|
+
(e: 'update:modelValue', value: boolean): void;
|
|
12
|
+
(e: 'dismiss'): void;
|
|
13
|
+
}
|
|
9
14
|
export declare const KAlertDefaultProps: KAlertProps;
|
|
10
|
-
export declare function useKAlertLogic(props: KAlertProps, emit: (event: 'dismiss') => void): {
|
|
15
|
+
export declare function useKAlertLogic(props: KAlertProps, emit: (((event: 'update:modelValue', value: boolean) => void) & ((event: 'dismiss') => void)) | ((event: any, ...args: any[]) => void)): {
|
|
11
16
|
visible: import("vue").Ref<boolean, boolean>;
|
|
12
17
|
dismiss: () => void;
|
|
13
18
|
icon: import("vue").ComputedRef<string>;
|
|
@@ -1,13 +1,23 @@
|
|
|
1
|
-
import { ref, computed } from "vue";
|
|
1
|
+
import { ref, computed, watch } from "vue";
|
|
2
2
|
export const KAlertDefaultProps = {
|
|
3
|
+
modelValue: true,
|
|
3
4
|
type: "info",
|
|
4
5
|
dismissible: false,
|
|
5
6
|
hideIcon: false
|
|
6
7
|
};
|
|
7
8
|
export function useKAlertLogic(props, emit) {
|
|
8
|
-
const visible = ref(true);
|
|
9
|
+
const visible = ref(props.modelValue ?? true);
|
|
10
|
+
watch(
|
|
11
|
+
() => props.modelValue,
|
|
12
|
+
(newVal) => {
|
|
13
|
+
if (newVal !== void 0) {
|
|
14
|
+
visible.value = newVal;
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
);
|
|
9
18
|
function dismiss() {
|
|
10
19
|
visible.value = false;
|
|
20
|
+
emit("update:modelValue", false);
|
|
11
21
|
emit("dismiss");
|
|
12
22
|
}
|
|
13
23
|
const iconMap = {
|
|
@@ -23,7 +23,7 @@ export interface KButtonEmits {
|
|
|
23
23
|
export declare function useKButtonLogic(props: KButtonProps, emit: KButtonEmits): {
|
|
24
24
|
isLink: import("vue").ComputedRef<boolean>;
|
|
25
25
|
isDisabled: import("vue").ComputedRef<boolean | undefined>;
|
|
26
|
-
buttonClasses: import("vue").ComputedRef<("default" | "info" | "success" | "warning" | "danger" | "
|
|
26
|
+
buttonClasses: import("vue").ComputedRef<("small" | "default" | "info" | "success" | "warning" | "danger" | "primary" | "light" | "dark" | "large" | "medium" | {
|
|
27
27
|
disabled: boolean | undefined;
|
|
28
28
|
'icon-only': boolean | undefined;
|
|
29
29
|
})[]>;
|
|
@@ -24,7 +24,12 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
24
24
|
type: import("vue").PropType<Date | String>;
|
|
25
25
|
default: null;
|
|
26
26
|
};
|
|
27
|
+
modelValue: {
|
|
28
|
+
type: import("vue").PropType<Date | String>;
|
|
29
|
+
default: undefined;
|
|
30
|
+
};
|
|
27
31
|
}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {} & {
|
|
32
|
+
"update:modelValue": (value: String | Date) => any;
|
|
28
33
|
"update:selectedDay": (value: String | Date) => any;
|
|
29
34
|
dayClicked: (date: Date, marked: import("./types.js").IMarkedDay[]) => any;
|
|
30
35
|
}, string, import("vue").PublicProps, Readonly<import("vue").ExtractPropTypes<{
|
|
@@ -53,10 +58,16 @@ declare const __VLS_export: import("vue").DefineComponent<import("vue").ExtractP
|
|
|
53
58
|
type: import("vue").PropType<Date | String>;
|
|
54
59
|
default: null;
|
|
55
60
|
};
|
|
61
|
+
modelValue: {
|
|
62
|
+
type: import("vue").PropType<Date | String>;
|
|
63
|
+
default: undefined;
|
|
64
|
+
};
|
|
56
65
|
}>> & Readonly<{
|
|
66
|
+
"onUpdate:modelValue"?: ((value: String | Date) => any) | undefined;
|
|
57
67
|
"onUpdate:selectedDay"?: ((value: String | Date) => any) | undefined;
|
|
58
68
|
onDayClicked?: ((date: Date, marked: import("./types.js").IMarkedDay[]) => any) | undefined;
|
|
59
69
|
}>, {
|
|
70
|
+
modelValue: String | Date;
|
|
60
71
|
view: string;
|
|
61
72
|
viewCount: number;
|
|
62
73
|
definedDays: import("./types.js").IDefinedDay[];
|
|
@@ -4,7 +4,7 @@ import { usePresetComponent } from "../../composables/usePresetComponent";
|
|
|
4
4
|
import { computed } from "vue";
|
|
5
5
|
import KCalendarDefault from "../../presets/default/components/KCalendar/KCalendar.vue";
|
|
6
6
|
const props = defineProps(KCalendarDefaultProps);
|
|
7
|
-
const emit = defineEmits(["update:selectedDay", "dayClicked"]);
|
|
7
|
+
const emit = defineEmits(["update:selectedDay", "update:modelValue", "dayClicked"]);
|
|
8
8
|
const {
|
|
9
9
|
monthSelectedDay,
|
|
10
10
|
actualYear,
|