dragAndDropService.d.ts 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. import { BeanStub } from "../context/beanStub";
  2. import { Column } from "../entities/column";
  3. import { ColumnApi } from "../columnController/columnApi";
  4. import { GridApi } from "../gridApi";
  5. import { RowDropZoneParams } from "../gridPanel/rowDragFeature";
  6. import { RowNode } from "../entities/rowNode";
  7. export interface DragItem {
  8. /**
  9. * When dragging a row, this contains the row node being dragged
  10. * When dragging multiple rows, this contains the row that started the drag.
  11. */
  12. rowNode?: RowNode;
  13. /** When dragging multiple rows, this contains all rows being dragged */
  14. rowNodes?: RowNode[];
  15. /** When dragging columns, this contains the columns being dragged */
  16. columns?: Column[];
  17. /** When dragging columns, this contains the visible state of the columns */
  18. visibleState?: {
  19. [key: string]: boolean;
  20. };
  21. }
  22. export declare enum DragSourceType {
  23. ToolPanel = 0,
  24. HeaderCell = 1,
  25. RowDrag = 2,
  26. ChartPanel = 3
  27. }
  28. export interface DragSource {
  29. /** The type of the drag source, used by the drop target to know where the drag originated from. */
  30. type: DragSourceType;
  31. /** Element which, when dragged, will kick off the DnD process */
  32. eElement: HTMLElement;
  33. /** If eElement is dragged, then the dragItem is the object that gets passed around. */
  34. getDragItem: () => DragItem;
  35. /** This name appears in the ghost icon when dragging */
  36. dragItemName: string | (() => string) | null;
  37. /** Icon to show when not over a drop zone */
  38. defaultIconName?: string;
  39. /** The drop target associated with this dragSource. When dragging starts, this target does not get an
  40. * onDragEnter event. */
  41. dragSourceDropTarget?: DropTarget;
  42. /** After how many pixels of dragging should the drag operation start. Default is 4. */
  43. dragStartPixels?: number;
  44. /** Callback for drag started */
  45. onDragStarted?: () => void;
  46. /** Callback for drag stopped */
  47. onDragStopped?: () => void;
  48. }
  49. export interface DropTarget {
  50. /** The main container that will get the drop. */
  51. getContainer(): HTMLElement;
  52. /** If any secondary containers. For example when moving columns in ag-Grid, we listen for drops
  53. * in the header as well as the body (main rows and pinned rows) of the grid. */
  54. getSecondaryContainers?(): HTMLElement[];
  55. /** Icon to show when drag is over */
  56. getIconName?(): string;
  57. isInterestedIn(type: DragSourceType): boolean;
  58. /** Callback for when drag enters */
  59. onDragEnter?(params: DraggingEvent): void;
  60. /** Callback for when drag leaves */
  61. onDragLeave?(params: DraggingEvent): void;
  62. /** Callback for when dragging */
  63. onDragging?(params: DraggingEvent): void;
  64. /** Callback for when drag stops */
  65. onDragStop?(params: DraggingEvent): void;
  66. external?: boolean;
  67. }
  68. export declare enum VerticalDirection {
  69. Up = 0,
  70. Down = 1
  71. }
  72. export declare enum HorizontalDirection {
  73. Left = 0,
  74. Right = 1
  75. }
  76. export interface DraggingEvent {
  77. event: MouseEvent;
  78. x: number;
  79. y: number;
  80. vDirection: VerticalDirection;
  81. hDirection: HorizontalDirection;
  82. dragSource: DragSource;
  83. dragItem: DragItem;
  84. fromNudge: boolean;
  85. api: GridApi;
  86. columnApi: ColumnApi;
  87. dropZoneTarget: HTMLElement;
  88. }
  89. export declare class DragAndDropService extends BeanStub {
  90. private gridOptionsWrapper;
  91. private dragService;
  92. private environment;
  93. private columnApi;
  94. private gridApi;
  95. static ICON_PINNED: string;
  96. static ICON_MOVE: string;
  97. static ICON_LEFT: string;
  98. static ICON_RIGHT: string;
  99. static ICON_GROUP: string;
  100. static ICON_AGGREGATE: string;
  101. static ICON_PIVOT: string;
  102. static ICON_NOT_ALLOWED: string;
  103. static ICON_HIDE: string;
  104. static GHOST_TEMPLATE: string;
  105. private dragSourceAndParamsList;
  106. private dragItem;
  107. private eventLastTime;
  108. private dragSource;
  109. private dragging;
  110. private eGhost;
  111. private eGhostParent;
  112. private eGhostIcon;
  113. private dropTargets;
  114. private lastDropTarget;
  115. private ePinnedIcon;
  116. private eHideIcon;
  117. private eMoveIcon;
  118. private eLeftIcon;
  119. private eRightIcon;
  120. private eGroupIcon;
  121. private eAggregateIcon;
  122. private ePivotIcon;
  123. private eDropNotAllowedIcon;
  124. private init;
  125. addDragSource(dragSource: DragSource, allowTouch?: boolean): void;
  126. removeDragSource(dragSource: DragSource): void;
  127. private clearDragSourceParamsList;
  128. nudge(): void;
  129. private onDragStart;
  130. private onDragStop;
  131. private onDragging;
  132. private enterDragTargetIfExists;
  133. private leaveLastTargetIfExists;
  134. private getAllContainersFromDropTarget;
  135. private isMouseOnDropTarget;
  136. addDropTarget(dropTarget: DropTarget): void;
  137. removeDropTarget(dropTarget: DropTarget): void;
  138. hasExternalDropZones(): boolean;
  139. findExternalZone(params: RowDropZoneParams): DropTarget;
  140. getHorizontalDirection(event: MouseEvent): HorizontalDirection;
  141. getVerticalDirection(event: MouseEvent): VerticalDirection;
  142. createDropTargetEvent(dropTarget: DropTarget, event: MouseEvent, hDirection: HorizontalDirection, vDirection: VerticalDirection, fromNudge: boolean): DraggingEvent;
  143. private positionGhost;
  144. private removeGhost;
  145. private createGhost;
  146. setGhostIcon(iconName: string, shake?: boolean): void;
  147. }