57 lines
1.3 KiB
TypeScript
57 lines
1.3 KiB
TypeScript
import { type 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;
|
|
}
|