diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index a5da13fec..000000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,28 +0,0 @@ -name: ci -on: [ push, pull_request ] -jobs: - build: - runs-on: ubuntu-latest - - steps: - - name: Checkout - uses: actions/checkout@v2 - - name: Use Node.js - uses: actions/setup-node@v1 - with: - node-version: '10.x' - - name: Cache Node.js modules - uses: actions/cache@v2 - with: - # npm cache files are stored in `~/.npm` on Linux/macOS - path: ~/.npm - key: ${{ runner.OS }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.OS }}-node- - ${{ runner.OS }}- - - name: Install dependencies - run: npm ci - - name: Build - run: COVERAGE=1 npm run all - - name: Upload coverage - run: npx codecov \ No newline at end of file diff --git a/README.md b/README.md index 3cfaf3e18..60d1b863c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ # diagram-js -[![Build Status](https://travis-ci.com/bpmn-io/diagram-js.svg?branch=develop)](https://travis-ci.com/bpmn-io/diagram-js) +[![Build Status](https://travis-ci.org/bpmn-io/diagram-js.svg?branch=develop)](https://travis-ci.org/bpmn-io/diagram-js) A toolbox for displaying and modifying diagrams on the web. diff --git a/lib/features/dragging/index.js b/lib/features/dragging/index.js index aad5ab41f..f9ff8e635 100644 --- a/lib/features/dragging/index.js +++ b/lib/features/dragging/index.js @@ -1,15 +1,11 @@ import SelectionModule from '../selection'; import Dragging from './Dragging'; -import HoverFix from './HoverFix'; + export default { - __init__: [ - 'hoverFix' - ], __depends__: [ - SelectionModule + SelectionModule, ], dragging: [ 'type', Dragging ], - hoverFix: [ 'type', HoverFix ] }; \ No newline at end of file diff --git a/lib/features/dragging/HoverFix.js b/lib/features/hover-fix/HoverFix.js similarity index 71% rename from lib/features/dragging/HoverFix.js rename to lib/features/hover-fix/HoverFix.js index e644ab483..2e60df412 100644 --- a/lib/features/dragging/HoverFix.js +++ b/lib/features/hover-fix/HoverFix.js @@ -79,59 +79,48 @@ export default function HoverFix(eventBus, dragging, elementRegistry) { /** - * We make sure that drag.out is always fired, even if the + * We make sure that element.out is always fired, even if the * browser swallows an element.out event. * * Event sequence: * - * drag.hover + * element.hover * (element.out >> sometimes swallowed) - * element.hover >> ensure we fired drag.out + * element.hover >> ensure we fired element.out */ - eventBus.on('drag.init', function() { + (function() { + var hoverGfx; + var hover; - var hover, hoverGfx; + eventBus.on('element.hover', function(event) { - function setDragHover(event) { - hover = event.hover; - hoverGfx = event.hoverGfx; - } + // (1) remember current hover element + hoverGfx = event.gfx; + hover = event.element; + }); - function unsetHover() { - hover = null; - hoverGfx = null; - } + eventBus.on('element.hover', HIGH_PRIORITY, function(event) { - function ensureOut() { + // (3) am I on an element still? + if (hover) { - if (!hover) { - return; + // (4) that is a problem, gotta "simulate the out" + eventBus.fire('element.out', { + element: hover, + gfx: hoverGfx + }); } - var element = hover, - gfx = hoverGfx; - - hover = null; - hoverGfx = null; - - // emit synthetic out event - dragging.out({ - element: element, - gfx: gfx - }); - } + }); - eventBus.on('drag.hover', setDragHover); - eventBus.on('element.out', unsetHover); - eventBus.on('element.hover', HIGH_PRIORITY, ensureOut); + eventBus.on('element.out', function() { - eventBus.once('drag.cleanup', function() { - eventBus.off('drag.hover', setDragHover); - eventBus.off('element.out', unsetHover); - eventBus.off('element.hover', ensureOut); + // (2) unset hover state if we correctly outed us *GG* + hoverGfx = null; + hover = null; }); - }); + })(); this._findTargetGfx = function(event) { var position, diff --git a/lib/features/hover-fix/index.js b/lib/features/hover-fix/index.js new file mode 100644 index 000000000..50fd80339 --- /dev/null +++ b/lib/features/hover-fix/index.js @@ -0,0 +1,14 @@ +import DraggingModule from '../dragging'; + +import HoverFix from './HoverFix'; + + +export default { + __init__: [ + 'hoverFix' + ], + __depends__: [ + DraggingModule + ], + hoverFix: [ 'type', HoverFix ], +}; \ No newline at end of file diff --git a/test/spec/features/create/CreateSpec.js b/test/spec/features/create/CreateSpec.js index e7ae00f62..867f33d7c 100644 --- a/test/spec/features/create/CreateSpec.js +++ b/test/spec/features/create/CreateSpec.js @@ -10,6 +10,7 @@ import { import modelingModule from 'lib/features/modeling'; import moveModule from 'lib/features/move'; import dragModule from 'lib/features/dragging'; +import hoverFixModule from 'lib/features/hover-fix'; import createModule from 'lib/features/create'; import attachSupportModule from 'lib/features/attach-support'; import connectionPreviewModule from 'lib/features/connection-preview'; @@ -27,7 +28,8 @@ var testModules = [ attachSupportModule, modelingModule, moveModule, - dragModule + dragModule, + hoverFixModule ]; var LOW_PRIORITY = 500; diff --git a/test/spec/features/dragging/HoverFixSpec.js b/test/spec/features/hover-fix/HoverFixSpec.js similarity index 72% rename from test/spec/features/dragging/HoverFixSpec.js rename to test/spec/features/hover-fix/HoverFixSpec.js index b84c34fa5..a5415792f 100644 --- a/test/spec/features/dragging/HoverFixSpec.js +++ b/test/spec/features/hover-fix/HoverFixSpec.js @@ -8,11 +8,12 @@ import { assign } from 'min-dash'; import { createCanvasEvent as canvasEvent } from '../../../util/MockEvents'; import dragModule from 'lib/features/dragging'; +import hoverFixModule from 'lib/features/hover-fix'; describe('features/dragging - HoverFix', function() { - beforeEach(bootstrapDiagram({ modules: [ dragModule ] })); + beforeEach(bootstrapDiagram({ modules: [ dragModule, hoverFixModule ] })); var shape1, shape2; @@ -44,6 +45,63 @@ describe('features/dragging - HoverFix', function() { describe('hover fix', function() { + it('should ensure the correct events are fired in sequence', inject(function(canvas, eventBus) { + + // given + var events = []; + + eventBus.on(['element.hover', 'element.out'], function(event) { + events.push({ type: event.type, element: event.element }); + }); + + eventBus.fire('element.hover', { element: shape1, gfx: canvas.getGraphics(shape1) }); + + // assume + expect(events).to.eql([{ type: 'element.hover', element: shape1 }]); + + // when + eventBus.fire('element.hover', { element: shape2, gfx: canvas.getGraphics(shape2) }); + + // then + expect(events).to.eql([ + { type: 'element.hover', element: shape1 }, + { type: 'element.out', element: shape1 }, + { type: 'element.hover', element: shape2 } + ]); + })); + + + it('should not interfere with the normal hovering process', inject(function(canvas, eventBus) { + + // given + var events = []; + + eventBus.on(['element.hover', 'element.out'], function(event) { + events.push({ type: event.type, element: event.element }); + }); + + eventBus.fire('element.hover', { element: shape1, gfx: canvas.getGraphics(shape1) }); + + // assume + expect(events).to.eql([{ type: 'element.hover', element: shape1 }]); + + // when + eventBus.fire('element.out', { element: shape1, gfx: canvas.getGraphics(shape2) }); + eventBus.fire('element.hover', { element: shape2, gfx: canvas.getGraphics(shape2) }); + + // then + expect(events).to.eql([ + { type: 'element.hover', element: shape1 }, + { type: 'element.out', element: shape1 }, + { type: 'element.hover', element: shape2 } + ]); + })); + + }); + + + describe('dragging fix', function() { + beforeEach(inject(function(dragging) { dragging.setOptions({ manual: true }); }));