@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.
Files changed (137) hide show
  1. package/dist/core/config.d.ts +13 -0
  2. package/dist/core/config.js +13 -0
  3. package/dist/core/editor/cascaderEditor/index.d.ts +5 -0
  4. package/dist/core/editor/cascaderEditor/index.js +54 -0
  5. package/dist/core/editor/cascaderEditor/index.less +28 -0
  6. package/dist/core/editor/dateEditor/index.d.ts +5 -0
  7. package/dist/core/editor/dateEditor/index.js +56 -0
  8. package/dist/core/editor/dateEditor/index.less +11 -0
  9. package/dist/core/editor/index.d.ts +4 -0
  10. package/dist/core/editor/index.js +4 -0
  11. package/dist/core/editor/numberEditor/index.d.ts +8 -0
  12. package/dist/core/editor/numberEditor/index.js +107 -0
  13. package/dist/core/editor/numberEditor/index.less +30 -0
  14. package/dist/core/editor/selectEditor/index.d.ts +6 -0
  15. package/dist/core/editor/selectEditor/index.js +96 -0
  16. package/dist/core/editor/selectEditor/index.less +43 -0
  17. package/dist/core/reducers/index.d.ts +9 -0
  18. package/dist/core/reducers/index.js +38 -0
  19. package/dist/core/reducers/keyboardReducer.d.ts +2 -0
  20. package/dist/core/reducers/keyboardReducer.js +93 -0
  21. package/dist/core/reducers/mouseReducer.d.ts +2 -0
  22. package/dist/core/reducers/mouseReducer.js +164 -0
  23. package/dist/core/reducers/sideEffectReducer.d.ts +4 -0
  24. package/dist/core/reducers/sideEffectReducer.js +378 -0
  25. package/dist/core/reducers/stateReducer.d.ts +2 -0
  26. package/dist/core/reducers/stateReducer.js +174 -0
  27. package/dist/core/sheet/Cell.d.ts +4 -0
  28. package/dist/core/sheet/Cell.js +181 -0
  29. package/dist/core/sheet/DataEditor.d.ts +3 -0
  30. package/dist/core/sheet/DataEditor.js +24 -0
  31. package/dist/core/sheet/DefaultCell.d.ts +11 -0
  32. package/dist/core/sheet/DefaultCell.js +31 -0
  33. package/dist/core/sheet/DefaultRow.d.ts +12 -0
  34. package/dist/core/sheet/DefaultRow.js +28 -0
  35. package/dist/core/sheet/DefaultRowMapper.d.ts +8 -0
  36. package/dist/core/sheet/DefaultRowMapper.js +15 -0
  37. package/dist/core/sheet/DefaultShell.d.ts +8 -0
  38. package/dist/core/sheet/DefaultShell.js +12 -0
  39. package/dist/core/sheet/Event.d.ts +5 -0
  40. package/dist/core/sheet/Event.js +17 -0
  41. package/dist/core/sheet/ValueViewer.d.ts +3 -0
  42. package/dist/core/sheet/ValueViewer.js +9 -0
  43. package/dist/core/sheet/index.d.ts +5 -0
  44. package/dist/core/sheet/index.js +265 -0
  45. package/dist/core/sheet/index.less +307 -0
  46. package/dist/core/sheet/useCellEvent.d.ts +3 -0
  47. package/dist/core/sheet/useCellEvent.js +22 -0
  48. package/dist/core/sheet/useContextMenu.d.ts +21 -0
  49. package/dist/core/sheet/useContextMenu.js +86 -0
  50. package/dist/core/sheet/useKeyBoardEvent.d.ts +3 -0
  51. package/dist/core/sheet/useKeyBoardEvent.js +66 -0
  52. package/dist/core/sheet/useMouseEvent.d.ts +3 -0
  53. package/dist/core/sheet/useMouseEvent.js +298 -0
  54. package/dist/core/sheet/useSelectVisible.d.ts +2 -0
  55. package/dist/core/sheet/useSelectVisible.js +57 -0
  56. package/dist/core/sheet/useVirtualList.d.ts +7 -0
  57. package/dist/core/sheet/useVirtualList.js +103 -0
  58. package/dist/core/sheet/var.less +41 -0
  59. package/dist/core/shell/draggableShell/index.d.ts +5 -0
  60. package/dist/core/shell/draggableShell/index.js +197 -0
  61. package/dist/core/shell/draggableShell/index.less +16 -0
  62. package/dist/core/shell/tableShell.d.ts +5 -0
  63. package/dist/core/shell/tableShell.js +109 -0
  64. package/dist/core/table/events.d.ts +15 -0
  65. package/dist/core/table/events.js +95 -0
  66. package/dist/core/table/index.d.ts +4 -0
  67. package/dist/core/table/index.js +313 -0
  68. package/dist/core/table/useGroupConfig.d.ts +2 -0
  69. package/dist/core/table/useGroupConfig.js +65 -0
  70. package/dist/core/table/useRowSelection.d.ts +2 -0
  71. package/dist/core/table/useRowSelection.js +24 -0
  72. package/dist/core/table/util.d.ts +8 -0
  73. package/dist/core/table/util.js +29 -0
  74. package/dist/core/util.d.ts +59 -0
  75. package/dist/core/util.js +490 -0
  76. package/dist/core/viewer/btnViewer/index.d.ts +2 -0
  77. package/dist/core/viewer/btnViewer/index.js +37 -0
  78. package/dist/core/viewer/cascaderViewer/index.d.ts +2 -0
  79. package/dist/core/viewer/cascaderViewer/index.js +11 -0
  80. package/dist/core/viewer/checkViewer/index.d.ts +2 -0
  81. package/dist/core/viewer/checkViewer/index.js +23 -0
  82. package/dist/core/viewer/editViewer/index.d.ts +2 -0
  83. package/dist/core/viewer/editViewer/index.js +31 -0
  84. package/dist/core/viewer/groupViewer/index.d.ts +2 -0
  85. package/dist/core/viewer/groupViewer/index.js +34 -0
  86. package/dist/core/viewer/index.d.ts +7 -0
  87. package/dist/core/viewer/index.js +7 -0
  88. package/dist/core/viewer/selectorViewer/index.d.ts +2 -0
  89. package/dist/core/viewer/selectorViewer/index.js +16 -0
  90. package/dist/core/viewer/switchViewer/index.d.ts +2 -0
  91. package/dist/core/viewer/switchViewer/index.js +22 -0
  92. package/dist/example/antComponent.d.ts +3 -0
  93. package/dist/example/antComponent.js +314 -0
  94. package/dist/example/basic.d.ts +4 -0
  95. package/dist/example/basic.js +121 -0
  96. package/dist/example/ellipsis.d.ts +3 -0
  97. package/dist/example/ellipsis.js +64 -0
  98. package/dist/example/fixed.d.ts +3 -0
  99. package/dist/example/fixed.js +89 -0
  100. package/dist/example/group.d.ts +3 -0
  101. package/dist/example/group.js +123 -0
  102. package/dist/example/index.less +5 -0
  103. package/dist/example/selection.d.ts +4 -0
  104. package/dist/example/selection.js +86 -0
  105. package/dist/example/sheet.d.ts +4 -0
  106. package/dist/example/sheet.js +393 -0
  107. package/dist/example/valuationAnalyze.d.ts +2 -0
  108. package/dist/example/valuationAnalyze.js +227 -0
  109. package/dist/hooks/index.d.ts +8 -0
  110. package/dist/hooks/index.js +7 -0
  111. package/dist/hooks/useEventBus.d.ts +4 -0
  112. package/dist/hooks/useEventBus.js +17 -0
  113. package/dist/hooks/useKeyboard.d.ts +18 -0
  114. package/dist/hooks/useKeyboard.js +108 -0
  115. package/dist/hooks/useMiddlewareReducer.d.ts +12 -0
  116. package/dist/hooks/useMiddlewareReducer.js +47 -0
  117. package/dist/hooks/useMouse.d.ts +11 -0
  118. package/dist/hooks/useMouse.js +68 -0
  119. package/dist/hooks/useSetState.d.ts +2 -0
  120. package/dist/hooks/useSetState.js +27 -0
  121. package/dist/hooks/useSheetEvent.d.ts +5 -0
  122. package/dist/hooks/useSheetEvent.js +5 -0
  123. package/dist/hooks/useWidthConfig.d.ts +4 -0
  124. package/dist/hooks/useWidthConfig.js +5 -0
  125. package/dist/index.d.ts +8 -0
  126. package/dist/index.js +8 -0
  127. package/dist/standardUtils/index.d.ts +9 -0
  128. package/dist/standardUtils/index.js +32 -0
  129. package/dist/type/index.d.ts +2 -0
  130. package/dist/type/index.js +4 -0
  131. package/dist/type/sheet.d.ts +205 -0
  132. package/dist/type/sheet.js +9 -0
  133. package/dist/type/sheetTable.d.ts +89 -0
  134. package/dist/type/sheetTable.js +1 -0
  135. package/dist/typings/index.d.ts +1 -0
  136. package/package.json +1 -1
  137. package/changes.md +0 -45
