@vjdesigns/vjdesigns-ui 2.0.0 → 2.2.0

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 (90) hide show
  1. package/README.md +781 -724
  2. package/dist/ai/llms-full.txt +555 -480
  3. package/dist/ai/llms.txt +1 -0
  4. package/dist/ai/registry.json +220 -7
  5. package/dist/components/data-display/Chat/Chat.cjs.js +1 -0
  6. package/dist/components/data-display/Chat/Chat.d.ts +114 -0
  7. package/dist/components/data-display/Chat/Chat.mjs +301 -0
  8. package/dist/components/data-display/Chat/Chat.module.css.cjs.js +1 -0
  9. package/dist/components/data-display/Chat/Chat.module.css.mjs +32 -0
  10. package/dist/components/data-display/Chat/index.d.ts +2 -0
  11. package/dist/components/data-display/Chat/streams.cjs.js +4 -0
  12. package/dist/components/data-display/Chat/streams.d.ts +32 -0
  13. package/dist/components/data-display/Chat/streams.mjs +35 -0
  14. package/dist/components/feedback/Toast/ToastProvider.cjs.js +1 -1
  15. package/dist/components/feedback/Toast/ToastProvider.d.ts +4 -1
  16. package/dist/components/feedback/Toast/ToastProvider.mjs +44 -26
  17. package/dist/components/forms/Combobox/Combobox.cjs.js +1 -1
  18. package/dist/components/forms/Combobox/Combobox.mjs +5 -5
  19. package/dist/components/forms/TagInput/TagInput.cjs.js +1 -1
  20. package/dist/components/forms/TagInput/TagInput.mjs +5 -5
  21. package/dist/i18n/en.cjs.js +1 -1
  22. package/dist/i18n/en.mjs +21 -0
  23. package/dist/i18n/types.d.ts +35 -0
  24. package/dist/index.cjs.js +1 -1
  25. package/dist/index.d.ts +1 -0
  26. package/dist/index.mjs +85 -83
  27. package/dist/locales/ar.cjs.js +1 -1
  28. package/dist/locales/ar.mjs +21 -0
  29. package/dist/locales/bn.cjs.js +1 -1
  30. package/dist/locales/bn.mjs +21 -0
  31. package/dist/locales/cs.cjs.js +1 -1
  32. package/dist/locales/cs.mjs +21 -0
  33. package/dist/locales/da.cjs.js +1 -1
  34. package/dist/locales/da.mjs +21 -0
  35. package/dist/locales/de.cjs.js +1 -1
  36. package/dist/locales/de.mjs +21 -0
  37. package/dist/locales/el.cjs.js +1 -1
  38. package/dist/locales/el.mjs +21 -0
  39. package/dist/locales/es.cjs.js +1 -1
  40. package/dist/locales/es.mjs +21 -0
  41. package/dist/locales/fa.cjs.js +1 -1
  42. package/dist/locales/fa.mjs +21 -0
  43. package/dist/locales/fi.cjs.js +1 -1
  44. package/dist/locales/fi.mjs +21 -0
  45. package/dist/locales/fr.cjs.js +1 -1
  46. package/dist/locales/fr.mjs +21 -0
  47. package/dist/locales/he.cjs.js +1 -1
  48. package/dist/locales/he.mjs +21 -0
  49. package/dist/locales/hi.cjs.js +1 -1
  50. package/dist/locales/hi.mjs +21 -0
  51. package/dist/locales/hu.cjs.js +1 -1
  52. package/dist/locales/hu.mjs +21 -0
  53. package/dist/locales/id.cjs.js +1 -1
  54. package/dist/locales/id.mjs +21 -0
  55. package/dist/locales/it.cjs.js +1 -1
  56. package/dist/locales/it.mjs +21 -0
  57. package/dist/locales/ja.cjs.js +1 -1
  58. package/dist/locales/ja.mjs +21 -0
  59. package/dist/locales/ko.cjs.js +1 -1
  60. package/dist/locales/ko.mjs +21 -0
  61. package/dist/locales/nb.cjs.js +1 -1
  62. package/dist/locales/nb.mjs +21 -0
  63. package/dist/locales/nl.cjs.js +1 -1
  64. package/dist/locales/nl.mjs +21 -0
  65. package/dist/locales/pl.cjs.js +1 -1
  66. package/dist/locales/pl.mjs +21 -0
  67. package/dist/locales/pt-BR.cjs.js +1 -1
  68. package/dist/locales/pt-BR.mjs +21 -0
  69. package/dist/locales/ro.cjs.js +1 -1
  70. package/dist/locales/ro.mjs +21 -0
  71. package/dist/locales/ru.cjs.js +1 -1
  72. package/dist/locales/ru.mjs +21 -0
  73. package/dist/locales/sv.cjs.js +1 -1
  74. package/dist/locales/sv.mjs +21 -0
  75. package/dist/locales/th.cjs.js +1 -1
  76. package/dist/locales/th.mjs +21 -0
  77. package/dist/locales/tr.cjs.js +1 -1
  78. package/dist/locales/tr.mjs +21 -0
  79. package/dist/locales/uk.cjs.js +1 -1
  80. package/dist/locales/uk.mjs +21 -0
  81. package/dist/locales/ur.cjs.js +1 -1
  82. package/dist/locales/ur.mjs +21 -0
  83. package/dist/locales/vi.cjs.js +1 -1
  84. package/dist/locales/vi.mjs +21 -0
  85. package/dist/locales/zh-Hans.cjs.js +1 -1
  86. package/dist/locales/zh-Hans.mjs +21 -0
  87. package/dist/locales/zh-Hant.cjs.js +1 -1
  88. package/dist/locales/zh-Hant.mjs +21 -0
  89. package/dist/vjdesigns-ui.css +1 -1
  90. package/package.json +90 -88
