tabletop-commander/types.d.ts

57 lines
1.1 KiB
TypeScript

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;