@mcurcio/patchbay 0.4.0 → 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.
Files changed (55) hide show
  1. package/README.md +8 -7
  2. package/dist/composites.css +1 -1
  3. package/dist/composites.js +573 -53
  4. package/dist/composites.js.map +1 -1
  5. package/dist/graph.css +1 -0
  6. package/dist/graph.js +696 -0
  7. package/dist/graph.js.map +1 -0
  8. package/dist/hooks.js +433 -28
  9. package/dist/hooks.js.map +1 -1
  10. package/dist/primitives.css +1 -1
  11. package/dist/primitives.js +34 -16
  12. package/dist/primitives.js.map +1 -1
  13. package/dist/tokens.css +22 -2
  14. package/dist/types/composites/command-palette/CommandPalette.d.ts +68 -0
  15. package/dist/types/composites/command-palette/index.d.ts +4 -0
  16. package/dist/types/composites/command-palette/rank.d.ts +39 -0
  17. package/dist/types/composites/index.d.ts +3 -0
  18. package/dist/types/composites/shortcut-sheet/ShortcutSheet.d.ts +41 -0
  19. package/dist/types/composites/shortcut-sheet/index.d.ts +2 -0
  20. package/dist/types/composites/toaster/Toaster.d.ts +38 -0
  21. package/dist/types/composites/toaster/index.d.ts +2 -0
  22. package/dist/types/graph/add-at/index.d.ts +2 -0
  23. package/dist/types/graph/add-at/useAddAt.d.ts +32 -0
  24. package/dist/types/graph/canvas-tools/CanvasTools.d.ts +40 -0
  25. package/dist/types/graph/canvas-tools/index.d.ts +2 -0
  26. package/dist/types/graph/canvas-tools/motion.d.ts +2 -0
  27. package/dist/types/graph/connect-hints/index.d.ts +4 -0
  28. package/dist/types/graph/connect-hints/mergeFlowProps.d.ts +10 -0
  29. package/dist/types/graph/connect-hints/useConnectHints.d.ts +48 -0
  30. package/dist/types/graph/follow-fit/index.d.ts +2 -0
  31. package/dist/types/graph/follow-fit/useFollowFit.d.ts +21 -0
  32. package/dist/types/graph/ghost-wire/GhostWire.d.ts +16 -0
  33. package/dist/types/graph/ghost-wire/index.d.ts +2 -0
  34. package/dist/types/graph/index.d.ts +9 -1
  35. package/dist/types/graph/meter/Meter.d.ts +56 -0
  36. package/dist/types/graph/meter/index.d.ts +2 -0
  37. package/dist/types/graph/node-box/NodeBox.d.ts +53 -0
  38. package/dist/types/graph/node-box/geometry.d.ts +47 -0
  39. package/dist/types/graph/node-box/index.d.ts +4 -0
  40. package/dist/types/graph/port-row/PortRow.d.ts +31 -0
  41. package/dist/types/graph/port-row/index.d.ts +2 -0
  42. package/dist/types/graph/wire/Wire.d.ts +27 -0
  43. package/dist/types/graph/wire/index.d.ts +2 -0
  44. package/dist/types/hooks/index.d.ts +4 -0
  45. package/dist/types/hooks/use-live-value/index.d.ts +2 -0
  46. package/dist/types/hooks/use-live-value/useLiveValue.d.ts +9 -0
  47. package/dist/types/hooks/use-media-breakpoint/index.d.ts +2 -0
  48. package/dist/types/hooks/use-media-breakpoint/useMediaBreakpoint.d.ts +25 -0
  49. package/dist/types/hooks/use-shortcuts/index.d.ts +2 -0
  50. package/dist/types/hooks/use-shortcuts/useShortcuts.d.ts +58 -0
  51. package/dist/types/hooks/use-toasts/index.d.ts +4 -0
  52. package/dist/types/hooks/use-toasts/toastQueue.d.ts +76 -0
  53. package/dist/types/hooks/use-toasts/useToasts.d.ts +31 -0
  54. package/dist/types/primitives/button/Button.d.ts +4 -1
  55. package/package.json +2 -2
