@petrarca/sonnet-graph 0.7.0 → 0.9.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.d.ts CHANGED
@@ -1,10 +1,9 @@
1
- import * as zustand from 'zustand';
2
- import { UseBoundStore, StoreApi } from 'zustand';
3
1
  import * as React from 'react';
4
2
  import React__default, { ReactNode } from 'react';
3
+ import * as zustand from 'zustand';
4
+ import { UseBoundStore, StoreApi } from 'zustand';
5
5
  import { GraphEdge, GraphNode } from 'reagraph';
6
6
  import cytoscape from 'cytoscape';
7
- import * as react_jsx_runtime from 'react/jsx-runtime';
8
7
  import { z } from 'zod';
9
8
  import { JsonSchema, UISchema } from '@petrarca/sonnet-core/schema';
10
9
  import { WidgetRegistry } from '@petrarca/sonnet-forms';
@@ -272,6 +271,107 @@ declare function normalizeGraph(nodes: VisualGraphNode[], edges: VisualGraphEdge
272
271
  */
273
272
  declare const EMPTY_NORMALIZED: VisualGraphNormalized;
274
273
 
274
+ /**
275
+ * Extracts graph elements from tabular Cypher query rows.
276
+ *
277
+ * cypher-graphdb (the underlying graph-database library) serializes a
278
+ * node/relationship RETURN-column value wrapped as `{ node: RawGraphNode }` /
279
+ * `{ edge: RawGraphEdge }` (its `serialize_model(with_type=True)` default,
280
+ * shared by every consumer of a cypher-graphdb-backed Cypher endpoint) --
281
+ * scalar columns (a property projection, an aggregate) are unwrapped plain
282
+ * values. A host whose backend returns query results as plain tabular rows
283
+ * (rather than a pre-shaped `{ nodes, edges }` response) uses this to decide
284
+ * whether a result is graph-shaped at all and to collect its elements, deduped
285
+ * by `id_` (the same node/edge commonly repeats across rows).
286
+ */
287
+ interface ExtractedGraphRows {
288
+ nodes: RawGraphNode[];
289
+ edges: RawGraphEdge[];
290
+ /** True if any row cell was a wrapped node/edge -- the result has something to draw. */
291
+ isGraph: boolean;
292
+ }
293
+ /** Scan tabular rows (each an array of RETURN-column cell values) for wrapped node/edge cells. */
294
+ declare function extractGraphFromRows(rows: unknown[][]): ExtractedGraphRows;
295
+
296
+ /**
297
+ * QueryEditor -- a pure, reusable query editor (no store or app dependencies).
298
+ *
299
+ * A props-based editor for graph query languages (Cypher, Datalog, ...): an
300
+ * auto-sizing textarea, Ctrl/Cmd+Enter to execute, an inline error alert with
301
+ * copy-to-clipboard, and an optional custom action-button slot. Every host
302
+ * (an app's own query bar, a graph workbench) drives it purely through props,
303
+ * so it carries none of the caller's state.
304
+ *
305
+ * Promoted into sonnet-graph from the cypher-graphdb explorer, decoupled from
306
+ * that app's clipboard hook (uses sonnet-core's copyTextToClipboard).
307
+ */
308
+
309
+ interface QueryEditorProps {
310
+ /** Current query text value. */
311
+ value: string;
312
+ /** Called when the user executes (Ctrl/Cmd+Enter or the Run button). */
313
+ onExecute: (query: string) => void;
314
+ /** Called when the query text changes. */
315
+ onChange?: (query: string) => void;
316
+ /** Whether execution is in progress. */
317
+ isLoading?: boolean;
318
+ /** Error message to display (null = none). */
319
+ error?: string | null;
320
+ /** Placeholder for the empty editor. */
321
+ placeholder?: string;
322
+ /** Minimum rows (default 1). */
323
+ minRows?: number;
324
+ /** Maximum rows before the textarea scrolls (default 12). */
325
+ maxRows?: number;
326
+ /** Extra class on the wrapper. */
327
+ className?: string;
328
+ /** Custom action buttons (replaces the default Run button). */
329
+ renderActions?: (props: {
330
+ onExecute: () => void;
331
+ isLoading: boolean;
332
+ }) => React__default.ReactNode;
333
+ }
334
+ declare function QueryEditor({ value, onExecute, onChange, isLoading, error, placeholder, minRows, maxRows, className, renderActions, }: QueryEditorProps): React__default.ReactElement;
335
+
336
+ /**
337
+ * createQueryHistoryStore -- a persisted list of recently-run query strings.
338
+ *
339
+ * A reusable Zustand store factory for a graph query editor's history: add()
340
+ * prepends (de-duping repeats), the list is capped, and it persists to
341
+ * localStorage under a caller-chosen key so history survives reloads. Language-
342
+ * and backend-agnostic (it stores plain query text), so any editor -- Cypher,
343
+ * Datalog -- can use it. The consuming app creates one instance and shares it
344
+ * between the query bar (which add()s on run) and the History dropdown.
345
+ */
346
+
347
+ interface QueryHistoryState {
348
+ queries: string[];
349
+ add: (query: string) => void;
350
+ clear: () => void;
351
+ }
352
+ type QueryHistoryStore = UseBoundStore<StoreApi<QueryHistoryState>>;
353
+ /**
354
+ * Build a persisted query-history store.
355
+ *
356
+ * @param persistKey localStorage key (unique per editor, e.g. "graph-query-history").
357
+ * @param limit max entries to retain (default 50).
358
+ */
359
+ declare function createQueryHistoryStore(persistKey: string, limit?: number): QueryHistoryStore;
360
+
361
+ /**
362
+ * QueryHistory -- a dropdown of recently-run queries.
363
+ *
364
+ * Reads a QueryHistoryStore (created by createQueryHistoryStore) and lets the
365
+ * user pick a past query (onSelect) or clear the list. Presentational + store-
366
+ * bound only; the consuming app decides what onSelect does (typically: load the
367
+ * query into the editor). Designed to sit in a QueryEditor's renderActions slot.
368
+ */
369
+
370
+ declare function QueryHistory({ store, onSelect, }: {
371
+ store: QueryHistoryStore;
372
+ onSelect: (query: string) => void;
373
+ }): React__default.ReactElement;
374
+
275
375
  /**
276
376
  * Extract display label from a node or edge using resolved display config.
277
377
  *
@@ -880,23 +980,23 @@ interface GraphVisualizerProps {
880
980
  /** Fetch distinct edge types for a node (for expand options panel). */
881
981
  getNodeEdgeTypes?: (id: number) => Promise<string[]>;
882
982
  }
