refactor[wip]: replace typewriter-editor with ProseMirror for rich text editing

This commit is contained in:
Shibo Lyu 2025-04-02 01:17:09 +08:00
parent 7299c1dee0
commit cd6a8e392e
4 changed files with 167 additions and 45 deletions

View file

@ -0,0 +1,23 @@
import { EditorState } from 'prosemirror-state';
import { history, undo, redo } from 'prosemirror-history';
import { keymap } from 'prosemirror-keymap';
import { baseKeymap } from 'prosemirror-commands';
import { messageSchema } from './schema';
export function createMessageEditorState() {
const state = EditorState.create({
schema: messageSchema,
plugins: [
history(),
keymap({
'Mod-z': undo,
'Mod-y': redo,
'Mod-Shift-z': redo
}),
keymap(baseKeymap)
]
});
return state;
}

View file

@ -0,0 +1,31 @@
import { Schema } from 'prosemirror-model';
import { nodes as basicNodes, marks as basicMarks } from 'prosemirror-schema-basic';
export const messageSchema = new Schema({
nodes: {
doc: { content: 'block' }, // For now we only support a single block
paragragh: {
content: 'inline*'
},
text: basicNodes.text
},
marks: {
...basicMarks,
underline: {
parseDOM: [{ tag: 'u' }],
toDOM: () => ['u', 0]
},
strikethrough: {
parseDOM: [{ tag: 's' }],
toDOM: () => ['s', 0]
},
tag: {
parseDOM: [{ tag: 'span[data-weblah-tag]' }],
toDOM: () => ['span', { 'data-weblah-richtext-tag': true }, 0]
},
spoiler: {
parseDOM: [{ tag: 'span[data-weblah-spoiler]' }],
toDOM: () => ['span', { 'data-weblah-richtext-spoiler': true }, 0]
}
}
});