UNPKG

7.1 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright Google LLC All Rights Reserved.
4 *
5 * Use of this source code is governed by an MIT-style license that can be
6 * found in the LICENSE file at https://angular.io/license
7 */
8import { Injectable, Inject, NgZone } from '@angular/core';
9import { DOCUMENT } from '@angular/common';
10import { ViewportRuler } from '@angular/cdk/scrolling';
11import { DragRef } from './drag-ref';
12import { DropListRef } from './drop-list-ref';
13import { DragDropRegistry } from './drag-drop-registry';
14import * as i0 from "@angular/core";
15import * as i1 from "@angular/cdk/scrolling";
16import * as i2 from "./drag-drop-registry";
17/** Default configuration to be used when creating a `DragRef`. */
18const DEFAULT_CONFIG = {
19 dragStartThreshold: 5,
20 pointerDirectionChangeThreshold: 5,
21};
22/**
23 * Service that allows for drag-and-drop functionality to be attached to DOM elements.
24 */
25class DragDrop {
26 constructor(_document, _ngZone, _viewportRuler, _dragDropRegistry) {
27 this._document = _document;
28 this._ngZone = _ngZone;
29 this._viewportRuler = _viewportRuler;
30 this._dragDropRegistry = _dragDropRegistry;
31 }
32 /**
33 * Turns an element into a draggable item.
34 * @param element Element to which to attach the dragging functionality.
35 * @param config Object used to configure the dragging behavior.
36 */
37 createDrag(element, config = DEFAULT_CONFIG) {
38 return new DragRef(element, config, this._document, this._ngZone, this._viewportRuler, this._dragDropRegistry);
39 }
40 /**
41 * Turns an element into a drop list.
42 * @param element Element to which to attach the drop list functionality.
43 */
44 createDropList(element) {
45 return new DropListRef(element, this._dragDropRegistry, this._document, this._ngZone, this._viewportRuler);
46 }
47 static { this.ɵfac = i0.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: DragDrop, deps: [{ token: DOCUMENT }, { token: i0.NgZone }, { token: i1.ViewportRuler }, { token: i2.DragDropRegistry }], target: i0.ɵɵFactoryTarget.Injectable }); }
48 static { this.ɵprov = i0.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: DragDrop, providedIn: 'root' }); }
49}
50export { DragDrop };
51i0.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "16.0.0", ngImport: i0, type: DragDrop, decorators: [{
52 type: Injectable,
53 args: [{ providedIn: 'root' }]
54 }], ctorParameters: function () { return [{ type: undefined, decorators: [{
55 type: Inject,
56 args: [DOCUMENT]
57 }] }, { type: i0.NgZone }, { type: i1.ViewportRuler }, { type: i2.DragDropRegistry }]; } });
58//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZHJhZy1kcm9wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9kcmFnLWRyb3AvZHJhZy1kcm9wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxVQUFVLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBYSxNQUFNLGVBQWUsQ0FBQztBQUNyRSxPQUFPLEVBQUMsUUFBUSxFQUFDLE1BQU0saUJBQWlCLENBQUM7QUFDekMsT0FBTyxFQUFDLGFBQWEsRUFBQyxNQUFNLHdCQUF3QixDQUFDO0FBQ3JELE9BQU8sRUFBQyxPQUFPLEVBQWdCLE1BQU0sWUFBWSxDQUFDO0FBQ2xELE9BQU8sRUFBQyxXQUFXLEVBQUMsTUFBTSxpQkFBaUIsQ0FBQztBQUM1QyxPQUFPLEVBQUMsZ0JBQWdCLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQzs7OztBQUV0RCxrRUFBa0U7QUFDbEUsTUFBTSxjQUFjLEdBQUc7SUFDckIsa0JBQWtCLEVBQUUsQ0FBQztJQUNyQiwrQkFBK0IsRUFBRSxDQUFDO0NBQ25DLENBQUM7QUFFRjs7R0FFRztBQUNILE1BQ2EsUUFBUTtJQUNuQixZQUM0QixTQUFjLEVBQ2hDLE9BQWUsRUFDZixjQUE2QixFQUM3QixpQkFBeUQ7UUFId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