-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Migrate undo-manager package to TS #70757
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
Merged
manzoorwanijk
merged 4 commits into
WordPress:trunk
from
dhruvikpatel18:try/convert-undo-manager-ts
Jul 31, 2025
Merged
Changes from 1 commit
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
eae4da5
feat: Migrate undo-manager package to TS
dhruvikpatel18 26ace8a
fix: added explicit type casting for compose package
dhruvikpatel18 5f2a6e5
centralized the types interfaces
dhruvikpatel18 dbfa856
removed restrictions for From and To types
dhruvikpatel18 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
centralized the types interfaces
- Loading branch information
commit 5f2a6e54aaff89a5b4d601ff29458086b5da7282
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,19 +1,65 @@ | ||
| export type HistoryChange = { | ||
| from: any; | ||
| to: any; | ||
| }; | ||
| /** | ||
| * Represents a single change in history. | ||
| */ | ||
| export interface HistoryChange< T = unknown > { | ||
| /** The previous value */ | ||
| from: T; | ||
| /** The new value */ | ||
| to: T; | ||
| } | ||
|
|
||
| export type HistoryChanges = { | ||
| id: string | Record< string, any >; | ||
| changes: Record< string, HistoryChange >; | ||
| }; | ||
| /** | ||
| * Represents changes for a single item. | ||
| */ | ||
| export interface HistoryChanges< T = unknown > { | ||
| /** The identifier for the item being changed */ | ||
| id: string | Record< string, unknown >; | ||
| /** The changes made to the item */ | ||
| changes: Record< string, HistoryChange< T > >; | ||
| } | ||
|
|
||
| export type HistoryRecord = Array< HistoryChanges >; | ||
| /** | ||
| * Represents a record of history changes. | ||
| */ | ||
| export type HistoryRecord< T = unknown > = HistoryChanges< T >[]; | ||
|
|
||
| export type UndoManager = { | ||
| addRecord: ( record: HistoryRecord, isStaged: boolean ) => void; | ||
| undo: () => HistoryRecord | undefined; | ||
| redo: () => HistoryRecord | undefined; | ||
| /** | ||
| * The undo manager interface. | ||
| */ | ||
| export interface UndoManager< T = unknown > { | ||
| /** | ||
| * Record changes into the history. | ||
| * | ||
| * @param record A record of changes to record. | ||
| * @param isStaged Whether to immediately create an undo point or not. | ||
| */ | ||
| addRecord: ( record?: HistoryRecord< T >, isStaged?: boolean ) => void; | ||
|
|
||
| /** | ||
| * Undo the last recorded changes. | ||
| * | ||
| * @return The undone record or undefined if nothing to undo. | ||
| */ | ||
| undo: () => HistoryRecord< T > | undefined; | ||
|
|
||
| /** | ||
| * Redo the last undone changes. | ||
| * | ||
| * @return The redone record or undefined if nothing to redo. | ||
| */ | ||
| redo: () => HistoryRecord< T > | undefined; | ||
|
|
||
| /** | ||
| * Check if there are changes that can be undone. | ||
| * | ||
| * @return Whether there are changes to undo. | ||
| */ | ||
| hasUndo: () => boolean; | ||
|
|
||
| /** | ||
| * Check if there are changes that can be redone. | ||
| * | ||
| * @return Whether there are changes to redo. | ||
| */ | ||
| hasRedo: () => boolean; | ||
| }; | ||
| } | ||
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.
Isn't it possible that
fromandtocan be of different type?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.
Yes it is possible, have changed the interface to allow
fromandtoto be different types.