-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
refactor: rewrite blocksuite dnd #9595
Conversation
How to use the Graphite Merge QueueAdd either label to this PR to merge it via the merge queue:
You must have a Graphite account in order to use the merge queue. Sign up using this link. An organization admin has enabled the Graphite Merge Queue in this repository. Please do not merge from GitHub as this will restart CI on PRs being processed by the merge queue. This stack of pull requests is managed by Graphite. Learn more about stacking. |
116dec2
to
d003e9c
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## canary #9595 +/- ##
==========================================
+ Coverage 52.91% 52.99% +0.08%
==========================================
Files 2198 2199 +1
Lines 99030 99038 +8
Branches 16825 16828 +3
==========================================
+ Hits 52401 52489 +88
+ Misses 45222 45144 -78
+ Partials 1407 1405 -2
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. |
09539ea
to
eb8007b
Compare
blocksuite/affine/components/src/drag-indicator/file-drop-manager.ts
Outdated
Show resolved
Hide resolved
Merge activity
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
blocksuite/affine/widget-drag-handle/src/watchers/page-watcher.ts
Outdated
Show resolved
Hide resolved
62116ca
to
95c065e
Compare
### Changed - Refactored BlockSuite drag-and-drop using @atlaskit/pragmatic-drag-and-drop/element/adapter. - Updated block dragging to use the new drag-and-drop infrastructure. ### BlockSuite DND API Access the BlockSuite drag-and-drop API via `std.dnd`. This is a lightweight wrapper around pragmatic-drag-and-drop, offering convenient generic types and more intuitive option names. #### Drag payload structure There's some constrain about drag payload. The whole drag payload looks like this: ```typescript type DragPayload = { entity: { type: string }, from: { at: 'blocksuite', docId: string } } ``` - The `from` field is auto-generated—no need for manual handling. - The `entity` field is customizable, but it must include a `type`. All drag-and-drop methods accept a generic type for entity, ensuring more accurate payloads in event handlers. ```typescript type BlockEntity = { type: 'blocks', blockIds: string[] } dnd.draggable<BlockEntity>({ element: someElement, setDragData: () => { // the return type must satisfy the generic type // in this case, it's BlockEntity return { type: 'blocks', blockIds: [] } } }); dnd.monitor<BlockEntity>({ // the arguments is same for other event handler onDrag({ source }) { // the type of this is BlockEntity source.data.entity } }) ``` #### Drop payload When hover on droppable target. You can set drop payload as well. All drag-and-drop methods accept a second generic type for drop payload. The drop payload is customizable. Additionally, the DND system will add an `edge` field to the final payload object, indicating the nearest edge of the drop target relative to the current drag position. ```typescript type DropPayload = { blockId: string; } dnd.dropTarget<BlockEntity, DropPayload>({ getData() { // the type should be DropPayload return { blockId: 'someId' } } }); dnd.monitor<BlockEntity, DropPayload>({ // drag over on drop target onDrag({ location }) { const target = location.current.dropTargets[0]; // the type is DropPayload target.data; // retrieve the nearest edge of the drop target relative to the current drop position. target.data.edge; } }) ```
184e141
to
9971719
Compare
Suspect IssuesThis pull request was deployed and Sentry observed the following issues:
Did you find this useful? React with a 👍 or 👎 |
Changed
BlockSuite DND API
Access the BlockSuite drag-and-drop API via
std.dnd
. This is a lightweight wrapper around pragmatic-drag-and-drop, offering convenient generic types and more intuitive option names.Drag payload structure
There's some constrain about drag payload. The whole drag payload looks like this:
from
field is auto-generated—no need for manual handling.entity
field is customizable, but it must include atype
.All drag-and-drop methods accept a generic type for entity, ensuring more accurate payloads in event handlers.
Drop payload
When hover on droppable target. You can set drop payload as well. All drag-and-drop methods accept a second generic type for drop payload.
The drop payload is customizable. Additionally, the DND system will add an
edge
field to the final payload object, indicating the nearest edge of the drop target relative to the current drag position.