@pisell/materials 6.12.104 → 6.12.106
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/build/lowcode/assets-daily.json +11 -11
- package/build/lowcode/assets-dev.json +2 -2
- package/build/lowcode/assets-prod.json +11 -11
- package/build/lowcode/meta.js +1 -1
- package/build/lowcode/render/default/view.css +1 -1
- package/build/lowcode/render/default/view.js +2 -2
- package/build/lowcode/view.css +1 -1
- package/build/lowcode/view.js +2 -2
- package/es/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +44 -5
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +2 -1
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.js +5 -2
- package/es/components/pisellDraggable/components/TreeItem/TreeItem.less +4 -2
- package/es/components/pisellDraggable/index.d.ts +3 -1
- package/es/components/pisellDraggable/index.js +287 -207
- package/es/components/pisellDraggable/types.d.ts +3 -1
- package/es/components/pisellDraggable/utilities.js +90 -79
- package/es/components/pisellDropSort/PisellDropSort.js +11 -4
- package/es/components/pisellDropSort/components/SortableItem/index.js +8 -5
- package/es/components/pisellDropSort/components/SortableItem/index.less +22 -0
- package/es/components/pisellDropSort/types.d.ts +1 -0
- package/es/components/pisellNavigationMenu/PisellNavigationMenu.js +44 -21
- package/es/components/pisellNavigationMenu/PisellNavigationMenu.less +7 -0
- package/es/components/pisellNavigationMenu/index.d.ts +1 -1
- package/es/components/pisellNavigationMenu/types.d.ts +15 -2
- package/lib/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +43 -3
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +2 -1
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.js +5 -2
- package/lib/components/pisellDraggable/components/TreeItem/TreeItem.less +4 -2
- package/lib/components/pisellDraggable/index.d.ts +3 -1
- package/lib/components/pisellDraggable/index.js +281 -201
- package/lib/components/pisellDraggable/types.d.ts +3 -1
- package/lib/components/pisellDraggable/utilities.js +90 -79
- package/lib/components/pisellDropSort/PisellDropSort.js +10 -3
- package/lib/components/pisellDropSort/components/SortableItem/index.js +8 -5
- package/lib/components/pisellDropSort/components/SortableItem/index.less +22 -0
- package/lib/components/pisellDropSort/types.d.ts +1 -0
- package/lib/components/pisellNavigationMenu/PisellNavigationMenu.js +44 -21
- package/lib/components/pisellNavigationMenu/PisellNavigationMenu.less +7 -0
- package/lib/components/pisellNavigationMenu/index.d.ts +1 -1
- package/lib/components/pisellNavigationMenu/types.d.ts +15 -2
- package/package.json +1 -1
|
@@ -28,14 +28,17 @@ const _excluded = [
|
|
|
28
28
|
"item",
|
|
29
29
|
"renderItem",
|
|
30
30
|
"isBlocked",
|
|
31
|
+
"isError",
|
|
32
|
+
"dropPosition",
|
|
31
33
|
"__designMode"
|
|
32
34
|
];
|
|
33
35
|
const TreeItem = (0, react.forwardRef)((props, ref) => {
|
|
34
|
-
const { childCount, clone, depth, disableSelection, disableInteraction, ghost, handleProps, indentationWidth, indicator, collapsed, onCollapse, onRemove, style, wrapperRef, item, renderItem, isBlocked, __designMode } = props, otherProps = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
|
|
35
|
-
if (renderItem) return renderItem(props, ref);
|
|
36
|
+
const { childCount, clone, depth, disableSelection, disableInteraction, ghost, handleProps, indentationWidth, indicator, collapsed, onCollapse, onRemove, style, wrapperRef, item, renderItem, isBlocked, isError, dropPosition, __designMode } = props, otherProps = require_objectWithoutProperties._objectWithoutProperties(props, _excluded);
|
|
37
|
+
if (renderItem) return /* @__PURE__ */ react.default.createElement(react.default.Fragment, null, renderItem(props, ref));
|
|
36
38
|
return /* @__PURE__ */ react.default.createElement("li", require_objectSpread2._objectSpread2({
|
|
37
39
|
className: (0, classnames.default)("Wrapper", clone && "clone", ghost && "ghost", indicator && "indicator", disableSelection && "disableSelection", disableInteraction && "disableInteraction"),
|
|
38
40
|
ref: wrapperRef,
|
|
41
|
+
"data-drop-position": dropPosition,
|
|
39
42
|
style: { "--spacing": `${indentationWidth * depth}px` }
|
|
40
43
|
}, otherProps), /* @__PURE__ */ react.default.createElement("div", {
|
|
41
44
|
className: "TreeItem",
|
|
@@ -103,7 +103,9 @@
|
|
|
103
103
|
color: #fff;
|
|
104
104
|
}
|
|
105
105
|
|
|
106
|
-
.disableInteraction
|
|
106
|
+
.disableInteraction,
|
|
107
|
+
[data-pisell-drop-sort-dragging] > .Wrapper,
|
|
108
|
+
[data-pisell-drop-sort-dragging] > .pisell-lowcode-drop-sort-item {
|
|
107
109
|
pointer-events: none;
|
|
108
110
|
}
|
|
109
111
|
|
|
@@ -125,4 +127,4 @@
|
|
|
125
127
|
&.collapsed svg {
|
|
126
128
|
transform: rotate(-90deg);
|
|
127
129
|
}
|
|
128
|
-
}
|
|
130
|
+
}
|
|
@@ -16,7 +16,7 @@ interface Props {
|
|
|
16
16
|
/** 是否支持删除节点功能 */
|
|
17
17
|
removable?: boolean;
|
|
18
18
|
/** 自定义渲染树节点 */
|
|
19
|
-
renderItem?:
|
|
19
|
+
renderItem?: Props$1['renderItem'];
|
|
20
20
|
/** 树形数据变化回调 */
|
|
21
21
|
onChange?: (items: TreeItems) => void;
|
|
22
22
|
/** 删除节点前 */
|
|
@@ -27,6 +27,8 @@ interface Props {
|
|
|
27
27
|
maxLevel?: number;
|
|
28
28
|
/** 自定义拖拽判断函数,返回false时阻止拖拽 */
|
|
29
29
|
canDrop?: (dragItem: FlattenedItem, dropTarget: FlattenedItem, parentId: UniqueIdentifier | null, parentNode: any) => boolean;
|
|
30
|
+
dropOnPageAsSibling?: boolean;
|
|
31
|
+
dropBoundary?: React.RefObject<HTMLElement>;
|
|
30
32
|
}
|
|
31
33
|
declare const Demo: (props: Props) => React.JSX.Element;
|
|
32
34
|
//#endregion
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const require_runtime = require("../../_virtual/_rolldown/runtime.js");
|
|
2
2
|
const require_objectSpread2 = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/objectSpread2.js");
|
|
3
3
|
const require_asyncToGenerator = require("../../_virtual/_@oxc-project_runtime@0.122.0/helpers/asyncToGenerator.js");
|
|
4
|
+
const require_TreeItem = require("./components/TreeItem/TreeItem.js");
|
|
4
5
|
const require_utilities = require("./utilities.js");
|
|
5
6
|
const require_SortableTreeItem = require("./components/TreeItem/SortableTreeItem.js");
|
|
6
7
|
let react = require("react");
|
|
@@ -91,239 +92,318 @@ const dropAnimationConfig = {
|
|
|
91
92
|
});
|
|
92
93
|
}
|
|
93
94
|
};
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
95
|
+
const overlayStyle = { pointerEvents: "none" };
|
|
96
|
+
const dropPositionAttribute = "data-drop-position";
|
|
97
|
+
const dropLineOffset = "--pisell-drop-sort-line-offset";
|
|
98
|
+
const draggingAttribute = "data-pisell-drop-sort-dragging";
|
|
99
|
+
function clearDropMarker(row) {
|
|
100
|
+
row === null || row === void 0 || row.removeAttribute(dropPositionAttribute);
|
|
101
|
+
row === null || row === void 0 || row.style.removeProperty(dropLineOffset);
|
|
102
|
+
}
|
|
103
|
+
function NavigationDropSurface({ id, boundary, rows, firstRowId }) {
|
|
104
|
+
const { setNodeRef } = (0, _dnd_kit_core.useDroppable)({ id });
|
|
103
105
|
(0, react.useEffect)(() => {
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
const
|
|
126
|
-
|
|
127
|
-
* 传感器上下文
|
|
128
|
-
* 存储扁平化的节点数据和偏移量信息
|
|
129
|
-
*/
|
|
130
|
-
const sensorContext = (0, react.useRef)({
|
|
131
|
-
items: flattenedItems,
|
|
132
|
-
offset: offsetLeft
|
|
133
|
-
});
|
|
106
|
+
var _ref, _boundary$current;
|
|
107
|
+
const firstRow = firstRowId === void 0 ? null : rows.get(firstRowId);
|
|
108
|
+
setNodeRef((_ref = (_boundary$current = boundary === null || boundary === void 0 ? void 0 : boundary.current) !== null && _boundary$current !== void 0 ? _boundary$current : firstRow) !== null && _ref !== void 0 ? _ref : null);
|
|
109
|
+
return () => setNodeRef(null);
|
|
110
|
+
}, [
|
|
111
|
+
boundary,
|
|
112
|
+
firstRowId,
|
|
113
|
+
rows,
|
|
114
|
+
setNodeRef
|
|
115
|
+
]);
|
|
116
|
+
return null;
|
|
117
|
+
}
|
|
118
|
+
function SortableTree({ collapsible = true, value = initialItems, indicator = false, indentationWidth = 50, removable = true, renderItem, onChange, onRemoveBefore, __designMode, maxLevel = 3, canDrop, dropOnPageAsSibling = false, dropBoundary }) {
|
|
119
|
+
var _activeItem$children, _items$;
|
|
120
|
+
const [items, setItems] = (0, react.useState)(value);
|
|
121
|
+
const [activeId, setActiveId] = (0, react.useState)(null);
|
|
122
|
+
const [preview, setPreview] = (0, react.useState)(null);
|
|
123
|
+
const previewRef = (0, react.useRef)(null);
|
|
124
|
+
const dragItems = (0, react.useRef)(null);
|
|
125
|
+
const navigationRows = (0, react.useRef)(/* @__PURE__ */ new Map());
|
|
126
|
+
const markedRow = (0, react.useRef)();
|
|
127
|
+
const draggingList = (0, react.useRef)();
|
|
128
|
+
const releasedPointer = (0, react.useRef)(null);
|
|
134
129
|
const sensors = (0, _dnd_kit_core.useSensors)((0, _dnd_kit_core.useSensor)(_dnd_kit_core.PointerSensor));
|
|
135
|
-
const
|
|
136
|
-
const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}, [flattenedItems, offsetLeft]);
|
|
130
|
+
const surfaceId = `navigation-drop-${(0, react.useId)()}`;
|
|
131
|
+
const setNavigationRow = (0, react.useCallback)((id, node) => {
|
|
132
|
+
if (node) navigationRows.current.set(id, node);
|
|
133
|
+
else navigationRows.current.delete(id);
|
|
134
|
+
}, []);
|
|
135
|
+
const onPointerRelease = (0, react.useCallback)((event) => {
|
|
136
|
+
if (event.isPrimary) releasedPointer.current = event;
|
|
137
|
+
}, []);
|
|
138
|
+
(0, react.useEffect)(() => setItems(value), [value]);
|
|
145
139
|
(0, react.useEffect)(() => {
|
|
146
140
|
document.body.id = "body";
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
141
|
+
return () => {
|
|
142
|
+
var _draggingList$current;
|
|
143
|
+
clearDropMarker(markedRow.current);
|
|
144
|
+
(_draggingList$current = draggingList.current) === null || _draggingList$current === void 0 || _draggingList$current.removeAttribute(draggingAttribute);
|
|
145
|
+
document.removeEventListener("pointerup", onPointerRelease, true);
|
|
146
|
+
if (dragItems.current) document.body.style.removeProperty("cursor");
|
|
147
|
+
};
|
|
148
|
+
}, [onPointerRelease]);
|
|
149
|
+
const { rows, indices, subtreeHeights } = (0, react.useMemo)(() => {
|
|
150
|
+
const rows = require_utilities.flattenTree(items);
|
|
151
|
+
const subtreeHeights = /* @__PURE__ */ new Map();
|
|
152
|
+
for (let index = rows.length - 1; index >= 0; index--) {
|
|
153
|
+
var _subtreeHeights$get, _subtreeHeights$get2;
|
|
154
|
+
const { id, parentId } = rows[index];
|
|
155
|
+
if (parentId === null) continue;
|
|
156
|
+
const height = ((_subtreeHeights$get = subtreeHeights.get(id)) !== null && _subtreeHeights$get !== void 0 ? _subtreeHeights$get : 0) + 1;
|
|
157
|
+
if (height > ((_subtreeHeights$get2 = subtreeHeights.get(parentId)) !== null && _subtreeHeights$get2 !== void 0 ? _subtreeHeights$get2 : 0)) subtreeHeights.set(parentId, height);
|
|
158
|
+
}
|
|
159
|
+
return {
|
|
160
|
+
rows,
|
|
161
|
+
indices: new Map(rows.map(({ id }, index) => [id, index])),
|
|
162
|
+
subtreeHeights
|
|
163
|
+
};
|
|
164
|
+
}, [items]);
|
|
165
|
+
const activeIndex = activeId === null ? void 0 : indices.get(activeId);
|
|
166
|
+
const activeItem = activeIndex === void 0 ? void 0 : rows[activeIndex];
|
|
167
|
+
const hiddenParent = (activeItem === null || activeItem === void 0 || (_activeItem$children = activeItem.children) === null || _activeItem$children === void 0 ? void 0 : _activeItem$children.length) && !activeItem.collapsed ? activeId : null;
|
|
168
|
+
const { visibleRows, visibleIndices, sortedIds, lastDescendants } = (0, react.useMemo)(() => {
|
|
169
|
+
const exclude = rows.filter((row) => {
|
|
170
|
+
var _row$children;
|
|
171
|
+
return row.collapsed && ((_row$children = row.children) === null || _row$children === void 0 ? void 0 : _row$children.length);
|
|
172
|
+
}).map(({ id }) => id);
|
|
173
|
+
if (hiddenParent !== null) exclude.push(hiddenParent);
|
|
174
|
+
const visibleRows = require_utilities.removeChildrenOf(rows, exclude);
|
|
175
|
+
const sortedIds = visibleRows.map(({ id }) => id);
|
|
176
|
+
const lastDescendants = /* @__PURE__ */ new Map();
|
|
177
|
+
if (dropOnPageAsSibling) for (let index = visibleRows.length - 1; index >= 0; index--) {
|
|
178
|
+
const row = visibleRows[index];
|
|
179
|
+
if (row.parentId !== null && !lastDescendants.has(row.parentId)) {
|
|
180
|
+
var _lastDescendants$get;
|
|
181
|
+
lastDescendants.set(row.parentId, (_lastDescendants$get = lastDescendants.get(row.id)) !== null && _lastDescendants$get !== void 0 ? _lastDescendants$get : row);
|
|
173
182
|
}
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
183
|
+
}
|
|
184
|
+
return {
|
|
185
|
+
visibleRows,
|
|
186
|
+
sortedIds,
|
|
187
|
+
visibleIndices: new Map(sortedIds.map((id, index) => [id, index])),
|
|
188
|
+
lastDescendants
|
|
189
|
+
};
|
|
190
|
+
}, [
|
|
191
|
+
dropOnPageAsSibling,
|
|
192
|
+
hiddenParent,
|
|
193
|
+
rows
|
|
194
|
+
]);
|
|
195
|
+
const hitTest = (0, react.useMemo)(() => require_utilities.createNavigationHitTest(sortedIds, navigationRows.current), [sortedIds]);
|
|
196
|
+
const navigationCollision = (0, react.useCallback)(({ pointerCoordinates, droppableContainers }) => {
|
|
197
|
+
const surface = droppableContainers[0];
|
|
198
|
+
if (!pointerCoordinates || (surface === null || surface === void 0 ? void 0 : surface.id) !== surfaceId) return [];
|
|
199
|
+
const target = hitTest(pointerCoordinates);
|
|
200
|
+
if (!target) return [];
|
|
201
|
+
return [{
|
|
202
|
+
id: surfaceId,
|
|
203
|
+
data: {
|
|
204
|
+
target,
|
|
205
|
+
pointerCoordinates,
|
|
206
|
+
droppableContainer: surface,
|
|
207
|
+
value: 0
|
|
208
|
+
}
|
|
209
|
+
}];
|
|
210
|
+
}, [hitTest, surfaceId]);
|
|
211
|
+
const activeChildCount = (0, react.useMemo)(() => activeId === null ? 0 : require_utilities.getChildCount(items, activeId) + 1, [activeId, items]);
|
|
212
|
+
const sectionDepth = ((_items$ = items[0]) === null || _items$ === void 0 ? void 0 : _items$.isSection) ? 1 : 0;
|
|
213
|
+
const resolveDrop = (0, ahooks.useMemoizedFn)((event, targetHit, pointer) => {
|
|
214
|
+
var _event$over, _subtreeHeights$get3, _canDrop;
|
|
215
|
+
if (dragItems.current !== items || activeId !== event.active.id) return null;
|
|
216
|
+
const targetId = dropOnPageAsSibling ? targetHit === null || targetHit === void 0 ? void 0 : targetHit.rowId : (_event$over = event.over) === null || _event$over === void 0 ? void 0 : _event$over.id;
|
|
217
|
+
if (targetId == null || dropOnPageAsSibling && targetId === activeId) return null;
|
|
218
|
+
const from = visibleIndices.get(event.active.id);
|
|
219
|
+
const to = visibleIndices.get(targetId);
|
|
220
|
+
if (from === void 0 || to === void 0) return null;
|
|
221
|
+
const item = visibleRows[from];
|
|
222
|
+
const target = visibleRows[to];
|
|
223
|
+
if (item.isSection) return null;
|
|
224
|
+
let depth;
|
|
225
|
+
let parentId;
|
|
226
|
+
let position;
|
|
227
|
+
const origin = pointer ? (0, _dnd_kit_utilities.getEventCoordinates)(event.activatorEvent) : null;
|
|
228
|
+
const offset = (pointer && origin ? pointer.x - origin.x : event.delta.x) / indentationWidth;
|
|
229
|
+
if (dropOnPageAsSibling) {
|
|
230
|
+
var _targetHit$position;
|
|
231
|
+
position = (_targetHit$position = targetHit === null || targetHit === void 0 ? void 0 : targetHit.position) !== null && _targetHit$position !== void 0 ? _targetHit$position : "before";
|
|
232
|
+
if (target.isSection || !target.disabledDrop && position === "after" && item.depth + Math.trunc(offset) > target.depth && !item.isGroup) {
|
|
233
|
+
position = "inside";
|
|
234
|
+
parentId = target.id;
|
|
235
|
+
depth = target.depth + 1;
|
|
236
|
+
} else {
|
|
237
|
+
parentId = target.parentId;
|
|
238
|
+
depth = target.depth;
|
|
239
|
+
}
|
|
240
|
+
} else {
|
|
241
|
+
({depth, parentId} = require_utilities.getProjection(visibleRows, visibleIndices, from, to, Math.round(offset)));
|
|
242
|
+
position = from < to ? "after" : "before";
|
|
243
|
+
}
|
|
244
|
+
const parentIndex = parentId === null ? void 0 : indices.get(parentId);
|
|
245
|
+
const parent = parentIndex === void 0 ? void 0 : rows[parentIndex];
|
|
246
|
+
const allowed = !(parent === null || parent === void 0 ? void 0 : parent.disabledDrop) && depth + ((_subtreeHeights$get3 = subtreeHeights.get(item.id)) !== null && _subtreeHeights$get3 !== void 0 ? _subtreeHeights$get3 : 0) < maxLevel && ((_canDrop = canDrop === null || canDrop === void 0 ? void 0 : canDrop(item, target, parentId, parent !== null && parent !== void 0 ? parent : null)) !== null && _canDrop !== void 0 ? _canDrop : true);
|
|
247
|
+
return {
|
|
248
|
+
targetId,
|
|
249
|
+
depth,
|
|
250
|
+
parentId,
|
|
251
|
+
position,
|
|
252
|
+
allowed
|
|
179
253
|
};
|
|
180
|
-
}());
|
|
181
|
-
/**
|
|
182
|
-
* 处理拖拽开始事件
|
|
183
|
-
* 设置当前拖拽项和初始状态
|
|
184
|
-
*/
|
|
185
|
-
const handleDragStart = (0, ahooks.useMemoizedFn)(({ active: { id: activeId } }) => {
|
|
186
|
-
setActiveId(activeId);
|
|
187
|
-
setOverId(activeId);
|
|
188
|
-
document.body.style.setProperty("cursor", "grabbing");
|
|
189
|
-
});
|
|
190
|
-
/**
|
|
191
|
-
* 处理拖拽移动事件
|
|
192
|
-
* 更新水平偏移量
|
|
193
|
-
*/
|
|
194
|
-
const handleDragMove = (0, ahooks.useMemoizedFn)(({ delta }) => {
|
|
195
|
-
setOffsetLeft(delta.x);
|
|
196
254
|
});
|
|
197
|
-
const
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
255
|
+
const handleDragStart = (0, ahooks.useMemoizedFn)(({ active }) => {
|
|
256
|
+
dragItems.current = items;
|
|
257
|
+
if (dropOnPageAsSibling) {
|
|
258
|
+
var _navigationRows$curre, _navigationRows$curre2, _draggingList$current2;
|
|
259
|
+
draggingList.current = (_navigationRows$curre = (_navigationRows$curre2 = navigationRows.current.get(active.id)) === null || _navigationRows$curre2 === void 0 ? void 0 : _navigationRows$curre2.parentElement) !== null && _navigationRows$curre !== void 0 ? _navigationRows$curre : void 0;
|
|
260
|
+
(_draggingList$current2 = draggingList.current) === null || _draggingList$current2 === void 0 || _draggingList$current2.setAttribute(draggingAttribute, "");
|
|
261
|
+
document.addEventListener("pointerup", onPointerRelease, true);
|
|
202
262
|
}
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
if (projected.depth >= maxLevel) return;
|
|
206
|
-
if (checkSubtreeDepth(flattenTreeData, activeId, projected.depth)) return;
|
|
207
|
-
setOverId(over.id);
|
|
263
|
+
setActiveId(active.id);
|
|
264
|
+
document.body.style.setProperty("cursor", "grabbing");
|
|
208
265
|
});
|
|
209
|
-
const
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
const dropTarget = flattenedItems.find((item) => item.id === over.id);
|
|
226
|
-
if (canDrop && dragItem && dropTarget) {
|
|
227
|
-
if (!canDrop(dragItem, dropTarget, parentId, targetParent)) return;
|
|
266
|
+
const updatePreview = (0, ahooks.useMemoizedFn)((event) => {
|
|
267
|
+
var _event$collisions;
|
|
268
|
+
const data = (_event$collisions = event.collisions) === null || _event$collisions === void 0 || (_event$collisions = _event$collisions[0]) === null || _event$collisions === void 0 ? void 0 : _event$collisions.data;
|
|
269
|
+
const next = resolveDrop(event, data === null || data === void 0 ? void 0 : data.target, data === null || data === void 0 ? void 0 : data.pointerCoordinates);
|
|
270
|
+
const previous = previewRef.current;
|
|
271
|
+
if ((previous === null || previous === void 0 ? void 0 : previous.targetId) === (next === null || next === void 0 ? void 0 : next.targetId) && (previous === null || previous === void 0 ? void 0 : previous.position) === (next === null || next === void 0 ? void 0 : next.position) && (previous === null || previous === void 0 ? void 0 : previous.parentId) === (next === null || next === void 0 ? void 0 : next.parentId) && (previous === null || previous === void 0 ? void 0 : previous.depth) === (next === null || next === void 0 ? void 0 : next.depth) && (previous === null || previous === void 0 ? void 0 : previous.allowed) === (next === null || next === void 0 ? void 0 : next.allowed)) return;
|
|
272
|
+
previewRef.current = next;
|
|
273
|
+
if (dropOnPageAsSibling) {
|
|
274
|
+
var _descendant$id;
|
|
275
|
+
const descendant = (next === null || next === void 0 ? void 0 : next.allowed) && next.position === "after" ? lastDescendants.get(next.targetId) : void 0;
|
|
276
|
+
const row = (next === null || next === void 0 ? void 0 : next.allowed) ? navigationRows.current.get((_descendant$id = descendant === null || descendant === void 0 ? void 0 : descendant.id) !== null && _descendant$id !== void 0 ? _descendant$id : next.targetId) : void 0;
|
|
277
|
+
if (markedRow.current !== row) clearDropMarker(markedRow.current);
|
|
278
|
+
if (row && next) {
|
|
279
|
+
row.setAttribute(dropPositionAttribute, next.position);
|
|
280
|
+
if (descendant) row.style.setProperty(dropLineOffset, `${(next.depth - descendant.depth) * indentationWidth}px`);
|
|
281
|
+
else row.style.removeProperty(dropLineOffset);
|
|
228
282
|
}
|
|
229
|
-
|
|
230
|
-
if (checkSubtreeDepth(flattenTreeData, active.id, depth)) return;
|
|
231
|
-
const clonedItems = JSON.parse(JSON.stringify(require_utilities.flattenTree(items)));
|
|
232
|
-
const overIndex = clonedItems.findIndex(({ id }) => id === over.id);
|
|
233
|
-
const activeIndex = clonedItems.findIndex(({ id }) => id === active.id);
|
|
234
|
-
const activeTreeItem = clonedItems[activeIndex];
|
|
235
|
-
clonedItems[activeIndex] = require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, activeTreeItem), {}, {
|
|
236
|
-
depth,
|
|
237
|
-
parentId
|
|
238
|
-
});
|
|
239
|
-
const newItems = require_utilities.buildTree((0, _dnd_kit_sortable.arrayMove)(clonedItems, activeIndex, overIndex));
|
|
240
|
-
setItems(newItems);
|
|
241
|
-
onChange === null || onChange === void 0 || onChange(newItems);
|
|
283
|
+
markedRow.current = row;
|
|
242
284
|
}
|
|
285
|
+
if (!dropOnPageAsSibling || (previous === null || previous === void 0 ? void 0 : previous.allowed) === false !== ((next === null || next === void 0 ? void 0 : next.allowed) === false)) setPreview(next);
|
|
243
286
|
});
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
287
|
+
function resetDrag() {
|
|
288
|
+
var _draggingList$current3;
|
|
289
|
+
dragItems.current = null;
|
|
290
|
+
releasedPointer.current = null;
|
|
291
|
+
document.removeEventListener("pointerup", onPointerRelease, true);
|
|
292
|
+
previewRef.current = null;
|
|
293
|
+
clearDropMarker(markedRow.current);
|
|
294
|
+
markedRow.current = void 0;
|
|
295
|
+
(_draggingList$current3 = draggingList.current) === null || _draggingList$current3 === void 0 || _draggingList$current3.removeAttribute(draggingAttribute);
|
|
296
|
+
draggingList.current = void 0;
|
|
297
|
+
setPreview(null);
|
|
298
|
+
setActiveId(null);
|
|
299
|
+
document.body.style.removeProperty("cursor");
|
|
300
|
+
}
|
|
301
|
+
const handleDragEnd = (0, ahooks.useMemoizedFn)((event) => {
|
|
302
|
+
var _event$collisions2;
|
|
303
|
+
const release = releasedPointer.current;
|
|
304
|
+
const activator = event.activatorEvent;
|
|
305
|
+
const pointer = release && release.pointerId === activator.pointerId ? {
|
|
306
|
+
x: release.clientX,
|
|
307
|
+
y: release.clientY
|
|
308
|
+
} : (_event$collisions2 = event.collisions) === null || _event$collisions2 === void 0 || (_event$collisions2 = _event$collisions2[0]) === null || _event$collisions2 === void 0 || (_event$collisions2 = _event$collisions2.data) === null || _event$collisions2 === void 0 ? void 0 : _event$collisions2.pointerCoordinates;
|
|
309
|
+
const proposal = resolveDrop(event, dropOnPageAsSibling && pointer ? hitTest(pointer) : void 0, pointer);
|
|
310
|
+
resetDrag();
|
|
311
|
+
if (!(proposal === null || proposal === void 0 ? void 0 : proposal.allowed)) return;
|
|
312
|
+
if (dropOnPageAsSibling && pointer && (dropBoundary === null || dropBoundary === void 0 ? void 0 : dropBoundary.current) && !dropBoundary.current.contains(document.elementFromPoint(pointer.x, pointer.y))) return;
|
|
313
|
+
const from = indices.get(event.active.id);
|
|
314
|
+
const targetIndex = indices.get(proposal.targetId);
|
|
315
|
+
if (from === void 0 || targetIndex === void 0) return;
|
|
316
|
+
const item = rows[from];
|
|
317
|
+
const to = targetIndex + Number(proposal.position !== "before") - Number(from < targetIndex);
|
|
318
|
+
if (from === to && item.parentId === proposal.parentId) return;
|
|
319
|
+
const nextRows = rows.slice();
|
|
320
|
+
nextRows.splice(from, 1);
|
|
321
|
+
nextRows.splice(to, 0, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, item), {}, {
|
|
322
|
+
depth: proposal.depth,
|
|
323
|
+
parentId: proposal.parentId
|
|
324
|
+
}));
|
|
325
|
+
const next = require_utilities.buildTree(nextRows);
|
|
326
|
+
setItems(next);
|
|
327
|
+
onChange === null || onChange === void 0 || onChange(next);
|
|
328
|
+
});
|
|
329
|
+
const handleRemove = (0, ahooks.useMemoizedFn)(function() {
|
|
330
|
+
var _ref2 = require_asyncToGenerator._asyncToGenerator(function* (item) {
|
|
331
|
+
if (onRemoveBefore && !(yield onRemoveBefore(item))) return;
|
|
332
|
+
setItems((items) => require_utilities.removeItem(items, item.id));
|
|
253
333
|
onChange === null || onChange === void 0 || onChange(items);
|
|
254
|
-
return newVal;
|
|
255
334
|
});
|
|
335
|
+
return function(_x) {
|
|
336
|
+
return _ref2.apply(this, arguments);
|
|
337
|
+
};
|
|
338
|
+
}());
|
|
339
|
+
const handleCollapse = (0, ahooks.useMemoizedFn)((id) => {
|
|
340
|
+
const next = require_utilities.setProperty(items, id, "collapsed", (value) => !value);
|
|
341
|
+
setItems(next);
|
|
342
|
+
onChange === null || onChange === void 0 || onChange(next);
|
|
256
343
|
});
|
|
257
|
-
const
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
__designMode
|
|
280
|
-
});
|
|
281
|
-
});
|
|
282
|
-
}, [
|
|
283
|
-
flattenedItems,
|
|
284
|
-
activeId,
|
|
285
|
-
projected === null || projected === void 0 ? void 0 : projected.depth,
|
|
344
|
+
const projectedDepth = !dropOnPageAsSibling && (preview === null || preview === void 0 ? void 0 : preview.allowed) ? preview.depth : void 0;
|
|
345
|
+
const projectedId = projectedDepth === void 0 ? null : activeId;
|
|
346
|
+
const tree = (0, react.useMemo)(() => visibleRows.map((item) => {
|
|
347
|
+
var _item$children, _item$children2;
|
|
348
|
+
const rowProps = {
|
|
349
|
+
id: item.id,
|
|
350
|
+
item,
|
|
351
|
+
depth: Math.max(0, (item.id === projectedId ? projectedDepth !== null && projectedDepth !== void 0 ? projectedDepth : item.depth : item.depth) - sectionDepth),
|
|
352
|
+
indentationWidth,
|
|
353
|
+
indicator,
|
|
354
|
+
collapsed: Boolean(item.collapsed && ((_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length)),
|
|
355
|
+
onCollapseItem: collapsible && !item.isSection && ((_item$children2 = item.children) === null || _item$children2 === void 0 ? void 0 : _item$children2.length) ? handleCollapse : void 0,
|
|
356
|
+
onRemoveItem: removable && !item.isSection ? handleRemove : void 0,
|
|
357
|
+
renderItem,
|
|
358
|
+
__designMode
|
|
359
|
+
};
|
|
360
|
+
return dropOnPageAsSibling ? /* @__PURE__ */ react.default.createElement(require_SortableTreeItem.DropTreeItem, require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({ key: item.id }, rowProps), {}, { setRowNode: setNavigationRow })) : /* @__PURE__ */ react.default.createElement(require_SortableTreeItem.default, require_objectSpread2._objectSpread2({ key: item.id }, rowProps));
|
|
361
|
+
}), [
|
|
362
|
+
visibleRows,
|
|
363
|
+
projectedId,
|
|
364
|
+
projectedDepth,
|
|
365
|
+
sectionDepth,
|
|
286
366
|
indentationWidth,
|
|
287
367
|
indicator,
|
|
288
368
|
collapsible,
|
|
369
|
+
removable,
|
|
289
370
|
handleCollapse,
|
|
290
371
|
handleRemove,
|
|
291
372
|
renderItem,
|
|
292
|
-
__designMode
|
|
373
|
+
__designMode,
|
|
374
|
+
dropOnPageAsSibling,
|
|
375
|
+
setNavigationRow
|
|
293
376
|
]);
|
|
294
377
|
return /* @__PURE__ */ react.default.createElement(_dnd_kit_core.DndContext, {
|
|
295
378
|
sensors,
|
|
296
|
-
collisionDetection: _dnd_kit_core.closestCenter,
|
|
297
|
-
measuring,
|
|
379
|
+
collisionDetection: dropOnPageAsSibling ? navigationCollision : _dnd_kit_core.closestCenter,
|
|
380
|
+
measuring: dropOnPageAsSibling ? void 0 : measuring,
|
|
298
381
|
onDragStart: handleDragStart,
|
|
299
|
-
onDragMove:
|
|
300
|
-
onDragOver:
|
|
382
|
+
onDragMove: updatePreview,
|
|
383
|
+
onDragOver: updatePreview,
|
|
301
384
|
onDragEnd: handleDragEnd,
|
|
302
|
-
onDragCancel:
|
|
303
|
-
}, /* @__PURE__ */ react.default.createElement(
|
|
385
|
+
onDragCancel: resetDrag
|
|
386
|
+
}, dropOnPageAsSibling && /* @__PURE__ */ react.default.createElement(NavigationDropSurface, {
|
|
387
|
+
id: surfaceId,
|
|
388
|
+
boundary: dropBoundary,
|
|
389
|
+
rows: navigationRows.current,
|
|
390
|
+
firstRowId: sortedIds[0]
|
|
391
|
+
}), dropOnPageAsSibling ? tree : /* @__PURE__ */ react.default.createElement(_dnd_kit_sortable.SortableContext, {
|
|
304
392
|
items: sortedIds,
|
|
305
393
|
strategy: _dnd_kit_sortable.verticalListSortingStrategy
|
|
306
|
-
},
|
|
394
|
+
}, tree), (0, react_dom.createPortal)(/* @__PURE__ */ react.default.createElement(_dnd_kit_core.DragOverlay, {
|
|
307
395
|
dropAnimation: dropAnimationConfig,
|
|
308
|
-
modifiers: indicator ? [adjustTranslate] : void 0
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
depth: activeItem.depth,
|
|
396
|
+
modifiers: indicator ? [adjustTranslate] : void 0,
|
|
397
|
+
style: dropOnPageAsSibling ? overlayStyle : void 0
|
|
398
|
+
}, activeItem ? /* @__PURE__ */ react.default.createElement(require_TreeItem.TreeItem, {
|
|
399
|
+
depth: Math.max(0, activeItem.depth - sectionDepth),
|
|
312
400
|
clone: true,
|
|
313
|
-
childCount:
|
|
401
|
+
childCount: activeChildCount,
|
|
314
402
|
item: activeItem,
|
|
315
403
|
indentationWidth,
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
resetState();
|
|
320
|
-
}
|
|
321
|
-
function resetState() {
|
|
322
|
-
setOverId(null);
|
|
323
|
-
setActiveId(null);
|
|
324
|
-
setOffsetLeft(0);
|
|
325
|
-
document.body.style.setProperty("cursor", "");
|
|
326
|
-
}
|
|
404
|
+
isError: (preview === null || preview === void 0 ? void 0 : preview.allowed) === false,
|
|
405
|
+
renderItem
|
|
406
|
+
}) : null), document.body));
|
|
327
407
|
}
|
|
328
408
|
/**
|
|
329
409
|
* 调整拖拽项的位置
|
|
@@ -6,6 +6,7 @@ interface TreeItem {
|
|
|
6
6
|
children: TreeItem[];
|
|
7
7
|
collapsed?: boolean;
|
|
8
8
|
disabledDrop?: boolean;
|
|
9
|
+
isSection?: boolean;
|
|
9
10
|
[key: string]: any;
|
|
10
11
|
}
|
|
11
12
|
type TreeItems = TreeItem[];
|
|
@@ -14,5 +15,6 @@ interface FlattenedItem extends TreeItem {
|
|
|
14
15
|
depth: number;
|
|
15
16
|
index: number;
|
|
16
17
|
}
|
|
18
|
+
type DropPosition = 'before' | 'after' | 'inside';
|
|
17
19
|
//#endregion
|
|
18
|
-
export { FlattenedItem, TreeItem, TreeItems };
|
|
20
|
+
export { DropPosition, FlattenedItem, TreeItem, TreeItems };
|