From cc4ea6f4a7c4315b625737b283ef539d831a0a70 Mon Sep 17 00:00:00 2001 From: michaelmalonenz Date: Sun, 27 Mar 2016 13:04:48 +1300 Subject: [PATCH] Prepare Release --- dist/amd/dragula-and-drop.js | 8 ++++---- dist/amd/index.js | 6 ++++-- dist/amd/move-before.js | 20 ++++++++++++++++++++ dist/aurelia-dragula.js | 27 +++++++++++++++++++++------ dist/commonjs/dragula-and-drop.js | 8 ++++---- dist/commonjs/index.js | 6 +++++- dist/commonjs/move-before.js | 18 ++++++++++++++++++ dist/es2015/dragula-and-drop.js | 8 ++++---- dist/es2015/index.js | 7 ++++--- dist/es2015/move-before.js | 12 ++++++++++++ dist/system/dragula-and-drop.js | 8 ++++---- dist/system/index.js | 11 +++++++++-- dist/system/move-before.js | 22 ++++++++++++++++++++++ dist/temp/aurelia-dragula.js | 21 +++++++++++++++++---- package.json | 2 +- 15 files changed, 149 insertions(+), 35 deletions(-) create mode 100644 dist/amd/move-before.js create mode 100644 dist/commonjs/move-before.js create mode 100644 dist/es2015/move-before.js create mode 100644 dist/system/move-before.js diff --git a/dist/amd/dragula-and-drop.js b/dist/amd/dragula-and-drop.js index 73d6a28..8632e72 100644 --- a/dist/amd/dragula-and-drop.js +++ b/dist/amd/dragula-and-drop.js @@ -14,7 +14,7 @@ define(['exports', 'aurelia-templating', 'aurelia-binding', 'aurelia-dependency- var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11, _dec12, _dec13, _dec14, _dec15, _dec16, _dec17, _dec18, _dec19, _dec20, _class; - var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bindable)({ name: 'moves', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec2 = (0, _aureliaTemplating.bindable)({ name: 'accepts', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec3 = (0, _aureliaTemplating.bindable)({ name: 'invalid', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec4 = (0, _aureliaTemplating.bindable)({ name: 'containers', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec5 = (0, _aureliaTemplating.bindable)({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec6 = (0, _aureliaTemplating.bindable)({ name: 'copy', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec7 = (0, _aureliaTemplating.bindable)({ name: 'copySortSource', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec8 = (0, _aureliaTemplating.bindable)({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: true }), _dec9 = (0, _aureliaTemplating.bindable)({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec10 = (0, _aureliaTemplating.bindable)({ name: 'direction', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec11 = (0, _aureliaTemplating.bindable)({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec12 = (0, _aureliaTemplating.bindable)({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec13 = (0, _aureliaTemplating.bindable)({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = (0, _aureliaTemplating.bindable)({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = (0, _aureliaTemplating.bindable)({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item, source) {} }), _dec16 = (0, _aureliaTemplating.bindable)({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item, target, source, sibling) {} }), _dec17 = (0, _aureliaTemplating.bindable)({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item) {} }), _dec18 = (0, _aureliaTemplating.customElement)('dragula-and-drop'), _dec19 = (0, _aureliaTemplating.noView)(), _dec20 = (0, _aureliaDependencyInjection.inject)(_options.GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { + var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bindable)({ name: 'moves', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec2 = (0, _aureliaTemplating.bindable)({ name: 'accepts', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec3 = (0, _aureliaTemplating.bindable)({ name: 'invalid', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec4 = (0, _aureliaTemplating.bindable)({ name: 'containers', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec5 = (0, _aureliaTemplating.bindable)({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec6 = (0, _aureliaTemplating.bindable)({ name: 'copy', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec7 = (0, _aureliaTemplating.bindable)({ name: 'copySortSource', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec8 = (0, _aureliaTemplating.bindable)({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: true }), _dec9 = (0, _aureliaTemplating.bindable)({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec10 = (0, _aureliaTemplating.bindable)({ name: 'direction', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec11 = (0, _aureliaTemplating.bindable)({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec12 = (0, _aureliaTemplating.bindable)({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec13 = (0, _aureliaTemplating.bindable)({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = (0, _aureliaTemplating.bindable)({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = (0, _aureliaTemplating.bindable)({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec16 = (0, _aureliaTemplating.bindable)({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec17 = (0, _aureliaTemplating.bindable)({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec18 = (0, _aureliaTemplating.customElement)('dragula-and-drop'), _dec19 = (0, _aureliaTemplating.noView)(), _dec20 = (0, _aureliaDependencyInjection.inject)(_options.GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { function DragulaAndDrop(globalOptions) { _classCallCheck(this, DragulaAndDrop); @@ -39,15 +39,15 @@ define(['exports', 'aurelia-templating', 'aurelia-binding', 'aurelia-dependency- this.dragula.on('drop', function (item, target, source, sibling) { _this.dragula.cancel(); - _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); + if (typeof _this.dropFn === 'function') _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); }); this.dragula.on('drag', function (item, source) { - _this.dragFn({ item: item, source: source }); + if (typeof _this.dragFn === 'function') _this.dragFn({ item: item, source: source }); }); this.dragula.on('dragend', function (item) { - _this.dragEndFn({ item: item }); + if (typeof _this.dragEndFn === 'function') _this.dragEndFn({ item: item }); }); }; diff --git a/dist/amd/index.js b/dist/amd/index.js index 2309134..caeb146 100644 --- a/dist/amd/index.js +++ b/dist/amd/index.js @@ -1,13 +1,15 @@ -define(['exports', './options', './dragula'], function (exports, _options, _dragula) { +define(['exports', './options', './dragula', './move-before'], function (exports, _options, _dragula, _moveBefore) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); - exports.Options = exports.Dragula = undefined; + exports.moveBefore = exports.DIRECTION = exports.Options = exports.Dragula = undefined; exports.configure = configure; exports.Dragula = _dragula.Dragula; exports.Options = _options.Options; + exports.DIRECTION = _options.DIRECTION; + exports.moveBefore = _moveBefore.moveBefore; function configure(config, callback) { var defaults = new _options.Options(); config.container.registerInstance(_options.GLOBAL_OPTIONS, defaults); diff --git a/dist/amd/move-before.js b/dist/amd/move-before.js new file mode 100644 index 0000000..90ec3b4 --- /dev/null +++ b/dist/amd/move-before.js @@ -0,0 +1,20 @@ +define(["exports"], function (exports) { + "use strict"; + + Object.defineProperty(exports, "__esModule", { + value: true + }); + exports.moveBefore = moveBefore; + function moveBefore(array, itemMatcherFn, siblingMatcherFn) { + var removedItem = remove(array, itemMatcherFn); + var nextIndex = array.findIndex(siblingMatcherFn); + array.splice(nextIndex >= 0 ? nextIndex : array.length, 0, removedItem); + } + + function remove(array, matcherFn) { + var index = array.findIndex(matcherFn); + if (index >= 0) { + return array.splice(index, 1)[0]; + } + } +}); \ No newline at end of file diff --git a/dist/aurelia-dragula.js b/dist/aurelia-dragula.js index 70f5c80..5c316aa 100644 --- a/dist/aurelia-dragula.js +++ b/dist/aurelia-dragula.js @@ -53,9 +53,9 @@ export function rm(el, className) { @bindable({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: bindingMode.oneTime }) @bindable({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drop-target' }) @bindable({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drag-source' }) -@bindable({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: (item, source) => {}}) -@bindable({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: (item, target, source, sibling) => {}}) -@bindable({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: (item) => {}}) +@bindable({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: bindingMode.oneTime }) +@bindable({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: bindingMode.oneTime }) +@bindable({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: bindingMode.oneTime }) @customElement('dragula-and-drop') @noView() @inject(GLOBAL_OPTIONS) @@ -81,15 +81,18 @@ export class DragulaAndDrop { this.dragula.on('drop', (item, target, source, sibling) => { this.dragula.cancel(); - this.dropFn({ item: item, target: target, source: source, sibling: sibling }); + if (typeof this.dropFn === 'function') + this.dropFn({ item: item, target: target, source: source, sibling: sibling }); }); this.dragula.on('drag', (item, source) => { - this.dragFn({ item: item, source: source}); + if (typeof this.dragFn === 'function') + this.dragFn({ item: item, source: source}); }); this.dragula.on('dragend', (item) => { - this.dragEndFn({ item: item }); + if (typeof this.dragEndFn === 'function') + this.dragEndFn({ item: item }); }) } @@ -699,6 +702,18 @@ export class Emitter { } } +export function moveBefore(array, itemMatcherFn, siblingMatcherFn) { + let removedItem = remove(array, itemMatcherFn); + let nextIndex = array.findIndex(siblingMatcherFn); + array.splice(nextIndex >= 0 ? nextIndex : array.length, 0, removedItem); +} + +function remove(array, matcherFn) { + let index = array.findIndex(matcherFn); + if (index >= 0) { + return array.splice(index, 1)[0]; + } +} export const GLOBAL_OPTIONS = 'GlobalOptions'; export const DIRECTION = { diff --git a/dist/commonjs/dragula-and-drop.js b/dist/commonjs/dragula-and-drop.js index 18665c0..720ede4 100644 --- a/dist/commonjs/dragula-and-drop.js +++ b/dist/commonjs/dragula-and-drop.js @@ -19,7 +19,7 @@ var _dragula = require('./dragula'); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } -var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bindable)({ name: 'moves', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec2 = (0, _aureliaTemplating.bindable)({ name: 'accepts', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec3 = (0, _aureliaTemplating.bindable)({ name: 'invalid', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec4 = (0, _aureliaTemplating.bindable)({ name: 'containers', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec5 = (0, _aureliaTemplating.bindable)({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec6 = (0, _aureliaTemplating.bindable)({ name: 'copy', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec7 = (0, _aureliaTemplating.bindable)({ name: 'copySortSource', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec8 = (0, _aureliaTemplating.bindable)({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: true }), _dec9 = (0, _aureliaTemplating.bindable)({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec10 = (0, _aureliaTemplating.bindable)({ name: 'direction', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec11 = (0, _aureliaTemplating.bindable)({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec12 = (0, _aureliaTemplating.bindable)({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec13 = (0, _aureliaTemplating.bindable)({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = (0, _aureliaTemplating.bindable)({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = (0, _aureliaTemplating.bindable)({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item, source) {} }), _dec16 = (0, _aureliaTemplating.bindable)({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item, target, source, sibling) {} }), _dec17 = (0, _aureliaTemplating.bindable)({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item) {} }), _dec18 = (0, _aureliaTemplating.customElement)('dragula-and-drop'), _dec19 = (0, _aureliaTemplating.noView)(), _dec20 = (0, _aureliaDependencyInjection.inject)(_options.GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { +var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bindable)({ name: 'moves', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec2 = (0, _aureliaTemplating.bindable)({ name: 'accepts', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec3 = (0, _aureliaTemplating.bindable)({ name: 'invalid', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec4 = (0, _aureliaTemplating.bindable)({ name: 'containers', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec5 = (0, _aureliaTemplating.bindable)({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec6 = (0, _aureliaTemplating.bindable)({ name: 'copy', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec7 = (0, _aureliaTemplating.bindable)({ name: 'copySortSource', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec8 = (0, _aureliaTemplating.bindable)({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: true }), _dec9 = (0, _aureliaTemplating.bindable)({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec10 = (0, _aureliaTemplating.bindable)({ name: 'direction', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec11 = (0, _aureliaTemplating.bindable)({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec12 = (0, _aureliaTemplating.bindable)({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec13 = (0, _aureliaTemplating.bindable)({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = (0, _aureliaTemplating.bindable)({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = (0, _aureliaTemplating.bindable)({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec16 = (0, _aureliaTemplating.bindable)({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec17 = (0, _aureliaTemplating.bindable)({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec18 = (0, _aureliaTemplating.customElement)('dragula-and-drop'), _dec19 = (0, _aureliaTemplating.noView)(), _dec20 = (0, _aureliaDependencyInjection.inject)(_options.GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { function DragulaAndDrop(globalOptions) { _classCallCheck(this, DragulaAndDrop); @@ -44,15 +44,15 @@ var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bin this.dragula.on('drop', function (item, target, source, sibling) { _this.dragula.cancel(); - _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); + if (typeof _this.dropFn === 'function') _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); }); this.dragula.on('drag', function (item, source) { - _this.dragFn({ item: item, source: source }); + if (typeof _this.dragFn === 'function') _this.dragFn({ item: item, source: source }); }); this.dragula.on('dragend', function (item) { - _this.dragEndFn({ item: item }); + if (typeof _this.dragEndFn === 'function') _this.dragEndFn({ item: item }); }); }; diff --git a/dist/commonjs/index.js b/dist/commonjs/index.js index 9d93795..ed208fb 100644 --- a/dist/commonjs/index.js +++ b/dist/commonjs/index.js @@ -3,15 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true }); -exports.Options = exports.Dragula = undefined; +exports.moveBefore = exports.DIRECTION = exports.Options = exports.Dragula = undefined; exports.configure = configure; var _options = require('./options'); var _dragula = require('./dragula'); +var _moveBefore = require('./move-before'); + exports.Dragula = _dragula.Dragula; exports.Options = _options.Options; +exports.DIRECTION = _options.DIRECTION; +exports.moveBefore = _moveBefore.moveBefore; function configure(config, callback) { var defaults = new _options.Options(); config.container.registerInstance(_options.GLOBAL_OPTIONS, defaults); diff --git a/dist/commonjs/move-before.js b/dist/commonjs/move-before.js new file mode 100644 index 0000000..aef98ac --- /dev/null +++ b/dist/commonjs/move-before.js @@ -0,0 +1,18 @@ +"use strict"; + +Object.defineProperty(exports, "__esModule", { + value: true +}); +exports.moveBefore = moveBefore; +function moveBefore(array, itemMatcherFn, siblingMatcherFn) { + var removedItem = remove(array, itemMatcherFn); + var nextIndex = array.findIndex(siblingMatcherFn); + array.splice(nextIndex >= 0 ? nextIndex : array.length, 0, removedItem); +} + +function remove(array, matcherFn) { + var index = array.findIndex(matcherFn); + if (index >= 0) { + return array.splice(index, 1)[0]; + } +} \ No newline at end of file diff --git a/dist/es2015/dragula-and-drop.js b/dist/es2015/dragula-and-drop.js index 5733ab7..d7daffc 100644 --- a/dist/es2015/dragula-and-drop.js +++ b/dist/es2015/dragula-and-drop.js @@ -7,7 +7,7 @@ import { inject } from 'aurelia-dependency-injection'; import { Options, GLOBAL_OPTIONS } from './options'; import { Dragula } from './dragula'; -export let DragulaAndDrop = (_dec = bindable({ name: 'moves', defaultBindingMode: bindingMode.oneTime }), _dec2 = bindable({ name: 'accepts', defaultBindingMode: bindingMode.oneTime }), _dec3 = bindable({ name: 'invalid', defaultBindingMode: bindingMode.oneTime }), _dec4 = bindable({ name: 'containers', defaultBindingMode: bindingMode.oneTime }), _dec5 = bindable({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: bindingMode.oneTime }), _dec6 = bindable({ name: 'copy', defaultBindingMode: bindingMode.oneTime }), _dec7 = bindable({ name: 'copySortSource', defaultBindingMode: bindingMode.oneTime }), _dec8 = bindable({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: bindingMode.oneTime, defaultValue: true }), _dec9 = bindable({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: bindingMode.oneTime }), _dec10 = bindable({ name: 'direction', defaultBindingMode: bindingMode.oneTime }), _dec11 = bindable({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: bindingMode.oneTime }), _dec12 = bindable({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: bindingMode.oneTime }), _dec13 = bindable({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = bindable({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = bindable({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: (item, source) => {} }), _dec16 = bindable({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: (item, target, source, sibling) => {} }), _dec17 = bindable({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: item => {} }), _dec18 = customElement('dragula-and-drop'), _dec19 = noView(), _dec20 = inject(GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = class DragulaAndDrop { +export let DragulaAndDrop = (_dec = bindable({ name: 'moves', defaultBindingMode: bindingMode.oneTime }), _dec2 = bindable({ name: 'accepts', defaultBindingMode: bindingMode.oneTime }), _dec3 = bindable({ name: 'invalid', defaultBindingMode: bindingMode.oneTime }), _dec4 = bindable({ name: 'containers', defaultBindingMode: bindingMode.oneTime }), _dec5 = bindable({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: bindingMode.oneTime }), _dec6 = bindable({ name: 'copy', defaultBindingMode: bindingMode.oneTime }), _dec7 = bindable({ name: 'copySortSource', defaultBindingMode: bindingMode.oneTime }), _dec8 = bindable({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: bindingMode.oneTime, defaultValue: true }), _dec9 = bindable({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: bindingMode.oneTime }), _dec10 = bindable({ name: 'direction', defaultBindingMode: bindingMode.oneTime }), _dec11 = bindable({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: bindingMode.oneTime }), _dec12 = bindable({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: bindingMode.oneTime }), _dec13 = bindable({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = bindable({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = bindable({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: bindingMode.oneTime }), _dec16 = bindable({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: bindingMode.oneTime }), _dec17 = bindable({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: bindingMode.oneTime }), _dec18 = customElement('dragula-and-drop'), _dec19 = noView(), _dec20 = inject(GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = class DragulaAndDrop { constructor(globalOptions) { this.dragula = {}; @@ -29,15 +29,15 @@ export let DragulaAndDrop = (_dec = bindable({ name: 'moves', defaultBindingMode this.dragula.on('drop', (item, target, source, sibling) => { this.dragula.cancel(); - this.dropFn({ item: item, target: target, source: source, sibling: sibling }); + if (typeof this.dropFn === 'function') this.dropFn({ item: item, target: target, source: source, sibling: sibling }); }); this.dragula.on('drag', (item, source) => { - this.dragFn({ item: item, source: source }); + if (typeof this.dragFn === 'function') this.dragFn({ item: item, source: source }); }); this.dragula.on('dragend', item => { - this.dragEndFn({ item: item }); + if (typeof this.dragEndFn === 'function') this.dragEndFn({ item: item }); }); } diff --git a/dist/es2015/index.js b/dist/es2015/index.js index e31895e..8a3d408 100644 --- a/dist/es2015/index.js +++ b/dist/es2015/index.js @@ -1,7 +1,8 @@ -import { Options, GLOBAL_OPTIONS } from './options'; - +import { Options, GLOBAL_OPTIONS, DIRECTION } from './options'; import { Dragula } from './dragula'; -export { Dragula, Options }; +import { moveBefore } from './move-before'; + +export { Dragula, Options, DIRECTION, moveBefore }; export function configure(config, callback) { let defaults = new Options(); diff --git a/dist/es2015/move-before.js b/dist/es2015/move-before.js new file mode 100644 index 0000000..35e4872 --- /dev/null +++ b/dist/es2015/move-before.js @@ -0,0 +1,12 @@ +export function moveBefore(array, itemMatcherFn, siblingMatcherFn) { + let removedItem = remove(array, itemMatcherFn); + let nextIndex = array.findIndex(siblingMatcherFn); + array.splice(nextIndex >= 0 ? nextIndex : array.length, 0, removedItem); +} + +function remove(array, matcherFn) { + let index = array.findIndex(matcherFn); + if (index >= 0) { + return array.splice(index, 1)[0]; + } +} \ No newline at end of file diff --git a/dist/system/dragula-and-drop.js b/dist/system/dragula-and-drop.js index 4986514..775a255 100644 --- a/dist/system/dragula-and-drop.js +++ b/dist/system/dragula-and-drop.js @@ -25,7 +25,7 @@ System.register(['aurelia-templating', 'aurelia-binding', 'aurelia-dependency-in Dragula = _dragula.Dragula; }], execute: function () { - _export('DragulaAndDrop', DragulaAndDrop = (_dec = bindable({ name: 'moves', defaultBindingMode: bindingMode.oneTime }), _dec2 = bindable({ name: 'accepts', defaultBindingMode: bindingMode.oneTime }), _dec3 = bindable({ name: 'invalid', defaultBindingMode: bindingMode.oneTime }), _dec4 = bindable({ name: 'containers', defaultBindingMode: bindingMode.oneTime }), _dec5 = bindable({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: bindingMode.oneTime }), _dec6 = bindable({ name: 'copy', defaultBindingMode: bindingMode.oneTime }), _dec7 = bindable({ name: 'copySortSource', defaultBindingMode: bindingMode.oneTime }), _dec8 = bindable({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: bindingMode.oneTime, defaultValue: true }), _dec9 = bindable({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: bindingMode.oneTime }), _dec10 = bindable({ name: 'direction', defaultBindingMode: bindingMode.oneTime }), _dec11 = bindable({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: bindingMode.oneTime }), _dec12 = bindable({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: bindingMode.oneTime }), _dec13 = bindable({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = bindable({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = bindable({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: function defaultValue(item, source) {} }), _dec16 = bindable({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: function defaultValue(item, target, source, sibling) {} }), _dec17 = bindable({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: bindingMode.oneTime, defaultValue: function defaultValue(item) {} }), _dec18 = customElement('dragula-and-drop'), _dec19 = noView(), _dec20 = inject(GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { + _export('DragulaAndDrop', DragulaAndDrop = (_dec = bindable({ name: 'moves', defaultBindingMode: bindingMode.oneTime }), _dec2 = bindable({ name: 'accepts', defaultBindingMode: bindingMode.oneTime }), _dec3 = bindable({ name: 'invalid', defaultBindingMode: bindingMode.oneTime }), _dec4 = bindable({ name: 'containers', defaultBindingMode: bindingMode.oneTime }), _dec5 = bindable({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: bindingMode.oneTime }), _dec6 = bindable({ name: 'copy', defaultBindingMode: bindingMode.oneTime }), _dec7 = bindable({ name: 'copySortSource', defaultBindingMode: bindingMode.oneTime }), _dec8 = bindable({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: bindingMode.oneTime, defaultValue: true }), _dec9 = bindable({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: bindingMode.oneTime }), _dec10 = bindable({ name: 'direction', defaultBindingMode: bindingMode.oneTime }), _dec11 = bindable({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: bindingMode.oneTime }), _dec12 = bindable({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: bindingMode.oneTime }), _dec13 = bindable({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = bindable({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = bindable({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: bindingMode.oneTime }), _dec16 = bindable({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: bindingMode.oneTime }), _dec17 = bindable({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: bindingMode.oneTime }), _dec18 = customElement('dragula-and-drop'), _dec19 = noView(), _dec20 = inject(GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { function DragulaAndDrop(globalOptions) { _classCallCheck(this, DragulaAndDrop); @@ -50,15 +50,15 @@ System.register(['aurelia-templating', 'aurelia-binding', 'aurelia-dependency-in this.dragula.on('drop', function (item, target, source, sibling) { _this.dragula.cancel(); - _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); + if (typeof _this.dropFn === 'function') _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); }); this.dragula.on('drag', function (item, source) { - _this.dragFn({ item: item, source: source }); + if (typeof _this.dragFn === 'function') _this.dragFn({ item: item, source: source }); }); this.dragula.on('dragend', function (item) { - _this.dragEndFn({ item: item }); + if (typeof _this.dragEndFn === 'function') _this.dragEndFn({ item: item }); }); }; diff --git a/dist/system/index.js b/dist/system/index.js index 7f54b29..dff9570 100644 --- a/dist/system/index.js +++ b/dist/system/index.js @@ -1,19 +1,26 @@ 'use strict'; -System.register(['./options', './dragula'], function (_export, _context) { - var Options, GLOBAL_OPTIONS, Dragula; +System.register(['./options', './dragula', './move-before'], function (_export, _context) { + var Options, GLOBAL_OPTIONS, DIRECTION, Dragula, moveBefore; return { setters: [function (_options) { Options = _options.Options; GLOBAL_OPTIONS = _options.GLOBAL_OPTIONS; + DIRECTION = _options.DIRECTION; }, function (_dragula) { Dragula = _dragula.Dragula; + }, function (_moveBefore) { + moveBefore = _moveBefore.moveBefore; }], execute: function () { _export('Dragula', Dragula); _export('Options', Options); + _export('DIRECTION', DIRECTION); + + _export('moveBefore', moveBefore); + function configure(config, callback) { var defaults = new Options(); config.container.registerInstance(GLOBAL_OPTIONS, defaults); diff --git a/dist/system/move-before.js b/dist/system/move-before.js new file mode 100644 index 0000000..5c2fcce --- /dev/null +++ b/dist/system/move-before.js @@ -0,0 +1,22 @@ +"use strict"; + +System.register([], function (_export, _context) { + + function remove(array, matcherFn) { + var index = array.findIndex(matcherFn); + if (index >= 0) { + return array.splice(index, 1)[0]; + } + } + return { + setters: [], + execute: function () { + function moveBefore(array, itemMatcherFn, siblingMatcherFn) { + var removedItem = remove(array, itemMatcherFn); + var nextIndex = array.findIndex(siblingMatcherFn); + array.splice(nextIndex >= 0 ? nextIndex : array.length, 0, removedItem); + } + _export("moveBefore", moveBefore); + } + }; +}); \ No newline at end of file diff --git a/dist/temp/aurelia-dragula.js b/dist/temp/aurelia-dragula.js index ff21caa..8abe2ce 100644 --- a/dist/temp/aurelia-dragula.js +++ b/dist/temp/aurelia-dragula.js @@ -11,6 +11,7 @@ var _dec, _dec2, _dec3, _dec4, _dec5, _dec6, _dec7, _dec8, _dec9, _dec10, _dec11 exports.add = add; exports.rm = rm; +exports.moveBefore = moveBefore; exports.touchy = touchy; var _aureliaTemplating = require('aurelia-templating'); @@ -62,7 +63,7 @@ function rm(el, className) { el.className = el.className.replace(lookupClass(className), ' ').trim(); } -var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bindable)({ name: 'moves', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec2 = (0, _aureliaTemplating.bindable)({ name: 'accepts', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec3 = (0, _aureliaTemplating.bindable)({ name: 'invalid', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec4 = (0, _aureliaTemplating.bindable)({ name: 'containers', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec5 = (0, _aureliaTemplating.bindable)({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec6 = (0, _aureliaTemplating.bindable)({ name: 'copy', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec7 = (0, _aureliaTemplating.bindable)({ name: 'copySortSource', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec8 = (0, _aureliaTemplating.bindable)({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: true }), _dec9 = (0, _aureliaTemplating.bindable)({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec10 = (0, _aureliaTemplating.bindable)({ name: 'direction', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec11 = (0, _aureliaTemplating.bindable)({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec12 = (0, _aureliaTemplating.bindable)({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec13 = (0, _aureliaTemplating.bindable)({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = (0, _aureliaTemplating.bindable)({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = (0, _aureliaTemplating.bindable)({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item, source) {} }), _dec16 = (0, _aureliaTemplating.bindable)({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item, target, source, sibling) {} }), _dec17 = (0, _aureliaTemplating.bindable)({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: function defaultValue(item) {} }), _dec18 = (0, _aureliaTemplating.customElement)('dragula-and-drop'), _dec19 = (0, _aureliaTemplating.noView)(), _dec20 = (0, _aureliaDependencyInjection.inject)(GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { +var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bindable)({ name: 'moves', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec2 = (0, _aureliaTemplating.bindable)({ name: 'accepts', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec3 = (0, _aureliaTemplating.bindable)({ name: 'invalid', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec4 = (0, _aureliaTemplating.bindable)({ name: 'containers', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec5 = (0, _aureliaTemplating.bindable)({ name: 'isContainer', attribute: 'is-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec6 = (0, _aureliaTemplating.bindable)({ name: 'copy', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec7 = (0, _aureliaTemplating.bindable)({ name: 'copySortSource', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec8 = (0, _aureliaTemplating.bindable)({ name: 'revertOnSpill', attribute: 'revert-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: true }), _dec9 = (0, _aureliaTemplating.bindable)({ name: 'removeOnSpill', attribute: 'remove-on-spill', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec10 = (0, _aureliaTemplating.bindable)({ name: 'direction', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec11 = (0, _aureliaTemplating.bindable)({ name: 'ignoreInputTextSelection', attribute: 'ingore-input-text-selection', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec12 = (0, _aureliaTemplating.bindable)({ name: 'mirrorContainer', attribute: 'mirror-container', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec13 = (0, _aureliaTemplating.bindable)({ name: 'targetClass', attribute: 'target-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drop-target' }), _dec14 = (0, _aureliaTemplating.bindable)({ name: 'sourceClass', attribute: 'source-class', defaultBindingMode: _aureliaBinding.bindingMode.oneTime, defaultValue: 'drag-source' }), _dec15 = (0, _aureliaTemplating.bindable)({ name: 'dragFn', attribute: 'drag-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec16 = (0, _aureliaTemplating.bindable)({ name: 'dropFn', attribute: 'drop-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec17 = (0, _aureliaTemplating.bindable)({ name: 'dragEndFn', attribute: 'drag-end-fn', defaultBindingMode: _aureliaBinding.bindingMode.oneTime }), _dec18 = (0, _aureliaTemplating.customElement)('dragula-and-drop'), _dec19 = (0, _aureliaTemplating.noView)(), _dec20 = (0, _aureliaDependencyInjection.inject)(GLOBAL_OPTIONS), _dec(_class = _dec2(_class = _dec3(_class = _dec4(_class = _dec5(_class = _dec6(_class = _dec7(_class = _dec8(_class = _dec9(_class = _dec10(_class = _dec11(_class = _dec12(_class = _dec13(_class = _dec14(_class = _dec15(_class = _dec16(_class = _dec17(_class = _dec18(_class = _dec19(_class = _dec20(_class = function () { function DragulaAndDrop(globalOptions) { _classCallCheck(this, DragulaAndDrop); @@ -87,15 +88,15 @@ var DragulaAndDrop = exports.DragulaAndDrop = (_dec = (0, _aureliaTemplating.bin this.dragula.on('drop', function (item, target, source, sibling) { _this.dragula.cancel(); - _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); + if (typeof _this.dropFn === 'function') _this.dropFn({ item: item, target: target, source: source, sibling: sibling }); }); this.dragula.on('drag', function (item, source) { - _this.dragFn({ item: item, source: source }); + if (typeof _this.dragFn === 'function') _this.dragFn({ item: item, source: source }); }); this.dragula.on('dragend', function (item) { - _this.dragEndFn({ item: item }); + if (typeof _this.dragEndFn === 'function') _this.dragEndFn({ item: item }); }); }; @@ -729,6 +730,18 @@ var Emitter = exports.Emitter = function () { return Emitter; }(); +function moveBefore(array, itemMatcherFn, siblingMatcherFn) { + var removedItem = remove(array, itemMatcherFn); + var nextIndex = array.findIndex(siblingMatcherFn); + array.splice(nextIndex >= 0 ? nextIndex : array.length, 0, removedItem); +} + +function remove(array, matcherFn) { + var index = array.findIndex(matcherFn); + if (index >= 0) { + return array.splice(index, 1)[0]; + } +} var GLOBAL_OPTIONS = exports.GLOBAL_OPTIONS = 'GlobalOptions'; var DIRECTION = exports.DIRECTION = { diff --git a/package.json b/package.json index 739a160..e671f2e 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "aurelia-dragula", - "version": "0.10.2", + "version": "0.11.0", "description": "An aurelia compatible version of Dragula", "keywords": [ "aurelia",