@alulore/kumiko 0.17.2 → 0.18.1

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.
Files changed (95) hide show
  1. package/dist/avatar/avatar-name.d.ts +12 -0
  2. package/dist/avatar/avatar-name.js +42 -0
  3. package/dist/avatar/avatar.css +274 -0
  4. package/dist/avatar/avatar.d.ts +72 -0
  5. package/dist/avatar/avatar.js +45 -0
  6. package/dist/avatar/index.d.ts +3 -0
  7. package/dist/avatar/index.js +3 -0
  8. package/dist/board/board-api.d.ts +1 -0
  9. package/dist/board/board-selection.d.ts +1 -0
  10. package/dist/board/board-slots.d.ts +7 -0
  11. package/dist/board/board-slots.js +2 -1
  12. package/dist/board/refused-home.js +26 -1
  13. package/dist/dialog/dialog.d.ts +9 -0
  14. package/dist/dialog/dialog.js +20 -0
  15. package/dist/dialog/index.d.ts +4 -3
  16. package/dist/dialog/index.js +4 -3
  17. package/dist/drawer/drawer.css +514 -0
  18. package/dist/drawer/drawer.d.ts +55 -0
  19. package/dist/drawer/drawer.js +43 -0
  20. package/dist/drawer/index.d.ts +2 -0
  21. package/dist/drawer/index.js +2 -0
  22. package/dist/file-input/file-dropzone.d.ts +67 -0
  23. package/dist/file-input/file-dropzone.js +97 -0
  24. package/dist/file-input/file-input.css +505 -0
  25. package/dist/file-input/file-input.d.ts +29 -0
  26. package/dist/file-input/file-input.js +21 -0
  27. package/dist/file-input/file-preview.d.ts +15 -0
  28. package/dist/file-input/file-preview.js +41 -0
  29. package/dist/file-input/index.d.ts +4 -0
  30. package/dist/file-input/index.js +4 -0
  31. package/dist/hover-card/hover-card.js +2 -0
  32. package/dist/media-viewer/index.d.ts +1 -0
  33. package/dist/media-viewer/index.js +1 -0
  34. package/dist/media-viewer/labels.d.ts +27 -0
  35. package/dist/media-viewer/labels.js +23 -0
  36. package/dist/media-viewer/media-viewer.d.ts +3 -0
  37. package/dist/media-viewer/media-viewer.js +6 -3
  38. package/dist/media-viewer/video-controls.js +4 -2
  39. package/dist/media-viewer/viewer-chrome.js +11 -5
  40. package/dist/menu/menu.js +2 -0
  41. package/dist/motion/settle-close.d.ts +5 -0
  42. package/dist/motion/settle-close.js +78 -0
  43. package/dist/otp-input/index.d.ts +2 -0
  44. package/dist/otp-input/index.js +2 -0
  45. package/dist/otp-input/otp-input.css +336 -0
  46. package/dist/otp-input/otp-input.d.ts +56 -0
  47. package/dist/otp-input/otp-input.js +44 -0
  48. package/dist/popover/index.d.ts +2 -1
  49. package/dist/popover/index.js +2 -1
  50. package/dist/popover/popover.d.ts +3 -0
  51. package/dist/popover/popover.js +8 -0
  52. package/dist/server-render.test.d.ts +1 -0
  53. package/dist/server-render.test.js +57 -0
  54. package/dist/shortcuts/bindings.d.ts +23 -3
  55. package/dist/shortcuts/bindings.js +15 -9
  56. package/dist/shortcuts/bound.d.ts +15 -0
  57. package/dist/shortcuts/bound.js +55 -0
  58. package/dist/shortcuts/help.d.ts +7 -1
  59. package/dist/shortcuts/help.js +2 -2
  60. package/dist/shortcuts/index.d.ts +2 -1
  61. package/dist/shortcuts/index.js +1 -0
  62. package/dist/shortcuts/judge.d.ts +3 -0
  63. package/dist/shortcuts/judge.js +9 -1
  64. package/dist/shortcuts/list.d.ts +6 -1
  65. package/dist/shortcuts/list.js +6 -5
  66. package/dist/shortcuts/notes.d.ts +4 -0
  67. package/dist/shortcuts/notes.js +6 -0
  68. package/dist/shortcuts/provider.d.ts +8 -1
  69. package/dist/shortcuts/provider.js +47 -11
  70. package/dist/shortcuts/registration.d.ts +3 -1
  71. package/dist/shortcuts/registration.js +10 -2
  72. package/dist/shortcuts/shortcuts.css +5 -0
  73. package/dist/skeleton/index.d.ts +1 -0
  74. package/dist/skeleton/index.js +1 -0
  75. package/dist/skeleton/skeleton.css +143 -0
  76. package/dist/skeleton/skeleton.d.ts +44 -0
  77. package/dist/skeleton/skeleton.js +22 -0
  78. package/dist/smooth-caret/smooth-caret.css +4 -2
  79. package/dist/tabs/index.d.ts +2 -0
  80. package/dist/tabs/index.js +2 -0
  81. package/dist/tabs/tabs.css +616 -0
  82. package/dist/tabs/tabs.d.ts +51 -0
  83. package/dist/tabs/tabs.js +20 -0
  84. package/dist/titlebar/index.d.ts +1 -1
  85. package/dist/titlebar/index.js +1 -1
  86. package/dist/titlebar/titlebar.d.ts +15 -2
  87. package/dist/titlebar/titlebar.js +18 -9
  88. package/dist/toast/index.d.ts +2 -1
  89. package/dist/toast/index.js +2 -1
  90. package/dist/tooltip/tooltip.js +2 -0
  91. package/dist/undo/index.d.ts +1 -1
  92. package/dist/undo/index.js +1 -1
  93. package/dist/undo/undo-keys.d.ts +7 -0
  94. package/dist/undo/undo-keys.js +18 -7
  95. package/package.json +59 -5