883
- declare function GraphVisualizer({ onCopyNode, extraToolbarContent, getNodeEdgeTypes, }: GraphVisualizerProps): react_jsx_runtime.JSX.Element;
983
+ declare function GraphVisualizer({ onCopyNode, extraToolbarContent, getNodeEdgeTypes, }: GraphVisualizerProps): React.JSX.Element;
884
984
 
885
985
  interface ActionPanelProps {
886
986
  /** Optional actions rendered at the top of the panel (e.g. CRUD buttons) */
887
987
  actions?: ReactNode;
888
988
  }
889
- declare function ActionPanel({ actions }: ActionPanelProps): react_jsx_runtime.JSX.Element;
989
+ declare function ActionPanel({ actions }: ActionPanelProps): React.JSX.Element;
890
990
 
891
991
  type Props$1 = {
892
992
  node: VisualGraphNode;
893
993
  };
894
- declare function NodeInfoCard({ node }: Props$1): react_jsx_runtime.JSX.Element;
994
+ declare function NodeInfoCard({ node }: Props$1): React.JSX.Element;
895
995
 
896
996
  type Props = {
897
997
  edge: VisualGraphEdge;
898
998
  };
899
- declare function EdgeInfoCard({ edge }: Props): react_jsx_runtime.JSX.Element;
999
+ declare function EdgeInfoCard({ edge }: Props): React.JSX.Element;
900
1000
 
901
1001
  /** A named group of node labels shown as its own legend sub-section. */
