aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/client/documents/Documents.ts12
-rw-r--r--src/client/util/DragManager.ts9
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx21
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkWithProxyView.tsx60
-rw-r--r--src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx59
5 files changed, 116 insertions, 45 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index 002de8b5f..79ba433c8 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -99,8 +99,18 @@ export namespace DocUtils {
linkDocProto.anchor2 = target;
linkDocProto.anchor2Page = target.curPage;
linkDocProto.anchor2Groups = new List<Doc>([]);
+
linkDocProto.context = targetContext;
+ let proxy1 = Docs.TextDocument({ width: 300, height: 100, borderRounding: 0 });
+ let proxy1Proto = Doc.GetProto(proxy1);
+ let proxy2 = Docs.TextDocument({ width: 300, height: 100, borderRounding: 0 });
+ let proxy2Proto = Doc.GetProto(proxy2);
+
+ linkDocProto.proxy1 = proxy1; // src: 1 targ: 2
+ linkDocProto.proxy2 = proxy2; // src: 2 targ: 1
+
+
LinkManager.Instance.allLinks.push(linkDoc);
return linkDoc;
@@ -377,7 +387,7 @@ export namespace Docs {
}
/*
-
+
this template requires an additional style setting on the collectionView-cont to make the layout relative
.collectionView-cont {
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 82d30e0e6..4787ac40f 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -45,6 +45,9 @@ export function SetupDrag(_reference: React.RefObject<HTMLElement>, docFunc: ()
export async function DragLinkAsDocument(dragEle: HTMLElement, x: number, y: number, linkDoc: Doc, sourceDoc: Doc) {
let draggeddoc = LinkManager.Instance.findOppositeAnchor(linkDoc, sourceDoc);
+
+ // TODO: if not in same context then don't drag
+
let moddrag = await Cast(draggeddoc.annotationOn, Doc);
let dragData = new DragManager.DocumentDragData(moddrag ? [moddrag] : [draggeddoc]);
DragManager.StartDocumentDrag([dragEle], dragData, x, y, {
@@ -58,6 +61,9 @@ export async function DragLinkAsDocument(dragEle: HTMLElement, x: number, y: num
export async function DragLinksAsDocuments(dragEle: HTMLElement, x: number, y: number, sourceDoc: Doc) {
let srcTarg = sourceDoc.proto;
let draggedDocs: Doc[] = [];
+
+ // TODO: if not in same context then don't drag
+
if (srcTarg) {
let linkDocs = LinkManager.Instance.findAllRelatedLinks(srcTarg);
if (linkDocs) {
@@ -74,6 +80,9 @@ export async function DragLinksAsDocuments(dragEle: HTMLElement, x: number, y: n
if (doc) moddrag.push(doc);
}
let dragData = new DragManager.DocumentDragData(moddrag.length ? moddrag : draggedDocs);
+ // dragData.moveDocument = (document, targetCollection, addDocument) => {
+ // return false;
+ // };
DragManager.StartDocumentDrag([dragEle], dragData, x, y, {
handlers: {
dragComplete: action(emptyFunction),
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
index 4d477454b..f995a35e3 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkView.tsx
@@ -18,8 +18,6 @@ export interface CollectionFreeFormLinkViewProps {
sourceView: DocumentView;
targetView: DocumentView;
- sameContext: boolean;
- addDocTab: (document: Doc, where: string) => void;
}
@observer
@@ -44,12 +42,6 @@ export class CollectionFreeFormLinkView extends React.Component<CollectionFreeFo
// }
// }
- followButton = (e: React.PointerEvent): void => {
- // TODO: would be nicer to open docview in context
- e.stopPropagation();
- console.log("follow");
- this.props.addDocTab(this.props.targetView.props.Document, "onRight");
- }
render() {
// let l = this.props.LinkDocs;
@@ -62,25 +54,14 @@ export class CollectionFreeFormLinkView extends React.Component<CollectionFreeFo
let x2 = NumCast(a2.Document.x) + (BoolCast(a2.Document.isMinimized, false) ? 5 : NumCast(a2.Document.width) / NumCast(a2.Document.zoomBasis, 1) / 2);
let y2 = NumCast(a2.Document.y) + (BoolCast(a2.Document.isMinimized, false) ? 5 : NumCast(a2.Document.height) / NumCast(a2.Document.zoomBasis, 1) / 2);
- if (!this.props.sameContext) {
- x2 = x1 + 300;
- y2 = y1 - 300;
- }
-
- let containing = "";
- if (this.props.targetView.props.ContainingCollectionView) {
- containing = StrCast(this.props.targetView.props.ContainingCollectionView.props.Document.title);
- }
- let text = "link to " + StrCast(this.props.targetView.props.Document.title) + (containing === "" ? "" : (" in the context of " + containing));
return (
<>
<line className="collectionfreeformlinkview-linkLine"
style={{ strokeWidth: `${2 * 1 / 2}` }}
x1={`${x1}`} y1={`${y1}`}
x2={`${x2}`} y2={`${y2}`} />
- {!this.props.sameContext ? <circle className="collectionfreeformlinkview-linkCircle" cx={x2} cy={y2} r={20} onPointerDown={this.followButton}></circle> : <></>}
- {!this.props.sameContext ? <text textAnchor="middle" className="collectionfreeformlinkview-linkText" x={`${x2}`} y={`${y2}`}> {text}</text> : <></>}
+
{/* <circle key="linkCircle" className="collectionfreeformlinkview-linkCircle"
cx={(x1 + x2) / 2} cy={(y1 + y2) / 2} r={8} onPointerDown={this.onPointerDown} /> */}
{/* <text key="linkText" textAnchor="middle" className="collectionfreeformlinkview-linkText" x={`${(x1 + x2) / 2}`} y={`${(y1 + y2) / 2}`}>
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkWithProxyView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkWithProxyView.tsx
new file mode 100644
index 000000000..81a00ba95
--- /dev/null
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinkWithProxyView.tsx
@@ -0,0 +1,60 @@
+import { observer } from "mobx-react";
+import { Doc, HeightSym, WidthSym } from "../../../../new_fields/Doc";
+import { BoolCast, NumCast, StrCast } from "../../../../new_fields/Types";
+import { InkingControl } from "../../InkingControl";
+import "./CollectionFreeFormLinkView.scss";
+import React = require("react");
+import v5 = require("uuid/v5");
+import { DocumentView } from "../../nodes/DocumentView";
+import { Docs } from "../../../documents/Documents";
+import { observable } from "mobx";
+
+export interface CollectionFreeFormLinkViewProps {
+ sourceView: DocumentView;
+ targetView: DocumentView;
+ proxyDoc: Doc;
+ addDocTab: (document: Doc, where: string) => void;
+}
+
+@observer
+export class CollectionFreeFormLinkWithProxyView extends React.Component<CollectionFreeFormLinkViewProps> {
+
+ // @observable private _proxyX: number = NumCast(this.props.proxyDoc.x);
+ // @observable private _proxyY: number = NumCast(this.props.proxyDoc.y);
+
+ followButton = (e: React.PointerEvent): void => {
+ // TODO: would be nicer to open docview in context
+ e.stopPropagation();
+ console.log("follow");
+ this.props.addDocTab(this.props.targetView.props.Document, "onRight");
+ }
+
+ render() {
+ let a1 = this.props.sourceView;
+ let a2 = this.props.proxyDoc;
+ let x1 = NumCast(a1.Document.x) + (BoolCast(a1.Document.isMinimized, false) ? 5 : NumCast(a1.Document.width) / NumCast(a1.Document.zoomBasis, 1) / 2);
+ let y1 = NumCast(a1.Document.y) + (BoolCast(a1.Document.isMinimized, false) ? 5 : NumCast(a1.Document.height) / NumCast(a1.Document.zoomBasis, 1) / 2);
+
+ let x2 = NumCast(a2.x) + (BoolCast(a2.isMinimized, false) ? 5 : NumCast(a2.width) / NumCast(a2.zoomBasis, 1) / 2);
+ let y2 = NumCast(a2.y) + (BoolCast(a2.isMinimized, false) ? 5 : NumCast(a2.height) / NumCast(a2.zoomBasis, 1) / 2);
+
+ // let containing = "";
+ // if (this.props.targetView.props.ContainingCollectionView) {
+ // containing = StrCast(this.props.targetView.props.ContainingCollectionView.props.Document.title);
+ // }
+
+ // let text = "link to " + StrCast(this.props.targetView.props.Document.title) + (containing === "" ? "" : (" in the context of " + containing));
+ return (
+ <>
+ <line className="collectionfreeformlinkview-linkLine"
+ style={{ strokeWidth: `${2 * 1 / 2}` }}
+ x1={`${x1}`} y1={`${y1}`}
+ x2={`${x2}`} y2={`${y2}`} />
+ {/* <circle className="collectionfreeformlinkview-linkCircle" cx={x2} cy={y2} r={20} ></circle>
+ <text textAnchor="middle" className="collectionfreeformlinkview-linkText" x={`${x2}`} y={`${y2}`}> {text}</text> */}
+ </>
+ );
+ }
+}
+
+//onPointerDown={this.followButton} \ No newline at end of file
diff --git a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx
index 86625863f..eaef1f32a 100644
--- a/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx
+++ b/src/client/views/collections/collectionFreeForm/CollectionFreeFormLinksView.tsx
@@ -11,6 +11,8 @@ import { CollectionViewProps } from "../CollectionSubView";
import "./CollectionFreeFormLinksView.scss";
import { CollectionFreeFormLinkView } from "./CollectionFreeFormLinkView";
import React = require("react");
+import { CollectionFreeFormLinkWithProxyView } from "./CollectionFreeFormLinkWithProxyView";
+import { Docs } from "../../../documents/Documents";
@observer
export class CollectionFreeFormLinksView extends React.Component<CollectionViewProps> {
@@ -159,47 +161,56 @@ export class CollectionFreeFormLinksView extends React.Component<CollectionViewP
// }
findUniquePairs = (): JSX.Element[] => {
- // console.log("FIND UNIQUE PAIRS");
let connections = DocumentManager.Instance.LinkedDocumentViews;
- let unique: Array<{ sourceView: DocumentView, targetView: DocumentView, sameContext: boolean }> = [];
+ let unique: Set<{ sourceView: DocumentView, targetView: DocumentView, linkDoc: Doc }> = new Set();
connections.forEach(c => {
- let match1Index = unique.findIndex(u => (c.anchor1View === u.sourceView) && (c.anchor2View === u.targetView));
- let match2Index = unique.findIndex(u => (c.anchor1View === u.targetView) && (c.anchor2View === u.sourceView));
+ // let match1Index = unique.findIndex(u => (c.anchor1View === u.sourceView) && (c.anchor2View === u.targetView));
+ // let match2Index = unique.findIndex(u => (c.anchor1View === u.targetView) && (c.anchor2View === u.sourceView));
+ let match1 = unique.has({ sourceView: c.anchor1View, targetView: c.anchor2View, linkDoc: c.linkDoc });
+ let match2 = unique.has({ sourceView: c.anchor2View, targetView: c.anchor1View, linkDoc: c.linkDoc });
let sameContext = c.anchor1View.props.ContainingCollectionView === c.anchor2View.props.ContainingCollectionView;
- if (!(match1Index > -1 || match2Index > -1)) {
- // if docview pair does not already exist in unique, push
- unique.push({ sourceView: c.anchor1View, targetView: c.anchor2View, sameContext: sameContext });
+ // if in same context, push if docview pair does not already exist
+ // else push both directions of pair
+ if (sameContext) {
+ if (!(match1 || match2)) unique.add({ sourceView: c.anchor1View, targetView: c.anchor2View, linkDoc: c.linkDoc });
} else {
- // if docview pair exists in unique, push if not in same context
- if (!sameContext) {
- match1Index > -1 ? unique.push({ sourceView: c.anchor2View, targetView: c.anchor1View, sameContext: sameContext })
- : unique.push({ sourceView: c.anchor1View, targetView: c.anchor2View, sameContext: sameContext });
- }
+ unique.add({ sourceView: c.anchor1View, targetView: c.anchor2View, linkDoc: c.linkDoc });
+ unique.add({ sourceView: c.anchor2View, targetView: c.anchor1View, linkDoc: c.linkDoc });
}
});
- console.log("\n UNIQUE");
+ let uniqueList: JSX.Element[] = [];
unique.forEach(u => {
- console.log(StrCast(u.sourceView.Document.title), StrCast(u.targetView.Document.title), u.sameContext);
- });
-
- // console.log("\n");
-
- return unique.map(u => {
// TODO: make better key
let key = StrCast(u.sourceView.Document[Id]) + "-link-" + StrCast(u.targetView.Document[Id]) + "-" + Date.now() + Math.random();
let sourceIn = u.sourceView.props.ContainingCollectionView ? u.sourceView.props.ContainingCollectionView.props.Document === this.props.Document : false;
let targetIn = u.targetView.props.ContainingCollectionView ? u.targetView.props.ContainingCollectionView.props.Document === this.props.Document : false;
- let inContainer = u.sameContext ? sourceIn || targetIn : sourceIn;
+ let sameContext = u.sourceView.props.ContainingCollectionView === u.targetView.props.ContainingCollectionView;
+ let inContainer = sameContext ? sourceIn || targetIn : sourceIn;
+
if (inContainer) {
- // console.log("key", key, StrCast(u.sourceView.Document.title), StrCast(u.targetView.Document.title));
- return <CollectionFreeFormLinkView key={key} sourceView={u.sourceView} targetView={u.targetView} sameContext={u.sameContext} addDocTab={this.props.addDocTab} />;
- } else {
- return <div key={key}></div>;
+ // let alias = Doc.MakeAlias(proxy);
+ if (sameContext) {
+ uniqueList.push(<CollectionFreeFormLinkView key={key} sourceView={u.sourceView} targetView={u.targetView} />);
+ } else {
+ let proxyKey = Doc.AreProtosEqual(u.sourceView.Document, Cast(u.linkDoc.anchor1, Doc, new Doc)) ? "proxy1" : "proxy2";
+ let proxy = Cast(u.linkDoc[proxyKey], Doc, new Doc);
+
+ let context = u.targetView.props.ContainingCollectionView ? (" in the context of " + StrCast(u.targetView.props.ContainingCollectionView.props.Document.title)) : "";
+ let text = proxyKey + " link to " + StrCast(u.targetView.props.Document.title) + context;
+
+ let proxyProto = Doc.GetProto(proxy);
+ proxyProto.data = text;
+
+ this.props.addDocument(proxy, false);
+ uniqueList.push(<CollectionFreeFormLinkWithProxyView key={key} sourceView={u.sourceView} targetView={u.targetView}
+ proxyDoc={proxy} addDocTab={this.props.addDocTab} />);
+ }
}
});
+ return uniqueList;
}
render() {