@dxos/react-ui-chat 0.8.4-main.ead640a → 0.8.4-main.effb148878

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.
Files changed (52) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/index.mjs +231 -245
  3. package/dist/lib/browser/index.mjs.map +4 -4
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/translations.mjs +14 -0
  6. package/dist/lib/browser/translations.mjs.map +7 -0
  7. package/dist/lib/node-esm/index.mjs +231 -245
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/lib/node-esm/translations.mjs +16 -0
  11. package/dist/lib/node-esm/translations.mjs.map +7 -0
  12. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts +17 -1
  13. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
  14. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +2 -2
  15. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
  16. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -8
  17. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
  18. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +3 -3
  19. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
  21. package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
  22. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts +40 -0
  23. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts.map +1 -0
  24. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts +27 -0
  25. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts.map +1 -0
  26. package/dist/types/src/components/ChatStatus/format.d.ts +7 -0
  27. package/dist/types/src/components/ChatStatus/format.d.ts.map +1 -0
  28. package/dist/types/src/components/ChatStatus/format.test.d.ts +2 -0
  29. package/dist/types/src/components/ChatStatus/format.test.d.ts.map +1 -0
  30. package/dist/types/src/components/ChatStatus/index.d.ts +3 -0
  31. package/dist/types/src/components/ChatStatus/index.d.ts.map +1 -0
  32. package/dist/types/src/components/index.d.ts +1 -0
  33. package/dist/types/src/components/index.d.ts.map +1 -1
  34. package/dist/types/src/index.d.ts +0 -1
  35. package/dist/types/src/index.d.ts.map +1 -1
  36. package/dist/types/src/translations.d.ts +2 -2
  37. package/dist/types/src/translations.d.ts.map +1 -1
  38. package/dist/types/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +52 -44
  40. package/src/components/ChatDialog/ChatDialog.stories.tsx +3 -3
  41. package/src/components/ChatDialog/ChatDialog.tsx +28 -18
  42. package/src/components/ChatEditor/ChatEditor.stories.tsx +19 -17
  43. package/src/components/ChatEditor/ChatEditor.tsx +33 -80
  44. package/src/components/ChatEditor/references.ts +18 -12
  45. package/src/components/ChatStatus/ChatStatus.stories.tsx +130 -0
  46. package/src/components/ChatStatus/ChatStatus.tsx +183 -0
  47. package/src/components/ChatStatus/format.test.ts +48 -0
  48. package/src/components/ChatStatus/format.ts +27 -0
  49. package/src/components/ChatStatus/index.ts +6 -0
  50. package/src/components/index.ts +1 -0
  51. package/src/index.ts +0 -1
  52. package/src/translations.ts +1 -1
package/package.json CHANGED
@@ -1,74 +1,82 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-chat",
3
- "version": "0.8.4-main.ead640a",
3
+ "version": "0.8.4-main.effb148878",
4
4
  "description": "Chat components.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
7
- "license": "MIT",
7
+ "repository": {
8
+ "type": "git",
9
+ "url": "https://github.com/dxos/dxos"
10
+ },
11
+ "license": "FSL-1.1-Apache-2.0",
8
12
  "author": "DXOS.org",
9
13
  "type": "module",
14
+ "imports": {
15
+ "#translations": "./src/translations.ts"
16
+ },
10
17
  "exports": {
11
18
  ".": {
12
19
  "source": "./src/index.ts",
13
20
  "types": "./dist/types/src/index.d.ts",
14
21
  "browser": "./dist/lib/browser/index.mjs",
15
22
  "node": "./dist/lib/node-esm/index.mjs"
23
+ },
24
+ "./translations": {
25
+ "source": "./src/translations.ts",
26
+ "types": "./dist/types/src/translations.d.ts",
27
+ "browser": "./dist/lib/browser/translations.mjs",
28
+ "node": "./dist/lib/node-esm/translations.mjs"
16
29
  }
17
30
  },
18
31
  "types": "dist/types/src/index.d.ts",
19
- "typesVersions": {
20
- "*": {}
21
- },
22
32
  "files": [
23
33
  "dist",
24
34
  "src"
25
35
  ],