@@ -0,0 +1,55 @@
1
+ import { registerShortcut } from "@ui-sdk/react/shortcuts";
2
+ import { useEffect, useRef } from "react";
3
+ import { defaultKeys, maxKeysPerAction } from "./bindings";
4
+ import { holdOverDialogs, overDialogsLayer } from "./over-dialogs";
5
+ import { useOptionalShortcuts } from "./provider";
6
+ /** Registers an action's own keys plainly, as a shortcut that is not listed or rebindable. */
7
+ function usePlain(latest, enabled) {
8
+ const overDialogs = latest.current.overDialogs ?? false;
9
+ useEffect(() => {
10
+ if (!enabled) {
11
+ return undefined;
12
+ }
13
+ const offs = [];
14
+ if (overDialogs) {
15
+ offs.push(holdOverDialogs());
16
+ }
17
+ for (let slot = 0; slot < maxKeysPerAction; slot += 1) {
18
+ offs.push(registerShortcut(() => defaultKeys(latest.current)[slot], (event) => latest.current.run(event), {
19
+ description: latest.current.description,
20
+ allowInInput: latest.current.allowInInput ?? false,
21
+ layer: overDialogs ? overDialogsLayer : undefined,
22
+ when: () => latest.current.when?.() ?? true
23
+ }));
24
+ }
25
+ return () => {
26
+ for (const off of offs) {
27
+ off();
28
+ }
29
+ };
30
+ }, [enabled, overDialogs, latest]);
31
+ }
32
+ /**
33
+ * Gives an action the code that runs it, from wherever that code lives in the tree.
34
+ *
35
+ * When the nearest `ShortcutsProvider` declares the same `id`, this binds `run` and `when` to that declaration:
36
+ * the provider's keys, saved changes, section and description win, and its `allowInInput`, `overDialogs` and
37
+ * pause rules apply. The binding goes when the component unmounts. With two bindings for one id, the one
38
+ * mounted last runs, and the other takes over again when it goes. The latest `run` and `when` are read on every
39
+ * key press, so they need not be stable.
40
+ *
41
+ * Without a provider, or when the provider does not declare the id, the action's own default keys are
42
+ * registered plainly, as a shortcut that is not listed and cannot be rebound. A hook can serve an app with
43
+ * a provider and one without.
44
+ */
45
+ export function useShortcutAction(action) {
46
+ const shortcuts = useOptionalShortcuts();
47
+ const latest = useRef(action);
48
+ useEffect(() => {
49
+ latest.current = action;
50
+ });
51
+ const declared = shortcuts?.actions.some((item) => item.id === action.id) ?? false;
52
+ const bind = shortcuts?.bind;
53
+ useEffect(() => (declared && bind ? bind(action.id, latest) : undefined), [declared, bind, action.id]);
54
+ usePlain(latest, !declared);
55
+ }
@@ -35,5 +35,11 @@ export type ShortcutsHelpProps = TriggerProps & {
35
35
  /** A button that opens the help sheet: what can run now, by section. Its keys (`helpKeys`) open it too. */
36
36
  export declare function ShortcutsHelp({ presentation, editable, label, title, description, className, ...trigger }: ShortcutsHelpProps): React.JSX.Element;
37
37
  /** Rebinding on its own, for apps that keep it in a settings page instead of the help sheet. */
38
- export declare function ShortcutsSettings(): React.JSX.Element;
38
+ export declare function ShortcutsSettings({ notes }: {
39
+ /**
40
+ * Whether fixed keys are listed too, read-only.
41
+ * @defaultValue true
42
+ */
43
+ notes?: boolean;
44
+ }): React.JSX.Element;
39
45
  export {};
@@ -31,6 +31,6 @@ export function ShortcutsHelp({ presentation = "dialog", editable = false, label
31
31
  return (_jsxs(Dialog, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(DialogTrigger, { ...trigger, render: render, className: className, children: label }), _jsx(DialogBackdrop, {}), _jsxs(DialogContent, { className: "kumiko-shortcuts-dialog", "data-kumiko-shortcuts": presentation, children: [_jsx(DialogTitle, { children: title }), description ? _jsx(DialogDescription, { children: description }) : null, _jsx(Body, { presentation: presentation, editable: editable, closer: _jsx(DialogClose, { render: _jsx(Button, { variant: "outline", size: "sm" }), children: "Close" }) })] })] }));
32
32
  }
33
33
  /** Rebinding on its own, for apps that keep it in a settings page instead of the help sheet. */
