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.

---
 src/client/views/collections/CollectionSubView.tsx | 19 +++++++++++--------
 1 file changed, 11 insertions(+), 8 deletions(-)

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

diff --git a/src/client/views/collections/CollectionSubView.tsx b/src/client/views/collections/CollectionSubView.tsx
index ecc2aea31..32198e3a2 100644
--- a/src/client/views/collections/CollectionSubView.tsx
+++ b/src/client/views/collections/CollectionSubView.tsx
@@ -4,7 +4,7 @@ import * as rp from 'request-promise';
 import { Utils, returnFalse } from '../../../Utils';
 import CursorField from '../../../fields/CursorField';
 import { Doc, DocListCast, Field, Opt, StrListCast } from '../../../fields/Doc';
-import { AclPrivate } from '../../../fields/DocSymbols';
+import { AclPrivate, DocData } from '../../../fields/DocSymbols';
 import { Id } from '../../../fields/FieldSymbols';
 import { List } from '../../../fields/List';
 import { listSpec } from '../../../fields/Schema';
@@ -196,13 +196,16 @@ export function CollectionSubView<X>(moreProps?: X) {
         @undoBatch
         protected onGesture(e: Event, ge: GestureUtils.GestureEvent) {}
 
-        protected onInternalPreDrop(e: Event, de: DragManager.DropEvent, dropAction: dropActionType) {
-            if (de.complete.docDragData) {
-                // if the dropEvent's dragAction is, say 'embed', but we're just dragging within a collection, we may not actually want to make an embedding.
-                // so we check if our collection has a dropAction set on it and if so, we use that instead.
-                if (dropAction && !de.complete.docDragData.draggedDocuments.some(d => d.embedContainer === this.Document && this.childDocs.includes(d))) {
-                    de.complete.docDragData.dropAction = dropAction;
-                }
+        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 => d.embedContainer !== this._props.Document);
+                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();
             }
         }
-- 
cgit v1.2.3-70-g09d2

