diff options
| author | Sam Wilkins <samwilkins333@gmail.com> | 2019-11-19 11:28:49 -0500 | 
|---|---|---|
| committer | Sam Wilkins <samwilkins333@gmail.com> | 2019-11-19 11:28:49 -0500 | 
| commit | 3f86ea5556ab7a1fc13cd9c74ef4305f2f5cd778 (patch) | |
| tree | 4d13f3401ecc80fb5bce22d2a3382545102fda7f /src/client/util/DragManager.ts | |
| parent | 611bb858265b6667f2b7db858d183cea16f273aa (diff) | |
| parent | d259cf7b16e64794bc12ae420f9b512a75eee46c (diff) | |
merged with master
Diffstat (limited to 'src/client/util/DragManager.ts')
| -rw-r--r-- | src/client/util/DragManager.ts | 34 | 
1 files changed, 13 insertions, 21 deletions
diff --git a/src/client/util/DragManager.ts b/src/client/util/DragManager.ts index 2c316ccdf..bbc29585c 100644 --- a/src/client/util/DragManager.ts +++ b/src/client/util/DragManager.ts @@ -14,6 +14,8 @@ import { ScriptField } from "../../new_fields/ScriptField";  import { List } from "../../new_fields/List";  import { PrefetchProxy } from "../../new_fields/Proxy";  import { listSpec } from "../../new_fields/Schema"; +import { Scripting } from "./Scripting"; +import { convertDropDataToButtons } from "./DropConverter";  export type dropActionType = "alias" | "copy" | undefined;  export function SetupDrag( @@ -87,12 +89,12 @@ export async function DragLinkAsDocument(dragEle: HTMLElement, x: number, y: num      }  } -export async function DragLinksAsDocuments(dragEle: HTMLElement, x: number, y: number, sourceDoc: Doc) { +export async function DragLinksAsDocuments(dragEle: HTMLElement, x: number, y: number, sourceDoc: Doc, singleLink?: Doc) {      let srcTarg = sourceDoc.proto;      let draggedDocs: Doc[] = [];      if (srcTarg) { -        let linkDocs = LinkManager.Instance.getAllRelatedLinks(srcTarg); +        let linkDocs = singleLink ? [singleLink] : LinkManager.Instance.getAllRelatedLinks(srcTarg);          if (linkDocs) {              draggedDocs = linkDocs.map(link => {                  let opp = LinkManager.Instance.getOppositeAnchor(link, sourceDoc); @@ -211,7 +213,9 @@ export namespace DragManager {          offset: number[];          dropAction: dropActionType;          userDropAction: dropActionType; +        embedDoc?: boolean;          moveDocument?: MoveFunction; +        isSelectionMove?: boolean; // indicates that an explicitly selected Document is being dragged.  this will suppress onDragStart scripts          applyAsTemplate?: boolean;          [id: string]: any;      } @@ -234,13 +238,13 @@ export namespace DragManager {      export let StartDragFunctions: (() => void)[] = []; -    export async function StartDocumentDrag(eles: HTMLElement[], dragData: DocumentDragData, downX: number, downY: number, options?: DragOptions) { +    export function StartDocumentDrag(eles: HTMLElement[], dragData: DocumentDragData, downX: number, downY: number, options?: DragOptions) {          runInAction(() => StartDragFunctions.map(func => func())); -        await dragData.draggedDocuments.map(d => d.dragFactory); +        dragData.draggedDocuments.map(d => d.dragFactory); // does this help?  trying to make sure the dragFactory Doc is loaded          StartDrag(eles, dragData, downX, downY, options, options && options.finishDrag ? options.finishDrag :              (dropData: { [id: string]: any }) => {                  (dropData.droppedDocuments = -                    dragData.draggedDocuments.map(d => ScriptCast(d.onDragStart) ? ScriptCast(d.onDragStart).script.run({ this: d }).result : +                    dragData.draggedDocuments.map(d => !dragData.isSelectionMove && !dragData.userDropAction && ScriptCast(d.onDragStart) ? ScriptCast(d.onDragStart).script.run({ this: d }).result :                          dragData.userDropAction === "alias" || (!dragData.userDropAction && dragData.dropAction === "alias") ? Doc.MakeAlias(d) :                              dragData.userDropAction === "copy" || (!dragData.userDropAction && dragData.dropAction === "copy") ? Doc.MakeCopy(d, true) : d)                  ); @@ -304,16 +308,6 @@ export namespace DragManager {          [id: string]: any;      } -    export class EmbedDragData { -        constructor(embeddableSourceDoc: Doc) { -            this.embeddableSourceDoc = embeddableSourceDoc; -            this.urlField = embeddableSourceDoc.data instanceof URLField ? embeddableSourceDoc.data : undefined; -        } -        embeddableSourceDoc: Doc; -        urlField?: URLField; -        [id: string]: any; -    } -      // for column dragging in schema view      export class ColumnDragData {          constructor(colKey: SchemaHeaderField) { @@ -327,10 +321,6 @@ export namespace DragManager {          StartDrag([ele], dragData, downX, downY, options);      } -    export function StartEmbedDrag(ele: HTMLElement, dragData: EmbedDragData, downX: number, downY: number, options?: DragOptions) { -        StartDrag([ele], dragData, downX, downY, options); -    } -      export function StartColumnDrag(ele: HTMLElement, dragData: ColumnDragData, downX: number, downY: number, options?: DragOptions) {          StartDrag([ele], dragData, downX, downY, options);      } @@ -426,16 +416,17 @@ export namespace DragManager {          const moveHandler = (e: PointerEvent) => {              e.preventDefault(); // required or dragging text menu link item ends up dragging the link button as native drag/drop              if (dragData instanceof DocumentDragData) { -                dragData.userDropAction = e.ctrlKey || e.altKey ? "alias" : undefined; +                dragData.userDropAction = e.ctrlKey ? "alias" : undefined;              }              if (((options && !options.withoutShiftDrag) || !options) && e.shiftKey && CollectionDockingView.Instance) {                  AbortDrag(); +                finishDrag && finishDrag(dragData);                  CollectionDockingView.Instance.StartOtherDrag({                      pageX: e.pageX,                      pageY: e.pageY,                      preventDefault: emptyFunction,                      button: 0 -                }, docs); +                }, dragData.droppedDocuments);              }              //TODO: Why can't we use e.movementX and e.movementY?              let moveX = e.pageX - lastX; @@ -508,3 +499,4 @@ export namespace DragManager {          }      }  } +Scripting.addGlobal(function convertToButtons(dragData: any) { convertDropDataToButtons(dragData as DragManager.DocumentDragData); });  | 
