@kdcloudjs/table 1.2.0-canary.9 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/@kdcloudjs/table.css +1 -1
- package/dist/@kdcloudjs/table.js +599 -119
- package/dist/@kdcloudjs/table.js.map +1 -1
- package/dist/@kdcloudjs/table.min.css +1 -1
- package/dist/@kdcloudjs/table.min.js +8 -8
- package/dist/@kdcloudjs/table.min.js.map +1 -1
- package/es/table/base/header.d.ts +2 -1
- package/es/table/base/header.js +4 -2
- package/es/table/base/helpers/TableDOMUtils.js +3 -1
- package/es/table/base/html-table.js +1 -1
- package/es/table/base/renderTemplates.js +24 -10
- package/es/table/base/styles.d.ts +7 -0
- package/es/table/base/styles.js +9 -2
- package/es/table/base/table.d.ts +2 -1
- package/es/table/base/table.js +73 -46
- package/es/table/pipeline/features/autoFill.js +3 -1
- package/es/table/pipeline/features/columnDrag.js +11 -7
- package/es/table/pipeline/features/columnFilter.js +1 -1
- package/es/table/pipeline/features/index.d.ts +1 -0
- package/es/table/pipeline/features/index.js +2 -1
- package/es/table/pipeline/features/multiSelect.js +18 -35
- package/es/table/pipeline/features/rangeSelection.js +3 -2
- package/es/table/pipeline/features/rowDrag.d.ts +30 -0
- package/es/table/pipeline/features/rowDrag.js +349 -0
- package/es/table/pipeline/features/singleSelect.js +6 -4
- package/es/table/pipeline/features/treeMode.js +6 -0
- package/es/table/pipeline/pipeline.d.ts +2 -0
- package/es/table/pipeline/pipeline.js +9 -1
- package/es/table/utils/index.d.ts +1 -0
- package/es/table/utils/index.js +2 -1
- package/es/table/utils/selectColumn.d.ts +4 -0
- package/es/table/utils/selectColumn.js +6 -0
- package/lib/table/base/header.d.ts +2 -1
- package/lib/table/base/header.js +4 -2
- package/lib/table/base/helpers/TableDOMUtils.js +3 -1
- package/lib/table/base/html-table.js +1 -1
- package/lib/table/base/renderTemplates.js +24 -10
- package/lib/table/base/styles.d.ts +7 -0
- package/lib/table/base/styles.js +9 -2
- package/lib/table/base/table.d.ts +2 -1
- package/lib/table/base/table.js +73 -46
- package/lib/table/pipeline/features/autoFill.js +3 -1
- package/lib/table/pipeline/features/columnDrag.js +10 -6
- package/lib/table/pipeline/features/columnFilter.js +1 -1
- package/lib/table/pipeline/features/index.d.ts +1 -0
- package/lib/table/pipeline/features/index.js +9 -1
- package/lib/table/pipeline/features/multiSelect.js +20 -38
- package/lib/table/pipeline/features/rangeSelection.js +3 -2
- package/lib/table/pipeline/features/rowDrag.d.ts +30 -0
- package/lib/table/pipeline/features/rowDrag.js +371 -0
- package/lib/table/pipeline/features/singleSelect.js +8 -5
- package/lib/table/pipeline/features/treeMode.js +6 -0
- package/lib/table/pipeline/pipeline.d.ts +2 -0
- package/lib/table/pipeline/pipeline.js +9 -1
- package/lib/table/utils/index.d.ts +1 -0
- package/lib/table/utils/index.js +21 -1
- package/lib/table/utils/selectColumn.d.ts +4 -0
- package/lib/table/utils/selectColumn.js +16 -0
- package/package.json +3 -3
|
@@ -9,7 +9,9 @@ exports.multiSelect = multiSelect;
|
|
|
9
9
|
|
|
10
10
|
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/slicedToArray"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _extends3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
|
13
15
|
|
|
14
16
|
var _set = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/set"));
|
|
15
17
|
|
|
@@ -23,14 +25,10 @@ var _others = require("../../utils/others");
|
|
|
23
25
|
|
|
24
26
|
var _utils = require("../../utils");
|
|
25
27
|
|
|
26
|
-
var fullRowsSetKey = 'fullRowsSetKey';
|
|
27
|
-
var allEnableKeys = 'allEnableKeys';
|
|
28
|
-
var selectValueSetKey = 'selectValueSetKey';
|
|
29
|
-
|
|
30
28
|
function multiSelect() {
|
|
31
29
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
32
30
|
return function multiSelectStep(pipeline) {
|
|
33
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
31
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l, _m;
|
|
34
32
|
|
|
35
33
|
var stateKey = 'multiSelect';
|
|
36
34
|
var Checkbox = pipeline.ctx.components.Checkbox;
|
|
@@ -57,8 +55,9 @@ function multiSelect() {
|
|
|
57
55
|
action: action
|
|
58
56
|
});
|
|
59
57
|
};
|
|
60
|
-
/** dataSource 中包含的所有 keys */
|
|
61
58
|
|
|
59
|
+
var dataSource = pipeline.getDataSource();
|
|
60
|
+
/** dataSource 中包含的所有 keys */
|
|
62
61
|
|
|
63
62
|
var fullKeySet = new _set.default();
|
|
64
63
|
/** 所有有效的 keys(disable 状态为 false) */
|
|
@@ -68,7 +67,7 @@ function multiSelect() {
|
|
|
68
67
|
var isAllChecked = set.size !== 0; // 当前不存在选中则默认为false
|
|
69
68
|
|
|
70
69
|
var isAnyChecked = false;
|
|
71
|
-
var flatDataSource = (0, _utils.collectNodes)(
|
|
70
|
+
var flatDataSource = (0, _utils.collectNodes)(dataSource);
|
|
72
71
|
flatDataSource.forEach(function (row, rowIndex) {
|
|
73
72
|
var rowKey = _internals.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
74
73
|
|
|
@@ -97,8 +96,6 @@ function multiSelect() {
|
|
|
97
96
|
checked: isAllChecked,
|
|
98
97
|
indeterminate: !isAllChecked && isAnyChecked,
|
|
99
98
|
onChange: function onChange(_) {
|
|
100
|
-
var allKeys = pipeline.getFeatureOptions(allEnableKeys);
|
|
101
|
-
|
|
102
99
|
if (isAllChecked) {
|
|
103
100
|
_onChange(_others.arrayUtils.diff(value, allKeys), '', allKeys, 'uncheck-all');
|
|
104
101
|
} else {
|
|
@@ -107,7 +104,7 @@ function multiSelect() {
|
|
|
107
104
|
}
|
|
108
105
|
});
|
|
109
106
|
|
|
110
|
-
var checkboxColumn = (0,
|
|
107
|
+
var checkboxColumn = (0, _extends3.default)((0, _extends3.default)({
|
|
111
108
|
name: '是否选中',
|
|
112
109
|
title: defaultCheckboxColumnTitle,
|
|
113
110
|
width: 50,
|
|
@@ -120,11 +117,9 @@ function multiSelect() {
|
|
|
120
117
|
|
|
121
118
|
var checkboxCellProps = {};
|
|
122
119
|
var preCellProps = (_b = (_a = opts.checkboxColumn) === null || _a === void 0 ? void 0 : _a.getCellProps) === null || _b === void 0 ? void 0 : _b.call(_a, value, row, rowIndex);
|
|
123
|
-
var fullRowsSet = pipeline.getFeatureOptions(fullRowsSetKey) || new _set.default();
|
|
124
|
-
var selectValueSet = pipeline.getFeatureOptions(selectValueSetKey) || new _set.default();
|
|
125
120
|
|
|
126
|
-
if (
|
|
127
|
-
var prevChecked =
|
|
121
|
+
if (fullKeySet.has(rowKey) && clickArea === 'cell') {
|
|
122
|
+
var prevChecked = set.has(rowKey);
|
|
128
123
|
var disabled = isDisabled(row, rowIndex);
|
|
129
124
|
checkboxCellProps = {
|
|
130
125
|
style: {
|
|
@@ -149,8 +144,7 @@ function multiSelect() {
|
|
|
149
144
|
|
|
150
145
|
var key = _internals.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
151
146
|
|
|
152
|
-
var
|
|
153
|
-
var checked = selectValueSet.has(key);
|
|
147
|
+
var checked = set.has(key);
|
|
154
148
|
return /*#__PURE__*/_react.default.createElement(Checkbox, {
|
|
155
149
|
checked: checked,
|
|
156
150
|
disabled: isDisabled(row, rowIndex),
|
|
@@ -171,10 +165,11 @@ function multiSelect() {
|
|
|
171
165
|
}
|
|
172
166
|
} : undefined
|
|
173
167
|
});
|
|
174
|
-
}
|
|
168
|
+
},
|
|
169
|
+
features: (0, _extends3.default)((0, _extends3.default)({}, (_l = opts.checkboxColumn) === null || _l === void 0 ? void 0 : _l.features), (0, _defineProperty2.default)({}, _utils.MULTI_SELECT_MARK_PROPNAME, true))
|
|
175
170
|
});
|
|
176
171
|
var nextColumns = (0, _slice.default)(_context = pipeline.getColumns()).call(_context);
|
|
177
|
-
var checkboxPlacement = (
|
|
172
|
+
var checkboxPlacement = (_m = opts.checkboxPlacement) !== null && _m !== void 0 ? _m : 'start';
|
|
178
173
|
|
|
179
174
|
if (checkboxPlacement === 'start') {
|
|
180
175
|
nextColumns.unshift(checkboxColumn);
|
|
@@ -188,9 +183,7 @@ function multiSelect() {
|
|
|
188
183
|
pipeline.appendRowPropsGetter(function (row, rowIndex) {
|
|
189
184
|
var rowKey = _internals.internals.safeGetRowKey(primaryKey, row, rowIndex);
|
|
190
185
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
if (!fullRowsSet.has(rowKey)) {
|
|
186
|
+
if (!fullKeySet.has(rowKey)) {
|
|
194
187
|
// rowKey 不在 fullKeySet 中说明这一行是在 multiSelect 之后才生成的,multiSelect 不对之后生成的行进行处理
|
|
195
188
|
return;
|
|
196
189
|
}
|
|
@@ -198,8 +191,7 @@ function multiSelect() {
|
|
|
198
191
|
var style = {};
|
|
199
192
|
var className;
|
|
200
193
|
var onClick;
|
|
201
|
-
var
|
|
202
|
-
var checked = selectValueSet.has(rowKey);
|
|
194
|
+
var checked = set.has(rowKey);
|
|
203
195
|
|
|
204
196
|
if (opts.highlightRowWhenSelected && checked) {
|
|
205
197
|
className = 'highlight';
|
|
@@ -226,32 +218,22 @@ function multiSelect() {
|
|
|
226
218
|
style: style,
|
|
227
219
|
onClick: onClick
|
|
228
220
|
};
|
|
229
|
-
});
|
|
230
|
-
|
|
231
|
-
pipeline.setFeatureOptions(fullRowsSetKey, fullKeySet);
|
|
232
|
-
pipeline.setFeatureOptions(allEnableKeys, allKeys);
|
|
233
|
-
pipeline.setFeatureOptions(selectValueSetKey, set);
|
|
234
|
-
fullKeySet = null;
|
|
235
|
-
allKeys = null;
|
|
236
|
-
set = null;
|
|
221
|
+
});
|
|
237
222
|
return pipeline;
|
|
238
223
|
|
|
239
224
|
function onCheckboxChange(prevChecked, key, batch) {
|
|
240
225
|
var batchKeys = [key];
|
|
241
226
|
|
|
242
227
|
if (batch && lastKey) {
|
|
243
|
-
var
|
|
244
|
-
|
|
245
|
-
var lastIdx = _allKeys.indexOf(lastKey);
|
|
246
|
-
|
|
247
|
-
var cntIdx = _allKeys.indexOf(key);
|
|
228
|
+
var lastIdx = allKeys.indexOf(lastKey);
|
|
229
|
+
var cntIdx = allKeys.indexOf(key);
|
|
248
230
|
|
|
249
231
|
var _ref = lastIdx < cntIdx ? [lastIdx, cntIdx] : [cntIdx, lastIdx],
|
|
250
232
|
_ref2 = (0, _slicedToArray2.default)(_ref, 2),
|
|
251
233
|
start = _ref2[0],
|
|
252
234
|
end = _ref2[1];
|
|
253
235
|
|
|
254
|
-
batchKeys = (0, _slice.default)(
|
|
236
|
+
batchKeys = (0, _slice.default)(allKeys).call(allKeys, start, end + 1);
|
|
255
237
|
}
|
|
256
238
|
|
|
257
239
|
if (prevChecked) {
|
|
@@ -176,7 +176,9 @@ function rangeSelection(opts) {
|
|
|
176
176
|
|
|
177
177
|
var isCtrlKey = mouseDownEvent.ctrlKey || mouseDownEvent.metaKey;
|
|
178
178
|
var isShiftKey = mouseDownEvent.shiftKey;
|
|
179
|
-
var target = mouseDownEvent.target;
|
|
179
|
+
var target = mouseDownEvent.target;
|
|
180
|
+
var startDragCell = getTargetCell(target, columns);
|
|
181
|
+
if (!startDragCell) return; // 每次点击时先确认初始生效的框选范围
|
|
180
182
|
|
|
181
183
|
setStartSelectedCellRanges(isCtrlKey, isShiftKey);
|
|
182
184
|
|
|
@@ -185,7 +187,6 @@ function rangeSelection(opts) {
|
|
|
185
187
|
return;
|
|
186
188
|
}
|
|
187
189
|
|
|
188
|
-
var startDragCell = getTargetCell(target, columns);
|
|
189
190
|
pipeline.setFeatureOptions(lastClickCellKey, startDragCell);
|
|
190
191
|
var draggingCell = startDragCell;
|
|
191
192
|
var mousemove$ = (0, _rxjs.fromEvent)(window, 'mousemove');
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { TablePipeline } from '../pipeline';
|
|
2
|
+
import { ArtColumn } from '../../interfaces';
|
|
3
|
+
interface RowDragEvent {
|
|
4
|
+
startRowIndex: number;
|
|
5
|
+
startRow: any;
|
|
6
|
+
endRowIndex: number;
|
|
7
|
+
endRow: any;
|
|
8
|
+
isFinished: boolean;
|
|
9
|
+
dragPosition: string;
|
|
10
|
+
}
|
|
11
|
+
export interface RowDragFeatureOptions {
|
|
12
|
+
/** 拖拽开始事件 */
|
|
13
|
+
onDragStart?: (event: RowDragEvent) => void;
|
|
14
|
+
/** 拖拽移动事件 */
|
|
15
|
+
onDragMove?: (event: RowDragEvent) => void;
|
|
16
|
+
/** 拖拽结束事件 */
|
|
17
|
+
onDragEnd?: (event: RowDragEvent) => void;
|
|
18
|
+
/** 判断一行是否要禁用拖拽 */
|
|
19
|
+
isDisabled?: (row: any, rowIndex: number) => boolean;
|
|
20
|
+
/** 拖拽列定义 */
|
|
21
|
+
rowDragColumn?: ArtColumn;
|
|
22
|
+
/** 行高 */
|
|
23
|
+
rowHeight?: number;
|
|
24
|
+
/** 拖拽过程中是否禁止滚动条滚动 */
|
|
25
|
+
suppressScrollMove?: boolean;
|
|
26
|
+
}
|
|
27
|
+
export declare const ROW_DRAG_COLUMN_CODE = "$_row_drag_column_&";
|
|
28
|
+
export declare const rowDragKey = "rowDragKey";
|
|
29
|
+
export declare function rowDrag(opt: RowDragFeatureOptions): (pipeline: TablePipeline) => TablePipeline;
|
|
30
|
+
export {};
|
|
@@ -0,0 +1,371 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _mapInstanceProperty = require("@babel/runtime-corejs3/core-js-stable/instance/map");
|
|
4
|
+
|
|
5
|
+
var _interopRequireDefault = require("@babel/runtime-corejs3/helpers/interopRequireDefault");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.ROW_DRAG_COLUMN_CODE = void 0;
|
|
11
|
+
exports.rowDrag = rowDrag;
|
|
12
|
+
exports.rowDragKey = void 0;
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
17
|
+
|
|
18
|
+
var _concat = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/concat"));
|
|
19
|
+
|
|
20
|
+
var _react = _interopRequireDefault(require("react"));
|
|
21
|
+
|
|
22
|
+
var _rxjs = require("rxjs");
|
|
23
|
+
|
|
24
|
+
var _operators = require("rxjs/operators");
|
|
25
|
+
|
|
26
|
+
var _classnames = _interopRequireDefault(require("classnames"));
|
|
27
|
+
|
|
28
|
+
var _styles = require("../../base/styles");
|
|
29
|
+
|
|
30
|
+
var ROW_DRAG_COLUMN_CODE = '$_row_drag_column_&';
|
|
31
|
+
exports.ROW_DRAG_COLUMN_CODE = ROW_DRAG_COLUMN_CODE;
|
|
32
|
+
var rowDragKey = 'rowDragKey';
|
|
33
|
+
exports.rowDragKey = rowDragKey;
|
|
34
|
+
var SCROLL_OFFSET = 30;
|
|
35
|
+
var defaultRowDragColumn = {
|
|
36
|
+
name: '拖拽列',
|
|
37
|
+
code: ROW_DRAG_COLUMN_CODE,
|
|
38
|
+
lock: true,
|
|
39
|
+
title: '',
|
|
40
|
+
width: 40,
|
|
41
|
+
align: 'center',
|
|
42
|
+
getCellProps: function getCellProps(value, row, rowIndex) {
|
|
43
|
+
return {
|
|
44
|
+
className: (0, _classnames.default)(_styles.Classes.rowDragCell)
|
|
45
|
+
};
|
|
46
|
+
},
|
|
47
|
+
render: function render(value, row, rowIndex) {
|
|
48
|
+
return /*#__PURE__*/_react.default.createElement("svg", {
|
|
49
|
+
viewBox: '0 0 1024 1024',
|
|
50
|
+
version: '1.1',
|
|
51
|
+
xmlns: 'http://www.w3.org/1999/xlink',
|
|
52
|
+
"data-icon": 'drag',
|
|
53
|
+
width: '16',
|
|
54
|
+
height: '16'
|
|
55
|
+
}, /*#__PURE__*/_react.default.createElement("path", {
|
|
56
|
+
d: 'M298.688 192a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m298.624 0a64 64 0 1 0 128 0 64 64 0 0 0-128 0zM298.688 512a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m298.624 0a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m-298.624 320a64 64 0 1 0 128 0 64 64 0 0 0-128 0z m298.624 0a64 64 0 1 0 128 0 64 64 0 0 0-128 0z',
|
|
57
|
+
"p-id": '4278'
|
|
58
|
+
}));
|
|
59
|
+
}
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
function rowDrag(opt) {
|
|
63
|
+
return function rowDragStep(pipeline) {
|
|
64
|
+
var _context;
|
|
65
|
+
|
|
66
|
+
var tableBody = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.tableBody;
|
|
67
|
+
var artTable = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.artTable;
|
|
68
|
+
if (!tableBody) return pipeline;
|
|
69
|
+
var dataSource = pipeline.getDataSource();
|
|
70
|
+
var rowHeight = (opt === null || opt === void 0 ? void 0 : opt.rowHeight) || 48;
|
|
71
|
+
|
|
72
|
+
var handleDragStrat = function handleDragStrat(event) {
|
|
73
|
+
var _a; // 开始拖拽
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
artTable.classList.add((0, _classnames.default)(_styles.Classes.rowDragging));
|
|
77
|
+
(_a = opt === null || opt === void 0 ? void 0 : opt.onDragStart) === null || _a === void 0 ? void 0 : _a.call(opt, event);
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
var handleDragMove = function handleDragMove(event) {
|
|
81
|
+
var _a;
|
|
82
|
+
|
|
83
|
+
(_a = opt === null || opt === void 0 ? void 0 : opt.onDragMove) === null || _a === void 0 ? void 0 : _a.call(opt, event);
|
|
84
|
+
pipeline.setStateAtKey(rowDragKey, event);
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
var handleDragEnd = function handleDragEnd(event, isOutOfRange) {
|
|
88
|
+
var _a;
|
|
89
|
+
|
|
90
|
+
artTable.classList.remove((0, _classnames.default)(_styles.Classes.rowDragging));
|
|
91
|
+
pipeline.setStateAtKey(rowDragKey, event); // 超出拖拽范围不触发dragend事件
|
|
92
|
+
|
|
93
|
+
if (!isOutOfRange) {
|
|
94
|
+
(_a = opt === null || opt === void 0 ? void 0 : opt.onDragEnd) === null || _a === void 0 ? void 0 : _a.call(opt, event);
|
|
95
|
+
}
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
var getDragEvent = function getDragEvent(startRowInfo, endRowInfo, _ref) {
|
|
99
|
+
var isFinished = _ref.isFinished,
|
|
100
|
+
_ref$dragPosition = _ref.dragPosition,
|
|
101
|
+
dragPosition = _ref$dragPosition === void 0 ? 'bottom' : _ref$dragPosition;
|
|
102
|
+
return {
|
|
103
|
+
startRowIndex: startRowInfo.rowIndex,
|
|
104
|
+
startRow: startRowInfo.row,
|
|
105
|
+
endRowIndex: endRowInfo.rowIndex,
|
|
106
|
+
endRow: endRowInfo.row,
|
|
107
|
+
dragPosition: dragPosition,
|
|
108
|
+
isFinished: isFinished
|
|
109
|
+
};
|
|
110
|
+
};
|
|
111
|
+
|
|
112
|
+
var updateScrollPosition = function updateScrollPosition(mouseMoveEvent) {
|
|
113
|
+
if (opt === null || opt === void 0 ? void 0 : opt.suppressScrollMove) return;
|
|
114
|
+
var clientY = mouseMoveEvent.clientY;
|
|
115
|
+
var tableBodyClientRect = tableBody.getBoundingClientRect();
|
|
116
|
+
var top = tableBodyClientRect.top,
|
|
117
|
+
height = tableBodyClientRect.height;
|
|
118
|
+
|
|
119
|
+
if (clientY + SCROLL_OFFSET >= top + height) {
|
|
120
|
+
pipeline.ref.current.domHelper.tableBody.scrollTop += SCROLL_OFFSET;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
if (clientY + SCROLL_OFFSET <= top) {
|
|
124
|
+
pipeline.ref.current.domHelper.tableBody.scrollTop -= SCROLL_OFFSET;
|
|
125
|
+
}
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
var onMouseDown = function onMouseDown(mouseDownEvent) {
|
|
129
|
+
var _a;
|
|
130
|
+
|
|
131
|
+
var startRowInfo = getTargetRowInfo(mouseDownEvent.target, tableBody, dataSource);
|
|
132
|
+
var endRowInfo = startRowInfo;
|
|
133
|
+
if (!startRowInfo || startRowInfo.code !== rowDragColumn.code) return;
|
|
134
|
+
if ((_a = opt === null || opt === void 0 ? void 0 : opt.isDisabled) === null || _a === void 0 ? void 0 : _a.call(opt, startRowInfo.row, startRowInfo.rowIndex)) return; // 默认拖拽插入的位置是向下
|
|
135
|
+
|
|
136
|
+
var dragPosition = 'bottom';
|
|
137
|
+
var isOutOfRange = false;
|
|
138
|
+
var dragStartEvent = getDragEvent(startRowInfo, endRowInfo, {
|
|
139
|
+
isFinished: false,
|
|
140
|
+
dragPosition: 'bottom'
|
|
141
|
+
});
|
|
142
|
+
handleDragStrat(dragStartEvent);
|
|
143
|
+
var tableWidth = tableBody.clientWidth;
|
|
144
|
+
var startRowRects = startRowInfo.cell.getBoundingClientRect(); // 光标位置距离初始拖拽行的偏移量
|
|
145
|
+
|
|
146
|
+
var startOffset = mouseDownEvent.clientY - startRowRects.top;
|
|
147
|
+
var dragElement = createDragElement(startRowRects, tableWidth, rowHeight); // 可拖拽的范围
|
|
148
|
+
|
|
149
|
+
var dragRange = getDragRange(tableBody, {
|
|
150
|
+
startOffset: startOffset,
|
|
151
|
+
rowHeight: rowHeight
|
|
152
|
+
});
|
|
153
|
+
var mousePosition = {
|
|
154
|
+
x: mouseDownEvent.clientX,
|
|
155
|
+
y: mouseDownEvent.clientY
|
|
156
|
+
};
|
|
157
|
+
var mousemove$ = (0, _rxjs.fromEvent)(window, 'mousemove');
|
|
158
|
+
var mouseup$ = (0, _rxjs.fromEvent)(window, 'mouseup');
|
|
159
|
+
|
|
160
|
+
var scrollCallback = function scrollCallback(event) {
|
|
161
|
+
// 在当前表格内滚动不处理
|
|
162
|
+
if (event.target === tableBody) return;
|
|
163
|
+
dragRange = getDragRange(tableBody, {
|
|
164
|
+
startOffset: startOffset,
|
|
165
|
+
rowHeight: rowHeight
|
|
166
|
+
});
|
|
167
|
+
var isOutOfRange = isOutOfDragRange(mousePosition, dragRange);
|
|
168
|
+
updateCurSorStyle(isOutOfRange);
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
document.addEventListener('scroll', scrollCallback, true);
|
|
172
|
+
var rowDrag$ = mousemove$.pipe((0, _mapInstanceProperty(_operators))(function (mouseMoveEvent) {
|
|
173
|
+
var clientX = mouseMoveEvent.clientX,
|
|
174
|
+
clientY = mouseMoveEvent.clientY;
|
|
175
|
+
var tagretRow = getTargetRowInfo(mouseMoveEvent.target, tableBody, dataSource);
|
|
176
|
+
|
|
177
|
+
if (tagretRow) {
|
|
178
|
+
endRowInfo = tagretRow;
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
var targetRowRects = endRowInfo.cell.getBoundingClientRect(); // 判断拖拽插入的位置,拖拽框上边框位于目标行之上则向上插入,否则向下插入
|
|
182
|
+
|
|
183
|
+
var isMoveToTop = clientY - startOffset < targetRowRects.top;
|
|
184
|
+
dragPosition = isMoveToTop ? 'top' : 'bottom';
|
|
185
|
+
isOutOfRange = isOutOfDragRange({
|
|
186
|
+
x: clientX,
|
|
187
|
+
y: clientY
|
|
188
|
+
}, dragRange);
|
|
189
|
+
mousePosition = {
|
|
190
|
+
x: clientX,
|
|
191
|
+
y: clientY
|
|
192
|
+
};
|
|
193
|
+
updateScrollPosition(mouseMoveEvent); // 拖拽到底时让滚动条可以滚动
|
|
194
|
+
|
|
195
|
+
updateDragElementPosition(dragElement, dragRange, {
|
|
196
|
+
x: clientX,
|
|
197
|
+
y: clientY,
|
|
198
|
+
startOffset: startOffset
|
|
199
|
+
});
|
|
200
|
+
updateCurSorStyle(isOutOfRange);
|
|
201
|
+
return {
|
|
202
|
+
startRowInfo: startRowInfo,
|
|
203
|
+
endRowInfo: endRowInfo,
|
|
204
|
+
dragPosition: dragPosition
|
|
205
|
+
};
|
|
206
|
+
}), (0, _operators.takeUntil)(mouseup$));
|
|
207
|
+
rowDrag$.subscribe({
|
|
208
|
+
next: function next(_ref2) {
|
|
209
|
+
var startRowInfo = _ref2.startRowInfo,
|
|
210
|
+
endRowInfo = _ref2.endRowInfo,
|
|
211
|
+
dragPosition = _ref2.dragPosition;
|
|
212
|
+
var dragMoveEvent = getDragEvent(startRowInfo, endRowInfo, {
|
|
213
|
+
isFinished: false,
|
|
214
|
+
dragPosition: dragPosition
|
|
215
|
+
});
|
|
216
|
+
handleDragMove(dragMoveEvent);
|
|
217
|
+
},
|
|
218
|
+
complete: function complete() {
|
|
219
|
+
var dragEndEvent = getDragEvent(startRowInfo, endRowInfo, {
|
|
220
|
+
isFinished: true,
|
|
221
|
+
dragPosition: dragPosition
|
|
222
|
+
});
|
|
223
|
+
handleDragEnd(dragEndEvent, isOutOfRange);
|
|
224
|
+
removeDragElement(dragElement);
|
|
225
|
+
removeCurSorStyle();
|
|
226
|
+
document.removeEventListener('scroll', scrollCallback, true);
|
|
227
|
+
}
|
|
228
|
+
});
|
|
229
|
+
};
|
|
230
|
+
|
|
231
|
+
var rowDragColumn = (opt === null || opt === void 0 ? void 0 : opt.rowDragColumn) || defaultRowDragColumn;
|
|
232
|
+
pipeline.setFeatureOptions('rowDragColumnKey', rowDragColumn.code);
|
|
233
|
+
var nextColumns = (0, _slice.default)(_context = pipeline.getColumns()).call(_context);
|
|
234
|
+
nextColumns.unshift(rowDragColumn);
|
|
235
|
+
pipeline.columns(nextColumns);
|
|
236
|
+
pipeline.addTableProps({
|
|
237
|
+
onMouseDown: onMouseDown
|
|
238
|
+
});
|
|
239
|
+
pipeline.appendRowPropsGetter(function (row, rowIndex) {
|
|
240
|
+
var _cx;
|
|
241
|
+
|
|
242
|
+
var rowDragEvent = pipeline.getStateAtKey(rowDragKey) || {};
|
|
243
|
+
var startRowIndex = rowDragEvent.startRowIndex,
|
|
244
|
+
endRowIndex = rowDragEvent.endRowIndex,
|
|
245
|
+
isFinished = rowDragEvent.isFinished,
|
|
246
|
+
dragPosition = rowDragEvent.dragPosition;
|
|
247
|
+
var isFooterCell = row[pipeline.getFeatureOptions('footerRowMetaKey')];
|
|
248
|
+
if (isFooterCell || isFinished || rowIndex !== startRowIndex && rowIndex !== endRowIndex) return;
|
|
249
|
+
var className = (0, _classnames.default)((_cx = {}, (0, _defineProperty2.default)(_cx, _styles.Classes.rowDragStart, rowIndex === startRowIndex), (0, _defineProperty2.default)(_cx, _styles.Classes.rowDragEnd, rowIndex === endRowIndex), (0, _defineProperty2.default)(_cx, _styles.Classes.rowDragEndToTop, rowIndex === endRowIndex && dragPosition === 'top'), (0, _defineProperty2.default)(_cx, _styles.Classes.rowDragEndToBottom, rowIndex === endRowIndex && dragPosition === 'bottom'), _cx));
|
|
250
|
+
return {
|
|
251
|
+
className: className
|
|
252
|
+
};
|
|
253
|
+
});
|
|
254
|
+
return pipeline;
|
|
255
|
+
};
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
function getTargetRowInfo(target, tableBody, record) {
|
|
259
|
+
while (target && tableBody.contains(target)) {
|
|
260
|
+
if (target.getAttribute('data-role') === 'table-cell') {
|
|
261
|
+
var code = target.getAttribute('data-code');
|
|
262
|
+
var rowIndex = parseInt(target.getAttribute('data-rowindex'));
|
|
263
|
+
var row = record[rowIndex];
|
|
264
|
+
var isFooterCell = isEleInFooter(target);
|
|
265
|
+
if (!row || isFooterCell) return null;
|
|
266
|
+
return {
|
|
267
|
+
rowIndex: rowIndex,
|
|
268
|
+
row: row,
|
|
269
|
+
code: code,
|
|
270
|
+
cell: target
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
target = target.parentElement;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
return null;
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
function isEleInFooter(target) {
|
|
281
|
+
while (target && !target.classList.contains(_styles.Classes.artTable)) {
|
|
282
|
+
if (target.classList.contains(_styles.Classes.tableFooter)) {
|
|
283
|
+
return true;
|
|
284
|
+
}
|
|
285
|
+
|
|
286
|
+
target = target.parentElement;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
return false;
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
function createDragElement(rects, tableWidth, rowHeight) {
|
|
293
|
+
var _context2, _context3, _context4;
|
|
294
|
+
|
|
295
|
+
var x = rects.x,
|
|
296
|
+
y = rects.y;
|
|
297
|
+
var dragMoveElement = document.createElement('div');
|
|
298
|
+
dragMoveElement.className = (0, _classnames.default)(_styles.Classes.rowDragElement);
|
|
299
|
+
dragMoveElement.style.cssText = (0, _concat.default)(_context2 = (0, _concat.default)(_context3 = (0, _concat.default)(_context4 = "position:fixed;z-index:9999;left:".concat(x, "px;top:")).call(_context4, y, "px;pointer-events:none;width:")).call(_context3, tableWidth, "px;height:")).call(_context2, rowHeight, "px;background:var(--primary-color);opacity: 0.1;");
|
|
300
|
+
document.body.appendChild(dragMoveElement);
|
|
301
|
+
return dragMoveElement;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
function updateDragElementPosition(element, dragRange, _ref3) {
|
|
305
|
+
var x = _ref3.x,
|
|
306
|
+
y = _ref3.y,
|
|
307
|
+
startOffset = _ref3.startOffset;
|
|
308
|
+
var validPosition = getValidPosition({
|
|
309
|
+
x: x,
|
|
310
|
+
y: y
|
|
311
|
+
}, dragRange);
|
|
312
|
+
element.style.top = validPosition.y - startOffset + 'px';
|
|
313
|
+
return element;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
function removeDragElement(element) {
|
|
317
|
+
document.body.removeChild(element);
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
function updateCurSorStyle(isOutOfRange) {
|
|
321
|
+
if (isOutOfRange) {
|
|
322
|
+
document.body.style.cursor = 'no-drop';
|
|
323
|
+
} else {
|
|
324
|
+
document.body.style.cursor = 'move';
|
|
325
|
+
}
|
|
326
|
+
}
|
|
327
|
+
|
|
328
|
+
function removeCurSorStyle() {
|
|
329
|
+
document.body.style.cursor = 'default';
|
|
330
|
+
}
|
|
331
|
+
|
|
332
|
+
function getDragRange(tableBody, _ref4) {
|
|
333
|
+
var startOffset = _ref4.startOffset,
|
|
334
|
+
rowHeight = _ref4.rowHeight;
|
|
335
|
+
var tableBodyClientRect = tableBody.getBoundingClientRect();
|
|
336
|
+
var height = tableBodyClientRect.height,
|
|
337
|
+
width = tableBodyClientRect.width,
|
|
338
|
+
top = tableBodyClientRect.top,
|
|
339
|
+
left = tableBodyClientRect.left;
|
|
340
|
+
return {
|
|
341
|
+
minX: left,
|
|
342
|
+
maxX: left + width,
|
|
343
|
+
minY: top - rowHeight + startOffset,
|
|
344
|
+
maxY: top + height + startOffset
|
|
345
|
+
};
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
function getValidPosition(position, dragRange) {
|
|
349
|
+
var x = position.x,
|
|
350
|
+
y = position.y;
|
|
351
|
+
var minX = dragRange.minX,
|
|
352
|
+
maxX = dragRange.maxX,
|
|
353
|
+
minY = dragRange.minY,
|
|
354
|
+
maxY = dragRange.maxY;
|
|
355
|
+
var newX = x < minX ? minX : x > maxX ? maxX : x;
|
|
356
|
+
var newY = y < minY ? minY : y > maxY ? maxY : y;
|
|
357
|
+
return {
|
|
358
|
+
x: newX,
|
|
359
|
+
y: newY
|
|
360
|
+
};
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
function isOutOfDragRange(position, dragRange) {
|
|
364
|
+
var x = position.x,
|
|
365
|
+
y = position.y;
|
|
366
|
+
var minX = dragRange.minX,
|
|
367
|
+
maxX = dragRange.maxX,
|
|
368
|
+
minY = dragRange.minY,
|
|
369
|
+
maxY = dragRange.maxY;
|
|
370
|
+
return x > maxX || x < minX || y > maxY || y < minY;
|
|
371
|
+
}
|
|
@@ -9,7 +9,9 @@ exports.singleSelect = singleSelect;
|
|
|
9
9
|
|
|
10
10
|
var _slice = _interopRequireDefault(require("@babel/runtime-corejs3/core-js-stable/instance/slice"));
|
|
11
11
|
|
|
12
|
-
var
|
|
12
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/defineProperty"));
|
|
13
|
+
|
|
14
|
+
var _extends3 = _interopRequireDefault(require("@babel/runtime-corejs3/helpers/extends"));
|
|
13
15
|
|
|
14
16
|
var _react = _interopRequireDefault(require("react"));
|
|
15
17
|
|
|
@@ -24,7 +26,7 @@ function singleSelect() {
|
|
|
24
26
|
return function singleSelectStep(pipeline) {
|
|
25
27
|
var _context;
|
|
26
28
|
|
|
27
|
-
var _a, _b, _c, _d, _e;
|
|
29
|
+
var _a, _b, _c, _d, _e, _f;
|
|
28
30
|
|
|
29
31
|
var Radio = pipeline.ctx.components.Radio;
|
|
30
32
|
|
|
@@ -45,7 +47,7 @@ function singleSelect() {
|
|
|
45
47
|
pipeline.setStateAtKey(stateKey, rowKey);
|
|
46
48
|
};
|
|
47
49
|
|
|
48
|
-
var radioColumn = (0,
|
|
50
|
+
var radioColumn = (0, _extends3.default)((0, _extends3.default)({
|
|
49
51
|
name: '',
|
|
50
52
|
width: 50,
|
|
51
53
|
align: 'center'
|
|
@@ -97,10 +99,11 @@ function singleSelect() {
|
|
|
97
99
|
onChange(rowKey);
|
|
98
100
|
} : undefined
|
|
99
101
|
});
|
|
100
|
-
}
|
|
102
|
+
},
|
|
103
|
+
features: (0, _extends3.default)((0, _extends3.default)({}, (_e = opts.radioColumn) === null || _e === void 0 ? void 0 : _e.features), (0, _defineProperty2.default)({}, _utils.SINGLE_SELECT_MARK_PROPNAME, true))
|
|
101
104
|
});
|
|
102
105
|
var nextColumns = (0, _slice.default)(_context = pipeline.getColumns()).call(_context);
|
|
103
|
-
var radioPlacement = (
|
|
106
|
+
var radioPlacement = (_f = opts.radioPlacement) !== null && _f !== void 0 ? _f : 'start';
|
|
104
107
|
|
|
105
108
|
if (radioPlacement === 'start') {
|
|
106
109
|
nextColumns.unshift(radioColumn);
|
|
@@ -101,6 +101,11 @@ function treeMode() {
|
|
|
101
101
|
return pipeline.mapDataSource(processDataSource).mapColumns(processColumns);
|
|
102
102
|
|
|
103
103
|
function processDataSource(input) {
|
|
104
|
+
if (pipeline.isSameInputDataSource() && openKeys === pipeline.getFeatureOptions('lastOpenKeys')) {
|
|
105
|
+
return pipeline.getFeatureOptions('lastTreeMode');
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
pipeline.setFeatureOptions('lastOpenKeys', pipeline.getStateAtKey(stateKey) || openKeys);
|
|
104
109
|
var result = [];
|
|
105
110
|
dfs(input, 0);
|
|
106
111
|
|
|
@@ -143,6 +148,7 @@ function treeMode() {
|
|
|
143
148
|
}
|
|
144
149
|
}
|
|
145
150
|
|
|
151
|
+
pipeline.setFeatureOptions('lastTreeMode', result);
|
|
146
152
|
return result;
|
|
147
153
|
}
|
|
148
154
|
|
|
@@ -35,6 +35,7 @@ export declare class TablePipeline {
|
|
|
35
35
|
private readonly _rowPropsGetters;
|
|
36
36
|
private _tableProps;
|
|
37
37
|
private _dataSource;
|
|
38
|
+
private _isSameInputDataSource;
|
|
38
39
|
private _columns;
|
|
39
40
|
private _footerDataSource?;
|
|
40
41
|
static defaultIndents: TablePipelineIndentsConfig;
|
|
@@ -51,6 +52,7 @@ export declare class TablePipeline {
|
|
|
51
52
|
appendRowPropsGetter(getter: RowPropsGetter): this;
|
|
52
53
|
addTableProps(props: React.HTMLAttributes<HTMLTableElement>): void;
|
|
53
54
|
getDataSource(name?: string): any[];
|
|
55
|
+
isSameInputDataSource(): boolean;
|
|
54
56
|
getColumns(name?: string): any[];
|
|
55
57
|
getFooterDataSource(): any[];
|
|
56
58
|
getStateAtKey<T = any>(stateKey: string, defaultValue?: T): T;
|
|
@@ -92,6 +92,11 @@ var TablePipeline = /*#__PURE__*/function () {
|
|
|
92
92
|
return this._snapshots[name].dataSource;
|
|
93
93
|
}
|
|
94
94
|
}
|
|
95
|
+
}, {
|
|
96
|
+
key: "isSameInputDataSource",
|
|
97
|
+
value: function isSameInputDataSource() {
|
|
98
|
+
return this._isSameInputDataSource;
|
|
99
|
+
}
|
|
95
100
|
}, {
|
|
96
101
|
key: "getColumns",
|
|
97
102
|
value: function getColumns(name) {
|
|
@@ -143,9 +148,12 @@ var TablePipeline = /*#__PURE__*/function () {
|
|
|
143
148
|
|
|
144
149
|
if (this._dataSource != null || this._columns != null) {
|
|
145
150
|
throw new Error('input 不能调用两次');
|
|
146
|
-
}
|
|
151
|
+
} // 在 pipeline 中识别本次更新是否有数据变化
|
|
152
|
+
|
|
147
153
|
|
|
154
|
+
this._isSameInputDataSource = _input.dataSource === this.ref.current._lastInputDataSource;
|
|
148
155
|
this._dataSource = _input.dataSource;
|
|
156
|
+
this.ref.current._lastInputDataSource = _input.dataSource;
|
|
149
157
|
this._columns = (0, _map.default)(_context = _input.columns).call(_context, function (col) {
|
|
150
158
|
return (0, _extends3.default)((0, _extends3.default)({}, col), {
|
|
151
159
|
key: _this.guid()
|