From 65a1a272b15fb9c08ef75a12946d7f3751a500c7 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Thu, 19 Sep 2024 02:54:28 -0400
Subject: added stop propagation for clicking on tags and icon tags.  fixed
 dragging crash from doc nested in card view to card view.  still needs more
 work for card view to honor canEmbed

---
 .../views/collections/CollectionCardDeckView.tsx   | 32 +++++++++++-----------
 1 file changed, 16 insertions(+), 16 deletions(-)

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

diff --git a/src/client/views/collections/CollectionCardDeckView.tsx b/src/client/views/collections/CollectionCardDeckView.tsx
index 8fea3dbd6..cab7d51e4 100644
--- a/src/client/views/collections/CollectionCardDeckView.tsx
+++ b/src/client/views/collections/CollectionCardDeckView.tsx
@@ -6,6 +6,7 @@ import { emptyFunction } from '../../../Utils';
 import { Doc, StrListCast } from '../../../fields/Doc';
 import { DocData } from '../../../fields/DocSymbols';
 import { Id } from '../../../fields/FieldSymbols';
+import { List } from '../../../fields/List';
 import { BoolCast, DateCast, DocCast, NumCast, RTFCast, ScriptCast, StrCast } from '../../../fields/Types';
 import { URLField } from '../../../fields/URLField';
 import { gptImageLabel } from '../../apis/gpt/GPT';
@@ -21,7 +22,6 @@ import { DocumentView } from '../nodes/DocumentView';
 import { GPTPopup, GPTPopupMode } from '../pdf/GPTPopup/GPTPopup';
 import './CollectionCardDeckView.scss';
 import { CollectionSubView, SubCollectionViewProps } from './CollectionSubView';
-import { List } from '../../../fields/List';
 
 enum cardSortings {
     Time = 'time',
@@ -51,7 +51,6 @@ export class CollectionCardView extends CollectionSubView() {
     @observable _docRefs = new ObservableMap<Doc, DocumentView>();
     @observable _maxRowCount = 10;
     @observable _docDraggedIndex: number = -1;
-    @observable _isACardBeingDragged: boolean = false;
     @observable overIndex: number = -1;
 
     static imageUrlToBase64 = async (imageUrl: string): Promise<string> => {
@@ -76,7 +75,6 @@ export class CollectionCardView extends CollectionSubView() {
         makeObservable(this);
         this.setRegenerateCallback();
     }
-
     protected createDashEventsTarget = (ele: HTMLDivElement | null) => {
         this._dropDisposer?.();
         if (ele) {
@@ -269,11 +267,10 @@ export class CollectionCardView extends CollectionSubView() {
      */
 
     @action
-    onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {
-        if (DragManager.docsBeingDragged.length != 0) {
-            this._isACardBeingDragged = true;
-
-            const newIndex = this.findCardDropIndex(e.clientX, e.clientY);
+    onPointerMove = (x: number, y: number) => {
+        this._docDraggedIndex = -1;
+        if (DragManager.docsBeingDragged.length) {
+            const newIndex = this.findCardDropIndex(x, y);
 
             if (newIndex !== this._docDraggedIndex && newIndex != -1) {
                 this._docDraggedIndex = newIndex;
@@ -297,18 +294,19 @@ export class CollectionCardView extends CollectionSubView() {
     onInternalDrop = undoable(
         action((e: Event, de: DragManager.DropEvent) => {
             if (de.complete.docDragData) {
-                this._isACardBeingDragged = false;
                 const dragIndex = this._docDraggedIndex;
-                if (dragIndex > -1) {
+                const draggedDoc = DragManager.docsBeingDragged[0];
+                if (dragIndex > -1 && draggedDoc) {
                     this._docDraggedIndex = -1;
-                    const draggedDoc = DragManager.docsBeingDragged[0];
                     const sorted = this.sortedDocs;
                     const originalIndex = sorted.findIndex(doc => doc === draggedDoc);
 
                     this.Document.cardSort = '';
-                    sorted.splice(originalIndex, 1);
+                    originalIndex !== -1 && sorted.splice(originalIndex, 1);
                     sorted.splice(dragIndex, 0, draggedDoc);
-                    this.dataDoc[this.fieldKey] = new List<Doc>(sorted);
+                    if (de.complete.docDragData.removeDocument?.(draggedDoc)) {
+                        this.dataDoc[this.fieldKey] = new List<Doc>(sorted);
+                    }
                 }
                 e.stopPropagation();
                 return true;
@@ -397,7 +395,7 @@ export class CollectionCardView extends CollectionSubView() {
             const draggedDoc = DragManager.docsBeingDragged[0];
             const originalIndex = docs.findIndex(doc => doc === draggedDoc);
 
-            docs.splice(originalIndex, 1);
+            originalIndex !== -1 && docs.splice(originalIndex, 1);
             docs.splice(dragIndex, 0, draggedDoc);
         }
 
@@ -619,7 +617,8 @@ export class CollectionCardView extends CollectionSubView() {
             const realIndex = sortedDocs.indexOf(doc);
             const calcRowIndex = this.overflowIndexCalc(realIndex);
             const amCards = this.overflowAmCardsCalc(realIndex);
-            const isSelected = DocumentView.SelectedDocs().includes(doc);
+            const view = DocumentView.getDocumentView(doc, this.DocumentView?.());
+            const isSelected = view?.ComponentView?.isAnyChildContentActive?.() || view?.IsSelected ? true : false;
 
             const childScreenToLocal = () => {
                 this._forceChildXf;
@@ -645,6 +644,7 @@ export class CollectionCardView extends CollectionSubView() {
                     key={doc[Id]}
                     className={`card-item${isSelected ? '-active' : anySelected ? '-inactive' : ''}`}
                     onPointerUp={() => {
+                        if (DocumentView.SelectedDocs().includes(doc)) return;
                         // this turns off documentDecorations during a transition, then turns them back on afterward.
                         SnappingManager.SetIsResizing(doc[Id]);
                         setTimeout(
@@ -675,9 +675,9 @@ export class CollectionCardView extends CollectionSubView() {
 
         return (
             <div
-                onPointerMove={e => this.onPointerMove(e)}
                 className="collectionCardView-outer"
                 ref={(ele: HTMLDivElement | null) => this.createDashEventsTarget(ele)}
+                onPointerMove={e => this.onPointerMove(e.clientX, e.clientY)}
                 onDrop={this.onExternalDrop.bind(this)}
                 style={{
                     background: this._props.styleProvider?.(this.layoutDoc, this._props, StyleProp.BackgroundColor) as string,
-- 
cgit v1.2.3-70-g09d2

