@dxos/react-ui-editor 0.4.6 → 0.4.7-main.06facb4
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 +970 -740
- 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 +9 -0
- 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 +0 -9
- package/dist/types/src/components/TextEditor/TextEditor.stories.d.ts.map +1 -1
- 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/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/{components/TextEditor → extensions/automerge}/automerge.stories.d.ts +4 -2
- package/dist/types/src/extensions/automerge/automerge.stories.d.ts.map +1 -0
- package/dist/types/src/extensions/command/command.d.ts +10 -0
- package/dist/types/src/extensions/command/command.d.ts.map +1 -0
- package/dist/types/src/extensions/command/hint.d.ts +7 -0
- package/dist/types/src/extensions/command/hint.d.ts.map +1 -0
- package/dist/types/src/extensions/command/index.d.ts +2 -0
- package/dist/types/src/extensions/command/index.d.ts.map +1 -0
- package/dist/types/src/extensions/command/state.d.ts +18 -0
- package/dist/types/src/extensions/command/state.d.ts.map +1 -0
- package/dist/types/src/extensions/cursor-line-margin.d.ts.map +1 -1
- package/dist/types/src/extensions/dnd.d.ts +3 -0
- package/dist/types/src/extensions/dnd.d.ts.map +1 -0
- package/dist/types/src/extensions/index.d.ts +2 -1
- package/dist/types/src/extensions/index.d.ts.map +1 -1
- package/dist/types/src/extensions/listener.d.ts +1 -1
- package/dist/types/src/extensions/listener.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/decorate.d.ts +4 -0
- package/dist/types/src/extensions/markdown/decorate.d.ts.map +1 -1
- package/dist/types/src/extensions/util/dom.d.ts +15 -0
- package/dist/types/src/extensions/util/dom.d.ts.map +1 -0
- package/dist/types/src/hooks/defs.d.ts +5 -11
- package/dist/types/src/hooks/defs.d.ts.map +1 -1
- package/dist/types/src/hooks/useEditorView.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts +20 -5
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/{components/TextEditor/hooks.stories.d.ts → hooks/useTextEditor.stories.d.ts} +1 -3
- package/dist/types/src/hooks/useTextEditor.stories.d.ts.map +1 -0
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/styles/index.d.ts +0 -1
- package/dist/types/src/styles/index.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +25 -25
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +95 -8
- package/src/components/TextEditor/TextEditor.stories.tsx +0 -15
- package/src/components/TextEditor/TextEditor.tsx +13 -6
- package/src/components/TextEditor/index.ts +0 -3
- package/src/components/Toolbar/Toolbar.stories.tsx +2 -1
- package/src/{components/TextEditor → extensions/automerge}/automerge.stories.tsx +32 -37
- package/src/extensions/awareness.ts +3 -3
- package/src/extensions/command/command.ts +35 -0
- package/src/extensions/command/hint.ts +76 -0
- package/src/extensions/command/index.ts +5 -0
- package/src/extensions/command/state.ts +106 -0
- package/src/extensions/cursor-line-margin.ts +2 -1
- package/src/extensions/dnd.ts +15 -0
- package/src/extensions/index.ts +2 -1
- package/src/extensions/listener.ts +3 -3
- package/src/extensions/markdown/bundle.ts +4 -15
- package/src/extensions/markdown/decorate.ts +75 -31
- package/src/extensions/util/dom.ts +36 -0
- package/src/hooks/defs.ts +6 -20
- package/src/hooks/useActionHandler.ts +11 -11
- package/src/hooks/useEditorView.ts +0 -1
- package/src/{components/TextEditor/hooks.stories.tsx → hooks/useTextEditor.stories.tsx} +8 -8
- package/src/hooks/useTextEditor.ts +69 -14
- package/src/hooks/useTextModel.ts +18 -18
- package/src/index.ts +2 -0
- package/src/styles/index.ts +0 -1
- package/src/themes/default.ts +1 -0
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +0 -1
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +0 -1
- package/dist/types/src/extensions/basic.d.ts +0 -9
- package/dist/types/src/extensions/basic.d.ts.map +0 -1
- package/dist/types/src/styles/cursors.d.ts +0 -5
- package/dist/types/src/styles/cursors.d.ts.map +0 -1
- package/src/extensions/basic.ts +0 -41
- package/src/styles/cursors.ts +0 -21
|
@@ -6,23 +6,23 @@ import type { EditorView } from '@codemirror/view';
|
|
|
6
6
|
|
|
7
7
|
import type { ToolbarProps } from '../components';
|
|
8
8
|
import {
|
|
9
|
-
createComment,
|
|
10
|
-
insertTable,
|
|
11
|
-
setHeading,
|
|
12
|
-
setStyle,
|
|
13
|
-
toggleStyle,
|
|
14
|
-
addLink,
|
|
15
|
-
removeLink,
|
|
16
9
|
Inline,
|
|
17
10
|
List,
|
|
18
|
-
addList,
|
|
19
|
-
removeList,
|
|
20
|
-
toggleList,
|
|
21
11
|
addBlockquote,
|
|
22
|
-
removeBlockquote,
|
|
23
12
|
addCodeblock,
|
|
13
|
+
addLink,
|
|
14
|
+
addList,
|
|
15
|
+
createComment,
|
|
16
|
+
insertTable,
|
|
17
|
+
removeBlockquote,
|
|
24
18
|
removeCodeblock,
|
|
19
|
+
removeLink,
|
|
20
|
+
removeList,
|
|
21
|
+
setHeading,
|
|
22
|
+
setStyle,
|
|
25
23
|
toggleBlockquote,
|
|
24
|
+
toggleList,
|
|
25
|
+
toggleStyle,
|
|
26
26
|
} from '../extensions';
|
|
27
27
|
|
|
28
28
|
export const useActionHandler = (view?: EditorView | null): ToolbarProps['onAction'] => {
|
|
@@ -21,7 +21,6 @@ import { type MutableRefObject, useRef, useState } from 'react';
|
|
|
21
21
|
* };
|
|
22
22
|
* ```
|
|
23
23
|
*/
|
|
24
|
-
// TODO(burdon): Replace with useTextEditor.
|
|
25
24
|
export const useEditorView = (id: string): [MutableRefObject<EditorView | null>, boolean] => {
|
|
26
25
|
const editorRef = useRef<EditorView | null>(null);
|
|
27
26
|
const [prev, setPrev] = useState<[EditorView | null, string]>([null, '']);
|
|
@@ -10,7 +10,9 @@ import { Toolbar as NaturalToolbar, Select, useThemeContext, Tooltip } from '@dx
|
|
|
10
10
|
import { attentionSurface, mx, textBlockWidth } from '@dxos/react-ui-theme';
|
|
11
11
|
import { withTheme } from '@dxos/storybook-utils';
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import { useActionHandler } from './useActionHandler';
|
|
14
|
+
import { createBasicExtensions, createThemeExtensions, useTextEditor } from './useTextEditor';
|
|
15
|
+
import { Toolbar } from '../components';
|
|
14
16
|
import {
|
|
15
17
|
type EditorMode,
|
|
16
18
|
EditorModes,
|
|
@@ -20,11 +22,9 @@ import {
|
|
|
20
22
|
image,
|
|
21
23
|
table,
|
|
22
24
|
useFormattingState,
|
|
23
|
-
} from '
|
|
24
|
-
import {
|
|
25
|
-
import
|
|
26
|
-
import translations from '../../translations';
|
|
27
|
-
import { Toolbar } from '../Toolbar';
|
|
25
|
+
} from '../extensions';
|
|
26
|
+
import { markdownTheme } from '../themes';
|
|
27
|
+
import translations from '../translations';
|
|
28
28
|
|
|
29
29
|
// TODO(burdon): Demo toolbar with hooks.
|
|
30
30
|
// TODO(burdon): Build components from hooks and adapters for model/extensions, etc.
|
|
@@ -46,7 +46,7 @@ const Story = ({ autoFocus, placeholder, doc, readonly }: StoryProps) => {
|
|
|
46
46
|
const extensions = useMemo(
|
|
47
47
|
() => [
|
|
48
48
|
editorMode ? EditorModes[editorMode] : [],
|
|
49
|
-
|
|
49
|
+
createBasicExtensions({ readonly }),
|
|
50
50
|
createThemeExtensions({
|
|
51
51
|
themeMode,
|
|
52
52
|
theme: markdownTheme,
|
|
@@ -116,7 +116,7 @@ const EditorModeToolbar = ({
|
|
|
116
116
|
|
|
117
117
|
export default {
|
|
118
118
|
title: 'react-ui-editor/useTextEditor',
|
|
119
|
-
component: TextEditor,
|
|
119
|
+
// component: TextEditor,
|
|
120
120
|
decorators: [withTheme],
|
|
121
121
|
render: (args: StoryProps) => (
|
|
122
122
|
<Tooltip.Provider>
|
|
@@ -2,6 +2,9 @@
|
|
|
2
2
|
// Copyright 2024 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { closeBrackets } from '@codemirror/autocomplete';
|
|
6
|
+
import { history } from '@codemirror/commands';
|
|
7
|
+
import { bracketMatching } from '@codemirror/language';
|
|
5
8
|
import {
|
|
6
9
|
EditorSelection,
|
|
7
10
|
EditorState,
|
|
@@ -9,7 +12,17 @@ import {
|
|
|
9
12
|
type Extension,
|
|
10
13
|
type StateEffect,
|
|
11
14
|
} from '@codemirror/state';
|
|
12
|
-
import {
|
|
15
|
+
import {
|
|
16
|
+
crosshairCursor,
|
|
17
|
+
drawSelection,
|
|
18
|
+
dropCursor,
|
|
19
|
+
EditorView,
|
|
20
|
+
highlightActiveLine,
|
|
21
|
+
lineNumbers,
|
|
22
|
+
placeholder,
|
|
23
|
+
scrollPastEnd,
|
|
24
|
+
} from '@codemirror/view';
|
|
25
|
+
import defaultsDeep from 'lodash.defaultsdeep';
|
|
13
26
|
import { type DependencyList, type RefObject, useEffect, useRef, useState } from 'react';
|
|
14
27
|
|
|
15
28
|
import { log } from '@dxos/log';
|
|
@@ -38,7 +51,7 @@ export type UseTextEditor = {
|
|
|
38
51
|
// TODO(wittjosiah): Does not work in strict mode.
|
|
39
52
|
export const useTextEditor = (
|
|
40
53
|
{ autoFocus, scrollTo, debug, doc, selection, extensions }: UseTextEditorOptions = {},
|
|
41
|
-
deps
|
|
54
|
+
deps: DependencyList = [],
|
|
42
55
|
): UseTextEditor => {
|
|
43
56
|
const onUpdate = useRef<() => void>();
|
|
44
57
|
const [view, setView] = useState<EditorView>();
|
|
@@ -114,23 +127,66 @@ export const useTextEditor = (
|
|
|
114
127
|
|
|
115
128
|
// TODO(burdon): Factor out extension factories.
|
|
116
129
|
|
|
117
|
-
|
|
130
|
+
/**
|
|
131
|
+
* https://codemirror.net/docs/extensions
|
|
132
|
+
* https://github.com/codemirror/basic-setup
|
|
133
|
+
*/
|
|
134
|
+
// TODO(burdon): Reconcile with createMarkdownExtensions.
|
|
135
|
+
export type BasicExtensionsOptions = {
|
|
136
|
+
allowMultipleSelections?: boolean;
|
|
137
|
+
bracketMatching?: boolean;
|
|
138
|
+
closeBrackets?: boolean;
|
|
139
|
+
crosshairCursor?: boolean;
|
|
140
|
+
dropCursor?: boolean;
|
|
141
|
+
drawSelection?: boolean;
|
|
142
|
+
editable?: boolean;
|
|
143
|
+
highlightActiveLine?: boolean;
|
|
144
|
+
history?: boolean;
|
|
145
|
+
lineNumbers?: boolean;
|
|
146
|
+
lineWrapping?: boolean;
|
|
147
|
+
placeholder?: string;
|
|
118
148
|
readonly?: boolean;
|
|
149
|
+
scrollPastEnd?: boolean;
|
|
150
|
+
tabSize?: number;
|
|
151
|
+
};
|
|
152
|
+
|
|
153
|
+
const defaults: BasicExtensionsOptions = {
|
|
154
|
+
bracketMatching: true,
|
|
155
|
+
closeBrackets: true,
|
|
156
|
+
drawSelection: true,
|
|
157
|
+
editable: true,
|
|
158
|
+
history: true,
|
|
159
|
+
lineWrapping: true,
|
|
119
160
|
};
|
|
120
161
|
|
|
121
|
-
|
|
122
|
-
|
|
162
|
+
export const createBasicExtensions = (_props?: BasicExtensionsOptions): Extension => {
|
|
163
|
+
const props: BasicExtensionsOptions = defaultsDeep({}, _props, defaults);
|
|
123
164
|
return [
|
|
124
|
-
//
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
165
|
+
// TODO(burdon): Doesn't catch errors in keymap functions.
|
|
166
|
+
EditorView.exceptionSink.of((err) => {
|
|
167
|
+
log.catch(err);
|
|
168
|
+
}),
|
|
169
|
+
|
|
170
|
+
props.allowMultipleSelections && EditorState.allowMultipleSelections.of(true),
|
|
171
|
+
props.bracketMatching && bracketMatching(),
|
|
172
|
+
props.closeBrackets && closeBrackets(),
|
|
173
|
+
props.crosshairCursor && crosshairCursor(),
|
|
174
|
+
props.dropCursor && dropCursor(),
|
|
175
|
+
props.drawSelection && drawSelection(),
|
|
176
|
+
props.highlightActiveLine && highlightActiveLine(),
|
|
177
|
+
props.history && history(),
|
|
178
|
+
props.lineNumbers && lineNumbers(),
|
|
179
|
+
props.lineWrapping && EditorView.lineWrapping,
|
|
180
|
+
props.placeholder && placeholder(props.placeholder),
|
|
181
|
+
props.readonly && [EditorState.readOnly.of(true), EditorView.editable.of(false)],
|
|
182
|
+
props.scrollPastEnd && scrollPastEnd(),
|
|
183
|
+
props.tabSize && EditorState.tabSize.of(props.tabSize),
|
|
184
|
+
].filter(isNotFalsy);
|
|
128
185
|
};
|
|
129
186
|
|
|
130
187
|
export type ThemeExtensionsOptions = {
|
|
131
188
|
theme?: ThemeStyles;
|
|
132
189
|
themeMode?: ThemeMode;
|
|
133
|
-
lineWrap?: boolean;
|
|
134
190
|
slots?: {
|
|
135
191
|
editor?: {
|
|
136
192
|
className?: string;
|
|
@@ -143,11 +199,10 @@ export type ThemeExtensionsOptions = {
|
|
|
143
199
|
|
|
144
200
|
export const createThemeExtensions = ({ theme, themeMode, slots }: ThemeExtensionsOptions = {}): Extension => {
|
|
145
201
|
return [
|
|
146
|
-
//
|
|
147
202
|
EditorView.baseTheme(defaultTheme),
|
|
148
|
-
theme && EditorView.theme(theme),
|
|
149
203
|
EditorView.darkTheme.of(themeMode === 'dark'),
|
|
150
|
-
EditorView.
|
|
151
|
-
EditorView.
|
|
204
|
+
theme && EditorView.theme(theme),
|
|
205
|
+
slots?.editor?.className && EditorView.editorAttributes.of({ class: slots.editor.className }),
|
|
206
|
+
slots?.content?.className && EditorView.contentAttributes.of({ class: slots.content.className }),
|
|
152
207
|
].filter(isNotFalsy);
|
|
153
208
|
};
|
|
@@ -11,12 +11,13 @@ import { type AutomergeTextCompat, getRawDoc } from '@dxos/echo-schema';
|
|
|
11
11
|
import { invariant } from '@dxos/invariant';
|
|
12
12
|
import { isAutomergeObject, type Space, type TextObject } from '@dxos/react-client/echo';
|
|
13
13
|
import { type Identity } from '@dxos/react-client/halo';
|
|
14
|
+
import { hueTokens } from '@dxos/react-ui-theme';
|
|
15
|
+
import { hexToHue } from '@dxos/util';
|
|
14
16
|
|
|
15
17
|
import { SpaceAwarenessProvider } from './awareness-provider';
|
|
16
|
-
import { type EditorModel
|
|
18
|
+
import { type EditorModel } from './defs';
|
|
17
19
|
import { automerge, awareness } from '../extensions';
|
|
18
20
|
import { type DocAccessor } from '../extensions/automerge/defs';
|
|
19
|
-
import { cursorColor } from '../styles';
|
|
20
21
|
|
|
21
22
|
export type useTextExtensionsProps = {
|
|
22
23
|
id: string;
|
|
@@ -29,6 +30,9 @@ export type useTextExtensionsProps = {
|
|
|
29
30
|
export const useTextExtensions = ({ id, text, space, identity }: useTextExtensionsProps): Extension[] => {
|
|
30
31
|
const extensions: Extension[] = [automerge(text)];
|
|
31
32
|
|
|
33
|
+
const peerId = identity?.identityKey.toHex();
|
|
34
|
+
const { cursorLightValue, cursorDarkValue } = hueTokens[hexToHue(peerId ?? '0')];
|
|
35
|
+
|
|
32
36
|
if (space && identity) {
|
|
33
37
|
const awarenessProvider = new SpaceAwarenessProvider({
|
|
34
38
|
space,
|
|
@@ -36,8 +40,8 @@ export const useTextExtensions = ({ id, text, space, identity }: useTextExtensio
|
|
|
36
40
|
peerId: identity.identityKey.toHex(),
|
|
37
41
|
info: {
|
|
38
42
|
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
|
39
|
-
color:
|
|
40
|
-
lightColor:
|
|
43
|
+
color: cursorDarkValue,
|
|
44
|
+
lightColor: cursorLightValue,
|
|
41
45
|
},
|
|
42
46
|
});
|
|
43
47
|
|
|
@@ -64,6 +68,7 @@ export const useTextModel = (props: UseTextModelProps): EditorModel | undefined
|
|
|
64
68
|
* For use primarily in stories & tests so the dependence on TextObject can be avoided.
|
|
65
69
|
* @deprecated
|
|
66
70
|
*/
|
|
71
|
+
// TODO(burdon): Remove.
|
|
67
72
|
export const useInMemoryTextModel = ({
|
|
68
73
|
id,
|
|
69
74
|
defaultContent,
|
|
@@ -72,10 +77,10 @@ export const useInMemoryTextModel = ({
|
|
|
72
77
|
defaultContent?: string;
|
|
73
78
|
}): EditorModel & { setContent: Dispatch<SetStateAction<string>> } => {
|
|
74
79
|
const [content, setContent] = useState(defaultContent ?? '');
|
|
75
|
-
return { id, content,
|
|
80
|
+
return { id, content, text: () => content, setContent };
|
|
76
81
|
};
|
|
77
82
|
|
|
78
|
-
const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
83
|
+
const createModel = ({ space, identity, text }: UseTextModelProps): EditorModel | undefined => {
|
|
79
84
|
if (!text) {
|
|
80
85
|
return undefined;
|
|
81
86
|
}
|
|
@@ -84,6 +89,9 @@ const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
|
84
89
|
const obj = text as any as AutomergeTextCompat;
|
|
85
90
|
const doc = getRawDoc(obj, [obj.field]);
|
|
86
91
|
|
|
92
|
+
const peerId = identity?.identityKey.toHex();
|
|
93
|
+
const { cursorLightValue, cursorDarkValue } = hueTokens[hexToHue(peerId ?? '0')];
|
|
94
|
+
|
|
87
95
|
const awarenessProvider =
|
|
88
96
|
space &&
|
|
89
97
|
new SpaceAwarenessProvider({
|
|
@@ -91,29 +99,21 @@ const createModel = ({ space, identity, text }: UseTextModelProps) => {
|
|
|
91
99
|
channel: `automerge.awareness.${obj.id}`,
|
|
92
100
|
info: {
|
|
93
101
|
displayName: identity ? identity.profile?.displayName ?? generateName(identity.identityKey.toHex()) : undefined,
|
|
94
|
-
color:
|
|
95
|
-
lightColor:
|
|
102
|
+
color: cursorLightValue,
|
|
103
|
+
lightColor: cursorDarkValue,
|
|
96
104
|
},
|
|
97
105
|
peerId: identity?.identityKey.toHex() ?? 'Anonymous',
|
|
98
106
|
});
|
|
99
107
|
|
|
100
|
-
const extensions = [
|
|
108
|
+
const extensions = [automerge({ handle: doc.handle, path: doc.path })];
|
|
101
109
|
if (awarenessProvider) {
|
|
102
110
|
extensions.push(awareness(awarenessProvider));
|
|
103
111
|
}
|
|
104
112
|
|
|
105
|
-
|
|
113
|
+
return {
|
|
106
114
|
id: obj.id,
|
|
107
115
|
content: doc,
|
|
108
116
|
text: () => get(doc.handle.docSync(), doc.path),
|
|
109
117
|
extension: extensions,
|
|
110
|
-
peer: identity
|
|
111
|
-
? {
|
|
112
|
-
id: identity.identityKey.toHex(),
|
|
113
|
-
name: identity.profile?.displayName,
|
|
114
|
-
}
|
|
115
|
-
: undefined,
|
|
116
118
|
};
|
|
117
|
-
|
|
118
|
-
return model;
|
|
119
119
|
};
|
package/src/index.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
//
|
|
2
2
|
// Copyright 2022 DXOS.org
|
|
3
3
|
//
|
|
4
|
+
|
|
4
5
|
import translations from './translations';
|
|
5
6
|
|
|
6
7
|
export { type Extension, type EditorState } from '@codemirror/state';
|
|
7
8
|
export { type EditorView, keymap } from '@codemirror/view';
|
|
9
|
+
export { tags } from '@lezer/highlight';
|
|
8
10
|
|
|
9
11
|
export { TextKind } from '@dxos/protocols/proto/dxos/echo/model/text';
|
|
10
12
|
export { Doc, YText, YXmlFragment } from '@dxos/text-model';
|
package/src/styles/index.ts
CHANGED
package/src/themes/default.ts
CHANGED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"automerge.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/automerge.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAGpB,OAAO,uBAAuB,CAAC;AAc/B,OAAO,EAAE,WAAW,EAAE,MAAM,iCAAiC,CAAC;AAW9D,KAAK,WAAW,GAAG;IACjB,MAAM,EAAE,WAAW,CAAC;CACrB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA6DF,wBAKE;AAEF,eAAO,MAAM,OAAO,IAAK,CAAC;AAoB1B,eAAO,MAAM,QAAQ;;;CAmBpB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"hooks.stories.d.ts","sourceRoot":"","sources":["../../../../../src/components/TextEditor/hooks.stories.tsx"],"names":[],"mappings":"AAIA,OAAO,YAAY,CAAC;AAEpB,OAAO,KAA4B,MAAM,OAAO,CAAC;AA4BjD,KAAK,UAAU,GAAG;IAChB,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;;;;;mBAiFe,UAAU;;;;;;;;;;;;;;;;;;;;;;;;AAJ3B,wBAUE;AAEF,eAAO,MAAM,OAAO;;;;;;CAMnB,CAAC"}
|
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
import { type Extension } from '@codemirror/state';
|
|
2
|
-
import { type ThemeMode } from '@dxos/react-ui';
|
|
3
|
-
import { type TextEditorProps } from '../components';
|
|
4
|
-
export type BasicBundleOptions = {
|
|
5
|
-
themeMode?: ThemeMode;
|
|
6
|
-
bracketMatching?: boolean;
|
|
7
|
-
} & Pick<TextEditorProps, 'placeholder' | 'lineWrapping'>;
|
|
8
|
-
export declare const createBasicBundle: ({ themeMode, placeholder: _placeholder, lineWrapping, bracketMatching: _bracketMatching, }?: BasicBundleOptions) => Extension[];
|
|
9
|
-
//# sourceMappingURL=basic.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"basic.d.ts","sourceRoot":"","sources":["../../../../src/extensions/basic.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAInD,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,eAAe,CAAC;AAErD,MAAM,MAAM,kBAAkB,GAAG;IAC/B,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,GAAG,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,cAAc,CAAC,CAAC;AAE1D,eAAO,MAAM,iBAAiB,gGAK3B,kBAAkB,KAAQ,SAAS,EAchB,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cursors.d.ts","sourceRoot":"","sources":["../../../../src/styles/cursors.ts"],"names":[],"mappings":"AAoBA,eAAO,MAAM,WAAW;;;CAAsD,CAAC"}
|
package/src/extensions/basic.ts
DELETED
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
import { closeBrackets } from '@codemirror/autocomplete';
|
|
6
|
-
import { history } from '@codemirror/commands';
|
|
7
|
-
import { bracketMatching, defaultHighlightStyle, syntaxHighlighting } from '@codemirror/language';
|
|
8
|
-
import { type Extension } from '@codemirror/state';
|
|
9
|
-
import { oneDarkHighlightStyle } from '@codemirror/theme-one-dark';
|
|
10
|
-
import { drawSelection, EditorView, highlightActiveLine, placeholder } from '@codemirror/view';
|
|
11
|
-
|
|
12
|
-
import { type ThemeMode } from '@dxos/react-ui';
|
|
13
|
-
import { isNotFalsy } from '@dxos/util';
|
|
14
|
-
|
|
15
|
-
import { type TextEditorProps } from '../components';
|
|
16
|
-
|
|
17
|
-
export type BasicBundleOptions = {
|
|
18
|
-
themeMode?: ThemeMode;
|
|
19
|
-
bracketMatching?: boolean;
|
|
20
|
-
} & Pick<TextEditorProps, 'placeholder' | 'lineWrapping'>;
|
|
21
|
-
|
|
22
|
-
export const createBasicBundle = ({
|
|
23
|
-
themeMode,
|
|
24
|
-
placeholder: _placeholder,
|
|
25
|
-
lineWrapping = true,
|
|
26
|
-
bracketMatching: _bracketMatching = true,
|
|
27
|
-
}: BasicBundleOptions = {}): Extension[] =>
|
|
28
|
-
[
|
|
29
|
-
lineWrapping && EditorView.lineWrapping,
|
|
30
|
-
|
|
31
|
-
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
32
|
-
_bracketMatching && bracketMatching(),
|
|
33
|
-
closeBrackets(),
|
|
34
|
-
drawSelection(),
|
|
35
|
-
highlightActiveLine(),
|
|
36
|
-
history(),
|
|
37
|
-
_placeholder && placeholder(_placeholder),
|
|
38
|
-
|
|
39
|
-
// https://github.com/codemirror/theme-one-dark
|
|
40
|
-
themeMode === 'dark' ? syntaxHighlighting(oneDarkHighlightStyle) : syntaxHighlighting(defaultHighlightStyle),
|
|
41
|
-
].filter(isNotFalsy);
|
package/src/styles/cursors.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
//
|
|
2
|
-
// Copyright 2023 DXOS.org
|
|
3
|
-
//
|
|
4
|
-
|
|
5
|
-
// Copied from https://github.com/yjs/y-codemirror.next#example.
|
|
6
|
-
|
|
7
|
-
import * as random from 'lib0/random';
|
|
8
|
-
|
|
9
|
-
const cursorColors = [
|
|
10
|
-
{ color: '#30bced', light: '#30bced33' },
|
|
11
|
-
{ color: '#6eeb83', light: '#6eeb8333' },
|
|
12
|
-
{ color: '#ffbc42', light: '#ffbc4233' },
|
|
13
|
-
{ color: '#ecd444', light: '#ecd44433' },
|
|
14
|
-
{ color: '#ee6352', light: '#ee635233' },
|
|
15
|
-
{ color: '#9ac2c9', light: '#9ac2c933' },
|
|
16
|
-
{ color: '#8acb88', light: '#8acb8833' },
|
|
17
|
-
{ color: '#1be7ff', light: '#1be7ff33' },
|
|
18
|
-
];
|
|
19
|
-
|
|
20
|
-
// Select a random color for this user.
|
|
21
|
-
export const cursorColor = cursorColors[random.uint32() % cursorColors.length];
|