Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

oribella-aurelia-sortable

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

oribella-aurelia-sortable - npm Package Compare versions

Comparing version 0.6.0 to 0.7.0

demo/dist/0-0.6.0.js

43

CHANGELOG.md

@@ -0,7 +1,39 @@

<a name="0.7.0"></a>
# 0.7.0 (2016-04-01)
### Bug Fixes
* **package:** update `jspm` `main` file ([12aac4b](https://github.com/oribella/aurelia-sortable/commit/12aac4b))
* **sortable:** rename to `oa-sortable`, `oa-sortable-item` ([1c841d2](https://github.com/oribella/aurelia-sortable/commit/1c841d2)), closes [#10](https://github.com/oribella/aurelia-sortable/issues/10)
### Features
* **document-scroll:** handle `document`scrolling, `parent` scrolling and `sortable` scrolling ([b9f2ead](https://github.com/oribella/aurelia-sortable/commit/b9f2ead)), closes [#12](https://github.com/oribella/aurelia-sortable/issues/12)
* **drag:** add drag element to `viewport` ([502a5ef](https://github.com/oribella/aurelia-sortable/commit/502a5ef))
### BREAKING CHANGES
* drag: `placeholder` not longer exist. If you we using `placeholderClass` before you should use `sortingClass` instead.
* sortable:
* document-scroll: Removed bindable `boundingRect`
<a name="0.6.0"></a>
# 0.6.0 (2016-03-03)
# [0.6.0](https://github.com/oribella/aurelia-sortable/compare/52fe314...v0.6.0) (2016-03-03)
### Chores
* update dependencies ([52fe314](https://github.com/oribella/aurelia-sortable/commit/52fe314))
### BREAKING CHANGES
*
<a name="0.5.3"></a>

@@ -119,4 +151,13 @@ ## [0.5.3](https://github.com/oribella/aurelia-sortable/compare/c0d8e31...v0.5.3) (2015-12-13)

### Chores
* update to latest Aurelia dependencies ([362b735](https://github.com/oribella/aurelia-sortable/commit/362b735))
### BREAKING CHANGES
* s how to access Aurelia APIs. However it's not a breaking change from aurelia-sortable point of view
<a name="0.2.1"></a>

@@ -123,0 +164,0 @@ ## [0.2.1](https://github.com/oribella/aurelia-sortable/compare/c4a0a29...v0.2.1) (2015-08-18)

154

dist/amd/auto-scroll.js

@@ -7,124 +7,84 @@ define(["exports", "aurelia-dependency-injection"], function (exports, _aureliaDependencyInjection) {

});
exports.AutoScroll = undefined;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _dec, _class;
var AutoScroll = (function () {
var AutoScroll = exports.AutoScroll = (_dec = (0, _aureliaDependencyInjection.transient)(), _dec(_class = function () {
function AutoScroll() {
_classCallCheck(this, _AutoScroll);
_classCallCheck(this, AutoScroll);
this.ticks = [0, 0];
this.rAFId = -1;
this.axis = "";
this.speed = 10;
this.sensitivity = 10;
this.active = false;
}
_createClass(AutoScroll, [{
key: "start",
value: function start() {
var axis = arguments.length <= 0 || arguments[0] === undefined ? "" : arguments[0];
var speed = arguments.length <= 1 || arguments[1] === undefined ? 10 : arguments[1];
var sensitivity = arguments.length <= 2 || arguments[2] === undefined ? 10 : arguments[2];
AutoScroll.prototype.start = function start() {
var speed = arguments.length <= 0 || arguments[0] === undefined ? 10 : arguments[0];
this.axis = axis;
this.speed = speed;
this.sensitivity = sensitivity;
this.speed = speed;
};
AutoScroll.prototype.update = function update(element, dirX, dirY, frameCntX, frameCntY) {
var _this = this;
if (this.active) {
if (dirX === 0 && dirY === 0) {
cancelAnimationFrame(this.rAFId);
this.active = false;
}
return;
}
}, {
key: "update",
value: function update(element, x, y, scrollWidth, scrollHeight, scrollRect) {
var _this = this;
if (dirX === 0 && dirY === 0) {
return;
}
var rAF = arguments.length <= 6 || arguments[6] === undefined ? requestAnimationFrame : arguments[6];
var cAF = arguments.length <= 7 || arguments[7] === undefined ? cancelAnimationFrame : arguments[7];
if (frameCntX === 0 && frameCntY === 0) {
return;
}
var d = this.getScrollDirection(x, y, scrollRect);
if (this.active) {
if (d[0] === 0 && d[1] === 0) {
cAF(this.rAFId);
this.active = false;
}
var scrollDeltaX = dirX * this.speed;
var scrollDeltaY = dirY * this.speed;
var autoScroll = function autoScroll() {
if (!_this.active) {
return;
}
if (d[0] === 0 && d[1] === 0) {
return;
if (frameCntX > 0) {
element.scrollLeft += scrollDeltaX;
}
if (frameCntY > 0) {
element.scrollTop += scrollDeltaY;
}
this.ticks = this.getTicks(d, element.scrollLeft, element.scrollTop, scrollWidth, scrollHeight, scrollRect.width, scrollRect.height);
if (this.ticks[0] <= 0 && this.ticks[1] <= 0) {
--frameCntX;
--frameCntY;
if (frameCntX <= 0 && frameCntY <= 0) {
_this.active = false;
return;
}
var scrollDeltaX = d[0] * this.speed;
var scrollDeltaY = d[1] * this.speed;
_this.rAFId = requestAnimationFrame(autoScroll);
};
var autoScroll = function autoScroll() {
this.active = true;
autoScroll();
};
if (_this.ticks[0] > 0) {
element.scrollLeft += scrollDeltaX;
}
if (_this.ticks[1] > 0) {
element.scrollTop += scrollDeltaY;
}
AutoScroll.prototype.end = function end() {
var cAF = arguments.length <= 0 || arguments[0] === undefined ? cancelAnimationFrame : arguments[0];
--_this.ticks[0];
--_this.ticks[1];
if (_this.ticks[0] <= 0 && _this.ticks[1] <= 0) {
_this.active = false;
return;
}
cAF(this.rAFId);
this.active = false;
};
_this.rAFId = rAF(autoScroll);
};
this.active = true;
autoScroll();
}
}, {
key: "end",
value: function end() {
var cAF = arguments.length <= 0 || arguments[0] === undefined ? cancelAnimationFrame : arguments[0];
cAF(this.rAFId);
this.ticks = [0, 0];
}
}, {
key: "getTicks",
value: function getTicks(d, scrollLeft, scrollTop, scrollWidth, scrollHeight, width, height) {
var ticks = [];
ticks[0] = d[0] > 0 ? Math.ceil((scrollWidth - width - scrollLeft) / this.speed) : d[0] < 0 ? scrollLeft / this.speed : 0;
ticks[1] = d[1] > 0 ? Math.ceil((scrollHeight - height - scrollTop) / this.speed) : d[1] < 0 ? scrollTop / this.speed : 0;
return ticks;
}
}, {
key: "getScrollDirection",
value: function getScrollDirection(x, y, scrollRect) {
var left = scrollRect.left;
var top = scrollRect.top;
var right = scrollRect.right;
var _scrollRect$bottom = scrollRect.bottom;
var bottom = _scrollRect$bottom === undefined ? 0 : _scrollRect$bottom;
var d = [0, 0];
d[0] = this.axis === "y" ? 0 : x >= right - this.sensitivity ? 1 : x <= left + this.sensitivity ? -1 : 0;
d[1] = this.axis === "x" ? 0 : y >= bottom - this.sensitivity ? 1 : y <= top + this.sensitivity ? -1 : 0;
return d;
}
}]);
var _AutoScroll = AutoScroll;
AutoScroll = (0, _aureliaDependencyInjection.transient)()(AutoScroll) || AutoScroll;
return AutoScroll;
})();
exports.AutoScroll = AutoScroll;
});
}()) || _class);
});
//# sourceMappingURL=auto-scroll.js.map

@@ -7,10 +7,15 @@ define(["exports", "aurelia-dependency-injection"], function (exports, _aureliaDependencyInjection) {

});
exports.Drag = undefined;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _dec, _class;
var Drag = (function () {
var Drag = exports.Drag = (_dec = (0, _aureliaDependencyInjection.transient)(), _dec(_class = function () {
function Drag() {
_classCallCheck(this, _Drag);
_classCallCheck(this, Drag);

@@ -24,92 +29,93 @@ this.startLeft = 0;

_createClass(Drag, [{
key: "pin",
value: function pin(element, rect, dragZIndex) {
this.element = element;
Drag.prototype.pin = function pin() {
this.item.sortingClass = this.sortingClass;
this.clone = this.element.cloneNode(true);
this.clone.style.position = "absolute";
this.clone.style.width = this.rect.width + "px";
this.clone.style.height = this.rect.height + "px";
this.clone.style.pointerEvents = "none";
this.clone.style.margin = 0;
this.clone.style.zIndex = this.dragZIndex;
document.body.appendChild(this.clone);
};
var style = {};
style.position = element.style.position;
style.left = element.style.left;
style.top = element.style.top;
style.width = element.style.width;
style.height = element.style.height;
style.pointerEvents = element.style.pointerEvents;
style.zIndex = element.style.zIndex;
Drag.prototype.unpin = function unpin() {
this.item.sortingClass = "";
document.body.removeChild(this.clone);
this.clone = null;
};
element.style.position = "absolute";
element.style.width = rect.width + "px";
element.style.height = rect.height + "px";
element.style.pointerEvents = "none";
element.style.zIndex = dragZIndex;
Drag.prototype.getCenterX = function getCenterX() {
return this.rect.left + this.rect.width / 2;
};
return function () {
Object.keys(style).forEach(function (key) {
element.style[key] = style[key];
});
};
}
}, {
key: "getCenterX",
value: function getCenterX() {
return this.rect.left + this.rect.width / 2;
}
}, {
key: "getCenterY",
value: function getCenterY() {
return this.rect.top + this.rect.height / 2;
}
}, {
key: "start",
value: function start(element, pageX, pageY, scrollLeft, scrollTop, dragZIndex) {
var rect = this.rect = element.getBoundingClientRect();
var offsetParentRect = element.offsetParent.getBoundingClientRect();
Drag.prototype.getCenterY = function getCenterY() {
return this.rect.top + this.rect.height / 2;
};
this.startLeft = rect.left - offsetParentRect.left;
this.startTop = rect.top - offsetParentRect.top;
Drag.prototype.start = function start(element, item, x, y, viewportScroll, scrollLeft, scrollTop, dragZIndex, axis, sortingClass, minPosX, maxPosX, minPosY, maxPosY) {
this.element = element;
this.item = item;
this.sortingClass = sortingClass;
this.dragZIndex = dragZIndex;
var rect = this.rect = element.getBoundingClientRect();
this.offsetX = this.startLeft - pageX - scrollLeft;
this.offsetY = this.startTop - pageY - scrollTop;
this.startLeft = rect.left;
this.startTop = rect.top;
this.unpin = this.pin(element, rect, dragZIndex);
this.offsetX = this.startLeft - x;
this.offsetY = this.startTop - y;
this.update(pageX, pageY, scrollLeft, scrollTop);
this.pin();
this.update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY);
};
Drag.prototype.update = function update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY) {
x += this.offsetX;
y += this.offsetY;
if (viewportScroll) {
x += scrollLeft;
y += scrollTop;
}
}, {
key: "update",
value: function update(pageX, pageY, scrollLeft, scrollTop, axis) {
var left = pageX + this.offsetX + scrollLeft;
var top = pageY + this.offsetY + scrollTop;
switch (axis) {
case "x":
top = this.startTop;
break;
case "y":
left = this.startLeft;
break;
default:
break;
}
if (x < minPosX) {
x = minPosX;
}
if (x > maxPosX - this.rect.width) {
x = maxPosX - this.rect.width;
}
this.element.style.left = left + "px";
this.element.style.top = top + "px";
if (y < minPosY) {
y = minPosY;
}
}, {
key: "end",
value: function end() {
if (this.element) {
if (typeof this.unpin === "function") {
this.unpin();
}
this.element = null;
}
if (y > maxPosY - this.rect.height) {
y = maxPosY - this.rect.height;
}
}]);
var _Drag = Drag;
Drag = (0, _aureliaDependencyInjection.transient)()(Drag) || Drag;
switch (axis) {
case "x":
y = this.startTop;
break;
case "y":
x = this.startLeft;
break;
}
this.clone.style.left = x + "px";
this.clone.style.top = y + "px";
};
Drag.prototype.end = function end() {
if (this.element === null) {
return;
}
this.unpin();
this.element = null;
this.item = null;
};
return Drag;
})();
exports.Drag = Drag;
});
}()) || _class);
});
//# sourceMappingURL=drag.js.map

@@ -8,6 +8,6 @@ define(["exports"], function (exports) {

exports.configure = configure;
function configure(config) {
config.globalResources("./sortable");
}
});
});
//# sourceMappingURL=index.js.map

@@ -7,149 +7,90 @@ define(["exports", "aurelia-pal", "aurelia-templating", "aurelia-dependency-injection", "oribella-default-gestures", "./drag", "./auto-scroll"], function (exports, _aureliaPal, _aureliaTemplating, _aureliaDependencyInjection, _oribellaDefaultGestures, _drag, _autoScroll) {

});
exports.SortableItem = exports.Sortable = undefined;
var _createDecoratedClass = (function () { function defineProperties(target, descriptors, initializers) { for (var i = 0; i < descriptors.length; i++) { var descriptor = descriptors[i]; var decorators = descriptor.decorators; var key = descriptor.key; delete descriptor.key; delete descriptor.decorators; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor || descriptor.initializer) descriptor.writable = true; if (decorators) { for (var f = 0; f < decorators.length; f++) { var decorator = decorators[f]; if (typeof decorator === "function") { descriptor = decorator(target, key, descriptor) || descriptor; } else { throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator); } } if (descriptor.initializer !== undefined) { initializers[key] = descriptor; continue; } } Object.defineProperty(target, key, descriptor); } } return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) { if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers); if (staticProps) defineProperties(Constructor, staticProps, staticInitializers); return Constructor; }; })();
function _initDefineProp(target, property, descriptor, context) {
if (!descriptor) return;
Object.defineProperty(target, property, {
enumerable: descriptor.enumerable,
configurable: descriptor.configurable,
writable: descriptor.writable,
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
});
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineDecoratedPropertyDescriptor(target, key, descriptors) { var _descriptor = descriptors[key]; if (!_descriptor) return; var descriptor = {}; for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; descriptor.value = descriptor.initializer ? descriptor.initializer.call(target) : undefined; Object.defineProperty(target, key, descriptor); }
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
var PLACEHOLDER = "__placeholder__";
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
exports.PLACEHOLDER = PLACEHOLDER;
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
var Sortable = (function () {
var _instanceInitializers = {};
var _instanceInitializers = {};
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
_createDecoratedClass(Sortable, [{
key: "scroll",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return null;
},
enumerable: true
}, {
key: "scrollSpeed",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return 10;
},
enumerable: true
}, {
key: "scrollSensitivity",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return 10;
},
enumerable: true
}, {
key: "items",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return [];
},
enumerable: true
}, {
key: "placeholderClass",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return "placeholder";
},
enumerable: true
}, {
key: "axis",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return "";
},
enumerable: true
}, {
key: "boundingRect",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return null;
},
//{ left, top, right, bottom }
enumerable: true
}, {
key: "moved",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return function () {};
},
enumerable: true
}, {
key: "dragZIndex",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return 1;
},
enumerable: true
}, {
key: "disallowedDragTagNames",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return ["INPUT", "SELECT", "TEXTAREA"];
},
enumerable: true
}, {
key: "allowDrag",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
var _this = this;
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return function (args) {
if (_this.disallowedDragTagNames.indexOf(args.event.target.tagName) !== -1) {
return false;
}
if (args.event.target.isContentEditable) {
return false;
}
return true;
};
},
enumerable: true
}, {
key: "allowMove",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return function () {
return true;
};
},
enumerable: true
}], null, _instanceInitializers);
return desc;
}
function _initializerWarningHelper(descriptor, context) {
throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
}
var _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _dec4, _class4, _desc2, _value2, _class5, _descriptor13;
var SORTABLE_ITEM = "oa-sortable-item";
var Sortable = exports.Sortable = (_dec = (0, _aureliaTemplating.customAttribute)("oa-sortable"), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaPal.DOM.Element, _drag.Drag, _autoScroll.AutoScroll), _dec3 = (0, _aureliaDependencyInjection.transient)(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = function () {
function Sortable(element, drag, autoScroll) {
_classCallCheck(this, _Sortable);
_classCallCheck(this, Sortable);
_defineDecoratedPropertyDescriptor(this, "scroll", _instanceInitializers);
_initDefineProp(this, "scroll", _descriptor, this);
_defineDecoratedPropertyDescriptor(this, "scrollSpeed", _instanceInitializers);
_initDefineProp(this, "scrollSpeed", _descriptor2, this);
_defineDecoratedPropertyDescriptor(this, "scrollSensitivity", _instanceInitializers);
_initDefineProp(this, "scrollSensitivity", _descriptor3, this);
_defineDecoratedPropertyDescriptor(this, "items", _instanceInitializers);
_initDefineProp(this, "items", _descriptor4, this);
_defineDecoratedPropertyDescriptor(this, "placeholderClass", _instanceInitializers);
_initDefineProp(this, "sortingClass", _descriptor5, this);
_defineDecoratedPropertyDescriptor(this, "axis", _instanceInitializers);
_initDefineProp(this, "draggingClass", _descriptor6, this);
_defineDecoratedPropertyDescriptor(this, "boundingRect", _instanceInitializers);
_initDefineProp(this, "axis", _descriptor7, this);
_defineDecoratedPropertyDescriptor(this, "moved", _instanceInitializers);
_initDefineProp(this, "moved", _descriptor8, this);
_defineDecoratedPropertyDescriptor(this, "dragZIndex", _instanceInitializers);
_initDefineProp(this, "dragZIndex", _descriptor9, this);
_defineDecoratedPropertyDescriptor(this, "disallowedDragTagNames", _instanceInitializers);
_initDefineProp(this, "disallowedDragTagNames", _descriptor10, this);
_defineDecoratedPropertyDescriptor(this, "allowDrag", _instanceInitializers);
_initDefineProp(this, "allowDrag", _descriptor11, this);
_defineDecoratedPropertyDescriptor(this, "allowMove", _instanceInitializers);
_initDefineProp(this, "allowMove", _descriptor12, this);
this.selector = "[sortable-item]";
this.selector = "[" + SORTABLE_ITEM + "]";
this.fromIx = -1;
this.toIx = -1;
this.pageX = 0;
this.pageY = 0;
this.scrollRect = { left: 0, top: 0, width: 0, height: 0 };
this.x = 0;
this.y = 0;
this.lastElementFromPointRect = null;

@@ -165,302 +106,402 @@

_createDecoratedClass(Sortable, [{
key: "activate",
value: function activate() {
this.removeListener = _oribellaDefaultGestures.oribella.on(this.element, "swipe", this);
if (typeof this.scroll === "string") {
this.scroll = this.closest(this.element, this.scroll);
Sortable.prototype.activate = function activate() {
this.removeListener = _oribellaDefaultGestures.oribella.on(this.element, "swipe", this);
var scroll = this.scroll;
if (typeof scroll === "string") {
if (scroll === "document") {
this.scroll = document.scrollingElement || document.documentElement || document.body;
this.viewportScroll = true;
this.removeScroll = this.bindScroll(document, this.onScroll.bind(this));
return;
} else {
scroll = this.closest(this.element, scroll);
}
if (!(this.scroll instanceof _aureliaPal.DOM.Element)) {
this.scroll = this.element;
}
this.removeScroll = this.bindScroll(this.scroll, this.onScroll.bind(this));
}
}, {
key: "deactivate",
value: function deactivate() {
if (typeof this.removeListener === "function") {
this.removeListener();
}
if (typeof this.removeScroll === "function") {
this.removeScroll();
}
this.scroll = scroll;
if (!(this.scroll instanceof _aureliaPal.DOM.Element)) {
this.scroll = this.element;
}
}, {
key: "attached",
value: function attached() {
this.activate();
this.removeScroll = this.bindScroll(this.scroll, this.onScroll.bind(this));
};
Sortable.prototype.deactivate = function deactivate() {
if (typeof this.removeListener === "function") {
this.removeListener();
}
}, {
key: "detached",
value: function detached() {
this.deactivate();
if (typeof this.removeScroll === "function") {
this.removeScroll();
}
}, {
key: "bindScroll",
value: function bindScroll(scroll, fn) {
scroll.addEventListener("scroll", fn, false);
return function () {
scroll.removeEventListener("scroll", fn, false);
};
};
Sortable.prototype.attached = function attached() {
this.activate();
};
Sortable.prototype.detached = function detached() {
this.deactivate();
};
Sortable.prototype.bindScroll = function bindScroll(scroll, fn) {
scroll.addEventListener("scroll", fn, false);
return function () {
scroll.removeEventListener("scroll", fn, false);
};
};
Sortable.prototype.onScroll = function onScroll() {
if (!this.drag.element) {
return;
}
}, {
key: "onScroll",
value: function onScroll() {
if (!this.drag.element) {
return;
}
var scrollLeft = this.scroll.scrollLeft;
var scrollTop = this.scroll.scrollTop;
this.drag.update(this.pageX, this.pageY, scrollLeft, scrollTop, this.axis);
var _scroll = this.scroll;
var scrollLeft = _scroll.scrollLeft;
var scrollTop = _scroll.scrollTop;
var _getPoint = this.getPoint(this.pageX, this.pageY);
this.drag.update(this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.axis, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
var x = _getPoint.x;
var y = _getPoint.y;
var _getPoint = this.getPoint(this.x, this.y);
this.tryMove(x, y, scrollLeft, scrollTop);
var x = _getPoint.x;
var y = _getPoint.y;
this.tryMove(x, y, scrollLeft, scrollTop);
};
Sortable.prototype.getScrollFrames = function getScrollFrames(maxPos, scrollPos) {
return Math.max(0, Math.ceil(Math.abs(maxPos - scrollPos) / this.scrollSpeed));
};
Sortable.prototype.getScrollDirectionX = function getScrollDirectionX(x, _ref) {
var left = _ref.left;
var right = _ref.right;
var dir = 0;
switch (this.axis) {
default:
case "x":
if (x >= right - this.scrollSensitivity) {
dir = 1;
} else if (x <= left + this.scrollSensitivity) {
dir = -1;
}
break;
}
}, {
key: "hide",
value: function hide(element) {
var display = element.style.display;
element.style.display = "none";
return function () {
element.style.display = display;
};
}
}, {
key: "closest",
value: function closest(element, selector) {
var rootElement = arguments.length <= 2 || arguments[2] === undefined ? document : arguments[2];
return dir;
};
var valid = false;
while (!valid && element !== null && element !== rootElement && element !== document) {
valid = (0, _oribellaDefaultGestures.matchesSelector)(element, selector);
if (valid) {
break;
Sortable.prototype.getScrollDirectionY = function getScrollDirectionY(y, _ref2) {
var top = _ref2.top;
var bottom = _ref2.bottom;
var dir = 0;
switch (this.axis) {
default:
case "y":
if (y >= bottom - this.scrollSensitivity) {
dir = 1;
} else if (y <= top + this.scrollSensitivity) {
dir = -1;
}
element = element.parentNode;
}
return valid ? element : null;
break;
}
}, {
key: "getItemViewModel",
value: function getItemViewModel(element) {
return element.au["sortable-item"].viewModel;
}
}, {
key: "addPlaceholder",
value: function addPlaceholder(toIx, item) {
var placeholder = Object.create(item, { placeholderClass: { value: this.placeholderClass, writable: true } });
return dir;
};
if (!placeholder.style) {
placeholder.style = {};
}
placeholder.style.width = this.drag.rect.width;
placeholder.style.height = this.drag.rect.height;
Sortable.prototype.hide = function hide(element) {
var display = element.style.display;
element.style.display = "none";
return function () {
element.style.display = display;
};
};
this[PLACEHOLDER] = placeholder;
this.items.splice(toIx, 0, placeholder);
}
}, {
key: "removePlaceholder",
value: function removePlaceholder() {
var ix = this.items.indexOf(this[PLACEHOLDER]);
if (ix !== -1) {
this.items.splice(ix, 1);
Sortable.prototype.closest = function closest(element, selector) {
var rootElement = arguments.length <= 2 || arguments[2] === undefined ? document : arguments[2];
var valid = false;
while (!valid && element !== null && element !== rootElement && element !== document) {
valid = (0, _oribellaDefaultGestures.matchesSelector)(element, selector);
if (valid) {
break;
}
element = element.parentNode;
}
}, {
key: "movePlaceholder",
value: function movePlaceholder(toIx) {
var fromIx = this.items.indexOf(this[PLACEHOLDER]);
this.move(fromIx, toIx);
return valid ? element : null;
};
Sortable.prototype.getItemViewModel = function getItemViewModel(element) {
return element.au[SORTABLE_ITEM].viewModel;
};
Sortable.prototype.moveSortingItem = function moveSortingItem(toIx) {
var fromIx = this.items.indexOf(this.drag.item);
this.move(fromIx, toIx);
};
Sortable.prototype.move = function move(fromIx, toIx) {
if (fromIx !== -1 && toIx !== -1 && fromIx !== toIx) {
this.items.splice(toIx, 0, this.items.splice(fromIx, 1)[0]);
}
}, {
key: "move",
value: function move(fromIx, toIx) {
if (fromIx !== -1 && toIx !== -1 && fromIx !== toIx) {
this.items.splice(toIx, 0, this.items.splice(fromIx, 1)[0]);
}
};
Sortable.prototype.tryUpdate = function tryUpdate(x, y, offsetX, offsetY) {
var showFn = this.hide(this.drag.clone);
this.tryMove(x, y, offsetX, offsetY);
showFn();
};
Sortable.prototype.pointInside = function pointInside(x, y, rect) {
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
};
Sortable.prototype.elementFromPoint = function elementFromPoint(x, y) {
var element = document.elementFromPoint(x, y);
if (!element) {
return null;
}
}, {
key: "tryUpdate",
value: function tryUpdate(pageX, pageY, offsetX, offsetY) {
var showFn = this.hide(this.drag.element);
this.tryMove(pageX, pageY, offsetX, offsetY);
showFn();
element = this.closest(element, this.selector, this.element);
if (!element) {
return null;
}
}, {
key: "pointInside",
value: function pointInside(x, y, rect) {
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
return element;
};
Sortable.prototype.canThrottle = function canThrottle(x, y, offsetX, offsetY) {
return this.lastElementFromPointRect && this.pointInside(x + offsetX, y + offsetY, this.lastElementFromPointRect);
};
Sortable.prototype.tryMove = function tryMove(x, y, offsetX, offsetY) {
if (this.canThrottle(x, y, offsetX, offsetY)) {
return;
}
}, {
key: "elementFromPoint",
value: function elementFromPoint(x, y) {
var element = document.elementFromPoint(x, y);
if (!element) {
return null;
}
element = this.closest(element, this.selector, this.element);
if (!element) {
return null;
}
return element;
var element = this.elementFromPoint(x, y);
if (!element) {
return;
}
}, {
key: "canThrottle",
value: function canThrottle(x, y, offsetX, offsetY) {
return this.lastElementFromPointRect && this.pointInside(x + offsetX, y + offsetY, this.lastElementFromPointRect);
var vm = this.getItemViewModel(element);
this.lastElementFromPointRect = element.getBoundingClientRect();
if (!this.allowMove({ item: vm.item })) {
return;
}
}, {
key: "tryMove",
value: function tryMove(x, y, offsetX, offsetY) {
if (this.canThrottle(x, y, offsetX, offsetY)) {
return;
}
var element = this.elementFromPoint(x, y);
if (!element) {
return;
}
var model = this.getItemViewModel(element);
this.lastElementFromPointRect = element.getBoundingClientRect();
if (!this.allowMove({ item: model.item })) {
return;
}
var ix = model.ctx.$index;
this.movePlaceholder(ix);
this.moveSortingItem(vm.ctx.$index);
};
Sortable.prototype.getPoint = function getPoint(pageX, pageY) {
switch (this.axis) {
case "x":
pageY = this.drag.getCenterY();
break;
case "y":
pageX = this.drag.getCenterX();
break;
default:
break;
}
}, {
key: "getPoint",
value: function getPoint(pageX, pageY) {
switch (this.axis) {
case "x":
pageY = this.drag.getCenterY();
break;
case "y":
pageX = this.drag.getCenterX();
break;
default:
break;
}
return {
x: Math.max(this.boundingRect.left, Math.min(this.boundingRect.right, pageX)),
y: Math.max(this.boundingRect.top, Math.min(this.boundingRect.bottom, pageY))
};
return {
x: pageX,
y: pageY
};
};
Sortable.prototype.down = function down(e, data, element) {
if (this.allowDrag({ event: e, item: this.getItemViewModel(element).item })) {
e.preventDefault();
return undefined;
}
}, {
key: "down",
value: function down(e, data, element) {
if (this.allowDrag({ event: e, item: this.getItemViewModel(element).item })) {
e.preventDefault();
return undefined;
}
return false;
return false;
};
Sortable.prototype.start = function start(e, data, element) {
var _scroll2 = this.scroll;
var scrollLeft = _scroll2.scrollLeft;
var scrollTop = _scroll2.scrollTop;
this.windowHeight = innerHeight;
this.windowWidth = innerWidth;
this.x = data.pointers[0].client.x;
this.y = data.pointers[0].client.y;
this.sortableRect = this.element.getBoundingClientRect();
this.scrollRect = this.scroll.getBoundingClientRect();
this.scrollWidth = this.scroll.scrollWidth;
this.scrollHeight = this.scroll.scrollHeight;
this.boundingRect = {
left: Math.max(0, this.sortableRect.left),
top: Math.max(0, this.sortableRect.top),
bottom: Math.min(this.windowHeight, this.sortableRect.bottom),
right: Math.min(this.windowWidth, this.sortableRect.right)
};
this.sortableContainsScroll = this.element.contains(this.scroll);
if (this.sortableContainsScroll) {
this.scrollMaxPosX = this.scrollWidth - this.scrollRect.width;
this.scrollMaxPosY = this.scrollHeight - this.scrollRect.height;
this.dragMinPosX = this.sortableRect.left;
this.dragMaxPosX = this.sortableRect.left + this.scrollWidth;
this.dragMaxPosY = this.sortableRect.top + this.scrollHeight;
this.dragMinPosY = this.sortableRect.top;
} else {
this.scrollMaxPosX = this.sortableRect.right - this.windowWidth + (this.viewportScroll ? scrollLeft : 0);
this.scrollMaxPosY = this.sortableRect.bottom - this.windowHeight + (this.viewportScroll ? scrollTop : 0);
this.dragMinPosX = this.sortableRect.left + scrollLeft;
this.dragMaxPosX = this.scrollMaxPosX + this.windowWidth;
this.dragMinPosY = this.sortableRect.top + scrollTop;
this.dragMaxPosY = this.scrollMaxPosY + this.windowHeight;
}
}, {
key: "start",
value: function start(e, data, element) {
this.pageX = data.pointers[0].page.x;
this.pageY = data.pointers[0].page.y;
this.scrollRect = this.scroll.getBoundingClientRect();
this.scrollWidth = this.scroll.scrollWidth;
this.scrollHeight = this.scroll.scrollHeight;
this.boundingRect = this.boundingRect || { left: this.scrollRect.left + 5, top: this.scrollRect.top + 5, right: this.scrollRect.right - 5, bottom: this.scrollRect.bottom - 5 };
this.drag.start(element, this.pageX, this.pageY, this.scroll.scrollLeft, this.scroll.scrollTop, this.dragZIndex);
this.autoScroll.start(this.axis, this.scrollSpeed, this.scrollSensitivity);
var viewModel = this.getItemViewModel(element);
this.fromIx = viewModel.ctx.$index;
this.toIx = -1;
this.addPlaceholder(this.fromIx, viewModel.item);
this.lastElementFromPointRect = this.drag.rect;
}
}, {
key: "update",
value: function update(e, data) {
var p = data.pointers[0].page;
var pageX = this.pageX = p.x;
var pageY = this.pageY = p.y;
var scrollLeft = this.scroll.scrollLeft;
var scrollTop = this.scroll.scrollTop;
this.drag.update(pageX, pageY, scrollLeft, scrollTop, this.axis);
this.sortingViewModel = this.getItemViewModel(element);
this.fromIx = this.sortingViewModel.ctx.$index;
this.toIx = -1;
var _getPoint2 = this.getPoint(pageX, pageY);
this.drag.start(element, this.sortingViewModel.item, this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.dragZIndex, this.axis, this.sortingClass, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
this.autoScroll.start(this.scrollSpeed);
this.lastElementFromPointRect = this.drag.rect;
};
var x = _getPoint2.x;
var y = _getPoint2.y;
Sortable.prototype.update = function update(e, data) {
var p = data.pointers[0].client;
var _scroll3 = this.scroll;
var scrollLeft = _scroll3.scrollLeft;
var scrollTop = _scroll3.scrollTop;
var scrollX = this.autoScroll.active ? scrollLeft : 0;
var scrollY = this.autoScroll.active ? scrollTop : 0;
this.tryUpdate(x, y, scrollX, scrollY);
this.autoScroll.update(this.scroll, x, y, this.scrollWidth, this.scrollHeight, this.scrollRect);
this.x = p.x;
this.y = p.y;
this.drag.update(this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.axis, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
var _getPoint2 = this.getPoint(p.x, p.y);
var x = _getPoint2.x;
var y = _getPoint2.y;
var scrollX = this.autoScroll.active ? scrollLeft : 0;
var scrollY = this.autoScroll.active ? scrollTop : 0;
this.tryUpdate(x, y, scrollX, scrollY);
var dirX = this.getScrollDirectionX(x, this.boundingRect);
var dirY = this.getScrollDirectionY(y, this.boundingRect);
var frameCntX = this.getScrollFrames(dirX === -1 ? 0 : this.scrollMaxPosX, scrollLeft);
var frameCntY = this.getScrollFrames(dirY === -1 ? 0 : this.scrollMaxPosY, scrollTop);
if (dirX === 1 && scrollLeft >= this.scrollMaxPosX || dirX === -1 && scrollLeft === 0) {
frameCntX = 0;
}
}, {
key: "end",
value: function end() {
this.toIx = this.items.indexOf(this[PLACEHOLDER]);
if (this.toIx === -1) {
return; //cancelled
}
this.move(this.toIx < this.fromIx ? this.fromIx + 1 : this.fromIx, this.toIx);
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
if (dirY === 1 && scrollTop >= this.scrollMaxPosY || dirY === -1 && scrollTop === 0) {
frameCntY = 0;
}
this.autoScroll.update(this.scroll, dirX, dirY, frameCntX, frameCntY);
};
if (this.fromIx < this.toIx) {
--this.toIx;
}
if (this.fromIx !== this.toIx) {
this.moved({ fromIx: this.fromIx, toIx: this.toIx });
}
Sortable.prototype.end = function end() {
if (!this.drag.item) {
return; //cancelled
}
}, {
key: "cancel",
value: function cancel() {
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
this.stop();
if (this.fromIx !== this.toIx) {
this.moved({ fromIx: this.fromIx, toIx: this.toIx });
}
}], null, _instanceInitializers);
};
var _Sortable = Sortable;
Sortable = (0, _aureliaDependencyInjection.transient)()(Sortable) || Sortable;
Sortable = (0, _aureliaDependencyInjection.inject)(_aureliaPal.DOM.Element, _drag.Drag, _autoScroll.AutoScroll)(Sortable) || Sortable;
Sortable = (0, _aureliaTemplating.customAttribute)("sortable")(Sortable) || Sortable;
return Sortable;
})();
Sortable.prototype.cancel = function cancel() {
this.move(this.sortingViewModel.ctx.$index, this.fromIx);
this.stop();
};
exports.Sortable = Sortable;
Sortable.prototype.stop = function stop() {
this.drag.end();
this.autoScroll.end();
};
var SortableItem = (function () {
var _instanceInitializers2 = {};
return Sortable;
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "scroll", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return null;
}
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "scrollSpeed", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return 10;
}
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "scrollSensitivity", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return 10;
}
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "items", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "sortingClass", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return "oa-sorting";
}
}), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "draggingClass", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return "oa-dragging";
}
}), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "axis", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return "";
}
}), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "moved", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return function () {};
}
}), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "dragZIndex", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return 1;
}
}), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "disallowedDragTagNames", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return ["INPUT", "SELECT", "TEXTAREA"];
}
}), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "allowDrag", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
var _this = this;
return function (args) {
if (_this.disallowedDragTagNames.indexOf(args.event.target.tagName) !== -1) {
return false;
}
if (args.event.target.isContentEditable) {
return false;
}
return true;
};
}
}), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "allowMove", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return function () {
return true;
};
}
})), _class2)) || _class) || _class) || _class);
var SortableItem = exports.SortableItem = (_dec4 = (0, _aureliaTemplating.customAttribute)("oa-sortable-item"), _dec4(_class4 = (_class5 = function () {
function SortableItem() {
_classCallCheck(this, _SortableItem);
_classCallCheck(this, SortableItem);
_defineDecoratedPropertyDescriptor(this, "item", _instanceInitializers2);
_initDefineProp(this, "item", _descriptor13, this);
}
_createDecoratedClass(SortableItem, [{
key: "bind",
value: function bind(ctx, overrideCtx) {
this.ctx = overrideCtx; //Need a reference to the item's $index
}
}, {
key: "item",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return null;
},
enumerable: true
}], null, _instanceInitializers2);
SortableItem.prototype.bind = function bind(ctx, overrideCtx) {
this.ctx = overrideCtx; //Need a reference to the item's $index
};
var _SortableItem = SortableItem;
SortableItem = (0, _aureliaTemplating.customAttribute)("sortable-item")(SortableItem) || SortableItem;
return SortableItem;
})();
exports.SortableItem = SortableItem;
});
}(), (_descriptor13 = _applyDecoratedDescriptor(_class5.prototype, "item", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return null;
}
})), _class5)) || _class4);
});
//# sourceMappingURL=sortable.js.map

