@dxos/react-ui-editor 0.3.11-main.fbbdc2a → 0.3.11-main.fc97a54

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 (202) hide show
  1. package/dist/lib/browser/index.mjs +2904 -1394
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +16 -14
  5. package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
  6. package/dist/types/src/components/TextEditor/TextEditor.d.ts +20 -17
  7. package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
  8. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +6 -6
  9. package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
  10. package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -1
  11. package/dist/types/src/components/TextEditor/hooks.stories.d.ts +23 -0
  12. package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -0
  13. package/dist/types/src/components/Toolbar/Toolbar.d.ts +29 -0
  14. package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
  15. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +25 -0
  16. package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
  17. package/dist/types/src/components/Toolbar/index.d.ts +2 -0
  18. package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
  19. package/dist/types/src/components/index.d.ts +1 -0
  20. package/dist/types/src/components/index.d.ts.map +1 -1
  21. package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
  22. package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
  23. package/dist/types/src/extensions/automerge/automerge.spec.d.ts +2 -0
  24. package/dist/types/src/extensions/automerge/automerge.spec.d.ts.map +1 -0
  25. package/dist/types/src/extensions/automerge/automerge.test.d.ts +2 -0
  26. package/dist/types/src/extensions/automerge/automerge.test.d.ts.map +1 -0
  27. package/dist/types/src/extensions/automerge/cursor.d.ts +1 -1
  28. package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
  29. package/dist/types/src/extensions/automerge/defs.d.ts +9 -11
  30. package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
  31. package/dist/types/src/extensions/automerge/semaphore.d.ts +8 -12
  32. package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
  33. package/dist/types/src/extensions/automerge/update-automerge.d.ts +2 -2
  34. package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
  35. package/dist/types/src/extensions/awareness.d.ts +2 -2
  36. package/dist/types/src/extensions/awareness.d.ts.map +1 -1
  37. package/dist/types/src/extensions/basic.d.ts +4 -5
  38. package/dist/types/src/extensions/basic.d.ts.map +1 -1
  39. package/dist/types/src/extensions/comments.d.ts +41 -20
  40. package/dist/types/src/extensions/comments.d.ts.map +1 -1
  41. package/dist/types/src/{util → extensions}/cursor.d.ts +10 -2
  42. package/dist/types/src/extensions/cursor.d.ts.map +1 -0
  43. package/dist/types/src/extensions/index.d.ts +2 -8
  44. package/dist/types/src/extensions/index.d.ts.map +1 -1
  45. package/dist/types/src/extensions/markdown/bundle.d.ts +3 -6
  46. package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
  47. package/dist/types/src/extensions/markdown/code.d.ts.map +1 -0
  48. package/dist/types/src/extensions/markdown/formatting.d.ts +58 -0
  49. package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -0
  50. package/dist/types/src/extensions/markdown/formatting.test.d.ts +3 -0
  51. package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -0
  52. package/dist/types/src/extensions/markdown/heading.d.ts +6 -0
  53. package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -0
  54. package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
  55. package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -0
  56. package/dist/types/src/extensions/markdown/image.d.ts.map +1 -0
  57. package/dist/types/src/extensions/markdown/index.d.ts +8 -0
  58. package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
  59. package/dist/types/src/extensions/markdown/link.d.ts.map +1 -0
  60. package/dist/types/src/extensions/markdown/table.d.ts.map +1 -0
  61. package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -0
  62. package/dist/types/src/extensions/mention.d.ts.map +1 -1
  63. package/dist/types/src/extensions/outliner.d.ts +4 -0
  64. package/dist/types/src/extensions/outliner.d.ts.map +1 -0
  65. package/dist/types/src/hooks/awareness-provider.d.ts +7 -4
  66. package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -1
  67. package/dist/types/src/hooks/defs.d.ts +25 -0
  68. package/dist/types/src/hooks/defs.d.ts.map +1 -0
  69. package/dist/types/src/hooks/index.d.ts +4 -2
  70. package/dist/types/src/hooks/index.d.ts.map +1 -1
  71. package/dist/types/src/hooks/useActionHandler.d.ts +4 -0
  72. package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -0
  73. package/dist/types/src/hooks/useEditorView.d.ts +17 -0
  74. package/dist/types/src/hooks/useEditorView.d.ts.map +1 -0
  75. package/dist/types/src/hooks/useTextEditor.d.ts +39 -0
  76. package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -0
  77. package/dist/types/src/hooks/useTextModel.d.ts +14 -32
  78. package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
  79. package/dist/types/src/index.d.ts +3 -0
  80. package/dist/types/src/index.d.ts.map +1 -1
  81. package/dist/types/src/styles/markdown.d.ts +2 -2
  82. package/dist/types/src/styles/markdown.d.ts.map +1 -1
  83. package/dist/types/src/styles/tokens.d.ts +1 -0
  84. package/dist/types/src/styles/tokens.d.ts.map +1 -1
  85. package/dist/types/src/themes/default.d.ts.map +1 -1
  86. package/dist/types/src/util.d.ts +7 -0
  87. package/dist/types/src/util.d.ts.map +1 -0
  88. package/package.json +48 -37
  89. package/src/components/TextEditor/MarkdownEditor.stories.tsx +85 -92
  90. package/src/components/TextEditor/TextEditor.stories.tsx +12 -46
  91. package/src/components/TextEditor/TextEditor.tsx +135 -95
  92. package/src/components/TextEditor/automerge.stories.tsx +1 -2
  93. package/src/components/TextEditor/hooks.stories.tsx +111 -0
  94. package/src/components/Toolbar/Toolbar.stories.tsx +102 -0
  95. package/src/components/Toolbar/Toolbar.tsx +264 -0
  96. package/src/components/Toolbar/index.ts +5 -0
  97. package/src/components/index.ts +1 -0
  98. package/src/extensions/autocomplete.ts +23 -19
  99. package/src/extensions/automerge/automerge.spec.tsx +76 -0
  100. package/src/extensions/automerge/automerge.test.ts +13 -0
  101. package/src/extensions/automerge/automerge.ts +55 -46
  102. package/src/extensions/automerge/cursor.ts +5 -4
  103. package/src/extensions/automerge/defs.ts +13 -34
  104. package/src/extensions/automerge/semaphore.ts +33 -32
  105. package/src/extensions/automerge/update-automerge.ts +14 -8
  106. package/src/extensions/automerge/update-codemirror.ts +5 -5
  107. package/src/extensions/awareness.ts +46 -49
  108. package/src/extensions/basic.ts +17 -10
  109. package/src/extensions/blast.ts +4 -1
  110. package/src/extensions/comments.ts +332 -267
  111. package/src/extensions/cursor.ts +50 -0
  112. package/src/extensions/index.ts +2 -8
  113. package/src/extensions/markdown/bundle.ts +23 -28
  114. package/src/extensions/markdown/code.ts +150 -0
  115. package/src/extensions/markdown/formatting.test.ts +482 -0
  116. package/src/extensions/markdown/formatting.ts +1237 -0
  117. package/src/extensions/markdown/heading.ts +59 -0
  118. package/src/extensions/markdown/highlight.ts +11 -26
  119. package/src/extensions/markdown/hr.ts +71 -0
  120. package/src/extensions/markdown/image.ts +87 -0
  121. package/src/extensions/markdown/index.ts +8 -0
  122. package/src/extensions/{link.ts → markdown/link.ts} +90 -83
  123. package/src/extensions/{table.ts → markdown/table.ts} +10 -4
  124. package/src/extensions/markdown/tasklist.ts +110 -0
  125. package/src/extensions/mention.ts +9 -2
  126. package/src/extensions/outliner.ts +12 -0
  127. package/src/hooks/awareness-provider.ts +24 -20
  128. package/src/hooks/defs.ts +42 -0
  129. package/src/hooks/index.ts +5 -2
  130. package/src/hooks/useActionHandler.ts +93 -0
  131. package/src/hooks/useEditorView.ts +29 -0
  132. package/src/hooks/useTextEditor.ts +153 -0
  133. package/src/hooks/useTextModel.ts +67 -60
  134. package/src/index.ts +3 -0
  135. package/src/styles/markdown.ts +9 -12
  136. package/src/styles/tokens.ts +3 -0
  137. package/src/themes/default.ts +59 -83
  138. package/src/util.ts +41 -0
  139. package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
  140. package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
  141. package/dist/types/src/components/TextEditor/yjs.stories.d.ts +0 -12
  142. package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
  143. package/dist/types/src/extensions/code.d.ts.map +0 -1
  144. package/dist/types/src/extensions/hr.d.ts.map +0 -1
  145. package/dist/types/src/extensions/image.d.ts.map +0 -1
  146. package/dist/types/src/extensions/link.d.ts.map +0 -1
  147. package/dist/types/src/extensions/mermaid.d.ts +0 -3
  148. package/dist/types/src/extensions/mermaid.d.ts.map +0 -1
  149. package/dist/types/src/extensions/table.d.ts.map +0 -1
  150. package/dist/types/src/extensions/tasklist.d.ts.map +0 -1
  151. package/dist/types/src/extensions/yjs/cursor.d.ts +0 -4
  152. package/dist/types/src/extensions/yjs/cursor.d.ts.map +0 -1
  153. package/dist/types/src/extensions/yjs/index.d.ts +0 -2
  154. package/dist/types/src/extensions/yjs/index.d.ts.map +0 -1
  155. package/dist/types/src/extensions/yjs/yjs.d.ts +0 -4
  156. package/dist/types/src/extensions/yjs/yjs.d.ts.map +0 -1
  157. package/dist/types/src/extensions/yjs/yjs.test.d.ts +0 -2
  158. package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +0 -1
  159. package/dist/types/src/hooks/automerge.d.ts +0 -3
  160. package/dist/types/src/hooks/automerge.d.ts.map +0 -1
  161. package/dist/types/src/hooks/yjs.d.ts +0 -27
  162. package/dist/types/src/hooks/yjs.d.ts.map +0 -1
  163. package/dist/types/src/testing/index.d.ts +0 -3
  164. package/dist/types/src/testing/index.d.ts.map +0 -1
  165. package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
  166. package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
  167. package/dist/types/src/testing/proto/index.d.ts +0 -2
  168. package/dist/types/src/testing/proto/index.d.ts.map +0 -1
  169. package/dist/types/src/testing/replicator.d.ts +0 -45
  170. package/dist/types/src/testing/replicator.d.ts.map +0 -1
  171. package/dist/types/src/util/cursor.d.ts.map +0 -1
  172. package/dist/types/src/util/index.d.ts +0 -3
  173. package/dist/types/src/util/index.d.ts.map +0 -1
  174. package/dist/types/src/util/util.d.ts +0 -5
  175. package/dist/types/src/util/util.d.ts.map +0 -1
  176. package/src/components/TextEditor/codemirror.stories.ts +0 -115
  177. package/src/components/TextEditor/yjs.stories.tsx +0 -56
  178. package/src/extensions/code.ts +0 -99
  179. package/src/extensions/hr.ts +0 -74
  180. package/src/extensions/image.ts +0 -69
  181. package/src/extensions/mermaid.ts +0 -11
  182. package/src/extensions/tasklist.ts +0 -121
  183. package/src/extensions/yjs/cursor.ts +0 -21
  184. package/src/extensions/yjs/index.ts +0 -5
  185. package/src/extensions/yjs/yjs.test.ts +0 -35
  186. package/src/extensions/yjs/yjs.ts +0 -16
  187. package/src/hooks/automerge.ts +0 -52
  188. package/src/hooks/yjs.ts +0 -178
  189. package/src/testing/index.ts +0 -6
  190. package/src/testing/proto/gen/schema.ts +0 -49
  191. package/src/testing/proto/index.ts +0 -5
  192. package/src/testing/proto/schema.proto +0 -15
  193. package/src/testing/replicator.ts +0 -184
  194. package/src/util/cursor.ts +0 -29
  195. package/src/util/index.ts +0 -6
  196. package/src/util/util.ts +0 -18
  197. /package/dist/types/src/extensions/{code.d.ts → markdown/code.d.ts} +0 -0
  198. /package/dist/types/src/extensions/{hr.d.ts → markdown/hr.d.ts} +0 -0
  199. /package/dist/types/src/extensions/{image.d.ts → markdown/image.d.ts} +0 -0
  200. /package/dist/types/src/extensions/{link.d.ts → markdown/link.d.ts} +0 -0
  201. /package/dist/types/src/extensions/{table.d.ts → markdown/table.d.ts} +0 -0
  202. /package/dist/types/src/extensions/{tasklist.d.ts → markdown/tasklist.d.ts} +0 -0
