@dxos/react-ui-chat 0.8.4-main.ae835ea → 0.8.4-main.bc2380dfbc

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 (52) hide show
  1. package/LICENSE +102 -5
  2. package/dist/lib/browser/index.mjs +214 -217
  3. package/dist/lib/browser/index.mjs.map +4 -4
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/translations.mjs +14 -0
  6. package/dist/lib/browser/translations.mjs.map +7 -0
  7. package/dist/lib/node-esm/index.mjs +214 -217
  8. package/dist/lib/node-esm/index.mjs.map +4 -4
  9. package/dist/lib/node-esm/meta.json +1 -1
  10. package/dist/lib/node-esm/translations.mjs +16 -0
  11. package/dist/lib/node-esm/translations.mjs.map +7 -0
  12. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts +17 -1
  13. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
  14. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +2 -2
  15. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
  16. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -8
  17. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
  18. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +3 -3
  19. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
  20. package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
  21. package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
  22. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts +40 -0
  23. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts.map +1 -0
  24. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts +27 -0
  25. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts.map +1 -0
  26. package/dist/types/src/components/ChatStatus/format.d.ts +7 -0
  27. package/dist/types/src/components/ChatStatus/format.d.ts.map +1 -0
  28. package/dist/types/src/components/ChatStatus/format.test.d.ts +2 -0
  29. package/dist/types/src/components/ChatStatus/format.test.d.ts.map +1 -0
  30. package/dist/types/src/components/ChatStatus/index.d.ts +3 -0
  31. package/dist/types/src/components/ChatStatus/index.d.ts.map +1 -0
  32. package/dist/types/src/components/index.d.ts +1 -0
  33. package/dist/types/src/components/index.d.ts.map +1 -1
  34. package/dist/types/src/index.d.ts +0 -1
  35. package/dist/types/src/index.d.ts.map +1 -1
  36. package/dist/types/src/translations.d.ts +2 -2
  37. package/dist/types/src/translations.d.ts.map +1 -1
  38. package/dist/types/tsconfig.tsbuildinfo +1 -1
  39. package/package.json +48 -40
  40. package/src/components/ChatDialog/ChatDialog.stories.tsx +3 -3
  41. package/src/components/ChatDialog/ChatDialog.tsx +28 -18
  42. package/src/components/ChatEditor/ChatEditor.stories.tsx +19 -17
  43. package/src/components/ChatEditor/ChatEditor.tsx +33 -80
  44. package/src/components/ChatEditor/references.ts +18 -12
  45. package/src/components/ChatStatus/ChatStatus.stories.tsx +130 -0
  46. package/src/components/ChatStatus/ChatStatus.tsx +183 -0
  47. package/src/components/ChatStatus/format.test.ts +48 -0
  48. package/src/components/ChatStatus/format.ts +27 -0
  49. package/src/components/ChatStatus/index.ts +6 -0
  50. package/src/components/index.ts +1 -0
  51. package/src/index.ts +0 -1
  52. package/src/translations.ts +1 -1
package/LICENSE CHANGED
@@ -1,8 +1,105 @@
1
- MIT License
2
- Copyright (c) 2022 DXOS
1
+ # Functional Source License, Version 1.1, ALv2 Future License
3
2
 
4
- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
3
+ ## Abbreviation
5
4
 
6
- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
5
+ FSL-1.1-Apache-2.0
7
6
 
8
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
7
+ ## Notice
8
+
9
+ Copyright 2026 DXOS
10
+
11
+ ## Terms and Conditions
12
+
13
+ ### Licensor ("We")
14
+
15
+ The party offering the Software under these Terms and Conditions.
16
+
17
+ ### The Software
18
+
19
+ The "Software" is each version of the software that we make available under
20
+ these Terms and Conditions, as indicated by our inclusion of these Terms and
21
+ Conditions with the Software.
22
+
23
+ ### License Grant
24
+
25
+ Subject to your compliance with this License Grant and the Patents,
26
+ Redistribution and Trademark clauses below, we hereby grant you the right to
27
+ use, copy, modify, create derivative works, publicly perform, publicly display
28
+ and redistribute the Software for any Permitted Purpose identified below.
29
+
30
+ ### Permitted Purpose
31
+
32
+ A Permitted Purpose is any purpose other than a Competing Use. A Competing Use
33
+ means making the Software available to others in a commercial product or
34
+ service that:
35
+
36
+ 1. substitutes for the Software;
37
+
38
+ 2. substitutes for any other product or service we offer using the Software
39
+ that exists as of the date we make the Software available; or
40
+
41
+ 3. offers the same or substantially similar functionality as the Software.
42
+
43
+ Permitted Purposes specifically include using the Software:
44
+
45
+ 1. for your internal use and access;
46
+
47
+ 2. for non-commercial education;
48
+
49
+ 3. for non-commercial research; and
50
+
51
+ 4. in connection with professional services that you provide to a licensee
52
+ using the Software in accordance with these Terms and Conditions.
53
+
54
+ ### Patents
55
+
56
+ To the extent your use for a Permitted Purpose would necessarily infringe our
57
+ patents, the license grant above includes a license under our patents. If you
58
+ make a claim against any party that the Software infringes or contributes to
59
+ the infringement of any patent, then your patent license to the Software ends
60
+ immediately.
61
+
62
+ ### Redistribution
63
+
64
+ The Terms and Conditions apply to all copies, modifications and derivatives of
65
+ the Software.
66
+
67
+ If you redistribute any copies, modifications or derivatives of the Software,
68
+ you must include a copy of or a link to these Terms and Conditions and not
69
+ remove any copyright notices provided in or with the Software.
70
+
71
+ ### Disclaimer
72
+
73
+ THE SOFTWARE IS PROVIDED "AS IS" AND WITHOUT WARRANTIES OF ANY KIND, EXPRESS OR
74
+ IMPLIED, INCLUDING WITHOUT LIMITATION WARRANTIES OF FITNESS FOR A PARTICULAR
75
+ PURPOSE, MERCHANTABILITY, TITLE OR NON-INFRINGEMENT.
76
+
77
+ IN NO EVENT WILL WE HAVE ANY LIABILITY TO YOU ARISING OUT OF OR RELATED TO THE
78
+ SOFTWARE, INCLUDING INDIRECT, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES,
79
+ EVEN IF WE HAVE BEEN INFORMED OF THEIR POSSIBILITY IN ADVANCE.
80
+
81
+ ### Trademarks
82
+
83
+ Except for displaying the License Details and identifying us as the origin of
84
+ the Software, you have no right under these Terms and Conditions to use our
85
+ trademarks, trade names, service marks or product names.
86
+
87
+ ## Grant of Future License
88
+
89
+ We hereby irrevocably grant you an additional license to use the Software under
90
+ the Apache License, Version 2.0 that is effective on the second anniversary of
91
+ the date we make the Software available. On or after that date, you may use the
92
+ Software under the Apache License, Version 2.0, in which case the following
93
+ will apply:
94
+
95
+ Licensed under the Apache License, Version 2.0 (the "License"); you may not use
96
+ this file except in compliance with the License.
97
+
98
+ You may obtain a copy of the License at
99
+
100
+ http://www.apache.org/licenses/LICENSE-2.0
101
+
102
+ Unless required by applicable law or agreed to in writing, software distributed
103
+ under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
104
+ CONDITIONS OF ANY KIND, either express or implied. See the License for the
105
+ specific language governing permissions and limitations under the License.
@@ -1,121 +1,97 @@
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
5
  import { ResizeHandle, resizeAttributes, sizeStyle } from "@dxos/react-ui-dnd";
7
- import { mx } from "@dxos/react-ui-theme";
6
+ import { mx } from "@dxos/ui-theme";
8
7
  var preventDefault = (event) => event.preventDefault();
