@liveblocks/react-tiptap 3.21.0-exp1 → 3.21.0-exp10
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/LiveblocksExtension.cjs +3 -2
- package/dist/LiveblocksExtension.cjs.map +1 -1
- package/dist/LiveblocksExtension.js +3 -2
- package/dist/LiveblocksExtension.js.map +1 -1
- package/dist/collaboration-liveblocks/cursors.cjs +10 -211
- package/dist/collaboration-liveblocks/cursors.cjs.map +1 -1
- package/dist/collaboration-liveblocks/cursors.js +6 -209
- package/dist/collaboration-liveblocks/cursors.js.map +1 -1
- package/dist/collaboration-liveblocks/plugin.cjs +13 -189
- package/dist/collaboration-liveblocks/plugin.cjs.map +1 -1
- package/dist/collaboration-liveblocks/plugin.js +12 -190
- package/dist/collaboration-liveblocks/plugin.js.map +1 -1
- package/dist/collaboration-liveblocks/schema.cjs +23 -139
- package/dist/collaboration-liveblocks/schema.cjs.map +1 -1
- package/dist/collaboration-liveblocks/schema.js +5 -128
- package/dist/collaboration-liveblocks/schema.js.map +1 -1
- package/dist/comments/CommentsExtension.cjs +3 -2
- package/dist/comments/CommentsExtension.cjs.map +1 -1
- package/dist/comments/CommentsExtension.js +2 -1
- package/dist/comments/CommentsExtension.js.map +1 -1
- package/dist/index.d.cts +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/mentions/MentionExtension.cjs +6 -4
- package/dist/mentions/MentionExtension.cjs.map +1 -1
- package/dist/mentions/MentionExtension.js +5 -3
- package/dist/mentions/MentionExtension.js.map +1 -1
- package/dist/types.cjs.map +1 -1
- package/dist/types.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.cjs.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +7 -6
- package/dist/collaboration-liveblocks/mapping.cjs +0 -218
- package/dist/collaboration-liveblocks/mapping.cjs.map +0 -1
- package/dist/collaboration-liveblocks/mapping.js +0 -207
- package/dist/collaboration-liveblocks/mapping.js.map +0 -1
- package/dist/collaboration-liveblocks/remote.cjs +0 -210
- package/dist/collaboration-liveblocks/remote.cjs.map +0 -1
- package/dist/collaboration-liveblocks/remote.js +0 -207
- package/dist/collaboration-liveblocks/remote.js.map +0 -1
- package/dist/collaboration-liveblocks/steps.cjs +0 -359
- package/dist/collaboration-liveblocks/steps.cjs.map +0 -1
- package/dist/collaboration-liveblocks/steps.js +0 -356
- package/dist/collaboration-liveblocks/steps.js.map +0 -1
|
@@ -1,196 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createLiveblocksCollaborationPlugin } from '@liveblocks/prosemirror';
|
|
2
|
+
export { LIVEBLOCKS_COLLABORATION_PLUGIN_KEY } from '@liveblocks/prosemirror';
|
|
2
3
|
import { Extension } from '@tiptap/core';
|
|
3
|
-
import {
|
|
4
|
-
import { PluginKey, Plugin } from '@tiptap/pm/state';
|
|
5
|
-
import { applyRemoteStorageUpdates } from './remote.js';
|
|
6
|
-
import { createDefaultDocument, createLiveblocksTiptapNode, liveblocksTiptapNodeToJson, stringifyDocument } from './schema.js';
|
|
7
|
-
import { classifyTransaction, applyIncrementalOperations } from './steps.js';
|
|
4
|
+
import { createDefaultDocument } from './schema.js';
|
|
8
5
|
|
|
9
|
-
const LIVEBLOCKS_COLLABORATION_PLUGIN_KEY = new PluginKey("liveblocks-collaboration");
|
|
10
6
|
function isProseMirrorJsonNode(value) {
|
|
11
7
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
12
8
|
}
|
|
13
|
-
function getInitialDocument(initialContent, view) {
|
|
14
|
-
if (isProseMirrorJsonNode(initialContent)) {
|
|
15
|
-
return initialContent;
|
|
16
|
-
}
|
|
17
|
-
const currentDocument = view.state.doc.toJSON();
|
|
18
|
-
if (isProseMirrorJsonNode(currentDocument)) {
|
|
19
|
-
return currentDocument;
|
|
20
|
-
}
|
|
21
|
-
return createDefaultDocument();
|
|
22
|
-
}
|
|
23
|
-
function replaceEditorDocument(view, document) {
|
|
24
|
-
let nextDocument;
|
|
25
|
-
try {
|
|
26
|
-
nextDocument = view.state.schema.nodeFromJSON(document);
|
|
27
|
-
} catch {
|
|
28
|
-
nextDocument = view.state.schema.nodeFromJSON(createDefaultDocument());
|
|
29
|
-
}
|
|
30
|
-
if (nextDocument.childCount === 0) {
|
|
31
|
-
nextDocument = view.state.schema.nodeFromJSON(createDefaultDocument());
|
|
32
|
-
}
|
|
33
|
-
const tr = view.state.tr.replace(
|
|
34
|
-
0,
|
|
35
|
-
view.state.doc.content.size,
|
|
36
|
-
new Slice(nextDocument.content, 0, 0)
|
|
37
|
-
);
|
|
38
|
-
tr.setMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY, { isRemote: true }).setMeta(
|
|
39
|
-
"addToHistory",
|
|
40
|
-
false
|
|
41
|
-
);
|
|
42
|
-
view.dispatch(tr);
|
|
43
|
-
}
|
|
44
|
-
function getDocumentRoot(root, field) {
|
|
45
|
-
const documentRoot = root.get(field);
|
|
46
|
-
if (!(documentRoot instanceof LiveObject)) {
|
|
47
|
-
return void 0;
|
|
48
|
-
}
|
|
49
|
-
return documentRoot;
|
|
50
|
-
}
|
|
51
|
-
function setDocumentRoot(root, field, document) {
|
|
52
|
-
root.set(field, createLiveblocksTiptapNode(document));
|
|
53
|
-
}
|
|
54
|
-
function createLiveblocksCollaborationPlugin(options) {
|
|
55
|
-
const room = options.room;
|
|
56
|
-
if (room === void 0) {
|
|
57
|
-
throw new Error(
|
|
58
|
-
"[Liveblocks] The Liveblocks collaboration plugin requires a room."
|
|
59
|
-
);
|
|
60
|
-
}
|
|
61
|
-
let view;
|
|
62
|
-
let root;
|
|
63
|
-
let unsubscribe;
|
|
64
|
-
let destroyed = false;
|
|
65
|
-
let isApplyingRemoteUpdate = false;
|
|
66
|
-
let isApplyingLocalUpdate = false;
|
|
67
|
-
let lastDocument = "";
|
|
68
|
-
const applyStorageToEditor = (updates) => {
|
|
69
|
-
if (view === void 0 || root === void 0) {
|
|
70
|
-
return;
|
|
71
|
-
}
|
|
72
|
-
const documentRoot = getDocumentRoot(root, options.field);
|
|
73
|
-
if (documentRoot === void 0) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
if (isApplyingLocalUpdate) {
|
|
77
|
-
return;
|
|
78
|
-
}
|
|
79
|
-
const document = liveblocksTiptapNodeToJson(documentRoot);
|
|
80
|
-
const serializedDocument = stringifyDocument(document);
|
|
81
|
-
if (serializedDocument === lastDocument) {
|
|
82
|
-
return;
|
|
83
|
-
}
|
|
84
|
-
if (updates !== void 0) {
|
|
85
|
-
const result = applyRemoteStorageUpdates(view, documentRoot, updates);
|
|
86
|
-
if (result.type === "applied") {
|
|
87
|
-
lastDocument = serializedDocument;
|
|
88
|
-
isApplyingRemoteUpdate = true;
|
|
89
|
-
try {
|
|
90
|
-
view.dispatch(
|
|
91
|
-
result.tr.setMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY, { isRemote: true }).setMeta("addToHistory", false)
|
|
92
|
-
);
|
|
93
|
-
} finally {
|
|
94
|
-
isApplyingRemoteUpdate = false;
|
|
95
|
-
}
|
|
96
|
-
return;
|
|
97
|
-
}
|
|
98
|
-
}
|
|
99
|
-
lastDocument = serializedDocument;
|
|
100
|
-
isApplyingRemoteUpdate = true;
|
|
101
|
-
try {
|
|
102
|
-
replaceEditorDocument(view, document);
|
|
103
|
-
} finally {
|
|
104
|
-
isApplyingRemoteUpdate = false;
|
|
105
|
-
}
|
|
106
|
-
};
|
|
107
|
-
return new Plugin({
|
|
108
|
-
key: LIVEBLOCKS_COLLABORATION_PLUGIN_KEY,
|
|
109
|
-
state: {
|
|
110
|
-
init: () => ({ isReady: false }),
|
|
111
|
-
apply(tr, state) {
|
|
112
|
-
const meta = tr.getMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY);
|
|
113
|
-
return meta?.isReady !== void 0 ? { ...state, isReady: meta.isReady } : state;
|
|
114
|
-
}
|
|
115
|
-
},
|
|
116
|
-
appendTransaction(transactions, oldState, newState) {
|
|
117
|
-
if (root === void 0 || isApplyingRemoteUpdate || !transactions.some((transaction) => transaction.docChanged) || transactions.some(
|
|
118
|
-
(transaction) => Boolean(transaction.getMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY))
|
|
119
|
-
)) {
|
|
120
|
-
return null;
|
|
121
|
-
}
|
|
122
|
-
const currentRoot = root;
|
|
123
|
-
const documentRoot = getDocumentRoot(currentRoot, options.field);
|
|
124
|
-
const classified = documentRoot !== void 0 ? classifyTransaction(
|
|
125
|
-
transactions,
|
|
126
|
-
oldState.doc,
|
|
127
|
-
newState.doc,
|
|
128
|
-
documentRoot
|
|
129
|
-
) : { type: "unsupported" };
|
|
130
|
-
room.batch(() => {
|
|
131
|
-
if (classified.type === "incremental") {
|
|
132
|
-
isApplyingLocalUpdate = true;
|
|
133
|
-
try {
|
|
134
|
-
applyIncrementalOperations(classified.operations);
|
|
135
|
-
} finally {
|
|
136
|
-
isApplyingLocalUpdate = false;
|
|
137
|
-
}
|
|
138
|
-
} else {
|
|
139
|
-
const document = newState.doc.toJSON();
|
|
140
|
-
if (!isProseMirrorJsonNode(document)) {
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
const serializedDocument = stringifyDocument(document);
|
|
144
|
-
if (serializedDocument === lastDocument) {
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
lastDocument = serializedDocument;
|
|
148
|
-
setDocumentRoot(currentRoot, options.field, document);
|
|
149
|
-
}
|
|
150
|
-
});
|
|
151
|
-
return null;
|
|
152
|
-
},
|
|
153
|
-
view(editorView) {
|
|
154
|
-
view = editorView;
|
|
155
|
-
room.getStorage().then(({ root: storageRoot }) => {
|
|
156
|
-
if (destroyed) {
|
|
157
|
-
return;
|
|
158
|
-
}
|
|
159
|
-
root = storageRoot;
|
|
160
|
-
if (getDocumentRoot(storageRoot, options.field) === void 0) {
|
|
161
|
-
const initialDocument = getInitialDocument(
|
|
162
|
-
options.initialContent,
|
|
163
|
-
editorView
|
|
164
|
-
);
|
|
165
|
-
room.history.disable(() => {
|
|
166
|
-
setDocumentRoot(storageRoot, options.field, initialDocument);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
applyStorageToEditor();
|
|
170
|
-
const tr = editorView.state.tr.setMeta(
|
|
171
|
-
LIVEBLOCKS_COLLABORATION_PLUGIN_KEY,
|
|
172
|
-
{ isReady: true }
|
|
173
|
-
);
|
|
174
|
-
editorView.dispatch(tr);
|
|
175
|
-
unsubscribe = room.subscribe(storageRoot, applyStorageToEditor, {
|
|
176
|
-
isDeep: true
|
|
177
|
-
});
|
|
178
|
-
});
|
|
179
|
-
return {
|
|
180
|
-
update(nextView) {
|
|
181
|
-
view = nextView;
|
|
182
|
-
},
|
|
183
|
-
destroy() {
|
|
184
|
-
destroyed = true;
|
|
185
|
-
unsubscribe?.();
|
|
186
|
-
unsubscribe = void 0;
|
|
187
|
-
view = void 0;
|
|
188
|
-
root = void 0;
|
|
189
|
-
}
|
|
190
|
-
};
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}
|
|
194
9
|
const LiveblocksCollaboration = Extension.create({
|
|
195
10
|
name: "collaboration",
|
|
196
11
|
priority: 1e3,
|
|
@@ -238,9 +53,16 @@ const LiveblocksCollaboration = Extension.create({
|
|
|
238
53
|
};
|
|
239
54
|
},
|
|
240
55
|
addProseMirrorPlugins() {
|
|
241
|
-
return [
|
|
56
|
+
return [
|
|
57
|
+
createLiveblocksCollaborationPlugin({
|
|
58
|
+
room: this.options.room,
|
|
59
|
+
field: this.options.field,
|
|
60
|
+
initialContent: isProseMirrorJsonNode(this.options.initialContent) ? this.options.initialContent : void 0,
|
|
61
|
+
fallbackDocument: createDefaultDocument
|
|
62
|
+
})
|
|
63
|
+
];
|
|
242
64
|
}
|
|
243
65
|
});
|
|
244
66
|
|
|
245
|
-
export {
|
|
67
|
+
export { LiveblocksCollaboration };
|
|
246
68
|
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../src/collaboration-liveblocks/plugin.ts"],"sourcesContent":["import type { LsonObject, StorageUpdate } from \"@liveblocks/client\";\nimport { LiveObject } from \"@liveblocks/client\";\nimport type { Content } from \"@tiptap/core\";\nimport { Extension } from \"@tiptap/core\";\nimport { Slice } from \"@tiptap/pm/model\";\nimport { Plugin, PluginKey } from \"@tiptap/pm/state\";\nimport type { EditorView } from \"@tiptap/pm/view\";\n\nimport { applyRemoteStorageUpdates } from \"./remote\";\nimport {\n createDefaultDocument,\n createLiveblocksTiptapNode,\n type LiveblocksTiptapNode,\n liveblocksTiptapNodeToJson,\n type ProseMirrorJsonNode,\n stringifyDocument,\n} from \"./schema\";\nimport { applyIncrementalOperations, classifyTransaction } from \"./steps\";\nimport type { LiveblocksTiptapRoom } from \"./types\";\n\nexport const LIVEBLOCKS_COLLABORATION_PLUGIN_KEY = new PluginKey<{\n isReady: boolean;\n}>(\"liveblocks-collaboration\");\n\ntype LiveblocksCollaborationOptions = {\n room?: LiveblocksTiptapRoom;\n field: string;\n initialContent?: Content;\n};\n\ntype LiveblocksCollaborationStorage = {\n isDisabled: boolean;\n};\n\nfunction isProseMirrorJsonNode(value: unknown): value is ProseMirrorJsonNode {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\nfunction getInitialDocument(\n initialContent: Content | undefined,\n view: EditorView\n): ProseMirrorJsonNode {\n if (isProseMirrorJsonNode(initialContent)) {\n return initialContent;\n }\n\n const currentDocument: unknown = view.state.doc.toJSON();\n if (isProseMirrorJsonNode(currentDocument)) {\n return currentDocument;\n }\n\n return createDefaultDocument();\n}\n\nfunction replaceEditorDocument(\n view: EditorView,\n document: ProseMirrorJsonNode\n): void {\n let nextDocument;\n try {\n nextDocument = view.state.schema.nodeFromJSON(document);\n } catch {\n nextDocument = view.state.schema.nodeFromJSON(createDefaultDocument());\n }\n\n if (nextDocument.childCount === 0) {\n nextDocument = view.state.schema.nodeFromJSON(createDefaultDocument());\n }\n\n const tr = view.state.tr.replace(\n 0,\n view.state.doc.content.size,\n new Slice(nextDocument.content, 0, 0)\n );\n\n tr.setMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY, { isRemote: true }).setMeta(\n \"addToHistory\",\n false\n );\n\n view.dispatch(tr);\n}\n\nfunction getDocumentRoot(\n root: LiveObject<LsonObject>,\n field: string\n): LiveblocksTiptapNode | undefined {\n const documentRoot = root.get(field);\n if (!(documentRoot instanceof LiveObject)) {\n return undefined;\n }\n\n return documentRoot as LiveblocksTiptapNode;\n}\n\nfunction setDocumentRoot(\n root: LiveObject<LsonObject>,\n field: string,\n document: ProseMirrorJsonNode\n): void {\n root.set(field, createLiveblocksTiptapNode(document));\n}\n\nfunction createLiveblocksCollaborationPlugin(\n options: LiveblocksCollaborationOptions\n): Plugin {\n const room = options.room;\n if (room === undefined) {\n throw new Error(\n \"[Liveblocks] The Liveblocks collaboration plugin requires a room.\"\n );\n }\n\n let view: EditorView | undefined;\n let root: LiveObject<LsonObject> | undefined;\n let unsubscribe: (() => void) | undefined;\n let destroyed = false;\n let isApplyingRemoteUpdate = false;\n let isApplyingLocalUpdate = false;\n let lastDocument = \"\";\n\n const applyStorageToEditor = (updates?: StorageUpdate[]) => {\n if (view === undefined || root === undefined) {\n return;\n }\n\n const documentRoot = getDocumentRoot(root, options.field);\n if (documentRoot === undefined) {\n return;\n }\n\n if (isApplyingLocalUpdate) {\n return;\n }\n\n const document = liveblocksTiptapNodeToJson(documentRoot);\n const serializedDocument = stringifyDocument(document);\n\n if (serializedDocument === lastDocument) {\n return;\n }\n\n if (updates !== undefined) {\n const result = applyRemoteStorageUpdates(view, documentRoot, updates);\n if (result.type === \"applied\") {\n lastDocument = serializedDocument;\n isApplyingRemoteUpdate = true;\n try {\n view.dispatch(\n result.tr\n .setMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY, { isRemote: true })\n .setMeta(\"addToHistory\", false)\n );\n } finally {\n isApplyingRemoteUpdate = false;\n }\n return;\n }\n }\n\n lastDocument = serializedDocument;\n isApplyingRemoteUpdate = true;\n try {\n replaceEditorDocument(view, document);\n } finally {\n isApplyingRemoteUpdate = false;\n }\n };\n\n return new Plugin({\n key: LIVEBLOCKS_COLLABORATION_PLUGIN_KEY,\n state: {\n init: () => ({ isReady: false }),\n apply(tr, state) {\n const meta = tr.getMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY) as\n | { isReady?: boolean }\n | undefined;\n\n return meta?.isReady !== undefined\n ? { ...state, isReady: meta.isReady }\n : state;\n },\n },\n appendTransaction(transactions, oldState, newState) {\n if (\n root === undefined ||\n isApplyingRemoteUpdate ||\n !transactions.some((transaction) => transaction.docChanged) ||\n transactions.some((transaction) =>\n Boolean(transaction.getMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY))\n )\n ) {\n return null;\n }\n\n const currentRoot = root;\n\n const documentRoot = getDocumentRoot(currentRoot, options.field);\n const classified =\n documentRoot !== undefined\n ? classifyTransaction(\n transactions,\n oldState.doc,\n newState.doc,\n documentRoot\n )\n : { type: \"unsupported\" as const };\n\n room.batch(() => {\n if (classified.type === \"incremental\") {\n isApplyingLocalUpdate = true;\n try {\n applyIncrementalOperations(classified.operations);\n } finally {\n isApplyingLocalUpdate = false;\n }\n } else {\n const document: unknown = newState.doc.toJSON();\n if (!isProseMirrorJsonNode(document)) {\n return;\n }\n\n const serializedDocument = stringifyDocument(document);\n if (serializedDocument === lastDocument) {\n return;\n }\n\n lastDocument = serializedDocument;\n setDocumentRoot(currentRoot, options.field, document);\n }\n });\n\n return null;\n },\n view(editorView) {\n view = editorView;\n\n room.getStorage().then(({ root: storageRoot }) => {\n if (destroyed) {\n return;\n }\n\n root = storageRoot;\n\n if (getDocumentRoot(storageRoot, options.field) === undefined) {\n const initialDocument = getInitialDocument(\n options.initialContent,\n editorView\n );\n room.history.disable(() => {\n setDocumentRoot(storageRoot, options.field, initialDocument);\n });\n }\n\n applyStorageToEditor();\n\n const tr = editorView.state.tr.setMeta(\n LIVEBLOCKS_COLLABORATION_PLUGIN_KEY,\n { isReady: true }\n );\n editorView.dispatch(tr);\n\n unsubscribe = room.subscribe(storageRoot, applyStorageToEditor, {\n isDeep: true,\n });\n });\n\n return {\n update(nextView) {\n view = nextView;\n },\n destroy() {\n destroyed = true;\n unsubscribe?.();\n unsubscribe = undefined;\n view = undefined;\n root = undefined;\n },\n };\n },\n });\n}\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n collaboration: {\n undo: () => ReturnType;\n redo: () => ReturnType;\n };\n }\n}\n\nexport const LiveblocksCollaboration = Extension.create<\n LiveblocksCollaborationOptions,\n LiveblocksCollaborationStorage\n>({\n name: \"collaboration\",\n priority: 1000,\n\n addOptions() {\n return {\n room: undefined,\n field: \"default\",\n initialContent: undefined,\n };\n },\n\n addStorage() {\n return {\n isDisabled: false,\n };\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ dispatch, tr }) => {\n tr.setMeta(\"preventDispatch\", true);\n\n if (\n this.options.room === undefined ||\n !this.options.room.history.canUndo()\n ) {\n return false;\n }\n\n if (dispatch) {\n this.options.room.history.undo();\n }\n\n return true;\n },\n redo:\n () =>\n ({ dispatch, tr }) => {\n tr.setMeta(\"preventDispatch\", true);\n\n if (\n this.options.room === undefined ||\n !this.options.room.history.canRedo()\n ) {\n return false;\n }\n\n if (dispatch) {\n this.options.room.history.redo();\n }\n\n return true;\n },\n };\n },\n\n addKeyboardShortcuts() {\n return {\n \"Mod-z\": () => this.editor.commands.undo(),\n \"Mod-y\": () => this.editor.commands.redo(),\n \"Shift-Mod-z\": () => this.editor.commands.redo(),\n };\n },\n\n addProseMirrorPlugins() {\n return [createLiveblocksCollaborationPlugin(this.options)];\n },\n});\n"],"names":[],"mappings":";;;;;;;;AAoBa,MAAA,mCAAA,GAAsC,IAAI,SAAA,CAEpD,0BAA0B,EAAA;AAY7B,SAAS,sBAAsB,KAA8C,EAAA;AAC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,GAC3D;AACF,CAAC;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../src/collaboration-liveblocks/plugin.ts"],"sourcesContent":["import {\n createLiveblocksCollaborationPlugin,\n LIVEBLOCKS_COLLABORATION_PLUGIN_KEY,\n type LiveblocksProsemirrorRoom,\n type ProseMirrorJsonNode,\n} from \"@liveblocks/prosemirror\";\nimport type { Content } from \"@tiptap/core\";\nimport { Extension } from \"@tiptap/core\";\n\nimport { createDefaultDocument } from \"./schema\";\n\nexport { LIVEBLOCKS_COLLABORATION_PLUGIN_KEY };\n\ntype LiveblocksCollaborationOptions = {\n room?: LiveblocksProsemirrorRoom;\n field: string;\n initialContent?: Content;\n};\n\ntype LiveblocksCollaborationStorage = {\n isDisabled: boolean;\n};\n\nfunction isProseMirrorJsonNode(value: unknown): value is ProseMirrorJsonNode {\n return (\n typeof value === \"object\" &&\n value !== null &&\n typeof (value as { type?: unknown }).type === \"string\"\n );\n}\n\ndeclare module \"@tiptap/core\" {\n interface Commands<ReturnType> {\n collaboration: {\n undo: () => ReturnType;\n redo: () => ReturnType;\n };\n }\n}\n\nexport const LiveblocksCollaboration = Extension.create<\n LiveblocksCollaborationOptions,\n LiveblocksCollaborationStorage\n>({\n name: \"collaboration\",\n priority: 1000,\n\n addOptions() {\n return {\n room: undefined,\n field: \"default\",\n initialContent: undefined,\n };\n },\n\n addStorage() {\n return {\n isDisabled: false,\n };\n },\n\n addCommands() {\n return {\n undo:\n () =>\n ({ dispatch, tr }) => {\n tr.setMeta(\"preventDispatch\", true);\n\n if (\n this.options.room === undefined ||\n !this.options.room.history.canUndo()\n ) {\n return false;\n }\n\n if (dispatch) {\n this.options.room.history.undo();\n }\n\n return true;\n },\n redo:\n () =>\n ({ dispatch, tr }) => {\n tr.setMeta(\"preventDispatch\", true);\n\n if (\n this.options.room === undefined ||\n !this.options.room.history.canRedo()\n ) {\n return false;\n }\n\n if (dispatch) {\n this.options.room.history.redo();\n }\n\n return true;\n },\n };\n },\n\n addKeyboardShortcuts() {\n return {\n \"Mod-z\": () => this.editor.commands.undo(),\n \"Mod-y\": () => this.editor.commands.redo(),\n \"Shift-Mod-z\": () => this.editor.commands.redo(),\n };\n },\n\n addProseMirrorPlugins() {\n return [\n createLiveblocksCollaborationPlugin({\n room: this.options.room,\n field: this.options.field,\n initialContent: isProseMirrorJsonNode(this.options.initialContent)\n ? this.options.initialContent\n : undefined,\n fallbackDocument: createDefaultDocument,\n }),\n ];\n },\n});\n"],"names":[],"mappings":";;;;;AAuBA,SAAS,sBAAsB,KAA8C,EAAA;AAC3E,EAAA,OACE,OAAO,KAAU,KAAA,QAAA,IACjB,UAAU,IACV,IAAA,OAAQ,MAA6B,IAAS,KAAA,QAAA,CAAA;AAElD,CAAA;AAWa,MAAA,uBAAA,GAA0B,UAAU,MAG/C,CAAA;AAAA,EACA,IAAM,EAAA,eAAA;AAAA,EACN,QAAU,EAAA,GAAA;AAAA,EAEV,UAAa,GAAA;AACX,IAAO,OAAA;AAAA,MACL,IAAM,EAAA,KAAA,CAAA;AAAA,MACN,KAAO,EAAA,SAAA;AAAA,MACP,cAAgB,EAAA,KAAA,CAAA;AAAA,KAClB,CAAA;AAAA,GACF;AAAA,EAEA,UAAa,GAAA;AACX,IAAO,OAAA;AAAA,MACL,UAAY,EAAA,KAAA;AAAA,KACd,CAAA;AAAA,GACF;AAAA,EAEA,WAAc,GAAA;AACZ,IAAO,OAAA;AAAA,MACL,MACE,MACA,CAAC,EAAE,QAAA,EAAU,IAAS,KAAA;AACpB,QAAG,EAAA,CAAA,OAAA,CAAQ,mBAAmB,IAAI,CAAA,CAAA;AAElC,QACE,IAAA,IAAA,CAAK,OAAQ,CAAA,IAAA,KAAS,KACtB,CAAA,IAAA,CAAC,KAAK,OAAQ,CAAA,IAAA,CAAK,OAAQ,CAAA,OAAA,EAC3B,EAAA;AACA,UAAO,OAAA,KAAA,CAAA;AAAA,SACT;AAEA,QAAA,IAAI,QAAU,EAAA;AACZ,UAAK,IAAA,CAA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AA;AAAA,KACH,CAAA;AAAA,GACF;AACF,CAAC;;;;"}
|
|
@@ -1,150 +1,34 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var prosemirror = require('@liveblocks/prosemirror');
|
|
4
4
|
|
|
5
|
-
const TEXT_MARKS_ATTRIBUTE = "__liveblocks_tiptap_marks";
|
|
6
|
-
function isJsonObject(value) {
|
|
7
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
8
|
-
}
|
|
9
|
-
function marksToAttributes(marks) {
|
|
10
|
-
if (marks === void 0 || marks.length === 0) {
|
|
11
|
-
return void 0;
|
|
12
|
-
}
|
|
13
|
-
return {
|
|
14
|
-
[TEXT_MARKS_ATTRIBUTE]: marks.map((mark) => ({
|
|
15
|
-
type: mark.type,
|
|
16
|
-
...mark.attrs !== void 0 ? { attrs: mark.attrs } : {}
|
|
17
|
-
}))
|
|
18
|
-
};
|
|
19
|
-
}
|
|
20
|
-
function attributesToMarks(attributes) {
|
|
21
|
-
const rawMarks = attributes?.[TEXT_MARKS_ATTRIBUTE];
|
|
22
|
-
if (!Array.isArray(rawMarks)) {
|
|
23
|
-
return void 0;
|
|
24
|
-
}
|
|
25
|
-
const marks = [];
|
|
26
|
-
for (const rawMark of rawMarks) {
|
|
27
|
-
if (!isJsonObject(rawMark) || typeof rawMark.type !== "string") {
|
|
28
|
-
continue;
|
|
29
|
-
}
|
|
30
|
-
marks.push({
|
|
31
|
-
type: rawMark.type,
|
|
32
|
-
...isJsonObject(rawMark.attrs) ? { attrs: rawMark.attrs } : {}
|
|
33
|
-
});
|
|
34
|
-
}
|
|
35
|
-
return marks.length > 0 ? marks : void 0;
|
|
36
|
-
}
|
|
37
|
-
function marksToAttributesPatch(marks) {
|
|
38
|
-
const attributes = marksToAttributes(marks);
|
|
39
|
-
return {
|
|
40
|
-
[TEXT_MARKS_ATTRIBUTE]: attributes?.[TEXT_MARKS_ATTRIBUTE] === void 0 ? null : attributes[TEXT_MARKS_ATTRIBUTE]
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
function createLiveblocksTiptapNode(node) {
|
|
44
|
-
if (node.type === "text") {
|
|
45
|
-
const text = new client.LiveText();
|
|
46
|
-
text.insert(0, node.text ?? "", marksToAttributes(node.marks));
|
|
47
|
-
return new client.LiveObject({
|
|
48
|
-
id: client.nanoid(),
|
|
49
|
-
type: node.type,
|
|
50
|
-
text
|
|
51
|
-
});
|
|
52
|
-
}
|
|
53
|
-
return new client.LiveObject({
|
|
54
|
-
id: client.nanoid(),
|
|
55
|
-
type: node.type,
|
|
56
|
-
...node.attrs !== void 0 ? { attrs: node.attrs } : {},
|
|
57
|
-
content: new client.LiveList(
|
|
58
|
-
(node.content ?? []).map((child) => createLiveblocksTiptapNode(child))
|
|
59
|
-
)
|
|
60
|
-
});
|
|
61
|
-
}
|
|
62
|
-
function getLiveblocksNodeId(node) {
|
|
63
|
-
return node.get("id");
|
|
64
|
-
}
|
|
65
|
-
function getLiveblocksNodeType(node) {
|
|
66
|
-
return node.get("type");
|
|
67
|
-
}
|
|
68
|
-
function getLiveblocksNodeContent(node) {
|
|
69
|
-
const content = node.get("content");
|
|
70
|
-
return content instanceof client.LiveList ? content : void 0;
|
|
71
|
-
}
|
|
72
|
-
function getLiveblocksNodeText(node) {
|
|
73
|
-
const text = node.get("text");
|
|
74
|
-
return text instanceof client.LiveText ? text : void 0;
|
|
75
|
-
}
|
|
76
|
-
function updateLiveblocksNodeAttrs(node, attrs) {
|
|
77
|
-
if (attrs === void 0) {
|
|
78
|
-
node.delete("attrs");
|
|
79
|
-
} else {
|
|
80
|
-
node.set("attrs", attrs);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function liveTextToTextNodes(text) {
|
|
84
|
-
const nodes = [];
|
|
85
|
-
for (const [segmentText, segmentAttributes] of text.toJSON()) {
|
|
86
|
-
if (segmentText.length === 0) {
|
|
87
|
-
continue;
|
|
88
|
-
}
|
|
89
|
-
nodes.push({
|
|
90
|
-
type: "text",
|
|
91
|
-
text: segmentText,
|
|
92
|
-
...segmentAttributes !== void 0 ? { marks: attributesToMarks(segmentAttributes) } : {}
|
|
93
|
-
});
|
|
94
|
-
}
|
|
95
|
-
return nodes;
|
|
96
|
-
}
|
|
97
|
-
function liveblocksTiptapNodeToJsonNodes(node) {
|
|
98
|
-
const type = node.get("type");
|
|
99
|
-
if (type === "text") {
|
|
100
|
-
const text = node.get("text");
|
|
101
|
-
return text instanceof client.LiveText ? liveTextToTextNodes(text) : [];
|
|
102
|
-
}
|
|
103
|
-
const content = node.get("content");
|
|
104
|
-
const jsonNode = {
|
|
105
|
-
type,
|
|
106
|
-
...node.get("attrs") !== void 0 ? { attrs: node.get("attrs") } : {}
|
|
107
|
-
};
|
|
108
|
-
if (content instanceof client.LiveList && content.length > 0) {
|
|
109
|
-
const children = [];
|
|
110
|
-
for (let index = 0; index < content.length; index++) {
|
|
111
|
-
const child = content.get(index);
|
|
112
|
-
if (child !== void 0) {
|
|
113
|
-
children.push(...liveblocksTiptapNodeToJsonNodes(child));
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (children.length > 0) {
|
|
117
|
-
jsonNode.content = children;
|
|
118
|
-
}
|
|
119
|
-
}
|
|
120
|
-
return [jsonNode];
|
|
121
|
-
}
|
|
122
|
-
function liveblocksTiptapNodeToJson(node) {
|
|
123
|
-
const [jsonNode] = liveblocksTiptapNodeToJsonNodes(node);
|
|
124
|
-
if (jsonNode === void 0 || jsonNode.type === "doc" && (!Array.isArray(jsonNode.content) || jsonNode.content.length === 0)) {
|
|
125
|
-
return createDefaultDocument();
|
|
126
|
-
}
|
|
127
|
-
return jsonNode;
|
|
128
|
-
}
|
|
129
5
|
function createDefaultDocument() {
|
|
130
6
|
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
131
7
|
}
|
|
132
|
-
function
|
|
133
|
-
return
|
|
8
|
+
function liveblocksTiptapNodeToJson(node) {
|
|
9
|
+
return prosemirror.liveblocksProsemirrorNodeToJson(node, createDefaultDocument);
|
|
134
10
|
}
|
|
135
11
|
|
|
136
|
-
exports
|
|
137
|
-
|
|
12
|
+
Object.defineProperty(exports, 'createLiveblocksTiptapNode', {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () { return prosemirror.createLiveblocksProsemirrorNode; }
|
|
15
|
+
});
|
|
16
|
+
Object.defineProperty(exports, 'getLiveblocksNodeContent', {
|
|
17
|
+
enumerable: true,
|
|
18
|
+
get: function () { return prosemirror.getLiveblocksNodeContent; }
|
|
19
|
+
});
|
|
20
|
+
Object.defineProperty(exports, 'getLiveblocksNodeId', {
|
|
21
|
+
enumerable: true,
|
|
22
|
+
get: function () { return prosemirror.getLiveblocksNodeId; }
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, 'getLiveblocksNodeText', {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return prosemirror.getLiveblocksNodeText; }
|
|
27
|
+
});
|
|
28
|
+
Object.defineProperty(exports, 'liveblocksTiptapNodeToJsonNodes', {
|
|
29
|
+
enumerable: true,
|
|
30
|
+
get: function () { return prosemirror.liveblocksProsemirrorNodeToJsonNodes; }
|
|
31
|
+
});
|
|
138
32
|
exports.createDefaultDocument = createDefaultDocument;
|
|
139
|
-
exports.createLiveblocksTiptapNode = createLiveblocksTiptapNode;
|
|
140
|
-
exports.getLiveblocksNodeContent = getLiveblocksNodeContent;
|
|
141
|
-
exports.getLiveblocksNodeId = getLiveblocksNodeId;
|
|
142
|
-
exports.getLiveblocksNodeText = getLiveblocksNodeText;
|
|
143
|
-
exports.getLiveblocksNodeType = getLiveblocksNodeType;
|
|
144
33
|
exports.liveblocksTiptapNodeToJson = liveblocksTiptapNodeToJson;
|
|
145
|
-
exports.liveblocksTiptapNodeToJsonNodes = liveblocksTiptapNodeToJsonNodes;
|
|
146
|
-
exports.marksToAttributes = marksToAttributes;
|
|
147
|
-
exports.marksToAttributesPatch = marksToAttributesPatch;
|
|
148
|
-
exports.stringifyDocument = stringifyDocument;
|
|
149
|
-
exports.updateLiveblocksNodeAttrs = updateLiveblocksNodeAttrs;
|
|
150
34
|
//# sourceMappingURL=schema.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.cjs","sources":["../../src/collaboration-liveblocks/schema.ts"],"sourcesContent":["import {\n type Json,\n type JsonObject,\n LiveList,\n LiveObject,\n LiveText,\n type LiveTextAttributes,\n type LiveTextAttributesPatch,\n type LiveTextData,\n nanoid,\n} from \"@liveblocks/client\";\n\nexport const TEXT_MARKS_ATTRIBUTE = \"__liveblocks_tiptap_marks\";\n\nexport type ProseMirrorJsonNode = {\n type: string;\n attrs?: JsonObject;\n content?: ProseMirrorJsonNode[];\n text?: string;\n marks?: ProseMirrorJsonMark[];\n};\n\nexport type ProseMirrorJsonMark = {\n type: string;\n attrs?: JsonObject;\n};\n\ntype LiveblocksTiptapNodeData = {\n id: string;\n type: string;\n attrs?: JsonObject;\n content?: LiveList<LiveblocksTiptapNode>;\n text?: LiveText;\n};\n\nexport type LiveblocksTiptapNode = LiveObject<LiveblocksTiptapNodeData>;\n\nfunction isJsonObject(value: Json | undefined): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport function marksToAttributes(\n marks: ProseMirrorJsonMark[] | undefined\n): LiveTextAttributes | undefined {\n if (marks === undefined || marks.length === 0) {\n return undefined;\n }\n\n return {\n [TEXT_MARKS_ATTRIBUTE]: marks.map((mark) => ({\n type: mark.type,\n ...(mark.attrs !== undefined ? { attrs: mark.attrs } : {}),\n })),\n };\n}\n\nexport function attributesToMarks(\n attributes: JsonObject | undefined\n): ProseMirrorJsonMark[] | undefined {\n const rawMarks = attributes?.[TEXT_MARKS_ATTRIBUTE];\n\n if (!Array.isArray(rawMarks)) {\n return undefined;\n }\n\n const marks: ProseMirrorJsonMark[] = [];\n for (const rawMark of rawMarks) {\n if (!isJsonObject(rawMark) || typeof rawMark.type !== \"string\") {\n continue;\n }\n\n marks.push({\n type: rawMark.type,\n ...(isJsonObject(rawMark.attrs) ? { attrs: rawMark.attrs } : {}),\n });\n }\n\n return marks.length > 0 ? marks : undefined;\n}\n\nexport function marksToAttributesPatch(\n marks: ProseMirrorJsonMark[] | undefined\n): LiveTextAttributesPatch {\n const attributes = marksToAttributes(marks);\n return {\n [TEXT_MARKS_ATTRIBUTE]:\n attributes?.[TEXT_MARKS_ATTRIBUTE] === undefined\n ? null\n : attributes[TEXT_MARKS_ATTRIBUTE],\n };\n}\n\nexport function createLiveblocksTiptapNode(\n node: ProseMirrorJsonNode\n): LiveblocksTiptapNode {\n if (node.type === \"text\") {\n const text = new LiveText();\n text.insert(0, node.text ?? \"\", marksToAttributes(node.marks));\n\n return new LiveObject({\n id: nanoid(),\n type: node.type,\n text,\n });\n }\n\n return new LiveObject({\n id: nanoid(),\n type: node.type,\n ...(node.attrs !== undefined ? { attrs: node.attrs } : {}),\n content: new LiveList(\n (node.content ?? []).map((child) => createLiveblocksTiptapNode(child))\n ),\n });\n}\n\nexport function getLiveblocksNodeId(node: LiveblocksTiptapNode): string {\n return node.get(\"id\");\n}\n\nexport function getLiveblocksNodeType(node: LiveblocksTiptapNode): string {\n return node.get(\"type\");\n}\n\nexport function getLiveblocksNodeContent(\n node: LiveblocksTiptapNode\n): LiveList<LiveblocksTiptapNode> | undefined {\n const content = node.get(\"content\");\n return content instanceof LiveList ? content : undefined;\n}\n\nexport function getLiveblocksNodeText(\n node: LiveblocksTiptapNode\n): LiveText | undefined {\n const text = node.get(\"text\");\n return text instanceof LiveText ? text : undefined;\n}\n\nexport function updateLiveblocksNodeAttrs(\n node: LiveblocksTiptapNode,\n attrs: JsonObject | undefined\n): void {\n if (attrs === undefined) {\n node.delete(\"attrs\");\n } else {\n node.set(\"attrs\", attrs);\n }\n}\n\nfunction liveTextToTextNodes(text: LiveText): ProseMirrorJsonNode[] {\n const nodes: ProseMirrorJsonNode[] = [];\n\n for (const [segmentText, segmentAttributes] of text.toJSON()) {\n if (segmentText.length === 0) {\n continue;\n }\n\n nodes.push({\n type: \"text\",\n text: segmentText,\n ...(segmentAttributes !== undefined\n ? { marks: attributesToMarks(segmentAttributes) }\n : {}),\n });\n }\n\n return nodes;\n}\n\nexport function liveblocksTiptapNodeToJsonNodes(\n node: LiveblocksTiptapNode\n): ProseMirrorJsonNode[] {\n const type = node.get(\"type\");\n\n if (type === \"text\") {\n const text = node.get(\"text\");\n return text instanceof LiveText ? liveTextToTextNodes(text) : [];\n }\n\n const content = node.get(\"content\");\n const jsonNode: ProseMirrorJsonNode = {\n type,\n ...(node.get(\"attrs\") !== undefined ? { attrs: node.get(\"attrs\") } : {}),\n };\n\n if (content instanceof LiveList && content.length > 0) {\n const children: ProseMirrorJsonNode[] = [];\n\n for (let index = 0; index < content.length; index++) {\n const child = content.get(index);\n if (child !== undefined) {\n children.push(...liveblocksTiptapNodeToJsonNodes(child));\n }\n }\n\n if (children.length > 0) {\n jsonNode.content = children;\n }\n }\n\n return [jsonNode];\n}\n\nexport function liveblocksTiptapNodeToJson(\n node: LiveblocksTiptapNode\n): ProseMirrorJsonNode {\n const [jsonNode] = liveblocksTiptapNodeToJsonNodes(node);\n\n if (\n jsonNode === undefined ||\n (jsonNode.type === \"doc\" &&\n (!Array.isArray(jsonNode.content) || jsonNode.content.length === 0))\n ) {\n return createDefaultDocument();\n }\n\n return jsonNode;\n}\n\nexport function createDefaultDocument(): ProseMirrorJsonNode {\n return { type: \"doc\", content: [{ type: \"paragraph\" }] };\n}\n\nexport function stringifyDocument(node: ProseMirrorJsonNode): string {\n return JSON.stringify(node);\n}\n\nexport type { LiveTextData };\n"],"names":["LiveText","LiveObject","nanoid","LiveList"],"mappings":";;;;AAYO,MAAM,oBAAuB,GAAA,4BAAA;AAyBpC,SAAS,aAAa,KAA8C,EAAA;AAClE,EAAO,OAAA,OAAO,UAAU,QAAY,IAAA,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA,CAAA;AAC5E,CAA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KAAS,UAChB,CAAC,KAAA,CAAM,OAAQ,CAAA,QAAA,CAAS,OAAO,CAAA,IAAK,QAAS,CAAA,OAAA,CAAQ,WAAW,CACnE,CAAA,EAAA;AACA,IAAA,OAAO,qBAAsB,EAAA,CAAA;AAAA,GAC/B;AAEA,EAAO,OAAA,QAAA,CAAA;AACT,CAAA;AAEO,SAAS,qBAA6C,GAAA;AAC3D,EAAO,OAAA,EAAE,MAAM,KAAO,EAAA,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,WAAY,EAAC,CAAE,EAAA,CAAA;AACzD,CAAA;AAEO,SAAS,kBAAkB,IAAmC,EAAA;AACnE,EAAO,OAAA,IAAA,CAAK,UAAU,IAAI,CAAA,CAAA;AAC5B;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"schema.cjs","sources":["../../src/collaboration-liveblocks/schema.ts"],"sourcesContent":["import {\n type LiveblocksProsemirrorNode,\n liveblocksProsemirrorNodeToJson,\n type ProseMirrorJsonNode,\n} from \"@liveblocks/prosemirror\";\n\nexport type {\n LiveblocksProsemirrorNode as LiveblocksTiptapNode,\n ProseMirrorJsonMark,\n ProseMirrorJsonNode,\n} from \"@liveblocks/prosemirror\";\nexport {\n createLiveblocksProsemirrorNode as createLiveblocksTiptapNode,\n getLiveblocksNodeContent,\n getLiveblocksNodeId,\n getLiveblocksNodeText,\n liveblocksProsemirrorNodeToJsonNodes as liveblocksTiptapNodeToJsonNodes,\n} from \"@liveblocks/prosemirror\";\n\nexport function createDefaultDocument(): ProseMirrorJsonNode {\n return { type: \"doc\", content: [{ type: \"paragraph\" }] };\n}\n\nexport function liveblocksTiptapNodeToJson(\n node: LiveblocksProsemirrorNode\n): ProseMirrorJsonNode {\n return liveblocksProsemirrorNodeToJson(node, createDefaultDocument);\n}\n"],"names":["liveblocksProsemirrorNodeToJson"],"mappings":";;;;AAmBO,SAAS,qBAA6C,GAAA;AAC3D,EAAO,OAAA,EAAE,MAAM,KAAO,EAAA,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,WAAY,EAAC,CAAE,EAAA,CAAA;AACzD,CAAA;AAEO,SAAS,2BACd,IACqB,EAAA;AACrB,EAAO,OAAAA,2CAAA,CAAgC,MAAM,qBAAqB,CAAA,CAAA;AACpE;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,135 +1,12 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { liveblocksProsemirrorNodeToJson } from '@liveblocks/prosemirror';
|
|
2
|
+
export { createLiveblocksProsemirrorNode as createLiveblocksTiptapNode, getLiveblocksNodeContent, getLiveblocksNodeId, getLiveblocksNodeText, liveblocksProsemirrorNodeToJsonNodes as liveblocksTiptapNodeToJsonNodes } from '@liveblocks/prosemirror';
|
|
2
3
|
|
|
3
|
-
const TEXT_MARKS_ATTRIBUTE = "__liveblocks_tiptap_marks";
|
|
4
|
-
function isJsonObject(value) {
|
|
5
|
-
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
6
|
-
}
|
|
7
|
-
function marksToAttributes(marks) {
|
|
8
|
-
if (marks === void 0 || marks.length === 0) {
|
|
9
|
-
return void 0;
|
|
10
|
-
}
|
|
11
|
-
return {
|
|
12
|
-
[TEXT_MARKS_ATTRIBUTE]: marks.map((mark) => ({
|
|
13
|
-
type: mark.type,
|
|
14
|
-
...mark.attrs !== void 0 ? { attrs: mark.attrs } : {}
|
|
15
|
-
}))
|
|
16
|
-
};
|
|
17
|
-
}
|
|
18
|
-
function attributesToMarks(attributes) {
|
|
19
|
-
const rawMarks = attributes?.[TEXT_MARKS_ATTRIBUTE];
|
|
20
|
-
if (!Array.isArray(rawMarks)) {
|
|
21
|
-
return void 0;
|
|
22
|
-
}
|
|
23
|
-
const marks = [];
|
|
24
|
-
for (const rawMark of rawMarks) {
|
|
25
|
-
if (!isJsonObject(rawMark) || typeof rawMark.type !== "string") {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
marks.push({
|
|
29
|
-
type: rawMark.type,
|
|
30
|
-
...isJsonObject(rawMark.attrs) ? { attrs: rawMark.attrs } : {}
|
|
31
|
-
});
|
|
32
|
-
}
|
|
33
|
-
return marks.length > 0 ? marks : void 0;
|
|
34
|
-
}
|
|
35
|
-
function marksToAttributesPatch(marks) {
|
|
36
|
-
const attributes = marksToAttributes(marks);
|
|
37
|
-
return {
|
|
38
|
-
[TEXT_MARKS_ATTRIBUTE]: attributes?.[TEXT_MARKS_ATTRIBUTE] === void 0 ? null : attributes[TEXT_MARKS_ATTRIBUTE]
|
|
39
|
-
};
|
|
40
|
-
}
|
|
41
|
-
function createLiveblocksTiptapNode(node) {
|
|
42
|
-
if (node.type === "text") {
|
|
43
|
-
const text = new LiveText();
|
|
44
|
-
text.insert(0, node.text ?? "", marksToAttributes(node.marks));
|
|
45
|
-
return new LiveObject({
|
|
46
|
-
id: nanoid(),
|
|
47
|
-
type: node.type,
|
|
48
|
-
text
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
return new LiveObject({
|
|
52
|
-
id: nanoid(),
|
|
53
|
-
type: node.type,
|
|
54
|
-
...node.attrs !== void 0 ? { attrs: node.attrs } : {},
|
|
55
|
-
content: new LiveList(
|
|
56
|
-
(node.content ?? []).map((child) => createLiveblocksTiptapNode(child))
|
|
57
|
-
)
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
function getLiveblocksNodeId(node) {
|
|
61
|
-
return node.get("id");
|
|
62
|
-
}
|
|
63
|
-
function getLiveblocksNodeType(node) {
|
|
64
|
-
return node.get("type");
|
|
65
|
-
}
|
|
66
|
-
function getLiveblocksNodeContent(node) {
|
|
67
|
-
const content = node.get("content");
|
|
68
|
-
return content instanceof LiveList ? content : void 0;
|
|
69
|
-
}
|
|
70
|
-
function getLiveblocksNodeText(node) {
|
|
71
|
-
const text = node.get("text");
|
|
72
|
-
return text instanceof LiveText ? text : void 0;
|
|
73
|
-
}
|
|
74
|
-
function updateLiveblocksNodeAttrs(node, attrs) {
|
|
75
|
-
if (attrs === void 0) {
|
|
76
|
-
node.delete("attrs");
|
|
77
|
-
} else {
|
|
78
|
-
node.set("attrs", attrs);
|
|
79
|
-
}
|
|
80
|
-
}
|
|
81
|
-
function liveTextToTextNodes(text) {
|
|
82
|
-
const nodes = [];
|
|
83
|
-
for (const [segmentText, segmentAttributes] of text.toJSON()) {
|
|
84
|
-
if (segmentText.length === 0) {
|
|
85
|
-
continue;
|
|
86
|
-
}
|
|
87
|
-
nodes.push({
|
|
88
|
-
type: "text",
|
|
89
|
-
text: segmentText,
|
|
90
|
-
...segmentAttributes !== void 0 ? { marks: attributesToMarks(segmentAttributes) } : {}
|
|
91
|
-
});
|
|
92
|
-
}
|
|
93
|
-
return nodes;
|
|
94
|
-
}
|
|
95
|
-
function liveblocksTiptapNodeToJsonNodes(node) {
|
|
96
|
-
const type = node.get("type");
|
|
97
|
-
if (type === "text") {
|
|
98
|
-
const text = node.get("text");
|
|
99
|
-
return text instanceof LiveText ? liveTextToTextNodes(text) : [];
|
|
100
|
-
}
|
|
101
|
-
const content = node.get("content");
|
|
102
|
-
const jsonNode = {
|
|
103
|
-
type,
|
|
104
|
-
...node.get("attrs") !== void 0 ? { attrs: node.get("attrs") } : {}
|
|
105
|
-
};
|
|
106
|
-
if (content instanceof LiveList && content.length > 0) {
|
|
107
|
-
const children = [];
|
|
108
|
-
for (let index = 0; index < content.length; index++) {
|
|
109
|
-
const child = content.get(index);
|
|
110
|
-
if (child !== void 0) {
|
|
111
|
-
children.push(...liveblocksTiptapNodeToJsonNodes(child));
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
if (children.length > 0) {
|
|
115
|
-
jsonNode.content = children;
|
|
116
|
-
}
|
|
117
|
-
}
|
|
118
|
-
return [jsonNode];
|
|
119
|
-
}
|
|
120
|
-
function liveblocksTiptapNodeToJson(node) {
|
|
121
|
-
const [jsonNode] = liveblocksTiptapNodeToJsonNodes(node);
|
|
122
|
-
if (jsonNode === void 0 || jsonNode.type === "doc" && (!Array.isArray(jsonNode.content) || jsonNode.content.length === 0)) {
|
|
123
|
-
return createDefaultDocument();
|
|
124
|
-
}
|
|
125
|
-
return jsonNode;
|
|
126
|
-
}
|
|
127
4
|
function createDefaultDocument() {
|
|
128
5
|
return { type: "doc", content: [{ type: "paragraph" }] };
|
|
129
6
|
}
|
|
130
|
-
function
|
|
131
|
-
return
|
|
7
|
+
function liveblocksTiptapNodeToJson(node) {
|
|
8
|
+
return liveblocksProsemirrorNodeToJson(node, createDefaultDocument);
|
|
132
9
|
}
|
|
133
10
|
|
|
134
|
-
export {
|
|
11
|
+
export { createDefaultDocument, liveblocksTiptapNodeToJson };
|
|
135
12
|
//# sourceMappingURL=schema.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"schema.js","sources":["../../src/collaboration-liveblocks/schema.ts"],"sourcesContent":["import {\n type Json,\n type JsonObject,\n LiveList,\n LiveObject,\n LiveText,\n type LiveTextAttributes,\n type LiveTextAttributesPatch,\n type LiveTextData,\n nanoid,\n} from \"@liveblocks/client\";\n\nexport const TEXT_MARKS_ATTRIBUTE = \"__liveblocks_tiptap_marks\";\n\nexport type ProseMirrorJsonNode = {\n type: string;\n attrs?: JsonObject;\n content?: ProseMirrorJsonNode[];\n text?: string;\n marks?: ProseMirrorJsonMark[];\n};\n\nexport type ProseMirrorJsonMark = {\n type: string;\n attrs?: JsonObject;\n};\n\ntype LiveblocksTiptapNodeData = {\n id: string;\n type: string;\n attrs?: JsonObject;\n content?: LiveList<LiveblocksTiptapNode>;\n text?: LiveText;\n};\n\nexport type LiveblocksTiptapNode = LiveObject<LiveblocksTiptapNodeData>;\n\nfunction isJsonObject(value: Json | undefined): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nexport function marksToAttributes(\n marks: ProseMirrorJsonMark[] | undefined\n): LiveTextAttributes | undefined {\n if (marks === undefined || marks.length === 0) {\n return undefined;\n }\n\n return {\n [TEXT_MARKS_ATTRIBUTE]: marks.map((mark) => ({\n type: mark.type,\n ...(mark.attrs !== undefined ? { attrs: mark.attrs } : {}),\n })),\n };\n}\n\nexport function attributesToMarks(\n attributes: JsonObject | undefined\n): ProseMirrorJsonMark[] | undefined {\n const rawMarks = attributes?.[TEXT_MARKS_ATTRIBUTE];\n\n if (!Array.isArray(rawMarks)) {\n return undefined;\n }\n\n const marks: ProseMirrorJsonMark[] = [];\n for (const rawMark of rawMarks) {\n if (!isJsonObject(rawMark) || typeof rawMark.type !== \"string\") {\n continue;\n }\n\n marks.push({\n type: rawMark.type,\n ...(isJsonObject(rawMark.attrs) ? { attrs: rawMark.attrs } : {}),\n });\n }\n\n return marks.length > 0 ? marks : undefined;\n}\n\nexport function marksToAttributesPatch(\n marks: ProseMirrorJsonMark[] | undefined\n): LiveTextAttributesPatch {\n const attributes = marksToAttributes(marks);\n return {\n [TEXT_MARKS_ATTRIBUTE]:\n attributes?.[TEXT_MARKS_ATTRIBUTE] === undefined\n ? null\n : attributes[TEXT_MARKS_ATTRIBUTE],\n };\n}\n\nexport function createLiveblocksTiptapNode(\n node: ProseMirrorJsonNode\n): LiveblocksTiptapNode {\n if (node.type === \"text\") {\n const text = new LiveText();\n text.insert(0, node.text ?? \"\", marksToAttributes(node.marks));\n\n return new LiveObject({\n id: nanoid(),\n type: node.type,\n text,\n });\n }\n\n return new LiveObject({\n id: nanoid(),\n type: node.type,\n ...(node.attrs !== undefined ? { attrs: node.attrs } : {}),\n content: new LiveList(\n (node.content ?? []).map((child) => createLiveblocksTiptapNode(child))\n ),\n });\n}\n\nexport function getLiveblocksNodeId(node: LiveblocksTiptapNode): string {\n return node.get(\"id\");\n}\n\nexport function getLiveblocksNodeType(node: LiveblocksTiptapNode): string {\n return node.get(\"type\");\n}\n\nexport function getLiveblocksNodeContent(\n node: LiveblocksTiptapNode\n): LiveList<LiveblocksTiptapNode> | undefined {\n const content = node.get(\"content\");\n return content instanceof LiveList ? content : undefined;\n}\n\nexport function getLiveblocksNodeText(\n node: LiveblocksTiptapNode\n): LiveText | undefined {\n const text = node.get(\"text\");\n return text instanceof LiveText ? text : undefined;\n}\n\nexport function updateLiveblocksNodeAttrs(\n node: LiveblocksTiptapNode,\n attrs: JsonObject | undefined\n): void {\n if (attrs === undefined) {\n node.delete(\"attrs\");\n } else {\n node.set(\"attrs\", attrs);\n }\n}\n\nfunction liveTextToTextNodes(text: LiveText): ProseMirrorJsonNode[] {\n const nodes: ProseMirrorJsonNode[] = [];\n\n for (const [segmentText, segmentAttributes] of text.toJSON()) {\n if (segmentText.length === 0) {\n continue;\n }\n\n nodes.push({\n type: \"text\",\n text: segmentText,\n ...(segmentAttributes !== undefined\n ? { marks: attributesToMarks(segmentAttributes) }\n : {}),\n });\n }\n\n return nodes;\n}\n\nexport function liveblocksTiptapNodeToJsonNodes(\n node: LiveblocksTiptapNode\n): ProseMirrorJsonNode[] {\n const type = node.get(\"type\");\n\n if (type === \"text\") {\n const text = node.get(\"text\");\n return text instanceof LiveText ? liveTextToTextNodes(text) : [];\n }\n\n const content = node.get(\"content\");\n const jsonNode: ProseMirrorJsonNode = {\n type,\n ...(node.get(\"attrs\") !== undefined ? { attrs: node.get(\"attrs\") } : {}),\n };\n\n if (content instanceof LiveList && content.length > 0) {\n const children: ProseMirrorJsonNode[] = [];\n\n for (let index = 0; index < content.length; index++) {\n const child = content.get(index);\n if (child !== undefined) {\n children.push(...liveblocksTiptapNodeToJsonNodes(child));\n }\n }\n\n if (children.length > 0) {\n jsonNode.content = children;\n }\n }\n\n return [jsonNode];\n}\n\nexport function liveblocksTiptapNodeToJson(\n node: LiveblocksTiptapNode\n): ProseMirrorJsonNode {\n const [jsonNode] = liveblocksTiptapNodeToJsonNodes(node);\n\n if (\n jsonNode === undefined ||\n (jsonNode.type === \"doc\" &&\n (!Array.isArray(jsonNode.content) || jsonNode.content.length === 0))\n ) {\n return createDefaultDocument();\n }\n\n return jsonNode;\n}\n\nexport function createDefaultDocument(): ProseMirrorJsonNode {\n return { type: \"doc\", content: [{ type: \"paragraph\" }] };\n}\n\nexport function stringifyDocument(node: ProseMirrorJsonNode): string {\n return JSON.stringify(node);\n}\n\nexport type { LiveTextData };\n"],"names":[],"mappings":";;AAYO,MAAM,oBAAuB,GAAA,4BAAA;AAyBpC,SAAS,aAAa,KAA8C,EAAA;AAClE,EAAO,OAAA,OAAO,UAAU,QAAY,IAAA,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA,CAAA;AAC5E,CAAA;AAEO,SAAS,kBACd,KACgC,EAAA;AAChC,EAAA,IAAI,KAAU,KAAA,KAAA,CAAA,IAAa,KAAM,CAAA,MAAA,KAAW,CAAG,EAAA;AAC7C,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AAEA,EAAO,OAAA;AAAA,IACL,CAAC,oBAAoB,GAAG,KAAM,CAAA,GAAA,CAAI,CAAC,IAAU,MAAA;AAAA,MAC3C,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,GAAI,KAAK,KAAU,KAAA,KAAA,CAAA,GAAY,EAAE,KAAO,EAAA,IAAA,CAAK,KAAM,EAAA,GAAI,EAAC;AAAA,KACxD,CAAA,CAAA;AAAA,GACJ,CAAA;AACF,CAAA;AAEO,SAAS,kBACd,UACmC,EAAA;AACnC,EAAM,MAAA,QAAA,GAAW,aAAa,oBAAoB,CAAA,CAAA;AAElD,EAAA,IAAI,CAAC,KAAA,CAAM,OAAQ,CAAA,QAAQ,CAAG,EAAA;AAC5B,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,QAA+B,EAAC,CAAA;AACtC,EAAA,KAAA,MAAW,WAAW,QAAU,EAAA;AAC9B,IAAA,IAAI,CAAC,YAAa,CAAA,OAAO,KAAK,OAAO,OAAA,CAAQ,SAAS,QAAU,EAAA;AAC9D,MAAA,SAAA;AAAA,KACF;AAEA,IAAA,KAAA,CAAM,IAAK,CAAA;AAAA,MACT,MAAM,OAAQ,CAAA,IAAA;AAAA,MACd,GAAI,YAAa,CA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AA,QAAA,CAAA;AAAA,KACrB;AAAA,GACF;AAEA,EAAA,OAAO,CAAC,QAAQ,CAAA,CAAA;AAClB,CAAA;AAEO,SAAS,2BACd,IACqB,EAAA;AACrB,EAAA,MAAM,CAAC,QAAQ,CAAI,GAAA,+BAAA,CAAgC,IAAI,CAAA,CAAA;AAEvD,EAAA,IACE,QAAa,KAAA,KAAA,CAAA,IACZ,QAAS,CAAA,IAAA,KAAS,UAChB,CAAC,KAAA,CAAM,OAAQ,CAAA,QAAA,CAAS,OAAO,CAAA,IAAK,QAAS,CAAA,OAAA,CAAQ,WAAW,CACnE,CAAA,EAAA;AACA,IAAA,OAAO,qBAAsB,EAAA,CAAA;AAAA,GAC/B;AAEA,EAAO,OAAA,QAAA,CAAA;AACT,CAAA;AAEO,SAAS,qBAA6C,GAAA;AAC3D,EAAO,OAAA,EAAE,MAAM,KAAO,EAAA,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,WAAY,EAAC,CAAE,EAAA,CAAA;AACzD,CAAA;AAEO,SAAS,kBAAkB,IAAmC,EAAA;AACnE,EAAO,OAAA,IAAA,CAAK,UAAU,IAAI,CAAA,CAAA;AAC5B;;;;"}
|
|
1
|
+
{"version":3,"file":"schema.js","sources":["../../src/collaboration-liveblocks/schema.ts"],"sourcesContent":["import {\n type LiveblocksProsemirrorNode,\n liveblocksProsemirrorNodeToJson,\n type ProseMirrorJsonNode,\n} from \"@liveblocks/prosemirror\";\n\nexport type {\n LiveblocksProsemirrorNode as LiveblocksTiptapNode,\n ProseMirrorJsonMark,\n ProseMirrorJsonNode,\n} from \"@liveblocks/prosemirror\";\nexport {\n createLiveblocksProsemirrorNode as createLiveblocksTiptapNode,\n getLiveblocksNodeContent,\n getLiveblocksNodeId,\n getLiveblocksNodeText,\n liveblocksProsemirrorNodeToJsonNodes as liveblocksTiptapNodeToJsonNodes,\n} from \"@liveblocks/prosemirror\";\n\nexport function createDefaultDocument(): ProseMirrorJsonNode {\n return { type: \"doc\", content: [{ type: \"paragraph\" }] };\n}\n\nexport function liveblocksTiptapNodeToJson(\n node: LiveblocksProsemirrorNode\n): ProseMirrorJsonNode {\n return liveblocksProsemirrorNodeToJson(node, createDefaultDocument);\n}\n"],"names":[],"mappings":";;;AAmBO,SAAS,qBAA6C,GAAA;AAC3D,EAAO,OAAA,EAAE,MAAM,KAAO,EAAA,OAAA,EAAS,CAAC,EAAE,IAAA,EAAM,WAAY,EAAC,CAAE,EAAA,CAAA;AACzD,CAAA;AAEO,SAAS,2BACd,IACqB,EAAA;AACrB,EAAO,OAAA,+BAAA,CAAgC,MAAM,qBAAqB,CAAA,CAAA;AACpE;;;;"}
|
|
@@ -6,9 +6,10 @@ var model = require('@tiptap/pm/model');
|
|
|
6
6
|
var state = require('@tiptap/pm/state');
|
|
7
7
|
var view = require('@tiptap/pm/view');
|
|
8
8
|
var yProsemirror = require('y-prosemirror');
|
|
9
|
-
|
|
9
|
+
require('../collaboration-liveblocks/plugin.cjs');
|
|
10
10
|
var types = require('../types.cjs');
|
|
11
11
|
var utils = require('../utils.cjs');
|
|
12
|
+
var prosemirror = require('@liveblocks/prosemirror');
|
|
12
13
|
|
|
13
14
|
const FILTERED_THREADS_PLUGIN_KEY = new state.PluginKey();
|
|
14
15
|
function getFilteredThreads(state) {
|
|
@@ -261,7 +262,7 @@ const CommentsExtension = core.Extension.create({
|
|
|
261
262
|
onSelectionUpdate({ transaction }) {
|
|
262
263
|
const yjsMeta = transaction.getMeta(yProsemirror.ySyncPluginKey);
|
|
263
264
|
const liveblocksMeta = transaction.getMeta(
|
|
264
|
-
|
|
265
|
+
prosemirror.LIVEBLOCKS_COLLABORATION_PLUGIN_KEY
|
|
265
266
|
);
|
|
266
267
|
const isRemoteCollaborationUpdate = yjsMeta || liveblocksMeta;
|
|
267
268
|
if (this.storage.pendingComment && !isRemoteCollaborationUpdate) {
|