Move ReviveEditor and ReviveHistory to App
This commit is contained in:
parent
8962132a4d
commit
fb6bc1289d
3 changed files with 55 additions and 53 deletions
|
@ -152,6 +152,32 @@
|
||||||
const component = this.GetAppComponent();
|
const component = this.GetAppComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: isLoaded }))
|
component.dispatchEvent(new CustomEvent(eventType, { detail: isLoaded }))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revive the references in the editor state by mutation
|
||||||
|
* Useful after using JSON.stringify with a replacer
|
||||||
|
* @param editorState Editor state to revive
|
||||||
|
* @param callback Callback with the revived state
|
||||||
|
*/
|
||||||
|
public ReviveEditorState(editorState: IEditorState, callback: (state: IEditorState) => void) {
|
||||||
|
const eventType = 'reviveEditorState';
|
||||||
|
this.app.AddEventListener(eventType, callback);
|
||||||
|
const component = this.GetAppComponent();
|
||||||
|
component.dispatchEvent(new CustomEvent(eventType, { detail: editorState }));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Revive the references in the history by mutation
|
||||||
|
* Useful after using JSON.stringify with a replacer
|
||||||
|
* @param history History to revive
|
||||||
|
* @param callback Callback with the revived state
|
||||||
|
*/
|
||||||
|
public ReviveHistory(history: IHistoryState[], callback: (state: IHistoryState[]) => void) {
|
||||||
|
const eventType = 'reviveHistory';
|
||||||
|
this.app.AddEventListener(eventType, callback);
|
||||||
|
const component = this.GetAppComponent();
|
||||||
|
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -227,32 +253,6 @@
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* Revive the references in the editor state by mutation
|
|
||||||
* Useful after using JSON.stringify with a replacer
|
|
||||||
* @param editorState Editor state to revive
|
|
||||||
* @param callback Callback with the revived state
|
|
||||||
*/
|
|
||||||
public ReviveEditorState(editorState: IEditorState, callback: (state: IEditorState) => void) {
|
|
||||||
const eventType = 'reviveEditorState';
|
|
||||||
this.app.AddEventListener(eventType, callback);
|
|
||||||
const component = this.GetEditorComponent();
|
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: editorState }));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Revive the references in the history by mutation
|
|
||||||
* Useful after using JSON.stringify with a replacer
|
|
||||||
* @param history History to revive
|
|
||||||
* @param callback Callback with the revived state
|
|
||||||
*/
|
|
||||||
public ReviveHistory(history: IHistoryState[], callback: (state: IHistoryState[]) => void) {
|
|
||||||
const eventType = 'reviveHistory';
|
|
||||||
this.app.AddEventListener(eventType, callback);
|
|
||||||
const component = this.GetEditorComponent();
|
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add a new state to the editor
|
* Add a new state to the editor
|
||||||
* @param historyState New history state to append
|
* @param historyState New history state to append
|
||||||
|
|
|
@ -1,4 +1,6 @@
|
||||||
import { IEditorState } from '../Interfaces/IEditorState';
|
import { IEditorState } from '../Interfaces/IEditorState';
|
||||||
|
import { IHistoryState } from '../Interfaces/IHistoryState';
|
||||||
|
import { Revive, ReviveHistory as ReviveHistoryAction } from '../utils/saveload';
|
||||||
|
|
||||||
export interface IAppEvent {
|
export interface IAppEvent {
|
||||||
name: string
|
name: string
|
||||||
|
@ -12,7 +14,9 @@ export interface IAppEvent {
|
||||||
|
|
||||||
export const events: IAppEvent[] = [
|
export const events: IAppEvent[] = [
|
||||||
{ name: 'setEditor', func: SetEditor },
|
{ name: 'setEditor', func: SetEditor },
|
||||||
{ name: 'setLoaded', func: SetLoaded }
|
{ name: 'setLoaded', func: SetLoaded },
|
||||||
|
{ name: 'reviveEditorState', func: ReviveEditorState },
|
||||||
|
{ name: 'reviveHistory', func: ReviveHistory }
|
||||||
];
|
];
|
||||||
|
|
||||||
function SetEditor(
|
function SetEditor(
|
||||||
|
@ -36,3 +40,25 @@ function SetLoaded(
|
||||||
const isLoaded: boolean = eventInitDict?.detail;
|
const isLoaded: boolean = eventInitDict?.detail;
|
||||||
setLoaded(isLoaded);
|
setLoaded(isLoaded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function ReviveEditorState(
|
||||||
|
root: Element | Document,
|
||||||
|
setEditor: (newState: IEditorState) => void,
|
||||||
|
setLoaded: (loaded: boolean) => void,
|
||||||
|
eventInitDict?: CustomEventInit): 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,
|
||||||
|
setLoaded: (loaded: boolean) => void,
|
||||||
|
eventInitDict?: CustomEventInit): void {
|
||||||
|
const history: IHistoryState[] = eventInitDict?.detail;
|
||||||
|
ReviveHistoryAction(history);
|
||||||
|
const customEvent = new CustomEvent<IHistoryState[]>('reviveHistory', { detail: history });
|
||||||
|
root.dispatchEvent(customEvent);
|
||||||
|
}
|
||||||
|
|
|
@ -5,7 +5,7 @@ import { GetCurrentHistory } from '../Components/Editor/Editor';
|
||||||
import { IEditorState } from '../Interfaces/IEditorState';
|
import { IEditorState } from '../Interfaces/IEditorState';
|
||||||
import { IHistoryState } from '../Interfaces/IHistoryState';
|
import { IHistoryState } from '../Interfaces/IHistoryState';
|
||||||
import { FindContainerById } from '../utils/itertools';
|
import { FindContainerById } from '../utils/itertools';
|
||||||
import { GetCircularReplacer, Revive, ReviveHistory as ReviveHistoryAction } from '../utils/saveload';
|
import { GetCircularReplacer, ReviveHistory as ReviveHistoryAction } from '../utils/saveload';
|
||||||
|
|
||||||
export interface IEditorEvent {
|
export interface IEditorEvent {
|
||||||
name: string
|
name: string
|
||||||
|
@ -21,8 +21,6 @@ export const events: IEditorEvent[] = [
|
||||||
{ name: 'getEditorState', func: GetEditorState },
|
{ name: 'getEditorState', func: GetEditorState },
|
||||||
{ name: 'getEditorStateAsString', func: GetEditorStateAsString },
|
{ name: 'getEditorStateAsString', func: GetEditorStateAsString },
|
||||||
{ name: 'setHistory', func: SetHistory },
|
{ name: 'setHistory', func: SetHistory },
|
||||||
{ name: 'reviveEditorState', func: ReviveEditorState },
|
|
||||||
{ name: 'reviveHistory', func: ReviveHistory },
|
|
||||||
{ name: 'getCurrentHistoryState', func: GetCurrentHistoryState },
|
{ name: 'getCurrentHistoryState', func: GetCurrentHistoryState },
|
||||||
{ name: 'appendNewState', func: AppendNewState },
|
{ name: 'appendNewState', func: AppendNewState },
|
||||||
{ name: 'addContainer', func: AddContainer },
|
{ name: 'addContainer', func: AddContainer },
|
||||||
|
@ -61,28 +59,6 @@ function SetHistory(root: Element | Document,
|
||||||
root.dispatchEvent(customEvent);
|
root.dispatchEvent(customEvent);
|
||||||
}
|
}
|
||||||
|
|
||||||
function ReviveEditorState(
|
|
||||||
root: Element | Document,
|
|
||||||
editorState: IEditorState,
|
|
||||||
setNewHistory: (newHistory: IHistoryState[]) => void,
|
|
||||||
eventInitDict?: CustomEventInit): void {
|
|
||||||
const anEditorState: IEditorState = eventInitDict?.detail;
|
|
||||||
Revive(anEditorState);
|
|
||||||
const customEvent = new CustomEvent<IEditorState>('reviveEditorState', { detail: anEditorState });
|
|
||||||
root.dispatchEvent(customEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
function ReviveHistory(
|
|
||||||
root: Element | Document,
|
|
||||||
editorState: IEditorState,
|
|
||||||
setNewHistory: (newHistory: IHistoryState[]) => void,
|
|
||||||
eventInitDict?: CustomEventInit): void {
|
|
||||||
const history: IHistoryState[] = eventInitDict?.detail;
|
|
||||||
ReviveHistoryAction(history);
|
|
||||||
const customEvent = new CustomEvent<IHistoryState[]>('reviveHistory', { detail: history });
|
|
||||||
root.dispatchEvent(customEvent);
|
|
||||||
}
|
|
||||||
|
|
||||||
function GetCurrentHistoryState(root: Element | Document,
|
function GetCurrentHistoryState(root: Element | Document,
|
||||||
editorState: IEditorState): void {
|
editorState: IEditorState): void {
|
||||||
const customEvent = new CustomEvent<IHistoryState>(
|
const customEvent = new CustomEvent<IHistoryState>(
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue