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