@@ -0,0 +1,4 @@
1
+ export { defaultChangeLabels, NodeBox } from "./NodeBox";
2
+ export type { NodeBoxChange, NodeBoxChangeLabels, NodeBoxProps, NodeBoxTone, PortSpec } from "./NodeBox";
3
+ export { HANDLE_HIT, HANDLE_SIZE, NODE_FOOTER, NODE_HEADER, NODE_LINE, NODE_PAD, NODE_ROW, NODE_WIDTH, nodeBoxSize, } from "./geometry";
4
+ export type { NodeBoxShape, NodePorts } from "./geometry";
@@ -0,0 +1,31 @@
1
+ import type { ReactNode } from "react";
2
+ import "./PortRow.css";
3
+ /** Which side of the box a port is on: an input is a target handle on the left edge, an output a source on the right. */
4
+ export type PortSide = "input" | "output";
5
+ /**
6
+ * What a port shows while a wire is dragged: `origin` the handle the drag began at, `ok` a handle that accepts it,
7
+ * `no` one that refuses it, `null` no drag. An open enum; one it does not know is drawn as `null`.
8
+ */
9
+ export type PortHint = "ok" | "no" | "origin" | null | (string & {});
10
+ export type PortRowProps = {
11
+ /** The handle id, passed to React Flow's `<Handle id>` unchanged (the app's own scheme). */
12
+ id: string;
13
+ /** `input` (a target handle on the left edge) or `output` (a source handle on the right edge). */
14
+ side: PortSide;
15
+ /** The port's name; a string is also its tooltip. */
16
+ label: ReactNode;
17
+ /** After the label in the muted code face: the port's type. */
18
+ typeLabel?: ReactNode;
19
+ /** While a wire is dragged: `origin`, `ok`, `no`, or `null` for no drag. Given, it wins over `<ConnectHints>`'. */
20
+ hint?: PortHint;
21
+ /** Why the port refuses the wire: the handle's and the row's tooltip while `hint` is `no`. */
22
+ reason?: string;
23
+ /** A problem with the port: a warning mark beside the label, with these as its words. */
24
+ problem?: string;
25
+ /** A slot at the row's inner end, toward the box's centre (a `Meter`). */
26
+ trailing?: ReactNode;
27
+ /** Whether a wire may start or end here; true by default (`<Handle isConnectable>`). */
28
+ connectable?: boolean;
29
+ };
30
+ /** Draws one port: its handle at the edge, its label and type, a problem's mark and a trailing slot. */
31
+ export declare function PortRow({ id, side, label, typeLabel, hint: ownHint, reason: ownReason, problem, trailing, connectable, }: PortRowProps): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { PortRow } from "./PortRow";
2
+ export type { PortHint, PortRowProps, PortSide } from "./PortRow";
@@ -0,0 +1,27 @@
1
+ import { type Edge, type EdgeProps } from "@xyflow/react";
2
+ import { type ReactNode } from "react";
3
+ import type { PillTone } from "../../primitives";
4
+ import "./Wire.css";
5
+ /** Pill's tones, the changes, `pending` and `refused`; any other string is drawn in the edge stroke. */
6
+ export type WireTone = PillTone | "added" | "removed" | "changed" | "pending" | "refused" | (string & {});
7
+ /** A wire's look, as React Flow's edge `data`. */
8
+ export type WireData = {
9
+ /** The stroke's tone; none, or one it does not know, is React Flow's edge stroke. */
10
+ tone?: WireTone;
11
+ /** The signal's level, 0 to 1 (clamped; not a number is 0): thickness and brightness. None is the plain wire. */
12
+ emphasis?: number;
13
+ /** Dashes: an edit not yet saved. */
14
+ dashed?: boolean;
15
+ /** Dots moving along the wire toward the input; not drawn under reduced motion. */
16
+ flow?: boolean;
17
+ /** An arrowhead at the input end, facing the handle's side. */
18
+ arrow?: boolean;
19
+ /** At the midpoint, on the raised surface; it takes no pointer events. */
20
+ label?: ReactNode;
21
+ /** The wire's tooltip, on its hit path. */
22
+ title?: string;
23
+ };
24
+ /** An edge drawn by `Wire`: register it as `edgeTypes={{ wire: Wire }}`. */
25
+ export type WireEdge = Edge<WireData, "wire">;
26
+ /** Draws a wire between two handles: its tone, level, dashes, flow, arrow, label and tooltip from the edge's data. */
27
+ export declare function Wire({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data, selected, interactionWidth, markerStart, markerEnd, style, }: EdgeProps<WireEdge>): import("react").JSX.Element;
@@ -0,0 +1,2 @@
1
+ export { Wire } from "./Wire";
2
+ export type { WireData, WireEdge, WireTone } from "./Wire";
@@ -1,2 +1,6 @@
1
+ export * from "./use-live-value";
2
+ export * from "./use-media-breakpoint";
1
3
  export * from "./use-persistent-state";
4
+ export * from "./use-shortcuts";
2
5
  export * from "./use-theme";
6
+ export * from "./use-toasts";
@@ -0,0 +1,2 @@
1
+ export { useLiveValue } from "./useLiveValue";
2
+ export type { LiveSubscribe } from "./useLiveValue";
@@ -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,2 @@
1
+ export { mediaQueries, narrowBelow, phoneBelow, readBreakpoint, serverBreakpoint, useMediaBreakpoint, widthOf, } from "./useMediaBreakpoint";
2
+ export type { MediaBreakpoint, MediaWidth } from "./useMediaBreakpoint";
@@ -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,2 @@
1
+ export { ariaKeyShortcuts, detectPlatform, findShortcut, isTextTarget, keyLabel, matchesKeys, useShortcuts, } from "./useShortcuts";
2
+ export type { Platform, Shortcut, UseShortcutsOptions } from "./useShortcuts";
@@ -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;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcurcio/patchbay",
3
- "version": "0.4.0",
3
+ "version": "0.6.0",
4
4
  "description": "A React component library for graph-based editors and live dashboards: design tokens and themes, primitives, and React Flow graph components",
5
5
  "keywords": [
6
6
  "react",
@@ -74,7 +74,7 @@
74
74
  "check": "pnpm typecheck && pnpm lint && pnpm format:check && pnpm test && pnpm build"
75
75
  },
76
76
  "peerDependencies": {
77
- "@xyflow/react": "^12.0.0",
77
+ "@xyflow/react": "^12.1.0",
78
78
  "knobly": "^1.0.0",
79
79
  "react": "^19.0.0",
80
80
  "react-dom": "^19.0.0"