@dxos/react-ui-editor 0.4.4-main.3a00f69 → 0.4.4-main.3e48778
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 +61 -50
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/MarkdownEditor.stories.d.ts +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +3 -3
- 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 +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/basic.d.ts +2 -1
- package/dist/types/src/extensions/basic.d.ts.map +1 -1
- package/dist/types/src/hooks/useEditorView.d.ts +6 -4
- package/dist/types/src/hooks/useEditorView.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/package.json +24 -24
- package/src/components/TextEditor/TextEditor.tsx +3 -3
- package/src/components/Toolbar/Toolbar.stories.tsx +3 -3
- package/src/extensions/automerge/cursor.ts +3 -2
- package/src/extensions/basic.ts +3 -1
- package/src/extensions/markdown/image.ts +1 -1
- package/src/hooks/useEditorView.ts +13 -11
- package/src/hooks/useTextModel.ts +3 -9
|
@@ -3,27 +3,29 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type EditorView } from '@codemirror/view';
|
|
6
|
-
import { type
|
|
6
|
+
import { type MutableRefObject, useRef, useState } from 'react';
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
* Hook for accessing the editor view.
|
|
10
10
|
*
|
|
11
11
|
* ```tsx
|
|
12
12
|
* const Test = () => {
|
|
13
|
-
* const [editorRef,
|
|
13
|
+
* const [editorRef, viewInvalidated] = useEditorView();
|
|
14
14
|
* useEffect(() => {
|
|
15
|
-
*
|
|
15
|
+
* if (editorRef.current && !viewInvalidated) {
|
|
16
|
+
* editorView?.focus();
|
|
17
|
+
* }
|
|
16
18
|
* }, [editorView]);
|
|
17
19
|
* return <TextEditor ref={editorRef} />;
|
|
18
20
|
* };
|
|
19
21
|
* ```
|
|
20
22
|
*/
|
|
21
|
-
export const useEditorView = (): [
|
|
22
|
-
const
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
];
|
|
23
|
+
export const useEditorView = (id: string): [MutableRefObject<EditorView | null>, boolean] => {
|
|
24
|
+
const editorRef = useRef<EditorView | null>(null);
|
|
25
|
+
const [prev, setPrev] = useState<[EditorView | null, string]>([null, '']);
|
|
26
|
+
if (prev[0] !== editorRef.current) {
|
|
27
|
+
setPrev([editorRef.current, id]);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
return [editorRef, prev[1] !== id];
|
|
29
31
|
};
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import get from 'lodash.get';
|
|
6
|
-
import { type Dispatch, type SetStateAction,
|
|
6
|
+
import { type Dispatch, type SetStateAction, useState, useMemo } from 'react';
|
|
7
7
|
|
|
8
8
|
import { generateName } from '@dxos/display-name';
|
|
9
9
|
import { type AutomergeTextCompat, getRawDoc } from '@dxos/echo-schema';
|
|
@@ -27,14 +27,8 @@ export type UseTextModelProps = {
|
|
|
27
27
|
* @deprecated
|
|
28
28
|
*/
|
|
29
29
|
// TODO(burdon): Remove once automerge lands.
|
|
30
|
-
export const useTextModel = (props: UseTextModelProps): EditorModel | undefined =>
|
|
31
|
-
|
|
32
|
-
const { identity, space, text } = props;
|
|
33
|
-
useEffect(() => {
|
|
34
|
-
setModel(createModel(props));
|
|
35
|
-
}, [identity, space, text]);
|
|
36
|
-
return model;
|
|
37
|
-
};
|
|
30
|
+
export const useTextModel = (props: UseTextModelProps): EditorModel | undefined =>
|
|
31
|
+
useMemo(() => createModel(props), Object.values(props));
|
|
38
32
|
|
|
39
33
|
/**
|
|
40
34
|
* For use primarily in stories & tests so the dependence on TextObject can be avoided.
|