Implement setEditor + Add some macros
This commit is contained in:
parent
6de2c23989
commit
2ea43890f0
5 changed files with 142 additions and 13 deletions
25
src/Events/AppEvents.ts
Normal file
25
src/Events/AppEvents.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import { IEditorState } from '../Interfaces/IEditorState';
|
||||
|
||||
export interface IAppEvent {
|
||||
name: string
|
||||
func: (
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
eventInitDict?: CustomEventInit
|
||||
) => void
|
||||
}
|
||||
|
||||
export const events: IAppEvent[] = [
|
||||
{ name: 'setEditor', func: SetEditor }
|
||||
];
|
||||
|
||||
function SetEditor(
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
eventInitDict?: CustomEventInit
|
||||
): void {
|
||||
const editor: IEditorState = eventInitDict?.detail;
|
||||
setEditor(editor);
|
||||
const customEvent = new CustomEvent<IEditorState>('setEditor', { detail: editor });
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
|
@ -19,7 +19,7 @@ export interface IEditorEvent {
|
|||
|
||||
export const events: IEditorEvent[] = [
|
||||
{ name: 'getEditorState', func: GetEditorState },
|
||||
{ name: 'setEditorState', func: SetEditorState },
|
||||
{ name: 'setHistory', func: SetHistory },
|
||||
{ name: 'reviveEditorState', func: ReviveEditorState },
|
||||
{ name: 'reviveHistory', func: ReviveHistory },
|
||||
{ name: 'getCurrentHistoryState', func: GetCurrentHistoryState },
|
||||
|
@ -41,15 +41,14 @@ function GetEditorState(root: Element | Document,
|
|||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
// TODO: In the near future, implement a real SetEditorState which also change IConfiguration
|
||||
function SetEditorState(root: Element | Document,
|
||||
function SetHistory(root: Element | Document,
|
||||
editorState: IEditorState,
|
||||
setNewHistory: (newHistory: IHistoryState[]) => void,
|
||||
eventInitDict?: CustomEventInit): void {
|
||||
const history: IHistoryState[] = eventInitDict?.detail;
|
||||
ReviveHistoryAction(history);
|
||||
setNewHistory(history);
|
||||
const customEvent = new CustomEvent<IEditorState>('setEditorState', { detail: editorState });
|
||||
const customEvent = new CustomEvent<IEditorState>('setHistory', { detail: editorState });
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue