@bendyline/squisq-react 2.12.7 → 2.12.9
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/graph/index.d.ts +223 -0
- package/dist/graph/index.js +1074 -0
- package/dist/squisq-player.full.global.js +446 -447
- package/dist/squisq-player.global.js +78 -79
- package/dist/standalone-player-full.js +1 -1
- package/dist/standalone-source.js +1 -1
- package/package.json +7 -2
|
@@ -0,0 +1,223 @@
|
|
|
1
|
+
import * as react from 'react';
|
|
2
|
+
import { CSSProperties } from 'react';
|
|
3
|
+
import { LayoutResult, GraphLayoutEngine, LayoutGraph, LayoutOptions } from '@bendyline/squisq-graph';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* A named color role. Hosts map each to their palette through
|
|
7
|
+
* `--squisq-graph-tone-<tone>`; `neutral` is the plain node.
|
|
8
|
+
*/
|
|
9
|
+
type GraphTone = 'neutral' | 'accent' | 'positive' | 'notice' | 'warning' | 'danger' | 'muted';
|
|
10
|
+
/** How one laid-out node is drawn. Matched to `LayoutResult.nodes` by id. */
|
|
11
|
+
interface GraphViewNode {
|
|
12
|
+
id: string;
|
|
13
|
+
label: string;
|
|
14
|
+
/** A smaller second line (a folder, a count). Size the node with `graphNodeSize` to fit it. */
|
|
15
|
+
detail?: string;
|
|
16
|
+
/** A short chip at the right edge, such as a count of findings. */
|
|
17
|
+
badge?: string;
|
|
18
|
+
tone?: GraphTone;
|
|
19
|
+
/** An explicit fill, for color lenses; wins over the tone's. */
|
|
20
|
+
fill?: string;
|
|
21
|
+
/** Show a toggle: a collapsed group that can open, or an open container that can close. */
|
|
22
|
+
expandable?: boolean;
|
|
23
|
+
expanded?: boolean;
|
|
24
|
+
/** Tooltip; defaults to the label. */
|
|
25
|
+
title?: string;
|
|
26
|
+
className?: string;
|
|
27
|
+
}
|
|
28
|
+
/** How one routed edge is drawn. Matched to `LayoutResult.edges` by id. */
|
|
29
|
+
interface GraphViewEdge {
|
|
30
|
+
id: string;
|
|
31
|
+
/** Line weight; width grows with its logarithm. Default 1. */
|
|
32
|
+
weight?: number;
|
|
33
|
+
dashed?: boolean;
|
|
34
|
+
/** Arrowheads at both ends. */
|
|
35
|
+
bidirectional?: boolean;
|
|
36
|
+
tone?: GraphTone;
|
|
37
|
+
/** Tooltip. */
|
|
38
|
+
title?: string;
|
|
39
|
+
className?: string;
|
|
40
|
+
}
|
|
41
|
+
interface DiagramViewerProps {
|
|
42
|
+
/** Positions and routes from `@bendyline/squisq-graph`. */
|
|
43
|
+
layout: LayoutResult;
|
|
44
|
+
/** Presentation per node id; a node without one shows its id. */
|
|
45
|
+
nodes?: readonly GraphViewNode[];
|
|
46
|
+
edges?: readonly GraphViewEdge[];
|
|
47
|
+
/** Controlled selection (node ids). */
|
|
48
|
+
selectedIds?: readonly string[];
|
|
49
|
+
onSelectionChange?: (ids: string[]) => void;
|
|
50
|
+
/** Double-click or Enter on a node. */
|
|
51
|
+
onNodeActivate?: (id: string) => void;
|
|
52
|
+
/** A toggle was clicked, or Space pressed on an expandable node; `expanded` is the state asked for. */
|
|
53
|
+
onContainerToggle?: (id: string, expanded: boolean) => void;
|
|
54
|
+
onEdgeClick?: (id: string) => void;
|
|
55
|
+
onHoverChange?: (id: string | null) => void;
|
|
56
|
+
/** Keep these nodes (and the edges between them) bright and dim the rest, e.g. search hits. */
|
|
57
|
+
highlightIds?: readonly string[];
|
|
58
|
+
/** Hovering a node dims everything but it, its neighbors and its edges. Default true. */
|
|
59
|
+
hoverNeighbors?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* What the mouse wheel does: zoom (default), or scroll the page unless
|
|
62
|
+
* Ctrl/⌘ is held — for a diagram embedded in a scrolling document.
|
|
63
|
+
*/
|
|
64
|
+
wheel?: 'zoom' | 'scroll-unless-modifier';
|
|
65
|
+
/** Corner radius of edge bends. Default 6. */
|
|
66
|
+
cornerRadius?: number;
|
|
67
|
+
/** Screen padding when fitting, and the largest scale a fit may reach. Defaults 24 and 1.5. */
|
|
68
|
+
fitPadding?: number;
|
|
69
|
+
maxFitScale?: number;
|
|
70
|
+
/** Show the zoom and fit buttons. Default true. */
|
|
71
|
+
controls?: boolean;
|
|
72
|
+
/** Name of the diagram for assistive technology. */
|
|
73
|
+
ariaLabel: string;
|
|
74
|
+
/** What to announce when a node is selected; defaults to its label. */
|
|
75
|
+
describeNode?: (id: string) => string;
|
|
76
|
+
/** Size to assume before the element is measured (tests, server rendering). */
|
|
77
|
+
initialSize?: {
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
};
|
|
81
|
+
className?: string;
|
|
82
|
+
style?: CSSProperties;
|
|
83
|
+
}
|
|
84
|
+
interface DiagramViewerHandle {
|
|
85
|
+
/** Fit the whole drawing. */
|
|
86
|
+
fit(): void;
|
|
87
|
+
/** Fit these nodes. */
|
|
88
|
+
focus(ids: readonly string[]): void;
|
|
89
|
+
/** Pan just enough to show this node, keeping the zoom. */
|
|
90
|
+
reveal(id: string): void;
|
|
91
|
+
/**
|
|
92
|
+
* Hold this node at its screen position through the next layout, when one
|
|
93
|
+
* arrives within a few seconds. The viewer does this itself when a toggle
|
|
94
|
+
* opens or closes a node; call it before changing the graph some other way.
|
|
95
|
+
*/
|
|
96
|
+
keepInPlace(id: string): void;
|
|
97
|
+
zoomBy(factor: number): void;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
declare const DiagramViewer: react.ForwardRefExoticComponent<DiagramViewerProps & react.RefAttributes<DiagramViewerHandle>>;
|
|
101
|
+
|
|
102
|
+
/** Above this many nodes, `DiagramViewer` draws only what is near the screen. */
|
|
103
|
+
declare const GRAPH_VIEW_CULL_AT = 600;
|
|
104
|
+
|
|
105
|
+
/**
|
|
106
|
+
* useGraphLayout — lay a graph out for `DiagramViewer`, off the render path.
|
|
107
|
+
*
|
|
108
|
+
* Results are cached by `graphSignature`, so returning to a graph seen
|
|
109
|
+
* recently is instant. A layout superseded before it finishes is aborted;
|
|
110
|
+
* with a worker engine that ends the worker's work too. While a new layout
|
|
111
|
+
* is computing the previous one stays in place, and `slow` turns on only
|
|
112
|
+
* when the wait is long enough to be worth showing.
|
|
113
|
+
*/
|
|
114
|
+
|
|
115
|
+
/** Forget every cached layout (tests, or after the engine version changes). */
|
|
116
|
+
declare function clearGraphLayoutCache(): void;
|
|
117
|
+
interface UseGraphLayoutOptions {
|
|
118
|
+
/** Where layouts run; default the calling thread. Pass `createWorkerLayoutEngine()` for large graphs. */
|
|
119
|
+
engine?: GraphLayoutEngine;
|
|
120
|
+
/** How long a layout may take before `slow` turns on. Default 150 ms. */
|
|
121
|
+
slowAfterMs?: number;
|
|
122
|
+
}
|
|
123
|
+
interface GraphLayoutState {
|
|
124
|
+
/** The layout for the current graph, or the previous one while it computes; null before the first. */
|
|
125
|
+
layout: LayoutResult | null;
|
|
126
|
+
/** True while the current graph's layout is still computing. */
|
|
127
|
+
pending: boolean;
|
|
128
|
+
/** True once a pending layout has taken longer than `slowAfterMs`. */
|
|
129
|
+
slow: boolean;
|
|
130
|
+
error: Error | null;
|
|
131
|
+
signature: string | null;
|
|
132
|
+
}
|
|
133
|
+
declare function useGraphLayout(graph: LayoutGraph | null, options?: LayoutOptions, config?: UseGraphLayoutOptions): GraphLayoutState;
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Text measurement without the DOM. A layout is computed before anything is
|
|
137
|
+
* drawn, often in a worker, so node sizes come from a character-width table
|
|
138
|
+
* for a typical UI sans-serif. The viewer truncates labels with the same
|
|
139
|
+
* table, which is what keeps a label inside the box it was sized for.
|
|
140
|
+
*/
|
|
141
|
+
/** Approximate rendered width of `text` at `fontSize`, in the same units. */
|
|
142
|
+
declare function estimateTextWidth(text: string, fontSize?: number): number;
|
|
143
|
+
/** `text` cut with an ellipsis so it fits `maxWidth`; unchanged when it already fits. */
|
|
144
|
+
declare function truncateToWidth(text: string, maxWidth: number, fontSize?: number): string;
|
|
145
|
+
/** The type sizes and insets the viewer draws nodes with. */
|
|
146
|
+
declare const GRAPH_NODE_METRICS: {
|
|
147
|
+
readonly labelSize: 12;
|
|
148
|
+
readonly detailSize: 10;
|
|
149
|
+
readonly badgeSize: 10;
|
|
150
|
+
readonly paddingX: 10;
|
|
151
|
+
/** Height of a node with a label only, and with a label plus a detail line. */
|
|
152
|
+
readonly height: 28;
|
|
153
|
+
readonly heightWithDetail: 40;
|
|
154
|
+
/** Width of a badge per character beyond its padding, and the room for a toggle chevron. */
|
|
155
|
+
readonly badgePadding: 10;
|
|
156
|
+
readonly toggleWidth: 16;
|
|
157
|
+
};
|
|
158
|
+
interface GraphNodeSizeInput {
|
|
159
|
+
label: string;
|
|
160
|
+
detail?: string;
|
|
161
|
+
badge?: string;
|
|
162
|
+
expandable?: boolean;
|
|
163
|
+
}
|
|
164
|
+
interface GraphNodeSizeOptions {
|
|
165
|
+
minWidth?: number;
|
|
166
|
+
maxWidth?: number;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* The box a node needs for its label, detail, badge and toggle, clamped to
|
|
170
|
+
* `minWidth`–`maxWidth` (default 64–280). Feed the result to the layout as
|
|
171
|
+
* the node's size; the viewer truncates whatever the clamp cut off.
|
|
172
|
+
*/
|
|
173
|
+
declare function graphNodeSize(node: GraphNodeSizeInput, options?: GraphNodeSizeOptions): {
|
|
174
|
+
width: number;
|
|
175
|
+
height: number;
|
|
176
|
+
};
|
|
177
|
+
|
|
178
|
+
/**
|
|
179
|
+
* Pan and zoom as plain math: a transform `{ tx, ty, scale }` maps drawing
|
|
180
|
+
* units to screen pixels (`screen = drawing * scale + t`). Pure, so the
|
|
181
|
+
* viewer and its tests share one definition of fitting and zooming.
|
|
182
|
+
*/
|
|
183
|
+
interface ViewTransform {
|
|
184
|
+
tx: number;
|
|
185
|
+
ty: number;
|
|
186
|
+
scale: number;
|
|
187
|
+
}
|
|
188
|
+
interface Size {
|
|
189
|
+
width: number;
|
|
190
|
+
height: number;
|
|
191
|
+
}
|
|
192
|
+
/** Zoom by `factor`, keeping the drawing point under screen point (`fx`, `fy`) still. */
|
|
193
|
+
declare function zoomAt(t: ViewTransform, factor: number, fx: number, fy: number): ViewTransform;
|
|
194
|
+
/** The transform that centers `box` in `size`, as large as fits within `maxScale`. */
|
|
195
|
+
declare function fitTransform(box: {
|
|
196
|
+
x: number;
|
|
197
|
+
y: number;
|
|
198
|
+
width: number;
|
|
199
|
+
height: number;
|
|
200
|
+
}, size: Size, padding?: number, maxScale?: number): ViewTransform;
|
|
201
|
+
/** The part of the drawing the screen shows. */
|
|
202
|
+
declare function visibleRect(t: ViewTransform, size: Size): {
|
|
203
|
+
x0: number;
|
|
204
|
+
y0: number;
|
|
205
|
+
x1: number;
|
|
206
|
+
y1: number;
|
|
207
|
+
};
|
|
208
|
+
/** Pan the least distance that brings `box` fully into view (with `margin`), keeping the scale. */
|
|
209
|
+
declare function revealTransform(t: ViewTransform, box: {
|
|
210
|
+
x: number;
|
|
211
|
+
y: number;
|
|
212
|
+
width: number;
|
|
213
|
+
height: number;
|
|
214
|
+
}, size: Size, margin?: number): ViewTransform;
|
|
215
|
+
|
|
216
|
+
/**
|
|
217
|
+
* The viewer's stylesheet, rendered with each viewer so it needs no CSS
|
|
218
|
+
* import. Every color is a custom property with a light fallback; a host
|
|
219
|
+
* themes the viewer by setting them on an ancestor.
|
|
220
|
+
*/
|
|
221
|
+
declare const GRAPH_TONE_NAMES: readonly ["neutral", ...string[]];
|
|
222
|
+
|
|
223
|
+
export { DiagramViewer, type DiagramViewerHandle, type DiagramViewerProps, GRAPH_NODE_METRICS, GRAPH_TONE_NAMES, GRAPH_VIEW_CULL_AT, type GraphLayoutState, type GraphNodeSizeInput, type GraphNodeSizeOptions, type GraphTone, type GraphViewEdge, type GraphViewNode, type UseGraphLayoutOptions, type ViewTransform, clearGraphLayoutCache, estimateTextWidth, fitTransform, graphNodeSize, revealTransform, truncateToWidth, useGraphLayout, visibleRect, zoomAt };
|