9
8
  var Endcap = ({ children }) => {
10
- var _effect = _useSignals();
11
- try {
12
- return /* @__PURE__ */ React.createElement("div", {
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: _open = false, expanded: expandedParam = false, onOpenChange, onExpandedChange, onEscape }) => {
21
- var _effect = _useSignals();
22
- try {
23
- const [size, setSize] = useState("min-content");
24
- const [open, setOpen] = useControlledState(_open, onOpenChange);
25
- const [expanded, setExpanded] = useControlledState(expandedParam, onExpandedChange);
26
- return /* @__PURE__ */ React.createElement(ChatDialogContextProvider, {
27
- open,
28
- setOpen,
29
- expanded,
30
- setExpanded,
31
- size,
32
- setSize
33
- }, /* @__PURE__ */ React.createElement(Dialog.Root, {
34
- modal: false,
35
- open,
36
- onOpenChange: setOpen
37
- }, /* @__PURE__ */ React.createElement("div", {
38
- role: "none",
39
- className: "dx-dialog__overlay bg-transparent pointer-events-none",
40
- "data-block-align": "end"
41
- }, /* @__PURE__ */ React.createElement(Dialog.Content, {
42
- inOverlayLayout: true,
43
- classNames: [
44
- "grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden",
45
- "box-content md:is-[35rem] md:max-is-none pointer-events-auto"
46
- ],
47
- onEscapeKeyDown: onEscape,
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
+ className: "dx-dialog__overlay bg-transparent pointer-events-none",
31
+ "data-block-align": "end"
32
+ }, /* @__PURE__ */ React.createElement(Dialog.Content, {
33
+ size: "md",
34
+ inOverlayLayout: true,
35
+ classNames: [
36
+ "grid grid-rows-[var(--dx-rail-action)_1fr_min-content] p-0 overflow-hidden box-content pointer-events-auto"
37
+ ],
38
+ onEscapeKeyDown: onEscape,
39
+ onInteractOutside: preventDefault
40
+ }, children))));
53
41
  };
54
42
  ChatDialogRoot.displayName = "ChatDialog.Root";
43
+ var CHAT_DIALOG_HEADER_NAME = "ChatDialog.Header";
55
44
  var ChatDialogHeader = ({ classNames, title }) => {
56
- var _effect = _useSignals();
57
- try {
58
- const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);
59
- return /* @__PURE__ */ React.createElement("div", {
60
- className: mx("grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden", classNames)
61
- }, /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(Dialog.Close, null, /* @__PURE__ */ React.createElement(Icon, {
62
- icon: "ph--x--regular"
63
- }))), /* @__PURE__ */ React.createElement(Dialog.Title, {
64
- classNames: "flex w-full justify-center text-sm text-subdued select-none cursor-pointer",
65
- onClick: () => setExpanded((expanded2) => !expanded2)
66
- }, title), /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(IconButton, {
67
- variant: "ghost",
68
- icon: "ph--caret-up--regular",
69
- iconOnly: true,
70
- classNames: mx("!p-1 [&>svg]:transition [&>svg]:duration-200", expanded && "[&>svg]:rotate-180"),
71
- label: expanded ? "Close" : "Open",
72
- onClick: () => setExpanded((expanded2) => !expanded2)
73
- })));
74
- } finally {
75
- _effect.f();
76
- }
45
+ const { expanded, setExpanded } = useChatDialogContext(CHAT_DIALOG_HEADER_NAME);
46
+ return /* @__PURE__ */ React.createElement("div", {
47
+ className: mx("grid grid-cols-[var(--dx-rail-action)_1fr_min-content] items-center overflow-hidden", classNames)
48
+ }, /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(Dialog.Close, null, /* @__PURE__ */ React.createElement(Icon, {
49
+ icon: "ph--x--regular"
50
+ }))), /* @__PURE__ */ React.createElement(Dialog.Title, {
51
+ classNames: "flex w-full justify-center text-sm text-subdued select-none cursor-pointer",
52
+ onClick: () => setExpanded((expanded2) => !expanded2)
53
+ }, title), /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(IconButton, {
54
+ variant: "ghost",
55
+ icon: "ph--caret-up--regular",
56
+ iconOnly: true,
57
+ classNames: mx("p-1! [&>svg]:transition [&>svg]:duration-200", expanded && "[&>svg]:rotate-180"),
58
+ label: expanded ? "Close" : "Open",
59
+ onClick: () => setExpanded((expanded2) => !expanded2)
60
+ })));
77
61
  };
78
- ChatDialogHeader.displayName = "ChatDialog.Header";
62
+ ChatDialogHeader.displayName = CHAT_DIALOG_HEADER_NAME;
63
+ var CHAT_DIALOG_CONTENT_NAME = "ChatDialog.Content";
79
64
  var ChatDialogContent = ({ children, classNames }) => {
80
- var _effect = _useSignals();
81
- try {
82
- const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);
83
- useEffect(() => {
84
- setSize(expanded ? "min-content" : 0);
85
- }, [
86
- expanded
87
- ]);
88
- return /* @__PURE__ */ React.createElement("div", {
89
- className: mx("flex flex-col overflow-y-auto border-t border-b border-subduedSeparator", 'transition-[block-size] ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200', classNames),
90
- style: {
91
- ...sizeStyle(size, "vertical", true),
92
- maxBlockSize: "calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)"
93
- },
94
- ...resizeAttributes
95
- }, /* @__PURE__ */ React.createElement(ResizeHandle, {
96
- side: "block-start",
97
- iconPosition: "center",
98
- defaultSize: "min-content",
99
- fallbackSize: 0,
100
- minSize: 0,
101
- onSizeChange: setSize
102
- }), children);
103
- } finally {
104
- _effect.f();
105
- }
65
+ const { expanded, size, setSize } = useChatDialogContext(CHAT_DIALOG_CONTENT_NAME);
66
+ useEffect(() => {
67
+ setSize(expanded ? "min-content" : 0);
68
+ }, [
69
+ expanded
70
+ ]);
71
+ return /* @__PURE__ */ React.createElement("div", {
72
+ className: mx("border-t border-b border-subdued-separator", 'transition ease-in-out duration-0 [&:not([data-dx-resizing="true"])]:duration-200', classNames),
73
+ style: {
74
+ ...sizeStyle(size, "vertical", true),
75
+ maxBlockSize: "calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)"
76
+ },
77
+ ...resizeAttributes
78
+ }, /* @__PURE__ */ React.createElement(ResizeHandle, {
79
+ side: "block-start",
80
+ iconPosition: "center",
81
+ defaultSize: "min-content",
82
+ fallbackSize: 0,
83
+ minSize: 0,
84
+ onSizeChange: setSize
85
+ }), children);
106
86
  };
