UNPKG

@duoduo-oba/ng-devui

Version:

DevUI components based on Angular

1,434 lines (1,430 loc) 215 kB
import { ElementRef, Injectable, NgZone, EventEmitter, Component, ChangeDetectorRef, Directive, ComponentFactoryResolver, Input, Renderer2, Optional, Self, HostBinding, Output, HostListener, ContentChildren, NgModule } from '@angular/core'; import { Subject, Observable, Subscription, fromEvent, merge } from 'rxjs'; import { __extends, __values } from 'tslib'; import { OverlayContainerRef } from '@duoduo-oba/ng-devui/overlay-container'; import { filter, distinctUntilChanged, tap, throttleTime } from 'rxjs/operators'; import { CommonModule } from '@angular/common'; /** * @fileoverview added by tsickle * Generated from: touch-support/dragdrop-touch.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ /** * 2020.03.23-Modified from https://github.com/Bernardo-Castilho/dragdroptouch, license: MIT,reason:Converting .js file to .ts file * Huawei Technologies Co.,Ltd.<devcloudmobile\@huawei.com> */ var DragDropTouch = /** @class */ (function () { function DragDropTouch() { var _this = this; this.lastClick = 0; // ** event handlers this.touchstart = (/** * @param {?} e * @return {?} */ function (e) { if (_this.shouldHandle(e)) { // raise double-click and prevent zooming if (Date.now() - _this.lastClick < DragDropTouch.DBLCLICK) { if (_this.dispatchEvent(e, 'dblclick', e.target)) { e.preventDefault(); _this.reset(); return; } } // clear all variables _this.reset(); // get nearest draggable element /** @type {?} */ var src = _this.closestDraggable(e.target); if (src) { _this.dragSource = src; _this.ptDown = _this.getPoint(e); _this.lastTouch = e; if (DragDropTouch.IS_PRESS_HOLD_MODE) { _this.pressHoldInterval = setTimeout((/** * @return {?} */ function () { _this.bindTouchmoveTouchend(e); _this.isDragEnabled = true; _this.touchmove(e); }), DragDropTouch.PRESS_HOLD_AWAIT); } else { e.preventDefault(); _this.bindTouchmoveTouchend(e); } } } }); this.touchmoveOnDocument = (/** * @param {?} e * @return {?} */ function (e) { if (_this.shouldCancelPressHoldMove(e)) { _this.reset(); return; } }); this.touchmove = (/** * @param {?} e * @return {?} */ function (e) { if (_this.shouldCancelPressHoldMove(e)) { _this.reset(); return; } if (_this.shouldHandleMove(e) || _this.shouldHandlePressHoldMove(e)) { /** @type {?} */ var target = _this.getTarget(e); // start dragging if (_this.dragSource && !_this.img && _this.shouldStartDragging(e)) { _this.dispatchEvent(e, 'dragstart', _this.dragSource); _this.createImage(e); } // continue dragging if (_this.img) { _this.clearDragoverInterval(); _this.lastTouch = e; e.preventDefault(); // prevent scrolling if (target !== _this.lastTarget) { // according to drag drop implementation of the browser, dragenterB is supposed to fired before dragleaveA _this.dispatchEvent(e, 'dragenter', target); _this.dispatchEvent(_this.lastTouch, 'dragleave', _this.lastTarget); _this.lastTarget = target; } _this.moveImage(e); _this.isDropZone = _this.dispatchEvent(e, 'dragover', target); // should continue dispatch dragover event when touch position stay still _this.setDragoverInterval(e); } } }); this.touchendOnDocument = (/** * @param {?} e * @return {?} */ function (e) { if (_this.shouldHandle(e)) { if (!_this.img) { _this.dragSource = null; _this.lastClick = Date.now(); } // finish dragging _this.destroyImage(); if (_this.dragSource) { _this.reset(); } } }); this.touchend = (/** * @param {?} e * @return {?} */ function (e) { if (_this.shouldHandle(e)) { // user clicked the element but didn't drag, so clear the source and simulate a click if (!_this.img) { _this.dragSource = null; // browser will dispatch click event after trigger touchend, since touchstart didn't preventDefault // this._dispatchEvent(this._lastTouch, 'click', e.target); _this.lastClick = Date.now(); } // finish dragging _this.destroyImage(); if (_this.dragSource) { if (e.type.indexOf('cancel') < 0 && _this.isDropZone) { _this.dispatchEvent(_this.lastTouch, 'drop', _this.lastTarget); } _this.dispatchEvent(_this.lastTouch, 'dragend', _this.dragSource); _this.reset(); } } }); // enforce singleton pattern if (DragDropTouch.instance) { throw new Error('DragDropTouch instance already created.'); } // detect passive event support // https://github.com/Modernizr/Modernizr/issues/1894 /** @type {?} */ var supportsPassive = false; document.addEventListener('test', (/** * @return {?} */ function () { }), { /** * @return {?} */ get passive() { supportsPassive = true; return true; } }); // listen to touch events if (DragDropTouch.isTouchDevice()) { // 能响应触摸事件 /** @type {?} */ var d = document; /** @type {?} */ var ts = this.touchstart; /** @type {?} */ var tmod = this.touchmoveOnDocument; /** @type {?} */ var teod = this.touchendOnDocument; /** @type {?} */ var opt = supportsPassive ? { passive: false, capture: false } : false; /** @type {?} */ var optPassive = supportsPassive ? { passive: true } : false; d.addEventListener('touchstart', ts, opt); d.addEventListener('touchmove', tmod, optPassive); d.addEventListener('touchend', teod); d.addEventListener('touchcancel', teod); this.touchmoveListener = this.touchmove; this.touchendListener = this.touchend; this.listenerOpt = opt; } } /** * Gets a reference to the @see:DragDropTouch singleton. */ /** * Gets a reference to the \@see:DragDropTouch singleton. * @return {?} */ DragDropTouch.getInstance = /** * Gets a reference to the \@see:DragDropTouch singleton. * @return {?} */ function () { if (!DragDropTouch.instance) { DragDropTouch.instance = new DragDropTouch(); } return DragDropTouch.instance; }; /** * @return {?} */ DragDropTouch.isTouchDevice = /** * @return {?} */ function () { /** @type {?} */ var d = document; /** @type {?} */ var w = window; /** @type {?} */ var bool; if ('ontouchstart' in d // normal mobile device || 'ontouchstart' in w || navigator.maxTouchPoints > 0 || navigator.msMaxTouchPoints > 0 || window['DocumentTouch'] && document instanceof window['DocumentTouch']) { bool = true; } else { /** @type {?} */ var fakeBody = document.createElement('fakebody'); fakeBody.innerHTML += "\n <style>\n @media (touch-enabled),(-webkit-touch-enabled),(-moz-touch-enabled),(-o-touch-enabled){\n #touch_test {\n top: 42px;\n position: absolute;\n }\n }\n </style>"; document.documentElement.appendChild(fakeBody); /** @type {?} */ var touchTestNode = document.createElement('div'); touchTestNode.id = 'touch_test'; fakeBody.appendChild(touchTestNode); bool = touchTestNode.offsetTop === 42; fakeBody.parentElement.removeChild(fakeBody); } return bool; }; // ** event listener binding // ** event listener binding /** * @param {?} e * @return {?} */ DragDropTouch.prototype.bindTouchmoveTouchend = // ** event listener binding /** * @param {?} e * @return {?} */ function (e) { this.touchTarget = e.target; e.target.addEventListener('touchmove', this.touchmoveListener, this.listenerOpt); e.target.addEventListener('touchend', this.touchendListener); e.target.addEventListener('touchcancel', this.touchendListener); }; /** * @return {?} */ DragDropTouch.prototype.removeTouchmoveTouchend = /** * @return {?} */ function () { if (this.touchTarget) { this.touchTarget.removeEventListener('touchmove', this.touchmoveListener); this.touchTarget.removeEventListener('touchend', this.touchendListener); this.touchTarget.removeEventListener('touchcancel', this.touchendListener); this.touchTarget = undefined; } }; // ** utilities // ignore events that have been handled or that involve more than one touch // ** utilities // ignore events that have been handled or that involve more than one touch /** * @param {?} e * @return {?} */ DragDropTouch.prototype.shouldHandle = // ** utilities // ignore events that have been handled or that involve more than one touch /** * @param {?} e * @return {?} */ function (e) { return e && !e.defaultPrevented && e.touches && e.touches.length < 2; }; // use regular condition outside of press & hold mode // use regular condition outside of press & hold mode /** * @param {?} e * @return {?} */ DragDropTouch.prototype.shouldHandleMove = // use regular condition outside of press & hold mode /** * @param {?} e * @return {?} */ function (e) { return !DragDropTouch.IS_PRESS_HOLD_MODE && this.shouldHandle(e); }; // allow to handle moves that involve many touches for press & hold // allow to handle moves that involve many touches for press & hold /** * @param {?} e * @return {?} */ DragDropTouch.prototype.shouldHandlePressHoldMove = // allow to handle moves that involve many touches for press & hold /** * @param {?} e * @return {?} */ function (e) { return DragDropTouch.IS_PRESS_HOLD_MODE && this.isDragEnabled && e && e.touches && e.touches.length; }; // reset data if user drags without pressing & holding // reset data if user drags without pressing & holding /** * @param {?} e * @return {?} */ DragDropTouch.prototype.shouldCancelPressHoldMove = // reset data if user drags without pressing & holding /** * @param {?} e * @return {?} */ function (e) { return DragDropTouch.IS_PRESS_HOLD_MODE && !this.isDragEnabled && this.getDelta(e) > DragDropTouch.PRESS_HOLD_MARGIN; }; // start dragging when mouseover element matches drag handler selector and specified delta is detected // start dragging when mouseover element matches drag handler selector and specified delta is detected /** * @param {?} e * @return {?} */ DragDropTouch.prototype.shouldStartDragging = // start dragging when mouseover element matches drag handler selector and specified delta is detected /** * @param {?} e * @return {?} */ function (e) { /** @type {?} */ var dragHandleSelector = this.getDragHandle(); // start dragging when mouseover element matches drag handler selector if (dragHandleSelector && !this.matchSelector(e.target, dragHandleSelector)) { return false; } // start dragging when specified delta is detected /** @type {?} */ var delta = this.getDelta(e); return delta > DragDropTouch.THRESHOLD || (DragDropTouch.IS_PRESS_HOLD_MODE && delta >= DragDropTouch.PRESS_HOLD_THRESHOLD); }; // find drag handler selector for dragstart only with partial element // find drag handler selector for dragstart only with partial element /** * @return {?} */ DragDropTouch.prototype.getDragHandle = // find drag handler selector for dragstart only with partial element /** * @return {?} */ function () { if (this.dragSource) { return this.dragSource.getAttribute(DragDropTouch.DRAG_HANDLE_ATTR) || ''; } return ''; }; // test if element matches selector // test if element matches selector /** * @param {?} element * @param {?} selector * @return {?} */ DragDropTouch.prototype.matchSelector = // test if element matches selector /** * @param {?} element * @param {?} selector * @return {?} */ function (element, selector) { if (selector) { /** @type {?} */ var proto = Element.prototype; /** @type {?} */ var func = proto['matches'] || proto['matchesSelector'] || proto['mozMatchesSelector'] || proto['msMatchesSelector'] || proto['oMatchesSelector'] || proto['webkitMatchesSelector'] || (/** * @param {?} s * @return {?} */ function (s) { /** @type {?} */ var matches = (this.document || this.ownerDocument).querySelectorAll(s); /** @type {?} */ var i = matches.length; while (--i >= 0 && matches.item(i) !== this) { // do nothing } return i > -1; }); return func.call(element, selector); } return true; }; // clear all members // clear all members /** * @return {?} */ DragDropTouch.prototype.reset = // clear all members /** * @return {?} */ function () { this.removeTouchmoveTouchend(); this.destroyImage(); this.dragSource = null; this.lastTouch = null; this.lastTarget = null; this.ptDown = null; this.isDragEnabled = false; this.isDropZone = false; this.dataTransfer = new DragDropTouch.DataTransfer(); clearInterval(this.pressHoldInterval); this.clearDragoverInterval(); }; // get point for a touch event // get point for a touch event /** * @param {?} e * @param {?=} page * @return {?} */ DragDropTouch.prototype.getPoint = // get point for a touch event /** * @param {?} e * @param {?=} page * @return {?} */ function (e, page) { if (e && e.touches) { e = e.touches[0]; } return { x: page ? e.pageX : e.clientX, y: page ? e.pageY : e.clientY }; }; // get distance between the current touch event and the first one // get distance between the current touch event and the first one /** * @param {?} e * @return {?} */ DragDropTouch.prototype.getDelta = // get distance between the current touch event and the first one /** * @param {?} e * @return {?} */ function (e) { if (DragDropTouch.IS_PRESS_HOLD_MODE && !this.ptDown) { return 0; } /** @type {?} */ var p = this.getPoint(e); return Math.abs(p.x - this.ptDown.x) + Math.abs(p.y - this.ptDown.y); }; // get the element at a given touch event // get the element at a given touch event /** * @param {?} e * @return {?} */ DragDropTouch.prototype.getTarget = // get the element at a given touch event /** * @param {?} e * @return {?} */ function (e) { /** @type {?} */ var pt = this.getPoint(e); /** @type {?} */ var el = document.elementFromPoint(pt.x, pt.y); while (el && getComputedStyle(el).pointerEvents === 'none') { el = el.parentElement; } return (/** @type {?} */ (el)); }; // create drag image from source element // create drag image from source element /** * @param {?} e * @return {?} */ DragDropTouch.prototype.createImage = // create drag image from source element /** * @param {?} e * @return {?} */ function (e) { // just in case... if (this.img) { this.destroyImage(); } // create drag image from custom element or drag source /** @type {?} */ var src = this.imgCustom || this.dragSource; this.img = src.cloneNode(true); this.copyStyle(src, this.img); this.img.style.top = this.img.style.left = '-9999px'; // if creating from drag source, apply offset and opacity if (!this.imgCustom) { /** @type {?} */ var rc = src.getBoundingClientRect(); /** @type {?} */ var pt = this.getPoint(e); this.imgOffset = { x: pt.x - rc.left, y: pt.y - rc.top }; this.img.style.opacity = DragDropTouch.OPACITY.toString(); } // add image to document this.moveImage(e); document.body.appendChild(this.img); }; // dispose of drag image element // dispose of drag image element /** * @return {?} */ DragDropTouch.prototype.destroyImage = // dispose of drag image element /** * @return {?} */ function () { if (this.img && this.img.parentElement) { this.img.parentElement.removeChild(this.img); } this.img = null; this.imgCustom = null; }; // move the drag image element // move the drag image element /** * @param {?} e * @return {?} */ DragDropTouch.prototype.moveImage = // move the drag image element /** * @param {?} e * @return {?} */ function (e) { var _this = this; requestAnimationFrame((/** * @return {?} */ function () { if (_this.img) { /** @type {?} */ var pt = _this.getPoint(e, true); /** @type {?} */ var s = _this.img.style; s.position = 'absolute'; s.pointerEvents = 'none'; s.zIndex = '999999'; s.left = Math.round(pt.x - _this.imgOffset.x) + 'px'; s.top = Math.round(pt.y - _this.imgOffset.y) + 'px'; } })); }; // copy properties from an object to another // copy properties from an object to another /** * @param {?} dst * @param {?} src * @param {?} props * @return {?} */ DragDropTouch.prototype.copyProps = // copy properties from an object to another /** * @param {?} dst * @param {?} src * @param {?} props * @return {?} */ function (dst, src, props) { for (var i = 0; i < props.length; i++) { /** @type {?} */ var p = props[i]; dst[p] = src[p]; } }; // copy styles/attributes from drag source to drag image element // copy styles/attributes from drag source to drag image element /** * @param {?} src * @param {?} dst * @return {?} */ DragDropTouch.prototype.copyStyle = // copy styles/attributes from drag source to drag image element /** * @param {?} src * @param {?} dst * @return {?} */ function (src, dst) { // remove potentially troublesome attributes DragDropTouch.rmvAttrs.forEach((/** * @param {?} att * @return {?} */ function (att) { dst.removeAttribute(att); })); // copy canvas content if (src instanceof HTMLCanvasElement) { /** @type {?} */ var canSrc = src; /** @type {?} */ var canDst = dst; canDst.width = canSrc.width; canDst.height = canSrc.height; canDst.getContext('2d').drawImage(canSrc, 0, 0); } // copy canvas content for nested canvas element /** @type {?} */ var srcCanvases = src.querySelectorAll('canvas'); if (srcCanvases.length > 0) { /** @type {?} */ var dstCanvases = dst.querySelectorAll('canvas'); for (var i = 0; i < dstCanvases.length; i++) { /** @type {?} */ var cSrc = srcCanvases[i]; /** @type {?} */ var cDst = dstCanvases[i]; cDst.getContext('2d').drawImage(cSrc, 0, 0); } } // copy style (without transitions) /** @type {?} */ var cs = getComputedStyle(src); for (var i = 0; i < cs.length; i++) { /** @type {?} */ var key = cs[i]; if (key.indexOf('transition') < 0) { dst.style[key] = cs[key]; } } dst.style.pointerEvents = 'none'; // and repeat for all children for (var i = 0; i < src.children.length; i++) { this.copyStyle(src.children[i], dst.children[i]); } }; // synthesize and dispatch an event // returns true if the event has been handled (e.preventDefault == true) // synthesize and dispatch an event // returns true if the event has been handled (e.preventDefault == true) /** * @param {?} e * @param {?} type * @param {?} target * @return {?} */ DragDropTouch.prototype.dispatchEvent = // synthesize and dispatch an event // returns true if the event has been handled (e.preventDefault == true) /** * @param {?} e * @param {?} type * @param {?} target * @return {?} */ function (e, type, target) { if (e && target) { /** @type {?} */ var evt = document.createEvent('Event'); /** @type {?} */ var t = e.touches ? e.touches[0] : e; evt.initEvent(type, true, true); /** @type {?} */ var obj = { button: 0, which: 0, buttons: 1, dataTransfer: this.dataTransfer }; this.copyProps(evt, e, DragDropTouch.kbdProps); this.copyProps(evt, t, DragDropTouch.ptProps); this.copyProps(evt, { fromTouch: true }, ['fromTouch']); // mark as from touch event this.copyProps(evt, obj, Object.keys(obj)); target.dispatchEvent(evt); return evt.defaultPrevented; } return false; }; // gets an element's closest draggable ancestor // gets an element's closest draggable ancestor /** * @param {?} e * @return {?} */ DragDropTouch.prototype.closestDraggable = // gets an element's closest draggable ancestor /** * @param {?} e * @return {?} */ function (e) { for (; e; e = e.parentElement) { if (e.hasAttribute('draggable') && e.draggable) { return e; } } return null; }; // repeat dispatch dragover event when touch point stay still // repeat dispatch dragover event when touch point stay still /** * @param {?} e * @return {?} */ DragDropTouch.prototype.setDragoverInterval = // repeat dispatch dragover event when touch point stay still /** * @param {?} e * @return {?} */ function (e) { var _this = this; this.dragoverTimer = setInterval((/** * @return {?} */ function () { /** @type {?} */ var target = _this.getTarget(e); if (target !== _this.lastTarget) { _this.dispatchEvent(e, 'dragenter', target); _this.dispatchEvent(e, 'dragleave', _this.lastTarget); _this.lastTarget = target; } _this.isDropZone = _this.dispatchEvent(e, 'dragover', target); }), DragDropTouch.DRAG_OVER_TIME); }; /** * @return {?} */ DragDropTouch.prototype.clearDragoverInterval = /** * @return {?} */ function () { if (this.dragoverTimer) { clearInterval(this.dragoverTimer); this.dragoverTimer = undefined; } }; DragDropTouch.THRESHOLD = 5; // pixels to move before drag starts // pixels to move before drag starts DragDropTouch.OPACITY = 0.5; // drag image opacity // drag image opacity DragDropTouch.DBLCLICK = 500; // max ms between clicks in a double click // max ms between clicks in a double click DragDropTouch.DRAG_OVER_TIME = 300; // interval ms when drag over // interval ms when drag over DragDropTouch.CTX_MENU = 900; // ms to hold before raising 'contextmenu' event // ms to hold before raising 'contextmenu' event DragDropTouch.IS_PRESS_HOLD_MODE = true; // decides of press & hold mode presence // decides of press & hold mode presence DragDropTouch.PRESS_HOLD_AWAIT = 400; // ms to wait before press & hold is detected // ms to wait before press & hold is detected DragDropTouch.PRESS_HOLD_MARGIN = 25; // pixels that finger might shiver while pressing // pixels that finger might shiver while pressing DragDropTouch.PRESS_HOLD_THRESHOLD = 0; // pixels to move before drag starts // pixels to move before drag starts DragDropTouch.DRAG_HANDLE_ATTR = 'data-drag-handle-selector'; DragDropTouch.rmvAttrs = 'id,class,style,draggable'.split(','); DragDropTouch.kbdProps = 'altKey,ctrlKey,metaKey,shiftKey'.split(','); DragDropTouch.ptProps = 'pageX,pageY,clientX,clientY,screenX,screenY'.split(','); DragDropTouch.instance = null; return DragDropTouch; }()); if (false) { /** @type {?} */ DragDropTouch.THRESHOLD; /** @type {?} */ DragDropTouch.OPACITY; /** @type {?} */ DragDropTouch.DBLCLICK; /** @type {?} */ DragDropTouch.DRAG_OVER_TIME; /** @type {?} */ DragDropTouch.CTX_MENU; /** @type {?} */ DragDropTouch.IS_PRESS_HOLD_MODE; /** @type {?} */ DragDropTouch.PRESS_HOLD_AWAIT; /** @type {?} */ DragDropTouch.PRESS_HOLD_MARGIN; /** @type {?} */ DragDropTouch.PRESS_HOLD_THRESHOLD; /** @type {?} */ DragDropTouch.DRAG_HANDLE_ATTR; /** @type {?} */ DragDropTouch.rmvAttrs; /** @type {?} */ DragDropTouch.kbdProps; /** @type {?} */ DragDropTouch.ptProps; /** * @type {?} * @private */ DragDropTouch.instance; /** @type {?} */ DragDropTouch.prototype.dataTransfer; /** @type {?} */ DragDropTouch.prototype.lastClick; /** @type {?} */ DragDropTouch.prototype.lastTouch; /** @type {?} */ DragDropTouch.prototype.lastTarget; /** @type {?} */ DragDropTouch.prototype.dragSource; /** @type {?} */ DragDropTouch.prototype.ptDown; /** @type {?} */ DragDropTouch.prototype.isDragEnabled; /** @type {?} */ DragDropTouch.prototype.isDropZone; /** @type {?} */ DragDropTouch.prototype.pressHoldInterval; /** @type {?} */ DragDropTouch.prototype.img; /** @type {?} */ DragDropTouch.prototype.imgCustom; /** @type {?} */ DragDropTouch.prototype.imgOffset; /** @type {?} */ DragDropTouch.prototype.dragoverTimer; /** @type {?} */ DragDropTouch.prototype.touchTarget; /** @type {?} */ DragDropTouch.prototype.touchmoveListener; /** @type {?} */ DragDropTouch.prototype.touchendListener; /** @type {?} */ DragDropTouch.prototype.listenerOpt; /** @type {?} */ DragDropTouch.prototype.touchstart; /** @type {?} */ DragDropTouch.prototype.touchmoveOnDocument; /** @type {?} */ DragDropTouch.prototype.touchmove; /** @type {?} */ DragDropTouch.prototype.touchendOnDocument; /** @type {?} */ DragDropTouch.prototype.touchend; } (function (DragDropTouch) { /** * Object used to hold the data that is being dragged during drag and drop operations. * * It may hold one or more data items of different types. For more information about * drag and drop operations and data transfer objects, see * <a href="https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer">HTML Drag and Drop API</a>. * * This object is created automatically by the \@see:DragDropTouch singleton and is * accessible through the \@see:dataTransfer property of all drag events. */ var /** * Object used to hold the data that is being dragged during drag and drop operations. * * It may hold one or more data items of different types. For more information about * drag and drop operations and data transfer objects, see * <a href="https://developer.mozilla.org/en-US/docs/Web/API/DataTransfer">HTML Drag and Drop API</a>. * * This object is created automatically by the \@see:DragDropTouch singleton and is * accessible through the \@see:dataTransfer property of all drag events. */ DataTransfer = /** @class */ (function () { function DataTransfer() { this._dropEffect = 'move'; this._effectAllowed = 'all'; this._data = {}; } Object.defineProperty(DataTransfer.prototype, "dropEffect", { get: /** * @return {?} */ function () { return this._dropEffect; }, set: /** * @param {?} value * @return {?} */ function (value) { this._dropEffect = value; }, enumerable: true, configurable: true }); Object.defineProperty(DataTransfer.prototype, "effectAllowed", { get: /** * @return {?} */ function () { return this._effectAllowed; }, set: /** * @param {?} value * @return {?} */ function (value) { this._effectAllowed = value; }, enumerable: true, configurable: true }); Object.defineProperty(DataTransfer.prototype, "types", { get: /** * @return {?} */ function () { return Object.keys(this._data); }, enumerable: true, configurable: true }); /** * Removes the data associated with a given type. * * The type argument is optional. If the type is empty or not specified, the data * associated with all types is removed. If data for the specified type does not exist, * or the data transfer contains no data, this method will have no effect. * * @param type Type of data to remove. */ /** * Removes the data associated with a given type. * * The type argument is optional. If the type is empty or not specified, the data * associated with all types is removed. If data for the specified type does not exist, * or the data transfer contains no data, this method will have no effect. * * @param {?} type Type of data to remove. * @return {?} */ DataTransfer.prototype.clearData = /** * Removes the data associated with a given type. * * The type argument is optional. If the type is empty or not specified, the data * associated with all types is removed. If data for the specified type does not exist, * or the data transfer contains no data, this method will have no effect. * * @param {?} type Type of data to remove. * @return {?} */ function (type) { if (type !== null) { delete this._data[type]; } else { this._data = null; } }; /** * Retrieves the data for a given type, or an empty string if data for that type does * not exist or the data transfer contains no data. * * @param type Type of data to retrieve. */ /** * Retrieves the data for a given type, or an empty string if data for that type does * not exist or the data transfer contains no data. * * @param {?} type Type of data to retrieve. * @return {?} */ DataTransfer.prototype.getData = /** * Retrieves the data for a given type, or an empty string if data for that type does * not exist or the data transfer contains no data. * * @param {?} type Type of data to retrieve. * @return {?} */ function (type) { return this._data[type] || ''; }; /** * Set the data for a given type. * * For a list of recommended drag types, please see * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Recommended_Drag_Types. * * @param type Type of data to add. * @param value Data to add. */ /** * Set the data for a given type. * * For a list of recommended drag types, please see * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Recommended_Drag_Types. * * @param {?} type Type of data to add. * @param {?} value Data to add. * @return {?} */ DataTransfer.prototype.setData = /** * Set the data for a given type. * * For a list of recommended drag types, please see * https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/Recommended_Drag_Types. * * @param {?} type Type of data to add. * @param {?} value Data to add. * @return {?} */ function (type, value) { this._data[type] = value; }; /** * Set the image to be used for dragging if a custom one is desired. * * @param img An image element to use as the drag feedback image. * @param offsetX The horizontal offset within the image. * @param offsetY The vertical offset within the image. */ /** * Set the image to be used for dragging if a custom one is desired. * * @param {?} img An image element to use as the drag feedback image. * @param {?} offsetX The horizontal offset within the image. * @param {?} offsetY The vertical offset within the image. * @return {?} */ DataTransfer.prototype.setDragImage = /** * Set the image to be used for dragging if a custom one is desired. * * @param {?} img An image element to use as the drag feedback image. * @param {?} offsetX The horizontal offset within the image. * @param {?} offsetY The vertical offset within the image. * @return {?} */ function (img, offsetX, offsetY) { /** @type {?} */ var ddt = DragDropTouch.getInstance(); ddt.imgCustom = img; ddt.imgOffset = { x: offsetX, y: offsetY }; }; return DataTransfer; }()); DragDropTouch.DataTransfer = DataTransfer; if (false) { /** @type {?} */ DataTransfer.prototype.files; /** @type {?} */ DataTransfer.prototype.items; /** * @type {?} * @private */ DataTransfer.prototype._data; /** * Gets or sets the type of drag-and-drop operation currently selected. * The value must be 'none', 'copy', 'link', or 'move'. * @type {?} * @private */ DataTransfer.prototype._dropEffect; /** * Gets or sets the types of operations that are possible. * Must be one of 'none', 'copy', 'copyLink', 'copyMove', 'link', * 'linkMove', 'move', 'all' or 'uninitialized'. * @type {?} * @private */ DataTransfer.prototype._effectAllowed; /** * Gets an array of strings giving the formats that were set in the \@see:dragstart event. * @type {?} * @private */ DataTransfer.prototype._types; } })(DragDropTouch || (DragDropTouch = {})); /** * @fileoverview added by tsickle * Generated from: shared/utils.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var Utils = /** @class */ (function () { function Utils() { } /** * Polyfill for element.matches. * See: https://developer.mozilla.org/en/docs/Web/API/Element/matches#Polyfill * element */ /** * Polyfill for element.matches. * See: https://developer.mozilla.org/en/docs/Web/API/Element/matches#Polyfill * element * @param {?} element * @param {?} selectorName * @return {?} */ Utils.matches = /** * Polyfill for element.matches. * See: https://developer.mozilla.org/en/docs/Web/API/Element/matches#Polyfill * element * @param {?} element * @param {?} selectorName * @return {?} */ function (element, selectorName) { /** @type {?} */ var proto = Element.prototype; /** @type {?} */ var func = proto['matches'] || proto.matchesSelector || proto.mozMatchesSelector || proto.msMatchesSelector || proto.oMatchesSelector || proto.webkitMatchesSelector || (/** * @param {?} s * @return {?} */ function (s) { /** @type {?} */ var matches = (this.document || this.ownerDocument).querySelectorAll(s); /** @type {?} */ var i = matches.length; while (--i >= 0 && matches.item(i) !== this) { // do nothing } return i > -1; }); return func.call(element, selectorName); }; /** * Applies the specified css class on nativeElement * elementRef * className */ /** * Applies the specified css class on nativeElement * elementRef * className * @param {?} elementRef * @param {?} className * @return {?} */ Utils.addClass = /** * Applies the specified css class on nativeElement * elementRef * className * @param {?} elementRef * @param {?} className * @return {?} */ function (elementRef, className) { if (className === undefined) { return; } /** @type {?} */ var e = this.getElementWithValidClassList(elementRef); if (e) { e.classList.add(className); } }; /** * Removes the specified class from nativeElement * elementRef * className */ /** * Removes the specified class from nativeElement * elementRef * className * @param {?} elementRef * @param {?} className * @return {?} */ Utils.removeClass = /** * Removes the specified class from nativeElement * elementRef * className * @param {?} elementRef * @param {?} className * @return {?} */ function (elementRef, className) { if (className === undefined) { return; } /** @type {?} */ var e = this.getElementWithValidClassList(elementRef); if (e) { e.classList.remove(className); } }; /** * Gets element with valid classList * * elementRef * @returns ElementRef | null */ /** * Gets element with valid classList * * elementRef * @private * @param {?} elementRef * @return {?} ElementRef | null */ Utils.getElementWithValidClassList = /** * Gets element with valid classList * * elementRef * @private * @param {?} elementRef * @return {?} ElementRef | null */ function (elementRef) { /** @type {?} */ var e = elementRef instanceof ElementRef ? elementRef.nativeElement : elementRef; if (e.classList !== undefined && e.classList !== null) { return e; } return null; }; /** * @param {?} args * @param {?=} slice * @param {?=} sliceEnd * @return {?} */ Utils.slice = /** * @param {?} args * @param {?=} slice * @param {?=} sliceEnd * @return {?} */ function (args, slice, sliceEnd) { /** @type {?} */ var ret = []; /** @type {?} */ var len = args.length; if (0 === len) { return ret; } /** @type {?} */ var start = slice < 0 ? Math.max(0, slice + len) : slice || 0; if (sliceEnd !== undefined) { len = sliceEnd < 0 ? sliceEnd + len : sliceEnd; } while (len-- > start) { ret[len - start] = args[len]; } return ret; }; // 动态添加styles // 动态添加styles /** * @param {?} el * @param {?} styles * @return {?} */ Utils.addElStyles = // 动态添加styles /** * @param {?} el * @param {?} styles * @return {?} */ function (el, styles) { if (styles instanceof Object) { var _loop_1 = function (s) { if (styles.hasOwnProperty(s)) { if (Array.isArray(styles[s])) { // 用于支持兼容渐退 styles[s].forEach((/** * @param {?} val * @return {?} */ function (val) { el.style[s] = val; })); } else { el.style[s] = styles[s]; } } }; for (var s in styles) { _loop_1(s); } } }; return Utils; }()); /** * @fileoverview added by tsickle * Generated from: services/drag-drop.service.ts * @suppress {checkTypes,constantProperty,extraRequire,missingOverride,missingReturn,unusedPrivateMembers,uselessCode} checked by tsc */ var DragDropService = /** @class */ (function () { function DragDropService(ngZone) { var _this = this; this.ngZone = ngZone; this.dropTargets = []; this.dropEvent = new Subject(); this.dragEndEvent = new Subject(); this.dragStartEvent = new Subject(); this.subscription = Observable.create().subscribe(); this.dragEmptyImage = new Image(); this.dragItemParentName = ''; this.dragItemChildrenName = ''; this.intersectionObserver = null; /*协同拖拽需要 */ this.dragElShowHideEvent = new Subject(); this.followMouse4CloneNode = (/** * @param {?} event * @return {?} */ function (event) { var _a = _this.dragOffset, offsetLeft = _a.offsetLeft, offsetTop = _a.offsetTop; var clientX = event.clientX, clientY = event.clientY; requestAnimationFrame((/** * @return {?} */ function () { if (!_this.dragCloneNode) { return; } _this.dragCloneNode.style.left = clientX - offsetLeft + 'px'; _this.dragCloneNode.style.top = clientY - offsetTop + 'px'; })); }); this.touchInstance = DragDropTouch.getInstance(); // service not support OnInit, only support OnDestroy, so write in constructor // tslint:disable-next-line: max-line-length this.dragEmptyImage.src = 'data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAADUlEQVQImWNgYGBgAAAABQABh6FO1AAAAABJRU5ErkJggg=='; // safari的img必须要有src } /** * @return {?} */ DragDropService.prototype.newSubscription = /** * @return {?} */ function () { this.subscription.unsubscribe(); return this.subscription = Observable.create().subscribe(); }; /** * @return {?} */ DragDropService.prototype.enableDraggedCloneNodeFollowMouse = /** * @return {?} */ function () { var _this = this; if (!this.dragCloneNode) { this.dragItemContainer = this.draggedEl.parentElement; if (this.dragPreviewDirective && this.dragPreviewDirective.dragPreviewTemplate) { this.dragPreviewDirective.createPreview(); this.dragCloneNode = this.dragPreviewDirective.getPreviewElement(); this.dragItemContainer = document.body; } else { this.dragCloneNode = this.draggedEl.cloneNode(true); } this.dragCloneNode.style.margin = '0'; if (this.dragFollowOptions && this.dragFollowOptions.appendToBody) { this.dragItemContainer = document.body; this.copyStyle(this.draggedEl, this.dragCloneNode); } if (this.dragItemChildrenName !== '') { /** @type {?} */ var parentElement = this.dragItemParentName === '' ? this.dragCloneNode : document.querySelector(this.dragItemParentName); /** @type {?} */ var dragItemChildren = parentElement.querySelectorAll(this.dragItemChildrenName); this.interceptChildNode(parentElement, dragItemChildren); } // 拷贝canvas的内容 /** @type {?} */ var originCanvasArr_1 = this.draggedEl.querySelectorAll('canvas'); /** @type {?} */ var targetCanvasArr = this.dragCloneNode.querySelectorAll('canvas'); [].forEach.call(targetCanvasArr, (/** * @param {?} canvas * @param {?} index * @return {?} */ function (canvas, index) { canvas.getContext('2d').drawImage(originCanvasArr_1[index], 0, 0); })); this.ngZone.runOutsideAngular((/** * @return {?}