Skip to content

feat(joint-core): add Paper#setDragging / Paper#isDragging API#3321

Merged
Geliogabalus merged 4 commits into
clientIO:masterfrom
kumilingus:feat/paper-set-is-dragging-master
May 19, 2026
Merged

feat(joint-core): add Paper#setDragging / Paper#isDragging API#3321
Geliogabalus merged 4 commits into
clientIO:masterfrom
kumilingus:feat/paper-set-is-dragging-master

Conversation

@kumilingus
Copy link
Copy Markdown
Contributor

Summary

Adds two public methods on dia.Paper for marking and reading the active-drag state on an event:

  • paper.setDragging(evt, value = true) — stash the drag flag on the event's per-paper eventData bag (defaults to true).
  • paper.isDragging(evt) — boolean read of the same flag.

Joint-core itself sets the flag from every action-confirmed drag-start branch:

File Method Gate
dia/ElementView.mjs dragStart after can('elementMove')
dia/LinkView.mjs dragStart after can('linkMove')
dia/LinkView.mjs dragLabelStart inside can('labelMove') block
dia/LinkView.mjs dragArrowheadStart after can('arrowheadMove')
dia/CellView.mjs dragLinkStart when the magnet→link transition actually creates the link

The magnet path notably waits until CellView.dragLinkStart runs (which may be deferred under magnetThreshold: 'onleave'), so a magnet pointerdown alone doesn't trip the flag — only when the link actually starts.

Motivation

External consumers (plugins, embedding hosts) currently have to inspect view-level eventData (action, linkView, etc) to determine whether a drag is actually in progress, which means leaking joint-core internals across the API boundary. With these two methods, the question "is a drag actually happening?" becomes a one-call public API.

Use cases:

  • Capture-on-drag (setPointerCapture only after a drag is confirmed — i.e. not on every pointerdown).
  • Drag-aware UI overlays / cursors that need to react only to confirmed drags.
  • Plugins that listen on pointermove and want to gate their work on real drag state.

A follow-up PR in @joint/react uses this API to drive setPointerCapture + a jj-is-dragging CSS class.

Changes

  • packages/joint-core/src/dia/Paper.mjs — define setDragging and isDragging.
  • packages/joint-core/src/dia/ElementView.mjs — call paper.setDragging(evt) after can('elementMove').
  • packages/joint-core/src/dia/LinkView.mjs — call paper.setDragging(evt) in dragStart, dragLabelStart, dragArrowheadStart.
  • packages/joint-core/src/dia/CellView.mjs — call paper.setDragging(evt) at the end of dragLinkStart.
  • packages/joint-core/types/dia.d.ts — declarations for both methods.

Test plan

  • yarn workspace @joint/core test — full QUnit suite (server + client).
  • grunt test:server --file=test/jointjs/paper.js — Paper-specific.
  • Manual: in any demo, attach paper.on('pointermove', evt => console.log(paper.isDragging(evt))) — expect true only after a drag-start gate has passed (drag the element / link / label / arrowhead, or magnet-to-link).

🤖 Generated with Claude Code

kumilingus and others added 4 commits May 18, 2026 17:49
New public methods on `dia.Paper` for marking and reading the active-drag state on an event:

- `paper.setDragging(evt, value = true)` — stash the drag flag on the event's per-paper `eventData` bag (defaults to `true`).
- `paper.isDragging(evt)` — boolean read of the same flag.

Joint-core itself sets the flag from every action-confirmed drag-start branch:

- `ElementView.dragStart` — element move (after `can('elementMove')`).
- `LinkView.dragStart` — link move (after `can('linkMove')`).
- `LinkView.dragLabelStart` — label move (inside `can('labelMove')` block).
- `LinkView.dragArrowheadStart` — arrowhead move (after `can('arrowheadMove')`).
- `CellView.dragLinkStart` — magnet→link transition (when the link is actually created, which may be deferred under `magnetThreshold: 'onleave'`).

External consumers (plugins / hosts) can now ask "is a drag actually happening?" without inspecting view-level eventData internals. Useful for capture-on-drag, custom cursors, drag-aware UI overlays, etc.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Always sets to true. The optional value parameter was unused code for a hypothetical reset use case. YAGNI — easy to add later if needed.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Adds a QUnit module that verifies:
- direct API round-trip (set then read);
- `isDragging` defaults to false on fresh events;
- `ElementView.dragStart` flips the flag after `can('elementMove')` passes;
- `isDragging` stays false when `elementMove` is denied;
- `LinkView.dragStart` flips the flag after `can('linkMove')`.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
…ging signatures

`dia.Event` was unresolved inside dia.d.ts itself; the file declares
`export type Event = mvc.TriggeredEvent` and other methods reference
`Event` directly. Match the convention.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
@kumilingus kumilingus requested a review from Geliogabalus May 18, 2026 16:09
@Geliogabalus Geliogabalus merged commit ec6eb33 into clientIO:master May 19, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants