@shortround/react 0.7.0 → 0.8.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,18 @@
1
1
  # @shortround/react
2
2
 
3
+ ## 0.8.0
4
+
5
+ ### Minor Changes
6
+
7
+ - The palette follows the store's highlight only: cmdk's own first row no longer runs when the store highlights
8
+ nothing, so Enter goes to the store (with a producer, it asks it). See MIGRATING.md, 0.8.0.
9
+ - While the user's chosen row holds (`isHighlightChosen`), rows that arrive are drawn below it, and a group whose rows
10
+ sit apart has its heading drawn again where they sit.
11
+ - During a run the input is empty and a Status row says what runs; a run that rejects shows its error under the input
12
+ and is logged (`ShortRoundPalette: an intention failed`), where 0.7.0 left the rejection unhandled.
13
+ - Tab completes the highlighted completion row, else the first.
14
+ - Takes `@shortround/core` `^0.8.0` as a peer.
15
+
3
16
  ## 0.7.0
4
17
 
5
18
  ### Minor Changes
package/README.md CHANGED
@@ -170,7 +170,9 @@ so it can't be typed in while that modal is open; give the modal `disableEnforce
170
170
  `ModalProps={{ disableEnforceFocus: true }}` on a `Drawer`).
171
171
 
172
172
  - **Cmd/Ctrl+K** opens it from anywhere, or brings focus back into it when it is already open.
173
- `installKeyboardShortcuts={false}` turns off this global shortcut only.
173
+ `installKeyboardShortcuts={false}` turns off this global shortcut only. To name it in your own text, as the user's
174
+ keyboard has it, use core's `describeShortcut('K')` ("Cmd+K" on a Mac, "Ctrl+K" elsewhere), on the client: during a server
175
+ render it names the server's platform.
174
176
  - On open, focus moves to its input (to the sidekick itself in compact size); on close, focus returns to where it
175
177
  was, unless the user has since moved it elsewhere in the page. After a row is clicked, focus goes back to the
176
178
  input, so typing carries on.
@@ -179,11 +181,23 @@ so it can't be typed in while that modal is open; give the modal `disableEnforce
179
181
  - **Enter** runs the highlighted row. After every new list the highlight is on the list's first enabled row of your