34
- export function ShortcutsSettings() {
35
- return (_jsx("div", { className: "kumiko-shortcuts-sheet", "data-presentation": "settings", children: _jsx(ShortcutsList, { editing: true }) }));
34
+ export function ShortcutsSettings({ notes = true }) {
35
+ return (_jsx("div", { className: "kumiko-shortcuts-sheet", "data-presentation": "settings", children: _jsx(ShortcutsList, { editing: true, notes: notes }) }));
36
36
  }
@@ -1,4 +1,5 @@
1
- export { type ShortcutAction, type Overrides } from "./bindings";
1
+ export { type BoundShortcutAction, type ShortcutAction, type Overrides } from "./bindings";
2
+ export { useShortcutAction } from "./bound";
2
3
  export { reportDrag, useIsDragging, useReportDrag } from "./guard";
3
4
  export { ShortcutsHelp, ShortcutsSettings, type HelpPresentation, type ShortcutsHelpProps } from "./help";
4
5
  export { ShortcutBadgesButton, ShortcutHint, type ShortcutHintProps } from "./hints";
@@ -1,4 +1,5 @@
1
1
  export {} from "./bindings";
2
+ export { useShortcutAction } from "./bound";
2
3
  export { reportDrag, useIsDragging, useReportDrag } from "./guard";
3
4
  export { ShortcutsHelp, ShortcutsSettings } from "./help";
4
5
  export { ShortcutBadgesButton, ShortcutHint } from "./hints";
@@ -1,4 +1,5 @@
1
1
  import { type Overrides, type Resolution, type ShortcutAction } from "./bindings";
2
+ import { type ShortcutNote } from "./notes";
2
3
  /** The reserved-keys and taken-keys choices a verdict depends on. */
3
4
  export interface JudgeOptions {
4
5
  reserved: "block" | "warn";
@@ -39,4 +40,6 @@ export declare function judge(context: {
39
40
  actions: readonly ShortcutAction[];
40
41
  overrides: Overrides;
41
42
  options: JudgeOptions;
43
+ /** Keys a widget handles itself. No action can take them. */
44
+ notes?: readonly ShortcutNote[];
42
45
  }, target: Target, raw: string, allowReserved: boolean): Verdict;
@@ -1,8 +1,9 @@
1
1
  import { keysOf, ownerOf } from "./bindings";
2
2
  import { canonicalKeys, describeKeys } from "./keys";
3
+ import { noteOwning } from "./notes";
3
4
  /** Decides what happens to new keys: used, refused with a reason, or a question first. */
4
5
  export function judge(context, target, raw, allowReserved) {
5
- const { actions, overrides, options } = context;
6
+ const { actions, overrides, options, notes = [] } = context;
6
7
  const action = actions.find((item) => item.id === target.id);
7
8
  const keys = canonicalKeys(raw);
8
9
  const own = action ? keysOf(action, overrides) : [];
@@ -18,6 +19,13 @@ export function judge(context, target, raw, allowReserved) {
18
19
  ? { kind: "refused", message: `${describeKeys(keys)} is reserved. ${reason}` }
19
20
  : { kind: "ask", pending: { kind: "reserved", keys, reason } };
20
21
  }
22
+ const fixed = noteOwning(notes, keys);
23
+ if (fixed) {
24
+ return {
25
+ kind: "refused",
26
+ message: `${describeKeys(keys)} is fixed for “${fixed.description}”.`
27
+ };
28
+ }
21
29
  const owner = ownerOf(actions, overrides, keys, target.id);
22
30
  if (!owner) {
23
31
  return { kind: "bind", keys, how: "plain" };
@@ -11,6 +11,11 @@ export interface ShortcutsListProps {
11
11
  all?: boolean;
12
12
  /** Keeps only actions whose name or section contains this text. */
13
13
  query?: string;
14
+ /**
15
+ * Whether keys that are fixed (`notes` on the provider) are listed too, read-only, with their reason.
16
+ * @defaultValue true
17
+ */
18
+ notes?: boolean;
14
19
  }
15
20
  /** The actions grouped by section, each with its keys. With `editing`, every key can be changed. */
16
- export declare function ShortcutsList({ editing, all, query }: ShortcutsListProps): React.JSX.Element;
21
+ export declare function ShortcutsList({ editing, all, query, notes: showNotes }: ShortcutsListProps): React.JSX.Element;
@@ -33,17 +33,18 @@ function Row({ action, editing, rebinder }) {
33
33
  return (_jsxs("li", { "data-unavailable": available.has(action.id) ? undefined : "", children: [_jsx("span", { className: "kumiko-shortcuts-name", children: action.description }), editing ? (_jsx(KeyEditor, { action: action, rebinder: rebinder })) : (_jsx("span", { className: "kumiko-shortcuts-keys", children: keysFor(action.id).map((key) => (_jsx(Kbd, { keys: key, listen: false }, key))) })), rebinder.target?.id === action.id ? _jsx(Capture, { rebinder: rebinder }) : null] }));
34
34
  }
35
35
  function NoteRow({ note }) {
36
- return (_jsxs("li", { "data-note": "", children: [_jsx("span", { className: "kumiko-shortcuts-name", children: note.description }), _jsx("span", { className: "kumiko-shortcuts-keys", children: noteKeys(note).map((key) => (_jsx(Kbd, { keys: key, listen: false }, key))) })] }));
36
+ return (_jsxs("li", { "data-note": "", children: [_jsx("span", { className: "kumiko-shortcuts-name", children: note.description }), _jsxs("span", { className: "kumiko-shortcuts-keys", children: [note.reason ? (_jsx("span", { className: "kumiko-shortcuts-reason", children: note.reason })) : null, noteKeys(note).map((key) => (_jsx(Kbd, { keys: key, listen: false }, key)))] })] }));
37
37
  }
38
38
  function EditFooter() {
39
- const { resetAll, overrides, options, saveFailed } = useShortcuts();
40
- return (_jsxs(_Fragment, { children: [saveFailed ? (_jsx("p", { className: "kumiko-shortcuts-message", role: "alert", children: "Your changes could not be saved. They last until the page closes." })) : null, Object.keys(overrides).length > 0 ? (_jsx("p", { children: _jsx(Button, { variant: "outline", size: "sm", type: "button", onClick: resetAll, children: "Reset all" }) })) : null, options.multipleKeys ? null : (_jsx("p", { className: "kumiko-shortcuts-empty", children: "Each action has one key." }))] }));
39
+ const { resetAll, overrides, actions, options, saveFailed } = useShortcuts();
40
+ const changed = actions.some((action) => action.id in overrides);
41
+ return (_jsxs(_Fragment, { children: [saveFailed ? (_jsx("p", { className: "kumiko-shortcuts-message", role: "alert", children: "Your changes could not be saved. They last until the page closes." })) : null, changed ? (_jsx("p", { children: _jsx(Button, { variant: "outline", size: "sm", type: "button", onClick: resetAll, children: "Reset all" }) })) : null, options.multipleKeys ? null : (_jsx("p", { className: "kumiko-shortcuts-empty", children: "Each action has one key." }))] }));
41
42
  }
42
43
  /** The actions grouped by section, each with its keys. With `editing`, every key can be changed. */
43
- export function ShortcutsList({ editing = false, all = editing, query = "" }) {
44
+ export function ShortcutsList({ editing = false, all = editing, query = "", notes: showNotes = true }) {
44
45
  const { actions, notes, available } = useShortcuts();
45
46
  const rebinder = useRebinder();
46
47
  const needle = query.trim().toLowerCase();
47
- const sections = sectionRows(actions, notes, (action) => all || available.has(action.id), needle);
48
+ const sections = sectionRows(actions, showNotes ? notes : [], (action) => all || action.listed === "always" || available.has(action.id), needle);
48
49
  return (_jsxs("div", { className: "kumiko-shortcuts-list", "data-editing": editing ? "" : undefined, children: [sections.map(({ section, rows }) => (_jsxs("section", { children: [_jsx("h3", { children: section }), _jsx("ul", { children: rows.map((row) => row.kind === "note" ? (_jsx(NoteRow, { note: row.note }, `note:${row.note.description}`)) : (_jsx(Row, { action: row.action, editing: editing, rebinder: rebinder }, row.action.id))) })] }, section))), sections.length === 0 ? (_jsx("p", { className: "kumiko-shortcuts-empty", children: needle === "" ? "Nothing has a shortcut right now." : "No shortcut matches." })) : null, editing ? _jsx(EditFooter, {}) : null] }));
49
50
  }
@@ -7,6 +7,8 @@ export interface ShortcutNote {
7
7
  section: string;
8
8
  /** The keys, one or several, written like `"mod+k"`. */
9
9
  keys: string | readonly string[];
10
+ /** Why the keys are fixed, shown as muted text beside the note: "Board keys", "System-wide". */
11
+ reason?: string;
10
12
  }
11
13
  /** One line of the help sheet: an action people can rebind, or a note they can only read. */
12
14
  export type ShortcutRow = {
@@ -25,4 +27,6 @@ export interface ShortcutSection {
25
27
  * section the actions come first, then the notes. Notes are always shown, and a search still filters them by text.
26
28
  */
27
29
  export declare function sectionRows(actions: readonly ShortcutAction[], notes: readonly ShortcutNote[], keepAction: (action: ShortcutAction) => boolean, needle: string): ShortcutSection[];
30
+ /** The note that owns these keys, so no action can be rebound onto them. */
31
+ export declare function noteOwning(notes: readonly ShortcutNote[], keys: string): ShortcutNote | undefined;
28
32
  export declare function noteKeys(note: ShortcutNote): string[];
@@ -1,3 +1,4 @@
1
+ import { canonicalKeys } from "./keys";
1
2
  function matches(text, needle) {
2
3
  return needle === "" || text.toLowerCase().includes(needle);
3
4
  }
@@ -22,6 +23,11 @@ export function sectionRows(actions, notes, keepAction, needle) {
22
23
  rows: rows.filter((row) => sectionOf(row) === section)
23
24
  }));
24
25
  }
26
+ /** The note that owns these keys, so no action can be rebound onto them. */
27
+ export function noteOwning(notes, keys) {
28
+ const wanted = canonicalKeys(keys);
29
+ return notes.find((note) => noteKeys(note).some((key) => canonicalKeys(key) === wanted));
30
+ }
25
31
  export function noteKeys(note) {
26
32
  return typeof note.keys === "string" ? [note.keys] : [...note.keys];
27
33
  }
@@ -1,5 +1,5 @@
1
1
  import { type StoredStorage } from "../stored";
2
- import { type Overrides, type ShortcutAction } from "./bindings";
2
+ import { type BoundShortcutAction, type Overrides, type ShortcutAction } from "./bindings";
3
3
  import type { ShortcutNote } from "./notes";
4
4
  export type TakenKeys = "ask" | "refuse" | "newest";
5
5
  export type ReservedMode = "block" | "warn";
@@ -87,8 +87,15 @@ export interface ShortcutsContextValue {
87
87
  saveFailed: boolean;
88
88
  modHeld: boolean;
89
89
  setModHeld: (held: boolean) => void;
90
+ /**
91
+ * Binds code to a declared action. The binding last mounted for an id wins, and the one before it takes
92
+ * over again when that one goes. Returns the way to remove it.
93
+ */
94
+ bind: (id: string, binding: React.RefObject<BoundShortcutAction>) => () => void;
90
95
  }
91
96
  export declare function useShortcuts(): ShortcutsContextValue;
97
+ /** The shortcuts of the nearest provider, or nothing when there is none. */
98
+ export declare function useOptionalShortcuts(): ShortcutsContextValue | null;
92
99
  export type ShortcutsProviderProps = ShortcutsOptions & {
93
100
  /** What the app can do, and the keys that do it. */
94
101
  actions: readonly ShortcutAction[];
@@ -1,7 +1,7 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { createContext, use, useCallback, useEffect, useMemo, useRef, useState } from "react";
3
3
  import { defineStored, useStored } from "../stored";
4
- import { isOverrides, keysOf, sanitizeOverrides } from "./bindings";
4
+ import { isOverrides, keysOf, sanitizeOverrides, withoutActions } from "./bindings";
5
5
  import { defaultReservedKeys } from "./keys";
6
6
  import { listAvailable, useModHeld, useRegistration } from "./registration";
7
7
  const ShortcutsContext = createContext(null);
@@ -12,6 +12,10 @@ export function useShortcuts() {
12
12
  }
13
13
  return value;
14
14
  }
15
+ /** The shortcuts of the nearest provider, or nothing when there is none. */
16
+ export function useOptionalShortcuts() {
17
+ return use(ShortcutsContext);
18
+ }
15
19
  /** The saved bindings, followed live, and what to call to change them. A failed save is reported. */
16
20
  function useSavedOverrides(props, actions) {
17
21
  const { storage = "local", storageKey = "kumiko.shortcuts", onSaveError } = props;
@@ -62,6 +66,19 @@ function useResolved(props) {
62
66
  resetEach
63
67
  ]);
64
68
  }
69
+ /** The code components have bound to declared actions, newest last, read afresh on every key press. */
70
+ function useBindings() {
71
+ const stacks = useRef(new Map());
72
+ return useMemo(() => ({
73
+ bind: (id, binding) => {
74
+ stacks.current.set(id, [...(stacks.current.get(id) ?? []), binding]);
75
+ return () => {
76
+ stacks.current.set(id, (stacks.current.get(id) ?? []).filter((item) => item !== binding));
77
+ };
78
+ },
79
+ binding: (id) => stacks.current.get(id)?.at(-1)?.current
80
+ }), []);
81
+ }
65
82
  /** The help sheet's open state. The list of what can run is taken as it opens, because a modal sheet pauses the page. */
66
83
  function useHelpState(live) {
67
84
  const [helpOpen, setHelpOpen] = useState(false);
@@ -73,19 +90,15 @@ function useHelpState(live) {
73
90
  const closeHelp = useCallback(() => setHelpOpen(false), []);
74
91
  return useMemo(() => ({ helpOpen, available, openHelp, closeHelp }), [helpOpen, available, openHelp, closeHelp]);
75
92
  }
76
- /** Wraps the part of the app that has shortcuts: registers every action and holds what the help sheet and hints need. */
77
- export function ShortcutsProvider(props) {
78
- const { actions, children, notes = noNotes } = props;
79
- const options = useResolved(props);
80
- const [overrides, setOverrides, saveFailed] = useSavedOverrides(props, actions);
81
- const live = useRef({ ...options, actions, overrides, toggleHelp: () => { } });
82
- const help = useHelpState(live);
83
- const [modHeld, setModHeld] = useModHeld(options.hints === "badges");
93
+ /** Keeps what the registered shortcuts read fresh, and registers the actions through ui-sdk. */
94
+ function useRegistered(live, now) {
95
+ const { options, actions, overrides, binding, help } = now;
84
96
  useEffect(() => {
85
97
  live.current = {
86
98
  ...options,
87
99
  actions,
88
100
  overrides,
101
+ binding,
89
102
  toggleHelp: () => (help.helpOpen ? help.closeHelp() : help.openHelp())
90
103
  };
91
104
  });
@@ -94,6 +107,17 @@ export function ShortcutsProvider(props) {
94
107
  ...options.helpKeys
95
108
  ].join("|");
96
109
  useRegistration(live, signature);
110
+ }
111
+ /** Wraps the part of the app that has shortcuts: registers every action and holds what the help sheet and hints need. */
112
+ export function ShortcutsProvider(props) {
113
+ const { actions, children, notes = noNotes } = props;
114
+ const options = useResolved(props);
115
+ const [overrides, setOverrides, saveFailed] = useSavedOverrides(props, actions);
116
+ const { bind, binding } = useBindings();
117
+ const live = useRef({ ...options, actions, overrides, toggleHelp: () => { }, binding });
118
+ const help = useHelpState(live);
119
+ const [modHeld, setModHeld] = useModHeld(options.hints === "badges");
120
+ useRegistered(live, { options, actions, overrides, binding, help });
97
121
  const value = useMemo(() => ({
98
122
  ...help,
99
123
  actions,
@@ -107,10 +131,22 @@ export function ShortcutsProvider(props) {
107
131
  : [];
108
132
  },
109
133
  setOverrides,
110
- resetAll: () => setOverrides({}),
134
+ resetAll: () => setOverrides(withoutActions(overrides, actions)),
135
+ bind,
111
136
  saveFailed,
112
137
  modHeld,
113
138
  setModHeld
114
- }), [help, actions, notes, overrides, options, setOverrides, saveFailed, modHeld, setModHeld]);
139
+ }), [
140
+ help,
141
+ actions,
142
+ notes,
143
+ overrides,
144
+ options,
145
+ setOverrides,
146
+ saveFailed,
147
+ modHeld,
148
+ setModHeld,
149
+ bind
150
+ ]);
115
151
  return _jsx(ShortcutsContext, { value: value, children: children });
116
152
  }
@@ -1,4 +1,4 @@
1
- import { type Overrides, type ShortcutAction } from "./bindings";
1
+ import { type BoundShortcutAction, type Overrides, type ShortcutAction } from "./bindings";
2
2
  /** What the registered shortcuts read on every key press, kept fresh by the provider. */
3
3
  export interface Live {
4
4
  actions: readonly ShortcutAction[];
@@ -7,6 +7,8 @@ export interface Live {
7
7
  multipleKeys: boolean;
8
8
  helpKeys: readonly string[];
9
9
  toggleHelp: () => void;
10
+ /** The component bound to an action id right now: the one mounted last. */
11
+ binding: (id: string) => BoundShortcutAction | undefined;
10
12
  }
11
13
  /**
12
14
  * Registers one slot per key an action can hold, through ui-sdk. The keys are read on every key
@@ -15,11 +15,19 @@ function registerSlot(live, action, slot) {
15
15
  return current && (slot === 0 || live.current.multipleKeys)
16
16
  ? keysOf(current, live.current.overrides)[slot]
17
17
  : undefined;
18
- }, (event) => find()?.run(event), {
18
+ }, (event) => (live.current.binding(action.id)?.run ?? find()?.run)?.(event), {
19
19
  description: action.description,
20
20
  allowInInput: action.allowInInput ?? false,
21
21
  layer: action.overDialogs ? overDialogsLayer : undefined,
22
- when: () => calm(live) && (find()?.when?.() ?? true)
22
+ when: () => {
23
+ const bound = live.current.binding(action.id);
24
+ const declared = find();
25
+ /* Nothing to run means the key is left alone for whatever else wants it. */
26
+ return (calm(live) &&
27
+ (bound !== undefined || declared?.run !== undefined) &&
28
+ (declared?.when?.() ?? true) &&
29
+ (bound?.when?.() ?? true));
30
+ }
23
31
  });
