draggable-helper
Advanced tools
Comparing version 3.0.3 to 3.0.4
/*! | ||
* draggable-helper v3.0.3 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
* draggable-helper v3.0.4 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
'use strict'; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
var _defineProperty = _interopDefault(require('@babel/runtime/helpers/defineProperty')); | ||
var hp = require('helper-js'); | ||
var DragEventService = _interopDefault(require('drag-event-service')); | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function getOffsetParent(el) { | ||
var offsetParent = el.offsetParent; | ||
if (!offsetParent || offsetParent === document.body && getComputedStyle(document.body).position === 'static') { | ||
offsetParent = document.body.parentElement; | ||
} | ||
return offsetParent; | ||
} // get el current position. like jQuery.position | ||
// the position is relative to offsetParent viewport left top. it is for set absolute position, absolute position is relative to offsetParent viewport left top. | ||
// 相对于offsetParent可视区域左上角(el.offsetLeft或top包含父元素的滚动距离, 所以要减去). position一般用于设置绝对定位的情况, 而绝对定位就是以可视区域左上角为原点. | ||
function getPosition(el) { | ||
var offsetParent = getOffsetParent(el); | ||
var ps = { | ||
x: el.offsetLeft, | ||
y: el.offsetTop | ||
}; | ||
var parent = el; | ||
while (true) { | ||
parent = parent.parentElement; | ||
if (parent === offsetParent || !parent) { | ||
break; | ||
} | ||
ps.x -= parent.scrollLeft; | ||
ps.y -= parent.scrollTop; | ||
} | ||
return ps; | ||
} // get position of a el if its offset is given. like jQuery.offset. | ||
function getBoundingClientRect(el) { | ||
// refer: http://www.51xuediannao.com/javascript/getBoundingClientRect.html | ||
var xy = el.getBoundingClientRect(); | ||
var top = xy.top - document.documentElement.clientTop, | ||
//document.documentElement.clientTop 在IE67中始终为2,其他高级点的浏览器为0 | ||
bottom = xy.bottom, | ||
left = xy.left - document.documentElement.clientLeft, | ||
//document.documentElement.clientLeft 在IE67中始终为2,其他高级点的浏览器为0 | ||
right = xy.right, | ||
width = xy.width || right - left, | ||
//IE67不存在width 使用right - left获得 | ||
height = xy.height || bottom - top; | ||
var x = left; | ||
var y = top; | ||
return { | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left, | ||
width: width, | ||
height: height, | ||
x: x, | ||
y: y | ||
}; | ||
} | ||
function findParent(el, callback, opt) { | ||
var cur = opt && opt.withSelf ? el : el.parentElement; | ||
while (cur) { | ||
var r = callback(cur); | ||
if (r === 'break') { | ||
return; | ||
} else if (r) { | ||
return cur; | ||
} else { | ||
cur = cur.parentElement; | ||
} | ||
} | ||
} | ||
function backupAttr(el, name) { | ||
var key = "original_".concat(name); | ||
el[key] = el.getAttribute(name); | ||
} | ||
function restoreAttr(el, name) { | ||
var key = "original_".concat(name); | ||
el.setAttribute(name, el[key]); | ||
} // source: http://youmightnotneedjquery.com/ | ||
function hasClass(el, className) { | ||
if (el.classList) { | ||
return el.classList.contains(className); | ||
} else { | ||
return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className); | ||
} | ||
} // source: http://youmightnotneedjquery.com/ | ||
function addClass(el, className) { | ||
if (!hasClass(el, className)) { | ||
if (el.classList) { | ||
el.classList.add(className); | ||
} else { | ||
el.className += ' ' + className; | ||
} | ||
} | ||
} // source: http://youmightnotneedjquery.com/ | ||
/*! | ||
* drag-event-service v1.0.1 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
/*! | ||
* helper-js v1.4.14 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
function onDOM(el, name, handler) { | ||
for (var _len6 = arguments.length, args = new Array(_len6 > 3 ? _len6 - 3 : 0), _key8 = 3; _key8 < _len6; _key8++) { | ||
args[_key8 - 3] = arguments[_key8]; | ||
} | ||
if (el.addEventListener) { | ||
// 所有主流浏览器,除了 IE 8 及更早 IE版本 | ||
el.addEventListener.apply(el, [name, handler].concat(args)); | ||
} else if (el.attachEvent) { | ||
// IE 8 及更早 IE 版本 | ||
el.attachEvent.apply(el, ["on".concat(name), handler].concat(args)); | ||
} | ||
} | ||
function offDOM(el, name, handler) { | ||
for (var _len7 = arguments.length, args = new Array(_len7 > 3 ? _len7 - 3 : 0), _key9 = 3; _key9 < _len7; _key9++) { | ||
args[_key9 - 3] = arguments[_key9]; | ||
} | ||
if (el.removeEventListener) { | ||
// 所有主流浏览器,除了 IE 8 及更早 IE版本 | ||
el.removeEventListener.apply(el, [name, handler].concat(args)); | ||
} else if (el.detachEvent) { | ||
// IE 8 及更早 IE 版本 | ||
el.detachEvent.apply(el, ["on".concat(name), handler].concat(args)); | ||
} | ||
} // support desktop and mobile | ||
var events = { | ||
start: ['mousedown', 'touchstart'], | ||
move: ['mousemove', 'touchmove'], | ||
end: ['mouseup', 'touchend'] | ||
}; | ||
var index = { | ||
isTouch: function isTouch(e) { | ||
return e.type && e.type.startsWith('touch'); | ||
}, | ||
_getStore: function _getStore(el) { | ||
if (!el._wrapperStore) { | ||
el._wrapperStore = []; | ||
} | ||
return el._wrapperStore; | ||
}, | ||
on: function on(el, name, handler, options) { | ||
var _resolveOptions = resolveOptions(options), | ||
args = _resolveOptions.args, | ||
mouseArgs = _resolveOptions.mouseArgs, | ||
touchArgs = _resolveOptions.touchArgs; | ||
var store = this._getStore(el); | ||
var ts = this; | ||
var wrapper = function wrapper(e) { | ||
var mouse; | ||
var isTouch = ts.isTouch(e); | ||
if (isTouch) { | ||
// touch | ||
mouse = { | ||
x: e.changedTouches[0].pageX, | ||
y: e.changedTouches[0].pageY | ||
}; | ||
} else { | ||
// mouse | ||
mouse = { | ||
x: e.pageX, | ||
y: e.pageY | ||
}; | ||
if (name === 'start' && e.which !== 1) { | ||
// not left button mousedown | ||
return; | ||
} | ||
} | ||
return handler.call(this, e, mouse); | ||
}; | ||
store.push({ | ||
handler: handler, | ||
wrapper: wrapper | ||
}); // follow format will cause big bundle size | ||
// 以下写法将会使打包工具认为hp是上下文, 导致打包整个hp | ||
// hp.onDOM(el, events[name][0], wrapper, ...args) | ||
onDOM.call.apply(onDOM, [null, el, events[name][0], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
onDOM.call.apply(onDOM, [null, el, events[name][1], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(touchArgs)))); | ||
}, | ||
off: function off(el, name, handler, options) { | ||
var _resolveOptions2 = resolveOptions(options), | ||
args = _resolveOptions2.args, | ||
mouseArgs = _resolveOptions2.mouseArgs; | ||
var store = this._getStore(el); | ||
for (var i = store.length - 1; i >= 0; i--) { | ||
var _store$i = store[i], | ||
handler2 = _store$i.handler, | ||
wrapper = _store$i.wrapper; | ||
if (handler === handler2) { | ||
offDOM.call.apply(offDOM, [null, el, events[name][0], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
offDOM.call.apply(offDOM, [null, el, events[name][1], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
store.splice(i, 1); | ||
} | ||
} | ||
} | ||
}; | ||
function resolveOptions(options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
var args = options.args || []; | ||
var mouseArgs = options.mouseArgs || []; | ||
var touchArgs = options.touchArgs || []; | ||
return { | ||
args: args, | ||
mouseArgs: mouseArgs, | ||
touchArgs: touchArgs | ||
}; | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
/*** | ||
@@ -370,5 +63,5 @@ const destroy = draggableHelper(HTMLElement dragHandlerEl, Object opt = {}) | ||
var UNDRAGGABLE_CLASS = 'undraggable'; | ||
function index$1 (dragHandlerEl) { | ||
function index (dragHandlerEl) { | ||
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
opt = _objectSpread2({ | ||
opt = _objectSpread({ | ||
minTranslate: 10, | ||
@@ -379,4 +72,4 @@ draggingClass: 'dragging' | ||
var destroy = function destroy() { | ||
index.off(dragHandlerEl, 'start', dragHandlerEl._draggbleEventHandler); | ||
var destroy = () => { | ||
DragEventService.off(dragHandlerEl, 'start', dragHandlerEl._draggbleEventHandler); | ||
delete dragHandlerEl._draggbleEventHandler; | ||
@@ -390,3 +83,3 @@ }; | ||
dragHandlerEl._draggbleEventHandler = start; | ||
index.on(dragHandlerEl, 'start', start); | ||
DragEventService.on(dragHandlerEl, 'start', start); | ||
return destroy; | ||
@@ -404,8 +97,8 @@ | ||
if (hasClass(e.target, UNDRAGGABLE_CLASS)) { | ||
if (hp.hasClass(e.target, UNDRAGGABLE_CLASS)) { | ||
return; | ||
} | ||
var isParentUndraggable = findParent(e.target, function (el) { | ||
if (hasClass(el, UNDRAGGABLE_CLASS)) { | ||
var isParentUndraggable = hp.findParent(e.target, el => { | ||
if (hp.hasClass(el, UNDRAGGABLE_CLASS)) { | ||
return true; | ||
@@ -430,3 +123,3 @@ } | ||
store.startEvent = e; | ||
store.initialMouse = _objectSpread2({}, store.mouse); | ||
store.initialMouse = _objectSpread({}, store.mouse); | ||
/* | ||
@@ -437,3 +130,3 @@ must set passive false for touch, else the follow error occurs in Chrome: | ||
index.on(document, 'move', moving, { | ||
DragEventService.on(document, 'move', moving, { | ||
touchArgs: [{ | ||
@@ -443,3 +136,3 @@ passive: false | ||
}); | ||
index.on(window, 'end', drop); | ||
DragEventService.on(window, 'end', drop); | ||
} | ||
@@ -454,8 +147,8 @@ | ||
var _resolveDragedElAndIn = resolveDragedElAndInitialPosition(), | ||
el = _resolveDragedElAndIn.el, | ||
position = _resolveDragedElAndIn.position; | ||
var { | ||
el, | ||
position | ||
} = resolveDragedElAndInitialPosition(); | ||
store.el = el; | ||
store.initialPosition = _objectSpread2({}, position); | ||
store.initialPosition = _objectSpread({}, position); | ||
canDrag = opt.drag && opt.drag(store.startEvent, e, store, opt); | ||
@@ -468,5 +161,5 @@ | ||
var size = getBoundingClientRect(el); | ||
var size = hp.getBoundingClientRect(el); | ||
var style = _objectSpread2({ | ||
var style = _objectSpread({ | ||
width: "".concat(Math.ceil(size.width), "px"), | ||
@@ -481,3 +174,3 @@ height: "".concat(Math.ceil(size.height), "px"), | ||
backupAttr(el, 'style'); | ||
hp.backupAttr(el, 'style'); | ||
@@ -489,4 +182,4 @@ for (var key in style) { | ||
backupAttr(el, 'class'); | ||
addClass(el, opt.draggingClass); | ||
hp.backupAttr(el, 'class'); | ||
hp.addClass(el, opt.draggingClass); | ||
} | ||
@@ -544,3 +237,3 @@ | ||
function drop(e) { | ||
index.off(document, 'move', moving, { | ||
DragEventService.off(document, 'move', moving, { | ||
touchArgs: [{ | ||
@@ -550,3 +243,3 @@ passive: false | ||
}); | ||
index.off(window, 'end', drop); // drag executed if movedCount > 0 | ||
DragEventService.off(window, 'end', drop); // drag executed if movedCount > 0 | ||
@@ -556,11 +249,12 @@ if (store.movedCount > 0) { | ||
store.endEvent = e; | ||
var _store = store, | ||
el = _store.el; | ||
var { | ||
el | ||
} = store; | ||
var restoreDOM = function restoreDOM() { | ||
var restoreDOM = () => { | ||
if (opt.clone) { | ||
el.parentElement.removeChild(el); | ||
} else { | ||
restoreAttr(el, 'style'); | ||
restoreAttr(el, 'class'); | ||
hp.restoreAttr(el, 'style'); | ||
hp.restoreAttr(el, 'class'); | ||
} | ||
@@ -592,4 +286,4 @@ }; | ||
return { | ||
position: getPosition(el0), | ||
el: el | ||
position: hp.getPosition(el0), | ||
el | ||
}; | ||
@@ -605,2 +299,2 @@ } | ||
exports.default = index$1; | ||
module.exports = index; |
/*! | ||
* draggable-helper v3.0.3 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
function _defineProperty(obj, key, value) { | ||
if (key in obj) { | ||
Object.defineProperty(obj, key, { | ||
value: value, | ||
enumerable: true, | ||
configurable: true, | ||
writable: true | ||
}); | ||
} else { | ||
obj[key] = value; | ||
} | ||
* draggable-helper v3.0.4 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
import _defineProperty from '@babel/runtime/helpers/defineProperty'; | ||
import { hasClass, findParent, getPosition, getBoundingClientRect, backupAttr, addClass, restoreAttr } from 'helper-js'; | ||
import DragEventService from 'drag-event-service'; | ||
return obj; | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function getOffsetParent(el) { | ||
var offsetParent = el.offsetParent; | ||
if (!offsetParent || offsetParent === document.body && getComputedStyle(document.body).position === 'static') { | ||
offsetParent = document.body.parentElement; | ||
} | ||
return offsetParent; | ||
} // get el current position. like jQuery.position | ||
// the position is relative to offsetParent viewport left top. it is for set absolute position, absolute position is relative to offsetParent viewport left top. | ||
// 相对于offsetParent可视区域左上角(el.offsetLeft或top包含父元素的滚动距离, 所以要减去). position一般用于设置绝对定位的情况, 而绝对定位就是以可视区域左上角为原点. | ||
function getPosition(el) { | ||
var offsetParent = getOffsetParent(el); | ||
var ps = { | ||
x: el.offsetLeft, | ||
y: el.offsetTop | ||
}; | ||
var parent = el; | ||
while (true) { | ||
parent = parent.parentElement; | ||
if (parent === offsetParent || !parent) { | ||
break; | ||
} | ||
ps.x -= parent.scrollLeft; | ||
ps.y -= parent.scrollTop; | ||
} | ||
return ps; | ||
} // get position of a el if its offset is given. like jQuery.offset. | ||
function getBoundingClientRect(el) { | ||
// refer: http://www.51xuediannao.com/javascript/getBoundingClientRect.html | ||
var xy = el.getBoundingClientRect(); | ||
var top = xy.top - document.documentElement.clientTop, | ||
//document.documentElement.clientTop 在IE67中始终为2,其他高级点的浏览器为0 | ||
bottom = xy.bottom, | ||
left = xy.left - document.documentElement.clientLeft, | ||
//document.documentElement.clientLeft 在IE67中始终为2,其他高级点的浏览器为0 | ||
right = xy.right, | ||
width = xy.width || right - left, | ||
//IE67不存在width 使用right - left获得 | ||
height = xy.height || bottom - top; | ||
var x = left; | ||
var y = top; | ||
return { | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left, | ||
width: width, | ||
height: height, | ||
x: x, | ||
y: y | ||
}; | ||
} | ||
function findParent(el, callback, opt) { | ||
var cur = opt && opt.withSelf ? el : el.parentElement; | ||
while (cur) { | ||
var r = callback(cur); | ||
if (r === 'break') { | ||
return; | ||
} else if (r) { | ||
return cur; | ||
} else { | ||
cur = cur.parentElement; | ||
} | ||
} | ||
} | ||
function backupAttr(el, name) { | ||
var key = "original_".concat(name); | ||
el[key] = el.getAttribute(name); | ||
} | ||
function restoreAttr(el, name) { | ||
var key = "original_".concat(name); | ||
el.setAttribute(name, el[key]); | ||
} // source: http://youmightnotneedjquery.com/ | ||
function hasClass(el, className) { | ||
if (el.classList) { | ||
return el.classList.contains(className); | ||
} else { | ||
return new RegExp('(^| )' + className + '( |$)', 'gi').test(el.className); | ||
} | ||
} // source: http://youmightnotneedjquery.com/ | ||
function addClass(el, className) { | ||
if (!hasClass(el, className)) { | ||
if (el.classList) { | ||
el.classList.add(className); | ||
} else { | ||
el.className += ' ' + className; | ||
} | ||
} | ||
} // source: http://youmightnotneedjquery.com/ | ||
/*! | ||
* drag-event-service v1.0.1 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
/*! | ||
* helper-js v1.4.14 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
function onDOM(el, name, handler) { | ||
for (var _len6 = arguments.length, args = new Array(_len6 > 3 ? _len6 - 3 : 0), _key8 = 3; _key8 < _len6; _key8++) { | ||
args[_key8 - 3] = arguments[_key8]; | ||
} | ||
if (el.addEventListener) { | ||
// 所有主流浏览器,除了 IE 8 及更早 IE版本 | ||
el.addEventListener.apply(el, [name, handler].concat(args)); | ||
} else if (el.attachEvent) { | ||
// IE 8 及更早 IE 版本 | ||
el.attachEvent.apply(el, ["on".concat(name), handler].concat(args)); | ||
} | ||
} | ||
function offDOM(el, name, handler) { | ||
for (var _len7 = arguments.length, args = new Array(_len7 > 3 ? _len7 - 3 : 0), _key9 = 3; _key9 < _len7; _key9++) { | ||
args[_key9 - 3] = arguments[_key9]; | ||
} | ||
if (el.removeEventListener) { | ||
// 所有主流浏览器,除了 IE 8 及更早 IE版本 | ||
el.removeEventListener.apply(el, [name, handler].concat(args)); | ||
} else if (el.detachEvent) { | ||
// IE 8 及更早 IE 版本 | ||
el.detachEvent.apply(el, ["on".concat(name), handler].concat(args)); | ||
} | ||
} // support desktop and mobile | ||
var events = { | ||
start: ['mousedown', 'touchstart'], | ||
move: ['mousemove', 'touchmove'], | ||
end: ['mouseup', 'touchend'] | ||
}; | ||
var index = { | ||
isTouch: function isTouch(e) { | ||
return e.type && e.type.startsWith('touch'); | ||
}, | ||
_getStore: function _getStore(el) { | ||
if (!el._wrapperStore) { | ||
el._wrapperStore = []; | ||
} | ||
return el._wrapperStore; | ||
}, | ||
on: function on(el, name, handler, options) { | ||
var _resolveOptions = resolveOptions(options), | ||
args = _resolveOptions.args, | ||
mouseArgs = _resolveOptions.mouseArgs, | ||
touchArgs = _resolveOptions.touchArgs; | ||
var store = this._getStore(el); | ||
var ts = this; | ||
var wrapper = function wrapper(e) { | ||
var mouse; | ||
var isTouch = ts.isTouch(e); | ||
if (isTouch) { | ||
// touch | ||
mouse = { | ||
x: e.changedTouches[0].pageX, | ||
y: e.changedTouches[0].pageY | ||
}; | ||
} else { | ||
// mouse | ||
mouse = { | ||
x: e.pageX, | ||
y: e.pageY | ||
}; | ||
if (name === 'start' && e.which !== 1) { | ||
// not left button mousedown | ||
return; | ||
} | ||
} | ||
return handler.call(this, e, mouse); | ||
}; | ||
store.push({ | ||
handler: handler, | ||
wrapper: wrapper | ||
}); // follow format will cause big bundle size | ||
// 以下写法将会使打包工具认为hp是上下文, 导致打包整个hp | ||
// hp.onDOM(el, events[name][0], wrapper, ...args) | ||
onDOM.call.apply(onDOM, [null, el, events[name][0], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
onDOM.call.apply(onDOM, [null, el, events[name][1], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(touchArgs)))); | ||
}, | ||
off: function off(el, name, handler, options) { | ||
var _resolveOptions2 = resolveOptions(options), | ||
args = _resolveOptions2.args, | ||
mouseArgs = _resolveOptions2.mouseArgs; | ||
var store = this._getStore(el); | ||
for (var i = store.length - 1; i >= 0; i--) { | ||
var _store$i = store[i], | ||
handler2 = _store$i.handler, | ||
wrapper = _store$i.wrapper; | ||
if (handler === handler2) { | ||
offDOM.call.apply(offDOM, [null, el, events[name][0], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
offDOM.call.apply(offDOM, [null, el, events[name][1], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
store.splice(i, 1); | ||
} | ||
} | ||
} | ||
}; | ||
function resolveOptions(options) { | ||
if (!options) { | ||
options = {}; | ||
} | ||
var args = options.args || []; | ||
var mouseArgs = options.mouseArgs || []; | ||
var touchArgs = options.touchArgs || []; | ||
return { | ||
args: args, | ||
mouseArgs: mouseArgs, | ||
touchArgs: touchArgs | ||
}; | ||
} | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
/*** | ||
@@ -366,5 +59,5 @@ const destroy = draggableHelper(HTMLElement dragHandlerEl, Object opt = {}) | ||
var UNDRAGGABLE_CLASS = 'undraggable'; | ||
function index$1 (dragHandlerEl) { | ||
function index (dragHandlerEl) { | ||
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
opt = _objectSpread2({ | ||
opt = _objectSpread({ | ||
minTranslate: 10, | ||
@@ -375,4 +68,4 @@ draggingClass: 'dragging' | ||
var destroy = function destroy() { | ||
index.off(dragHandlerEl, 'start', dragHandlerEl._draggbleEventHandler); | ||
var destroy = () => { | ||
DragEventService.off(dragHandlerEl, 'start', dragHandlerEl._draggbleEventHandler); | ||
delete dragHandlerEl._draggbleEventHandler; | ||
@@ -386,3 +79,3 @@ }; | ||
dragHandlerEl._draggbleEventHandler = start; | ||
index.on(dragHandlerEl, 'start', start); | ||
DragEventService.on(dragHandlerEl, 'start', start); | ||
return destroy; | ||
@@ -404,3 +97,3 @@ | ||
var isParentUndraggable = findParent(e.target, function (el) { | ||
var isParentUndraggable = findParent(e.target, el => { | ||
if (hasClass(el, UNDRAGGABLE_CLASS)) { | ||
@@ -426,3 +119,3 @@ return true; | ||
store.startEvent = e; | ||
store.initialMouse = _objectSpread2({}, store.mouse); | ||
store.initialMouse = _objectSpread({}, store.mouse); | ||
/* | ||
@@ -433,3 +126,3 @@ must set passive false for touch, else the follow error occurs in Chrome: | ||
index.on(document, 'move', moving, { | ||
DragEventService.on(document, 'move', moving, { | ||
touchArgs: [{ | ||
@@ -439,3 +132,3 @@ passive: false | ||
}); | ||
index.on(window, 'end', drop); | ||
DragEventService.on(window, 'end', drop); | ||
} | ||
@@ -450,8 +143,8 @@ | ||
var _resolveDragedElAndIn = resolveDragedElAndInitialPosition(), | ||
el = _resolveDragedElAndIn.el, | ||
position = _resolveDragedElAndIn.position; | ||
var { | ||
el, | ||
position | ||
} = resolveDragedElAndInitialPosition(); | ||
store.el = el; | ||
store.initialPosition = _objectSpread2({}, position); | ||
store.initialPosition = _objectSpread({}, position); | ||
canDrag = opt.drag && opt.drag(store.startEvent, e, store, opt); | ||
@@ -466,3 +159,3 @@ | ||
var style = _objectSpread2({ | ||
var style = _objectSpread({ | ||
width: "".concat(Math.ceil(size.width), "px"), | ||
@@ -538,3 +231,3 @@ height: "".concat(Math.ceil(size.height), "px"), | ||
function drop(e) { | ||
index.off(document, 'move', moving, { | ||
DragEventService.off(document, 'move', moving, { | ||
touchArgs: [{ | ||
@@ -544,3 +237,3 @@ passive: false | ||
}); | ||
index.off(window, 'end', drop); // drag executed if movedCount > 0 | ||
DragEventService.off(window, 'end', drop); // drag executed if movedCount > 0 | ||
@@ -550,6 +243,7 @@ if (store.movedCount > 0) { | ||
store.endEvent = e; | ||
var _store = store, | ||
el = _store.el; | ||
var { | ||
el | ||
} = store; | ||
var restoreDOM = function restoreDOM() { | ||
var restoreDOM = () => { | ||
if (opt.clone) { | ||
@@ -587,3 +281,3 @@ el.parentElement.removeChild(el); | ||
position: getPosition(el0), | ||
el: el | ||
el | ||
}; | ||
@@ -599,2 +293,2 @@ } | ||
export default index$1; | ||
export default index; |
/*! | ||
* draggable-helper v3.0.3 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
* draggable-helper v3.0.4 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) : | ||
typeof define === 'function' && define.amd ? define(['exports'], factory) : | ||
(global = global || self, factory(global.draggableHelper = {})); | ||
}(this, (function (exports) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory() : | ||
typeof define === 'function' && define.amd ? define(factory) : | ||
(global = global || self, global.draggableHelper = factory()); | ||
}(this, (function () { 'use strict'; | ||
@@ -27,56 +27,10 @@ function _defineProperty(obj, key, value) { | ||
function ownKeys(object, enumerableOnly) { | ||
var keys = Object.keys(object); | ||
var defineProperty = _defineProperty; | ||
if (Object.getOwnPropertySymbols) { | ||
var symbols = Object.getOwnPropertySymbols(object); | ||
if (enumerableOnly) symbols = symbols.filter(function (sym) { | ||
return Object.getOwnPropertyDescriptor(object, sym).enumerable; | ||
}); | ||
keys.push.apply(keys, symbols); | ||
} | ||
/*! | ||
* helper-js v1.4.21 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
return keys; | ||
} | ||
function _objectSpread2(target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
var source = arguments[i] != null ? arguments[i] : {}; | ||
if (i % 2) { | ||
ownKeys(Object(source), true).forEach(function (key) { | ||
_defineProperty(target, key, source[key]); | ||
}); | ||
} else if (Object.getOwnPropertyDescriptors) { | ||
Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); | ||
} else { | ||
ownKeys(Object(source)).forEach(function (key) { | ||
Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); | ||
}); | ||
} | ||
} | ||
return target; | ||
} | ||
function _toConsumableArray(arr) { | ||
return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); | ||
} | ||
function _arrayWithoutHoles(arr) { | ||
if (Array.isArray(arr)) { | ||
for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) arr2[i] = arr[i]; | ||
return arr2; | ||
} | ||
} | ||
function _iterableToArray(iter) { | ||
if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); | ||
} | ||
function _nonIterableSpread() { | ||
throw new TypeError("Invalid attempt to spread non-iterable instance"); | ||
} | ||
function getOffsetParent(el) { | ||
@@ -94,3 +48,2 @@ var offsetParent = el.offsetParent; | ||
function getPosition(el) { | ||
@@ -117,3 +70,2 @@ var offsetParent = getOffsetParent(el); | ||
} // get position of a el if its offset is given. like jQuery.offset. | ||
function getBoundingClientRect(el) { | ||
@@ -134,13 +86,12 @@ // refer: http://www.51xuediannao.com/javascript/getBoundingClientRect.html | ||
return { | ||
top: top, | ||
right: right, | ||
bottom: bottom, | ||
left: left, | ||
width: width, | ||
height: height, | ||
x: x, | ||
y: y | ||
top, | ||
right, | ||
bottom, | ||
left, | ||
width, | ||
height, | ||
x, | ||
y | ||
}; | ||
} | ||
function findParent(el, callback, opt) { | ||
@@ -161,3 +112,2 @@ var cur = opt && opt.withSelf ? el : el.parentElement; | ||
} | ||
function backupAttr(el, name) { | ||
@@ -167,3 +117,2 @@ var key = "original_".concat(name); | ||
} | ||
function restoreAttr(el, name) { | ||
@@ -174,3 +123,2 @@ var key = "original_".concat(name); | ||
function hasClass(el, className) { | ||
@@ -184,3 +132,2 @@ if (el.classList) { | ||
function addClass(el, className) { | ||
@@ -196,13 +143,2 @@ if (!hasClass(el, className)) { | ||
/*! | ||
* drag-event-service v1.0.1 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
/*! | ||
* helper-js v1.4.14 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
function onDOM(el, name, handler) { | ||
@@ -215,9 +151,8 @@ for (var _len6 = arguments.length, args = new Array(_len6 > 3 ? _len6 - 3 : 0), _key8 = 3; _key8 < _len6; _key8++) { | ||
// 所有主流浏览器,除了 IE 8 及更早 IE版本 | ||
el.addEventListener.apply(el, [name, handler].concat(args)); | ||
el.addEventListener(name, handler, ...args); | ||
} else if (el.attachEvent) { | ||
// IE 8 及更早 IE 版本 | ||
el.attachEvent.apply(el, ["on".concat(name), handler].concat(args)); | ||
el.attachEvent("on".concat(name), handler, ...args); | ||
} | ||
} | ||
function offDOM(el, name, handler) { | ||
@@ -230,10 +165,16 @@ for (var _len7 = arguments.length, args = new Array(_len7 > 3 ? _len7 - 3 : 0), _key9 = 3; _key9 < _len7; _key9++) { | ||
// 所有主流浏览器,除了 IE 8 及更早 IE版本 | ||
el.removeEventListener.apply(el, [name, handler].concat(args)); | ||
el.removeEventListener(name, handler, ...args); | ||
} else if (el.detachEvent) { | ||
// IE 8 及更早 IE 版本 | ||
el.detachEvent.apply(el, ["on".concat(name), handler].concat(args)); | ||
el.detachEvent("on".concat(name), handler, ...args); | ||
} | ||
} // support desktop and mobile | ||
} | ||
/*! | ||
* drag-event-service v1.0.2 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
// support desktop and mobile | ||
var events = { | ||
@@ -245,6 +186,7 @@ start: ['mousedown', 'touchstart'], | ||
var index = { | ||
isTouch: function isTouch(e) { | ||
isTouch(e) { | ||
return e.type && e.type.startsWith('touch'); | ||
}, | ||
_getStore: function _getStore(el) { | ||
_getStore(el) { | ||
if (!el._wrapperStore) { | ||
@@ -256,8 +198,10 @@ el._wrapperStore = []; | ||
}, | ||
on: function on(el, name, handler, options) { | ||
var _resolveOptions = resolveOptions(options), | ||
args = _resolveOptions.args, | ||
mouseArgs = _resolveOptions.mouseArgs, | ||
touchArgs = _resolveOptions.touchArgs; | ||
on(el, name, handler, options) { | ||
var { | ||
args, | ||
mouseArgs, | ||
touchArgs | ||
} = resolveOptions(options); | ||
var store = this._getStore(el); | ||
@@ -294,4 +238,4 @@ | ||
store.push({ | ||
handler: handler, | ||
wrapper: wrapper | ||
handler, | ||
wrapper | ||
}); // follow format will cause big bundle size | ||
@@ -301,20 +245,24 @@ // 以下写法将会使打包工具认为hp是上下文, 导致打包整个hp | ||
onDOM.call.apply(onDOM, [null, el, events[name][0], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
onDOM.call.apply(onDOM, [null, el, events[name][1], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(touchArgs)))); | ||
onDOM.call(null, el, events[name][0], wrapper, ...[...args, ...mouseArgs]); | ||
onDOM.call(null, el, events[name][1], wrapper, ...[...args, ...touchArgs]); | ||
}, | ||
off: function off(el, name, handler, options) { | ||
var _resolveOptions2 = resolveOptions(options), | ||
args = _resolveOptions2.args, | ||
mouseArgs = _resolveOptions2.mouseArgs; | ||
off(el, name, handler, options) { | ||
var { | ||
args, | ||
mouseArgs, | ||
touchArgs | ||
} = resolveOptions(options); | ||
var store = this._getStore(el); | ||
for (var i = store.length - 1; i >= 0; i--) { | ||
var _store$i = store[i], | ||
handler2 = _store$i.handler, | ||
wrapper = _store$i.wrapper; | ||
var { | ||
handler: handler2, | ||
wrapper | ||
} = store[i]; | ||
if (handler === handler2) { | ||
offDOM.call.apply(offDOM, [null, el, events[name][0], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
offDOM.call.apply(offDOM, [null, el, events[name][1], wrapper].concat([].concat(_toConsumableArray(args), _toConsumableArray(mouseArgs)))); | ||
offDOM.call(null, el, events[name][0], wrapper, ...[...args, ...mouseArgs]); | ||
offDOM.call(null, el, events[name][1], wrapper, ...[...args, ...mouseArgs]); | ||
store.splice(i, 1); | ||
@@ -324,2 +272,3 @@ } | ||
} | ||
}; | ||
@@ -336,8 +285,11 @@ | ||
return { | ||
args: args, | ||
mouseArgs: mouseArgs, | ||
touchArgs: touchArgs | ||
args, | ||
mouseArgs, | ||
touchArgs | ||
}; | ||
} | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
/*** | ||
@@ -391,3 +343,3 @@ const destroy = draggableHelper(HTMLElement dragHandlerEl, Object opt = {}) | ||
var opt = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
opt = _objectSpread2({ | ||
opt = _objectSpread({ | ||
minTranslate: 10, | ||
@@ -446,3 +398,3 @@ draggingClass: 'dragging' | ||
store.startEvent = e; | ||
store.initialMouse = _objectSpread2({}, store.mouse); | ||
store.initialMouse = _objectSpread({}, store.mouse); | ||
/* | ||
@@ -473,3 +425,3 @@ must set passive false for touch, else the follow error occurs in Chrome: | ||
store.el = el; | ||
store.initialPosition = _objectSpread2({}, position); | ||
store.initialPosition = _objectSpread({}, position); | ||
canDrag = opt.drag && opt.drag(store.startEvent, e, store, opt); | ||
@@ -484,3 +436,3 @@ | ||
var style = _objectSpread2({ | ||
var style = _objectSpread({ | ||
width: "".concat(Math.ceil(size.width), "px"), | ||
@@ -613,6 +565,4 @@ height: "".concat(Math.ceil(size.height), "px"), | ||
exports.default = index$1; | ||
return index$1; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
}))); |
/*! | ||
* draggable-helper v3.0.3 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t=t||self).draggableHelper={})}(this,(function(t){"use strict";function e(t,e,n){return e in t?Object.defineProperty(t,e,{value:n,enumerable:!0,configurable:!0,writable:!0}):t[e]=n,t}function n(t,e){var n=Object.keys(t);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(t);e&&(r=r.filter((function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable}))),n.push.apply(n,r)}return n}function r(t){for(var r=1;r<arguments.length;r++){var o=null!=arguments[r]?arguments[r]:{};r%2?n(Object(o),!0).forEach((function(n){e(t,n,o[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(o)):n(Object(o)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(o,e))}))}return t}function o(t){return function(t){if(Array.isArray(t)){for(var e=0,n=new Array(t.length);e<t.length;e++)n[e]=t[e];return n}}(t)||function(t){if(Symbol.iterator in Object(t)||"[object Arguments]"===Object.prototype.toString.call(t))return Array.from(t)}(t)||function(){throw new TypeError("Invalid attempt to spread non-iterable instance")}()}function a(t){for(var e=function(t){var e=t.offsetParent;return(!e||e===document.body&&"static"===getComputedStyle(document.body).position)&&(e=document.body.parentElement),e}(t),n={x:t.offsetLeft,y:t.offsetTop},r=t;(r=r.parentElement)!==e&&r;)n.x-=r.scrollLeft,n.y-=r.scrollTop;return n}function i(t,e){t["original_".concat(e)]=t.getAttribute(e)}function c(t,e){var n="original_".concat(e);t.setAttribute(e,t[n])}function l(t,e){return t.classList?t.classList.contains(e):new RegExp("(^| )"+e+"( |$)","gi").test(t.className)} | ||
* draggable-helper v3.0.4 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).draggableHelper=t()}(this,(function(){"use strict";var e=function(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}; | ||
/*! | ||
* drag-event-service v1.0.1 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
* helper-js v1.4.21 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/function t(e){for(var t=function(e){var t=e.offsetParent;return(!t||t===document.body&&"static"===getComputedStyle(document.body).position)&&(t=document.body.parentElement),t}(e),n={x:e.offsetLeft,y:e.offsetTop},r=e;(r=r.parentElement)!==t&&r;)n.x-=r.scrollLeft,n.y-=r.scrollTop;return n}function n(e){var t=e.getBoundingClientRect(),n=t.top-document.documentElement.clientTop,r=t.bottom,o=t.left-document.documentElement.clientLeft,a=t.right;return{top:n,right:a,bottom:r,left:o,width:t.width||a-o,height:t.height||r-n,x:o,y:n}}function r(e,t,n){for(var r=n&&n.withSelf?e:e.parentElement;r;){var o=t(r);if("break"===o)return;if(o)return r;r=r.parentElement}}function o(e,t){e["original_".concat(t)]=e.getAttribute(t)}function a(e,t){var n="original_".concat(t);e.setAttribute(t,e[n])}function i(e,t){return e.classList?e.classList.contains(t):new RegExp("(^| )"+t+"( |$)","gi").test(e.className)}function l(e,t){i(e,t)||(e.classList?e.classList.add(t):e.className+=" "+t)}function s(e,t,n){for(var r=arguments.length,o=new Array(r>3?r-3:0),a=3;a<r;a++)o[a-3]=arguments[a];e.addEventListener?e.addEventListener(t,n,...o):e.attachEvent&&e.attachEvent("on".concat(t),n,...o)}function u(e,t,n){for(var r=arguments.length,o=new Array(r>3?r-3:0),a=3;a<r;a++)o[a-3]=arguments[a];e.removeEventListener?e.removeEventListener(t,n,...o):e.detachEvent&&e.detachEvent("on".concat(t),n,...o)} | ||
/*! | ||
* helper-js v1.4.14 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/ | ||
function u(t,e,n){for(var r=arguments.length,o=new Array(r>3?r-3:0),a=3;a<r;a++)o[a-3]=arguments[a];t.addEventListener?t.addEventListener.apply(t,[e,n].concat(o)):t.attachEvent&&t.attachEvent.apply(t,["on".concat(e),n].concat(o))}function s(t,e,n){for(var r=arguments.length,o=new Array(r>3?r-3:0),a=3;a<r;a++)o[a-3]=arguments[a];t.removeEventListener?t.removeEventListener.apply(t,[e,n].concat(o)):t.detachEvent&&t.detachEvent.apply(t,["on".concat(e),n].concat(o))}var f={start:["mousedown","touchstart"],move:["mousemove","touchmove"],end:["mouseup","touchend"]},p={isTouch:function(t){return t.type&&t.type.startsWith("touch")},_getStore:function(t){return t._wrapperStore||(t._wrapperStore=[]),t._wrapperStore},on:function(t,e,n,r){var a=g(r),i=a.args,c=a.mouseArgs,l=a.touchArgs,s=this._getStore(t),p=this,d=function(t){var r;if(p.isTouch(t))r={x:t.changedTouches[0].pageX,y:t.changedTouches[0].pageY};else if(r={x:t.pageX,y:t.pageY},"start"===e&&1!==t.which)return;return n.call(this,t,r)};s.push({handler:n,wrapper:d}),u.call.apply(u,[null,t,f[e][0],d].concat([].concat(o(i),o(c)))),u.call.apply(u,[null,t,f[e][1],d].concat([].concat(o(i),o(l))))},off:function(t,e,n,r){for(var a=g(r),i=a.args,c=a.mouseArgs,l=this._getStore(t),u=l.length-1;u>=0;u--){var p=l[u],d=p.handler,v=p.wrapper;n===d&&(s.call.apply(s,[null,t,f[e][0],v].concat([].concat(o(i),o(c)))),s.call.apply(s,[null,t,f[e][1],v].concat([].concat(o(i),o(c)))),l.splice(u,1))}}};function g(t){return t||(t={}),{args:t.args||[],mouseArgs:t.mouseArgs||[],touchArgs:t.touchArgs||[]}}var d=["INPUT","TEXTAREA","SELECT","OPTGROUP","OPTION"],v="undraggable";t.default=function(t){var e=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};e=r({minTranslate:10,draggingClass:"dragging"},e);var n={movedCount:0},o=function(){p.off(t,"start",t._draggbleEventHandler),delete t._draggbleEventHandler};return t._draggbleEventHandler&&o(),t._draggbleEventHandler=u,p.on(t,"start",u),o;function u(o,a){e.triggerBySelf&&o.target!==t||(d.includes(o.target.tagName)||l(o.target,v)||function(t,e,n){for(var r=n&&n.withSelf?t:t.parentElement;r;){var o=e(r);if("break"===o)return;if(o)return r;r=r.parentElement}}(o.target,(function(e){return!!l(e,v)||(e===t?"break":void 0)}))||(o.preventDefault(),n.mouse={x:a.x,y:a.y},n.startEvent=o,n.initialMouse=r({},n.mouse),p.on(document,"move",f,{touchArgs:[{passive:!1}]}),p.on(window,"end",g)))}function s(o){var c=e.beforeDrag&&e.beforeDrag(n.startEvent,o,n,e);if(!1===c)return!1;var u=function(){var r=e.getEl?e.getEl(t,n,e):t,o=r;n.originalEl=r,e.clone&&(o=r.cloneNode(!0),r.parentElement.appendChild(o));return{position:a(r),el:o}}(),s=u.el,f=u.position;if(n.el=s,n.initialPosition=r({},f),!1===(c=e.drag&&e.drag(n.startEvent,o,n,e)))return!1;var p=function(t){var e=t.getBoundingClientRect(),n=e.top-document.documentElement.clientTop,r=e.bottom,o=e.left-document.documentElement.clientLeft,a=e.right;return{top:n,right:a,bottom:r,left:o,width:e.width||a-o,height:e.height||r-n,x:o,y:n}}(s),g=r({width:"".concat(Math.ceil(p.width),"px"),height:"".concat(Math.ceil(p.height),"px"),zIndex:9999,opacity:.8,position:"absolute",left:f.x+"px",top:f.y+"px"},e.style||e.getStyle&&e.getStyle(n,e)||{});for(var d in i(s,"style"),g)s.style[d]=g[d];i(s,"class"),function(t,e){l(t,e)||(t.classList?t.classList.add(e):t.className+=" "+e)}(s,e.draggingClass)}function f(t,r){t.preventDefault(),n.mouse={x:r.x,y:r.y};var o=n.move={x:n.mouse.x-n.initialMouse.x,y:n.mouse.y-n.initialMouse.y};if(0===n.movedCount&&e.minTranslate){var a=Math.pow(n.move.x,2),i=Math.pow(n.move.y,2);if(Math.pow(a+i,.5)<e.minTranslate)return}var c=!0;if(0===n.movedCount&&!1===s(t)&&(c=!1),c&&e.moving&&!1===e.moving(t,n,e)&&(c=!1),c){if(!n||!n.el)return;Object.assign(n.el.style,{left:n.initialPosition.x+o.x+"px",top:n.initialPosition.y+o.y+"px"}),n.movedCount++}}function g(t){if(p.off(document,"move",f,{touchArgs:[{passive:!1}]}),p.off(window,"end",g),n.movedCount>0){n.movedCount=0,n.endEvent=t;var r=n.el,o=function(){e.clone?r.parentElement.removeChild(r):(c(r,"style"),c(r,"class"))};e.restoreDOMManuallyOndrop||(o(),o=null),n.restoreDOM=o,e.drop&&e.drop(t,n,e)}n={movedCount:0}}},Object.defineProperty(t,"__esModule",{value:!0})})); | ||
//# sourceMappingURL=draggable-helper.min.js.map | ||
* drag-event-service v1.0.2 | ||
* (c) phphe <phphe@outlook.com> (https://github.com/phphe) | ||
* Released under the MIT License. | ||
*/var c={start:["mousedown","touchstart"],move:["mousemove","touchmove"],end:["mouseup","touchend"]},f={isTouch:e=>e.type&&e.type.startsWith("touch"),_getStore:e=>(e._wrapperStore||(e._wrapperStore=[]),e._wrapperStore),on(e,t,n,r){var{args:o,mouseArgs:a,touchArgs:i}=g(r),l=this._getStore(e),u=this,f=function(e){var r;if(u.isTouch(e))r={x:e.changedTouches[0].pageX,y:e.changedTouches[0].pageY};else if(r={x:e.pageX,y:e.pageY},"start"===t&&1!==e.which)return;return n.call(this,e,r)};l.push({handler:n,wrapper:f}),s.call(null,e,c[t][0],f,...o,...a),s.call(null,e,c[t][1],f,...o,...i)},off(e,t,n,r){for(var{args:o,mouseArgs:a,touchArgs:i}=g(r),l=this._getStore(e),s=l.length-1;s>=0;s--){var{handler:f,wrapper:d}=l[s];n===f&&(u.call(null,e,c[t][0],d,...o,...a),u.call(null,e,c[t][1],d,...o,...a),l.splice(s,1))}}};function g(e){return e||(e={}),{args:e.args||[],mouseArgs:e.mouseArgs||[],touchArgs:e.touchArgs||[]}}function d(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function p(t){for(var n=1;n<arguments.length;n++){var r=null!=arguments[n]?arguments[n]:{};n%2?d(Object(r),!0).forEach((function(n){e(t,n,r[n])})):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):d(Object(r)).forEach((function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))}))}return t}var v=["INPUT","TEXTAREA","SELECT","OPTGROUP","OPTION"];return function(e){var s=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};s=p({minTranslate:10,draggingClass:"dragging"},s);var u={movedCount:0},c=function(){f.off(e,"start",e._draggbleEventHandler),delete e._draggbleEventHandler};return e._draggbleEventHandler&&c(),e._draggbleEventHandler=g,f.on(e,"start",g),c;function g(t,n){s.triggerBySelf&&t.target!==e||(v.includes(t.target.tagName)||i(t.target,"undraggable")||r(t.target,(function(t){return!!i(t,"undraggable")||(t===e?"break":void 0)}))||(t.preventDefault(),u.mouse={x:n.x,y:n.y},u.startEvent=t,u.initialMouse=p({},u.mouse),f.on(document,"move",m,{touchArgs:[{passive:!1}]}),f.on(window,"end",h)))}function d(e){var t=s.beforeDrag&&s.beforeDrag(u.startEvent,e,u,s);if(!1===t)return!1;var r=y(),a=r.el,i=r.position;if(u.el=a,u.initialPosition=p({},i),!1===(t=s.drag&&s.drag(u.startEvent,e,u,s)))return!1;var c=n(a),f=p({width:"".concat(Math.ceil(c.width),"px"),height:"".concat(Math.ceil(c.height),"px"),zIndex:9999,opacity:.8,position:"absolute",left:i.x+"px",top:i.y+"px"},s.style||s.getStyle&&s.getStyle(u,s)||{});for(var g in o(a,"style"),f)a.style[g]=f[g];o(a,"class"),l(a,s.draggingClass)}function m(e,t){e.preventDefault(),u.mouse={x:t.x,y:t.y};var n=u.move={x:u.mouse.x-u.initialMouse.x,y:u.mouse.y-u.initialMouse.y};if(0===u.movedCount&&s.minTranslate){var r=Math.pow(u.move.x,2),o=Math.pow(u.move.y,2);if(Math.pow(r+o,.5)<s.minTranslate)return}var a=!0;if(0===u.movedCount&&!1===d(e)&&(a=!1),a&&s.moving&&!1===s.moving(e,u,s)&&(a=!1),a){if(!u||!u.el)return;Object.assign(u.el.style,{left:u.initialPosition.x+n.x+"px",top:u.initialPosition.y+n.y+"px"}),u.movedCount++}}function h(e){if(f.off(document,"move",m,{touchArgs:[{passive:!1}]}),f.off(window,"end",h),u.movedCount>0){u.movedCount=0,u.endEvent=e;var t=u.el,n=function(){s.clone?t.parentElement.removeChild(t):(a(t,"style"),a(t,"class"))};s.restoreDOMManuallyOndrop||(n(),n=null),u.restoreDOM=n,s.drop&&s.drop(e,u,s)}u={movedCount:0}}function y(){var n=s.getEl?s.getEl(e,u,s):e,r=n;return u.originalEl=n,s.clone&&(r=n.cloneNode(!0),n.parentElement.appendChild(r)),{position:t(n),el:r}}}})); |
{ | ||
"name": "draggable-helper", | ||
"version": "3.0.3", | ||
"version": "3.0.4", | ||
"description": "", | ||
@@ -25,9 +25,10 @@ "main": "dist/draggable-helper.cjs.js", | ||
"devDependencies": { | ||
"rollup-helper": "^2.0.1" | ||
"rollup-helper": "^2.0.12" | ||
}, | ||
"dependencies": { | ||
"drag-event-service": "^1.0.1", | ||
"helper-js": "^1.4.14" | ||
"@babel/runtime": "^7.7.7", | ||
"drag-event-service": "^1.0.2", | ||
"helper-js": "^1.4.21" | ||
}, | ||
"license": "MIT" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
43117
3
7
968
+ Added@babel/runtime@^7.7.7
Updateddrag-event-service@^1.0.2
Updatedhelper-js@^1.4.21