-
Notifications
You must be signed in to change notification settings - Fork 3.5k
refactor: table drag preview using decorations #8597
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
Open
aaryan610
wants to merge
1
commit into
preview
Choose a base branch
from
refactor/table-drag-preview
base: preview
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+123
−36
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
64 changes: 64 additions & 0 deletions
64
packages/editor/src/core/extensions/table/plugins/drag-state.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,64 @@ | ||
| /** | ||
| * Copyright (c) 2023-present Plane Software, Inc. and contributors | ||
| * SPDX-License-Identifier: AGPL-3.0-only | ||
| * See the LICENSE file for details. | ||
| */ | ||
|
|
||
| import type { Transaction } from "@tiptap/pm/state"; | ||
| import { Plugin, PluginKey } from "@tiptap/pm/state"; | ||
| import { Decoration, DecorationSet } from "@tiptap/pm/view"; | ||
|
|
||
| const TABLE_DRAG_STATE_PLUGIN_KEY = new PluginKey("tableDragState"); | ||
|
|
||
| export const updateTransactionMeta = (tr: Transaction, hiddenCellPositions: number[] | null) => { | ||
| tr.setMeta(TABLE_DRAG_STATE_PLUGIN_KEY, hiddenCellPositions); | ||
| }; | ||
|
|
||
| /** | ||
| * @description Plugin to manage table drag state using decorations. | ||
| * This allows hiding cell content during drag operations without modifying the document. | ||
| * Decorations are local to each user and not persisted or shared. | ||
| */ | ||
| export const TableDragStatePlugin = new Plugin({ | ||
| key: TABLE_DRAG_STATE_PLUGIN_KEY, | ||
| state: { | ||
| init() { | ||
| return DecorationSet.empty; | ||
| }, | ||
| apply(tr, oldState) { | ||
| // Get metadata about which cells to hide | ||
| const hiddenCellPositions = tr.getMeta(TABLE_DRAG_STATE_PLUGIN_KEY) as number[] | null; | ||
|
|
||
| if (hiddenCellPositions === undefined) { | ||
| // No change, map decorations through the transaction | ||
| return oldState.map(tr.mapping, tr.doc); | ||
| } | ||
|
|
||
| if (hiddenCellPositions === null || !Array.isArray(hiddenCellPositions) || hiddenCellPositions.length === 0) { | ||
| // Clear all decorations | ||
| return DecorationSet.empty; | ||
| } | ||
|
|
||
| // Create decorations for hidden cells | ||
| const decorations: Decoration[] = []; | ||
| hiddenCellPositions.forEach((pos) => { | ||
| if (typeof pos !== "number") return; | ||
| const node = tr.doc.nodeAt(pos); | ||
| if (node) { | ||
| decorations.push( | ||
| Decoration.node(pos, pos + node.nodeSize, { | ||
| class: "content-hidden", | ||
| }) | ||
| ); | ||
| } | ||
| }); | ||
|
|
||
| return DecorationSet.create(tr.doc, decorations); | ||
| }, | ||
| }, | ||
| props: { | ||
| decorations(state) { | ||
| return this.getState(state); | ||
| }, | ||
| }, | ||
| }); |
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
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
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
Oops, something went wrong.
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.
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.
showCellContentsetsCORE_EDITOR_META.ADD_TO_HISTORYtotrue, whereashideCellContentsets it tofalseand the previousupdateCellContentVisibilityhelper always disabled history for these drag-only visibility changes. This makes the "show" operation behave differently from the previous implementation and from the "hide" operation, and may cause purely visual decoration updates to be recorded in the undo history. To keep drag-preview visibility changes invisible to undo/redo (as before), consider settingADD_TO_HISTORYtofalsehere as well.