@dxos/react-ui-chat 0.8.4-main.f5c0578 → 0.8.4-main.fcc0d83b33

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 (51) hide show
  1. package/dist/lib/browser/index.mjs +215 -339
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/translations.mjs +14 -0
  5. package/dist/lib/browser/translations.mjs.map +7 -0
  6. package/dist/lib/node-esm/index.mjs +215 -339
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/lib/node-esm/translations.mjs +16 -0
  10. package/dist/lib/node-esm/translations.mjs.map +7 -0
  11. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts +17 -1
  12. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
  13. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +35 -5
  14. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -9
  16. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
  17. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +20 -5
  18. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
  19. package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
  20. package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
  21. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts +40 -0
  22. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts.map +1 -0
  23. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts +27 -0
  24. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts.map +1 -0
  25. package/dist/types/src/components/ChatStatus/format.d.ts +7 -0
  26. package/dist/types/src/components/ChatStatus/format.d.ts.map +1 -0
  27. package/dist/types/src/components/ChatStatus/format.test.d.ts +2 -0
  28. package/dist/types/src/components/ChatStatus/format.test.d.ts.map +1 -0
  29. package/dist/types/src/components/ChatStatus/index.d.ts +3 -0
  30. package/dist/types/src/components/ChatStatus/index.d.ts.map +1 -0
  31. package/dist/types/src/components/index.d.ts +1 -0
  32. package/dist/types/src/components/index.d.ts.map +1 -1
  33. package/dist/types/src/translations.d.ts +2 -35
  34. package/dist/types/src/translations.d.ts.map +1 -1
  35. package/dist/types/tsconfig.tsbuildinfo +1 -1
  36. package/package.json +51 -42
  37. package/src/components/ChatDialog/ChatDialog.stories.tsx +7 -9
  38. package/src/components/ChatDialog/ChatDialog.tsx +27 -17
  39. package/src/components/ChatEditor/ChatEditor.stories.tsx +23 -23
  40. package/src/components/ChatEditor/ChatEditor.tsx +35 -65
  41. package/src/components/ChatEditor/references.ts +18 -12
  42. package/src/components/ChatStatus/ChatStatus.stories.tsx +130 -0
  43. package/src/components/ChatStatus/ChatStatus.tsx +183 -0
  44. package/src/components/ChatStatus/format.test.ts +48 -0
  45. package/src/components/ChatStatus/format.ts +27 -0
  46. package/src/components/ChatStatus/index.ts +6 -0
  47. package/src/components/index.ts +1 -0
  48. package/src/translations.ts +2 -41
  49. package/dist/types/src/components/ChatEditor/autocomplete.d.ts +0 -26
  50. package/dist/types/src/components/ChatEditor/autocomplete.d.ts.map +0 -1
  51. package/src/components/ChatEditor/autocomplete.ts +0 -220
