@alulore/kumiko 0.17.0 → 0.17.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.
@@ -36,12 +36,22 @@ function clock(seconds) {
36
36
  const whole = Math.max(0, Math.floor(seconds));
37
37
  return `${Math.floor(whole / 60)}:${String(whole % 60).padStart(2, "0")}`;
38
38
  }
39
+ /*
40
+ * A play() that can't finish (the video left the page, or the browser needs a tap first) leaves
41
+ * the clip paused, which is what the controls already show. Nothing else needs to hear of it.
42
+ */
43
+ function keepPaused(error) {
44
+ if (!(error instanceof DOMException) ||
45
+ !["AbortError", "NotAllowedError"].includes(error.name)) {
46
+ throw error;
47
+ }
48
+ }
39
49
  function togglePlay(video) {
40
50
  if (!video) {
41
51
  return;
42
52
  }
43
53
  if (video.paused) {
44
- void video.play();
54
+ video.play().catch(keepPaused);
45
55
  }
46
56
  else {
47
57
  video.pause();
@@ -14,6 +14,12 @@ export interface ShortcutAction {
14
14
  when?: () => boolean;
15
15
  /** Whether it also runs while focus is in a text field. Keys with Ctrl, Cmd or Alt always do. */
16
16
  allowInInput?: boolean;
17
+ /**
18
+ * Whether it keeps running while a modal (a dialog or a sheet) is open. For app-wide chords such as a
19
+ * finder or settings. Typing in a field, `when` and the pause during a drag or menu still apply.
20
+ * @defaultValue false
21
+ */
22
+ overDialogs?: boolean;
17
23
  }
18
24
  /** The keys people changed, by action id. An action that is not in here uses its defaults. */
19
25
  export type Overrides = Readonly<Record<string, readonly string[]>>;
@@ -1,5 +1,8 @@
1
+ import { DialogTrigger } from "../dialog";
1
2
  export type HelpPresentation = "popover" | "dialog" | "panel";
2
- export interface ShortcutsHelpProps {
3
+ /** The button attributes and `render` the sheet's trigger takes, as the other triggers do. */
4
+ type TriggerProps = Omit<React.ComponentProps<typeof DialogTrigger>, "children" | "className" | "controller">;
5
+ export type ShortcutsHelpProps = TriggerProps & {
3
6
  /**
4
7
  * Where the sheet appears: a dialog with search, a popover from its button, or a panel at the side.
5
8
  * @defaultValue "dialog"
@@ -18,8 +21,9 @@ export interface ShortcutsHelpProps {
18
21
  label?: React.ReactNode;
19
22
  /** A class for the button. */
20
23
  className?: string;
21
- }
24
+ };
22
25
  /** A button that opens the help sheet: what can run now, by section. Its keys (`helpKeys`) open it too. */
23
- export declare function ShortcutsHelp({ presentation, editable, label, className }: ShortcutsHelpProps): React.JSX.Element;
26
+ export declare function ShortcutsHelp({ presentation, editable, label, className, ...trigger }: ShortcutsHelpProps): React.JSX.Element;
24
27
  /** Rebinding on its own, for apps that keep it in a settings page instead of the help sheet. */
25
28
  export declare function ShortcutsSettings(): React.JSX.Element;
29
+ export {};
@@ -12,13 +12,13 @@ function Body({ presentation, editable }) {
12
12
  return (_jsxs("div", { className: "kumiko-shortcuts-sheet", "data-presentation": presentation, children: [presentation === "dialog" ? (_jsx("input", { type: "search", "aria-label": "Search shortcuts", placeholder: "Search shortcuts", value: query, onChange: (event) => setQuery(event.target.value) })) : null, _jsx(ShortcutsList, { editing: editing, all: editing, query: query }), help.length > 0 ? (_jsxs("p", { className: "kumiko-shortcuts-foot", children: ["This sheet opens with ", help.join(" or "), "."] })) : null, editable ? (_jsx("button", { type: "button", onClick: () => setEditing((now) => !now), children: editing ? "Done" : "Edit keys" })) : null] }));
13
13
  }
14
14
  /** A button that opens the help sheet: what can run now, by section. Its keys (`helpKeys`) open it too. */
15
- export function ShortcutsHelp({ presentation = "dialog", editable = false, label = "Shortcuts", className }) {
15
+ export function ShortcutsHelp({ presentation = "dialog", editable = false, label = "Shortcuts", className, ...trigger }) {
16
16
  const { helpOpen, openHelp, closeHelp } = useShortcuts();
17
17
  const onOpenChange = (open) => (open ? openHelp() : closeHelp());
18
18
  if (presentation === "popover") {
19
- return (_jsxs(Popover, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(PopoverTrigger, { className: className, children: label }), _jsxs(PopoverContent, { align: "end", sideOffset: 8, className: "kumiko-shortcuts-popover", children: [_jsx(PopoverTitle, { children: "Keyboard shortcuts" }), _jsx(PopoverDescription, { children: "What works right now." }), _jsx(Body, { presentation: presentation, editable: editable })] })] }));
19
+ return (_jsxs(Popover, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(PopoverTrigger, { ...trigger, className: className, children: label }), _jsxs(PopoverContent, { align: "end", sideOffset: 8, className: "kumiko-shortcuts-popover", children: [_jsx(PopoverTitle, { children: "Keyboard shortcuts" }), _jsx(PopoverDescription, { children: "What works right now." }), _jsx(Body, { presentation: presentation, editable: editable })] })] }));
20
20
  }
