feat(joint-core, joint-react): PointerEvents drag survival + capture in React preset#3320
Merged
Merged
Conversation
…in React preset joint-core - Adds `Paper#setDragging(evt, value=true)` / `Paper#isDragging(evt)` — public API for marking and reading the active drag state on an event. Called from every action-confirmed drag-start branch: `ElementView.dragStart`, `LinkView.dragStart`, `LinkView.dragLabelStart`, `LinkView.dragArrowheadStart`, `CellView.dragLinkStart`. External consumers (e.g. joint-react) can detect "drag is actually happening" without inspecting view-level eventData. joint-react preset (`presets/paper.ts`) - Switches paper drag-survival to real PointerEvents: `documentEvents` binds `pointermove` / `pointerup` / `pointercancel` instead of mouse + touch pairs. Joint-core's events hash stays unchanged (mousedown / touchstart still drive pointerdown). - On first pointermove of a confirmed drag (per `paper.isDragging(evt)`), calls `setPointerCapture` on the original pointerdown target — so drags survive the pointer leaving the host. `pointerup` / `pointercancel` releases capture. - Tracks the original pointerdown target via `startListening` listeners on `cell:pointerdown` + `element:magnet:pointerdown` — captures the magnet's deeper target when present (passive-magnet ordering: magnet event fires before cell event, guard prevents overwrite). - Adds `jj-is-dragging` class on paper.el during drag; styles.css gates new `--jj-drag-cursor` / `--jj-dragging-cursor` / `--jj-port-drag-cursor` / `--jj-port-dragging-cursor` CSS vars on `.jj-box` and `.jj-port-body[magnet="active"]`. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
Always sets to true. 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>
Geliogabalus
approved these changes
May 19, 2026
This was referenced Jul 3, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Paper#setDragging(evt, value=true)/Paper#isDragging(evt)API. Joint-core itself sets the flag from every action-confirmed drag-start branch (element / link / label / arrowhead / magnet→link). External consumers can ask "is a drag actually happening?" without poking view eventData internals.PointerEvent(pointermove/pointerup/pointercancel) and acquiressetPointerCaptureon the original pointerdown target on the firstpointermoveof a confirmed drag. Drags now survive the pointer leaving the host.Joint-core's
eventshash is unchanged —mousedown/touchstartstill drivepointerdown. OnlydocumentEvents(the drag-survival layer) is swapped to pointer events in the React preset.joint-core changes
dia/Paper.mjs— addsetDragging/isDraggingneardelegateDragEvents. No callers outside the new API methods.dia/ElementView.mjs—dragStartcallspaper.setDragging(evt)aftercan('elementMove')passes.dia/LinkView.mjs—dragStart,dragLabelStart,dragArrowheadStartall callpaper.setDragging(evt)inside their respectivecan(\u2026)gates.dia/CellView.mjs—dragLinkStartcallspaper.setDragging(evt)once the magnet\u2192link transition actually creates the link (covers the magnet path that defers viamagnetThreshold='onleave').types/dia.d.ts— declare both methods.joint-react changes
packages/joint-react/src/presets/paper.ts:documentEventsoverridden to{ pointermove, pointerup, pointercancel }.startListeningextended to recordpointerTargetoncell:pointerdown+element:magnet:pointerdown(magnet event fires first on passive magnets; guard prevents the later cell event from overwriting).pointermoveoverride: whenpaper.isDragging(event)passes andcaptureTargetnot yet set, callssetPointerCapture(pointerId)ondata.pointerTarget(falls back topaper.el) and stashescaptureTarget. Addsjj-is-draggingclass topaper.el.pointerupoverride: releases capture oncaptureTarget, clearsjj-is-draggingclass.packages/joint-react/src/css/styles.css:--jj-drag-cursor,--jj-dragging-cursor,--jj-port-drag-cursor,--jj-port-dragging-cursor..jj-is-dragging .jj-box,.jj-is-dragging .jj-port-body[magnet=\"active\"]cursor rules gated on the dragging class.Test plan
yarn workspace @joint/react jest --testPathPatterns=\"paper\"— 85/85 pass.yarn workspace @joint/react typecheckclean (modulo the pre-existingcode-controlled-mode-reset-bug.tsxheight regression already on dev).\ud83e\udd16 Generated with Claude Code