Add historyCurrentStep to setHistory event
This commit is contained in:
parent
749609f9a0
commit
7a81bbaec6
3 changed files with 14 additions and 10 deletions
|
@ -261,11 +261,14 @@
|
||||||
* @param history Whole history of the editor
|
* @param history Whole history of the editor
|
||||||
* @param callback (optional)
|
* @param callback (optional)
|
||||||
*/
|
*/
|
||||||
public SetHistory(history: IHistoryState[], callback?: (state: IEditorState) => void) {
|
public SetHistory(
|
||||||
|
{ history, historyCurrentStep }: { history: IHistoryState[], historyCurrentStep?: number},
|
||||||
|
callback?: (state: IEditorState) => void
|
||||||
|
): void {
|
||||||
const eventType = 'setHistory';
|
const eventType = 'setHistory';
|
||||||
this.app.AddEventListener(eventType, callback);
|
this.app.AddEventListener(eventType, callback);
|
||||||
const component = this.GetEditorComponent();
|
const component = this.GetEditorComponent();
|
||||||
component.dispatchEvent(new CustomEvent(eventType, { detail: history }));
|
component.dispatchEvent(new CustomEvent(eventType, { detail: { history, historyCurrentStep }}));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -158,7 +158,7 @@ function UseCustomEvents(
|
||||||
historyCurrentStep: number,
|
historyCurrentStep: number,
|
||||||
configuration: IConfiguration,
|
configuration: IConfiguration,
|
||||||
editorRef: React.RefObject<HTMLDivElement>,
|
editorRef: React.RefObject<HTMLDivElement>,
|
||||||
setNewHistory: (newHistory: IHistoryState[]) => void
|
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void
|
||||||
): void {
|
): void {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const editorState: IEditorState = {
|
const editorState: IEditorState = {
|
||||||
|
@ -219,10 +219,10 @@ function UseEditorListener(
|
||||||
function UseNewHistoryState(
|
function UseNewHistoryState(
|
||||||
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
|
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
|
||||||
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
|
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
|
||||||
): (newHistory: IHistoryState[]) => void {
|
): (newHistory: IHistoryState[], historyCurrentStep?: number) => void {
|
||||||
return (newHistory) => {
|
return (newHistory, historyCurrentStep?: number) => {
|
||||||
setHistory(newHistory);
|
setHistory(newHistory);
|
||||||
setHistoryCurrentStep(newHistory.length - 1);
|
setHistoryCurrentStep(historyCurrentStep !== undefined && historyCurrentStep !== null ? historyCurrentStep : newHistory.length - 1);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -12,7 +12,7 @@ export interface IEditorEvent {
|
||||||
func: (
|
func: (
|
||||||
root: Element | Document,
|
root: Element | Document,
|
||||||
editorState: IEditorState,
|
editorState: IEditorState,
|
||||||
setNewHistory: (newHistory: IHistoryState[]) => void,
|
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void,
|
||||||
eventInitDict?: CustomEventInit
|
eventInitDict?: CustomEventInit
|
||||||
) => void
|
) => void
|
||||||
}
|
}
|
||||||
|
@ -50,11 +50,12 @@ function GetEditorStateAsString(root: Element | Document,
|
||||||
|
|
||||||
function SetHistory(root: Element | Document,
|
function SetHistory(root: Element | Document,
|
||||||
editorState: IEditorState,
|
editorState: IEditorState,
|
||||||
setNewHistory: (newHistory: IHistoryState[]) => void,
|
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void,
|
||||||
eventInitDict?: CustomEventInit): void {
|
eventInitDict?: CustomEventInit): void {
|
||||||
const history: IHistoryState[] = eventInitDict?.detail;
|
const history: IHistoryState[] = eventInitDict?.detail.history;
|
||||||
|
const historyCurrentStep: number | undefined = eventInitDict?.detail.historyCurrentStep;
|
||||||
ReviveHistoryAction(history);
|
ReviveHistoryAction(history);
|
||||||
setNewHistory(history);
|
setNewHistory(history, historyCurrentStep);
|
||||||
const customEvent = new CustomEvent<IEditorState>('setHistory', { detail: editorState });
|
const customEvent = new CustomEvent<IEditorState>('setHistory', { detail: editorState });
|
||||||
root.dispatchEvent(customEvent);
|
root.dispatchEvent(customEvent);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue