Files
cinny/src/app/components/editor/slate.d.ts
T

110 lines
2.3 KiB
TypeScript
Raw Normal View History

2023-06-12 21:15:23 +10:00
import { BaseEditor } from 'slate';
import { ReactEditor } from 'slate-react';
2023-06-16 11:11:03 +10:00
import { HistoryEditor } from 'slate-history';
2023-10-18 13:15:30 +11:00
import { BlockType } from './types';
2023-06-12 21:15:23 +10:00
export type HeadingLevel = 1 | 2 | 3;
2023-06-16 11:11:03 +10:00
export type Editor = BaseEditor & HistoryEditor & ReactEditor;
2023-06-12 21:15:23 +10:00
export type Text = {
text: string;
};
export type FormattedText = Text & {
bold?: boolean;
italic?: boolean;
underline?: boolean;
strikeThrough?: boolean;
code?: boolean;
spoiler?: boolean;
};
export type LinkElement = {
type: BlockType.Link;
href: string;
2023-10-14 16:08:43 +11:00
children: Text[];
2023-06-12 21:15:23 +10:00
};
2023-10-14 16:08:43 +11:00
2023-06-12 21:15:23 +10:00
export type MentionElement = {
type: BlockType.Mention;
id: string;
highlight: boolean;
name: string;
children: Text[];
};
export type EmoticonElement = {
type: BlockType.Emoticon;
key: string;
shortcode: string;
children: Text[];
};
2023-10-18 13:15:30 +11:00
export type CommandElement = {
type: BlockType.Command;
command: string;
children: Text[];
};
2023-06-12 21:15:23 +10:00
2023-10-18 13:15:30 +11:00
export type InlineElement = Text | LinkElement | MentionElement | EmoticonElement | CommandElement;
2023-10-14 16:08:43 +11:00
2023-06-12 21:15:23 +10:00
export type ParagraphElement = {
type: BlockType.Paragraph;
2023-10-14 16:08:43 +11:00
children: InlineElement[];
2023-06-12 21:15:23 +10:00
};
export type HeadingElement = {
type: BlockType.Heading;
level: HeadingLevel;
2023-10-14 16:08:43 +11:00
children: InlineElement[];
2023-06-12 21:15:23 +10:00
};
export type CodeLineElement = {
type: BlockType.CodeLine;
children: Text[];
};
export type CodeBlockElement = {
type: BlockType.CodeBlock;
children: CodeLineElement[];
};
export type QuoteLineElement = {
type: BlockType.QuoteLine;
2023-10-14 16:08:43 +11:00
children: InlineElement[];
2023-06-12 21:15:23 +10:00
};
export type BlockQuoteElement = {
type: BlockType.BlockQuote;
children: QuoteLineElement[];
};
export type ListItemElement = {
type: BlockType.ListItem;
2023-10-14 16:08:43 +11:00
children: InlineElement[];
2023-06-12 21:15:23 +10:00
};
export type OrderedListElement = {
type: BlockType.OrderedList;
children: ListItemElement[];
};
export type UnorderedListElement = {
type: BlockType.UnorderedList;
children: ListItemElement[];
};
export type CustomElement =
| LinkElement
| MentionElement
| EmoticonElement
2023-10-18 13:15:30 +11:00
| CommandElement
2023-06-12 21:15:23 +10:00
| ParagraphElement
| HeadingElement
| CodeLineElement
| CodeBlockElement
| QuoteLineElement
| BlockQuoteElement
| ListItemElement
| OrderedListElement
| UnorderedListElement;
declare module 'slate' {
interface CustomTypes {
2023-06-16 11:11:03 +10:00
Editor: Editor;
2023-06-12 21:15:23 +10:00
Element: CustomElement;
Text: FormattedText & Text;
}
}