@inf-monkeys-tech/monkeys-design 0.4.44 → 0.4.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.
@@ -1778,6 +1778,52 @@ function buildFlattenedTree(nodes, expandedNodeIds) {
1778
1778
  flattenTree(nodes, expandedNodeIds, void 0, 0, entries);
1779
1779
  return entries;
1780
1780
  }
1781
+ function findAncestorEntryAtDepth(entries, entry, depth) {
1782
+ if (depth < 0) return void 0;
1783
+ let parentId = entry.parentId;
1784
+ while (parentId) {
1785
+ const parentEntry = entries.find((candidate) => candidate.node.id === parentId);
1786
+ if (!parentEntry) return void 0;
1787
+ if (parentEntry.depth === depth) return parentEntry;
1788
+ parentId = parentEntry.parentId;
1789
+ }
1790
+ return void 0;
1791
+ }
1792
+ function countSiblingsBeforeDrop(entries, activeEntry, overEntry, parentId, targetDepth) {
1793
+ const targetEntry = activeEntry.node.id === overEntry.node.id ? activeEntry : overEntry;
1794
+ let index = 0;
1795
+ for (const entry of entries) {
1796
+ if (entry.node.id === targetEntry.node.id) break;
1797
+ if (entry.node.id === activeEntry.node.id) continue;
1798
+ if (entry.parentId === parentId && entry.depth === targetDepth) {
1799
+ index += 1;
1800
+ }
1801
+ }
1802
+ return index;
1803
+ }
1804
+ function projectDataExplorerDraggableTreeDrop({
1805
+ flattenedNodes,
1806
+ activeEntry,
1807
+ overEntry,
1808
+ dragOffsetX,
1809
+ indentSize
1810
+ }) {
1811
+ const depthDelta = Math.round(dragOffsetX / Math.max(1, indentSize));
1812
+ const projectedDepth = Math.max(0, activeEntry.depth + depthDelta);
1813
+ const targetDepth = Math.min(projectedDepth, overEntry.depth);
1814
+ const parentAtDepth = targetDepth === 0 ? void 0 : targetDepth === overEntry.depth ? overEntry.parentId : findAncestorEntryAtDepth(flattenedNodes, overEntry, targetDepth)?.parentId;
1815
+ return {
1816
+ parentId: parentAtDepth,
1817
+ index: countSiblingsBeforeDrop(
1818
+ flattenedNodes,
1819
+ activeEntry,
1820
+ overEntry,
1821
+ parentAtDepth,
1822
+ targetDepth
1823
+ ),
1824
+ depth: targetDepth
1825
+ };
1826
+ }
1781
1827
  function DraggableTreeItem({
1782
1828
  entry,
1783
1829
  selected,
@@ -2153,7 +2199,7 @@ function DataExplorerDraggableTree({
2153
2199
  const handleDragEnd = (event) => {
2154
2200
  const activeId = String(event.active.id || "");
2155
2201
  const overId = event.over ? String(event.over.id || "") : "";
2156
- if (!activeId || !overId || activeId === overId || !onDragEnd) {
2202
+ if (!activeId || !overId || !onDragEnd) {
2157
2203
  clearDragState();
2158
2204
  return;
2159
2205
  }
@@ -2163,14 +2209,29 @@ function DataExplorerDraggableTree({
2163
2209
  clearDragState();
2164
2210
  return;
2165
2211
  }
2212
+ const projectedDrop = projectDataExplorerDraggableTreeDrop({
2213
+ flattenedNodes,
2214
+ activeEntry: activeEntry2,
2215
+ overEntry,
2216
+ dragOffsetX: event.delta.x,
2217
+ indentSize
2218
+ });
2219
+ if (activeEntry2.parentId === projectedDrop.parentId && activeEntry2.index === projectedDrop.index) {
2220
+ clearDragState();
2221
+ return;
2222
+ }
2166
2223
  const payload = {
2167
2224
  activeNode: activeEntry2.node,
2168
2225
  overNode: overEntry.node,
2169
2226
  activeParentId: activeEntry2.parentId,
2170
2227
  overParentId: overEntry.parentId,
2228
+ targetParentId: projectedDrop.parentId,
2171
2229
  activeIndex: activeEntry2.index,
2172
2230
  overIndex: overEntry.index,
2231
+ targetIndex: projectedDrop.index,
2232
+ targetDepth: projectedDrop.depth,
2173
2233
  sameParent: activeEntry2.parentId === overEntry.parentId,
2234
+ targetSameParent: activeEntry2.parentId === projectedDrop.parentId,
2174
2235
  context
2175
2236
  };
2176
2237
  void onDragEnd(payload);