tabletop-commander/types.d.ts
2024-03-19 14:49:50 -06:00

94 lines
1.7 KiB
TypeScript

// MD Parser
type IdentifiedToken<M> = {
metadata: M;
children?: Token[];
uuid: string;
raw: string;
content: string;
rendersChildrenOnly?: boolean;
rendersContentOnly?: boolean;
};
type TokenRenderer<M> = (t: Token<M>) => ReactNode;
type TokenAttributes = {
type: string;
render: TokenRenderer;
};
type Token<M = Record<string, string>> = IdentifiedToken<M> & TokenAttributes;
type TokenMarker<M = Record<string, string>> = {
start: number;
end: number;
type: string;
parent?: TokenMarker;
token: Token<M>;
};
type FrontMatter = Record<string, string>;
type SearchFunction = (
s: string,
start: number,
end: number,
) => {
start: number;
end: number;
text: string;
lastIndex: number;
};
type TokenIdentifier<M> = {
rx: RegExp;
parse: (s: string) => Token<M>;
search?: SearchFunction;
};
type TokenIdentifierMap = Map<string, TokenIdentifier<any>>;
type IdentifierRegistration = <N = Record<string, string>>(
type: string,
match: RegExp,
parseFunction: (s: string, rx: RegExp) => IdentifiedToken<N>,
renderFunction: TokenRenderer<N>,
openTagRx?: RegExp,
closeTagRx?: RegExp,
) => void;
// Schema
type MetadataType = {
[key: string]: string;
};
type FieldType = {
type: FieldTypes;
value: string;
isConstant: boolean;
limit: number;
minimum: number;
};
type TypeType = Record<string, FieldType>;
type Template = {
type: string;
display: string;
};
type Schema = {
id: string;
name: string;
schema: Record<string, Template>;
types: Record<string, TypeType>;
};
// Input Binder
type InputBinder = {
name: string;
value: string | number;
onChange: (
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>,
) => void;
};