chore: Editor refactor (#3286)

* cleanup

* add context

* EventEmitter allows removal of toolbar props from extensions

* Move to 'packages' of extensions
Remove EmojiTrigger extension

* types

* iteration

* fix render flashing

* fix: Missing nodes in collection descriptions
This commit is contained in:
Tom Moor
2022-03-30 19:10:34 -07:00
committed by GitHub
parent c5b9a742c0
commit 6f2a4488e8
30 changed files with 517 additions and 581 deletions

View File

@@ -7,6 +7,7 @@ import { Decoration, DecorationSet, EditorView } from "prosemirror-view";
import * as React from "react";
import ReactDOM from "react-dom";
import Extension from "../lib/Extension";
import { EventType } from "../types";
const MAX_MATCH = 500;
const OPEN_REGEX = /^\/(\w+)?$/;
@@ -65,7 +66,7 @@ export default class BlockMenuTrigger extends Extension {
new Plugin({
props: {
handleClick: () => {
this.options.onClose();
this.editor.events.emit(EventType.blockMenuClose);
return false;
},
handleKeyDown: (view, event) => {
@@ -79,9 +80,9 @@ export default class BlockMenuTrigger extends Extension {
const { pos } = view.state.selection.$from;
return run(view, pos, pos, OPEN_REGEX, (state, match) => {
if (match) {
this.options.onOpen(match[1]);
this.editor.events.emit(EventType.blockMenuOpen, match[1]);
} else {
this.options.onClose();
this.editor.events.emit(EventType.blockMenuClose);
}
return null;
});
@@ -125,7 +126,7 @@ export default class BlockMenuTrigger extends Extension {
decorations.push(
Decoration.widget(parent.pos, () => {
button.addEventListener("click", () => {
this.options.onOpen("");
this.editor.events.emit(EventType.blockMenuOpen, "");
});
return button;
})
@@ -176,7 +177,7 @@ export default class BlockMenuTrigger extends Extension {
state.selection.$from.parent.type.name === "paragraph" &&
!isInTable(state)
) {
this.options.onOpen(match[1]);
this.editor.events.emit(EventType.blockMenuOpen, match[1]);
}
return null;
}),
@@ -186,7 +187,7 @@ export default class BlockMenuTrigger extends Extension {
// /word<space>
new InputRule(CLOSE_REGEX, (state, match) => {
if (match) {
this.options.onClose();
this.editor.events.emit(EventType.blockMenuClose);
}
return null;
}),