@@ -0,0 +1,301 @@
1
+ import { useControllableState as e } from "../../../hooks/useControllableState.mjs";
2
+ import { useMessages as t } from "../../utilities/LocaleProvider/LocaleProvider.mjs";
3
+ import { useClipboard as n } from "../../../hooks/useClipboard.mjs";
4
+ import { useReducedMotion as r } from "../../../hooks/useEnvironment.mjs";
5
+ import { cx as i } from "../../../utils/cx.mjs";
6
+ import { announce as a } from "../../../utils/announce.mjs";
7
+ import { VisuallyHidden as o } from "../../utilities/VisuallyHidden/VisuallyHidden.mjs";
8
+ import { Button as s, IconButton as c } from "../../primitives/Button/Button.mjs";
9
+ import { Icon as l } from "../../primitives/Icon/Icon.mjs";
10
+ import { ScrollArea as u } from "../../layout/ScrollArea/ScrollArea.mjs";
11
+ import { Textarea as ee } from "../../forms/Textarea/Textarea.mjs";
12
+ import d from "./Chat.module.css.mjs";
13
+ import { useCallback as f, useEffect as p, useId as te, useLayoutEffect as ne, useRef as m, useState as h } from "react";
14
+ import { jsx as g, jsxs as _ } from "react/jsx-runtime";
15
+ //#region src/components/data-display/Chat/Chat.tsx
16
+ var re = 48, ie = typeof window < "u" ? ne : p;
17
+ function ae(e) {
18
+ return e != null && typeof e[Symbol.asyncIterator] == "function";
19
+ }
20
+ var oe = () => /* @__PURE__ */ g(l, { children: /* @__PURE__ */ g("rect", {
21
+ x: "7",
22
+ y: "7",
23
+ width: "10",
24
+ height: "10",
25
+ rx: "2",
26
+ fill: "currentColor",
27
+ stroke: "none"
28
+ }) }), v = ({ messages: ne, defaultMessages: v, onMessagesChange: se, onSend: y, onStop: ce, onError: b, draft: le, defaultDraft: ue, onDraftChange: de, suggestions: x, emptyState: fe, renderContent: S, assistantName: pe, assistantAvatar: me, userAvatar: he, copyable: C = !0, disclaimer: w, placeholder: ge, maxLength: T, disabled: E = !1, labels: _e, className: ve, "aria-label": ye, ...D }) => {
29
+ let O = {
30
+ ...t().chat,
31
+ ..._e
32
+ }, k = pe ?? O.assistant, be = r(), A = te(), j = `${A}-hint`, [M, N] = e({
33
+ value: ne,
34
+ defaultValue: v ?? [],
35
+ onChange: se
36
+ }), P = m(M), F = m(M);
37
+ M !== F.current && (F.current = M, P.current = M);
38
+ let I = f((e) => {
39
+ let t = e(P.current);
40
+ P.current = t, N(t);
41
+ }, [N]), L = f((e, t) => I((n) => n.map((n) => n.id === e ? {
42
+ ...n,
43
+ ...t
44
+ } : n)), [I]), xe = m(0), R = () => `${A}-${++xe.current}`, [z, B] = e({
45
+ value: le,
46
+ defaultValue: ue ?? "",
47
+ onChange: de
48
+ }), [V, H] = h(!1), U = m(null), W = m(null), G = m(y);
49
+ G.current = y;
50
+ let K = m(b);
51
+ K.current = b, p(() => () => U.current?.abort(), []);
52
+ let q = m(null), J = m(!0), [Se, Y] = h(!0), Ce = () => {
53
+ let e = q.current;
54
+ if (!e) return;
55
+ let t = e.scrollHeight - e.scrollTop - e.clientHeight <= re;
56
+ J.current = t, Y(t);
57
+ };
58
+ ie(() => {
59
+ let e = q.current;
60
+ e && J.current && (e.scrollTop = e.scrollHeight);
61
+ }, [M]);
62
+ let we = () => {
63
+ let e = q.current;
64
+ e && (J.current = !0, Y(!0), e.scrollTo({
65
+ top: e.scrollHeight,
66
+ behavior: be ? "auto" : "smooth"
67
+ }), W.current?.focus());
68
+ }, X = async (e, t) => {
69
+ let n = R();
70
+ I(() => [...e, {
71
+ id: n,
72
+ role: "assistant",
73
+ content: "",
74
+ status: "streaming"
75
+ }]), J.current = !0, Y(!0), H(!0), a(O.typing(k));
76
+ let r = new AbortController();
77
+ U.current = r;
78
+ let i = "";
79
+ try {
80
+ let o = await G.current?.(t, {
81
+ messages: e,
82
+ signal: r.signal
83
+ });
84
+ if (typeof o == "string") i = o;
85
+ else if (ae(o)) for await (let e of o) {
86
+ if (r.signal.aborted) break;
87
+ i += e, L(n, { content: i });
88
+ }
89
+ else if (!r.signal.aborted) {
90
+ I((e) => e.filter((e) => e.id !== n));
91
+ return;
92
+ }
93
+ if (r.signal.aborted) throw r.signal.reason;
94
+ L(n, {
95
+ content: i,
96
+ status: "done"
97
+ }), a(`${O.assistantSaid(k)} ${i}`);
98
+ } catch (e) {
99
+ r.signal.aborted ? (L(n, {
100
+ content: i,
101
+ status: "stopped"
102
+ }), a(O.stopped)) : (K.current?.(e), L(n, {
103
+ content: i,
104
+ status: "error"
105
+ }), a(O.error));
106
+ } finally {
107
+ U.current === r && (U.current = null), H(!1);
108
+ }
109
+ }, Z = (e) => {
110
+ let t = e.trim();
111
+ !t || V || E || (B(""), X([...P.current, {
112
+ id: R(),
113
+ role: "user",
114
+ content: t,
115
+ status: "done"
116
+ }], t));
117
+ }, Q = () => {
118
+ U.current && (U.current.abort(), ce?.(), W.current?.focus());
119
+ }, Te = (e) => {
120
+ let t = P.current, n = t.findIndex((t) => t.id === e) - 1;
121
+ for (; n >= 0 && t[n].role !== "user";) n--;
122
+ n < 0 || V || (X(t.slice(0, n + 1), t[n].content), W.current?.focus());
123
+ }, Ee = (e) => {
124
+ e.preventDefault(), V ? Q() : Z(z);
125
+ }, De = (e) => {
126
+ if (e.key === "Escape" && V) {
127
+ e.preventDefault(), Q();
128
+ return;
129
+ }
130
+ e.key === "Enter" && !e.shiftKey && !e.nativeEvent.isComposing && (e.preventDefault(), Z(e.currentTarget.value));
131
+ }, { copy: Oe } = n(), [$, ke] = h(null);
132
+ p(() => {
133
+ if ($ === null) return;
134
+ let e = window.setTimeout(() => ke(null), 2e3);
135
+ return () => window.clearTimeout(e);
136
+ }, [$]);
137
+ let Ae = async (e) => {
138
+ await Oe(e.content) && (ke(e.id), a(O.copied));
139
+ }, je = M.filter((e) => e.role !== "system").length === 0, Me = M[M.length - 1], Ne = (e) => {
140
+ if (e.role === "system") return /* @__PURE__ */ g("p", {
141
+ className: d.system,
142
+ children: e.content
143
+ }, e.id);
144
+ let t = e.role === "user", n = e.status ?? "done", r = n === "streaming" && e.content === "", a = t ? he : me, u = !t && !V && e === Me && (n === "error" || n === "stopped");
145
+ return /* @__PURE__ */ _("article", {
146
+ className: i(d.message, t ? d.user : d.assistant),
147
+ "data-role": e.role,
148
+ "data-status": n,
149
+ "aria-busy": n === "streaming" || void 0,
150
+ children: [a != null && /* @__PURE__ */ g("div", {
151
+ className: d.avatar,
152
+ "aria-hidden": "true",
153
+ children: a
154
+ }), /* @__PURE__ */ _("div", {
155
+ className: d.body,
156
+ children: [
157
+ r ? /* @__PURE__ */ _("div", {
158
+ className: d.bubble,
159
+ children: [/* @__PURE__ */ _("span", {
160
+ className: d.dots,
161
+ "aria-hidden": "true",
162
+ children: [
163
+ /* @__PURE__ */ g("span", {}),
164
+ /* @__PURE__ */ g("span", {}),
165
+ /* @__PURE__ */ g("span", {})
166
+ ]
167
+ }), /* @__PURE__ */ g(o, { children: O.typing(k) })]
168
+ }) : e.content !== "" && /* @__PURE__ */ _("div", {
169
+ className: d.bubble,
170
+ children: [/* @__PURE__ */ _(o, { children: [t ? O.youSaid : O.assistantSaid(k), " "] }), S ? S(e) : /* @__PURE__ */ g("p", {
171
+ className: d.text,
172
+ children: e.content
173
+ })]
174
+ }),
175
+ n === "error" && /* @__PURE__ */ _("p", {
176
+ className: d.error,
177
+ children: [/* @__PURE__ */ g(l, {
178
+ name: "error",
179
+ size: "sm"
180
+ }), /* @__PURE__ */ g("span", { children: e.error ?? O.error })]
181
+ }),
182
+ n === "stopped" && /* @__PURE__ */ g("p", {
183
+ className: d.note,
184
+ children: O.stopped
185
+ }),
186
+ !t && (u || C && n === "done" && e.content !== "") && /* @__PURE__ */ _("div", {
187
+ className: d.actions,
188
+ children: [C && n === "done" && e.content !== "" && /* @__PURE__ */ g(c, {
189
+ variant: "ghost",
190
+ tone: "neutral",
191
+ size: "sm",
192
+ "aria-label": $ === e.id ? O.copied : O.copy,
193
+ onClick: () => void Ae(e),
194
+ children: /* @__PURE__ */ g(l, { name: $ === e.id ? "check" : "copy" })
195
+ }), u && /* @__PURE__ */ g(s, {
196
+ variant: "ghost",
197
+ tone: "neutral",
198
+ size: "sm",
199
+ startIcon: /* @__PURE__ */ g(l, { name: "refresh" }),
200
+ onClick: () => Te(e.id),
201
+ children: O.retry
202
+ })]
203
+ })
204
+ ]
205
+ })]
206
+ }, e.id);
207
+ };
208
+ return /* @__PURE__ */ _("section", {
209
+ ...D,
210
+ "aria-label": ye ?? (D["aria-labelledby"] ? void 0 : O.region),
211
+ className: i(d.root, ve),
212
+ children: [/* @__PURE__ */ _("div", {
213
+ className: d.logWrap,
214
+ children: [/* @__PURE__ */ g(u, {
215
+ className: d.log,
216
+ viewportRef: q,
217
+ onViewportScroll: Ce,
218
+ "aria-label": O.log,
219
+ "aria-busy": V || void 0,
220
+ tabIndex: 0,
221
+ children: /* @__PURE__ */ _("div", {
222
+ className: d.messages,
223
+ children: [je && /* @__PURE__ */ _("div", {
224
+ className: d.empty,
225
+ children: [fe ?? /* @__PURE__ */ g("p", {
226
+ className: d.emptyTitle,
227
+ children: O.emptyTitle
228
+ }), x && x.length > 0 && /* @__PURE__ */ g("div", {
229
+ role: "group",
230
+ "aria-label": O.suggestions,
231
+ className: d.suggestions,
232
+ children: x.map((e) => /* @__PURE__ */ g(s, {
233
+ variant: "outline",
234
+ tone: "neutral",
235
+ size: "sm",
236
+ disabled: E,
237
+ className: d.suggestion,
238
+ onClick: () => Z(e),
239
+ children: e
240
+ }, e))
241
+ })]
242
+ }), M.map(Ne)]
243
+ })
244
+ }), !Se && !je && /* @__PURE__ */ g(c, {
245
+ variant: "soft",
246
+ tone: "neutral",
247
+ size: "sm",
248
+ className: d.jump,
249
+ "aria-label": O.scrollToLatest,
250
+ onClick: we,
251
+ children: /* @__PURE__ */ g(l, { name: "arrow-down" })
252
+ })]
253
+ }), /* @__PURE__ */ _("form", {
254
+ className: d.composer,
255
+ onSubmit: Ee,
256
+ children: [
257
+ /* @__PURE__ */ _("div", {
258
+ className: d.inputRow,
259
+ children: [/* @__PURE__ */ g(ee, {
260
+ ref: W,
261
+ className: d.input,
262
+ "aria-label": O.input,
263
+ "aria-describedby": j,
264
+ placeholder: ge ?? O.placeholder,
265
+ value: z,
266
+ onValueChange: B,
267
+ onKeyDown: De,
268
+ autoResize: !0,
269
+ rows: 1,
270
+ maxRows: 6,
271
+ maxLength: T,
272
+ showCount: T !== void 0,
273
+ disabled: E,
274
+ enterKeyHint: "send"
275
+ }), V ? /* @__PURE__ */ g(c, {
276
+ type: "submit",
277
+ variant: "soft",
278
+ tone: "neutral",
279
+ "aria-label": O.stop,
280
+ children: /* @__PURE__ */ g(oe, {})
281
+ }) : /* @__PURE__ */ g(c, {
282
+ type: "submit",
283
+ "aria-label": O.send,
284
+ disabled: E || z.trim() === "",
285
+ children: /* @__PURE__ */ g(l, { name: "arrow-up" })
286
+ })]
287
+ }),
288
+ /* @__PURE__ */ g(o, {
289
+ id: j,
290
+ children: O.hint
291
+ }),
292
+ w != null && /* @__PURE__ */ g("p", {
293
+ className: d.disclaimer,
294
+ children: w
295
+ })
296
+ ]
297
+ })]
298
+ });
299
+ };
300
+ //#endregion
301
+ export { v as Chat };
@@ -0,0 +1 @@
1
+ var e=`_root_1vnqg_8`,t=`_logWrap_1vnqg_18`,n=`_log_1vnqg_18`,r=`_messages_1vnqg_30`,i=`_empty_1vnqg_39`,a=`_emptyTitle_1vnqg_48`,o=`_suggestions_1vnqg_56`,s=`_suggestion_1vnqg_56`,c=`_message_1vnqg_30`,l=`_enter_1vnqg_1`,u=`_user_1vnqg_80`,d=`_assistant_1vnqg_85`,f=`_avatar_1vnqg_89`,p=`_body_1vnqg_94`,m=`_bubble_1vnqg_105`,h=`_text_1vnqg_128`,g=`_dots_1vnqg_134`,_=`_bounce_1vnqg_1`,v=`_error_1vnqg_185`,y=`_note_1vnqg_194`,b=`_actions_1vnqg_201`,x=`_system_1vnqg_207`,S=`_jump_1vnqg_217`,C=`_composer_1vnqg_230`,w=`_inputRow_1vnqg_238`,T=`_input_1vnqg_238`,E=`_disclaimer_1vnqg_248`,D={root:e,logWrap:t,log:n,messages:r,empty:i,emptyTitle:a,suggestions:o,suggestion:s,message:c,enter:l,user:u,assistant:d,avatar:f,body:p,bubble:m,text:h,dots:g,bounce:_,error:v,note:y,actions:b,system:x,jump:S,composer:C,inputRow:w,input:T,disclaimer:E};exports.actions=b,exports.assistant=d,exports.avatar=f,exports.body=p,exports.bounce=_,exports.bubble=m,exports.composer=C,exports.default=D,exports.disclaimer=E,exports.dots=g,exports.empty=i,exports.emptyTitle=a,exports.enter=l,exports.error=v,exports.input=T,exports.inputRow=w,exports.jump=S,exports.log=n,exports.logWrap=t,exports.message=c,exports.messages=r,exports.note=y,exports.root=e,exports.suggestion=s,exports.suggestions=o,exports.system=x,exports.text=h,exports.user=u;
@@ -0,0 +1,32 @@
1
+ //#region src/components/data-display/Chat/Chat.module.css
2
+ var e = "_root_1vnqg_8", t = "_logWrap_1vnqg_18", n = "_log_1vnqg_18", r = "_messages_1vnqg_30", i = "_empty_1vnqg_39", a = "_emptyTitle_1vnqg_48", o = "_suggestions_1vnqg_56", s = "_suggestion_1vnqg_56", c = "_message_1vnqg_30", l = "_enter_1vnqg_1", u = "_user_1vnqg_80", d = "_assistant_1vnqg_85", f = "_avatar_1vnqg_89", p = "_body_1vnqg_94", m = "_bubble_1vnqg_105", h = "_text_1vnqg_128", g = "_dots_1vnqg_134", _ = "_bounce_1vnqg_1", v = "_error_1vnqg_185", y = "_note_1vnqg_194", b = "_actions_1vnqg_201", x = "_system_1vnqg_207", S = "_jump_1vnqg_217", C = "_composer_1vnqg_230", w = "_inputRow_1vnqg_238", T = "_input_1vnqg_238", E = "_disclaimer_1vnqg_248", D = {
3
+ root: e,
4
+ logWrap: t,
5
+ log: n,
6
+ messages: r,
7
+ empty: i,
8
+ emptyTitle: a,
9
+ suggestions: o,
10
+ suggestion: s,
11
+ message: c,
12
+ enter: l,
13
+ user: u,
14
+ assistant: d,
15
+ avatar: f,
16
+ body: p,
17
+ bubble: m,
18
+ text: h,
19
+ dots: g,
20
+ bounce: _,
21
+ error: v,
22
+ note: y,
23
+ actions: b,
24
+ system: x,
25
+ jump: S,
26
+ composer: C,
27
+ inputRow: w,
28
+ input: T,
29
+ disclaimer: E
30
+ };
31
+ //#endregion
32
+ export { b as actions, d as assistant, f as avatar, p as body, _ as bounce, m as bubble, C as composer, D as default, E as disclaimer, g as dots, i as empty, a as emptyTitle, l as enter, v as error, T as input, w as inputRow, S as jump, n as log, t as logWrap, c as message, r as messages, y as note, e as root, s as suggestion, o as suggestions, x as system, h as text, u as user };
@@ -0,0 +1,2 @@
1
+ export * from './Chat';
2
+ export * from './streams';
@@ -0,0 +1,4 @@
1
+ function e(e){let t=e instanceof Response?e.body:e;if(!t)throw Error(`readTextStream: the response has no body to read.`);return t}async function*t(t){let n=e(t).getReader(),r=new TextDecoder;try{for(;;){let{done:e,value:t}=await n.read();if(e)break;let i=r.decode(t,{stream:!0});i&&(yield i)}let e=r.decode();e&&(yield e)}finally{n.releaseLock()}}async function*n(e){let n=``,r=function*(e){let t=n.split(/\r?\n\r?\n/);n=e?``:t.pop()??``;for(let e of t){let t=e.split(/\r?\n/).filter(e=>e.startsWith(`data:`)).map(e=>e.slice(5).replace(/^ /,``));t.length>0&&(yield t.join(`
2
+ `))}};for await(let i of t(e))n+=i,yield*r(!1);n+=`
3
+
4
+ `,yield*r(!0)}exports.readEventStream=n,exports.readTextStream=t;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Helpers for turning a streaming HTTP response into the `AsyncIterable<string>`
3
+ * that `Chat`'s `onSend` can return. They read with `getReader()`, so they
4
+ * work in browsers without async iteration of `ReadableStream`.
5
+ */
6
+ type ByteSource = Response | ReadableStream<Uint8Array> | null | undefined;
7
+ /**
8
+ * Yields decoded text chunks from a plain streaming response (a body that is
9
+ * just the reply text, sent in pieces).
10
+ *
11
+ * ```ts
12
+ * onSend={async function* (text, { signal }) {
13
+ * const res = await fetch("/api/chat", { method: "POST", body: text, signal });
14
+ * yield* readTextStream(res);
15
+ * }}
16
+ * ```
17
+ */
18
+ export declare function readTextStream(source: ByteSource): AsyncGenerator<string>;
19
+ /**
20
+ * Yields the `data` of each server-sent event (`text/event-stream`), the
21
+ * format most LLM APIs stream in. Multi-line data is joined with `\n`. Parse
22
+ * each payload yourself, since every API shapes it differently.
23
+ *
24
+ * ```ts
25
+ * for await (const data of readEventStream(res)) {
26
+ * if (data === "[DONE]") break;
27
+ * yield JSON.parse(data).delta ?? "";
28
+ * }
29
+ * ```
30
+ */
31
+ export declare function readEventStream(source: ByteSource): AsyncGenerator<string>;
32
+ export {};
@@ -0,0 +1,35 @@
1
+ //#region src/components/data-display/Chat/streams.ts
2
+ function e(e) {
3
+ let t = e instanceof Response ? e.body : e;
4
+ if (!t) throw Error("readTextStream: the response has no body to read.");
5
+ return t;
6
+ }
7
+ async function* t(t) {
8
+ let n = e(t).getReader(), r = new TextDecoder();
9
+ try {
10
+ for (;;) {
11
+ let { done: e, value: t } = await n.read();
12
+ if (e) break;
13
+ let i = r.decode(t, { stream: !0 });
14
+ i && (yield i);
15
+ }
16
+ let e = r.decode();
17
+ e && (yield e);
18
+ } finally {
19
+ n.releaseLock();
20
+ }
21
+ }
22
+ async function* n(e) {
23
+ let n = "", r = function* (e) {
24
+ let t = n.split(/\r?\n\r?\n/);
25
+ n = e ? "" : t.pop() ?? "";
26
+ for (let e of t) {
27
+ let t = e.split(/\r?\n/).filter((e) => e.startsWith("data:")).map((e) => e.slice(5).replace(/^ /, ""));
28
+ t.length > 0 && (yield t.join("\n"));
29
+ }
30
+ };
31
+ for await (let i of t(e)) n += i, yield* r(!1);
32
+ n += "\n\n", yield* r(!0);
33
+ }
34
+ //#endregion
35
+ export { n as readEventStream, t as readTextStream };
@@ -1 +1 @@
1
- const e=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),t=require("./toastStore.cjs.js"),n=require("./useToast.cjs.js"),r=require("./ToastViewport.cjs.js");let i=require("react"),a=require("react/jsx-runtime");var o=[`F8`],s=({children:s,store:c=t.toastStore,placement:l=`bottom-end`,max:u=3,duration:d=5e3,gap:f=3,label:p,hotkey:m=o,showProgress:h=!1,toneLabels:g,closeLabel:_,queuedLabel:v,className:y})=>{let b=e.useMessages(),x=p??b.toast.region,S=_??b.toast.dismiss,C=v??b.toast.queued,w=(0,i.useMemo)(()=>({store:c,api:c===t.toastStore?t.toast:t.createToastApi(c)}),[c]),T=(0,i.useMemo)(()=>({neutral:``,...b.toast.tone,...g}),[b.toast.tone,g]);return(0,a.jsxs)(n.ToastContext.Provider,{value:w,children:[s,(0,a.jsx)(r.ToastViewport,{store:c,placement:l,max:u,duration:d,gap:f,label:x,hotkey:m,showProgress:h,toneLabels:T,closeLabel:S,queuedLabel:C,className:y})]})};exports.ToastProvider=s;
1
+ const e=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),t=require("./toastStore.cjs.js"),n=require("./useToast.cjs.js"),r=require("./ToastViewport.cjs.js");let i=require("react"),a=require("react/jsx-runtime");var o=[`F8`],s=globalThis.process?.env?.NODE_ENV!==`production`,c=typeof window<`u`?i.useLayoutEffect:i.useEffect,l=new Map,u=new Set,d=e=>(u.add(e),()=>{u.delete(e)}),f=()=>u.forEach(e=>e());function p(e,t){let[n]=(0,i.useState)(()=>Symbol(`ToastProvider`));return c(()=>{if(t)return;let r=l.get(e)??[];return s&&r.length>0&&console.warn("[ToastProvider] Another ToastProvider already shows this store's toasts, so this one won't draw a second viewport. Use one ToastProvider near the root of your app (inside your LocaleProvider), or pass `store={createToastStore()}` to keep separate toasts."),l.set(e,[...r,n]),f(),()=>{let t=(l.get(e)??[]).filter(e=>e!==n);t.length>0?l.set(e,t):l.delete(e),f()}},[e,t,n]),(0,i.useSyncExternalStore)(d,()=>!t&&l.get(e)?.[0]===n,()=>!t)}var m=({children:s,store:c=t.toastStore,placement:l=`bottom-end`,max:u=3,duration:d=5e3,gap:f=3,label:m,hotkey:h=o,showProgress:g=!1,toneLabels:_,closeLabel:v,queuedLabel:y,className:b})=>{let x=e.useMessages(),S=p(c,(0,i.useContext)(n.ToastContext)?.store===c),C=m??x.toast.region,w=v??x.toast.dismiss,T=y??x.toast.queued,E=(0,i.useMemo)(()=>({store:c,api:c===t.toastStore?t.toast:t.createToastApi(c)}),[c]),D=(0,i.useMemo)(()=>({neutral:``,...x.toast.tone,..._}),[x.toast.tone,_]);return(0,a.jsxs)(n.ToastContext.Provider,{value:E,children:[s,S&&(0,a.jsx)(r.ToastViewport,{store:c,placement:l,max:u,duration:d,gap:f,label:C,hotkey:h,showProgress:g,toneLabels:D,closeLabel:w,queuedLabel:T,className:b})]})};exports.ToastProvider=m;
@@ -45,7 +45,10 @@ export interface ToastProviderProps {
45
45
  }
46
46
  /**
47
47
  * Renders the toast viewport (in a portal) and provides `useToast()`.
48
- * Place it once near the root of your app.
48
+ * Place it once near the root of your app, inside your `LocaleProvider` so
49
+ * its built-in text (like "+2 more notifications") is in the app's language.
50
+ * Each store gets one viewport: a second provider on the same store (nested
51
+ * or not) only provides `useToast()`, so toasts are never drawn twice.
49
52
  *
50
53
  * Accessibility:
51
54
  * - The viewport is a labelled region ("Notifications (F8)"). The hotkey
@@ -2,35 +2,53 @@ import { useMessages as e } from "../../utilities/LocaleProvider/LocaleProvider.
2
2
  import { createToastApi as t, toast as n, toastStore as r } from "./toastStore.mjs";
3
3
  import { ToastContext as i } from "./useToast.mjs";
4
4
  import { ToastViewport as a } from "./ToastViewport.mjs";
5
- import { useMemo as o } from "react";
6
- import { jsx as s, jsxs as c } from "react/jsx-runtime";
5
+ import { useContext as o, useEffect as s, useLayoutEffect as c, useMemo as l, useState as u, useSyncExternalStore as d } from "react";
6
+ import { jsx as f, jsxs as p } from "react/jsx-runtime";
7
7
  //#region src/components/feedback/Toast/ToastProvider.tsx
8
- var l = ["F8"], u = ({ children: u, store: d = r, placement: f = "bottom-end", max: p = 3, duration: m = 5e3, gap: h = 3, label: g, hotkey: _ = l, showProgress: v = !1, toneLabels: y, closeLabel: b, queuedLabel: x, className: S }) => {
9
- let C = e(), w = g ?? C.toast.region, T = b ?? C.toast.dismiss, E = x ?? C.toast.queued, D = o(() => ({
10
- store: d,
11
- api: d === r ? n : t(d)
12
- }), [d]), O = o(() => ({
8
+ var m = ["F8"], h = globalThis.process?.env?.NODE_ENV !== "production", g = typeof window < "u" ? c : s, _ = /* @__PURE__ */ new Map(), v = /* @__PURE__ */ new Set(), y = (e) => (v.add(e), () => {
9
+ v.delete(e);
10
+ }), b = () => v.forEach((e) => e());
11
+ function x(e, t) {
12
+ let [n] = u(() => Symbol("ToastProvider"));
13
+ return g(() => {
14
+ if (t) return;
15
+ let r = _.get(e) ?? [];
16
+ return h && r.length > 0 && console.warn("[ToastProvider] Another ToastProvider already shows this store's toasts, so this one won't draw a second viewport. Use one ToastProvider near the root of your app (inside your LocaleProvider), or pass `store={createToastStore()}` to keep separate toasts."), _.set(e, [...r, n]), b(), () => {
17
+ let t = (_.get(e) ?? []).filter((e) => e !== n);
18
+ t.length > 0 ? _.set(e, t) : _.delete(e), b();
19
+ };
20
+ }, [
21
+ e,
22
+ t,
23
+ n
24
+ ]), d(y, () => !t && _.get(e)?.[0] === n, () => !t);
25
+ }
26
+ var S = ({ children: s, store: c = r, placement: u = "bottom-end", max: d = 3, duration: h = 5e3, gap: g = 3, label: _, hotkey: v = m, showProgress: y = !1, toneLabels: b, closeLabel: S, queuedLabel: C, className: w }) => {
27
+ let T = e(), E = x(c, o(i)?.store === c), D = _ ?? T.toast.region, O = S ?? T.toast.dismiss, k = C ?? T.toast.queued, A = l(() => ({
28
+ store: c,
29
+ api: c === r ? n : t(c)
30
+ }), [c]), j = l(() => ({
13
31
  neutral: "",
14
- ...C.toast.tone,
15
- ...y
16
- }), [C.toast.tone, y]);
17
- return /* @__PURE__ */ c(i.Provider, {
18
- value: D,
19
- children: [u, /* @__PURE__ */ s(a, {
20
- store: d,
21
- placement: f,
22
- max: p,
23
- duration: m,
24
- gap: h,
25
- label: w,
26
- hotkey: _,
27
- showProgress: v,
28
- toneLabels: O,
29
- closeLabel: T,
30
- queuedLabel: E,
31
- className: S
32
+ ...T.toast.tone,
33
+ ...b
34
+ }), [T.toast.tone, b]);
35
+ return /* @__PURE__ */ p(i.Provider, {
36
+ value: A,
37
+ children: [s, E && /* @__PURE__ */ f(a, {
38
+ store: c,
39
+ placement: u,
40
+ max: d,
41
+ duration: h,
42
+ gap: g,
43
+ label: D,
44
+ hotkey: v,
45
+ showProgress: y,
46
+ toneLabels: j,
47
+ closeLabel: O,
48
+ queuedLabel: k,
49
+ className: w
32
50
  })]
33
51
  });
34
52
  };
35
53
  //#endregion
36
- export { u as ToastProvider };
54
+ export { S as ToastProvider };
@@ -1 +1 @@
1
- const e=require("../../../hooks/useControllableState.cjs.js"),t=require("../../../hooks/useOverlayLayer.cjs.js"),n=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),r=require("../../../utils/refs.cjs.js"),i=require("../../../utils/cx.cjs.js"),ee=require("../../utilities/VisuallyHidden/VisuallyHidden.cjs.js"),te=require("../../primitives/Icon/icons.cjs.js"),ne=require("../../data-display/Chip/Chip.cjs.js"),re=require("../Field/FieldContext.cjs.js"),a=require("./comboboxUtils.cjs.js"),o=require("./Combobox.module.css.cjs.js"),ie=require("./ComboboxPopup.cjs.js");let s=require("react"),c=require("react/jsx-runtime"),ae=require("react-dom");var oe={sm:o.default.sm,md:o.default.md,lg:o.default.lg},se={sm:`sm`,md:`sm`,lg:`md`};function l(e){return typeof e==`string`||typeof e==`number`?String(e):``}var ce=500,le=le=>{let u=n.useMessages().combobox,{options:d,renderOption:ue,multiple:f=!1,value:de,defaultValue:fe,onValueChange:pe,inputValue:me,defaultInputValue:he,onInputValueChange:ge,open:_e,defaultOpen:ve=!1,onOpenChange:ye,filter:be,loading:p=!1,loadingMessage:xe=u.loading,emptyMessage:m=u.empty,resultsMessage:Se=u.results,allowCustomValue:h=!1,onCreate:Ce,createLabel:we=u.create,clearable:Te=!1,clearLabel:Ee=u.clear,requiredMessage:De=u.required,clearOnEscape:Oe=!1,showSuggestionsLabel:ke=u.showSuggestions,hideSuggestionsLabel:Ae=u.hideSuggestions,selectedLabel:je=u.selected,autoHighlight:Me=!1,loop:Ne=!0,size:Pe,invalid:Fe,required:Ie,disabled:Le,readOnly:Re,name:g,placement:ze=`bottom-start`,maxHeight:Be,fullWidth:Ve=!0,container:He,inputClassName:Ue,className:We,style:Ge,id:Ke,ref:qe,placeholder:Je,onChange:Ye,onKeyDown:Xe,onBlur:Ze,"aria-describedby":Qe,"aria-label":_,"aria-labelledby":$e,...et}=le,v=re.useFieldContext(),y=re.useFieldControl({id:Ke,invalid:Fe,required:Ie,disabled:Le,readOnly:Re,size:Pe,"aria-describedby":Qe},{nativeRequired:!1}),b=y.size??`md`,x=!y.disabled&&!y.readOnly,tt=(0,s.useId)(),nt=y.id??`${tt}-input`,S=`${tt}-listbox`,C=(0,s.useRef)(null),w=(0,s.useRef)(null),T=(0,s.useRef)(null),rt=(0,s.useCallback)(e=>{C.current=e,r.assignRef(qe,e)},[qe]),E=(0,s.useRef)(new Map);for(let e of d)E.current.set(e.value,e);let D=e=>d.find(t=>t.value===e)??E.current.get(e),[O,k]=e.useControllableState({value:de,defaultValue:fe??(f?[]:null),onChange:pe}),A=f?Array.isArray(O)?O:[]:typeof O==`string`?[O]:[],j=!f&&typeof O==`string`?O:null,M=j===null?``:D(j)?.label??j,[N,P]=e.useControllableState({value:me,defaultValue:he??(f?``:M),onChange:ge}),it=A.length>0||h&&!f&&N.trim()!==``;(0,s.useEffect)(()=>{C.current?.setCustomValidity(y.required&&!it?De:``)},[y.required,it,De]);let[F,I]=e.useControllableState({value:_e,defaultValue:ve,onChange:ye}),at=F&&x,[L,R]=(0,s.useState)(!1),[z,B]=(0,s.useState)(null),ot=be===!1?null:be??a.defaultComboboxFilter,st=(e,t)=>{let n=[];d.forEach((t,r)=>{(!ot||ot(t,e))&&n.push({kind:`option`,key:t.value,option:t,id:`${S}-option-${r}`})});let r=N.trim();return Ce&&t&&r!==``&&!d.some(e=>a.normalizeText(e.label)===a.normalizeText(r))&&n.push({kind:`create`,key:a.CREATE_KEY,text:r,id:`${S}-create`}),a.orderItems(n)},V=f||L,H=st(V?N:``,V),U=z===null?-1:H.findIndex(e=>e.key===z);U>=0&&!a.isEnabled(H[U])&&(U=-1),U===-1&&Me&&V&&N.trim()!==``&&(U=a.findEnabled(H,-1,1,!0));let ct=m!=null&&m!==!1&&m!==``,W=at&&(H.length>0||p||ct),lt=W&&U>=0?H[U].id:void 0,[ut,G]=(0,s.useState)(``),dt=H.filter(e=>e.kind===`option`).length,ft=H.find(e=>e.kind===`create`),K=W?p?l(xe):dt>0?Se(dt):ft?.kind===`create`?l(we(ft.text)):l(m):``;(0,s.useEffect)(()=>{if(!K)return;let e=window.setTimeout(()=>G(K),ce);return()=>window.clearTimeout(e)},[K]),(0,s.useEffect)(()=>{W||G(``)},[W]);let q=(0,s.useRef)(me!==void 0&&!f&&M!==``?null:M);(0,s.useEffect)(()=>{f||q.current===M||(q.current=M,!(h&&M===``)&&(L||P(M)))},[f,M,L,h,P]);let J=e=>{(!e||x)&&(I(e),e||B(null))},pt=t.useOverlayLayer({active:W,elements:()=>[w,T],onEscape:()=>J(!1),onOutsidePress:()=>J(!1)}),Y=e=>{if(!x)return;let t=!f&&N===M,n=f||L&&!t;t&&R(!1);let r=st(n?N:``,n),i=-1;e===`first`?i=a.findEnabled(r,-1,1,!0):e===`last`?i=a.findEnabled(r,-1,-1,!0):e===`selected`&&(i=r.findIndex(e=>e.kind===`option`&&!e.option.disabled&&A.includes(e.option.value)),i<0&&(i=a.findEnabled(r,-1,1,!0))),B(i>=0?r[i].key:null),I(!0)},mt=e=>{let t=a.findEnabled(H,U,e,Ne);B(t>=0?H[t].key:null)},X=(e,t)=>{if(f){let n=A.includes(e);k(n?A.filter(t=>t!==e):[...A,e]),P(``),R(!1),B(e),G(n?u.optionRemoved(t):u.optionSelected(t));return}k(e),q.current=t,P(t),R(!1),J(!1)},ht=e=>{if(!a.isEnabled(e))return;if(e.kind===`option`){X(e.option.value,e.option.label);return}let t=Ce?.(e.text);if(typeof t==`string`){E.current.set(t,{value:t,label:e.text}),X(t,e.text);return}R(!1),f?P(``):J(!1)},gt=e=>{x&&(k(A.filter(t=>t!==e)),G(u.optionRemoved(D(e)?.label??e)))},Z=()=>{k(f?[]:null),q.current=``,P(``),R(!1),B(null)},_t=e=>{Ye?.(e),P(e.target.value),R(!0),B(null),F||J(!0)},vt=e=>{if(Xe?.(e),!(e.defaultPrevented||e.nativeEvent.isComposing||y.disabled))switch(e.key){case`ArrowDown`:if(!x)return;e.preventDefault(),e.altKey?W||Y(`none`):W?mt(1):Y(f?`first`:`selected`);return;case`ArrowUp`:if(!x)return;e.preventDefault(),e.altKey?J(!1):W?mt(-1):Y(`last`);return;case`Enter`:if(!W){f&&h&&N.trim()&&x&&(e.preventDefault(),e.repeat||yt()),!f&&x&&(0,ae.flushSync)(bt);return}if(e.preventDefault(),e.repeat)return;U>=0?ht(H[U]):f&&h&&N.trim()?yt():(!f&&h&&N!==M&&j!==null&&k(null),J(!1));return;case`Escape`:if(W)return;if(F){e.preventDefault(),I(!1);return}if(!x)return;{let t=f?``:M;if(N!==t){e.preventDefault(),P(t),R(!1);return}Oe&&(j!==null||A.length>0)&&(e.preventDefault(),Z())}return;case`Home`:case`End`:case`ArrowLeft`:case`ArrowRight`:z!==null&&B(null);return;case`Backspace`:f&&x&&!e.repeat&&N===``&&A.length>0&&gt(A[A.length-1]);return;default:return}},yt=()=>{let e=N.trim(),t=d.find(t=>a.normalizeText(t.label)===a.normalizeText(e));if(A.includes(t?.value??e)){P(``);return}if(t){t.disabled||X(t.value,t.label);return}E.current.set(e,{value:e,label:e}),X(e,e)},bt=()=>{if(!(f||N===M)){if(N.trim()===``){j===null?N!==``&&P(``):Z();return}if(h){j!==null&&k(null);return}P(M)}},xt=e=>{Ze?.(e),J(!1),R(!1),bt()},St=(0,s.useRef)(()=>{});St.current=()=>{if(de!==void 0)return;let e=fe??(f?[]:null);k(e);let t=typeof e==`string`?D(e)?.label??e:``;P(he??(f?``:t)),J(!1),R(!1)},(0,s.useEffect)(()=>{let e=C.current?.form;if(!e)return;let t=()=>St.current();return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)},[]);let Ct=e=>{let t=C.current;if(!t||y.disabled)return;let n=e.target;w.current?.contains(n)&&(n===t||n.closest(`button, a`)||(e.preventDefault(),t.focus()))},wt=e=>{let t=e.target;w.current?.contains(t)&&!t.closest(`button, a`)&&(F||Y(`none`))},Tt=()=>{C.current?.focus(),W||F?J(!1):Y(`none`)},Et=()=>{Z(),G(u.cleared),C.current?.focus()},Q=e=>e.preventDefault(),Dt=Te&&x&&(A.length>0||N!==``),$=f&&A.length>0,Ot=$e??(_?void 0:v&&!v.isGroup?v.labelId:void 0),kt=g===void 0?null:f?A.map(e=>(0,c.jsx)(`input`,{type:`hidden`,name:g,value:e,disabled:y.disabled},e)):(0,c.jsx)(`input`,{type:`hidden`,name:g,value:j??(h?N:``),disabled:y.disabled});return(0,c.jsxs)(`div`,{ref:w,className:i.cx(o.default.root,oe[b],Ve&&o.default.fullWidth,f&&o.default.multiple,$&&o.default.hasChips,y.invalid&&o.default.invalid,y.disabled&&o.default.disabled,y.readOnly&&!y.disabled&&o.default.readOnly,We),style:Ge,"data-size":b,"data-state":W?`open`:`closed`,onMouseDown:Ct,onClick:wt,children:[$&&(0,c.jsx)(ne.ChipGroup,{"aria-label":je,size:se[b],tone:`primary`,variant:`soft`,disabled:y.disabled,focusFallback:C,className:o.default.chips,children:A.map(e=>{let t=D(e);return(0,c.jsx)(ne.Chip,{startIcon:t?.icon,onRemove:x?()=>gt(e):void 0,children:t?.label??e},e)})}),(0,c.jsx)(`input`,{autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`none`,spellCheck:!1,...et,ref:rt,id:nt,type:`text`,role:`combobox`,"aria-label":_,"aria-labelledby":$e,"aria-expanded":W,"aria-controls":S,"aria-autocomplete":`list`,"aria-activedescendant":lt,...y.ariaProps,placeholder:$?void 0:Je,value:N,disabled:y.disabled,readOnly:y.readOnly,className:i.cx(o.default.input,Ue),onChange:_t,onKeyDown:vt,onBlur:xt}),(0,c.jsxs)(`span`,{className:o.default.actions,children:[Dt&&(0,c.jsx)(`button`,{type:`button`,className:o.default.iconButton,"aria-label":Ee,onMouseDown:Q,onClick:Et,children:(0,c.jsx)(te.CloseIcon,{size:b===`lg`?`sm`:`xs`,strokeWidth:2.5})}),(0,c.jsx)(`button`,{type:`button`,tabIndex:-1,className:i.cx(o.default.iconButton,o.default.toggle),"aria-label":W?Ae:ke,disabled:!x,onMouseDown:Q,onClick:Tt,children:(0,c.jsx)(te.ChevronDownIcon,{size:b===`sm`?`sm`:`md`,className:o.default.chevron})})]}),kt,(0,c.jsx)(ee.VisuallyHidden,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:ut}),W&&(0,c.jsx)(ie.ComboboxPopup,{anchorRef:w,positionerRef:T,layer:pt,listboxId:S,labelledBy:Ot,label:_,multiple:f,size:b,placement:ze,maxHeight:Be,items:H,highlightedIndex:U,isSelected:e=>A.includes(e),onHighlight:e=>B(H[e]?.key??null),onChoose:ht,renderOption:ue,createLabel:we,loading:p,loadingMessage:xe,emptyMessage:m,container:He})]})};exports.Combobox=le,exports.defaultComboboxFilter=a.defaultComboboxFilter;
1
+ const e=require("../../../hooks/useControllableState.cjs.js"),t=require("../../../hooks/useOverlayLayer.cjs.js"),n=require("../../utilities/LocaleProvider/LocaleProvider.cjs.js"),r=require("../../../utils/refs.cjs.js"),i=require("../../../utils/cx.cjs.js"),ee=require("../../utilities/VisuallyHidden/VisuallyHidden.cjs.js"),te=require("../../primitives/Icon/icons.cjs.js"),ne=require("../Field/FieldContext.cjs.js"),re=require("../../data-display/Chip/Chip.cjs.js"),a=require("./comboboxUtils.cjs.js"),o=require("./Combobox.module.css.cjs.js"),ie=require("./ComboboxPopup.cjs.js");let s=require("react"),c=require("react/jsx-runtime"),ae=require("react-dom");var oe={sm:o.default.sm,md:o.default.md,lg:o.default.lg},se={sm:`sm`,md:`sm`,lg:`md`};function l(e){return typeof e==`string`||typeof e==`number`?String(e):``}var ce=500,le=le=>{let u=n.useMessages().combobox,{options:d,renderOption:ue,multiple:f=!1,value:de,defaultValue:fe,onValueChange:pe,inputValue:me,defaultInputValue:he,onInputValueChange:ge,open:_e,defaultOpen:ve=!1,onOpenChange:ye,filter:be,loading:p=!1,loadingMessage:xe=u.loading,emptyMessage:m=u.empty,resultsMessage:Se=u.results,allowCustomValue:h=!1,onCreate:Ce,createLabel:we=u.create,clearable:Te=!1,clearLabel:Ee=u.clear,requiredMessage:De=u.required,clearOnEscape:Oe=!1,showSuggestionsLabel:ke=u.showSuggestions,hideSuggestionsLabel:Ae=u.hideSuggestions,selectedLabel:je=u.selected,autoHighlight:Me=!1,loop:Ne=!0,size:Pe,invalid:Fe,required:Ie,disabled:Le,readOnly:Re,name:g,placement:ze=`bottom-start`,maxHeight:Be,fullWidth:Ve=!0,container:He,inputClassName:Ue,className:We,style:Ge,id:Ke,ref:qe,placeholder:Je,onChange:Ye,onKeyDown:Xe,onBlur:Ze,"aria-describedby":Qe,"aria-label":_,"aria-labelledby":$e,...et}=le,v=ne.useFieldContext(),y=ne.useFieldControl({id:Ke,invalid:Fe,required:Ie,disabled:Le,readOnly:Re,size:Pe,"aria-describedby":Qe},{nativeRequired:!1}),b=y.size??`md`,x=!y.disabled&&!y.readOnly,tt=(0,s.useId)(),nt=y.id??`${tt}-input`,S=`${tt}-listbox`,C=(0,s.useRef)(null),w=(0,s.useRef)(null),T=(0,s.useRef)(null),rt=(0,s.useCallback)(e=>{C.current=e,r.assignRef(qe,e)},[qe]),E=(0,s.useRef)(new Map);for(let e of d)E.current.set(e.value,e);let D=e=>d.find(t=>t.value===e)??E.current.get(e),[O,k]=e.useControllableState({value:de,defaultValue:fe??(f?[]:null),onChange:pe}),A=f?Array.isArray(O)?O:[]:typeof O==`string`?[O]:[],j=!f&&typeof O==`string`?O:null,M=j===null?``:D(j)?.label??j,[N,P]=e.useControllableState({value:me,defaultValue:he??(f?``:M),onChange:ge}),it=A.length>0||h&&!f&&N.trim()!==``;(0,s.useEffect)(()=>{C.current?.setCustomValidity(y.required&&!it?De:``)},[y.required,it,De]);let[F,I]=e.useControllableState({value:_e,defaultValue:ve,onChange:ye}),at=F&&x,[L,R]=(0,s.useState)(!1),[z,B]=(0,s.useState)(null),ot=be===!1?null:be??a.defaultComboboxFilter,st=(e,t)=>{let n=[];d.forEach((t,r)=>{(!ot||ot(t,e))&&n.push({kind:`option`,key:t.value,option:t,id:`${S}-option-${r}`})});let r=N.trim();return Ce&&t&&r!==``&&!d.some(e=>a.normalizeText(e.label)===a.normalizeText(r))&&n.push({kind:`create`,key:a.CREATE_KEY,text:r,id:`${S}-create`}),a.orderItems(n)},V=f||L,H=st(V?N:``,V),U=z===null?-1:H.findIndex(e=>e.key===z);U>=0&&!a.isEnabled(H[U])&&(U=-1),U===-1&&Me&&V&&N.trim()!==``&&(U=a.findEnabled(H,-1,1,!0));let ct=m!=null&&m!==!1&&m!==``,W=at&&(H.length>0||p||ct),lt=W&&U>=0?H[U].id:void 0,[ut,G]=(0,s.useState)(``),dt=H.filter(e=>e.kind===`option`).length,ft=H.find(e=>e.kind===`create`),K=W?p?l(xe):dt>0?Se(dt):ft?.kind===`create`?l(we(ft.text)):l(m):``;(0,s.useEffect)(()=>{if(!K)return;let e=window.setTimeout(()=>G(K),ce);return()=>window.clearTimeout(e)},[K]),(0,s.useEffect)(()=>{W||G(``)},[W]);let q=(0,s.useRef)(me!==void 0&&!f&&M!==``?null:M);(0,s.useEffect)(()=>{f||q.current===M||(q.current=M,!(h&&M===``)&&(L||P(M)))},[f,M,L,h,P]);let J=e=>{(!e||x)&&(I(e),e||B(null))},pt=t.useOverlayLayer({active:W,elements:()=>[w,T],onEscape:()=>J(!1),onOutsidePress:()=>J(!1)}),Y=e=>{if(!x)return;let t=!f&&N===M,n=f||L&&!t;t&&R(!1);let r=st(n?N:``,n),i=-1;e===`first`?i=a.findEnabled(r,-1,1,!0):e===`last`?i=a.findEnabled(r,-1,-1,!0):e===`selected`&&(i=r.findIndex(e=>e.kind===`option`&&!e.option.disabled&&A.includes(e.option.value)),i<0&&(i=a.findEnabled(r,-1,1,!0))),B(i>=0?r[i].key:null),I(!0)},mt=e=>{let t=a.findEnabled(H,U,e,Ne);B(t>=0?H[t].key:null)},X=(e,t)=>{if(f){let n=A.includes(e);k(n?A.filter(t=>t!==e):[...A,e]),P(``),R(!1),B(e),G(n?u.optionRemoved(t):u.optionSelected(t));return}k(e),q.current=t,P(t),R(!1),J(!1)},ht=e=>{if(!a.isEnabled(e))return;if(e.kind===`option`){X(e.option.value,e.option.label);return}let t=Ce?.(e.text);if(typeof t==`string`){E.current.set(t,{value:t,label:e.text}),X(t,e.text);return}R(!1),f?P(``):J(!1)},gt=e=>{x&&(k(A.filter(t=>t!==e)),G(u.optionRemoved(D(e)?.label??e)))},Z=()=>{k(f?[]:null),q.current=``,P(``),R(!1),B(null)},_t=e=>{Ye?.(e),P(e.target.value),R(!0),B(null),F||J(!0)},vt=e=>{if(Xe?.(e),!(e.defaultPrevented||e.nativeEvent.isComposing||y.disabled))switch(e.key){case`ArrowDown`:if(!x)return;e.preventDefault(),e.altKey?W||Y(`none`):W?mt(1):Y(f?`first`:`selected`);return;case`ArrowUp`:if(!x)return;e.preventDefault(),e.altKey?J(!1):W?mt(-1):Y(`last`);return;case`Enter`:if(!W){f&&h&&N.trim()&&x&&(e.preventDefault(),e.repeat||yt()),!f&&x&&(0,ae.flushSync)(bt);return}if(e.preventDefault(),e.repeat)return;U>=0?ht(H[U]):f&&h&&N.trim()?yt():(!f&&h&&N!==M&&j!==null&&k(null),J(!1));return;case`Escape`:if(W)return;if(F){e.preventDefault(),I(!1);return}if(!x)return;{let t=f?``:M;if(N!==t){e.preventDefault(),P(t),R(!1);return}Oe&&(j!==null||A.length>0)&&(e.preventDefault(),Z())}return;case`Home`:case`End`:case`ArrowLeft`:case`ArrowRight`:z!==null&&B(null);return;case`Backspace`:f&&x&&!e.repeat&&N===``&&A.length>0&&gt(A[A.length-1]);return;default:return}},yt=()=>{let e=N.trim(),t=d.find(t=>a.normalizeText(t.label)===a.normalizeText(e));if(A.includes(t?.value??e)){P(``);return}if(t){t.disabled||X(t.value,t.label);return}E.current.set(e,{value:e,label:e}),X(e,e)},bt=()=>{if(!(f||N===M)){if(N.trim()===``){j===null?N!==``&&P(``):Z();return}if(h){j!==null&&k(null);return}P(M)}},xt=e=>{Ze?.(e),J(!1),R(!1),bt()},St=(0,s.useRef)(()=>{});St.current=()=>{if(de!==void 0)return;let e=fe??(f?[]:null);k(e);let t=typeof e==`string`?D(e)?.label??e:``;P(he??(f?``:t)),J(!1),R(!1)},(0,s.useEffect)(()=>{let e=C.current?.form;if(!e)return;let t=()=>St.current();return e.addEventListener(`reset`,t),()=>e.removeEventListener(`reset`,t)},[]);let Ct=e=>{let t=C.current;if(!t||y.disabled)return;let n=e.target;w.current?.contains(n)&&(n===t||n.closest(`button, a`)||(e.preventDefault(),t.focus()))},wt=e=>{let t=e.target;w.current?.contains(t)&&!t.closest(`button, a`)&&(F||Y(`none`))},Tt=()=>{C.current?.focus(),W||F?J(!1):Y(`none`)},Et=()=>{Z(),G(u.cleared),C.current?.focus()},Q=e=>e.preventDefault(),Dt=Te&&x&&(A.length>0||N!==``),$=f&&A.length>0,Ot=$e??(_?void 0:v&&!v.isGroup?v.labelId:void 0),kt=g===void 0?null:f?A.map(e=>(0,c.jsx)(`input`,{type:`hidden`,name:g,value:e,disabled:y.disabled},e)):(0,c.jsx)(`input`,{type:`hidden`,name:g,value:j??(h?N:``),disabled:y.disabled});return(0,c.jsxs)(`div`,{ref:w,className:i.cx(o.default.root,oe[b],Ve&&o.default.fullWidth,f&&o.default.multiple,$&&o.default.hasChips,y.invalid&&o.default.invalid,y.disabled&&o.default.disabled,y.readOnly&&!y.disabled&&o.default.readOnly,We),style:Ge,"data-size":b,"data-state":W?`open`:`closed`,onMouseDown:Ct,onClick:wt,children:[$&&(0,c.jsx)(re.ChipGroup,{"aria-label":je,size:se[b],tone:`primary`,variant:`soft`,disabled:y.disabled,focusFallback:C,className:o.default.chips,children:A.map(e=>{let t=D(e);return(0,c.jsx)(re.Chip,{startIcon:t?.icon,onRemove:x?()=>gt(e):void 0,children:t?.label??e},e)})}),(0,c.jsx)(`input`,{autoComplete:`off`,autoCorrect:`off`,autoCapitalize:`none`,spellCheck:!1,...et,ref:rt,id:nt,type:`text`,role:`combobox`,"aria-label":_,"aria-labelledby":$e,"aria-expanded":W,"aria-controls":S,"aria-autocomplete":`list`,"aria-activedescendant":lt,...y.ariaProps,placeholder:$?void 0:Je,value:N,disabled:y.disabled,readOnly:y.readOnly,className:i.cx(o.default.input,Ue),onChange:_t,onKeyDown:vt,onBlur:xt}),(0,c.jsxs)(`span`,{className:o.default.actions,children:[Dt&&(0,c.jsx)(`button`,{type:`button`,className:o.default.iconButton,"aria-label":Ee,onMouseDown:Q,onClick:Et,children:(0,c.jsx)(te.CloseIcon,{size:b===`lg`?`sm`:`xs`,strokeWidth:2.5})}),(0,c.jsx)(`button`,{type:`button`,tabIndex:-1,className:i.cx(o.default.iconButton,o.default.toggle),"aria-label":W?Ae:ke,disabled:!x,onMouseDown:Q,onClick:Tt,children:(0,c.jsx)(te.ChevronDownIcon,{size:b===`sm`?`sm`:`md`,className:o.default.chevron})})]}),kt,(0,c.jsx)(ee.VisuallyHidden,{role:`status`,"aria-live":`polite`,"aria-atomic":`true`,children:ut}),W&&(0,c.jsx)(ie.ComboboxPopup,{anchorRef:w,positionerRef:T,layer:pt,listboxId:S,labelledBy:Ot,label:_,multiple:f,size:b,placement:ze,maxHeight:Be,items:H,highlightedIndex:U,isSelected:e=>A.includes(e),onHighlight:e=>B(H[e]?.key??null),onChoose:ht,renderOption:ue,createLabel:we,loading:p,loadingMessage:xe,emptyMessage:m,container:He})]})};exports.Combobox=le,exports.defaultComboboxFilter=a.defaultComboboxFilter;
@@ -5,8 +5,8 @@ import { assignRef as r } from "../../../utils/refs.mjs";
5
5
  import { cx as i } from "../../../utils/cx.mjs";
