@dxos/react-ui-chat 0.8.4-main.f9ba587 → 0.8.4-main.fcfe5033a5

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 (32) hide show
  1. package/dist/lib/browser/index.mjs +143 -335
  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 +143 -335
  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 -5
  10. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
  11. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -8
  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 -5
  14. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
  16. package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
  17. package/dist/types/src/index.d.ts +1 -0
  18. package/dist/types/src/index.d.ts.map +1 -1
  19. package/dist/types/src/translations.d.ts +2 -35
  20. package/dist/types/src/translations.d.ts.map +1 -1
  21. package/dist/types/tsconfig.tsbuildinfo +1 -1
  22. package/package.json +43 -39
  23. package/src/components/ChatDialog/ChatDialog.stories.tsx +8 -10
  24. package/src/components/ChatDialog/ChatDialog.tsx +29 -19
  25. package/src/components/ChatEditor/ChatEditor.stories.tsx +23 -23
  26. package/src/components/ChatEditor/ChatEditor.tsx +33 -67
  27. package/src/components/ChatEditor/references.ts +19 -13
  28. package/src/index.ts +1 -0
  29. package/src/translations.ts +2 -41
  30. package/dist/types/src/components/ChatEditor/autocomplete.d.ts +0 -25
  31. package/dist/types/src/components/ChatEditor/autocomplete.d.ts.map +0 -1
  32. package/src/components/ChatEditor/autocomplete.ts +0 -218
@@ -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
- }