Refactor Editor and module functions (#15)
All checks were successful
continuous-integration/drone/push Build is passing

Moved all module functions to separate utils modules

Replaced standard with standard with typescript

Extracted UI elements to separate component

Reviewed-on: https://git.siklos-chaneru.duckdns.org/Siklos/svg-layout-designer-react/pulls/15
This commit is contained in:
Siklos 2022-08-05 15:38:44 -04:00
parent 8e34d6b72a
commit 293af45144
26 changed files with 477 additions and 367 deletions

View file

@ -1,37 +1,49 @@
import * as React from 'react';
import { ReactSVGPanZoom, Tool, Value, TOOL_PAN } from 'react-svg-pan-zoom';
import { UncontrolledReactSVGPanZoom } from 'react-svg-pan-zoom';
import { Container } from './Elements/Container';
import { ContainerModel } from '../../Interfaces/ContainerModel';
import { Selector } from './Elements/Selector';
interface ISVGProps {
width: number,
height: number,
children: ContainerModel | ContainerModel[] | null,
width: number
height: number
children: ContainerModel | ContainerModel[] | null
selected: ContainerModel | null
}
interface ISVGState {
value: Value,
tool: Tool
viewerWidth: number,
viewerHeight: number,
}
export class SVG extends React.PureComponent<ISVGProps> {
public state: ISVGState;
public static ID = 'svg';
public state: ISVGState;
constructor(props: ISVGProps) {
super(props);
this.state = {
value: {
viewerWidth: window.innerWidth,
viewerHeight: window.innerHeight
} as Value,
tool: TOOL_PAN
viewerWidth: window.innerWidth,
viewerHeight: window.innerHeight
};
}
render() {
resizeViewBox(): void {
this.setState({
viewerWidth: window.innerWidth,
viewerHeight: window.innerHeight
});
}
componentDidMount(): void {
window.addEventListener('resize', this.resizeViewBox.bind(this));
}
componentWillUnmount(): void {
window.removeEventListener('resize', this.resizeViewBox.bind(this));
}
render(): JSX.Element {
const xmlns = '<http://www.w3.org/2000/svg>';
const properties = {
@ -49,13 +61,11 @@ export class SVG extends React.PureComponent<ISVGProps> {
return (
<div id={SVG.ID}>
<ReactSVGPanZoom
width={window.innerWidth}
height={window.innerHeight}
<UncontrolledReactSVGPanZoom
width={this.state.viewerWidth}
height={this.state.viewerHeight}
background={'#ffffff'}
defaultTool='pan'
value={this.state.value} onChangeValue={value => this.setState({ value })}
tool={this.state.tool} onChangeTool={tool => this.setState({ tool })}
miniatureProps={{
position: 'left',
background: '#616264',
@ -67,9 +77,8 @@ export class SVG extends React.PureComponent<ISVGProps> {
{ children }
<Selector selected={this.props.selected} />
</svg>
</ReactSVGPanZoom>
</UncontrolledReactSVGPanZoom>
</div>
);
};
}