@zhenliang/sheet 0.1.39 → 0.1.41

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.
@@ -0,0 +1,5 @@
1
+ import React from "react";
2
+ export declare const AddButton: React.FC<{
3
+ handleAdd?: () => void;
4
+ handleBatchAdd?: (count: number) => void;
5
+ }>;
@@ -0,0 +1,92 @@
1
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
+ 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
+ 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); }
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
+ 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
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
+ import { MoreOutlined } from "@ant-design/icons";
8
+ import { Form, InputNumber, Popover, Button } from "antd";
9
+ import React, { useEffect, useRef, useState } from "react";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { jsxs as _jsxs } from "react/jsx-runtime";
12
+ var RowPop = function RowPop(props) {
13
+ var handleBatchAdd = props.handleBatchAdd;
14
+ var inputRef = useRef(null);
15
+ useEffect(function () {
16
+ var interval = setInterval(function () {
17
+ var _inputRef$current;
18
+ (_inputRef$current = inputRef.current) === null || _inputRef$current === void 0 || _inputRef$current.focus();
19
+ }, 200);
20
+ return function () {
21
+ clearInterval(interval);
22
+ };
23
+ }, []);
24
+ return /*#__PURE__*/_jsx(Form, {
25
+ initialValues: {
26
+ count: 10
27
+ },
28
+ onFinish: function onFinish(values) {
29
+ handleBatchAdd && handleBatchAdd(values.count);
30
+ },
31
+ children: /*#__PURE__*/_jsx(Form.Item, {
32
+ style: {
33
+ marginBottom: 0
34
+ },
35
+ label: "\u884C\u6570",
36
+ name: "count",
37
+ children: /*#__PURE__*/_jsx(InputNumber, {
38
+ style: {
39
+ width: 100
40
+ },
41
+ ref: inputRef,
42
+ min: 1,
43
+ max: 100,
44
+ onClick: function onClick(e) {
45
+ e.nativeEvent.target.focus();
46
+ e.stopPropagation();
47
+ }
48
+ })
49
+ })
50
+ });
51
+ };
52
+ export var AddButton = function AddButton(props) {
53
+ var handleAdd = props.handleAdd,
54
+ handleBatchAdd = props.handleBatchAdd;
55
+ var _useState = useState(false),
56
+ _useState2 = _slicedToArray(_useState, 2),
57
+ open = _useState2[0],
58
+ setOpen = _useState2[1];
59
+ if (!handleAdd && !handleBatchAdd) {
60
+ return null;
61
+ }
62
+ return /*#__PURE__*/_jsxs(Button, {
63
+ type: "dashed",
64
+ style: {
65
+ width: '100%',
66
+ height: 32
67
+ },
68
+ onClick: function onClick(e) {
69
+ handleAdd && handleAdd();
70
+ },
71
+ children: ["+ \u6DFB\u52A0", /*#__PURE__*/_jsx(Popover, {
72
+ open: open,
73
+ getPopupContainer: function getPopupContainer(node) {
74
+ return node.parentNode;
75
+ },
76
+ onOpenChange: setOpen,
77
+ trigger: ['click'],
78
+ destroyTooltipOnHide: true,
79
+ content: /*#__PURE__*/_jsx(RowPop, {
80
+ handleBatchAdd: handleBatchAdd
81
+ }),
82
+ children: /*#__PURE__*/_jsx(MoreOutlined, {
83
+ style: {
84
+ marginLeft: 0
85
+ },
86
+ onClick: function onClick(e) {
87
+ e.stopPropagation();
88
+ }
89
+ })
90
+ })]
91
+ });
92
+ };
@@ -1,5 +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
- var _excluded = ["sheetInstance", "columns", "dataSource", "rowKey", "rowSelection", "groupConfig", "onChange", "handleAdd", "draggable", "eventHandler"];
2
+ var _excluded = ["sheetInstance", "columns", "dataSource", "rowKey", "rowSelection", "groupConfig", "onChange", "handleAdd", "handleBatchAdd", "draggable", "eventHandler"];
3
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
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; }
5
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; }
@@ -16,7 +16,7 @@ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) r
16
16
  import { Sheet, useSetState } from "../..";
17
17
  import { GroupContext } from "../../hooks/useGroupConfig";
18
18
  import { WidthContext } from "../../hooks/useWidthConfig";
19
- import { Button, ConfigProvider, Empty } from 'antd';
19
+ import { ConfigProvider, Empty } from 'antd';
20
20
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
21
21
  import { SheetEvent } from "../sheet/Event";
22
22
  import { DraggableShell } from "../shell/draggableShell";
