Add historyCurrentStep to setHistory event

This commit is contained in:
Eric NGUYEN 2022-10-13 16:18:16 +02:00
parent 749609f9a0
commit 7a81bbaec6
3 changed files with 14 additions and 10 deletions

View file

@ -158,7 +158,7 @@ function UseCustomEvents(
historyCurrentStep: number,
configuration: IConfiguration,
editorRef: React.RefObject<HTMLDivElement>,
setNewHistory: (newHistory: IHistoryState[]) => void
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void
): void {
useEffect(() => {
const editorState: IEditorState = {
@ -219,10 +219,10 @@ function UseEditorListener(
function UseNewHistoryState(
setHistory: Dispatch<SetStateAction<IHistoryState[]>>,
setHistoryCurrentStep: Dispatch<SetStateAction<number>>
): (newHistory: IHistoryState[]) => void {
return (newHistory) => {
): (newHistory: IHistoryState[], historyCurrentStep?: number) => void {
return (newHistory, historyCurrentStep?: number) => {
setHistory(newHistory);
setHistoryCurrentStep(newHistory.length - 1);
setHistoryCurrentStep(historyCurrentStep !== undefined && historyCurrentStep !== null ? historyCurrentStep : newHistory.length - 1);
};
}

View file

@ -12,7 +12,7 @@ export interface IEditorEvent {
func: (
root: Element | Document,
editorState: IEditorState,
setNewHistory: (newHistory: IHistoryState[]) => void,
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void,
eventInitDict?: CustomEventInit
) => void
}
@ -50,11 +50,12 @@ function GetEditorStateAsString(root: Element | Document,
function SetHistory(root: Element | Document,
editorState: IEditorState,
setNewHistory: (newHistory: IHistoryState[]) => void,
setNewHistory: (newHistory: IHistoryState[], historyCurrentStep?: number) => void,
eventInitDict?: CustomEventInit): void {
const history: IHistoryState[] = eventInitDict?.detail;
const history: IHistoryState[] = eventInitDict?.detail.history;
const historyCurrentStep: number | undefined = eventInitDict?.detail.historyCurrentStep;
ReviveHistoryAction(history);
setNewHistory(history);
setNewHistory(history, historyCurrentStep);
const customEvent = new CustomEvent<IEditorState>('setHistory', { detail: editorState });
root.dispatchEvent(customEvent);
}