@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.
- package/README.md +8 -7
- 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 +696 -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 +34 -16
- package/dist/primitives.js.map +1 -1
- package/dist/tokens.css +22 -2
- 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/add-at/index.d.ts +2 -0
- package/dist/types/graph/add-at/useAddAt.d.ts +32 -0
- package/dist/types/graph/canvas-tools/CanvasTools.d.ts +40 -0
- package/dist/types/graph/canvas-tools/index.d.ts +2 -0
- package/dist/types/graph/canvas-tools/motion.d.ts +2 -0
- package/dist/types/graph/connect-hints/index.d.ts +4 -0
- package/dist/types/graph/connect-hints/mergeFlowProps.d.ts +10 -0
- package/dist/types/graph/connect-hints/useConnectHints.d.ts +48 -0
- package/dist/types/graph/follow-fit/index.d.ts +2 -0
- package/dist/types/graph/follow-fit/useFollowFit.d.ts +21 -0
- package/dist/types/graph/ghost-wire/GhostWire.d.ts +16 -0
- package/dist/types/graph/ghost-wire/index.d.ts +2 -0
- package/dist/types/graph/index.d.ts +9 -1
- package/dist/types/graph/meter/Meter.d.ts +56 -0
- package/dist/types/graph/meter/index.d.ts +2 -0
- package/dist/types/graph/node-box/NodeBox.d.ts +53 -0
- package/dist/types/graph/node-box/geometry.d.ts +47 -0
- package/dist/types/graph/node-box/index.d.ts +4 -0
- package/dist/types/graph/port-row/PortRow.d.ts +31 -0
- package/dist/types/graph/port-row/index.d.ts +2 -0
- package/dist/types/graph/wire/Wire.d.ts +27 -0
- package/dist/types/graph/wire/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/button/Button.d.ts +4 -1
- package/package.json +2 -2
package/dist/tokens.css
CHANGED
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
--pb-motion-flow: 1s;
|
|
75
75
|
--pb-motion-spin: 0.8s;
|
|
76
76
|
|
|
77
|
-
/* Density: the spacing steps, a
|
|
77
|
+
/* Density: the spacing steps, a compact control's height, the top bar's height. */
|
|
78
78
|
--pb-space-1: 2px;
|
|
79
79
|
--pb-space-2: 4px;
|
|
80
80
|
--pb-space-3: 8px;
|
|
@@ -83,6 +83,18 @@
|
|
|
83
83
|
--pb-row: 22px;
|
|
84
84
|
--pb-bar: 44px;
|
|
85
85
|
|
|
86
|
+
/* Node geometry: a node box's fixed sizes, the same values as the constants /graph exports (NODE_WIDTH and the
|
|
87
|
+
rest), since an app lays its nodes out from those before they render. A brand may not set these; the tests hold
|
|
88
|
+
each equal to its constant and fail on a brand that sets one. */
|
|
89
|
+
--pb-node-width: 240px;
|
|
90
|
+
--pb-node-header: 46px;
|
|
91
|
+
--pb-node-line: 22px;
|
|
92
|
+
--pb-node-row: 22px;
|
|
93
|
+
--pb-node-pad: 8px;
|
|
94
|
+
--pb-node-footer: 28px;
|
|
95
|
+
--pb-node-handle: 10px;
|
|
96
|
+
--pb-node-handle-hit: 20px;
|
|
97
|
+
|
|
86
98
|
/* Type: the faces, the two text sizes, and the code boxes' size (shared by a textarea, its highlighted copy and a
|
|
87
99
|
gutter, so their glyphs line up). */
|
|
88
100
|
--pb-font-ui: system-ui, sans-serif;
|
|
@@ -171,10 +183,11 @@
|
|
|
171
183
|
}
|
|
172
184
|
|
|
173
185
|
/* A finger: every text field is 16 px, code boxes included, as iOS Safari zooms the page when a smaller field takes
|
|
174
|
-
the focus. */
|
|
186
|
+
the focus; a handle's hit area grows to 32 px (handles sit 22 px apart, too close for 36 px targets). */
|
|
175
187
|
@media (hover: none) and (pointer: coarse) {
|
|
176
188
|
:root {
|
|
177
189
|
--pb-code-size: 16px;
|
|
190
|
+
--pb-node-handle-hit: 32px;
|
|
178
191
|
}
|
|
179
192
|
}
|
|
180
193
|
|
|
@@ -219,3 +232,10 @@
|
|
|
219
232
|
--xy-minimap-node-background-color: var(--pb-sunken);
|
|
220
233
|
--xy-minimap-node-stroke-color: var(--pb-line-strong);
|
|
221
234
|
}
|
|
235
|
+
|
|
236
|
+
/* React Flow's attribution link is drawn in a fixed grey of its own, below 4.5:1 on its panel, with no variable to
|
|
237
|
+
point at a token; the muted text colour keeps it legible in both themes and under a brand. Written under .react-flow,
|
|
238
|
+
so it wins whichever of the two stylesheets an app loads first. */
|
|
239
|
+
.react-flow .react-flow__attribution a {
|
|
240
|
+
color: var(--pb-muted);
|
|
241
|
+
}
|
|
@@ -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;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import { type OnConnectEnd, type OnConnectStart } from "@xyflow/react";
|
|
2
|
+
import { type MouseEvent as ReactMouseEvent } from "react";
|
|
3
|
+
import type { PortRef } from "../connect-hints";
|
|
4
|
+
import type { PortSide } from "../port-row";
|
|
5
|
+
/** A point in flow coordinates. */
|
|
6
|
+
export type FlowPoint = {
|
|
7
|
+
x: number;
|
|
8
|
+
y: number;
|
|
9
|
+
};
|
|
10
|
+
/** Called with where to add, and the port a dropped wire came from (absent for a double-click). */
|
|
11
|
+
export type OnAddAt = (point: FlowPoint, from?: PortRef & {
|
|
12
|
+
side: PortSide;
|
|
13
|
+
}) => void;
|
|
14
|
+
/** The props `useAddAt` gives `<ReactFlow>`. */
|
|
15
|
+
export type AddAtFlowProps = {
|
|
16
|
+
onDoubleClick: (event: ReactMouseEvent<HTMLDivElement>) => void;
|
|
17
|
+
onConnectStart: OnConnectStart;
|
|
18
|
+
onConnectEnd: OnConnectEnd;
|
|
19
|
+
zoomOnDoubleClick: false;
|
|
20
|
+
};
|
|
21
|
+
export type AddAtOptions = {
|
|
22
|
+
/** false switches adding off (as while the graph is read-only); true by default. */
|
|
23
|
+
enabled?: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Calls `onAddAt` for a double-click on empty canvas and for a wire dropped there where no handle took it. Its
|
|
27
|
+
* `flowProps` go to `<ReactFlow>` (through `mergeFlowProps` with others); it turns React Flow's zoom on double-click
|
|
28
|
+
* off, as the double-click is the add.
|
|
29
|
+
*/
|
|
30
|
+
export declare function useAddAt(onAddAt: OnAddAt, options?: AddAtOptions): {
|
|
31
|
+
flowProps: AddAtFlowProps;
|
|
32
|
+
};
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { type FitViewOptions, type Node, type PanelPosition } from "@xyflow/react";
|
|
2
|
+
import type { ReactNode } from "react";
|
|
3
|
+
import "./CanvasTools.css";
|
|
4
|
+
/** The tools' words, each replaceable. */
|
|
5
|
+
export interface CanvasToolsLabels {
|
|
6
|
+
/** The tool group's accessible name: "Canvas". */
|
|
7
|
+
toolbar: string;
|
|
8
|
+
zoomIn: string;
|
|
9
|
+
zoomOut: string;
|
|
10
|
+
fit: string;
|
|
11
|
+
tidy: string;
|
|
12
|
+
minimap: string;
|
|
13
|
+
}
|
|
14
|
+
export declare const defaultCanvasToolsLabels: CanvasToolsLabels;
|
|
15
|
+
/** The app's own key bindings for the tools, as `aria-keyshortcuts` values: shown, not bound. */
|
|
16
|
+
export type CanvasToolsShortcuts = Partial<Record<"zoomIn" | "zoomOut" | "fit" | "tidy" | "minimap", string>>;
|
|
17
|
+
export type CanvasToolsProps<NodeType extends Node = Node> = {
|
|
18
|
+
/** Where the panel sits on the canvas, React Flow's `PanelPosition`: "bottom-left" by default. */
|
|
19
|
+
position?: PanelPosition | (string & {});
|
|
20
|
+
/** React Flow's fit options for the fit tool. */
|
|
21
|
+
fitOptions?: FitViewOptions<NodeType>;
|
|
22
|
+
/** Replaces the fit tool's own fit (pass useFollowFit's `fit`, so the tool also resumes following). */
|
|
23
|
+
onFit?: () => void;
|
|
24
|
+
/** The tidy tool, shown only when given: the layout is the app's. */
|
|
25
|
+
onTidy?: () => void;
|
|
26
|
+
/** Whether the minimap is on: the minimap tool is pressed and React Flow's <MiniMap> is drawn. */
|
|
27
|
+
minimap?: boolean;
|
|
28
|
+
/** The minimap tool, shown only when given: called with the state a press asks for. */
|
|
29
|
+
onMinimap?: (next: boolean) => void;
|
|
30
|
+
/** The class of each node's shape in the minimap, so the app colours it by the node's state. */
|
|
31
|
+
minimapNodeClassName?: string | ((node: NodeType) => string);
|
|
32
|
+
keyShortcuts?: CanvasToolsShortcuts;
|
|
33
|
+
/** Words to replace; the rest keep their defaults. */
|
|
34
|
+
labels?: Partial<CanvasToolsLabels>;
|
|
35
|
+
/** Added to the panel's own `pb-canvas-tools` class. */
|
|
36
|
+
className?: string;
|
|
37
|
+
/** More tools (IconButtons) after patchbay's. */
|
|
38
|
+
children?: ReactNode;
|
|
39
|
+
};
|
|
40
|
+
export declare function CanvasTools<NodeType extends Node = Node>({ position, fitOptions, onFit, onTidy, minimap, onMinimap, minimapNodeClassName, keyShortcuts, labels, className, children, }: CanvasToolsProps<NodeType>): import("react").JSX.Element;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export { mergeFlowProps } from "./mergeFlowProps";
|
|
2
|
+
export type { MergedFlowProps } from "./mergeFlowProps";
|
|
3
|
+
export { ConnectHints, useConnectHints } from "./useConnectHints";
|
|
4
|
+
export type { CanConnect, ConnectHintsFlowProps, ConnectHintsValue, PortHintOf, PortRef } from "./useConnectHints";
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
type UnionToIntersection<U> = (U extends unknown ? (each: U) => void : never) extends (each: infer I) => void ? I : never;
|
|
2
|
+
/** The objects' props together: each handler is every object's handler for that name. */
|
|
3
|
+
export type MergedFlowProps<T extends readonly (object | undefined)[]> = UnionToIntersection<Exclude<T[number], undefined>>;
|
|
4
|
+
/**
|
|
5
|
+
* One object of `<ReactFlow>` props from several: a handler given by more than one object calls each in order, and
|
|
6
|
+
* `isValidConnection` accepts only when each accepts (it stops at the first that refuses). Any other prop is the last
|
|
7
|
+
* object's that gives it; `undefined` gives nothing.
|
|
8
|
+
*/
|
|
9
|
+
export declare function mergeFlowProps<const T extends readonly (object | undefined)[]>(...objects: T): MergedFlowProps<T>;
|
|
10
|
+
export {};
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import type { Connection, Edge, OnConnectEnd, OnConnectStart } from "@xyflow/react";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import type { PortHint, PortSide } from "../port-row";
|
|
4
|
+
/** One handle: its node's id and its handle id (`null` for a handle without one). */
|
|
5
|
+
export type PortRef = {
|
|
6
|
+
nodeId: string;
|
|
7
|
+
handleId: string | null;
|
|
8
|
+
};
|
|
9
|
+
/**
|
|
10
|
+
* Whether a wire may join `from` (always the output) to `to` (always the input), whichever end the drag began at:
|
|
11
|
+
* `true` accepts, `false` refuses, a string refuses and is the reason.
|
|
12
|
+
*/
|
|
13
|
+
export type CanConnect = (from: PortRef, to: PortRef) => boolean | string;
|
|
14
|
+
/** What one handle shows while a wire is dragged, and why when it refuses. */
|
|
15
|
+
export type PortHintOf = {
|
|
16
|
+
hint: PortHint;
|
|
17
|
+
reason?: string;
|
|
18
|
+
};
|
|
19
|
+
/** The drag in progress, as `<ConnectHints>` hands it to every `PortRow`; `null` while no wire is dragged. */
|
|
20
|
+
export type ConnectHintsValue = {
|
|
21
|
+
/** The handle the drag began at, and its side. */
|
|
22
|
+
origin: PortRef & {
|
|
23
|
+
side: PortSide;
|
|
24
|
+
};
|
|
25
|
+
/** The hint for one handle: `origin`, `ok` or `no` (with its reason) on the other side, `null` on the origin's. */
|
|
26
|
+
hintFor: (port: PortRef, side: PortSide) => PortHintOf;
|
|
27
|
+
} | null;
|
|
28
|
+
/** The handlers `useConnectHints` gives `<ReactFlow>`. */
|
|
29
|
+
export type ConnectHintsFlowProps = {
|
|
30
|
+
onConnectStart: OnConnectStart;
|
|
31
|
+
onConnectEnd: OnConnectEnd;
|
|
32
|
+
isValidConnection: (connection: Edge | Connection) => boolean;
|
|
33
|
+
};
|
|
34
|
+
/** Hands a drag's hints to every `PortRow` inside it. */
|
|
35
|
+
export declare function ConnectHints({ value, children }: {
|
|
36
|
+
value: ConnectHintsValue;
|
|
37
|
+
children?: ReactNode;
|
|
38
|
+
}): import("react").JSX.Element;
|
|
39
|
+
/** The drag's hints from the nearest `<ConnectHints>`, or `null` outside one or while no wire is dragged. */
|
|
40
|
+
export declare function useConnectHintsValue(): ConnectHintsValue;
|
|
41
|
+
/**
|
|
42
|
+
* Tracks a wire's drag from React Flow's connect start to its end and judges each candidate handle by `canConnect`.
|
|
43
|
+
* `flowProps` goes to `<ReactFlow>` (through `mergeFlowProps` with others), `value` to `<ConnectHints>`.
|
|
44
|
+
*/
|
|
45
|
+
export declare function useConnectHints(canConnect: CanConnect): {
|
|
46
|
+
value: ConnectHintsValue;
|
|
47
|
+
flowProps: ConnectHintsFlowProps;
|
|
48
|
+
};
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { type FitViewOptions, type Node, type OnMove, type Viewport } from "@xyflow/react";
|
|
2
|
+
export type FollowFitOptions<NodeType extends Node = Node> = {
|
|
3
|
+
/** The app's value that changes when nodes are added, removed or laid out; a change fits again while following. */
|
|
4
|
+
key: unknown;
|
|
5
|
+
/** React Flow's fit options, for every fit. */
|
|
6
|
+
fitOptions?: FitViewOptions<NodeType>;
|
|
7
|
+
/** Called with the viewport after each fit has landed, in the frame after the viewport is set. */
|
|
8
|
+
onFitted?: (viewport: Viewport) => void;
|
|
9
|
+
};
|
|
10
|
+
/** The props `useFollowFit` gives `<ReactFlow>`. */
|
|
11
|
+
export type FollowFitFlowProps = {
|
|
12
|
+
onMoveStart: OnMove;
|
|
13
|
+
};
|
|
14
|
+
export type FollowFit = {
|
|
15
|
+
/** Whether the view fits again on its own: true from the start, false once the person moves the view. */
|
|
16
|
+
following: boolean;
|
|
17
|
+
/** Fits now, moving as the fit tool does, and follows again. */
|
|
18
|
+
fit: () => void;
|
|
19
|
+
flowProps: FollowFitFlowProps;
|
|
20
|
+
};
|
|
21
|
+
export declare function useFollowFit<NodeType extends Node = Node>({ key, fitOptions, onFitted, }: FollowFitOptions<NodeType>): FollowFit;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { type Edge, type EdgeProps } from "@xyflow/react";
|
|
2
|
+
import { type ReactNode } from "react";
|
|
3
|
+
import "./GhostWire.css";
|
|
4
|
+
/** `pending` (the default) or `refused`; any other string is drawn as `pending`. */
|
|
5
|
+
export type GhostWireTone = "pending" | "refused" | (string & {});
|
|
6
|
+
/** A ghost wire's look, as React Flow's edge `data`. */
|
|
7
|
+
export type GhostWireData = {
|
|
8
|
+
/** `pending` (dashed in the quiet tone, dimmed) or `refused` (the error tone). */
|
|
9
|
+
tone?: GhostWireTone;
|
|
10
|
+
/** At the midpoint, on the raised surface; it takes no pointer events. */
|
|
11
|
+
label?: ReactNode;
|
|
12
|
+
};
|
|
13
|
+
/** An edge drawn by `GhostWire`: register it as `edgeTypes={{ ghost: GhostWire }}`. */
|
|
14
|
+
export type GhostWireEdge = Edge<GhostWireData, "ghost">;
|
|
15
|
+
/** Draws a request's wire between two handles while it is on its way. */
|
|
16
|
+
export declare function GhostWire({ id, sourceX, sourceY, targetX, targetY, sourcePosition, targetPosition, data, }: EdgeProps<GhostWireEdge>): import("react").JSX.Element;
|
|
@@ -1 +1,9 @@
|
|
|
1
|
-
export
|
|
1
|
+
export * from "./add-at";
|
|
2
|
+
export * from "./canvas-tools";
|
|
3
|
+
export * from "./connect-hints";
|
|
4
|
+
export * from "./follow-fit";
|
|
5
|
+
export * from "./ghost-wire";
|
|
6
|
+
export * from "./meter";
|
|
7
|
+
export * from "./node-box";
|
|
8
|
+
export * from "./port-row";
|
|
9
|
+
export * from "./wire";
|
|
@@ -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,53 @@
|
|
|
1
|
+
import { type ComponentPropsWithoutRef, type ReactNode } from "react";
|
|
2
|
+
import { type PortRowProps } from "../port-row";
|
|
3
|
+
import type { NodePorts } from "./geometry";
|
|
4
|
+
import "./NodeBox.css";
|
|
5
|
+
/** A box's stripe down its start edge: an open enum, and one it does not know is drawn in `--pb-line-strong`. */
|
|
6
|
+
export type NodeBoxTone = "ok" | "warn" | "err" | "quiet" | "off" | "accent" | "muted" | (string & {});
|
|
7
|
+
/** An edit not yet applied: an open enum, and one it does not know is a plain border with its own string as the word. */
|
|
8
|
+
export type NodeBoxChange = "added" | "removed" | "renamed" | "changed" | (string & {});
|
|
9
|
+
/** The words of the change badge. */
|
|
10
|
+
export type NodeBoxChangeLabels = {
|
|
11
|
+
added: string;
|
|
12
|
+
removed: string;
|
|
13
|
+
renamed: string;
|
|
14
|
+
changed: string;
|
|
15
|
+
};
|
|
16
|
+
/** English defaults for `changeLabels`. */
|
|
17
|
+
export declare const defaultChangeLabels: NodeBoxChangeLabels;
|
|
18
|
+
/** One port of a box: a `PortRow`'s props without `side`, which `NodeBox` sets. */
|
|
19
|
+
export type PortSpec = Omit<PortRowProps, "side">;
|
|
20
|
+
export type NodeBoxProps = Omit<ComponentPropsWithoutRef<"div">, "title" | "children" | "role"> & {
|
|
21
|
+
/** The node's name, one line cut with an ellipsis; a string is also the header's tooltip. Names the box's group. */
|
|
22
|
+
title: ReactNode;
|
|
23
|
+
/** The second header line, muted: the node's type. */
|
|
24
|
+
subtitle?: ReactNode;
|
|
25
|
+
/** The stripe down the box's start edge, in the tone's colour; none, or one it does not know, in `--pb-line-strong`. */
|
|
26
|
+
tone?: NodeBoxTone;
|
|
27
|
+
/** A dashed border, the stripe hatched and the words muted. Drawing only: whether its ports connect is the app's. */
|
|
28
|
+
disabled?: boolean;
|
|
29
|
+
/** The border in `--pb-err` and the header on `--pb-err-soft`; the reason goes in `line`. */
|
|
30
|
+
failed?: boolean;
|
|
31
|
+
/** An edit not yet applied: a 2 px border in its tone and a badge with its word; `removed` strikes the title. */
|
|
32
|
+
change?: NodeBoxChange;
|
|
33
|
+
/** The change badge's words; English by default. */
|
|
34
|
+
changeLabels?: Partial<NodeBoxChangeLabels>;
|
|
35
|
+
/** A slot at the header's end (a `Pill`). */
|
|
36
|
+
status?: ReactNode;
|
|
37
|
+
/** One row under the header saying why the node is silent; a string is also its tooltip. */
|
|
38
|
+
line?: ReactNode;
|
|
39
|
+
/** The input ports, keyed by `id`. */
|
|
40
|
+
inputs?: readonly PortSpec[];
|
|
41
|
+
/** The output ports, keyed by `id`. */
|
|
42
|
+
outputs?: readonly PortSpec[];
|
|
43
|
+
/** `stacked` (the default: the inputs' rows, then the outputs') or `side-by-side` (two columns). */
|
|
44
|
+
ports?: NodePorts;
|
|
45
|
+
/** A slot: one row at the foot (badges). */
|
|
46
|
+
footer?: ReactNode;
|
|
47
|
+
/** Selected, from React Flow's `NodeProps`: a 2 px outline in the accent. */
|
|
48
|
+
selected?: boolean;
|
|
49
|
+
/** Its width in px; `NODE_WIDTH` by default. */
|
|
50
|
+
width?: number;
|
|
51
|
+
};
|
|
52
|
+
/** Draws a node's box; render it inside a React Flow node. */
|
|
53
|
+
export declare function NodeBox({ title, subtitle, tone, disabled, failed, change, changeLabels, status, line, inputs, outputs, ports, footer, selected, width, className, style, ...rest }: NodeBoxProps): import("react").JSX.Element;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/** The default width of a node box, in px; `NodeBox`'s `width` overrides it per node (`--pb-node-width`). */
|
|
2
|
+
export declare const NODE_WIDTH = 240;
|
|
3
|
+
/** The header (title and subtitle), with or without a subtitle, in px (`--pb-node-header`). */
|
|
4
|
+
export declare const NODE_HEADER = 46;
|
|
5
|
+
/** The `line` row, when there is one, in px (`--pb-node-line`). */
|
|
6
|
+
export declare const NODE_LINE = 22;
|
|
7
|
+
/** One port row, in px (`--pb-node-row`). */
|
|
8
|
+
export declare const NODE_ROW = 22;
|
|
9
|
+
/** The space above the first port row and below the last, in px (`--pb-node-pad`). */
|
|
10
|
+
export declare const NODE_PAD = 8;
|
|
11
|
+
/** The footer, when there is one, in px (`--pb-node-footer`). */
|
|
12
|
+
export declare const NODE_FOOTER = 28;
|
|
13
|
+
/** A handle's dot, in px (`--pb-node-handle`). */
|
|
14
|
+
export declare const HANDLE_SIZE = 10;
|
|
15
|
+
/** A handle's hit area, centred on the dot, in px (`--pb-node-handle-hit`); 32 px on a touch screen. */
|
|
16
|
+
export declare const HANDLE_HIT = 20;
|
|
17
|
+
/**
|
|
18
|
+
* How a node box lays out its ports: `stacked` (the inputs' rows, then the outputs') or `side-by-side` (two columns,
|
|
19
|
+
* row n of each on one line). An open enum; one it does not know is stacked.
|
|
20
|
+
*/
|
|
21
|
+
export type NodePorts = "stacked" | "side-by-side" | (string & {});
|
|
22
|
+
/** What decides a node box's size: its port counts, their layout, and whether it has a line and a footer. */
|
|
23
|
+
export type NodeBoxShape = {
|
|
24
|
+
/** How many input ports. */
|
|
25
|
+
inputs: number;
|
|
26
|
+
/** How many output ports. */
|
|
27
|
+
outputs: number;
|
|
28
|
+
/** How the ports are laid out. */
|
|
29
|
+
ports: NodePorts;
|
|
30
|
+
/** Whether it has a `line` row. */
|
|
31
|
+
line: boolean;
|
|
32
|
+
/** Whether it has a footer. */
|
|
33
|
+
footer: boolean;
|
|
34
|
+
/** Its width in px; `NODE_WIDTH` by default. */
|
|
35
|
+
width?: number;
|
|
36
|
+
};
|
|
37
|
+
/** How many port rows a box draws: inputs plus outputs stacked, the larger of the two side by side. */
|
|
38
|
+
export declare function nodePortRows(inputs: number, outputs: number, ports: NodePorts): number;
|
|
39
|
+
/**
|
|
40
|
+
* A node box's size in px, the one formula layout code sizes nodes with: the header, the line when there is one, the
|
|
41
|
+
* port rows and the padding above and below them when there are ports, and the footer when there is one. The box's
|
|
42
|
+
* 1 px border is inside it; the selection ring is outside.
|
|
43
|
+
*/
|
|
44
|
+
export declare function nodeBoxSize({ inputs, outputs, ports, line, footer, width }: NodeBoxShape): {
|
|
45
|
+
width: number;
|
|
46
|
+
height: number;
|
|
47
|
+
};
|