@dxos/react-ui-editor 0.3.10-main.3cfd481 → 0.3.10-main.3edbcce
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 +351 -131
- 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 +3 -0
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +1 -0
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts +3 -2
- package/dist/types/src/components/TextEditor/extensions/autocomplete.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts +18 -0
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts +10 -0
- package/dist/types/src/components/TextEditor/extensions/demo.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/extensions/experimental.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +2 -0
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts +4 -2
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts +1 -4
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/themes/default.d.ts +3 -0
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +1 -1
- package/dist/types/src/hooks/automerge/PatchSemaphore.d.ts +3 -0
- package/dist/types/src/hooks/automerge/PatchSemaphore.d.ts.map +1 -1
- package/dist/types/src/hooks/automerge/index.d.ts +1 -1
- package/dist/types/src/hooks/automerge/index.d.ts.map +1 -1
- package/dist/types/src/hooks/automerge/plugin.d.ts.map +1 -1
- package/dist/types/src/hooks/automerge/translation/automerge-to-codemirror.d.ts +5 -0
- package/dist/types/src/hooks/automerge/translation/automerge-to-codemirror.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge/translation/codemirror-to-automerge.d.ts +6 -0
- package/dist/types/src/hooks/automerge/translation/codemirror-to-automerge.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge/translation/index.d.ts +3 -0
- package/dist/types/src/hooks/automerge/translation/index.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/testing/replicator.d.ts.map +1 -1
- package/package.json +20 -19
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +41 -8
- package/src/components/TextEditor/TextEditor.tsx +32 -11
- package/src/components/TextEditor/extensions/autocomplete.ts +5 -3
- package/src/components/TextEditor/extensions/comments.ts +190 -0
- package/src/components/TextEditor/extensions/demo.ts +66 -0
- package/src/components/TextEditor/extensions/experimental.tsx +1 -0
- package/src/components/TextEditor/extensions/index.ts +2 -0
- package/src/components/TextEditor/extensions/link.ts +10 -2
- package/src/components/TextEditor/extensions/listener.ts +3 -2
- package/src/components/TextEditor/extensions/markdown/bundle.ts +6 -14
- package/src/components/TextEditor/extensions/markdown/highlight.ts +2 -1
- package/src/components/TextEditor/extensions/tasklist.ts +73 -79
- package/src/components/TextEditor/themes/default.ts +15 -0
- package/src/hooks/automerge/PatchSemaphore.ts +12 -9
- package/src/hooks/automerge/index.ts +1 -1
- package/src/hooks/automerge/plugin.ts +1 -0
- package/src/hooks/automerge/{amToCodemirror.ts → translation/automerge-to-codemirror.ts} +10 -2
- package/src/hooks/automerge/{codeMirrorToAm.ts → translation/codemirror-to-automerge.ts} +7 -4
- package/src/hooks/automerge/translation/index.ts +6 -0
- package/src/hooks/useTextModel.ts +11 -8
- package/src/testing/replicator.ts +5 -5
- package/dist/types/src/hooks/automerge/amToCodemirror.d.ts +0 -6
- package/dist/types/src/hooks/automerge/amToCodemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/codeMirrorToAm.d.ts +0 -7
- package/dist/types/src/hooks/automerge/codeMirrorToAm.d.ts.map +0 -1
|
@@ -2,112 +2,106 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { syntaxTree } from '@codemirror/language';
|
|
6
5
|
import {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
type
|
|
13
|
-
|
|
14
|
-
|
|
6
|
+
EditorView,
|
|
7
|
+
Decoration,
|
|
8
|
+
WidgetType,
|
|
9
|
+
MatchDecorator,
|
|
10
|
+
ViewPlugin,
|
|
11
|
+
type DecorationSet,
|
|
12
|
+
type ViewUpdate,
|
|
13
|
+
} from '@codemirror/view';
|
|
15
14
|
|
|
16
15
|
class CheckboxWidget extends WidgetType {
|
|
17
|
-
constructor(
|
|
16
|
+
constructor(
|
|
17
|
+
private readonly _pos: number,
|
|
18
|
+
private _checked: boolean,
|
|
19
|
+
private readonly _indent: number,
|
|
20
|
+
private readonly _onCheck: (check: boolean) => void,
|
|
21
|
+
) {
|
|
18
22
|
super();
|
|
19
23
|
}
|
|
20
24
|
|
|
21
25
|
override eq(other: CheckboxWidget) {
|
|
22
|
-
|
|
23
|
-
// TODO(burdon): Is this efficient? Check life-cycle.
|
|
24
|
-
return this._pos === other._pos && this._checked === other._checked;
|
|
26
|
+
return this._pos === other._pos && this._checked === other._checked && this._indent === other._indent;
|
|
25
27
|
}
|
|
26
28
|
|
|
27
29
|
toDOM(view: EditorView) {
|
|
28
|
-
// console.log('toDom', this._pos);
|
|
29
30
|
const wrap = document.createElement('span');
|
|
30
|
-
wrap.setAttribute('aria-hidden', 'true');
|
|
31
31
|
wrap.className = 'cm-task-item';
|
|
32
|
+
wrap.setAttribute('aria-hidden', 'true');
|
|
33
|
+
wrap.style.setProperty('margin-left', this._indent * 24 + 'px');
|
|
32
34
|
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
this.
|
|
38
|
-
view.dispatch({
|
|
39
|
-
changes: {
|
|
40
|
-
from: this._pos + 1,
|
|
41
|
-
to: this._pos + 2,
|
|
42
|
-
insert: this._checked ? 'x' : ' ',
|
|
43
|
-
},
|
|
44
|
-
// TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
|
|
45
|
-
selection: {
|
|
46
|
-
anchor: this._pos + 4,
|
|
47
|
-
// anchor: this._getCursor(),
|
|
48
|
-
},
|
|
49
|
-
});
|
|
35
|
+
const input = wrap.appendChild(document.createElement('input'));
|
|
36
|
+
input.type = 'checkbox';
|
|
37
|
+
input.checked = this._checked;
|
|
38
|
+
input.onchange = (event: Event) => {
|
|
39
|
+
this._onCheck((event.target as any).checked);
|
|
50
40
|
return true;
|
|
51
41
|
};
|
|
52
42
|
|
|
53
43
|
return wrap;
|
|
54
44
|
}
|
|
55
45
|
|
|
56
|
-
// TODO(burdon): Remove listener?
|
|
57
|
-
// override destroy() {
|
|
58
|
-
// console.log('destroy', this._pos);
|
|
59
|
-
// }
|
|
60
|
-
|
|
61
46
|
override ignoreEvent() {
|
|
62
47
|
return false;
|
|
63
48
|
}
|
|
64
49
|
}
|
|
65
50
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
51
|
+
// TODO(burdon): Reconcile with theme.
|
|
52
|
+
const styles = EditorView.baseTheme({
|
|
53
|
+
'& .cm-task-item': {
|
|
54
|
+
paddingLeft: '4px',
|
|
55
|
+
paddingRight: '8px',
|
|
56
|
+
},
|
|
57
|
+
});
|
|
69
58
|
|
|
70
|
-
export const
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
59
|
+
export const tasklist = () => {
|
|
60
|
+
// TODO(burdon): Matcher isn't as precise as syntax tree.
|
|
61
|
+
// Allows for indents to be greater than AST would allow.
|
|
62
|
+
const taskMatcher = new MatchDecorator({
|
|
63
|
+
regexp: /^(\s*)- \[([ xX])\]\s/g,
|
|
64
|
+
decoration: (match, view, pos) => {
|
|
65
|
+
const indent = Math.floor(match[1].length / 2);
|
|
66
|
+
const checked = match[2] === 'x' || match[2] === 'X';
|
|
67
|
+
return Decoration.replace({
|
|
68
|
+
widget: new CheckboxWidget(pos, checked, indent, (checked) => {
|
|
69
|
+
const idx = pos + match[0].indexOf('[') + 1;
|
|
70
|
+
view.dispatch({
|
|
71
|
+
changes: {
|
|
72
|
+
from: idx,
|
|
73
|
+
to: idx + 1,
|
|
74
|
+
insert: checked ? 'x' : ' ',
|
|
75
|
+
},
|
|
76
|
+
// TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
|
|
77
|
+
selection: {
|
|
78
|
+
anchor: idx + 3,
|
|
79
|
+
},
|
|
80
|
+
});
|
|
81
|
+
}),
|
|
82
|
+
});
|
|
83
|
+
},
|
|
74
84
|
});
|
|
75
85
|
|
|
76
|
-
const
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
builder.add(
|
|
83
|
-
node.from,
|
|
84
|
-
node.to,
|
|
85
|
-
Decoration.replace({
|
|
86
|
-
widget: new CheckboxWidget(node.from, () => lastPosition, isChecked(state, node.from)),
|
|
87
|
-
}),
|
|
88
|
-
);
|
|
89
|
-
}
|
|
90
|
-
},
|
|
91
|
-
});
|
|
86
|
+
const tasks = ViewPlugin.fromClass(
|
|
87
|
+
class {
|
|
88
|
+
tasks: DecorationSet;
|
|
89
|
+
constructor(view: EditorView) {
|
|
90
|
+
this.tasks = taskMatcher.createDeco(view);
|
|
91
|
+
}
|
|
92
92
|
|
|
93
|
-
|
|
94
|
-
|
|
93
|
+
update(update: ViewUpdate) {
|
|
94
|
+
this.tasks = taskMatcher.updateDeco(update, this.tasks);
|
|
95
|
+
}
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
decorations: (instance) => instance.tasks,
|
|
99
|
+
provide: (plugin) =>
|
|
100
|
+
EditorView.atomicRanges.of((view) => {
|
|
101
|
+
return view.plugin(plugin)?.tasks || Decoration.none;
|
|
102
|
+
}),
|
|
103
|
+
},
|
|
104
|
+
);
|
|
95
105
|
|
|
96
|
-
return [
|
|
97
|
-
listener,
|
|
98
|
-
StateField.define<RangeSet<any>>({
|
|
99
|
-
create: (state) => checkbox(state),
|
|
100
|
-
update: (_: RangeSet<any>, tr: Transaction) => checkbox(tr.state),
|
|
101
|
-
provide: (field) => EditorView.decorations.from(field),
|
|
102
|
-
}),
|
|
103
|
-
];
|
|
106
|
+
return [tasks, styles];
|
|
104
107
|
};
|
|
105
|
-
|
|
106
|
-
// TODO(burdon): Reconcile with theme.
|
|
107
|
-
export const styles = EditorView.baseTheme({
|
|
108
|
-
'& .cm-task-item': {
|
|
109
|
-
padding: '0 4px',
|
|
110
|
-
},
|
|
111
|
-
});
|
|
112
|
-
|
|
113
|
-
export const tasklist = () => [statefield(), styles];
|
|
@@ -159,6 +159,18 @@ export const textTheme: {
|
|
|
159
159
|
'& .cm-scroller': {
|
|
160
160
|
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
161
161
|
},
|
|
162
|
+
'& .cm-placeholder': {
|
|
163
|
+
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
164
|
+
},
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
export const markdownTheme: {
|
|
168
|
+
[selector: string]: StyleSpec;
|
|
169
|
+
} = {
|
|
170
|
+
// NOTE: Must leave base font family as is (i.e., monospace) due to fenced code blocks.
|
|
171
|
+
'& .cm-placeholder': {
|
|
172
|
+
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
173
|
+
},
|
|
162
174
|
};
|
|
163
175
|
|
|
164
176
|
export const codeTheme: {
|
|
@@ -167,4 +179,7 @@ export const codeTheme: {
|
|
|
167
179
|
'& .cm-scroller': {
|
|
168
180
|
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
169
181
|
},
|
|
182
|
+
'& .cm-placeholder': {
|
|
183
|
+
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
184
|
+
},
|
|
170
185
|
};
|
|
@@ -2,20 +2,24 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// TODO(burdon): Additional copyright?
|
|
6
|
+
|
|
5
7
|
import { type EditorView } from '@codemirror/view';
|
|
6
8
|
|
|
7
9
|
import { next as automerge } from '@dxos/automerge/automerge';
|
|
8
10
|
|
|
9
|
-
import amToCodemirror from './amToCodemirror';
|
|
10
|
-
import codeMirrorToAm from './codeMirrorToAm';
|
|
11
11
|
import { type IDocHandle } from './handle';
|
|
12
12
|
import { type Field, isReconcileTx, getPath, reconcileAnnotationType, updateHeads, getLastHeads } from './plugin';
|
|
13
|
+
import { automergeToCodemirror, codemirrorToAutomerge } from './translation';
|
|
13
14
|
|
|
14
15
|
type Doc<T> = automerge.Doc<T>;
|
|
15
16
|
type Heads = automerge.Heads;
|
|
16
17
|
|
|
17
18
|
type ChangeFn = (atHeads: Heads, change: (doc: Doc<unknown>) => void) => Heads | undefined;
|
|
18
19
|
|
|
20
|
+
/**
|
|
21
|
+
* TODO(burdon): Comment.
|
|
22
|
+
*/
|
|
19
23
|
export class PatchSemaphore {
|
|
20
24
|
_field!: Field;
|
|
21
25
|
_inReconcile = false;
|
|
@@ -39,7 +43,7 @@ export class PatchSemaphore {
|
|
|
39
43
|
|
|
40
44
|
const transactions = view.state.field(this._field).unreconciledTransactions.filter((tx) => !isReconcileTx(tx));
|
|
41
45
|
|
|
42
|
-
// First undo all the unreconciled transactions
|
|
46
|
+
// First undo all the unreconciled transactions.
|
|
43
47
|
const toInvert = transactions.slice().reverse();
|
|
44
48
|
for (const tx of toInvert) {
|
|
45
49
|
const inverted = tx.changes.invert(tx.startState.doc);
|
|
@@ -50,19 +54,18 @@ export class PatchSemaphore {
|
|
|
50
54
|
});
|
|
51
55
|
}
|
|
52
56
|
|
|
53
|
-
//
|
|
54
|
-
let newHeads =
|
|
57
|
+
// Apply the unreconciled transactions to the document.
|
|
58
|
+
let newHeads = codemirrorToAutomerge(this._field, handle, transactions, view.state);
|
|
55
59
|
|
|
56
|
-
// NOTE: null and undefined each come from automerge and repo respectively
|
|
60
|
+
// NOTE: null and undefined each come from automerge and repo respectively.
|
|
57
61
|
if (newHeads === null || newHeads === undefined) {
|
|
58
62
|
// TODO: @alexjg this is the call that's resetting the editor state on click
|
|
59
63
|
newHeads = automerge.getHeads(handle.docSync()!);
|
|
60
64
|
}
|
|
61
65
|
|
|
62
|
-
//
|
|
63
|
-
// and apply that to the codemirror doc
|
|
66
|
+
// Now get the diff between the updated state of the document and the heads and apply that to the codemirror doc.
|
|
64
67
|
const diff = automerge.equals(oldHeads, newHeads) ? [] : automerge.diff(handle.docSync()!, oldHeads, newHeads);
|
|
65
|
-
|
|
68
|
+
automergeToCodemirror(view, selection, path, diff);
|
|
66
69
|
|
|
67
70
|
view.dispatch({
|
|
68
71
|
effects: updateHeads(newHeads),
|
|
@@ -2,6 +2,8 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// TODO(burdon): Additional copyright?
|
|
6
|
+
|
|
5
7
|
import { ChangeSet, type ChangeSpec, type EditorSelection, type EditorState } from '@codemirror/state';
|
|
6
8
|
import { type EditorView } from '@codemirror/view';
|
|
7
9
|
|
|
@@ -14,9 +16,14 @@ import {
|
|
|
14
16
|
type SpliceTextPatch,
|
|
15
17
|
} from '@dxos/automerge/automerge';
|
|
16
18
|
|
|
17
|
-
import { reconcileAnnotationType } from '
|
|
19
|
+
import { reconcileAnnotationType } from '../plugin';
|
|
18
20
|
|
|
19
|
-
export
|
|
21
|
+
export const automergeToCodemirror = (
|
|
22
|
+
view: EditorView,
|
|
23
|
+
selection: EditorSelection,
|
|
24
|
+
target: Prop[],
|
|
25
|
+
patches: Patch[],
|
|
26
|
+
) => {
|
|
20
27
|
for (const patch of patches) {
|
|
21
28
|
const changeSpec = handlePatch(patch, target, view.state);
|
|
22
29
|
if (changeSpec != null) {
|
|
@@ -28,6 +35,7 @@ export default (view: EditorView, selection: EditorSelection, target: Prop[], pa
|
|
|
28
35
|
});
|
|
29
36
|
}
|
|
30
37
|
}
|
|
38
|
+
|
|
31
39
|
view.dispatch({
|
|
32
40
|
selection,
|
|
33
41
|
annotations: reconcileAnnotationType.of({}),
|
|
@@ -2,14 +2,16 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
// TODO(burdon): Additional copyright?
|
|
6
|
+
|
|
5
7
|
import { type EditorState, type Text, type Transaction } from '@codemirror/state';
|
|
6
8
|
|
|
7
9
|
import { next as am, type Heads } from '@dxos/automerge/automerge';
|
|
8
10
|
|
|
9
|
-
import { type IDocHandle } from '
|
|
10
|
-
import { type Field } from '
|
|
11
|
+
import { type IDocHandle } from '../handle';
|
|
12
|
+
import { type Field } from '../plugin';
|
|
11
13
|
|
|
12
|
-
export
|
|
14
|
+
export const codemirrorToAutomerge = (
|
|
13
15
|
field: Field,
|
|
14
16
|
handle: IDocHandle,
|
|
15
17
|
transactions: Transaction[],
|
|
@@ -18,7 +20,7 @@ export default (
|
|
|
18
20
|
const { lastHeads, path } = state.field(field);
|
|
19
21
|
|
|
20
22
|
// We don't want to call `automerge.updateAt` if there are no changes.
|
|
21
|
-
// Otherwise later on `automerge.diff` will return empty patches that result in a no-op but still mess up the selection.
|
|
23
|
+
// Otherwise, later on `automerge.diff` will return empty patches that result in a no-op but still mess up the selection.
|
|
22
24
|
let hasChanges = false;
|
|
23
25
|
for (const tr of transactions) {
|
|
24
26
|
tr.changes.iterChanges(() => {
|
|
@@ -37,5 +39,6 @@ export default (
|
|
|
37
39
|
});
|
|
38
40
|
}
|
|
39
41
|
});
|
|
42
|
+
|
|
40
43
|
return newHeads ?? undefined;
|
|
41
44
|
};
|
|
@@ -29,6 +29,7 @@ type Awareness = awarenessProtocol.Awareness;
|
|
|
29
29
|
// TODO(wittjosiah): Factor out to common package? @dxos/react-client?
|
|
30
30
|
export type EditorModel = {
|
|
31
31
|
id: string;
|
|
32
|
+
// TODO(burdon): Remove.
|
|
32
33
|
content: string | YText | YXmlFragment | DocAccessor;
|
|
33
34
|
text: () => string;
|
|
34
35
|
extension?: Extension;
|
|
@@ -57,28 +58,30 @@ export const useTextModel = ({ identity, space, text }: UseTextModelOptions): Ed
|
|
|
57
58
|
};
|
|
58
59
|
|
|
59
60
|
const createModel = (options: UseTextModelOptions) => {
|
|
60
|
-
const {
|
|
61
|
-
|
|
61
|
+
const { text } = options;
|
|
62
62
|
if (isActualAutomergeObject(text)) {
|
|
63
63
|
return createAutomergeModel(options);
|
|
64
64
|
} else {
|
|
65
|
-
if (!
|
|
65
|
+
if (!text?.doc) {
|
|
66
66
|
return undefined;
|
|
67
67
|
}
|
|
68
|
+
|
|
68
69
|
return createYjsModel(options);
|
|
69
70
|
}
|
|
70
71
|
};
|
|
71
72
|
|
|
72
73
|
const createYjsModel = ({ identity, space, text }: UseTextModelOptions): EditorModel => {
|
|
73
|
-
invariant(
|
|
74
|
-
const provider =
|
|
74
|
+
invariant(text?.doc && text?.content);
|
|
75
|
+
const provider = space
|
|
76
|
+
? new SpaceAwarenessProvider({ space, doc: text.doc, channel: `yjs.awareness.${text.id}` })
|
|
77
|
+
: undefined;
|
|
75
78
|
|
|
76
79
|
return {
|
|
77
80
|
id: text.doc.guid,
|
|
78
81
|
content: text.content,
|
|
79
82
|
text: () => text.content!.toString(),
|
|
80
|
-
extension: yCollab(text.content as YText, provider
|
|
81
|
-
awareness: provider
|
|
83
|
+
extension: yCollab(text.content as YText, provider?.awareness),
|
|
84
|
+
awareness: provider?.awareness,
|
|
82
85
|
peer: identity
|
|
83
86
|
? {
|
|
84
87
|
id: identity.identityKey.toHex(),
|
|
@@ -88,7 +91,7 @@ const createYjsModel = ({ identity, space, text }: UseTextModelOptions): EditorM
|
|
|
88
91
|
};
|
|
89
92
|
};
|
|
90
93
|
|
|
91
|
-
const createAutomergeModel = ({ identity,
|
|
94
|
+
const createAutomergeModel = ({ identity, text }: UseTextModelOptions): EditorModel => {
|
|
92
95
|
const obj = text as any as AutomergeTextCompat;
|
|
93
96
|
const doc = getRawDoc(obj, [obj.field]);
|
|
94
97
|
|
|
@@ -163,16 +163,17 @@ export class Replicator {
|
|
|
163
163
|
colorLight: cursorColor.light,
|
|
164
164
|
});
|
|
165
165
|
|
|
166
|
+
const field = 'content';
|
|
167
|
+
const content = this._kind === TextKind.PLAIN ? doc.getText(field) : doc.getXmlFragment(field);
|
|
166
168
|
const model: EditorModel = {
|
|
167
169
|
id: doc.guid,
|
|
168
|
-
|
|
169
|
-
|
|
170
|
+
text: () => content.toString(),
|
|
171
|
+
content,
|
|
170
172
|
awareness: provider.awareness,
|
|
171
173
|
peer: { id },
|
|
172
174
|
};
|
|
173
175
|
|
|
174
176
|
this._peers.push(model);
|
|
175
|
-
|
|
176
177
|
return model;
|
|
177
178
|
};
|
|
178
179
|
}
|
|
@@ -184,6 +185,5 @@ export type UseYjsModelOptions = {
|
|
|
184
185
|
};
|
|
185
186
|
|
|
186
187
|
export const useYjsModel = ({ replicator, id, doc }: UseYjsModelOptions): EditorModel => {
|
|
187
|
-
|
|
188
|
-
return peer;
|
|
188
|
+
return useMemo(() => replicator.createPeer(id, doc), [doc]);
|
|
189
189
|
};
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type EditorSelection } from '@codemirror/state';
|
|
2
|
-
import { type EditorView } from '@codemirror/view';
|
|
3
|
-
import { type Patch, type Prop } from '@dxos/automerge/automerge';
|
|
4
|
-
declare const _default: (view: EditorView, selection: EditorSelection, target: Prop[], patches: Patch[]) => void;
|
|
5
|
-
export default _default;
|
|
6
|
-
//# sourceMappingURL=amToCodemirror.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"amToCodemirror.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/automerge/amToCodemirror.ts"],"names":[],"mappings":"AAIA,OAAO,EAA8B,KAAK,eAAe,EAAoB,MAAM,mBAAmB,CAAC;AACvG,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,EAGL,KAAK,KAAK,EACV,KAAK,IAAI,EAGV,MAAM,2BAA2B,CAAC;+BAIb,UAAU,aAAa,eAAe,UAAU,IAAI,EAAE,WAAW,KAAK,EAAE;AAA9F,wBAgBE"}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
import { type EditorState, type Transaction } from '@codemirror/state';
|
|
2
|
-
import { type Heads } from '@dxos/automerge/automerge';
|
|
3
|
-
import { type IDocHandle } from './handle';
|
|
4
|
-
import { type Field } from './plugin';
|
|
5
|
-
declare const _default: (field: Field, handle: IDocHandle, transactions: Transaction[], state: EditorState) => Heads | undefined;
|
|
6
|
-
export default _default;
|
|
7
|
-
//# sourceMappingURL=codeMirrorToAm.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"codeMirrorToAm.d.ts","sourceRoot":"","sources":["../../../../../src/hooks/automerge/codeMirrorToAm.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,WAAW,EAAa,KAAK,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAElF,OAAO,EAAc,KAAK,KAAK,EAAE,MAAM,2BAA2B,CAAC;AAEnE,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,KAAK,KAAK,EAAE,MAAM,UAAU,CAAC;+CAI5B,UAAU,gBACJ,WAAW,EAAE,SACpB,WAAW,KACjB,KAAK,GAAG,SAAS;AALpB,wBA6BE"}
|