@dxos/react-ui-chat 0.8.4-main.3f58842 → 0.8.4-main.5ea62a8

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 (29) hide show
  1. package/dist/lib/browser/index.mjs +71 -31
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/node-esm/index.mjs +71 -31
  5. package/dist/lib/node-esm/index.mjs.map +4 -4
  6. package/dist/lib/node-esm/meta.json +1 -1
  7. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
  8. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +35 -4
  9. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
  10. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +3 -2
  11. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
  12. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +20 -4
  13. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
  14. package/dist/types/src/components/ChatEditor/autocomplete.d.ts +2 -1
  15. package/dist/types/src/components/ChatEditor/autocomplete.d.ts.map +1 -1
  16. package/dist/types/src/index.d.ts +1 -0
  17. package/dist/types/src/index.d.ts.map +1 -1
  18. package/dist/types/src/translations.d.ts +1 -34
  19. package/dist/types/src/translations.d.ts.map +1 -1
  20. package/dist/types/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +26 -25
  22. package/src/components/ChatDialog/ChatDialog.stories.tsx +7 -6
  23. package/src/components/ChatDialog/ChatDialog.tsx +2 -2
  24. package/src/components/ChatEditor/ChatEditor.stories.tsx +6 -5
  25. package/src/components/ChatEditor/ChatEditor.tsx +9 -8
  26. package/src/components/ChatEditor/autocomplete.ts +8 -6
  27. package/src/components/ChatEditor/references.ts +1 -1
  28. package/src/index.ts +1 -0
  29. package/src/translations.ts +1 -40
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-chat",
3
- "version": "0.8.4-main.3f58842",
3
+ "version": "0.8.4-main.5ea62a8",
4
4
  "description": "Chat components.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -9,6 +9,7 @@
9
9
  "type": "module",
