@shortround/react 0.0.0-stage → 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 ADDED
@@ -0,0 +1,58 @@
1
+ # @shortround/react
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
+
21
+ ## 0.5.0
22
+
23
+ ### Major Changes
24
+
25
+ - First release. The React UI that was in `@shortround/core` up to 0.4.0, unchanged in behaviour: `ShortRoundSidekick`,
26
+ `ShortRoundProvider`, `useShortRound`, `useSidekick`, `useShortRoundToast`, `SidekickStoreProvider`,
27
+ `useSidekickStore`, the palette on cmdk, keyboard, focus and the dialog, and the theme contract's types
28
+ (`SidekickComponents`, `ShortRoundTheme`, `IconRegistry`, `ToastProps`). It draws `@shortround/core`, which it takes
29
+ as a peer (`^0.5.0`; the packages are released at one version). See MIGRATING.md, 0.5.0. Earlier history: `@shortround/core`'s CHANGELOG.
30
+ - `useShortRound` is `@shortround/core`'s `createPaletteStore` as a hook, with the same return value, plus
31
+ `revertIntentions` (the Back and Cancel rows a list asked for). Its `dispatch` chooses a row as `ShortRoundSidekick`
32
+ does: it keeps the Back and Cancel a result asks for, and a completion row sets the input.
33
+
34
+ ### Minor Changes
35
+
36
+ - Accepts React 19 as well as 18: the `react` and `react-dom` peers are `^18.2.0 || ^19.0.0`.
37
+ - The palette shows completion rows (see `@shortround/core`'s 0.5.0): choosing one, by Enter or a click, sets the
38
+ input and keeps the palette open; Tab applies the first enabled one, and otherwise moves focus as usual.
39
+ - The palette renders again when its resolver says its rows changed, and stops listening when the resolver is
40
+ replaced or the palette unmounts. The highlight returns to the first enabled row when the rows change that way; the
41
+ rule is core's palette store's (`highlightedId`), which the palette reads.
42
+ - `ShortRoundSidekick` takes `palette` (a catalog's palette, `buildPalette`'s result), instead of `defaultIntentions`
43
+ and the two resolvers: it opens on `palette.current()` with that side panel, and follows `palette.notify()` while
44
+ open. `defaultIntentions` is now optional.
45
+ - Line hints: with a palette that has `commandLine()`, the input shows each word coloured by its role and the rest of
46
+ the next word as ghost text, and Tab completes through the line wherever the caret is. On by default;
47
+ `disableLineHints` turns them off. Pickers and typed-text steps show the plain input. Each word is a `span` with
48
+ `data-role`, for themes. The hints and the typed-line rows are one reading, the palette store's line: a lookup is
49
+ called once per text, and with the caret mid-line the completion rows are the next steps at the caret.
50
+
51
+ ### Patch Changes
52
+
53
+ - In a typed-text step, choosing a row whose result brings no list (only a `message`, say) no longer turns matching
54
+ back on: `disableInputMatching` belongs to the list a result brings (`@shortround/core` 0.5.0).
55
+ - A row whose id starts or ends with a space can be chosen, and shows as highlighted. cmdk trims an item's value, so
56
+ such a row's id came back changed and choosing it did nothing; each row now reports its own id.
57
+ - Uses the app's React JSX runtime (`react/jsx-runtime`) instead of a bundled copy of React 18's, which would break
58
+ under another React. The package ships its `CHANGELOG.md`.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Christian Sepulveda
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,579 @@
1
- # Temporary Holding Version
1
+ # @shortround/react
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ShortRound for React: the command palette and sidekick, their hooks, the provider that chooses a theme, and the theme
4
+ contract. It draws [`@shortround/core`](https://github.com/csepulv/shortround/tree/main/packages/shortround-core),
5
+ which holds the palette's state, matching, the catalog engine and the constants, with no UI.
6
+
7
+ ## Installation
8
+
9
+ ```bash
10
+ npm install @shortround/core @shortround/react
11
+ ```
12
+
13
+ For the MUI theme the examples use: `npm install @shortround/mui`, with its peers (see its README).
14
+
15
+ `@shortround/core` is a peer: your app installs it, and imports the constants and stores from it. So are `react` and
16
+ `react-dom`, 18.2 or 19. The package is ES modules only. The look comes from
17
+ - a theme package like `@shortround/mui`, or
18
+ - your own components (see Custom UI Components).
19
+
20
+ It can be imported outside a browser, so your Node tests can import code that imports it.
21
+
22
+ Upgrading from an earlier version? See the
23
+ [migration guide](https://github.com/csepulv/shortround/blob/main/MIGRATING.md).
24
+
25
+ ## Choosing a theme: ShortRoundProvider
26
+
27
+ An app chooses its theme once, at its root. Below the provider, app code depends only on this package and
28
+ `@shortround/core`.
29
+
30
+ ```jsx
31
+ import { ShortRoundProvider, ShortRoundSidekick, useShortRoundToast } from '@shortround/react';
32
+ import { muiTheme } from '@shortround/mui'; // the root is the only place that names a theme
33
+
34
+ root.render(
35
+ <ShortRoundProvider theme={muiTheme}>
36
+ <App />
37
+ </ShortRoundProvider>
38
+ );
39
+
40
+ // Anywhere below:
41
+ <ShortRoundSidekick title="Short Round" defaultIntentions={intentions} />;
42
+ const { showToast } = useShortRoundToast(); // shows a toast in the theme's Toast
43
+ ```
44
+
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.
53
+ - An action's `message` is shown as a toast.
54
+ - A nested `ShortRoundProvider` wins for its subtree.
55
+ - `ShortRoundSidekick`'s `SidekickComponents` and `showToast` props (the 0.2.x way to choose a look) override the provider; each prop
56
+ overrides only its own part (slots or toast). Without a provider, `SidekickComponents` is required. Define the
57
+ slot components at module scope too: a slot component created during render remounts on every render, which
58
+ moves focus back into the palette.
59
+ - `ShortRoundProvider` and `SidekickStoreProvider` are separate: one chooses the theme, the other shares one
60
+ palette's state (see Sidekick Store).
61
+
62
+ ## A palette from a catalog
63
+
64
+ An app with a catalog hands the sidekick the palette `buildPalette` returns, instead of `defaultIntentions` and the
65
+ two resolvers:
66
+
67
+ ```jsx
68
+ <ShortRoundSidekick title="Short Round" palette={palette} />
69
+ ```
70
+
71
+ The sidekick opens on `palette.current()` (the commands the app's state allows now) with that state's side panel.
72
+ While it is open, it follows `palette.notify()`: call it when your app's state changes outside the palette, and the
73
+ list re-reads. Build the palette once. See `@shortround/core`'s
74
+ [ADOPTING-A-CATALOG.md](https://github.com/csepulv/shortround/blob/main/packages/shortround-core/ADOPTING-A-CATALOG.md).
75
+
76
+ **Line hints.** With a palette, the input shows how the line is being read: each word marked with its role, and, when the
77
+ caret is at the end of the line, the rest of the next word as ghost text (`@shortround/mui` greys it). Tab completes through the line, wherever the caret is; Enter runs the
78
+ highlighted row as before. Pickers and typed-text steps show the plain input. Turn the hints off with
79
+ `disableLineHints`:
80
+
81
+ ```jsx
82
+ <ShortRoundSidekick palette={palette} disableLineHints />
83
+ ```
84
+
85
+ A theme colours the words: each is a `span` with `data-role` (`verb`, `text`, `hint`, `param`, `value`, `unread`,
86
+ `broken`, and `ghost` for the ghost), inside the element the theme's `IntentionPalette.Input` slot already receives.
87
+ `@shortround/mui` colours them from its theme's palette. The words line up under the input on their own: they copy
88
+ the input's position and text style. A theme's `data-role` rules should change only colour and decoration: the
89
+ words sit under the input's own text, so anything that changes a word's width (weight, size, font, letter spacing)
90
+ moves the words after it away from the caret.
91
+
92
+ ## Icons
93
+
94
+ An intention's `icon` is a name. Without anything more, the theme draws its own icon for that name (see the theme's
95
+ README for its names). To use your own icons, from any library, give the provider an icon registry once:
96
+
97
+ ```jsx
98
+ const icons = {
99
+ Icon: MaterialSymbol, // draws any name: <Icon name="forum" />
100
+ names: { chat: 'forum' }, // an intention's icon name → the name Icon (or the theme) knows
101
+ intentions: { 'app.send': ChatBubble } // an icon for one intention, by its id
102
+ };
103
+
104
+ <ShortRoundProvider theme={muiTheme} icons={icons}>
105
+ <App />
106
+ </ShortRoundProvider>
107
+ ```
108
+
109
+ Each row's icon is the first that applies:
110
+
111
+ 1. the intention's entry in `intentions`, by id (even if the intention has no `icon`);
112
+ 2. none, when the intention has no `icon`; the theme keeps the space, so titles line up;
113
+ 3. for Back and Cancel, the theme's icons;
114
+ 4. otherwise the name, mapped by `names`, drawn by `Icon`;
115
+ 5. without `Icon`, the theme's icon for the name;
116
+ 6. the theme's placeholder, for a name it doesn't know.
117
+
118
+ - `Icon` draws every named row but Back and Cancel. An icon font can't tell a name it lacks, so with `Icon` the
119
+ placeholder doesn't appear.
120
+ - Back and Cancel keep the theme's icons, since your icon set may have no name for them. To change them, use
121
+ `intentions: { [RevertIntentionIds.BACK]: MyBack }`.
122
+ - Your icons draw at the size you give them.
123
+ - Define the registry at module scope (or memoize it), like the theme.
124
+
125
+ ## The side panel (sidecar)
126
+
127
+ The side panel shows content beside the palette. By default, palette navigation drives it:
128
+
129
+ - an action's result opens it (`sideEffects.sidecarRenderer`) or closes it (`sideEffects.closeSidecar`); a result
130
+ with neither leaves it as it is;
131
+ - Back replays the result of the last earlier step that brought a list (a step that only showed a message or
132
+ changed the panel doesn't count);
133
+ - Back to the start list and Cancel show the start list's panel (`defaultSidecarRenderer`), or close it;
134
+ - opening the palette shows the start list's panel, if any;
135
+ - closing the palette, however it closes, clears it. The panel never outlives the palette.
136
+
137
+ To decide changes yourself, give `ShortRoundSidekick` a `sidecarReducer`. Core proposes each change but a close, with
138
+ a reason, and applies what the reducer returns:
139
+
140
+ ```jsx
141
+ // Keep the chat across Back and Cancel, and bring it back when the palette opens again.
142
+ // (renderChat and chat.wasShowing are your app's: its chat renderer, and whether the chat showed at the last close.)
143
+ const keepChat = (current, proposed, { reason }) => {
144
+ if (reason === 'open') return chat.wasShowing ? { renderer: renderChat } : proposed;
145
+ if (['start', 'reset', 'back'].includes(reason) && current.renderer === renderChat) return current;
146
+ return proposed;
147
+ };
148
+
149
+ <ShortRoundSidekick defaultIntentions={intentions} sidecarReducer={keepChat} />
150
+ ```
151
+
152
+ - A change is `{ renderer }` or `{ renderer: null }`; `current` has the same shape. Returning `current` keeps the
153
+ panel as it is, without remounting its content.
154
+ - Reasons: `result`, `back`, `start` (Back to the start list), `reset` (Cancel), `open`, `app`.
155
+ - From app code, inside or outside React: `store.openSidecar(renderer)` and `store.closeSidecar()` (reason `app`), or
156
+ `useSidekick()`'s `setSidecarRenderer` and `closeSidecar`, which do the same. Call them while the palette is open:
157
+ opening the palette replaces a panel set while it was closed, unless your reducer keeps it (returns `current` for
158
+ `open`).
159
+
160
+ ## Keyboard, focus and screen readers
161
+
162
+ The sidekick is a non-modal dialog: the page stays usable while it's open, and clicking outside doesn't close it.
163
+ A modal of your own that holds focus (such as MUI's `Drawer` or `Dialog`) pulls focus back from the sidekick's input,
164
+ so it can't be typed in while that modal is open; give the modal `disableEnforceFocus` (MUI:
165
+ `ModalProps={{ disableEnforceFocus: true }}` on a `Drawer`).
166
+
167
+ - **Cmd/Ctrl+K** opens it from anywhere, or brings focus back into it when it is already open.
168
+ `installKeyboardShortcuts={false}` turns off this global shortcut only.
169
+ - On open, focus moves to its input (to the sidekick itself in compact size); on close, focus returns to where it
170
+ was, unless the user has since moved it elsewhere in the page. After a row is clicked, focus goes back to the
171
+ input, so typing carries on.
172
+ - **Escape** closes it when pressed inside it, so Escape in your own dialogs and fields stays yours. Content inside
173
+ the sidekick (a widget in the side panel) sees Escape first and can keep it with `event.preventDefault()`.
174
+ - **Enter** runs the highlighted row. After every new list the highlight is on the list's first enabled row of your
175
+ own, so the first Enter in a picker or a typed-text prompt runs it rather than Back. On a completion row (see Typed
176
+ input), Enter completes the input instead of running anything.
177
+ - **Tab**, with a catalog palette, first completes through the line (see Line hints). Otherwise it completes the input
178
+ with the first enabled completion row, when the list has one; otherwise Tab moves focus as usual.
179
+ - **Arrow keys** move through the rows and wrap around at either end. Back and Cancel, when a list shows them, are
180
+ drawn at the top under **Navigate** but come last for the keyboard: ArrowUp from the first row reaches them.
181
+ - It is announced as a dialog named by `title` (or "ShortRound"), and its controls carry `ControlLabels`.
182
+ - `ShortRoundSidekick`'s `onClose` is called after the sidekick closes, whatever closed it: the close control,
183
+ Escape, or the app through the store.
184
+
185
+ ## Hooks
186
+
187
+ ### useShortRound
188
+
189
+ Manages the list of intentions and fuzzy matching of user input, for a palette you draw yourself. It is
190
+ `@shortround/core`'s palette store (`createPaletteStore`) as a hook.
191
+
192
+ ```jsx
193
+ import { useShortRound } from '@shortround/react';
194
+
195
+ const {
196
+ inputValue,
197
+ onInputChange,
198
+ intentions,
199
+ revertIntentions,
200
+ dispatch,
201
+ reset,
202
+ back,
203
+ inputMessage,
204
+ dispatchedStack
205
+ } = useShortRound({
206
+ defaultIntentions
207
+ });
208
+ ```
209
+
210
+ **Parameters:**
211
+ - `defaultIntentions: Intention[]` - Initial set of intentions to display
212
+ - `resolveDefaultInput?: (text: string) => Intention[]` - Turns typed text into extra rows for the default list
213
+ (see Typed input). `ShortRoundSidekick` takes the same prop
214
+ - `resolveDefaultFallbackInput?: ResolveFallbackInput` - Adds rows after the default list's matches (see Typed input).
215
+ `ShortRoundSidekick` takes the same prop
216
+
217
+ **Returns:**
218
+ - `inputValue: string` - Current input text
219
+ - `onInputChange: (value: string) => void` - Update input and trigger fuzzy matching
220
+ - `intentions: Intention[]` - Filtered intentions based on input
221
+ - `revertIntentions: Intention[]` - The Back and Cancel rows the current list asked for; draw them under Navigate
222
+ (see System Intentions)
223
+ - `dispatch: (intentionId: string) => Promise<IntentionActionResult>` - Choose a row, as `ShortRoundSidekick` does: a
224
+ completion row sets the input; any other runs, and keeps the Back and Cancel its result asks for
225
+ - `reset: () => Promise<IntentionActionResult>` - Reset to default intentions
226
+ - `back: () => Promise<IntentionActionResult>` - Go back to previous intention set
227
+ - `inputMessage?: { type: string; text: string }` - Validation message to display
228
+ - `dispatchedStack: { intention: Intention; result: IntentionActionResult }[]` - History of executed intentions,
229
+ each with the result its action returned. Back drops the step that brought the current list, and the steps after
230
+ it, and returns to the list of the last earlier step that brought one; a step whose result brings no list
231
+ (`intentions`) leaves the list, and its Back and Cancel, as they are
232
+
233
+ ### useSidekick
234
+
235
+ UI controller that manages the popover (overlay) and sidekick drawer.
236
+
237
+ ```jsx
238
+ import { useSidekick } from '@shortround/react';
239
+
240
+ const {
241
+ isOpen,
242
+ isSidecarOpen,
243
+ onOpen,
244
+ onClose,
245
+ setSidecarRenderer,
246
+ closeSidecar,
247
+ height,
248
+ anchorOrigin,
249
+ cycleAnchorOrigin,
250
+ // ... other properties
251
+ } = useSidekick({
252
+ store, // optional: external store
253
+ initial: { size: 'medium' } // optional: initial state
254
+ });
255
+ ```
256
+
257
+ **Parameters:**
258
+ - `store?: SidekickStore` - External store instance
259
+ - `initial?: Partial<SidekickStoreState>` - Initial state overrides, used only when there is no `store` and no
260
+ `SidekickStoreProvider` above
261
+
262
+ **Returns:** Full sidekick state and control methods (see TypeScript definitions for complete interface). Among
263
+ them, `anchorPosition` is the CSS position for the current `anchorOrigin`; it is worked out, not stored.
264
+
265
+ ## Intention Object
266
+
267
+ ```jsx
268
+ {
269
+ id: 'unique-identifier',
270
+ title: 'Display Name',
271
+ group: 'Category Name', // optional: rows without one share one unnamed group
272
+ aliases: ['search', 'terms'], // optional
273
+ icon: 'icon-name', // optional: a name (see Icons)
274
+ disabled: false, // optional
275
+ completion: 'search grid with ', // optional: a completion row sets the input to this; action isn't called
276
+ validate: (input) => ({ valid: input.length > 0, message: 'Type a name first' }), // optional: a returned message shows
277
+ action: async (input) => {
278
+ // Your logic here
279
+ return {
280
+ intentions: newIntentions, // optional: new intention set
281
+ shouldReset: false, // optional: close palette
282
+ disableInputMatching: false, // optional, with intentions: that list ignores typed text (a typed-text step)
283
+ resolveInput: (text) => [], // optional: rows from typed text, for the new list (see Typed input)
284
+ includeRevertIntentions: [RevertIntentionIds.BACK], // optional: add back/cancel
285
+ message: 'Success!', // optional: toast notification
286
+ sideEffects: {
287
+ sidecarRenderer: () => <MyComponent /> // optional: show sidekick content
288
+ }
289
+ };
290
+ }
291
+ }
292
+ ```
293
+
294
+ ## Typed input
295
+
296
+ A resolver turns what the user types into rows of its own, so a line such as `sort created newest` can become one
297
+ row that runs directly. The default list's resolver is `resolveDefaultInput`; a list an action returns brings its
298
+ own as `resolveInput`, or none.
299
+
300
+ - Resolved rows show first, then the fuzzy matches; a resolved row with a listed row's id replaces it.
301
+ - Back restores the previous list's resolver.
302
+ - A resolver runs on every render while text is typed, so keep it quick and synchronous. One that throws adds no
303
+ rows and logs why. It adds nothing during a typed-text step (`disableInputMatching`).
304
+ - Memoize it, like `defaultIntentions`: a new resolver resets the list and the input.
305
+ - A resolver whose rows can change while the input doesn't (an async lookup landed) may carry
306
+ `subscribe(listener)`, returning a function that stops the listening. The palette subscribes to the current
307
+ resolver, renders again each time the listener is called, and unsubscribes when the resolver is replaced or the
308
+ palette unmounts.
309
+
310
+ ```js
311
+ const resolveInput = (text) => engine.rowsFor(text); // (engine is your app's)
312
+ resolveInput.subscribe = (listener) => engine.onChange(listener); // returns an unsubscribe function
313
+ ```
314
+
315
+ A row with `completion` is a completion row: choosing it (Enter or a click) sets the input to `completion` and keeps
316
+ the palette open; its `action` isn't called and Back doesn't step back over it. Tab applies the first enabled
317
+ completion row. A resolver can offer completions beside runnable rows, so a user builds a line step by step: `search`
318
+ → `search grid with ` → `search grid with tags react`.
319
+
320
+ A fallback adds rows after the matches, such as "Send as chat: <text>" for a question no command matches. The default
321
+ list's is `resolveDefaultFallbackInput`; a list an action returns brings its own as `resolveFallbackInput`, or none (a
322
+ picker, say).
323
+
324
+ ```jsx
325
+ // (chat.send is your app's.)
326
+ const sendAsChat = (text, { matches }) =>
327
+ matches.length
328
+ ? []
329
+ : [{ id: 'send-as-chat', title: `Send as chat: ${text}`, group: 'Chat', action: () => chat.send(text) }];
330
+
331
+ <ShortRoundSidekick defaultIntentions={intentions} resolveDefaultFallbackInput={sendAsChat} />
332
+ ```
333
+
334
+ - It's called while text is typed (not on a blank input, not during a typed-text step) with `matches`: what the list
335
+ shows before it, typed-line rows then fuzzy matches. Return rows only when `matches` is empty for an "unmatched"
336
+ row, or always to offer them after any matches.
337
+ - Its rows can be chosen; a row whose id is already listed is left out. They come last when their `group` is one no
338
+ match uses (`Chat` above). A row in a match's group, or with no group while ungrouped matches show, is drawn at the
339
+ end of that group, before later groups.
340
+ - Start and Cancel restore the default list's; Back restores the earlier list's.
341
+ - Keep it quick and synchronous, and memoize it: a new function resets the list and the input. So read app state that
342
+ changes (such as whether the chat shows) when the fallback runs, through a ref or a store, rather than closing over
343
+ it. One that throws adds no rows and logs why.
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
+
379
+ `@shortround/core`'s catalog engine (`loadCatalog`, `buildPalette`) builds the intentions, the resolver and (given
380
+ one) the fallback from a YAML catalog: see its
381
+ [CATALOG.md](https://github.com/csepulv/shortround/tree/main/packages/shortround-core/CATALOG.md).
382
+
383
+ ## System Intentions
384
+
385
+ ShortRound provides built-in system intentions for navigation, from `@shortround/core`:
386
+
387
+ ```jsx
388
+ import { RevertIntentionIds, makeRevertIntentionsFor } from '@shortround/core';
389
+
390
+ // Available system intentions
391
+ RevertIntentionIds.BACK // Go back to previous intention set
392
+ RevertIntentionIds.RESET // Reset to default intentions
393
+
394
+ // Include them in your action results
395
+ return {
396
+ intentions: myIntentions,
397
+ includeRevertIntentions: [RevertIntentionIds.BACK, RevertIntentionIds.RESET]
398
+ };
399
+ ```
400
+
401
+ They form a group of their own, `Navigate`, separate from any group of yours (even one with the same name), drawn
402
+ at the top of the list and last for the keyboard (see Keyboard, focus and screen readers).
403
+
404
+ `ShortRoundSidekick` draws them. A palette of your own on `useShortRound` draws the hook's `revertIntentions`, and
405
+ chooses one with `dispatch` (for example `dispatch(RevertIntentionIds.BACK)`).
406
+
407
+ ## Sidekick Store
408
+
409
+ For advanced usage, you can create and manage the sidekick store manually. The store is `@shortround/core`'s; it works
410
+ outside React too.
411
+
412
+ ```jsx
413
+ import { createSidekickStore } from '@shortround/core';
414
+ import { SidekickStoreProvider } from '@shortround/react';
415
+
416
+ const store = createSidekickStore({
417
+ size: 'full',
418
+ anchorOrigin: 'center',
419
+ commandWidth: '50vw'
420
+ });
421
+
422
+ function App() {
423
+ return (
424
+ <SidekickStoreProvider store={store}>
425
+ {/* Your components */}
426
+ </SidekickStoreProvider>
427
+ );
428
+ }
429
+ ```
430
+
431
+ To open the palette somewhere else, name the place: `createSidekickStore({ anchorOrigin: 'bottom-left' })`, or the
432
+ same in `ShortRoundSidekick`'s `initialSidekickState`. Each of the nine `AnchorPositions` is placed with CSS alone,
433
+ so it stays in place when the window is resized.
434
+
435
+ ## Constants
436
+
437
+ From `@shortround/core`:
438
+
439
+ ```jsx
440
+ import { AnchorPositions, ControlLabels, Sizes } from '@shortround/core';
441
+
442
+ // Available anchor positions
443
+ AnchorPositions.CENTER, AnchorPositions.TOP_LEFT, etc.
444
+
445
+ // Available sizes
446
+ Sizes.COMPACT, Sizes.MEDIUM, Sizes.FULL
447
+
448
+ // The control bar's accessible names, passed to a theme's ControlBar as `labels`
449
+ ControlLabels.close, ControlLabels.anchor, ControlLabels.size, ControlLabels.sizes.compact
450
+ ```
451
+
452
+ ## TypeScript Support
453
+
454
+ This package includes full TypeScript definitions. Key types:
455
+
456
+ - `UseShortRoundResult` - Hook return type
457
+ - `UseSidekickResult` - Hook return type
458
+ - `AnchorPositionStyle` - The CSS position `useSidekick` returns as `anchorPosition`
459
+ - `SidekickComponents` - Interface for custom UI implementations
460
+ - `ShortRoundTheme` - What `ShortRoundProvider` takes: `{ components, Toast }`
461
+ - `IconRegistry` - The app's own icons: `{ Icon, names, intentions }` (see Icons)
462
+ - `ToastProps` - The Toast view's props
463
+
464
+ The headless types are `@shortround/core`'s: `Intention`, `IntentionActionResult`, `SidekickStore`, `SidecarReducer`,
465
+ `SidecarChange`, `SidecarReason` (see The side panel), and `ResolveInput`, `ResolveFallbackInput` (see Typed input).
466
+
467
+ ## Custom UI Components
468
+
469
+ While we provide pre-built UI packages like `@shortround/mui`, you can create your own theme. Slots only draw:
470
+ ShortRound renders cmdk (the input, each row, keyboard and selection), moves focus and announces the sidekick, so a
471
+ theme imports no cmdk. Row styling goes in the palette frame, through cmdk's attributes (`[cmdk-item]`,
472
+ `[data-selected="true"]`). The test hooks (`data-testid`) below are the ones the conformance suite looks for.
473
+
474
+ ```jsx
475
+ const SIZES = ['compact', 'medium', 'full'];
476
+
477
+ const MySidekickComponents = {
478
+ IntentionPalette: {
479
+ Frame: ({ height, children }) => <div style={{ height }}>{children}</div>,
480
+ // `input` is ShortRound's input element; place it.
481
+ Input: ({ input, inputMessage }) => (
482
+ <div>
483
+ {input}
484
+ {inputMessage && <p>{inputMessage.text}</p>}
485
+ </div>
486
+ ),
487
+ // Drawn inside ShortRound's row, which handles click, keyboard and disabled. ShortRound chooses `icon`;
488
+ // the space stays when there is none, so titles line up.
489
+ Item: ({ intention, icon }) => (
490
+ <div>
491
+ <span style={{ display: 'inline-block', width: 18 }}>{icon}</span>
492
+ <span>{intention.title}</span>
493
+ {intention.subtitle && <small>{intention.subtitle}</small>}
494
+ </div>
495
+ ),
496
+ Group: ({ name }) => <div className="group-header">{name}</div>,
497
+ NoMatches: ({ inputValue }) => (
498
+ <div data-testid="shortround-no-matches">No matches for "{inputValue}"</div>
499
+ )
500
+ },
501
+ Sidekick: {
502
+ Frame: ({ height, commandWidth, children }) => (
503
+ <div style={{ height, width: commandWidth }}>{children}</div>
504
+ ),
505
+ // `labels` are ShortRound's accessible names (ControlLabels); apply them.
506
+ ControlBar: ({ title, labels, onClose, setSize, cycleAnchorOrigin }) => (
507
+ <div>
508
+ <span>{title}</span>
509
+ <button aria-label={labels.anchor} data-testid="shortround-anchor" onClick={cycleAnchorOrigin}>
510
+ ⌖
511
+ </button>
512
+ <div aria-label={labels.size} role="group">
513
+ {SIZES.map((size) => (
514
+ <button
515
+ aria-label={labels.sizes[size]}
516
+ data-testid={`shortround-size-${size}`}
517
+ key={size}
518
+ onClick={() => setSize(size)}
519
+ >
520
+ {size[0].toUpperCase()}
521
+ </button>
522
+ ))}
523
+ </div>
524
+ <button aria-label={labels.close} data-testid="shortround-close" onClick={onClose}>
525
+ ×
526
+ </button>
527
+ </div>
528
+ ),
529
+ Popover: ({ anchorPosition, height, totalWidth, children }) => (
530
+ <div style={{ position: 'fixed', ...anchorPosition, height, width: totalWidth, display: 'flex' }}>
531
+ {children}
532
+ </div>
533
+ )
534
+ },
535
+ SidecarContent: ({ isOpen, renderSidecar, height }) => (
536
+ <div style={{ height, display: isOpen ? 'block' : 'none' }}>
537
+ {renderSidecar?.()}
538
+ </div>
539
+ ),
540
+ // The theme's icons by name; `back` and `cancel` for Back and Cancel, `unknown` for a name it doesn't know.
541
+ // Kept with the slots, so apps passing SidekickComponents without a provider get them too.
542
+ // (SearchIcon and the others stand for your own icon components.)
543
+ icons: { search: SearchIcon, back: BackIcon, cancel: CancelIcon, unknown: UnknownIcon }
544
+ };
545
+
546
+ // A theme is the slots plus a Toast view; ShortRoundProvider holds the toast's state.
547
+ const myTheme = {
548
+ components: MySidekickComponents,
549
+ Toast: ({ isOpen, message, onClose }) =>
550
+ isOpen ? (
551
+ <div data-testid="shortround-toast" role="status" onClick={onClose}>
552
+ {message}
553
+ </div>
554
+ ) : null
555
+ };
556
+
557
+ // Use your theme at the app's root
558
+ <ShortRoundProvider theme={myTheme}>
559
+ <App />
560
+ </ShortRoundProvider>
561
+ ```
562
+
563
+ What each slot must do, beyond its props, is written in the JSDoc on `SidekickComponents` in this package's types.
564
+ To check a theme against those obligations, run the conformance suite from your theme's tests: see
565
+ [`@shortround/conformance`](https://github.com/csepulv/shortround/tree/main/packages/shortround-conformance)
566
+ (GitHub only, not on npm).
567
+
568
+ **For a complete implementation example**, see the [@shortround/mui package source code](https://github.com/csepulv/shortround/tree/main/packages/shortround-mui/src) which demonstrates proper component integration with Material-UI.
569
+
570
+ ## Other Packages
571
+
572
+ - **[@shortround/core](https://github.com/csepulv/shortround/tree/main/packages/shortround-core)** - The palette
573
+ without a UI: its state, matching, the catalog engine and the constants
574
+ - **[@shortround/mui](https://github.com/csepulv/shortround/tree/main/packages/shortround-mui)** - Material-UI components
575
+ - See the [GitHub repo](https://github.com/csepulv/shortround) for other package details and examples
576
+
577
+ ## License
578
+
579
+ MIT