diff --git a/README.md b/README.md index 7fa3b5c..5ecff80 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,34 @@ Run `npm ci` Run `npm run dev` +## Testing the API + +This program fetch the data structure from others application, allowing it to assemble them later. + +### With NodeJS + +```bash +node run ./test-server/node-http.js +``` + +The web server will be running at `http://localhost:5000` + +Configure the file `.env.development` with the url + + +### With bun + +Install `bun` + +Inside `test-server` folder, run : + +```bash +bun run http.js +``` + +The web server will be running at `http://localhost:5000` + +Configure the file `.env.development` with the url # Deploy @@ -29,39 +57,3 @@ Run `npm run build` Run `npm ci` Run `npm test` - - -# API - -You can preload a state by setting the `state` URL parameter -with a url address to a `state.json` file. - -Example: `http://localhost:4000/?state=http://localhost:5000/state.json` - -# Testing the external API - -This program fetch the data structure from others applications, allowing it to assemble them later. - -## With NodeJS - -```bash -node run ./test-server/node-http.js -``` - -The web server will be running at `http://localhost:5000` - -Configure the file `.env.development` with the url - -## With bun.sh - -Install `bun` - -Inside `test-server` folder, run : - -```bash -bun run http.js -``` - -The web server will be running at `http://localhost:5000` - -Configure the file `.env.development` with the url \ No newline at end of file diff --git a/src/App.tsx b/src/App.tsx index 2b8c7fd..e6ea857 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import './App.scss'; import { MainMenu } from './Components/MainMenu/MainMenu'; -import { ContainerModel, findContainerById, IContainerModel, MakeIterator } from './Interfaces/ContainerModel'; +import { ContainerModel, findContainerById, IContainerModel, MakeIterator } from './Components/SVG/Elements/ContainerModel'; import Editor, { IEditorState } from './Editor'; import { AvailableContainer } from './Interfaces/AvailableContainer'; import { Configuration } from './Interfaces/Configuration'; @@ -40,22 +40,6 @@ export class App extends React.Component { }; } - componentDidMount() { - const queryString = window.location.search; - const urlParams = new URLSearchParams(queryString); - const state = urlParams.get('state'); - - if (state === null) { - return; - } - - fetch(state) - .then((response) => response.json()) - .then((data: IEditorState) => { - this.LoadState(data); - }); - } - public NewEditor() { // Fetch the configuration from the API fetchConfiguration().then((configuration: Configuration) => { @@ -102,22 +86,18 @@ export class App extends React.Component { const result = reader.result as string; const editorState: IEditorState = JSON.parse(result); - this.LoadState(editorState); + Revive(editorState); + + this.setState({ + configuration: editorState.configuration, + history: editorState.history, + historyCurrentStep: editorState.historyCurrentStep, + isLoaded: true + } as IAppState); }); reader.readAsText(file); } - private LoadState(editorState: IEditorState) { - Revive(editorState); - - this.setState({ - configuration: editorState.configuration, - history: editorState.history, - historyCurrentStep: editorState.historyCurrentStep, - isLoaded: true - } as IAppState); - } - public render() { if (this.state.isLoaded) { return ( diff --git a/src/Components/ElementsSidebar/ElementsSidebar.tsx b/src/Components/ElementsSidebar/ElementsSidebar.tsx index c4ea51a..4e599ef 100644 --- a/src/Components/ElementsSidebar/ElementsSidebar.tsx +++ b/src/Components/ElementsSidebar/ElementsSidebar.tsx @@ -1,7 +1,7 @@ import * as React from 'react'; import { motion } from 'framer-motion'; import { Properties } from '../Properties/Properties'; -import { IContainerModel, getDepth, MakeIterator } from '../../Interfaces/ContainerModel'; +import { IContainerModel, getDepth, MakeIterator } from '../SVG/Elements/ContainerModel'; interface IElementsSidebarProps { MainContainer: IContainerModel | null, @@ -13,7 +13,7 @@ interface IElementsSidebarProps { selectContainer: (container: IContainerModel) => void } -export class ElementsSidebar extends React.PureComponent { +export class ElementsSidebar extends React.Component { public iterateChilds(handleContainer: (container: IContainerModel) => void): React.ReactNode { if (!this.props.MainContainer) { return null; @@ -53,7 +53,7 @@ export class ElementsSidebar extends React.PureComponent duration: 0.150 }} className={ - `w-full elements-sidebar-row whitespace-pre + `w-full elements-sidebar-row whitespace-pre text-left text-sm font-medium transition-all ${selectedClass}` } key={key} diff --git a/src/Components/FloatingButton/FloatingButton.tsx b/src/Components/FloatingButton/FloatingButton.tsx deleted file mode 100644 index fb5fc1c..0000000 --- a/src/Components/FloatingButton/FloatingButton.tsx +++ /dev/null @@ -1,10 +0,0 @@ -import * as React from 'react'; - -interface IFloatingButtonProps { -} - -const FloatingButton: React.FC = (props: IFloatingButtonProps) => { - return <>; -}; - -export default FloatingButton; diff --git a/src/Components/History/History.tsx b/src/Components/History/History.tsx index e77a8c7..750fcc7 100644 --- a/src/Components/History/History.tsx +++ b/src/Components/History/History.tsx @@ -9,7 +9,7 @@ interface IHistoryProps { jumpTo: (move: number) => void } -export class History extends React.PureComponent { +export class History extends React.Component { public render() { const isOpenClasses = this.props.isOpen ? 'right-0' : '-right-64'; @@ -33,7 +33,7 @@ export class History extends React.PureComponent { key={move} onClick={() => this.props.jumpTo(move)} className={ - `w-full elements-sidebar-row whitespace-pre + `w-full elements-sidebar-row whitespace-pre text-left text-sm font-medium transition-all ${selectedClass}` } > diff --git a/src/Components/Properties/Properties.tsx b/src/Components/Properties/Properties.tsx index 65cfefd..61d0bff 100644 --- a/src/Components/Properties/Properties.tsx +++ b/src/Components/Properties/Properties.tsx @@ -6,7 +6,20 @@ interface IPropertiesProps { onChange: (key: string, value: string) => void } -export class Properties extends React.PureComponent { +interface IPropertiesState { + hasUpdate: boolean +} + +export class Properties extends React.Component { + public state: IPropertiesState; + + constructor(props: IPropertiesProps) { + super(props); + this.state = { + hasUpdate: false + }; + } + public render() { if (this.props.properties === undefined) { return
; diff --git a/src/Components/SVG/Elements/Container.tsx b/src/Components/SVG/Elements/Container.tsx index a352bcd..bf56127 100644 --- a/src/Components/SVG/Elements/Container.tsx +++ b/src/Components/SVG/Elements/Container.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { getDepth, IContainerModel } from '../../../Interfaces/ContainerModel'; +import { getDepth, IContainerModel } from './ContainerModel'; import { Dimension } from './Dimension'; export interface IContainerProps { @@ -8,13 +8,13 @@ export interface IContainerProps { const GAP = 50; -export class Container extends React.PureComponent { +export class Container extends React.Component { /** * Render the container * @returns Render the container */ public render(): React.ReactNode { - const containersElements = this.props.model.children.map(child => ); + const containersElements = this.props.model.children.map(child => new Container({ model: child } as IContainerProps).render()); const xText = Number(this.props.model.properties.width) / 2; const yText = Number(this.props.model.properties.height) / 2; const transform = `translate(${Number(this.props.model.properties.x)}, ${Number(this.props.model.properties.y)})`; diff --git a/src/Interfaces/ContainerModel.ts b/src/Components/SVG/Elements/ContainerModel.ts similarity index 97% rename from src/Interfaces/ContainerModel.ts rename to src/Components/SVG/Elements/ContainerModel.ts index 787cf91..d66f6c8 100644 --- a/src/Interfaces/ContainerModel.ts +++ b/src/Components/SVG/Elements/ContainerModel.ts @@ -1,4 +1,4 @@ -import Properties from './Properties'; +import Properties from '../../../Interfaces/Properties'; export interface IContainerModel { children: IContainerModel[], diff --git a/src/Components/SVG/Elements/Dimension.tsx b/src/Components/SVG/Elements/Dimension.tsx index 96ab2c9..276345f 100644 --- a/src/Components/SVG/Elements/Dimension.tsx +++ b/src/Components/SVG/Elements/Dimension.tsx @@ -9,7 +9,7 @@ interface IDimensionProps { strokeWidth: number; } -export class Dimension extends React.PureComponent { +export class Dimension extends React.Component { public render() { const style = { stroke: 'black' diff --git a/src/Components/SVG/Elements/DimensionLayer.tsx b/src/Components/SVG/Elements/DimensionLayer.tsx index 3a3dee8..610177b 100644 --- a/src/Components/SVG/Elements/DimensionLayer.tsx +++ b/src/Components/SVG/Elements/DimensionLayer.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { ContainerModel, getDepth, MakeIterator } from '../../../Interfaces/ContainerModel'; +import { ContainerModel, getDepth, MakeIterator } from './ContainerModel'; import { Dimension } from './Dimension'; interface IDimensionLayerProps { @@ -22,16 +22,15 @@ const getDimensionsNodes = (root: ContainerModel): React.ReactNode[] => { const y = -(GAP * (getDepth(container) + 1)); const strokeWidth = 1; const text = width.toString(); - dimensions.push( - - ); + const dimension = new Dimension({ + id, + xStart, + xEnd, + y, + strokeWidth, + text + }); + dimensions.push(dimension.render()); } return dimensions; }; diff --git a/src/Components/SVG/Elements/Selector.tsx b/src/Components/SVG/Elements/Selector.tsx index de6d9a3..6fc1b9b 100644 --- a/src/Components/SVG/Elements/Selector.tsx +++ b/src/Components/SVG/Elements/Selector.tsx @@ -1,5 +1,5 @@ import * as React from 'react'; -import { IContainerModel, getAbsolutePosition } from '../../../Interfaces/ContainerModel'; +import { IContainerModel, getAbsolutePosition } from './ContainerModel'; interface ISelectorProps { selected: IContainerModel | null diff --git a/src/Components/SVG/SVG.tsx b/src/Components/SVG/SVG.tsx index c11e39b..9583571 100644 --- a/src/Components/SVG/SVG.tsx +++ b/src/Components/SVG/SVG.tsx @@ -1,28 +1,33 @@ import * as React from 'react'; import { ReactSVGPanZoom, Tool, Value, TOOL_PAN } from 'react-svg-pan-zoom'; import { Container } from './Elements/Container'; -import { ContainerModel } from '../../Interfaces/ContainerModel'; +import { ContainerModel } from './Elements/ContainerModel'; import { Selector } from './Elements/Selector'; interface ISVGProps { - width: number, - height: number, children: ContainerModel | ContainerModel[] | null, selected: ContainerModel | null } interface ISVGState { + viewBox: number[], value: Value, tool: Tool } -export class SVG extends React.PureComponent { +export class SVG extends React.Component { public state: ISVGState; public svg: React.RefObject; constructor(props: ISVGProps) { super(props); this.state = { + viewBox: [ + 0, + 0, + window.innerWidth, + window.innerHeight + ], value: { viewerWidth: window.innerWidth, viewerHeight: window.innerHeight @@ -32,20 +37,38 @@ export class SVG extends React.PureComponent { this.svg = React.createRef(); } + resizeViewBox() { + this.setState({ + viewBox: [ + 0, + 0, + window.innerWidth, + window.innerHeight + ] + }); + } + + componentDidMount() { + window.addEventListener('resize', this.resizeViewBox.bind(this)); + } + + componentWillUnmount() { + window.removeEventListener('resize', this.resizeViewBox.bind(this)); + } + render() { const xmlns = ''; const properties = { - width: this.props.width, - height: this.props.height, + viewBox: this.state.viewBox.join(' '), xmlns }; let children: React.ReactNode | React.ReactNode[] = []; if (Array.isArray(this.props.children)) { - children = this.props.children.map(child => ); + children = this.props.children.map(child => new Container({ model: child }).render()); } else if (this.props.children !== null) { - children = ; + children = new Container({ model: this.props.children }).render(); } return ( @@ -56,12 +79,6 @@ export class SVG extends React.PureComponent { 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', - width: window.innerWidth - 12, - height: 120 - }} > { children } diff --git a/src/Components/Sidebar/Sidebar.tsx b/src/Components/Sidebar/Sidebar.tsx index dd34812..af08ce9 100644 --- a/src/Components/Sidebar/Sidebar.tsx +++ b/src/Components/Sidebar/Sidebar.tsx @@ -8,7 +8,7 @@ interface ISidebarProps { buttonOnClick: (type: string) => void; } -export default class Sidebar extends React.PureComponent { +export default class Sidebar extends React.Component { public render() { const listElements = this.props.componentOptions.map(componentOption => - + { current.MainContainer }