@@ -6,125 +6,81 @@ "use strict";

});
exports.AutoScroll = undefined;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _dec, _class;
var _aureliaDependencyInjection = require("aurelia-dependency-injection");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _aureliaDependencyInjection = require("aurelia-dependency-injection");
var AutoScroll = (function () {
var AutoScroll = exports.AutoScroll = (_dec = (0, _aureliaDependencyInjection.transient)(), _dec(_class = function () {
function AutoScroll() {
_classCallCheck(this, _AutoScroll);
_classCallCheck(this, AutoScroll);
this.ticks = [0, 0];
this.rAFId = -1;
this.axis = "";
this.speed = 10;
this.sensitivity = 10;
this.active = false;
}
_createClass(AutoScroll, [{
key: "start",
value: function start() {
var axis = arguments.length <= 0 || arguments[0] === undefined ? "" : arguments[0];
var speed = arguments.length <= 1 || arguments[1] === undefined ? 10 : arguments[1];
var sensitivity = arguments.length <= 2 || arguments[2] === undefined ? 10 : arguments[2];
AutoScroll.prototype.start = function start() {
var speed = arguments.length <= 0 || arguments[0] === undefined ? 10 : arguments[0];
this.axis = axis;
this.speed = speed;
this.sensitivity = sensitivity;
this.speed = speed;
};
AutoScroll.prototype.update = function update(element, dirX, dirY, frameCntX, frameCntY) {
var _this = this;
if (this.active) {
if (dirX === 0 && dirY === 0) {
cancelAnimationFrame(this.rAFId);
this.active = false;
}
return;
}
}, {
key: "update",
value: function update(element, x, y, scrollWidth, scrollHeight, scrollRect) {
var _this = this;
if (dirX === 0 && dirY === 0) {
return;
}
var rAF = arguments.length <= 6 || arguments[6] === undefined ? requestAnimationFrame : arguments[6];
var cAF = arguments.length <= 7 || arguments[7] === undefined ? cancelAnimationFrame : arguments[7];
if (frameCntX === 0 && frameCntY === 0) {
return;
}
var d = this.getScrollDirection(x, y, scrollRect);
if (this.active) {
if (d[0] === 0 && d[1] === 0) {
cAF(this.rAFId);
this.active = false;
}
var scrollDeltaX = dirX * this.speed;
var scrollDeltaY = dirY * this.speed;
var autoScroll = function autoScroll() {
if (!_this.active) {
return;
}
if (d[0] === 0 && d[1] === 0) {
return;
if (frameCntX > 0) {
element.scrollLeft += scrollDeltaX;
}
if (frameCntY > 0) {
element.scrollTop += scrollDeltaY;
}
this.ticks = this.getTicks(d, element.scrollLeft, element.scrollTop, scrollWidth, scrollHeight, scrollRect.width, scrollRect.height);
if (this.ticks[0] <= 0 && this.ticks[1] <= 0) {
--frameCntX;
--frameCntY;
if (frameCntX <= 0 && frameCntY <= 0) {
_this.active = false;
return;
}
var scrollDeltaX = d[0] * this.speed;
var scrollDeltaY = d[1] * this.speed;
_this.rAFId = requestAnimationFrame(autoScroll);
};
var autoScroll = function autoScroll() {
this.active = true;
autoScroll();
};
if (_this.ticks[0] > 0) {
element.scrollLeft += scrollDeltaX;
}
if (_this.ticks[1] > 0) {
element.scrollTop += scrollDeltaY;
}
AutoScroll.prototype.end = function end() {
var cAF = arguments.length <= 0 || arguments[0] === undefined ? cancelAnimationFrame : arguments[0];
--_this.ticks[0];
--_this.ticks[1];
if (_this.ticks[0] <= 0 && _this.ticks[1] <= 0) {
_this.active = false;
return;
}
cAF(this.rAFId);
this.active = false;
};
_this.rAFId = rAF(autoScroll);
};
this.active = true;
autoScroll();
}
}, {
key: "end",
value: function end() {
var cAF = arguments.length <= 0 || arguments[0] === undefined ? cancelAnimationFrame : arguments[0];
cAF(this.rAFId);
this.ticks = [0, 0];
}
}, {
key: "getTicks",
value: function getTicks(d, scrollLeft, scrollTop, scrollWidth, scrollHeight, width, height) {
var ticks = [];
ticks[0] = d[0] > 0 ? Math.ceil((scrollWidth - width - scrollLeft) / this.speed) : d[0] < 0 ? scrollLeft / this.speed : 0;
ticks[1] = d[1] > 0 ? Math.ceil((scrollHeight - height - scrollTop) / this.speed) : d[1] < 0 ? scrollTop / this.speed : 0;
return ticks;
}
}, {
key: "getScrollDirection",
value: function getScrollDirection(x, y, scrollRect) {
var left = scrollRect.left;
var top = scrollRect.top;
var right = scrollRect.right;
var _scrollRect$bottom = scrollRect.bottom;
var bottom = _scrollRect$bottom === undefined ? 0 : _scrollRect$bottom;
var d = [0, 0];
d[0] = this.axis === "y" ? 0 : x >= right - this.sensitivity ? 1 : x <= left + this.sensitivity ? -1 : 0;
d[1] = this.axis === "x" ? 0 : y >= bottom - this.sensitivity ? 1 : y <= top + this.sensitivity ? -1 : 0;
return d;
}
}]);
var _AutoScroll = AutoScroll;
AutoScroll = (0, _aureliaDependencyInjection.transient)()(AutoScroll) || AutoScroll;
return AutoScroll;
})();
exports.AutoScroll = AutoScroll;
}()) || _class);
//# sourceMappingURL=auto-scroll.js.map

@@ -6,12 +6,13 @@ "use strict";

});
exports.Drag = undefined;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
var _dec, _class;
var _aureliaDependencyInjection = require("aurelia-dependency-injection");
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var _aureliaDependencyInjection = require("aurelia-dependency-injection");
var Drag = (function () {
var Drag = exports.Drag = (_dec = (0, _aureliaDependencyInjection.transient)(), _dec(_class = function () {
function Drag() {
_classCallCheck(this, _Drag);
_classCallCheck(this, Drag);

@@ -25,91 +26,92 @@ this.startLeft = 0;

_createClass(Drag, [{
key: "pin",
value: function pin(element, rect, dragZIndex) {
this.element = element;
Drag.prototype.pin = function pin() {
this.item.sortingClass = this.sortingClass;
this.clone = this.element.cloneNode(true);
this.clone.style.position = "absolute";
this.clone.style.width = this.rect.width + "px";
this.clone.style.height = this.rect.height + "px";
this.clone.style.pointerEvents = "none";
this.clone.style.margin = 0;
this.clone.style.zIndex = this.dragZIndex;
document.body.appendChild(this.clone);
};
var style = {};
style.position = element.style.position;
style.left = element.style.left;
style.top = element.style.top;
style.width = element.style.width;
style.height = element.style.height;
style.pointerEvents = element.style.pointerEvents;
style.zIndex = element.style.zIndex;
Drag.prototype.unpin = function unpin() {
this.item.sortingClass = "";
document.body.removeChild(this.clone);
this.clone = null;
};
element.style.position = "absolute";
element.style.width = rect.width + "px";
element.style.height = rect.height + "px";
element.style.pointerEvents = "none";
element.style.zIndex = dragZIndex;
Drag.prototype.getCenterX = function getCenterX() {
return this.rect.left + this.rect.width / 2;
};
return function () {
Object.keys(style).forEach(function (key) {
element.style[key] = style[key];
});
};
}
}, {
key: "getCenterX",
value: function getCenterX() {
return this.rect.left + this.rect.width / 2;
}
}, {
key: "getCenterY",
value: function getCenterY() {
return this.rect.top + this.rect.height / 2;
}
}, {
key: "start",
value: function start(element, pageX, pageY, scrollLeft, scrollTop, dragZIndex) {
var rect = this.rect = element.getBoundingClientRect();
var offsetParentRect = element.offsetParent.getBoundingClientRect();
Drag.prototype.getCenterY = function getCenterY() {
return this.rect.top + this.rect.height / 2;
};
this.startLeft = rect.left - offsetParentRect.left;
this.startTop = rect.top - offsetParentRect.top;
Drag.prototype.start = function start(element, item, x, y, viewportScroll, scrollLeft, scrollTop, dragZIndex, axis, sortingClass, minPosX, maxPosX, minPosY, maxPosY) {
this.element = element;
this.item = item;
this.sortingClass = sortingClass;
this.dragZIndex = dragZIndex;
var rect = this.rect = element.getBoundingClientRect();
this.offsetX = this.startLeft - pageX - scrollLeft;
this.offsetY = this.startTop - pageY - scrollTop;
this.startLeft = rect.left;
this.startTop = rect.top;
this.unpin = this.pin(element, rect, dragZIndex);
this.offsetX = this.startLeft - x;
this.offsetY = this.startTop - y;
this.update(pageX, pageY, scrollLeft, scrollTop);
this.pin();
this.update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY);
};
Drag.prototype.update = function update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY) {
x += this.offsetX;
y += this.offsetY;
if (viewportScroll) {
x += scrollLeft;
y += scrollTop;
}
}, {
key: "update",
value: function update(pageX, pageY, scrollLeft, scrollTop, axis) {
var left = pageX + this.offsetX + scrollLeft;
var top = pageY + this.offsetY + scrollTop;
switch (axis) {
case "x":
top = this.startTop;
break;
case "y":
left = this.startLeft;
break;
default:
break;
}
if (x < minPosX) {
x = minPosX;
}
if (x > maxPosX - this.rect.width) {
x = maxPosX - this.rect.width;
}
this.element.style.left = left + "px";
this.element.style.top = top + "px";
if (y < minPosY) {
y = minPosY;
}
}, {
key: "end",
value: function end() {
if (this.element) {
if (typeof this.unpin === "function") {
this.unpin();
}
this.element = null;
}
if (y > maxPosY - this.rect.height) {
y = maxPosY - this.rect.height;
}
}]);
var _Drag = Drag;
Drag = (0, _aureliaDependencyInjection.transient)()(Drag) || Drag;
switch (axis) {
case "x":
y = this.startTop;
break;
case "y":
x = this.startLeft;
break;
}
this.clone.style.left = x + "px";
this.clone.style.top = y + "px";
};
Drag.prototype.end = function end() {
if (this.element === null) {
return;
}
this.unpin();
this.element = null;
this.item = null;
};
return Drag;
})();
exports.Drag = Drag;
}()) || _class);
//# sourceMappingURL=drag.js.map

@@ -7,5 +7,5 @@ "use strict";

exports.configure = configure;
function configure(config) {
config.globalResources("./sortable");
}
}
//# sourceMappingURL=index.js.map

@@ -6,9 +6,6 @@ "use strict";

});
exports.SortableItem = exports.Sortable = undefined;
var _createDecoratedClass = (function () { function defineProperties(target, descriptors, initializers) { for (var i = 0; i < descriptors.length; i++) { var descriptor = descriptors[i]; var decorators = descriptor.decorators; var key = descriptor.key; delete descriptor.key; delete descriptor.decorators; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor || descriptor.initializer) descriptor.writable = true; if (decorators) { for (var f = 0; f < decorators.length; f++) { var decorator = decorators[f]; if (typeof decorator === "function") { descriptor = decorator(target, key, descriptor) || descriptor; } else { throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator); } } if (descriptor.initializer !== undefined) { initializers[key] = descriptor; continue; } } Object.defineProperty(target, key, descriptor); } } return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) { if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers); if (staticProps) defineProperties(Constructor, staticProps, staticInitializers); return Constructor; }; })();
var _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _dec4, _class4, _desc2, _value2, _class5, _descriptor13;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineDecoratedPropertyDescriptor(target, key, descriptors) { var _descriptor = descriptors[key]; if (!_descriptor) return; var descriptor = {}; for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; descriptor.value = descriptor.initializer ? descriptor.initializer.call(target) : undefined; Object.defineProperty(target, key, descriptor); }
var _aureliaPal = require("aurelia-pal");

@@ -26,142 +23,82 @@

var PLACEHOLDER = "__placeholder__";
function _initDefineProp(target, property, descriptor, context) {
if (!descriptor) return;
Object.defineProperty(target, property, {
enumerable: descriptor.enumerable,
configurable: descriptor.configurable,
writable: descriptor.writable,
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
});
}
exports.PLACEHOLDER = PLACEHOLDER;
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
var Sortable = (function () {
var _instanceInitializers = {};
var _instanceInitializers = {};
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
_createDecoratedClass(Sortable, [{
key: "scroll",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return null;
},
enumerable: true
}, {
key: "scrollSpeed",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return 10;
},
enumerable: true
}, {
key: "scrollSensitivity",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return 10;
},
enumerable: true
}, {
key: "items",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return [];
},
enumerable: true
}, {
key: "placeholderClass",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return "placeholder";
},
enumerable: true
}, {
key: "axis",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return "";
},
enumerable: true
}, {
key: "boundingRect",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return null;
},
//{ left, top, right, bottom }
enumerable: true
}, {
key: "moved",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return function () {};
},
enumerable: true
}, {
key: "dragZIndex",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return 1;
},
enumerable: true
}, {
key: "disallowedDragTagNames",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return ["INPUT", "SELECT", "TEXTAREA"];
},
enumerable: true
}, {
key: "allowDrag",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
var _this = this;
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
return function (args) {
if (_this.disallowedDragTagNames.indexOf(args.event.target.tagName) !== -1) {
return false;
}
if (args.event.target.isContentEditable) {
return false;
}
return true;
};
},
enumerable: true
}, {
key: "allowMove",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return function () {
return true;
};
},
enumerable: true
}], null, _instanceInitializers);
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return desc;
}
function _initializerWarningHelper(descriptor, context) {
throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
}
var SORTABLE_ITEM = "oa-sortable-item";
var Sortable = exports.Sortable = (_dec = (0, _aureliaTemplating.customAttribute)("oa-sortable"), _dec2 = (0, _aureliaDependencyInjection.inject)(_aureliaPal.DOM.Element, _drag.Drag, _autoScroll.AutoScroll), _dec3 = (0, _aureliaDependencyInjection.transient)(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = function () {
function Sortable(element, drag, autoScroll) {
_classCallCheck(this, _Sortable);
_classCallCheck(this, Sortable);
_defineDecoratedPropertyDescriptor(this, "scroll", _instanceInitializers);
_initDefineProp(this, "scroll", _descriptor, this);
_defineDecoratedPropertyDescriptor(this, "scrollSpeed", _instanceInitializers);
_initDefineProp(this, "scrollSpeed", _descriptor2, this);
_defineDecoratedPropertyDescriptor(this, "scrollSensitivity", _instanceInitializers);
_initDefineProp(this, "scrollSensitivity", _descriptor3, this);
_defineDecoratedPropertyDescriptor(this, "items", _instanceInitializers);
_initDefineProp(this, "items", _descriptor4, this);
_defineDecoratedPropertyDescriptor(this, "placeholderClass", _instanceInitializers);
_initDefineProp(this, "sortingClass", _descriptor5, this);
_defineDecoratedPropertyDescriptor(this, "axis", _instanceInitializers);
_initDefineProp(this, "draggingClass", _descriptor6, this);
_defineDecoratedPropertyDescriptor(this, "boundingRect", _instanceInitializers);
_initDefineProp(this, "axis", _descriptor7, this);
_defineDecoratedPropertyDescriptor(this, "moved", _instanceInitializers);
_initDefineProp(this, "moved", _descriptor8, this);
_defineDecoratedPropertyDescriptor(this, "dragZIndex", _instanceInitializers);
_initDefineProp(this, "dragZIndex", _descriptor9, this);
_defineDecoratedPropertyDescriptor(this, "disallowedDragTagNames", _instanceInitializers);
_initDefineProp(this, "disallowedDragTagNames", _descriptor10, this);
_defineDecoratedPropertyDescriptor(this, "allowDrag", _instanceInitializers);
_initDefineProp(this, "allowDrag", _descriptor11, this);
_defineDecoratedPropertyDescriptor(this, "allowMove", _instanceInitializers);
_initDefineProp(this, "allowMove", _descriptor12, this);
this.selector = "[sortable-item]";
this.selector = "[" + SORTABLE_ITEM + "]";
this.fromIx = -1;
this.toIx = -1;
this.pageX = 0;
this.pageY = 0;
this.scrollRect = { left: 0, top: 0, width: 0, height: 0 };
this.x = 0;
this.y = 0;
this.lastElementFromPointRect = null;

@@ -177,301 +114,401 @@

_createDecoratedClass(Sortable, [{
key: "activate",
value: function activate() {
this.removeListener = _oribellaDefaultGestures.oribella.on(this.element, "swipe", this);
if (typeof this.scroll === "string") {
this.scroll = this.closest(this.element, this.scroll);
Sortable.prototype.activate = function activate() {
this.removeListener = _oribellaDefaultGestures.oribella.on(this.element, "swipe", this);
var scroll = this.scroll;
if (typeof scroll === "string") {
if (scroll === "document") {
this.scroll = document.scrollingElement || document.documentElement || document.body;
this.viewportScroll = true;
this.removeScroll = this.bindScroll(document, this.onScroll.bind(this));
return;
} else {
scroll = this.closest(this.element, scroll);
}
if (!(this.scroll instanceof _aureliaPal.DOM.Element)) {
this.scroll = this.element;
}
this.removeScroll = this.bindScroll(this.scroll, this.onScroll.bind(this));
}
}, {
key: "deactivate",
value: function deactivate() {
if (typeof this.removeListener === "function") {
this.removeListener();
}
if (typeof this.removeScroll === "function") {
this.removeScroll();
}
this.scroll = scroll;
if (!(this.scroll instanceof _aureliaPal.DOM.Element)) {
this.scroll = this.element;
}
}, {
key: "attached",
value: function attached() {
this.activate();
this.removeScroll = this.bindScroll(this.scroll, this.onScroll.bind(this));
};
Sortable.prototype.deactivate = function deactivate() {
if (typeof this.removeListener === "function") {
this.removeListener();
}
}, {
key: "detached",
value: function detached() {
this.deactivate();
if (typeof this.removeScroll === "function") {
this.removeScroll();
}
}, {
key: "bindScroll",
value: function bindScroll(scroll, fn) {
scroll.addEventListener("scroll", fn, false);
return function () {
scroll.removeEventListener("scroll", fn, false);
};
};
Sortable.prototype.attached = function attached() {
this.activate();
};
Sortable.prototype.detached = function detached() {
this.deactivate();
};
Sortable.prototype.bindScroll = function bindScroll(scroll, fn) {
scroll.addEventListener("scroll", fn, false);
return function () {
scroll.removeEventListener("scroll", fn, false);
};
};
Sortable.prototype.onScroll = function onScroll() {
if (!this.drag.element) {
return;
}
}, {
key: "onScroll",
value: function onScroll() {
if (!this.drag.element) {
return;
}
var scrollLeft = this.scroll.scrollLeft;
var scrollTop = this.scroll.scrollTop;
this.drag.update(this.pageX, this.pageY, scrollLeft, scrollTop, this.axis);
var _scroll = this.scroll;
var scrollLeft = _scroll.scrollLeft;
var scrollTop = _scroll.scrollTop;
var _getPoint = this.getPoint(this.pageX, this.pageY);
this.drag.update(this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.axis, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
var x = _getPoint.x;
var y = _getPoint.y;
var _getPoint = this.getPoint(this.x, this.y);
this.tryMove(x, y, scrollLeft, scrollTop);
var x = _getPoint.x;
var y = _getPoint.y;
this.tryMove(x, y, scrollLeft, scrollTop);
};
Sortable.prototype.getScrollFrames = function getScrollFrames(maxPos, scrollPos) {
return Math.max(0, Math.ceil(Math.abs(maxPos - scrollPos) / this.scrollSpeed));
};
Sortable.prototype.getScrollDirectionX = function getScrollDirectionX(x, _ref) {
var left = _ref.left;
var right = _ref.right;
var dir = 0;
switch (this.axis) {
default:
case "x":
if (x >= right - this.scrollSensitivity) {
dir = 1;
} else if (x <= left + this.scrollSensitivity) {
dir = -1;
}
break;
}
}, {
key: "hide",
value: function hide(element) {
var display = element.style.display;
element.style.display = "none";
return function () {
element.style.display = display;
};
}
}, {
key: "closest",
value: function closest(element, selector) {
var rootElement = arguments.length <= 2 || arguments[2] === undefined ? document : arguments[2];
return dir;
};
var valid = false;
while (!valid && element !== null && element !== rootElement && element !== document) {
valid = (0, _oribellaDefaultGestures.matchesSelector)(element, selector);
if (valid) {
break;
Sortable.prototype.getScrollDirectionY = function getScrollDirectionY(y, _ref2) {
var top = _ref2.top;
var bottom = _ref2.bottom;
var dir = 0;
switch (this.axis) {
default:
case "y":
if (y >= bottom - this.scrollSensitivity) {
dir = 1;
} else if (y <= top + this.scrollSensitivity) {
dir = -1;
}
element = element.parentNode;
}
return valid ? element : null;
break;
}
}, {
key: "getItemViewModel",
value: function getItemViewModel(element) {
return element.au["sortable-item"].viewModel;
}
}, {
key: "addPlaceholder",
value: function addPlaceholder(toIx, item) {
var placeholder = Object.create(item, { placeholderClass: { value: this.placeholderClass, writable: true } });
return dir;
};
if (!placeholder.style) {
placeholder.style = {};
}
placeholder.style.width = this.drag.rect.width;
placeholder.style.height = this.drag.rect.height;
Sortable.prototype.hide = function hide(element) {
var display = element.style.display;
element.style.display = "none";
return function () {
element.style.display = display;
};
};
this[PLACEHOLDER] = placeholder;
this.items.splice(toIx, 0, placeholder);
}
}, {
key: "removePlaceholder",
value: function removePlaceholder() {
var ix = this.items.indexOf(this[PLACEHOLDER]);
if (ix !== -1) {
this.items.splice(ix, 1);
Sortable.prototype.closest = function closest(element, selector) {
var rootElement = arguments.length <= 2 || arguments[2] === undefined ? document : arguments[2];
var valid = false;
while (!valid && element !== null && element !== rootElement && element !== document) {
valid = (0, _oribellaDefaultGestures.matchesSelector)(element, selector);
if (valid) {
break;
}
element = element.parentNode;
}
}, {
key: "movePlaceholder",
value: function movePlaceholder(toIx) {
var fromIx = this.items.indexOf(this[PLACEHOLDER]);
this.move(fromIx, toIx);
return valid ? element : null;
};
Sortable.prototype.getItemViewModel = function getItemViewModel(element) {
return element.au[SORTABLE_ITEM].viewModel;
};
Sortable.prototype.moveSortingItem = function moveSortingItem(toIx) {
var fromIx = this.items.indexOf(this.drag.item);
this.move(fromIx, toIx);
};
Sortable.prototype.move = function move(fromIx, toIx) {
if (fromIx !== -1 && toIx !== -1 && fromIx !== toIx) {
this.items.splice(toIx, 0, this.items.splice(fromIx, 1)[0]);
}
}, {
key: "move",
value: function move(fromIx, toIx) {
if (fromIx !== -1 && toIx !== -1 && fromIx !== toIx) {
this.items.splice(toIx, 0, this.items.splice(fromIx, 1)[0]);
}
};
Sortable.prototype.tryUpdate = function tryUpdate(x, y, offsetX, offsetY) {
var showFn = this.hide(this.drag.clone);
this.tryMove(x, y, offsetX, offsetY);
showFn();
};
Sortable.prototype.pointInside = function pointInside(x, y, rect) {
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
};
Sortable.prototype.elementFromPoint = function elementFromPoint(x, y) {
var element = document.elementFromPoint(x, y);
if (!element) {
return null;
}
}, {
key: "tryUpdate",
value: function tryUpdate(pageX, pageY, offsetX, offsetY) {
var showFn = this.hide(this.drag.element);
this.tryMove(pageX, pageY, offsetX, offsetY);
showFn();
element = this.closest(element, this.selector, this.element);
if (!element) {
return null;
}
}, {
key: "pointInside",
value: function pointInside(x, y, rect) {
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
return element;
};
Sortable.prototype.canThrottle = function canThrottle(x, y, offsetX, offsetY) {
return this.lastElementFromPointRect && this.pointInside(x + offsetX, y + offsetY, this.lastElementFromPointRect);
};
Sortable.prototype.tryMove = function tryMove(x, y, offsetX, offsetY) {
if (this.canThrottle(x, y, offsetX, offsetY)) {
return;
}
}, {
key: "elementFromPoint",
value: function elementFromPoint(x, y) {
var element = document.elementFromPoint(x, y);
if (!element) {
return null;
}
element = this.closest(element, this.selector, this.element);
if (!element) {
return null;
}
return element;
var element = this.elementFromPoint(x, y);
if (!element) {
return;
}
}, {
key: "canThrottle",
value: function canThrottle(x, y, offsetX, offsetY) {
return this.lastElementFromPointRect && this.pointInside(x + offsetX, y + offsetY, this.lastElementFromPointRect);
var vm = this.getItemViewModel(element);
this.lastElementFromPointRect = element.getBoundingClientRect();
if (!this.allowMove({ item: vm.item })) {
return;
}
}, {
key: "tryMove",
value: function tryMove(x, y, offsetX, offsetY) {
if (this.canThrottle(x, y, offsetX, offsetY)) {
return;
}
var element = this.elementFromPoint(x, y);
if (!element) {
return;
}
var model = this.getItemViewModel(element);
this.lastElementFromPointRect = element.getBoundingClientRect();
if (!this.allowMove({ item: model.item })) {
return;
}
var ix = model.ctx.$index;
this.movePlaceholder(ix);
this.moveSortingItem(vm.ctx.$index);
};
Sortable.prototype.getPoint = function getPoint(pageX, pageY) {
switch (this.axis) {
case "x":
pageY = this.drag.getCenterY();
break;
case "y":
pageX = this.drag.getCenterX();
break;
default:
break;
}
}, {
key: "getPoint",
value: function getPoint(pageX, pageY) {
switch (this.axis) {
case "x":
pageY = this.drag.getCenterY();
break;
case "y":
pageX = this.drag.getCenterX();
break;
default:
break;
}
return {
x: Math.max(this.boundingRect.left, Math.min(this.boundingRect.right, pageX)),
y: Math.max(this.boundingRect.top, Math.min(this.boundingRect.bottom, pageY))
};
return {
x: pageX,
y: pageY
};
};
Sortable.prototype.down = function down(e, data, element) {
if (this.allowDrag({ event: e, item: this.getItemViewModel(element).item })) {
e.preventDefault();
return undefined;
}
}, {
key: "down",
value: function down(e, data, element) {
if (this.allowDrag({ event: e, item: this.getItemViewModel(element).item })) {
e.preventDefault();
return undefined;
}
return false;
return false;
};
Sortable.prototype.start = function start(e, data, element) {
var _scroll2 = this.scroll;
var scrollLeft = _scroll2.scrollLeft;
var scrollTop = _scroll2.scrollTop;
this.windowHeight = innerHeight;
this.windowWidth = innerWidth;
this.x = data.pointers[0].client.x;
this.y = data.pointers[0].client.y;
this.sortableRect = this.element.getBoundingClientRect();
this.scrollRect = this.scroll.getBoundingClientRect();
this.scrollWidth = this.scroll.scrollWidth;
this.scrollHeight = this.scroll.scrollHeight;
this.boundingRect = {
left: Math.max(0, this.sortableRect.left),
top: Math.max(0, this.sortableRect.top),
bottom: Math.min(this.windowHeight, this.sortableRect.bottom),
right: Math.min(this.windowWidth, this.sortableRect.right)
};
this.sortableContainsScroll = this.element.contains(this.scroll);
if (this.sortableContainsScroll) {
this.scrollMaxPosX = this.scrollWidth - this.scrollRect.width;
this.scrollMaxPosY = this.scrollHeight - this.scrollRect.height;
this.dragMinPosX = this.sortableRect.left;
this.dragMaxPosX = this.sortableRect.left + this.scrollWidth;
this.dragMaxPosY = this.sortableRect.top + this.scrollHeight;
this.dragMinPosY = this.sortableRect.top;
} else {
this.scrollMaxPosX = this.sortableRect.right - this.windowWidth + (this.viewportScroll ? scrollLeft : 0);
this.scrollMaxPosY = this.sortableRect.bottom - this.windowHeight + (this.viewportScroll ? scrollTop : 0);
this.dragMinPosX = this.sortableRect.left + scrollLeft;
this.dragMaxPosX = this.scrollMaxPosX + this.windowWidth;
this.dragMinPosY = this.sortableRect.top + scrollTop;
this.dragMaxPosY = this.scrollMaxPosY + this.windowHeight;
}
}, {
key: "start",
value: function start(e, data, element) {
this.pageX = data.pointers[0].page.x;
this.pageY = data.pointers[0].page.y;
this.scrollRect = this.scroll.getBoundingClientRect();
this.scrollWidth = this.scroll.scrollWidth;
this.scrollHeight = this.scroll.scrollHeight;
this.boundingRect = this.boundingRect || { left: this.scrollRect.left + 5, top: this.scrollRect.top + 5, right: this.scrollRect.right - 5, bottom: this.scrollRect.bottom - 5 };
this.drag.start(element, this.pageX, this.pageY, this.scroll.scrollLeft, this.scroll.scrollTop, this.dragZIndex);
this.autoScroll.start(this.axis, this.scrollSpeed, this.scrollSensitivity);
var viewModel = this.getItemViewModel(element);
this.fromIx = viewModel.ctx.$index;
this.toIx = -1;
this.addPlaceholder(this.fromIx, viewModel.item);
this.lastElementFromPointRect = this.drag.rect;
}
}, {
key: "update",
value: function update(e, data) {
var p = data.pointers[0].page;
var pageX = this.pageX = p.x;
var pageY = this.pageY = p.y;
var scrollLeft = this.scroll.scrollLeft;
var scrollTop = this.scroll.scrollTop;
this.drag.update(pageX, pageY, scrollLeft, scrollTop, this.axis);
this.sortingViewModel = this.getItemViewModel(element);
this.fromIx = this.sortingViewModel.ctx.$index;
this.toIx = -1;
var _getPoint2 = this.getPoint(pageX, pageY);
this.drag.start(element, this.sortingViewModel.item, this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.dragZIndex, this.axis, this.sortingClass, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
this.autoScroll.start(this.scrollSpeed);
this.lastElementFromPointRect = this.drag.rect;
};
var x = _getPoint2.x;
var y = _getPoint2.y;
Sortable.prototype.update = function update(e, data) {
var p = data.pointers[0].client;
var _scroll3 = this.scroll;
var scrollLeft = _scroll3.scrollLeft;
var scrollTop = _scroll3.scrollTop;
var scrollX = this.autoScroll.active ? scrollLeft : 0;
var scrollY = this.autoScroll.active ? scrollTop : 0;
this.tryUpdate(x, y, scrollX, scrollY);
this.autoScroll.update(this.scroll, x, y, this.scrollWidth, this.scrollHeight, this.scrollRect);
this.x = p.x;
this.y = p.y;
this.drag.update(this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.axis, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
var _getPoint2 = this.getPoint(p.x, p.y);
var x = _getPoint2.x;
var y = _getPoint2.y;
var scrollX = this.autoScroll.active ? scrollLeft : 0;
var scrollY = this.autoScroll.active ? scrollTop : 0;
this.tryUpdate(x, y, scrollX, scrollY);
var dirX = this.getScrollDirectionX(x, this.boundingRect);
var dirY = this.getScrollDirectionY(y, this.boundingRect);
var frameCntX = this.getScrollFrames(dirX === -1 ? 0 : this.scrollMaxPosX, scrollLeft);
var frameCntY = this.getScrollFrames(dirY === -1 ? 0 : this.scrollMaxPosY, scrollTop);
if (dirX === 1 && scrollLeft >= this.scrollMaxPosX || dirX === -1 && scrollLeft === 0) {
frameCntX = 0;
}
}, {
key: "end",
value: function end() {
this.toIx = this.items.indexOf(this[PLACEHOLDER]);
if (this.toIx === -1) {
return; //cancelled
}
this.move(this.toIx < this.fromIx ? this.fromIx + 1 : this.fromIx, this.toIx);
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
if (dirY === 1 && scrollTop >= this.scrollMaxPosY || dirY === -1 && scrollTop === 0) {
frameCntY = 0;
}
this.autoScroll.update(this.scroll, dirX, dirY, frameCntX, frameCntY);
};
if (this.fromIx < this.toIx) {
--this.toIx;
}
if (this.fromIx !== this.toIx) {
this.moved({ fromIx: this.fromIx, toIx: this.toIx });
}
Sortable.prototype.end = function end() {
if (!this.drag.item) {
return; //cancelled
}
}, {
key: "cancel",
value: function cancel() {
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
this.stop();
if (this.fromIx !== this.toIx) {
this.moved({ fromIx: this.fromIx, toIx: this.toIx });
}
}], null, _instanceInitializers);
};
var _Sortable = Sortable;
Sortable = (0, _aureliaDependencyInjection.transient)()(Sortable) || Sortable;
Sortable = (0, _aureliaDependencyInjection.inject)(_aureliaPal.DOM.Element, _drag.Drag, _autoScroll.AutoScroll)(Sortable) || Sortable;
Sortable = (0, _aureliaTemplating.customAttribute)("sortable")(Sortable) || Sortable;
return Sortable;
})();
Sortable.prototype.cancel = function cancel() {
this.move(this.sortingViewModel.ctx.$index, this.fromIx);
this.stop();
};
exports.Sortable = Sortable;
Sortable.prototype.stop = function stop() {
this.drag.end();
this.autoScroll.end();
};
var SortableItem = (function () {
var _instanceInitializers2 = {};
return Sortable;
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "scroll", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return null;
}
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "scrollSpeed", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return 10;
}
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "scrollSensitivity", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return 10;
}
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "items", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "sortingClass", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return "oa-sorting";
}
}), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "draggingClass", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return "oa-dragging";
}
}), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "axis", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return "";
}
}), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "moved", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return function () {};
}
}), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "dragZIndex", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return 1;
}
}), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "disallowedDragTagNames", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return ["INPUT", "SELECT", "TEXTAREA"];
}
}), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "allowDrag", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
var _this = this;
return function (args) {
if (_this.disallowedDragTagNames.indexOf(args.event.target.tagName) !== -1) {
return false;
}
if (args.event.target.isContentEditable) {
return false;
}
return true;
};
}
}), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "allowMove", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return function () {
return true;
};
}
})), _class2)) || _class) || _class) || _class);
var SortableItem = exports.SortableItem = (_dec4 = (0, _aureliaTemplating.customAttribute)("oa-sortable-item"), _dec4(_class4 = (_class5 = function () {
function SortableItem() {
_classCallCheck(this, _SortableItem);
_classCallCheck(this, SortableItem);
_defineDecoratedPropertyDescriptor(this, "item", _instanceInitializers2);
_initDefineProp(this, "item", _descriptor13, this);
}
_createDecoratedClass(SortableItem, [{
key: "bind",
value: function bind(ctx, overrideCtx) {
this.ctx = overrideCtx; //Need a reference to the item's $index
}
}, {
key: "item",
decorators: [_aureliaTemplating.bindable],
initializer: function initializer() {
return null;
},
enumerable: true
}], null, _instanceInitializers2);
SortableItem.prototype.bind = function bind(ctx, overrideCtx) {
this.ctx = overrideCtx; //Need a reference to the item's $index
};
var _SortableItem = SortableItem;
SortableItem = (0, _aureliaTemplating.customAttribute)("sortable-item")(SortableItem) || SortableItem;
return SortableItem;
})();
exports.SortableItem = SortableItem;
}(), (_descriptor13 = _applyDecoratedDescriptor(_class5.prototype, "item", [_aureliaTemplating.bindable], {
enumerable: true,
initializer: function initializer() {
return null;
}
})), _class5)) || _class4);
//# sourceMappingURL=sortable.js.map

