@duoduo-oba/ng-devui
Version:
DevUI components based on Angular
1,206 lines (1,180 loc) • 250 kB
JavaScript
(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core'), require('rxjs'), require('ng-devui/overlay-container'), require('rxjs/operators'), require('@angular/common')) :
typeof define === 'function' && define.amd ? define('ng-devui/dragdrop', ['exports', '@angular/core', 'rxjs', 'ng-devui/overlay-container', 'rxjs/operators', '@angular/common'], factory) :
(global = global || self, factory((global['ng-devui'] = global['ng-devui'] || {}, global['ng-devui'].dragdrop = {}), global.ng.core, global.rxjs, global['ng-devui']['overlay-container'], global.rxjs.operators, global.ng.common));
}(this, (function (exports, core, rxjs, overlayContainer, operators, common) { 'use strict';
/*! *****************************************************************************
Copyright (c) Microsoft Corporation. All rights reserved.
Licensed under the Apache License, Version 2.0 (the "License"); you may not use
this file except in compliance with the License. You may obtain a copy of the
License at http://www.apache.org/licenses/LICENSE-2.0
THIS CODE IS PROVIDED ON AN *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION ANY IMPLIED
WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A PARTICULAR PURPOSE,
MERCHANTABLITY OR NON-INFRINGEMENT.
See the Apache Version 2.0 License for specific language governing permissions
and limitations under the License.
***************************************************************************** */
/* global Reflect, Promise */
var extendStatics = function(d, b) {
extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return extendStatics(d, b);
};
function __extends(d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
}
var __assign = function() {
__assign = Object.assign || function __assign(t) {
for (var s, i = 1, n = arguments.length; i < n; i++) {
s = arguments[i];
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
}
return t;
};
return __assign.apply(this, arguments);
};
function __rest(s, e) {
var t = {};
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
t[p] = s[p];
if (s != null && typeof Object.getOwnPropertySymbols === "function")
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
t[p[i]] = s[p[i]];
}
return t;
}
function __decorate(decorators, target, key, desc) {
var c = arguments.length, r = c < 3 ? target : desc === null ? desc = Object.getOwnPropertyDescriptor(target, key) : desc, d;
if (typeof Reflect === "object" && typeof Reflect.decorate === "function") r = Reflect.decorate(decorators, target, key, desc);
else for (var i = decorators.length - 1; i >= 0; i--) if (d = decorators[i]) r = (c < 3 ? d(r) : c > 3 ? d(target, key, r) : d(target, key)) || r;
return c > 3 && r && Object.defineProperty(target, key, r), r;
}
function __param(paramIndex, decorator) {
return function (target, key) { decorator(target, key, paramIndex); }
}
function __metadata(metadataKey, metadataValue) {
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(metadataKey, metadataValue);
}
function __awaiter(thisArg, _arguments, P, generator) {
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : new P(function (resolve) { resolve(result.value); }).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
}
function __generator(thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (_) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
}
function __exportStar(m, exports) {
for (var p in m) if (!exports.hasOwnProperty(p)) exports[p] = m[p];
}
function __values(o) {
var m = typeof Symbol === "function" && o[Symbol.iterator], i = 0;
if (m) return m.call(o);
return {
next: function () {
if (o && i >= o.length) o = void 0;
return { value: o && o[i++], done: !o };
}
};
}
function __read(o, n) {
var m = typeof Symbol === "function" && o[Symbol.iterator];
if (!m) return o;
var i = m.call(o), r, ar = [], e;
try {
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
}
catch (error) { e = { error: error }; }
finally {
try {
if (r && !r.done && (m = i["return"])) m.call(i);
}
finally { if (e) throw e.error; }
}
return ar;
}
function __spread() {
for (var ar = [], i = 0; i < arguments.length; i++)
ar = ar.concat(__read(arguments[i]));
return ar;
}
function __spreadArrays() {
for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
for (var r = Array(s), k = 0, i = 0; i < il; i++)
for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
r[k] = a[j];
return r;
};
function __await(v) {
return this instanceof __await ? (this.v = v, this) : new __await(v);
}
function __asyncGenerator(thisArg, _arguments, generator) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var g = generator.apply(thisArg, _arguments || []), i, q = [];
return i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i;
function verb(n) { if (g[n]) i[n] = function (v) { return new Promise(function (a, b) { q.push([n, v, a, b]) > 1 || resume(n, v); }); }; }
function resume(n, v) { try { step(g[n](v)); } catch (e) { settle(q[0][3], e); } }
function step(r) { r.value instanceof __await ? Promise.resolve(r.value.v).then(fulfill, reject) : settle(q[0][2], r); }
function fulfill(value) { resume("next", value); }
function reject(value) { resume("throw", value); }
function settle(f, v) { if (f(v), q.shift(), q.length) resume(q[0][0], q[0][1]); }
}
function __asyncDelegator(o) {
var i, p;
return i = {}, verb("next"), verb("throw", function (e) { throw e; }), verb("return"), i[Symbol.iterator] = function () { return this; }, i;
function verb(n, f) { i[n] = o[n] ? function (v) { return (p = !p) ? { value: __await(o[n](v)), done: n === "return" } : f ? f(v) : v; } : f; }
}
function __asyncValues(o) {
if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
var m = o[Symbol.asyncIterator], i;
return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
}
function __makeTemplateObject(cooked, raw) {
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
return cooked;
};
function __importStar(mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
result.default = mod;
return result;
}
function __importDefault(mod) {
return (mod && mod.__esModule) ? mod : { default: mod };
}
/**
* @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.
*