107
- ChatDialogContent.displayName = "ChatDialog.Content";
87
+ ChatDialogContent.displayName = CHAT_DIALOG_CONTENT_NAME;
88
+ var CHAT_DIALOG_FOOTER_NAME = "ChatDialog.Footer";
108
89
  var ChatDialogFooter = ({ children, classNames }) => {
109
- var _effect = _useSignals();
110
- try {
111
- return /* @__PURE__ */ React.createElement("div", {
112
- className: mx(classNames)
113
- }, children);
114
- } finally {
115
- _effect.f();
116
- }
90
+ return /* @__PURE__ */ React.createElement("div", {
91
+ className: mx(classNames)
92
+ }, children);
117
93
  };
118
- ChatDialogFooter.displayName = "ChatDialog.Footer";
94
+ ChatDialogFooter.displayName = CHAT_DIALOG_FOOTER_NAME;
119
95
  var ChatDialog = {
120
96
  Root: ChatDialogRoot,
121
97
  Header: ChatDialogHeader,
@@ -131,15 +107,7 @@ import { Mutex } from "@dxos/async";
131
107
  import { invariant } from "@dxos/invariant";
132
108
  var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-chat/src/components/ChatEditor/references.ts";
133
109
  var references = ({ provider, triggerCharacter = "@", debug = false }) => {
134
- invariant(triggerCharacter.length === 1, void 0, {
135
- F: __dxlog_file,
136
- L: 50,
137
- S: void 0,
138
- A: [
139
- "triggerCharacter.length === 1",
140
- ""
141
- ]
142
- });
110
+ invariant(triggerCharacter.length === 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 14, S: void 0, A: ["triggerCharacter.length === 1", ""] });
143
111
  const decorationField = ViewPlugin.fromClass(class ReferenceView {
144
112
  // TODO(burdon): Why?
145
113
  _mutex = new Mutex();
@@ -186,7 +154,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
186
154
  }
187
155
  }, {
188
156
  decorations: (v) => v.decorations,
189
- provide: (plugin) => [
157
+ provide: () => [
190
158
  EditorView.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
191
159
  ]
192
160
  });
@@ -201,7 +169,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
201
169
  }
202
170
  }),
