@zhenliang/sheet 0.1.74 → 0.1.76-beta.2

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();
@@ -361,18 +361,19 @@ export var sideEffectReducer = {
361
361
  dispatch({
362
362
  type: 'changes',
363
363
  payload: {
364
- history: newHistory
364
+ history: newHistory,
365
+ recoverHistory: []
365
366
  }
366
367
  });
367
- cellChangeHandler && cellChangeHandler(changes);
368
+ cellChangeHandler && cellChangeHandler(changes, undefined, 'Delete');
368
369
  },
369
370
  reverse: function reverse(dispatch, getState) {
370
371
  var _getState10 = getState(),
371
372
  start = _getState10.start,
372
373
  end = _getState10.end,
373
374
  history = _getState10.history,
374
- _getState10$recoverHi = _getState10.recoverHisotry,
375
- recoverHisotry = _getState10$recoverHi === void 0 ? [] : _getState10$recoverHi,
375
+ _getState10$recoverHi = _getState10.recoverHistory,
376
+ recoverHistory = _getState10$recoverHi === void 0 ? [] : _getState10$recoverHi,
376
377
  cellChangeHandler = _getState10.cellChangeHandler,
377
378
  eventBus = _getState10.eventBus,
378
379
  data = _getState10.data;
@@ -386,12 +387,12 @@ export var sideEffectReducer = {
386
387
  type: 'changes',
387
388
  payload: {
388
389
  history: changeHistory,
389
- recoverHisotry: [].concat(_toConsumableArray(recoverHisotry), [change])
390
+ recoverHistory: [].concat(_toConsumableArray(recoverHistory), [change])
390
391
  }
391
392
  });
392
393
  return;
393
394
  }
394
- cellChangeHandler && cellChangeHandler(change.changes);
395
+ cellChangeHandler && cellChangeHandler(change.changes, undefined, 'Reverse');
395
396
  var recoverChange = _objectSpread(_objectSpread({}, change), {}, {
396
397
  changes: change.changes.map(function (item) {
397
398
  var _item$row, _item$col;
@@ -410,23 +411,23 @@ export var sideEffectReducer = {
410
411
  end: end
411
412
  },
412
413
  history: changeHistory,
413
- recoverHisotry: [].concat(_toConsumableArray(recoverHisotry), [recoverChange])
414
+ recoverHistory: [].concat(_toConsumableArray(recoverHistory), [recoverChange])
414
415
  }
415
416
  });
416
417
  },
417
418
  recover: function recover(dispatch, getState) {
418
419
  var _getState11 = getState(),
419
420
  eventBus = _getState11.eventBus,
420
- _getState11$recoverHi = _getState11.recoverHisotry,
421
- recoverHisotry = _getState11$recoverHi === void 0 ? [] : _getState11$recoverHi,
421
+ _getState11$recoverHi = _getState11.recoverHistory,
422
+ recoverHistory = _getState11$recoverHi === void 0 ? [] : _getState11$recoverHi,
422
423
  _getState11$history = _getState11.history,
423
424
  history = _getState11$history === void 0 ? [] : _getState11$history,
424
425
  cellChangeHandler = _getState11.cellChangeHandler,
425
426
  start = _getState11.start,
426
427
  end = _getState11.end,
427
428
  data = _getState11.data;
428
- if (!(recoverHisotry !== null && recoverHisotry !== void 0 && recoverHisotry.length)) return;
429
- var changeHistory = _toConsumableArray(recoverHisotry);
429
+ if (!(recoverHistory !== null && recoverHistory !== void 0 && recoverHistory.length)) return;
430
+ var changeHistory = _toConsumableArray(recoverHistory);
430
431
  var change = changeHistory.pop();
431
432
  var type = change.type;
432
433
  if (!['Edit', 'Paste', 'Delete'].includes(type)) {
@@ -434,7 +435,7 @@ export var sideEffectReducer = {
434
435
  dispatch({
435
436
  type: 'changes',
436
437
  payload: {
437
- recoverHisotry: changeHistory,
438
+ recoverHistory: changeHistory,
438
439
  history: [].concat(_toConsumableArray(history), [change])
439
440
  }
440
441
  });
@@ -448,7 +449,7 @@ export var sideEffectReducer = {
448
449
  });
449
450
  })
