@dxos/react-ui-chat 0.8.4-main.a4bbb77 → 0.8.4-main.abd8ff62ef

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 (51) hide show
  1. package/dist/lib/browser/index.mjs +232 -250
  2. package/dist/lib/browser/index.mjs.map +4 -4
  3. package/dist/lib/browser/meta.json +1 -1
  4. package/dist/lib/browser/translations.mjs +14 -0
  5. package/dist/lib/browser/translations.mjs.map +7 -0
  6. package/dist/lib/node-esm/index.mjs +232 -250
  7. package/dist/lib/node-esm/index.mjs.map +4 -4
  8. package/dist/lib/node-esm/meta.json +1 -1
  9. package/dist/lib/node-esm/translations.mjs +16 -0
  10. package/dist/lib/node-esm/translations.mjs.map +7 -0
  11. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts +17 -1
  12. package/dist/types/src/components/ChatDialog/ChatDialog.d.ts.map +1 -1
  13. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts +2 -3
  14. package/dist/types/src/components/ChatDialog/ChatDialog.stories.d.ts.map +1 -1
  15. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts +7 -8
  16. package/dist/types/src/components/ChatEditor/ChatEditor.d.ts.map +1 -1
  17. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts +3 -3
  18. package/dist/types/src/components/ChatEditor/ChatEditor.stories.d.ts.map +1 -1
  19. package/dist/types/src/components/ChatEditor/references.d.ts +4 -0
  20. package/dist/types/src/components/ChatEditor/references.d.ts.map +1 -1
  21. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts +40 -0
  22. package/dist/types/src/components/ChatStatus/ChatStatus.d.ts.map +1 -0
  23. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts +27 -0
  24. package/dist/types/src/components/ChatStatus/ChatStatus.stories.d.ts.map +1 -0
  25. package/dist/types/src/components/ChatStatus/format.d.ts +7 -0
  26. package/dist/types/src/components/ChatStatus/format.d.ts.map +1 -0
  27. package/dist/types/src/components/ChatStatus/format.test.d.ts +2 -0
  28. package/dist/types/src/components/ChatStatus/format.test.d.ts.map +1 -0
  29. package/dist/types/src/components/ChatStatus/index.d.ts +3 -0
  30. package/dist/types/src/components/ChatStatus/index.d.ts.map +1 -0
  31. package/dist/types/src/components/index.d.ts +1 -0
  32. package/dist/types/src/components/index.d.ts.map +1 -1
  33. package/dist/types/src/index.d.ts +0 -1
  34. package/dist/types/src/index.d.ts.map +1 -1
  35. package/dist/types/src/translations.d.ts +2 -2
  36. package/dist/types/src/translations.d.ts.map +1 -1
  37. package/dist/types/tsconfig.tsbuildinfo +1 -1
  38. package/package.json +46 -38
  39. package/src/components/ChatDialog/ChatDialog.stories.tsx +4 -5
  40. package/src/components/ChatDialog/ChatDialog.tsx +27 -17
  41. package/src/components/ChatEditor/ChatEditor.stories.tsx +19 -17
  42. package/src/components/ChatEditor/ChatEditor.tsx +33 -85
  43. package/src/components/ChatEditor/references.ts +18 -12
  44. package/src/components/ChatStatus/ChatStatus.stories.tsx +130 -0
  45. package/src/components/ChatStatus/ChatStatus.tsx +183 -0
  46. package/src/components/ChatStatus/format.test.ts +48 -0
  47. package/src/components/ChatStatus/format.ts +27 -0
  48. package/src/components/ChatStatus/index.ts +6 -0
  49. package/src/components/index.ts +1 -0
  50. package/src/index.ts +0 -1
  51. 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/react-ui-theme";
8
+ import { mx } from "@dxos/ui-theme";
10
9
  var preventDefault = (event) => event.preventDefault();