24
32
  }
25
33
  /**
@@ -101,6 +101,11 @@
101
101
  border-block-end: 1px solid var(--kumiko-shortcuts-row-border);
102
102
  }
103
103
 
104
+ .kumiko-shortcuts-reason {
105
+ color: var(--kumiko-shortcuts-heading-fg);
106
+ font-size: 0.8125rem;
107
+ }
108
+
104
109
  .kumiko-shortcuts-list li[data-unavailable] .kumiko-shortcuts-name {
105
110
  opacity: 0.55;
106
111
  }
@@ -0,0 +1 @@
1
+ export { Skeleton, SkeletonGroup, SkeletonText, type SkeletonAnimation, type SkeletonGroupProps, type SkeletonProps, type SkeletonShape, type SkeletonTextProps } from "./skeleton";
@@ -0,0 +1 @@
1
+ export { Skeleton, SkeletonGroup, SkeletonText } from "./skeleton";
@@ -0,0 +1,143 @@
1
+ @import "../motion/motion.css";
2
+
3
+ /*
4
+ * Loading placeholders. The shimmer sweeps a band of light along the line's direction, timed from the spin token;
5
+ * reduced and still motion swap it for a slow pulse, a fade, which reduced motion keeps.
6
+ */
7
+ @layer kumiko {
8
+ :where(:root) {
9
+ --kumiko-skeleton-bg: color-mix(in oklab, CanvasText 9%, transparent);
10
+ --kumiko-skeleton-shine: color-mix(in oklab, CanvasText 16%, transparent);
11
+ --kumiko-skeleton-radius: 0.375rem;
12
+ --kumiko-skeleton-text-radius: 0.25rem;
13
+ --kumiko-skeleton-text-height: 0.7em;
14
+ --kumiko-skeleton-text-gap: 0;
15
+ --kumiko-skeleton-size: 1rem;
16
+ --kumiko-skeleton-band: 40%;
17
+ }
18
+
19
+ :where([data-slot="skeleton"]) {
20
+ --_skeleton-sweep: calc(var(--kumiko-spin-duration) * 2);
21
+ --_skeleton-pulse: calc(var(--kumiko-fade-duration) * 12);
22
+
23
+ display: block;
24
+ box-sizing: border-box;
25
+ inline-size: 100%;
26
+ block-size: var(--kumiko-skeleton-size);
27
+ border-radius: var(--kumiko-skeleton-radius);
28
+ background-color: var(--kumiko-skeleton-bg);
29
+ background-image: linear-gradient(
30
+ 90deg,
31
+ transparent calc(50% - var(--kumiko-skeleton-band) / 2),
32
+ var(--kumiko-skeleton-shine) 50%,
33
+ transparent calc(50% + var(--kumiko-skeleton-band) / 2)
34
+ );
35
+ background-repeat: no-repeat;
36
+ background-size: 300% 100%;
37
+ animation: kumiko-skeleton-sweep var(--_skeleton-sweep) ease-in-out infinite;
38
+ }
39
+
40
+ @keyframes kumiko-skeleton-sweep {
41
+ from {
42
+ background-position: 100% 0;
43
+ }
44
+
45
+ to {
46
+ background-position: 0 0;
47
+ }
48
+ }
49
+
50
+ /* In right-to-left text the band sweeps the other way, from the start of the line. */
51
+ :where([data-slot="skeleton"]:dir(rtl)) {
52
+ animation-direction: reverse;
53
+ }
54
+
55
+ :where([data-slot="skeleton"][data-shape="circle"]) {
56
+ flex: none;
57
+ inline-size: var(--kumiko-skeleton-size);
58
+ aspect-ratio: 1;
59
+ block-size: auto;
60
+ border-radius: 50%;
61
+ }
62
+
63
+ /* A line of text: a bar as tall as the text's letters, centred in a line box of the text's line height. */
64
+ :where([data-slot="skeleton"][data-shape="text"]) {
65
+ block-size: var(--kumiko-skeleton-text-height);
66
+ margin-block: calc((1lh - var(--kumiko-skeleton-text-height)) / 2);
67
+ border-radius: var(--kumiko-skeleton-text-radius);
68
+ }
69
+
70
+ :where([data-slot="skeleton-text"]) {
71
+ display: grid;
72
+ gap: var(--kumiko-skeleton-text-gap);
73
+ }
74
+
75
+ /* Pulse: the shine fades in and out over the whole block instead of sweeping. */
76
+ :where(
77
+ [data-slot="skeleton"]:is(
78
+ [data-animation="pulse"],
79
+ :not([data-animation]):is([data-kumiko-skeleton~="pulse"] *)
80
+ )
81
+ ) {
82
+ background-image: none;
83
+ animation: kumiko-skeleton-pulse var(--_skeleton-pulse) ease-in-out infinite;
84
+ }
85
+
86
+ @keyframes kumiko-skeleton-pulse {
87
+ 50% {
88
+ background-color: var(--kumiko-skeleton-shine);
89
+ }
90
+ }
91
+
92
+ :where(
93
+ [data-slot="skeleton"]:is(
94
+ [data-animation="still"],
95
+ :not([data-animation]):is([data-kumiko-skeleton~="still"] *)
96
+ )
97
+ ) {
98
+ background-image: none;
99
+ animation: none;
100
+ }
101
+
102
+ /* A sweep is movement: reduced and still motion pulse instead, slowly. A still skeleton stays still. */
103
+ @media (prefers-reduced-motion: reduce) {
104
+ :where(
105
+ [data-slot="skeleton"]:not([data-animation="still"]):not(
106
+ :not([data-animation]):is([data-kumiko-skeleton~="still"] *)
107
+ )
108
+ ) {
109
+ background-image: none;
110
+ animation: kumiko-skeleton-pulse calc(var(--_skeleton-pulse) * 1.5) ease-in-out infinite;
111
+ }
112
+ }
113
+
114
+ :where(
115
+ [data-kumiko-motion="still"]
116
+ [data-slot="skeleton"]:not([data-animation="still"]):not(
117
+ :not([data-animation]):is([data-kumiko-skeleton~="still"] *)
118
+ )
119
+ ) {
120
+ background-image: none;
121
+ animation: kumiko-skeleton-pulse calc(var(--_skeleton-pulse) * 1.5) ease-in-out infinite;
122
+ }
123
+
124
+ /* The status a group announces is for screen readers only. */
125
+ :where([data-slot="skeleton-status"]) {
126
+ position: absolute;
127
+ inline-size: 1px;
128
+ block-size: 1px;
129
+ margin: -1px;
130
+ padding: 0;
131
+ overflow: hidden;
132
+ border: 0;
133
+ white-space: nowrap;
134
+ clip-path: inset(50%);
135
+ }
136
+
137
+ @media (forced-colors: active) {
138
+ :where([data-slot="skeleton"]) {
139
+ background: GrayText;
140
+ forced-color-adjust: none;
141
+ }
142
+ }
143
+ }
@@ -0,0 +1,44 @@
1
+ /** How a placeholder moves: a band of light sweeps across it, it fades between two tints, or it holds still. */
2
+ export type SkeletonAnimation = "shimmer" | "pulse" | "still";
3
+ /** A block, a circle (for an avatar), or a line of text. */
4
+ export type SkeletonShape = "rect" | "circle" | "text";
5
+ type Length = number | string;
6
+ export interface SkeletonProps extends Omit<React.ComponentProps<"span">, "children"> {
7
+ /** @defaultValue "rect" */
8
+ shape?: SkeletonShape;
9
+ /** A number is pixels; a string is any CSS length, like `"60%"` or `"12rem"`. */
10
+ width?: Length;
11
+ /** A number is pixels; a string is any CSS length. A circle takes its width when this is left out. */
12
+ height?: Length;
13
+ /**
14
+ * Without it, `data-kumiko-skeleton="pulse"` or `"still"` on any container picks. Reduced and still motion turn
15
+ * the shimmer into a slow pulse.
16
+ * @defaultValue "shimmer"
17
+ */
18
+ animation?: SkeletonAnimation;
19
+ }
20
+ /** A placeholder in the shape of something still loading. Screen readers skip it; announce loading with `SkeletonGroup`. */
21
+ export declare function Skeleton({ shape, width, height, animation, style, ...props }: SkeletonProps): React.JSX.Element;
22
+ export interface SkeletonTextProps extends Omit<React.ComponentProps<"span">, "children"> {
23
+ /** @defaultValue 3 */
24
+ lines?: number;
25
+ /** How long the last line is, so the block reads as a paragraph. @defaultValue "60%" */
26
+ lastWidth?: Length;
27
+ animation?: SkeletonAnimation;
28
+ }
29
+ /** Lines of text still loading, each as tall as a line of the surrounding text, the last one shorter. */
30
+ export declare function SkeletonText({ lines, lastWidth, animation, ...props }: SkeletonTextProps): React.JSX.Element;
31
+ export interface SkeletonGroupProps extends React.ComponentProps<"div"> {
32
+ /**
33
+ * What screen readers hear while it loads.
34
+ * @defaultValue "Loading"
35
+ */
36
+ label?: string;
37
+ }
38
+ /**
39
+ * Holds the placeholders for one thing that is loading, and tells screen readers so: it is busy, and a status says
40
+ * `label`. Swap it for the content once it arrives. The status sits just outside the busy box, because screen
41
+ * readers hold back what a busy region says.
42
+ */
43
+ export declare function SkeletonGroup({ label, children, ...props }: SkeletonGroupProps): React.JSX.Element;
44
+ export {};
@@ -0,0 +1,22 @@
1
+ import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ function length(value) {
3
+ return typeof value === "number" ? `${value}px` : value;
4
+ }
5
+ /** A placeholder in the shape of something still loading. Screen readers skip it; announce loading with `SkeletonGroup`. */
6
+ export function Skeleton({ shape = "rect", width, height, animation, style, ...props }) {
7
+ const size = { inlineSize: length(width), blockSize: length(height) };
8
+ return (_jsx("span", { "aria-hidden": true, "data-slot": "skeleton", "data-shape": shape, "data-animation": animation, style: { ...size, ...style }, ...props }));
9
+ }
10
+ /** Lines of text still loading, each as tall as a line of the surrounding text, the last one shorter. */
11
+ export function SkeletonText({ lines = 3, lastWidth = "60%", animation, ...props }) {
12
+ const count = Math.max(1, Math.floor(lines));
13
+ return (_jsx("span", { "aria-hidden": true, "data-slot": "skeleton-text", ...props, children: Array.from({ length: count }, (_, line) => (_jsx(Skeleton, { shape: "text", animation: animation, width: line === count - 1 && count > 1 ? lastWidth : undefined }, line))) }));
14
+ }
15
+ /**
16
+ * Holds the placeholders for one thing that is loading, and tells screen readers so: it is busy, and a status says
17
+ * `label`. Swap it for the content once it arrives. The status sits just outside the busy box, because screen
18
+ * readers hold back what a busy region says.
19
+ */
20
+ export function SkeletonGroup({ label = "Loading", children, ...props }) {
21
+ return (_jsxs(_Fragment, { children: [_jsx("span", { role: "status", "data-slot": "skeleton-status", children: label }), _jsx("div", { "aria-busy": "true", "data-slot": "skeleton-group", ...props, children: children })] }));
22
+ }
@@ -51,7 +51,8 @@
51
51
  transform-origin: center;