203
171
  autocompletion({
204
- tooltipClass: () => "shadow rounded",
172
+ tooltipClass: () => "shadow rounded-sm",
205
173
  activateOnTyping: true,
206
174
  aboveCursor: true,
207
175
  closeOnBlur: !debug,
@@ -234,129 +202,158 @@ var ReferenceWidget = class extends WidgetType {
234
202
  constructor(data) {
235
203
  super(), this.data = data;
236
204
  }
205
+ ignoreEvent() {
206
+ return true;
207
+ }
208
+ eq(other) {
209
+ return this.data.uri === other.data.uri;
210
+ }
237
211
  toDOM() {
238
212
  const span = document.createElement("span");
239
- span.textContent = `@ ${this.data.label}`;
213
+ span.textContent = `@${this.data.label}`;
240
214
  span.className = "cm-reference-pill";
241
215
  return span;
242
216
  }
243
- eq(other) {
244
- return other.data.uri === this.data.uri;
245
- }
246
- ignoreEvent() {
247
- return true;
248
- }
249
217
  };
250
218
 
251
219
  // src/components/ChatEditor/ChatEditor.tsx
252
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
253
- import { keymap as keymap2 } from "@codemirror/view";
254
- import { useFocusFinders } from "@fluentui/react-tabster";
255
- import React2, { forwardRef, useImperativeHandle } from "react";
220
+ import React2, { forwardRef, useMemo } from "react";
256
221
  import { useThemeContext } from "@dxos/react-ui";
257
- import { autocomplete, createBasicExtensions, createThemeExtensions, useTextEditor } from "@dxos/react-ui-editor";
258
- import { mx as mx2 } from "@dxos/react-ui-theme";
222
+ import { Editor } from "@dxos/react-ui-editor";
223
+ import { createBasicExtensions, createThemeExtensions, submit, xmlFormatting } from "@dxos/ui-editor";
259
224
  import { isTruthy } from "@dxos/util";
260
- var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, extensions, references: references2, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel }, forwardRef2) => {
261
- var _effect = _useSignals2();
262
- try {
263
- const { themeMode } = useThemeContext();
264
- const { findNextFocusable, findPrevFocusable } = useFocusFinders();
265
- const { parentRef, view } = useTextEditor(() => ({
266
- debug: true,
267
- autoFocus,
268
- extensions: [
269
- createThemeExtensions({
270
- themeMode
271
- }),
272
- createBasicExtensions({
273
- bracketMatching: false,
274
- lineWrapping,
275
- placeholder
276
- }),
277
- autocomplete({
278
- onSubmit,
279
- onSuggest,
280
- onCancel
281
- }),
282
- references2 ? references({
283
- provider: references2.provider
284
- }) : [],
285
- // TODO(burdon): Standardize.
286
- keymap2.of([
287
- {
288
- key: "Tab",
289
- preventDefault: true,
290
- run: (view2) => {
291
- findNextFocusable(view2.dom)?.focus();
292
- return true;
293
- }
294
- },
295
- {
296
- key: "Shift-Tab",
297
- preventDefault: true,
298
- run: (view2) => {
299
- findPrevFocusable(view2.dom)?.focus();
300
- return true;
301
- }
302
- }
303
- ]),
304
- extensions
305
- ].filter(isTruthy)
306
- }), [
307
- themeMode,
308
- extensions,
309
- onSubmit,
310
- onSuggest,
311
- onCancel
312
- ]);
313
- useImperativeHandle(forwardRef2, () => {
314
- return {
315
- focus: () => {
316
- view?.focus();
317
- },
318
- getText: () => view?.state.doc.toString() ?? "",
319
- setText: (text) => {
320
- view?.dispatch({
321
- changes: {
322
- from: 0,
323
- to: view.state.doc.length,
324
- insert: text
325
- },
326
- selection: {
327
- anchor: text.length,
328
- head: text.length
329
- }
330
- });
331
- }
332
- };
333
- }, [
334
- view,
225
+ var useChatExtensions = ({ extensions, lineWrapping = false, placeholder, onSubmit }) => {
226
+ const { themeMode } = useThemeContext();
227
+ return useMemo(() => [
228
+ createThemeExtensions({
229
+ themeMode
230
+ }),
231
+ createBasicExtensions({
232
+ bracketMatching: false,
233
+ lineWrapping,
234
+ placeholder
235
+ }),
236
+ xmlFormatting(),
237
+ submit({
335
238
  onSubmit
336
- ]);
337
- return /* @__PURE__ */ React2.createElement("div", {
338
- ref: parentRef,
339
- className: mx2("is-full", classNames)
340
- });
341
- } finally {
342
- _effect.f();
343
- }
239
+ }),
240
+ extensions
241
+ ].filter(isTruthy), [
242
+ themeMode,
243
+ extensions,
244
+ onSubmit
245
+ ]);
246
+ };
247
+ var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, autoFocus, extensions: extensionsProp, lineWrapping = false, placeholder, onSubmit }, forwardRef3) => {
248
+ const extensions = useChatExtensions({
249
+ extensions: extensionsProp,
250
+ lineWrapping,
251
+ placeholder,
252
+ onSubmit
253
+ });
254
+ return /* @__PURE__ */ React2.createElement(Editor.Root, {
255
+ ref: forwardRef3
256
+ }, /* @__PURE__ */ React2.createElement(Editor.View, {
257
+ classNames,
258
+ autoFocus,
259
+ extensions
260
+ }));
344
261
  });
345
262
 
