@zhenliang/sheet 0.1.7-4.beta.1 → 0.1.7-6.beta.1
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/core/reducers/sideEffectReducer.js +12 -11
- package/dist/core/reducers/stateReducer.js +10 -3
- package/dist/core/sheet/index.js +32 -1
- package/dist/core/sheet/useKeyBoardEvent.js +13 -6
- package/dist/core/sheet/useMouseEvent.js +3 -2
- package/dist/core/util.d.ts +1 -0
- package/dist/core/util.js +4 -0
- package/dist/example/antComponent.js +16 -14
- package/dist/hooks/useKeyboard.js +3 -2
- package/dist/type/sheet.d.ts +2 -2
- package/package.json +1 -1
|
@@ -361,7 +361,8 @@ 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
368
|
cellChangeHandler && cellChangeHandler(changes, undefined, 'Delete');
|
|
@@ -371,8 +372,8 @@ export var sideEffectReducer = {
|
|
|
371
372
|
start = _getState10.start,
|
|
372
373
|
end = _getState10.end,
|
|
373
374
|
history = _getState10.history,
|
|
374
|
-
_getState10$recoverHi = _getState10.
|
|
375
|
-
|
|
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,7 +387,7 @@ export var sideEffectReducer = {
|
|
|
386
387
|
type: 'changes',
|
|
387
388
|
payload: {
|
|
388
389
|
history: changeHistory,
|
|
389
|
-
|
|
390
|
+
recoverHistory: [].concat(_toConsumableArray(recoverHistory), [change])
|
|
390
391
|
}
|
|
391
392
|
});
|
|
392
393
|
return;
|
|
@@ -410,23 +411,23 @@ export var sideEffectReducer = {
|
|
|
410
411
|
end: end
|
|
411
412
|
},
|
|
412
413
|
history: changeHistory,
|
|
413
|
-
|
|
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.
|
|
421
|
-
|
|
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 (!(
|
|
429
|
-
var changeHistory = _toConsumableArray(
|
|
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
|
-
|
|
438
|
+
recoverHistory: changeHistory,
|
|
438
439
|
history: [].concat(_toConsumableArray(history), [change])
|
|
439
440
|
}
|
|
440
441
|
});
|
|
@@ -459,7 +460,7 @@ export var sideEffectReducer = {
|
|
|
459
460
|
end: end
|
|
460
461
|
},
|
|
461
462
|
history: [].concat(_toConsumableArray(history), [reverseChange]),
|
|
462
|
-
|
|
463
|
+
recoverHistory: changeHistory
|
|
463
464
|
}
|
|
464
465
|
});
|
|
465
466
|
}
|
|
@@ -145,11 +145,13 @@ export var stateReducer = _objectSpread({
|
|
|
145
145
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
146
146
|
editing: undefined,
|
|
147
147
|
lastEditing: state.editing,
|
|
148
|
-
history: history
|
|
148
|
+
history: history,
|
|
149
|
+
recoverHistory: []
|
|
149
150
|
});
|
|
150
151
|
}
|
|
151
152
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
152
|
-
history: history
|
|
153
|
+
history: history,
|
|
154
|
+
recoverHistory: []
|
|
153
155
|
});
|
|
154
156
|
},
|
|
155
157
|
popHistory: function popHistory(state) {
|
|
@@ -162,8 +164,13 @@ export var stateReducer = _objectSpread({
|
|
|
162
164
|
});
|
|
163
165
|
},
|
|
164
166
|
pushHistory: function pushHistory(state, payload) {
|
|
167
|
+
var newRecoverHistory = state.recoverHistory;
|
|
168
|
+
if (['DeleteRow', 'NewRow'].includes(payload.type)) {
|
|
169
|
+
newRecoverHistory = [];
|
|
170
|
+
}
|
|
165
171
|
return _objectSpread(_objectSpread({}, state), {}, {
|
|
166
|
-
history: [].concat(_toConsumableArray(state.history || []), [payload])
|
|
172
|
+
history: [].concat(_toConsumableArray(state.history || []), [payload]),
|
|
173
|
+
recoverHistory: newRecoverHistory
|
|
167
174
|
});
|
|
168
175
|
},
|
|
169
176
|
select: function select(state, payload) {
|
package/dist/core/sheet/index.js
CHANGED
|
@@ -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:
|
|
427
|
+
cell: menuCell,
|
|
397
428
|
showMenu: menu.showMenu,
|
|
398
429
|
contextMenu: ContextMenu,
|
|
399
430
|
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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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({
|
package/dist/core/util.d.ts
CHANGED
|
@@ -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
|
};
|
|
@@ -160,19 +160,22 @@ var columns = [{
|
|
|
160
160
|
width: 200,
|
|
161
161
|
dataIndex: 'address5',
|
|
162
162
|
key: '6'
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
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,
|
package/dist/type/sheet.d.ts
CHANGED
|
@@ -91,7 +91,7 @@ export type MenuRenderProps = {
|
|
|
91
91
|
top: number;
|
|
92
92
|
left: number;
|
|
93
93
|
};
|
|
94
|
-
cell?: CellPosition
|
|
94
|
+
cell?: CellPosition & Partial<Cell>;
|
|
95
95
|
onContextMenu?: (event: any) => void;
|
|
96
96
|
children?: ReactNode | ReactNode[];
|
|
97
97
|
target?: any;
|
|
@@ -213,7 +213,7 @@ export type UpdateStateType = {
|
|
|
213
213
|
value?: string;
|
|
214
214
|
};
|
|
215
215
|
history: OperateHistory[];
|
|
216
|
-
|
|
216
|
+
recoverHistory: OperateHistory[];
|
|
217
217
|
freePaste?: boolean;
|
|
218
218
|
data: Cell[][];
|
|
219
219
|
mouseDown: boolean;
|