@katlux/toolkit 0.1.1-alpha.144 → 0.1.1-alpha.146
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/ai-init.mjs +517 -0
- package/bin/ai-tokens.mjs +1043 -0
- package/bin/cli.mjs +80 -43
- package/bin/create-preset.mjs +1 -0
- package/bin/preset-contracts.json +2941 -0
- package/dist/compiled/composables/locales.mjs +204 -25
- package/dist/compiled/composables/useDataProvider.mjs +36 -25
- package/dist/compiled/composables/useFilterLogic.mjs +10 -2
- package/dist/compiled/composables/useKatluxForm.mjs +6 -4
- package/dist/compiled/composables/useVirtualDataset.mjs +689 -0
- package/dist/compiled/composables/useVirtualScroll.mjs +29 -9
- package/dist/module.cjs +63 -77
- package/dist/module.d.cts +5 -0
- package/dist/module.d.mts +4 -1
- package/dist/module.json +1 -1
- package/dist/module.mjs +60 -78
- package/dist/runtime/components/KAccordion/KAccordion.global.d.vue.ts +2 -2
- package/dist/runtime/components/KAccordion/KAccordion.global.vue.d.ts +2 -2
- package/dist/runtime/components/KAlert/KAlert.global.d.vue.ts +1 -1
- package/dist/runtime/components/KAlert/KAlert.global.vue.d.ts +1 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.global.d.vue.ts +7 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue +4 -1
- package/dist/runtime/components/KBulkActions/KBulkActions.global.vue.d.ts +7 -3
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.d.ts +4 -2
- package/dist/runtime/components/KBulkActions/KBulkActions.logic.js +70 -37
- package/dist/runtime/components/KButton/KButton.global.d.vue.ts +2 -2
- package/dist/runtime/components/KButton/KButton.global.vue.d.ts +2 -2
- package/dist/runtime/components/KButton/KButton.logic.d.ts +1 -1
- package/dist/runtime/components/KCalendar/KCalendar.global.d.vue.ts +19 -10
- package/dist/runtime/components/KCalendar/KCalendar.global.vue +7 -2
- package/dist/runtime/components/KCalendar/KCalendar.global.vue.d.ts +19 -10
- package/dist/runtime/components/KCalendar/KCalendar.logic.d.ts +14 -201
- package/dist/runtime/components/KCalendar/KCalendar.logic.js +60 -11
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.d.vue.ts +25 -5
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue +11 -1
- package/dist/runtime/components/KCalendar/KCalendarMonth.global.vue.d.ts +25 -5
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.d.ts +19 -3
- package/dist/runtime/components/KCalendar/KCalendarMonth.logic.js +115 -1
- package/dist/runtime/components/KCheckbox/KCheckbox.global.d.vue.ts +2 -2
- package/dist/runtime/components/KCheckbox/KCheckbox.global.vue.d.ts +2 -2
- package/dist/runtime/components/KCombobox/KCombobox.global.d.vue.ts +9 -9
- package/dist/runtime/components/KCombobox/KCombobox.global.vue +1 -1
- package/dist/runtime/components/KCombobox/KCombobox.global.vue.d.ts +9 -9
- package/dist/runtime/components/KCombobox/KCombobox.logic.d.ts +7 -1
- package/dist/runtime/components/KCombobox/KCombobox.logic.js +1 -1
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.d.vue.ts +14 -14
- package/dist/runtime/components/KCompositeInput/KCompositeInput.global.vue.d.ts +14 -14
- package/dist/runtime/components/KCompositeInput/KCompositeInput.logic.d.ts +3 -3
- package/dist/runtime/components/KContextMenu/KContextMenu.logic.js +5 -0
- package/dist/runtime/components/KDatatable/KDataIterator.global.d.vue.ts +22 -18
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue +23 -16
- package/dist/runtime/components/KDatatable/KDataIterator.global.vue.d.ts +22 -18
- package/dist/runtime/components/KDatatable/KDataIterator.logic.d.ts +13 -10
- package/dist/runtime/components/KDatatable/KDataIterator.logic.js +25 -20
- package/dist/runtime/components/KDatatable/KDatatable.global.d.vue.ts +9 -13
- package/dist/runtime/components/KDatatable/KDatatable.global.vue +6 -5
- package/dist/runtime/components/KDatatable/KDatatable.global.vue.d.ts +9 -13
- package/dist/runtime/components/KDatatable/KDatatable.logic.d.ts +4 -6
- package/dist/runtime/components/KDatatable/KDatatable.logic.js +26 -19
- package/dist/runtime/components/KDatePicker/KDatePicker.global.d.vue.ts +31 -15
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue +38 -13
- package/dist/runtime/components/KDatePicker/KDatePicker.global.vue.d.ts +31 -15
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.d.ts +28 -6
- package/dist/runtime/components/KDatePicker/KDatePicker.logic.js +197 -53
- 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/KDateTimePicker/KDateTimePicker.logic.js +2 -0
- package/dist/runtime/components/KDropdown/KDropdown.global.d.vue.ts +1 -1
- package/dist/runtime/components/KDropdown/KDropdown.global.vue.d.ts +1 -1
- package/dist/runtime/components/KGantt/KGantt.global.d.vue.ts +55 -6
- package/dist/runtime/components/KGantt/KGantt.global.vue +12 -3
- package/dist/runtime/components/KGantt/KGantt.global.vue.d.ts +55 -6
- package/dist/runtime/components/KGantt/KGantt.logic.d.ts +33 -5
- package/dist/runtime/components/KGantt/KGantt.logic.js +39 -6
- 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/KLoader/KLoader.global.vue +2 -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/KMultiTabs/MultiTabs.global.d.vue.ts +23 -0
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.vue +22 -0
- package/dist/runtime/components/KMultiTabs/MultiTabs.global.vue.d.ts +23 -0
- package/dist/runtime/components/KPagination/KPagination.global.d.vue.ts +4 -2
- package/dist/runtime/components/KPagination/KPagination.global.vue +2 -1
- package/dist/runtime/components/KPagination/KPagination.global.vue.d.ts +4 -2
- package/dist/runtime/components/KPagination/KPagination.logic.d.ts +1 -0
- package/dist/runtime/components/KPagination/KPagination.logic.js +57 -5
- package/dist/runtime/components/KRadiobox/KRadiobox.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRadiobox/KRadiobox.global.vue.d.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KRangeSlider/KRangeSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.d.vue.ts +1 -1
- package/dist/runtime/components/KSlider/KSlider.global.vue.d.ts +1 -1
- package/dist/runtime/components/KTabs/KTabs.global.d.vue.ts +2 -2
- package/dist/runtime/components/KTabs/KTabs.global.vue.d.ts +2 -2
- 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 +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/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 +7 -7
- package/dist/runtime/components/KTree/KTree.global.vue.d.ts +7 -7
- package/dist/runtime/components/KTree/KTree.logic.d.ts +2 -2
- package/dist/runtime/components/KTree/KTree.logic.js +16 -12
- package/dist/runtime/components/KTreePicker/KTreePicker.global.d.vue.ts +7 -9
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue +1 -5
- package/dist/runtime/components/KTreePicker/KTreePicker.global.vue.d.ts +7 -9
- package/dist/runtime/components/KTreeView/KTreeView.global.d.vue.ts +39 -5
- package/dist/runtime/components/KTreeView/KTreeView.global.vue +19 -1
- package/dist/runtime/components/KTreeView/KTreeView.global.vue.d.ts +39 -5
- package/dist/runtime/components/KTreeView/KTreeView.logic.d.ts +23 -3
- package/dist/runtime/components/KTreeView/KTreeView.logic.js +76 -6
- package/dist/runtime/composables/locales.js +204 -25
- package/dist/runtime/composables/useDataProvider.d.ts +5 -3
- package/dist/runtime/composables/useDataProvider.js +36 -25
- package/dist/runtime/composables/useFilterLogic.d.ts +16 -4
- package/dist/runtime/composables/useFilterLogic.js +10 -2
- package/dist/runtime/composables/useKatluxForm.d.ts +4 -4
- package/dist/runtime/composables/useKatluxForm.js +6 -4
- package/dist/runtime/composables/useSortLogic.d.ts +1 -1
- package/dist/runtime/composables/useVirtualDataset.d.ts +121 -0
- package/dist/runtime/composables/useVirtualDataset.js +689 -0
- package/dist/runtime/composables/useVirtualScroll.d.ts +8 -4
- package/dist/runtime/composables/useVirtualScroll.js +29 -9
- package/dist/runtime/plugins/nuxtCompatPlugin.js +9 -1
- package/dist/runtime/presets/default/assets/scss/css-variables.css +3 -0
- package/dist/runtime/presets/default/assets/scss/css-variables.scss +6 -1
- package/dist/runtime/presets/default/assets/scss/index.css +3 -0
- package/dist/runtime/presets/default/assets/svg/katlux-logo.svg +7 -0
- package/dist/runtime/presets/default/assets/svg/katlux.svg +6 -0
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.d.vue.ts +3 -2
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue +31 -3
- package/dist/runtime/presets/default/components/KBulkActions/KBulkActions.vue.d.ts +3 -2
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.d.vue.ts +3 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.vue +6 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendar.vue.d.ts +3 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.d.vue.ts +5 -0
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue +33 -2
- package/dist/runtime/presets/default/components/KCalendar/KCalendarMonth.vue.d.ts +5 -0
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.d.vue.ts +2 -2
- package/dist/runtime/presets/default/components/KCheckbox/KCheckbox.vue.d.ts +2 -2
- package/dist/runtime/presets/default/components/KContextMenu/KContextMenu.vue +7 -1
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.d.vue.ts +30 -8
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue +80 -164
- package/dist/runtime/presets/default/components/KDataIterator/KDataIterator.vue.d.ts +30 -8
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.d.vue.ts +16 -9
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue +99 -394
- package/dist/runtime/presets/default/components/KDatatable/KDatatable.vue.d.ts +16 -9
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.d.vue.ts +6 -0
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue +71 -4
- package/dist/runtime/presets/default/components/KDatePicker/KDatePicker.vue.d.ts +6 -0
- package/dist/runtime/presets/default/components/KGantt/KGantt.d.vue.ts +11 -12
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue +77 -14
- package/dist/runtime/presets/default/components/KGantt/KGantt.vue.d.ts +11 -12
- package/dist/runtime/presets/default/components/KGantt/KGanttTimeline.vue +1 -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/dist/runtime/presets/default/components/KTree/KTree.d.vue.ts +4 -4
- package/dist/runtime/presets/default/components/KTree/KTree.vue +48 -14
- package/dist/runtime/presets/default/components/KTree/KTree.vue.d.ts +4 -4
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.d.vue.ts +11 -2
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue +14 -2
- package/dist/runtime/presets/default/components/KTreeView/KTreeView.vue.d.ts +11 -2
- package/dist/skills/KATLUX_INDEX.md +9 -6
- package/dist/skills/katlux-components/SKILL.md +2 -0
- package/dist/skills/katlux-components/components/KBulkActions.md +25 -1
- package/dist/skills/katlux-components/components/KCombobox.md +2 -2
- package/dist/skills/katlux-components/components/KDataIterator.md +12 -4
- package/dist/skills/katlux-components/components/KDatatable.md +38 -0
- package/dist/skills/katlux-components/components/KDatePicker.md +3 -1
- package/dist/skills/katlux-components/components/KGantt.md +9 -0
- package/dist/skills/katlux-components/components/KIcon.md +1 -1
- package/dist/skills/katlux-components/components/KLineChart.md +3 -0
- package/dist/skills/katlux-components/components/KProductList.md +0 -1
- package/dist/skills/katlux-components/components/KScatterChart.md +3 -0
- package/dist/skills/katlux-components/components/KTreePicker.md +2 -1
- package/dist/skills/katlux-components/components/KTreeView.md +12 -0
- package/dist/skills/katlux-config/SKILL.md +19 -8
- package/dist/skills/katlux-presets/SKILL.md +121 -1
- package/dist/skills/katlux-presets/creating-a-preset.md +67 -0
- package/dist/skills/katlux-providers/SKILL.md +7 -5
- package/dist/skills/katlux-providers/providers/ADataProvider.md +16 -9
- package/dist/skills/katlux-providers/providers/CAPIFlatClientDataProvider.md +27 -3
- package/dist/skills/katlux-providers/providers/CAPIFlatServerDataProvider.md +11 -1
- package/dist/skills/katlux-providers/providers/CFlatClientDataProvider.md +19 -4
- package/dist/skills/katlux-providers/providers/CFlatServerDataProvider.md +4 -2
- package/dist/skills/katlux-providers/providers/CTreeClientDataProvider.md +2 -2
- package/dist/skills/katlux-providers/providers/RequestProvider.md +10 -0
- package/dist/skills/katlux-providers/providers/encryption-field-level.md +63 -19
- package/dist/skills/katlux-providers/providers/encryption-key-management.md +20 -2
- package/dist/skills/katlux-providers/providers/encryption-key-pinning.md +25 -11
- package/dist/skills/katlux-providers/providers/encryption-searchable.md +218 -0
- package/dist/skills/katlux-providers/providers/encryption-symmetric.md +25 -1
- package/dist/skills/katlux-providers/providers/encryption-threat-model.md +63 -0
- package/dist/skills/katlux-providers/providers/encryption.md +26 -1
- package/dist/skills/katlux-providers/providers/types.md +3 -1
- package/dist/skills/katlux-providers/providers/useDataProvider.md +2 -1
- package/dist/skills/katlux-providers/providers/useVirtualDataset.md +154 -0
- package/dist/skills/katlux-tokens/SKILL.md +2 -1
- package/dist/types.d.mts +1 -1
- package/package.json +9 -3
- package/bin/add-ai-reference.mjs +0 -259
|
@@ -0,0 +1,689 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ref,
|
|
3
|
+
shallowRef,
|
|
4
|
+
computed,
|
|
5
|
+
unref,
|
|
6
|
+
isRef,
|
|
7
|
+
watch,
|
|
8
|
+
onScopeDispose
|
|
9
|
+
} from "vue";
|
|
10
|
+
import { isEncrypted } from "@katlux/providers";
|
|
11
|
+
import { useVirtualScroll } from "./useVirtualScroll.mjs";
|
|
12
|
+
import { useDataProvider } from "./useDataProvider.mjs";
|
|
13
|
+
function isUseDataProviderReturn(val) {
|
|
14
|
+
return val !== null && typeof val === "object" && "pageData" in val && isRef(val.pageData) && "stateVersion" in val && isRef(val.stateVersion);
|
|
15
|
+
}
|
|
16
|
+
export function useVirtualDataset(options) {
|
|
17
|
+
const resolveRawProvider = () => {
|
|
18
|
+
if (isUseDataProviderReturn(options.dataProvider)) {
|
|
19
|
+
return options.dataProvider.rawProvider;
|
|
20
|
+
}
|
|
21
|
+
if (typeof options.dataProvider === "function") {
|
|
22
|
+
return options.dataProvider();
|
|
23
|
+
}
|
|
24
|
+
return isRef(options.dataProvider) ? options.dataProvider.value : options.dataProvider;
|
|
25
|
+
};
|
|
26
|
+
const rawProvider = resolveRawProvider();
|
|
27
|
+
const initialPageSize = unref(options.pageSize) ?? rawProvider?.pageSize ?? 10;
|
|
28
|
+
const datasetPageSize = ref(initialPageSize);
|
|
29
|
+
if (options.pageSize !== void 0 && isRef(options.pageSize)) {
|
|
30
|
+
watch(() => unref(options.pageSize), (newVal) => {
|
|
31
|
+
if (newVal !== void 0 && newVal !== datasetPageSize.value) {
|
|
32
|
+
datasetPageSize.value = newVal;
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
const dpBridge = isUseDataProviderReturn(options.dataProvider) ? options.dataProvider : useDataProvider(() => resolveRawProvider(), {
|
|
37
|
+
pageSize: datasetPageSize
|
|
38
|
+
});
|
|
39
|
+
let customUnsub = null;
|
|
40
|
+
const attachCustomProviderListener = (dp) => {
|
|
41
|
+
if (customUnsub) {
|
|
42
|
+
try {
|
|
43
|
+
customUnsub();
|
|
44
|
+
} catch {
|
|
45
|
+
}
|
|
46
|
+
customUnsub = null;
|
|
47
|
+
}
|
|
48
|
+
if (dp && typeof dp.on === "function") {
|
|
49
|
+
try {
|
|
50
|
+
const off = dp.on("change", () => {
|
|
51
|
+
dpBridge.stateVersion.value++;
|
|
52
|
+
});
|
|
53
|
+
customUnsub = () => {
|
|
54
|
+
if (typeof off === "function") off();
|
|
55
|
+
else if (typeof dp.off === "function") dp.off("change");
|
|
56
|
+
};
|
|
57
|
+
} catch {
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
attachCustomProviderListener(resolveRawProvider());
|
|
62
|
+
try {
|
|
63
|
+
onScopeDispose(() => {
|
|
64
|
+
if (customUnsub) {
|
|
65
|
+
try {
|
|
66
|
+
customUnsub();
|
|
67
|
+
} catch {
|
|
68
|
+
}
|
|
69
|
+
customUnsub = null;
|
|
70
|
+
}
|
|
71
|
+
});
|
|
72
|
+
} catch {
|
|
73
|
+
}
|
|
74
|
+
if (isRef(options.dataProvider) || typeof options.dataProvider === "function") {
|
|
75
|
+
watch(resolveRawProvider, (newDp) => {
|
|
76
|
+
attachCustomProviderListener(newDp);
|
|
77
|
+
});
|
|
78
|
+
}
|
|
79
|
+
const pageRows = computed(() => dpBridge.pageData.value || []);
|
|
80
|
+
const activeFilter = computed(() => {
|
|
81
|
+
return dpBridge.filter.value || dpBridge.rawProvider?.filter || null;
|
|
82
|
+
});
|
|
83
|
+
const effectivePageSize = computed(() => {
|
|
84
|
+
const ps = unref(options.pageSize) ?? dpBridge.pageSize.value ?? dpBridge.rawProvider?.pageSize;
|
|
85
|
+
return typeof ps === "number" && ps > 0 ? ps : 10;
|
|
86
|
+
});
|
|
87
|
+
const isLoading = computed(() => {
|
|
88
|
+
return dpBridge.loading.value || dpBridge.initialLoad.value || false;
|
|
89
|
+
});
|
|
90
|
+
const dpFields = computed(() => {
|
|
91
|
+
const _ver = dpBridge.stateVersion.value;
|
|
92
|
+
const bridgeFields = dpBridge.fields?.value;
|
|
93
|
+
if (Array.isArray(bridgeFields) && bridgeFields.length > 0) return bridgeFields;
|
|
94
|
+
const rawFields = dpBridge.rawProvider?.fields;
|
|
95
|
+
if (Array.isArray(rawFields) && rawFields.length > 0) return rawFields;
|
|
96
|
+
if (pageRows.value.length > 0 && pageRows.value[0]) {
|
|
97
|
+
return Object.keys(pageRows.value[0]).filter((k) => !k.startsWith("__"));
|
|
98
|
+
}
|
|
99
|
+
return [];
|
|
100
|
+
});
|
|
101
|
+
const rowIdKey = computed(() => {
|
|
102
|
+
return unref(options.idKey) || dpBridge.rawProvider?.idKey || "id";
|
|
103
|
+
});
|
|
104
|
+
const datasetItems = computed(() => {
|
|
105
|
+
const _ver = dpBridge.stateVersion.value;
|
|
106
|
+
const currentRows = pageRows.value;
|
|
107
|
+
const dp = dpBridge.rawProvider;
|
|
108
|
+
const isVirtual = unref(options.virtualScroll);
|
|
109
|
+
if (isVirtual && dp) {
|
|
110
|
+
if (Array.isArray(dp.rowMap)) return dp.rowMap;
|
|
111
|
+
if (Array.isArray(dp.rowMap?.value)) return dp.rowMap.value;
|
|
112
|
+
if (Array.isArray(dp.allVisibleRows)) return dp.allVisibleRows;
|
|
113
|
+
if (Array.isArray(dp.allVisibleRows?.value)) return dp.allVisibleRows.value;
|
|
114
|
+
if (Array.isArray(dp.allVisibleNodes)) return dp.allVisibleNodes;
|
|
115
|
+
if (Array.isArray(dp.allVisibleNodes?.value)) return dp.allVisibleNodes.value;
|
|
116
|
+
if (Array.isArray(dp.filteredData?.value)) return dp.filteredData.value;
|
|
117
|
+
if (Array.isArray(dp.filteredData)) return dp.filteredData;
|
|
118
|
+
if (Array.isArray(dp.allData?.value)) return dp.allData.value;
|
|
119
|
+
if (Array.isArray(dp.allData)) return dp.allData;
|
|
120
|
+
if (Array.isArray(dp.data)) return dp.data;
|
|
121
|
+
}
|
|
122
|
+
return currentRows;
|
|
123
|
+
});
|
|
124
|
+
const virtualScrollReturn = useVirtualScroll({
|
|
125
|
+
totalCount: computed(() => {
|
|
126
|
+
const _ver = dpBridge.stateVersion.value;
|
|
127
|
+
const isVirtual = unref(options.virtualScroll);
|
|
128
|
+
if (isVirtual) {
|
|
129
|
+
const rc = dpBridge.rowCount.value ?? dpBridge.rawProvider?.rowCount;
|
|
130
|
+
const count = typeof rc === "number" ? rc : unref(rc);
|
|
131
|
+
if (typeof count === "number" && count >= 0) return count;
|
|
132
|
+
if (Array.isArray(dpBridge.rawProvider?.rowMap)) {
|
|
133
|
+
return dpBridge.rawProvider.rowMap.length;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
return pageRows.value.length;
|
|
137
|
+
}),
|
|
138
|
+
items: datasetItems,
|
|
139
|
+
itemHeight: options.itemHeight ?? 40,
|
|
140
|
+
containerHeight: options.viewportHeight ?? options.containerHeight ?? 500,
|
|
141
|
+
buffer: options.buffer ?? 5,
|
|
142
|
+
virtualScroll: computed(() => !!unref(options.virtualScroll)),
|
|
143
|
+
columns: options.columns,
|
|
144
|
+
scrollThreshold: options.scrollThreshold,
|
|
145
|
+
onThresholdReach: () => {
|
|
146
|
+
const dp = dpBridge.rawProvider;
|
|
147
|
+
if (unref(options.virtualScroll)) {
|
|
148
|
+
if (typeof dp?.loadMore === "function") {
|
|
149
|
+
dp.loadMore();
|
|
150
|
+
}
|
|
151
|
+
} else {
|
|
152
|
+
if (typeof dp?.loadMore === "function") {
|
|
153
|
+
dp.loadMore();
|
|
154
|
+
} else if (typeof dp?.nextPage === "function" && dp.hasMore) {
|
|
155
|
+
dp.nextPage();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
options.onThresholdReach?.();
|
|
159
|
+
}
|
|
160
|
+
});
|
|
161
|
+
const {
|
|
162
|
+
visibleItems,
|
|
163
|
+
startIndex,
|
|
164
|
+
endIndex,
|
|
165
|
+
topSpacerHeight,
|
|
166
|
+
bottomSpacerHeight,
|
|
167
|
+
totalHeight,
|
|
168
|
+
scrollTop,
|
|
169
|
+
viewportHeight,
|
|
170
|
+
containerRef,
|
|
171
|
+
onScroll,
|
|
172
|
+
scrollToIndex,
|
|
173
|
+
containerCssVars
|
|
174
|
+
} = virtualScrollReturn;
|
|
175
|
+
const deliveredRowsCache = shallowRef(/* @__PURE__ */ new Map());
|
|
176
|
+
const requestedPages = /* @__PURE__ */ new Set();
|
|
177
|
+
let isFetchingPage = false;
|
|
178
|
+
const pageQueue = [];
|
|
179
|
+
let cacheGeneration = 0;
|
|
180
|
+
watch(pageRows, (rows) => {
|
|
181
|
+
if (Array.isArray(rows) && rows.length > 0) {
|
|
182
|
+
const idKey = rowIdKey.value;
|
|
183
|
+
const nextCache = new Map(deliveredRowsCache.value);
|
|
184
|
+
for (const r of rows) {
|
|
185
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id;
|
|
186
|
+
if (id !== void 0 && id !== null) {
|
|
187
|
+
nextCache.set(id, r);
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
deliveredRowsCache.value = nextCache;
|
|
191
|
+
const curPage = dpBridge.currentPage.value || dpBridge.rawProvider?.currentPage || 1;
|
|
192
|
+
requestedPages.add(curPage);
|
|
193
|
+
}
|
|
194
|
+
}, { immediate: true });
|
|
195
|
+
const processPageQueue = async () => {
|
|
196
|
+
if (isFetchingPage || pageQueue.length === 0) return;
|
|
197
|
+
const nextPage = pageQueue.shift();
|
|
198
|
+
const dp = dpBridge.rawProvider;
|
|
199
|
+
if (!dp) return;
|
|
200
|
+
const currentGen = cacheGeneration;
|
|
201
|
+
isFetchingPage = true;
|
|
202
|
+
try {
|
|
203
|
+
const ps = effectivePageSize.value;
|
|
204
|
+
const pageStart = (nextPage - 1) * ps;
|
|
205
|
+
const pageEnd = pageStart + ps;
|
|
206
|
+
let resolvedRows;
|
|
207
|
+
if (typeof dp.resolveRangeRows === "function") {
|
|
208
|
+
resolvedRows = await dp.resolveRangeRows(pageStart, pageEnd);
|
|
209
|
+
} else if (typeof dp.getWindowRows === "function") {
|
|
210
|
+
resolvedRows = await dp.getWindowRows(pageStart, pageEnd);
|
|
211
|
+
} else if (typeof dp.loadRange === "function") {
|
|
212
|
+
await dp.loadRange(pageStart, pageEnd);
|
|
213
|
+
if (Array.isArray(dp.rowMap)) {
|
|
214
|
+
resolvedRows = dp.rowMap.slice(pageStart, pageEnd);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
if (currentGen !== cacheGeneration) return;
|
|
218
|
+
if (Array.isArray(resolvedRows) && resolvedRows.length > 0) {
|
|
219
|
+
const idKey = rowIdKey.value;
|
|
220
|
+
const nextCache = new Map(deliveredRowsCache.value);
|
|
221
|
+
for (const r of resolvedRows) {
|
|
222
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id;
|
|
223
|
+
if (id !== void 0 && id !== null) {
|
|
224
|
+
nextCache.set(id, r);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
deliveredRowsCache.value = nextCache;
|
|
228
|
+
} else {
|
|
229
|
+
requestedPages.delete(nextPage);
|
|
230
|
+
}
|
|
231
|
+
} catch (err) {
|
|
232
|
+
console.warn("[useVirtualDataset] processPageQueue error:", err);
|
|
233
|
+
} finally {
|
|
234
|
+
isFetchingPage = false;
|
|
235
|
+
if (pageQueue.length > 0) {
|
|
236
|
+
processPageQueue();
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
};
|
|
240
|
+
const queuePage = (page) => {
|
|
241
|
+
if (!requestedPages.has(page)) {
|
|
242
|
+
requestedPages.add(page);
|
|
243
|
+
pageQueue.push(page);
|
|
244
|
+
processPageQueue();
|
|
245
|
+
}
|
|
246
|
+
};
|
|
247
|
+
const ensureVisiblePagesLoaded = () => {
|
|
248
|
+
if (!unref(options.virtualScroll)) return;
|
|
249
|
+
const start = startIndex.value;
|
|
250
|
+
const end = endIndex.value;
|
|
251
|
+
const dp = dpBridge.rawProvider;
|
|
252
|
+
if (dp && typeof dp.ensureRangeLoaded === "function") {
|
|
253
|
+
dp.ensureRangeLoaded(start, end);
|
|
254
|
+
}
|
|
255
|
+
const vHeight = typeof viewportHeight.value === "number" && viewportHeight.value > 0 ? viewportHeight.value : 500;
|
|
256
|
+
const rawH = unref(options.itemHeight);
|
|
257
|
+
const iHeight = typeof rawH === "number" && rawH > 0 ? rawH : 40;
|
|
258
|
+
const visibleEnd = Math.ceil((scrollTop.value + vHeight) / iHeight);
|
|
259
|
+
const needsMore = scrollTop.value > 0 && end > datasetItems.value.length || visibleEnd > datasetItems.value.length;
|
|
260
|
+
if (dp && typeof dp.loadMore === "function" && dp.batchLoad !== "onDemand" && dp.hasMore && !dp.loading && !dp._inFlightLoadMore && needsMore) {
|
|
261
|
+
const res = dp.loadMore();
|
|
262
|
+
if (res instanceof Promise) {
|
|
263
|
+
res.catch((err) => {
|
|
264
|
+
console.warn("[useVirtualDataset] loadMore error:", err);
|
|
265
|
+
});
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
const ps = effectivePageSize.value;
|
|
269
|
+
if (!ps || ps <= 0) return;
|
|
270
|
+
const startPage = Math.floor(start / ps) + 1;
|
|
271
|
+
const endPage = Math.floor(Math.max(0, end - 1) / ps) + 1;
|
|
272
|
+
for (let p = startPage; p <= endPage; p++) {
|
|
273
|
+
queuePage(p);
|
|
274
|
+
}
|
|
275
|
+
};
|
|
276
|
+
watch([startIndex, endIndex, () => datasetItems.value.length, dpBridge.stateVersion, () => unref(options.virtualScroll)], () => {
|
|
277
|
+
ensureVisiblePagesLoaded();
|
|
278
|
+
}, { immediate: true });
|
|
279
|
+
const invalidateCache = () => {
|
|
280
|
+
cacheGeneration++;
|
|
281
|
+
deliveredRowsCache.value = /* @__PURE__ */ new Map();
|
|
282
|
+
requestedPages.clear();
|
|
283
|
+
pageQueue.length = 0;
|
|
284
|
+
if (Array.isArray(pageRows.value) && pageRows.value.length > 0) {
|
|
285
|
+
const idKey = rowIdKey.value;
|
|
286
|
+
const nextCache = /* @__PURE__ */ new Map();
|
|
287
|
+
for (const r of pageRows.value) {
|
|
288
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id;
|
|
289
|
+
if (id !== void 0 && id !== null) {
|
|
290
|
+
nextCache.set(id, r);
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
deliveredRowsCache.value = nextCache;
|
|
294
|
+
const curPage = dpBridge.currentPage.value || dpBridge.rawProvider?.currentPage || 1;
|
|
295
|
+
requestedPages.add(curPage);
|
|
296
|
+
}
|
|
297
|
+
if (unref(options.virtualScroll)) {
|
|
298
|
+
ensureVisiblePagesLoaded();
|
|
299
|
+
}
|
|
300
|
+
};
|
|
301
|
+
watch([dpBridge.filter, dpBridge.sortList, dpBridge.filterSortVersion], () => {
|
|
302
|
+
invalidateCache();
|
|
303
|
+
});
|
|
304
|
+
watch(() => dpBridge.rawProvider, () => {
|
|
305
|
+
invalidateCache();
|
|
306
|
+
});
|
|
307
|
+
const displayRows = computed(() => {
|
|
308
|
+
if (unref(options.virtualScroll)) {
|
|
309
|
+
const items = visibleItems.value;
|
|
310
|
+
const cache = deliveredRowsCache.value;
|
|
311
|
+
const dp = dpBridge.rawProvider;
|
|
312
|
+
const hasRefDecrypt = dp && typeof dp.getDecryptedRow === "function";
|
|
313
|
+
if (cache.size > 0 || hasRefDecrypt) {
|
|
314
|
+
const idKey = rowIdKey.value;
|
|
315
|
+
return items.map((item) => {
|
|
316
|
+
const id = item?.[idKey] ?? item?.id ?? item?._id;
|
|
317
|
+
if (id !== void 0 && id !== null && cache.has(id)) {
|
|
318
|
+
return cache.get(id);
|
|
319
|
+
}
|
|
320
|
+
if (hasRefDecrypt && typeof item === "object" && item !== null) {
|
|
321
|
+
const decrypted = dp.getDecryptedRow(item);
|
|
322
|
+
if (decrypted) return decrypted;
|
|
323
|
+
}
|
|
324
|
+
return item;
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return items;
|
|
328
|
+
}
|
|
329
|
+
return pageRows.value;
|
|
330
|
+
});
|
|
331
|
+
const isCellEncrypted = (val) => {
|
|
332
|
+
if (!val || typeof val !== "object") return false;
|
|
333
|
+
if (val.__encrypted === true) return true;
|
|
334
|
+
const cipher = dpBridge.rawProvider?.cipherProvider;
|
|
335
|
+
if (cipher && typeof cipher.isEncrypted === "function") {
|
|
336
|
+
return cipher.isEncrypted(val);
|
|
337
|
+
}
|
|
338
|
+
return typeof isEncrypted === "function" ? isEncrypted(val) : false;
|
|
339
|
+
};
|
|
340
|
+
const selectedRows = options.selectedRows ?? ref([]);
|
|
341
|
+
const selectAll = options.selectAll ?? ref(false);
|
|
342
|
+
const unselectedRows = options.unselectedRows ?? ref([]);
|
|
343
|
+
const selectAllFilter = ref(null);
|
|
344
|
+
const effectiveSelectAllScope = computed(() => {
|
|
345
|
+
if (unref(options.virtualScroll)) {
|
|
346
|
+
if (unref(options.selectAllScope) === "page") {
|
|
347
|
+
console.warn(
|
|
348
|
+
'[useVirtualDataset] virtualScroll is enabled with selectAllScope="page". Overriding selectAllScope to "dataset" because page-scoped selection is incompatible with virtual scrolling.'
|
|
349
|
+
);
|
|
350
|
+
}
|
|
351
|
+
return "dataset";
|
|
352
|
+
}
|
|
353
|
+
return unref(options.selectAllScope) || "page";
|
|
354
|
+
});
|
|
355
|
+
const getRowKey = (row, index) => {
|
|
356
|
+
const idKey = rowIdKey.value;
|
|
357
|
+
if (row && row[idKey] !== void 0 && row[idKey] !== null) {
|
|
358
|
+
return row[idKey];
|
|
359
|
+
}
|
|
360
|
+
if (row && row.id !== void 0 && row.id !== null) {
|
|
361
|
+
return row.id;
|
|
362
|
+
}
|
|
363
|
+
if (row && row._id !== void 0 && row._id !== null) {
|
|
364
|
+
return row._id;
|
|
365
|
+
}
|
|
366
|
+
return unref(options.virtualScroll) ? startIndex.value + index : index;
|
|
367
|
+
};
|
|
368
|
+
const selectedRowIds = computed(() => {
|
|
369
|
+
const idKey = rowIdKey.value;
|
|
370
|
+
const set = /* @__PURE__ */ new Set();
|
|
371
|
+
for (const r of selectedRows.value || []) {
|
|
372
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id ?? r;
|
|
373
|
+
set.add(id);
|
|
374
|
+
set.add(r);
|
|
375
|
+
}
|
|
376
|
+
return set;
|
|
377
|
+
});
|
|
378
|
+
const unselectedRowIds = computed(() => {
|
|
379
|
+
const idKey = rowIdKey.value;
|
|
380
|
+
const set = /* @__PURE__ */ new Set();
|
|
381
|
+
for (const r of unselectedRows.value || []) {
|
|
382
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id ?? r;
|
|
383
|
+
set.add(id);
|
|
384
|
+
set.add(r);
|
|
385
|
+
}
|
|
386
|
+
return set;
|
|
387
|
+
});
|
|
388
|
+
const isRowSelected = (row) => {
|
|
389
|
+
const idKey = rowIdKey.value;
|
|
390
|
+
const rowId = row?.[idKey] ?? row?.id ?? row?._id ?? row;
|
|
391
|
+
if (effectiveSelectAllScope.value === "dataset" && selectAll.value) {
|
|
392
|
+
if (selectAllFilter.value !== null && selectAllFilter.value !== JSON.stringify(activeFilter.value)) {
|
|
393
|
+
if (unselectedRowIds.value.has(rowId) || unselectedRowIds.value.has(row)) return false;
|
|
394
|
+
return selectedRowIds.value.has(rowId) || selectedRowIds.value.has(row);
|
|
395
|
+
}
|
|
396
|
+
return !unselectedRowIds.value.has(rowId) && !unselectedRowIds.value.has(row);
|
|
397
|
+
}
|
|
398
|
+
return selectedRowIds.value.has(rowId) || selectedRowIds.value.has(row);
|
|
399
|
+
};
|
|
400
|
+
const pageSelectedCount = computed(() => {
|
|
401
|
+
if (!datasetItems.value || datasetItems.value.length === 0) return 0;
|
|
402
|
+
let count = 0;
|
|
403
|
+
const ids = selectedRowIds.value;
|
|
404
|
+
const idKey = rowIdKey.value;
|
|
405
|
+
for (const r of datasetItems.value) {
|
|
406
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id ?? r;
|
|
407
|
+
if (ids.has(id) || ids.has(r)) count++;
|
|
408
|
+
}
|
|
409
|
+
return count;
|
|
410
|
+
});
|
|
411
|
+
const isAllSelected = computed(() => {
|
|
412
|
+
const total = datasetItems.value.length;
|
|
413
|
+
if (total === 0) return false;
|
|
414
|
+
if (effectiveSelectAllScope.value === "dataset") {
|
|
415
|
+
if (selectAll.value === true) {
|
|
416
|
+
if (selectAllFilter.value !== null && selectAllFilter.value !== JSON.stringify(activeFilter.value)) {
|
|
417
|
+
return pageSelectedCount.value === total;
|
|
418
|
+
}
|
|
419
|
+
return unselectedRows.value.length === 0;
|
|
420
|
+
}
|
|
421
|
+
return pageSelectedCount.value === total;
|
|
422
|
+
}
|
|
423
|
+
return pageSelectedCount.value === total;
|
|
424
|
+
});
|
|
425
|
+
const isIndeterminate = computed(() => {
|
|
426
|
+
const total = datasetItems.value.length;
|
|
427
|
+
if (total === 0) return false;
|
|
428
|
+
if (isAllSelected.value) return false;
|
|
429
|
+
if (effectiveSelectAllScope.value === "dataset") {
|
|
430
|
+
if (selectAll.value === true) {
|
|
431
|
+
if (selectAllFilter.value !== null && selectAllFilter.value !== JSON.stringify(activeFilter.value)) {
|
|
432
|
+
return pageSelectedCount.value > 0;
|
|
433
|
+
}
|
|
434
|
+
return unselectedRows.value.length > 0;
|
|
435
|
+
}
|
|
436
|
+
return pageSelectedCount.value > 0;
|
|
437
|
+
}
|
|
438
|
+
return pageSelectedCount.value > 0 && pageSelectedCount.value < total;
|
|
439
|
+
});
|
|
440
|
+
const handleSelectAll = () => {
|
|
441
|
+
const total = datasetItems.value.length;
|
|
442
|
+
if (total === 0) return;
|
|
443
|
+
if (effectiveSelectAllScope.value === "dataset") {
|
|
444
|
+
if (isAllSelected.value) {
|
|
445
|
+
selectAll.value = false;
|
|
446
|
+
selectAllFilter.value = null;
|
|
447
|
+
unselectedRows.value = [];
|
|
448
|
+
selectedRows.value = [];
|
|
449
|
+
} else {
|
|
450
|
+
selectAll.value = true;
|
|
451
|
+
selectAllFilter.value = JSON.stringify(activeFilter.value);
|
|
452
|
+
unselectedRows.value = [];
|
|
453
|
+
selectedRows.value = [];
|
|
454
|
+
}
|
|
455
|
+
return;
|
|
456
|
+
}
|
|
457
|
+
const idKey = rowIdKey.value;
|
|
458
|
+
if (isAllSelected.value) {
|
|
459
|
+
const pageIdSet = new Set(
|
|
460
|
+
datasetItems.value.map((r) => r?.[idKey] ?? r?.id ?? r?._id ?? r)
|
|
461
|
+
);
|
|
462
|
+
selectedRows.value = (selectedRows.value || []).filter((r) => {
|
|
463
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id ?? r;
|
|
464
|
+
return !pageIdSet.has(id) && !pageIdSet.has(r);
|
|
465
|
+
});
|
|
466
|
+
unselectedRows.value = [];
|
|
467
|
+
selectAll.value = false;
|
|
468
|
+
} else {
|
|
469
|
+
const existingIds = selectedRowIds.value;
|
|
470
|
+
const toAdd = datasetItems.value.filter((r) => {
|
|
471
|
+
const id = r?.[idKey] ?? r?.id ?? r?._id ?? r;
|
|
472
|
+
return !existingIds.has(id) && !existingIds.has(r);
|
|
473
|
+
});
|
|
474
|
+
selectedRows.value = [...selectedRows.value || [], ...toAdd];
|
|
475
|
+
unselectedRows.value = [];
|
|
476
|
+
selectAll.value = false;
|
|
477
|
+
}
|
|
478
|
+
};
|
|
479
|
+
const toggleRow = (row) => {
|
|
480
|
+
const idKey = rowIdKey.value;
|
|
481
|
+
const rowId = row?.[idKey] ?? row?.id ?? row?._id ?? row;
|
|
482
|
+
if (effectiveSelectAllScope.value === "dataset" && selectAll.value) {
|
|
483
|
+
const isCurrentlyExcluded = unselectedRowIds.value.has(rowId) || unselectedRowIds.value.has(row);
|
|
484
|
+
if (isCurrentlyExcluded) {
|
|
485
|
+
unselectedRows.value = (unselectedRows.value || []).filter((r) => {
|
|
486
|
+
const rId = r?.[idKey] ?? r?.id ?? r?._id ?? r;
|
|
487
|
+
return rId !== rowId && r !== row;
|
|
488
|
+
});
|
|
489
|
+
} else {
|
|
490
|
+
unselectedRows.value = [...unselectedRows.value || [], row];
|
|
491
|
+
}
|
|
492
|
+
return;
|
|
493
|
+
}
|
|
494
|
+
const isSelected = isRowSelected(row);
|
|
495
|
+
if (isSelected) {
|
|
496
|
+
const next = (selectedRows.value || []).filter((r) => {
|
|
497
|
+
const rId = r?.[idKey] ?? r?.id ?? r?._id ?? r;
|
|
498
|
+
return rId !== rowId && r !== row;
|
|
499
|
+
});
|
|
500
|
+
selectedRows.value = next;
|
|
501
|
+
} else {
|
|
502
|
+
selectedRows.value = [...selectedRows.value || [], row];
|
|
503
|
+
}
|
|
504
|
+
};
|
|
505
|
+
const focusedIndex = ref(-1);
|
|
506
|
+
const theadStickyOffset = options.theadStickyOffset ?? 40;
|
|
507
|
+
const resolveTheadOffset = () => {
|
|
508
|
+
if (containerRef.value) {
|
|
509
|
+
const thead = containerRef.value.querySelector("thead");
|
|
510
|
+
if (thead && thead.offsetHeight > 0) {
|
|
511
|
+
return thead.offsetHeight;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return theadStickyOffset;
|
|
515
|
+
};
|
|
516
|
+
const resolveItemH = () => {
|
|
517
|
+
if (containerRef.value) {
|
|
518
|
+
const rowEl = containerRef.value.querySelector('tbody tr, [role="row"]');
|
|
519
|
+
if (rowEl && rowEl.offsetHeight > 0) {
|
|
520
|
+
return rowEl.offsetHeight;
|
|
521
|
+
}
|
|
522
|
+
}
|
|
523
|
+
const raw = unref(options.itemHeight);
|
|
524
|
+
if (typeof raw === "function") return 40;
|
|
525
|
+
return typeof raw === "number" && raw > 0 ? raw : 40;
|
|
526
|
+
};
|
|
527
|
+
const resolveVpH = () => {
|
|
528
|
+
if (containerRef.value && containerRef.value.clientHeight > 0) {
|
|
529
|
+
return containerRef.value.clientHeight;
|
|
530
|
+
}
|
|
531
|
+
if (viewportHeight.value > 0) {
|
|
532
|
+
return viewportHeight.value;
|
|
533
|
+
}
|
|
534
|
+
const v = options.viewportHeight ?? options.containerHeight;
|
|
535
|
+
if (typeof v === "function") return v() || 500;
|
|
536
|
+
const num = unref(v);
|
|
537
|
+
return typeof num === "number" && num > 0 ? num : 500;
|
|
538
|
+
};
|
|
539
|
+
const ensureVisible = (index) => {
|
|
540
|
+
const total = datasetItems.value.length;
|
|
541
|
+
if (total === 0) return;
|
|
542
|
+
const itemH = resolveItemH();
|
|
543
|
+
const vpH = resolveVpH();
|
|
544
|
+
const rowTop = index * itemH;
|
|
545
|
+
const rowBottom = rowTop + itemH;
|
|
546
|
+
if (rowTop < scrollTop.value) {
|
|
547
|
+
const offset = resolveTheadOffset();
|
|
548
|
+
scrollToIndex(index, "auto", index > 0 ? offset : 0);
|
|
549
|
+
} else if (rowBottom > scrollTop.value + vpH) {
|
|
550
|
+
const targetScroll = Math.max(0, rowBottom - vpH);
|
|
551
|
+
scrollTop.value = targetScroll;
|
|
552
|
+
if (containerRef.value) {
|
|
553
|
+
containerRef.value.scrollTop = targetScroll;
|
|
554
|
+
}
|
|
555
|
+
}
|
|
556
|
+
};
|
|
557
|
+
const handleKeyDown = (e) => {
|
|
558
|
+
if (!unref(options.virtualScroll)) return;
|
|
559
|
+
const total = datasetItems.value.length;
|
|
560
|
+
if (total === 0) return;
|
|
561
|
+
const itemH = resolveItemH();
|
|
562
|
+
const vpH = resolveVpH();
|
|
563
|
+
const firstInView = Math.floor(scrollTop.value / itemH);
|
|
564
|
+
const lastInView = Math.min(total - 1, Math.floor((scrollTop.value + vpH) / itemH) - 1);
|
|
565
|
+
if (e.key === "ArrowDown") {
|
|
566
|
+
e.preventDefault();
|
|
567
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
568
|
+
focusedIndex.value = Math.min(total - 1, firstInView);
|
|
569
|
+
} else {
|
|
570
|
+
focusedIndex.value = Math.min(total - 1, focusedIndex.value + 1);
|
|
571
|
+
}
|
|
572
|
+
ensureVisible(focusedIndex.value);
|
|
573
|
+
} else if (e.key === "ArrowUp") {
|
|
574
|
+
e.preventDefault();
|
|
575
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
576
|
+
focusedIndex.value = Math.max(0, lastInView);
|
|
577
|
+
} else {
|
|
578
|
+
focusedIndex.value = Math.max(0, focusedIndex.value - 1);
|
|
579
|
+
}
|
|
580
|
+
ensureVisible(focusedIndex.value);
|
|
581
|
+
} else if (e.key === "PageDown") {
|
|
582
|
+
e.preventDefault();
|
|
583
|
+
const step = Math.max(1, Math.floor(vpH / itemH));
|
|
584
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
585
|
+
focusedIndex.value = Math.min(total - 1, firstInView + step);
|
|
586
|
+
} else {
|
|
587
|
+
focusedIndex.value = Math.min(total - 1, focusedIndex.value + step);
|
|
588
|
+
}
|
|
589
|
+
ensureVisible(focusedIndex.value);
|
|
590
|
+
} else if (e.key === "PageUp") {
|
|
591
|
+
e.preventDefault();
|
|
592
|
+
const step = Math.max(1, Math.floor(vpH / itemH));
|
|
593
|
+
if (focusedIndex.value < firstInView || focusedIndex.value > lastInView) {
|
|
594
|
+
focusedIndex.value = Math.max(0, lastInView - step);
|
|
595
|
+
} else {
|
|
596
|
+
focusedIndex.value = Math.max(0, focusedIndex.value - step);
|
|
597
|
+
}
|
|
598
|
+
ensureVisible(focusedIndex.value);
|
|
599
|
+
} else if (e.key === "Home") {
|
|
600
|
+
e.preventDefault();
|
|
601
|
+
focusedIndex.value = 0;
|
|
602
|
+
scrollToIndex(0, "auto", 0);
|
|
603
|
+
} else if (e.key === "End") {
|
|
604
|
+
e.preventDefault();
|
|
605
|
+
focusedIndex.value = total - 1;
|
|
606
|
+
scrollToIndex(total - 1, "auto", theadStickyOffset);
|
|
607
|
+
}
|
|
608
|
+
};
|
|
609
|
+
return {
|
|
610
|
+
// Virtual Scroll & Projection
|
|
611
|
+
datasetItems,
|
|
612
|
+
datatableItems: datasetItems,
|
|
613
|
+
displayRows,
|
|
614
|
+
visibleItems,
|
|
615
|
+
startIndex,
|
|
616
|
+
endIndex,
|
|
617
|
+
topSpacerHeight,
|
|
618
|
+
bottomSpacerHeight,
|
|
619
|
+
totalHeight,
|
|
620
|
+
scrollTop,
|
|
621
|
+
viewportHeight,
|
|
622
|
+
containerRef,
|
|
623
|
+
onScroll,
|
|
624
|
+
scrollToIndex,
|
|
625
|
+
containerCssVars,
|
|
626
|
+
// Delivered Rows Cache & Decryption
|
|
627
|
+
deliveredRowsCache,
|
|
628
|
+
invalidateCache,
|
|
629
|
+
ensureVisiblePagesLoaded,
|
|
630
|
+
isCellEncrypted,
|
|
631
|
+
// Selection Bridge
|
|
632
|
+
rowIdKey,
|
|
633
|
+
getRowKey,
|
|
634
|
+
selectedRows,
|
|
635
|
+
selectAll,
|
|
636
|
+
unselectedRows,
|
|
637
|
+
effectiveSelectAllScope,
|
|
638
|
+
selectedRowIds,
|
|
639
|
+
unselectedRowIds,
|
|
640
|
+
isRowSelected,
|
|
641
|
+
pageSelectedCount,
|
|
642
|
+
isAllSelected,
|
|
643
|
+
isIndeterminate,
|
|
644
|
+
handleSelectAll,
|
|
645
|
+
toggleRow,
|
|
646
|
+
// Keyboard Navigation Bridge
|
|
647
|
+
focusedIndex,
|
|
648
|
+
handleKeyDown,
|
|
649
|
+
ensureVisible,
|
|
650
|
+
// Provider State Bridge (from useDataProvider)
|
|
651
|
+
get rawProvider() {
|
|
652
|
+
return dpBridge.rawProvider;
|
|
653
|
+
},
|
|
654
|
+
pageData: dpBridge.pageData,
|
|
655
|
+
pageRows,
|
|
656
|
+
rowCount: dpBridge.rowCount,
|
|
657
|
+
dpRowCount: dpBridge.rowCount,
|
|
658
|
+
filter: dpBridge.filter,
|
|
659
|
+
dpFilter: dpBridge.filter,
|
|
660
|
+
activeFilter,
|
|
661
|
+
sortList: dpBridge.sortList,
|
|
662
|
+
dpSortList: dpBridge.sortList,
|
|
663
|
+
loading: dpBridge.loading,
|
|
664
|
+
dpLoading: dpBridge.loading,
|
|
665
|
+
initialLoad: dpBridge.initialLoad,
|
|
666
|
+
dpInitialLoad: dpBridge.initialLoad,
|
|
667
|
+
isLoading,
|
|
668
|
+
error: dpBridge.error,
|
|
669
|
+
dpError: dpBridge.error,
|
|
670
|
+
stateVersion: dpBridge.stateVersion,
|
|
671
|
+
dpStateVersion: dpBridge.stateVersion,
|
|
672
|
+
filterSortVersion: dpBridge.filterSortVersion,
|
|
673
|
+
dpFilterSortVersion: dpBridge.filterSortVersion,
|
|
674
|
+
currentPage: dpBridge.currentPage,
|
|
675
|
+
dpCurrentPage: dpBridge.currentPage,
|
|
676
|
+
pageSize: dpBridge.pageSize,
|
|
677
|
+
dpPageSize: dpBridge.pageSize,
|
|
678
|
+
effectivePageSize,
|
|
679
|
+
dpFields,
|
|
680
|
+
setCurrentPage: dpBridge.setCurrentPage,
|
|
681
|
+
setPageSize: dpBridge.setPageSize,
|
|
682
|
+
setFilter: dpBridge.setFilter,
|
|
683
|
+
setSortList: dpBridge.setSortList,
|
|
684
|
+
refresh: dpBridge.refresh,
|
|
685
|
+
loadPageData: dpBridge.loadPageData,
|
|
686
|
+
getState: dpBridge.getState,
|
|
687
|
+
setState: dpBridge.setState
|
|
688
|
+
};
|
|
689
|
+
}
|