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/DocumentView.tsx | 26 +++++++++++++++++++++++++-
 1 file changed, 25 insertions(+), 1 deletion(-)

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

diff --git a/src/client/views/nodes/DocumentView.tsx b/src/client/views/nodes/DocumentView.tsx
index e7de87ea5..955698190 100644
--- a/src/client/views/nodes/DocumentView.tsx
+++ b/src/client/views/nodes/DocumentView.tsx
@@ -2,7 +2,7 @@ import { IconProp } from "@fortawesome/fontawesome-svg-core";
 import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
 import { action, computed, IReactionDisposer, observable, reaction, runInAction } from "mobx";
 import { observer } from "mobx-react";
-import { AclAdmin, AclEdit, AclPrivate, DataSym, Doc, DocListCast, Field, Opt, StrListCast } from "../../../fields/Doc";
+import { AclAdmin, AclEdit, AclPrivate, DataSym, Doc, DocListCast, DocListCastAsync, Field, Opt, StrListCast, WidthSym } from "../../../fields/Doc";
 import { Document } from '../../../fields/documentSchemas';
 import { Id } from '../../../fields/FieldSymbols';
 import { InkTool } from '../../../fields/InkField';
@@ -1247,6 +1247,10 @@ export class DocumentView extends React.Component<DocumentViewProps> {
         return this.props.ScreenToLocalTransform().translate(-this.centeringX, -this.centeringY).scale(1 / this.nativeScaling);
     }
     componentDidMount() {
+        this._disposers.reactionScript = reaction(
+            () => ScriptCast(this.rootDoc.reactionScript)?.script?.run({ this: this.props.Document, self: Cast(this.rootDoc, Doc, null) || this.props.Document }).result,
+            output => output
+        );
         this._disposers.height = reaction(
             () => NumCast(this.layoutDoc._height),
             action(height => {
@@ -1298,4 +1302,24 @@ export class DocumentView extends React.Component<DocumentViewProps> {
 ScriptingGlobals.add(function toggleDetail(dv: DocumentView, detailLayoutKeySuffix: string) {
     if (dv.Document.layoutKey === "layout_" + detailLayoutKeySuffix) dv.switchViews(false, "layout");
     else dv.switchViews(true, detailLayoutKeySuffix);
+});
+
+ScriptingGlobals.add(function updateLinkCollection(linkCollection: Doc) {
+    const linkSource = Cast(linkCollection.linkSource, Doc, null);
+    const collectedLinks = DocListCast(Doc.GetProto(linkCollection).data);
+    let wid = linkSource[WidthSym]();
+    const links = DocListCast(linkSource.links);
+    links.forEach(link => {
+        const other = LinkManager.getOppositeAnchor(link, linkSource);
+        const otherdoc = !other ? undefined : other.annotationOn ? Cast(other.annotationOn, Doc, null) : other;
+        if (otherdoc && !collectedLinks?.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(linkCollection), "data", alias);
+        }
+    });
+    return links;
 });
\ No newline at end of file
-- 
cgit v1.2.3-70-g09d2

