tabletop-commander/types.d.ts

105 lines
1.9 KiB
TypeScript

import { FieldTypes } from "./components/schema/fieldtypes";
// 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 SchemaFields = Record<string, FieldTypes>;
type SchemaTypes = Record<string, TypeType>;
type Schema = {
id: string;
name: string;
fields: SchemaFields;
types: SchemaTypes;
version: number;
gameSystemId?: string | null;
};
// Input Binder
type InputBinder = {
name: string;
value: string | number;
onChange: (
e: ChangeEvent<HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement>,
) => void;
};
// Query
type QueryableObject = Record<string, any>;