mirror of
https://github.com/outline/outline.git
synced 2026-11-21 05:24:03 +03:00
* perf: Keep vendor-prosemirror out of the eager authenticated bundle Split the data-only helpers `getEmpty` and `isEmpty` out of `ProsemirrorHelper` into a new prosemirror-free `ProsemirrorDataHelper` module, and point the sidebar, DocumentNew, and other lightweight callers at it. This removes the static edge from the authenticated entry graph to `prosemirror-model`, deferring the ~653 KB vendor-prosemirror chunk until an editor surface is actually opened. Fixes #13005 Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> * Use non-optional collection.data in defined branch Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com> --------- Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
48 lines
1018 B
TypeScript
48 lines
1018 B
TypeScript
import type { ProsemirrorData } from "../types";
|
|
|
|
/**
|
|
* Helpers that operate on plain `ProsemirrorData` JSON.
|
|
*/
|
|
export class ProsemirrorDataHelper {
|
|
/**
|
|
* Get a new empty document.
|
|
*
|
|
* @returns a new empty document as JSON.
|
|
*/
|
|
static getEmpty(): ProsemirrorData {
|
|
return {
|
|
type: "doc",
|
|
content: [
|
|
{
|
|
content: [],
|
|
type: "paragraph",
|
|
},
|
|
],
|
|
};
|
|
}
|
|
|
|
/**
|
|
* Returns true if the data looks like an empty document.
|
|
*
|
|
* @param data The ProsemirrorData to check.
|
|
* @returns True if the document is empty.
|
|
*/
|
|
static isEmpty(data: ProsemirrorData): boolean {
|
|
if (data.type !== "doc") {
|
|
return false;
|
|
}
|
|
|
|
if (data.content?.length === 1) {
|
|
const node = data.content[0];
|
|
return (
|
|
node.type === "paragraph" &&
|
|
(node.content === null ||
|
|
node.content === undefined ||
|
|
node.content.length === 0)
|
|
);
|
|
}
|
|
|
|
return !data.content || data.content.length === 0;
|
|
}
|
|
}
|