@@ -24,6 +24,7 @@ import { TableShell } from "../shell/tableShell";
24
24
  import { GroupEvent, SelectionEvent } from "./events";
25
25
  import { formatGroupData, useGroupConfig } from "./useGroupConfig";
26
26
  import { formatSelectionData, useRowSelection } from "./useRowSelection";
27
+ import { AddButton } from "./addButton";
27
28
  import { jsx as _jsx } from "react/jsx-runtime";
28
29
  import { jsxs as _jsxs } from "react/jsx-runtime";
29
30
  var Table = function Table(_ref) {
@@ -35,6 +36,7 @@ var Table = function Table(_ref) {
35
36
  groupConfig = _ref.groupConfig,
36
37
  onChange = _ref.onChange,
37
38
  handleAdd = _ref.handleAdd,
39
+ handleBatchAdd = _ref.handleBatchAdd,
38
40
  draggable = _ref.draggable,
39
41
  eventHandler = _ref.eventHandler,
40
42
  args = _objectWithoutProperties(_ref, _excluded);
@@ -202,15 +204,10 @@ var Table = function Table(_ref) {
202
204
  name: key,
203
205
  handler: eventHandler === null || eventHandler === void 0 ? void 0 : eventHandler[key]
204
206
  }, key);
205
- }), handleAdd ? /*#__PURE__*/_jsx(Button, {
206
- type: "dashed",
207
- style: {
208
- width: '100%',
209
- height: 32
210
- },
211
- onClick: handleAdd,
212
- children: "+ \u6DFB\u52A0"
213
- }) : null]
207
+ }), /*#__PURE__*/_jsx(AddButton, {
208
+ handleAdd: handleAdd,
209
+ handleBatchAdd: handleBatchAdd
210
+ })]
214
211
  }))
215
212
  })
216
213
  })
@@ -38,13 +38,29 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
38
38
  }, [dataSource]);
