@kdcloudjs/table 1.2.0-canary.1 → 1.2.0-canary.10

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/@kdcloudjs/table.css +1 -1
  2. package/dist/@kdcloudjs/table.js +517 -49
  3. package/dist/@kdcloudjs/table.js.map +1 -1
  4. package/dist/@kdcloudjs/table.min.css +1 -1
  5. package/dist/@kdcloudjs/table.min.js +8 -8
  6. package/dist/@kdcloudjs/table.min.js.map +1 -1
  7. package/es/locale/locale.d.ts +8 -4
  8. package/es/locale/zh-CN.d.ts +8 -4
  9. package/es/locale/zh-CN.js +10 -4
  10. package/es/table/base/helpers/TableDOMUtils.js +17 -14
  11. package/es/table/base/styles.d.ts +10 -0
  12. package/es/table/base/styles.js +12 -2
  13. package/es/table/base/table.js +38 -7
  14. package/es/table/common-views.js +3 -1
  15. package/es/table/interfaces.d.ts +5 -0
  16. package/es/table/pipeline/features/autoFill.js +7 -3
  17. package/es/table/pipeline/features/columnFilter.js +17 -5
  18. package/es/table/pipeline/features/columnResizeWidth.js +3 -1
  19. package/es/table/pipeline/features/filter/DefaultFilterContent.d.ts +1 -1
  20. package/es/table/pipeline/features/filter/DefaultFilterContent.js +11 -5
  21. package/es/table/pipeline/features/filter/Filter.d.ts +4 -1
  22. package/es/table/pipeline/features/filter/Filter.js +4 -2
  23. package/es/table/pipeline/features/index.d.ts +1 -0
  24. package/es/table/pipeline/features/index.js +2 -1
  25. package/es/table/pipeline/features/multiSelect.js +31 -12
  26. package/es/table/pipeline/features/rowDrag.d.ts +28 -0
  27. package/es/table/pipeline/features/rowDrag.js +325 -0
  28. package/es/table/pipeline/features/sort.js +22 -3
  29. package/lib/locale/locale.d.ts +8 -4
  30. package/lib/locale/zh-CN.d.ts +8 -4
  31. package/lib/locale/zh-CN.js +10 -4
  32. package/lib/table/base/helpers/TableDOMUtils.js +17 -14
  33. package/lib/table/base/styles.d.ts +10 -0
  34. package/lib/table/base/styles.js +12 -2
  35. package/lib/table/base/table.js +38 -7
  36. package/lib/table/common-views.js +3 -1
  37. package/lib/table/interfaces.d.ts +5 -0
  38. package/lib/table/pipeline/features/autoFill.js +7 -3
  39. package/lib/table/pipeline/features/columnFilter.js +18 -6
  40. package/lib/table/pipeline/features/columnResizeWidth.js +3 -1
  41. package/lib/table/pipeline/features/filter/DefaultFilterContent.d.ts +1 -1
  42. package/lib/table/pipeline/features/filter/DefaultFilterContent.js +11 -5
  43. package/lib/table/pipeline/features/filter/Filter.d.ts +4 -1
  44. package/lib/table/pipeline/features/filter/Filter.js +4 -2
  45. package/lib/table/pipeline/features/index.d.ts +1 -0
  46. package/lib/table/pipeline/features/index.js +9 -1
  47. package/lib/table/pipeline/features/multiSelect.js +33 -12
  48. package/lib/table/pipeline/features/rowDrag.d.ts +28 -0
  49. package/lib/table/pipeline/features/rowDrag.js +347 -0
  50. package/lib/table/pipeline/features/sort.js +22 -3
  51. package/package.json +1 -1
