tabletop-commander/types.d.ts

101 lines
1.9 KiB
TypeScript

import { ReactNode } from "react";
type InlineToken = {
type:
| "text"
| "bold"
| "anchor"
| "image"
| "popover"
| "italic"
| "inline-code";
content: string;
data?: any;
uuid: string;
};
type InlineTokenInsert = {
start: number;
end: number;
} & InlineToken;
type Line = string | InlineToken[];
type MultilineToken = {
type: "code" | "p";
lines: SingleLineToken[];
};
type SingleLineCfg = {
rx: RegExp;
create: (line: string) => SingleLineToken;
replaceRx: RegExp;
shouldMendNextLine?: boolean;
};
type SingleLineToken = {
type: "h1" | "h2" | "h3" | "text" | `list${number}`;
line: Line;
raw: string;
mends?: boolean;
cfg?: SingleLineCfg;
uuid: string;
};
type IdentifiedToken = {
metadata: Record<string, string>;
children?: Token[];
uuid: string;
raw: string;
content: string;
rendersChildrenOnly?: boolean;
rendersContentOnly?: boolean;
};
type TokenRenderer = (t: Token) => ReactNode;
type TokenAttributes = {
type: string;
render: TokenRenderer;
};
type Token = IdentifiedToken & TokenAttributes;
type TokenMarker = {
start: number;
end: number;
type: string;
parent?: TokenMarker;
token: Token;
};
type FrontMatter = Record<string, string>;
type MultilineCfg = {
rx: RegExp;
closeRx?: RegExp;
create: (tokens: Token[]) => SingleLineToken[];
replace: (line: string) => string;
};
// -=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
type BlockToken = {
type: "block" | "grid" | "card" | "accordion";
metadata: any;
children: BlockChildren[];
parent?: string;
closed: boolean;
uuid: string;
};
type BlockChildren = ParagraphToken | BlockToken | SingleLineToken;
type ParagraphToken = {
content: SingleLineToken[];
allowsInline: boolean;
type: "p" | "code";
metadata: any;
closed: boolean;
uuid: string;
};