Implement Pattern
This commit is contained in:
parent
c0a7a26874
commit
f6e4238b3d
4 changed files with 290 additions and 77 deletions
|
@ -67,6 +67,8 @@ export interface IAvailableContainer {
|
|||
|
||||
/**
|
||||
* (optional)
|
||||
* Disabled when Pattern is used.
|
||||
*
|
||||
* 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.
|
||||
|
@ -81,6 +83,13 @@ export interface IAvailableContainer {
|
|||
*/
|
||||
DefaultChildType?: string
|
||||
|
||||
/**
|
||||
* Allow to use a Pattern to create the list of children
|
||||
* Cannot be used with DefaultChildType,
|
||||
* DefaultChildType will be disabled for this container and the children
|
||||
*/
|
||||
Pattern?: string
|
||||
|
||||
/** if true, show the dimension of the container */
|
||||
ShowSelfDimensions?: boolean
|
||||
|
||||
|
|
|
@ -1,10 +1,12 @@
|
|||
/* eslint-disable @typescript-eslint/naming-convention */
|
||||
import { IAvailableContainer } from './IAvailableContainer';
|
||||
import { IAvailableSymbol } from './IAvailableSymbol';
|
||||
import { IPattern } from './IPattern';
|
||||
|
||||
/** Model of configuration for the application to configure it */
|
||||
export interface IConfiguration {
|
||||
AvailableContainers: IAvailableContainer[] // TODO: Use a Map<string, IAvailableContainer>
|
||||
AvailableSymbols: IAvailableSymbol[] // TODO: Use a Map<string, IAvailableContainer>
|
||||
Patterns: IPattern[]
|
||||
MainContainer: IAvailableContainer
|
||||
}
|
||||
|
|
57
src/Interfaces/IPattern.ts
Normal file
57
src/Interfaces/IPattern.ts
Normal file
|
@ -0,0 +1,57 @@
|
|||
import { IAvailableContainer } from './IAvailableContainer';
|
||||
|
||||
export interface IPattern {
|
||||
/**
|
||||
* Unique id for the pattern
|
||||
*/
|
||||
id: string
|
||||
|
||||
/**
|
||||
* Text to display in the sidebar
|
||||
*/
|
||||
text: string
|
||||
|
||||
/**
|
||||
* IAvailableContainer id used to wrap the children.
|
||||
*/
|
||||
wrapper: string
|
||||
|
||||
/**
|
||||
* List of ids of Pattern or IAvailableContainer
|
||||
* If a IAvailableContainer and a Pattern have the same id,
|
||||
* IAvailableContainer will be prioritized
|
||||
*/
|
||||
children: string[]
|
||||
}
|
||||
|
||||
export type ContainerOrPattern = IAvailableContainer | IPattern;
|
||||
|
||||
export function GetPattern(
|
||||
id: string,
|
||||
configs: Map<string, IAvailableContainer>,
|
||||
patterns: Map<string, IPattern>
|
||||
): ContainerOrPattern | undefined {
|
||||
let containerOrPattern: ContainerOrPattern | undefined = configs.get(id);
|
||||
containerOrPattern = containerOrPattern ?? patterns.get(id);
|
||||
return containerOrPattern;
|
||||
}
|
||||
|
||||
export function IsPattern(
|
||||
id: string,
|
||||
configs: Map<string, IAvailableContainer>,
|
||||
patterns: Map<string, IPattern>
|
||||
): boolean {
|
||||
let containerOrPattern: ContainerOrPattern | undefined = configs.get(id);
|
||||
|
||||
if (containerOrPattern !== undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
containerOrPattern = patterns.get(id);
|
||||
|
||||
if (containerOrPattern === undefined) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue