Implement Pattern
This commit is contained in:
parent
c0a7a26874
commit
f6e4238b3d
4 changed files with 290 additions and 77 deletions
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