@ai-matrx/office 0.8.11 → 0.8.13

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/docs.cjs CHANGED
@@ -191,13 +191,13 @@ var DocumentModel = (_class = class {
191
191
  return editor;
192
192
  }
193
193
  onViewMutation(viewId, info, options) {
194
- if (this.relaying || _optionalChain([options, 'optionalAccess', _15 => _15.fromCollab]) || _optionalChain([options, 'optionalAccess', _16 => _16.fromChangeset])) return;
194
+ if (this.relaying || _optionalChain([options, 'optionalAccess', _19 => _19.fromCollab]) || _optionalChain([options, 'optionalAccess', _20 => _20.fromChangeset])) return;
195
195
  const view = this.views.get(viewId);
196
196
  if (!view || !view.port.editable()) return;
197
197
  this.lastEditedView = viewId;
198
198
  this.relay(info, viewId);
199
199
  for (const listener of this.collabListeners) listener(info, options);
200
- if (this.otListeners.size && !_optionalChain([options, 'optionalAccess', _17 => _17.onlyLocal])) {
200
+ if (this.otListeners.size && !_optionalChain([options, 'optionalAccess', _21 => _21.onlyLocal])) {
201
201
  const m = {
202
202
  id: info.id,
203
203
  params: info.params,
@@ -226,7 +226,7 @@ var DocumentModel = (_class = class {
226
226
  try {
227
227
  const snap = view.port.snapshot();
228
228
  view.pre = snap ? structuredClone(snap) : null;
229
- } catch (e4) {
229
+ } catch (e5) {
230
230
  view.pre = null;
231
231
  }
232
232
  }
@@ -257,8 +257,8 @@ var DocumentModel = (_class = class {
257
257
  /** The unit id a view's document has (what a replayed mutation must be addressed to). */
258
258
  unitIdOf(view) {
259
259
  try {
260
- return _nullishCoalesce(_nullishCoalesce(_optionalChain([view, 'access', _18 => _18.port, 'access', _19 => _19.unitId, 'optionalCall', _20 => _20()]), () => ( _optionalChain([view, 'access', _21 => _21.port, 'access', _22 => _22.snapshot, 'call', _23 => _23(), 'optionalAccess', _24 => _24.id]))), () => ( null));
261
- } catch (e5) {
260
+ return _nullishCoalesce(_nullishCoalesce(_optionalChain([view, 'access', _22 => _22.port, 'access', _23 => _23.unitId, 'optionalCall', _24 => _24()]), () => ( _optionalChain([view, 'access', _25 => _25.port, 'access', _26 => _26.snapshot, 'call', _27 => _27(), 'optionalAccess', _28 => _28.id]))), () => ( null));
261
+ } catch (e6) {
262
262
  return null;
263
263
  }
264
264
  }
@@ -291,7 +291,7 @@ var DocumentModel = (_class = class {
291
291
  /** A view could not follow an edit: say so, then show the saved version (unless this tab has unsaved edits of its own). */
292
292
  applyFailed(mutationId, error) {
293
293
  try {
294
- _optionalChain([this, 'access', _25 => _25.deps, 'access', _26 => _26.onApplyFailed, 'optionalCall', _27 => _27(this.documentId, mutationId, error)]);
294
+ _optionalChain([this, 'access', _29 => _29.deps, 'access', _30 => _30.onApplyFailed, 'optionalCall', _31 => _31(this.documentId, mutationId, error)]);
295
295
  } catch (notifyError) {
296
296
  console.warn(`[document-model] the notice for ${this.documentId}'s failed apply also failed`, notifyError);
297
297
  }
@@ -319,7 +319,7 @@ var DocumentModel = (_class = class {
319
319
  async write(reason) {
320
320
  if (this.ot) {
321
321
  const wrote = await this.ot.write(reason);
322
- if (wrote) _optionalChain([this, 'access', _28 => _28.deps, 'access', _29 => _29.onSaved, 'optionalCall', _30 => _30(this.documentId, reason === "manual" ? "manual" : "autosave")]);
322
+ if (wrote) _optionalChain([this, 'access', _32 => _32.deps, 'access', _33 => _33.onSaved, 'optionalCall', _34 => _34(this.documentId, reason === "manual" ? "manual" : "autosave")]);
323
323
  return wrote;
324
324
  }
325
325
  const snapshot = this.latest();
@@ -344,7 +344,7 @@ var DocumentModel = (_class = class {
344
344
  this.saving = false;
345
345
  }
346
346
  if (this.views.size === 0) this.stored = snapshot;
347
- _optionalChain([this, 'access', _31 => _31.deps, 'access', _32 => _32.onSaved, 'optionalCall', _33 => _33(this.documentId, origin)]);
347
+ _optionalChain([this, 'access', _35 => _35.deps, 'access', _36 => _36.onSaved, 'optionalCall', _37 => _37(this.documentId, origin)]);
348
348
  return true;
349
349
  }
350
350
  hasUnsaved() {
@@ -387,7 +387,7 @@ var DocumentModel = (_class = class {
387
387
  replaceContent(row) {
388
388
  if (this.ot) return this.ot.replace(row.snapshot);
389
389
  this.show(row);
390
- _optionalChain([this, 'access', _34 => _34.collab, 'optionalAccess', _35 => _35.announceReplaced, 'call', _36 => _36(row.id)]);
390
+ _optionalChain([this, 'access', _38 => _38.collab, 'optionalAccess', _39 => _39.announceReplaced, 'call', _40 => _40(row.id)]);
391
391
  }
392
392
  /** A peer replaced the document: show the newest save (once). */
393
393
  async onPeerReplaced() {
@@ -410,7 +410,7 @@ var DocumentModel = (_class = class {
410
410
  this.relaying = true;
411
411
  try {
412
412
  for (const view of this.views.values()) view.port.remount(snapshot);
413
- _optionalChain([this, 'access', _37 => _37.parked, 'optionalAccess', _38 => _38.remount, 'call', _39 => _39(snapshot)]);
413
+ _optionalChain([this, 'access', _41 => _41.parked, 'optionalAccess', _42 => _42.remount, 'call', _43 => _43(snapshot)]);
414
414
  } finally {
415
415
  this.relaying = false;
416
416
  }
@@ -484,8 +484,8 @@ var DocumentModel = (_class = class {
484
484
  const input = Array.isArray(params.actions) ? params.actions.length : 0;
485
485
  let sel = null;
486
486
  try {
487
- sel = _nullishCoalesce(_optionalChain([view, 'access', _40 => _40.port, 'access', _41 => _41.selection, 'optionalAccess', _42 => _42.get, 'call', _43 => _43()]), () => ( null));
488
- } catch (e6) {
487
+ sel = _nullishCoalesce(_optionalChain([view, 'access', _44 => _44.port, 'access', _45 => _45.selection, 'optionalAccess', _46 => _46.get, 'call', _47 => _47()]), () => ( null));
488
+ } catch (e7) {
489
489
  sel = null;
490
490
  }
491
491
  const p = { ...params, ...unitId ? { unitId } : {}, textRanges: null, noNeedSetTextRange: true };
@@ -495,7 +495,7 @@ var DocumentModel = (_class = class {
495
495
  const moved = sel && sel.length && sel.every((r) => !r.segmentId) ? moveRangesThroughBodyEdit(sel, params.actions) : null;
496
496
  if (moved) {
497
497
  try {
498
- _optionalChain([view, 'access', _44 => _44.port, 'access', _45 => _45.selection, 'optionalAccess', _46 => _46.set, 'call', _47 => _47(moved)]);
498
+ _optionalChain([view, 'access', _48 => _48.port, 'access', _49 => _49.selection, 'optionalAccess', _50 => _50.set, 'call', _51 => _51(moved)]);
499
499
  } catch (error) {
500
500
  console.warn(`[document-model] could not move this view's caret past a collaborator's edit`, error);
501
501
  }
@@ -514,7 +514,7 @@ var DocumentModel = (_class = class {
514
514
  this.relaying = true;
515
515
  try {
516
516
  for (const view of this.views.values()) view.port.remount(s2);
517
- _optionalChain([this, 'access', _48 => _48.parked, 'optionalAccess', _49 => _49.remount, 'call', _50 => _50(s2)]);
517
+ _optionalChain([this, 'access', _52 => _52.parked, 'optionalAccess', _53 => _53.remount, 'call', _54 => _54(s2)]);
518
518
  } finally {
519
519
  this.relaying = false;
520
520
  }
@@ -523,12 +523,22 @@ var DocumentModel = (_class = class {
523
523
  const out = [];
524
524
  for (const view of this.views.values()) {
525
525
  const unitId = this.unitIdOf(view);
526
- const service = _optionalChain([view, 'access', _51 => _51.port, 'access', _52 => _52.undoRedo, 'optionalCall', _53 => _53()]);
526
+ const service = _optionalChain([view, 'access', _55 => _55.port, 'access', _56 => _56.undoRedo, 'optionalCall', _57 => _57()]);
527
527
  if (unitId && service) out.push({ service, unitId });
528
528
  }
529
529
  return out;
530
530
  },
531
- markDirty: () => this.markDirty()
531
+ markDirty: () => this.markDirty(),
532
+ selection: () => {
533
+ for (const view of this.views.values()) {
534
+ try {
535
+ const sel = _optionalChain([view, 'access', _58 => _58.port, 'access', _59 => _59.selection, 'optionalAccess', _60 => _60.get, 'call', _61 => _61()]);
536
+ if (sel) return sel;
537
+ } catch (e8) {
538
+ }
539
+ }
540
+ return null;
541
+ }
532
542
  }}
533
543
  /** Join the document's ordered-log room once (C3). Exclusive with `startCollab`. */
534
544
  startOtRoom(factory) {
@@ -581,9 +591,9 @@ var DocumentModel = (_class = class {
581
591
  * so a collaborator's save still reaches the body a returning view boots from.
582
592
  */
583
593
  rest() {
584
- _optionalChain([this, 'access', _54 => _54.collab, 'optionalAccess', _55 => _55.stop, 'call', _56 => _56()]);
594
+ _optionalChain([this, 'access', _62 => _62.collab, 'optionalAccess', _63 => _63.stop, 'call', _64 => _64()]);
585
595
  this.collab = null;
586
- _optionalChain([this, 'access', _57 => _57.ot, 'optionalAccess', _58 => _58.stop, 'call', _59 => _59()]);
596
+ _optionalChain([this, 'access', _65 => _65.ot, 'optionalAccess', _66 => _66.stop, 'call', _67 => _67()]);
587
597
  this.ot = null;
588
598
  this.awareness = null;
589
599
  }
@@ -599,9 +609,9 @@ var DocumentModel = (_class = class {
599
609
  console.warn(`[document-model] could not dispose ${this.documentId}'s kept editor`, error);
600
610
  }
601
611
  }
602
- _optionalChain([this, 'access', _60 => _60.realtimeClose, 'optionalCall', _61 => _61()]);
612
+ _optionalChain([this, 'access', _68 => _68.realtimeClose, 'optionalCall', _69 => _69()]);
603
613
  this.realtimeClose = null;
604
- _optionalChain([this, 'access', _62 => _62.pageClose, 'optionalCall', _63 => _63()]);
614
+ _optionalChain([this, 'access', _70 => _70.pageClose, 'optionalCall', _71 => _71()]);
605
615
  this.pageClose = null;
606
616
  }
607
617
  }, _class);
@@ -611,7 +621,11 @@ function moveRangesThroughBodyEdit(ranges, actions) {
611
621
  const sub = a[1];
612
622
  if (!sub || sub.et !== "text-x" || !Array.isArray(sub.e)) return null;
613
623
  const e2 = sub.e;
614
- return ranges.map((r) => ({ startOffset: _core.TextX.transformPosition(e2, r.startOffset, false), endOffset: _core.TextX.transformPosition(e2, r.endOffset, false) }));
624
+ return ranges.map((r) => {
625
+ const collapsed = r.startOffset === r.endOffset;
626
+ const startOffset = _core.TextX.transformPosition(e2, r.startOffset, collapsed);
627
+ return { startOffset, endOffset: collapsed ? startOffset : _core.TextX.transformPosition(e2, r.endOffset, true) };
628
+ });
615
629
  }
616
630
  function contentFingerprint(snapshot) {
617
631
  const { id: _id, rev: _rev, ...content } = snapshot;