@dxos/react-ui-editor 0.3.11-main.00a28cb → 0.3.11-main.0252f93
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.
- package/dist/lib/browser/index.mjs +1304 -1092
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +12 -17
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +13 -5
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +9 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +14 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.spec.d.ts +2 -0
- package/dist/types/src/extensions/automerge/automerge.spec.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.test.d.ts +2 -0
- package/dist/types/src/extensions/automerge/automerge.test.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/defs.d.ts +8 -10
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/semaphore.d.ts +7 -6
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +2 -2
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/awareness.d.ts +2 -2
- package/dist/types/src/extensions/awareness.d.ts.map +1 -1
- package/dist/types/src/extensions/basic.d.ts +4 -5
- package/dist/types/src/extensions/basic.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +23 -15
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/cursor.d.ts +3 -3
- package/dist/types/src/extensions/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +0 -7
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +3 -6
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/code.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/formatting.d.ts +11 -0
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/heading.d.ts +6 -0
- package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/image.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts +8 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/table.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/tasklist.d.ts +3 -0
- package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -1
- package/dist/types/src/hooks/awareness-provider.d.ts +7 -4
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -1
- package/dist/types/src/hooks/defs.d.ts +25 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +3 -2
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useActionHandler.d.ts +4 -0
- package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts +17 -0
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts +2 -27
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts +2 -2
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +2 -0
- package/dist/types/src/util.d.ts.map +1 -1
- package/package.json +45 -36
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +64 -75
- package/src/components/TextEditor/TextEditor.tsx +103 -71
- package/src/components/TextEditor/comments.stories.tsx +46 -44
- package/src/components/Toolbar/Toolbar.stories.tsx +86 -0
- package/src/components/Toolbar/Toolbar.tsx +115 -0
- package/src/extensions/autocomplete.ts +6 -3
- package/src/extensions/automerge/automerge.spec.tsx +76 -0
- package/src/extensions/automerge/automerge.test.ts +13 -0
- package/src/extensions/automerge/automerge.ts +50 -39
- package/src/extensions/automerge/cursor.ts +3 -3
- package/src/extensions/automerge/defs.ts +11 -36
- package/src/extensions/automerge/semaphore.ts +31 -28
- package/src/extensions/automerge/update-automerge.ts +14 -8
- package/src/extensions/automerge/update-codemirror.ts +5 -5
- package/src/extensions/awareness.ts +17 -17
- package/src/extensions/basic.ts +22 -17
- package/src/extensions/comments.ts +247 -179
- package/src/extensions/cursor.ts +7 -3
- package/src/extensions/index.ts +0 -7
- package/src/extensions/markdown/bundle.ts +20 -30
- package/src/extensions/markdown/code.ts +142 -0
- package/src/extensions/markdown/formatting.ts +159 -0
- package/src/extensions/markdown/heading.ts +59 -0
- package/src/extensions/markdown/highlight.ts +9 -15
- package/src/extensions/markdown/hr.ts +71 -0
- package/src/extensions/markdown/index.ts +8 -0
- package/src/extensions/{link.ts → markdown/link.ts} +5 -2
- package/src/extensions/{tasklist.ts → markdown/tasklist.ts} +48 -34
- package/src/extensions/mention.ts +9 -2
- package/src/hooks/awareness-provider.ts +24 -20
- package/src/hooks/defs.ts +42 -0
- package/src/hooks/index.ts +3 -2
- package/src/hooks/useActionHandler.ts +45 -0
- package/src/hooks/useTextEditor.ts +29 -0
- package/src/hooks/useTextModel.ts +49 -55
- package/src/styles/markdown.ts +9 -10
- package/src/themes/default.ts +1 -3
- package/src/util.ts +26 -3
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/code.d.ts.map +0 -1
- package/dist/types/src/extensions/hr.d.ts.map +0 -1
- package/dist/types/src/extensions/image.d.ts.map +0 -1
- package/dist/types/src/extensions/link.d.ts.map +0 -1
- package/dist/types/src/extensions/table.d.ts.map +0 -1
- package/dist/types/src/extensions/tasklist.d.ts +0 -7
- package/dist/types/src/extensions/tasklist.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/cursor.d.ts +0 -4
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/index.d.ts +0 -2
- package/dist/types/src/extensions/yjs/index.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.d.ts +0 -4
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.test.d.ts +0 -2
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge.d.ts +0 -3
- package/dist/types/src/hooks/automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs.d.ts +0 -27
- package/dist/types/src/hooks/yjs.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
- package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
- package/dist/types/src/testing/proto/index.d.ts +0 -2
- package/dist/types/src/testing/proto/index.d.ts.map +0 -1
- package/dist/types/src/testing/replicator.d.ts +0 -45
- package/dist/types/src/testing/replicator.d.ts.map +0 -1
- package/src/components/TextEditor/codemirror.stories.ts +0 -115
- package/src/components/TextEditor/yjs.stories.tsx +0 -56
- package/src/extensions/code.ts +0 -104
- package/src/extensions/hr.ts +0 -72
- package/src/extensions/yjs/cursor.ts +0 -22
- package/src/extensions/yjs/index.ts +0 -5
- package/src/extensions/yjs/yjs.test.ts +0 -35
- package/src/extensions/yjs/yjs.ts +0 -16
- package/src/hooks/automerge.ts +0 -52
- package/src/hooks/yjs.ts +0 -156
- package/src/testing/index.ts +0 -6
- package/src/testing/proto/gen/schema.ts +0 -49
- package/src/testing/proto/index.ts +0 -5
- package/src/testing/proto/schema.proto +0 -15
- package/src/testing/replicator.ts +0 -184
- /package/dist/types/src/extensions/{code.d.ts → markdown/code.d.ts} +0 -0
- /package/dist/types/src/extensions/{hr.d.ts → markdown/hr.d.ts} +0 -0
- /package/dist/types/src/extensions/{image.d.ts → markdown/image.d.ts} +0 -0
- /package/dist/types/src/extensions/{link.d.ts → markdown/link.d.ts} +0 -0
- /package/dist/types/src/extensions/{table.d.ts → markdown/table.d.ts} +0 -0
- /package/src/extensions/{image.ts → markdown/image.ts} +0 -0
- /package/src/extensions/{table.ts → markdown/table.ts} +0 -0
|
@@ -4,57 +4,32 @@
|
|
|
4
4
|
// Ref: https://github.com/automerge/automerge-codemirror
|
|
5
5
|
//
|
|
6
6
|
|
|
7
|
-
import { Annotation, StateEffect, type StateField, type EditorState, type Transaction
|
|
7
|
+
import { Annotation, StateEffect, type StateField, type EditorState, type Transaction } from '@codemirror/state';
|
|
8
8
|
|
|
9
9
|
import { type ChangeFn, type ChangeOptions, type Doc, type Heads, type Prop } from '@dxos/automerge/automerge';
|
|
10
10
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
export type Value = {
|
|
14
|
-
lastHeads: Heads;
|
|
11
|
+
export type State = {
|
|
15
12
|
path: Prop[];
|
|
13
|
+
lastHeads: Heads;
|
|
16
14
|
unreconciledTransactions: Transaction[];
|
|
17
15
|
};
|
|
18
16
|
|
|
17
|
+
export const getPath = (state: EditorState, field: StateField<State>): Prop[] => state.field(field).path;
|
|
18
|
+
export const getLastHeads = (state: EditorState, field: StateField<State>): Heads => state.field(field).lastHeads;
|
|
19
|
+
|
|
19
20
|
export type UpdateHeads = {
|
|
20
21
|
newHeads: Heads;
|
|
21
22
|
};
|
|
22
23
|
|
|
23
|
-
export const
|
|
24
|
-
|
|
25
|
-
export const updateHeads = (newHeads: Heads): StateEffect<UpdateHeads> => effectType.of({ newHeads });
|
|
26
|
-
|
|
27
|
-
export const getLastHeads = (state: EditorState, field: StateField<Value>): Heads => state.field(field).lastHeads;
|
|
28
|
-
|
|
29
|
-
export const getPath = (state: EditorState, field: StateField<Value>): Prop[] => state.field(field).path;
|
|
30
|
-
|
|
31
|
-
export const reconcileAnnotationType = Annotation.define<unknown>();
|
|
32
|
-
|
|
33
|
-
export const isReconcileTx = (tr: Transaction): boolean => !!tr.annotation(reconcileAnnotationType);
|
|
24
|
+
export const updateHeadsEffect = StateEffect.define<UpdateHeads>({});
|
|
34
25
|
|
|
35
|
-
|
|
36
|
-
export const semaphoreFacet = Facet.define<PatchSemaphore, PatchSemaphore>({
|
|
37
|
-
combine: (values) => values.at(-1)!, // Take last.
|
|
38
|
-
});
|
|
26
|
+
export const updateHeads = (newHeads: Heads): StateEffect<UpdateHeads> => updateHeadsEffect.of({ newHeads });
|
|
39
27
|
|
|
40
|
-
|
|
41
|
-
export const makeReconcile = (tr: TransactionSpec) => {
|
|
42
|
-
if (tr.annotations != null) {
|
|
43
|
-
if (tr.annotations instanceof Array) {
|
|
44
|
-
tr.annotations = [...tr.annotations, reconcileAnnotationType.of({})];
|
|
45
|
-
} else {
|
|
46
|
-
tr.annotations = [tr.annotations, reconcileAnnotationType.of({})];
|
|
47
|
-
}
|
|
48
|
-
} else {
|
|
49
|
-
tr.annotations = [reconcileAnnotationType.of({})];
|
|
50
|
-
}
|
|
28
|
+
export const reconcileAnnotation = Annotation.define<boolean>();
|
|
51
29
|
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
// annotations: reconcileAnnotationType.of({})
|
|
55
|
-
// }
|
|
30
|
+
export const isReconcile = (tr: Transaction): boolean => {
|
|
31
|
+
return !!tr.annotation(reconcileAnnotation);
|
|
56
32
|
};
|
|
57
|
-
*/
|
|
58
33
|
|
|
59
34
|
export type IDocHandle<T = any> = {
|
|
60
35
|
docSync(): Doc<T> | undefined;
|
|
@@ -7,72 +7,75 @@
|
|
|
7
7
|
import { type StateField } from '@codemirror/state';
|
|
8
8
|
import { type EditorView } from '@codemirror/view';
|
|
9
9
|
|
|
10
|
-
import { next as
|
|
10
|
+
import { next as A } from '@dxos/automerge/automerge';
|
|
11
11
|
|
|
12
12
|
import {
|
|
13
13
|
getLastHeads,
|
|
14
14
|
getPath,
|
|
15
|
-
|
|
16
|
-
|
|
15
|
+
isReconcile,
|
|
16
|
+
reconcileAnnotation,
|
|
17
17
|
updateHeads,
|
|
18
18
|
type IDocHandle,
|
|
19
|
-
type
|
|
19
|
+
type State,
|
|
20
20
|
} from './defs';
|
|
21
21
|
import { updateAutomerge } from './update-automerge';
|
|
22
22
|
import { updateCodeMirror } from './update-codemirror';
|
|
23
23
|
|
|
24
24
|
/**
|
|
25
|
-
* Implements three-way merge (on each mutation
|
|
25
|
+
* Implements three-way merge (on each mutation).
|
|
26
26
|
*/
|
|
27
27
|
export class PatchSemaphore {
|
|
28
|
-
_inReconcile = false;
|
|
28
|
+
private _inReconcile = false;
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
// prettier-ignore
|
|
31
|
+
constructor(
|
|
32
|
+
private readonly _handle: IDocHandle,
|
|
33
|
+
private readonly _state: StateField<State>
|
|
34
|
+
) {}
|
|
31
35
|
|
|
32
|
-
reconcile
|
|
33
|
-
if (this._inReconcile) {
|
|
34
|
-
|
|
36
|
+
reconcile(view: EditorView) {
|
|
37
|
+
if (!this._inReconcile) {
|
|
38
|
+
this._inReconcile = true;
|
|
39
|
+
this.doReconcile(view);
|
|
40
|
+
this._inReconcile = false;
|
|
35
41
|
}
|
|
36
|
-
|
|
42
|
+
}
|
|
37
43
|
|
|
38
|
-
|
|
44
|
+
private doReconcile(view: EditorView) {
|
|
45
|
+
const path = getPath(view.state, this._state);
|
|
39
46
|
|
|
40
47
|
// Get the heads before the unreconciled transactions are applied.
|
|
41
|
-
const oldHeads = getLastHeads(view.state, this.
|
|
48
|
+
const oldHeads = getLastHeads(view.state, this._state);
|
|
42
49
|
let selection = view.state.selection;
|
|
43
50
|
|
|
44
51
|
// First undo all the unreconciled transactions.
|
|
45
|
-
const transactions = view.state.field(this.
|
|
52
|
+
const transactions = view.state.field(this._state).unreconciledTransactions.filter((tx) => !isReconcile(tx));
|
|
46
53
|
const toInvert = transactions.slice().reverse();
|
|
47
|
-
for (const
|
|
48
|
-
const inverted =
|
|
54
|
+
for (const tr of toInvert) {
|
|
55
|
+
const inverted = tr.changes.invert(tr.startState.doc);
|
|
49
56
|
selection = selection.map(inverted);
|
|
50
57
|
view.dispatch({
|
|
51
58
|
changes: inverted,
|
|
52
|
-
annotations:
|
|
59
|
+
annotations: reconcileAnnotation.of(true),
|
|
53
60
|
});
|
|
54
61
|
}
|
|
55
62
|
|
|
56
63
|
// Apply the unreconciled transactions to the document.
|
|
57
|
-
let newHeads = updateAutomerge(this._field, this._handle, transactions, view.state);
|
|
58
|
-
|
|
59
64
|
// NOTE: null and undefined each come from automerge and repo respectively.
|
|
65
|
+
let newHeads = updateAutomerge(this._state, this._handle, transactions, view.state);
|
|
60
66
|
if (newHeads === null || newHeads === undefined) {
|
|
61
|
-
// TODO:
|
|
62
|
-
newHeads =
|
|
67
|
+
// TODO(alexjg): this is the call that's resetting the editor state on click.
|
|
68
|
+
newHeads = A.getHeads(this._handle.docSync()!);
|
|
63
69
|
}
|
|
64
70
|
|
|
65
71
|
// Now get the diff between the updated state of the document and the heads and apply that to the codemirror doc.
|
|
66
|
-
const diff =
|
|
67
|
-
? []
|
|
68
|
-
: automerge.diff(this._handle.docSync()!, oldHeads, newHeads);
|
|
72
|
+
const diff = A.equals(oldHeads, newHeads) ? [] : A.diff(this._handle.docSync()!, oldHeads, newHeads);
|
|
69
73
|
updateCodeMirror(view, selection, path, diff);
|
|
70
74
|
|
|
75
|
+
// Update automerge state.
|
|
71
76
|
view.dispatch({
|
|
72
77
|
effects: updateHeads(newHeads),
|
|
73
|
-
annotations:
|
|
78
|
+
annotations: reconcileAnnotation.of(false),
|
|
74
79
|
});
|
|
75
|
-
|
|
76
|
-
this._inReconcile = false;
|
|
77
|
-
};
|
|
80
|
+
}
|
|
78
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
|
|
7
|
+
import { type EditorState, type StateField, type Transaction, type Text } from '@codemirror/state';
|
|
8
8
|
|
|
9
|
-
import { next as
|
|
9
|
+
import { next as A, type Heads } from '@dxos/automerge/automerge';
|
|
10
10
|
|
|
11
|
-
import { type IDocHandle, type
|
|
11
|
+
import { type IDocHandle, type State } from './defs';
|
|
12
12
|
|
|
13
13
|
export const updateAutomerge = (
|
|
14
|
-
field: StateField<
|
|
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:
|
|
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
|
|
37
|
-
|
|
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 {
|
|
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:
|
|
29
|
+
annotations: reconcileAnnotation.of(false),
|
|
30
30
|
});
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
33
|
|
|
34
34
|
view.dispatch({
|
|
35
35
|
selection,
|
|
36
|
-
annotations:
|
|
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((
|
|
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
|
|
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 }];
|
|
@@ -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
|
|
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
|
-
|
|
71
|
+
awarenessProvider.of(provider),
|
|
73
72
|
ViewPlugin.fromClass(RemoteSelectionsDecorator, {
|
|
74
73
|
decorations: (value) => value.decorations,
|
|
75
74
|
}),
|
|
@@ -92,7 +91,7 @@ export class RemoteSelectionsDecorator implements PluginValue {
|
|
|
92
91
|
|
|
93
92
|
constructor(view: EditorView) {
|
|
94
93
|
this._cursorConverter = view.state.facet(Cursor.converter);
|
|
95
|
-
this._provider = view.state.facet(
|
|
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([])] });
|
|
@@ -251,7 +250,6 @@ class RemoteCaretWidget extends WidgetType {
|
|
|
251
250
|
}
|
|
252
251
|
}
|
|
253
252
|
|
|
254
|
-
// TODO(burdon): Mixed case?
|
|
255
253
|
const styles = EditorView.baseTheme({
|
|
256
254
|
'.cm-collab-selection': {},
|
|
257
255
|
'.cm-collab-selectionLine': {
|
|
@@ -266,38 +264,40 @@ const styles = EditorView.baseTheme({
|
|
|
266
264
|
marginRight: '-1px',
|
|
267
265
|
boxSizing: 'border-box',
|
|
268
266
|
display: 'inline',
|
|
267
|
+
cursor: 'pointer',
|
|
269
268
|
},
|
|
270
269
|
'.cm-collab-selectionCaretDot': {
|
|
271
270
|
borderRadius: '50%',
|
|
272
271
|
position: 'absolute',
|
|
273
|
-
width: '.
|
|
274
|
-
height: '.
|
|
275
|
-
top: '-.
|
|
276
|
-
left: '-.
|
|
272
|
+
width: '.5em',
|
|
273
|
+
height: '.5em',
|
|
274
|
+
top: '-.25em',
|
|
275
|
+
left: '-.25em',
|
|
277
276
|
backgroundColor: 'inherit',
|
|
278
277
|
transition: 'transform .3s ease-in-out',
|
|
279
278
|
boxSizing: 'border-box',
|
|
280
279
|
},
|
|
281
280
|
'.cm-collab-selectionCaret:hover > .cm-collab-selectionCaretDot': {
|
|
282
|
-
transformOrigin: 'bottom center',
|
|
283
281
|
transform: 'scale(0)',
|
|
282
|
+
transformOrigin: 'center',
|
|
284
283
|
},
|
|
285
284
|
'.cm-collab-selectionInfo': {
|
|
286
285
|
position: 'absolute',
|
|
287
|
-
|
|
288
|
-
|
|
286
|
+
transform: 'translate(-50%, 0)',
|
|
287
|
+
top: '-20px',
|
|
288
|
+
left: 0,
|
|
289
289
|
fontSize: '.75em',
|
|
290
|
-
fontFamily: 'serif',
|
|
290
|
+
fontFamily: 'sans-serif',
|
|
291
291
|
fontStyle: 'normal',
|
|
292
292
|
fontWeight: 'normal',
|
|
293
293
|
lineHeight: 'normal',
|
|
294
294
|
userSelect: 'none',
|
|
295
295
|
color: 'white',
|
|
296
|
-
|
|
297
|
-
paddingRight: '2px',
|
|
296
|
+
padding: '2px',
|
|
298
297
|
zIndex: 101,
|
|
299
298
|
transition: 'opacity .3s ease-in-out',
|
|
300
299
|
backgroundColor: 'inherit',
|
|
300
|
+
borderRadius: '2px',
|
|
301
301
|
// These should be separate.
|
|
302
302
|
opacity: 0,
|
|
303
303
|
transitionDelay: '0s',
|
package/src/extensions/basic.ts
CHANGED
|
@@ -3,30 +3,35 @@
|
|
|
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
|
|
12
|
+
import { type ThemeMode } from '@dxos/react-ui';
|
|
13
|
+
|
|
14
|
+
import { type TextEditorProps } from '../components';
|
|
12
15
|
|
|
13
16
|
export type BasicBundleOptions = {
|
|
14
|
-
readonly?: boolean;
|
|
15
17
|
themeMode?: ThemeMode;
|
|
16
|
-
|
|
17
|
-
};
|
|
18
|
+
} & Pick<TextEditorProps, 'placeholder' | 'lineWrapping'>;
|
|
18
19
|
|
|
19
|
-
export const basicBundle = ({
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
export const basicBundle = ({
|
|
21
|
+
themeMode,
|
|
22
|
+
placeholder: _placeholder,
|
|
23
|
+
lineWrapping = true,
|
|
24
|
+
}: BasicBundleOptions): Extension[] => [
|
|
25
|
+
lineWrapping ? EditorView.lineWrapping : [],
|
|
22
26
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
27
|
+
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
28
|
+
bracketMatching(),
|
|
29
|
+
closeBrackets(),
|
|
30
|
+
drawSelection(),
|
|
31
|
+
highlightActiveLine(),
|
|
32
|
+
history(),
|
|
33
|
+
_placeholder ? placeholder(_placeholder) : [],
|
|
29
34
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
// https://github.com/codemirror/theme-one-dark
|
|
36
|
+
themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
|
|
37
|
+
];
|