@@ -7,74 +7,75 @@
7
7
  import { type StateField } from '@codemirror/state';
8
8
  import { type EditorView } from '@codemirror/view';
9
9
 
10
- import { next as automerge } from '@dxos/automerge/automerge';
10
+ import { next as A } from '@dxos/automerge/automerge';
11
11
 
12
12
  import {
13
13
  getLastHeads,
14
14
  getPath,
15
- isReconcileTx,
16
- reconcileAnnotationType,
15
+ isReconcile,
16
+ reconcileAnnotation,
17
17
  updateHeads,
18
18
  type IDocHandle,
19
- type Value,
19
+ type State,
20
20
  } from './defs';
21
21
  import { updateAutomerge } from './update-automerge';
22
22
  import { updateCodeMirror } from './update-codemirror';
23
23
 
24
- type Doc<T> = automerge.Doc<T>;
25
- type Heads = automerge.Heads;
26
-
27
- type ChangeFn = (atHeads: Heads, change: (doc: Doc<unknown>) => void) => Heads | undefined;
28
-
29
24
  /**
30
- * TODO(burdon): Comment.
25
+ * Implements three-way merge (on each mutation).
31
26
  */
32
27
  export class PatchSemaphore {
33
- _inReconcile = false;
34
- _queue: Array<ChangeFn> = [];
28
+ private _inReconcile = false;
35
29
 
36
- constructor(private readonly _field: StateField<Value>) {}
30
+ // prettier-ignore
31
+ constructor(
32
+ private readonly _handle: IDocHandle,
33
+ private readonly _state: StateField<State>
34
+ ) {}
37
35
 
38
- reconcile = (handle: IDocHandle, view: EditorView) => {
39
- if (this._inReconcile) {
40
- return;
36
+ reconcile(view: EditorView) {
37
+ if (!this._inReconcile) {
38
+ this._inReconcile = true;
39
+ this.doReconcile(view);
40
+ this._inReconcile = false;
41
41
  }
42
- this._inReconcile = true;
42
+ }
43
+
44
+ private doReconcile(view: EditorView) {
45
+ const path = getPath(view.state, this._state);
43
46
 
44
- const path = getPath(view.state, this._field);
45
- const oldHeads = getLastHeads(view.state, this._field);
47
+ // Get the heads before the unreconciled transactions are applied.
48
+ const oldHeads = getLastHeads(view.state, this._state);
46
49
  let selection = view.state.selection;
47
50
 
48
51
  // First undo all the unreconciled transactions.
49
- const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
52
+ const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcile(tx));
50
53
  const toInvert = transactions.slice().reverse();
51
- for (const tx of toInvert) {
52
- const inverted = tx.changes.invert(tx.startState.doc);
54
+ for (const tr of toInvert) {
55
+ const inverted = tr.changes.invert(tr.startState.doc);
53
56
  selection = selection.map(inverted);
54
57
  view.dispatch({
55
58
  changes: inverted,
56
- annotations: reconcileAnnotationType.of(true),
59
+ annotations: reconcileAnnotation.of(true),
57
60
  });
58
61
  }
59
62
 
60
63
  // Apply the unreconciled transactions to the document.
61
- let newHeads = updateAutomerge(this._field, handle, transactions, view.state);
62
-
63
64
  // NOTE: null and undefined each come from automerge and repo respectively.
65
+ let newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
64
66
  if (newHeads === null || newHeads === undefined) {
65
- // TODO: @alexjg this is the call that's resetting the editor state on click
66
- newHeads = automerge.getHeads(handle.docSync()!);
67
+ // TODO(alexjg): this is the call that's resetting the editor state on click.
68
+ newHeads = A.getHeads(this._handle.docSync()!);
67
69
  }
68
70
 
69
71
  // Now get the diff between the updated state of the document and the heads and apply that to the codemirror doc.
70
- const diff = automerge.equals(oldHeads, newHeads) ? [] : automerge.diff(handle.docSync()!, oldHeads, newHeads);
72
+ const diff = A.equals(oldHeads, newHeads) ? [] : A.diff(this._handle.docSync()!, oldHeads, newHeads);
71
73
  updateCodeMirror(view, selection, path, diff);
72
74
 
75
+ // Update automerge state.
73
76
  view.dispatch({
74
77
  effects: updateHeads(newHeads),
75
- annotations: reconcileAnnotationType.of({}),
78
+ annotations: reconcileAnnotation.of(false),
76
79
  });
77
-
78
- this._inReconcile = false;
79
- };
80
+ }
80
81
  }
@@ -4,17 +4,17 @@
4
4
  // Ref: https://github.com/automerge/automerge-codemirror
5
5
  //
6
6
 
7
- import { type EditorState, type StateField, type Text, type Transaction } from '@codemirror/state';
7
+ import { type EditorState, type StateField, type Transaction, type Text } from '@codemirror/state';
8
8
 
9
- import { next as am, type Heads } from '@dxos/automerge/automerge';
9
+ import { next as A, type Heads } from '@dxos/automerge/automerge';
10
10
 
11
- import { type IDocHandle, type Value } from './defs';
11
+ import { type IDocHandle, type State } from './defs';
12
12
 
13
13
  export const updateAutomerge = (
14
- field: StateField<Value>,
14
+ field: StateField<State>,
15
15
  handle: IDocHandle,
16
16
  transactions: Transaction[],
17
- state: EditorState,
17
+ state: EditorState, // TODO(burdon): Just pass in the state field value?
18
18
  ): Heads | undefined => {
19
19
  const { lastHeads, path } = state.field(field);
20
20
 
@@ -31,12 +31,18 @@ export const updateAutomerge = (
31
31
  return undefined;
32
32
  }
33
33
 
34
- const newHeads = handle.changeAt(lastHeads, (doc: am.Doc<unknown>) => {
34
+ const newHeads = handle.changeAt(lastHeads, (doc: A.Doc<unknown>) => {
35
+ const invertedTransactions: { from: number; del: number; insert: Text }[] = [];
35
36
  for (const tr of transactions) {
36
- tr.changes.iterChanges((fromA: number, toA: number, _fromB: number, _toB: number, inserted: Text) => {
37
- am.splice(doc, path, fromA, toA - fromA, inserted.toString());
37
+ tr.changes.iterChanges((fromA, toA, _fromB, _toB, insert) => {
38
+ invertedTransactions.push({ from: fromA, del: toA - fromA, insert });
38
39
  });
39
40
  }
41
+
42
+ // TODO(burdon): Hack to apply in reverse order to properly apply range.
43
+ invertedTransactions.reverse().forEach(({ from, del, insert }) => {
44
+ A.splice(doc, path.slice(), from, del, insert.toString());
45
+ });
40
46
  });
41
47
 
42
48
  return newHeads ?? undefined;
@@ -16,7 +16,7 @@ import {
16
16
  type SpliceTextPatch,
17
17
  } from '@dxos/automerge/automerge';
18
18
 
19
- import { reconcileAnnotationType } from './defs';
19
+ import { reconcileAnnotation } from './defs';
20
20
 
21
21
  export const updateCodeMirror = (view: EditorView, selection: EditorSelection, target: Prop[], patches: Patch[]) => {
22
22
  for (const patch of patches) {
@@ -26,14 +26,14 @@ export const updateCodeMirror = (view: EditorView, selection: EditorSelection, t
26
26
  selection = selection.map(changeSet, 1);
27
27
  view.dispatch({
28
28
  changes: changeSet,
29
- annotations: reconcileAnnotationType.of({}),
29
+ annotations: reconcileAnnotation.of(false),
30
30
  });
31
31
  }
32
32
  }
33
33
 
34
34
  view.dispatch({
35
35
  selection,
36
- annotations: reconcileAnnotationType.of({}),
36
+ annotations: reconcileAnnotation.of(false),
37
37
  });
38
38
  };
39
39
 
@@ -57,7 +57,7 @@ const handleInsert = (target: Prop[], patch: InsertPatch): Array<ChangeSpec> =>
57
57
  return [];
58
58
  }
59
59
 
60
- const text = patch.values.map((v) => (v ? v.toString() : '')).join('');
60
+ const text = patch.values.map((value) => (value ? value.toString() : '')).join('');
61
61
  return [{ from: index, to: index, insert: text }];
62
62
  };
63
63
 
@@ -88,7 +88,7 @@ const handlePut = (target: Prop[], patch: PutPatch, state: EditorState): Array<C
88
88
 
89
89
  const length = state.doc.length;
90
90
  if (typeof patch.value !== 'string') {
91
- return []; // TODO(dmaretskyi): How to handle non string values?
91
+ return []; // TODO(dmaretskyi): How to handle non-string values?
92
92
  }
93
93
 
94
94
  return [{ from: 0, to: length, insert: patch.value as any }];
@@ -16,7 +16,7 @@ import {
16
16
  import { Event } from '@dxos/async';
17
17
  import { Context } from '@dxos/context';
18
18
 
19
- import { CursorConverter } from '../util';
19
+ import { Cursor, type CursorConverter } from './cursor';
20
20
 
21
21
  export interface AwarenessProvider {
22
22
  remoteStateChange: Event<void>;
@@ -24,8 +24,8 @@ export interface AwarenessProvider {
24
24
  open(): void;
25
25
  close(): void;
26
26
 
27
- update(position: AwarenessPosition | undefined): void;
28
27
  getRemoteStates(): AwarenessState[];
28
+ update(position: AwarenessPosition | undefined): void;
29
29
  }
30
30
 
31
31
  const dummyProvider: AwarenessProvider = {
@@ -34,11 +34,11 @@ const dummyProvider: AwarenessProvider = {
34
34
  open: () => {},
35
35
  close: () => {},
36
36
 
37
- update: () => {},
38
37
  getRemoteStates: () => [],
38
+ update: () => {},
39
39
  };
40
40
 
41
- export const AwarenessProvider = Facet.define<AwarenessProvider, AwarenessProvider>({
41
+ export const awarenessProvider = Facet.define<AwarenessProvider, AwarenessProvider>({
42
42
  combine: (providers) => providers[0] ?? dummyProvider,
43
43
  });
44
44
 
@@ -66,10 +66,9 @@ export type AwarenessState = {
66
66
  /**
67
67
  * Extension provides presence information about other peers.
68
68
  */
69
- // TODO(burdon): Why provide default?
70
69
  export const awareness = (provider = dummyProvider): Extension => {
71
70
  return [
72
- AwarenessProvider.of(provider),
71
+ awarenessProvider.of(provider),
73
72
  ViewPlugin.fromClass(RemoteSelectionsDecorator, {
74
73
  decorations: (value) => value.decorations,
75
74
  }),
@@ -91,8 +90,8 @@ export class RemoteSelectionsDecorator implements PluginValue {
91
90
  private _lastHead?: number = undefined;
92
91
 
93
92
  constructor(view: EditorView) {
94
- this._cursorConverter = view.state.facet(CursorConverter);
95
- this._provider = view.state.facet(AwarenessProvider);
93
+ this._cursorConverter = view.state.facet(Cursor.converter);
94
+ this._provider = view.state.facet(awarenessProvider);
96
95
  this._provider.open();
97
96
  this._provider.remoteStateChange.on(this._ctx, () => {
98
97
  view.dispatch({ annotations: [RemoteSelectionChangedAnnotation.of([])] });
@@ -156,7 +155,7 @@ export class RemoteSelectionsDecorator implements PluginValue {
156
155
  to: end,
157
156
  value: Decoration.mark({
158
157
  attributes: { style: `background-color: ${lightColor}` },
159
- class: 'cm-ySelection',
158
+ class: 'cm-collab-selection',
160
159
  }),
161
160
  });
162
161
  } else {
@@ -166,7 +165,7 @@ export class RemoteSelectionsDecorator implements PluginValue {
166
165
  to: startLine.from + startLine.length,
167
166
  value: Decoration.mark({
168
167
  attributes: { style: `background-color: ${color}` },
169
- class: 'cm-ySelection',
168
+ class: 'cm-collab-selection',
170
169
  }),
171
170
  });
172
171
 
@@ -176,7 +175,7 @@ export class RemoteSelectionsDecorator implements PluginValue {
176
175
  to: end,
177
176
  value: Decoration.mark({
178
177
  attributes: { style: `background-color: ${color}` },
179
- class: 'cm-ySelection',
178
+ class: 'cm-collab-selection',
180
179
  }),
181
180
  });
182
181
 
@@ -186,7 +185,7 @@ export class RemoteSelectionsDecorator implements PluginValue {
186
185
  from: linePos,
187
186
  to: linePos,
188
187
  value: Decoration.line({
189
- attributes: { style: `background-color: ${color}`, class: 'cm-yLineSelection' },
188
+ attributes: { style: `background-color: ${color}`, class: 'cm-collab-selectionLine' },
190
189
  }),
191
190
  });
192
191
  }
@@ -208,24 +207,25 @@ export class RemoteSelectionsDecorator implements PluginValue {
208
207
  }
209
208
 
210
209
  class RemoteCaretWidget extends WidgetType {
211
- constructor(public name: string, public color: string) {
210
+ constructor(
211
+ private readonly _name: string,
212
+ private readonly _color: string,
213
+ ) {
212
214
  super();
213
- this.name = name;
214
- this.color = color;
215
215
  }
216
216
 
217
- toDOM(): HTMLElement {
217
+ override toDOM(): HTMLElement {
218
218
  const span = document.createElement('span');
219
- span.className = 'cm-ySelectionCaret';
220
- span.style.backgroundColor = this.color;
221
- span.style.borderColor = this.color;
219
+ span.className = 'cm-collab-selectionCaret';
220
+ span.style.backgroundColor = this._color;
221
+ span.style.borderColor = this._color;
222
222
 
223
223
  const dot = document.createElement('div');
224
- dot.className = 'cm-ySelectionCaretDot';
224
+ dot.className = 'cm-collab-selectionCaretDot';
225
225
 
226
226
  const info = document.createElement('div');
227
- info.className = 'cm-ySelectionInfo';
228
- info.innerText = this.name;
227
+ info.className = 'cm-collab-selectionInfo';
228
+ info.innerText = this._name;
229
229
 
230
230
  span.appendChild(document.createTextNode('\u2060'));
231
231
  span.appendChild(dot);
@@ -236,18 +236,14 @@ class RemoteCaretWidget extends WidgetType {
236
236
  return span;
237
237
  }
238
238
 
239
- override eq(widget: this) {
240
- return widget.color === this.color;
241
- }
242
-
243
- compare(widget: this) {
244
- return widget.color === this.color;
245
- }
246
-
247
239
  override updateDOM() {
248
240
  return false;
249
241
  }
250
242
 
243
+ override eq(widget: this) {
244
+ return widget._color === this._color;
245
+ }
246
+
251
247
  override get estimatedHeight() {
252
248
  return -1;
253
249
  }
@@ -257,14 +253,13 @@ class RemoteCaretWidget extends WidgetType {
257
253
  }
258
254
  }
259
255
 
260
- // TODO(burdon): Rename prefix (y for yjs?)
261
256
  const styles = EditorView.baseTheme({
262
- '.cm-ySelection': {},
263
- '.cm-yLineSelection': {
257
+ '.cm-collab-selection': {},
258
+ '.cm-collab-selectionLine': {
264
259
  padding: 0,
265
260
  margin: '0px 2px 0px 4px',
266
261
  },
267
- '.cm-ySelectionCaret': {
262
+ '.cm-collab-selectionCaret': {
268
263
  position: 'relative',
269
264
  borderLeft: '1px solid black',
270
265
  borderRight: '1px solid black',
@@ -272,44 +267,46 @@ const styles = EditorView.baseTheme({
272
267
  marginRight: '-1px',
273
268
  boxSizing: 'border-box',
274
269
  display: 'inline',
270
+ cursor: 'pointer',
275
271
  },
276
- '.cm-ySelectionCaretDot': {
272
+ '.cm-collab-selectionCaretDot': {
277
273
  borderRadius: '50%',
278
274
  position: 'absolute',
279
- width: '.4em',
280
- height: '.4em',
281
- top: '-.2em',
282
- left: '-.2em',
275
+ width: '.5em',
276
+ height: '.5em',
277
+ top: '-.25em',
278
+ left: '-.25em',
283
279
  backgroundColor: 'inherit',
284
280
  transition: 'transform .3s ease-in-out',
285
281
  boxSizing: 'border-box',
286
282
  },
287
- '.cm-ySelectionCaret:hover > .cm-ySelectionCaretDot': {
288
- transformOrigin: 'bottom center',
283
+ '.cm-collab-selectionCaret:hover > .cm-collab-selectionCaretDot': {
289
284
  transform: 'scale(0)',
285
+ transformOrigin: 'center',
290
286
  },
291
- '.cm-ySelectionInfo': {
287
+ '.cm-collab-selectionInfo': {
292
288
  position: 'absolute',
293
- top: '-1.05em',
294
- left: '-1px',
289
+ transform: 'translate(-50%, 0)',
290
+ top: '-20px',
291
+ left: 0,
295
292
  fontSize: '.75em',
296
- fontFamily: 'serif',
293
+ fontFamily: 'sans-serif',
297
294
  fontStyle: 'normal',
298
295
  fontWeight: 'normal',
299
296
  lineHeight: 'normal',
300
297
  userSelect: 'none',
301
298
  color: 'white',
302
- paddingLeft: '2px',
303
- paddingRight: '2px',
299
+ padding: '2px',
304
300
  zIndex: 101,
305
301
  transition: 'opacity .3s ease-in-out',
306
302
  backgroundColor: 'inherit',
307
- // these should be separate
303
+ borderRadius: '2px',
304
+ // These should be separate.
308
305
  opacity: 0,
309
306
  transitionDelay: '0s',
310
307
  whiteSpace: 'nowrap',
311
308
  },
312
- '.cm-ySelectionCaret:hover > .cm-ySelectionInfo': {
309
+ '.cm-collab-selectionCaret:hover > .cm-collab-selectionInfo': {
313
310
  opacity: 1,
314
311
  transitionDelay: '0s',
315
312
  },
@@ -3,30 +3,37 @@
3
3
  //
4
4
 
5
5
  import { closeBrackets } from '@codemirror/autocomplete';
6
+ import { history } from '@codemirror/commands';
6
7
  import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
7
8
  import { type Extension } from '@codemirror/state';
8
9
  import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
9
- import { drawSelection, EditorView, placeholder } from '@codemirror/view';
10
+ import { drawSelection, EditorView, highlightActiveLine, placeholder } from '@codemirror/view';
10
11
 
11
- import type { ThemeMode } from '@dxos/react-ui';
12
+ import { type ThemeMode } from '@dxos/react-ui';
13
+ import { isNotFalsy } from '@dxos/util';
14
+
15
+ import { type TextEditorProps } from '../components';
12
16
 
13
17
  export type BasicBundleOptions = {
14
- readonly?: boolean;
15
18
  themeMode?: ThemeMode;
16
- placeholder?: string;
17
- };
19
+ } & Pick<TextEditorProps, 'placeholder' | 'lineWrapping'>;
18
20
 
19
- export const basicBundle = ({ readonly, themeMode, placeholder: _placeholder }: BasicBundleOptions): Extension[] =>
21
+ export const createBasicBundle = ({
22
+ themeMode,
23
+ placeholder: _placeholder,
24
+ lineWrapping = true,
25
+ }: BasicBundleOptions = {}): Extension[] =>
20
26
  [
21
- EditorView.lineWrapping,
27
+ lineWrapping && EditorView.lineWrapping,
22
28
 
23
- // TODO(burdon): Compare with minimalSetup.
24
29
  // https://codemirror.net/docs/ref/#codemirror.minimalSetup
25
30
  bracketMatching(),
26
31
  closeBrackets(),
27
32
  drawSelection(),
33
+ highlightActiveLine(),
34
+ history(),
28
35
  _placeholder && placeholder(_placeholder),
29
36
 
30
- // TODO(burdon): Is this required?
37
+ // https://github.com/codemirror/theme-one-dark
31
38
  themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
32
- ].filter(Boolean) as Extension[];
39
+ ].filter(isNotFalsy);
@@ -125,7 +125,10 @@ class Blaster {
125
125
 
126
126
  _lastPoint = { x: 0, y: 0 };
127
127
 
128
- constructor(private readonly _node: HTMLElement, private readonly _options: BlastOptions) {
128
+ constructor(
129
+ private readonly _node: HTMLElement,
130
+ private readonly _options: BlastOptions,
131
+ ) {
129
132
  this._effect = this._options.effect === 1 ? new Effect1(_options) : new Effect2(_options);
130
133
  }
131
134