346
- // src/translations.ts
347
- var translationKey = "react-ui-chat";
348
- var translations = [
349
- {
350
- "en-US": {
351
- [translationKey]: {}
263
+ // src/components/ChatStatus/ChatStatus.tsx
264
+ import { createContext as createContext2 } from "@radix-ui/react-context";
265
+ import React3, { forwardRef as forwardRef2, useEffect as useEffect2, useImperativeHandle, useState as useState2 } from "react";
266
+ import { mx as mx2 } from "@dxos/ui-theme";
267
+
268
+ // src/components/ChatStatus/format.ts
269
+ var SECOND = 1e3;
270
+ var MINUTE = 60 * SECOND;
271
+ var HOUR = 60 * MINUTE;
272
+ var formatElapsed = (ms) => {
273
+ const safe = Math.max(0, ms);
274
+ if (safe < MINUTE) {
275
+ return `${Math.floor(safe / SECOND)}s`;
276
+ }
277
+ if (safe < HOUR) {
278
+ const m2 = Math.floor(safe / MINUTE);
279
+ const s = Math.floor(safe % MINUTE / SECOND);
280
+ return `${m2}m ${s}s`;
281
+ }
282
+ const h = Math.floor(safe / HOUR);
283
+ const m = Math.floor(safe % HOUR / MINUTE);
284
+ return `${h}h ${m}m`;
285
+ };
286
+
287
+ // src/components/ChatStatus/ChatStatus.tsx
288
+ var TICK_MS = 1e3;
289
+ var [ChatStatusProvider, useChatStatusContext] = createContext2("ChatStatus");
290
+ var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, defaultRunning = true }, forwardedRef) => {
291
+ const [elapsed, setElapsed] = useState2(0);
292
+ const [running, setRunning] = useState2(defaultRunning);
293
+ useEffect2(() => {
294
+ if (!running) {
295
+ return;
352
296
  }
297
+ const startedAt = Date.now() - elapsed * TICK_MS;
298
+ let timeout;
299
+ const tick = () => {
300
+ setElapsed(Math.floor((Date.now() - startedAt) / TICK_MS));
301
+ timeout = setTimeout(tick, TICK_MS - Date.now() % TICK_MS);
302
+ };
303
+ timeout = setTimeout(tick, TICK_MS - Date.now() % TICK_MS);
304
+ return () => clearTimeout(timeout);
305
+ }, [
306
+ running
307
+ ]);
308
+ useImperativeHandle(forwardedRef, () => ({
309
+ start: () => setRunning(true),
310
+ stop: () => setRunning(false)
311
+ }), []);
312
+ return /* @__PURE__ */ React3.createElement(ChatStatusProvider, {
313
+ elapsed,
314
+ running
315
+ }, /* @__PURE__ */ React3.createElement("span", {
316
+ className: mx2("inline-flex items-center gap-2 text-description font-mono tabular-nums", classNames)
317
+ }, children));
318
+ });
319
+ Root.displayName = "ChatChatStatus.Root";
320
+ var Icon2 = ({ classNames, children }) => {
321
+ if (children !== void 0) {
322
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, children);
353
323
  }
354
- ];
324
+ return /* @__PURE__ */ React3.createElement("span", {
325
+ "aria-hidden": "true",
326
+ className: mx2("inline-block size-2 rounded-full bg-current animate-halo-pulse", classNames)
327
+ });
328
+ };
329
+ var Stopwatch = ({ classNames, offset = 0 }) => {
330
+ const { elapsed } = useChatStatusContext("ChatChatStatus.Stopwatch");
331
+ return /* @__PURE__ */ React3.createElement("span", {
332
+ "aria-live": "off",
333
+ className: mx2(classNames)
334
+ }, formatElapsed((elapsed + offset) * 1e3));
335
+ };
336
+ var Separator = ({ classNames }) => /* @__PURE__ */ React3.createElement("span", {
337
+ "aria-hidden": "true",
338
+ className: mx2("opacity-50", classNames)
339
+ }, "\xB7");
340
+ var Text = ({ classNames, children }) => /* @__PURE__ */ React3.createElement("span", {
341
+ className: mx2(classNames)
342
+ }, children);
343
+ var ChatStatus = {
344
+ Root,
345
+ Icon: Icon2,
346
+ Stopwatch,
347
+ Separator,
348
+ Text
349
+ };
355
350
  export {
356
351
  ChatDialog,
357
352
  ChatEditor,
353
+ ChatStatus,
354
+ formatElapsed,
358
355
  references,
359
- translationKey,
360
- translations
356
+ useChatExtensions,
357
+ useChatStatusContext
361
358
  };
362
359
  //# sourceMappingURL=index.mjs.map