@mcurcio/patchbay 0.7.0 → 0.8.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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"shell.js","names":["inspectorBounds","drawerBounds","clamp","px","max","min","clampInspectorWidth","drawerMaxHeight","share","windowHeight","clampDrawerHeight","defaultAppShellLabels","subscribeToResize","onChange","useWindowHeight","useSyncExternalStore","DrawerGlyph","open","TopBar","brand","status","start","end","Drawer","bodyId","useId","height","drawer","words","Splitter","IconButton","AppShell","labels","layout","useMediaBreakpoint","width","inspector","wide","className","topBar","children","Sheet"],"sources":["../src/shell/app-shell/bounds.ts","../src/shell/app-shell/AppShell.tsx"],"sourcesContent":["// The sizes the shell holds its panes to (docs/components.md#appshell): an inspector 280–560 px wide, and a drawer\n// from 120 px to 70 % of the window's height. Pure, so an app can check a kept size with the same rules before it\n// draws (as usePersistentState's check).\n\n/** The inspector's width in px. */\nexport const inspectorBounds = { min: 280, max: 560 } as const;\n\n/** The drawer's height: at least `min` px, at most `maxShare` of the window's height. */\nexport const drawerBounds = { min: 120, maxShare: 0.7 } as const;\n\n/** `px` as whole px within `min` and `max`; a value that is not a finite number is `min`. */\nfunction clamp(px: number, min: number, max: number): number {\n if (!Number.isFinite(px)) return min;\n return Math.min(max, Math.max(min, Math.round(px)));\n}\n\n/** The inspector's width as drawn for an asked `px`: whole px within 280–560. */\nexport function clampInspectorWidth(px: number): number {\n return clamp(px, inspectorBounds.min, inspectorBounds.max);\n}\n\n/** The tallest the drawer may be in a window `windowHeight` px high: 70 % of it, and never below the least. */\nexport function drawerMaxHeight(windowHeight: number): number {\n const share = Number.isFinite(windowHeight) ? Math.floor(windowHeight * drawerBounds.maxShare) : 0;\n return Math.max(drawerBounds.min, share);\n}\n\n/** The drawer's height as drawn for an asked `px` in a window `windowHeight` px high. */\nexport function clampDrawerHeight(px: number, windowHeight: number): number {\n return clamp(px, drawerBounds.min, drawerMaxHeight(windowHeight));\n}\n","// The layout of a graph-editing app (docs/components.md#appshell): a top bar of slots, the canvas, an inspector on the\n// right and a drawer along the bottom, filling the screen (100dvh) inside the safe-area insets. It keeps no data: the\n// inspector's width, the drawer's height and whether each is open are the app's props, drawn within the shell's bounds\n// (bounds.ts) and changed through callbacks. Below 760 px the inspector is a Sheet over the canvas's right edge, below\n// 600 px one rising from the bottom (useMediaBreakpoint's widths). The drawer's body stays mounted while it is closed,\n// so what it holds (a draft, a caret, a scroll position) is still there when it opens.\nimport { type ReactNode, useId, useSyncExternalStore } from \"react\";\nimport { useMediaBreakpoint } from \"../../hooks\";\nimport { IconButton, Sheet, Splitter } from \"../../primitives\";\nimport { clampDrawerHeight, clampInspectorWidth, drawerBounds, drawerMaxHeight, inspectorBounds } from \"./bounds\";\nimport \"./AppShell.css\";\n\n/**\n * The top bar's slots, drawn in reading order (left to right in left-to-right text): the brand, a status, the app's\n * controls, and controls at the far end.\n */\nexport type AppShellTopBar = {\n /** The app's mark or name, first. */\n brand?: ReactNode;\n /** A short state after the brand (a connection's Pill). */\n status?: ReactNode;\n /** The app's controls, taking the free width. */\n start?: ReactNode;\n /** Controls at the far end (a theme switch, a menu). */\n end?: ReactNode;\n};\n\nexport type AppShellInspector = {\n /** What the inspector shows: usually a Panel, which scrolls on its own. */\n content: ReactNode;\n /** Whether it is shown; the app holds it. */\n open: boolean;\n /** Asked for with false when the person closes the narrow window's sheet (its close button, or Escape inside it). */\n onOpen: (open: boolean) => void;\n /** Its width in px, drawn within 280–560 px (`inspectorBounds`); a narrow window's sheet takes it too. */\n width: number;\n /** A new width from its splitter, in whole px within the bounds. */\n onWidth: (px: number) => void;\n};\n\nexport type AppShellDrawer = {\n /** The drawer's header, beside its show and hide button; shown while it is closed too. */\n header: ReactNode;\n /** The drawer's body, mounted while it is closed. */\n content: ReactNode;\n /** Whether its body is shown; the app holds it. */\n open: boolean;\n /** Asked for by its show and hide button. */\n onOpen: (open: boolean) => void;\n /** Its height in px while open, header included, drawn within 120 px and 70 % of the window (`drawerBounds`). */\n height: number;\n /** A new height from its splitter, in whole px within the bounds. */\n onHeight: (px: number) => void;\n};\n\n/** The shell's own words, each replaceable. */\nexport interface AppShellLabels {\n /** The inspector's name, as a region and as a sheet: \"Inspector\". */\n inspector: string;\n /** The drawer's name as a region: \"Drawer\". */\n drawer: string;\n /** The inspector's splitter: \"Resize the inspector\". */\n resizeInspector: string;\n /** The drawer's splitter: \"Resize the drawer\". */\n resizeDrawer: string;\n /** The drawer's button while it is closed: \"Show the drawer\". */\n showDrawer: string;\n /** The drawer's button while it is open: \"Hide the drawer\". */\n hideDrawer: string;\n /** The inspector sheet's close button: \"Close\". */\n close: string;\n}\n\nexport const defaultAppShellLabels: AppShellLabels = {\n inspector: \"Inspector\",\n drawer: \"Drawer\",\n resizeInspector: \"Resize the inspector\",\n resizeDrawer: \"Resize the drawer\",\n showDrawer: \"Show the drawer\",\n hideDrawer: \"Hide the drawer\",\n close: \"Close\",\n};\n\nexport type AppShellProps = {\n /** The top bar's slots; without them there is no bar. */\n topBar?: AppShellTopBar;\n /** The inspector; without it there is none. */\n inspector?: AppShellInspector;\n /** The drawer; without it there is none. */\n drawer?: AppShellDrawer;\n /** The canvas, filling the workspace. */\n children: ReactNode;\n /** Words to replace; the rest keep their defaults. */\n labels?: Partial<AppShellLabels>;\n /** A class added to the shell. */\n className?: string;\n};\n\nfunction subscribeToResize(onChange: () => void): () => void {\n window.addEventListener(\"resize\", onChange);\n return () => {\n window.removeEventListener(\"resize\", onChange);\n };\n}\n\n/** The window's height in px, kept current as it resizes; 0 with no window (the drawer then holds to its least). */\nfunction useWindowHeight(): number {\n return useSyncExternalStore(\n subscribeToResize,\n () => window.innerHeight,\n () => 0,\n );\n}\n\n/** A chevron pointing up (show) or down (hide), in the current text colour. */\nfunction DrawerGlyph({ open }: { open: boolean }) {\n return (\n <svg viewBox=\"0 0 16 16\" width=\"12\" height=\"12\" aria-hidden=\"true\">\n <path d={open ? \"M3 6l5 5 5-5\" : \"M3 10l5-5 5 5\"} fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.75\" />\n </svg>\n );\n}\n\nfunction TopBar({ brand, status, start, end }: AppShellTopBar) {\n return (\n <header className=\"pb-shell-bar\">\n {brand !== undefined && <div className=\"pb-shell-brand\">{brand}</div>}\n {status !== undefined && <div className=\"pb-shell-status\">{status}</div>}\n <div className=\"pb-shell-start\">{start}</div>\n {end !== undefined && <div className=\"pb-shell-end\">{end}</div>}\n </header>\n );\n}\n\nfunction Drawer({ drawer, words }: { drawer: AppShellDrawer; words: AppShellLabels }) {\n const bodyId = useId();\n const windowHeight = useWindowHeight();\n const height = clampDrawerHeight(drawer.height, windowHeight);\n return (\n <section\n className=\"pb-shell-drawer\"\n aria-label={words.drawer}\n data-open={drawer.open ? \"\" : undefined}\n style={drawer.open ? { height: `${height}px` } : undefined}\n >\n {drawer.open && (\n <Splitter\n orientation=\"horizontal\"\n edge=\"start\"\n value={height}\n min={drawerBounds.min}\n max={drawerMaxHeight(windowHeight)}\n onChange={drawer.onHeight}\n label={words.resizeDrawer}\n />\n )}\n <div className=\"pb-shell-drawer-head\">\n <div className=\"pb-shell-drawer-header\">{drawer.header}</div>\n <IconButton\n className=\"pb-shell-drawer-toggle\"\n label={drawer.open ? words.hideDrawer : words.showDrawer}\n aria-expanded={drawer.open}\n aria-controls={bodyId}\n onClick={() => {\n drawer.onOpen(!drawer.open);\n }}\n >\n <DrawerGlyph open={drawer.open} />\n </IconButton>\n </div>\n <div className=\"pb-shell-drawer-body\" id={bodyId} hidden={!drawer.open}>\n {drawer.content}\n </div>\n </section>\n );\n}\n\n/** Lays out a graph editor: top bar, canvas, inspector and drawer, with a sheet for the inspector on narrow windows. */\nexport function AppShell({ topBar, inspector, drawer, children, labels, className }: AppShellProps) {\n const words = { ...defaultAppShellLabels, ...labels };\n const { width: layout } = useMediaBreakpoint();\n const width = inspector === undefined ? 0 : clampInspectorWidth(inspector.width);\n const wide = layout === \"wide\";\n return (\n <div\n className={className === undefined ? \"pb-shell\" : `pb-shell ${className}`}\n data-layout={layout}\n data-bar={topBar === undefined ? undefined : \"\"}\n data-drawer={drawer === undefined ? undefined : \"\"}\n >\n {topBar !== undefined && <TopBar {...topBar} />}\n <div className=\"pb-shell-main\">\n <main className=\"pb-shell-workspace\">\n {children}\n {inspector !== undefined && !wide && (\n <Sheet\n open={inspector.open}\n onClose={() => {\n inspector.onOpen(false);\n }}\n side={layout === \"phone\" ? \"bottom\" : \"right\"}\n label={words.inspector}\n width={width}\n labels={{ close: words.close }}\n >\n {inspector.content}\n </Sheet>\n )}\n </main>\n {inspector !== undefined && wide && inspector.open && (\n <aside className=\"pb-shell-inspector\" aria-label={words.inspector} style={{ width: `${width}px` }}>\n <Splitter\n orientation=\"vertical\"\n edge=\"start\"\n value={width}\n min={inspectorBounds.min}\n max={inspectorBounds.max}\n onChange={inspector.onWidth}\n label={words.resizeInspector}\n />\n <div className=\"pb-shell-inspector-body\">{inspector.content}</div>\n </aside>\n )}\n </div>\n {drawer !== undefined && <Drawer drawer={drawer} words={words} />}\n </div>\n );\n}\n"],"mappings":";;;;;AAKA,IAAaA,IAAkB;CAAE,KAAK;CAAK,KAAK;AAAI,GAGvCC,IAAe;CAAE,KAAK;CAAK,UAAU;AAAI;AAGtD,SAASC,EAAM,GAAY,GAAa,GAAqB;CAE3D,OADK,OAAO,SAASC,CAAE,IAChB,KAAK,IAAIC,GAAK,KAAK,IAAIC,GAAK,KAAK,MAAMF,CAAE,CAAC,CAAC,IADjBE;AAEnC;AAGA,SAAgBC,EAAoB,GAAoB;CACtD,OAAOJ,EAAMC,GAAIH,EAAgB,KAAKA,EAAgB,GAAG;AAC3D;AAGA,SAAgBO,EAAgB,GAA8B;CAC5D,IAAMC,IAAQ,OAAO,SAASC,CAAY,IAAI,KAAK,MAAMA,IAAeR,EAAa,QAAQ,IAAI;CACjG,OAAO,KAAK,IAAIA,EAAa,KAAKO,CAAK;AACzC;AAGA,SAAgBE,EAAkB,GAAY,GA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AAf,UAAA,CACE,kBAAC,QAAD;KAAM,WAAU;KAAhB,UAAA,CACGC,GACAJ,MAAc,KAAA,KAAa,CAACC,KAC3B,kBAACI,GAAD;MACE,MAAML,EAAU;MAChB,eAAe;OACb,EAAU,OAAO,EAAK;MACxB;MACA,MAAMH,MAAW,UAAU,WAAW;MACtC,OAAOL,EAAM;MACN;MACP,QAAQ,EAAE,OAAOA,EAAM,MAAM;MAE5B,UAAAQ,EAAU;KACN,CAAA,CAEL;IACL,CAAA,GAAAA,MAAc,KAAA,KAAaC,KAAQD,EAAU,QAC5C,kBAAC,SAAD;KAAO,WAAU;KAAqB,cAAYR,EAAM;KAAW,OAAO,EAAE,OAAO,GAAGO,EAAM,IAAI;KAAhG,UAAA,CACE,kBAACN,GAAD;MACE,aAAY;MACZ,MAAK;MACL,OAAOM;MACP,KAAKnC,EAAgB;MACrB,KAAKA,EAAgB;MACrB,UAAUoC,EAAU;MACpB,OAAOR,EAAM;KACd,CAAA,GACD,kBAAC,OAAD;MAAK,WAAU;MAA2B,UAAAQ,EAAU;KAAa,CAAA,CAC5D;IAEN,CAAA,CAAA;;GACJT,MAAW,KAAA,KAAa,kBAACJ,GAAD;IAAgB;IAAe;GAAQ,CAAA;EAC7D;;AAET"}
@@ -0,0 +1,45 @@
1
+ import { type ComponentPropsWithRef } from "react";
2
+ import { type CodeCaret, type CodeDiagnostic, type CodeLanguage, type Highlighter } from "./highlight";
3
+ import "./CodeEditor.css";
4
+ /** The editor's own words, each replaceable. */
5
+ export interface CodeEditorLabels {
6
+ /** How a diagnostic is read, and shown over its gutter mark: "Line 3, column 5: error E1: message". */
7
+ diagnostic: (diagnostic: CodeDiagnostic) => string;
8
+ /** Read after the editor's name while it can be edited: how Tab works and how to leave. */
9
+ tabKey: string;
10
+ }
11
+ export declare const defaultCodeEditorLabels: CodeEditorLabels;
12
+ export type CodeEditorProps = Omit<ComponentPropsWithRef<"textarea">, "value" | "defaultValue" | "onChange"> & {
13
+ /** The text. CRLF and a lone CR are shown as LF, and an edit gives the text back with LF. */
14
+ value: string;
15
+ /** The person changed the text: the textarea's whole new value. */
16
+ onChange?: (value: string) => void;
17
+ /** A language built in ("knobly"); any other draws plain text. `highlight` wins over it. */
18
+ language?: CodeLanguage;
19
+ /** The app's highlighter, from the shown text to its spans. */
20
+ highlight?: Highlighter;
21
+ /** What the app found in the text, marked in the gutter and under the text, and read with the editor. */
22
+ diagnostics?: readonly CodeDiagnostic[];
23
+ /** The caret moved (by a key, a press, an edit or a gutter mark): its line, column and offset. */
24
+ onCaret?: (caret: CodeCaret) => void;
25
+ /** Show the line-number gutter (true by default). */
26
+ lineNumbers?: boolean;
27
+ /** What Tab inserts, and Shift+Tab takes away from a line's start: a tab by default. */
28
+ indent?: string;
29
+ /** Words to replace; the rest keep their defaults. */
30
+ labels?: Partial<CodeEditorLabels>;
31
+ };
32
+ /**
33
+ * What Tab (or Shift+Tab, `out`) does to a text and its selection: the range it replaces, with what, and the
34
+ * selection after. Tab in one line replaces the selection with the indent; across lines, and Shift+Tab always, it
35
+ * indents or outdents each line the selection touches (empty lines are left alone when indenting). Undefined when
36
+ * nothing would change.
37
+ */
38
+ export declare function tabEdit(text: string, start: number, end: number, indent: string, out: boolean): {
39
+ from: number;
40
+ to: number;
41
+ insert: string;
42
+ start: number;
43
+ end: number;
44
+ } | undefined;
45
+ export declare function CodeEditor({ value, onChange, language, highlight, diagnostics, onCaret, lineNumbers, indent, labels, readOnly, className, style, ref, onKeyDown, onBlur, onScroll, onSelect, "aria-describedby": describedBy, ...rest }: CodeEditorProps): import("react").JSX.Element;
@@ -0,0 +1,5 @@
1
+ import type { CodeRun } from "./highlight";
2
+ import "./CodeRuns.css";
3
+ export declare function CodeRuns({ runs }: {
4
+ runs: readonly CodeRun[];
5
+ }): (string | import("react").JSX.Element)[];
@@ -0,0 +1,12 @@
1
+ import { type ComponentPropsWithRef } from "react";
2
+ import { type CodeLanguage, type Highlighter } from "./highlight";
3
+ import "./CodeText.css";
4
+ export type CodeTextProps = Omit<ComponentPropsWithRef<"pre">, "children"> & {
5
+ /** The text; CRLF and a lone CR are drawn as LF. */
6
+ value: string;
7
+ /** A language built in ("knobly"); any other draws plain text. `highlight` wins over it. */
8
+ language?: CodeLanguage;
9
+ /** The app's highlighter, from the shown text to its spans. */
10
+ highlight?: Highlighter;
11
+ };
12
+ export declare function CodeText({ value, language, highlight, className, ...rest }: CodeTextProps): import("react").JSX.Element;
@@ -0,0 +1,83 @@
1
+ /** A highlighter's span: offsets into the shown text (`end` exclusive) and its class. */
2
+ export type CodeSpan = {
3
+ readonly start: number;
4
+ readonly end: number;
5
+ /**
6
+ * How it is drawn: "directive", "keyword", "word", "variable", "number", "string", "comment", "punctuation" or
7
+ * "error" have a colour each; "space", "" and any other class are drawn as plain text.
8
+ */
9
+ readonly class: string;
10
+ };
11
+ /** A highlighter: the text, as shown (LF line breaks), to its spans. Pure and total. */
12
+ export type Highlighter = (text: string) => readonly CodeSpan[];
13
+ /** A language built in: "knobly"; any other is drawn as plain text unless a highlighter is given. */
14
+ export type CodeLanguage = "knobly" | (string & {});
15
+ /** How bad a diagnostic is: "error" and "warning" have their own mark; any other is drawn neutrally. */
16
+ export type CodeSeverity = "error" | "warning" | (string & {});
17
+ /** Something the app found in the text: a line (from 1) and an optional column (from 1, in UTF-16 code units). */
18
+ export type CodeDiagnostic = {
19
+ line: number;
20
+ column?: number;
21
+ severity: CodeSeverity;
22
+ message: string;
23
+ /** The app's own code for it, read with the message. */
24
+ code?: string;
25
+ };
26
+ /** Where the caret is: a line and a column, both from 1, and its offset into the shown text. */
27
+ export type CodeCaret = {
28
+ line: number;
29
+ column: number;
30
+ offset: number;
31
+ };
32
+ /** The mark a severity draws. */
33
+ export type CodeMarkLevel = "error" | "warning" | "other";
34
+ /** One run of shown text, drawn in one class with at most one mark. */
35
+ export type CodeRun = {
36
+ text: string;
37
+ class: string;
38
+ mark?: CodeMarkLevel;
39
+ };
40
+ /** One gutter row per shown line, with its diagnostics in the order given. */
41
+ export type CodeGutterRow = {
42
+ line: number;
43
+ mark?: CodeMarkLevel;
44
+ /** Where a press on its mark puts the caret: the first diagnostic's column, else 1. */
45
+ column: number;
46
+ diagnostics: CodeDiagnostic[];
47
+ };
48
+ /**
49
+ * The text as a textarea shows it: a textarea holds LF line breaks only, so CRLF and a lone CR are drawn as LF. The
50
+ * value itself is never changed.
51
+ */
52
+ export declare function shownText(text: string): string;
53
+ /** Where each line of shown text starts. "" is one line, and a last newline starts an empty one after it. */
54
+ export declare function lineStarts(shown: string): number[];
55
+ /** The caret at an offset into the shown text, clamped to the text. */
56
+ export declare function caretAt(shown: string, offset: number): CodeCaret;
57
+ /** The offset of a line and column (both from 1) into the shown text, each clamped to the text. */
58
+ export declare function offsetAt(shown: string, line: number, column?: number): number;
59
+ /** The mark a severity draws: error, warning, or a neutral one for any other. */
60
+ export declare function markLevel(severity: string): CodeMarkLevel;
61
+ /** A diagnostic's mark in the shown text: from its column to the word's end, or the line's text without a column. */
62
+ export declare function markRange(shown: string, diagnostic: CodeDiagnostic): {
63
+ start: number;
64
+ end: number;
65
+ };
66
+ /**
67
+ * The shown text cut into runs by the spans (clipped to the text, empty ones ignored; where two overlap, the later
68
+ * one wins) and the diagnostics' marks (where two overlap, error over warning over any other). Joined, the runs are
69
+ * the shown text exactly.
70
+ */
71
+ export declare function codeRuns(shown: string, spans?: readonly CodeSpan[], diagnostics?: readonly CodeDiagnostic[]): CodeRun[];
72
+ /** One row per shown line; a diagnostic's line is clamped to the text, so one past the end marks the last line. */
73
+ export declare function gutterRows(shown: string, diagnostics?: readonly CodeDiagnostic[]): CodeGutterRow[];
74
+ /**
75
+ * Loads knobly's highlighter from the optional knobly peer, once for the page; null when knobly is not installed (the
76
+ * view then draws plain text, and says so once on the console).
77
+ */
78
+ export declare function loadKnobly(): Promise<Highlighter | null>;
79
+ /**
80
+ * The highlighter a view draws with: the app's `highlight` when given, else knobly's for language "knobly" (once
81
+ * loaded; plain text until then), else none.
82
+ */
83
+ export declare function useHighlighter(language: CodeLanguage | undefined, highlight: Highlighter | undefined): Highlighter | undefined;
@@ -0,0 +1,6 @@
1
+ export { CodeEditor, defaultCodeEditorLabels, tabEdit } from "./CodeEditor";
2
+ export type { CodeEditorLabels, CodeEditorProps } from "./CodeEditor";
3
+ export { CodeText } from "./CodeText";
4
+ export type { CodeTextProps } from "./CodeText";
5
+ export { caretAt, codeRuns, gutterRows, loadKnobly, markLevel, offsetAt, shownText } from "./highlight";
6
+ export type { CodeCaret, CodeDiagnostic, CodeGutterRow, CodeLanguage, CodeMarkLevel, CodeRun, CodeSeverity, CodeSpan, Highlighter, } from "./highlight";
@@ -1,4 +1,5 @@
1
1
  export * from "./banner";
