@shortround/react 0.0.0-stage → 0.5.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.
@@ -0,0 +1,647 @@
1
+ import { createPaletteStore as he, createSidekickStore as Q, cycleCorners as fe, RevertIntentionIds as me, NAVIGATE_GROUP as pe, ControlLabels as Se } from "@shortround/core";
2
+ import { useRef as m, useSyncExternalStore as H, useEffect as T, createContext as Z, useContext as ee, useMemo as F, useCallback as _, createElement as ge, useLayoutEffect as L, forwardRef as we, useState as ve } from "react";
3
+ import { jsx as i, jsxs as O, Fragment as ye } from "react/jsx-runtime";
4
+ import Re from "tiny-invariant";
5
+ import { motion as K } from "framer-motion";
6
+ import { Command as E, useCommandState as te } from "cmdk";
7
+ function ne({
8
+ palette: e,
9
+ defaultIntentions: t,
10
+ resolveDefaultInput: n,
11
+ resolveDefaultFallbackInput: o
12
+ }) {
13
+ const r = m(null);
14
+ r.current || (r.current = he({
15
+ palette: e,
16
+ defaultIntentions: t,
17
+ resolveDefaultInput: n,
18
+ resolveDefaultFallbackInput: o
19
+ }));
20
+ const c = r.current, s = H(c.subscribe, c.getState, c.getState);
21
+ return T(() => {
22
+ c.setDefaults({
23
+ palette: e,
24
+ defaultIntentions: t,
25
+ resolveDefaultInput: n,
26
+ resolveDefaultFallbackInput: o
27
+ });
28
+ }, [c, e, t, n, o]), T(() => c.watchResolver(), [c]), T(() => c.watchPalette(), [c, e]), { store: c, state: s, intentions: c.rows() };
29
+ }
30
+ function ht({
31
+ defaultIntentions: e,
32
+ resolveDefaultInput: t,
33
+ resolveDefaultFallbackInput: n
34
+ }) {
35
+ const { store: o, state: r, intentions: c } = ne({
36
+ defaultIntentions: e,
37
+ resolveDefaultInput: t,
38
+ resolveDefaultFallbackInput: n
39
+ });
40
+ return {
41
+ inputValue: r.inputValue,
42
+ inputMessage: r.inputMessage,
43
+ onInputChange: o.changeInput,
44
+ intentions: c,
45
+ revertIntentions: r.revertIntentions,
46
+ dispatch: (s) => o.select(s),
47
+ reset: o.reset,
48
+ back: o.back,
49
+ dispatchedStack: r.dispatchedStack
50
+ };
51
+ }
52
+ const V = 0.35, Oe = "100vh", ke = Object.freeze({
53
+ center: { top: "50%", left: "50%", transform: "translate(-50%, -50%)" },
54
+ "top-left": { top: 0, left: 0 },
55
+ top: { top: 0, left: "50%", transform: "translateX(-50%)" },
56
+ left: { top: "50%", left: 0, transform: "translateY(-50%)" },
57
+ "top-right": { top: 0, right: 0 },
58
+ right: { top: "50%", right: 0, transform: "translateY(-50%)" },
59
+ "bottom-right": { bottom: 0, right: 0 },
60
+ bottom: { bottom: 0, left: "50%", transform: "translateX(-50%)" },
61
+ "bottom-left": { bottom: 0, left: 0 }
62
+ }), q = Object.freeze({
63
+ compact: { height: "auto" },
64
+ medium: { height: "50vh" },
65
+ full: { height: Oe }
66
+ }), oe = "ShortRound", Ie = ({ onOpen: e, installKeyboardShortcuts: t = !0 }) => {
67
+ const n = m({ onOpen: e });
68
+ n.current = { onOpen: e }, T(() => {
69
+ if (!t)
70
+ return;
71
+ const o = (r) => {
72
+ (r.metaKey || r.ctrlKey) && r.key === "k" && n.current.onOpen();
73
+ };
74
+ return document.addEventListener("keydown", o, { capture: !0 }), () => document.removeEventListener("keydown", o, { capture: !0 });
75
+ }, [t]);
76
+ }, re = Z(null), W = () => ee(re);
77
+ function be({ store: e, initial: t, children: n }) {
78
+ const o = W(), r = m(null);
79
+ !e && !o && !r.current && (r.current = Q(t));
80
+ const c = e ?? o ?? r.current;
81
+ return /* @__PURE__ */ i(re.Provider, { value: c, children: n });
82
+ }
83
+ function U(e = {}) {
84
+ const t = W();
85
+ let n = e.store || t;
86
+ const o = m(null);
87
+ n || (o.current || (o.current = Q(e.initial)), n = o.current);
88
+ const r = H(n.subscribe, n.get, n.get), c = F(() => {
89
+ const { maxTotalWidth: s, commandWidth: a, anchorOrigin: d, internalSidecarRenderer: h, size: l } = r, { height: p } = q[l], w = `calc(${s} - ${a})`, v = (f) => n.set({ anchorOrigin: f }), y = () => {
90
+ v(fe(d));
91
+ }, R = () => {
92
+ if (h)
93
+ return h();
94
+ };
95
+ return {
96
+ // Worked out from the origin, so a store created with only `anchorOrigin` opens there; a position stored
97
+ // beside it (a 0.3.0 workaround) is ignored.
98
+ anchorPosition: ke[d],
99
+ onOpen: () => n.set({ isOpen: !0 }),
100
+ setIsOpen: (f) => {
101
+ n.set({ isOpen: f });
102
+ },
103
+ onClose: () => {
104
+ n.clearSidecar(), n.set({ isOpen: !1 });
105
+ },
106
+ height: p,
107
+ setSize: (f) => {
108
+ Re(q[f], `Unknown size: ${f}`), n.set({ size: f });
109
+ },
110
+ setAnchorOrigin: v,
111
+ cycleAnchorOrigin: y,
112
+ // The app's own calls: through the reducer, with the reason `app`.
113
+ setSidecarRenderer: n.openSidecar,
114
+ commandWidth: a,
115
+ sidecarWidth: w,
116
+ closeSidecar: n.closeSidecar,
117
+ renderSidecar: R
118
+ };
119
+ }, [n, r]);
120
+ return { ...r, ...c };
121
+ }
122
+ const ce = Z(null), j = () => ee(ce);
123
+ function ft() {
124
+ const e = j();
125
+ if (!e)
126
+ throw new Error("useShortRoundToast needs a <ShortRoundProvider theme={…}> above it");
127
+ return { showToast: e.showToast };
128
+ }
129
+ function X(e) {
130
+ (e.querySelector("[cmdk-input]") ?? e).focus();
131
+ }
132
+ function Ee() {
133
+ const e = m(null), t = m(null), n = _((r) => {
134
+ if (r) {
135
+ t.current = document.activeElement, e.current = r, X(r);
136
+ return;
137
+ }
138
+ const c = e.current, s = t.current;
139
+ e.current = null, t.current = null;
140
+ const a = document.activeElement;
141
+ (!a || a === document.body || c?.contains(a)) && s && s !== document.body && s.isConnected && s.focus();
142
+ }, []), o = _(() => {
143
+ e.current && X(e.current);
144
+ }, []);
145
+ return { attachDialog: n, focusInside: o };
146
+ }
147
+ const Te = { subscribe: () => () => {
148
+ }, getState: () => null };
149
+ function Ce({ palette: e, disableLineHints: t, store: n }) {
150
+ const o = typeof e?.commandLine == "function" && !t, r = o ? n.commandLine() : null, c = r ?? Te, s = H(c.subscribe, c.getState, c.getState);
151
+ return { canShowHints: o, lineState: r ? s : null, complete: () => !n.commandLine() || !n.completeFirst() ? null : n.commandLine()?.getState().caret ?? null };
152
+ }
153
+ const Le = new Set(Object.values(me)), J = (e, t) => t[e] ?? t.unknown, A = (e, t) => e ? ge(e, t) : void 0;
154
+ function xe(e, { registry: t = {}, themeIcons: n = {} }) {
155
+ const o = t.intentions?.[e.id];
156
+ if (o)
157
+ return A(o);
158
+ if (!e.icon)
159
+ return;
160
+ if (Le.has(e.id))
161
+ return A(J(e.icon, n));
162
+ const r = t.names?.[e.icon] ?? e.icon;
163
+ return t.Icon ? A(t.Icon, { name: r }) : A(J(r, n));
164
+ }
165
+ const Pe = [
166
+ "fontFamily",
167
+ "fontSize",
168
+ "fontWeight",
169
+ "fontStyle",
170
+ "lineHeight",
171
+ "letterSpacing",
172
+ "textIndent",
173
+ "paddingTop",
174
+ "paddingRight",
175
+ "paddingBottom",
176
+ "paddingLeft",
177
+ "borderTopWidth",
178
+ "borderRightWidth",
179
+ "borderBottomWidth",
180
+ "borderLeftWidth"
181
+ ];
182
+ function De({ children: e, inputRef: t, lineState: n }) {
183
+ const o = m(null), r = !!n;
184
+ return L(() => {
185
+ const c = t.current, s = o.current;
186
+ if (!c)
187
+ return;
188
+ if (!r) {
189
+ c.style.color = "", c.style.caretColor = "";
190
+ return;
191
+ }
192
+ Fe(c, s);
193
+ const a = () => {
194
+ s.scrollLeft = c.scrollLeft;
195
+ };
196
+ return a(), c.addEventListener("scroll", a), () => c.removeEventListener("scroll", a);
197
+ }), /* @__PURE__ */ O("div", { "data-testid": "shortround-line-input", style: Ae, children: [
198
+ r && /* @__PURE__ */ i("div", { "aria-hidden": !0, "data-testid": "shortround-line-shadow", ref: o, style: _e, children: /* @__PURE__ */ i(We, { state: n }) }),
199
+ e
200
+ ] });
201
+ }
202
+ const Ae = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0 }, _e = {
203
+ position: "absolute",
204
+ pointerEvents: "none",
205
+ whiteSpace: "pre",
206
+ overflow: "hidden",
207
+ borderStyle: "solid",
208
+ borderColor: "transparent",
209
+ // The shadow is sized from the input's offset box, which includes padding and border.
210
+ boxSizing: "border-box"
211
+ };
212
+ function Fe(e, t) {
213
+ const n = window.getComputedStyle(e);
214
+ e.style.color !== "transparent" && (t.style.color = n.color, e.style.caretColor = n.color, e.style.color = "transparent"), Pe.forEach((o) => {
215
+ t.style[o] = n[o];
216
+ }), Object.assign(t.style, {
217
+ left: `${e.offsetLeft}px`,
218
+ top: `${e.offsetTop}px`,
219
+ width: `${e.offsetWidth}px`,
220
+ height: `${e.offsetHeight}px`
221
+ });
222
+ }
223
+ function We({ state: e }) {
224
+ const t = [];
225
+ let n = 0;
226
+ for (const o of e.roles)
227
+ o.start > n && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n, o.start) }, `gap-${n}`)), t.push(
228
+ /* @__PURE__ */ i("span", { "data-role": o.role, title: o.reason, children: e.text.slice(o.start, o.end) }, o.start)
229
+ ), n = o.end;
230
+ return n < e.text.length && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n) }, `tail-${n}`)), /* @__PURE__ */ O(ye, { children: [
231
+ t,
232
+ e.ghost && /* @__PURE__ */ i("span", { "data-role": "ghost", children: e.ghost })
233
+ ] });
234
+ }
235
+ const Ne = "Type a intention or search...", Ge = { display: "flex", flexDirection: "column" }, $e = { order: -1 }, ze = "shortround::navigate", He = "shortround::no-group";
236
+ function Ke(e) {
237
+ const t = document.activeElement;
238
+ e && t !== e && e.closest("[cmdk-root]")?.contains(t) && e.focus();
239
+ }
240
+ function Ve({ intention: e, onSelect: t, Item: n, iconSources: o }) {
241
+ const r = te((c) => c.value) === e.id.trim();
242
+ return /* @__PURE__ */ i(
243
+ E.Item,
244
+ {
245
+ "data-testid": `shortround-item-${e.id}`,
246
+ disabled: e.disabled,
247
+ keywords: e.keywords,
248
+ onSelect: () => t(e.id),
249
+ value: e.id,
250
+ children: /* @__PURE__ */ i(
251
+ n,
252
+ {
253
+ icon: xe(e, o),
254
+ intention: e,
255
+ isSelected: r
256
+ }
257
+ )
258
+ }
259
+ );
260
+ }
261
+ const Ue = (e) => e.reduce((t, n) => {
262
+ const o = n.group ?? void 0;
263
+ let r = t.find((c) => c.name === o);
264
+ return r || (r = { name: o, intentions: [] }, t.push(r)), r.intentions.push(n), t;
265
+ }, []);
266
+ function je({ groupRef: e, rowIds: t }) {
267
+ const n = te((r) => r.value), o = t.includes(n);
268
+ return T(() => {
269
+ if (!o)
270
+ return;
271
+ const r = requestAnimationFrame(
272
+ () => e.current?.scrollIntoView({ block: "nearest" })
273
+ );
274
+ return () => cancelAnimationFrame(r);
275
+ }, [n, o, e]), null;
276
+ }
277
+ function Ye(e) {
278
+ const t = m(null);
279
+ return L(() => {
280
+ t.current !== null && e.current && (e.current.setSelectionRange(t.current, t.current), t.current = null);
281
+ }), t;
282
+ }
283
+ function Me({
284
+ palette: e,
285
+ defaultIntentions: t,
286
+ resolveDefaultInput: n,
287
+ resolveDefaultFallbackInput: o,
288
+ defaultSidecarRenderer: r,
289
+ IntentionPalette: c,
290
+ iconSources: s = {},
291
+ showToast: a,
292
+ label: d,
293
+ disableLineHints: h = !1
294
+ }) {
295
+ const { store: l, state: p, intentions: w } = ne({
296
+ palette: e,
297
+ defaultIntentions: t,
298
+ resolveDefaultInput: n,
299
+ resolveDefaultFallbackInput: o
300
+ }), { inputValue: v, inputMessage: y, revertIntentions: R } = p, { height: f, onClose: k } = U(), I = W(), S = m(null), x = m(null), N = Ye(S), C = Ce({ palette: e, disableLineHints: h, store: l }), G = F(() => Ue(w), [w]), $ = p.highlightedId?.trim() ?? "", z = (u) => {
301
+ const g = [...w, ...R].find(({ id: b }) => b.trim() === u);
302
+ l.highlight(g?.id ?? u);
303
+ }, P = (u) => l.changeInput(u, S.current?.selectionStart), se = (u) => {
304
+ const { value: g, selectionStart: b } = u.target, D = l.commandLine()?.getState();
305
+ D && g === l.getState().inputValue && D.caret !== b && l.changeInput(g, b);
306
+ }, ie = () => {
307
+ const u = C.complete();
308
+ return u !== null ? (N.current = u, !0) : l.completeFirst();
309
+ }, ae = (u) => {
310
+ u.key === "Tab" && ie() && (u.preventDefault(), S.current?.focus());
311
+ }, ue = async (u) => {
312
+ Ke(S.current);
313
+ const g = await l.select(u, { sidekickStore: I, defaultSidecarRenderer: r });
314
+ if (g.isCompletion) {
315
+ S.current?.focus();
316
+ return;
317
+ }
318
+ g.isRejected || (g.message && a?.({ message: g.message }), g.shouldReset && k());
319
+ }, Y = /* @__PURE__ */ i(
320
+ E.Input,
321
+ {
322
+ "data-testid": "shortround-input",
323
+ onKeyDown: ae,
324
+ onSelect: se,
325
+ onValueChange: P,
326
+ placeholder: Ne,
327
+ ref: S,
328
+ value: v
329
+ }
330
+ ), le = C.canShowHints ? /* @__PURE__ */ i(De, { inputRef: S, lineState: C.lineState, children: Y }) : Y, M = ({ key: u, name: g, intentions: b, style: D, ref: de }) => /* @__PURE__ */ O(E.Group, { ref: de, style: D, children: [
331
+ /* @__PURE__ */ i(c.Group, { name: g }),
332
+ b.map((B) => /* @__PURE__ */ i(
333
+ Ve,
334
+ {
335
+ Item: c.Item,
336
+ iconSources: s,
337
+ intention: B,
338
+ onSelect: ue
339
+ },
340
+ B.id
341
+ ))
342
+ ] }, u);
343
+ return /* @__PURE__ */ i(c.Frame, { height: f, children: /* @__PURE__ */ O(
344
+ E,
345
+ {
346
+ label: d,
347
+ loop: !0,
348
+ onValueChange: z,
349
+ shouldFilter: !1,
350
+ value: $,
351
+ children: [
352
+ /* @__PURE__ */ i(c.Input, { input: le, inputMessage: y }),
353
+ /* @__PURE__ */ O(
354
+ E.List,
355
+ {
356
+ style: {
357
+ height: `calc(${f} - 107px)`,
358
+ // not sure why 107 works
359
+ overflowY: "auto",
360
+ padding: "8px 0"
361
+ },
362
+ children: [
363
+ /* @__PURE__ */ i(E.Empty, { children: /* @__PURE__ */ i(c.NoMatches, { inputValue: v }) }),
364
+ /* @__PURE__ */ O("div", { style: Ge, children: [
365
+ G.map((u) => M({ key: u.name ?? He, ...u })),
366
+ R.length > 0 && M({
367
+ key: ze,
368
+ name: pe,
369
+ intentions: R,
370
+ style: $e,
371
+ ref: x
372
+ })
373
+ ] })
374
+ ]
375
+ }
376
+ ),
377
+ /* @__PURE__ */ i(
378
+ je,
379
+ {
380
+ groupRef: x,
381
+ rowIds: R.map(({ id: u }) => u)
382
+ }
383
+ )
384
+ ]
385
+ }
386
+ ) });
387
+ }
388
+ function Be({
389
+ title: e,
390
+ palette: t,
391
+ defaultIntentions: n,
392
+ resolveDefaultInput: o,
393
+ resolveDefaultFallbackInput: r,
394
+ SidekickComponents: c,
395
+ showToast: s,
396
+ defaultSidecarRenderer: a,
397
+ disableLineHints: d
398
+ }) {
399
+ const { onClose: h, setSize: l, anchorOrigin: p, cycleAnchorOrigin: w, height: v, size: y, commandWidth: R } = U(), { Sidekick: f, IntentionPalette: k } = c, I = j()?.icons, S = F(
400
+ () => ({ registry: I, themeIcons: c.icons }),
401
+ [I, c.icons]
402
+ );
403
+ return /* @__PURE__ */ i(K.div, { layout: !0, transition: { duration: V, ease: "easeInOut" }, children: /* @__PURE__ */ O(f.Frame, { commandWidth: R, height: v, children: [
404
+ /* @__PURE__ */ i(
405
+ f.ControlBar,
406
+ {
407
+ anchorOrigin: p,
408
+ cycleAnchorOrigin: w,
409
+ labels: Se,
410
+ onClose: h,
411
+ setSize: l,
412
+ size: y,
413
+ title: e
414
+ }
415
+ ),
416
+ y !== "compact" && /* @__PURE__ */ i(
417
+ Me,
418
+ {
419
+ IntentionPalette: k,
420
+ defaultIntentions: n,
421
+ defaultSidecarRenderer: a,
422
+ disableLineHints: d,
423
+ iconSources: S,
424
+ label: e ?? oe,
425
+ palette: t,
426
+ resolveDefaultFallbackInput: r,
427
+ resolveDefaultInput: o,
428
+ showToast: s
429
+ }
430
+ )
431
+ ] }) });
432
+ }
433
+ function qe({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
434
+ const c = {
435
+ open: { width: o, pointerEvents: "auto" },
436
+ closed: { width: 0, pointerEvents: "none" }
437
+ };
438
+ return /* @__PURE__ */ i(
439
+ K.div,
440
+ {
441
+ animate: e ? "open" : "closed",
442
+ layout: !0,
443
+ style: { display: "flex", overflow: "hidden", opacity: 1 },
444
+ transition: { duration: V, ease: "easeInOut" },
445
+ variants: c,
446
+ children: /* @__PURE__ */ i(r, { height: n, isOpen: e, renderSidecar: t })
447
+ }
448
+ );
449
+ }
450
+ function Xe(e, t) {
451
+ const n = m(e), o = m(t);
452
+ o.current = t, T(() => {
453
+ n.current && !e && o.current?.(), n.current = e;
454
+ }, [e]);
455
+ }
456
+ function Je(e, t, { sidecarReducer: n, defaultSidecarRenderer: o, palette: r }) {
457
+ const c = m(n);
458
+ c.current = n;
459
+ const s = m(!1), a = () => r ? r.current().sidecarRenderer : o, d = m(a);
460
+ d.current = a, L(() => (e.setSidecarReducer(
461
+ (...h) => (c.current ?? ((l, p) => p))(...h)
462
+ ), () => e.setSidecarReducer(void 0)), [e]), L(() => {
463
+ t && !s.current ? e.changeSidecar({ renderer: d.current() ?? null }, "open") : !t && s.current && e.clearSidecar(), s.current = t;
464
+ }, [e, t]);
465
+ }
466
+ function Qe(e, t) {
467
+ L(() => {
468
+ document.activeElement === document.body && t();
469
+ }, [e, t]);
470
+ }
471
+ const Ze = {
472
+ display: "flex",
473
+ flexDirection: "inherit",
474
+ alignItems: "inherit",
475
+ width: "100%",
476
+ height: "100%"
477
+ }, et = we(function({ name: t, onClose: n, children: o }, r) {
478
+ return /* @__PURE__ */ i(
479
+ "div",
480
+ {
481
+ "aria-label": t,
482
+ "aria-modal": "false",
483
+ onKeyDown: (s) => {
484
+ s.key === "Escape" && !s.defaultPrevented && n();
485
+ },
486
+ ref: r,
487
+ role: "dialog",
488
+ style: Ze,
489
+ tabIndex: -1,
490
+ children: o
491
+ }
492
+ );
493
+ });
494
+ function tt({
495
+ title: e,
496
+ palette: t,
497
+ defaultIntentions: n,
498
+ resolveDefaultInput: o,
499
+ resolveDefaultFallbackInput: r,
500
+ SidekickComponents: c,
501
+ showToast: s,
502
+ installKeyboardShortcuts: a,
503
+ notifyClose: d,
504
+ sidecarReducer: h,
505
+ defaultSidecarRenderer: l,
506
+ disableLineHints: p
507
+ }) {
508
+ const {
509
+ isSidecarOpen: w,
510
+ anchorOrigin: v,
511
+ renderSidecar: y,
512
+ height: R,
513
+ sidecarWidth: f,
514
+ isOpen: k,
515
+ anchorPosition: I,
516
+ totalWidth: S,
517
+ size: x,
518
+ onOpen: N,
519
+ onClose: C
520
+ } = U(), { Sidekick: G, SidecarContent: $ } = c, { attachDialog: z, focusInside: P } = Ee();
521
+ return Ie({
522
+ onOpen: k ? P : N,
523
+ installKeyboardShortcuts: a
524
+ }), Qe(x, P), Xe(k, d), Je(W(), k, {
525
+ sidecarReducer: h,
526
+ defaultSidecarRenderer: l,
527
+ palette: t
528
+ }), k ? /* @__PURE__ */ i(
529
+ K.div,
530
+ {
531
+ animate: {
532
+ width: S
533
+ },
534
+ layout: !0,
535
+ transition: { duration: V, ease: "easeInOut" },
536
+ children: /* @__PURE__ */ i(
537
+ G.Popover,
538
+ {
539
+ anchorOrigin: v,
540
+ anchorPosition: I,
541
+ height: R,
542
+ totalWidth: S,
543
+ children: /* @__PURE__ */ O(et, { name: e ?? oe, onClose: C, ref: z, children: [
544
+ /* @__PURE__ */ i(
545
+ Be,
546
+ {
547
+ SidekickComponents: c,
548
+ defaultIntentions: n,
549
+ defaultSidecarRenderer: l,
550
+ disableLineHints: p,
551
+ palette: t,
552
+ resolveDefaultFallbackInput: r,
553
+ resolveDefaultInput: o,
554
+ showToast: s,
555
+ title: e
556
+ }
557
+ ),
558
+ /* @__PURE__ */ i(
559
+ qe,
560
+ {
561
+ Content: $,
562
+ height: R,
563
+ isOpen: w,
564
+ renderSidecar: y,
565
+ width: f
566
+ }
567
+ )
568
+ ] })
569
+ }
570
+ )
571
+ }
572
+ ) : null;
573
+ }
574
+ function nt(e, t) {
575
+ const n = j(), o = e ?? n?.components;
576
+ if (!o)
577
+ throw new Error(
578
+ "ShortRoundSidekick has no theme: wrap the app in <ShortRoundProvider theme={…}>, or pass SidekickComponents"
579
+ );
580
+ return { components: o, showToast: t ?? n?.showToast };
581
+ }
582
+ function mt({
583
+ title: e,
584
+ palette: t,
585
+ defaultIntentions: n,
586
+ resolveDefaultInput: o,
587
+ resolveDefaultFallbackInput: r,
588
+ SidekickComponents: c,
589
+ showToast: s,
590
+ installKeyboardShortcuts: a,
591
+ sidekickStore: d,
592
+ initialSidekickState: h,
593
+ onClose: l,
594
+ sidecarReducer: p,
595
+ defaultSidecarRenderer: w,
596
+ disableLineHints: v
597
+ }) {
598
+ const y = nt(c, s);
599
+ return /* @__PURE__ */ i(be, { initial: h, store: d, children: /* @__PURE__ */ i(
600
+ tt,
601
+ {
602
+ SidekickComponents: y.components,
603
+ defaultIntentions: n,
604
+ defaultSidecarRenderer: w,
605
+ disableLineHints: v,
606
+ installKeyboardShortcuts: a,
607
+ notifyClose: l,
608
+ palette: t,
609
+ resolveDefaultFallbackInput: r,
610
+ resolveDefaultInput: o,
611
+ showToast: y.showToast,
612
+ sidecarReducer: p,
613
+ title: e
614
+ }
615
+ ) });
616
+ }
617
+ const ot = { isOpen: !1, message: null }, rt = ["IntentionPalette", "Sidekick", "SidecarContent"];
618
+ function ct(e) {
619
+ const t = ["components", "Toast"].filter((o) => !e?.[o]);
620
+ if (t.length > 0)
621
+ throw new Error(`ShortRoundProvider: the theme has no ${t.join(" or ")}`);
622
+ const n = rt.filter((o) => !e.components[o]);
623
+ if (n.length > 0)
624
+ throw new Error(
625
+ `ShortRoundProvider: the theme has no ${n.map((o) => `components.${o}`).join(" or ")}`
626
+ );
627
+ }
628
+ function pt({ theme: e, icons: t, children: n }) {
629
+ ct(e);
630
+ const [o, r] = ve(ot), c = _(({ message: h }) => r({ isOpen: !0, message: h }), []), s = _(() => r((h) => ({ ...h, isOpen: !1 })), []), a = F(
631
+ () => ({ components: e.components, showToast: c, icons: t }),
632
+ [e.components, c, t]
633
+ ), { Toast: d } = e;
634
+ return /* @__PURE__ */ O(ce.Provider, { value: a, children: [
635
+ n,
636
+ /* @__PURE__ */ i(d, { isOpen: o.isOpen, message: o.message, onClose: s })
637
+ ] });
638
+ }
639
+ export {
640
+ pt as ShortRoundProvider,
641
+ mt as ShortRoundSidekick,
642
+ be as SidekickStoreProvider,
643
+ ht as useShortRound,
644
+ ft as useShortRoundToast,
645
+ U as useSidekick,
646
+ W as useSidekickStore
647
+ };