@rainbow-oh/yee-c 0.8.12 → 0.8.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/Pagination/style/index.less +4 -0
- package/dist/cjs/Spin/demo/types.js +1 -1
- package/dist/cjs/Spin/indicator.js +4 -2
- package/dist/cjs/Spin/style/index.less +2 -8
- package/dist/cjs/Table/col-group.d.ts +2 -2
- package/dist/cjs/Table/col-group.js +1 -1
- package/dist/cjs/Table/demo/sorter-callback.js +3 -2
- package/dist/cjs/Table/demo/sorter.js +3 -2
- package/dist/cjs/Table/hooks/useExpand.d.ts +2 -2
- package/dist/cjs/Table/hooks/useFilter.d.ts +8 -2
- package/dist/cjs/Table/hooks/useFilter.js +36 -22
- package/dist/cjs/Table/hooks/usePagination.js +8 -8
- package/dist/cjs/Table/hooks/useSelection.d.ts +3 -3
- package/dist/cjs/Table/hooks/useSelection.js +8 -9
- package/dist/cjs/Table/hooks/useSorter.d.ts +6 -3
- package/dist/cjs/Table/hooks/useSorter.js +193 -87
- package/dist/cjs/Table/interface.d.ts +10 -7
- package/dist/cjs/Table/table.js +51 -45
- package/dist/cjs/Table/tbody/index.js +13 -5
- package/dist/cjs/Table/tbody/lazy-row.js +6 -3
- package/dist/cjs/Table/tbody/row.js +5 -4
- package/dist/cjs/Table/theader/cell.js +4 -0
- package/dist/cjs/Table/theader/filter.js +52 -20
- package/dist/cjs/Table/util/index.js +5 -3
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +1 -1
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Pagination/style/index.less +4 -0
- package/dist/esm/Spin/demo/types.js +6 -3
- package/dist/esm/Spin/indicator.js +4 -2
- package/dist/esm/Spin/style/index.less +2 -8
- package/dist/esm/Table/col-group.d.ts +2 -2
- package/dist/esm/Table/col-group.js +1 -1
- package/dist/esm/Table/demo/sorter-callback.js +3 -2
- package/dist/esm/Table/demo/sorter.js +3 -2
- package/dist/esm/Table/hooks/useExpand.d.ts +2 -2
- package/dist/esm/Table/hooks/useFilter.d.ts +8 -2
- package/dist/esm/Table/hooks/useFilter.js +52 -32
- package/dist/esm/Table/hooks/usePagination.js +8 -10
- package/dist/esm/Table/hooks/useSelection.d.ts +3 -3
- package/dist/esm/Table/hooks/useSelection.js +16 -11
- package/dist/esm/Table/hooks/useSorter.d.ts +6 -3
- package/dist/esm/Table/hooks/useSorter.js +218 -105
- package/dist/esm/Table/interface.d.ts +10 -7
- package/dist/esm/Table/table.js +42 -47
- package/dist/esm/Table/tbody/index.js +8 -5
- package/dist/esm/Table/tbody/lazy-row.js +7 -3
- package/dist/esm/Table/tbody/row.js +7 -6
- package/dist/esm/Table/theader/cell.js +7 -1
- package/dist/esm/Table/theader/filter.js +75 -27
- package/dist/esm/Table/util/index.js +6 -3
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +1 -1
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +1 -1
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Pagination/style/index.less +4 -0
- package/src/Spin/demo/types.tsx +3 -3
- package/src/Spin/index.en-US.md +2 -8
- package/src/Spin/index.zh-CN.md +2 -8
- package/src/Spin/indicator.tsx +2 -0
- package/src/Spin/style/index.less +2 -8
- package/src/Table/col-group.tsx +1 -1
- package/src/Table/demo/sorter-callback.tsx +3 -2
- package/src/Table/demo/sorter.tsx +3 -2
- package/src/Table/hooks/useExpand.ts +3 -3
- package/src/Table/hooks/useFilter.ts +47 -23
- package/src/Table/hooks/usePagination.ts +9 -10
- package/src/Table/hooks/useSelection.ts +18 -20
- package/src/Table/hooks/useSorter.ts +236 -82
- package/src/Table/interface.ts +19 -7
- package/src/Table/table.tsx +54 -49
- package/src/Table/tbody/index.tsx +14 -5
- package/src/Table/tbody/lazy-row.tsx +6 -3
- package/src/Table/tbody/row.tsx +5 -4
- package/src/Table/theader/cell.tsx +10 -0
- package/src/Table/theader/filter.tsx +64 -22
- package/src/Table/util/index.ts +3 -1
- package/src/version.ts +1 -1
|
@@ -35,5 +35,5 @@ module.exports = __toCommonJS(types_exports);
|
|
|
35
35
|
var import_yee_c = require("../..");
|
|
36
36
|
var import_react = __toESM(require("react"));
|
|
37
37
|
var types_default = () => {
|
|
38
|
-
return /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, { direction: "vertical" }, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, null, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Spin, { variant: "dot" }), /* @__PURE__ */ import_react.default.createElement("span", null, "dot")), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, null, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Spin, { variant: "ring" }), /* @__PURE__ */ import_react.default.createElement("span", null, "ring")), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, null, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Spin, { variant: "spokes" }), /* @__PURE__ */ import_react.default.createElement("span", null, "spokes")));
|
|
38
|
+
return /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, { direction: "vertical" }, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, null, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Spin, { variant: "dot", color: "error" }), /* @__PURE__ */ import_react.default.createElement("span", null, "dot")), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, null, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Spin, { variant: "ring", color: "error" }), /* @__PURE__ */ import_react.default.createElement("span", null, "ring")), /* @__PURE__ */ import_react.default.createElement(import_yee_c.Space, null, /* @__PURE__ */ import_react.default.createElement(import_yee_c.Spin, { variant: "spokes", color: "error" }), /* @__PURE__ */ import_react.default.createElement("span", null, "spokes")));
|
|
39
39
|
};
|
|
@@ -109,7 +109,8 @@ var SpokesSpinner = (props) => {
|
|
|
109
109
|
classNames,
|
|
110
110
|
styles,
|
|
111
111
|
width,
|
|
112
|
-
height
|
|
112
|
+
height,
|
|
113
|
+
color
|
|
113
114
|
} = props;
|
|
114
115
|
const containerSize = sizeMap[size];
|
|
115
116
|
const count = 8;
|
|
@@ -133,7 +134,8 @@ var SpokesSpinner = (props) => {
|
|
|
133
134
|
className: `${prefixCls}-spokes-line`,
|
|
134
135
|
style: {
|
|
135
136
|
transform: `rotate(${i * (360 / count)}deg)`,
|
|
136
|
-
animationDelay: `${i * 1 / count}s
|
|
137
|
+
animationDelay: `${i * 1 / count}s`,
|
|
138
|
+
backgroundColor: color
|
|
137
139
|
}
|
|
138
140
|
}
|
|
139
141
|
)))
|
|
@@ -43,10 +43,7 @@
|
|
|
43
43
|
display: block;
|
|
44
44
|
border-style: solid;
|
|
45
45
|
border-color: var(--yee-color-bg-layout, rgba(0, 0, 0, 8%));
|
|
46
|
-
border-top-color: var(
|
|
47
|
-
--yee-spin-default-color,
|
|
48
|
-
var(--yee-color-primary, #1677ff)
|
|
49
|
-
);
|
|
46
|
+
border-top-color: var(--m-indicator-dot-bg-color);
|
|
50
47
|
border-radius: 50%;
|
|
51
48
|
animation: yee-spin-ring-rotate 0.8s linear infinite;
|
|
52
49
|
}
|
|
@@ -67,10 +64,7 @@
|
|
|
67
64
|
height: 40%;
|
|
68
65
|
margin-left: -1px;
|
|
69
66
|
transform-origin: center bottom;
|
|
70
|
-
background-color: var(
|
|
71
|
-
--yee-spin-default-color,
|
|
72
|
-
var(--yee-color-primary, #1677ff)
|
|
73
|
-
);
|
|
67
|
+
background-color: var(--m-indicator-dot-bg-color);
|
|
74
68
|
border-radius: 1px;
|
|
75
69
|
animation: yee-spin-spokes-fade 1.2s linear infinite;
|
|
76
70
|
}
|
|
@@ -3,5 +3,5 @@ import { ColumnProps } from './interface';
|
|
|
3
3
|
interface TableColGroupProps {
|
|
4
4
|
columns: Array<ColumnProps>;
|
|
5
5
|
}
|
|
6
|
-
declare const
|
|
7
|
-
export default
|
|
6
|
+
declare const ColGroup: React.MemoExoticComponent<({ columns }: TableColGroupProps) => React.JSX.Element>;
|
|
7
|
+
export default ColGroup;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ExpandableType } from '../interface';
|
|
2
|
-
export default function useExpand(expandable: ExpandableType | undefined, allKeys:
|
|
1
|
+
import { ExpandableType, SelectionKeyType } from '../interface';
|
|
2
|
+
export default function useExpand(expandable: ExpandableType | undefined, allKeys: SelectionKeyType[], getRowKey: (record: Record<string, any>) => SelectionKeyType): {
|
|
3
3
|
expandedRowKeys: (string | number)[];
|
|
4
4
|
onExpand: ({ expanded, record, }: {
|
|
5
5
|
expanded: boolean;
|
|
@@ -1,13 +1,19 @@
|
|
|
1
|
-
type FilterValue
|
|
1
|
+
import type { ColumnProps, FilterValue } from '../interface';
|
|
2
2
|
type FilterInput = FilterValue | FilterValue[];
|
|
3
3
|
type FilterOptions = {
|
|
4
4
|
dataIndex: string;
|
|
5
5
|
value: FilterInput;
|
|
6
6
|
};
|
|
7
|
-
|
|
7
|
+
type FilterRecord = {
|
|
8
|
+
value: FilterInput;
|
|
9
|
+
dataIndex: string;
|
|
10
|
+
};
|
|
11
|
+
export default function useFilter({ data, columns, }: {
|
|
8
12
|
data: Array<Record<string, unknown>>;
|
|
13
|
+
columns: ColumnProps[];
|
|
9
14
|
}): {
|
|
10
15
|
data: Record<string, unknown>[];
|
|
16
|
+
filterRecords: FilterRecord[];
|
|
11
17
|
onFilter: ({ value, dataIndex }: FilterOptions) => void;
|
|
12
18
|
};
|
|
13
19
|
export {};
|
|
@@ -43,39 +43,52 @@ var import_react = require("react");
|
|
|
43
43
|
var isEmptyFilterValue = (value) => value === "" || Array.isArray(value) && value.length === 0;
|
|
44
44
|
var normalizeValue = (value) => value === null || value === void 0 ? "" : String(value).toLowerCase();
|
|
45
45
|
function useFilter({
|
|
46
|
-
data
|
|
46
|
+
data,
|
|
47
|
+
columns
|
|
47
48
|
}) {
|
|
48
49
|
const [filterRecords, setFilterRecords] = (0, import_react.useState)([]);
|
|
50
|
+
const columnMap = (0, import_react.useMemo)(
|
|
51
|
+
() => new Map(
|
|
52
|
+
columns.flatMap(
|
|
53
|
+
(column) => column.dataIndex ? [[column.dataIndex, column]] : []
|
|
54
|
+
)
|
|
55
|
+
),
|
|
56
|
+
[columns]
|
|
57
|
+
);
|
|
58
|
+
(0, import_react.useEffect)(() => {
|
|
59
|
+
setFilterRecords((current) => {
|
|
60
|
+
const next = current.filter(({ dataIndex }) => columnMap.has(dataIndex));
|
|
61
|
+
return next.length === current.length ? current : next;
|
|
62
|
+
});
|
|
63
|
+
}, [columnMap]);
|
|
49
64
|
const onFilter = ({ value, dataIndex }) => {
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
(item) => item.dataIndex !== dataIndex
|
|
54
|
-
);
|
|
55
|
-
} else {
|
|
56
|
-
let exited = false;
|
|
57
|
-
newFilterMap = newFilterMap.map((item) => {
|
|
58
|
-
if (item.dataIndex === dataIndex) {
|
|
59
|
-
exited = true;
|
|
60
|
-
return __spreadProps(__spreadValues({}, item), { value });
|
|
61
|
-
}
|
|
62
|
-
return item;
|
|
63
|
-
});
|
|
64
|
-
if (!exited) {
|
|
65
|
-
newFilterMap.push({ dataIndex, value });
|
|
65
|
+
setFilterRecords((current) => {
|
|
66
|
+
if (isEmptyFilterValue(value)) {
|
|
67
|
+
return current.filter((item) => item.dataIndex !== dataIndex);
|
|
66
68
|
}
|
|
67
|
-
|
|
68
|
-
|
|
69
|
+
const index = current.findIndex((item) => item.dataIndex === dataIndex);
|
|
70
|
+
if (index === -1) {
|
|
71
|
+
return [...current, { dataIndex, value }];
|
|
72
|
+
}
|
|
73
|
+
return current.map(
|
|
74
|
+
(item, itemIndex) => itemIndex === index ? __spreadProps(__spreadValues({}, item), { value }) : item
|
|
75
|
+
);
|
|
76
|
+
});
|
|
69
77
|
};
|
|
70
78
|
const filtered = (0, import_react.useMemo)(() => {
|
|
71
79
|
const handled = filterRecords.filter(
|
|
72
|
-
({ dataIndex, value }) => Boolean(dataIndex) && !isEmptyFilterValue(value)
|
|
80
|
+
({ dataIndex, value }) => Boolean(dataIndex) && columnMap.has(dataIndex) && !isEmptyFilterValue(value)
|
|
73
81
|
);
|
|
74
82
|
if (!handled.length) {
|
|
75
83
|
return data;
|
|
76
84
|
}
|
|
77
85
|
return data.filter((item) => {
|
|
78
|
-
return handled.
|
|
86
|
+
return handled.every(({ dataIndex, value }) => {
|
|
87
|
+
var _a, _b;
|
|
88
|
+
const customFilter = (_b = (_a = columnMap.get(dataIndex)) == null ? void 0 : _a.filter) == null ? void 0 : _b.onFilter;
|
|
89
|
+
if (customFilter) {
|
|
90
|
+
return Array.isArray(value) ? value.some((filterValue) => customFilter(filterValue, item)) : customFilter(value, item);
|
|
91
|
+
}
|
|
79
92
|
const targetValue = normalizeValue(item[dataIndex]);
|
|
80
93
|
if (Array.isArray(value)) {
|
|
81
94
|
return value.some(
|
|
@@ -85,9 +98,10 @@ function useFilter({
|
|
|
85
98
|
return targetValue.includes(normalizeValue(value));
|
|
86
99
|
});
|
|
87
100
|
});
|
|
88
|
-
}, [data, filterRecords]);
|
|
101
|
+
}, [columnMap, data, filterRecords]);
|
|
89
102
|
return {
|
|
90
103
|
data: filtered,
|
|
104
|
+
filterRecords,
|
|
91
105
|
onFilter
|
|
92
106
|
};
|
|
93
107
|
}
|
|
@@ -119,14 +119,6 @@ function usePagination({
|
|
|
119
119
|
pageSize: pageSize2
|
|
120
120
|
});
|
|
121
121
|
};
|
|
122
|
-
if (pagination === false) {
|
|
123
|
-
return {
|
|
124
|
-
pageData: data,
|
|
125
|
-
current: 1,
|
|
126
|
-
pageSize: data.length,
|
|
127
|
-
pagination: false
|
|
128
|
-
};
|
|
129
|
-
}
|
|
130
122
|
const pageData = (0, import_react.useMemo)(() => {
|
|
131
123
|
const total = data.length;
|
|
132
124
|
if (total <= mergedPageSize)
|
|
@@ -139,6 +131,14 @@ function usePagination({
|
|
|
139
131
|
const start = (current2 - 1) * mergedPageSize;
|
|
140
132
|
return data.slice(start, start + mergedPageSize);
|
|
141
133
|
}, [data, meregdCurrent, mergedPageSize]);
|
|
134
|
+
if (pagination === false) {
|
|
135
|
+
return {
|
|
136
|
+
pageData: data,
|
|
137
|
+
current: 1,
|
|
138
|
+
pageSize: data.length,
|
|
139
|
+
pagination: false
|
|
140
|
+
};
|
|
141
|
+
}
|
|
142
142
|
return {
|
|
143
143
|
pageData,
|
|
144
144
|
current: meregdCurrent,
|
|
@@ -3,15 +3,15 @@ import type { RowSelectionType, SelectionKeyType } from '../interface';
|
|
|
3
3
|
export default function useSelection({ pageData, dataSource: data, getRowKey, rowSelection, allKeys, }: {
|
|
4
4
|
pageData: Array<Record<string, unknown>>;
|
|
5
5
|
dataSource: Array<Record<string, unknown>>;
|
|
6
|
-
getRowKey: (record: Record<string, unknown>) =>
|
|
6
|
+
getRowKey: (record: Record<string, unknown>) => SelectionKeyType;
|
|
7
7
|
allKeys: Array<SelectionKeyType>;
|
|
8
8
|
rowSelection?: RowSelectionType;
|
|
9
9
|
}): {
|
|
10
10
|
selectedRowKeys: (string | number)[];
|
|
11
11
|
checkedAll: boolean;
|
|
12
|
-
pageDataRowKeys:
|
|
12
|
+
pageDataRowKeys: SelectionKeyType[];
|
|
13
13
|
onCheck: (checked: boolean, key: number | string) => void;
|
|
14
14
|
onCheckAll: (event: ChangeEvent<HTMLInputElement>) => void;
|
|
15
15
|
onRadioCheck: (checked: boolean, key: number | string) => void;
|
|
16
|
-
onChange: (event: ChangeEvent<HTMLInputElement
|
|
16
|
+
onChange: (event: ChangeEvent<HTMLInputElement>, key: SelectionKeyType) => void;
|
|
17
17
|
};
|
|
@@ -62,19 +62,19 @@ function useSelection({
|
|
|
62
62
|
onChange == null ? void 0 : onChange(rowKeys, rowRecords);
|
|
63
63
|
};
|
|
64
64
|
const getDisabledKeys = () => {
|
|
65
|
+
if (disabled === true) {
|
|
66
|
+
return pageData.map((record) => getRowKey(record));
|
|
67
|
+
}
|
|
65
68
|
if (Array.isArray(disabled)) {
|
|
66
|
-
return disabled;
|
|
69
|
+
return pageData.filter((_, index) => disabled[index]).map((record) => getRowKey(record));
|
|
67
70
|
}
|
|
68
71
|
if (typeof disabled === "function") {
|
|
69
|
-
return
|
|
72
|
+
return pageData.filter((record, index) => disabled(record, index)).map((record) => getRowKey(record));
|
|
70
73
|
}
|
|
71
74
|
return [];
|
|
72
75
|
};
|
|
73
|
-
const getPageDataRowKeys = () => {
|
|
74
|
-
return Array.isArray(pageData) && pageData.map((record) => getRowKey(record));
|
|
75
|
-
};
|
|
76
76
|
const disabledKeys = getDisabledKeys();
|
|
77
|
-
const pageDataRowKeys =
|
|
77
|
+
const pageDataRowKeys = pageData.map((record) => getRowKey(record));
|
|
78
78
|
const isCheckedAll = () => {
|
|
79
79
|
const filtered = pageDataRowKeys.filter(
|
|
80
80
|
(key) => !disabledKeys.includes(key)
|
|
@@ -108,15 +108,14 @@ function useSelection({
|
|
|
108
108
|
);
|
|
109
109
|
setMergedSelectedRowKeys(rowKeys);
|
|
110
110
|
onChange == null ? void 0 : onChange(rowKeys, rowRecords);
|
|
111
|
-
onSelectAll == null ? void 0 : onSelectAll(rowKeys, rowRecords
|
|
111
|
+
onSelectAll == null ? void 0 : onSelectAll(checked, rowKeys, rowRecords);
|
|
112
112
|
};
|
|
113
113
|
const onRadioCheck = (checked, key) => {
|
|
114
114
|
const record = pageData.find((item) => getRowKey(item) === key);
|
|
115
115
|
setMergedSelectedRowKeys([key]);
|
|
116
116
|
onChange == null ? void 0 : onChange([key], record);
|
|
117
117
|
};
|
|
118
|
-
const handleChange = (event) => {
|
|
119
|
-
const key = event.target.value;
|
|
118
|
+
const handleChange = (event, key) => {
|
|
120
119
|
const checked = event.target.checked;
|
|
121
120
|
if (type === "checkbox") {
|
|
122
121
|
onCheck(checked, key);
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { ColumnProps } from '../interface';
|
|
2
|
-
type
|
|
3
|
-
|
|
2
|
+
type SortOrder = 1 | -1;
|
|
3
|
+
type SortState = Record<string, SortOrder>;
|
|
4
|
+
type SortChangeResult = {
|
|
5
|
+
data: Array<Record<string, unknown>>;
|
|
6
|
+
sorters: SortState;
|
|
4
7
|
};
|
|
5
8
|
export default function useSorter({ data, columns, }: {
|
|
6
9
|
data: Array<Record<string, unknown>>;
|
|
@@ -8,6 +11,6 @@ export default function useSorter({ data, columns, }: {
|
|
|
8
11
|
}): {
|
|
9
12
|
data: Record<string, unknown>[];
|
|
10
13
|
sorters: SortState;
|
|
11
|
-
onSort: (dataIndex: string) =>
|
|
14
|
+
onSort: (dataIndex: string) => SortChangeResult;
|
|
12
15
|
};
|
|
13
16
|
export {};
|
|
@@ -1,21 +1,7 @@
|
|
|
1
1
|
var __defProp = Object.defineProperty;
|
|
2
2
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
3
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
4
|
-
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
4
|
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
5
|
var __export = (target, all) => {
|
|
20
6
|
for (var name in all)
|
|
21
7
|
__defProp(target, name, { get: all[name], enumerable: true });
|
|
@@ -37,85 +23,205 @@ __export(useSorter_exports, {
|
|
|
37
23
|
});
|
|
38
24
|
module.exports = __toCommonJS(useSorter_exports);
|
|
39
25
|
var import_react = require("react");
|
|
26
|
+
var getSorterConfig = (column) => column && typeof column.sorter === "object" ? column.sorter : void 0;
|
|
27
|
+
var toSortOrder = (order) => {
|
|
28
|
+
if (order === "ascend")
|
|
29
|
+
return 1;
|
|
30
|
+
if (order === "descend")
|
|
31
|
+
return -1;
|
|
32
|
+
return 0;
|
|
33
|
+
};
|
|
34
|
+
var getNextSortOrder = (order) => {
|
|
35
|
+
if (order === 0)
|
|
36
|
+
return 1;
|
|
37
|
+
if (order === 1)
|
|
38
|
+
return -1;
|
|
39
|
+
return 0;
|
|
40
|
+
};
|
|
41
|
+
var isMultipleSorter = (column) => {
|
|
42
|
+
var _a;
|
|
43
|
+
return Boolean((_a = getSorterConfig(column)) == null ? void 0 : _a.multiple);
|
|
44
|
+
};
|
|
45
|
+
var applySortChange = (queue, column, order, columnMap) => {
|
|
46
|
+
var _a;
|
|
47
|
+
const { dataIndex } = column;
|
|
48
|
+
if (!dataIndex)
|
|
49
|
+
return queue;
|
|
50
|
+
if (order === 0) {
|
|
51
|
+
return queue.filter((item) => item.dataIndex !== dataIndex);
|
|
52
|
+
}
|
|
53
|
+
const multiple = (_a = getSorterConfig(column)) == null ? void 0 : _a.multiple;
|
|
54
|
+
const nextItem = { dataIndex, order };
|
|
55
|
+
if (!multiple) {
|
|
56
|
+
return [nextItem];
|
|
57
|
+
}
|
|
58
|
+
const next = queue.filter(
|
|
59
|
+
(item) => item.dataIndex === dataIndex || isMultipleSorter(columnMap.get(item.dataIndex))
|
|
60
|
+
);
|
|
61
|
+
const currentIndex = next.findIndex((item) => item.dataIndex === dataIndex);
|
|
62
|
+
if (currentIndex === -1) {
|
|
63
|
+
next.push(nextItem);
|
|
64
|
+
} else {
|
|
65
|
+
next[currentIndex] = nextItem;
|
|
66
|
+
}
|
|
67
|
+
if (typeof multiple === "number") {
|
|
68
|
+
const limit = Math.max(1, Math.floor(multiple));
|
|
69
|
+
while (next.length > limit) {
|
|
70
|
+
const removeIndex = next.findIndex(
|
|
71
|
+
(item) => item.dataIndex !== dataIndex
|
|
72
|
+
);
|
|
73
|
+
if (removeIndex === -1)
|
|
74
|
+
break;
|
|
75
|
+
next.splice(removeIndex, 1);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
return next;
|
|
79
|
+
};
|
|
80
|
+
var normalizeQueue = (queue, columnMap) => queue.reduce((next, item) => {
|
|
81
|
+
const column = columnMap.get(item.dataIndex);
|
|
82
|
+
return column ? applySortChange(next, column, item.order, columnMap) : next;
|
|
83
|
+
}, []);
|
|
84
|
+
var areQueuesEqual = (a, b) => a.length === b.length && a.every(
|
|
85
|
+
(item, index) => {
|
|
86
|
+
var _a, _b;
|
|
87
|
+
return item.dataIndex === ((_a = b[index]) == null ? void 0 : _a.dataIndex) && item.order === ((_b = b[index]) == null ? void 0 : _b.order);
|
|
88
|
+
}
|
|
89
|
+
);
|
|
90
|
+
var createColumnMap = (columns) => new Map(
|
|
91
|
+
columns.filter((column) => Boolean(column.dataIndex && column.sorter)).map((column) => [column.dataIndex, column])
|
|
92
|
+
);
|
|
93
|
+
var createInitialQueue = (columns, columnMap) => columns.reduce((queue, column) => {
|
|
94
|
+
const config = getSorterConfig(column);
|
|
95
|
+
const order = toSortOrder(
|
|
96
|
+
(config == null ? void 0 : config.sortOrder) !== void 0 ? config.sortOrder : config == null ? void 0 : config.defaultSortOrder
|
|
97
|
+
);
|
|
98
|
+
return order ? applySortChange(queue, column, order, columnMap) : queue;
|
|
99
|
+
}, []);
|
|
100
|
+
var mergeControlledSorters = (queue, columns, columnMap) => {
|
|
101
|
+
const controlledOrders = /* @__PURE__ */ new Map();
|
|
102
|
+
columns.forEach((column) => {
|
|
103
|
+
const config = getSorterConfig(column);
|
|
104
|
+
if (column.dataIndex && (config == null ? void 0 : config.sortOrder) !== void 0) {
|
|
105
|
+
controlledOrders.set(column.dataIndex, toSortOrder(config.sortOrder));
|
|
106
|
+
}
|
|
107
|
+
});
|
|
108
|
+
const uncontrolledQueue = queue.filter(
|
|
109
|
+
(item) => !controlledOrders.has(item.dataIndex)
|
|
110
|
+
);
|
|
111
|
+
const controlledQueue = [];
|
|
112
|
+
queue.forEach((item) => {
|
|
113
|
+
const controlledOrder = controlledOrders.get(item.dataIndex);
|
|
114
|
+
if (controlledOrder === void 0)
|
|
115
|
+
return;
|
|
116
|
+
controlledOrders.delete(item.dataIndex);
|
|
117
|
+
if (controlledOrder) {
|
|
118
|
+
controlledQueue.push({
|
|
119
|
+
dataIndex: item.dataIndex,
|
|
120
|
+
order: controlledOrder
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
});
|
|
124
|
+
columns.forEach((column) => {
|
|
125
|
+
const { dataIndex } = column;
|
|
126
|
+
if (!dataIndex)
|
|
127
|
+
return;
|
|
128
|
+
const controlledOrder = controlledOrders.get(dataIndex);
|
|
129
|
+
if (controlledOrder) {
|
|
130
|
+
controlledQueue.push({ dataIndex, order: controlledOrder });
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
return normalizeQueue([...uncontrolledQueue, ...controlledQueue], columnMap);
|
|
134
|
+
};
|
|
135
|
+
var queueToSortState = (queue) => Object.fromEntries(
|
|
136
|
+
queue.map(({ dataIndex, order }) => [dataIndex, order])
|
|
137
|
+
);
|
|
138
|
+
var compareValues = (a, b) => {
|
|
139
|
+
if (Object.is(a, b))
|
|
140
|
+
return 0;
|
|
141
|
+
if (typeof a === "number" && typeof b === "number")
|
|
142
|
+
return a - b;
|
|
143
|
+
if (typeof a === "bigint" && typeof b === "bigint")
|
|
144
|
+
return a < b ? -1 : 1;
|
|
145
|
+
if (a instanceof Date && b instanceof Date)
|
|
146
|
+
return a.getTime() - b.getTime();
|
|
147
|
+
if (typeof a === "boolean" && typeof b === "boolean") {
|
|
148
|
+
return Number(a) - Number(b);
|
|
149
|
+
}
|
|
150
|
+
return String(a).localeCompare(String(b));
|
|
151
|
+
};
|
|
152
|
+
var sortData = (data, queue, columnMap) => {
|
|
153
|
+
if (!queue.length)
|
|
154
|
+
return data;
|
|
155
|
+
return [...data].sort((a, b) => {
|
|
156
|
+
var _a;
|
|
157
|
+
for (const { dataIndex, order } of queue) {
|
|
158
|
+
const aValue = a[dataIndex];
|
|
159
|
+
const bValue = b[dataIndex];
|
|
160
|
+
const compare = (_a = getSorterConfig(columnMap.get(dataIndex))) == null ? void 0 : _a.sort;
|
|
161
|
+
if (compare) {
|
|
162
|
+
const result2 = compare(a, b);
|
|
163
|
+
if (result2 !== 0) {
|
|
164
|
+
return order === -1 ? -result2 : result2;
|
|
165
|
+
}
|
|
166
|
+
continue;
|
|
167
|
+
}
|
|
168
|
+
if (aValue === null && bValue === null)
|
|
169
|
+
continue;
|
|
170
|
+
if (aValue === null || aValue === void 0)
|
|
171
|
+
return 1;
|
|
172
|
+
if (bValue === null || bValue === void 0)
|
|
173
|
+
return -1;
|
|
174
|
+
const result = compareValues(aValue, bValue);
|
|
175
|
+
if (result !== 0) {
|
|
176
|
+
return order === -1 ? -result : result;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
return 0;
|
|
180
|
+
});
|
|
181
|
+
};
|
|
40
182
|
function useSorter({
|
|
41
183
|
data,
|
|
42
184
|
columns
|
|
43
185
|
}) {
|
|
44
|
-
const
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (!sorter)
|
|
49
|
-
return;
|
|
50
|
-
const { defaultSortOrder } = typeof sorter === "boolean" ? {} : sorter;
|
|
51
|
-
if (dataIndex && sorter) {
|
|
52
|
-
if (defaultSortOrder === "ascend") {
|
|
53
|
-
sorters2[dataIndex] = 1;
|
|
54
|
-
} else if (defaultSortOrder === "descend") {
|
|
55
|
-
sorters2[dataIndex] = -1;
|
|
56
|
-
} else {
|
|
57
|
-
sorters2[dataIndex] = 0;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
return sorters2;
|
|
62
|
-
}, [columns]);
|
|
63
|
-
const [sorters, setSorters] = (0, import_react.useState)(getDefaultSorters());
|
|
186
|
+
const columnMap = (0, import_react.useMemo)(() => createColumnMap(columns), [columns]);
|
|
187
|
+
const [internalQueue, setInternalQueue] = (0, import_react.useState)(
|
|
188
|
+
() => createInitialQueue(columns, columnMap)
|
|
189
|
+
);
|
|
64
190
|
(0, import_react.useEffect)(() => {
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
setSorters((prev) => {
|
|
69
|
-
var _a;
|
|
70
|
-
const newSorters = __spreadValues({}, prev);
|
|
71
|
-
const currentOrder = (_a = newSorters[dataIndex]) != null ? _a : 0;
|
|
72
|
-
if (currentOrder === 0) {
|
|
73
|
-
newSorters[dataIndex] = 1;
|
|
74
|
-
} else if (currentOrder === 1) {
|
|
75
|
-
newSorters[dataIndex] = -1;
|
|
76
|
-
} else {
|
|
77
|
-
newSorters[dataIndex] = 0;
|
|
78
|
-
}
|
|
79
|
-
const isMultipleSort = void 0;
|
|
80
|
-
if (isMultipleSort) {
|
|
81
|
-
} else {
|
|
82
|
-
Object.keys(newSorters).forEach((key) => {
|
|
83
|
-
if (key !== dataIndex) {
|
|
84
|
-
delete newSorters[key];
|
|
85
|
-
}
|
|
86
|
-
});
|
|
87
|
-
}
|
|
88
|
-
return newSorters;
|
|
89
|
-
});
|
|
90
|
-
};
|
|
91
|
-
const sorted = (0, import_react.useMemo)(() => {
|
|
92
|
-
const activeSorters = Object.entries(sorters).filter(
|
|
93
|
-
([, order]) => order !== 0
|
|
94
|
-
);
|
|
95
|
-
if (activeSorters.length === 0) {
|
|
96
|
-
return data;
|
|
97
|
-
}
|
|
98
|
-
const sortedData = [...data].sort((a, b) => {
|
|
99
|
-
for (const [dataIndex, order] of activeSorters) {
|
|
100
|
-
const aValue = a[dataIndex];
|
|
101
|
-
const bValue = b[dataIndex];
|
|
102
|
-
if (aValue === null && bValue === null)
|
|
103
|
-
continue;
|
|
104
|
-
if (aValue === null || aValue === void 0)
|
|
105
|
-
return 1;
|
|
106
|
-
if (bValue === null || bValue === void 0)
|
|
107
|
-
return -1;
|
|
108
|
-
if (aValue < bValue) {
|
|
109
|
-
return order === -1 ? 1 : -1;
|
|
110
|
-
}
|
|
111
|
-
if (aValue > bValue) {
|
|
112
|
-
return order === -1 ? -1 : 1;
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
return 0;
|
|
191
|
+
setInternalQueue((current) => {
|
|
192
|
+
const next = normalizeQueue(current, columnMap);
|
|
193
|
+
return areQueuesEqual(current, next) ? current : next;
|
|
116
194
|
});
|
|
117
|
-
|
|
118
|
-
|
|
195
|
+
}, [columnMap]);
|
|
196
|
+
const activeQueue = (0, import_react.useMemo)(
|
|
197
|
+
() => mergeControlledSorters(internalQueue, columns, columnMap),
|
|
198
|
+
[internalQueue, columns, columnMap]
|
|
199
|
+
);
|
|
200
|
+
const sorters = (0, import_react.useMemo)(() => queueToSortState(activeQueue), [activeQueue]);
|
|
201
|
+
const sorted = (0, import_react.useMemo)(
|
|
202
|
+
() => sortData(data, activeQueue, columnMap),
|
|
203
|
+
[data, activeQueue, columnMap]
|
|
204
|
+
);
|
|
205
|
+
const onSort = (0, import_react.useCallback)(
|
|
206
|
+
(dataIndex) => {
|
|
207
|
+
var _a, _b;
|
|
208
|
+
const column = columnMap.get(dataIndex);
|
|
209
|
+
if (!column)
|
|
210
|
+
return { data: sorted, sorters };
|
|
211
|
+
const currentOrder = (_b = (_a = activeQueue.find((item) => item.dataIndex === dataIndex)) == null ? void 0 : _a.order) != null ? _b : 0;
|
|
212
|
+
const nextQueue = applySortChange(
|
|
213
|
+
activeQueue,
|
|
214
|
+
column,
|
|
215
|
+
getNextSortOrder(currentOrder),
|
|
216
|
+
columnMap
|
|
217
|
+
);
|
|
218
|
+
const nextSorters = queueToSortState(nextQueue);
|
|
219
|
+
const nextData = sortData(data, nextQueue, columnMap);
|
|
220
|
+
setInternalQueue(nextQueue);
|
|
221
|
+
return { data: nextData, sorters: nextSorters };
|
|
222
|
+
},
|
|
223
|
+
[activeQueue, columnMap, data, sorted, sorters]
|
|
224
|
+
);
|
|
119
225
|
return {
|
|
120
226
|
data: sorted,
|
|
121
227
|
sorters,
|