2
+ export * from "./code-editor";
2
3
  export * from "./command-palette";
3
4
  export * from "./diff-view";
4
5
  export * from "./shortcut-sheet";
@@ -10,12 +10,15 @@ export type FollowFitOptions<NodeType extends Node = Node> = {
10
10
  /** The props `useFollowFit` gives `<ReactFlow>`. */
11
11
  export type FollowFitFlowProps = {
12
12
  onMoveStart: OnMove;
13
+ onMoveEnd: OnMove;
13
14
  };
14
15
  export type FollowFit = {
15
16
  /** Whether the view fits again on its own: true from the start, false once the person moves the view. */
16
17
  following: boolean;
17
18
  /** Fits now, moving as the fit tool does, and follows again. */
18
19
  fit: () => void;
20
+ /** Stops following, as the person's own move does: for an app that moves the view itself (going to a node). */
21
+ stop: () => void;
19
22
  flowProps: FollowFitFlowProps;
20
23
  };
21
24
  export declare function useFollowFit<NodeType extends Node = Node>({ key, fitOptions, onFitted, }: FollowFitOptions<NodeType>): FollowFit;
@@ -0,0 +1,76 @@
1
+ import { type ReactNode } from "react";
2
+ import "./AppShell.css";
3
+ /**
4
+ * The top bar's slots, drawn in reading order (left to right in left-to-right text): the brand, a status, the app's
5
+ * controls, and controls at the far end.
6
+ */
7
+ export type AppShellTopBar = {
8
+ /** The app's mark or name, first. */
9
+ brand?: ReactNode;
10
+ /** A short state after the brand (a connection's Pill). */
11
+ status?: ReactNode;
12
+ /** The app's controls, taking the free width. */
13
+ start?: ReactNode;
14
+ /** Controls at the far end (a theme switch, a menu). */
15
+ end?: ReactNode;
16
+ };
17
+ export type AppShellInspector = {
18
+ /** What the inspector shows: usually a Panel, which scrolls on its own. */
19
+ content: ReactNode;
20
+ /** Whether it is shown; the app holds it. */
21
+ open: boolean;
22
+ /** Asked for with false when the person closes the narrow window's sheet (its close button, or Escape inside it). */
23
+ onOpen: (open: boolean) => void;
24
+ /** Its width in px, drawn within 280–560 px (`inspectorBounds`); a narrow window's sheet takes it too. */
25
+ width: number;
26
+ /** A new width from its splitter, in whole px within the bounds. */
27
+ onWidth: (px: number) => void;
28
+ };
29
+ export type AppShellDrawer = {
30
+ /** The drawer's header, beside its show and hide button; shown while it is closed too. */
31
+ header: ReactNode;
32
+ /** The drawer's body, mounted while it is closed. */
33
+ content: ReactNode;
34
+ /** Whether its body is shown; the app holds it. */
35
+ open: boolean;
36
+ /** Asked for by its show and hide button. */
37
+ onOpen: (open: boolean) => void;
38
+ /** Its height in px while open, header included, drawn within 120 px and 70 % of the window (`drawerBounds`). */
39
+ height: number;
40
+ /** A new height from its splitter, in whole px within the bounds. */
41
+ onHeight: (px: number) => void;
42
+ };
43
+ /** The shell's own words, each replaceable. */
44
+ export interface AppShellLabels {
45
+ /** The inspector's name, as a region and as a sheet: "Inspector". */
46
+ inspector: string;
47
+ /** The drawer's name as a region: "Drawer". */
48
+ drawer: string;
49
+ /** The inspector's splitter: "Resize the inspector". */
50
+ resizeInspector: string;
51
+ /** The drawer's splitter: "Resize the drawer". */
52
+ resizeDrawer: string;
53
+ /** The drawer's button while it is closed: "Show the drawer". */
54
+ showDrawer: string;
55
+ /** The drawer's button while it is open: "Hide the drawer". */
56
+ hideDrawer: string;
57
+ /** The inspector sheet's close button: "Close". */
58
+ close: string;
59
+ }
60
+ export declare const defaultAppShellLabels: AppShellLabels;
61
+ export type AppShellProps = {
62
+ /** The top bar's slots; without them there is no bar. */
63
+ topBar?: AppShellTopBar;
64
+ /** The inspector; without it there is none. */
65
+ inspector?: AppShellInspector;
66
+ /** The drawer; without it there is none. */
67
+ drawer?: AppShellDrawer;
68
+ /** The canvas, filling the workspace. */
69
+ children: ReactNode;
70
+ /** Words to replace; the rest keep their defaults. */
71
+ labels?: Partial<AppShellLabels>;
72
+ /** A class added to the shell. */
73
+ className?: string;
74
+ };
75
+ /** Lays out a graph editor: top bar, canvas, inspector and drawer, with a sheet for the inspector on narrow windows. */
76
+ export declare function AppShell({ topBar, inspector, drawer, children, labels, className }: AppShellProps): import("react").JSX.Element;
@@ -0,0 +1,16 @@
1
+ /** The inspector's width in px. */
2
+ export declare const inspectorBounds: {
3
+ readonly min: 280;
4
+ readonly max: 560;
5
+ };
6
+ /** The drawer's height: at least `min` px, at most `maxShare` of the window's height. */
7
+ export declare const drawerBounds: {
8
+ readonly min: 120;
9
+ readonly maxShare: 0.7;
10
+ };
11
+ /** The inspector's width as drawn for an asked `px`: whole px within 280–560. */
12
+ export declare function clampInspectorWidth(px: number): number;
13
+ /** The tallest the drawer may be in a window `windowHeight` px high: 70 % of it, and never below the least. */
14
+ export declare function drawerMaxHeight(windowHeight: number): number;
15
+ /** The drawer's height as drawn for an asked `px` in a window `windowHeight` px high. */
16
+ export declare function clampDrawerHeight(px: number, windowHeight: number): number;
@@ -0,0 +1,3 @@
1
+ export { AppShell, defaultAppShellLabels } from "./AppShell";
2
+ export type { AppShellDrawer, AppShellInspector, AppShellLabels, AppShellProps, AppShellTopBar } from "./AppShell";
3
+ export { clampDrawerHeight, clampInspectorWidth, drawerBounds, drawerMaxHeight, inspectorBounds } from "./bounds";
@@ -1 +1 @@
1
- export {};
1
+ export * from "./app-shell";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@mcurcio/patchbay",
3
- "version": "0.7.0",
3
+ "version": "0.8.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",