@@ -1,10 +0,12 @@

System.register(["aurelia-dependency-injection"], function (_export) {
"use strict";
"use strict";
var transient, AutoScroll;
System.register(["aurelia-dependency-injection"], function (_export, _context) {
var transient, _dec, _class, AutoScroll;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
return {

@@ -15,117 +17,73 @@ setters: [function (_aureliaDependencyInjection) {

execute: function () {
AutoScroll = (function () {
_export("AutoScroll", AutoScroll = (_dec = transient(), _dec(_class = function () {
function AutoScroll() {
_classCallCheck(this, _AutoScroll);
_classCallCheck(this, AutoScroll);
this.ticks = [0, 0];
this.rAFId = -1;
this.axis = "";
this.speed = 10;
this.sensitivity = 10;
this.active = false;
}
_createClass(AutoScroll, [{
key: "start",
value: function start() {
var axis = arguments.length <= 0 || arguments[0] === undefined ? "" : arguments[0];
var speed = arguments.length <= 1 || arguments[1] === undefined ? 10 : arguments[1];
var sensitivity = arguments.length <= 2 || arguments[2] === undefined ? 10 : arguments[2];
AutoScroll.prototype.start = function start() {
var speed = arguments.length <= 0 || arguments[0] === undefined ? 10 : arguments[0];
this.axis = axis;
this.speed = speed;
this.sensitivity = sensitivity;
this.speed = speed;
};
AutoScroll.prototype.update = function update(element, dirX, dirY, frameCntX, frameCntY) {
var _this = this;
if (this.active) {
if (dirX === 0 && dirY === 0) {
cancelAnimationFrame(this.rAFId);
this.active = false;
}
return;
}
}, {
key: "update",
value: function update(element, x, y, scrollWidth, scrollHeight, scrollRect) {
var _this = this;
if (dirX === 0 && dirY === 0) {
return;
}
var rAF = arguments.length <= 6 || arguments[6] === undefined ? requestAnimationFrame : arguments[6];
var cAF = arguments.length <= 7 || arguments[7] === undefined ? cancelAnimationFrame : arguments[7];
if (frameCntX === 0 && frameCntY === 0) {
return;
}
var d = this.getScrollDirection(x, y, scrollRect);
if (this.active) {
if (d[0] === 0 && d[1] === 0) {
cAF(this.rAFId);
this.active = false;
}
var scrollDeltaX = dirX * this.speed;
var scrollDeltaY = dirY * this.speed;
var autoScroll = function autoScroll() {
if (!_this.active) {
return;
}
if (d[0] === 0 && d[1] === 0) {
return;
if (frameCntX > 0) {
element.scrollLeft += scrollDeltaX;
}
if (frameCntY > 0) {
element.scrollTop += scrollDeltaY;
}
this.ticks = this.getTicks(d, element.scrollLeft, element.scrollTop, scrollWidth, scrollHeight, scrollRect.width, scrollRect.height);
if (this.ticks[0] <= 0 && this.ticks[1] <= 0) {
--frameCntX;
--frameCntY;
if (frameCntX <= 0 && frameCntY <= 0) {
_this.active = false;
return;
}
var scrollDeltaX = d[0] * this.speed;
var scrollDeltaY = d[1] * this.speed;
_this.rAFId = requestAnimationFrame(autoScroll);
};
var autoScroll = function autoScroll() {
this.active = true;
autoScroll();
};
if (_this.ticks[0] > 0) {
element.scrollLeft += scrollDeltaX;
}
if (_this.ticks[1] > 0) {
element.scrollTop += scrollDeltaY;
}
AutoScroll.prototype.end = function end() {
var cAF = arguments.length <= 0 || arguments[0] === undefined ? cancelAnimationFrame : arguments[0];
--_this.ticks[0];
--_this.ticks[1];
if (_this.ticks[0] <= 0 && _this.ticks[1] <= 0) {
_this.active = false;
return;
}
cAF(this.rAFId);
this.active = false;
};
_this.rAFId = rAF(autoScroll);
};
this.active = true;
autoScroll();
}
}, {
key: "end",
value: function end() {
var cAF = arguments.length <= 0 || arguments[0] === undefined ? cancelAnimationFrame : arguments[0];
cAF(this.rAFId);
this.ticks = [0, 0];
}
}, {
key: "getTicks",
value: function getTicks(d, scrollLeft, scrollTop, scrollWidth, scrollHeight, width, height) {
var ticks = [];
ticks[0] = d[0] > 0 ? Math.ceil((scrollWidth - width - scrollLeft) / this.speed) : d[0] < 0 ? scrollLeft / this.speed : 0;
ticks[1] = d[1] > 0 ? Math.ceil((scrollHeight - height - scrollTop) / this.speed) : d[1] < 0 ? scrollTop / this.speed : 0;
return ticks;
}
}, {
key: "getScrollDirection",
value: function getScrollDirection(x, y, scrollRect) {
var left = scrollRect.left;
var top = scrollRect.top;
var right = scrollRect.right;
var _scrollRect$bottom = scrollRect.bottom;
var bottom = _scrollRect$bottom === undefined ? 0 : _scrollRect$bottom;
var d = [0, 0];
d[0] = this.axis === "y" ? 0 : x >= right - this.sensitivity ? 1 : x <= left + this.sensitivity ? -1 : 0;
d[1] = this.axis === "x" ? 0 : y >= bottom - this.sensitivity ? 1 : y <= top + this.sensitivity ? -1 : 0;
return d;
}
}]);
var _AutoScroll = AutoScroll;
AutoScroll = transient()(AutoScroll) || AutoScroll;
return AutoScroll;
})();
}()) || _class));

@@ -135,2 +93,3 @@ _export("AutoScroll", AutoScroll);

};
});
});
//# sourceMappingURL=auto-scroll.js.map

@@ -1,10 +0,12 @@

System.register(["aurelia-dependency-injection"], function (_export) {
"use strict";
"use strict";
var transient, Drag;
System.register(["aurelia-dependency-injection"], function (_export, _context) {
var transient, _dec, _class, Drag;
var _createClass = (function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; })();
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
return {

@@ -15,5 +17,5 @@ setters: [function (_aureliaDependencyInjection) {

execute: function () {
Drag = (function () {
_export("Drag", Drag = (_dec = transient(), _dec(_class = function () {
function Drag() {
_classCallCheck(this, _Drag);
_classCallCheck(this, Drag);

@@ -27,90 +29,92 @@ this.startLeft = 0;

_createClass(Drag, [{
key: "pin",
value: function pin(element, rect, dragZIndex) {
this.element = element;
Drag.prototype.pin = function pin() {
this.item.sortingClass = this.sortingClass;
this.clone = this.element.cloneNode(true);
this.clone.style.position = "absolute";
this.clone.style.width = this.rect.width + "px";
this.clone.style.height = this.rect.height + "px";
this.clone.style.pointerEvents = "none";
this.clone.style.margin = 0;
this.clone.style.zIndex = this.dragZIndex;
document.body.appendChild(this.clone);
};
var style = {};
style.position = element.style.position;
style.left = element.style.left;
style.top = element.style.top;
style.width = element.style.width;
style.height = element.style.height;
style.pointerEvents = element.style.pointerEvents;
style.zIndex = element.style.zIndex;
Drag.prototype.unpin = function unpin() {
this.item.sortingClass = "";
document.body.removeChild(this.clone);
this.clone = null;
};
element.style.position = "absolute";
element.style.width = rect.width + "px";
element.style.height = rect.height + "px";
element.style.pointerEvents = "none";
element.style.zIndex = dragZIndex;
Drag.prototype.getCenterX = function getCenterX() {
return this.rect.left + this.rect.width / 2;
};
return function () {
Object.keys(style).forEach(function (key) {
element.style[key] = style[key];
});
};
}
}, {
key: "getCenterX",
value: function getCenterX() {
return this.rect.left + this.rect.width / 2;
}
}, {
key: "getCenterY",
value: function getCenterY() {
return this.rect.top + this.rect.height / 2;
}
}, {
key: "start",
value: function start(element, pageX, pageY, scrollLeft, scrollTop, dragZIndex) {
var rect = this.rect = element.getBoundingClientRect();
var offsetParentRect = element.offsetParent.getBoundingClientRect();
Drag.prototype.getCenterY = function getCenterY() {
return this.rect.top + this.rect.height / 2;
};
this.startLeft = rect.left - offsetParentRect.left;
this.startTop = rect.top - offsetParentRect.top;
Drag.prototype.start = function start(element, item, x, y, viewportScroll, scrollLeft, scrollTop, dragZIndex, axis, sortingClass, minPosX, maxPosX, minPosY, maxPosY) {
this.element = element;
this.item = item;
this.sortingClass = sortingClass;
this.dragZIndex = dragZIndex;
var rect = this.rect = element.getBoundingClientRect();
this.offsetX = this.startLeft - pageX - scrollLeft;
this.offsetY = this.startTop - pageY - scrollTop;
this.startLeft = rect.left;
this.startTop = rect.top;
this.unpin = this.pin(element, rect, dragZIndex);
this.offsetX = this.startLeft - x;
this.offsetY = this.startTop - y;
this.update(pageX, pageY, scrollLeft, scrollTop);
this.pin();
this.update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY);
};
Drag.prototype.update = function update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY) {
x += this.offsetX;
y += this.offsetY;
if (viewportScroll) {
x += scrollLeft;
y += scrollTop;
}
}, {
key: "update",
value: function update(pageX, pageY, scrollLeft, scrollTop, axis) {
var left = pageX + this.offsetX + scrollLeft;
var top = pageY + this.offsetY + scrollTop;
switch (axis) {
case "x":
top = this.startTop;
break;
case "y":
left = this.startLeft;
break;
default:
break;
}
if (x < minPosX) {
x = minPosX;
}
if (x > maxPosX - this.rect.width) {
x = maxPosX - this.rect.width;
}
this.element.style.left = left + "px";
this.element.style.top = top + "px";
if (y < minPosY) {
y = minPosY;
}
}, {
key: "end",
value: function end() {
if (this.element) {
if (typeof this.unpin === "function") {
this.unpin();
}
this.element = null;
}
if (y > maxPosY - this.rect.height) {
y = maxPosY - this.rect.height;
}
}]);
var _Drag = Drag;
Drag = transient()(Drag) || Drag;
switch (axis) {
case "x":
y = this.startTop;
break;
case "y":
x = this.startLeft;
break;
}
this.clone.style.left = x + "px";
this.clone.style.top = y + "px";
};
Drag.prototype.end = function end() {
if (this.element === null) {
return;
}
this.unpin();
this.element = null;
this.item = null;
};
return Drag;
})();
}()) || _class));

@@ -120,2 +124,3 @@ _export("Drag", Drag);

};
});
});
//# sourceMappingURL=drag.js.map

@@ -1,14 +0,15 @@

System.register([], function (_export) {
"use strict";
"use strict";
_export("configure", configure);
function configure(config) {
config.globalResources("./sortable");
}
System.register([], function (_export, _context) {
return {
setters: [],
execute: function () {}
execute: function () {
function configure(config) {
config.globalResources("./sortable");
}
_export("configure", configure);
}
};
});
});
//# sourceMappingURL=index.js.map

@@ -1,12 +0,55 @@

System.register(["aurelia-pal", "aurelia-templating", "aurelia-dependency-injection", "oribella-default-gestures", "./drag", "./auto-scroll"], function (_export) {
"use strict";
"use strict";
var DOM, customAttribute, bindable, inject, transient, oribella, matchesSelector, STRATEGY_FLAG, Drag, AutoScroll, PLACEHOLDER, Sortable, SortableItem;
System.register(["aurelia-pal", "aurelia-templating", "aurelia-dependency-injection", "oribella-default-gestures", "./drag", "./auto-scroll"], function (_export, _context) {
var DOM, customAttribute, bindable, inject, transient, oribella, matchesSelector, STRATEGY_FLAG, Drag, AutoScroll, _dec, _dec2, _dec3, _class, _desc, _value, _class2, _descriptor, _descriptor2, _descriptor3, _descriptor4, _descriptor5, _descriptor6, _descriptor7, _descriptor8, _descriptor9, _descriptor10, _descriptor11, _descriptor12, _dec4, _class4, _desc2, _value2, _class5, _descriptor13, SORTABLE_ITEM, Sortable, SortableItem;
var _createDecoratedClass = (function () { function defineProperties(target, descriptors, initializers) { for (var i = 0; i < descriptors.length; i++) { var descriptor = descriptors[i]; var decorators = descriptor.decorators; var key = descriptor.key; delete descriptor.key; delete descriptor.decorators; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor || descriptor.initializer) descriptor.writable = true; if (decorators) { for (var f = 0; f < decorators.length; f++) { var decorator = decorators[f]; if (typeof decorator === "function") { descriptor = decorator(target, key, descriptor) || descriptor; } else { throw new TypeError("The decorator for method " + descriptor.key + " is of the invalid type " + typeof decorator); } } if (descriptor.initializer !== undefined) { initializers[key] = descriptor; continue; } } Object.defineProperty(target, key, descriptor); } } return function (Constructor, protoProps, staticProps, protoInitializers, staticInitializers) { if (protoProps) defineProperties(Constructor.prototype, protoProps, protoInitializers); if (staticProps) defineProperties(Constructor, staticProps, staticInitializers); return Constructor; }; })();
function _initDefineProp(target, property, descriptor, context) {
if (!descriptor) return;
Object.defineProperty(target, property, {
enumerable: descriptor.enumerable,
configurable: descriptor.configurable,
writable: descriptor.writable,
value: descriptor.initializer ? descriptor.initializer.call(context) : void 0
});
}
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _classCallCheck(instance, Constructor) {
if (!(instance instanceof Constructor)) {
throw new TypeError("Cannot call a class as a function");
}
}
function _defineDecoratedPropertyDescriptor(target, key, descriptors) { var _descriptor = descriptors[key]; if (!_descriptor) return; var descriptor = {}; for (var _key in _descriptor) descriptor[_key] = _descriptor[_key]; descriptor.value = descriptor.initializer ? descriptor.initializer.call(target) : undefined; Object.defineProperty(target, key, descriptor); }
function _applyDecoratedDescriptor(target, property, decorators, descriptor, context) {
var desc = {};
Object['ke' + 'ys'](descriptor).forEach(function (key) {
desc[key] = descriptor[key];
});
desc.enumerable = !!desc.enumerable;
desc.configurable = !!desc.configurable;
if ('value' in desc || desc.initializer) {
desc.writable = true;
}
desc = decorators.slice().reverse().reduce(function (desc, decorator) {
return decorator(target, property, desc) || desc;
}, desc);
if (context && desc.initializer !== void 0) {
desc.value = desc.initializer ? desc.initializer.call(context) : void 0;
desc.initializer = undefined;
}
if (desc.initializer === void 0) {
Object['define' + 'Property'](target, property, desc);
desc = null;
}
return desc;
}
function _initializerWarningHelper(descriptor, context) {
throw new Error('Decorating class property failed. Please ensure that transform-class-properties is enabled.');
}
return {

@@ -31,142 +74,37 @@ setters: [function (_aureliaPal) {

execute: function () {
PLACEHOLDER = "__placeholder__";
SORTABLE_ITEM = "oa-sortable-item";
_export("PLACEHOLDER", PLACEHOLDER);
Sortable = (function () {
var _instanceInitializers = {};
var _instanceInitializers = {};
_createDecoratedClass(Sortable, [{
key: "scroll",
decorators: [bindable],
initializer: function initializer() {
return null;
},
enumerable: true
}, {
key: "scrollSpeed",
decorators: [bindable],
initializer: function initializer() {
return 10;
},
enumerable: true
}, {
key: "scrollSensitivity",
decorators: [bindable],
initializer: function initializer() {
return 10;
},
enumerable: true
}, {
key: "items",
decorators: [bindable],
initializer: function initializer() {
return [];
},
enumerable: true
}, {
key: "placeholderClass",
decorators: [bindable],
initializer: function initializer() {
return "placeholder";
},
enumerable: true
}, {
key: "axis",
decorators: [bindable],
initializer: function initializer() {
return "";
},
enumerable: true
}, {
key: "boundingRect",
decorators: [bindable],
initializer: function initializer() {
return null;
},
//{ left, top, right, bottom }
enumerable: true
}, {
key: "moved",
decorators: [bindable],
initializer: function initializer() {
return function () {};
},
enumerable: true
}, {
key: "dragZIndex",
decorators: [bindable],
initializer: function initializer() {
return 1;
},
enumerable: true
}, {
key: "disallowedDragTagNames",
decorators: [bindable],
initializer: function initializer() {
return ["INPUT", "SELECT", "TEXTAREA"];
},
enumerable: true
}, {
key: "allowDrag",
decorators: [bindable],
initializer: function initializer() {
var _this = this;
return function (args) {
if (_this.disallowedDragTagNames.indexOf(args.event.target.tagName) !== -1) {
return false;
}
if (args.event.target.isContentEditable) {
return false;
}
return true;
};
},
enumerable: true
}, {
key: "allowMove",
decorators: [bindable],
initializer: function initializer() {
return function () {
return true;
};
},
enumerable: true
}], null, _instanceInitializers);
_export("Sortable", Sortable = (_dec = customAttribute("oa-sortable"), _dec2 = inject(DOM.Element, Drag, AutoScroll), _dec3 = transient(), _dec(_class = _dec2(_class = _dec3(_class = (_class2 = function () {
function Sortable(element, drag, autoScroll) {
_classCallCheck(this, _Sortable);
_classCallCheck(this, Sortable);
_defineDecoratedPropertyDescriptor(this, "scroll", _instanceInitializers);
_initDefineProp(this, "scroll", _descriptor, this);
_defineDecoratedPropertyDescriptor(this, "scrollSpeed", _instanceInitializers);
_initDefineProp(this, "scrollSpeed", _descriptor2, this);
_defineDecoratedPropertyDescriptor(this, "scrollSensitivity", _instanceInitializers);
_initDefineProp(this, "scrollSensitivity", _descriptor3, this);
_defineDecoratedPropertyDescriptor(this, "items", _instanceInitializers);
_initDefineProp(this, "items", _descriptor4, this);
_defineDecoratedPropertyDescriptor(this, "placeholderClass", _instanceInitializers);
_initDefineProp(this, "sortingClass", _descriptor5, this);
_defineDecoratedPropertyDescriptor(this, "axis", _instanceInitializers);
_initDefineProp(this, "draggingClass", _descriptor6, this);
_defineDecoratedPropertyDescriptor(this, "boundingRect", _instanceInitializers);
_initDefineProp(this, "axis", _descriptor7, this);
_defineDecoratedPropertyDescriptor(this, "moved", _instanceInitializers);
_initDefineProp(this, "moved", _descriptor8, this);
_defineDecoratedPropertyDescriptor(this, "dragZIndex", _instanceInitializers);
_initDefineProp(this, "dragZIndex", _descriptor9, this);
_defineDecoratedPropertyDescriptor(this, "disallowedDragTagNames", _instanceInitializers);
_initDefineProp(this, "disallowedDragTagNames", _descriptor10, this);
_defineDecoratedPropertyDescriptor(this, "allowDrag", _instanceInitializers);
_initDefineProp(this, "allowDrag", _descriptor11, this);
_defineDecoratedPropertyDescriptor(this, "allowMove", _instanceInitializers);
_initDefineProp(this, "allowMove", _descriptor12, this);
this.selector = "[sortable-item]";
this.selector = "[" + SORTABLE_ITEM + "]";
this.fromIx = -1;
this.toIx = -1;
this.pageX = 0;
this.pageY = 0;
this.scrollRect = { left: 0, top: 0, width: 0, height: 0 };
this.x = 0;
this.y = 0;
this.lastElementFromPointRect = null;

@@ -182,300 +120,404 @@

_createDecoratedClass(Sortable, [{
key: "activate",
value: function activate() {
this.removeListener = oribella.on(this.element, "swipe", this);
if (typeof this.scroll === "string") {
this.scroll = this.closest(this.element, this.scroll);
Sortable.prototype.activate = function activate() {
this.removeListener = oribella.on(this.element, "swipe", this);
var scroll = this.scroll;
if (typeof scroll === "string") {
if (scroll === "document") {
this.scroll = document.scrollingElement || document.documentElement || document.body;
this.viewportScroll = true;
this.removeScroll = this.bindScroll(document, this.onScroll.bind(this));
return;
} else {
scroll = this.closest(this.element, scroll);
}
if (!(this.scroll instanceof DOM.Element)) {
this.scroll = this.element;
}
this.removeScroll = this.bindScroll(this.scroll, this.onScroll.bind(this));
}
}, {
key: "deactivate",
value: function deactivate() {
if (typeof this.removeListener === "function") {
this.removeListener();
}
if (typeof this.removeScroll === "function") {
this.removeScroll();
}
this.scroll = scroll;
if (!(this.scroll instanceof DOM.Element)) {
this.scroll = this.element;
}
}, {
key: "attached",
value: function attached() {
this.activate();
this.removeScroll = this.bindScroll(this.scroll, this.onScroll.bind(this));
};
Sortable.prototype.deactivate = function deactivate() {
if (typeof this.removeListener === "function") {
this.removeListener();
}
}, {
key: "detached",
value: function detached() {
this.deactivate();
if (typeof this.removeScroll === "function") {
this.removeScroll();
}
}, {
key: "bindScroll",
value: function bindScroll(scroll, fn) {
scroll.addEventListener("scroll", fn, false);
return function () {
scroll.removeEventListener("scroll", fn, false);
};
};
Sortable.prototype.attached = function attached() {
this.activate();
};
Sortable.prototype.detached = function detached() {
this.deactivate();
};
Sortable.prototype.bindScroll = function bindScroll(scroll, fn) {
scroll.addEventListener("scroll", fn, false);
return function () {
scroll.removeEventListener("scroll", fn, false);
};
};
Sortable.prototype.onScroll = function onScroll() {
if (!this.drag.element) {
return;
}
}, {
key: "onScroll",
value: function onScroll() {
if (!this.drag.element) {
return;
}
var scrollLeft = this.scroll.scrollLeft;
var scrollTop = this.scroll.scrollTop;
this.drag.update(this.pageX, this.pageY, scrollLeft, scrollTop, this.axis);
var _scroll = this.scroll;
var scrollLeft = _scroll.scrollLeft;
var scrollTop = _scroll.scrollTop;
var _getPoint = this.getPoint(this.pageX, this.pageY);
this.drag.update(this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.axis, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
var x = _getPoint.x;
var y = _getPoint.y;
var _getPoint = this.getPoint(this.x, this.y);
this.tryMove(x, y, scrollLeft, scrollTop);
var x = _getPoint.x;
var y = _getPoint.y;
this.tryMove(x, y, scrollLeft, scrollTop);
};
Sortable.prototype.getScrollFrames = function getScrollFrames(maxPos, scrollPos) {
return Math.max(0, Math.ceil(Math.abs(maxPos - scrollPos) / this.scrollSpeed));
};
Sortable.prototype.getScrollDirectionX = function getScrollDirectionX(x, _ref) {
var left = _ref.left;
var right = _ref.right;
var dir = 0;
switch (this.axis) {
default:
case "x":
if (x >= right - this.scrollSensitivity) {
dir = 1;
} else if (x <= left + this.scrollSensitivity) {
dir = -1;
}
break;
}
}, {
key: "hide",
value: function hide(element) {
var display = element.style.display;
element.style.display = "none";
return function () {
element.style.display = display;
};
}
}, {
key: "closest",
value: function closest(element, selector) {
var rootElement = arguments.length <= 2 || arguments[2] === undefined ? document : arguments[2];
return dir;
};
var valid = false;
while (!valid && element !== null && element !== rootElement && element !== document) {
valid = matchesSelector(element, selector);
if (valid) {
break;
Sortable.prototype.getScrollDirectionY = function getScrollDirectionY(y, _ref2) {
var top = _ref2.top;
var bottom = _ref2.bottom;
var dir = 0;
switch (this.axis) {
default:
case "y":
if (y >= bottom - this.scrollSensitivity) {
dir = 1;
} else if (y <= top + this.scrollSensitivity) {
dir = -1;
}
element = element.parentNode;
}
return valid ? element : null;
break;
}
}, {
key: "getItemViewModel",
value: function getItemViewModel(element) {
return element.au["sortable-item"].viewModel;
}
}, {
key: "addPlaceholder",
value: function addPlaceholder(toIx, item) {
var placeholder = Object.create(item, { placeholderClass: { value: this.placeholderClass, writable: true } });
return dir;
};
if (!placeholder.style) {
placeholder.style = {};
}
placeholder.style.width = this.drag.rect.width;
placeholder.style.height = this.drag.rect.height;
Sortable.prototype.hide = function hide(element) {
var display = element.style.display;
element.style.display = "none";
return function () {
element.style.display = display;
};
};
this[PLACEHOLDER] = placeholder;
this.items.splice(toIx, 0, placeholder);
}
}, {
key: "removePlaceholder",
value: function removePlaceholder() {
var ix = this.items.indexOf(this[PLACEHOLDER]);
if (ix !== -1) {
this.items.splice(ix, 1);
Sortable.prototype.closest = function closest(element, selector) {
var rootElement = arguments.length <= 2 || arguments[2] === undefined ? document : arguments[2];
var valid = false;
while (!valid && element !== null && element !== rootElement && element !== document) {
valid = matchesSelector(element, selector);
if (valid) {
break;
}
element = element.parentNode;
}
}, {
key: "movePlaceholder",
value: function movePlaceholder(toIx) {
var fromIx = this.items.indexOf(this[PLACEHOLDER]);
this.move(fromIx, toIx);
return valid ? element : null;
};
Sortable.prototype.getItemViewModel = function getItemViewModel(element) {
return element.au[SORTABLE_ITEM].viewModel;
};
Sortable.prototype.moveSortingItem = function moveSortingItem(toIx) {
var fromIx = this.items.indexOf(this.drag.item);
this.move(fromIx, toIx);
};
Sortable.prototype.move = function move(fromIx, toIx) {
if (fromIx !== -1 && toIx !== -1 && fromIx !== toIx) {
this.items.splice(toIx, 0, this.items.splice(fromIx, 1)[0]);
}
}, {
key: "move",
value: function move(fromIx, toIx) {
if (fromIx !== -1 && toIx !== -1 && fromIx !== toIx) {
this.items.splice(toIx, 0, this.items.splice(fromIx, 1)[0]);
}
};
Sortable.prototype.tryUpdate = function tryUpdate(x, y, offsetX, offsetY) {
var showFn = this.hide(this.drag.clone);
this.tryMove(x, y, offsetX, offsetY);
showFn();
};
Sortable.prototype.pointInside = function pointInside(x, y, rect) {
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
};
Sortable.prototype.elementFromPoint = function elementFromPoint(x, y) {
var element = document.elementFromPoint(x, y);
if (!element) {
return null;
}
}, {
key: "tryUpdate",
value: function tryUpdate(pageX, pageY, offsetX, offsetY) {
var showFn = this.hide(this.drag.element);
this.tryMove(pageX, pageY, offsetX, offsetY);
showFn();
element = this.closest(element, this.selector, this.element);
if (!element) {
return null;
}
}, {
key: "pointInside",
value: function pointInside(x, y, rect) {
return x >= rect.left && x <= rect.right && y >= rect.top && y <= rect.bottom;
return element;
};
Sortable.prototype.canThrottle = function canThrottle(x, y, offsetX, offsetY) {
return this.lastElementFromPointRect && this.pointInside(x + offsetX, y + offsetY, this.lastElementFromPointRect);
};
Sortable.prototype.tryMove = function tryMove(x, y, offsetX, offsetY) {
if (this.canThrottle(x, y, offsetX, offsetY)) {
return;
}
}, {
key: "elementFromPoint",
value: function elementFromPoint(x, y) {
var element = document.elementFromPoint(x, y);
if (!element) {
return null;
}
element = this.closest(element, this.selector, this.element);
if (!element) {
return null;
}
return element;
var element = this.elementFromPoint(x, y);
if (!element) {
return;
}
}, {
key: "canThrottle",
value: function canThrottle(x, y, offsetX, offsetY) {
return this.lastElementFromPointRect && this.pointInside(x + offsetX, y + offsetY, this.lastElementFromPointRect);
var vm = this.getItemViewModel(element);
this.lastElementFromPointRect = element.getBoundingClientRect();
if (!this.allowMove({ item: vm.item })) {
return;
}
}, {
key: "tryMove",
value: function tryMove(x, y, offsetX, offsetY) {
if (this.canThrottle(x, y, offsetX, offsetY)) {
return;
}
var element = this.elementFromPoint(x, y);
if (!element) {
return;
}
var model = this.getItemViewModel(element);
this.lastElementFromPointRect = element.getBoundingClientRect();
if (!this.allowMove({ item: model.item })) {
return;
}
var ix = model.ctx.$index;
this.movePlaceholder(ix);
this.moveSortingItem(vm.ctx.$index);
};
Sortable.prototype.getPoint = function getPoint(pageX, pageY) {
switch (this.axis) {
case "x":
pageY = this.drag.getCenterY();
break;
case "y":
pageX = this.drag.getCenterX();
break;
default:
break;
}
}, {
key: "getPoint",
value: function getPoint(pageX, pageY) {
switch (this.axis) {
case "x":
pageY = this.drag.getCenterY();
break;
case "y":
pageX = this.drag.getCenterX();
break;
default:
break;
}
return {
x: Math.max(this.boundingRect.left, Math.min(this.boundingRect.right, pageX)),
y: Math.max(this.boundingRect.top, Math.min(this.boundingRect.bottom, pageY))
};
return {
x: pageX,
y: pageY
};
};
Sortable.prototype.down = function down(e, data, element) {
if (this.allowDrag({ event: e, item: this.getItemViewModel(element).item })) {
e.preventDefault();
return undefined;
}
}, {
key: "down",
value: function down(e, data, element) {
if (this.allowDrag({ event: e, item: this.getItemViewModel(element).item })) {
e.preventDefault();
return undefined;
}
return false;
return false;
};
Sortable.prototype.start = function start(e, data, element) {
var _scroll2 = this.scroll;
var scrollLeft = _scroll2.scrollLeft;
var scrollTop = _scroll2.scrollTop;
this.windowHeight = innerHeight;
this.windowWidth = innerWidth;
this.x = data.pointers[0].client.x;
this.y = data.pointers[0].client.y;
this.sortableRect = this.element.getBoundingClientRect();
this.scrollRect = this.scroll.getBoundingClientRect();
this.scrollWidth = this.scroll.scrollWidth;
this.scrollHeight = this.scroll.scrollHeight;
this.boundingRect = {
left: Math.max(0, this.sortableRect.left),
top: Math.max(0, this.sortableRect.top),
bottom: Math.min(this.windowHeight, this.sortableRect.bottom),
right: Math.min(this.windowWidth, this.sortableRect.right)
};
this.sortableContainsScroll = this.element.contains(this.scroll);
if (this.sortableContainsScroll) {
this.scrollMaxPosX = this.scrollWidth - this.scrollRect.width;
this.scrollMaxPosY = this.scrollHeight - this.scrollRect.height;
this.dragMinPosX = this.sortableRect.left;
this.dragMaxPosX = this.sortableRect.left + this.scrollWidth;
this.dragMaxPosY = this.sortableRect.top + this.scrollHeight;
this.dragMinPosY = this.sortableRect.top;
} else {
this.scrollMaxPosX = this.sortableRect.right - this.windowWidth + (this.viewportScroll ? scrollLeft : 0);
this.scrollMaxPosY = this.sortableRect.bottom - this.windowHeight + (this.viewportScroll ? scrollTop : 0);
this.dragMinPosX = this.sortableRect.left + scrollLeft;
this.dragMaxPosX = this.scrollMaxPosX + this.windowWidth;
this.dragMinPosY = this.sortableRect.top + scrollTop;
this.dragMaxPosY = this.scrollMaxPosY + this.windowHeight;
}
}, {
key: "start",
value: function start(e, data, element) {
this.pageX = data.pointers[0].page.x;
this.pageY = data.pointers[0].page.y;
this.scrollRect = this.scroll.getBoundingClientRect();
this.scrollWidth = this.scroll.scrollWidth;
this.scrollHeight = this.scroll.scrollHeight;
this.boundingRect = this.boundingRect || { left: this.scrollRect.left + 5, top: this.scrollRect.top + 5, right: this.scrollRect.right - 5, bottom: this.scrollRect.bottom - 5 };
this.drag.start(element, this.pageX, this.pageY, this.scroll.scrollLeft, this.scroll.scrollTop, this.dragZIndex);
this.autoScroll.start(this.axis, this.scrollSpeed, this.scrollSensitivity);
var viewModel = this.getItemViewModel(element);
this.fromIx = viewModel.ctx.$index;
this.toIx = -1;
this.addPlaceholder(this.fromIx, viewModel.item);
this.lastElementFromPointRect = this.drag.rect;
}
}, {
key: "update",
value: function update(e, data) {
var p = data.pointers[0].page;
var pageX = this.pageX = p.x;
var pageY = this.pageY = p.y;
var scrollLeft = this.scroll.scrollLeft;
var scrollTop = this.scroll.scrollTop;
this.drag.update(pageX, pageY, scrollLeft, scrollTop, this.axis);
this.sortingViewModel = this.getItemViewModel(element);
this.fromIx = this.sortingViewModel.ctx.$index;
this.toIx = -1;
var _getPoint2 = this.getPoint(pageX, pageY);
this.drag.start(element, this.sortingViewModel.item, this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.dragZIndex, this.axis, this.sortingClass, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
this.autoScroll.start(this.scrollSpeed);
this.lastElementFromPointRect = this.drag.rect;
};
var x = _getPoint2.x;
var y = _getPoint2.y;
Sortable.prototype.update = function update(e, data) {
var p = data.pointers[0].client;
var _scroll3 = this.scroll;
var scrollLeft = _scroll3.scrollLeft;
var scrollTop = _scroll3.scrollTop;
var scrollX = this.autoScroll.active ? scrollLeft : 0;
var scrollY = this.autoScroll.active ? scrollTop : 0;
this.tryUpdate(x, y, scrollX, scrollY);
this.autoScroll.update(this.scroll, x, y, this.scrollWidth, this.scrollHeight, this.scrollRect);
this.x = p.x;
this.y = p.y;
this.drag.update(this.x, this.y, this.viewportScroll, scrollLeft, scrollTop, this.axis, this.dragMinPosX, this.dragMaxPosX, this.dragMinPosY, this.dragMaxPosY);
var _getPoint2 = this.getPoint(p.x, p.y);
var x = _getPoint2.x;
var y = _getPoint2.y;
var scrollX = this.autoScroll.active ? scrollLeft : 0;
var scrollY = this.autoScroll.active ? scrollTop : 0;
this.tryUpdate(x, y, scrollX, scrollY);
var dirX = this.getScrollDirectionX(x, this.boundingRect);
var dirY = this.getScrollDirectionY(y, this.boundingRect);
var frameCntX = this.getScrollFrames(dirX === -1 ? 0 : this.scrollMaxPosX, scrollLeft);
var frameCntY = this.getScrollFrames(dirY === -1 ? 0 : this.scrollMaxPosY, scrollTop);
if (dirX === 1 && scrollLeft >= this.scrollMaxPosX || dirX === -1 && scrollLeft === 0) {
frameCntX = 0;
}
}, {
key: "end",
value: function end() {
this.toIx = this.items.indexOf(this[PLACEHOLDER]);
if (this.toIx === -1) {
return; //cancelled
}
this.move(this.toIx < this.fromIx ? this.fromIx + 1 : this.fromIx, this.toIx);
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
if (dirY === 1 && scrollTop >= this.scrollMaxPosY || dirY === -1 && scrollTop === 0) {
frameCntY = 0;
}
this.autoScroll.update(this.scroll, dirX, dirY, frameCntX, frameCntY);
};
if (this.fromIx < this.toIx) {
--this.toIx;
}
if (this.fromIx !== this.toIx) {
this.moved({ fromIx: this.fromIx, toIx: this.toIx });
}
Sortable.prototype.end = function end() {
if (!this.drag.item) {
return; //cancelled
}
}, {
key: "cancel",
value: function cancel() {
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
this.stop();
if (this.fromIx !== this.toIx) {
this.moved({ fromIx: this.fromIx, toIx: this.toIx });
}
}], null, _instanceInitializers);
};
var _Sortable = Sortable;
Sortable = transient()(Sortable) || Sortable;
Sortable = inject(DOM.Element, Drag, AutoScroll)(Sortable) || Sortable;
Sortable = customAttribute("sortable")(Sortable) || Sortable;
Sortable.prototype.cancel = function cancel() {
this.move(this.sortingViewModel.ctx.$index, this.fromIx);
this.stop();
};
Sortable.prototype.stop = function stop() {
this.drag.end();
this.autoScroll.end();
};
return Sortable;
})();
}(), (_descriptor = _applyDecoratedDescriptor(_class2.prototype, "scroll", [bindable], {
enumerable: true,
initializer: function initializer() {
return null;
}
}), _descriptor2 = _applyDecoratedDescriptor(_class2.prototype, "scrollSpeed", [bindable], {
enumerable: true,
initializer: function initializer() {
return 10;
}
}), _descriptor3 = _applyDecoratedDescriptor(_class2.prototype, "scrollSensitivity", [bindable], {
enumerable: true,
initializer: function initializer() {
return 10;
}
}), _descriptor4 = _applyDecoratedDescriptor(_class2.prototype, "items", [bindable], {
enumerable: true,
initializer: function initializer() {
return [];
}
}), _descriptor5 = _applyDecoratedDescriptor(_class2.prototype, "sortingClass", [bindable], {
enumerable: true,
initializer: function initializer() {
return "oa-sorting";
}
}), _descriptor6 = _applyDecoratedDescriptor(_class2.prototype, "draggingClass", [bindable], {
enumerable: true,
initializer: function initializer() {
return "oa-dragging";
}
}), _descriptor7 = _applyDecoratedDescriptor(_class2.prototype, "axis", [bindable], {
enumerable: true,
initializer: function initializer() {
return "";
}
}), _descriptor8 = _applyDecoratedDescriptor(_class2.prototype, "moved", [bindable], {
enumerable: true,
initializer: function initializer() {
return function () {};
}
}), _descriptor9 = _applyDecoratedDescriptor(_class2.prototype, "dragZIndex", [bindable], {
enumerable: true,
initializer: function initializer() {
return 1;
}
}), _descriptor10 = _applyDecoratedDescriptor(_class2.prototype, "disallowedDragTagNames", [bindable], {
enumerable: true,
initializer: function initializer() {
return ["INPUT", "SELECT", "TEXTAREA"];
}
}), _descriptor11 = _applyDecoratedDescriptor(_class2.prototype, "allowDrag", [bindable], {
enumerable: true,
initializer: function initializer() {
var _this = this;
return function (args) {
if (_this.disallowedDragTagNames.indexOf(args.event.target.tagName) !== -1) {
return false;
}
if (args.event.target.isContentEditable) {
return false;
}
return true;
};
}
}), _descriptor12 = _applyDecoratedDescriptor(_class2.prototype, "allowMove", [bindable], {
enumerable: true,
initializer: function initializer() {
return function () {
return true;
};
}
})), _class2)) || _class) || _class) || _class));
_export("Sortable", Sortable);
SortableItem = (function () {
var _instanceInitializers2 = {};
_export("SortableItem", SortableItem = (_dec4 = customAttribute("oa-sortable-item"), _dec4(_class4 = (_class5 = function () {
function SortableItem() {
_classCallCheck(this, _SortableItem);
_classCallCheck(this, SortableItem);
_defineDecoratedPropertyDescriptor(this, "item", _instanceInitializers2);
_initDefineProp(this, "item", _descriptor13, this);
}
_createDecoratedClass(SortableItem, [{
key: "bind",
value: function bind(ctx, overrideCtx) {
this.ctx = overrideCtx; //Need a reference to the item's $index
}
}, {
key: "item",
decorators: [bindable],
initializer: function initializer() {
return null;
},
enumerable: true
}], null, _instanceInitializers2);
SortableItem.prototype.bind = function bind(ctx, overrideCtx) {
this.ctx = overrideCtx; //Need a reference to the item's $index
};
var _SortableItem = SortableItem;
SortableItem = customAttribute("sortable-item")(SortableItem) || SortableItem;
return SortableItem;
})();
}(), (_descriptor13 = _applyDecoratedDescriptor(_class5.prototype, "item", [bindable], {
enumerable: true,
initializer: function initializer() {
return null;
}
})), _class5)) || _class4));

@@ -485,2 +527,3 @@ _export("SortableItem", SortableItem);

};
});
});
//# sourceMappingURL=sortable.js.map
{
"name": "oribella-aurelia-sortable",
"version": "0.6.0",
"version": "0.7.0",
"description": "",

@@ -10,15 +10,20 @@ "license": "MIT",

"type": "git",
"url": "http://github.com/oribella/aurelia-sortable"
"url": "https://github.com/oribella/aurelia-sortable"
},
"scripts": {
"version": "dev-changelog && git add CHANGELOG.md",
"build": "dev-build -cas",
"build": "dev-build",
"test": "dev-test -- test/initialize-pal.js test/*.spec.js",
"test:browser": "dev-test-browser test/*.spec.js --init-files test/initialize-pal-browser.js",
"test:browser:ci": "dev-test-browser test/*.spec.js --init-files test/initialize-pal-browser.js --single-run",
"coverage": "dev-coverage -- -- test/initialize-pal.js test/*.spec.js",
"lint": "dev-lint"
"coverage": "dev-coverage -- test/initialize-pal.js test/*.spec.js",
"lint": "dev-lint",
"dev": "cd demo && webpack-dev-server --config webpack.config.js --hot --inline --progress --devtool cheap-module-eval-source-map",
"demo:build": "cd demo && webpack --config webpack.config.js --progress --profile",
"demo:prod": "cd demo && webpack -p --config webpack.prod.config.js --progress --devtool source-map",
"demo:deploy": "git subtree split --prefix demo/dist -b gh-pages && git push origin gh-pages:gh-pages"
},
"jspmNodeConversion": false,
"jspm": {
"registry": "npm",
"jspmPackage": true,
"main": "index",

@@ -29,27 +34,27 @@ "format": "amd",

},
"peerDependencies": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@^1.0.0-beta.1.1.4",
"aurelia-pal": "npm:aurelia-pal@^1.0.0-beta.1.1.1",
"aurelia-pal-browser": "npm:aurelia-pal-browser@^1.0.0-beta.1.1.4",
"aurelia-templating": "npm:aurelia-templating@^1.0.0-beta.1.1.2",
"oribella-default-gestures": "^0.5.2"
},
"dependencies": {
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@^1.0.0-beta.1",
"aurelia-pal": "npm:aurelia-pal@^1.0.0-beta.1.0.1",
"aurelia-pal-browser": "npm:aurelia-pal-browser@^1.0.0-beta.1.0.1",
"aurelia-templating": "npm:aurelia-templating@^1.0.0-beta.1.0.1",
"oribella-default-gestures": "npm:oribella-default-gestures@^0.4.0"
},
"devDependencies": {
"aurelia-binding": "npm:aurelia-binding@^1.0.0-beta.1.1.1",
"aurelia-loader": "npm:aurelia-loader@^1.0.0-beta.1.1.0",
"aurelia-logging": "npm:aurelia-logging@^1.0.0-beta.1.1.1",
"aurelia-metadata": "npm:aurelia-metadata@^1.0.0-beta.1.1.3",
"aurelia-path": "npm:aurelia-path@^1.0.0-beta.1.1.0",
"aurelia-polyfills": "npm:aurelia-polyfills@^1.0.0-beta.1.0.1",
"aurelia-task-queue": "npm:aurelia-task-queue@^1.0.0-beta.1.1.0",
"babel": "npm:babel-core@^5.8.24",
"babel-runtime": "npm:babel-runtime@^5.8.24",
"core-js": "npm:core-js@^2.1.3"
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@^1.0.0-beta.1.1.4",
"aurelia-pal": "npm:aurelia-pal@^1.0.0-beta.1.1.1",
"aurelia-pal-browser": "npm:aurelia-pal-browser@^1.0.0-beta.1.1.4",
"aurelia-templating": "npm:aurelia-templating@^1.0.0-beta.1.1.2",
"oribella-default-gestures": "^0.5.2"
}
},
"devDependencies": {
"dependencies": {
"aurelia-binding": "^1.0.0-beta.1.2.2",
"aurelia-dependency-injection": "^1.0.0-beta.1.1.4",
"aurelia-event-aggregator": "^1.0.0-beta.1.1.1",
"aurelia-framework": "^1.0.0-beta.1.1.4",
"aurelia-history-browser": "^1.0.0-beta.1.1.4",
"aurelia-http-client": "^1.0.0-beta.1.1.2",
"aurelia-loader": "^1.0.0-beta.1.1.1",
"aurelia-logging": "^1.0.0-beta.1.1.2",
"aurelia-logging-console": "^1.0.0-beta.1.1.4",
"aurelia-metadata": "^1.0.0-beta.1.1.6",

@@ -60,8 +65,25 @@ "aurelia-pal": "^1.0.0-beta.1.1.1",

"aurelia-polyfills": "^1.0.0-beta.1.0.1",
"aurelia-router": "^1.0.0-beta.1.1.3",
"aurelia-task-queue": "^1.0.0-beta.1.1.1",
"aurelia-templating": "^1.0.0-beta.1.1.2",
"jspm": "^0.16.15",
"oribella-default-gestures": "^0.4.0",
"oribella-dev": "^0.1.25"
"aurelia-templating-binding": "^1.0.0-beta.1.1.2",
"aurelia-templating-resources": "^1.0.0-beta.1.1.3",
"aurelia-templating-router": "^1.0.0-beta.1.1.2",
"oribella-default-gestures": "^0.5.2"
},
"devDependencies": {
"aurelia-bootstrapper-webpack": "^0.1.0",
"aurelia-webpack-plugin": "^1.0.0-beta.1.0.0",
"babel-loader": "^6.2.4",
"css-loader": "^0.23.1",
"file-loader": "^0.8.5",
"font-awesome": "^4.5.0",
"html-webpack-plugin": "^2.9.0",
"oribella-dev": "^0.3.7",
"raw-loader": "^0.5.1",
"style-loader": "^0.13.0",
"url-loader": "^0.5.7",
"webpack": "^1.12.14",
"webpack-dev-server": "^1.14.1"
}
}

@@ -92,15 +92,2 @@ # oribella/aurelia-sortable

To be able to constrain the *sortable* bounding rect add:
```markup
<!-- Other bindings omitted -->
<div sortable="bounding-rect.bind: {
left: 20,
top: 20,
right: 20,
bottom: 20 }">
</div>
```
This is useful if the list has a padding and you still want to lock the `axis` movement.
###### Default `boundingRect={ left: 0, top: 0, right: 0, bottom : 0 }`.
To make sure that the dragging of a *sortable item* always is on top of other elements make sure to bind:

@@ -107,0 +94,0 @@ ```markup

@@ -5,19 +5,13 @@ import {transient} from "aurelia-dependency-injection";

export class AutoScroll {
ticks = [0, 0];
rAFId = -1;
axis = "";
speed = 10;
sensitivity = 10;
active = false;
start(axis = "", speed = 10, sensitivity = 10) {
this.axis = axis;
start(speed = 10) {
this.speed = speed;
this.sensitivity = sensitivity;
}
update(element, x, y, scrollWidth, scrollHeight, scrollRect, rAF = requestAnimationFrame, cAF = cancelAnimationFrame) {
const d = this.getScrollDirection(x, y, scrollRect);
if(this.active) {
if(d[0] === 0 && d[1] === 0) {
cAF(this.rAFId);
update(element, dirX, dirY, frameCntX, frameCntY) {
if (this.active) {
if (dirX === 0 && dirY === 0) {
cancelAnimationFrame(this.rAFId);
this.active = false;

@@ -27,26 +21,28 @@ }

}
if(d[0] === 0 && d[1] === 0) {
if (dirX === 0 && dirY === 0) {
return;
}
this.ticks = this.getTicks(d, element.scrollLeft, element.scrollTop, scrollWidth, scrollHeight, scrollRect.width, scrollRect.height);
if(this.ticks[0] <= 0 && this.ticks[1] <= 0) {
if (frameCntX === 0 && frameCntY === 0) {
return;
}
const scrollDeltaX = d[0] * this.speed;
const scrollDeltaY = d[1] * this.speed;
const scrollDeltaX = dirX * this.speed;
const scrollDeltaY = dirY * this.speed;
const autoScroll = () => {
if(this.ticks[0] > 0) {
if ( !this.active ) {
return;
}
if (frameCntX > 0) {
element.scrollLeft += scrollDeltaX;
}
if(this.ticks[1] > 0) {
if (frameCntY > 0) {
element.scrollTop += scrollDeltaY;
}
--this.ticks[0];
--this.ticks[1];
if (this.ticks[0] <= 0 && this.ticks[1] <= 0) {
--frameCntX;
--frameCntY;
if (frameCntX <= 0 && frameCntY <= 0) {
this.active = false;

@@ -56,3 +52,3 @@ return;

this.rAFId = rAF(autoScroll);
this.rAFId = requestAnimationFrame(autoScroll);
};

@@ -65,31 +61,4 @@

cAF(this.rAFId);
this.ticks = [0, 0];
this.active = false;
}
getTicks(d, scrollLeft, scrollTop, scrollWidth, scrollHeight, width, height) {
const ticks = [];
ticks[0] = d[0] > 0 ?
Math.ceil((scrollWidth - width - scrollLeft) / this.speed) :
d[0] < 0 ? scrollLeft / this.speed : 0;
ticks[1] = d[1] > 0 ?
Math.ceil((scrollHeight - height - scrollTop) / this.speed) :
d[1] < 0 ? scrollTop / this.speed : 0;
return ticks;
}
getScrollDirection(x, y, scrollRect) {
const { left, top, right, bottom = 0 } = scrollRect;
const d = [0, 0];
d[0] = this.axis === "y" ? 0 :
(x >= right - this.sensitivity) ? 1 :
(x <= left + this.sensitivity) ? -1 : 0;
d[1] = this.axis === "x" ? 0 :
(y >= bottom - this.sensitivity) ? 1 :
(y <= top + this.sensitivity) ? -1 : 0;
return d;
}
}

@@ -11,26 +11,18 @@ import {transient} from "aurelia-dependency-injection";

pin(element, rect, dragZIndex) {
this.element = element;
let style = {};
style.position = element.style.position;
style.left = element.style.left;
style.top = element.style.top;
style.width = element.style.width;
style.height = element.style.height;
style.pointerEvents = element.style.pointerEvents;
style.zIndex = element.style.zIndex;
element.style.position = "absolute";
element.style.width = rect.width + "px";
element.style.height = rect.height + "px";
element.style.pointerEvents = "none";
element.style.zIndex = dragZIndex;
return () => {
Object.keys( style ).forEach( key => {
element.style[key] = style[key];
} );
};
pin() {
this.item.sortingClass = this.sortingClass;
this.clone = this.element.cloneNode(true);
this.clone.style.position = "absolute";
this.clone.style.width = this.rect.width + "px";
this.clone.style.height = this.rect.height + "px";
this.clone.style.pointerEvents = "none";
this.clone.style.margin = 0;
this.clone.style.zIndex = this.dragZIndex;
document.body.appendChild(this.clone);
}
unpin() {
this.item.sortingClass = "";
document.body.removeChild(this.clone);
this.clone = null;
}
getCenterX() {

@@ -42,42 +34,61 @@ return this.rect.left + this.rect.width / 2;

}
start(element, pageX, pageY, scrollLeft, scrollTop, dragZIndex) {
start(element, item, x, y, viewportScroll, scrollLeft, scrollTop, dragZIndex, axis, sortingClass, minPosX, maxPosX, minPosY, maxPosY) {
this.element = element;
this.item = item;
this.sortingClass = sortingClass;
this.dragZIndex = dragZIndex;
const rect = (this.rect = element.getBoundingClientRect());
const offsetParentRect = element.offsetParent.getBoundingClientRect();
this.startLeft = rect.left - offsetParentRect.left;
this.startTop = rect.top - offsetParentRect.top;
this.startLeft = rect.left;
this.startTop = rect.top;
this.offsetX = this.startLeft - pageX - scrollLeft;
this.offsetY = this.startTop - pageY - scrollTop;
this.offsetX = this.startLeft - x;
this.offsetY = this.startTop - y;
this.unpin = this.pin(element, rect, dragZIndex);
this.pin();
this.update(pageX, pageY, scrollLeft, scrollTop);
this.update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY);
}
update(pageX, pageY, scrollLeft, scrollTop, axis) {
let left = pageX + this.offsetX + scrollLeft;
let top = pageY + this.offsetY + scrollTop;
update(x, y, viewportScroll, scrollLeft, scrollTop, axis, minPosX, maxPosX, minPosY, maxPosY) {
x += this.offsetX;
y += this.offsetY;
if (viewportScroll) {
x += scrollLeft;
y += scrollTop;
}
if (x < minPosX) {
x = minPosX;
}
if (x > maxPosX - this.rect.width) {
x = maxPosX - this.rect.width;
}
if (y < minPosY) {
y = minPosY;
}
if (y > maxPosY - this.rect.height) {
y = maxPosY - this.rect.height;
}
switch (axis) {
case "x":
top = this.startTop;
y = this.startTop;
break;
case "y":
left = this.startLeft;
x = this.startLeft;
break;
default:
break;
}
this.element.style.left = left + "px";
this.element.style.top = top + "px";
this.clone.style.left = x + "px";
this.clone.style.top = y + "px";
}
end() {
if (this.element) {
if(typeof this.unpin === "function") {
this.unpin();
}
this.element = null;
if (this.element === null) {
return;
}
this.unpin();
this.element = null;
this.item = null;
}
}

@@ -8,5 +8,5 @@ import {DOM} from "aurelia-pal";

export const PLACEHOLDER = "__placeholder__";
const SORTABLE_ITEM = "oa-sortable-item";
@customAttribute("sortable")
@customAttribute("oa-sortable")
@inject(DOM.Element, Drag, AutoScroll)

@@ -20,5 +20,5 @@ @transient()

@bindable items = [];
@bindable placeholderClass = "placeholder";
@bindable sortingClass = "oa-sorting";
@bindable draggingClass = "oa-dragging";
@bindable axis = "";
@bindable boundingRect = null; //{ left, top, right, bottom }
@bindable moved = () => {};

@@ -38,8 +38,7 @@ @bindable dragZIndex = 1;

selector = "[sortable-item]";
selector = "[" + SORTABLE_ITEM + "]";
fromIx = -1;
toIx = -1;
pageX = 0;
pageY = 0;
scrollRect = { left: 0, top: 0, width: 0, height: 0 };
x = 0;
y = 0;
lastElementFromPointRect = null;

@@ -57,5 +56,14 @@

this.removeListener = oribella.on(this.element, "swipe", this);
if (typeof this.scroll === "string") {
this.scroll = this.closest(this.element, this.scroll);
let scroll = this.scroll;
if (typeof scroll === "string") {
if (scroll === "document") {
this.scroll = document.scrollingElement || document.documentElement || document.body;
this.viewportScroll = true;
this.removeScroll = this.bindScroll(document, this.onScroll.bind(this));
return;
} else {
scroll = this.closest(this.element, scroll);
}
}
this.scroll = scroll;
if (!(this.scroll instanceof DOM.Element)) {

@@ -90,8 +98,47 @@ this.scroll = this.element;

}
const scrollLeft = this.scroll.scrollLeft;
const scrollTop = this.scroll.scrollTop;
this.drag.update(this.pageX, this.pageY, scrollLeft, scrollTop, this.axis);
const { x, y } = this.getPoint(this.pageX, this.pageY);
const { scrollLeft, scrollTop } = this.scroll;
this.drag.update(this.x,
this.y,
this.viewportScroll,
scrollLeft,
scrollTop,
this.axis,
this.dragMinPosX,
this.dragMaxPosX,
this.dragMinPosY,
this.dragMaxPosY);
const { x, y } = this.getPoint(this.x, this.y);
this.tryMove(x, y, scrollLeft, scrollTop);
}
getScrollFrames(maxPos, scrollPos) {
return Math.max(0, Math.ceil(Math.abs(maxPos - scrollPos) / this.scrollSpeed));
}
getScrollDirectionX(x, { left, right }) {
let dir = 0;
switch (this.axis) {
default:
case "x":
if (x >= right - this.scrollSensitivity) {
dir = 1;
} else if (x <= left + this.scrollSensitivity) {
dir = -1;
}
break;
}
return dir;
}
getScrollDirectionY(y, { top, bottom }) {
let dir = 0;
switch (this.axis) {
default:
case "y":
if (y >= bottom - this.scrollSensitivity) {
dir = 1;
} else if (y <= top + this.scrollSensitivity) {
dir = -1;
}
break;
}
return dir;
}
hide(element) {

@@ -117,24 +164,6 @@ const display = element.style.display;

getItemViewModel(element) {
return element.au["sortable-item"].viewModel;
return element.au[SORTABLE_ITEM].viewModel;
}
addPlaceholder(toIx, item) {
let placeholder = Object.create(item, { placeholderClass: { value: this.placeholderClass, writable: true }});
if (!placeholder.style) {
placeholder.style = {};
}
placeholder.style.width = this.drag.rect.width;
placeholder.style.height = this.drag.rect.height;
this[PLACEHOLDER] = placeholder;
this.items.splice(toIx, 0, placeholder);
}
removePlaceholder() {
const ix = this.items.indexOf(this[PLACEHOLDER]);
if (ix !== -1) {
this.items.splice(ix, 1);
}
}
movePlaceholder(toIx) {
const fromIx = this.items.indexOf(this[PLACEHOLDER]);
moveSortingItem(toIx) {
const fromIx = this.items.indexOf(this.drag.item);
this.move(fromIx, toIx);

@@ -147,5 +176,5 @@ }

}
tryUpdate(pageX, pageY, offsetX, offsetY) {
const showFn = this.hide(this.drag.element);
this.tryMove(pageX, pageY, offsetX, offsetY);
tryUpdate(x, y, offsetX, offsetY) {
const showFn = this.hide(this.drag.clone);
this.tryMove(x, y, offsetX, offsetY);
showFn();

@@ -182,9 +211,8 @@ }

}
const model = this.getItemViewModel(element);
const vm = this.getItemViewModel(element);
this.lastElementFromPointRect = element.getBoundingClientRect();
if (!this.allowMove({ item: model.item })) {
if (!this.allowMove({ item: vm.item })) {
return;
}
const ix = model.ctx.$index;
this.movePlaceholder(ix);
this.moveSortingItem(vm.ctx.$index);
}

@@ -203,4 +231,4 @@ getPoint(pageX, pageY) {

return {
x: Math.max(this.boundingRect.left, Math.min(this.boundingRect.right, pageX)),
y: Math.max(this.boundingRect.top, Math.min(this.boundingRect.bottom, pageY))
x: pageX,
y: pageY
};

@@ -216,43 +244,96 @@ }

start(e, data, element) {
this.pageX = data.pointers[0].page.x;
this.pageY = data.pointers[0].page.y;
const { scrollLeft, scrollTop } = this.scroll;
this.windowHeight = innerHeight;
this.windowWidth = innerWidth;
this.x = data.pointers[0].client.x;
this.y = data.pointers[0].client.y;
this.sortableRect = this.element.getBoundingClientRect();
this.scrollRect = this.scroll.getBoundingClientRect();
this.scrollWidth = this.scroll.scrollWidth;
this.scrollHeight = this.scroll.scrollHeight;
this.boundingRect = this.boundingRect || { left: this.scrollRect.left + 5, top: this.scrollRect.top + 5, right: this.scrollRect.right - 5, bottom: this.scrollRect.bottom - 5 };
this.drag.start(element, this.pageX, this.pageY, this.scroll.scrollLeft, this.scroll.scrollTop, this.dragZIndex);
this.autoScroll.start(this.axis, this.scrollSpeed, this.scrollSensitivity);
const viewModel = this.getItemViewModel(element);
this.fromIx = viewModel.ctx.$index;
this.boundingRect = {
left: Math.max(0, this.sortableRect.left),
top: Math.max(0, this.sortableRect.top),
bottom: Math.min(this.windowHeight, this.sortableRect.bottom),
right: Math.min(this.windowWidth, this.sortableRect.right)
};
this.sortableContainsScroll = this.element.contains(this.scroll);
if (this.sortableContainsScroll) {
this.scrollMaxPosX = this.scrollWidth - this.scrollRect.width;
this.scrollMaxPosY = this.scrollHeight - this.scrollRect.height;
this.dragMinPosX = this.sortableRect.left;
this.dragMaxPosX = this.sortableRect.left + this.scrollWidth;
this.dragMaxPosY = this.sortableRect.top + this.scrollHeight;
this.dragMinPosY = this.sortableRect.top;
} else {
this.scrollMaxPosX = this.sortableRect.right - this.windowWidth + (this.viewportScroll ? scrollLeft : 0);
this.scrollMaxPosY = this.sortableRect.bottom - this.windowHeight + (this.viewportScroll ? scrollTop : 0);
this.dragMinPosX = this.sortableRect.left + scrollLeft;
this.dragMaxPosX = this.scrollMaxPosX + this.windowWidth;
this.dragMinPosY = this.sortableRect.top + scrollTop;
this.dragMaxPosY = this.scrollMaxPosY + this.windowHeight;
}
this.sortingViewModel = this.getItemViewModel(element);
this.fromIx = this.sortingViewModel.ctx.$index;
this.toIx = -1;
this.addPlaceholder(this.fromIx, viewModel.item);
this.drag.start( element,
this.sortingViewModel.item,
this.x, this.y,
this.viewportScroll,
scrollLeft,
scrollTop,
this.dragZIndex,
this.axis, this.sortingClass,
this.dragMinPosX,
this.dragMaxPosX,
this.dragMinPosY,
this.dragMaxPosY);
this.autoScroll.start(this.scrollSpeed);
this.lastElementFromPointRect = this.drag.rect;
}
update(e, data) {
const p = data.pointers[0].page;
const pageX = (this.pageX = p.x);
const pageY = (this.pageY = p.y);
const scrollLeft = this.scroll.scrollLeft;
const scrollTop = this.scroll.scrollTop;
this.drag.update(pageX, pageY, scrollLeft, scrollTop, this.axis);
const { x, y } = this.getPoint(pageX, pageY);
const p = data.pointers[0].client;
const { scrollLeft, scrollTop } = this.scroll;
this.x = p.x;
this.y = p.y;
this.drag.update(this.x,
this.y,
this.viewportScroll,
scrollLeft,
scrollTop,
this.axis,
this.dragMinPosX,
this.dragMaxPosX,
this.dragMinPosY,
this.dragMaxPosY);
const { x, y } = this.getPoint(p.x, p.y);
const scrollX = this.autoScroll.active ? scrollLeft : 0;
const scrollY = this.autoScroll.active ? scrollTop : 0;
this.tryUpdate(x, y, scrollX, scrollY);
this.autoScroll.update(this.scroll, x, y, this.scrollWidth, this.scrollHeight, this.scrollRect);
const dirX = this.getScrollDirectionX(x, this.boundingRect);
const dirY = this.getScrollDirectionY(y, this.boundingRect);
let frameCntX = this.getScrollFrames(dirX === -1 ? 0 : this.scrollMaxPosX, scrollLeft);
let frameCntY = this.getScrollFrames(dirY === -1 ? 0 : this.scrollMaxPosY, scrollTop);
if ((dirX === 1 && scrollLeft >= this.scrollMaxPosX) ||
(dirX === -1 && scrollLeft === 0)) {
frameCntX = 0;
}
if ((dirY === 1 && scrollTop >= this.scrollMaxPosY) ||
(dirY === -1 && scrollTop === 0)) {
frameCntY = 0;
}
this.autoScroll.update(this.scroll, dirX, dirY, frameCntX, frameCntY);
}
end() {
this.toIx = this.items.indexOf(this[PLACEHOLDER]);
if (this.toIx === -1) {
if (!this.drag.item) {
return; //cancelled
}
this.move(this.toIx < this.fromIx ? this.fromIx + 1 : this.fromIx, this.toIx);
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
if (this.fromIx < this.toIx) {
--this.toIx;
}
this.stop();
if (this.fromIx !== this.toIx) {

@@ -263,9 +344,12 @@ this.moved( { fromIx: this.fromIx, toIx: this.toIx } );

cancel() {
this.move(this.sortingViewModel.ctx.$index, this.fromIx);
this.stop();
}
stop() {
this.drag.end();
this.autoScroll.end();
this.removePlaceholder();
}
}
@customAttribute("sortable-item")
@customAttribute("oa-sortable-item")
export class SortableItem {

@@ -272,0 +356,0 @@

@@ -7,2 +7,4 @@ import "aurelia-polyfills";

};
global.innerWidth = 1068;
global.innerHeight = 768;
global.MockElement = function() {

@@ -9,0 +11,0 @@ this.firstChild = {

import {Container} from "aurelia-dependency-injection";
import {TemplatingEngine} from "aurelia-templating";
import {DOM} from "aurelia-pal";
import {Sortable, SortableItem, PLACEHOLDER} from "../src/sortable";
import {Sortable, SortableItem} from "../src/sortable";
import {Drag} from "../src/drag";

@@ -44,3 +44,3 @@ import {AutoScroll} from "../src/auto-scroll";

it("should set selector", () => {
expect(sortable.selector).to.equal("[sortable-item]");
expect(sortable.selector).to.equal("[oa-sortable-item]");
});

@@ -72,4 +72,4 @@

it("should set placeholderClass", () => {
expect(sortable.placeholderClass).to.equal("placeholder");
it("should set sortingClass", () => {
expect(sortable.sortingClass).to.equal("oa-sorting");
});

@@ -81,6 +81,2 @@

it("should have a bounding rect", () => {
expect(sortable.boundingRect).to.be.a("null");
});
it("should have a moved function", () => {

@@ -225,5 +221,10 @@ expect(sortable.moved).to.be.a("function");

sortable.scroll = { scrollLeft: 0, scrollTop: 0 };
sortable.pageX = 100;
sortable.pageY = 200;
sortable.x = 100;
sortable.y = 200;
sortable.axis = "foo";
sortable.dragMinPosX = 0;
sortable.dragMaxPosX = 100;
sortable.dragMinPosY = 0;
sortable.dragMaxPosY = 200;
sortable.viewportScroll = false;
dragUpdate = sandbox.stub(sortable.drag, "update");

@@ -244,3 +245,3 @@ getPoint = sandbox.stub(sortable, "getPoint").returns({ x: 0, y: 0 });

sortable.onScroll();
expect(dragUpdate).to.have.been.calledWithExactly(100, 200, 0, 0, "foo");
expect(dragUpdate).to.have.been.calledWithExactly(100, 200, false, 0, 0, "foo", 0, 100, 0, 200);
});

@@ -282,3 +283,3 @@

let viewModel = {};
let mockElement = { au: { "sortable-item": { viewModel: viewModel } } };
let mockElement = { au: { "oa-sortable-item": { viewModel: viewModel } } };
expect(sortable.getItemViewModel(mockElement)).to.equal(viewModel);

@@ -289,32 +290,2 @@ });

describe("placeholder", () => {
let splice;
let indexOf;
let move;
beforeEach(() => {
splice = sandbox.stub(sortable.items, "splice");
indexOf = sandbox.stub(sortable.items, "indexOf");
move = sandbox.stub(sortable, "move");
});
it("should add a placeholder", () => {
sortable.addPlaceholder(13, {});
expect(splice).to.have.been.calledWithExactly(13, 0, sortable[PLACEHOLDER]);
});
it("should remove placeholder", () => {
indexOf.returns(5);
sortable.removePlaceholder();
expect(splice).to.have.been.calledWithExactly(5, 1);
});
it("should move placeholder", () => {
indexOf.returns(5);
sortable.movePlaceholder(8);
expect(move).to.have.been.calledWithExactly(5, 8);
});
});
describe("`move`", () => {

@@ -348,3 +319,3 @@ let splice;

it("should hide drag element", () => {
sortable.drag.element = mockElement;
sortable.drag.clone = mockElement;
sortable.tryUpdate();

@@ -355,3 +326,3 @@ expect(hide).to.have.been.calledWithExactly(mockElement);

it("should show the drag element", () => {
sortable.drag.element = mockElement;
sortable.drag.clone = mockElement;
sortable.tryUpdate();

@@ -375,3 +346,2 @@ expect(showFn).to.have.callCount(1);

let getItemViewModel;
let movePlaceholder;
let allowMove;

@@ -391,3 +361,2 @@

getItemViewModel = sandbox.stub(sortable, "getItemViewModel");
movePlaceholder = sandbox.stub(sortable, "movePlaceholder");
});

@@ -406,3 +375,2 @@

expect(getItemViewModel).to.have.callCount(0);
expect(movePlaceholder).to.have.callCount(0);
});

@@ -425,3 +393,2 @@

expect(getItemViewModel).to.have.callCount(0);
expect(movePlaceholder).to.have.callCount(0);
});

@@ -446,19 +413,2 @@

it("should call `movePlaceholder` if `allowMove` is truthy", () => {
elementFromPoint.returns(mockElementFromPoint);
closest.returns(mockElementFromPoint);
getItemViewModel.returns({ item: {}, ctx: { $index: 13 } });
sortable.tryMove(100, 200);
expect(movePlaceholder).to.have.been.calledWithExactly(13);
});
it("should not call `movePlaceholder` if `allowMove` is falsy", () => {
allowMove.returns(false);
elementFromPoint.returns(mockElementFromPoint);
closest.returns(mockElementFromPoint);
getItemViewModel.returns({ item: {}, ctx: { $index: 13 } });
sortable.tryMove(100, 200);
expect(movePlaceholder).to.have.callCount(0);
});
});

@@ -498,31 +448,2 @@

describe("`boundingRect`", () => {
it("should return min x", () => {
let { x } = sortable.getPoint(1);
expect(x).to.equal(boundingRect.left);
});
it("should return max x", () => {
let { x } = sortable.getPoint(200);
expect(x).to.equal(boundingRect.right);
});
it("should return min y", () => {
let { y } = sortable.getPoint( -1, 1);
expect(y).to.equal(boundingRect.top);
});
it("should return max y", () => {
let { y } = sortable.getPoint( -1, 200);
expect(y).to.equal(boundingRect.bottom);
});
it("should return valid x, y", () => {
let { x, y } = sortable.getPoint(50, 75);
expect(x).to.equal(50);
expect(y).to.equal(75);
});
});
});

@@ -568,6 +489,7 @@

describe("`start`", () => {
let pageX;
let pageY;
let x;
let y;
//let element;
let scroll;
let boundingRect;
//let boundingRect;
let placeholder;

@@ -577,3 +499,2 @@ let scrollSpeed;

let getItemViewModel;
let addPlaceholder;
let item = {};

@@ -585,6 +506,7 @@ let ctx = {};

beforeEach(() => {
pageX = 10;
pageY = 20;
boundingRect = { left: 10, top: 20, right: 30, bottom: 40 };
scroll = { scrollLeft: 0, scrollTop: 0, getBoundingClientRect: sandbox.stub().returns({}) };
x = 10;
y = 20;
//boundingRect = { left: 10, top: 20, right: 30, bottom: 40 };
element = { getBoundingClientRect: sandbox.stub().returns({}), contains: sandbox.stub().returns(false) };
scroll = { scrollLeft: 0, scrollTop: 0, getBoundingClientRect: sandbox.stub().returns({}), contains: sandbox.stub().returns(false) };
placeholder = {};

@@ -594,2 +516,6 @@ scrollSpeed = 99;

sortable = Object.create(sortable, {
"element": {
value: element,
writable: true
},
"scroll": {

@@ -599,6 +525,2 @@ value: scroll,

},
"boundingRect": {
value: boundingRect,
writable: true
},
"axis": {

@@ -629,13 +551,12 @@ value: "foo",

autoScrollStart = sandbox.stub(sortable.autoScroll, "start");
addPlaceholder = sandbox.stub(sortable, "addPlaceholder");
});
it("should set `pageX`", () => {
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
expect(sortable.pageX).to.equal(pageX);
it("should set `x`", () => {
sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
expect(sortable.x).to.equal(x);
});
it("should set `pageY`", () => {
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
expect(sortable.pageY).to.equal(pageY);
it("should set `y`", () => {
sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
expect(sortable.y).to.equal(y);
});

@@ -645,3 +566,3 @@

scroll.getBoundingClientRect.returns( { left: 5, top: 6, bottom: 7, right: 8, width: 9, height: 10 });
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
expect(sortable.scrollRect).to.deep.equal({ left: 5, top: 6, bottom: 7, right: 8, width: 9, height: 10 });

@@ -652,28 +573,28 @@ });

it("should set `boundingRect`", () => {
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
expect(sortable.boundingRect).to.equal(boundingRect);
});
// it("should set `boundingRect`", () => {
// sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
// expect(sortable.boundingRect).to.equal(boundingRect);
// });
it("should set default `boundingRect`", () => {
sortable.boundingRect = null;
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
expect(sortable.boundingRect).to.deep.equal({
left: sortable.scrollRect.left + 5,
top: sortable.scrollRect.top + 5,
right: sortable.scrollRect.right - 5,
bottom: sortable.scrollRect.bottom - 5
});
});
// it("should set default `boundingRect`", () => {
// sortable.boundingRect = null;
// sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
// expect(sortable.boundingRect).to.deep.equal({
// left: sortable.scrollRect.left + 5,
// top: sortable.scrollRect.top + 5,
// right: sortable.scrollRect.right - 5,
// bottom: sortable.scrollRect.bottom - 5
// });
// });
});
it("should call `drag.start`", () => {
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, element);
expect(dragStart).to.have.been.calledWithExactly(element, 10, 20, scroll.scrollLeft, scroll.scrollTop, -1);
it.skip("should call `drag.start`", () => {
sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, element);
expect(dragStart).to.have.been.calledWithExactly(element, 10, 20, false, false, scroll.scrollLeft, scroll.scrollTop, -1, "foo", sinon.match.object);
});
it("should call `autoScroll.start`", () => {
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
expect(autoScrollStart).to.have.been.calledWithExactly("foo", scrollSpeed, scrollSensitivity);
sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
expect(autoScrollStart).to.have.been.calledWithExactly(scrollSpeed);
});

@@ -683,3 +604,3 @@

getItemViewModel.returns( { ctx: { $index: 13 } });
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
expect(sortable.fromIx).to.equal(13);

@@ -689,20 +610,16 @@ });

it("should set `toIx`", () => {
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
sortable.start({}, { pointers: [{ client: { x: x, y: y }}] }, {});
expect(sortable.toIx).to.equal(-1);
});
it("should call `addPlaceholder`", () => {
getItemViewModel.returns( { ctx: { $index: 13 }, item: { foo: {} }});
sortable.start({}, { pointers: [{ page: { x: pageX, y: pageY }}] }, {});
expect(addPlaceholder).to.have.been.calledWithExactly(13, { foo: {} });
});
});
describe("`update`", () => {
let pageX;
let pageY;
let x;
let y;
let scroll;
let scrollRect;
let axis;
let boundingRect;
let dragBoundingRect;
let dragUpdate;

@@ -714,9 +631,11 @@ let getPoint;

beforeEach(() => {
pageX = 10;
pageY = 20;
x = 10;
y = 20;
scroll = { scrollLeft: 0, scrollTop: 0 };
scrollRect = {};
axis = "foo";
boundingRect = { left: 0, top: 100, bottom: 150, right: 75 };
dragBoundingRect = { left: 0, top: 100, bottom: 200, right: 300 };
dragUpdate = sandbox.stub(sortable.drag, "update");
getPoint = sandbox.stub(sortable, "getPoint").returns( { x: pageX, y: pageY });
getPoint = sandbox.stub(sortable, "getPoint").returns( { x: x, y: y });
tryUpdate = sandbox.stub(sortable, "tryUpdate");

@@ -736,2 +655,10 @@ autoScrollUpdate = sandbox.stub(sortable.autoScroll, "update");

writable: true
},
"boundingRect": {
value: boundingRect,
writable: true
},
"dragBoundingRect": {
value: dragBoundingRect,
writable: true
}

@@ -741,38 +668,38 @@ });

it("should set `pageX`", () => {
sortable.update({}, { pointers: [{ page: { x: pageX, y: pageY }}] });
expect(sortable.pageX).to.equal(10);
it("should set `x`", () => {
sortable.update({}, { pointers: [{ client: { x: x, y: y }}] });
expect(sortable.x).to.equal(10);
});
it("should set `pageY`", () => {
sortable.update({}, { pointers: [{ page: { x: pageX, y: pageY }}] });
expect(sortable.pageY).to.equal(20);
it("should set `y`", () => {
sortable.update({}, { pointers: [{ client: { x: x, y: y }}] });
expect(sortable.y).to.equal(20);
});
it("should call `drag.update`", () => {
sortable.update({}, { pointers: [{ page: { x: pageX, y: pageY }}] });
expect(dragUpdate).to.have.been.calledWithExactly(pageX, pageY, scroll.scrollLeft, scroll.scrollTop, axis);
it.skip("should call `drag.update`", () => {
sortable.update({}, { pointers: [{ client: { x: x, y: y }}] });
expect(dragUpdate).to.have.been.calledWithExactly(x, y, scroll.scrollLeft, scroll.scrollTop, axis, sinon.match.object);
});
it("should call `getPoint`", () => {
sortable.update({}, { pointers: [{ page: { x: pageX, y: pageY }}] });
expect(getPoint).to.have.been.calledWithExactly(pageX, pageY);
sortable.update({}, { pointers: [{ client: { x: x, y: y }}] });
expect(getPoint).to.have.been.calledWithExactly(x, y);
});
it("should call `tryUpdate`", () => {
pageX = 3;
pageY = 6;
getPoint.returns( { x: pageX, y: pageY });
sortable.update({}, { pointers: [{ page: { x: pageX, y: pageY }}] });
expect(tryUpdate).to.have.been.calledWithExactly(pageX, pageY, scroll.scrollLeft, scroll.scrollTop);
x = 3;
y = 6;
getPoint.returns( { x: x, y: y });
sortable.update({}, { pointers: [{ client: { x: x, y: y }}] });
expect(tryUpdate).to.have.been.calledWithExactly(x, y, scroll.scrollLeft, scroll.scrollTop);
});
it("should call `autoScroll.update`", () => {
pageX = 12;
pageY = 24;
it.skip("should call `autoScroll.update`", () => {
x = 12;
y = 24;
sortable.scrollWidth = 0;
sortable.scrollHeight = 0;
getPoint.returns( { x: pageX, y: pageY });
sortable.update({}, { pointers: [{ page: { x: pageX, y: pageY }}] });
expect(autoScrollUpdate).to.have.been.calledWithExactly(scroll, pageX, pageY, 0, 0, scrollRect);
getPoint.returns( { x: x, y: y });
sortable.update({}, { pointers: [{ client: { x: x, y: y }}] });
expect(autoScrollUpdate).to.have.been.calledWithExactly(scroll, x, y, 0, 0, scrollRect);
});

@@ -787,3 +714,2 @@

let autoScrollEnd;
let removePlaceholder;
let moved;

@@ -798,3 +724,2 @@ let fromIx;

autoScrollEnd = sandbox.stub(sortable.autoScroll, "end");
removePlaceholder = sandbox.stub(sortable, "removePlaceholder");
moved = sandbox.stub();

@@ -815,7 +740,6 @@ sortable = Object.create(sortable, {

expect(autoScrollEnd).to.have.callCount(0);
expect(removePlaceholder).to.have.callCount(0);
expect(moved).to.have.callCount(0);
});
describe("`toIx`", () => {
describe.skip("`toIx`", () => {

@@ -842,3 +766,3 @@ it("should set `toIx` to indexOf `placeholder` if `fromIx` is greater than `toIx`", () => {

describe("`move`", () => {
describe.skip("`move`", () => {

@@ -865,3 +789,3 @@ it("should call `move` with `fromIx` + 1 if `toIx` less than `fromIx`", () => {

it("should call `drag.end`", () => {
it.skip("should call `drag.end`", () => {
sortable.end();

@@ -871,3 +795,3 @@ expect(dragEnd).to.have.been.calledWithExactly();

it("should call `autoScroll.end`", () => {
it.skip("should call `autoScroll.end`", () => {
sortable.end();

@@ -877,8 +801,3 @@ expect(autoScrollEnd).to.have.been.calledWithExactly();

it("should call `removePlaceholder`", () => {
sortable.end();
expect(removePlaceholder).to.have.been.calledWithExactly();
});
it("should call `moved`", () => {
it.skip("should call `moved`", () => {
fromIx = 2;

@@ -900,3 +819,2 @@ sortable.fromIx = fromIx;

let autoScrollEnd;
let removePlaceholder;

@@ -906,6 +824,5 @@ beforeEach(() => {

autoScrollEnd = sandbox.stub(sortable.autoScroll, "end");
removePlaceholder = sandbox.stub(sortable, "removePlaceholder");
});
it("should call `drag.end`", () => {
it.skip("should call `drag.end`", () => {
sortable.cancel();

@@ -915,3 +832,3 @@ expect(dragEnd).to.have.been.calledWithExactly();

it("should call `autoScroll.end`", () => {
it.skip("should call `autoScroll.end`", () => {
sortable.cancel();

@@ -921,7 +838,2 @@ expect(autoScrollEnd).to.have.been.calledWithExactly();

it("should call `removePlaceholder`", () => {
sortable.cancel();
expect(removePlaceholder).to.have.been.calledWithExactly();
});
});

@@ -928,0 +840,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc