@liveblocks/node-prosemirror 3.14.0-pre4 → 3.14.0-types1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -3,7 +3,7 @@ var _core = require('@liveblocks/core');
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node-prosemirror";
6
- var PKG_VERSION = "3.14.0-pre4";
6
+ var PKG_VERSION = "3.14.0-types1";
7
7
  var PKG_FORMAT = "cjs";
8
8
 
9
9
  // src/document.ts
@@ -1 +1 @@
1
- {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-node-prosemirror/dist/index.cjs","../src/index.ts","../src/version.ts","../src/document.ts","../src/comment.ts","../src/group-mention.ts","../src/mention.ts"],"names":["mergeAttributes","Node"],"mappings":"AAAA;ACAA,wCAA4B;ADE5B;AACA;AEAO,IAAM,SAAA,EAAW,8BAAA;AACjB,IAAM,YAAA,EAAiD,aAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;AFE7D;AACA;AGNA,qCAAmC;AAGnC,yCAA4B;AAC5B,yGAAuB;AAEvB,2DAA0C;AAC1C,6CAAoD;AACpD,0BAAyE;AHKzE;AACA;AIhBA;AAEO,IAAM,6BAAA,EAA+B,uBAAA;AAErC,IAAM,iBAAA,EAAmB,WAAA,CAAK,MAAA,CAAO;AAAA,EAC1C,IAAA,EAAM,4BAAA;AAAA,EACN,QAAA,EAAU,EAAA;AAAA,EACV,SAAA,EAAW,KAAA;AAAA,EACX,WAAA,EAAa,IAAA;AAAA,EACb,aAAA,CAAA,EAAgB;AAEd,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ;AAAA,QACN,SAAA,EAAW,CAAC,OAAA,EAAA,GAAY,CAAC,CAAC,OAAA,CAAQ,YAAA,CAAa,aAAa,CAAA;AAAA,QAC5D,UAAA,EAAY,CAAC,UAAA,EAAA,GAAe;AAC1B,UAAA,OAAQ,UAAA,CAA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GAAA;AACT;AHuFA;AACA;ACxTA,+BAAA,QAAY,EAAU,WAAA,EAAa,UAAU,CAAA;AD0T7C;AACE;AACF,0DAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-node-prosemirror/dist/index.cjs","sourcesContent":[null,"import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\nexport type {\n LiveblocksDocumentApi,\n LiveblocksProsemirrorOptions,\n} from \"./document\";\nexport { withProsemirrorDocument } from \"./document\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/node-prosemirror\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import type { Liveblocks } from \"@liveblocks/node\";\nimport type { TextSerializer } from \"@tiptap/core\";\nimport { getSchema, getText } from \"@tiptap/core\";\nimport type { Node, Schema } from \"@tiptap/pm/model\";\nimport type { Transaction } from \"@tiptap/pm/state\";\nimport { EditorState } from \"@tiptap/pm/state\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport type { MarkdownSerializer } from \"prosemirror-markdown\";\nimport { defaultMarkdownSerializer } from \"prosemirror-markdown\";\nimport { initProseMirrorDoc, updateYFragment } from \"y-prosemirror\";\nimport { applyUpdate, Doc, encodeStateAsUpdate, encodeStateVector } from \"yjs\";\n\nimport { CommentExtension } from \"./comment\";\nimport { GroupMentionExtension } from \"./group-mention\";\nimport { MentionExtension } from \"./mention\";\n\nexport type LiveblocksProsemirrorOptions = {\n roomId: string;\n schema?: Schema;\n client: Liveblocks;\n field?: string;\n};\n\nexport type LiveblocksDocumentApi = {\n refresh: () => Promise<void>;\n update: (\n modifyFn: (doc: Node, tr: Transaction) => Transaction\n ) => Promise<void>;\n setContent: (content: null | object | string) => Promise<void>;\n clearContent: () => Promise<void>;\n getText: (options?: {\n blockSeparator?: string;\n textSerializers?: Record<string, TextSerializer>;\n }) => string;\n getEditorState: () => EditorState;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON: () => any; // upstream ProseMirror uses \"any\"\n toMarkdown: () => string;\n};\n\nconst DEFAULT_SCHEMA = getSchema([\n CommentExtension,\n MentionExtension,\n StarterKit,\n GroupMentionExtension,\n]);\n\nconst getLiveblocksDocumentState = async (\n roomId: string,\n client: Liveblocks,\n schema: Schema,\n field: string\n) => {\n const update = new Uint8Array(\n await client.getYjsDocumentAsBinaryUpdate(roomId)\n );\n const ydoc = new Doc();\n applyUpdate(ydoc, update);\n const fragment = ydoc.getXmlFragment(field ?? \"default\");\n const { mapping, doc } = initProseMirrorDoc(fragment, schema);\n const state = EditorState.create({\n schema,\n doc,\n });\n\n return {\n fragment,\n state,\n ydoc,\n mapping,\n };\n};\n\n/**\n *\n * This is simplified re-implementation of TipTap's createDocument function\n *\n * @param content\n * @param schema\n * @param parseOptions\n * @returns\n */\nconst createDocumentFromContent = (content: object, schema: Schema) => {\n try {\n return schema.nodeFromJSON(content);\n } catch (error) {\n console.warn(\n \"[warn]: Invalid content.\",\n \"Passed value:\",\n content,\n \"Error:\",\n error\n );\n return false;\n }\n};\n\n/**\n *\n * `withProsemirrorDocument` is the main entry point to access and modify prosemirror (or TipTap) documents on your backend.\n * This function internally instantiates a Prosemirror state and allows you to modify and export its values asynchronously\n * with a simplified interface. It's important to note that the api works with Prosemirror's document state and Transactions api.\n *\n * @param options Specify the roomId, client, and optionally the prosemirror schema. If no schema is applied, a default schema of TipTap's StarterKit + Liveblocks mentions/comments is used.\n * @param callback The call back function is optionally async and receives the document API as its only argument.\n *\n * @example\n *\n * import { Liveblocks } from \"@liveblocks/node\";\n * import { withProsemirrorDocument } from \"@liveblocks/node-prosemirror\";\n *\n * const client = new Liveblocks({secret: \"sk_your_secret_key\"});\n * const text = await withProsemirrorDocument(\n * { client, roomId: \"your-room\" },\n * async (docApi) => {\n * await docApi.update((tr) => {\n * return tr.insertText(\"Hello World, from Liveblocks!!\", 0);\n * });\n * return docApi.getTextContent();\n * }\n * );\n *\n */\nexport async function withProsemirrorDocument<T>(\n { roomId, schema: maybeSchema, client, field }: LiveblocksProsemirrorOptions,\n callback: (api: LiveblocksDocumentApi) => Promise<T> | T\n): Promise<T> {\n const schema = maybeSchema ?? DEFAULT_SCHEMA;\n let liveblocksState = await getLiveblocksDocumentState(\n roomId,\n client,\n schema,\n field ?? \"default\"\n );\n\n const val = await callback({\n /**\n * Fetches and resyncs the latest document with Liveblocks\n */\n async refresh() {\n liveblocksState = await getLiveblocksDocumentState(\n roomId,\n client,\n schema,\n field ?? \"default\"\n );\n },\n /**\n * Provide a callback to modify documetns with prosemirrors's standard api.\n */\n async update(modifyFn) {\n const { ydoc, fragment, state, mapping } = liveblocksState;\n // Flush any pending updates (there really shouldn't be any?), this may be a NOOP\n const beforeVector = encodeStateVector(ydoc);\n const afterState = state.apply(modifyFn(state.doc, state.tr));\n ydoc.transact(() => {\n updateYFragment(ydoc, fragment, afterState.doc, {\n mapping,\n isOMark: new Map(),\n });\n });\n // grab update after diffing\n const diffUpdate = encodeStateAsUpdate(ydoc, beforeVector);\n await client.sendYjsBinaryUpdate(roomId, diffUpdate);\n await this.refresh();\n },\n\n /**\n * allows you to set content similar to TipTap's setcontent. Only accepts nulls, objects or strings.\n * Unlike TipTap, strings won't be parsed with DOMParser\n * */\n async setContent(content: null | object | string) {\n if (typeof content === \"string\") {\n return this.update((doc, tr) => {\n tr.delete(0, doc.content.size);\n tr.insertText(content);\n return tr;\n });\n }\n if (content === null) {\n return this.clearContent();\n }\n const node = createDocumentFromContent(content, schema);\n if (!node) {\n throw \"Invalid content\";\n }\n return this.update((doc, tr) => {\n tr.delete(0, doc.content.size);\n tr.insert(0, node);\n return tr;\n });\n },\n async clearContent() {\n await this.update((doc, tr) => {\n tr.delete(0, doc.content.size);\n return tr;\n });\n },\n\n /**\n * Uses TipTap's getText function, which allows passing a custom text serializer\n */\n getText(options?: {\n blockSeparator?: string;\n textSerializers?: Record<string, TextSerializer>;\n }) {\n const { state } = liveblocksState;\n return getText(state.doc, options);\n },\n\n /**\n * Helper function to return prosemirror document in JSON form\n */\n toJSON() {\n // upstream ProseMirror uses \"any\" type for json\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return liveblocksState.state.doc.toJSON();\n },\n /**\n * Helper function to return editor state as Markdown. By default it uses the defaultMarkdownSerializer from prosemirror-markdown, but you may pass your own\n */\n toMarkdown(serializer?: MarkdownSerializer) {\n return (serializer ?? defaultMarkdownSerializer).serialize(\n liveblocksState.state.doc\n );\n },\n /**\n * Helper function to return the editor's current prosemirror state\n */\n getEditorState() {\n return liveblocksState.state;\n },\n });\n return val;\n}\n","import { Mark, mergeAttributes } from \"@tiptap/core\";\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\nexport const CommentExtension = Mark.create({\n name: LIVEBLOCKS_COMMENT_MARK_TYPE,\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n addAttributes() {\n // Return an object with attribute configuration\n return {\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-lb-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-lb-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, unknown> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"lb-root lb-tiptap-thread-mark\",\n }),\n ];\n },\n});\n","import { mergeAttributes, Node } from \"@tiptap/core\";\n\nexport const LIVEBLOCKS_GROUP_MENTION_TYPE = \"liveblocksGroupMention\";\n\nexport const GroupMentionExtension = Node.create({\n name: LIVEBLOCKS_GROUP_MENTION_TYPE,\n group: \"inline\",\n inline: true,\n selectable: true,\n atom: true,\n\n priority: 101,\n parseHTML() {\n return [\n {\n tag: \"liveblocks-group-mention\",\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\"liveblocks-group-mention\", mergeAttributes(HTMLAttributes)];\n },\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-id\"),\n renderHTML: (attributes) => {\n if (!attributes.id) {\n return {};\n }\n\n return {\n \"data-id\": attributes.id as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n userIds: {\n default: null,\n parseHTML: (element) => {\n const userIdsAttribute = element.getAttribute(\"data-user-ids\");\n\n if (!userIdsAttribute) {\n return null;\n }\n\n try {\n const userIds = JSON.parse(userIdsAttribute) as string[];\n\n return Array.isArray(userIds) ? userIds : null;\n } catch {\n return null;\n }\n },\n renderHTML: (attributes) => {\n if (!attributes.userIds || !Array.isArray(attributes.userIds)) {\n return {};\n }\n\n return {\n \"data-user-ids\": JSON.stringify(attributes.userIds),\n };\n },\n },\n notificationId: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-notification-id\"),\n renderHTML: (attributes) => {\n if (!attributes.notificationId) {\n return {};\n }\n\n return {\n \"data-notification-id\": attributes.notificationId as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n };\n },\n});\n","import { mergeAttributes, Node } from \"@tiptap/core\";\n\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const MentionExtension = Node.create({\n name: LIVEBLOCKS_MENTION_TYPE,\n group: \"inline\",\n inline: true,\n selectable: true,\n atom: true,\n\n priority: 101,\n parseHTML() {\n return [\n {\n tag: \"liveblocks-mention\",\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\"liveblocks-mention\", mergeAttributes(HTMLAttributes)];\n },\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-id\"),\n renderHTML: (attributes) => {\n if (!attributes.id) {\n return {};\n }\n\n return {\n \"data-id\": attributes.id as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n notificationId: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-notification-id\"),\n renderHTML: (attributes) => {\n if (!attributes.notificationId) {\n return {};\n }\n\n return {\n \"data-notification-id\": attributes.notificationId as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n };\n },\n});\n"]}
1
+ {"version":3,"sources":["/home/runner/work/liveblocks/liveblocks/packages/liveblocks-node-prosemirror/dist/index.cjs","../src/index.ts","../src/version.ts","../src/document.ts","../src/comment.ts","../src/group-mention.ts","../src/mention.ts"],"names":["mergeAttributes","Node"],"mappings":"AAAA;ACAA,wCAA4B;ADE5B;AACA;AEAO,IAAM,SAAA,EAAW,8BAAA;AACjB,IAAM,YAAA,EAAiD,eAAA;AACvD,IAAM,WAAA,EAAgD,KAAA;AFE7D;AACA;AGNA,qCAAmC;AAGnC,yCAA4B;AAC5B,yGAAuB;AAEvB,2DAA0C;AAC1C,6CAAoD;AACpD,0BAAyE;AHKzE;AACA;AIhBA;AAEO,IAAM,6BAAA,EAA+B,uBAAA;AAErC,IAAM,iBAAA,EAAmB,WAAA,CAAK,MAAA,CAAO;AAAA,EAC1C,IAAA,EAAM,4BAAA;AAAA,EACN,QAAA,EAAU,EAAA;AAAA,EACV,SAAA,EAAW,KAAA;AAAA,EACX,WAAA,EAAa,IAAA;AAAA,EACb,aAAA,CAAA,EAAgB;AAEd,IAAA,OAAO;AAAA,MACL,MAAA,EAAQ;AAAA,QACN,SAAA,EAAW,CAAC,OAAA,EAAA,GAAY,CAAC,CAAC,OAAA,CAAQ,YAAA,CAAa,aAAa,CAAA;AAAA,QAC5D,UAAA,EAAY,CAAC,UAAA,EAAA,GAAe;AAC1B,UAAA,OAAQ,UAAA,CAAmC,OAAA,EACvC;AAAA,YACE,aA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,+BAAA,QAAY,EAAU,WAAA,EAAa,UAAU,CAAA;AD0T7C;AACE;AACF,0DAAC","file":"/home/runner/work/liveblocks/liveblocks/packages/liveblocks-node-prosemirror/dist/index.cjs","sourcesContent":[null,"import { detectDupes } from \"@liveblocks/core\";\n\nimport { PKG_FORMAT, PKG_NAME, PKG_VERSION } from \"./version\";\n\nexport type {\n LiveblocksDocumentApi,\n LiveblocksProsemirrorOptions,\n} from \"./document\";\nexport { withProsemirrorDocument } from \"./document\";\n\ndetectDupes(PKG_NAME, PKG_VERSION, PKG_FORMAT);\n","declare const __VERSION__: string;\ndeclare const TSUP_FORMAT: string;\n\nexport const PKG_NAME = \"@liveblocks/node-prosemirror\";\nexport const PKG_VERSION = typeof __VERSION__ === \"string\" && __VERSION__;\nexport const PKG_FORMAT = typeof TSUP_FORMAT === \"string\" && TSUP_FORMAT;\n","import type { Liveblocks } from \"@liveblocks/node\";\nimport type { TextSerializer } from \"@tiptap/core\";\nimport { getSchema, getText } from \"@tiptap/core\";\nimport type { Node, Schema } from \"@tiptap/pm/model\";\nimport type { Transaction } from \"@tiptap/pm/state\";\nimport { EditorState } from \"@tiptap/pm/state\";\nimport StarterKit from \"@tiptap/starter-kit\";\nimport type { MarkdownSerializer } from \"prosemirror-markdown\";\nimport { defaultMarkdownSerializer } from \"prosemirror-markdown\";\nimport { initProseMirrorDoc, updateYFragment } from \"y-prosemirror\";\nimport { applyUpdate, Doc, encodeStateAsUpdate, encodeStateVector } from \"yjs\";\n\nimport { CommentExtension } from \"./comment\";\nimport { GroupMentionExtension } from \"./group-mention\";\nimport { MentionExtension } from \"./mention\";\n\nexport type LiveblocksProsemirrorOptions = {\n roomId: string;\n schema?: Schema;\n client: Liveblocks;\n field?: string;\n};\n\nexport type LiveblocksDocumentApi = {\n refresh: () => Promise<void>;\n update: (\n modifyFn: (doc: Node, tr: Transaction) => Transaction\n ) => Promise<void>;\n setContent: (content: null | object | string) => Promise<void>;\n clearContent: () => Promise<void>;\n getText: (options?: {\n blockSeparator?: string;\n textSerializers?: Record<string, TextSerializer>;\n }) => string;\n getEditorState: () => EditorState;\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n toJSON: () => any; // upstream ProseMirror uses \"any\"\n toMarkdown: () => string;\n};\n\nconst DEFAULT_SCHEMA = getSchema([\n CommentExtension,\n MentionExtension,\n StarterKit,\n GroupMentionExtension,\n]);\n\nconst getLiveblocksDocumentState = async (\n roomId: string,\n client: Liveblocks,\n schema: Schema,\n field: string\n) => {\n const update = new Uint8Array(\n await client.getYjsDocumentAsBinaryUpdate(roomId)\n );\n const ydoc = new Doc();\n applyUpdate(ydoc, update);\n const fragment = ydoc.getXmlFragment(field ?? \"default\");\n const { mapping, doc } = initProseMirrorDoc(fragment, schema);\n const state = EditorState.create({\n schema,\n doc,\n });\n\n return {\n fragment,\n state,\n ydoc,\n mapping,\n };\n};\n\n/**\n *\n * This is simplified re-implementation of TipTap's createDocument function\n *\n * @param content\n * @param schema\n * @param parseOptions\n * @returns\n */\nconst createDocumentFromContent = (content: object, schema: Schema) => {\n try {\n return schema.nodeFromJSON(content);\n } catch (error) {\n console.warn(\n \"[warn]: Invalid content.\",\n \"Passed value:\",\n content,\n \"Error:\",\n error\n );\n return false;\n }\n};\n\n/**\n *\n * `withProsemirrorDocument` is the main entry point to access and modify prosemirror (or TipTap) documents on your backend.\n * This function internally instantiates a Prosemirror state and allows you to modify and export its values asynchronously\n * with a simplified interface. It's important to note that the api works with Prosemirror's document state and Transactions api.\n *\n * @param options Specify the roomId, client, and optionally the prosemirror schema. If no schema is applied, a default schema of TipTap's StarterKit + Liveblocks mentions/comments is used.\n * @param callback The call back function is optionally async and receives the document API as its only argument.\n *\n * @example\n *\n * import { Liveblocks } from \"@liveblocks/node\";\n * import { withProsemirrorDocument } from \"@liveblocks/node-prosemirror\";\n *\n * const client = new Liveblocks({secret: \"sk_your_secret_key\"});\n * const text = await withProsemirrorDocument(\n * { client, roomId: \"your-room\" },\n * async (docApi) => {\n * await docApi.update((tr) => {\n * return tr.insertText(\"Hello World, from Liveblocks!!\", 0);\n * });\n * return docApi.getTextContent();\n * }\n * );\n *\n */\nexport async function withProsemirrorDocument<T>(\n { roomId, schema: maybeSchema, client, field }: LiveblocksProsemirrorOptions,\n callback: (api: LiveblocksDocumentApi) => Promise<T> | T\n): Promise<T> {\n const schema = maybeSchema ?? DEFAULT_SCHEMA;\n let liveblocksState = await getLiveblocksDocumentState(\n roomId,\n client,\n schema,\n field ?? \"default\"\n );\n\n const val = await callback({\n /**\n * Fetches and resyncs the latest document with Liveblocks\n */\n async refresh() {\n liveblocksState = await getLiveblocksDocumentState(\n roomId,\n client,\n schema,\n field ?? \"default\"\n );\n },\n /**\n * Provide a callback to modify documetns with prosemirrors's standard api.\n */\n async update(modifyFn) {\n const { ydoc, fragment, state, mapping } = liveblocksState;\n // Flush any pending updates (there really shouldn't be any?), this may be a NOOP\n const beforeVector = encodeStateVector(ydoc);\n const afterState = state.apply(modifyFn(state.doc, state.tr));\n ydoc.transact(() => {\n updateYFragment(ydoc, fragment, afterState.doc, {\n mapping,\n isOMark: new Map(),\n });\n });\n // grab update after diffing\n const diffUpdate = encodeStateAsUpdate(ydoc, beforeVector);\n await client.sendYjsBinaryUpdate(roomId, diffUpdate);\n await this.refresh();\n },\n\n /**\n * allows you to set content similar to TipTap's setcontent. Only accepts nulls, objects or strings.\n * Unlike TipTap, strings won't be parsed with DOMParser\n * */\n async setContent(content: null | object | string) {\n if (typeof content === \"string\") {\n return this.update((doc, tr) => {\n tr.delete(0, doc.content.size);\n tr.insertText(content);\n return tr;\n });\n }\n if (content === null) {\n return this.clearContent();\n }\n const node = createDocumentFromContent(content, schema);\n if (!node) {\n throw \"Invalid content\";\n }\n return this.update((doc, tr) => {\n tr.delete(0, doc.content.size);\n tr.insert(0, node);\n return tr;\n });\n },\n async clearContent() {\n await this.update((doc, tr) => {\n tr.delete(0, doc.content.size);\n return tr;\n });\n },\n\n /**\n * Uses TipTap's getText function, which allows passing a custom text serializer\n */\n getText(options?: {\n blockSeparator?: string;\n textSerializers?: Record<string, TextSerializer>;\n }) {\n const { state } = liveblocksState;\n return getText(state.doc, options);\n },\n\n /**\n * Helper function to return prosemirror document in JSON form\n */\n toJSON() {\n // upstream ProseMirror uses \"any\" type for json\n // eslint-disable-next-line @typescript-eslint/no-unsafe-return\n return liveblocksState.state.doc.toJSON();\n },\n /**\n * Helper function to return editor state as Markdown. By default it uses the defaultMarkdownSerializer from prosemirror-markdown, but you may pass your own\n */\n toMarkdown(serializer?: MarkdownSerializer) {\n return (serializer ?? defaultMarkdownSerializer).serialize(\n liveblocksState.state.doc\n );\n },\n /**\n * Helper function to return the editor's current prosemirror state\n */\n getEditorState() {\n return liveblocksState.state;\n },\n });\n return val;\n}\n","import { Mark, mergeAttributes } from \"@tiptap/core\";\n\nexport const LIVEBLOCKS_COMMENT_MARK_TYPE = \"liveblocksCommentMark\";\n\nexport const CommentExtension = Mark.create({\n name: LIVEBLOCKS_COMMENT_MARK_TYPE,\n excludes: \"\",\n inclusive: false,\n keepOnSplit: true,\n addAttributes() {\n // Return an object with attribute configuration\n return {\n orphan: {\n parseHTML: (element) => !!element.getAttribute(\"data-orphan\"),\n renderHTML: (attributes) => {\n return (attributes as { orphan: boolean }).orphan\n ? {\n \"data-orphan\": \"true\",\n }\n : {};\n },\n default: false,\n },\n threadId: {\n parseHTML: (element) => element.getAttribute(\"data-lb-thread-id\"),\n renderHTML: (attributes) => {\n return {\n \"data-lb-thread-id\": (attributes as { threadId: string }).threadId,\n };\n },\n default: \"\",\n },\n };\n },\n\n renderHTML({ HTMLAttributes }: { HTMLAttributes: Record<string, unknown> }) {\n return [\n \"span\",\n mergeAttributes(HTMLAttributes, {\n class: \"lb-root lb-tiptap-thread-mark\",\n }),\n ];\n },\n});\n","import { mergeAttributes, Node } from \"@tiptap/core\";\n\nexport const LIVEBLOCKS_GROUP_MENTION_TYPE = \"liveblocksGroupMention\";\n\nexport const GroupMentionExtension = Node.create({\n name: LIVEBLOCKS_GROUP_MENTION_TYPE,\n group: \"inline\",\n inline: true,\n selectable: true,\n atom: true,\n\n priority: 101,\n parseHTML() {\n return [\n {\n tag: \"liveblocks-group-mention\",\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\"liveblocks-group-mention\", mergeAttributes(HTMLAttributes)];\n },\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-id\"),\n renderHTML: (attributes) => {\n if (!attributes.id) {\n return {};\n }\n\n return {\n \"data-id\": attributes.id as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n userIds: {\n default: null,\n parseHTML: (element) => {\n const userIdsAttribute = element.getAttribute(\"data-user-ids\");\n\n if (!userIdsAttribute) {\n return null;\n }\n\n try {\n const userIds = JSON.parse(userIdsAttribute) as string[];\n\n return Array.isArray(userIds) ? userIds : null;\n } catch {\n return null;\n }\n },\n renderHTML: (attributes) => {\n if (!attributes.userIds || !Array.isArray(attributes.userIds)) {\n return {};\n }\n\n return {\n \"data-user-ids\": JSON.stringify(attributes.userIds),\n };\n },\n },\n notificationId: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-notification-id\"),\n renderHTML: (attributes) => {\n if (!attributes.notificationId) {\n return {};\n }\n\n return {\n \"data-notification-id\": attributes.notificationId as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n };\n },\n});\n","import { mergeAttributes, Node } from \"@tiptap/core\";\n\nexport const LIVEBLOCKS_MENTION_TYPE = \"liveblocksMention\";\n\nexport const MentionExtension = Node.create({\n name: LIVEBLOCKS_MENTION_TYPE,\n group: \"inline\",\n inline: true,\n selectable: true,\n atom: true,\n\n priority: 101,\n parseHTML() {\n return [\n {\n tag: \"liveblocks-mention\",\n },\n ];\n },\n\n renderHTML({ HTMLAttributes }) {\n return [\"liveblocks-mention\", mergeAttributes(HTMLAttributes)];\n },\n\n addAttributes() {\n return {\n id: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-id\"),\n renderHTML: (attributes) => {\n if (!attributes.id) {\n return {};\n }\n\n return {\n \"data-id\": attributes.id as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n notificationId: {\n default: null,\n parseHTML: (element) => element.getAttribute(\"data-notification-id\"),\n renderHTML: (attributes) => {\n if (!attributes.notificationId) {\n return {};\n }\n\n return {\n \"data-notification-id\": attributes.notificationId as string, // \"as\" typing because TipTap doesn't have a way to type attributes\n };\n },\n },\n };\n },\n});\n"]}
package/dist/index.js CHANGED
@@ -3,7 +3,7 @@ import { detectDupes } from "@liveblocks/core";
3
3
 
4
4
  // src/version.ts
5
5
  var PKG_NAME = "@liveblocks/node-prosemirror";
6
- var PKG_VERSION = "3.14.0-pre4";
6
+ var PKG_VERSION = "3.14.0-types1";
7
7
  var PKG_FORMAT = "esm";
8
8
 
9
9
  // src/document.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@liveblocks/node-prosemirror",
3
- "version": "3.14.0-pre4",
3
+ "version": "3.14.0-types1",
4
4
  "description": "A server-side utility that lets you modify prosemirror and tiptap documents hosted in Liveblocks.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
@@ -34,8 +34,8 @@
34
34
  "test:watch": "NODE_OPTIONS=\"--no-deprecation\" vitest"
35
35
  },
36
36
  "dependencies": {
37
- "@liveblocks/core": "3.14.0-pre4",
38
- "@liveblocks/node": "3.14.0-pre4",
37
+ "@liveblocks/core": "3.14.0-types1",
38
+ "@liveblocks/node": "3.14.0-types1",
39
39
  "yjs": "^13.6.20"
40
40
  },
41
41
  "peerDependencies": {