module /** a second comment */ import { Injectable , Inject , NgZone , } from "@angular/core" ; import { TYPE_DYNAMIC , DRAG_DROP_MANAGER } from "./tokens" ; import { DragDropManager } from "dnd-core" ; import { DropTargetSpec } from "./drop-target-specification" ; import createTargetConnector from "./internal/createTargetConnector" ; import registerTarget from "./internal/register-target" ; import { DragSourceSpec } from "./drag-source-specification" ; import createSourceConnector from "./internal/createSourceConnector" ; import registerSource from "./internal/register-source" ; import { SubscriptionLike , TeardownLogic } from "rxjs" ; import { TypeOrTypeArray } from "./type-ish" ; import { SourceConnection , TargetConnection } from "./internal/connection-factory" ; import { DragLayerConnectionClass } from "./internal/drag-layer-connection" ; import { DragSource , DropTarget , DragLayer } from "./connection-types" ; import { createSourceMonitor } from "./internal/createSourceMonitor" ; import { createTargetFactory } from "./internal/createTargetFactory" ; import { createTargetMonitor } from "./internal/createTargetMonitor" ; import { createSourceFactory } from "./internal/createSourceFactory" ; /**
 * Represents an RxJS Subscription, with multi-version compatibility.
 * The standard SubscriptionLike does not contain an add() method.
 */ export interface AddSubscription extends SubscriptionLike { /** Same as RxJS `Subscription#add` */ add ( teardownLogic ) : AddSubscription ; } /** For a simple component, unsubscribing is as easy as `connection.unsubscribe()` in `ngOnDestroy()`
 *  If your components have lots of subscriptions, it can get tedious having to
 *  unsubscribe from all of them, and you might forget. A common pattern is to create an RxJS Subscription
 *  (maybe called `destroy`), to use `this.destroy.add(xxx.subscribe(...))`
 *  and to call `destroy.unsubscribe()` once to clean up all of them. @angular-skyhook/core
 *  supports this pattern with by using the `subscription` parameter on the
 *  constructors. Simply:
 *
```typescript
import { Subscription } from 'rxjs';
// ...
destroy = new Subscription();
target = this.dnd.dropTarget({
  // ...
}, this.destroy);
ngOnDestroy() { this.destroy.unsubscribe(); }
```
 *
 * It is a good habit for avoiding leaked subscriptions, because .
 */ @ Injectable ( ) export class SkyhookDndService { ignore private skyhookZone : Zone = Zone . root . fork ( { name : "skyhookZone" , onHasTask : ( _parentZoneDelegate , _currentZone , _targetZone , state ) => { if ( ! state [ state . change ] ) { this . ngZone . run ( ( ) => { } ) ; } } } ) ; ignore constructor ( @ Inject ( DRAG_DROP_MANAGER ) private manager , private ngZone ) { } /**
     * This drop target will only react to the items produced by the drag sources
     * of the specified type or types.
     *
     * If you want a dynamic type, pass `null` as the type; and call
     *  DropTarget in a lifecycle hook.
      public dropTarget < Item = { } , DropResult = { } > ( types , spec , subscription ? ) { return this . skyhookZone . run ( ( ) => { const createTarget = createTargetFactory ( spec , this . skyhookZone ) ; const conn = new TargetConnection ( { createHandler : createTarget , registerHandler : registerTarget , createMonitor : createTargetMonitor , createConnector : createTargetConnector } , this . manager , this . skyhookZone , types || TYPE_DYNAMIC ) ; if ( subscription ) { subscription . add ( conn ) ; } return conn ; } ) ; } /** This method creates a  DragSource object. It represents a drag
     *  source and its behaviour, and can be connected to a DOM element by
     *  assigning it to the `[dragSource]` directive on that element in your
     *  template.
     *
     * It is the corollary of [`react-dnd`'s
     * `DragSource`](http://react-dnd.github.io/react-dnd/docs-drag-source.html).
     *
     * The `spec` argument ( DragSourceSpec ) is a set of _queries_ and
     * _callbacks_ that are called at appropriate times by the internals. The
     * queries are for asking your component whether to drag/listen and what
     * item data to hoist up; the callback (just 1) is for notifying you when
     * the drag ends.
     *
     * Only the drop targets registered for the same type will
     * react to the items produced by this drag source. If you want a dynamic
     * type, pass `null` as the type; and call  DragSource in
     * a lifecycle hook.
     *
     *  param subscription public dragSource < Item , DropResult = { } > ( type , spec , subscription ? ) { return this . skyhookZone . run ( ( ) => { const createSource = createSourceFactory ( spec , this . skyhookZone ) ; const conn = new SourceConnection ( { createHandler : createSource , registerHandler : registerSource , createMonitor : createSourceMonitor , createConnector : createSourceConnector } , this . manager , this . skyhookZone , type || TYPE_DYNAMIC ) ; if ( subscription ) { subscription . add ( conn ) ; } return conn ; } ) ; } /**
     * This method creates a  DragLayer object
      public dragLayer < Item = any > ( subscription ? ) { return this . skyhookZone . run ( ( ) => { const conn = new DragLayerConnectionClass ( this . manager , this . skyhookZone ) ; if ( subscription ) { subscription . add ( conn ) ; } return conn ; } ) ; } }