26
36
  "dependencies": {
27
- "@codemirror/autocomplete": "^6.19.0",
28
- "@codemirror/language": "^6.11.3",
29
- "@codemirror/search": "^6.5.11",
30
- "@codemirror/state": "^6.5.2",
31
- "@codemirror/view": "^6.38.4",
32
- "@fluentui/react-tabster": "^9.24.2",
33
- "@preact-signals/safe-react": "^0.9.0",
34
- "@preact/signals-core": "^1.12.1",
37
+ "@codemirror/autocomplete": "^6.20.2",
38
+ "@codemirror/language": "^6.12.3",
39
+ "@codemirror/search": "^6.7.0",
40
+ "@codemirror/state": "^6.6.0",
41
+ "@codemirror/view": "^6.43.0",
42
+ "@fluentui/react-tabster": "9.26.11",
35
43
  "@radix-ui/react-accordion": "1.2.3",
36
44
  "@radix-ui/react-context": "1.1.1",
37
- "@dxos/async": "0.8.4-main.ead640a",
38
- "@dxos/debug": "0.8.4-main.ead640a",
39
- "@dxos/echo": "0.8.4-main.ead640a",
40
- "@dxos/live-object": "0.8.4-main.ead640a",
41
- "@dxos/log": "0.8.4-main.ead640a",
42
- "@dxos/react-ui": "0.8.4-main.ead640a",
43
- "@dxos/react-ui-components": "0.8.4-main.ead640a",
44
- "@dxos/invariant": "0.8.4-main.ead640a",
45
- "@dxos/react-ui-dnd": "0.8.4-main.ead640a",
46
- "@dxos/react-ui-sfx": "0.8.4-main.ead640a",
47
- "@dxos/react-ui-editor": "0.8.4-main.ead640a",
48
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.ead640a",
49
- "@dxos/react-ui-text-tooltip": "0.8.4-main.ead640a",
50
- "@dxos/util": "0.8.4-main.ead640a",
51
- "@dxos/react-ui-types": "0.8.4-main.ead640a",
52
- "@dxos/react-ui-theme": "0.8.4-main.ead640a"
45
+ "@dxos/async": "0.8.4-main.effb148878",
46
+ "@dxos/debug": "0.8.4-main.effb148878",
47
+ "@dxos/echo": "0.8.4-main.effb148878",
48
+ "@dxos/invariant": "0.8.4-main.effb148878",
49
+ "@dxos/log": "0.8.4-main.effb148878",
50
+ "@dxos/react-ui-dnd": "0.8.4-main.effb148878",
51
+ "@dxos/react-ui-components": "0.8.4-main.effb148878",
52
+ "@dxos/react-ui": "0.8.4-main.effb148878",
53
+ "@dxos/react-ui-editor": "0.8.4-main.effb148878",
54
+ "@dxos/react-ui-text-tooltip": "0.8.4-main.effb148878",
55
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.effb148878",
56
+ "@dxos/ui-editor": "0.8.4-main.effb148878",
57
+ "@dxos/ui-theme": "0.8.4-main.effb148878",
58
+ "@dxos/util": "0.8.4-main.effb148878",
59
+ "@dxos/ui-types": "0.8.4-main.effb148878",
60
+ "@dxos/react-ui-sfx": "0.8.4-main.effb148878"
53
61
  },
54
62
  "devDependencies": {
55
- "@types/react": "~19.2.2",
56
- "@types/react-dom": "~19.2.1",
57
- "effect": "3.18.3",
58
- "react": "~19.2.0",
59
- "react-dom": "~19.2.0",
60
- "vite": "7.1.9",
61
- "@dxos/echo": "0.8.4-main.ead640a",
62
- "@dxos/random": "0.8.4-main.ead640a",
63
- "@dxos/storybook-utils": "0.8.4-main.ead640a",
64
- "@dxos/react-client": "0.8.4-main.ead640a"
63
+ "@types/react": "~19.2.7",
64
+ "@types/react-dom": "~19.2.3",
65
+ "effect": "3.20.0",
66
+ "react": "~19.2.3",
67
+ "react-dom": "~19.2.3",
68
+ "vite": "^8.0.14",
69
+ "@dxos/react-client": "0.8.4-main.effb148878",
70
+ "@dxos/echo": "0.8.4-main.effb148878",
71
+ "@dxos/storybook-utils": "0.8.4-main.effb148878",
72
+ "@dxos/random": "0.8.4-main.effb148878"
65
73
  },
