@zhenliang/sheet 0.1.22 → 0.1.23
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.js +13 -0
- package/dist/core/editor/cascaderEditor/index.d.ts +5 -0
- package/dist/core/editor/cascaderEditor/index.js +54 -0
- package/dist/core/editor/cascaderEditor/index.less +28 -0
- package/dist/core/editor/dateEditor/index.d.ts +5 -0
- package/dist/core/editor/dateEditor/index.js +56 -0
- package/dist/core/editor/dateEditor/index.less +11 -0
- package/dist/core/editor/index.d.ts +4 -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.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.js +96 -0
- package/dist/core/editor/selectEditor/index.less +43 -0
- package/dist/core/reducers/index.d.ts +9 -0
- package/dist/core/reducers/index.js +38 -0
- package/dist/core/reducers/keyboardReducer.d.ts +2 -0
- package/dist/core/reducers/keyboardReducer.js +93 -0
- package/dist/core/reducers/mouseReducer.d.ts +2 -0
- package/dist/core/reducers/mouseReducer.js +164 -0
- package/dist/core/reducers/sideEffectReducer.d.ts +4 -0
- package/dist/core/reducers/sideEffectReducer.js +378 -0
- package/dist/core/reducers/stateReducer.d.ts +2 -0
- package/dist/core/reducers/stateReducer.js +174 -0
- package/dist/core/sheet/Cell.d.ts +4 -0
- package/dist/core/sheet/Cell.js +181 -0
- package/dist/core/sheet/DataEditor.d.ts +3 -0
- package/dist/core/sheet/DataEditor.js +24 -0
- package/dist/core/sheet/DefaultCell.d.ts +11 -0
- package/dist/core/sheet/DefaultCell.js +31 -0
- package/dist/core/sheet/DefaultRow.d.ts +12 -0
- package/dist/core/sheet/DefaultRow.js +28 -0
- package/dist/core/sheet/DefaultRowMapper.d.ts +8 -0
- package/dist/core/sheet/DefaultRowMapper.js +15 -0
- package/dist/core/sheet/DefaultShell.d.ts +8 -0
- package/dist/core/sheet/DefaultShell.js +12 -0
- package/dist/core/sheet/Event.d.ts +5 -0
- package/dist/core/sheet/Event.js +17 -0
- package/dist/core/sheet/ValueViewer.d.ts +3 -0
- package/dist/core/sheet/ValueViewer.js +9 -0
- package/dist/core/sheet/index.d.ts +5 -0
- package/dist/core/sheet/index.js +265 -0
- package/dist/core/sheet/index.less +307 -0
- package/dist/core/sheet/useCellEvent.d.ts +3 -0
- package/dist/core/sheet/useCellEvent.js +22 -0
- package/dist/core/sheet/useContextMenu.d.ts +21 -0
- package/dist/core/sheet/useContextMenu.js +86 -0
- package/dist/core/sheet/useKeyBoardEvent.d.ts +3 -0
- package/dist/core/sheet/useKeyBoardEvent.js +66 -0
- package/dist/core/sheet/useMouseEvent.d.ts +3 -0
- package/dist/core/sheet/useMouseEvent.js +298 -0
- package/dist/core/sheet/useSelectVisible.d.ts +2 -0
- package/dist/core/sheet/useSelectVisible.js +57 -0
- package/dist/core/sheet/useVirtualList.d.ts +7 -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 +5 -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 +5 -0
- package/dist/core/shell/tableShell.js +109 -0
- package/dist/core/table/events.d.ts +15 -0
- package/dist/core/table/events.js +95 -0
- package/dist/core/table/index.d.ts +4 -0
- package/dist/core/table/index.js +313 -0
- package/dist/core/table/useGroupConfig.d.ts +2 -0
- package/dist/core/table/useGroupConfig.js +65 -0
- package/dist/core/table/useRowSelection.d.ts +2 -0
- package/dist/core/table/useRowSelection.js +24 -0
- package/dist/core/table/util.d.ts +8 -0
- package/dist/core/table/util.js +29 -0
- package/dist/core/util.d.ts +59 -0
- package/dist/core/util.js +490 -0
- package/dist/core/viewer/btnViewer/index.d.ts +2 -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.js +11 -0
- package/dist/core/viewer/checkViewer/index.d.ts +2 -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.js +31 -0
- package/dist/core/viewer/groupViewer/index.d.ts +2 -0
- package/dist/core/viewer/groupViewer/index.js +34 -0
- package/dist/core/viewer/index.d.ts +7 -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.js +16 -0
- package/dist/core/viewer/switchViewer/index.d.ts +2 -0
- package/dist/core/viewer/switchViewer/index.js +22 -0
- package/dist/example/antComponent.d.ts +3 -0
- package/dist/example/antComponent.js +314 -0
- package/dist/example/basic.d.ts +4 -0
- package/dist/example/basic.js +121 -0
- package/dist/example/ellipsis.d.ts +3 -0
- package/dist/example/ellipsis.js +64 -0
- package/dist/example/fixed.d.ts +3 -0
- package/dist/example/fixed.js +89 -0
- package/dist/example/group.d.ts +3 -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.js +86 -0
- package/dist/example/sheet.d.ts +4 -0
- package/dist/example/sheet.js +393 -0
- package/dist/example/valuationAnalyze.d.ts +2 -0
- package/dist/example/valuationAnalyze.js +227 -0
- package/dist/hooks/index.d.ts +8 -0
- package/dist/hooks/index.js +7 -0
- package/dist/hooks/useEventBus.d.ts +4 -0
- package/dist/hooks/useEventBus.js +17 -0
- package/dist/hooks/useKeyboard.d.ts +18 -0
- package/dist/hooks/useKeyboard.js +108 -0
- package/dist/hooks/useMiddlewareReducer.d.ts +12 -0
- package/dist/hooks/useMiddlewareReducer.js +47 -0
- package/dist/hooks/useMouse.d.ts +11 -0
- package/dist/hooks/useMouse.js +68 -0
- package/dist/hooks/useSetState.d.ts +2 -0
- package/dist/hooks/useSetState.js +27 -0
- package/dist/hooks/useSheetEvent.d.ts +5 -0
- package/dist/hooks/useSheetEvent.js +5 -0
- package/dist/hooks/useWidthConfig.d.ts +4 -0
- package/dist/hooks/useWidthConfig.js +5 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +8 -0
- package/dist/standardUtils/index.d.ts +9 -0
- package/dist/standardUtils/index.js +32 -0
- package/dist/type/index.d.ts +2 -0
- package/dist/type/index.js +4 -0
- package/dist/type/sheet.d.ts +205 -0
- package/dist/type/sheet.js +9 -0
- package/dist/type/sheetTable.d.ts +89 -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,227 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import { getNumberEditor, getSelectEditor, Table } from "./..";
|
|
8
|
+
import { Button } from 'antd';
|
|
9
|
+
import { isNil } from 'lodash';
|
|
10
|
+
import { useCallback, useState } from 'react';
|
|
11
|
+
import { SwitchViewer } from "../core/viewer";
|
|
12
|
+
import { SheetType } from "../type";
|
|
13
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
14
|
+
var RateValueInput = getNumberEditor({
|
|
15
|
+
addonAfter: '%',
|
|
16
|
+
min: 0,
|
|
17
|
+
max: 100
|
|
18
|
+
});
|
|
19
|
+
var ValueInput = getNumberEditor({
|
|
20
|
+
min: 0,
|
|
21
|
+
max: 100000000
|
|
22
|
+
});
|
|
23
|
+
var RateViewer = function RateViewer(props) {
|
|
24
|
+
var value = props.value;
|
|
25
|
+
return /*#__PURE__*/_jsx("span", {
|
|
26
|
+
children: value ? value + '%' : '-'
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var data = [{
|
|
30
|
+
id: 2443,
|
|
31
|
+
draftId: '101601',
|
|
32
|
+
valuationType: 2,
|
|
33
|
+
termDiscountRate: null,
|
|
34
|
+
reversionDiscountRate: null,
|
|
35
|
+
vacancyDiscountRate: null,
|
|
36
|
+
discountRate: 8.5,
|
|
37
|
+
exitCapRate: 4.5,
|
|
38
|
+
gfaUnitPrice: 107350.31545913525,
|
|
39
|
+
nlaUnitPrice: 90130.38038659678,
|
|
40
|
+
totalValuation: 1622707368.4802885,
|
|
41
|
+
isEnabled: true
|
|
42
|
+
}, {
|
|
43
|
+
id: 2444,
|
|
44
|
+
draftId: '101601',
|
|
45
|
+
valuationType: 5,
|
|
46
|
+
termDiscountRate: 4.5,
|
|
47
|
+
reversionDiscountRate: 5.5,
|
|
48
|
+
vacancyDiscountRate: 5.5,
|
|
49
|
+
discountRate: null,
|
|
50
|
+
exitCapRate: null,
|
|
51
|
+
gfaUnitPrice: 89327.04427210477,
|
|
52
|
+
nlaUnitPrice: 89327.04427210477,
|
|
53
|
+
totalValuation: 1429232708.3536763,
|
|
54
|
+
isEnabled: false
|
|
55
|
+
}];
|
|
56
|
+
var evaluateMethods = [{
|
|
57
|
+
label: 'DCF',
|
|
58
|
+
value: 2
|
|
59
|
+
}, {
|
|
60
|
+
label: 'T&R',
|
|
61
|
+
value: 5
|
|
62
|
+
}];
|
|
63
|
+
var EvaSelect = getSelectEditor(evaluateMethods);
|
|
64
|
+
export default (function () {
|
|
65
|
+
var _useState = useState(data),
|
|
66
|
+
_useState2 = _slicedToArray(_useState, 1),
|
|
67
|
+
state = _useState2[0];
|
|
68
|
+
var columns = [{
|
|
69
|
+
title: '默认使用',
|
|
70
|
+
dataIndex: 'isEnabled',
|
|
71
|
+
width: 66,
|
|
72
|
+
// cellType: 'operate',
|
|
73
|
+
readonly: function readonly(value, record) {
|
|
74
|
+
return !!record.valuationType;
|
|
75
|
+
},
|
|
76
|
+
render: SwitchViewer
|
|
77
|
+
// component: (record: any, row: number, col: number) => (
|
|
78
|
+
// <Switch
|
|
79
|
+
// disabled={isNil(record.valuationType)}
|
|
80
|
+
// checked={record.isEnabled}
|
|
81
|
+
// onChange={handleSwitchChange(record, row)}
|
|
82
|
+
// />
|
|
83
|
+
// ),
|
|
84
|
+
}, {
|
|
85
|
+
title: '评估方法',
|
|
86
|
+
dataIndex: 'valuationType',
|
|
87
|
+
width: 134,
|
|
88
|
+
readonly: function readonly(value, record, row) {
|
|
89
|
+
return !row;
|
|
90
|
+
},
|
|
91
|
+
render: function (props) {
|
|
92
|
+
var _evaluateMethods$find;
|
|
93
|
+
return /*#__PURE__*/_jsx("span", {
|
|
94
|
+
children: (_evaluateMethods$find = evaluateMethods.find(function (item) {
|
|
95
|
+
return item.value === props.value;
|
|
96
|
+
})) === null || _evaluateMethods$find === void 0 ? void 0 : _evaluateMethods$find.label
|
|
97
|
+
});
|
|
98
|
+
},
|
|
99
|
+
editor: getSelectEditor(evaluateMethods)
|
|
100
|
+
// calcReadOnly: (record, rowIndex) => !rowIndex,
|
|
101
|
+
// getSelectOptions: (record: any) => {
|
|
102
|
+
// if (record.valuationType === 2) {
|
|
103
|
+
// return evaluateMethods.slice(0, 1);
|
|
104
|
+
// }
|
|
105
|
+
// return evaluateMethods.slice(1);
|
|
106
|
+
// },
|
|
107
|
+
}, {
|
|
108
|
+
title: '租期内折现率',
|
|
109
|
+
dataIndex: 'termDiscountRate',
|
|
110
|
+
width: 134,
|
|
111
|
+
editor: RateValueInput,
|
|
112
|
+
render: RateViewer,
|
|
113
|
+
readonly: function readonly(value, record, row) {
|
|
114
|
+
return !row || isNil(record.valuationType);
|
|
115
|
+
}
|
|
116
|
+
// calcReadOnly: (record, rowIndex) => !rowIndex || isNil(record.valuationType),
|
|
117
|
+
}, {
|
|
118
|
+
title: '租期外折现率',
|
|
119
|
+
dataIndex: 'reversionDiscountRate',
|
|
120
|
+
width: 134,
|
|
121
|
+
render: RateViewer,
|
|
122
|
+
editor: RateValueInput,
|
|
123
|
+
readonly: function readonly(value, record, row) {
|
|
124
|
+
return !row || isNil(record.valuationType);
|
|
125
|
+
}
|
|
126
|
+
}, {
|
|
127
|
+
title: '空置面积折现率',
|
|
128
|
+
dataIndex: 'vacancyDiscountRate',
|
|
129
|
+
width: 134,
|
|
130
|
+
render: RateViewer,
|
|
131
|
+
editor: RateValueInput,
|
|
132
|
+
readonly: function readonly(value, record, row) {
|
|
133
|
+
return !row || isNil(record.valuationType);
|
|
134
|
+
}
|
|
135
|
+
}, {
|
|
136
|
+
title: '折现率',
|
|
137
|
+
dataIndex: 'discountRate',
|
|
138
|
+
width: 134,
|
|
139
|
+
render: RateViewer,
|
|
140
|
+
editor: EvaSelect,
|
|
141
|
+
readonly: function readonly(value, record, row) {
|
|
142
|
+
return !row || isNil(record.valuationType);
|
|
143
|
+
}
|
|
144
|
+
}, {
|
|
145
|
+
title: '退出资本化率',
|
|
146
|
+
dataIndex: 'exitCapRate',
|
|
147
|
+
width: 134,
|
|
148
|
+
render: RateViewer,
|
|
149
|
+
editor: RateValueInput,
|
|
150
|
+
readonly: function readonly(value, record, row) {
|
|
151
|
+
return !row || isNil(record.valuationType);
|
|
152
|
+
}
|
|
153
|
+
}, {
|
|
154
|
+
title: '估值单价/GFA',
|
|
155
|
+
dataIndex: 'gfaUnitPrice',
|
|
156
|
+
width: 134,
|
|
157
|
+
editor: ValueInput,
|
|
158
|
+
readonly: true
|
|
159
|
+
}, {
|
|
160
|
+
title: '估值单价/NLA',
|
|
161
|
+
dataIndex: 'nlaUnitPrice',
|
|
162
|
+
width: 134,
|
|
163
|
+
editor: ValueInput,
|
|
164
|
+
readonly: true
|
|
165
|
+
}, {
|
|
166
|
+
title: '估值',
|
|
167
|
+
dataIndex: 'totalValuation',
|
|
168
|
+
width: 134,
|
|
169
|
+
editor: ValueInput,
|
|
170
|
+
readonly: true
|
|
171
|
+
}, {
|
|
172
|
+
title: '操作',
|
|
173
|
+
width: 62,
|
|
174
|
+
dataIndex: 'id',
|
|
175
|
+
fixed: SheetType.CellAlign.right,
|
|
176
|
+
editable: false,
|
|
177
|
+
render: function (props) {
|
|
178
|
+
var row = props.row,
|
|
179
|
+
record = props.record;
|
|
180
|
+
if (row) {
|
|
181
|
+
return /*#__PURE__*/_jsx("div", {
|
|
182
|
+
children: /*#__PURE__*/_jsx(Button, {
|
|
183
|
+
type: "link",
|
|
184
|
+
onClick: function onClick() {
|
|
185
|
+
// handleDelete((record as { id: number }).id);
|
|
186
|
+
// const infos = [{ id: record.id, row, extra: record }];
|
|
187
|
+
// operateCb && operateCb(4, { row, infos });
|
|
188
|
+
},
|
|
189
|
+
size: "small",
|
|
190
|
+
children: "\u5220\u9664"
|
|
191
|
+
})
|
|
192
|
+
});
|
|
193
|
+
}
|
|
194
|
+
return /*#__PURE__*/_jsx("div", {
|
|
195
|
+
className: "value-viewer number-value-viewer"
|
|
196
|
+
});
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
// component: (record: any, row: number, col: number, operateCb?: ExcelTableType.OperateCollector) => {
|
|
200
|
+
// if (row) {
|
|
201
|
+
// return (
|
|
202
|
+
// <div>
|
|
203
|
+
// <Button
|
|
204
|
+
// type="link"
|
|
205
|
+
// onClick={() => {
|
|
206
|
+
// handleDelete(record.id);
|
|
207
|
+
// const infos = [{ id: record.id, row, extra: record }];
|
|
208
|
+
// operateCb && operateCb(4, { row, infos });
|
|
209
|
+
// }}
|
|
210
|
+
// size="small"
|
|
211
|
+
// >
|
|
212
|
+
// 删除
|
|
213
|
+
// </Button>
|
|
214
|
+
// </div>
|
|
215
|
+
// );
|
|
216
|
+
// }
|
|
217
|
+
// return <div className="value-viewer number-value-viewer" />;
|
|
218
|
+
// },
|
|
219
|
+
}];
|
|
220
|
+
|
|
221
|
+
var handleChange = useCallback(function () {}, [state]);
|
|
222
|
+
return /*#__PURE__*/_jsx(Table, {
|
|
223
|
+
columns: columns,
|
|
224
|
+
dataSource: state,
|
|
225
|
+
onChange: handleChange
|
|
226
|
+
});
|
|
227
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { useEventBus } from './useEventBus';
|
|
2
|
+
export { useKeyBoard } from './useKeyboard';
|
|
3
|
+
export { useMiddlewareReducer } from './useMiddlewareReducer';
|
|
4
|
+
export type { Dispatch, FunctionAction, NormalAction, } from './useMiddlewareReducer';
|
|
5
|
+
export { useMouse } from './useMouse';
|
|
6
|
+
export { useSetState } from './useSetState';
|
|
7
|
+
export { SheetEventContext, useSheetEvent } from './useSheetEvent';
|
|
8
|
+
export { useWidth, WidthContext } from './useWidthConfig';
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
export { useEventBus } from "./useEventBus";
|
|
2
|
+
export { useKeyBoard } from "./useKeyboard";
|
|
3
|
+
export { useMiddlewareReducer } from "./useMiddlewareReducer";
|
|
4
|
+
export { useMouse } from "./useMouse";
|
|
5
|
+
export { useSetState } from "./useSetState";
|
|
6
|
+
export { SheetEventContext, useSheetEvent } from "./useSheetEvent";
|
|
7
|
+
export { useWidth, WidthContext } from "./useWidthConfig";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import EventEmitter from 'events';
|
|
2
|
+
import { useEffect, useRef } from 'react';
|
|
3
|
+
var useEventBus = function useEventBus() {
|
|
4
|
+
var eventBus = useRef(new EventEmitter());
|
|
5
|
+
useEffect(function () {
|
|
6
|
+
return function () {
|
|
7
|
+
var _eventBus$current;
|
|
8
|
+
(_eventBus$current = eventBus.current) === null || _eventBus$current === void 0 ? void 0 : _eventBus$current.removeAllListeners();
|
|
9
|
+
eventBus.current = null;
|
|
10
|
+
};
|
|
11
|
+
}, []);
|
|
12
|
+
if (!eventBus.current) {
|
|
13
|
+
eventBus.current = new EventEmitter();
|
|
14
|
+
}
|
|
15
|
+
return eventBus.current;
|
|
16
|
+
};
|
|
17
|
+
export { useEventBus };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
declare type KeyOrClipBoardEvent = (event: KeyboardEvent | ClipboardEvent, value?: any) => void;
|
|
2
|
+
declare type KeyboardHandler = {
|
|
3
|
+
move: KeyOrClipBoardEvent;
|
|
4
|
+
escape: KeyOrClipBoardEvent;
|
|
5
|
+
delete: KeyOrClipBoardEvent;
|
|
6
|
+
enter: KeyOrClipBoardEvent;
|
|
7
|
+
otherInput: KeyOrClipBoardEvent;
|
|
8
|
+
copy: KeyOrClipBoardEvent;
|
|
9
|
+
paste: KeyOrClipBoardEvent;
|
|
10
|
+
reverse: KeyOrClipBoardEvent;
|
|
11
|
+
cut: KeyOrClipBoardEvent;
|
|
12
|
+
};
|
|
13
|
+
export declare function move(keyCode: number, isShiftKey: boolean): {
|
|
14
|
+
row: number;
|
|
15
|
+
col: number;
|
|
16
|
+
} | undefined;
|
|
17
|
+
export declare const useKeyBoard: (handler: KeyboardHandler, listenElement: HTMLSpanElement | null) => void;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { useCallback, useEffect } from 'react';
|
|
2
|
+
import { BACKSPACE_KEY, C_KEY, DELETE_KEY, DOWN_KEY, ENTER_KEY, ESCAPE_KEY, LEFT_KEY, RIGHT_KEY, TAB_KEY, UP_KEY, V_KEY, X_KEY, Z_KEY } from "../core/config";
|
|
3
|
+
import { isInputKey } from "../core/util";
|
|
4
|
+
var ua = window.navigator.userAgent;
|
|
5
|
+
var isIE = /MSIE|Trident/.test(ua);
|
|
6
|
+
export function move(keyCode, isShiftKey) {
|
|
7
|
+
if (keyCode === TAB_KEY) {
|
|
8
|
+
return {
|
|
9
|
+
row: 0,
|
|
10
|
+
col: isShiftKey ? -1 : 1
|
|
11
|
+
};
|
|
12
|
+
} else if (keyCode === RIGHT_KEY) {
|
|
13
|
+
return {
|
|
14
|
+
row: 0,
|
|
15
|
+
col: 1
|
|
16
|
+
};
|
|
17
|
+
} else if (keyCode === LEFT_KEY) {
|
|
18
|
+
return {
|
|
19
|
+
row: 0,
|
|
20
|
+
col: -1
|
|
21
|
+
};
|
|
22
|
+
} else if (keyCode === UP_KEY) {
|
|
23
|
+
return {
|
|
24
|
+
row: -1,
|
|
25
|
+
col: 0
|
|
26
|
+
};
|
|
27
|
+
} else if (keyCode === DOWN_KEY) {
|
|
28
|
+
return {
|
|
29
|
+
row: 1,
|
|
30
|
+
col: 0
|
|
31
|
+
};
|
|
32
|
+
} else if (keyCode === ENTER_KEY) {
|
|
33
|
+
return {
|
|
34
|
+
row: isShiftKey ? -1 : 1,
|
|
35
|
+
col: 0
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
export var useKeyBoard = function useKeyBoard(handler, listenElement) {
|
|
40
|
+
var handleKey = useCallback(function (e) {
|
|
41
|
+
if (e.defaultPrevented) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var ctrlKey = e.ctrlKey,
|
|
45
|
+
metaKey = e.metaKey,
|
|
46
|
+
keyCode = e.keyCode,
|
|
47
|
+
shiftKey = e.shiftKey;
|
|
48
|
+
var ctrlKeyPressed = ctrlKey || metaKey;
|
|
49
|
+
var isEscape = keyCode === ESCAPE_KEY;
|
|
50
|
+
if (isEscape) {
|
|
51
|
+
handler.escape(e);
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
var isReverse = ctrlKeyPressed && keyCode === Z_KEY;
|
|
55
|
+
if (isReverse) {
|
|
56
|
+
handler.reverse(e);
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
var isCopy = ctrlKeyPressed && keyCode === C_KEY;
|
|
60
|
+
if (isCopy && isIE) {
|
|
61
|
+
handler.copy(e);
|
|
62
|
+
return;
|
|
63
|
+
}
|
|
64
|
+
var isCut = ctrlKeyPressed && keyCode === X_KEY;
|
|
65
|
+
if (isCut && isIE) {
|
|
66
|
+
handler.copy(e);
|
|
67
|
+
return;
|
|
68
|
+
}
|
|
69
|
+
var isPaste = ctrlKeyPressed && keyCode === V_KEY;
|
|
70
|
+
if (isPaste && isIE) {
|
|
71
|
+
handler.paste(e);
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
var isDelete = keyCode === DELETE_KEY || keyCode === BACKSPACE_KEY;
|
|
75
|
+
if (isDelete) {
|
|
76
|
+
handler.delete(e);
|
|
77
|
+
return;
|
|
78
|
+
}
|
|
79
|
+
var isEnter = keyCode === ENTER_KEY;
|
|
80
|
+
if (isEnter && !shiftKey) {
|
|
81
|
+
handler.enter(e);
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (ctrlKeyPressed) {
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
var isValueInput = isInputKey(keyCode);
|
|
88
|
+
if (isValueInput) {
|
|
89
|
+
handler.otherInput(e, e.key);
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
var moveInfo = move(keyCode, shiftKey);
|
|
93
|
+
moveInfo && handler.move(e, moveInfo);
|
|
94
|
+
}, [handler]);
|
|
95
|
+
useEffect(function () {
|
|
96
|
+
if (!listenElement) return;
|
|
97
|
+
listenElement.addEventListener('keydown', handleKey);
|
|
98
|
+
document.addEventListener('copy', handler.copy);
|
|
99
|
+
document.addEventListener('paste', handler.paste);
|
|
100
|
+
document.addEventListener('cut', handler.cut);
|
|
101
|
+
return function () {
|
|
102
|
+
listenElement.removeEventListener('keydown', handleKey);
|
|
103
|
+
document.removeEventListener('copy', handler.copy);
|
|
104
|
+
document.removeEventListener('paste', handler.paste);
|
|
105
|
+
document.removeEventListener('cut', handler.cut);
|
|
106
|
+
};
|
|
107
|
+
}, [listenElement]);
|
|
108
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export declare type NormalAction = {
|
|
2
|
+
type: string;
|
|
3
|
+
payload?: any;
|
|
4
|
+
};
|
|
5
|
+
export declare type FunctionAction = (dispatch: any, getState?: () => any) => any;
|
|
6
|
+
export declare type Dispatch = (action: any) => any;
|
|
7
|
+
export declare type MiddlewareAPI<A> = {
|
|
8
|
+
getState: () => A;
|
|
9
|
+
dispatch: Dispatch;
|
|
10
|
+
};
|
|
11
|
+
export declare type Middleware<A> = (api: MiddlewareAPI<A>) => (next: Dispatch) => Dispatch;
|
|
12
|
+
export declare const useMiddlewareReducer: <A, B>(reducer: (state: A, action: B) => A, initialState: A, middleware?: Middleware<A>[]) => [A, Dispatch];
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
2
|
+
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
|
+
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); }
|
|
4
|
+
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; }
|
|
5
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
6
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
+
import * as React from 'react';
|
|
8
|
+
export var useMiddlewareReducer = function useMiddlewareReducer(reducer, initialState) {
|
|
9
|
+
var middleware = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
10
|
+
var _React$useState = React.useState(initialState),
|
|
11
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
12
|
+
state = _React$useState2[0],
|
|
13
|
+
setState = _React$useState2[1];
|
|
14
|
+
var stateRef = React.useRef(state);
|
|
15
|
+
var dispatch = React.useMemo(function () {
|
|
16
|
+
var dispatch = function dispatch() {
|
|
17
|
+
throw new Error("Dispatching while constructing your middleware is not allowed. " + "Other middleware would not be applied to this dispatch.");
|
|
18
|
+
};
|
|
19
|
+
var middlewareAPI = {
|
|
20
|
+
getState: function getState() {
|
|
21
|
+
return stateRef.current;
|
|
22
|
+
},
|
|
23
|
+
dispatch: function (_dispatch) {
|
|
24
|
+
function dispatch(_x2) {
|
|
25
|
+
return _dispatch.apply(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
dispatch.toString = function () {
|
|
28
|
+
return _dispatch.toString();
|
|
29
|
+
};
|
|
30
|
+
return dispatch;
|
|
31
|
+
}(function (action) {
|
|
32
|
+
return dispatch(action);
|
|
33
|
+
})
|
|
34
|
+
};
|
|
35
|
+
var localDispatch = function localDispatch(action) {
|
|
36
|
+
stateRef.current = reducer(stateRef.current, action);
|
|
37
|
+
setState(stateRef.current);
|
|
38
|
+
};
|
|
39
|
+
dispatch = middleware.map(function (middleware) {
|
|
40
|
+
return middleware(middlewareAPI);
|
|
41
|
+
}).reduceRight(function (acc, middleware) {
|
|
42
|
+
return middleware(acc);
|
|
43
|
+
}, localDispatch);
|
|
44
|
+
return dispatch;
|
|
45
|
+
}, []);
|
|
46
|
+
return [state, dispatch];
|
|
47
|
+
};
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
declare type MouseHandler = {
|
|
2
|
+
mouseUp: (value: MouseEvent) => void;
|
|
3
|
+
mouseDown: (value: MouseEvent) => void;
|
|
4
|
+
mouseOver: (value: MouseEvent) => void;
|
|
5
|
+
mouseLeave: (value: MouseEvent) => void;
|
|
6
|
+
mouseEnter: (value: MouseEvent) => void;
|
|
7
|
+
doubleClick: (value: MouseEvent) => void;
|
|
8
|
+
loseFocus: (value: MouseEvent) => void;
|
|
9
|
+
};
|
|
10
|
+
export declare const useMouse: (handler: MouseHandler, listenElement: HTMLSpanElement | null) => void;
|
|
11
|
+
export {};
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { debounce } from 'lodash';
|
|
2
|
+
import { useCallback, useEffect, useRef } from 'react';
|
|
3
|
+
export var useMouse = function useMouse(handler, listenElement) {
|
|
4
|
+
var mouseUp = handler.mouseUp,
|
|
5
|
+
mouseDown = handler.mouseDown,
|
|
6
|
+
mouseOver = handler.mouseOver,
|
|
7
|
+
mouseLeave = handler.mouseLeave,
|
|
8
|
+
mouseEnter = handler.mouseEnter,
|
|
9
|
+
doubleClick = handler.doubleClick,
|
|
10
|
+
loseFocus = handler.loseFocus;
|
|
11
|
+
var handlerRef = useRef();
|
|
12
|
+
|
|
13
|
+
// todo
|
|
14
|
+
var wrapper = useCallback(function (handle) {
|
|
15
|
+
return function (e) {
|
|
16
|
+
if (!listenElement.contains(e.target)) {
|
|
17
|
+
return;
|
|
18
|
+
}
|
|
19
|
+
handle(e);
|
|
20
|
+
};
|
|
21
|
+
}, [listenElement]);
|
|
22
|
+
useEffect(function () {
|
|
23
|
+
return function () {
|
|
24
|
+
if (!handlerRef.current) return;
|
|
25
|
+
var _handlerRef$current = handlerRef.current,
|
|
26
|
+
listenerMouseUp = _handlerRef$current.mouseUp,
|
|
27
|
+
listenerMouseDown = _handlerRef$current.mouseDown,
|
|
28
|
+
listenerMouseOver = _handlerRef$current.mouseOver,
|
|
29
|
+
listenerMouseLeave = _handlerRef$current.mouseLeave,
|
|
30
|
+
listenerMouseEnter = _handlerRef$current.mouseEnter,
|
|
31
|
+
listenerDoubleClick = _handlerRef$current.doubleClick;
|
|
32
|
+
document.removeEventListener('mouseup', listenerMouseUp);
|
|
33
|
+
document.removeEventListener('mousedown', listenerMouseDown);
|
|
34
|
+
document.removeEventListener('dblclick', listenerDoubleClick);
|
|
35
|
+
listenElement === null || listenElement === void 0 ? void 0 : listenElement.removeEventListener('mouseover', listenerMouseOver);
|
|
36
|
+
listenElement === null || listenElement === void 0 ? void 0 : listenElement.removeEventListener('mouseleave', listenerMouseLeave);
|
|
37
|
+
listenElement === null || listenElement === void 0 ? void 0 : listenElement.removeEventListener('mouseenter', listenerMouseEnter);
|
|
38
|
+
};
|
|
39
|
+
}, []);
|
|
40
|
+
useEffect(function () {
|
|
41
|
+
if (!listenElement) return;
|
|
42
|
+
var debounceOver = debounce(mouseOver, 10);
|
|
43
|
+
var wrappedMouseUp = mouseUp;
|
|
44
|
+
var wrappedMouseDown = function wrappedMouseDown(e) {
|
|
45
|
+
if (!(listenElement !== null && listenElement !== void 0 && listenElement.contains(e.target))) {
|
|
46
|
+
loseFocus(e);
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
mouseDown(e);
|
|
50
|
+
};
|
|
51
|
+
var wrappedMouseDoubleClick = wrapper(doubleClick);
|
|
52
|
+
handlerRef.current = {
|
|
53
|
+
mouseUp: wrappedMouseUp,
|
|
54
|
+
mouseDown: wrappedMouseDown,
|
|
55
|
+
doubleClick: wrappedMouseDoubleClick,
|
|
56
|
+
mouseOver: debounceOver,
|
|
57
|
+
mouseLeave: mouseLeave,
|
|
58
|
+
mouseEnter: mouseEnter,
|
|
59
|
+
loseFocus: loseFocus
|
|
60
|
+
};
|
|
61
|
+
document.addEventListener('mouseup', wrappedMouseUp);
|
|
62
|
+
document.addEventListener('mousedown', wrappedMouseDown);
|
|
63
|
+
document.addEventListener('dblclick', wrappedMouseDoubleClick);
|
|
64
|
+
listenElement === null || listenElement === void 0 ? void 0 : listenElement.addEventListener('mouseover', debounceOver);
|
|
65
|
+
listenElement === null || listenElement === void 0 ? void 0 : listenElement.addEventListener('mouseleave', mouseLeave);
|
|
66
|
+
listenElement === null || listenElement === void 0 ? void 0 : listenElement.addEventListener('mouseenter', mouseEnter);
|
|
67
|
+
}, [listenElement]);
|
|
68
|
+
};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
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
|
+
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
|
|
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."); }
|
|
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); }
|
|
10
|
+
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; }
|
|
11
|
+
function _iterableToArrayLimit(arr, i) { var _i = null == arr ? null : "undefined" != typeof Symbol && arr[Symbol.iterator] || arr["@@iterator"]; if (null != _i) { var _s, _e, _x, _r, _arr = [], _n = !0, _d = !1; try { if (_x = (_i = _i.call(arr)).next, 0 === i) { if (Object(_i) !== _i) return; _n = !1; } else for (; !(_n = (_s = _x.call(_i)).done) && (_arr.push(_s.value), _arr.length !== i); _n = !0); } catch (err) { _d = !0, _e = err; } finally { try { if (!_n && null != _i.return && (_r = _i.return(), Object(_r) !== _r)) return; } finally { if (_d) throw _e; } } return _arr; } }
|
|
12
|
+
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
13
|
+
import { useCallback, useState } from 'react';
|
|
14
|
+
var useSetState = function useSetState() {
|
|
15
|
+
var initialState = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
16
|
+
var _useState = useState(initialState),
|
|
17
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
18
|
+
state = _useState2[0],
|
|
19
|
+
setState = _useState2[1];
|
|
20
|
+
var setMergeState = useCallback(function (patch) {
|
|
21
|
+
setState(function (prevState) {
|
|
22
|
+
return _objectSpread(_objectSpread({}, prevState), typeof patch === 'function' ? patch(prevState) : patch);
|
|
23
|
+
});
|
|
24
|
+
}, []);
|
|
25
|
+
return [state, setMergeState];
|
|
26
|
+
};
|
|
27
|
+
export { useSetState };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SheetTableType, SheetType } from './type';
|
|
2
|
+
export * from './core/editor';
|
|
3
|
+
export { default as Sheet } from './core/sheet';
|
|
4
|
+
export { default as Table } from './core/table';
|
|
5
|
+
export * from './core/viewer';
|
|
6
|
+
export * from './hooks';
|
|
7
|
+
export { useSheetEvent } from './hooks/useSheetEvent';
|
|
8
|
+
export { SheetTableType, SheetType };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { SheetTableType, SheetType } from "./type";
|
|
2
|
+
export * from "./core/editor";
|
|
3
|
+
export { default as Sheet } from "./core/sheet";
|
|
4
|
+
export { default as Table } from "./core/table";
|
|
5
|
+
export * from "./core/viewer";
|
|
6
|
+
export * from "./hooks";
|
|
7
|
+
export { useSheetEvent } from "./hooks/useSheetEvent";
|
|
8
|
+
export { SheetTableType, SheetType };
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare type ValueParams = string | number | null | undefined;
|
|
2
|
+
export declare const formatPrecision: (value: ValueParams, precision?: number) => string;
|
|
3
|
+
/**
|
|
4
|
+
* 千位分隔符
|
|
5
|
+
* @param value 需要千分符格式化的数据
|
|
6
|
+
* @returns 含千分符的字符串
|
|
7
|
+
*/
|
|
8
|
+
export declare const thousandsSeparator: (value: string | number) => string;
|
|
9
|
+
export {};
|