@kdcloudjs/table 1.2.0-canary.16 → 1.2.0-canary.16-hotfix
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 +2047 -3489
- package/dist/@kdcloudjs/table.js.map +1 -1
- package/dist/@kdcloudjs/table.min.css +1 -1
- package/dist/@kdcloudjs/table.min.js +16 -16
- package/dist/@kdcloudjs/table.min.js.map +1 -1
- package/es/_utils/arrayUtil.js +0 -3
- package/es/_utils/devwarning.js +0 -1
- package/es/_utils/formatUtil.js +35 -96
- package/es/_utils/hooks.js +18 -42
- package/es/_utils/index.js +0 -2
- package/es/_utils/numberUtil.js +32 -55
- package/es/_utils/omit.js +0 -2
- package/es/_utils/type.js +0 -2
- package/es/_utils/usePopper.js +74 -137
- package/es/config-provider/compDefaultProps.js +0 -1
- package/es/config-provider/configProvider.js +2 -7
- package/es/config-provider/defaultConfig.js +0 -1
- package/es/index.js +0 -2
- package/es/locale/locale.js +5 -43
- package/es/table/base/calculations.js +22 -72
- package/es/table/base/colgroup.js +0 -1
- package/es/table/base/empty.js +4 -4
- package/es/table/base/header.js +14 -67
- package/es/table/base/helpers/SpanManager.js +3 -9
- package/es/table/base/helpers/TableDOMUtils.js +4 -27
- package/es/table/base/helpers/__test__/SpanManager.test.js +2 -2
- package/es/table/base/helpers/__test__/TableDOMUtils.test.js +0 -1
- package/es/table/base/helpers/getRichVisibleRectsStream.js +11 -44
- package/es/table/base/helpers/rowHeightManager.js +0 -28
- package/es/table/base/html-table.js +14 -35
- package/es/table/base/loading.js +6 -8
- package/es/table/base/renderTemplates.js +26 -44
- package/es/table/base/styles.js +0 -9
- package/es/table/base/table.js +95 -181
- package/es/table/base/utils.js +14 -54
- package/es/table/common-views.js +0 -7
- package/es/table/internals.js +0 -13
- package/es/table/pipeline/features/autoFill.js +11 -40
- package/es/table/pipeline/features/autoRowSpan.js +1 -14
- package/es/table/pipeline/features/colGroupExtendable.js +4 -19
- package/es/table/pipeline/features/columnDrag.d.ts +1 -0
- package/es/table/pipeline/features/columnDrag.js +236 -303
- package/es/table/pipeline/features/columnFilter.js +11 -48
- package/es/table/pipeline/features/columnHover.js +1 -7
- package/es/table/pipeline/features/columnRangeHover.js +1 -8
- package/es/table/pipeline/features/columnResizeWidth.js +51 -42
- package/es/table/pipeline/features/contextMenu.js +18 -89
- package/es/table/pipeline/features/filter/DefaultFilterContent.js +10 -25
- package/es/table/pipeline/features/filter/DefaultFilterIcon.js +1 -1
- package/es/table/pipeline/features/filter/Filter.js +25 -48
- package/es/table/pipeline/features/filter/FilterPanel.js +11 -25
- package/es/table/pipeline/features/filter/util.js +0 -4
- package/es/table/pipeline/features/footerDataSource.js +0 -3
- package/es/table/pipeline/features/mergeCellHover.js +0 -1
- package/es/table/pipeline/features/multiSelect.js +15 -57
- package/es/table/pipeline/features/rangeSelection.js +63 -142
- package/es/table/pipeline/features/rowDetail.js +2 -41
- package/es/table/pipeline/features/rowDrag.js +36 -71
- package/es/table/pipeline/features/rowGrouping.js +2 -35
- package/es/table/pipeline/features/singleSelect.js +0 -24
- package/es/table/pipeline/features/sort.js +31 -83
- package/es/table/pipeline/features/tips.js +0 -6
- package/es/table/pipeline/features/treeMode.js +9 -44
- package/es/table/pipeline/features/treeSelect.js +0 -26
- package/es/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
- package/es/table/pipeline/features/utils/touchEventUtils.js +65 -0
- package/es/table/pipeline/pipeline.js +11 -51
- package/es/table/pivot/cross-table/buildCrossTable.js +15 -64
- package/es/table/pivot/cross-table/cross-table.js +22 -28
- package/es/table/pivot/cross-tree-table/buildCrossTreeTable.js +14 -47
- package/es/table/pivot/cross-tree-table/cross-tree-table.js +28 -50
- package/es/table/pivot/pivot-utils/buildDrillTree.js +10 -23
- package/es/table/pivot/pivot-utils/builders.js +31 -71
- package/es/table/pivot/pivot-utils/convert-utils.js +13 -39
- package/es/table/pivot/pivot-utils/simpleEncode.js +0 -1
- package/es/table/transforms/autoRowSpan.js +1 -15
- package/es/table/transforms/autoWidth.js +10 -32
- package/es/table/transforms/buildTree.js +1 -2
- package/es/table/transforms/columnHover.js +9 -15
- package/es/table/transforms/columnRangeHover.js +12 -19
- package/es/table/transforms/columnResize.js +15 -37
- package/es/table/transforms/flatten.js +0 -3
- package/es/table/transforms/orderField.js +0 -3
- package/es/table/transforms/sort.js +36 -88
- package/es/table/transforms/tips.js +1 -6
- package/es/table/transforms/treeMode.js +30 -69
- package/es/table/transforms/visible.js +0 -2
- package/es/table/use/useResizeObserver.js +1 -4
- package/es/table/utils/applyTransforms.js +0 -1
- package/es/table/utils/buildTree.js +4 -19
- package/es/table/utils/collectNodes.js +1 -10
- package/es/table/utils/console.js +0 -14
- package/es/table/utils/copyToClipboard.js +0 -4
- package/es/table/utils/element.js +14 -41
- package/es/table/utils/exportTableAsExcel.js +4 -40
- package/es/table/utils/getTreeDepth.js +1 -9
- package/es/table/utils/groupBy.js +1 -10
- package/es/table/utils/layeredFilter.js +0 -4
- package/es/table/utils/layeredSort.js +0 -5
- package/es/table/utils/makeRecursiveMapper.js +1 -12
- package/es/table/utils/mergeCellProps.js +6 -13
- package/es/table/utils/others.js +3 -16
- package/es/table/utils/proto.js +2 -30
- package/es/table/utils/smartCompare.js +4 -12
- package/es/table/utils/traverseColumn.js +2 -15
- package/es/table/utils/tree-data-helpers/StrictTreeDataHelper.js +1 -22
- package/es/table/utils/tree-data-helpers/TreeDataHelper.js +15 -69
- package/lib/_utils/arrayUtil.js +0 -5
- package/lib/_utils/devwarning.js +0 -5
- package/lib/_utils/formatUtil.js +35 -100
- package/lib/_utils/hooks.js +18 -53
- package/lib/_utils/index.js +0 -6
- package/lib/_utils/numberUtil.js +32 -63
- package/lib/_utils/omit.js +0 -5
- package/lib/_utils/react-children.js +0 -5
- package/lib/_utils/type.js +0 -6
- package/lib/_utils/usePopper.js +74 -158
- package/lib/config-provider/ConfigContext.js +1 -4
- package/lib/config-provider/compDefaultProps.js +0 -1
- package/lib/config-provider/configProvider.js +3 -18
- package/lib/config-provider/defaultConfig.js +0 -5
- package/lib/config-provider/index.js +0 -6
- package/lib/index.js +2 -8
- package/lib/locale/index.js +0 -7
- package/lib/locale/locale.js +5 -57
- package/lib/table/base/calculations.js +22 -83
- package/lib/table/base/colgroup.js +0 -5
- package/lib/table/base/empty.js +4 -16
- package/lib/table/base/header.js +14 -77
- package/lib/table/base/helpers/SpanManager.js +3 -11
- package/lib/table/base/helpers/TableDOMUtils.js +2 -27
- package/lib/table/base/helpers/__test__/SpanManager.test.js +2 -4
- package/lib/table/base/helpers/__test__/TableDOMUtils.test.js +0 -5
- package/lib/table/base/helpers/__test__/rowHeightManager.test.js +0 -1
- package/lib/table/base/helpers/getRichVisibleRectsStream.js +11 -62
- package/lib/table/base/helpers/rowHeightManager.js +0 -33
- package/lib/table/base/html-table.js +14 -45
- package/lib/table/base/index.js +0 -2
- package/lib/table/base/loading.js +6 -12
- package/lib/table/base/renderTemplates.js +27 -58
- package/lib/table/base/styles.js +0 -21
- package/lib/table/base/table.js +95 -214
- package/lib/table/base/utils.js +14 -89
- package/lib/table/common-views.js +0 -16
- package/lib/table/index.js +0 -13
- package/lib/table/internals.js +0 -14
- package/lib/table/pipeline/features/autoFill.js +11 -47
- package/lib/table/pipeline/features/autoRowSpan.js +1 -19
- package/lib/table/pipeline/features/buildTree.js +0 -2
- package/lib/table/pipeline/features/colGroupExtendable.js +4 -32
- package/lib/table/pipeline/features/columnDrag.d.ts +1 -0
- package/lib/table/pipeline/features/columnDrag.js +236 -309
- package/lib/table/pipeline/features/columnFilter.js +11 -62
- package/lib/table/pipeline/features/columnHover.js +1 -11
- package/lib/table/pipeline/features/columnRangeHover.js +1 -13
- package/lib/table/pipeline/features/columnResizeWidth.js +51 -58
- package/lib/table/pipeline/features/contextMenu.js +18 -113
- package/lib/table/pipeline/features/filter/DefaultFilterContent.js +10 -43
- package/lib/table/pipeline/features/filter/DefaultFilterIcon.js +1 -4
- package/lib/table/pipeline/features/filter/Filter.js +25 -70
- package/lib/table/pipeline/features/filter/FilterPanel.js +11 -40
- package/lib/table/pipeline/features/filter/index.js +0 -5
- package/lib/table/pipeline/features/filter/util.js +0 -7
- package/lib/table/pipeline/features/footerDataSource.js +0 -10
- package/lib/table/pipeline/features/index.js +0 -23
- package/lib/table/pipeline/features/mergeCellHover.js +0 -5
- package/lib/table/pipeline/features/multiSelect.js +15 -71
- package/lib/table/pipeline/features/rangeSelection.js +63 -159
- package/lib/table/pipeline/features/rowDetail.js +2 -65
- package/lib/table/pipeline/features/rowDrag.js +36 -81
- package/lib/table/pipeline/features/rowGrouping.js +2 -55
- package/lib/table/pipeline/features/singleSelect.js +0 -34
- package/lib/table/pipeline/features/sort.js +31 -103
- package/lib/table/pipeline/features/tips.js +0 -15
- package/lib/table/pipeline/features/treeMode.js +9 -65
- package/lib/table/pipeline/features/treeSelect.js +0 -34
- package/lib/table/pipeline/features/utils/touchEventUtils.d.ts +15 -0
- package/lib/table/pipeline/features/utils/touchEventUtils.js +76 -0
- package/lib/table/pipeline/index.js +0 -8
- package/lib/table/pipeline/pipeline.js +11 -60
- package/lib/table/pivot/cross-table/buildCrossTable.js +15 -75
- package/lib/table/pivot/cross-table/cross-table.js +22 -36
- package/lib/table/pivot/cross-table/index.js +0 -4
- package/lib/table/pivot/cross-tree-table/buildCrossTreeTable.js +14 -60
- package/lib/table/pivot/cross-tree-table/cross-tree-table.js +28 -60
- package/lib/table/pivot/cross-tree-table/index.js +0 -3
- package/lib/table/pivot/pivot-utils/buildDrillTree.js +10 -29
- package/lib/table/pivot/pivot-utils/builders.js +31 -82
- package/lib/table/pivot/pivot-utils/convert-utils.js +13 -57
- package/lib/table/pivot/pivot-utils/index.js +0 -7
- package/lib/table/pivot/pivot-utils/simpleEncode.js +0 -2
- package/lib/table/style/css.js +0 -1
- package/lib/table/style/index.js +0 -1
- package/lib/table/transforms/autoRowSpan.js +1 -21
- package/lib/table/transforms/autoWidth.js +10 -53
- package/lib/table/transforms/buildTree.js +1 -4
- package/lib/table/transforms/columnHover.js +9 -22
- package/lib/table/transforms/columnRangeHover.js +12 -27
- package/lib/table/transforms/columnResize.js +15 -56
- package/lib/table/transforms/flatten.js +0 -5
- package/lib/table/transforms/index.js +0 -12
- package/lib/table/transforms/orderField.js +0 -7
- package/lib/table/transforms/sort.js +36 -112
- package/lib/table/transforms/tips.js +1 -16
- package/lib/table/transforms/treeMode.js +30 -96
- package/lib/table/transforms/visible.js +0 -7
- package/lib/table/transforms/warnTransformsDeprecated.js +0 -4
- package/lib/table/use/useResizeObserver.js +1 -8
- package/lib/table/utils/applyTransforms.js +0 -2
- package/lib/table/utils/buildTree.js +4 -30
- package/lib/table/utils/collectNodes.js +1 -15
- package/lib/table/utils/console.js +0 -16
- package/lib/table/utils/copyToClipboard.js +0 -6
- package/lib/table/utils/element.js +14 -46
- package/lib/table/utils/exportTableAsExcel.js +4 -49
- package/lib/table/utils/getTreeDepth.js +1 -14
- package/lib/table/utils/groupBy.js +1 -14
- package/lib/table/utils/index.js +0 -21
- package/lib/table/utils/isGroupColumn.js +0 -3
- package/lib/table/utils/isLeafNode.js +0 -1
- package/lib/table/utils/layeredFilter.js +0 -10
- package/lib/table/utils/layeredSort.js +0 -10
- package/lib/table/utils/makeRecursiveMapper.js +1 -21
- package/lib/table/utils/mergeCellProps.js +6 -17
- package/lib/table/utils/others.js +3 -31
- package/lib/table/utils/proto.js +2 -33
- package/lib/table/utils/selectColumn.js +0 -1
- package/lib/table/utils/smartCompare.js +4 -13
- package/lib/table/utils/traverseColumn.js +2 -22
- package/lib/table/utils/tree-data-helpers/StrictTreeDataHelper.js +1 -30
- package/lib/table/utils/tree-data-helpers/TreeDataHelper.js +15 -82
- package/package.json +2 -1
|
@@ -4,57 +4,56 @@ import _toConsumableArray from "@babel/runtime-corejs3/helpers/toConsumableArray
|
|
|
4
4
|
import _filterInstanceProperty from "@babel/runtime-corejs3/core-js-stable/instance/filter";
|
|
5
5
|
import { makeRecursiveMapper, mergeCellProps, collectNodes, isLeafNode, isSelectColumn } from '../../utils';
|
|
6
6
|
import { FILL_COLUMN_CODE } from './autoFill';
|
|
7
|
+
import { getEventCoordinates, hasMovedEnough, addPointerEventListeners, removePointerEventListeners } from './utils/touchEventUtils';
|
|
7
8
|
var stateKey = 'columnDrag';
|
|
8
9
|
var SCROLL_SIZE = 30;
|
|
9
|
-
|
|
10
10
|
function disableSelect(event) {
|
|
11
11
|
event.preventDefault();
|
|
12
12
|
}
|
|
13
|
-
|
|
14
13
|
function sortColumns(columns, sort) {
|
|
15
14
|
var res = new Array(columns.length);
|
|
16
|
-
|
|
17
15
|
var lastColumns = _toConsumableArray(columns);
|
|
18
|
-
|
|
19
16
|
while (columns.length) {
|
|
20
17
|
var cloumn = columns.pop();
|
|
21
18
|
res[sort[cloumn.code]] = cloumn;
|
|
22
19
|
}
|
|
23
|
-
|
|
24
20
|
if (_filterInstanceProperty(res).call(res, Boolean).length !== lastColumns.length) {
|
|
25
21
|
return lastColumns;
|
|
26
22
|
}
|
|
27
|
-
|
|
28
23
|
return res;
|
|
29
24
|
}
|
|
30
|
-
|
|
31
25
|
function stopClickPropagation(e) {
|
|
32
26
|
e.stopPropagation();
|
|
33
27
|
}
|
|
34
|
-
|
|
28
|
+
function adjustTranslation(isRTL) {
|
|
29
|
+
return function (value) {
|
|
30
|
+
return isRTL ? -value : value;
|
|
31
|
+
};
|
|
32
|
+
}
|
|
35
33
|
export function columnDrag() {
|
|
36
34
|
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
|
|
37
35
|
return function (pipeline) {
|
|
36
|
+
var direction = pipeline.ctx.direction;
|
|
37
|
+
var _adjustTranslation = adjustTranslation(direction === 'rtl');
|
|
38
38
|
var _pipeline$getStateAtK = pipeline.getStateAtKey(stateKey, {}),
|
|
39
|
-
|
|
40
|
-
|
|
39
|
+
cloumnsTranslateData = _pipeline$getStateAtK.cloumnsTranslateData;
|
|
41
40
|
var columns = pipeline.getColumns();
|
|
42
|
-
var tableBody = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.tableBody;
|
|
41
|
+
var tableBody = pipeline.ref.current.domHelper && pipeline.ref.current.domHelper.tableBody;
|
|
42
|
+
// if (cloumnsSortData) {
|
|
43
43
|
// columns = sortColumns(columns, cloumnsSortData)
|
|
44
44
|
// }
|
|
45
|
-
|
|
46
45
|
pipeline.columns(_filterInstanceProperty(columns).call(columns, function (column) {
|
|
47
46
|
return column;
|
|
48
47
|
}));
|
|
49
48
|
return pipeline.mapColumns(makeRecursiveMapper(function (col, recursiveFlatMapInfo) {
|
|
50
49
|
var path = recursiveFlatMapInfo.path,
|
|
51
|
-
|
|
50
|
+
isLeaf = recursiveFlatMapInfo.isLeaf;
|
|
52
51
|
var style = cloumnsTranslateData ? {
|
|
53
52
|
transition: '.3s',
|
|
54
53
|
transform: "translate3d(".concat(cloumnsTranslateData[col.code], "px, 0px, 0px)")
|
|
55
54
|
} : {};
|
|
56
|
-
var prevGetCellProps = col.getCellProps;
|
|
57
|
-
|
|
55
|
+
var prevGetCellProps = col.getCellProps;
|
|
56
|
+
// !col.code: 选择列 col.lock: 固定列 不允许拖拽
|
|
58
57
|
if (col.lock || !col.code) return col;
|
|
59
58
|
return _extends(_extends({}, col), {
|
|
60
59
|
getCellProps: function getCellProps(value, record, rowIndex) {
|
|
@@ -63,328 +62,262 @@ export function columnDrag() {
|
|
|
63
62
|
style: style
|
|
64
63
|
});
|
|
65
64
|
},
|
|
66
|
-
headerCellProps: mergeCellProps(col.headerCellProps, {
|
|
67
|
-
onMouseDown:
|
|
65
|
+
headerCellProps: mergeCellProps(col.headerCellProps, _extends(_extends({}, isLeaf && path.length === 1 ? {
|
|
66
|
+
onMouseDown: function onMouseDown(e) {
|
|
68
67
|
if (e.button !== 0 || !e.currentTarget.contains(e.target)) {
|
|
69
68
|
return;
|
|
70
69
|
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
//
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
var
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
if (
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
var index = replaceIndex;
|
|
178
|
-
|
|
179
|
-
if (startIndex > replaceIndex) {
|
|
180
|
-
// 左移
|
|
181
|
-
while (index < startIndex) {
|
|
182
|
-
var _columns$index = columns[index],
|
|
183
|
-
code = _columns$index.code,
|
|
184
|
-
lock = _columns$index.lock,
|
|
185
|
-
width = _columns$index.width,
|
|
186
|
-
children = _columns$index.children;
|
|
187
|
-
|
|
188
|
-
if (enableMove({
|
|
189
|
-
code: code,
|
|
190
|
-
lock: lock
|
|
191
|
-
})) {
|
|
192
|
-
cloumnsTranslateData[code] += optionColumn.width;
|
|
193
|
-
|
|
194
|
-
if (isLeafNode(columns[index])) {
|
|
195
|
-
cloumnsTranslateData[optionColumn.code] -= width;
|
|
196
|
-
} else {
|
|
197
|
-
cloumnsTranslateData[optionColumn.code] -= getColumnWidth(columns[index]);
|
|
198
|
-
moveAllChildren(children, cloumnsTranslateData, optionColumn.width);
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
columnMoved = true;
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
index++;
|
|
205
|
-
}
|
|
206
|
-
} else if (startIndex < replaceIndex) {
|
|
207
|
-
// 右移
|
|
208
|
-
while (startIndex < index) {
|
|
209
|
-
var _columns$index2 = columns[index],
|
|
210
|
-
_code = _columns$index2.code,
|
|
211
|
-
_lock = _columns$index2.lock,
|
|
212
|
-
_width = _columns$index2.width,
|
|
213
|
-
_children = _columns$index2.children;
|
|
214
|
-
|
|
215
|
-
if (enableMove({
|
|
216
|
-
code: _code,
|
|
217
|
-
lock: _lock
|
|
218
|
-
})) {
|
|
219
|
-
cloumnsTranslateData[_code] -= optionColumn.width;
|
|
220
|
-
|
|
221
|
-
if (isLeafNode(columns[index])) {
|
|
222
|
-
cloumnsTranslateData[optionColumn.code] += _width;
|
|
223
|
-
} else {
|
|
224
|
-
cloumnsTranslateData[optionColumn.code] += getColumnWidth(columns[index]);
|
|
225
|
-
moveAllChildren(_children, cloumnsTranslateData, optionColumn.width, true);
|
|
226
|
-
}
|
|
227
|
-
|
|
228
|
-
columnMoved = true;
|
|
229
|
-
}
|
|
230
|
-
|
|
231
|
-
index--;
|
|
70
|
+
handlePointerDown(e.nativeEvent, false, e.currentTarget);
|
|
71
|
+
},
|
|
72
|
+
onTouchStart: function onTouchStart(e) {
|
|
73
|
+
// 阻止触摸事件的默认行为
|
|
74
|
+
if (e.cancelable) {
|
|
75
|
+
e.preventDefault();
|
|
76
|
+
}
|
|
77
|
+
handlePointerDown(e.nativeEvent, true, e.currentTarget);
|
|
78
|
+
}
|
|
79
|
+
} : {}), {
|
|
80
|
+
style: style
|
|
81
|
+
}))
|
|
82
|
+
});
|
|
83
|
+
// 统一的拖拽处理函数
|
|
84
|
+
function handlePointerDown(startEvent, isTouch, currentTarget) {
|
|
85
|
+
var _a;
|
|
86
|
+
window.addEventListener('selectstart', disableSelect);
|
|
87
|
+
var columnMoved = false;
|
|
88
|
+
var columns = pipeline.getColumns();
|
|
89
|
+
var _pipeline$getStateAtK2 = pipeline.getStateAtKey(stateKey, {}),
|
|
90
|
+
cloumnsTranslateData = _pipeline$getStateAtK2.cloumnsTranslateData;
|
|
91
|
+
var cloumnsSortData = {};
|
|
92
|
+
columns.forEach(function (item, index) {
|
|
93
|
+
cloumnsSortData[item.code] = index;
|
|
94
|
+
});
|
|
95
|
+
var rect = (_a = currentTarget.parentElement) === null || _a === void 0 ? void 0 : _a.getClientRects()[0];
|
|
96
|
+
if (!rect) return;
|
|
97
|
+
var startX = direction === 'rtl' ? rect.right : rect.left;
|
|
98
|
+
var startCoordinates = getEventCoordinates(startEvent);
|
|
99
|
+
var mouseDownClientX = startCoordinates.clientX;
|
|
100
|
+
var mouseDownClientY = startCoordinates.clientY;
|
|
101
|
+
var moveData = [];
|
|
102
|
+
var allColumns = collectNodes(columns);
|
|
103
|
+
var tableBodyClientRect = tableBody.getBoundingClientRect();
|
|
104
|
+
var startScrollLeft = pipeline.ref.current.domHelper.virtual.scrollLeft;
|
|
105
|
+
var updateScrollPosition = function updateScrollPosition(client) {
|
|
106
|
+
var clientX = client.clientX;
|
|
107
|
+
var left = tableBodyClientRect.left,
|
|
108
|
+
width = tableBodyClientRect.width;
|
|
109
|
+
if (clientX + SCROLL_SIZE >= left + width) {
|
|
110
|
+
pipeline.ref.current.domHelper.virtual.scrollLeft += SCROLL_SIZE;
|
|
111
|
+
}
|
|
112
|
+
if (clientX - SCROLL_SIZE <= left) {
|
|
113
|
+
pipeline.ref.current.domHelper.virtual.scrollLeft -= SCROLL_SIZE;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
function handlePointerMove(e) {
|
|
117
|
+
// 触摸事件需要阻止默认行为,防止页面滚动
|
|
118
|
+
if (isTouch && e.cancelable) {
|
|
119
|
+
e.preventDefault();
|
|
120
|
+
}
|
|
121
|
+
var coordinates = getEventCoordinates(e);
|
|
122
|
+
var client = {
|
|
123
|
+
clientX: coordinates.clientX,
|
|
124
|
+
clientY: coordinates.clientY
|
|
125
|
+
};
|
|
126
|
+
var scrollDistance = pipeline.ref.current.domHelper.virtual.scrollLeft - startScrollLeft;
|
|
127
|
+
var startPosition = startX - scrollDistance; // 表头最左边起点
|
|
128
|
+
var offsetDistance = direction === 'rtl' ? startPosition - coordinates.clientX : coordinates.clientX - startPosition;
|
|
129
|
+
updateScrollPosition(client);
|
|
130
|
+
if (offsetDistance < 20) {
|
|
131
|
+
return;
|
|
132
|
+
} else {
|
|
133
|
+
e.stopPropagation();
|
|
134
|
+
}
|
|
135
|
+
document.body.style.userSelect = 'none';
|
|
136
|
+
currentTarget.style.cursor = 'move';
|
|
137
|
+
// 重置位置信息
|
|
138
|
+
cloumnsTranslateData = {};
|
|
139
|
+
allColumns.forEach(function (item) {
|
|
140
|
+
cloumnsTranslateData[item.code] = 0;
|
|
141
|
+
});
|
|
142
|
+
// 计算平移位置
|
|
143
|
+
var replaceIndex = 0;
|
|
144
|
+
var totalWitdth = getColumnWidth(columns[replaceIndex]);
|
|
145
|
+
while (totalWitdth < offsetDistance && replaceIndex < columns.length - 1) {
|
|
146
|
+
replaceIndex++;
|
|
147
|
+
totalWitdth += getColumnWidth(columns[replaceIndex]);
|
|
148
|
+
}
|
|
149
|
+
// 需要取最新startIndex, 不能直接用makeRecursiveMapper提供的startIndex(因为map时还没添加选择列、充满列等后面use添加的列)
|
|
150
|
+
var startIndex;
|
|
151
|
+
columns.forEach(function (column, index) {
|
|
152
|
+
if (column.code === col.code) {
|
|
153
|
+
startIndex = index;
|
|
154
|
+
}
|
|
155
|
+
});
|
|
156
|
+
var optionColumn = columns[startIndex];
|
|
157
|
+
var index = replaceIndex;
|
|
158
|
+
if (startIndex > replaceIndex) {
|
|
159
|
+
// 左移
|
|
160
|
+
while (index < startIndex) {
|
|
161
|
+
var _columns$index = columns[index],
|
|
162
|
+
code = _columns$index.code,
|
|
163
|
+
lock = _columns$index.lock,
|
|
164
|
+
width = _columns$index.width,
|
|
165
|
+
children = _columns$index.children;
|
|
166
|
+
if (enableMove({
|
|
167
|
+
code: code,
|
|
168
|
+
lock: lock
|
|
169
|
+
})) {
|
|
170
|
+
cloumnsTranslateData[code] += _adjustTranslation(optionColumn.width);
|
|
171
|
+
if (isLeafNode(columns[index])) {
|
|
172
|
+
cloumnsTranslateData[optionColumn.code] -= _adjustTranslation(width);
|
|
173
|
+
} else {
|
|
174
|
+
cloumnsTranslateData[optionColumn.code] -= _adjustTranslation(getColumnWidth(columns[index]));
|
|
175
|
+
moveAllChildren(children, cloumnsTranslateData, _adjustTranslation(optionColumn.width));
|
|
232
176
|
}
|
|
177
|
+
columnMoved = true;
|
|
233
178
|
}
|
|
234
|
-
|
|
235
|
-
window.requestAnimationFrame(function () {
|
|
236
|
-
pipeline.setStateAtKey(stateKey, {
|
|
237
|
-
cloumnsTranslateData: cloumnsTranslateData
|
|
238
|
-
});
|
|
239
|
-
moveData = [startIndex, replaceIndex];
|
|
240
|
-
});
|
|
179
|
+
index++;
|
|
241
180
|
}
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
181
|
+
} else if (startIndex < replaceIndex) {
|
|
182
|
+
// 右移
|
|
183
|
+
while (startIndex < index) {
|
|
184
|
+
var _columns$index2 = columns[index],
|
|
185
|
+
_code = _columns$index2.code,
|
|
186
|
+
_lock = _columns$index2.lock,
|
|
187
|
+
_width = _columns$index2.width,
|
|
188
|
+
_children = _columns$index2.children;
|
|
189
|
+
if (enableMove({
|
|
190
|
+
code: _code,
|
|
191
|
+
lock: _lock
|
|
192
|
+
})) {
|
|
193
|
+
cloumnsTranslateData[_code] -= _adjustTranslation(optionColumn.width);
|
|
194
|
+
if (isLeafNode(columns[index])) {
|
|
195
|
+
cloumnsTranslateData[optionColumn.code] += _adjustTranslation(_width);
|
|
196
|
+
} else {
|
|
197
|
+
cloumnsTranslateData[optionColumn.code] += _adjustTranslation(getColumnWidth(columns[index]));
|
|
198
|
+
moveAllChildren(_children, cloumnsTranslateData, _adjustTranslation(optionColumn.width), true);
|
|
199
|
+
}
|
|
200
|
+
columnMoved = true;
|
|
252
201
|
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
_lock2 = _columns$index4.lock;
|
|
299
|
-
|
|
300
|
-
if (enableMove({
|
|
301
|
-
code: _code2,
|
|
302
|
-
lock: _lock2
|
|
303
|
-
})) {
|
|
304
|
-
cloumnsSortData[_code2] -= 1;
|
|
305
|
-
cloumnsSortData[optionColumn.code] += 1;
|
|
306
|
-
columnMoved = true;
|
|
307
|
-
}
|
|
308
|
-
|
|
309
|
-
index--;
|
|
310
|
-
}
|
|
202
|
+
index--;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
window.requestAnimationFrame(function () {
|
|
206
|
+
pipeline.setStateAtKey(stateKey, {
|
|
207
|
+
cloumnsTranslateData: cloumnsTranslateData
|
|
208
|
+
});
|
|
209
|
+
moveData = [startIndex, replaceIndex];
|
|
210
|
+
});
|
|
211
|
+
}
|
|
212
|
+
function handlePointerUp(e) {
|
|
213
|
+
removePointerEventListeners(document.body, {
|
|
214
|
+
onPointerMove: handlePointerMove,
|
|
215
|
+
onPointerUp: handlePointerUp
|
|
216
|
+
}, isTouch);
|
|
217
|
+
window.removeEventListener('selectstart', disableSelect);
|
|
218
|
+
var endCoordinates = getEventCoordinates(e);
|
|
219
|
+
if (hasMovedEnough(mouseDownClientX, mouseDownClientY, endCoordinates.clientX, endCoordinates.clientY)) {
|
|
220
|
+
e.stopPropagation(); // 存在移动就阻止冒泡
|
|
221
|
+
currentTarget.addEventListener('click', stopClickPropagation); // 阻止列头点击事件,防止拖动后触发列头过滤事件
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
window.requestAnimationFrame(function () {
|
|
225
|
+
// 取消阻止列头点击事件
|
|
226
|
+
currentTarget.removeEventListener('click', stopClickPropagation);
|
|
227
|
+
currentTarget = null;
|
|
228
|
+
var _moveData = moveData,
|
|
229
|
+
_moveData2 = _slicedToArray(_moveData, 2),
|
|
230
|
+
startIndex = _moveData2[0],
|
|
231
|
+
replaceIndex = _moveData2[1];
|
|
232
|
+
var optionColumn = columns[startIndex];
|
|
233
|
+
var index = replaceIndex;
|
|
234
|
+
if (startIndex > replaceIndex) {
|
|
235
|
+
// 左移
|
|
236
|
+
while (index < startIndex) {
|
|
237
|
+
var _columns$index3 = columns[index],
|
|
238
|
+
code = _columns$index3.code,
|
|
239
|
+
lock = _columns$index3.lock;
|
|
240
|
+
if (enableMove({
|
|
241
|
+
code: code,
|
|
242
|
+
lock: lock
|
|
243
|
+
})) {
|
|
244
|
+
cloumnsSortData[code] += 1;
|
|
245
|
+
cloumnsSortData[optionColumn.code] -= 1;
|
|
246
|
+
columnMoved = true;
|
|
311
247
|
}
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
onColumnDragStopped(columnMoved, newColumns);
|
|
248
|
+
index++;
|
|
249
|
+
}
|
|
250
|
+
} else if (startIndex < replaceIndex) {
|
|
251
|
+
// 右移
|
|
252
|
+
while (index > startIndex) {
|
|
253
|
+
var _columns$index4 = columns[index],
|
|
254
|
+
_code2 = _columns$index4.code,
|
|
255
|
+
_lock2 = _columns$index4.lock;
|
|
256
|
+
if (enableMove({
|
|
257
|
+
code: _code2,
|
|
258
|
+
lock: _lock2
|
|
259
|
+
})) {
|
|
260
|
+
cloumnsSortData[_code2] -= 1;
|
|
261
|
+
cloumnsSortData[optionColumn.code] += 1;
|
|
262
|
+
columnMoved = true;
|
|
329
263
|
}
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
264
|
+
index--;
|
|
265
|
+
}
|
|
266
|
+
}
|
|
267
|
+
var onColumnDragStopped = opts.onColumnDragStopped;
|
|
268
|
+
// 拖拽结束返回列顺序
|
|
269
|
+
if (onColumnDragStopped) {
|
|
270
|
+
var _context;
|
|
271
|
+
var isRowDragColumn = function isRowDragColumn(code) {
|
|
272
|
+
var rowDragColumnKey = pipeline.getFeatureOptions('rowDragColumnKey');
|
|
273
|
+
return code === rowDragColumnKey;
|
|
274
|
+
};
|
|
275
|
+
var newColumns = _filterInstanceProperty(_context = sortColumns(columns, cloumnsSortData)).call(_context, function (column) {
|
|
276
|
+
return column.code !== FILL_COLUMN_CODE && !isRowDragColumn(column.code) && !isSelectColumn(column);
|
|
334
277
|
});
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
currentTarget.style.cursor = '';
|
|
278
|
+
// TODO drag需要在resize之后use,否则这里返回的列对应的宽度不是拖拽后的
|
|
279
|
+
onColumnDragStopped(columnMoved, newColumns);
|
|
338
280
|
}
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
}
|
|
343
|
-
style
|
|
344
|
-
|
|
345
|
-
|
|
281
|
+
pipeline.setStateAtKey(stateKey, {
|
|
282
|
+
cloumnsTranslateData: null
|
|
283
|
+
});
|
|
284
|
+
});
|
|
285
|
+
document.body.style.userSelect = '';
|
|
286
|
+
currentTarget.style.opacity = '';
|
|
287
|
+
currentTarget.style.cursor = '';
|
|
288
|
+
}
|
|
289
|
+
var onColumnDragStart = opts.onColumnDragStart;
|
|
290
|
+
onColumnDragStart && onColumnDragStart(col);
|
|
291
|
+
addPointerEventListeners(document.body, {
|
|
292
|
+
onPointerMove: handlePointerMove,
|
|
293
|
+
onPointerUp: handlePointerUp
|
|
294
|
+
}, isTouch);
|
|
295
|
+
}
|
|
346
296
|
}));
|
|
347
297
|
};
|
|
348
298
|
}
|
|
349
|
-
|
|
350
299
|
function enableMove(_ref) {
|
|
351
300
|
var lock = _ref.lock,
|
|
352
|
-
|
|
301
|
+
code = _ref.code;
|
|
353
302
|
return code && code !== FILL_COLUMN_CODE && !lock;
|
|
354
303
|
}
|
|
355
|
-
|
|
356
304
|
function getColumnWidth(col) {
|
|
357
305
|
if (col.children) {
|
|
358
306
|
return col.children.reduce(function (acc, col) {
|
|
359
307
|
return acc + getColumnWidth(col);
|
|
360
308
|
}, 0);
|
|
361
309
|
}
|
|
362
|
-
|
|
363
310
|
return col.width;
|
|
364
311
|
}
|
|
365
|
-
|
|
366
312
|
function moveAllChildren(cols, cloumnsTranslateData, width, isMinus) {
|
|
367
313
|
cols.forEach(function (col) {
|
|
368
314
|
var _a;
|
|
369
|
-
|
|
370
315
|
var code = col.code,
|
|
371
|
-
|
|
316
|
+
children = col.children;
|
|
372
317
|
var movedWidth = (_a = cloumnsTranslateData[code]) !== null && _a !== void 0 ? _a : 0;
|
|
373
318
|
cloumnsTranslateData[code] = movedWidth + (isMinus ? -width : width);
|
|
374
|
-
|
|
375
319
|
if (!isLeafNode(col)) {
|
|
376
320
|
moveAllChildren(children, cloumnsTranslateData, width);
|
|
377
321
|
}
|
|
378
322
|
});
|
|
379
|
-
}
|
|
380
|
-
|
|
381
|
-
function _isMoveWhenClicking(mouseDownClientX, mouseDownClientY, mouseUpClientX, mouseUpClientY) {
|
|
382
|
-
var xDiff = mouseUpClientX - mouseDownClientX;
|
|
383
|
-
var yDiff = mouseUpClientY - mouseDownClientY; // 鼠标点按和松开的偏移量大于5px,认为存在移动
|
|
384
|
-
|
|
385
|
-
if (Math.sqrt(xDiff * xDiff + yDiff * yDiff) > 5) {
|
|
386
|
-
return true;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
return false;
|
|
390
323
|
}
|