@dxos/react-ui-editor 0.3.11-main.668f0ff → 0.3.11-main.674a7f9
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 +2031 -1641
- 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 +14 -14
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +20 -17
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +6 -3
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- package/dist/types/src/{hooks/automerge → components/TextEditor}/automerge.stories.d.ts +6 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/comments.stories.d.ts +26 -0
- package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +1 -0
- package/dist/types/src/components/TextEditor/index.d.ts +0 -2
- package/dist/types/src/components/TextEditor/index.d.ts.map +1 -1
- package/dist/types/src/extensions/autocomplete.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts +9 -0
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts +5 -0
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/defs.d.ts +24 -0
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/index.d.ts +3 -0
- package/dist/types/src/extensions/automerge/index.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/semaphore.d.ts +14 -0
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts +5 -0
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/update-codemirror.d.ts.map +1 -0
- package/dist/types/src/extensions/awareness.d.ts +46 -0
- package/dist/types/src/extensions/awareness.d.ts.map +1 -0
- package/dist/types/src/extensions/basic.d.ts +8 -0
- package/dist/types/src/extensions/basic.d.ts.map +1 -0
- package/dist/types/src/extensions/blast.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/comments.d.ts +33 -18
- package/dist/types/src/extensions/comments.d.ts.map +1 -0
- package/dist/types/src/extensions/cursor.d.ts +25 -0
- package/dist/types/src/extensions/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +13 -0
- package/dist/types/src/extensions/index.d.ts.map +1 -0
- package/dist/types/src/extensions/listener.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/bundle.d.ts +2 -5
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/code.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 -0
- 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 +10 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -0
- package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/link.d.ts +1 -0
- 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.map +1 -0
- package/dist/types/src/extensions/mention.d.ts.map +1 -0
- package/dist/types/src/extensions/outliner.d.ts +4 -0
- package/dist/types/src/extensions/outliner.d.ts.map +1 -0
- package/dist/types/src/extensions/typewriter.d.ts.map +1 -0
- package/dist/types/src/hooks/awareness-provider.d.ts +31 -0
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -0
- 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 -1
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- 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 -31
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +5 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/styles/cursors.d.ts.map +1 -0
- package/dist/types/src/styles/index.d.ts +1 -0
- package/dist/types/src/styles/index.d.ts.map +1 -1
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/styles/tokens.d.ts +1 -0
- package/dist/types/src/styles/tokens.d.ts.map +1 -1
- package/dist/types/src/{components/TextEditor/themes → themes}/default.d.ts +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -0
- package/dist/types/src/themes/index.d.ts.map +1 -0
- package/dist/types/src/util.d.ts +7 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +33 -34
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +88 -91
- package/src/components/TextEditor/TextEditor.stories.tsx +13 -34
- package/src/components/TextEditor/TextEditor.tsx +123 -94
- package/src/{hooks/automerge → components/TextEditor}/automerge.stories.tsx +66 -6
- package/src/components/TextEditor/comments.stories.tsx +357 -0
- package/src/components/TextEditor/index.ts +0 -3
- package/src/{components/TextEditor/extensions → extensions}/autocomplete.ts +23 -19
- package/src/extensions/automerge/automerge.ts +88 -0
- package/src/extensions/automerge/cursor.ts +52 -0
- package/src/extensions/automerge/defs.ts +41 -0
- package/src/extensions/automerge/index.ts +6 -0
- package/src/{hooks → extensions}/automerge/semaphore.ts +34 -29
- package/src/{hooks → extensions}/automerge/update-automerge.ts +5 -6
- package/src/{hooks → extensions}/automerge/update-codemirror.ts +13 -5
- package/src/extensions/awareness.ts +310 -0
- package/src/extensions/basic.ts +37 -0
- package/src/extensions/comments.ts +428 -0
- package/src/extensions/cursor.ts +50 -0
- package/src/{components/TextEditor/extensions → extensions}/index.ts +4 -8
- package/src/extensions/listener.ts +35 -0
- package/src/{components/TextEditor/extensions → extensions}/markdown/bundle.ts +18 -24
- package/src/{components/TextEditor/extensions → extensions/markdown}/code.ts +28 -23
- package/src/extensions/markdown/heading.ts +60 -0
- package/src/{components/TextEditor/extensions → extensions}/markdown/highlight.ts +4 -13
- package/src/extensions/markdown/hr.ts +72 -0
- package/src/extensions/markdown/image.ts +87 -0
- package/src/extensions/markdown/index.ts +13 -0
- package/src/{components/TextEditor/extensions → extensions/markdown}/link.ts +116 -62
- package/src/{components/TextEditor/extensions → extensions/markdown}/table.ts +10 -4
- package/src/extensions/markdown/tasklist.ts +111 -0
- package/src/{components/TextEditor/extensions → extensions}/mention.ts +9 -2
- package/src/extensions/outliner.ts +12 -0
- package/src/{components/TextEditor/extensions → extensions}/typewriter.ts +1 -1
- package/src/hooks/awareness-provider.ts +124 -0
- package/src/hooks/defs.ts +42 -0
- package/src/hooks/index.ts +4 -1
- package/src/hooks/useTextEditor.ts +29 -0
- package/src/hooks/useTextModel.ts +30 -115
- package/src/index.ts +5 -0
- package/src/styles/index.ts +1 -0
- package/src/styles/markdown.ts +0 -2
- package/src/styles/tokens.ts +3 -0
- package/src/{components/TextEditor/themes → themes}/default.ts +52 -79
- package/src/util.ts +41 -0
- 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/extensions/autocomplete.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts +0 -9
- package/dist/types/src/components/TextEditor/extensions/basic.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/blast.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/code.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/comments.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/hr.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/image.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/index.d.ts +0 -17
- package/dist/types/src/components/TextEditor/extensions/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/link.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/listener.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/bundle.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/highlight.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/markdown/index.d.ts +0 -3
- package/dist/types/src/components/TextEditor/extensions/markdown/index.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/mention.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/mermaid.d.ts +0 -3
- package/dist/types/src/components/TextEditor/extensions/mermaid.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/table.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tasklist.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts +0 -12
- package/dist/types/src/components/TextEditor/extensions/tooltip.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/typewriter.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/extensions/util.d.ts +0 -5
- package/dist/types/src/components/TextEditor/extensions/util.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/default.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/themes/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/automerge.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/handle.d.ts +0 -9
- package/dist/types/src/hooks/automerge/handle.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/index.d.ts +0 -3
- package/dist/types/src/hooks/automerge/index.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/plugin.d.ts +0 -26
- package/dist/types/src/hooks/automerge/plugin.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/semaphore.d.ts +0 -19
- package/dist/types/src/hooks/automerge/semaphore.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-automerge.d.ts +0 -6
- package/dist/types/src/hooks/automerge/update-automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge/update-codemirror.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/cursors.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/index.d.ts +0 -3
- package/dist/types/src/hooks/yjs/index.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/space-provider.d.ts +0 -27
- package/dist/types/src/hooks/yjs/space-provider.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts +0 -12
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.test.d.ts +0 -2
- package/dist/types/src/hooks/yjs/yjs.test.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 -114
- package/src/components/TextEditor/extensions/basic.ts +0 -32
- package/src/components/TextEditor/extensions/comments.ts +0 -389
- package/src/components/TextEditor/extensions/hr.ts +0 -74
- package/src/components/TextEditor/extensions/image.ts +0 -69
- package/src/components/TextEditor/extensions/listener.ts +0 -39
- package/src/components/TextEditor/extensions/markdown/index.ts +0 -6
- package/src/components/TextEditor/extensions/mermaid.ts +0 -11
- package/src/components/TextEditor/extensions/tasklist.ts +0 -121
- package/src/components/TextEditor/extensions/tooltip.ts +0 -61
- package/src/components/TextEditor/extensions/util.ts +0 -18
- package/src/hooks/automerge/handle.ts +0 -14
- package/src/hooks/automerge/index.ts +0 -6
- package/src/hooks/automerge/plugin.ts +0 -134
- package/src/hooks/yjs/index.ts +0 -6
- package/src/hooks/yjs/space-provider.ts +0 -126
- package/src/hooks/yjs/yjs.stories.tsx +0 -56
- package/src/hooks/yjs/yjs.test.ts +0 -59
- 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 -189
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/autocomplete.d.ts +0 -0
- /package/dist/types/src/{hooks → extensions}/automerge/update-codemirror.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/blast.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/listener.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/code.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/markdown/highlight.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/hr.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/image.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/table.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions/markdown}/tasklist.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/mention.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/extensions → extensions}/typewriter.d.ts +0 -0
- /package/dist/types/src/{hooks/yjs → styles}/cursors.d.ts +0 -0
- /package/dist/types/src/{components/TextEditor/themes → themes}/index.d.ts +0 -0
- /package/src/{components/TextEditor/extensions → extensions}/blast.ts +0 -0
- /package/src/{hooks/yjs → styles}/cursors.ts +0 -0
- /package/src/{components/TextEditor/themes → themes}/index.ts +0 -0
|
@@ -1,74 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
Decoration,
|
|
7
|
-
type DecorationSet,
|
|
8
|
-
EditorView,
|
|
9
|
-
MatchDecorator,
|
|
10
|
-
ViewPlugin,
|
|
11
|
-
type ViewUpdate,
|
|
12
|
-
WidgetType,
|
|
13
|
-
} from '@codemirror/view';
|
|
14
|
-
import get from 'lodash.get';
|
|
15
|
-
|
|
16
|
-
import { tokens } from '../../../styles';
|
|
17
|
-
|
|
18
|
-
// TODO(burdon): Reconcile with theme.
|
|
19
|
-
const styles = EditorView.baseTheme({
|
|
20
|
-
'& .cm-hr': {
|
|
21
|
-
// TODO(burdon): ???
|
|
22
|
-
// Note that block-level decorations should not have vertical margins,
|
|
23
|
-
borderBottom: `1px solid ${get(tokens, 'extend.colors.neutral.200')}`,
|
|
24
|
-
},
|
|
25
|
-
});
|
|
26
|
-
|
|
27
|
-
class HorizontalRuleWidget extends WidgetType {
|
|
28
|
-
constructor(readonly _pos: number) {
|
|
29
|
-
super();
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
override eq(other: WidgetType) {
|
|
33
|
-
return this._pos === (other as any as HorizontalRuleWidget)._pos;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
toDOM(view: EditorView) {
|
|
37
|
-
// TODO(burdon): Create <hr> element? Does this clash with markdown parser?
|
|
38
|
-
const el = document.createElement('div');
|
|
39
|
-
el.className = 'cm-hr';
|
|
40
|
-
return el;
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
const placeholderMatcher = new MatchDecorator({
|
|
45
|
-
regexp: /^---$/g,
|
|
46
|
-
decoration: (match, view, pos) =>
|
|
47
|
-
Decoration.replace({
|
|
48
|
-
widget: new HorizontalRuleWidget(pos),
|
|
49
|
-
}),
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
export const hr = () => [
|
|
53
|
-
styles,
|
|
54
|
-
ViewPlugin.fromClass(
|
|
55
|
-
class {
|
|
56
|
-
rules: DecorationSet;
|
|
57
|
-
constructor(view: EditorView) {
|
|
58
|
-
this.rules = placeholderMatcher.createDeco(view);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
update(update: ViewUpdate) {
|
|
62
|
-
this.rules = placeholderMatcher.updateDeco(update, this.rules);
|
|
63
|
-
}
|
|
64
|
-
},
|
|
65
|
-
{
|
|
66
|
-
decorations: (instance) => instance.rules,
|
|
67
|
-
// TODO(burdon): Is this really atomic (cursor can move into ---).
|
|
68
|
-
provide: (plugin) =>
|
|
69
|
-
EditorView.atomicRanges.of((view) => {
|
|
70
|
-
return view.plugin(plugin)?.rules || Decoration.none;
|
|
71
|
-
}),
|
|
72
|
-
},
|
|
73
|
-
),
|
|
74
|
-
];
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { syntaxTree } from '@codemirror/language';
|
|
6
|
-
import {
|
|
7
|
-
type EditorState,
|
|
8
|
-
type Extension,
|
|
9
|
-
type RangeSet,
|
|
10
|
-
RangeSetBuilder,
|
|
11
|
-
StateField,
|
|
12
|
-
type Transaction,
|
|
13
|
-
} from '@codemirror/state';
|
|
14
|
-
import { Decoration, EditorView, WidgetType } from '@codemirror/view';
|
|
15
|
-
|
|
16
|
-
export type ImageOptions = {};
|
|
17
|
-
|
|
18
|
-
export const image = (options: ImageOptions = {}): Extension => {
|
|
19
|
-
return StateField.define<RangeSet<any>>({
|
|
20
|
-
create: (state) => update(state, options),
|
|
21
|
-
update: (_: RangeSet<any>, tr: Transaction) => update(tr.state, options),
|
|
22
|
-
provide: (field) => EditorView.decorations.from(field),
|
|
23
|
-
});
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
const update = (state: EditorState, options: ImageOptions) => {
|
|
27
|
-
const builder = new RangeSetBuilder();
|
|
28
|
-
const cursor = state.selection.main.head;
|
|
29
|
-
|
|
30
|
-
syntaxTree(state).iterate({
|
|
31
|
-
enter: (node) => {
|
|
32
|
-
if (node.name === 'Image') {
|
|
33
|
-
const urlNode = node.node.getChild('URL');
|
|
34
|
-
if (urlNode) {
|
|
35
|
-
const hide = state.readOnly || cursor < node.from || cursor > node.to;
|
|
36
|
-
const url = state.sliceDoc(urlNode.from, urlNode.to);
|
|
37
|
-
builder.add(
|
|
38
|
-
hide ? node.from : node.to,
|
|
39
|
-
node.to,
|
|
40
|
-
Decoration.replace({
|
|
41
|
-
block: true, // Prevent cursor from entering.
|
|
42
|
-
widget: new ImageWidget(url),
|
|
43
|
-
}),
|
|
44
|
-
);
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
},
|
|
48
|
-
});
|
|
49
|
-
|
|
50
|
-
return builder.finish();
|
|
51
|
-
};
|
|
52
|
-
|
|
53
|
-
class ImageWidget extends WidgetType {
|
|
54
|
-
constructor(readonly _url: string) {
|
|
55
|
-
super();
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
// TODO(burdon): Does this need to be unique for each position?
|
|
59
|
-
override eq(other: WidgetType) {
|
|
60
|
-
return this._url === (other as any as ImageWidget)._url;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
toDOM(view: EditorView) {
|
|
64
|
-
const img = document.createElement('img');
|
|
65
|
-
img.setAttribute('src', this._url);
|
|
66
|
-
img.setAttribute('class', 'cm-image');
|
|
67
|
-
return img;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Extension, StateField } from '@codemirror/state';
|
|
6
|
-
import { EditorView } from '@codemirror/view';
|
|
7
|
-
|
|
8
|
-
import { nonNullable } from '@dxos/util';
|
|
9
|
-
|
|
10
|
-
export type ListenerOptions = {
|
|
11
|
-
onFocus?: (focused: boolean) => void;
|
|
12
|
-
onChange?: (text: string) => void;
|
|
13
|
-
};
|
|
14
|
-
|
|
15
|
-
/**
|
|
16
|
-
* Event listener.
|
|
17
|
-
*/
|
|
18
|
-
export const listener = ({ onFocus, onChange }: ListenerOptions): Extension =>
|
|
19
|
-
[
|
|
20
|
-
onFocus
|
|
21
|
-
? EditorView.focusChangeEffect.of((view, focused) => {
|
|
22
|
-
onFocus(focused);
|
|
23
|
-
return null;
|
|
24
|
-
})
|
|
25
|
-
: undefined,
|
|
26
|
-
|
|
27
|
-
onChange
|
|
28
|
-
? StateField.define({
|
|
29
|
-
create: () => null,
|
|
30
|
-
update: (_value, transaction) => {
|
|
31
|
-
if (transaction.docChanged) {
|
|
32
|
-
onChange(transaction.newDoc.toString());
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return null;
|
|
36
|
-
},
|
|
37
|
-
})
|
|
38
|
-
: undefined,
|
|
39
|
-
].filter(nonNullable);
|
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Extension } from '@codemirror/state';
|
|
6
|
-
|
|
7
|
-
// TODO(burdon): How will this interact with the code extension?
|
|
8
|
-
// TODO(burdon): Move to mermaid-plugin (which should contribute this extension).
|
|
9
|
-
export const mermaid = (): Extension => {
|
|
10
|
-
return [];
|
|
11
|
-
};
|
|
@@ -1,121 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
EditorView,
|
|
7
|
-
Decoration,
|
|
8
|
-
WidgetType,
|
|
9
|
-
MatchDecorator,
|
|
10
|
-
ViewPlugin,
|
|
11
|
-
type DecorationSet,
|
|
12
|
-
type ViewUpdate,
|
|
13
|
-
} from '@codemirror/view';
|
|
14
|
-
|
|
15
|
-
// TODO(burdon): Reconcile with theme.
|
|
16
|
-
const styles = EditorView.baseTheme({
|
|
17
|
-
'& .cm-task-item': {
|
|
18
|
-
paddingLeft: '4px',
|
|
19
|
-
paddingRight: '8px',
|
|
20
|
-
},
|
|
21
|
-
});
|
|
22
|
-
|
|
23
|
-
class CheckboxWidget extends WidgetType {
|
|
24
|
-
constructor(
|
|
25
|
-
private readonly _pos: number,
|
|
26
|
-
private _checked: boolean,
|
|
27
|
-
private readonly _indent: number,
|
|
28
|
-
private readonly _onCheck?: (check: boolean) => void,
|
|
29
|
-
) {
|
|
30
|
-
super();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
override eq(other: CheckboxWidget) {
|
|
34
|
-
return this._pos === other._pos && this._checked === other._checked && this._indent === other._indent;
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
toDOM(view: EditorView) {
|
|
38
|
-
const wrap = document.createElement('span');
|
|
39
|
-
wrap.className = 'cm-task-item';
|
|
40
|
-
wrap.setAttribute('aria-hidden', 'true');
|
|
41
|
-
wrap.style.setProperty('margin-left', this._indent * 24 + 'px');
|
|
42
|
-
|
|
43
|
-
const input = wrap.appendChild(document.createElement('input'));
|
|
44
|
-
input.type = 'checkbox';
|
|
45
|
-
input.checked = this._checked;
|
|
46
|
-
if (!this._onCheck) {
|
|
47
|
-
input.setAttribute('disabled', 'true');
|
|
48
|
-
}
|
|
49
|
-
if (this._onCheck) {
|
|
50
|
-
input.onchange = (event: Event) => {
|
|
51
|
-
this._onCheck?.((event.target as any).checked);
|
|
52
|
-
return true;
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
return wrap;
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
override ignoreEvent() {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
}
|
|
63
|
-
|
|
64
|
-
export type TasklistOptions = {};
|
|
65
|
-
|
|
66
|
-
export const tasklist = (options: TasklistOptions = {}) => {
|
|
67
|
-
// TODO(burdon): Matcher isn't as precise as syntax tree.
|
|
68
|
-
// Allows for indents to be greater than AST would allow.
|
|
69
|
-
const taskMatcher = new MatchDecorator({
|
|
70
|
-
regexp: /^(\s*)- \[([ xX])\]\s/g,
|
|
71
|
-
decoration: (match, view, pos) => {
|
|
72
|
-
const indent = Math.floor(match[1].length / 2);
|
|
73
|
-
const checked = match[2] === 'x' || match[2] === 'X';
|
|
74
|
-
return Decoration.replace({
|
|
75
|
-
widget: new CheckboxWidget(
|
|
76
|
-
pos,
|
|
77
|
-
checked,
|
|
78
|
-
indent,
|
|
79
|
-
view.state.readOnly
|
|
80
|
-
? undefined
|
|
81
|
-
: (checked) => {
|
|
82
|
-
const idx = pos + match[0].indexOf('[') + 1;
|
|
83
|
-
view.dispatch({
|
|
84
|
-
changes: {
|
|
85
|
-
from: idx,
|
|
86
|
-
to: idx + 1,
|
|
87
|
-
insert: checked ? 'x' : ' ',
|
|
88
|
-
},
|
|
89
|
-
// TODO(burdon): Restore cursor position? More useful to move to end of line (can indent).
|
|
90
|
-
selection: {
|
|
91
|
-
anchor: idx + 3,
|
|
92
|
-
},
|
|
93
|
-
});
|
|
94
|
-
},
|
|
95
|
-
),
|
|
96
|
-
});
|
|
97
|
-
},
|
|
98
|
-
});
|
|
99
|
-
|
|
100
|
-
const tasks = ViewPlugin.fromClass(
|
|
101
|
-
class {
|
|
102
|
-
tasks: DecorationSet;
|
|
103
|
-
constructor(view: EditorView) {
|
|
104
|
-
this.tasks = taskMatcher.createDeco(view);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
update(update: ViewUpdate) {
|
|
108
|
-
this.tasks = taskMatcher.updateDeco(update, this.tasks);
|
|
109
|
-
}
|
|
110
|
-
},
|
|
111
|
-
{
|
|
112
|
-
decorations: (value) => value.tasks,
|
|
113
|
-
provide: (plugin) =>
|
|
114
|
-
EditorView.atomicRanges.of((view) => {
|
|
115
|
-
return view.plugin(plugin)?.tasks || Decoration.none;
|
|
116
|
-
}),
|
|
117
|
-
},
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
return [tasks, styles];
|
|
121
|
-
};
|
|
@@ -1,61 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { type Extension } from '@codemirror/state';
|
|
6
|
-
import { hoverTooltip } from '@codemirror/view';
|
|
7
|
-
|
|
8
|
-
import { tooltipContent } from '@dxos/react-ui-theme';
|
|
9
|
-
|
|
10
|
-
const markdownLinkRegexp = /\[([^\]]+)]\(([^)]+)\)/;
|
|
11
|
-
|
|
12
|
-
export type TooltipOptions = {
|
|
13
|
-
onHover: (el: Element, url: string) => void;
|
|
14
|
-
regexp?: RegExp;
|
|
15
|
-
};
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* https://codemirror.net/examples/tooltip
|
|
19
|
-
* https://codemirror.net/docs/ref/#view.hoverTooltip
|
|
20
|
-
* https://github.com/codemirror/view/blob/main/src/tooltip.ts
|
|
21
|
-
*/
|
|
22
|
-
export const tooltip = ({ onHover, regexp = markdownLinkRegexp }: TooltipOptions): Extension =>
|
|
23
|
-
hoverTooltip((view, pos) => {
|
|
24
|
-
const { from, text } = view.state.doc.lineAt(pos);
|
|
25
|
-
const p = pos - from;
|
|
26
|
-
|
|
27
|
-
let idx = 0;
|
|
28
|
-
let match;
|
|
29
|
-
do {
|
|
30
|
-
match = text.substring(idx).match(regexp);
|
|
31
|
-
if (!match) {
|
|
32
|
-
match = undefined;
|
|
33
|
-
break;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
idx = text.indexOf(match[0]);
|
|
37
|
-
if (p >= idx && p < idx + match[0].length) {
|
|
38
|
-
break;
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
idx += match[0].length;
|
|
42
|
-
} while (true);
|
|
43
|
-
|
|
44
|
-
if (!match) {
|
|
45
|
-
return null;
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
const [, , url] = match ?? [];
|
|
49
|
-
|
|
50
|
-
return {
|
|
51
|
-
pos: idx + from,
|
|
52
|
-
end: idx + from + match[0].length,
|
|
53
|
-
above: true,
|
|
54
|
-
create: () => {
|
|
55
|
-
const el = document.createElement('div');
|
|
56
|
-
el.className = tooltipContent({}, 'pli-2 plb-1');
|
|
57
|
-
onHover(el, url);
|
|
58
|
-
return { dom: el, offset: { x: 0, y: 4 } };
|
|
59
|
-
},
|
|
60
|
-
};
|
|
61
|
-
});
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2024 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { log } from '@dxos/log';
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* CodeMirror callbacks swallow errors so wrap handlers.
|
|
9
|
-
*/
|
|
10
|
-
// TODO(burdon): Figure out how to systematize this.
|
|
11
|
-
export const callbackWrapper = <T extends Function>(fn: T): T =>
|
|
12
|
-
((...args: any[]) => {
|
|
13
|
-
try {
|
|
14
|
-
return fn(...args);
|
|
15
|
-
} catch (error) {
|
|
16
|
-
log.catch(error);
|
|
17
|
-
}
|
|
18
|
-
}) as unknown as T;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import type * as A from '@dxos/automerge/automerge';
|
|
6
|
-
|
|
7
|
-
export type IDocHandle<T = any> = {
|
|
8
|
-
docSync(): A.Doc<T> | undefined;
|
|
9
|
-
change(callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): void;
|
|
10
|
-
changeAt(heads: A.Heads, callback: A.ChangeFn<T>, options?: A.ChangeOptions<T>): string[] | undefined;
|
|
11
|
-
|
|
12
|
-
addListener(event: 'change', listener: () => void): void;
|
|
13
|
-
removeListener(event: 'change', listener: () => void): void;
|
|
14
|
-
};
|
|
@@ -1,134 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import {
|
|
6
|
-
Annotation,
|
|
7
|
-
type EditorState,
|
|
8
|
-
type Extension,
|
|
9
|
-
Facet,
|
|
10
|
-
StateEffect,
|
|
11
|
-
StateField,
|
|
12
|
-
type Transaction,
|
|
13
|
-
type TransactionSpec,
|
|
14
|
-
} from '@codemirror/state';
|
|
15
|
-
import { ViewPlugin, type EditorView, type PluginValue, type ViewUpdate } from '@codemirror/view';
|
|
16
|
-
|
|
17
|
-
import * as automerge from '@dxos/automerge/automerge';
|
|
18
|
-
import { type Heads, type Prop } from '@dxos/automerge/automerge';
|
|
19
|
-
|
|
20
|
-
import { type IDocHandle } from './handle';
|
|
21
|
-
import { PatchSemaphore } from './semaphore';
|
|
22
|
-
|
|
23
|
-
export type Value = {
|
|
24
|
-
lastHeads: Heads;
|
|
25
|
-
path: Prop[];
|
|
26
|
-
unreconciledTransactions: Transaction[];
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
type UpdateHeads = {
|
|
30
|
-
newHeads: Heads;
|
|
31
|
-
};
|
|
32
|
-
|
|
33
|
-
export const effectType = StateEffect.define<UpdateHeads>({});
|
|
34
|
-
|
|
35
|
-
export const updateHeads = (newHeads: Heads): StateEffect<UpdateHeads> => effectType.of({ newHeads });
|
|
36
|
-
|
|
37
|
-
export const getLastHeads = (state: EditorState, field: Field): Heads => state.field(field).lastHeads;
|
|
38
|
-
|
|
39
|
-
export const getPath = (state: EditorState, field: Field): Prop[] => state.field(field).path;
|
|
40
|
-
|
|
41
|
-
export type Field = StateField<Value>;
|
|
42
|
-
|
|
43
|
-
const semaphoreFacet = Facet.define<PatchSemaphore, PatchSemaphore>({
|
|
44
|
-
combine: (values) => values.at(-1)!, // Take last.
|
|
45
|
-
});
|
|
46
|
-
|
|
47
|
-
export type AutomergePlugin = {
|
|
48
|
-
extension: Extension;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
export const automergePlugin = (handle: IDocHandle, path: Prop[]): AutomergePlugin => {
|
|
52
|
-
const stateField: StateField<Value> = StateField.define({
|
|
53
|
-
create: () => ({
|
|
54
|
-
lastHeads: automerge.getHeads(handle.docSync()!),
|
|
55
|
-
unreconciledTransactions: [],
|
|
56
|
-
path: path.slice(),
|
|
57
|
-
}),
|
|
58
|
-
update: (value: Value, tr: Transaction) => {
|
|
59
|
-
const result: Value = {
|
|
60
|
-
lastHeads: value.lastHeads,
|
|
61
|
-
unreconciledTransactions: value.unreconciledTransactions.slice(),
|
|
62
|
-
path: path.slice(),
|
|
63
|
-
};
|
|
64
|
-
let clearUnreconciled = false;
|
|
65
|
-
for (const effect of tr.effects) {
|
|
66
|
-
if (effect.is(effectType)) {
|
|
67
|
-
result.lastHeads = effect.value.newHeads;
|
|
68
|
-
clearUnreconciled = true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
if (clearUnreconciled) {
|
|
72
|
-
result.unreconciledTransactions = [];
|
|
73
|
-
} else {
|
|
74
|
-
if (!isReconcileTx(tr)) {
|
|
75
|
-
result.unreconciledTransactions.push(tr);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return result;
|
|
79
|
-
},
|
|
80
|
-
});
|
|
81
|
-
|
|
82
|
-
const semaphore = new PatchSemaphore(stateField);
|
|
83
|
-
|
|
84
|
-
const viewPlugin = ViewPlugin.fromClass(
|
|
85
|
-
class AutomergeCodemirrorViewPlugin implements PluginValue {
|
|
86
|
-
private _view: EditorView;
|
|
87
|
-
|
|
88
|
-
constructor(view: EditorView) {
|
|
89
|
-
this._view = view;
|
|
90
|
-
handle.addListener('change', this._handleChange);
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
update(update: ViewUpdate) {
|
|
94
|
-
if (update.transactions.length > 0 && update.transactions.some((t) => !isReconcileTx(t))) {
|
|
95
|
-
queueMicrotask(() => {
|
|
96
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
97
|
-
});
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
destroy() {
|
|
102
|
-
handle.addListener('change', this._handleChange);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
private _handleChange = () => {
|
|
106
|
-
this._view.state.facet(semaphoreFacet).reconcile(handle, this._view);
|
|
107
|
-
};
|
|
108
|
-
},
|
|
109
|
-
);
|
|
110
|
-
|
|
111
|
-
return {
|
|
112
|
-
extension: [stateField, semaphoreFacet.of(semaphore), viewPlugin],
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
export const reconcileAnnotationType = Annotation.define<unknown>();
|
|
117
|
-
|
|
118
|
-
export const isReconcileTx = (tr: Transaction): boolean => !!tr.annotation(reconcileAnnotationType);
|
|
119
|
-
|
|
120
|
-
export const makeReconcile = (tr: TransactionSpec) => {
|
|
121
|
-
if (tr.annotations != null) {
|
|
122
|
-
if (tr.annotations instanceof Array) {
|
|
123
|
-
tr.annotations = [...tr.annotations, reconcileAnnotationType.of({})];
|
|
124
|
-
} else {
|
|
125
|
-
tr.annotations = [tr.annotations, reconcileAnnotationType.of({})];
|
|
126
|
-
}
|
|
127
|
-
} else {
|
|
128
|
-
tr.annotations = [reconcileAnnotationType.of({})];
|
|
129
|
-
}
|
|
130
|
-
// return {
|
|
131
|
-
// ...tr,
|
|
132
|
-
// annotations: reconcileAnnotationType.of({})
|
|
133
|
-
// }
|
|
134
|
-
};
|
package/src/hooks/yjs/index.ts
DELETED
|
@@ -1,126 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import * as decoding from 'lib0/decoding';
|
|
6
|
-
import * as encoding from 'lib0/encoding';
|
|
7
|
-
import { Observable } from 'lib0/observable';
|
|
8
|
-
import * as awarenessProtocol from 'y-protocols/awareness';
|
|
9
|
-
import { type Doc } from 'yjs';
|
|
10
|
-
|
|
11
|
-
import { log } from '@dxos/log';
|
|
12
|
-
import { type Space } from '@dxos/react-client/echo';
|
|
13
|
-
import { type GossipMessage } from '@dxos/react-client/mesh';
|
|
14
|
-
|
|
15
|
-
type Awareness = awarenessProtocol.Awareness;
|
|
16
|
-
|
|
17
|
-
// Based on https://github.com/yjs/y-webrtc/blob/88baab2/src/y-webrtc.js.
|
|
18
|
-
|
|
19
|
-
const messageAwareness = 1;
|
|
20
|
-
const messageQueryAwareness = 3;
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* Yjs awareness provider on top of a DXOS space.
|
|
24
|
-
*/
|
|
25
|
-
export class SpaceAwarenessProvider extends Observable<any> {
|
|
26
|
-
private readonly _space: Space;
|
|
27
|
-
private readonly _awareness: Awareness;
|
|
28
|
-
private readonly _clientId: number;
|
|
29
|
-
private readonly _channel: string;
|
|
30
|
-
|
|
31
|
-
constructor({ space, doc, channel, awareness }: { space: Space; doc: Doc; channel: string; awareness?: Awareness }) {
|
|
32
|
-
super();
|
|
33
|
-
this._space = space;
|
|
34
|
-
this._awareness = awareness ?? new awarenessProtocol.Awareness(doc);
|
|
35
|
-
this._channel = channel;
|
|
36
|
-
this._clientId = doc.clientID;
|
|
37
|
-
|
|
38
|
-
this._awareness.on('update', this._handleAwarenessUpdate.bind(this));
|
|
39
|
-
this._space.listen(this._channel, this._handleSpaceMessage.bind(this));
|
|
40
|
-
|
|
41
|
-
if (typeof window !== 'undefined') {
|
|
42
|
-
window.addEventListener('beforeunload', this._handleBeforeUnload.bind(this));
|
|
43
|
-
} else if (typeof process !== 'undefined') {
|
|
44
|
-
process.on('exit', this._handleBeforeUnload.bind(this));
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
// Post queryAwareness.
|
|
48
|
-
const encoderAwarenessQuery = encoding.createEncoder();
|
|
49
|
-
encoding.writeVarUint(encoderAwarenessQuery, messageQueryAwareness);
|
|
50
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessQuery));
|
|
51
|
-
|
|
52
|
-
// Post local awareness state.
|
|
53
|
-
const encoderAwarenessState = encoding.createEncoder();
|
|
54
|
-
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
55
|
-
encoding.writeVarUint8Array(
|
|
56
|
-
encoderAwarenessState,
|
|
57
|
-
awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this._clientId]),
|
|
58
|
-
);
|
|
59
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
get awareness(): Awareness {
|
|
63
|
-
return this._awareness;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
private _handleAwarenessUpdate({ added, updated, removed }: any, origin: any) {
|
|
67
|
-
log('awareness update', { added, updated, removed, origin });
|
|
68
|
-
const changedClients = added.concat(updated).concat(removed);
|
|
69
|
-
const encoderAwareness = encoding.createEncoder();
|
|
70
|
-
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
71
|
-
encoding.writeVarUint8Array(
|
|
72
|
-
encoderAwareness,
|
|
73
|
-
awarenessProtocol.encodeAwarenessUpdate(this._awareness, changedClients),
|
|
74
|
-
);
|
|
75
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
private _handleSpaceMessage({ payload }: GossipMessage) {
|
|
79
|
-
log('space message', payload);
|
|
80
|
-
const data = new Uint8Array(Array.from(Object.values(payload)));
|
|
81
|
-
const encoder = this._readMessage(data);
|
|
82
|
-
if (encoder) {
|
|
83
|
-
void this._space.postMessage(this._channel, encoding.toUint8Array(encoder));
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
private _readMessage(message: Uint8Array) {
|
|
88
|
-
const decoder = decoding.createDecoder(message);
|
|
89
|
-
const encoder = encoding.createEncoder();
|
|
90
|
-
const messageType = decoding.readVarUint(decoder);
|
|
91
|
-
|
|
92
|
-
let sendReply = false;
|
|
93
|
-
switch (messageType) {
|
|
94
|
-
case messageAwareness: {
|
|
95
|
-
awarenessProtocol.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
96
|
-
break;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
case messageQueryAwareness: {
|
|
100
|
-
encoding.writeVarUint(encoder, messageAwareness);
|
|
101
|
-
encoding.writeVarUint8Array(
|
|
102
|
-
encoder,
|
|
103
|
-
awarenessProtocol.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())),
|
|
104
|
-
);
|
|
105
|
-
sendReply = true;
|
|
106
|
-
break;
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
default: {
|
|
110
|
-
console.error('Invalid message:', messageType);
|
|
111
|
-
return encoder;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
if (!sendReply) {
|
|
116
|
-
// Nothing has been written, no answer created.
|
|
117
|
-
return null;
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
return encoder;
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
private _handleBeforeUnload() {
|
|
124
|
-
awarenessProtocol.removeAwarenessStates(this._awareness, [this._clientId], 'window unload');
|
|
125
|
-
}
|
|
126
|
-
}
|