@varlet/ui 3.17.1 → 3.18.0-alpha.1781190469654
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/es/app-bar/AppBar.mjs +2 -0
- package/es/app-bar/appBar.css +1 -1
- package/es/app-bar/props.mjs +8 -0
- package/es/badge/badge.css +1 -1
- package/es/bottom-navigation-item/BottomNavigationItem.mjs +1 -1
- package/es/bottom-navigation-item/bottomNavigationItem.css +1 -1
- package/es/button/Button.mjs +13 -6
- package/es/button/button.css +1 -1
- package/es/button/props.mjs +2 -0
- package/es/collapse-transition/useCollapseTransition.mjs +27 -8
- package/es/data-table/DataTable.mjs +656 -0
- package/es/data-table/DataTableBodyCell.mjs +210 -0
- package/es/data-table/DataTableHeaderCell.mjs +237 -0
- package/es/data-table/DataTableSfc.css +0 -0
- package/es/data-table/dataTable.css +1 -0
- package/es/data-table/index.mjs +12 -0
- package/es/data-table/props.mjs +94 -0
- package/es/data-table/span.mjs +29 -0
- package/es/data-table/style/index.mjs +17 -0
- package/es/data-table/useBodyRows.mjs +141 -0
- package/es/data-table/useColumnSizes.mjs +175 -0
- package/es/data-table/useColumnsFixedOffsets.mjs +90 -0
- package/es/data-table/useContainerScroll.mjs +35 -0
- package/es/data-table/useExpandRow.mjs +46 -0
- package/es/data-table/useFootRows.mjs +49 -0
- package/es/data-table/useHeaderRows.mjs +113 -0
- package/es/data-table/usePagination.mjs +101 -0
- package/es/data-table/useSelectionColumn.mjs +242 -0
- package/es/data-table/useSorter.mjs +70 -0
- package/es/data-table/useTreeExpand.mjs +69 -0
- package/es/icon/icon.css +1 -1
- package/es/index.bundle.mjs +25 -1
- package/es/index.mjs +21 -1
- package/es/locale/en-US.mjs +3 -1
- package/es/locale/fa-IR.mjs +3 -1
- package/es/locale/ja-JP.mjs +3 -1
- package/es/locale/zh-CN.mjs +3 -1
- package/es/locale/zh-TW.mjs +3 -1
- package/es/menu/Menu.mjs +1 -0
- package/es/menu/menu.css +1 -1
- package/es/menu-select/MenuSelect.mjs +1 -1
- package/es/menu-select/menuSelect.css +1 -1
- package/es/otp-input/OtpInput.mjs +39 -12
- package/es/pagination/pagination.css +1 -1
- package/es/rail-navigation/RailNavigation.mjs +87 -0
- package/es/rail-navigation/RailNavigationSfc.css +0 -0
- package/es/rail-navigation/index.mjs +12 -0
- package/es/rail-navigation/props.mjs +21 -0
- package/es/rail-navigation/provide.mjs +12 -0
- package/es/rail-navigation/railNavigation.css +1 -0
- package/es/rail-navigation/style/index.mjs +3 -0
- package/es/rail-navigation-item/RailNavigationItem.mjs +177 -0
- package/es/rail-navigation-item/RailNavigationItemSfc.css +0 -0
- package/es/rail-navigation-item/index.mjs +12 -0
- package/es/rail-navigation-item/props.mjs +19 -0
- package/es/rail-navigation-item/provide.mjs +17 -0
- package/es/rail-navigation-item/railNavigationItem.css +1 -0
- package/es/rail-navigation-item/style/index.mjs +6 -0
- package/es/select/Select.mjs +1 -1
- package/es/select/select.css +1 -1
- package/es/snackbar/style/index.mjs +1 -1
- package/es/style.mjs +4 -0
- package/es/styles/common.css +1 -1
- package/es/table/Table.mjs +22 -9
- package/es/table/props.mjs +3 -1
- package/es/table/table.css +1 -1
- package/es/themes/dark/appBar.mjs +3 -0
- package/es/themes/dark/bottomNavigationItem.mjs +1 -0
- package/es/themes/dark/button.mjs +3 -0
- package/es/themes/dark/dataTable.mjs +31 -0
- package/es/themes/dark/index.mjs +6 -2
- package/es/themes/dark/railNavigation.mjs +12 -0
- package/es/themes/dark/railNavigationItem.mjs +18 -0
- package/es/themes/dark/table.mjs +4 -1
- package/es/themes/dark/treeMenu.mjs +32 -0
- package/es/themes/md3-dark/appBar.mjs +3 -0
- package/es/themes/md3-dark/bottomNavigationItem.mjs +1 -0
- package/es/themes/md3-dark/button.mjs +3 -0
- package/es/themes/md3-dark/dataTable.mjs +31 -0
- package/es/themes/md3-dark/index.mjs +6 -2
- package/es/themes/md3-dark/railNavigation.mjs +12 -0
- package/es/themes/md3-dark/railNavigationItem.mjs +18 -0
- package/es/themes/md3-dark/table.mjs +4 -1
- package/es/themes/md3-dark/treeMenu.mjs +32 -0
- package/es/themes/md3-light/appBar.mjs +3 -0
- package/es/themes/md3-light/bottomNavigationItem.mjs +1 -0
- package/es/themes/md3-light/button.mjs +3 -0
- package/es/themes/md3-light/dataTable.mjs +31 -0
- package/es/themes/md3-light/index.mjs +6 -2
- package/es/themes/md3-light/pagination.mjs +1 -1
- package/es/themes/md3-light/railNavigation.mjs +12 -0
- package/es/themes/md3-light/railNavigationItem.mjs +18 -0
- package/es/themes/md3-light/table.mjs +4 -1
- package/es/themes/md3-light/treeMenu.mjs +32 -0
- package/es/tree-menu/TreeMenu.mjs +223 -0
- package/es/tree-menu/TreeMenuOption.mjs +206 -0
- package/es/tree-menu/TreeMenuSfc.css +0 -0
- package/es/tree-menu/index.mjs +12 -0
- package/es/tree-menu/props.mjs +40 -0
- package/es/tree-menu/style/index.mjs +6 -0
- package/es/tree-menu/treeMenu.css +1 -0
- package/es/varlet.css +1 -1
- package/es/varlet.esm.js +11262 -8955
- package/highlight/web-types.en-US.json +414 -1
- package/highlight/web-types.zh-CN.json +148 -1
- package/lib/varlet.cjs.js +10836 -8015
- package/lib/varlet.css +1 -1
- package/package.json +7 -7
- package/types/appBar.d.ts +6 -0
- package/types/button.d.ts +2 -0
- package/types/buttonGroup.d.ts +1 -1
- package/types/dataTable.d.ts +173 -0
- package/types/index.d.ts +8 -0
- package/types/railNavigation.d.ts +27 -0
- package/types/railNavigationItem.d.ts +38 -0
- package/types/styleVars.d.ts +84 -0
- package/types/table.d.ts +2 -0
- package/types/treeMenu.d.ts +80 -0
- package/umd/varlet.js +7 -7
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { call, clamp, isBoolean } from "@varlet/shared";
|
|
21
|
+
import { computed, watch } from "vue";
|
|
22
|
+
const defaultPaginationOptions = {
|
|
23
|
+
simple: false,
|
|
24
|
+
disabled: false,
|
|
25
|
+
showSizeChanger: false,
|
|
26
|
+
showQuickJumper: false,
|
|
27
|
+
maxPagerCount: 5,
|
|
28
|
+
sizeOption: [10, 20, 50, 100],
|
|
29
|
+
showTotal: void 0
|
|
30
|
+
};
|
|
31
|
+
function usePagination({
|
|
32
|
+
pagination,
|
|
33
|
+
remote,
|
|
34
|
+
loading,
|
|
35
|
+
page,
|
|
36
|
+
pageSize,
|
|
37
|
+
total,
|
|
38
|
+
data,
|
|
39
|
+
onUpdatePage
|
|
40
|
+
}) {
|
|
41
|
+
const paginationProps = computed(() => {
|
|
42
|
+
const resolvedPagination = pagination();
|
|
43
|
+
if (isBoolean(resolvedPagination)) {
|
|
44
|
+
return __spreadProps(__spreadValues({}, defaultPaginationOptions), {
|
|
45
|
+
disabled: loading()
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return __spreadProps(__spreadValues(__spreadValues({}, defaultPaginationOptions), resolvedPagination), {
|
|
49
|
+
disabled: loading() || resolvedPagination.disabled === true
|
|
50
|
+
});
|
|
51
|
+
});
|
|
52
|
+
const paginationTotal = computed(() => {
|
|
53
|
+
var _a;
|
|
54
|
+
if (pagination() === false) {
|
|
55
|
+
return data().length;
|
|
56
|
+
}
|
|
57
|
+
return remote() ? (_a = total()) != null ? _a : 0 : data().length;
|
|
58
|
+
});
|
|
59
|
+
const showPagination = computed(() => {
|
|
60
|
+
return pagination() !== false && paginationTotal.value > 0;
|
|
61
|
+
});
|
|
62
|
+
const pageCount = computed(() => {
|
|
63
|
+
if (!showPagination.value) {
|
|
64
|
+
return 1;
|
|
65
|
+
}
|
|
66
|
+
return clamp(Math.ceil(paginationTotal.value / pageSize()), 1, Number.MAX_SAFE_INTEGER);
|
|
67
|
+
});
|
|
68
|
+
const normalizedPage = computed(() => {
|
|
69
|
+
if (!showPagination.value) {
|
|
70
|
+
return 1;
|
|
71
|
+
}
|
|
72
|
+
return clamp(page(), 1, pageCount.value);
|
|
73
|
+
});
|
|
74
|
+
const pagedData = computed(() => {
|
|
75
|
+
if (!showPagination.value || remote()) {
|
|
76
|
+
return data();
|
|
77
|
+
}
|
|
78
|
+
const start = (normalizedPage.value - 1) * pageSize();
|
|
79
|
+
return data().slice(start, start + pageSize());
|
|
80
|
+
});
|
|
81
|
+
watch(
|
|
82
|
+
[pagination, remote, total, page, normalizedPage],
|
|
83
|
+
([currentPagination, currentRemote, currentTotal, currentPage, nextPage]) => {
|
|
84
|
+
if (currentPagination === false || currentRemote && currentTotal == null || currentPage === nextPage) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
call(onUpdatePage == null ? void 0 : onUpdatePage(), nextPage);
|
|
88
|
+
},
|
|
89
|
+
{ immediate: true }
|
|
90
|
+
);
|
|
91
|
+
return {
|
|
92
|
+
paginationProps,
|
|
93
|
+
paginationTotal,
|
|
94
|
+
showPagination,
|
|
95
|
+
normalizedPage,
|
|
96
|
+
pagedData
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
export {
|
|
100
|
+
usePagination
|
|
101
|
+
};
|
|
@@ -0,0 +1,242 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { computed } from "vue";
|
|
21
|
+
function useSelectionColumn({
|
|
22
|
+
columns,
|
|
23
|
+
tree,
|
|
24
|
+
cascade,
|
|
25
|
+
pagedData,
|
|
26
|
+
allFlatRows,
|
|
27
|
+
treeRowMeta,
|
|
28
|
+
checkedRowKeys,
|
|
29
|
+
isSelectionColumn,
|
|
30
|
+
getTreeChildren
|
|
31
|
+
}) {
|
|
32
|
+
const selectionColumn = computed(() => columns().find(isSelectionColumn));
|
|
33
|
+
const cascadeSelectionEnabled = computed(() => {
|
|
34
|
+
return tree() && cascade() && !!selectionColumn.value && isMultipleSelectionColumn(selectionColumn.value);
|
|
35
|
+
});
|
|
36
|
+
const checkedRowKeySet = computed(() => new Set(checkedRowKeys.value));
|
|
37
|
+
const treeSelectionStates = computed(() => {
|
|
38
|
+
const states = /* @__PURE__ */ new Map();
|
|
39
|
+
const column = selectionColumn.value;
|
|
40
|
+
if (!column) {
|
|
41
|
+
return states;
|
|
42
|
+
}
|
|
43
|
+
for (const row of pagedData()) {
|
|
44
|
+
visit(row);
|
|
45
|
+
}
|
|
46
|
+
function visit(row) {
|
|
47
|
+
const flatRow = treeRowMeta().rowByObject.get(row);
|
|
48
|
+
if (!flatRow) {
|
|
49
|
+
return {
|
|
50
|
+
checked: false,
|
|
51
|
+
indeterminate: false,
|
|
52
|
+
selectable: false
|
|
53
|
+
};
|
|
54
|
+
}
|
|
55
|
+
const children = getTreeChildren(row);
|
|
56
|
+
const childStates = children.map(visit);
|
|
57
|
+
const selectable = isRowSelectable(row, flatRow.rowIndex, column);
|
|
58
|
+
const selfChecked = checkedRowKeySet.value.has(flatRow.key);
|
|
59
|
+
if (!cascadeSelectionEnabled.value || childStates.length === 0) {
|
|
60
|
+
const state2 = {
|
|
61
|
+
checked: selfChecked,
|
|
62
|
+
indeterminate: false
|
|
63
|
+
};
|
|
64
|
+
states.set(flatRow.key, state2);
|
|
65
|
+
return __spreadProps(__spreadValues({}, state2), {
|
|
66
|
+
selectable
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
const selectableChildren = childStates.filter((childState) => childState.selectable);
|
|
70
|
+
const allChildrenChecked = selectableChildren.length > 0 ? selectableChildren.every((childState) => childState.checked) : selfChecked;
|
|
71
|
+
const someChildrenSelected = selectableChildren.some(
|
|
72
|
+
(childState) => childState.checked || childState.indeterminate
|
|
73
|
+
);
|
|
74
|
+
const state = {
|
|
75
|
+
checked: selectable ? allChildrenChecked : false,
|
|
76
|
+
indeterminate: selectableChildren.length > 0 && !allChildrenChecked && someChildrenSelected
|
|
77
|
+
};
|
|
78
|
+
states.set(flatRow.key, state);
|
|
79
|
+
return __spreadProps(__spreadValues({}, state), {
|
|
80
|
+
selectable: selectable || selectableChildren.length > 0
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
return states;
|
|
84
|
+
});
|
|
85
|
+
const currentSelectableRows = computed(() => {
|
|
86
|
+
const column = selectionColumn.value;
|
|
87
|
+
if (!column) {
|
|
88
|
+
return [];
|
|
89
|
+
}
|
|
90
|
+
return allFlatRows().filter((flatRow) => isRowSelectable(flatRow.row, flatRow.rowIndex, column));
|
|
91
|
+
});
|
|
92
|
+
const allCurrentRowsSelected = computed(() => {
|
|
93
|
+
return currentSelectableRows.value.length > 0 && currentSelectableRows.value.every((flatRow) => {
|
|
94
|
+
return isRowKeySelected(flatRow.key);
|
|
95
|
+
});
|
|
96
|
+
});
|
|
97
|
+
const someCurrentRowsSelected = computed(() => {
|
|
98
|
+
return currentSelectableRows.value.some(
|
|
99
|
+
(flatRow) => isRowKeySelected(flatRow.key) || isRowKeyIndeterminate(flatRow.key)
|
|
100
|
+
) && !allCurrentRowsSelected.value;
|
|
101
|
+
});
|
|
102
|
+
function isMultipleSelectionColumn(column) {
|
|
103
|
+
return column.multiple !== false;
|
|
104
|
+
}
|
|
105
|
+
function isSelectionColumnSelectable(column) {
|
|
106
|
+
return column.selectable !== false;
|
|
107
|
+
}
|
|
108
|
+
function isRowSelectable(row, rowIndex, column) {
|
|
109
|
+
if (!column || column.selectable == null || column.selectable === true) {
|
|
110
|
+
return true;
|
|
111
|
+
}
|
|
112
|
+
if (column.selectable === false) {
|
|
113
|
+
return false;
|
|
114
|
+
}
|
|
115
|
+
return column.selectable({
|
|
116
|
+
row,
|
|
117
|
+
rowIndex
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
function updateCheckedRowKeys(value) {
|
|
121
|
+
checkedRowKeys.value = value;
|
|
122
|
+
}
|
|
123
|
+
function isRowKeySelected(key) {
|
|
124
|
+
var _a, _b;
|
|
125
|
+
return (_b = (_a = treeSelectionStates.value.get(key)) == null ? void 0 : _a.checked) != null ? _b : checkedRowKeySet.value.has(key);
|
|
126
|
+
}
|
|
127
|
+
function isRowKeyIndeterminate(key) {
|
|
128
|
+
var _a, _b;
|
|
129
|
+
return (_b = (_a = treeSelectionStates.value.get(key)) == null ? void 0 : _a.indeterminate) != null ? _b : false;
|
|
130
|
+
}
|
|
131
|
+
function toggleRowSelection(bodyRow, selected) {
|
|
132
|
+
const column = selectionColumn.value;
|
|
133
|
+
if (!column || !isSelectionColumnSelectable(column) || !isRowSelectable(bodyRow.row, bodyRow.rowIndex, column)) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
if (!isMultipleSelectionColumn(column)) {
|
|
137
|
+
updateCheckedRowKeys(
|
|
138
|
+
selected ? [bodyRow.key] : checkedRowKeys.value.filter((key) => {
|
|
139
|
+
return key !== bodyRow.key;
|
|
140
|
+
})
|
|
141
|
+
);
|
|
142
|
+
return;
|
|
143
|
+
}
|
|
144
|
+
const nextKeys = new Set(checkedRowKeys.value);
|
|
145
|
+
if (cascadeSelectionEnabled.value) {
|
|
146
|
+
for (const key of collectSelectableBranchKeys(bodyRow.row)) {
|
|
147
|
+
if (selected) {
|
|
148
|
+
nextKeys.add(key);
|
|
149
|
+
} else {
|
|
150
|
+
nextKeys.delete(key);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
syncAncestorSelection(nextKeys, bodyRow.key);
|
|
154
|
+
} else if (selected) {
|
|
155
|
+
nextKeys.add(bodyRow.key);
|
|
156
|
+
} else {
|
|
157
|
+
nextKeys.delete(bodyRow.key);
|
|
158
|
+
}
|
|
159
|
+
updateCheckedRowKeys([...nextKeys]);
|
|
160
|
+
}
|
|
161
|
+
function toggleCurrentSelectableRows(selected) {
|
|
162
|
+
const column = selectionColumn.value;
|
|
163
|
+
if (!column || !isSelectionColumnSelectable(column) || !isMultipleSelectionColumn(column)) {
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
const nextKeys = new Set(checkedRowKeys.value);
|
|
167
|
+
for (const flatRow of currentSelectableRows.value) {
|
|
168
|
+
if (selected) {
|
|
169
|
+
nextKeys.add(flatRow.key);
|
|
170
|
+
} else {
|
|
171
|
+
nextKeys.delete(flatRow.key);
|
|
172
|
+
}
|
|
173
|
+
}
|
|
174
|
+
updateCheckedRowKeys([...nextKeys]);
|
|
175
|
+
}
|
|
176
|
+
function collectSelectableBranchKeys(row) {
|
|
177
|
+
const column = selectionColumn.value;
|
|
178
|
+
const keys = [];
|
|
179
|
+
if (!column) {
|
|
180
|
+
return keys;
|
|
181
|
+
}
|
|
182
|
+
function visit(currentRow) {
|
|
183
|
+
const flatRow = treeRowMeta().rowByObject.get(currentRow);
|
|
184
|
+
if (!flatRow) {
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
if (isRowSelectable(currentRow, flatRow.rowIndex, column)) {
|
|
188
|
+
keys.push(flatRow.key);
|
|
189
|
+
}
|
|
190
|
+
for (const child of getTreeChildren(currentRow)) {
|
|
191
|
+
visit(child);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
visit(row);
|
|
195
|
+
return keys;
|
|
196
|
+
}
|
|
197
|
+
function shouldAncestorBeChecked(row, nextKeys) {
|
|
198
|
+
const column = selectionColumn.value;
|
|
199
|
+
const flatRow = treeRowMeta().rowByObject.get(row);
|
|
200
|
+
if (!column || !flatRow) {
|
|
201
|
+
return false;
|
|
202
|
+
}
|
|
203
|
+
const selectable = isRowSelectable(row, flatRow.rowIndex, column);
|
|
204
|
+
const children = getTreeChildren(row);
|
|
205
|
+
if (!children.length) {
|
|
206
|
+
return selectable ? nextKeys.has(flatRow.key) : true;
|
|
207
|
+
}
|
|
208
|
+
return selectable && children.every((child) => {
|
|
209
|
+
return shouldAncestorBeChecked(child, nextKeys);
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function syncAncestorSelection(nextKeys, key) {
|
|
213
|
+
let parentKey = treeRowMeta().parentKeyByChild.get(key);
|
|
214
|
+
while (parentKey != null) {
|
|
215
|
+
const parentRow = treeRowMeta().rowByKey.get(parentKey);
|
|
216
|
+
if (!parentRow) {
|
|
217
|
+
break;
|
|
218
|
+
}
|
|
219
|
+
if (shouldAncestorBeChecked(parentRow.row, nextKeys)) {
|
|
220
|
+
nextKeys.add(parentKey);
|
|
221
|
+
} else {
|
|
222
|
+
nextKeys.delete(parentKey);
|
|
223
|
+
}
|
|
224
|
+
parentKey = treeRowMeta().parentKeyByChild.get(parentKey);
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return {
|
|
228
|
+
currentSelectableRows,
|
|
229
|
+
allCurrentRowsSelected,
|
|
230
|
+
someCurrentRowsSelected,
|
|
231
|
+
isMultipleSelectionColumn,
|
|
232
|
+
isSelectionColumnSelectable,
|
|
233
|
+
isRowSelectable,
|
|
234
|
+
isRowKeySelected,
|
|
235
|
+
isRowKeyIndeterminate,
|
|
236
|
+
toggleRowSelection,
|
|
237
|
+
toggleCurrentSelectableRows
|
|
238
|
+
};
|
|
239
|
+
}
|
|
240
|
+
export {
|
|
241
|
+
useSelectionColumn
|
|
242
|
+
};
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
import { call } from "@varlet/shared";
|
|
21
|
+
import { computed } from "vue";
|
|
22
|
+
function useSorter({ sorters, sortMode, onUpdateSorters }) {
|
|
23
|
+
const activeSorters = computed(() => sorters());
|
|
24
|
+
function isColumnSortable(column) {
|
|
25
|
+
var _a;
|
|
26
|
+
return column.type == null && !((_a = column.children) == null ? void 0 : _a.length) && column.sorter === true;
|
|
27
|
+
}
|
|
28
|
+
function getColumnSorterOrder(columnKey) {
|
|
29
|
+
var _a;
|
|
30
|
+
return (_a = activeSorters.value.find((sorter) => sorter.key === columnKey)) == null ? void 0 : _a.order;
|
|
31
|
+
}
|
|
32
|
+
function toggleColumnSorter(columnKey) {
|
|
33
|
+
const currentOrder = getColumnSorterOrder(columnKey);
|
|
34
|
+
if (sortMode() === "single") {
|
|
35
|
+
call(
|
|
36
|
+
onUpdateSorters(),
|
|
37
|
+
currentOrder == null ? [{ key: columnKey, order: "asc" }] : currentOrder === "asc" ? [{ key: columnKey, order: "desc" }] : []
|
|
38
|
+
);
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
if (currentOrder == null) {
|
|
42
|
+
call(onUpdateSorters(), [...activeSorters.value, { key: columnKey, order: "asc" }]);
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (currentOrder === "asc") {
|
|
46
|
+
call(
|
|
47
|
+
onUpdateSorters(),
|
|
48
|
+
activeSorters.value.map(
|
|
49
|
+
(sorter) => sorter.key !== columnKey ? sorter : __spreadProps(__spreadValues({}, sorter), {
|
|
50
|
+
order: "desc"
|
|
51
|
+
})
|
|
52
|
+
)
|
|
53
|
+
);
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
call(
|
|
57
|
+
onUpdateSorters(),
|
|
58
|
+
activeSorters.value.filter((sorter) => sorter.key !== columnKey)
|
|
59
|
+
);
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
activeSorters,
|
|
63
|
+
isColumnSortable,
|
|
64
|
+
getColumnSorterOrder,
|
|
65
|
+
toggleColumnSorter
|
|
66
|
+
};
|
|
67
|
+
}
|
|
68
|
+
export {
|
|
69
|
+
useSorter
|
|
70
|
+
};
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { computed, watch } from "vue";
|
|
2
|
+
function useTreeExpand({ tree, data, expandedTreeRowKeys, getRowKey, getTreeChildren }) {
|
|
3
|
+
const expandedTreeRowKeySet = computed(() => new Set(expandedTreeRowKeys.value));
|
|
4
|
+
const collapsedTreeRowKeys = computed(() => {
|
|
5
|
+
if (!tree()) {
|
|
6
|
+
return /* @__PURE__ */ new Set();
|
|
7
|
+
}
|
|
8
|
+
const validKeys = collectExpandableRowKeys(data());
|
|
9
|
+
const collapsedKeys = /* @__PURE__ */ new Set();
|
|
10
|
+
for (const key of validKeys) {
|
|
11
|
+
if (!expandedTreeRowKeySet.value.has(key)) {
|
|
12
|
+
collapsedKeys.add(key);
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
return collapsedKeys;
|
|
16
|
+
});
|
|
17
|
+
watch(
|
|
18
|
+
[data, tree],
|
|
19
|
+
() => {
|
|
20
|
+
syncExpandedTreeRowKeys();
|
|
21
|
+
},
|
|
22
|
+
{ immediate: true }
|
|
23
|
+
);
|
|
24
|
+
function toggleTreeRowExpanded(bodyRow) {
|
|
25
|
+
if (!tree() || !bodyRow.expandable) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const target = new Set(expandedTreeRowKeys.value);
|
|
29
|
+
if (target.has(bodyRow.key)) {
|
|
30
|
+
target.delete(bodyRow.key);
|
|
31
|
+
} else {
|
|
32
|
+
target.add(bodyRow.key);
|
|
33
|
+
}
|
|
34
|
+
expandedTreeRowKeys.value = [...target];
|
|
35
|
+
}
|
|
36
|
+
function syncExpandedTreeRowKeys() {
|
|
37
|
+
if (!tree()) {
|
|
38
|
+
expandedTreeRowKeys.value = [];
|
|
39
|
+
return;
|
|
40
|
+
}
|
|
41
|
+
const validKeys = collectExpandableRowKeys(data());
|
|
42
|
+
expandedTreeRowKeys.value = expandedTreeRowKeys.value.filter((key) => validKeys.has(key));
|
|
43
|
+
}
|
|
44
|
+
function collectExpandableRowKeys(rows) {
|
|
45
|
+
const keys = /* @__PURE__ */ new Set();
|
|
46
|
+
let rowIndex = 0;
|
|
47
|
+
function visit(source) {
|
|
48
|
+
for (const row of source) {
|
|
49
|
+
const currentRowIndex = rowIndex;
|
|
50
|
+
rowIndex += 1;
|
|
51
|
+
const children = getTreeChildren(row);
|
|
52
|
+
if (children.length > 0) {
|
|
53
|
+
keys.add(getRowKey(row, currentRowIndex));
|
|
54
|
+
}
|
|
55
|
+
visit(children);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
visit(rows);
|
|
59
|
+
return keys;
|
|
60
|
+
}
|
|
61
|
+
return {
|
|
62
|
+
collapsedTreeRowKeys,
|
|
63
|
+
expandedTreeRowKeySet,
|
|
64
|
+
toggleTreeRowExpanded
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
export {
|
|
68
|
+
useTreeExpand
|
|
69
|
+
};
|