* add func to parse html to editor input * add plain to html input function * re-construct markdown * fix missing return * fix falsy condition * fix reading href instead of src of emoji * add message editor - WIP * fix plain to editor input func * add save edit message functionality * show edited event source code * focus message input on after editing message * use del tag for strike-through instead of s * prevent autocomplete from re-opening after esc * scroll out of view msg editor in view * handle up arrow edit * handle scroll to message editor without effect * revert prev commit: effect run after editor render * ignore relation event from editable * allow data-md tag for del and em in sanitize html * prevent edit without changes * ignore previous reply when replying to msg * fix up arrow edit not working sometime
103 lines
2.1 KiB
TypeScript
103 lines
2.1 KiB
TypeScript
import { BaseEditor } from 'slate';
|
|
import { ReactEditor } from 'slate-react';
|
|
import { HistoryEditor } from 'slate-history';
|
|
import { BlockType } from './Elements';
|
|
|
|
export type HeadingLevel = 1 | 2 | 3;
|
|
|
|
export type Editor = BaseEditor & HistoryEditor & ReactEditor;
|
|
|
|
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;
|
|
children: Text[];
|
|
};
|
|
|
|
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[];
|
|
};
|
|
|
|
export type InlineElement = Text | LinkElement | MentionElement | EmoticonElement;
|
|
|
|
export type ParagraphElement = {
|
|
type: BlockType.Paragraph;
|
|
children: InlineElement[];
|
|
};
|
|
export type HeadingElement = {
|
|
type: BlockType.Heading;
|
|
level: HeadingLevel;
|
|
children: InlineElement[];
|
|
};
|
|
export type CodeLineElement = {
|
|
type: BlockType.CodeLine;
|
|
children: Text[];
|
|
};
|
|
export type CodeBlockElement = {
|
|
type: BlockType.CodeBlock;
|
|
children: CodeLineElement[];
|
|
};
|
|
export type QuoteLineElement = {
|
|
type: BlockType.QuoteLine;
|
|
children: InlineElement[];
|
|
};
|
|
export type BlockQuoteElement = {
|
|
type: BlockType.BlockQuote;
|
|
children: QuoteLineElement[];
|
|
};
|
|
export type ListItemElement = {
|
|
type: BlockType.ListItem;
|
|
children: InlineElement[];
|
|
};
|
|
export type OrderedListElement = {
|
|
type: BlockType.OrderedList;
|
|
children: ListItemElement[];
|
|
};
|
|
export type UnorderedListElement = {
|
|
type: BlockType.UnorderedList;
|
|
children: ListItemElement[];
|
|
};
|
|
|
|
export type CustomElement =
|
|
| LinkElement
|
|
| MentionElement
|
|
| EmoticonElement
|
|
| ParagraphElement
|
|
| HeadingElement
|
|
| CodeLineElement
|
|
| CodeBlockElement
|
|
| QuoteLineElement
|
|
| BlockQuoteElement
|
|
| ListItemElement
|
|
| OrderedListElement
|
|
| UnorderedListElement;
|
|
|
|
declare module 'slate' {
|
|
interface CustomTypes {
|
|
Editor: Editor;
|
|
Element: CustomElement;
|
|
Text: FormattedText & Text;
|
|
}
|
|
}
|