@dxos/react-ui-editor 0.4.1 → 0.4.2-main.16babdb

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.
@@ -8,14 +8,114 @@ import { tags as tags2 } from "@lezer/highlight";
8
8
 
9
9
  // packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
10
10
  import { EditorState as EditorState2 } from "@codemirror/state";
11
- import { EditorView as EditorView14 } from "@codemirror/view";
11
+ import { EditorView as EditorView15 } from "@codemirror/view";
12
12
  import { vim } from "@replit/codemirror-vim";
13
13
  import defaultsDeep2 from "lodash.defaultsdeep";
14
14
  import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState as useState2 } from "react";
15
15
  import { log as log2 } from "@dxos/log";
16
16
  import { useThemeContext } from "@dxos/react-ui";
17
17
  import { focusRing, mx as mx3 } from "@dxos/react-ui-theme";
18
- import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
18
+ import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
19
+
20
+ // packages/ui/react-ui-editor/src/extensions/annotations.ts
21
+ import { StateField } from "@codemirror/state";
22
+ import { Decoration, EditorView } from "@codemirror/view";
23
+ import { isNotFalsy } from "@dxos/util";
24
+
25
+ // packages/ui/react-ui-editor/src/extensions/cursor.ts
26
+ import { Facet } from "@codemirror/state";
27
+ var defaultCursorConverter = {
28
+ toCursor: (position) => position.toString(),
29
+ fromCursor: (cursor) => parseInt(cursor)
30
+ };
31
+ var Cursor = class _Cursor {
32
+ static {
33
+ this.converter = Facet.define({
34
+ combine: (providers) => providers[0] ?? defaultCursorConverter
35
+ });
36
+ }
37
+ static {
38
+ this.getCursorFromRange = (state, range) => {
39
+ const cursorConverter2 = state.facet(_Cursor.converter);
40
+ const from = cursorConverter2.toCursor(range.from);
41
+ const to = cursorConverter2.toCursor(range.to, -1);
42
+ return [
43
+ from,
44
+ to
45
+ ].join(":");
46
+ };
47
+ }
48
+ static {
49
+ this.getRangeFromCursor = (state, cursor) => {
50
+ const cursorConverter2 = state.facet(_Cursor.converter);
51
+ const parts = cursor.split(":");
52
+ const from = cursorConverter2.fromCursor(parts[0]);
53
+ const to = cursorConverter2.fromCursor(parts[1]);
54
+ return from !== void 0 && to !== void 0 ? {
55
+ from,
56
+ to
57
+ } : void 0;
58
+ };
59
+ }
60
+ };
61
+
62
+ // packages/ui/react-ui-editor/src/extensions/annotations.ts
63
+ var annotationMark = Decoration.mark({
64
+ class: "cm-annotation"
65
+ });
66
+ var annotations = (options = {}) => {
67
+ const match = (state) => {
68
+ const annotations2 = [];
69
+ const text = state.doc.toString();
70
+ if (options.match) {
71
+ const matches = text.matchAll(options.match);
72
+ for (const match2 of matches) {
73
+ const from = match2.index;
74
+ const to = from + match2[0].length;
75
+ const cursor = Cursor.getCursorFromRange(state, {
76
+ from,
77
+ to
78
+ });
79
+ annotations2.push({
80
+ cursor
81
+ });
82
+ }
83
+ }
84
+ return annotations2;
85
+ };
86
+ const annotationsState = StateField.define({
87
+ create: (state) => {
88
+ return match(state);
89
+ },
90
+ update: (value, tr) => {
91
+ if (!tr.changes.empty) {
92
+ return match(tr.state);
93
+ }
94
+ return value;
95
+ }
96
+ });
97
+ return [
98
+ annotationsState,
99
+ EditorView.decorations.compute([
100
+ annotationsState
101
+ ], (state) => {
102
+ const annotations2 = state.field(annotationsState);
103
+ const decorations = annotations2.map((annotation) => {
104
+ const range = Cursor.getRangeFromCursor(state, annotation.cursor);
105
+ return range && annotationMark.range(range.from, range.to);
106
+ }).filter(isNotFalsy);
107
+ return Decoration.set(decorations);
108
+ }),
109
+ styles
110
+ ];
111
+ };
112
+ var styles = EditorView.baseTheme({
113
+ ".cm-annotation": {
114
+ textDecoration: "underline",
115
+ textDecorationStyle: "wavy",
116
+ textDecorationColor: "red"
117
+ }
118
+ });
19
119
 
20
120
  // packages/ui/react-ui-editor/src/extensions/autocomplete.ts
21
121
  import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
@@ -55,8 +155,8 @@ var autocomplete = ({ onSearch }) => {
55
155
 
56
156
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
57
157
  import { invertedEffects } from "@codemirror/commands";
58
- import { StateField } from "@codemirror/state";
59
- import { EditorView, ViewPlugin } from "@codemirror/view";
158
+ import { StateField as StateField2 } from "@codemirror/state";
159
+ import { EditorView as EditorView2, ViewPlugin } from "@codemirror/view";
60
160
  import { next as A4 } from "@dxos/automerge/automerge";
61
161
 
62
162
  // packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
@@ -291,46 +391,9 @@ var PatchSemaphore = class {
291
391
  }
292
392
  };
293
393
 
