@dxos/react-ui-editor 0.3.11-main.73ee990 → 0.3.11-main.764a9c1
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 +1649 -234
- 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 +1 -2
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/{comments.stories.d.ts → hooks.stories.d.ts} +9 -12
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +27 -7
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +12 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/index.d.ts +2 -0
- package/dist/types/src/components/Toolbar/index.d.ts.map +1 -0
- package/dist/types/src/components/index.d.ts +1 -0
- package/dist/types/src/components/index.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.spec.d.ts +2 -0
- package/dist/types/src/extensions/automerge/automerge.spec.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/automerge.test.d.ts +2 -0
- package/dist/types/src/extensions/automerge/automerge.test.d.ts.map +1 -0
- package/dist/types/src/extensions/automerge/defs.d.ts +5 -5
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/semaphore.d.ts +2 -1
- package/dist/types/src/extensions/automerge/semaphore.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/update-automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/awareness.d.ts +1 -1
- package/dist/types/src/extensions/basic.d.ts +1 -1
- package/dist/types/src/extensions/basic.d.ts.map +1 -1
- package/dist/types/src/extensions/comments.d.ts +6 -2
- package/dist/types/src/extensions/comments.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 -1
- package/dist/types/src/extensions/markdown/formatting.d.ts +55 -8
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/formatting.test.d.ts +3 -0
- package/dist/types/src/extensions/markdown/formatting.test.d.ts.map +1 -0
- package/dist/types/src/hooks/index.d.ts +1 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useActionHandler.d.ts +2 -2
- package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -1
- package/dist/types/src/hooks/useEditorView.d.ts +17 -0
- package/dist/types/src/hooks/useEditorView.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextEditor.d.ts +36 -14
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +12 -0
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +39 -26
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +5 -6
- package/src/components/TextEditor/TextEditor.tsx +26 -16
- package/src/components/TextEditor/automerge.stories.tsx +1 -2
- package/src/components/TextEditor/hooks.stories.tsx +111 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +22 -6
- package/src/components/Toolbar/Toolbar.tsx +224 -75
- package/src/components/Toolbar/index.ts +5 -0
- package/src/components/index.ts +1 -0
- package/src/extensions/automerge/automerge.spec.tsx +76 -0
- package/src/extensions/automerge/automerge.test.ts +13 -0
- package/src/extensions/automerge/automerge.ts +27 -11
- package/src/extensions/automerge/cursor.ts +3 -3
- package/src/extensions/automerge/defs.ts +9 -9
- package/src/extensions/automerge/semaphore.ts +17 -19
- package/src/extensions/automerge/update-automerge.ts +9 -9
- package/src/extensions/automerge/update-codemirror.ts +5 -5
- package/src/extensions/awareness.ts +7 -4
- package/src/extensions/basic.ts +15 -13
- package/src/extensions/blast.ts +4 -1
- package/src/extensions/comments.ts +84 -30
- package/src/extensions/markdown/bundle.ts +10 -5
- package/src/extensions/markdown/code.ts +12 -4
- package/src/extensions/markdown/formatting.test.ts +482 -0
- package/src/extensions/markdown/formatting.ts +1133 -55
- package/src/extensions/markdown/link.ts +8 -2
- package/src/hooks/index.ts +1 -0
- package/src/hooks/useActionHandler.ts +61 -13
- package/src/hooks/useEditorView.ts +29 -0
- package/src/hooks/useTextEditor.ts +143 -19
- package/src/hooks/useTextModel.ts +28 -9
- package/src/index.ts +1 -1
- package/src/themes/default.ts +10 -5
- package/dist/types/src/components/TextEditor/comments.stories.d.ts.map +0 -1
- package/src/components/TextEditor/comments.stories.tsx +0 -357
|
@@ -91,7 +91,10 @@ export const link = (options: LinkOptions = {}): Extension => {
|
|
|
91
91
|
};
|
|
92
92
|
|
|
93
93
|
class LinkButton extends WidgetType {
|
|
94
|
-
constructor(
|
|
94
|
+
constructor(
|
|
95
|
+
private readonly _url: string,
|
|
96
|
+
private readonly _onAttach: LinkOptions['onRender'],
|
|
97
|
+
) {
|
|
95
98
|
super();
|
|
96
99
|
}
|
|
97
100
|
|
|
@@ -107,7 +110,10 @@ class LinkButton extends WidgetType {
|
|
|
107
110
|
}
|
|
108
111
|
|
|
109
112
|
class LinkText extends WidgetType {
|
|
110
|
-
constructor(
|
|
113
|
+
constructor(
|
|
114
|
+
private readonly _text: string,
|
|
115
|
+
private readonly _url?: string,
|
|
116
|
+
) {
|
|
111
117
|
super();
|
|
112
118
|
}
|
|
113
119
|
|
package/src/hooks/index.ts
CHANGED
|
@@ -4,32 +4,78 @@
|
|
|
4
4
|
|
|
5
5
|
import type { EditorView } from '@codemirror/view';
|
|
6
6
|
|
|
7
|
-
import type { ToolbarProps } from '../components
|
|
8
|
-
import {
|
|
7
|
+
import type { ToolbarProps } from '../components';
|
|
8
|
+
import {
|
|
9
|
+
createComment,
|
|
10
|
+
insertTable,
|
|
11
|
+
setHeading,
|
|
12
|
+
setStyle,
|
|
13
|
+
toggleStyle,
|
|
14
|
+
addLink,
|
|
15
|
+
removeLink,
|
|
16
|
+
Inline,
|
|
17
|
+
List,
|
|
18
|
+
addList,
|
|
19
|
+
removeList,
|
|
20
|
+
toggleList,
|
|
21
|
+
addBlockquote,
|
|
22
|
+
removeBlockquote,
|
|
23
|
+
addCodeblock,
|
|
24
|
+
removeCodeblock,
|
|
25
|
+
toggleBlockquote,
|
|
26
|
+
} from '../extensions';
|
|
9
27
|
|
|
10
|
-
export const useActionHandler = (view
|
|
28
|
+
export const useActionHandler = (view?: EditorView | null): ToolbarProps['onAction'] => {
|
|
11
29
|
return (action) => {
|
|
12
30
|
if (!view) {
|
|
13
31
|
return;
|
|
14
32
|
}
|
|
15
33
|
|
|
34
|
+
let inlineType, listType;
|
|
16
35
|
switch (action.type) {
|
|
17
36
|
case 'heading':
|
|
18
37
|
setHeading(parseInt(action.data))(view);
|
|
19
38
|
break;
|
|
20
39
|
|
|
21
|
-
case '
|
|
22
|
-
|
|
40
|
+
case 'strong':
|
|
41
|
+
case 'emphasis':
|
|
42
|
+
case 'strikethrough':
|
|
43
|
+
case 'code':
|
|
44
|
+
inlineType =
|
|
45
|
+
action.type === 'strong'
|
|
46
|
+
? Inline.Strong
|
|
47
|
+
: action.type === 'emphasis'
|
|
48
|
+
? Inline.Emphasis
|
|
49
|
+
: action.type === 'strikethrough'
|
|
50
|
+
? Inline.Strikethrough
|
|
51
|
+
: Inline.Code;
|
|
52
|
+
(typeof action.data === 'boolean' ? setStyle(inlineType, action.data) : toggleStyle(inlineType))(view);
|
|
23
53
|
break;
|
|
24
|
-
|
|
25
|
-
|
|
54
|
+
|
|
55
|
+
case 'list-ordered':
|
|
56
|
+
case 'list-bullet':
|
|
57
|
+
case 'list-tasks':
|
|
58
|
+
listType =
|
|
59
|
+
action.type === 'list-ordered' ? List.Ordered : action.type === 'list-bullet' ? List.Bullet : List.Task;
|
|
60
|
+
(action.data === false
|
|
61
|
+
? removeList(listType)
|
|
62
|
+
: action.data === true
|
|
63
|
+
? addList(listType)
|
|
64
|
+
: toggleList(listType))(view);
|
|
26
65
|
break;
|
|
27
|
-
|
|
28
|
-
|
|
66
|
+
|
|
67
|
+
case 'blockquote':
|
|
68
|
+
(action.data === false ? removeBlockquote : action.data === true ? addBlockquote : toggleBlockquote)(view);
|
|
69
|
+
break;
|
|
70
|
+
case 'codeblock':
|
|
71
|
+
(action.data === false ? removeCodeblock : addCodeblock)(view);
|
|
72
|
+
break;
|
|
73
|
+
case 'table':
|
|
74
|
+
insertTable(view);
|
|
29
75
|
break;
|
|
30
76
|
|
|
31
|
-
case '
|
|
32
|
-
|
|
77
|
+
case 'link':
|
|
78
|
+
(action.data === false ? removeLink : addLink)(view);
|
|
33
79
|
break;
|
|
34
80
|
|
|
35
81
|
case 'comment':
|
|
@@ -37,9 +83,11 @@ export const useActionHandler = (view: EditorView | null): ToolbarProps['onActio
|
|
|
37
83
|
break;
|
|
38
84
|
}
|
|
39
85
|
|
|
40
|
-
// TODO(burdon): Hack
|
|
86
|
+
// TODO(burdon): Hack otherwise remains on heading selector.
|
|
41
87
|
setTimeout(() => {
|
|
42
|
-
view.
|
|
88
|
+
if (!view.hasFocus) {
|
|
89
|
+
view.focus();
|
|
90
|
+
}
|
|
43
91
|
});
|
|
44
92
|
};
|
|
45
93
|
};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import { type EditorView } from '@codemirror/view';
|
|
6
|
+
import { type RefCallback, useState } from 'react';
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Hook for accessing the editor view.
|
|
10
|
+
*
|
|
11
|
+
* ```tsx
|
|
12
|
+
* const Test = () => {
|
|
13
|
+
* const [editorRef, editorView] = useEditorView();
|
|
14
|
+
* useEffect(() => {
|
|
15
|
+
* editorView?.focus();
|
|
16
|
+
* }, [editorView]);
|
|
17
|
+
* return <TextEditor ref={editorRef} />;
|
|
18
|
+
* };
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
export const useEditorView = (): [RefCallback<EditorView | null>, EditorView | null] => {
|
|
22
|
+
const [view, setView] = useState<EditorView | null>(null);
|
|
23
|
+
return [
|
|
24
|
+
(ref: EditorView | null) => {
|
|
25
|
+
setView(ref);
|
|
26
|
+
},
|
|
27
|
+
view,
|
|
28
|
+
];
|
|
29
|
+
};
|
|
@@ -2,28 +2,152 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
-
import {
|
|
6
|
-
|
|
5
|
+
import {
|
|
6
|
+
EditorSelection,
|
|
7
|
+
EditorState,
|
|
8
|
+
type EditorStateConfig,
|
|
9
|
+
type Extension,
|
|
10
|
+
type StateEffect,
|
|
11
|
+
} from '@codemirror/state';
|
|
12
|
+
import { EditorView } from '@codemirror/view';
|
|
13
|
+
import { type RefObject, useEffect, useRef, useState } from 'react';
|
|
14
|
+
|
|
15
|
+
import { log } from '@dxos/log';
|
|
16
|
+
import { type ThemeMode } from '@dxos/react-ui';
|
|
17
|
+
import { isNotFalsy } from '@dxos/util';
|
|
18
|
+
|
|
19
|
+
import { type ThemeStyles } from '..//styles';
|
|
20
|
+
import { defaultTheme } from '../themes';
|
|
21
|
+
import { logChanges } from '../util';
|
|
22
|
+
|
|
23
|
+
export type UseTextEditorOptions = {
|
|
24
|
+
autoFocus?: boolean;
|
|
25
|
+
scrollTo?: StateEffect<any>;
|
|
26
|
+
debug?: boolean;
|
|
27
|
+
} & EditorStateConfig;
|
|
28
|
+
|
|
29
|
+
export type UseTextEditor = {
|
|
30
|
+
parentRef: RefObject<HTMLDivElement>;
|
|
31
|
+
view?: EditorView;
|
|
32
|
+
};
|
|
7
33
|
|
|
8
34
|
/**
|
|
9
|
-
* Hook for
|
|
10
|
-
*
|
|
11
|
-
* ```tsx
|
|
12
|
-
* const Test = () => {
|
|
13
|
-
* const [editorRef, editorView] = useTextEditor();
|
|
14
|
-
* useEffect(() => {
|
|
15
|
-
* editorView?.focus();
|
|
16
|
-
* }, [editorView]);
|
|
17
|
-
* return <TextEditor ref={editorRef} />;
|
|
18
|
-
* };
|
|
19
|
-
* ```
|
|
35
|
+
* Hook for creating editor.
|
|
20
36
|
*/
|
|
21
|
-
export const useTextEditor = (
|
|
22
|
-
|
|
37
|
+
export const useTextEditor = ({
|
|
38
|
+
autoFocus,
|
|
39
|
+
scrollTo,
|
|
40
|
+
debug,
|
|
41
|
+
doc,
|
|
42
|
+
selection,
|
|
43
|
+
extensions,
|
|
44
|
+
}: UseTextEditorOptions = {}): UseTextEditor => {
|
|
45
|
+
const onUpdate = useRef<() => void>();
|
|
46
|
+
const [view, setView] = useState<EditorView>();
|
|
47
|
+
const parentRef = useRef<HTMLDivElement>(null);
|
|
48
|
+
useEffect(() => {
|
|
49
|
+
if (parentRef.current) {
|
|
50
|
+
// https://codemirror.net/docs/ref/#state.EditorStateConfig
|
|
51
|
+
const state = EditorState.create({
|
|
52
|
+
doc,
|
|
53
|
+
selection,
|
|
54
|
+
extensions: [
|
|
55
|
+
// TODO(burdon): Doesn't catch errors in keymap functions.
|
|
56
|
+
EditorView.exceptionSink.of((err) => {
|
|
57
|
+
log.catch(err);
|
|
58
|
+
}),
|
|
59
|
+
extensions,
|
|
60
|
+
EditorView.updateListener.of(() => {
|
|
61
|
+
onUpdate.current?.();
|
|
62
|
+
}),
|
|
63
|
+
].filter(isNotFalsy),
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
// https://codemirror.net/docs/ref/#view.EditorViewConfig
|
|
67
|
+
const view = new EditorView({
|
|
68
|
+
parent: parentRef.current,
|
|
69
|
+
scrollTo,
|
|
70
|
+
state,
|
|
71
|
+
// NOTE: Uncomment to debug/monitor all transactions.
|
|
72
|
+
// https://codemirror.net/docs/ref/#view.EditorView.dispatch
|
|
73
|
+
dispatchTransactions: (trs, view) => {
|
|
74
|
+
if (debug) {
|
|
75
|
+
logChanges(trs);
|
|
76
|
+
}
|
|
77
|
+
view.update(trs);
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
|
|
81
|
+
setView(view);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return () => {
|
|
85
|
+
view?.destroy();
|
|
86
|
+
};
|
|
87
|
+
}, [parentRef]);
|
|
88
|
+
|
|
89
|
+
useEffect(() => {
|
|
90
|
+
if (view) {
|
|
91
|
+
// Select end of line if not specified.
|
|
92
|
+
if (!selection && !view.state.selection.main.anchor) {
|
|
93
|
+
selection = EditorSelection.single(view.state.doc.line(1).to);
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
// Set selection after first update (since content may rerender on focus).
|
|
97
|
+
// TODO(burdon): BUG on first render may appear in middle of formatted heading.
|
|
98
|
+
// TODO(burdon): Make invisible until first render?
|
|
99
|
+
if (selection || scrollTo) {
|
|
100
|
+
onUpdate.current = () => {
|
|
101
|
+
onUpdate.current = undefined;
|
|
102
|
+
view.dispatch({ selection, effects: scrollTo && [scrollTo], scrollIntoView: !scrollTo });
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
if (autoFocus) {
|
|
107
|
+
view.focus();
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}, [view, autoFocus, selection, scrollTo]);
|
|
111
|
+
|
|
112
|
+
return { parentRef, view };
|
|
113
|
+
};
|
|
114
|
+
|
|
115
|
+
// TODO(burdon): Factor out extension factories.
|
|
116
|
+
|
|
117
|
+
export type DataExtensionsOptions = {
|
|
118
|
+
readonly?: boolean;
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
// TODO(burdon): Pass in TextObject (remove model).
|
|
122
|
+
export const createDataExtensions = ({ readonly = false } = {}): Extension => {
|
|
23
123
|
return [
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
view,
|
|
124
|
+
//
|
|
125
|
+
EditorState.readOnly.of(readonly),
|
|
126
|
+
EditorView.editable.of(!readonly),
|
|
28
127
|
];
|
|
29
128
|
};
|
|
129
|
+
|
|
130
|
+
export type ThemeExtensionsOptions = {
|
|
131
|
+
theme?: ThemeStyles;
|
|
132
|
+
themeMode?: ThemeMode;
|
|
133
|
+
lineWrap?: boolean;
|
|
134
|
+
slots?: {
|
|
135
|
+
editor?: {
|
|
136
|
+
className?: string;
|
|
137
|
+
};
|
|
138
|
+
content?: {
|
|
139
|
+
className?: string;
|
|
140
|
+
};
|
|
141
|
+
};
|
|
142
|
+
};
|
|
143
|
+
|
|
144
|
+
export const createThemeExtensions = ({ theme, themeMode, slots }: ThemeExtensionsOptions = {}): Extension => {
|
|
145
|
+
return [
|
|
146
|
+
//
|
|
147
|
+
EditorView.baseTheme(defaultTheme),
|
|
148
|
+
theme && EditorView.theme(theme),
|
|
149
|
+
EditorView.darkTheme.of(themeMode === 'dark'),
|
|
150
|
+
EditorView.editorAttributes.of({ class: slots?.editor?.className ?? '' }),
|
|
151
|
+
EditorView.contentAttributes.of({ class: slots?.content?.className ?? '' }),
|
|
152
|
+
].filter(isNotFalsy);
|
|
153
|
+
};
|
|
@@ -3,18 +3,17 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import get from 'lodash.get';
|
|
6
|
-
import { useEffect, useState } from 'react';
|
|
6
|
+
import { type Dispatch, type SetStateAction, useEffect, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { generateName } from '@dxos/display-name';
|
|
9
9
|
import { type AutomergeTextCompat, getRawDoc } from '@dxos/echo-schema';
|
|
10
10
|
import { invariant } from '@dxos/invariant';
|
|
11
11
|
import { isAutomergeObject, type Space, type TextObject } from '@dxos/react-client/echo';
|
|
12
12
|
import { type Identity } from '@dxos/react-client/halo';
|
|
13
|
-
import { isNotNullOrUndefined } from '@dxos/util';
|
|
14
13
|
|
|
15
14
|
import { SpaceAwarenessProvider } from './awareness-provider';
|
|
16
15
|
import { type EditorModel, modelState } from './defs';
|
|
17
|
-
import { automerge, awareness
|
|
16
|
+
import { automerge, awareness } from '../extensions';
|
|
18
17
|
import { cursorColor } from '../styles';
|
|
19
18
|
|
|
20
19
|
// TODO(burdon): Remove space/identity dependency. Define interface for the framework re content and presence.
|
|
@@ -31,6 +30,22 @@ export const useTextModel = (props: UseTextModelProps): EditorModel | undefined
|
|
|
31
30
|
return model;
|
|
32
31
|
};
|
|
33
32
|
|
|
33
|
+
/**
|
|
34
|
+
* For use primarily in stories & tests so the dependence on TextObject can be avoided.
|
|
35
|
+
* @param id
|
|
36
|
+
* @param defaultContent
|
|
37
|
+
*/
|
|
38
|
+
export const useInMemoryTextModel = ({
|
|
39
|
+
id,
|
|
40
|
+
defaultContent,
|
|
41
|
+
}: {
|
|
42
|
+
id: string;
|
|
43
|
+
defaultContent?: string;
|
|
44
|
+
}): EditorModel & { setContent: Dispatch<SetStateAction<string>> } => {
|
|
45
|
+
const [content, setContent] = useState(defaultContent ?? '');
|
|
46
|
+
return { id, content, setContent, text: () => content };
|
|
47
|
+
};
|
|
48
|
+
|
|
34
49
|
const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
35
50
|
invariant(isAutomergeObject(text));
|
|
36
51
|
const obj = text as any as AutomergeTextCompat;
|
|
@@ -49,16 +64,20 @@ const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
|
49
64
|
peerId: identity?.identityKey.toHex() ?? 'Anonymous',
|
|
50
65
|
});
|
|
51
66
|
|
|
67
|
+
const extensions = [
|
|
68
|
+
//
|
|
69
|
+
modelState.init(() => model),
|
|
70
|
+
automerge({ handle: doc.handle, path: doc.path }),
|
|
71
|
+
];
|
|
72
|
+
if (awarenessProvider) {
|
|
73
|
+
extensions.push(awareness(awarenessProvider));
|
|
74
|
+
}
|
|
75
|
+
|
|
52
76
|
const model: EditorModel = {
|
|
53
77
|
id: obj.id,
|
|
54
78
|
content: doc,
|
|
55
79
|
text: () => get(doc.handle.docSync(), doc.path),
|
|
56
|
-
extension:
|
|
57
|
-
modelState.init(() => model),
|
|
58
|
-
automerge({ handle: doc.handle, path: doc.path }),
|
|
59
|
-
awarenessProvider && AwarenessProvider.of(awarenessProvider),
|
|
60
|
-
awareness(),
|
|
61
|
-
].filter(isNotNullOrUndefined),
|
|
80
|
+
extension: extensions,
|
|
62
81
|
peer: identity
|
|
63
82
|
? {
|
|
64
83
|
id: identity.identityKey.toHex(),
|
package/src/index.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
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
|
+
export { type EditorView, keymap } from '@codemirror/view';
|
|
9
9
|
|
|
10
10
|
export * from './components';
|
|
11
11
|
export * from './extensions';
|
package/src/themes/default.ts
CHANGED
|
@@ -49,9 +49,11 @@ export const defaultTheme: ThemeStyles = {
|
|
|
49
49
|
'&.cm-focused': {
|
|
50
50
|
outline: 'none',
|
|
51
51
|
},
|
|
52
|
+
|
|
52
53
|
'.cm-scroller': {
|
|
53
|
-
overflow: 'visible',
|
|
54
|
+
// overflow: 'visible',
|
|
54
55
|
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
56
|
+
lineHeight: 1.4,
|
|
55
57
|
},
|
|
56
58
|
|
|
57
59
|
'.cm-content': {
|
|
@@ -60,11 +62,11 @@ export const defaultTheme: ThemeStyles = {
|
|
|
60
62
|
fontSize: '16px',
|
|
61
63
|
},
|
|
62
64
|
'&light .cm-content': {
|
|
63
|
-
color: get(tokens, 'extend.
|
|
65
|
+
color: get(tokens, 'extend.semanticColors.base.fg.light', 'black'),
|
|
64
66
|
caretColor: 'black',
|
|
65
67
|
},
|
|
66
68
|
'&dark .cm-content': {
|
|
67
|
-
color: get(tokens, 'extend.
|
|
69
|
+
color: get(tokens, 'extend.semanticColors.base.fg.dark', 'white'),
|
|
68
70
|
caretColor: 'white',
|
|
69
71
|
},
|
|
70
72
|
|
|
@@ -77,8 +79,11 @@ export const defaultTheme: ThemeStyles = {
|
|
|
77
79
|
'&dark .cm-cursor, &dark .cm-dropCursor': {
|
|
78
80
|
borderLeft: '2px solid white',
|
|
79
81
|
},
|
|
80
|
-
'.cm-placeholder': {
|
|
81
|
-
|
|
82
|
+
'&light .cm-placeholder': {
|
|
83
|
+
color: get(tokens, 'extend.semanticColors.description.light', 'rgba(0,0,0,.2)'),
|
|
84
|
+
},
|
|
85
|
+
'&dark .cm-placeholder': {
|
|
86
|
+
color: get(tokens, 'extend.semanticColors.description.dark', 'rgba(255,255,255,.2)'),
|
|
82
87
|
},
|
|
83
88
|
|
|
84
89
|
//
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"comments.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/comments.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,EAAE,KAAK,UAAU,EAAU,MAAM,kBAAkB,CAAC;AAG3D,OAAO,KAAwD,MAAM,OAAO,CAAC;AA6M7E,KAAK,UAAU,GAAG;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,UAAU,CAAC,EAAE,OAAO,CAAC;CACtB,CAAC;;;;;mBAoHe,UAAU;;AAJ3B,wBAKE;AAWF,eAAO,MAAM,OAAO;;;;CAInB,CAAC;AAEF,eAAO,MAAM,OAAO;;;;;CAKnB,CAAC"}
|