@zhenliang/sheet 0.1.74 → 0.1.76

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.
@@ -35,7 +35,7 @@ export var sideEffectReducer = {
35
35
  cell: cell
36
36
  }
37
37
  });
38
- cellChangeHandler && cellChangeHandler([cell]);
38
+ cellChangeHandler && cellChangeHandler([cell], undefined, 'Edit');
39
39
  });
40
40
  });
41
41
  eventBus.on('cell-create', function (_ref) {
@@ -307,7 +307,7 @@ export var sideEffectReducer = {
307
307
  }
308
308
  }
309
309
  });
310
- cellChangeHandler && cellChangeHandler(legalChanges, freePaste ? legalExtChanges : []);
310
+ cellChangeHandler && cellChangeHandler(legalChanges, freePaste ? legalExtChanges : [], 'Paste');
311
311
  case 18:
312
312
  case "end":
313
313
  return _context.stop();
@@ -364,7 +364,7 @@ export var sideEffectReducer = {
364
364
  history: newHistory
365
365
  }
366
366
  });
367
- cellChangeHandler && cellChangeHandler(changes);
367
+ cellChangeHandler && cellChangeHandler(changes, undefined, 'Delete');
368
368
  },
369
369
  reverse: function reverse(dispatch, getState) {
370
370
  var _getState10 = getState(),
@@ -391,7 +391,7 @@ export var sideEffectReducer = {
391
391
  });
392
392
  return;
393
393
  }
394
- cellChangeHandler && cellChangeHandler(change.changes);
394
+ cellChangeHandler && cellChangeHandler(change.changes, undefined, 'Reverse');
395
395
  var recoverChange = _objectSpread(_objectSpread({}, change), {}, {
396
396
  changes: change.changes.map(function (item) {
397
397
  var _item$row, _item$col;
@@ -448,7 +448,7 @@ export var sideEffectReducer = {
448
448
  });
449
449
  })
450
450
  });
