Add GetDefaultEditorState to App CustomEvents

This commit is contained in:
Eric NGUYEN 2022-10-13 15:01:38 +02:00
parent a89b92eab8
commit 749609f9a0
2 changed files with 30 additions and 1 deletions

View file

@ -1,5 +1,7 @@
import { IConfiguration } from '../Interfaces/IConfiguration';
import { IEditorState } from '../Interfaces/IEditorState';
import { IHistoryState } from '../Interfaces/IHistoryState';
import { GetDefaultEditorState as GetDefaultEditorStateAction } from '../utils/default';
import { Revive, ReviveHistory as ReviveHistoryAction } from '../utils/saveload';
export interface IAppEvent {
@ -16,7 +18,8 @@ export const events: IAppEvent[] = [
{ name: 'setEditor', func: SetEditor },
{ name: 'setLoaded', func: SetLoaded },
{ name: 'reviveEditorState', func: ReviveEditorState },
{ name: 'reviveHistory', func: ReviveHistory }
{ name: 'reviveHistory', func: ReviveHistory },
{ name: 'getDefaultEditorState', func: GetDefaultEditorState }
];
function SetEditor(
@ -62,3 +65,14 @@ function ReviveHistory(
const customEvent = new CustomEvent<IHistoryState[]>('reviveHistory', { detail: history });
root.dispatchEvent(customEvent);
}
function GetDefaultEditorState(
root: Element | Document,
setEditor: (newState: IEditorState) => void,
setLoaded: (loaded: boolean) => void,
eventInitDict?: CustomEventInit): void {
const configuration: IConfiguration = eventInitDict?.detail;
const editorState = GetDefaultEditorStateAction(configuration);
const customEvent = new CustomEvent<IEditorState>('reviveHistory', { detail: editorState });
root.dispatchEvent(customEvent);
}