@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.
Files changed (50) hide show
  1. package/build/lowcode/assets-daily.json +11 -11
  2. package/build/lowcode/assets-dev.json +2 -2
  3. package/build/lowcode/assets-prod.json +11 -11
  4. package/build/lowcode/meta.js +1 -1
  5. package/build/lowcode/preview.js +1 -1
  6. package/build/lowcode/render/default/view.css +1 -1
  7. package/build/lowcode/render/default/view.js +4 -4
  8. package/build/lowcode/view.css +1 -1
  9. package/build/lowcode/view.js +4 -4
  10. package/es/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +44 -5
  11. package/es/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +2 -1
  12. package/es/components/pisellDraggable/components/TreeItem/TreeItem.js +5 -2
  13. package/es/components/pisellDraggable/components/TreeItem/TreeItem.less +4 -2
  14. package/es/components/pisellDraggable/index.d.ts +3 -1
  15. package/es/components/pisellDraggable/index.js +287 -207
  16. package/es/components/pisellDraggable/types.d.ts +3 -1
  17. package/es/components/pisellDraggable/utilities.js +90 -79
  18. package/es/components/pisellDropSort/PisellDropSort.js +11 -4
  19. package/es/components/pisellDropSort/components/SortableItem/index.js +8 -5
  20. package/es/components/pisellDropSort/components/SortableItem/index.less +22 -0
  21. package/es/components/pisellDropSort/types.d.ts +1 -0
  22. package/es/components/pisellNavigationMenu/PisellNavigationMenu.js +44 -21
  23. package/es/components/pisellNavigationMenu/PisellNavigationMenu.less +7 -0
  24. package/es/components/pisellNavigationMenu/index.d.ts +1 -1
  25. package/es/components/pisellNavigationMenu/types.d.ts +15 -2
  26. package/es/components/pisellToast/squareToast/toast.js +1 -1
  27. package/es/components/productCard/cartSkuCard/variants/A12/index.js +3 -1
  28. package/es/components/productCard/cartSkuCard/variants/A12/index.less +11 -0
  29. package/es/pisell-materials.tw.css +1 -1
  30. package/lib/components/pisellDraggable/components/TreeItem/SortableTreeItem.js +43 -3
  31. package/lib/components/pisellDraggable/components/TreeItem/TreeItem.d.ts +2 -1
  32. package/lib/components/pisellDraggable/components/TreeItem/TreeItem.js +5 -2
  33. package/lib/components/pisellDraggable/components/TreeItem/TreeItem.less +4 -2
  34. package/lib/components/pisellDraggable/index.d.ts +3 -1
  35. package/lib/components/pisellDraggable/index.js +281 -201
  36. package/lib/components/pisellDraggable/types.d.ts +3 -1
  37. package/lib/components/pisellDraggable/utilities.js +90 -79
  38. package/lib/components/pisellDropSort/PisellDropSort.js +10 -3
  39. package/lib/components/pisellDropSort/components/SortableItem/index.js +8 -5
  40. package/lib/components/pisellDropSort/components/SortableItem/index.less +22 -0
  41. package/lib/components/pisellDropSort/types.d.ts +1 -0
  42. package/lib/components/pisellNavigationMenu/PisellNavigationMenu.js +44 -21
  43. package/lib/components/pisellNavigationMenu/PisellNavigationMenu.less +7 -0
  44. package/lib/components/pisellNavigationMenu/index.d.ts +1 -1
  45. package/lib/components/pisellNavigationMenu/types.d.ts +15 -2
  46. package/lib/components/pisellToast/squareToast/toast.js +1 -1
  47. package/lib/components/productCard/cartSkuCard/variants/A12/index.js +3 -1
  48. package/lib/components/productCard/cartSkuCard/variants/A12/index.less +11 -0
  49. package/lib/pisell-materials.tw.css +1 -1
  50. package/package.json +3 -3
