@dxos/react-ui-editor 0.4.6-main.aeca3cc → 0.4.6-main.e47f68d
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 +143 -96
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/types/src/components/TextEditor/TextEditor.d.ts +2 -0
- package/dist/types/src/components/TextEditor/TextEditor.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts +3 -5
- package/dist/types/src/components/TextEditor/automerge.stories.d.ts.map +1 -1
- package/dist/types/src/components/TextEditor/hooks.stories.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.d.ts.map +1 -1
- package/dist/types/src/components/Toolbar/Toolbar.stories.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/automerge.d.ts +2 -7
- package/dist/types/src/extensions/automerge/automerge.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/cursor.d.ts +2 -3
- package/dist/types/src/extensions/automerge/cursor.d.ts.map +1 -1
- package/dist/types/src/extensions/automerge/defs.d.ts +9 -2
- package/dist/types/src/extensions/automerge/defs.d.ts.map +1 -1
- package/dist/types/src/hooks/defs.d.ts +1 -0
- package/dist/types/src/hooks/defs.d.ts.map +1 -1
- package/dist/types/src/hooks/useEditorView.d.ts +1 -0
- package/dist/types/src/hooks/useEditorView.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextEditor.d.ts +3 -3
- package/dist/types/src/hooks/useTextEditor.d.ts.map +1 -1
- package/dist/types/src/hooks/useTextModel.d.ts +12 -4
- package/dist/types/src/hooks/useTextModel.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -1
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/styles/layout.d.ts +2 -3
- package/dist/types/src/styles/layout.d.ts.map +1 -1
- package/dist/types/src/themes/default.d.ts.map +1 -1
- package/package.json +26 -25
- package/src/components/TextEditor/MarkdownEditor.stories.tsx +1 -1
- package/src/components/TextEditor/TextEditor.tsx +36 -18
- package/src/components/TextEditor/automerge.stories.tsx +15 -16
- package/src/components/TextEditor/hooks.stories.tsx +11 -8
- package/src/components/Toolbar/Toolbar.stories.tsx +9 -6
- package/src/components/Toolbar/Toolbar.tsx +22 -2
- package/src/extensions/automerge/automerge.ts +10 -15
- package/src/extensions/automerge/cursor.ts +2 -3
- package/src/extensions/automerge/defs.ts +15 -2
- package/src/hooks/defs.ts +2 -0
- package/src/hooks/useEditorView.ts +2 -0
- package/src/hooks/useTextEditor.ts +8 -12
- package/src/hooks/useTextModel.ts +34 -5
- package/src/index.ts +1 -7
- package/src/styles/layout.ts +2 -5
- package/src/themes/default.ts +14 -3
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Copyright 2023 DXOS.org
|
|
3
3
|
//
|
|
4
4
|
|
|
5
|
+
import { type Extension } from '@codemirror/state';
|
|
5
6
|
import get from 'lodash.get';
|
|
6
7
|
import { type Dispatch, type SetStateAction, useState, useMemo } from 'react';
|
|
7
8
|
|
|
@@ -14,13 +15,42 @@ import { type Identity } from '@dxos/react-client/halo';
|
|
|
14
15
|
import { SpaceAwarenessProvider } from './awareness-provider';
|
|
15
16
|
import { type EditorModel, modelState } from './defs';
|
|
16
17
|
import { automerge, awareness } from '../extensions';
|
|
18
|
+
import { type DocAccessor } from '../extensions/automerge/defs';
|
|
17
19
|
import { cursorColor } from '../styles';
|
|
18
20
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
21
|
+
export type useTextExtensionsProps = {
|
|
22
|
+
id: string;
|
|
23
|
+
text: DocAccessor;
|
|
22
24
|
space?: Space;
|
|
25
|
+
identity?: Identity;
|
|
26
|
+
};
|
|
27
|
+
|
|
28
|
+
// TODO(burdon): Factor out automerge defs and extension (not hook).
|
|
29
|
+
export const useTextExtensions = ({ id, text, space, identity }: useTextExtensionsProps): Extension[] => {
|
|
30
|
+
const extensions: Extension[] = [automerge(text)];
|
|
31
|
+
|
|
32
|
+
if (space && identity) {
|
|
33
|
+
const awarenessProvider = new SpaceAwarenessProvider({
|
|
34
|
+
space,
|
|
35
|
+
channel: `awareness.${id}`,
|
|
36
|
+
peerId: identity.identityKey.toHex(),
|
|
37
|
+
info: {
|
|
38
|
+
displayName: identity.profile?.displayName ?? generateName(identity.identityKey.toHex()),
|
|
39
|
+
color: cursorColor.color,
|
|
40
|
+
lightColor: cursorColor.light,
|
|
41
|
+
},
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
extensions.push(awareness(awarenessProvider));
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
return extensions;
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
export type UseTextModelProps = {
|
|
23
51
|
text?: TextObject;
|
|
52
|
+
space?: Space;
|
|
53
|
+
identity?: Identity | null;
|
|
24
54
|
};
|
|
25
55
|
|
|
26
56
|
/**
|
|
@@ -32,8 +62,7 @@ export const useTextModel = (props: UseTextModelProps): EditorModel | undefined
|
|
|
32
62
|
|
|
33
63
|
/**
|
|
34
64
|
* For use primarily in stories & tests so the dependence on TextObject can be avoided.
|
|
35
|
-
* @
|
|
36
|
-
* @param defaultContent
|
|
65
|
+
* @deprecated
|
|
37
66
|
*/
|
|
38
67
|
export const useInMemoryTextModel = ({
|
|
39
68
|
id,
|
package/src/index.ts
CHANGED
|
@@ -12,13 +12,7 @@ export { Doc, YText, YXmlFragment } from '@dxos/text-model';
|
|
|
12
12
|
export * from './components';
|
|
13
13
|
export * from './extensions';
|
|
14
14
|
export * from './hooks';
|
|
15
|
-
export {
|
|
16
|
-
getToken,
|
|
17
|
-
editorWithToolbarLayout,
|
|
18
|
-
editorFillLayoutEditor,
|
|
19
|
-
editorFillLayoutRoot,
|
|
20
|
-
editorHalfViewportOverscrollContent,
|
|
21
|
-
} from './styles';
|
|
15
|
+
export { getToken, editorWithToolbarLayout, editorFillLayoutRoot, editorFillLayoutEditor } from './styles';
|
|
22
16
|
export * from './themes';
|
|
23
17
|
export * from './util';
|
|
24
18
|
export { translations };
|
package/src/styles/layout.ts
CHANGED
|
@@ -5,8 +5,5 @@
|
|
|
5
5
|
export const editorWithToolbarLayout =
|
|
6
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
|
-
export const editorFillLayoutRoot = 'bs-full
|
|
9
|
-
export const editorFillLayoutEditor =
|
|
10
|
-
'bs-full overflow-hidden [&>.cm-scroller]:bs-full [&>.cm-scroller]:overflow-y-auto';
|
|
11
|
-
|
|
12
|
-
export const editorHalfViewportOverscrollContent = 'after:block after:min-bs-[50dvh] after:pointer-events-none';
|
|
8
|
+
export const editorFillLayoutRoot = 'bs-full relative';
|
|
9
|
+
export const editorFillLayoutEditor = '!absolute inset-0';
|
package/src/themes/default.ts
CHANGED
|
@@ -50,14 +50,18 @@ export const defaultTheme: ThemeStyles = {
|
|
|
50
50
|
outline: 'none',
|
|
51
51
|
},
|
|
52
52
|
|
|
53
|
+
// NOTE: See https://codemirror.net/docs/guide (DOM Structure).
|
|
53
54
|
'.cm-scroller': {
|
|
54
|
-
//
|
|
55
|
+
// TODO(burdon): Reconcile with docs: https://codemirror.net/docs/guide
|
|
56
|
+
// Inside of that is the scroller element. If the editor has its own scrollbar, this one should be styled with overflow: auto. But it doesn't have to—the editor also supports growing to accomodate its content, or growing up to a certain max-height and then scrolling.
|
|
57
|
+
overflowY: 'auto',
|
|
55
58
|
fontFamily: get(tokens, 'fontFamily.mono', []).join(','),
|
|
56
|
-
lineHeight: 1.
|
|
59
|
+
lineHeight: 1.5,
|
|
57
60
|
},
|
|
58
61
|
|
|
59
62
|
'.cm-content': {
|
|
60
|
-
|
|
63
|
+
// TODO(burdon): Is it possible to remove the padding value from CM's default theme?
|
|
64
|
+
// padding: 'unset',
|
|
61
65
|
// NOTE: Base font size (otherwise defined by HTML tag, which might be different for storybook).
|
|
62
66
|
fontSize: '16px',
|
|
63
67
|
},
|
|
@@ -96,6 +100,13 @@ export const defaultTheme: ThemeStyles = {
|
|
|
96
100
|
background: 'transparent',
|
|
97
101
|
},
|
|
98
102
|
|
|
103
|
+
//
|
|
104
|
+
// gutter
|
|
105
|
+
//
|
|
106
|
+
'.cm-gutterElement': {
|
|
107
|
+
width: '48px',
|
|
108
|
+
},
|
|
109
|
+
|
|
99
110
|
//
|
|
100
111
|
// Selection
|
|
101
112
|
//
|