@@ -0,0 +1,265 @@
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 { useEffect, useMemo, useRef } from 'react';
14
+ // import ReduxLogger from 'redux-logger';
15
+ import ReduxThunk from 'redux-thunk';
16
+ import DefaultRow from "./DefaultRow";
17
+ import DefaultShell from "./DefaultShell";
18
+ import { ArrowDownOutlined, ArrowUpOutlined } from '@ant-design/icons';
19
+ import { isNil, isNumber } from 'lodash';
20
+ import { SheetEventContext, useEventBus, useMiddlewareReducer } from "../../hooks";
21
+ import sheetReducer from "../reducers";
22
+ import { classNames, getRowHeight, rowToActualRow } from "../util";
23
+ import { DefaultRowMapper } from "./DefaultRowMapper";
24
+ import "./index.less";
25
+ import { useCellEvent } from "./useCellEvent";
26
+ import { useContextMenu } from "./useContextMenu";
27
+ import { useKeyBoardEvent } from "./useKeyBoardEvent";
28
+ import { useMouseEvent } from "./useMouseEvent";
29
+ import { useSelectVisible } from "./useSelectVisible";
30
+ import { useVirtualList } from "./useVirtualList";
31
+ import { jsx as _jsx } from "react/jsx-runtime";
32
+ import { jsxs as _jsxs } from "react/jsx-runtime";
33
+ var Sheet = function Sheet(props) {
34
+ var _state$data$length, _state$data3, _scroll$y, _scroll$x;
35
+ var _props$sheetInstance = props.sheetInstance,
36
+ sheetInstance = _props$sheetInstance === void 0 ? {
37
+ current: null
38
+ } : _props$sheetInstance,
39
+ _props$sheetRenderer = props.sheetRenderer,
40
+ SheetShell = _props$sheetRenderer === void 0 ? DefaultShell : _props$sheetRenderer,
41
+ _props$rowRenderer = props.rowRenderer,
42
+ Row = _props$rowRenderer === void 0 ? DefaultRow : _props$rowRenderer,
43
+ ContextMenu = props.menuRenderer,
44
+ _props$virtualized = props.virtualized,
45
+ virtualized = _props$virtualized === void 0 ? false : _props$virtualized,
46
+ sticky = props.sticky,
47
+ className = props.className,
48
+ data = props.data,
49
+ _props$freePaste = props.freePaste,
50
+ freePaste = _props$freePaste === void 0 ? false : _props$freePaste,
51
+ _props$groupConfig = props.groupConfig,
52
+ groupConfig = _props$groupConfig === void 0 ? undefined : _props$groupConfig,
53
+ onCellsChanged = props.onCellsChanged,
54
+ onContextMenu = props.onContextMenu,
55
+ rowClassName = props.rowClassName,
56
+ scroll = props.scroll,
57
+ children = props.children,
58
+ showBackEdit = props.showBackEdit,
59
+ backEditStyle = props.backEditStyle;
60
+ var sheetWrapperRef = useRef(null);
61
+ var contextMenuRef = useRef(null);
62
+ var eventBus = useEventBus();
63
+ var _useMiddlewareReducer = useMiddlewareReducer(sheetReducer, {
64
+ data: data,
65
+ mouseDown: false,
66
+ editing: undefined,
67
+ lastFocus: [],
68
+ groupConfig: groupConfig,
69
+ eventBus: eventBus
70
+ },
71
+ // [ReduxThunk, ReduxLogger],
72
+ [ReduxThunk]),
73
+ _useMiddlewareReducer2 = _slicedToArray(_useMiddlewareReducer, 2),
74
+ state = _useMiddlewareReducer2[0],
75
+ dispatch = _useMiddlewareReducer2[1];
76
+ useEffect(function () {
77
+ sheetInstance.current = {
78
+ zoomTo: function zoomTo(row) {
79
+ // 给定 row 回到行
80
+ // 不给定 row 默认回到编辑行和列
81
+ dispatch(function (d, getState) {
82
+ var _ref, _sheetWrapperRef$curr;
83
+ var _getState = getState(),
84
+ start = _getState.start,
85
+ groupConfig = _getState.groupConfig,
86
+ data = _getState.data;
87
+ var container = sheetWrapperRef.current;
88
+ if (!start && isNil(row)) return;
89
+ var actual = rowToActualRow((_ref = row) !== null && _ref !== void 0 ? _ref : start === null || start === void 0 ? void 0 : start.row, groupConfig);
90
+ var rowHeight = getRowHeight(container);
91
+ var firstRowCell = container.querySelector("td.cell[data-col='".concat(start === null || start === void 0 ? void 0 : start.col, "']"));
92
+ var colPosition = firstRowCell ? firstRowCell.offsetLeft - firstRowCell.clientWidth : 0;
93
+ var scrollHeight = actual * rowHeight;
94
+ (_sheetWrapperRef$curr = sheetWrapperRef.current) === null || _sheetWrapperRef$curr === void 0 ? void 0 : _sheetWrapperRef$curr.scrollTo(isNumber(row) ? 0 : colPosition, scrollHeight);
95
+
96
+ // 最后一行的bug暂时用 scroll end 事件来处理
97
+ if (isNil(row) && start.row === data.length - 1 && sheetWrapperRef.current) {
98
+ var handleScrollEnd = function handleScrollEnd() {
99
+ var _sheetWrapperRef$curr2, _sheetWrapperRef$curr3;
100
+ (_sheetWrapperRef$curr2 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr2 === void 0 ? void 0 : _sheetWrapperRef$curr2.scrollTo(isNumber(row) ? 0 : colPosition, scrollHeight);
101
+ (_sheetWrapperRef$curr3 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr3 === void 0 ? void 0 : _sheetWrapperRef$curr3.removeEventListener('scrollend', handleScrollEnd);
102
+ };
103
+ sheetWrapperRef.current.addEventListener('scrollend', handleScrollEnd);
104
+ }
105
+ });
106
+ },
107
+ pushToHistory: function pushToHistory(config) {
108
+ dispatch({
109
+ type: 'pushHistory',
110
+ payload: config
111
+ });
112
+ },
113
+ selectRow: function selectRow(row) {
114
+ if (isNil(row)) {
115
+ dispatch({
116
+ type: 'clearSelect'
117
+ });
118
+ } else {
119
+ dispatch({
120
+ type: 'selectRow',
121
+ payload: row
122
+ });
123
+ }
124
+ },
125
+ select: function select(props) {
126
+ dispatch({
127
+ type: 'select',
128
+ payload: props
129
+ });
130
+ },
131
+ popHistory: function popHistory() {
132
+ var history = state.history;
133
+ dispatch({
134
+ type: 'popHistory'
135
+ });
136
+ return history !== null && history !== void 0 && history.length ? history === null || history === void 0 ? void 0 : history[history.length - 1] : {};
137
+ }
138
+ };
139
+ }, [sheetWrapperRef.current, state.history]);
140
+ useEffect(function () {
141
+ // 同步必要的状态
142
+ dispatch({
143
+ type: 'changes',
144
+ payload: {
145
+ cellChangeHandler: onCellsChanged,
146
+ data: data,
147
+ freePaste: freePaste,
148
+ groupConfig: groupConfig
149
+ }
150
+ });
151
+ }, [onCellsChanged, data, freePaste, groupConfig]);
152
+ useCellEvent(dispatch, state);
153
+ useMouseEvent(dispatch, sheetWrapperRef);
154
+ useKeyBoardEvent(dispatch, sheetWrapperRef);
155
+ var menu = useContextMenu(dispatch, sheetWrapperRef, !!ContextMenu, contextMenuRef);
156
+
157
+ // timeout 的副作用不适合放reducer里面
158
+ useEffect(function () {
159
+ if (!state.editing && state.start) {
160
+ setTimeout(function () {
161
+ var _sheetWrapperRef$curr4;
162
+ // 表格获取焦点 + 接收keyboard event
163
+ (_sheetWrapperRef$curr4 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr4 === void 0 ? void 0 : _sheetWrapperRef$curr4.focus({
164
+ preventScroll: true
165
+ });
166
+ }, 1);
167
+ }
168
+ }, [state.editing, state.start]);
169
+ var _useVirtualList = useVirtualList(sheetWrapperRef, state.data, groupConfig, virtualized),
170
+ virtualStart = _useVirtualList.virtualStart,
171
+ virtualEnd = _useVirtualList.virtualEnd,
172
+ paddingTop = _useVirtualList.paddingTop,
173
+ paddingBottom = _useVirtualList.paddingBottom;
174
+ useEffect(function () {
175
+ dispatch({
176
+ type: 'clearEdit'
177
+ });
178
+ dispatch({
179
+ type: 'clearSelectIfNotSingleRow'
180
+ });
181
+ }, [groupConfig]);
182
+ var rowElements = useMemo(function () {
183
+ var _state$data, _state$data$slice;
184
+ return state === null || state === void 0 ? void 0 : (_state$data = state.data) === null || _state$data === void 0 ? void 0 : (_state$data$slice = _state$data.slice(virtualStart, virtualEnd)) === null || _state$data$slice === void 0 ? void 0 : _state$data$slice.map(function (rowData) {
185
+ var _state$data2, _rowData;
186
+ var row = (state === null || state === void 0 ? void 0 : (_state$data2 = state.data) === null || _state$data2 === void 0 ? void 0 : _state$data2.indexOf(rowData)) || 0;
187
+ var rowCN = rowClassName instanceof Function ? rowClassName === null || rowClassName === void 0 ? void 0 : rowClassName(rowData === null || rowData === void 0 ? void 0 : (_rowData = rowData[rowData.length - 1]) === null || _rowData === void 0 ? void 0 : _rowData.record, row) : rowClassName;
188
+ return /*#__PURE__*/_jsx(Row, {
189
+ row: row,
190
+ cells: rowData,
191
+ groupConfig: groupConfig,
192
+ rowClassName: rowCN,
193
+ children: /*#__PURE__*/_jsx(DefaultRowMapper, {
194
+ rowData: rowData,
195
+ row: row
196
+ })
197
+ }, row);
198
+ });
199
+ }, [state.data, groupConfig, virtualStart, virtualEnd, rowClassName]);
200
+ var memoHeight = Math.min(((_state$data$length = state === null || state === void 0 ? void 0 : (_state$data3 = state.data) === null || _state$data3 === void 0 ? void 0 : _state$data3.length) !== null && _state$data$length !== void 0 ? _state$data$length : 0) + 1, 10) * 42 + 43;
201
+ var _useSelectVisible = useSelectVisible(sheetWrapperRef, state.start),
202
+ _useSelectVisible2 = _slicedToArray(_useSelectVisible, 2),
203
+ startRowVisible = _useSelectVisible2[0],
204
+ direction = _useSelectVisible2[1];
205
+ return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
206
+ value: eventBus,
207
+ children: /*#__PURE__*/_jsxs("span", {
208
+ children: [/*#__PURE__*/_jsxs("span", {
209
+ ref: sheetWrapperRef,
210
+ tabIndex: 0,
211
+ className: classNames('harvest harvest-sheet-container', className),
212
+ style: {
213
+ maxHeight: (_scroll$y = scroll === null || scroll === void 0 ? void 0 : scroll.y) !== null && _scroll$y !== void 0 ? _scroll$y : memoHeight,
214
+ width: (_scroll$x = scroll === null || scroll === void 0 ? void 0 : scroll.x) !== null && _scroll$x !== void 0 ? _scroll$x : '100%'
215
+ },
216
+ children: [/*#__PURE__*/_jsxs(SheetShell, {
217
+ className: classNames('harvest-sheet', className),
218
+ children: [virtualized && paddingTop > 0 && /*#__PURE__*/_jsx("tr", {
219
+ style: {
220
+ height: 0,
221
+ paddingBottom: paddingTop,
222
+ display: 'block'
223
+ }
224
+ }), rowElements, virtualized && paddingBottom > 0 && /*#__PURE__*/_jsx("tr", {
225
+ style: {
226
+ height: 0,
227
+ paddingBottom: paddingBottom,
228
+ display: 'block'
229
+ }
230
+ })]
231
+ }, "sheet"), ContextMenu ? /*#__PURE__*/_jsx("div", {
232
+ ref: contextMenuRef,
233
+ style: {
234
+ display: menu.showMenu ? '' : 'none'
235
+ },
236
+ children: /*#__PURE__*/_jsx(ContextMenu, {
237
+ position: menu.position,
238
+ cell: menu.cellPosition,
239
+ onContextMenu: onContextMenu
240
+ })
241
+ }) : null]
242
+ }), /*#__PURE__*/_jsxs("div", {
243
+ className: "harvest-sheet-control",
244
+ children: [children, showBackEdit && !startRowVisible ? /*#__PURE__*/_jsxs("div", {
245
+ className: "back-edit",
246
+ onClick: function onClick() {
247
+ var _sheetInstance$curren;
248
+ return sheetInstance === null || sheetInstance === void 0 ? void 0 : (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 ? void 0 : _sheetInstance$curren.zoomTo();
249
+ },
250
+ style: _objectSpread({}, !backEditStyle ? {
251
+ top: 0,
252
+ right: 0
253
+ } : backEditStyle),
254
+ children: [direction === 'up' ? /*#__PURE__*/_jsx(ArrowUpOutlined, {}) : /*#__PURE__*/_jsx(ArrowDownOutlined, {}), /*#__PURE__*/_jsx("span", {
255
+ style: {
256
+ marginLeft: 0
257
+ },
258
+ children: "\u8FD4\u56DE\u7F16\u8F91\u884C"
259
+ })]
260
+ }) : null]
261
+ })]
262
+ })
263
+ });
264
+ };
265
+ export default Sheet;
@@ -0,0 +1,307 @@
1
+ @import './var.less';
2
+
3
+ .harvest-sheet-container{
4
+ overflow: auto;
5
+ display: block;
6
+ position: relative ;
7
+ // scroll-behavior:smooth;
8
+ }
9
+
10
+ .harvest-sheet-container .header{
11
+ z-index: 2;
12
+
13
+ }
14
+
15
+
16
+
17
+
18
+ span.harvest-sheet-container, span.harvest-sheet-container:focus {
19
+ outline: none;
20
+ }
21
+
22
+ .harvest-sheet-container .harvest-sheet {
23
+ width: 100%;
24
+ border-collapse: collapse;
25
+ table-layout: fixed;
26
+
27
+ tr{
28
+ height:var(--row-height);
29
+
30
+ th.cell-title{
31
+ line-height: var(--row-height);
32
+ border-bottom: 1px solid transparent;
33
+ }
34
+
35
+ td{
36
+ line-height: var(--row-height);
37
+ }
38
+
39
+ &:last-of-type{
40
+ .td{
41
+ border-bottom: 1px solid transparent;
42
+ }
43
+
44
+ }
45
+ }
46
+
47
+ }
48
+
49
+ .harvest-sheet-container .harvest-sheet .cell {
50
+ height: 17px;
51
+ font-size: var(--cell-font-size);
52
+ padding-left:var(--cell-padding-horizontal);
53
+ padding-right:var(--cell-padding-horizontal);
54
+ padding-top:var(--cell-padding-vertical);
55
+ padding-bottom:var(--cell-padding-vertical);
56
+ border: 1px solid var(--cell-border-color);
57
+ background-color: var(--cell-background-color);
58
+ cursor: cell;
59
+ text-align: right;
60
+ // transition: box-shadow 100ms ease-out;
61
+ user-select: none;
62
+ vertical-align: bottom;
63
+ position: relative;
64
+
65
+ }
66
+
67
+
68
+ .harvest-sheet-container .harvest-sheet .cell.fixed{
69
+ position: sticky;
70
+ z-index: 2;
71
+
72
+ &.cell-title{
73
+ z-index: 3;
74
+
75
+ }
76
+
77
+
78
+ &::before{
79
+ position: absolute;
80
+ top: -1px;
81
+ left: 0;
82
+ width: 100%;
83
+ border-color: var(--cell-border-color);
84
+ border-top: 1px solid var(--cell-border-color);
85
+ content: "";
86
+ }
87
+
88
+ &.fixed-left::after{
89
+ position: absolute;
90
+ top: 0;
91
+ bottom: -1px;
92
+ right: -1px;
93
+ width: 30px;
94
+ border-left: 1px solid var(--cell-border-color);
95
+ content: "";
96
+ pointer-events: none;
97
+ transform: translate(100%);
98
+ transition: box-shadow .3s;
99
+ box-shadow: var(--cell-fixed-box-shadow-left);
100
+ }
101
+
102
+
103
+ &.fixed-right{
104
+ transform: translateX(1px);
105
+ }
106
+
107
+ &.fixed-right::after{
108
+ position: absolute;
109
+ top: 0;
110
+ bottom: -1px;
111
+ left: -1px;
112
+ width: 30px;
113
+ border-right: 1px solid var(--cell-border-color);
114
+ content: "";
115
+ pointer-events: none;
116
+ transform: translate(-100%);
117
+ transition: box-shadow .3s;
118
+ box-shadow: var(--cell-fixed-box-shadow-right);
119
+
120
+
121
+ }
122
+
123
+ &.fixed-unset{
124
+ position: unset;
125
+ }
126
+ }
127
+
128
+
129
+ .harvest-sheet-container .harvest-sheet .cell.selected {
130
+ border:1px double;
131
+ border-color:var(--cell-border-color);
132
+ box-shadow: var(--cell-box-shadow);
133
+ }
134
+
135
+ .harvest-sheet-container .harvest-sheet .cell.selected-start {
136
+ box-shadow: none;
137
+ }
138
+
139
+ .harvest-sheet-container .harvest-sheet .cell.selected-top{
140
+ border-top-color: var(--resizer);
141
+ border-top-width: 1px;
142
+ }
143
+
144
+ .harvest-sheet-container .harvest-sheet .cell.selected-left{
145
+ border-left-color: var(--resizer);
146
+ border-left-width:1px;
147
+ }
148
+
149
+ .harvest-sheet-container .harvest-sheet .cell.selected-bottom{
150
+ border-bottom-color: var(--resizer);
151
+ border-bottom-width:1px;
152
+ }
153
+
154
+ .harvest-sheet-container .harvest-sheet .cell.selected-right{
155
+ border-right-color: var(--resizer);
156
+ border-right-width:1px;
157
+ }
158
+
159
+
160
+ .harvest-sheet-container .harvest-sheet .cell.sheet-control{
161
+ border-right: 1px solid transparent;
162
+ background: var(--cell-background-color) ;
163
+ color:var(--read-color);
164
+
165
+ &.read-only{
166
+ border-right: 1px solid var(--cell-title-background-color);
167
+ }
168
+ // position: relative !important;
169
+ }
170
+
171
+ .harvest-sheet-container .harvest-sheet .cell.read-only {
172
+ background: var(--cell-read-only-background-color);
173
+ color: var(--read-color);
174
+ text-align: center;
175
+ cursor: not-allowed;
176
+ }
177
+
178
+
179
+ .harvest-sheet-container .harvest-sheet .cell-title.sheet-control{
180
+ border-right: 1px solid var(--cell-title-background-color);
181
+ }
182
+
183
+ .harvest-sheet-container .harvest-sheet .cell.cell-title{
184
+ background-color: var(--cell-title-background-color);
185
+
186
+ &:hover{
187
+ background-color: var(--cell-title-background-color);
188
+
189
+ }
190
+ }
191
+
192
+
193
+ .harvest-sheet-container .harvest-sheet .cell:not(.cell.read-only):hover{
194
+ background-color: var(--cell-hover);
195
+ }
196
+
197
+
198
+
199
+ .harvest-sheet-container .harvest-sheet .cell > .text {
200
+ overflow: hidden;
201
+ padding: 2px 5px;
202
+ text-overflow: ellipsis;
203
+ }
204
+
205
+
206
+ .harvest-sheet-container .harvest-sheet .cell > input {
207
+ display: block;
208
+ width: calc(100% - 6px);
209
+ font-size: var(--cell-font-size);
210
+ height: 11px;
211
+ border: 2px solid rgb(33, 133, 208);
212
+ background: none;
213
+ outline: none !important;
214
+ text-align:inherit;
215
+ }
216
+
217
+ .harvest-sheet-container .harvest-sheet .cell,
218
+ .harvest-sheet-container .harvest-sheet.wrap .cell,
219
+ .harvest-sheet-container .harvest-sheet .cell.wrap,
220
+ .harvest-sheet-container .harvest-sheet.wrap .cell.wrap,
221
+ .harvest-sheet-container .harvest-sheet.nowrap .cell.wrap,
222
+ .harvest-sheet-container .harvest-sheet.clip .cell.wrap {
223
+ white-space: normal;
224
+ }
225
+
226
+ .harvest-sheet-container .harvest-sheet.nowrap .cell,
227
+ .harvest-sheet-container .harvest-sheet .cell.nowrap,
228
+ .harvest-sheet-container .harvest-sheet.nowrap .cell.nowrap,
229
+ .harvest-sheet-container .harvest-sheet.wrap .cell.nowrap,
230
+ .harvest-sheet-container .harvest-sheet.clip .cell.nowrap {
231
+ overflow-x: visible;
232
+ white-space: nowrap;
233
+ }
234
+
235
+ .harvest-sheet-container .harvest-sheet.clip .cell,
236
+ .harvest-sheet-container .harvest-sheet .cell.clip,
237
+ .harvest-sheet-container .harvest-sheet.clip .cell.clip,
238
+ .harvest-sheet-container .harvest-sheet.wrap .cell.clip,
239
+ .harvest-sheet-container .harvest-sheet.nowrap .cell.clip {
240
+ overflow-x: hidden;
241
+ white-space: nowrap;
242
+ }
243
+
244
+ .harvest-sheet-container .harvest-sheet .cell .value-viewer{
245
+ overflow: hidden;
246
+ text-overflow: ellipsis;
247
+ white-space: nowrap;
248
+ }
249
+
250
+ .harvest-sheet-container .harvest-sheet .cell .value-viewer, .harvest-sheet-container .harvest-sheet .cell .data-editor {
251
+ display: block;
252
+ font-size: var(--cell-font-size);
253
+ line-height:var(--cell-inner-height) ;
254
+ height:var(--cell-inner-height) ;
255
+ padding:0
256
+ }
257
+
258
+ .harvest-sheet-container .harvest-sheet .cell .data-editor {
259
+ border:none;
260
+ border-radius: none;
261
+ height:var(--cell-inner-height);
262
+ }
263
+
264
+
265
+
266
+ .harvest-sheet-container .harvest-menu{
267
+ background-color: white;
268
+ position: fixed;
269
+ z-index: 3;
270
+ box-shadow: 0 3px 12px 2px rgba(31, 35, 41, 10%);
271
+
272
+ .harvest-menu-item{
273
+ margin: 1px 3px;
274
+ padding: 4px 8px;
275
+ cursor: pointer;
276
+ font-size: 14px;
277
+ line-height: 22px;
278
+
279
+ &:hover{
280
+ background-color: rgba(31, 35, 41, 5%)
281
+ }
282
+ }
283
+
284
+ }
285
+
286
+ .harvest-sheet-control{
287
+ position: relative;
288
+ z-index: 3;
289
+ bottom: 0;
290
+ left: 0;
291
+ background-color: white;
292
+ }
293
+
294
+ .harvest-sheet-control .back-edit{
295
+ padding: 5px 8px;
296
+ margin: 1px;
297
+ height: 30px;
298
+ display: flex;
299
+ width: 105px;
300
+ cursor: pointer;
301
+ align-items: center;
302
+ justify-content: center;
303
+ position: absolute;
304
+ z-index: 4;
305
+ border:1px solid #D8DFEB;
306
+ border-radius:2px;
307
+ }
@@ -0,0 +1,3 @@
1
+ import { Dispatch } from "../../hooks/useMiddlewareReducer";
2
+ import type { SheetType } from "../../type";
3
+ export declare const useCellEvent: (dispatch: Dispatch, listenerVar?: Partial<SheetType.UpdateStateType>) => void;
@@ -0,0 +1,22 @@
1
+ import { useEffect } from 'react';
2
+ import { sideEffectReducer } from "../reducers";
3
+ export var useCellEvent = function useCellEvent(dispatch, listenerVar) {
4
+ var _ref = listenerVar || {},
5
+ start = _ref.start,
6
+ end = _ref.end,
7
+ lastSelected = _ref.lastSelected,
8
+ editing = _ref.editing,
9
+ lastEditing = _ref.lastEditing;
10
+ useEffect(function () {
11
+ dispatch(sideEffectReducer.init);
12
+ return function () {
13
+ dispatch(sideEffectReducer.destroy);
14
+ };
15
+ }, []);
16
+ useEffect(function () {
17
+ dispatch(sideEffectReducer.emitSelectChange);
18
+ }, [start, end, lastSelected]);
19
+ useEffect(function () {
20
+ dispatch(sideEffectReducer.emitEditChange);
21
+ }, [editing, lastEditing]);
22
+ };
@@ -0,0 +1,21 @@
1
+ import { Dispatch } from "../..";
2
+ import type { SheetType } from "../../type";
3
+ export declare type MenuEvent = {
4
+ showMenu: boolean;
5
+ position: {
6
+ top: number;
7
+ left: number;
8
+ };
9
+ cellPosition: SheetType.CellPosition;
10
+ };
11
+ export declare const useContextMenu: (dispatch: Dispatch, elementRef: React.RefObject<SheetType.refAssertion>, enableContextMenu: boolean | undefined, contextMenuRef: React.RefObject<HTMLDivElement>) => {
12
+ showMenu: boolean;
13
+ position: {
14
+ top: number;
15
+ left: number;
16
+ };
17
+ cellPosition: {
18
+ row: number;
19
+ col: number;
20
+ };
21
+ };