aboutsummaryrefslogtreecommitdiff
path: root/src/client/documents/Documents.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/documents/Documents.ts')
-rw-r--r--src/client/documents/Documents.ts99
1 files changed, 80 insertions, 19 deletions
diff --git a/src/client/documents/Documents.ts b/src/client/documents/Documents.ts
index de6c5bc6a..df5c39562 100644
--- a/src/client/documents/Documents.ts
+++ b/src/client/documents/Documents.ts
@@ -25,7 +25,7 @@ import { OmitKeys } from "../../Utils";
import { ImageField, VideoField, AudioField, PdfField, WebField } from "../../new_fields/URLField";
import { HtmlField } from "../../new_fields/HtmlField";
import { List } from "../../new_fields/List";
-import { Cast, NumCast } from "../../new_fields/Types";
+import { Cast, NumCast, StrCast } from "../../new_fields/Types";
import { IconField } from "../../new_fields/IconField";
import { listSpec } from "../../new_fields/Schema";
import { DocServer } from "../DocServer";
@@ -34,6 +34,11 @@ import { dropActionType } from "../util/DragManager";
import { DateField } from "../../new_fields/DateField";
import { UndoManager } from "../util/UndoManager";
import { RouteStore } from "../../server/RouteStore";
+import { LinkManager } from "../util/LinkManager";
+import { LinkButtonBox } from "../views/nodes/LinkButtonBox";
+import { LinkButtonField, LinkButtonData } from "../../new_fields/LinkButtonField";
+import { DocumentManager } from "../util/DocumentManager";
+import { Id } from "../../new_fields/FieldSymbols";
var requestImageSize = require('request-image-size');
var path = require('path');
@@ -66,29 +71,74 @@ export interface DocumentOptions {
}
const delegateKeys = ["x", "y", "width", "height", "panX", "panY"];
+// export interface LinkData {
+// anchor1: Doc;
+// anchor1Page: number;
+// anchor1Tags: Array<{ tag: string, name: string, description: string }>;
+// anchor2: Doc;
+// anchor2Page: number;
+// anchor2Tags: Array<{ tag: string, name: string, description: string }>;
+// }
+
+// export interface TagData {
+// tag: string;
+// name: string;
+// description: string;
+// }
+
export namespace DocUtils {
- export function MakeLink(source: Doc, target: Doc, targetContext?: Doc, title: string = "", description: string = "", tags: string = "Default") {
- let protoSrc = source.proto ? source.proto : source;
- let protoTarg = target.proto ? target.proto : target;
+ // export function MakeLink(source: Doc, target: Doc, targetContext?: Doc, title: string = "", description: string = "", tags: string = "Default") {
+ // let protoSrc = source.proto ? source.proto : source;
+ // let protoTarg = target.proto ? target.proto : target;
+ export function MakeLink(source: Doc, target: Doc, targetContext?: Doc) {
+ if (LinkManager.Instance.doesLinkExist(source, target)) return;
+
UndoManager.RunInBatch(() => {
+
let linkDoc = Docs.TextDocument({ width: 100, height: 30, borderRounding: -1 });
let linkDocProto = Doc.GetProto(linkDoc);
- linkDocProto.title = title === "" ? source.title + " to " + target.title : title;
- linkDocProto.linkDescription = description;
- linkDocProto.linkTags = tags;
+ // linkDocProto.title = title === "" ? source.title + " to " + target.title : title;
+ // linkDocProto.linkDescription = description;
+ // linkDocProto.linkTags = tags;
+
+ linkDocProto.anchor1 = source;
+ linkDocProto.anchor1Page = source.curPage;
+ linkDocProto.anchor1Groups = new List<Doc>([]);
+ linkDocProto.anchor2 = target;
+ linkDocProto.anchor2Page = target.curPage;
+ linkDocProto.anchor2Groups = new List<Doc>([]);
+
+ linkDocProto.context = targetContext;
+
+ let sourceViews = DocumentManager.Instance.getDocumentViews(source);
+ let targetViews = DocumentManager.Instance.getDocumentViews(target);
+ sourceViews.forEach(sv => {
+ targetViews.forEach(tv => {
- linkDocProto.linkedTo = target;
- linkDocProto.linkedFrom = source;
- linkDocProto.linkedToPage = target.curPage;
- linkDocProto.linkedFromPage = source.curPage;
- linkDocProto.linkedToContext = targetContext;
+ // TODO: do only for when diff contexts
+ let proxy1 = Docs.LinkButtonDocument(
+ { sourceViewId: StrCast(sv.props.Document[Id]), targetViewId: StrCast(tv.props.Document[Id]) },
+ { width: 200, height: 100, borderRounding: 0 });
+ let proxy1Proto = Doc.GetProto(proxy1);
+ proxy1Proto.sourceViewId = StrCast(sv.props.Document[Id]);
+ proxy1Proto.targetViewId = StrCast(tv.props.Document[Id]);
+ proxy1Proto.isLinkButton = true;
+
+ let proxy2 = Docs.LinkButtonDocument(
+ { sourceViewId: StrCast(tv.props.Document[Id]), targetViewId: StrCast(sv.props.Document[Id]) },
+ { width: 200, height: 100, borderRounding: 0 });
+ let proxy2Proto = Doc.GetProto(proxy2);
+ proxy2Proto.sourceViewId = StrCast(tv.props.Document[Id]);
+ proxy2Proto.targetViewId = StrCast(sv.props.Document[Id]);
+ proxy2Proto.isLinkButton = true;
+
+ LinkManager.Instance.linkProxies.push(proxy1);
+ LinkManager.Instance.linkProxies.push(proxy2);
+ });
+ });
+
+ LinkManager.Instance.allLinks.push(linkDoc);
- let linkedFrom = Cast(protoTarg.linkedFromDocs, listSpec(Doc));
- let linkedTo = Cast(protoSrc.linkedToDocs, listSpec(Doc));
- !linkedFrom && (protoTarg.linkedFromDocs = linkedFrom = new List<Doc>());
- !linkedTo && (protoSrc.linkedToDocs = linkedTo = new List<Doc>());
- linkedFrom.push(linkDoc);
- linkedTo.push(linkDoc);
return linkDoc;
}, "make link");
}
@@ -107,6 +157,7 @@ export namespace Docs {
let audioProto: Doc;
let pdfProto: Doc;
let iconProto: Doc;
+ let linkProto: Doc;
const textProtoId = "textProto";
const histoProtoId = "histoProto";
const pdfProtoId = "pdfProto";
@@ -117,6 +168,7 @@ export namespace Docs {
const videoProtoId = "videoProto";
const audioProtoId = "audioProto";
const iconProtoId = "iconProto";
+ const linkProtoId = "linkProto";
export function initProtos(): Promise<void> {
return DocServer.GetRefFields([textProtoId, histoProtoId, collProtoId, imageProtoId, webProtoId, kvpProtoId, videoProtoId, audioProtoId, pdfProtoId, iconProtoId]).then(fields => {
@@ -130,6 +182,7 @@ export namespace Docs {
audioProto = fields[audioProtoId] as Doc || CreateAudioPrototype();
pdfProto = fields[pdfProtoId] as Doc || CreatePdfPrototype();
iconProto = fields[iconProtoId] as Doc || CreateIconPrototype();
+ linkProto = fields[linkProtoId] as Doc || CreateLinkPrototype();
});
}
@@ -162,6 +215,11 @@ export namespace Docs {
{ x: 0, y: 0, width: Number(MINIMIZED_ICON_SIZE), height: Number(MINIMIZED_ICON_SIZE) });
return iconProto;
}
+ function CreateLinkPrototype(): Doc {
+ let linkProto = setupPrototypeOptions(linkProtoId, "LINK_PROTO", LinkButtonBox.LayoutString(),
+ { x: 0, y: 0, width: 300 });
+ return linkProto;
+ }
function CreateTextPrototype(): Doc {
let textProto = setupPrototypeOptions(textProtoId, "TEXT_PROTO", FormattedTextBox.LayoutString(),
{ x: 0, y: 0, width: 300, backgroundColor: "#f1efeb" });
@@ -248,6 +306,9 @@ export namespace Docs {
export function IconDocument(icon: string, options: DocumentOptions = {}) {
return CreateInstance(iconProto, new IconField(icon), options);
}
+ export function LinkButtonDocument(data: LinkButtonData, options: DocumentOptions = {}) {
+ return CreateInstance(linkProto, new LinkButtonField(data), options);
+ }
export function PdfDocument(url: string, options: DocumentOptions = {}) {
return CreateInstance(pdfProto, new PdfField(new URL(url)), options);
}
@@ -363,7 +424,7 @@ export namespace Docs {
}
/*
-
+
this template requires an additional style setting on the collectionView-cont to make the layout relative
.collectionView-cont {