-
Notifications
You must be signed in to change notification settings - Fork 4.2k
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
Extract undo/redo as a separate package #54292
Conversation
Size Change: -3.35 kB (0%) Total Size: 1.52 MB
ℹ️ View Unchanged
|
Ok This should be ready now, I addressed all the edge cases that were causing some e2e test failures. |
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.
I'm not sure if we should do this extraction now. With collaborative editing starting we need an undo solution that works well with multiple authors potentially changing multiple documents. So undo will probably use something like yjs-undo-manager or multi-document undo manager bellow. If we can use one of these solutions maybe we don't necessarily need to expose anything for now.
@jorgefilipecosta that is a good point and I've actually thought about it, that said, I think regardless of whether we need a different undo/redo manager once we have collaborative editing, I think this API is good for third-party editors and we may end up having two different undo/redo managers depending on the use-case. I'll probably make this package "bundled" to start with to avoid any WP public API. |
Yes, I understand the block editor as a framework needs to have undo even in simple solutions where we don't have collaborative editing and things like that. My expectation would be that even in a simple case we can use one of the third-party undo solutions for consistency and maintainability. And in a simple case one non-sync document, one user, the third-party solutions would still work. But we don't know the future and if we can get away with just a single thrid-party undo manager our undo manager may become a wrapper of another solution in that case. |
The goal here is to open some possibilities for third-party users. So we don't want new APIs for WordPress, I made this a "bundled" package now. cc @ellatrix @jorgefilipecosta |
Co-authored-by: Ella <[email protected]>
Right, but wouldn't it be better to start with exposing the wrapper then, and if they need a lower level API, expose this? |
@ellatrix For npm developers it's totally ok to have both APIs, I don't see any downsides. For WordPress less so, so I made the package private (bundled) for now. |
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.
For me this is good, at the very least the separation makes it easier to understand what's going on with undo/redo, so that's valuable.
Related #53874
One piece of feedback we've received regardless of third-party block editors is that they have to recreate undo/redo behavior on their own. This PR is the first step to help them do that without writing too much code. Basically here, I'm extracting the undo/redo manager from the reducer of "core-data" into a new dedicated package.
I think the best way to understand how to use this package is to check its unit tests. It's something like:
The next step for me is going to be to write a React hook around this undo/redo manager, something like that:
Testing instructions