902
1002
  interface NodeLabelBucket {
@@ -910,7 +1010,22 @@ interface OverviewProps {
910
1010
  /** Heading for the edge (arrow) section. Default "Relations". */
911
1011
  edgeSectionTitle?: string;
912
1012
  }
913
- declare function Overview({ nodeBuckets, edgeSectionTitle }?: OverviewProps): react_jsx_runtime.JSX.Element | null;
1013
+ declare function Overview({ nodeBuckets, edgeSectionTitle }?: OverviewProps): React.JSX.Element | null;
1014
+
1015
+ /**
1016
+ * CenteredMessage -- a message centered in the pane it fills: empty states,
1017
+ * "cannot display" notices, loading placeholders, and error text. One component
1018
+ * so every graph pane (and host apps' own loading/error states) look the same.
1019
+ */
1020
+
1021
+ declare const TONE: {
1022
+ readonly muted: "text-muted-foreground";
1023
+ readonly destructive: "text-destructive";
1024
+ };
1025
+ declare function CenteredMessage({ children, tone, }: {
1026
+ children: React__default.ReactNode;
1027
+ tone?: keyof typeof TONE;
1028
+ }): React__default.ReactElement;
914
1029
 
915
1030
  interface GraphA11yListProps {
916
1031
  /** Render on-screen instead of visually-hidden (still a11y-present). */
@@ -921,7 +1036,7 @@ interface GraphA11yListProps {
921
1036
  maxHeight?: number;
922
1037
  className?: string;
923
1038
  }
924
- declare function GraphA11yList({ visible, rowHeight, maxHeight, className, }: GraphA11yListProps): react_jsx_runtime.JSX.Element;
1039
+ declare function GraphA11yList({ visible, rowHeight, maxHeight, className, }: GraphA11yListProps): React.JSX.Element;
925
1040
 
926
1041
  /**
927
1042
  * Graph model (metamodel) types.
@@ -1961,4 +2076,526 @@ interface DeleteNodeDialogProps {
1961
2076
  }
1962
2077
  declare function DeleteNodeDialog({ open, onOpenChange, node, port, onDeleted, }: DeleteNodeDialogProps): React__default.ReactElement;
1963
2078
 
1964
- export { ActionPanel, type ActionPanelState, type ActionPanelStore, type CapabilitiesValidation, type Cardinality, type ColorPalette, type CreateEdgeInput, type CreateNodeInput, type CreateNodeWithRelationsInput, type CreateNodeWithRelationsResult, DeleteNodeDialog, type DeleteNodeDialogProps, EMPTY_NORMALIZED, EdgeFormSheet, type EdgeFormSheetProps, EdgeInfoCard, type EdgeTypeMode, type EdgeTypeView, type EdgeVisual, type EditMode$1 as EditMode, type EditableMode, type ExpandOptions, type ExpandResult, GraphA11yList, type GraphA11yListProps, type GraphCapabilities, type GraphCapabilitiesValidation, type GraphDataHook, type GraphDataStore, type GraphDisplayConfig, type EditMode as GraphEditMode, GraphEditToolbar, type GraphEditToolbarProps, type GraphExplorationDeps, type GraphExplorationStore, type GraphFilterStore, type GraphFocusAction, type GraphFocusStore, type GraphModel, type GraphModelCapabilities, type GraphModelDisplay, GraphModelEditor, type GraphModelEditorProps, type GraphModelProperty, type GraphMutationPort, type GraphProperties, type GraphProperty, type GraphRelation, type GraphRenderer, GraphRendererProvider, type GraphSchemaProvider, type GraphStatistics, type WorkspaceStores as GraphStoreBundle, GraphStoresContext, type GraphTypeSchema, GraphVisualizer, type GraphVisualizerProps, type LabelDisplayMap, type LiveGraphDataResult, ModelActionPanel, type ModelActionPanelProps, type ModelGraph, NodeFormSheet, type NodeFormSheetProps, NodeInfoCard, NodeTypeNameSheet, type NodeTypeNameSheetProps, type NodeTypeView, type NodeVisual, type NormalizedGraph, Overview, PropertyFormSheet, type PropertyFormSheetProps, type PropertyInput, type PropertyView, type RawGraphEdge, type RawGraphNode, type RelationCardinality, type RelationDef, type RelationDetailView, RelationFormSheet, type RelationFormSheetProps, type RelationInput, type RelationMap, type RelationView, type ResolvedCapabilities, type ResolvedGraphCapabilities, type SelectionStore, type StoreFactory, TypeDetailPanel, type TypeDetailPanelProps, type UpdateEdgeInput, type UpdateNodeInput, type UpdateNodeWithRelationsInput, type UpdateNodeWithRelationsResult, type VisualGraphEdge, type VisualGraphNode, type VisualGraphNormalized, type WorkspaceStores, type XGraph, addEdgeType, addNodeType, addRelation, buildColorPalette, buildColorPaletteFromNodes, capabilitiesSchema, cardinalityLabel, createActionPanelStore, createGraphDataStore, createGraphExplorationStore, createGraphFilterStore, createGraphFocusStore, createSelectionStore, deleteEdgeType, deleteEdgeTypeProperty, deleteNodeProperty, deleteNodeType, deleteRelation, deleteRelationProperty, edgeTypeView, editableRelations, enrichEdge, enrichEdges, enrichNode, enrichNodes, enrichSchemaWithRelations, extractDisplayLabel, extractRelationFields, findEdgeType, findType, graphCapabilitiesSchema, groupEdgesByRelation, hasProperties, hasRelationFields, initializeFormData, isEdgeType, isNodeType, isRawGraphNode, isRelationField, isVisualEdge, isVisualNode, modelToGraph, nodeTypeView, normalizeGraph, reconcileFilter, relationFieldName, relationTitle, relationTypeFromField, relationView, renameEdgeType, renameNodeType, resolveCapabilities, resolveGraphCapabilities, resolveRelationEdge, setEdgeTypeProperty, setNodeProperty, setRelationProperty, toCytoscapeEdge, toCytoscapeNode, toReagraphEdge, toReagraphNode, typeLabel, updateRelation, useActionPanelStore, useCytoscapeData, useGraphFocus, useGraphRenderer, useLiveGraphData, useReagraphData, useStableRef, useWorkspaceGraphData, useWorkspaceGraphExploration, useWorkspaceGraphFilter, useWorkspaceGraphFocus, useWorkspaceSelection, validateCapabilities, validateGraphCapabilities };
2079
+ /**
2080
+ * GraphFinder -- locate nodes and edges within the currently loaded graph.
2081
+ *
2082
+ * Three modes:
2083
+ * - Full-Text: natural-language, typo-tolerant search (Orama index over all
2084
+ * loaded elements).
2085
+ * - Expression: MistQL pipe expressions over the flattened graph
2086
+ * (e.g. ``Person | filter name == "John"``). Collections available:
2087
+ * nodes/edges/graph (all), vnodes/vedges/vgraph (visible only), and each
2088
+ * label (Person, ACTED_IN, ...).
2089
+ * - Both: expression filters first, then full-text searches that subset.
2090
+ *
2091
+ * Results are click-to-focus, double-click-to-focus-and-select on the canvas.
2092
+ * Renderer-agnostic: uses only the workspace stores and live graph data.
2093
+ */
2094
+
2095
+ declare function GraphFinder(): React__default.ReactElement;
2096
+
2097
+ /**
2098
+ * Graph finder types.
2099
+ *
2100
+ * Type definitions for the client-side graph finder: the Orama full-text
2101
+ * index over the loaded nodes/edges, its documents, results, and options.
2102
+ */
2103
+ /**
2104
+ * Orama document structure for indexing nodes and edges.
2105
+ *
2106
+ * Contains fallback fields (always present) that make any node/edge
2107
+ * searchable without a data-model schema.
2108
+ */
2109
+ interface OramaDocument {
2110
+ /** Unique ID (node or edge ID) */
2111
+ id_: string;
2112
+ /** Type: 'node' or 'edge' */
2113
+ type: "node" | "edge";
2114
+ /** Label (e.g. 'Person', 'ACTED_IN') */
2115
+ label_: string;
2116
+ /** Display name for UI */
2117
+ displayName: string;
2118
+ /** Concatenated text from all properties for full-text search */
2119
+ searchableText: string;
2120
+ /** JSON-stringified properties (fallback field) */
2121
+ properties_json: string;
2122
+ /** Whether this item is currently visible in the graph */
2123
+ isVisible: boolean;
2124
+ /** Start node ID (edges only) */
2125
+ start_id_?: string;
2126
+ /** End node ID (edges only) */
2127
+ end_id_?: string;
2128
+ }
2129
+ /** A finder full-text result with relevance score. */
2130
+ interface OramaSearchResult {
2131
+ /** The matched document */
2132
+ document: OramaDocument;
2133
+ /** Relevance score (higher = more relevant) */
2134
+ score: number;
2135
+ /** Matched terms (for highlighting) */
2136
+ positions?: Record<string, unknown>;
2137
+ }
2138
+ /** Finder index statistics for status display. */
2139
+ interface ServiceStats {
2140
+ totalIndexed: number;
2141
+ nodesIndexed: number;
2142
+ edgesIndexed: number;
2143
+ /** Timestamp of last index build */
2144
+ lastIndexBuild: number | null;
2145
+ /** Whether the index is ready to search */
2146
+ isReady: boolean;
2147
+ }
2148
+ /** Configuration for the finder's Orama search service. */
2149
+ interface OramaSearchServiceConfig {
2150
+ /** Enable debug logging (default: false) */
2151
+ debug?: boolean;
2152
+ /** Maximum nodes to index -- safety limit (default: 100000) */
2153
+ maxNodes?: number;
2154
+ /** Lazy initialization -- only build when needed (default: true) */
2155
+ lazyInit?: boolean;
2156
+ }
2157
+ /** Options for a full-text finder query. */
2158
+ interface SearchOptions {
2159
+ /** Search term (natural language query) */
2160
+ term: string;
2161
+ /** Filter by node/edge labels (optional) */
2162
+ labels?: string[];
2163
+ /** Only search visible items (default: false) */
2164
+ visibleOnly?: boolean;
2165
+ /** Maximum number of results (default: 50) */
2166
+ limit?: number;
2167
+ /** Include edge results (default: true) */
2168
+ includeEdges?: boolean;
2169
+ /** Include node results (default: true) */
2170
+ includeNodes?: boolean;
2171
+ /** Custom field boosting (optional) */
2172
+ boost?: Record<string, number>;
2173
+ }
2174
+ /**
2175
+ * Visibility tracking subset used when building documents.
2176
+ * A subset of the normalized graph shape.
2177
+ */
2178
+ interface NormalizedData {
2179
+ hiddenNodeIds: Set<string>;
2180
+ hiddenEdgeIds: Set<string>;
2181
+ }
2182
+
2183
+ /**
2184
+ * useGraphSearch -- full-text finder over the currently loaded graph.
2185
+ *
2186
+ * Wraps an OramaSearchService whose index is built on demand: not when the
2187
+ * finder opens, only when the user actually runs a full-text search. The
2188
+ * index covers ALL nodes/edges from the last query (``baseNormalized``, the
2189
+ * same source expression mode uses), independent of label filters or focus.
2190
+ * When the underlying data changes the index is marked dirty and rebuilt on
2191
+ * the next search.
2192
+ */
2193
+
2194
+ interface UseGraphSearchReturn {
2195
+ /** Run a full-text search; builds/rebuilds the index on demand. */
2196
+ search: (query: string, options?: Omit<SearchOptions, "term">) => Promise<OramaSearchResult[]>;
2197
+ /** Whether the index is initialized and current. */
2198
+ isReady: boolean;
2199
+ /** Whether the index is being (re)built. */
2200
+ isIndexing: boolean;
2201
+ /** Current index statistics (null before first build). */
2202
+ stats: ServiceStats | null;
2203
+ /** Any initialization/indexing error. */
2204
+ error: Error | null;
2205
+ }
2206
+ declare function useGraphSearch(): UseGraphSearchReturn;
2207
+
2208
+ /**
2209
+ * Orama full-text index for the graph finder.
2210
+ *
2211
+ * Maintains a client-side Orama index over the nodes/edges currently loaded
2212
+ * from a query. Uses a full rebuild when the index becomes dirty (simple and
2213
+ * fast for typical graphs) and lazily initializes only when first searched.
2214
+ */
2215
+
2216
+ declare class OramaSearchService {
2217
+ private db;
2218
+ private config;
2219
+ private isDirty;
2220
+ private isInitialized;
2221
+ private lastIndexBuild;
2222
+ private stats;
2223
+ constructor(config?: OramaSearchServiceConfig);
2224
+ /** Create the empty index with the finder schema (idempotent). */
2225
+ initialize(): Promise<void>;
2226
+ /** Drop all documents (recreates the index; Orama has no bulk delete). */
2227
+ clear(): Promise<void>;
2228
+ /** Mark the index stale so the next search rebuilds it. */
2229
+ markDirty(): void;
2230
+ /** Whether the index needs a (re)build before searching. */
2231
+ needsRebuild(): boolean;
2232
+ /** Rebuild the whole index from the given nodes and edges. */
2233
+ rebuildIndex(nodes: VisualGraphNode[], edges: VisualGraphEdge[], normalized?: NormalizedData): Promise<void>;
2234
+ /** Run a full-text query against the index. */
2235
+ search(options: SearchOptions): Promise<OramaSearchResult[]>;
2236
+ /** Current index statistics. */
2237
+ getStats(): ServiceStats;
2238
+ /** Whether the index is ready to serve searches. */
2239
+ isReady(): boolean;
2240
+ }
2241
+
2242
+ /**
2243
+ * Flatten a normalized graph into a query-friendly shape for the finder's
2244
+ * expression mode (MistQL). Node/edge properties are spread to the top level,
2245
+ * and collections are grouped by label, so queries like
2246
+ * ``Person | filter name == "John"`` or ``graph | filter name == "ABC"`` work.
2247
+ */
2248
+
2249
+ /** A node with its properties spread to the top level. */
2250
+ interface FlattenedNode {
2251
+ id_: number;
2252
+ label_: string;
2253
+ displayName: string;
2254
+ color: string;
2255
+ [key: string]: unknown;
2256
+ }
2257
+ /** An edge with its properties spread to the top level. */
2258
+ interface FlattenedEdge {
2259
+ id_: number;
2260
+ label_: string;
2261
+ start_id_: number;
2262
+ end_id_: number;
2263
+ [key: string]: unknown;
2264
+ }
2265
+ /** Flattened graph with raw, combined, and label-grouped collections. */
2266
+ interface FlattenedGraphData {
2267
+ nodes: FlattenedNode[];
2268
+ edges: FlattenedEdge[];
2269
+ /** All nodes and edges as a single array. */
2270
+ graph: Array<FlattenedNode | FlattenedEdge>;
2271
+ _labels: string[];
2272
+ _edgeLabels: string[];
2273
+ /** Dynamic label groups, e.g. Person / ACTED_IN. */
2274
+ [key: string]: unknown;
2275
+ }
2276
+ /** Flatten normalized graph data. Pure function -- no React hooks. */
2277
+ declare function flattenGraphData(normalized: NormalizedGraph): FlattenedGraphData;
2278
+
2279
+ /**
2280
+ * Tabular result types.
2281
+ *
2282
+ * Transport-agnostic shapes for rendering a query result as a table. A host
2283
+ * app maps its own query response onto {@link TabularResult}; the visualizer
2284
+ * never fetches -- data and paging arrive as props.
2285
+ */
2286
+
2287
+ /** One result row: positional cells, a record, or a bare scalar. */
2288
+ type TabularRow = Record<string, unknown> | unknown[] | unknown;
2289
+ /** How rows are interpreted when deriving columns. */
2290
+ type TabularMode = "record" | "array" | "value";
2291
+ /** Resolved header list plus the row interpretation it implies. */
2292
+ interface TabularHeaders {
2293
+ headers: string[];
2294
+ mode: TabularMode;
2295
+ }
2296
+ /**
2297
+ * Window metadata for a server-paged result. ``total`` is null when the
2298
+ * backend cannot cheaply count (then rely on ``has_more``); ``truncated``
2299
+ * means the result was capped before counting.
2300
+ */
2301
+ interface TabularPageInfo {
2302
+ offset: number;
2303
+ limit: number;
2304
+ returned?: number;
2305
+ total?: number | null;
2306
+ has_more: boolean;
2307
+ truncated?: boolean;
2308
+ }
2309
+ /** A query result to render as a table. */
2310
+ interface TabularResult {
2311
+ /** Result rows (tabular cells in RETURN-column order, or records). */
2312
+ rows: TabularRow[];
2313
+ /** Column-name metadata from the server (RETURN argument -> name). */
2314
+ colNames?: Record<string, string> | null;
2315
+ /** Present when the result is one server-paged window. */
2316
+ page?: TabularPageInfo | null;
2317
+ }
2318
+ /** A graph node/edge found inside a table cell (``{node}``/``{edge}``-wrapped). */
2319
+ type GraphCell = {
2320
+ kind: "node";
2321
+ data: RawGraphNode;
2322
+ } | {
2323
+ kind: "edge";
2324
+ data: RawGraphEdge;
2325
+ };
2326
+
2327
+ /**
2328
+ * PaginationFooter -- "Showing a-b of total" plus page-size and prev/next
2329
+ * controls for a server-paged tabular result. Renders nothing when unpaged.
2330
+ */
2331
+
2332
+ interface PaginationControls {
2333
+ pageIndex: number;
2334
+ pageSize?: number;
2335
+ pageSizeOptions?: readonly number[];
2336
+ onPageChange?: (index: number) => void;
2337
+ onPageSizeChange?: (size: number) => void;
2338
+ }
2339
+
2340
+ /**
2341
+ * TabularVisualizer -- render a query result as a table.
2342
+ *
2343
+ * Pure and transport-agnostic: the host passes the result (and, for server
2344
+ * paging, the page state + callbacks); nothing is fetched here. Graph node/edge
2345
+ * cells render as label-colored chips that open an inspector sheet; other
2346
+ * values render as syntax-highlighted JSON. Offers sort (disabled while
2347
+ * server-paged, since it would only reorder the current page), column resize,
2348
+ * row virtualization, CSV/TSV/JSON export and copy, and a pagination footer.
2349
+ */
2350
+
2351
+ interface TabularVisualizerProps extends Partial<PaginationControls> {
2352
+ /** The result to render; undefined = nothing run yet. */
2353
+ result?: TabularResult;
2354
+ /** Optional schema display config for node/edge captions. */
2355
+ labelDisplayMap?: LabelDisplayMap;
2356
+ /** Base file name for exports (default "query-result"). */
2357
+ exportFileName?: string;
2358
+ }
2359
+ declare function TabularVisualizer({ result, labelDisplayMap, exportFileName, pageIndex, ...controls }: TabularVisualizerProps): React__default.ReactElement;
2360
+
2361
+ /**
2362
+ * Graph | Table result view switch.
2363
+ *
2364
+ * useResultView carries cypher-graphdb's ViewContext intent without its URL
2365
+ * coupling. The rule, per result:
2366
+ *
2367
+ * keep the current view if it can display the result; otherwise switch to a
2368
+ * view that can.
2369
+ *
2370
+ * In practice the only automatic switch is Graph -> Table when a graph result
2371
+ * is replaced by a scalar/aggregate (which Graph cannot draw). A graph or empty
2372
+ * result never forces a switch (both views can show it), so the operator's
2373
+ * choice -- including a manual one -- is preserved. The first result (no view
2374
+ * chosen yet) opens in its natural view, or in ``initialView`` if given.
2375
+ *
2376
+ * Routing/URL sync stays in the host app (ResultWorkspace's view/onViewChange).
2377
+ */
2378
+ type ResultView = "graph" | "table";
2379
+ /** Result shape: a graph (nodes/edges), tabular rows (scalars/aggregates), or empty. */
2380
+ type ResultKind = "graph" | "tabular" | "empty";
2381
+ /** Classify a result from whether it holds graph elements and how many rows it has. */
2382
+ declare function classifyResult(isGraph: boolean, rowCount: number): ResultKind;
2383
+ /**
2384
+ * Whether a view can display a result kind. Graph can show graph + empty (an
2385
+ * empty canvas) but not tabular rows; Table can show anything.
2386
+ */
2387
+ declare function isViewValid(view: ResultView, kind: ResultKind): boolean;
2388
+ /** The view a fresh result opens in: graph for a graph result, table otherwise. */
2389
+ declare function naturalView(kind: ResultKind): ResultView;
2390
+ interface ResultViewOptions {
2391
+ /** View to open the FIRST result in (e.g. read from the URL). Honored once. */
2392
+ initialView?: ResultView;
2393
+ }
2394
+ /**
2395
+ * Active result view for the current result (identified by ``resultKey``).
2396
+ * Adjusts during render, not in an effect, so a view that would be invalid for
2397
+ * a new result never paints before correcting.
2398
+ */
2399
+ declare function useResultView(kind: ResultKind, resultKey: unknown, { initialView }?: ResultViewOptions): [ResultView, (view: ResultView) => void];
2400
+
2401
+ /** Graph | Table result view switch (controlled). See resultView.ts for the view state. */
2402
+
2403
+ declare function ResultViewTabs({ value, onChange, }: {
2404
+ value: ResultView;
2405
+ onChange: (view: ResultView) => void;
2406
+ }): React__default.ReactElement;
2407
+
2408
+ /**
2409
+ * GraphInspector -- right-side sheet inspecting a node/edge from a table cell:
2410
+ * header (color, label, id, caption), copy actions, then Properties and JSON tabs.
2411
+ */
2412
+
2413
+ interface GraphInspectorProps {
2414
+ cell: GraphCell | null;
2415
+ open: boolean;
2416
+ onOpenChange: (open: boolean) => void;
2417
+ palette?: ColorPalette;
2418
+ labelDisplayMap?: LabelDisplayMap;
2419
+ }
2420
+ declare function GraphInspector({ cell, open, onOpenChange, palette, labelDisplayMap, }: GraphInspectorProps): React__default.ReactElement;
2421
+
2422
+ /**
2423
+ * GraphChip -- compact single-line chip for a node/edge in a table cell:
2424
+ * label-colored dot (node) or arrow (edge), label, caption, "+N" properties.
2425
+ * Activating it opens the inspector.
2426
+ */
2427
+
2428
+ declare function GraphChipImpl({ cell }: {
2429
+ cell: GraphCell;
2430
+ }): React__default.ReactElement;
2431
+ declare const GraphChip: React__default.MemoExoticComponent<typeof GraphChipImpl>;
2432
+
2433
+ /**
2434
+ * Table cell renderers: graph node/edge values become a GraphChip, everything
2435
+ * else renders as syntax-highlighted JSON (colors from the --json-* tokens).
2436
+ */
2437
+
2438
+ /** Syntax-highlighted rendering of any JSON value. */
2439
+ declare function JsonRenderer({ value, className, }: {
2440
+ value: unknown;
2441
+ className?: string;
2442
+ }): React__default.ReactElement;
2443
+ /**
2444
+ * One table cell. Memoized on ``value`` so the recursive JSON formatting is
2445
+ * not recomputed on sort/resize/scroll re-renders (cell values are stable).
2446
+ */
2447
+ declare function JsonCellImpl({ value }: {
2448
+ value: unknown;
2449
+ }): React__default.ReactElement;
2450
+ declare const JsonCell: React__default.MemoExoticComponent<typeof JsonCellImpl>;
2451
+
2452
+ /**
2453
+ * Helpers for graph node/edge values inside table cells.
2454
+ *
2455
+ * A tabular cell holding a graph object is wrapped as ``{ node: {...} }`` or
2456
+ * ``{ edge: {...} }`` (the cypher-graphdb serialization convention also used by
2457
+ * extractGraphFromRows). These helpers detect that shape and derive a caption
2458
+ * and label color, reusing the graph view's enrichment so they match.
2459
+ */
2460
+
2461
+ /** Detect a graph node/edge wrapped in a cell; null for scalars, maps, arrays. */
2462
+ declare function asGraphCell(value: unknown): GraphCell | null;
2463
+ /** Caption: schema display config first, then a property heuristic, then ``Label #id``. */
2464
+ declare function captionFor(cell: GraphCell, labelDisplayMap?: LabelDisplayMap): string;
2465
+ /** Number of properties (drives the ``+N`` indicator). */
2466
+ declare function propertyCount(cell: GraphCell): number;
2467
+ /** Label color from the palette, falling back to neutral. */
2468
+ declare function colorForLabel(label: string, palette?: ColorPalette): string;
2469
+
2470
+ /**
2471
+ * Column derivation for tabular results.
2472
+ */
2473
+
2474
+ /**
2475
+ * Resolve display column names from the server's col_names metadata.
2476
+ *
2477
+ * Wildcard columns (all-numeric keys) use the VALUES (resolved labels, e.g.
2478
+ * "Product"); explicit columns use the KEYS (aliases/expressions, e.g.
2479
+ * "p.name"). Missing columns are padded as ``column_N``.
2480
+ */
2481
+ declare function resolveColumnNames(colNames: Record<string, string> | null | undefined, columnCount: number): string[];
2482
+ /**
2483
+ * Derive the header list and row interpretation from the rows.
2484
+ * Records win over arrays (union of keys, sorted); arrays use col_names;
2485
+ * otherwise a single ``value`` column.
2486
+ */
2487
+ declare function deriveHeaders(rows: TabularRow[], colNames?: Record<string, string> | null): TabularHeaders;
2488
+ /** Extract one cell value from a row by header/index under a mode. */
2489
+ declare function getCellValue(row: TabularRow, header: string, index: number, mode: TabularMode): unknown;
2490
+
2491
+ /**
2492
+ * Export helpers for tabular results: CSV / TSV / JSON strings and a browser
2493
+ * download trigger.
2494
+ */
2495
+
2496
+ /** CSV (comma-separated, RFC 4180). */
2497
+ declare function toCsv(rows: TabularRow[], headers: string[], mode: TabularMode): string;
2498
+ /** TSV (tab-separated; avoids the CSV locale/separator ambiguity in Excel). */
2499
+ declare function toTsv(rows: TabularRow[], headers: string[], mode: TabularMode): string;
2500
+ /** Pretty JSON array of objects keyed by header, whatever the row shape. */
2501
+ declare function toJson(rows: TabularRow[], headers: string[], mode: TabularMode): string;
2502
+ /**
2503
+ * Whether CSV/TSV is meaningful: true when at least one sampled cell is flat
2504
+ * (scalar). If every sampled cell is an object/array, flat formats would only
2505
+ * produce stringified JSON blobs.
2506
+ */
2507
+ declare function isFlatExportSuitable(rows: TabularRow[], headers: string[], mode: TabularMode): boolean;
2508
+ /** Trigger a browser download of in-memory content. */
2509
+ declare function downloadFile(content: string, filename: string, mimeType: string): void;
2510
+
2511
+ /**
2512
+ * Pane selection for the result workspace (cypher-graphdb's Workspace rules).
2513
+ *
2514
+ * The kind vocabulary and view validity live in tabular/resultView (the single
2515
+ * source of truth the view-switch logic uses); this adds which concrete pane to
2516
+ * render for a given view + result:
2517
+ * - graph: a graph result in the graph view (nodes/edges, or an empty canvas);
2518
+ * - table: a result shown as a table;
2519
+ * - graph-unavailable: a tabular result while in the graph view (cannot draw);
2520
+ * - table-empty: an empty result in the table view ("no results").
2521
+ */
2522
+
2523
+ type PaneChoice = "graph" | "table" | "graph-unavailable" | "table-empty";
2524
+ declare function choosePane(view: ResultView, kind: ResultKind): PaneChoice;
2525
+
2526
+ /**
2527
+ * ResultWorkspace -- the result area under a query bar: the Graph | Table
2528
+ * switch plus the pane for the active view.
2529
+ *
2530
+ * Owns the layout and the pane rules so every app renders results the same
2531
+ * way; the host supplies the two panes (the graph pane and the table) and
2532
+ * describes the result (kind + a key that changes on each execution). Each new
2533
+ * result opens in its natural view; the operator's own switch sticks until the
2534
+ * next result.
2535
+ *
2536
+ * The view is managed here by default. A host that keeps it elsewhere (e.g. in
2537
+ * the URL, with back/forward) passes ``view`` + ``onViewChange`` to control it,
2538
+ * or just ``initialView`` to choose the first result's view.
2539
+ */
2540
+
2541
+ interface ResultWorkspaceProps {
2542
+ kind: ResultKind;
2543
+ /** Changes on every execution (also re-runs of the same query). */
2544
+ resultKey: unknown;
2545
+ /** The graph pane, e.g. a GraphPane. */
2546
+ graphPane: React__default.ReactNode;
2547
+ /** The table pane, e.g. a TabularVisualizer wired to the host's data. */
2548
+ tablePane: React__default.ReactNode;
2549
+ /** Controlled view. When set, the host owns the view and must update it. */
2550
+ view?: ResultView;
2551
+ /**
2552
+ * Called when the operator switches view (controlled or not). Tabs report on
2553
+ * both pointer-down and focus, so one click can call this twice with the same
2554
+ * value before the host re-renders -- keep it idempotent (e.g. navigate only
2555
+ * if the path actually differs).
2556
+ */
2557
+ onViewChange?: (view: ResultView) => void;
2558
+ /** View for the first result (uncontrolled), e.g. read from the URL. */
2559
+ initialView?: ResultView;
2560
+ }
2561
+ declare function ResultWorkspace({ kind, resultKey, graphPane, tablePane, view: controlledView, onViewChange, initialView, }: ResultWorkspaceProps): React__default.ReactElement;
2562
+
2563
+ /**
2564
+ * GraphPane -- the graph result pane: accessible element list, the renderer
2565
+ * canvas, and a resizable action (details/overview) panel.
2566
+ *
2567
+ * The generic part of cypher-graphdb's GraphViewer. App-specific behavior comes
2568
+ * in through props -- action buttons, extra toolbar content, copy handling,
2569
+ * edge-type lookup, a banner, and renderer persistence -- never through app
2570
+ * stores. The host provides the graph stores (GraphStoresContext).
2571
+ */
2572
+
2573
+ interface GraphPaneProps extends GraphVisualizerProps {
2574
+ /** False while the graph data is still being prepared (shows the placeholder). */
2575
+ ready?: boolean;
2576
+ /** Placeholder text while not ready. */
2577
+ loadingLabel?: string;
2578
+ /** Overlay over the canvas, e.g. a LargeResultBanner. */
2579
+ banner?: React__default.ReactNode;
2580
+ /** Actions at the top of the action panel (e.g. CRUD buttons). */
2581
+ actions?: React__default.ReactNode;
2582
+ /** Initial renderer (default cytoscape). */
2583
+ defaultRenderer?: GraphRenderer;
2584
+ /** Called when the operator switches renderer (e.g. to persist it in the URL). */
2585
+ onRendererChange?: (renderer: GraphRenderer) => void;
2586
+ }
2587
+ declare function GraphPane({ ready, loadingLabel, banner, actions, defaultRenderer, onRendererChange, ...visualizerProps }: GraphPaneProps): React__default.ReactElement;
2588
+
2589
+ /**
2590
+ * LargeResultBanner -- persistent, non-blocking notice over the graph canvas
2591
+ * when the server bounded the query to the node budget: how many of the total
2592
+ * results are shown, and a nudge to refine. Renders nothing unless the result
2593
+ * was windowed and more rows exist.
2594
+ */
2595
+
2596
+ declare function LargeResultBanner({ page, }: {
2597
+ page?: TabularPageInfo | null;
2598
+ }): React__default.ReactElement | null;
2599
+
2600
+ export { ActionPanel, CenteredMessage, DeleteNodeDialog, EMPTY_NORMALIZED, EdgeFormSheet, EdgeInfoCard, GraphA11yList, GraphChip, GraphEditToolbar, GraphFinder, GraphInspector, GraphModelEditor, GraphPane, GraphRendererProvider, GraphStoresContext, GraphVisualizer, JsonCell, JsonRenderer, LargeResultBanner, ModelActionPanel, NodeFormSheet, NodeInfoCard, NodeTypeNameSheet, OramaSearchService, Overview, PropertyFormSheet, QueryEditor, QueryHistory, RelationFormSheet, ResultViewTabs, ResultWorkspace, TabularVisualizer, TypeDetailPanel, addEdgeType, addNodeType, addRelation, asGraphCell, buildColorPalette, buildColorPaletteFromNodes, capabilitiesSchema, captionFor, cardinalityLabel, choosePane, classifyResult, colorForLabel, createActionPanelStore, createGraphDataStore, createGraphExplorationStore, createGraphFilterStore, createGraphFocusStore, createQueryHistoryStore, createSelectionStore, deleteEdgeType, deleteEdgeTypeProperty, deleteNodeProperty, deleteNodeType, deleteRelation, deleteRelationProperty, deriveHeaders, downloadFile, edgeTypeView, editableRelations, enrichEdge, enrichEdges, enrichNode, enrichNodes, enrichSchemaWithRelations, extractDisplayLabel, extractGraphFromRows, extractRelationFields, findEdgeType, findType, flattenGraphData, getCellValue, graphCapabilitiesSchema, groupEdgesByRelation, hasProperties, hasRelationFields, initializeFormData, isEdgeType, isFlatExportSuitable, isNodeType, isRawGraphNode, isRelationField, isViewValid, isVisualEdge, isVisualNode, modelToGraph, naturalView, nodeTypeView, normalizeGraph, propertyCount, reconcileFilter, relationFieldName, relationTitle, relationTypeFromField, relationView, renameEdgeType, renameNodeType, resolveCapabilities, resolveColumnNames, resolveGraphCapabilities, resolveRelationEdge, setEdgeTypeProperty, setNodeProperty, setRelationProperty, toCsv, toCytoscapeEdge, toCytoscapeNode, toJson, toReagraphEdge, toReagraphNode, toTsv, typeLabel, updateRelation, useActionPanelStore, useCytoscapeData, useGraphFocus, useGraphRenderer, useGraphSearch, useLiveGraphData, useReagraphData, useResultView, useStableRef, useWorkspaceGraphData, useWorkspaceGraphExploration, useWorkspaceGraphFilter, useWorkspaceGraphFocus, useWorkspaceSelection, validateCapabilities, validateGraphCapabilities };
2601
+ export type { ActionPanelState, ActionPanelStore, CapabilitiesValidation, Cardinality, ColorPalette, CreateEdgeInput, CreateNodeInput, CreateNodeWithRelationsInput, CreateNodeWithRelationsResult, DeleteNodeDialogProps, EdgeFormSheetProps, EdgeTypeMode, EdgeTypeView, EdgeVisual, EditMode$1 as EditMode, EditableMode, ExpandOptions, ExpandResult, ExtractedGraphRows, FlattenedEdge, FlattenedGraphData, FlattenedNode, GraphA11yListProps, GraphCapabilities, GraphCapabilitiesValidation, GraphCell, GraphDataHook, GraphDataStore, GraphDisplayConfig, EditMode as GraphEditMode, GraphEditToolbarProps, GraphExplorationDeps, GraphExplorationStore, GraphFilterStore, GraphFocusAction, GraphFocusStore, GraphModel, GraphModelCapabilities, GraphModelDisplay, GraphModelEditorProps, GraphModelProperty, GraphMutationPort, GraphPaneProps, GraphProperties, GraphProperty, GraphRelation, GraphRenderer, GraphSchemaProvider, GraphStatistics, WorkspaceStores as GraphStoreBundle, GraphTypeSchema, GraphVisualizerProps, LabelDisplayMap, LiveGraphDataResult, ModelActionPanelProps, ModelGraph, NodeFormSheetProps, NodeTypeNameSheetProps, NodeTypeView, NodeVisual, NormalizedData, NormalizedGraph, OramaDocument, OramaSearchResult, OramaSearchServiceConfig, PaneChoice, PropertyFormSheetProps, PropertyInput, PropertyView, QueryEditorProps, QueryHistoryState, QueryHistoryStore, RawGraphEdge, RawGraphNode, RelationCardinality, RelationDef, RelationDetailView, RelationFormSheetProps, RelationInput, RelationMap, RelationView, ResolvedCapabilities, ResolvedGraphCapabilities, ResultKind, ResultView, ResultWorkspaceProps, SearchOptions, SelectionStore, ServiceStats, StoreFactory, TabularHeaders, TabularMode, TabularPageInfo, TabularResult, TabularRow, TabularVisualizerProps, TypeDetailPanelProps, UpdateEdgeInput, UpdateNodeInput, UpdateNodeWithRelationsInput, UpdateNodeWithRelationsResult, UseGraphSearchReturn, VisualGraphEdge, VisualGraphNode, VisualGraphNormalized, WorkspaceStores, XGraph };