linkmore-design 1.1.21 → 1.1.22-beta.1
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/LmDrag/LmDrag.d.ts +2 -3
- package/dist/LmEditTable/EditTable.d.ts +14 -4
- package/dist/LmTable/common/index.d.ts +10 -0
- package/dist/LmTable/components/Container/Container.d.ts +18 -0
- package/dist/LmTable/components/Container/index.d.ts +2 -0
- package/dist/LmTable/components/DndContainer.d.ts +37 -5
- package/dist/LmTable/components/HeaderCol.d.ts +1 -0
- package/dist/LmTable/components/Item/Item.d.ts +37 -0
- package/dist/LmTable/components/Item/components/Action/Action.d.ts +10 -0
- package/dist/LmTable/components/Item/components/Action/index.d.ts +2 -0
- package/dist/LmTable/components/Item/components/Handle/index.d.ts +4 -0
- package/dist/LmTable/components/Item/components/Remove/index.d.ts +2 -0
- package/dist/LmTable/components/Item/components/index.d.ts +3 -0
- package/dist/LmTable/components/Item/index.d.ts +2 -0
- package/dist/LmTable/components/{sortableBoxCol.d.ts → SortableBox.d.ts} +0 -0
- package/dist/LmTable/demos/{excelGroup.d.ts → draggable.d.ts} +0 -0
- package/dist/LmTable/hooks/useDndItems.d.ts +13 -0
- package/dist/LmTable/multipleContainersKeyboardCoordinates.d.ts +3 -0
- package/dist/LmTable/testDemos/group.d.ts +2 -0
- package/dist/LmUpload/fns/index.d.ts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.umd.css +367 -0
- package/dist/index.umd.js +1775 -51950
- package/dist/index.umd.min.css +1 -1
- package/dist/index.umd.min.js +23 -47
- package/dist/variables.css +10 -2
- package/es/LmDrag/LmDrag.d.ts +2 -3
- package/es/LmEditTable/EditTable.d.ts +14 -4
- package/es/LmEditTable/EditTable.js +78 -54
- package/es/LmFilter/components/DropdownFIlter.js +26 -5
- package/es/LmFilter/style/index.css +9 -0
- package/es/LmFilter/style/variables.css +9 -0
- package/es/LmTable/Table.js +132 -125
- package/es/LmTable/common/index.d.ts +10 -0
- package/es/LmTable/common/index.js +38 -0
- package/es/LmTable/components/Container/Container.css +87 -0
- package/es/LmTable/components/Container/Container.d.ts +18 -0
- package/es/LmTable/components/Container/Container.js +48 -0
- package/es/LmTable/components/Container/index.d.ts +2 -0
- package/es/LmTable/components/Container/index.js +1 -0
- package/es/LmTable/components/DndContainer.d.ts +37 -5
- package/es/LmTable/components/DndContainer.js +699 -24
- package/es/LmTable/components/DndContainer.module.css +6 -0
- package/es/LmTable/components/HeaderCol.js +46 -0
- package/es/LmTable/components/Item/Item.css +113 -0
- package/es/LmTable/components/Item/Item.d.ts +37 -0
- package/es/LmTable/components/Item/Item.js +88 -0
- package/es/LmTable/components/Item/components/Action/Action.css +41 -0
- package/es/LmTable/components/Item/components/Action/Action.d.ts +10 -0
- package/es/LmTable/components/Item/components/Action/Action.js +35 -0
- package/es/LmTable/components/Item/components/Action/index.d.ts +2 -0
- package/es/LmTable/components/Item/components/Action/index.js +1 -0
- package/es/LmTable/components/Item/components/Handle/index.d.ts +4 -0
- package/es/LmTable/components/Item/components/Handle/index.js +15 -0
- package/es/LmTable/components/Item/components/Remove/index.d.ts +2 -0
- package/es/LmTable/components/Item/components/Remove/index.js +16 -0
- package/es/LmTable/components/Item/components/index.d.ts +3 -0
- package/es/LmTable/components/Item/components/index.js +3 -0
- package/es/LmTable/components/Item/index.d.ts +2 -0
- package/es/LmTable/components/Item/index.js +2 -0
- package/es/LmTable/components/{sortableBoxCol.js → SortableBox.js} +0 -0
- package/es/LmTable/hooks/useDndItems.d.ts +13 -0
- package/es/LmTable/hooks/useDndItems.js +156 -0
- package/es/LmTable/multipleContainersKeyboardCoordinates.d.ts +3 -0
- package/es/LmTable/multipleContainersKeyboardCoordinates.js +117 -0
- package/es/LmTable/style/index.css +1 -2
- package/es/LmTable/style/variables.css +1 -2
- package/es/LmTable/testDemos/group.js +131 -0
- package/es/LmUpload/UploadList/ItemPictureCard.js +2 -9
- package/es/LmUpload/UploadList/index.js +3 -6
- package/es/LmUpload/fns/index.d.ts +1 -0
- package/es/LmUpload/fns/index.js +17 -2
- package/es/index.d.ts +1 -0
- package/es/styles/variables.css +10 -2
- package/lib/LmDrag/LmDrag.d.ts +2 -3
- package/lib/LmEditTable/EditTable.d.ts +14 -4
- package/lib/LmEditTable/EditTable.js +77 -53
- package/lib/LmFilter/components/DropdownFIlter.js +26 -5
- package/lib/LmFilter/style/index.css +9 -0
- package/lib/LmFilter/style/variables.css +9 -0
- package/lib/LmTable/Table.js +132 -125
- package/lib/LmTable/common/index.d.ts +10 -0
- package/lib/LmTable/common/index.js +48 -0
- package/lib/LmTable/components/Container/Container.css +87 -0
- package/lib/LmTable/components/Container/Container.d.ts +18 -0
- package/lib/LmTable/components/Container/Container.js +62 -0
- package/lib/LmTable/components/Container/index.d.ts +2 -0
- package/lib/LmTable/components/Container/index.js +13 -0
- package/lib/LmTable/components/DndContainer.d.ts +37 -5
- package/lib/LmTable/components/DndContainer.js +709 -26
- package/lib/LmTable/components/DndContainer.module.css +6 -0
- package/lib/LmTable/components/HeaderCol.js +46 -0
- package/lib/LmTable/components/Item/Item.css +113 -0
- package/lib/LmTable/components/Item/Item.d.ts +37 -0
- package/lib/LmTable/components/Item/Item.js +104 -0
- package/lib/LmTable/components/Item/components/Action/Action.css +41 -0
- package/lib/LmTable/components/Item/components/Action/Action.d.ts +10 -0
- package/lib/LmTable/components/Item/components/Action/Action.js +50 -0
- package/lib/LmTable/components/Item/components/Action/index.d.ts +2 -0
- package/lib/LmTable/components/Item/components/Action/index.js +13 -0
- package/lib/LmTable/components/Item/components/Handle/index.d.ts +4 -0
- package/lib/LmTable/components/Item/components/Handle/index.js +27 -0
- package/lib/LmTable/components/Item/components/Remove/index.d.ts +2 -0
- package/lib/LmTable/components/Item/components/Remove/index.js +27 -0
- package/lib/LmTable/components/Item/components/index.d.ts +3 -0
- package/lib/LmTable/components/Item/components/index.js +31 -0
- package/lib/LmTable/components/Item/index.d.ts +2 -0
- package/lib/LmTable/components/Item/index.js +33 -0
- package/lib/LmTable/components/{sortableBoxCol.js → SortableBox.js} +0 -0
- package/lib/LmTable/hooks/useDndItems.d.ts +13 -0
- package/lib/LmTable/hooks/useDndItems.js +168 -0
- package/lib/LmTable/multipleContainersKeyboardCoordinates.d.ts +3 -0
- package/lib/LmTable/multipleContainersKeyboardCoordinates.js +126 -0
- package/lib/LmTable/style/index.css +1 -2
- package/lib/LmTable/style/variables.css +1 -2
- package/lib/LmTable/testDemos/group.js +131 -0
- package/lib/LmUpload/UploadList/ItemPictureCard.js +2 -9
- package/lib/LmUpload/UploadList/index.js +3 -6
- package/lib/LmUpload/fns/index.d.ts +1 -0
- package/lib/LmUpload/fns/index.js +17 -2
- package/lib/index.d.ts +1 -0
- package/lib/styles/variables.css +10 -2
- package/package.json +4 -4
- package/dist/LmTable/components/sortableItemCol.d.ts +0 -1
- package/es/LmTable/components/sortableItemCol.js +0 -56
- package/lib/LmTable/components/sortableItemCol.js +0 -56
|
@@ -1,35 +1,710 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
3
|
-
import
|
|
4
|
-
import React from 'react'; // 可拖拽容器
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
|
|
3
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
5
4
|
|
|
6
|
-
var
|
|
7
|
-
var
|
|
8
|
-
move = _ref.move;
|
|
9
|
-
var sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
|
|
10
|
-
coordinateGetter: sortableKeyboardCoordinates
|
|
11
|
-
})); // 拖拽结束
|
|
5
|
+
var __rest = this && this.__rest || function (s, e) {
|
|
6
|
+
var t = {};
|
|
12
7
|
|
|
13
|
-
var
|
|
14
|
-
|
|
15
|
-
|
|
8
|
+
for (var p in s) {
|
|
9
|
+
if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) t[p] = s[p];
|
|
10
|
+
}
|
|
16
11
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
if (s != null && typeof Object.getOwnPropertySymbols === "function") for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
|
|
13
|
+
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) t[p[i]] = s[p[i]];
|
|
14
|
+
}
|
|
15
|
+
return t;
|
|
16
|
+
};
|
|
17
|
+
|
|
18
|
+
import React, { useCallback, useEffect, useRef, useState } from 'react';
|
|
19
|
+
import { createPortal, unstable_batchedUpdates } from 'react-dom';
|
|
20
|
+
import { closestCenter, pointerWithin, // 返回指针悬停在其上的矩形
|
|
21
|
+
rectIntersection, DndContext, DragOverlay, // DropAnimation,
|
|
22
|
+
getFirstCollision, KeyboardSensor, MouseSensor, TouchSensor, useDroppable, useSensors, useSensor, MeasuringStrategy } from '@dnd-kit/core';
|
|
23
|
+
import { SortableContext, useSortable, arrayMove, defaultAnimateLayoutChanges, horizontalListSortingStrategy } from '@dnd-kit/sortable';
|
|
24
|
+
import { CSS } from '@dnd-kit/utilities';
|
|
25
|
+
import multipleContainersCoordinateGetter from '../multipleContainersKeyboardCoordinates';
|
|
26
|
+
import { Item } from './Item';
|
|
27
|
+
import { Container } from './Container';
|
|
28
|
+
import classNames from 'classnames';
|
|
29
|
+
import "./DndContainer.module.css";
|
|
30
|
+
|
|
31
|
+
var defaultDropAnimationSideEffects = function defaultDropAnimationSideEffects(options) {
|
|
32
|
+
return function (_ref) {
|
|
33
|
+
var active = _ref.active,
|
|
34
|
+
dragOverlay = _ref.dragOverlay;
|
|
35
|
+
var originalStyles = {};
|
|
36
|
+
var styles = options.styles,
|
|
37
|
+
className = options.className;
|
|
38
|
+
|
|
39
|
+
if (styles === null || styles === void 0 ? void 0 : styles.active) {
|
|
40
|
+
for (var _i = 0, _Object$entries = Object.entries(styles.active); _i < _Object$entries.length; _i++) {
|
|
41
|
+
var _Object$entries$_i = _slicedToArray(_Object$entries[_i], 2),
|
|
42
|
+
key = _Object$entries$_i[0],
|
|
43
|
+
value = _Object$entries$_i[1];
|
|
44
|
+
|
|
45
|
+
if (value === undefined) {
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
originalStyles[key] = active.node.style.getPropertyValue(key);
|
|
50
|
+
active.node.style.setProperty(key, value);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
if (styles === null || styles === void 0 ? void 0 : styles.dragOverlay) {
|
|
55
|
+
for (var _i2 = 0, _Object$entries2 = Object.entries(styles.dragOverlay); _i2 < _Object$entries2.length; _i2++) {
|
|
56
|
+
var _Object$entries2$_i = _slicedToArray(_Object$entries2[_i2], 2),
|
|
57
|
+
_key = _Object$entries2$_i[0],
|
|
58
|
+
_value = _Object$entries2$_i[1];
|
|
59
|
+
|
|
60
|
+
if (_value === undefined) {
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
dragOverlay.node.style.setProperty(_key, _value);
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
if (className === null || className === void 0 ? void 0 : className.active) {
|
|
69
|
+
active.node.classList.add(className.active);
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (className === null || className === void 0 ? void 0 : className.dragOverlay) {
|
|
73
|
+
dragOverlay.node.classList.add(className.dragOverlay);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return function cleanup() {
|
|
77
|
+
for (var _i3 = 0, _Object$entries3 = Object.entries(originalStyles); _i3 < _Object$entries3.length; _i3++) {
|
|
78
|
+
var _Object$entries3$_i = _slicedToArray(_Object$entries3[_i3], 2),
|
|
79
|
+
_key2 = _Object$entries3$_i[0],
|
|
80
|
+
_value2 = _Object$entries3$_i[1];
|
|
81
|
+
|
|
82
|
+
active.node.style.setProperty(_key2, _value2);
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
if (className === null || className === void 0 ? void 0 : className.active) {
|
|
86
|
+
active.node.classList.remove(className.active);
|
|
87
|
+
}
|
|
88
|
+
};
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
|
|
92
|
+
var animateLayoutChanges = function animateLayoutChanges(args) {
|
|
93
|
+
return defaultAnimateLayoutChanges(Object.assign(Object.assign({}, args), {
|
|
94
|
+
wasDragging: true
|
|
95
|
+
}));
|
|
96
|
+
};
|
|
97
|
+
|
|
98
|
+
function DroppableContainer(_a) {
|
|
99
|
+
var _b;
|
|
100
|
+
|
|
101
|
+
var children = _a.children,
|
|
102
|
+
_a$columns = _a.columns,
|
|
103
|
+
columns = _a$columns === void 0 ? 1 : _a$columns,
|
|
104
|
+
disabled = _a.disabled,
|
|
105
|
+
id = _a.id,
|
|
106
|
+
items = _a.items,
|
|
107
|
+
style = _a.style,
|
|
108
|
+
props = __rest(_a, ["children", "columns", "disabled", "id", "items", "style"]);
|
|
109
|
+
|
|
110
|
+
var _useSortable = useSortable({
|
|
111
|
+
id: id,
|
|
112
|
+
data: {
|
|
113
|
+
type: 'container',
|
|
114
|
+
children: items
|
|
115
|
+
},
|
|
116
|
+
animateLayoutChanges: animateLayoutChanges
|
|
117
|
+
}),
|
|
118
|
+
active = _useSortable.active,
|
|
119
|
+
attributes = _useSortable.attributes,
|
|
120
|
+
isDragging = _useSortable.isDragging,
|
|
121
|
+
listeners = _useSortable.listeners,
|
|
122
|
+
over = _useSortable.over,
|
|
123
|
+
setNodeRef = _useSortable.setNodeRef,
|
|
124
|
+
transition = _useSortable.transition,
|
|
125
|
+
transform = _useSortable.transform;
|
|
126
|
+
|
|
127
|
+
var isOverContainer = over ? id === over.id && ((_b = active === null || active === void 0 ? void 0 : active.data.current) === null || _b === void 0 ? void 0 : _b.type) !== 'container' || items.includes(over.id) : false;
|
|
128
|
+
return /*#__PURE__*/React.createElement(Container, Object.assign({
|
|
129
|
+
ref: disabled ? undefined : setNodeRef,
|
|
130
|
+
style: Object.assign(Object.assign({}, style), {
|
|
131
|
+
transition: transition,
|
|
132
|
+
transform: CSS.Translate.toString(transform),
|
|
133
|
+
opacity: isDragging ? 0.5 : undefined
|
|
134
|
+
}),
|
|
135
|
+
hover: isOverContainer,
|
|
136
|
+
handleProps: Object.assign(Object.assign({}, attributes), listeners),
|
|
137
|
+
columns: columns
|
|
138
|
+
}, props), children);
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
var dropAnimation = {
|
|
142
|
+
sideEffects: defaultDropAnimationSideEffects({
|
|
143
|
+
styles: {
|
|
144
|
+
active: {
|
|
145
|
+
opacity: '0.5'
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
})
|
|
149
|
+
};
|
|
150
|
+
export var TRASH_ID = 'void';
|
|
151
|
+
var PLACEHOLDER_ID = 'placeholder'; // const empty: UniqueIdentifier[] = [];
|
|
152
|
+
|
|
153
|
+
export default function DndContainer(_ref2) {
|
|
154
|
+
var _ref2$adjustScale = _ref2.adjustScale,
|
|
155
|
+
adjustScale = _ref2$adjustScale === void 0 ? false : _ref2$adjustScale,
|
|
156
|
+
_ref2$itemCount = _ref2.itemCount,
|
|
157
|
+
itemCount = _ref2$itemCount === void 0 ? 3 : _ref2$itemCount,
|
|
158
|
+
cancelDrop = _ref2.cancelDrop,
|
|
159
|
+
columns = _ref2.columns,
|
|
160
|
+
_ref2$handle = _ref2.handle,
|
|
161
|
+
handle = _ref2$handle === void 0 ? false : _ref2$handle,
|
|
162
|
+
initialItems = _ref2.items,
|
|
163
|
+
containerStyle = _ref2.containerStyle,
|
|
164
|
+
_ref2$coordinateGette = _ref2.coordinateGetter,
|
|
165
|
+
coordinateGetter = _ref2$coordinateGette === void 0 ? multipleContainersCoordinateGetter : _ref2$coordinateGette,
|
|
166
|
+
_ref2$getItemStyles = _ref2.getItemStyles,
|
|
167
|
+
getItemStyles = _ref2$getItemStyles === void 0 ? function () {
|
|
168
|
+
return {};
|
|
169
|
+
} : _ref2$getItemStyles,
|
|
170
|
+
_ref2$wrapperStyle = _ref2.wrapperStyle,
|
|
171
|
+
wrapperStyle = _ref2$wrapperStyle === void 0 ? function () {
|
|
172
|
+
return {};
|
|
173
|
+
} : _ref2$wrapperStyle,
|
|
174
|
+
modifiers = _ref2.modifiers,
|
|
175
|
+
renderItem = _ref2.renderItem,
|
|
176
|
+
_ref2$trashable = _ref2.trashable,
|
|
177
|
+
trashable = _ref2$trashable === void 0 ? false : _ref2$trashable,
|
|
178
|
+
scrollable = _ref2.scrollable,
|
|
179
|
+
children = _ref2.children,
|
|
180
|
+
_ref2$updateItems = _ref2.updateItems,
|
|
181
|
+
updateItems = _ref2$updateItems === void 0 ? function () {
|
|
182
|
+
return {};
|
|
183
|
+
} : _ref2$updateItems,
|
|
184
|
+
_ref2$rowGroupTitle = _ref2.rowGroupTitle,
|
|
185
|
+
rowGroupTitle = _ref2$rowGroupTitle === void 0 ? '行分组' : _ref2$rowGroupTitle,
|
|
186
|
+
_ref2$colGroupTitle = _ref2.colGroupTitle,
|
|
187
|
+
colGroupTitle = _ref2$colGroupTitle === void 0 ? '列分组' : _ref2$colGroupTitle;
|
|
188
|
+
|
|
189
|
+
var _useState = useState(function () {
|
|
190
|
+
return initialItems;
|
|
191
|
+
}),
|
|
192
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
193
|
+
items = _useState2[0],
|
|
194
|
+
setItems = _useState2[1];
|
|
195
|
+
|
|
196
|
+
useEffect(function () {
|
|
197
|
+
setItems(initialItems);
|
|
198
|
+
}, [initialItems]);
|
|
199
|
+
|
|
200
|
+
var _useState3 = useState(Object.keys(items)),
|
|
201
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
202
|
+
containers = _useState4[0],
|
|
203
|
+
setContainers = _useState4[1];
|
|
204
|
+
|
|
205
|
+
var _useState5 = useState(null),
|
|
206
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
207
|
+
activeId = _useState6[0],
|
|
208
|
+
setActiveId = _useState6[1];
|
|
209
|
+
|
|
210
|
+
var lastOverId = useRef(null); // 是否移动到新容器
|
|
211
|
+
|
|
212
|
+
var recentlyMovedToNewContainer = useRef(false);
|
|
213
|
+
var isSortingContainer = activeId ? containers.includes(activeId) : false; // 执行顺序: onDragStart,collisionDetection,onDragOver,[...collisionDetection],onDragEnd
|
|
214
|
+
|
|
215
|
+
/**
|
|
216
|
+
* Custom collision detection strategy optimized for multiple containers
|
|
217
|
+
* 针对多个容器优化的自定义碰撞检测策略
|
|
218
|
+
* - First, find any droppable containers intersecting with the pointer.
|
|
219
|
+
* - If there are none, find intersecting containers with the active draggable.
|
|
220
|
+
* - If there are no intersecting containers, return the last matched intersection
|
|
221
|
+
* 1.首先,找到与指针相交的任何可放置容器。2.如果没有,则查找具有活动可拖动对象的相交容器。3.如果没有交叉容器,则返回最后匹配的交叉
|
|
222
|
+
*/
|
|
223
|
+
|
|
224
|
+
var collisionDetectionStrategy = useCallback(function (args) {
|
|
225
|
+
var _a;
|
|
226
|
+
|
|
227
|
+
if (activeId && activeId in items) {
|
|
228
|
+
return closestCenter(Object.assign(Object.assign({}, args), {
|
|
229
|
+
droppableContainers: args.droppableContainers.filter(function (container) {
|
|
230
|
+
return container.id in items;
|
|
231
|
+
})
|
|
232
|
+
}));
|
|
233
|
+
} // Start by finding any intersecting droppable
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
var pointerIntersections = pointerWithin(args);
|
|
237
|
+
var intersections = pointerIntersections.length > 0 ? // If there are droppables intersecting with the pointer, return those
|
|
238
|
+
pointerIntersections : rectIntersection(args);
|
|
239
|
+
var overId = getFirstCollision(intersections, 'id');
|
|
240
|
+
|
|
241
|
+
if (overId != null) {
|
|
242
|
+
if (overId === TRASH_ID) {
|
|
243
|
+
// If the intersecting droppable is the trash, return early
|
|
244
|
+
// Remove this if you're not using trashable functionality in your app
|
|
245
|
+
return intersections;
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
if (overId in items) {
|
|
249
|
+
var containerItems = items[overId]; // If a container is matched and it contains items (columns 'A', 'B', 'C')
|
|
250
|
+
|
|
251
|
+
if (containerItems.length > 0) {
|
|
252
|
+
// Return the closest droppable within that container
|
|
253
|
+
overId = (_a = closestCenter(Object.assign(Object.assign({}, args), {
|
|
254
|
+
droppableContainers: args.droppableContainers.filter(function (container) {
|
|
255
|
+
return container.id !== overId && containerItems.includes(container.id);
|
|
256
|
+
})
|
|
257
|
+
}))[0]) === null || _a === void 0 ? void 0 : _a.id;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
lastOverId.current = overId;
|
|
262
|
+
return [{
|
|
263
|
+
id: overId
|
|
264
|
+
}];
|
|
265
|
+
} // When a draggable item moves to a new container, the layout may shift
|
|
266
|
+
// and the `overId` may become `null`. We manually set the cached `lastOverId`
|
|
267
|
+
// to the id of the draggable item that was moved to the new container, otherwise
|
|
268
|
+
// the previous `overId` will be returned which can cause items to incorrectly shift positions
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
if (recentlyMovedToNewContainer.current) {
|
|
272
|
+
lastOverId.current = activeId;
|
|
273
|
+
} // If no droppable is matched, return the last match
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
return lastOverId.current ? [{
|
|
277
|
+
id: lastOverId.current
|
|
278
|
+
}] : [];
|
|
279
|
+
}, [activeId, items]);
|
|
280
|
+
|
|
281
|
+
var _useState7 = useState(null),
|
|
282
|
+
_useState8 = _slicedToArray(_useState7, 2),
|
|
283
|
+
clonedItems = _useState8[0],
|
|
284
|
+
setClonedItems = _useState8[1]; // 传感器
|
|
20
285
|
|
|
21
286
|
|
|
22
|
-
|
|
23
|
-
|
|
287
|
+
var sensors = useSensors(useSensor(MouseSensor), useSensor(TouchSensor), useSensor(KeyboardSensor, {
|
|
288
|
+
coordinateGetter: coordinateGetter
|
|
289
|
+
}));
|
|
290
|
+
|
|
291
|
+
var findContainer = function findContainer(id) {
|
|
292
|
+
if (id in items) {
|
|
293
|
+
return id;
|
|
24
294
|
}
|
|
295
|
+
|
|
296
|
+
return Object.keys(items).find(function (key) {
|
|
297
|
+
return items[key].includes(id);
|
|
298
|
+
});
|
|
299
|
+
};
|
|
300
|
+
|
|
301
|
+
var getIndex = function getIndex(id) {
|
|
302
|
+
var container = findContainer(id);
|
|
303
|
+
|
|
304
|
+
if (!container) {
|
|
305
|
+
return -1;
|
|
306
|
+
}
|
|
307
|
+
|
|
308
|
+
var index = items[container].indexOf(id);
|
|
309
|
+
return index;
|
|
25
310
|
};
|
|
26
311
|
|
|
312
|
+
var onDragCancel = function onDragCancel() {
|
|
313
|
+
if (clonedItems) {
|
|
314
|
+
// Reset items to their original state in case items have been
|
|
315
|
+
// Dragged across containers
|
|
316
|
+
setItems(clonedItems);
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
setActiveId(null);
|
|
320
|
+
setClonedItems(null);
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
useEffect(function () {
|
|
324
|
+
var id = requestAnimationFrame(function () {
|
|
325
|
+
recentlyMovedToNewContainer.current = false;
|
|
326
|
+
});
|
|
327
|
+
return function () {
|
|
328
|
+
return cancelAnimationFrame(id);
|
|
329
|
+
};
|
|
330
|
+
}, [items]);
|
|
331
|
+
var topContainers = containers.filter(function (item) {
|
|
332
|
+
return item !== 'tableHeader';
|
|
333
|
+
});
|
|
334
|
+
var tableContainer = containers.filter(function (item) {
|
|
335
|
+
return item === 'tableHeader';
|
|
336
|
+
})[0];
|
|
27
337
|
return /*#__PURE__*/React.createElement(DndContext, {
|
|
28
338
|
sensors: sensors,
|
|
29
|
-
collisionDetection:
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
}
|
|
339
|
+
collisionDetection: collisionDetectionStrategy,
|
|
340
|
+
measuring: {
|
|
341
|
+
droppable: {
|
|
342
|
+
strategy: MeasuringStrategy.Always
|
|
343
|
+
}
|
|
344
|
+
},
|
|
345
|
+
onDragStart: function onDragStart(_ref3) {
|
|
346
|
+
var active = _ref3.active;
|
|
347
|
+
setActiveId(active.id);
|
|
348
|
+
setClonedItems(items);
|
|
349
|
+
},
|
|
350
|
+
onDragOver: function onDragOver(_ref4) {
|
|
351
|
+
var active = _ref4.active,
|
|
352
|
+
over = _ref4.over;
|
|
353
|
+
var overId = over === null || over === void 0 ? void 0 : over.id;
|
|
354
|
+
|
|
355
|
+
if (overId == null || overId === TRASH_ID || active.id in items) {
|
|
356
|
+
return;
|
|
357
|
+
}
|
|
358
|
+
|
|
359
|
+
var overContainer = findContainer(overId);
|
|
360
|
+
var activeContainer = findContainer(active.id);
|
|
361
|
+
|
|
362
|
+
if (!overContainer || !activeContainer) {
|
|
363
|
+
return;
|
|
364
|
+
}
|
|
365
|
+
|
|
366
|
+
if (activeContainer !== overContainer) {
|
|
367
|
+
setItems(function (items) {
|
|
368
|
+
var _Object$assign;
|
|
369
|
+
|
|
370
|
+
var activeItems = items[activeContainer];
|
|
371
|
+
var overItems = items[overContainer];
|
|
372
|
+
var overIndex = overItems.indexOf(overId);
|
|
373
|
+
var activeIndex = activeItems.indexOf(active.id);
|
|
374
|
+
var newIndex;
|
|
375
|
+
|
|
376
|
+
if (overId in items) {
|
|
377
|
+
newIndex = overItems.length + 1;
|
|
378
|
+
} else {
|
|
379
|
+
// 当前激活的是否在目标下面
|
|
380
|
+
var isBelowOverItem = over && active.rect.current.translated && active.rect.current.translated.top > over.rect.top + over.rect.height;
|
|
381
|
+
var modifier = isBelowOverItem ? 1 : 0;
|
|
382
|
+
newIndex = overIndex >= 0 ? overIndex + modifier : overItems.length + 1;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
recentlyMovedToNewContainer.current = true;
|
|
386
|
+
return Object.assign(Object.assign({}, items), (_Object$assign = {}, _defineProperty(_Object$assign, activeContainer, items[activeContainer].filter(function (item) {
|
|
387
|
+
return item !== active.id;
|
|
388
|
+
})), _defineProperty(_Object$assign, overContainer, [].concat(_toConsumableArray(items[overContainer].slice(0, newIndex)), [items[activeContainer][activeIndex]], _toConsumableArray(items[overContainer].slice(newIndex, items[overContainer].length)))), _Object$assign));
|
|
389
|
+
});
|
|
390
|
+
}
|
|
391
|
+
},
|
|
392
|
+
onDragEnd: function onDragEnd(_ref5) {
|
|
393
|
+
var active = _ref5.active,
|
|
394
|
+
over = _ref5.over;
|
|
395
|
+
|
|
396
|
+
// 容器拖拽
|
|
397
|
+
if (active.id in items && (over === null || over === void 0 ? void 0 : over.id)) {
|
|
398
|
+
setContainers(function (containers) {
|
|
399
|
+
var activeIndex = containers.indexOf(active.id);
|
|
400
|
+
var overIndex = containers.indexOf(over.id);
|
|
401
|
+
return arrayMove(containers, activeIndex, overIndex);
|
|
402
|
+
});
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
var activeContainer = findContainer(active.id);
|
|
406
|
+
|
|
407
|
+
if (!activeContainer) {
|
|
408
|
+
setActiveId(null);
|
|
409
|
+
return;
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
var overId = over === null || over === void 0 ? void 0 : over.id;
|
|
413
|
+
|
|
414
|
+
if (overId == null) {
|
|
415
|
+
setActiveId(null);
|
|
416
|
+
return;
|
|
417
|
+
}
|
|
418
|
+
|
|
419
|
+
if (overId === TRASH_ID) {
|
|
420
|
+
console.log('TRASH_ID', overId);
|
|
421
|
+
setItems(function (items) {
|
|
422
|
+
return Object.assign(Object.assign({}, items), _defineProperty({}, activeContainer, items[activeContainer].filter(function (id) {
|
|
423
|
+
return id !== activeId;
|
|
424
|
+
})));
|
|
425
|
+
});
|
|
426
|
+
setActiveId(null);
|
|
427
|
+
return;
|
|
428
|
+
}
|
|
429
|
+
|
|
430
|
+
if (overId === PLACEHOLDER_ID) {
|
|
431
|
+
var newContainerId = getNextContainerId();
|
|
432
|
+
unstable_batchedUpdates(function () {
|
|
433
|
+
setContainers(function (containers) {
|
|
434
|
+
return [].concat(_toConsumableArray(containers), [newContainerId]);
|
|
435
|
+
});
|
|
436
|
+
console.log('PLACEHOLDER_ID', overId);
|
|
437
|
+
setItems(function (items) {
|
|
438
|
+
var _Object$assign3;
|
|
439
|
+
|
|
440
|
+
return Object.assign(Object.assign({}, items), (_Object$assign3 = {}, _defineProperty(_Object$assign3, activeContainer, items[activeContainer].filter(function (id) {
|
|
441
|
+
return id !== activeId;
|
|
442
|
+
})), _defineProperty(_Object$assign3, newContainerId, [active.id]), _Object$assign3));
|
|
443
|
+
});
|
|
444
|
+
setActiveId(null);
|
|
445
|
+
});
|
|
446
|
+
return;
|
|
447
|
+
}
|
|
448
|
+
|
|
449
|
+
var overContainer = findContainer(overId);
|
|
450
|
+
|
|
451
|
+
if (overContainer) {
|
|
452
|
+
var activeIndex = items[activeContainer].indexOf(active.id);
|
|
453
|
+
var overIndex = items[overContainer].indexOf(overId);
|
|
454
|
+
|
|
455
|
+
if (activeIndex !== overIndex) {
|
|
456
|
+
var newItems = Object.assign(Object.assign({}, items), _defineProperty({}, overContainer, arrayMove(items[overContainer], activeIndex, overIndex)));
|
|
457
|
+
setItems(newItems);
|
|
458
|
+
updateItems(newItems);
|
|
459
|
+
} else {
|
|
460
|
+
updateItems(items);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
setActiveId(null);
|
|
465
|
+
},
|
|
466
|
+
cancelDrop: cancelDrop,
|
|
467
|
+
onDragCancel: onDragCancel,
|
|
468
|
+
modifiers: modifiers
|
|
469
|
+
}, /*#__PURE__*/React.createElement("div", {
|
|
470
|
+
style: {
|
|
471
|
+
display: 'flex',
|
|
472
|
+
boxSizing: 'border-box'
|
|
473
|
+
}
|
|
474
|
+
}, topContainers.map(function (containerId) {
|
|
475
|
+
return /*#__PURE__*/React.createElement(DroppableContainer, {
|
|
476
|
+
key: containerId,
|
|
477
|
+
id: containerId,
|
|
478
|
+
label: containerId === 'row' ? rowGroupTitle : colGroupTitle,
|
|
479
|
+
columns: columns,
|
|
480
|
+
items: items[containerId],
|
|
481
|
+
scrollable: true,
|
|
482
|
+
style: containerStyle,
|
|
483
|
+
unstyled: false
|
|
484
|
+
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
485
|
+
items: items[containerId],
|
|
486
|
+
strategy: horizontalListSortingStrategy
|
|
487
|
+
}, items[containerId].map(function (value, index) {
|
|
488
|
+
return /*#__PURE__*/React.createElement(SortableItem, {
|
|
489
|
+
disabled: isSortingContainer,
|
|
490
|
+
key: value,
|
|
491
|
+
id: value,
|
|
492
|
+
index: index,
|
|
493
|
+
handle: true,
|
|
494
|
+
style: getItemStyles,
|
|
495
|
+
wrapperStyle: wrapperStyle,
|
|
496
|
+
renderItem: renderItem,
|
|
497
|
+
containerId: containerId,
|
|
498
|
+
getIndex: getIndex,
|
|
499
|
+
onRemove: function onRemove() {
|
|
500
|
+
updateItems(items, value);
|
|
501
|
+
}
|
|
502
|
+
});
|
|
503
|
+
})));
|
|
504
|
+
})), /*#__PURE__*/React.createElement("div", {
|
|
505
|
+
className: classNames('dnd_table_container'),
|
|
506
|
+
style: {
|
|
507
|
+
display: 'flex',
|
|
508
|
+
boxSizing: 'border-box',
|
|
509
|
+
justifyContent: 'column'
|
|
510
|
+
}
|
|
511
|
+
}, /*#__PURE__*/React.createElement(DroppableContainer, {
|
|
512
|
+
key: tableContainer,
|
|
513
|
+
id: tableContainer,
|
|
514
|
+
columns: 1,
|
|
515
|
+
items: items[tableContainer],
|
|
516
|
+
scrollable: scrollable,
|
|
517
|
+
style: containerStyle,
|
|
518
|
+
unstyled: false
|
|
519
|
+
}, /*#__PURE__*/React.createElement(SortableContext, {
|
|
520
|
+
items: items[tableContainer],
|
|
521
|
+
strategy: horizontalListSortingStrategy
|
|
522
|
+
}, /*#__PURE__*/React.createElement("li", {
|
|
523
|
+
style: {
|
|
524
|
+
width: '100%'
|
|
525
|
+
}
|
|
526
|
+
}, children)))), /*#__PURE__*/createPortal( /*#__PURE__*/React.createElement(DragOverlay, {
|
|
527
|
+
adjustScale: adjustScale,
|
|
528
|
+
dropAnimation: dropAnimation
|
|
529
|
+
}, activeId ? containers.includes(activeId) ? renderContainerDragOverlay(activeId) : renderSortableItemDragOverlay(activeId) : null), document.body), trashable && activeId && !containers.includes(activeId) ? /*#__PURE__*/React.createElement(Trash, {
|
|
530
|
+
id: TRASH_ID
|
|
531
|
+
}) : null);
|
|
532
|
+
|
|
533
|
+
function renderSortableItemDragOverlay(id) {
|
|
534
|
+
return /*#__PURE__*/React.createElement(Item, {
|
|
535
|
+
value: id,
|
|
536
|
+
handle: handle,
|
|
537
|
+
style: getItemStyles({
|
|
538
|
+
containerId: findContainer(id),
|
|
539
|
+
overIndex: -1,
|
|
540
|
+
index: getIndex(id),
|
|
541
|
+
value: id,
|
|
542
|
+
isSorting: true,
|
|
543
|
+
isDragging: true,
|
|
544
|
+
isDragOverlay: true
|
|
545
|
+
}),
|
|
546
|
+
color: getColor(id),
|
|
547
|
+
wrapperStyle: wrapperStyle({
|
|
548
|
+
index: 0
|
|
549
|
+
}),
|
|
550
|
+
renderItem: renderItem,
|
|
551
|
+
dragOverlay: true
|
|
552
|
+
});
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
function renderContainerDragOverlay(containerId) {
|
|
556
|
+
return /*#__PURE__*/React.createElement(Container, {
|
|
557
|
+
label: "Column ".concat(containerId),
|
|
558
|
+
columns: columns,
|
|
559
|
+
style: {
|
|
560
|
+
height: '100%'
|
|
561
|
+
},
|
|
562
|
+
shadow: true,
|
|
563
|
+
unstyled: false
|
|
564
|
+
}, items[containerId].map(function (item, index) {
|
|
565
|
+
return /*#__PURE__*/React.createElement(Item, {
|
|
566
|
+
key: item,
|
|
567
|
+
value: item,
|
|
568
|
+
handle: handle,
|
|
569
|
+
style: getItemStyles({
|
|
570
|
+
containerId: containerId,
|
|
571
|
+
overIndex: -1,
|
|
572
|
+
index: getIndex(item),
|
|
573
|
+
value: item,
|
|
574
|
+
isDragging: false,
|
|
575
|
+
isSorting: false,
|
|
576
|
+
isDragOverlay: false
|
|
577
|
+
}),
|
|
578
|
+
color: getColor(item),
|
|
579
|
+
wrapperStyle: wrapperStyle({
|
|
580
|
+
index: index
|
|
581
|
+
}),
|
|
582
|
+
renderItem: renderItem
|
|
583
|
+
});
|
|
584
|
+
}));
|
|
585
|
+
}
|
|
586
|
+
|
|
587
|
+
function getNextContainerId() {
|
|
588
|
+
var containerIds = Object.keys(items);
|
|
589
|
+
var lastContainerId = containerIds[containerIds.length - 1];
|
|
590
|
+
return String.fromCharCode(lastContainerId.charCodeAt(0) + 1);
|
|
591
|
+
}
|
|
592
|
+
}
|
|
593
|
+
|
|
594
|
+
function getColor(id) {
|
|
595
|
+
switch (String(id)[0]) {
|
|
596
|
+
case 'A':
|
|
597
|
+
return '#7193f1';
|
|
598
|
+
|
|
599
|
+
case 'B':
|
|
600
|
+
return '#ffda6c';
|
|
601
|
+
|
|
602
|
+
case 'C':
|
|
603
|
+
return '#00bcd4';
|
|
604
|
+
|
|
605
|
+
case 'D':
|
|
606
|
+
return '#ef769f';
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
return undefined;
|
|
610
|
+
}
|
|
611
|
+
|
|
612
|
+
function Trash(_ref6) {
|
|
613
|
+
var id = _ref6.id;
|
|
614
|
+
|
|
615
|
+
var _useDroppable = useDroppable({
|
|
616
|
+
id: id
|
|
617
|
+
}),
|
|
618
|
+
setNodeRef = _useDroppable.setNodeRef,
|
|
619
|
+
isOver = _useDroppable.isOver;
|
|
620
|
+
|
|
621
|
+
return /*#__PURE__*/React.createElement("div", {
|
|
622
|
+
ref: setNodeRef,
|
|
623
|
+
style: {
|
|
624
|
+
display: 'flex',
|
|
625
|
+
alignItems: 'center',
|
|
626
|
+
justifyContent: 'center',
|
|
627
|
+
position: 'fixed',
|
|
628
|
+
left: '50%',
|
|
629
|
+
marginLeft: -150,
|
|
630
|
+
bottom: 20,
|
|
631
|
+
width: 300,
|
|
632
|
+
height: 60,
|
|
633
|
+
borderRadius: 5,
|
|
634
|
+
border: '1px solid',
|
|
635
|
+
borderColor: isOver ? 'red' : '#DDD'
|
|
636
|
+
}
|
|
637
|
+
}, "Drop here to delete");
|
|
638
|
+
}
|
|
639
|
+
|
|
640
|
+
function SortableItem(_ref7) {
|
|
641
|
+
var disabled = _ref7.disabled,
|
|
642
|
+
id = _ref7.id,
|
|
643
|
+
index = _ref7.index,
|
|
644
|
+
handle = _ref7.handle,
|
|
645
|
+
renderItem = _ref7.renderItem,
|
|
646
|
+
style = _ref7.style,
|
|
647
|
+
containerId = _ref7.containerId,
|
|
648
|
+
getIndex = _ref7.getIndex,
|
|
649
|
+
wrapperStyle = _ref7.wrapperStyle,
|
|
650
|
+
onRemove = _ref7.onRemove;
|
|
651
|
+
|
|
652
|
+
var _useSortable2 = useSortable({
|
|
653
|
+
id: id
|
|
654
|
+
}),
|
|
655
|
+
setNodeRef = _useSortable2.setNodeRef,
|
|
656
|
+
listeners = _useSortable2.listeners,
|
|
657
|
+
isDragging = _useSortable2.isDragging,
|
|
658
|
+
isSorting = _useSortable2.isSorting,
|
|
659
|
+
over = _useSortable2.over,
|
|
660
|
+
overIndex = _useSortable2.overIndex,
|
|
661
|
+
transform = _useSortable2.transform,
|
|
662
|
+
transition = _useSortable2.transition;
|
|
663
|
+
|
|
664
|
+
var mounted = useMountStatus();
|
|
665
|
+
var mountedWhileDragging = isDragging && !mounted;
|
|
666
|
+
return /*#__PURE__*/React.createElement(Item, {
|
|
667
|
+
ref: disabled ? undefined : setNodeRef,
|
|
668
|
+
value: id,
|
|
669
|
+
dragging: isDragging,
|
|
670
|
+
sorting: isSorting,
|
|
671
|
+
handle: handle,
|
|
672
|
+
handleProps: undefined,
|
|
673
|
+
index: index,
|
|
674
|
+
wrapperStyle: wrapperStyle({
|
|
675
|
+
index: index
|
|
676
|
+
}),
|
|
677
|
+
style: style({
|
|
678
|
+
index: index,
|
|
679
|
+
value: id,
|
|
680
|
+
isDragging: isDragging,
|
|
681
|
+
isSorting: isSorting,
|
|
682
|
+
overIndex: over ? getIndex(over.id) : overIndex,
|
|
683
|
+
containerId: containerId
|
|
684
|
+
}),
|
|
685
|
+
color: getColor(id),
|
|
686
|
+
transition: transition,
|
|
687
|
+
transform: transform,
|
|
688
|
+
fadeIn: mountedWhileDragging,
|
|
689
|
+
listeners: listeners,
|
|
690
|
+
renderItem: renderItem,
|
|
691
|
+
onRemove: onRemove
|
|
692
|
+
});
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
function useMountStatus() {
|
|
696
|
+
var _useState9 = useState(false),
|
|
697
|
+
_useState10 = _slicedToArray(_useState9, 2),
|
|
698
|
+
isMounted = _useState10[0],
|
|
699
|
+
setIsMounted = _useState10[1];
|
|
34
700
|
|
|
35
|
-
|
|
701
|
+
useEffect(function () {
|
|
702
|
+
var timeout = setTimeout(function () {
|
|
703
|
+
return setIsMounted(true);
|
|
704
|
+
}, 500);
|
|
705
|
+
return function () {
|
|
706
|
+
return clearTimeout(timeout);
|
|
707
|
+
};
|
|
708
|
+
}, []);
|
|
709
|
+
return isMounted;
|
|
710
|
+
}
|