Merge branch 'dev' into dev.loading
This commit is contained in:
commit
0ac42b3500
41 changed files with 1609 additions and 1241 deletions
|
@ -3,17 +3,22 @@ import { AppState } from '../Enums/AppState';
|
|||
import { IConfiguration } from '../Interfaces/IConfiguration';
|
||||
import { IEditorState } from '../Interfaces/IEditorState';
|
||||
import { IHistoryState } from '../Interfaces/IHistoryState';
|
||||
import { ILanguage } from '../Interfaces/ILanguage';
|
||||
import { languageOptions, translations } from '../Translations/Translations';
|
||||
import { GetDefaultEditorState as GetDefaultEditorStateAction } from '../utils/default';
|
||||
import { Revive, ReviveHistory as ReviveHistoryAction } from '../utils/saveload';
|
||||
|
||||
interface IAppEventParams {
|
||||
root: Element | Document
|
||||
languageContext: ILanguage
|
||||
setEditor: (newState: IEditorState) => void
|
||||
setAppState: (appState: AppState) => void
|
||||
eventInitDict?: CustomEventInit
|
||||
}
|
||||
|
||||
export interface IAppEvent {
|
||||
name: string
|
||||
func: (
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
setAppState: (appState: AppState) => void,
|
||||
eventInitDict?: CustomEventInit
|
||||
) => void
|
||||
func: (params: IAppEventParams) => void
|
||||
}
|
||||
|
||||
export const events: IAppEvent[] = [
|
||||
|
@ -21,12 +26,16 @@ export const events: IAppEvent[] = [
|
|||
{ name: 'setAppState', func: SetAppState },
|
||||
{ name: 'reviveEditorState', func: ReviveEditorState },
|
||||
{ name: 'reviveHistory', func: ReviveHistory },
|
||||
{ name: 'getDefaultEditorState', func: GetDefaultEditorState }
|
||||
{ name: 'getDefaultEditorState', func: GetDefaultEditorState },
|
||||
{ name: 'addLanguage', func: AddLanguage },
|
||||
{ name: 'setLanguage', func: SetLanguage },
|
||||
{ name: 'getLanguages', func: GetLanguages }
|
||||
];
|
||||
|
||||
export function UseCustomEvents(
|
||||
root: Element | Document,
|
||||
appRef: React.RefObject<HTMLDivElement>,
|
||||
languageContext: ILanguage,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
setAppState: (appState: AppState) => void
|
||||
): void {
|
||||
|
@ -34,12 +43,13 @@ export function UseCustomEvents(
|
|||
const funcs = new Map<string, () => void>();
|
||||
for (const event of events) {
|
||||
function Func(eventInitDict?: CustomEventInit): void {
|
||||
return event.func(
|
||||
return event.func({
|
||||
root,
|
||||
languageContext,
|
||||
setEditor,
|
||||
setAppState,
|
||||
eventInitDict
|
||||
);
|
||||
});
|
||||
}
|
||||
appRef.current?.addEventListener(event.name, Func);
|
||||
funcs.set(event.name, Func);
|
||||
|
@ -56,12 +66,12 @@ export function UseCustomEvents(
|
|||
});
|
||||
}
|
||||
|
||||
function SetEditor(
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
setAppState: (appState: AppState) => void,
|
||||
eventInitDict?: CustomEventInit
|
||||
): void {
|
||||
function SetEditor({
|
||||
root,
|
||||
setEditor,
|
||||
setAppState,
|
||||
eventInitDict
|
||||
}: IAppEventParams): void {
|
||||
const editor: IEditorState = eventInitDict?.detail;
|
||||
setEditor(editor);
|
||||
setAppState(AppState.Loading);
|
||||
|
@ -69,45 +79,74 @@ function SetEditor(
|
|||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
function SetAppState(
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
setAppState: (appState: AppState) => void,
|
||||
eventInitDict?: CustomEventInit
|
||||
): void {
|
||||
function SetAppState({
|
||||
setAppState,
|
||||
eventInitDict
|
||||
}: IAppEventParams): void {
|
||||
const appState: AppState = eventInitDict?.detail;
|
||||
setAppState(appState);
|
||||
}
|
||||
|
||||
function ReviveEditorState(
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
setAppState: (appState: AppState) => void,
|
||||
eventInitDict?: CustomEventInit): void {
|
||||
function ReviveEditorState({
|
||||
root,
|
||||
eventInitDict
|
||||
}: IAppEventParams): void {
|
||||
const anEditorState: IEditorState = eventInitDict?.detail;
|
||||
Revive(anEditorState);
|
||||
const customEvent = new CustomEvent<IEditorState>('reviveEditorState', { detail: anEditorState });
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
function ReviveHistory(
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
setAppState: (appState: AppState) => void,
|
||||
eventInitDict?: CustomEventInit): void {
|
||||
function ReviveHistory({
|
||||
root,
|
||||
eventInitDict
|
||||
}: IAppEventParams): void {
|
||||
const history: IHistoryState[] = eventInitDict?.detail;
|
||||
ReviveHistoryAction(history);
|
||||
const customEvent = new CustomEvent<IHistoryState[]>('reviveHistory', { detail: history });
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
function GetDefaultEditorState(
|
||||
root: Element | Document,
|
||||
setEditor: (newState: IEditorState) => void,
|
||||
setAppState: (appState: AppState) => void,
|
||||
eventInitDict?: CustomEventInit): void {
|
||||
function GetDefaultEditorState({
|
||||
root,
|
||||
eventInitDict
|
||||
}: IAppEventParams): void {
|
||||
const configuration: IConfiguration = eventInitDict?.detail;
|
||||
const editorState = GetDefaultEditorStateAction(configuration);
|
||||
const customEvent = new CustomEvent<IEditorState>('getDefaultEditorState', { detail: editorState });
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
function AddLanguage({
|
||||
root,
|
||||
eventInitDict
|
||||
}: IAppEventParams): void {
|
||||
const language: ILanguage = eventInitDict?.detail.language;
|
||||
const option: string = eventInitDict?.detail.option;
|
||||
languageOptions[language.language] = option;
|
||||
translations[language.language] = language.dictionary;
|
||||
const customEvent = new CustomEvent('addLanguage');
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
function SetLanguage({
|
||||
root,
|
||||
languageContext,
|
||||
eventInitDict
|
||||
}: IAppEventParams): void {
|
||||
const language: string = eventInitDict?.detail;
|
||||
let success = false;
|
||||
if (languageContext.languageChange !== undefined) {
|
||||
languageContext.languageChange(language);
|
||||
success = true;
|
||||
}
|
||||
const customEvent = new CustomEvent<boolean>('setLanguage', { detail: success });
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
||||
function GetLanguages({
|
||||
root
|
||||
}: IAppEventParams): void {
|
||||
const customEvent = new CustomEvent<Record<string, Record<string, string>>>('getLanguages', { detail: translations });
|
||||
root.dispatchEvent(customEvent);
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import { IHistoryState } from '../Interfaces/IHistoryState';
|
|||
import { FindContainerById } from '../utils/itertools';
|
||||
import { GetCircularReplacer } from '../utils/saveload';
|
||||
|
||||
// TODO: set the params of func in an interface
|
||||
export interface IEditorEvent {
|
||||
name: string
|
||||
func: (
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue