0
0
Fork 0
mirror of https://github.com/BookStackApp/BookStack.git synced 2025-04-10 07:17:32 +00:00

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
resources/js/wysiwyg

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(),