Replace isComponentsOpen, isSymbolsOpen by SelectorMode in SVG.tsx

This commit is contained in:
Eric NGUYEN 2023-02-10 17:07:26 +01:00
parent 579422653b
commit 9797ada55a
2 changed files with 36 additions and 8 deletions

View file

@ -21,9 +21,14 @@ interface ISVGProps {
selectedContainer?: IContainerModel selectedContainer?: IContainerModel
symbols: Map<string, ISymbolModel> symbols: Map<string, ISymbolModel>
selectedSymbol?: ISymbolModel selectedSymbol?: ISymbolModel
selectorMode: SelectorMode
selectContainer: (containerId: string) => void selectContainer: (containerId: string) => void
isComponentsOpen: boolean }
isSymbolsOpen: boolean
export enum SelectorMode {
Nothing,
Containers,
Symbols
} }
export const ID = 'svg'; export const ID = 'svg';
@ -62,6 +67,25 @@ export function SVG(props: ISVGProps): JSX.Element {
selectContainer={props.selectContainer} selectContainer={props.selectContainer}
/>; />;
function Selector(): JSX.Element {
switch (props.selectorMode) {
case SelectorMode.Containers:
return <SelectorContainer
containers={props.containers}
scale={scale}
selected={props.selectedContainer}
/>;
case SelectorMode.Symbols:
return <SelectorSymbol
symbols={props.symbols}
scale={scale}
selected={props.selectedSymbol}
/>;
default:
return <></>;
}
}
return ( return (
<div id={ID} className={props.className}> <div id={ID} className={props.className}>
<ReactSVGPanZoom <ReactSVGPanZoom
@ -102,9 +126,7 @@ export function SVG(props: ISVGProps): JSX.Element {
: null} : null}
<DimensionLayer containers={props.containers} symbols={props.symbols} scale={scale} root={props.children} /> <DimensionLayer containers={props.containers} symbols={props.symbols} scale={scale} root={props.children} />
<SymbolLayer scale={scale} symbols={props.symbols} /> <SymbolLayer scale={scale} symbols={props.symbols} />
{/* leave this at the end so it can be removed during the svg export */} <Selector />
{ props.isComponentsOpen ? <SelectorContainer containers={props.containers} scale={scale} selected={props.selectedContainer} /> : null }
{ props.isSymbolsOpen ? <SelectorSymbol symbols={props.symbols} scale={scale} selected={props.selectedSymbol} /> : null }
</svg> </svg>
</ReactSVGPanZoom> </ReactSVGPanZoom>
</div> </div>

View file

@ -8,7 +8,7 @@ import { BAR_WIDTH } from '../Bar/Bar';
import { Canvas } from '../Canvas/Canvas'; import { Canvas } from '../Canvas/Canvas';
import { AddDimensions } from '../Canvas/DimensionLayer'; import { AddDimensions } from '../Canvas/DimensionLayer';
import { RenderSelector } from '../Canvas/Selector'; import { RenderSelector } from '../Canvas/Selector';
import { SVG } from '../SVG/SVG'; import { SelectorMode, SVG } from '../SVG/SVG';
import { RenderSymbol } from '../Canvas/Symbol'; import { RenderSymbol } from '../Canvas/Symbol';
import { useState } from 'react'; import { useState } from 'react';
import { type ISymbolModel } from '../../Interfaces/ISymbolModel'; import { type ISymbolModel } from '../../Interfaces/ISymbolModel';
@ -71,6 +71,13 @@ export function Viewer({
return <></>; return <></>;
} }
let selectorMode = SelectorMode.Nothing;
if (isComponentsOpen) {
selectorMode = SelectorMode.Containers;
} else if (isSymbolsOpen) {
selectorMode = SelectorMode.Symbols;
}
if (USE_EXPERIMENTAL_CANVAS_API) { if (USE_EXPERIMENTAL_CANVAS_API) {
function Draw(ctx: CanvasRenderingContext2D, frameCount: number, scale: number, translatePos: IPoint): void { function Draw(ctx: CanvasRenderingContext2D, frameCount: number, scale: number, translatePos: IPoint): void {
if (mainContainer === undefined) { if (mainContainer === undefined) {
@ -144,9 +151,8 @@ export function Viewer({
selectedContainer={selectedContainer} selectedContainer={selectedContainer}
symbols={current.symbols} symbols={current.symbols}
selectedSymbol={selectedSymbol} selectedSymbol={selectedSymbol}
selectorMode={selectorMode}
selectContainer={selectContainer} selectContainer={selectContainer}
isComponentsOpen={isComponentsOpen}
isSymbolsOpen={isSymbolsOpen}
> >
{mainContainer} {mainContainer}
</SVG> </SVG>