52
52
  }
53
53
 
54
- [data-slot="smooth-caret"][data-idle="true"] [data-slot="smooth-caret-bar"] {
54
+ [data-slot="smooth-caret"][data-visible="true"][data-idle="true"]
55
+ [data-slot="smooth-caret-bar"] {
55
56
  animation: kumiko-smooth-caret-blink var(--kumiko-smooth-caret-blink-duration) ease-in-out
56
57
  infinite;
57
58
  }
@@ -145,7 +146,8 @@
145
146
  transition: none;
146
147
  }
147
148
 
148
- [data-slot="smooth-caret"][data-idle="true"] [data-slot="smooth-caret-bar"] {
149
+ [data-slot="smooth-caret"][data-visible="true"][data-idle="true"]
150
+ [data-slot="smooth-caret-bar"] {
149
151
  animation: none;
150
152
  }
151
153
 
@@ -0,0 +1,2 @@
1
+ export { Tabs, TabsCount, TabsList, type TabsCountProps, type TabsGlide, type TabsListProps, type TabsLook, type TabsPanelMotion, type TabsProps, type TabsSize } from "./tabs";
2
+ export { createTabsController, TabsPanel, TabsTab, TabsTabIcon, type TabsApi, type TabsChangeOptions, type TabsController, type TabsDirection, type TabsOrientation, type TabsPanelState, type TabsState, type TabsTabState, type TabsValueChangeReason } from "@ui-sdk/react/tabs";
@@ -0,0 +1,2 @@
1
+ export { Tabs, TabsCount, TabsList } from "./tabs";
2
+ export { createTabsController, TabsPanel, TabsTab, TabsTabIcon } from "@ui-sdk/react/tabs";