@zhenliang/sheet 0.1.45 → 0.1.46

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.
@@ -11,3 +11,5 @@ export declare const Z_KEY = 90;
11
11
  export declare const C_KEY = 67;
12
12
  export declare const V_KEY = 86;
13
13
  export declare const X_KEY = 88;
14
+ export declare const A_KEY = 65;
15
+ export declare const Y_KEY = 89;
@@ -10,4 +10,6 @@ export var BACKSPACE_KEY = 8;
10
10
  export var Z_KEY = 90;
11
11
  export var C_KEY = 67;
12
12
  export var V_KEY = 86;
13
- export var X_KEY = 88;
13
+ export var X_KEY = 88;
14
+ export var A_KEY = 65;
15
+ export var Y_KEY = 89;
@@ -1,5 +1,5 @@
1
1
  import type { SheetType } from "../../type";
2
- export type SheetAction = 'change' | 'changes' | 'rowMove' | 'colMove' | 'editFinish' | 'pushHistory' | 'popHistory' | 'selectRow' | 'select' | 'clearSelect' | 'clearSelectIfNotSingleRow' | 'clearEdit' | 'mouseDown' | 'mouseOver' | 'mouseUp' | 'loseFocus' | 'doubleClick' | 'mouseLeaveInterval' | 'move' | 'escape' | 'reverse' | 'delete' | 'enter' | 'otherInput' | 'none';
2
+ export type SheetAction = 'change' | 'changes' | 'rowMove' | 'colMove' | 'editFinish' | 'pushHistory' | 'popHistory' | 'select' | 'clearSelect' | 'clearSelectIfNotSingleRow' | 'clearEdit' | 'mouseDown' | 'mouseOver' | 'mouseUp' | 'selectRow' | 'selectCol' | 'loseFocus' | 'doubleClick' | 'mouseLeaveInterval' | 'move' | 'selectAll' | 'escape' | 'reverse' | 'delete' | 'enter' | 'otherInput' | 'none';
3
3
  export type reducerAction = (type: Partial<SheetType.UpdateStateType>, payload?: unknown) => Partial<SheetType.UpdateStateType>;
