@arbidocs/blocks 0.4.155 → 0.4.157
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/{ConnectedNativeDocxComparison-OLWRQSRS.js → ConnectedNativeDocxComparison-2PLOOXSH.js} +6 -6
- package/dist/{ConnectedNativeDocxComparison-OLWRQSRS.js.map → ConnectedNativeDocxComparison-2PLOOXSH.js.map} +1 -1
- package/dist/{ConnectedNativeDocxComparison-YORMOPPN.cjs → ConnectedNativeDocxComparison-S25BPUH5.cjs} +7 -7
- package/dist/{ConnectedNativeDocxComparison-YORMOPPN.cjs.map → ConnectedNativeDocxComparison-S25BPUH5.cjs.map} +1 -1
- package/dist/{ConnectedNativeDocxEditor-34EBIIFS.js → ConnectedNativeDocxEditor-JJAGMHZC.js} +4 -4
- package/dist/{ConnectedNativeDocxEditor-34EBIIFS.js.map → ConnectedNativeDocxEditor-JJAGMHZC.js.map} +1 -1
- package/dist/{ConnectedNativeDocxEditor-EHTWGGX3.cjs → ConnectedNativeDocxEditor-YA4HWLY4.cjs} +6 -6
- package/dist/{ConnectedNativeDocxEditor-EHTWGGX3.cjs.map → ConnectedNativeDocxEditor-YA4HWLY4.cjs.map} +1 -1
- package/dist/{ConnectedStreamedWordArtifact-5DK6QGYN.cjs → ConnectedStreamedWordArtifact-EXYZAU4Y.cjs} +7 -7
- package/dist/ConnectedStreamedWordArtifact-EXYZAU4Y.cjs.map +1 -0
- package/dist/{ConnectedStreamedWordArtifact-GLIDLSAS.js → ConnectedStreamedWordArtifact-YAAXY5KY.js} +6 -6
- package/dist/{ConnectedStreamedWordArtifact-GLIDLSAS.js.map → ConnectedStreamedWordArtifact-YAAXY5KY.js.map} +1 -1
- package/dist/{NativeDocxEditor-XT5ZLFGU.js → NativeDocxEditor-JBQMH3MP.js} +3 -3
- package/dist/{NativeDocxEditor-XT5ZLFGU.js.map → NativeDocxEditor-JBQMH3MP.js.map} +1 -1
- package/dist/{NativeDocxEditor-5VBNM5I7.cjs → NativeDocxEditor-M3I776GD.cjs} +7 -7
- package/dist/{NativeDocxEditor-5VBNM5I7.cjs.map → NativeDocxEditor-M3I776GD.cjs.map} +1 -1
- package/dist/{chunk-MF5KQ4PS.js → chunk-2CWM2CFZ.js} +4 -4
- package/dist/{chunk-MF5KQ4PS.js.map → chunk-2CWM2CFZ.js.map} +1 -1
- package/dist/{chunk-6HMCF4AJ.js → chunk-5ZIYPZYE.js} +1033 -5
- package/dist/chunk-5ZIYPZYE.js.map +1 -0
- package/dist/{chunk-KHXEIEXN.js → chunk-7IRSCMNK.js} +3 -3
- package/dist/{chunk-KHXEIEXN.js.map → chunk-7IRSCMNK.js.map} +1 -1
- package/dist/{chunk-TZOQKV64.js → chunk-EWCJXUBP.js} +3 -3
- package/dist/{chunk-TZOQKV64.js.map → chunk-EWCJXUBP.js.map} +1 -1
- package/dist/{chunk-CU6LDQ57.js → chunk-F3EZDBDJ.js} +4 -4
- package/dist/{chunk-CU6LDQ57.js.map → chunk-F3EZDBDJ.js.map} +1 -1
- package/dist/{chunk-W7CWGURO.js → chunk-FTZ45WHY.js} +6 -685
- package/dist/chunk-FTZ45WHY.js.map +1 -0
- package/dist/{chunk-CQCNU5KT.cjs → chunk-IJEISII2.cjs} +6 -6
- package/dist/{chunk-CQCNU5KT.cjs.map → chunk-IJEISII2.cjs.map} +1 -1
- package/dist/{chunk-NPR5BGFF.cjs → chunk-JSQEAPTC.cjs} +26 -14
- package/dist/chunk-JSQEAPTC.cjs.map +1 -0
- package/dist/{chunk-MUDEL7UL.cjs → chunk-NPLGB4LI.cjs} +4 -703
- package/dist/chunk-NPLGB4LI.cjs.map +1 -0
- package/dist/{chunk-265GOG4W.js → chunk-ONTUMV74.js} +26 -14
- package/dist/chunk-ONTUMV74.js.map +1 -0
- package/dist/chunk-OTU5KGQ6.cjs +18 -0
- package/dist/{chunk-HUATKA3M.cjs.map → chunk-OTU5KGQ6.cjs.map} +1 -1
- package/dist/{chunk-GO3BN76C.js → chunk-PGOSIJ2I.js} +3 -3
- package/dist/{chunk-GO3BN76C.js.map → chunk-PGOSIJ2I.js.map} +1 -1
- package/dist/{chunk-WV4TD2HZ.cjs → chunk-QJFJ5JBF.cjs} +1055 -2
- package/dist/chunk-QJFJ5JBF.cjs.map +1 -0
- package/dist/chunk-S74QMZVZ.cjs +18 -0
- package/dist/{chunk-C3SMTA3C.cjs.map → chunk-S74QMZVZ.cjs.map} +1 -1
- package/dist/{chunk-KUT2Y7JF.cjs → chunk-TQIY2SVY.cjs} +5 -5
- package/dist/{chunk-KUT2Y7JF.cjs.map → chunk-TQIY2SVY.cjs.map} +1 -1
- package/dist/{chunk-757OYF6G.cjs → chunk-VY4UFXTM.cjs} +4 -4
- package/dist/{chunk-757OYF6G.cjs.map → chunk-VY4UFXTM.cjs.map} +1 -1
- package/dist/connect/docx.cjs +10 -10
- package/dist/connect/docx.js +6 -6
- package/dist/connect/index.cjs +626 -66
- package/dist/connect/index.cjs.map +1 -1
- package/dist/connect/index.js +564 -9
- package/dist/connect/index.js.map +1 -1
- package/dist/connect/viewer.cjs +43 -43
- package/dist/connect/viewer.js +5 -5
- package/dist/connection/files/index.d.ts +5 -0
- package/dist/connection/files/support.d.ts +2 -0
- package/dist/connection/files/upload/AddFromAccountsButton.d.ts +16 -0
- package/dist/connection/files/upload/ConnectedUpload.d.ts +36 -0
- package/dist/connection/files/upload/ConnectedUploadDropzone.d.ts +36 -0
- package/dist/connection/files/upload/EmptyWorkspaceUpload.d.ts +13 -0
- package/dist/connection/files/upload/useAddFromUrls.d.ts +13 -0
- package/dist/docx/index.cjs +47 -47
- package/dist/docx/index.js +3 -3
- package/dist/files/PrivacyExplainerModal.d.ts +8 -0
- package/dist/files/ShareToggle.d.ts +8 -0
- package/dist/files/UrlInputDialog.d.ts +24 -0
- package/dist/files/index.cjs +298 -278
- package/dist/files/index.d.ts +4 -0
- package/dist/files/index.js +2 -2
- package/dist/files/media-preview.d.ts +24 -0
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.cjs +96 -29
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.cjs.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.d.cts +1 -1
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.d.ts +1 -1
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.js +98 -31
- package/node_modules/@arbidocs/coedit/dist/hocuspocus.js.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/index.cjs +96 -29
- package/node_modules/@arbidocs/coedit/dist/index.cjs.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/index.d.cts +1 -1
- package/node_modules/@arbidocs/coedit/dist/index.d.ts +1 -1
- package/node_modules/@arbidocs/coedit/dist/index.js +98 -31
- package/node_modules/@arbidocs/coedit/dist/index.js.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/server.cjs +98 -33
- package/node_modules/@arbidocs/coedit/dist/server.cjs.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/server.d.cts +1 -1
- package/node_modules/@arbidocs/coedit/dist/server.d.ts +1 -1
- package/node_modules/@arbidocs/coedit/dist/server.js +99 -34
- package/node_modules/@arbidocs/coedit/dist/server.js.map +1 -1
- package/node_modules/@arbidocs/coedit/dist/{session-Cf9iu1Vt.d.cts → session-WGvWs6yO.d.cts} +22 -4
- package/node_modules/@arbidocs/coedit/dist/{session-Cf9iu1Vt.d.ts → session-WGvWs6yO.d.ts} +22 -4
- package/node_modules/@arbidocs/coedit/package.json +1 -1
- package/package.json +5 -5
- package/dist/ConnectedStreamedWordArtifact-5DK6QGYN.cjs.map +0 -1
- package/dist/chunk-265GOG4W.js.map +0 -1
- package/dist/chunk-6HMCF4AJ.js.map +0 -1
- package/dist/chunk-C3SMTA3C.cjs +0 -18
- package/dist/chunk-HUATKA3M.cjs +0 -18
- package/dist/chunk-MUDEL7UL.cjs.map +0 -1
- package/dist/chunk-NPR5BGFF.cjs.map +0 -1
- package/dist/chunk-W7CWGURO.js.map +0 -1
- package/dist/chunk-WV4TD2HZ.cjs.map +0 -1
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { COLLAB_FORMAT, MaterializeError } from './encoding.cjs';
|
|
2
|
-
export { C as CollaborationSessionError, D as DocxCollaborationSession, a as DocxCollaborationSessionOptions } from './session-
|
|
2
|
+
export { C as CollaborationSessionError, D as DocxCollaborationSession, a as DocxCollaborationSessionOptions } from './session-WGvWs6yO.cjs';
|
|
3
3
|
export { C as COLLAB_PROTOCOL, D as DOCUMENT_COLLABORATION_VERSIONS } from './versions-DXiFQMA6.cjs';
|
|
4
4
|
import { EditorModule } from '@docx-editor.dev/core';
|
|
5
5
|
import { EditorCollaborationSession } from '@docx-editor.dev/core/collaboration';
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export { COLLAB_FORMAT, MaterializeError } from './encoding.js';
|
|
2
|
-
export { C as CollaborationSessionError, D as DocxCollaborationSession, a as DocxCollaborationSessionOptions } from './session-
|
|
2
|
+
export { C as CollaborationSessionError, D as DocxCollaborationSession, a as DocxCollaborationSessionOptions } from './session-WGvWs6yO.js';
|
|
3
3
|
export { C as COLLAB_PROTOCOL, D as DOCUMENT_COLLABORATION_VERSIONS } from './versions-DXiFQMA6.js';
|
|
4
4
|
import { EditorModule } from '@docx-editor.dev/core';
|
|
5
5
|
import { EditorCollaborationSession } from '@docx-editor.dev/core/collaboration';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import * as Y3 from 'yjs';
|
|
2
|
-
import { readOoxmlPart, validateExternalTarget, relsPartNameFor, contentTypesPartBytes, withContentTypeOverride } from '@docx-editor.dev/core/store';
|
|
2
|
+
import { ORIGIN_IDS, readOoxmlPart, validateExternalTarget, relsPartNameFor, contentTypesPartBytes, withContentTypeOverride } from '@docx-editor.dev/core/store';
|
|
3
3
|
import { createCollaborationStatusTracker, safeParticipantColor } from '@docx-editor.dev/core/collaboration';
|
|
4
|
-
import { historyGroupOfJournal } from '@docx-editor.dev/core/collaboration/replication';
|
|
4
|
+
import { historyGroupOfJournal, mapOffsetAcrossText } from '@docx-editor.dev/core/collaboration/replication';
|
|
5
5
|
|
|
6
6
|
// src/encoding.ts
|
|
7
7
|
|
|
@@ -1254,7 +1254,6 @@ function applyJournal(doc, registry, journal, origin, context) {
|
|
|
1254
1254
|
|
|
1255
1255
|
// src/sync.ts
|
|
1256
1256
|
var LOCAL_ORIGIN = /* @__PURE__ */ Symbol("arbi-coedit/local");
|
|
1257
|
-
var DEFAULT_REMOTE_DELAY_MS = 40;
|
|
1258
1257
|
var MirrorSync = class {
|
|
1259
1258
|
doc;
|
|
1260
1259
|
registry = new NodeRegistry();
|
|
@@ -1263,14 +1262,11 @@ var MirrorSync = class {
|
|
|
1263
1262
|
actorId;
|
|
1264
1263
|
onFailure;
|
|
1265
1264
|
onLocalJournal;
|
|
1265
|
+
aroundRemote;
|
|
1266
1266
|
disposers = [];
|
|
1267
|
-
remoteDelayMs;
|
|
1268
1267
|
operation = 0;
|
|
1269
1268
|
applyingRemote = false;
|
|
1270
1269
|
failed = false;
|
|
1271
|
-
remoteDirty = false;
|
|
1272
|
-
remoteOrigin;
|
|
1273
|
-
remoteTimer;
|
|
1274
1270
|
/** Parts whose node ids must be re-registered before the next local journal; true means all. */
|
|
1275
1271
|
staleParts = null;
|
|
1276
1272
|
constructor(options) {
|
|
@@ -1279,7 +1275,7 @@ var MirrorSync = class {
|
|
|
1279
1275
|
this.actorId = options.actorId;
|
|
1280
1276
|
this.onFailure = options.onFailure;
|
|
1281
1277
|
this.onLocalJournal = options.onLocalJournal;
|
|
1282
|
-
this.
|
|
1278
|
+
this.aroundRemote = options.aroundRemote;
|
|
1283
1279
|
registerMirror(this.doc, this.registry);
|
|
1284
1280
|
this.cache = new MaterializeCache(this.doc);
|
|
1285
1281
|
this.disposers.push(() => this.cache.destroy());
|
|
@@ -1300,16 +1296,10 @@ var MirrorSync = class {
|
|
|
1300
1296
|
const onAfterTransaction = (transaction) => {
|
|
1301
1297
|
if (transaction.origin === LOCAL_ORIGIN || this.failed) return;
|
|
1302
1298
|
if (transaction.changed.size === 0 && transaction.changedParentTypes.size === 0) return;
|
|
1303
|
-
this.
|
|
1304
|
-
this.remoteOrigin = transaction.origin;
|
|
1305
|
-
if (this.remoteDelayMs <= 0) this.flushRemote();
|
|
1306
|
-
else if (this.remoteTimer === void 0) {
|
|
1307
|
-
this.remoteTimer = setTimeout(() => this.flushRemote(), this.remoteDelayMs);
|
|
1308
|
-
}
|
|
1299
|
+
this.publishRemote(transaction.origin);
|
|
1309
1300
|
};
|
|
1310
1301
|
this.doc.on("afterTransaction", onAfterTransaction);
|
|
1311
1302
|
this.disposers.push(() => this.doc.off("afterTransaction", onAfterTransaction));
|
|
1312
|
-
this.disposers.push(() => clearTimeout(this.remoteTimer));
|
|
1313
1303
|
}
|
|
1314
1304
|
get hasFailed() {
|
|
1315
1305
|
return this.failed;
|
|
@@ -1318,17 +1308,8 @@ var MirrorSync = class {
|
|
|
1318
1308
|
beforeRemote() {
|
|
1319
1309
|
this.port.flushPendingJournals();
|
|
1320
1310
|
}
|
|
1321
|
-
/** Publish any waiting remote change now. Call before a local operation runs. */
|
|
1322
|
-
flushRemote() {
|
|
1323
|
-
clearTimeout(this.remoteTimer);
|
|
1324
|
-
this.remoteTimer = void 0;
|
|
1325
|
-
if (!this.remoteDirty || this.failed) return;
|
|
1326
|
-
this.remoteDirty = false;
|
|
1327
|
-
this.publishRemote(this.remoteOrigin);
|
|
1328
|
-
}
|
|
1329
1311
|
/** Make the local tree equal to the room: used when the editor opened an older snapshot of it. */
|
|
1330
1312
|
adopt() {
|
|
1331
|
-
this.remoteDirty = false;
|
|
1332
1313
|
this.publishRemote(void 0);
|
|
1333
1314
|
}
|
|
1334
1315
|
/** Re-register node ids for parts a remote publication replaced; deferred until a local edit needs them. */
|
|
@@ -1338,23 +1319,29 @@ var MirrorSync = class {
|
|
|
1338
1319
|
this.staleParts = null;
|
|
1339
1320
|
}
|
|
1340
1321
|
publishRemote(origin) {
|
|
1322
|
+
if (this.failed) return;
|
|
1323
|
+
const published = this.aroundRemote?.();
|
|
1341
1324
|
this.applyingRemote = true;
|
|
1342
1325
|
const changed = this.cache.take();
|
|
1326
|
+
let ok = false;
|
|
1343
1327
|
try {
|
|
1344
1328
|
const result = this.port.applyRemotePackage(materialize(this.doc, this.cache, changed), {
|
|
1345
|
-
origin:
|
|
1329
|
+
// The editor's own origin for a peer's change: it carries the local caret only across those.
|
|
1330
|
+
origin: ORIGIN_IDS.mutationRemote,
|
|
1346
1331
|
actorId: typeof origin === "string" ? origin : this.actorId,
|
|
1347
1332
|
operationId: `${this.actorId}:remote:${this.operation++}`
|
|
1348
1333
|
});
|
|
1349
1334
|
if (!result.ok) throw new JournalError(result.reason);
|
|
1350
1335
|
if (changed === null || this.staleParts === true) this.staleParts = true;
|
|
1351
1336
|
else this.staleParts = /* @__PURE__ */ new Set([...this.staleParts ?? [], ...changed]);
|
|
1337
|
+
ok = true;
|
|
1352
1338
|
} catch (error) {
|
|
1353
1339
|
this.cache.restore(changed);
|
|
1354
1340
|
this.fail(error instanceof MaterializeError ? "materialize" : "apply", error);
|
|
1355
1341
|
} finally {
|
|
1356
1342
|
this.applyingRemote = false;
|
|
1357
1343
|
}
|
|
1344
|
+
if (ok) published?.();
|
|
1358
1345
|
}
|
|
1359
1346
|
fail(code, error) {
|
|
1360
1347
|
if (this.failed) return;
|
|
@@ -1408,7 +1395,6 @@ var DocxCollaborationSession = class {
|
|
|
1408
1395
|
doc;
|
|
1409
1396
|
awareness;
|
|
1410
1397
|
offlineEditing;
|
|
1411
|
-
remoteDelayMs;
|
|
1412
1398
|
tracker = createCollaborationStatusTracker("initializing");
|
|
1413
1399
|
statusListeners = /* @__PURE__ */ new Set();
|
|
1414
1400
|
participantListeners = /* @__PURE__ */ new Set();
|
|
@@ -1421,6 +1407,10 @@ var DocxCollaborationSession = class {
|
|
|
1421
1407
|
selectionsCache = [];
|
|
1422
1408
|
selectionsKey = "[]";
|
|
1423
1409
|
baselineVector;
|
|
1410
|
+
/** The selection the editor last published, carried across the remote changes since. */
|
|
1411
|
+
carried = null;
|
|
1412
|
+
selectionMove = null;
|
|
1413
|
+
inputFlush = null;
|
|
1424
1414
|
disposers = [];
|
|
1425
1415
|
constructor(options) {
|
|
1426
1416
|
this.documentId = options.documentId;
|
|
@@ -1429,7 +1419,6 @@ var DocxCollaborationSession = class {
|
|
|
1429
1419
|
this.doc = options.doc;
|
|
1430
1420
|
this.awareness = options.awareness;
|
|
1431
1421
|
this.offlineEditing = options.offlineEditing ?? false;
|
|
1432
|
-
this.remoteDelayMs = options.remoteDelayMs;
|
|
1433
1422
|
this.undoManager = new Y3.UndoManager(
|
|
1434
1423
|
[
|
|
1435
1424
|
this.doc.getMap("parts"),
|
|
@@ -1491,7 +1480,6 @@ var DocxCollaborationSession = class {
|
|
|
1491
1480
|
return this.port !== void 0;
|
|
1492
1481
|
}
|
|
1493
1482
|
gateOperations() {
|
|
1494
|
-
this.sync?.flushRemote();
|
|
1495
1483
|
switch (this.status()) {
|
|
1496
1484
|
case "ready":
|
|
1497
1485
|
return this.port ? null : "collaboration-session-not-attached";
|
|
@@ -1520,7 +1508,7 @@ var DocxCollaborationSession = class {
|
|
|
1520
1508
|
doc: this.doc,
|
|
1521
1509
|
port,
|
|
1522
1510
|
actorId: this.identity.actorId,
|
|
1523
|
-
|
|
1511
|
+
aroundRemote: () => this.carrySelection(),
|
|
1524
1512
|
onFailure: (code, detail) => {
|
|
1525
1513
|
this.markFailed(code === "journal" ? "local-mirror-failed" : "remote-apply-failed", detail);
|
|
1526
1514
|
},
|
|
@@ -1544,8 +1532,21 @@ var DocxCollaborationSession = class {
|
|
|
1544
1532
|
}
|
|
1545
1533
|
/** Transport hook: call before integrating inbound Yjs data so queued local edits are mirrored first. */
|
|
1546
1534
|
beforeRemote() {
|
|
1535
|
+
this.inputFlush?.();
|
|
1547
1536
|
this.sync?.beforeRemote();
|
|
1548
1537
|
}
|
|
1538
|
+
/**
|
|
1539
|
+
* Bind the editor's pending-input flush (`PaginatedSurface.flushPendingInput`). The session writes
|
|
1540
|
+
* below the editor's input buffer, so it lands queued typing before a remote change and lays the
|
|
1541
|
+
* change out right after it: the editor carries its caret at that layout, and a keystroke before
|
|
1542
|
+
* it would otherwise use the caret from before the change. Returns the unbind function.
|
|
1543
|
+
*/
|
|
1544
|
+
bindEditorInput(flush) {
|
|
1545
|
+
this.inputFlush = flush;
|
|
1546
|
+
return () => {
|
|
1547
|
+
if (this.inputFlush === flush) this.inputFlush = null;
|
|
1548
|
+
};
|
|
1549
|
+
}
|
|
1549
1550
|
// ── Undo ─────────────────────────────────────────────────────────────────
|
|
1550
1551
|
canUndo() {
|
|
1551
1552
|
return this.undoManager.undoStack.length > 0;
|
|
@@ -1558,7 +1559,6 @@ var DocxCollaborationSession = class {
|
|
|
1558
1559
|
if (this.gateOperations() !== null || !this.canUndo()) return false;
|
|
1559
1560
|
this.undoManager.stopCapturing();
|
|
1560
1561
|
this.undoManager.undo();
|
|
1561
|
-
this.sync?.flushRemote();
|
|
1562
1562
|
return true;
|
|
1563
1563
|
}
|
|
1564
1564
|
redo() {
|
|
@@ -1566,13 +1566,79 @@ var DocxCollaborationSession = class {
|
|
|
1566
1566
|
if (this.gateOperations() !== null || !this.canRedo()) return false;
|
|
1567
1567
|
this.undoManager.stopCapturing();
|
|
1568
1568
|
this.undoManager.redo();
|
|
1569
|
-
this.sync?.flushRemote();
|
|
1570
1569
|
return true;
|
|
1571
1570
|
}
|
|
1572
1571
|
// ── Presence ─────────────────────────────────────────────────────────────
|
|
1573
1572
|
setLocalSelection(selection) {
|
|
1573
|
+
this.carried = selection && selection.kind !== "cells" ? { from: null, selection } : null;
|
|
1574
|
+
this.selectionMove = null;
|
|
1574
1575
|
this.awareness.setLocalStateField("selection", selection);
|
|
1575
1576
|
}
|
|
1577
|
+
/** Where the last remote change carried the local selection; see `carrySelection`. */
|
|
1578
|
+
remoteSelectionMove() {
|
|
1579
|
+
return this.selectionMove;
|
|
1580
|
+
}
|
|
1581
|
+
/**
|
|
1582
|
+
* Called before a remote change reaches the port: notes the selection's paragraphs and their text,
|
|
1583
|
+
* and returns what carries it across the change once the port holds the new tree. The editor
|
|
1584
|
+
* takes the carried selection when a local edit was coalesced with the remote change, where it
|
|
1585
|
+
* cannot map its caret by the text alone. Several remote changes before the editor publishes its
|
|
1586
|
+
* selection again chain, all from the selection it published.
|
|
1587
|
+
*/
|
|
1588
|
+
carrySelection() {
|
|
1589
|
+
const port = this.port;
|
|
1590
|
+
const carried = this.carried;
|
|
1591
|
+
const settle = () => this.inputFlush?.();
|
|
1592
|
+
if (!port || !carried) return settle;
|
|
1593
|
+
const before = (address) => {
|
|
1594
|
+
const paragraph = port.paragraphByStableId(address.paragraphId);
|
|
1595
|
+
if (!paragraph) return null;
|
|
1596
|
+
const offset = Math.min(address.offset, paragraph.text.length);
|
|
1597
|
+
return { nodeId: paragraph.nodeId, text: paragraph.text, offset };
|
|
1598
|
+
};
|
|
1599
|
+
const anchor = before(carried.selection.anchor);
|
|
1600
|
+
const head = before(carried.selection.head);
|
|
1601
|
+
if (!anchor || !head) {
|
|
1602
|
+
this.carried = null;
|
|
1603
|
+
this.selectionMove = null;
|
|
1604
|
+
return settle;
|
|
1605
|
+
}
|
|
1606
|
+
const from = carried.from ?? {
|
|
1607
|
+
anchor: { nodeId: anchor.nodeId, offset: anchor.offset },
|
|
1608
|
+
head: { nodeId: head.nodeId, offset: head.offset }
|
|
1609
|
+
};
|
|
1610
|
+
return () => {
|
|
1611
|
+
const after = (address, was) => {
|
|
1612
|
+
const paragraph = port.paragraphByStableId(address.paragraphId);
|
|
1613
|
+
if (!paragraph) return null;
|
|
1614
|
+
const offset = mapOffsetAcrossText(was.offset, was.text, paragraph.text);
|
|
1615
|
+
return { paragraphId: address.paragraphId, nodeId: paragraph.nodeId, offset };
|
|
1616
|
+
};
|
|
1617
|
+
const nextAnchor = after(carried.selection.anchor, anchor);
|
|
1618
|
+
const nextHead = after(carried.selection.head, head);
|
|
1619
|
+
if (!nextAnchor || !nextHead) {
|
|
1620
|
+
this.carried = null;
|
|
1621
|
+
this.selectionMove = null;
|
|
1622
|
+
} else {
|
|
1623
|
+
this.carried = {
|
|
1624
|
+
from,
|
|
1625
|
+
selection: {
|
|
1626
|
+
...carried.selection,
|
|
1627
|
+
anchor: { paragraphId: nextAnchor.paragraphId, offset: nextAnchor.offset },
|
|
1628
|
+
head: { paragraphId: nextHead.paragraphId, offset: nextHead.offset }
|
|
1629
|
+
}
|
|
1630
|
+
};
|
|
1631
|
+
this.selectionMove = {
|
|
1632
|
+
from,
|
|
1633
|
+
to: {
|
|
1634
|
+
anchor: { nodeId: nextAnchor.nodeId, offset: nextAnchor.offset },
|
|
1635
|
+
head: { nodeId: nextHead.nodeId, offset: nextHead.offset }
|
|
1636
|
+
}
|
|
1637
|
+
};
|
|
1638
|
+
}
|
|
1639
|
+
settle();
|
|
1640
|
+
};
|
|
1641
|
+
}
|
|
1576
1642
|
participants() {
|
|
1577
1643
|
return this.participantsCache;
|
|
1578
1644
|
}
|
|
@@ -1644,6 +1710,7 @@ var DocxCollaborationSession = class {
|
|
|
1644
1710
|
this.sync?.destroy();
|
|
1645
1711
|
this.sync = void 0;
|
|
1646
1712
|
this.port = void 0;
|
|
1713
|
+
this.inputFlush = null;
|
|
1647
1714
|
this.undoManager.destroy();
|
|
1648
1715
|
this.awareness.setLocalState(null);
|
|
1649
1716
|
for (const dispose of this.disposers.splice(0)) dispose();
|