@dxos/react-ui-chat 0.8.4-main.c1de068 → 0.8.4-main.e098934

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 (30) hide show
  1. package/dist/lib/browser/index.mjs +50 -179
  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 +50 -179
  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 +1 -1
  8. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
  9. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +35 -4
  10. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
  11. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +4 -4
  12. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
  13. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +20 -4
  14. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
  15. package/dist/types/src/index.d.ts +1 -0
  16. package/dist/types/src/index.d.ts.map +1 -1
  17. package/dist/types/src/translations.d.ts +1 -34
  18. package/dist/types/src/translations.d.ts.map +1 -1
  19. package/dist/types/tsconfig.tsbuildinfo +1 -1
  20. package/package.json +31 -30
  21. package/src/components/ChatDialog/ChatDialog.stories.tsx +7 -6
  22. package/src/components/ChatDialog/ChatDialog.tsx +4 -4
  23. package/src/components/ChatEditor/ChatEditor.stories.tsx +6 -5
  24. package/src/components/ChatEditor/ChatEditor.tsx +10 -8
  25. package/src/components/ChatEditor/references.ts +1 -1
  26. package/src/index.ts +1 -0
  27. package/src/translations.ts +1 -40
  28. package/dist/types/src/components/ChatEditor/autocomplete.d.ts +0 -25
  29. package/dist/types/src/components/ChatEditor/autocomplete.d.ts.map +0 -1
  30. package/src/components/ChatEditor/autocomplete.ts +0 -218
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-chat",
3
- "version": "0.8.4-main.c1de068",
3
+ "version": "0.8.4-main.e098934",
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"
@@ -23,50 +24,50 @@
23
24
  "src"
24
25
  ],
