diff --git a/src/Components/App/App.tsx b/src/Components/App/App.tsx index 88eb9ee..ef86b3c 100644 --- a/src/Components/App/App.tsx +++ b/src/Components/App/App.tsx @@ -1,5 +1,5 @@ import React, { Dispatch, SetStateAction, useCallback, useEffect, useRef, useState } from 'react'; -import { events as EVENTS, UseCustomEvents } from '../../Events/AppEvents'; +import { UseCustomEvents } from '../../Events/AppEvents'; import { MainMenu } from '../MainMenu/MainMenu'; import { ContainerModel, IContainerModel } from '../../Interfaces/IContainerModel'; import { Editor } from '../Editor/Editor'; diff --git a/src/Components/Editor/Actions/AddContainer.ts b/src/Components/Editor/Actions/AddContainer.ts index 0bfd0e9..b50babb 100644 --- a/src/Components/Editor/Actions/AddContainer.ts +++ b/src/Components/Editor/Actions/AddContainer.ts @@ -27,21 +27,15 @@ import { SortChildren } from './ContainerOperations'; */ export function AddContainerToSelectedContainer( type: string, - selected: IContainerModel | undefined, + selected: IContainerModel, configuration: IConfiguration, fullHistory: IHistoryState[], historyCurrentStep: number -): IHistoryState[] | null { - if (selected === null || - selected === undefined) { - return null; - } - - const parent = selected; +): IHistoryState[] { return AddContainer( - parent.children.length, + selected.children.length, type, - parent.properties.id, + selected.properties.id, configuration, fullHistory, historyCurrentStep diff --git a/src/Components/Editor/Editor.tsx b/src/Components/Editor/Editor.tsx index 7707608..372ab06 100644 --- a/src/Components/Editor/Editor.tsx +++ b/src/Components/Editor/Editor.tsx @@ -140,16 +140,17 @@ export function Editor(props: IEditorProps): JSX.Element { historyCurrentStep ))} addContainer={(type) => { - const newHistory = AddContainerToSelectedContainer( + if (selected === null || selected === undefined) { + return; + } + + setNewHistory(AddContainerToSelectedContainer( type, selected, configuration, history, historyCurrentStep - ); - if (newHistory !== null) { - setNewHistory(newHistory); - } + )); }} addContainerAt={(index, type, parent) => setNewHistory( AddContainer( diff --git a/src/Events/EditorEvents.ts b/src/Events/EditorEvents.ts index 5cb644a..c67fc4c 100644 --- a/src/Events/EditorEvents.ts +++ b/src/Events/EditorEvents.ts @@ -240,20 +240,16 @@ function AppendContainerToSelectedContainer(root: Element | Document, const selected = FindContainerById(currentState.containers, currentState.selectedContainerId); - const newHistory = AddContainerToSelectedContainerAction( - type, - selected, - editorState.configuration, - history, - editorState.historyCurrentStep - ); - - if (newHistory === null) { - return; + if (selected !== null && selected !== undefined) { + setNewHistory(AddContainerToSelectedContainerAction( + type, + selected, + editorState.configuration, + history, + editorState.historyCurrentStep + )); } - setNewHistory(newHistory); - const customEvent = new CustomEvent( 'appendContainerToSelectedContainer', { detail: structuredClone(editorState.history[editorState.historyCurrentStep]) });