@@ -0,0 +1,347 @@
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
+ var clientY = mouseMoveEvent.clientY;
114
+ var tableBodyClientRect = tableBody.getBoundingClientRect();
115
+ var top = tableBodyClientRect.top,
116
+ height = tableBodyClientRect.height;
117
+
118
+ if (clientY + SCROLL_OFFSET >= top + height) {
119
+ pipeline.ref.current.domHelper.tableBody.scrollTop += SCROLL_OFFSET;
120
+ }
121
+
122
+ if (clientY + SCROLL_OFFSET <= top) {
123
+ pipeline.ref.current.domHelper.tableBody.scrollTop -= SCROLL_OFFSET;
124
+ }
125
+ };
126
+
127
+ var onMouseDown = function onMouseDown(mouseDownEvent) {
128
+ var _a;
129
+
130
+ var startRowInfo = getTargetRowInfo(mouseDownEvent.target, tableBody, dataSource);
131
+ var endRowInfo = startRowInfo;
132
+ if (!startRowInfo || startRowInfo.code !== rowDragColumn.code) return;
133
+ 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; // 默认拖拽插入的位置是向下
134
+
135
+ var dragPosition = 'bottom';
136
+ var isOutOfRange = false;
137
+ var dragStartEvent = getDragEvent(startRowInfo, endRowInfo, {
138
+ isFinished: false,
139
+ dragPosition: 'bottom'
140
+ });
141
+ handleDragStrat(dragStartEvent);
142
+ var tableWidth = tableBody.clientWidth;
143
+ var startRowRects = startRowInfo.cell.getBoundingClientRect(); // 光标位置距离初始拖拽行的偏移量
144
+
145
+ var startOffset = mouseDownEvent.clientY - startRowRects.y;
146
+ var dragElement = createDragElement(startRowRects, tableWidth, rowHeight); // 可拖拽的范围
147
+
148
+ var dragRange = getDragRange(tableBody, {
149
+ startOffset: startOffset,
150
+ rowHeight: startRowRects.height
151
+ });
152
+ var mousemove$ = (0, _rxjs.fromEvent)(window, 'mousemove');
153
+ var mouseup$ = (0, _rxjs.fromEvent)(window, 'mouseup');
154
+ var rowDrag$ = mousemove$.pipe((0, _mapInstanceProperty(_operators))(function (mouseMoveEvent) {
155
+ var clientX = mouseMoveEvent.clientX,
156
+ clientY = mouseMoveEvent.clientY;
157
+ var tagretRow = getTargetRowInfo(mouseMoveEvent.target, tableBody, dataSource);
158
+
159
+ if (tagretRow) {
160
+ endRowInfo = tagretRow;
161
+ }
162
+
163
+ var targetRowRects = endRowInfo.cell.getBoundingClientRect(); // 判断拖拽插入的位置,拖拽框上边框位于目标行之上则向上插入,否则向下插入
164
+
165
+ var isMoveToTop = clientY - startOffset < targetRowRects.y;
166
+ dragPosition = isMoveToTop ? 'top' : 'bottom';
167
+ isOutOfRange = isOutOfDragRange({
168
+ x: clientX,
169
+ y: clientY
170
+ }, dragRange);
171
+ updateScrollPosition(mouseMoveEvent); // 拖拽到底时让滚动条可以滚动
172
+
173
+ updateDragElementPosition(dragElement, dragRange, {
174
+ x: clientX,
175
+ y: clientY,
176
+ startOffset: startOffset
177
+ });
178
+ updateCurSorStyle(isOutOfRange);
179
+ return {
180
+ startRowInfo: startRowInfo,
181
+ endRowInfo: endRowInfo,
182
+ dragPosition: dragPosition
183
+ };
184
+ }), (0, _operators.takeUntil)(mouseup$));
185
+ rowDrag$.subscribe({
186
+ next: function next(_ref2) {
187
+ var startRowInfo = _ref2.startRowInfo,
188
+ endRowInfo = _ref2.endRowInfo,
189
+ dragPosition = _ref2.dragPosition;
190
+ var dragMoveEvent = getDragEvent(startRowInfo, endRowInfo, {
191
+ isFinished: false,
192
+ dragPosition: dragPosition
193
+ });
194
+ handleDragMove(dragMoveEvent);
195
+ },
196
+ complete: function complete() {
197
+ var dragEndEvent = getDragEvent(startRowInfo, endRowInfo, {
198
+ isFinished: true,
199
+ dragPosition: dragPosition
200
+ });
201
+ handleDragEnd(dragEndEvent, isOutOfRange);
202
+ removeDragElement(dragElement);
203
+ removeCurSorStyle();
204
+ }
205
+ });
206
+ };
207
+
208
+ var rowDragColumn = (opt === null || opt === void 0 ? void 0 : opt.rowDragColumn) || defaultRowDragColumn;
209
+ var nextColumns = (0, _slice.default)(_context = pipeline.getColumns()).call(_context);
210
+ nextColumns.unshift(rowDragColumn);
211
+ pipeline.columns(nextColumns);
212
+ pipeline.addTableProps({
213
+ onMouseDown: onMouseDown
214
+ });
215
+ pipeline.appendRowPropsGetter(function (row, rowIndex) {
216
+ var _cx;
217
+
218
+ var rowDragEvent = pipeline.getStateAtKey(rowDragKey) || {};
219
+ var startRowIndex = rowDragEvent.startRowIndex,
220
+ endRowIndex = rowDragEvent.endRowIndex,
221
+ isFinished = rowDragEvent.isFinished,
222
+ dragPosition = rowDragEvent.dragPosition;
223
+ var isFooterCell = row[pipeline.getFeatureOptions('footerRowMetaKey')];
224
+ if (isFooterCell || isFinished || rowIndex !== startRowIndex && rowIndex !== endRowIndex) return;
225
+ 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));
226
+ return {
227
+ className: className
228
+ };
229
+ });
230
+ return pipeline;
231
+ };
232
+ }
233
+
234
+ function getTargetRowInfo(target, tableBody, record) {
235
+ while (target && tableBody.contains(target)) {
236
+ if (target.getAttribute('data-role') === 'table-cell') {
237
+ var code = target.getAttribute('data-code');
238
+ var rowIndex = parseInt(target.getAttribute('data-rowindex'));
239
+ var row = record[rowIndex];
240
+ var isFooterCell = isEleInFooter(target);
241
+ if (!row || isFooterCell) return null;
242
+ return {
243
+ rowIndex: rowIndex,
244
+ row: row,
245
+ code: code,
246
+ cell: target
247
+ };
248
+ }
249
+
250
+ target = target.parentElement;
251
+ }
252
+
253
+ return null;
254
+ }
255
+
256
+ function isEleInFooter(target) {
257
+ while (target && !target.classList.contains(_styles.Classes.artTable)) {
258
+ if (target.classList.contains(_styles.Classes.tableFooter)) {
259
+ return true;
260
+ }
261
+
262
+ target = target.parentElement;
263
+ }
264
+
265
+ return false;
266
+ }
267
+
268
+ function createDragElement(rects, tableWidth, rowHeight) {
269
+ var _context2, _context3, _context4;
270
+
271
+ var x = rects.x,
272
+ y = rects.y;
273
+ var dragMoveElement = document.createElement('div');
274
+ dragMoveElement.className = (0, _classnames.default)(_styles.Classes.rowDragElement);
275
+ 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;");
276
+ document.body.appendChild(dragMoveElement);
277
+ return dragMoveElement;
278
+ }
279
+
280
+ function updateDragElementPosition(element, dragRange, _ref3) {
281
+ var x = _ref3.x,
282
+ y = _ref3.y,
283
+ startOffset = _ref3.startOffset;
284
+ var validPosition = getValidPosition({
285
+ x: x,
286
+ y: y
287
+ }, dragRange);
288
+ element.style.top = validPosition.y - startOffset + 'px';
289
+ return element;
290
+ }
291
+
292
+ function removeDragElement(element) {
293
+ document.body.removeChild(element);
294
+ }
295
+
296
+ function updateCurSorStyle(isOutOfRange) {
297
+ if (isOutOfRange) {
298
+ document.body.style.cursor = 'no-drop';
299
+ } else {
300
+ document.body.style.cursor = 'move';
301
+ }
302
+ }
303
+
304
+ function removeCurSorStyle() {
305
+ document.body.style.cursor = 'default';
306
+ }
307
+
308
+ function getDragRange(tableBody, _ref4) {
309
+ var startOffset = _ref4.startOffset,
310
+ rowHeight = _ref4.rowHeight;
311
+ var tableBodyClientRect = tableBody.getBoundingClientRect();
312
+ var height = tableBodyClientRect.height,
313
+ width = tableBodyClientRect.width,
314
+ x = tableBodyClientRect.x,
315
+ y = tableBodyClientRect.y;
316
+ return {
317
+ minX: x,
318
+ maxX: x + width,
319
+ minY: y - rowHeight + startOffset,
320
+ maxY: y + height + startOffset
321
+ };
322
+ }
323
+
324
+ function getValidPosition(position, dragRange) {
325
+ var x = position.x,
326
+ y = position.y;
327
+ var minX = dragRange.minX,
328
+ maxX = dragRange.maxX,
329
+ minY = dragRange.minY,
330
+ maxY = dragRange.maxY;
331
+ var newX = x < minX ? minX : x > maxX ? maxX : x;
332
+ var newY = y < minY ? minY : y > maxY ? maxY : y;
333
+ return {
334
+ x: newX,
335
+ y: newY
336
+ };
337
+ }
338
+
339
+ function isOutOfDragRange(position, dragRange) {
340
+ var x = position.x,
341
+ y = position.y;
342
+ var minX = dragRange.minX,
343
+ maxX = dragRange.maxX,
344
+ minY = dragRange.minY,
345
+ maxY = dragRange.maxY;
346
+ return x > maxX || x < minX || y > maxY || y < minY;
347
+ }
@@ -338,10 +338,29 @@ function sort() {
338
338
  title: col.title && col.title[0] ? col.title[0] : col.title
339
339
  })));
