diff --git a/src/Components/Editor/ContainerOperations.ts b/src/Components/Editor/ContainerOperations.ts index 8ad34ec..ea4db42 100644 --- a/src/Components/Editor/ContainerOperations.ts +++ b/src/Components/Editor/ContainerOperations.ts @@ -1,4 +1,4 @@ -import React, { Dispatch, SetStateAction } from 'react'; +import { Dispatch, SetStateAction } from 'react'; import { HistoryState } from '../../Interfaces/HistoryState'; import { Configuration } from '../../Interfaces/Configuration'; import { ContainerModel, IContainerModel } from '../../Interfaces/ContainerModel'; @@ -60,7 +60,7 @@ export function DeleteContainer( } if (container === null || container === undefined) { - throw new Error('[DeleteContainer] Container model was not found among children of the main container!'); + throw new Error('[OnPropertyChange] Container model was not found among children of the main container!'); } if (container.parent != null) { @@ -266,76 +266,6 @@ export function OnPropertyChange( setHistoryCurrentStep(history.length); } -/** - * Handled the property change event in the properties form - * @param key Property name - * @param value New value of the property - * @returns void - */ -export function OnPropertiesSubmit( - event: React.SyntheticEvent, - refs: Array>, - fullHistory: HistoryState[], - historyCurrentStep: number, - setHistory: Dispatch>, - setHistoryCurrentStep: Dispatch> -): void { - event.preventDefault(); - const history = getCurrentHistory(fullHistory, historyCurrentStep); - const current = history[history.length - 1]; - - if (current.SelectedContainer === null || - current.SelectedContainer === undefined) { - throw new Error('[OnPropertyChange] Property was changed before selecting a Container'); - } - - if (parent === null) { - const selectedContainerClone: IContainerModel = structuredClone(current.SelectedContainer); - for (const ref of refs) { - const input = ref.current; - if (input instanceof HTMLInputElement) { - (selectedContainerClone.properties as any)[input.id] = input.value; - } - } - setHistory(history.concat([{ - LastAction: 'Change property of main', - MainContainer: selectedContainerClone, - SelectedContainer: selectedContainerClone, - SelectedContainerId: selectedContainerClone.properties.id, - TypeCounters: Object.assign({}, current.TypeCounters) - }])); - setHistoryCurrentStep(history.length); - return; - } - - const mainContainerClone: IContainerModel = structuredClone(current.MainContainer); - const container: ContainerModel | undefined = findContainerById(mainContainerClone, current.SelectedContainer.properties.id); - - if (container === null || container === undefined) { - throw new Error('[OnPropertyChange] Container model was not found among children of the main container!'); - } - - for (const ref of refs) { - const input = ref.current; - if (input instanceof HTMLInputElement) { - (container.properties as any)[input.id] = input.value; - } - } - - if (container.properties.isRigidBody) { - RecalculatePhysics(container); - } - - setHistory(history.concat([{ - LastAction: `Change property of container ${container.properties.id}`, - MainContainer: mainContainerClone, - SelectedContainer: container, - SelectedContainerId: container.properties.id, - TypeCounters: Object.assign({}, current.TypeCounters) - }])); - setHistoryCurrentStep(history.length); -} - // TODO put this in a different file export function RecalculatePhysics(container: IContainerModel): IContainerModel { diff --git a/src/Components/Editor/Editor.tsx b/src/Components/Editor/Editor.tsx index b008607..ad27c22 100644 --- a/src/Components/Editor/Editor.tsx +++ b/src/Components/Editor/Editor.tsx @@ -4,7 +4,7 @@ import { Configuration } from '../../Interfaces/Configuration'; import { SVG } from '../SVG/SVG'; import { HistoryState } from '../../Interfaces/HistoryState'; import { UI } from '../UI/UI'; -import { SelectContainer, DeleteContainer, OnPropertyChange, AddContainerToSelectedContainer, AddContainer, OnPropertiesSubmit } from './ContainerOperations'; +import { SelectContainer, DeleteContainer, OnPropertyChange, AddContainerToSelectedContainer, AddContainer } from './ContainerOperations'; import { SaveEditorAsJSON, SaveEditorAsSVG } from './Save'; import { onKeyDown } from './Shortcuts'; @@ -72,14 +72,6 @@ const Editor: React.FunctionComponent = (props) => { setHistory, setHistoryCurrentStep )} - OnPropertiesSubmit={(event, refs) => OnPropertiesSubmit( - event, - refs, - history, - historyCurrentStep, - setHistory, - setHistoryCurrentStep - )} AddContainerToSelectedContainer={(type) => AddContainerToSelectedContainer( type, configuration, diff --git a/src/Components/ElementsSidebar/ElementsSidebar.tsx b/src/Components/ElementsSidebar/ElementsSidebar.tsx index 96be3fe..873161d 100644 --- a/src/Components/ElementsSidebar/ElementsSidebar.tsx +++ b/src/Components/ElementsSidebar/ElementsSidebar.tsx @@ -14,7 +14,6 @@ interface IElementsSidebarProps { isHistoryOpen: boolean SelectedContainer: IContainerModel | null OnPropertyChange: (key: string, value: string | number | boolean) => void - OnPropertiesSubmit: (event: React.FormEvent, refs: Array>) => void SelectContainer: (container: IContainerModel) => void DeleteContainer: (containerid: string) => void AddContainer: (index: number, type: string, parent: string) => void @@ -146,11 +145,7 @@ export const ElementsSidebar: React.FC = (props: IElement props.DeleteContainer(onClickContainerId); }} /> - + ); }; diff --git a/src/Components/MainMenu/MainMenu.tsx b/src/Components/MainMenu/MainMenu.tsx index 9c8b27f..1d84f9a 100644 --- a/src/Components/MainMenu/MainMenu.tsx +++ b/src/Components/MainMenu/MainMenu.tsx @@ -38,8 +38,13 @@ export const MainMenu: React.FC = (props) => { diff --git a/src/Components/Properties/Properties.tsx b/src/Components/Properties/Properties.tsx index cf87e5b..c1ac966 100644 --- a/src/Components/Properties/Properties.tsx +++ b/src/Components/Properties/Properties.tsx @@ -1,50 +1,25 @@ -import React, { useState } from 'react'; +import * as React from 'react'; import ContainerProperties from '../../Interfaces/Properties'; -import { ToggleButton } from '../ToggleButton/ToggleButton'; import { INPUT_TYPES } from './PropertiesInputTypes'; interface IPropertiesProps { properties?: ContainerProperties onChange: (key: string, value: string | number | boolean) => void - onSubmit: (event: React.FormEvent, refs: Array>) => void } export const Properties: React.FC = (props: IPropertiesProps) => { - const [isDynamicInput, setIsDynamicInput] = useState(false); - if (props.properties === undefined) { return
; } const groupInput: React.ReactNode[] = []; - const refs: Array> = []; Object .entries(props.properties) - .forEach((pair) => handleProperties(pair, groupInput, refs, isDynamicInput, props.onChange)); - - const form = isDynamicInput - ?
- { groupInput } -
- :
props.onSubmit(event, refs)} - > - - { groupInput } -
- ; + .forEach((pair) => handleProperties(pair, groupInput, props.onChange)); return ( -
- setIsDynamicInput(!isDynamicInput)} - /> - { form } +
+ { groupInput }
); }; @@ -52,8 +27,6 @@ export const Properties: React.FC = (props: IPropertiesProps) const handleProperties = ( [key, value]: [string, string | number], groupInput: React.ReactNode[], - refs: Array>, - isDynamicInput: boolean, onChange: (key: string, value: string | number | boolean) => void ): void => { const id = `property-${key}`; @@ -69,49 +42,31 @@ const handleProperties = ( type = INPUT_TYPES[key]; } - const ref: React.RefObject = React.useRef(null); - refs.push(ref); - const isDisabled = ['id', 'parentId'].includes(key); - const input = isDynamicInput - ? { - if (type === 'checkbox') { - onChange(key, event.target.checked); - return; - } - onChange(key, event.target.value); - }} - disabled={isDisabled} - /> - : ; + /// groupInput.push(
- - {input} + + { + if (type === 'checkbox') { + onChange(key, event.target.checked); + return; + } + onChange(key, event.target.value); + }} + disabled={isDisabled} + />
); }; diff --git a/src/Components/ToggleButton/ToggleButton.scss b/src/Components/ToggleButton/ToggleButton.scss deleted file mode 100644 index 0948f52..0000000 --- a/src/Components/ToggleButton/ToggleButton.scss +++ /dev/null @@ -1,8 +0,0 @@ -input:checked ~ .dot { - transform: translateX(100%); -} -input:checked ~ .line { - background-color: #3B82F6; -} - - diff --git a/src/Components/ToggleButton/ToggleButton.tsx b/src/Components/ToggleButton/ToggleButton.tsx deleted file mode 100644 index 198bf99..0000000 --- a/src/Components/ToggleButton/ToggleButton.tsx +++ /dev/null @@ -1,52 +0,0 @@ -import React, { FC } from 'react'; -import './ToggleButton.scss'; - -interface IToggleButtonProps { - id: string - text: string - type?: TOGGLE_TYPE - title: string - checked: boolean - onChange: React.ChangeEventHandler -} - -export enum TOGGLE_TYPE { - MATERIAL, - IOS -} - -export const ToggleButton: FC = (props) => { - const id = `toggle-${props.id}`; - const type = props.type ?? TOGGLE_TYPE.MATERIAL; - let classLine = 'line w-10 h-4 bg-gray-400 rounded-full shadow-inner'; - let classDot = 'dot absolute w-6 h-6 bg-white rounded-full shadow -left-1 -top-1 transition'; - if (type === TOGGLE_TYPE.IOS) { - classLine = 'line block bg-gray-600 w-14 h-8 rounded-full'; - classDot = 'dot absolute left-1 top-1 bg-white w-6 h-6 rounded-full transition'; - } - - return ( -
-
- -
-
- ); -}; diff --git a/src/Components/UI/UI.tsx b/src/Components/UI/UI.tsx index 5c7012e..6d6adbe 100644 --- a/src/Components/UI/UI.tsx +++ b/src/Components/UI/UI.tsx @@ -17,7 +17,6 @@ interface IUIProps { SelectContainer: (container: ContainerModel) => void DeleteContainer: (containerId: string) => void OnPropertyChange: (key: string, value: string | number | boolean) => void - OnPropertiesSubmit: (event: React.FormEvent, refs: Array>) => void AddContainerToSelectedContainer: (type: string) => void AddContainer: (index: number, type: string, parentId: string) => void SaveEditorAsJSON: () => void @@ -60,7 +59,6 @@ export const UI: React.FunctionComponent = (props: IUIProps) => { isOpen={isElementsSidebarOpen} isHistoryOpen={isHistoryOpen} OnPropertyChange={props.OnPropertyChange} - OnPropertiesSubmit={props.OnPropertiesSubmit} SelectContainer={props.SelectContainer} DeleteContainer={props.DeleteContainer} AddContainer={props.AddContainer} diff --git a/src/index.scss b/src/index.scss index f653990..1bc3361 100644 --- a/src/index.scss +++ b/src/index.scss @@ -23,16 +23,6 @@ @apply transition-all bg-blue-100 hover:bg-blue-200 text-blue-700 text-lg font-semibold p-8 rounded-lg } - .normal-btn { - @apply text-sm - py-2 px-4 - rounded-full border-0 - font-semibold - transition-all - bg-blue-100 text-blue-700 - hover:bg-blue-200 - } - .floating-btn { @apply h-full w-full text-white align-middle items-center justify-center } diff --git a/src/utils/default.ts b/src/utils/default.ts index a117ef0..552b8a0 100644 --- a/src/utils/default.ts +++ b/src/utils/default.ts @@ -30,9 +30,9 @@ export const DEFAULT_MAINCONTAINER_PROPS: Properties = { parentId: 'null', x: 0, y: 0, + isRigidBody: false, width: DEFAULT_CONFIG.MainContainer.Width, height: DEFAULT_CONFIG.MainContainer.Height, - isRigidBody: false, fillOpacity: 0, stroke: 'black' };