@dxos/react-ui-editor 0.4.4-main.3a00f69 → 0.4.4-main.4468a54
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 +62 -51
- 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/dist/types/src/styles/layout.d.ts +1 -1
- package/dist/types/src/styles/layout.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
- package/src/styles/layout.ts +1 -1
package/src/extensions/basic.ts
CHANGED
|
@@ -16,18 +16,20 @@ import { type TextEditorProps } from '../components';
|
|
|
16
16
|
|
|
17
17
|
export type BasicBundleOptions = {
|
|
18
18
|
themeMode?: ThemeMode;
|
|
19
|
+
bracketMatching?: boolean;
|
|
19
20
|
} & Pick<TextEditorProps, 'placeholder' | 'lineWrapping'>;
|
|
20
21
|
|
|
21
22
|
export const createBasicBundle = ({
|
|
22
23
|
themeMode,
|
|
23
24
|
placeholder: _placeholder,
|
|
24
25
|
lineWrapping = true,
|
|
26
|
+
bracketMatching: _bracketMatching = true,
|
|
25
27
|
}: BasicBundleOptions = {}): Extension[] =>
|
|
26
28
|
[
|
|
27
29
|
lineWrapping && EditorView.lineWrapping,
|
|
28
30
|
|
|
29
31
|
// https://codemirror.net/docs/ref/#codemirror.minimalSetup
|
|
30
|
-
bracketMatching(),
|
|
32
|
+
_bracketMatching && bracketMatching(),
|
|
31
33
|
closeBrackets(),
|
|
32
34
|
drawSelection(),
|
|
33
35
|
highlightActiveLine(),
|
|
@@ -26,7 +26,7 @@ export const image = (options: ImageOptions = {}): Extension => {
|
|
|
26
26
|
from = Math.min(from, fromB);
|
|
27
27
|
to = Math.max(to, toB);
|
|
28
28
|
});
|
|
29
|
-
// Expand to cover lines
|
|
29
|
+
// Expand to cover lines.
|
|
30
30
|
from = tr.state.doc.lineAt(from).from;
|
|
31
31
|
to = tr.state.doc.lineAt(to).to;
|
|
32
32
|
return value.map(tr.changes).update({
|
|
@@ -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.
|
package/src/styles/layout.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
export const editorWithToolbarLayout =
|
|
6
|
-
'grid grid-cols-1 grid-rows-[min-content_1fr] justify-center content-start overflow-hidden';
|
|
6
|
+
'grid grid-cols-1 grid-rows-[min-content_1fr] data-[toolbar=disabled]:grid-rows-[1fr] justify-center content-start overflow-hidden';
|
|
7
7
|
|
|
8
8
|
export const editorFillLayoutRoot = 'min-bs-full grid';
|
|
9
9
|
export const editorFillLayoutEditor = 'min-bs-full';
|