66
74
  "peerDependencies": {
67
- "effect": "^3.13.3",
68
- "react": "^19.0.0",
69
- "react-dom": "^19.0.0",
70
- "@dxos/react-ui": "0.8.4-main.ead640a",
71
- "@dxos/react-ui-theme": "0.8.4-main.ead640a"
75
+ "effect": "3.20.0",
76
+ "react": "~19.2.3",
77
+ "react-dom": "~19.2.3",
78
+ "@dxos/react-ui": "0.8.4-main.effb148878",
79
+ "@dxos/ui-theme": "0.8.4-main.effb148878"
72
80
  },
73
81
  "publishConfig": {
74
82
  "access": "public"
@@ -8,7 +8,7 @@ import React, { useState } from 'react';
8
8
  import { Input, Toolbar } from '@dxos/react-ui';
9
9
  import { withLayout, withTheme } from '@dxos/react-ui/testing';
10
10
 
11
- import { translations } from '../../translations';
11
+ import { translations } from '#translations';
12
12
 
13
13
  import { ChatDialog } from './ChatDialog';
14
14
 
@@ -37,7 +37,7 @@ const meta = {
37
37
  <ChatDialog.Header title='Chat' />
38
38
  <ChatDialog.Content>
39
39
  {items.map((item) => (
40
- <div key={item} className='pis-4 pbe-1'>
40
+ <div key={item} className='ps-4 pb-1'>
41
41
  {item}
42
42
  </div>
43
43
  ))}
@@ -51,7 +51,7 @@ const meta = {
51
51
  </>
52
52
  );
53
53
  },
54
- decorators: [withTheme, withLayout({ container: 'column' })],
54
+ decorators: [withTheme(), withLayout({ layout: 'column' })],
55
55
  parameters: {
56
56
  translations,
57
57
  },
@@ -7,14 +7,16 @@ 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/react-ui-theme';
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 w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center'>{children}</div>
17
+ <div className='grid w-[var(--dx-rail-action)] h-[var(--dx-rail-action)] items-center justify-center'>
18
+ {children}
19
+ </div>
18
20
  );
19
21
  };
20
22
 