@@ -1,220 +0,0 @@
1
- //
2
- // Copyright 2025 DXOS.org
3
- //
4
-
5
- import { type Extension, Prec } from '@codemirror/state';
6
- import {
7
- Decoration,
8
- type DecorationSet,
9
- EditorView,
10
- ViewPlugin,
11
- type ViewUpdate,
12
- WidgetType,
13
- keymap,
14
- } from '@codemirror/view';
15
-
16
- export type AutocompleteOptions = {
17
- fireIfEmpty?: boolean;
18
-
19
- /**
20
- * Callback triggered when Enter is pressed.
21
- * @param text The current text in the editor
22
- * @returns true if the editor should reset the document.
23
- */
24
- onSubmit?: (text: string) => boolean | void;
25
-
26
- /**
27
- * Function that returns a list of suggestions based on the current text.
28
- * @param text The current text before the cursor
29
- * @returns Array of suggestion strings
30
- */
31
- onSuggest?: (text: string) => string[];
32
-
33
- /**
34
- * ESC pressed.
35
- */
36
- onCancel?: () => void;
37
- };
38
-
39
- /**
40
- * Creates an autocomplete extension that shows inline suggestions.
41
- * Pressing Tab will complete the suggestion.
42
- */
43
- // TODO(burdon): Move to react-ui-editor.
44
- export const autocomplete = ({ fireIfEmpty, onSubmit, onSuggest, onCancel }: AutocompleteOptions): Extension => {
45
- const suggest = ViewPlugin.fromClass(
46
- class {
47
- _decorations: DecorationSet;
48
- _currentSuggestion: string | null = null;
49
-
50
- constructor(view: EditorView) {
51
- this._decorations = this.computeDecorations(view);
52
- }
53
-
54
- update(update: ViewUpdate) {
55
- if (update.docChanged || update.selectionSet) {
56
- this._decorations = this.computeDecorations(update.view);
57
- }
58
- }
59
-
60
- private computeDecorations(view: EditorView): DecorationSet {
61
- const text = view.state.doc.toString();
62
- const suggestions = onSuggest?.(text) ?? [];
63
- if (!suggestions.length) {
64
- this._currentSuggestion = null;
65
- return Decoration.none;
66
- }
67
-
68
- // Get the first suggestion.
69
- this._currentSuggestion = suggestions[0];
70
- const suffix = this._currentSuggestion.slice(text.length);
71
- if (!suffix) {
72
- return Decoration.none;
73
- }
74
-
75
- // Always show ghost text at the end of the document.
76
- return Decoration.set([
77
- Decoration.widget({
78
- widget: new InlineSuggestionWidget(suffix),
79
- side: 1,
80
- }).range(view.state.doc.length),
81
- ]);
82
- }
83
-
84
- completeSuggestion(view: EditorView): boolean {
85
- if (!this._currentSuggestion) {
86
- return false;
87
- }
88
-
89
- const text = view.state.doc.toString();
90
- const suffix = this._currentSuggestion.slice(text.length);
91
- if (!suffix) {
92
- return false;
93
- }
94
-
95
- view.dispatch({
96
- changes: {
97
- from: view.state.doc.length,
98
- insert: suffix,
99
- },
100
- selection: {
101
- anchor: view.state.doc.length + suffix.length,
102
- },
103
- });
104
-
105
- return true;
106
- }
107
- },
108
- {
109
- decorations: (v) => v._decorations,
110
- },
111
- );
112
-
113
- return [
114
- suggest,
115
- EditorView.theme({
116
- '.cm-inline-suggestion': {
117
- opacity: 0.4,
118
- },
119
- }),
120
-
121
- Prec.highest(
122
- keymap.of([
123
- {
124
- key: 'Tab',
125
- preventDefault: true,
126
- run: (view) => {
127
- const plugin = view.plugin(suggest);
128
- return plugin?.completeSuggestion(view) ?? false;
129
- },
130
- },
131
- {
132
- key: 'ArrowRight',
133
- preventDefault: true,
134
- run: (view) => {
135
- // Only complete if cursor is at the end
136
- if (view.state.selection.main.head !== view.state.doc.length) {
137
- return false;
138
- }
139
-
140
- const plugin = view.plugin(suggest);
141
- return plugin?.completeSuggestion(view) ?? false;
142
- },
143
- },
144
- {
145
- key: 'Enter',
146
- preventDefault: true,
147
- run: (view) => {
148
- const text = view.state.doc.toString().trim();
149
- if (onSubmit && (fireIfEmpty || text.length > 0)) {
150
- const reset = onSubmit(text);
151
-
152
- // Clear the document after calling onEnter.
153
- if (reset) {
154
- view.dispatch({
155
- changes: {
156
- from: 0,
157
- to: view.state.doc.length,
158
- insert: '',
159
- },
160
- });
161
- }
162
- }
163
-
164
- return true;
165
- },
166
- },
167
- {
168
- key: 'Shift-Enter',
169
- preventDefault: true,
170
- run: (view) => {
171
- view.dispatch({
172
- changes: {
173
- from: view.state.selection.main.head,
174
- insert: '\n',
175
- },
176
- selection: {
177
- anchor: view.state.selection.main.head + 1,
178
- head: view.state.selection.main.head + 1,
179
- },
180
- });
181
- return true;
182
- },
183
- },
184
- {
185
- key: 'Escape',
186
- preventDefault: true,
187
- run: (view) => {
188
- // Clear the entire document.
189
- view.dispatch({
190
- changes: {
191
- from: 0,
192
- to: view.state.doc.length,
193
- insert: '',
194
- },
195
- });
196
- onCancel?.();
197
- return true;
198
- },
199
- },
200
- ]),
201
- ),
202
- ];
203
- };
204
-
205
- class InlineSuggestionWidget extends WidgetType {
206
- constructor(private suffix: string) {
207
- super();
208
- }
209
-
210
- override toDOM(): HTMLSpanElement {
211
- const span = document.createElement('span');
212
- span.textContent = this.suffix;
213
- span.className = 'cm-inline-suggestion';
214
- return span;
215
- }
216
-
217
- override eq(other: InlineSuggestionWidget): boolean {
218
- return other.suffix === this.suffix;
219
- }
220
- }