Lexical: Linked up change/draft management

This commit is contained in:
Dan Brown 2024-07-29 21:43:20 +01:00
parent d86837ac07
commit fe05cff64f
No known key found for this signature in database
GPG Key ID: 46D9F943C24A2EF9
3 changed files with 16 additions and 4 deletions

View File

@ -58,8 +58,21 @@ export function createPageEditorInstance(container: HTMLElement, htmlContent: st
if (debugView) {
debugView.hidden = true;
}
editor.registerUpdateListener(({editorState}) => {
console.log('editorState', editorState.toJSON());
let changeFromLoading = true;
editor.registerUpdateListener(({editorState, dirtyElements, dirtyLeaves}) => {
// Emit change event to component system (for draft detection) on actual user content change
if (dirtyElements.size > 0 || dirtyLeaves.size > 0) {
if (changeFromLoading) {
changeFromLoading = false;
} else {
window.$events.emit('editor-html-change', '');
}
}
// Debug logic
// console.log('editorState', editorState.toJSON());
if (debugView) {
debugView.textContent = JSON.stringify(editorState.toJSON(), null, 2);
}

View File

@ -2,7 +2,7 @@
## In progress
- Draft/change management (connect with page editor component)
//
## Main Todo

View File

@ -175,7 +175,6 @@ export class EditorUIManager {
protected setupEditor(editor: LexicalEditor) {
// Update button states on editor selection change
editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
console.log('select change', arguments);
this.triggerStateUpdate({
editor: editor,
selection: $getSelection(),