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