@shortround/react 0.5.0 → 0.7.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,37 @@
1
1
  # @shortround/react
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - The palette follows core's Enter rule: with no row highlighted, Enter goes to the store (`pressEnter()`), so a line
8
+ that reads two ways, or held free text, runs nothing until the user picks a row, and a `confirm` command asks on the
9
+ first Enter and runs on the second. The arrows and the pointer still pick a row. See MIGRATING.md, 0.7.0.
10
+ - The palette passes the store's `enterLine` (what Enter will do) to the theme's `IntentionPalette.Input` slot; its
11
+ props type gains `enterLine`.
12
+ - The palette's list leaves room for whatever grows above it (the theme's input with its Enter line), so its last
13
+ row isn't cut off. The theme's `Input` slot now renders inside a `<div>` the palette measures; a theme whose input
14
+ relied on being a direct child of the list's container may need its styles moved to that slot's own root.
15
+ - Takes `@shortround/core` `^0.7.0` as a peer.
16
+
17
+ ## 0.6.0
18
+
19
+ ### Breaking Changes
20
+
21
+ - `ShortRoundProvider` needs only `components` and `Toast`. It no longer refuses a theme without `IntentionPalette`,
22
+ `Sidekick` or `SidecarContent`; `ShortRoundSidekick` throws when it mounts instead, naming the groups it misses
23
+ (`ShortRoundSidekick: the theme has no components.Sidekick`). A theme for an app that draws only the chat has `Chat`
24
+ and a `Toast`.
25
+ - Types: `ShortRoundTheme.components` is `Partial<SidekickComponents>` with other groups allowed. Under `strict`, code
26
+ that reads a group off a value typed `ShortRoundTheme` (`theme.components.Sidekick.Frame`) needs a check or `!`.
27
+
28
+ ### Minor Changes
29
+
30
+ - `LineInput`: an input with the typed line drawn under it (each word's role, and the ghost), for a host's own input.
31
+ - `useShortRoundComponents()`: the nearest provider's slots, or `null` without one, for a package that draws through
32
+ slot groups of its own (`@shortround/chat`'s `Chat`).
33
+ - Takes `@shortround/core` `^0.6.0` as a peer.
34
+
3
35
  ## 0.5.0
4
36
 
5
37
  ### Major Changes
package/README.md CHANGED
@@ -42,9 +42,14 @@ root.render(
42
42
  const { showToast } = useShortRoundToast(); // shows a toast in the theme's Toast
43
43
  ```
44
44
 
45
- - A theme is `{ components, Toast }`: the `SidekickComponents` slots and a Toast view. The provider holds the
46
- toast's state; the theme only draws it. Define the theme at module scope (or memoize it): a theme object built
47
- on every render remounts its Toast.
45
+ - A theme is `{ components, Toast }`: slot groups and a Toast view. The provider holds the toast's state; the theme
46
+ only draws it. Define the theme at module scope (or memoize it): a Toast or slot component created during render
47
+ remounts on every render.
48
+ - Each slot group is needed only by what draws it. `ShortRoundSidekick` needs `IntentionPalette`, `Sidekick` and
49
+ `SidecarContent`, and throws when it mounts, naming any it misses; `@shortround/chat`'s chat needs `Chat`. So an app
50
+ that draws only the chat gives a theme with `Chat` and a `Toast`.
51
+ - `useShortRoundComponents()` gives the nearest provider's `theme.components` (or `null`), for a package that draws
52
+ through a slot group of its own.
48
53
  - An action's `message` is shown as a toast.
49
54
  - A nested `ShortRoundProvider` wins for its subtree.
50
55
  - `ShortRoundSidekick`'s `SidekickComponents` and `showToast` props (the 0.2.x way to choose a look) override the provider; each prop
@@ -84,6 +89,11 @@ the input's position and text style. A theme's `data-role` rules should change o
84
89
  words sit under the input's own text, so anything that changes a word's width (weight, size, font, letter spacing)
85
90
  moves the words after it away from the caret.
86
91
 
92
+ On a typed line, the `IntentionPalette.Input` slot also receives `enterLine`: what Enter will do, in the catalog's
93
+ names ("↵ search grid", "↑↓ Choose …, then ↵", "Confirm: queue all?"; core's README, "The Enter line"). Show it
94
+ apart from `inputMessage`, each of its `words` in a `span` with `data-role` when it has a `role`, so the same rules
95
+ colour it as the input's words. It follows the highlight: after the arrows, it says what the row they moved to runs.
96
+
87
97
  ## Icons
88
98
 
89
99
  An intention's `icon` is a name. Without anything more, the theme draws its own icon for that name (see the theme's
@@ -168,7 +178,10 @@ so it can't be typed in while that modal is open; give the modal `disableEnforce
168
178
  the sidekick (a widget in the side panel) sees Escape first and can keep it with `event.preventDefault()`.
169
179
  - **Enter** runs the highlighted row. After every new list the highlight is on the list's first enabled row of your
170
180
  own, so the first Enter in a picker or a typed-text prompt runs it rather than Back. On a completion row (see Typed
171
- input), Enter completes the input instead of running anything.
181
+ input), Enter completes the input instead of running anything. On a typed line, core's Enter rule decides first.
182
+ A line that reads several ways, a command declared `confirm`, or free text not declared `asTyped` leaves no row
183
+ highlighted. Enter then runs nothing, or for a `confirm` command asks, so the next Enter runs it. An arrow or the
184
+ pointer highlights a row, and Enter runs it.
172
185
  - **Tab**, with a catalog palette, first completes through the line (see Line hints). Otherwise it completes the input
173
186
  with the first enabled completion row, when the list has one; otherwise Tab moves focus as usual.
174
187
  - **Arrow keys** move through the rows and wrap around at either end. Back and Cancel, when a list shows them, are
@@ -337,6 +350,40 @@ const sendAsChat = (text, { matches }) =>
337
350
  changes (such as whether the chat shows) when the fallback runs, through a ref or a store, rather than closing over
338
351
  it. One that throws adds no rows and logs why.
339
352
 
353
+ ### Line hints in your own input: LineInput
354
+
355
+ The sidekick's input shows each typed word coloured by its role and the rest of the next word as ghost text. A host
356
+ with its own input (a chat, an editor's command field) gets the same drawing with `LineInput`: wrap the input, pass
357
+ its ref, and pass a command line's state. The input stays on top with its text made transparent, so typing, the caret
358
+ and selection stay native.
359
+
360
+ ```jsx
361
+ import { useRef, useSyncExternalStore } from 'react';
362
+ import { LineInput } from '@shortround/react';
363
+
364
+ function CommandField({ line }) {
365
+ // line: a command line from @shortround/core (palette.commandLine(), or runtime.commandLine())
366
+ const inputRef = useRef(null);
367
+ const lineState = useSyncExternalStore(line.subscribe, line.getState);
368
+ return (
369
+ <LineInput inputRef={inputRef} lineState={lineState}>
370
+ <input
371
+ ref={inputRef}
372
+ value={lineState.text}
373
+ onChange={(event) => line.change(event.target.value, event.target.selectionStart)}
374
+ />
375
+ </LineInput>
376
+ );
377
+ }
378
+ ```
379
+
380
+ - Each word is a `<span data-role="…">` (`verb`, `text`, `hint`, `param`, `value`, `unread`, `broken`) and the ghost a
381
+ `<span data-role="ghost">`, inside `data-testid="shortround-line-shadow"`. Colour them in your stylesheet.
382
+ - The line is drawn on one line. Pass `lineState={null}` while the text has a line break (a `<textarea>`), and the
383
+ input shows as it is.
384
+ - A chat line's state should go through core's `drawnLineState`, so a line that reads as chat isn't drawn as a broken
385
+ command.
386
+
340
387
  `@shortround/core`'s catalog engine (`loadCatalog`, `buildPalette`) builds the intentions, the resolver and (given
341
388
  one) the fallback from a YAML catalog: see its
342
389
  [CATALOG.md](https://github.com/csepulv/shortround/tree/main/packages/shortround-core/CATALOG.md).
@@ -438,10 +485,19 @@ const SIZES = ['compact', 'medium', 'full'];
438
485
  const MySidekickComponents = {
439
486
  IntentionPalette: {
440
487
  Frame: ({ height, children }) => <div style={{ height }}>{children}</div>,
441
- // `input` is ShortRound's input element; place it.
442
- Input: ({ input, inputMessage }) => (
488
+ // `input` is ShortRound's input element; place it. `enterLine` says what Enter will do, on a typed line.
489
+ Input: ({ input, inputMessage, enterLine }) => (
443
490
  <div>
444
491
  {input}
492
+ {enterLine && (
493
+ <p>
494
+ {enterLine.words.map((word, index) => (
495
+ <span data-role={word.role} key={index}>
496
+ {word.text}
497
+ </span>
498
+ ))}
499
+ </p>
500
+ )}
445
501
  {inputMessage && <p>{inputMessage.text}</p>}
446
502
  </div>
447
503
  ),
package/dist/react.es.js CHANGED
@@ -1,38 +1,38 @@
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({
1
+ import { createPaletteStore as ve, createSidekickStore as ne, cycleCorners as ye, RevertIntentionIds as ke, isEnterWaiting as Ee, NAVIGATE_GROUP as Oe, ControlLabels as Ie } from "@shortround/core";
2
+ import { useRef as d, useSyncExternalStore as U, useEffect as L, createContext as oe, useContext as re, useMemo as H, useCallback as G, useState as V, useLayoutEffect as x, createElement as be, forwardRef as Ce } from "react";
3
+ import { jsx as i, jsxs as k, Fragment as Te } from "react/jsx-runtime";
4
+ import Le from "tiny-invariant";
5
+ import { motion as Y } from "framer-motion";
6
+ import { Command as T, useCommandState as se } from "cmdk";
7
+ function ce({
8
8
  palette: e,
9
9
  defaultIntentions: t,
10
10
  resolveDefaultInput: n,
11
11
  resolveDefaultFallbackInput: o
12
12
  }) {
13
- const r = m(null);
14
- r.current || (r.current = he({
13
+ const r = d(null);
14
+ r.current || (r.current = ve({
15
15
  palette: e,
16
16
  defaultIntentions: t,
17
17
  resolveDefaultInput: n,
18
18
  resolveDefaultFallbackInput: o
19
19
  }));
20
- const c = r.current, s = H(c.subscribe, c.getState, c.getState);
21
- return T(() => {
22
- c.setDefaults({
20
+ const s = r.current, c = U(s.subscribe, s.getState, s.getState);
21
+ return L(() => {
22
+ s.setDefaults({
23
23
  palette: e,
24
24
  defaultIntentions: t,
25
25
  resolveDefaultInput: n,
26
26
  resolveDefaultFallbackInput: o
27
27
  });
28
- }, [c, e, t, n, o]), T(() => c.watchResolver(), [c]), T(() => c.watchPalette(), [c, e]), { store: c, state: s, intentions: c.rows() };
28
+ }, [s, e, t, n, o]), L(() => s.watchResolver(), [s]), L(() => s.watchPalette(), [s, e]), { store: s, state: c, intentions: s.rows() };
29
29
  }
30
- function ht({
30
+ function Tt({
31
31
  defaultIntentions: e,
32
32
  resolveDefaultInput: t,
33
33
  resolveDefaultFallbackInput: n
34
34
  }) {
35
- const { store: o, state: r, intentions: c } = ne({
35
+ const { store: o, state: r, intentions: s } = ce({
36
36
  defaultIntentions: e,
37
37
  resolveDefaultInput: t,
38
38
  resolveDefaultFallbackInput: n
@@ -41,15 +41,15 @@ function ht({
41
41
  inputValue: r.inputValue,
42
42
  inputMessage: r.inputMessage,
43
43
  onInputChange: o.changeInput,
44
- intentions: c,
44
+ intentions: s,
45
45
  revertIntentions: r.revertIntentions,
46
- dispatch: (s) => o.select(s),
46
+ dispatch: (c) => o.select(c),
47
47
  reset: o.reset,
48
48
  back: o.back,
49
49
  dispatchedStack: r.dispatchedStack
50
50
  };
51
51
  }
52
- const V = 0.35, Oe = "100vh", ke = Object.freeze({
52
+ const j = 0.35, xe = "100vh", Ae = Object.freeze({
53
53
  center: { top: "50%", left: "50%", transform: "translate(-50%, -50%)" },
54
54
  "top-left": { top: 0, left: 0 },
55
55
  top: { top: 0, left: "50%", transform: "translateX(-50%)" },
@@ -59,13 +59,13 @@ const V = 0.35, Oe = "100vh", ke = Object.freeze({
59
59
  "bottom-right": { bottom: 0, right: 0 },
60
60
  bottom: { bottom: 0, left: "50%", transform: "translateX(-50%)" },
61
61
  "bottom-left": { bottom: 0, left: 0 }
62
- }), q = Object.freeze({
62
+ }), Z = Object.freeze({
63
63
  compact: { height: "auto" },
64
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(() => {
65
+ full: { height: xe }
66
+ }), ie = "ShortRound", _e = ({ onOpen: e, installKeyboardShortcuts: t = !0 }) => {
67
+ const n = d({ onOpen: e });
68
+ n.current = { onOpen: e }, L(() => {
69
69
  if (!t)
70
70
  return;
71
71
  const o = (r) => {
@@ -73,96 +73,111 @@ const V = 0.35, Oe = "100vh", ke = Object.freeze({
73
73
  };
74
74
  return document.addEventListener("keydown", o, { capture: !0 }), () => document.removeEventListener("keydown", o, { capture: !0 });
75
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 });
76
+ }, ae = oe(null), K = () => re(ae);
77
+ function De({ store: e, initial: t, children: n }) {
78
+ const o = K(), r = d(null);
79
+ !e && !o && !r.current && (r.current = ne(t));
80
+ const s = e ?? o ?? r.current;
81
+ return /* @__PURE__ */ i(ae.Provider, { value: s, children: n });
82
82
  }
83
- function U(e = {}) {
84
- const t = W();
83
+ function B(e = {}) {
84
+ const t = K();
85
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();
86
+ const o = d(null);
87
+ n || (o.current || (o.current = ne(e.initial)), n = o.current);
88
+ const r = U(n.subscribe, n.get, n.get), s = H(() => {
89
+ const { maxTotalWidth: c, commandWidth: a, anchorOrigin: f, internalSidecarRenderer: m, size: l } = r, { height: p } = Z[l], g = `calc(${c} - ${a})`, w = (h) => n.set({ anchorOrigin: h }), R = () => {
90
+ w(ye(f));
91
+ }, E = () => {
92
+ if (m)
93
+ return m();
94
94
  };
95
95
  return {
96
96
  // Worked out from the origin, so a store created with only `anchorOrigin` opens there; a position stored
97
97
  // beside it (a 0.3.0 workaround) is ignored.
98
- anchorPosition: ke[d],
98
+ anchorPosition: Ae[f],
99
99
  onOpen: () => n.set({ isOpen: !0 }),
100
- setIsOpen: (f) => {
101
- n.set({ isOpen: f });
100
+ setIsOpen: (h) => {
101
+ n.set({ isOpen: h });
102
102
  },
103
103
  onClose: () => {
104
104
  n.clearSidecar(), n.set({ isOpen: !1 });
105
105
  },
106
106
  height: p,
107
- setSize: (f) => {
108
- Re(q[f], `Unknown size: ${f}`), n.set({ size: f });
107
+ setSize: (h) => {
108
+ Le(Z[h], `Unknown size: ${h}`), n.set({ size: h });
109
109
  },
110
- setAnchorOrigin: v,
111
- cycleAnchorOrigin: y,
110
+ setAnchorOrigin: w,
111
+ cycleAnchorOrigin: R,
112
112
  // The app's own calls: through the reducer, with the reason `app`.
113
113
  setSidecarRenderer: n.openSidecar,
114
114
  commandWidth: a,
115
- sidecarWidth: w,
115
+ sidecarWidth: g,
116
116
  closeSidecar: n.closeSidecar,
117
- renderSidecar: R
117
+ renderSidecar: E
118
118
  };
119
119
  }, [n, r]);
120
- return { ...r, ...c };
120
+ return { ...r, ...s };
121
121
  }
122
- const ce = Z(null), j = () => ee(ce);
123
- function ft() {
124
- const e = j();
122
+ const ue = oe(null), M = () => re(ue), Lt = () => M()?.components ?? null;
123
+ function xt() {
124
+ const e = M();
125
125
  if (!e)
126
126
  throw new Error("useShortRoundToast needs a <ShortRoundProvider theme={…}> above it");
127
127
  return { showToast: e.showToast };
128
128
  }
129
- function X(e) {
129
+ function ee(e) {
130
130
  (e.querySelector("[cmdk-input]") ?? e).focus();
131
131
  }
132
- function Ee() {
133
- const e = m(null), t = m(null), n = _((r) => {
132
+ function Pe() {
133
+ const e = d(null), t = d(null), n = G((r) => {
134
134
  if (r) {
135
- t.current = document.activeElement, e.current = r, X(r);
135
+ t.current = document.activeElement, e.current = r, ee(r);
136
136
  return;
137
137
  }
138
- const c = e.current, s = t.current;
138
+ const s = e.current, c = t.current;
139
139
  e.current = null, t.current = null;
140
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);
141
+ (!a || a === document.body || s?.contains(a)) && c && c !== document.body && c.isConnected && c.focus();
142
+ }, []), o = G(() => {
143
+ e.current && ee(e.current);
144
144
  }, []);
145
145
  return { attachDialog: n, focusInside: o };
146
146
  }
147
- const Te = { subscribe: () => () => {
147
+ function We(e) {
148
+ const [t, n] = V(0), o = d(1 / 0);
149
+ return x(() => {
150
+ const r = e.current;
151
+ if (!r || typeof ResizeObserver > "u")
152
+ return;
153
+ const s = () => {
154
+ const a = r.offsetHeight;
155
+ o.current = Math.min(o.current, a), n(a - o.current);
156
+ };
157
+ s();
158
+ const c = new ResizeObserver(s);
159
+ return c.observe(r), () => c.disconnect();
160
+ }, [e]), t;
161
+ }
162
+ const Fe = { subscribe: () => () => {
148
163
  }, 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 };
164
+ function Ne({ palette: e, disableLineHints: t, store: n }) {
165
+ const o = typeof e?.commandLine == "function" && !t, r = o ? n.commandLine() : null, s = r ?? Fe, c = U(s.subscribe, s.getState, s.getState);
166
+ return { canShowHints: o, lineState: r ? c : null, complete: () => !n.commandLine() || !n.completeFirst() ? null : n.commandLine()?.getState().caret ?? null };
152
167
  }
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 = {} }) {
168
+ const Ge = new Set(Object.values(ke)), te = (e, t) => t[e] ?? t.unknown, N = (e, t) => e ? be(e, t) : void 0;
169
+ function He(e, { registry: t = {}, themeIcons: n = {} }) {
155
170
  const o = t.intentions?.[e.id];
156
171
  if (o)
157
- return A(o);
172
+ return N(o);
158
173
  if (!e.icon)
159
174
  return;
160
- if (Le.has(e.id))
161
- return A(J(e.icon, n));
175
+ if (Ge.has(e.id))
176
+ return N(te(e.icon, n));
162
177
  const r = t.names?.[e.icon] ?? e.icon;
163
- return t.Icon ? A(t.Icon, { name: r }) : A(J(r, n));
178
+ return t.Icon ? N(t.Icon, { name: r }) : N(te(r, n));
164
179
  }
165
- const Pe = [
180
+ const Ke = [
166
181
  "fontFamily",
167
182
  "fontSize",
168
183
  "fontWeight",
@@ -179,27 +194,27 @@ const Pe = [
179
194
  "borderBottomWidth",
180
195
  "borderLeftWidth"
181
196
  ];
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)
197
+ function Me({ children: e, inputRef: t, lineState: n }) {
198
+ const o = d(null), r = !!n;
199
+ return x(() => {
200
+ const s = t.current, c = o.current;
201
+ if (!s)
187
202
  return;
188
203
  if (!r) {
189
- c.style.color = "", c.style.caretColor = "";
204
+ s.style.color = "", s.style.caretColor = "";
190
205
  return;
191
206
  }
192
- Fe(c, s);
207
+ Ue(s, c);
193
208
  const a = () => {
194
- s.scrollLeft = c.scrollLeft;
209
+ c.scrollLeft = s.scrollLeft;
195
210
  };
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 }) }),
211
+ return a(), s.addEventListener("scroll", a), () => s.removeEventListener("scroll", a);
212
+ }), /* @__PURE__ */ k("div", { "data-testid": "shortround-line-input", style: $e, children: [
213
+ r && /* @__PURE__ */ i("div", { "aria-hidden": !0, "data-testid": "shortround-line-shadow", ref: o, style: ze, children: /* @__PURE__ */ i(Ve, { state: n }) }),
199
214
  e
200
215
  ] });
201
216
  }
202
- const Ae = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0 }, _e = {
217
+ const $e = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0 }, ze = {
203
218
  position: "absolute",
204
219
  pointerEvents: "none",
205
220
  whiteSpace: "pre",
@@ -209,9 +224,9 @@ const Ae = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0
209
224
  // The shadow is sized from the input's offset box, which includes padding and border.
210
225
  boxSizing: "border-box"
211
226
  };
212
- function Fe(e, t) {
227
+ function Ue(e, t) {
213
228
  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) => {
229
+ e.style.color !== "transparent" && (t.style.color = n.color, e.style.caretColor = n.color, e.style.color = "transparent"), Ke.forEach((o) => {
215
230
  t.style[o] = n[o];
216
231
  }), Object.assign(t.style, {
217
232
  left: `${e.offsetLeft}px`,
@@ -220,27 +235,27 @@ function Fe(e, t) {
220
235
  height: `${e.offsetHeight}px`
221
236
  });
222
237
  }
223
- function We({ state: e }) {
238
+ function Ve({ state: e }) {
224
239
  const t = [];
225
240
  let n = 0;
226
241
  for (const o of e.roles)
227
242
  o.start > n && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n, o.start) }, `gap-${n}`)), t.push(
228
243
  /* @__PURE__ */ i("span", { "data-role": o.role, title: o.reason, children: e.text.slice(o.start, o.end) }, o.start)
229
244
  ), 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: [
245
+ return n < e.text.length && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n) }, `tail-${n}`)), /* @__PURE__ */ k(Te, { children: [
231
246
  t,
232
247
  e.ghost && /* @__PURE__ */ i("span", { "data-role": "ghost", children: e.ghost })
233
248
  ] });
234
249
  }
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) {
250
+ const Ye = "Type a intention or search...", je = 107, Be = { display: "flex", flexDirection: "column" }, qe = { order: -1 }, Xe = "shortround::navigate", Je = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp", "Home", "End"]), Qe = /* @__PURE__ */ new Set(["n", "p", "j", "k"]), Ze = "shortround::no-row", et = (e) => Je.has(e.key) || e.ctrlKey && Qe.has(e.key), tt = (e) => e.nativeEvent.isComposing || e.keyCode === 229, nt = "shortround::no-group";
251
+ function ot(e) {
237
252
  const t = document.activeElement;
238
253
  e && t !== e && e.closest("[cmdk-root]")?.contains(t) && e.focus();
239
254
  }
240
- function Ve({ intention: e, onSelect: t, Item: n, iconSources: o }) {
241
- const r = te((c) => c.value) === e.id.trim();
255
+ function rt({ intention: e, onSelect: t, Item: n, iconSources: o }) {
256
+ const r = se((s) => s.value) === e.id.trim();
242
257
  return /* @__PURE__ */ i(
243
- E.Item,
258
+ T.Item,
244
259
  {
245
260
  "data-testid": `shortround-item-${e.id}`,
246
261
  disabled: e.disabled,
@@ -250,7 +265,7 @@ function Ve({ intention: e, onSelect: t, Item: n, iconSources: o }) {
250
265
  children: /* @__PURE__ */ i(
251
266
  n,
252
267
  {
253
- icon: xe(e, o),
268
+ icon: He(e, o),
254
269
  intention: e,
255
270
  isSelected: r
256
271
  }
@@ -258,14 +273,14 @@ function Ve({ intention: e, onSelect: t, Item: n, iconSources: o }) {
258
273
  }
259
274
  );
260
275
  }
261
- const Ue = (e) => e.reduce((t, n) => {
276
+ const st = (e) => e.reduce((t, n) => {
262
277
  const o = n.group ?? void 0;
263
- let r = t.find((c) => c.name === o);
278
+ let r = t.find((s) => s.name === o);
264
279
  return r || (r = { name: o, intentions: [] }, t.push(r)), r.intentions.push(n), t;
265
280
  }, []);
266
- function je({ groupRef: e, rowIds: t }) {
267
- const n = te((r) => r.value), o = t.includes(n);
268
- return T(() => {
281
+ function ct({ groupRef: e, rowIds: t }) {
282
+ const n = se((r) => r.value), o = t.includes(n);
283
+ return L(() => {
269
284
  if (!o)
270
285
  return;
271
286
  const r = requestAnimationFrame(
@@ -274,295 +289,316 @@ function je({ groupRef: e, rowIds: t }) {
274
289
  return () => cancelAnimationFrame(r);
275
290
  }, [n, o, e]), null;
276
291
  }
277
- function Ye(e) {
278
- const t = m(null);
279
- return L(() => {
292
+ function it(e) {
293
+ const t = d(null);
294
+ return x(() => {
280
295
  t.current !== null && e.current && (e.current.setSelectionRange(t.current, t.current), t.current = null);
281
296
  }), t;
282
297
  }
283
- function Me({
298
+ function at({
284
299
  palette: e,
285
300
  defaultIntentions: t,
286
301
  resolveDefaultInput: n,
287
302
  resolveDefaultFallbackInput: o,
288
303
  defaultSidecarRenderer: r,
289
- IntentionPalette: c,
290
- iconSources: s = {},
304
+ IntentionPalette: s,
305
+ iconSources: c = {},
291
306
  showToast: a,
292
- label: d,
293
- disableLineHints: h = !1
307
+ label: f,
308
+ disableLineHints: m = !1
294
309
  }) {
295
- const { store: l, state: p, intentions: w } = ne({
310
+ const { store: l, state: p, intentions: g } = ce({
296
311
  palette: e,
297
312
  defaultIntentions: t,
298
313
  resolveDefaultInput: n,
299
314
  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();
315
+ }), { inputValue: w, inputMessage: R, enterLine: E, revertIntentions: h } = p, { height: v, onClose: I } = B(), b = K(), y = d(null), P = d(null), $ = We(P), W = d(null), z = it(y), A = Ne({ palette: e, disableLineHints: m, store: l }), F = H(() => st(g), [g]), [le, de] = V(0), he = p.highlightedId?.trim() ?? `${Ze}:${le}`, _ = d(!1), q = () => {
316
+ _.current = !0, queueMicrotask(() => {
317
+ _.current = !1;
318
+ });
319
+ }, fe = (u) => {
320
+ const S = _.current;
321
+ _.current = !1;
322
+ const { enter: O } = l.getState();
323
+ if (O && Ee(O) && !S) {
324
+ de((D) => D + 1);
325
+ return;
326
+ }
327
+ const C = [...g, ...h].find(({ id: D }) => D.trim() === u);
328
+ l.highlight(C?.id ?? u);
329
+ }, me = (u) => {
330
+ _.current = !1, l.changeInput(u, y.current?.selectionStart);
331
+ }, pe = (u) => {
332
+ const { value: S, selectionStart: O } = u.target, C = l.commandLine()?.getState();
333
+ C && S === l.getState().inputValue && C.caret !== O && l.changeInput(S, O);
334
+ }, Se = () => {
335
+ const u = A.complete();
336
+ return u !== null ? (z.current = u, !0) : l.completeFirst();
337
+ }, ge = (u) => {
338
+ if (u.key === "Tab" && Se()) {
339
+ u.preventDefault(), y.current?.focus();
316
340
  return;
317
341
  }
318
- g.isRejected || (g.message && a?.({ message: g.message }), g.shouldReset && k());
319
- }, Y = /* @__PURE__ */ i(
320
- E.Input,
342
+ if (et(u)) {
343
+ q();
344
+ return;
345
+ }
346
+ u.key === "Enter" && !tt(u) && !l.getState().highlightedId && (u.preventDefault(), l.pressEnter());
347
+ }, we = async (u) => {
348
+ ot(y.current);
349
+ const S = await l.select(u, { sidekickStore: b, defaultSidecarRenderer: r });
350
+ if (S.isCompletion) {
351
+ y.current?.focus();
352
+ return;
353
+ }
354
+ S.isRejected || (S.message && a?.({ message: S.message }), S.shouldReset && I());
355
+ }, X = /* @__PURE__ */ i(
356
+ T.Input,
321
357
  {
322
358
  "data-testid": "shortround-input",
323
- onKeyDown: ae,
324
- onSelect: se,
325
- onValueChange: P,
326
- placeholder: Ne,
327
- ref: S,
328
- value: v
359
+ onKeyDown: ge,
360
+ onSelect: pe,
361
+ onValueChange: me,
362
+ placeholder: Ye,
363
+ ref: y,
364
+ value: w
329
365
  }
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,
366
+ ), Re = A.canShowHints ? /* @__PURE__ */ i(Me, { inputRef: y, lineState: A.lineState, children: X }) : X, J = ({ key: u, name: S, intentions: O, style: C, ref: D }) => /* @__PURE__ */ k(T.Group, { ref: D, style: C, children: [
367
+ /* @__PURE__ */ i(s.Group, { name: S }),
368
+ O.map((Q) => /* @__PURE__ */ i(
369
+ rt,
334
370
  {
335
- Item: c.Item,
336
- iconSources: s,
337
- intention: B,
338
- onSelect: ue
371
+ Item: s.Item,
372
+ iconSources: c,
373
+ intention: Q,
374
+ onSelect: we
339
375
  },
340
- B.id
376
+ Q.id
341
377
  ))
342
378
  ] }, u);
343
- return /* @__PURE__ */ i(c.Frame, { height: f, children: /* @__PURE__ */ O(
344
- E,
379
+ return /* @__PURE__ */ i(s.Frame, { height: v, children: /* @__PURE__ */ k(
380
+ T,
345
381
  {
346
- label: d,
382
+ label: f,
347
383
  loop: !0,
348
- onValueChange: z,
384
+ onValueChange: fe,
349
385
  shouldFilter: !1,
350
- value: $,
386
+ value: he,
351
387
  children: [
352
- /* @__PURE__ */ i(c.Input, { input: le, inputMessage: y }),
353
- /* @__PURE__ */ O(
354
- E.List,
388
+ /* @__PURE__ */ i("div", { ref: P, children: /* @__PURE__ */ i(s.Input, { enterLine: E, input: Re, inputMessage: R }) }),
389
+ /* @__PURE__ */ k(
390
+ T.List,
355
391
  {
392
+ onPointerMoveCapture: q,
356
393
  style: {
357
- height: `calc(${f} - 107px)`,
358
- // not sure why 107 works
394
+ height: `calc(${v} - ${je + $}px)`,
359
395
  overflowY: "auto",
360
396
  padding: "8px 0"
361
397
  },
362
398
  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
399
+ /* @__PURE__ */ i(T.Empty, { children: /* @__PURE__ */ i(s.NoMatches, { inputValue: w }) }),
400
+ /* @__PURE__ */ k("div", { style: Be, children: [
401
+ F.map((u) => J({ key: u.name ?? nt, ...u })),
402
+ h.length > 0 && J({
403
+ key: Xe,
404
+ name: Oe,
405
+ intentions: h,
406
+ style: qe,
407
+ ref: W
372
408
  })
373
409
  ] })
374
410
  ]
375
411
  }
376
412
  ),
377
413
  /* @__PURE__ */ i(
378
- je,
414
+ ct,
379
415
  {
380
- groupRef: x,
381
- rowIds: R.map(({ id: u }) => u)
416
+ groupRef: W,
417
+ rowIds: h.map(({ id: u }) => u)
382
418
  }
383
419
  )
384
420
  ]
385
421
  }
386
422
  ) });
387
423
  }
388
- function Be({
424
+ function ut({
389
425
  title: e,
390
426
  palette: t,
391
427
  defaultIntentions: n,
392
428
  resolveDefaultInput: o,
393
429
  resolveDefaultFallbackInput: r,
394
- SidekickComponents: c,
395
- showToast: s,
430
+ SidekickComponents: s,
431
+ showToast: c,
396
432
  defaultSidecarRenderer: a,
397
- disableLineHints: d
433
+ disableLineHints: f
398
434
  }) {
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]
435
+ const { onClose: m, setSize: l, anchorOrigin: p, cycleAnchorOrigin: g, height: w, size: R, commandWidth: E } = B(), { Sidekick: h, IntentionPalette: v } = s, I = M()?.icons, b = H(
436
+ () => ({ registry: I, themeIcons: s.icons }),
437
+ [I, s.icons]
402
438
  );
403
- return /* @__PURE__ */ i(K.div, { layout: !0, transition: { duration: V, ease: "easeInOut" }, children: /* @__PURE__ */ O(f.Frame, { commandWidth: R, height: v, children: [
439
+ return /* @__PURE__ */ i(Y.div, { layout: !0, transition: { duration: j, ease: "easeInOut" }, children: /* @__PURE__ */ k(h.Frame, { commandWidth: E, height: w, children: [
404
440
  /* @__PURE__ */ i(
405
- f.ControlBar,
441
+ h.ControlBar,
406
442
  {
407
443
  anchorOrigin: p,
408
- cycleAnchorOrigin: w,
409
- labels: Se,
410
- onClose: h,
444
+ cycleAnchorOrigin: g,
445
+ labels: Ie,
446
+ onClose: m,
411
447
  setSize: l,
412
- size: y,
448
+ size: R,
413
449
  title: e
414
450
  }
415
451
  ),
416
- y !== "compact" && /* @__PURE__ */ i(
417
- Me,
452
+ R !== "compact" && /* @__PURE__ */ i(
453
+ at,
418
454
  {
419
- IntentionPalette: k,
455
+ IntentionPalette: v,
420
456
  defaultIntentions: n,
421
457
  defaultSidecarRenderer: a,
422
- disableLineHints: d,
423
- iconSources: S,
424
- label: e ?? oe,
458
+ disableLineHints: f,
459
+ iconSources: b,
460
+ label: e ?? ie,
425
461
  palette: t,
426
462
  resolveDefaultFallbackInput: r,
427
463
  resolveDefaultInput: o,
428
- showToast: s
464
+ showToast: c
429
465
  }
430
466
  )
431
467
  ] }) });
432
468
  }
433
- function qe({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
434
- const c = {
469
+ function lt({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
470
+ const s = {
435
471
  open: { width: o, pointerEvents: "auto" },
436
472
  closed: { width: 0, pointerEvents: "none" }
437
473
  };
438
474
  return /* @__PURE__ */ i(
439
- K.div,
475
+ Y.div,
440
476
  {
441
477
  animate: e ? "open" : "closed",
442
478
  layout: !0,
443
479
  style: { display: "flex", overflow: "hidden", opacity: 1 },
444
- transition: { duration: V, ease: "easeInOut" },
445
- variants: c,
480
+ transition: { duration: j, ease: "easeInOut" },
481
+ variants: s,
446
482
  children: /* @__PURE__ */ i(r, { height: n, isOpen: e, renderSidecar: t })
447
483
  }
448
484
  );
449
485
  }
450
- function Xe(e, t) {
451
- const n = m(e), o = m(t);
452
- o.current = t, T(() => {
486
+ function dt(e, t) {
487
+ const n = d(e), o = d(t);
488
+ o.current = t, L(() => {
453
489
  n.current && !e && o.current?.(), n.current = e;
454
490
  }, [e]);
455
491
  }
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;
492
+ function ht(e, t, { sidecarReducer: n, defaultSidecarRenderer: o, palette: r }) {
493
+ const s = d(n);
494
+ s.current = n;
495
+ const c = d(!1), a = () => r ? r.current().sidecarRenderer : o, f = d(a);
496
+ f.current = a, x(() => (e.setSidecarReducer(
497
+ (...m) => (s.current ?? ((l, p) => p))(...m)
498
+ ), () => e.setSidecarReducer(void 0)), [e]), x(() => {
499
+ t && !c.current ? e.changeSidecar({ renderer: f.current() ?? null }, "open") : !t && c.current && e.clearSidecar(), c.current = t;
464
500
  }, [e, t]);
465
501
  }
466
- function Qe(e, t) {
467
- L(() => {
502
+ function ft(e, t) {
503
+ x(() => {
468
504
  document.activeElement === document.body && t();
469
505
  }, [e, t]);
470
506
  }
471
- const Ze = {
507
+ const mt = {
472
508
  display: "flex",
473
509
  flexDirection: "inherit",
474
510
  alignItems: "inherit",
475
511
  width: "100%",
476
512
  height: "100%"
477
- }, et = we(function({ name: t, onClose: n, children: o }, r) {
513
+ }, pt = Ce(function({ name: t, onClose: n, children: o }, r) {
478
514
  return /* @__PURE__ */ i(
479
515
  "div",
480
516
  {
481
517
  "aria-label": t,
482
518
  "aria-modal": "false",
483
- onKeyDown: (s) => {
484
- s.key === "Escape" && !s.defaultPrevented && n();
519
+ onKeyDown: (c) => {
520
+ c.key === "Escape" && !c.defaultPrevented && n();
485
521
  },
486
522
  ref: r,
487
523
  role: "dialog",
488
- style: Ze,
524
+ style: mt,
489
525
  tabIndex: -1,
490
526
  children: o
491
527
  }
492
528
  );
493
529
  });
494
- function tt({
530
+ function St({
495
531
  title: e,
496
532
  palette: t,
497
533
  defaultIntentions: n,
498
534
  resolveDefaultInput: o,
499
535
  resolveDefaultFallbackInput: r,
500
- SidekickComponents: c,
501
- showToast: s,
536
+ SidekickComponents: s,
537
+ showToast: c,
502
538
  installKeyboardShortcuts: a,
503
- notifyClose: d,
504
- sidecarReducer: h,
539
+ notifyClose: f,
540
+ sidecarReducer: m,
505
541
  defaultSidecarRenderer: l,
506
542
  disableLineHints: p
507
543
  }) {
508
544
  const {
509
- isSidecarOpen: w,
510
- anchorOrigin: v,
511
- renderSidecar: y,
512
- height: R,
513
- sidecarWidth: f,
514
- isOpen: k,
545
+ isSidecarOpen: g,
546
+ anchorOrigin: w,
547
+ renderSidecar: R,
548
+ height: E,
549
+ sidecarWidth: h,
550
+ isOpen: v,
515
551
  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,
552
+ totalWidth: b,
553
+ size: y,
554
+ onOpen: P,
555
+ onClose: $
556
+ } = B(), { Sidekick: W, SidecarContent: z } = s, { attachDialog: A, focusInside: F } = Pe();
557
+ return _e({
558
+ onOpen: v ? F : P,
523
559
  installKeyboardShortcuts: a
524
- }), Qe(x, P), Xe(k, d), Je(W(), k, {
525
- sidecarReducer: h,
560
+ }), ft(y, F), dt(v, f), ht(K(), v, {
561
+ sidecarReducer: m,
526
562
  defaultSidecarRenderer: l,
527
563
  palette: t
528
- }), k ? /* @__PURE__ */ i(
529
- K.div,
564
+ }), v ? /* @__PURE__ */ i(
565
+ Y.div,
530
566
  {
531
567
  animate: {
532
- width: S
568
+ width: b
533
569
  },
534
570
  layout: !0,
535
- transition: { duration: V, ease: "easeInOut" },
571
+ transition: { duration: j, ease: "easeInOut" },
536
572
  children: /* @__PURE__ */ i(
537
- G.Popover,
573
+ W.Popover,
538
574
  {
539
- anchorOrigin: v,
575
+ anchorOrigin: w,
540
576
  anchorPosition: I,
541
- height: R,
542
- totalWidth: S,
543
- children: /* @__PURE__ */ O(et, { name: e ?? oe, onClose: C, ref: z, children: [
577
+ height: E,
578
+ totalWidth: b,
579
+ children: /* @__PURE__ */ k(pt, { name: e ?? ie, onClose: $, ref: A, children: [
544
580
  /* @__PURE__ */ i(
545
- Be,
581
+ ut,
546
582
  {
547
- SidekickComponents: c,
583
+ SidekickComponents: s,
548
584
  defaultIntentions: n,
549
585
  defaultSidecarRenderer: l,
550
586
  disableLineHints: p,
551
587
  palette: t,
552
588
  resolveDefaultFallbackInput: r,
553
589
  resolveDefaultInput: o,
554
- showToast: s,
590
+ showToast: c,
555
591
  title: e
556
592
  }
557
593
  ),
558
594
  /* @__PURE__ */ i(
559
- qe,
595
+ lt,
560
596
  {
561
- Content: $,
562
- height: R,
563
- isOpen: w,
564
- renderSidecar: y,
565
- width: f
597
+ Content: z,
598
+ height: E,
599
+ isOpen: g,
600
+ renderSidecar: R,
601
+ width: h
566
602
  }
567
603
  )
568
604
  ] })
@@ -571,77 +607,82 @@ function tt({
571
607
  }
572
608
  ) : null;
573
609
  }
574
- function nt(e, t) {
575
- const n = j(), o = e ?? n?.components;
610
+ function gt(e, t) {
611
+ const n = M(), o = e ?? n?.components;
576
612
  if (!o)
577
613
  throw new Error(
578
614
  "ShortRoundSidekick has no theme: wrap the app in <ShortRoundProvider theme={…}>, or pass SidekickComponents"
579
615
  );
580
- return { components: o, showToast: t ?? n?.showToast };
616
+ return Rt(o), { components: o, showToast: t ?? n?.showToast };
617
+ }
618
+ const wt = ["IntentionPalette", "Sidekick", "SidecarContent"];
619
+ function Rt(e) {
620
+ const t = wt.filter((n) => !e[n]);
621
+ if (t.length > 0)
622
+ throw new Error(
623
+ `ShortRoundSidekick: the theme has no ${t.map((n) => `components.${n}`).join(" or ")}`
624
+ );
581
625
  }
582
- function mt({
626
+ function At({
583
627
  title: e,
584
628
  palette: t,
585
629
  defaultIntentions: n,
586
630
  resolveDefaultInput: o,
587
631
  resolveDefaultFallbackInput: r,
588
- SidekickComponents: c,
589
- showToast: s,
632
+ SidekickComponents: s,
633
+ showToast: c,
590
634
  installKeyboardShortcuts: a,
591
- sidekickStore: d,
592
- initialSidekickState: h,
635
+ sidekickStore: f,
636
+ initialSidekickState: m,
593
637
  onClose: l,
594
638
  sidecarReducer: p,
595
- defaultSidecarRenderer: w,
596
- disableLineHints: v
639
+ defaultSidecarRenderer: g,
640
+ disableLineHints: w
597
641
  }) {
598
- const y = nt(c, s);
599
- return /* @__PURE__ */ i(be, { initial: h, store: d, children: /* @__PURE__ */ i(
600
- tt,
642
+ const R = gt(s, c);
643
+ return /* @__PURE__ */ i(De, { initial: m, store: f, children: /* @__PURE__ */ i(
644
+ St,
601
645
  {
602
- SidekickComponents: y.components,
646
+ SidekickComponents: R.components,
603
647
  defaultIntentions: n,
604
- defaultSidecarRenderer: w,
605
- disableLineHints: v,
648
+ defaultSidecarRenderer: g,
649
+ disableLineHints: w,
606
650
  installKeyboardShortcuts: a,
607
651
  notifyClose: l,
608
652
  palette: t,
609
653
  resolveDefaultFallbackInput: r,
610
654
  resolveDefaultInput: o,
611
- showToast: y.showToast,
655
+ showToast: R.showToast,
612
656
  sidecarReducer: p,
613
657
  title: e
614
658
  }
615
659
  ) });
616
660
  }
617
- const ot = { isOpen: !1, message: null }, rt = ["IntentionPalette", "Sidekick", "SidecarContent"];
618
- function ct(e) {
619
- const t = ["components", "Toast"].filter((o) => !e?.[o]);
661
+ const vt = { isOpen: !1, message: null };
662
+ function yt(e) {
663
+ const t = ["components", "Toast"].filter((n) => !e?.[n]);
620
664
  if (t.length > 0)
621
665
  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
666
  }
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: [
667
+ function _t({ theme: e, icons: t, children: n }) {
668
+ yt(e);
669
+ const [o, r] = V(vt), s = G(({ message: m }) => r({ isOpen: !0, message: m }), []), c = G(() => r((m) => ({ ...m, isOpen: !1 })), []), a = H(
670
+ () => ({ components: e.components, showToast: s, icons: t }),
671
+ [e.components, s, t]
672
+ ), { Toast: f } = e;
673
+ return /* @__PURE__ */ k(ue.Provider, { value: a, children: [
635
674
  n,
636
- /* @__PURE__ */ i(d, { isOpen: o.isOpen, message: o.message, onClose: s })
675
+ /* @__PURE__ */ i(f, { isOpen: o.isOpen, message: o.message, onClose: c })
637
676
  ] });
638
677
  }
639
678
  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
679
+ Me as LineInput,
680
+ _t as ShortRoundProvider,
681
+ At as ShortRoundSidekick,
682
+ De as SidekickStoreProvider,
683
+ Tt as useShortRound,
684
+ Lt as useShortRoundComponents,
685
+ xt as useShortRoundToast,
686
+ B as useSidekick,
687
+ K as useSidekickStore
647
688
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shortround/react",
3
- "version": "0.5.0",
3
+ "version": "0.7.0",
4
4
  "description": "ShortRound for React: the command palette, the sidekick, the provider and the theme contract, on @shortround/core.",
5
5
  "keywords": [
6
6
  "shortround",
@@ -40,7 +40,7 @@
40
40
  ],
41
41
  "types": "./src/index.d.ts",
42
42
  "devDependencies": {
43
- "@shortround/core": "0.5.0",
43
+ "@shortround/core": "0.7.0",
44
44
  "@testing-library/jest-dom": "^6.6.3",
45
45
  "@testing-library/react": "^16.3.0",
46
46
  "@types/react": "19.1.8",
@@ -53,7 +53,7 @@
53
53
  "vitest": "^3.2.4"
54
54
  },
55
55
  "peerDependencies": {
56
- "@shortround/core": "^0.5.0",
56
+ "@shortround/core": "^0.7.0",
57
57
  "react": "^18.2.0 || ^19.0.0",
58
58
  "react-dom": "^18.2.0 || ^19.0.0"
59
59
  },
package/src/index.d.ts CHANGED
@@ -2,7 +2,9 @@
2
2
  // constants) are @shortround/core's; this file imports them and doesn't re-export them.
3
3
  import type {
4
4
  AnchorPosition,
5
+ CommandLineState,
5
6
  ControlLabels,
7
+ EnterLine,
6
8
  Intention,
7
9
  IntentionActionResult,
8
10
  PaletteSource,
@@ -12,7 +14,7 @@ import type {
12
14
  SidekickStore,
13
15
  SidekickStoreState
14
16
  } from '@shortround/core';
15
- import { JSX, ReactNode } from 'react';
17
+ import { JSX, ReactNode, RefObject } from 'react';
16
18
 
17
19
  /** Where the sidekick sits for an anchor origin, as CSS position properties. */
18
20
  export interface AnchorPositionStyle {
@@ -51,10 +53,15 @@ export interface SidekickComponents {
51
53
  IntentionPalette: {
52
54
  /** Renders its children. Row styling goes here, through cmdk's attributes (`[cmdk-item]`, `[data-selected]`). */
53
55
  Frame: React.ComponentType<{ height: string; children: ReactNode }>;
54
- /** Places `input` (the palette's cmdk input, `data-testid="shortround-input"`) and shows `inputMessage.text`. */
56
+ /**
57
+ * Places `input` (the palette's cmdk input, `data-testid="shortround-input"`) and shows `inputMessage.text`. Shows
58
+ * `enterLine`, when given, apart from the message: what Enter will do ("↵ search grid"), each of its `words` with
59
+ * its `role` (`verb`, `param`, `value`; the roles the input's words have), and `enterLine.text` whole.
60
+ */
55
61
  Input: React.ComponentType<{
56
62
  input: ReactNode;
57
63
  inputMessage?: { type: string; text: string };
64
+ enterLine?: EnterLine;
58
65
  }>;
59
66
  /**
60
67
  * Draws one row inside the palette's cmdk item (`data-testid="shortround-item-<id>"`): shows the title and
@@ -139,11 +146,13 @@ export interface ToastProps {
139
146
 
140
147
  /**
141
148
  * What an app hands to `ShortRoundProvider`, once, at its root (defined at module scope, or memoized): the slots and
142
- * the Toast view. Toast's obligation: while `isOpen`, show `message` (`data-testid="shortround-toast"`); otherwise
143
- * render nothing.
149
+ * the Toast view. Each slot group is needed only by what draws it: `ShortRoundSidekick` throws, naming the groups it
150
+ * misses, when it mounts; another package's group (such as `@shortround/chat`'s `Chat`) is checked by its own
151
+ * component. Toast's obligation: while `isOpen`, show `message` (`data-testid="shortround-toast"`); otherwise render
152
+ * nothing.
144
153
  */
145
154
  export interface ShortRoundTheme {
146
- components: SidekickComponents;
155
+ components: Partial<SidekickComponents> & { [group: string]: any };
147
156
  Toast: React.ComponentType<ToastProps>;
148
157
  }
149
158
 
@@ -162,6 +171,12 @@ export function ShortRoundProvider(props: {
162
171
  /** Shows a toast in the nearest provider's theme. Throws outside a `ShortRoundProvider`. */
163
172
  export function useShortRoundToast(): { showToast: (args: { message: string }) => void };
164
173
 
174
+ /**
175
+ * The nearest `ShortRoundProvider`'s theme slots (`theme.components`), or `null` with no provider. For a package that
176
+ * draws through a slot group of its own, such as `@shortround/chat`'s `Chat`, which the provider doesn't require.
177
+ */
178
+ export function useShortRoundComponents(): ShortRoundTheme['components'] | null;
179
+
165
180
  export interface UseShortRoundResult {
166
181
  inputValue: string;
167
182
  inputMessage?: { type: string; text: string };
@@ -241,3 +256,17 @@ export function ShortRoundSidekick(props: {
241
256
  */
242
257
  disableLineHints?: boolean;
243
258
  }): JSX.Element;
259
+
260
+ /**
261
+ * An input with its typed line drawn under it, for a host's own input (a chat, an editor's command field): each word
262
+ * with its role (`data-role` on the word's span, for a stylesheet to colour) and the ghost text after the last word
263
+ * (`data-role="ghost"`). The input itself (`children`, an `<input>` or `<textarea>` whose element is `inputRef`) stays
264
+ * on top with its text made transparent, so typing, the caret and selection stay native. Without `lineState` the input
265
+ * shows as it is. The line is drawn on one line: pass no `lineState` while the text has a line break.
266
+ */
267
+ export function LineInput(props: {
268
+ children: ReactNode;
269
+ inputRef: RefObject<HTMLInputElement | HTMLTextAreaElement | null>;
270
+ /** A command line's state (`CommandLine.getState()`, or a chat line's `drawnLineState`), or `null`. */
271
+ lineState?: CommandLineState | null;
272
+ }): JSX.Element;