451
- cellChangeHandler && cellChangeHandler(change.changes);
451
+ cellChangeHandler && cellChangeHandler(change.changes, undefined, 'Recover');
452
452
  dispatch({
453
453
  type: 'changes',
454
454
  payload: {
@@ -1,3 +1,9 @@
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
+ 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(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); }
1
7
  function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
2
8
  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
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); }
@@ -231,6 +237,21 @@ var Sheet = function Sheet(props) {
231
237
  useMouseEvent(dispatch, sheetWrapperRef);
232
238
  useKeyBoardEvent(dispatch, sheetWrapperRef);
233
239
  var menu = useContextMenu(dispatch, sheetWrapperRef, !!ContextMenu, contextMenuRef);
240
+ var menuCell = useMemo(function () {
241
+ var _data$cellPosition$ro, _data$cellPosition$ro2, _data$cellPosition$ro3;
242
+ var cellPosition = menu.cellPosition,
243
+ showMenu = menu.showMenu;
244
+ if (!showMenu) {
245
+ return cellPosition;
246
+ }
247
+ var _ref2 = (_data$cellPosition$ro = data === null || data === void 0 || (_data$cellPosition$ro2 = data[cellPosition.row]) === null || _data$cellPosition$ro2 === void 0 ? void 0 : _data$cellPosition$ro2[cellPosition.col - 1 - ((_data$cellPosition$ro3 = data[cellPosition.row][0].col) !== null && _data$cellPosition$ro3 !== void 0 ? _data$cellPosition$ro3 : 0)]) !== null && _data$cellPosition$ro !== void 0 ? _data$cellPosition$ro : {},
248
+ id = _ref2.id,
249
+ dataIndex = _ref2.dataIndex;
250
+ return _objectSpread(_objectSpread({}, cellPosition), {}, {
251
+ id: id,
252
+ key: dataIndex
253
+ });
254
+ }, [data, menu.cellPosition]);
234
255
  var _useRemarkContainer = useRemarkContainer(sheetWrapperRef, state.start, state.editing, showRemark),
235
256
  remarkInfo = _useRemarkContainer.remarkInfo;
236
257
 
@@ -393,7 +414,7 @@ var Sheet = function Sheet(props) {
393
414
  }, "sheet"), /*#__PURE__*/_jsx(Menu, {
394
415
  ref: contextMenuRef,
395
416
  position: menu.position,
396
- cell: menu.cellPosition,
417
+ cell: menuCell,
397
418
  showMenu: menu.showMenu,
398
419
  contextMenu: ContextMenu,
399
420
  onContextMenu: onContextMenu
@@ -1,6 +1,6 @@
1
1
  import { useKeyBoard } from "../..";
2
2
  import { sideEffectReducer } from "../reducers/sideEffectReducer";
3
- import { ensureFocus, getRowHeight } from "../util";
3
+ import { ensureFocus, getRowHeight, isSearchElement } from "../util";
4
4
  export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
5
5
  useKeyBoard({
6
6
  move: function move(e, value) {
@@ -63,13 +63,20 @@ export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
63
63
  }
64
64
  });
65
65
  },
66
- copy: function copy() {
67
- dispatch(sideEffectReducer.copy);
66
+ copy: function copy(e) {
67
+ var _elementRef$current2;
68
+ var isFromSearch = isSearchElement((_elementRef$current2 = elementRef.current) === null || _elementRef$current2 === void 0 ? void 0 : _elementRef$current2.parentElement, e.target);
69
+ isFromSearch ? null : dispatch(sideEffectReducer.copy);
68
70
  },
69
- paste: function paste() {
70
- dispatch(sideEffectReducer.paste);
71
+ paste: function paste(e) {
72
+ var _elementRef$current3;
73
+ var isFromSearch = isSearchElement((_elementRef$current3 = elementRef.current) === null || _elementRef$current3 === void 0 ? void 0 : _elementRef$current3.parentElement, e.target);
74
+ isFromSearch ? null : dispatch(sideEffectReducer.paste);
71
75
  },
72
- cut: function cut() {
76
+ cut: function cut(e) {
77
+ var _elementRef$current4;
78
+ var isFromSearch = isSearchElement((_elementRef$current4 = elementRef.current) === null || _elementRef$current4 === void 0 ? void 0 : _elementRef$current4.parentElement, e.target);
79
+ if (isFromSearch) return;
73
80
  dispatch(sideEffectReducer.copy);
74
81
  dispatch(sideEffectReducer.delete);
75
82
  },
@@ -1,6 +1,6 @@
1
1
  import { useMouse } from "../..";
2
2
  import { useCallback, useEffect, useRef } from 'react';
3
- import { extractDataRowAndCol, findParentTd } from "../util";
3
+ import { extractDataRowAndCol, findParentTd, isSearchElement } from "../util";
4
4
  var rowCount = 10; //每秒10行
5
5
  var colCount = 5; //每秒5列
6
6
 
@@ -267,7 +267,8 @@ export var useMouseEvent = function useMouseEvent(dispatch, elementRef) {
267
267
  }, []);
268
268
  var loseFocus = useCallback(function (e) {
269
269
  var _elementRef$current10, _elementRef$current11;
270
- var isSearch = (_elementRef$current10 = elementRef.current) === null || _elementRef$current10 === void 0 || (_elementRef$current10 = _elementRef$current10.parentElement) === null || _elementRef$current10 === void 0 || (_elementRef$current10 = _elementRef$current10.nextSibling) === null || _elementRef$current10 === void 0 ? void 0 : _elementRef$current10.contains(e.target);
270
+ // todo 加一个root node
271
+ var isSearch = isSearchElement((_elementRef$current10 = elementRef.current) === null || _elementRef$current10 === void 0 ? void 0 : _elementRef$current10.parentElement, e.target);
271
272
  var isTableAControl = (_elementRef$current11 = elementRef.current) === null || _elementRef$current11 === void 0 || (_elementRef$current11 = _elementRef$current11.parentElement) === null || _elementRef$current11 === void 0 ? void 0 : _elementRef$current11.contains(e.target);
272
273
  if (!(isTableAControl || isSearch)) {
273
274
  dispatch({
@@ -140,7 +140,7 @@ var Table = function Table(_ref) {
140
140
  setData([[]]);
141
141
  }
142
142
  }, [dataSource, columns]);
143
- var handleChanges = useCallback(function (changes, extChange) {
143
+ var handleChanges = useCallback(function (changes, extChange, type) {
144
144
  if (freeze) return;
145
145
  onChange && onChange(changes.map(function (item) {
146
146
  return {
@@ -158,7 +158,7 @@ var Table = function Table(_ref) {
158
158
  key: item.key || columns[item.col - offset].dataIndex,
159
159
  value: item.value
160
160
  };
161
- }));
161
+ }), type);
162
162
  }, [columns, onChange, hasControl, freeze]);
163
163
  var handleReverse = useCallback(function (value) {
164
164
  var _ref2 = value,
@@ -62,3 +62,4 @@ export declare const stripRowIndex: (data: SheetType.Cell[][]) => {
62
62
  endIndex: number;
63
63
  };
64
64
  export declare const ensureFocus: (container?: HTMLElement | null) => void;
65
+ export declare const isSearchElement: (tableRootNode: HTMLDivElement, target: HTMLElement) => boolean | undefined;
package/dist/core/util.js CHANGED
@@ -495,4 +495,8 @@ export var ensureFocus = function ensureFocus(container) {
495
495
  clearInterval(focusInterval);
496
496
  focusInterval = undefined;
497
497
  }, 1000);
498
+ };
499
+ export var isSearchElement = function isSearchElement(tableRootNode, target) {
500
+ var _tableRootNode$nextSi;
501
+ return (_tableRootNode$nextSi = tableRootNode.nextSibling) === null || _tableRootNode$nextSi === void 0 || (_tableRootNode$nextSi = _tableRootNode$nextSi.nextSibling) === null || _tableRootNode$nextSi === void 0 ? void 0 : _tableRootNode$nextSi.contains(target);
498
502
  };
@@ -1,6 +1,6 @@
1
1
  import { useCallback, useEffect } from 'react';
2
2
  import { A_KEY, BACKSPACE_KEY, C_KEY, DELETE_KEY, DOWN_KEY, ENTER_KEY, ESCAPE_KEY, F_KEY, LEFT_KEY, RIGHT_KEY, TAB_KEY, UP_KEY, V_KEY, X_KEY, Y_KEY, Z_KEY } from "../core/config";
3
- import { isInputKey } from "../core/util";
3
+ import { isInputKey, isSearchElement } from "../core/util";
4
4
  var ua = window.navigator.userAgent;
5
5
  var isIE = /MSIE|Trident/.test(ua);
6
6
  export function move(keyCode, isShiftKey) {
@@ -38,7 +38,8 @@ export function move(keyCode, isShiftKey) {
38
38
  }
39
39
  export var useKeyBoard = function useKeyBoard(handler, listenElement) {
40
40
  var handleKey = useCallback(function (e) {
41
- if (e.defaultPrevented) {
41
+ var isFromSearch = isSearchElement(listenElement === null || listenElement === void 0 ? void 0 : listenElement.parentElement, e.target);
42
+ if (e.defaultPrevented || isFromSearch) {
42
43
  return;
43
44
  }
44
45
  var ctrlKey = e.ctrlKey,
@@ -69,8 +69,9 @@ export type CellData = {
69
69
  key?: string;
70
70
  value?: string;
71
71
  };
72
+ export type ChangeType = 'Edit' | 'Paste' | 'Delete' | 'Reverse' | 'Recover';
72
73
  export type CellNavigable = (cell?: Cell, row?: number, col?: number) => boolean;
73
- export type CellChangeHandler = (cells: CellData[], additions?: CellData[]) => void;
74
+ export type CellChangeHandler = (cells: CellData[], additions: CellData[] | undefined, type: ChangeType) => void;
74
75
  export type RowGroup = {
75
76
  groupName: string;
76
77
  groupStart: number;
@@ -90,7 +91,7 @@ export type MenuRenderProps = {
90
91
  top: number;
91
92
  left: number;
92
93
  };
93
- cell?: CellPosition;
94
+ cell?: CellPosition & Partial<Cell>;
94
95
  onContextMenu?: (event: any) => void;
95
96
  children?: ReactNode | ReactNode[];
96
97
  target?: any;
@@ -233,7 +234,7 @@ export type UpdateStateType = {
233
234
  lastEditing: CellPosition & {
234
235
  confirm?: boolean;
235
236
  };
236
- cellChangeHandler: (cells: CellData[], additions?: CellData[]) => void;
237
+ cellChangeHandler: (cells: CellData[], additions: CellData[] | undefined, type: ChangeType) => void;
237
238
  fixedInfo: SheetType.FixedInfo[];
238
239
  } & SearchState;
239
240
  export type UpdateFocus = (start: CellPosition, end: CellPosition) => void;
@@ -1,5 +1,6 @@
1
1
  import { CSSProperties, ReactNode } from 'react';
2
2
  import { SheetType } from '.';
3
+ import { ChangeType } from './sheet';
3
4
  export type refAssertion = {
4
5
  contains?: (target: EventTarget | null) => boolean;
5
6
  focus?: () => boolean;
@@ -100,7 +101,7 @@ export type TableProps = {
100
101
  groupConfig?: TableGroupConfig;
101
102
  menuRenderer?: React.FC<SheetType.MenuRenderProps>;
102
103
  onContextMenu?: (event: any) => void;
103
- onChange: (changes: TableChange[], extChanges?: TableChange[]) => void;
104
+ onChange: (changes: TableChange[], extChanges: TableChange[] | undefined, type: ChangeType) => void;
104
105
  handleAdd?: () => void;
105
106
  handleBatchAdd?: (value: number) => void;
106
107
  eventHandler?: Record<'reverse' | 'btn-click' | 'cell-edit' | 'cell-switch' | string, undefined | EventHandler>;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.74",
3
+ "version": "0.1.76",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -85,4 +85,4 @@
85
85
  "fizz.zhou@ap.jll.com"
86
86
  ],
87
87
  "preid": "beta"
88
- }
88
+ }