21
- return (_jsxs(Dialog, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(DialogTrigger, { className: className, children: label }), _jsx(DialogBackdrop, {}), _jsxs(DialogContent, { className: "kumiko-shortcuts-dialog", "data-kumiko-shortcuts": presentation, children: [_jsx(DialogTitle, { children: "Keyboard shortcuts" }), _jsx(DialogDescription, { children: "What works right now." }), _jsx(Body, { presentation: presentation, editable: editable }), _jsx(DialogClose, { className: className, children: "Close" })] })] }));
21
+ return (_jsxs(Dialog, { open: helpOpen, onOpenChange: onOpenChange, children: [_jsx(DialogTrigger, { ...trigger, className: className, children: label }), _jsx(DialogBackdrop, {}), _jsxs(DialogContent, { className: "kumiko-shortcuts-dialog", "data-kumiko-shortcuts": presentation, children: [_jsx(DialogTitle, { children: "Keyboard shortcuts" }), _jsx(DialogDescription, { children: "What works right now." }), _jsx(Body, { presentation: presentation, editable: editable }), _jsx(DialogClose, { className: className, children: "Close" })] })] }));
22
22
  }
23
23
  /** Rebinding on its own, for apps that keep it in a settings page instead of the help sheet. */
24
24
  export function ShortcutsSettings() {
@@ -6,6 +6,7 @@ export { defaultReservedKeys } from "./keys";
6
6
  export { type ShortcutNote } from "./notes";
7
7
  export { ShortcutsList, type ShortcutsListProps } from "./list";
8
8
  export { ShortcutsProvider, useShortcuts, type CaptureMode, type HintMode, type ReservedMode, type ShortcutsContextValue, type ShortcutsOptions, type ShortcutsProviderProps, type TakenKeys } from "./provider";
9
- export { shortcuts, useShortcut, useShortcutHint, type ShortcutInfo } from "@ui-sdk/react/shortcuts";
9
+ export { ariaKeyshortcuts, formatShortcut, shortcuts, useShortcutHint, type ShortcutInfo } from "@ui-sdk/react/shortcuts";
10
+ export { useShortcut, type OverDialogsOptions } from "./over-dialogs";
10
11
  export { Capture as ShortcutPrompt } from "./capture";
11
12
  export { useRebinder, type Rebinder, type Target } from "./rebinder";
@@ -6,6 +6,7 @@ export { defaultReservedKeys } from "./keys";
6
6
  export {} from "./notes";
7
7
  export { ShortcutsList } from "./list";
8
8
  export { ShortcutsProvider, useShortcuts } from "./provider";
9
- export { shortcuts, useShortcut, useShortcutHint } from "@ui-sdk/react/shortcuts";
9
+ export { ariaKeyshortcuts, formatShortcut, shortcuts, useShortcutHint } from "@ui-sdk/react/shortcuts";
10
+ export { useShortcut } from "./over-dialogs";
10
11
  export { Capture as ShortcutPrompt } from "./capture";
11
12
  export { useRebinder } from "./rebinder";
@@ -1,10 +1,15 @@
1
1
  import { Fragment as _Fragment, jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
2
+ import { formatShortcut } from "@ui-sdk/react/shortcuts";
2
3
  import { Kbd } from "../kbd";
3
4
  import { defaultKeys, maxKeysPerAction } from "./bindings";
4
5
  import { Capture } from "./capture";
5
6
  import { noteKeys, sectionRows } from "./notes";
6
7
  import { useShortcuts } from "./provider";
7
8
  import { useRebinder } from "./rebinder";
9
+ /** The key as a person sees it (Ctrl+K), without the marks that keep it left to right, for a screen reader. */
10
+ function spoken(key) {
11
+ return formatShortcut(key).replaceAll(/[⁦⁩]/gu, "");
12
+ }
8
13
  function sameKeys(action, keys) {
9
14
  const defaults = defaultKeys(action);
10
15
  return keys.length === defaults.length && keys.every((key, index) => key === defaults[index]);
@@ -14,7 +19,7 @@ function KeyChip({ action, slot, removable, rebinder }) {
14
19
  const key = keysFor(action.id)[slot] ?? "";
15
20
  const { target } = rebinder;
16
21
  const changing = target?.id === action.id && target.slot === slot;
17
- return (_jsxs("span", { className: "kumiko-shortcuts-key", "data-changing": changing ? "" : undefined, children: [_jsx(Kbd, { keys: key, listen: false }), _jsx("button", { type: "button", "aria-label": `Change ${key} for ${action.description}`, onClick: () => rebinder.begin({ id: action.id, slot }), children: "Change" }), removable ? (_jsx("button", { type: "button", "aria-label": `Remove ${key} from ${action.description}`, onClick: () => rebinder.remove(action.id, slot), children: "Remove" })) : null] }));
22
+ return (_jsxs("span", { className: "kumiko-shortcuts-key", "data-changing": changing ? "" : undefined, children: [_jsx(Kbd, { keys: key, listen: false }), _jsx("button", { type: "button", "aria-label": `Change ${spoken(key)} for ${action.description}`, onClick: () => rebinder.begin({ id: action.id, slot }), children: "Change" }), removable ? (_jsx("button", { type: "button", "aria-label": `Remove ${spoken(key)} from ${action.description}`, onClick: () => rebinder.remove(action.id, slot), children: "Remove" })) : null] }));
18
23
  }
19
24
  function KeyEditor({ action, rebinder }) {
20
25
  const { keysFor, options } = useShortcuts();
@@ -0,0 +1,18 @@
1
+ import { type ShortcutHandler, type UseShortcutOptions } from "@ui-sdk/react/shortcuts";
2
+ /**
3
+ * Keeps the one hidden element that makes a shortcut survive modals. It is created for the first holder,
4
+ * bound as a persistent layer, and removed when the last holder lets go.
5
+ */
6
+ export declare function holdOverDialogs(): () => void;
7
+ /** The `layer` that keeps a shortcut running over modals. Nothing while no shortcut asked for it. */
8
+ export declare function overDialogsLayer(): Element | undefined;
9
+ export type OverDialogsOptions = UseShortcutOptions & {
10
+ /**
11
+ * Whether the shortcut keeps running while a modal (a dialog or a sheet) is open. Typing in a field and
12
+ * `when` still apply.
13
+ * @defaultValue false
14
+ */
15
+ overDialogs?: boolean;
16
+ };
17
+ /** The ui-sdk `useShortcut`, with `overDialogs` for app-wide chords that must work over a modal. */
18
+ export declare function useShortcut(keys: string | null | undefined, handler: ShortcutHandler, { overDialogs, ...options }?: OverDialogsOptions): void;
@@ -0,0 +1,38 @@
1
+ import { bindPersistentLayer } from "@ui-sdk/core";
2
+ import { useShortcut as useUiShortcut } from "@ui-sdk/react/shortcuts";
3
+ import { useEffect } from "react";
4
+ let layer;
5
+ let unbind;
6
+ let holders = 0;
7
+ /**
8
+ * Keeps the one hidden element that makes a shortcut survive modals. It is created for the first holder,
9
+ * bound as a persistent layer, and removed when the last holder lets go.
10
+ */
11
+ export function holdOverDialogs() {
12
+ holders += 1;
13
+ if (!layer) {
14
+ layer = document.createElement("div");
15
+ layer.hidden = true;
16
+ layer.dataset.kumikoShortcutsOverDialogs = "";
17
+ document.body.append(layer);
18
+ unbind = bindPersistentLayer(layer);
19
+ }
20
+ return () => {
21
+ holders -= 1;
22
+ if (holders === 0) {
23
+ unbind?.();
24
+ layer?.remove();
25
+ layer = undefined;
26
+ unbind = undefined;
27
+ }
28
+ };
29
+ }
30
+ /** The `layer` that keeps a shortcut running over modals. Nothing while no shortcut asked for it. */
31
+ export function overDialogsLayer() {
32
+ return layer;
33
+ }
34
+ /** The ui-sdk `useShortcut`, with `overDialogs` for app-wide chords that must work over a modal. */
35
+ export function useShortcut(keys, handler, { overDialogs = false, ...options } = {}) {
36
+ useEffect(() => (overDialogs ? holdOverDialogs() : undefined), [overDialogs]);
37
+ useUiShortcut(keys, handler, overDialogs ? { ...options, layer: overDialogsLayer } : options);
38
+ }
@@ -90,7 +90,7 @@ export function ShortcutsProvider(props) {
90
90
  };
91
91
  });
92
92
  const signature = [
93
- ...actions.map((action) => `${action.id}:${action.description}:${action.allowInInput}`),
93
+ ...actions.map((action) => `${action.id}:${action.description}:${action.allowInInput}:${action.overDialogs}`),
94
94
  ...options.helpKeys
95
95
  ].join("|");
96
96
  useRegistration(live, signature);
@@ -3,6 +3,7 @@ import { useEffect, useState } from "react";
3
3
  import { keysOf, maxKeysPerAction } from "./bindings";
4
4
  import { isDragging, isMenuOpen } from "./guard";
5
5
  import { canonicalKeys, onApple } from "./keys";
6
+ import { holdOverDialogs, overDialogsLayer } from "./over-dialogs";
6
7
  /** Whether page shortcuts may run: not while a drag or a menu is open, unless the app turned that off. */
7
8
  function calm(live) {
8
9
  return !live.current.pauseWhileBusy || (!isDragging() && !isMenuOpen());
@@ -17,6 +18,7 @@ function registerSlot(live, action, slot) {
17
18
  }, (event) => find()?.run(event), {
18
19
  description: action.description,
19
20
  allowInInput: action.allowInInput ?? false,
21
+ layer: action.overDialogs ? overDialogsLayer : undefined,
20
22
  when: () => calm(live) && (find()?.when?.() ?? true)
21
23
  });
22
24
  }
@@ -27,6 +29,9 @@ function registerSlot(live, action, slot) {
27
29
  export function useRegistration(live, signature) {
28
30
  useEffect(() => {
29
31
  const offs = [];
32
+ if (live.current.actions.some((action) => action.overDialogs)) {
33
+ offs.push(holdOverDialogs());
34
+ }
30
35
  for (const action of live.current.actions) {
31
36
  for (let slot = 0; slot < maxKeysPerAction; slot += 1) {
32
37
  offs.push(registerSlot(live, action, slot));
@@ -18,7 +18,11 @@ export interface UndoApi {
18
18
  /** Whether undo and redo controls should ignore taps: a step runs and extra taps are dropped. */
19
19
  locked: boolean;
20
20
  place: string | undefined;
21
- /** Stores a step and returns the stored entry. */
21
+ /**
22
+ * Stores a step and returns the stored entry. A step that doesn't name a `place` gets this
23
+ * provider's. A step that names one keeps it, and `place: undefined` on purpose stays
24
+ * placeless. `store.remember` never stamps.
25
+ */
22
26
  remember: (entry: NewUndoEntry) => UndoEntry;
23
27
  undo: () => Promise<void>;
24
28
  redo: () => Promise<void>;
@@ -17,7 +17,7 @@ function bind({ store, scope, place }, snapshot) {
17
17
  busy: snapshot.busy,
18
18
  locked: snapshot.busy && snapshot.busyMode === "ignore",
19
19
  place,
20
- remember: store.remember,
20
+ remember: (entry) => store.remember("place" in entry ? entry : { ...entry, place }),
21
21
  undo: () => store.undo(scope),
22
22
  redo: () => store.redo(scope),
23
23
  undoEntry: (id) => store.undoEntry(id, scope),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@alulore/kumiko",
3
- "version": "0.17.0",
3
+ "version": "0.17.1",
4
4
  "description": "Polished, cozy React components with gentle motion, built on ui-sdk. Every look and behaviour can be switched with props and CSS tokens.",
5
5
  "license": "MIT",
6
6
  "repository": {