Skip to content

Commit

Permalink
feat(dia.ElementView): add getTargetParentView() method (#2748)
Browse files Browse the repository at this point in the history
  • Loading branch information
kumilingus authored Sep 2, 2024
1 parent ca80b2c commit 0d29e70
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/joint-core/src/dia/ElementView.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,11 @@ export const ElementView = CellView.extend({
}
},

getTargetParentView: function(evt) {
const { candidateEmbedView = null } = this.eventData(evt);
return candidateEmbedView;
},

getDelegatedView: function() {

var view = this;
Expand Down
34 changes: 34 additions & 0 deletions packages/joint-core/test/jointjs/embedding.js
Original file line number Diff line number Diff line change
Expand Up @@ -396,4 +396,38 @@ QUnit.module('embedding', function(hooks) {
}), 'All links were brought to front.');
});

QUnit.test('getTargetParentView()', function(assert) {

let evt;

const r1 = new joint.shapes.standard.Rectangle({
position: { x: 100, y: 100 },
size: { width: 100, height: 100 }
});
const r2 = new joint.shapes.standard.Rectangle({
position: { x: 500, y: 500 },
size: { width: 100, height: 100 }
});

this.graph.addCells([r1, r2]);

const v1 = r1.findView(this.paper);
const v2 = r2.findView(this.paper);

evt = new $.Event({ target: v1.el });
assert.equal(v2.getTargetParentView(evt), null);
v2.pointerdown(evt, 500, 500);
v2.pointermove(evt, 600, 600);
assert.equal(v2.getTargetParentView(evt), null);
v2.pointerup(evt, 600, 600);
assert.equal(v2.getTargetParentView(evt), null);

evt = new $.Event({ target: v1.el });
v2.pointerdown(evt, 600, 600);
v2.pointermove(evt, 100, 100);
assert.equal(v2.getTargetParentView(evt), v1);
v2.pointerup(evt, 100, 100);
assert.equal(v2.getTargetParentView(evt), null);
assert.equal(r2.get('parent'), r1.id);
});
});
2 changes: 2 additions & 0 deletions packages/joint-core/types/joint.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -989,6 +989,8 @@ export namespace dia {

getDelegatedView(): ElementView | null;

getTargetParentView(evt: dia.Event): CellView | null;

findPortNode(portId: string | number): SVGElement | null;
findPortNode(portId: string | number, selector: string): E | null;

Expand Down

0 comments on commit 0d29e70

Please sign in to comment.