Add MinWidth to properties + add docs to IProperties + refactor default container properties into a function in default.ts
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
parent
60329ef143
commit
3da8a0c55e
4 changed files with 87 additions and 23 deletions
|
@ -8,6 +8,7 @@ import IProperties from '../../Interfaces/IProperties';
|
||||||
import { AddMethod } from '../../Enums/AddMethod';
|
import { AddMethod } from '../../Enums/AddMethod';
|
||||||
import { IAvailableContainer } from '../../Interfaces/IAvailableContainer';
|
import { IAvailableContainer } from '../../Interfaces/IAvailableContainer';
|
||||||
import { XPositionReference } from '../../Enums/XPositionReference';
|
import { XPositionReference } from '../../Enums/XPositionReference';
|
||||||
|
import { GetDefaultContainerProps } from '../../utils/default';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Select a container
|
* Select a container
|
||||||
|
@ -203,25 +204,17 @@ export function AddContainer(
|
||||||
|
|
||||||
let x = containerConfig.DefaultX ?? 0;
|
let x = containerConfig.DefaultX ?? 0;
|
||||||
const y = containerConfig.DefaultY ?? 0;
|
const y = containerConfig.DefaultY ?? 0;
|
||||||
const width = containerConfig.Width ?? parentClone.properties.width;
|
|
||||||
const height = containerConfig.Height ?? parentClone.properties.height;
|
|
||||||
|
|
||||||
x = ApplyAddMethod(index, containerConfig, parentClone, x);
|
x = ApplyAddMethod(index, containerConfig, parentClone, x);
|
||||||
|
|
||||||
const defaultProperties: IProperties = {
|
const defaultProperties = GetDefaultContainerProps(
|
||||||
id: `${type}-${count}`,
|
type,
|
||||||
parentId: parentClone.properties.id,
|
count,
|
||||||
|
parentClone,
|
||||||
x,
|
x,
|
||||||
y,
|
y,
|
||||||
width,
|
containerConfig
|
||||||
height,
|
);
|
||||||
isRigidBody: false,
|
|
||||||
isAnchor: false,
|
|
||||||
XPositionReference: containerConfig.XPositionReference ?? XPositionReference.Left,
|
|
||||||
customSVG: containerConfig.CustomSVG,
|
|
||||||
style: containerConfig.Style,
|
|
||||||
userData: containerConfig.UserData
|
|
||||||
};
|
|
||||||
|
|
||||||
// Create the container
|
// Create the container
|
||||||
const newContainer = new ContainerModel(
|
const newContainer = new ContainerModel(
|
||||||
|
@ -265,6 +258,7 @@ function ApplyAddMethod(index: number, containerConfig: IAvailableContainer, par
|
||||||
if (index > 0 && (
|
if (index > 0 && (
|
||||||
containerConfig.AddMethod === undefined ||
|
containerConfig.AddMethod === undefined ||
|
||||||
containerConfig.AddMethod === AddMethod.Append)) {
|
containerConfig.AddMethod === AddMethod.Append)) {
|
||||||
|
// Append method (default)
|
||||||
const lastChild: IContainerModel | undefined = parent.children.at(index - 1);
|
const lastChild: IContainerModel | undefined = parent.children.at(index - 1);
|
||||||
|
|
||||||
if (lastChild !== undefined) {
|
if (lastChild !== undefined) {
|
||||||
|
|
|
@ -5,13 +5,14 @@ import { XPositionReference } from '../Enums/XPositionReference';
|
||||||
/** Model of available container used in application configuration */
|
/** Model of available container used in application configuration */
|
||||||
export interface IAvailableContainer {
|
export interface IAvailableContainer {
|
||||||
Type: string
|
Type: string
|
||||||
Width?: number
|
|
||||||
Height?: number
|
|
||||||
DefaultX?: number
|
DefaultX?: number
|
||||||
DefaultY?: number
|
DefaultY?: number
|
||||||
|
Width?: number
|
||||||
|
Height?: number
|
||||||
|
MinWidth?: number
|
||||||
AddMethod?: AddMethod
|
AddMethod?: AddMethod
|
||||||
XPositionReference?: XPositionReference
|
XPositionReference?: XPositionReference
|
||||||
CustomSVG?: string
|
CustomSVG?: string
|
||||||
Style: React.CSSProperties
|
Style?: React.CSSProperties
|
||||||
UserData?: object
|
UserData?: object
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,24 +3,68 @@ import { XPositionReference } from '../Enums/XPositionReference';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Properties of a container
|
* Properties of a container
|
||||||
* @property id id of the container
|
|
||||||
* @property parentId id of the parent container
|
|
||||||
* @property x horizontal offset of the container
|
|
||||||
* @property y vertical offset of the container
|
|
||||||
* @property isRigidBody if true apply rigid body behaviors
|
|
||||||
* @property isAnchor if true apply anchor behaviors
|
|
||||||
*/
|
*/
|
||||||
export default interface IProperties {
|
export default interface IProperties {
|
||||||
|
/** id of the container */
|
||||||
id: string
|
id: string
|
||||||
|
|
||||||
|
/** id of the parent container (null when there is no parent) */
|
||||||
parentId: string | null
|
parentId: string | null
|
||||||
|
|
||||||
|
/** horizontal offset */
|
||||||
x: number
|
x: number
|
||||||
|
|
||||||
|
/** vertical offset */
|
||||||
y: number
|
y: number
|
||||||
|
|
||||||
|
/** width */
|
||||||
width: number
|
width: number
|
||||||
|
|
||||||
|
/** height */
|
||||||
height: number
|
height: number
|
||||||
|
|
||||||
|
/** true if rigid, false otherwise */
|
||||||
isRigidBody: boolean
|
isRigidBody: boolean
|
||||||
|
|
||||||
|
/** true if anchor, false otherwise */
|
||||||
isAnchor: boolean
|
isAnchor: boolean
|
||||||
|
|
||||||
|
/** Horizontal alignment, also determines the visual location of x {Left = 0, Center, Right } */
|
||||||
XPositionReference: XPositionReference
|
XPositionReference: XPositionReference
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (optional)
|
||||||
|
* Minimum width used when isRigidBody = true.
|
||||||
|
* Allows the container to set isRigidBody to false when it gets squeezed
|
||||||
|
* by an anchor
|
||||||
|
*/
|
||||||
|
minWidth?: number
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (optional)
|
||||||
|
* Replace a <rect> by a customized "SVG". It is not really an svg but it at least allows
|
||||||
|
* to draw some patterns that can be bind to the properties of the container
|
||||||
|
* Use {prop} to bind a property. Use {{ styleProp }} to use an object.
|
||||||
|
* Example :
|
||||||
|
* ```
|
||||||
|
* `<rect width="{width}" height="{height}" style="{style}"></rect>
|
||||||
|
* <rect width="{width}" height="{height}" stroke="black" fill-opacity="0"></rect>
|
||||||
|
* <line x1="0" y1="0" x2="{width}" y2="{height}" stroke="black" style='{{ "transform":"scaleY(0.5)"}}'></line>
|
||||||
|
* <line x1="{width}" y1="0" x2="0" y2="{height}" stroke="black" style='{userData.styleLine}'></line>
|
||||||
|
* `
|
||||||
|
* ```
|
||||||
|
*/
|
||||||
customSVG?: string
|
customSVG?: string
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (optional)
|
||||||
|
* Style of the <rect>
|
||||||
|
*/
|
||||||
style?: React.CSSProperties
|
style?: React.CSSProperties
|
||||||
|
|
||||||
|
/**
|
||||||
|
* (optional)
|
||||||
|
* User data that can be used for data storage or custom SVG
|
||||||
|
*/
|
||||||
userData?: object
|
userData?: object
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,5 +1,7 @@
|
||||||
import { XPositionReference } from '../Enums/XPositionReference';
|
import { XPositionReference } from '../Enums/XPositionReference';
|
||||||
|
import { IAvailableContainer } from '../Interfaces/IAvailableContainer';
|
||||||
import { IConfiguration } from '../Interfaces/IConfiguration';
|
import { IConfiguration } from '../Interfaces/IConfiguration';
|
||||||
|
import { IContainerModel } from '../Interfaces/IContainerModel';
|
||||||
import IProperties from '../Interfaces/IProperties';
|
import IProperties from '../Interfaces/IProperties';
|
||||||
|
|
||||||
export const DEFAULT_CONFIG: IConfiguration = {
|
export const DEFAULT_CONFIG: IConfiguration = {
|
||||||
|
@ -42,6 +44,29 @@ export const DEFAULT_MAINCONTAINER_PROPS: IProperties = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const GetDefaultContainerProps = (
|
||||||
|
type: string,
|
||||||
|
typeCount: number,
|
||||||
|
parent: IContainerModel,
|
||||||
|
x: number,
|
||||||
|
y: number,
|
||||||
|
containerConfig: IAvailableContainer
|
||||||
|
): IProperties => ({
|
||||||
|
id: `${type}-${typeCount}`,
|
||||||
|
parentId: parent.properties.id,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
width: containerConfig.Width ?? containerConfig.MinWidth ?? parent.properties.width,
|
||||||
|
height: containerConfig.Height ?? parent.properties.height,
|
||||||
|
isRigidBody: false,
|
||||||
|
isAnchor: false,
|
||||||
|
XPositionReference: containerConfig.XPositionReference ?? XPositionReference.Left,
|
||||||
|
minWidth: containerConfig.MinWidth,
|
||||||
|
customSVG: containerConfig.CustomSVG,
|
||||||
|
style: containerConfig.Style,
|
||||||
|
userData: containerConfig.UserData
|
||||||
|
});
|
||||||
|
|
||||||
export const DIMENSION_MARGIN = 50;
|
export const DIMENSION_MARGIN = 50;
|
||||||
export const NOTCHES_LENGTH = 4;
|
export const NOTCHES_LENGTH = 4;
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue