Lexical: Linked up change/draft management
This commit is contained in:
parent
d86837ac07
commit
fe05cff64f
|
@ -58,8 +58,21 @@ export function createPageEditorInstance(container: HTMLElement, htmlContent: st
|
||||||
if (debugView) {
|
if (debugView) {
|
||||||
debugView.hidden = true;
|
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) {
|
if (debugView) {
|
||||||
debugView.textContent = JSON.stringify(editorState.toJSON(), null, 2);
|
debugView.textContent = JSON.stringify(editorState.toJSON(), null, 2);
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
|
|
||||||
## In progress
|
## In progress
|
||||||
|
|
||||||
- Draft/change management (connect with page editor component)
|
//
|
||||||
|
|
||||||
## Main Todo
|
## Main Todo
|
||||||
|
|
||||||
|
|
|
@ -175,7 +175,6 @@ export class EditorUIManager {
|
||||||
protected setupEditor(editor: LexicalEditor) {
|
protected setupEditor(editor: LexicalEditor) {
|
||||||
// Update button states on editor selection change
|
// Update button states on editor selection change
|
||||||
editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
editor.registerCommand(SELECTION_CHANGE_COMMAND, () => {
|
||||||
console.log('select change', arguments);
|
|
||||||
this.triggerStateUpdate({
|
this.triggerStateUpdate({
|
||||||
editor: editor,
|
editor: editor,
|
||||||
selection: $getSelection(),
|
selection: $getSelection(),
|
||||||
|
|
Loading…
Reference in New Issue