@dxos/react-ui-editor 0.3.11-main.5e1976a → 0.3.11-main.604a65a
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 +1245 -654
- 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/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/index.d.ts +0 -6
- 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/formatting.d.ts +13 -0
- package/dist/types/src/extensions/markdown/formatting.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 +8 -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/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/styles/markdown.d.ts +2 -2
- package/dist/types/src/styles/markdown.d.ts.map +1 -1
- package/package.json +39 -26
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +14 -18
- package/src/components/TextEditor/TextEditor.tsx +24 -12
- package/src/components/TextEditor/automerge.stories.tsx +1 -2
- 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/index.ts +0 -6
- package/src/extensions/markdown/bundle.ts +9 -8
- package/src/extensions/markdown/code.ts +150 -0
- package/src/extensions/markdown/formatting.ts +188 -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 +8 -0
- package/src/extensions/{link.ts → markdown/link.ts} +5 -2
- package/src/extensions/{tasklist.ts → markdown/tasklist.ts} +2 -3
- 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/styles/markdown.ts +9 -10
- package/src/themes/default.ts +4 -4
- 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/src/extensions/code.ts +0 -104
- /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
|
@@ -3,12 +3,12 @@ import type { ThemeMode } from '@dxos/react-ui';
|
|
|
3
3
|
import { type TextEditorProps } from '../../components';
|
|
4
4
|
export type MarkdownBundleOptions = {
|
|
5
5
|
themeMode?: ThemeMode;
|
|
6
|
-
} & Pick<TextEditorProps, '
|
|
6
|
+
} & Pick<TextEditorProps, 'placeholder' | 'lineWrapping'>;
|
|
7
7
|
/**
|
|
8
8
|
* Markdown bundle.
|
|
9
9
|
* Refs:
|
|
10
10
|
* https://codemirror.net/docs/community
|
|
11
11
|
* https://codemirror.net/docs/ref/#codemirror.basicSetup
|
|
12
12
|
*/
|
|
13
|
-
export declare const
|
|
13
|
+
export declare const createMarkdownExtensions: ({ themeMode, placeholder: _placeholder, lineWrapping, }?: MarkdownBundleOptions) => Extension[];
|
|
14
14
|
//# sourceMappingURL=bundle.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/bundle.ts"],"names":[],"mappings":"AAUA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAYhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"bundle.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/bundle.ts"],"names":[],"mappings":"AAUA,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAYhE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAIhD,OAAO,EAAE,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAExD,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,CAAC,EAAE,SAAS,CAAC;CACvB,GAAG,IAAI,CAAC,eAAe,EAAE,aAAa,GAAG,cAAc,CAAC,CAAC;AAE1D;;;;;GAKG;AAEH,eAAO,MAAM,wBAAwB,6DAIlC,qBAAqB,KAAQ,SAAS,EAyDxC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"code.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/code.ts"],"names":[],"mappings":"AAkIA,eAAO,MAAM,IAAI,+CAmBhB,CAAC"}
|
|
@@ -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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"heading.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/heading.ts"],"names":[],"mappings":"AAMA,OAAO,EAAc,KAAK,aAAa,EAAmB,UAAU,EAAE,KAAK,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAkChH,eAAO,MAAM,OAAO;;mBASG,UAAU;IAShC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/highlight.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAmB,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,cAAc,EAAS,MAAM,iBAAiB,CAAC;AAe7D;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;CAexB,CAAC;AAaF,eAAO,MAAM,sBAAsB,EAAE,cAAc,EAKlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,cAAe,OAAO,
|
|
1
|
+
{"version":3,"file":"highlight.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/highlight.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACtD,OAAO,EAAmB,GAAG,EAAE,MAAM,kBAAkB,CAAC;AACxD,OAAO,EAAE,KAAK,cAAc,EAAS,MAAM,iBAAiB,CAAC;AAe7D;;;;GAIG;AACH,eAAO,MAAM,YAAY;;;;;;;;;;;;;CAexB,CAAC;AAaF,eAAO,MAAM,sBAAsB,EAAE,cAAc,EAKlD,CAAC;AAEF;;;;;;;;;;GAUG;AACH,eAAO,MAAM,sBAAsB,cAAe,OAAO,mBAmHxD,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hr.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/hr.ts"],"names":[],"mappings":"AAmDA,eAAO,MAAM,EAAE,+CAmBd,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"image.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/image.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,SAAS,EAA4C,MAAM,mBAAmB,CAAC;AAG/G,MAAM,MAAM,YAAY,GAAG,EAAE,CAAC;AAE9B,eAAO,MAAM,KAAK,aAAa,YAAY,KAAQ,SA8BlD,CAAC"}
|
|
@@ -1,3 +1,11 @@
|
|
|
1
1
|
export * from './bundle';
|
|
2
|
+
export * from './code';
|
|
3
|
+
export * from './formatting';
|
|
4
|
+
export * from './heading';
|
|
2
5
|
export * from './highlight';
|
|
6
|
+
export * from './hr';
|
|
7
|
+
export * from './image';
|
|
8
|
+
export * from './link';
|
|
9
|
+
export * from './table';
|
|
10
|
+
export * from './tasklist';
|
|
3
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/index.ts"],"names":[],"mappings":"AAIA,cAAc,UAAU,CAAC;AACzB,cAAc,aAAa,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"}
|
|
@@ -0,0 +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;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"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"table.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/table.ts"],"names":[],"mappings":"AAKA,OAAO,EAAoB,KAAK,QAAQ,EAAmB,UAAU,EAAoB,MAAM,mBAAmB,CAAC;AASnH,MAAM,MAAM,YAAY,GAAG,EAAE,CAAC;AAE9B;;;GAGG;AACH,eAAO,MAAM,KAAK,aAAa,YAAY,8BAM1C,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tasklist.d.ts","sourceRoot":"","sources":["../../../../../src/extensions/markdown/tasklist.ts"],"names":[],"mappings":"AAsFA,MAAM,MAAM,eAAe,GAAG,EAAE,CAAC;AAEjC,eAAO,MAAM,QAAQ,aAAa,eAAe,4CAqBhD,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,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"}
|
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.604a65a",
|
|
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/
|
|
40
|
-
"@dxos/
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/echo-schema": "0.3.11-main.
|
|
44
|
-
"@dxos/
|
|
45
|
-
"@dxos/
|
|
46
|
-
"@dxos/
|
|
47
|
-
"@dxos/
|
|
48
|
-
"@dxos/react-ui
|
|
49
|
-
"@dxos/text-model": "0.3.11-main.
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/
|
|
39
|
+
"@dxos/async": "0.3.11-main.604a65a",
|
|
40
|
+
"@dxos/automerge": "0.3.11-main.604a65a",
|
|
41
|
+
"@dxos/context": "0.3.11-main.604a65a",
|
|
42
|
+
"@dxos/display-name": "0.3.11-main.604a65a",
|
|
43
|
+
"@dxos/debug": "0.3.11-main.604a65a",
|
|
44
|
+
"@dxos/echo-schema": "0.3.11-main.604a65a",
|
|
45
|
+
"@dxos/log": "0.3.11-main.604a65a",
|
|
46
|
+
"@dxos/invariant": "0.3.11-main.604a65a",
|
|
47
|
+
"@dxos/protocols": "0.3.11-main.604a65a",
|
|
48
|
+
"@dxos/react-async": "0.3.11-main.604a65a",
|
|
49
|
+
"@dxos/react-ui": "0.3.11-main.604a65a",
|
|
50
|
+
"@dxos/text-model": "0.3.11-main.604a65a",
|
|
51
|
+
"@dxos/util": "0.3.11-main.604a65a",
|
|
52
|
+
"@dxos/react-ui-theme": "0.3.11-main.604a65a"
|
|
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.604a65a",
|
|
81
|
+
"@dxos/echo-signals": "0.3.11-main.604a65a",
|
|
82
|
+
"@dxos/keyboard": "0.3.11-main.604a65a",
|
|
83
|
+
"@dxos/react-ui": "0.3.11-main.604a65a",
|
|
84
|
+
"@dxos/echo-typegen": "0.3.11-main.604a65a",
|
|
85
|
+
"@dxos/react-client": "0.3.11-main.604a65a",
|
|
86
|
+
"@dxos/storybook-utils": "0.3.11-main.604a65a"
|
|
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.604a65a"
|
|
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,16 +34,11 @@ import {
|
|
|
31
34
|
table,
|
|
32
35
|
tasklist,
|
|
33
36
|
typewriter,
|
|
34
|
-
type CommentsOptions,
|
|
35
|
-
type LinkOptions,
|
|
36
37
|
useComments,
|
|
38
|
+
formatting,
|
|
37
39
|
} from '../../extensions';
|
|
38
40
|
import { type Comment, useTextModel } from '../../hooks';
|
|
39
41
|
|
|
40
|
-
// Extensions:
|
|
41
|
-
// TODO(burdon): Table of contents.
|
|
42
|
-
// TODO(burdon): Front-matter
|
|
43
|
-
|
|
44
42
|
faker.seed(101);
|
|
45
43
|
|
|
46
44
|
const str = (...lines: string[]) => lines.join('\n');
|
|
@@ -82,7 +80,7 @@ const text = {
|
|
|
82
80
|
'## Code',
|
|
83
81
|
'',
|
|
84
82
|
'```',
|
|
85
|
-
'
|
|
83
|
+
'$ ls -las',
|
|
86
84
|
'```',
|
|
87
85
|
'',
|
|
88
86
|
'```tsx',
|
|
@@ -213,11 +211,10 @@ const onRenderLink: LinkOptions['onRender'] = (el, url) => {
|
|
|
213
211
|
type StoryProps = {
|
|
214
212
|
text?: string;
|
|
215
213
|
comments?: Comment[];
|
|
216
|
-
automerge?: boolean;
|
|
217
214
|
} & Pick<TextEditorProps, 'readonly' | 'placeholder' | 'slots' | 'extensions'>;
|
|
218
215
|
|
|
219
|
-
const Story = ({ text, comments,
|
|
220
|
-
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) });
|
|
221
218
|
const view = useRef<EditorView>(null);
|
|
222
219
|
const model = useTextModel({ text: item.text });
|
|
223
220
|
useComments(view.current, comments);
|
|
@@ -248,12 +245,11 @@ const defaults = [
|
|
|
248
245
|
onSearch: (text) => links.filter(({ label }) => label.toLowerCase().includes(text.toLowerCase())),
|
|
249
246
|
}),
|
|
250
247
|
code(),
|
|
248
|
+
formatting(),
|
|
249
|
+
heading(),
|
|
251
250
|
hr(),
|
|
252
251
|
image(),
|
|
253
252
|
link({ onRender: onRenderLink, onHover: onHoverLinkTooltip }),
|
|
254
|
-
// mention({
|
|
255
|
-
// onSearch: (text) => names.filter((name) => name.toLowerCase().startsWith(text.toLowerCase())),
|
|
256
|
-
// }),
|
|
257
253
|
table(),
|
|
258
254
|
tasklist(),
|
|
259
255
|
];
|
|
@@ -290,11 +286,11 @@ export const Links = {
|
|
|
290
286
|
};
|
|
291
287
|
|
|
292
288
|
export const Code = {
|
|
293
|
-
render: () => <Story text={str(text.code, text.footer)} extensions={[code()]}
|
|
289
|
+
render: () => <Story text={str(text.code, text.footer)} extensions={[code()]} />,
|
|
294
290
|
};
|
|
295
291
|
|
|
296
292
|
export const Image = {
|
|
297
|
-
render: () => <Story text={str(text.image, text.footer)}
|
|
293
|
+
render: () => <Story text={str(text.image, text.footer)} extensions={[image()]} />,
|
|
298
294
|
};
|
|
299
295
|
|
|
300
296
|
export const Lists = {
|
|
@@ -345,18 +341,18 @@ export const Mention = {
|
|
|
345
341
|
|
|
346
342
|
export const Comments = {
|
|
347
343
|
render: () => {
|
|
348
|
-
const [
|
|
344
|
+
const [_comments, setComments] = useState<Comment[]>([]);
|
|
349
345
|
|
|
350
346
|
return (
|
|
351
347
|
<Story
|
|
352
348
|
text={str('# Comments', '', text.paragraphs, text.footer)}
|
|
353
|
-
comments={
|
|
349
|
+
comments={_comments}
|
|
354
350
|
extensions={[
|
|
355
351
|
comments({
|
|
356
352
|
onHover: onCommentsHover,
|
|
357
353
|
onCreate: (range) => {
|
|
358
354
|
const id = PublicKey.random().toHex();
|
|
359
|
-
|
|
355
|
+
setComments((commentRanges) => [...commentRanges, { id, cursor: range }]);
|
|
360
356
|
return id;
|
|
361
357
|
},
|
|
362
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}
|
|
@@ -13,7 +13,7 @@ import React, { useEffect, useRef, useState } from 'react';
|
|
|
13
13
|
|
|
14
14
|
import { type Prop } from '@dxos/automerge/automerge';
|
|
15
15
|
import { Repo, type DocHandle } from '@dxos/automerge/automerge-repo';
|
|
16
|
-
import { Filter
|
|
16
|
+
import { Filter } from '@dxos/echo-schema';
|
|
17
17
|
import { type PublicKey } from '@dxos/keys';
|
|
18
18
|
import { Expando, TextObject, useSpace } from '@dxos/react-client/echo';
|
|
19
19
|
import { useIdentity } from '@dxos/react-client/halo';
|
|
@@ -130,7 +130,6 @@ const EchoStory = ({ id, spaceKey }: { id: number; spaceKey: PublicKey }) => {
|
|
|
130
130
|
|
|
131
131
|
export const WithEcho = {
|
|
132
132
|
render: () => {
|
|
133
|
-
setGlobalAutomergePreference(true);
|
|
134
133
|
return (
|
|
135
134
|
<ClientRepeater
|
|
136
135
|
count={2}
|
|
@@ -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}
|