@zhenliang/sheet 0.1.87 → 0.1.88

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.
@@ -8,6 +8,8 @@ interface ControlProps {
8
8
  backToEditRow: () => void;
9
9
  toTop: () => void;
10
10
  toBottom: () => void;
11
+ reverse: () => void;
12
+ recover: () => void;
11
13
  backEditStyle?: Partial<CSSProperties>;
12
14
  ControlContainer?: React.FC<any>;
13
15
  showBackEdit?: boolean;
@@ -16,6 +18,9 @@ interface ControlProps {
16
18
  end?: CellPosition;
17
19
  selecting?: boolean;
18
20
  };
21
+ showRecoverBtn: boolean;
22
+ recoverLength: number;
23
+ reverseLength: number;
19
24
  }
20
25
  export declare const Control: React.FC<ControlProps>;
21
26
  export {};
@@ -1,4 +1,4 @@
1
- import { EditOutlined, VerticalAlignBottomOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
1
+ import { EditOutlined, RedoOutlined, UndoOutlined, VerticalAlignBottomOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
2
2
  import { Button, Tooltip } from 'antd';
3
3
  import React, { useMemo } from 'react';
4
4
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -16,14 +16,35 @@ export var Control = function Control(props) {
16
16
  toTop = props.toTop,
17
17
  toBottom = props.toBottom,
18
18
  backToEditRow = props.backToEditRow,
19
+ reverse = props.reverse,
20
+ recover = props.recover,
19
21
  _props$backEditStyle = props.backEditStyle,
20
22
  backEditStyle = _props$backEditStyle === void 0 ? {
21
23
  bottom: 0,
22
24
  right: 0
23
25
  } : _props$backEditStyle,
24
- ControlContainer = props.ControlContainer;
26
+ ControlContainer = props.ControlContainer,
27
+ showRecoverBtn = props.showRecoverBtn,
28
+ recoverLength = props.recoverLength,
29
+ reverseLength = props.reverseLength;
25
30
  var btns = useMemo(function () {
26
31
  var tempBtns = [{
32
+ title: '撤销',
33
+ disabled: reverseLength === 0,
34
+ event: reverse,
35
+ icon: /*#__PURE__*/_jsx(UndoOutlined, {
36
+ style: itemStyle
37
+ }),
38
+ isShow: showRecoverBtn
39
+ }, {
40
+ title: '恢复',
41
+ disabled: recoverLength === 0,
42
+ event: recover,
43
+ icon: /*#__PURE__*/_jsx(RedoOutlined, {
44
+ style: itemStyle
45
+ }),
46
+ isShow: showRecoverBtn
47
+ }, {
27
48
  title: '置顶',
28
49
  disabled: firstRowVisible,
29
50
  event: toTop,
@@ -51,7 +72,7 @@ export var Control = function Control(props) {
51
72
  return tempBtns.filter(function (item) {
52
73
  return item.isShow;
53
74
  });
54
- }, [firstRowVisible, showQuickLocationBtn, lastRowVisible, startRowVisible, showBackEdit]);
75
+ }, [firstRowVisible, showQuickLocationBtn, lastRowVisible, startRowVisible, showBackEdit, recoverLength, reverseLength, reverse, recover]);
55
76
  if (!showBackEdit && !showQuickLocationBtn) return null;
56
77
  if (ControlContainer) {
57
78
  return /*#__PURE__*/_jsx(ControlContainer, {
@@ -20,6 +20,7 @@ import { Empty } from 'antd';
20
20
  import { isEmpty, isNil, isNumber } from 'lodash';
21
21
  import { SheetEventContext, useEventBus, useMiddlewareReducer } from "../../hooks";
22
22
  import sheetReducer from "../reducers";
23
+ import { sideEffectReducer } from "../reducers/sideEffectReducer";
23
24
  import { classNames, getRowHeight, rowToActualRow } from "../util";
24
25
  import { Control } from "./Control";
25
26
  import { DefaultRowMapper } from "./DefaultRowMapper";
@@ -394,6 +395,18 @@ var Sheet = function Sheet(props) {
394
395
  handleScroll();
395
396
  }
396
397
  }, []);
398
+ var _useMemo = useMemo(function () {
399
+ var history = state.history,
400
+ recoverHistory = state.recoverHistory;
401
+ var reverseLength = history ? history.length : 0;
402
+ var recoverLength = recoverHistory ? recoverHistory.length : 0;
403
+ return {
404
+ reverseLength: reverseLength,
405
+ recoverLength: recoverLength
406
+ };
407
+ }, [state]),
408
+ reverseLength = _useMemo.reverseLength,
409
+ recoverLength = _useMemo.recoverLength;
397
410
  return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
398
411
  value: eventBus,
399
412
  children: /*#__PURE__*/_jsxs(_Fragment, {
@@ -432,6 +445,15 @@ var Sheet = function Sheet(props) {
432
445
  }), /*#__PURE__*/_jsxs("div", {
433
446
  className: "harvest-sheet-control",
434
447
  children: [/*#__PURE__*/_jsx(Control, {
448
+ showRecoverBtn: !freeze,
449
+ reverse: function reverse() {
450
+ dispatch(sideEffectReducer.reverse);
451
+ },
452
+ recover: function recover() {
453
+ dispatch(sideEffectReducer.recover);
454
+ },
455
+ reverseLength: reverseLength,
456
+ recoverLength: recoverLength,
435
457
  showBackEdit: showBackEdit,
436
458
  startRowVisible: startRowVisible,
437
459
  backToEditRow: function backToEditRow() {
@@ -108,6 +108,7 @@ export type SheetInstance = {
108
108
  }) => void;
109
109
  popHistory: () => OperateHistory;
110
110
  dropHistory: () => OperateHistory[];
111
+ dropRecover: () => OperateHistory[];
111
112
  call: (caller: (...args: any) => void, ...args: any) => void;
112
113
  };
113
114
  export type SheetProps = {
@@ -141,6 +142,7 @@ export type SheetProps = {
141
142
  showQuickLocationBtn?: boolean;
142
143
  showRemark?: boolean;
143
144
  ControlContainer?: React.FC;
145
+ showRecoverBtn?: boolean;
144
146
  };
145
147
  export type WidthConfigContext = {
146
148
  onChange?: (value: Record<number | string, number>) => void;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.87",
3
+ "version": "0.1.88",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -85,4 +85,5 @@
85
85
  "fizz.zhou@ap.jll.com"
86
86
  ],
87
87
  "preid": "beta"
88
+
88
89
  }