@dxos/react-ui-chat 0.8.4-main.c4373fc → 0.8.4-main.c85a9c8dae
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 +145 -230
- package/dist/lib/browser/index.mjs.map +3 -3
- package/dist/lib/browser/meta.json +1 -1
- package/dist/lib/node-esm/index.mjs +145 -230
- package/dist/lib/node-esm/index.mjs.map +3 -3
- 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 +2 -3
- 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 +3 -3
- 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/translations.d.ts +2 -2
- package/dist/types/src/translations.d.ts.map +1 -1
- package/dist/types/tsconfig.tsbuildinfo +1 -1
- package/package.json +37 -35
- package/src/components/ChatDialog/ChatDialog.stories.tsx +3 -4
- package/src/components/ChatDialog/ChatDialog.tsx +27 -17
- package/src/components/ChatEditor/ChatEditor.stories.tsx +17 -15
- package/src/components/ChatEditor/ChatEditor.tsx +31 -80
- package/src/components/ChatEditor/references.ts +18 -12
- package/src/translations.ts +1 -1
|
@@ -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
7
|
import { ResizeHandle, resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
|
|
9
|
-
import { mx } from "@dxos/
|
|
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,
|
|
@@ -131,24 +108,11 @@ import { RangeSet } from "@codemirror/state";
|
|
|
131
108
|
import { Decoration, EditorView, ViewPlugin, WidgetType, keymap } from "@codemirror/view";
|
|
132
109
|
import { Mutex } from "@dxos/async";
|
|
133
110
|
import { invariant } from "@dxos/invariant";
|
|
134
|
-
function _define_property(obj, key, value) {
|
|
135
|
-
if (key in obj) {
|
|
136
|
-
Object.defineProperty(obj, key, {
|
|
137
|
-
value,
|
|
138
|
-
enumerable: true,
|
|
139
|
-
configurable: true,
|
|
140
|
-
writable: true
|
|
141
|
-
});
|
|
142
|
-
} else {
|
|
143
|
-
obj[key] = value;
|
|
144
|
-
}
|
|
145
|
-
return obj;
|
|
146
|
-
}
|
|
147
111
|
var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-chat/src/components/ChatEditor/references.ts";
|
|
148
112
|
var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
149
113
|
invariant(triggerCharacter.length === 1, void 0, {
|
|
150
114
|
F: __dxlog_file,
|
|
151
|
-
L:
|
|
115
|
+
L: 56,
|
|
152
116
|
S: void 0,
|
|
153
117
|
A: [
|
|
154
118
|
"triggerCharacter.length === 1",
|
|
@@ -156,6 +120,19 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
156
120
|
]
|
|
157
121
|
});
|
|
158
122
|
const decorationField = ViewPlugin.fromClass(class ReferenceView {
|
|
123
|
+
// TODO(burdon): Why?
|
|
124
|
+
_mutex = new Mutex();
|
|
125
|
+
decorations = Decoration.set([]);
|
|
126
|
+
constructor(view) {
|
|
127
|
+
queueMicrotask(async () => {
|
|
128
|
+
const guard = await this._mutex.acquire();
|
|
129
|
+
try {
|
|
130
|
+
this.decorations = await this._computeDecorations(view);
|
|
131
|
+
} finally {
|
|
132
|
+
guard.release();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
159
136
|
update(update) {
|
|
160
137
|
if (update.docChanged) {
|
|
161
138
|
queueMicrotask(async () => {
|
|
@@ -186,21 +163,9 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
186
163
|
}
|
|
187
164
|
return Decoration.set(decorations);
|
|
188
165
|
}
|
|
189
|
-
constructor(view) {
|
|
190
|
-
_define_property(this, "_mutex", new Mutex());
|
|
191
|
-
_define_property(this, "decorations", Decoration.set([]));
|
|
192
|
-
queueMicrotask(async () => {
|
|
193
|
-
const guard = await this._mutex.acquire();
|
|
194
|
-
try {
|
|
195
|
-
this.decorations = await this._computeDecorations(view);
|
|
196
|
-
} finally {
|
|
197
|
-
guard.release();
|
|
198
|
-
}
|
|
199
|
-
});
|
|
200
|
-
}
|
|
201
166
|
}, {
|
|
202
167
|
decorations: (v) => v.decorations,
|
|
203
|
-
provide: (
|
|
168
|
+
provide: () => [
|
|
204
169
|
EditorView.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
|
|
205
170
|
]
|
|
206
171
|
});
|
|
@@ -215,7 +180,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
215
180
|
}
|
|
216
181
|
}),
|
|
217
182
|
autocompletion({
|
|
218
|
-
tooltipClass: () => "shadow rounded",
|
|
183
|
+
tooltipClass: () => "shadow rounded-sm",
|
|
219
184
|
activateOnTyping: true,
|
|
220
185
|
aboveCursor: true,
|
|
221
186
|
closeOnBlur: !debug,
|
|
@@ -244,120 +209,69 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
|
|
|
244
209
|
];
|
|
245
210
|
};
|
|
246
211
|
var ReferenceWidget = class extends WidgetType {
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
span.className = "cm-reference-pill";
|
|
251
|
-
return span;
|
|
252
|
-
}
|
|
253
|
-
eq(other) {
|
|
254
|
-
return other.data.uri === this.data.uri;
|
|
212
|
+
data;
|
|
213
|
+
constructor(data) {
|
|
214
|
+
super(), this.data = data;
|
|
255
215
|
}
|
|
256
216
|
ignoreEvent() {
|
|
257
217
|
return true;
|
|
258
218
|
}
|
|
259
|
-
|
|
260
|
-
|
|
219
|
+
eq(other) {
|
|
220
|
+
return this.data.uri === other.data.uri;
|
|
221
|
+
}
|
|
222
|
+
toDOM() {
|
|
223
|
+
const span = document.createElement("span");
|
|
224
|
+
span.textContent = `@${this.data.label}`;
|
|
225
|
+
span.className = "cm-reference-pill";
|
|
226
|
+
return span;
|
|
261
227
|
}
|
|
262
228
|
};
|
|
263
229
|
|
|
264
230
|
// src/components/ChatEditor/ChatEditor.tsx
|
|
265
|
-
import {
|
|
266
|
-
import { keymap as keymap2 } from "@codemirror/view";
|
|
267
|
-
import { useFocusFinders } from "@fluentui/react-tabster";
|
|
268
|
-
import React2, { forwardRef, useImperativeHandle } from "react";
|
|
231
|
+
import React2, { forwardRef, useMemo } from "react";
|
|
269
232
|
import { useThemeContext } from "@dxos/react-ui";
|
|
270
|
-
import {
|
|
271
|
-
import {
|
|
233
|
+
import { Editor } from "@dxos/react-ui-editor";
|
|
234
|
+
import { createBasicExtensions, createThemeExtensions, submit } from "@dxos/ui-editor";
|
|
272
235
|
import { isTruthy } from "@dxos/util";
|
|
273
|
-
var
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
createBasicExtensions({
|
|
286
|
-
bracketMatching: false,
|
|
287
|
-
lineWrapping,
|
|
288
|
-
placeholder
|
|
289
|
-
}),
|
|
290
|
-
autocomplete({
|
|
291
|
-
onSubmit,
|
|
292
|
-
onSuggest,
|
|
293
|
-
onCancel
|
|
294
|
-
}),
|
|
295
|
-
references2 ? references({
|
|
296
|
-
provider: references2.provider
|
|
297
|
-
}) : [],
|
|
298
|
-
// TODO(burdon): Standardize.
|
|
299
|
-
keymap2.of([
|
|
300
|
-
{
|
|
301
|
-
key: "Tab",
|
|
302
|
-
preventDefault: true,
|
|
303
|
-
run: (view2) => {
|
|
304
|
-
findNextFocusable(view2.dom)?.focus();
|
|
305
|
-
return true;
|
|
306
|
-
}
|
|
307
|
-
},
|
|
308
|
-
{
|
|
309
|
-
key: "Shift-Tab",
|
|
310
|
-
preventDefault: true,
|
|
311
|
-
run: (view2) => {
|
|
312
|
-
findPrevFocusable(view2.dom)?.focus();
|
|
313
|
-
return true;
|
|
314
|
-
}
|
|
315
|
-
}
|
|
316
|
-
]),
|
|
317
|
-
extensions
|
|
318
|
-
].filter(isTruthy)
|
|
319
|
-
}), [
|
|
320
|
-
themeMode,
|
|
321
|
-
extensions,
|
|
322
|
-
onSubmit,
|
|
323
|
-
onSuggest,
|
|
324
|
-
onCancel
|
|
325
|
-
]);
|
|
326
|
-
useImperativeHandle(forwardRef2, () => {
|
|
327
|
-
return {
|
|
328
|
-
focus: () => {
|
|
329
|
-
view?.focus();
|
|
330
|
-
},
|
|
331
|
-
getText: () => view?.state.doc.toString() ?? "",
|
|
332
|
-
setText: (text) => {
|
|
333
|
-
view?.dispatch({
|
|
334
|
-
changes: {
|
|
335
|
-
from: 0,
|
|
336
|
-
to: view.state.doc.length,
|
|
337
|
-
insert: text
|
|
338
|
-
},
|
|
339
|
-
selection: {
|
|
340
|
-
anchor: text.length,
|
|
341
|
-
head: text.length
|
|
342
|
-
}
|
|
343
|
-
});
|
|
344
|
-
}
|
|
345
|
-
};
|
|
346
|
-
}, [
|
|
347
|
-
view,
|
|
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({
|
|
348
248
|
onSubmit
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
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.Content, {
|
|
267
|
+
classNames,
|
|
268
|
+
autoFocus,
|
|
269
|
+
extensions
|
|
270
|
+
}));
|
|
357
271
|
});
|
|
358
272
|
|
|
359
273
|
// src/translations.ts
|
|
360
|
-
var translationKey = "react-ui-chat";
|
|
274
|
+
var translationKey = "@dxos/react-ui-chat";
|
|
361
275
|
var translations = [
|
|
362
276
|
{
|
|
363
277
|
"en-US": {
|
|
@@ -370,6 +284,7 @@ export {
|
|
|
370
284
|
ChatEditor,
|
|
371
285
|
references,
|
|
372
286
|
translationKey,
|
|
373
|
-
translations
|
|
287
|
+
translations,
|
|
288
|
+
useChatExtensions
|
|
374
289
|
};
|
|
375
290
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/components/ChatDialog/ChatDialog.tsx", "../../../src/components/ChatEditor/references.ts", "../../../src/components/ChatEditor/ChatEditor.tsx", "../../../src/translations.ts"],
|
|
4
|
-
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type Dispatch, type PropsWithChildren, type SetStateAction, useEffect, useState } from 'react';\n\nimport { Dialog, Icon, IconButton, type ThemedClassName, useControlledState } from '@dxos/react-ui';\nimport { ResizeHandle, type Size, resizeAttributes, sizeStyle } from '@dxos/react-ui-dnd';\nimport { mx } from '@dxos/react-ui-theme';\n\nconst preventDefault = (event: Event) => event.preventDefault();\n\n// TODO(burdon): Factor out.\nconst Endcap = ({ children }: PropsWithChildren) => {\n return (\n <div className='grid w-[var(--rail-action)] h-[var(--rail-action)] items-center justify-center'>{children}</div>\n );\n};\n\n//\n// Context\n//\n\ntype ChatDialogContextValue = {\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n expanded: boolean;\n setExpanded: Dispatch<SetStateAction<boolean>>;\n size: Size;\n setSize: Dispatch<SetStateAction<Size>>;\n};\n\nconst [ChatDialogContextProvider, useChatDialogContext] = createContext<ChatDialogContextValue>('ChatDialog');\n\n//\n// Root\n//\n\ntype ChatDialogRootProps = PropsWithChildren<{\n open?: boolean;\n expanded?: boolean;\n onOpenChange?: (open: boolean) => void;\n onExpandedChange?: (expanded: boolean) => void;\n onEscape?: () => void;\n}>;\n\nconst ChatDialogRoot = ({\n children,\n open: _open = false,\n expanded: expandedParam = false,\n onOpenChange,\n onExpandedChange,\n onEscape,\n}: ChatDialogRootProps) => {\n const [size, setSize] = useState<Size>('min-content');\n const [open, setOpen] = useControlledState<boolean>(_open, onOpenChange);\n const [expanded, setExpanded] = useControlledState<boolean>(expandedParam, onExpandedChange);\n\n // NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.\n // 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.\n return (\n <ChatDialogContextProvider\n open={open}\n setOpen={setOpen}\n expanded={expanded}\n setExpanded={setExpanded}\n size={size}\n setSize={setSize}\n >\n <Dialog.Root modal={false} open={open} onOpenChange={setOpen}>\n <div role='none' className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>\n <Dialog.Content\n inOverlayLayout\n classNames={[\n 'grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden',\n 'box-content md:is-[35rem] md:max-is-none pointer-events-auto',\n ]}\n onEscapeKeyDown={onEscape}\n onInteractOutside={preventDefault}\n >\n {children}\n </Dialog.Content>\n </div>\n </Dialog.Root>\n </ChatDialogContextProvider>\n );\n};\n\nChatDialogRoot.displayName = 'ChatDialog.Root';\n\n//\n// Header\n//\n\ntype ChatDialogHeaderProps = ThemedClassName<{\n title?: string;\n}>;\n\nconst ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {\n const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);\n\n return (\n <div className={mx('grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}>\n <Endcap>\n <Dialog.Close>\n <Icon icon='ph--x--regular' />\n </Dialog.Close>\n </Endcap>\n <Dialog.Title\n classNames='flex w-full justify-center text-sm text-subdued select-none cursor-pointer'\n onClick={() => setExpanded((expanded) => !expanded)}\n >\n {title}\n </Dialog.Title>\n <Endcap>\n <IconButton\n variant='ghost'\n icon='ph--caret-up--regular'\n iconOnly\n classNames={mx('!p-1 [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}\n label={expanded ? 'Close' : 'Open'}\n onClick={() => setExpanded((expanded) => !expanded)}\n />\n </Endcap>\n </div>\n );\n};\n\nChatDialogHeader.displayName = 'ChatDialog.Header';\n\n//\n// Content\n//\n\ntype ChatDialogContentProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {\n const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);\n useEffect(() => {\n setSize(expanded ? 'min-content' : 0);\n }, [expanded]);\n\n return (\n <div\n className={mx(\n 'flex flex-col overflow-y-auto border-t border-b border-subduedSeparator',\n 'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing=\"true\"])]:duration-200',\n classNames,\n )}\n style={{\n ...sizeStyle(size, 'vertical', true),\n maxBlockSize: 'calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)',\n }}\n {...resizeAttributes}\n >\n <ResizeHandle\n side='block-start'\n iconPosition='center'\n defaultSize='min-content'\n fallbackSize={0}\n minSize={0}\n onSizeChange={setSize}\n />\n {children}\n </div>\n );\n};\n\nChatDialogContent.displayName = 'ChatDialog.Content';\n\n//\n// Footer\n//\n\ntype ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {\n return <div className={mx(classNames)}>{children}</div>;\n};\n\nChatDialogFooter.displayName = 'ChatDialog.Footer';\n\n//\n// ChatDialog\n//\n\nexport const ChatDialog = {\n Root: ChatDialogRoot,\n Header: ChatDialogHeader,\n Content: ChatDialogContent,\n Footer: ChatDialogFooter,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type CompletionResult, autocompletion, completionKeymap } from '@codemirror/autocomplete';\nimport { type Extension, RangeSet } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nimport { Mutex } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\n\n// TODO(dmaretskyi): Consider adding details renderer for when you hover over the reference.\nexport type ReferenceData = {\n uri: string;\n label: string;\n};\n\nexport interface ReferencesProvider {\n getReferences({ query }: { query: string }): Promise<ReferenceData[]>;\n resolveReference({ uri }: { uri: string }): Promise<ReferenceData | null>;\n}\n\nexport type ReferencesOptions = {\n provider: ReferencesProvider;\n\n /**\n * @default '@'\n */\n triggerCharacter?: string;\n\n /**\n * Prevent the autocomplete from closing when the user blurs the editor.\n * @default false\n */\n debug?: boolean;\n};\n\n/**\n * Lookup object references.\n */\nexport const references = ({ provider, triggerCharacter = '@', debug = false }: ReferencesOptions): Extension => {\n invariant(triggerCharacter.length === 1);\n\n const decorationField = ViewPlugin.fromClass(\n class ReferenceView {\n // TODO(burdon): Why?\n private _mutex = new Mutex();\n\n decorations: DecorationSet = Decoration.set([]);\n\n constructor(view: EditorView) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(view);\n } finally {\n guard.release();\n }\n });\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(update.view);\n } finally {\n guard.release();\n }\n });\n }\n }\n\n private async _computeDecorations(view: EditorView): Promise<DecorationSet> {\n const text = view.state.doc.toString();\n const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\\\s`, 'g'));\n\n const decorations = [];\n for (const match of references) {\n const reference = match[0];\n const uri = reference.slice(1, -1);\n const data = await provider.resolveReference({ uri });\n if (data) {\n decorations.push(\n Decoration.replace({\n widget: new ReferenceWidget(data),\n }).range(match.index!, match.index! + reference.length),\n );\n }\n }\n\n return Decoration.set(decorations);\n }\n },\n {\n decorations: (v) => v.decorations,\n provide: (plugin) => [\n EditorView.atomicRanges.of(\n (view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,\n ),\n ],\n },\n );\n\n return [\n decorationField,\n\n EditorView.theme({\n '.cm-reference-pill': {\n borderRadius: '0.25rem',\n borderWidth: '1px',\n marginRight: '0.25rem',\n marginLeft: '0.25rem',\n },\n }),\n\n autocompletion({\n tooltipClass: () => 'shadow rounded',\n activateOnTyping: true,\n aboveCursor: true,\n closeOnBlur: !debug,\n override: [\n async (context): Promise<CompletionResult | null> => {\n const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));\n if (!match || match?.to === match?.from) {\n return null;\n }\n\n const query = match.text.slice(1);\n const references = await provider.getReferences({ query });\n return {\n from: match.from,\n filter: false,\n options: references.map((reference) => ({\n label: reference.label,\n apply: `${triggerCharacter}${reference.uri} `,\n })),\n };\n },\n ],\n }),\n\n keymap.of(completionKeymap),\n ];\n};\n\nclass ReferenceWidget extends WidgetType {\n constructor(private data: ReferenceData) {\n super();\n }\n\n override toDOM(): HTMLSpanElement {\n const span = document.createElement('span');\n span.textContent = `@ ${this.data.label}`;\n span.className = 'cm-reference-pill';\n return span;\n }\n\n override eq(other: ReferenceWidget): boolean {\n return other.data.uri === this.data.uri;\n }\n\n override ignoreEvent(): boolean {\n return true;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension } from '@codemirror/state';\nimport { keymap } from '@codemirror/view';\nimport { useFocusFinders } from '@fluentui/react-tabster';\nimport React, { forwardRef, useImperativeHandle } from 'react';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport {\n type AutocompleteOptions,\n type BasicExtensionsOptions,\n type UseTextEditorProps,\n autocomplete,\n createBasicExtensions,\n createThemeExtensions,\n useTextEditor,\n} from '@dxos/react-ui-editor';\nimport { mx } from '@dxos/react-ui-theme';\nimport { isTruthy } from '@dxos/util';\n\nimport { type ReferencesOptions, references as referencesExtension } from './references';\n\nexport interface ChatEditorController {\n focus(): void;\n getText(): string;\n setText(text: string): void;\n}\n\nexport type ChatEditorProps = ThemedClassName<\n {\n extensions?: Extension;\n references?: ReferencesOptions;\n } & AutocompleteOptions &\n Pick<UseTextEditorProps, 'id' | 'autoFocus'> &\n Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>\n>;\n\nexport const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(\n (\n { classNames, extensions, references, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel },\n forwardRef,\n ) => {\n const { themeMode } = useThemeContext();\n const { findNextFocusable, findPrevFocusable } = useFocusFinders();\n const { parentRef, view } = useTextEditor(\n () => ({\n debug: true,\n autoFocus,\n extensions: [\n createThemeExtensions({ themeMode }),\n createBasicExtensions({ bracketMatching: false, lineWrapping, placeholder }),\n autocomplete({ onSubmit, onSuggest, onCancel }),\n references ? referencesExtension({ provider: references.provider }) : [],\n // TODO(burdon): Standardize.\n keymap.of([\n {\n key: 'Tab',\n preventDefault: true,\n run: (view) => {\n findNextFocusable(view.dom)?.focus();\n return true;\n },\n },\n {\n key: 'Shift-Tab',\n preventDefault: true,\n run: (view) => {\n findPrevFocusable(view.dom)?.focus();\n return true;\n },\n },\n ]),\n extensions,\n ].filter(isTruthy),\n }),\n [themeMode, extensions, onSubmit, onSuggest, onCancel],\n );\n\n // Expose editor view.\n useImperativeHandle(forwardRef, () => {\n return {\n focus: () => {\n view?.focus();\n },\n getText: () => view?.state.doc.toString() ?? '',\n setText: (text: string) => {\n view?.dispatch({\n changes: {\n from: 0,\n to: view.state.doc.length,\n insert: text,\n },\n selection: {\n anchor: text.length,\n head: text.length,\n },\n });\n },\n };\n }, [view, onSubmit]);\n\n return <div ref={parentRef} className={mx('is-full', classNames)} />;\n },\n);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Resource } from '@dxos/react-ui';\n\nexport const translationKey = 'react-ui-chat';\n\nexport const translations = [\n {\n 'en-US': {\n [translationKey]: {},\n },\n },\n] as const satisfies Resource[];\n"],
|
|
5
|
-
"mappings": "
|
|
6
|
-
"names": ["createContext", "React", "useEffect", "useState", "Dialog", "Icon", "IconButton", "useControlledState", "ResizeHandle", "resizeAttributes", "sizeStyle", "mx", "preventDefault", "event", "Endcap", "children", "div", "className", "ChatDialogContextProvider", "useChatDialogContext", "createContext", "ChatDialogRoot", "open", "
|
|
4
|
+
"sourcesContent": ["//\n// Copyright 2025 DXOS.org\n//\n\nimport { createContext } from '@radix-ui/react-context';\nimport React, { type Dispatch, type PropsWithChildren, type SetStateAction, useEffect, useState } from 'react';\n\nimport { Dialog, Icon, IconButton, type ThemedClassName, useControlledState } from '@dxos/react-ui';\nimport { ResizeHandle, type Size, resizeAttributes, sizeStyle } from '@dxos/react-ui-dnd';\nimport { mx } from '@dxos/ui-theme';\n\nconst preventDefault = (event: Event) => event.preventDefault();\n\n// TODO(burdon): Factor out.\nconst Endcap = ({ children }: PropsWithChildren) => {\n return (\n <div className='grid w-[var(--dx-rail-action)] h-[var(--dx-rail-action)] items-center justify-center'>\n {children}\n </div>\n );\n};\n\n//\n// Context\n//\n\ntype ChatDialogContextValue = {\n open: boolean;\n setOpen: Dispatch<SetStateAction<boolean>>;\n expanded: boolean;\n setExpanded: Dispatch<SetStateAction<boolean>>;\n size: Size;\n setSize: Dispatch<SetStateAction<Size>>;\n};\n\nconst [ChatDialogContextProvider, useChatDialogContext] = createContext<ChatDialogContextValue>('ChatDialog');\n\n//\n// Root\n//\n\ntype ChatDialogRootProps = PropsWithChildren<{\n open?: boolean;\n expanded?: boolean;\n onOpenChange?: (open: boolean) => void;\n onExpandedChange?: (expanded: boolean) => void;\n onEscape?: () => void;\n}>;\n\nconst ChatDialogRoot = ({\n children,\n open: openProp = false,\n expanded: expandedProp = false,\n onOpenChange,\n onExpandedChange,\n onEscape,\n}: ChatDialogRootProps) => {\n const [size, setSize] = useState<Size>('min-content');\n const [open, setOpen] = useControlledState<boolean>(openProp, onOpenChange);\n const [expanded, setExpanded] = useControlledState<boolean>(expandedProp, onExpandedChange);\n\n // NOTE: We set the min size to 5rem (80px), and the header and prompt bar to 40px (i.e., the rail-size) each.\n // 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.\n return (\n <ChatDialogContextProvider\n open={open}\n setOpen={setOpen}\n expanded={expanded}\n setExpanded={setExpanded}\n size={size}\n setSize={setSize}\n >\n <Dialog.Root modal={false} open={open} onOpenChange={setOpen}>\n <div role='none' className='dx-dialog__overlay bg-transparent pointer-events-none' data-block-align='end'>\n <Dialog.Content\n size='md'\n inOverlayLayout\n classNames={[\n 'grid grid-rows-[var(--dx-rail-action)_1fr_min-content] p-0 overflow-hidden box-content pointer-events-auto',\n ]}\n onEscapeKeyDown={onEscape}\n onInteractOutside={preventDefault}\n >\n {children}\n </Dialog.Content>\n </div>\n </Dialog.Root>\n </ChatDialogContextProvider>\n );\n};\n\nChatDialogRoot.displayName = 'ChatDialog.Root';\n\n//\n// Header\n//\n\nconst CHAT_DIALOG_HEADER_NAME = 'ChatDialog.Header';\n\ntype ChatDialogHeaderProps = ThemedClassName<{\n title?: string;\n}>;\n\nconst ChatDialogHeader = ({ classNames, title }: ChatDialogHeaderProps) => {\n const { expanded, setExpanded } = useChatDialogContext(CHAT_DIALOG_HEADER_NAME);\n\n return (\n <div\n className={mx('grid grid-cols-[var(--dx-rail-action)_1fr_min-content] items-center overflow-hidden', classNames)}\n >\n <Endcap>\n <Dialog.Close>\n <Icon icon='ph--x--regular' />\n </Dialog.Close>\n </Endcap>\n <Dialog.Title\n classNames='flex w-full justify-center text-sm text-subdued select-none cursor-pointer'\n onClick={() => setExpanded((expanded) => !expanded)}\n >\n {title}\n </Dialog.Title>\n <Endcap>\n <IconButton\n variant='ghost'\n icon='ph--caret-up--regular'\n iconOnly\n classNames={mx('p-1! [&>svg]:transition [&>svg]:duration-200', expanded && '[&>svg]:rotate-180')}\n label={expanded ? 'Close' : 'Open'}\n onClick={() => setExpanded((expanded) => !expanded)}\n />\n </Endcap>\n </div>\n );\n};\n\nChatDialogHeader.displayName = CHAT_DIALOG_HEADER_NAME;\n\n//\n// Content\n//\n\nconst CHAT_DIALOG_CONTENT_NAME = 'ChatDialog.Content';\n\ntype ChatDialogContentProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogContent = ({ children, classNames }: ChatDialogContentProps) => {\n const { expanded, size, setSize } = useChatDialogContext(CHAT_DIALOG_CONTENT_NAME);\n useEffect(() => {\n setSize(expanded ? 'min-content' : 0);\n }, [expanded]);\n\n return (\n <div\n className={mx(\n 'border-t border-b border-subdued-separator',\n 'transition ease-in-out duration-0 [&:not([data-dx-resizing=\"true\"])]:duration-200',\n classNames,\n )}\n style={{\n ...sizeStyle(size, 'vertical', true),\n maxBlockSize: 'calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)',\n }}\n {...resizeAttributes}\n >\n <ResizeHandle\n side='block-start'\n iconPosition='center'\n defaultSize='min-content'\n fallbackSize={0}\n minSize={0}\n onSizeChange={setSize}\n />\n {children}\n </div>\n );\n};\n\nChatDialogContent.displayName = CHAT_DIALOG_CONTENT_NAME;\n\n//\n// Footer\n//\n\nconst CHAT_DIALOG_FOOTER_NAME = 'ChatDialog.Footer';\n\ntype ChatDialogFooterProps = ThemedClassName<PropsWithChildren>;\n\nconst ChatDialogFooter = ({ children, classNames }: ChatDialogFooterProps) => {\n return <div className={mx(classNames)}>{children}</div>;\n};\n\nChatDialogFooter.displayName = CHAT_DIALOG_FOOTER_NAME;\n\n//\n// ChatDialog\n//\n\nexport const ChatDialog = {\n Root: ChatDialogRoot,\n Header: ChatDialogHeader,\n Content: ChatDialogContent,\n Footer: ChatDialogFooter,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type CompletionResult, autocompletion, completionKeymap } from '@codemirror/autocomplete';\nimport { type Extension, RangeSet } from '@codemirror/state';\nimport {\n Decoration,\n type DecorationSet,\n EditorView,\n ViewPlugin,\n type ViewUpdate,\n WidgetType,\n keymap,\n} from '@codemirror/view';\n\nimport { Mutex } from '@dxos/async';\nimport { invariant } from '@dxos/invariant';\n\n// TODO(dmaretskyi): Consider adding details renderer for when you hover over the reference.\nexport type ReferenceData = {\n uri: string; // TODO(burdon): Rename dxn.\n label: string;\n};\n\n/**\n * @deprecated\n */\n// TODO(burdon): Remove.\nexport interface ReferencesProvider {\n getReferences({ query }: { query: string }): Promise<ReferenceData[]>;\n resolveReference({ uri }: { uri: string }): Promise<ReferenceData | null>;\n}\n\nexport type ReferencesOptions = {\n provider: ReferencesProvider;\n\n /**\n * @default '@'\n */\n triggerCharacter?: string;\n\n /**\n * Prevent the autocomplete from closing when the user blurs the editor.\n * @default false\n */\n debug?: boolean;\n};\n\n/**\n * Lookup object references.\n * @deprecated\n */\n// TODO(burdon): Remove.\nexport const references = ({ provider, triggerCharacter = '@', debug = false }: ReferencesOptions): Extension => {\n invariant(triggerCharacter.length === 1);\n\n const decorationField = ViewPlugin.fromClass(\n class ReferenceView {\n // TODO(burdon): Why?\n private _mutex = new Mutex();\n\n decorations: DecorationSet = Decoration.set([]);\n\n constructor(view: EditorView) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(view);\n } finally {\n guard.release();\n }\n });\n }\n\n update(update: ViewUpdate) {\n if (update.docChanged) {\n queueMicrotask(async () => {\n const guard = await this._mutex.acquire();\n try {\n this.decorations = await this._computeDecorations(update.view);\n } finally {\n guard.release();\n }\n });\n }\n }\n\n private async _computeDecorations(view: EditorView): Promise<DecorationSet> {\n const text = view.state.doc.toString();\n const references = text.matchAll(new RegExp(`${triggerCharacter}[a-zA-Z0-9@:]+\\\\s`, 'g'));\n\n const decorations = [];\n for (const match of references) {\n const reference = match[0];\n const uri = reference.slice(1, -1);\n const data = await provider.resolveReference({ uri });\n if (data) {\n decorations.push(\n Decoration.replace({\n widget: new ReferenceWidget(data),\n }).range(match.index!, match.index! + reference.length),\n );\n }\n }\n\n return Decoration.set(decorations);\n }\n },\n {\n decorations: (v) => v.decorations,\n provide: () => [\n EditorView.atomicRanges.of(\n (view): DecorationSet => view.plugin(decorationField)?.decorations ?? RangeSet.empty,\n ),\n ],\n },\n );\n\n return [\n decorationField,\n\n EditorView.theme({\n '.cm-reference-pill': {\n borderRadius: '0.25rem',\n borderWidth: '1px',\n marginRight: '0.25rem',\n marginLeft: '0.25rem',\n },\n }),\n\n autocompletion({\n tooltipClass: () => 'shadow rounded-sm',\n activateOnTyping: true,\n aboveCursor: true,\n closeOnBlur: !debug,\n override: [\n async (context): Promise<CompletionResult | null> => {\n const match = context.matchBefore(new RegExp(`${triggerCharacter}[a-zA-Z0-9]+`));\n if (!match || match?.to === match?.from) {\n return null;\n }\n\n const query = match.text.slice(1);\n const references = await provider.getReferences({ query });\n return {\n from: match.from,\n filter: false,\n options: references.map((reference) => ({\n label: reference.label,\n apply: `${triggerCharacter}${reference.uri} `,\n })),\n };\n },\n ],\n }),\n\n keymap.of(completionKeymap),\n ];\n};\n\nclass ReferenceWidget extends WidgetType {\n constructor(private data: ReferenceData) {\n super();\n }\n\n override ignoreEvent() {\n return true;\n }\n\n override eq(other: this) {\n return this.data.uri === other.data.uri;\n }\n\n override toDOM() {\n const span = document.createElement('span');\n span.textContent = `@${this.data.label}`;\n span.className = 'cm-reference-pill';\n return span;\n }\n}\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { type Extension } from '@codemirror/state';\nimport React, { forwardRef, useMemo } from 'react';\n\nimport { type ThemedClassName, useThemeContext } from '@dxos/react-ui';\nimport { Editor, type EditorController, type UseTextEditorProps } from '@dxos/react-ui-editor';\nimport {\n type BasicExtensionsOptions,\n type SubmitOptions,\n createBasicExtensions,\n createThemeExtensions,\n submit,\n} from '@dxos/ui-editor';\nimport { isTruthy } from '@dxos/util';\n\nimport { type ReferencesOptions } from './references';\n\nexport interface ChatEditorController extends EditorController {}\n\nexport type ChatEditorProps = ThemedClassName<\n {\n extensions?: Extension;\n references?: ReferencesOptions;\n } & (SubmitOptions &\n Pick<UseTextEditorProps, 'id' | 'autoFocus'> &\n Pick<BasicExtensionsOptions, 'lineWrapping' | 'placeholder'>)\n>;\n\nexport const useChatExtensions = ({ extensions, lineWrapping = false, placeholder, onSubmit }: ChatEditorProps) => {\n const { themeMode } = useThemeContext();\n return useMemo<Extension[]>(\n () =>\n [\n createThemeExtensions({ themeMode }),\n createBasicExtensions({ bracketMatching: false, lineWrapping, placeholder }),\n submit({ onSubmit }),\n extensions,\n ].filter(isTruthy),\n [themeMode, extensions, onSubmit],\n );\n};\n\nexport const ChatEditor = forwardRef<ChatEditorController, ChatEditorProps>(\n ({ classNames, autoFocus, extensions: extensionsProp, lineWrapping = false, placeholder, onSubmit }, forwardRef) => {\n const extensions = useChatExtensions({ extensions: extensionsProp, lineWrapping, placeholder, onSubmit });\n\n // TODO(burdon): Popover.\n return (\n <Editor.Root ref={forwardRef}>\n <Editor.Content classNames={classNames} autoFocus={autoFocus} extensions={extensions} />\n </Editor.Root>\n );\n },\n);\n", "//\n// Copyright 2023 DXOS.org\n//\n\nimport { type Resource } from '@dxos/react-ui';\n\nexport const translationKey = '@dxos/react-ui-chat';\n\nexport const translations = [\n {\n 'en-US': {\n [translationKey]: {},\n },\n },\n] as const satisfies Resource[];\n"],
|
|
5
|
+
"mappings": ";;;AAIA,SAASA,qBAAqB;AAC9B,OAAOC,SAAqEC,WAAWC,gBAAgB;AAEvG,SAASC,QAAQC,MAAMC,YAAkCC,0BAA0B;AACnF,SAASC,cAAyBC,kBAAkBC,iBAAiB;AACrE,SAASC,UAAU;AAEnB,IAAMC,iBAAiB,CAACC,UAAiBA,MAAMD,eAAc;AAG7D,IAAME,SAAS,CAAC,EAAEC,SAAQ,MAAqB;AAC7C,SACE,sBAAA,cAACC,OAAAA;IAAIC,WAAU;KACZF,QAAAA;AAGP;AAeA,IAAM,CAACG,2BAA2BC,oBAAAA,IAAwBC,cAAsC,YAAA;AAchG,IAAMC,iBAAiB,CAAC,EACtBN,UACAO,MAAMC,WAAW,OACjBC,UAAUC,eAAe,OACzBC,cACAC,kBACAC,SAAQ,MACY;AACpB,QAAM,CAACC,MAAMC,OAAAA,IAAWC,SAAe,aAAA;AACvC,QAAM,CAACT,MAAMU,OAAAA,IAAWC,mBAA4BV,UAAUG,YAAAA;AAC9D,QAAM,CAACF,UAAUU,WAAAA,IAAeD,mBAA4BR,cAAcE,gBAAAA;AAI1E,SACE,sBAAA,cAACT,2BAAAA;IACCI;IACAU;IACAR;IACAU;IACAL;IACAC;KAEA,sBAAA,cAACK,OAAOC,MAAI;IAACC,OAAO;IAAOf;IAAYI,cAAcM;KACnD,sBAAA,cAA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AAaC,2BACxB,CAAC,EAAEC,YAAYC,WAAWhB,YAAYiB,gBAAgBhB,eAAe,OAAOC,aAAaC,SAAQ,GAAIW,gBAAAA;AACnG,QAAMd,aAAaD,kBAAkB;IAAEC,YAAYiB;IAAgBhB;IAAcC;IAAaC;EAAS,CAAA;AAGvG,SACE,gBAAAe,OAAA,cAACC,OAAOC,MAAI;IAACC,KAAKP;KAChB,gBAAAI,OAAA,cAACC,OAAOG,SAAO;IAACP;IAAwBC;IAAsBhB;;AAGpE,CAAA;;;ACjDK,IAAMuB,iBAAiB;AAEvB,IAAMC,eAAe;EAC1B;IACE,SAAS;MACP,CAACD,cAAAA,GAAiB,CAAC;IACrB;EACF;;",
|
|
6
|
+
"names": ["createContext", "React", "useEffect", "useState", "Dialog", "Icon", "IconButton", "useControlledState", "ResizeHandle", "resizeAttributes", "sizeStyle", "mx", "preventDefault", "event", "Endcap", "children", "div", "className", "ChatDialogContextProvider", "useChatDialogContext", "createContext", "ChatDialogRoot", "open", "openProp", "expanded", "expandedProp", "onOpenChange", "onExpandedChange", "onEscape", "size", "setSize", "useState", "setOpen", "useControlledState", "setExpanded", "Dialog", "Root", "modal", "role", "data-block-align", "Content", "inOverlayLayout", "classNames", "onEscapeKeyDown", "onInteractOutside", "displayName", "CHAT_DIALOG_HEADER_NAME", "ChatDialogHeader", "title", "mx", "Close", "Icon", "icon", "Title", "onClick", "IconButton", "variant", "iconOnly", "label", "CHAT_DIALOG_CONTENT_NAME", "ChatDialogContent", "useEffect", "style", "sizeStyle", "maxBlockSize", "resizeAttributes", "ResizeHandle", "side", "iconPosition", "defaultSize", "fallbackSize", "minSize", "onSizeChange", "CHAT_DIALOG_FOOTER_NAME", "ChatDialogFooter", "ChatDialog", "Header", "Footer", "autocompletion", "completionKeymap", "RangeSet", "Decoration", "EditorView", "ViewPlugin", "WidgetType", "keymap", "Mutex", "invariant", "references", "provider", "triggerCharacter", "debug", "length", "decorationField", "fromClass", "ReferenceView", "_mutex", "decorations", "set", "view", "queueMicrotask", "guard", "acquire", "_computeDecorations", "release", "update", "docChanged", "text", "state", "doc", "toString", "matchAll", "RegExp", "match", "reference", "uri", "slice", "data", "resolveReference", "push", "replace", "widget", "ReferenceWidget", "range", "index", "v", "provide", "atomicRanges", "of", "plugin", "empty", "theme", "borderRadius", "borderWidth", "marginRight", "marginLeft", "tooltipClass", "activateOnTyping", "aboveCursor", "closeOnBlur", "override", "context", "matchBefore", "to", "from", "query", "getReferences", "filter", "options", "map", "label", "apply", "ignoreEvent", "eq", "other", "toDOM", "span", "document", "createElement", "textContent", "className", "React", "forwardRef", "useMemo", "useThemeContext", "Editor", "createBasicExtensions", "createThemeExtensions", "submit", "isTruthy", "useChatExtensions", "extensions", "lineWrapping", "placeholder", "onSubmit", "themeMode", "useThemeContext", "useMemo", "createThemeExtensions", "createBasicExtensions", "bracketMatching", "submit", "filter", "isTruthy", "ChatEditor", "forwardRef", "classNames", "autoFocus", "extensionsProp", "React", "Editor", "Root", "ref", "Content", "translationKey", "translations"]
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytes":
|
|
1
|
+
{"inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytes":17552,"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatDialog/index.ts":{"bytes":480,"imports":[{"path":"src/components/ChatDialog/ChatDialog.tsx","kind":"import-statement","original":"./ChatDialog"}],"format":"esm"},"src/components/ChatEditor/references.ts":{"bytes":16061,"imports":[{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/ChatEditor.tsx":{"bytes":5856,"imports":[{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true},{"path":"@dxos/ui-editor","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"format":"esm"},"src/components/ChatEditor/index.ts":{"bytes":574,"imports":[{"path":"src/components/ChatEditor/references.ts","kind":"import-statement","original":"./references"},{"path":"src/components/ChatEditor/ChatEditor.tsx","kind":"import-statement","original":"./ChatEditor"}],"format":"esm"},"src/components/index.ts":{"bytes":563,"imports":[{"path":"src/components/ChatDialog/index.ts","kind":"import-statement","original":"./ChatDialog"},{"path":"src/components/ChatEditor/index.ts","kind":"import-statement","original":"./ChatEditor"}],"format":"esm"},"src/translations.ts":{"bytes":1055,"imports":[],"format":"esm"},"src/index.ts":{"bytes":558,"imports":[{"path":"src/components/index.ts","kind":"import-statement","original":"./components"},{"path":"src/translations.ts","kind":"import-statement","original":"./translations"}],"format":"esm"}},"outputs":{"dist/lib/node-esm/index.mjs.map":{"imports":[],"exports":[],"inputs":{},"bytes":21223},"dist/lib/node-esm/index.mjs":{"imports":[{"path":"@radix-ui/react-context","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-dnd","kind":"import-statement","external":true},{"path":"@dxos/ui-theme","kind":"import-statement","external":true},{"path":"@codemirror/autocomplete","kind":"import-statement","external":true},{"path":"@codemirror/state","kind":"import-statement","external":true},{"path":"@codemirror/view","kind":"import-statement","external":true},{"path":"@dxos/async","kind":"import-statement","external":true},{"path":"@dxos/invariant","kind":"import-statement","external":true},{"path":"react","kind":"import-statement","external":true},{"path":"@dxos/react-ui","kind":"import-statement","external":true},{"path":"@dxos/react-ui-editor","kind":"import-statement","external":true},{"path":"@dxos/ui-editor","kind":"import-statement","external":true},{"path":"@dxos/util","kind":"import-statement","external":true}],"exports":["ChatDialog","ChatEditor","references","translationKey","translations","useChatExtensions"],"entryPoint":"src/index.ts","inputs":{"src/components/ChatDialog/ChatDialog.tsx":{"bytesInOutput":4386},"src/components/ChatDialog/index.ts":{"bytesInOutput":0},"src/components/index.ts":{"bytesInOutput":0},"src/components/ChatEditor/references.ts":{"bytesInOutput":3687},"src/components/ChatEditor/index.ts":{"bytesInOutput":0},"src/components/ChatEditor/ChatEditor.tsx":{"bytesInOutput":1210},"src/index.ts":{"bytesInOutput":0},"src/translations.ts":{"bytesInOutput":124}},"bytes":9800}}}
|