@zhenliang/sheet 0.1.60 → 0.1.61
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/changes.md +45 -0
- package/dist/core/sheet/Control.js +1 -2
- package/dist/core/sheet/index.js +44 -8
- package/dist/core/sheet/index.less +2 -3
- package/dist/core/table/addButton.js +3 -2
- package/dist/core/table/index.js +1 -0
- package/dist/example/antComponent.js +1 -0
- package/dist/example/basic.js +7 -3
- package/dist/type/sheet.d.ts +1 -0
- package/package.json +2 -2
package/changes.md
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
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
|
|
@@ -41,7 +41,7 @@ export var Control = function Control(props) {
|
|
|
41
41
|
}, {
|
|
42
42
|
title: '返回编辑行',
|
|
43
43
|
disabled: startRowVisible,
|
|
44
|
-
event:
|
|
44
|
+
event: backToEditRow,
|
|
45
45
|
icon: /*#__PURE__*/_jsx(EditOutlined, {
|
|
46
46
|
style: itemStyle
|
|
47
47
|
}),
|
|
@@ -57,7 +57,6 @@ export var Control = function Control(props) {
|
|
|
57
57
|
}
|
|
58
58
|
return /*#__PURE__*/_jsx("div", {
|
|
59
59
|
className: "control",
|
|
60
|
-
onClick: backToEditRow,
|
|
61
60
|
style: backEditStyle,
|
|
62
61
|
children: btns.map(function (item) {
|
|
63
62
|
return /*#__PURE__*/_jsx("div", {
|
package/dist/core/sheet/index.js
CHANGED
|
@@ -4,7 +4,7 @@ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o =
|
|
|
4
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
5
|
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; } }
|
|
6
6
|
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
|
|
7
|
-
import { useEffect, useImperativeHandle, useMemo, useRef } from 'react';
|
|
7
|
+
import { useEffect, useImperativeHandle, useMemo, useRef, useState } from 'react';
|
|
8
8
|
// import ReduxLogger from 'redux-logger';
|
|
9
9
|
import ReduxThunk from 'redux-thunk';
|
|
10
10
|
import DefaultRow from "./DefaultRow";
|
|
@@ -19,19 +19,19 @@ import { Control } from "./Control";
|
|
|
19
19
|
import { DefaultRowMapper } from "./DefaultRowMapper";
|
|
20
20
|
import { Menu } from "./Menu";
|
|
21
21
|
import "./index.less";
|
|
22
|
+
import { SearchInput } from "./searchInput";
|
|
22
23
|
import { useCellEvent } from "./useCellEvent";
|
|
23
24
|
import { useContextMenu } from "./useContextMenu";
|
|
24
25
|
import { useKeyBoardEvent } from "./useKeyBoardEvent";
|
|
25
26
|
import { useMouseEvent } from "./useMouseEvent";
|
|
27
|
+
import { useSearchInput } from "./useSearchInput";
|
|
26
28
|
import { useSelectVisible } from "./useSelectVisible";
|
|
27
29
|
import { VirtualizeEnd, VirtualizeStart, useVirtualList } from "./useVirtualList";
|
|
28
|
-
import { SearchInput } from "./searchInput";
|
|
29
|
-
import { useSearchInput } from "./useSearchInput";
|
|
30
30
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
31
31
|
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
32
32
|
import { Fragment as _Fragment } from "react/jsx-runtime";
|
|
33
33
|
var Sheet = function Sheet(props) {
|
|
34
|
-
var _visibleData$length, _scroll$y, _scroll$x;
|
|
34
|
+
var _visibleData$length, _scroll$y, _scroll$x, _sheetWrapperRef$curr5;
|
|
35
35
|
var _props$sheetInstance = props.sheetInstance,
|
|
36
36
|
sheetInstance = _props$sheetInstance === void 0 ? {
|
|
37
37
|
current: null
|
|
@@ -64,7 +64,12 @@ var Sheet = function Sheet(props) {
|
|
|
64
64
|
hideColBar = _props$hideColBar === void 0 ? true : _props$hideColBar,
|
|
65
65
|
_props$showQuickLocat = props.showQuickLocationBtn,
|
|
66
66
|
showQuickLocationBtn = _props$showQuickLocat === void 0 ? false : _props$showQuickLocat,
|
|
67
|
-
ControlContainer = props.ControlContainer
|
|
67
|
+
ControlContainer = props.ControlContainer,
|
|
68
|
+
handleAdd = props.handleAdd;
|
|
69
|
+
var _useState = useState(false),
|
|
70
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
71
|
+
mouseOnTable = _useState2[0],
|
|
72
|
+
setMouseOnTable = _useState2[1];
|
|
68
73
|
var sheetWrapperRef = useRef(null);
|
|
69
74
|
var contextMenuRef = useRef(null);
|
|
70
75
|
var eventBus = useEventBus();
|
|
@@ -246,7 +251,7 @@ var Sheet = function Sheet(props) {
|
|
|
246
251
|
firstRowVisible = _useSelectVisible4[0];
|
|
247
252
|
var _useSelectVisible5 = useSelectVisible(sheetWrapperRef, {
|
|
248
253
|
col: 0,
|
|
249
|
-
row: ((
|
|
254
|
+
row: ((data === null || data === void 0 ? void 0 : data.length) || 1) - 1
|
|
250
255
|
}),
|
|
251
256
|
_useSelectVisible6 = _slicedToArray(_useSelectVisible5, 1),
|
|
252
257
|
lastRowVisible = _useSelectVisible6[0];
|
|
@@ -264,10 +269,27 @@ var Sheet = function Sheet(props) {
|
|
|
264
269
|
return null;
|
|
265
270
|
}, [isEmptyData, emptyRenderer]);
|
|
266
271
|
var hasHorizontalScrollbar = sheetWrapperRef.current && sheetWrapperRef.current.scrollWidth > sheetWrapperRef.current.clientWidth;
|
|
272
|
+
// 解决滚动条出现
|
|
273
|
+
var offSetBottom = useMemo(function () {
|
|
274
|
+
var height = 0;
|
|
275
|
+
if (handleAdd) {
|
|
276
|
+
height += 32;
|
|
277
|
+
}
|
|
278
|
+
if (showBackEdit || showQuickLocationBtn) {
|
|
279
|
+
height += 24;
|
|
280
|
+
}
|
|
281
|
+
if (height > 0 && hasHorizontalScrollbar && boldScroll && mouseOnTable) {
|
|
282
|
+
height -= 30;
|
|
283
|
+
}
|
|
284
|
+
return height;
|
|
285
|
+
}, [handleAdd, showBackEdit, showQuickLocationBtn, hasHorizontalScrollbar, boldScroll, mouseOnTable]);
|
|
267
286
|
return /*#__PURE__*/_jsx(SheetEventContext.Provider, {
|
|
268
287
|
value: eventBus,
|
|
269
288
|
children: /*#__PURE__*/_jsxs(_Fragment, {
|
|
270
289
|
children: [/*#__PURE__*/_jsxs("span", {
|
|
290
|
+
style: {
|
|
291
|
+
position: 'relative'
|
|
292
|
+
},
|
|
271
293
|
children: [/*#__PURE__*/_jsxs("span", {
|
|
272
294
|
ref: sheetWrapperRef,
|
|
273
295
|
tabIndex: 0,
|
|
@@ -276,6 +298,12 @@ var Sheet = function Sheet(props) {
|
|
|
276
298
|
maxHeight: (_scroll$y = scroll === null || scroll === void 0 ? void 0 : scroll.y) !== null && _scroll$y !== void 0 ? _scroll$y : memoHeight,
|
|
277
299
|
width: (_scroll$x = scroll === null || scroll === void 0 ? void 0 : scroll.x) !== null && _scroll$x !== void 0 ? _scroll$x : '100%'
|
|
278
300
|
},
|
|
301
|
+
onMouseOver: function onMouseOver() {
|
|
302
|
+
return setMouseOnTable(true);
|
|
303
|
+
},
|
|
304
|
+
onMouseLeave: function onMouseLeave() {
|
|
305
|
+
return setMouseOnTable(false);
|
|
306
|
+
},
|
|
279
307
|
children: [/*#__PURE__*/_jsxs(SheetShell, {
|
|
280
308
|
className: classNames('harvest-sheet', className),
|
|
281
309
|
children: [/*#__PURE__*/_jsx(VirtualizeStart, {
|
|
@@ -293,8 +321,16 @@ var Sheet = function Sheet(props) {
|
|
|
293
321
|
contextMenu: ContextMenu,
|
|
294
322
|
onContextMenu: onContextMenu
|
|
295
323
|
}), EmptyElement]
|
|
324
|
+
}), /*#__PURE__*/_jsx("div", {
|
|
325
|
+
style: {
|
|
326
|
+
height: offSetBottom
|
|
327
|
+
}
|
|
296
328
|
}), /*#__PURE__*/_jsxs("div", {
|
|
297
329
|
className: "harvest-sheet-control",
|
|
330
|
+
style: {
|
|
331
|
+
top: (_sheetWrapperRef$curr5 = sheetWrapperRef.current) === null || _sheetWrapperRef$curr5 === void 0 ? void 0 : _sheetWrapperRef$curr5.clientHeight,
|
|
332
|
+
width: '100%'
|
|
333
|
+
},
|
|
298
334
|
children: [/*#__PURE__*/_jsx(Control, {
|
|
299
335
|
showBackEdit: showBackEdit,
|
|
300
336
|
startRowVisible: startRowVisible,
|
|
@@ -310,8 +346,8 @@ var Sheet = function Sheet(props) {
|
|
|
310
346
|
return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren2 = sheetInstance.current) === null || _sheetInstance$curren2 === void 0 ? void 0 : _sheetInstance$curren2.zoomTo(0);
|
|
311
347
|
},
|
|
312
348
|
toBottom: function toBottom() {
|
|
313
|
-
var _sheetInstance$curren3,
|
|
314
|
-
return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren3 = sheetInstance.current) === null || _sheetInstance$curren3 === void 0 ? void 0 : _sheetInstance$curren3.zoomTo(((
|
|
349
|
+
var _sheetInstance$curren3, _data$length;
|
|
350
|
+
return sheetInstance === null || sheetInstance === void 0 || (_sheetInstance$curren3 = sheetInstance.current) === null || _sheetInstance$curren3 === void 0 ? void 0 : _sheetInstance$curren3.zoomTo(((_data$length = data === null || data === void 0 ? void 0 : data.length) !== null && _data$length !== void 0 ? _data$length : 1) - 1);
|
|
315
351
|
},
|
|
316
352
|
showQuickLocationBtn: showQuickLocationBtn,
|
|
317
353
|
ControlContainer: ControlContainer
|
|
@@ -292,11 +292,9 @@ span.harvest-sheet-container:focus {
|
|
|
292
292
|
}
|
|
293
293
|
|
|
294
294
|
.harvest-sheet-control {
|
|
295
|
-
position:
|
|
295
|
+
position: absolute;
|
|
296
296
|
z-index: 3;
|
|
297
|
-
bottom: 0;
|
|
298
297
|
left: 0;
|
|
299
|
-
background-color: white;
|
|
300
298
|
}
|
|
301
299
|
|
|
302
300
|
.harvest-sheet-control .control {
|
|
@@ -306,6 +304,7 @@ span.harvest-sheet-container:focus {
|
|
|
306
304
|
flex-direction: row;
|
|
307
305
|
justify-content: flex-end;
|
|
308
306
|
border-radius: 2px;
|
|
307
|
+
height: 24px;
|
|
309
308
|
.control-item {
|
|
310
309
|
margin-right: 4px;
|
|
311
310
|
&:last-child {
|
|
@@ -66,9 +66,10 @@ export var AddButton = function AddButton(props) {
|
|
|
66
66
|
type: "dashed",
|
|
67
67
|
style: {
|
|
68
68
|
width: '100%',
|
|
69
|
-
height: 32
|
|
69
|
+
height: 32,
|
|
70
|
+
backgroundColor: '#fff'
|
|
70
71
|
},
|
|
71
|
-
onClick: function onClick(
|
|
72
|
+
onClick: function onClick() {
|
|
72
73
|
handleAdd && handleAdd();
|
|
73
74
|
},
|
|
74
75
|
children: ["+ \u6DFB\u52A0", _handleBatchAdd && /*#__PURE__*/_jsx(Popover, {
|
package/dist/core/table/index.js
CHANGED
|
@@ -187,6 +187,7 @@ var Table = function Table(_ref) {
|
|
|
187
187
|
sheetRenderer: WrappedTableShell,
|
|
188
188
|
data: data,
|
|
189
189
|
onCellsChanged: handleChanges,
|
|
190
|
+
handleAdd: handleAdd,
|
|
190
191
|
children: [/*#__PURE__*/_jsx(SelectionEvent, {
|
|
191
192
|
hasChildren: hasChildren,
|
|
192
193
|
rowSelection: rowSelection,
|
package/dist/example/basic.js
CHANGED
|
@@ -31,20 +31,24 @@ var columns = [{
|
|
|
31
31
|
return /*#__PURE__*/_jsx("a", {
|
|
32
32
|
children: value
|
|
33
33
|
});
|
|
34
|
-
}
|
|
34
|
+
},
|
|
35
|
+
width: 100
|
|
35
36
|
}, {
|
|
36
37
|
title: 'Age',
|
|
37
38
|
dataIndex: 'age',
|
|
38
|
-
key: 'age'
|
|
39
|
+
key: 'age',
|
|
40
|
+
width: 100
|
|
39
41
|
}, {
|
|
40
42
|
title: 'Address',
|
|
41
43
|
editable: false,
|
|
42
44
|
dataIndex: 'address',
|
|
43
|
-
key: 'address'
|
|
45
|
+
key: 'address',
|
|
46
|
+
width: 100
|
|
44
47
|
}, {
|
|
45
48
|
title: 'Tags',
|
|
46
49
|
key: 'tags',
|
|
47
50
|
dataIndex: 'tags',
|
|
51
|
+
width: 100,
|
|
48
52
|
render: function render(_ref2) {
|
|
49
53
|
var tags = _ref2.record.tags;
|
|
50
54
|
return /*#__PURE__*/_jsx(_Fragment, {
|
package/dist/type/sheet.d.ts
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@zhenliang/sheet",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.61",
|
|
4
4
|
"description": "A react library developed with dumi",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"module": "dist/index.js",
|
|
@@ -80,4 +80,4 @@
|
|
|
80
80
|
"authors": [
|
|
81
81
|
"fizz.zhou@ap.jll.com"
|
|
82
82
|
]
|
|
83
|
-
}
|
|
83
|
+
}
|