@dxos/react-ui-editor 0.3.11-main.508f304 → 0.3.11-main.514e6e4
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 +665 -791
- 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.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -2
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/extensions/awareness.d.ts +1 -3
- package/dist/types/src/extensions/awareness.d.ts.map +1 -1
- package/dist/types/src/extensions/basic.d.ts +2 -2
- package/dist/types/src/extensions/basic.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +3 -3
- package/dist/types/src/extensions/comments.d.ts.map +1 -1
- package/dist/types/src/extensions/index.d.ts +0 -7
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/bundle.d.ts +2 -2
- package/dist/types/src/extensions/markdown/bundle.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/code.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/heading.d.ts +6 -0
- package/dist/types/src/extensions/markdown/heading.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/highlight.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/hr.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/image.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts +7 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/table.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/tasklist.d.ts.map +1 -0
- package/dist/types/src/hooks/awareness-provider.d.ts +7 -4
- package/dist/types/src/hooks/awareness-provider.d.ts.map +1 -1
- package/dist/types/src/hooks/defs.d.ts +1 -4
- package/dist/types/src/hooks/defs.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +1 -2
- 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.map +1 -1
- package/dist/types/src/styles/markdown.d.ts +2 -2
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +24 -27
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +6 -4
- package/src/components/TextEditor/TextEditor.tsx +12 -15
- package/src/components/TextEditor/comments.stories.tsx +5 -5
- package/src/extensions/awareness.ts +14 -31
- package/src/extensions/basic.ts +3 -3
- package/src/extensions/comments.ts +15 -15
- package/src/extensions/index.ts +0 -7
- package/src/extensions/markdown/bundle.ts +3 -7
- package/src/extensions/markdown/code.ts +127 -0
- package/src/extensions/markdown/heading.ts +59 -0
- package/src/extensions/markdown/highlight.ts +9 -15
- package/src/extensions/{hr.ts → markdown/hr.ts} +3 -4
- package/src/extensions/markdown/index.ts +7 -0
- package/src/extensions/{link.ts → markdown/link.ts} +1 -2
- package/src/extensions/{tasklist.ts → markdown/tasklist.ts} +2 -3
- package/src/hooks/awareness-provider.ts +24 -20
- package/src/hooks/defs.ts +1 -6
- package/src/hooks/index.ts +1 -2
- package/src/hooks/useTextEditor.ts +29 -0
- package/src/hooks/useTextModel.ts +46 -12
- package/src/styles/markdown.ts +9 -10
- package/src/themes/default.ts +0 -2
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/codemirror.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts +0 -12
- package/dist/types/src/components/TextEditor/yjs.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/code.d.ts.map +0 -1
- package/dist/types/src/extensions/hr.d.ts.map +0 -1
- package/dist/types/src/extensions/image.d.ts.map +0 -1
- package/dist/types/src/extensions/link.d.ts.map +0 -1
- package/dist/types/src/extensions/table.d.ts.map +0 -1
- package/dist/types/src/extensions/tasklist.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/cursor.d.ts +0 -4
- package/dist/types/src/extensions/yjs/cursor.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/index.d.ts +0 -2
- package/dist/types/src/extensions/yjs/index.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.d.ts +0 -4
- package/dist/types/src/extensions/yjs/yjs.d.ts.map +0 -1
- package/dist/types/src/extensions/yjs/yjs.test.d.ts +0 -2
- package/dist/types/src/extensions/yjs/yjs.test.d.ts.map +0 -1
- package/dist/types/src/hooks/automerge.d.ts +0 -4
- package/dist/types/src/hooks/automerge.d.ts.map +0 -1
- package/dist/types/src/hooks/yjs.d.ts +0 -28
- package/dist/types/src/hooks/yjs.d.ts.map +0 -1
- package/dist/types/src/testing/index.d.ts +0 -3
- package/dist/types/src/testing/index.d.ts.map +0 -1
- package/dist/types/src/testing/proto/gen/schema.d.ts +0 -15
- package/dist/types/src/testing/proto/gen/schema.d.ts.map +0 -1
- package/dist/types/src/testing/proto/index.d.ts +0 -2
- package/dist/types/src/testing/proto/index.d.ts.map +0 -1
- package/dist/types/src/testing/replicator.d.ts +0 -45
- package/dist/types/src/testing/replicator.d.ts.map +0 -1
- package/src/components/TextEditor/codemirror.stories.ts +0 -115
- package/src/components/TextEditor/yjs.stories.tsx +0 -56
- package/src/extensions/code.ts +0 -104
- package/src/extensions/yjs/cursor.ts +0 -22
- package/src/extensions/yjs/index.ts +0 -5
- package/src/extensions/yjs/yjs.test.ts +0 -35
- package/src/extensions/yjs/yjs.ts +0 -16
- package/src/hooks/automerge.ts +0 -53
- package/src/hooks/yjs.ts +0 -157
- package/src/testing/index.ts +0 -6
- package/src/testing/proto/gen/schema.ts +0 -49
- package/src/testing/proto/index.ts +0 -5
- package/src/testing/proto/schema.proto +0 -15
- package/src/testing/replicator.ts +0 -184
- /package/dist/types/src/extensions/{code.d.ts → markdown/code.d.ts} +0 -0
- /package/dist/types/src/extensions/{hr.d.ts → markdown/hr.d.ts} +0 -0
- /package/dist/types/src/extensions/{image.d.ts → markdown/image.d.ts} +0 -0
- /package/dist/types/src/extensions/{link.d.ts → markdown/link.d.ts} +0 -0
- /package/dist/types/src/extensions/{table.d.ts → markdown/table.d.ts} +0 -0
- /package/dist/types/src/extensions/{tasklist.d.ts → markdown/tasklist.d.ts} +0 -0
- /package/src/extensions/{image.ts → markdown/image.ts} +0 -0
- /package/src/extensions/{table.ts → markdown/table.ts} +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export type HeadingLevel = 1 | 2 | 3 | 4 | 5 | 6;
|
|
2
|
-
export declare const headings: Record<HeadingLevel, string
|
|
3
|
-
export declare const heading: (level: HeadingLevel
|
|
2
|
+
export declare const headings: Record<HeadingLevel, string>;
|
|
3
|
+
export declare const heading: (level: HeadingLevel) => string;
|
|
4
4
|
export declare const text = "text-neutral-800 dark:text-neutral-200";
|
|
5
5
|
export declare const light = "text-neutral-200 dark:text-neutral-800";
|
|
6
6
|
export declare const mark: string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../../src/styles/markdown.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAIjD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"markdown.d.ts","sourceRoot":"","sources":["../../../../src/styles/markdown.ts"],"names":[],"mappings":"AAMA,MAAM,MAAM,YAAY,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;AAIjD,eAAO,MAAM,QAAQ,EAAE,MAAM,CAAC,YAAY,EAAE,MAAM,CAOjD,CAAC;AAEF,eAAO,MAAM,OAAO,UAAW,YAAY,WAE1C,CAAC;AAEF,eAAO,MAAM,IAAI,2CAA2C,CAAC;AAC7D,eAAO,MAAM,KAAK,2CAA2C,CAAC;AAE9D,eAAO,MAAM,IAAI,QAAmE,CAAC;AAErF,eAAO,MAAM,SAAS,UAAU,CAAC;AAEjC,eAAO,MAAM,IAAI,cAAc,CAAC;AAChC,eAAO,MAAM,MAAM,WAAW,CAAC;AAC/B,eAAO,MAAM,aAAa,iBAAiB,CAAC;AAE5C,eAAO,MAAM,IAAI,mEAAmE,CAAC;AACrF,eAAO,MAAM,QAAQ,+BAA+B,CAAC;AACrD,eAAO,MAAM,SAAS,kDAAkD,CAAC;AAEzE,eAAO,MAAM,SAAS,QAAmB,CAAC;AAE1C,eAAO,MAAM,UAAU,QAAsF,CAAC;AAE9G,eAAO,MAAM,cAAc,0GAC8E,CAAC;AAG1G,eAAO,MAAM,aAAa,wHAC6F,CAAC;AACxH,eAAO,MAAM,WAAW,+IACkH,CAAC;AAE3I,eAAO,MAAM,QAAQ,gDAAgD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../src/themes/default.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,WAAW,EAAU,MAAM,WAAW,CAAC;AAKrD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,EAAE,
|
|
1
|
+
{"version":3,"file":"default.d.ts","sourceRoot":"","sources":["../../../../src/themes/default.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,WAAW,EAAU,MAAM,WAAW,CAAC;AAKrD;;;;;;;;;;GAUG;AACH,eAAO,MAAM,YAAY,EAAE,WA+N1B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,WAOvB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,WAO3B,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,WAOvB,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-editor",
|
|
3
|
-
"version": "0.3.11-main.
|
|
3
|
+
"version": "0.3.11-main.514e6e4",
|
|
4
4
|
"description": "Document editing experience within a DXOS shell.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
@@ -35,23 +35,20 @@
|
|
|
35
35
|
"lodash.pick": "^4.4.0",
|
|
36
36
|
"lodash.sortby": "^4.7.0",
|
|
37
37
|
"style-mod": "^4.1.0",
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
-
"
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
52
|
-
"@dxos/react-ui-theme": "0.3.11-main.508f304",
|
|
53
|
-
"@dxos/text-model": "0.3.11-main.508f304",
|
|
54
|
-
"@dxos/util": "0.3.11-main.508f304"
|
|
38
|
+
"@dxos/async": "0.3.11-main.514e6e4",
|
|
39
|
+
"@dxos/context": "0.3.11-main.514e6e4",
|
|
40
|
+
"@dxos/display-name": "0.3.11-main.514e6e4",
|
|
41
|
+
"@dxos/debug": "0.3.11-main.514e6e4",
|
|
42
|
+
"@dxos/echo-schema": "0.3.11-main.514e6e4",
|
|
43
|
+
"@dxos/invariant": "0.3.11-main.514e6e4",
|
|
44
|
+
"@dxos/automerge": "0.3.11-main.514e6e4",
|
|
45
|
+
"@dxos/log": "0.3.11-main.514e6e4",
|
|
46
|
+
"@dxos/protocols": "0.3.11-main.514e6e4",
|
|
47
|
+
"@dxos/react-async": "0.3.11-main.514e6e4",
|
|
48
|
+
"@dxos/react-ui-theme": "0.3.11-main.514e6e4",
|
|
49
|
+
"@dxos/text-model": "0.3.11-main.514e6e4",
|
|
50
|
+
"@dxos/react-ui": "0.3.11-main.514e6e4",
|
|
51
|
+
"@dxos/util": "0.3.11-main.514e6e4"
|
|
55
52
|
},
|
|
56
53
|
"devDependencies": {
|
|
57
54
|
"@automerge/automerge-repo-network-broadcastchannel": "^1.0.19",
|
|
@@ -67,24 +64,24 @@
|
|
|
67
64
|
"deepsignal": "1.4.0-shallow.0",
|
|
68
65
|
"react": "^18.2.0",
|
|
69
66
|
"react-dom": "^18.2.0",
|
|
70
|
-
"@dxos/
|
|
71
|
-
"@dxos/
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/echo-
|
|
74
|
-
"@dxos/react-ui": "0.3.11-main.
|
|
75
|
-
"@dxos/
|
|
76
|
-
"@dxos/
|
|
67
|
+
"@dxos/echo-signals": "0.3.11-main.514e6e4",
|
|
68
|
+
"@dxos/config": "0.3.11-main.514e6e4",
|
|
69
|
+
"@dxos/keyboard": "0.3.11-main.514e6e4",
|
|
70
|
+
"@dxos/echo-typegen": "0.3.11-main.514e6e4",
|
|
71
|
+
"@dxos/react-ui": "0.3.11-main.514e6e4",
|
|
72
|
+
"@dxos/storybook-utils": "0.3.11-main.514e6e4",
|
|
73
|
+
"@dxos/react-client": "0.3.11-main.514e6e4"
|
|
77
74
|
},
|
|
78
75
|
"peerDependencies": {
|
|
79
76
|
"@phosphor-icons/react": "^2.0.5",
|
|
80
77
|
"react": "^18.2.0",
|
|
81
78
|
"react-dom": "^18.2.0",
|
|
82
|
-
"@dxos/react-client": "0.3.11-main.
|
|
79
|
+
"@dxos/react-client": "0.3.11-main.514e6e4"
|
|
83
80
|
},
|
|
84
81
|
"publishConfig": {
|
|
85
82
|
"access": "public"
|
|
86
83
|
},
|
|
87
84
|
"scripts": {
|
|
88
|
-
"
|
|
85
|
+
"test": "true"
|
|
89
86
|
}
|
|
90
87
|
}
|
|
@@ -34,6 +34,7 @@ import {
|
|
|
34
34
|
type CommentsOptions,
|
|
35
35
|
type LinkOptions,
|
|
36
36
|
useComments,
|
|
37
|
+
heading,
|
|
37
38
|
} from '../../extensions';
|
|
38
39
|
import { type Comment, useTextModel } from '../../hooks';
|
|
39
40
|
|
|
@@ -82,7 +83,7 @@ const text = {
|
|
|
82
83
|
'## Code',
|
|
83
84
|
'',
|
|
84
85
|
'```',
|
|
85
|
-
'
|
|
86
|
+
'$ ls -las',
|
|
86
87
|
'```',
|
|
87
88
|
'',
|
|
88
89
|
'```tsx',
|
|
@@ -248,6 +249,7 @@ const defaults = [
|
|
|
248
249
|
onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
|
|
249
250
|
}),
|
|
250
251
|
code(),
|
|
252
|
+
heading(),
|
|
251
253
|
hr(),
|
|
252
254
|
image(),
|
|
253
255
|
link({ onRender: onRenderLink, onHover: onHoverLinkTooltip }),
|
|
@@ -290,11 +292,11 @@ export const Links = {
|
|
|
290
292
|
};
|
|
291
293
|
|
|
292
294
|
export const Code = {
|
|
293
|
-
render: () => <Story text={str(text.code, text.footer)} extensions={[code()]}
|
|
295
|
+
render: () => <Story text={str(text.code, text.footer)} extensions={[code()]} />,
|
|
294
296
|
};
|
|
295
297
|
|
|
296
298
|
export const Image = {
|
|
297
|
-
render: () => <Story text={str(text.image, text.footer)}
|
|
299
|
+
render: () => <Story text={str(text.image, text.footer)} extensions={[image()]} />,
|
|
298
300
|
};
|
|
299
301
|
|
|
300
302
|
export const Lists = {
|
|
@@ -366,7 +368,7 @@ export const Comments = {
|
|
|
366
368
|
'update',
|
|
367
369
|
JSON.stringify({
|
|
368
370
|
comments: state.comments.length,
|
|
369
|
-
active: state.selection.
|
|
371
|
+
active: state.selection.current?.slice(0, 8),
|
|
370
372
|
closest: state.selection.closest?.slice(0, 8),
|
|
371
373
|
}),
|
|
372
374
|
);
|
|
@@ -20,9 +20,9 @@ import React, {
|
|
|
20
20
|
|
|
21
21
|
import { log } from '@dxos/log';
|
|
22
22
|
import { useThemeContext } from '@dxos/react-ui';
|
|
23
|
-
import {
|
|
23
|
+
import { attentionSurface, mx } from '@dxos/react-ui-theme';
|
|
24
24
|
|
|
25
|
-
import { basicBundle, markdownBundle
|
|
25
|
+
import { basicBundle, markdownBundle } from '../../extensions';
|
|
26
26
|
import { type EditorModel } from '../../hooks';
|
|
27
27
|
import { type ThemeStyles } from '../../styles';
|
|
28
28
|
import { defaultTheme, markdownTheme, textTheme } from '../../themes';
|
|
@@ -53,10 +53,10 @@ export type TextEditorSlots = {
|
|
|
53
53
|
|
|
54
54
|
// TODO(burdon): Spellcheck?
|
|
55
55
|
export type TextEditorProps = {
|
|
56
|
-
model: EditorModel;
|
|
56
|
+
model: EditorModel; // TODO(burdon): Optional (e.g., just provide content if readonly).
|
|
57
57
|
readonly?: boolean; // TODO(burdon): Move into model.
|
|
58
|
-
|
|
59
|
-
|
|
58
|
+
autoFocus?: boolean;
|
|
59
|
+
lineWrapping?: boolean;
|
|
60
60
|
scrollTo?: StateEffect<any>; // TODO(burdon): Restore scroll position: scrollTo EditorView.scrollSnapshot().
|
|
61
61
|
selection?: { anchor: number; head?: number };
|
|
62
62
|
editorMode?: EditorMode; // TODO(burdon): Factor out.
|
|
@@ -75,7 +75,7 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
75
75
|
{
|
|
76
76
|
model,
|
|
77
77
|
readonly,
|
|
78
|
-
|
|
78
|
+
autoFocus,
|
|
79
79
|
scrollTo,
|
|
80
80
|
selection,
|
|
81
81
|
editorMode,
|
|
@@ -98,13 +98,10 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
98
98
|
|
|
99
99
|
// Set focus.
|
|
100
100
|
useEffect(() => {
|
|
101
|
-
if (
|
|
101
|
+
if (autoFocus) {
|
|
102
102
|
view?.focus();
|
|
103
103
|
}
|
|
104
|
-
}, [view,
|
|
105
|
-
|
|
106
|
-
// Monitor awareness.
|
|
107
|
-
useAwareness(model);
|
|
104
|
+
}, [view, autoFocus]);
|
|
108
105
|
|
|
109
106
|
// Create editor state and view.
|
|
110
107
|
// The view is recreated if the model or extensions are changed.
|
|
@@ -214,14 +211,14 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
214
211
|
|
|
215
212
|
// TODO(burdon): Single-line/scroll.
|
|
216
213
|
export const TextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
217
|
-
({ readonly, placeholder,
|
|
214
|
+
({ readonly, placeholder, lineWrapping, theme = textTheme, slots, extensions = [], ...props }, forwardedRef) => {
|
|
218
215
|
const { themeMode } = useThemeContext();
|
|
219
216
|
const updatedSlots = defaultsDeep({}, slots, defaultTextSlots);
|
|
220
217
|
return (
|
|
221
218
|
<BaseTextEditor
|
|
222
219
|
ref={forwardedRef}
|
|
223
220
|
readonly={readonly}
|
|
224
|
-
extensions={[basicBundle({ themeMode, placeholder,
|
|
221
|
+
extensions={[basicBundle({ themeMode, placeholder, lineWrapping }), ...extensions]}
|
|
225
222
|
theme={theme}
|
|
226
223
|
slots={updatedSlots}
|
|
227
224
|
{...props}
|
|
@@ -238,7 +235,7 @@ export const MarkdownEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
238
235
|
<BaseTextEditor
|
|
239
236
|
ref={forwardedRef}
|
|
240
237
|
readonly={readonly}
|
|
241
|
-
extensions={[markdownBundle({ themeMode,
|
|
238
|
+
extensions={[markdownBundle({ themeMode, placeholder }), ...extensions]}
|
|
242
239
|
theme={theme}
|
|
243
240
|
slots={updatedSlots}
|
|
244
241
|
{...props}
|
|
@@ -250,7 +247,7 @@ export const MarkdownEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
250
247
|
export const defaultSlots: TextEditorSlots = {
|
|
251
248
|
root: {
|
|
252
249
|
// TODO(burdon): Add focusRing by default/as property?
|
|
253
|
-
className: mx('flex flex-col grow overflow-y-auto',
|
|
250
|
+
className: mx('flex flex-col grow overflow-y-auto', attentionSurface),
|
|
254
251
|
},
|
|
255
252
|
editor: {
|
|
256
253
|
className: 'h-full p-2',
|
|
@@ -153,7 +153,7 @@ const Thread: FC<{
|
|
|
153
153
|
<div ref={containerRef} onClick={() => onSelect()} className='flex'>
|
|
154
154
|
<TextEditor
|
|
155
155
|
ref={editorRef}
|
|
156
|
-
|
|
156
|
+
autoFocus={focus}
|
|
157
157
|
model={model}
|
|
158
158
|
placeholder={'Enter comment...'}
|
|
159
159
|
slots={{ root: { className: 'grow rounded-b' } }}
|
|
@@ -241,7 +241,7 @@ const Story = ({ text, autoCreate }: StoryProps) => {
|
|
|
241
241
|
: [],
|
|
242
242
|
},
|
|
243
243
|
]);
|
|
244
|
-
setSelected(id);
|
|
244
|
+
setSelected(id); // TODO(burdon): Not required.
|
|
245
245
|
return id;
|
|
246
246
|
};
|
|
247
247
|
|
|
@@ -273,8 +273,8 @@ const Story = ({ text, autoCreate }: StoryProps) => {
|
|
|
273
273
|
);
|
|
274
274
|
};
|
|
275
275
|
|
|
276
|
-
const handleSelectComment: CommentsOptions['onSelect'] = ({ comments, selection: {
|
|
277
|
-
log.info('select', { active:
|
|
276
|
+
const handleSelectComment: CommentsOptions['onSelect'] = ({ comments, selection: { current, closest } }) => {
|
|
277
|
+
log.info('select', { active: current?.slice(0, 4), closest: closest?.slice(0, 4) });
|
|
278
278
|
setThreads((threads) =>
|
|
279
279
|
threads.map((thread) => {
|
|
280
280
|
const comment = comments.find(({ comment }) => comment.id === thread.id);
|
|
@@ -287,7 +287,7 @@ const Story = ({ text, autoCreate }: StoryProps) => {
|
|
|
287
287
|
}),
|
|
288
288
|
);
|
|
289
289
|
|
|
290
|
-
setSelected(
|
|
290
|
+
setSelected(current ?? closest);
|
|
291
291
|
};
|
|
292
292
|
|
|
293
293
|
const handleSelectThread = (id: string) => {
|
|
@@ -12,16 +12,11 @@ import {
|
|
|
12
12
|
type ViewUpdate,
|
|
13
13
|
WidgetType,
|
|
14
14
|
} from '@codemirror/view';
|
|
15
|
-
import { useEffect } from 'react';
|
|
16
15
|
|
|
17
16
|
import { Event } from '@dxos/async';
|
|
18
17
|
import { Context } from '@dxos/context';
|
|
19
|
-
import { generateName } from '@dxos/display-name';
|
|
20
|
-
import { useThemeContext } from '@dxos/react-ui';
|
|
21
|
-
import { getColorForValue } from '@dxos/react-ui-theme';
|
|
22
18
|
|
|
23
19
|
import { Cursor, type CursorConverter } from './cursor';
|
|
24
|
-
import { type EditorModel } from '../hooks';
|
|
25
20
|
|
|
26
21
|
export interface AwarenessProvider {
|
|
27
22
|
remoteStateChange: Event<void>;
|
|
@@ -29,8 +24,8 @@ export interface AwarenessProvider {
|
|
|
29
24
|
open(): void;
|
|
30
25
|
close(): void;
|
|
31
26
|
|
|
32
|
-
update(position: AwarenessPosition | undefined): void;
|
|
33
27
|
getRemoteStates(): AwarenessState[];
|
|
28
|
+
update(position: AwarenessPosition | undefined): void;
|
|
34
29
|
}
|
|
35
30
|
|
|
36
31
|
const dummyProvider: AwarenessProvider = {
|
|
@@ -39,8 +34,8 @@ const dummyProvider: AwarenessProvider = {
|
|
|
39
34
|
open: () => {},
|
|
40
35
|
close: () => {},
|
|
41
36
|
|
|
42
|
-
update: () => {},
|
|
43
37
|
getRemoteStates: () => [],
|
|
38
|
+
update: () => {},
|
|
44
39
|
};
|
|
45
40
|
|
|
46
41
|
export const AwarenessProvider = Facet.define<AwarenessProvider, AwarenessProvider>({
|
|
@@ -81,19 +76,6 @@ export const awareness = (provider = dummyProvider): Extension => {
|
|
|
81
76
|
];
|
|
82
77
|
};
|
|
83
78
|
|
|
84
|
-
export const useAwareness = ({ awareness, peer }: EditorModel) => {
|
|
85
|
-
const { themeMode } = useThemeContext();
|
|
86
|
-
useEffect(() => {
|
|
87
|
-
if (awareness && peer) {
|
|
88
|
-
awareness.setLocalStateField('user', {
|
|
89
|
-
name: peer.name ?? generateName(peer.id),
|
|
90
|
-
color: getColorForValue({ value: peer.id, type: 'color' }),
|
|
91
|
-
colorLight: getColorForValue({ value: peer.id, themeMode, type: 'highlight' }),
|
|
92
|
-
});
|
|
93
|
-
}
|
|
94
|
-
}, [awareness, peer, themeMode]);
|
|
95
|
-
};
|
|
96
|
-
|
|
97
79
|
/**
|
|
98
80
|
* Generates selection decorations from remote peers.
|
|
99
81
|
*/
|
|
@@ -268,7 +250,6 @@ class RemoteCaretWidget extends WidgetType {
|
|
|
268
250
|
}
|
|
269
251
|
}
|
|
270
252
|
|
|
271
|
-
// TODO(burdon): Mixed case?
|
|
272
253
|
const styles = EditorView.baseTheme({
|
|
273
254
|
'.cm-collab-selection': {},
|
|
274
255
|
'.cm-collab-selectionLine': {
|
|
@@ -283,38 +264,40 @@ const styles = EditorView.baseTheme({
|
|
|
283
264
|
marginRight: '-1px',
|
|
284
265
|
boxSizing: 'border-box',
|
|
285
266
|
display: 'inline',
|
|
267
|
+
cursor: 'pointer',
|
|
286
268
|
},
|
|
287
269
|
'.cm-collab-selectionCaretDot': {
|
|
288
270
|
borderRadius: '50%',
|
|
289
271
|
position: 'absolute',
|
|
290
|
-
width: '.
|
|
291
|
-
height: '.
|
|
292
|
-
top: '-.
|
|
293
|
-
left: '-.
|
|
272
|
+
width: '.5em',
|
|
273
|
+
height: '.5em',
|
|
274
|
+
top: '-.25em',
|
|
275
|
+
left: '-.25em',
|
|
294
276
|
backgroundColor: 'inherit',
|
|
295
277
|
transition: 'transform .3s ease-in-out',
|
|
296
278
|
boxSizing: 'border-box',
|
|
297
279
|
},
|
|
298
280
|
'.cm-collab-selectionCaret:hover > .cm-collab-selectionCaretDot': {
|
|
299
|
-
transformOrigin: 'bottom center',
|
|
300
281
|
transform: 'scale(0)',
|
|
282
|
+
transformOrigin: 'center',
|
|
301
283
|
},
|
|
302
284
|
'.cm-collab-selectionInfo': {
|
|
303
285
|
position: 'absolute',
|
|
304
|
-
|
|
305
|
-
|
|
286
|
+
transform: 'translate(-50%, 0)',
|
|
287
|
+
top: '-20px',
|
|
288
|
+
left: 0,
|
|
306
289
|
fontSize: '.75em',
|
|
307
|
-
fontFamily: 'serif',
|
|
290
|
+
fontFamily: 'sans-serif',
|
|
308
291
|
fontStyle: 'normal',
|
|
309
292
|
fontWeight: 'normal',
|
|
310
293
|
lineHeight: 'normal',
|
|
311
294
|
userSelect: 'none',
|
|
312
295
|
color: 'white',
|
|
313
|
-
|
|
314
|
-
paddingRight: '2px',
|
|
296
|
+
padding: '2px',
|
|
315
297
|
zIndex: 101,
|
|
316
298
|
transition: 'opacity .3s ease-in-out',
|
|
317
299
|
backgroundColor: 'inherit',
|
|
300
|
+
borderRadius: '2px',
|
|
318
301
|
// These should be separate.
|
|
319
302
|
opacity: 0,
|
|
320
303
|
transitionDelay: '0s',
|
package/src/extensions/basic.ts
CHANGED
|
@@ -15,14 +15,14 @@ import { type TextEditorProps } from '../components';
|
|
|
15
15
|
|
|
16
16
|
export type BasicBundleOptions = {
|
|
17
17
|
themeMode?: ThemeMode;
|
|
18
|
-
} & Pick<TextEditorProps, 'placeholder' | '
|
|
18
|
+
} & Pick<TextEditorProps, 'placeholder' | 'lineWrapping'>;
|
|
19
19
|
|
|
20
20
|
export const basicBundle = ({
|
|
21
21
|
themeMode,
|
|
22
22
|
placeholder: _placeholder,
|
|
23
|
-
|
|
23
|
+
lineWrapping = true,
|
|
24
24
|
}: BasicBundleOptions): Extension[] => [
|
|
25
|
-
|
|
25
|
+
lineWrapping ? EditorView.lineWrapping : [],
|
|
26
26
|
|
|
27
27
|
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
28
28
|
bracketMatching(),
|
|
@@ -21,14 +21,14 @@ const styles = EditorView.baseTheme({
|
|
|
21
21
|
'& .cm-comment': {
|
|
22
22
|
backgroundColor: getToken('extend.colors.yellow.50'),
|
|
23
23
|
},
|
|
24
|
-
'& .cm-comment-
|
|
24
|
+
'& .cm-comment-current': {
|
|
25
25
|
backgroundColor: getToken('extend.colors.yellow.100'),
|
|
26
26
|
},
|
|
27
27
|
});
|
|
28
28
|
|
|
29
29
|
const marks = {
|
|
30
30
|
highlight: Decoration.mark({ class: 'cm-comment' }),
|
|
31
|
-
highlightActive: Decoration.mark({ class: 'cm-comment-
|
|
31
|
+
highlightActive: Decoration.mark({ class: 'cm-comment-current' }),
|
|
32
32
|
};
|
|
33
33
|
|
|
34
34
|
type CommentState = {
|
|
@@ -38,7 +38,7 @@ type CommentState = {
|
|
|
38
38
|
};
|
|
39
39
|
|
|
40
40
|
type SelectionState = {
|
|
41
|
-
|
|
41
|
+
current?: string;
|
|
42
42
|
closest?: string;
|
|
43
43
|
};
|
|
44
44
|
|
|
@@ -60,7 +60,7 @@ export const setFocus = (view: EditorView, id: string, center = true) => {
|
|
|
60
60
|
effects: [
|
|
61
61
|
//
|
|
62
62
|
EditorView.scrollIntoView(range.from, center ? { y: 'center' } : undefined),
|
|
63
|
-
setSelection.of({
|
|
63
|
+
setSelection.of({ current: id }),
|
|
64
64
|
],
|
|
65
65
|
});
|
|
66
66
|
}
|
|
@@ -117,7 +117,7 @@ const commentsState = StateField.define<CommentsState>({
|
|
|
117
117
|
*/
|
|
118
118
|
const highlightDecorations = EditorView.decorations.compute([commentsState], (state) => {
|
|
119
119
|
const {
|
|
120
|
-
selection: {
|
|
120
|
+
selection: { current },
|
|
121
121
|
comments,
|
|
122
122
|
} = state.field(commentsState);
|
|
123
123
|
|
|
@@ -129,7 +129,7 @@ const highlightDecorations = EditorView.decorations.compute([commentsState], (st
|
|
|
129
129
|
return undefined;
|
|
130
130
|
}
|
|
131
131
|
|
|
132
|
-
if (comment.comment.id ===
|
|
132
|
+
if (comment.comment.id === current) {
|
|
133
133
|
return marks.highlightActive.range(range.from, range.to);
|
|
134
134
|
} else {
|
|
135
135
|
return marks.highlight.range(range.from, range.to);
|
|
@@ -279,7 +279,7 @@ export const comments = (options: CommentsOptions = {}): Extension => {
|
|
|
279
279
|
if (id) {
|
|
280
280
|
// Update range.
|
|
281
281
|
view.dispatch({
|
|
282
|
-
effects: setSelection.of({
|
|
282
|
+
effects: setSelection.of({ current: id }),
|
|
283
283
|
selection: { anchor: from },
|
|
284
284
|
});
|
|
285
285
|
|
|
@@ -371,10 +371,10 @@ export const comments = (options: CommentsOptions = {}): Extension => {
|
|
|
371
371
|
//
|
|
372
372
|
// Track selection/proximity.
|
|
373
373
|
//
|
|
374
|
-
EditorView.updateListener.of(({ view, state
|
|
374
|
+
EditorView.updateListener.of(({ view, state }) => {
|
|
375
375
|
let min = Infinity;
|
|
376
376
|
const {
|
|
377
|
-
selection: {
|
|
377
|
+
selection: { current, closest },
|
|
378
378
|
comments,
|
|
379
379
|
} = state.field(commentsState);
|
|
380
380
|
|
|
@@ -382,11 +382,11 @@ export const comments = (options: CommentsOptions = {}): Extension => {
|
|
|
382
382
|
const selection: SelectionState = {};
|
|
383
383
|
comments.forEach(({ comment, range }) => {
|
|
384
384
|
if (head >= range.from && head <= range.to) {
|
|
385
|
-
selection.
|
|
385
|
+
selection.current = comment.id;
|
|
386
386
|
selection.closest = undefined;
|
|
387
387
|
}
|
|
388
388
|
|
|
389
|
-
if (!selection.
|
|
389
|
+
if (!selection.current) {
|
|
390
390
|
const d = Math.min(Math.abs(head - range.from), Math.abs(head - range.to));
|
|
391
391
|
if (d < min) {
|
|
392
392
|
selection.closest = comment.id;
|
|
@@ -395,7 +395,7 @@ export const comments = (options: CommentsOptions = {}): Extension => {
|
|
|
395
395
|
}
|
|
396
396
|
});
|
|
397
397
|
|
|
398
|
-
if (selection.
|
|
398
|
+
if (selection.current !== current || selection.closest !== closest) {
|
|
399
399
|
view.dispatch({ effects: setSelection.of(selection) });
|
|
400
400
|
|
|
401
401
|
// Update callback.
|
|
@@ -415,11 +415,11 @@ export const comments = (options: CommentsOptions = {}): Extension => {
|
|
|
415
415
|
};
|
|
416
416
|
|
|
417
417
|
/**
|
|
418
|
-
* Update state field.
|
|
418
|
+
* Update comments state field.
|
|
419
419
|
*/
|
|
420
|
-
export const useComments = (view
|
|
420
|
+
export const useComments = (view: EditorView | null, comments: Comment[] = []) => {
|
|
421
421
|
useEffect(() => {
|
|
422
|
-
if (view
|
|
422
|
+
if (view) {
|
|
423
423
|
view.dispatch({
|
|
424
424
|
effects: setComments.of(comments),
|
|
425
425
|
});
|
package/src/extensions/index.ts
CHANGED
|
@@ -7,17 +7,10 @@ export * from './automerge';
|
|
|
7
7
|
export * from './awareness';
|
|
8
8
|
export * from './basic';
|
|
9
9
|
export * from './blast';
|
|
10
|
-
export * from './code';
|
|
11
10
|
export * from './comments';
|
|
12
11
|
export * from './cursor';
|
|
13
|
-
export * from './hr';
|
|
14
|
-
export * from './image';
|
|
15
|
-
export * from './link';
|
|
16
12
|
export * from './listener';
|
|
17
13
|
export * from './markdown';
|
|
18
14
|
export * from './mention';
|
|
19
15
|
export * from './outliner';
|
|
20
|
-
export * from './table';
|
|
21
|
-
export * from './tasklist';
|
|
22
16
|
export * from './typewriter';
|
|
23
|
-
export * from './yjs';
|
|
@@ -27,7 +27,7 @@ import { type TextEditorProps } from '../../components';
|
|
|
27
27
|
|
|
28
28
|
export type MarkdownBundleOptions = {
|
|
29
29
|
themeMode?: ThemeMode;
|
|
30
|
-
} & Pick<TextEditorProps, '
|
|
30
|
+
} & Pick<TextEditorProps, 'placeholder'>;
|
|
31
31
|
|
|
32
32
|
/**
|
|
33
33
|
* Markdown bundle.
|
|
@@ -36,11 +36,7 @@ export type MarkdownBundleOptions = {
|
|
|
36
36
|
* https://codemirror.net/docs/ref/#codemirror.basicSetup
|
|
37
37
|
*/
|
|
38
38
|
// TODO(burdon): Add Composer here: https://codemirror.net/docs/community
|
|
39
|
-
export const markdownBundle = ({
|
|
40
|
-
readonly,
|
|
41
|
-
themeMode,
|
|
42
|
-
placeholder: _placeholder,
|
|
43
|
-
}: MarkdownBundleOptions): Extension[] => {
|
|
39
|
+
export const markdownBundle = ({ themeMode, placeholder: _placeholder }: MarkdownBundleOptions): Extension[] => {
|
|
44
40
|
return [
|
|
45
41
|
EditorState.allowMultipleSelections.of(true),
|
|
46
42
|
EditorState.tabSize.of(2),
|
|
@@ -82,7 +78,7 @@ export const markdownBundle = ({
|
|
|
82
78
|
themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
|
|
83
79
|
|
|
84
80
|
// Custom styles.
|
|
85
|
-
syntaxHighlighting(markdownHighlightStyle(
|
|
81
|
+
syntaxHighlighting(markdownHighlightStyle()),
|
|
86
82
|
|
|
87
83
|
keymap.of([
|
|
88
84
|
// https://codemirror.net/docs/ref/#commands.indentWithTab
|