refactor(editor): history as a store extension (#12214)

<!-- This is an auto-generated comment: release notes by coderabbit.ai -->

## Summary by CodeRabbit

- **Refactor**
  - Improved history and undo/redo management across the app by introducing a dedicated history extension. Undo/redo operations now use a more focused undo manager, resulting in clearer and more consistent behavior.
- **Documentation**
  - Updated API documentation to reflect changes in history management, including revised method signatures and removal of outdated event references.

<!-- end of auto-generated comment: release notes by coderabbit.ai -->
This commit is contained in:
Saul-Mirone
2025-05-12 01:50:57 +00:00
parent e91e0e1812
commit 6fb7f51ea2
16 changed files with 124 additions and 78 deletions
@@ -411,7 +411,7 @@ export class CodeBlockComponent extends CaptionedBlockComponent<CodeBlockModel>
})}
.yText=${this.model.props.text.yText}
.inlineEventSource=${this.topContenteditableElement ?? nothing}
.undoManager=${this.store.history}
.undoManager=${this.store.history.undoManager}
.attributesSchema=${this.inlineManager.getSchema()}
.attributeRenderer=${this.inlineManager.getRenderer()}
.readonly=${this.store.readonly}
@@ -185,7 +185,7 @@ export class ListBlockComponent extends CaptionedBlockComponent<ListBlockModel>
<rich-text
.yText=${this.model.props.text.yText}
.inlineEventSource=${this.topContenteditableElement ?? nothing}
.undoManager=${this.store.history}
.undoManager=${this.store.history.undoManager}
.attributeRenderer=${this.attributeRenderer}
.attributesSchema=${this.attributesSchema}
.markdownMatches=${this.inlineManager?.markdownMatches}
@@ -293,7 +293,7 @@ export class ParagraphBlockComponent extends CaptionedBlockComponent<ParagraphBl
<rich-text
.yText=${this.model.props.text.yText}
.inlineEventSource=${this.topContenteditableElement ?? nothing}
.undoManager=${this.store.history}
.undoManager=${this.store.history.undoManager}
.attributesSchema=${this.attributesSchema}
.attributeRenderer=${this.attributeRenderer}
.markdownMatches=${this.inlineManager?.markdownMatches}
@@ -210,7 +210,7 @@ export class DocTitle extends WithDisposable(ShadowlessElement) {
>
<rich-text
.yText=${this._rootModel?.props.title.yText}
.undoManager=${this.doc.history}
.undoManager=${this.doc.history.undoManager}
.verticalScrollContainerGetter=${() => this._viewport}
.readonly=${this.doc.readonly}
.enableFormat=${false}
@@ -89,14 +89,14 @@ function notifyWithUndoActionImpl(
options.abort?.addEventListener('abort', abort);
const clearOnClose = () => {
store.history.off('stack-item-added', addHandler);
store.history.off('stack-item-popped', popHandler);
store.history.undoManager.off('stack-item-added', addHandler);
store.history.undoManager.off('stack-item-popped', popHandler);
disposable.unsubscribe();
options.abort?.removeEventListener('abort', abort);
};
const addHandler = store.history.on('stack-item-added', abort);
const popHandler = store.history.on('stack-item-popped', abort);
const addHandler = store.history.undoManager.on('stack-item-added', abort);
const popHandler = store.history.undoManager.on('stack-item-popped', abort);
const disposable = provider
.get(EditorLifeCycleExtension)
.slots.unmounted.subscribe(() => abort());
@@ -59,7 +59,7 @@ abstract class ToolbarContextBase {
}
get history() {
return this.store.history;
return this.store.history.undoManager;
}
get view() {