@zhenliang/sheet 0.1.27 → 0.1.29
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/core/reducers/keyboardReducer.js +2 -1
- package/dist/core/sheet/Control.d.ts +10 -0
- package/dist/core/sheet/Control.js +32 -0
- package/dist/core/sheet/DefaultRow.js +1 -7
- package/dist/core/sheet/Menu.d.ts +6 -0
- package/dist/core/sheet/Menu.js +21 -0
- package/dist/core/sheet/index.js +66 -65
- package/dist/core/sheet/useSelectVisible.js +1 -0
- package/dist/core/sheet/useVirtualList.d.ts +10 -1
- package/dist/core/sheet/useVirtualList.js +38 -38
- package/dist/core/shell/draggableShell/index.js +9 -2
- package/dist/core/table/events.d.ts +0 -2
- package/dist/core/table/events.js +15 -24
- package/dist/core/table/index.js +60 -168
- package/dist/core/table/useGroupConfig.d.ts +4 -1
- package/dist/core/table/useGroupConfig.js +78 -1
- package/dist/core/table/useRowSelection.d.ts +13 -1
- package/dist/core/table/useRowSelection.js +50 -0
- package/dist/core/util.d.ts +1 -1
- package/dist/core/util.js +5 -4
- package/dist/core/viewer/groupViewer/index.js +22 -9
- package/dist/example/sheet.js +1 -1
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useGroupConfig.d.ts +4 -0
- package/dist/hooks/useGroupConfig.js +5 -0
- package/dist/hooks/useWidthConfig.d.ts +3 -3
- package/dist/type/sheet.d.ts +15 -3
- package/dist/type/sheetTable.d.ts +2 -2
- package/package.json +1 -1
package/dist/core/table/index.js
CHANGED
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
2
|
var _excluded = ["sheetInstance", "columns", "dataSource", "rowKey", "rowSelection", "groupConfig", "onChange", "handleAdd", "draggable", "eventHandler"];
|
|
3
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
-
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
6
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
7
3
|
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
8
4
|
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
9
5
|
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
@@ -18,22 +14,19 @@ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
|
18
14
|
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
19
15
|
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
20
16
|
import { Sheet, useSetState } from "../..";
|
|
17
|
+
import { GroupContext } from "../../hooks/useGroupConfig";
|
|
21
18
|
import { WidthContext } from "../../hooks/useWidthConfig";
|
|
22
19
|
import { Button } from 'antd';
|
|
23
20
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
24
21
|
import { SheetEvent } from "../sheet/Event";
|
|
25
22
|
import { DraggableShell } from "../shell/draggableShell";
|
|
26
23
|
import { TableShell } from "../shell/tableShell";
|
|
27
|
-
import { groupConfigToGroupMap } from "../util";
|
|
28
|
-
import { CheckViewer } from "../viewer/checkViewer";
|
|
29
|
-
import { GroupViewer } from "../viewer/groupViewer";
|
|
30
24
|
import { GroupEvent, SelectionEvent } from "./events";
|
|
31
|
-
import { useGroupConfig } from "./useGroupConfig";
|
|
32
|
-
import { useRowSelection } from "./useRowSelection";
|
|
25
|
+
import { formatGroupData, useGroupConfig } from "./useGroupConfig";
|
|
26
|
+
import { formatSelectionData, useRowSelection } from "./useRowSelection";
|
|
33
27
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
34
28
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
35
29
|
var Table = function Table(_ref) {
|
|
36
|
-
var _rowGroupConfig$group, _rowGroupConfig$group2;
|
|
37
30
|
var sheetRef = _ref.sheetInstance,
|
|
38
31
|
columns = _ref.columns,
|
|
39
32
|
dataSource = _ref.dataSource,
|
|
@@ -72,119 +65,26 @@ var Table = function Table(_ref) {
|
|
|
72
65
|
_useGroupConfig2 = _slicedToArray(_useGroupConfig, 2),
|
|
73
66
|
rowGroupConfig = _useGroupConfig2[0],
|
|
74
67
|
setGroupConfig = _useGroupConfig2[1];
|
|
75
|
-
var _ref2 = rowGroupConfig || {},
|
|
76
|
-
groups = _ref2.groups,
|
|
77
|
-
groupOpen = _ref2.groupOpen;
|
|
78
68
|
useEffect(function () {
|
|
79
69
|
if (!hasChildren) return;
|
|
80
70
|
if (!dataSource || !columns) return;
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
});
|
|
86
|
-
|
|
87
|
-
dataSource.forEach(function (item, row) {
|
|
88
|
-
var groupList = [item];
|
|
89
|
-
if (item.children) {
|
|
90
|
-
groupList = [item].concat(_toConsumableArray(item.children));
|
|
91
|
-
}
|
|
92
|
-
groupList.forEach(function (itemRow) {
|
|
93
|
-
var _columns$, _columns$2, _columns$3, _columns$4, _groupMap$get, _groupMap$get2;
|
|
94
|
-
var dataRow = [];
|
|
95
|
-
var rowId = itemRow.id || itemRow.key || String(currentIndex);
|
|
96
|
-
if (rowKey) {
|
|
97
|
-
if (rowKey instanceof Function) {
|
|
98
|
-
rowId = rowKey(itemRow, row);
|
|
99
|
-
} else {
|
|
100
|
-
rowId = itemRow[rowKey];
|
|
101
|
-
}
|
|
102
|
-
}
|
|
103
|
-
dataRow.push({
|
|
104
|
-
id: rowId,
|
|
105
|
-
row: currentIndex,
|
|
106
|
-
col: -1,
|
|
107
|
-
editable: !((columns === null || columns === void 0 ? void 0 : columns[0].editable) instanceof Function) ? columns === null || columns === void 0 || (_columns$ = columns[0]) === null || _columns$ === void 0 ? void 0 : _columns$.editable : columns === null || columns === void 0 || (_columns$2 = columns[0]) === null || _columns$2 === void 0 ? void 0 : _columns$2.editable('', itemRow, currentIndex),
|
|
108
|
-
readonly: !((columns === null || columns === void 0 ? void 0 : columns[0].readonly) instanceof Function) ? columns === null || columns === void 0 || (_columns$3 = columns[0]) === null || _columns$3 === void 0 ? void 0 : _columns$3.readonly : columns === null || columns === void 0 || (_columns$4 = columns[0]) === null || _columns$4 === void 0 ? void 0 : _columns$4.readonly('', itemRow, currentIndex),
|
|
109
|
-
align: 'center',
|
|
110
|
-
fixed: 'unset',
|
|
111
|
-
value: groupMap.get(currentIndex) && ((_groupMap$get = groupMap.get(currentIndex)) === null || _groupMap$get === void 0 ? void 0 : _groupMap$get.isStart),
|
|
112
|
-
record: {
|
|
113
|
-
open: groupMap.get(currentIndex) && ((_groupMap$get2 = groupMap.get(currentIndex)) === null || _groupMap$get2 === void 0 ? void 0 : _groupMap$get2.isOpen)
|
|
114
|
-
},
|
|
115
|
-
valueViewer: GroupViewer,
|
|
116
|
-
className: 'sheet-control'
|
|
117
|
-
});
|
|
118
|
-
columns.forEach(function (colInfo, col) {
|
|
119
|
-
var _colInfo$cellConfig, _colInfo$cellConfig2, _colInfo$cellConfig3;
|
|
120
|
-
var value = itemRow[colInfo.dataIndex || ''];
|
|
121
|
-
dataRow.push({
|
|
122
|
-
id: rowId,
|
|
123
|
-
value: value,
|
|
124
|
-
record: itemRow,
|
|
125
|
-
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, itemRow, currentIndex, col),
|
|
126
|
-
align: colInfo.align,
|
|
127
|
-
fixed: colInfo.fixed,
|
|
128
|
-
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, itemRow, currentIndex, col),
|
|
129
|
-
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
130
|
-
dataEditor: colInfo.editor ? colInfo.editor : undefined,
|
|
131
|
-
row: currentIndex,
|
|
132
|
-
className: !(((_colInfo$cellConfig = colInfo.cellConfig) === null || _colInfo$cellConfig === void 0 ? void 0 : _colInfo$cellConfig.className) instanceof Function) ? (_colInfo$cellConfig2 = colInfo.cellConfig) === null || _colInfo$cellConfig2 === void 0 ? void 0 : _colInfo$cellConfig2.className : (_colInfo$cellConfig3 = colInfo.cellConfig) === null || _colInfo$cellConfig3 === void 0 ? void 0 : _colInfo$cellConfig3.className(value, itemRow, currentIndex),
|
|
133
|
-
col: col
|
|
134
|
-
});
|
|
135
|
-
});
|
|
136
|
-
data.push(dataRow);
|
|
137
|
-
currentIndex++;
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
setData(data);
|
|
141
|
-
}, [dataSource, columns, groups, hasChildren, rowGroupConfig]);
|
|
71
|
+
setData(formatGroupData({
|
|
72
|
+
dataSource: dataSource,
|
|
73
|
+
columns: columns,
|
|
74
|
+
rowKey: rowKey
|
|
75
|
+
}));
|
|
76
|
+
}, [dataSource, columns, hasChildren, rowKey]);
|
|
142
77
|
useEffect(function () {
|
|
143
78
|
if (hasChildren) return;
|
|
144
79
|
if (!dataSource || !columns) return;
|
|
145
|
-
setData(
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
rowId = item[rowKey];
|
|
152
|
-
}
|
|
153
|
-
}
|
|
154
|
-
var rows = [];
|
|
155
|
-
if (rowSelection) {
|
|
156
|
-
rows.push({
|
|
157
|
-
id: rowId,
|
|
158
|
-
row: row,
|
|
159
|
-
col: -1,
|
|
160
|
-
readonly: true,
|
|
161
|
-
align: 'center',
|
|
162
|
-
value: checkedRow[row],
|
|
163
|
-
valueViewer: CheckViewer,
|
|
164
|
-
className: 'sheet-control'
|
|
165
|
-
});
|
|
166
|
-
}
|
|
167
|
-
columns.forEach(function (colInfo, col) {
|
|
168
|
-
var _colInfo$cellConfig4, _colInfo$cellConfig5, _colInfo$cellConfig6;
|
|
169
|
-
var value = item[colInfo.dataIndex || ''];
|
|
170
|
-
rows.push({
|
|
171
|
-
id: rowId,
|
|
172
|
-
value: value,
|
|
173
|
-
record: item,
|
|
174
|
-
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, item, row, col),
|
|
175
|
-
align: colInfo.align,
|
|
176
|
-
fixed: colInfo.fixed,
|
|
177
|
-
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, item, row),
|
|
178
|
-
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
179
|
-
dataEditor: colInfo.editor ? colInfo.editor : undefined,
|
|
180
|
-
className: !(((_colInfo$cellConfig4 = colInfo.cellConfig) === null || _colInfo$cellConfig4 === void 0 ? void 0 : _colInfo$cellConfig4.className) instanceof Function) ? (_colInfo$cellConfig5 = colInfo.cellConfig) === null || _colInfo$cellConfig5 === void 0 ? void 0 : _colInfo$cellConfig5.className : (_colInfo$cellConfig6 = colInfo.cellConfig) === null || _colInfo$cellConfig6 === void 0 ? void 0 : _colInfo$cellConfig6.className(value, item, row),
|
|
181
|
-
row: row,
|
|
182
|
-
col: col
|
|
183
|
-
});
|
|
184
|
-
});
|
|
185
|
-
return rows;
|
|
80
|
+
setData(formatSelectionData({
|
|
81
|
+
dataSource: dataSource,
|
|
82
|
+
columns: columns,
|
|
83
|
+
checked: checkedRow,
|
|
84
|
+
rowKey: rowKey,
|
|
85
|
+
rowSelection: rowSelection
|
|
186
86
|
}));
|
|
187
|
-
}, [dataSource, columns, checkedRow, hasChildren]);
|
|
87
|
+
}, [dataSource, columns, checkedRow, hasChildren, rowKey, rowSelection]);
|
|
188
88
|
useEffect(function () {
|
|
189
89
|
if (!dataSource || !columns) {
|
|
190
90
|
setData([[]]);
|
|
@@ -210,17 +110,15 @@ var Table = function Table(_ref) {
|
|
|
210
110
|
}));
|
|
211
111
|
}, [columns, onChange, hasControl]);
|
|
212
112
|
var handleReverse = useCallback(function (value) {
|
|
213
|
-
var
|
|
214
|
-
type =
|
|
215
|
-
extraInfo =
|
|
113
|
+
var _ref2 = value,
|
|
114
|
+
type = _ref2.type,
|
|
115
|
+
extraInfo = _ref2.extraInfo;
|
|
216
116
|
if (type === 'Custom') {
|
|
217
|
-
var
|
|
218
|
-
_groupConfig =
|
|
219
|
-
extraType =
|
|
220
|
-
lastData = _ref4.data;
|
|
117
|
+
var _ref3 = extraInfo,
|
|
118
|
+
_groupConfig = _ref3.groupConfig,
|
|
119
|
+
extraType = _ref3.extraType;
|
|
221
120
|
if (extraType === 'group') {
|
|
222
121
|
setGroupConfig(_groupConfig);
|
|
223
|
-
setData(lastData);
|
|
224
122
|
}
|
|
225
123
|
}
|
|
226
124
|
}, [data, groupConfig]);
|
|
@@ -232,9 +130,6 @@ var Table = function Table(_ref) {
|
|
|
232
130
|
newChecked[currentRow] = !newChecked[currentRow];
|
|
233
131
|
setCheckedRow(newChecked);
|
|
234
132
|
}, [sheetInstance, checkedRow]);
|
|
235
|
-
var headGroupOpen = !(rowGroupConfig !== null && rowGroupConfig !== void 0 && (_rowGroupConfig$group = rowGroupConfig.groupOpen) !== null && _rowGroupConfig$group !== void 0 && _rowGroupConfig$group.length) ? !!(rowGroupConfig !== null && rowGroupConfig !== void 0 && rowGroupConfig.defaultOpen) : !(rowGroupConfig !== null && rowGroupConfig !== void 0 && (_rowGroupConfig$group2 = rowGroupConfig.groupOpen) !== null && _rowGroupConfig$group2 !== void 0 && _rowGroupConfig$group2.some(function (value) {
|
|
236
|
-
return !value;
|
|
237
|
-
}));
|
|
238
133
|
var headSelection = !!rowSelection;
|
|
239
134
|
var WrappedTableShell = useMemo(function () {
|
|
240
135
|
if (draggable) {
|
|
@@ -244,9 +139,6 @@ var Table = function Table(_ref) {
|
|
|
244
139
|
showGroup: hasChildren,
|
|
245
140
|
showSelect: !!rowSelection,
|
|
246
141
|
controlProps: {
|
|
247
|
-
group: {
|
|
248
|
-
open: headGroupOpen
|
|
249
|
-
},
|
|
250
142
|
check: {
|
|
251
143
|
checked: false
|
|
252
144
|
}
|
|
@@ -259,55 +151,55 @@ var Table = function Table(_ref) {
|
|
|
259
151
|
showGroup: hasChildren,
|
|
260
152
|
showSelect: !!rowSelection,
|
|
261
153
|
controlProps: {
|
|
262
|
-
group: {
|
|
263
|
-
open: headGroupOpen
|
|
264
|
-
},
|
|
265
154
|
check: {
|
|
266
155
|
checked: false
|
|
267
156
|
}
|
|
268
157
|
}
|
|
269
158
|
});
|
|
270
|
-
}, [columns.length, draggable, headSelection, hasChildren
|
|
159
|
+
}, [columns.length, draggable, headSelection, hasChildren]);
|
|
271
160
|
return /*#__PURE__*/_jsx(WidthContext.Provider, {
|
|
272
161
|
value: {
|
|
273
162
|
widths: widths,
|
|
274
163
|
onChange: setWidth
|
|
275
164
|
},
|
|
276
|
-
children: /*#__PURE__*/
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
rowSelection: rowSelection,
|
|
285
|
-
onChange: handleRowSelect
|
|
286
|
-
}), /*#__PURE__*/_jsx(GroupEvent, {
|
|
287
|
-
hasChildren: hasChildren,
|
|
165
|
+
children: /*#__PURE__*/_jsx(GroupContext.Provider, {
|
|
166
|
+
value: {
|
|
167
|
+
config: rowGroupConfig,
|
|
168
|
+
onChange: setGroupConfig
|
|
169
|
+
},
|
|
170
|
+
children: /*#__PURE__*/_jsxs(Sheet, _objectSpread(_objectSpread({}, args), {}, {
|
|
171
|
+
sheetInstance: sheetInstance,
|
|
172
|
+
sheetRenderer: WrappedTableShell,
|
|
288
173
|
data: data,
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
174
|
+
onCellsChanged: handleChanges,
|
|
175
|
+
children: [/*#__PURE__*/_jsx(SelectionEvent, {
|
|
176
|
+
hasChildren: hasChildren,
|
|
177
|
+
rowSelection: rowSelection,
|
|
178
|
+
onChange: handleRowSelect
|
|
179
|
+
}), /*#__PURE__*/_jsx(GroupEvent, {
|
|
180
|
+
hasChildren: hasChildren,
|
|
181
|
+
data: data,
|
|
182
|
+
sheetInstance: sheetInstance.current,
|
|
183
|
+
onGridChange: setData
|
|
184
|
+
}), /*#__PURE__*/_jsx(SheetEvent, {
|
|
185
|
+
name: "reverse",
|
|
186
|
+
handler: handleReverse
|
|
187
|
+
}, "_reverse"), Object.keys(eventHandler || {}).map(function (key) {
|
|
188
|
+
return /*#__PURE__*/_jsx(SheetEvent, {
|
|
189
|
+
name: key,
|
|
190
|
+
handler: eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler[key]
|
|
191
|
+
}, key);
|
|
192
|
+
}), handleAdd ? /*#__PURE__*/_jsx(Button, {
|
|
193
|
+
type: "dashed",
|
|
194
|
+
style: {
|
|
195
|
+
width: '100%',
|
|
196
|
+
height: 32
|
|
197
|
+
},
|
|
198
|
+
onClick: handleAdd,
|
|
199
|
+
children: "+ \u6DFB\u52A0"
|
|
200
|
+
}) : null]
|
|
201
|
+
}))
|
|
202
|
+
})
|
|
311
203
|
});
|
|
312
204
|
};
|
|
313
205
|
export default Table;
|
|
@@ -1,2 +1,5 @@
|
|
|
1
1
|
import type { SheetTableType, SheetType } from "../../type";
|
|
2
|
-
export declare const useGroupConfig: (dataSource: Record<string, unknown>[], tableGroupConfig?: SheetTableType.TableGroupConfig, hasChildren?: boolean) => [SheetType.RowGroupConfig
|
|
2
|
+
export declare const useGroupConfig: (dataSource: Record<string, unknown>[], tableGroupConfig?: SheetTableType.TableGroupConfig, hasChildren?: boolean) => [SheetType.RowGroupConfig & {
|
|
3
|
+
configMap: SheetType.GroupMap;
|
|
4
|
+
}, (value: SheetType.RowGroupConfig) => void];
|
|
5
|
+
export declare const formatGroupData: (param: Pick<SheetTableType.TableProps, 'dataSource' | 'columns' | 'rowKey'>) => SheetType.Cell[][];
|
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
|
2
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
3
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
4
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
5
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
6
|
+
function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
|
|
7
|
+
function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
|
|
8
|
+
function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
9
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
10
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
1
11
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
12
|
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
3
13
|
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
|
@@ -6,6 +16,8 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
|
|
|
6
16
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
17
|
import { flatten, isNil } from 'lodash';
|
|
8
18
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
19
|
+
import { groupConfigToGroupMap } from "../util";
|
|
20
|
+
import { GroupViewer } from "../viewer";
|
|
9
21
|
import { dataSourceToRowConfig } from "./util";
|
|
10
22
|
export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig, hasChildren) {
|
|
11
23
|
var _useState = useState(),
|
|
@@ -61,5 +73,70 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
|
|
|
61
73
|
setGroupConfig(value);
|
|
62
74
|
groupConfigRef.current = value;
|
|
63
75
|
}, [setGroupConfig]);
|
|
64
|
-
|
|
76
|
+
var groupMap = useMemo(function () {
|
|
77
|
+
return groupConfigToGroupMap({
|
|
78
|
+
groups: groupConfig === null || groupConfig === void 0 ? void 0 : groupConfig.groups,
|
|
79
|
+
groupOpen: groupConfig === null || groupConfig === void 0 ? void 0 : groupConfig.groupOpen
|
|
80
|
+
});
|
|
81
|
+
}, [groupConfig]);
|
|
82
|
+
return [_objectSpread(_objectSpread({}, groupConfig), {}, {
|
|
83
|
+
configMap: groupMap
|
|
84
|
+
}), handleGroupChange];
|
|
85
|
+
};
|
|
86
|
+
export var formatGroupData = function formatGroupData(param) {
|
|
87
|
+
var dataSource = param.dataSource,
|
|
88
|
+
columns = param.columns,
|
|
89
|
+
rowKey = param.rowKey;
|
|
90
|
+
var data = [];
|
|
91
|
+
var currentIndex = 0;
|
|
92
|
+
dataSource.forEach(function (item, row) {
|
|
93
|
+
var groupList = [item];
|
|
94
|
+
if (item.children) {
|
|
95
|
+
groupList = [item].concat(_toConsumableArray(item.children));
|
|
96
|
+
}
|
|
97
|
+
groupList.forEach(function (itemRow) {
|
|
98
|
+
var _columns$, _columns$2, _columns$3, _columns$4;
|
|
99
|
+
var dataRow = [];
|
|
100
|
+
var rowId = itemRow.id || itemRow.key || String(currentIndex);
|
|
101
|
+
if (rowKey) {
|
|
102
|
+
if (rowKey instanceof Function) {
|
|
103
|
+
rowId = rowKey(itemRow, row);
|
|
104
|
+
} else {
|
|
105
|
+
rowId = itemRow[rowKey];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
dataRow.push({
|
|
109
|
+
id: rowId,
|
|
110
|
+
row: currentIndex,
|
|
111
|
+
col: -1,
|
|
112
|
+
editable: !((columns === null || columns === void 0 ? void 0 : columns[0].editable) instanceof Function) ? columns === null || columns === void 0 || (_columns$ = columns[0]) === null || _columns$ === void 0 ? void 0 : _columns$.editable : columns === null || columns === void 0 || (_columns$2 = columns[0]) === null || _columns$2 === void 0 ? void 0 : _columns$2.editable('', itemRow, currentIndex),
|
|
113
|
+
readonly: !((columns === null || columns === void 0 ? void 0 : columns[0].readonly) instanceof Function) ? columns === null || columns === void 0 || (_columns$3 = columns[0]) === null || _columns$3 === void 0 ? void 0 : _columns$3.readonly : columns === null || columns === void 0 || (_columns$4 = columns[0]) === null || _columns$4 === void 0 ? void 0 : _columns$4.readonly('', itemRow, currentIndex),
|
|
114
|
+
align: 'center',
|
|
115
|
+
fixed: 'unset',
|
|
116
|
+
valueViewer: GroupViewer,
|
|
117
|
+
className: 'sheet-control'
|
|
118
|
+
});
|
|
119
|
+
columns.forEach(function (colInfo, col) {
|
|
120
|
+
var _colInfo$cellConfig, _colInfo$cellConfig2, _colInfo$cellConfig3;
|
|
121
|
+
var value = itemRow[colInfo.dataIndex || ''];
|
|
122
|
+
dataRow.push({
|
|
123
|
+
id: rowId,
|
|
124
|
+
value: value,
|
|
125
|
+
record: itemRow,
|
|
126
|
+
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, itemRow, currentIndex, col),
|
|
127
|
+
align: colInfo.align,
|
|
128
|
+
fixed: colInfo.fixed,
|
|
129
|
+
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, itemRow, currentIndex, col),
|
|
130
|
+
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
131
|
+
dataEditor: colInfo.editor ? colInfo.editor : undefined,
|
|
132
|
+
row: currentIndex,
|
|
133
|
+
className: !(((_colInfo$cellConfig = colInfo.cellConfig) === null || _colInfo$cellConfig === void 0 ? void 0 : _colInfo$cellConfig.className) instanceof Function) ? (_colInfo$cellConfig2 = colInfo.cellConfig) === null || _colInfo$cellConfig2 === void 0 ? void 0 : _colInfo$cellConfig2.className : (_colInfo$cellConfig3 = colInfo.cellConfig) === null || _colInfo$cellConfig3 === void 0 ? void 0 : _colInfo$cellConfig3.className(value, itemRow, currentIndex),
|
|
134
|
+
col: col
|
|
135
|
+
});
|
|
136
|
+
});
|
|
137
|
+
data.push(dataRow);
|
|
138
|
+
currentIndex++;
|
|
139
|
+
});
|
|
140
|
+
});
|
|
141
|
+
return data;
|
|
65
142
|
};
|
|
@@ -1,2 +1,14 @@
|
|
|
1
|
-
import { SheetTableType } from "../..";
|
|
1
|
+
import { SheetTableType, SheetType } from "../..";
|
|
2
2
|
export declare const useRowSelection: (dataSource: Record<string, unknown>[], rowSelection?: SheetTableType.TableRowSelection, hasChildren?: boolean) => [boolean[], (value: boolean[]) => void];
|
|
3
|
+
export declare const formatSelectionData: (param: Pick<SheetTableType.TableProps, "columns" | "dataSource" | "rowKey" | "rowSelection"> & {
|
|
4
|
+
checked: boolean[];
|
|
5
|
+
}) => {
|
|
6
|
+
id: string;
|
|
7
|
+
row: number;
|
|
8
|
+
col: number;
|
|
9
|
+
readonly: boolean;
|
|
10
|
+
align: SheetType.CellAlign;
|
|
11
|
+
value: string;
|
|
12
|
+
valueViewer: SheetType.CellViewer;
|
|
13
|
+
className: string;
|
|
14
|
+
}[][];
|
|
@@ -4,6 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
4
|
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; }
|
|
5
5
|
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; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { CheckViewer } from "../..";
|
|
7
8
|
import { useEffect, useRef, useState } from 'react';
|
|
8
9
|
export var useRowSelection = function useRowSelection(dataSource, rowSelection, hasChildren) {
|
|
9
10
|
var _dataSource$length;
|
|
@@ -21,4 +22,53 @@ export var useRowSelection = function useRowSelection(dataSource, rowSelection,
|
|
|
21
22
|
checkedRowRef.current = currentEmpty;
|
|
22
23
|
}, [dataSource.length, hasChildren, rowSelection]);
|
|
23
24
|
return [checkedRow, setCheckedRow];
|
|
25
|
+
};
|
|
26
|
+
export var formatSelectionData = function formatSelectionData(param) {
|
|
27
|
+
var dataSource = param.dataSource,
|
|
28
|
+
columns = param.columns,
|
|
29
|
+
checked = param.checked,
|
|
30
|
+
rowKey = param.rowKey,
|
|
31
|
+
rowSelection = param.rowSelection;
|
|
32
|
+
return dataSource.map(function (item, row) {
|
|
33
|
+
var rowId = item.id || item.key || String(row);
|
|
34
|
+
if (rowKey) {
|
|
35
|
+
if (rowKey instanceof Function) {
|
|
36
|
+
rowId = rowKey(item, row);
|
|
37
|
+
} else {
|
|
38
|
+
rowId = item[rowKey];
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
var rows = [];
|
|
42
|
+
if (rowSelection) {
|
|
43
|
+
rows.push({
|
|
44
|
+
id: rowId,
|
|
45
|
+
row: row,
|
|
46
|
+
col: -1,
|
|
47
|
+
readonly: true,
|
|
48
|
+
align: 'center',
|
|
49
|
+
value: checked[row],
|
|
50
|
+
valueViewer: CheckViewer,
|
|
51
|
+
className: 'sheet-control'
|
|
52
|
+
});
|
|
53
|
+
}
|
|
54
|
+
columns.forEach(function (colInfo, col) {
|
|
55
|
+
var _colInfo$cellConfig, _colInfo$cellConfig2, _colInfo$cellConfig3;
|
|
56
|
+
var value = item[colInfo.dataIndex || ''];
|
|
57
|
+
rows.push({
|
|
58
|
+
id: rowId,
|
|
59
|
+
value: value,
|
|
60
|
+
record: item,
|
|
61
|
+
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, item, row, col),
|
|
62
|
+
align: colInfo.align,
|
|
63
|
+
fixed: colInfo.fixed,
|
|
64
|
+
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, item, row),
|
|
65
|
+
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
66
|
+
dataEditor: colInfo.editor ? colInfo.editor : undefined,
|
|
67
|
+
className: !(((_colInfo$cellConfig = colInfo.cellConfig) === null || _colInfo$cellConfig === void 0 ? void 0 : _colInfo$cellConfig.className) instanceof Function) ? (_colInfo$cellConfig2 = colInfo.cellConfig) === null || _colInfo$cellConfig2 === void 0 ? void 0 : _colInfo$cellConfig2.className : (_colInfo$cellConfig3 = colInfo.cellConfig) === null || _colInfo$cellConfig3 === void 0 ? void 0 : _colInfo$cellConfig3.className(value, item, row),
|
|
68
|
+
row: row,
|
|
69
|
+
col: col
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
return rows;
|
|
73
|
+
});
|
|
24
74
|
};
|
package/dist/core/util.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare function renderValue(cell: SheetType.Cell): string | number;
|
|
|
32
32
|
export declare const optionsToValuesFromLabelOrValue: (options: SheetType.OptionsType[], val: string) => string[];
|
|
33
33
|
export declare const optionsTransferToValue: (options: SheetType.OptionsType[], val: string, key?: string) => string[];
|
|
34
34
|
export declare const valuesTransferToLabel: (options?: SheetType.OptionsType[], value?: string) => string | null;
|
|
35
|
-
export declare const groupConfigToGroupMap: (rowGroupConfig?: SheetType.RowGroupConfig) => Map<number, SheetType.RowGroup & {
|
|
35
|
+
export declare const groupConfigToGroupMap: (rowGroupConfig?: Partial<SheetType.RowGroupConfig>) => Map<number, SheetType.RowGroup & {
|
|
36
36
|
isStart: boolean;
|
|
37
37
|
isOpen: boolean;
|
|
38
38
|
}>;
|
package/dist/core/util.js
CHANGED
|
@@ -97,7 +97,7 @@ export function stringToClipboardData(str, count) {
|
|
|
97
97
|
});
|
|
98
98
|
}
|
|
99
99
|
export var defaultParsePaste = function defaultParsePaste(str) {
|
|
100
|
-
return str.split(/\r\n|\n|\r/).map(function (row) {
|
|
100
|
+
return str.trim().split(/\r\n|\n|\r/).map(function (row) {
|
|
101
101
|
return row.split('\t');
|
|
102
102
|
});
|
|
103
103
|
};
|
|
@@ -189,7 +189,7 @@ export function formatDataToCell(_ref2) {
|
|
|
189
189
|
});
|
|
190
190
|
});
|
|
191
191
|
if (hasStartAndNotOpen) {
|
|
192
|
-
|
|
192
|
+
message.error('有折叠单元格,不可粘贴');
|
|
193
193
|
return {
|
|
194
194
|
changes: [],
|
|
195
195
|
extChanges: []
|
|
@@ -308,9 +308,10 @@ export var groupConfigToGroupMap = function groupConfigToGroupMap(rowGroupConfig
|
|
|
308
308
|
var groupStart = group.groupStart,
|
|
309
309
|
groupEnd = group.groupEnd;
|
|
310
310
|
for (var i = groupStart; i <= groupEnd; i++) {
|
|
311
|
+
var _rowGroupConfig$group2;
|
|
311
312
|
groupMap.set(i, _objectSpread(_objectSpread({}, group), {}, {
|
|
312
313
|
isStart: i === groupStart,
|
|
313
|
-
isOpen: rowGroupConfig.groupOpen[index]
|
|
314
|
+
isOpen: !!(rowGroupConfig !== null && rowGroupConfig !== void 0 && (_rowGroupConfig$group2 = rowGroupConfig.groupOpen) !== null && _rowGroupConfig$group2 !== void 0 && _rowGroupConfig$group2[index])
|
|
314
315
|
}));
|
|
315
316
|
}
|
|
316
317
|
});
|
|
@@ -354,7 +355,7 @@ export var changeGroupConfig = function changeGroupConfig(rowGroupConfig, change
|
|
|
354
355
|
});
|
|
355
356
|
};
|
|
356
357
|
export var rowToActualRow = function rowToActualRow(row, groupConfig) {
|
|
357
|
-
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] :
|
|
358
|
+
var max = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 100000;
|
|
358
359
|
var groupMap = groupConfigToGroupMap(groupConfig);
|
|
359
360
|
if (!groupMap.size || row < 0) return row;
|
|
360
361
|
var openCount = 0;
|
|
@@ -1,33 +1,46 @@
|
|
|
1
1
|
import { MinusSquareOutlined, PlusSquareOutlined } from '@ant-design/icons';
|
|
2
2
|
import { useSheetEvent } from "../../..";
|
|
3
|
+
import { useGroup } from "../../../hooks/useGroupConfig";
|
|
3
4
|
import { useCallback } from 'react';
|
|
4
5
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
5
6
|
export var GroupViewer = function GroupViewer(props) {
|
|
6
|
-
var
|
|
7
|
-
|
|
7
|
+
var _config$configMap, _config$configMap2, _config$groupOpen;
|
|
8
|
+
var _props$row = props.row,
|
|
9
|
+
row = _props$row === void 0 ? 0 : _props$row,
|
|
8
10
|
record = props.record;
|
|
11
|
+
var _ref = record || {},
|
|
12
|
+
isHeader = _ref.isHeader;
|
|
13
|
+
var _useGroup = useGroup(),
|
|
14
|
+
config = _useGroup.config;
|
|
9
15
|
var eventBus = useSheetEvent();
|
|
16
|
+
var isStart = config === null || config === void 0 || (_config$configMap = config.configMap) === null || _config$configMap === void 0 || (_config$configMap = _config$configMap.get(row)) === null || _config$configMap === void 0 ? void 0 : _config$configMap.isStart;
|
|
17
|
+
var isOpen = config === null || config === void 0 || (_config$configMap2 = config.configMap) === null || _config$configMap2 === void 0 || (_config$configMap2 = _config$configMap2.get(row)) === null || _config$configMap2 === void 0 ? void 0 : _config$configMap2.isOpen;
|
|
18
|
+
var allOpen = !(config !== null && config !== void 0 && (_config$groupOpen = config.groupOpen) !== null && _config$groupOpen !== void 0 && _config$groupOpen.some(function (value) {
|
|
19
|
+
return !value;
|
|
20
|
+
}));
|
|
10
21
|
var handleChange = useCallback(function () {
|
|
11
22
|
if (!eventBus) return;
|
|
12
|
-
if (
|
|
13
|
-
eventBus.emit('group-open-title', !
|
|
23
|
+
if (isHeader) {
|
|
24
|
+
eventBus.emit('group-open-title', !allOpen);
|
|
14
25
|
} else {
|
|
15
26
|
eventBus.emit('group-open', {
|
|
16
27
|
row: row,
|
|
17
|
-
open:
|
|
28
|
+
open: !isOpen
|
|
18
29
|
});
|
|
19
30
|
}
|
|
20
|
-
}, [eventBus, row,
|
|
21
|
-
if (
|
|
31
|
+
}, [eventBus, row, isOpen, allOpen]);
|
|
32
|
+
if (isStart || isHeader) {
|
|
33
|
+
var currentOpen = record !== null && record !== void 0 && record.isHeader ? allOpen : isOpen;
|
|
22
34
|
return /*#__PURE__*/_jsx("span", {
|
|
23
35
|
style: {
|
|
24
|
-
cursor: 'pointer'
|
|
36
|
+
cursor: 'pointer',
|
|
37
|
+
pointerEvents: 'all'
|
|
25
38
|
},
|
|
26
39
|
onMouseDown: function onMouseDown(e) {
|
|
27
40
|
return e.stopPropagation();
|
|
28
41
|
},
|
|
29
42
|
onClick: handleChange,
|
|
30
|
-
children: !
|
|
43
|
+
children: !currentOpen ? /*#__PURE__*/_jsx(PlusSquareOutlined, {
|
|
31
44
|
rev: undefined
|
|
32
45
|
}) : /*#__PURE__*/_jsx(MinusSquareOutlined, {
|
|
33
46
|
rev: undefined
|
package/dist/example/sheet.js
CHANGED
package/dist/hooks/index.d.ts
CHANGED
|
@@ -5,4 +5,4 @@ export type { Dispatch, FunctionAction, NormalAction, } from './useMiddlewareRed
|
|
|
5
5
|
export { useMouse } from './useMouse';
|
|
6
6
|
export { useSetState } from './useSetState';
|
|
7
7
|
export { SheetEventContext, useSheetEvent } from './useSheetEvent';
|
|
8
|
-
export {
|
|
8
|
+
export { WidthContext, useWidth } from './useWidthConfig';
|
package/dist/hooks/index.js
CHANGED
|
@@ -4,4 +4,4 @@ export { useMiddlewareReducer } from "./useMiddlewareReducer";
|
|
|
4
4
|
export { useMouse } from "./useMouse";
|
|
5
5
|
export { useSetState } from "./useSetState";
|
|
6
6
|
export { SheetEventContext, useSheetEvent } from "./useSheetEvent";
|
|
7
|
-
export {
|
|
7
|
+
export { WidthContext, useWidth } from "./useWidthConfig";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
-
import {
|
|
3
|
-
export declare const WidthContext: import("react").Context<
|
|
4
|
-
export declare function useWidth():
|
|
2
|
+
import { WidthConfigContext } from '../type/sheet';
|
|
3
|
+
export declare const WidthContext: import("react").Context<WidthConfigContext>;
|
|
4
|
+
export declare function useWidth(): WidthConfigContext;
|