180
182
  own, so the first Enter in a picker or a typed-text prompt runs it rather than Back. On a completion row (see Typed
181
183
  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.
185
- - **Tab**, with a catalog palette, first completes through the line (see Line hints). Otherwise it completes the input
186
- with the first enabled completion row, when the list has one; otherwise Tab moves focus as usual.
184
+ A line that reads several ways, a command declared `confirm`, a line read only through a rewrite, a near spelling
185
+ of a value (alone, `refnd`, or before its command's name, `in trnsit filter`), free text not declared `asTyped`, or a
186
+ lookup that could add a reading still loading beside one that could run leaves no row highlighted. Enter then runs
187
+ nothing, or for a `confirm` command, a rewritten line or a near spelling asks, so the next Enter runs it.
188
+ On a line Enter can't yet run or complete, your fallback rows aren't highlighted while Enter would ask your
189
+ producer, or while such a lookup loads; a line whose first word starts no command keeps its fallback row
190
+ highlighted while a lookup loads, unless the lookup is a `canStartCommand` param's. A line that can complete still
191
+ highlights its completion row. An arrow or the pointer highlights a row, and Enter runs it. That row stays
192
+ highlighted, in its place, while the text is the same and it still shows: rows a lookup brings then are drawn below
193
+ it, under their group's heading again when that group is already above. Once a row runs, the input
194
+ clears, and a Status row and the Enter line say "Running archive…" until it settles ("· ↵ waits until it finishes"
195
+ on the Enter line over a line typed meanwhile); no row is highlighted then, so Enter starts nothing more (an arrow, a click, Back and Cancel still act),
196
+ text typed meanwhile stays, and a run that rejects gives the text back with its error as the input's message (the
197
+ palette logs the rejection with `console.error`).
198
+ - **Tab**, with a catalog palette, first completes through the line (see Line hints): the completion row the arrows
199
+ reached, else the first. Otherwise it completes the input with the highlighted completion row, else the first enabled
200
+ one, when the list has one; otherwise Tab moves focus as usual.
187
201
  - **Arrow keys** move through the rows and wrap around at either end. Back and Cancel, when a list shows them, are
188
202
  drawn at the top under **Navigate** but come last for the keyboard: ArrowUp from the first row reaches them.
189
203
  - It is announced as a dialog named by `title` (or "ShortRound"), and its controls carry `ControlLabels`.
package/dist/react.es.js CHANGED
@@ -1,38 +1,38 @@
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({
1
+ import { createPaletteStore as ke, createSidekickStore as te, cycleCorners as Oe, RevertIntentionIds as Ee, NAVIGATE_GROUP as Ie, ControlLabels as be } from "@shortround/core";
2
+ import { useRef as d, useSyncExternalStore as z, useEffect as x, createContext as ne, useContext as oe, useMemo as $, useCallback as N, useState as U, useLayoutEffect as A, createElement as Ce, forwardRef as Te } from "react";
3
+ import { jsx as i, jsxs as k, Fragment as Le } from "react/jsx-runtime";
4
+ import xe from "tiny-invariant";
5
+ import { motion as V } from "framer-motion";
6
+ import { Command as L, useCommandState as re } from "cmdk";
7
+ function se({
8
8
  palette: e,
9
9
  defaultIntentions: t,
10
10
  resolveDefaultInput: n,
11
11
  resolveDefaultFallbackInput: o
12
12
  }) {
13
13
  const r = d(null);
14
- r.current || (r.current = ve({
14
+ r.current || (r.current = ke({
15
15
  palette: e,
16
16
  defaultIntentions: t,
17
17
  resolveDefaultInput: n,
18
18
  resolveDefaultFallbackInput: o
19
19
  }));
20
- const s = r.current, c = U(s.subscribe, s.getState, s.getState);
21
- return L(() => {
20
+ const s = r.current, c = z(s.subscribe, s.getState, s.getState);
21
+ return x(() => {
22
22
  s.setDefaults({
23
23
  palette: e,
24
24
  defaultIntentions: t,
25
25
  resolveDefaultInput: n,
26
26
  resolveDefaultFallbackInput: o
27
27
  });
28
- }, [s, e, t, n, o]), L(() => s.watchResolver(), [s]), L(() => s.watchPalette(), [s, e]), { store: s, state: c, intentions: s.rows() };
28
+ }, [s, e, t, n, o]), x(() => s.watchResolver(), [s]), x(() => s.watchPalette(), [s, e]), { store: s, state: c, intentions: s.rows() };
29
29
  }
30
- function Tt({
30
+ function At({
31
31
  defaultIntentions: e,
32
32
  resolveDefaultInput: t,
33
33
  resolveDefaultFallbackInput: n
34
34
  }) {
35
- const { store: o, state: r, intentions: s } = ce({
35
+ const { store: o, state: r, intentions: s } = se({
36
36
  defaultIntentions: e,
37
37
  resolveDefaultInput: t,
38
38
  resolveDefaultFallbackInput: n
@@ -49,7 +49,7 @@ function Tt({
49
49
  dispatchedStack: r.dispatchedStack
50
50
  };
51
51
  }
52
- const j = 0.35, xe = "100vh", Ae = Object.freeze({
52
+ const Y = 0.35, Ae = "100vh", _e = 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 j = 0.35, xe = "100vh", Ae = 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
- }), Z = Object.freeze({
62
+ }), Q = Object.freeze({
63
63
  compact: { height: "auto" },
64
64
  medium: { height: "50vh" },
65
- full: { height: xe }
66
- }), ie = "ShortRound", _e = ({ onOpen: e, installKeyboardShortcuts: t = !0 }) => {
65
+ full: { height: Ae }
66
+ }), ce = "ShortRound", Pe = ({ onOpen: e, installKeyboardShortcuts: t = !0 }) => {
67
67
  const n = d({ onOpen: e });
68
- n.current = { onOpen: e }, L(() => {
68
+ n.current = { onOpen: e }, x(() => {
69
69
  if (!t)
70
70
  return;
71
71
  const o = (r) => {
@@ -73,29 +73,29 @@ const j = 0.35, xe = "100vh", Ae = Object.freeze({
73
73
  };
74
74
  return document.addEventListener("keydown", o, { capture: !0 }), () => document.removeEventListener("keydown", o, { capture: !0 });
75
75
  }, [t]);
76
- }, ae = oe(null), K = () => re(ae);
76
+ }, ie = ne(null), F = () => oe(ie);
77
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));
78
+ const o = F(), r = d(null);
79
+ !e && !o && !r.current && (r.current = te(t));
80
80
  const s = e ?? o ?? r.current;
81
- return /* @__PURE__ */ i(ae.Provider, { value: s, children: n });
81
+ return /* @__PURE__ */ i(ie.Provider, { value: s, children: n });
82
82
  }
83
- function B(e = {}) {
84
- const t = K();
83
+ function j(e = {}) {
84
+ const t = F();
85
85
  let n = e.store || t;
86
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 = () => {
87
+ n || (o.current || (o.current = te(e.initial)), n = o.current);
88
+ const r = z(n.subscribe, n.get, n.get), s = $(() => {
89
+ const { maxTotalWidth: c, commandWidth: a, anchorOrigin: f, internalSidecarRenderer: m, size: l } = r, { height: g } = Q[l], S = `calc(${c} - ${a})`, w = (h) => n.set({ anchorOrigin: h }), R = () => {
90
+ w(Oe(f));
91
+ }, O = () => {
92
92
  if (m)
93
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: Ae[f],
98
+ anchorPosition: _e[f],
99
99
  onOpen: () => n.set({ isOpen: !0 }),
100
100
  setIsOpen: (h) => {
101
101
  n.set({ isOpen: h });
@@ -103,50 +103,50 @@ function B(e = {}) {
103
103
  onClose: () => {
104
104
  n.clearSidecar(), n.set({ isOpen: !1 });
105
105
  },
106
- height: p,
106
+ height: g,
107
107
  setSize: (h) => {
108
- Le(Z[h], `Unknown size: ${h}`), n.set({ size: h });
108
+ xe(Q[h], `Unknown size: ${h}`), n.set({ size: h });
109
109
  },
110
110
  setAnchorOrigin: w,
111
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: g,
115
+ sidecarWidth: S,
116
116
  closeSidecar: n.closeSidecar,
117
- renderSidecar: E
117
+ renderSidecar: O
118
118
  };
119
119
  }, [n, r]);
120
120
  return { ...r, ...s };
121
121
  }
122
- const ue = oe(null), M = () => re(ue), Lt = () => M()?.components ?? null;
123
- function xt() {
124
- const e = M();
122
+ const ae = ne(null), G = () => oe(ae), _t = () => G()?.components ?? null;
123
+ function Pt() {
124
+ const e = G();
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 ee(e) {
129
+ function Z(e) {
130
130
  (e.querySelector("[cmdk-input]") ?? e).focus();
131
131
  }
132
- function Pe() {
133
- const e = d(null), t = d(null), n = G((r) => {
132
+ function We() {
133
+ const e = d(null), t = d(null), n = N((r) => {
134
134
  if (r) {
135
- t.current = document.activeElement, e.current = r, ee(r);
135
+ t.current = document.activeElement, e.current = r, Z(r);
136
136
  return;
137
137
  }
138
138
  const s = e.current, c = t.current;
139
139
  e.current = null, t.current = null;
140
140
  const a = document.activeElement;
141
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);
142
+ }, []), o = N(() => {
143
+ e.current && Z(e.current);
144
144
  }, []);
145
145
  return { attachDialog: n, focusInside: o };
146
146
  }
147
- function We(e) {
148
- const [t, n] = V(0), o = d(1 / 0);
149
- return x(() => {
147
+ function Ne(e) {
148
+ const [t, n] = U(0), o = d(1 / 0);
149
+ return A(() => {
150
150
  const r = e.current;
151
151
  if (!r || typeof ResizeObserver > "u")
152
152
  return;
@@ -159,23 +159,23 @@ function We(e) {
159
159
  return c.observe(r), () => c.disconnect();
160
160
  }, [e]), t;
161
161
  }
162
- const Fe = { subscribe: () => () => {
162
+ const $e = { subscribe: () => () => {
163
163
  }, getState: () => 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);
164
+ function Fe({ palette: e, disableLineHints: t, store: n }) {
165
+ const o = typeof e?.commandLine == "function" && !t, r = o ? n.commandLine() : null, s = r ?? $e, c = z(s.subscribe, s.getState, s.getState);
166
166
  return { canShowHints: o, lineState: r ? c : null, complete: () => !n.commandLine() || !n.completeFirst() ? null : n.commandLine()?.getState().caret ?? null };
167
167
  }
168
- const Ge = new Set(Object.values(ke)), te = (e, t) => t[e] ?? t.unknown, N = (e, t) => e ? be(e, t) : void 0;
168
+ const Ge = new Set(Object.values(Ee)), ee = (e, t) => t[e] ?? t.unknown, W = (e, t) => e ? Ce(e, t) : void 0;
169
169
  function He(e, { registry: t = {}, themeIcons: n = {} }) {
170
170
  const o = t.intentions?.[e.id];
171
171
  if (o)
172
- return N(o);
172
+ return W(o);
173
173
  if (!e.icon)
174
174
  return;
175
175
  if (Ge.has(e.id))
176
- return N(te(e.icon, n));
176
+ return W(ee(e.icon, n));
177
177
  const r = t.names?.[e.icon] ?? e.icon;
178
- return t.Icon ? N(t.Icon, { name: r }) : N(te(r, n));
178
+ return t.Icon ? W(t.Icon, { name: r }) : W(ee(r, n));
179
179
  }
180
180
  const Ke = [
181
181
  "fontFamily",
@@ -196,7 +196,7 @@ const Ke = [
196
196
  ];
197
197
  function Me({ children: e, inputRef: t, lineState: n }) {
198
198
  const o = d(null), r = !!n;
199
- return x(() => {
199
+ return A(() => {
200
200
  const s = t.current, c = o.current;
201
201
  if (!s)
202
202
  return;
@@ -204,17 +204,17 @@ function Me({ children: e, inputRef: t, lineState: n }) {
204
204
  s.style.color = "", s.style.caretColor = "";
205
205
  return;
206
206
  }
207
- Ue(s, c);
207
+ Ve(s, c);
208
208
  const a = () => {
209
209
  c.scrollLeft = s.scrollLeft;
210
210
  };
211
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 }) }),
212
+ }), /* @__PURE__ */ k("div", { "data-testid": "shortround-line-input", style: ze, children: [
213
+ r && /* @__PURE__ */ i("div", { "aria-hidden": !0, "data-testid": "shortround-line-shadow", ref: o, style: Ue, children: /* @__PURE__ */ i(Ye, { state: n }) }),
214
214
  e
215
215
  ] });
216
216
  }
217
- const $e = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0 }, ze = {
217
+ const ze = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0 }, Ue = {
218
218
  position: "absolute",
219
219
  pointerEvents: "none",
220
220
  whiteSpace: "pre",
@@ -224,7 +224,7 @@ const $e = { position: "relative", flex: "1 1 auto", width: "100%", minWidth: 0
224
224
  // The shadow is sized from the input's offset box, which includes padding and border.
225
225
  boxSizing: "border-box"
226
226
  };
227
- function Ue(e, t) {
227
+ function Ve(e, t) {
228
228
  const n = window.getComputedStyle(e);
229
229
  e.style.color !== "transparent" && (t.style.color = n.color, e.style.caretColor = n.color, e.style.color = "transparent"), Ke.forEach((o) => {
230
230
  t.style[o] = n[o];
@@ -235,27 +235,27 @@ function Ue(e, t) {
235
235
  height: `${e.offsetHeight}px`
236
236
  });
237
237
  }
238
- function Ve({ state: e }) {
238
+ function Ye({ state: e }) {
239
239
  const t = [];
240
240
  let n = 0;
241
241
  for (const o of e.roles)
242
242
  o.start > n && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n, o.start) }, `gap-${n}`)), t.push(
243
243
  /* @__PURE__ */ i("span", { "data-role": o.role, title: o.reason, children: e.text.slice(o.start, o.end) }, o.start)
244
244
  ), n = o.end;
245
- return n < e.text.length && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n) }, `tail-${n}`)), /* @__PURE__ */ k(Te, { children: [
245
+ return n < e.text.length && t.push(/* @__PURE__ */ i("span", { children: e.text.slice(n) }, `tail-${n}`)), /* @__PURE__ */ k(Le, { children: [
246
246
  t,
247
247
  e.ghost && /* @__PURE__ */ i("span", { "data-role": "ghost", children: e.ghost })
248
248
  ] });
249
249
  }
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) {
250
+ const je = "Type a intention or search...", Be = 107, qe = { display: "flex", flexDirection: "column" }, Xe = { order: -1 }, Je = "shortround::navigate", Qe = /* @__PURE__ */ new Set(["ArrowDown", "ArrowUp", "Home", "End"]), Ze = /* @__PURE__ */ new Set(["n", "p", "j", "k"]), et = "shortround::no-row", tt = (e) => Qe.has(e.key) || e.ctrlKey && Ze.has(e.key), nt = (e) => e.nativeEvent.isComposing || e.keyCode === 229, ot = "shortround::no-group";
251
+ function rt(e) {
252
252
  const t = document.activeElement;
253
253
  e && t !== e && e.closest("[cmdk-root]")?.contains(t) && e.focus();
254
254
  }
255
- function rt({ intention: e, onSelect: t, Item: n, iconSources: o }) {
256
- const r = se((s) => s.value) === e.id.trim();
255
+ function st({ intention: e, onSelect: t, Item: n, iconSources: o }) {
256
+ const r = re((s) => s.value) === e.id.trim();
257
257
  return /* @__PURE__ */ i(
258
- T.Item,
258
+ L.Item,
259
259
  {
260
260
  "data-testid": `shortround-item-${e.id}`,
261
261
  disabled: e.disabled,
@@ -273,14 +273,20 @@ function rt({ intention: e, onSelect: t, Item: n, iconSources: o }) {
273
273
  }
274
274
  );
275
275
  }
276
- const st = (e) => e.reduce((t, n) => {
277
- const o = n.group ?? void 0;
276
+ const ue = (e) => e.group ?? void 0, ct = (e) => e.reduce((t, n) => {
277
+ const o = ue(n);
278
278
  let r = t.find((s) => s.name === o);
279
279
  return r || (r = { name: o, intentions: [] }, t.push(r)), r.intentions.push(n), t;
280
- }, []);
281
- function ct({ groupRef: e, rowIds: t }) {
282
- const n = se((r) => r.value), o = t.includes(n);
283
- return L(() => {
280
+ }, []), it = (e) => e.reduce((t, n) => {
281
+ const o = ue(n), r = t.at(-1);
282
+ if (r && r.name === o)
283
+ return r.intentions.push(n), t;
284
+ const s = t.filter((c) => c.name === o).length;
285
+ return [...t, { name: o, run: s, intentions: [n] }];
286
+ }, []), at = ({ name: e, run: t = 0 }) => `${e ?? ot}${t ? `#${t}` : ""}`;
287
+ function ut({ groupRef: e, rowIds: t }) {
288
+ const n = re((r) => r.value), o = t.includes(n);
289
+ return x(() => {
284
290
  if (!o)
285
291
  return;
286
292
  const r = requestAnimationFrame(
@@ -289,13 +295,13 @@ function ct({ groupRef: e, rowIds: t }) {
289
295
  return () => cancelAnimationFrame(r);
290
296
  }, [n, o, e]), null;
291
297
  }
292
- function it(e) {
298
+ function lt(e) {
293
299
  const t = d(null);
294
- return x(() => {
300
+ return A(() => {
295
301
  t.current !== null && e.current && (e.current.setSelectionRange(t.current, t.current), t.current = null);
296
302
  }), t;
297
303
  }
298
- function at({
304
+ function dt({
299
305
  palette: e,
300
306
  defaultIntentions: t,
301
307
  resolveDefaultInput: n,
@@ -307,113 +313,116 @@ function at({
307
313
  label: f,
308
314
  disableLineHints: m = !1
309
315
  }) {
310
- const { store: l, state: p, intentions: g } = ce({
316
+ const { store: l, state: g, intentions: S } = se({
311
317
  palette: e,
312
318
  defaultIntentions: t,
313
319
  resolveDefaultInput: n,
314
320
  resolveDefaultFallbackInput: o
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 = () => {
321
+ }), { inputValue: w, inputMessage: R, enterLine: O, revertIntentions: h, isHighlightChosen: v } = g, { height: b, onClose: C } = j(), H = F(), y = d(null), P = d(null), K = Ne(P), D = d(null), M = lt(y), T = Fe({ palette: e, disableLineHints: m, store: l }), le = $(
322
+ () => v ? it(S) : ct(S),
323
+ [S, v]
324
+ ), [de, he] = U(0), fe = g.highlightedId?.trim() ?? `${et}:${de}`, _ = d(!1), B = () => {
316
325
  _.current = !0, queueMicrotask(() => {
317
326
  _.current = !1;
318
327
  });
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);
328
+ }, me = (u) => {
329
+ const p = _.current;
330
+ if (_.current = !1, l.getState().highlightedId === void 0 && !p) {
331
+ he((I) => I + 1);
325
332
  return;
326
333
  }
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);
334
+ const E = [...S, ...h].find(({ id: I }) => I.trim() === u);
335
+ l.highlight(E?.id ?? u);
331
336
  }, 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
+ _.current = !1, l.changeInput(u, y.current?.selectionStart);
337
338
  }, ge = (u) => {
339
+ const { value: p, selectionStart: E } = u.target, I = l.commandLine()?.getState();
340
+ I && p === l.getState().inputValue && I.caret !== E && l.changeInput(p, E);
341
+ }, Se = () => {
342
+ const u = T.complete();
343
+ return u !== null ? (M.current = u, !0) : l.completeFirst();
344
+ }, we = (u) => {
338
345
  if (u.key === "Tab" && Se()) {
339
346
  u.preventDefault(), y.current?.focus();
340
347
  return;
341
348
  }
342
- if (et(u)) {
343
- q();
349
+ if (tt(u)) {
350
+ B();
344
351
  return;
345
352
  }
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
+ u.key === "Enter" && !nt(u) && !l.getState().highlightedId && (u.preventDefault(), l.pressEnter());
354
+ }, Re = async (u) => {
355
+ rt(y.current);
356
+ const p = await l.select(u, { sidekickStore: H, defaultSidecarRenderer: r }).catch((E) => console.error("ShortRoundPalette: an intention failed", { id: u, error: E }));
357
+ if (p) {
358
+ if (p.isCompletion) {
359
+ y.current?.focus();
360
+ return;
361
+ }
362
+ p.isRejected || (p.message && a?.({ message: p.message }), p.shouldReset && C());
353
363
  }
354
- S.isRejected || (S.message && a?.({ message: S.message }), S.shouldReset && I());
355
- }, X = /* @__PURE__ */ i(
356
- T.Input,
364
+ }, q = /* @__PURE__ */ i(
365
+ L.Input,
357
366
  {
358
367
  "data-testid": "shortround-input",
359
- onKeyDown: ge,
360
- onSelect: pe,
361
- onValueChange: me,
362
- placeholder: Ye,
368
+ onKeyDown: we,
369
+ onSelect: ge,
370
+ onValueChange: pe,
371
+ placeholder: je,
363
372
  ref: y,
364
373
  value: w
365
374
  }
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,
375
+ ), ve = T.canShowHints ? /* @__PURE__ */ i(Me, { inputRef: y, lineState: T.lineState, children: q }) : q, X = ({ key: u, name: p, intentions: E, style: I, ref: ye }) => /* @__PURE__ */ k(L.Group, { ref: ye, style: I, children: [
376
+ /* @__PURE__ */ i(s.Group, { name: p }),
377
+ E.map((J) => /* @__PURE__ */ i(
378
+ st,
370
379
  {
371
380
  Item: s.Item,
372
381
  iconSources: c,
373
- intention: Q,
374
- onSelect: we
382
+ intention: J,
383
+ onSelect: Re
375
384
  },
376
- Q.id
385
+ J.id
377
386
  ))
378
387
  ] }, u);
379
- return /* @__PURE__ */ i(s.Frame, { height: v, children: /* @__PURE__ */ k(
380
- T,
388
+ return /* @__PURE__ */ i(s.Frame, { height: b, children: /* @__PURE__ */ k(
389
+ L,
381
390
  {
382
391
  label: f,
383
392
  loop: !0,
384
- onValueChange: fe,
393
+ onValueChange: me,
385
394
  shouldFilter: !1,
386
- value: he,
395
+ value: fe,
387
396
  children: [
388
- /* @__PURE__ */ i("div", { ref: P, children: /* @__PURE__ */ i(s.Input, { enterLine: E, input: Re, inputMessage: R }) }),
397
+ /* @__PURE__ */ i("div", { ref: P, children: /* @__PURE__ */ i(s.Input, { enterLine: O, input: ve, inputMessage: R }) }),
389
398
  /* @__PURE__ */ k(
390
- T.List,
399
+ L.List,
391
400
  {
392
- onPointerMoveCapture: q,
401
+ onPointerMoveCapture: B,
393
402
  style: {
394
- height: `calc(${v} - ${je + $}px)`,
403
+ height: `calc(${b} - ${Be + K}px)`,
395
404
  overflowY: "auto",
396
405
  padding: "8px 0"
397
406
  },
398
407
  children: [
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,
408
+ /* @__PURE__ */ i(L.Empty, { children: /* @__PURE__ */ i(s.NoMatches, { inputValue: w }) }),
409
+ /* @__PURE__ */ k("div", { style: qe, children: [
410
+ le.map((u) => X({ key: at(u), ...u })),
411
+ h.length > 0 && X({
412
+ key: Je,
413
+ name: Ie,
405
414
  intentions: h,
406
- style: qe,
407
- ref: W
415
+ style: Xe,
416
+ ref: D
408
417
  })
409
418
  ] })
410
419
  ]
411
420
  }
412
421
  ),
413
422
  /* @__PURE__ */ i(
414
- ct,
423
+ ut,
415
424
  {
416
- groupRef: W,
425
+ groupRef: D,
417
426
  rowIds: h.map(({ id: u }) => u)
418
427
  }
419
428
  )
@@ -421,7 +430,7 @@ function at({
421
430
  }
422
431
  ) });
423
432
  }
424
- function ut({
433
+ function ht({
425
434
  title: e,
426
435
  palette: t,
427
436
  defaultIntentions: n,
@@ -432,17 +441,17 @@ function ut({
432
441
  defaultSidecarRenderer: a,
433
442
  disableLineHints: f
434
443
  }) {
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]
444
+ const { onClose: m, setSize: l, anchorOrigin: g, cycleAnchorOrigin: S, height: w, size: R, commandWidth: O } = j(), { Sidekick: h, IntentionPalette: v } = s, b = G()?.icons, C = $(
445
+ () => ({ registry: b, themeIcons: s.icons }),
446
+ [b, s.icons]
438
447
  );
439
- return /* @__PURE__ */ i(Y.div, { layout: !0, transition: { duration: j, ease: "easeInOut" }, children: /* @__PURE__ */ k(h.Frame, { commandWidth: E, height: w, children: [
448
+ return /* @__PURE__ */ i(V.div, { layout: !0, transition: { duration: Y, ease: "easeInOut" }, children: /* @__PURE__ */ k(h.Frame, { commandWidth: O, height: w, children: [
440
449
  /* @__PURE__ */ i(
441
450
  h.ControlBar,
442
451
  {
443
- anchorOrigin: p,
444
- cycleAnchorOrigin: g,
445
- labels: Ie,
452
+ anchorOrigin: g,
453
+ cycleAnchorOrigin: S,
454
+ labels: be,
446
455
  onClose: m,
447
456
  setSize: l,
448
457
  size: R,
@@ -450,14 +459,14 @@ function ut({
450
459
  }
451
460
  ),
452
461
  R !== "compact" && /* @__PURE__ */ i(
453
- at,
462
+ dt,
454
463
  {
455
464
  IntentionPalette: v,
456
465
  defaultIntentions: n,
457
466
  defaultSidecarRenderer: a,
458
467
  disableLineHints: f,
459
- iconSources: b,
460
- label: e ?? ie,
468
+ iconSources: C,
469
+ label: e ?? ce,
461
470
  palette: t,
462
471
  resolveDefaultFallbackInput: r,
463
472
  resolveDefaultInput: o,
@@ -466,51 +475,51 @@ function ut({
466
475
  )
467
476
  ] }) });
468
477
  }
469
- function lt({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
478
+ function ft({ isOpen: e, renderSidecar: t, height: n, width: o, Content: r }) {
470
479
  const s = {
471
480
  open: { width: o, pointerEvents: "auto" },
472
481
  closed: { width: 0, pointerEvents: "none" }
473
482
  };
474
483
  return /* @__PURE__ */ i(
475
- Y.div,
484
+ V.div,
476
485
  {
477
486
  animate: e ? "open" : "closed",
478
487
  layout: !0,
479
488
  style: { display: "flex", overflow: "hidden", opacity: 1 },
480
- transition: { duration: j, ease: "easeInOut" },
489
+ transition: { duration: Y, ease: "easeInOut" },
481
490
  variants: s,
482
491
  children: /* @__PURE__ */ i(r, { height: n, isOpen: e, renderSidecar: t })
483
492
  }
484
493
  );
485
494
  }
486
- function dt(e, t) {
495
+ function mt(e, t) {
487
496
  const n = d(e), o = d(t);
488
- o.current = t, L(() => {
497
+ o.current = t, x(() => {
489
498
  n.current && !e && o.current?.(), n.current = e;
490
499
  }, [e]);
491
500
  }
492
- function ht(e, t, { sidecarReducer: n, defaultSidecarRenderer: o, palette: r }) {
501
+ function pt(e, t, { sidecarReducer: n, defaultSidecarRenderer: o, palette: r }) {
493
502
  const s = d(n);
494
503
  s.current = n;
495
504
  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(() => {
505
+ f.current = a, A(() => (e.setSidecarReducer(
506
+ (...m) => (s.current ?? ((l, g) => g))(...m)
507
+ ), () => e.setSidecarReducer(void 0)), [e]), A(() => {
499
508
  t && !c.current ? e.changeSidecar({ renderer: f.current() ?? null }, "open") : !t && c.current && e.clearSidecar(), c.current = t;
500
509
  }, [e, t]);
501
510
  }
502
- function ft(e, t) {
503
- x(() => {
511
+ function gt(e, t) {
512
+ A(() => {
504
513
  document.activeElement === document.body && t();
505
514
  }, [e, t]);
506
515
  }
507
- const mt = {
516
+ const St = {
508
517
  display: "flex",
509
518
  flexDirection: "inherit",
510
519
  alignItems: "inherit",
511
520
  width: "100%",
512
521
  height: "100%"
513
- }, pt = Ce(function({ name: t, onClose: n, children: o }, r) {
522
+ }, wt = Te(function({ name: t, onClose: n, children: o }, r) {
514
523
  return /* @__PURE__ */ i(
515
524
  "div",
516
525
  {
@@ -521,13 +530,13 @@ const mt = {
521
530
  },
522
531
  ref: r,
523
532
  role: "dialog",
524
- style: mt,
533
+ style: St,
525
534
  tabIndex: -1,
526
535
  children: o
527
536
  }
528
537
  );
529
538
  });
530
- function St({
539
+ function Rt({
531
540
  title: e,
532
541
  palette: t,
533
542
  defaultIntentions: n,
@@ -539,51 +548,51 @@ function St({
539
548
  notifyClose: f,
540
549
  sidecarReducer: m,
541
550
  defaultSidecarRenderer: l,
542
- disableLineHints: p
551
+ disableLineHints: g
543
552
  }) {
544
553
  const {
545
- isSidecarOpen: g,
554
+ isSidecarOpen: S,
546
555
  anchorOrigin: w,
547
556
  renderSidecar: R,
548
- height: E,
557
+ height: O,
549
558
  sidecarWidth: h,
550
559
  isOpen: v,
551
- anchorPosition: I,
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,
560
+ anchorPosition: b,
561
+ totalWidth: C,
562
+ size: H,
563
+ onOpen: y,
564
+ onClose: P
565
+ } = j(), { Sidekick: K, SidecarContent: D } = s, { attachDialog: M, focusInside: T } = We();
566
+ return Pe({
567
+ onOpen: v ? T : y,
559
568
  installKeyboardShortcuts: a
560
- }), ft(y, F), dt(v, f), ht(K(), v, {
569
+ }), gt(H, T), mt(v, f), pt(F(), v, {
561
570
  sidecarReducer: m,
562
571
  defaultSidecarRenderer: l,
563
572
  palette: t
564
573
  }), v ? /* @__PURE__ */ i(
565
- Y.div,
574
+ V.div,
566
575
  {
567
576
  animate: {
568
- width: b
577
+ width: C
569
578
  },
570
579
  layout: !0,
571
- transition: { duration: j, ease: "easeInOut" },
580
+ transition: { duration: Y, ease: "easeInOut" },
572
581
  children: /* @__PURE__ */ i(
573
- W.Popover,
582
+ K.Popover,
574
583
  {
575
584
  anchorOrigin: w,
576
- anchorPosition: I,
577
- height: E,
578
- totalWidth: b,
579
- children: /* @__PURE__ */ k(pt, { name: e ?? ie, onClose: $, ref: A, children: [
585
+ anchorPosition: b,
586
+ height: O,
587
+ totalWidth: C,
588
+ children: /* @__PURE__ */ k(wt, { name: e ?? ce, onClose: P, ref: M, children: [
580
589
  /* @__PURE__ */ i(
581
- ut,
590
+ ht,
582
591
  {
583
592
  SidekickComponents: s,
584
593
  defaultIntentions: n,
585
594
  defaultSidecarRenderer: l,
586
- disableLineHints: p,
595
+ disableLineHints: g,
587
596
  palette: t,
588
597
  resolveDefaultFallbackInput: r,
589
598
  resolveDefaultInput: o,
@@ -592,11 +601,11 @@ function St({
592
601
  }
593
602
  ),
594
603
  /* @__PURE__ */ i(
595
- lt,
604
+ ft,
596
605
  {
597
- Content: z,
598
- height: E,
599
- isOpen: g,
606
+ Content: D,
607
+ height: O,
608
+ isOpen: S,
600
609
  renderSidecar: R,
601
610
  width: h
602
611
  }
@@ -607,23 +616,23 @@ function St({
607
616
  }
608
617
  ) : null;
609
618
  }
610
- function gt(e, t) {
611
- const n = M(), o = e ?? n?.components;
619
+ function vt(e, t) {
620
+ const n = G(), o = e ?? n?.components;
612
621
  if (!o)
613
622
  throw new Error(
614
623
  "ShortRoundSidekick has no theme: wrap the app in <ShortRoundProvider theme={…}>, or pass SidekickComponents"
615
624
  );
616
- return Rt(o), { components: o, showToast: t ?? n?.showToast };
625
+ return kt(o), { components: o, showToast: t ?? n?.showToast };
617
626
  }
618
- const wt = ["IntentionPalette", "Sidekick", "SidecarContent"];
619
- function Rt(e) {
620
- const t = wt.filter((n) => !e[n]);
627
+ const yt = ["IntentionPalette", "Sidekick", "SidecarContent"];
628
+ function kt(e) {
629
+ const t = yt.filter((n) => !e[n]);
621
630
  if (t.length > 0)
622
631
  throw new Error(
623
632
  `ShortRoundSidekick: the theme has no ${t.map((n) => `components.${n}`).join(" or ")}`
624
633
  );
625
634
  }
626
- function At({
635
+ function Dt({
627
636
  title: e,
628
637
  palette: t,
629
638
  defaultIntentions: n,
@@ -635,17 +644,17 @@ function At({
635
644
  sidekickStore: f,
636
645
  initialSidekickState: m,
637
646
  onClose: l,
638
- sidecarReducer: p,
639
- defaultSidecarRenderer: g,
647
+ sidecarReducer: g,
648
+ defaultSidecarRenderer: S,
640
649
  disableLineHints: w
641
650
  }) {
642
- const R = gt(s, c);
651
+ const R = vt(s, c);
643
652
  return /* @__PURE__ */ i(De, { initial: m, store: f, children: /* @__PURE__ */ i(
644
- St,
653
+ Rt,
645
654
  {
646
655
  SidekickComponents: R.components,
647
656
  defaultIntentions: n,
648
- defaultSidecarRenderer: g,
657
+ defaultSidecarRenderer: S,
649
658
  disableLineHints: w,
650
659
  installKeyboardShortcuts: a,
651
660
  notifyClose: l,
@@ -653,36 +662,36 @@ function At({
653
662
  resolveDefaultFallbackInput: r,
654
663
  resolveDefaultInput: o,
655
664
  showToast: R.showToast,
656
- sidecarReducer: p,
665
+ sidecarReducer: g,
657
666
  title: e
658
667
  }
659
668
  ) });
660
669
  }
661
- const vt = { isOpen: !1, message: null };
662
- function yt(e) {
670
+ const Ot = { isOpen: !1, message: null };
671
+ function Et(e) {
663
672
  const t = ["components", "Toast"].filter((n) => !e?.[n]);
664
673
  if (t.length > 0)
665
674
  throw new Error(`ShortRoundProvider: the theme has no ${t.join(" or ")}`);
666
675
  }
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(
676
+ function Wt({ theme: e, icons: t, children: n }) {
677
+ Et(e);
678
+ const [o, r] = U(Ot), s = N(({ message: m }) => r({ isOpen: !0, message: m }), []), c = N(() => r((m) => ({ ...m, isOpen: !1 })), []), a = $(
670
679
  () => ({ components: e.components, showToast: s, icons: t }),
671
680
  [e.components, s, t]
672
681
  ), { Toast: f } = e;
673
- return /* @__PURE__ */ k(ue.Provider, { value: a, children: [
682
+ return /* @__PURE__ */ k(ae.Provider, { value: a, children: [
674
683
  n,
675
684
  /* @__PURE__ */ i(f, { isOpen: o.isOpen, message: o.message, onClose: c })
676
685
  ] });
677
686
  }
678
687
  export {
679
688
  Me as LineInput,
680
- _t as ShortRoundProvider,
681
- At as ShortRoundSidekick,
689
+ Wt as ShortRoundProvider,
690
+ Dt as ShortRoundSidekick,
682
691
  De as SidekickStoreProvider,
683
- Tt as useShortRound,
684
- Lt as useShortRoundComponents,
685
- xt as useShortRoundToast,
686
- B as useSidekick,
687
- K as useSidekickStore
692
+ At as useShortRound,
693
+ _t as useShortRoundComponents,
694
+ Pt as useShortRoundToast,
695
+ j as useSidekick,
696
+ F as useSidekickStore
688
697
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@shortround/react",
3
- "version": "0.7.0",
3
+ "version": "0.8.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.7.0",
43
+ "@shortround/core": "0.8.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.7.0",
56
+ "@shortround/core": "^0.8.0",
57
57
  "react": "^18.2.0 || ^19.0.0",
58
58
  "react-dom": "^18.2.0 || ^19.0.0"
59
59
  },