@dxos/react-ui-editor 0.3.11-main.2c83f41 → 0.3.11-main.2e1a8e1

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.
Files changed (107) hide show
  1. package/dist/lib/browser/index.mjs +748 -753
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +16 -13
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts +19 -17
  7. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  8. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +6 -6
  9. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
  10. package/dist/types/src/components/TextEditor/comments.stories.d.ts +26 -0
  11. package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -0
  12. package/dist/types/src/components/TextEditor/yjs.stories.d.ts +1 -1
  13. package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
  14. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  15. package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
  16. package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
  17. package/dist/types/src/extensions/automerge/defs.d.ts +7 -9
  18. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  19. package/dist/types/src/extensions/automerge/index.d.ts +0 -1
  20. package/dist/types/src/extensions/automerge/index.d.ts.map +1 -1
  21. package/dist/types/src/extensions/automerge/semaphore.d.ts +7 -12
  22. package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
  23. package/dist/types/src/extensions/automerge/update-automerge.d.ts +2 -2
  24. package/dist/types/src/extensions/awareness.d.ts +2 -0
  25. package/dist/types/src/extensions/awareness.d.ts.map +1 -1
  26. package/dist/types/src/extensions/basic.d.ts +4 -5
  27. package/dist/types/src/extensions/basic.d.ts.map +1 -1
  28. package/dist/types/src/extensions/code.d.ts.map +1 -1
  29. package/dist/types/src/extensions/comments.d.ts +31 -18
  30. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  31. package/dist/types/src/{util → extensions}/cursor.d.ts +10 -2
  32. package/dist/types/src/extensions/cursor.d.ts.map +1 -0
  33. package/dist/types/src/extensions/hr.d.ts.map +1 -1
  34. package/dist/types/src/extensions/index.d.ts +2 -0
  35. package/dist/types/src/extensions/index.d.ts.map +1 -1
  36. package/dist/types/src/extensions/markdown/bundle.d.ts +2 -5
  37. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  38. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  39. package/dist/types/src/extensions/mention.d.ts.map +1 -1
  40. package/dist/types/src/extensions/outliner.d.ts +4 -0
  41. package/dist/types/src/extensions/outliner.d.ts.map +1 -0
  42. package/dist/types/src/extensions/tasklist.d.ts.map +1 -1
  43. package/dist/types/src/extensions/yjs/cursor.d.ts +1 -1
  44. package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -1
  45. package/dist/types/src/hooks/automerge.d.ts +2 -1
  46. package/dist/types/src/hooks/automerge.d.ts.map +1 -1
  47. package/dist/types/src/hooks/defs.d.ts +28 -0
  48. package/dist/types/src/hooks/defs.d.ts.map +1 -0
  49. package/dist/types/src/hooks/index.d.ts +2 -1
  50. package/dist/types/src/hooks/index.d.ts.map +1 -1
  51. package/dist/types/src/hooks/useTextModel.d.ts +2 -32
  52. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  53. package/dist/types/src/hooks/yjs.d.ts +2 -1
  54. package/dist/types/src/hooks/yjs.d.ts.map +1 -1
  55. package/dist/types/src/index.d.ts +1 -0
  56. package/dist/types/src/index.d.ts.map +1 -1
  57. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  58. package/dist/types/src/themes/default.d.ts.map +1 -1
  59. package/dist/types/src/util.d.ts +7 -0
  60. package/dist/types/src/util.d.ts.map +1 -0
  61. package/package.json +32 -31
  62. package/src/components/TextEditor/MarkdownEditor.stories.tsx +77 -79
  63. package/src/components/TextEditor/TextEditor.stories.tsx +12 -46
  64. package/src/components/TextEditor/TextEditor.tsx +113 -92
  65. package/src/components/TextEditor/comments.stories.tsx +357 -0
  66. package/src/extensions/autocomplete.ts +6 -3
  67. package/src/extensions/automerge/automerge.ts +24 -49
  68. package/src/extensions/automerge/cursor.ts +2 -1
  69. package/src/extensions/automerge/defs.ts +10 -31
  70. package/src/extensions/automerge/index.ts +0 -1
  71. package/src/extensions/automerge/semaphore.ts +23 -20
  72. package/src/extensions/automerge/update-automerge.ts +2 -2
  73. package/src/extensions/awareness.ts +45 -34
  74. package/src/extensions/basic.ts +22 -17
  75. package/src/extensions/code.ts +24 -18
  76. package/src/extensions/comments.ts +242 -234
  77. package/src/extensions/cursor.ts +50 -0
  78. package/src/extensions/hr.ts +49 -50
  79. package/src/extensions/image.ts +2 -2
  80. package/src/extensions/index.ts +2 -0
  81. package/src/extensions/link.ts +7 -7
  82. package/src/extensions/markdown/bundle.ts +18 -24
  83. package/src/extensions/markdown/highlight.ts +0 -8
  84. package/src/extensions/mention.ts +9 -2
  85. package/src/extensions/outliner.ts +12 -0
  86. package/src/extensions/table.ts +2 -2
  87. package/src/extensions/tasklist.ts +78 -86
  88. package/src/extensions/yjs/cursor.ts +2 -1
  89. package/src/extensions/yjs/yjs.test.ts +1 -1
  90. package/src/extensions/yjs/yjs.ts +2 -2
  91. package/src/hooks/automerge.ts +2 -1
  92. package/src/hooks/defs.ts +47 -0
  93. package/src/hooks/index.ts +3 -1
  94. package/src/hooks/useTextModel.ts +3 -49
  95. package/src/hooks/yjs.ts +2 -23
  96. package/src/index.ts +1 -0
  97. package/src/styles/markdown.ts +0 -2
  98. package/src/themes/default.ts +17 -50
  99. package/src/util.ts +41 -0
  100. package/dist/types/src/util/cursor.d.ts.map +0 -1
  101. package/dist/types/src/util/index.d.ts +0 -3
  102. package/dist/types/src/util/index.d.ts.map +0 -1
  103. package/dist/types/src/util/util.d.ts +0 -5
  104. package/dist/types/src/util/util.d.ts.map +0 -1
  105. package/src/util/cursor.ts +0 -29
  106. package/src/util/index.ts +0 -6
  107. package/src/util/util.ts +0 -18
@@ -7,14 +7,14 @@ import { tags as tags2 } from "@lezer/highlight";
7
7
 
8
8
  // packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
9
9
  import { EditorState as EditorState2 } from "@codemirror/state";
10
- import { EditorView as EditorView12 } from "@codemirror/view";
10
+ import { EditorView as EditorView13 } from "@codemirror/view";
11
11
  import { useFocusableGroup } from "@fluentui/react-tabster";
12
12
  import { vim } from "@replit/codemirror-vim";
13
13
  import defaultsDeep2 from "lodash.defaultsdeep";