294
- // packages/ui/react-ui-editor/src/extensions/cursor.ts
295
- import { Facet } from "@codemirror/state";
296
- var defaultCursorConverter = {
297
- toCursor: (position) => position.toString(),
298
- fromCursor: (cursor) => parseInt(cursor)
299
- };
300
- var Cursor = class _Cursor {
301
- static {
302
- this.converter = Facet.define({
303
- combine: (providers) => providers[0] ?? defaultCursorConverter
304
- });
305
- }
306
- static {
307
- this.getCursorFromRange = (state, range) => {
308
- const cursorConverter2 = state.facet(_Cursor.converter);
309
- const from = cursorConverter2.toCursor(range.from);
310
- const to = cursorConverter2.toCursor(range.to, -1);
311
- return [
312
- from,
313
- to
314
- ].join(":");
315
- };
316
- }
317
- static {
318
- this.getRangeFromCursor = (state, cursor) => {
319
- const cursorConverter2 = state.facet(_Cursor.converter);
320
- const parts = cursor.split(":");
321
- const from = cursorConverter2.fromCursor(parts[0]);
322
- const to = cursorConverter2.fromCursor(parts[1]);
323
- return from !== void 0 && to !== void 0 ? {
324
- from,
325
- to
326
- } : void 0;
327
- };
328
- }
329
- };
330
-
331
394
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
332
395
  var automerge = ({ handle, path }) => {
333
- const syncState = StateField.define({
396
+ const syncState = StateField2.define({
334
397
  create: () => ({
335
398
  path: path.slice(),
336
399
  lastHeads: A4.getHeads(handle.docSync()),
@@ -377,7 +440,7 @@ var automerge = ({ handle, path }) => {
377
440
  }
378
441
  }),
379
442
  // Reconcile local updates.
380
- EditorView.updateListener.of(({ view, changes }) => {
443
+ EditorView2.updateListener.of(({ view, changes }) => {
381
444
  if (!changes.empty) {
382
445
  semaphore.reconcile(view);
383
446
  }
@@ -398,7 +461,7 @@ var automerge = ({ handle, path }) => {
398
461
 
399
462
  // packages/ui/react-ui-editor/src/extensions/awareness.ts
400
463
  import { Annotation as Annotation2, Facet as Facet2, RangeSet } from "@codemirror/state";
401
- import { Decoration, EditorView as EditorView2, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
464
+ import { Decoration as Decoration2, EditorView as EditorView3, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
402
465
  import { Event } from "@dxos/async";
403
466
  import { Context } from "@dxos/context";
404
467
  var dummyProvider = {
@@ -421,7 +484,7 @@ var awareness = (provider = dummyProvider) => {
421
484
  ViewPlugin2.fromClass(RemoteSelectionsDecorator, {
422
485
  decorations: (value) => value.decorations
423
486
  }),
424
- styles
487
+ styles2
425
488
  ];
426
489
  };
427
490
  var RemoteSelectionsDecorator = class {
@@ -481,7 +544,7 @@ var RemoteSelectionsDecorator = class {
481
544
  decorations.push({
482
545
  from: start,
483
546
  to: end,
484
- value: Decoration.mark({
547
+ value: Decoration2.mark({
485
548
  attributes: {
486
549
  style: `background-color: ${lightColor}`
487
550
  },
@@ -492,7 +555,7 @@ var RemoteSelectionsDecorator = class {
492
555
  decorations.push({
493
556
  from: start,
494
557
  to: startLine.from + startLine.length,
495
- value: Decoration.mark({
558
+ value: Decoration2.mark({
496
559
  attributes: {
497
560
  style: `background-color: ${color}`
498
561
  },
@@ -502,7 +565,7 @@ var RemoteSelectionsDecorator = class {
502
565
  decorations.push({
503
566
  from: endLine.from,
504
567
  to: end,
505
- value: Decoration.mark({
568
+ value: Decoration2.mark({
506
569
  attributes: {
507
570
  style: `background-color: ${color}`
508
571
  },
@@ -514,7 +577,7 @@ var RemoteSelectionsDecorator = class {
514
577
  decorations.push({
515
578
  from: linePos,
516
579
  to: linePos,
517
- value: Decoration.line({
580
+ value: Decoration2.line({
518
581
  attributes: {
519
582
  style: `background-color: ${color}`,
520
583
  class: "cm-collab-selectionLine"
@@ -526,14 +589,14 @@ var RemoteSelectionsDecorator = class {
526
589
  decorations.push({
527
590
  from: head,
528
591
  to: head,
529
- value: Decoration.widget({
592
+ value: Decoration2.widget({
530
593
  side: head - anchor > 0 ? -1 : 1,
531
594
  block: false,
532
595
  widget: new RemoteCaretWidget(state.info.displayName ?? "Anonymous", color)
533
596
  })
534
597
  });
535
598
  }
536
- this.decorations = Decoration.set(decorations, true);
599
+ this.decorations = Decoration2.set(decorations, true);
537
600
  }
538
601
  };
539
602
  var RemoteCaretWidget = class extends WidgetType {
@@ -572,7 +635,7 @@ var RemoteCaretWidget = class extends WidgetType {
572
635
  return true;
573
636
  }
574
637
  };
575
- var styles = EditorView2.baseTheme({
638
+ var styles2 = EditorView3.baseTheme({
576
639
  ".cm-collab-selection": {},
577
640
  ".cm-collab-selectionLine": {
578
641
  padding: 0,
@@ -636,10 +699,10 @@ import { closeBrackets } from "@codemirror/autocomplete";
636
699
  import { history } from "@codemirror/commands";
637
700
  import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
638
701
  import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
639
- import { drawSelection, EditorView as EditorView3, highlightActiveLine, placeholder } from "@codemirror/view";
640
- import { isNotFalsy } from "@dxos/util";
702
+ import { drawSelection, EditorView as EditorView4, highlightActiveLine, placeholder } from "@codemirror/view";
703
+ import { isNotFalsy as isNotFalsy2 } from "@dxos/util";
641
704
  var createBasicBundle = ({ themeMode, placeholder: _placeholder, lineWrapping = true } = {}) => [
642
- lineWrapping && EditorView3.lineWrapping,
705
+ lineWrapping && EditorView4.lineWrapping,
643
706
  // https://codemirror.net/docs/ref/#codemirror.minimalSetup
644
707
  bracketMatching(),
645
708
  closeBrackets(),
@@ -649,10 +712,10 @@ var createBasicBundle = ({ themeMode, placeholder: _placeholder, lineWrapping =
649
712
  _placeholder && placeholder(_placeholder),
650
713
  // https://github.com/codemirror/theme-one-dark
651
714
  themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
652
- ].filter(isNotFalsy);
715
+ ].filter(isNotFalsy2);
653
716
 
654
717
  // packages/ui/react-ui-editor/src/extensions/blast.ts
655
- import { EditorView as EditorView4, keymap as keymap2 } from "@codemirror/view";
718
+ import { EditorView as EditorView5, keymap as keymap2 } from "@codemirror/view";
656
719
  import defaultsDeep from "lodash.defaultsdeep";
657
720
  import { invariant } from "@dxos/invariant";
658
721
  var __dxlog_file = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/blast.ts";
@@ -700,7 +763,7 @@ var blast = (options = defaultOptions) => {
700
763
  };
701
764
  return [
702
765
  // Cursor moved.
703
- EditorView4.updateListener.of((update2) => {
766
+ EditorView5.updateListener.of((update2) => {
704
767
  if (blaster?.node !== update2.view.scrollDOM) {
705
768
  if (blaster) {
706
769
  blaster.destroy();
@@ -963,8 +1026,8 @@ var random = (min, max) => {
963
1026
 
964
1027
  // packages/ui/react-ui-editor/src/extensions/comments.ts
965
1028
  import { invertedEffects as invertedEffects2 } from "@codemirror/commands";
966
- import { Facet as Facet3, StateEffect as StateEffect2, StateField as StateField2 } from "@codemirror/state";
967
- import { hoverTooltip, keymap as keymap3, Decoration as Decoration2, EditorView as EditorView5 } from "@codemirror/view";
1029
+ import { Facet as Facet3, StateEffect as StateEffect2, StateField as StateField3 } from "@codemirror/state";
1030
+ import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView6 } from "@codemirror/view";
968
1031
  import sortBy from "lodash.sortby";
969
1032
  import { useEffect } from "react";
970
1033
  import { debounce } from "@dxos/async";
@@ -1073,7 +1136,7 @@ var logChanges = (trs) => {
1073
1136
  };
1074
1137
 
1075
1138
  // packages/ui/react-ui-editor/src/extensions/comments.ts
1076
- var styles2 = EditorView5.baseTheme({
1139
+ var styles3 = EditorView6.baseTheme({
1077
1140
  "&light .cm-comment, &light .cm-comment-current": {
1078
1141
  mixBlendMode: "darken"
1079
1142
  },
@@ -1095,10 +1158,10 @@ var styles2 = EditorView5.baseTheme({
1095
1158
  backgroundColor: getToken("extend.colors.yellow.950")
1096
1159
  }
1097
1160
  });
1098
- var commentMark = Decoration2.mark({
1161
+ var commentMark = Decoration3.mark({
1099
1162
  class: "cm-comment"
1100
1163
  });
1101
- var commentCurrentMark = Decoration2.mark({
1164
+ var commentCurrentMark = Decoration3.mark({
1102
1165
  class: "cm-comment-current"
1103
1166
  });
1104
1167
  var focusComment = (view, id, center = true) => {
@@ -1114,7 +1177,7 @@ var focusComment = (view, id, center = true) => {
1114
1177
  },
1115
1178
  effects: [
1116
1179
  //
1117
- EditorView5.scrollIntoView(range.from, center ? {
1180
+ EditorView6.scrollIntoView(range.from, center ? {
1118
1181
  y: "center"
1119
1182
  } : void 0),
1120
1183
  setSelection.of({
@@ -1127,7 +1190,7 @@ var focusComment = (view, id, center = true) => {
1127
1190
  var setComments = StateEffect2.define();
1128
1191
  var setSelection = StateEffect2.define();
1129
1192
  var setCommentState = StateEffect2.define();
1130
- var commentsState = StateField2.define({
1193
+ var commentsState = StateField3.define({
1131
1194
  create: () => ({
1132
1195
  comments: [],
1133
1196
  selection: {}
@@ -1163,7 +1226,7 @@ var commentsState = StateField2.define({
1163
1226
  return value;
1164
1227
  }
1165
1228
  });
1166
- var commentsDecorations = EditorView5.decorations.compute([
1229
+ var commentsDecorations = EditorView6.decorations.compute([
1167
1230
  commentsState
1168
1231
  ], (state) => {
1169
1232
  const { selection: { current }, comments: comments2 } = state.field(commentsState);
@@ -1179,7 +1242,7 @@ var commentsDecorations = EditorView5.decorations.compute([
1179
1242
  return commentMark.range(range.from, range.to);
1180
1243
  }
1181
1244
  }).filter(nonNullable);
1182
- return Decoration2.set(decorations);
1245
+ return Decoration3.set(decorations);
1183
1246
  });
1184
1247
  var trackPastedComments = (onUpdate) => {
1185
1248
  let tracked = null;
@@ -1201,7 +1264,7 @@ var trackPastedComments = (onUpdate) => {
1201
1264
  }
1202
1265
  };
1203
1266
  return [
1204
- EditorView5.domEventHandlers({
1267
+ EditorView6.domEventHandlers({
1205
1268
  cut: handleTrack,
1206
1269
  copy: handleTrack
1207
1270
  }),
@@ -1223,7 +1286,7 @@ var trackPastedComments = (onUpdate) => {
1223
1286
  return effects;
1224
1287
  }),
1225
1288
  // Handle paste or the undo of comment deletion.
1226
- EditorView5.updateListener.of((update2) => {
1289
+ EditorView6.updateListener.of((update2) => {
1227
1290
  const restore = [];
1228
1291
  for (let i = 0; i < update2.transactions.length; i++) {
1229
1292
  const tr = update2.transactions[i];
@@ -1330,7 +1393,7 @@ var comments = (options = {}) => {
1330
1393
  optionsFacet.of(options),
1331
1394
  commentsState,
1332
1395
  commentsDecorations,
1333
- styles2,
1396
+ styles3,
1334
1397
  //
1335
1398
  // Keymap.
1336
1399
  //
@@ -1373,7 +1436,7 @@ var comments = (options = {}) => {
1373
1436
  //
1374
1437
  // Track deleted ranges and update ranges for decorations.
1375
1438
  //
1376
- EditorView5.updateListener.of(({ view, state, changes }) => {
1439
+ EditorView6.updateListener.of(({ view, state, changes }) => {
1377
1440
  let mod = false;
1378
1441
  const { comments: comments2, ...value } = state.field(commentsState);
1379
1442
  changes.iterChanges((from, to, from2, to2) => {
@@ -1405,7 +1468,7 @@ var comments = (options = {}) => {
1405
1468
  //
1406
1469
  // Track selection/proximity.
1407
1470
  //
1408
- EditorView5.updateListener.of(({ view, state }) => {
1471
+ EditorView6.updateListener.of(({ view, state }) => {
1409
1472
  let min = Infinity;
1410
1473
  const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
1411
1474
  const { head } = state.selection.main;
@@ -1454,14 +1517,14 @@ var useComments = (view, comments2 = []) => {
1454
1517
  };
1455
1518
 
1456
1519
  // packages/ui/react-ui-editor/src/extensions/listener.ts
1457
- import { EditorView as EditorView6 } from "@codemirror/view";
1520
+ import { EditorView as EditorView7 } from "@codemirror/view";
1458
1521
  var listener = ({ onFocus, onChange }) => {
1459
1522
  const extensions = [];
1460
- onFocus && extensions.push(EditorView6.focusChangeEffect.of((_, focused) => {
1523
+ onFocus && extensions.push(EditorView7.focusChangeEffect.of((_, focused) => {
1461
1524
  onFocus(focused);
1462
1525
  return null;
1463
1526
  }));
1464
- onChange && extensions.push(EditorView6.updateListener.of((update2) => {
1527
+ onChange && extensions.push(EditorView7.updateListener.of((update2) => {
1465
1528
  onChange(update2.state.doc.toString());
1466
1529
  }));
1467
1530
  return extensions;
@@ -1476,8 +1539,8 @@ import { languages } from "@codemirror/language-data";
1476
1539
  import { searchKeymap } from "@codemirror/search";
1477
1540
  import { EditorState } from "@codemirror/state";
1478
1541
  import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
1479
- import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView7, highlightActiveLine as highlightActiveLine2, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1480
- import { isNotFalsy as isNotFalsy2 } from "@dxos/util";
1542
+ import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView8, highlightActiveLine as highlightActiveLine2, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1543
+ import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
1481
1544
 
1482
1545
  // packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
1483
1546
  import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
@@ -1670,7 +1733,7 @@ var markdownHighlightStyle = (readonly) => {
1670
1733
  // packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
1671
1734
  var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrapping = true } = {}) => {
1672
1735
  return [
1673
- lineWrapping && EditorView7.lineWrapping,
1736
+ lineWrapping && EditorView8.lineWrapping,
1674
1737
  EditorState.allowMultipleSelections.of(true),
1675
1738
  EditorState.tabSize.of(2),
1676
1739
  // https://github.com/codemirror/basic-setup
@@ -1717,15 +1780,15 @@ var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrap
1717
1780
  // https://codemirror.net/docs/ref/#commands.standardKeymap
1718
1781
  ...standardKeymap
1719
1782
  ])
1720
- ].filter(isNotFalsy2);
1783
+ ].filter(isNotFalsy3);
1721
1784
  };
1722
1785
 
1723
1786
  // packages/ui/react-ui-editor/src/extensions/markdown/code.ts
1724
1787
  import { syntaxTree } from "@codemirror/language";
1725
1788
  import { RangeSetBuilder } from "@codemirror/state";
1726
- import { ViewPlugin as ViewPlugin3, EditorView as EditorView8, Decoration as Decoration3, WidgetType as WidgetType2 } from "@codemirror/view";
1789
+ import { ViewPlugin as ViewPlugin3, EditorView as EditorView9, Decoration as Decoration4, WidgetType as WidgetType2 } from "@codemirror/view";
1727
1790
  import { mx as mx2 } from "@dxos/react-ui-theme";
1728
- var styles3 = EditorView8.baseTheme({
1791
+ var styles4 = EditorView9.baseTheme({
1729
1792
  "& .cm-code": {
1730
1793
  fontFamily: getToken("fontFamily.mono", []).join(",")
1731
1794
  },
@@ -1802,11 +1865,11 @@ var buildDecorations = (view) => {
1802
1865
  for (let i = range[0]; i <= range[1]; i++) {
1803
1866
  const block = blocks[i];
1804
1867
  if (!edit && (i === range[0] || i === range[1])) {
1805
- builder.add(block.from, block.to, Decoration3.replace({
1868
+ builder.add(block.from, block.to, Decoration4.replace({
1806
1869
  widget: i === range[0] ? top : bottom
1807
1870
  }));
1808
1871
  } else {
1809
- builder.add(block.from, block.from, Decoration3.line({
1872
+ builder.add(block.from, block.from, Decoration4.line({
1810
1873
  class: mx2("cm-code cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
1811
1874
  }));
1812
1875
  }
@@ -1831,7 +1894,7 @@ var code2 = () => {
1831
1894
  }, {
1832
1895
  decorations: (value) => value.decorations
1833
1896
  }),
1834
- styles3
1897
+ styles4
1835
1898
  ];
1836
1899
  };
1837
1900
 
@@ -1839,7 +1902,7 @@ var code2 = () => {
1839
1902
  import { snippet } from "@codemirror/autocomplete";
1840
1903
  import { syntaxTree as syntaxTree2 } from "@codemirror/language";
1841
1904
  import { RangeSetBuilder as RangeSetBuilder2, EditorSelection } from "@codemirror/state";
1842
- import { Decoration as Decoration4, EditorView as EditorView9, keymap as keymap5, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
1905
+ import { Decoration as Decoration5, EditorView as EditorView10, keymap as keymap5, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
1843
1906
  import { useState, useMemo } from "react";
1844
1907
  var compareFormatting = (a, b) => a.blockType === b.blockType && a.strong === b.strong && a.emphasis === b.emphasis && a.strikethrough === b.strikethrough && a.code === b.code && a.link === b.link && a.listStyle === b.listStyle && a.blockQuote === b.blockQuote;
1845
1908
  var Inline;
@@ -2681,7 +2744,7 @@ var styling = () => {
2681
2744
  const replace = (node, marks) => {
2682
2745
  if (cursor <= node.from || cursor >= node.to) {
2683
2746
  for (const mark2 of marks) {
2684
- builder.add(mark2.from, mark2.to, Decoration4.replace({}));
2747
+ builder.add(mark2.from, mark2.to, Decoration5.replace({}));
2685
2748
  }
2686
2749
  }
2687
2750
  };
@@ -2911,7 +2974,7 @@ var getFormatting = (state) => {
2911
2974
  };
2912
2975
  var useFormattingState = () => {
2913
2976
  const [state, setState] = useState(null);
2914
- const observer = useMemo(() => EditorView9.updateListener.of((update2) => {
2977
+ const observer = useMemo(() => EditorView10.updateListener.of((update2) => {
2915
2978
  if (update2.docChanged || update2.selectionSet) {
2916
2979
  const newState = getFormatting(update2.state);
2917
2980
  if (!state || !compareFormatting(state, newState)) {
@@ -2928,7 +2991,7 @@ var useFormattingState = () => {
2928
2991
  // packages/ui/react-ui-editor/src/extensions/markdown/heading.ts
2929
2992
  import { syntaxTree as syntaxTree3 } from "@codemirror/language";
2930
2993
  import { RangeSetBuilder as RangeSetBuilder3 } from "@codemirror/state";
2931
- import { Decoration as Decoration5, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
2994
+ import { Decoration as Decoration6, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
2932
2995
  var buildDecorations2 = (view) => {
2933
2996
  const builder = new RangeSetBuilder3();
2934
2997
  const { state } = view;
@@ -2946,7 +3009,7 @@ var buildDecorations2 = (view) => {
2946
3009
  const mark2 = node.node.getChild("HeaderMark");
2947
3010
  if (mark2) {
2948
3011
  if (!view.hasFocus || view.state.readOnly || cursor < node.from || cursor > node.to) {
2949
- builder.add(mark2.from, mark2.to + 1, Decoration5.replace({}));
3012
+ builder.add(mark2.from, mark2.to + 1, Decoration6.replace({}));
2950
3013
  }
2951
3014
  }
2952
3015
  }
@@ -2976,8 +3039,8 @@ var heading2 = () => {
2976
3039
  // packages/ui/react-ui-editor/src/extensions/markdown/hr.ts
2977
3040
  import { syntaxTree as syntaxTree4 } from "@codemirror/language";
2978
3041
  import { RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
2979
- import { Decoration as Decoration6, EditorView as EditorView10, ViewPlugin as ViewPlugin6, WidgetType as WidgetType3 } from "@codemirror/view";
2980
- var styles4 = EditorView10.baseTheme({
3042
+ import { Decoration as Decoration7, EditorView as EditorView11, ViewPlugin as ViewPlugin6, WidgetType as WidgetType3 } from "@codemirror/view";
3043
+ var styles5 = EditorView11.baseTheme({
2981
3044
  "& .cm-hr": {
2982
3045
  // Note that block-level decorations should not have vertical margins,
2983
3046
  borderTop: `1px solid ${getToken("extend.colors.neutral.200")}`
@@ -2990,7 +3053,7 @@ var HorizontalRuleWidget = class extends WidgetType3 {
2990
3053
  return el;
2991
3054
  }
2992
3055
  };
2993
- var decoration = Decoration6.replace({
3056
+ var decoration = Decoration7.replace({
2994
3057
  widget: new HorizontalRuleWidget()
2995
3058
  });
2996
3059
  var buildDecorations3 = (view) => {
@@ -3024,18 +3087,18 @@ var hr = () => {
3024
3087
  }, {
3025
3088
  decorations: (value) => value.decorations
3026
3089
  }),
3027
- styles4
3090
+ styles5
3028
3091
  ];
3029
3092
  };
3030
3093
 
3031
3094
  // packages/ui/react-ui-editor/src/extensions/markdown/image.ts
3032
3095
  import { syntaxTree as syntaxTree5 } from "@codemirror/language";
3033
- import { StateField as StateField3 } from "@codemirror/state";
3034
- import { Decoration as Decoration7, EditorView as EditorView11, WidgetType as WidgetType4 } from "@codemirror/view";
3096
+ import { StateField as StateField4 } from "@codemirror/state";
3097
+ import { Decoration as Decoration8, EditorView as EditorView12, WidgetType as WidgetType4 } from "@codemirror/view";
3035
3098
  var image = (options = {}) => {
3036
- return StateField3.define({
3099
+ return StateField4.define({
3037
3100
  create: (state) => {
3038
- return Decoration7.set(buildDecorations4(0, state.doc.length, state));
3101
+ return Decoration8.set(buildDecorations4(0, state.doc.length, state));
3039
3102
  },
3040
3103
  update: (value, tr) => {
3041
3104
  if (!tr.docChanged && !tr.selection) {
@@ -3058,7 +3121,7 @@ var image = (options = {}) => {
3058
3121
  add: buildDecorations4(from, to, tr.state)
3059
3122
  });
3060
3123
  },
3061
- provide: (field) => EditorView11.decorations.from(field)
3124
+ provide: (field) => EditorView12.decorations.from(field)
3062
3125
  });
3063
3126
  };
3064
3127
  var buildDecorations4 = (from, to, state) => {
@@ -3071,7 +3134,7 @@ var buildDecorations4 = (from, to, state) => {
3071
3134
  if (urlNode) {
3072
3135
  const hide = state.readOnly || cursor < node.from || cursor > node.to;
3073
3136
  const url = state.sliceDoc(urlNode.from, urlNode.to);
3074
- decorations.push(Decoration7.replace({
3137
+ decorations.push(Decoration8.replace({
3075
3138
  block: true,
3076
3139
  widget: new ImageWidget(url)
3077
3140
  }).range(hide ? node.from : node.to, node.to));
@@ -3103,7 +3166,7 @@ var ImageWidget = class extends WidgetType4 {
3103
3166
  // packages/ui/react-ui-editor/src/extensions/markdown/link.ts
3104
3167
  import { syntaxTree as syntaxTree6 } from "@codemirror/language";
3105
3168
  import { RangeSetBuilder as RangeSetBuilder5 } from "@codemirror/state";
3106
- import { hoverTooltip as hoverTooltip2, Decoration as Decoration8, ViewPlugin as ViewPlugin7, WidgetType as WidgetType5 } from "@codemirror/view";
3169
+ import { hoverTooltip as hoverTooltip2, Decoration as Decoration9, ViewPlugin as ViewPlugin7, WidgetType as WidgetType5 } from "@codemirror/view";
3107
3170
  import { tooltipContent } from "@dxos/react-ui-theme";
3108
3171
  var link = (options = {}) => {
3109
3172
  const extensions = [
@@ -3218,12 +3281,12 @@ var buildDecorations5 = (view, options) => {
3218
3281
  return false;
3219
3282
  }
3220
3283
  if (!view.hasFocus || state.readOnly || cursor < node.from || cursor > node.to) {
3221
- builder.add(node.from, node.to, Decoration8.replace({
3284
+ builder.add(node.from, node.to, Decoration9.replace({
3222
3285
  widget: new LinkText(text, options.link ? url : void 0)
3223
3286
  }));
3224
3287
  }
3225
3288
  if (options.onRender) {
3226
- builder.add(node.to, node.to, Decoration8.replace({
3289
+ builder.add(node.to, node.to, Decoration9.replace({
3227
3290
  widget: new LinkButton(url, options.onRender)
3228
3291
  }));
3229
3292
  }
@@ -3239,13 +3302,13 @@ var buildDecorations5 = (view, options) => {
3239
3302
 
3240
3303
  // packages/ui/react-ui-editor/src/extensions/markdown/table.ts
3241
3304
  import { syntaxTree as syntaxTree7 } from "@codemirror/language";
3242
- import { RangeSetBuilder as RangeSetBuilder6, StateField as StateField4 } from "@codemirror/state";
3243
- import { Decoration as Decoration9, EditorView as EditorView12, WidgetType as WidgetType6 } from "@codemirror/view";
3305
+ import { RangeSetBuilder as RangeSetBuilder6, StateField as StateField5 } from "@codemirror/state";
3306
+ import { Decoration as Decoration10, EditorView as EditorView13, WidgetType as WidgetType6 } from "@codemirror/view";
3244
3307
  var table = (options = {}) => {
3245
- return StateField4.define({
3308
+ return StateField5.define({
3246
3309
  create: (state) => update(state, options),
3247
3310
  update: (_, tr) => update(tr.state, options),
3248
- provide: (field) => EditorView12.decorations.from(field)
3311
+ provide: (field) => EditorView13.decorations.from(field)
3249
3312
  });
3250
3313
  };
3251
3314
  var update = (state, options) => {
@@ -3289,10 +3352,10 @@ var update = (state, options) => {
3289
3352
  });
3290
3353
  tables.forEach((table2) => {
3291
3354
  const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
3292
- hide && builder.add(table2.from, table2.to, Decoration9.replace({
3355
+ hide && builder.add(table2.from, table2.to, Decoration10.replace({
3293
3356
  widget: new TableWidget(table2)
3294
3357
  }));
3295
- builder.add(table2.from, table2.to, Decoration9.mark({
3358
+ builder.add(table2.from, table2.to, Decoration10.mark({
3296
3359
  class: "cm-table"
3297
3360
  }));
3298
3361
  });
@@ -3338,8 +3401,8 @@ var TableWidget = class extends WidgetType6 {
3338
3401
  // packages/ui/react-ui-editor/src/extensions/markdown/tasklist.ts
3339
3402
  import { syntaxTree as syntaxTree8 } from "@codemirror/language";
3340
3403
  import { RangeSetBuilder as RangeSetBuilder7 } from "@codemirror/state";
3341
- import { EditorView as EditorView13, Decoration as Decoration10, WidgetType as WidgetType7, ViewPlugin as ViewPlugin8 } from "@codemirror/view";
3342
- var styles5 = EditorView13.baseTheme({
3404
+ import { EditorView as EditorView14, Decoration as Decoration11, WidgetType as WidgetType7, ViewPlugin as ViewPlugin8 } from "@codemirror/view";
3405
+ var styles6 = EditorView14.baseTheme({
3343
3406
  "& .cm-task": {
3344
3407
  color: getToken("extend.colors.blue.500")
3345
3408
  },
@@ -3385,10 +3448,10 @@ var CheckboxWidget = class extends WidgetType7 {
3385
3448
  return false;
3386
3449
  }
3387
3450
  };
3388
- var checkedDecoration = Decoration10.replace({
3451
+ var checkedDecoration = Decoration11.replace({
3389
3452
  widget: new CheckboxWidget(true)
3390
3453
  });
3391
- var uncheckedDecoration = Decoration10.replace({
3454
+ var uncheckedDecoration = Decoration11.replace({
3392
3455
  widget: new CheckboxWidget(false)
3393
3456
  });
3394
3457
  var buildDecorations6 = (view) => {
@@ -3401,7 +3464,7 @@ var buildDecorations6 = (view) => {
3401
3464
  if (node.name === "TaskMarker") {
3402
3465
  if (cursor < node.from || cursor > node.to) {
3403
3466
  const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
3404
- builder.add(node.from - 2, node.from - 1, Decoration10.mark({
3467
+ builder.add(node.from - 2, node.from - 1, Decoration11.mark({
3405
3468
  class: "cm-task"
3406
3469
  }));
3407
3470
  builder.add(node.from, node.to, checked ? checkedDecoration : uncheckedDecoration);
@@ -3428,7 +3491,7 @@ var tasklist = (options = {}) => {
3428
3491
  }, {
3429
3492
  decorations: (value) => value.decorations
3430
3493
  }),
3431
- styles5
3494
+ styles6
3432
3495
  ];
3433
3496
  };
3434
3497
 
@@ -3801,27 +3864,27 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
3801
3864
  selection,
3802
3865
  extensions: [
3803
3866
  // TODO(burdon): Doesn't catch errors in keymap functions.
3804
- EditorView14.exceptionSink.of((err) => {
3867
+ EditorView15.exceptionSink.of((err) => {
3805
3868
  log2.catch(err, void 0, {
3806
3869
  F: __dxlog_file3,
3807
- L: 134,
3870
+ L: 135,
3808
3871
  S: void 0,
3809
3872
  C: (f, a) => f(...a)
3810
3873
  });
3811
3874
  }),
3812
3875
  // Theme.
3813
3876
  // TODO(burdon): Make configurable.
3814
- EditorView14.baseTheme(defaultTheme),
3815
- EditorView14.theme(theme ?? {}),
3816
- EditorView14.darkTheme.of(themeMode === "dark"),
3817
- EditorView14.editorAttributes.of({
3877
+ EditorView15.baseTheme(defaultTheme),
3878
+ EditorView15.theme(theme ?? {}),
3879
+ EditorView15.darkTheme.of(themeMode === "dark"),
3880
+ EditorView15.editorAttributes.of({
3818
3881
  class: slots.editor?.className ?? ""
3819
3882
  }),
3820
- EditorView14.contentAttributes.of({
3883
+ EditorView15.contentAttributes.of({
3821
3884
  class: slots.content?.className ?? ""
3822
3885
  }),
3823
3886
  // State.
3824
- EditorView14.editable.of(!readonly),
3887
+ EditorView15.editable.of(!readonly),
3825
3888
  EditorState2.readOnly.of(!!readonly),
3826
3889
  // Storage and replication.
3827
3890
  // NOTE: This must come before user extensions.
@@ -3830,9 +3893,9 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, s
3830
3893
  editorMode === "vim" && vim(),
3831
3894
  // Custom.
3832
3895
  ...extensions
3833
- ].filter(isNotFalsy3)
3896
+ ].filter(isNotFalsy4)
3834
3897
  });
3835
- const newView = new EditorView14({
3898
+ const newView = new EditorView15({
3836
3899
  state,
3837
3900
  parent: rootRef.current,
3838
3901
  scrollTo,
@@ -4243,8 +4306,8 @@ var SpaceAwarenessProvider = class {
4243
4306
  };
4244
4307
 
4245
4308
  // packages/ui/react-ui-editor/src/hooks/defs.ts
4246
- import { StateField as StateField5 } from "@codemirror/state";
4247
- var modelState = StateField5.define({
4309
+ import { StateField as StateField6 } from "@codemirror/state";
4310
+ var modelState = StateField6.define({
4248
4311
  create: () => void 0,
4249
4312
  update: (model) => model
4250
4313
  });
@@ -4311,10 +4374,10 @@ var useEditorView = () => {
4311
4374
 
4312
4375
  // packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
4313
4376
  import { EditorSelection as EditorSelection2, EditorState as EditorState3 } from "@codemirror/state";
4314
- import { EditorView as EditorView15 } from "@codemirror/view";
4377
+ import { EditorView as EditorView16 } from "@codemirror/view";
4315
4378
  import { useEffect as useEffect3, useRef as useRef2, useState as useState4 } from "react";
4316
4379
  import { log as log4 } from "@dxos/log";
4317
- import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
4380
+ import { isNotFalsy as isNotFalsy5 } from "@dxos/util";
4318
4381
  var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
4319
4382
  var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions } = {}) => {
4320
4383
  const onUpdate = useRef2();
@@ -4327,7 +4390,7 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
4327
4390
  selection,
4328
4391
  extensions: [
4329
4392
  // TODO(burdon): Doesn't catch errors in keymap functions.
4330
- EditorView15.exceptionSink.of((err) => {
4393
+ EditorView16.exceptionSink.of((err) => {
4331
4394
  log4.catch(err, void 0, {
4332
4395
  F: __dxlog_file5,
4333
4396
  L: 57,
@@ -4336,12 +4399,12 @@ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions }
4336
4399
  });
4337
4400
  }),
4338
4401
  extensions,
4339
- EditorView15.updateListener.of(() => {
4402
+ EditorView16.updateListener.of(() => {
4340
4403
  onUpdate.current?.();
4341
4404
  })
4342
- ].filter(isNotFalsy4)
4405
+ ].filter(isNotFalsy5)
4343
4406
  });
4344
- const view2 = new EditorView15({
4407
+ const view2 = new EditorView16({
4345
4408
  parent: parentRef.current,
4346
4409
  scrollTo,
4347
4410
  state,
@@ -4398,22 +4461,22 @@ var createDataExtensions = ({ readonly = false } = {}) => {
4398
4461
  return [
4399
4462
  //
4400
4463
  EditorState3.readOnly.of(readonly),
4401
- EditorView15.editable.of(!readonly)
4464
+ EditorView16.editable.of(!readonly)
4402
4465
  ];
4403
4466
  };
4404
4467
  var createThemeExtensions = ({ theme, themeMode, slots } = {}) => {
4405
4468
  return [
4406
4469
  //
4407
- EditorView15.baseTheme(defaultTheme),
4408
- theme && EditorView15.theme(theme),
4409
- EditorView15.darkTheme.of(themeMode === "dark"),
4410
- EditorView15.editorAttributes.of({
4470
+ EditorView16.baseTheme(defaultTheme),
4471
+ theme && EditorView16.theme(theme),
4472
+ EditorView16.darkTheme.of(themeMode === "dark"),
4473
+ EditorView16.editorAttributes.of({
4411
4474
  class: slots?.editor?.className ?? ""
4412
4475
  }),
4413
- EditorView15.contentAttributes.of({
4476
+ EditorView16.contentAttributes.of({
4414
4477
  class: slots?.content?.className ?? ""
4415
4478
  })
4416
- ].filter(isNotFalsy4);
4479
+ ].filter(isNotFalsy5);
4417
4480
  };
4418
4481
 
4419
4482
  // packages/ui/react-ui-editor/src/hooks/useTextModel.ts
@@ -4444,9 +4507,12 @@ var useInMemoryTextModel = ({ id, defaultContent }) => {
4444
4507
  };
4445
4508
  };
4446
4509
  var createModel = ({ space, identity, text }) => {
4510
+ if (!text) {
4511
+ return void 0;
4512
+ }
4447
4513
  invariant3(isAutomergeObject(text), void 0, {
4448
4514
  F: __dxlog_file6,
4449
- L: 50,
4515
+ L: 54,
4450
4516
  S: void 0,
4451
4517
  A: [
4452
4518
  "isAutomergeObject(text)",
@@ -4468,7 +4534,6 @@ var createModel = ({ space, identity, text }) => {
4468
4534
  peerId: identity?.identityKey.toHex() ?? "Anonymous"
4469
4535
  });
4470
4536
  const extensions = [
4471
- //
4472
4537
  modelState.init(() => model),
4473
4538
  automerge({
4474
4539
  handle: doc.handle,
@@ -4510,6 +4575,7 @@ export {
4510
4575
  addLink,
4511
4576
  addList,
4512
4577
  addStyle,
4578
+ annotations,
4513
4579
  autocomplete,
4514
4580
  automerge,
4515
4581
  awareness,