@liveblocks/react-tiptap 3.21.0-exp1 → 3.21.0-exp2
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/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/mentions/MentionExtension.cjs +3 -2
- package/dist/mentions/MentionExtension.cjs.map +1 -1
- package/dist/mentions/MentionExtension.js +2 -1
- package/dist/mentions/MentionExtension.js.map +1 -1
- package/dist/version.cjs +1 -1
- package/dist/version.js +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,198 +1,12 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var
|
|
3
|
+
var prosemirror = require('@liveblocks/prosemirror');
|
|
4
4
|
var core = require('@tiptap/core');
|
|
5
|
-
var model = require('@tiptap/pm/model');
|
|
6
|
-
var state = require('@tiptap/pm/state');
|
|
7
|
-
var remote = require('./remote.cjs');
|
|
8
5
|
var schema = require('./schema.cjs');
|
|
9
|
-
var steps = require('./steps.cjs');
|
|
10
6
|
|
|
11
|
-
const LIVEBLOCKS_COLLABORATION_PLUGIN_KEY = new state.PluginKey("liveblocks-collaboration");
|
|
12
7
|
function isProseMirrorJsonNode(value) {
|
|
13
8
|
return typeof value === "object" && value !== null && typeof value.type === "string";
|
|
14
9
|
}
|
|
15
|
-
function getInitialDocument(initialContent, view) {
|
|
16
|
-
if (isProseMirrorJsonNode(initialContent)) {
|
|
17
|
-
return initialContent;
|
|
18
|
-
}
|
|
19
|
-
const currentDocument = view.state.doc.toJSON();
|
|
20
|
-
if (isProseMirrorJsonNode(currentDocument)) {
|
|
21
|
-
return currentDocument;
|
|
22
|
-
}
|
|
23
|
-
return schema.createDefaultDocument();
|
|
24
|
-
}
|
|
25
|
-
function replaceEditorDocument(view, document) {
|
|
26
|
-
let nextDocument;
|
|
27
|
-
try {
|
|
28
|
-
nextDocument = view.state.schema.nodeFromJSON(document);
|
|
29
|
-
} catch {
|
|
30
|
-
nextDocument = view.state.schema.nodeFromJSON(schema.createDefaultDocument());
|
|
31
|
-
}
|
|
32
|
-
if (nextDocument.childCount === 0) {
|
|
33
|
-
nextDocument = view.state.schema.nodeFromJSON(schema.createDefaultDocument());
|
|
34
|
-
}
|
|
35
|
-
const tr = view.state.tr.replace(
|
|
36
|
-
0,
|
|
37
|
-
view.state.doc.content.size,
|
|
38
|
-
new model.Slice(nextDocument.content, 0, 0)
|
|
39
|
-
);
|
|
40
|
-
tr.setMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY, { isRemote: true }).setMeta(
|
|
41
|
-
"addToHistory",
|
|
42
|
-
false
|
|
43
|
-
);
|
|
44
|
-
view.dispatch(tr);
|
|
45
|
-
}
|
|
46
|
-
function getDocumentRoot(root, field) {
|
|
47
|
-
const documentRoot = root.get(field);
|
|
48
|
-
if (!(documentRoot instanceof client.LiveObject)) {
|
|
49
|
-
return void 0;
|
|
50
|
-
}
|
|
51
|
-
return documentRoot;
|
|
52
|
-
}
|
|
53
|
-
function setDocumentRoot(root, field, document) {
|
|
54
|
-
root.set(field, schema.createLiveblocksTiptapNode(document));
|
|
55
|
-
}
|
|
56
|
-
function createLiveblocksCollaborationPlugin(options) {
|
|
57
|
-
const room = options.room;
|
|
58
|
-
if (room === void 0) {
|
|
59
|
-
throw new Error(
|
|
60
|
-
"[Liveblocks] The Liveblocks collaboration plugin requires a room."
|
|
61
|
-
);
|
|
62
|
-
}
|
|
63
|
-
let view;
|
|
64
|
-
let root;
|
|
65
|
-
let unsubscribe;
|
|
66
|
-
let destroyed = false;
|
|
67
|
-
let isApplyingRemoteUpdate = false;
|
|
68
|
-
let isApplyingLocalUpdate = false;
|
|
69
|
-
let lastDocument = "";
|
|
70
|
-
const applyStorageToEditor = (updates) => {
|
|
71
|
-
if (view === void 0 || root === void 0) {
|
|
72
|
-
return;
|
|
73
|
-
}
|
|
74
|
-
const documentRoot = getDocumentRoot(root, options.field);
|
|
75
|
-
if (documentRoot === void 0) {
|
|
76
|
-
return;
|
|
77
|
-
}
|
|
78
|
-
if (isApplyingLocalUpdate) {
|
|
79
|
-
return;
|
|
80
|
-
}
|
|
81
|
-
const document = schema.liveblocksTiptapNodeToJson(documentRoot);
|
|
82
|
-
const serializedDocument = schema.stringifyDocument(document);
|
|
83
|
-
if (serializedDocument === lastDocument) {
|
|
84
|
-
return;
|
|
85
|
-
}
|
|
86
|
-
if (updates !== void 0) {
|
|
87
|
-
const result = remote.applyRemoteStorageUpdates(view, documentRoot, updates);
|
|
88
|
-
if (result.type === "applied") {
|
|
89
|
-
lastDocument = serializedDocument;
|
|
90
|
-
isApplyingRemoteUpdate = true;
|
|
91
|
-
try {
|
|
92
|
-
view.dispatch(
|
|
93
|
-
result.tr.setMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY, { isRemote: true }).setMeta("addToHistory", false)
|
|
94
|
-
);
|
|
95
|
-
} finally {
|
|
96
|
-
isApplyingRemoteUpdate = false;
|
|
97
|
-
}
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
100
|
-
}
|
|
101
|
-
lastDocument = serializedDocument;
|
|
102
|
-
isApplyingRemoteUpdate = true;
|
|
103
|
-
try {
|
|
104
|
-
replaceEditorDocument(view, document);
|
|
105
|
-
} finally {
|
|
106
|
-
isApplyingRemoteUpdate = false;
|
|
107
|
-
}
|
|
108
|
-
};
|
|
109
|
-
return new state.Plugin({
|
|
110
|
-
key: LIVEBLOCKS_COLLABORATION_PLUGIN_KEY,
|
|
111
|
-
state: {
|
|
112
|
-
init: () => ({ isReady: false }),
|
|
113
|
-
apply(tr, state) {
|
|
114
|
-
const meta = tr.getMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY);
|
|
115
|
-
return meta?.isReady !== void 0 ? { ...state, isReady: meta.isReady } : state;
|
|
116
|
-
}
|
|
117
|
-
},
|
|
118
|
-
appendTransaction(transactions, oldState, newState) {
|
|
119
|
-
if (root === void 0 || isApplyingRemoteUpdate || !transactions.some((transaction) => transaction.docChanged) || transactions.some(
|
|
120
|
-
(transaction) => Boolean(transaction.getMeta(LIVEBLOCKS_COLLABORATION_PLUGIN_KEY))
|
|
121
|
-
)) {
|
|
122
|
-
return null;
|
|
123
|
-
}
|
|
124
|
-
const currentRoot = root;
|
|
125
|
-
const documentRoot = getDocumentRoot(currentRoot, options.field);
|
|
126
|
-
const classified = documentRoot !== void 0 ? steps.classifyTransaction(
|
|
127
|
-
transactions,
|
|
128
|
-
oldState.doc,
|
|
129
|
-
newState.doc,
|
|
130
|
-
documentRoot
|
|
131
|
-
) : { type: "unsupported" };
|
|
132
|
-
room.batch(() => {
|
|
133
|
-
if (classified.type === "incremental") {
|
|
134
|
-
isApplyingLocalUpdate = true;
|
|
135
|
-
try {
|
|
136
|
-
steps.applyIncrementalOperations(classified.operations);
|
|
137
|
-
} finally {
|
|
138
|
-
isApplyingLocalUpdate = false;
|
|
139
|
-
}
|
|
140
|
-
} else {
|
|
141
|
-
const document = newState.doc.toJSON();
|
|
142
|
-
if (!isProseMirrorJsonNode(document)) {
|
|
143
|
-
return;
|
|
144
|
-
}
|
|
145
|
-
const serializedDocument = schema.stringifyDocument(document);
|
|
146
|
-
if (serializedDocument === lastDocument) {
|
|
147
|
-
return;
|
|
148
|
-
}
|
|
149
|
-
lastDocument = serializedDocument;
|
|
150
|
-
setDocumentRoot(currentRoot, options.field, document);
|
|
151
|
-
}
|
|
152
|
-
});
|
|
153
|
-
return null;
|
|
154
|
-
},
|
|
155
|
-
view(editorView) {
|
|
156
|
-
view = editorView;
|
|
157
|
-
room.getStorage().then(({ root: storageRoot }) => {
|
|
158
|
-
if (destroyed) {
|
|
159
|
-
return;
|
|
160
|
-
}
|
|
161
|
-
root = storageRoot;
|
|
162
|
-
if (getDocumentRoot(storageRoot, options.field) === void 0) {
|
|
163
|
-
const initialDocument = getInitialDocument(
|
|
164
|
-
options.initialContent,
|
|
165
|
-
editorView
|
|
166
|
-
);
|
|
167
|
-
room.history.disable(() => {
|
|
168
|
-
setDocumentRoot(storageRoot, options.field, initialDocument);
|
|
169
|
-
});
|
|
170
|
-
}
|
|
171
|
-
applyStorageToEditor();
|
|
172
|
-
const tr = editorView.state.tr.setMeta(
|
|
173
|
-
LIVEBLOCKS_COLLABORATION_PLUGIN_KEY,
|
|
174
|
-
{ isReady: true }
|
|
175
|
-
);
|
|
176
|
-
editorView.dispatch(tr);
|
|
177
|
-
unsubscribe = room.subscribe(storageRoot, applyStorageToEditor, {
|
|
178
|
-
isDeep: true
|
|
179
|
-
});
|
|
180
|
-
});
|
|
181
|
-
return {
|
|
182
|
-
update(nextView) {
|
|
183
|
-
view = nextView;
|
|
184
|
-
},
|
|
185
|
-
destroy() {
|
|
186
|
-
destroyed = true;
|
|
187
|
-
unsubscribe?.();
|
|
188
|
-
unsubscribe = void 0;
|
|
189
|
-
view = void 0;
|
|
190
|
-
root = void 0;
|
|
191
|
-
}
|
|
192
|
-
};
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
10
|
const LiveblocksCollaboration = core.Extension.create({
|
|
197
11
|
name: "collaboration",
|
|
198
12
|
priority: 1e3,
|
|
@@ -240,10 +54,20 @@ const LiveblocksCollaboration = core.Extension.create({
|
|
|
240
54
|
};
|
|
241
55
|
},
|
|
242
56
|
addProseMirrorPlugins() {
|
|
243
|
-
return [
|
|
57
|
+
return [
|
|
58
|
+
prosemirror.createLiveblocksCollaborationPlugin({
|
|
59
|
+
room: this.options.room,
|
|
60
|
+
field: this.options.field,
|
|
61
|
+
initialContent: isProseMirrorJsonNode(this.options.initialContent) ? this.options.initialContent : void 0,
|
|
62
|
+
fallbackDocument: schema.createDefaultDocument
|
|
63
|
+
})
|
|
64
|
+
];
|
|
244
65
|
}
|
|
245
66
|
});
|
|
246
67
|
|
|
247
|
-
exports
|
|
68
|
+
Object.defineProperty(exports, 'LIVEBLOCKS_COLLABORATION_PLUGIN_KEY', {
|
|
69
|
+
enumerable: true,
|
|
70
|
+
get: function () { return prosemirror.LIVEBLOCKS_COLLABORATION_PLUGIN_KEY; }
|
|
71
|
+
});
|
|
248
72
|
exports.LiveblocksCollaboration = LiveblocksCollaboration;
|
|
249
73
|
//# sourceMappingURL=plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","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":["PluginKey","createDefaultDocument","Slice","LiveObject","createLiveblocksTiptapNode","liveblocksTiptapNodeToJson","stringifyDocument","applyRemoteStorageUpdates","Plugin","classifyTransaction","applyIncrementalOperations","Extension"],"mappings":";;;;;;;;;;AAoBa,MAAA,mCAAA,GAAsC,IAAIA,eAAA,CAEpD,0BAA0B,EAAA;AAY7B,SAAS,sBAAsB,KAA8C,EAAA;AAC3E,EAAA,OACE,OAAO,KAAU,KAAA,QAA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C;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs","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":["Extension","createLiveblocksCollaborationPlugin","createDefaultDocument"],"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,GAA0BA,eAAU,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,EA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AAAC,4BAAA;AAAA,OACnB,CAAA;AAAA,KACH,CAAA;AAAA,GACF;AACF,CAAC;;;;;;;;"}
|
|
@@ -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;AAC3E,EAAA,OACE,OAAO,KAAU,KAAA,QAAA,IACjB,UAAU,IACV,IAAA,OAAQ,MAA6B,IAAS,KAAA,QAAA,CAAA;AAElD,CAAA;AAEA,SAAS,kBAAA,CACP,gBACA,IACqB,EAAA;AACrB,EAAI,IAAA,qBAAA,CAAsB,cAAc,CAAG,EAAA;AACzC,IAAO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UAAK,IAAA,CAAA,OAAA,CAAQ,IAAK,CAAA,OAAA,CAAQ,IAAK,EAAA,CAAA;AAAA,SACjC;AAEA,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAAA,MACF,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,CAAA,OAAA,CAAQ,IAAK,CAAA,OAAA,CAAQ,IAAK,EAAA,CAAA;AAAA,SACjC;AAEA,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAAA,KACJ,CAAA;AAAA,GACF;AAAA,EAEA,oBAAuB,GAAA;AACrB,IAAO,OAAA;AAAA,MACL,OAAS,EAAA,MAAM,IAAK,CAAA,MAAA,CAAO,SAAS,IAAK,EAAA;AAAA,MACzC,OAAS,EAAA,MAAM,IAAK,CAAA,MAAA,CAAO,SAAS,IAAK,EAAA;AAAA,MACzC,aAAe,EAAA,MAAM,IAAK,CAAA,MAAA,CAAO,SAAS,IAAK,EAAA;AAAA,KACjD,CAAA;AAAA,GACF;AAAA,EAEA,qBAAwB,GAAA;AACtB,IAAA,OAAO,CAAC,mCAAA,CAAoC,IAAK,CAAA,OAAO,CAAC,CAAA,CAAA;AAAA,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,CAAA,OAAA,CAAQ,IAAK,CAAA,OAAA,CAAQ,IAAK,EAAA,CAAA;AAAA,SACjC;AAEA,QAAO,OAAA,IAAA,CAAA;AAAA,OACT;AAAA,MACF,MACE,MACA,CAAC,EAAE,QAAA,EAAU,IAAS,KAAA;AACpB,QAAG,EAAA,CAAA,OAAA,CAAQ,mBAAmB,I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