@dxos/react-ui-editor 0.3.11-main.cc2fe2c → 0.3.11-main.ccc0ca3
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 +782 -241
- 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/hooks.stories.d.ts +23 -0
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts +25 -0
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts +23 -0
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -0
- 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 +13 -0
- package/dist/types/src/extensions/markdown/formatting.d.ts.map +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts +1 -0
- package/dist/types/src/extensions/markdown/index.d.ts.map +1 -1
- package/dist/types/src/extensions/markdown/link.d.ts.map +1 -1
- package/dist/types/src/hooks/index.d.ts +2 -0
- package/dist/types/src/hooks/index.d.ts.map +1 -1
- package/dist/types/src/hooks/useActionHandler.d.ts +4 -0
- package/dist/types/src/hooks/useActionHandler.d.ts.map +1 -0
- 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.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 +10 -16
- package/src/components/TextEditor/TextEditor.tsx +24 -12
- package/src/components/TextEditor/comments.stories.tsx +3 -3
- package/src/components/TextEditor/hooks.stories.tsx +106 -0
- package/src/components/Toolbar/Toolbar.stories.tsx +90 -0
- package/src/components/Toolbar/Toolbar.tsx +166 -0
- 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 +26 -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 +12 -6
- package/src/extensions/automerge/update-codemirror.ts +5 -5
- package/src/extensions/awareness.ts +3 -3
- package/src/extensions/basic.ts +15 -13
- package/src/extensions/comments.ts +113 -65
- package/src/extensions/markdown/bundle.ts +10 -5
- package/src/extensions/markdown/code.ts +24 -9
- package/src/extensions/markdown/formatting.ts +188 -0
- package/src/extensions/markdown/heading.ts +1 -1
- package/src/extensions/markdown/index.ts +1 -0
- package/src/extensions/markdown/link.ts +4 -0
- package/src/hooks/index.ts +2 -0
- package/src/hooks/useActionHandler.ts +62 -0
- package/src/hooks/useEditorView.ts +29 -0
- package/src/hooks/useTextEditor.ts +143 -19
- package/src/hooks/useTextModel.ts +11 -8
- package/src/themes/default.ts +4 -2
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Extension } from '@codemirror/state';
|
|
2
|
+
import { type Command, type EditorView } from '@codemirror/view';
|
|
3
|
+
export type FormattingOptions = {};
|
|
4
|
+
export declare const setHeading: (level: number) => Command;
|
|
5
|
+
export declare const toggleStyle: (mark: string) => Command;
|
|
6
|
+
export declare const insertCodeblock: (view: EditorView) => void;
|
|
7
|
+
export declare const insertTable: (view: EditorView) => void;
|
|
8
|
+
export declare const toggleBold: Command;
|
|
9
|
+
export declare const toggleItalic: Command;
|
|
10
|
+
export declare const toggleStrikethrough: Command;
|
|
11
|
+
export declare const toggleList: (view: EditorView) => void;
|
|
12
|
+
export declare const formatting: (options?: FormattingOptions) => Extension;
|
|
13
|
+
//# sourceMappingURL=formatting.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"formatting.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/formatting.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,mBAAmB,CAAC;AACpE,OAAO,EACL,KAAK,OAAO,EAGZ,KAAK,UAAU,EAIhB,MAAM,kBAAkB,CAAC;AAG1B,MAAM,MAAM,iBAAiB,GAAG,EAAE,CAAC;AAEnC,eAAO,MAAM,UAAU,UACb,MAAM,KAAG,OA6BhB,CAAC;AAEJ,eAAO,MAAM,WAAW,SACf,MAAM,KAAG,OAwBf,CAAC;AAUJ,eAAO,MAAM,eAAe,SAAU,UAAU,SAQ/C,CAAC;AAEF,eAAO,MAAM,WAAW,SAAU,UAAU,SAQ3C,CAAC;AAEF,eAAO,MAAM,UAAU,SAAoB,CAAC;AAC5C,eAAO,MAAM,YAAY,SAAmB,CAAC;AAC7C,eAAO,MAAM,mBAAmB,SAAoB,CAAC;AAErD,eAAO,MAAM,UAAU,SAAU,UAAU,SAAO,CAAC;AAEnD,eAAO,MAAM,UAAU,aAAa,iBAAiB,KAAQ,SAU5D,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,cAAc,CAAC;AAC7B,cAAc,WAAW,CAAC;AAC1B,cAAc,aAAa,CAAC;AAC5B,cAAc,MAAM,CAAC;AACrB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,cAAc,YAAY,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/link.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,mBAAmB,CAAC;
|
|
1
|
+
{"version":3,"file":"link.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/link.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,KAAK,SAAS,EAAmB,MAAM,mBAAmB,CAAC;AAmBpE,MAAM,MAAM,WAAW,GAAG;IACxB,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,OAAO,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7C,QAAQ,CAAC,EAAE,CAAC,EAAE,EAAE,OAAO,EAAE,GAAG,EAAE,MAAM,KAAK,IAAI,CAAC;CAC/C,CAAC;AAEF;;;GAGG;AACH,eAAO,MAAM,IAAI,aAAa,WAAW,KAAQ,SAuDhD,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC;AAEvB,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AACrC,cAAc,QAAQ,CAAC;AAEvB,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,gBAAgB,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useActionHandler.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useActionHandler.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAEnD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAYlD,eAAO,MAAM,gBAAgB,UAAW,UAAU,GAAG,IAAI,KAAG,YAAY,CAAC,UAAU,CA2ClF,CAAC"}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type EditorView } from '@codemirror/view';
|
|
2
|
+
import { type RefCallback } from 'react';
|
|
3
|
+
/**
|
|
4
|
+
* Hook for accessing the editor view.
|
|
5
|
+
*
|
|
6
|
+
* ```tsx
|
|
7
|
+
* const Test = () => {
|
|
8
|
+
* const [editorRef, editorView] = useEditorView();
|
|
9
|
+
* useEffect(() => {
|
|
10
|
+
* editorView?.focus();
|
|
11
|
+
* }, [editorView]);
|
|
12
|
+
* return <TextEditor ref={editorRef} />;
|
|
13
|
+
* };
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export declare const useEditorView: () => [RefCallback<EditorView | null>, EditorView | null];
|
|
17
|
+
//# sourceMappingURL=useEditorView.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useEditorView.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useEditorView.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,KAAK,WAAW,EAAY,MAAM,OAAO,CAAC;AAEnD;;;;;;;;;;;;GAYG;AACH,eAAO,MAAM,aAAa,QAAO,CAAC,YAAY,UAAU,GAAG,IAAI,CAAC,EAAE,UAAU,GAAG,IAAI,CAQlF,CAAC"}
|
|
@@ -1,17 +1,39 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import {
|
|
1
|
+
import { type EditorStateConfig, type Extension, type StateEffect } from '@codemirror/state';
|
|
2
|
+
import { EditorView } from '@codemirror/view';
|
|
3
|
+
import { type RefObject } from 'react';
|
|
4
|
+
import { type ThemeMode } from '@dxos/react-ui';
|
|
5
|
+
import { type ThemeStyles } from '..//styles';
|
|
6
|
+
export type UseTextEditorOptions = {
|
|
7
|
+
autoFocus?: boolean;
|
|
8
|
+
scrollTo?: StateEffect<any>;
|
|
9
|
+
debug?: boolean;
|
|
10
|
+
} & EditorStateConfig;
|
|
11
|
+
export type UseTextEditor = {
|
|
12
|
+
parentRef: RefObject<HTMLDivElement>;
|
|
13
|
+
view?: EditorView;
|
|
14
|
+
};
|
|
3
15
|
/**
|
|
4
|
-
* Hook for
|
|
5
|
-
*
|
|
6
|
-
* ```tsx
|
|
7
|
-
* const Test = () => {
|
|
8
|
-
* const [editorRef, editorView] = useTextEditor();
|
|
9
|
-
* useEffect(() => {
|
|
10
|
-
* editorView?.focus();
|
|
11
|
-
* }, [editorView]);
|
|
12
|
-
* return <TextEditor ref={editorRef} />;
|
|
13
|
-
* };
|
|
14
|
-
* ```
|
|
16
|
+
* Hook for creating editor.
|
|
15
17
|
*/
|
|
16
|
-
export declare const useTextEditor: (
|
|
18
|
+
export declare const useTextEditor: ({ autoFocus, scrollTo, debug, doc, selection, extensions, }?: UseTextEditorOptions) => UseTextEditor;
|
|
19
|
+
export type DataExtensionsOptions = {
|
|
20
|
+
readonly?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export declare const createDataExtensions: ({ readonly }?: {
|
|
23
|
+
readonly?: boolean | undefined;
|
|
24
|
+
}) => Extension;
|
|
25
|
+
export type ThemeExtensionsOptions = {
|
|
26
|
+
theme?: ThemeStyles;
|
|
27
|
+
themeMode?: ThemeMode;
|
|
28
|
+
lineWrap?: boolean;
|
|
29
|
+
slots?: {
|
|
30
|
+
editor?: {
|
|
31
|
+
className?: string;
|
|
32
|
+
};
|
|
33
|
+
content?: {
|
|
34
|
+
className?: string;
|
|
35
|
+
};
|
|
36
|
+
};
|
|
37
|
+
};
|
|
38
|
+
export declare const createThemeExtensions: ({ theme, themeMode, slots }?: ThemeExtensionsOptions) => Extension;
|
|
17
39
|
//# sourceMappingURL=useTextEditor.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTextEditor.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTextEditor.ts"],"names":[],"mappings":"AAIA,OAAO,
|
|
1
|
+
{"version":3,"file":"useTextEditor.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTextEditor.ts"],"names":[],"mappings":"AAIA,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,SAAS,EACd,KAAK,WAAW,EACjB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAC9C,OAAO,EAAE,KAAK,SAAS,EAA+B,MAAM,OAAO,CAAC;AAGpE,OAAO,EAAE,KAAK,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAGhD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,YAAY,CAAC;AAI9C,MAAM,MAAM,oBAAoB,GAAG;IACjC,SAAS,CAAC,EAAE,OAAO,CAAC;IACpB,QAAQ,CAAC,EAAE,WAAW,CAAC,GAAG,CAAC,CAAC;IAC5B,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB,GAAG,iBAAiB,CAAC;AAEtB,MAAM,MAAM,aAAa,GAAG;IAC1B,SAAS,EAAE,SAAS,CAAC,cAAc,CAAC,CAAC;IACrC,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,aAAa,iEAOvB,oBAAoB,KAAQ,aAqE9B,CAAC;AAIF,MAAM,MAAM,qBAAqB,GAAG;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAGF,eAAO,MAAM,oBAAoB;;MAAgC,SAMhE,CAAC;AAEF,MAAM,MAAM,sBAAsB,GAAG;IACnC,KAAK,CAAC,EAAE,WAAW,CAAC;IACpB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,KAAK,CAAC,EAAE;QACN,MAAM,CAAC,EAAE;YACP,SAAS,CAAC,EAAE,MAAM,CAAC;SACpB,CAAC;QACF,OAAO,CAAC,EAAE;YACR,SAAS,CAAC,EAAE,MAAM,CAAC;SACpB,CAAC;KACH,CAAC;CACH,CAAC;AAEF,eAAO,MAAM,qBAAqB,iCAAiC,sBAAsB,KAAQ,SAShG,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useTextModel.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTextModel.ts"],"names":[],"mappings":"AAUA,OAAO,EAAqB,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"useTextModel.d.ts","sourceRoot":"","sources":["../../../../src/hooks/useTextModel.ts"],"names":[],"mappings":"AAUA,OAAO,EAAqB,KAAK,KAAK,EAAE,KAAK,UAAU,EAAE,MAAM,yBAAyB,CAAC;AACzF,OAAO,EAAE,KAAK,QAAQ,EAAE,MAAM,yBAAyB,CAAC;AAGxD,OAAO,EAAE,KAAK,WAAW,EAAc,MAAM,QAAQ,CAAC;AAKtD,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAC3B,KAAK,CAAC,EAAE,KAAK,CAAC;IACd,IAAI,CAAC,EAAE,UAAU,CAAC;CACnB,CAAC;AAEF,eAAO,MAAM,YAAY,UAAW,iBAAiB,KAAG,WAAW,GAAG,SAKrE,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,WAiO1B,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.ccc0ca3",
|
|
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",
|
|
@@ -23,10 +23,11 @@
|
|
|
23
23
|
"@codemirror/state": "^6.4.0",
|
|
24
24
|
"@codemirror/theme-one-dark": "^6.1.2",
|
|
25
25
|
"@codemirror/view": "^6.23.0",
|
|
26
|
-
"@fluentui/react-tabster": "^9.
|
|
26
|
+
"@fluentui/react-tabster": "^9.17.4",
|
|
27
27
|
"@lezer/common": "^1.2.1",
|
|
28
28
|
"@lezer/highlight": "^1.2.0",
|
|
29
29
|
"@lezer/markdown": "^1.2.0",
|
|
30
|
+
"@radix-ui/react-context": "^1.0.0",
|
|
30
31
|
"@replit/codemirror-vim": "^6.0.14",
|
|
31
32
|
"codemirror": "6.0.1",
|
|
32
33
|
"lib0": "^0.2.65",
|
|
@@ -35,53 +36,65 @@
|
|
|
35
36
|
"lodash.pick": "^4.4.0",
|
|
36
37
|
"lodash.sortby": "^4.7.0",
|
|
37
38
|
"style-mod": "^4.1.0",
|
|
38
|
-
"@dxos/async": "0.3.11-main.
|
|
39
|
-
"@dxos/automerge": "0.3.11-main.
|
|
40
|
-
"@dxos/context": "0.3.11-main.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/log": "0.3.11-main.
|
|
46
|
-
"@dxos/react-async": "0.3.11-main.
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/
|
|
49
|
-
"@dxos/react-ui": "0.3.11-main.
|
|
50
|
-
"@dxos/text-model": "0.3.11-main.
|
|
51
|
-
"@dxos/util": "0.3.11-main.
|
|
39
|
+
"@dxos/async": "0.3.11-main.ccc0ca3",
|
|
40
|
+
"@dxos/automerge": "0.3.11-main.ccc0ca3",
|
|
41
|
+
"@dxos/context": "0.3.11-main.ccc0ca3",
|
|
42
|
+
"@dxos/display-name": "0.3.11-main.ccc0ca3",
|
|
43
|
+
"@dxos/debug": "0.3.11-main.ccc0ca3",
|
|
44
|
+
"@dxos/echo-schema": "0.3.11-main.ccc0ca3",
|
|
45
|
+
"@dxos/invariant": "0.3.11-main.ccc0ca3",
|
|
46
|
+
"@dxos/log": "0.3.11-main.ccc0ca3",
|
|
47
|
+
"@dxos/react-async": "0.3.11-main.ccc0ca3",
|
|
48
|
+
"@dxos/react-ui": "0.3.11-main.ccc0ca3",
|
|
49
|
+
"@dxos/protocols": "0.3.11-main.ccc0ca3",
|
|
50
|
+
"@dxos/react-ui-theme": "0.3.11-main.ccc0ca3",
|
|
51
|
+
"@dxos/text-model": "0.3.11-main.ccc0ca3",
|
|
52
|
+
"@dxos/util": "0.3.11-main.ccc0ca3"
|
|
52
53
|
},
|
|
53
54
|
"devDependencies": {
|
|
54
|
-
"@automerge/automerge-repo-network-broadcastchannel": "^1.0
|
|
55
|
+
"@automerge/automerge-repo-network-broadcastchannel": "^1.1.0",
|
|
55
56
|
"@faker-js/faker": "^8.3.1",
|
|
56
57
|
"@phosphor-icons/react": "^2.0.5",
|
|
57
58
|
"@preact/signals-react": "^1.3.6",
|
|
59
|
+
"@testing-library/dom": "^8.17.1",
|
|
60
|
+
"@testing-library/react": "^13.4.0",
|
|
61
|
+
"@testing-library/user-event": "^14.4.3",
|
|
58
62
|
"@types/lodash.defaultsdeep": "^4.6.6",
|
|
59
63
|
"@types/lodash.get": "^4.4.7",
|
|
60
64
|
"@types/lodash.pick": "^4.4.7",
|
|
61
65
|
"@types/lodash.sortby": "^4.7.7",
|
|
62
66
|
"@types/react": "^18.0.21",
|
|
63
67
|
"@types/react-dom": "^18.0.6",
|
|
68
|
+
"@types/react-test-renderer": "^17.0.2",
|
|
69
|
+
"@vitest/ui": "^1.2.1",
|
|
64
70
|
"deepsignal": "1.4.0-shallow.0",
|
|
71
|
+
"happy-dom": "^13.3.1",
|
|
72
|
+
"jsdom": "^20.0.1",
|
|
65
73
|
"react": "^18.2.0",
|
|
66
74
|
"react-dom": "^18.2.0",
|
|
67
|
-
"
|
|
68
|
-
"
|
|
69
|
-
"
|
|
70
|
-
"
|
|
71
|
-
"
|
|
72
|
-
"@dxos/
|
|
73
|
-
"@dxos/
|
|
75
|
+
"react-test-renderer": "^18.2.0",
|
|
76
|
+
"vite": "^5.0.12",
|
|
77
|
+
"vite-plugin-top-level-await": "^1.4.1",
|
|
78
|
+
"vite-plugin-wasm": "^3.3.0",
|
|
79
|
+
"vitest": "^1.2.1",
|
|
80
|
+
"@dxos/config": "0.3.11-main.ccc0ca3",
|
|
81
|
+
"@dxos/echo-signals": "0.3.11-main.ccc0ca3",
|
|
82
|
+
"@dxos/react-client": "0.3.11-main.ccc0ca3",
|
|
83
|
+
"@dxos/react-ui": "0.3.11-main.ccc0ca3",
|
|
84
|
+
"@dxos/storybook-utils": "0.3.11-main.ccc0ca3",
|
|
85
|
+
"@dxos/echo-typegen": "0.3.11-main.ccc0ca3",
|
|
86
|
+
"@dxos/keyboard": "0.3.11-main.ccc0ca3"
|
|
74
87
|
},
|
|
75
88
|
"peerDependencies": {
|
|
76
89
|
"@phosphor-icons/react": "^2.0.5",
|
|
77
90
|
"react": "^18.2.0",
|
|
78
91
|
"react-dom": "^18.2.0",
|
|
79
|
-
"@dxos/react-client": "0.3.11-main.
|
|
92
|
+
"@dxos/react-client": "0.3.11-main.ccc0ca3"
|
|
80
93
|
},
|
|
81
94
|
"publishConfig": {
|
|
82
95
|
"access": "public"
|
|
83
96
|
},
|
|
84
97
|
"scripts": {
|
|
85
|
-
"
|
|
98
|
+
"vitest": "vitest --ui"
|
|
86
99
|
}
|
|
87
100
|
}
|
|
@@ -19,11 +19,14 @@ import { withTheme } from '@dxos/storybook-utils';
|
|
|
19
19
|
|
|
20
20
|
import { MarkdownEditor, type TextEditorProps } from './TextEditor';
|
|
21
21
|
import {
|
|
22
|
+
type CommentsOptions,
|
|
23
|
+
type LinkOptions,
|
|
22
24
|
autocomplete,
|
|
23
25
|
blast,
|
|
24
26
|
code,
|
|
25
27
|
comments,
|
|
26
28
|
defaultOptions,
|
|
29
|
+
heading,
|
|
27
30
|
hr,
|
|
28
31
|
image,
|
|
29
32
|
link,
|
|
@@ -31,17 +34,11 @@ import {
|
|
|
31
34
|
table,
|
|
32
35
|
tasklist,
|
|
33
36
|
typewriter,
|
|
34
|
-
type CommentsOptions,
|
|
35
|
-
type LinkOptions,
|
|
36
37
|
useComments,
|
|
37
|
-
|
|
38
|
+
formatting,
|
|
38
39
|
} from '../../extensions';
|
|
39
40
|
import { type Comment, useTextModel } from '../../hooks';
|
|
40
41
|
|
|
41
|
-
// Extensions:
|
|
42
|
-
// TODO(burdon): Table of contents.
|
|
43
|
-
// TODO(burdon): Front-matter
|
|
44
|
-
|
|
45
42
|
faker.seed(101);
|
|
46
43
|
|
|
47
44
|
const str = (...lines: string[]) => lines.join('\n');
|
|
@@ -214,11 +211,10 @@ const onRenderLink: LinkOptions['onRender'] = (el, url) => {
|
|
|
214
211
|
type StoryProps = {
|
|
215
212
|
text?: string;
|
|
216
213
|
comments?: Comment[];
|
|
217
|
-
automerge?: boolean;
|
|
218
214
|
} & Pick<TextEditorProps, 'readonly' | 'placeholder' | 'slots' | 'extensions'>;
|
|
219
215
|
|
|
220
|
-
const Story = ({ text, comments,
|
|
221
|
-
const [item] = useState({ text: new TextObject(text
|
|
216
|
+
const Story = ({ text, comments, placeholder = 'New document.', ...props }: StoryProps) => {
|
|
217
|
+
const [item] = useState({ text: new TextObject(text) });
|
|
222
218
|
const view = useRef<EditorView>(null);
|
|
223
219
|
const model = useTextModel({ text: item.text });
|
|
224
220
|
useComments(view.current, comments);
|
|
@@ -249,13 +245,11 @@ const defaults = [
|
|
|
249
245
|
onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
|
|
250
246
|
}),
|
|
251
247
|
code(),
|
|
248
|
+
formatting(),
|
|
252
249
|
heading(),
|
|
253
250
|
hr(),
|
|
254
251
|
image(),
|
|
255
252
|
link({ onRender: onRenderLink, onHover: onHoverLinkTooltip }),
|
|
256
|
-
// mention({
|
|
257
|
-
// onSearch: (text) => names.filter((name) => name.toLowerCase().startsWith(text.toLowerCase())),
|
|
258
|
-
// }),
|
|
259
253
|
table(),
|
|
260
254
|
tasklist(),
|
|
261
255
|
];
|
|
@@ -347,18 +341,18 @@ export const Mention = {
|
|
|
347
341
|
|
|
348
342
|
export const Comments = {
|
|
349
343
|
render: () => {
|
|
350
|
-
const [
|
|
344
|
+
const [_comments, setComments] = useState<Comment[]>([]);
|
|
351
345
|
|
|
352
346
|
return (
|
|
353
347
|
<Story
|
|
354
348
|
text={str('# Comments', '', text.paragraphs, text.footer)}
|
|
355
|
-
comments={
|
|
349
|
+
comments={_comments}
|
|
356
350
|
extensions={[
|
|
357
351
|
comments({
|
|
358
352
|
onHover: onCommentsHover,
|
|
359
353
|
onCreate: (range) => {
|
|
360
354
|
const id = PublicKey.random().toHex();
|
|
361
|
-
|
|
355
|
+
setComments((commentRanges) => [...commentRanges, { id, cursor: range }]);
|
|
362
356
|
return id;
|
|
363
357
|
},
|
|
364
358
|
onSelect: (state) => {
|
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import { EditorState, type Extension, type StateEffect } from '@codemirror/state';
|
|
6
6
|
import { EditorView } from '@codemirror/view';
|
|
7
|
-
import { useFocusableGroup } from '@fluentui/react-tabster';
|
|
7
|
+
// import { useFocusableGroup } from '@fluentui/react-tabster';
|
|
8
8
|
import { vim } from '@replit/codemirror-vim';
|
|
9
9
|
import defaultsDeep from 'lodash.defaultsdeep';
|
|
10
10
|
import React, {
|
|
@@ -21,8 +21,9 @@ import React, {
|
|
|
21
21
|
import { log } from '@dxos/log';
|
|
22
22
|
import { useThemeContext } from '@dxos/react-ui';
|
|
23
23
|
import { attentionSurface, mx } from '@dxos/react-ui-theme';
|
|
24
|
+
import { isNotFalsy } from '@dxos/util';
|
|
24
25
|
|
|
25
|
-
import {
|
|
26
|
+
import { createBasicBundle, createMarkdownExtensions } from '../../extensions';
|
|
26
27
|
import { type EditorModel } from '../../hooks';
|
|
27
28
|
import { type ThemeStyles } from '../../styles';
|
|
28
29
|
import { defaultTheme, markdownTheme, textTheme } from '../../themes';
|
|
@@ -86,7 +87,12 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
86
87
|
},
|
|
87
88
|
forwardedRef,
|
|
88
89
|
) => {
|
|
89
|
-
|
|
90
|
+
// TODO(burdon): Hook causes error even if properties are not spread into div.
|
|
91
|
+
// Uncaught TypeError: Cannot read properties of undefined (reading 'relatedTarget')
|
|
92
|
+
// Uses event.detail, which is deprecated (not event.details). At runtime the event has a property `details`.
|
|
93
|
+
// https://github.com/microsoft/tabster/blob/master/src/State/FocusedElement.ts#L348 (e.detail.relatedTarget)
|
|
94
|
+
// https://github.com/microsoft/keyborg/blob/49e49b2c3ba0a5f6cc518ac46825d7551def8109/src/FocusEvent.ts#L58
|
|
95
|
+
// const tabsterDOMAttribute = useFocusableGroup({ tabBehavior: 'limited' });
|
|
90
96
|
const { themeMode } = useThemeContext();
|
|
91
97
|
|
|
92
98
|
const rootRef = useRef<HTMLDivElement>(null);
|
|
@@ -98,7 +104,12 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
98
104
|
|
|
99
105
|
// Set focus.
|
|
100
106
|
useEffect(() => {
|
|
101
|
-
if (autoFocus) {
|
|
107
|
+
if (autoFocus && !view?.hasFocus) {
|
|
108
|
+
if (view?.state.selection.main?.from === 0) {
|
|
109
|
+
// Start at end of line.
|
|
110
|
+
const { to } = view.state.doc.lineAt(0);
|
|
111
|
+
view?.dispatch({ selection: { anchor: to } });
|
|
112
|
+
}
|
|
102
113
|
view?.focus();
|
|
103
114
|
}
|
|
104
115
|
}, [view, autoFocus]);
|
|
@@ -132,18 +143,19 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
132
143
|
EditorView.contentAttributes.of({ class: slots.content?.className ?? '' }),
|
|
133
144
|
|
|
134
145
|
// State.
|
|
146
|
+
EditorView.editable.of(!readonly),
|
|
135
147
|
EditorState.readOnly.of(!!readonly),
|
|
136
148
|
|
|
137
149
|
// Storage and replication.
|
|
138
150
|
// NOTE: This must come before user extensions.
|
|
139
151
|
model.extension,
|
|
140
152
|
|
|
141
|
-
// TODO(burdon): Factor out (
|
|
153
|
+
// TODO(burdon): Factor out? (Requires special handling for Escape/Enter below).
|
|
142
154
|
editorMode === 'vim' && vim(),
|
|
143
155
|
|
|
144
156
|
// Custom.
|
|
145
157
|
...extensions,
|
|
146
|
-
].filter(
|
|
158
|
+
].filter(isNotFalsy),
|
|
147
159
|
});
|
|
148
160
|
|
|
149
161
|
//
|
|
@@ -175,6 +187,7 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
175
187
|
|
|
176
188
|
// Handles tab/focus.
|
|
177
189
|
// Pressing Escape focuses the outer div (to support tab navigation); pressing Enter refocuses the editor.
|
|
190
|
+
// TODO(burdon): Convert to keymap?
|
|
178
191
|
const handleKeyUp = useCallback(
|
|
179
192
|
(event: KeyboardEvent) => {
|
|
180
193
|
const { key, altKey, shiftKey, metaKey, ctrlKey } = event;
|
|
@@ -186,7 +199,7 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
186
199
|
|
|
187
200
|
case 'Escape': {
|
|
188
201
|
if (editorMode === 'vim' && (altKey || shiftKey || metaKey || ctrlKey)) {
|
|
189
|
-
|
|
202
|
+
view?.focus();
|
|
190
203
|
}
|
|
191
204
|
break;
|
|
192
205
|
}
|
|
@@ -200,16 +213,15 @@ export const BaseTextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
200
213
|
key={model.id}
|
|
201
214
|
role='none'
|
|
202
215
|
tabIndex={0}
|
|
203
|
-
onKeyUp={handleKeyUp}
|
|
204
216
|
{...slots.root}
|
|
205
|
-
{...(editorMode !== 'vim' && tabsterDOMAttribute)}
|
|
217
|
+
// {...(editorMode !== 'vim' && tabsterDOMAttribute)}
|
|
218
|
+
onKeyUp={handleKeyUp}
|
|
206
219
|
ref={rootRef}
|
|
207
220
|
/>
|
|
208
221
|
);
|
|
209
222
|
},
|
|
210
223
|
);
|
|
211
224
|
|
|
212
|
-
// TODO(burdon): Single-line/scroll.
|
|
213
225
|
export const TextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
214
226
|
({ readonly, placeholder, lineWrapping, theme = textTheme, slots, extensions = [], ...props }, forwardedRef) => {
|
|
215
227
|
const { themeMode } = useThemeContext();
|
|
@@ -218,7 +230,7 @@ export const TextEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
218
230
|
<BaseTextEditor
|
|
219
231
|
ref={forwardedRef}
|
|
220
232
|
readonly={readonly}
|
|
221
|
-
extensions={[
|
|
233
|
+
extensions={[createBasicBundle({ themeMode, placeholder, lineWrapping }), ...extensions]}
|
|
222
234
|
theme={theme}
|
|
223
235
|
slots={updatedSlots}
|
|
224
236
|
{...props}
|
|
@@ -235,7 +247,7 @@ export const MarkdownEditor = forwardRef<EditorView, TextEditorProps>(
|
|
|
235
247
|
<BaseTextEditor
|
|
236
248
|
ref={forwardedRef}
|
|
237
249
|
readonly={readonly}
|
|
238
|
-
extensions={[
|
|
250
|
+
extensions={[createMarkdownExtensions({ themeMode, placeholder }), ...extensions]}
|
|
239
251
|
theme={theme}
|
|
240
252
|
slots={updatedSlots}
|
|
241
253
|
{...props}
|
|
@@ -17,7 +17,7 @@ import { fixedInsetFlexLayout, mx } from '@dxos/react-ui-theme';
|
|
|
17
17
|
import { withTheme } from '@dxos/storybook-utils';
|
|
18
18
|
|
|
19
19
|
import { MarkdownEditor, TextEditor } from './TextEditor';
|
|
20
|
-
import { comments, type CommentsOptions,
|
|
20
|
+
import { comments, type CommentsOptions, focusComment, useComments } from '../../extensions';
|
|
21
21
|
import { type Comment, type Range, useTextModel } from '../../hooks';
|
|
22
22
|
|
|
23
23
|
faker.seed(101);
|
|
@@ -50,7 +50,7 @@ const Editor: FC<{
|
|
|
50
50
|
if (!view.current?.hasFocus && selectedValue !== selected) {
|
|
51
51
|
setSelected(selectedValue);
|
|
52
52
|
if (selectedValue) {
|
|
53
|
-
|
|
53
|
+
focusComment(view.current!, selectedValue);
|
|
54
54
|
}
|
|
55
55
|
}
|
|
56
56
|
}, [selected, commentRanges, selectedValue]);
|
|
@@ -150,7 +150,7 @@ const Thread: FC<{
|
|
|
150
150
|
</div>
|
|
151
151
|
))}
|
|
152
152
|
|
|
153
|
-
<div ref={containerRef} onClick={() => onSelect()}
|
|
153
|
+
<div ref={containerRef} className='flex' onClick={() => onSelect()}>
|
|
154
154
|
<TextEditor
|
|
155
155
|
ref={editorRef}
|
|
156
156
|
autoFocus={focus}
|
|
@@ -0,0 +1,106 @@
|
|
|
1
|
+
//
|
|
2
|
+
// Copyright 2024 DXOS.org
|
|
3
|
+
//
|
|
4
|
+
|
|
5
|
+
import '@dxosTheme';
|
|
6
|
+
|
|
7
|
+
import React from 'react';
|
|
8
|
+
|
|
9
|
+
import { useThemeContext } from '@dxos/react-ui';
|
|
10
|
+
import { fixedInsetFlexLayout, groupSurface, mx } from '@dxos/react-ui-theme';
|
|
11
|
+
import { withTheme } from '@dxos/storybook-utils';
|
|
12
|
+
|
|
13
|
+
import { TextEditor } from './TextEditor';
|
|
14
|
+
import {
|
|
15
|
+
code,
|
|
16
|
+
createMarkdownExtensions,
|
|
17
|
+
formatting,
|
|
18
|
+
heading,
|
|
19
|
+
hr,
|
|
20
|
+
image,
|
|
21
|
+
link,
|
|
22
|
+
table,
|
|
23
|
+
tasklist,
|
|
24
|
+
} from '../../extensions';
|
|
25
|
+
import { createDataExtensions, createThemeExtensions, useActionHandler, useTextEditor } from '../../hooks';
|
|
26
|
+
import { markdownTheme } from '../../themes';
|
|
27
|
+
import { Toolbar } from '../Toolbar';
|
|
28
|
+
|
|
29
|
+
// TODO(burdon): Demo toolbar with hooks.
|
|
30
|
+
// TODO(burdon): Build components from hooks and adapters for model/extensions, etc.
|
|
31
|
+
// TODO(burdon): Remove BaseTextEditor.
|
|
32
|
+
// TODO(burdon): Move scrolling container layout/logic into TextEditor/MarkdownEditor components.
|
|
33
|
+
// TODO(burdon): Define keymap in composer framework format.
|
|
34
|
+
|
|
35
|
+
type StoryProps = {
|
|
36
|
+
autoFocus?: boolean;
|
|
37
|
+
placeholder?: string;
|
|
38
|
+
doc?: string;
|
|
39
|
+
readonly?: boolean;
|
|
40
|
+
};
|
|
41
|
+
|
|
42
|
+
const Story = ({ autoFocus, placeholder, doc, readonly }: StoryProps) => {
|
|
43
|
+
const { themeMode } = useThemeContext();
|
|
44
|
+
const { parentRef, view } = useTextEditor({
|
|
45
|
+
autoFocus,
|
|
46
|
+
doc,
|
|
47
|
+
extensions: [
|
|
48
|
+
//
|
|
49
|
+
createDataExtensions({ readonly }),
|
|
50
|
+
createThemeExtensions({
|
|
51
|
+
themeMode,
|
|
52
|
+
theme: markdownTheme,
|
|
53
|
+
slots: {
|
|
54
|
+
// TODO(burdon): Document classes re base theme.
|
|
55
|
+
// Semantic tokens (e.g., replacement of input surface).
|
|
56
|
+
editor: {
|
|
57
|
+
className: 'h-full p-4 bg-white text-black dark:bg-black dark:text-white',
|
|
58
|
+
},
|
|
59
|
+
},
|
|
60
|
+
}),
|
|
61
|
+
// TODO(burdon): Move lineWrapping.
|
|
62
|
+
createMarkdownExtensions({ placeholder, lineWrapping: true }),
|
|
63
|
+
// TODO(burdon): Move into markdown bundle (with React callbacks).
|
|
64
|
+
code(),
|
|
65
|
+
formatting(),
|
|
66
|
+
heading(),
|
|
67
|
+
hr(),
|
|
68
|
+
image(),
|
|
69
|
+
link(),
|
|
70
|
+
table(),
|
|
71
|
+
tasklist(),
|
|
72
|
+
],
|
|
73
|
+
});
|
|
74
|
+
|
|
75
|
+
const handleAction = useActionHandler(view);
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<div className={mx(fixedInsetFlexLayout, groupSurface)}>
|
|
79
|
+
<div className='flex h-full justify-center'>
|
|
80
|
+
<div className='flex flex-col h-full w-[800px]'>
|
|
81
|
+
<Toolbar.Root onAction={handleAction}>
|
|
82
|
+
<Toolbar.Markdown />
|
|
83
|
+
</Toolbar.Root>
|
|
84
|
+
|
|
85
|
+
{/* TODO(burdon): Handle scrolling in component wrapper (like this). */}
|
|
86
|
+
<div role='none' className='h-full overflow-y-auto' ref={parentRef} />
|
|
87
|
+
</div>
|
|
88
|
+
</div>
|
|
89
|
+
</div>
|
|
90
|
+
);
|
|
91
|
+
};
|
|
92
|
+
|
|
93
|
+
export default {
|
|
94
|
+
title: 'react-ui-editor/useTextEditor',
|
|
95
|
+
component: TextEditor,
|
|
96
|
+
decorators: [withTheme],
|
|
97
|
+
render: (args: StoryProps) => <Story {...args} />,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
export const Default = {
|
|
101
|
+
args: {
|
|
102
|
+
autoFocus: true,
|
|
103
|
+
placeholder: 'Text...',
|
|
104
|
+
doc: '# Demo\n\nThis is a document.\n\n',
|
|
105
|
+
},
|
|
106
|
+
};
|