From 2c3264bca271af170b620cfc44ecdfafb77aacc0 Mon Sep 17 00:00:00 2001
From: bobzel <zzzman@gmail.com>
Date: Mon, 28 Mar 2022 12:20:07 -0400
Subject: enabled dragging documents onto tab bar without shift.  modified link
 pivot document to automatically update when links are added and be a stacking
 view

---
 src/client/views/nodes/DocumentLinksButton.tsx | 35 ++++++++------------------
 1 file changed, 11 insertions(+), 24 deletions(-)

(limited to 'src/client/views/nodes/DocumentLinksButton.tsx')

diff --git a/src/client/views/nodes/DocumentLinksButton.tsx b/src/client/views/nodes/DocumentLinksButton.tsx
index 7e6ca4248..804e82856 100644
--- a/src/client/views/nodes/DocumentLinksButton.tsx
+++ b/src/client/views/nodes/DocumentLinksButton.tsx
@@ -2,9 +2,10 @@ import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
 import { Tooltip } from "@material-ui/core";
 import { action, computed, observable, runInAction } from "mobx";
 import { observer } from "mobx-react";
-import { Doc, DocListCast, DocListCastAsync, Opt, WidthSym } from "../../../fields/Doc";
+import { Doc, Opt } from "../../../fields/Doc";
 import { Id } from "../../../fields/FieldSymbols";
-import { Cast, StrCast } from "../../../fields/Types";
+import { ScriptField } from "../../../fields/ScriptField";
+import { StrCast } from "../../../fields/Types";
 import { TraceMobx } from "../../../fields/util";
 import { emptyFunction, returnFalse, setupMoveUpEvents } from "../../../Utils";
 import { DocServer } from "../../DocServer";
@@ -20,7 +21,6 @@ import { DocumentView } from "./DocumentView";
 import { LinkDescriptionPopup } from "./LinkDescriptionPopup";
 import { TaskCompletionBox } from "./TaskCompletedBox";
 import React = require("react");
-import { Transform } from "../../util/Transform";
 
 const higflyout = require("@hig/flyout");
 export const { anchorPoints } = higflyout;
@@ -72,31 +72,18 @@ export class DocumentLinksButton extends React.Component<DocumentLinksButtonProp
     onLinkMenuOpen = (e: React.PointerEvent): void => {
         setupMoveUpEvents(this, e, this.onLinkButtonMoved, emptyFunction, action((e, doubleTap) => {
             if (doubleTap) {
-                const rootDoc = this.props.View.rootDoc;
-                const docid = Doc.CurrentUserEmail + Doc.GetProto(rootDoc)[Id] + "-pivotish";
-                DocServer.GetRefField(docid).then(async docx => {
+                const linkSource = this.props.View.rootDoc;
+                const docid = Doc.CurrentUserEmail + Doc.GetProto(linkSource)[Id] + "-pivotish";
+                DocServer.GetRefField(docid).then(docx => {
                     const rootAlias = () => {
-                        const rootAlias = Doc.MakeAlias(rootDoc);
+                        const rootAlias = Doc.MakeAlias(linkSource);
                         rootAlias.x = rootAlias.y = 0;
                         return rootAlias;
                     };
-                    let wid = rootDoc[WidthSym]();
-                    const target = ((docx instanceof Doc) && docx) || Docs.Create.FreeformDocument([rootAlias()], { title: this.props.View.Document.title + "-pivot", _width: 500, _height: 500, }, docid);
-                    const docs = await DocListCastAsync(Doc.GetProto(target).data);
-                    if (!target.pivotFocusish) (Doc.GetProto(target).pivotFocusish = target);
-                    DocListCast(rootDoc.links).forEach(link => {
-                        const other = LinkManager.getOppositeAnchor(link, rootDoc);
-                        const otherdoc = !other ? undefined : other.annotationOn ? Cast(other.annotationOn, Doc, null) : other;
-                        if (otherdoc && !docs?.some(d => Doc.AreProtosEqual(d, otherdoc))) {
-                            const alias = Doc.MakeAlias(otherdoc);
-                            alias.x = wid;
-                            alias.y = 0;
-                            alias._lockedPosition = false;
-                            wid += otherdoc[WidthSym]();
-                            Doc.AddDocToList(Doc.GetProto(target), "data", alias);
-                        }
-                    });
-                    LightboxView.SetLightboxDoc(target);
+                    const linkCollection = ((docx instanceof Doc) && docx) || Docs.Create.StackingDocument([/*rootAlias()*/], { title: this.props.View.Document.title + "-pivot", _width: 500, _height: 500, }, docid);
+                    linkCollection.linkSource = linkSource;
+                    if (!linkCollection.reactionScript) linkCollection.reactionScript = ScriptField.MakeScript("updateLinkCollection(self)");
+                    LightboxView.SetLightboxDoc(linkCollection);
                 });
             }
             else DocumentLinksButton.LinkEditorDocView = this.props.View;
-- 
cgit v1.2.3-70-g09d2

