@zhenliang/sheet 0.1.6 → 0.1.7-3.beta.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/dist/assets/arrow-mac-down.svg +19 -0
- package/dist/assets/arrow-mac-right.svg +17 -0
- package/dist/assets/arrow-windows-down.svg +17 -0
- package/dist/assets/arrow-windows-right.svg +17 -0
- package/dist/core/config.d.ts +3 -0
- package/dist/core/config.js +4 -1
- package/dist/core/editor/cascaderEditor/index.d.ts +1 -1
- package/dist/core/editor/cascaderEditor/index.js +12 -11
- package/dist/core/editor/cascaderEditor/index.less +15 -7
- package/dist/core/editor/dateEditor/index.js +31 -8
- package/dist/core/editor/dateEditor/index.less +9 -2
- package/dist/core/editor/numberEditor/index.d.ts +3 -1
- package/dist/core/editor/numberEditor/index.js +62 -27
- package/dist/core/editor/numberEditor/index.less +3 -2
- package/dist/core/editor/selectEditor/index.d.ts +1 -1
- package/dist/core/editor/selectEditor/index.js +34 -19
- package/dist/core/editor/selectEditor/index.less +16 -5
- package/dist/core/reducers/index.d.ts +2 -2
- package/dist/core/reducers/index.js +8 -1
- package/dist/core/reducers/keyboardReducer.js +39 -9
- package/dist/core/reducers/mouseReducer.js +115 -11
- package/dist/core/reducers/sideEffectReducer.d.ts +1 -1
- package/dist/core/reducers/sideEffectReducer.js +146 -41
- package/dist/core/reducers/stateReducer.d.ts +1 -0
- package/dist/core/reducers/stateReducer.js +96 -27
- package/dist/core/sheet/Cell.d.ts +1 -1
- package/dist/core/sheet/Cell.js +33 -24
- package/dist/core/sheet/Control.d.ts +21 -0
- package/dist/core/sheet/Control.js +83 -0
- package/dist/core/sheet/DataEditor.js +3 -3
- package/dist/core/sheet/DefaultCell.d.ts +8 -3
- package/dist/core/sheet/DefaultCell.js +12 -8
- package/dist/core/sheet/DefaultRow.js +3 -9
- package/dist/core/sheet/DefaultRowMapper.d.ts +3 -0
- package/dist/core/sheet/DefaultRowMapper.js +22 -6
- package/dist/core/sheet/DefaultShell.js +1 -1
- package/dist/core/sheet/Event.d.ts +1 -1
- package/dist/core/sheet/Event.js +1 -1
- package/dist/core/sheet/Menu.d.ts +6 -0
- package/dist/core/sheet/Menu.js +21 -0
- package/dist/core/sheet/ValueViewer.js +1 -1
- package/dist/core/sheet/index.js +249 -88
- package/dist/core/sheet/index.less +199 -107
- package/dist/core/sheet/searchInput.d.ts +15 -0
- package/dist/core/sheet/searchInput.js +78 -0
- package/dist/core/sheet/useCellEvent.js +1 -1
- package/dist/core/sheet/useContextMenu.d.ts +1 -1
- package/dist/core/sheet/useContextMenu.js +13 -10
- package/dist/core/sheet/useKeyBoardEvent.js +19 -2
- package/dist/core/sheet/useMouseEvent.js +19 -12
- package/dist/core/sheet/useSearchInput.d.ts +11 -0
- package/dist/core/sheet/useSearchInput.js +65 -0
- package/dist/core/sheet/useSelectVisible.d.ts +1 -1
- package/dist/core/sheet/useSelectVisible.js +17 -7
- package/dist/core/sheet/useVirtualList.d.ts +10 -1
- package/dist/core/sheet/useVirtualList.js +44 -28
- package/dist/core/sheet/var.less +41 -34
- package/dist/core/shell/draggableShell/index.d.ts +4 -1
- package/dist/core/shell/draggableShell/index.js +133 -50
- package/dist/core/shell/tableShell.d.ts +4 -1
- package/dist/core/shell/tableShell.js +82 -34
- package/dist/core/table/addButton.d.ts +6 -0
- package/dist/core/table/addButton.js +103 -0
- package/dist/core/table/events.d.ts +1 -3
- package/dist/core/table/events.js +28 -34
- package/dist/core/table/index.js +97 -190
- package/dist/core/table/index.less +12 -0
- package/dist/core/table/useGroupConfig.d.ts +4 -1
- package/dist/core/table/useGroupConfig.js +139 -14
- package/dist/core/table/useRowSelection.d.ts +3 -0
- package/dist/core/table/useRowSelection.js +68 -2
- package/dist/core/util.d.ts +10 -4
- package/dist/core/util.js +121 -69
- package/dist/core/viewer/btnViewer/index.js +3 -3
- package/dist/core/viewer/cascaderViewer/index.js +6 -1
- package/dist/core/viewer/checkViewer/index.js +2 -2
- package/dist/core/viewer/editViewer/index.js +3 -3
- package/dist/core/viewer/groupViewer/index.js +26 -10
- package/dist/core/viewer/selectorViewer/index.js +7 -3
- package/dist/core/viewer/switchViewer/index.js +10 -4
- package/dist/example/antComponent.d.ts +1 -1
- package/dist/example/antComponent.js +63 -37
- package/dist/example/basic.d.ts +1 -1
- package/dist/example/basic.js +20 -14
- package/dist/example/ellipsis.d.ts +1 -1
- package/dist/example/ellipsis.js +3 -2
- package/dist/example/fixed.d.ts +1 -1
- package/dist/example/fixed.js +3 -2
- package/dist/example/group.js +40 -17
- package/dist/example/selection.d.ts +1 -1
- package/dist/example/selection.js +9 -8
- package/dist/example/sheet.d.ts +1 -1
- package/dist/example/sheet.js +21 -22
- package/dist/example/valuationAnalyze.d.ts +1 -0
- package/dist/example/valuationAnalyze.js +3 -4
- package/dist/hooks/index.d.ts +1 -1
- package/dist/hooks/index.js +1 -1
- package/dist/hooks/useEventBus.d.ts +1 -0
- package/dist/hooks/useEventBus.js +2 -2
- package/dist/hooks/useGroupConfig.d.ts +4 -0
- package/dist/hooks/useGroupConfig.js +5 -0
- package/dist/hooks/useKeyboard.d.ts +5 -2
- package/dist/hooks/useKeyboard.js +17 -3
- package/dist/hooks/useMiddlewareReducer.d.ts +5 -5
- package/dist/hooks/useMiddlewareReducer.js +3 -3
- package/dist/hooks/useMouse.d.ts +1 -1
- package/dist/hooks/useMouse.js +7 -7
- package/dist/hooks/useSetState.js +7 -7
- package/dist/hooks/useSheetEvent.d.ts +1 -1
- package/dist/hooks/useSheetEvent.js +2 -2
- package/dist/hooks/useWidthConfig.d.ts +3 -3
- package/dist/hooks/useWidthConfig.js +2 -2
- package/dist/standardUtils/index.d.ts +1 -1
- package/dist/standardUtils/index.js +1 -1
- package/dist/type/sheet.d.ts +76 -31
- package/dist/type/sheetTable.d.ts +21 -12
- package/package.json +7 -4
|
@@ -1,19 +1,21 @@
|
|
|
1
|
-
function _typeof(
|
|
2
|
-
function ownKeys(
|
|
3
|
-
function _objectSpread(
|
|
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 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; }
|
|
3
|
+
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; }
|
|
4
4
|
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; }
|
|
5
|
-
function _toPropertyKey(
|
|
6
|
-
function _toPrimitive(
|
|
5
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
6
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
7
7
|
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
8
8
|
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."); }
|
|
9
9
|
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); }
|
|
10
10
|
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
11
11
|
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
12
12
|
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; }
|
|
13
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
14
|
+
import { useGroup } from "../../hooks/useGroupConfig";
|
|
13
15
|
import { SheetEvent } from "../sheet/Event";
|
|
14
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
15
|
-
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
16
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
16
|
+
import { jsx as _jsx } from "../../../node_modules/@types/react/jsx-runtime";
|
|
17
|
+
import { Fragment as _Fragment } from "../../../node_modules/@types/react/jsx-runtime";
|
|
18
|
+
import { jsxs as _jsxs } from "../../../node_modules/@types/react/jsx-runtime";
|
|
17
19
|
export var SelectionEvent = function SelectionEvent(props) {
|
|
18
20
|
var hasChildren = props.hasChildren,
|
|
19
21
|
rowSelection = props.rowSelection,
|
|
@@ -31,44 +33,34 @@ export var SelectionEvent = function SelectionEvent(props) {
|
|
|
31
33
|
};
|
|
32
34
|
export var GroupEvent = function GroupEvent(props) {
|
|
33
35
|
var hasChildren = props.hasChildren,
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
36
|
+
sheetInstance = props.sheetInstance;
|
|
37
|
+
var _useGroup = useGroup(),
|
|
38
|
+
_useGroup$config = _useGroup.config,
|
|
39
|
+
rowGroupConfig = _useGroup$config === void 0 ? {} : _useGroup$config,
|
|
40
|
+
onGroupChange = _useGroup.onChange;
|
|
39
41
|
if (!hasChildren) return null;
|
|
40
|
-
var
|
|
41
|
-
groups = _ref.groups;
|
|
42
|
+
var groups = rowGroupConfig.groups;
|
|
42
43
|
return /*#__PURE__*/_jsxs(_Fragment, {
|
|
43
44
|
children: [/*#__PURE__*/_jsx(SheetEvent, {
|
|
44
45
|
name: "group-open",
|
|
45
46
|
handler: function handler(e) {
|
|
46
|
-
var
|
|
47
|
-
row =
|
|
48
|
-
var index = groups.findIndex(function (item) {
|
|
47
|
+
var _ref = e,
|
|
48
|
+
row = _ref.row;
|
|
49
|
+
var index = groups === null || groups === void 0 ? void 0 : groups.findIndex(function (item) {
|
|
49
50
|
return item.groupStart === row;
|
|
50
51
|
});
|
|
51
52
|
if (index >= 0) {
|
|
52
|
-
var groupOpen = _toConsumableArray(rowGroupConfig.groupOpen);
|
|
53
|
-
groupOpen[index] = !rowGroupConfig.groupOpen[index];
|
|
53
|
+
var groupOpen = _toConsumableArray(rowGroupConfig === null || rowGroupConfig === void 0 ? void 0 : rowGroupConfig.groupOpen);
|
|
54
|
+
groupOpen[index] = !(rowGroupConfig !== null && rowGroupConfig !== void 0 && rowGroupConfig.groupOpen[index]);
|
|
54
55
|
onGroupChange && onGroupChange(_objectSpread(_objectSpread({}, rowGroupConfig), {}, {
|
|
55
56
|
groupOpen: groupOpen
|
|
56
57
|
}));
|
|
57
|
-
|
|
58
|
-
newGrid[row] = _toConsumableArray(newGrid[row]);
|
|
59
|
-
newGrid[row][0] = _objectSpread(_objectSpread({}, newGrid[row][0]), {}, {
|
|
60
|
-
record: {
|
|
61
|
-
open: !!groupOpen[index]
|
|
62
|
-
}
|
|
63
|
-
});
|
|
64
|
-
onGridChange && onGridChange(newGrid);
|
|
65
|
-
sheetInstance === null || sheetInstance === void 0 ? void 0 : sheetInstance.pushToHistory({
|
|
58
|
+
sheetInstance === null || sheetInstance === void 0 || sheetInstance.pushToHistory({
|
|
66
59
|
type: 'Custom',
|
|
67
60
|
changes: [],
|
|
68
61
|
extraInfo: {
|
|
69
62
|
extraType: 'group',
|
|
70
|
-
groupConfig: rowGroupConfig
|
|
71
|
-
data: data
|
|
63
|
+
groupConfig: rowGroupConfig
|
|
72
64
|
}
|
|
73
65
|
});
|
|
74
66
|
}
|
|
@@ -76,17 +68,19 @@ export var GroupEvent = function GroupEvent(props) {
|
|
|
76
68
|
}, "group-open"), /*#__PURE__*/_jsx(SheetEvent, {
|
|
77
69
|
name: "group-open-title",
|
|
78
70
|
handler: function handler(value) {
|
|
71
|
+
if (!(rowGroupConfig !== null && rowGroupConfig !== void 0 && rowGroupConfig.groupOpen.some(function (item) {
|
|
72
|
+
return item !== value;
|
|
73
|
+
}))) return;
|
|
79
74
|
onGroupChange && onGroupChange(_objectSpread(_objectSpread({}, rowGroupConfig), {}, {
|
|
80
75
|
groupOpen: Array(rowGroupConfig === null || rowGroupConfig === void 0 ? void 0 : rowGroupConfig.groupOpen.length).fill(value),
|
|
81
76
|
defaultOpen: !groups.length ? value : undefined
|
|
82
77
|
}));
|
|
83
|
-
sheetInstance === null || sheetInstance === void 0
|
|
78
|
+
sheetInstance === null || sheetInstance === void 0 || sheetInstance.pushToHistory({
|
|
84
79
|
type: 'Custom',
|
|
85
80
|
changes: [],
|
|
86
81
|
extraInfo: {
|
|
87
82
|
extraType: 'group',
|
|
88
|
-
groupConfig: rowGroupConfig
|
|
89
|
-
data: data
|
|
83
|
+
groupConfig: rowGroupConfig
|
|
90
84
|
}
|
|
91
85
|
});
|
|
92
86
|
}
|
package/dist/core/table/index.js
CHANGED
|
@@ -1,39 +1,33 @@
|
|
|
1
|
-
function _typeof(
|
|
2
|
-
var _excluded = ["sheetInstance", "columns", "dataSource", "rowKey", "rowSelection", "groupConfig", "onChange", "handleAdd", "draggable", "eventHandler"];
|
|
3
|
-
function
|
|
4
|
-
function
|
|
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
|
-
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; }
|
|
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; }
|
|
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
|
+
var _excluded = ["sheetInstance", "columns", "dataSource", "rowKey", "rowSelection", "groupConfig", "onChange", "handleAdd", "handleBatchAdd", "draggable", "eventHandler"];
|
|
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; }
|
|
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; }
|
|
10
|
-
function _toPropertyKey(
|
|
11
|
-
function _toPrimitive(
|
|
6
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
|
7
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
|
12
8
|
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
13
9
|
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
10
|
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); }
|
|
15
11
|
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; }
|
|
16
|
-
function _iterableToArrayLimit(
|
|
12
|
+
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; } }
|
|
17
13
|
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
|
-
import {
|
|
23
|
-
import { useCallback, useEffect, useMemo, useRef, useState } from
|
|
19
|
+
import { ConfigProvider, Empty } from 'antd';
|
|
20
|
+
import { useCallback, useEffect, useMemo, useRef, useState } from "../../../node_modules/@types/react";
|
|
24
21
|
import { SheetEvent } from "../sheet/Event";
|
|
25
22
|
import { DraggableShell } from "../shell/draggableShell";
|
|
26
23
|
import { TableShell } from "../shell/tableShell";
|
|
27
|
-
import {
|
|
28
|
-
import { CheckViewer } from "../viewer/checkViewer";
|
|
29
|
-
import { GroupViewer } from "../viewer/groupViewer";
|
|
24
|
+
import { AddButton } from "./addButton";
|
|
30
25
|
import { GroupEvent, SelectionEvent } from "./events";
|
|
31
|
-
import { useGroupConfig } from "./useGroupConfig";
|
|
32
|
-
import { useRowSelection } from "./useRowSelection";
|
|
33
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
34
|
-
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
26
|
+
import { formatGroupData, useGroupConfig } from "./useGroupConfig";
|
|
27
|
+
import { formatSelectionData, useRowSelection } from "./useRowSelection";
|
|
28
|
+
import { jsx as _jsx } from "../../../node_modules/@types/react/jsx-runtime";
|
|
29
|
+
import { jsxs as _jsxs } from "../../../node_modules/@types/react/jsx-runtime";
|
|
35
30
|
var Table = function Table(_ref) {
|
|
36
|
-
var _rowGroupConfig$group, _rowGroupConfig$group2;
|
|
37
31
|
var sheetRef = _ref.sheetInstance,
|
|
38
32
|
columns = _ref.columns,
|
|
39
33
|
dataSource = _ref.dataSource,
|
|
@@ -42,6 +36,7 @@ var Table = function Table(_ref) {
|
|
|
42
36
|
groupConfig = _ref.groupConfig,
|
|
43
37
|
onChange = _ref.onChange,
|
|
44
38
|
handleAdd = _ref.handleAdd,
|
|
39
|
+
handleBatchAdd = _ref.handleBatchAdd,
|
|
45
40
|
draggable = _ref.draggable,
|
|
46
41
|
eventHandler = _ref.eventHandler,
|
|
47
42
|
args = _objectWithoutProperties(_ref, _excluded);
|
|
@@ -55,11 +50,14 @@ var Table = function Table(_ref) {
|
|
|
55
50
|
widths = _useSetState2[0],
|
|
56
51
|
setWidth = _useSetState2[1];
|
|
57
52
|
var sheetInstance = sheetRef || _sheetInstance;
|
|
58
|
-
var
|
|
53
|
+
var dataHasChildren = dataSource === null || dataSource === void 0 ? void 0 : dataSource.some(function (item) {
|
|
59
54
|
var _item$children;
|
|
60
|
-
return (item === null || item === void 0
|
|
61
|
-
})
|
|
55
|
+
return (item === null || item === void 0 || (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) > 0;
|
|
56
|
+
});
|
|
57
|
+
var configWithChildren = !!groupConfig && !!dataSource.length;
|
|
58
|
+
var hasChildren = dataHasChildren || configWithChildren;
|
|
62
59
|
var hasControl = hasChildren || !!rowSelection;
|
|
60
|
+
var offset = hasControl ? 2 : 1;
|
|
63
61
|
var _useRowSelection = useRowSelection(dataSource, rowSelection, hasChildren),
|
|
64
62
|
_useRowSelection2 = _slicedToArray(_useRowSelection, 2),
|
|
65
63
|
checkedRow = _useRowSelection2[0],
|
|
@@ -70,119 +68,26 @@ var Table = function Table(_ref) {
|
|
|
70
68
|
_useGroupConfig2 = _slicedToArray(_useGroupConfig, 2),
|
|
71
69
|
rowGroupConfig = _useGroupConfig2[0],
|
|
72
70
|
setGroupConfig = _useGroupConfig2[1];
|
|
73
|
-
var _ref2 = rowGroupConfig || {},
|
|
74
|
-
groups = _ref2.groups,
|
|
75
|
-
groupOpen = _ref2.groupOpen;
|
|
76
71
|
useEffect(function () {
|
|
77
72
|
if (!hasChildren) return;
|
|
78
73
|
if (!dataSource || !columns) return;
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
dataSource.forEach(function (item, row) {
|
|
86
|
-
var groupList = [item];
|
|
87
|
-
if (item.children) {
|
|
88
|
-
groupList = [item].concat(_toConsumableArray(item.children));
|
|
89
|
-
}
|
|
90
|
-
groupList.forEach(function (itemRow) {
|
|
91
|
-
var _columns$, _columns$2, _columns$3, _columns$4, _groupMap$get, _groupMap$get2;
|
|
92
|
-
var dataRow = [];
|
|
93
|
-
var rowId = itemRow.id || itemRow.key || String(currentIndex);
|
|
94
|
-
if (rowKey) {
|
|
95
|
-
if (rowKey instanceof Function) {
|
|
96
|
-
rowId = rowKey(itemRow, row);
|
|
97
|
-
} else {
|
|
98
|
-
rowId = itemRow[rowKey];
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
dataRow.push({
|
|
102
|
-
id: rowId,
|
|
103
|
-
row: currentIndex,
|
|
104
|
-
col: -1,
|
|
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),
|
|
107
|
-
align: 'center',
|
|
108
|
-
fixed: 'unset',
|
|
109
|
-
value: groupMap.get(currentIndex) && ((_groupMap$get = groupMap.get(currentIndex)) === null || _groupMap$get === void 0 ? void 0 : _groupMap$get.isStart),
|
|
110
|
-
record: {
|
|
111
|
-
open: groupMap.get(currentIndex) && ((_groupMap$get2 = groupMap.get(currentIndex)) === null || _groupMap$get2 === void 0 ? void 0 : _groupMap$get2.isOpen)
|
|
112
|
-
},
|
|
113
|
-
valueViewer: GroupViewer,
|
|
114
|
-
className: 'sheet-control'
|
|
115
|
-
});
|
|
116
|
-
columns.forEach(function (colInfo, col) {
|
|
117
|
-
var _colInfo$cellConfig, _colInfo$cellConfig2, _colInfo$cellConfig3;
|
|
118
|
-
var value = itemRow[colInfo.dataIndex || ''];
|
|
119
|
-
dataRow.push({
|
|
120
|
-
id: rowId,
|
|
121
|
-
value: value,
|
|
122
|
-
record: itemRow,
|
|
123
|
-
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, itemRow, currentIndex),
|
|
124
|
-
align: colInfo.align,
|
|
125
|
-
fixed: colInfo.fixed,
|
|
126
|
-
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, itemRow, currentIndex),
|
|
127
|
-
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
128
|
-
dataEditor: colInfo.editor ? colInfo.editor : undefined,
|
|
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),
|
|
131
|
-
col: col
|
|
132
|
-
});
|
|
133
|
-
});
|
|
134
|
-
data.push(dataRow);
|
|
135
|
-
currentIndex++;
|
|
136
|
-
});
|
|
137
|
-
});
|
|
138
|
-
setData(data);
|
|
139
|
-
}, [dataSource, columns, groups, hasChildren, rowGroupConfig]);
|
|
74
|
+
setData(formatGroupData({
|
|
75
|
+
dataSource: dataSource,
|
|
76
|
+
columns: columns,
|
|
77
|
+
rowKey: rowKey
|
|
78
|
+
}));
|
|
79
|
+
}, [dataSource, columns, hasChildren, rowKey]);
|
|
140
80
|
useEffect(function () {
|
|
141
81
|
if (hasChildren) return;
|
|
142
82
|
if (!dataSource || !columns) return;
|
|
143
|
-
setData(
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
rowId = item[rowKey];
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
var rows = [];
|
|
153
|
-
if (rowSelection) {
|
|
154
|
-
rows.push({
|
|
155
|
-
id: rowId,
|
|
156
|
-
row: row,
|
|
157
|
-
col: -1,
|
|
158
|
-
readonly: true,
|
|
159
|
-
align: 'center',
|
|
160
|
-
value: checkedRow[row],
|
|
161
|
-
valueViewer: CheckViewer,
|
|
162
|
-
className: 'sheet-control'
|
|
163
|
-
});
|
|
164
|
-
}
|
|
165
|
-
columns.forEach(function (colInfo, col) {
|
|
166
|
-
var _colInfo$cellConfig4, _colInfo$cellConfig5, _colInfo$cellConfig6;
|
|
167
|
-
var value = item[colInfo.dataIndex || ''];
|
|
168
|
-
rows.push({
|
|
169
|
-
id: rowId,
|
|
170
|
-
value: value,
|
|
171
|
-
record: item,
|
|
172
|
-
readonly: !(colInfo.readonly instanceof Function) ? colInfo.readonly : colInfo.readonly(value, item, row),
|
|
173
|
-
align: colInfo.align,
|
|
174
|
-
fixed: colInfo.fixed,
|
|
175
|
-
editable: !(colInfo.editable instanceof Function) ? colInfo.editable : colInfo.editable(value, item, row),
|
|
176
|
-
valueViewer: colInfo.render ? colInfo.render : undefined,
|
|
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),
|
|
179
|
-
row: row,
|
|
180
|
-
col: col
|
|
181
|
-
});
|
|
182
|
-
});
|
|
183
|
-
return rows;
|
|
83
|
+
setData(formatSelectionData({
|
|
84
|
+
dataSource: dataSource,
|
|
85
|
+
columns: columns,
|
|
86
|
+
checked: checkedRow,
|
|
87
|
+
rowKey: rowKey,
|
|
88
|
+
rowSelection: rowSelection
|
|
184
89
|
}));
|
|
185
|
-
}, [dataSource, columns, checkedRow, hasChildren]);
|
|
90
|
+
}, [dataSource, columns, checkedRow, hasChildren, rowKey, rowSelection]);
|
|
186
91
|
useEffect(function () {
|
|
187
92
|
if (!dataSource || !columns) {
|
|
188
93
|
setData([[]]);
|
|
@@ -191,32 +96,32 @@ var Table = function Table(_ref) {
|
|
|
191
96
|
var handleChanges = useCallback(function (changes, extChange) {
|
|
192
97
|
onChange && onChange(changes.map(function (item) {
|
|
193
98
|
return {
|
|
99
|
+
col: item.col,
|
|
194
100
|
row: item.row,
|
|
195
101
|
id: item.id,
|
|
196
|
-
key: columns[
|
|
102
|
+
key: item.key || columns[item.col - offset].dataIndex,
|
|
197
103
|
value: item.value
|
|
198
104
|
};
|
|
199
105
|
}), extChange === null || extChange === void 0 ? void 0 : extChange.map(function (item) {
|
|
200
106
|
return {
|
|
107
|
+
col: item.col,
|
|
201
108
|
row: item.row,
|
|
202
109
|
id: item.id,
|
|
203
|
-
key: columns[
|
|
110
|
+
key: item.key || columns[item.col - offset].dataIndex,
|
|
204
111
|
value: item.value
|
|
205
112
|
};
|
|
206
113
|
}));
|
|
207
114
|
}, [columns, onChange, hasControl]);
|
|
208
115
|
var handleReverse = useCallback(function (value) {
|
|
209
|
-
var
|
|
210
|
-
type =
|
|
211
|
-
extraInfo =
|
|
116
|
+
var _ref2 = value,
|
|
117
|
+
type = _ref2.type,
|
|
118
|
+
extraInfo = _ref2.extraInfo;
|
|
212
119
|
if (type === 'Custom') {
|
|
213
|
-
var
|
|
214
|
-
_groupConfig =
|
|
215
|
-
extraType =
|
|
216
|
-
lastData = _ref4.data;
|
|
120
|
+
var _ref3 = extraInfo,
|
|
121
|
+
_groupConfig = _ref3.groupConfig,
|
|
122
|
+
extraType = _ref3.extraType;
|
|
217
123
|
if (extraType === 'group') {
|
|
218
124
|
setGroupConfig(_groupConfig);
|
|
219
|
-
setData(lastData);
|
|
220
125
|
}
|
|
221
126
|
}
|
|
222
127
|
}, [data, groupConfig]);
|
|
@@ -228,13 +133,15 @@ var Table = function Table(_ref) {
|
|
|
228
133
|
newChecked[currentRow] = !newChecked[currentRow];
|
|
229
134
|
setCheckedRow(newChecked);
|
|
230
135
|
}, [sheetInstance, checkedRow]);
|
|
231
|
-
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) {
|
|
232
|
-
return !value;
|
|
233
|
-
}));
|
|
234
136
|
var headSelection = !!rowSelection;
|
|
235
|
-
|
|
137
|
+
var columnsTitle = useMemo(function () {
|
|
138
|
+
return columns.filter(function (item) {
|
|
139
|
+
return typeof item.title === 'string';
|
|
140
|
+
}).map(function (item) {
|
|
141
|
+
return item.title;
|
|
142
|
+
}).join('_');
|
|
143
|
+
}, [columns]);
|
|
236
144
|
var WrappedTableShell = useMemo(function () {
|
|
237
|
-
console.log('shell-render', '损耗性能大');
|
|
238
145
|
if (draggable) {
|
|
239
146
|
return DraggableShell({
|
|
240
147
|
columns: columns,
|
|
@@ -242,9 +149,6 @@ var Table = function Table(_ref) {
|
|
|
242
149
|
showGroup: hasChildren,
|
|
243
150
|
showSelect: !!rowSelection,
|
|
244
151
|
controlProps: {
|
|
245
|
-
group: {
|
|
246
|
-
open: headGroupOpen
|
|
247
|
-
},
|
|
248
152
|
check: {
|
|
249
153
|
checked: false
|
|
250
154
|
}
|
|
@@ -257,55 +161,58 @@ var Table = function Table(_ref) {
|
|
|
257
161
|
showGroup: hasChildren,
|
|
258
162
|
showSelect: !!rowSelection,
|
|
259
163
|
controlProps: {
|
|
260
|
-
group: {
|
|
261
|
-
open: headGroupOpen
|
|
262
|
-
},
|
|
263
164
|
check: {
|
|
264
165
|
checked: false
|
|
265
166
|
}
|
|
266
167
|
}
|
|
267
168
|
});
|
|
268
|
-
}, [columns.length, draggable, headSelection, hasChildren
|
|
269
|
-
return /*#__PURE__*/_jsx(
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
169
|
+
}, [columns.length, columnsTitle, draggable, headSelection, hasChildren]);
|
|
170
|
+
return /*#__PURE__*/_jsx(ConfigProvider, {
|
|
171
|
+
renderEmpty: function renderEmpty() {
|
|
172
|
+
return /*#__PURE__*/_jsx(Empty, {
|
|
173
|
+
image: Empty.PRESENTED_IMAGE_SIMPLE
|
|
174
|
+
});
|
|
273
175
|
},
|
|
274
|
-
children: /*#__PURE__*/
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
onChange: handleRowSelect
|
|
284
|
-
}), /*#__PURE__*/_jsx(GroupEvent, {
|
|
285
|
-
hasChildren: hasChildren,
|
|
286
|
-
data: data,
|
|
287
|
-
rowGroupConfig: rowGroupConfig,
|
|
288
|
-
sheetInstance: sheetInstance.current,
|
|
289
|
-
onGridChange: setData,
|
|
290
|
-
onGroupChange: setGroupConfig
|
|
291
|
-
}), /*#__PURE__*/_jsx(SheetEvent, {
|
|
292
|
-
name: "reverse",
|
|
293
|
-
handler: handleReverse
|
|
294
|
-
}, "_reverse"), Object.keys(eventHandler || {}).map(function (key) {
|
|
295
|
-
return /*#__PURE__*/_jsx(SheetEvent, {
|
|
296
|
-
name: key,
|
|
297
|
-
handler: eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler[key]
|
|
298
|
-
}, key);
|
|
299
|
-
}), handleAdd ? /*#__PURE__*/_jsx(Button, {
|
|
300
|
-
type: "dashed",
|
|
301
|
-
style: {
|
|
302
|
-
width: '100%',
|
|
303
|
-
height: 32
|
|
176
|
+
children: /*#__PURE__*/_jsx(WidthContext.Provider, {
|
|
177
|
+
value: {
|
|
178
|
+
widths: widths,
|
|
179
|
+
onChange: setWidth
|
|
180
|
+
},
|
|
181
|
+
children: /*#__PURE__*/_jsx(GroupContext.Provider, {
|
|
182
|
+
value: {
|
|
183
|
+
config: rowGroupConfig,
|
|
184
|
+
onChange: setGroupConfig
|
|
304
185
|
},
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
186
|
+
children: /*#__PURE__*/_jsxs(Sheet, _objectSpread(_objectSpread({}, args), {}, {
|
|
187
|
+
sheetInstance: sheetInstance,
|
|
188
|
+
sheetRenderer: WrappedTableShell,
|
|
189
|
+
data: data,
|
|
190
|
+
onCellsChanged: handleChanges,
|
|
191
|
+
handleAdd: handleAdd,
|
|
192
|
+
children: [/*#__PURE__*/_jsx(SelectionEvent, {
|
|
193
|
+
hasChildren: hasChildren,
|
|
194
|
+
rowSelection: rowSelection,
|
|
195
|
+
onChange: handleRowSelect
|
|
196
|
+
}), /*#__PURE__*/_jsx(GroupEvent, {
|
|
197
|
+
hasChildren: hasChildren,
|
|
198
|
+
data: data,
|
|
199
|
+
sheetInstance: sheetInstance.current,
|
|
200
|
+
onGridChange: setData
|
|
201
|
+
}), /*#__PURE__*/_jsx(SheetEvent, {
|
|
202
|
+
name: "reverse",
|
|
203
|
+
handler: handleReverse
|
|
204
|
+
}, "_reverse"), Object.keys(eventHandler || {}).map(function (key) {
|
|
205
|
+
return /*#__PURE__*/_jsx(SheetEvent, {
|
|
206
|
+
name: key,
|
|
207
|
+
handler: eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler[key]
|
|
208
|
+
}, key);
|
|
209
|
+
}), /*#__PURE__*/_jsx(AddButton, {
|
|
210
|
+
handleAdd: handleAdd,
|
|
211
|
+
handleBatchAdd: handleBatchAdd
|
|
212
|
+
})]
|
|
213
|
+
}))
|
|
214
|
+
})
|
|
215
|
+
})
|
|
309
216
|
});
|
|
310
217
|
};
|
|
311
218
|
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[][];
|