Global document undo manager

I’d like to reset a Y.Doc to a previous state. My understanding is that I have to use an undo manager, but it seems to always be scoped to some shared types. In my case, I don’t know anything about the structure of the document. Is there a way for the undo manager to be globally scoped to the document?

I recommend that you know about the structure of the Y.Doc. Having “root-level” types with non-static names almost always has bad side effects. They should be know at “compile-time” (as far as that applies to JavaScript).

Nevertheless, you can implement what you are looking for. You could extract all the available types by doing Array.from(ydoc.share.keys()). Note that any root-level type added after initializing the undo-manager must be added manually.

Also, note that you can’t remove root-level types. Once they are initialized, you can only delete all their content. Root-level types are meant to be static.

The structure of the Y.Doc is static and well defined, I just want a mechanism to reset the document to a previous state, which is agnostic to the document. To give some context, I’m working on this suggestion system, where a fork of a document is created. If the suggestions are not merged back to the root document, I want to reset the document to its pre-fork state.
Thanks for the solution, I’ll try that. I’m wondering if that will work with nested shared types? Also, do shared types support multiple undo managers at the same time?