Implement AddEditorListenerHook + Fix some bugs with types

This commit is contained in:
Eric NGUYEN 2022-09-23 13:49:22 +02:00
parent 3a7c60bd1c
commit 6de2c23989
2 changed files with 61 additions and 4 deletions

View file

@ -152,6 +152,23 @@ function UseCustomEvents(
});
}
function UseEditorListener(
root: Element | Document,
history: IHistoryState[],
historyCurrentStep: number,
configuration: IConfiguration
): void {
useEffect(() => {
const editorState: IEditorState = {
history,
historyCurrentStep,
configuration
};
const event = new CustomEvent('editorListener', { detail: editorState });
root.dispatchEvent(event);
});
}
/**
* Return a macro function to use both setHistory
* and setHistoryCurrentStep at the same time
@ -186,6 +203,12 @@ export function Editor(props: IEditorProps): JSX.Element {
editorRef,
setNewHistory
);
UseEditorListener(
props.root,
history,
historyCurrentStep,
props.configuration
);
// Context Menu
const menuActions = new Map();