14
- import React, { forwardRef, useCallback, useEffect, useImperativeHandle, useState } from "react";
15
- import { generateName } from "@dxos/display-name";
16
- import { useThemeContext } from "@dxos/react-ui";
17
- import { getColorForValue, inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
14
+ import React, { forwardRef, useCallback, useEffect as useEffect3, useImperativeHandle, useRef, useState } from "react";
15
+ import { log as log2 } from "@dxos/log";
16
+ import { useThemeContext as useThemeContext2 } from "@dxos/react-ui";
17
+ import { inputSurface, mx as mx3 } from "@dxos/react-ui-theme";
18
18
 
19
19
  // packages/ui/react-ui-editor/src/extensions/autocomplete.ts
20
20
  import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
@@ -29,9 +29,11 @@ var autocomplete = ({ onSearch }) => {
29
29
  // https://codemirror.net/examples/autocompletion
30
30
  // https://codemirror.net/docs/ref/#autocomplete.autocompletion
31
31
  autocompletion({
32
- defaultKeymap: false,
33
- // Don't start unless key press.
34
- activateOnTyping: false
32
+ activateOnTyping: true,
33
+ // closeOnBlur: false,
34
+ // defaultKeymap: false,
35
+ // TODO(burdon): Styles/fragments.
36
+ tooltipClass: () => "shadow rounded"
35
37
  }),
36
38
  // TODO(burdon): Option to create new page?
37
39
  // TODO(burdon): Optional decoration via addToOptions
@@ -51,8 +53,8 @@ var autocomplete = ({ onSearch }) => {
51
53
  };
52
54
 
53
55
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
54
- import { Facet as Facet2, StateField } from "@codemirror/state";
55
- import { ViewPlugin } from "@codemirror/view";
56
+ import { StateField } from "@codemirror/state";
57
+ import { EditorView } from "@codemirror/view";
56
58
  import { next as A } from "@dxos/automerge/automerge";
57
59
 
58
60
  // packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
@@ -94,12 +96,12 @@ var cursorConverter = (handle, path) => ({
94
96
  // packages/ui/react-ui-editor/src/extensions/automerge/defs.ts
95
97
  import { Annotation, StateEffect } from "@codemirror/state";
96
98
  var effectType = StateEffect.define({});
99
+ var reconcileAnnotationType = Annotation.define();
100
+ var getPath = (state, field) => state.field(field).path;
101
+ var getLastHeads = (state, field) => state.field(field).lastHeads;
97
102
  var updateHeads = (newHeads) => effectType.of({
98
103
  newHeads
99
104
  });
100
- var getLastHeads = (state, field) => state.field(field).lastHeads;
101
- var getPath = (state, field) => state.field(field).path;
102
- var reconcileAnnotationType = Annotation.define();
103
105
  var isReconcileTx = (tr) => !!tr.annotation(reconcileAnnotationType);
104
106
 
105
107
  // packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
@@ -237,85 +239,95 @@ var charPath = (textPath, candidatePath) => {
237
239
 
238
240
  // packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
239
241
  var PatchSemaphore = class {
240
- constructor(_field) {
241
- this._field = _field;
242
+ // prettier-ignore
243
+ constructor(_handle, _state) {
244
+ this._handle = _handle;
245
+ this._state = _state;
242
246
  this._inReconcile = false;
243
- this._queue = [];
244
- this.reconcile = (handle, view) => {
245
- if (this._inReconcile) {
246
- return;
247
- }
248
- this._inReconcile = true;
249
- const path = getPath(view.state, this._field);
250
- const oldHeads = getLastHeads(view.state, this._field);
251
- let selection = view.state.selection;
252
- const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
253
- const toInvert = transactions.slice().reverse();
254
- for (const tx of toInvert) {
255
- const inverted = tx.changes.invert(tx.startState.doc);
256
- selection = selection.map(inverted);
257
- view.dispatch({
258
- changes: inverted,
259
- annotations: reconcileAnnotationType.of(true)
260
- });
261
- }
262
- let newHeads = updateAutomerge(this._field, handle, transactions, view.state);
263
- if (newHeads === null || newHeads === void 0) {
264
- newHeads = automerge2.getHeads(handle.docSync());
265
- }
266
- const diff = automerge2.equals(oldHeads, newHeads) ? [] : automerge2.diff(handle.docSync(), oldHeads, newHeads);
267
- updateCodeMirror(view, selection, path, diff);
247
+ }
248
+ // NOTE: Cannot destruct view.state.
249
+ reconcile(view) {
250
+ if (this._inReconcile) {
251
+ return;
252
+ }
253
+ this._inReconcile = true;
254
+ const path = getPath(view.state, this._state);
255
+ const oldHeads = getLastHeads(view.state, this._state);
256
+ let selection = view.state.selection;
257
+ const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
258
+ const toInvert = transactions.slice().reverse();
259
+ for (const tx of toInvert) {
260
+ const inverted = tx.changes.invert(tx.startState.doc);
261
+ selection = selection.map(inverted);
268
262
  view.dispatch({
269
- effects: updateHeads(newHeads),
270
- annotations: reconcileAnnotationType.of({})
263
+ changes: inverted,
264
+ annotations: reconcileAnnotationType.of(true)
271
265
  });
272
- this._inReconcile = false;
273
- };
266
+ }
267
+ let newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
268
+ if (newHeads === null || newHeads === void 0) {
269
+ newHeads = automerge2.getHeads(this._handle.docSync());
270
+ }
271
+ const diff = automerge2.equals(oldHeads, newHeads) ? [] : automerge2.diff(this._handle.docSync(), oldHeads, newHeads);
272
+ updateCodeMirror(view, selection, path, diff);
273
+ view.dispatch({
274
+ effects: updateHeads(newHeads),
275
+ annotations: reconcileAnnotationType.of({})
276
+ });
277
+ this._inReconcile = false;
274
278
  }
275
279
  };
276
280
 
277
- // packages/ui/react-ui-editor/src/util/cursor.ts
281
+ // packages/ui/react-ui-editor/src/extensions/cursor.ts
278
282
  import { Facet } from "@codemirror/state";
279
- var DEFAULT_CURSOR_CONVERTER = {
283
+ var defaultCursorConverter = {
280
284
  toCursor: (position) => position.toString(),
281
285
  fromCursor: (cursor) => parseInt(cursor)
282
286
  };
283
- var CursorConverter = Facet.define({
284
- combine: (providers) => providers[0] ?? DEFAULT_CURSOR_CONVERTER
285
- });
286
-
287
- // packages/ui/react-ui-editor/src/util/util.ts
288
- import { log } from "@dxos/log";
289
- var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/util/util.ts";
290
- var callbackWrapper = (fn) => (...args) => {
291
- try {
292
- return fn(...args);
293
- } catch (error) {
294
- log.catch(error, void 0, {
295
- F: __dxlog_file,
296
- L: 16,
297
- S: void 0,
298
- C: (f, a) => f(...a)
287
+ var Cursor = class _Cursor {
288
+ static {
289
+ this.converter = Facet.define({
290
+ combine: (providers) => providers[0] ?? defaultCursorConverter
299
291
  });
300
292
  }
293
+ static {
294
+ this.getCursorFromRange = (state, range) => {
295
+ const cursorConverter3 = state.facet(_Cursor.converter);
296
+ const from = cursorConverter3.toCursor(range.from);
297
+ const to = cursorConverter3.toCursor(range.to, -1);
298
+ return [
299
+ from,
300
+ to
301
+ ].join(":");
302
+ };
303
+ }
304
+ static {
305
+ this.getRangeFromCursor = (state, cursor) => {
306
+ const cursorConverter3 = state.facet(_Cursor.converter);
307
+ const parts = cursor.split(":");
308
+ const from = cursorConverter3.fromCursor(parts[0]);
309
+ const to = cursorConverter3.fromCursor(parts[1]);
310
+ return from !== void 0 && to !== void 0 ? {
311
+ from,
312
+ to
313
+ } : void 0;
314
+ };
315
+ }
301
316
  };
302
317
 
303
318
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
304
- var semaphoreFacet = Facet2.define({
305
- combine: (values) => values.at(-1)
306
- });
307
319
  var automerge3 = ({ handle, path }) => {
308
- const stateField = StateField.define({
320
+ const state = StateField.define({
309
321
  create: () => ({
322
+ path: path.slice(),
310
323
  lastHeads: A.getHeads(handle.docSync()),
311
- unreconciledTransactions: [],
312
- path: path.slice()
324
+ unreconciledTransactions: []
313
325
  }),
314
326
  update: (value, tr) => {
315
327
  const result = {
328
+ path: path.slice(),
316
329
  lastHeads: value.lastHeads,
317
- unreconciledTransactions: value.unreconciledTransactions.slice(),
318
- path: path.slice()
330
+ unreconciledTransactions: value.unreconciledTransactions.slice()
319
331
  };
320
332
  let clearUnreconciled = false;
321
333
  for (const effect of tr.effects) {
@@ -334,41 +346,27 @@ var automerge3 = ({ handle, path }) => {
334
346
  return result;
335
347
  }
336
348
  });
337
- const semaphore = new PatchSemaphore(stateField);
338
- const viewPlugin = ViewPlugin.fromClass(class AutomergeCodemirrorViewPlugin {
339
- constructor(_view) {
340
- this._view = _view;
341
- this._handleChange = () => {
342
- this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
343
- };
344
- handle.addListener("change", this._handleChange);
345
- }
346
- update(update2) {
347
- if (update2.transactions.length > 0 && update2.transactions.some((tr) => !isReconcileTx(tr))) {
348
- queueMicrotask(() => {
349
- this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
350
- });
349
+ const semaphore = new PatchSemaphore(handle, state);
350
+ return [
351
+ Cursor.converter.of(cursorConverter(handle, path)),
352
+ EditorView.updateListener.of(({ view, changes }) => {
353
+ if (!changes.empty) {
354
+ semaphore.reconcile(view);
351
355
  }
352
- }
353
- destroy() {
354
- handle.addListener("change", this._handleChange);
355
- }
356
- });
357
- return {
358
- extension: [
359
- CursorConverter.of(cursorConverter(handle, path)),
360
- semaphoreFacet.of(semaphore),
361
- stateField,
362
- viewPlugin
363
- ]
364
- };
356
+ }),
357
+ state
358
+ ];
365
359
  };
366
360
 
367
361
  // packages/ui/react-ui-editor/src/extensions/awareness.ts
368
- import { Annotation as Annotation2, Facet as Facet3, RangeSet } from "@codemirror/state";
369
- import { Decoration, EditorView, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
362
+ import { Annotation as Annotation2, Facet as Facet2, RangeSet } from "@codemirror/state";
363
+ import { Decoration, EditorView as EditorView2, ViewPlugin, WidgetType } from "@codemirror/view";
364
+ import { useEffect } from "react";
370
365
  import { Event } from "@dxos/async";
371
366
  import { Context } from "@dxos/context";
367
+ import { generateName } from "@dxos/display-name";
368
+ import { useThemeContext } from "@dxos/react-ui";
369
+ import { getColorForValue } from "@dxos/react-ui-theme";
372
370
  var dummyProvider = {
373
371
  remoteStateChange: new Event(),
374
372
  open: () => {
@@ -379,26 +377,49 @@ var dummyProvider = {
379
377
  },
380
378
  getRemoteStates: () => []
381
379
  };
382
- var AwarenessProvider = Facet3.define({
380
+ var AwarenessProvider = Facet2.define({
383
381
  combine: (providers) => providers[0] ?? dummyProvider
384
382
  });
385
383
  var RemoteSelectionChangedAnnotation = Annotation2.define();
386
384
  var awareness = (provider = dummyProvider) => {
387
385
  return [
388
386
  AwarenessProvider.of(provider),
389
- ViewPlugin2.fromClass(RemoteSelectionsDecorator, {
387
+ ViewPlugin.fromClass(RemoteSelectionsDecorator, {
390
388
  decorations: (value) => value.decorations
391
389
  }),
392
390
  styles
393
391
  ];
394
392
  };
393
+ var useAwareness = ({ awareness: awareness2, peer }) => {
394
+ const { themeMode } = useThemeContext();
395
+ useEffect(() => {
396
+ if (awareness2 && peer) {
397
+ awareness2.setLocalStateField("user", {
398
+ name: peer.name ?? generateName(peer.id),
399
+ color: getColorForValue({
400
+ value: peer.id,
401
+ type: "color"
402
+ }),
403
+ colorLight: getColorForValue({
404
+ value: peer.id,
405
+ themeMode,
406
+ type: "highlight"
407
+ })
408
+ });
409
+ }
410
+ }, [
411
+ awareness2,
412
+ peer,
413
+ themeMode
414
+ ]);
415
+ };
395
416
  var RemoteSelectionsDecorator = class {
396
417
  constructor(view) {
397
418
  this.decorations = RangeSet.of([]);
398
419
  this._ctx = new Context();
399
420
  this._lastAnchor = void 0;
400
421
  this._lastHead = void 0;
401
- this._cursorConverter = view.state.facet(CursorConverter);
422
+ this._cursorConverter = view.state.facet(Cursor.converter);
402
423
  this._provider = view.state.facet(AwarenessProvider);
403
424
  this._provider.open();
404
425
  this._provider.remoteStateChange.on(this._ctx, () => {
@@ -453,7 +474,7 @@ var RemoteSelectionsDecorator = class {
453
474
  attributes: {
454
475
  style: `background-color: ${lightColor}`
455
476
  },
456
- class: "cm-ySelection"
477
+ class: "cm-collab-selection"
457
478
  })
458
479
  });
459
480
  } else {
@@ -464,7 +485,7 @@ var RemoteSelectionsDecorator = class {
464
485
  attributes: {
465
486
  style: `background-color: ${color}`
466
487
  },
467
- class: "cm-ySelection"
488
+ class: "cm-collab-selection"
468
489
  })
469
490
  });
470
491
  decorations.push({
@@ -474,7 +495,7 @@ var RemoteSelectionsDecorator = class {
474
495
  attributes: {
475
496
  style: `background-color: ${color}`
476
497
  },
477
- class: "cm-ySelection"
498
+ class: "cm-collab-selection"
478
499
  })
479
500
  });
480
501
  for (let i = startLine.number + 1; i < endLine.number; i++) {
@@ -485,7 +506,7 @@ var RemoteSelectionsDecorator = class {
485
506
  value: Decoration.line({
486
507
  attributes: {
487
508
  style: `background-color: ${color}`,
488
- class: "cm-yLineSelection"
509
+ class: "cm-collab-selectionLine"
489
510
  }
490
511
  })
491
512
  });
@@ -505,23 +526,21 @@ var RemoteSelectionsDecorator = class {
505
526
  }
506
527
  };
507
528
  var RemoteCaretWidget = class extends WidgetType {
508
- constructor(name, color) {
529
+ constructor(_name, _color) {
509
530
  super();
510
- this.name = name;
511
- this.color = color;
512
- this.name = name;
513
- this.color = color;
531
+ this._name = _name;
532
+ this._color = _color;
514
533
  }
515
534
  toDOM() {
516
535
  const span = document.createElement("span");
517
- span.className = "cm-ySelectionCaret";
518
- span.style.backgroundColor = this.color;
519
- span.style.borderColor = this.color;
536
+ span.className = "cm-collab-selectionCaret";
537
+ span.style.backgroundColor = this._color;
538
+ span.style.borderColor = this._color;
520
539
  const dot = document.createElement("div");
521
- dot.className = "cm-ySelectionCaretDot";
540
+ dot.className = "cm-collab-selectionCaretDot";
522
541
  const info = document.createElement("div");
523
- info.className = "cm-ySelectionInfo";
524
- info.innerText = this.name;
542
+ info.className = "cm-collab-selectionInfo";
543
+ info.innerText = this._name;
525
544
  span.appendChild(document.createTextNode("\u2060"));
526
545
  span.appendChild(dot);
527
546
  span.appendChild(document.createTextNode("\u2060"));
@@ -529,15 +548,12 @@ var RemoteCaretWidget = class extends WidgetType {
529
548
  span.appendChild(document.createTextNode("\u2060"));
530
549
  return span;
531
550
  }
532
- eq(widget) {
533
- return widget.color === this.color;
534
- }
535
- compare(widget) {
536
- return widget.color === this.color;
537
- }
538
551
  updateDOM() {
539
552
  return false;
540
553
  }
554
+ eq(widget) {
555
+ return widget._color === this._color;
556
+ }
541
557
  get estimatedHeight() {
542
558
  return -1;
543
559
  }
@@ -545,13 +561,13 @@ var RemoteCaretWidget = class extends WidgetType {
545
561
  return true;
546
562
  }
547
563
  };
548
- var styles = EditorView.baseTheme({
549
- ".cm-ySelection": {},
550
- ".cm-yLineSelection": {
564
+ var styles = EditorView2.baseTheme({
565
+ ".cm-collab-selection": {},
566
+ ".cm-collab-selectionLine": {
551
567
  padding: 0,
552
568
  margin: "0px 2px 0px 4px"
553
569
  },
554
- ".cm-ySelectionCaret": {
570
+ ".cm-collab-selectionCaret": {
555
571
  position: "relative",
556
572
  borderLeft: "1px solid black",
557
573
  borderRight: "1px solid black",
@@ -560,7 +576,7 @@ var styles = EditorView.baseTheme({
560
576
  boxSizing: "border-box",
561
577
  display: "inline"
562
578
  },
563
- ".cm-ySelectionCaretDot": {
579
+ ".cm-collab-selectionCaretDot": {
564
580
  borderRadius: "50%",
565
581
  position: "absolute",
566
582
  width: ".4em",
@@ -571,11 +587,11 @@ var styles = EditorView.baseTheme({
571
587
  transition: "transform .3s ease-in-out",
572
588
  boxSizing: "border-box"
573
589
  },
574
- ".cm-ySelectionCaret:hover > .cm-ySelectionCaretDot": {
590
+ ".cm-collab-selectionCaret:hover > .cm-collab-selectionCaretDot": {
575
591
  transformOrigin: "bottom center",
576
592
  transform: "scale(0)"
577
593
  },
578
- ".cm-ySelectionInfo": {
594
+ ".cm-collab-selectionInfo": {
579
595
  position: "absolute",
580
596
  top: "-1.05em",
581
597
  left: "-1px",
@@ -591,12 +607,12 @@ var styles = EditorView.baseTheme({
591
607
  zIndex: 101,
592
608
  transition: "opacity .3s ease-in-out",
593
609
  backgroundColor: "inherit",
594
- // these should be separate
610
+ // These should be separate.
595
611
  opacity: 0,
596
612
  transitionDelay: "0s",
597
613
  whiteSpace: "nowrap"
598
614
  },
599
- ".cm-ySelectionCaret:hover > .cm-ySelectionInfo": {
615
+ ".cm-collab-selectionCaret:hover > .cm-collab-selectionInfo": {
600
616
  opacity: 1,
601
617
  transitionDelay: "0s"
602
618
  }
@@ -604,26 +620,28 @@ var styles = EditorView.baseTheme({
604
620
 
605
621
  // packages/ui/react-ui-editor/src/extensions/basic.ts
606
622
  import { closeBrackets } from "@codemirror/autocomplete";
623
+ import { history } from "@codemirror/commands";
607
624
  import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
608
625
  import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
609
- import { drawSelection, EditorView as EditorView2, placeholder } from "@codemirror/view";
610
- var basicBundle = ({ readonly, themeMode, placeholder: _placeholder }) => [
611
- EditorView2.lineWrapping,
612
- // TODO(burdon): Compare with minimalSetup.
626
+ import { drawSelection, EditorView as EditorView3, highlightActiveLine, placeholder } from "@codemirror/view";
627
+ var basicBundle = ({ themeMode, placeholder: _placeholder, multiline = true }) => [
628
+ multiline ? EditorView3.lineWrapping : [],
613
629
  // https://codemirror.net/docs/ref/#codemirror.minimalSetup
614
630
  bracketMatching(),
615
631
  closeBrackets(),
616
632
  drawSelection(),
617
- _placeholder && placeholder(_placeholder),
618
- // TODO(burdon): Is this required?
633
+ highlightActiveLine(),
634
+ history(),
635
+ _placeholder ? placeholder(_placeholder) : [],
636
+ // https://github.com/codemirror/theme-one-dark
619
637
  themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
620
- ].filter(Boolean);
638
+ ];
621
639
 
622
640
  // packages/ui/react-ui-editor/src/extensions/blast.ts
623
- import { EditorView as EditorView3, keymap as keymap2 } from "@codemirror/view";
641
+ import { EditorView as EditorView4, keymap as keymap2 } from "@codemirror/view";
624
642
  import defaultsDeep from "lodash.defaultsdeep";
625
643
  import { invariant } from "@dxos/invariant";
626
- var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/blast.ts";
644
+ var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/blast.ts";
627
645
  var defaultOptions = {
628
646
  effect: 2,
629
647
  maxParticles: 200,
@@ -668,7 +686,7 @@ var blast = (options = defaultOptions) => {
668
686
  };
669
687
  return [
670
688
  // Cursor moved.
671
- EditorView3.updateListener.of((update2) => {
689
+ EditorView4.updateListener.of((update2) => {
672
690
  if (blaster?.node !== update2.view.scrollDOM) {
673
691
  if (blaster) {
674
692
  blaster.destroy();
@@ -750,7 +768,7 @@ var Blaster = class {
750
768
  }
751
769
  initialize() {
752
770
  invariant(!this._canvas && !this._ctx, void 0, {
753
- F: __dxlog_file2,
771
+ F: __dxlog_file,
754
772
  L: 138,
755
773
  S: this,
756
774
  A: [
@@ -787,7 +805,7 @@ var Blaster = class {
787
805
  }
788
806
  start() {
789
807
  invariant(this._canvas && this._ctx, void 0, {
790
- F: __dxlog_file2,
808
+ F: __dxlog_file,
791
809
  L: 177,
792
810
  S: this,
793
811
  A: [
@@ -930,7 +948,7 @@ var random = (min, max) => {
930
948
  };
931
949
 
932
950
  // packages/ui/react-ui-editor/src/extensions/code.ts
933
- import { ViewPlugin as ViewPlugin3, EditorView as EditorView4, Decoration as Decoration2 } from "@codemirror/view";
951
+ import { ViewPlugin as ViewPlugin2, EditorView as EditorView5, Decoration as Decoration2 } from "@codemirror/view";
934
952
  import { mx as mx2 } from "@dxos/react-ui-theme";
935
953
 
936
954
  // packages/ui/react-ui-editor/src/styles/cursors.ts
@@ -1021,7 +1039,7 @@ var getToken = (path, defaultValue = void 0) => get2(tokens, path, defaultValue)
1021
1039
 
1022
1040
  // packages/ui/react-ui-editor/src/extensions/code.ts
1023
1041
  var CODE_REGEX = /```[\s\S]*?```/gs;
1024
- var styles2 = EditorView4.baseTheme({
1042
+ var styles2 = EditorView5.baseTheme({
1025
1043
  "& .cm-codeblock": {
1026
1044
  fontFamily: getToken("fontFamily.mono", []).join(",")
1027
1045
  },
@@ -1055,32 +1073,35 @@ var getLineRange = (lines, from, to) => {
1055
1073
  ];
1056
1074
  };
1057
1075
  var code2 = () => {
1058
- const getDecorations = (view) => {
1076
+ const buildDecorations5 = (view) => {
1059
1077
  const decorations = [];
1060
- if (view.state.readOnly) {
1061
- const text = view.state.doc.sliceString(0);
1062
- const matches = text.matchAll(CODE_REGEX);
1063
- const blocks = view.viewportLineBlocks;
1064
- for (const match of matches) {
1065
- const range = getLineRange(blocks, match.index, match.index + match[0].length);
1066
- for (let i = range[0]; i <= range[1]; i++) {
1067
- const block = blocks[i];
1068
- decorations.push(Decoration2.line({
1069
- class: mx2("cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
1070
- }).range(block.from));
1071
- }
1078
+ const text = view.state.doc.sliceString(0);
1079
+ const matches = text.matchAll(CODE_REGEX);
1080
+ const blocks = view.viewportLineBlocks;
1081
+ for (const match of matches) {
1082
+ const range = getLineRange(blocks, match.index, match.index + match[0].length);
1083
+ for (let i = range[0]; i <= range[1]; i++) {
1084
+ const block = blocks[i];
1085
+ decorations.push(Decoration2.line({
1086
+ class: mx2("cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
1087
+ }).range(block.from));
1072
1088
  }
1073
1089
  }
1074
1090
  return Decoration2.set(decorations);
1075
1091
  };
1076
1092
  return [
1077
- ViewPlugin3.fromClass(class {
1093
+ ViewPlugin2.fromClass(class {
1078
1094
  constructor(view) {
1079
- this.decorations = getDecorations(view);
1095
+ this.hasFocus = false;
1096
+ this.decorations = buildDecorations5(view);
1080
1097
  }
1081
1098
  update(update2) {
1082
- if (update2.docChanged || update2.viewportChanged) {
1083
- this.decorations = getDecorations(update2.view);
1099
+ if (
1100
+ // TODO(burdon): Generalize for other extensions.
1101
+ this.hasFocus !== update2.view.hasFocus || update2.startState.readOnly !== update2.view.state.readOnly || update2.docChanged || update2.viewportChanged
1102
+ ) {
1103
+ this.hasFocus = update2.view.hasFocus;
1104
+ this.decorations = buildDecorations5(update2.view);
1084
1105
  }
1085
1106
  }
1086
1107
  }, {
@@ -1092,23 +1113,51 @@ var code2 = () => {
1092
1113
 
1093
1114
  // packages/ui/react-ui-editor/src/extensions/comments.ts
1094
1115
  import { StateEffect as StateEffect2, StateField as StateField2 } from "@codemirror/state";
1095
- import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView5, MatchDecorator, ViewPlugin as ViewPlugin4, WidgetType as WidgetType2 } from "@codemirror/view";
1116
+ import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView6 } from "@codemirror/view";
1096
1117
  import sortBy from "lodash.sortby";
1118
+ import { useEffect as useEffect2 } from "react";
1097
1119
  import { debounce } from "@dxos/async";
1098
1120
  import { invariant as invariant2 } from "@dxos/invariant";
1099
- import { log as log2 } from "@dxos/log";
1100
1121
  import { nonNullable } from "@dxos/util";
1122
+
1123
+ // packages/ui/react-ui-editor/src/util.ts
1124
+ import { log } from "@dxos/log";
1125
+ var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/util.ts";
1126
+ var callbackWrapper = (fn) => (...args) => {
1127
+ try {
1128
+ return fn(...args);
1129
+ } catch (err) {
1130
+ log.catch(err, void 0, {
1131
+ F: __dxlog_file2,
1132
+ L: 18,
1133
+ S: void 0,
1134
+ C: (f, a) => f(...a)
1135
+ });
1136
+ }
1137
+ };
1138
+ var logChanges = (trs) => {
1139
+ const changes = trs.flatMap((tr) => {
1140
+ if (tr.changes.empty) {
1141
+ return void 0;
1142
+ }
1143
+ const changes2 = [];
1144
+ tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => changes2.push(JSON.stringify({
1145
+ fromA,
1146
+ toA,
1147
+ fromB,
1148
+ toB,
1149
+ inserted: inserted.toString()
1150
+ })));
1151
+ return changes2;
1152
+ }).filter(Boolean);
1153
+ if (changes.length) {
1154
+ console.log("changes", changes);
1155
+ }
1156
+ };
1157
+
1158
+ // packages/ui/react-ui-editor/src/extensions/comments.ts
1101
1159
  var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
1102
- var styles3 = EditorView5.baseTheme({
1103
- "& .cm-bookmark": {
1104
- cursor: "pointer",
1105
- margin: "4px",
1106
- padding: "4px",
1107
- backgroundColor: "yellow"
1108
- },
1109
- "& .cm-bookmark-selected": {
1110
- backgroundColor: "orange"
1111
- },
1160
+ var styles3 = EditorView6.baseTheme({
1112
1161
  "& .cm-comment": {
1113
1162
  backgroundColor: getToken("extend.colors.yellow.50")
1114
1163
  },
@@ -1124,49 +1173,59 @@ var marks = {
1124
1173
  class: "cm-comment-active"
1125
1174
  })
1126
1175
  };
1127
- var setFocus = (view, thread) => {
1128
- const range = view.state.field(commentsStateField).ranges.find((range2) => range2.id === thread);
1129
- if (!range) {
1176
+ var setFocus = (view, id, center = true) => {
1177
+ const comment = view.state.field(commentsState).comments.find((range2) => range2.comment.id === id);
1178
+ if (!comment?.comment.cursor) {
1130
1179
  return;
1131
1180
  }
1132
- view.dispatch({
1133
- effects: setSelection.of({
1134
- active: thread
1135
- }),
1136
- selection: {
1137
- anchor: range.from
1138
- },
1139
- scrollIntoView: true
1140
- });
1181
+ const range = Cursor.getRangeFromCursor(view.state, comment.comment.cursor);
1182
+ if (range) {
1183
+ view.dispatch({
1184
+ selection: {
1185
+ anchor: range.from
1186
+ },
1187
+ effects: [
1188
+ //
1189
+ EditorView6.scrollIntoView(range.from, center ? {
1190
+ y: "center"
1191
+ } : void 0),
1192
+ setSelection.of({
1193
+ active: id
1194
+ })
1195
+ ]
1196
+ });
1197
+ }
1141
1198
  };
1142
- var setCommentRange = StateEffect2.define();
1199
+ var setComments = StateEffect2.define();
1143
1200
  var setSelection = StateEffect2.define();
1144
1201
  var setCommentState = StateEffect2.define();
1145
- var commentsStateField = StateField2.define({
1202
+ var commentsState = StateField2.define({
1146
1203
  create: () => ({
1147
- ranges: []
1204
+ comments: [],
1205
+ selection: {}
1148
1206
  }),
1149
1207
  update: (value, tr) => {
1150
- const cursorConverter3 = tr.state.facet(CursorConverter);
1151
1208
  for (const effect of tr.effects) {
1152
1209
  if (effect.is(setSelection)) {
1153
1210
  return {
1154
1211
  ...value,
1155
- ...effect.value
1212
+ selection: effect.value
1156
1213
  };
1157
1214
  }
1158
- if (effect.is(setCommentRange)) {
1159
- const { comments: comments2 } = effect.value;
1160
- const ranges = comments2.map((comment) => {
1161
- const range = getRangeFromCursor(cursorConverter3, comment.cursor);
1215
+ if (effect.is(setComments)) {
1216
+ const comments2 = effect.value.map((comment) => {
1217
+ if (!comment.cursor) {
1218
+ return void 0;
1219
+ }
1220
+ const range = Cursor.getRangeFromCursor(tr.state, comment.cursor);
1162
1221
  return range && {
1163
- ...comment,
1164
- ...range
1222
+ comment,
1223
+ range
1165
1224
  };
1166
1225
  }).filter(nonNullable);
1167
1226
  return {
1168
1227
  ...value,
1169
- ranges
1228
+ comments: comments2
1170
1229
  };
1171
1230
  }
1172
1231
  if (effect.is(setCommentState)) {
@@ -1176,78 +1235,109 @@ var commentsStateField = StateField2.define({
1176
1235
  return value;
1177
1236
  }
1178
1237
  });
1179
- var highlightDecorations = EditorView5.decorations.compute([
1180
- commentsStateField
1238
+ var highlightDecorations = EditorView6.decorations.compute([
1239
+ commentsState
1181
1240
  ], (state) => {
1182
- const { active, ranges } = state.field(commentsStateField);
1183
- const decorations = sortBy(ranges ?? [], (range) => range.from)?.flatMap((selection) => {
1184
- if (selection.from === selection.to) {
1241
+ const { selection: { active }, comments: comments2 } = state.field(commentsState);
1242
+ const decorations = sortBy(comments2 ?? [], (range) => range.range.from)?.flatMap((comment) => {
1243
+ const range = comment.range;
1244
+ if (!range || range.from === range.to) {
1245
+ console.warn("Invalid range:", range);
1185
1246
  return void 0;
1186
1247
  }
1187
- const range = {
1188
- from: selection.from,
1189
- to: selection.to
1190
- };
1191
- if (selection.id === active) {
1248
+ if (comment.comment.id === active) {
1192
1249
  return marks.highlightActive.range(range.from, range.to);
1193
1250
  } else {
1194
1251
  return marks.highlight.range(range.from, range.to);
1195
1252
  }
1196
- }).filter(nonNullable) ?? [];
1253
+ }).filter(nonNullable);
1197
1254
  return Decoration3.set(decorations);
1198
1255
  });
1199
- var BookmarkWidget = class extends WidgetType2 {
1200
- constructor(_anchor, _id, _handleClick) {
1201
- super();
1202
- this._anchor = _anchor;
1203
- this._id = _id;
1204
- this._handleClick = _handleClick;
1205
- invariant2(this._id, void 0, {
1206
- F: __dxlog_file3,
1207
- L: 168,
1208
- S: this,
1209
- A: [
1210
- "this._id",
1211
- ""
1212
- ]
1213
- });
1214
- }
1215
- eq(other) {
1216
- return this._anchor === other._anchor && this._id === other._id;
1217
- }
1218
- toDOM() {
1219
- const span = document.createElement("span");
1220
- span.className = "cm-bookmark";
1221
- span.textContent = "\u203B";
1222
- if (this._handleClick) {
1223
- span.onclick = () => this._handleClick();
1256
+ var trackPastedComments = (onUpdate) => {
1257
+ let tracked = null;
1258
+ const handleTrack = (event, view) => {
1259
+ const comments2 = view.state.field(commentsState);
1260
+ const { main } = view.state.selection;
1261
+ const selectedRanges = comments2.comments.filter(({ range }) => range.from >= main.from && range.to <= main.to && range.from < range.to);
1262
+ if (!selectedRanges.length) {
1263
+ tracked = null;
1264
+ } else {
1265
+ tracked = {
1266
+ text: view.state.doc.slice(main.from, main.to),
1267
+ comments: selectedRanges.map(({ comment, range }) => ({
1268
+ id: comment.id,
1269
+ from: range.from - main.from,
1270
+ to: range.to - main.from
1271
+ }))
1272
+ };
1224
1273
  }
1225
- return span;
1226
- }
1274
+ };
1275
+ return [
1276
+ EditorView6.domEventHandlers({
1277
+ cut: handleTrack,
1278
+ copy: handleTrack
1279
+ }),
1280
+ // Handle paste.
1281
+ EditorView6.updateListener.of(({ view, state, transactions }) => {
1282
+ if (tracked) {
1283
+ const paste = transactions.find((tr) => tr.isUserEvent("input.paste"));
1284
+ if (paste) {
1285
+ let found = -1;
1286
+ paste.changes.iterChanges((fromA, toA, fromB, toB, text) => {
1287
+ if (text.eq(tracked.text)) {
1288
+ for (let i = transactions.indexOf(paste) + 1; i < transactions.length; i++) {
1289
+ fromB = transactions[i].changes.mapPos(fromB);
1290
+ }
1291
+ found = fromB;
1292
+ }
1293
+ });
1294
+ if (found > -1) {
1295
+ for (const moved of tracked.comments) {
1296
+ const range = {
1297
+ from: found + moved.from,
1298
+ to: found + moved.to
1299
+ };
1300
+ const cursor = Cursor.getCursorFromRange(state, range);
1301
+ onUpdate(moved.id, cursor);
1302
+ }
1303
+ }
1304
+ tracked = null;
1305
+ }
1306
+ }
1307
+ })
1308
+ ];
1227
1309
  };
1228
1310
  var comments = (options = {}) => {
1311
+ const { key: shortcut = "meta-'" } = options;
1229
1312
  const handleSelect = debounce((state) => options.onSelect?.(state), 200);
1230
1313
  const createCommentThread = (view) => {
1231
- const cursorConverter3 = view.state.facet(CursorConverter);
1232
1314
  invariant2(options.onCreate, void 0, {
1233
1315
  F: __dxlog_file3,
1234
- L: 224,
1316
+ L: 259,
1235
1317
  S: void 0,
1236
1318
  A: [
1237
1319
  "options.onCreate",
1238
1320
  ""
1239
1321
  ]
1240
1322
  });
1241
- const { head, from, to } = view.state.selection.main;
1323
+ const { from, to } = view.state.selection.main;
1242
1324
  if (from === to) {
1243
1325
  return false;
1244
1326
  }
1245
- const relPos = getCursorFromRange(cursorConverter3, {
1327
+ if (to === view.state.doc.length) {
1328
+ view.dispatch({
1329
+ changes: {
1330
+ from: to,
1331
+ insert: "\n"
1332
+ }
1333
+ });
1334
+ }
1335
+ const cursor = Cursor.getCursorFromRange(view.state, {
1246
1336
  from,
1247
1337
  to
1248
1338
  });
1249
- if (relPos) {
1250
- const id = callbackWrapper(options.onCreate)(relPos);
1339
+ if (cursor) {
1340
+ const id = options.onCreate?.(cursor, view.coordsAtPos(from));
1251
1341
  if (id) {
1252
1342
  view.dispatch({
1253
1343
  effects: setSelection.of({
@@ -1257,53 +1347,13 @@ var comments = (options = {}) => {
1257
1347
  anchor: from
1258
1348
  }
1259
1349
  });
1260
- if (options.footnote) {
1261
- const tag = `[^${id}]`;
1262
- view.dispatch({
1263
- changes: {
1264
- from: head,
1265
- insert: tag
1266
- },
1267
- selection: {
1268
- anchor: head + tag.length
1269
- }
1270
- });
1271
- }
1272
1350
  return true;
1273
1351
  }
1274
1352
  }
1275
1353
  return false;
1276
1354
  };
1277
- const bookmarksViewPlugin = ViewPlugin4.fromClass(class BookmarkViewPlugin {
1278
- static {
1279
- // Match markdown footnotes (option).
1280
- // https://www.markdownguide.org/extended-syntax/#footnotes
1281
- this.bookmarkMatcher = new MatchDecorator({
1282
- regexp: /\[\^(\w+)\]/g,
1283
- decoration: (match, view, pos) => {
1284
- const id = match[1];
1285
- return Decoration3.replace({
1286
- id,
1287
- widget: new BookmarkWidget(pos, id)
1288
- });
1289
- }
1290
- });
1291
- }
1292
- constructor(view) {
1293
- this.bookmarks = BookmarkViewPlugin.bookmarkMatcher.createDeco(view);
1294
- }
1295
- update(update2) {
1296
- this.bookmarks = BookmarkViewPlugin.bookmarkMatcher.updateDeco(update2, this.bookmarks);
1297
- }
1298
- }, {
1299
- decorations: (instance) => instance.bookmarks,
1300
- provide: (plugin) => EditorView5.atomicRanges.of((view) => {
1301
- return view.plugin(plugin)?.bookmarks || Decoration3.none;
1302
- })
1303
- });
1304
1355
  return [
1305
- bookmarksViewPlugin,
1306
- commentsStateField,
1356
+ commentsState,
1307
1357
  highlightDecorations,
1308
1358
  styles3,
1309
1359
  //
@@ -1311,7 +1361,7 @@ var comments = (options = {}) => {
1311
1361
  //
1312
1362
  options.onCreate ? keymap3.of([
1313
1363
  {
1314
- key: options?.key ?? "meta-'",
1364
+ key: shortcut,
1315
1365
  run: callbackWrapper(createCommentThread)
1316
1366
  }
1317
1367
  ]) : [],
@@ -1328,7 +1378,7 @@ var comments = (options = {}) => {
1328
1378
  above: true,
1329
1379
  create: () => {
1330
1380
  const el = document.createElement("div");
1331
- options.onHover?.(el);
1381
+ options.onHover(el, shortcut);
1332
1382
  return {
1333
1383
  dom: el,
1334
1384
  offset: {
@@ -1341,156 +1391,154 @@ var comments = (options = {}) => {
1341
1391
  }
1342
1392
  return null;
1343
1393
  }, {
1344
- hideOnChange: true,
1394
+ // TODO(burdon): Hide on change triggered immediately?
1395
+ // hideOnChange: true,
1345
1396
  hoverTime: 1e3
1346
1397
  }) : [],
1347
1398
  //
1348
- // Monitor cursor movement and text updates.
1349
- // TODO(burdon): Is there a better (finer grained) way to do this?
1399
+ // Track deleted ranges and update ranges for decorations.
1350
1400
  //
1351
- EditorView5.updateListener.of(({ view, state, changes }) => {
1352
- const cursorConverter3 = view.state.facet(CursorConverter);
1353
- {
1354
- let mod = false;
1355
- const { active, ranges } = state.field(commentsStateField);
1356
- changes.iterChanges((from, to, from2, to2) => {
1357
- ranges.forEach((range) => {
1358
- if (from2 === to2) {
1359
- const newRange = getRangeFromCursor(cursorConverter3, range.cursor);
1360
- if (!newRange || newRange.to - newRange.from === 0) {
1361
- log2.info("deleted comment", {
1362
- thread: range.id
1363
- }, {
1364
- F: __dxlog_file3,
1365
- L: 358,
1366
- S: void 0,
1367
- C: (f, a) => f(...a)
1368
- });
1369
- }
1370
- }
1371
- if (from <= range.to) {
1372
- const newRange = getRangeFromCursor(cursorConverter3, range.cursor);
1373
- Object.assign(range, newRange);
1374
- mod = true;
1401
+ EditorView6.updateListener.of(({ view, state, changes }) => {
1402
+ let mod = false;
1403
+ const { comments: comments2, ...value } = state.field(commentsState);
1404
+ changes.iterChanges((from, to, from2, to2) => {
1405
+ comments2.forEach(({ comment, range }) => {
1406
+ if (from2 === to2) {
1407
+ const newRange = Cursor.getRangeFromCursor(view.state, comment.cursor);
1408
+ if (!newRange || newRange.to - newRange.from === 0) {
1409
+ options.onDelete?.(comment.id);
1375
1410
  }
1376
- });
1411
+ }
1412
+ if (from <= range.to) {
1413
+ const newRange = Cursor.getRangeFromCursor(view.state, comment.cursor);
1414
+ Object.assign(range, newRange);
1415
+ mod = true;
1416
+ }
1417
+ });
1418
+ });
1419
+ if (mod) {
1420
+ view.dispatch({
1421
+ effects: setCommentState.of({
1422
+ comments: comments2,
1423
+ ...value
1424
+ })
1377
1425
  });
1378
- if (mod) {
1379
- view.dispatch({
1380
- effects: setCommentState.of({
1381
- active,
1382
- ranges
1383
- })
1384
- });
1385
- }
1386
1426
  }
1387
- {
1388
- const { head } = state.selection.main;
1389
- let min = Infinity;
1390
- const { active, closest, ranges } = state.field(commentsStateField);
1391
- const selected = {
1392
- active: void 0,
1393
- closest: void 0
1394
- };
1395
- ranges.forEach((comment) => {
1396
- const d = Math.min(Math.abs(head - comment.from), Math.abs(head - comment.to));
1397
- if (head >= comment.from && head <= comment.to) {
1398
- selected.active = comment.id;
1399
- }
1427
+ }),
1428
+ //
1429
+ // Track selection/proximity.
1430
+ //
1431
+ EditorView6.updateListener.of(({ view, state, changes }) => {
1432
+ let min = Infinity;
1433
+ const { selection: { active, closest }, comments: comments2 } = state.field(commentsState);
1434
+ const { head } = state.selection.main;
1435
+ const selection = {};
1436
+ comments2.forEach(({ comment, range }) => {
1437
+ if (head >= range.from && head <= range.to) {
1438
+ selection.active = comment.id;
1439
+ selection.closest = void 0;
1440
+ }
1441
+ if (!selection.active) {
1442
+ const d = Math.min(Math.abs(head - range.from), Math.abs(head - range.to));
1400
1443
  if (d < min) {
1401
- selected.closest = comment.id;
1444
+ selection.closest = comment.id;
1402
1445
  min = d;
1403
1446
  }
1404
- });
1405
- if (selected.active !== active || selected.closest !== closest) {
1406
- view.dispatch({
1407
- effects: setSelection.of(selected)
1408
- });
1409
- handleSelect({
1410
- ...selected,
1411
- ranges: ranges.map((range) => ({
1412
- ...range,
1413
- location: view.coordsAtPos(range.from)
1414
- }))
1415
- });
1416
1447
  }
1448
+ });
1449
+ if (selection.active !== active || selection.closest !== closest) {
1450
+ view.dispatch({
1451
+ effects: setSelection.of(selection)
1452
+ });
1453
+ handleSelect({
1454
+ selection,
1455
+ comments: comments2.map(({ comment, range }) => ({
1456
+ comment,
1457
+ range,
1458
+ location: view.coordsAtPos(range.from)
1459
+ }))
1460
+ });
1417
1461
  }
1418
- })
1462
+ }),
1463
+ options.onUpdate ? trackPastedComments(options.onUpdate) : []
1419
1464
  ];
1420
1465
  };
1421
- var getCursorFromRange = (cursorConverter3, range) => {
1422
- const from = cursorConverter3.toCursor(range.from);
1423
- const to = cursorConverter3.toCursor(range.to, -1);
1424
- return [
1425
- from,
1426
- to
1427
- ].join(":");
1428
- };
1429
- var getRangeFromCursor = (cursorConverter3, cursor) => {
1430
- const parts = cursor.split(":");
1431
- const from = cursorConverter3.fromCursor(parts[0]);
1432
- const to = cursorConverter3.fromCursor(parts[1]);
1433
- return from !== void 0 && to !== void 0 ? {
1434
- from,
1435
- to
1436
- } : void 0;
1466
+ var useComments = (view, comments2) => {
1467
+ useEffect2(() => {
1468
+ if (view && comments2) {
1469
+ view.dispatch({
1470
+ effects: setComments.of(comments2)
1471
+ });
1472
+ }
1473
+ }, [
1474
+ view,
1475
+ comments2
1476
+ ]);
1437
1477
  };
1438
1478
 
1439
1479
  // packages/ui/react-ui-editor/src/extensions/hr.ts
1440
- import { Decoration as Decoration4, EditorView as EditorView6, MatchDecorator as MatchDecorator2, ViewPlugin as ViewPlugin5, WidgetType as WidgetType3 } from "@codemirror/view";
1441
- var styles4 = EditorView6.baseTheme({
1480
+ import { syntaxTree } from "@codemirror/language";
1481
+ import { RangeSetBuilder } from "@codemirror/state";
1482
+ import { Decoration as Decoration4, EditorView as EditorView7, ViewPlugin as ViewPlugin3, WidgetType as WidgetType2 } from "@codemirror/view";
1483
+ var styles4 = EditorView7.baseTheme({
1442
1484
  "& .cm-hr": {
1443
- // TODO(burdon): ???
1444
1485
  // Note that block-level decorations should not have vertical margins,
1445
- borderBottom: `1px solid ${getToken("extend.colors.neutral.200")}`
1486
+ borderTop: `1px solid ${getToken("extend.colors.neutral.200")}`
1446
1487
  }
1447
1488
  });
1448
- var HorizontalRuleWidget = class extends WidgetType3 {
1449
- constructor(_pos) {
1450
- super();
1451
- this._pos = _pos;
1452
- }
1453
- eq(other) {
1454
- return this._pos === other._pos;
1455
- }
1456
- toDOM(view) {
1489
+ var HorizontalRuleWidget = class extends WidgetType2 {
1490
+ toDOM() {
1457
1491
  const el = document.createElement("div");
1458
1492
  el.className = "cm-hr";
1459
1493
  return el;
1460
1494
  }
1461
1495
  };
1462
- var placeholderMatcher = new MatchDecorator2({
1463
- regexp: /^---$/g,
1464
- decoration: (match, view, pos) => Decoration4.replace({
1465
- widget: new HorizontalRuleWidget(pos)
1466
- })
1496
+ var decoration = Decoration4.replace({
1497
+ widget: new HorizontalRuleWidget()
1467
1498
  });
1468
- var hr = () => [
1469
- styles4,
1470
- ViewPlugin5.fromClass(class {
1471
- constructor(view) {
1472
- this.rules = placeholderMatcher.createDeco(view);
1473
- }
1474
- update(update2) {
1475
- this.rules = placeholderMatcher.updateDeco(update2, this.rules);
1476
- }
1477
- }, {
1478
- decorations: (instance) => instance.rules,
1479
- // TODO(burdon): Is this really atomic (cursor can move into ---).
1480
- provide: (plugin) => EditorView6.atomicRanges.of((view) => {
1481
- return view.plugin(plugin)?.rules || Decoration4.none;
1499
+ var buildDecorations = (view) => {
1500
+ const builder = new RangeSetBuilder();
1501
+ const { state } = view;
1502
+ const cursor = state.selection.main.head;
1503
+ for (const { from, to } of view.visibleRanges) {
1504
+ syntaxTree(state).iterate({
1505
+ enter: (node) => {
1506
+ if (node.name === "HorizontalRule") {
1507
+ if (cursor <= node.from || cursor >= node.to) {
1508
+ builder.add(node.from, node.to, decoration);
1509
+ }
1510
+ }
1511
+ },
1512
+ from,
1513
+ to
1514
+ });
1515
+ }
1516
+ return builder.finish();
1517
+ };
1518
+ var hr = () => {
1519
+ return [
1520
+ styles4,
1521
+ ViewPlugin3.fromClass(class {
1522
+ constructor(view) {
1523
+ this.decorations = buildDecorations(view);
1524
+ }
1525
+ update(update2) {
1526
+ this.decorations = buildDecorations(update2.view);
1527
+ }
1528
+ }, {
1529
+ decorations: (v) => v.decorations
1482
1530
  })
1483
- })
1484
- ];
1531
+ ];
1532
+ };
1485
1533
 
1486
1534
  // packages/ui/react-ui-editor/src/extensions/image.ts
1487
- import { syntaxTree } from "@codemirror/language";
1535
+ import { syntaxTree as syntaxTree2 } from "@codemirror/language";
1488
1536
  import { StateField as StateField3 } from "@codemirror/state";
1489
- import { Decoration as Decoration5, EditorView as EditorView7, WidgetType as WidgetType4 } from "@codemirror/view";
1537
+ import { Decoration as Decoration5, EditorView as EditorView8, WidgetType as WidgetType3 } from "@codemirror/view";
1490
1538
  var image = (options = {}) => {
1491
1539
  return StateField3.define({
1492
1540
  create: (state) => {
1493
- return Decoration5.set(buildDecorations(0, state.doc.length, state));
1541
+ return Decoration5.set(buildDecorations2(0, state.doc.length, state));
1494
1542
  },
1495
1543
  update: (value, tr) => {
1496
1544
  if (!tr.docChanged && !tr.selection) {
@@ -1510,16 +1558,16 @@ var image = (options = {}) => {
1510
1558
  filterFrom: from,
1511
1559
  filterTo: to,
1512
1560
  filter: () => false,
1513
- add: buildDecorations(from, to, tr.state)
1561
+ add: buildDecorations2(from, to, tr.state)
1514
1562
  });
1515
1563
  },
1516
- provide: (field) => EditorView7.decorations.from(field)
1564
+ provide: (field) => EditorView8.decorations.from(field)
1517
1565
  });
1518
1566
  };
1519
- var buildDecorations = (from, to, state) => {
1567
+ var buildDecorations2 = (from, to, state) => {
1520
1568
  const decorations = [];
1521
1569
  const cursor = state.selection.main.head;
1522
- syntaxTree(state).iterate({
1570
+ syntaxTree2(state).iterate({
1523
1571
  enter: (node) => {
1524
1572
  if (node.name === "Image") {
1525
1573
  const urlNode = node.node.getChild("URL");
@@ -1538,7 +1586,7 @@ var buildDecorations = (from, to, state) => {
1538
1586
  });
1539
1587
  return decorations;
1540
1588
  };
1541
- var ImageWidget = class extends WidgetType4 {
1589
+ var ImageWidget = class extends WidgetType3 {
1542
1590
  constructor(_url) {
1543
1591
  super();
1544
1592
  this._url = _url;
@@ -1556,19 +1604,19 @@ var ImageWidget = class extends WidgetType4 {
1556
1604
  };
1557
1605
 
1558
1606
  // packages/ui/react-ui-editor/src/extensions/link.ts
1559
- import { syntaxTree as syntaxTree2 } from "@codemirror/language";
1560
- import { RangeSetBuilder } from "@codemirror/state";
1561
- import { Decoration as Decoration6, WidgetType as WidgetType5, hoverTooltip as hoverTooltip2, ViewPlugin as ViewPlugin6 } from "@codemirror/view";
1607
+ import { syntaxTree as syntaxTree3 } from "@codemirror/language";
1608
+ import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
1609
+ import { hoverTooltip as hoverTooltip2, Decoration as Decoration6, ViewPlugin as ViewPlugin4, WidgetType as WidgetType4 } from "@codemirror/view";
1562
1610
  import { tooltipContent } from "@dxos/react-ui-theme";
1563
1611
  var link = (options = {}) => {
1564
1612
  const extensions = [
1565
- ViewPlugin6.fromClass(class {
1613
+ ViewPlugin4.fromClass(class {
1566
1614
  constructor(view) {
1567
- this.decorations = buildDecorations2(view, options);
1615
+ this.decorations = buildDecorations3(view, options);
1568
1616
  }
1569
1617
  update(update2) {
1570
1618
  if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
1571
- this.decorations = buildDecorations2(update2.view, options);
1619
+ this.decorations = buildDecorations3(update2.view, options);
1572
1620
  }
1573
1621
  }
1574
1622
  }, {
@@ -1581,7 +1629,7 @@ var link = (options = {}) => {
1581
1629
  // https://codemirror.net/docs/ref/#view.hoverTooltip
1582
1630
  // https://github.com/codemirror/view/blob/main/src/tooltip.ts
1583
1631
  hoverTooltip2((view, pos, side) => {
1584
- const syntax = syntaxTree2(view.state).resolveInner(pos, side);
1632
+ const syntax = syntaxTree3(view.state).resolveInner(pos, side);
1585
1633
  let link2 = null;
1586
1634
  for (let i = 0, node = syntax; !link2 && node && i < 5; node = node.parent, i++) {
1587
1635
  link2 = node.name === "Link" ? node : null;
@@ -1613,7 +1661,7 @@ var link = (options = {}) => {
1613
1661
  }
1614
1662
  return extensions;
1615
1663
  };
1616
- var LinkButton = class extends WidgetType5 {
1664
+ var LinkButton = class extends WidgetType4 {
1617
1665
  constructor(_url, _onAttach) {
1618
1666
  super();
1619
1667
  this._url = _url;
@@ -1628,7 +1676,7 @@ var LinkButton = class extends WidgetType5 {
1628
1676
  return el;
1629
1677
  }
1630
1678
  };
1631
- var LinkText = class extends WidgetType5 {
1679
+ var LinkText = class extends WidgetType4 {
1632
1680
  constructor(_text, _url) {
1633
1681
  super();
1634
1682
  this._text = _text;
@@ -1657,12 +1705,12 @@ var LinkText = class extends WidgetType5 {
1657
1705
  return link2;
1658
1706
  }
1659
1707
  };
1660
- var buildDecorations2 = (view, options) => {
1661
- const builder = new RangeSetBuilder();
1708
+ var buildDecorations3 = (view, options) => {
1709
+ const builder = new RangeSetBuilder2();
1662
1710
  const { state } = view;
1663
1711
  const cursor = state.selection.main.head;
1664
1712
  for (const { from, to } of view.visibleRanges) {
1665
- syntaxTree2(state).iterate({
1713
+ syntaxTree3(state).iterate({
1666
1714
  enter: (node) => {
1667
1715
  if (node.name === "Link") {
1668
1716
  const marks2 = node.node.getChildren("LinkMark");
@@ -1693,14 +1741,14 @@ var buildDecorations2 = (view, options) => {
1693
1741
  };
1694
1742
 
1695
1743
  // packages/ui/react-ui-editor/src/extensions/listener.ts
1696
- import { EditorView as EditorView8 } from "@codemirror/view";
1744
+ import { EditorView as EditorView9 } from "@codemirror/view";
1697
1745
  var listener = ({ onFocus, onChange }) => {
1698
1746
  const extensions = [];
1699
- onFocus && extensions.push(EditorView8.focusChangeEffect.of((_, focused) => {
1747
+ onFocus && extensions.push(EditorView9.focusChangeEffect.of((_, focused) => {
1700
1748
  onFocus(focused);
1701
1749
  return null;
1702
1750
  }));
1703
- onChange && extensions.push(EditorView8.updateListener.of((update2) => {
1751
+ onChange && extensions.push(EditorView9.updateListener.of((update2) => {
1704
1752
  onChange(update2.state.doc.toString());
1705
1753
  }));
1706
1754
  return extensions;
@@ -1708,14 +1756,14 @@ var listener = ({ onFocus, onChange }) => {
1708
1756
 
1709
1757
  // packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
1710
1758
  import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
1711
- import { history, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
1759
+ import { history as history2, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
1712
1760
  import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
1713
1761
  import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
1714
1762
  import { languages } from "@codemirror/language-data";
1715
1763
  import { searchKeymap } from "@codemirror/search";
1716
1764
  import { EditorState } from "@codemirror/state";
1717
1765
  import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
1718
- import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView9, highlightActiveLine, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1766
+ import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView10, highlightActiveLine as highlightActiveLine2, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1719
1767
 
1720
1768
  // packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
1721
1769
  import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
@@ -1728,7 +1776,6 @@ var markdownTags = {
1728
1776
  CodeText: Tag.define(),
1729
1777
  EmphasisMark: Tag.define(),
1730
1778
  HeaderMark: Tag.define(),
1731
- // HorizontalRule: Tag.define(),
1732
1779
  InlineCode: Tag.define(),
1733
1780
  LinkLabel: Tag.define(),
1734
1781
  LinkReference: Tag.define(),
@@ -1892,12 +1939,6 @@ var markdownHighlightStyle = (readonly) => {
1892
1939
  ],
1893
1940
  class: blockquote
1894
1941
  },
1895
- // TODO(burdon): Replace with extension.
1896
- // {
1897
- // tag: [markdownTags.HorizontalRule],
1898
- // class: mx(horizontalRule, readonly && '-indent-[100rem]'),
1899
- // },
1900
- // TODO(burdon): Only if being edited.
1901
1942
  {
1902
1943
  tag: [
1903
1944
  markdownTags.TableCell
@@ -1917,17 +1958,17 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
1917
1958
  return [
1918
1959
  EditorState.allowMultipleSelections.of(true),
1919
1960
  EditorState.tabSize.of(2),
1920
- EditorView9.lineWrapping,
1921
- customKeymap(),
1961
+ EditorView10.lineWrapping,
1962
+ // https://github.com/codemirror/basic-setup
1922
1963
  bracketMatching2(),
1923
1964
  closeBrackets2(),
1924
1965
  crosshairCursor(),
1925
1966
  dropCursor(),
1926
1967
  drawSelection2(),
1927
- highlightActiveLine(),
1928
- history(),
1968
+ highlightActiveLine2(),
1969
+ history2(),
1929
1970
  indentOnInput(),
1930
- _placeholder && placeholder2(_placeholder),
1971
+ _placeholder ? placeholder2(_placeholder) : [],
1931
1972
  // Main extension.
1932
1973
  // https://github.com/codemirror/lang-markdown
1933
1974
  // https://codemirror.net/5/mode/markdown/index.html (demo).
@@ -1949,34 +1990,40 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
1949
1990
  // https://github.com/codemirror/theme-one-dark
1950
1991
  themeMode === "dark" ? syntaxHighlighting2(oneDarkHighlightStyle2) : syntaxHighlighting2(defaultHighlightStyle2),
1951
1992
  // Custom styles.
1952
- syntaxHighlighting2(markdownHighlightStyle(readonly))
1953
- ].filter(Boolean);
1954
- };
1955
- var customKeymap = () => keymap4.of([
1956
- // https://codemirror.net/docs/ref/#commands.indentWithTab
1957
- indentWithTab,
1958
- // https://codemirror.net/docs/ref/#commands.standardKeymap
1959
- ...standardKeymap,
1960
- // https://codemirror.net/docs/ref/#commands.historyKeymap
1961
- ...historyKeymap,
1962
- // https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
1963
- ...closeBracketsKeymap,
1964
- // https://codemirror.net/docs/ref/#search.searchKeymap
1965
- ...searchKeymap
1966
- ]);
1993
+ syntaxHighlighting2(markdownHighlightStyle(readonly)),
1994
+ keymap4.of([
1995
+ // https://codemirror.net/docs/ref/#commands.indentWithTab
1996
+ indentWithTab,
1997
+ // https://codemirror.net/docs/ref/#autocomplete.closeBracketsKeymap
1998
+ ...closeBracketsKeymap,
1999
+ // https://codemirror.net/docs/ref/#commands.historyKeymap
2000
+ ...historyKeymap,
2001
+ // https://codemirror.net/docs/ref/#search.searchKeymap
2002
+ ...searchKeymap,
2003
+ // https://codemirror.net/docs/ref/#commands.standardKeymap
2004
+ ...standardKeymap
2005
+ ])
2006
+ ];
2007
+ };
1967
2008
 
1968
2009
  // packages/ui/react-ui-editor/src/extensions/mention.ts
1969
2010
  import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
1970
2011
  var mention = ({ onSearch }) => {
1971
2012
  return autocompletion2({
2013
+ // TODO(burdon): Not working.
2014
+ activateOnTyping: true,
2015
+ // activateOnTypingDelay: 100,
2016
+ // selectOnOpen: true,
1972
2017
  closeOnBlur: false,
2018
+ // defaultKeymap: false,
2019
+ icons: false,
1973
2020
  override: [
1974
2021
  (context) => {
2022
+ console.log(context);
1975
2023
  const match = context.matchBefore(/@(\w+)?/);
1976
2024
  if (!match || match.from === match.to && !context.explicit) {
1977
2025
  return null;
1978
2026
  }
1979
- console.log(match);
1980
2027
  return {
1981
2028
  from: match.from,
1982
2029
  options: onSearch(match.text.slice(1).toLowerCase()).map((value) => ({
@@ -1988,19 +2035,24 @@ var mention = ({ onSearch }) => {
1988
2035
  });
1989
2036
  };
1990
2037
 
2038
+ // packages/ui/react-ui-editor/src/extensions/outliner.ts
2039
+ var outliner = (options = {}) => {
2040
+ return [];
2041
+ };
2042
+
1991
2043
  // packages/ui/react-ui-editor/src/extensions/table.ts
1992
- import { syntaxTree as syntaxTree3 } from "@codemirror/language";
1993
- import { RangeSetBuilder as RangeSetBuilder2, StateField as StateField4 } from "@codemirror/state";
1994
- import { Decoration as Decoration7, EditorView as EditorView10, WidgetType as WidgetType6 } from "@codemirror/view";
2044
+ import { syntaxTree as syntaxTree4 } from "@codemirror/language";
2045
+ import { RangeSetBuilder as RangeSetBuilder3, StateField as StateField4 } from "@codemirror/state";
2046
+ import { Decoration as Decoration7, EditorView as EditorView11, WidgetType as WidgetType5 } from "@codemirror/view";
1995
2047
  var table = (options = {}) => {
1996
2048
  return StateField4.define({
1997
2049
  create: (state) => update(state, options),
1998
2050
  update: (_, tr) => update(tr.state, options),
1999
- provide: (field) => EditorView10.decorations.from(field)
2051
+ provide: (field) => EditorView11.decorations.from(field)
2000
2052
  });
2001
2053
  };
2002
2054
  var update = (state, options) => {
2003
- const builder = new RangeSetBuilder2();
2055
+ const builder = new RangeSetBuilder3();
2004
2056
  const cursor = state.selection.main.head;
2005
2057
  const tables = [];
2006
2058
  const getTable = () => tables[tables.length - 1];
@@ -2008,7 +2060,7 @@ var update = (state, options) => {
2008
2060
  const table2 = getTable();
2009
2061
  return table2.rows?.[table2.rows.length - 1];
2010
2062
  };
2011
- syntaxTree3(state).iterate({
2063
+ syntaxTree4(state).iterate({
2012
2064
  enter: (node) => {
2013
2065
  switch (node.name) {
2014
2066
  case "Table": {
@@ -2049,7 +2101,7 @@ var update = (state, options) => {
2049
2101
  });
2050
2102
  return builder.finish();
2051
2103
  };
2052
- var TableWidget = class extends WidgetType6 {
2104
+ var TableWidget = class extends WidgetType5 {
2053
2105
  constructor(_table) {
2054
2106
  super();
2055
2107
  this._table = _table;
@@ -2087,85 +2139,98 @@ var TableWidget = class extends WidgetType6 {
2087
2139
  };
2088
2140
 
2089
2141
  // packages/ui/react-ui-editor/src/extensions/tasklist.ts
2090
- import { EditorView as EditorView11, Decoration as Decoration8, WidgetType as WidgetType7, MatchDecorator as MatchDecorator3, ViewPlugin as ViewPlugin7 } from "@codemirror/view";
2091
- var styles5 = EditorView11.baseTheme({
2092
- "& .cm-task-item": {
2093
- paddingLeft: "4px",
2094
- paddingRight: "8px"
2142
+ import { syntaxTree as syntaxTree5 } from "@codemirror/language";
2143
+ import { RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
2144
+ import { EditorView as EditorView12, Decoration as Decoration8, WidgetType as WidgetType6, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
2145
+ var styles5 = EditorView12.baseTheme({
2146
+ "& .cm-task": {
2147
+ color: getToken("extend.colors.blue.500")
2148
+ },
2149
+ "& .cm-task-checkbox": {
2150
+ marginLeft: "4px",
2151
+ marginRight: "4px"
2095
2152
  }
2096
2153
  });
2097
- var CheckboxWidget = class extends WidgetType7 {
2098
- constructor(_checked, _indent, _onCheck) {
2154
+ var CheckboxWidget = class extends WidgetType6 {
2155
+ constructor(_checked) {
2099
2156
  super();
2100
2157
  this._checked = _checked;
2101
- this._indent = _indent;
2102
- this._onCheck = _onCheck;
2103
2158
  }
2104
2159
  eq(other) {
2105
- return this._checked === other._checked && this._indent === other._indent;
2160
+ return this._checked === other._checked;
2106
2161
  }
2107
2162
  toDOM(view) {
2108
- const wrap = document.createElement("span");
2109
- wrap.className = "cm-task-item";
2110
- wrap.setAttribute("aria-hidden", "true");
2111
- wrap.style.setProperty("margin-left", this._indent * 24 + "px");
2112
- const input = wrap.appendChild(document.createElement("input"));
2163
+ const input = document.createElement("input");
2164
+ input.className = "cm-task-checkbox";
2113
2165
  input.type = "checkbox";
2114
2166
  input.checked = this._checked;
2115
- if (!this._onCheck) {
2167
+ if (view.state.readOnly) {
2116
2168
  input.setAttribute("disabled", "true");
2117
- }
2118
- if (this._onCheck) {
2119
- input.onchange = (event) => {
2120
- this._onCheck?.(event.target.checked);
2121
- return true;
2169
+ } else {
2170
+ input.onmousedown = (event) => {
2171
+ const pos = view.posAtDOM(input);
2172
+ const text = view.state.sliceDoc(pos, pos + 3);
2173
+ if (text === (this._checked ? "[x]" : "[ ]")) {
2174
+ view.dispatch({
2175
+ changes: {
2176
+ from: pos + 1,
2177
+ to: pos + 2,
2178
+ insert: this._checked ? " " : "x"
2179
+ }
2180
+ });
2181
+ event.preventDefault();
2182
+ }
2122
2183
  };
2123
2184
  }
2124
- return wrap;
2185
+ return input;
2125
2186
  }
2126
2187
  ignoreEvent() {
2127
2188
  return false;
2128
2189
  }
2129
2190
  };
2191
+ var checkedDecoration = Decoration8.replace({
2192
+ widget: new CheckboxWidget(true)
2193
+ });
2194
+ var uncheckedDecoration = Decoration8.replace({
2195
+ widget: new CheckboxWidget(false)
2196
+ });
2197
+ var buildDecorations4 = (view) => {
2198
+ const builder = new RangeSetBuilder4();
2199
+ const { state } = view;
2200
+ const cursor = state.selection.main.head;
2201
+ for (const { from, to } of view.visibleRanges) {
2202
+ syntaxTree5(state).iterate({
2203
+ enter: (node) => {
2204
+ if (node.name === "TaskMarker") {
2205
+ if (cursor < node.from || cursor > node.to) {
2206
+ const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
2207
+ builder.add(node.from - 2, node.from - 1, Decoration8.mark({
2208
+ class: "cm-task"
2209
+ }));
2210
+ builder.add(node.from, node.to, checked ? checkedDecoration : uncheckedDecoration);
2211
+ }
2212
+ }
2213
+ },
2214
+ from,
2215
+ to
2216
+ });
2217
+ }
2218
+ return builder.finish();
2219
+ };
2130
2220
  var tasklist = (options = {}) => {
2131
- const taskMatcher = new MatchDecorator3({
2132
- regexp: /^(\s*)- \[([ xX])\]\s/g,
2133
- decoration: (match, view, pos) => {
2134
- const indent = Math.floor(match[1].length / 2);
2135
- const checked = match[2] === "x" || match[2] === "X";
2136
- return Decoration8.replace({
2137
- widget: new CheckboxWidget(checked, indent, view.state.readOnly ? void 0 : (checked2) => {
2138
- const idx = pos + match[0].indexOf("[") + 1;
2139
- view.dispatch({
2140
- changes: {
2141
- from: idx,
2142
- to: idx + 1,
2143
- insert: checked2 ? "x" : " "
2144
- },
2145
- // TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
2146
- selection: {
2147
- anchor: idx + 3
2148
- }
2149
- });
2150
- })
2151
- });
2152
- }
2153
- });
2154
- const tasks = ViewPlugin7.fromClass(class {
2155
- constructor(view) {
2156
- this.tasks = taskMatcher.createDeco(view);
2157
- }
2158
- update(update2) {
2159
- this.tasks = taskMatcher.updateDeco(update2, this.tasks);
2160
- }
2161
- }, {
2162
- decorations: (value) => value.tasks,
2163
- provide: (plugin) => EditorView11.atomicRanges.of((view) => {
2164
- return view.plugin(plugin)?.tasks || Decoration8.none;
2165
- })
2166
- });
2167
2221
  return [
2168
- tasks,
2222
+ ViewPlugin5.fromClass(class {
2223
+ constructor(view) {
2224
+ this.decorations = buildDecorations4(view);
2225
+ }
2226
+ update(update2) {
2227
+ if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
2228
+ this.decorations = buildDecorations4(update2.view);
2229
+ }
2230
+ }
2231
+ }, {
2232
+ decorations: (v) => v.decorations
2233
+ }),
2169
2234
  styles5
2170
2235
  ];
2171
2236
  };
@@ -2244,7 +2309,7 @@ var cursorConverter2 = (text) => ({
2244
2309
 
2245
2310
  // packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
2246
2311
  var yjs = (content, awareness2) => [
2247
- CursorConverter.of(cursorConverter2(content)),
2312
+ Cursor.converter.of(cursorConverter2(content)),
2248
2313
  yCollab(content, awareness2)
2249
2314
  ];
2250
2315
 
@@ -2341,33 +2406,6 @@ var defaultTheme = {
2341
2406
  backgroundColor: get3(tokens, "extend.colors.yellow.700")
2342
2407
  },
2343
2408
  //
2344
- // collaboration
2345
- // TODO(burdon): Review classnames (YJS dependent?) Note: e2e tests depend on this class.
2346
- //
2347
- "&light .cm-ySelection, &light .cm-yLineSelection": {
2348
- mixBlendMode: "multiply"
2349
- },
2350
- "&dark .cm-ySelection, &dark .cm-yLineSelection": {
2351
- mixBlendMode: "screen"
2352
- },
2353
- ".cm-ySelectionInfo": {
2354
- padding: "2px 4px",
2355
- marginBlockStart: "-4px"
2356
- },
2357
- ".cm-ySelection, & .cm-selectionMatch": {
2358
- paddingBlockStart: ".15em",
2359
- paddingBlockEnd: ".15em"
2360
- },
2361
- ".cm-ySelectionCaret": {
2362
- display: "inline-block",
2363
- insetBlockStart: ".1em",
2364
- blockSize: "1.4em",
2365
- verticalAlign: "top"
2366
- },
2367
- ".cm-yLineSelection": {
2368
- margin: 0
2369
- },
2370
- //
2371
2409
  // link
2372
2410
  //
2373
2411
  ".cm-link": {
@@ -2404,13 +2442,6 @@ var defaultTheme = {
2404
2442
  textDecoration: "none"
2405
2443
  },
2406
2444
  //
2407
- // widgets
2408
- //
2409
- ".cm-widgetBuffer": {
2410
- display: "none",
2411
- height: 0
2412
- },
2413
- //
2414
2445
  // table
2415
2446
  //
2416
2447
  ".cm-table *": {
@@ -2441,27 +2472,17 @@ var defaultTheme = {
2441
2472
  },
2442
2473
  //
2443
2474
  // font size
2444
- // TODO(thure): This appears to be the best or only way to set selection caret heights, but it's far more verbose than it needs to be.
2475
+ // TODO(thure): This appears to be the best or only way to set selection caret heights,
2476
+ // but it's far more verbose than it needs to be.
2445
2477
  //
2446
- ...Object.keys(get3(tokens, "extend.fontSize", {})).reduce((acc, fontSize) => {
2447
- const height = get3(tokens, [
2448
- "extend",
2449
- "fontSize",
2450
- fontSize,
2451
- 1,
2452
- "lineHeight"
2453
- ]);
2454
- acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = {
2455
- height
2456
- };
2457
- acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = {
2458
- height
2459
- };
2460
- acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = {
2461
- height
2462
- };
2463
- return acc;
2464
- }, {}),
2478
+ // ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
2479
+ // const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
2480
+ //
2481
+ // acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
2482
+ // acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
2483
+ // acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
2484
+ // return acc;
2485
+ // }, {}),
2465
2486
  /**
2466
2487
  * Panels
2467
2488
  * TODO(burdon): Needs styling attention (esp. dark mode).
@@ -2512,7 +2533,9 @@ var textTheme = {
2512
2533
  }
2513
2534
  };
2514
2535
  var markdownTheme = {
2515
- // NOTE: Must leave base font family as is (i.e., monospace) due to fenced code blocks.
2536
+ ".cm-scroller": {
2537
+ fontFamily: get3(tokens, "fontFamily.body", []).join(",")
2538
+ },
2516
2539
  ".cm-placeholder": {
2517
2540
  fontFamily: get3(tokens, "fontFamily.body", []).join(",")
2518
2541
  }
@@ -2527,95 +2550,91 @@ var codeTheme = {
2527
2550
  };
2528
2551
 
2529
2552
  // packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
2553
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx";
2530
2554
  var EditorModes = [
2531
2555
  "default",
2532
2556
  "vim"
2533
2557
  ];
2534
- var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: comments2, extensions = [], editorMode, slots = defaultSlots }, forwardedRef) => {
2535
- const { themeMode } = useThemeContext();
2558
+ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autofocus, scrollTo, selection, editorMode, theme, slots = defaultSlots, extensions = [] }, forwardedRef) => {
2536
2559
  const tabsterDOMAttribute = useFocusableGroup({
2537
2560
  tabBehavior: "limited"
2538
2561
  });
2539
- const [root, setRoot] = useState(null);
2540
- const [{ state = void 0, view = void 0 } = {}, setEditor] = useState();
2541
- useImperativeHandle(forwardedRef, () => ({
2542
- root,
2543
- state,
2562
+ const { themeMode } = useThemeContext2();
2563
+ const rootRef = useRef(null);
2564
+ const [view, setView] = useState(null);
2565
+ useImperativeHandle(forwardedRef, () => view, [
2544
2566
  view
2545
- }), [
2546
- view,
2547
- state,
2548
- root
2549
- ]);
2550
- const { awareness: awareness2, peer } = model;
2551
- useEffect(() => {
2552
- if (awareness2 && peer) {
2553
- awareness2.setLocalStateField("user", {
2554
- name: peer.name ?? generateName(peer.id),
2555
- color: getColorForValue({
2556
- value: peer.id,
2557
- type: "color"
2558
- }),
2559
- colorLight: getColorForValue({
2560
- value: peer.id,
2561
- themeMode,
2562
- type: "highlight"
2563
- })
2564
- });
2565
- }
2566
- }, [
2567
- awareness2,
2568
- peer,
2569
- themeMode
2570
2567
  ]);
2571
- useEffect(() => {
2572
- if (view && comments2?.length) {
2573
- view.dispatch({
2574
- effects: setCommentRange.of({
2575
- model,
2576
- comments: comments2
2577
- })
2578
- });
2568
+ useEffect3(() => {
2569
+ if (autofocus) {
2570
+ view?.focus();
2579
2571
  }
2580
2572
  }, [
2581
2573
  view,
2582
- comments2
2574
+ autofocus
2583
2575
  ]);
2584
- useEffect(() => {
2585
- if (!root) {
2576
+ useAwareness(model);
2577
+ useEffect3(() => {
2578
+ if (!model || !rootRef.current) {
2586
2579
  return;
2587
2580
  }
2588
- const state2 = EditorState2.create({
2581
+ const state = EditorState2.create({
2589
2582
  doc: model.text(),
2583
+ selection,
2590
2584
  extensions: [
2591
- readonly && EditorState2.readOnly.of(readonly),
2592
- // TODO(burdon): Factor out VIM mode? (manage via MarkdownPlugin).
2593
- editorMode === "vim" && vim(),
2585
+ // TODO(burdon): Doesn't catch errors in keymap functions.
2586
+ EditorView13.exceptionSink.of((err) => {
2587
+ log2.catch(err, void 0, {
2588
+ F: __dxlog_file4,
2589
+ L: 114,
2590
+ S: void 0,
2591
+ C: (f, a) => f(...a)
2592
+ });
2593
+ }),
2594
2594
  // Theme.
2595
- // TODO(burdon): Make theme configurable.
2596
- EditorView12.baseTheme(defaultTheme),
2597
- EditorView12.theme(slots?.editor?.theme ?? {}),
2598
- EditorView12.darkTheme.of(themeMode === "dark"),
2595
+ // TODO(burdon): Make configurable.
2596
+ EditorView13.baseTheme(defaultTheme),
2597
+ EditorView13.theme(theme ?? {}),
2598
+ EditorView13.darkTheme.of(themeMode === "dark"),
2599
+ EditorView13.editorAttributes.of({
2600
+ class: slots.editor?.className ?? ""
2601
+ }),
2602
+ EditorView13.contentAttributes.of({
2603
+ class: slots.content?.className ?? ""
2604
+ }),
2605
+ // State.
2606
+ EditorState2.readOnly.of(!!readonly),
2599
2607
  // Storage and replication.
2608
+ // NOTE: This must come before user extensions.
2600
2609
  model.extension,
2610
+ // TODO(burdon): Factor out (requires special handling for Escape/focus).
2611
+ editorMode === "vim" && vim(),
2601
2612
  // Custom.
2602
2613
  ...extensions
2603
2614
  ].filter(Boolean)
2604
2615
  });
2605
- view?.destroy();
2606
- setEditor({
2607
- state: state2,
2608
- view: new EditorView12({
2609
- state: state2,
2610
- parent: root
2611
- })
2616
+ const newView = new EditorView13({
2617
+ state,
2618
+ parent: rootRef.current,
2619
+ scrollTo,
2620
+ // NOTE: Uncomment to debug/monitor all transactions.
2621
+ // https://codemirror.net/docs/ref/#view.EditorView.dispatch
2622
+ dispatchTransactions: (trs, view2) => {
2623
+ view2.update(trs);
2624
+ const debug = false;
2625
+ if (debug) {
2626
+ logChanges(trs);
2627
+ }
2628
+ }
2612
2629
  });
2630
+ view?.destroy();
2631
+ setView(newView);
2613
2632
  return () => {
2614
- view?.destroy();
2615
- setEditor(void 0);
2633
+ newView?.destroy();
2634
+ setView(null);
2616
2635
  };
2617
2636
  }, [
2618
- root,
2637
+ rootRef,
2619
2638
  model,
2620
2639
  readonly,
2621
2640
  editorMode,
@@ -2625,11 +2644,13 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: co
2625
2644
  const { key, altKey, shiftKey, metaKey, ctrlKey } = event;
2626
2645
  switch (key) {
2627
2646
  case "Enter": {
2628
- view?.contentDOM.focus();
2647
+ view?.focus();
2629
2648
  break;
2630
2649
  }
2631
2650
  case "Escape": {
2632
- editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey) && root?.focus();
2651
+ if (editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey)) {
2652
+ rootRef.current?.focus();
2653
+ }
2633
2654
  break;
2634
2655
  }
2635
2656
  }
@@ -2639,65 +2660,66 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, comments: co
2639
2660
  ]);
2640
2661
  return /* @__PURE__ */ React.createElement("div", {
2641
2662
  key: model.id,
2642
- ref: setRoot,
2663
+ role: "none",
2643
2664
  tabIndex: 0,
2644
- ...slots?.root,
2665
+ onKeyUp: handleKeyUp,
2666
+ ...slots.root,
2645
2667
  ...editorMode !== "vim" && tabsterDOMAttribute,
2646
- onKeyUp: handleKeyUp
2668
+ ref: rootRef
2647
2669
  });
2648
2670
  });
2649
- var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots: _slots, ...props }, forwardedRef) => {
2650
- const { themeMode } = useThemeContext();
2651
- const slots = defaultsDeep2({}, _slots, defaultTextSlots);
2671
+ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, multiline, theme = textTheme, slots, extensions = [], ...props }, forwardedRef) => {
2672
+ const { themeMode } = useThemeContext2();
2673
+ const updatedSlots = defaultsDeep2({}, slots, defaultTextSlots);
2652
2674
  return /* @__PURE__ */ React.createElement(BaseTextEditor, {
2653
2675
  ref: forwardedRef,
2654
2676
  readonly,
2655
2677
  extensions: [
2656
2678
  basicBundle({
2657
- readonly,
2658
2679
  themeMode,
2659
- placeholder: slots?.editor?.placeholder
2680
+ placeholder: placeholder3,
2681
+ multiline
2660
2682
  }),
2661
2683
  ...extensions
2662
2684
  ],
2663
- slots,
2685
+ theme,
2686
+ slots: updatedSlots,
2664
2687
  ...props
2665
2688
  });
2666
2689
  });
2667
- var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, extensions = [], slots: _slots, ...props }, forwardedRef) => {
2668
- const { themeMode } = useThemeContext();
2669
- const slots = defaultsDeep2({}, _slots, defaultMarkdownSlots);
2690
+ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, theme = markdownTheme, slots, extensions = [], ...props }, forwardedRef) => {
2691
+ const { themeMode } = useThemeContext2();
2692
+ const updatedSlots = defaultsDeep2({}, slots, defaultMarkdownSlots);
2670
2693
  return /* @__PURE__ */ React.createElement(BaseTextEditor, {
2671
2694
  ref: forwardedRef,
2672
2695
  readonly,
2673
2696
  extensions: [
2674
2697
  markdownBundle({
2675
- readonly,
2676
2698
  themeMode,
2677
- placeholder: slots?.editor?.placeholder
2699
+ readonly,
2700
+ placeholder: placeholder3
2678
2701
  }),
2679
2702
  ...extensions
2680
2703
  ],
2681
- slots,
2704
+ theme,
2705
+ slots: updatedSlots,
2682
2706
  ...props
2683
2707
  });
2684
2708
  });
2685
2709
  var defaultSlots = {
2686
2710
  root: {
2687
- className: mx3("p-2", inputSurface)
2711
+ // TODO(burdon): Add focusRing by default/as property?
2712
+ className: mx3("flex flex-col grow overflow-y-auto", inputSurface)
2713
+ },
2714
+ editor: {
2715
+ className: "h-full p-2"
2688
2716
  }
2689
2717
  };
2690
2718
  var defaultTextSlots = {
2691
- ...defaultSlots,
2692
- editor: {
2693
- theme: textTheme
2694
- }
2719
+ ...defaultSlots
2695
2720
  };
2696
2721
  var defaultMarkdownSlots = {
2697
- ...defaultSlots,
2698
- editor: {
2699
- theme: markdownTheme
2700
- }
2722
+ ...defaultSlots
2701
2723
  };
2702
2724
 
2703
2725
  // packages/ui/react-ui-editor/src/hooks/automerge.ts
@@ -2710,7 +2732,7 @@ import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
2710
2732
  import { Context as Context2 } from "@dxos/context";
2711
2733
  import { invariant as invariant3 } from "@dxos/invariant";
2712
2734
  import { log as log3 } from "@dxos/log";
2713
- var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
2735
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
2714
2736
  var DEBOUNCE_INTERVAL = 100;
2715
2737
  var SpaceAwarenessProvider = class {
2716
2738
  constructor(params) {
@@ -2751,7 +2773,7 @@ var SpaceAwarenessProvider = class {
2751
2773
  log3.debug("failed to query awareness", {
2752
2774
  err
2753
2775
  }, {
2754
- F: __dxlog_file4,
2776
+ F: __dxlog_file5,
2755
2777
  L: 85,
2756
2778
  S: this,
2757
2779
  C: (f, a) => f(...a)
@@ -2765,7 +2787,7 @@ var SpaceAwarenessProvider = class {
2765
2787
  }
2766
2788
  update(position) {
2767
2789
  invariant3(this._postTask, void 0, {
2768
- F: __dxlog_file4,
2790
+ F: __dxlog_file5,
2769
2791
  L: 96,
2770
2792
  S: this,
2771
2793
  A: [
@@ -2785,7 +2807,7 @@ var SpaceAwarenessProvider = class {
2785
2807
  }
2786
2808
  _handleQueryMessage() {
2787
2809
  invariant3(this._postTask, void 0, {
2788
- F: __dxlog_file4,
2810
+ F: __dxlog_file5,
2789
2811
  L: 111,
2790
2812
  S: this,
2791
2813
  A: [
@@ -2797,7 +2819,7 @@ var SpaceAwarenessProvider = class {
2797
2819
  }
2798
2820
  _handlePostMessage(message) {
2799
2821
  invariant3(message.kind === "post", void 0, {
2800
- F: __dxlog_file4,
2822
+ F: __dxlog_file5,
2801
2823
  L: 116,
2802
2824
  S: this,
2803
2825
  A: [
@@ -2810,25 +2832,63 @@ var SpaceAwarenessProvider = class {
2810
2832
  }
2811
2833
  };
2812
2834
 
2813
- // packages/ui/react-ui-editor/src/hooks/useTextModel.ts
2835
+ // packages/ui/react-ui-editor/src/hooks/defs.ts
2814
2836
  import { StateField as StateField5 } from "@codemirror/state";
2815
- import { useEffect as useEffect2, useState as useState2 } from "react";
2816
- import { isAutomergeObject } from "@dxos/react-client/echo";
2837
+ var modelState = StateField5.define({
2838
+ create: () => void 0,
2839
+ update: (model) => model
2840
+ });
2841
+
2842
+ // packages/ui/react-ui-editor/src/hooks/automerge.ts
2843
+ var createAutomergeModel = ({ space, identity, text }) => {
2844
+ const obj = text;
2845
+ const doc = getRawDoc(obj, [
2846
+ obj.field
2847
+ ]);
2848
+ const awarenessProvider = space && new SpaceAwarenessProvider({
2849
+ space,
2850
+ channel: `automerge.awareness.${obj.id}`,
2851
+ info: {
2852
+ displayName: identity?.profile?.displayName ?? "",
2853
+ color: cursorColor.color,
2854
+ lightColor: cursorColor.light
2855
+ },
2856
+ peerId: identity?.identityKey.toHex() ?? "Anonymous"
2857
+ });
2858
+ const model = {
2859
+ id: obj.id,
2860
+ content: doc,
2861
+ text: () => get4(doc.handle.docSync(), doc.path),
2862
+ // TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
2863
+ extension: [
2864
+ modelState.init(() => model),
2865
+ automerge3({
2866
+ handle: doc.handle,
2867
+ path: doc.path
2868
+ }),
2869
+ awarenessProvider && AwarenessProvider.of(awarenessProvider),
2870
+ awareness()
2871
+ ].filter(isNotNullOrUndefined),
2872
+ peer: identity ? {
2873
+ id: identity.identityKey.toHex(),
2874
+ name: identity.profile?.displayName
2875
+ } : void 0
2876
+ };
2877
+ return model;
2878
+ };
2817
2879
 
2818
2880
  // packages/ui/react-ui-editor/src/hooks/yjs.ts
2819
2881
  import * as decoding from "lib0/decoding";
2820
2882
  import * as encoding from "lib0/encoding";
2821
2883
  import { Observable } from "lib0/observable";
2822
2884
  import * as YP from "y-protocols/awareness";
2823
- import * as Y2 from "yjs";
2824
2885
  import { invariant as invariant4 } from "@dxos/invariant";
2825
2886
  import { log as log4 } from "@dxos/log";
2826
- import { arrayToString as arrayToString2, stringToArray as stringToArray2 } from "@dxos/util";
2827
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/yjs.ts";
2887
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/yjs.ts";
2828
2888
  var createYjsModel = ({ identity, space, text }) => {
2829
2889
  invariant4(text?.doc && text?.content, void 0, {
2830
- F: __dxlog_file5,
2831
- L: 23,
2890
+ F: __dxlog_file6,
2891
+ L: 22,
2832
2892
  S: void 0,
2833
2893
  A: [
2834
2894
  "text?.doc && text?.content",
@@ -2844,34 +2904,6 @@ var createYjsModel = ({ identity, space, text }) => {
2844
2904
  id: text.doc.guid,
2845
2905
  content: text.content,
2846
2906
  text: () => text.content.toString(),
2847
- // https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
2848
- // TODO(dmaretskyi): Refactor as cursor-converter.
2849
- getCursorFromRange: (range) => {
2850
- const from = Y2.encodeRelativePosition(Y2.createRelativePositionFromTypeIndex(text.content, range.from));
2851
- const to = Y2.encodeRelativePosition(Y2.createRelativePositionFromTypeIndex(text.content, range.to, -1));
2852
- return [
2853
- arrayToString2(from),
2854
- arrayToString2(to)
2855
- ].join(":");
2856
- },
2857
- getRangeFromCursor: (cursor) => {
2858
- invariant4(text.doc, void 0, {
2859
- F: __dxlog_file5,
2860
- L: 40,
2861
- S: void 0,
2862
- A: [
2863
- "text.doc",
2864
- ""
2865
- ]
2866
- });
2867
- const parts = cursor.split(":");
2868
- const from = Y2.createAbsolutePositionFromRelativePosition(Y2.decodeRelativePosition(stringToArray2(parts[0])), text.doc);
2869
- const to = Y2.createAbsolutePositionFromRelativePosition(Y2.decodeRelativePosition(stringToArray2(parts[1])), text.doc);
2870
- return from && to ? {
2871
- from: from.index,
2872
- to: to.index
2873
- } : void 0;
2874
- },
2875
2907
  extension: [
2876
2908
  modelState.init(() => model),
2877
2909
  yjs(text.content, provider?.awareness)
@@ -2920,8 +2952,8 @@ var YAwarenessProvider = class extends Observable {
2920
2952
  removed,
2921
2953
  origin
2922
2954
  }, {
2923
- F: __dxlog_file5,
2924
- L: 122,
2955
+ F: __dxlog_file6,
2956
+ L: 101,
2925
2957
  S: this,
2926
2958
  C: (f, a) => f(...a)
2927
2959
  });
@@ -2933,8 +2965,8 @@ var YAwarenessProvider = class extends Observable {
2933
2965
  }
2934
2966
  _handleSpaceMessage({ payload }) {
2935
2967
  log4("space message", payload, {
2936
- F: __dxlog_file5,
2937
- L: 131,
2968
+ F: __dxlog_file6,
2969
+ L: 110,
2938
2970
  S: this,
2939
2971
  C: (f, a) => f(...a)
2940
2972
  });
@@ -2978,14 +3010,12 @@ var YAwarenessProvider = class extends Observable {
2978
3010
  };
2979
3011
 
2980
3012
  // packages/ui/react-ui-editor/src/hooks/useTextModel.ts
2981
- var modelState = StateField5.define({
2982
- create: () => void 0,
2983
- update: (model) => model
2984
- });
3013
+ import { useEffect as useEffect4, useState as useState2 } from "react";
3014
+ import { isAutomergeObject } from "@dxos/react-client/echo";
2985
3015
  var useTextModel = (props) => {
2986
3016
  const { identity, space, text } = props;
2987
- const [model, setModel] = useState2(() => createModel(props));
2988
- useEffect2(() => setModel(createModel(props)), [
3017
+ const [model, setModel] = useState2();
3018
+ useEffect4(() => setModel(createModel(props)), [
2989
3019
  identity,
2990
3020
  space,
2991
3021
  text
@@ -3002,48 +3032,10 @@ var createModel = (props) => {
3002
3032
  return void 0;
3003
3033
  }
3004
3034
  };
3005
-
3006
- // packages/ui/react-ui-editor/src/hooks/automerge.ts
3007
- var createAutomergeModel = ({ space, identity, text }) => {
3008
- const obj = text;
3009
- const doc = getRawDoc(obj, [
3010
- obj.field
3011
- ]);
3012
- const awarenessProvider = space && new SpaceAwarenessProvider({
3013
- space,
3014
- channel: `automerge.awareness.${obj.id}`,
3015
- info: {
3016
- displayName: identity?.profile?.displayName ?? "",
3017
- color: cursorColor.color,
3018
- lightColor: cursorColor.light
3019
- },
3020
- peerId: identity?.identityKey.toHex() ?? "Anonymous"
3021
- });
3022
- const model = {
3023
- id: obj.id,
3024
- content: doc,
3025
- text: () => get4(doc.handle.docSync(), doc.path),
3026
- // TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
3027
- extension: [
3028
- modelState.init(() => model),
3029
- automerge3({
3030
- handle: doc.handle,
3031
- path: doc.path
3032
- }),
3033
- awarenessProvider && AwarenessProvider.of(awarenessProvider),
3034
- awareness()
3035
- ].filter(isNotNullOrUndefined),
3036
- peer: identity ? {
3037
- id: identity.identityKey.toHex(),
3038
- name: identity.profile?.displayName
3039
- } : void 0
3040
- };
3041
- return model;
3042
- };
3043
3035
  export {
3044
3036
  AwarenessProvider,
3045
3037
  BaseTextEditor,
3046
- CursorConverter,
3038
+ Cursor,
3047
3039
  Doc,
3048
3040
  EditorModes,
3049
3041
  MarkdownEditor,
@@ -3065,7 +3057,6 @@ export {
3065
3057
  comments,
3066
3058
  createAutomergeModel,
3067
3059
  createYjsModel,
3068
- cursorConverter,
3069
3060
  defaultMarkdownSlots,
3070
3061
  defaultOptions,
3071
3062
  defaultSlots,
@@ -3076,6 +3067,7 @@ export {
3076
3067
  image,
3077
3068
  link,
3078
3069
  listener,
3070
+ logChanges,
3079
3071
  markdownBundle,
3080
3072
  markdownHighlightStyle,
3081
3073
  markdownTags,
@@ -3083,7 +3075,8 @@ export {
3083
3075
  markdownTheme,
3084
3076
  mention,
3085
3077
  modelState,
3086
- setCommentRange,
3078
+ outliner,
3079
+ setComments,
3087
3080
  setFocus,
3088
3081
  setSelection,
3089
3082
  table,
@@ -3091,6 +3084,8 @@ export {
3091
3084
  tasklist,
3092
3085
  textTheme,
3093
3086
  typewriter,
3087
+ useAwareness,
3088
+ useComments,
3094
3089
  useTextModel,
3095
3090
  yjs
3096
3091
  };