@zhenliang/sheet 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -2
- package/dist/core/config.js +1 -2
- package/dist/core/editor/cascaderEditor/index.js +14 -7
- package/dist/core/editor/dateEditor/index.d.ts +1 -1
- package/dist/core/editor/dateEditor/index.js +2 -3
- package/dist/core/editor/index.d.ts +1 -1
- package/dist/core/editor/index.js +2 -3
- package/dist/core/editor/numberEditor/index.js +50 -6
- package/dist/core/editor/numberEditor/index.less +1 -0
- package/dist/core/editor/selectEditor/index.d.ts +1 -1
- package/dist/core/editor/selectEditor/index.js +23 -5
- package/dist/core/reducers/index.d.ts +1 -1
- package/dist/core/reducers/index.js +3 -2
- package/dist/core/reducers/keyboardReducer.js +2 -3
- package/dist/core/reducers/mouseReducer.js +1 -2
- package/dist/core/reducers/sideEffectReducer.js +49 -25
- package/dist/core/reducers/stateReducer.js +35 -10
- package/dist/core/sheet/Cell.js +37 -16
- package/dist/core/sheet/DataEditor.js +4 -2
- package/dist/core/sheet/DefaultCell.js +1 -2
- package/dist/core/sheet/DefaultRow.d.ts +1 -0
- package/dist/core/sheet/DefaultRow.js +5 -3
- package/dist/core/sheet/DefaultRowMapper.js +1 -2
- package/dist/core/sheet/DefaultShell.js +1 -2
- package/dist/core/sheet/Event.js +2 -3
- package/dist/core/sheet/ValueViewer.js +1 -2
- package/dist/core/sheet/index.js +54 -15
- package/dist/core/sheet/index.less +20 -11
- package/dist/core/sheet/useCellEvent.js +1 -2
- package/dist/core/sheet/useContextMenu.d.ts +1 -1
- package/dist/core/sheet/useContextMenu.js +2 -3
- package/dist/core/sheet/useKeyBoardEvent.js +15 -3
- package/dist/core/sheet/useMouseEvent.js +3 -4
- package/dist/core/sheet/useSelectVisible.d.ts +2 -0
- package/dist/core/sheet/useSelectVisible.js +48 -0
- package/dist/core/sheet/useVirtualList.d.ts +1 -1
- package/dist/core/sheet/useVirtualList.js +24 -20
- package/dist/core/shell/draggableShell/index.d.ts +0 -1
- package/dist/core/shell/draggableShell/index.js +21 -13
- package/dist/core/shell/tableShell.d.ts +0 -1
- package/dist/core/shell/tableShell.js +9 -6
- package/dist/core/table/events.d.ts +15 -0
- package/dist/core/table/events.js +94 -0
- package/dist/core/table/index.js +91 -112
- package/dist/core/table/useGroupConfig.js +24 -7
- package/dist/core/table/useRowSelection.d.ts +2 -1
- package/dist/core/table/useRowSelection.js +1 -2
- package/dist/core/table/util.js +2 -3
- package/dist/core/util.d.ts +5 -2
- package/dist/core/util.js +97 -16
- package/dist/core/viewer/btnViewer/index.js +2 -3
- package/dist/core/viewer/cascaderViewer/index.d.ts +2 -0
- package/dist/core/viewer/cascaderViewer/index.js +11 -0
- package/dist/core/viewer/checkViewer/index.js +2 -3
- package/dist/core/viewer/editViewer/index.js +2 -3
- package/dist/core/viewer/groupViewer/index.js +5 -3
- package/dist/core/viewer/index.d.ts +1 -0
- package/dist/core/viewer/index.js +2 -2
- package/dist/core/viewer/selectorViewer/index.d.ts +2 -0
- package/dist/core/viewer/selectorViewer/index.js +12 -0
- package/dist/core/viewer/switchViewer/index.js +2 -3
- package/dist/example/antComponent.js +60 -14
- package/dist/example/basic.js +2 -3
- package/dist/example/ellipsis.js +1 -2
- package/dist/example/fixed.js +1 -2
- package/dist/example/group.js +42 -4
- package/dist/example/selection.js +2 -3
- package/dist/example/sheet.js +52 -16
- package/dist/example/valuationAnalyze.js +20 -18
- package/dist/hooks/index.d.ts +1 -0
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useEventBus.d.ts +0 -1
- package/dist/hooks/useEventBus.js +1 -2
- package/dist/hooks/useKeyboard.js +1 -2
- package/dist/hooks/useMiddlewareReducer.js +1 -2
- package/dist/hooks/useMouse.js +1 -2
- package/dist/hooks/useSetState.js +1 -2
- package/dist/hooks/useSheetEvent.js +1 -2
- package/dist/hooks/useWidthConfig.d.ts +4 -0
- package/dist/hooks/useWidthConfig.js +5 -0
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -1
- package/dist/standardUtils/index.js +2 -3
- package/dist/type/index.js +1 -2
- package/dist/type/sheet.d.ts +14 -3
- package/dist/type/sheet.js +1 -2
- package/dist/type/sheetTable.d.ts +43 -14
- package/dist/type/sheetTable.js +1 -2
- package/package.json +1 -1
- package/dist/core/config.js.map +0 -1
- package/dist/core/editor/cascaderEditor/index.js.map +0 -1
- package/dist/core/editor/dateEditor/index.js.map +0 -1
- package/dist/core/editor/index.js.map +0 -1
- package/dist/core/editor/numberEditor/index.js.map +0 -1
- package/dist/core/editor/selectEditor/index.js.map +0 -1
- package/dist/core/reducers/index.js.map +0 -1
- package/dist/core/reducers/keyboardReducer.js.map +0 -1
- package/dist/core/reducers/mouseReducer.js.map +0 -1
- package/dist/core/reducers/sideEffectReducer.js.map +0 -1
- package/dist/core/reducers/stateReducer.js.map +0 -1
- package/dist/core/sheet/Cell.js.map +0 -1
- package/dist/core/sheet/DataEditor.js.map +0 -1
- package/dist/core/sheet/DefaultCell.js.map +0 -1
- package/dist/core/sheet/DefaultRow.js.map +0 -1
- package/dist/core/sheet/DefaultRowMapper.js.map +0 -1
- package/dist/core/sheet/DefaultShell.js.map +0 -1
- package/dist/core/sheet/Event.js.map +0 -1
- package/dist/core/sheet/ValueViewer.js.map +0 -1
- package/dist/core/sheet/index.js.map +0 -1
- package/dist/core/sheet/useCellEvent.js.map +0 -1
- package/dist/core/sheet/useContextMenu.js.map +0 -1
- package/dist/core/sheet/useKeyBoardEvent.js.map +0 -1
- package/dist/core/sheet/useMouseEvent.js.map +0 -1
- package/dist/core/sheet/useVirtualList.js.map +0 -1
- package/dist/core/shell/draggableShell/index.js.map +0 -1
- package/dist/core/shell/tableShell.js.map +0 -1
- package/dist/core/table/index.js.map +0 -1
- package/dist/core/table/useGroupConfig.js.map +0 -1
- package/dist/core/table/useRowSelection.js.map +0 -1
- package/dist/core/table/util.js.map +0 -1
- package/dist/core/util.js.map +0 -1
- package/dist/core/viewer/btnViewer/index.js.map +0 -1
- package/dist/core/viewer/checkViewer/index.js.map +0 -1
- package/dist/core/viewer/editViewer/index.js.map +0 -1
- package/dist/core/viewer/groupViewer/index.js.map +0 -1
- package/dist/core/viewer/index.js.map +0 -1
- package/dist/core/viewer/switchViewer/index.js.map +0 -1
- package/dist/example/antComponent.js.map +0 -1
- package/dist/example/basic.js.map +0 -1
- package/dist/example/ellipsis.js.map +0 -1
- package/dist/example/fixed.js.map +0 -1
- package/dist/example/group.js.map +0 -1
- package/dist/example/selection.js.map +0 -1
- package/dist/example/sheet.js.map +0 -1
- package/dist/example/valuationAnalyze.js.map +0 -1
- package/dist/hooks/index.js.map +0 -1
- package/dist/hooks/useEventBus.js.map +0 -1
- package/dist/hooks/useKeyboard.js.map +0 -1
- package/dist/hooks/useMiddlewareReducer.js.map +0 -1
- package/dist/hooks/useMouse.js.map +0 -1
- package/dist/hooks/useSetState.js.map +0 -1
- package/dist/hooks/useSheetEvent.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/standardUtils/index.js.map +0 -1
- package/dist/type/index.js.map +0 -1
- package/dist/type/sheet.js.map +0 -1
- package/dist/type/sheetTable.js.map +0 -1
package/dist/core/table/index.js
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
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); }
|
|
3
7
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
8
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
5
9
|
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; }
|
|
6
10
|
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
7
11
|
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); }
|
|
8
|
-
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
9
|
-
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."); }
|
|
10
|
-
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
|
-
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
12
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
13
|
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."); }
|
|
14
14
|
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); }
|
|
@@ -17,7 +17,8 @@ function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefine
|
|
|
17
17
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
18
18
|
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
19
|
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
|
-
import { Sheet } from "../..";
|
|
20
|
+
import { Sheet, useSetState } from "../..";
|
|
21
|
+
import { WidthContext } from "../../hooks/useWidthConfig";
|
|
21
22
|
import { Button } from 'antd';
|
|
22
23
|
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
23
24
|
import { SheetEvent } from "../sheet/Event";
|
|
@@ -26,11 +27,13 @@ import { TableShell } from "../shell/tableShell";
|
|
|
26
27
|
import { groupConfigToGroupMap } from "../util";
|
|
27
28
|
import { CheckViewer } from "../viewer/checkViewer";
|
|
28
29
|
import { GroupViewer } from "../viewer/groupViewer";
|
|
30
|
+
import { GroupEvent, SelectionEvent } from "./events";
|
|
29
31
|
import { useGroupConfig } from "./useGroupConfig";
|
|
30
32
|
import { useRowSelection } from "./useRowSelection";
|
|
31
33
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
32
34
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
33
35
|
var Table = function Table(_ref) {
|
|
36
|
+
var _rowGroupConfig$group;
|
|
34
37
|
var sheetRef = _ref.sheetInstance,
|
|
35
38
|
columns = _ref.columns,
|
|
36
39
|
dataSource = _ref.dataSource,
|
|
@@ -47,19 +50,23 @@ var Table = function Table(_ref) {
|
|
|
47
50
|
data = _useState2[0],
|
|
48
51
|
setData = _useState2[1];
|
|
49
52
|
var _sheetInstance = useRef(null);
|
|
53
|
+
var _useSetState = useSetState({}),
|
|
54
|
+
_useSetState2 = _slicedToArray(_useSetState, 2),
|
|
55
|
+
widths = _useSetState2[0],
|
|
56
|
+
setWidth = _useSetState2[1];
|
|
50
57
|
var sheetInstance = sheetRef || _sheetInstance;
|
|
51
|
-
var hasChildren = dataSource === null || dataSource === void 0 ? void 0 : dataSource.some(function (item) {
|
|
58
|
+
var hasChildren = (dataSource === null || dataSource === void 0 ? void 0 : dataSource.some(function (item) {
|
|
52
59
|
var _item$children;
|
|
53
60
|
return (item === null || item === void 0 ? void 0 : (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0;
|
|
54
|
-
});
|
|
55
|
-
var hasControl = hasChildren || rowSelection;
|
|
61
|
+
})) || !!groupConfig;
|
|
62
|
+
var hasControl = hasChildren || !!rowSelection;
|
|
56
63
|
var _useRowSelection = useRowSelection(dataSource, rowSelection, hasChildren),
|
|
57
64
|
_useRowSelection2 = _slicedToArray(_useRowSelection, 2),
|
|
58
65
|
checkedRow = _useRowSelection2[0],
|
|
59
66
|
setCheckedRow = _useRowSelection2[1];
|
|
60
|
-
var _useGroupConfig = useGroupConfig(dataSource, {
|
|
67
|
+
var _useGroupConfig = useGroupConfig(dataSource, _objectSpread({
|
|
61
68
|
defaultOpen: true
|
|
62
|
-
}, hasChildren),
|
|
69
|
+
}, groupConfig), hasChildren),
|
|
63
70
|
_useGroupConfig2 = _slicedToArray(_useGroupConfig, 2),
|
|
64
71
|
rowGroupConfig = _useGroupConfig2[0],
|
|
65
72
|
setGroupConfig = _useGroupConfig2[1];
|
|
@@ -81,22 +88,24 @@ var Table = function Table(_ref) {
|
|
|
81
88
|
groupList = [item].concat(_toConsumableArray(item.children));
|
|
82
89
|
}
|
|
83
90
|
groupList.forEach(function (itemRow) {
|
|
84
|
-
var _groupMap$get, _groupMap$get2;
|
|
91
|
+
var _columns$, _columns$2, _columns$3, _columns$4, _groupMap$get, _groupMap$get2;
|
|
85
92
|
var dataRow = [];
|
|
86
|
-
var rowId =
|
|
93
|
+
var rowId = itemRow.id || itemRow.key || String(currentIndex);
|
|
87
94
|
if (rowKey) {
|
|
88
95
|
if (rowKey instanceof Function) {
|
|
89
|
-
rowId = rowKey(
|
|
96
|
+
rowId = rowKey(itemRow, row);
|
|
90
97
|
} else {
|
|
91
|
-
rowId =
|
|
98
|
+
rowId = itemRow[rowKey];
|
|
92
99
|
}
|
|
93
100
|
}
|
|
94
101
|
dataRow.push({
|
|
95
102
|
id: rowId,
|
|
96
103
|
row: currentIndex,
|
|
97
104
|
col: -1,
|
|
98
|
-
editable:
|
|
105
|
+
editable: !((columns === null || columns === void 0 ? void 0 : columns[0].editable) instanceof Function) ? columns === null || columns === void 0 ? void 0 : (_columns$ = columns[0]) === null || _columns$ === void 0 ? void 0 : _columns$.editable : columns === null || columns === void 0 ? void 0 : (_columns$2 = columns[0]) === null || _columns$2 === void 0 ? void 0 : _columns$2.editable('', itemRow, currentIndex),
|
|
106
|
+
readonly: !((columns === null || columns === void 0 ? void 0 : columns[0].readonly) instanceof Function) ? columns === null || columns === void 0 ? void 0 : (_columns$3 = columns[0]) === null || _columns$3 === void 0 ? void 0 : _columns$3.readonly : columns === null || columns === void 0 ? void 0 : (_columns$4 = columns[0]) === null || _columns$4 === void 0 ? void 0 : _columns$4.readonly('', itemRow, currentIndex),
|
|
99
107
|
align: 'center',
|
|
108
|
+
fixed: 'unset',
|
|
100
109
|
value: groupMap.get(currentIndex) && ((_groupMap$get = groupMap.get(currentIndex)) === null || _groupMap$get === void 0 ? void 0 : _groupMap$get.isStart),
|
|
101
110
|
record: {
|
|
102
111
|
open: groupMap.get(currentIndex) && ((_groupMap$get2 = groupMap.get(currentIndex)) === null || _groupMap$get2 === void 0 ? void 0 : _groupMap$get2.isOpen)
|
|
@@ -105,6 +114,7 @@ var Table = function Table(_ref) {
|
|
|
105
114
|
className: 'sheet-control'
|
|
106
115
|
});
|
|
107
116
|
columns.forEach(function (colInfo, col) {
|
|
117
|
+
var _colInfo$cellConfig, _colInfo$cellConfig2, _colInfo$cellConfig3;
|
|
108
118
|
var value = itemRow[colInfo.dataIndex || ''];
|
|
109
119
|
dataRow.push({
|
|
110
120
|
id: rowId,
|
|
@@ -113,10 +123,11 @@ var Table = function Table(_ref) {
|
|
|
113
123
|
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, itemRow, currentIndex),
|
|
114
124
|
align: colInfo.align,
|
|
115
125
|
fixed: colInfo.fixed,
|
|
116
|
-
editable: colInfo.editable,
|
|
126
|
+
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, itemRow, currentIndex),
|
|
117
127
|
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
118
128
|
dataEditor: colInfo.editor ? colInfo.editor : undefined,
|
|
119
129
|
row: currentIndex,
|
|
130
|
+
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),
|
|
120
131
|
col: col
|
|
121
132
|
});
|
|
122
133
|
});
|
|
@@ -130,7 +141,7 @@ var Table = function Table(_ref) {
|
|
|
130
141
|
if (hasChildren) return;
|
|
131
142
|
if (!dataSource || !columns) return;
|
|
132
143
|
setData(dataSource.map(function (item, row) {
|
|
133
|
-
var rowId = String(row);
|
|
144
|
+
var rowId = item.id || item.key || String(row);
|
|
134
145
|
if (rowKey) {
|
|
135
146
|
if (rowKey instanceof Function) {
|
|
136
147
|
rowId = rowKey(item, row);
|
|
@@ -152,6 +163,7 @@ var Table = function Table(_ref) {
|
|
|
152
163
|
});
|
|
153
164
|
}
|
|
154
165
|
columns.forEach(function (colInfo, col) {
|
|
166
|
+
var _colInfo$cellConfig4, _colInfo$cellConfig5, _colInfo$cellConfig6;
|
|
155
167
|
var value = item[colInfo.dataIndex || ''];
|
|
156
168
|
rows.push({
|
|
157
169
|
id: rowId,
|
|
@@ -160,9 +172,10 @@ var Table = function Table(_ref) {
|
|
|
160
172
|
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, item, row),
|
|
161
173
|
align: colInfo.align,
|
|
162
174
|
fixed: colInfo.fixed,
|
|
163
|
-
editable: colInfo.editable,
|
|
175
|
+
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, item, row),
|
|
164
176
|
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
165
177
|
dataEditor: colInfo.editor ? colInfo.editor : undefined,
|
|
178
|
+
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),
|
|
166
179
|
row: row,
|
|
167
180
|
col: col
|
|
168
181
|
});
|
|
@@ -175,7 +188,7 @@ var Table = function Table(_ref) {
|
|
|
175
188
|
setData([[]]);
|
|
176
189
|
}
|
|
177
190
|
}, [dataSource, columns]);
|
|
178
|
-
var handleChanges = useCallback(function (changes) {
|
|
191
|
+
var handleChanges = useCallback(function (changes, extChange) {
|
|
179
192
|
onChange && onChange(changes.map(function (item) {
|
|
180
193
|
return {
|
|
181
194
|
row: item.row,
|
|
@@ -183,6 +196,13 @@ var Table = function Table(_ref) {
|
|
|
183
196
|
key: columns[hasControl ? item.col - 1 : item.col].dataIndex,
|
|
184
197
|
value: item.value
|
|
185
198
|
};
|
|
199
|
+
}), extChange === null || extChange === void 0 ? void 0 : extChange.map(function (item) {
|
|
200
|
+
return {
|
|
201
|
+
row: item.row,
|
|
202
|
+
id: item.id,
|
|
203
|
+
key: columns[hasControl ? item.col - 1 : item.col].dataIndex,
|
|
204
|
+
value: item.value
|
|
205
|
+
};
|
|
186
206
|
}));
|
|
187
207
|
}, [columns, onChange, hasControl]);
|
|
188
208
|
var handleReverse = useCallback(function (value) {
|
|
@@ -202,15 +222,19 @@ var Table = function Table(_ref) {
|
|
|
202
222
|
}, [data, groupConfig]);
|
|
203
223
|
var handleRowSelect = useCallback(function (value) {
|
|
204
224
|
if (!sheetInstance.current) return;
|
|
225
|
+
var currentRow = value;
|
|
205
226
|
// sheetInstance.current?.selectRow(value as number);
|
|
206
227
|
var newChecked = Array(checkedRow.length).fill(false);
|
|
207
|
-
newChecked[
|
|
228
|
+
newChecked[currentRow] = !newChecked[currentRow];
|
|
208
229
|
setCheckedRow(newChecked);
|
|
209
230
|
}, [sheetInstance, checkedRow]);
|
|
231
|
+
var headGroupOpen = !(rowGroupConfig !== null && rowGroupConfig !== void 0 && (_rowGroupConfig$group = rowGroupConfig.groupOpen) !== null && _rowGroupConfig$group !== void 0 && _rowGroupConfig$group.some(function (value) {
|
|
232
|
+
return !value;
|
|
233
|
+
}));
|
|
234
|
+
var headSelection = !!rowSelection;
|
|
210
235
|
var WrappedTableShell = useMemo(function () {
|
|
211
|
-
|
|
236
|
+
console.log('shell-render', '损耗性能大');
|
|
212
237
|
if (draggable) {
|
|
213
|
-
var _rowGroupConfig$group;
|
|
214
238
|
return DraggableShell({
|
|
215
239
|
columns: columns,
|
|
216
240
|
className: 'baseTable',
|
|
@@ -218,9 +242,7 @@ var Table = function Table(_ref) {
|
|
|
218
242
|
showSelect: !!rowSelection,
|
|
219
243
|
controlProps: {
|
|
220
244
|
group: {
|
|
221
|
-
open:
|
|
222
|
-
return !value;
|
|
223
|
-
}))
|
|
245
|
+
open: headGroupOpen
|
|
224
246
|
},
|
|
225
247
|
check: {
|
|
226
248
|
checked: false
|
|
@@ -235,97 +257,54 @@ var Table = function Table(_ref) {
|
|
|
235
257
|
showSelect: !!rowSelection,
|
|
236
258
|
controlProps: {
|
|
237
259
|
group: {
|
|
238
|
-
open:
|
|
239
|
-
return !value;
|
|
240
|
-
}))
|
|
260
|
+
open: headGroupOpen
|
|
241
261
|
},
|
|
242
262
|
check: {
|
|
243
263
|
checked: false
|
|
244
264
|
}
|
|
245
265
|
}
|
|
246
266
|
});
|
|
247
|
-
}, [columns, draggable,
|
|
248
|
-
return /*#__PURE__*/
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
data: data
|
|
290
|
-
}
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
}, "group-open"), /*#__PURE__*/_jsx(SheetEvent, {
|
|
295
|
-
name: "group-open-title",
|
|
296
|
-
handler: function handler(value) {
|
|
297
|
-
var _sheetInstance$curren2;
|
|
298
|
-
setGroupConfig(_objectSpread(_objectSpread({}, rowGroupConfig), {}, {
|
|
299
|
-
groupOpen: Array(rowGroupConfig.groupOpen.length).fill(value)
|
|
300
|
-
}));
|
|
301
|
-
(_sheetInstance$curren2 = sheetInstance.current) === null || _sheetInstance$curren2 === void 0 ? void 0 : _sheetInstance$curren2.pushToHistory({
|
|
302
|
-
type: 'Custom',
|
|
303
|
-
changes: [],
|
|
304
|
-
extraInfo: {
|
|
305
|
-
extraType: 'group',
|
|
306
|
-
groupConfig: rowGroupConfig,
|
|
307
|
-
data: data
|
|
308
|
-
}
|
|
309
|
-
});
|
|
310
|
-
}
|
|
311
|
-
}, "group-open-title")] : null, /*#__PURE__*/_jsx(SheetEvent, {
|
|
312
|
-
name: "reverse",
|
|
313
|
-
handler: handleReverse
|
|
314
|
-
}, "_reverse"), Object.keys(eventHandler || {}).map(function (key) {
|
|
315
|
-
return /*#__PURE__*/_jsx(SheetEvent, {
|
|
316
|
-
name: key,
|
|
317
|
-
handler: eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler[key]
|
|
318
|
-
}, key);
|
|
319
|
-
}), handleAdd ? /*#__PURE__*/_jsx(Button, {
|
|
320
|
-
type: "dashed",
|
|
321
|
-
style: {
|
|
322
|
-
width: '100%',
|
|
323
|
-
height: 32
|
|
324
|
-
},
|
|
325
|
-
onClick: handleAdd,
|
|
326
|
-
children: "+ \u6DFB\u52A0"
|
|
327
|
-
}) : null]
|
|
328
|
-
}));
|
|
267
|
+
}, [columns.length, draggable, headSelection, hasChildren, headGroupOpen]);
|
|
268
|
+
return /*#__PURE__*/_jsx(WidthContext.Provider, {
|
|
269
|
+
value: {
|
|
270
|
+
widths: widths,
|
|
271
|
+
onChange: setWidth
|
|
272
|
+
},
|
|
273
|
+
children: /*#__PURE__*/_jsxs(Sheet, _objectSpread(_objectSpread({}, args), {}, {
|
|
274
|
+
sheetInstance: sheetInstance,
|
|
275
|
+
sheetRenderer: WrappedTableShell,
|
|
276
|
+
groupConfig: rowGroupConfig,
|
|
277
|
+
data: data,
|
|
278
|
+
onCellsChanged: handleChanges,
|
|
279
|
+
children: [/*#__PURE__*/_jsx(SelectionEvent, {
|
|
280
|
+
hasChildren: hasChildren,
|
|
281
|
+
rowSelection: rowSelection,
|
|
282
|
+
onChange: handleRowSelect
|
|
283
|
+
}), /*#__PURE__*/_jsx(GroupEvent, {
|
|
284
|
+
hasChildren: hasChildren,
|
|
285
|
+
data: data,
|
|
286
|
+
rowGroupConfig: rowGroupConfig,
|
|
287
|
+
sheetInstance: sheetInstance.current,
|
|
288
|
+
onGridChange: setData,
|
|
289
|
+
onGroupChange: setGroupConfig
|
|
290
|
+
}), /*#__PURE__*/_jsx(SheetEvent, {
|
|
291
|
+
name: "reverse",
|
|
292
|
+
handler: handleReverse
|
|
293
|
+
}, "_reverse"), Object.keys(eventHandler || {}).map(function (key) {
|
|
294
|
+
return /*#__PURE__*/_jsx(SheetEvent, {
|
|
295
|
+
name: key,
|
|
296
|
+
handler: eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler[key]
|
|
297
|
+
}, key);
|
|
298
|
+
}), handleAdd ? /*#__PURE__*/_jsx(Button, {
|
|
299
|
+
type: "dashed",
|
|
300
|
+
style: {
|
|
301
|
+
width: '100%',
|
|
302
|
+
height: 32
|
|
303
|
+
},
|
|
304
|
+
onClick: handleAdd,
|
|
305
|
+
children: "+ \u6DFB\u52A0"
|
|
306
|
+
}) : null]
|
|
307
|
+
}))
|
|
308
|
+
});
|
|
329
309
|
};
|
|
330
|
-
export default Table;
|
|
331
|
-
//# sourceMappingURL=index.js.map
|
|
310
|
+
export default Table;
|
|
@@ -4,7 +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(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import { useEffect, useRef, useState } from 'react';
|
|
7
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
|
|
8
8
|
import { dataSourceToRowConfig } from "./util";
|
|
9
9
|
export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig, hasChildren) {
|
|
10
10
|
var _useState = useState(),
|
|
@@ -12,13 +12,26 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
|
|
|
12
12
|
groupConfig = _useState2[0],
|
|
13
13
|
setGroupConfig = _useState2[1];
|
|
14
14
|
var groupConfigRef = useRef();
|
|
15
|
+
var childrenLength = useMemo(function () {
|
|
16
|
+
if (!(dataSource !== null && dataSource !== void 0 && dataSource.length)) return 0;
|
|
17
|
+
var data = dataSource;
|
|
18
|
+
var childrenCount = data.filter(function (item) {
|
|
19
|
+
var _item$children;
|
|
20
|
+
return !!((_item$children = item.children) !== null && _item$children !== void 0 && _item$children.length);
|
|
21
|
+
}).reduce(function (count, _ref) {
|
|
22
|
+
var children = _ref.children;
|
|
23
|
+
return count + (children === null || children === void 0 ? void 0 : children.length) ? children.length : 0;
|
|
24
|
+
}, 0);
|
|
25
|
+
return childrenCount;
|
|
26
|
+
}, [dataSource]);
|
|
15
27
|
useEffect(function () {
|
|
16
28
|
if (!hasChildren) return;
|
|
29
|
+
console.log('groupConfigEffect', dataSource.length);
|
|
17
30
|
var rowConfig = dataSourceToRowConfig(dataSource, tableGroupConfig === null || tableGroupConfig === void 0 ? void 0 : tableGroupConfig.defaultOpen);
|
|
18
31
|
if (groupConfigRef.current) {
|
|
19
|
-
groupConfigRef.current.groups.forEach(function (
|
|
32
|
+
groupConfigRef.current.groups.forEach(function (_ref2, index) {
|
|
20
33
|
var _groupConfigRef$curre;
|
|
21
|
-
var groupName =
|
|
34
|
+
var groupName = _ref2.groupName;
|
|
22
35
|
var rowIndex = rowConfig.groups.findIndex(function (item) {
|
|
23
36
|
return item.groupName === groupName;
|
|
24
37
|
});
|
|
@@ -26,8 +39,12 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
|
|
|
26
39
|
});
|
|
27
40
|
}
|
|
28
41
|
setGroupConfig(rowConfig);
|
|
42
|
+
console.log('groupConfigEffect', rowConfig.groups, rowConfig.groupOpen);
|
|
29
43
|
groupConfigRef.current = rowConfig;
|
|
30
|
-
}, [dataSource, hasChildren]);
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
44
|
+
}, [dataSource.length, childrenLength, hasChildren]);
|
|
45
|
+
var handleGroupChange = useCallback(function (value) {
|
|
46
|
+
setGroupConfig(value);
|
|
47
|
+
groupConfigRef.current = value;
|
|
48
|
+
}, [setGroupConfig]);
|
|
49
|
+
return [groupConfig, handleGroupChange];
|
|
50
|
+
};
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
|
|
1
|
+
import { SheetTableType } from "../..";
|
|
2
|
+
export declare const useRowSelection: (dataSource: Record<string, unknown>[], rowSelection?: SheetTableType.TableRowSelection, hasChildren?: boolean) => [boolean[], (value: boolean[]) => void];
|
|
@@ -21,5 +21,4 @@ export var useRowSelection = function useRowSelection(dataSource, rowSelection,
|
|
|
21
21
|
checkedRowRef.current = currentEmpty;
|
|
22
22
|
}, [dataSource.length, hasChildren, rowSelection]);
|
|
23
23
|
return [checkedRow, setCheckedRow];
|
|
24
|
-
};
|
|
25
|
-
//# sourceMappingURL=useRowSelection.js.map
|
|
24
|
+
};
|
package/dist/core/table/util.js
CHANGED
|
@@ -13,7 +13,7 @@ export var dataSourceToRowConfig = function dataSourceToRowConfig(dataSource) {
|
|
|
13
13
|
if ((children === null || children === void 0 ? void 0 : children.length) > 0) {
|
|
14
14
|
groups.push({
|
|
15
15
|
groupStart: currentIndex,
|
|
16
|
-
groupEnd: currentIndex + children.length
|
|
16
|
+
groupEnd: currentIndex + children.length,
|
|
17
17
|
// 默认 key 或者 id 是行数据的唯一标识
|
|
18
18
|
groupName: "".concat(item.key || item.id || index, "group")
|
|
19
19
|
});
|
|
@@ -26,5 +26,4 @@ export var dataSourceToRowConfig = function dataSourceToRowConfig(dataSource) {
|
|
|
26
26
|
groups: groups,
|
|
27
27
|
groupOpen: groupOpen
|
|
28
28
|
};
|
|
29
|
-
};
|
|
30
|
-
//# sourceMappingURL=util.js.map
|
|
29
|
+
};
|
package/dist/core/util.d.ts
CHANGED
|
@@ -29,7 +29,10 @@ export declare function formatDataToCell({ start, editing, end, data, pasteData,
|
|
|
29
29
|
} | undefined;
|
|
30
30
|
export declare const defaultValueRenderer: (cell: SheetType.Cell) => string | number | null | undefined;
|
|
31
31
|
export declare function renderValue(cell: SheetType.Cell): string | number;
|
|
32
|
-
export declare const
|
|
32
|
+
export declare const optionsToValuesFromLabelOrValue: (options: SheetType.OptionsType[], val: string) => string[];
|
|
33
|
+
export declare const optionsTransferToValue: (options: SheetType.OptionsType[], val: string, key?: string) => string[];
|
|
34
|
+
export declare const optionsTransferToValue2: (options?: SheetType.OptionsType[], value?: string, path?: string[]) => string[];
|
|
35
|
+
export declare const valuesTransferToLabel: (options?: SheetType.OptionsType[], value?: string) => string | null;
|
|
33
36
|
export declare const groupConfigToGroupMap: (rowGroupConfig?: SheetType.RowGroupConfig) => Map<number, SheetType.RowGroup & {
|
|
34
37
|
isStart: boolean;
|
|
35
38
|
isOpen: boolean;
|
|
@@ -43,7 +46,7 @@ export declare const getRowHeight: (container: HTMLSpanElement) => number;
|
|
|
43
46
|
export declare const getNextVisibleRow: (row: number, maxRow: number, groupMap?: Map<number, SheetType.RowGroup & {
|
|
44
47
|
isStart: boolean;
|
|
45
48
|
isOpen: boolean;
|
|
46
|
-
}
|
|
49
|
+
}>, up?: number) => number | null;
|
|
47
50
|
export declare const calcMenuPosition: ({ tableElement, menuElement, x, y, }: {
|
|
48
51
|
tableElement: SheetType.refAssertion | null;
|
|
49
52
|
menuElement?: Element | null | undefined;
|