chore: Upgrade all of prosemirror (#5366)
Co-authored-by: Apoorv Mishra <apoorvmishra101092@gmail.com>
This commit is contained in:
@@ -13,13 +13,12 @@ export default function markdownToYDoc(
|
||||
// in the editor embeds were created at runtime by converting links
|
||||
// into embeds where they match. Because we're converting to a CRDT structure
|
||||
// on the server we need to mimic this behavior.
|
||||
function urlsToEmbeds(node: Node): Node {
|
||||
function urlsToEmbeds(node: Node): Node | null {
|
||||
if (node.type.name === "paragraph") {
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'content' does not exist on type 'Fragmen... Remove this comment to see the full error message
|
||||
for (const textNode of node.content.content) {
|
||||
for (const embed of embeds) {
|
||||
if (textNode.text && embed.matcher(textNode.text)) {
|
||||
// @ts-expect-error ts-migrate(2322) FIXME: Type 'ProsemirrorNode<Schema<never, never>> | null... Remove this comment to see the full error message
|
||||
return schema.nodes.embed.createAndFill({
|
||||
href: textNode.text,
|
||||
});
|
||||
@@ -30,14 +29,19 @@ export default function markdownToYDoc(
|
||||
|
||||
if (node.content) {
|
||||
const contentAsArray =
|
||||
// @ts-expect-error ts-migrate(2339) FIXME: Property 'content' does not exist on type 'Fragmen... Remove this comment to see the full error message
|
||||
// @ts-expect-error content
|
||||
node.content instanceof Fragment ? node.content.content : node.content;
|
||||
// @ts-expect-error content
|
||||
node.content = Fragment.fromArray(contentAsArray.map(urlsToEmbeds));
|
||||
}
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
node = urlsToEmbeds(node);
|
||||
if (node) {
|
||||
node = urlsToEmbeds(node);
|
||||
}
|
||||
|
||||
// @ts-expect-error null node
|
||||
return prosemirrorToYDoc(node, fieldName);
|
||||
}
|
||||
|
||||
@@ -3,7 +3,7 @@ import { parser } from ".";
|
||||
test("renders an empty doc", () => {
|
||||
const ast = parser.parse("");
|
||||
|
||||
expect(ast.toJSON()).toEqual({
|
||||
expect(ast?.toJSON()).toEqual({
|
||||
content: [{ type: "paragraph" }],
|
||||
type: "doc",
|
||||
});
|
||||
|
||||
@@ -54,7 +54,7 @@ export default class DocumentHelper {
|
||||
Y.applyUpdate(ydoc, document.state);
|
||||
return Node.fromJSON(schema, yDocToProsemirrorJSON(ydoc, "default"));
|
||||
}
|
||||
return parser.parse(document.text);
|
||||
return parser.parse(document.text) || Node.fromJSON(schema, {});
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -12,6 +12,9 @@ import { parser } from "@server/editor";
|
||||
export default function parseDocumentIds(text: string): string[] {
|
||||
const doc = parser.parse(text);
|
||||
const identifiers: string[] = [];
|
||||
if (!doc) {
|
||||
return identifiers;
|
||||
}
|
||||
|
||||
doc.descendants((node: Node) => {
|
||||
// get text nodes
|
||||
|
||||
@@ -4,6 +4,9 @@ import { parser } from "@server/editor";
|
||||
export default function parseImages(text: string): string[] {
|
||||
const doc = parser.parse(text);
|
||||
const images: string[] = [];
|
||||
if (!doc) {
|
||||
return images;
|
||||
}
|
||||
|
||||
doc.descendants((node: Node) => {
|
||||
if (node.type.name === "image") {
|
||||
|
||||
Reference in New Issue
Block a user