@zhenliang/sheet 0.1.58 → 0.1.60

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.
@@ -1,10 +1,15 @@
1
1
  import React, { CSSProperties } from 'react';
2
2
  interface ControlProps {
3
- showBackEdit?: boolean;
4
3
  startRowVisible: boolean;
5
- handelClick: () => void;
4
+ firstRowVisible: boolean;
5
+ lastRowVisible: boolean;
6
+ showQuickLocationBtn: boolean;
7
+ backToEditRow: () => void;
8
+ toTop: () => void;
9
+ toBottom: () => void;
6
10
  backEditStyle?: Partial<CSSProperties>;
7
- direction: 'up' | 'down';
11
+ ControlContainer?: React.FC;
12
+ showBackEdit?: boolean;
8
13
  }
9
14
  export declare const Control: React.FC<ControlProps>;
10
15
  export {};
@@ -1,32 +1,81 @@
1
- import { ArrowDownOutlined, ArrowUpOutlined } from '@ant-design/icons';
2
- import React from 'react';
1
+ import { EditOutlined, VerticalAlignBottomOutlined, VerticalAlignTopOutlined } from '@ant-design/icons';
2
+ import { Button, Tooltip } from 'antd';
3
+ import React, { useMemo } from 'react';
3
4
  import { jsx as _jsx } from "react/jsx-runtime";
