diff --git a/.travis.yml b/.travis.yml index cc1ba6e..1d3284d 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,7 +3,7 @@ language: node_js node_js: # we recommend testing addons with the same minimum supported node version as Ember CLI # so that your addon works for all apps - - "8" + - "10" sudo: false dist: trusty @@ -18,6 +18,7 @@ env: global: # See https://git.io/vdao3 for details. - JOBS=1 + matrix: # we recommend new addons test the current and previous LTS # as well as latest stable release (bonus points to beta/canary) diff --git a/README.md b/README.md index 5571140..ee9b02d 100644 --- a/README.md +++ b/README.md @@ -360,7 +360,6 @@ export default Ember.ArrayController.extend({ post.save(); } } -} }); ``` diff --git a/addon/components/draggable-object-target.js b/addon/components/draggable-object-target.js index 97c2c8d..5c19f2c 100644 --- a/addon/components/draggable-object-target.js +++ b/addon/components/draggable-object-target.js @@ -55,13 +55,23 @@ export default Component.extend(Droppable, { } }, - mouseEnter(e) { + handleMouseEnter(e) { let mouseEnter = this.get('onMouseEnter'); if (mouseEnter) { mouseEnter(e); } }, + didInsertElement() { + this._super(...arguments); + this.element.addEventListener('mouseenter', this.handleMouseEnter); + }, + + willDestroyElement() { + this._super(...arguments); + this.element.removeEventListener('mouseenter', this.handleMouseEnter); + }, + actions: { acceptForDrop() { let hashId = this.get('coordinator.clickedId'); diff --git a/addon/components/draggable-object.js b/addon/components/draggable-object.js index 8a32d24..07d8236 100644 --- a/addon/components/draggable-object.js +++ b/addon/components/draggable-object.js @@ -7,7 +7,7 @@ import { set } from '@ember/object'; import { wrapper } from 'ember-drag-drop/utils/proxy-unproxy-objects'; export default Component.extend({ - dragCoordinator: service(), + dragCoordinator: service('drag-coordinator'), overrideClass: 'draggable-object', classNameBindings: [':js-draggableObject','isDraggingObject:is-dragging-object:', 'overrideClass'], attributeBindings: ['dragReady:draggable'], @@ -26,7 +26,7 @@ export default Component.extend({ proxyContent: computed('content', function() { return wrapper(this.get('content')); }), - + init() { this._super(...arguments); diff --git a/addon/components/object-bin.js b/addon/components/object-bin.js index 58011e4..be2f5db 100644 --- a/addon/components/object-bin.js +++ b/addon/components/object-bin.js @@ -7,7 +7,7 @@ function removeOne(arr,obj) { var l2 = arr.get('length'); if (l-1 !== l2) { - throw "bad length " + l + " " + l2; + throw new Error("bad length " + l + " " + l2); } } diff --git a/addon/components/sortable-objects.js b/addon/components/sortable-objects.js index 9ca3ade..a4fef47 100644 --- a/addon/components/sortable-objects.js +++ b/addon/components/sortable-objects.js @@ -3,7 +3,7 @@ import { inject as service } from '@ember/service'; import { A } from '@ember/array'; export default Component.extend( { - dragCoordinator: service(), + dragCoordinator: service('drag-coordinator'), overrideClass: 'sortable-objects', classNameBindings: ['overrideClass'], enableSort: true, diff --git a/addon/services/drag-coordinator.js b/addon/services/drag-coordinator.js index 5417b7c..d9f81ee 100644 --- a/addon/services/drag-coordinator.js +++ b/addon/services/drag-coordinator.js @@ -77,18 +77,26 @@ export default Service.extend({ const currentOffsetItem = this.get('currentOffsetItem'); const pos = this.relativeClientPosition(emberObject.element, event); const hasSameSortingScope = this.get('currentDragItem.sortingScope') === emberObject.get('sortingScope'); - let moveDirection = false; + let moveDirections = []; if (!this.get('lastEvent')) { this.set('lastEvent', event); } if (event.clientY < this.get('lastEvent').clientY) { - moveDirection = 'up'; + moveDirections.push('up'); } if (event.clientY > this.get('lastEvent').clientY) { - moveDirection = 'down'; + moveDirections.push('down'); + } + + if (event.clientX < this.get('lastEvent').clientX) { + moveDirections.push('left'); + } + + if (event.clientX > this.get('lastEvent').clientX) { + moveDirections.push('right'); } this.set('lastEvent', event); @@ -96,7 +104,10 @@ export default Service.extend({ if (!this.get('isMoving') && this.get('currentDragEvent')) { if (event.target !== this.get('currentDragEvent').target && hasSameSortingScope) { //if not dragging over self if (currentOffsetItem !== emberObject) { - if (pos.py > 0.33 && moveDirection === 'up' || pos.py > 0.33 && moveDirection === 'down') { + if (pos.py < 0.67 && moveDirections.indexOf('up') >= 0 || + pos.py > 0.33 && moveDirections.indexOf('down') >= 0 || + pos.px < 0.67 && moveDirections.indexOf('left') >= 0 || + pos.px > 0.33 && moveDirections.indexOf('right') >= 0) { this.moveElements(emberObject); this.set('currentOffsetItem', emberObject); diff --git a/app/models/obj-hash.js b/app/models/obj-hash.js index c6581e7..bff7cd4 100644 --- a/app/models/obj-hash.js +++ b/app/models/obj-hash.js @@ -21,7 +21,7 @@ export default EmberObject.extend({ getObj: function(key) { var res = this.get('content')[key]; if (!res) { - throw "no obj for key "+key; + throw new Error("no obj for key "+key); } return res; }, diff --git a/test-support/helpers/drag-drop.js b/test-support/helpers/drag-drop.js index a21736c..f3479a6 100644 --- a/test-support/helpers/drag-drop.js +++ b/test-support/helpers/drag-drop.js @@ -1,2 +1,2 @@ export { default } from 'ember-drag-drop/test-support/helpers/drag-drop'; -export * from 'ember-drag-drop/test-support/helpers/drag-drop'; +export * from 'ember-drag-drop/test-support/helpers/drag-drop'; \ No newline at end of file diff --git a/test-support/helpers/ember-drag-drop.js b/test-support/helpers/ember-drag-drop.js index edb2c53..45f1c9f 100644 --- a/test-support/helpers/ember-drag-drop.js +++ b/test-support/helpers/ember-drag-drop.js @@ -6,7 +6,7 @@ function drop($dragHandle, dropCssPath, dragEvent) { let dropTarget = document.querySelector(dropCssPath); if (dropTarget.length === 0) { - throw(`There are no drop targets by the given selector: '${dropCssPath}'`); + throw new Error(`There are no drop targets by the given selector: '${dropCssPath}'`); } run(() => {