450
451
  });
451
- cellChangeHandler && cellChangeHandler(change.changes);
452
+ cellChangeHandler && cellChangeHandler(change.changes, undefined, 'Recover');
452
453
  dispatch({
453
454
  type: 'changes',
454
455
  payload: {
@@ -459,7 +460,7 @@ export var sideEffectReducer = {
459
460
  end: end
460
461
  },
461
462
  history: [].concat(_toConsumableArray(history), [reverseChange]),
462
- recoverHisotry: changeHistory
463
+ recoverHistory: changeHistory
463
464
  }
464
465
  });
465
466
  }
@@ -10,12 +10,13 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
10
10
  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; }
11
11
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
12
12
  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); }
13
- import { stripRowIndex } from "../util";
13
+ import { noramlizeSearch, searchInclude, stripRowIndex } from "../util";
14
14
  export var searchReducer = {
15
15
  changeSearch: function changeSearch(state, payload) {
16
16
  var data = state.data;
17
17
  var count = 0;
18
18
  var searchResultList = [];
19
+ var normalSearchText = noramlizeSearch(payload);
19
20
  payload && (data === null || data === void 0 ? void 0 : data.forEach(function (row, i) {
20
21
  return row.forEach(function (item, j) {
21
22
  var _item$dataEditor, _item$value;
@@ -24,9 +25,8 @@ export var searchReducer = {
24
25
  }
25
26
  var formatterValue;
26
27
  if (item.searchKey) {
27
- var _formatterValue;
28
28
  formatterValue = item.searchKey(item.record);
29
- if ((_formatterValue = formatterValue) !== null && _formatterValue !== void 0 && _formatterValue.includes(payload)) {
29
+ if (searchInclude(normalSearchText, formatterValue)) {
30
30
  count++;
31
31
  searchResultList.push({
32
32
  row: i,
@@ -36,9 +36,9 @@ export var searchReducer = {
36
36
  });
37
37
  }
38
38
  } else if ((_item$dataEditor = item.dataEditor) !== null && _item$dataEditor !== void 0 && _item$dataEditor.formatter) {
39
- var _item$dataEditor2, _formatterValue2;
39
+ var _item$dataEditor2;
40
40
  formatterValue = (_item$dataEditor2 = item.dataEditor) === null || _item$dataEditor2 === void 0 || (_item$dataEditor2 = _item$dataEditor2.formatter(item.value, item.record)) === null || _item$dataEditor2 === void 0 ? void 0 : _item$dataEditor2.toString();
41
- if ((_formatterValue2 = formatterValue) !== null && _formatterValue2 !== void 0 && _formatterValue2.includes(payload)) {
41
+ if (searchInclude(normalSearchText, formatterValue)) {
42
42
  count++;
43
43
  searchResultList.push({
44
44
  row: i,
@@ -47,7 +47,7 @@ export var searchReducer = {
47
47
  formatterValue: formatterValue
48
48
  });
49
49
  }
50
- } else if ((_item$value = item.value) !== null && _item$value !== void 0 && _item$value.toString().includes(payload)) {
50
+ } else if (searchInclude(normalSearchText, (_item$value = item.value) === null || _item$value === void 0 ? void 0 : _item$value.toString())) {
51
51
  count++;
52
52
  searchResultList.push({
53
53
  row: i,
@@ -61,7 +61,8 @@ export var searchReducer = {
61
61
  searchText: payload,
62
62
  searchTotal: count,
63
63
  searchCurrent: -1,
64
- searchResultList: searchResultList
64
+ searchResultList: searchResultList,
65
+ shouldSearchUpdate: false
65
66
  });
66
67
  },
67
68
  closeSearch: function closeSearch(state) {
@@ -145,11 +146,13 @@ export var stateReducer = _objectSpread({
145
146
  return _objectSpread(_objectSpread({}, state), {}, {
146
147
  editing: undefined,
147
148
  lastEditing: state.editing,
148
- history: history
149
+ history: history,
150
+ recoverHistory: []
149
151
  });
150
152
  }
151
153
  return _objectSpread(_objectSpread({}, state), {}, {
152
- history: history
154
+ history: history,
155
+ recoverHistory: []
153
156
  });
154
157
  },
155
158
  popHistory: function popHistory(state) {
@@ -162,8 +165,13 @@ export var stateReducer = _objectSpread({
162
165
  });
163
166
  },
164
167
  pushHistory: function pushHistory(state, payload) {
168
+ var newRecoverHistory = state.recoverHistory;
169
+ if (['DeleteRow', 'NewRow'].includes(payload.type)) {
170
+ newRecoverHistory = [];
171
+ }
165
172
  return _objectSpread(_objectSpread({}, state), {}, {
166
- history: [].concat(_toConsumableArray(state.history || []), [payload])
173
+ history: [].concat(_toConsumableArray(state.history || []), [payload]),
174
+ recoverHistory: newRecoverHistory
167
175
  });
168
176
  },
169
177
  select: function select(state, 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); }
@@ -202,6 +208,16 @@ var Sheet = function Sheet(props) {
202
208
  });
203
209
  return history !== null && history !== void 0 ? history : [];
204
210
  },
211
+ dropRecover: function dropRecover() {
212
+ var recoverHistory = state.recoverHistory;
213
+ dispatch({
214
+ type: 'changes',
215
+ payload: {
216
+ recoverHistory: []
217
+ }
218
+ });
219
+ return recoverHistory !== null && recoverHistory !== void 0 ? recoverHistory : [];
220
+ },
205
221
  call: function call(caller) {
206
222
  for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
207
223
  args[_key - 1] = arguments[_key];
@@ -231,6 +247,21 @@ var Sheet = function Sheet(props) {
231
247
  useMouseEvent(dispatch, sheetWrapperRef);
232
248
  useKeyBoardEvent(dispatch, sheetWrapperRef);
233
249
  var menu = useContextMenu(dispatch, sheetWrapperRef, !!ContextMenu, contextMenuRef);
250
+ var menuCell = useMemo(function () {
251
+ var _data$cellPosition$ro, _data$cellPosition$ro2, _data$cellPosition$ro3;
252
+ var cellPosition = menu.cellPosition,
253
+ showMenu = menu.showMenu;
254
+ if (!showMenu) {
255
+ return cellPosition;
256
+ }
257
+ 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 : {},
258
+ id = _ref2.id,
259
+ dataIndex = _ref2.dataIndex;
260
+ return _objectSpread(_objectSpread({}, cellPosition), {}, {
261
+ id: id,
262
+ key: dataIndex
263
+ });
264
+ }, [data, menu.cellPosition]);
234
265
  var _useRemarkContainer = useRemarkContainer(sheetWrapperRef, state.start, state.editing, showRemark),
235
266
  remarkInfo = _useRemarkContainer.remarkInfo;
236
267
 
@@ -393,7 +424,7 @@ var Sheet = function Sheet(props) {
393
424
  }, "sheet"), /*#__PURE__*/_jsx(Menu, {
394
425
  ref: contextMenuRef,
395
426
  position: menu.position,
396
- cell: menu.cellPosition,
427
+ cell: menuCell,
397
428
  showMenu: menu.showMenu,
398
429
  contextMenu: ContextMenu,
399
430
  onContextMenu: onContextMenu
@@ -441,6 +472,7 @@ var Sheet = function Sheet(props) {
441
472
  current: state.searchCurrent,
442
473
  calledCount: state.searchCalledCount,
443
474
  open: state.showSearch,
475
+ shouldUpdate: state.shouldSearchUpdate,
444
476
  goNext: goNext,
445
477
  goLast: goLast,
446
478
  onChange: changeSearch,
@@ -349,16 +349,24 @@ span.harvest-sheet-container:focus {
349
349
  }
350
350
  }
351
351
 
352
+ @keyframes pop{
353
+ 0% {width:0px}
354
+ 100% {width:290px}
355
+ }
356
+
357
+
358
+
352
359
  .harvest-search-text {
353
360
  position: absolute;
354
361
  top: 0px;
355
362
  right: 0px;
356
- width: 280px;
357
363
  z-index: 4;
358
364
  font-size: 14px;
359
365
  margin: 5px;
366
+ animation: pop .5s ease;
360
367
  }
361
368
 
369
+
362
370
  .harvest-search-text .search-text-suffix {
363
371
  .search-text-disabled {
364
372
  color: #a4a9b2;
@@ -1,6 +1,7 @@
1
1
  import { CSSProperties } from 'react';
2
2
  interface SearchInputProps {
3
3
  open?: boolean;
4
+ shouldUpdate?: boolean;
4
5
  style?: Partial<CSSProperties>;
5
6
  value?: string;
6
7
  current?: number;
@@ -1,6 +1,7 @@
1
1
  import { CloseOutlined, DownOutlined, UpOutlined } from '@ant-design/icons';
2
2
  import { Divider, Input } from 'antd';
3
- import { useEffect, useRef } from 'react';
3
+ import { useEffect, useMemo, useRef } from 'react';
4
+ import { getTextWidth } from "../util";
4
5
  import { jsxs as _jsxs } from "react/jsx-runtime";
5
6
  import { jsx as _jsx } from "react/jsx-runtime";
6
7
  export var SearchInput = function SearchInput(props) {
@@ -12,6 +13,8 @@ export var SearchInput = function SearchInput(props) {
12
13
  value = props.value,
13
14
  _onChange = props.onChange,
14
15
  open = props.open,
16
+ _props$shouldUpdate = props.shouldUpdate,
17
+ shouldUpdate = _props$shouldUpdate === void 0 ? false : _props$shouldUpdate,
15
18
  onClose = props.onClose,
16
19
  goLast = props.goLast,
17
20
  goNext = props.goNext,
@@ -23,6 +26,21 @@ export var SearchInput = function SearchInput(props) {
23
26
  inputRef.current.focus();
24
27
  }
25
28
  }, [calledCount]);
29
+ var inputWidth = useMemo(function () {
30
+ var otherWidth = 140;
31
+ var textWidth = 0;
32
+ if (!value) {
33
+ textWidth = 150;
34
+ return otherWidth + textWidth;
35
+ }
36
+ textWidth = getTextWidth(value);
37
+ if (textWidth > 350) {
38
+ textWidth = 350;
39
+ } else if (textWidth < 150) {
40
+ textWidth = 150;
41
+ }
42
+ return textWidth + otherWidth;
43
+ }, [value]);
26
44
  if (!open) {
27
45
  return null;
28
46
  }
@@ -33,14 +51,23 @@ export var SearchInput = function SearchInput(props) {
33
51
  ref: inputRef,
34
52
  placeholder: "\u67E5\u627E",
35
53
  autoFocus: true,
54
+ onFocus: function onFocus(e) {
55
+ return e.target.select();
56
+ },
57
+ contentEditable: true,
36
58
  style: {
37
- height: 40
59
+ height: 40,
60
+ width: inputWidth,
61
+ minWidth: 250
38
62
  },
39
63
  value: value,
40
64
  onChange: function onChange(e) {
41
65
  return _onChange && _onChange(e.target.value);
42
66
  },
43
67
  onPressEnter: function onPressEnter(e) {
68
+ if (shouldUpdate) {
69
+ _onChange && _onChange(e.target.value);
70
+ }
44
71
  if (e.shiftKey) goLast && goLast();else goNext && goNext();
45
72
  setTimeout(function () {
46
73
  var _inputRef$current;
@@ -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({
@@ -48,6 +48,16 @@ export var useSearchInput = function useSearchInput(state, dispatch, handlerRef)
48
48
  payload: value
49
49
  });
50
50
  }, [state.data]);
51
+ useEffect(function () {
52
+ if (state.searchText) {
53
+ dispatch({
54
+ type: 'changes',
55
+ payload: {
56
+ shouldSearchUpdate: true
57
+ }
58
+ });
59
+ }
60
+ }, [state.data]);
51
61
  useEffect(function () {
52
62
  var _state$searchResultLi2;
53
63
  if (!((_state$searchResultLi2 = state.searchResultList) !== null && _state$searchResultLi2 !== void 0 && _state$searchResultLi2.length)) {
@@ -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,7 @@ 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;
66
+ export declare const noramlizeSearch: (target: string) => string;
67
+ export declare const searchInclude: (search: string, compare: string) => boolean;
68
+ export declare const getTextWidth: (text: any) => number;
package/dist/core/util.js CHANGED
@@ -495,4 +495,39 @@ 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);
502
+ };
503
+ var punctuationMap = new Map([[",", ","], [":", ":"], [";", ";"]]);
504
+ export var noramlizeSearch = function noramlizeSearch(target) {
505
+ if (!target) {
506
+ return target;
507
+ }
508
+ var lower = target.toLowerCase();
509
+ // 逗号分号
510
+ punctuationMap.forEach(function (value, key) {
511
+ lower = lower.replace(new RegExp(key, "g"), value);
512
+ });
513
+ return lower;
514
+ };
515
+ export var searchInclude = function searchInclude(search, compare) {
516
+ if (!compare) {
517
+ return false;
518
+ }
519
+ var normalCompare = noramlizeSearch(compare);
520
+ return normalCompare.includes(search);
521
+ };
522
+ export var getTextWidth = function getTextWidth(text) {
523
+ // 创建隐藏的临时元素
524
+ var tempElement = document.createElement("span");
525
+ tempElement.style.visibility = "hidden";
526
+ tempElement.style.whiteSpace = "pre"; // 保持空格和换行的格式
527
+ tempElement.style.display = "inline-block";
528
+ tempElement.textContent = text;
529
+ document.body.appendChild(tempElement);
530
+ var width = tempElement.offsetWidth;
531
+ document.body.removeChild(tempElement);
532
+ return width;
498
533
  };
@@ -160,19 +160,22 @@ var columns = [{
160
160
  width: 200,
161
161
  dataIndex: 'address5',
162
162
  key: '6'
163
- }, {
164
- title: 'Column 7',
165
- width: 200,
166
- dataIndex: 'address6',
167
- key: '7',
168
- fixed: 'right'
169
- }, {
170
- title: 'Column 8',
171
- width: 200,
172
- dataIndex: 'address7',
173
- key: '8',
174
- fixed: 'right'
175
- }, {
163
+ },
164
+ // {
165
+ // title: 'Column 7',
166
+ // width: 200,
167
+ // dataIndex: 'address6',
168
+ // key: '7',
169
+ // fixed: 'right',
170
+ // },
171
+ // {
172
+ // title: 'Column 8',
173
+ // width: 200,
174
+ // dataIndex: 'address7',
175
+ // key: '8',
176
+ // fixed: 'right',
177
+ // },
178
+ {
176
179
  title: 'Action',
177
180
  align: SheetType.CellAlign.center,
178
181
  key: 'operation',
@@ -218,7 +221,6 @@ var App = function App() {
218
221
  setOptions = _useState4[1];
219
222
  var sheetInstance = useRef(null);
220
223
  var handleChange = useCallback(function (changes, extChange) {
221
- // console.log(extChange);
222
224
  var newState = cloneDeep(state);
223
225
  changes.forEach(function (change) {
224
226
  var row = change.row,
@@ -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;
@@ -195,6 +196,7 @@ export type CellProps = {
195
196
  };
196
197
  export type SearchState = {
197
198
  showSearch: boolean;
199
+ shouldSearchUpdate: boolean;
198
200
  searchText: string;
199
201
  searchTotal: number;
200
202
  searchCurrent: number;
@@ -212,7 +214,7 @@ export type UpdateStateType = {
212
214
  value?: string;
213
215
  };
214
216
  history: OperateHistory[];
215
- recoverHisotry: OperateHistory[];
217
+ recoverHistory: OperateHistory[];
216
218
  freePaste?: boolean;
217
219
  data: Cell[][];
218
220
  mouseDown: boolean;
@@ -233,7 +235,7 @@ export type UpdateStateType = {
233
235
  lastEditing: CellPosition & {
234
236
  confirm?: boolean;
235
237
  };
236
- cellChangeHandler: (cells: CellData[], additions?: CellData[]) => void;
238
+ cellChangeHandler: (cells: CellData[], additions: CellData[] | undefined, type: ChangeType) => void;
237
239
  fixedInfo: SheetType.FixedInfo[];
238
240
  } & SearchState;
239
241
  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-beta.2",
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
+ }