@liveblocks/react-tiptap 3.19.5-rc1 → 3.20.0-exp1
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 +51 -5
- package/dist/LiveblocksExtension.cjs.map +1 -1
- package/dist/LiveblocksExtension.js +51 -5
- package/dist/LiveblocksExtension.js.map +1 -1
- package/dist/ai/AiExtension.cjs +2 -1
- package/dist/ai/AiExtension.cjs.map +1 -1
- package/dist/ai/AiExtension.js +2 -1
- package/dist/ai/AiExtension.js.map +1 -1
- package/dist/collaboration-liveblocks/cursors.cjs +267 -0
- package/dist/collaboration-liveblocks/cursors.cjs.map +1 -0
- package/dist/collaboration-liveblocks/cursors.js +264 -0
- package/dist/collaboration-liveblocks/cursors.js.map +1 -0
- package/dist/collaboration-liveblocks/mapping.cjs +218 -0
- package/dist/collaboration-liveblocks/mapping.cjs.map +1 -0
- package/dist/collaboration-liveblocks/mapping.js +207 -0
- package/dist/collaboration-liveblocks/mapping.js.map +1 -0
- package/dist/collaboration-liveblocks/plugin.cjs +249 -0
- package/dist/collaboration-liveblocks/plugin.cjs.map +1 -0
- package/dist/collaboration-liveblocks/plugin.js +246 -0
- package/dist/collaboration-liveblocks/plugin.js.map +1 -0
- package/dist/collaboration-liveblocks/remote.cjs +210 -0
- package/dist/collaboration-liveblocks/remote.cjs.map +1 -0
- package/dist/collaboration-liveblocks/remote.js +207 -0
- package/dist/collaboration-liveblocks/remote.js.map +1 -0
- package/dist/collaboration-liveblocks/schema.cjs +150 -0
- package/dist/collaboration-liveblocks/schema.cjs.map +1 -0
- package/dist/collaboration-liveblocks/schema.js +135 -0
- package/dist/collaboration-liveblocks/schema.js.map +1 -0
- package/dist/collaboration-liveblocks/steps.cjs +359 -0
- package/dist/collaboration-liveblocks/steps.cjs.map +1 -0
- package/dist/collaboration-liveblocks/steps.js +356 -0
- package/dist/collaboration-liveblocks/steps.js.map +1 -0
- package/dist/comments/CommentsExtension.cjs +7 -1
- package/dist/comments/CommentsExtension.cjs.map +1 -1
- package/dist/comments/CommentsExtension.js +7 -1
- package/dist/comments/CommentsExtension.js.map +1 -1
- package/dist/index.d.cts +5 -0
- package/dist/index.d.ts +5 -0
- package/dist/mentions/MentionExtension.cjs +4 -1
- package/dist/mentions/MentionExtension.cjs.map +1 -1
- package/dist/mentions/MentionExtension.js +4 -1
- 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 +6 -6
- package/src/styles/index.css +12 -4
- package/styles.css +1 -1
- package/styles.css.map +1 -1
|
@@ -0,0 +1,359 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var client = require('@liveblocks/client');
|
|
4
|
+
var mapping = require('./mapping.cjs');
|
|
5
|
+
var schema = require('./schema.cjs');
|
|
6
|
+
|
|
7
|
+
function isObject(value) {
|
|
8
|
+
return typeof value === "object" && value !== null;
|
|
9
|
+
}
|
|
10
|
+
function isJsonObject(value) {
|
|
11
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
function parseMarks(value) {
|
|
14
|
+
if (!Array.isArray(value)) {
|
|
15
|
+
return void 0;
|
|
16
|
+
}
|
|
17
|
+
const marks = [];
|
|
18
|
+
for (const mark of value) {
|
|
19
|
+
if (!isObject(mark) || typeof mark.type !== "string") {
|
|
20
|
+
return void 0;
|
|
21
|
+
}
|
|
22
|
+
marks.push({
|
|
23
|
+
type: mark.type,
|
|
24
|
+
...isJsonObject(mark.attrs) ? { attrs: mark.attrs } : {}
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
return marks.length > 0 ? marks : void 0;
|
|
28
|
+
}
|
|
29
|
+
function parseProseMirrorJsonNode(value) {
|
|
30
|
+
if (!isObject(value) || typeof value.type !== "string") {
|
|
31
|
+
return void 0;
|
|
32
|
+
}
|
|
33
|
+
const node = { type: value.type };
|
|
34
|
+
if (isJsonObject(value.attrs)) {
|
|
35
|
+
node.attrs = value.attrs;
|
|
36
|
+
}
|
|
37
|
+
if (typeof value.text === "string") {
|
|
38
|
+
node.text = value.text;
|
|
39
|
+
}
|
|
40
|
+
const marks = parseMarks(value.marks);
|
|
41
|
+
if (marks !== void 0) {
|
|
42
|
+
node.marks = marks;
|
|
43
|
+
}
|
|
44
|
+
if (Array.isArray(value.content)) {
|
|
45
|
+
const content = [];
|
|
46
|
+
for (const child of value.content) {
|
|
47
|
+
const parsedChild = parseProseMirrorJsonNode(child);
|
|
48
|
+
if (parsedChild === void 0) {
|
|
49
|
+
return void 0;
|
|
50
|
+
}
|
|
51
|
+
content.push(parsedChild);
|
|
52
|
+
}
|
|
53
|
+
node.content = content;
|
|
54
|
+
}
|
|
55
|
+
return node;
|
|
56
|
+
}
|
|
57
|
+
function prosemirrorNodeToJson(node) {
|
|
58
|
+
return parseProseMirrorJsonNode(node.toJSON());
|
|
59
|
+
}
|
|
60
|
+
function getNodeAttrs(node) {
|
|
61
|
+
return prosemirrorNodeToJson(node)?.attrs;
|
|
62
|
+
}
|
|
63
|
+
function isReplaceStepJson(value) {
|
|
64
|
+
return isObject(value) && value.stepType === "replace" && typeof value.from === "number" && typeof value.to === "number";
|
|
65
|
+
}
|
|
66
|
+
function isMarkStepJson(value) {
|
|
67
|
+
return isObject(value) && (value.stepType === "addMark" || value.stepType === "removeMark") && typeof value.from === "number" && typeof value.to === "number";
|
|
68
|
+
}
|
|
69
|
+
function getTextContentFromSlice(slice) {
|
|
70
|
+
const content = slice?.content;
|
|
71
|
+
if (content === void 0 || content.length === 0) {
|
|
72
|
+
return { text: "" };
|
|
73
|
+
}
|
|
74
|
+
let text = "";
|
|
75
|
+
let marks;
|
|
76
|
+
for (const node of content) {
|
|
77
|
+
if (!isObject(node) || node.type !== "text") {
|
|
78
|
+
return void 0;
|
|
79
|
+
}
|
|
80
|
+
const nodeText = node.text;
|
|
81
|
+
if (typeof nodeText !== "string") {
|
|
82
|
+
return void 0;
|
|
83
|
+
}
|
|
84
|
+
const nodeMarks = parseMarks(node.marks);
|
|
85
|
+
if (text.length === 0) {
|
|
86
|
+
marks = nodeMarks;
|
|
87
|
+
} else if (JSON.stringify(marks ?? []) !== JSON.stringify(nodeMarks ?? [])) {
|
|
88
|
+
return void 0;
|
|
89
|
+
}
|
|
90
|
+
text += nodeText;
|
|
91
|
+
}
|
|
92
|
+
return { text, marks };
|
|
93
|
+
}
|
|
94
|
+
function classifyReplaceStep(step, oldDoc, liveRoot) {
|
|
95
|
+
const inserted = getTextContentFromSlice(step.slice);
|
|
96
|
+
if (inserted === void 0) {
|
|
97
|
+
return void 0;
|
|
98
|
+
}
|
|
99
|
+
const operations = [];
|
|
100
|
+
if (step.from !== step.to) {
|
|
101
|
+
const fromRange = mapping.findTextRangeAtPositionInDocument(
|
|
102
|
+
oldDoc,
|
|
103
|
+
liveRoot,
|
|
104
|
+
step.from
|
|
105
|
+
);
|
|
106
|
+
const toRange = mapping.findTextRangeAtPositionInDocument(
|
|
107
|
+
oldDoc,
|
|
108
|
+
liveRoot,
|
|
109
|
+
step.to
|
|
110
|
+
);
|
|
111
|
+
if (fromRange === void 0 || toRange === void 0 || fromRange.nodeId !== toRange.nodeId) {
|
|
112
|
+
return void 0;
|
|
113
|
+
}
|
|
114
|
+
operations.push({
|
|
115
|
+
type: "delete",
|
|
116
|
+
node: fromRange.node,
|
|
117
|
+
index: fromRange.liveOffset + step.from - fromRange.from,
|
|
118
|
+
length: step.to - step.from
|
|
119
|
+
});
|
|
120
|
+
}
|
|
121
|
+
if (inserted.text.length > 0) {
|
|
122
|
+
const range = mapping.findTextRangeAtPositionInDocument(
|
|
123
|
+
oldDoc,
|
|
124
|
+
liveRoot,
|
|
125
|
+
step.from
|
|
126
|
+
);
|
|
127
|
+
if (range === void 0) {
|
|
128
|
+
return void 0;
|
|
129
|
+
}
|
|
130
|
+
operations.push({
|
|
131
|
+
type: "insert",
|
|
132
|
+
node: range.node,
|
|
133
|
+
index: range.liveOffset + step.from - range.from,
|
|
134
|
+
text: inserted.text,
|
|
135
|
+
attributes: schema.marksToAttributes(inserted.marks)
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return operations.length > 0 ? operations : void 0;
|
|
139
|
+
}
|
|
140
|
+
function marksFromNode(node) {
|
|
141
|
+
const marks = node.marks.map((mark) => {
|
|
142
|
+
const json = mark.toJSON();
|
|
143
|
+
if (!isObject(json) || typeof json.type !== "string") {
|
|
144
|
+
return void 0;
|
|
145
|
+
}
|
|
146
|
+
return {
|
|
147
|
+
type: json.type,
|
|
148
|
+
...isJsonObject(json.attrs) ? { attrs: json.attrs } : {}
|
|
149
|
+
};
|
|
150
|
+
});
|
|
151
|
+
const parsedMarks = marks.filter((mark) => mark !== void 0);
|
|
152
|
+
return parsedMarks.length > 0 ? parsedMarks : void 0;
|
|
153
|
+
}
|
|
154
|
+
function classifyMarkStep(step, oldIndex, newDoc) {
|
|
155
|
+
const operations = [];
|
|
156
|
+
newDoc.nodesBetween(step.from, step.to, (node, pos) => {
|
|
157
|
+
if (!node.isText || node.nodeSize === 0) {
|
|
158
|
+
return true;
|
|
159
|
+
}
|
|
160
|
+
const from = Math.max(step.from, pos);
|
|
161
|
+
const to = Math.min(step.to, pos + node.nodeSize);
|
|
162
|
+
const range = mapping.findTextRangeAtPosition(oldIndex, from);
|
|
163
|
+
if (range === void 0 || to <= from) {
|
|
164
|
+
operations.length = 0;
|
|
165
|
+
return false;
|
|
166
|
+
}
|
|
167
|
+
operations.push({
|
|
168
|
+
type: "format",
|
|
169
|
+
node: range.node,
|
|
170
|
+
index: range.liveOffset + from - range.from,
|
|
171
|
+
length: to - from,
|
|
172
|
+
attributes: schema.marksToAttributesPatch(marksFromNode(node))
|
|
173
|
+
});
|
|
174
|
+
return true;
|
|
175
|
+
});
|
|
176
|
+
return operations.length > 0 ? operations : void 0;
|
|
177
|
+
}
|
|
178
|
+
function createNodeOperation(type, content, index, node) {
|
|
179
|
+
const jsonNode = prosemirrorNodeToJson(node);
|
|
180
|
+
if (jsonNode === void 0) {
|
|
181
|
+
return void 0;
|
|
182
|
+
}
|
|
183
|
+
return {
|
|
184
|
+
type,
|
|
185
|
+
content,
|
|
186
|
+
index,
|
|
187
|
+
node: schema.createLiveblocksTiptapNode(jsonNode)
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
function classifyAttrsChange(oldNode, newNode, liveNode) {
|
|
191
|
+
if (oldNode.isText || oldNode.type !== newNode.type || !oldNode.content.eq(newNode.content) || oldNode.sameMarkup(newNode)) {
|
|
192
|
+
return void 0;
|
|
193
|
+
}
|
|
194
|
+
return [
|
|
195
|
+
{ type: "updateAttrs", node: liveNode, attrs: getNodeAttrs(newNode) }
|
|
196
|
+
];
|
|
197
|
+
}
|
|
198
|
+
function findCommonPrefix(oldParent, newParent) {
|
|
199
|
+
const max = Math.min(oldParent.childCount, newParent.childCount);
|
|
200
|
+
let prefix = 0;
|
|
201
|
+
while (prefix < max && oldParent.child(prefix).eq(newParent.child(prefix))) {
|
|
202
|
+
prefix++;
|
|
203
|
+
}
|
|
204
|
+
return prefix;
|
|
205
|
+
}
|
|
206
|
+
function findCommonSuffix(oldParent, newParent, prefix) {
|
|
207
|
+
const max = Math.min(
|
|
208
|
+
oldParent.childCount - prefix,
|
|
209
|
+
newParent.childCount - prefix
|
|
210
|
+
);
|
|
211
|
+
let suffix = 0;
|
|
212
|
+
while (suffix < max && oldParent.child(oldParent.childCount - suffix - 1).eq(newParent.child(newParent.childCount - suffix - 1))) {
|
|
213
|
+
suffix++;
|
|
214
|
+
}
|
|
215
|
+
return suffix;
|
|
216
|
+
}
|
|
217
|
+
function classifyChildrenChange(oldParent, newParent, liveParent) {
|
|
218
|
+
const content = schema.getLiveblocksNodeContent(liveParent);
|
|
219
|
+
if (content === void 0) {
|
|
220
|
+
return void 0;
|
|
221
|
+
}
|
|
222
|
+
if (oldParent.childCount === newParent.childCount) {
|
|
223
|
+
const operations = [];
|
|
224
|
+
for (let index = 0; index < oldParent.childCount; index++) {
|
|
225
|
+
const oldChild = oldParent.child(index);
|
|
226
|
+
const newChild = newParent.child(index);
|
|
227
|
+
if (oldChild.eq(newChild)) {
|
|
228
|
+
continue;
|
|
229
|
+
}
|
|
230
|
+
const liveChild = content.get(index);
|
|
231
|
+
if (liveChild === void 0) {
|
|
232
|
+
return void 0;
|
|
233
|
+
}
|
|
234
|
+
const childOperations = classifyAttrsChange(oldChild, newChild, liveChild) ?? classifyNodeChange(oldChild, newChild, liveChild);
|
|
235
|
+
if (childOperations !== void 0) {
|
|
236
|
+
operations.push(...childOperations);
|
|
237
|
+
continue;
|
|
238
|
+
}
|
|
239
|
+
const operation = createNodeOperation(
|
|
240
|
+
"setNode",
|
|
241
|
+
content,
|
|
242
|
+
index,
|
|
243
|
+
newChild
|
|
244
|
+
);
|
|
245
|
+
if (operation === void 0) {
|
|
246
|
+
return void 0;
|
|
247
|
+
}
|
|
248
|
+
operations.push(operation);
|
|
249
|
+
}
|
|
250
|
+
return operations.length > 0 ? operations : void 0;
|
|
251
|
+
}
|
|
252
|
+
const prefix = findCommonPrefix(oldParent, newParent);
|
|
253
|
+
const suffix = findCommonSuffix(oldParent, newParent, prefix);
|
|
254
|
+
if (oldParent.childCount + 1 === newParent.childCount && prefix + suffix === oldParent.childCount) {
|
|
255
|
+
const operation = createNodeOperation(
|
|
256
|
+
"insertNode",
|
|
257
|
+
content,
|
|
258
|
+
prefix,
|
|
259
|
+
newParent.child(prefix)
|
|
260
|
+
);
|
|
261
|
+
return operation === void 0 ? void 0 : [operation];
|
|
262
|
+
}
|
|
263
|
+
if (oldParent.childCount + 1 === newParent.childCount && prefix + suffix + 1 === oldParent.childCount) {
|
|
264
|
+
const setOperation = createNodeOperation(
|
|
265
|
+
"setNode",
|
|
266
|
+
content,
|
|
267
|
+
prefix,
|
|
268
|
+
newParent.child(prefix)
|
|
269
|
+
);
|
|
270
|
+
const insertOperation = createNodeOperation(
|
|
271
|
+
"insertNode",
|
|
272
|
+
content,
|
|
273
|
+
prefix + 1,
|
|
274
|
+
newParent.child(prefix + 1)
|
|
275
|
+
);
|
|
276
|
+
return setOperation === void 0 || insertOperation === void 0 ? void 0 : [setOperation, insertOperation];
|
|
277
|
+
}
|
|
278
|
+
if (oldParent.childCount - 1 === newParent.childCount && prefix + suffix === newParent.childCount) {
|
|
279
|
+
return [{ type: "deleteNode", content, index: prefix }];
|
|
280
|
+
}
|
|
281
|
+
if (oldParent.childCount - 1 === newParent.childCount && prefix + suffix + 1 === newParent.childCount) {
|
|
282
|
+
const operation = createNodeOperation(
|
|
283
|
+
"setNode",
|
|
284
|
+
content,
|
|
285
|
+
prefix,
|
|
286
|
+
newParent.child(prefix)
|
|
287
|
+
);
|
|
288
|
+
return operation === void 0 ? void 0 : [operation, { type: "deleteNode", content, index: prefix + 1 }];
|
|
289
|
+
}
|
|
290
|
+
return void 0;
|
|
291
|
+
}
|
|
292
|
+
function classifyNodeChange(oldNode, newNode, liveNode) {
|
|
293
|
+
const attrOperations = classifyAttrsChange(oldNode, newNode, liveNode) ?? [];
|
|
294
|
+
const childOperations = oldNode.type === newNode.type ? classifyChildrenChange(oldNode, newNode, liveNode) : void 0;
|
|
295
|
+
const operations = [...attrOperations, ...childOperations ?? []];
|
|
296
|
+
return operations.length > 0 ? operations : void 0;
|
|
297
|
+
}
|
|
298
|
+
function classifyStructuralChange(oldDoc, newDoc, liveRoot) {
|
|
299
|
+
return classifyNodeChange(oldDoc, newDoc, liveRoot);
|
|
300
|
+
}
|
|
301
|
+
function classifyTransaction(transactions, oldDoc, newDoc, liveRoot) {
|
|
302
|
+
const changedTransactions = transactions.filter(
|
|
303
|
+
(transaction2) => transaction2.docChanged
|
|
304
|
+
);
|
|
305
|
+
if (changedTransactions.length !== 1) {
|
|
306
|
+
return { type: "unsupported" };
|
|
307
|
+
}
|
|
308
|
+
const [transaction] = changedTransactions;
|
|
309
|
+
if (transaction === void 0 || transaction.steps.length !== 1) {
|
|
310
|
+
return { type: "unsupported" };
|
|
311
|
+
}
|
|
312
|
+
const [step] = transaction.steps;
|
|
313
|
+
const stepJson = step?.toJSON();
|
|
314
|
+
const operations = isReplaceStepJson(stepJson) ? classifyReplaceStep(stepJson, oldDoc, liveRoot) : isMarkStepJson(stepJson) ? classifyMarkStep(
|
|
315
|
+
stepJson,
|
|
316
|
+
mapping.buildLiveblocksTreeIndex(oldDoc, liveRoot),
|
|
317
|
+
newDoc
|
|
318
|
+
) : void 0;
|
|
319
|
+
const structuralOperations = operations ?? classifyStructuralChange(oldDoc, newDoc, liveRoot);
|
|
320
|
+
if (structuralOperations === void 0) {
|
|
321
|
+
return { type: "unsupported" };
|
|
322
|
+
}
|
|
323
|
+
return { type: "incremental", operations: structuralOperations };
|
|
324
|
+
}
|
|
325
|
+
function applyIncrementalOperations(operations) {
|
|
326
|
+
for (const operation of operations) {
|
|
327
|
+
if (operation.type === "insert") {
|
|
328
|
+
const text = operation.node.get("text");
|
|
329
|
+
if (!(text instanceof client.LiveText)) {
|
|
330
|
+
continue;
|
|
331
|
+
}
|
|
332
|
+
text.insert(operation.index, operation.text, operation.attributes);
|
|
333
|
+
} else if (operation.type === "delete") {
|
|
334
|
+
const text = operation.node.get("text");
|
|
335
|
+
if (!(text instanceof client.LiveText)) {
|
|
336
|
+
continue;
|
|
337
|
+
}
|
|
338
|
+
text.delete(operation.index, operation.length);
|
|
339
|
+
} else if (operation.type === "format") {
|
|
340
|
+
const text = operation.node.get("text");
|
|
341
|
+
if (!(text instanceof client.LiveText)) {
|
|
342
|
+
continue;
|
|
343
|
+
}
|
|
344
|
+
text.format(operation.index, operation.length, operation.attributes);
|
|
345
|
+
} else if (operation.type === "insertNode") {
|
|
346
|
+
operation.content.insert(operation.node, operation.index);
|
|
347
|
+
} else if (operation.type === "deleteNode") {
|
|
348
|
+
operation.content.delete(operation.index);
|
|
349
|
+
} else if (operation.type === "setNode") {
|
|
350
|
+
operation.content.set(operation.index, operation.node);
|
|
351
|
+
} else {
|
|
352
|
+
schema.updateLiveblocksNodeAttrs(operation.node, operation.attrs);
|
|
353
|
+
}
|
|
354
|
+
}
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
exports.applyIncrementalOperations = applyIncrementalOperations;
|
|
358
|
+
exports.classifyTransaction = classifyTransaction;
|
|
359
|
+
//# sourceMappingURL=steps.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"steps.cjs","sources":["../../src/collaboration-liveblocks/steps.ts"],"sourcesContent":["import { type JsonObject, type LiveList, LiveText } from \"@liveblocks/client\";\nimport type { Node as ProseMirrorNode } from \"@tiptap/pm/model\";\nimport type { Transaction } from \"@tiptap/pm/state\";\n\nimport {\n buildLiveblocksTreeIndex,\n findTextRangeAtPosition,\n findTextRangeAtPositionInDocument,\n type LiveblocksTreeIndex,\n} from \"./mapping\";\nimport {\n createLiveblocksTiptapNode,\n getLiveblocksNodeContent,\n type LiveblocksTiptapNode,\n marksToAttributes,\n marksToAttributesPatch,\n type ProseMirrorJsonMark,\n type ProseMirrorJsonNode,\n updateLiveblocksNodeAttrs,\n} from \"./schema\";\n\nexport type IncrementalOperation =\n | {\n type: \"insert\";\n text: string;\n index: number;\n attributes?: ReturnType<typeof marksToAttributes>;\n node: LiveblocksTiptapNode;\n }\n | {\n type: \"delete\";\n index: number;\n length: number;\n node: LiveblocksTiptapNode;\n }\n | {\n type: \"format\";\n index: number;\n length: number;\n attributes: ReturnType<typeof marksToAttributesPatch>;\n node: LiveblocksTiptapNode;\n }\n | {\n type: \"insertNode\";\n content: LiveList<LiveblocksTiptapNode>;\n index: number;\n node: LiveblocksTiptapNode;\n }\n | {\n type: \"deleteNode\";\n content: LiveList<LiveblocksTiptapNode>;\n index: number;\n }\n | {\n type: \"setNode\";\n content: LiveList<LiveblocksTiptapNode>;\n index: number;\n node: LiveblocksTiptapNode;\n }\n | {\n type: \"updateAttrs\";\n attrs: JsonObject | undefined;\n node: LiveblocksTiptapNode;\n };\n\nexport type ClassifiedTransaction =\n | {\n type: \"incremental\";\n operations: IncrementalOperation[];\n }\n | {\n type: \"unsupported\";\n };\n\ntype ReplaceStepJson = {\n stepType: \"replace\";\n from: number;\n to: number;\n slice?: {\n content?: unknown[];\n };\n};\n\ntype MarkStepJson = {\n stepType: \"addMark\" | \"removeMark\";\n from: number;\n to: number;\n};\n\nfunction isObject(value: unknown): value is Record<string, unknown> {\n return typeof value === \"object\" && value !== null;\n}\n\nfunction isJsonObject(value: unknown): value is JsonObject {\n return typeof value === \"object\" && value !== null && !Array.isArray(value);\n}\n\nfunction parseMarks(value: unknown): ProseMirrorJsonMark[] | undefined {\n if (!Array.isArray(value)) {\n return undefined;\n }\n\n const marks: ProseMirrorJsonMark[] = [];\n\n for (const mark of value) {\n if (!isObject(mark) || typeof mark.type !== \"string\") {\n return undefined;\n }\n\n marks.push({\n type: mark.type,\n ...(isJsonObject(mark.attrs) ? { attrs: mark.attrs } : {}),\n });\n }\n\n return marks.length > 0 ? marks : undefined;\n}\n\nfunction parseProseMirrorJsonNode(\n value: unknown\n): ProseMirrorJsonNode | undefined {\n if (!isObject(value) || typeof value.type !== \"string\") {\n return undefined;\n }\n\n const node: ProseMirrorJsonNode = { type: value.type };\n\n if (isJsonObject(value.attrs)) {\n node.attrs = value.attrs;\n }\n\n if (typeof value.text === \"string\") {\n node.text = value.text;\n }\n\n const marks = parseMarks(value.marks);\n if (marks !== undefined) {\n node.marks = marks;\n }\n\n if (Array.isArray(value.content)) {\n const content: ProseMirrorJsonNode[] = [];\n for (const child of value.content) {\n const parsedChild = parseProseMirrorJsonNode(child);\n if (parsedChild === undefined) {\n return undefined;\n }\n\n content.push(parsedChild);\n }\n\n node.content = content;\n }\n\n return node;\n}\n\nfunction prosemirrorNodeToJson(\n node: ProseMirrorNode\n): ProseMirrorJsonNode | undefined {\n return parseProseMirrorJsonNode(node.toJSON());\n}\n\nfunction getNodeAttrs(node: ProseMirrorNode): JsonObject | undefined {\n return prosemirrorNodeToJson(node)?.attrs;\n}\n\nfunction isReplaceStepJson(value: unknown): value is ReplaceStepJson {\n return (\n isObject(value) &&\n value.stepType === \"replace\" &&\n typeof value.from === \"number\" &&\n typeof value.to === \"number\"\n );\n}\n\nfunction isMarkStepJson(value: unknown): value is MarkStepJson {\n return (\n isObject(value) &&\n (value.stepType === \"addMark\" || value.stepType === \"removeMark\") &&\n typeof value.from === \"number\" &&\n typeof value.to === \"number\"\n );\n}\n\nfunction getTextContentFromSlice(\n slice: ReplaceStepJson[\"slice\"]\n): { text: string; marks?: ProseMirrorJsonMark[] } | undefined {\n const content = slice?.content;\n if (content === undefined || content.length === 0) {\n return { text: \"\" };\n }\n\n let text = \"\";\n let marks: ProseMirrorJsonMark[] | undefined;\n\n for (const node of content) {\n if (!isObject(node) || node.type !== \"text\") {\n return undefined;\n }\n\n const nodeText = node.text;\n if (typeof nodeText !== \"string\") {\n return undefined;\n }\n\n const nodeMarks = parseMarks(node.marks);\n if (text.length === 0) {\n marks = nodeMarks;\n } else if (\n JSON.stringify(marks ?? []) !== JSON.stringify(nodeMarks ?? [])\n ) {\n return undefined;\n }\n\n text += nodeText;\n }\n\n return { text, marks };\n}\n\nfunction classifyReplaceStep(\n step: ReplaceStepJson,\n oldDoc: ProseMirrorNode,\n liveRoot: LiveblocksTiptapNode\n): IncrementalOperation[] | undefined {\n const inserted = getTextContentFromSlice(step.slice);\n if (inserted === undefined) {\n return undefined;\n }\n\n const operations: IncrementalOperation[] = [];\n\n if (step.from !== step.to) {\n const fromRange = findTextRangeAtPositionInDocument(\n oldDoc,\n liveRoot,\n step.from\n );\n const toRange = findTextRangeAtPositionInDocument(\n oldDoc,\n liveRoot,\n step.to\n );\n\n if (\n fromRange === undefined ||\n toRange === undefined ||\n fromRange.nodeId !== toRange.nodeId\n ) {\n return undefined;\n }\n\n operations.push({\n type: \"delete\",\n node: fromRange.node,\n index: fromRange.liveOffset + step.from - fromRange.from,\n length: step.to - step.from,\n });\n }\n\n if (inserted.text.length > 0) {\n const range = findTextRangeAtPositionInDocument(\n oldDoc,\n liveRoot,\n step.from\n );\n if (range === undefined) {\n return undefined;\n }\n\n operations.push({\n type: \"insert\",\n node: range.node,\n index: range.liveOffset + step.from - range.from,\n text: inserted.text,\n attributes: marksToAttributes(inserted.marks),\n });\n }\n\n return operations.length > 0 ? operations : undefined;\n}\n\nfunction marksFromNode(\n node: ProseMirrorNode\n): ProseMirrorJsonMark[] | undefined {\n const marks = node.marks.map((mark) => {\n const json: unknown = mark.toJSON();\n if (!isObject(json) || typeof json.type !== \"string\") {\n return undefined;\n }\n\n return {\n type: json.type,\n ...(isJsonObject(json.attrs) ? { attrs: json.attrs } : {}),\n };\n });\n\n const parsedMarks = marks.filter((mark) => mark !== undefined);\n return parsedMarks.length > 0 ? parsedMarks : undefined;\n}\n\nfunction classifyMarkStep(\n step: MarkStepJson,\n oldIndex: LiveblocksTreeIndex,\n newDoc: ProseMirrorNode\n): IncrementalOperation[] | undefined {\n const operations: IncrementalOperation[] = [];\n\n newDoc.nodesBetween(step.from, step.to, (node, pos) => {\n if (!node.isText || node.nodeSize === 0) {\n return true;\n }\n\n const from = Math.max(step.from, pos);\n const to = Math.min(step.to, pos + node.nodeSize);\n const range = findTextRangeAtPosition(oldIndex, from);\n\n if (range === undefined || to <= from) {\n operations.length = 0;\n return false;\n }\n\n operations.push({\n type: \"format\",\n node: range.node,\n index: range.liveOffset + from - range.from,\n length: to - from,\n attributes: marksToAttributesPatch(marksFromNode(node)),\n });\n\n return true;\n });\n\n return operations.length > 0 ? operations : undefined;\n}\n\nfunction createNodeOperation(\n type: \"insertNode\" | \"setNode\",\n content: LiveList<LiveblocksTiptapNode>,\n index: number,\n node: ProseMirrorNode\n): IncrementalOperation | undefined {\n const jsonNode = prosemirrorNodeToJson(node);\n if (jsonNode === undefined) {\n return undefined;\n }\n\n return {\n type,\n content,\n index,\n node: createLiveblocksTiptapNode(jsonNode),\n };\n}\n\nfunction classifyAttrsChange(\n oldNode: ProseMirrorNode,\n newNode: ProseMirrorNode,\n liveNode: LiveblocksTiptapNode\n): IncrementalOperation[] | undefined {\n if (\n oldNode.isText ||\n oldNode.type !== newNode.type ||\n !oldNode.content.eq(newNode.content) ||\n oldNode.sameMarkup(newNode)\n ) {\n return undefined;\n }\n\n return [\n { type: \"updateAttrs\", node: liveNode, attrs: getNodeAttrs(newNode) },\n ];\n}\n\nfunction findCommonPrefix(\n oldParent: ProseMirrorNode,\n newParent: ProseMirrorNode\n): number {\n const max = Math.min(oldParent.childCount, newParent.childCount);\n let prefix = 0;\n\n while (prefix < max && oldParent.child(prefix).eq(newParent.child(prefix))) {\n prefix++;\n }\n\n return prefix;\n}\n\nfunction findCommonSuffix(\n oldParent: ProseMirrorNode,\n newParent: ProseMirrorNode,\n prefix: number\n): number {\n const max = Math.min(\n oldParent.childCount - prefix,\n newParent.childCount - prefix\n );\n let suffix = 0;\n\n while (\n suffix < max &&\n oldParent\n .child(oldParent.childCount - suffix - 1)\n .eq(newParent.child(newParent.childCount - suffix - 1))\n ) {\n suffix++;\n }\n\n return suffix;\n}\n\nfunction classifyChildrenChange(\n oldParent: ProseMirrorNode,\n newParent: ProseMirrorNode,\n liveParent: LiveblocksTiptapNode\n): IncrementalOperation[] | undefined {\n const content = getLiveblocksNodeContent(liveParent);\n if (content === undefined) {\n return undefined;\n }\n\n if (oldParent.childCount === newParent.childCount) {\n const operations: IncrementalOperation[] = [];\n\n for (let index = 0; index < oldParent.childCount; index++) {\n const oldChild = oldParent.child(index);\n const newChild = newParent.child(index);\n if (oldChild.eq(newChild)) {\n continue;\n }\n\n const liveChild = content.get(index);\n if (liveChild === undefined) {\n return undefined;\n }\n\n const childOperations =\n classifyAttrsChange(oldChild, newChild, liveChild) ??\n classifyNodeChange(oldChild, newChild, liveChild);\n\n if (childOperations !== undefined) {\n operations.push(...childOperations);\n continue;\n }\n\n const operation = createNodeOperation(\n \"setNode\",\n content,\n index,\n newChild\n );\n if (operation === undefined) {\n return undefined;\n }\n\n operations.push(operation);\n }\n\n return operations.length > 0 ? operations : undefined;\n }\n\n const prefix = findCommonPrefix(oldParent, newParent);\n const suffix = findCommonSuffix(oldParent, newParent, prefix);\n\n if (\n oldParent.childCount + 1 === newParent.childCount &&\n prefix + suffix === oldParent.childCount\n ) {\n const operation = createNodeOperation(\n \"insertNode\",\n content,\n prefix,\n newParent.child(prefix)\n );\n return operation === undefined ? undefined : [operation];\n }\n\n if (\n oldParent.childCount + 1 === newParent.childCount &&\n prefix + suffix + 1 === oldParent.childCount\n ) {\n const setOperation = createNodeOperation(\n \"setNode\",\n content,\n prefix,\n newParent.child(prefix)\n );\n const insertOperation = createNodeOperation(\n \"insertNode\",\n content,\n prefix + 1,\n newParent.child(prefix + 1)\n );\n\n return setOperation === undefined || insertOperation === undefined\n ? undefined\n : [setOperation, insertOperation];\n }\n\n if (\n oldParent.childCount - 1 === newParent.childCount &&\n prefix + suffix === newParent.childCount\n ) {\n return [{ type: \"deleteNode\", content, index: prefix }];\n }\n\n if (\n oldParent.childCount - 1 === newParent.childCount &&\n prefix + suffix + 1 === newParent.childCount\n ) {\n const operation = createNodeOperation(\n \"setNode\",\n content,\n prefix,\n newParent.child(prefix)\n );\n\n return operation === undefined\n ? undefined\n : [operation, { type: \"deleteNode\", content, index: prefix + 1 }];\n }\n\n return undefined;\n}\n\nfunction classifyNodeChange(\n oldNode: ProseMirrorNode,\n newNode: ProseMirrorNode,\n liveNode: LiveblocksTiptapNode\n): IncrementalOperation[] | undefined {\n const attrOperations = classifyAttrsChange(oldNode, newNode, liveNode) ?? [];\n const childOperations =\n oldNode.type === newNode.type\n ? classifyChildrenChange(oldNode, newNode, liveNode)\n : undefined;\n const operations = [...attrOperations, ...(childOperations ?? [])];\n\n return operations.length > 0 ? operations : undefined;\n}\n\nfunction classifyStructuralChange(\n oldDoc: ProseMirrorNode,\n newDoc: ProseMirrorNode,\n liveRoot: LiveblocksTiptapNode\n): IncrementalOperation[] | undefined {\n return classifyNodeChange(oldDoc, newDoc, liveRoot);\n}\n\nexport function classifyTransaction(\n transactions: readonly Transaction[],\n oldDoc: ProseMirrorNode,\n newDoc: ProseMirrorNode,\n liveRoot: LiveblocksTiptapNode\n): ClassifiedTransaction {\n const changedTransactions = transactions.filter(\n (transaction) => transaction.docChanged\n );\n\n if (changedTransactions.length !== 1) {\n return { type: \"unsupported\" };\n }\n\n const [transaction] = changedTransactions;\n if (transaction === undefined || transaction.steps.length !== 1) {\n return { type: \"unsupported\" };\n }\n\n const [step] = transaction.steps;\n const stepJson: unknown = step?.toJSON();\n\n const operations = isReplaceStepJson(stepJson)\n ? classifyReplaceStep(stepJson, oldDoc, liveRoot)\n : isMarkStepJson(stepJson)\n ? classifyMarkStep(\n stepJson,\n buildLiveblocksTreeIndex(oldDoc, liveRoot),\n newDoc\n )\n : undefined;\n\n const structuralOperations =\n operations ?? classifyStructuralChange(oldDoc, newDoc, liveRoot);\n\n if (structuralOperations === undefined) {\n return { type: \"unsupported\" };\n }\n\n return { type: \"incremental\", operations: structuralOperations };\n}\n\nexport function applyIncrementalOperations(\n operations: readonly IncrementalOperation[]\n): void {\n for (const operation of operations) {\n if (operation.type === \"insert\") {\n const text = operation.node.get(\"text\");\n if (!(text instanceof LiveText)) {\n continue;\n }\n\n text.insert(operation.index, operation.text, operation.attributes);\n } else if (operation.type === \"delete\") {\n const text = operation.node.get(\"text\");\n if (!(text instanceof LiveText)) {\n continue;\n }\n\n text.delete(operation.index, operation.length);\n } else if (operation.type === \"format\") {\n const text = operation.node.get(\"text\");\n if (!(text instanceof LiveText)) {\n continue;\n }\n\n text.format(operation.index, operation.length, operation.attributes);\n } else if (operation.type === \"insertNode\") {\n operation.content.insert(operation.node, operation.index);\n } else if (operation.type === \"deleteNode\") {\n operation.content.delete(operation.index);\n } else if (operation.type === \"setNode\") {\n operation.content.set(operation.index, operation.node);\n } else {\n updateLiveblocksNodeAttrs(operation.node, operation.attrs);\n }\n }\n}\n"],"names":["findTextRangeAtPositionInDocument","marksToAttributes","findTextRangeAtPosition","marksToAttributesPatch","createLiveblocksTiptapNode","getLiveblocksNodeContent","transaction","buildLiveblocksTreeIndex","LiveText","updateLiveblocksNodeAttrs"],"mappings":";;;;;;AAyFA,SAAS,SAAS,KAAkD,EAAA;AAClE,EAAO,OAAA,OAAO,KAAU,KAAA,QAAA,IAAY,KAAU,KAAA,IAAA,CAAA;AAChD,CAAA;AAEA,SAAS,aAAa,KAAqC,EAAA;AACzD,EAAO,OAAA,OAAO,UAAU,QAAY,IAAA,KAAA,KAAU,QAAQ,CAAC,KAAA,CAAM,QAAQ,KAAK,CAAA,CAAA;AAC5E,CAAA;AAEA,SAAS,WAAW,KAAmD,EAAA;AACrE,EAAA,IAAI,CAAC,KAAA,CAAM,OAAQ,CAAA,KAAK,CAAG,EAAA;AACzB,IAAO,OAAA,KAAA,CAAA,CAAA;AAAA,GACT;AAEA,EAAA,MAAM,QAA+B,EAAC,CAAA;AAEtC,EAAA,KAAA,MAAW,QAAQ,KAAO,EAAA;AACxB,IAAA,IAAI,CAAC,QAAS,CAAA,IAAI,KAAK,OAAO,IAAA,CAAK,SAAS,QAAU,EAAA;AACpD,MAAO,OAAA,KAAA,CAAA,CAAA;AAAA,KACT;AAEA,IAAA,KAAA,CAAM,IAAK,CAAA;AAAA,MACT,MAAM,IAAK,CAAA,IAAA;AAAA,MACX,GAAI,YAAa,CAAA,IAAA,CAAK,KAAK,CAAA,GAAI,EAAE,KAAO,EAAA,IAAA,CAAK,KAAM,EAAA,GAAI,EAAC;AAAA,KACzD,CAAA,CAAA;AAAA,GACH;AAEA,EAAO,OAAA,KAAA,CAAM,MAAS,GAAA,CAAA,GAAI,KAAQ,GAAA,KAAA,CAAA,CAAA;AACpC,CAAA;AAEA,SAAS,yBACP,KACiC,EAAA;AACjC,EAAA,IAAI,CAAC,QAAS,CAAA,KAAK,KAAK,OAAO,KAAA,CAAM,SAAS,QAAU,EAAA;AACtD,IAAO,OAAA,KAAA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