@danxbot/ui 2.4.0 → 2.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/dist/index.js +12319 -11679
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/types/components/node-canvas/NodeCanvas.d.ts +58 -0
- package/dist/types/components/node-canvas/index.d.ts +3 -0
- package/dist/types/components/node-canvas/layout.d.ts +17 -0
- package/dist/types/components/node-canvas/types.d.ts +113 -0
- package/dist/types/components/node-canvas/use-canvas-gestures.d.ts +39 -0
- package/dist/types/index.d.ts +1 -0
- package/package.json +2 -2
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CanvasNode, CanvasOrientation, NodeRenderer } from "./types";
|
|
2
|
+
export interface NodeCanvasProps<Extra = unknown> {
|
|
3
|
+
/** The whole tree. The canvas walks into it; it never mutates it. */
|
|
4
|
+
root: CanvasNode<Extra>;
|
|
5
|
+
/**
|
|
6
|
+
* What this canvas IS — "Org chart", "Dependency graph for the March build".
|
|
7
|
+
*
|
|
8
|
+
* Required for the same reason `StatusChecklist.label` and
|
|
9
|
+
* `KanbanBoard.label` are: it is the accessible name of the whole structure,
|
|
10
|
+
* and somebody landing on it by keyboard has nothing else to tell them what
|
|
11
|
+
* they are inside.
|
|
12
|
+
*/
|
|
13
|
+
label: string;
|
|
14
|
+
/**
|
|
15
|
+
* The node body. Receives the consumer's own node type and a context of
|
|
16
|
+
* purely structural facts.
|
|
17
|
+
*
|
|
18
|
+
* A RENDER PROP RATHER THAN CHILDREN-AS-A-FUNCTION, because a canvas draws
|
|
19
|
+
* MANY nodes and `children` reads as one. `<NodeCanvas>{(node) => …}` looks
|
|
20
|
+
* like a single child and is really a template invoked N times, which is the
|
|
21
|
+
* ambiguity this library already avoids elsewhere (`ProvenanceDisclosure`
|
|
22
|
+
* takes `actions`, `Chat` takes a `components` map). It is optional: the
|
|
23
|
+
* default draws the `label` the node already declares and nothing else, so
|
|
24
|
+
* the component is usable with no wiring and the default introduces no
|
|
25
|
+
* vocabulary of its own.
|
|
26
|
+
*/
|
|
27
|
+
renderNode?: NodeRenderer<Extra>;
|
|
28
|
+
/** Which way the chart grows. See `CanvasOrientation`. */
|
|
29
|
+
orientation?: CanvasOrientation;
|
|
30
|
+
/** Levels below the current root to draw. `1` is the root and its children. */
|
|
31
|
+
depth?: number;
|
|
32
|
+
/** Along-axis extent of a node that does not declare its own, in px. */
|
|
33
|
+
nodeWidth?: number;
|
|
34
|
+
/** Cross-axis extent of a node that does not declare its own, in px. */
|
|
35
|
+
nodeHeight?: number;
|
|
36
|
+
/** Height of the scrolling viewport. Any CSS length. */
|
|
37
|
+
height?: string;
|
|
38
|
+
/**
|
|
39
|
+
* Fired after the canvas re-roots, with the trail from the ORIGINAL root.
|
|
40
|
+
*
|
|
41
|
+
* Observation, not control: the canvas owns where it is. A consumer that
|
|
42
|
+
* needs to restore a position across a reload stores this and remounts with
|
|
43
|
+
* a different `root`.
|
|
44
|
+
*/
|
|
45
|
+
onRootChange?: (node: CanvasNode<Extra>, path: CanvasNode<Extra>[]) => void;
|
|
46
|
+
/** Fired when a node drag commits. The offset is from its laid-out position. */
|
|
47
|
+
onNodeDragEnd?: (event: {
|
|
48
|
+
id: string;
|
|
49
|
+
offset: {
|
|
50
|
+
x: number;
|
|
51
|
+
y: number;
|
|
52
|
+
};
|
|
53
|
+
}) => void;
|
|
54
|
+
/** Nothing pans, drags or descends. Reading still works, including by keyboard. */
|
|
55
|
+
disabled?: boolean;
|
|
56
|
+
className?: string;
|
|
57
|
+
}
|
|
58
|
+
export declare function NodeCanvas<Extra = unknown>({ root, label, renderNode, orientation, depth, nodeWidth, nodeHeight, height, onRootChange, onNodeDragEnd, disabled, className, }: NodeCanvasProps<Extra>): import("react").JSX.Element;
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
export { NodeCanvas, type NodeCanvasProps } from "./NodeCanvas";
|
|
2
|
+
export { LAYOUT_DEFAULTS, layoutTree, pathToNode } from "./layout";
|
|
3
|
+
export type { CanvasEdge, CanvasLayout, CanvasNode, CanvasOrientation, LayoutOptions, NodeRenderContext, NodeRenderer, PlacedNode, } from "./types";
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { CanvasLayout, CanvasNode, LayoutOptions } from "./types";
|
|
2
|
+
export declare const LAYOUT_DEFAULTS: Required<LayoutOptions>;
|
|
3
|
+
/**
|
|
4
|
+
* Lay a tree out.
|
|
5
|
+
*
|
|
6
|
+
* Coordinates are plane-local and start at 0 on both axes: the caller decides
|
|
7
|
+
* where the plane sits and how much padding surrounds it.
|
|
8
|
+
*/
|
|
9
|
+
export declare function layoutTree<Extra>(root: CanvasNode<Extra>, options?: LayoutOptions): CanvasLayout<Extra>;
|
|
10
|
+
/**
|
|
11
|
+
* The ids from the ORIGINAL root down to `targetId`, inclusive.
|
|
12
|
+
*
|
|
13
|
+
* `null` when the id is not in the tree, which the canvas treats as a
|
|
14
|
+
* programming error rather than as an empty trail — a breadcrumb that silently
|
|
15
|
+
* renders nothing is how a broken `rootId` looks like a styling bug.
|
|
16
|
+
*/
|
|
17
|
+
export declare function pathToNode<Extra>(root: CanvasNode<Extra>, targetId: string): CanvasNode<Extra>[] | null;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import type { ReactNode } from "react";
|
|
2
|
+
/**
|
|
3
|
+
* One node of the tree.
|
|
4
|
+
*
|
|
5
|
+
* `Extra` carries the consumer's own fields DOWN THE WHOLE TREE, so
|
|
6
|
+
* `renderNode` receives their type rather than ours plus a cast:
|
|
7
|
+
*
|
|
8
|
+
* ```ts
|
|
9
|
+
* type Task = { owner: string; done: boolean };
|
|
10
|
+
* const root: CanvasNode<Task> = { id: "r", label: "Release", owner: "ada", done: false, children: [...] };
|
|
11
|
+
* <NodeCanvas root={root} renderNode={(node) => <span>{node.owner}</span>} />
|
|
12
|
+
* ```
|
|
13
|
+
*
|
|
14
|
+
* Written as an intersection rather than an interface with a type parameter
|
|
15
|
+
* because the recursion has to carry `Extra` into `children` — an interface
|
|
16
|
+
* cannot refer to its own instantiation that way without a self-referencing
|
|
17
|
+
* constraint that every consumer then has to spell out.
|
|
18
|
+
*/
|
|
19
|
+
export type CanvasNode<Extra = unknown> = Extra & {
|
|
20
|
+
/** Stable across renders. Node positions, focus and drag offsets are keyed on it. */
|
|
21
|
+
id: string;
|
|
22
|
+
/**
|
|
23
|
+
* The accessible name, the breadcrumb text, and the default body.
|
|
24
|
+
*
|
|
25
|
+
* A plain string, not a `ReactNode`, and that is deliberate: it is read
|
|
26
|
+
* aloud and printed into a trail, and neither of those can do anything with
|
|
27
|
+
* an element tree. Rich content belongs in `renderNode`.
|
|
28
|
+
*/
|
|
29
|
+
label: string;
|
|
30
|
+
children?: readonly CanvasNode<Extra>[];
|
|
31
|
+
/** Along-axis extent for this node only, when it differs from the canvas default. */
|
|
32
|
+
width?: number;
|
|
33
|
+
/** Cross-axis extent for this node only, when it differs from the canvas default. */
|
|
34
|
+
height?: number;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Which way the chart grows.
|
|
38
|
+
*
|
|
39
|
+
* `vertical` puts the root at the top with children below it — the shape most
|
|
40
|
+
* people picture. `horizontal` puts the root at the left with children to the
|
|
41
|
+
* right, which is what deep trees with long labels actually want: label text
|
|
42
|
+
* runs along the level axis in one and across it in the other, so a horizontal
|
|
43
|
+
* chart of the same tree is narrower and reads without truncation.
|
|
44
|
+
*/
|
|
45
|
+
export type CanvasOrientation = "vertical" | "horizontal";
|
|
46
|
+
/** A node with its box resolved, in plane coordinates. `x`/`y` are its TOP-LEFT. */
|
|
47
|
+
export interface PlacedNode<Extra = unknown> {
|
|
48
|
+
id: string;
|
|
49
|
+
node: CanvasNode<Extra>;
|
|
50
|
+
/** 0 for the node the canvas is currently rooted on. */
|
|
51
|
+
depth: number;
|
|
52
|
+
/** Null for the current root. Ids of nodes outside this view never appear. */
|
|
53
|
+
parentId: string | null;
|
|
54
|
+
x: number;
|
|
55
|
+
y: number;
|
|
56
|
+
width: number;
|
|
57
|
+
height: number;
|
|
58
|
+
/** How many children it has, whether or not this view is showing them. */
|
|
59
|
+
childCount: number;
|
|
60
|
+
/**
|
|
61
|
+
* It has children and this view is not drawing them — the node sits on the
|
|
62
|
+
* bottom row of the visible depth. The affordance to descend belongs here.
|
|
63
|
+
*/
|
|
64
|
+
hasHiddenChildren: boolean;
|
|
65
|
+
}
|
|
66
|
+
/** Parent → child, by id. Both ends are always present in `nodes`. */
|
|
67
|
+
export interface CanvasEdge {
|
|
68
|
+
from: string;
|
|
69
|
+
to: string;
|
|
70
|
+
}
|
|
71
|
+
export interface CanvasLayout<Extra = unknown> {
|
|
72
|
+
nodes: PlacedNode<Extra>[];
|
|
73
|
+
edges: CanvasEdge[];
|
|
74
|
+
/** Extent of the laid-out nodes. The plane is this plus padding on each side. */
|
|
75
|
+
width: number;
|
|
76
|
+
height: number;
|
|
77
|
+
}
|
|
78
|
+
export interface LayoutOptions {
|
|
79
|
+
/** Along-axis extent of a node that does not declare its own. */
|
|
80
|
+
nodeWidth?: number;
|
|
81
|
+
/** Cross-axis extent of a node that does not declare its own. */
|
|
82
|
+
nodeHeight?: number;
|
|
83
|
+
/** Clear space between two adjacent nodes on the same level. */
|
|
84
|
+
siblingGap?: number;
|
|
85
|
+
/** Clear space between one level and the next. */
|
|
86
|
+
levelGap?: number;
|
|
87
|
+
orientation?: CanvasOrientation;
|
|
88
|
+
/**
|
|
89
|
+
* How many levels BELOW the root to draw. `1` shows the root and its
|
|
90
|
+
* children; `0` shows the root alone.
|
|
91
|
+
*/
|
|
92
|
+
depth?: number;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* What `renderNode` is told about the node it is drawing.
|
|
96
|
+
*
|
|
97
|
+
* Every field is structural — a fact about the node's place in the tree or in
|
|
98
|
+
* the current interaction. None of them is a fact about what the node is.
|
|
99
|
+
*/
|
|
100
|
+
export interface NodeRenderContext {
|
|
101
|
+
/** 0 for the node the canvas is rooted on. */
|
|
102
|
+
depth: number;
|
|
103
|
+
isRoot: boolean;
|
|
104
|
+
childCount: number;
|
|
105
|
+
hasChildren: boolean;
|
|
106
|
+
/** Children exist and this view stops short of them — clicking descends. */
|
|
107
|
+
hasHiddenChildren: boolean;
|
|
108
|
+
/** This node carries the canvas's single tab stop. */
|
|
109
|
+
isFocused: boolean;
|
|
110
|
+
/** A pointer is carrying this node right now. */
|
|
111
|
+
isDragging: boolean;
|
|
112
|
+
}
|
|
113
|
+
export type NodeRenderer<Extra = unknown> = (node: CanvasNode<Extra>, context: NodeRenderContext) => ReactNode;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import type { Point } from "@/lib/dnd/types";
|
|
2
|
+
/** Plane-local box of a node, as the layout placed it. */
|
|
3
|
+
export interface NodeBox {
|
|
4
|
+
x: number;
|
|
5
|
+
y: number;
|
|
6
|
+
width: number;
|
|
7
|
+
height: number;
|
|
8
|
+
}
|
|
9
|
+
export interface CanvasGestureOptions {
|
|
10
|
+
/** Where a node sits before any drag offset. Null for an id not on screen. */
|
|
11
|
+
layoutBoxOf: (id: string) => NodeBox | null;
|
|
12
|
+
/** Extent of the scrolled plane. Node positions are clamped inside it. */
|
|
13
|
+
planeSize: {
|
|
14
|
+
width: number;
|
|
15
|
+
height: number;
|
|
16
|
+
};
|
|
17
|
+
/** A press that released without activating — the click that descends. */
|
|
18
|
+
onNodeClick: (id: string) => void;
|
|
19
|
+
/** A drag that committed. Offsets stay owned here either way. */
|
|
20
|
+
onNodeDragEnd?: (event: {
|
|
21
|
+
id: string;
|
|
22
|
+
offset: Point;
|
|
23
|
+
}) => void;
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
}
|
|
26
|
+
export interface CanvasGestures {
|
|
27
|
+
/** Drag offsets from the layout position, by node id. */
|
|
28
|
+
offsets: Readonly<Record<string, Point>>;
|
|
29
|
+
/** The node a pointer is currently carrying, or null. */
|
|
30
|
+
draggingId: string | null;
|
|
31
|
+
panning: boolean;
|
|
32
|
+
/** Ref callback for the scroll viewport. Stable — see the note at its use. */
|
|
33
|
+
bindViewport: (node: HTMLDivElement | null) => void;
|
|
34
|
+
/** Ref callback for one node's element. Stable per id. */
|
|
35
|
+
bindNode: (id: string) => (node: HTMLElement | null) => void;
|
|
36
|
+
/** Drop every offset — called when the layout underneath them changes. */
|
|
37
|
+
clearOffsets: () => void;
|
|
38
|
+
}
|
|
39
|
+
export declare function useCanvasGestures(options: CanvasGestureOptions): CanvasGestures;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -101,3 +101,4 @@ export { RBACProvider, useRBAC, AccountMenu, DevToolsPopover, RolePermissionMatr
|
|
|
101
101
|
export { UseCaseCard, RoadmapItemCard, RoadmapSwimlaneBoard, UseCaseLedgerPage, RoadmapPage, PhaseManager, TrackManager, deriveRoadmapItemStatus, isFullyBuilt, isUnbuilt, trackIds, trackProgress, toneForIndex, CATEGORY_TONES, type Domain, type Phase, type Track, type RoadmapItem, type RoadmapItemStatus, type UseCase, type UseCaseStatus, type UseCaseDecision, type UseCaseCardProps, type RoadmapItemCardProps, type RoadmapSwimlaneBoardProps, type UseCaseLedgerPageProps, type RoadmapPageProps, type PhaseManagerProps, type TrackManagerProps, } from "./components/roadmap";
|
|
102
102
|
export { ProvenanceDisclosure, ProvenanceBadge, ConfidenceMeter, provenanceStateLabel, confidenceBand, type ProvenanceRecord, type ProvenanceState, type ProvenanceSource, type ProvenanceCheck, type ProvenanceCall, type ProvenanceSignoff, type ConfidenceBand, type ProvenanceDisclosureProps, type ProvenanceTriggerBadge, type ProvenanceBadgeProps, type ProvenanceBadgeAppearance, type ConfidenceMeterProps, } from "./components/provenance";
|
|
103
103
|
export { createSimStore, resetSimStores, useSimSettings, setSimSettings, getNetworkSpeed, getDataSource, simulateLatency, SimNetworkError, type SimStore, type SimStoreOptions, type SimSettings, type NetworkSpeed, type DataSource, type SimNamespace, } from "./lib/sim";
|
|
104
|
+
export { NodeCanvas, LAYOUT_DEFAULTS, layoutTree, pathToNode, type NodeCanvasProps, type CanvasEdge, type CanvasLayout, type CanvasNode, type CanvasOrientation, type LayoutOptions, type NodeRenderContext, type NodeRenderer, type PlacedNode, } from "./components/node-canvas";
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@danxbot/ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.5.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Danxbot — a domain-agnostic React design system with motion as a first-class primitive.",
|
|
6
6
|
"license": "MIT",
|
|
@@ -78,7 +78,7 @@
|
|
|
78
78
|
"audit:arrows": "node scripts/audit-arrows.mjs",
|
|
79
79
|
"audit:motion": "node scripts/audit-motion.mjs",
|
|
80
80
|
"audit:responsive": "node scripts/audit-responsive.mjs",
|
|
81
|
-
"audit:dnd": "node scripts/audit-dnd.mjs && node scripts/probe-dnd-sensors.mjs && node scripts/probe-dnd-a11y.mjs && node scripts/probe-drag-follow.mjs",
|
|
81
|
+
"audit:dnd": "node scripts/audit-dnd.mjs && node scripts/probe-dnd-sensors.mjs && node scripts/probe-dnd-a11y.mjs && node scripts/probe-drag-follow.mjs && node scripts/probe-drag-overflow.mjs && node scripts/probe-node-canvas.mjs",
|
|
82
82
|
"audit:axtree": "node scripts/audit-axtree.mjs",
|
|
83
83
|
"audit:mutations": "node scripts/audit-mutations.mjs",
|
|
84
84
|
"audit:palette": "node scripts/audit-palette.mjs",
|