@zhenliang/sheet 0.1.22 → 0.1.24
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/config.d.ts +13 -0
- package/dist/core/config.d.ts.map +1 -0
- package/dist/core/config.js +13 -0
- package/dist/core/editor/cascaderEditor/index.d.ts +5 -0
- package/dist/core/editor/cascaderEditor/index.d.ts.map +1 -0
- package/dist/core/editor/cascaderEditor/index.js +53 -0
- package/dist/core/editor/cascaderEditor/index.less +32 -0
- package/dist/core/editor/dateEditor/index.d.ts +5 -0
- package/dist/core/editor/dateEditor/index.d.ts.map +1 -0
- package/dist/core/editor/dateEditor/index.js +56 -0
- package/dist/core/editor/dateEditor/index.less +18 -0
- package/dist/core/editor/index.d.ts +4 -0
- package/dist/core/editor/index.d.ts.map +1 -0
- package/dist/core/editor/index.js +4 -0
- package/dist/core/editor/numberEditor/index.d.ts +8 -0
- package/dist/core/editor/numberEditor/index.d.ts.map +1 -0
- package/dist/core/editor/numberEditor/index.js +107 -0
- package/dist/core/editor/numberEditor/index.less +30 -0
- package/dist/core/editor/selectEditor/index.d.ts +6 -0
- package/dist/core/editor/selectEditor/index.d.ts.map +1 -0
- package/dist/core/editor/selectEditor/index.js +96 -0
- package/dist/core/editor/selectEditor/index.less +48 -0
- package/dist/core/reducers/index.d.ts +9 -0
- package/dist/core/reducers/index.d.ts.map +1 -0
- package/dist/core/reducers/index.js +38 -0
- package/dist/core/reducers/keyboardReducer.d.ts +2 -0
- package/dist/core/reducers/keyboardReducer.d.ts.map +1 -0
- package/dist/core/reducers/keyboardReducer.js +93 -0
- package/dist/core/reducers/mouseReducer.d.ts +2 -0
- package/dist/core/reducers/mouseReducer.d.ts.map +1 -0
- package/dist/core/reducers/mouseReducer.js +164 -0
- package/dist/core/reducers/sideEffectReducer.d.ts +4 -0
- package/dist/core/reducers/sideEffectReducer.d.ts.map +1 -0
- package/dist/core/reducers/sideEffectReducer.js +378 -0
- package/dist/core/reducers/stateReducer.d.ts +2 -0
- package/dist/core/reducers/stateReducer.d.ts.map +1 -0
- package/dist/core/reducers/stateReducer.js +174 -0
- package/dist/core/sheet/Cell.d.ts +4 -0
- package/dist/core/sheet/Cell.d.ts.map +1 -0
- package/dist/core/sheet/Cell.js +181 -0
- package/dist/core/sheet/DataEditor.d.ts +3 -0
- package/dist/core/sheet/DataEditor.d.ts.map +1 -0
- package/dist/core/sheet/DataEditor.js +24 -0
- package/dist/core/sheet/DefaultCell.d.ts +12 -0
- package/dist/core/sheet/DefaultCell.d.ts.map +1 -0
- package/dist/core/sheet/DefaultCell.js +31 -0
- package/dist/core/sheet/DefaultRow.d.ts +12 -0
- package/dist/core/sheet/DefaultRow.d.ts.map +1 -0
- package/dist/core/sheet/DefaultRow.js +28 -0
- package/dist/core/sheet/DefaultRowMapper.d.ts +8 -0
- package/dist/core/sheet/DefaultRowMapper.d.ts.map +1 -0
- package/dist/core/sheet/DefaultRowMapper.js +18 -0
- package/dist/core/sheet/DefaultShell.d.ts +8 -0
- package/dist/core/sheet/DefaultShell.d.ts.map +1 -0
- package/dist/core/sheet/DefaultShell.js +12 -0
- package/dist/core/sheet/Event.d.ts +5 -0
- package/dist/core/sheet/Event.d.ts.map +1 -0
- package/dist/core/sheet/Event.js +17 -0
- package/dist/core/sheet/ValueViewer.d.ts +3 -0
- package/dist/core/sheet/ValueViewer.d.ts.map +1 -0
- package/dist/core/sheet/ValueViewer.js +9 -0
- package/dist/core/sheet/index.d.ts +5 -0
- package/dist/core/sheet/index.d.ts.map +1 -0
- package/dist/core/sheet/index.js +262 -0
- package/dist/core/sheet/index.less +307 -0
- package/dist/core/sheet/useCellEvent.d.ts +3 -0
- package/dist/core/sheet/useCellEvent.d.ts.map +1 -0
- package/dist/core/sheet/useCellEvent.js +22 -0
- package/dist/core/sheet/useContextMenu.d.ts +21 -0
- package/dist/core/sheet/useContextMenu.d.ts.map +1 -0
- package/dist/core/sheet/useContextMenu.js +86 -0
- package/dist/core/sheet/useKeyBoardEvent.d.ts +3 -0
- package/dist/core/sheet/useKeyBoardEvent.d.ts.map +1 -0
- package/dist/core/sheet/useKeyBoardEvent.js +66 -0
- package/dist/core/sheet/useMouseEvent.d.ts +3 -0
- package/dist/core/sheet/useMouseEvent.d.ts.map +1 -0
- package/dist/core/sheet/useMouseEvent.js +298 -0
- package/dist/core/sheet/useSelectVisible.d.ts +2 -0
- package/dist/core/sheet/useSelectVisible.d.ts.map +1 -0
- package/dist/core/sheet/useSelectVisible.js +57 -0
- package/dist/core/sheet/useVirtualList.d.ts +7 -0
- package/dist/core/sheet/useVirtualList.d.ts.map +1 -0
- package/dist/core/sheet/useVirtualList.js +103 -0
- package/dist/core/sheet/var.less +41 -0
- package/dist/core/shell/draggableShell/index.d.ts +6 -0
- package/dist/core/shell/draggableShell/index.d.ts.map +1 -0
- package/dist/core/shell/draggableShell/index.js +197 -0
- package/dist/core/shell/draggableShell/index.less +16 -0
- package/dist/core/shell/tableShell.d.ts +6 -0
- package/dist/core/shell/tableShell.d.ts.map +1 -0
- package/dist/core/shell/tableShell.js +109 -0
- package/dist/core/table/events.d.ts +15 -0
- package/dist/core/table/events.d.ts.map +1 -0
- package/dist/core/table/events.js +95 -0
- package/dist/core/table/index.d.ts +4 -0
- package/dist/core/table/index.d.ts.map +1 -0
- package/dist/core/table/index.js +313 -0
- package/dist/core/table/useGroupConfig.d.ts +2 -0
- package/dist/core/table/useGroupConfig.d.ts.map +1 -0
- package/dist/core/table/useGroupConfig.js +65 -0
- package/dist/core/table/useRowSelection.d.ts +2 -0
- package/dist/core/table/useRowSelection.d.ts.map +1 -0
- package/dist/core/table/useRowSelection.js +24 -0
- package/dist/core/table/util.d.ts +8 -0
- package/dist/core/table/util.d.ts.map +1 -0
- package/dist/core/table/util.js +29 -0
- package/dist/core/util.d.ts +58 -0
- package/dist/core/util.d.ts.map +1 -0
- package/dist/core/util.js +457 -0
- package/dist/core/viewer/btnViewer/index.d.ts +2 -0
- package/dist/core/viewer/btnViewer/index.d.ts.map +1 -0
- package/dist/core/viewer/btnViewer/index.js +37 -0
- package/dist/core/viewer/cascaderViewer/index.d.ts +2 -0
- package/dist/core/viewer/cascaderViewer/index.d.ts.map +1 -0
- package/dist/core/viewer/cascaderViewer/index.js +16 -0
- package/dist/core/viewer/checkViewer/index.d.ts +2 -0
- package/dist/core/viewer/checkViewer/index.d.ts.map +1 -0
- package/dist/core/viewer/checkViewer/index.js +23 -0
- package/dist/core/viewer/editViewer/index.d.ts +2 -0
- package/dist/core/viewer/editViewer/index.d.ts.map +1 -0
- package/dist/core/viewer/editViewer/index.js +32 -0
- package/dist/core/viewer/groupViewer/index.d.ts +2 -0
- package/dist/core/viewer/groupViewer/index.d.ts.map +1 -0
- package/dist/core/viewer/groupViewer/index.js +38 -0
- package/dist/core/viewer/index.d.ts +7 -0
- package/dist/core/viewer/index.d.ts.map +1 -0
- package/dist/core/viewer/index.js +7 -0
- package/dist/core/viewer/selectorViewer/index.d.ts +2 -0
- package/dist/core/viewer/selectorViewer/index.d.ts.map +1 -0
- package/dist/core/viewer/selectorViewer/index.js +16 -0
- package/dist/core/viewer/switchViewer/index.d.ts +2 -0
- package/dist/core/viewer/switchViewer/index.d.ts.map +1 -0
- package/dist/core/viewer/switchViewer/index.js +22 -0
- package/dist/example/antComponent.d.ts +3 -0
- package/dist/example/antComponent.d.ts.map +1 -0
- package/dist/example/antComponent.js +313 -0
- package/dist/example/basic.d.ts +4 -0
- package/dist/example/basic.d.ts.map +1 -0
- package/dist/example/basic.js +121 -0
- package/dist/example/ellipsis.d.ts +3 -0
- package/dist/example/ellipsis.d.ts.map +1 -0
- package/dist/example/ellipsis.js +64 -0
- package/dist/example/fixed.d.ts +3 -0
- package/dist/example/fixed.d.ts.map +1 -0
- package/dist/example/fixed.js +89 -0
- package/dist/example/group.d.ts +3 -0
- package/dist/example/group.d.ts.map +1 -0
- package/dist/example/group.js +123 -0
- package/dist/example/index.less +5 -0
- package/dist/example/selection.d.ts +4 -0
- package/dist/example/selection.d.ts.map +1 -0
- package/dist/example/selection.js +86 -0
- package/dist/example/sheet.d.ts +4 -0
- package/dist/example/sheet.d.ts.map +1 -0
- package/dist/example/sheet.js +397 -0
- package/dist/example/valuationAnalyze.d.ts +3 -0
- package/dist/example/valuationAnalyze.d.ts.map +1 -0
- package/dist/example/valuationAnalyze.js +227 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.d.ts.map +1 -0
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/useEventBus.d.ts +4 -0
- package/dist/hooks/useEventBus.d.ts.map +1 -0
- package/dist/hooks/useEventBus.js +17 -0
- package/dist/hooks/useKeyboard.d.ts +18 -0
- package/dist/hooks/useKeyboard.d.ts.map +1 -0
- package/dist/hooks/useKeyboard.js +108 -0
- package/dist/hooks/useMiddlewareReducer.d.ts +12 -0
- package/dist/hooks/useMiddlewareReducer.d.ts.map +1 -0
- package/dist/hooks/useMiddlewareReducer.js +47 -0
- package/dist/hooks/useMouse.d.ts +11 -0
- package/dist/hooks/useMouse.d.ts.map +1 -0
- package/dist/hooks/useMouse.js +68 -0
- package/dist/hooks/useSetState.d.ts +2 -0
- package/dist/hooks/useSetState.d.ts.map +1 -0
- package/dist/hooks/useSetState.js +27 -0
- package/dist/hooks/useSheetEvent.d.ts +5 -0
- package/dist/hooks/useSheetEvent.d.ts.map +1 -0
- package/dist/hooks/useSheetEvent.js +5 -0
- package/dist/hooks/useWidthConfig.d.ts +4 -0
- package/dist/hooks/useWidthConfig.d.ts.map +1 -0
- package/dist/hooks/useWidthConfig.js +5 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +8 -0
- package/dist/standardUtils/index.d.ts +9 -0
- package/dist/standardUtils/index.d.ts.map +1 -0
- package/dist/standardUtils/index.js +32 -0
- package/dist/type/index.d.ts +2 -0
- package/dist/type/index.d.ts.map +1 -0
- package/dist/type/index.js +4 -0
- package/dist/type/sheet.d.ts +205 -0
- package/dist/type/sheet.d.ts.map +1 -0
- package/dist/type/sheet.js +9 -0
- package/dist/type/sheetTable.d.ts +89 -0
- package/dist/type/sheetTable.d.ts.map +1 -0
- package/dist/type/sheetTable.js +1 -0
- package/dist/typings/index.d.ts +1 -0
- package/package.json +1 -1
- package/changes.md +0 -45
|
@@ -0,0 +1,93 @@
|
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
import { isNil } from 'lodash';
|
|
8
|
+
import { getNextVisibleRow, groupConfigToGroupMap } from "../util";
|
|
9
|
+
export var keyboardReducer = {
|
|
10
|
+
move: function move(state, payload) {
|
|
11
|
+
var _state$start, _state$start2;
|
|
12
|
+
var _ref = payload,
|
|
13
|
+
row = _ref.row,
|
|
14
|
+
col = _ref.col;
|
|
15
|
+
var groupConfig = state.groupConfig,
|
|
16
|
+
_state$data = state.data,
|
|
17
|
+
data = _state$data === void 0 ? [] : _state$data;
|
|
18
|
+
var newRow = (((_state$start = state.start) === null || _state$start === void 0 ? void 0 : _state$start.row) || 0) + row;
|
|
19
|
+
if (groupConfig) {
|
|
20
|
+
newRow = getNextVisibleRow(newRow, data.length, groupConfigToGroupMap(groupConfig), row < 0 ? -1 : 1);
|
|
21
|
+
}
|
|
22
|
+
var currentPos = {
|
|
23
|
+
row: newRow,
|
|
24
|
+
col: (((_state$start2 = state.start) === null || _state$start2 === void 0 ? void 0 : _state$start2.col) || 0) + col
|
|
25
|
+
};
|
|
26
|
+
var lastEditing = state.lastEditing;
|
|
27
|
+
if (state.editing) {
|
|
28
|
+
lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
|
|
29
|
+
confirm: true
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
if (isNil(currentPos.row)) {
|
|
33
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
34
|
+
start: undefined,
|
|
35
|
+
end: undefined,
|
|
36
|
+
lastSelected: {
|
|
37
|
+
start: state.start,
|
|
38
|
+
end: state.end
|
|
39
|
+
},
|
|
40
|
+
editing: undefined,
|
|
41
|
+
lastEditing: lastEditing
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
45
|
+
start: currentPos,
|
|
46
|
+
end: currentPos,
|
|
47
|
+
lastSelected: {
|
|
48
|
+
start: state.start,
|
|
49
|
+
end: state.end
|
|
50
|
+
},
|
|
51
|
+
editing: undefined,
|
|
52
|
+
lastEditing: lastEditing
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
escape: function escape(state) {
|
|
56
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
57
|
+
editing: undefined,
|
|
58
|
+
lastEditing: state.editing
|
|
59
|
+
});
|
|
60
|
+
},
|
|
61
|
+
reverse: function reverse(state) {
|
|
62
|
+
return state;
|
|
63
|
+
},
|
|
64
|
+
delete: function _delete(state) {
|
|
65
|
+
return state;
|
|
66
|
+
},
|
|
67
|
+
enter: function enter(state, payload) {
|
|
68
|
+
var _data$start$row;
|
|
69
|
+
var start = state.start,
|
|
70
|
+
end = state.end,
|
|
71
|
+
editing = state.editing,
|
|
72
|
+
data = state.data;
|
|
73
|
+
if (!start || !end || data !== null && data !== void 0 && (_data$start$row = data[start.row]) !== null && _data$start$row !== void 0 && _data$start$row[start.col].readonly) {
|
|
74
|
+
return state;
|
|
75
|
+
}
|
|
76
|
+
if (!editing) {
|
|
77
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
78
|
+
end: start,
|
|
79
|
+
editing: _objectSpread(_objectSpread({}, start), {}, {
|
|
80
|
+
value: payload
|
|
81
|
+
})
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
return keyboardReducer.move(state, {
|
|
85
|
+
row: 1,
|
|
86
|
+
col: 0
|
|
87
|
+
});
|
|
88
|
+
},
|
|
89
|
+
otherInput: function otherInput(state, payload) {
|
|
90
|
+
if (state.editing) return state;
|
|
91
|
+
return keyboardReducer.enter(state, payload);
|
|
92
|
+
}
|
|
93
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mouseReducer.d.ts","sourceRoot":"","sources":["mouseReducer.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAE,MAAM,GAAG,CAAC;AAElC,eAAO,MAAM,YAAY,EAAE,MAAM,CAAC,MAAM,EAAE,aAAa,CA+ItD,CAAC"}
|
|
@@ -0,0 +1,164 @@
|
|
|
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(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
6
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
7
|
+
export var mouseReducer = {
|
|
8
|
+
mouseDown: function mouseDown(state, payload) {
|
|
9
|
+
var _ref = payload,
|
|
10
|
+
_ref$pos = _ref.pos,
|
|
11
|
+
row = _ref$pos.row,
|
|
12
|
+
col = _ref$pos.col,
|
|
13
|
+
shiftKey = _ref.shiftKey;
|
|
14
|
+
var data = state.data,
|
|
15
|
+
start = state.start,
|
|
16
|
+
end = state.end;
|
|
17
|
+
if (data !== null && data !== void 0 && data[row][col].fixed) {
|
|
18
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
19
|
+
start: undefined,
|
|
20
|
+
end: undefined,
|
|
21
|
+
lastSelected: {
|
|
22
|
+
start: start,
|
|
23
|
+
end: end
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
if (shiftKey) {
|
|
28
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
29
|
+
mouseDown: true,
|
|
30
|
+
editing: undefined,
|
|
31
|
+
lastEditing: _objectSpread(_objectSpread({}, state.editing), {}, {
|
|
32
|
+
confirm: true
|
|
33
|
+
}),
|
|
34
|
+
start: start ? start : {
|
|
35
|
+
row: row,
|
|
36
|
+
col: col
|
|
37
|
+
},
|
|
38
|
+
end: {
|
|
39
|
+
row: row,
|
|
40
|
+
col: col
|
|
41
|
+
},
|
|
42
|
+
lastSelected: {
|
|
43
|
+
start: start,
|
|
44
|
+
end: end
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
49
|
+
mouseDown: true,
|
|
50
|
+
editing: undefined,
|
|
51
|
+
lastEditing: _objectSpread(_objectSpread({}, state.editing), {}, {
|
|
52
|
+
confirm: true
|
|
53
|
+
}),
|
|
54
|
+
start: {
|
|
55
|
+
row: row,
|
|
56
|
+
col: col
|
|
57
|
+
},
|
|
58
|
+
end: {
|
|
59
|
+
row: row,
|
|
60
|
+
col: col
|
|
61
|
+
},
|
|
62
|
+
lastSelected: {
|
|
63
|
+
start: start,
|
|
64
|
+
end: end
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
},
|
|
68
|
+
mouseOver: function mouseOver(state, payload) {
|
|
69
|
+
var _ref2 = payload,
|
|
70
|
+
row = _ref2.row,
|
|
71
|
+
col = _ref2.col;
|
|
72
|
+
var data = state.data;
|
|
73
|
+
if (state.mouseDown === false || data !== null && data !== void 0 && data[row][col].fixed) return state;
|
|
74
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
75
|
+
end: {
|
|
76
|
+
row: row,
|
|
77
|
+
col: col
|
|
78
|
+
},
|
|
79
|
+
lastSelected: {
|
|
80
|
+
start: state.start,
|
|
81
|
+
end: state.end
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
},
|
|
85
|
+
mouseUp: function mouseUp(state, payload) {
|
|
86
|
+
var _ref3 = payload,
|
|
87
|
+
row = _ref3.row,
|
|
88
|
+
col = _ref3.col;
|
|
89
|
+
var data = state.data;
|
|
90
|
+
if (state.mouseDown === false || data !== null && data !== void 0 && data[row][col].fixed) return state;
|
|
91
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
92
|
+
mouseDown: false,
|
|
93
|
+
end: {
|
|
94
|
+
row: row,
|
|
95
|
+
col: col
|
|
96
|
+
},
|
|
97
|
+
lastSelected: {
|
|
98
|
+
start: state.start,
|
|
99
|
+
end: state.end
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
loseFocus: function loseFocus(state) {
|
|
104
|
+
var lastEditing = state.lastEditing;
|
|
105
|
+
if (state.editing) {
|
|
106
|
+
lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
|
|
107
|
+
confirm: true
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
111
|
+
start: undefined,
|
|
112
|
+
end: undefined,
|
|
113
|
+
editing: undefined,
|
|
114
|
+
lastEditing: lastEditing,
|
|
115
|
+
lastSelected: {
|
|
116
|
+
start: state.start,
|
|
117
|
+
end: state.end
|
|
118
|
+
}
|
|
119
|
+
});
|
|
120
|
+
},
|
|
121
|
+
doubleClick: function doubleClick(state, payload) {
|
|
122
|
+
var _data$row$col;
|
|
123
|
+
var _ref4 = payload,
|
|
124
|
+
row = _ref4.row,
|
|
125
|
+
col = _ref4.col;
|
|
126
|
+
var data = state.data;
|
|
127
|
+
if (data !== null && data !== void 0 && (_data$row$col = data[row][col]) !== null && _data$row$col !== void 0 && _data$row$col.readonly) {
|
|
128
|
+
return state;
|
|
129
|
+
}
|
|
130
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
131
|
+
mouseDown: false,
|
|
132
|
+
editing: {
|
|
133
|
+
row: row,
|
|
134
|
+
col: col
|
|
135
|
+
},
|
|
136
|
+
start: {
|
|
137
|
+
row: row,
|
|
138
|
+
col: col
|
|
139
|
+
},
|
|
140
|
+
end: {
|
|
141
|
+
row: row,
|
|
142
|
+
col: col
|
|
143
|
+
},
|
|
144
|
+
lastSelected: {
|
|
145
|
+
start: state.start,
|
|
146
|
+
end: state.end
|
|
147
|
+
},
|
|
148
|
+
lastEditing: state.editing
|
|
149
|
+
});
|
|
150
|
+
},
|
|
151
|
+
mouseLeaveInterval: function mouseLeaveInterval(state, payload) {
|
|
152
|
+
var _data$, _end$col;
|
|
153
|
+
var _ref5 = payload,
|
|
154
|
+
end = _ref5.end;
|
|
155
|
+
var data = state.data;
|
|
156
|
+
// fixed 列不选中
|
|
157
|
+
if (data !== null && data !== void 0 && (_data$ = data[0]) !== null && _data$ !== void 0 && (_data$ = _data$[(_end$col = end.col) !== null && _end$col !== void 0 ? _end$col : 0]) !== null && _data$ !== void 0 && _data$.fixed) {
|
|
158
|
+
return state;
|
|
159
|
+
}
|
|
160
|
+
return _objectSpread(_objectSpread({}, state), {}, {
|
|
161
|
+
end: end
|
|
162
|
+
});
|
|
163
|
+
}
|
|
164
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { SheetType } from "../../type";
|
|
2
|
+
import { FunctionAction, NormalAction } from '../../hooks';
|
|
3
|
+
export type asyncActionType = (dispatch: (action: NormalAction | FunctionAction) => void, getState: () => SheetType.UpdateStateType) => void;
|
|
4
|
+
export declare const sideEffectReducer: Record<string, asyncActionType>;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"sideEffectReducer.d.ts","sourceRoot":"","sources":["sideEffectReducer.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,mBAA8B;AAEvD,OAAO,EAAE,cAAc,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAW3D,MAAM,MAAM,eAAe,GAAG,CAC5B,QAAQ,EAAE,CAAC,MAAM,EAAE,YAAY,GAAG,cAAc,KAAK,IAAI,EACzD,QAAQ,EAAE,MAAM,SAAS,CAAC,eAAe,KACtC,IAAI,CAAC;AAEV,eAAO,MAAM,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CA6T7D,CAAC"}
|
|
@@ -0,0 +1,378 @@
|
|
|
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 _regeneratorRuntime() { "use strict"; /*! regenerator-runtime -- Copyright (c) 2014-present, Facebook, Inc. -- license (MIT): https://github.com/facebook/regenerator/blob/main/LICENSE */ _regeneratorRuntime = function _regeneratorRuntime() { return e; }; var t, e = {}, r = Object.prototype, n = r.hasOwnProperty, o = Object.defineProperty || function (t, e, r) { t[e] = r.value; }, i = "function" == typeof Symbol ? Symbol : {}, a = i.iterator || "@@iterator", c = i.asyncIterator || "@@asyncIterator", u = i.toStringTag || "@@toStringTag"; function define(t, e, r) { return Object.defineProperty(t, e, { value: r, enumerable: !0, configurable: !0, writable: !0 }), t[e]; } try { define({}, ""); } catch (t) { define = function define(t, e, r) { return t[e] = r; }; } function wrap(t, e, r, n) { var i = e && e.prototype instanceof Generator ? e : Generator, a = Object.create(i.prototype), c = new Context(n || []); return o(a, "_invoke", { value: makeInvokeMethod(t, r, c) }), a; } function tryCatch(t, e, r) { try { return { type: "normal", arg: t.call(e, r) }; } catch (t) { return { type: "throw", arg: t }; } } e.wrap = wrap; var h = "suspendedStart", l = "suspendedYield", f = "executing", s = "completed", y = {}; function Generator() {} function GeneratorFunction() {} function GeneratorFunctionPrototype() {} var p = {}; define(p, a, function () { return this; }); var d = Object.getPrototypeOf, v = d && d(d(values([]))); v && v !== r && n.call(v, a) && (p = v); var g = GeneratorFunctionPrototype.prototype = Generator.prototype = Object.create(p); function defineIteratorMethods(t) { ["next", "throw", "return"].forEach(function (e) { define(t, e, function (t) { return this._invoke(e, t); }); }); } function AsyncIterator(t, e) { function invoke(r, o, i, a) { var c = tryCatch(t[r], t, o); if ("throw" !== c.type) { var u = c.arg, h = u.value; return h && "object" == _typeof(h) && n.call(h, "__await") ? e.resolve(h.__await).then(function (t) { invoke("next", t, i, a); }, function (t) { invoke("throw", t, i, a); }) : e.resolve(h).then(function (t) { u.value = t, i(u); }, function (t) { return invoke("throw", t, i, a); }); } a(c.arg); } var r; o(this, "_invoke", { value: function value(t, n) { function callInvokeWithMethodAndArg() { return new e(function (e, r) { invoke(t, n, e, r); }); } return r = r ? r.then(callInvokeWithMethodAndArg, callInvokeWithMethodAndArg) : callInvokeWithMethodAndArg(); } }); } function makeInvokeMethod(e, r, n) { var o = h; return function (i, a) { if (o === f) throw new Error("Generator is already running"); if (o === s) { if ("throw" === i) throw a; return { value: t, done: !0 }; } for (n.method = i, n.arg = a;;) { var c = n.delegate; if (c) { var u = maybeInvokeDelegate(c, n); if (u) { if (u === y) continue; return u; } } if ("next" === n.method) n.sent = n._sent = n.arg;else if ("throw" === n.method) { if (o === h) throw o = s, n.arg; n.dispatchException(n.arg); } else "return" === n.method && n.abrupt("return", n.arg); o = f; var p = tryCatch(e, r, n); if ("normal" === p.type) { if (o = n.done ? s : l, p.arg === y) continue; return { value: p.arg, done: n.done }; } "throw" === p.type && (o = s, n.method = "throw", n.arg = p.arg); } }; } function maybeInvokeDelegate(e, r) { var n = r.method, o = e.iterator[n]; if (o === t) return r.delegate = null, "throw" === n && e.iterator.return && (r.method = "return", r.arg = t, maybeInvokeDelegate(e, r), "throw" === r.method) || "return" !== n && (r.method = "throw", r.arg = new TypeError("The iterator does not provide a '" + n + "' method")), y; var i = tryCatch(o, e.iterator, r.arg); if ("throw" === i.type) return r.method = "throw", r.arg = i.arg, r.delegate = null, y; var a = i.arg; return a ? a.done ? (r[e.resultName] = a.value, r.next = e.nextLoc, "return" !== r.method && (r.method = "next", r.arg = t), r.delegate = null, y) : a : (r.method = "throw", r.arg = new TypeError("iterator result is not an object"), r.delegate = null, y); } function pushTryEntry(t) { var e = { tryLoc: t[0] }; 1 in t && (e.catchLoc = t[1]), 2 in t && (e.finallyLoc = t[2], e.afterLoc = t[3]), this.tryEntries.push(e); } function resetTryEntry(t) { var e = t.completion || {}; e.type = "normal", delete e.arg, t.completion = e; } function Context(t) { this.tryEntries = [{ tryLoc: "root" }], t.forEach(pushTryEntry, this), this.reset(!0); } function values(e) { if (e || "" === e) { var r = e[a]; if (r) return r.call(e); if ("function" == typeof e.next) return e; if (!isNaN(e.length)) { var o = -1, i = function next() { for (; ++o < e.length;) if (n.call(e, o)) return next.value = e[o], next.done = !1, next; return next.value = t, next.done = !0, next; }; return i.next = i; } } throw new TypeError(_typeof(e) + " is not iterable"); } return GeneratorFunction.prototype = GeneratorFunctionPrototype, o(g, "constructor", { value: GeneratorFunctionPrototype, configurable: !0 }), o(GeneratorFunctionPrototype, "constructor", { value: GeneratorFunction, configurable: !0 }), GeneratorFunction.displayName = define(GeneratorFunctionPrototype, u, "GeneratorFunction"), e.isGeneratorFunction = function (t) { var e = "function" == typeof t && t.constructor; return !!e && (e === GeneratorFunction || "GeneratorFunction" === (e.displayName || e.name)); }, e.mark = function (t) { return Object.setPrototypeOf ? Object.setPrototypeOf(t, GeneratorFunctionPrototype) : (t.__proto__ = GeneratorFunctionPrototype, define(t, u, "GeneratorFunction")), t.prototype = Object.create(g), t; }, e.awrap = function (t) { return { __await: t }; }, defineIteratorMethods(AsyncIterator.prototype), define(AsyncIterator.prototype, c, function () { return this; }), e.AsyncIterator = AsyncIterator, e.async = function (t, r, n, o, i) { void 0 === i && (i = Promise); var a = new AsyncIterator(wrap(t, r, n, o), i); return e.isGeneratorFunction(r) ? a : a.next().then(function (t) { return t.done ? t.value : a.next(); }); }, defineIteratorMethods(g), define(g, u, "Generator"), define(g, a, function () { return this; }), define(g, "toString", function () { return "[object Generator]"; }), e.keys = function (t) { var e = Object(t), r = []; for (var n in e) r.push(n); return r.reverse(), function next() { for (; r.length;) { var t = r.pop(); if (t in e) return next.value = t, next.done = !1, next; } return next.done = !0, next; }; }, e.values = values, Context.prototype = { constructor: Context, reset: function reset(e) { if (this.prev = 0, this.next = 0, this.sent = this._sent = t, this.done = !1, this.delegate = null, this.method = "next", this.arg = t, this.tryEntries.forEach(resetTryEntry), !e) for (var r in this) "t" === r.charAt(0) && n.call(this, r) && !isNaN(+r.slice(1)) && (this[r] = t); }, stop: function stop() { this.done = !0; var t = this.tryEntries[0].completion; if ("throw" === t.type) throw t.arg; return this.rval; }, dispatchException: function dispatchException(e) { if (this.done) throw e; var r = this; function handle(n, o) { return a.type = "throw", a.arg = e, r.next = n, o && (r.method = "next", r.arg = t), !!o; } for (var o = this.tryEntries.length - 1; o >= 0; --o) { var i = this.tryEntries[o], a = i.completion; if ("root" === i.tryLoc) return handle("end"); if (i.tryLoc <= this.prev) { var c = n.call(i, "catchLoc"), u = n.call(i, "finallyLoc"); if (c && u) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } else if (c) { if (this.prev < i.catchLoc) return handle(i.catchLoc, !0); } else { if (!u) throw new Error("try statement without catch or finally"); if (this.prev < i.finallyLoc) return handle(i.finallyLoc); } } } }, abrupt: function abrupt(t, e) { for (var r = this.tryEntries.length - 1; r >= 0; --r) { var o = this.tryEntries[r]; if (o.tryLoc <= this.prev && n.call(o, "finallyLoc") && this.prev < o.finallyLoc) { var i = o; break; } } i && ("break" === t || "continue" === t) && i.tryLoc <= e && e <= i.finallyLoc && (i = null); var a = i ? i.completion : {}; return a.type = t, a.arg = e, i ? (this.method = "next", this.next = i.finallyLoc, y) : this.complete(a); }, complete: function complete(t, e) { if ("throw" === t.type) throw t.arg; return "break" === t.type || "continue" === t.type ? this.next = t.arg : "return" === t.type ? (this.rval = this.arg = t.arg, this.method = "return", this.next = "end") : "normal" === t.type && e && (this.next = e), y; }, finish: function finish(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.finallyLoc === t) return this.complete(r.completion, r.afterLoc), resetTryEntry(r), y; } }, catch: function _catch(t) { for (var e = this.tryEntries.length - 1; e >= 0; --e) { var r = this.tryEntries[e]; if (r.tryLoc === t) { var n = r.completion; if ("throw" === n.type) { var o = n.arg; resetTryEntry(r); } return o; } } throw new Error("illegal catch attempt"); }, delegateYield: function delegateYield(e, r, n) { return this.delegate = { iterator: values(e), resultName: r, nextLoc: n }, "next" === this.method && (this.arg = t), y; } }, e; }
|
|
3
|
+
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
|
4
|
+
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
|
5
|
+
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); }
|
|
6
|
+
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
|
7
|
+
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
|
8
|
+
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; }
|
|
9
|
+
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; }
|
|
10
|
+
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; }
|
|
11
|
+
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; }
|
|
12
|
+
function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
|
|
13
|
+
function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
|
|
14
|
+
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } }
|
|
15
|
+
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; }
|
|
16
|
+
import { head, isNil, last, pick } from 'lodash';
|
|
17
|
+
import { clipboardDataToString, flatRowCol, flatRowColIndex, formatDataToCell, getRowColConfig, groupConfigToGroupMap, stringToClipboardData } from "../util";
|
|
18
|
+
export var sideEffectReducer = {
|
|
19
|
+
init: function init(dispatch, getState) {
|
|
20
|
+
var _getState = getState(),
|
|
21
|
+
eventBus = _getState.eventBus;
|
|
22
|
+
eventBus.on('cell-change', function (cell) {
|
|
23
|
+
dispatch(function () {
|
|
24
|
+
var _getState2 = getState(),
|
|
25
|
+
cellChangeHandler = _getState2.cellChangeHandler;
|
|
26
|
+
dispatch({
|
|
27
|
+
type: 'editFinish',
|
|
28
|
+
payload: {
|
|
29
|
+
cell: cell
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
cellChangeHandler && cellChangeHandler([cell]);
|
|
33
|
+
});
|
|
34
|
+
});
|
|
35
|
+
eventBus.on('cell-create', function (_ref) {
|
|
36
|
+
var row = _ref.row,
|
|
37
|
+
col = _ref.col;
|
|
38
|
+
var _getState3 = getState(),
|
|
39
|
+
start = _getState3.start,
|
|
40
|
+
end = _getState3.end;
|
|
41
|
+
var _getRowColConfig = getRowColConfig(start, end),
|
|
42
|
+
startRow = _getRowColConfig.startRow,
|
|
43
|
+
endRow = _getRowColConfig.endRow,
|
|
44
|
+
startCol = _getRowColConfig.startCol,
|
|
45
|
+
endCol = _getRowColConfig.endCol;
|
|
46
|
+
var isMultiSelected = startRow !== endRow && startCol !== endCol;
|
|
47
|
+
var isSelected = row >= startRow && row <= endRow && col >= startCol && col <= endCol;
|
|
48
|
+
if (isSelected) {
|
|
49
|
+
eventBus.emit("cell-".concat(row, "-").concat(col, "-change"), {
|
|
50
|
+
selected: true,
|
|
51
|
+
selectedInfo: {
|
|
52
|
+
isStart: row === (start === null || start === void 0 ? void 0 : start.row) && col === start.col && isMultiSelected,
|
|
53
|
+
isTop: row === startRow,
|
|
54
|
+
isBottom: row === endRow,
|
|
55
|
+
isLeft: col === startCol,
|
|
56
|
+
isRight: col === endCol
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
},
|
|
62
|
+
destroy: function destroy(d, getState) {
|
|
63
|
+
var _getState4 = getState(),
|
|
64
|
+
eventBus = _getState4.eventBus;
|
|
65
|
+
eventBus === null || eventBus === void 0 || eventBus.removeAllListeners();
|
|
66
|
+
},
|
|
67
|
+
emitSelectChange: function emitSelectChange(d, getState) {
|
|
68
|
+
var _getState5 = getState(),
|
|
69
|
+
eventBus = _getState5.eventBus,
|
|
70
|
+
lastSelected = _getState5.lastSelected,
|
|
71
|
+
start = _getState5.start,
|
|
72
|
+
end = _getState5.end;
|
|
73
|
+
var _getRowColConfig2 = getRowColConfig(start, end),
|
|
74
|
+
startRow = _getRowColConfig2.startRow,
|
|
75
|
+
endRow = _getRowColConfig2.endRow,
|
|
76
|
+
startCol = _getRowColConfig2.startCol,
|
|
77
|
+
endCol = _getRowColConfig2.endCol;
|
|
78
|
+
var selectedCellIndex = flatRowColIndex(start, end);
|
|
79
|
+
var selectedCells = flatRowCol(start, end);
|
|
80
|
+
var cancelCells = flatRowCol(lastSelected === null || lastSelected === void 0 ? void 0 : lastSelected.start, lastSelected === null || lastSelected === void 0 ? void 0 : lastSelected.end);
|
|
81
|
+
cancelCells.forEach(function (cell) {
|
|
82
|
+
if (selectedCells.includes(cell)) return;
|
|
83
|
+
eventBus.emit("cell-".concat(cell, "-change"), {
|
|
84
|
+
selected: false,
|
|
85
|
+
selectedInfo: undefined
|
|
86
|
+
});
|
|
87
|
+
});
|
|
88
|
+
selectedCellIndex.forEach(function (_ref2) {
|
|
89
|
+
var row = _ref2.row,
|
|
90
|
+
col = _ref2.col;
|
|
91
|
+
eventBus.emit("cell-".concat(row, "-").concat(col, "-change"), {
|
|
92
|
+
selected: true,
|
|
93
|
+
selectedInfo: {
|
|
94
|
+
isStart: row === (start === null || start === void 0 ? void 0 : start.row) && col === start.col && selectedCellIndex.length !== 1,
|
|
95
|
+
isTop: row === startRow,
|
|
96
|
+
isBottom: row === endRow,
|
|
97
|
+
isLeft: col === startCol,
|
|
98
|
+
isRight: col === endCol
|
|
99
|
+
}
|
|
100
|
+
});
|
|
101
|
+
});
|
|
102
|
+
},
|
|
103
|
+
emitEditChange: function emitEditChange(d, getState) {
|
|
104
|
+
var _getState6 = getState(),
|
|
105
|
+
editing = _getState6.editing,
|
|
106
|
+
lastEditing = _getState6.lastEditing,
|
|
107
|
+
eventBus = _getState6.eventBus;
|
|
108
|
+
if (!isNil(editing === null || editing === void 0 ? void 0 : editing.col) && !isNil(editing === null || editing === void 0 ? void 0 : editing.row)) {
|
|
109
|
+
eventBus.emit("cell-".concat(editing.row, "-").concat(editing.col, "-change"), {
|
|
110
|
+
editing: true,
|
|
111
|
+
value: editing.value
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
if (!isNil(lastEditing === null || lastEditing === void 0 ? void 0 : lastEditing.col) && !isNil(lastEditing === null || lastEditing === void 0 ? void 0 : lastEditing.row)) {
|
|
115
|
+
//清空上一个编辑cell的状态
|
|
116
|
+
eventBus.emit("cell-".concat(lastEditing.row, "-").concat(lastEditing.col, "-change"), {
|
|
117
|
+
editing: false,
|
|
118
|
+
confirm: lastEditing === null || lastEditing === void 0 ? void 0 : lastEditing.confirm
|
|
119
|
+
});
|
|
120
|
+
d({
|
|
121
|
+
type: 'changes',
|
|
122
|
+
payload: {
|
|
123
|
+
lastEditing: undefined
|
|
124
|
+
}
|
|
125
|
+
});
|
|
126
|
+
}
|
|
127
|
+
},
|
|
128
|
+
copy: function copy(d, getState) {
|
|
129
|
+
var _getState7 = getState(),
|
|
130
|
+
start = _getState7.start,
|
|
131
|
+
end = _getState7.end,
|
|
132
|
+
data = _getState7.data,
|
|
133
|
+
groupConfig = _getState7.groupConfig;
|
|
134
|
+
if (!start || !end) {
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
var cellIndex = flatRowColIndex(start, end);
|
|
138
|
+
var groupMap = groupConfigToGroupMap(groupConfig);
|
|
139
|
+
var count = 0;
|
|
140
|
+
var copyData = cellIndex.reduce(function (left, _ref3) {
|
|
141
|
+
var _ref3$row = _ref3.row,
|
|
142
|
+
row = _ref3$row === void 0 ? 0 : _ref3$row,
|
|
143
|
+
_ref3$col = _ref3.col,
|
|
144
|
+
col = _ref3$col === void 0 ? 0 : _ref3$col;
|
|
145
|
+
var currentRow = left.currentRow,
|
|
146
|
+
value = left.value;
|
|
147
|
+
if (groupMap.get(row)) {
|
|
148
|
+
var _groupMap$get, _groupMap$get2;
|
|
149
|
+
// 如果是分组的子行并且是合并的状态
|
|
150
|
+
if (!((_groupMap$get = groupMap.get(row)) !== null && _groupMap$get !== void 0 && _groupMap$get.isStart) && !((_groupMap$get2 = groupMap.get(row)) !== null && _groupMap$get2 !== void 0 && _groupMap$get2.isOpen)) {
|
|
151
|
+
return {
|
|
152
|
+
currentRow: row,
|
|
153
|
+
value: "".concat(value)
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
count++;
|
|
158
|
+
|
|
159
|
+
// 复制到剪贴板的时候执行 formatter
|
|
160
|
+
var _data$row$col = data[row][col],
|
|
161
|
+
dataValue = _data$row$col.value,
|
|
162
|
+
dataEditor = _data$row$col.dataEditor,
|
|
163
|
+
record = _data$row$col.record;
|
|
164
|
+
var _ref4 = dataEditor || {},
|
|
165
|
+
dataFormatter = _ref4.formatter;
|
|
166
|
+
var formattedValue = dataFormatter ? dataFormatter(dataValue, record) : dataValue;
|
|
167
|
+
if (isNil(dataValue)) {
|
|
168
|
+
formattedValue = ' ';
|
|
169
|
+
}
|
|
170
|
+
if (currentRow === -1) {
|
|
171
|
+
return {
|
|
172
|
+
currentRow: row,
|
|
173
|
+
value: formattedValue
|
|
174
|
+
};
|
|
175
|
+
}
|
|
176
|
+
var currentValue = "".concat(value).concat(currentRow === row ? '\t' : '\n', " ").concat(formattedValue);
|
|
177
|
+
return {
|
|
178
|
+
currentRow: row,
|
|
179
|
+
value: currentValue
|
|
180
|
+
};
|
|
181
|
+
}, {
|
|
182
|
+
currentRow: -1,
|
|
183
|
+
value: ''
|
|
184
|
+
});
|
|
185
|
+
var text = copyData.value;
|
|
186
|
+
stringToClipboardData(text, count);
|
|
187
|
+
},
|
|
188
|
+
paste: function paste(dispatch, getState) {
|
|
189
|
+
return _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
|
|
190
|
+
var _extChanges$;
|
|
191
|
+
var _getState8, start, end, cellChangeHandler, history, _getState8$freePaste, freePaste, data, groupConfig, pasteData, changeInfo, changes, extChanges, legalChanges, lastRow, lastIndex, legalExtChanges, newHistory;
|
|
192
|
+
return _regeneratorRuntime().wrap(function _callee$(_context) {
|
|
193
|
+
while (1) switch (_context.prev = _context.next) {
|
|
194
|
+
case 0:
|
|
195
|
+
_getState8 = getState(), start = _getState8.start, end = _getState8.end, cellChangeHandler = _getState8.cellChangeHandler, history = _getState8.history, _getState8$freePaste = _getState8.freePaste, freePaste = _getState8$freePaste === void 0 ? false : _getState8$freePaste, data = _getState8.data, groupConfig = _getState8.groupConfig;
|
|
196
|
+
if (!(!start || !end)) {
|
|
197
|
+
_context.next = 3;
|
|
198
|
+
break;
|
|
199
|
+
}
|
|
200
|
+
return _context.abrupt("return");
|
|
201
|
+
case 3:
|
|
202
|
+
_context.next = 5;
|
|
203
|
+
return clipboardDataToString();
|
|
204
|
+
case 5:
|
|
205
|
+
pasteData = _context.sent;
|
|
206
|
+
changeInfo = formatDataToCell(_objectSpread(_objectSpread({}, pick(getState(), ['data', 'start', 'end', 'editing'])), {}, {
|
|
207
|
+
pasteData: pasteData,
|
|
208
|
+
groupConfig: groupConfig,
|
|
209
|
+
freePaste: freePaste
|
|
210
|
+
}));
|
|
211
|
+
if (changeInfo) {
|
|
212
|
+
_context.next = 9;
|
|
213
|
+
break;
|
|
214
|
+
}
|
|
215
|
+
return _context.abrupt("return");
|
|
216
|
+
case 9:
|
|
217
|
+
changes = changeInfo.changes, extChanges = changeInfo.extChanges;
|
|
218
|
+
legalChanges = changes.filter(function (_ref5) {
|
|
219
|
+
var row = _ref5.row,
|
|
220
|
+
col = _ref5.col,
|
|
221
|
+
value = _ref5.value;
|
|
222
|
+
var editor = data[row][col].dataEditor;
|
|
223
|
+
if (editor && editor.checker) {
|
|
224
|
+
return editor.checker(value, data[row][col].record);
|
|
225
|
+
}
|
|
226
|
+
return true;
|
|
227
|
+
}).map(function (_ref6) {
|
|
228
|
+
var _data$row$col2, _editor$parser;
|
|
229
|
+
var row = _ref6.row,
|
|
230
|
+
col = _ref6.col,
|
|
231
|
+
value = _ref6.value;
|
|
232
|
+
var editor = data[row][col].dataEditor;
|
|
233
|
+
return {
|
|
234
|
+
row: row,
|
|
235
|
+
col: col,
|
|
236
|
+
id: (_data$row$col2 = data[row][col]) === null || _data$row$col2 === void 0 ? void 0 : _data$row$col2.id,
|
|
237
|
+
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 || (_editor$parser = editor.parser) === null || _editor$parser === void 0 ? void 0 : _editor$parser.call(editor, value, data[row][col].record) : value
|
|
238
|
+
};
|
|
239
|
+
});
|
|
240
|
+
lastRow = extChanges === null || extChanges === void 0 || (_extChanges$ = extChanges[0]) === null || _extChanges$ === void 0 ? void 0 : _extChanges$.row;
|
|
241
|
+
lastIndex = 1;
|
|
242
|
+
legalExtChanges = extChanges === null || extChanges === void 0 ? void 0 : extChanges.filter(function (_ref7) {
|
|
243
|
+
var value = _ref7.value,
|
|
244
|
+
col = _ref7.col;
|
|
245
|
+
var editor = data[0][col].dataEditor;
|
|
246
|
+
if (editor && editor.checker) {
|
|
247
|
+
return editor.checker(value);
|
|
248
|
+
}
|
|
249
|
+
return true;
|
|
250
|
+
}).map(function (_ref8) {
|
|
251
|
+
var _editor$parser2;
|
|
252
|
+
var row = _ref8.row,
|
|
253
|
+
col = _ref8.col,
|
|
254
|
+
value = _ref8.value;
|
|
255
|
+
var editor = data[0][col].dataEditor;
|
|
256
|
+
if (lastRow !== row) {
|
|
257
|
+
lastRow = row;
|
|
258
|
+
lastIndex++;
|
|
259
|
+
}
|
|
260
|
+
return {
|
|
261
|
+
row: row,
|
|
262
|
+
col: col,
|
|
263
|
+
value: editor !== null && editor !== void 0 && editor.parser ? editor === null || editor === void 0 || (_editor$parser2 = editor.parser) === null || _editor$parser2 === void 0 ? void 0 : _editor$parser2.call(editor, value) : value,
|
|
264
|
+
id: -lastIndex
|
|
265
|
+
};
|
|
266
|
+
});
|
|
267
|
+
newHistory = _toConsumableArray(history || []);
|
|
268
|
+
newHistory.push({
|
|
269
|
+
changes: legalChanges.map(function (item) {
|
|
270
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
271
|
+
value: data[item.row][item.col].value
|
|
272
|
+
});
|
|
273
|
+
}),
|
|
274
|
+
type: 'Paste'
|
|
275
|
+
});
|
|
276
|
+
dispatch({
|
|
277
|
+
type: 'changes',
|
|
278
|
+
payload: {
|
|
279
|
+
start: pick(legalChanges[0], ['row', 'col']),
|
|
280
|
+
history: newHistory,
|
|
281
|
+
end: pick(legalChanges[legalChanges.length - 1], ['row', 'col']),
|
|
282
|
+
lastSelected: {
|
|
283
|
+
start: start,
|
|
284
|
+
end: end
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
});
|
|
288
|
+
cellChangeHandler && cellChangeHandler(legalChanges, freePaste ? legalExtChanges : []);
|
|
289
|
+
case 18:
|
|
290
|
+
case "end":
|
|
291
|
+
return _context.stop();
|
|
292
|
+
}
|
|
293
|
+
}, _callee);
|
|
294
|
+
}))();
|
|
295
|
+
},
|
|
296
|
+
delete: function _delete(dispatch, getState) {
|
|
297
|
+
var _getState9 = getState(),
|
|
298
|
+
cellChangeHandler = _getState9.cellChangeHandler,
|
|
299
|
+
start = _getState9.start,
|
|
300
|
+
end = _getState9.end,
|
|
301
|
+
data = _getState9.data,
|
|
302
|
+
history = _getState9.history,
|
|
303
|
+
groupConfig = _getState9.groupConfig,
|
|
304
|
+
editing = _getState9.editing;
|
|
305
|
+
if (editing) return;
|
|
306
|
+
var groupMap = groupConfigToGroupMap(groupConfig);
|
|
307
|
+
var cellIndex = flatRowColIndex(start, end);
|
|
308
|
+
var changes = cellIndex.filter(function (item) {
|
|
309
|
+
var _data$item$row;
|
|
310
|
+
return !(data !== null && data !== void 0 && (_data$item$row = data[item.row]) !== null && _data$item$row !== void 0 && _data$item$row[item.col].readonly);
|
|
311
|
+
}).filter(
|
|
312
|
+
// 过滤掉分组的子行并且是关闭的状态
|
|
313
|
+
function (item) {
|
|
314
|
+
var _groupMap$get3, _groupMap$get4;
|
|
315
|
+
return !(groupMap.get(item.row) && !((_groupMap$get3 = groupMap.get(item.row)) !== null && _groupMap$get3 !== void 0 && _groupMap$get3.isStart) && !((_groupMap$get4 = groupMap.get(item.row)) !== null && _groupMap$get4 !== void 0 && _groupMap$get4.isOpen));
|
|
316
|
+
}).map(function (item) {
|
|
317
|
+
var _data$item$row2, _data$item$row3;
|
|
318
|
+
return {
|
|
319
|
+
cell: data === null || data === void 0 || (_data$item$row2 = data[item.row]) === null || _data$item$row2 === void 0 ? void 0 : _data$item$row2[item.col],
|
|
320
|
+
row: item.row,
|
|
321
|
+
col: item.col,
|
|
322
|
+
value: null,
|
|
323
|
+
id: data === null || data === void 0 || (_data$item$row3 = data[item.row]) === null || _data$item$row3 === void 0 ? void 0 : _data$item$row3[item.col].id
|
|
324
|
+
};
|
|
325
|
+
});
|
|
326
|
+
var newHistory = _toConsumableArray(history || []);
|
|
327
|
+
newHistory.push({
|
|
328
|
+
changes: changes.map(function (item) {
|
|
329
|
+
return _objectSpread(_objectSpread({}, item), {}, {
|
|
330
|
+
value: data[item.row][item.col].value
|
|
331
|
+
});
|
|
332
|
+
}),
|
|
333
|
+
type: 'Delete'
|
|
334
|
+
});
|
|
335
|
+
dispatch({
|
|
336
|
+
type: 'changes',
|
|
337
|
+
payload: {
|
|
338
|
+
history: newHistory
|
|
339
|
+
}
|
|
340
|
+
});
|
|
341
|
+
cellChangeHandler && cellChangeHandler(changes);
|
|
342
|
+
},
|
|
343
|
+
reverse: function reverse(dispatch, getState) {
|
|
344
|
+
var _getState10 = getState(),
|
|
345
|
+
start = _getState10.start,
|
|
346
|
+
end = _getState10.end,
|
|
347
|
+
history = _getState10.history,
|
|
348
|
+
cellChangeHandler = _getState10.cellChangeHandler,
|
|
349
|
+
eventBus = _getState10.eventBus;
|
|
350
|
+
if (!(history !== null && history !== void 0 && history.length)) return;
|
|
351
|
+
var changeHistory = _toConsumableArray(history);
|
|
352
|
+
var change = changeHistory.pop();
|
|
353
|
+
var type = change.type;
|
|
354
|
+
if (!['Edit', 'Paste', 'Delete'].includes(type)) {
|
|
355
|
+
eventBus.emit('reverse', change);
|
|
356
|
+
dispatch({
|
|
357
|
+
type: 'changes',
|
|
358
|
+
payload: {
|
|
359
|
+
history: changeHistory
|
|
360
|
+
}
|
|
361
|
+
});
|
|
362
|
+
return;
|
|
363
|
+
}
|
|
364
|
+
cellChangeHandler && cellChangeHandler(change.changes);
|
|
365
|
+
dispatch({
|
|
366
|
+
type: 'changes',
|
|
367
|
+
payload: {
|
|
368
|
+
start: pick(head(change.changes), ['row', 'col']),
|
|
369
|
+
end: pick(last(change.changes), ['row', 'col']),
|
|
370
|
+
lastSelected: {
|
|
371
|
+
start: start,
|
|
372
|
+
end: end
|
|
373
|
+
},
|
|
374
|
+
history: changeHistory
|
|
375
|
+
}
|
|
376
|
+
});
|
|
377
|
+
}
|
|
378
|
+
};
|