Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master'
Browse files Browse the repository at this point in the history
  • Loading branch information
sludemann committed Nov 29, 2018
2 parents 63ce0e1 + 6e3705d commit 6938697
Show file tree
Hide file tree
Showing 55 changed files with 9,144 additions and 10,565 deletions.
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ As Aurelia doesn't support IE < 9, Aurelia-Dragula won't, either. Aurelia-dragu

Aurelia Dragula differs from the upstream library, in that it also passes the view-models for the `item` (and `sibling` on the drop event) if the item being dragged corresponds to an Aurelia Custom Element.

##Usage
## Usage

The element itself is called `dragula-and-drop` and you can bind all the options available for the main library (with camel-case converted to hyphenated attribute names in the standard way) to it as well as a couple of extras. The functions are short-hand for binding to the equivalent events and should be bound with `.call` and if you want to receive arguments, they should be named the same as in the Type column below:

Expand Down Expand Up @@ -87,7 +87,7 @@ Where `array` is the array in which to move the objects,
A more complete example is available [here](https://github.com/michaelmalonenz/aurelia-dragula-example).


###Options
### Options
`import {Options} from 'aurelia-dragula;`

The options can either be passed in as a parameter to the Dragula constructor for individual instances, or can be set globally during plugin configuration:
Expand All @@ -99,9 +99,10 @@ let dragula = new Dragula(options);
```
or
```javascript
aurelia.use('aurelia-dragula', (options) => {
options.revertOnSpill = false;
});
aurelia.use
.plugin('aurelia-dragula', (options) => {
options.revertOnSpill = false;
});
```

They can be used in conjunction with one another, with the individually set settings taking precedence over the global settings.
Expand Down Expand Up @@ -186,7 +187,7 @@ They can be used in conjunction with one another, with the individually set sett
</table>


###Events
### Events
Events can be subscribed to by calling `dragula.on` with the event name and a callback. They can be registered for multiple times, with different callbacks.

```javascript
Expand Down
16 changes: 2 additions & 14 deletions build/tasks/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ gulp.task('build', function(callback) {
return runSequence(
'clean',
'build-index',
['build-es2015-temp', 'build-es2015', 'build-commonjs', 'build-amd', 'build-system'],
['build-commonjs', 'build-amd', 'build-system'],
'build-html',
'copy-css',
callback
Expand All @@ -57,18 +57,6 @@ gulp.task('build-index', function(){
.pipe(gulp.dest(paths.output));
});

gulp.task('build-es2015-temp', function () {
return gulp.src(paths.output + jsName)
.pipe(to5(assign({}, compilerOptions.commonjs())))
.pipe(gulp.dest(paths.output + 'temp'));
});

gulp.task('build-es2015', function () {
return gulp.src(paths.source)
.pipe(to5(assign({}, compilerOptions.es2015())))
.pipe(gulp.dest(paths.output + 'es2015'));
});

gulp.task('build-commonjs', function () {
return gulp.src(paths.source)
.pipe(to5(assign({}, compilerOptions.commonjs())))
Expand All @@ -88,7 +76,7 @@ gulp.task('build-system', function () {
});

gulp.task('copy-css', function() {
[ 'es2015', 'commonjs', 'amd', 'system'].forEach(function(dir) {
[ 'commonjs', 'amd', 'system'].forEach(function(dir) {
return gulp.src(paths.style)
.pipe(gulp.dest(paths.output + dir));
});
Expand Down
70 changes: 38 additions & 32 deletions config.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,48 +7,54 @@ System.config({
},

map: {
"aurelia-binding": "npm:[email protected]",
"aurelia-dependency-injection": "npm:[email protected]",
"aurelia-logging": "npm:[email protected]",
"aurelia-pal": "npm:[email protected]",
"aurelia-pal-browser": "npm:[email protected]",
"aurelia-polyfills": "npm:[email protected]",
"aurelia-templating": "npm:[email protected]",
"npm:[email protected]": {
"aurelia-logging": "npm:[email protected]",
"aurelia-metadata": "npm:[email protected]",
"aurelia-pal": "npm:[email protected]",
"aurelia-task-queue": "npm:[email protected]"
},
"npm:[email protected]": {
"aurelia-metadata": "npm:[email protected]",
"aurelia-pal": "npm:[email protected]"
"aurelia-binding": "npm:[email protected]",
"aurelia-dependency-injection": "npm:[email protected]",
"aurelia-logging": "npm:[email protected]",
"aurelia-pal": "npm:[email protected]",
"aurelia-pal-browser": "npm:[email protected]",
"aurelia-polyfills": "npm:[email protected]",
"aurelia-templating": "npm:[email protected]",
"npm:[email protected]": {
"aurelia-logging": "npm:[email protected]",
"aurelia-metadata": "npm:[email protected]",
"aurelia-pal": "npm:[email protected]",
"aurelia-task-queue": "npm:[email protected]"
},
"npm:[email protected]": {
"aurelia-logging": "npm:[email protected]",
"aurelia-metadata": "npm:[email protected]",
"aurelia-pal": "npm:[email protected]",
"aurelia-task-queue": "npm:[email protected]"
},
"npm:[email protected]": {
"aurelia-metadata": "npm:[email protected]",
"aurelia-pal": "npm:[email protected]"
},
"npm:[email protected]": {
"aurelia-metadata": "npm:[email protected].3",
"aurelia-metadata": "npm:[email protected].4",
"aurelia-path": "npm:[email protected]"
},
"npm:[email protected].3": {
"aurelia-pal": "npm:aurelia-pal@1.3.0"
"npm:[email protected].4": {
"aurelia-pal": "npm:aurelia-pal@1.8.0"
},
"npm:aurelia-pal-browser@1.2.1": {
"aurelia-pal": "npm:aurelia-pal@1.3.0"
"npm:aurelia-pal-browser@1.8.0": {
"aurelia-pal": "npm:aurelia-pal@1.8.0"
},
"npm:aurelia-polyfills@1.2.2": {
"aurelia-pal": "npm:aurelia-pal@1.3.0"
"npm:aurelia-polyfills@1.3.0": {
"aurelia-pal": "npm:aurelia-pal@1.8.0"
},
"npm:aurelia-task-queue@1.2.0": {
"aurelia-pal": "npm:aurelia-pal@1.3.0"
"npm:aurelia-task-queue@1.3.1": {
"aurelia-pal": "npm:aurelia-pal@1.8.0"
},
"npm:aurelia-templating@1.4.2": {
"aurelia-binding": "npm:aurelia-binding@1.2.1",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.3.1",
"npm:aurelia-templating@1.10.0": {
"aurelia-binding": "npm:[email protected].5",
"aurelia-dependency-injection": "npm:aurelia-dependency-injection@1.4.1",
"aurelia-loader": "npm:[email protected]",
"aurelia-logging": "npm:aurelia-logging@1.3.1",
"aurelia-metadata": "npm:[email protected].3",
"aurelia-pal": "npm:aurelia-pal@1.3.0",
"aurelia-logging": "npm:aurelia-logging@1.5.0",
"aurelia-metadata": "npm:[email protected].4",
"aurelia-pal": "npm:aurelia-pal@1.8.0",
"aurelia-path": "npm:[email protected]",
"aurelia-task-queue": "npm:aurelia-task-queue@1.2.0"
"aurelia-task-queue": "npm:aurelia-task-queue@1.3.1"
}
}
});
6 changes: 3 additions & 3 deletions dist/amd/dragula-and-drop.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ define(['exports', 'aurelia-templating', 'aurelia-binding', 'aurelia-dependency-
invalid: this._invalid.bind(this)
};

var options = Object.assign(aureliaOptions, boundOptions);
this.dragula = new _dragula.Dragula(options);
this.options = Object.assign(aureliaOptions, boundOptions);
this.dragula = new _dragula.Dragula(this.options);

this.dragula.on('drop', this._dropFunction.bind(this));

Expand Down Expand Up @@ -69,7 +69,7 @@ define(['exports', 'aurelia-templating', 'aurelia-binding', 'aurelia-dependency-
};

DragulaAndDrop.prototype._dropFunction = function _dropFunction(item, target, source, sibling, itemVM, siblingVM) {
this.dragula.cancel();
this.dragula.cancel(this.options.revertOnSpill, true);
if (typeof this.dropFn === 'function') this.dropFn({ item: item, target: target, source: source, sibling: sibling, itemVM: itemVM, siblingVM: siblingVM });
};

Expand Down
61 changes: 37 additions & 24 deletions dist/amd/dragula.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
function Dragula(options) {
_classCallCheck(this, Dragula);

var len = arguments.length;
var globalOptions = _aureliaDependencyInjection.Container.instance.get(_options.GLOBAL_OPTIONS);
this.options = Object.assign({}, globalOptions, options);
this._emitter = new _emitter.Emitter();
Expand All @@ -78,7 +77,7 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
this.boundPreventGrabbed = this._preventGrabbed.bind(this);
this.boundDrag = this.drag.bind(this);

this._events();
this._addEvents();

this._mirror;
this._source;
Expand Down Expand Up @@ -111,10 +110,14 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
return this.options.containers.indexOf(el) !== -1 || this.options.isContainer(el);
};

Dragula.prototype._events = function _events(remove) {
var op = remove ? 'removeEventListener' : 'addEventListener';
(0, _touchy.touchy)(document.documentElement, op, 'mousedown', this.boundGrab);
(0, _touchy.touchy)(document.documentElement, op, 'mouseup', this.boundRelease);
Dragula.prototype._addEvents = function _addEvents() {
(0, _touchy.touchy)(document.documentElement, 'addEventListener', 'mousedown', this.boundGrab);
(0, _touchy.touchy)(document.documentElement, 'addEventListener', 'mouseup', this.boundRelease);
};

Dragula.prototype._removeEvents = function _removeEvents() {
(0, _touchy.touchy)(document.documentElement, 'removeEventListener', 'mousedown', this.boundGrab);
(0, _touchy.touchy)(document.documentElement, 'removeEventListener', 'mouseup', this.boundRelease);
};

Dragula.prototype._eventualMovements = function _eventualMovements(remove) {
Expand All @@ -128,8 +131,8 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
};

Dragula.prototype.destroy = function destroy() {
this._events(true);
this._release({});
this._removeEvents();
this._release({ clientX: -1, clientY: -1 });
this._emitter.destroy();
};

Expand Down Expand Up @@ -192,7 +195,8 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
this._offsetX = _util.Util.getCoord('pageX', e) - offset.left;
this._offsetY = _util.Util.getCoord('pageY', e) - offset.top;

classes.add(this._copy || this._item, 'gu-transit');
var item = this._copy || this._item;
classes.add(item, 'gu-transit');
this.renderMirrorImage();
this.drag(e);
};
Expand Down Expand Up @@ -248,6 +252,7 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u

this._source = context.source;
this._item = context.item;

this._initialSibling = context.item.nextSibling;
this._currentSibling = _util.Util.nextEl(context.item);

Expand Down Expand Up @@ -292,7 +297,9 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
Dragula.prototype.drop = function drop(item, target) {
if (this._copy && this.options.copySortSource && target === this._source) {
var parent = _util.Util.getParent(this._item);
if (parent) parent.removeChild(this._item);
if (parent) {
parent.removeChild(this._item);
}
}
if (this._isInitialPlacement(target)) {
this._emitter.emit('cancel', item, this._source, this._source, _util.Util.getViewModel(this._item));
Expand All @@ -316,17 +323,22 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
};

Dragula.prototype.cancel = function cancel(revert) {
var forceIgnoreRevert = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;

if (!this.dragging) {
return;
}

if (this._initialSibling && this._initialSibling.nodeName === '#comment' && this._initialSibling.data === 'anchor') {
forceIgnoreRevert = false;
}
var reverts = arguments.length > 0 ? revert : this.options.revertOnSpill;
var item = this._copy || this._item;
var parent = _util.Util.getParent(item);
if (this._copy && parent) {
parent.removeChild(this._copy);
}
var initial = this._isInitialPlacement(parent);
if (initial === false && !this._copy && reverts) {
if (initial === false && reverts && this._copy && parent && parent !== this._source) {
parent.removeChild(this._copy);
} else {
this._source.insertBefore(item, this._initialSibling);
}
if (initial || reverts) {
Expand Down Expand Up @@ -359,7 +371,8 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
} else if (this._mirror) {
sibling = this._currentSibling;
} else {
sibling = (this._copy || this._item).nextSibling;
var item = this._copy || this._item;
sibling = item.nextSibling;
}
return target === this._source && sibling === this._initialSibling;
};
Expand Down Expand Up @@ -397,7 +410,7 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
return;
}

if (this._lastRenderTime !== null && Date.now() - this._lastRenderTime < MIN_TIME_BETWEEN_REDRAWS_MS) {
if (this._lastRenderTime != null && Date.now() - this._lastRenderTime < MIN_TIME_BETWEEN_REDRAWS_MS) {
return;
}
this._lastRenderTime = Date.now();
Expand Down Expand Up @@ -428,8 +441,8 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u

var elementBehindCursor = _util.Util.getElementBehindPoint(this._mirror, clientX, clientY);
var dropTarget = this._findDropTarget(elementBehindCursor, clientX, clientY);
var changed = dropTarget !== null && dropTarget !== this._lastDropTarget;
if (changed || dropTarget === null) {
var changed = dropTarget != null && dropTarget !== this._lastDropTarget;
if (changed || dropTarget == null) {
out();
this._lastDropTarget = dropTarget;
over();
Expand All @@ -443,7 +456,7 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
}
var reference = void 0;
var immediate = _util.Util.getImmediateChild(dropTarget, elementBehindCursor);
if (immediate !== null) {
if (immediate != null) {
reference = this.getReference(dropTarget, immediate, clientX, clientY);
} else if (this.options.revertOnSpill === true && !this._copy) {
reference = this._initialSibling;
Expand All @@ -454,7 +467,7 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
}
return;
}
if (reference === null && changed || reference !== item && reference !== _util.Util.nextEl(item)) {
if (reference == null && changed || reference !== item && reference !== _util.Util.nextEl(item)) {
this._currentSibling = reference;
dropTarget.insertBefore(item, reference);
this._emitter.emit('shadow', item, dropTarget, this._source, _util.Util.getViewModel(item));
Expand Down Expand Up @@ -497,11 +510,12 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
};

Dragula.prototype.getReference = function getReference(dropTarget, target, x, y) {
var horizontal = this.options.direction === 'horizontal';
var outside = function outside() {
var len = dropTarget.children.length;
var i = void 0;
var el = void 0;
var rect = void 0;
var i = void 0,
el = void 0,
rect = void 0;
for (i = 0; i < len; i++) {
el = dropTarget.children[i];
rect = el.getBoundingClientRect();
Expand All @@ -527,7 +541,6 @@ define(['exports', 'aurelia-dependency-injection', './touchy', './options', './u
return resolve(y > rect.top + _util.Util.getRectHeight(rect) / 2);
};

var horizontal = this.options.direction === 'horizontal';
var reference = target !== dropTarget ? inside() : outside();
return reference;
};
Expand Down
4 changes: 3 additions & 1 deletion dist/amd/emitter.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ define(['exports'], function (exports) {
var index = eventList.findIndex(function (x) {
return x.func === fn;
});
if (index >= 0) eventList.splice(index, 1);
if (index >= 0) {
eventList.splice(index, 1);
}
}
}
};
Expand Down
3 changes: 2 additions & 1 deletion dist/amd/options.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ define(['exports'], function (exports) {
this.copySortSource = false;
this.revertOnSpill = false;
this.removeOnSpill = false;
this.direction = DIRECTION.VERTICAL, this.ignoreInputTextSelection = true;
this.direction = DIRECTION.VERTICAL;
this.ignoreInputTextSelection = true;
this.mirrorContainer = document.body;
}

Expand Down
Loading

0 comments on commit 6938697

Please sign in to comment.