@@ -47,15 +49,15 @@ type ChatDialogRootProps = PropsWithChildren<{
47
49
 
48
50
  const ChatDialogRoot = ({
49
51
  children,
50
- open: _open = false,
51
- expanded: expandedParam = false,
52
+ open: openProp = false,
53
+ expanded: expandedProp = false,
52
54
  onOpenChange,
53
55
  onExpandedChange,
54
56
  onEscape,
55
57
  }: ChatDialogRootProps) => {
56
58
  const [size, setSize] = useState<Size>('min-content');
57
- const [open, setOpen] = useControlledState<boolean>(_open, onOpenChange);
58
- const [expanded, setExpanded] = useControlledState<boolean>(expandedParam, onExpandedChange);
59
+ const [open, setOpen] = useControlledState<boolean>(openProp, onOpenChange);
60
+ const [expanded, setExpanded] = useControlledState<boolean>(expandedProp, onExpandedChange);
59
61
 
60
62
  // NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.
61
63
  // 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.
@@ -69,12 +71,12 @@ const ChatDialogRoot = ({
69
71
  setSize={setSize}
70
72
  >
71
73
  <Dialog.Root modal={false} open={open} onOpenChange={setOpen}>
72
- <div role='none' className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>
74
+ <div className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>
73
75
  <Dialog.Content
76
+ size='md'
74
77
  inOverlayLayout
75
78
  classNames={[
76
- 'grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden',
77
- 'box-content md:is-[35rem] md:max-is-none pointer-events-auto',
79
+ 'grid grid-rows-[var(--dx-rail-action)_1fr_min-content] p-0 overflow-hidden box-content pointer-events-auto',
78
80
  ]}
79
81
  onEscapeKeyDown={onEscape}
80
82
  onInteractOutside={preventDefault}
@@ -93,15 +95,19 @@ ChatDialogRoot.displayName = 'ChatDialog.Root';
93
95
  // Header
94
96
  //
95
97
 
98
+ const CHAT_DIALOG_HEADER_NAME = 'ChatDialog.Header';
99
+
96
100
  type ChatDialogHeaderProps = ThemedClassName<{
97
101
  title?: string;
98
102
  }>;
99
103
 
100
104
  const ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {
101
- const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);
105
+ const { expanded, setExpanded } = useChatDialogContext(CHAT_DIALOG_HEADER_NAME);
102
106
 
103
107
  return (
104
- <div className={mx('grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}>
108
+ <div
109
+ className={mx('grid grid-cols-[var(--dx-rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}
110
+ >
105
111
  <Endcap>
106
112
  <Dialog.Close>
107
113
  <Icon icon='ph--x--regular' />
@@ -118,7 +124,7 @@ const ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {
118
124
  variant='ghost'
119
125
  icon='ph--caret-up--regular'
120
126
  iconOnly
121
- classNames={mx('!p-1 [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}
127
+ classNames={mx('p-1! [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}
122
128
  label={expanded ? 'Close' : 'Open'}
123
129
  onClick={() => setExpanded((expanded) => !expanded)}
124
130
  />
@@ -127,16 +133,18 @@ const ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {
127
133
  );
128
134
  };
129
135
 
130
- ChatDialogHeader.displayName = 'ChatDialog.Header';
136
+ ChatDialogHeader.displayName = CHAT_DIALOG_HEADER_NAME;
131
137
 
132
138
  //
133
139
  // Content
134
140
  //
135
141
 
142
+ const CHAT_DIALOG_CONTENT_NAME = 'ChatDialog.Content';
143
+
136
144
  type ChatDialogContentProps = ThemedClassName<PropsWithChildren>;
137
145
 
138
146
  const ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {
139
- const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);
147
+ const { expanded, size, setSize } = useChatDialogContext(CHAT_DIALOG_CONTENT_NAME);
140
148
  useEffect(() => {
141
149
  setSize(expanded ? 'min-content' : 0);
142
150
  }, [expanded]);
@@ -144,8 +152,8 @@ const ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) =>
144
152
  return (
145
153
  <div
146
154
  className={mx(
147
- 'flex flex-col overflow-y-auto border-t border-b border-subduedSeparator',
148
- 'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200',
155
+ 'border-t border-b border-subdued-separator',
156
+ 'transition ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200',
149
157
  classNames,
150
158
  )}
151
159
  style={{
@@ -167,19 +175,21 @@ const ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) =>
167
175
  );
168
176
  };
169
177
 
170
- ChatDialogContent.displayName = 'ChatDialog.Content';
178
+ ChatDialogContent.displayName = CHAT_DIALOG_CONTENT_NAME;
171
179
 
172
180
  //
173
181
  // Footer
174
182
  //
175
183
 
184
+ const CHAT_DIALOG_FOOTER_NAME = 'ChatDialog.Footer';
185
+
176
186
  type ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;
177
187
 
178
188
  const ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {
179
189
  return <div className={mx(classNames)}>{children}</div>;
180
190
  };
181
191
 
182
- ChatDialogFooter.displayName = 'ChatDialog.Footer';
192
+ ChatDialogFooter.displayName = CHAT_DIALOG_FOOTER_NAME;
183
193
 
184
194
  //
185
195
  // ChatDialog
@@ -7,7 +7,7 @@ import { type Meta, type StoryObj } from '@storybook/react-vite';
7
7
  import { log } from '@dxos/log';
8
8
  import { withTheme } from '@dxos/react-ui/testing';
9
9
 
10
- import { translations } from '../../translations';
10
+ import { translations } from '#translations';
11
11
 
12
12
  import { ChatEditor } from './ChatEditor';
13
13
  import { type ReferenceData } from './references';
@@ -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,
@@ -31,34 +31,36 @@ type Story = StoryObj<typeof meta>;
31
31
  export const Default: Story = {
32
32
  args: {
33
33
  classNames,
34
+ placeholder: 'Ask a question...',
34
35
  },
35
36
  };
36
37
 
38
+ // TODO(burdon): Restore and reconcile with suggest/typeahead.
37
39
  export const WithSuggestions: Story = {
38
40
  args: {
39
41
  classNames,
40
42
  onSubmit: (text) => {
41
43
  log('onSubmit', { text });
42
44
  },
43
- onSuggest: (text) => {
44
- const trimmed = text.trim().toLowerCase();
45
- if (trimmed.length < 2) {
46
- return [];
47
- }
48
45
 
49
- const suggestions = [
50
- 'Create a kanban board',
51
- 'Create a new project',
52
- 'Find flights to Tokyo',
53
- "Let's play chess",
54
- 'Show me Paris on a map',
55
- ];
56
-
57
- return suggestions.filter((s) => s.toLowerCase().startsWith(text));
58
- },
46
+ // onSuggest: (text) => {
47
+ // const trimmed = text.trim().toLowerCase();
48
+ // if (trimmed.length < 2) {
49
+ // return [];
50
+ // }
51
+ // const suggestions = [
52
+ // 'Create a kanban board',
53
+ // 'Create a new project',
54
+ // 'Find flights to Tokyo',
55
+ // "Let's play chess",
56
+ // 'Show me Paris on a map',
57
+ // ];
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,57 @@
3
3
  //
4
4
 
5
5
  import { type Extension } from '@codemirror/state';
6
- import { keymap } from '@codemirror/view';
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 UseTextEditorProps,
15
- autocomplete,
12
+ type SubmitOptions,
16
13
  createBasicExtensions,
17
14
  createThemeExtensions,
18
- useTextEditor,
19
- } from '@dxos/react-ui-editor';
20
- import { mx } from '@dxos/react-ui-theme';
15
+ submit,
16
+ xmlFormatting,
17
+ } from '@dxos/ui-editor';
21
18
  import { isTruthy } from '@dxos/util';
22
19
 
23
- import { type ReferencesOptions, references as referencesExtension } from './references';
20
+ import { type ReferencesOptions } from './references';
24
21
 
25
- export interface ChatEditorController {
26
- focus(): void;
27
- getText(): string;
28
- setText(text: string): void;
29
- }
22
+ export interface ChatEditorController extends EditorController {}
30
23
 
31
24
  export type ChatEditorProps = ThemedClassName<
32
25
  {
33
26
  extensions?: Extension;
34
27
  references?: ReferencesOptions;
35
- } & AutocompleteOptions &
28
+ } & (SubmitOptions &
36
29
  Pick<UseTextEditorProps, 'id' | 'autoFocus'> &
37
- Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>
30
+ Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>)
38
31
  >;
39
32
 
33
+ export const useChatExtensions = ({ extensions, lineWrapping = false, placeholder, onSubmit }: ChatEditorProps) => {
34
+ const { themeMode } = useThemeContext();
35
+ return useMemo<Extension[]>(
36
+ () =>
37
+ [
38
+ createThemeExtensions({ themeMode }),
39
+ createBasicExtensions({ bracketMatching: false, lineWrapping, placeholder }),
40
+ xmlFormatting(),
41
+ submit({ onSubmit }),
42
+ extensions,
43
+ ].filter(isTruthy),
44
+ [themeMode, extensions, onSubmit],
45
+ );
46
+ };
47
+
40
48
  export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
41
- (
42
- { classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel },
43
- forwardRef,
44
- ) => {
45
- const { themeMode } = useThemeContext();
46
- const { findNextFocusable, findPrevFocusable } = useFocusFinders();
47
- const { parentRef, view } = useTextEditor(
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],
49
+ ({ classNames, autoFocus, extensions: extensionsProp, lineWrapping = false, placeholder, onSubmit }, forwardRef) => {
50
+ const extensions = useChatExtensions({ extensions: extensionsProp, lineWrapping, placeholder, onSubmit });
51
+
52
+ // TODO(burdon): Popover.
53
+ return (
54
+ <Editor.Root ref={forwardRef}>
55
+ <Editor.View classNames={classNames} autoFocus={autoFocus} extensions={extensions} />
56
+ </Editor.Root>
79
57
  );
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
58
  },
106
59
  );
@@ -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: (plugin) => [
112
+ provide: () => [
107
113
  EditorView.atomicRanges.of(
108
114
  (view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,
109
115
  ),
@@ -124,7 +130,7 @@ export const references = ({ provider, triggerCharacter = '@', debug = false }:
124
130
  }),
125
131
 
126
132
  autocompletion({
127
- tooltipClass: () => 'shadow rounded',
133
+ tooltipClass: () => 'shadow rounded-sm',
128
134
  activateOnTyping: true,
129
135
  aboveCursor: true,
130
136
  closeOnBlur: !debug,
@@ -158,18 +164,18 @@ class ReferenceWidget extends WidgetType {
158
164
  super();
159
165
  }
160
166
 
161
- override toDOM(): HTMLSpanElement {
162
- const span = document.createElement('span');
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: ReferenceWidget): boolean {
169
- return other.data.uri === this.data.uri;
171
+ override eq(other: this) {
172
+ return this.data.uri === other.data.uri;
170
173
  }
171
174
 
172
- override ignoreEvent(): boolean {
173
- return true;
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
  }