import { Container, DisplayObject, MouseEvent, Matrix2D } from '@thegraid/easeljs-module'; import { XY } from '@thegraid/common-lib'; declare module '@thegraid/easeljs-module' { interface DisplayObject { DragData?: DragData; doNotDrag: boolean; } } /** Info about the current drag operation, shared between pressmove(s) and pressup. * * drag context and scale info for isScaleCont */ export interface DragInfo { first: boolean; dropCont?: Container; srcCont: Container; dropNdx: number; event: MouseEvent; stageX0: number; stageY0: number; dxy: XY; objx: number; objy: number; scalmat: Matrix2D; targetC: Container; targetD: DisplayObject; rotation: number; } type OnHandler = Function; type DnDFunc = (c: DisplayObject | Container, ctx?: DragInfo) => void; /** attached to each dragable DisplayObject. scope.dragfunc()/dropfunc() * * [dragInfo is set while dispObj is being dragged] * [also: dragCont.getChild(1) === dispObj] */ type DragData = { target: DisplayObject; scope: Object; dragfunc: DnDFunc; dropfunc: DnDFunc; dragInfo?: DragInfo; pressmove?: OnHandler; pressup?: OnHandler; stagemousemove?: OnHandler; clickToDrag?: boolean; isScaleCont?: boolean; dragStopped?: boolean; }; /** * expect a singleton instance to control drag/drop on a single ScalableContainer */ export declare class Dragger { /** @param parent for this dragger.dragCont */ constructor(parent: Container); /** Info about the current drag operation, shared between pressmove(s) and pressup. */ dragCont: Container; /** * Make the singleton dragCont for this Dragger * @param parent the createjs Stage, unless you know better */ makeDragCont(parent: Container): void; /** * Move obj to dragCont and * compose initial DragInfo for pressmove: { first: true, srcCont, dxy, targetD, ... } * * dragCont.addChild(obj); dragCont.parent.setChildIndex(dragCont, numChildren-1) * @param event pressmove MouseEvent (for stageXY & localXY) * @param obj e.currentTarget (the pressmove Listener object) * @returns DragInfo with srcCont, dxy, etc */ newDragInfo(event: MouseEvent, obj: DisplayObject, data: DragData): DragInfo; /** handle 'pressmove' event on a 'dragable' DisplayObject target */ pressmove(event: MouseEvent, data: DragData): void; pressup(event: MouseEvent, data: DragData): void; /** makeDragable will initialize DragData */ getDragData(dispObj: DisplayObject): DragData; setDragData(dispObj: DisplayObject, data?: DragData): DragData; /** * addEventListeners for pressmove/pressup (stagemousedown/up and stagemousemove) * Drag dispObj on stage.dragCont; and drop (addChild) on the orig OR new parent. * @param target the object to become dragable * @param scope object to use a 'this' when calling dragfunc, dropfunc (else dispObj.parent) * @param dragfunc? f(dispObj|Container, dragInfo) Default: lastCont.addChild(obj) * @param dropfunc? f(dispObj|Container, dragInfo) * @param isScaleCont? set true if dispObj is the ScaleableContainer (a parent of this Dragger) */ makeDragable(target: DisplayObject, scope?: Object, dragfunc?: DnDFunc, dropfunc?: DnDFunc, isScaleCont?: boolean): this; /** * Clicking on object will initiate dragging; click again to drop. * @param dispObj the dragable object * @param value [true] to enable clickToDrag, false to disable; */ clickToDrag(dispObj: DisplayObject, value?: boolean): void; /** * queue a pressup event with nativeEvent = { button: 0} * * @param target * @param ctd [true] initiate dragging of target * @returns target.DragData */ dispatchPressup(target: DisplayObject, ctd?: boolean): DragData; /** * like dispatchPressup(), but invokes this.pressup() as method * @param target * @param ctd [true] initiate clickToDrag * @returns target.DragData */ invokePressup(target: DisplayObject, ctd?: boolean): DragData; /** Move [dragable] target to mouse as if clickToDrag at {x,y}. */ dragTarget(target: DisplayObject, dxy?: XY): void; /** * Release drag target from mouse, ignore pressmove events on target until pressup. * If clickToDrag(target) is dragging, invoke pressup->dropFunc; else wait for actual pressup. */ stopDrag(): void; /** prevent DisplayObject from being dragable * @deprecated use stopDragable() or stopDrag() */ notDragable(dispObj: DisplayObject): void; /** remove pressmove and pressup listenerf from dispObj. */ stopDragable(dispObj: DisplayObject): DragData; } export {};