This commit is contained in:
Carl Fuchs 2023-02-03 16:58:54 +01:00
parent 532151b939
commit 62abd3ff03
4 changed files with 85 additions and 4 deletions

View file

@ -11,6 +11,7 @@ interface IComponentsProps {
selectedContainer: IContainerModel | undefined selectedContainer: IContainerModel | undefined
componentOptions: IAvailableContainer[] componentOptions: IAvailableContainer[]
categories: ICategory[] categories: ICategory[]
replaceableCategoryName: string | undefined
buttonOnClick: (type: string) => void buttonOnClick: (type: string) => void
} }
@ -62,6 +63,10 @@ export function Components(props: IComponentsProps): JSX.Element {
disabled = config.Blacklist?.find(type => type === componentOption.Type) !== undefined ?? false; disabled = config.Blacklist?.find(type => type === componentOption.Type) !== undefined ?? false;
} }
if (componentOption.Category !== props.replaceableCategoryName) {
disabled = true;
}
if (disabled && hideDisabled) { if (disabled && hideDisabled) {
return; return;
} }

View file

@ -8,6 +8,7 @@ import Swal from 'sweetalert2';
import { PropertyType } from '../../../Enums/PropertyType'; import { PropertyType } from '../../../Enums/PropertyType';
import { TransformX, TransformY } from '../../../utils/svg'; import { TransformX, TransformY } from '../../../utils/svg';
import { Orientation } from '../../../Enums/Orientation'; import { Orientation } from '../../../Enums/Orientation';
import { AddContainers, AddContainerToSelectedContainer } from './AddContainer';
/** /**
* Select a container * Select a container
@ -109,6 +110,68 @@ export function DeleteContainer(
return history; return history;
} }
/**
* Replace a container
* @param containerId containerId of the container to delete
* @param fullHistory History of the editor
* @param historyCurrentStep Current step
* @returns New history
*/
// export function ReplaceByContainer(
// containerId: string,
// newContainerId: string,
// fullHistory: IHistoryState[],
// historyCurrentStep: number
// ): IHistoryState[] {
// const history = GetCurrentHistory(fullHistory, historyCurrentStep);
// const current = history[history.length - 1];
//
//
// const containers = structuredClone(current.containers);
// const container = FindContainerById(containers, containerId);
// if (container === undefined) {
// throw new Error(`[ReplaceContainer] Tried to delete a container that is not present in the main container: ${containerId}`);
// }
// ///
// const parent = FindContainerById(containers, container.properties.parentId);
// if (parent === undefined || parent === null) {
// throw new Error('[ReplaceContainer] Cannot replace a container that does not exists');
// }
//
// const index = parent.children.indexOf(container.properties.id);
//
// const newHistoryAfterDelete = DeleteContainer(
// container.properties.id,
// history,
// historyCurrentStep
// );
//
// const newContainer = FindContainerById(containers, container.properties.parentId);
//
// AddContainerToSelectedContainer(
// ne,
// selected,
// configuration,
// history,
// historyCurrentStep
// );
//
//
// /// /
//
//
// history.push({
// lastAction: `Replace ${containerId} By InsertnewId`,
// mainContainer: current.mainContainer,
// containers,
// newContainerId,
// typeCounters: Object.assign({}, current.typeCounters),
// symbols: newSymbols,
// selectedSymbolId: current.selectedSymbolId
// });
// return history;
// }
/** /**
* Returns the next container that will be selected * Returns the next container that will be selected
* after the selectedContainer is removed. * after the selectedContainer is removed.
@ -371,9 +434,8 @@ function AssignProperty(container: IContainerModel, key: string, value: string |
/** /**
* Link a symbol to a container * Link a symbol to a container
* @param containerId Container id * @param containerId Container id
* @param oldSymbolId Old Symbol id * @param oldSymbol
* @param newSymbolId New Symbol id * @param newSymbol
* @param symbols Current list of symbols
* @returns * @returns
*/ */
export function LinkSymbol( export function LinkSymbol(

View file

@ -56,9 +56,18 @@ export function InitActions(
menuActions.set( menuActions.set(
'elements-sidebar-row', 'elements-sidebar-row',
[{ [{
text: Text({ textId: '@ReplaceByContainer' }),
title: Text({ textId: '@ReplaceByContainerTitle' }),
shortcut: '<kbd>R</kbd>',
action: (target: HTMLElement) => {
const id = target.id;
console.log('replace');
}
}, {
text: Text({ textId: '@DeleteContainer' }), text: Text({ textId: '@DeleteContainer' }),
title: Text({ textId: '@DeleteContainerTitle' }), title: Text({ textId: '@DeleteContainerTitle' }),
shortcut: '<kbd>Suppr</kbd>', shortcut: '<kbd>Suppr</kbd>',
action: (target: HTMLElement) => { action: (target: HTMLElement) => {
const id = target.id; const id = target.id;
const newHistory = DeleteContainer( const newHistory = DeleteContainer(
@ -68,7 +77,8 @@ export function InitActions(
); );
setNewHistory(newHistory); setNewHistory(newHistory);
} }
}] }
]
); );
menuActions.set( menuActions.set(

View file

@ -97,11 +97,15 @@ export function UI({ editorState, ...methods }: IUIProps): JSX.Element {
switch (selectedSidebar) { switch (selectedSidebar) {
case SidebarType.Components: case SidebarType.Components:
leftSidebarTitle = Text({ textId: '@Components' }); leftSidebarTitle = Text({ textId: '@Components' });
const AllowedReplaceCategory = undefined;
leftChildren = <Components leftChildren = <Components
selectedContainer={selectedContainer} selectedContainer={selectedContainer}
componentOptions={configuration.AvailableContainers} componentOptions={configuration.AvailableContainers}
categories={configuration.Categories} categories={configuration.Categories}
buttonOnClick={methods.addContainer} buttonOnClick={methods.addContainer}
replaceableCategoryName={AllowedReplaceCategory}
/>; />;
rightSidebarTitle = Text({ textId: '@Elements' }); rightSidebarTitle = Text({ textId: '@Elements' });
rightChildren = <ElementsList rightChildren = <ElementsList