aboutsummaryrefslogtreecommitdiff
path: root/src/client/util/DragManager.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/client/util/DragManager.ts')
-rw-r--r--src/client/util/DragManager.ts38
1 files changed, 17 insertions, 21 deletions
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts
index 19f1f8d15..437fea0ea 100644
--- a/src/client/util/DragManager.ts
+++ b/src/client/util/DragManager.ts
@@ -13,7 +13,7 @@ import * as globalCssVariables from "../views/globalCssVariables.scss";
import { UndoManager } from "./UndoManager";
import { SnappingManager } from "./SnappingManager";
-export type dropActionType = "alias" | "copy" | "move" | "same" | "none" | undefined; // undefined = move, "same" = move but don't call removeDropProperties
+export type dropActionType = "alias" | "copy" | "move" | "same" | "proto" | "none" | undefined; // undefined = move, "same" = move but don't call removeDropProperties
export function SetupDrag(
_reference: React.RefObject<HTMLElement>,
docFunc: () => Doc | Promise<Doc> | undefined,
@@ -138,13 +138,13 @@ export namespace DragManager {
isSelectionMove?: boolean; // indicates that an explicitly selected Document is being dragged. this will suppress onDragStart scripts
}
export class LinkDragData {
- constructor(linkSourceDoc: Doc) {
- this.linkSourceDocument = linkSourceDoc;
+ constructor(dragDoc: Doc, linkSourceGetAnchor: () => Doc) {
+ this.dragDocument = dragDoc;
+ this.linkSourceGetAnchor = linkSourceGetAnchor;
}
- droppedDocuments: Doc[] = [];
- linkSourceDocument: Doc;
- dontClearTextBox?: boolean;
- linkDropCallback?: (data: { linkDocument: Doc }) => void;
+ dragDocument: Doc;
+ linkSourceGetAnchor: () => Doc;
+ linkSourceDoc?: Doc;
}
export class ColumnDragData {
constructor(colKey: SchemaHeaderField) {
@@ -154,23 +154,18 @@ export namespace DragManager {
}
// used by PDFs,Text,Image,Video,Web to conditionally (if the drop completes) create a text annotation when dragging the annotate button from the AnchorMenu when a text/region selection has been made.
// this is pretty clunky and should be rethought out using linkDrag or DocumentDrag
- export class AnchorAnnoDragData {
- constructor(dragDoc: Doc, annotationDocCreator: () => Doc, dropDocCreator: () => Doc) {
- this.dragDocument = dragDoc;
+ export class AnchorAnnoDragData extends LinkDragData {
+ constructor(dragDoc: Doc, linkSourceGetAnchor: () => Doc, dropDocCreator: (annotationOn: Doc | undefined) => Doc) {
+ super(dragDoc, linkSourceGetAnchor);
this.dropDocCreator = dropDocCreator;
- this.annotationDocCreator = annotationDocCreator;
this.offset = [0, 0];
}
- targetContext: Doc | undefined;
- dragDocument: Doc;
- annotationDocCreator: () => Doc;
- dropDocCreator: () => Doc;
+ linkSourceDoc?: Doc;
+ dropDocCreator: (annotationOn: Doc | undefined) => Doc;
dropDocument?: Doc;
- annotationDocument?: Doc;
offset: number[];
dropAction: dropActionType;
userDropAction: dropActionType;
- linkDropCallback?: (data: { linkDocument: Doc }) => void;
}
export function MakeDropTarget(
@@ -221,8 +216,9 @@ export namespace DragManager {
docDragData.droppedDocuments =
dragData.draggedDocuments.map(d => !dragData.isSelectionMove && !dragData.userDropAction && ScriptCast(d.onDragStart) ? addAudioTag(ScriptCast(d.onDragStart).script.run({ this: d }).result) :
docDragData.dropAction === "alias" ? Doc.MakeAlias(d) :
- docDragData.dropAction === "copy" ? Doc.MakeClone(d) : d);
- docDragData.dropAction !== "same" && docDragData.droppedDocuments.forEach((drop: Doc, i: number) => {
+ docDragData.dropAction === "proto" ? Doc.GetProto(d) :
+ docDragData.dropAction === "copy" ? Doc.MakeClone(d) : d);
+ !["same", "proto"].includes(docDragData.dropAction as any) && docDragData.droppedDocuments.forEach((drop: Doc, i: number) => {
const dragProps = Cast(dragData.draggedDocuments[i].removeDropProperties, listSpec("string"), []);
const remProps = (dragData?.removeDropProperties || []).concat(Array.from(dragProps));
remProps.map(prop => drop[prop] = undefined);
@@ -257,8 +253,8 @@ export namespace DragManager {
}
// drags a linker button and creates a link on drop
- export function StartLinkDrag(ele: HTMLElement, sourceDoc: Doc, downX: number, downY: number, options?: DragOptions) {
- StartDrag([ele], new DragManager.LinkDragData(sourceDoc), downX, downY, options);
+ export function StartLinkDrag(ele: HTMLElement, sourceDoc: Doc, sourceDocGetAnchor: undefined | (() => Doc), downX: number, downY: number, options?: DragOptions) {
+ StartDrag([ele], new DragManager.LinkDragData(sourceDoc, () => sourceDocGetAnchor?.() ?? sourceDoc), downX, downY, options);
}
// drags a column from a schema view