From a6577f0c085d206db11e491bd4a1e4bae70e0ee6 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Fri, 12 Apr 2024 13:51:07 -0400
Subject:  fixed auto play for trails.  fixed presbox to allow drag and drop in
 addition to pin button.  fixed tree view to not 'move' items that have a
 'copy' drop action.  fixed dragPreDrop functions in tree and stacking views
 to use source drag action over target drop action.

---
 .../CollectionStackingViewFieldColumn.tsx           | 21 ++++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)

(limited to 'src/client/views/collections/CollectionStackingViewFieldColumn.tsx')

diff --git a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
index 641e01b81..c5292f880 100644
--- a/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
+++ b/src/client/views/collections/CollectionStackingViewFieldColumn.tsx
@@ -12,7 +12,7 @@ import { TraceMobx } from '../../../fields/util';
 import { DivHeight, DivWidth, emptyFunction, returnEmptyString, setupMoveUpEvents } from '../../../Utils';
 import { Docs, DocUtils } from '../../documents/Documents';
 import { DocumentType } from '../../documents/DocumentTypes';
-import { DragManager } from '../../util/DragManager';
+import { DragManager, dropActionType } from '../../util/DragManager';
 import { SnappingManager } from '../../util/SnappingManager';
 import { Transform } from '../../util/Transform';
 import { undoBatch } from '../../util/UndoManager';
@@ -66,11 +66,26 @@ export class CollectionStackingViewFieldColumn extends ObservableReactComponent<
 
     _ele: HTMLElement | null = null;
 
+    protected onInternalPreDrop = (e: Event, de: DragManager.DropEvent, targetDropAction: dropActionType) => {
+        const dragData = de.complete.docDragData;
+        if (dragData) {
+            const sourceDragAction = dragData.dropAction;
+            const sameCollection = !dragData.draggedDocuments.some(d => !this._props.docList.includes(d));
+            dragData.dropAction = !sameCollection // if doc from another tree
+                ? sourceDragAction || targetDropAction // then use the source's dragAction otherwise the target's
+                : sourceDragAction === dropActionType.inPlace // if source drag is inPlace
+                  ? sourceDragAction // keep the doc in place
+                  : dropActionType.same; // otherwise use same tree semantics to move within tree
+
+            e.stopPropagation();
+        }
+    };
+
     // This is likely similar to what we will be doing. Why do we need to make these refs?
     // is that the only way to have drop targets?
     createColumnDropRef = (ele: HTMLDivElement | null) => {
         this.dropDisposer?.();
-        if (ele) this.dropDisposer = DragManager.MakeDropTarget(ele, this.columnDrop.bind(this), this._props.Document);
+        if (ele) this.dropDisposer = DragManager.MakeDropTarget(ele, this.columnDrop.bind(this), this._props.Document, this.onInternalPreDrop.bind(this));
         else if (this._ele) this.props.refList.splice(this.props.refList.indexOf(this._ele), 1);
         this._ele = ele;
     };
@@ -345,7 +360,7 @@ export class CollectionStackingViewFieldColumn extends ObservableReactComponent<
                     <div>
                         <div
                             key={`${heading}-stack`}
-                            className={`collectionStackingView-masonrySingle`}
+                            className="collectionStackingView-masonrySingle"
                             style={{
                                 padding: `${columnYMargin}px ${0}px ${this._props.yMargin}px ${0}px`,
                                 margin: 'auto',
-- 
cgit v1.2.3-70-g09d2

