cisse-vue-ui 0.8.4 → 0.9.0
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/README.md +666 -4
- package/dist/{CheckboxGroup.vue_vue_type_script_setup_true_lang-B190Yija.js → CheckboxGroup.vue_vue_type_script_setup_true_lang-ZP02bMgY.js} +2 -2
- package/dist/{CheckboxGroup.vue_vue_type_script_setup_true_lang-B190Yija.js.map → CheckboxGroup.vue_vue_type_script_setup_true_lang-ZP02bMgY.js.map} +1 -1
- package/dist/{ConfirmDialog.vue_vue_type_script_setup_true_lang-DWs2V7xX.js → ConfirmDialog.vue_vue_type_script_setup_true_lang-C5KHLMvx.js} +37 -184
- package/dist/ConfirmDialog.vue_vue_type_script_setup_true_lang-C5KHLMvx.js.map +1 -0
- package/dist/{ConfirmDialog.vue_vue_type_script_setup_true_lang-BGUoa5fT.cjs → ConfirmDialog.vue_vue_type_script_setup_true_lang-CLfy0-Wb.cjs} +33 -180
- package/dist/ConfirmDialog.vue_vue_type_script_setup_true_lang-CLfy0-Wb.cjs.map +1 -0
- package/dist/{FilterTabs.vue_vue_type_script_setup_true_lang-DYxh-wFx.cjs → FilterTabs.vue_vue_type_script_setup_true_lang-COkZbeGG.cjs} +1259 -208
- package/dist/FilterTabs.vue_vue_type_script_setup_true_lang-COkZbeGG.cjs.map +1 -0
- package/dist/{FilterTabs.vue_vue_type_script_setup_true_lang-BmJHgkBs.js → FilterTabs.vue_vue_type_script_setup_true_lang-CzpYHtc5.js} +1268 -217
- package/dist/FilterTabs.vue_vue_type_script_setup_true_lang-CzpYHtc5.js.map +1 -0
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-BHopJ9RG.js +298 -0
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-BHopJ9RG.js.map +1 -0
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-Bo3HqgX0.cjs +297 -0
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-Bo3HqgX0.cjs.map +1 -0
- package/dist/components/core/AccordionItem.test.d.ts +1 -0
- package/dist/components/core/Breadcrumb.stories.d.ts +5 -0
- package/dist/components/core/CardWrapper.stories.d.ts +32 -0
- package/dist/components/core/CardWrapper.test.d.ts +1 -0
- package/dist/components/core/CardWrapper.vue.d.ts +129 -0
- package/dist/components/core/CollapsibleCard.vue.d.ts +1 -1
- package/dist/components/core/DataTable.stories.d.ts +38 -0
- package/dist/components/core/Dropdown.vue.d.ts +1 -1
- package/dist/components/core/Popover.vue.d.ts +2 -2
- package/dist/components/core/Tooltip.stories.d.ts +3 -0
- package/dist/components/core/index.cjs +39 -22
- package/dist/components/core/index.cjs.map +1 -1
- package/dist/components/core/index.d.ts +4 -1
- package/dist/components/core/index.js +39 -22
- package/dist/components/core/table/DataTable.test.d.ts +1 -0
- package/dist/components/core/{TableComponent.vue.d.ts → table/DataTable.vue.d.ts} +60 -7
- package/dist/components/core/table/Table.stories.d.ts +27 -0
- package/dist/components/core/table/atoms/Caption.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Caption.vue.d.ts +26 -0
- package/dist/components/core/table/atoms/Col.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Col.vue.d.ts +8 -0
- package/dist/components/core/table/atoms/Colgroup.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Colgroup.vue.d.ts +17 -0
- package/dist/components/core/table/atoms/Table.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Table.vue.d.ts +46 -0
- package/dist/components/core/table/atoms/Tbody.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Tbody.vue.d.ts +17 -0
- package/dist/components/core/table/atoms/Td.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Td.vue.d.ts +43 -0
- package/dist/components/core/table/atoms/Tfoot.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Tfoot.vue.d.ts +17 -0
- package/dist/components/core/table/atoms/Th.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Th.vue.d.ts +64 -0
- package/dist/components/core/table/atoms/Thead.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Thead.vue.d.ts +17 -0
- package/dist/components/core/table/atoms/Tr.test.d.ts +1 -0
- package/dist/components/core/table/atoms/Tr.vue.d.ts +35 -0
- package/dist/components/core/table/atoms/index.d.ts +10 -0
- package/dist/components/core/table/index.d.ts +3 -0
- package/dist/components/core/table/molecules/ExpandableRow.test.d.ts +1 -0
- package/dist/components/core/table/molecules/ExpandableRow.vue.d.ts +47 -0
- package/dist/components/core/table/molecules/TableFooter.test.d.ts +1 -0
- package/dist/components/core/table/molecules/TableFooter.vue.d.ts +21 -0
- package/dist/components/core/table/molecules/TableHeader.test.d.ts +1 -0
- package/dist/components/core/table/molecules/TableHeader.vue.d.ts +49 -0
- package/dist/components/core/table/molecules/TableRow.test.d.ts +1 -0
- package/dist/components/core/table/molecules/TableRow.vue.d.ts +59 -0
- package/dist/components/core/table/molecules/index.d.ts +4 -0
- package/dist/components/feedback/Progress.vue.d.ts +1 -1
- package/dist/components/feedback/TableSkeleton.vue.d.ts +1 -1
- package/dist/components/feedback/index.cjs +14 -14
- package/dist/components/feedback/index.js +14 -14
- package/dist/components/form/Combobox.vue.d.ts +1 -1
- package/dist/components/form/DatePicker.vue.d.ts +1 -1
- package/dist/components/form/FormSection.vue.d.ts +1 -1
- package/dist/components/form/IconPicker.stories.d.ts +19 -0
- package/dist/components/form/IconPicker.test.d.ts +1 -0
- package/dist/components/form/InputWrapper.stories.d.ts +0 -5
- package/dist/components/form/Rating.vue.d.ts +1 -1
- package/dist/components/form/SearchInput.vue.d.ts +1 -1
- package/dist/components/form/index.js +2 -2
- package/dist/components/index.cjs +53 -36
- package/dist/components/index.cjs.map +1 -1
- package/dist/components/index.js +65 -48
- package/dist/composables/index.cjs +15 -8
- package/dist/composables/index.cjs.map +1 -1
- package/dist/composables/index.d.ts +7 -0
- package/dist/composables/index.js +12 -5
- package/dist/composables/useColumnResize.d.ts +38 -0
- package/dist/composables/useColumnResize.test.d.ts +1 -0
- package/dist/composables/useColumnVisibility.d.ts +44 -0
- package/dist/composables/useColumnVisibility.test.d.ts +1 -0
- package/dist/composables/useEditableCell.d.ts +51 -0
- package/dist/composables/useEditableCell.test.d.ts +1 -0
- package/dist/composables/usePagination.d.ts +44 -0
- package/dist/composables/usePagination.test.d.ts +1 -0
- package/dist/composables/usePinnedRows.d.ts +41 -0
- package/dist/composables/usePinnedRows.test.d.ts +1 -0
- package/dist/composables/useTableKeyboardNavigation.d.ts +52 -0
- package/dist/composables/useTableKeyboardNavigation.test.d.ts +1 -0
- package/dist/composables/useVirtualScroll.d.ts +32 -0
- package/dist/composables/useVirtualScroll.test.d.ts +1 -0
- package/dist/index-0kwQORZJ.js +114 -0
- package/dist/index-0kwQORZJ.js.map +1 -0
- package/dist/{index-LFQFhClN.cjs → index-BMSH4AOz.cjs} +54 -37
- package/dist/{index-LFQFhClN.cjs.map → index-BMSH4AOz.cjs.map} +1 -1
- package/dist/{index-SNefWfX0.js → index-BaWpldIJ.js} +3 -3
- package/dist/{index-SNefWfX0.js.map → index-BaWpldIJ.js.map} +1 -1
- package/dist/index.cjs +69 -45
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +79 -55
- package/dist/style.css +1 -1
- package/dist/types/components.d.ts +1 -1
- package/dist/types/property.d.ts +8 -0
- package/dist/usePagination-BGwbICFC.js +135 -0
- package/dist/usePagination-BGwbICFC.js.map +1 -0
- package/dist/usePagination-gvvh1zqA.cjs +134 -0
- package/dist/usePagination-gvvh1zqA.cjs.map +1 -0
- package/dist/useVirtualScroll-BivP86fA.cjs +869 -0
- package/dist/useVirtualScroll-BivP86fA.cjs.map +1 -0
- package/dist/useVirtualScroll-YeZru2Eo.js +870 -0
- package/dist/useVirtualScroll-YeZru2Eo.js.map +1 -0
- package/package.json +1 -1
- package/dist/ConfirmDialog.vue_vue_type_script_setup_true_lang-BGUoa5fT.cjs.map +0 -1
- package/dist/ConfirmDialog.vue_vue_type_script_setup_true_lang-DWs2V7xX.js.map +0 -1
- package/dist/FilterTabs.vue_vue_type_script_setup_true_lang-BmJHgkBs.js.map +0 -1
- package/dist/FilterTabs.vue_vue_type_script_setup_true_lang-DYxh-wFx.cjs.map +0 -1
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-BwtEbaiT.js +0 -150
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-BwtEbaiT.js.map +0 -1
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-DtwwmfWr.cjs +0 -149
- package/dist/ListSkeleton.vue_vue_type_script_setup_true_lang-DtwwmfWr.cjs.map +0 -1
- package/dist/components/core/TableComponent.stories.d.ts +0 -16
- package/dist/index-CyL_6V7D.js +0 -97
- package/dist/index-CyL_6V7D.js.map +0 -1
- package/dist/useDarkMode-Cl5QWTlC.js +0 -53
- package/dist/useDarkMode-Cl5QWTlC.js.map +0 -1
- package/dist/useDarkMode-DLZcJEUQ.cjs +0 -52
- package/dist/useDarkMode-DLZcJEUQ.cjs.map +0 -1
- package/dist/useToast-Bk60GArg.cjs +0 -176
- package/dist/useToast-Bk60GArg.cjs.map +0 -1
- package/dist/useToast-ina5g3mj.js +0 -177
- package/dist/useToast-ina5g3mj.js.map +0 -1
|
@@ -0,0 +1,869 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
const vue = require("vue");
|
|
3
|
+
var IDX = 256, HEX = [], SIZE = 256, BUFFER;
|
|
4
|
+
while (IDX--) HEX[IDX] = (IDX + 256).toString(16).substring(1);
|
|
5
|
+
function uid(len) {
|
|
6
|
+
var i = 0, tmp = 11;
|
|
7
|
+
if (!BUFFER || IDX + tmp > SIZE * 2) {
|
|
8
|
+
for (BUFFER = "", IDX = 0; i < SIZE; i++) {
|
|
9
|
+
BUFFER += HEX[Math.random() * 256 | 0];
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return BUFFER.substring(IDX, IDX++ + tmp);
|
|
13
|
+
}
|
|
14
|
+
const notifications = vue.ref([]);
|
|
15
|
+
function useNotifications() {
|
|
16
|
+
const notify = (type, message, options = {}) => {
|
|
17
|
+
const id = uid();
|
|
18
|
+
const notification = {
|
|
19
|
+
id,
|
|
20
|
+
type,
|
|
21
|
+
message,
|
|
22
|
+
title: options.title ?? null,
|
|
23
|
+
duration: options.duration ?? 5e3
|
|
24
|
+
};
|
|
25
|
+
notifications.value.push(notification);
|
|
26
|
+
if (notification.duration && notification.duration > 0) {
|
|
27
|
+
setTimeout(() => remove(id), notification.duration);
|
|
28
|
+
}
|
|
29
|
+
return id;
|
|
30
|
+
};
|
|
31
|
+
const success = (message, options) => notify("success", message, options);
|
|
32
|
+
const warning = (message, options) => notify("warning", message, options);
|
|
33
|
+
const error = (message, options) => notify("error", message, options);
|
|
34
|
+
const info = (message, options) => notify("info", message, options);
|
|
35
|
+
const remove = (id) => {
|
|
36
|
+
notifications.value = notifications.value.filter((n) => n.id !== id);
|
|
37
|
+
};
|
|
38
|
+
const clear = () => {
|
|
39
|
+
notifications.value = [];
|
|
40
|
+
};
|
|
41
|
+
return {
|
|
42
|
+
notifications: vue.readonly(notifications),
|
|
43
|
+
notify,
|
|
44
|
+
success,
|
|
45
|
+
warning,
|
|
46
|
+
error,
|
|
47
|
+
info,
|
|
48
|
+
remove,
|
|
49
|
+
clear
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
function useExportCSV() {
|
|
53
|
+
const escapeCSV = (value) => {
|
|
54
|
+
if (value === null || value === void 0) return "";
|
|
55
|
+
const str = String(value);
|
|
56
|
+
if (str.includes(",") || str.includes('"') || str.includes("\n")) {
|
|
57
|
+
return `"${str.replace(/"/g, '""')}"`;
|
|
58
|
+
}
|
|
59
|
+
return str;
|
|
60
|
+
};
|
|
61
|
+
const exportToCSV = (data, columns, filename = "export.csv") => {
|
|
62
|
+
if (!data || data.length === 0) {
|
|
63
|
+
console.warn("No data to export");
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
const headers = columns.map((col) => escapeCSV(col.label)).join(",");
|
|
67
|
+
const rows = data.map(
|
|
68
|
+
(item) => columns.map((col) => escapeCSV(item[col.key])).join(",")
|
|
69
|
+
);
|
|
70
|
+
const csv = [headers, ...rows].join("\n");
|
|
71
|
+
const blob = new Blob([csv], { type: "text/csv;charset=utf-8;" });
|
|
72
|
+
const url = URL.createObjectURL(blob);
|
|
73
|
+
const link = document.createElement("a");
|
|
74
|
+
link.setAttribute("href", url);
|
|
75
|
+
link.setAttribute("download", filename);
|
|
76
|
+
link.style.visibility = "hidden";
|
|
77
|
+
document.body.appendChild(link);
|
|
78
|
+
link.click();
|
|
79
|
+
document.body.removeChild(link);
|
|
80
|
+
URL.revokeObjectURL(url);
|
|
81
|
+
};
|
|
82
|
+
return {
|
|
83
|
+
exportToCSV,
|
|
84
|
+
escapeCSV
|
|
85
|
+
};
|
|
86
|
+
}
|
|
87
|
+
function useModal(options) {
|
|
88
|
+
const {
|
|
89
|
+
initialOpen = false,
|
|
90
|
+
initialData = null,
|
|
91
|
+
onOpen,
|
|
92
|
+
onClose
|
|
93
|
+
} = options ?? {};
|
|
94
|
+
const isOpen = vue.ref(initialOpen);
|
|
95
|
+
const data = vue.ref(initialData);
|
|
96
|
+
const open = (newData) => {
|
|
97
|
+
data.value = newData ?? null;
|
|
98
|
+
isOpen.value = true;
|
|
99
|
+
onOpen == null ? void 0 : onOpen(data.value);
|
|
100
|
+
};
|
|
101
|
+
const close = () => {
|
|
102
|
+
isOpen.value = false;
|
|
103
|
+
data.value = null;
|
|
104
|
+
onClose == null ? void 0 : onClose();
|
|
105
|
+
};
|
|
106
|
+
const toggle = () => {
|
|
107
|
+
if (isOpen.value) {
|
|
108
|
+
close();
|
|
109
|
+
} else {
|
|
110
|
+
open();
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
return {
|
|
114
|
+
isOpen,
|
|
115
|
+
data,
|
|
116
|
+
open,
|
|
117
|
+
close,
|
|
118
|
+
toggle
|
|
119
|
+
};
|
|
120
|
+
}
|
|
121
|
+
function useModals(modals) {
|
|
122
|
+
return modals;
|
|
123
|
+
}
|
|
124
|
+
const toasts = vue.ref([]);
|
|
125
|
+
let toastId = 0;
|
|
126
|
+
function useToast() {
|
|
127
|
+
const add = (options) => {
|
|
128
|
+
const id = `toast-${++toastId}`;
|
|
129
|
+
const toast = {
|
|
130
|
+
id,
|
|
131
|
+
message: options.message,
|
|
132
|
+
type: options.type || "info",
|
|
133
|
+
title: options.title,
|
|
134
|
+
duration: options.duration ?? 5e3
|
|
135
|
+
};
|
|
136
|
+
toasts.value.push(toast);
|
|
137
|
+
return id;
|
|
138
|
+
};
|
|
139
|
+
const remove = (id) => {
|
|
140
|
+
const index = toasts.value.findIndex((t) => t.id === id);
|
|
141
|
+
if (index > -1) {
|
|
142
|
+
toasts.value.splice(index, 1);
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
const clear = () => {
|
|
146
|
+
toasts.value = [];
|
|
147
|
+
};
|
|
148
|
+
const success = (message, title) => {
|
|
149
|
+
return add({ message, title, type: "success" });
|
|
150
|
+
};
|
|
151
|
+
const error = (message, title) => {
|
|
152
|
+
return add({ message, title, type: "error" });
|
|
153
|
+
};
|
|
154
|
+
const warning = (message, title) => {
|
|
155
|
+
return add({ message, title, type: "warning" });
|
|
156
|
+
};
|
|
157
|
+
const info = (message, title) => {
|
|
158
|
+
return add({ message, title, type: "info" });
|
|
159
|
+
};
|
|
160
|
+
return {
|
|
161
|
+
toasts,
|
|
162
|
+
add,
|
|
163
|
+
remove,
|
|
164
|
+
clear,
|
|
165
|
+
success,
|
|
166
|
+
error,
|
|
167
|
+
warning,
|
|
168
|
+
info
|
|
169
|
+
};
|
|
170
|
+
}
|
|
171
|
+
function useTableKeyboardNavigation(options) {
|
|
172
|
+
const {
|
|
173
|
+
tableRef,
|
|
174
|
+
rowCount,
|
|
175
|
+
colCount,
|
|
176
|
+
cellNavigation = false,
|
|
177
|
+
onRowActivate,
|
|
178
|
+
onCellActivate,
|
|
179
|
+
onFocusChange,
|
|
180
|
+
skipHeader = true,
|
|
181
|
+
wrap = true
|
|
182
|
+
} = options;
|
|
183
|
+
const focusedRow = vue.ref(skipHeader ? 1 : 0);
|
|
184
|
+
const focusedCol = vue.ref(0);
|
|
185
|
+
const isActive = vue.ref(false);
|
|
186
|
+
const totalRows = vue.computed(() => typeof rowCount === "number" ? rowCount : rowCount.value);
|
|
187
|
+
const totalCols = vue.computed(() => typeof colCount === "number" ? colCount : colCount.value);
|
|
188
|
+
const startRow = vue.computed(() => skipHeader ? 1 : 0);
|
|
189
|
+
const clampRow = (row) => {
|
|
190
|
+
if (wrap) {
|
|
191
|
+
if (row < startRow.value) return totalRows.value - 1;
|
|
192
|
+
if (row >= totalRows.value) return startRow.value;
|
|
193
|
+
return row;
|
|
194
|
+
}
|
|
195
|
+
return Math.max(startRow.value, Math.min(totalRows.value - 1, row));
|
|
196
|
+
};
|
|
197
|
+
const clampCol = (col) => {
|
|
198
|
+
if (wrap) {
|
|
199
|
+
if (col < 0) return totalCols.value - 1;
|
|
200
|
+
if (col >= totalCols.value) return 0;
|
|
201
|
+
return col;
|
|
202
|
+
}
|
|
203
|
+
return Math.max(0, Math.min(totalCols.value - 1, col));
|
|
204
|
+
};
|
|
205
|
+
const setFocusedRow = (index) => {
|
|
206
|
+
focusedRow.value = clampRow(index);
|
|
207
|
+
onFocusChange == null ? void 0 : onFocusChange(focusedRow.value, focusedCol.value);
|
|
208
|
+
};
|
|
209
|
+
const setFocusedCell = (row, col) => {
|
|
210
|
+
focusedRow.value = clampRow(row);
|
|
211
|
+
focusedCol.value = clampCol(col);
|
|
212
|
+
onFocusChange == null ? void 0 : onFocusChange(focusedRow.value, focusedCol.value);
|
|
213
|
+
};
|
|
214
|
+
const activate = () => {
|
|
215
|
+
isActive.value = true;
|
|
216
|
+
focusCurrentElement();
|
|
217
|
+
};
|
|
218
|
+
const deactivate = () => {
|
|
219
|
+
isActive.value = false;
|
|
220
|
+
};
|
|
221
|
+
const focusCurrentElement = () => {
|
|
222
|
+
if (!tableRef.value) return;
|
|
223
|
+
const selector = cellNavigation ? `tr:nth-child(${focusedRow.value + 1}) td:nth-child(${focusedCol.value + 1}), tr:nth-child(${focusedRow.value + 1}) th:nth-child(${focusedCol.value + 1})` : `tr:nth-child(${focusedRow.value + 1})`;
|
|
224
|
+
const element = tableRef.value.querySelector(selector);
|
|
225
|
+
element == null ? void 0 : element.focus();
|
|
226
|
+
};
|
|
227
|
+
const handleKeyDown = (event) => {
|
|
228
|
+
if (!isActive.value) return;
|
|
229
|
+
const { key, shiftKey, ctrlKey, metaKey } = event;
|
|
230
|
+
if (ctrlKey || metaKey) return;
|
|
231
|
+
let handled = false;
|
|
232
|
+
switch (key) {
|
|
233
|
+
case "ArrowDown":
|
|
234
|
+
setFocusedRow(focusedRow.value + 1);
|
|
235
|
+
handled = true;
|
|
236
|
+
break;
|
|
237
|
+
case "ArrowUp":
|
|
238
|
+
setFocusedRow(focusedRow.value - 1);
|
|
239
|
+
handled = true;
|
|
240
|
+
break;
|
|
241
|
+
case "ArrowRight":
|
|
242
|
+
if (cellNavigation) {
|
|
243
|
+
setFocusedCell(focusedRow.value, focusedCol.value + 1);
|
|
244
|
+
handled = true;
|
|
245
|
+
}
|
|
246
|
+
break;
|
|
247
|
+
case "ArrowLeft":
|
|
248
|
+
if (cellNavigation) {
|
|
249
|
+
setFocusedCell(focusedRow.value, focusedCol.value - 1);
|
|
250
|
+
handled = true;
|
|
251
|
+
}
|
|
252
|
+
break;
|
|
253
|
+
case "Home":
|
|
254
|
+
if (cellNavigation) {
|
|
255
|
+
setFocusedCell(shiftKey ? startRow.value : focusedRow.value, 0);
|
|
256
|
+
} else {
|
|
257
|
+
setFocusedRow(startRow.value);
|
|
258
|
+
}
|
|
259
|
+
handled = true;
|
|
260
|
+
break;
|
|
261
|
+
case "End":
|
|
262
|
+
if (cellNavigation) {
|
|
263
|
+
setFocusedCell(
|
|
264
|
+
shiftKey ? totalRows.value - 1 : focusedRow.value,
|
|
265
|
+
totalCols.value - 1
|
|
266
|
+
);
|
|
267
|
+
} else {
|
|
268
|
+
setFocusedRow(totalRows.value - 1);
|
|
269
|
+
}
|
|
270
|
+
handled = true;
|
|
271
|
+
break;
|
|
272
|
+
case "PageDown":
|
|
273
|
+
setFocusedRow(focusedRow.value + 10);
|
|
274
|
+
handled = true;
|
|
275
|
+
break;
|
|
276
|
+
case "PageUp":
|
|
277
|
+
setFocusedRow(focusedRow.value - 10);
|
|
278
|
+
handled = true;
|
|
279
|
+
break;
|
|
280
|
+
case "Enter":
|
|
281
|
+
case " ":
|
|
282
|
+
if (cellNavigation) {
|
|
283
|
+
onCellActivate == null ? void 0 : onCellActivate(focusedRow.value, focusedCol.value);
|
|
284
|
+
} else {
|
|
285
|
+
onRowActivate == null ? void 0 : onRowActivate(focusedRow.value);
|
|
286
|
+
}
|
|
287
|
+
handled = true;
|
|
288
|
+
break;
|
|
289
|
+
case "Escape":
|
|
290
|
+
deactivate();
|
|
291
|
+
handled = true;
|
|
292
|
+
break;
|
|
293
|
+
case "Tab":
|
|
294
|
+
deactivate();
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
if (handled) {
|
|
298
|
+
event.preventDefault();
|
|
299
|
+
event.stopPropagation();
|
|
300
|
+
focusCurrentElement();
|
|
301
|
+
}
|
|
302
|
+
};
|
|
303
|
+
const getRowProps = (rowIndex) => ({
|
|
304
|
+
tabIndex: focusedRow.value === rowIndex && isActive.value ? 0 : -1,
|
|
305
|
+
"aria-selected": focusedRow.value === rowIndex ? true : void 0,
|
|
306
|
+
onFocus: () => {
|
|
307
|
+
if (!isActive.value) {
|
|
308
|
+
isActive.value = true;
|
|
309
|
+
}
|
|
310
|
+
focusedRow.value = rowIndex;
|
|
311
|
+
}
|
|
312
|
+
});
|
|
313
|
+
const getCellProps = (rowIndex, colIndex) => ({
|
|
314
|
+
tabIndex: focusedRow.value === rowIndex && focusedCol.value === colIndex && isActive.value ? 0 : -1,
|
|
315
|
+
"aria-selected": focusedRow.value === rowIndex && focusedCol.value === colIndex ? true : void 0,
|
|
316
|
+
onFocus: () => {
|
|
317
|
+
if (!isActive.value) {
|
|
318
|
+
isActive.value = true;
|
|
319
|
+
}
|
|
320
|
+
focusedRow.value = rowIndex;
|
|
321
|
+
focusedCol.value = colIndex;
|
|
322
|
+
}
|
|
323
|
+
});
|
|
324
|
+
const handleTableFocus = () => {
|
|
325
|
+
if (!isActive.value) {
|
|
326
|
+
activate();
|
|
327
|
+
}
|
|
328
|
+
};
|
|
329
|
+
vue.onMounted(() => {
|
|
330
|
+
var _a;
|
|
331
|
+
(_a = tableRef.value) == null ? void 0 : _a.addEventListener("focus", handleTableFocus, true);
|
|
332
|
+
});
|
|
333
|
+
vue.onUnmounted(() => {
|
|
334
|
+
var _a;
|
|
335
|
+
(_a = tableRef.value) == null ? void 0 : _a.removeEventListener("focus", handleTableFocus, true);
|
|
336
|
+
});
|
|
337
|
+
return {
|
|
338
|
+
focusedRow,
|
|
339
|
+
focusedCol,
|
|
340
|
+
isActive,
|
|
341
|
+
setFocusedRow,
|
|
342
|
+
setFocusedCell,
|
|
343
|
+
activate,
|
|
344
|
+
deactivate,
|
|
345
|
+
getRowProps,
|
|
346
|
+
getCellProps,
|
|
347
|
+
handleKeyDown
|
|
348
|
+
};
|
|
349
|
+
}
|
|
350
|
+
function useColumnVisibility(options) {
|
|
351
|
+
const {
|
|
352
|
+
columns: columnsOption,
|
|
353
|
+
initialHidden = [],
|
|
354
|
+
persist = false,
|
|
355
|
+
storageKey = "table-column-visibility",
|
|
356
|
+
minVisible = 1
|
|
357
|
+
} = options;
|
|
358
|
+
const loadInitialState = () => {
|
|
359
|
+
if (persist && typeof window !== "undefined") {
|
|
360
|
+
try {
|
|
361
|
+
const stored = localStorage.getItem(storageKey);
|
|
362
|
+
if (stored) {
|
|
363
|
+
return new Set(JSON.parse(stored));
|
|
364
|
+
}
|
|
365
|
+
} catch {
|
|
366
|
+
}
|
|
367
|
+
}
|
|
368
|
+
return new Set(initialHidden);
|
|
369
|
+
};
|
|
370
|
+
const hiddenColumns = vue.ref(loadInitialState());
|
|
371
|
+
const saveState = () => {
|
|
372
|
+
if (persist && typeof window !== "undefined") {
|
|
373
|
+
try {
|
|
374
|
+
localStorage.setItem(storageKey, JSON.stringify([...hiddenColumns.value]));
|
|
375
|
+
} catch {
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
};
|
|
379
|
+
const rawColumns = vue.computed(() => {
|
|
380
|
+
const cols = "value" in columnsOption ? columnsOption.value : columnsOption;
|
|
381
|
+
return cols;
|
|
382
|
+
});
|
|
383
|
+
const columns = vue.computed(() => {
|
|
384
|
+
return rawColumns.value.map((col) => ({
|
|
385
|
+
...col,
|
|
386
|
+
hidden: hiddenColumns.value.has(col.name)
|
|
387
|
+
}));
|
|
388
|
+
});
|
|
389
|
+
const visibleColumns = vue.computed(() => {
|
|
390
|
+
return columns.value.filter((col) => !col.hidden);
|
|
391
|
+
});
|
|
392
|
+
const isVisible = (columnName) => {
|
|
393
|
+
return !hiddenColumns.value.has(columnName);
|
|
394
|
+
};
|
|
395
|
+
const show = (columnName) => {
|
|
396
|
+
hiddenColumns.value.delete(columnName);
|
|
397
|
+
hiddenColumns.value = new Set(hiddenColumns.value);
|
|
398
|
+
saveState();
|
|
399
|
+
};
|
|
400
|
+
const hide = (columnName) => {
|
|
401
|
+
if (visibleColumns.value.length <= minVisible) {
|
|
402
|
+
return;
|
|
403
|
+
}
|
|
404
|
+
hiddenColumns.value.add(columnName);
|
|
405
|
+
hiddenColumns.value = new Set(hiddenColumns.value);
|
|
406
|
+
saveState();
|
|
407
|
+
};
|
|
408
|
+
const toggle = (columnName) => {
|
|
409
|
+
if (isVisible(columnName)) {
|
|
410
|
+
hide(columnName);
|
|
411
|
+
} else {
|
|
412
|
+
show(columnName);
|
|
413
|
+
}
|
|
414
|
+
};
|
|
415
|
+
const showAll = () => {
|
|
416
|
+
hiddenColumns.value = /* @__PURE__ */ new Set();
|
|
417
|
+
saveState();
|
|
418
|
+
};
|
|
419
|
+
const hideAll = () => {
|
|
420
|
+
const columnsToKeep = rawColumns.value.slice(0, minVisible).map((c) => c.name);
|
|
421
|
+
const newHidden = new Set(
|
|
422
|
+
rawColumns.value.filter((c) => !columnsToKeep.includes(c.name)).map((c) => c.name)
|
|
423
|
+
);
|
|
424
|
+
hiddenColumns.value = newHidden;
|
|
425
|
+
saveState();
|
|
426
|
+
};
|
|
427
|
+
const reset = () => {
|
|
428
|
+
hiddenColumns.value = new Set(initialHidden);
|
|
429
|
+
saveState();
|
|
430
|
+
};
|
|
431
|
+
const setVisibility = (visibility) => {
|
|
432
|
+
const newHidden = /* @__PURE__ */ new Set();
|
|
433
|
+
let visibleCount = 0;
|
|
434
|
+
for (const col of rawColumns.value) {
|
|
435
|
+
const shouldBeVisible = visibility[col.name] ?? true;
|
|
436
|
+
if (shouldBeVisible) {
|
|
437
|
+
visibleCount++;
|
|
438
|
+
} else {
|
|
439
|
+
newHidden.add(col.name);
|
|
440
|
+
}
|
|
441
|
+
}
|
|
442
|
+
if (visibleCount < minVisible) {
|
|
443
|
+
let added = 0;
|
|
444
|
+
for (const col of rawColumns.value) {
|
|
445
|
+
if (newHidden.has(col.name)) {
|
|
446
|
+
newHidden.delete(col.name);
|
|
447
|
+
added++;
|
|
448
|
+
if (visibleCount + added >= minVisible) break;
|
|
449
|
+
}
|
|
450
|
+
}
|
|
451
|
+
}
|
|
452
|
+
hiddenColumns.value = newHidden;
|
|
453
|
+
saveState();
|
|
454
|
+
};
|
|
455
|
+
return {
|
|
456
|
+
columns,
|
|
457
|
+
visibleColumns,
|
|
458
|
+
hiddenColumns,
|
|
459
|
+
isVisible,
|
|
460
|
+
show,
|
|
461
|
+
hide,
|
|
462
|
+
toggle,
|
|
463
|
+
showAll,
|
|
464
|
+
hideAll,
|
|
465
|
+
reset,
|
|
466
|
+
setVisibility
|
|
467
|
+
};
|
|
468
|
+
}
|
|
469
|
+
function useColumnResize(options) {
|
|
470
|
+
const {
|
|
471
|
+
columns: columnsOption,
|
|
472
|
+
defaultMinWidth = 50,
|
|
473
|
+
defaultMaxWidth = 1e3,
|
|
474
|
+
storageKey,
|
|
475
|
+
persist = false
|
|
476
|
+
} = options;
|
|
477
|
+
const allColumns = vue.computed(() => {
|
|
478
|
+
return "value" in columnsOption ? columnsOption.value : columnsOption;
|
|
479
|
+
});
|
|
480
|
+
const getInitialWidths = () => {
|
|
481
|
+
const map = /* @__PURE__ */ new Map();
|
|
482
|
+
allColumns.value.forEach((col) => {
|
|
483
|
+
map.set(col.name, col.width);
|
|
484
|
+
});
|
|
485
|
+
return map;
|
|
486
|
+
};
|
|
487
|
+
const loadFromStorage = () => {
|
|
488
|
+
if (!persist || !storageKey) return null;
|
|
489
|
+
try {
|
|
490
|
+
const stored = localStorage.getItem(storageKey);
|
|
491
|
+
if (stored) {
|
|
492
|
+
const parsed = JSON.parse(stored);
|
|
493
|
+
return new Map(Object.entries(parsed));
|
|
494
|
+
}
|
|
495
|
+
} catch {
|
|
496
|
+
}
|
|
497
|
+
return null;
|
|
498
|
+
};
|
|
499
|
+
const saveToStorage = () => {
|
|
500
|
+
if (!persist || !storageKey) return;
|
|
501
|
+
try {
|
|
502
|
+
const obj = Object.fromEntries(widths.value);
|
|
503
|
+
localStorage.setItem(storageKey, JSON.stringify(obj));
|
|
504
|
+
} catch {
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
const widths = vue.ref(loadFromStorage() ?? getInitialWidths());
|
|
508
|
+
vue.watch(
|
|
509
|
+
allColumns,
|
|
510
|
+
(newColumns) => {
|
|
511
|
+
const stored = loadFromStorage();
|
|
512
|
+
newColumns.forEach((col) => {
|
|
513
|
+
if (!widths.value.has(col.name)) {
|
|
514
|
+
widths.value.set(col.name, (stored == null ? void 0 : stored.get(col.name)) ?? col.width);
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
},
|
|
518
|
+
{ deep: true }
|
|
519
|
+
);
|
|
520
|
+
const resizingColumn = vue.ref(null);
|
|
521
|
+
const startX = vue.ref(0);
|
|
522
|
+
const startWidth = vue.ref(0);
|
|
523
|
+
const isResizing = vue.computed(() => resizingColumn.value !== null);
|
|
524
|
+
const columnWidths = vue.computed(() => {
|
|
525
|
+
const result = {};
|
|
526
|
+
widths.value.forEach((width, name) => {
|
|
527
|
+
result[name] = width;
|
|
528
|
+
});
|
|
529
|
+
return result;
|
|
530
|
+
});
|
|
531
|
+
const getWidth = (name) => {
|
|
532
|
+
var _a;
|
|
533
|
+
return widths.value.get(name) ?? ((_a = allColumns.value.find((c) => c.name === name)) == null ? void 0 : _a.width) ?? 100;
|
|
534
|
+
};
|
|
535
|
+
const getColumnConfig = (name) => {
|
|
536
|
+
return allColumns.value.find((c) => c.name === name);
|
|
537
|
+
};
|
|
538
|
+
const setWidth = (name, width) => {
|
|
539
|
+
const config = getColumnConfig(name);
|
|
540
|
+
const minWidth = (config == null ? void 0 : config.minWidth) ?? defaultMinWidth;
|
|
541
|
+
const maxWidth = (config == null ? void 0 : config.maxWidth) ?? defaultMaxWidth;
|
|
542
|
+
const clampedWidth = Math.max(minWidth, Math.min(maxWidth, width));
|
|
543
|
+
const newWidths = new Map(widths.value);
|
|
544
|
+
newWidths.set(name, clampedWidth);
|
|
545
|
+
widths.value = newWidths;
|
|
546
|
+
saveToStorage();
|
|
547
|
+
};
|
|
548
|
+
const handleMouseMove = (event) => {
|
|
549
|
+
if (!resizingColumn.value) return;
|
|
550
|
+
const clientX = "touches" in event ? event.touches[0].clientX : event.clientX;
|
|
551
|
+
const deltaX = clientX - startX.value;
|
|
552
|
+
const newWidth = startWidth.value + deltaX;
|
|
553
|
+
setWidth(resizingColumn.value, newWidth);
|
|
554
|
+
};
|
|
555
|
+
const handleMouseUp = () => {
|
|
556
|
+
resizingColumn.value = null;
|
|
557
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
558
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
559
|
+
document.removeEventListener("touchmove", handleMouseMove);
|
|
560
|
+
document.removeEventListener("touchend", handleMouseUp);
|
|
561
|
+
document.body.style.cursor = "";
|
|
562
|
+
document.body.style.userSelect = "";
|
|
563
|
+
};
|
|
564
|
+
const startResize = (name, event) => {
|
|
565
|
+
event.preventDefault();
|
|
566
|
+
resizingColumn.value = name;
|
|
567
|
+
startX.value = "touches" in event ? event.touches[0].clientX : event.clientX;
|
|
568
|
+
startWidth.value = getWidth(name);
|
|
569
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
570
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
571
|
+
document.addEventListener("touchmove", handleMouseMove);
|
|
572
|
+
document.addEventListener("touchend", handleMouseUp);
|
|
573
|
+
document.body.style.cursor = "col-resize";
|
|
574
|
+
document.body.style.userSelect = "none";
|
|
575
|
+
};
|
|
576
|
+
const reset = () => {
|
|
577
|
+
widths.value = getInitialWidths();
|
|
578
|
+
saveToStorage();
|
|
579
|
+
};
|
|
580
|
+
const resetColumn = (name) => {
|
|
581
|
+
const config = getColumnConfig(name);
|
|
582
|
+
if (config) {
|
|
583
|
+
setWidth(name, config.width);
|
|
584
|
+
}
|
|
585
|
+
};
|
|
586
|
+
return {
|
|
587
|
+
columnWidths,
|
|
588
|
+
getWidth,
|
|
589
|
+
setWidth,
|
|
590
|
+
startResize,
|
|
591
|
+
isResizing,
|
|
592
|
+
resizingColumn,
|
|
593
|
+
reset,
|
|
594
|
+
resetColumn
|
|
595
|
+
};
|
|
596
|
+
}
|
|
597
|
+
function usePinnedRows(options = {}) {
|
|
598
|
+
const {
|
|
599
|
+
keyField = "id",
|
|
600
|
+
initialPinned = [],
|
|
601
|
+
maxPinnedTop = Infinity,
|
|
602
|
+
maxPinnedBottom = Infinity
|
|
603
|
+
} = options;
|
|
604
|
+
const getItemKey = (item) => {
|
|
605
|
+
const key = item[keyField];
|
|
606
|
+
return String(key ?? Math.random());
|
|
607
|
+
};
|
|
608
|
+
const pinnedMap = vue.shallowRef(
|
|
609
|
+
new Map(initialPinned.map((p) => [getItemKey(p.item), p]))
|
|
610
|
+
);
|
|
611
|
+
const pinnedTop = vue.computed(() => {
|
|
612
|
+
const items = [];
|
|
613
|
+
pinnedMap.value.forEach(({ item, position }) => {
|
|
614
|
+
if (position === "top") {
|
|
615
|
+
items.push(item);
|
|
616
|
+
}
|
|
617
|
+
});
|
|
618
|
+
return items;
|
|
619
|
+
});
|
|
620
|
+
const pinnedBottom = vue.computed(() => {
|
|
621
|
+
const items = [];
|
|
622
|
+
pinnedMap.value.forEach(({ item, position }) => {
|
|
623
|
+
if (position === "bottom") {
|
|
624
|
+
items.push(item);
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
return items;
|
|
628
|
+
});
|
|
629
|
+
const pinnedKeys = vue.computed(() => {
|
|
630
|
+
return new Set(pinnedMap.value.keys());
|
|
631
|
+
});
|
|
632
|
+
const isPinned = (item) => {
|
|
633
|
+
return pinnedMap.value.has(getItemKey(item));
|
|
634
|
+
};
|
|
635
|
+
const getPinPosition = (item) => {
|
|
636
|
+
const pinned = pinnedMap.value.get(getItemKey(item));
|
|
637
|
+
return (pinned == null ? void 0 : pinned.position) ?? null;
|
|
638
|
+
};
|
|
639
|
+
const pin = (item, position) => {
|
|
640
|
+
const currentCount = position === "top" ? pinnedTop.value.length : pinnedBottom.value.length;
|
|
641
|
+
const maxCount = position === "top" ? maxPinnedTop : maxPinnedBottom;
|
|
642
|
+
if (currentCount >= maxCount && getPinPosition(item) !== position) {
|
|
643
|
+
return;
|
|
644
|
+
}
|
|
645
|
+
const key = getItemKey(item);
|
|
646
|
+
const newMap = new Map(pinnedMap.value);
|
|
647
|
+
newMap.set(key, { item, position });
|
|
648
|
+
pinnedMap.value = newMap;
|
|
649
|
+
};
|
|
650
|
+
const unpin = (item) => {
|
|
651
|
+
const key = getItemKey(item);
|
|
652
|
+
if (pinnedMap.value.has(key)) {
|
|
653
|
+
const newMap = new Map(pinnedMap.value);
|
|
654
|
+
newMap.delete(key);
|
|
655
|
+
pinnedMap.value = newMap;
|
|
656
|
+
}
|
|
657
|
+
};
|
|
658
|
+
const togglePin = (item, position = "top") => {
|
|
659
|
+
if (isPinned(item)) {
|
|
660
|
+
unpin(item);
|
|
661
|
+
} else {
|
|
662
|
+
pin(item, position);
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
const movePin = (item, newPosition) => {
|
|
666
|
+
if (isPinned(item)) {
|
|
667
|
+
pin(item, newPosition);
|
|
668
|
+
}
|
|
669
|
+
};
|
|
670
|
+
const clearAll = () => {
|
|
671
|
+
pinnedMap.value = /* @__PURE__ */ new Map();
|
|
672
|
+
};
|
|
673
|
+
const clear = (position) => {
|
|
674
|
+
const newMap = /* @__PURE__ */ new Map();
|
|
675
|
+
pinnedMap.value.forEach((pinned, key) => {
|
|
676
|
+
if (pinned.position !== position) {
|
|
677
|
+
newMap.set(key, pinned);
|
|
678
|
+
}
|
|
679
|
+
});
|
|
680
|
+
pinnedMap.value = newMap;
|
|
681
|
+
};
|
|
682
|
+
return {
|
|
683
|
+
pinnedTop,
|
|
684
|
+
pinnedBottom,
|
|
685
|
+
pinnedKeys,
|
|
686
|
+
isPinned,
|
|
687
|
+
getPinPosition,
|
|
688
|
+
pin,
|
|
689
|
+
unpin,
|
|
690
|
+
togglePin,
|
|
691
|
+
movePin,
|
|
692
|
+
clearAll,
|
|
693
|
+
clear
|
|
694
|
+
};
|
|
695
|
+
}
|
|
696
|
+
function useEditableCell(options = {}) {
|
|
697
|
+
const {
|
|
698
|
+
keyField = "id",
|
|
699
|
+
onSave,
|
|
700
|
+
onCancel,
|
|
701
|
+
validate
|
|
702
|
+
} = options;
|
|
703
|
+
const editingCell = vue.ref(null);
|
|
704
|
+
const editValue = vue.ref(null);
|
|
705
|
+
const error = vue.ref(null);
|
|
706
|
+
const saving = vue.ref(false);
|
|
707
|
+
const currentItem = vue.ref(null);
|
|
708
|
+
const originalValue = vue.ref(null);
|
|
709
|
+
const getItemKey = (item) => {
|
|
710
|
+
const key = item[keyField];
|
|
711
|
+
return String(key ?? Math.random());
|
|
712
|
+
};
|
|
713
|
+
const isEditing = (rowKey, field) => {
|
|
714
|
+
var _a, _b;
|
|
715
|
+
return ((_a = editingCell.value) == null ? void 0 : _a.rowKey) === rowKey && ((_b = editingCell.value) == null ? void 0 : _b.field) === field;
|
|
716
|
+
};
|
|
717
|
+
const startEdit = (item, field, currentValue) => {
|
|
718
|
+
if (editingCell.value) {
|
|
719
|
+
cancelEdit();
|
|
720
|
+
}
|
|
721
|
+
currentItem.value = item;
|
|
722
|
+
originalValue.value = currentValue;
|
|
723
|
+
editValue.value = currentValue;
|
|
724
|
+
error.value = null;
|
|
725
|
+
editingCell.value = {
|
|
726
|
+
rowKey: getItemKey(item),
|
|
727
|
+
field
|
|
728
|
+
};
|
|
729
|
+
};
|
|
730
|
+
const confirmEdit = async () => {
|
|
731
|
+
if (!editingCell.value || !currentItem.value) return;
|
|
732
|
+
const event = {
|
|
733
|
+
item: currentItem.value,
|
|
734
|
+
field: editingCell.value.field,
|
|
735
|
+
originalValue: originalValue.value,
|
|
736
|
+
newValue: editValue.value
|
|
737
|
+
};
|
|
738
|
+
if (validate) {
|
|
739
|
+
const validationError = validate(event);
|
|
740
|
+
if (validationError) {
|
|
741
|
+
error.value = validationError;
|
|
742
|
+
return;
|
|
743
|
+
}
|
|
744
|
+
}
|
|
745
|
+
saving.value = true;
|
|
746
|
+
error.value = null;
|
|
747
|
+
try {
|
|
748
|
+
if (onSave) {
|
|
749
|
+
await onSave(event);
|
|
750
|
+
}
|
|
751
|
+
editingCell.value = null;
|
|
752
|
+
editValue.value = null;
|
|
753
|
+
currentItem.value = null;
|
|
754
|
+
originalValue.value = null;
|
|
755
|
+
} catch (e) {
|
|
756
|
+
error.value = e instanceof Error ? e.message : "Failed to save";
|
|
757
|
+
} finally {
|
|
758
|
+
saving.value = false;
|
|
759
|
+
}
|
|
760
|
+
};
|
|
761
|
+
const cancelEdit = () => {
|
|
762
|
+
if (editingCell.value && currentItem.value && onCancel) {
|
|
763
|
+
onCancel({
|
|
764
|
+
item: currentItem.value,
|
|
765
|
+
field: editingCell.value.field,
|
|
766
|
+
originalValue: originalValue.value
|
|
767
|
+
});
|
|
768
|
+
}
|
|
769
|
+
editingCell.value = null;
|
|
770
|
+
editValue.value = null;
|
|
771
|
+
error.value = null;
|
|
772
|
+
currentItem.value = null;
|
|
773
|
+
originalValue.value = null;
|
|
774
|
+
};
|
|
775
|
+
const updateValue = (value) => {
|
|
776
|
+
editValue.value = value;
|
|
777
|
+
error.value = null;
|
|
778
|
+
};
|
|
779
|
+
const editingItem = vue.computed(() => currentItem.value);
|
|
780
|
+
return {
|
|
781
|
+
editingCell,
|
|
782
|
+
editValue,
|
|
783
|
+
error,
|
|
784
|
+
saving,
|
|
785
|
+
isEditing,
|
|
786
|
+
startEdit,
|
|
787
|
+
confirmEdit,
|
|
788
|
+
cancelEdit,
|
|
789
|
+
updateValue,
|
|
790
|
+
editingItem
|
|
791
|
+
};
|
|
792
|
+
}
|
|
793
|
+
function useVirtualScroll(options) {
|
|
794
|
+
const {
|
|
795
|
+
items: itemsOption,
|
|
796
|
+
rowHeight,
|
|
797
|
+
containerHeight,
|
|
798
|
+
overscan = 3
|
|
799
|
+
} = options;
|
|
800
|
+
const scrollTop = vue.ref(0);
|
|
801
|
+
const containerRef = vue.ref(null);
|
|
802
|
+
const allItems = vue.computed(() => {
|
|
803
|
+
return "value" in itemsOption ? itemsOption.value : itemsOption;
|
|
804
|
+
});
|
|
805
|
+
const totalHeight = vue.computed(() => {
|
|
806
|
+
return allItems.value.length * rowHeight;
|
|
807
|
+
});
|
|
808
|
+
const visibleCount = vue.computed(() => {
|
|
809
|
+
return Math.ceil(containerHeight / rowHeight);
|
|
810
|
+
});
|
|
811
|
+
const startIndex = vue.computed(() => {
|
|
812
|
+
const rawStart = Math.floor(scrollTop.value / rowHeight);
|
|
813
|
+
return Math.max(0, rawStart - overscan);
|
|
814
|
+
});
|
|
815
|
+
const endIndex = vue.computed(() => {
|
|
816
|
+
const rawEnd = startIndex.value + visibleCount.value + overscan * 2;
|
|
817
|
+
return Math.min(allItems.value.length, rawEnd);
|
|
818
|
+
});
|
|
819
|
+
const visibleItems = vue.computed(() => {
|
|
820
|
+
return allItems.value.slice(startIndex.value, endIndex.value);
|
|
821
|
+
});
|
|
822
|
+
const offsetY = vue.computed(() => {
|
|
823
|
+
return startIndex.value * rowHeight;
|
|
824
|
+
});
|
|
825
|
+
const onScroll = (event) => {
|
|
826
|
+
const target = event.target;
|
|
827
|
+
scrollTop.value = target.scrollTop;
|
|
828
|
+
};
|
|
829
|
+
const scrollToIndex = (index) => {
|
|
830
|
+
const targetScroll = index * rowHeight;
|
|
831
|
+
if (containerRef.value) {
|
|
832
|
+
containerRef.value.scrollTop = targetScroll;
|
|
833
|
+
}
|
|
834
|
+
scrollTop.value = targetScroll;
|
|
835
|
+
};
|
|
836
|
+
vue.onMounted(() => {
|
|
837
|
+
if (containerRef.value) {
|
|
838
|
+
containerRef.value.addEventListener("scroll", onScroll, { passive: true });
|
|
839
|
+
}
|
|
840
|
+
});
|
|
841
|
+
vue.onUnmounted(() => {
|
|
842
|
+
if (containerRef.value) {
|
|
843
|
+
containerRef.value.removeEventListener("scroll", onScroll);
|
|
844
|
+
}
|
|
845
|
+
});
|
|
846
|
+
return {
|
|
847
|
+
visibleItems,
|
|
848
|
+
totalHeight,
|
|
849
|
+
offsetY,
|
|
850
|
+
startIndex,
|
|
851
|
+
endIndex,
|
|
852
|
+
scrollTop,
|
|
853
|
+
onScroll,
|
|
854
|
+
scrollToIndex,
|
|
855
|
+
containerRef
|
|
856
|
+
};
|
|
857
|
+
}
|
|
858
|
+
exports.useColumnResize = useColumnResize;
|
|
859
|
+
exports.useColumnVisibility = useColumnVisibility;
|
|
860
|
+
exports.useEditableCell = useEditableCell;
|
|
861
|
+
exports.useExportCSV = useExportCSV;
|
|
862
|
+
exports.useModal = useModal;
|
|
863
|
+
exports.useModals = useModals;
|
|
864
|
+
exports.useNotifications = useNotifications;
|
|
865
|
+
exports.usePinnedRows = usePinnedRows;
|
|
866
|
+
exports.useTableKeyboardNavigation = useTableKeyboardNavigation;
|
|
867
|
+
exports.useToast = useToast;
|
|
868
|
+
exports.useVirtualScroll = useVirtualScroll;
|
|
869
|
+
//# sourceMappingURL=useVirtualScroll-BivP86fA.cjs.map
|