think/packages/client/src/tiptap/editor/collaboration/kit.ts

160 lines
5.5 KiB
TypeScript
Raw Normal View History

2022-05-10 07:00:38 +00:00
import { Toast } from '@douyinfe/semi-ui';
2022-05-16 09:23:59 +00:00
// 自定义节点扩展
import { Attachment } from 'tiptap/core/extensions/attachment';
2022-05-03 16:52:33 +00:00
import { BackgroundColor } from 'tiptap/core/extensions/background-color';
import { Blockquote } from 'tiptap/core/extensions/blockquote';
import { Bold } from 'tiptap/core/extensions/bold';
import { BulletList } from 'tiptap/core/extensions/bullet-list';
2022-05-16 09:23:59 +00:00
import { Callout } from 'tiptap/core/extensions/callout';
2022-06-13 10:03:45 +00:00
import { Clipboard } from 'tiptap/core/extensions/clipboard';
import { Code, CodeMarkPlugin } from 'tiptap/core/extensions/code';
2022-05-03 16:52:33 +00:00
import { CodeBlock } from 'tiptap/core/extensions/code-block';
import { Color } from 'tiptap/core/extensions/color';
import { ColorHighlighter } from 'tiptap/core/extensions/color-highlighter';
2022-05-16 09:23:59 +00:00
import { Countdown } from 'tiptap/core/extensions/countdown';
// 基础扩展
import { Document } from 'tiptap/core/extensions/document';
import { DocumentChildren } from 'tiptap/core/extensions/document-children';
import { DocumentReference } from 'tiptap/core/extensions/document-reference';
2022-05-03 16:52:33 +00:00
import { Dropcursor } from 'tiptap/core/extensions/dropcursor';
2022-05-16 09:23:59 +00:00
import { Emoji } from 'tiptap/core/extensions/emoji';
2022-05-03 16:52:33 +00:00
import { EventEmitter } from 'tiptap/core/extensions/event-emitter';
2022-05-16 09:23:59 +00:00
import { Flow } from 'tiptap/core/extensions/flow';
2022-05-03 16:52:33 +00:00
import { Focus } from 'tiptap/core/extensions/focus';
import { FontSize } from 'tiptap/core/extensions/font-size';
import { Gapcursor } from 'tiptap/core/extensions/gapcursor';
import { HardBreak } from 'tiptap/core/extensions/hard-break';
import { Heading } from 'tiptap/core/extensions/heading';
import { HorizontalRule } from 'tiptap/core/extensions/horizontal-rule';
import { HTMLMarks } from 'tiptap/core/extensions/html-marks';
2022-05-16 09:23:59 +00:00
import { Iframe } from 'tiptap/core/extensions/iframe';
2022-05-03 16:52:33 +00:00
import { Image } from 'tiptap/core/extensions/image';
import { Indent } from 'tiptap/core/extensions/indent';
import { Italic } from 'tiptap/core/extensions/italic';
2022-05-16 09:23:59 +00:00
import { Katex } from 'tiptap/core/extensions/katex';
2022-05-03 16:52:33 +00:00
import { Link } from 'tiptap/core/extensions/link';
import { ListItem } from 'tiptap/core/extensions/listItem';
import { Loading } from 'tiptap/core/extensions/loading';
2022-05-16 09:23:59 +00:00
import { Mention } from 'tiptap/core/extensions/mention';
import { Mind } from 'tiptap/core/extensions/mind';
2022-05-03 16:52:33 +00:00
import { OrderedList } from 'tiptap/core/extensions/ordered-list';
import { Paragraph } from 'tiptap/core/extensions/paragraph';
2022-05-16 09:23:59 +00:00
import { Paste } from 'tiptap/core/extensions/paste';
2022-05-03 16:52:33 +00:00
import { Placeholder } from 'tiptap/core/extensions/placeholder';
2022-05-16 09:23:59 +00:00
import { QuickInsert } from 'tiptap/core/extensions/quick-insert';
2022-05-04 09:20:06 +00:00
import { ScrollIntoView } from 'tiptap/core/extensions/scroll-into-view';
2022-05-16 09:23:59 +00:00
import { SearchNReplace } from 'tiptap/core/extensions/search';
import { SelectionExtension } from 'tiptap/core/extensions/selection';
import { Status } from 'tiptap/core/extensions/status';
2022-05-03 16:52:33 +00:00
import { Strike } from 'tiptap/core/extensions/strike';
import { Subscript } from 'tiptap/core/extensions/subscript';
import { Superscript } from 'tiptap/core/extensions/superscript';
import { Table } from 'tiptap/core/extensions/table';
import { TableCell } from 'tiptap/core/extensions/table-cell';
import { TableHeader } from 'tiptap/core/extensions/table-header';
2022-05-16 09:23:59 +00:00
import { TableOfContents } from 'tiptap/core/extensions/table-of-contents';
2022-05-03 16:52:33 +00:00
import { TableRow } from 'tiptap/core/extensions/table-row';
2022-05-16 09:23:59 +00:00
import { TaskItem } from 'tiptap/core/extensions/task-item';
import { TaskList } from 'tiptap/core/extensions/task-list';
2022-05-03 16:52:33 +00:00
import { Text } from 'tiptap/core/extensions/text';
import { TextAlign } from 'tiptap/core/extensions/text-align';
import { TextStyle } from 'tiptap/core/extensions/text-style';
import { Title } from 'tiptap/core/extensions/title';
import { TrailingNode } from 'tiptap/core/extensions/trailing-node';
import { Underline } from 'tiptap/core/extensions/underline';
// markdown 支持
import { markdownToProsemirror } from 'tiptap/markdown/markdown-to-prosemirror';
import { markdownToHTML } from 'tiptap/markdown/markdown-to-prosemirror/markdown-to-html';
import { prosemirrorToMarkdown } from 'tiptap/markdown/prosemirror-to-markdown';
const DocumentWithTitle = Document.extend({
content: 'title block+',
});
export const CollaborationKit = [
Paragraph,
Placeholder.configure({
placeholder: ({ node, editor }) => {
if (node.type.name === 'title') {
return editor.isEditable ? '请输入标题' : '未命名文档';
2022-05-03 16:52:33 +00:00
}
if (!editor.isEditable) return;
2022-05-03 16:52:33 +00:00
return '输入 / 唤起更多';
},
showOnlyCurrent: false,
showOnlyWhenEditable: false,
2022-05-03 16:52:33 +00:00
}),
BackgroundColor,
Blockquote,
Bold,
BulletList,
2022-06-13 10:03:45 +00:00
Clipboard.configure({
prosemirrorToMarkdown,
}),
2022-05-03 16:52:33 +00:00
Code,
CodeMarkPlugin,
2022-05-03 16:52:33 +00:00
CodeBlock,
Color,
ColorHighlighter,
Dropcursor,
EventEmitter,
Focus,
FontSize,
Gapcursor,
HardBreak,
Heading,
HorizontalRule,
...HTMLMarks,
Image,
Indent,
Italic,
Link,
ListItem,
Loading,
OrderedList,
SelectionExtension,
2022-05-05 09:48:21 +00:00
ScrollIntoView,
2022-05-03 16:52:33 +00:00
Strike,
Subscript,
Superscript,
Table,
TableCell,
TableHeader,
TableRow,
Text,
TextAlign,
TextStyle,
TaskItem,
TaskList,
TrailingNode,
Underline,
Paste.configure({
markdownToHTML,
markdownToProsemirror,
prosemirrorToMarkdown,
}),
Attachment,
Callout,
Countdown,
DocumentChildren,
DocumentReference,
Emoji,
2022-05-11 06:05:11 +00:00
Flow,
2022-05-03 16:52:33 +00:00
Iframe,
Katex,
Mention,
Mind,
QuickInsert,
SearchNReplace,
Status,
2022-05-10 07:00:38 +00:00
TableOfContents.configure({
onHasOneBeforeInsert: () => {
Toast.info('目录已存在');
},
}),
2022-05-03 16:52:33 +00:00
Title,
DocumentWithTitle,
];