feat: Add @mention support to comments (#5001)

* Refactor, remove confusing 'packages' language

* Basic notifications when mentioned in comment

* fix: Incorrect trimming of comments

* test
This commit is contained in:
Tom Moor
2023-03-06 22:19:49 -05:00
committed by GitHub
parent 28c4854985
commit d3b099819d
18 changed files with 301 additions and 220 deletions

View File

@@ -1,4 +1,5 @@
import { Node } from "prosemirror-model";
import { Node, Schema } from "prosemirror-model";
import textBetween from "@shared/editor/lib/textBetween";
import headingToSlug from "../editor/lib/headingToSlug";
export type Heading = {
@@ -25,6 +26,23 @@ export type Task = {
};
export default class ProsemirrorHelper {
/**
* Returns the node as plain text.
*
* @param node The node to convert.
* @param schema The schema to use.
* @returns The document content as plain text without formatting.
*/
static toPlainText(node: Node, schema: Schema) {
const textSerializers = Object.fromEntries(
Object.entries(schema.nodes)
.filter(([, node]) => node.spec.toPlainText)
.map(([name, node]) => [name, node.spec.toPlainText])
);
return textBetween(node, 0, node.content.size, textSerializers);
}
/**
* Removes any empty paragraphs from the beginning and end of the document.
*
@@ -34,9 +52,11 @@ export default class ProsemirrorHelper {
const first = doc.firstChild;
const last = doc.lastChild;
const firstIsEmpty =
first?.type.name === "paragraph" && !first.textContent.trim();
first &&
ProsemirrorHelper.toPlainText(first, doc.type.schema).trim() === "";
const lastIsEmpty =
last?.type.name === "paragraph" && !last.textContent.trim();
last &&
ProsemirrorHelper.toPlainText(last, doc.type.schema).trim() === "";
const firstIsLast = first === last;
return doc.cut(