6
6
  import { VisuallyHidden as ee } from "../../utilities/VisuallyHidden/VisuallyHidden.mjs";
7
7
  import { ChevronDownIcon as te, CloseIcon as ne } from "../../primitives/Icon/icons.mjs";
8
- import { Chip as re, ChipGroup as ie } from "../../data-display/Chip/Chip.mjs";
9
- import { useFieldContext as ae, useFieldControl as oe } from "../Field/FieldContext.mjs";
8
+ import { useFieldContext as re, useFieldControl as ie } from "../Field/FieldContext.mjs";
9
+ import { Chip as ae, ChipGroup as oe } from "../../data-display/Chip/Chip.mjs";
10
10
  import { CREATE_KEY as se, defaultComboboxFilter as ce, findEnabled as a, isEnabled as le, normalizeText as o, orderItems as ue } from "./comboboxUtils.mjs";
11
11
  import s from "./Combobox.module.css.mjs";
12
12
  import { ComboboxPopup as de } from "./ComboboxPopup.mjs";
@@ -27,7 +27,7 @@ function f(e) {
27
27
  return typeof e == "string" || typeof e == "number" ? String(e) : "";
28
28
  }
29
29
  var ve = 500, ye = (ye) => {
30
- let p = n().combobox, { options: m, renderOption: be, multiple: h = !1, value: xe, defaultValue: Se, onValueChange: Ce, inputValue: we, defaultInputValue: Te, onInputValueChange: Ee, open: De, defaultOpen: Oe = !1, onOpenChange: ke, filter: Ae, loading: g = !1, loadingMessage: je = p.loading, emptyMessage: _ = p.empty, resultsMessage: Me = p.results, allowCustomValue: v = !1, onCreate: Ne, createLabel: Pe = p.create, clearable: Fe = !1, clearLabel: Ie = p.clear, requiredMessage: Le = p.required, clearOnEscape: Re = !1, showSuggestionsLabel: ze = p.showSuggestions, hideSuggestionsLabel: Be = p.hideSuggestions, selectedLabel: Ve = p.selected, autoHighlight: He = !1, loop: Ue = !0, size: We, invalid: Ge, required: Ke, disabled: qe, readOnly: Je, name: y, placement: Ye = "bottom-start", maxHeight: Xe, fullWidth: Ze = !0, container: Qe, inputClassName: $e, className: et, style: tt, id: nt, ref: rt, placeholder: it, onChange: at, onKeyDown: ot, onBlur: st, "aria-describedby": ct, "aria-label": b, "aria-labelledby": lt, ...ut } = ye, x = ae(), S = oe({
30
+ let p = n().combobox, { options: m, renderOption: be, multiple: h = !1, value: xe, defaultValue: Se, onValueChange: Ce, inputValue: we, defaultInputValue: Te, onInputValueChange: Ee, open: De, defaultOpen: Oe = !1, onOpenChange: ke, filter: Ae, loading: g = !1, loadingMessage: je = p.loading, emptyMessage: _ = p.empty, resultsMessage: Me = p.results, allowCustomValue: v = !1, onCreate: Ne, createLabel: Pe = p.create, clearable: Fe = !1, clearLabel: Ie = p.clear, requiredMessage: Le = p.required, clearOnEscape: Re = !1, showSuggestionsLabel: ze = p.showSuggestions, hideSuggestionsLabel: Be = p.hideSuggestions, selectedLabel: Ve = p.selected, autoHighlight: He = !1, loop: Ue = !0, size: We, invalid: Ge, required: Ke, disabled: qe, readOnly: Je, name: y, placement: Ye = "bottom-start", maxHeight: Xe, fullWidth: Ze = !0, container: Qe, inputClassName: $e, className: et, style: tt, id: nt, ref: rt, placeholder: it, onChange: at, onKeyDown: ot, onBlur: st, "aria-describedby": ct, "aria-label": b, "aria-labelledby": lt, ...ut } = ye, x = re(), S = ie({
31
31
  id: nt,
32
32
  invalid: Ge,
33
33
  required: Ke,
@@ -258,7 +258,7 @@ var ve = 500, ye = (ye) => {
258
258
  onMouseDown: Pt,
259
259
  onClick: Ft,
260
260
  children: [
261
- Bt && /* @__PURE__ */ d(ie, {
261
+ Bt && /* @__PURE__ */ d(oe, {
262
262
  "aria-label": Ve,
263
263
  size: _e[C],
264
264
  tone: "primary",
@@ -268,7 +268,7 @@ var ve = 500, ye = (ye) => {
268
268
  className: s.chips,
269
269
  children: M.map((e) => {
270
270
  let t = k(e);
271
- return /* @__PURE__ */ d(re, {
271
+ return /* @__PURE__ */ d(ae, {
272
272
  startIcon: t?.icon,
273
273
  onRemove: w ? () => Dt(e) : void 0,
274
274
  children: t?.label ?? e