aboutsummaryrefslogtreecommitdiff
path: root/src/client/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util')
-rw-r--r--src/client/util/DocumentManager.ts46
-rw-r--r--src/client/util/DragManager.ts47
2 files changed, 52 insertions, 41 deletions
diff --git a/src/client/util/DocumentManager.ts b/src/client/util/DocumentManager.ts
index 325f4894d..c4cb6721a 100644
--- a/src/client/util/DocumentManager.ts
+++ b/src/client/util/DocumentManager.ts
@@ -85,51 +85,25 @@ export class DocumentManager {
@computed
public get LinkedDocumentViews() {
- // console.log("linked");
- // let docs = DocListCast(CurrentUserUtils.UserDocument.data);
- // docs.forEach(d => {
- // console.log("d", StrCast(d.title));
-
- // });
-
- // let d = Cast(CurrentUserUtils.UserDocument.activeWorkspace, Doc, new Doc);
- // console.log("DOC", StrCast(d.title));
-
-
-
- let linked = DocumentManager.Instance.DocumentViews.filter(dv => dv.isSelected() || BoolCast(dv.props.Document.libraryBrush, false)).reduce((pairs, dv) => {
- // console.log("FINDING LINKED DVs FOR", StrCast(dv.props.Document.title));
+ return DocumentManager.Instance.DocumentViews.filter(dv => dv.isSelected() || BoolCast(dv.props.Document.libraryBrush, false)).reduce((pairs, dv) => {
let linksList = LinkManager.Instance.findAllRelatedLinks(dv.props.Document);
+ // let linksList = DocListCast(dv.props.Document.linkedToDocs);
if (linksList && linksList.length) {
pairs.push(...linksList.reduce((pairs, link) => {
- // if (link) {
- let destination = LinkManager.Instance.findOppositeAnchor(link, dv.props.Document);
- // console.log("FINDING FOR", StrCast(dv.Document.title), StrCast(destination.title));
-
- if (destination) {
- let dvs = DocumentManager.Instance.getDocumentViews(destination);
- if (dvs.length > 0) {
- dvs.map(docView1 => {
- // console.log("PUSHING LINK BETWEEN", StrCast(dv.props.Document.title), StrCast(docView1.props.Document.title));
- // TODO: if any docviews are not in the same context, draw a proxy
- // let sameContent = dv.props.ContainingCollectionView === docView1.props.ContainingCollectionView;
- pairs.push({ anchor1View: dv, anchor2View: docView1, linkDoc: link });
- // console.log("PUSHED", StrCast(dv.props.Document.title), StrCast(docView1.Document.title));
- });
- } else {
- let dv = DocumentManager.Instance.getDocumentView(destination);
- dv ? console.log(StrCast(dv.props.Document.title)) : console.log("cant find");
- }
+ if (link) {
+ let linkToDoc = LinkManager.Instance.findOppositeAnchor(link, dv.props.Document);
+ // console.log("FOUND ", DocumentManager.Instance.getDocumentViews(linkToDoc).length, "DOCVIEWS FOR", StrCast(linkToDoc.title), "WITH SOURCE", StrCast(dv.props.Document.title));
+ DocumentManager.Instance.getDocumentViews(linkToDoc).map(docView1 =>
+ pairs.push({ a: dv, b: docView1, l: link }));
}
- // }
return pairs;
- }, [] as { anchor1View: DocumentView, anchor2View: DocumentView, linkDoc: Doc }[]));
+ }, [] as { a: DocumentView, b: DocumentView, l: Doc }[]));
}
return pairs;
- }, [] as { anchor1View: DocumentView, anchor2View: DocumentView, linkDoc: Doc }[]);
- return linked;
+ }, [] as { a: DocumentView, b: DocumentView, l: Doc }[]);
}
+
@undoBatch
public jumpToDocument = async (docDelegate: Doc, forceDockFunc: boolean = false, dockFunc?: (doc: Doc) => void, linkPage?: number, docContext?: Doc): Promise<void> => {
let doc = Doc.GetProto(docDelegate);
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 11530ef09..2abcff4f7 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -48,12 +48,10 @@ 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]);
dragData.dropAction = "alias" as dropActionType;
- DragManager.StartDocumentDrag([dragEle], dragData, x, y, {
+ DragManager.StartLinkedDocumentDrag([dragEle], dragData, x, y, {
handlers: {
dragComplete: action(emptyFunction),
},
@@ -83,11 +81,21 @@ 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.dropAction = "alias" as dropActionType;
// dragData.moveDocument = (document, targetCollection, addDocument) => {
// return false;
// };
- DragManager.StartDocumentDrag([dragEle], dragData, x, y, {
+
+ // runInAction(() => StartDragFunctions.map(func => func()));
+ // (eles, dragData, downX, downY, options,
+ // (dropData: { [id: string]: any }) => {
+ // (dropData.droppedDocuments = dragData.userDropAction === "alias" || (!dragData.userDropAction && dragData.dropAction === "alias") ?
+ // dragData.draggedDocuments.map(d => Doc.MakeAlias(d)) :
+ // dragData.userDropAction === "copy" || (!dragData.userDropAction && dragData.dropAction === "copy") ?
+ // dragData.draggedDocuments.map(d => Doc.MakeCopy(d, true)) :
+ // dragData.draggedDocuments
+ // );
+ // });
+ DragManager.StartLinkedDocumentDrag([dragEle], dragData, x, y, {
handlers: {
dragComplete: action(emptyFunction),
},
@@ -215,6 +223,35 @@ export namespace DragManager {
});
}
+ export function StartLinkedDocumentDrag(eles: HTMLElement[], dragData: DocumentDragData, downX: number, downY: number, options?: DragOptions) {
+
+ runInAction(() => StartDragFunctions.map(func => func()));
+ StartDrag(eles, dragData, downX, downY, options,
+ (dropData: { [id: string]: any }) => {
+ dropData.droppedDocuments = dragData.draggedDocuments.map(d => {
+ let dv = DocumentManager.Instance.getDocumentView(d);
+ // console.log("DRAG", StrCast(d.title));
+
+ if (dv) {
+ console.log("DRAG", StrCast(d.title), "has view");
+ if (dv.props.ContainingCollectionView === SelectionManager.SelectedDocuments()[0].props.ContainingCollectionView) {
+ console.log("DRAG", StrCast(d.title), "same");
+ return d;
+ } else {
+ console.log("DRAG", StrCast(d.title), "diff");
+ return Doc.MakeAlias(d);
+ }
+ } else {
+ console.log("DRAG", StrCast(d.title), "has no view");
+ return Doc.MakeAlias(d);
+ }
+ // return (dv && dv.props.ContainingCollectionView !== SelectionManager.SelectedDocuments()[0].props.ContainingCollectionView) || !dv ?
+ // Doc.MakeAlias(d) : d;
+ });
+
+ });
+ }
+
export function StartAnnotationDrag(eles: HTMLElement[], dragData: AnnotationDragData, downX: number, downY: number, options?: DragOptions) {
StartDrag(eles, dragData, downX, downY, options);
}