10
10
  "exports": {
11
11
  ".": {
12
+ "source": "./src/index.ts",
12
13
  "types": "./dist/types/src/index.d.ts",
13
14
  "browser": "./dist/lib/browser/index.mjs",
14
15
  "node": "./dist/lib/node-esm/index.mjs"
@@ -32,41 +33,41 @@
32
33
  "@preact/signals-core": "^1.9.0",
33
34
  "@radix-ui/react-accordion": "1.2.3",
34
35
  "@radix-ui/react-context": "1.1.1",
35
- "@dxos/async": "0.8.4-main.3f58842",
36
- "@dxos/debug": "0.8.4-main.3f58842",
37
- "@dxos/echo-schema": "0.8.4-main.3f58842",
38
- "@dxos/invariant": "0.8.4-main.3f58842",
39
- "@dxos/live-object": "0.8.4-main.3f58842",
40
- "@dxos/log": "0.8.4-main.3f58842",
41
- "@dxos/react-ui": "0.8.4-main.3f58842",
42
- "@dxos/react-ui-components": "0.8.4-main.3f58842",
43
- "@dxos/react-ui-dnd": "0.8.4-main.3f58842",
44
- "@dxos/react-ui-editor": "0.8.4-main.3f58842",
45
- "@dxos/react-ui-sfx": "0.8.4-main.3f58842",
46
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.3f58842",
47
- "@dxos/react-ui-text-tooltip": "0.8.4-main.3f58842",
48
- "@dxos/react-ui-types": "0.8.4-main.3f58842",
49
- "@dxos/react-ui-theme": "0.8.4-main.3f58842",
50
- "@dxos/util": "0.8.4-main.3f58842"
36
+ "@dxos/async": "0.8.4-main.5ea62a8",
37
+ "@dxos/debug": "0.8.4-main.5ea62a8",
38
+ "@dxos/invariant": "0.8.4-main.5ea62a8",
39
+ "@dxos/log": "0.8.4-main.5ea62a8",
40
+ "@dxos/live-object": "0.8.4-main.5ea62a8",
41
+ "@dxos/react-ui-components": "0.8.4-main.5ea62a8",
42
+ "@dxos/react-ui-dnd": "0.8.4-main.5ea62a8",
43
+ "@dxos/echo-schema": "0.8.4-main.5ea62a8",
44
+ "@dxos/react-ui-sfx": "0.8.4-main.5ea62a8",
45
+ "@dxos/react-ui-editor": "0.8.4-main.5ea62a8",
46
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.5ea62a8",
47
+ "@dxos/react-ui-text-tooltip": "0.8.4-main.5ea62a8",
48
+ "@dxos/react-ui-theme": "0.8.4-main.5ea62a8",
49
+ "@dxos/react-ui-types": "0.8.4-main.5ea62a8",
50
+ "@dxos/util": "0.8.4-main.5ea62a8",
51
+ "@dxos/react-ui": "0.8.4-main.5ea62a8"
51
52
  },
52
53
  "devDependencies": {
53
54
  "@types/react": "~18.2.0",
54
55
  "@types/react-dom": "~18.2.0",
55
- "effect": "3.17.0",
56
+ "effect": "3.17.7",
56
57
  "react": "~18.2.0",
57
58
  "react-dom": "~18.2.0",
58
- "vite": "5.4.7",
59
- "@dxos/echo": "0.8.4-main.3f58842",
60
- "@dxos/random": "0.8.4-main.3f58842",
61
- "@dxos/react-client": "0.8.4-main.3f58842",
62
- "@dxos/storybook-utils": "0.8.4-main.3f58842"
59
+ "vite": "7.1.1",
60
+ "@dxos/echo": "0.8.4-main.5ea62a8",
61
+ "@dxos/random": "0.8.4-main.5ea62a8",
62
+ "@dxos/storybook-utils": "0.8.4-main.5ea62a8",
63
+ "@dxos/react-client": "0.8.4-main.5ea62a8"
63
64
  },
64
65
  "peerDependencies": {
65
66
  "effect": "^3.13.3",
66
67
  "react": "~18.2.0",
67
68
  "react-dom": "~18.2.0",
68
- "@dxos/react-ui": "0.8.4-main.3f58842",
69
- "@dxos/react-ui-theme": "0.8.4-main.3f58842"
69
+ "@dxos/react-ui": "0.8.4-main.5ea62a8",
70
+ "@dxos/react-ui-theme": "0.8.4-main.5ea62a8"
70
71
  },
71
72
  "publishConfig": {
72
73
  "access": "public"
@@ -4,18 +4,19 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type StoryObj, type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
  import React, { useState } from 'react';
9
9
 
10
10
  import { Input, Toolbar } from '@dxos/react-ui';
11
- import { withTheme, withLayout } from '@dxos/storybook-utils';
11
+ import { withLayout, withTheme } from '@dxos/storybook-utils';
12
12
 
13
- import { ChatDialog } from './ChatDialog';
14
13
  import { translations } from '../../translations';
15
14
 
15
+ import { ChatDialog } from './ChatDialog';
16
+
16
17
  const items = Array.from({ length: 100 }, (_, i) => `Item ${i}`);
17
18
 
18
- const meta: Meta<typeof ChatDialog.Root> = {
19
+ const meta = {
19
20
  title: 'ui/react-ui-chat/ChatDialog',
20
21
  component: ChatDialog.Root,
21
22
  render: (args) => {
@@ -56,10 +57,10 @@ const meta: Meta<typeof ChatDialog.Root> = {
56
57
  parameters: {
57
58
  translations,
58
59
  },
59
- };
60
+ } satisfies Meta<typeof ChatDialog.Root>;
60
61
 
61
62
  export default meta;
62
63
 
63
- type Story = StoryObj<typeof ChatDialog.Root>;
64
+ type Story = StoryObj<typeof meta>;
64
65
 
65
66
  export const Default: Story = {};
@@ -5,8 +5,8 @@
5
5
  import { createContext } from '@radix-ui/react-context';
6
6
  import React, { type Dispatch, type PropsWithChildren, type SetStateAction, useEffect, useState } from 'react';
7
7
 
8
- import { Dialog, Icon, IconButton, useControlledState, type ThemedClassName } from '@dxos/react-ui';
9
- import { resizeAttributes, ResizeHandle, type Size, sizeStyle } from '@dxos/react-ui-dnd';
8
+ import { Dialog, Icon, IconButton, type ThemedClassName, useControlledState } from '@dxos/react-ui';
9
+ import { ResizeHandle, type Size, resizeAttributes, sizeStyle } from '@dxos/react-ui-dnd';
10
10
  import { mx } from '@dxos/react-ui-theme';
11
11
 
12
12
  const preventDefault = (event: Event) => event.preventDefault();
@@ -4,16 +4,17 @@
4
4
 
5
5
  import '@dxos-theme';
6
6
 
7
- import { type StoryObj, type Meta } from '@storybook/react-vite';
7
+ import { type Meta, type StoryObj } from '@storybook/react-vite';
8
8
 
9
9
  import { log } from '@dxos/log';
10
10
  import { withTheme } from '@dxos/storybook-utils';
11
11
 
12
+ import { translations } from '../../translations';
13
+
12
14
  import { ChatEditor } from './ChatEditor';
13
15
  import { type ReferenceData } from './references';
14
- import { translations } from '../../translations';
15
16
 
16
- const meta: Meta<typeof ChatEditor> = {
17
+ const meta = {
17
18
  title: 'ui/react-ui-chat/ChatEditor',
18
19
  component: ChatEditor,
19
20
  decorators: [withTheme],
@@ -21,13 +22,13 @@ const meta: Meta<typeof ChatEditor> = {
21
22
  layout: 'centered',
22
23
  translations,
23
24
  },
24
- };
25
+ } satisfies Meta<typeof ChatEditor>;
25
26
 
26
27
  export default meta;
27
28
 
28
29
  const classNames = 'w-[20rem] p-2 border border-separator';
29
30
 
30
- type Story = StoryObj<typeof ChatEditor>;
31
+ type Story = StoryObj<typeof meta>;
31
32
 
32
33
  export const Default: Story = {
33
34
  args: {
@@ -16,13 +16,12 @@ import {
16
16
  import { mx } from '@dxos/react-ui-theme';
17
17
  import { isNonNullable } from '@dxos/util';
18
18
 
19
- import { autocomplete, type AutocompleteOptions } from './autocomplete';
20
- import { references as referencesExtension, type ReferencesOptions } from './references';
21
-
22
- // TODO(burdon): Handle object references.
19
+ import { type AutocompleteOptions, autocomplete } from './autocomplete';
20
+ import { type ReferencesOptions, references as referencesExtension } from './references';
23
21
 
24
22
  export interface ChatEditorController {
25
23
  focus(): void;
24
+ getText(): string;
26
25
  setText(text: string): void;
27
26
  }
28
27
 
@@ -31,7 +30,7 @@ export type ChatEditorProps = ThemedClassName<
31
30
  extensions?: Extension;
32
31
  references?: ReferencesOptions;
33
32
  } & AutocompleteOptions &
34
- Pick<UseTextEditorProps, 'autoFocus'> &
33
+ Pick<UseTextEditorProps, 'id' | 'autoFocus'> &
35
34
  Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>
36
35
  >;
37
36
 
@@ -41,8 +40,9 @@ export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
41
40
  forwardRef,
42
41
  ) => {
43
42
  const { themeMode } = useThemeContext();
43
+
44
44
  const { parentRef, view } = useTextEditor(
45
- {
45
+ () => ({
46
46
  debug: true,
47
47
  autoFocus,
48
48
  extensions: [
@@ -56,8 +56,8 @@ export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
56
56
  }),
57
57
  extensions,
58
58
  ].filter(isNonNullable),
59
- },
60
- [themeMode, extensions, onSubmit, onSuggest],
59
+ }),
60
+ [themeMode, extensions, onSubmit, onSuggest, onCancel],
61
61
  );
62
62
 
63
63
  // Expose editor view.
@@ -66,6 +66,7 @@ export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
66
66
  focus: () => {
67
67
  view?.focus();
68
68
  },
69
+ getText: () => view?.state.doc.toString() ?? '',
69
70
  setText: (text: string) => {
70
71
  view?.dispatch({
71
72
  changes: {
@@ -2,18 +2,20 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { Prec, type Extension } from '@codemirror/state';
5
+ import { type Extension, Prec } from '@codemirror/state';
6
6
  import {
7
- EditorView,
8
7
  Decoration,
9
- ViewPlugin,
10
- keymap,
11
8
  type DecorationSet,
9
+ EditorView,
10
+ ViewPlugin,
12
11
  type ViewUpdate,
13
12
  WidgetType,
13
+ keymap,
14
14
  } from '@codemirror/view';
15
15
 
16
16
  export type AutocompleteOptions = {
17
+ fireIfEmpty?: boolean;
18
+
17
19
  /**
18
20
  * Callback triggered when Enter is pressed.
19
21
  * @param text The current text in the editor
@@ -39,7 +41,7 @@ export type AutocompleteOptions = {
39
41
  * Pressing Tab will complete the suggestion.
40
42
  */
41
43
  // TODO(burdon): Move to react-ui-editor.
42
- export const autocomplete = ({ onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {
44
+ export const autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {
43
45
  const suggest = ViewPlugin.fromClass(
44
46
  class {
45
47
  _decorations: DecorationSet;
@@ -144,7 +146,7 @@ export const autocomplete = ({ onSubmit, onSuggest, onCancel }: AutocompleteOpti
144
146
  preventDefault: true,
145
147
  run: (view) => {
146
148
  const text = view.state.doc.toString().trim();
147
- if (text.length > 0 && onSubmit) {
149
+ if (onSubmit && (fireIfEmpty || text.length > 0)) {
148
150
  const reset = onSubmit(text);
149
151
 
150
152
  // Clear the document after calling onEnter.
@@ -2,7 +2,7 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
- import { autocompletion, completionKeymap, type CompletionResult } from '@codemirror/autocomplete';
5
+ import { type CompletionResult, autocompletion, completionKeymap } from '@codemirror/autocomplete';
6
6
  import { type Extension, RangeSet } from '@codemirror/state';
7
7
  import {
8
8
  Decoration,
package/src/index.ts CHANGED
@@ -3,3 +3,4 @@
3
3
  //
4
4
 
5
5
  export * from './components';
6
+ export * from './translations';
@@ -9,46 +9,7 @@ export const translationKey = 'react-ui-chat';
9
9
  export const translations = [
10
10
  {
11
11
  'en-US': {
12
- [translationKey]: {
13
- 'templates label': 'Templates',
14
- 'open ambient chat label': 'Open Assistant',
15
- 'assistant chat label': 'Assistant',
16
- 'plugin name': 'Assistant',
17
- 'object placeholder': 'New prompt',
18
- 'create object label': 'Create prompt',
19
- 'create trigger label': 'Create trigger',
20
- 'create stack section label': 'Create prompt',
21
- 'command placeholder': 'Enter slash command...',
22
- 'template placeholder': 'Enter template...',
23
- 'value placeholder': 'Enter value...',
24
- 'prompt rules label': 'Prompt Rules',
25
- 'typename placeholder': 'Enter typename of objects which this template is for',
26
- 'description placeholder': 'Enter description of when this template should be used',
27
- 'select preset template placeholder': 'Select preset',
28
- 'service registry label': 'Service Registry',
29
-
30
- 'sequence logs label': 'Logs',
31
-
32
- 'assistant dialog title': 'Assistant',
33
- 'open assistant label': 'Open assistant',
34
-
35
- 'search input placeholder': 'Search...',
36
- 'chat input placeholder': 'Ask a question...',
37
- 'chat stop': 'Cancel request.',
38
-
39
- 'button save': 'Save',
40
- 'button run': 'Run',
41
-
42
- 'prompt placeholder': 'Ask a question...',
43
- 'microphone button': 'Click to speak',
44
- 'cancel processing button': 'Stop processing',
45
-
46
- 'settings default label': 'Default',
47
- 'settings custom prompts label': 'Use custom prompts',
48
- 'settings llm provider label': 'LLM provider',
49
- 'settings edge llm model label': 'Remote language model',
50
- 'settings ollama llm model label': 'Ollama language model',
51
- },
12
+ [translationKey]: {},
52
13
  },
53
14
  },
54
15
  ] as const satisfies Resource[];