@dxos/react-ui-editor 0.3.11-main.7ff9773 → 0.3.11-main.80db41b

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 (166) hide show
  1. package/dist/lib/browser/index.mjs +1402 -934
  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 +1 -2
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts +3 -2
  7. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  8. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +1 -1
  9. package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -1
  10. package/dist/types/src/components/TextEditor/{yjs.stories.d.ts → hooks.stories.d.ts} +13 -2
  11. package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -0
  12. package/dist/types/src/components/Toolbar/Toolbar.d.ts +25 -0
  13. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
  14. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +23 -0
  15. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
  16. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  17. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  18. package/dist/types/src/components/index.d.ts +1 -0
  19. package/dist/types/src/components/index.d.ts.map +1 -1
  20. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  21. package/dist/types/src/extensions/automerge/automerge.spec.d.ts +2 -0
  22. package/dist/types/src/extensions/automerge/automerge.spec.d.ts.map +1 -0
  23. package/dist/types/src/extensions/automerge/automerge.test.d.ts +2 -0
  24. package/dist/types/src/extensions/automerge/automerge.test.d.ts.map +1 -0
  25. package/dist/types/src/extensions/automerge/defs.d.ts +5 -5
  26. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  27. package/dist/types/src/extensions/automerge/semaphore.d.ts +2 -1
  28. package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
  29. package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
  30. package/dist/types/src/extensions/awareness.d.ts +2 -4
  31. package/dist/types/src/extensions/awareness.d.ts.map +1 -1
  32. package/dist/types/src/extensions/basic.d.ts +2 -2
  33. package/dist/types/src/extensions/basic.d.ts.map +1 -1
  34. package/dist/types/src/extensions/comments.d.ts +9 -5
  35. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  36. package/dist/types/src/extensions/index.d.ts +0 -7
  37. package/dist/types/src/extensions/index.d.ts.map +1 -1
  38. package/dist/types/src/extensions/markdown/bundle.d.ts +2 -2
  39. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  40. package/dist/types/src/extensions/markdown/code.d.ts.map +1 -0
  41. package/dist/types/src/extensions/markdown/formatting.d.ts +13 -0
  42. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -0
  43. package/dist/types/src/extensions/markdown/heading.d.ts +6 -0
  44. package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -0
  45. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  46. package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -0
  47. package/dist/types/src/extensions/markdown/image.d.ts.map +1 -0
  48. package/dist/types/src/extensions/markdown/index.d.ts +8 -0
  49. package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
  50. package/dist/types/src/extensions/markdown/link.d.ts.map +1 -0
  51. package/dist/types/src/extensions/markdown/table.d.ts.map +1 -0
  52. package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -0
  53. package/dist/types/src/hooks/awareness-provider.d.ts +7 -4
  54. package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -1
  55. package/dist/types/src/hooks/defs.d.ts +1 -4
  56. package/dist/types/src/hooks/defs.d.ts.map +1 -1
  57. package/dist/types/src/hooks/index.d.ts +3 -2
  58. package/dist/types/src/hooks/index.d.ts.map +1 -1
  59. package/dist/types/src/hooks/useActionHandler.d.ts +4 -0
  60. package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -0
  61. package/dist/types/src/hooks/useEditorView.d.ts +17 -0
  62. package/dist/types/src/hooks/useEditorView.d.ts.map +1 -0
  63. package/dist/types/src/hooks/useTextEditor.d.ts +39 -0
  64. package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -0
  65. package/dist/types/src/hooks/useTextModel.d.ts +12 -0
  66. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  67. package/dist/types/src/index.d.ts +1 -1
  68. package/dist/types/src/index.d.ts.map +1 -1
  69. package/dist/types/src/styles/markdown.d.ts +2 -2
  70. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  71. package/dist/types/src/themes/default.d.ts.map +1 -1
  72. package/package.json +39 -29
  73. package/src/components/TextEditor/MarkdownEditor.stories.tsx +15 -19
  74. package/src/components/TextEditor/TextEditor.tsx +46 -27
  75. package/src/components/TextEditor/automerge.stories.tsx +1 -2
  76. package/src/components/TextEditor/hooks.stories.tsx +106 -0
  77. package/src/components/Toolbar/Toolbar.stories.tsx +90 -0
  78. package/src/components/Toolbar/Toolbar.tsx +166 -0
  79. package/src/components/Toolbar/index.ts +5 -0
  80. package/src/components/index.ts +1 -0
  81. package/src/extensions/automerge/automerge.spec.tsx +76 -0
  82. package/src/extensions/automerge/automerge.test.ts +13 -0
  83. package/src/extensions/automerge/automerge.ts +44 -10
  84. package/src/extensions/automerge/cursor.ts +3 -3
  85. package/src/extensions/automerge/defs.ts +9 -9
  86. package/src/extensions/automerge/semaphore.ts +17 -19
  87. package/src/extensions/automerge/update-automerge.ts +12 -6
  88. package/src/extensions/automerge/update-codemirror.ts +5 -5
  89. package/src/extensions/awareness.ts +21 -35
  90. package/src/extensions/basic.ts +17 -15
  91. package/src/extensions/blast.ts +4 -1
  92. package/src/extensions/comments.ts +137 -79
  93. package/src/extensions/index.ts +0 -7
  94. package/src/extensions/markdown/bundle.ts +9 -8
  95. package/src/extensions/markdown/code.ts +150 -0
  96. package/src/extensions/markdown/formatting.ts +188 -0
  97. package/src/extensions/markdown/heading.ts +59 -0
  98. package/src/extensions/markdown/highlight.ts +9 -15
  99. package/src/extensions/{hr.ts → markdown/hr.ts} +3 -4
  100. package/src/extensions/markdown/index.ts +8 -0
  101. package/src/extensions/{link.ts → markdown/link.ts} +13 -4
  102. package/src/extensions/{tasklist.ts → markdown/tasklist.ts} +2 -3
  103. package/src/hooks/awareness-provider.ts +24 -20
  104. package/src/hooks/defs.ts +1 -6
  105. package/src/hooks/index.ts +3 -2
  106. package/src/hooks/useActionHandler.ts +62 -0
  107. package/src/hooks/useEditorView.ts +29 -0
  108. package/src/hooks/useTextEditor.ts +153 -0
  109. package/src/hooks/useTextModel.ts +65 -12
  110. package/src/index.ts +1 -1
  111. package/src/styles/markdown.ts +9 -10
  112. package/src/themes/default.ts +11 -8
  113. package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
  114. package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
  115. package/dist/types/src/components/TextEditor/comments.stories.d.ts +0 -26
  116. package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +0 -1
  117. package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
  118. package/dist/types/src/extensions/code.d.ts.map +0 -1
  119. package/dist/types/src/extensions/hr.d.ts.map +0 -1
  120. package/dist/types/src/extensions/image.d.ts.map +0 -1
  121. package/dist/types/src/extensions/link.d.ts.map +0 -1
  122. package/dist/types/src/extensions/table.d.ts.map +0 -1
  123. package/dist/types/src/extensions/tasklist.d.ts.map +0 -1
  124. package/dist/types/src/extensions/yjs/cursor.d.ts +0 -4
  125. package/dist/types/src/extensions/yjs/cursor.d.ts.map +0 -1
  126. package/dist/types/src/extensions/yjs/index.d.ts +0 -2
  127. package/dist/types/src/extensions/yjs/index.d.ts.map +0 -1
  128. package/dist/types/src/extensions/yjs/yjs.d.ts +0 -4
  129. package/dist/types/src/extensions/yjs/yjs.d.ts.map +0 -1
  130. package/dist/types/src/extensions/yjs/yjs.test.d.ts +0 -2
  131. package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +0 -1
  132. package/dist/types/src/hooks/automerge.d.ts +0 -4
  133. package/dist/types/src/hooks/automerge.d.ts.map +0 -1
  134. package/dist/types/src/hooks/yjs.d.ts +0 -28
  135. package/dist/types/src/hooks/yjs.d.ts.map +0 -1
  136. package/dist/types/src/testing/index.d.ts +0 -3
  137. package/dist/types/src/testing/index.d.ts.map +0 -1
  138. package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
  139. package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
  140. package/dist/types/src/testing/proto/index.d.ts +0 -2
  141. package/dist/types/src/testing/proto/index.d.ts.map +0 -1
  142. package/dist/types/src/testing/replicator.d.ts +0 -45
  143. package/dist/types/src/testing/replicator.d.ts.map +0 -1
  144. package/src/components/TextEditor/codemirror.stories.ts +0 -115
  145. package/src/components/TextEditor/comments.stories.tsx +0 -357
  146. package/src/components/TextEditor/yjs.stories.tsx +0 -56
  147. package/src/extensions/code.ts +0 -104
  148. package/src/extensions/yjs/cursor.ts +0 -22
  149. package/src/extensions/yjs/index.ts +0 -5
  150. package/src/extensions/yjs/yjs.test.ts +0 -35
  151. package/src/extensions/yjs/yjs.ts +0 -16
  152. package/src/hooks/automerge.ts +0 -53
  153. package/src/hooks/yjs.ts +0 -157
  154. package/src/testing/index.ts +0 -6
  155. package/src/testing/proto/gen/schema.ts +0 -49
  156. package/src/testing/proto/index.ts +0 -5
  157. package/src/testing/proto/schema.proto +0 -15
  158. package/src/testing/replicator.ts +0 -184
  159. /package/dist/types/src/extensions/{code.d.ts → markdown/code.d.ts} +0 -0
  160. /package/dist/types/src/extensions/{hr.d.ts → markdown/hr.d.ts} +0 -0
  161. /package/dist/types/src/extensions/{image.d.ts → markdown/image.d.ts} +0 -0
  162. /package/dist/types/src/extensions/{link.d.ts → markdown/link.d.ts} +0 -0
  163. /package/dist/types/src/extensions/{table.d.ts → markdown/table.d.ts} +0 -0
  164. /package/dist/types/src/extensions/{tasklist.d.ts → markdown/tasklist.d.ts} +0 -0
  165. /package/src/extensions/{image.ts → markdown/image.ts} +0 -0
  166. /package/src/extensions/{table.ts → markdown/table.ts} +0 -0
@@ -1,6 +1,7 @@
1
1
  // packages/ui/react-ui-editor/src/index.ts
2
2
  import { TextKind } from "@dxos/protocols/proto/dxos/echo/model/text";
3
3
  import { Doc, YText, YXmlFragment } from "@dxos/text-model";
4
+ import { keymap as keymap7 } from "@codemirror/view";
4
5
 
5
6
  // packages/ui/react-ui-editor/src/components/TextEditor/index.ts
6
7
  import { tags as tags2 } from "@lezer/highlight";
@@ -8,13 +9,13 @@ import { tags as tags2 } from "@lezer/highlight";
8
9
  // packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx
9
10
  import { EditorState as EditorState2 } from "@codemirror/state";
10
11
  import { EditorView as EditorView13 } from "@codemirror/view";
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 as useEffect3, useImperativeHandle, useRef, useState } from "react";
14
+ import React, { forwardRef, useCallback, useEffect as useEffect2, useImperativeHandle, useRef, useState } from "react";
15
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";
16
+ import { useThemeContext } from "@dxos/react-ui";
17
+ import { focusRing, mx as mx3 } from "@dxos/react-ui-theme";
18
+ import { isNotFalsy as isNotFalsy3 } from "@dxos/util";
18
19
 
19
20
  // packages/ui/react-ui-editor/src/extensions/autocomplete.ts
20
21
  import { autocompletion, completionKeymap } from "@codemirror/autocomplete";
@@ -53,13 +54,14 @@ var autocomplete = ({ onSearch }) => {
53
54
  };
54
55
 
55
56
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
57
+ import { invertedEffects } from "@codemirror/commands";
56
58
  import { StateField } from "@codemirror/state";
57
- import { EditorView } from "@codemirror/view";
58
- import { next as A } from "@dxos/automerge/automerge";
59
+ import { EditorView, ViewPlugin } from "@codemirror/view";
60
+ import { next as A4 } from "@dxos/automerge/automerge";
59
61
 
60
62
  // packages/ui/react-ui-editor/src/extensions/automerge/cursor.ts
61
63
  import get from "lodash.get";
62
- import { next as automerge } from "@dxos/automerge/automerge";
64
+ import { next as A } from "@dxos/automerge/automerge";
63
65
  var cursorConverter = (handle, path) => ({
64
66
  // TODO(burdon): Handle assoc to associate with a previous character.
65
67
  toCursor: (pos) => {
@@ -71,7 +73,7 @@ var cursorConverter = (handle, path) => ({
71
73
  if (typeof value === "string" && value.length <= pos) {
72
74
  return "end";
73
75
  }
74
- return automerge.getCursor(doc, path.slice(), pos);
76
+ return A.getCursor(doc, path.slice(), pos);
75
77
  },
76
78
  fromCursor: (cursor) => {
77
79
  if (cursor === "") {
@@ -89,26 +91,28 @@ var cursorConverter = (handle, path) => ({
89
91
  return 0;
90
92
  }
91
93
  }
92
- return automerge.getCursorPosition(doc, path.slice(), cursor);
94
+ return A.getCursorPosition(doc, path.slice(), cursor);
93
95
  }
94
96
  });
95
97
 
96
98
  // packages/ui/react-ui-editor/src/extensions/automerge/defs.ts
97
99
  import { Annotation, StateEffect } from "@codemirror/state";
98
- var effectType = StateEffect.define({});
99
- var reconcileAnnotationType = Annotation.define();
100
100
  var getPath = (state, field) => state.field(field).path;
101
101
  var getLastHeads = (state, field) => state.field(field).lastHeads;
102
- var updateHeads = (newHeads) => effectType.of({
102
+ var updateHeadsEffect = StateEffect.define({});
103
+ var updateHeads = (newHeads) => updateHeadsEffect.of({
103
104
  newHeads
104
105
  });
105
- var isReconcileTx = (tr) => !!tr.annotation(reconcileAnnotationType);
106
+ var reconcileAnnotation = Annotation.define();
107
+ var isReconcile = (tr) => {
108
+ return !!tr.annotation(reconcileAnnotation);
109
+ };
106
110
 
107
111
  // packages/ui/react-ui-editor/src/extensions/automerge/semaphore.ts
108
- import { next as automerge2 } from "@dxos/automerge/automerge";
112
+ import { next as A3 } from "@dxos/automerge/automerge";
109
113
 
110
114
  // packages/ui/react-ui-editor/src/extensions/automerge/update-automerge.ts
111
- import { next as am } from "@dxos/automerge/automerge";
115
+ import { next as A2 } from "@dxos/automerge/automerge";
112
116
  var updateAutomerge = (field, handle, transactions, state) => {
113
117
  const { lastHeads, path } = state.field(field);
114
118
  let hasChanges = false;
@@ -121,11 +125,19 @@ var updateAutomerge = (field, handle, transactions, state) => {
121
125
  return void 0;
122
126
  }
123
127
  const newHeads = handle.changeAt(lastHeads, (doc) => {
128
+ const invertedTransactions = [];
124
129
  for (const tr of transactions) {
125
- tr.changes.iterChanges((fromA, toA, _fromB, _toB, inserted) => {
126
- am.splice(doc, path, fromA, toA - fromA, inserted.toString());
130
+ tr.changes.iterChanges((fromA, toA, _fromB, _toB, insert) => {
131
+ invertedTransactions.push({
132
+ from: fromA,
133
+ del: toA - fromA,
134
+ insert
135
+ });
127
136
  });
128
137
  }
138
+ invertedTransactions.reverse().forEach(({ from, del, insert }) => {
139
+ A2.splice(doc, path.slice(), from, del, insert.toString());
140
+ });
129
141
  });
130
142
  return newHeads ?? void 0;
131
143
  };
@@ -140,13 +152,13 @@ var updateCodeMirror = (view, selection, target, patches) => {
140
152
  selection = selection.map(changeSet, 1);
141
153
  view.dispatch({
142
154
  changes: changeSet,
143
- annotations: reconcileAnnotationType.of({})
155
+ annotations: reconcileAnnotation.of(false)
144
156
  });
145
157
  }
146
158
  }
147
159
  view.dispatch({
148
160
  selection,
149
- annotations: reconcileAnnotationType.of({})
161
+ annotations: reconcileAnnotation.of(false)
150
162
  });
151
163
  };
152
164
  var handlePatch = (patch, target, state) => {
@@ -167,7 +179,7 @@ var handleInsert = (target, patch) => {
167
179
  if (index == null) {
168
180
  return [];
169
181
  }
170
- const text = patch.values.map((v) => v ? v.toString() : "").join("");
182
+ const text = patch.values.map((value) => value ? value.toString() : "").join("");
171
183
  return [
172
184
  {
173
185
  from: index,
@@ -245,36 +257,37 @@ var PatchSemaphore = class {
245
257
  this._state = _state;
246
258
  this._inReconcile = false;
247
259
  }
248
- // NOTE: Cannot destruct view.state.
249
260
  reconcile(view) {
250
- if (this._inReconcile) {
251
- return;
261
+ if (!this._inReconcile) {
262
+ this._inReconcile = true;
263
+ this.doReconcile(view);
264
+ this._inReconcile = false;
252
265
  }
253
- this._inReconcile = true;
266
+ }
267
+ doReconcile(view) {
254
268
  const path = getPath(view.state, this._state);
255
269
  const oldHeads = getLastHeads(view.state, this._state);
256
270
  let selection = view.state.selection;
257
- const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
271
+ const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcile(tx));
258
272
  const toInvert = transactions.slice().reverse();
259
- for (const tx of toInvert) {
260
- const inverted = tx.changes.invert(tx.startState.doc);
273
+ for (const tr of toInvert) {
274
+ const inverted = tr.changes.invert(tr.startState.doc);
261
275
  selection = selection.map(inverted);
262
276
  view.dispatch({
263
277
  changes: inverted,
264
- annotations: reconcileAnnotationType.of(true)
278
+ annotations: reconcileAnnotation.of(true)
265
279
  });
266
280
  }
267
281
  let newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
268
282
  if (newHeads === null || newHeads === void 0) {
269
- newHeads = automerge2.getHeads(this._handle.docSync());
283
+ newHeads = A3.getHeads(this._handle.docSync());
270
284
  }
271
- const diff = automerge2.equals(oldHeads, newHeads) ? [] : automerge2.diff(this._handle.docSync(), oldHeads, newHeads);
285
+ const diff = A3.equals(oldHeads, newHeads) ? [] : A3.diff(this._handle.docSync(), oldHeads, newHeads);
272
286
  updateCodeMirror(view, selection, path, diff);
273
287
  view.dispatch({
274
288
  effects: updateHeads(newHeads),
275
- annotations: reconcileAnnotationType.of({})
289
+ annotations: reconcileAnnotation.of(false)
276
290
  });
277
- this._inReconcile = false;
278
291
  }
279
292
  };
280
293
 
@@ -292,9 +305,9 @@ var Cursor = class _Cursor {
292
305
  }
293
306
  static {
294
307
  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);
308
+ const cursorConverter2 = state.facet(_Cursor.converter);
309
+ const from = cursorConverter2.toCursor(range.from);
310
+ const to = cursorConverter2.toCursor(range.to, -1);
298
311
  return [
299
312
  from,
300
313
  to
@@ -303,10 +316,10 @@ var Cursor = class _Cursor {
303
316
  }
304
317
  static {
305
318
  this.getRangeFromCursor = (state, cursor) => {
306
- const cursorConverter3 = state.facet(_Cursor.converter);
319
+ const cursorConverter2 = state.facet(_Cursor.converter);
307
320
  const parts = cursor.split(":");
308
- const from = cursorConverter3.fromCursor(parts[0]);
309
- const to = cursorConverter3.fromCursor(parts[1]);
321
+ const from = cursorConverter2.fromCursor(parts[0]);
322
+ const to = cursorConverter2.fromCursor(parts[1]);
310
323
  return from !== void 0 && to !== void 0 ? {
311
324
  from,
312
325
  to
@@ -316,11 +329,11 @@ var Cursor = class _Cursor {
316
329
  };
317
330
 
318
331
  // packages/ui/react-ui-editor/src/extensions/automerge/automerge.ts
319
- var automerge3 = ({ handle, path }) => {
320
- const state = StateField.define({
332
+ var automerge = ({ handle, path }) => {
333
+ const syncState = StateField.define({
321
334
  create: () => ({
322
335
  path: path.slice(),
323
- lastHeads: A.getHeads(handle.docSync()),
336
+ lastHeads: A4.getHeads(handle.docSync()),
324
337
  unreconciledTransactions: []
325
338
  }),
326
339
  update: (value, tr) => {
@@ -331,7 +344,7 @@ var automerge3 = ({ handle, path }) => {
331
344
  };
332
345
  let clearUnreconciled = false;
333
346
  for (const effect of tr.effects) {
334
- if (effect.is(effectType)) {
347
+ if (effect.is(updateHeadsEffect)) {
335
348
  result.lastHeads = effect.value.newHeads;
336
349
  clearUnreconciled = true;
337
350
  }
@@ -339,80 +352,78 @@ var automerge3 = ({ handle, path }) => {
339
352
  if (clearUnreconciled) {
340
353
  result.unreconciledTransactions = [];
341
354
  } else {
342
- if (!isReconcileTx(tr)) {
355
+ if (!isReconcile(tr)) {
343
356
  result.unreconciledTransactions.push(tr);
344
357
  }
345
358
  }
346
359
  return result;
347
360
  }
348
361
  });
349
- const semaphore = new PatchSemaphore(handle, state);
362
+ const semaphore = new PatchSemaphore(handle, syncState);
350
363
  return [
351
364
  Cursor.converter.of(cursorConverter(handle, path)),
365
+ syncState,
366
+ // Reconcile external updates.
367
+ ViewPlugin.fromClass(class {
368
+ constructor(_view) {
369
+ this._view = _view;
370
+ handle.addListener("change", this._handleChange.bind(this));
371
+ }
372
+ destroy() {
373
+ handle.removeListener("change", this._handleChange.bind(this));
374
+ }
375
+ _handleChange() {
376
+ semaphore.reconcile(this._view);
377
+ }
378
+ }),
379
+ // Reconcile local updates.
352
380
  EditorView.updateListener.of(({ view, changes }) => {
353
381
  if (!changes.empty) {
354
382
  semaphore.reconcile(view);
355
383
  }
356
384
  }),
357
- state
385
+ // TODO(burdon): Record undo transactions.
386
+ // See https://github.com/yjs/y-codemirror.next/tree/main
387
+ // https://codemirror.net/examples/inverted-effect
388
+ invertedEffects.of((tr) => {
389
+ const effects = [];
390
+ if (!tr.changes.empty) {
391
+ tr.changes.iterChanges((fromA, toA, fromB, toB, inserted) => {
392
+ });
393
+ }
394
+ return effects;
395
+ })
358
396
  ];
359
397
  };
360
398
 
361
399
  // packages/ui/react-ui-editor/src/extensions/awareness.ts
362
400
  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";
401
+ import { Decoration, EditorView as EditorView2, ViewPlugin as ViewPlugin2, WidgetType } from "@codemirror/view";
365
402
  import { Event } from "@dxos/async";
366
403
  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";
370
404
  var dummyProvider = {
371
405
  remoteStateChange: new Event(),
372
406
  open: () => {
373
407
  },
374
408
  close: () => {
375
409
  },
410
+ getRemoteStates: () => [],
376
411
  update: () => {
377
- },
378
- getRemoteStates: () => []
412
+ }
379
413
  };
380
- var AwarenessProvider = Facet2.define({
414
+ var awarenessProvider = Facet2.define({
381
415
  combine: (providers) => providers[0] ?? dummyProvider
382
416
  });
383
417
  var RemoteSelectionChangedAnnotation = Annotation2.define();
384
418
  var awareness = (provider = dummyProvider) => {
385
419
  return [
386
- AwarenessProvider.of(provider),
387
- ViewPlugin.fromClass(RemoteSelectionsDecorator, {
420
+ awarenessProvider.of(provider),
421
+ ViewPlugin2.fromClass(RemoteSelectionsDecorator, {
388
422
  decorations: (value) => value.decorations
389
423
  }),
390
424
  styles
391
425
  ];
392
426
  };
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
- };
416
427
  var RemoteSelectionsDecorator = class {
417
428
  constructor(view) {
418
429
  this.decorations = RangeSet.of([]);
@@ -420,7 +431,7 @@ var RemoteSelectionsDecorator = class {
420
431
  this._lastAnchor = void 0;
421
432
  this._lastHead = void 0;
422
433
  this._cursorConverter = view.state.facet(Cursor.converter);
423
- this._provider = view.state.facet(AwarenessProvider);
434
+ this._provider = view.state.facet(awarenessProvider);
424
435
  this._provider.open();
425
436
  this._provider.remoteStateChange.on(this._ctx, () => {
426
437
  view.dispatch({
@@ -574,39 +585,41 @@ var styles = EditorView2.baseTheme({
574
585
  marginLeft: "-1px",
575
586
  marginRight: "-1px",
576
587
  boxSizing: "border-box",
577
- display: "inline"
588
+ display: "inline",
589
+ cursor: "pointer"
578
590
  },
579
591
  ".cm-collab-selectionCaretDot": {
580
592
  borderRadius: "50%",
581
593
  position: "absolute",
582
- width: ".4em",
583
- height: ".4em",
584
- top: "-.2em",
585
- left: "-.2em",
594
+ width: ".5em",
595
+ height: ".5em",
596
+ top: "-.25em",
597
+ left: "-.25em",
586
598
  backgroundColor: "inherit",
587
599
  transition: "transform .3s ease-in-out",
588
600
  boxSizing: "border-box"
589
601
  },
590
602
  ".cm-collab-selectionCaret:hover > .cm-collab-selectionCaretDot": {
591
- transformOrigin: "bottom center",
592
- transform: "scale(0)"
603
+ transform: "scale(0)",
604
+ transformOrigin: "center"
593
605
  },
594
606
  ".cm-collab-selectionInfo": {
595
607
  position: "absolute",
596
- top: "-1.05em",
597
- left: "-1px",
608
+ transform: "translate(-50%, 0)",
609
+ top: "-20px",
610
+ left: 0,
598
611
  fontSize: ".75em",
599
- fontFamily: "serif",
612
+ fontFamily: "sans-serif",
600
613
  fontStyle: "normal",
601
614
  fontWeight: "normal",
602
615
  lineHeight: "normal",
603
616
  userSelect: "none",
604
617
  color: "white",
605
- paddingLeft: "2px",
606
- paddingRight: "2px",
618
+ padding: "2px",
607
619
  zIndex: 101,
608
620
  transition: "opacity .3s ease-in-out",
609
621
  backgroundColor: "inherit",
622
+ borderRadius: "2px",
610
623
  // These should be separate.
611
624
  opacity: 0,
612
625
  transitionDelay: "0s",
@@ -624,18 +637,19 @@ import { history } from "@codemirror/commands";
624
637
  import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from "@codemirror/language";
625
638
  import { oneDarkHighlightStyle } from "@codemirror/theme-one-dark";
626
639
  import { drawSelection, EditorView as EditorView3, highlightActiveLine, placeholder } from "@codemirror/view";
627
- var basicBundle = ({ themeMode, placeholder: _placeholder, multiline = true }) => [
628
- multiline ? EditorView3.lineWrapping : [],
640
+ import { isNotFalsy } from "@dxos/util";
641
+ var createBasicBundle = ({ themeMode, placeholder: _placeholder, lineWrapping = true } = {}) => [
642
+ lineWrapping && EditorView3.lineWrapping,
629
643
  // https://codemirror.net/docs/ref/#codemirror.minimalSetup
630
644
  bracketMatching(),
631
645
  closeBrackets(),
632
646
  drawSelection(),
633
647
  highlightActiveLine(),
634
648
  history(),
635
- _placeholder ? placeholder(_placeholder) : [],
649
+ _placeholder && placeholder(_placeholder),
636
650
  // https://github.com/codemirror/theme-one-dark
637
651
  themeMode === "dark" ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle)
638
- ];
652
+ ].filter(isNotFalsy);
639
653
 
640
654
  // packages/ui/react-ui-editor/src/extensions/blast.ts
641
655
  import { EditorView as EditorView4, keymap as keymap2 } from "@codemirror/view";
@@ -674,10 +688,10 @@ var blast = (options = defaultOptions) => {
674
688
  const getPoint = (view, pos) => {
675
689
  const { left: x = 0, top: y = 0 } = view.coordsForChar(pos) ?? {};
676
690
  const element = document.elementFromPoint(x, y);
677
- const { offsetLeft: left = 0, offsetTop: top = 0 } = view.scrollDOM.parentElement ?? {};
691
+ const { offsetLeft: left = 0, offsetTop: top2 = 0 } = view.scrollDOM.parentElement ?? {};
678
692
  const point = {
679
693
  x: x - left,
680
- y: y - top
694
+ y: y - top2
681
695
  };
682
696
  return {
683
697
  element,
@@ -769,7 +783,7 @@ var Blaster = class {
769
783
  initialize() {
770
784
  invariant(!this._canvas && !this._ctx, void 0, {
771
785
  F: __dxlog_file,
772
- L: 138,
786
+ L: 141,
773
787
  S: this,
774
788
  A: [
775
789
  "!this._canvas && !this._ctx",
@@ -806,7 +820,7 @@ var Blaster = class {
806
820
  start() {
807
821
  invariant(this._canvas && this._ctx, void 0, {
808
822
  F: __dxlog_file,
809
- L: 177,
823
+ L: 180,
810
824
  S: this,
811
825
  A: [
812
826
  "this._canvas && this._ctx",
@@ -947,9 +961,14 @@ var random = (min, max) => {
947
961
  return min + ~~(Math.random() * (max - min + 1));
948
962
  };
949
963
 
950
- // packages/ui/react-ui-editor/src/extensions/code.ts
951
- import { ViewPlugin as ViewPlugin2, EditorView as EditorView5, Decoration as Decoration2 } from "@codemirror/view";
952
- import { mx as mx2 } from "@dxos/react-ui-theme";
964
+ // packages/ui/react-ui-editor/src/extensions/comments.ts
965
+ 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";
968
+ import sortBy from "lodash.sortby";
969
+ import { useEffect } from "react";
970
+ import { debounce } from "@dxos/async";
971
+ import { nonNullable } from "@dxos/util";
953
972
 
954
973
  // packages/ui/react-ui-editor/src/styles/cursors.ts
955
974
  import * as random2 from "lib0/random";
@@ -992,34 +1011,15 @@ var cursorColor = cursorColors[random2.uint32() % cursorColors.length];
992
1011
  // packages/ui/react-ui-editor/src/styles/markdown.ts
993
1012
  import { mx } from "@dxos/react-ui-theme";
994
1013
  var headings = {
995
- 1: [
996
- "mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl",
997
- "-ml-[10px]"
998
- ],
999
- 2: [
1000
- "mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl",
1001
- "-ml-[8px]"
1002
- ],
1003
- 3: [
1004
- "mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl",
1005
- "-ml-[7px]"
1006
- ],
1007
- 4: [
1008
- "mbs-4 mbe-2 font-medium text-inherit no-underline text-xl",
1009
- "-ml-[6px]"
1010
- ],
1011
- 5: [
1012
- "mbs-4 mbe-2 font-medium text-inherit no-underline text-lg",
1013
- "-ml-[5px]"
1014
- ],
1015
- 6: [
1016
- "mbs-4 mbe-2 font-medium text-inherit no-underline",
1017
- "-ml-[4px]"
1018
- ]
1019
- };
1020
- var heading = (level, readonly) => {
1021
- const [style, offset] = headings[level];
1022
- return mx(style, readonly && offset);
1014
+ 1: "mbs-4 mbe-2 font-medium text-inherit no-underline text-4xl",
1015
+ 2: "mbs-4 mbe-2 font-medium text-inherit no-underline text-3xl",
1016
+ 3: "mbs-4 mbe-2 font-medium text-inherit no-underline text-2xl",
1017
+ 4: "mbs-4 mbe-2 font-medium text-inherit no-underline text-xl",
1018
+ 5: "mbs-4 mbe-2 font-medium text-inherit no-underline text-lg",
1019
+ 6: "mbs-4 mbe-2 font-medium text-inherit no-underline"
1020
+ };
1021
+ var heading = (level) => {
1022
+ return headings[level];
1023
1023
  };
1024
1024
  var light = "text-neutral-200 dark:text-neutral-800";
1025
1025
  var mark = mx("!font-normal !no-underline !text-inherit opacity-40", light);
@@ -1037,89 +1037,6 @@ import { tailwindConfig } from "@dxos/react-ui-theme";
1037
1037
  var tokens = tailwindConfig({}).theme;
1038
1038
  var getToken = (path, defaultValue = void 0) => get2(tokens, path, defaultValue);
1039
1039
 
1040
- // packages/ui/react-ui-editor/src/extensions/code.ts
1041
- var CODE_REGEX = /```[\s\S]*?```/gs;
1042
- var styles2 = EditorView5.baseTheme({
1043
- "& .cm-codeblock": {
1044
- fontFamily: getToken("fontFamily.mono", []).join(",")
1045
- },
1046
- '&light [aria-readonly="true"] .cm-codeblock': {
1047
- background: getToken("extend.colors.neutral.50")
1048
- },
1049
- '&dark [aria-readonly="true"] .cm-codeblock': {
1050
- background: getToken("extend.colors.neutral.850")
1051
- },
1052
- '& [aria-readonly="true"] .cm-codeblock': {
1053
- display: "block",
1054
- paddingInline: "4px !important"
1055
- },
1056
- '& [aria-readonly="true"] .cm-codeblock-first': {
1057
- paddingTop: "4px !important",
1058
- borderTopLeftRadius: "4px",
1059
- borderTopRightRadius: "4px"
1060
- },
1061
- '& [aria-readonly="true"] .cm-codeblock-last': {
1062
- paddingBottom: "4px !important",
1063
- borderBottomLeftRadius: "4px",
1064
- borderBottomRightRadius: "4px"
1065
- }
1066
- });
1067
- var getLineRange = (lines, from, to) => {
1068
- const start = lines.findIndex((line) => line.from >= from);
1069
- const end = lines.findIndex((line) => line.to >= to);
1070
- return [
1071
- start,
1072
- end
1073
- ];
1074
- };
1075
- var code2 = () => {
1076
- const buildDecorations5 = (view) => {
1077
- const decorations = [];
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));
1088
- }
1089
- }
1090
- return Decoration2.set(decorations);
1091
- };
1092
- return [
1093
- ViewPlugin2.fromClass(class {
1094
- constructor(view) {
1095
- this.hasFocus = false;
1096
- this.decorations = buildDecorations5(view);
1097
- }
1098
- update(update2) {
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);
1105
- }
1106
- }
1107
- }, {
1108
- decorations: (value) => value.decorations
1109
- }),
1110
- styles2
1111
- ];
1112
- };
1113
-
1114
- // packages/ui/react-ui-editor/src/extensions/comments.ts
1115
- import { StateEffect as StateEffect2, StateField as StateField2 } from "@codemirror/state";
1116
- import { hoverTooltip, keymap as keymap3, Decoration as Decoration3, EditorView as EditorView6 } from "@codemirror/view";
1117
- import sortBy from "lodash.sortby";
1118
- import { useEffect as useEffect2 } from "react";
1119
- import { debounce } from "@dxos/async";
1120
- import { invariant as invariant2 } from "@dxos/invariant";
1121
- import { nonNullable } from "@dxos/util";
1122
-
1123
1040
  // packages/ui/react-ui-editor/src/util.ts
1124
1041
  import { log } from "@dxos/log";
1125
1042
  var __dxlog_file2 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/util.ts";
@@ -1156,24 +1073,35 @@ var logChanges = (trs) => {
1156
1073
  };
1157
1074
 
1158
1075
  // packages/ui/react-ui-editor/src/extensions/comments.ts
1159
- var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/extensions/comments.ts";
1160
- var styles3 = EditorView6.baseTheme({
1161
- "& .cm-comment": {
1076
+ var styles2 = EditorView5.baseTheme({
1077
+ "&light .cm-comment, &light .cm-comment-current": {
1078
+ mixBlendMode: "darken"
1079
+ },
1080
+ "&dark .cm-comment, &dark .cm-comment-current": {
1081
+ mixBlendMode: "plus-lighter"
1082
+ },
1083
+ "&light .cm-comment": {
1162
1084
  backgroundColor: getToken("extend.colors.yellow.50")
1163
1085
  },
1164
- "& .cm-comment-active": {
1086
+ "&light .cm-comment-current": {
1165
1087
  backgroundColor: getToken("extend.colors.yellow.100")
1088
+ },
1089
+ "&dark .cm-comment": {
1090
+ color: getToken("extend.colors.yellow.50"),
1091
+ backgroundColor: getToken("extend.colors.yellow.900")
1092
+ },
1093
+ "&dark .cm-comment-current": {
1094
+ color: getToken("extend.colors.yellow.100"),
1095
+ backgroundColor: getToken("extend.colors.yellow.950")
1166
1096
  }
1167
1097
  });
1168
- var marks = {
1169
- highlight: Decoration3.mark({
1170
- class: "cm-comment"
1171
- }),
1172
- highlightActive: Decoration3.mark({
1173
- class: "cm-comment-active"
1174
- })
1175
- };
1176
- var setFocus = (view, id, center = true) => {
1098
+ var commentMark = Decoration2.mark({
1099
+ class: "cm-comment"
1100
+ });
1101
+ var commentCurrentMark = Decoration2.mark({
1102
+ class: "cm-comment-current"
1103
+ });
1104
+ var focusComment = (view, id, center = true) => {
1177
1105
  const comment = view.state.field(commentsState).comments.find((range2) => range2.comment.id === id);
1178
1106
  if (!comment?.comment.cursor) {
1179
1107
  return;
@@ -1186,11 +1114,11 @@ var setFocus = (view, id, center = true) => {
1186
1114
  },
1187
1115
  effects: [
1188
1116
  //
1189
- EditorView6.scrollIntoView(range.from, center ? {
1117
+ EditorView5.scrollIntoView(range.from, center ? {
1190
1118
  y: "center"
1191
1119
  } : void 0),
1192
1120
  setSelection.of({
1193
- active: id
1121
+ current: id
1194
1122
  })
1195
1123
  ]
1196
1124
  });
@@ -1235,23 +1163,23 @@ var commentsState = StateField2.define({
1235
1163
  return value;
1236
1164
  }
1237
1165
  });
1238
- var highlightDecorations = EditorView6.decorations.compute([
1166
+ var commentsDecorations = EditorView5.decorations.compute([
1239
1167
  commentsState
1240
1168
  ], (state) => {
1241
- const { selection: { active }, comments: comments2 } = state.field(commentsState);
1169
+ const { selection: { current }, comments: comments2 } = state.field(commentsState);
1242
1170
  const decorations = sortBy(comments2 ?? [], (range) => range.range.from)?.flatMap((comment) => {
1243
1171
  const range = comment.range;
1244
1172
  if (!range || range.from === range.to) {
1245
1173
  console.warn("Invalid range:", range);
1246
1174
  return void 0;
1247
1175
  }
1248
- if (comment.comment.id === active) {
1249
- return marks.highlightActive.range(range.from, range.to);
1176
+ if (comment.comment.id === current) {
1177
+ return commentCurrentMark.range(range.from, range.to);
1250
1178
  } else {
1251
- return marks.highlight.range(range.from, range.to);
1179
+ return commentMark.range(range.from, range.to);
1252
1180
  }
1253
1181
  }).filter(nonNullable);
1254
- return Decoration3.set(decorations);
1182
+ return Decoration2.set(decorations);
1255
1183
  });
1256
1184
  var trackPastedComments = (onUpdate) => {
1257
1185
  let tracked = null;
@@ -1273,96 +1201,136 @@ var trackPastedComments = (onUpdate) => {
1273
1201
  }
1274
1202
  };
1275
1203
  return [
1276
- EditorView6.domEventHandlers({
1204
+ EditorView5.domEventHandlers({
1277
1205
  cut: handleTrack,
1278
1206
  copy: handleTrack
1279
1207
  }),
1280
- // Handle paste.
1281
- EditorView6.updateListener.of(({ view, state, transactions }) => {
1208
+ // Track deleted comments.
1209
+ invertedEffects2.of((tr) => {
1210
+ const { comments: comments2 } = tr.startState.field(commentsState);
1211
+ const effects = [];
1212
+ tr.changes.iterChangedRanges((fromA, toA) => {
1213
+ for (const { comment: { id }, range: { from, to } } of comments2) {
1214
+ if (from < to && from >= fromA && to <= toA) {
1215
+ effects.push(restoreCommentEffect.of({
1216
+ id,
1217
+ from,
1218
+ to
1219
+ }));
1220
+ }
1221
+ }
1222
+ });
1223
+ return effects;
1224
+ }),
1225
+ // Handle paste or the undo of comment deletion.
1226
+ EditorView5.updateListener.of((update2) => {
1227
+ const restore = [];
1228
+ for (let i = 0; i < update2.transactions.length; i++) {
1229
+ const tr = update2.transactions[i];
1230
+ for (let j = 0; j < restore.length; j++) {
1231
+ restore[j] = mapTrackedComment(restore[j], tr.changes);
1232
+ }
1233
+ for (const effect of tr.effects) {
1234
+ if (effect.is(restoreCommentEffect)) {
1235
+ restore.push(effect.value);
1236
+ }
1237
+ }
1238
+ }
1282
1239
  if (tracked) {
1283
- const paste = transactions.find((tr) => tr.isUserEvent("input.paste"));
1240
+ const paste = update2.transactions.find((tr) => tr.isUserEvent("input.paste"));
1284
1241
  if (paste) {
1285
1242
  let found = -1;
1286
1243
  paste.changes.iterChanges((fromA, toA, fromB, toB, text) => {
1287
1244
  if (text.eq(tracked.text)) {
1288
- for (let i = transactions.indexOf(paste) + 1; i < transactions.length; i++) {
1289
- fromB = transactions[i].changes.mapPos(fromB);
1245
+ for (let i = update2.transactions.indexOf(paste) + 1; i < update2.transactions.length; i++) {
1246
+ fromB = update2.transactions[i].changes.mapPos(fromB);
1290
1247
  }
1291
1248
  found = fromB;
1292
1249
  }
1293
1250
  });
1294
1251
  if (found > -1) {
1295
1252
  for (const moved of tracked.comments) {
1296
- const range = {
1253
+ restore.push({
1254
+ id: moved.id,
1297
1255
  from: found + moved.from,
1298
1256
  to: found + moved.to
1299
- };
1300
- const cursor = Cursor.getCursorFromRange(state, range);
1301
- onUpdate(moved.id, cursor);
1257
+ });
1302
1258
  }
1303
1259
  }
1304
1260
  tracked = null;
1305
1261
  }
1306
1262
  }
1263
+ for (const comment of restore) {
1264
+ const { comments: comments2 } = update2.startState.field(commentsState);
1265
+ const exists = comments2.some((c) => c.comment.id === comment.id && c.range.from < c.range.to);
1266
+ if (!exists) {
1267
+ const cursor = Cursor.getCursorFromRange(update2.state, comment);
1268
+ onUpdate(comment.id, cursor);
1269
+ }
1270
+ }
1307
1271
  })
1308
1272
  ];
1309
1273
  };
1310
- var comments = (options = {}) => {
1311
- const { key: shortcut = "meta-'" } = options;
1312
- const handleSelect = debounce((state) => options.onSelect?.(state), 200);
1313
- const createCommentThread = (view) => {
1314
- invariant2(options.onCreate, void 0, {
1315
- F: __dxlog_file3,
1316
- L: 259,
1317
- S: void 0,
1318
- A: [
1319
- "options.onCreate",
1320
- ""
1321
- ]
1274
+ var mapTrackedComment = (comment, changes) => ({
1275
+ id: comment.id,
1276
+ from: changes.mapPos(comment.from, 1),
1277
+ to: changes.mapPos(comment.to, 1)
1278
+ });
1279
+ var restoreCommentEffect = StateEffect2.define({
1280
+ map: mapTrackedComment
1281
+ });
1282
+ var optionsFacet = Facet3.define({
1283
+ combine: (providers) => providers[0]
1284
+ });
1285
+ var createComment = (view) => {
1286
+ const options = view.state.facet(optionsFacet);
1287
+ const { from, to } = view.state.selection.main;
1288
+ if (from === to) {
1289
+ return false;
1290
+ }
1291
+ if (to === view.state.doc.length) {
1292
+ view.dispatch({
1293
+ changes: {
1294
+ from: to,
1295
+ insert: "\n"
1296
+ }
1322
1297
  });
1323
- const { from, to } = view.state.selection.main;
1324
- if (from === to) {
1325
- return false;
1326
- }
1327
- if (to === view.state.doc.length) {
1298
+ }
1299
+ const cursor = Cursor.getCursorFromRange(view.state, {
1300
+ from,
1301
+ to
1302
+ });
1303
+ if (cursor) {
1304
+ const id = options.onCreate?.(cursor, view.coordsAtPos(from));
1305
+ if (id) {
1328
1306
  view.dispatch({
1329
- changes: {
1330
- from: to,
1331
- insert: "\n"
1307
+ effects: setSelection.of({
1308
+ current: id
1309
+ }),
1310
+ selection: {
1311
+ anchor: to
1332
1312
  }
1333
1313
  });
1314
+ return true;
1334
1315
  }
1335
- const cursor = Cursor.getCursorFromRange(view.state, {
1336
- from,
1337
- to
1338
- });
1339
- if (cursor) {
1340
- const id = options.onCreate?.(cursor, view.coordsAtPos(from));
1341
- if (id) {
1342
- view.dispatch({
1343
- effects: setSelection.of({
1344
- active: id
1345
- }),
1346
- selection: {
1347
- anchor: from
1348
- }
1349
- });
1350
- return true;
1351
- }
1352
- }
1353
- return false;
1354
- };
1316
+ }
1317
+ return false;
1318
+ };
1319
+ var comments = (options = {}) => {
1320
+ const { key: shortcut = "meta-'" } = options;
1321
+ const handleSelect = debounce((state) => options.onSelect?.(state), 200);
1355
1322
  return [
1323
+ optionsFacet.of(options),
1356
1324
  commentsState,
1357
- highlightDecorations,
1358
- styles3,
1325
+ commentsDecorations,
1326
+ styles2,
1359
1327
  //
1360
1328
  // Keymap.
1361
1329
  //
1362
1330
  options.onCreate ? keymap3.of([
1363
1331
  {
1364
1332
  key: shortcut,
1365
- run: callbackWrapper(createCommentThread)
1333
+ run: callbackWrapper(createComment)
1366
1334
  }
1367
1335
  ]) : [],
1368
1336
  //
@@ -1398,7 +1366,7 @@ var comments = (options = {}) => {
1398
1366
  //
1399
1367
  // Track deleted ranges and update ranges for decorations.
1400
1368
  //
1401
- EditorView6.updateListener.of(({ view, state, changes }) => {
1369
+ EditorView5.updateListener.of(({ view, state, changes }) => {
1402
1370
  let mod = false;
1403
1371
  const { comments: comments2, ...value } = state.field(commentsState);
1404
1372
  changes.iterChanges((from, to, from2, to2) => {
@@ -1428,17 +1396,17 @@ var comments = (options = {}) => {
1428
1396
  //
1429
1397
  // Track selection/proximity.
1430
1398
  //
1431
- EditorView6.updateListener.of(({ view, state, changes }) => {
1399
+ EditorView5.updateListener.of(({ view, state }) => {
1432
1400
  let min = Infinity;
1433
- const { selection: { active, closest }, comments: comments2 } = state.field(commentsState);
1401
+ const { selection: { current, closest }, comments: comments2 } = state.field(commentsState);
1434
1402
  const { head } = state.selection.main;
1435
1403
  const selection = {};
1436
1404
  comments2.forEach(({ comment, range }) => {
1437
1405
  if (head >= range.from && head <= range.to) {
1438
- selection.active = comment.id;
1406
+ selection.current = comment.id;
1439
1407
  selection.closest = void 0;
1440
1408
  }
1441
- if (!selection.active) {
1409
+ if (!selection.current) {
1442
1410
  const d = Math.min(Math.abs(head - range.from), Math.abs(head - range.to));
1443
1411
  if (d < min) {
1444
1412
  selection.closest = comment.id;
@@ -1446,7 +1414,7 @@ var comments = (options = {}) => {
1446
1414
  }
1447
1415
  }
1448
1416
  });
1449
- if (selection.active !== active || selection.closest !== closest) {
1417
+ if (selection.current !== current || selection.closest !== closest) {
1450
1418
  view.dispatch({
1451
1419
  effects: setSelection.of(selection)
1452
1420
  });
@@ -1463,9 +1431,9 @@ var comments = (options = {}) => {
1463
1431
  options.onUpdate ? trackPastedComments(options.onUpdate) : []
1464
1432
  ];
1465
1433
  };
1466
- var useComments = (view, comments2) => {
1467
- useEffect2(() => {
1468
- if (view && comments2) {
1434
+ var useComments = (view, comments2 = []) => {
1435
+ useEffect(() => {
1436
+ if (view) {
1469
1437
  view.dispatch({
1470
1438
  effects: setComments.of(comments2)
1471
1439
  });
@@ -1476,314 +1444,51 @@ var useComments = (view, comments2) => {
1476
1444
  ]);
1477
1445
  };
1478
1446
 
1479
- // packages/ui/react-ui-editor/src/extensions/hr.ts
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({
1484
- "& .cm-hr": {
1485
- // Note that block-level decorations should not have vertical margins,
1486
- borderTop: `1px solid ${getToken("extend.colors.neutral.200")}`
1487
- }
1488
- });
1489
- var HorizontalRuleWidget = class extends WidgetType2 {
1490
- toDOM() {
1491
- const el = document.createElement("div");
1492
- el.className = "cm-hr";
1493
- return el;
1494
- }
1495
- };
1496
- var decoration = Decoration4.replace({
1497
- widget: new HorizontalRuleWidget()
1498
- });
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
1530
- })
1531
- ];
1447
+ // packages/ui/react-ui-editor/src/extensions/listener.ts
1448
+ import { EditorView as EditorView6 } from "@codemirror/view";
1449
+ var listener = ({ onFocus, onChange }) => {
1450
+ const extensions = [];
1451
+ onFocus && extensions.push(EditorView6.focusChangeEffect.of((_, focused) => {
1452
+ onFocus(focused);
1453
+ return null;
1454
+ }));
1455
+ onChange && extensions.push(EditorView6.updateListener.of((update2) => {
1456
+ onChange(update2.state.doc.toString());
1457
+ }));
1458
+ return extensions;
1532
1459
  };
1533
1460
 
1534
- // packages/ui/react-ui-editor/src/extensions/image.ts
1535
- import { syntaxTree as syntaxTree2 } from "@codemirror/language";
1536
- import { StateField as StateField3 } from "@codemirror/state";
1537
- import { Decoration as Decoration5, EditorView as EditorView8, WidgetType as WidgetType3 } from "@codemirror/view";
1538
- var image = (options = {}) => {
1539
- return StateField3.define({
1540
- create: (state) => {
1541
- return Decoration5.set(buildDecorations2(0, state.doc.length, state));
1542
- },
1543
- update: (value, tr) => {
1544
- if (!tr.docChanged && !tr.selection) {
1545
- return value;
1546
- }
1547
- const cursor = tr.state.selection.main.head;
1548
- const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
1549
- let from = Math.min(cursor, oldCursor);
1550
- let to = Math.max(cursor, oldCursor);
1551
- tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
1552
- from = Math.min(from, fromB);
1553
- to = Math.max(to, toB);
1554
- });
1555
- from = tr.state.doc.lineAt(from).from;
1556
- to = tr.state.doc.lineAt(to).to;
1557
- return value.map(tr.changes).update({
1558
- filterFrom: from,
1559
- filterTo: to,
1560
- filter: () => false,
1561
- add: buildDecorations2(from, to, tr.state)
1562
- });
1563
- },
1564
- provide: (field) => EditorView8.decorations.from(field)
1565
- });
1566
- };
1567
- var buildDecorations2 = (from, to, state) => {
1568
- const decorations = [];
1569
- const cursor = state.selection.main.head;
1570
- syntaxTree2(state).iterate({
1571
- enter: (node) => {
1572
- if (node.name === "Image") {
1573
- const urlNode = node.node.getChild("URL");
1574
- if (urlNode) {
1575
- const hide = state.readOnly || cursor < node.from || cursor > node.to;
1576
- const url = state.sliceDoc(urlNode.from, urlNode.to);
1577
- decorations.push(Decoration5.replace({
1578
- block: true,
1579
- widget: new ImageWidget(url)
1580
- }).range(hide ? node.from : node.to, node.to));
1581
- }
1582
- }
1583
- },
1584
- from,
1585
- to
1586
- });
1587
- return decorations;
1588
- };
1589
- var ImageWidget = class extends WidgetType3 {
1590
- constructor(_url) {
1591
- super();
1592
- this._url = _url;
1593
- }
1594
- eq(other) {
1595
- return this._url === other._url;
1596
- }
1597
- toDOM(view) {
1598
- const img = document.createElement("img");
1599
- img.setAttribute("src", this._url);
1600
- img.setAttribute("class", "cm-image");
1601
- img.onload = () => img.classList.add("cm-loaded-image");
1602
- return img;
1603
- }
1604
- };
1605
-
1606
- // packages/ui/react-ui-editor/src/extensions/link.ts
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";
1610
- import { tooltipContent } from "@dxos/react-ui-theme";
1611
- var link = (options = {}) => {
1612
- const extensions = [
1613
- ViewPlugin4.fromClass(class {
1614
- constructor(view) {
1615
- this.decorations = buildDecorations3(view, options);
1616
- }
1617
- update(update2) {
1618
- if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
1619
- this.decorations = buildDecorations3(update2.view, options);
1620
- }
1621
- }
1622
- }, {
1623
- decorations: (v) => v.decorations
1624
- })
1625
- ];
1626
- if (options.onHover) {
1627
- extensions.push(
1628
- // https://codemirror.net/examples/tooltip
1629
- // https://codemirror.net/docs/ref/#view.hoverTooltip
1630
- // https://github.com/codemirror/view/blob/main/src/tooltip.ts
1631
- hoverTooltip2((view, pos, side) => {
1632
- const syntax = syntaxTree3(view.state).resolveInner(pos, side);
1633
- let link2 = null;
1634
- for (let i = 0, node = syntax; !link2 && node && i < 5; node = node.parent, i++) {
1635
- link2 = node.name === "Link" ? node : null;
1636
- }
1637
- const url = link2 && link2.getChild("URL");
1638
- if (!url || !link2) {
1639
- return null;
1640
- }
1641
- const urlText = view.state.sliceDoc(url.from, url.to);
1642
- return {
1643
- pos: link2.from,
1644
- end: link2.to,
1645
- above: true,
1646
- create: () => {
1647
- const el = document.createElement("div");
1648
- el.className = tooltipContent({}, "pli-2 plb-1");
1649
- options.onHover(el, urlText);
1650
- return {
1651
- dom: el,
1652
- offset: {
1653
- x: 0,
1654
- y: 4
1655
- }
1656
- };
1657
- }
1658
- };
1659
- })
1660
- );
1661
- }
1662
- return extensions;
1663
- };
1664
- var LinkButton = class extends WidgetType4 {
1665
- constructor(_url, _onAttach) {
1666
- super();
1667
- this._url = _url;
1668
- this._onAttach = _onAttach;
1669
- }
1670
- eq(other) {
1671
- return this._url === other._url;
1672
- }
1673
- toDOM(view) {
1674
- const el = document.createElement("span");
1675
- this._onAttach(el, this._url);
1676
- return el;
1677
- }
1678
- };
1679
- var LinkText = class extends WidgetType4 {
1680
- constructor(_text, _url) {
1681
- super();
1682
- this._text = _text;
1683
- this._url = _url;
1684
- }
1685
- eq(other) {
1686
- return this._url === other._url;
1687
- }
1688
- toDOM(view) {
1689
- const link2 = document.createElement("a");
1690
- link2.setAttribute("class", "cm-link");
1691
- link2.textContent = this._text;
1692
- if (this._url) {
1693
- link2.setAttribute("rel", "noreferrer");
1694
- link2.setAttribute("target", "_blank");
1695
- link2.href = this._url;
1696
- } else {
1697
- link2.onclick = () => {
1698
- view.dispatch({
1699
- selection: {
1700
- anchor: view.posAtDOM(link2)
1701
- }
1702
- });
1703
- };
1704
- }
1705
- return link2;
1706
- }
1707
- };
1708
- var buildDecorations3 = (view, options) => {
1709
- const builder = new RangeSetBuilder2();
1710
- const { state } = view;
1711
- const cursor = state.selection.main.head;
1712
- for (const { from, to } of view.visibleRanges) {
1713
- syntaxTree3(state).iterate({
1714
- enter: (node) => {
1715
- if (node.name === "Link") {
1716
- const marks2 = node.node.getChildren("LinkMark");
1717
- const text = marks2.length >= 2 ? state.sliceDoc(marks2[0].to, marks2[1].from) : "";
1718
- const urlNode = node.node.getChild("URL");
1719
- const url = urlNode ? state.sliceDoc(urlNode.from, urlNode.to) : "";
1720
- if (!url) {
1721
- return false;
1722
- }
1723
- if (!view.hasFocus || state.readOnly || cursor < node.from || cursor > node.to) {
1724
- builder.add(node.from, node.to, Decoration6.replace({
1725
- widget: new LinkText(text, options.link ? url : void 0)
1726
- }));
1727
- }
1728
- if (options.onRender) {
1729
- builder.add(node.to, node.to, Decoration6.replace({
1730
- widget: new LinkButton(url, options.onRender)
1731
- }));
1732
- }
1733
- return false;
1734
- }
1735
- },
1736
- from,
1737
- to
1738
- });
1739
- }
1740
- return builder.finish();
1741
- };
1742
-
1743
- // packages/ui/react-ui-editor/src/extensions/listener.ts
1744
- import { EditorView as EditorView9 } from "@codemirror/view";
1745
- var listener = ({ onFocus, onChange }) => {
1746
- const extensions = [];
1747
- onFocus && extensions.push(EditorView9.focusChangeEffect.of((_, focused) => {
1748
- onFocus(focused);
1749
- return null;
1750
- }));
1751
- onChange && extensions.push(EditorView9.updateListener.of((update2) => {
1752
- onChange(update2.state.doc.toString());
1753
- }));
1754
- return extensions;
1755
- };
1756
-
1757
- // packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
1758
- import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
1759
- import { history as history2, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
1760
- import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
1761
- import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
1762
- import { languages } from "@codemirror/language-data";
1763
- import { searchKeymap } from "@codemirror/search";
1764
- import { EditorState } from "@codemirror/state";
1765
- import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
1766
- import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView10, highlightActiveLine as highlightActiveLine2, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1767
-
1768
- // packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
1769
- import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
1770
- import { HighlightStyle } from "@codemirror/language";
1771
- import { tags, styleTags, Tag } from "@lezer/highlight";
1772
- import { Table } from "@lezer/markdown";
1773
- var markdownTags = {
1774
- Blockquote: Tag.define(),
1775
- CodeMark: Tag.define(),
1776
- CodeText: Tag.define(),
1777
- EmphasisMark: Tag.define(),
1778
- HeaderMark: Tag.define(),
1779
- InlineCode: Tag.define(),
1780
- LinkLabel: Tag.define(),
1781
- LinkReference: Tag.define(),
1782
- ListMark: Tag.define(),
1783
- QuoteMark: Tag.define(),
1784
- URL: Tag.define(),
1785
- // Custom.
1786
- TableCell: Tag.define()
1461
+ // packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
1462
+ import { closeBrackets as closeBrackets2, closeBracketsKeymap } from "@codemirror/autocomplete";
1463
+ import { history as history2, historyKeymap, indentWithTab, standardKeymap } from "@codemirror/commands";
1464
+ import { markdownLanguage as markdownLanguage3, markdown } from "@codemirror/lang-markdown";
1465
+ import { bracketMatching as bracketMatching2, defaultHighlightStyle as defaultHighlightStyle2, indentOnInput, syntaxHighlighting as syntaxHighlighting2 } from "@codemirror/language";
1466
+ import { languages } from "@codemirror/language-data";
1467
+ import { searchKeymap } from "@codemirror/search";
1468
+ import { EditorState } from "@codemirror/state";
1469
+ import { oneDarkHighlightStyle as oneDarkHighlightStyle2 } from "@codemirror/theme-one-dark";
1470
+ import { crosshairCursor, drawSelection as drawSelection2, dropCursor, EditorView as EditorView7, highlightActiveLine as highlightActiveLine2, keymap as keymap4, placeholder as placeholder2 } from "@codemirror/view";
1471
+ import { isNotFalsy as isNotFalsy2 } from "@dxos/util";
1472
+
1473
+ // packages/ui/react-ui-editor/src/extensions/markdown/highlight.ts
1474
+ import { markdownLanguage as markdownLanguage2 } from "@codemirror/lang-markdown";
1475
+ import { HighlightStyle } from "@codemirror/language";
1476
+ import { tags, styleTags, Tag } from "@lezer/highlight";
1477
+ import { Table } from "@lezer/markdown";
1478
+ var markdownTags = {
1479
+ Blockquote: Tag.define(),
1480
+ CodeMark: Tag.define(),
1481
+ CodeText: Tag.define(),
1482
+ EmphasisMark: Tag.define(),
1483
+ HeaderMark: Tag.define(),
1484
+ InlineCode: Tag.define(),
1485
+ LinkLabel: Tag.define(),
1486
+ LinkReference: Tag.define(),
1487
+ ListMark: Tag.define(),
1488
+ QuoteMark: Tag.define(),
1489
+ URL: Tag.define(),
1490
+ // Custom.
1491
+ TableCell: Tag.define()
1787
1492
  };
1788
1493
  Table.defineNodes?.forEach((node) => {
1789
1494
  switch (node?.name) {
@@ -1860,7 +1565,7 @@ var markdownHighlightStyle = (readonly) => {
1860
1565
  markdownTags.QuoteMark,
1861
1566
  markdownTags.EmphasisMark
1862
1567
  ],
1863
- class: readonly ? "hidden" : mark
1568
+ class: mark
1864
1569
  },
1865
1570
  // E.g., code block language (after ```).
1866
1571
  {
@@ -1868,7 +1573,7 @@ var markdownHighlightStyle = (readonly) => {
1868
1573
  tags.function(tags.variableName),
1869
1574
  tags.labelName
1870
1575
  ],
1871
- class: readonly ? "hidden" : codeMark
1576
+ class: codeMark
1872
1577
  },
1873
1578
  {
1874
1579
  tag: [
@@ -1879,27 +1584,27 @@ var markdownHighlightStyle = (readonly) => {
1879
1584
  // Headings.
1880
1585
  {
1881
1586
  tag: tags.heading1,
1882
- class: heading(1, readonly)
1587
+ class: heading(1)
1883
1588
  },
1884
1589
  {
1885
1590
  tag: tags.heading2,
1886
- class: heading(2, readonly)
1591
+ class: heading(2)
1887
1592
  },
1888
1593
  {
1889
1594
  tag: tags.heading3,
1890
- class: heading(3, readonly)
1595
+ class: heading(3)
1891
1596
  },
1892
1597
  {
1893
1598
  tag: tags.heading4,
1894
- class: heading(4, readonly)
1599
+ class: heading(4)
1895
1600
  },
1896
1601
  {
1897
1602
  tag: tags.heading5,
1898
- class: heading(5, readonly)
1603
+ class: heading(5)
1899
1604
  },
1900
1605
  {
1901
1606
  tag: tags.heading6,
1902
- class: heading(6, readonly)
1607
+ class: heading(6)
1903
1608
  },
1904
1609
  // Emphasis.
1905
1610
  {
@@ -1925,7 +1630,7 @@ var markdownHighlightStyle = (readonly) => {
1925
1630
  // However, since `codeLanguages` is also defined, the `lezer` will not parse fenced code blocks,
1926
1631
  // when a language is specified. In this case, the syntax highlighting extensions will colorize
1927
1632
  // the code, but all other CSS properties will be inherited.
1928
- // IMPORTANT: Therefore, the fenced code block will use the base editor font.
1633
+ // IMPORTANT: Therefore, the fenced code block will use the base editor font unless changed by an extension.
1929
1634
  {
1930
1635
  tag: [
1931
1636
  markdownTags.CodeText,
@@ -1954,11 +1659,11 @@ var markdownHighlightStyle = (readonly) => {
1954
1659
  };
1955
1660
 
1956
1661
  // packages/ui/react-ui-editor/src/extensions/markdown/bundle.ts
1957
- var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
1662
+ var createMarkdownExtensions = ({ themeMode, placeholder: _placeholder, lineWrapping = true } = {}) => {
1958
1663
  return [
1664
+ lineWrapping && EditorView7.lineWrapping,
1959
1665
  EditorState.allowMultipleSelections.of(true),
1960
1666
  EditorState.tabSize.of(2),
1961
- EditorView10.lineWrapping,
1962
1667
  // https://github.com/codemirror/basic-setup
1963
1668
  bracketMatching2(),
1964
1669
  closeBrackets2(),
@@ -1968,7 +1673,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
1968
1673
  highlightActiveLine2(),
1969
1674
  history2(),
1970
1675
  indentOnInput(),
1971
- _placeholder ? placeholder2(_placeholder) : [],
1676
+ _placeholder && placeholder2(_placeholder),
1972
1677
  // Main extension.
1973
1678
  // https://github.com/codemirror/lang-markdown
1974
1679
  // https://codemirror.net/5/mode/markdown/index.html (demo).
@@ -1990,7 +1695,7 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
1990
1695
  // https://github.com/codemirror/theme-one-dark
1991
1696
  themeMode === "dark" ? syntaxHighlighting2(oneDarkHighlightStyle2) : syntaxHighlighting2(defaultHighlightStyle2),
1992
1697
  // Custom styles.
1993
- syntaxHighlighting2(markdownHighlightStyle(readonly)),
1698
+ syntaxHighlighting2(markdownHighlightStyle()),
1994
1699
  keymap4.of([
1995
1700
  // https://codemirror.net/docs/ref/#commands.indentWithTab
1996
1701
  indentWithTab,
@@ -2003,47 +1708,580 @@ var markdownBundle = ({ readonly, themeMode, placeholder: _placeholder }) => {
2003
1708
  // https://codemirror.net/docs/ref/#commands.standardKeymap
2004
1709
  ...standardKeymap
2005
1710
  ])
2006
- ];
1711
+ ].filter(isNotFalsy2);
2007
1712
  };
2008
1713
 
2009
- // packages/ui/react-ui-editor/src/extensions/mention.ts
2010
- import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
2011
- var mention = ({ onSearch }) => {
2012
- return autocompletion2({
2013
- // TODO(burdon): Not working.
2014
- activateOnTyping: true,
2015
- // activateOnTypingDelay: 100,
2016
- // selectOnOpen: true,
2017
- closeOnBlur: false,
2018
- // defaultKeymap: false,
2019
- icons: false,
2020
- override: [
2021
- (context) => {
2022
- console.log(context);
2023
- const match = context.matchBefore(/@(\w+)?/);
2024
- if (!match || match.from === match.to && !context.explicit) {
2025
- return null;
2026
- }
2027
- return {
2028
- from: match.from,
2029
- options: onSearch(match.text.slice(1).toLowerCase()).map((value) => ({
2030
- label: `@${value}`
2031
- }))
2032
- };
2033
- }
2034
- ]
2035
- });
1714
+ // packages/ui/react-ui-editor/src/extensions/markdown/code.ts
1715
+ import { syntaxTree } from "@codemirror/language";
1716
+ import { RangeSetBuilder } from "@codemirror/state";
1717
+ import { ViewPlugin as ViewPlugin3, EditorView as EditorView8, Decoration as Decoration3, WidgetType as WidgetType2 } from "@codemirror/view";
1718
+ import { mx as mx2 } from "@dxos/react-ui-theme";
1719
+ var styles3 = EditorView8.baseTheme({
1720
+ "& .cm-code": {
1721
+ fontFamily: getToken("fontFamily.mono", []).join(",")
1722
+ },
1723
+ "& .cm-codeblock": {
1724
+ width: "100%",
1725
+ paddingInline: "1rem !important",
1726
+ position: "relative",
1727
+ "&::after": {
1728
+ content: '""',
1729
+ position: "absolute",
1730
+ inset: 0
1731
+ }
1732
+ },
1733
+ "&light .cm-codeblock": {
1734
+ "&::after": {
1735
+ background: getToken("extend.semanticColors.input.light"),
1736
+ mixBlendMode: "darken"
1737
+ }
1738
+ },
1739
+ "&dark .cm-codeblock": {
1740
+ "&::after": {
1741
+ background: getToken("extend.semanticColors.input.dark"),
1742
+ mixBlendMode: "lighten"
1743
+ }
1744
+ },
1745
+ "& .cm-codeblock-first": {
1746
+ display: "inline-block",
1747
+ "&::after": {
1748
+ borderTopLeftRadius: ".5rem",
1749
+ borderTopRightRadius: ".5rem"
1750
+ }
1751
+ },
1752
+ "& .cm-codeblock-last": {
1753
+ display: "inline-block",
1754
+ "&::after": {
1755
+ borderBottomLeftRadius: ".5rem",
1756
+ borderBottomRightRadius: ".5rem"
1757
+ }
1758
+ }
1759
+ });
1760
+ var getLineRange = (lines, from, to) => {
1761
+ const start = lines.findIndex((line) => line.from >= from);
1762
+ const end = lines.findIndex((line) => line.to >= to);
1763
+ return [
1764
+ start,
1765
+ end
1766
+ ];
2036
1767
  };
2037
-
2038
- // packages/ui/react-ui-editor/src/extensions/outliner.ts
2039
- var outliner = (options = {}) => {
2040
- return [];
1768
+ var LineWidget = class extends WidgetType2 {
1769
+ constructor(_className) {
1770
+ super();
1771
+ this._className = _className;
1772
+ }
1773
+ toDOM() {
1774
+ const el = document.createElement("span");
1775
+ el.innerHTML = "&nbsp;";
1776
+ el.className = mx2("cm-code cm-codeblock", this._className);
1777
+ return el;
1778
+ }
1779
+ };
1780
+ var top = new LineWidget("cm-codeblock-first");
1781
+ var bottom = new LineWidget("cm-codeblock-last");
1782
+ var buildDecorations = (view) => {
1783
+ const builder = new RangeSetBuilder();
1784
+ const { state } = view;
1785
+ const blocks = view.viewportLineBlocks;
1786
+ const cursor = state.selection.main.head;
1787
+ for (const { from, to } of view.visibleRanges) {
1788
+ syntaxTree(state).iterate({
1789
+ enter: (node) => {
1790
+ if (node.name === "FencedCode") {
1791
+ const edit = !view.state.readOnly && cursor >= node.from && cursor <= node.to;
1792
+ const range = getLineRange(blocks, node.from, node.to);
1793
+ for (let i = range[0]; i <= range[1]; i++) {
1794
+ const block = blocks[i];
1795
+ if (!edit && (i === range[0] || i === range[1])) {
1796
+ builder.add(block.from, block.to, Decoration3.replace({
1797
+ widget: i === range[0] ? top : bottom
1798
+ }));
1799
+ } else {
1800
+ builder.add(block.from, block.from, Decoration3.line({
1801
+ class: mx2("cm-code cm-codeblock", i === range[0] && "cm-codeblock-first", i === range[1] && "cm-codeblock-last")
1802
+ }));
1803
+ }
1804
+ }
1805
+ }
1806
+ },
1807
+ from,
1808
+ to
1809
+ });
1810
+ }
1811
+ return builder.finish();
1812
+ };
1813
+ var code2 = () => {
1814
+ return [
1815
+ ViewPlugin3.fromClass(class {
1816
+ constructor(view) {
1817
+ this.decorations = buildDecorations(view);
1818
+ }
1819
+ update(update2) {
1820
+ this.decorations = buildDecorations(update2.view);
1821
+ }
1822
+ }, {
1823
+ decorations: (value) => value.decorations
1824
+ }),
1825
+ styles3
1826
+ ];
1827
+ };
1828
+
1829
+ // packages/ui/react-ui-editor/src/extensions/markdown/formatting.ts
1830
+ import { snippet } from "@codemirror/autocomplete";
1831
+ import { syntaxTree as syntaxTree2 } from "@codemirror/language";
1832
+ import { RangeSetBuilder as RangeSetBuilder2 } from "@codemirror/state";
1833
+ import { Decoration as Decoration4, keymap as keymap5, ViewPlugin as ViewPlugin4 } from "@codemirror/view";
1834
+ var setHeading = (level) => (view) => {
1835
+ const { selection: { ranges }, doc } = view.state;
1836
+ const changes = [];
1837
+ for (const range of ranges) {
1838
+ const { number } = doc.lineAt(range.anchor);
1839
+ const { from, to } = doc.line(number);
1840
+ const line = doc.sliceString(from, to);
1841
+ const [_, marks, spaces] = line.match(/(#+)(\s+)/) ?? [];
1842
+ const current = marks?.length ?? 0;
1843
+ if (level !== current) {
1844
+ changes.push({
1845
+ from,
1846
+ to: from + current + (spaces?.length ?? 0),
1847
+ insert: "#".repeat(level) + (level > 0 ? " " : "")
1848
+ });
1849
+ }
1850
+ }
1851
+ if (changes.length) {
1852
+ view.dispatch({
1853
+ changes
1854
+ });
1855
+ }
1856
+ return true;
1857
+ };
1858
+ var toggleStyle = (mark2) => (view) => {
1859
+ const { ranges } = view.state.selection;
1860
+ for (const range of ranges) {
1861
+ if (range.from === range.to) {
1862
+ return false;
1863
+ }
1864
+ view.dispatch({
1865
+ changes: [
1866
+ {
1867
+ from: range.from,
1868
+ insert: mark2
1869
+ },
1870
+ {
1871
+ from: range.to,
1872
+ insert: mark2
1873
+ }
1874
+ ]
1875
+ });
1876
+ }
1877
+ return true;
1878
+ };
1879
+ var snippets = {
1880
+ codeblock: snippet([
1881
+ "```#{lang}",
1882
+ " #{}",
1883
+ "```"
1884
+ ].join("\n")),
1885
+ table: snippet([
1886
+ "| #{col1} | #{col2} |",
1887
+ "| ---- | ---- |",
1888
+ "| #{val1} | #{val2} |",
1889
+ "| #{val3} | #{val4} |"
1890
+ ].join("\n"))
1891
+ };
1892
+ var insertCodeblock = (view) => {
1893
+ const { selection: { main }, doc } = view.state;
1894
+ const { number } = doc.lineAt(main.anchor);
1895
+ const { from } = doc.line(number);
1896
+ snippets.codeblock(view, null, from, from);
1897
+ };
1898
+ var insertTable = (view) => {
1899
+ const { selection: { main }, doc } = view.state;
1900
+ const { number } = doc.lineAt(main.anchor);
1901
+ const { from } = doc.line(number);
1902
+ snippets.table(view, null, from, from);
1903
+ };
1904
+ var toggleBold = toggleStyle("**");
1905
+ var toggleItalic = toggleStyle("_");
1906
+ var toggleStrikethrough = toggleStyle("~~");
1907
+ var toggleList = (view) => {
1908
+ };
1909
+ var formatting = (options = {}) => {
1910
+ return [
1911
+ keymap5.of([
1912
+ {
1913
+ key: "meta-b",
1914
+ run: toggleBold
1915
+ }
1916
+ ]),
1917
+ styling()
1918
+ ];
1919
+ };
1920
+ var styling = () => {
1921
+ const buildDecorations7 = (view) => {
1922
+ const builder = new RangeSetBuilder2();
1923
+ const { state } = view;
1924
+ const cursor = state.selection.main.head;
1925
+ const replace = (node, marks) => {
1926
+ if (cursor <= node.from || cursor >= node.to) {
1927
+ for (const mark2 of marks) {
1928
+ builder.add(mark2.from, mark2.to, Decoration4.replace({}));
1929
+ }
1930
+ }
1931
+ };
1932
+ for (const { from, to } of view.visibleRanges) {
1933
+ syntaxTree2(state).iterate({
1934
+ enter: (node) => {
1935
+ switch (node.name) {
1936
+ case "Emphasis":
1937
+ case "StrongEmphasis": {
1938
+ const marks = node.node.getChildren("EmphasisMark");
1939
+ replace(node, marks);
1940
+ break;
1941
+ }
1942
+ case "Strikethrough": {
1943
+ const marks = node.node.getChildren("StrikethroughMark");
1944
+ replace(node, marks);
1945
+ break;
1946
+ }
1947
+ }
1948
+ },
1949
+ from,
1950
+ to
1951
+ });
1952
+ }
1953
+ return builder.finish();
1954
+ };
1955
+ return [
1956
+ ViewPlugin4.fromClass(class {
1957
+ constructor(view) {
1958
+ this.decorations = buildDecorations7(view);
1959
+ }
1960
+ update(update2) {
1961
+ this.decorations = buildDecorations7(update2.view);
1962
+ }
1963
+ }, {
1964
+ decorations: (value) => value.decorations
1965
+ })
1966
+ ];
1967
+ };
1968
+
1969
+ // packages/ui/react-ui-editor/src/extensions/markdown/heading.ts
1970
+ import { syntaxTree as syntaxTree3 } from "@codemirror/language";
1971
+ import { RangeSetBuilder as RangeSetBuilder3 } from "@codemirror/state";
1972
+ import { Decoration as Decoration5, ViewPlugin as ViewPlugin5 } from "@codemirror/view";
1973
+ var buildDecorations2 = (view) => {
1974
+ const builder = new RangeSetBuilder3();
1975
+ const { state } = view;
1976
+ const cursor = state.selection.main.head;
1977
+ for (const { from, to } of view.visibleRanges) {
1978
+ syntaxTree3(state).iterate({
1979
+ enter: (node) => {
1980
+ switch (node.name) {
1981
+ case "ATXHeading1":
1982
+ case "ATXHeading2":
1983
+ case "ATXHeading3":
1984
+ case "ATXHeading4":
1985
+ case "ATXHeading5":
1986
+ case "ATXHeading6": {
1987
+ const mark2 = node.node.getChild("HeaderMark");
1988
+ if (mark2) {
1989
+ if (!view.hasFocus || view.state.readOnly || cursor < node.from || cursor > node.to) {
1990
+ builder.add(mark2.from, mark2.to + 1, Decoration5.replace({}));
1991
+ }
1992
+ }
1993
+ }
1994
+ }
1995
+ },
1996
+ from,
1997
+ to
1998
+ });
1999
+ }
2000
+ return builder.finish();
2001
+ };
2002
+ var heading2 = () => {
2003
+ return [
2004
+ ViewPlugin5.fromClass(class {
2005
+ constructor(view) {
2006
+ this.decorations = buildDecorations2(view);
2007
+ }
2008
+ update(update2) {
2009
+ this.decorations = buildDecorations2(update2.view);
2010
+ }
2011
+ }, {
2012
+ decorations: (value) => value.decorations
2013
+ })
2014
+ ];
2015
+ };
2016
+
2017
+ // packages/ui/react-ui-editor/src/extensions/markdown/hr.ts
2018
+ import { syntaxTree as syntaxTree4 } from "@codemirror/language";
2019
+ import { RangeSetBuilder as RangeSetBuilder4 } from "@codemirror/state";
2020
+ import { Decoration as Decoration6, EditorView as EditorView9, ViewPlugin as ViewPlugin6, WidgetType as WidgetType3 } from "@codemirror/view";
2021
+ var styles4 = EditorView9.baseTheme({
2022
+ "& .cm-hr": {
2023
+ // Note that block-level decorations should not have vertical margins,
2024
+ borderTop: `1px solid ${getToken("extend.colors.neutral.200")}`
2025
+ }
2026
+ });
2027
+ var HorizontalRuleWidget = class extends WidgetType3 {
2028
+ toDOM() {
2029
+ const el = document.createElement("div");
2030
+ el.className = "cm-hr";
2031
+ return el;
2032
+ }
2033
+ };
2034
+ var decoration = Decoration6.replace({
2035
+ widget: new HorizontalRuleWidget()
2036
+ });
2037
+ var buildDecorations3 = (view) => {
2038
+ const builder = new RangeSetBuilder4();
2039
+ const { state } = view;
2040
+ const cursor = state.selection.main.head;
2041
+ for (const { from, to } of view.visibleRanges) {
2042
+ syntaxTree4(state).iterate({
2043
+ enter: (node) => {
2044
+ if (node.name === "HorizontalRule") {
2045
+ if (cursor <= node.from || cursor >= node.to) {
2046
+ builder.add(node.from, node.to, decoration);
2047
+ }
2048
+ }
2049
+ },
2050
+ from,
2051
+ to
2052
+ });
2053
+ }
2054
+ return builder.finish();
2055
+ };
2056
+ var hr = () => {
2057
+ return [
2058
+ ViewPlugin6.fromClass(class {
2059
+ constructor(view) {
2060
+ this.decorations = buildDecorations3(view);
2061
+ }
2062
+ update(update2) {
2063
+ this.decorations = buildDecorations3(update2.view);
2064
+ }
2065
+ }, {
2066
+ decorations: (value) => value.decorations
2067
+ }),
2068
+ styles4
2069
+ ];
2070
+ };
2071
+
2072
+ // packages/ui/react-ui-editor/src/extensions/markdown/image.ts
2073
+ import { syntaxTree as syntaxTree5 } from "@codemirror/language";
2074
+ import { StateField as StateField3 } from "@codemirror/state";
2075
+ import { Decoration as Decoration7, EditorView as EditorView10, WidgetType as WidgetType4 } from "@codemirror/view";
2076
+ var image = (options = {}) => {
2077
+ return StateField3.define({
2078
+ create: (state) => {
2079
+ return Decoration7.set(buildDecorations4(0, state.doc.length, state));
2080
+ },
2081
+ update: (value, tr) => {
2082
+ if (!tr.docChanged && !tr.selection) {
2083
+ return value;
2084
+ }
2085
+ const cursor = tr.state.selection.main.head;
2086
+ const oldCursor = tr.changes.mapPos(tr.startState.selection.main.head);
2087
+ let from = Math.min(cursor, oldCursor);
2088
+ let to = Math.max(cursor, oldCursor);
2089
+ tr.changes.iterChangedRanges((fromA, toA, fromB, toB) => {
2090
+ from = Math.min(from, fromB);
2091
+ to = Math.max(to, toB);
2092
+ });
2093
+ from = tr.state.doc.lineAt(from).from;
2094
+ to = tr.state.doc.lineAt(to).to;
2095
+ return value.map(tr.changes).update({
2096
+ filterFrom: from,
2097
+ filterTo: to,
2098
+ filter: () => false,
2099
+ add: buildDecorations4(from, to, tr.state)
2100
+ });
2101
+ },
2102
+ provide: (field) => EditorView10.decorations.from(field)
2103
+ });
2104
+ };
2105
+ var buildDecorations4 = (from, to, state) => {
2106
+ const decorations = [];
2107
+ const cursor = state.selection.main.head;
2108
+ syntaxTree5(state).iterate({
2109
+ enter: (node) => {
2110
+ if (node.name === "Image") {
2111
+ const urlNode = node.node.getChild("URL");
2112
+ if (urlNode) {
2113
+ const hide = state.readOnly || cursor < node.from || cursor > node.to;
2114
+ const url = state.sliceDoc(urlNode.from, urlNode.to);
2115
+ decorations.push(Decoration7.replace({
2116
+ block: true,
2117
+ widget: new ImageWidget(url)
2118
+ }).range(hide ? node.from : node.to, node.to));
2119
+ }
2120
+ }
2121
+ },
2122
+ from,
2123
+ to
2124
+ });
2125
+ return decorations;
2126
+ };
2127
+ var ImageWidget = class extends WidgetType4 {
2128
+ constructor(_url) {
2129
+ super();
2130
+ this._url = _url;
2131
+ }
2132
+ eq(other) {
2133
+ return this._url === other._url;
2134
+ }
2135
+ toDOM(view) {
2136
+ const img = document.createElement("img");
2137
+ img.setAttribute("src", this._url);
2138
+ img.setAttribute("class", "cm-image");
2139
+ img.onload = () => img.classList.add("cm-loaded-image");
2140
+ return img;
2141
+ }
2142
+ };
2143
+
2144
+ // packages/ui/react-ui-editor/src/extensions/markdown/link.ts
2145
+ import { syntaxTree as syntaxTree6 } from "@codemirror/language";
2146
+ import { RangeSetBuilder as RangeSetBuilder5 } from "@codemirror/state";
2147
+ import { hoverTooltip as hoverTooltip2, Decoration as Decoration8, ViewPlugin as ViewPlugin7, WidgetType as WidgetType5 } from "@codemirror/view";
2148
+ import { tooltipContent } from "@dxos/react-ui-theme";
2149
+ var link = (options = {}) => {
2150
+ const extensions = [
2151
+ ViewPlugin7.fromClass(class {
2152
+ constructor(view) {
2153
+ this.decorations = buildDecorations5(view, options);
2154
+ }
2155
+ update(update2) {
2156
+ if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
2157
+ this.decorations = buildDecorations5(update2.view, options);
2158
+ }
2159
+ }
2160
+ }, {
2161
+ decorations: (value) => value.decorations
2162
+ })
2163
+ ];
2164
+ if (options.onHover) {
2165
+ extensions.push(
2166
+ // https://codemirror.net/examples/tooltip
2167
+ // https://codemirror.net/docs/ref/#view.hoverTooltip
2168
+ // https://github.com/codemirror/view/blob/main/src/tooltip.ts
2169
+ hoverTooltip2((view, pos, side) => {
2170
+ const syntax = syntaxTree6(view.state).resolveInner(pos, side);
2171
+ let link2 = null;
2172
+ for (let i = 0, node = syntax; !link2 && node && i < 5; node = node.parent, i++) {
2173
+ link2 = node.name === "Link" ? node : null;
2174
+ }
2175
+ const url = link2 && link2.getChild("URL");
2176
+ if (!url || !link2) {
2177
+ return null;
2178
+ }
2179
+ const urlText = view.state.sliceDoc(url.from, url.to);
2180
+ return {
2181
+ pos: link2.from,
2182
+ end: link2.to,
2183
+ above: true,
2184
+ create: () => {
2185
+ const el = document.createElement("div");
2186
+ el.className = tooltipContent({}, "pli-2 plb-1");
2187
+ options.onHover(el, urlText);
2188
+ return {
2189
+ dom: el,
2190
+ offset: {
2191
+ x: 0,
2192
+ y: 4
2193
+ }
2194
+ };
2195
+ }
2196
+ };
2197
+ })
2198
+ );
2199
+ }
2200
+ return extensions;
2201
+ };
2202
+ var LinkButton = class extends WidgetType5 {
2203
+ constructor(_url, _onAttach) {
2204
+ super();
2205
+ this._url = _url;
2206
+ this._onAttach = _onAttach;
2207
+ }
2208
+ eq(other) {
2209
+ return this._url === other._url;
2210
+ }
2211
+ toDOM(view) {
2212
+ const el = document.createElement("span");
2213
+ this._onAttach(el, this._url);
2214
+ return el;
2215
+ }
2216
+ };
2217
+ var LinkText = class extends WidgetType5 {
2218
+ constructor(_text, _url) {
2219
+ super();
2220
+ this._text = _text;
2221
+ this._url = _url;
2222
+ }
2223
+ eq(other) {
2224
+ return this._url === other._url;
2225
+ }
2226
+ toDOM(view) {
2227
+ const link2 = document.createElement("a");
2228
+ link2.setAttribute("class", "cm-link");
2229
+ link2.textContent = this._text;
2230
+ if (this._url) {
2231
+ link2.setAttribute("rel", "noreferrer");
2232
+ link2.setAttribute("target", "_blank");
2233
+ link2.href = this._url;
2234
+ } else {
2235
+ link2.onclick = () => {
2236
+ view.dispatch({
2237
+ selection: {
2238
+ anchor: view.posAtDOM(link2)
2239
+ }
2240
+ });
2241
+ };
2242
+ }
2243
+ return link2;
2244
+ }
2245
+ };
2246
+ var buildDecorations5 = (view, options) => {
2247
+ const builder = new RangeSetBuilder5();
2248
+ const { state } = view;
2249
+ const cursor = state.selection.main.head;
2250
+ for (const { from, to } of view.visibleRanges) {
2251
+ syntaxTree6(state).iterate({
2252
+ enter: (node) => {
2253
+ if (node.name === "Link") {
2254
+ const marks = node.node.getChildren("LinkMark");
2255
+ const text = marks.length >= 2 ? state.sliceDoc(marks[0].to, marks[1].from) : "";
2256
+ const urlNode = node.node.getChild("URL");
2257
+ const url = urlNode ? state.sliceDoc(urlNode.from, urlNode.to) : "";
2258
+ if (!url) {
2259
+ return false;
2260
+ }
2261
+ if (!view.hasFocus || state.readOnly || cursor < node.from || cursor > node.to) {
2262
+ builder.add(node.from, node.to, Decoration8.replace({
2263
+ widget: new LinkText(text, options.link ? url : void 0)
2264
+ }));
2265
+ }
2266
+ if (options.onRender) {
2267
+ builder.add(node.to, node.to, Decoration8.replace({
2268
+ widget: new LinkButton(url, options.onRender)
2269
+ }));
2270
+ }
2271
+ return false;
2272
+ }
2273
+ },
2274
+ from,
2275
+ to
2276
+ });
2277
+ }
2278
+ return builder.finish();
2041
2279
  };
2042
2280
 
2043
- // packages/ui/react-ui-editor/src/extensions/table.ts
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";
2281
+ // packages/ui/react-ui-editor/src/extensions/markdown/table.ts
2282
+ import { syntaxTree as syntaxTree7 } from "@codemirror/language";
2283
+ import { RangeSetBuilder as RangeSetBuilder6, StateField as StateField4 } from "@codemirror/state";
2284
+ import { Decoration as Decoration9, EditorView as EditorView11, WidgetType as WidgetType6 } from "@codemirror/view";
2047
2285
  var table = (options = {}) => {
2048
2286
  return StateField4.define({
2049
2287
  create: (state) => update(state, options),
@@ -2052,7 +2290,7 @@ var table = (options = {}) => {
2052
2290
  });
2053
2291
  };
2054
2292
  var update = (state, options) => {
2055
- const builder = new RangeSetBuilder3();
2293
+ const builder = new RangeSetBuilder6();
2056
2294
  const cursor = state.selection.main.head;
2057
2295
  const tables = [];
2058
2296
  const getTable = () => tables[tables.length - 1];
@@ -2060,7 +2298,7 @@ var update = (state, options) => {
2060
2298
  const table2 = getTable();
2061
2299
  return table2.rows?.[table2.rows.length - 1];
2062
2300
  };
2063
- syntaxTree4(state).iterate({
2301
+ syntaxTree7(state).iterate({
2064
2302
  enter: (node) => {
2065
2303
  switch (node.name) {
2066
2304
  case "Table": {
@@ -2092,16 +2330,16 @@ var update = (state, options) => {
2092
2330
  });
2093
2331
  tables.forEach((table2) => {
2094
2332
  const hide = state.readOnly || cursor < table2.from || cursor > table2.to;
2095
- hide && builder.add(table2.from, table2.to, Decoration7.replace({
2333
+ hide && builder.add(table2.from, table2.to, Decoration9.replace({
2096
2334
  widget: new TableWidget(table2)
2097
2335
  }));
2098
- builder.add(table2.from, table2.to, Decoration7.mark({
2336
+ builder.add(table2.from, table2.to, Decoration9.mark({
2099
2337
  class: "cm-table"
2100
2338
  }));
2101
2339
  });
2102
2340
  return builder.finish();
2103
2341
  };
2104
- var TableWidget = class extends WidgetType5 {
2342
+ var TableWidget = class extends WidgetType6 {
2105
2343
  constructor(_table) {
2106
2344
  super();
2107
2345
  this._table = _table;
@@ -2138,10 +2376,10 @@ var TableWidget = class extends WidgetType5 {
2138
2376
  }
2139
2377
  };
2140
2378
 
2141
- // packages/ui/react-ui-editor/src/extensions/tasklist.ts
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";
2379
+ // packages/ui/react-ui-editor/src/extensions/markdown/tasklist.ts
2380
+ import { syntaxTree as syntaxTree8 } from "@codemirror/language";
2381
+ import { RangeSetBuilder as RangeSetBuilder7 } from "@codemirror/state";
2382
+ import { EditorView as EditorView12, Decoration as Decoration10, WidgetType as WidgetType7, ViewPlugin as ViewPlugin8 } from "@codemirror/view";
2145
2383
  var styles5 = EditorView12.baseTheme({
2146
2384
  "& .cm-task": {
2147
2385
  color: getToken("extend.colors.blue.500")
@@ -2151,7 +2389,7 @@ var styles5 = EditorView12.baseTheme({
2151
2389
  marginRight: "4px"
2152
2390
  }
2153
2391
  });
2154
- var CheckboxWidget = class extends WidgetType6 {
2392
+ var CheckboxWidget = class extends WidgetType7 {
2155
2393
  constructor(_checked) {
2156
2394
  super();
2157
2395
  this._checked = _checked;
@@ -2188,23 +2426,23 @@ var CheckboxWidget = class extends WidgetType6 {
2188
2426
  return false;
2189
2427
  }
2190
2428
  };
2191
- var checkedDecoration = Decoration8.replace({
2429
+ var checkedDecoration = Decoration10.replace({
2192
2430
  widget: new CheckboxWidget(true)
2193
2431
  });
2194
- var uncheckedDecoration = Decoration8.replace({
2432
+ var uncheckedDecoration = Decoration10.replace({
2195
2433
  widget: new CheckboxWidget(false)
2196
2434
  });
2197
- var buildDecorations4 = (view) => {
2198
- const builder = new RangeSetBuilder4();
2435
+ var buildDecorations6 = (view) => {
2436
+ const builder = new RangeSetBuilder7();
2199
2437
  const { state } = view;
2200
2438
  const cursor = state.selection.main.head;
2201
2439
  for (const { from, to } of view.visibleRanges) {
2202
- syntaxTree5(state).iterate({
2440
+ syntaxTree8(state).iterate({
2203
2441
  enter: (node) => {
2204
2442
  if (node.name === "TaskMarker") {
2205
2443
  if (cursor < node.from || cursor > node.to) {
2206
2444
  const checked = state.doc.sliceString(node.from + 1, node.to - 1) === "x";
2207
- builder.add(node.from - 2, node.from - 1, Decoration8.mark({
2445
+ builder.add(node.from - 2, node.from - 1, Decoration10.mark({
2208
2446
  class: "cm-task"
2209
2447
  }));
2210
2448
  builder.add(node.from, node.to, checked ? checkedDecoration : uncheckedDecoration);
@@ -2219,24 +2457,58 @@ var buildDecorations4 = (view) => {
2219
2457
  };
2220
2458
  var tasklist = (options = {}) => {
2221
2459
  return [
2222
- ViewPlugin5.fromClass(class {
2460
+ ViewPlugin8.fromClass(class {
2223
2461
  constructor(view) {
2224
- this.decorations = buildDecorations4(view);
2462
+ this.decorations = buildDecorations6(view);
2225
2463
  }
2226
2464
  update(update2) {
2227
2465
  if (update2.docChanged || update2.viewportChanged || update2.selectionSet) {
2228
- this.decorations = buildDecorations4(update2.view);
2466
+ this.decorations = buildDecorations6(update2.view);
2229
2467
  }
2230
2468
  }
2231
2469
  }, {
2232
- decorations: (v) => v.decorations
2470
+ decorations: (value) => value.decorations
2233
2471
  }),
2234
2472
  styles5
2235
2473
  ];
2236
2474
  };
2237
2475
 
2476
+ // packages/ui/react-ui-editor/src/extensions/mention.ts
2477
+ import { autocompletion as autocompletion2 } from "@codemirror/autocomplete";
2478
+ var mention = ({ onSearch }) => {
2479
+ return autocompletion2({
2480
+ // TODO(burdon): Not working.
2481
+ activateOnTyping: true,
2482
+ // activateOnTypingDelay: 100,
2483
+ // selectOnOpen: true,
2484
+ closeOnBlur: false,
2485
+ // defaultKeymap: false,
2486
+ icons: false,
2487
+ override: [
2488
+ (context) => {
2489
+ console.log(context);
2490
+ const match = context.matchBefore(/@(\w+)?/);
2491
+ if (!match || match.from === match.to && !context.explicit) {
2492
+ return null;
2493
+ }
2494
+ return {
2495
+ from: match.from,
2496
+ options: onSearch(match.text.slice(1).toLowerCase()).map((value) => ({
2497
+ label: `@${value}`
2498
+ }))
2499
+ };
2500
+ }
2501
+ ]
2502
+ });
2503
+ };
2504
+
2505
+ // packages/ui/react-ui-editor/src/extensions/outliner.ts
2506
+ var outliner = (options = {}) => {
2507
+ return [];
2508
+ };
2509
+
2238
2510
  // packages/ui/react-ui-editor/src/extensions/typewriter.ts
2239
- import { keymap as keymap5 } from "@codemirror/view";
2511
+ import { keymap as keymap6 } from "@codemirror/view";
2240
2512
  var defaultItems = [
2241
2513
  "hello world!",
2242
2514
  "this is a test.",
@@ -2246,7 +2518,7 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
2246
2518
  let t;
2247
2519
  let idx = 0;
2248
2520
  return [
2249
- keymap5.of([
2521
+ keymap6.of([
2250
2522
  {
2251
2523
  // Reset.
2252
2524
  key: "alt-meta-'",
@@ -2292,27 +2564,6 @@ var typewriter = ({ delay = 75, items = defaultItems } = {}) => {
2292
2564
  ];
2293
2565
  };
2294
2566
 
2295
- // packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
2296
- import { yCollab } from "y-codemirror.next";
2297
-
2298
- // packages/ui/react-ui-editor/src/extensions/yjs/cursor.ts
2299
- import * as Y from "yjs";
2300
- import { arrayToString, stringToArray } from "@dxos/util";
2301
- var cursorConverter2 = (text) => ({
2302
- toCursor: (index, assoc) => {
2303
- return arrayToString(Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text, index, assoc)));
2304
- },
2305
- fromCursor: (cursor) => {
2306
- return Y.createAbsolutePositionFromRelativePosition(Y.decodeRelativePosition(stringToArray(cursor)), text.doc)?.index ?? 0;
2307
- }
2308
- });
2309
-
2310
- // packages/ui/react-ui-editor/src/extensions/yjs/yjs.ts
2311
- var yjs = (content, awareness2) => [
2312
- Cursor.converter.of(cursorConverter2(content)),
2313
- yCollab(content, awareness2)
2314
- ];
2315
-
2316
2567
  // packages/ui/react-ui-editor/src/themes/default.ts
2317
2568
  import get3 from "lodash.get";
2318
2569
  var defaultTheme = {
@@ -2344,8 +2595,9 @@ var defaultTheme = {
2344
2595
  outline: "none"
2345
2596
  },
2346
2597
  ".cm-scroller": {
2347
- overflow: "visible",
2348
- fontFamily: get3(tokens, "fontFamily.mono", []).join(",")
2598
+ // overflow: 'visible',
2599
+ fontFamily: get3(tokens, "fontFamily.mono", []).join(","),
2600
+ lineHeight: 1.4
2349
2601
  },
2350
2602
  ".cm-content": {
2351
2603
  padding: 0,
@@ -2353,11 +2605,11 @@ var defaultTheme = {
2353
2605
  fontSize: "16px"
2354
2606
  },
2355
2607
  "&light .cm-content": {
2356
- color: get3(tokens, "extend.colors.neutral.900", "black"),
2608
+ color: get3(tokens, "extend.semanticColors.base.fg.light", "black"),
2357
2609
  caretColor: "black"
2358
2610
  },
2359
2611
  "&dark .cm-content": {
2360
- color: get3(tokens, "extend.colors.neutral.100", "white"),
2612
+ color: get3(tokens, "extend.semanticColors.base.fg.dark", "white"),
2361
2613
  caretColor: "white"
2362
2614
  },
2363
2615
  //
@@ -2369,8 +2621,11 @@ var defaultTheme = {
2369
2621
  "&dark .cm-cursor, &dark .cm-dropCursor": {
2370
2622
  borderLeft: "2px solid white"
2371
2623
  },
2372
- ".cm-placeholder": {
2373
- fontWeight: 100
2624
+ "&light .cm-placeholder": {
2625
+ color: get3(tokens, "extend.semanticColors.description.light", "rgba(0,0,0,.2)")
2626
+ },
2627
+ "&dark .cm-placeholder": {
2628
+ color: get3(tokens, "extend.semanticColors.description.dark", "rgba(255,255,255,.2)")
2374
2629
  },
2375
2630
  //
2376
2631
  // line
@@ -2379,7 +2634,7 @@ var defaultTheme = {
2379
2634
  paddingInline: 0
2380
2635
  },
2381
2636
  ".cm-activeLine": {
2382
- background: "inherit"
2637
+ background: "transparent"
2383
2638
  },
2384
2639
  //
2385
2640
  // Selection
@@ -2550,31 +2805,35 @@ var codeTheme = {
2550
2805
  };
2551
2806
 
2552
2807
  // 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";
2808
+ var __dxlog_file3 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/components/TextEditor/TextEditor.tsx";
2554
2809
  var EditorModes = [
2555
2810
  "default",
2556
2811
  "vim"
2557
2812
  ];
2558
- var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autofocus, scrollTo, selection, editorMode, theme, slots = defaultSlots, extensions = [] }, forwardedRef) => {
2559
- const tabsterDOMAttribute = useFocusableGroup({
2560
- tabBehavior: "limited"
2561
- });
2562
- const { themeMode } = useThemeContext2();
2813
+ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autoFocus, scrollTo, selection, editorMode, theme, slots = defaultSlots, extensions = [], debug }, forwardedRef) => {
2814
+ const { themeMode } = useThemeContext();
2563
2815
  const rootRef = useRef(null);
2564
2816
  const [view, setView] = useState(null);
2565
2817
  useImperativeHandle(forwardedRef, () => view, [
2566
2818
  view
2567
2819
  ]);
2568
- useEffect3(() => {
2569
- if (autofocus) {
2820
+ useEffect2(() => {
2821
+ if (autoFocus && !view?.hasFocus) {
2822
+ if (view?.state.selection.main?.from === 0) {
2823
+ const { to } = view.state.doc.lineAt(0);
2824
+ view?.dispatch({
2825
+ selection: {
2826
+ anchor: to
2827
+ }
2828
+ });
2829
+ }
2570
2830
  view?.focus();
2571
2831
  }
2572
2832
  }, [
2573
2833
  view,
2574
- autofocus
2834
+ autoFocus
2575
2835
  ]);
2576
- useAwareness(model);
2577
- useEffect3(() => {
2836
+ useEffect2(() => {
2578
2837
  if (!model || !rootRef.current) {
2579
2838
  return;
2580
2839
  }
@@ -2585,8 +2844,8 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autofocus, s
2585
2844
  // TODO(burdon): Doesn't catch errors in keymap functions.
2586
2845
  EditorView13.exceptionSink.of((err) => {
2587
2846
  log2.catch(err, void 0, {
2588
- F: __dxlog_file4,
2589
- L: 114,
2847
+ F: __dxlog_file3,
2848
+ L: 134,
2590
2849
  S: void 0,
2591
2850
  C: (f, a) => f(...a)
2592
2851
  });
@@ -2603,15 +2862,16 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autofocus, s
2603
2862
  class: slots.content?.className ?? ""
2604
2863
  }),
2605
2864
  // State.
2865
+ EditorView13.editable.of(!readonly),
2606
2866
  EditorState2.readOnly.of(!!readonly),
2607
2867
  // Storage and replication.
2608
2868
  // NOTE: This must come before user extensions.
2609
2869
  model.extension,
2610
- // TODO(burdon): Factor out (requires special handling for Escape/focus).
2870
+ // TODO(burdon): Factor out? (Requires special handling for Escape/Enter below).
2611
2871
  editorMode === "vim" && vim(),
2612
2872
  // Custom.
2613
2873
  ...extensions
2614
- ].filter(Boolean)
2874
+ ].filter(isNotFalsy3)
2615
2875
  });
2616
2876
  const newView = new EditorView13({
2617
2877
  state,
@@ -2620,11 +2880,10 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autofocus, s
2620
2880
  // NOTE: Uncomment to debug/monitor all transactions.
2621
2881
  // https://codemirror.net/docs/ref/#view.EditorView.dispatch
2622
2882
  dispatchTransactions: (trs, view2) => {
2623
- view2.update(trs);
2624
- const debug = false;
2625
2883
  if (debug) {
2626
2884
  logChanges(trs);
2627
2885
  }
2886
+ view2.update(trs);
2628
2887
  }
2629
2888
  });
2630
2889
  view?.destroy();
@@ -2649,7 +2908,7 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autofocus, s
2649
2908
  }
2650
2909
  case "Escape": {
2651
2910
  if (editorMode === "vim" && (altKey || shiftKey || metaKey || ctrlKey)) {
2652
- rootRef.current?.focus();
2911
+ view?.focus();
2653
2912
  }
2654
2913
  break;
2655
2914
  }
@@ -2662,23 +2921,23 @@ var BaseTextEditor = /* @__PURE__ */ forwardRef(({ model, readonly, autofocus, s
2662
2921
  key: model.id,
2663
2922
  role: "none",
2664
2923
  tabIndex: 0,
2665
- onKeyUp: handleKeyUp,
2666
2924
  ...slots.root,
2667
- ...editorMode !== "vim" && tabsterDOMAttribute,
2925
+ // {...(editorMode !== 'vim' && tabsterDOMAttribute)}
2926
+ onKeyUp: handleKeyUp,
2668
2927
  ref: rootRef
2669
2928
  });
2670
2929
  });
2671
- var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, multiline, theme = textTheme, slots, extensions = [], ...props }, forwardedRef) => {
2672
- const { themeMode } = useThemeContext2();
2930
+ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, lineWrapping, theme = textTheme, slots, extensions = [], ...props }, forwardedRef) => {
2931
+ const { themeMode } = useThemeContext();
2673
2932
  const updatedSlots = defaultsDeep2({}, slots, defaultTextSlots);
2674
2933
  return /* @__PURE__ */ React.createElement(BaseTextEditor, {
2675
2934
  ref: forwardedRef,
2676
2935
  readonly,
2677
2936
  extensions: [
2678
- basicBundle({
2937
+ createBasicBundle({
2679
2938
  themeMode,
2680
2939
  placeholder: placeholder3,
2681
- multiline
2940
+ lineWrapping
2682
2941
  }),
2683
2942
  ...extensions
2684
2943
  ],
@@ -2688,15 +2947,14 @@ var TextEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholde
2688
2947
  });
2689
2948
  });
2690
2949
  var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeholder3, theme = markdownTheme, slots, extensions = [], ...props }, forwardedRef) => {
2691
- const { themeMode } = useThemeContext2();
2950
+ const { themeMode } = useThemeContext();
2692
2951
  const updatedSlots = defaultsDeep2({}, slots, defaultMarkdownSlots);
2693
2952
  return /* @__PURE__ */ React.createElement(BaseTextEditor, {
2694
2953
  ref: forwardedRef,
2695
2954
  readonly,
2696
2955
  extensions: [
2697
- markdownBundle({
2956
+ createMarkdownExtensions({
2698
2957
  themeMode,
2699
- readonly,
2700
2958
  placeholder: placeholder3
2701
2959
  }),
2702
2960
  ...extensions
@@ -2708,11 +2966,10 @@ var MarkdownEditor = /* @__PURE__ */ forwardRef(({ readonly, placeholder: placeh
2708
2966
  });
2709
2967
  var defaultSlots = {
2710
2968
  root: {
2711
- // TODO(burdon): Add focusRing by default/as property?
2712
- className: mx3("flex flex-col grow overflow-y-auto", inputSurface)
2969
+ className: mx3("grow", focusRing)
2713
2970
  },
2714
2971
  editor: {
2715
- className: "h-full p-2"
2972
+ className: "bs-full"
2716
2973
  }
2717
2974
  };
2718
2975
  var defaultTextSlots = {
@@ -2722,22 +2979,178 @@ var defaultMarkdownSlots = {
2722
2979
  ...defaultSlots
2723
2980
  };
2724
2981
 
2725
- // packages/ui/react-ui-editor/src/hooks/automerge.ts
2726
- import get4 from "lodash.get";
2727
- import { getRawDoc } from "@dxos/echo-schema";
2728
- import { isNotNullOrUndefined } from "@dxos/util";
2982
+ // packages/ui/react-ui-editor/src/components/Toolbar/Toolbar.tsx
2983
+ import { At, CaretRight, ChatText, Code, Image, Link, ListBullets, ListChecks, ListNumbers, TextStrikethrough, Table as Table2, TextB, TextItalic } from "@phosphor-icons/react";
2984
+ import { createContext } from "@radix-ui/react-context";
2985
+ import React2 from "react";
2986
+ import { Button, DensityProvider, Select } from "@dxos/react-ui";
2987
+ import { getSize } from "@dxos/react-ui-theme";
2988
+ var [ToolbarContextProvider, useToolbarContext] = createContext("Toolbar");
2989
+ var ToolbarRoot = ({ children, onAction }) => {
2990
+ return /* @__PURE__ */ React2.createElement(ToolbarContextProvider, {
2991
+ onAction
2992
+ }, /* @__PURE__ */ React2.createElement(DensityProvider, {
2993
+ density: "fine"
2994
+ }, /* @__PURE__ */ React2.createElement("div", {
2995
+ role: "toolbar",
2996
+ className: "flex w-full shrink-0 p-2 gap-4 items-center whitespace-nowrap overflow-hidden"
2997
+ }, children)));
2998
+ };
2999
+ var ToolbarButton = ({ Icon, onClick, title }) => {
3000
+ const { onAction } = useToolbarContext("ToolbarButton");
3001
+ const handleClick = () => {
3002
+ const action = onClick();
3003
+ if (action) {
3004
+ onAction?.(action);
3005
+ }
3006
+ };
3007
+ return /* @__PURE__ */ React2.createElement(Button, {
3008
+ variant: "ghost",
3009
+ classNames: "p-2",
3010
+ onClick: handleClick,
3011
+ title
3012
+ }, /* @__PURE__ */ React2.createElement(Icon, {
3013
+ className: getSize(5)
3014
+ }));
3015
+ };
3016
+ var ToolbarSeparator = () => /* @__PURE__ */ React2.createElement("div", {
3017
+ className: "grow"
3018
+ });
3019
+ var MarkdownHeading = () => {
3020
+ const { onAction } = useToolbarContext("MarkdownFormatting");
3021
+ return /* @__PURE__ */ React2.createElement(Select.Root, {
3022
+ defaultValue: "0",
3023
+ onValueChange: (value) => onAction?.({
3024
+ type: "heading",
3025
+ data: parseInt(value)
3026
+ })
3027
+ }, /* @__PURE__ */ React2.createElement(Select.TriggerButton, {
3028
+ classNames: "w-[8rem]"
3029
+ }), /* @__PURE__ */ React2.createElement(Select.Portal, null, /* @__PURE__ */ React2.createElement(Select.Content, null, /* @__PURE__ */ React2.createElement(Select.Viewport, null, /* @__PURE__ */ React2.createElement(Select.Option, {
3030
+ value: "0"
3031
+ }, "Paragraph"), [
3032
+ 1,
3033
+ 2,
3034
+ 3,
3035
+ 4,
3036
+ 5,
3037
+ 6
3038
+ ].map((level) => /* @__PURE__ */ React2.createElement(Select.Option, {
3039
+ key: level,
3040
+ value: String(level)
3041
+ }, "Heading ", level))))));
3042
+ };
3043
+ var MarkdownStyles = () => /* @__PURE__ */ React2.createElement("div", {
3044
+ role: "none"
3045
+ }, /* @__PURE__ */ React2.createElement(ToolbarButton, {
3046
+ Icon: TextB,
3047
+ title: "Bold",
3048
+ onClick: () => ({
3049
+ type: "bold"
3050
+ })
3051
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3052
+ Icon: TextItalic,
3053
+ title: "Italic",
3054
+ onClick: () => ({
3055
+ type: "italic"
3056
+ })
3057
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3058
+ Icon: TextStrikethrough,
3059
+ title: "Strike-through",
3060
+ onClick: () => ({
3061
+ type: "strikethrough"
3062
+ })
3063
+ }));
3064
+ var MarkdownLists = () => /* @__PURE__ */ React2.createElement("div", {
3065
+ role: "none"
3066
+ }, /* @__PURE__ */ React2.createElement(ToolbarButton, {
3067
+ Icon: ListBullets,
3068
+ title: "Bullet list",
3069
+ onClick: () => ({
3070
+ type: "list"
3071
+ })
3072
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3073
+ Icon: ListNumbers,
3074
+ title: "Numbered list",
3075
+ onClick: () => ({
3076
+ type: "list-ordered"
3077
+ })
3078
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3079
+ Icon: ListChecks,
3080
+ title: "Task list",
3081
+ onClick: () => ({
3082
+ type: "list-tasks"
3083
+ })
3084
+ }));
3085
+ var MarkdownBlocks = () => /* @__PURE__ */ React2.createElement("div", {
3086
+ role: "none"
3087
+ }, /* @__PURE__ */ React2.createElement(ToolbarButton, {
3088
+ Icon: CaretRight,
3089
+ title: "Block quite",
3090
+ onClick: () => ({
3091
+ type: "blockquote"
3092
+ })
3093
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3094
+ Icon: Code,
3095
+ title: "Code block",
3096
+ onClick: () => ({
3097
+ type: "codeblock"
3098
+ })
3099
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3100
+ Icon: Table2,
3101
+ title: "Table",
3102
+ onClick: () => ({
3103
+ type: "table"
3104
+ })
3105
+ }));
3106
+ var MarkdownLinks = () => /* @__PURE__ */ React2.createElement("div", {
3107
+ role: "none"
3108
+ }, /* @__PURE__ */ React2.createElement(ToolbarButton, {
3109
+ Icon: Link,
3110
+ title: "Link",
3111
+ onClick: () => ({
3112
+ type: "link"
3113
+ })
3114
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3115
+ Icon: At,
3116
+ title: "Mention",
3117
+ onClick: () => ({
3118
+ type: "mention"
3119
+ })
3120
+ }), /* @__PURE__ */ React2.createElement(ToolbarButton, {
3121
+ Icon: Image,
3122
+ title: "Image",
3123
+ onClick: () => ({
3124
+ type: "image"
3125
+ })
3126
+ }));
3127
+ var MarkdownStandard = () => /* @__PURE__ */ React2.createElement(React2.Fragment, null, /* @__PURE__ */ React2.createElement(MarkdownHeading, null), /* @__PURE__ */ React2.createElement(MarkdownStyles, null), /* @__PURE__ */ React2.createElement(MarkdownLists, null), /* @__PURE__ */ React2.createElement(MarkdownBlocks, null), /* @__PURE__ */ React2.createElement(MarkdownLinks, null));
3128
+ var MarkdownExtended = () => /* @__PURE__ */ React2.createElement(Toolbar.Button, {
3129
+ Icon: ChatText,
3130
+ title: "Create comment",
3131
+ onClick: () => ({
3132
+ type: "comment"
3133
+ })
3134
+ });
3135
+ var Toolbar = {
3136
+ Root: ToolbarRoot,
3137
+ Button: ToolbarButton,
3138
+ Separator: ToolbarSeparator,
3139
+ Markdown: MarkdownStandard,
3140
+ Extended: MarkdownExtended
3141
+ };
2729
3142
 
2730
3143
  // packages/ui/react-ui-editor/src/hooks/awareness-provider.ts
2731
3144
  import { DeferredTask, Event as Event2, sleep } from "@dxos/async";
2732
3145
  import { Context as Context2 } from "@dxos/context";
2733
- import { invariant as invariant3 } from "@dxos/invariant";
3146
+ import { invariant as invariant2 } from "@dxos/invariant";
2734
3147
  import { log as log3 } from "@dxos/log";
2735
- var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
3148
+ var __dxlog_file4 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/awareness-provider.ts";
2736
3149
  var DEBOUNCE_INTERVAL = 100;
2737
3150
  var SpaceAwarenessProvider = class {
2738
3151
  constructor(params) {
2739
- this.remoteStateChange = new Event2();
2740
3152
  this._remoteStates = /* @__PURE__ */ new Map();
3153
+ this.remoteStateChange = new Event2();
2741
3154
  this._space = params.space;
2742
3155
  this._channel = params.channel;
2743
3156
  this._peerId = params.peerId;
@@ -2754,7 +3167,7 @@ var SpaceAwarenessProvider = class {
2754
3167
  await sleep(DEBOUNCE_INTERVAL);
2755
3168
  }
2756
3169
  });
2757
- const unsubscribe = this._space.listen(this._channel, (message) => {
3170
+ this._ctx.onDispose(this._space.listen(this._channel, (message) => {
2758
3171
  switch (message.payload.kind) {
2759
3172
  case "query": {
2760
3173
  this._handleQueryMessage();
@@ -2765,16 +3178,15 @@ var SpaceAwarenessProvider = class {
2765
3178
  break;
2766
3179
  }
2767
3180
  }
2768
- });
2769
- this._ctx.onDispose(unsubscribe);
3181
+ }));
2770
3182
  void this._space.postMessage(this._channel, {
2771
3183
  kind: "query"
2772
3184
  }).catch((err) => {
2773
3185
  log3.debug("failed to query awareness", {
2774
3186
  err
2775
3187
  }, {
2776
- F: __dxlog_file5,
2777
- L: 85,
3188
+ F: __dxlog_file4,
3189
+ L: 89,
2778
3190
  S: this,
2779
3191
  C: (f, a) => f(...a)
2780
3192
  });
@@ -2785,10 +3197,13 @@ var SpaceAwarenessProvider = class {
2785
3197
  this._ctx = void 0;
2786
3198
  this._postTask = void 0;
2787
3199
  }
3200
+ getRemoteStates() {
3201
+ return Array.from(this._remoteStates.values());
3202
+ }
2788
3203
  update(position) {
2789
- invariant3(this._postTask, void 0, {
2790
- F: __dxlog_file5,
2791
- L: 96,
3204
+ invariant2(this._postTask, void 0, {
3205
+ F: __dxlog_file4,
3206
+ L: 104,
2792
3207
  S: this,
2793
3208
  A: [
2794
3209
  "this._postTask",
@@ -2802,13 +3217,10 @@ var SpaceAwarenessProvider = class {
2802
3217
  };
2803
3218
  this._postTask.schedule();
2804
3219
  }
2805
- getRemoteStates() {
2806
- return Array.from(this._remoteStates.values());
2807
- }
2808
3220
  _handleQueryMessage() {
2809
- invariant3(this._postTask, void 0, {
2810
- F: __dxlog_file5,
2811
- L: 111,
3221
+ invariant2(this._postTask, void 0, {
3222
+ F: __dxlog_file4,
3223
+ L: 115,
2812
3224
  S: this,
2813
3225
  A: [
2814
3226
  "this._postTask",
@@ -2818,9 +3230,9 @@ var SpaceAwarenessProvider = class {
2818
3230
  this._postTask.schedule();
2819
3231
  }
2820
3232
  _handlePostMessage(message) {
2821
- invariant3(message.kind === "post", void 0, {
2822
- F: __dxlog_file5,
2823
- L: 116,
3233
+ invariant2(message.kind === "post", void 0, {
3234
+ F: __dxlog_file4,
3235
+ L: 120,
2824
3236
  S: this,
2825
3237
  A: [
2826
3238
  "message.kind === 'post'",
@@ -2839,182 +3251,177 @@ var modelState = StateField5.define({
2839
3251
  update: (model) => model
2840
3252
  });
2841
3253
 
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
3254
+ // packages/ui/react-ui-editor/src/hooks/useActionHandler.ts
3255
+ var useActionHandler = (view) => {
3256
+ return (action) => {
3257
+ if (!view) {
3258
+ return;
3259
+ }
3260
+ switch (action.type) {
3261
+ case "heading":
3262
+ setHeading(parseInt(action.data))(view);
3263
+ break;
3264
+ case "bold":
3265
+ toggleBold(view);
3266
+ break;
3267
+ case "italic":
3268
+ toggleItalic(view);
3269
+ break;
3270
+ case "strikethrough":
3271
+ toggleStrikethrough(view);
3272
+ break;
3273
+ case "list":
3274
+ toggleList(view);
3275
+ break;
3276
+ case "codeblock":
3277
+ insertCodeblock(view);
3278
+ break;
3279
+ case "table":
3280
+ insertTable(view);
3281
+ break;
3282
+ case "comment":
3283
+ createComment(view);
3284
+ break;
3285
+ }
3286
+ setTimeout(() => {
3287
+ view.focus();
3288
+ view.dispatch({
3289
+ selection: view.state.selection
3290
+ });
3291
+ });
2876
3292
  };
2877
- return model;
2878
3293
  };
2879
3294
 
2880
- // packages/ui/react-ui-editor/src/hooks/yjs.ts
2881
- import * as decoding from "lib0/decoding";
2882
- import * as encoding from "lib0/encoding";
2883
- import { Observable } from "lib0/observable";
2884
- import * as YP from "y-protocols/awareness";
2885
- import { invariant as invariant4 } from "@dxos/invariant";
2886
- import { log as log4 } from "@dxos/log";
2887
- var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/yjs.ts";
2888
- var createYjsModel = ({ identity, space, text }) => {
2889
- invariant4(text?.doc && text?.content, void 0, {
2890
- F: __dxlog_file6,
2891
- L: 22,
2892
- S: void 0,
2893
- A: [
2894
- "text?.doc && text?.content",
2895
- ""
2896
- ]
2897
- });
2898
- const provider = space ? new YAwarenessProvider({
2899
- space,
2900
- doc: text.doc,
2901
- channel: `yjs.awareness.${text.id}`
2902
- }) : void 0;
2903
- const model = {
2904
- id: text.doc.guid,
2905
- content: text.content,
2906
- text: () => text.content.toString(),
2907
- extension: [
2908
- modelState.init(() => model),
2909
- yjs(text.content, provider?.awareness)
2910
- ],
2911
- awareness: provider?.awareness,
2912
- peer: identity ? {
2913
- id: identity.identityKey.toHex(),
2914
- name: identity.profile?.displayName
2915
- } : void 0
2916
- };
2917
- return model;
3295
+ // packages/ui/react-ui-editor/src/hooks/useEditorView.ts
3296
+ import { useState as useState2 } from "react";
3297
+ var useEditorView = () => {
3298
+ const [view, setView] = useState2(null);
3299
+ return [
3300
+ (ref) => {
3301
+ setView(ref);
3302
+ },
3303
+ view
3304
+ ];
2918
3305
  };
2919
- var messageAwareness = 1;
2920
- var messageQueryAwareness = 3;
2921
- var YAwarenessProvider = class extends Observable {
2922
- constructor({ space, doc, channel, awareness: awareness2 }) {
2923
- super();
2924
- this._space = space;
2925
- this._awareness = awareness2 ?? new YP.Awareness(doc);
2926
- this._channel = channel;
2927
- this._clientId = doc.clientID;
2928
- this._awareness.on("update", this._handleAwarenessUpdate.bind(this));
2929
- this._space.listen(this._channel, this._handleSpaceMessage.bind(this));
2930
- if (typeof window !== "undefined") {
2931
- window.addEventListener("beforeunload", this._handleBeforeUnload.bind(this));
2932
- } else if (typeof process !== "undefined") {
2933
- process.on("exit", this._handleBeforeUnload.bind(this));
2934
- }
2935
- const encoderAwarenessQuery = encoding.createEncoder();
2936
- encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
2937
- void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessQuery));
2938
- const encoderAwarenessState = encoding.createEncoder();
2939
- encoding.writeVarUint(encoderAwarenessState, messageAwareness);
2940
- encoding.writeVarUint8Array(encoderAwarenessState, YP.encodeAwarenessUpdate(this.awareness, [
2941
- this._clientId
2942
- ]));
2943
- void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
2944
- }
2945
- get awareness() {
2946
- return this._awareness;
2947
- }
2948
- _handleAwarenessUpdate({ added, updated, removed }, origin) {
2949
- log4("awareness update", {
2950
- added,
2951
- updated,
2952
- removed,
2953
- origin
2954
- }, {
2955
- F: __dxlog_file6,
2956
- L: 101,
2957
- S: this,
2958
- C: (f, a) => f(...a)
2959
- });
2960
- const changedClients = added.concat(updated).concat(removed);
2961
- const encoderAwareness = encoding.createEncoder();
2962
- encoding.writeVarUint(encoderAwareness, messageAwareness);
2963
- encoding.writeVarUint8Array(encoderAwareness, YP.encodeAwarenessUpdate(this._awareness, changedClients));
2964
- void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
2965
- }
2966
- _handleSpaceMessage({ payload }) {
2967
- log4("space message", payload, {
2968
- F: __dxlog_file6,
2969
- L: 110,
2970
- S: this,
2971
- C: (f, a) => f(...a)
2972
- });
2973
- const data = new Uint8Array(Array.from(Object.values(payload)));
2974
- const encoder = this._readMessage(data);
2975
- if (encoder) {
2976
- void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
3306
+
3307
+ // packages/ui/react-ui-editor/src/hooks/useTextEditor.ts
3308
+ import { EditorSelection, EditorState as EditorState3 } from "@codemirror/state";
3309
+ import { EditorView as EditorView14 } from "@codemirror/view";
3310
+ import { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
3311
+ import { log as log4 } from "@dxos/log";
3312
+ import { isNotFalsy as isNotFalsy4 } from "@dxos/util";
3313
+ var __dxlog_file5 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextEditor.ts";
3314
+ var useTextEditor = ({ autoFocus, scrollTo, debug, doc, selection, extensions } = {}) => {
3315
+ const onUpdate = useRef2();
3316
+ const [view, setView] = useState3();
3317
+ const parentRef = useRef2(null);
3318
+ useEffect3(() => {
3319
+ if (parentRef.current) {
3320
+ const state = EditorState3.create({
3321
+ doc,
3322
+ selection,
3323
+ extensions: [
3324
+ // TODO(burdon): Doesn't catch errors in keymap functions.
3325
+ EditorView14.exceptionSink.of((err) => {
3326
+ log4.catch(err, void 0, {
3327
+ F: __dxlog_file5,
3328
+ L: 57,
3329
+ S: void 0,
3330
+ C: (f, a) => f(...a)
3331
+ });
3332
+ }),
3333
+ extensions,
3334
+ EditorView14.updateListener.of(() => {
3335
+ onUpdate.current?.();
3336
+ })
3337
+ ].filter(isNotFalsy4)
3338
+ });
3339
+ const view2 = new EditorView14({
3340
+ parent: parentRef.current,
3341
+ scrollTo,
3342
+ state,
3343
+ // NOTE: Uncomment to debug/monitor all transactions.
3344
+ // https://codemirror.net/docs/ref/#view.EditorView.dispatch
3345
+ dispatchTransactions: (trs, view3) => {
3346
+ if (debug) {
3347
+ logChanges(trs);
3348
+ }
3349
+ view3.update(trs);
3350
+ }
3351
+ });
3352
+ setView(view2);
2977
3353
  }
2978
- }
2979
- _readMessage(message) {
2980
- const decoder = decoding.createDecoder(message);
2981
- const encoder = encoding.createEncoder();
2982
- const messageType = decoding.readVarUint(decoder);
2983
- let sendReply = false;
2984
- switch (messageType) {
2985
- case messageAwareness: {
2986
- YP.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
2987
- break;
3354
+ return () => {
3355
+ view?.destroy();
3356
+ };
3357
+ }, [
3358
+ parentRef
3359
+ ]);
3360
+ useEffect3(() => {
3361
+ if (view) {
3362
+ if (!selection && !view.state.selection.main.anchor) {
3363
+ selection = EditorSelection.single(view.state.doc.line(1).to);
2988
3364
  }
2989
- case messageQueryAwareness: {
2990
- encoding.writeVarUint(encoder, messageAwareness);
2991
- encoding.writeVarUint8Array(encoder, YP.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())));
2992
- sendReply = true;
2993
- break;
3365
+ if (selection || scrollTo) {
3366
+ onUpdate.current = () => {
3367
+ onUpdate.current = void 0;
3368
+ view.dispatch({
3369
+ selection,
3370
+ effects: scrollTo && [
3371
+ scrollTo
3372
+ ],
3373
+ scrollIntoView: !scrollTo
3374
+ });
3375
+ };
2994
3376
  }
2995
- default: {
2996
- console.error("Invalid message:", messageType);
2997
- return encoder;
3377
+ if (autoFocus) {
3378
+ view.focus();
2998
3379
  }
2999
3380
  }
3000
- if (!sendReply) {
3001
- return null;
3002
- }
3003
- return encoder;
3004
- }
3005
- _handleBeforeUnload() {
3006
- YP.removeAwarenessStates(this._awareness, [
3007
- this._clientId
3008
- ], "window unload");
3009
- }
3381
+ }, [
3382
+ view,
3383
+ autoFocus,
3384
+ selection,
3385
+ scrollTo
3386
+ ]);
3387
+ return {
3388
+ parentRef,
3389
+ view
3390
+ };
3391
+ };
3392
+ var createDataExtensions = ({ readonly = false } = {}) => {
3393
+ return [
3394
+ //
3395
+ EditorState3.readOnly.of(readonly),
3396
+ EditorView14.editable.of(!readonly)
3397
+ ];
3398
+ };
3399
+ var createThemeExtensions = ({ theme, themeMode, slots } = {}) => {
3400
+ return [
3401
+ //
3402
+ EditorView14.baseTheme(defaultTheme),
3403
+ theme && EditorView14.theme(theme),
3404
+ EditorView14.darkTheme.of(themeMode === "dark"),
3405
+ EditorView14.editorAttributes.of({
3406
+ class: slots?.editor?.className ?? ""
3407
+ }),
3408
+ EditorView14.contentAttributes.of({
3409
+ class: slots?.content?.className ?? ""
3410
+ })
3411
+ ].filter(isNotFalsy4);
3010
3412
  };
3011
3413
 
3012
3414
  // packages/ui/react-ui-editor/src/hooks/useTextModel.ts
3013
- import { useEffect as useEffect4, useState as useState2 } from "react";
3415
+ import get4 from "lodash.get";
3416
+ import { useEffect as useEffect4, useState as useState4 } from "react";
3417
+ import { generateName } from "@dxos/display-name";
3418
+ import { getRawDoc } from "@dxos/echo-schema";
3419
+ import { invariant as invariant3 } from "@dxos/invariant";
3014
3420
  import { isAutomergeObject } from "@dxos/react-client/echo";
3421
+ var __dxlog_file6 = "/home/runner/work/dxos/dxos/packages/ui/react-ui-editor/src/hooks/useTextModel.ts";
3015
3422
  var useTextModel = (props) => {
3016
3423
  const { identity, space, text } = props;
3017
- const [model, setModel] = useState2();
3424
+ const [model, setModel] = useState4();
3018
3425
  useEffect4(() => setModel(createModel(props)), [
3019
3426
  identity,
3020
3427
  space,
@@ -3022,18 +3429,63 @@ var useTextModel = (props) => {
3022
3429
  ]);
3023
3430
  return model;
3024
3431
  };
3025
- var createModel = (props) => {
3026
- const { text } = props;
3027
- if (isAutomergeObject(text)) {
3028
- return createAutomergeModel(props);
3029
- } else if (text?.doc) {
3030
- return createYjsModel(props);
3031
- } else {
3032
- return void 0;
3432
+ var useInMemoryTextModel = ({ id, defaultContent }) => {
3433
+ const [content, setContent] = useState4(defaultContent ?? "");
3434
+ return {
3435
+ id,
3436
+ content,
3437
+ setContent,
3438
+ text: () => content
3439
+ };
3440
+ };
3441
+ var createModel = ({ space, identity, text }) => {
3442
+ invariant3(isAutomergeObject(text), void 0, {
3443
+ F: __dxlog_file6,
3444
+ L: 50,
3445
+ S: void 0,
3446
+ A: [
3447
+ "isAutomergeObject(text)",
3448
+ ""
3449
+ ]
3450
+ });
3451
+ const obj = text;
3452
+ const doc = getRawDoc(obj, [
3453
+ obj.field
3454
+ ]);
3455
+ const awarenessProvider2 = space && new SpaceAwarenessProvider({
3456
+ space,
3457
+ channel: `automerge.awareness.${obj.id}`,
3458
+ info: {
3459
+ displayName: identity ? identity.profile?.displayName ?? generateName(identity.identityKey.toHex()) : void 0,
3460
+ color: cursorColor.color,
3461
+ lightColor: cursorColor.light
3462
+ },
3463
+ peerId: identity?.identityKey.toHex() ?? "Anonymous"
3464
+ });
3465
+ const extensions = [
3466
+ //
3467
+ modelState.init(() => model),
3468
+ automerge({
3469
+ handle: doc.handle,
3470
+ path: doc.path
3471
+ })
3472
+ ];
3473
+ if (awarenessProvider2) {
3474
+ extensions.push(awareness(awarenessProvider2));
3033
3475
  }
3476
+ const model = {
3477
+ id: obj.id,
3478
+ content: doc,
3479
+ text: () => get4(doc.handle.docSync(), doc.path),
3480
+ extension: extensions,
3481
+ peer: identity ? {
3482
+ id: identity.identityKey.toHex(),
3483
+ name: identity.profile?.displayName
3484
+ } : void 0
3485
+ };
3486
+ return model;
3034
3487
  };
3035
3488
  export {
3036
- AwarenessProvider,
3037
3489
  BaseTextEditor,
3038
3490
  Cursor,
3039
3491
  Doc,
@@ -3043,32 +3495,40 @@ export {
3043
3495
  SpaceAwarenessProvider,
3044
3496
  TextEditor,
3045
3497
  TextKind,
3046
- YAwarenessProvider,
3498
+ Toolbar,
3047
3499
  YText,
3048
3500
  YXmlFragment,
3049
3501
  autocomplete,
3050
- automerge3 as automerge,
3502
+ automerge,
3051
3503
  awareness,
3052
- basicBundle,
3504
+ awarenessProvider,
3053
3505
  blast,
3054
3506
  callbackWrapper,
3055
3507
  code2 as code,
3056
3508
  codeTheme,
3057
3509
  comments,
3058
- createAutomergeModel,
3059
- createYjsModel,
3510
+ createBasicBundle,
3511
+ createComment,
3512
+ createDataExtensions,
3513
+ createMarkdownExtensions,
3514
+ createThemeExtensions,
3060
3515
  defaultMarkdownSlots,
3061
3516
  defaultOptions,
3062
3517
  defaultSlots,
3063
3518
  defaultTextSlots,
3064
3519
  defaultTheme,
3520
+ focusComment,
3521
+ formatting,
3065
3522
  getToken,
3523
+ heading2 as heading,
3066
3524
  hr,
3067
3525
  image,
3526
+ insertCodeblock,
3527
+ insertTable,
3528
+ keymap7 as keymap,
3068
3529
  link,
3069
3530
  listener,
3070
3531
  logChanges,
3071
- markdownBundle,
3072
3532
  markdownHighlightStyle,
3073
3533
  markdownTags,
3074
3534
  markdownTagsExtensions,
@@ -3077,16 +3537,24 @@ export {
3077
3537
  modelState,
3078
3538
  outliner,
3079
3539
  setComments,
3080
- setFocus,
3540
+ setHeading,
3081
3541
  setSelection,
3082
3542
  table,
3083
3543
  tags2 as tags,
3084
3544
  tasklist,
3085
3545
  textTheme,
3546
+ toggleBold,
3547
+ toggleItalic,
3548
+ toggleList,
3549
+ toggleStrikethrough,
3550
+ toggleStyle,
3086
3551
  typewriter,
3087
- useAwareness,
3552
+ useActionHandler,
3088
3553
  useComments,
3554
+ useEditorView,
3555
+ useInMemoryTextModel,
3556
+ useTextEditor,
3089
3557
  useTextModel,
3090
- yjs
3558
+ useToolbarContext
3091
3559
  };
3092
3560
  //# sourceMappingURL=index.mjs.map