340
340
 
341
- if (result.title && result.title[0]) {
342
- result.title[0] = sortNode;
341
+ var _sortNodeWithoutTitle = /*#__PURE__*/_react.default.createElement(SortHeaderCell, {
342
+ onToggle: function onToggle(e) {
343
+ if (stopClickEventPropagation) {
344
+ e.stopPropagation();
345
+ }
346
+
347
+ toggle(col.code);
348
+ },
349
+ sortOrder: sortOrder,
350
+ column: col,
351
+ sortIndex: sortIndex,
352
+ sortOptions: sortOptions
353
+ }); // 开启标题行高自适应后,修改表头的渲染结构
354
+
355
+
356
+ if (col.renderHeader) {
357
+ result.title = col.renderHeader(result.title, _sortNodeWithoutTitle);
343
358
  } else {
344
- result.title = sortNode;
359
+ if (result.title && result.title[0]) {
360
+ result.title[0] = sortNode;
361
+ } else {
362
+ result.title = sortNode;
363
+ }
345
364
  }
346
365
  }
347
366
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kdcloudjs/table",
3
- "version": "1.2.0-canary.1",
3
+ "version": "1.2.0-canary.10",
4
4
  "description": "金蝶 react table 组件",
5
5
  "title": "table",
6
6
  "keywords": [