diff --git a/public/smartcomponent/svg-layout-designer.ts b/public/smartcomponent/svg-layout-designer.ts index f345089..5cf900d 100644 --- a/public/smartcomponent/svg-layout-designer.ts +++ b/public/smartcomponent/svg-layout-designer.ts @@ -261,11 +261,14 @@ * @param history Whole history of the editor * @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'; this.app.AddEventListener(eventType, callback); const component = this.GetEditorComponent(); - component.dispatchEvent(new CustomEvent(eventType, { detail: history })); + component.dispatchEvent(new CustomEvent(eventType, { detail: { history, historyCurrentStep }})); } /** diff --git a/src/Components/Editor/Editor.tsx b/src/Components/Editor/Editor.tsx index ad80274..11aabd2 100644 --- a/src/Components/Editor/Editor.tsx +++ b/src/Components/Editor/Editor.tsx @@ -158,7 +158,7 @@ function UseCustomEvents( historyCurrentStep: number, configuration: IConfiguration, editorRef: React.RefObject, - 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>, setHistoryCurrentStep: Dispatch> -): (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); }; } diff --git a/src/Events/EditorEvents.ts b/src/Events/EditorEvents.ts index e1c2143..aa90c79 100644 --- a/src/Events/EditorEvents.ts +++ b/src/Events/EditorEvents.ts @@ -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('setHistory', { detail: editorState }); root.dispatchEvent(customEvent); }