@mcurcio/patchbay 0.3.0 → 0.5.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/README.md +4 -4
- package/dist/composites.css +1 -1
- package/dist/composites.js +573 -53
- package/dist/composites.js.map +1 -1
- package/dist/graph.css +1 -0
- package/dist/graph.js +123 -0
- package/dist/graph.js.map +1 -0
- package/dist/hooks.js +433 -28
- package/dist/hooks.js.map +1 -1
- package/dist/primitives.css +1 -1
- package/dist/primitives.js +39 -20
- package/dist/primitives.js.map +1 -1
- package/dist/types/composites/command-palette/CommandPalette.d.ts +68 -0
- package/dist/types/composites/command-palette/index.d.ts +4 -0
- package/dist/types/composites/command-palette/rank.d.ts +39 -0
- package/dist/types/composites/index.d.ts +3 -0
- package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +41 -0
- package/dist/types/composites/shortcut-sheet/index.d.ts +2 -0
- package/dist/types/composites/toaster/Toaster.d.ts +38 -0
- package/dist/types/composites/toaster/index.d.ts +2 -0
- package/dist/types/graph/index.d.ts +1 -1
- package/dist/types/graph/meter/Meter.d.ts +56 -0
- package/dist/types/graph/meter/index.d.ts +2 -0
- package/dist/types/hooks/index.d.ts +4 -0
- package/dist/types/hooks/use-live-value/index.d.ts +2 -0
- package/dist/types/hooks/use-live-value/useLiveValue.d.ts +9 -0
- package/dist/types/hooks/use-media-breakpoint/index.d.ts +2 -0
- package/dist/types/hooks/use-media-breakpoint/useMediaBreakpoint.d.ts +25 -0
- package/dist/types/hooks/use-shortcuts/index.d.ts +2 -0
- package/dist/types/hooks/use-shortcuts/useShortcuts.d.ts +58 -0
- package/dist/types/hooks/use-toasts/index.d.ts +4 -0
- package/dist/types/hooks/use-toasts/toastQueue.d.ts +76 -0
- package/dist/types/hooks/use-toasts/useToasts.d.ts +31 -0
- package/dist/types/primitives/badge/Badge.d.ts +10 -3
- package/dist/types/primitives/badge/index.d.ts +1 -1
- package/dist/types/primitives/button/Button.d.ts +4 -1
- package/dist/types/primitives/pill/Pill.d.ts +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Platform } from "../../hooks";
|
|
3
|
+
import "./CommandPalette.css";
|
|
4
|
+
/** One command in the palette. */
|
|
5
|
+
export type Command = {
|
|
6
|
+
/** Unique among the commands; the active command is kept by it while the list changes. */
|
|
7
|
+
id: string;
|
|
8
|
+
/** What the command is called; the query is matched against it. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** The heading it is listed under; groups are shown in the order they first appear. */
|
|
11
|
+
group: string;
|
|
12
|
+
/** Its key string, or several, shown through keyLabel ("Mod+K"); the palette does not bind them. */
|
|
13
|
+
keys?: string | readonly string[];
|
|
14
|
+
/** A second, quieter line: what it does, or what it acts on. Not matched. */
|
|
15
|
+
hint?: string;
|
|
16
|
+
/** Runs the command; the palette asks to close first. */
|
|
17
|
+
run: () => void;
|
|
18
|
+
/** Shown but skipped by the keys, and does nothing when pressed. */
|
|
19
|
+
disabled?: boolean;
|
|
20
|
+
};
|
|
21
|
+
/** A point in the window's coordinates (client px), such as where a press happened. */
|
|
22
|
+
export type PalettePoint = {
|
|
23
|
+
x: number;
|
|
24
|
+
y: number;
|
|
25
|
+
};
|
|
26
|
+
export type CommandPaletteProps = {
|
|
27
|
+
/** Whether the palette is shown; the app holds it. */
|
|
28
|
+
open: boolean;
|
|
29
|
+
/** Asked for on Escape, Tab, a press outside, the focus leaving, and before a command runs. */
|
|
30
|
+
onClose: () => void;
|
|
31
|
+
commands: readonly Command[];
|
|
32
|
+
/** Anchors the palette's top-left corner at this point, kept inside the window; centred near the top without it. */
|
|
33
|
+
at?: PalettePoint;
|
|
34
|
+
/** The field's placeholder, "Type a command" by default. */
|
|
35
|
+
placeholder?: string;
|
|
36
|
+
/** The palette's name for screen readers, "Commands" by default. */
|
|
37
|
+
label?: string;
|
|
38
|
+
/** Shown when there are no commands at all, "No commands" by default. */
|
|
39
|
+
emptyLabel?: ReactNode;
|
|
40
|
+
/** Shown when the query matches none, "No command matches “query”" by default. */
|
|
41
|
+
noMatchLabel?: (query: string) => ReactNode;
|
|
42
|
+
/** The platform keys are drawn for; the browser's by default. */
|
|
43
|
+
platform?: Platform;
|
|
44
|
+
/** Replaces keyLabel's words for keys and modifiers ("Escape", "Ctrl"). */
|
|
45
|
+
keyNames?: Readonly<Record<string, string>>;
|
|
46
|
+
/** A class added to the palette's box. */
|
|
47
|
+
className?: string;
|
|
48
|
+
};
|
|
49
|
+
/** The anchored palette's size, held inside the window less the gutter. */
|
|
50
|
+
export declare const PALETTE_WIDTH = 320;
|
|
51
|
+
export declare const PALETTE_HEIGHT = 360;
|
|
52
|
+
/** How far the anchored palette stays from the window's edges. */
|
|
53
|
+
export declare const PALETTE_GUTTER = 8;
|
|
54
|
+
/**
|
|
55
|
+
* Where an anchored palette goes: its top-left corner at the point, moved back inside the window (less the gutter)
|
|
56
|
+
* where it would cross an edge, and made smaller when the window is smaller than the palette. The height is the
|
|
57
|
+
* most it may take; a short list takes less.
|
|
58
|
+
*/
|
|
59
|
+
export declare function placePalette(at: PalettePoint, window: {
|
|
60
|
+
width: number;
|
|
61
|
+
height: number;
|
|
62
|
+
}): {
|
|
63
|
+
left: number;
|
|
64
|
+
top: number;
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
};
|
|
68
|
+
export declare function CommandPalette({ open, ...rest }: CommandPaletteProps): import("react").ReactPortal | null;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { CommandPalette, PALETTE_GUTTER, PALETTE_HEIGHT, PALETTE_WIDTH, placePalette } from "./CommandPalette";
|
|
2
|
+
export type { Command, CommandPaletteProps, PalettePoint } from "./CommandPalette";
|
|
3
|
+
export { markRuns, matchSubsequence, rankCommands } from "./rank";
|
|
4
|
+
export type { Rankable, RankedCommand, RankedGroup, SubsequenceMatch } from "./rank";
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/** Where a query's letters fell in a label, and how good the match is. */
|
|
2
|
+
export type SubsequenceMatch = {
|
|
3
|
+
/** The indices (UTF-16 code units) of the label's matched characters, ascending. */
|
|
4
|
+
indices: number[];
|
|
5
|
+
/** Higher is better; an empty query scores 0. */
|
|
6
|
+
score: number;
|
|
7
|
+
};
|
|
8
|
+
/**
|
|
9
|
+
* Finds the query's letters in the text, in order and in any case (white space in the query is ignored), the best
|
|
10
|
+
* way it can; undefined when they are not all there.
|
|
11
|
+
*/
|
|
12
|
+
export declare function matchSubsequence(text: string, query: string): SubsequenceMatch | undefined;
|
|
13
|
+
/** What ranking needs of a command. */
|
|
14
|
+
export type Rankable = {
|
|
15
|
+
label: string;
|
|
16
|
+
group: string;
|
|
17
|
+
};
|
|
18
|
+
/** A command that matched, with where its letters fell. */
|
|
19
|
+
export type RankedCommand<C extends Rankable> = {
|
|
20
|
+
command: C;
|
|
21
|
+
indices: number[];
|
|
22
|
+
score: number;
|
|
23
|
+
};
|
|
24
|
+
/** One group's matching commands. */
|
|
25
|
+
export type RankedGroup<C extends Rankable> = {
|
|
26
|
+
group: string;
|
|
27
|
+
items: RankedCommand<C>[];
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The commands whose labels match the query, in groups. With an empty query every command is kept, in the order given
|
|
31
|
+
* and its groups in the order they first appear; with one, each group's commands go best first and the groups by
|
|
32
|
+
* their best command, ties kept in the order given. Groups with no match are left out.
|
|
33
|
+
*/
|
|
34
|
+
export declare function rankCommands<C extends Rankable>(commands: readonly C[], query: string): RankedGroup<C>[];
|
|
35
|
+
/** The label cut into runs, each marked or not, so the matched letters can be drawn in <mark>. */
|
|
36
|
+
export declare function markRuns(label: string, indices: readonly number[]): {
|
|
37
|
+
text: string;
|
|
38
|
+
marked: boolean;
|
|
39
|
+
}[];
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ReactNode } from "react";
|
|
2
|
+
import { type Platform } from "../../hooks";
|
|
3
|
+
import "./ShortcutSheet.css";
|
|
4
|
+
/** One line of the sheet. */
|
|
5
|
+
export type ShortcutLine = {
|
|
6
|
+
/** The key string, or several that do the same ("Mod+K", ["Delete", "Backspace"]). */
|
|
7
|
+
keys: string | readonly string[];
|
|
8
|
+
/** What the key does. */
|
|
9
|
+
label: string;
|
|
10
|
+
/** The heading it is listed under. */
|
|
11
|
+
group: string;
|
|
12
|
+
};
|
|
13
|
+
export type ShortcutSheetProps = {
|
|
14
|
+
/** Whether the sheet is shown; the app holds it. */
|
|
15
|
+
open: boolean;
|
|
16
|
+
/** Asked for on Escape, the close button and a press on the scrim. */
|
|
17
|
+
onClose: () => void;
|
|
18
|
+
shortcuts: readonly ShortcutLine[];
|
|
19
|
+
/** The dialog's title, "Keyboard shortcuts" by default. */
|
|
20
|
+
title?: ReactNode;
|
|
21
|
+
/** A note under the lists (where the keys do not act, say). */
|
|
22
|
+
children?: ReactNode;
|
|
23
|
+
/** Between two keys that do the same, "or" by default. */
|
|
24
|
+
orLabel?: string;
|
|
25
|
+
/** Shown when there are no shortcuts, "No shortcuts" by default. */
|
|
26
|
+
emptyLabel?: ReactNode;
|
|
27
|
+
/** The close button's name, "Close" by default. */
|
|
28
|
+
closeLabel?: string;
|
|
29
|
+
/** The platform keys are drawn for; the browser's by default. */
|
|
30
|
+
platform?: Platform;
|
|
31
|
+
/** Replaces keyLabel's words for keys and modifiers ("Escape", "Ctrl"). */
|
|
32
|
+
keyNames?: Readonly<Record<string, string>>;
|
|
33
|
+
/** A class added to the dialog's box. */
|
|
34
|
+
className?: string;
|
|
35
|
+
};
|
|
36
|
+
/** The lines in groups, the groups in the order they first appear and each group's lines in the order given. */
|
|
37
|
+
export declare function groupShortcuts(shortcuts: readonly ShortcutLine[]): {
|
|
38
|
+
group: string;
|
|
39
|
+
lines: ShortcutLine[];
|
|
40
|
+
}[];
|
|
41
|
+
export declare function ShortcutSheet({ open, onClose, shortcuts, title, children, orLabel, emptyLabel, closeLabel, platform, keyNames, className, }: ShortcutSheetProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { type ComponentPropsWithRef, type ReactNode } from "react";
|
|
2
|
+
import type { ToastAction, ToastTone } from "../../hooks";
|
|
3
|
+
import "./Toaster.css";
|
|
4
|
+
/** Where the stack sits; any other string is drawn inline. */
|
|
5
|
+
export type ToasterPlacement = "top-start" | "top" | "top-end" | "bottom-start" | "bottom" | "bottom-end" | "inline" | (string & {});
|
|
6
|
+
/** A toast as the toaster draws it; useToasts' toasts are these. */
|
|
7
|
+
export type ToasterToast = {
|
|
8
|
+
id: number;
|
|
9
|
+
tone: ToastTone;
|
|
10
|
+
text: ReactNode;
|
|
11
|
+
/** How many times it was shown, coalesced; above 1 it shows "×n". */
|
|
12
|
+
count?: number;
|
|
13
|
+
action?: ToastAction;
|
|
14
|
+
};
|
|
15
|
+
export type ToasterProps = Omit<ComponentPropsWithRef<"section">, "children"> & {
|
|
16
|
+
/** The toasts shown, oldest first. */
|
|
17
|
+
toasts: readonly ToasterToast[];
|
|
18
|
+
/** How many older toasts are folded away, shown as "and n more". */
|
|
19
|
+
more?: number;
|
|
20
|
+
/** The person dismissed a toast (its button, its action, or Escape on it). */
|
|
21
|
+
onDismiss: (id: number) => void;
|
|
22
|
+
/** True while the person hovers over or is focused in the toasts, so the app holds their expiry. */
|
|
23
|
+
onHold?: (held: boolean) => void;
|
|
24
|
+
/**
|
|
25
|
+
* A corner or edge of the nearest positioned container ("bottom-end" by default; start and end follow the text's
|
|
26
|
+
* direction), or "inline": in the flow, where the app put it (in a canvas's own panel).
|
|
27
|
+
*/
|
|
28
|
+
placement?: ToasterPlacement;
|
|
29
|
+
/** The region's name, "Notifications" by default. */
|
|
30
|
+
label?: string;
|
|
31
|
+
/** The words on each Dismiss button, "Dismiss" by default. */
|
|
32
|
+
dismissLabel?: string;
|
|
33
|
+
/** The words for the folded toasts, "and n more" by default. */
|
|
34
|
+
moreLabel?: (more: number) => ReactNode;
|
|
35
|
+
/** What a screen reader reads for a count in place of "×n", "n times" by default. */
|
|
36
|
+
countLabel?: (count: number) => string;
|
|
37
|
+
};
|
|
38
|
+
export declare function Toaster({ toasts, more, onDismiss, onHold, placement, label, dismissLabel, moreLabel, countLabel, className, onPointerEnter, onPointerLeave, onFocus, onBlur, ...rest }: ToasterProps): import("react").JSX.Element;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./meter";
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type Ref } from "react";
|
|
2
|
+
import { type LiveSubscribe } from "../../hooks";
|
|
3
|
+
import "./Meter.css";
|
|
4
|
+
/** Which way the bar fills: an open enum, and one it does not know is drawn horizontal. */
|
|
5
|
+
export type MeterOrientation = "horizontal" | "vertical" | (string & {});
|
|
6
|
+
/** Writes the tooltip from the current peak and RMS in dBFS (`-Infinity` for silence) and whether the lamp is lit. */
|
|
7
|
+
export type MeterTitle = (peakDb: number, rmsDb: number, clipped: boolean) => string;
|
|
8
|
+
/** What a parent can do to a meter through its `ref`. */
|
|
9
|
+
export type MeterHandle = {
|
|
10
|
+
/** Empties the bar and clears the held peak and the clip lamp, as when the source closes. */
|
|
11
|
+
reset(): void;
|
|
12
|
+
};
|
|
13
|
+
export type MeterProps = Omit<ComponentPropsWithoutRef<"div">, "children" | "title" | "role"> & {
|
|
14
|
+
/** Adds a listener that means a new value is ready to read; returns what removes it. */
|
|
15
|
+
subscribe: LiveSubscribe;
|
|
16
|
+
/** The current `[peak, rms]` as linear amplitude, 1.0 being 0 dBFS. Not a number, or 0 and below, is silence. */
|
|
17
|
+
read: () => readonly [peak: number, rms: number];
|
|
18
|
+
/** `horizontal` (the default) or `vertical`. */
|
|
19
|
+
orientation?: MeterOrientation;
|
|
20
|
+
/** dBFS at the bar's empty end; the full end is 0 dBFS. -60 by default. */
|
|
21
|
+
floor?: number;
|
|
22
|
+
/** `[mid, hot]` in dBFS, where the bar turns from `--pb-meter-low` to `--pb-meter-mid` and to `--pb-meter-hot`. */
|
|
23
|
+
zones?: readonly [mid: number, hot: number];
|
|
24
|
+
/** How long the peak tick holds the highest peak, in ms. 1500 by default. */
|
|
25
|
+
holdMs?: number;
|
|
26
|
+
/** How fast the tick then falls toward the current peak, in dB a second. 20 by default. */
|
|
27
|
+
fallDbPerS?: number;
|
|
28
|
+
/** A peak at or above this linear amplitude lights the clip lamp. 1.0 (0 dBFS) by default. */
|
|
29
|
+
clipAt?: number;
|
|
30
|
+
/** How long the lamp stays lit after the last such peak, in ms. 2000 by default. */
|
|
31
|
+
clipHoldMs?: number;
|
|
32
|
+
/** The accessible name ("Level" by default); the numbers are never announced. */
|
|
33
|
+
label?: string;
|
|
34
|
+
/** The tooltip's words; `defaultMeterTitle` by default. */
|
|
35
|
+
title?: MeterTitle;
|
|
36
|
+
/** `reset()`, for when the source closes. */
|
|
37
|
+
ref?: Ref<MeterHandle>;
|
|
38
|
+
};
|
|
39
|
+
/** The scale's defaults, each a prop. */
|
|
40
|
+
export declare const defaultMeterScale: {
|
|
41
|
+
readonly floor: -60;
|
|
42
|
+
readonly zones: readonly [-18, -6];
|
|
43
|
+
readonly holdMs: 1500;
|
|
44
|
+
readonly fallDbPerS: 20;
|
|
45
|
+
readonly clipAt: 1;
|
|
46
|
+
readonly clipHoldMs: 2000;
|
|
47
|
+
};
|
|
48
|
+
/** How often, at most, the tooltip is refreshed while the pointer is over the meter, in ms. */
|
|
49
|
+
export declare const meterTitleEveryMs = 250;
|
|
50
|
+
/** A linear amplitude in dBFS; not a number, or 0 and below, is silence (`-Infinity`). */
|
|
51
|
+
export declare function toDb(linear: number): number;
|
|
52
|
+
/** Where a level in dBFS sits on a bar from `floor` (0) to 0 dBFS (1), clamped. */
|
|
53
|
+
export declare function meterFraction(db: number, floor: number): number;
|
|
54
|
+
/** The English tooltip: "peak -12.0 dB, rms -18.3 dB", with −∞ for silence. */
|
|
55
|
+
export declare const defaultMeterTitle: MeterTitle;
|
|
56
|
+
export declare function Meter({ subscribe, read, orientation, floor, zones, holdMs, fallDbPerS, clipAt, clipHoldMs, label, title, ref, className, style, onPointerEnter, onPointerLeave, ...rest }: MeterProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { type RefObject } from "react";
|
|
2
|
+
/** Adds a listener, called whenever a new value is ready to read; returns what removes it. */
|
|
3
|
+
export type LiveSubscribe = (listener: () => void) => () => void;
|
|
4
|
+
/**
|
|
5
|
+
* Subscribes to a hot value while the component is mounted, without React state. On subscribing, and on every call
|
|
6
|
+
* of the listener, it reads the value, keeps it in the returned ref and passes it to `onValue` (the paint). `read`
|
|
7
|
+
* and `onValue` may change every render; a new `subscribe` subscribes afresh, so pass a stable one.
|
|
8
|
+
*/
|
|
9
|
+
export declare function useLiveValue<T>(subscribe: LiveSubscribe, read: () => T, onValue?: (value: T) => void): RefObject<T | undefined>;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/** The window's width class: wide, narrow (below 760 px) or phone (below 600 px). */
|
|
2
|
+
export type MediaWidth = "wide" | "narrow" | "phone";
|
|
3
|
+
export type MediaBreakpoint = {
|
|
4
|
+
width: MediaWidth;
|
|
5
|
+
/** The main pointer is coarse and cannot hover: targets grow to their touch sizes. */
|
|
6
|
+
touch: boolean;
|
|
7
|
+
};
|
|
8
|
+
/** Narrow below this many CSS px. */
|
|
9
|
+
export declare const narrowBelow = 760;
|
|
10
|
+
/** Phone below this many CSS px. */
|
|
11
|
+
export declare const phoneBelow = 600;
|
|
12
|
+
/** The media queries the hook reads, for an app's own stylesheet or matchMedia. */
|
|
13
|
+
export declare const mediaQueries: {
|
|
14
|
+
readonly narrow: "(max-width: 759.98px)";
|
|
15
|
+
readonly phone: "(max-width: 599.98px)";
|
|
16
|
+
readonly touch: "(hover: none) and (pointer: coarse)";
|
|
17
|
+
};
|
|
18
|
+
/** The width class of a window `px` CSS px wide. */
|
|
19
|
+
export declare function widthOf(px: number): MediaWidth;
|
|
20
|
+
/** The answer with no window to ask. */
|
|
21
|
+
export declare const serverBreakpoint: MediaBreakpoint;
|
|
22
|
+
/** The answer now, from the window's media queries. */
|
|
23
|
+
export declare function readBreakpoint(): MediaBreakpoint;
|
|
24
|
+
/** The window's width class and touch flag, kept current as either changes. */
|
|
25
|
+
export declare function useMediaBreakpoint(): MediaBreakpoint;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/** Apple platforms use Cmd for Mod and draw modifiers as symbols; every other platform uses Ctrl. */
|
|
2
|
+
export type Platform = "apple" | "other";
|
|
3
|
+
export type Shortcut = {
|
|
4
|
+
/**
|
|
5
|
+
* The key, or several keys that do the same: modifiers then the key, joined by "+" ("Mod+K", "Shift+?",
|
|
6
|
+
* "Delete", "Mod+Shift+Z"). Modifiers are Mod, Ctrl, Alt, Shift and Meta (any case); the key is a
|
|
7
|
+
* KeyboardEvent key name ("Escape", "ArrowUp", "Space") or the character it types. A string naming a
|
|
8
|
+
* modifier it does not know never matches.
|
|
9
|
+
*/
|
|
10
|
+
keys: string | readonly string[];
|
|
11
|
+
/** What the binding does; called with the keydown event. */
|
|
12
|
+
run: (event: KeyboardEvent) => void;
|
|
13
|
+
/** Lets a chord act while focus is in a text field. Single keys and Escape never do, whatever this says. */
|
|
14
|
+
inTextFields?: boolean;
|
|
15
|
+
/** False turns the binding off without removing it from the table. */
|
|
16
|
+
enabled?: boolean;
|
|
17
|
+
/** Acts on the key's auto-repeat too; by default only the first press of a held key acts. */
|
|
18
|
+
repeat?: boolean;
|
|
19
|
+
/** False leaves the browser's own action for the key in place; by default a matched press prevents it. */
|
|
20
|
+
preventDefault?: boolean;
|
|
21
|
+
};
|
|
22
|
+
export type UseShortcutsOptions = {
|
|
23
|
+
/** False turns every binding off (while a dialog the bindings must not reach is open, say). */
|
|
24
|
+
enabled?: boolean;
|
|
25
|
+
/** Overrides the platform read from the browser. */
|
|
26
|
+
platform?: Platform;
|
|
27
|
+
};
|
|
28
|
+
/** The platform the page runs on, from the browser; "other" without one. */
|
|
29
|
+
export declare function detectPlatform(given?: Navigator): Platform;
|
|
30
|
+
type KeyEventLike = Pick<KeyboardEvent, "key" | "code" | "ctrlKey" | "altKey" | "shiftKey" | "metaKey">;
|
|
31
|
+
/** Whether a keydown matches a key string (or any of several) on the platform. */
|
|
32
|
+
export declare function matchesKeys(event: KeyEventLike, keys: string | readonly string[], platform?: Platform): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Whether keys pressed at the target belong to it: a text input, a textarea, a select, editable content, or anything
|
|
35
|
+
* inside an element with React Flow's `nokey` class.
|
|
36
|
+
*/
|
|
37
|
+
export declare function isTextTarget(target: EventTarget | null): boolean;
|
|
38
|
+
type LabelOptions = {
|
|
39
|
+
/** The platform the label is for; the browser's by default. */
|
|
40
|
+
platform?: Platform;
|
|
41
|
+
/** Replaces the words for keys and modifiers, by their names ("Escape", "Ctrl", "Space"). */
|
|
42
|
+
names?: Readonly<Record<string, string>>;
|
|
43
|
+
};
|
|
44
|
+
/**
|
|
45
|
+
* The key string as people read it: "⌘K" on Apple platforms and "Ctrl+K" elsewhere, "⇧⌘Z" and "Ctrl+Shift+Z". A
|
|
46
|
+
* string it cannot read is shown as written.
|
|
47
|
+
*/
|
|
48
|
+
export declare function keyLabel(keys: string, options?: LabelOptions): string;
|
|
49
|
+
/** The key strings as an `aria-keyshortcuts` value: "Meta+K" on Apple platforms, "Control+K" elsewhere. */
|
|
50
|
+
export declare function ariaKeyShortcuts(keys: string | readonly string[], platform?: Platform): string;
|
|
51
|
+
/** The first binding in the table that this keydown should run, if any. */
|
|
52
|
+
export declare function findShortcut(event: KeyboardEvent, bindings: readonly Shortcut[], platform?: Platform): Shortcut | undefined;
|
|
53
|
+
/**
|
|
54
|
+
* Binds the table's keys on the window while the component is mounted. The table may change every render; the
|
|
55
|
+
* listener always reads the latest. The first binding that matches a press runs, and only it.
|
|
56
|
+
*/
|
|
57
|
+
export declare function useShortcuts(bindings: readonly Shortcut[], options?: UseShortcutsOptions): void;
|
|
58
|
+
export {};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { addToast, clearToasts, dismissToast, emptyToastQueue, expireToasts, holdToasts, nextToastExpiry, toastDefaults, visibleToasts, } from "./toastQueue";
|
|
2
|
+
export type { Toast, ToastAction, ToastInput, ToastQueue, ToastQueueOptions, ToastTone } from "./toastQueue";
|
|
3
|
+
export { useToasts } from "./useToasts";
|
|
4
|
+
export type { ToasterBinding, UseToastsOptions, UseToastsResult } from "./useToasts";
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/** The tones a toast is drawn in; any other string is drawn neutrally. An `err` toast is an alert, the rest status. */
|
|
3
|
+
export type ToastTone = "ok" | "warn" | "err" | "quiet" | "off" | (string & {});
|
|
4
|
+
/** A button on a toast that acts on its news. Pressing it runs `run`, then dismisses the toast. */
|
|
5
|
+
export type ToastAction = {
|
|
6
|
+
/** The button's words. */
|
|
7
|
+
label: string;
|
|
8
|
+
run: () => void;
|
|
9
|
+
};
|
|
10
|
+
/** What the app shows. */
|
|
11
|
+
export type ToastInput = {
|
|
12
|
+
tone: ToastTone;
|
|
13
|
+
/** The news; any node, so it may hold code or emphasis. */
|
|
14
|
+
text: ReactNode;
|
|
15
|
+
/**
|
|
16
|
+
* Toasts shown under the same key within the coalescing window are one toast that counts up ("×3"), taking the
|
|
17
|
+
* newest tone, text and action. Without a key a toast never coalesces.
|
|
18
|
+
*/
|
|
19
|
+
key?: string;
|
|
20
|
+
action?: ToastAction;
|
|
21
|
+
/** How long this toast lasts unheld, in ms, in place of the queue's duration; Infinity keeps it until dismissed. */
|
|
22
|
+
duration?: number;
|
|
23
|
+
};
|
|
24
|
+
/** A toast in the queue. */
|
|
25
|
+
export type Toast = Omit<ToastInput, "duration"> & {
|
|
26
|
+
/** Its own, never reused while the queue lives. */
|
|
27
|
+
id: number;
|
|
28
|
+
/** How many times it was shown, coalesced; 1 at first. */
|
|
29
|
+
count: number;
|
|
30
|
+
/** When it was last shown, on the queue's clock. */
|
|
31
|
+
lastAt: number;
|
|
32
|
+
/** When it goes, on the queue's clock; Infinity for one kept until dismissed. */
|
|
33
|
+
expiresAt: number;
|
|
34
|
+
};
|
|
35
|
+
export type ToastQueue = {
|
|
36
|
+
/** Oldest first. */
|
|
37
|
+
readonly toasts: readonly Toast[];
|
|
38
|
+
/** While held: since when. */
|
|
39
|
+
readonly heldSince?: number;
|
|
40
|
+
/** The id the next new toast takes. */
|
|
41
|
+
readonly nextId: number;
|
|
42
|
+
};
|
|
43
|
+
export type ToastQueueOptions = {
|
|
44
|
+
/** How long a toast lasts unheld, in ms. */
|
|
45
|
+
duration?: number;
|
|
46
|
+
/** A toast shown again under its key within this many ms of its last showing counts up. */
|
|
47
|
+
coalesceWindow?: number;
|
|
48
|
+
};
|
|
49
|
+
/** The defaults: 8 s a toast, 5 s to coalesce, the newest four shown. */
|
|
50
|
+
export declare const toastDefaults: {
|
|
51
|
+
readonly duration: 8000;
|
|
52
|
+
readonly coalesceWindow: 5000;
|
|
53
|
+
readonly visible: 4;
|
|
54
|
+
};
|
|
55
|
+
/** The empty queue. */
|
|
56
|
+
export declare const emptyToastQueue: ToastQueue;
|
|
57
|
+
/** Adds a toast as the newest, or counts up the one it coalesces with and makes that the newest. */
|
|
58
|
+
export declare function addToast(queue: ToastQueue, input: ToastInput, now: number, options?: ToastQueueOptions): ToastQueue;
|
|
59
|
+
/** Takes the toast away; the same queue if it is not there. */
|
|
60
|
+
export declare function dismissToast(queue: ToastQueue, id: number): ToastQueue;
|
|
61
|
+
/** Takes every toast away. */
|
|
62
|
+
export declare function clearToasts(queue: ToastQueue): ToastQueue;
|
|
63
|
+
/**
|
|
64
|
+
* Holds the queue (nothing expires) or lets it go. Letting go moves each toast's expiry on by the time it was held:
|
|
65
|
+
* since the hold began, or since it was last shown if that came later. The same queue when nothing changes.
|
|
66
|
+
*/
|
|
67
|
+
export declare function holdToasts(queue: ToastQueue, held: boolean, now: number): ToastQueue;
|
|
68
|
+
/** Drops the toasts whose time is over; nothing while held. The same queue when none is over. */
|
|
69
|
+
export declare function expireToasts(queue: ToastQueue, now: number): ToastQueue;
|
|
70
|
+
/** When the soonest toast expires; undefined while held, or with none that expires. */
|
|
71
|
+
export declare function nextToastExpiry(queue: ToastQueue): number | undefined;
|
|
72
|
+
/** The newest `visible` toasts, oldest first, and how many older ones fold into "and n more". */
|
|
73
|
+
export declare function visibleToasts(queue: ToastQueue, visible?: number): {
|
|
74
|
+
shown: readonly Toast[];
|
|
75
|
+
more: number;
|
|
76
|
+
};
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { type Toast, type ToastInput } from "./toastQueue";
|
|
2
|
+
export type UseToastsOptions = {
|
|
3
|
+
/** How long a toast lasts unheld, in ms (8000). A toast's own `duration` wins. */
|
|
4
|
+
duration?: number;
|
|
5
|
+
/** A toast shown again under its key within this many ms of its last showing counts up (5000). */
|
|
6
|
+
coalesceWindow?: number;
|
|
7
|
+
/** How many toasts are shown, the newest; older ones fold into "and n more" (4). */
|
|
8
|
+
visible?: number;
|
|
9
|
+
/** The monotonic clock, in ms (`performance.now` by default); tests pass their own. */
|
|
10
|
+
now?: () => number;
|
|
11
|
+
};
|
|
12
|
+
/** What a Toaster draws from: spread it onto one (`<Toaster {...toasts.toasterProps} />`). */
|
|
13
|
+
export type ToasterBinding = {
|
|
14
|
+
/** The shown toasts, oldest first. */
|
|
15
|
+
toasts: readonly Toast[];
|
|
16
|
+
/** How many older toasts are folded away. */
|
|
17
|
+
more: number;
|
|
18
|
+
onDismiss: (id: number) => void;
|
|
19
|
+
/** Held while the person hovers over or is focused in the toasts: none expires. */
|
|
20
|
+
onHold: (held: boolean) => void;
|
|
21
|
+
};
|
|
22
|
+
export type UseToastsResult = {
|
|
23
|
+
/** Every toast in the queue, oldest first, the folded ones included. */
|
|
24
|
+
toasts: readonly Toast[];
|
|
25
|
+
/** Shows a toast, or counts up the one it coalesces with; returns its id. */
|
|
26
|
+
show: (input: ToastInput) => number;
|
|
27
|
+
dismiss: (id: number) => void;
|
|
28
|
+
clear: () => void;
|
|
29
|
+
toasterProps: ToasterBinding;
|
|
30
|
+
};
|
|
31
|
+
export declare function useToasts(options?: UseToastsOptions): UseToastsResult;
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import "./Badge.css";
|
|
3
3
|
/** The tones a badge draws; any other string is drawn neutrally. */
|
|
4
|
-
export type BadgeTone = "ok" | "warn" | "err" | "quiet" | "off" | (string & {});
|
|
4
|
+
export type BadgeTone = "ok" | "warn" | "err" | "quiet" | "off" | "accent" | "muted" | "added" | "removed" | "renamed" | "changed" | (string & {});
|
|
5
|
+
/** How a badge is drawn: outlined in its tone (the default), or filled with it. */
|
|
6
|
+
export type BadgeVariant = "outlined" | "filled";
|
|
5
7
|
export type BadgeProps = {
|
|
6
|
-
/** The badge's tone: its text and border colour
|
|
8
|
+
/** The badge's tone: its text and border colour (outlined) or its fill (filled). */
|
|
7
9
|
tone: BadgeTone;
|
|
10
|
+
/**
|
|
11
|
+
* Outlined (the default): text and border in the tone. Filled: the tone's fill under on-strong text, for a fact that
|
|
12
|
+
* must stand out.
|
|
13
|
+
*/
|
|
14
|
+
variant?: BadgeVariant;
|
|
8
15
|
/** What the badge says: a word, a count, a WarnMark beside them. */
|
|
9
16
|
children: ReactNode;
|
|
10
17
|
/** Shown on hover: what the badge means. */
|
|
@@ -13,4 +20,4 @@ export type BadgeProps = {
|
|
|
13
20
|
className?: string;
|
|
14
21
|
};
|
|
15
22
|
/** Draws a short word or count in a chip of its tone. */
|
|
16
|
-
export declare function Badge({ tone, children, title, className }: BadgeProps): import("react").JSX.Element;
|
|
23
|
+
export declare function Badge({ tone, variant, children, title, className }: BadgeProps): import("react").JSX.Element;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
export { Badge } from "./Badge";
|
|
2
|
-
export type { BadgeProps, BadgeTone } from "./Badge";
|
|
2
|
+
export type { BadgeProps, BadgeTone, BadgeVariant } from "./Badge";
|
|
@@ -9,5 +9,8 @@ export type ButtonProps = ComponentPropsWithRef<"button"> & {
|
|
|
9
9
|
size?: ButtonSize;
|
|
10
10
|
/** A request is on its way: a spinner over the words, aria-busy, and presses ignored. */
|
|
11
11
|
busy?: boolean;
|
|
12
|
+
/** The words shown while busy ("Saving"), beside the spinner; the width holds at the wider label, and the change is
|
|
13
|
+
* announced politely. On a button named by aria-label it replaces that name while busy. */
|
|
14
|
+
busyLabel?: string;
|
|
12
15
|
};
|
|
13
|
-
export declare function Button({ tone, size, busy, type, className, children, onClick, ...rest }: ButtonProps): import("react").JSX.Element;
|
|
16
|
+
export declare function Button({ tone, size, busy, busyLabel, type, className, children, onClick, ...rest }: ButtonProps): import("react").JSX.Element;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
2
|
import "./Pill.css";
|
|
3
3
|
/** The tones a pill draws; any other string is drawn neutrally. */
|
|
4
|
-
export type PillTone = "ok" | "warn" | "err" | "quiet" | "off" | (string & {});
|
|
4
|
+
export type PillTone = "ok" | "warn" | "err" | "quiet" | "off" | "accent" | "muted" | (string & {});
|
|
5
5
|
export type PillProps = {
|
|
6
6
|
/** The state's tone: the dot's and the word's colour. */
|
|
7
7
|
tone: PillTone;
|
package/package.json
CHANGED