@liveblocks/node-prosemirror 0.0.1 → 2.11.1

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.
@@ -0,0 +1,53 @@
1
+ import { Liveblocks } from '@liveblocks/node';
2
+ import { TextSerializer } from '@tiptap/core';
3
+ import { Schema, Node } from '@tiptap/pm/model';
4
+ import { Transaction, EditorState } from '@tiptap/pm/state';
5
+
6
+ declare type LiveblocksProsemirrorOptions = {
7
+ roomId: string;
8
+ schema?: Schema;
9
+ client: Liveblocks;
10
+ field?: string;
11
+ };
12
+ declare type LiveblocksDocumentApi = {
13
+ refresh: () => Promise<void>;
14
+ update: (modifyFn: (doc: Node, tr: Transaction) => Transaction) => Promise<void>;
15
+ setContent: (content: null | object | string) => Promise<void>;
16
+ clearContent: () => Promise<void>;
17
+ getText: (options?: {
18
+ blockSeparator?: string;
19
+ textSerializers?: Record<string, TextSerializer>;
20
+ }) => string;
21
+ getEditorState: () => EditorState;
22
+ toJSON: () => any;
23
+ toMarkdown: () => string;
24
+ };
25
+ /**
26
+ *
27
+ * `withProsemirrorDocument` is the main entry point to access and modify prosemirror (or TipTap) documents on your backend.
28
+ * This function internally instantiates a Prosemirror state and allows you to modify and export its values asynchronously
29
+ * with a simplified interface. It's important to note that the api works with Prosemirror's document state and Transactions api.
30
+ *
31
+ * @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.
32
+ * @param callback The call back function is optionally async and receives the document API as its only argument.
33
+ *
34
+ * @example
35
+ *
36
+ * import { Liveblocks } from "@liveblocks/node";
37
+ * import { withProsemirrorDocument } from "@liveblocks/node-prosemirror";
38
+ *
39
+ * const client = new Liveblocks({secret: "sk_your_secret_key"});
40
+ * const text = await withProsemirrorDocument(
41
+ * { client, roomId: "your-room" },
42
+ * async (docApi) => {
43
+ * await docApi.update((tr) => {
44
+ * return tr.insertText("Hello World, from Liveblocks!!", 0);
45
+ * });
46
+ * return docApi.getTextContent();
47
+ * }
48
+ * );
49
+ *
50
+ */
51
+ declare function withProsemirrorDocument<T>({ roomId, schema: maybeSchema, client, field }: LiveblocksProsemirrorOptions, callback: (api: LiveblocksDocumentApi) => Promise<T> | T): Promise<T>;
52
+
53
+ export { type LiveblocksDocumentApi, type LiveblocksProsemirrorOptions, withProsemirrorDocument };
@@ -0,0 +1,53 @@
1
+ import { Liveblocks } from '@liveblocks/node';
2
+ import { TextSerializer } from '@tiptap/core';
3
+ import { Schema, Node } from '@tiptap/pm/model';
4
+ import { Transaction, EditorState } from '@tiptap/pm/state';
5
+
6
+ declare type LiveblocksProsemirrorOptions = {
7
+ roomId: string;
8
+ schema?: Schema;
9
+ client: Liveblocks;
10
+ field?: string;
11
+ };
12
+ declare type LiveblocksDocumentApi = {
13
+ refresh: () => Promise<void>;
14
+ update: (modifyFn: (doc: Node, tr: Transaction) => Transaction) => Promise<void>;
15
+ setContent: (content: null | object | string) => Promise<void>;
16
+ clearContent: () => Promise<void>;
17
+ getText: (options?: {
18
+ blockSeparator?: string;
19
+ textSerializers?: Record<string, TextSerializer>;
20
+ }) => string;
21
+ getEditorState: () => EditorState;
22
+ toJSON: () => any;
23
+ toMarkdown: () => string;
24
+ };
25
+ /**
26
+ *
27
+ * `withProsemirrorDocument` is the main entry point to access and modify prosemirror (or TipTap) documents on your backend.
28
+ * This function internally instantiates a Prosemirror state and allows you to modify and export its values asynchronously
29
+ * with a simplified interface. It's important to note that the api works with Prosemirror's document state and Transactions api.
30
+ *
31
+ * @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.
32
+ * @param callback The call back function is optionally async and receives the document API as its only argument.
33
+ *
34
+ * @example
35
+ *
36
+ * import { Liveblocks } from "@liveblocks/node";
37
+ * import { withProsemirrorDocument } from "@liveblocks/node-prosemirror";
38
+ *
39
+ * const client = new Liveblocks({secret: "sk_your_secret_key"});
40
+ * const text = await withProsemirrorDocument(
41
+ * { client, roomId: "your-room" },
42
+ * async (docApi) => {
43
+ * await docApi.update((tr) => {
44
+ * return tr.insertText("Hello World, from Liveblocks!!", 0);
45
+ * });
46
+ * return docApi.getTextContent();
47
+ * }
48
+ * );
49
+ *
50
+ */
51
+ declare function withProsemirrorDocument<T>({ roomId, schema: maybeSchema, client, field }: LiveblocksProsemirrorOptions, callback: (api: LiveblocksDocumentApi) => Promise<T> | T): Promise<T>;
52
+
53
+ export { type LiveblocksDocumentApi, type LiveblocksProsemirrorOptions, withProsemirrorDocument };