svg-layout-designer-react/src/utils/default.ts
Siklos 9f9ec8dc65
All checks were successful
continuous-integration/drone/pr Build is passing
continuous-integration/drone/push Build is passing
Implement DefaultChildType
2022-08-18 15:51:45 +02:00

90 lines
2.3 KiB
TypeScript

import { XPositionReference } from '../Enums/XPositionReference';
import { IAvailableContainer } from '../Interfaces/IAvailableContainer';
import { IConfiguration } from '../Interfaces/IConfiguration';
import { IContainerModel } from '../Interfaces/IContainerModel';
import IProperties from '../Interfaces/IProperties';
/// CONTAINRE DEFAULTS ///
export const SHOW_TEXT = true;
export const DEFAULTCHILDTYPE_ALLOW_CYCLIC = false;
export const DEFAULTCHILDTYPE_MAX_DEPTH = 10;
/// DIMENSIONS DEFAULTS ///
export const SHOW_PARENT_DIMENSION = true;
export const SHOW_CHILDREN_DIMENSIONS = false;
export const SHOW_DIMENSIONS_PER_DEPTH = true;
export const DIMENSION_MARGIN = 50;
export const NOTCHES_LENGTH = 4;
/// EDITOR DEFAULTS ///
export const ENABLE_SHORTCUTS = true;
export const MAX_HISTORY = 200;
export const DEFAULT_CONFIG: IConfiguration = {
AvailableContainers: [
{
Type: 'Container',
Width: 75,
Height: 100,
Style: {
fillOpacity: 0,
stroke: 'green'
}
}
],
AvailableSymbols: [],
MainContainer: {
Type: 'Container',
Width: 2000,
Height: 100,
Style: {
fillOpacity: 0,
stroke: 'black'
}
}
};
export const DEFAULT_MAINCONTAINER_PROPS: IProperties = {
id: 'main',
parentId: 'null',
displayedText: 'main',
x: 0,
y: 0,
minWidth: 1,
width: Number(DEFAULT_CONFIG.MainContainer.Width),
height: Number(DEFAULT_CONFIG.MainContainer.Height),
isRigidBody: false,
isAnchor: false,
XPositionReference: XPositionReference.Left,
style: {
stroke: 'black',
fillOpacity: 0
}
};
export const GetDefaultContainerProps = (
type: string,
typeCount: number,
parent: IContainerModel,
x: number,
y: number,
containerConfig: IAvailableContainer
): IProperties => ({
id: `${type}-${typeCount}`,
parentId: parent.properties.id,
displayedText: `${type}-${typeCount}`,
x,
y,
width: containerConfig.Width ?? containerConfig.MinWidth ?? parent.properties.width,
height: containerConfig.Height ?? parent.properties.height,
isRigidBody: false, // set this to true to replicate Florian's project
isAnchor: false,
XPositionReference: containerConfig.XPositionReference ?? XPositionReference.Left,
minWidth: containerConfig.MinWidth ?? 0,
customSVG: containerConfig.CustomSVG,
style: containerConfig.Style,
userData: containerConfig.UserData
});