mirror of
https://github.com/Blah-IM/Weblah.git
synced 2025-08-20 19:12:40 +00:00
refactor[wip]: replace typewriter-editor with ProseMirror for rich text editing
This commit is contained in:
parent
7299c1dee0
commit
cd6a8e392e
4 changed files with 167 additions and 45 deletions
23
src/lib/components/RichTextInput/editorState.ts
Normal file
23
src/lib/components/RichTextInput/editorState.ts
Normal 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;
|
||||
}
|
31
src/lib/components/RichTextInput/schema.ts
Normal file
31
src/lib/components/RichTextInput/schema.ts
Normal 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]
|
||||
}
|
||||
}
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue