22# Distributed under the terms of the Modified BSD License.
33
44from abc import ABC , abstractmethod
5- from typing import Any , Callable , Dict , Optional
5+ from typing import Any , Callable , Optional
66
7- from pycrdt import Doc , Map , Subscription
7+ from pycrdt import Doc , Map , Subscription , UndoManager
88
99
1010class YBaseDoc (ABC ):
@@ -15,6 +15,11 @@ class YBaseDoc(ABC):
1515 subscribe to changes in the document.
1616 """
1717
18+ _ydoc : Doc
19+ _ystate : Map
20+ _subscriptions : dict [Any , Subscription ]
21+ _undo_manager : UndoManager
22+
1823 def __init__ (self , ydoc : Optional [Doc ] = None ):
1924 """
2025 Constructs a YBaseDoc.
@@ -27,7 +32,8 @@ def __init__(self, ydoc: Optional[Doc] = None):
2732 else :
2833 self ._ydoc = ydoc
2934 self ._ystate = self ._ydoc .get ("state" , type = Map )
30- self ._subscriptions : Dict [Any , Subscription ] = {}
35+ self ._subscriptions = {}
36+ self ._undo_manager = UndoManager (doc = self ._ydoc , capture_timeout_millis = 0 )
3137
3238 @property
3339 @abstractmethod
@@ -40,6 +46,15 @@ def version(self) -> str:
4046 """
4147
4248 @property
49+ def undo_manager (self ) -> UndoManager :
50+ """
51+ A :class:`pycrdt.UndoManager` for the document.
52+
53+ :return: The document's undo manager.
54+ :rtype: :class:`pycrdt.UndoManager`
55+ """
56+ return self ._undo_manager
57+
4358 def ystate (self ) -> Map :
4459 """
4560 A :class:`pycrdt.Map` containing the state of the document.
0 commit comments