@dxos/react-ui-chat 0.8.4-main.ae835ea → 0.8.4-main.bc674ce

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/package.json CHANGED
@@ -1,9 +1,13 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-chat",
3
- "version": "0.8.4-main.ae835ea",
3
+ "version": "0.8.4-main.bc674ce",
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": "^9.24.2",
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.ae835ea",
38
- "@dxos/debug": "0.8.4-main.ae835ea",
39
- "@dxos/live-object": "0.8.4-main.ae835ea",
40
- "@dxos/echo": "0.8.4-main.ae835ea",
41
- "@dxos/log": "0.8.4-main.ae835ea",
42
- "@dxos/react-ui": "0.8.4-main.ae835ea",
43
- "@dxos/react-ui-components": "0.8.4-main.ae835ea",
44
- "@dxos/react-ui-dnd": "0.8.4-main.ae835ea",
45
- "@dxos/react-ui-editor": "0.8.4-main.ae835ea",
46
- "@dxos/react-ui-sfx": "0.8.4-main.ae835ea",
47
- "@dxos/invariant": "0.8.4-main.ae835ea",
48
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.ae835ea",
49
- "@dxos/react-ui-text-tooltip": "0.8.4-main.ae835ea",
50
- "@dxos/react-ui-theme": "0.8.4-main.ae835ea",
51
- "@dxos/util": "0.8.4-main.ae835ea",
52
- "@dxos/react-ui-types": "0.8.4-main.ae835ea"
39
+ "@dxos/async": "0.8.4-main.bc674ce",
40
+ "@dxos/debug": "0.8.4-main.bc674ce",
41
+ "@dxos/invariant": "0.8.4-main.bc674ce",
42
+ "@dxos/echo": "0.8.4-main.bc674ce",
43
+ "@dxos/react-ui": "0.8.4-main.bc674ce",
44
+ "@dxos/log": "0.8.4-main.bc674ce",
45
+ "@dxos/react-ui-dnd": "0.8.4-main.bc674ce",
46
+ "@dxos/react-ui-editor": "0.8.4-main.bc674ce",
47
+ "@dxos/react-ui-components": "0.8.4-main.bc674ce",
48
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.bc674ce",
49
+ "@dxos/react-ui-text-tooltip": "0.8.4-main.bc674ce",
50
+ "@dxos/react-ui-sfx": "0.8.4-main.bc674ce",
51
+ "@dxos/ui-editor": "0.8.4-main.bc674ce",
52
+ "@dxos/ui-theme": "0.8.4-main.bc674ce",
53
+ "@dxos/util": "0.8.4-main.bc674ce",
54
+ "@dxos/ui-types": "0.8.4-main.bc674ce"
53
55
  },
54
56
  "devDependencies": {
55
- "@types/react": "~19.2.2",
56
- "@types/react-dom": "~19.2.2",
57
- "effect": "3.18.3",
58
- "react": "~19.2.0",
59
- "react-dom": "~19.2.0",
57
+ "@types/react": "~19.2.7",
58
+ "@types/react-dom": "~19.2.3",
59
+ "effect": "3.19.11",
60
+ "react": "~19.2.3",
61
+ "react-dom": "~19.2.3",
60
62
  "vite": "7.1.9",
61
- "@dxos/echo": "0.8.4-main.ae835ea",
62
- "@dxos/random": "0.8.4-main.ae835ea",
63
- "@dxos/react-client": "0.8.4-main.ae835ea",
64
- "@dxos/storybook-utils": "0.8.4-main.ae835ea"
63
+ "@dxos/random": "0.8.4-main.bc674ce",
64
+ "@dxos/react-client": "0.8.4-main.bc674ce",
65
+ "@dxos/echo": "0.8.4-main.bc674ce",
66
+ "@dxos/storybook-utils": "0.8.4-main.bc674ce"
65
67
  },
66
68
  "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.ae835ea",
71
- "@dxos/react-ui-theme": "0.8.4-main.ae835ea"
69
+ "effect": "3.19.11",
70
+ "react": "~19.2.3",
71
+ "react-dom": "~19.2.3",
72
+ "@dxos/react-ui": "0.8.4-main.bc674ce",
73
+ "@dxos/ui-theme": "0.8.4-main.bc674ce"
72
74
  },
73
75
  "publishConfig": {
74
76
  "access": "public"
@@ -42,7 +42,7 @@ const meta = {
42
42
  </div>
43
43
  ))}
44
44
  </ChatDialog.Content>
45
- <ChatDialog.Footer classNames='px-2 items-center'>
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,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,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/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 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: _open = false,
51
- expanded: expandedParam = false,
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>(_open, onOpenChange);
58
- const [expanded, setExpanded] = useControlledState<boolean>(expandedParam, onExpandedChange);
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.
@@ -108,7 +108,7 @@ const ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {
108
108
  </Dialog.Close>
109
109
  </Endcap>
110
110
  <Dialog.Title
111
- classNames='flex w-full justify-center text-sm text-subdued select-none cursor-pointer'
111
+ classNames='flex is-full justify-center text-sm text-subdued select-none cursor-pointer'
112
112
  onClick={() => setExpanded((expanded) => !expanded)}
113
113
  >
114
114
  {title}
@@ -144,7 +144,7 @@ const ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) =>
144
144
  return (
145
145
  <div
146
146
  className={mx(
147
- 'flex flex-col overflow-y-auto border-t border-b border-subduedSeparator',
147
+ 'flex flex-col overflow-y-auto border-bs border-be border-subduedSeparator',
148
148
  'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200',
149
149
  classNames,
150
150
  )}
@@ -24,7 +24,7 @@ const meta = {
24
24
 
25
25
  export default meta;
26
26
 
27
- const classNames = 'w-[20rem] p-2 border border-separator';
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
- const trimmed = text.trim().toLowerCase();
45
- if (trimmed.length < 2) {
46
- return [];
47
- }
44
+ // onSuggest: (text) => {
45
+ // const trimmed = text.trim().toLowerCase();
46
+ // if (trimmed.length < 2) {
47
+ // return [];
48
+ // }
48
49
 
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
- ];
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
- return suggestions.filter((s) => s.toLowerCase().startsWith(text));
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 { 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
+ } from '@dxos/ui-editor';
21
17
  import { isTruthy } from '@dxos/util';
22
18
 
23
- import { type ReferencesOptions, references as referencesExtension } from './references';
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
- } & AutocompleteOptions &
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
- { 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],
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: (plugin) => [
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 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
  }
@@ -4,7 +4,7 @@
4
4
 
5
5
  import { type Resource } from '@dxos/react-ui';
6
6
 
7
- export const translationKey = 'react-ui-chat';
7
+ export const translationKey = '@dxos/react-ui-chat';
8
8
 
9
9
  export const translations = [
10
10
  {