4
4
  declare const sheetReducer: (state: Partial<SheetType.UpdateStateType>, action: {
5
5
  type: SheetAction;
@@ -10,7 +10,6 @@ var sheetReducer = function sheetReducer(state, action) {
10
10
  case 'editFinish':
11
11
  case 'pushHistory':
12
12
  case 'popHistory':
13
- case 'selectRow':
14
13
  case 'select':
15
14
  case 'clearSelect':
16
15
  case 'clearSelectIfNotSingleRow':
@@ -22,12 +21,15 @@ var sheetReducer = function sheetReducer(state, action) {
22
21
  case 'loseFocus':
23
22
  case 'doubleClick':
24
23
  case 'mouseLeaveInterval':
24
+ case 'selectRow':
25
+ case 'selectCol':
25
26
  return mouseReducer[action.type](state, action.payload);
26
27
  case 'move':
27
28
  case 'escape':
28
29
  case 'reverse':
29
30
  case 'delete':
30
31
  case 'enter':
32
+ case 'selectAll':
31
33
  case 'otherInput':
32
34
  return keyboardReducer[action.type](state, action.payload);
33
35
  default:
@@ -5,7 +5,7 @@ function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key i
5
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
7
  import { isNil } from 'lodash';
8
- import { getNextVisibleRow, groupConfigToGroupMap } from "../util";
8
+ import { getNextVisibleRow, groupConfigToGroupMap, stripRowIndex } from "../util";
9
9
  export var keyboardReducer = {
10
10
  move: function move(state, payload) {
11
11
  var _state$start, _state$start2;
@@ -90,5 +90,34 @@ export var keyboardReducer = {
90
90
  otherInput: function otherInput(state, payload) {
91
91
  if (state.editing) return state;
92
92
  return keyboardReducer.enter(state, payload);
93
+ },
94
+ selectAll: function selectAll(state) {
95
+ var _state$data2 = state.data,
96
+ data = _state$data2 === void 0 ? [] : _state$data2;
97
+ var lastEditing;
98
+ if (state.editing) {
99
+ lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
100
+ confirm: true
101
+ });
102
+ }
103
+ var _stripRowIndex = stripRowIndex(data),
104
+ startIndex = _stripRowIndex.startIndex,
105
+ endIndex = _stripRowIndex.endIndex;
106
+ return _objectSpread(_objectSpread({}, state), {}, {
107
+ start: {
108
+ row: 0,
109
+ col: startIndex
110
+ },
111
+ end: {
112
+ row: data.length - 1,
113
+ col: endIndex
114
+ },
115
+ lastSelected: {
116
+ start: state.start,
117
+ end: state.end
118
+ },
119
+ editing: undefined,
120
+ lastEditing: lastEditing
121
+ });
93
122
  }
94
123
  };
@@ -4,6 +4,7 @@ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t =
4
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
5
  function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
6
6
  function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
7
+ import { stripRowIndex } from "../util";
7
8
  export var mouseReducer = {
8
9
  mouseDown: function mouseDown(state, payload) {
9
10
  var _ref = payload,
@@ -14,6 +15,11 @@ export var mouseReducer = {
14
15
  var data = state.data,
15
16
  start = state.start,
16
17
  end = state.end;
18
+ if ((data === null || data === void 0 ? void 0 : data[row][col].dataIndex) === 'index') {
19
+ return mouseReducer.selectRow(state, {
20
+ row: row
21
+ });
22
+ }
17
23
  if (data !== null && data !== void 0 && data[row][col].fixed) {
18
24
  return _objectSpread(_objectSpread({}, state), {}, {
19
25
  start: undefined,
@@ -160,5 +166,65 @@ export var mouseReducer = {
160
166
  return _objectSpread(_objectSpread({}, state), {}, {
161
167
  end: end
162
168
  });
169
+ },
170
+ selectRow: function selectRow(state, payload) {
171
+ var _ref6 = payload,
172
+ row = _ref6.row;
173
+ var _state$data = state.data,
174
+ data = _state$data === void 0 ? [] : _state$data;
175
+ var lastEditing;
176
+ var _stripRowIndex = stripRowIndex(data),
177
+ startIndex = _stripRowIndex.startIndex,
178
+ endIndex = _stripRowIndex.endIndex;
179
+ if (state.editing) {
180
+ lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
181
+ confirm: true
182
+ });
183
+ }
184
+ return _objectSpread(_objectSpread({}, state), {}, {
185
+ start: {
186
+ row: row,
187
+ col: startIndex
188
+ },
189
+ end: {
190
+ row: row,
191
+ col: endIndex
192
+ },
193
+ lastSelected: {
194
+ start: state.start,
195
+ end: state.end
196
+ },
197
+ editing: undefined,
198
+ lastEditing: lastEditing
199
+ });
200
+ },
201
+ selectCol: function selectCol(state, payload) {
202
+ var _ref7 = payload,
203
+ col = _ref7.col,
204
+ colSpan = _ref7.colSpan;
205
+ var _state$data2 = state.data,
206
+ data = _state$data2 === void 0 ? [] : _state$data2;
207
+ var lastEditing;
208
+ if (state.editing) {
209
+ lastEditing = _objectSpread(_objectSpread({}, state.editing), {}, {
210
+ confirm: true
211
+ });
212
+ }
213
+ return _objectSpread(_objectSpread({}, state), {}, {
214
+ start: {
215
+ row: 0,
216
+ col: col
217
+ },
218
+ end: {
219
+ row: data.length - 1,
220
+ col: col + (colSpan > 1 ? colSpan - 1 : 0)
221
+ },
222
+ lastSelected: {
223
+ start: state.start,
224
+ end: state.end
225
+ },
226
+ editing: undefined,
227
+ lastEditing: lastEditing
228
+ });
163
229
  }
164
230
  };
@@ -58,6 +58,18 @@ export var sideEffectReducer = {
58
58
  });
59
59
  }
60
60
  });
61
+ eventBus.on("row-select", function (value) {
62
+ dispatch({
63
+ type: 'selectRow',
64
+ payload: value
65
+ });
66
+ });
67
+ eventBus.on("col-select", function (value) {
68
+ dispatch({
69
+ type: 'selectCol',
70
+ payload: value
71
+ });
72
+ });
61
73
  },
62
74
  destroy: function destroy(d, getState) {
63
75
  var _getState4 = getState(),
@@ -1,4 +1,4 @@
1
1
  import type { SheetType } from "../../type";
2
2
  import React from 'react';
3
- declare const _default: React.MemoExoticComponent<(props: SheetType.CellProps) => JSX.Element>;
3
+ declare const _default: React.MemoExoticComponent<(props: SheetType.CellProps) => import("react/jsx-runtime").JSX.Element>;
4
4
  export default _default;
@@ -1,4 +1,3 @@
1
- /// <reference types="react" />
2
1
  import type { SheetType } from "../../type";
3
2
  declare const DefaultCell: (props: {
4
3
  cell: SheetType.Cell;
@@ -8,5 +7,5 @@ declare const DefaultCell: (props: {
8
7
  className: string;
9
8
  style: Record<string, string>;
10
9
  children: React.ReactElement;
11
- }) => JSX.Element;
10
+ }) => import("react/jsx-runtime").JSX.Element;
12
11
  export default DefaultCell;
@@ -20,7 +20,7 @@ var DefaultCell = function DefaultCell(props) {
20
20
  return /*#__PURE__*/_jsx("td", _objectSpread(_objectSpread({
21
21
  "data-row": row,
22
22
  "data-col": col,
23
- className: classNames(className, cell.fixed && 'fixed', cell.fixed && "fixed-".concat(cell.fixed)),
23
+ className: classNames(className, cell.fixed && 'fixed', cell.fixed && "fixed-".concat(cell.fixed), cell.dataIndex === 'index' ? "index" : null),
24
24
  colSpan: colSpan,
25
25
  rowSpan: rowSpan,
26
26
  style: style
@@ -6,7 +6,6 @@ function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" !=
6
6
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
7
7
  import { useEffect, useImperativeHandle, useMemo, useRef } from 'react';
8
8
  // import ReduxLogger from 'redux-logger';
9
- import cls from 'classnames';
10
9
  import ReduxThunk from 'redux-thunk';
11
10
  import DefaultRow from "./DefaultRow";
12
11
  import DefaultShell from "./DefaultShell";
@@ -239,10 +238,7 @@ var Sheet = function Sheet(props) {
239
238
  children: [/*#__PURE__*/_jsxs("span", {
240
239
  ref: sheetWrapperRef,
241
240
  tabIndex: 0,
242
- className: classNames('harvest harvest-sheet-container', className, cls({
243
- tableWarpScroll: hasHorizontalScrollbar && boldScroll,
244
- hideColBar: hideColBar
245
- })),
241
+ className: classNames('harvest harvest-sheet-container', className, hasHorizontalScrollbar && boldScroll ? 'tableWarpScroll' : null, hideColBar ? 'hideColBar' : null),
246
242
  style: {
247
243
  maxHeight: (_scroll$y = scroll === null || scroll === void 0 ? void 0 : scroll.y) !== null && _scroll$y !== void 0 ? _scroll$y : memoHeight,
248
244
  width: (_scroll$x = scroll === null || scroll === void 0 ? void 0 : scroll.x) !== null && _scroll$x !== void 0 ? _scroll$x : '100%'
@@ -10,7 +10,7 @@
10
10
  &::-webkit-scrollbar {
11
11
  display: none;
12
12
  }
13
-
13
+
14
14
  &:hover {
15
15
  &::-webkit-scrollbar {
16
16
  display: block;
@@ -22,24 +22,25 @@
22
22
  height: 10px;
23
23
  border-bottom: 10px solid #fff;
24
24
  }
25
-
25
+
26
26
  }
27
-
27
+
28
28
  }
29
29
 
30
- .harvest-sheet-container{
30
+ .harvest-sheet-container {
31
31
  display: block;
32
- position: relative ;
32
+ position: relative;
33
33
  // scroll-behavior:smooth;
34
34
  overflow: auto;
35
35
  }
36
36
 
37
- .harvest-sheet-container .header{
37
+ .harvest-sheet-container .header {
38
38
  z-index: 2;
39
-
39
+
40
40
  }
41
41
 
42
- span.harvest-sheet-container, span.harvest-sheet-container:focus {
42
+ span.harvest-sheet-container,
43
+ span.harvest-sheet-container:focus {
43
44
  outline: none;
44
45
  }
45
46
 
@@ -47,33 +48,33 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
47
48
  width: calc(100% - 1px);
48
49
  border-collapse: collapse;
49
50
  table-layout: fixed;
50
-
51
- tr{
52
- height:var(--row-height);
53
51
 
54
- th.cell-title{
52
+ tr {
53
+ height: var(--row-height);
54
+
55
+ th.cell-title {
55
56
  line-height: var(--row-height);
56
57
  border-bottom: 1px solid transparent;
57
58
  }
58
59
 
59
- td{
60
+ td {
60
61
  line-height: var(--row-height);
61
62
  }
62
-
63
- &:last-of-type{
64
- .td{
65
- border-bottom: 1px solid transparent;
63
+
64
+ &:last-of-type {
65
+ .td {
66
+ border-bottom: 1px solid transparent;
66
67
  }
67
68
 
68
69
  }
69
70
  }
70
71
 
71
- }
72
+ }
72
73
 
73
74
  .harvest-sheet-container .harvest-sheet .cell {
74
75
  height: 17px;
75
76
  font-size: var(--cell-font-size);
76
- padding:var(--cell-padding-vertical) var(--cell-padding-horizontal) var(--cell-padding-vertical) var(--cell-padding-horizontal);
77
+ padding: var(--cell-padding-vertical) var(--cell-padding-horizontal) var(--cell-padding-vertical) var(--cell-padding-horizontal);
77
78
  border: 1px solid var(--cell-border-color);
78
79
  background-color: var(--cell-background-color);
79
80
  cursor: cell;
@@ -83,20 +84,20 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
83
84
  vertical-align: bottom;
84
85
  position: relative;
85
86
 
86
- }
87
+ }
87
88
 
88
89
 
89
- .harvest-sheet-container .harvest-sheet .cell.fixed{
90
+ .harvest-sheet-container .harvest-sheet .cell.fixed {
90
91
  position: sticky;
91
92
  z-index: 2;
92
93
 
93
- &.cell-title{
94
+ &.cell-title {
94
95
  z-index: 3;
95
96
 
96
97
  }
97
-
98
-
99
- &::before{
98
+
99
+
100
+ &::before {
100
101
  position: absolute;
101
102
  top: -1px;
102
103
  left: 0;
@@ -106,7 +107,7 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
106
107
  content: "";
107
108
  }
108
109
 
109
- &.fixed-left::after{
110
+ &.fixed-left::after {
110
111
  position: absolute;
111
112
  top: 0;
112
113
  bottom: -1px;
@@ -120,12 +121,12 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
120
121
  box-shadow: var(--cell-fixed-box-shadow-left);
121
122
  }
122
123
 
123
-
124
- &.fixed-right{
124
+
125
+ &.fixed-right {
125
126
  transform: translateX(1px);
126
127
  }
127
128
 
128
- &.fixed-right::after{
129
+ &.fixed-right::after {
129
130
  position: absolute;
130
131
  top: 0;
131
132
  bottom: -1px;
@@ -141,15 +142,16 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
141
142
 
142
143
  }
143
144
 
144
- &.fixed-unset{
145
+ &.fixed-unset {
145
146
  position: unset;
146
147
  }
147
148
  }
148
149
 
149
150
 
151
+
150
152
  .harvest-sheet-container .harvest-sheet .cell.selected {
151
- border:1px double;
152
- border-color:var(--cell-border-color);
153
+ border: 1px double;
154
+ border-color: var(--cell-border-color);
153
155
  box-shadow: var(--cell-box-shadow);
154
156
  }
155
157
 
@@ -157,35 +159,36 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
157
159
  box-shadow: none;
158
160
  }
159
161
 
160
- .harvest-sheet-container .harvest-sheet .cell.selected-top{
162
+ .harvest-sheet-container .harvest-sheet .cell.selected-top {
161
163
  border-top-color: var(--resizer);
162
164
  border-top-width: 1px;
163
165
  }
164
166
 
165
- .harvest-sheet-container .harvest-sheet .cell.selected-left{
167
+ .harvest-sheet-container .harvest-sheet .cell.selected-left {
166
168
  border-left-color: var(--resizer);
167
- border-left-width:1px;
168
- }
169
+ border-left-width: 1px;
170
+ }
169
171
 
170
- .harvest-sheet-container .harvest-sheet .cell.selected-bottom{
172
+ .harvest-sheet-container .harvest-sheet .cell.selected-bottom {
171
173
  border-bottom-color: var(--resizer);
172
- border-bottom-width:1px;
174
+ border-bottom-width: 1px;
173
175
  }
174
176
 
175
- .harvest-sheet-container .harvest-sheet .cell.selected-right{
177
+ .harvest-sheet-container .harvest-sheet .cell.selected-right {
176
178
  border-right-color: var(--resizer);
177
- border-right-width:1px;
179
+ border-right-width: 1px;
178
180
  }
179
181
 
180
182
 
181
- .harvest-sheet-container .harvest-sheet .cell.sheet-control{
183
+ .harvest-sheet-container .harvest-sheet .cell.sheet-control {
182
184
  border-right: 1px solid transparent;
183
- background: var(--cell-background-color) ;
184
- color:var(--read-color);
185
+ background: var(--cell-background-color);
186
+ color: var(--read-color);
185
187
 
186
- &.read-only{
187
- border-right: 1px solid var(--cell-title-background-color);
188
+ &.read-only {
189
+ border-right: 1px solid var(--cell-title-background-color);
188
190
  }
191
+
189
192
  // position: relative !important;
190
193
  }
191
194
 
@@ -196,35 +199,39 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
196
199
  cursor: not-allowed;
197
200
  }
198
201
 
202
+ .harvest-sheet-container .harvest-sheet .cell.index {
203
+ cursor: e-resize;
204
+ }
205
+
199
206
 
200
- .harvest-sheet-container .harvest-sheet .cell-title.sheet-control{
207
+ .harvest-sheet-container .harvest-sheet .cell-title.sheet-control {
201
208
  border-right: 1px solid var(--cell-title-background-color);
202
209
  }
203
210
 
204
- .harvest-sheet-container .harvest-sheet .cell.cell-title{
205
- background-color: var(--cell-title-background-color);
206
-
207
- &:hover{
211
+ .harvest-sheet-container .harvest-sheet .cell.cell-title {
208
212
  background-color: var(--cell-title-background-color);
209
213
 
214
+ &:hover {
215
+ background-color: var(--cell-title-background-color);
216
+
210
217
  }
211
218
  }
212
219
 
213
220
 
214
- .harvest-sheet-container .harvest-sheet .cell:not(.cell.read-only):hover{
221
+ .harvest-sheet-container .harvest-sheet .cell:not(.cell.read-only):hover {
215
222
  background-color: var(--cell-hover);
216
223
  }
217
224
 
218
225
 
219
226
 
220
- .harvest-sheet-container .harvest-sheet .cell > .text {
227
+ .harvest-sheet-container .harvest-sheet .cell>.text {
221
228
  overflow: hidden;
222
229
  padding: 2px 5px;
223
230
  text-overflow: ellipsis;
224
231
  }
225
232
 
226
233
 
227
- .harvest-sheet-container .harvest-sheet .cell > input {
234
+ .harvest-sheet-container .harvest-sheet .cell>input {
228
235
  display: block;
229
236
  width: calc(100% - 6px);
230
237
  font-size: var(--cell-font-size);
@@ -232,7 +239,7 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
232
239
  border: 2px solid rgb(33, 133, 208);
233
240
  background: none;
234
241
  outline: none !important;
235
- text-align:inherit;
242
+ text-align: inherit;
236
243
  }
237
244
 
238
245
  .harvest-sheet-container .harvest-sheet .cell,
@@ -262,49 +269,50 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
262
269
  white-space: nowrap;
263
270
  }
264
271
 
265
- .harvest-sheet-container .harvest-sheet .cell .value-viewer{
272
+ .harvest-sheet-container .harvest-sheet .cell .value-viewer {
266
273
  overflow: hidden;
267
274
  text-overflow: ellipsis;
268
275
  white-space: nowrap;
269
276
  }
270
277
 
271
- .harvest-sheet-container .harvest-sheet .cell .value-viewer, .harvest-sheet-container .harvest-sheet .cell .data-editor {
278
+ .harvest-sheet-container .harvest-sheet .cell .value-viewer,
279
+ .harvest-sheet-container .harvest-sheet .cell .data-editor {
272
280
  display: block;
273
281
  font-size: var(--cell-font-size);
274
- line-height:var(--cell-inner-height) ;
275
- height:var(--cell-inner-height) ;
276
- padding:0
282
+ line-height: var(--cell-inner-height);
283
+ height: var(--cell-inner-height);
284
+ padding: 0
277
285
  }
278
286
 
279
287
  .harvest-sheet-container .harvest-sheet .cell .data-editor {
280
- border:none;
288
+ border: none;
281
289
  border-radius: none;
282
- height:var(--cell-inner-height);
290
+ height: var(--cell-inner-height);
283
291
  }
284
292
 
285
293
 
286
294
 
287
- .harvest-sheet-container .harvest-menu{
295
+ .harvest-sheet-container .harvest-menu {
288
296
  background-color: white;
289
297
  position: fixed;
290
298
  z-index: 3;
291
299
  box-shadow: 0 3px 12px 2px rgba(31, 35, 41, 10%);
292
300
 
293
- .harvest-menu-item{
301
+ .harvest-menu-item {
294
302
  margin: 1px 3px;
295
303
  padding: 4px 8px;
296
304
  cursor: pointer;
297
305
  font-size: 14px;
298
306
  line-height: 22px;
299
307
 
300
- &:hover{
308
+ &:hover {
301
309
  background-color: rgba(31, 35, 41, 5%)
302
310
  }
303
311
  }
304
312
 
305
313
  }
306
314
 
307
- .harvest-sheet-control{
315
+ .harvest-sheet-control {
308
316
  position: relative;
309
317
  z-index: 3;
310
318
  bottom: 0;
@@ -312,7 +320,7 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
312
320
  background-color: white;
313
321
  }
314
322
 
315
- .harvest-sheet-control .back-edit{
323
+ .harvest-sheet-control .back-edit {
316
324
  padding: 5px 8px;
317
325
  margin: 1px;
318
326
  height: 30px;
@@ -323,12 +331,12 @@ span.harvest-sheet-container, span.harvest-sheet-container:focus {
323
331
  justify-content: center;
324
332
  position: absolute;
325
333
  z-index: 4;
326
- border:1px solid #D8DFEB;
327
- border-radius:2px;
334
+ border: 1px solid #D8DFEB;
335
+ border-radius: 2px;
328
336
  }
329
337
 
330
338
  :global {
331
- .ant-empty-description{
339
+ .ant-empty-description {
332
340
  color: #A4A9B2;
333
341
  }
334
342
  }
@@ -21,6 +21,12 @@ export var useKeyBoardEvent = function useKeyBoardEvent(dispatch, elementRef) {
21
21
  });
22
22
  }
23
23
  },
24
+ selectAll: function selectAll(e) {
25
+ e.preventDefault();
26
+ dispatch({
27
+ type: 'selectAll'
28
+ });
29
+ },
24
30
  escape: function escape() {
25
31
  dispatch({
26
32
  type: 'escape'
@@ -9,7 +9,7 @@ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len
9
9
  function _iterableToArrayLimit(r, l) { var t = null == r ? null : "undefined" != typeof Symbol && r[Symbol.iterator] || r["@@iterator"]; if (null != t) { var e, n, i, u, a = [], f = !0, o = !1; try { if (i = (t = t.call(r)).next, 0 === l) { if (Object(t) !== t) return; f = !1; } else for (; !(f = (e = i.call(t)).done) && (a.push(e.value), a.length !== l); f = !0); } catch (r) { o = !0, n = r; } finally { try { if (!f && null != t.return && (u = t.return(), Object(u) !== u)) return; } finally { if (o) throw n; } } return a; } }
10
10
  function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
11
11
  import { createElement, useEffect, useMemo, useRef } from 'react';
12
- import { useSetState, useWidth } from "../../../hooks";
12
+ import { useSetState, useSheetEvent, useWidth } from "../../../hooks";
13
13
  import { classNames } from "../../util";
14
14
  import { CheckViewer } from "../../viewer/checkViewer";
15
15
  import { GroupViewer } from "../../viewer/groupViewer";
@@ -36,6 +36,7 @@ export var DraggableShell = function DraggableShell(_ref) {
36
36
  var _useWidth = useWidth(),
37
37
  contextWidths = _useWidth.widths,
38
38
  contextSetWidth = _useWidth.onChange;
39
+ var eventBus = useSheetEvent();
39
40
  var setWidth = contextSetWidth || _setWidth;
40
41
  var widths = contextWidths || _widths;
41
42
  var hasControl = showGroup || showSelect;
@@ -70,6 +71,17 @@ export var DraggableShell = function DraggableShell(_ref) {
70
71
  ((_item$titleConfig = item.titleConfig) === null || _item$titleConfig === void 0 ? void 0 : _item$titleConfig.colSpan) !== 0 && ths.push( /*#__PURE__*/_jsx("th", {
71
72
  className: classNames('cell', 'cell-title', 'read-only', item.fixed && 'fixed', item.fixed && "fixed-".concat(item.fixed), (_item$titleConfig2 = item.titleConfig) === null || _item$titleConfig2 === void 0 ? void 0 : _item$titleConfig2.className),
72
73
  colSpan: (_item$titleConfig3 = item.titleConfig) === null || _item$titleConfig3 === void 0 ? void 0 : _item$titleConfig3.colSpan,
74
+ onClick: function onClick(e) {
75
+ if (item.fixed) return;
76
+ var target = e.target;
77
+ if (e.nativeEvent.offsetX <= target.offsetWidth - 8) {
78
+ var _item$titleConfig4;
79
+ eventBus.emit('col-select', {
80
+ col: hasControl ? index + 1 : index,
81
+ colSpan: (_item$titleConfig4 = item.titleConfig) === null || _item$titleConfig4 === void 0 ? void 0 : _item$titleConfig4.colSpan
82
+ });
83
+ }
84
+ },
73
85
  style: {
74
86
  textAlign: (_ref3 = item.align) !== null && _ref3 !== void 0 ? _ref3 : 'unset',
75
87
  left: item.fixed === 'left' ? 0 : 'unset',
@@ -82,6 +94,7 @@ export var DraggableShell = function DraggableShell(_ref) {
82
94
  downRef.current.mouseDown = true;
83
95
  downRef.current.oldX = e.nativeEvent.x;
84
96
  downRef.current.oldWidth = downRef.current.offsetWidth;
97
+ e.preventDefault();
85
98
  } else {
86
99
  downRef.current = null;
87
100
  }
@@ -91,7 +104,7 @@ export var DraggableShell = function DraggableShell(_ref) {
91
104
  if (e.nativeEvent.offsetX > target.offsetWidth - 8) {
92
105
  target.style.cursor = 'col-resize';
93
106
  } else {
94
- target.style.cursor = 'default';
107
+ target.style.cursor = item.fixed ? 'default' : 's-resize';
95
108
  }
96
109
  //取出暂存的Table Cell
97
110
  if (downRef.current === undefined) downRef.current = target;
@@ -117,9 +130,9 @@ export var DraggableShell = function DraggableShell(_ref) {
117
130
  }
118
131
  var i = 0;
119
132
  columns.forEach(function (item, index) {
120
- var _item$titleConfig4, _item$dataIndex2;
133
+ var _item$titleConfig5, _item$dataIndex2;
121
134
  var currentWidth = item.width || 'unset';
122
- if (((_item$titleConfig4 = item.titleConfig) === null || _item$titleConfig4 === void 0 ? void 0 : _item$titleConfig4.colSpan) !== 0) {
135
+ if (((_item$titleConfig5 = item.titleConfig) === null || _item$titleConfig5 === void 0 ? void 0 : _item$titleConfig5.colSpan) !== 0) {
123
136
  currentWidth = widths[i] || item.width || 'unset';
124
137
  i++;
125
138
  }
@@ -147,12 +160,12 @@ export var DraggableShell = function DraggableShell(_ref) {
147
160
  var _downRef$current$oldW, _downRef$current$oldX;
148
161
  downRef.current.style.cursor = 'default';
149
162
  if (((_downRef$current$oldW = downRef.current.oldWidth) !== null && _downRef$current$oldW !== void 0 ? _downRef$current$oldW : 0) + (e.x - ((_downRef$current$oldX = downRef.current.oldX) !== null && _downRef$current$oldX !== void 0 ? _downRef$current$oldX : 0)) > 0) {
150
- var _downRef$current$oldW2, _downRef$current$oldX2, _headRef$current, _columns$actualIndex$;
163
+ var _downRef$current$oldW2, _downRef$current$oldX2, _headRef$current, _columns$actualIndex;
151
164
  var newWidth = Math.max(Number(((_downRef$current$oldW2 = downRef.current.oldWidth) !== null && _downRef$current$oldW2 !== void 0 ? _downRef$current$oldW2 : 0) + (e.x - ((_downRef$current$oldX2 = downRef.current.oldX) !== null && _downRef$current$oldX2 !== void 0 ? _downRef$current$oldX2 : 0))), 50);
152
165
  var cellList = [].slice.call((_headRef$current = headRef.current) === null || _headRef$current === void 0 ? void 0 : _headRef$current.cells);
153
166
  var changeIndex = cellList.indexOf(downRef.current);
154
167
  var actualIndex = hasControl ? changeIndex - 1 : changeIndex;
155
- var isDoubleSpan = (((_columns$actualIndex$ = columns[actualIndex].titleConfig) === null || _columns$actualIndex$ === void 0 ? void 0 : _columns$actualIndex$.colSpan) || 0) > 1;
168
+ var isDoubleSpan = (((_columns$actualIndex = columns[actualIndex]) === null || _columns$actualIndex === void 0 || (_columns$actualIndex = _columns$actualIndex.titleConfig) === null || _columns$actualIndex === void 0 ? void 0 : _columns$actualIndex.colSpan) || 0) > 1;
156
169
  var nextColumn = columns[actualIndex + 1] || {};
157
170
  var nextWidth = +String(nextColumn === null || nextColumn === void 0 ? void 0 : nextColumn.width).replace('px', '');
158
171
  //调整该列中的每个Cell
@@ -3,6 +3,7 @@ import { classNames } from "../util";
3
3
  import { CheckViewer } from "../viewer/checkViewer";
4
4
  import { GroupViewer } from "../viewer/groupViewer";
5
5
  import "./draggableShell/index.less";
6
+ import { useSheetEvent } from "../../hooks";
6
7
  import { jsx as _jsx } from "react/jsx-runtime";
7
8
  import { jsxs as _jsxs } from "react/jsx-runtime";
8
9
  import { Fragment as _Fragment } from "react/jsx-runtime";
@@ -14,6 +15,7 @@ export var TableShell = function TableShell(_ref) {
14
15
  controlProps = _ref.controlProps,
15
16
  _ref$controlWidth = _ref.controlWidth,
16
17
  controlWidth = _ref$controlWidth === void 0 ? 30 : _ref$controlWidth;
18
+ var eventBus = useSheetEvent();
17
19
  var TableShell = function TableShell(_ref2) {
18
20
  var children = _ref2.children;
19
21
  var thItems = useMemo(function () {
@@ -47,8 +49,14 @@ export var TableShell = function TableShell(_ref) {
47
49
  ((_item$titleConfig = item.titleConfig) === null || _item$titleConfig === void 0 ? void 0 : _item$titleConfig.colSpan) !== 0 && ths.push( /*#__PURE__*/_jsx("th", {
48
50
  className: classNames('cell', 'cell-title', 'read-only', item.fixed && 'fixed', item.fixed && "fixed-".concat(item.fixed)),
49
51
  colSpan: (_item$titleConfig2 = item.titleConfig) === null || _item$titleConfig2 === void 0 ? void 0 : _item$titleConfig2.colSpan,
52
+ onClick: function onClick() {
53
+ eventBus.emit('col-select', {
54
+ col: index
55
+ });
56
+ },
50
57
  style: {
51
58
  textAlign: (_ref3 = item.align) !== null && _ref3 !== void 0 ? _ref3 : 'unset',
59
+ cursor: 'e-resizer',
52
60
  left: item.fixed === 'left' ? 0 : 'unset',
53
61
  right: item.fixed === 'right' ? 0 : 'unset'
54
62
  },
@@ -48,7 +48,6 @@ export var useGroupConfig = function useGroupConfig(dataSource, tableGroupConfig
48
48
  return computedRowGroup.groups[index].groupStart !== group.groupStart || computedRowGroup.groups[index].groupEnd !== group.groupEnd;
49
49
  });
50
50
  if (!notSameGroup) {
51
- console.log(notSameGroup, rowGroup.groups, computedRowGroup);
52
51
  rowConfig = rowGroup;
53
52
  } else {
54
53
  var _tableGroupConfig$onC;
@@ -56,3 +56,7 @@ export declare const calcMenuPosition: ({ tableElement, menuElement, x, y, }: {
56
56
  top: number;
57
57
  left: number;
58
58
  };
59
+ export declare const stripRowIndex: (data: SheetType.Cell[][]) => {
60
+ startIndex: number;
61
+ endIndex: number;
62
+ };
package/dist/core/util.js CHANGED
@@ -456,4 +456,23 @@ export var calcMenuPosition = function calcMenuPosition(_ref5) {
456
456
  top: top,
457
457
  left: left
458
458
  };
459
+ };
460
+ export var stripRowIndex = function stripRowIndex(data) {
461
+ if (!data.length || !data[0].length) return {
462
+ startIndex: 0,
463
+ endIndex: 0
464
+ };
465
+ var rowData = data[0];
466
+ var startIndex = 0,
467
+ endIndex = rowData.length - 1;
468
+ if (rowData[0].fixed && !rowData[0].editable) {
469
+ startIndex = 1;
470
+ }
471
+ if (rowData[rowData.length - 1].fixed && !rowData[0].editable) {
472
+ endIndex = rowData.length - 2;
473
+ }
474
+ return {
475
+ startIndex: startIndex,
476
+ endIndex: endIndex
477
+ };
459
478
  };
@@ -1,3 +1,2 @@
1
- /// <reference types="react" />
2
- declare const _default: () => JSX.Element;
1
+ declare const _default: () => import("react/jsx-runtime").JSX.Element;
3
2
  export default _default;
@@ -2,6 +2,7 @@ type KeyOrClipBoardEvent = (event: KeyboardEvent | ClipboardEvent, value?: any)
2
2
  type KeyboardHandler = {
3
3
  move: KeyOrClipBoardEvent;
4
4
  escape: KeyOrClipBoardEvent;
5
+ selectAll: KeyOrClipBoardEvent;
5
6
  delete: KeyOrClipBoardEvent;
6
7
  enter: KeyOrClipBoardEvent;
7
8
  otherInput: KeyOrClipBoardEvent;
@@ -1,5 +1,5 @@
1
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";
2
+ import { A_KEY, 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
3
  import { isInputKey } from "../core/util";
4
4
  var ua = window.navigator.userAgent;
5
5
  var isIE = /MSIE|Trident/.test(ua);
@@ -56,6 +56,11 @@ export var useKeyBoard = function useKeyBoard(handler, listenElement) {
56
56
  handler.reverse(e);
57
57
  return;
58
58
  }
59
+ var isSelectAll = ctrlKeyPressed && keyCode === A_KEY;
60
+ if (isSelectAll) {
61
+ handler.selectAll(e);
62
+ return;
63
+ }
59
64
  var isCopy = ctrlKeyPressed && keyCode === C_KEY;
60
65
  if (isCopy && isIE) {
61
66
  handler.copy(e);
@@ -22,6 +22,7 @@ export type Cell = {
22
22
  record?: Record<string, unknown>;
23
23
  disableEvents?: boolean;
24
24
  dataEditor?: CellEditor;
25
+ dataIndex?: string;
25
26
  valueViewer?: CellViewer;
26
27
  className?: string;
27
28
  align?: CellAlign;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.45",
3
+ "version": "0.1.46",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",