@dxos/react-ui-editor 0.3.11-main.a996413 → 0.3.11-main.b00882f
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 +2010 -1505
- 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 +16 -13
- 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/codemirror.stories.d.ts.map +1 -1
- 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/{hooks/yjs → components/TextEditor}/yjs.stories.d.ts +1 -1
- package/dist/types/src/components/TextEditor/yjs.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 +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 +48 -0
- package/dist/types/src/extensions/awareness.d.ts.map +1 -0
- 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/code.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +32 -19
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- 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/hr.d.ts.map +1 -1
- package/dist/types/src/extensions/image.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +5 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/link.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +2 -5
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/mention.d.ts.map +1 -1
- 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/tasklist.d.ts.map +1 -1
- package/dist/types/src/extensions/yjs/cursor.d.ts +4 -0
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/index.d.ts +2 -0
- package/dist/types/src/extensions/yjs/index.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts +4 -0
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +1 -0
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +1 -0
- package/dist/types/src/hooks/automerge.d.ts +4 -0
- package/dist/types/src/hooks/automerge.d.ts.map +1 -0
- package/dist/types/src/hooks/awareness-provider.d.ts +28 -0
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -0
- package/dist/types/src/hooks/defs.d.ts +28 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +5 -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/hooks/{yjs/space-provider.d.ts → yjs.d.ts} +9 -8
- package/dist/types/src/hooks/yjs.d.ts.map +1 -0
- package/dist/types/src/index.d.ts +3 -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/testing/replicator.d.ts +2 -2
- package/dist/types/src/testing/replicator.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/dist/types/src/util.d.ts +7 -0
- package/dist/types/src/util.d.ts.map +1 -0
- package/package.json +32 -30
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +77 -80
- package/src/components/TextEditor/TextEditor.stories.tsx +13 -34
- package/src/components/TextEditor/TextEditor.tsx +125 -93
- package/src/{hooks/automerge → components/TextEditor}/automerge.stories.tsx +66 -6
- package/src/components/TextEditor/codemirror.stories.ts +3 -2
- package/src/components/TextEditor/comments.stories.tsx +357 -0
- package/src/{hooks/yjs → components/TextEditor}/yjs.stories.tsx +1 -1
- package/src/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 +327 -0
- package/src/extensions/basic.ts +22 -17
- package/src/extensions/code.ts +28 -23
- package/src/extensions/comments.ts +252 -229
- package/src/extensions/cursor.ts +50 -0
- package/src/extensions/hr.ts +50 -52
- package/src/extensions/image.ts +40 -22
- package/src/extensions/index.ts +5 -1
- package/src/extensions/link.ts +86 -88
- package/src/extensions/markdown/bundle.ts +18 -24
- package/src/extensions/markdown/highlight.ts +3 -12
- package/src/extensions/mention.ts +9 -2
- package/src/extensions/outliner.ts +12 -0
- package/src/extensions/table.ts +10 -4
- package/src/extensions/tasklist.ts +78 -88
- package/src/extensions/yjs/cursor.ts +22 -0
- package/src/extensions/yjs/index.ts +5 -0
- package/src/{hooks → extensions}/yjs/yjs.test.ts +2 -26
- package/src/extensions/yjs/yjs.ts +16 -0
- package/src/hooks/automerge.ts +53 -0
- package/src/hooks/awareness-provider.ts +120 -0
- package/src/hooks/defs.ts +47 -0
- package/src/hooks/index.ts +6 -1
- package/src/hooks/useTextEditor.ts +29 -0
- package/src/hooks/useTextModel.ts +9 -129
- package/src/hooks/{yjs/space-provider.ts → yjs.ts} +50 -19
- package/src/index.ts +3 -0
- package/src/styles/index.ts +1 -0
- package/src/styles/markdown.ts +0 -2
- package/src/styles/tokens.ts +3 -0
- package/src/testing/replicator.ts +10 -15
- package/src/themes/default.ts +51 -78
- package/src/util.ts +41 -0
- package/dist/types/src/extensions/mermaid.d.ts +0 -3
- package/dist/types/src/extensions/mermaid.d.ts.map +0 -1
- package/dist/types/src/extensions/util.d.ts +0 -5
- package/dist/types/src/extensions/util.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.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs/yjs.test.d.ts.map +0 -1
- package/src/extensions/mermaid.ts +0 -11
- package/src/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 -132
- package/src/hooks/yjs/index.ts +0 -6
- /package/dist/types/src/{hooks → extensions}/automerge/update-codemirror.d.ts +0 -0
- /package/dist/types/src/{hooks → extensions}/yjs/yjs.test.d.ts +0 -0
- /package/dist/types/src/{hooks/yjs → styles}/cursors.d.ts +0 -0
- /package/src/{hooks/yjs → styles}/cursors.ts +0 -0
|
@@ -2,67 +2,14 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import { type Extension, StateField } from '@codemirror/state';
|
|
6
|
-
import get from 'lodash.get';
|
|
7
5
|
import { useEffect, useState } from 'react';
|
|
8
|
-
import { yCollab } from 'y-codemirror.next';
|
|
9
|
-
import type * as awarenessProtocol from 'y-protocols/awareness';
|
|
10
|
-
import * as Y from 'yjs';
|
|
11
6
|
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
14
|
-
type DocAccessor,
|
|
15
|
-
type Space,
|
|
16
|
-
type TextObject,
|
|
17
|
-
type AutomergeTextCompat,
|
|
18
|
-
getRawDoc,
|
|
19
|
-
isActualAutomergeObject,
|
|
20
|
-
} from '@dxos/react-client/echo';
|
|
7
|
+
import { isAutomergeObject, type Space, type TextObject } from '@dxos/react-client/echo';
|
|
21
8
|
import { type Identity } from '@dxos/react-client/halo';
|
|
22
|
-
import type { YText, YXmlFragment } from '@dxos/text-model';
|
|
23
|
-
import { arrayToString, stringToArray } from '@dxos/util';
|
|
24
9
|
|
|
25
|
-
import {
|
|
26
|
-
import {
|
|
27
|
-
|
|
28
|
-
// TODO(burdon): Move.
|
|
29
|
-
type Awareness = awarenessProtocol.Awareness;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* State field makes the model available to other extensions.
|
|
33
|
-
*/
|
|
34
|
-
// TODO(burdon): Use facet?
|
|
35
|
-
export const modelState = StateField.define<EditorModel | undefined>({
|
|
36
|
-
create: () => undefined,
|
|
37
|
-
update: (model) => model,
|
|
38
|
-
});
|
|
39
|
-
|
|
40
|
-
export type Range = {
|
|
41
|
-
from: number;
|
|
42
|
-
to: number;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export type CommentRange = {
|
|
46
|
-
id: string;
|
|
47
|
-
// TODO(burdon): Split into begin/end?
|
|
48
|
-
cursor: string;
|
|
49
|
-
};
|
|
50
|
-
|
|
51
|
-
// TODO(wittjosiah): Factor out to common package? @dxos/react-client?
|
|
52
|
-
export type EditorModel = {
|
|
53
|
-
id: string;
|
|
54
|
-
// TODO(burdon): Remove.
|
|
55
|
-
content: string | YText | YXmlFragment | DocAccessor;
|
|
56
|
-
text: () => string;
|
|
57
|
-
getCursorFromRange?: (value: Range) => string;
|
|
58
|
-
getRangeFromCursor?: (cursor: string) => Range | undefined;
|
|
59
|
-
extension?: Extension;
|
|
60
|
-
awareness?: Awareness;
|
|
61
|
-
peer?: {
|
|
62
|
-
id: string;
|
|
63
|
-
name?: string;
|
|
64
|
-
};
|
|
65
|
-
};
|
|
10
|
+
import { createAutomergeModel } from './automerge';
|
|
11
|
+
import { type EditorModel } from './defs';
|
|
12
|
+
import { createYjsModel } from './yjs';
|
|
66
13
|
|
|
67
14
|
// TODO(burdon): Remove space/identity dependency. Define interface for the framework re content and presence.
|
|
68
15
|
export type UseTextModelProps = {
|
|
@@ -71,87 +18,20 @@ export type UseTextModelProps = {
|
|
|
71
18
|
text?: TextObject;
|
|
72
19
|
};
|
|
73
20
|
|
|
74
|
-
// TODO(burdon): Remove YJS/Automerge deps (from UI component -- create abstraction; incl. all ECHO/Space deps).
|
|
75
|
-
// TODO(wittjosiah): Factor out to common package? @dxos/react-client?
|
|
76
21
|
export const useTextModel = (props: UseTextModelProps): EditorModel | undefined => {
|
|
77
22
|
const { identity, space, text } = props;
|
|
78
|
-
const [model, setModel] = useState<EditorModel | undefined>(
|
|
23
|
+
const [model, setModel] = useState<EditorModel | undefined>();
|
|
79
24
|
useEffect(() => setModel(createModel(props)), [identity, space, text]);
|
|
80
25
|
return model;
|
|
81
26
|
};
|
|
82
27
|
|
|
83
28
|
const createModel = (props: UseTextModelProps) => {
|
|
84
29
|
const { text } = props;
|
|
85
|
-
if (
|
|
30
|
+
if (isAutomergeObject(text)) {
|
|
86
31
|
return createAutomergeModel(props);
|
|
87
|
-
} else {
|
|
88
|
-
if (!text?.doc) {
|
|
89
|
-
return undefined;
|
|
90
|
-
}
|
|
91
|
-
|
|
32
|
+
} else if (text?.doc) {
|
|
92
33
|
return createYjsModel(props);
|
|
34
|
+
} else {
|
|
35
|
+
return undefined;
|
|
93
36
|
}
|
|
94
37
|
};
|
|
95
|
-
|
|
96
|
-
const createYjsModel = ({ identity, space, text }: UseTextModelProps): EditorModel => {
|
|
97
|
-
invariant(text?.doc && text?.content);
|
|
98
|
-
const provider = space
|
|
99
|
-
? new SpaceAwarenessProvider({ space, doc: text.doc, channel: `yjs.awareness.${text.id}` })
|
|
100
|
-
: undefined;
|
|
101
|
-
|
|
102
|
-
const model: EditorModel = {
|
|
103
|
-
id: text.doc.guid,
|
|
104
|
-
content: text.content,
|
|
105
|
-
text: () => text.content!.toString(),
|
|
106
|
-
// https://github.com/yjs/yjs?tab=readme-ov-file#relative-positions
|
|
107
|
-
getCursorFromRange: (range: Range) => {
|
|
108
|
-
const from = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text.content as YText, range.from));
|
|
109
|
-
const to = Y.encodeRelativePosition(Y.createRelativePositionFromTypeIndex(text.content as YText, range.to, -1));
|
|
110
|
-
return [arrayToString(from), arrayToString(to)].join(':');
|
|
111
|
-
},
|
|
112
|
-
getRangeFromCursor: (cursor: string) => {
|
|
113
|
-
invariant(text.doc);
|
|
114
|
-
const parts = cursor.split(':');
|
|
115
|
-
const from = Y.createAbsolutePositionFromRelativePosition(
|
|
116
|
-
Y.decodeRelativePosition(stringToArray(parts[0])),
|
|
117
|
-
text.doc,
|
|
118
|
-
);
|
|
119
|
-
const to = Y.createAbsolutePositionFromRelativePosition(
|
|
120
|
-
Y.decodeRelativePosition(stringToArray(parts[1])),
|
|
121
|
-
text.doc,
|
|
122
|
-
);
|
|
123
|
-
return from && to ? { from: from.index, to: to.index } : undefined;
|
|
124
|
-
},
|
|
125
|
-
extension: [yCollab(text.content as YText, provider?.awareness), modelState.init(() => model)],
|
|
126
|
-
awareness: provider?.awareness,
|
|
127
|
-
peer: identity
|
|
128
|
-
? {
|
|
129
|
-
id: identity.identityKey.toHex(),
|
|
130
|
-
name: identity.profile?.displayName,
|
|
131
|
-
}
|
|
132
|
-
: undefined,
|
|
133
|
-
};
|
|
134
|
-
|
|
135
|
-
return model;
|
|
136
|
-
};
|
|
137
|
-
|
|
138
|
-
const createAutomergeModel = ({ identity, text }: UseTextModelProps): EditorModel => {
|
|
139
|
-
const obj = text as any as AutomergeTextCompat;
|
|
140
|
-
const doc = getRawDoc(obj, [obj.field]);
|
|
141
|
-
|
|
142
|
-
const model: EditorModel = {
|
|
143
|
-
id: obj.id,
|
|
144
|
-
content: doc,
|
|
145
|
-
text: () => get(doc.handle.docSync(), doc.path),
|
|
146
|
-
// TODO(burdon): https://automerge.org/automerge/api-docs/js/functions/next.getCursor.html
|
|
147
|
-
extension: [automergePlugin(doc.handle, doc.path), modelState.init(() => model)],
|
|
148
|
-
peer: identity
|
|
149
|
-
? {
|
|
150
|
-
id: identity.identityKey.toHex(),
|
|
151
|
-
name: identity.profile?.displayName,
|
|
152
|
-
}
|
|
153
|
-
: undefined,
|
|
154
|
-
};
|
|
155
|
-
|
|
156
|
-
return model;
|
|
157
|
-
};
|
|
@@ -5,14 +5,41 @@
|
|
|
5
5
|
import * as decoding from 'lib0/decoding';
|
|
6
6
|
import * as encoding from 'lib0/encoding';
|
|
7
7
|
import { Observable } from 'lib0/observable';
|
|
8
|
-
import * as
|
|
8
|
+
import * as YP from 'y-protocols/awareness';
|
|
9
9
|
import { type Doc } from 'yjs';
|
|
10
10
|
|
|
11
|
+
import { invariant } from '@dxos/invariant';
|
|
11
12
|
import { log } from '@dxos/log';
|
|
12
13
|
import { type Space } from '@dxos/react-client/echo';
|
|
13
14
|
import { type GossipMessage } from '@dxos/react-client/mesh';
|
|
14
|
-
|
|
15
|
-
|
|
15
|
+
import type { YText } from '@dxos/text-model';
|
|
16
|
+
|
|
17
|
+
import { type EditorModel, modelState } from './defs';
|
|
18
|
+
import { type UseTextModelProps } from './useTextModel';
|
|
19
|
+
import { yjs } from '../extensions';
|
|
20
|
+
|
|
21
|
+
export const createYjsModel = ({ identity, space, text }: UseTextModelProps): EditorModel => {
|
|
22
|
+
invariant(text?.doc && text?.content);
|
|
23
|
+
const provider = space
|
|
24
|
+
? new YAwarenessProvider({ space, doc: text.doc, channel: `yjs.awareness.${text.id}` })
|
|
25
|
+
: undefined;
|
|
26
|
+
|
|
27
|
+
const model: EditorModel = {
|
|
28
|
+
id: text.doc.guid,
|
|
29
|
+
content: text.content,
|
|
30
|
+
text: () => text.content!.toString(),
|
|
31
|
+
extension: [modelState.init(() => model), yjs(text.content as YText, provider?.awareness)],
|
|
32
|
+
awareness: provider?.awareness,
|
|
33
|
+
peer: identity
|
|
34
|
+
? {
|
|
35
|
+
id: identity.identityKey.toHex(),
|
|
36
|
+
name: identity.profile?.displayName,
|
|
37
|
+
}
|
|
38
|
+
: undefined,
|
|
39
|
+
};
|
|
40
|
+
|
|
41
|
+
return model;
|
|
42
|
+
};
|
|
16
43
|
|
|
17
44
|
// Based on https://github.com/yjs/y-webrtc/blob/88baab2/src/y-webrtc.js.
|
|
18
45
|
|
|
@@ -22,16 +49,26 @@ const messageQueryAwareness = 3;
|
|
|
22
49
|
/**
|
|
23
50
|
* Yjs awareness provider on top of a DXOS space.
|
|
24
51
|
*/
|
|
25
|
-
export class
|
|
52
|
+
export class YAwarenessProvider extends Observable<any> {
|
|
26
53
|
private readonly _space: Space;
|
|
27
|
-
private readonly _awareness: Awareness;
|
|
54
|
+
private readonly _awareness: YP.Awareness;
|
|
28
55
|
private readonly _clientId: number;
|
|
29
56
|
private readonly _channel: string;
|
|
30
57
|
|
|
31
|
-
constructor({
|
|
58
|
+
constructor({
|
|
59
|
+
space,
|
|
60
|
+
doc,
|
|
61
|
+
channel,
|
|
62
|
+
awareness,
|
|
63
|
+
}: {
|
|
64
|
+
space: Space;
|
|
65
|
+
doc: Doc;
|
|
66
|
+
channel: string;
|
|
67
|
+
awareness?: YP.Awareness;
|
|
68
|
+
}) {
|
|
32
69
|
super();
|
|
33
70
|
this._space = space;
|
|
34
|
-
this._awareness = awareness ?? new
|
|
71
|
+
this._awareness = awareness ?? new YP.Awareness(doc);
|
|
35
72
|
this._channel = channel;
|
|
36
73
|
this._clientId = doc.clientID;
|
|
37
74
|
|
|
@@ -52,14 +89,11 @@ export class SpaceAwarenessProvider extends Observable<any> {
|
|
|
52
89
|
// Post local awareness state.
|
|
53
90
|
const encoderAwarenessState = encoding.createEncoder();
|
|
54
91
|
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
55
|
-
encoding.writeVarUint8Array(
|
|
56
|
-
encoderAwarenessState,
|
|
57
|
-
awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this._clientId]),
|
|
58
|
-
);
|
|
92
|
+
encoding.writeVarUint8Array(encoderAwarenessState, YP.encodeAwarenessUpdate(this.awareness, [this._clientId]));
|
|
59
93
|
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwarenessState));
|
|
60
94
|
}
|
|
61
95
|
|
|
62
|
-
get awareness(): Awareness {
|
|
96
|
+
get awareness(): YP.Awareness {
|
|
63
97
|
return this._awareness;
|
|
64
98
|
}
|
|
65
99
|
|
|
@@ -68,10 +102,7 @@ export class SpaceAwarenessProvider extends Observable<any> {
|
|
|
68
102
|
const changedClients = added.concat(updated).concat(removed);
|
|
69
103
|
const encoderAwareness = encoding.createEncoder();
|
|
70
104
|
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
71
|
-
encoding.writeVarUint8Array(
|
|
72
|
-
encoderAwareness,
|
|
73
|
-
awarenessProtocol.encodeAwarenessUpdate(this._awareness, changedClients),
|
|
74
|
-
);
|
|
105
|
+
encoding.writeVarUint8Array(encoderAwareness, YP.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
75
106
|
void this._space.postMessage(this._channel, encoding.toUint8Array(encoderAwareness));
|
|
76
107
|
}
|
|
77
108
|
|
|
@@ -92,7 +123,7 @@ export class SpaceAwarenessProvider extends Observable<any> {
|
|
|
92
123
|
let sendReply = false;
|
|
93
124
|
switch (messageType) {
|
|
94
125
|
case messageAwareness: {
|
|
95
|
-
|
|
126
|
+
YP.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
96
127
|
break;
|
|
97
128
|
}
|
|
98
129
|
|
|
@@ -100,7 +131,7 @@ export class SpaceAwarenessProvider extends Observable<any> {
|
|
|
100
131
|
encoding.writeVarUint(encoder, messageAwareness);
|
|
101
132
|
encoding.writeVarUint8Array(
|
|
102
133
|
encoder,
|
|
103
|
-
|
|
134
|
+
YP.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())),
|
|
104
135
|
);
|
|
105
136
|
sendReply = true;
|
|
106
137
|
break;
|
|
@@ -121,6 +152,6 @@ export class SpaceAwarenessProvider extends Observable<any> {
|
|
|
121
152
|
}
|
|
122
153
|
|
|
123
154
|
private _handleBeforeUnload() {
|
|
124
|
-
|
|
155
|
+
YP.removeAwarenessStates(this._awareness, [this._clientId], 'window unload');
|
|
125
156
|
}
|
|
126
157
|
}
|
package/src/index.ts
CHANGED
|
@@ -5,8 +5,11 @@
|
|
|
5
5
|
export { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
|
|
6
6
|
export { Doc, YText, YXmlFragment } from '@dxos/text-model';
|
|
7
7
|
export { type Extension } from '@codemirror/state';
|
|
8
|
+
export { type EditorView } from '@codemirror/view';
|
|
8
9
|
|
|
9
10
|
export * from './components';
|
|
10
11
|
export * from './extensions';
|
|
11
12
|
export * from './hooks';
|
|
13
|
+
export { getToken } from './styles';
|
|
12
14
|
export * from './themes';
|
|
15
|
+
export * from './util';
|
package/src/styles/index.ts
CHANGED
package/src/styles/markdown.ts
CHANGED
|
@@ -39,10 +39,8 @@ export const codeBlock = 'mlb-2 font-mono bg-neutral-500/10 p-3 rounded';
|
|
|
39
39
|
|
|
40
40
|
export const inlineUrl = mx(code, 'px-1');
|
|
41
41
|
|
|
42
|
-
// TODO(burdon): Replace with widget.
|
|
43
42
|
export const blockquote = mx('pl-1 mr-1 border-is-4 border-primary-500/70 dark:border-primary-500/30', light);
|
|
44
43
|
|
|
45
|
-
// TODO(burdon): Replace with widget.
|
|
46
44
|
export const horizontalRule =
|
|
47
45
|
'flex mlb-4 border-b text-neutral-100 dark:text-neutral-900 border-neutral-200 dark:border-neutral-800';
|
|
48
46
|
|
package/src/styles/tokens.ts
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import get from 'lodash.get';
|
|
5
6
|
import type { StyleSpec } from 'style-mod';
|
|
6
7
|
|
|
7
8
|
import { tailwindConfig, type TailwindConfig } from '@dxos/react-ui-theme';
|
|
@@ -12,3 +13,5 @@ export type ThemeStyles = {
|
|
|
12
13
|
|
|
13
14
|
// TODO(thure): Why export the whole theme? Can this be done differently?
|
|
14
15
|
export const tokens: TailwindConfig['theme'] = tailwindConfig({}).theme;
|
|
16
|
+
|
|
17
|
+
export const getToken = (path: string, defaultValue: any = undefined) => get(tokens, path, defaultValue);
|
|
@@ -7,7 +7,7 @@ import * as decoding from 'lib0/decoding';
|
|
|
7
7
|
import * as encoding from 'lib0/encoding';
|
|
8
8
|
import { Observable } from 'lib0/observable';
|
|
9
9
|
import { useMemo } from 'react';
|
|
10
|
-
import * as
|
|
10
|
+
import * as YP from 'y-protocols/awareness';
|
|
11
11
|
import * as syncProtocol from 'y-protocols/sync';
|
|
12
12
|
import { Doc } from 'yjs';
|
|
13
13
|
|
|
@@ -15,9 +15,10 @@ import { Event } from '@dxos/async';
|
|
|
15
15
|
import { log } from '@dxos/log';
|
|
16
16
|
import { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
|
|
17
17
|
|
|
18
|
-
import {
|
|
18
|
+
import { type EditorModel } from '../hooks';
|
|
19
|
+
import { cursorColor } from '../styles';
|
|
19
20
|
|
|
20
|
-
type Awareness =
|
|
21
|
+
type Awareness = YP.Awareness;
|
|
21
22
|
|
|
22
23
|
const messageSync = 0;
|
|
23
24
|
const messageAwareness = 1;
|
|
@@ -35,7 +36,7 @@ export class AwarenessProvider extends Observable<any> {
|
|
|
35
36
|
super();
|
|
36
37
|
this._remoteUpdate = update;
|
|
37
38
|
this._doc = doc;
|
|
38
|
-
this._awareness = awareness ?? new
|
|
39
|
+
this._awareness = awareness ?? new YP.Awareness(doc);
|
|
39
40
|
|
|
40
41
|
this._doc.on('update', this._handleDocUpdate.bind(this));
|
|
41
42
|
this._awareness.on('update', this._handleAwarenessUpdate.bind(this));
|
|
@@ -55,10 +56,7 @@ export class AwarenessProvider extends Observable<any> {
|
|
|
55
56
|
// Post local awareness state.
|
|
56
57
|
const encoderAwarenessState = encoding.createEncoder();
|
|
57
58
|
encoding.writeVarUint(encoderAwarenessState, messageAwareness);
|
|
58
|
-
encoding.writeVarUint8Array(
|
|
59
|
-
encoderAwarenessState,
|
|
60
|
-
awarenessProtocol.encodeAwarenessUpdate(this.awareness, [this._doc.clientID]),
|
|
61
|
-
);
|
|
59
|
+
encoding.writeVarUint8Array(encoderAwarenessState, YP.encodeAwarenessUpdate(this.awareness, [this._doc.clientID]));
|
|
62
60
|
void this._remoteUpdate.emit(encoding.toUint8Array(encoderAwarenessState));
|
|
63
61
|
}
|
|
64
62
|
|
|
@@ -79,10 +77,7 @@ export class AwarenessProvider extends Observable<any> {
|
|
|
79
77
|
const changedClients = added.concat(updated).concat(removed);
|
|
80
78
|
const encoderAwareness = encoding.createEncoder();
|
|
81
79
|
encoding.writeVarUint(encoderAwareness, messageAwareness);
|
|
82
|
-
encoding.writeVarUint8Array(
|
|
83
|
-
encoderAwareness,
|
|
84
|
-
awarenessProtocol.encodeAwarenessUpdate(this._awareness, changedClients),
|
|
85
|
-
);
|
|
80
|
+
encoding.writeVarUint8Array(encoderAwareness, YP.encodeAwarenessUpdate(this._awareness, changedClients));
|
|
86
81
|
this._remoteUpdate.emit(encoding.toUint8Array(encoderAwareness));
|
|
87
82
|
}
|
|
88
83
|
|
|
@@ -109,7 +104,7 @@ export class AwarenessProvider extends Observable<any> {
|
|
|
109
104
|
}
|
|
110
105
|
|
|
111
106
|
case messageAwareness: {
|
|
112
|
-
|
|
107
|
+
YP.applyAwarenessUpdate(this._awareness, decoding.readVarUint8Array(decoder), this);
|
|
113
108
|
break;
|
|
114
109
|
}
|
|
115
110
|
|
|
@@ -117,7 +112,7 @@ export class AwarenessProvider extends Observable<any> {
|
|
|
117
112
|
encoding.writeVarUint(encoder, messageAwareness);
|
|
118
113
|
encoding.writeVarUint8Array(
|
|
119
114
|
encoder,
|
|
120
|
-
|
|
115
|
+
YP.encodeAwarenessUpdate(this._awareness, Array.from(this._awareness.getStates().keys())),
|
|
121
116
|
);
|
|
122
117
|
sendReply = true;
|
|
123
118
|
break;
|
|
@@ -138,7 +133,7 @@ export class AwarenessProvider extends Observable<any> {
|
|
|
138
133
|
}
|
|
139
134
|
|
|
140
135
|
private _handleBeforeUnload() {
|
|
141
|
-
|
|
136
|
+
YP.removeAwarenessStates(this._awareness, [this._doc.clientID], 'window unload');
|
|
142
137
|
}
|
|
143
138
|
}
|
|
144
139
|
|
package/src/themes/default.ts
CHANGED
|
@@ -6,8 +6,8 @@ import get from 'lodash.get';
|
|
|
6
6
|
|
|
7
7
|
import { type ThemeStyles, tokens } from '../styles';
|
|
8
8
|
|
|
9
|
-
// TODO(burdon): Can we
|
|
10
|
-
//
|
|
9
|
+
// TODO(burdon): Can we use @apply and import css file?
|
|
10
|
+
// https://tailwindcss.com/docs/reusing-styles#extracting-classes-with-apply?
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Minimal styles.
|
|
@@ -49,12 +49,12 @@ export const defaultTheme: ThemeStyles = {
|
|
|
49
49
|
'&.cm-focused': {
|
|
50
50
|
outline: 'none',
|
|
51
51
|
},
|
|
52
|
-
'
|
|
52
|
+
'.cm-scroller': {
|
|
53
53
|
overflow: 'visible',
|
|
54
54
|
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
55
55
|
},
|
|
56
56
|
|
|
57
|
-
'
|
|
57
|
+
'.cm-content': {
|
|
58
58
|
padding: 0,
|
|
59
59
|
// NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
|
60
60
|
fontSize: '16px',
|
|
@@ -77,17 +77,19 @@ export const defaultTheme: ThemeStyles = {
|
|
|
77
77
|
'&dark .cm-cursor, &dark .cm-dropCursor': {
|
|
78
78
|
borderLeft: '2px solid white',
|
|
79
79
|
},
|
|
80
|
-
'
|
|
80
|
+
'.cm-placeholder': {
|
|
81
81
|
fontWeight: 100,
|
|
82
82
|
},
|
|
83
83
|
|
|
84
84
|
//
|
|
85
85
|
// line
|
|
86
86
|
//
|
|
87
|
-
'
|
|
87
|
+
'.cm-line': {
|
|
88
88
|
paddingInline: 0,
|
|
89
|
+
// TODO(burdon): Other values leave gaps between lines when highlighted.
|
|
90
|
+
// lineHeight: 'normal',
|
|
89
91
|
},
|
|
90
|
-
'
|
|
92
|
+
'.cm-activeLine': {
|
|
91
93
|
background: 'inherit',
|
|
92
94
|
},
|
|
93
95
|
|
|
@@ -119,40 +121,10 @@ export const defaultTheme: ThemeStyles = {
|
|
|
119
121
|
backgroundColor: get(tokens, 'extend.colors.yellow.700'),
|
|
120
122
|
},
|
|
121
123
|
|
|
122
|
-
//
|
|
123
|
-
// collaboration
|
|
124
|
-
// TODO(burdon): Review classnames (YJS dependent?) Note: e2e tests depend on this class.
|
|
125
|
-
//
|
|
126
|
-
|
|
127
|
-
'&light .cm-ySelection, &light .cm-yLineSelection': {
|
|
128
|
-
mixBlendMode: 'multiply',
|
|
129
|
-
},
|
|
130
|
-
'&dark .cm-ySelection, &dark .cm-yLineSelection': {
|
|
131
|
-
mixBlendMode: 'screen',
|
|
132
|
-
},
|
|
133
|
-
|
|
134
|
-
'& .cm-ySelectionInfo': {
|
|
135
|
-
padding: '2px 4px',
|
|
136
|
-
marginBlockStart: '-4px',
|
|
137
|
-
},
|
|
138
|
-
'& .cm-ySelection, & .cm-selectionMatch': {
|
|
139
|
-
paddingBlockStart: '.15em',
|
|
140
|
-
paddingBlockEnd: '.15em',
|
|
141
|
-
},
|
|
142
|
-
'& .cm-ySelectionCaret': {
|
|
143
|
-
display: 'inline-block',
|
|
144
|
-
insetBlockStart: '.1em',
|
|
145
|
-
blockSize: '1.4em',
|
|
146
|
-
verticalAlign: 'top',
|
|
147
|
-
},
|
|
148
|
-
'& .cm-yLineSelection': {
|
|
149
|
-
margin: 0,
|
|
150
|
-
},
|
|
151
|
-
|
|
152
124
|
//
|
|
153
125
|
// link
|
|
154
126
|
//
|
|
155
|
-
'
|
|
127
|
+
'.cm-link': {
|
|
156
128
|
color: get(tokens, 'extend.colors.primary.500'),
|
|
157
129
|
textDecorationLine: 'underline',
|
|
158
130
|
textDecorationThickness: '1px',
|
|
@@ -164,75 +136,74 @@ export const defaultTheme: ThemeStyles = {
|
|
|
164
136
|
//
|
|
165
137
|
// tooltip
|
|
166
138
|
//
|
|
167
|
-
'
|
|
139
|
+
'.cm-tooltip': {
|
|
168
140
|
border: 'none',
|
|
169
141
|
},
|
|
170
|
-
'
|
|
142
|
+
'.cm-tooltip-below': {},
|
|
171
143
|
|
|
172
144
|
//
|
|
173
145
|
// autocomplete
|
|
174
146
|
//
|
|
175
|
-
'
|
|
147
|
+
'.cm-tooltip-autocomplete': {
|
|
176
148
|
marginTop: '4px',
|
|
177
149
|
marginLeft: '-3px',
|
|
178
150
|
},
|
|
179
|
-
'
|
|
180
|
-
'
|
|
181
|
-
'
|
|
151
|
+
'.cm-tooltip-autocomplete ul li': {},
|
|
152
|
+
'.cm-tooltip-autocomplete ul li[aria-selected]': {},
|
|
153
|
+
'.cm-completionIcon': {
|
|
182
154
|
display: 'none',
|
|
183
155
|
},
|
|
184
|
-
'
|
|
156
|
+
'.cm-completionLabel': {
|
|
185
157
|
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
186
158
|
},
|
|
187
|
-
'
|
|
159
|
+
'.cm-completionMatchedText': {
|
|
188
160
|
textDecoration: 'none',
|
|
189
161
|
},
|
|
190
162
|
|
|
191
|
-
//
|
|
192
|
-
// widgets
|
|
193
|
-
//
|
|
194
|
-
'& .cm-widgetBuffer': {
|
|
195
|
-
display: 'none',
|
|
196
|
-
height: 0,
|
|
197
|
-
},
|
|
198
|
-
|
|
199
163
|
//
|
|
200
164
|
// table
|
|
201
165
|
//
|
|
202
|
-
'
|
|
166
|
+
'.cm-table *': {
|
|
203
167
|
fontFamily: `${get(tokens, 'fontFamily.mono', []).join(',')} !important`,
|
|
204
168
|
textDecoration: 'none !important',
|
|
205
169
|
},
|
|
206
|
-
'
|
|
170
|
+
'.cm-table-head': {
|
|
207
171
|
padding: '2px 16px 2px 0px',
|
|
208
172
|
borderBottom: `1px solid ${get(tokens, 'extend.colors.neutral.500')}`,
|
|
209
173
|
fontWeight: 100,
|
|
210
174
|
textAlign: 'left',
|
|
211
175
|
color: get(tokens, 'extend.colors.neutral.500'),
|
|
212
176
|
},
|
|
213
|
-
'
|
|
177
|
+
'.cm-table-cell': {
|
|
214
178
|
padding: '2px 16px 2px 0px',
|
|
215
179
|
},
|
|
216
180
|
|
|
217
181
|
//
|
|
218
182
|
// image
|
|
219
183
|
//
|
|
220
|
-
'
|
|
221
|
-
|
|
184
|
+
'.cm-image': {
|
|
185
|
+
display: 'block',
|
|
186
|
+
height: '0',
|
|
187
|
+
},
|
|
188
|
+
'.cm-image.cm-loaded-image': {
|
|
189
|
+
height: 'auto',
|
|
190
|
+
borderTop: '0.5rem solid transparent',
|
|
191
|
+
borderBottom: '0.5rem solid transparent',
|
|
222
192
|
},
|
|
223
193
|
|
|
224
194
|
//
|
|
225
195
|
// font size
|
|
226
|
-
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
196
|
+
// TODO(thure): This appears to be the best or only way to set selection caret heights,
|
|
197
|
+
// but it's far more verbose than it needs to be.
|
|
227
198
|
//
|
|
228
|
-
...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
}, {}),
|
|
199
|
+
// ...Object.keys(get(tokens, 'extend.fontSize', {})).reduce((acc: Record<string, any>, fontSize) => {
|
|
200
|
+
// const height = get(tokens, ['extend', 'fontSize', fontSize, 1, 'lineHeight']);
|
|
201
|
+
//
|
|
202
|
+
// acc[`& .text-${fontSize} + .cm-ySelectionCaret`] = { height };
|
|
203
|
+
// acc[`& .text-${fontSize} + .cm-ySelection + .cm-ySelectionCaret`] = { height };
|
|
204
|
+
// acc[`& .text-${fontSize} + .cm-widgetBuffer + .cm-ySelectionCaret`] = { height };
|
|
205
|
+
// return acc;
|
|
206
|
+
// }, {}),
|
|
236
207
|
|
|
237
208
|
/**
|
|
238
209
|
* Panels
|
|
@@ -250,14 +221,14 @@ export const defaultTheme: ThemeStyles = {
|
|
|
250
221
|
* </div>
|
|
251
222
|
* </div
|
|
252
223
|
*/
|
|
253
|
-
'
|
|
224
|
+
'.cm-panels': {
|
|
254
225
|
border: `1px solid ${get(tokens, 'extend.colors.neutral.200')}`,
|
|
255
226
|
},
|
|
256
|
-
'
|
|
227
|
+
'.cm-panel': {
|
|
257
228
|
background: get(tokens, 'extend.colors.neutral.50'),
|
|
258
229
|
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
259
230
|
},
|
|
260
|
-
'
|
|
231
|
+
'.cm-button': {
|
|
261
232
|
margin: '4px',
|
|
262
233
|
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
263
234
|
background: get(tokens, 'extend.colors.neutral.100'),
|
|
@@ -271,32 +242,34 @@ export const defaultTheme: ThemeStyles = {
|
|
|
271
242
|
backgroundImage: 'none',
|
|
272
243
|
},
|
|
273
244
|
},
|
|
274
|
-
'
|
|
245
|
+
'.cm-panel input[type=checkbox]': {
|
|
275
246
|
marginRight: '0.4rem !important',
|
|
276
247
|
},
|
|
277
248
|
};
|
|
278
249
|
|
|
279
250
|
export const textTheme: ThemeStyles = {
|
|
280
|
-
'
|
|
251
|
+
'.cm-scroller': {
|
|
281
252
|
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
282
253
|
},
|
|
283
|
-
'
|
|
254
|
+
'.cm-placeholder': {
|
|
284
255
|
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
285
256
|
},
|
|
286
257
|
};
|
|
287
258
|
|
|
288
259
|
export const markdownTheme: ThemeStyles = {
|
|
289
|
-
|
|
290
|
-
|
|
260
|
+
'.cm-scroller': {
|
|
261
|
+
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
262
|
+
},
|
|
263
|
+
'.cm-placeholder': {
|
|
291
264
|
fontFamily: get(tokens, 'fontFamily.body', []).join(','),
|
|
292
265
|
},
|
|
293
266
|
};
|
|
294
267
|
|
|
295
268
|
export const codeTheme: ThemeStyles = {
|
|
296
|
-
'
|
|
269
|
+
'.cm-scroller': {
|
|
297
270
|
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
298
271
|
},
|
|
299
|
-
'
|
|
272
|
+
'.cm-placeholder': {
|
|
300
273
|
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
301
274
|
},
|
|
302
275
|
};
|