@dxos/react-ui-chat 0.8.4-main.406dc2a → 0.8.4-main.52d7546f51
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 +144 -229
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +144 -229
- package/dist/lib/node-esm/index.mjs.map +3 -3
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.d.ts +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +2 -3
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -8
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +3 -3
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
- package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +36 -34
- package/src/components/ChatDialog/ChatDialog.stories.tsx +3 -4
- package/src/components/ChatDialog/ChatDialog.tsx +19 -13
- package/src/components/ChatEditor/ChatEditor.stories.tsx +18 -16
- package/src/components/ChatEditor/ChatEditor.tsx +31 -80
- package/src/components/ChatEditor/references.ts +17 -11
- package/src/translations.ts +1 -1
package/package.json
CHANGED
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dxos/react-ui-chat",
|
|
3
|
-
"version": "0.8.4-main.
|
|
3
|
+
"version": "0.8.4-main.52d7546f51",
|
|
4
4
|
"description": "Chat components.",
|
|
5
5
|
"homepage": "https://dxos.org",
|
|
6
6
|
"bugs": "https://github.com/dxos/dxos/issues",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/dxos/dxos"
|
|
10
|
+
},
|
|
7
11
|
"license": "MIT",
|
|
8
12
|
"author": "DXOS.org",
|
|
9
13
|
"type": "module",
|
|
@@ -29,46 +33,44 @@
|
|
|
29
33
|
"@codemirror/search": "^6.5.11",
|
|
30
34
|
"@codemirror/state": "^6.5.2",
|
|
31
35
|
"@codemirror/view": "^6.38.4",
|
|
32
|
-
"@fluentui/react-tabster": "
|
|
33
|
-
"@preact-signals/safe-react": "^0.9.0",
|
|
34
|
-
"@preact/signals-core": "^1.12.1",
|
|
36
|
+
"@fluentui/react-tabster": "9.26.11",
|
|
35
37
|
"@radix-ui/react-accordion": "1.2.3",
|
|
36
38
|
"@radix-ui/react-context": "1.1.1",
|
|
37
|
-
"@dxos/async": "0.8.4-main.
|
|
38
|
-
"@dxos/
|
|
39
|
-
"@dxos/
|
|
40
|
-
"@dxos/log": "0.8.4-main.
|
|
41
|
-
"@dxos/
|
|
42
|
-
"@dxos/
|
|
43
|
-
"@dxos/
|
|
44
|
-
"@dxos/react-ui
|
|
45
|
-
"@dxos/react-ui-
|
|
46
|
-
"@dxos/react-ui-
|
|
47
|
-
"@dxos/react-ui-
|
|
48
|
-
"@dxos/react-ui-
|
|
49
|
-
"@dxos/
|
|
50
|
-
"@dxos/
|
|
51
|
-
"@dxos/util": "0.8.4-main.
|
|
52
|
-
"@dxos/
|
|
39
|
+
"@dxos/async": "0.8.4-main.52d7546f51",
|
|
40
|
+
"@dxos/echo": "0.8.4-main.52d7546f51",
|
|
41
|
+
"@dxos/debug": "0.8.4-main.52d7546f51",
|
|
42
|
+
"@dxos/log": "0.8.4-main.52d7546f51",
|
|
43
|
+
"@dxos/invariant": "0.8.4-main.52d7546f51",
|
|
44
|
+
"@dxos/react-ui-dnd": "0.8.4-main.52d7546f51",
|
|
45
|
+
"@dxos/react-ui-components": "0.8.4-main.52d7546f51",
|
|
46
|
+
"@dxos/react-ui": "0.8.4-main.52d7546f51",
|
|
47
|
+
"@dxos/react-ui-sfx": "0.8.4-main.52d7546f51",
|
|
48
|
+
"@dxos/react-ui-text-tooltip": "0.8.4-main.52d7546f51",
|
|
49
|
+
"@dxos/react-ui-editor": "0.8.4-main.52d7546f51",
|
|
50
|
+
"@dxos/react-ui-syntax-highlighter": "0.8.4-main.52d7546f51",
|
|
51
|
+
"@dxos/ui-editor": "0.8.4-main.52d7546f51",
|
|
52
|
+
"@dxos/ui-theme": "0.8.4-main.52d7546f51",
|
|
53
|
+
"@dxos/util": "0.8.4-main.52d7546f51",
|
|
54
|
+
"@dxos/ui-types": "0.8.4-main.52d7546f51"
|
|
53
55
|
},
|
|
54
56
|
"devDependencies": {
|
|
55
|
-
"@types/react": "~19.2.
|
|
56
|
-
"@types/react-dom": "~19.2.
|
|
57
|
-
"effect": "3.
|
|
58
|
-
"react": "~19.2.
|
|
59
|
-
"react-dom": "~19.2.
|
|
57
|
+
"@types/react": "~19.2.7",
|
|
58
|
+
"@types/react-dom": "~19.2.3",
|
|
59
|
+
"effect": "3.19.16",
|
|
60
|
+
"react": "~19.2.3",
|
|
61
|
+
"react-dom": "~19.2.3",
|
|
60
62
|
"vite": "7.1.9",
|
|
61
|
-
"@dxos/echo": "0.8.4-main.
|
|
62
|
-
"@dxos/random": "0.8.4-main.
|
|
63
|
-
"@dxos/react-client": "0.8.4-main.
|
|
64
|
-
"@dxos/storybook-utils": "0.8.4-main.
|
|
63
|
+
"@dxos/echo": "0.8.4-main.52d7546f51",
|
|
64
|
+
"@dxos/random": "0.8.4-main.52d7546f51",
|
|
65
|
+
"@dxos/react-client": "0.8.4-main.52d7546f51",
|
|
66
|
+
"@dxos/storybook-utils": "0.8.4-main.52d7546f51"
|
|
65
67
|
},
|
|
66
68
|
"peerDependencies": {
|
|
67
|
-
"effect": "
|
|
68
|
-
"react": "
|
|
69
|
-
"react-dom": "
|
|
70
|
-
"@dxos/react-ui": "0.8.4-main.
|
|
71
|
-
"@dxos/
|
|
69
|
+
"effect": "3.19.16",
|
|
70
|
+
"react": "~19.2.3",
|
|
71
|
+
"react-dom": "~19.2.3",
|
|
72
|
+
"@dxos/react-ui": "0.8.4-main.52d7546f51",
|
|
73
|
+
"@dxos/ui-theme": "0.8.4-main.52d7546f51"
|
|
72
74
|
},
|
|
73
75
|
"publishConfig": {
|
|
74
76
|
"access": "public"
|
|
@@ -6,7 +6,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
|
|
|
6
6
|
import React, { useState } from 'react';
|
|
7
7
|
|
|
8
8
|
import { Input, Toolbar } from '@dxos/react-ui';
|
|
9
|
-
import { withTheme } from '@dxos/react-ui/testing';
|
|
9
|
+
import { withLayout, withTheme } from '@dxos/react-ui/testing';
|
|
10
10
|
|
|
11
11
|
import { translations } from '../../translations';
|
|
12
12
|
|
|
@@ -42,7 +42,7 @@ const meta = {
|
|
|
42
42
|
</div>
|
|
43
43
|
))}
|
|
44
44
|
</ChatDialog.Content>
|
|
45
|
-
<ChatDialog.Footer classNames='
|
|
45
|
+
<ChatDialog.Footer classNames='pli-2 items-center'>
|
|
46
46
|
<Input.Root>
|
|
47
47
|
<Input.TextInput classNames='border-none' placeholder='Test' />
|
|
48
48
|
</Input.Root>
|
|
@@ -51,9 +51,8 @@ const meta = {
|
|
|
51
51
|
</>
|
|
52
52
|
);
|
|
53
53
|
},
|
|
54
|
-
decorators: [withTheme],
|
|
54
|
+
decorators: [withTheme(), withLayout({ layout: 'column' })],
|
|
55
55
|
parameters: {
|
|
56
|
-
layout: 'column',
|
|
57
56
|
translations,
|
|
58
57
|
},
|
|
59
58
|
} satisfies Meta<typeof ChatDialog.Root>;
|
|
@@ -7,14 +7,14 @@ import React, { type Dispatch, type PropsWithChildren, type SetStateAction, useE
|
|
|
7
7
|
|
|
8
8
|
import { Dialog, Icon, IconButton, type ThemedClassName, useControlledState } from '@dxos/react-ui';
|
|
9
9
|
import { ResizeHandle, type Size, resizeAttributes, sizeStyle } from '@dxos/react-ui-dnd';
|
|
10
|
-
import { mx } from '@dxos/
|
|
10
|
+
import { mx } from '@dxos/ui-theme';
|
|
11
11
|
|
|
12
12
|
const preventDefault = (event: Event) => event.preventDefault();
|
|
13
13
|
|
|
14
14
|
// TODO(burdon): Factor out.
|
|
15
15
|
const Endcap = ({ children }: PropsWithChildren) => {
|
|
16
16
|
return (
|
|
17
|
-
<div className='grid
|
|
17
|
+
<div className='grid is-[var(--rail-action)] bs-[var(--rail-action)] items-center justify-center'>{children}</div>
|
|
18
18
|
);
|
|
19
19
|
};
|
|
20
20
|
|
|
@@ -47,15 +47,15 @@ type ChatDialogRootProps = PropsWithChildren<{
|
|
|
47
47
|
|
|
48
48
|
const ChatDialogRoot = ({
|
|
49
49
|
children,
|
|
50
|
-
open:
|
|
51
|
-
expanded:
|
|
50
|
+
open: openProp = false,
|
|
51
|
+
expanded: expandedProp = false,
|
|
52
52
|
onOpenChange,
|
|
53
53
|
onExpandedChange,
|
|
54
54
|
onEscape,
|
|
55
55
|
}: ChatDialogRootProps) => {
|
|
56
56
|
const [size, setSize] = useState<Size>('min-content');
|
|
57
|
-
const [open, setOpen] = useControlledState<boolean>(
|
|
58
|
-
const [expanded, setExpanded] = useControlledState<boolean>(
|
|
57
|
+
const [open, setOpen] = useControlledState<boolean>(openProp, onOpenChange);
|
|
58
|
+
const [expanded, setExpanded] = useControlledState<boolean>(expandedProp, onExpandedChange);
|
|
59
59
|
|
|
60
60
|
// NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.
|
|
61
61
|
// The dialog has no vertical padding and has box-content so that when closed it collapses to the size of the header and prompt bar.
|
|
@@ -93,12 +93,14 @@ ChatDialogRoot.displayName = 'ChatDialog.Root';
|
|
|
93
93
|
// Header
|
|
94
94
|
//
|
|
95
95
|
|
|
96
|
+
const CHAT_DIALOG_HEADER_NAME = 'ChatDialog.Header';
|
|
97
|
+
|
|
96
98
|
type ChatDialogHeaderProps = ThemedClassName<{
|
|
97
99
|
title?: string;
|
|
98
100
|
}>;
|
|
99
101
|
|
|
100
102
|
const ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {
|
|
101
|
-
const { expanded, setExpanded } = useChatDialogContext(
|
|
103
|
+
const { expanded, setExpanded } = useChatDialogContext(CHAT_DIALOG_HEADER_NAME);
|
|
102
104
|
|
|
103
105
|
return (
|
|
104
106
|
<div className={mx('grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}>
|
|
@@ -108,7 +110,7 @@ const ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {
|
|
|
108
110
|
</Dialog.Close>
|
|
109
111
|
</Endcap>
|
|
110
112
|
<Dialog.Title
|
|
111
|
-
classNames='flex
|
|
113
|
+
classNames='flex is-full justify-center text-sm text-subdued select-none cursor-pointer'
|
|
112
114
|
onClick={() => setExpanded((expanded) => !expanded)}
|
|
113
115
|
>
|
|
114
116
|
{title}
|
|
@@ -127,16 +129,18 @@ const ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {
|
|
|
127
129
|
);
|
|
128
130
|
};
|
|
129
131
|
|
|
130
|
-
ChatDialogHeader.displayName =
|
|
132
|
+
ChatDialogHeader.displayName = CHAT_DIALOG_HEADER_NAME;
|
|
131
133
|
|
|
132
134
|
//
|
|
133
135
|
// Content
|
|
134
136
|
//
|
|
135
137
|
|
|
138
|
+
const CHAT_DIALOG_CONTENT_NAME = 'ChatDialog.Content';
|
|
139
|
+
|
|
136
140
|
type ChatDialogContentProps = ThemedClassName<PropsWithChildren>;
|
|
137
141
|
|
|
138
142
|
const ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {
|
|
139
|
-
const { expanded, size, setSize } = useChatDialogContext(
|
|
143
|
+
const { expanded, size, setSize } = useChatDialogContext(CHAT_DIALOG_CONTENT_NAME);
|
|
140
144
|
useEffect(() => {
|
|
141
145
|
setSize(expanded ? 'min-content' : 0);
|
|
142
146
|
}, [expanded]);
|
|
@@ -144,7 +148,7 @@ const ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) =>
|
|
|
144
148
|
return (
|
|
145
149
|
<div
|
|
146
150
|
className={mx(
|
|
147
|
-
'
|
|
151
|
+
'border-bs border-be border-subduedSeparator',
|
|
148
152
|
'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200',
|
|
149
153
|
classNames,
|
|
150
154
|
)}
|
|
@@ -167,19 +171,21 @@ const ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) =>
|
|
|
167
171
|
);
|
|
168
172
|
};
|
|
169
173
|
|
|
170
|
-
ChatDialogContent.displayName =
|
|
174
|
+
ChatDialogContent.displayName = CHAT_DIALOG_CONTENT_NAME;
|
|
171
175
|
|
|
172
176
|
//
|
|
173
177
|
// Footer
|
|
174
178
|
//
|
|
175
179
|
|
|
180
|
+
const CHAT_DIALOG_FOOTER_NAME = 'ChatDialog.Footer';
|
|
181
|
+
|
|
176
182
|
type ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;
|
|
177
183
|
|
|
178
184
|
const ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {
|
|
179
185
|
return <div className={mx(classNames)}>{children}</div>;
|
|
180
186
|
};
|
|
181
187
|
|
|
182
|
-
ChatDialogFooter.displayName =
|
|
188
|
+
ChatDialogFooter.displayName = CHAT_DIALOG_FOOTER_NAME;
|
|
183
189
|
|
|
184
190
|
//
|
|
185
191
|
// ChatDialog
|
|
@@ -15,7 +15,7 @@ import { type ReferenceData } from './references';
|
|
|
15
15
|
const meta = {
|
|
16
16
|
title: 'ui/react-ui-chat/ChatEditor',
|
|
17
17
|
component: ChatEditor,
|
|
18
|
-
decorators: [withTheme],
|
|
18
|
+
decorators: [withTheme()],
|
|
19
19
|
parameters: {
|
|
20
20
|
layout: 'centered',
|
|
21
21
|
translations,
|
|
@@ -24,7 +24,7 @@ const meta = {
|
|
|
24
24
|
|
|
25
25
|
export default meta;
|
|
26
26
|
|
|
27
|
-
const classNames = '
|
|
27
|
+
const classNames = 'is-[20rem] p-2 border border-separator';
|
|
28
28
|
|
|
29
29
|
type Story = StoryObj<typeof meta>;
|
|
30
30
|
|
|
@@ -34,31 +34,33 @@ export const Default: Story = {
|
|
|
34
34
|
},
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
+
// TODO(burdon): Restore and reconcile with suggest/typeahead.
|
|
37
38
|
export const WithSuggestions: Story = {
|
|
38
39
|
args: {
|
|
39
40
|
classNames,
|
|
40
41
|
onSubmit: (text) => {
|
|
41
42
|
log('onSubmit', { text });
|
|
42
43
|
},
|
|
43
|
-
onSuggest: (text) => {
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
44
|
+
// onSuggest: (text) => {
|
|
45
|
+
// const trimmed = text.trim().toLowerCase();
|
|
46
|
+
// if (trimmed.length < 2) {
|
|
47
|
+
// return [];
|
|
48
|
+
// }
|
|
48
49
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
50
|
+
// const suggestions = [
|
|
51
|
+
// 'Create a kanban board',
|
|
52
|
+
// 'Create a new project',
|
|
53
|
+
// 'Find flights to Tokyo',
|
|
54
|
+
// "Let's play chess",
|
|
55
|
+
// 'Show me Paris on a map',
|
|
56
|
+
// ];
|
|
56
57
|
|
|
57
|
-
|
|
58
|
-
},
|
|
58
|
+
// return suggestions.filter((s) => s.toLowerCase().startsWith(text));
|
|
59
|
+
// },
|
|
59
60
|
},
|
|
60
61
|
};
|
|
61
62
|
|
|
63
|
+
// TODO(burdon): Replace.
|
|
62
64
|
const references: ReferenceData[] = [
|
|
63
65
|
{
|
|
64
66
|
uri: 'dxn:echo:@:AAAAAAAA',
|
|
@@ -3,104 +3,55 @@
|
|
|
3
3
|
//
|
|
4
4
|
|
|
5
5
|
import { type Extension } from '@codemirror/state';
|
|
6
|
-
import {
|
|
7
|
-
import { useFocusFinders } from '@fluentui/react-tabster';
|
|
8
|
-
import React, { forwardRef, useImperativeHandle } from 'react';
|
|
6
|
+
import React, { forwardRef, useMemo } from 'react';
|
|
9
7
|
|
|
10
8
|
import { type ThemedClassName, useThemeContext } from '@dxos/react-ui';
|
|
9
|
+
import { Editor, type EditorController, type UseTextEditorProps } from '@dxos/react-ui-editor';
|
|
11
10
|
import {
|
|
12
|
-
type AutocompleteOptions,
|
|
13
11
|
type BasicExtensionsOptions,
|
|
14
|
-
type
|
|
15
|
-
autocomplete,
|
|
12
|
+
type SubmitOptions,
|
|
16
13
|
createBasicExtensions,
|
|
17
14
|
createThemeExtensions,
|
|
18
|
-
|
|
19
|
-
} from '@dxos/
|
|
20
|
-
import { mx } from '@dxos/react-ui-theme';
|
|
15
|
+
submit,
|
|
16
|
+
} from '@dxos/ui-editor';
|
|
21
17
|
import { isTruthy } from '@dxos/util';
|
|
22
18
|
|
|
23
|
-
import { type ReferencesOptions
|
|
19
|
+
import { type ReferencesOptions } from './references';
|
|
24
20
|
|
|
25
|
-
export interface ChatEditorController {
|
|
26
|
-
focus(): void;
|
|
27
|
-
getText(): string;
|
|
28
|
-
setText(text: string): void;
|
|
29
|
-
}
|
|
21
|
+
export interface ChatEditorController extends EditorController {}
|
|
30
22
|
|
|
31
23
|
export type ChatEditorProps = ThemedClassName<
|
|
32
24
|
{
|
|
33
25
|
extensions?: Extension;
|
|
34
26
|
references?: ReferencesOptions;
|
|
35
|
-
} &
|
|
27
|
+
} & (SubmitOptions &
|
|
36
28
|
Pick<UseTextEditorProps, 'id' | 'autoFocus'> &
|
|
37
|
-
Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>
|
|
29
|
+
Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>)
|
|
38
30
|
>;
|
|
39
31
|
|
|
32
|
+
export const useChatExtensions = ({ extensions, lineWrapping = false, placeholder, onSubmit }: ChatEditorProps) => {
|
|
33
|
+
const { themeMode } = useThemeContext();
|
|
34
|
+
return useMemo<Extension[]>(
|
|
35
|
+
() =>
|
|
36
|
+
[
|
|
37
|
+
createThemeExtensions({ themeMode }),
|
|
38
|
+
createBasicExtensions({ bracketMatching: false, lineWrapping, placeholder }),
|
|
39
|
+
submit({ onSubmit }),
|
|
40
|
+
extensions,
|
|
41
|
+
].filter(isTruthy),
|
|
42
|
+
[themeMode, extensions, onSubmit],
|
|
43
|
+
);
|
|
44
|
+
};
|
|
45
|
+
|
|
40
46
|
export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
|
|
41
|
-
(
|
|
42
|
-
{
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
debug: true,
|
|
50
|
-
autoFocus,
|
|
51
|
-
extensions: [
|
|
52
|
-
createThemeExtensions({ themeMode }),
|
|
53
|
-
createBasicExtensions({ bracketMatching: false, lineWrapping, placeholder }),
|
|
54
|
-
autocomplete({ onSubmit, onSuggest, onCancel }),
|
|
55
|
-
references ? referencesExtension({ provider: references.provider }) : [],
|
|
56
|
-
// TODO(burdon): Standardize.
|
|
57
|
-
keymap.of([
|
|
58
|
-
{
|
|
59
|
-
key: 'Tab',
|
|
60
|
-
preventDefault: true,
|
|
61
|
-
run: (view) => {
|
|
62
|
-
findNextFocusable(view.dom)?.focus();
|
|
63
|
-
return true;
|
|
64
|
-
},
|
|
65
|
-
},
|
|
66
|
-
{
|
|
67
|
-
key: 'Shift-Tab',
|
|
68
|
-
preventDefault: true,
|
|
69
|
-
run: (view) => {
|
|
70
|
-
findPrevFocusable(view.dom)?.focus();
|
|
71
|
-
return true;
|
|
72
|
-
},
|
|
73
|
-
},
|
|
74
|
-
]),
|
|
75
|
-
extensions,
|
|
76
|
-
].filter(isTruthy),
|
|
77
|
-
}),
|
|
78
|
-
[themeMode, extensions, onSubmit, onSuggest, onCancel],
|
|
47
|
+
({ classNames, autoFocus, extensions: extensionsProp, lineWrapping = false, placeholder, onSubmit }, forwardRef) => {
|
|
48
|
+
const extensions = useChatExtensions({ extensions: extensionsProp, lineWrapping, placeholder, onSubmit });
|
|
49
|
+
|
|
50
|
+
// TODO(burdon): Popover.
|
|
51
|
+
return (
|
|
52
|
+
<Editor.Root ref={forwardRef}>
|
|
53
|
+
<Editor.Content classNames={classNames} autoFocus={autoFocus} extensions={extensions} />
|
|
54
|
+
</Editor.Root>
|
|
79
55
|
);
|
|
80
|
-
|
|
81
|
-
// Expose editor view.
|
|
82
|
-
useImperativeHandle(forwardRef, () => {
|
|
83
|
-
return {
|
|
84
|
-
focus: () => {
|
|
85
|
-
view?.focus();
|
|
86
|
-
},
|
|
87
|
-
getText: () => view?.state.doc.toString() ?? '',
|
|
88
|
-
setText: (text: string) => {
|
|
89
|
-
view?.dispatch({
|
|
90
|
-
changes: {
|
|
91
|
-
from: 0,
|
|
92
|
-
to: view.state.doc.length,
|
|
93
|
-
insert: text,
|
|
94
|
-
},
|
|
95
|
-
selection: {
|
|
96
|
-
anchor: text.length,
|
|
97
|
-
head: text.length,
|
|
98
|
-
},
|
|
99
|
-
});
|
|
100
|
-
},
|
|
101
|
-
};
|
|
102
|
-
}, [view, onSubmit]);
|
|
103
|
-
|
|
104
|
-
return <div ref={parentRef} className={mx('is-full', classNames)} />;
|
|
105
56
|
},
|
|
106
57
|
);
|
|
@@ -19,10 +19,14 @@ import { invariant } from '@dxos/invariant';
|
|
|
19
19
|
|
|
20
20
|
// TODO(dmaretskyi): Consider adding details renderer for when you hover over the reference.
|
|
21
21
|
export type ReferenceData = {
|
|
22
|
-
uri: string;
|
|
22
|
+
uri: string; // TODO(burdon): Rename dxn.
|
|
23
23
|
label: string;
|
|
24
24
|
};
|
|
25
25
|
|
|
26
|
+
/**
|
|
27
|
+
* @deprecated
|
|
28
|
+
*/
|
|
29
|
+
// TODO(burdon): Remove.
|
|
26
30
|
export interface ReferencesProvider {
|
|
27
31
|
getReferences({ query }: { query: string }): Promise<ReferenceData[]>;
|
|
28
32
|
resolveReference({ uri }: { uri: string }): Promise<ReferenceData | null>;
|
|
@@ -45,7 +49,9 @@ export type ReferencesOptions = {
|
|
|
45
49
|
|
|
46
50
|
/**
|
|
47
51
|
* Lookup object references.
|
|
52
|
+
* @deprecated
|
|
48
53
|
*/
|
|
54
|
+
// TODO(burdon): Remove.
|
|
49
55
|
export const references = ({ provider, triggerCharacter = '@', debug = false }: ReferencesOptions): Extension => {
|
|
50
56
|
invariant(triggerCharacter.length === 1);
|
|
51
57
|
|
|
@@ -103,7 +109,7 @@ export const references = ({ provider, triggerCharacter = '@', debug = false }:
|
|
|
103
109
|
},
|
|
104
110
|
{
|
|
105
111
|
decorations: (v) => v.decorations,
|
|
106
|
-
provide: (
|
|
112
|
+
provide: () => [
|
|
107
113
|
EditorView.atomicRanges.of(
|
|
108
114
|
(view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,
|
|
109
115
|
),
|
|
@@ -158,18 +164,18 @@ class ReferenceWidget extends WidgetType {
|
|
|
158
164
|
super();
|
|
159
165
|
}
|
|
160
166
|
|
|
161
|
-
override
|
|
162
|
-
|
|
163
|
-
span.textContent = `@ ${this.data.label}`;
|
|
164
|
-
span.className = 'cm-reference-pill';
|
|
165
|
-
return span;
|
|
167
|
+
override ignoreEvent() {
|
|
168
|
+
return true;
|
|
166
169
|
}
|
|
167
170
|
|
|
168
|
-
override eq(other:
|
|
169
|
-
return
|
|
171
|
+
override eq(other: this) {
|
|
172
|
+
return this.data.uri === other.data.uri;
|
|
170
173
|
}
|
|
171
174
|
|
|
172
|
-
override
|
|
173
|
-
|
|
175
|
+
override toDOM() {
|
|
176
|
+
const span = document.createElement('span');
|
|
177
|
+
span.textContent = `@${this.data.label}`;
|
|
178
|
+
span.className = 'cm-reference-pill';
|
|
179
|
+
return span;
|
|
174
180
|
}
|
|
175
181
|
}
|