39
39
  useEffect(function () {
40
40
  if (!hasChildren) return;
41
- var rowConfig = dataSourceToRowConfig(dataSource, tableGroupConfig === null || tableGroupConfig === void 0 ? void 0 : tableGroupConfig.defaultOpen);
41
+ var computedRowGroup = dataSourceToRowConfig(dataSource, tableGroupConfig === null || tableGroupConfig === void 0 ? void 0 : tableGroupConfig.defaultOpen);
42
+ var rowConfig = computedRowGroup;
43
+ var _ref = tableGroupConfig || {},
44
+ rowGroup = _ref.rowGroup;
45
+ if (rowGroup) {
46
+ var notEqual = rowGroup.groups.length !== computedRowGroup.groups.length;
47
+ var notSameGroup = notEqual || rowGroup.groups.some(function (group, index) {
48
+ return computedRowGroup.groups[index].groupStart !== group.groupStart || computedRowGroup.groups[index].groupEnd !== group.groupEnd;
49
+ });
50
+ if (!notSameGroup) {
51
+ console.log(notSameGroup, rowGroup.groups, computedRowGroup);
52
+ rowConfig = rowGroup;
53
+ } else {
54
+ var _tableGroupConfig$onC;
55
+ tableGroupConfig === null || tableGroupConfig === void 0 || (_tableGroupConfig$onC = tableGroupConfig.onChange) === null || _tableGroupConfig$onC === void 0 || _tableGroupConfig$onC.call(tableGroupConfig, computedRowGroup);
56
+ }
57
+ }
42
58
  if (groupConfigRef.current) {
43
- rowConfig.groups.forEach(function (_ref, index) {
59
+ rowConfig.groups.forEach(function (_ref2, index) {
44
60
  var _groupConfigRef$curre, _groupConfigRef$curre2;
45
- var groupName = _ref.groupName,
46
- newGroupStart = _ref.groupStart,
47
- newGroupEnd = _ref.groupEnd;
61
+ var groupName = _ref2.groupName,
62
+ newGroupStart = _ref2.groupStart,
63
+ newGroupEnd = _ref2.groupEnd;
48
64
  var rowIndex = (_groupConfigRef$curre = (_groupConfigRef$curre2 = groupConfigRef.current) === null || _groupConfigRef$curre2 === void 0 ? void 0 : _groupConfigRef$curre2.groups.findIndex(function (item) {
49
65
  return item.groupName === groupName;
50
66
  })) !== null && _groupConfigRef$curre !== void 0 ? _groupConfigRef$curre : -1;
@@ -70,7 +86,9 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
70
86
  groupConfigRef.current = rowConfig;
71
87
  }, [dataSource.length, childrenLength, hasChildren]);
72
88
  var handleGroupChange = useCallback(function (value) {
89
+ var _tableGroupConfig$onC2;
73
90
  setGroupConfig(value);
91
+ tableGroupConfig === null || tableGroupConfig === void 0 || (_tableGroupConfig$onC2 = tableGroupConfig.onChange) === null || _tableGroupConfig$onC2 === void 0 || _tableGroupConfig$onC2.call(tableGroupConfig, value);
74
92
  groupConfigRef.current = value;
75
93
  }, [setGroupConfig]);
76
94
  var groupMap = useMemo(function () {
@@ -15,7 +15,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
15
15
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
16
16
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
17
17
  import { Button, Modal } from 'antd';
18
- import { cloneDeep, random } from 'lodash';
18
+ import { cloneDeep, random, range } from 'lodash';
19
19
  import React, { useCallback, useMemo, useRef, useState } from 'react';
20
20
  import { getCascaderEditor, getDateEditor, getNumberEditor, getSelectEditor } from "../core/editor";
21
21
  import Table from "../core/table";
@@ -180,7 +180,7 @@ var data = [{
180
180
  name: 'John Brown',
181
181
  date: '2020-01-01',
182
182
  open: true,
183
- age: 32,
183
+ age: 1,
184
184
  address1: 'West Lake',
185
185
  address2: '打开对话框1',
186
186
  select: '111111',
@@ -191,7 +191,7 @@ var data = [{
191
191
  open: false,
192
192
  date: '1990-01-01',
193
193
  address2: '打开对话框2',
194
- age: 40,
194
+ age: 2,
195
195
  select: '222222',
196
196
  address: 'London Park'
197
197
  }];
@@ -218,6 +218,7 @@ var App = function App() {
218
218
  }, [state]);
219
219
  var handleAdd = useCallback(function () {
220
220
  var _sheetInstance$curren;
221
+ var count = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 1;
221
222
  var newState = cloneDeep(state);
222
223
  (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 || _sheetInstance$curren.pushToHistory({
223
224
  type: 'NewRow',
@@ -226,16 +227,25 @@ var App = function App() {
226
227
  newRow: newState.length
227
228
  }
228
229
  });
229
- setState([].concat(_toConsumableArray(newState), [{
230
- key: String(random()),
231
- name: 'new',
232
- open: false,
233
- date: '1990-01-01',
234
- address2: "\u6253\u5F00\u5BF9\u8BDD\u68462".concat(newState.length + 2),
235
- age: 40 + newState.length,
236
- select: '111111',
237
- address: 'London Park'
238
- }]));
230
+ setState([].concat(_toConsumableArray(newState), _toConsumableArray(range(0, count).map(function (a, i) {
231
+ return {
232
+ key: String(random()),
233
+ name: 'new',
234
+ open: false,
235
+ date: '1990-01-01',
236
+ address2: "\u6253\u5F00\u5BF9\u8BDD\u68462".concat(newState.length + 2 + i),
237
+ age: newState[newState.length - 1].age + i + 1,
238
+ select: '111111',
239
+ address: 'London Park'
240
+ };
241
+ }))));
242
+ setTimeout(function () {
243
+ var _sheetInstance$curren2, _sheetInstance$curren3;
244
+ console.log('select', newState.length + count - 1);
245
+ (_sheetInstance$curren2 = sheetInstance.current) === null || _sheetInstance$curren2 === void 0 || _sheetInstance$curren2.selectRow(newState.length + count - 1);
246
+ console.log('zoomTO', newState.length + count - 1);
247
+ (_sheetInstance$curren3 = sheetInstance.current) === null || _sheetInstance$curren3 === void 0 || _sheetInstance$curren3.zoomTo(newState.length + count - 1);
248
+ }, 100);
239
249
  }, [state]);
240
250
  var handleOptionsAdd = useCallback(function () {
241
251
  setOptions([].concat(_toConsumableArray(options), [{
@@ -267,6 +277,7 @@ var App = function App() {
267
277
  },
268
278
  onChange: handleChange,
269
279
  handleAdd: handleAdd,
280
+ handleBatchAdd: handleAdd,
270
281
  eventHandler: {
271
282
  reverse: function reverse(value) {
272
283
  // 处理 行列删除自定义事件
@@ -86,6 +86,7 @@ export type TableProps = {
86
86
  onContextMenu?: (event: any) => void;
87
87
  onChange: (changes: TableChange[], extChanges?: TableChange[]) => void;
88
88
  handleAdd?: () => void;
89
+ handleBatchAdd?: () => void;
89
90
  eventHandler?: Record<'reverse' | 'btn-click' | 'cell-edit' | 'cell-switch' | string, undefined | EventHandler>;
90
91
  boldScroll?: boolean;
91
92
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.39",
3
+ "version": "0.1.41",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",