25
26
  "dependencies": {
26
- "@codemirror/autocomplete": "^6.18.1",
27
- "@codemirror/language": "^6.10.3",
28
- "@codemirror/search": "^6.5.6",
29
- "@codemirror/state": "^6.4.1",
30
- "@codemirror/view": "^6.34.1",
27
+ "@codemirror/autocomplete": "^6.18.7",
28
+ "@codemirror/language": "^6.11.3",
29
+ "@codemirror/search": "^6.5.11",
30
+ "@codemirror/state": "^6.5.2",
31
+ "@codemirror/view": "^6.38.2",
31
32
  "@preact-signals/safe-react": "^0.9.0",
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.c1de068",
36
- "@dxos/debug": "0.8.4-main.c1de068",
37
- "@dxos/echo-schema": "0.8.4-main.c1de068",
38
- "@dxos/invariant": "0.8.4-main.c1de068",
39
- "@dxos/live-object": "0.8.4-main.c1de068",
40
- "@dxos/log": "0.8.4-main.c1de068",
41
- "@dxos/react-ui": "0.8.4-main.c1de068",
42
- "@dxos/react-ui-components": "0.8.4-main.c1de068",
43
- "@dxos/react-ui-dnd": "0.8.4-main.c1de068",
44
- "@dxos/react-ui-editor": "0.8.4-main.c1de068",
45
- "@dxos/react-ui-sfx": "0.8.4-main.c1de068",
46
- "@dxos/react-ui-syntax-highlighter": "0.8.4-main.c1de068",
47
- "@dxos/react-ui-text-tooltip": "0.8.4-main.c1de068",
48
- "@dxos/react-ui-theme": "0.8.4-main.c1de068",
49
- "@dxos/react-ui-types": "0.8.4-main.c1de068",
50
- "@dxos/util": "0.8.4-main.c1de068"
36
+ "@dxos/debug": "0.8.4-main.e098934",
37
+ "@dxos/echo-schema": "0.8.4-main.e098934",
38
+ "@dxos/invariant": "0.8.4-main.e098934",
39
+ "@dxos/live-object": "0.8.4-main.e098934",
40
+ "@dxos/async": "0.8.4-main.e098934",
41
+ "@dxos/react-ui-components": "0.8.4-main.e098934",
42
+ "@dxos/react-ui-dnd": "0.8.4-main.e098934",
43
+ "@dxos/react-ui-editor": "0.8.4-main.e098934",
44
+ "@dxos/react-ui-sfx": "0.8.4-main.e098934",
45
+ "@dxos/react-ui-syntax-highlighter": "0.8.4-main.e098934",
46
+ "@dxos/react-ui-text-tooltip": "0.8.4-main.e098934",
47
+ "@dxos/react-ui-theme": "0.8.4-main.e098934",
48
+ "@dxos/react-ui-types": "0.8.4-main.e098934",
49
+ "@dxos/util": "0.8.4-main.e098934",
50
+ "@dxos/react-ui": "0.8.4-main.e098934",
51
+ "@dxos/log": "0.8.4-main.e098934"
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.c1de068",
60
- "@dxos/random": "0.8.4-main.c1de068",
61
- "@dxos/react-client": "0.8.4-main.c1de068",
62
- "@dxos/storybook-utils": "0.8.4-main.c1de068"
59
+ "vite": "7.1.1",
60
+ "@dxos/echo": "0.8.4-main.e098934",
61
+ "@dxos/random": "0.8.4-main.e098934",
62
+ "@dxos/react-client": "0.8.4-main.e098934",
63
+ "@dxos/storybook-utils": "0.8.4-main.e098934"
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.c1de068",
69
- "@dxos/react-ui-theme": "0.8.4-main.c1de068"
69
+ "@dxos/react-ui": "0.8.4-main.e098934",
70
+ "@dxos/react-ui-theme": "0.8.4-main.e098934"
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();
@@ -48,14 +48,14 @@ type ChatDialogRootProps = PropsWithChildren<{
48
48
  const ChatDialogRoot = ({
49
49
  children,
50
50
  open: _open = false,
51
- expanded: _expanded = false,
51
+ expanded: expandedParam = false,
52
52
  onOpenChange,
53
53
  onExpandedChange,
54
54
  onEscape,
55
55
  }: ChatDialogRootProps) => {
56
56
  const [size, setSize] = useState<Size>('min-content');
57
57
  const [open, setOpen] = useControlledState<boolean>(_open, onOpenChange);
58
- const [expanded, setExpanded] = useControlledState<boolean>(_expanded, onExpandedChange);
58
+ const [expanded, setExpanded] = useControlledState<boolean>(expandedParam, 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.
@@ -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: {
@@ -7,8 +7,10 @@ import React, { forwardRef, useImperativeHandle } from 'react';
7
7
 
8
8
  import { type ThemedClassName, useThemeContext } from '@dxos/react-ui';
9
9
  import {
10
+ type AutocompleteOptions,
10
11
  type BasicExtensionsOptions,
11
12
  type UseTextEditorProps,
13
+ autocomplete,
12
14
  createBasicExtensions,
13
15
  createThemeExtensions,
14
16
  useTextEditor,
@@ -16,13 +18,11 @@ import {
16
18
  import { mx } from '@dxos/react-ui-theme';
17
19
  import { isNonNullable } from '@dxos/util';
18
20
 
19
- import { autocomplete, type AutocompleteOptions } from './autocomplete';
20
- import { references as referencesExtension, type ReferencesOptions } from './references';
21
-
22
- // TODO(burdon): Handle object references.
21
+ import { type ReferencesOptions, references as referencesExtension } from './references';
23
22
 
24
23
  export interface ChatEditorController {
25
24
  focus(): void;
25
+ getText(): string;
26
26
  setText(text: string): void;
27
27
  }
28
28
 
@@ -31,7 +31,7 @@ export type ChatEditorProps = ThemedClassName<
31
31
  extensions?: Extension;
32
32
  references?: ReferencesOptions;
33
33
  } & AutocompleteOptions &
34
- Pick<UseTextEditorProps, 'autoFocus'> &
34
+ Pick<UseTextEditorProps, 'id' | 'autoFocus'> &
35
35
  Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>
36
36
  >;
37
37
 
@@ -41,8 +41,9 @@ export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
41
41
  forwardRef,
42
42
  ) => {
43
43
  const { themeMode } = useThemeContext();
44
+
44
45
  const { parentRef, view } = useTextEditor(
45
- {
46
+ () => ({
46
47
  debug: true,
47
48
  autoFocus,
48
49
  extensions: [
@@ -56,8 +57,8 @@ export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
56
57
  }),
57
58
  extensions,
58
59
  ].filter(isNonNullable),
59
- },
60
- [themeMode, extensions, onSubmit, onSuggest],
60
+ }),
61
+ [themeMode, extensions, onSubmit, onSuggest, onCancel],
61
62
  );
62
63
 
63
64
  // Expose editor view.
@@ -66,6 +67,7 @@ export const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(
66
67
  focus: () => {
67
68
  view?.focus();
68
69
  },
70
+ getText: () => view?.state.doc.toString() ?? '',
69
71
  setText: (text: string) => {
70
72
  view?.dispatch({
71
73
  changes: {
@@ -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[];
@@ -1,25 +0,0 @@
1
- import { type Extension } from '@codemirror/state';
2
- export type AutocompleteOptions = {
3
- /**
4
- * Callback triggered when Enter is pressed.
5
- * @param text The current text in the editor
6
- * @returns true if the editor should reset the document.
7
- */
8
- onSubmit?: (text: string) => boolean | void;
9
- /**
10
- * Function that returns a list of suggestions based on the current text.
11
- * @param text The current text before the cursor
12
- * @returns Array of suggestion strings
13
- */
14
- onSuggest?: (text: string) => string[];
15
- /**
16
- * ESC pressed.
17
- */
18
- onCancel?: () => void;
19
- };
20
- /**
21
- * Creates an autocomplete extension that shows inline suggestions.
22
- * Pressing Tab will complete the suggestion.
23
- */
24
- export declare const autocomplete: ({ onSubmit, onSuggest, onCancel }: AutocompleteOptions) => Extension;
25
- //# sourceMappingURL=autocomplete.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"autocomplete.d.ts","sourceRoot":"","sources":["../../../../../src/components/ChatEditor/autocomplete.ts"],"names":[],"mappings":"AAIA,OAAO,EAAQ,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAWzD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,OAAO,GAAG,IAAI,CAAC;IAE5C;;;;OAIG;IACH,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,EAAE,CAAC;IAEvC;;OAEG;IACH,QAAQ,CAAC,EAAE,MAAM,IAAI,CAAC;CACvB,CAAC;AAEF;;;GAGG;AAEH,eAAO,MAAM,YAAY,GAAI,mCAAmC,mBAAmB,KAAG,SA+JrF,CAAC"}
@@ -1,218 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { Prec, type Extension } from '@codemirror/state';
6
- import {
7
- EditorView,
8
- Decoration,
9
- ViewPlugin,
10
- keymap,
11
- type DecorationSet,
12
- type ViewUpdate,
13
- WidgetType,
14
- } from '@codemirror/view';
15
-
16
- export type AutocompleteOptions = {
17
- /**
18
- * Callback triggered when Enter is pressed.
19
- * @param text The current text in the editor
20
- * @returns true if the editor should reset the document.
21
- */
22
- onSubmit?: (text: string) => boolean | void;
23
-
24
- /**
25
- * Function that returns a list of suggestions based on the current text.
26
- * @param text The current text before the cursor
27
- * @returns Array of suggestion strings
28
- */
29
- onSuggest?: (text: string) => string[];
30
-
31
- /**
32
- * ESC pressed.
33
- */
34
- onCancel?: () => void;
35
- };
36
-
37
- /**
38
- * Creates an autocomplete extension that shows inline suggestions.
39
- * Pressing Tab will complete the suggestion.
40
- */
41
- // TODO(burdon): Move to react-ui-editor.
42
- export const autocomplete = ({ onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {
43
- const suggest = ViewPlugin.fromClass(
44
- class {
45
- _decorations: DecorationSet;
46
- _currentSuggestion: string | null = null;
47
-
48
- constructor(view: EditorView) {
49
- this._decorations = this.computeDecorations(view);
50
- }
51
-
52
- update(update: ViewUpdate) {
53
- if (update.docChanged || update.selectionSet) {
54
- this._decorations = this.computeDecorations(update.view);
55
- }
56
- }
57
-
58
- private computeDecorations(view: EditorView): DecorationSet {
59
- const text = view.state.doc.toString();
60
- const suggestions = onSuggest?.(text) ?? [];
61
- if (!suggestions.length) {
62
- this._currentSuggestion = null;
63
- return Decoration.none;
64
- }
65
-
66
- // Get the first suggestion.
67
- this._currentSuggestion = suggestions[0];
68
- const suffix = this._currentSuggestion.slice(text.length);
69
- if (!suffix) {
70
- return Decoration.none;
71
- }
72
-
73
- // Always show ghost text at the end of the document.
74
- return Decoration.set([
75
- Decoration.widget({
76
- widget: new InlineSuggestionWidget(suffix),
77
- side: 1,
78
- }).range(view.state.doc.length),
79
- ]);
80
- }
81
-
82
- completeSuggestion(view: EditorView): boolean {
83
- if (!this._currentSuggestion) {
84
- return false;
85
- }
86
-
87
- const text = view.state.doc.toString();
88
- const suffix = this._currentSuggestion.slice(text.length);
89
- if (!suffix) {
90
- return false;
91
- }
92
-
93
- view.dispatch({
94
- changes: {
95
- from: view.state.doc.length,
96
- insert: suffix,
97
- },
98
- selection: {
99
- anchor: view.state.doc.length + suffix.length,
100
- },
101
- });
102
-
103
- return true;
104
- }
105
- },
106
- {
107
- decorations: (v) => v._decorations,
108
- },
109
- );
110
-
111
- return [
112
- suggest,
113
- EditorView.theme({
114
- '.cm-inline-suggestion': {
115
- opacity: 0.4,
116
- },
117
- }),
118
-
119
- Prec.highest(
120
- keymap.of([
121
- {
122
- key: 'Tab',
123
- preventDefault: true,
124
- run: (view) => {
125
- const plugin = view.plugin(suggest);
126
- return plugin?.completeSuggestion(view) ?? false;
127
- },
128
- },
129
- {
130
- key: 'ArrowRight',
131
- preventDefault: true,
132
- run: (view) => {
133
- // Only complete if cursor is at the end
134
- if (view.state.selection.main.head !== view.state.doc.length) {
135
- return false;
136
- }
137
-
138
- const plugin = view.plugin(suggest);
139
- return plugin?.completeSuggestion(view) ?? false;
140
- },
141
- },
142
- {
143
- key: 'Enter',
144
- preventDefault: true,
145
- run: (view) => {
146
- const text = view.state.doc.toString().trim();
147
- if (text.length > 0 && onSubmit) {
148
- const reset = onSubmit(text);
149
-
150
- // Clear the document after calling onEnter.
151
- if (reset) {
152
- view.dispatch({
153
- changes: {
154
- from: 0,
155
- to: view.state.doc.length,
156
- insert: '',
157
- },
158
- });
159
- }
160
- }
161
-
162
- return true;
163
- },
164
- },
165
- {
166
- key: 'Shift-Enter',
167
- preventDefault: true,
168
- run: (view) => {
169
- view.dispatch({
170
- changes: {
171
- from: view.state.selection.main.head,
172
- insert: '\n',
173
- },
174
- selection: {
175
- anchor: view.state.selection.main.head + 1,
176
- head: view.state.selection.main.head + 1,
177
- },
178
- });
179
- return true;
180
- },
181
- },
182
- {
183
- key: 'Escape',
184
- preventDefault: true,
185
- run: (view) => {
186
- // Clear the entire document.
187
- view.dispatch({
188
- changes: {
189
- from: 0,
190
- to: view.state.doc.length,
191
- insert: '',
192
- },
193
- });
194
- onCancel?.();
195
- return true;
196
- },
197
- },
198
- ]),
199
- ),
200
- ];
201
- };
202
-
203
- class InlineSuggestionWidget extends WidgetType {
204
- constructor(private suffix: string) {
205
- super();
206
- }
207
-
208
- override toDOM(): HTMLSpanElement {
209
- const span = document.createElement('span');
210
- span.textContent = this.suffix;
211
- span.className = 'cm-inline-suggestion';
212
- return span;
213
- }
214
-
215
- override eq(other: InlineSuggestionWidget): boolean {
216
- return other.suffix === this.suffix;
217
- }
218
- }