4
- import { jsxs as _jsxs } from "react/jsx-runtime";
5
+ var itemStyle = {
6
+ fontSize: 18,
7
+ marginTop: 2
8
+ };
5
9
  export var Control = function Control(props) {
6
10
  var showBackEdit = props.showBackEdit,
11
+ showQuickLocationBtn = props.showQuickLocationBtn,
7
12
  startRowVisible = props.startRowVisible,
8
- handelClick = props.handelClick,
9
- backEditStyle = props.backEditStyle,
10
- direction = props.direction;
11
- if (!showBackEdit || startRowVisible) return null;
12
- var styles = backEditStyle || {
13
- top: 0,
14
- right: 0
15
- };
16
- var backIcon = direction === 'up' ? /*#__PURE__*/_jsx(ArrowUpOutlined, {
17
- rev: undefined
18
- }) : /*#__PURE__*/_jsx(ArrowDownOutlined, {
19
- rev: undefined
20
- });
21
- return /*#__PURE__*/_jsxs("div", {
22
- className: "back-edit",
23
- onClick: handelClick,
24
- style: styles,
25
- children: [backIcon, /*#__PURE__*/_jsx("span", {
26
- style: {
27
- marginLeft: 0
28
- },
29
- children: "\u8FD4\u56DE\u7F16\u8F91\u884C"
30
- })]
13
+ firstRowVisible = props.firstRowVisible,
14
+ lastRowVisible = props.lastRowVisible,
15
+ toTop = props.toTop,
16
+ toBottom = props.toBottom,
17
+ backToEditRow = props.backToEditRow,
18
+ _props$backEditStyle = props.backEditStyle,
19
+ backEditStyle = _props$backEditStyle === void 0 ? {
20
+ bottom: 0,
21
+ right: 0
22
+ } : _props$backEditStyle,
23
+ ControlContainer = props.ControlContainer;
24
+ var btns = useMemo(function () {
25
+ var tempBtns = [{
26
+ title: '置顶',
27
+ disabled: firstRowVisible,
28
+ event: toTop,
29
+ icon: /*#__PURE__*/_jsx(VerticalAlignTopOutlined, {
30
+ style: itemStyle
31
+ }),
32
+ isShow: showQuickLocationBtn
33
+ }, {
34
+ title: '置底',
35
+ disabled: lastRowVisible,
36
+ event: toBottom,
37
+ icon: /*#__PURE__*/_jsx(VerticalAlignBottomOutlined, {
38
+ style: itemStyle
39
+ }),
40
+ isShow: showQuickLocationBtn
41
+ }, {
42
+ title: '返回编辑行',
43
+ disabled: startRowVisible,
44
+ event: toBottom,
45
+ icon: /*#__PURE__*/_jsx(EditOutlined, {
46
+ style: itemStyle
47
+ }),
48
+ isShow: showBackEdit
49
+ }];
50
+ return tempBtns.filter(function (item) {
51
+ return item.isShow;
52
+ });
53
+ }, [firstRowVisible, showQuickLocationBtn, lastRowVisible, startRowVisible, showBackEdit]);
54
+ if (!showBackEdit && !showQuickLocationBtn) return null;
55
+ if (ControlContainer) {
56
+ return /*#__PURE__*/_jsx(ControlContainer, {});
57
+ }
58
+ return /*#__PURE__*/_jsx("div", {
59
+ className: "control",
60
+ onClick: backToEditRow,
61
+ style: backEditStyle,
62
+ children: btns.map(function (item) {
63
+ return /*#__PURE__*/_jsx("div", {
64
+ className: "control-item",
65
+ children: /*#__PURE__*/_jsx(Tooltip, {
66
+ title: item.title,
67
+ children: /*#__PURE__*/_jsx(Button, {
68
+ style: {
69
+ width: 24,
70
+ height: 24,
71
+ padding: 0
72
+ },
73
+ disabled: item.disabled,
74
+ onClick: item.event,
75
+ children: item.icon
76
+ })
77
+ })
78
+ }, item.title);
79
+ })
31
80
  });
32
81
  };
@@ -61,7 +61,10 @@ var Sheet = function Sheet(props) {
61
61
  _props$boldScroll = props.boldScroll,
62
62
  boldScroll = _props$boldScroll === void 0 ? true : _props$boldScroll,
63
63
  _props$hideColBar = props.hideColBar,
64
- hideColBar = _props$hideColBar === void 0 ? true : _props$hideColBar;
64
+ hideColBar = _props$hideColBar === void 0 ? true : _props$hideColBar,
65
+ _props$showQuickLocat = props.showQuickLocationBtn,
66
+ showQuickLocationBtn = _props$showQuickLocat === void 0 ? false : _props$showQuickLocat,
67
+ ControlContainer = props.ControlContainer;
65
68
  var sheetWrapperRef = useRef(null);
66
69
  var contextMenuRef = useRef(null);
67
70
  var eventBus = useEventBus();
@@ -233,9 +236,20 @@ var Sheet = function Sheet(props) {
233
236
  }, [visibleData, groupConfig, virtualStart, virtualEnd, rowClassName]);
234
237
  var memoHeight = Math.min(((_visibleData$length = visibleData === null || visibleData === void 0 ? void 0 : visibleData.length) !== null && _visibleData$length !== void 0 ? _visibleData$length : 0) + 1, 10) * 42 + 43;
235
238
  var _useSelectVisible = useSelectVisible(sheetWrapperRef, state.start),
236
- _useSelectVisible2 = _slicedToArray(_useSelectVisible, 2),
237
- startRowVisible = _useSelectVisible2[0],
238
- direction = _useSelectVisible2[1];
239
+ _useSelectVisible2 = _slicedToArray(_useSelectVisible, 1),
240
+ startRowVisible = _useSelectVisible2[0];
241
+ var _useSelectVisible3 = useSelectVisible(sheetWrapperRef, {
242
+ col: 0,
243
+ row: 0
244
+ }),
245
+ _useSelectVisible4 = _slicedToArray(_useSelectVisible3, 1),
246
+ firstRowVisible = _useSelectVisible4[0];
247
+ var _useSelectVisible5 = useSelectVisible(sheetWrapperRef, {
248
+ col: 0,
249
+ row: ((visibleData === null || visibleData === void 0 ? void 0 : visibleData.length) || 1) - 1
250
+ }),
251
+ _useSelectVisible6 = _slicedToArray(_useSelectVisible5, 1),
252
+ lastRowVisible = _useSelectVisible6[0];
239
253
  var isEmptyData = isEmpty(state.data);
240
254
  var EmptyElement = useMemo(function () {
241
255
  if (isEmptyData) {
@@ -281,16 +295,27 @@ var Sheet = function Sheet(props) {
281
295
  }), EmptyElement]
282
296
  }), /*#__PURE__*/_jsxs("div", {
283
297
  className: "harvest-sheet-control",
284
- children: [children, /*#__PURE__*/_jsx(Control, {
298
+ children: [/*#__PURE__*/_jsx(Control, {
285
299
  showBackEdit: showBackEdit,
286
300
  startRowVisible: startRowVisible,
287
- handelClick: function handelClick() {
301
+ backToEditRow: function backToEditRow() {
288
302
  var _sheetInstance$curren;
289
303
  return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren = sheetInstance.current) === null || _sheetInstance$curren === void 0 ? void 0 : _sheetInstance$curren.zoomTo();
290
304
  },
291
- direction: direction,
292
- backEditStyle: backEditStyle
293
- })]
305
+ firstRowVisible: firstRowVisible,
306
+ lastRowVisible: lastRowVisible,
307
+ backEditStyle: backEditStyle,
308
+ toTop: function toTop() {
309
+ var _sheetInstance$curren2;
310
+ return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren2 = sheetInstance.current) === null || _sheetInstance$curren2 === void 0 ? void 0 : _sheetInstance$curren2.zoomTo(0);
311
+ },
312
+ toBottom: function toBottom() {
313
+ var _sheetInstance$curren3, _visibleData$length2;
314
+ return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren3 = sheetInstance.current) === null || _sheetInstance$curren3 === void 0 ? void 0 : _sheetInstance$curren3.zoomTo(((_visibleData$length2 = visibleData === null || visibleData === void 0 ? void 0 : visibleData.length) !== null && _visibleData$length2 !== void 0 ? _visibleData$length2 : 1) - 1);
315
+ },
316
+ showQuickLocationBtn: showQuickLocationBtn,
317
+ ControlContainer: ControlContainer
318
+ }), children]
294
319
  })]