11
10
  var Endcap = ({ children }) => {
12
- var _effect = _useSignals();
13
- try {
14
- return /* @__PURE__ */ React.createElement("div", {
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: _open = false, expanded: expandedParam = false, onOpenChange, onExpandedChange, onEscape }) => {
23
- var _effect = _useSignals();
24
- try {
25
- const [size, setSize] = useState("min-content");
26
- const [open, setOpen] = useControlledState(_open, onOpenChange);
27
- const [expanded, setExpanded] = useControlledState(expandedParam, onExpandedChange);
28
- return /* @__PURE__ */ React.createElement(ChatDialogContextProvider, {
29
- open,
30
- setOpen,
31
- expanded,
32
- setExpanded,
33
- size,
34
- setSize
35
- }, /* @__PURE__ */ React.createElement(Dialog.Root, {
36
- modal: false,
37
- open,
38
- onOpenChange: setOpen
39
- }, /* @__PURE__ */ React.createElement("div", {
40
- role: "none",
41
- className: "dx-dialog__overlay bg-transparent pointer-events-none",
42
- "data-block-align": "end"
43
- }, /* @__PURE__ */ React.createElement(Dialog.Content, {
44
- inOverlayLayout: true,
45
- classNames: [
46
- "grid grid-rows-[var(--rail-action)_1fr_min-content] p-0 overflow-hidden",
47
- "box-content md:is-[35rem] md:max-is-none pointer-events-auto"
48
- ],
49
- onEscapeKeyDown: onEscape,
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
- var _effect = _useSignals();
59
- try {
60
- const { expanded, setExpanded } = useChatDialogContext(ChatDialogHeader.displayName);
61
- return /* @__PURE__ */ React.createElement("div", {
62
- className: mx("grid grid-cols-[var(--rail-action)_1fr_min-content] items-center overflow-hidden", classNames)
63
- }, /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(Dialog.Close, null, /* @__PURE__ */ React.createElement(Icon, {
64
- icon: "ph--x--regular"
65
- }))), /* @__PURE__ */ React.createElement(Dialog.Title, {
66
- classNames: "flex w-full justify-center text-sm text-subdued select-none cursor-pointer",
67
- onClick: () => setExpanded((expanded2) => !expanded2)
68
- }, title), /* @__PURE__ */ React.createElement(Endcap, null, /* @__PURE__ */ React.createElement(IconButton, {
69
- variant: "ghost",
70
- icon: "ph--caret-up--regular",
71
- iconOnly: true,
72
- classNames: mx("!p-1 [&>svg]:transition [&>svg]:duration-200", expanded && "[&>svg]:rotate-180"),
73
- label: expanded ? "Close" : "Open",
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 = "ChatDialog.Header";
65
+ ChatDialogHeader.displayName = CHAT_DIALOG_HEADER_NAME;
66
+ var CHAT_DIALOG_CONTENT_NAME = "ChatDialog.Content";
81
67
  var ChatDialogContent = ({ children, classNames }) => {
82
- var _effect = _useSignals();
83
- try {
84
- const { expanded, size, setSize } = useChatDialogContext(ChatDialogContent.displayName);
85
- useEffect(() => {
86
- setSize(expanded ? "min-content" : 0);
87
- }, [
88
- expanded
89
- ]);
90
- return /* @__PURE__ */ React.createElement("div", {
91
- 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),
92
- style: {
93
- ...sizeStyle(size, "vertical", true),
94
- maxBlockSize: "calc(100dvh - env(safe-area-inset-bottom) - env(safe-area-inset-top) - 14rem)"
95
- },
96
- ...resizeAttributes
97
- }, /* @__PURE__ */ React.createElement(ResizeHandle, {
98
- side: "block-start",
99
- iconPosition: "center",
100
- defaultSize: "min-content",
101
- fallbackSize: 0,
102
- minSize: 0,
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 = "ChatDialog.Content";
90
+ ChatDialogContent.displayName = CHAT_DIALOG_CONTENT_NAME;
91
+ var CHAT_DIALOG_FOOTER_NAME = "ChatDialog.Footer";
110
92
  var ChatDialogFooter = ({ children, classNames }) => {
111
- var _effect = _useSignals();
112
- try {
113
- return /* @__PURE__ */ React.createElement("div", {
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 = "ChatDialog.Footer";
97
+ ChatDialogFooter.displayName = CHAT_DIALOG_FOOTER_NAME;
121
98
  var ChatDialog = {
122
99
  Root: ChatDialogRoot,
123
100
  Header: ChatDialogHeader,
@@ -131,31 +108,23 @@ 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
- invariant(triggerCharacter.length === 1, void 0, {
150
- F: __dxlog_file,
151
- L: 50,
152
- S: void 0,
153
- A: [
154
- "triggerCharacter.length === 1",
155
- ""
156
- ]
157
- });
113
+ invariant(triggerCharacter.length === 1, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 14, S: void 0, A: ["triggerCharacter.length === 1", ""] });
158
114
  const decorationField = ViewPlugin.fromClass(class ReferenceView {
115
+ // TODO(burdon): Why?
116
+ _mutex = new Mutex();
117
+ decorations = Decoration.set([]);
118
+ constructor(view) {
119
+ queueMicrotask(async () => {
120
+ const guard = await this._mutex.acquire();
121
+ try {
122
+ this.decorations = await this._computeDecorations(view);
123
+ } finally {
124
+ guard.release();
125
+ }
126
+ });
127
+ }
159
128
  update(update) {
160
129
  if (update.docChanged) {
161
130
  queueMicrotask(async () => {
@@ -186,21 +155,9 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
186
155
  }
187
156
  return Decoration.set(decorations);
188
157
  }
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
158
  }, {
202
159
  decorations: (v) => v.decorations,
203
- provide: (plugin) => [
160
+ provide: () => [
204
161
  EditorView.atomicRanges.of((view) => view.plugin(decorationField)?.decorations ?? RangeSet.empty)
205
162
  ]
206
163
  });
@@ -215,7 +172,7 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
215
172
  }
216
173
  }),
217
174
  autocompletion({
218
- tooltipClass: () => "shadow rounded",
175
+ tooltipClass: () => "shadow rounded-sm",
219
176
  activateOnTyping: true,
220
177
  aboveCursor: true,
221
178
  closeOnBlur: !debug,
@@ -244,137 +201,162 @@ var references = ({ provider, triggerCharacter = "@", debug = false }) => {
244
201
  ];
245
202
  };
246
203
  var ReferenceWidget = class extends WidgetType {
247
- toDOM() {
248
- const span = document.createElement("span");
249
- span.textContent = `@ ${this.data.label}`;
250
- span.className = "cm-reference-pill";
251
- return span;
252
- }
253
- eq(other) {
254
- return other.data.uri === this.data.uri;
204
+ data;
205
+ constructor(data) {
206
+ super(), this.data = data;
255
207
  }
256
208
  ignoreEvent() {
257
209
  return true;
258
210
  }
259
- constructor(data) {
260
- super(), _define_property(this, "data", void 0), this.data = data;
211
+ eq(other) {
212
+ return this.data.uri === other.data.uri;
213
+ }
214
+ toDOM() {
215
+ const span = document.createElement("span");
216
+ span.textContent = `@${this.data.label}`;
217
+ span.className = "cm-reference-pill";
218
+ return span;
261
219
  }
262
220
  };
263
221
 
264
222
  // src/components/ChatEditor/ChatEditor.tsx
265
- import { useSignals as _useSignals2 } from "@preact-signals/safe-react/tracking";
266
- import { keymap as keymap2 } from "@codemirror/view";
267
- import { useFocusFinders } from "@fluentui/react-tabster";
268
- import React2, { forwardRef, useImperativeHandle } from "react";
223
+ import React2, { forwardRef, useMemo } from "react";
269
224
  import { useThemeContext } from "@dxos/react-ui";
270
- import { autocomplete, createBasicExtensions, createThemeExtensions, useTextEditor } from "@dxos/react-ui-editor";
271
- import { mx as mx2 } from "@dxos/react-ui-theme";
225
+ import { Editor } from "@dxos/react-ui-editor";
226
+ import { createBasicExtensions, createThemeExtensions, submit, xmlFormatting } from "@dxos/ui-editor";
272
227
  import { isTruthy } from "@dxos/util";
273
- var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, extensions, references: references2, autoFocus, lineWrapping = false, placeholder, onSubmit, onSuggest, onCancel }, forwardRef2) => {
274
- var _effect = _useSignals2();
275
- try {
276
- const { themeMode } = useThemeContext();
277
- const { findNextFocusable, findPrevFocusable } = useFocusFinders();
278
- const { parentRef, view } = useTextEditor(() => ({
279
- debug: true,
280
- autoFocus,
281
- extensions: [
282
- createThemeExtensions({
283
- themeMode
284
- }),
285
- createBasicExtensions({
286
- bracketMatching: false,
287
- lineWrapping,
288
- placeholder
289
- }),
290
- createBasicExtensions({
291
- bracketMatching: false,
292
- lineWrapping,
293
- placeholder
294
- }),
295
- autocomplete({
296
- onSubmit,
297
- onSuggest,
298
- onCancel
299
- }),
300
- references2 ? references({
301
- provider: references2.provider
302
- }) : [],
303
- // TODO(burdon): Standardize.
304
- keymap2.of([
305
- {
306
- key: "Tab",
307
- preventDefault: true,
308
- run: (view2) => {
309
- findNextFocusable(view2.dom)?.focus();
310
- return true;
311
- }
312
- },
313
- {
314
- key: "Shift-Tab",
315
- preventDefault: true,
316
- run: (view2) => {
317
- findPrevFocusable(view2.dom)?.focus();
318
- return true;
319
- }
320
- }
321
- ]),
322
- extensions
323
- ].filter(isTruthy)
324
- }), [
325
- themeMode,
326
- extensions,
327
- onSubmit,
328
- onSuggest,
329
- onCancel
330
- ]);
331
- useImperativeHandle(forwardRef2, () => {
332
- return {
333
- focus: () => {
334
- view?.focus();
335
- },
336
- getText: () => view?.state.doc.toString() ?? "",
337
- setText: (text) => {
338
- view?.dispatch({
339
- changes: {
340
- from: 0,
341
- to: view.state.doc.length,
342
- insert: text
343
- },
344
- selection: {
345
- anchor: text.length,
346
- head: text.length
347
- }
348
- });
349
- }
350
- };
351
- }, [
352
- view,
228
+ var useChatExtensions = ({ extensions, lineWrapping = false, placeholder, onSubmit }) => {
229
+ const { themeMode } = useThemeContext();
230
+ return useMemo(() => [
231
+ createThemeExtensions({
232
+ themeMode
233
+ }),
234
+ createBasicExtensions({
235
+ bracketMatching: false,
236
+ lineWrapping,
237
+ placeholder
238
+ }),
239
+ xmlFormatting(),
240
+ submit({
353
241
  onSubmit
354
- ]);
355
- return /* @__PURE__ */ React2.createElement("div", {
356
- ref: parentRef,
357
- className: mx2("is-full", classNames)
358
- });
359
- } finally {
360
- _effect.f();
361
- }
242
+ }),
243
+ extensions
244
+ ].filter(isTruthy), [
245
+ themeMode,
246
+ extensions,
247
+ onSubmit
248
+ ]);
249
+ };
250
+ var ChatEditor = /* @__PURE__ */ forwardRef(({ classNames, autoFocus, extensions: extensionsProp, lineWrapping = false, placeholder, onSubmit }, forwardRef3) => {
251
+ const extensions = useChatExtensions({
252
+ extensions: extensionsProp,
253
+ lineWrapping,
254
+ placeholder,
255
+ onSubmit
256
+ });
257
+ return /* @__PURE__ */ React2.createElement(Editor.Root, {
258
+ ref: forwardRef3
259
+ }, /* @__PURE__ */ React2.createElement(Editor.View, {
260
+ classNames,
261
+ autoFocus,
262
+ extensions
263
+ }));
362
264
  });
363
265
 
364
- // src/translations.ts
365
- var translationKey = "react-ui-chat";
366
- var translations = [
367
- {
368
- "en-US": {
369
- [translationKey]: {}
266
+ // src/components/ChatStatus/ChatStatus.tsx
267
+ import { createContext as createContext2 } from "@radix-ui/react-context";
268
+ import React3, { forwardRef as forwardRef2, useEffect as useEffect2, useImperativeHandle, useState as useState2 } from "react";
269
+ import { mx as mx2 } from "@dxos/ui-theme";
270
+
271
+ // src/components/ChatStatus/format.ts
272
+ var SECOND = 1e3;
273
+ var MINUTE = 60 * SECOND;
274
+ var HOUR = 60 * MINUTE;
275
+ var formatElapsed = (ms) => {
276
+ const safe = Math.max(0, ms);
277
+ if (safe < MINUTE) {
278
+ return `${Math.floor(safe / SECOND)}s`;
279
+ }
280
+ if (safe < HOUR) {
281
+ const m2 = Math.floor(safe / MINUTE);
282
+ const s = Math.floor(safe % MINUTE / SECOND);
283
+ return `${m2}m ${s}s`;
284
+ }
285
+ const h = Math.floor(safe / HOUR);
286
+ const m = Math.floor(safe % HOUR / MINUTE);
287
+ return `${h}h ${m}m`;
288
+ };
289
+
290
+ // src/components/ChatStatus/ChatStatus.tsx
291
+ var TICK_MS = 1e3;
292
+ var [ChatStatusProvider, useChatStatusContext] = createContext2("ChatStatus");
293
+ var Root = /* @__PURE__ */ forwardRef2(({ classNames, children, defaultRunning = true }, forwardedRef) => {
294
+ const [elapsed, setElapsed] = useState2(0);
295
+ const [running, setRunning] = useState2(defaultRunning);
296
+ useEffect2(() => {
297
+ if (!running) {
298
+ return;
370
299
  }
300
+ const startedAt = Date.now() - elapsed * TICK_MS;
301
+ let timeout;
302
+ const tick = () => {
303
+ setElapsed(Math.floor((Date.now() - startedAt) / TICK_MS));
304
+ timeout = setTimeout(tick, TICK_MS - Date.now() % TICK_MS);
305
+ };
306
+ timeout = setTimeout(tick, TICK_MS - Date.now() % TICK_MS);
307
+ return () => clearTimeout(timeout);
308
+ }, [
309
+ running
310
+ ]);
311
+ useImperativeHandle(forwardedRef, () => ({
312
+ start: () => setRunning(true),
313
+ stop: () => setRunning(false)
314
+ }), []);
315
+ return /* @__PURE__ */ React3.createElement(ChatStatusProvider, {
316
+ elapsed,
317
+ running
318
+ }, /* @__PURE__ */ React3.createElement("span", {
319
+ className: mx2("inline-flex items-center gap-2 text-description font-mono tabular-nums", classNames)
320
+ }, children));
321
+ });
322
+ Root.displayName = "ChatChatStatus.Root";
323
+ var Icon2 = ({ classNames, children }) => {
324
+ if (children !== void 0) {
325
+ return /* @__PURE__ */ React3.createElement(React3.Fragment, null, children);
371
326
  }
372
- ];
327
+ return /* @__PURE__ */ React3.createElement("span", {
328
+ "aria-hidden": "true",
329
+ className: mx2("inline-block size-2 rounded-full bg-current animate-halo-pulse", classNames)
330
+ });
331
+ };
332
+ var Stopwatch = ({ classNames, offset = 0 }) => {
333
+ const { elapsed } = useChatStatusContext("ChatChatStatus.Stopwatch");
334
+ return /* @__PURE__ */ React3.createElement("span", {
335
+ "aria-live": "off",
336
+ className: mx2(classNames)
337
+ }, formatElapsed((elapsed + offset) * 1e3));
338
+ };
339
+ var Separator = ({ classNames }) => /* @__PURE__ */ React3.createElement("span", {
340
+ "aria-hidden": "true",
341
+ className: mx2("opacity-50", classNames)
342
+ }, "\xB7");
343
+ var Text = ({ classNames, children }) => /* @__PURE__ */ React3.createElement("span", {
344
+ className: mx2(classNames)
345
+ }, children);
346
+ var ChatStatus = {
347
+ Root,
348
+ Icon: Icon2,
349
+ Stopwatch,
350
+ Separator,
351
+ Text
352
+ };
373
353
  export {
374
354
  ChatDialog,
375
355
  ChatEditor,
356
+ ChatStatus,
357
+ formatElapsed,
376
358
  references,
377
- translationKey,
378
- translations
359
+ useChatExtensions,
360
+ useChatStatusContext
379
361
  };
380
362
  //# sourceMappingURL=index.mjs.map