@rainbow-oh/yee-c 0.8.11 → 0.8.13
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/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 +10 -2
- package/dist/cjs/Table/hooks/useFilter.js +44 -31
- 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/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 +10 -2
- package/dist/esm/Table/hooks/useFilter.js +63 -36
- 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.js +1 -1
- package/package.json +1 -1
- 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 +66 -33
- 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
package/dist/cjs/Table/table.js
CHANGED
|
@@ -155,13 +155,24 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
155
155
|
expandable,
|
|
156
156
|
rowSelection
|
|
157
157
|
});
|
|
158
|
-
const {
|
|
159
|
-
data:
|
|
158
|
+
const {
|
|
159
|
+
data: filteredData,
|
|
160
|
+
filterRecords,
|
|
161
|
+
onFilter: onFilterInternal
|
|
162
|
+
} = (0, import_useFilter.default)({
|
|
163
|
+
data: dataSource,
|
|
164
|
+
columns: wrapedColumns
|
|
160
165
|
});
|
|
166
|
+
const filters = (0, import_react.useMemo)(
|
|
167
|
+
() => Object.fromEntries(
|
|
168
|
+
filterRecords.map(({ dataIndex, value }) => [dataIndex, value])
|
|
169
|
+
),
|
|
170
|
+
[filterRecords]
|
|
171
|
+
);
|
|
161
172
|
const {
|
|
162
173
|
data: sortedData,
|
|
163
174
|
sorters,
|
|
164
|
-
onSort
|
|
175
|
+
onSort: onSortInternal
|
|
165
176
|
} = (0, import_useSorter.default)({ data: filteredData, columns: wrapedColumns });
|
|
166
177
|
const { pageData, current, pageSize, pagination } = (0, import_usePagination.default)({
|
|
167
178
|
data: sortedData,
|
|
@@ -170,13 +181,25 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
170
181
|
onChange({
|
|
171
182
|
pagination: info,
|
|
172
183
|
sorter: sorters,
|
|
173
|
-
filters
|
|
174
|
-
// TODO: Extract filter info from onFilterInternal
|
|
184
|
+
filters,
|
|
175
185
|
currentDataSource: sortedData,
|
|
176
186
|
action: "paginate"
|
|
177
187
|
});
|
|
178
188
|
} : void 0
|
|
179
189
|
});
|
|
190
|
+
const handleSort = import_react.default.useCallback(
|
|
191
|
+
(dataIndex) => {
|
|
192
|
+
const next = onSortInternal(dataIndex);
|
|
193
|
+
onChange == null ? void 0 : onChange({
|
|
194
|
+
pagination: pagination === false ? void 0 : { current, pageSize },
|
|
195
|
+
sorter: next.sorters,
|
|
196
|
+
filters,
|
|
197
|
+
currentDataSource: next.data,
|
|
198
|
+
action: "sort"
|
|
199
|
+
});
|
|
200
|
+
},
|
|
201
|
+
[onSortInternal, onChange, pagination, current, pageSize, filters]
|
|
202
|
+
);
|
|
180
203
|
const { expandedRowKeys, onExpand } = (0, import_useExpand.default)(
|
|
181
204
|
expandable,
|
|
182
205
|
allKeys,
|
|
@@ -188,7 +211,7 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
188
211
|
onCheckAll,
|
|
189
212
|
onChange: onSelectionChange
|
|
190
213
|
} = (0, import_useSelection.default)({ pageData, dataSource, getRowKey, rowSelection, allKeys });
|
|
191
|
-
const
|
|
214
|
+
const prevFilterRecordsRef = (0, import_react.useRef)(filterRecords);
|
|
192
215
|
const contentWrapperRef = (0, import_react.useRef)(null);
|
|
193
216
|
const contentRef = (0, import_react.useRef)(null);
|
|
194
217
|
const [horizontalScroll, setHorizontalScroll] = import_react.default.useState({
|
|
@@ -211,46 +234,29 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
211
234
|
(current2) => current2.left === next.left && current2.right === next.right ? current2 : next
|
|
212
235
|
);
|
|
213
236
|
}, []);
|
|
214
|
-
const onFilter = import_react.default.useCallback(
|
|
215
|
-
(...args) => {
|
|
216
|
-
onFilterInternal(...args);
|
|
217
|
-
if (onChange) {
|
|
218
|
-
onChange({
|
|
219
|
-
pagination: pagination === false ? void 0 : { current, pageSize },
|
|
220
|
-
sorter: sorters,
|
|
221
|
-
filters: void 0,
|
|
222
|
-
// TODO: Extract filter info from args
|
|
223
|
-
currentDataSource: filteredData,
|
|
224
|
-
action: "filter"
|
|
225
|
-
});
|
|
226
|
-
}
|
|
227
|
-
},
|
|
228
|
-
[
|
|
229
|
-
onChange,
|
|
230
|
-
pagination,
|
|
231
|
-
current,
|
|
232
|
-
pageSize,
|
|
233
|
-
sorters,
|
|
234
|
-
filteredData,
|
|
235
|
-
onFilterInternal
|
|
236
|
-
]
|
|
237
|
-
);
|
|
238
237
|
(0, import_react.useEffect)(() => {
|
|
239
|
-
if (
|
|
238
|
+
if (prevFilterRecordsRef.current === filterRecords)
|
|
240
239
|
return;
|
|
241
|
-
|
|
242
|
-
if (
|
|
243
|
-
prevSortersRef.current = sorters;
|
|
244
|
-
onChange({
|
|
245
|
-
pagination: pagination === false ? void 0 : { current, pageSize },
|
|
246
|
-
sorter: sorters,
|
|
247
|
-
filters: void 0,
|
|
248
|
-
currentDataSource: sortedData,
|
|
249
|
-
action: "sort"
|
|
250
|
-
});
|
|
240
|
+
prevFilterRecordsRef.current = filterRecords;
|
|
241
|
+
if (!onChange)
|
|
251
242
|
return;
|
|
252
|
-
|
|
253
|
-
|
|
243
|
+
onChange({
|
|
244
|
+
pagination: pagination === false ? void 0 : { current, pageSize },
|
|
245
|
+
sorter: sorters,
|
|
246
|
+
filters,
|
|
247
|
+
currentDataSource: sortedData,
|
|
248
|
+
action: "filter"
|
|
249
|
+
});
|
|
250
|
+
}, [
|
|
251
|
+
filterRecords,
|
|
252
|
+
filters,
|
|
253
|
+
sortedData,
|
|
254
|
+
pagination,
|
|
255
|
+
current,
|
|
256
|
+
pageSize,
|
|
257
|
+
sorters,
|
|
258
|
+
onChange
|
|
259
|
+
]);
|
|
254
260
|
(0, import_react.useEffect)(() => {
|
|
255
261
|
updateHorizontalScroll();
|
|
256
262
|
const wrapper = contentWrapperRef.current;
|
|
@@ -290,9 +296,9 @@ var Table = import_react.default.forwardRef((baseprops, ref) => {
|
|
|
290
296
|
headerRows,
|
|
291
297
|
checkedAll,
|
|
292
298
|
sorters,
|
|
293
|
-
onSort,
|
|
299
|
+
onSort: handleSort,
|
|
294
300
|
onCheckAll,
|
|
295
|
-
onInternalFilter:
|
|
301
|
+
onInternalFilter: onFilterInternal
|
|
296
302
|
})
|
|
297
303
|
);
|
|
298
304
|
};
|
|
@@ -81,19 +81,26 @@ var TableBody = (props) => {
|
|
|
81
81
|
const resolveRowKey = (record) => typeof rowKey === "function" ? rowKey(record) : record[rowKey];
|
|
82
82
|
const getRenderRows = () => {
|
|
83
83
|
if (lazyLoad) {
|
|
84
|
-
return /* @__PURE__ */ import_react.default.createElement(
|
|
84
|
+
return /* @__PURE__ */ import_react.default.createElement(
|
|
85
|
+
import_lazy_row.default,
|
|
86
|
+
__spreadProps(__spreadValues({}, rest), {
|
|
87
|
+
pageData,
|
|
88
|
+
columns,
|
|
89
|
+
resolveRowKey
|
|
90
|
+
})
|
|
91
|
+
);
|
|
85
92
|
}
|
|
86
93
|
return pageData.map((record, index) => {
|
|
94
|
+
const resolvedRowKey = resolveRowKey(record);
|
|
87
95
|
if (RowRenderer) {
|
|
88
|
-
const rk = resolveRowKey(record);
|
|
89
96
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
90
97
|
RowRenderer,
|
|
91
98
|
{
|
|
92
|
-
key:
|
|
99
|
+
key: resolvedRowKey != null ? resolvedRowKey : index,
|
|
93
100
|
record,
|
|
94
101
|
index,
|
|
95
102
|
columns,
|
|
96
|
-
rowKey:
|
|
103
|
+
rowKey: resolvedRowKey
|
|
97
104
|
}
|
|
98
105
|
);
|
|
99
106
|
}
|
|
@@ -102,8 +109,9 @@ var TableBody = (props) => {
|
|
|
102
109
|
__spreadProps(__spreadValues({}, rest), {
|
|
103
110
|
columns,
|
|
104
111
|
record,
|
|
112
|
+
rowKeyValue: resolvedRowKey,
|
|
105
113
|
index,
|
|
106
|
-
key: `row-${
|
|
114
|
+
key: resolvedRowKey != null ? resolvedRowKey : `row-${index}`
|
|
107
115
|
})
|
|
108
116
|
);
|
|
109
117
|
});
|
|
@@ -67,21 +67,24 @@ var createBlank = (size, key) => {
|
|
|
67
67
|
return size ? [/* @__PURE__ */ React.createElement("tr", { style: { height: `${size * 47}px`, width: "100%" }, key })] : [];
|
|
68
68
|
};
|
|
69
69
|
var LazyRow = (props) => {
|
|
70
|
-
const _a = props, { range, pageData, columns } = _a, rest = __objRest(_a, ["range", "pageData", "columns"]);
|
|
70
|
+
const _a = props, { range, pageData, columns, resolveRowKey } = _a, rest = __objRest(_a, ["range", "pageData", "columns", "resolveRowKey"]);
|
|
71
71
|
const { start, end } = range;
|
|
72
72
|
let result = [];
|
|
73
73
|
const pl = pageData.length;
|
|
74
74
|
const startBlank = createBlank(start, "row-start");
|
|
75
75
|
result = result.concat(startBlank);
|
|
76
76
|
for (let i = start; i < (end > pl ? pl : end); i++) {
|
|
77
|
+
const record = pageData[i];
|
|
78
|
+
const rowKeyValue = resolveRowKey(record);
|
|
77
79
|
result.push(
|
|
78
80
|
/* @__PURE__ */ React.createElement(
|
|
79
81
|
import_row.default,
|
|
80
82
|
__spreadProps(__spreadValues({}, rest), {
|
|
81
83
|
columns,
|
|
82
|
-
record
|
|
84
|
+
record,
|
|
85
|
+
rowKeyValue,
|
|
83
86
|
index: i,
|
|
84
|
-
key:
|
|
87
|
+
key: rowKeyValue != null ? rowKeyValue : `row-${i}`
|
|
85
88
|
})
|
|
86
89
|
)
|
|
87
90
|
);
|
|
@@ -74,6 +74,7 @@ var TableRow = (props) => {
|
|
|
74
74
|
const _a = props, {
|
|
75
75
|
index,
|
|
76
76
|
record,
|
|
77
|
+
rowKeyValue,
|
|
77
78
|
columns,
|
|
78
79
|
highlight,
|
|
79
80
|
stripe,
|
|
@@ -90,6 +91,7 @@ var TableRow = (props) => {
|
|
|
90
91
|
} = _a, rest = __objRest(_a, [
|
|
91
92
|
"index",
|
|
92
93
|
"record",
|
|
94
|
+
"rowKeyValue",
|
|
93
95
|
"columns",
|
|
94
96
|
"highlight",
|
|
95
97
|
"stripe",
|
|
@@ -104,9 +106,9 @@ var TableRow = (props) => {
|
|
|
104
106
|
"onDoubleClick",
|
|
105
107
|
"onSelectionChange"
|
|
106
108
|
]);
|
|
107
|
-
const { prefixCls
|
|
109
|
+
const { prefixCls } = (0, import_react.useContext)(import_table.TableCtx);
|
|
108
110
|
const expanded = expandedRowKeys == null ? void 0 : expandedRowKeys.includes(
|
|
109
|
-
expandedKeyType === "index" ? index + 1 :
|
|
111
|
+
expandedKeyType === "index" ? index + 1 : rowKeyValue
|
|
110
112
|
);
|
|
111
113
|
const high = import_react.default.useMemo(() => {
|
|
112
114
|
if (typeof highlight === "undefined")
|
|
@@ -128,14 +130,13 @@ var TableRow = (props) => {
|
|
|
128
130
|
};
|
|
129
131
|
const getSelection = (column) => {
|
|
130
132
|
const { type, disabled: colDisabled, onCell } = column;
|
|
131
|
-
const rowKeyValue = record[rowKey];
|
|
132
133
|
const props2 = (onCell == null ? void 0 : onCell(record, index)) || {};
|
|
133
134
|
const checked = selectedRowKeys == null ? void 0 : selectedRowKeys.includes(rowKeyValue);
|
|
134
135
|
const disabled = typeof colDisabled === "function" ? colDisabled(record, index) : Array.isArray(colDisabled) ? colDisabled[index] : !!colDisabled;
|
|
135
136
|
const commonProps = __spreadValues({
|
|
136
137
|
checked,
|
|
137
138
|
value: rowKeyValue,
|
|
138
|
-
onChange: onSelectionChange,
|
|
139
|
+
onChange: (event) => onSelectionChange(event, rowKeyValue),
|
|
139
140
|
disabled
|
|
140
141
|
}, props2);
|
|
141
142
|
if (type === "checkbox") {
|
|
@@ -122,12 +122,16 @@ var HeadCell = (props) => {
|
|
|
122
122
|
const showFilter = !!filter;
|
|
123
123
|
const sortOrder = dataIndex && (sorters == null ? void 0 : sorters[dataIndex]) || 0;
|
|
124
124
|
const displaySortOrder = sortOrder === -1 ? 2 : sortOrder;
|
|
125
|
+
const currentSortOrder = sortOrder === 1 ? "ascend" : sortOrder === -1 ? "descend" : null;
|
|
125
126
|
const handleSort = () => {
|
|
126
127
|
if (dataIndex && onSort) {
|
|
127
128
|
onSort(dataIndex, sorter);
|
|
128
129
|
}
|
|
129
130
|
};
|
|
130
131
|
const renderSort = () => {
|
|
132
|
+
if (typeof sorter === "object" && sorter.icon) {
|
|
133
|
+
return /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefixCls}-column-sorter` }, sorter.icon(currentSortOrder));
|
|
134
|
+
}
|
|
131
135
|
const trigger = /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefixCls}-column-sorter` }, /* @__PURE__ */ import_react.default.createElement(
|
|
132
136
|
import_arrow_icon.default,
|
|
133
137
|
{
|
|
@@ -49,13 +49,31 @@ var getStrLower = (str) => {
|
|
|
49
49
|
}
|
|
50
50
|
return str;
|
|
51
51
|
};
|
|
52
|
+
var areFilterValuesEqual = (a, b) => {
|
|
53
|
+
if (!Array.isArray(a) || !Array.isArray(b))
|
|
54
|
+
return a === b;
|
|
55
|
+
return a.length === b.length && a.every((value, index) => value === b[index]);
|
|
56
|
+
};
|
|
57
|
+
var hasFilterValue = (value) => Array.isArray(value) ? value.length > 0 : value !== "";
|
|
52
58
|
var HeaderFilter = import_react.default.memo((props) => {
|
|
53
59
|
const { filter, column, getPopupContainer, onInternalFilter } = props;
|
|
54
60
|
const { prefixCls } = (0, import_react.useContext)(import_table.TableCtx);
|
|
55
61
|
const { locale } = (0, import_locale.useLocale)();
|
|
56
62
|
const { table: tableLocale } = locale;
|
|
57
63
|
const { dataIndex } = column;
|
|
64
|
+
const {
|
|
65
|
+
items,
|
|
66
|
+
icon,
|
|
67
|
+
searchable = true,
|
|
68
|
+
filterMode = "menu",
|
|
69
|
+
filtered,
|
|
70
|
+
filterOnClose = true,
|
|
71
|
+
render
|
|
72
|
+
} = filter;
|
|
58
73
|
const inputRef = (0, import_react.useRef)(null);
|
|
74
|
+
const initialValue = items ? [] : "";
|
|
75
|
+
const committedValueRef = (0, import_react.useRef)(initialValue);
|
|
76
|
+
const [committedValue, setCommittedValue] = (0, import_react.useState)(initialValue);
|
|
59
77
|
const [open, setOpen] = (0, import_react.useState)(false);
|
|
60
78
|
const [selectNodes, setSelectNodes] = (0, import_react.useState)([]);
|
|
61
79
|
const [searchValue, setSearchValue] = (0, import_react.useState)("");
|
|
@@ -71,30 +89,34 @@ var HeaderFilter = import_react.default.memo((props) => {
|
|
|
71
89
|
const inputChange = (value) => {
|
|
72
90
|
setSearchValue(value);
|
|
73
91
|
};
|
|
74
|
-
const
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
92
|
+
const getCurrentValue = (type) => type === "search" ? searchValue : selectNodes;
|
|
93
|
+
const commitValue = (value) => {
|
|
94
|
+
const committed = Array.isArray(value) ? [...value] : value;
|
|
95
|
+
committedValueRef.current = committed;
|
|
96
|
+
setCommittedValue(committed);
|
|
78
97
|
};
|
|
79
|
-
const
|
|
98
|
+
const applyFilter = (type) => {
|
|
99
|
+
const value = getCurrentValue(type);
|
|
100
|
+
commitValue(value);
|
|
80
101
|
onInternalFilter({
|
|
81
102
|
dataIndex,
|
|
82
|
-
value
|
|
103
|
+
value,
|
|
83
104
|
type,
|
|
84
105
|
column
|
|
85
106
|
});
|
|
107
|
+
};
|
|
108
|
+
const reset = () => {
|
|
109
|
+
const value = items ? [] : "";
|
|
110
|
+
setSearchValue("");
|
|
111
|
+
setSelectNodes([]);
|
|
112
|
+
commitValue(value);
|
|
113
|
+
onInternalFilter({ dataIndex, value, column });
|
|
114
|
+
};
|
|
115
|
+
const ok = (type) => {
|
|
116
|
+
applyFilter(type);
|
|
86
117
|
setOpen(false);
|
|
87
118
|
};
|
|
88
119
|
let popup;
|
|
89
|
-
const {
|
|
90
|
-
items,
|
|
91
|
-
icon,
|
|
92
|
-
searchable = true,
|
|
93
|
-
filterMode = "menu"
|
|
94
|
-
// filtered,
|
|
95
|
-
// filterOnClose,
|
|
96
|
-
// onFilter,
|
|
97
|
-
} = filter;
|
|
98
120
|
const searchInputNode = searchable ? /* @__PURE__ */ import_react.default.createElement(
|
|
99
121
|
import_Input.default,
|
|
100
122
|
{
|
|
@@ -110,7 +132,9 @@ var HeaderFilter = import_react.default.memo((props) => {
|
|
|
110
132
|
ref: inputRef
|
|
111
133
|
}
|
|
112
134
|
) : null;
|
|
113
|
-
if (
|
|
135
|
+
if (render) {
|
|
136
|
+
popup = render();
|
|
137
|
+
} else if (items) {
|
|
114
138
|
let dataSource = [];
|
|
115
139
|
const inputValue = getStrLower(searchValue);
|
|
116
140
|
const filteredItems = inputValue ? items.filter(
|
|
@@ -152,15 +176,23 @@ var HeaderFilter = import_react.default.memo((props) => {
|
|
|
152
176
|
} else {
|
|
153
177
|
return null;
|
|
154
178
|
}
|
|
155
|
-
const handleOpenChange = (
|
|
156
|
-
|
|
179
|
+
const handleOpenChange = (nextOpen) => {
|
|
180
|
+
if (!nextOpen && open && filterOnClose && !render) {
|
|
181
|
+
const type = items ? "filter" : "search";
|
|
182
|
+
const value = getCurrentValue(type);
|
|
183
|
+
if (!areFilterValuesEqual(value, committedValueRef.current)) {
|
|
184
|
+
applyFilter(type);
|
|
185
|
+
}
|
|
186
|
+
}
|
|
187
|
+
setOpen(nextOpen);
|
|
157
188
|
};
|
|
189
|
+
const isFiltered = filtered != null ? filtered : hasFilterValue(committedValue);
|
|
158
190
|
const renderTrigger = () => {
|
|
159
|
-
const trigger = typeof icon === "function" ? icon() : /* @__PURE__ */ import_react.default.createElement(
|
|
191
|
+
const trigger = typeof icon === "function" ? icon(isFiltered) : /* @__PURE__ */ import_react.default.createElement(
|
|
160
192
|
import_Button.default,
|
|
161
193
|
{
|
|
162
194
|
icon: items ? /* @__PURE__ */ import_react.default.createElement(import_lucide_react.ListFilter, { size: 14, strokeWidth: 1.5 }) : /* @__PURE__ */ import_react.default.createElement(import_lucide_react.Search, { size: 14, strokeWidth: 1.5 }),
|
|
163
|
-
variant:
|
|
195
|
+
variant: isFiltered ? "filled" : void 0,
|
|
164
196
|
type: "text",
|
|
165
197
|
size: "small"
|
|
166
198
|
}
|
|
@@ -40,7 +40,7 @@ __export(util_exports, {
|
|
|
40
40
|
});
|
|
41
41
|
module.exports = __toCommonJS(util_exports);
|
|
42
42
|
function handleColumns(columns) {
|
|
43
|
-
var _a;
|
|
43
|
+
var _a, _b;
|
|
44
44
|
let leftWidthCount = 0;
|
|
45
45
|
let rightWidthCount = 0;
|
|
46
46
|
for (let i = 0; i < columns.length; i++) {
|
|
@@ -48,7 +48,9 @@ function handleColumns(columns) {
|
|
|
48
48
|
if (col.fixed === true || col.fixed === "left") {
|
|
49
49
|
col.fixed = "left";
|
|
50
50
|
col.style = __spreadProps(__spreadValues({}, col.style), { left: leftWidthCount });
|
|
51
|
-
|
|
51
|
+
const nextFixed = (_a = columns[i + 1]) == null ? void 0 : _a.fixed;
|
|
52
|
+
const nextIsFixedLeft = nextFixed === true || nextFixed === "left";
|
|
53
|
+
if (!nextIsFixedLeft) {
|
|
52
54
|
col.isFixedLeftLast = true;
|
|
53
55
|
}
|
|
54
56
|
leftWidthCount = leftWidthCount + (col.width ? parseFloat(col.width) : 0);
|
|
@@ -58,7 +60,7 @@ function handleColumns(columns) {
|
|
|
58
60
|
const col = columns[j] || {};
|
|
59
61
|
if (col.fixed === "right") {
|
|
60
62
|
col.style = __spreadProps(__spreadValues({}, col.style), { right: rightWidthCount });
|
|
61
|
-
if (((
|
|
63
|
+
if (((_b = columns[j - 1]) == null ? void 0 : _b.fixed) !== "right") {
|
|
62
64
|
col.isFixedRightFirst = true;
|
|
63
65
|
}
|
|
64
66
|
rightWidthCount = rightWidthCount + (col.width ? parseFloat(col.width) : 0);
|
package/dist/cjs/version.d.ts
CHANGED
package/dist/cjs/version.js
CHANGED
|
@@ -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,11 +1,19 @@
|
|
|
1
|
+
import type { ColumnProps, FilterValue } from '../interface';
|
|
2
|
+
type FilterInput = FilterValue | FilterValue[];
|
|
1
3
|
type FilterOptions = {
|
|
2
4
|
dataIndex: string;
|
|
3
|
-
value:
|
|
5
|
+
value: FilterInput;
|
|
4
6
|
};
|
|
5
|
-
|
|
7
|
+
type FilterRecord = {
|
|
8
|
+
value: FilterInput;
|
|
9
|
+
dataIndex: string;
|
|
10
|
+
};
|
|
11
|
+
export default function useFilter({ data, columns, }: {
|
|
6
12
|
data: Array<Record<string, unknown>>;
|
|
13
|
+
columns: ColumnProps[];
|
|
7
14
|
}): {
|
|
8
15
|
data: Record<string, unknown>[];
|
|
16
|
+
filterRecords: FilterRecord[];
|
|
9
17
|
onFilter: ({ value, dataIndex }: FilterOptions) => void;
|
|
10
18
|
};
|
|
11
19
|
export {};
|
|
@@ -14,65 +14,92 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
14
14
|
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) arr2[i] = arr[i]; return arr2; }
|
|
15
15
|
function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
|
|
16
16
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
17
|
-
import { useMemo, useState } from 'react';
|
|
17
|
+
import { useEffect, useMemo, useState } from 'react';
|
|
18
|
+
var isEmptyFilterValue = function isEmptyFilterValue(value) {
|
|
19
|
+
return value === '' || Array.isArray(value) && value.length === 0;
|
|
20
|
+
};
|
|
21
|
+
var normalizeValue = function normalizeValue(value) {
|
|
22
|
+
return value === null || value === undefined ? '' : String(value).toLowerCase();
|
|
23
|
+
};
|
|
18
24
|
export default function useFilter(_ref) {
|
|
19
|
-
var data = _ref.data
|
|
25
|
+
var data = _ref.data,
|
|
26
|
+
columns = _ref.columns;
|
|
20
27
|
var _useState = useState([]),
|
|
21
28
|
_useState2 = _slicedToArray(_useState, 2),
|
|
22
29
|
filterRecords = _useState2[0],
|
|
23
30
|
setFilterRecords = _useState2[1];
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
dataIndex
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
var columnMap = useMemo(function () {
|
|
32
|
+
return new Map(columns.flatMap(function (column) {
|
|
33
|
+
return column.dataIndex ? [[column.dataIndex, column]] : [];
|
|
34
|
+
}));
|
|
35
|
+
}, [columns]);
|
|
36
|
+
useEffect(function () {
|
|
37
|
+
setFilterRecords(function (current) {
|
|
38
|
+
var next = current.filter(function (_ref2) {
|
|
39
|
+
var dataIndex = _ref2.dataIndex;
|
|
40
|
+
return columnMap.has(dataIndex);
|
|
31
41
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
+
return next.length === current.length ? current : next;
|
|
43
|
+
});
|
|
44
|
+
}, [columnMap]);
|
|
45
|
+
var onFilter = function onFilter(_ref3) {
|
|
46
|
+
var value = _ref3.value,
|
|
47
|
+
dataIndex = _ref3.dataIndex;
|
|
48
|
+
setFilterRecords(function (current) {
|
|
49
|
+
if (isEmptyFilterValue(value)) {
|
|
50
|
+
return current.filter(function (item) {
|
|
51
|
+
return item.dataIndex !== dataIndex;
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
var index = current.findIndex(function (item) {
|
|
55
|
+
return item.dataIndex === dataIndex;
|
|
42
56
|
});
|
|
43
|
-
if (
|
|
44
|
-
|
|
57
|
+
if (index === -1) {
|
|
58
|
+
return [].concat(_toConsumableArray(current), [{
|
|
45
59
|
dataIndex: dataIndex,
|
|
46
60
|
value: value
|
|
47
|
-
});
|
|
61
|
+
}]);
|
|
48
62
|
}
|
|
49
|
-
|
|
50
|
-
|
|
63
|
+
return current.map(function (item, itemIndex) {
|
|
64
|
+
return itemIndex === index ? _objectSpread(_objectSpread({}, item), {}, {
|
|
65
|
+
value: value
|
|
66
|
+
}) : item;
|
|
67
|
+
});
|
|
68
|
+
});
|
|
51
69
|
};
|
|
52
70
|
var filtered = useMemo(function () {
|
|
53
|
-
var handled = filterRecords.filter(function (
|
|
54
|
-
|
|
71
|
+
var handled = filterRecords.filter(function (_ref4) {
|
|
72
|
+
var dataIndex = _ref4.dataIndex,
|
|
73
|
+
value = _ref4.value;
|
|
74
|
+
return Boolean(dataIndex) && columnMap.has(dataIndex) && !isEmptyFilterValue(value);
|
|
55
75
|
});
|
|
56
76
|
if (!handled.length) {
|
|
57
77
|
return data;
|
|
58
78
|
}
|
|
59
79
|
return data.filter(function (item) {
|
|
60
|
-
return handled.
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
80
|
+
return handled.every(function (_ref5) {
|
|
81
|
+
var _columnMap$get;
|
|
82
|
+
var dataIndex = _ref5.dataIndex,
|
|
83
|
+
value = _ref5.value;
|
|
84
|
+
var customFilter = (_columnMap$get = columnMap.get(dataIndex)) === null || _columnMap$get === void 0 || (_columnMap$get = _columnMap$get.filter) === null || _columnMap$get === void 0 ? void 0 : _columnMap$get.onFilter;
|
|
85
|
+
if (customFilter) {
|
|
86
|
+
return Array.isArray(value) ? value.some(function (filterValue) {
|
|
87
|
+
return customFilter(filterValue, item);
|
|
88
|
+
}) : customFilter(value, item);
|
|
89
|
+
}
|
|
90
|
+
var targetValue = normalizeValue(item[dataIndex]);
|
|
91
|
+
if (Array.isArray(value)) {
|
|
92
|
+
return value.some(function (filterValue) {
|
|
93
|
+
return targetValue === normalizeValue(filterValue);
|
|
65
94
|
});
|
|
66
|
-
} else {
|
|
67
|
-
var v = o.value.toLowerCase();
|
|
68
|
-
var t = item[o.dataIndex] || '';
|
|
69
|
-
return t.toLowerCase().includes(v);
|
|
70
95
|
}
|
|
96
|
+
return targetValue.includes(normalizeValue(value));
|
|
71
97
|
});
|
|
72
98
|
});
|
|
73
|
-
}, [data, filterRecords]);
|
|
99
|
+
}, [columnMap, data, filterRecords]);
|
|
74
100
|
return {
|
|
75
101
|
data: filtered,
|
|
102
|
+
filterRecords: filterRecords,
|
|
76
103
|
onFilter: onFilter
|
|
77
104
|
};
|
|
78
105
|
}
|