@@ -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
- function SortableTree({ collapsible = true, value = initialItems, indicator = false, indentationWidth = 50, removable = true, renderItem, onChange, onRemoveBefore, __designMode, maxLevel = 3, canDrop }) {
95
- /** 当前树形数据 */
96
- const [items, setItems] = (0, react.useState)([]);
97
- /** 当前正在拖拽的节点ID */
98
- const [activeId, setActiveId] = (0, react.useState)(null);
99
- /** 当前拖拽悬停的节点ID */
100
- const [overId, setOverId] = (0, react.useState)(null);
101
- /** 水平偏移量,用于确定拖拽时的层级变化 */
102
- const [offsetLeft, setOffsetLeft] = (0, react.useState)(0);
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
- console.log("初始化", value);
105
- setItems(value);
106
- }, [value]);
107
- const flattenTreeData = (0, react.useMemo)(() => {
108
- return require_utilities.flattenTree(items);
109
- }, [items]);
110
- /**
111
- * 扁平化处理树形数据
112
- * 1. 将树形结构转换为扁平数组
113
- * 2. 处理折叠状态
114
- * 3. 移除被折叠节点的子节点
115
- */
116
- const flattenedItems = (0, react.useMemo)(() => {
117
- const collapsedItems = flattenTreeData.reduce((acc, { children = [], collapsed, id }) => collapsed && children.length ? [...acc, id] : acc, []);
118
- return require_utilities.removeChildrenOf(flattenTreeData, activeId != null ? [activeId, ...collapsedItems] : collapsedItems);
119
- }, [activeId, flattenTreeData]);
120
- console.log("flattenedItems", flattenedItems);
121
- /**
122
- * 计算拖拽投影
123
- * 根据当前拖拽状态计算目标位置和深度
124
- */
125
- const projected = activeId && overId ? require_utilities.getProjection(flattenedItems, activeId, overId, offsetLeft, indentationWidth) : null;
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 sortedIds = (0, react.useMemo)(() => flattenedItems.map(({ id }) => id), [flattenedItems]);
136
- const activeItem = (0, react.useMemo)(() => {
137
- return activeId ? flattenedItems.find(({ id }) => id === activeId) : null;
138
- }, [activeId, flattenedItems]);
139
- (0, react.useEffect)(() => {
140
- sensorContext.current = {
141
- items: flattenedItems,
142
- offset: offsetLeft
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
- * @param items 当前项目列表
151
- * @param itemId 要检查的项目ID
152
- * @param baseDepth 基础深度
153
- * @returns 是否超过限制
154
- */
155
- function checkSubtreeDepth(items, itemId, baseDepth) {
156
- if (!items.find((i) => i.id === itemId)) return false;
157
- if (baseDepth >= maxLevel) return true;
158
- const children = items.filter((i) => i.parentId === itemId);
159
- if (baseDepth >= maxLevel - 1 && children.length > 0) return true;
160
- return children.some((child) => {
161
- const childNewDepth = baseDepth + 1;
162
- return childNewDepth >= maxLevel || checkSubtreeDepth(items, child.id, childNewDepth);
163
- });
164
- }
165
- /**
166
- * 处理节点删除
167
- * 从树形结构中移除指定节点
168
- */
169
- const handleRemove = (0, ahooks.useMemoizedFn)(function() {
170
- var _ref = require_asyncToGenerator._asyncToGenerator(function* (item) {
171
- if (onRemoveBefore) {
172
- if (!(yield onRemoveBefore === null || onRemoveBefore === void 0 ? void 0 : onRemoveBefore(item))) return;
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
- setItems((items) => require_utilities.removeItem(items, item.id));
175
- onChange === null || onChange === void 0 || onChange(items);
176
- });
177
- return function(_x) {
178
- return _ref.apply(this, arguments);
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 handleDragOver = (0, ahooks.useMemoizedFn)(({ over }) => {
198
- if (!projected || !over) {
199
- var _over$id;
200
- setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : null);
201
- return;
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
- const targetParent = projected.parentId ? flattenedItems.find((item) => item.id === projected.parentId) : null;
204
- if (targetParent === null || targetParent === void 0 ? void 0 : targetParent.disabledDrop) return;
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 parentNode = (0, react.useMemo)(() => {
210
- return (projected === null || projected === void 0 ? void 0 : projected.parentId) ? flattenedItems.find((item) => item.id === projected.parentId) : null;
211
- }, [flattenedItems, projected === null || projected === void 0 ? void 0 : projected.parentId]);
212
- /**
213
- * 处理拖拽结束事件
214
- * 1. 重置状态
215
- * 2. 更新节点位置和层级
216
- * 3. 重建树形结构
217
- */
218
- const handleDragEnd = (0, ahooks.useMemoizedFn)(({ active, over }) => {
219
- resetState();
220
- if (projected && over) {
221
- const { depth, parentId } = projected;
222
- const targetParent = parentId ? flattenedItems.find((item) => item.id === parentId) : null;
223
- if (targetParent === null || targetParent === void 0 ? void 0 : targetParent.disabledDrop) return;
224
- const dragItem = flattenedItems.find((item) => item.id === active.id);
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
- if (depth >= maxLevel) return;
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
- const handleCollapse = (0, ahooks.useMemoizedFn)((id) => {
249
- setItems((items) => {
250
- const newVal = require_utilities.setProperty(items, id, "collapsed", (value) => {
251
- return !value;
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 isError = (0, react.useMemo)(() => {
258
- return !(canDrop === null || canDrop === void 0 ? void 0 : canDrop(activeItem || {}, {}, projected === null || projected === void 0 ? void 0 : projected.parentId, parentNode));
259
- }, [
260
- projected,
261
- activeItem,
262
- canDrop,
263
- parentNode
264
- ]);
265
- const renderTreeItems = (0, react.useMemo)(() => {
266
- return flattenedItems.map((item) => {
267
- const { id, children, collapsed, depth } = item;
268
- return /* @__PURE__ */ react.default.createElement(require_SortableTreeItem.default, {
269
- key: id,
270
- id,
271
- item,
272
- depth: id === activeId && projected ? projected.depth : depth,
273
- indentationWidth,
274
- indicator,
275
- collapsed: Boolean(collapsed && (children === null || children === void 0 ? void 0 : children.length)),
276
- onCollapse: collapsible && (children === null || children === void 0 ? void 0 : children.length) ? () => handleCollapse(id) : void 0,
277
- onRemove: removable ? () => handleRemove(item) : void 0,
278
- renderItem,
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: handleDragMove,
300
- onDragOver: handleDragOver,
382
+ onDragMove: updatePreview,
383
+ onDragOver: updatePreview,
301
384
  onDragEnd: handleDragEnd,
302
- onDragCancel: handleDragCancel
303
- }, /* @__PURE__ */ react.default.createElement(_dnd_kit_sortable.SortableContext, {
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
- }, renderTreeItems, (0, react_dom.createPortal)(/* @__PURE__ */ react.default.createElement(_dnd_kit_core.DragOverlay, {
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
- }, activeId && activeItem ? /* @__PURE__ */ react.default.createElement(require_SortableTreeItem.default, {
310
- id: activeId,
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: require_utilities.getChildCount(items, activeId) + 1,
401
+ childCount: activeChildCount,
314
402
  item: activeItem,
315
403
  indentationWidth,
316
- renderItem: (props, ref) => renderItem === null || renderItem === void 0 ? void 0 : renderItem(require_objectSpread2._objectSpread2(require_objectSpread2._objectSpread2({}, props), {}, { isError }), ref)
317
- }) : null), document.body)));
318
- function handleDragCancel() {
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 };