@dxos/react-ui-chat 0.8.4-main.b97322e → 0.8.4-main.bcb3aa67d6
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/dist/lib/browser/index.mjs +143 -335
- package/dist/lib/browser/index.mjs.map +4 -4
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +143 -335
- package/dist/lib/node-esm/index.mjs.map +4 -4
- package/dist/lib/node-esm/meta.json +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.d.ts +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +35 -5
- package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -8
- package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +20 -5
- package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
- package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
- package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
- package/dist/types/src/index.d.ts +1 -0
- package/dist/types/src/index.d.ts.map +1 -1
- package/dist/types/src/translations.d.ts +2 -35
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +43 -39
- package/src/components/ChatDialog/ChatDialog.stories.tsx +9 -10
- package/src/components/ChatDialog/ChatDialog.tsx +29 -19
- package/src/components/ChatEditor/ChatEditor.stories.tsx +24 -23
- package/src/components/ChatEditor/ChatEditor.tsx +33 -63
- package/src/components/ChatEditor/references.ts +19 -13
- package/src/index.ts +1 -0
- package/src/translations.ts +2 -41
- package/dist/types/src/components/ChatEditor/autocomplete.d.ts +0 -25
- package/dist/types/src/components/ChatEditor/autocomplete.d.ts.map +0 -1
- package/src/components/ChatEditor/autocomplete.ts +0 -218
|
@@ -1,121 +1,98 @@
|
|
|
1
1
|
// src/components/ChatDialog/ChatDialog.tsx
|
|
2
|
-
import { useSignals as _useSignals } from "@preact-signals/safe-react/tracking";
|
|
3
2
|
import { createContext } from "@radix-ui/react-context";
|
|
4
3
|
import React, { useEffect, useState } from "react";
|
|
5
4
|
import { Dialog, Icon, IconButton, useControlledState } from "@dxos/react-ui";
|
|
6
|
-
import {
|
|
7
|
-
import { mx } from "@dxos/
|
|
5
|
+
import { ResizeHandle, resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
|
|
6
|
+
import { mx } from "@dxos/ui-theme";
|
|
8
7
|
var preventDefault = (event) => event.preventDefault();
|
|
9
8
|
var Endcap = ({ children }) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
className: "grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center"
|
|
14
|
-
}, children);
|
|
15
|
-
} finally {
|
|
16
|
-
_effect.f();
|
|
17
|
-
}
|
|
9
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
10
|
+
className: "grid w-[var(--dx-rail-action)] h-[var(--dx-rail-action)] items-center justify-center"
|
|
11
|
+
}, children);
|
|
18
12
|
};
|
|
19
13
|
var [ChatDialogContextProvider, useChatDialogContext] = createContext("ChatDialog");
|
|
20
|
-
var ChatDialogRoot = ({ children, open:
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
onInteractOutside: preventDefault
|
|
49
|
-
}, children))));
|
|
50
|
-
} finally {
|
|
51
|
-
_effect.f();
|
|
52
|
-
}
|
|
14
|
+
var ChatDialogRoot = ({ children, open: openProp = false, expanded: expandedProp = false, onOpenChange, onExpandedChange, onEscape }) => {
|
|
15
|
+
const [size, setSize] = useState("min-content");
|
|
16
|
+
const [open, setOpen] = useControlledState(openProp, onOpenChange);
|
|
17
|
+
const [expanded, setExpanded] = useControlledState(expandedProp, onExpandedChange);
|
|
18
|
+
return /* @__PURE__ */ React.createElement(ChatDialogContextProvider, {
|
|
19
|
+
open,
|
|
20
|
+
setOpen,
|
|
21
|
+
expanded,
|
|
22
|
+
setExpanded,
|
|
23
|
+
size,
|
|
24
|
+
setSize
|
|
25
|
+
}, /* @__PURE__ */ React.createElement(Dialog.Root, {
|
|
26
|
+
modal: false,
|
|
27
|
+
open,
|
|
28
|
+
onOpenChange: setOpen
|
|
29
|
+
}, /* @__PURE__ */ React.createElement("div", {
|
|
30
|
+
role: "none",
|
|
31
|
+
className: "dx-dialog__overlay bg-transparent pointer-events-none",
|
|
32
|
+
"data-block-align": "end"
|
|
33
|
+
}, /* @__PURE__ */ React.createElement(Dialog.Content, {
|
|
34
|
+
size: "md",
|
|
35
|
+
inOverlayLayout: true,
|
|
36
|
+
classNames: [
|
|
37
|
+
"grid grid-rows-[var(--dx-rail-action)_1fr_min-content] p-0 overflow-hidden box-content pointer-events-auto"
|
|
38
|
+
],
|
|
39
|
+
onEscapeKeyDown: onEscape,
|
|
40
|
+
onInteractOutside: preventDefault
|
|
41
|
+
}, children))));
|
|
53
42
|
};
|
|
54
43
|
ChatDialogRoot.displayName = "ChatDialog.Root";
|
|
44
|
+
var CHAT_DIALOG_HEADER_NAME = "ChatDialog.Header";
|
|
55
45
|
var ChatDialogHeader = ({ classNames, title }) => {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
onClick: () => setExpanded((expanded2) => !expanded2)
|
|
73
|
-
})));
|
|
74
|
-
} finally {
|
|
75
|
-
_effect.f();
|
|
76
|
-
}
|
|
46
|
+
const { expanded, setExpanded } = useChatDialogContext(CHAT_DIALOG_HEADER_NAME);
|
|
47
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
48
|
+
className: mx("grid grid-cols-[var(--dx-rail-action)_1fr_min-content] items-center overflow-hidden", classNames)
|
|
49
|
+
}, /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(Dialog.Close, null, /* @__PURE__ */ React.createElement(Icon, {
|
|
50
|
+
icon: "ph--x--regular"
|
|
51
|
+
}))), /* @__PURE__ */ React.createElement(Dialog.Title, {
|
|
52
|
+
classNames: "flex w-full justify-center text-sm text-subdued select-none cursor-pointer",
|
|
53
|
+
onClick: () => setExpanded((expanded2) => !expanded2)
|
|
54
|
+
}, title), /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(IconButton, {
|
|
55
|
+
variant: "ghost",
|
|
56
|
+
icon: "ph--caret-up--regular",
|
|
57
|
+
iconOnly: true,
|
|
58
|
+
classNames: mx("p-1! [&>svg]:transition [&>svg]:duration-200", expanded && "[&>svg]:rotate-180"),
|
|
59
|
+
label: expanded ? "Close" : "Open",
|
|
60
|
+
onClick: () => setExpanded((expanded2) => !expanded2)
|
|
61
|
+
})));
|
|
77
62
|
};
|
|
78
|
-
ChatDialogHeader.displayName =
|
|
63
|
+
ChatDialogHeader.displayName = CHAT_DIALOG_HEADER_NAME;
|
|
64
|
+
var CHAT_DIALOG_CONTENT_NAME = "ChatDialog.Content";
|
|
79
65
|
var ChatDialogContent = ({ children, classNames }) => {
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
])
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
onSizeChange: setSize
|
|
102
|
-
}), children);
|
|
103
|
-
} finally {
|
|
104
|
-
_effect.f();
|
|
105
|
-
}
|
|
66
|
+
const { expanded, size, setSize } = useChatDialogContext(CHAT_DIALOG_CONTENT_NAME);
|
|
67
|
+
useEffect(() => {
|
|
68
|
+
setSize(expanded ? "min-content" : 0);
|
|
69
|
+
}, [
|
|
70
|
+
expanded
|
|
71
|
+
]);
|
|
72
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
73
|
+
className: mx("border-t border-b border-subdued-separator", 'transition ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200', classNames),
|
|
74
|
+
style: {
|
|
75
|
+
...sizeStyle(size, "vertical", true),
|
|
76
|
+
maxBlockSize: "calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)"
|
|
77
|
+
},
|
|
78
|
+
...resizeAttributes
|
|
79
|
+
}, /* @__PURE__ */ React.createElement(ResizeHandle, {
|
|
80
|
+
side: "block-start",
|
|
81
|
+
iconPosition: "center",
|
|
82
|
+
defaultSize: "min-content",
|
|
83
|
+
fallbackSize: 0,
|
|
84
|
+
minSize: 0,
|
|
85
|
+
onSizeChange: setSize
|
|
86
|
+
}), children);
|
|
106
87
|
};
|
|
107
|
-
ChatDialogContent.displayName =
|
|
88
|
+
ChatDialogContent.displayName = CHAT_DIALOG_CONTENT_NAME;
|
|
89
|
+
var CHAT_DIALOG_FOOTER_NAME = "ChatDialog.Footer";
|
|
108
90
|
var ChatDialogFooter = ({ children, classNames }) => {
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
className: mx(classNames)
|
|
113
|
-
}, children);
|
|
114
|
-
} finally {
|
|
115
|
-
_effect.f();
|
|
116
|
-
}
|
|
91
|
+
return /* @__PURE__ */ React.createElement("div", {
|
|
92
|
+
className: mx(classNames)
|
|
93
|
+
}, children);
|
|
117
94
|
};
|
|
118
|
-
ChatDialogFooter.displayName =
|
|
95
|
+
ChatDialogFooter.displayName = CHAT_DIALOG_FOOTER_NAME;
|
|
119
96
|
var ChatDialog = {
|
|
120
97
|
Root: ChatDialogRoot,
|
|
121
98
|
Header: ChatDialogHeader,
|
|
@@ -133,7 +110,7 @@ var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-chat/src/components/Chat
|
|
|
133
110
|
var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
134
111
|
invariant(triggerCharacter.length === 1, void 0, {
|
|
135
112
|
F: __dxlog_file,
|
|
136
|
-
L:
|
|
113
|
+
L: 56,
|
|
137
114
|
S: void 0,
|
|
138
115
|
A: [
|
|
139
116
|
"triggerCharacter.length === 1",
|
|
@@ -141,10 +118,10 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
141
118
|
]
|
|
142
119
|
});
|
|
143
120
|
const decorationField = ViewPlugin.fromClass(class ReferenceView {
|
|
121
|
+
// TODO(burdon): Why?
|
|
122
|
+
_mutex = new Mutex();
|
|
123
|
+
decorations = Decoration.set([]);
|
|
144
124
|
constructor(view) {
|
|
145
|
-
// TODO(burdon): Why?
|
|
146
|
-
this._mutex = new Mutex();
|
|
147
|
-
this.decorations = Decoration.set([]);
|
|
148
125
|
queueMicrotask(async () => {
|
|
149
126
|
const guard = await this._mutex.acquire();
|
|
150
127
|
try {
|
|
@@ -186,7 +163,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
186
163
|
}
|
|
187
164
|
}, {
|
|
188
165
|
decorations: (v) => v.decorations,
|
|
189
|
-
provide: (
|
|
166
|
+
provide: () => [
|
|
190
167
|
EditorView.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
|
|
191
168
|
]
|
|
192
169
|
});
|
|
@@ -201,7 +178,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
201
178
|
}
|
|
202
179
|
}),
|
|
203
180
|
autocompletion({
|
|
204
|
-
tooltipClass: () => "shadow rounded",
|
|
181
|
+
tooltipClass: () => "shadow rounded-sm",
|
|
205
182
|
activateOnTyping: true,
|
|
206
183
|
aboveCursor: true,
|
|
207
184
|
closeOnBlur: !debug,
|
|
@@ -230,251 +207,82 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
230
207
|
];
|
|
231
208
|
};
|
|
232
209
|
var ReferenceWidget = class extends WidgetType {
|
|
210
|
+
data;
|
|
233
211
|
constructor(data) {
|
|
234
212
|
super(), this.data = data;
|
|
235
213
|
}
|
|
236
|
-
toDOM() {
|
|
237
|
-
const span = document.createElement("span");
|
|
238
|
-
span.textContent = `@ ${this.data.label}`;
|
|
239
|
-
span.className = "cm-reference-pill";
|
|
240
|
-
return span;
|
|
241
|
-
}
|
|
242
|
-
eq(other) {
|
|
243
|
-
return other.data.uri === this.data.uri;
|
|
244
|
-
}
|
|
245
214
|
ignoreEvent() {
|
|
246
215
|
return true;
|
|
247
216
|
}
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
// src/components/ChatEditor/ChatEditor.tsx
|
|
251
|
-
import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
|
|
252
|
-
import React2, { forwardRef, useImperativeHandle } from "react";
|
|
253
|
-
import { useThemeContext } from "@dxos/react-ui";
|
|
254
|
-
import { createBasicExtensions, createThemeExtensions, useTextEditor } from "@dxos/react-ui-editor";
|
|
255
|
-
import { mx as mx2 } from "@dxos/react-ui-theme";
|
|
256
|
-
import { isNonNullable } from "@dxos/util";
|
|
257
|
-
|
|
258
|
-
// src/components/ChatEditor/autocomplete.ts
|
|
259
|
-
import { Prec } from "@codemirror/state";
|
|
260
|
-
import { EditorView as EditorView2, Decoration as Decoration2, ViewPlugin as ViewPlugin2, keymap as keymap2, WidgetType as WidgetType2 } from "@codemirror/view";
|
|
261
|
-
var autocomplete = ({ onSubmit, onSuggest, onCancel }) => {
|
|
262
|
-
const suggest = ViewPlugin2.fromClass(class {
|
|
263
|
-
constructor(view) {
|
|
264
|
-
this._currentSuggestion = null;
|
|
265
|
-
this._decorations = this.computeDecorations(view);
|
|
266
|
-
}
|
|
267
|
-
update(update) {
|
|
268
|
-
if (update.docChanged || update.selectionSet) {
|
|
269
|
-
this._decorations = this.computeDecorations(update.view);
|
|
270
|
-
}
|
|
271
|
-
}
|
|
272
|
-
computeDecorations(view) {
|
|
273
|
-
const text = view.state.doc.toString();
|
|
274
|
-
const suggestions = onSuggest?.(text) ?? [];
|
|
275
|
-
if (!suggestions.length) {
|
|
276
|
-
this._currentSuggestion = null;
|
|
277
|
-
return Decoration2.none;
|
|
278
|
-
}
|
|
279
|
-
this._currentSuggestion = suggestions[0];
|
|
280
|
-
const suffix = this._currentSuggestion.slice(text.length);
|
|
281
|
-
if (!suffix) {
|
|
282
|
-
return Decoration2.none;
|
|
283
|
-
}
|
|
284
|
-
return Decoration2.set([
|
|
285
|
-
Decoration2.widget({
|
|
286
|
-
widget: new InlineSuggestionWidget(suffix),
|
|
287
|
-
side: 1
|
|
288
|
-
}).range(view.state.doc.length)
|
|
289
|
-
]);
|
|
290
|
-
}
|
|
291
|
-
completeSuggestion(view) {
|
|
292
|
-
if (!this._currentSuggestion) {
|
|
293
|
-
return false;
|
|
294
|
-
}
|
|
295
|
-
const text = view.state.doc.toString();
|
|
296
|
-
const suffix = this._currentSuggestion.slice(text.length);
|
|
297
|
-
if (!suffix) {
|
|
298
|
-
return false;
|
|
299
|
-
}
|
|
300
|
-
view.dispatch({
|
|
301
|
-
changes: {
|
|
302
|
-
from: view.state.doc.length,
|
|
303
|
-
insert: suffix
|
|
304
|
-
},
|
|
305
|
-
selection: {
|
|
306
|
-
anchor: view.state.doc.length + suffix.length
|
|
307
|
-
}
|
|
308
|
-
});
|
|
309
|
-
return true;
|
|
310
|
-
}
|
|
311
|
-
}, {
|
|
312
|
-
decorations: (v) => v._decorations
|
|
313
|
-
});
|
|
314
|
-
return [
|
|
315
|
-
suggest,
|
|
316
|
-
EditorView2.theme({
|
|
317
|
-
".cm-inline-suggestion": {
|
|
318
|
-
opacity: 0.4
|
|
319
|
-
}
|
|
320
|
-
}),
|
|
321
|
-
Prec.highest(keymap2.of([
|
|
322
|
-
{
|
|
323
|
-
key: "Tab",
|
|
324
|
-
preventDefault: true,
|
|
325
|
-
run: (view) => {
|
|
326
|
-
const plugin = view.plugin(suggest);
|
|
327
|
-
return plugin?.completeSuggestion(view) ?? false;
|
|
328
|
-
}
|
|
329
|
-
},
|
|
330
|
-
{
|
|
331
|
-
key: "ArrowRight",
|
|
332
|
-
preventDefault: true,
|
|
333
|
-
run: (view) => {
|
|
334
|
-
if (view.state.selection.main.head !== view.state.doc.length) {
|
|
335
|
-
return false;
|
|
336
|
-
}
|
|
337
|
-
const plugin = view.plugin(suggest);
|
|
338
|
-
return plugin?.completeSuggestion(view) ?? false;
|
|
339
|
-
}
|
|
340
|
-
},
|
|
341
|
-
{
|
|
342
|
-
key: "Enter",
|
|
343
|
-
preventDefault: true,
|
|
344
|
-
run: (view) => {
|
|
345
|
-
const text = view.state.doc.toString().trim();
|
|
346
|
-
if (text.length > 0 && onSubmit) {
|
|
347
|
-
const reset = onSubmit(text);
|
|
348
|
-
if (reset) {
|
|
349
|
-
view.dispatch({
|
|
350
|
-
changes: {
|
|
351
|
-
from: 0,
|
|
352
|
-
to: view.state.doc.length,
|
|
353
|
-
insert: ""
|
|
354
|
-
}
|
|
355
|
-
});
|
|
356
|
-
}
|
|
357
|
-
}
|
|
358
|
-
return true;
|
|
359
|
-
}
|
|
360
|
-
},
|
|
361
|
-
{
|
|
362
|
-
key: "Shift-Enter",
|
|
363
|
-
preventDefault: true,
|
|
364
|
-
run: (view) => {
|
|
365
|
-
view.dispatch({
|
|
366
|
-
changes: {
|
|
367
|
-
from: view.state.selection.main.head,
|
|
368
|
-
insert: "\n"
|
|
369
|
-
},
|
|
370
|
-
selection: {
|
|
371
|
-
anchor: view.state.selection.main.head + 1,
|
|
372
|
-
head: view.state.selection.main.head + 1
|
|
373
|
-
}
|
|
374
|
-
});
|
|
375
|
-
return true;
|
|
376
|
-
}
|
|
377
|
-
},
|
|
378
|
-
{
|
|
379
|
-
key: "Escape",
|
|
380
|
-
preventDefault: true,
|
|
381
|
-
run: (view) => {
|
|
382
|
-
view.dispatch({
|
|
383
|
-
changes: {
|
|
384
|
-
from: 0,
|
|
385
|
-
to: view.state.doc.length,
|
|
386
|
-
insert: ""
|
|
387
|
-
}
|
|
388
|
-
});
|
|
389
|
-
onCancel?.();
|
|
390
|
-
return true;
|
|
391
|
-
}
|
|
392
|
-
}
|
|
393
|
-
]))
|
|
394
|
-
];
|
|
395
|
-
};
|
|
396
|
-
var InlineSuggestionWidget = class extends WidgetType2 {
|
|
397
|
-
constructor(suffix) {
|
|
398
|
-
super(), this.suffix = suffix;
|
|
217
|
+
eq(other) {
|
|
218
|
+
return this.data.uri === other.data.uri;
|
|
399
219
|
}
|
|
400
220
|
toDOM() {
|
|
401
221
|
const span = document.createElement("span");
|
|
402
|
-
span.textContent = this.
|
|
403
|
-
span.className = "cm-
|
|
222
|
+
span.textContent = `@${this.data.label}`;
|
|
223
|
+
span.className = "cm-reference-pill";
|
|
404
224
|
return span;
|
|
405
225
|
}
|
|
406
|
-
eq(other) {
|
|
407
|
-
return other.suffix === this.suffix;
|
|
408
|
-
}
|
|
409
226
|
};
|
|
410
227
|
|
|
411
228
|
// src/components/ChatEditor/ChatEditor.tsx
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
provider: references2.provider
|
|
430
|
-
}) : [],
|
|
431
|
-
createBasicExtensions({
|
|
432
|
-
bracketMatching: false,
|
|
433
|
-
lineWrapping,
|
|
434
|
-
placeholder
|
|
435
|
-
}),
|
|
436
|
-
extensions
|
|
437
|
-
].filter(isNonNullable)
|
|
438
|
-
}, [
|
|
439
|
-
themeMode,
|
|
440
|
-
extensions,
|
|
441
|
-
onSubmit,
|
|
442
|
-
onSuggest
|
|
443
|
-
]);
|
|
444
|
-
useImperativeHandle(forwardRef2, () => {
|
|
445
|
-
return {
|
|
446
|
-
focus: () => {
|
|
447
|
-
view?.focus();
|
|
448
|
-
},
|
|
449
|
-
setText: (text) => {
|
|
450
|
-
view?.dispatch({
|
|
451
|
-
changes: {
|
|
452
|
-
from: 0,
|
|
453
|
-
to: view.state.doc.length,
|
|
454
|
-
insert: text
|
|
455
|
-
},
|
|
456
|
-
selection: {
|
|
457
|
-
anchor: text.length,
|
|
458
|
-
head: text.length
|
|
459
|
-
}
|
|
460
|
-
});
|
|
461
|
-
}
|
|
462
|
-
};
|
|
463
|
-
}, [
|
|
464
|
-
view,
|
|
229
|
+
import React2, { forwardRef, useMemo } from "react";
|
|
230
|
+
import { useThemeContext } from "@dxos/react-ui";
|
|
231
|
+
import { Editor } from "@dxos/react-ui-editor";
|
|
232
|
+
import { createBasicExtensions, createThemeExtensions, submit } from "@dxos/ui-editor";
|
|
233
|
+
import { isTruthy } from "@dxos/util";
|
|
234
|
+
var useChatExtensions = ({ extensions, lineWrapping = false, placeholder, onSubmit }) => {
|
|
235
|
+
const { themeMode } = useThemeContext();
|
|
236
|
+
return useMemo(() => [
|
|
237
|
+
createThemeExtensions({
|
|
238
|
+
themeMode
|
|
239
|
+
}),
|
|
240
|
+
createBasicExtensions({
|
|
241
|
+
bracketMatching: false,
|
|
242
|
+
lineWrapping,
|
|
243
|
+
placeholder
|
|
244
|
+
}),
|
|
245
|
+
submit({
|
|
465
246
|
onSubmit
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
247
|
+
}),
|
|
248
|
+
extensions
|
|
249
|
+
].filter(isTruthy), [
|
|
250
|
+
themeMode,
|
|
251
|
+
extensions,
|
|
252
|
+
onSubmit
|
|
253
|
+
]);
|
|
254
|
+
};
|
|
255
|
+
var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, autoFocus, extensions: extensionsProp, lineWrapping = false, placeholder, onSubmit }, forwardRef2) => {
|
|
256
|
+
const extensions = useChatExtensions({
|
|
257
|
+
extensions: extensionsProp,
|
|
258
|
+
lineWrapping,
|
|
259
|
+
placeholder,
|
|
260
|
+
onSubmit
|
|
261
|
+
});
|
|
262
|
+
return /* @__PURE__ */ React2.createElement(Editor.Root, {
|
|
263
|
+
ref: forwardRef2
|
|
264
|
+
}, /* @__PURE__ */ React2.createElement(Editor.Content, {
|
|
265
|
+
classNames,
|
|
266
|
+
autoFocus,
|
|
267
|
+
extensions
|
|
268
|
+
}));
|
|
474
269
|
});
|
|
270
|
+
|
|
271
|
+
// src/translations.ts
|
|
272
|
+
var translationKey = "@dxos/react-ui-chat";
|
|
273
|
+
var translations = [
|
|
274
|
+
{
|
|
275
|
+
"en-US": {
|
|
276
|
+
[translationKey]: {}
|
|
277
|
+
}
|
|
278
|
+
}
|
|
279
|
+
];
|
|
475
280
|
export {
|
|
476
281
|
ChatDialog,
|
|
477
282
|
ChatEditor,
|
|
478
|
-
references
|
|
283
|
+
references,
|
|
284
|
+
translationKey,
|
|
285
|
+
translations,
|
|
286
|
+
useChatExtensions
|
|
479
287
|
};
|
|
480
288
|
//# sourceMappingURL=index.mjs.map
|