@shortround/react 0.5.0 → 0.6.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,23 @@
1
1
  # @shortround/react
2
2
 
3
+ ## 0.6.0
4
+
5
+ ### Breaking Changes
6
+
7
+ - `ShortRoundProvider` needs only `components` and `Toast`. It no longer refuses a theme without `IntentionPalette`,
8
+ `Sidekick` or `SidecarContent`; `ShortRoundSidekick` throws when it mounts instead, naming the groups it misses
9
+ (`ShortRoundSidekick: the theme has no components.Sidekick`). A theme for an app that draws only the chat has `Chat`
10
+ and a `Toast`.
11
+ - Types: `ShortRoundTheme.components` is `Partial<SidekickComponents>` with other groups allowed. Under `strict`, code
12
+ that reads a group off a value typed `ShortRoundTheme` (`theme.components.Sidekick.Frame`) needs a check or `!`.
13
+
14
+ ### Minor Changes
15
+
16
+ - `LineInput`: an input with the typed line drawn under it (each word's role, and the ghost), for a host's own input.
17
+ - `useShortRoundComponents()`: the nearest provider's slots, or `null` without one, for a package that draws through
18
+ slot groups of its own (`@shortround/chat`'s `Chat`).
19
+ - Takes `@shortround/core` `^0.6.0` as a peer.
20
+
3
21
  ## 0.5.0
4
22
 
5
23
  ### 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
@@ -337,6 +342,40 @@ const sendAsChat = (text, { matches }) =>
337
342
  changes (such as whether the chat shows) when the fallback runs, through a ref or a store, rather than closing over
338
343
  it. One that throws adds no rows and logs why.
339
344
 
345
+ ### Line hints in your own input: LineInput
346
+
347
+ The sidekick's input shows each typed word coloured by its role and the rest of the next word as ghost text. A host
348
+ with its own input (a chat, an editor's command field) gets the same drawing with `LineInput`: wrap the input, pass
349
+ its ref, and pass a command line's state. The input stays on top with its text made transparent, so typing, the caret
350
+ and selection stay native.
351
+
352
+ ```jsx
353
+ import { useRef, useSyncExternalStore } from 'react';
354
+ import { LineInput } from '@shortround/react';
355
+
356
+ function CommandField({ line }) {
357
+ // line: a command line from @shortround/core (palette.commandLine(), or runtime.commandLine())
358
+ const inputRef = useRef(null);
359
+ const lineState = useSyncExternalStore(line.subscribe, line.getState);
360
+ return (
361
+ <LineInput inputRef={inputRef} lineState={lineState}>
362
+ <input
363
+ ref={inputRef}
364
+ value={lineState.text}
365
+ onChange={(event) => line.change(event.target.value, event.target.selectionStart)}
366
+ />
367
+ </LineInput>
368
+ );
369
+ }
370
+ ```
371
+
372
+ - Each word is a `<span data-role="…">` (`verb`, `text`, `hint`, `param`, `value`, `unread`, `broken`) and the ghost a
373
+ `<span data-role="ghost">`, inside `data-testid="shortround-line-shadow"`. Colour them in your stylesheet.
374
+ - The line is drawn on one line. Pass `lineState={null}` while the text has a line break (a `<textarea>`), and the
375
+ input shows as it is.
376
+ - A chat line's state should go through core's `drawnLineState`, so a line that reads as chat isn't drawn as a broken
377
+ command.
378
+
340
379
  `@shortround/core`'s catalog engine (`loadCatalog`, `buildPalette`) builds the intentions, the resolver and (given
341
380
  one) the fallback from a YAML catalog: see its
342
381
  [CATALOG.md](https://github.com/csepulv/shortround/tree/main/packages/shortround-core/CATALOG.md).
package/dist/react.es.js CHANGED
@@ -1,9 +1,9 @@
1
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";
2
+ import { useRef as m, useSyncExternalStore as H, useEffect as C, 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 k, Fragment as Re } from "react/jsx-runtime";
4
+ import ye from "tiny-invariant";
5
+ import { motion as V } from "framer-motion";
6
+ import { Command as b, useCommandState as te } from "cmdk";
7
7
  function ne({
8
8
  palette: e,
9
9
  defaultIntentions: t,
@@ -18,16 +18,16 @@ function ne({
18
18
  resolveDefaultFallbackInput: o
19
19
  }));
20
20
  const c = r.current, s = H(c.subscribe, c.getState, c.getState);
21
- return T(() => {
21
+ return C(() => {
22
22
  c.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
+ }, [c, e, t, n, o]), C(() => c.watchResolver(), [c]), C(() => c.watchPalette(), [c, e]), { store: c, state: s, intentions: c.rows() };
29
29
  }
30
- function ht({
30
+ function ft({
31
31
  defaultIntentions: e,
32
32
  resolveDefaultInput: t,
33
33
  resolveDefaultFallbackInput: n
@@ -49,7 +49,7 @@ function ht({
49
49
  dispatchedStack: r.dispatchedStack
50
50
  };
51
51
  }
52
- const V = 0.35, Oe = "100vh", ke = Object.freeze({
52
+ const U = 0.35, ke = "100vh", Oe = 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%)" },
@@ -62,10 +62,10 @@ const V = 0.35, Oe = "100vh", ke = Object.freeze({
62
62
  }), q = Object.freeze({
63
63
  compact: { height: "auto" },
64
64
  medium: { height: "50vh" },
65
- full: { height: Oe }
65
+ full: { height: ke }
66
66
  }), oe = "ShortRound", Ie = ({ onOpen: e, installKeyboardShortcuts: t = !0 }) => {
67
67
  const n = m({ onOpen: e });
68
- n.current = { onOpen: e }, T(() => {
68
+ n.current = { onOpen: e }, C(() => {
69
69
  if (!t)
70
70
  return;
71
71
  const o = (r) => {
@@ -74,28 +74,28 @@ const V = 0.35, Oe = "100vh", ke = Object.freeze({
74
74
  return document.addEventListener("keydown", o, { capture: !0 }), () => document.removeEventListener("keydown", o, { capture: !0 });
75
75
  }, [t]);
76
76
  }, re = Z(null), W = () => ee(re);
77
- function be({ store: e, initial: t, children: n }) {
77
+ function Ee({ store: e, initial: t, children: n }) {
78
78
  const o = W(), r = m(null);
79
79
  !e && !o && !r.current && (r.current = Q(t));
80
80
  const c = e ?? o ?? r.current;
81
81
  return /* @__PURE__ */ i(re.Provider, { value: c, children: n });
82
82
  }
83
- function U(e = {}) {
83
+ function j(e = {}) {
84
84
  const t = W();
85
85
  let n = e.store || t;
86
86
  const o = m(null);
87
87
  n || (o.current || (o.current = Q(e.initial)), n = o.current);
88
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 = () => {
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 }), R = () => {
90
90
  v(fe(d));
91
- }, R = () => {
91
+ }, y = () => {
92
92
  if (h)
93
93
  return h();
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: Oe[d],
99
99
  onOpen: () => n.set({ isOpen: !0 }),
100
100
  setIsOpen: (f) => {
101
101
  n.set({ isOpen: f });
@@ -105,23 +105,23 @@ function U(e = {}) {
105
105
  },
106
106
  height: p,
107
107
  setSize: (f) => {
108
- Re(q[f], `Unknown size: ${f}`), n.set({ size: f });
108
+ ye(q[f], `Unknown size: ${f}`), n.set({ size: f });
109
109
  },
110
110
  setAnchorOrigin: v,
111
- cycleAnchorOrigin: y,
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
115
  sidecarWidth: w,
116
116
  closeSidecar: n.closeSidecar,
117
- renderSidecar: R
117
+ renderSidecar: y
118
118
  };
119
119
  }, [n, r]);
120
120
  return { ...r, ...c };
121
121
  }
122
- const ce = Z(null), j = () => ee(ce);
123
- function ft() {
124
- const e = j();
122
+ const ce = Z(null), N = () => ee(ce), mt = () => N()?.components ?? null;
123
+ function pt() {
124
+ const e = N();
125
125
  if (!e)
126
126
  throw new Error("useShortRoundToast needs a <ShortRoundProvider theme={…}> above it");
127
127
  return { showToast: e.showToast };
@@ -129,7 +129,7 @@ function ft() {
129
129
  function X(e) {
130
130
  (e.querySelector("[cmdk-input]") ?? e).focus();
131
131
  }
132
- function Ee() {
132
+ function be() {
133
133
  const e = m(null), t = m(null), n = _((r) => {
134
134
  if (r) {
135
135
  t.current = document.activeElement, e.current = r, X(r);
@@ -144,10 +144,10 @@ function Ee() {
144
144
  }, []);
145
145
  return { attachDialog: n, focusInside: o };
146
146
  }
147
- const Te = { subscribe: () => () => {
147
+ const Ce = { subscribe: () => () => {
148
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);
149
+ function Te({ palette: e, disableLineHints: t, store: n }) {
150
+ const o = typeof e?.commandLine == "function" && !t, r = o ? n.commandLine() : null, c = r ?? Ce, s = H(c.subscribe, c.getState, c.getState);
151
151
  return { canShowHints: o, lineState: r ? s : null, complete: () => !n.commandLine() || !n.completeFirst() ? null : n.commandLine()?.getState().caret ?? null };
152
152
  }
153
153
  const Le = new Set(Object.values(me)), J = (e, t) => t[e] ?? t.unknown, A = (e, t) => e ? ge(e, t) : void 0;
@@ -194,7 +194,7 @@ function De({ children: e, inputRef: t, lineState: n }) {
194
194
  s.scrollLeft = c.scrollLeft;
195
195
  };
196
196
  return a(), c.addEventListener("scroll", a), () => c.removeEventListener("scroll", a);
197
- }), /* @__PURE__ */ O("div", { "data-testid": "shortround-line-input", style: Ae, children: [
197
+ }), /* @__PURE__ */ k("div", { "data-testid": "shortround-line-input", style: Ae, children: [
198
198
  r && /* @__PURE__ */ i("div", { "aria-hidden": !0, "data-testid": "shortround-line-shadow", ref: o, style: _e, children: /* @__PURE__ */ i(We, { state: n }) }),
199
199
  e
200
200
  ] });
@@ -227,20 +227,20 @@ function We({ state: e }) {
227
227
  o.start > n && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n, o.start) }, `gap-${n}`)), t.push(
228
228
  /* @__PURE__ */ i("span", { "data-role": o.role, title: o.reason, children: e.text.slice(o.start, o.end) }, o.start)
229
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: [
230
+ return n < e.text.length && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n) }, `tail-${n}`)), /* @__PURE__ */ k(Re, { children: [
231
231
  t,
232
232
  e.ghost && /* @__PURE__ */ i("span", { "data-role": "ghost", children: e.ghost })
233
233
  ] });
234
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) {
235
+ const Ne = "Type a intention or search...", Ge = { display: "flex", flexDirection: "column" }, $e = { order: -1 }, ze = "shortround::navigate", Ke = "shortround::no-group";
236
+ function He(e) {
237
237
  const t = document.activeElement;
238
238
  e && t !== e && e.closest("[cmdk-root]")?.contains(t) && e.focus();
239
239
  }
240
240
  function Ve({ intention: e, onSelect: t, Item: n, iconSources: o }) {
241
241
  const r = te((c) => c.value) === e.id.trim();
242
242
  return /* @__PURE__ */ i(
243
- E.Item,
243
+ b.Item,
244
244
  {
245
245
  "data-testid": `shortround-item-${e.id}`,
246
246
  disabled: e.disabled,
@@ -265,7 +265,7 @@ const Ue = (e) => e.reduce((t, n) => {
265
265
  }, []);
266
266
  function je({ groupRef: e, rowIds: t }) {
267
267
  const n = te((r) => r.value), o = t.includes(n);
268
- return T(() => {
268
+ return C(() => {
269
269
  if (!o)
270
270
  return;
271
271
  const r = requestAnimationFrame(
@@ -297,27 +297,27 @@ function Me({
297
297
  defaultIntentions: t,
298
298
  resolveDefaultInput: n,
299
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);
300
+ }), { inputValue: v, inputMessage: R, revertIntentions: y } = p, { height: f, onClose: O } = j(), I = W(), S = m(null), x = m(null), G = Ye(S), T = Te({ palette: e, disableLineHints: h, store: l }), $ = F(() => Ue(w), [w]), z = p.highlightedId?.trim() ?? "", K = (u) => {
301
+ const g = [...w, ...y].find(({ id: E }) => E.trim() === u);
302
302
  l.highlight(g?.id ?? u);
303
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);
304
+ const { value: g, selectionStart: E } = u.target, D = l.commandLine()?.getState();
305
+ D && g === l.getState().inputValue && D.caret !== E && l.changeInput(g, E);
306
306
  }, ie = () => {
307
- const u = C.complete();
308
- return u !== null ? (N.current = u, !0) : l.completeFirst();
307
+ const u = T.complete();
308
+ return u !== null ? (G.current = u, !0) : l.completeFirst();
309
309
  }, ae = (u) => {
310
310
  u.key === "Tab" && ie() && (u.preventDefault(), S.current?.focus());
311
311
  }, ue = async (u) => {
312
- Ke(S.current);
312
+ He(S.current);
313
313
  const g = await l.select(u, { sidekickStore: I, defaultSidecarRenderer: r });
314
314
  if (g.isCompletion) {
315
315
  S.current?.focus();
316
316
  return;
317
317
  }
318
- g.isRejected || (g.message && a?.({ message: g.message }), g.shouldReset && k());
318
+ g.isRejected || (g.message && a?.({ message: g.message }), g.shouldReset && O());
319
319
  }, Y = /* @__PURE__ */ i(
320
- E.Input,
320
+ b.Input,
321
321
  {
322
322
  "data-testid": "shortround-input",
323
323
  onKeyDown: ae,
@@ -327,9 +327,9 @@ function Me({
327
327
  ref: S,
328
328
  value: v
329
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: [
330
+ ), le = T.canShowHints ? /* @__PURE__ */ i(De, { inputRef: S, lineState: T.lineState, children: Y }) : Y, M = ({ key: u, name: g, intentions: E, style: D, ref: de }) => /* @__PURE__ */ k(b.Group, { ref: de, style: D, children: [
331
331
  /* @__PURE__ */ i(c.Group, { name: g }),
332
- b.map((B) => /* @__PURE__ */ i(
332
+ E.map((B) => /* @__PURE__ */ i(
333
333
  Ve,
334
334
  {
335
335
  Item: c.Item,
@@ -340,18 +340,18 @@ function Me({
340
340
  B.id
341
341
  ))
342
342
  ] }, u);
343
- return /* @__PURE__ */ i(c.Frame, { height: f, children: /* @__PURE__ */ O(
344
- E,
343
+ return /* @__PURE__ */ i(c.Frame, { height: f, children: /* @__PURE__ */ k(
344
+ b,
345
345
  {
346
346
  label: d,
347
347
  loop: !0,
348
- onValueChange: z,
348
+ onValueChange: K,
349
349
  shouldFilter: !1,
350
- value: $,
350
+ value: z,
351
351
  children: [
352
- /* @__PURE__ */ i(c.Input, { input: le, inputMessage: y }),
353
- /* @__PURE__ */ O(
354
- E.List,
352
+ /* @__PURE__ */ i(c.Input, { input: le, inputMessage: R }),
353
+ /* @__PURE__ */ k(
354
+ b.List,
355
355
  {
356
356
  style: {
357
357
  height: `calc(${f} - 107px)`,
@@ -360,13 +360,13 @@ function Me({
360
360
  padding: "8px 0"
361
361
  },
362
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({
363
+ /* @__PURE__ */ i(b.Empty, { children: /* @__PURE__ */ i(c.NoMatches, { inputValue: v }) }),
364
+ /* @__PURE__ */ k("div", { style: Ge, children: [
365
+ $.map((u) => M({ key: u.name ?? Ke, ...u })),
366
+ y.length > 0 && M({
367
367
  key: ze,
368
368
  name: pe,
369
- intentions: R,
369
+ intentions: y,
370
370
  style: $e,
371
371
  ref: x
372
372
  })
@@ -378,7 +378,7 @@ function Me({
378
378
  je,
379
379
  {
380
380
  groupRef: x,
381
- rowIds: R.map(({ id: u }) => u)
381
+ rowIds: y.map(({ id: u }) => u)
382
382
  }
383
383
  )
384
384
  ]
@@ -396,11 +396,11 @@ function Be({
396
396
  defaultSidecarRenderer: a,
397
397
  disableLineHints: d
398
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(
399
+ const { onClose: h, setSize: l, anchorOrigin: p, cycleAnchorOrigin: w, height: v, size: R, commandWidth: y } = j(), { Sidekick: f, IntentionPalette: O } = c, I = N()?.icons, S = F(
400
400
  () => ({ registry: I, themeIcons: c.icons }),
401
401
  [I, c.icons]
402
402
  );
403
- return /* @__PURE__ */ i(K.div, { layout: !0, transition: { duration: V, ease: "easeInOut" }, children: /* @__PURE__ */ O(f.Frame, { commandWidth: R, height: v, children: [
403
+ return /* @__PURE__ */ i(V.div, { layout: !0, transition: { duration: U, ease: "easeInOut" }, children: /* @__PURE__ */ k(f.Frame, { commandWidth: y, height: v, children: [
404
404
  /* @__PURE__ */ i(
405
405
  f.ControlBar,
406
406
  {
@@ -409,14 +409,14 @@ function Be({
409
409
  labels: Se,
410
410
  onClose: h,
411
411
  setSize: l,
412
- size: y,
412
+ size: R,
413
413
  title: e
414
414
  }
415
415
  ),
416
- y !== "compact" && /* @__PURE__ */ i(
416
+ R !== "compact" && /* @__PURE__ */ i(
417
417
  Me,
418
418
  {
419
- IntentionPalette: k,
419
+ IntentionPalette: O,
420
420
  defaultIntentions: n,
421
421
  defaultSidecarRenderer: a,
422
422
  disableLineHints: d,
@@ -436,12 +436,12 @@ function qe({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
436
436
  closed: { width: 0, pointerEvents: "none" }
437
437
  };
438
438
  return /* @__PURE__ */ i(
439
- K.div,
439
+ V.div,
440
440
  {
441
441
  animate: e ? "open" : "closed",
442
442
  layout: !0,
443
443
  style: { display: "flex", overflow: "hidden", opacity: 1 },
444
- transition: { duration: V, ease: "easeInOut" },
444
+ transition: { duration: U, ease: "easeInOut" },
445
445
  variants: c,
446
446
  children: /* @__PURE__ */ i(r, { height: n, isOpen: e, renderSidecar: t })
447
447
  }
@@ -449,7 +449,7 @@ function qe({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
449
449
  }
450
450
  function Xe(e, t) {
451
451
  const n = m(e), o = m(t);
452
- o.current = t, T(() => {
452
+ o.current = t, C(() => {
453
453
  n.current && !e && o.current?.(), n.current = e;
454
454
  }, [e]);
455
455
  }
@@ -508,39 +508,39 @@ function tt({
508
508
  const {
509
509
  isSidecarOpen: w,
510
510
  anchorOrigin: v,
511
- renderSidecar: y,
512
- height: R,
511
+ renderSidecar: R,
512
+ height: y,
513
513
  sidecarWidth: f,
514
- isOpen: k,
514
+ isOpen: O,
515
515
  anchorPosition: I,
516
516
  totalWidth: S,
517
517
  size: x,
518
- onOpen: N,
519
- onClose: C
520
- } = U(), { Sidekick: G, SidecarContent: $ } = c, { attachDialog: z, focusInside: P } = Ee();
518
+ onOpen: G,
519
+ onClose: T
520
+ } = j(), { Sidekick: $, SidecarContent: z } = c, { attachDialog: K, focusInside: P } = be();
521
521
  return Ie({
522
- onOpen: k ? P : N,
522
+ onOpen: O ? P : G,
523
523
  installKeyboardShortcuts: a
524
- }), Qe(x, P), Xe(k, d), Je(W(), k, {
524
+ }), Qe(x, P), Xe(O, d), Je(W(), O, {
525
525
  sidecarReducer: h,
526
526
  defaultSidecarRenderer: l,
527
527
  palette: t
528
- }), k ? /* @__PURE__ */ i(
529
- K.div,
528
+ }), O ? /* @__PURE__ */ i(
529
+ V.div,
530
530
  {
531
531
  animate: {
532
532
  width: S
533
533
  },
534
534
  layout: !0,
535
- transition: { duration: V, ease: "easeInOut" },
535
+ transition: { duration: U, ease: "easeInOut" },
536
536
  children: /* @__PURE__ */ i(
537
- G.Popover,
537
+ $.Popover,
538
538
  {
539
539
  anchorOrigin: v,
540
540
  anchorPosition: I,
541
- height: R,
541
+ height: y,
542
542
  totalWidth: S,
543
- children: /* @__PURE__ */ O(et, { name: e ?? oe, onClose: C, ref: z, children: [
543
+ children: /* @__PURE__ */ k(et, { name: e ?? oe, onClose: T, ref: K, children: [
544
544
  /* @__PURE__ */ i(
545
545
  Be,
546
546
  {
@@ -558,10 +558,10 @@ function tt({
558
558
  /* @__PURE__ */ i(
559
559
  qe,
560
560
  {
561
- Content: $,
562
- height: R,
561
+ Content: z,
562
+ height: y,
563
563
  isOpen: w,
564
- renderSidecar: y,
564
+ renderSidecar: R,
565
565
  width: f
566
566
  }
567
567
  )
@@ -572,14 +572,22 @@ function tt({
572
572
  ) : null;
573
573
  }
574
574
  function nt(e, t) {
575
- const n = j(), o = e ?? n?.components;
575
+ const n = N(), o = e ?? n?.components;
576
576
  if (!o)
577
577
  throw new Error(
578
578
  "ShortRoundSidekick has no theme: wrap the app in <ShortRoundProvider theme={…}>, or pass SidekickComponents"
579
579
  );
580
- return { components: o, showToast: t ?? n?.showToast };
580
+ return rt(o), { components: o, showToast: t ?? n?.showToast };
581
581
  }
582
- function mt({
582
+ const ot = ["IntentionPalette", "Sidekick", "SidecarContent"];
583
+ function rt(e) {
584
+ const t = ot.filter((n) => !e[n]);
585
+ if (t.length > 0)
586
+ throw new Error(
587
+ `ShortRoundSidekick: the theme has no ${t.map((n) => `components.${n}`).join(" or ")}`
588
+ );
589
+ }
590
+ function St({
583
591
  title: e,
584
592
  palette: t,
585
593
  defaultIntentions: n,
@@ -595,11 +603,11 @@ function mt({
595
603
  defaultSidecarRenderer: w,
596
604
  disableLineHints: v
597
605
  }) {
598
- const y = nt(c, s);
599
- return /* @__PURE__ */ i(be, { initial: h, store: d, children: /* @__PURE__ */ i(
606
+ const R = nt(c, s);
607
+ return /* @__PURE__ */ i(Ee, { initial: h, store: d, children: /* @__PURE__ */ i(
600
608
  tt,
601
609
  {
602
- SidekickComponents: y.components,
610
+ SidekickComponents: R.components,
603
611
  defaultIntentions: n,
604
612
  defaultSidecarRenderer: w,
605
613
  disableLineHints: v,
@@ -608,40 +616,37 @@ function mt({
608
616
  palette: t,
609
617
  resolveDefaultFallbackInput: r,
610
618
  resolveDefaultInput: o,
611
- showToast: y.showToast,
619
+ showToast: R.showToast,
612
620
  sidecarReducer: p,
613
621
  title: e
614
622
  }
615
623
  ) });
616
624
  }
617
- const ot = { isOpen: !1, message: null }, rt = ["IntentionPalette", "Sidekick", "SidecarContent"];
618
- function ct(e) {
619
- const t = ["components", "Toast"].filter((o) => !e?.[o]);
625
+ const ct = { isOpen: !1, message: null };
626
+ function st(e) {
627
+ const t = ["components", "Toast"].filter((n) => !e?.[n]);
620
628
  if (t.length > 0)
621
629
  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
630
  }
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
+ function gt({ theme: e, icons: t, children: n }) {
632
+ st(e);
633
+ const [o, r] = ve(ct), c = _(({ message: h }) => r({ isOpen: !0, message: h }), []), s = _(() => r((h) => ({ ...h, isOpen: !1 })), []), a = F(
631
634
  () => ({ components: e.components, showToast: c, icons: t }),
632
635
  [e.components, c, t]
633
636
  ), { Toast: d } = e;
634
- return /* @__PURE__ */ O(ce.Provider, { value: a, children: [
637
+ return /* @__PURE__ */ k(ce.Provider, { value: a, children: [
635
638
  n,
636
639
  /* @__PURE__ */ i(d, { isOpen: o.isOpen, message: o.message, onClose: s })
637
640
  ] });
638
641
  }
639
642
  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,
643
+ De as LineInput,
644
+ gt as ShortRoundProvider,
645
+ St as ShortRoundSidekick,
646
+ Ee as SidekickStoreProvider,
647
+ ft as useShortRound,
648
+ mt as useShortRoundComponents,
649
+ pt as useShortRoundToast,
650
+ j as useSidekick,
646
651
  W as useSidekickStore
647
652
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shortround/react",
3
- "version": "0.5.0",
3
+ "version": "0.6.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.6.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.6.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,6 +2,7 @@
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,
6
7
  Intention,
7
8
  IntentionActionResult,
@@ -12,7 +13,7 @@ import type {
12
13
  SidekickStore,
13
14
  SidekickStoreState
14
15
  } from '@shortround/core';
15
- import { JSX, ReactNode } from 'react';
16
+ import { JSX, ReactNode, RefObject } from 'react';
16
17
 
17
18
  /** Where the sidekick sits for an anchor origin, as CSS position properties. */
18
19
  export interface AnchorPositionStyle {
@@ -139,11 +140,13 @@ export interface ToastProps {
139
140
 
140
141
  /**
141
142
  * 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.
143
+ * the Toast view. Each slot group is needed only by what draws it: `ShortRoundSidekick` throws, naming the groups it
144
+ * misses, when it mounts; another package's group (such as `@shortround/chat`'s `Chat`) is checked by its own
145
+ * component. Toast's obligation: while `isOpen`, show `message` (`data-testid="shortround-toast"`); otherwise render
146
+ * nothing.
144
147
  */
145
148
  export interface ShortRoundTheme {
146
- components: SidekickComponents;
149
+ components: Partial<SidekickComponents> & { [group: string]: any };
147
150
  Toast: React.ComponentType<ToastProps>;
148
151
  }
149
152
 
@@ -162,6 +165,12 @@ export function ShortRoundProvider(props: {
162
165
  /** Shows a toast in the nearest provider's theme. Throws outside a `ShortRoundProvider`. */
163
166
  export function useShortRoundToast(): { showToast: (args: { message: string }) => void };
164
167
 
168
+ /**
169
+ * The nearest `ShortRoundProvider`'s theme slots (`theme.components`), or `null` with no provider. For a package that
170
+ * draws through a slot group of its own, such as `@shortround/chat`'s `Chat`, which the provider doesn't require.
171
+ */
172
+ export function useShortRoundComponents(): ShortRoundTheme['components'] | null;
173
+
165
174
  export interface UseShortRoundResult {
166
175
  inputValue: string;
167
176
  inputMessage?: { type: string; text: string };
@@ -241,3 +250,17 @@ export function ShortRoundSidekick(props: {
241
250
  */
242
251
  disableLineHints?: boolean;
243
252
  }): JSX.Element;
253
+
254
+ /**
255
+ * An input with its typed line drawn under it, for a host's own input (a chat, an editor's command field): each word
256
+ * with its role (`data-role` on the word's span, for a stylesheet to colour) and the ghost text after the last word
257
+ * (`data-role="ghost"`). The input itself (`children`, an `<input>` or `<textarea>` whose element is `inputRef`) stays
258
+ * on top with its text made transparent, so typing, the caret and selection stay native. Without `lineState` the input
259
+ * shows as it is. The line is drawn on one line: pass no `lineState` while the text has a line break.
260
+ */
261
+ export function LineInput(props: {
262
+ children: ReactNode;
263
+ inputRef: RefObject<HTMLInputElement | HTMLTextAreaElement | null>;
264
+ /** A command line's state (`CommandLine.getState()`, or a chat line's `drawnLineState`), or `null`. */
265
+ lineState?: CommandLineState | null;
266
+ }): JSX.Element;