295
320
  }), /*#__PURE__*/_jsx(SearchInput, {
296
321
  style: props.searchStyle,
@@ -22,9 +22,7 @@
22
22
  height: 10px;
23
23
  border-bottom: 10px solid #fff;
24
24
  }
25
-
26
25
  }
27
-
28
26
  }
29
27
 
30
28
  .harvest-sheet-container {
@@ -36,7 +34,6 @@
36
34
 
37
35
  .harvest-sheet-container .header {
38
36
  z-index: 2;
39
-
40
37
  }
41
38
 
42
39
  span.harvest-sheet-container,
@@ -65,16 +62,15 @@ span.harvest-sheet-container:focus {
65
62
  .td {
66
63
  border-bottom: 1px solid transparent;
67
64
  }
68
-
69
65
  }
70
66
  }
71
-
72
67
  }
73
68
 
74
69
  .harvest-sheet-container .harvest-sheet .cell {
75
70
  height: 17px;
76
71
  font-size: var(--cell-font-size);
77
- padding: var(--cell-padding-vertical) var(--cell-padding-horizontal) var(--cell-padding-vertical) var(--cell-padding-horizontal);
72
+ padding: var(--cell-padding-vertical) var(--cell-padding-horizontal)
73
+ var(--cell-padding-vertical) var(--cell-padding-horizontal);
78
74
  border: 1px solid var(--cell-border-color);
79
75
  background-color: var(--cell-background-color);
80
76
  cursor: cell;
@@ -83,20 +79,16 @@ span.harvest-sheet-container:focus {
83
79
  user-select: none;
84
80
  vertical-align: bottom;
85
81
  position: relative;
86
-
87
82
  }
88
83
 
89
-
90
84
  .harvest-sheet-container .harvest-sheet .cell.fixed {
91
85
  position: sticky;
92
86
  z-index: 2;
93
87
 
94
88
  &.cell-title {
95
89
  z-index: 3;
96
-
97
90
  }
98
91
 
99
-
100
92
  &::before {
101
93
  position: absolute;
102
94
  top: -1px;
@@ -104,7 +96,7 @@ span.harvest-sheet-container:focus {
104
96
  width: 100%;
105
97
  border-color: var(--cell-border-color);
106
98
  border-top: 1px solid var(--cell-border-color);
107
- content: "";
99
+ content: '';
108
100
  }
109
101
 
110
102
  &.fixed-left::after {
@@ -114,14 +106,13 @@ span.harvest-sheet-container:focus {
114
106
  right: -1px;
115
107
  width: 30px;
116
108
  border-left: 1px solid var(--cell-border-color);
117
- content: "";
109
+ content: '';
118
110
  pointer-events: none;
119
111
  transform: translate(100%);
120
- transition: box-shadow .3s;
112
+ transition: box-shadow 0.3s;
121
113
  box-shadow: var(--cell-fixed-box-shadow-left);
122
114
  }
123
115
 
124
-
125
116
  &.fixed-right {
126
117
  transform: translateX(1px);
127
118
  }
@@ -133,13 +124,11 @@ span.harvest-sheet-container:focus {
133
124
  left: -1px;
134
125
  width: 30px;
135
126
  border-right: 1px solid var(--cell-border-color);
136
- content: "";
127
+ content: '';
137
128
  pointer-events: none;
138
129
  transform: translate(-100%);
139
- transition: box-shadow .3s;
130
+ transition: box-shadow 0.3s;
140
131
  box-shadow: var(--cell-fixed-box-shadow-right);
141
-
142
-
143
132
  }
144
133
 
145
134
  &.fixed-unset {
@@ -147,8 +136,6 @@ span.harvest-sheet-container:focus {
147
136
  }
148
137
  }
149
138
 
150
-
151
-
152
139
  .harvest-sheet-container .harvest-sheet .cell.selected {
153
140
  border-color: var(--cell-border-color);
154
141
  box-shadow: var(--cell-box-shadow);
@@ -180,7 +167,6 @@ span.harvest-sheet-container:focus {
180
167
  border-right-width: 1px;
181
168
  }
182
169
 
183
-
184
170
  .harvest-sheet-container .harvest-sheet .cell.sheet-control {
185
171
  border-right: 1px solid transparent;
186
172
  background: var(--cell-background-color);
@@ -204,7 +190,6 @@ span.harvest-sheet-container:focus {
204
190
  cursor: var(--arrow-right) 12 12, e-resize;
205
191
  }
206
192
 
207
-
208
193
  .harvest-sheet-container .harvest-sheet .cell-title.sheet-control {
209
194
  border-right: 1px solid var(--cell-title-background-color);
210
195
  }
@@ -215,25 +200,20 @@ span.harvest-sheet-container:focus {
215
200
 
216
201
  &:hover {
217
202
  background-color: var(--cell-title-background-color);
218
-
219
203
  }
220
204
  }
221
205
 
222
-
223
206
  .harvest-sheet-container .harvest-sheet .cell:not(.cell.read-only):hover {
224
207
  background-color: var(--cell-hover);
225
208
  }
226
209
 
227
-
228
-
229
- .harvest-sheet-container .harvest-sheet .cell>.text {
210
+ .harvest-sheet-container .harvest-sheet .cell > .text {
230
211
  overflow: hidden;
231
212
  padding: 2px 5px;
232
213
  text-overflow: ellipsis;
233
214
  }
234
215
 
235
-
236
- .harvest-sheet-container .harvest-sheet .cell>input {
216
+ .harvest-sheet-container .harvest-sheet .cell > input {
237
217
  display: block;
238
218
  width: calc(100% - 6px);
239
219
  font-size: var(--cell-font-size);
@@ -283,7 +263,7 @@ span.harvest-sheet-container:focus {
283
263
  font-size: var(--cell-font-size);
284
264
  line-height: var(--cell-inner-height);
285
265
  height: var(--cell-inner-height);
286
- padding: 0
266
+ padding: 0;
287
267
  }
288
268
 
289
269
  .harvest-sheet-container .harvest-sheet .cell .data-editor {
@@ -292,8 +272,6 @@ span.harvest-sheet-container:focus {
292
272
  height: var(--cell-inner-height);
293
273
  }
294
274
 
295
-
296
-
297
275
  .harvest-sheet-container .harvest-menu {
298
276
  background-color: white;
299
277
  position: fixed;
@@ -308,10 +286,9 @@ span.harvest-sheet-container:focus {
308
286
  line-height: 22px;
309
287
 
310
288
  &:hover {
311
- background-color: rgba(31, 35, 41, 5%)
289
+ background-color: rgba(31, 35, 41, 5%);
312
290
  }
313
291
  }
314
-
315
292
  }
316
293
 
317
294
  .harvest-sheet-control {
@@ -322,19 +299,20 @@ span.harvest-sheet-container:focus {
322
299
  background-color: white;
323
300
  }
324
301
 
325
- .harvest-sheet-control .back-edit {
326
- padding: 5px 8px;
327
- margin: 1px;
328
- height: 30px;
302
+ .harvest-sheet-control .control {
303
+ margin: 4px 1px 4px 0;
329
304
  display: flex;
330
- width: 105px;
331
- cursor: pointer;
332
305
  align-items: center;
333
- justify-content: center;
334
- position: absolute;
335
- z-index: 4;
336
- border: 1px solid #D8DFEB;
306
+ flex-direction: row;
307
+ justify-content: flex-end;
337
308
  border-radius: 2px;
309
+ .control-item {
310
+ margin-right: 4px;
311
+ &:last-child {
312
+ margin-right: 0;
313
+ }
314
+ }
315
+
338
316
  }
339
317
 
340
318
  .harvest-search-text {
@@ -349,21 +327,21 @@ span.harvest-sheet-container:focus {
349
327
 
350
328
  .harvest-search-text .search-text-suffix {
351
329
  .search-text-disabled {
352
- color: #A4A9B2;
330
+ color: #a4a9b2;
353
331
  }
354
332
 
355
- >span {
333
+ > span {
356
334
  margin: 0 3px;
357
335
  }
358
336
  }
359
337
 
360
338
  .harvest-search-text .ant-input-affix-wrapper-focused {
361
- border-color: #0078E0;
362
- box-shadow: 0px 0px 0px 2px rgba(24, 144, 255, 0.20);
339
+ border-color: #0078e0;
340
+ box-shadow: 0px 0px 0px 2px rgba(24, 144, 255, 0.2);
363
341
  }
364
342
 
365
343
  :global {
366
344
  .ant-empty-description {
367
- color: #A4A9B2;
345
+ color: #a4a9b2;
368
346
  }
369
- }
347
+ }
@@ -115,7 +115,8 @@ var App = function App() {
115
115
  draggable: true,
116
116
  columns: columns,
117
117
  dataSource: dataSource,
118
- onChange: onChange
118
+ onChange: onChange,
119
+ showQuickLocationBtn: true
119
120
  });
120
121
  };
121
122
  export default App;
@@ -120,6 +120,8 @@ export type SheetProps = {
120
120
  children?: any[];
121
121
  boldScroll?: boolean;
122
122
  hideColBar?: boolean;
123
+ showQuickLocationBtn?: boolean;
124
+ ControlContainer?: React.FC;
123
125
  };
124
126
  export type WidthConfigContext = {
125
127
  onChange?: (value: Record<number | string, number>) => void;
@@ -91,4 +91,6 @@ export type TableProps = {
91
91
  handleBatchAdd?: (value: number) => void;
92
92
  eventHandler?: Record<'reverse' | 'btn-click' | 'cell-edit' | 'cell-switch' | string, undefined | EventHandler>;
93
93
  boldScroll?: boolean;
94
+ showQuickLocationBtn?: boolean;
95
+ ControlContainer?: React.FC;
94
96
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@zhenliang/sheet",
3
- "version": "0.1.58",
3
+ "version": "0.1.60",
4
4
  "description": "A react library developed with dumi",
5
5
  "license": "MIT",
6
6
  "module": "dist/index.js",
@@ -8,6 +8,7 @@
8
8
  "files": [
9
9
  "dist"
10
10
  ],
11
+ "preid": "beta",
11
12
  "scripts": {
12
13
  "build": "father build",
13
14
  "build:watch": "father dev",
@@ -79,4 +80,4 @@
79
80
  "authors": [
80
81
  "fizz.zhou@ap.jll.com"
81
82
  ]
82
- }
83
+ }
package/changes.md DELETED
@@ -1,45 +0,0 @@
1
- ### 为什么要重写
2
-
3
- #### 存在问题
4
-
5
- 1、表格选择逻辑与虚拟列表的冲突
6
- 2、表格的刷新机制: setRefresh(在多人开发的时候不便维护)
7
- 3、回调地狱
8
- 4、无法从 jll-portal 中剥离,有些地方与业务字段耦合
9
-
10
- #### 后果
11
-
12
- 1、新增功能难度大
13
- 2、修改容易出 bug
14
- 3、不利于业务代码优化和重构
15
-
16
- ### 重写后的表格
17
-
18
- #### 优点
19
-
20
- 1、维护性
21
- 2、扩展性
22
- 3、新的功能
23
-
24
- #### 新的 API
25
-
26
- 1、TableProps
27
-
28
- | 表头 | 表头 | 表头 |
29
- | -------------------------------------------- | ----------------------- | ---- |
30
- | className | container 类名 | 无 | |
31
- | | sheetInstance | sheet 对外暴露的一些 API | 选中行,参与回滚等 | |
32
-
33
- | columns | 表格列 | 无 ,必填 |
34
- | dataSource | 数据源 | 无,必填 |
35
- | virtualized |虚拟列表 | false |
36
- | draggable | 列宽可调整 | false |
37
- | rowClassName | 行类名 | 无 |
38
- | rowKey | 唯一标识字段 | key , id |
39
- | scroll | 同 antd table | {y:Math.min(400,row \* 40)} |
40
- | rowSelection | 选中行的配置 | 尚未完全实现 |
41
- | groupConfig | 表格分组 | 表格内部自动支持,对外配置尚未完全实现 |
42
- | onChange | 表格 cell change handler | 无 |
43
- | eventHandler | 自定义事件 handler | Record<string,(value:unknown)=>void> |
44
-
45
- 2、 ColumnProps