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 | */
|
---|
8 | import { Injectable, Inject, NgZone } from '@angular/core';
|
---|
9 | import { DOCUMENT } from '@angular/common';
|
---|
10 | import { ViewportRuler } from '@angular/cdk/scrolling';
|
---|
11 | import { DragRef } from './drag-ref';
|
---|
12 | import { DropListRef } from './drop-list-ref';
|
---|
13 | import { DragDropRegistry } from './drag-drop-registry';
|
---|
14 | import * as i0 from "@angular/core";
|
---|
15 | import * as i1 from "@angular/common";
|
---|
16 | import * as i2 from "@angular/cdk/scrolling";
|
---|
17 | import * as i3 from "./drag-drop-registry";
|
---|
18 | /** Default configuration to be used when creating a `DragRef`. */
|
---|
19 | const DEFAULT_CONFIG = {
|
---|
20 | dragStartThreshold: 5,
|
---|
21 | pointerDirectionChangeThreshold: 5
|
---|
22 | };
|
---|
23 | /**
|
---|
24 | * Service that allows for drag-and-drop functionality to be attached to DOM elements.
|
---|
25 | */
|
---|
26 | export class DragDrop {
|
---|
27 | constructor(_document, _ngZone, _viewportRuler, _dragDropRegistry) {
|
---|
28 | this._document = _document;
|
---|
29 | this._ngZone = _ngZone;
|
---|
30 | this._viewportRuler = _viewportRuler;
|
---|
31 | this._dragDropRegistry = _dragDropRegistry;
|
---|
32 | }
|
---|
33 | /**
|
---|
34 | * Turns an element into a draggable item.
|
---|
35 | * @param element Element to which to attach the dragging functionality.
|
---|
36 | * @param config Object used to configure the dragging behavior.
|
---|
37 | */
|
---|
38 | createDrag(element, config = DEFAULT_CONFIG) {
|
---|
39 | return new DragRef(element, config, this._document, this._ngZone, this._viewportRuler, this._dragDropRegistry);
|
---|
40 | }
|
---|
41 | /**
|
---|
42 | * Turns an element into a drop list.
|
---|
43 | * @param element Element to which to attach the drop list functionality.
|
---|
44 | */
|
---|
45 | createDropList(element) {
|
---|
46 | return new DropListRef(element, this._dragDropRegistry, this._document, this._ngZone, this._viewportRuler);
|
---|
47 | }
|
---|
48 | }
|
---|
49 | DragDrop.ɵprov = i0.ɵɵdefineInjectable({ factory: function DragDrop_Factory() { return new DragDrop(i0.ɵɵinject(i1.DOCUMENT), i0.ɵɵinject(i0.NgZone), i0.ɵɵinject(i2.ViewportRuler), i0.ɵɵinject(i3.DragDropRegistry)); }, token: DragDrop, providedIn: "root" });
|
---|
50 | DragDrop.decorators = [
|
---|
51 | { type: Injectable, args: [{ providedIn: 'root' },] }
|
---|
52 | ];
|
---|
53 | DragDrop.ctorParameters = () => [
|
---|
54 | { type: undefined, decorators: [{ type: Inject, args: [DOCUMENT,] }] },
|
---|
55 | { type: NgZone },
|
---|
56 | { type: ViewportRuler },
|
---|
57 | { type: DragDropRegistry }
|
---|
58 | ];
|
---|
59 | //# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiZHJhZy1kcm9wLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vLi4vLi4vLi4vLi4vc3JjL2Nkay9kcmFnLWRyb3AvZHJhZy1kcm9wLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBOzs7Ozs7R0FNRztBQUVILE9BQU8sRUFBQyxVQUFVLEVBQUUsTUFBTSxFQUFFLE1BQU0sRUFBYSxNQUFNLGVBQWUsQ0FBQztBQUNyRSxPQUFPLEVBQUMsUUFBUSxFQUFDLE1BQU0saUJBQWlCLENBQUM7QUFDekMsT0FBTyxFQUFDLGFBQWEsRUFBQyxNQUFNLHdCQUF3QixDQUFDO0FBQ3JELE9BQU8sRUFBQyxPQUFPLEVBQWdCLE1BQU0sWUFBWSxDQUFDO0FBQ2xELE9BQU8sRUFBQyxXQUFXLEVBQUMsTUFBTSxpQkFBaUIsQ0FBQztBQUM1QyxPQUFPLEVBQUMsZ0JBQWdCLEVBQUMsTUFBTSxzQkFBc0IsQ0FBQzs7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