@dxos/react-ui-editor 0.4.2-main.4b31084 → 0.4.2-main.9938bdc

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.
@@ -154,7 +154,6 @@ var autocomplete = ({ onSearch }) => {
154
154
  };
155
155
 
156
156
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
157
- import { invertedEffects } from "@codemirror/commands";
158
157
  import { StateField as StateField2 } from "@codemirror/state";
159
158
  import { EditorView as EditorView2, ViewPlugin } from "@codemirror/view";
160
159
  import { next as A4 } from "@dxos/automerge/automerge";
@@ -208,7 +207,7 @@ var isReconcile = (tr) => {
208
207
  return !!tr.annotation(reconcileAnnotation);
209
208
  };
210
209
 
211
- // packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
210
+ // packages/ui/react-ui-editor/src/extensions/automerge/sync.ts
212
211
  import { next as A3 } from "@dxos/automerge/automerge";
213
212
 
214
213
  // packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
@@ -349,40 +348,42 @@ var charPath = (textPath, candidatePath) => {
349
348
  return null;
350
349
  };
351
350
 
352
- // packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
353
- var PatchSemaphore = class {
351
+ // packages/ui/react-ui-editor/src/extensions/automerge/sync.ts
352
+ var Syncer = class {
354
353
  // prettier-ignore
355
354
  constructor(_handle, _state) {
356
355
  this._handle = _handle;
357
356
  this._state = _state;
358
- this._inReconcile = false;
357
+ this._pending = false;
359
358
  }
360
- reconcile(view) {
361
- if (!this._inReconcile) {
362
- this._inReconcile = true;
363
- this.doReconcile(view);
364
- this._inReconcile = false;
359
+ reconcile(view, editor) {
360
+ if (this._pending) {
361
+ return;
365
362
  }
363
+ this._pending = true;
364
+ if (editor) {
365
+ this.onEditorChange(view);
366
+ } else {
367
+ this.onAutomergeChange(view);
368
+ }
369
+ this._pending = false;
366
370
  }
367
- doReconcile(view) {
368
- const path = getPath(view.state, this._state);
369
- const oldHeads = getLastHeads(view.state, this._state);
370
- let selection = view.state.selection;
371
+ onEditorChange(view) {
371
372
  const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcile(tx));
372
- const toInvert = transactions.slice().reverse();
373
- for (const tr of toInvert) {
374
- const inverted = tr.changes.invert(tr.startState.doc);
375
- selection = selection.map(inverted);
373
+ const newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
374
+ if (newHeads) {
376
375
  view.dispatch({
377
- changes: inverted,
378
- annotations: reconcileAnnotation.of(true)
376
+ effects: updateHeads(newHeads),
377
+ annotations: reconcileAnnotation.of(false)
379
378
  });
380
379
  }
381
- let newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
382
- if (newHeads === null || newHeads === void 0) {
383
- newHeads = A3.getHeads(this._handle.docSync());
384
- }
380
+ }
381
+ onAutomergeChange(view) {
382
+ const oldHeads = getLastHeads(view.state, this._state);
383
+ const newHeads = A3.getHeads(this._handle.docSync());
385
384
  const diff = A3.equals(oldHeads, newHeads) ? [] : A3.diff(this._handle.docSync(), oldHeads, newHeads);
385
+ const selection = view.state.selection;
386
+ const path = getPath(view.state, this._state);
386
387
  updateCodeMirror(view, selection, path, diff);
387
388
  view.dispatch({
388
389
  effects: updateHeads(newHeads),
@@ -422,7 +423,7 @@ var automerge = ({ handle, path }) => {
422
423
  return result;
423
424
  }
424
425
  });
425
- const semaphore = new PatchSemaphore(handle, syncState);
426
+ const syncer = new Syncer(handle, syncState);
426
427
  return [
427
428
  Cursor.converter.of(cursorConverter(handle, path)),
428
429
  syncState,
@@ -436,25 +437,14 @@ var automerge = ({ handle, path }) => {
436
437
  handle.removeListener("change", this._handleChange.bind(this));
437
438
  }
438
439
  _handleChange() {
439
- semaphore.reconcile(this._view);
440
+ syncer.reconcile(this._view, false);
440
441
  }
441
442
  }),
442
443
  // Reconcile local updates.
443
444
  EditorView2.updateListener.of(({ view, changes }) => {
444
445
  if (!changes.empty) {
445
- semaphore.reconcile(view);
446
- }
447
- }),
448
- // TODO(burdon): Record undo transactions.
449
- // See https://github.com/yjs/y-codemirror.next/tree/main
450
- // https://codemirror.net/examples/inverted-effect
451
- invertedEffects.of((tr) => {
452
- const effects = [];
453
- if (!tr.changes.empty) {
454
- tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
455
- });
446
+ syncer.reconcile(view, true);
456
447
  }
457
- return effects;
458
448
  })
459
449
  ];
460
450
  };
@@ -1025,7 +1015,7 @@ var random = (min, max) => {
1025
1015
  };
1026
1016
 
1027
1017
  // packages/ui/react-ui-editor/src/extensions/comments.ts
1028
- import { invertedEffects as invertedEffects2 } from "@codemirror/commands";
1018
+ import { invertedEffects } from "@codemirror/commands";
1029
1019
  import { Facet as Facet3, StateEffect as StateEffect2, StateField as StateField3 } from "@codemirror/state";
1030
1020
  import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView6 } from "@codemirror/view";
1031
1021
  import sortBy from "lodash.sortby";
@@ -1269,7 +1259,7 @@ var trackPastedComments = (onUpdate) => {
1269
1259
  copy: handleTrack
1270
1260
  }),
1271
1261
  // Track deleted comments.
1272
- invertedEffects2.of((tr) => {
1262
+ invertedEffects.of((tr) => {
1273
1263
  const { comments: comments2 } = tr.startState.field(commentsState);
1274
1264
  const effects = [];
1275
1265
  tr.changes.iterChangedRanges((fromA, toA) => {