@petrarca/sonnet-graph 0.6.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.
package/README.md CHANGED
@@ -1,35 +1,33 @@
1
1
  # @petrarca/sonnet-graph
2
2
 
3
- Renderer-agnostic property graph visualization, exploration, and enrichment
4
- for the Petrarca Sonnet component library.
5
-
6
- ## What's included
7
-
8
- **GraphVisualizer** — Main visualization component. Renders a property graph
9
- using the active renderer (Cytoscape or Reagraph). Supports node/edge
10
- selection, focus mode, hide/show, and graph expansion.
11
-
12
- **ActionPanel** — Side panel showing selected node/edge details and graph
13
- exploration actions.
14
-
15
- **GraphA11yList** — Accessible DOM mirror of the graph's selectable elements.
16
- Cytoscape (canvas) and Reagraph (WebGL) draw nodes/edges outside the DOM, so they
17
- are invisible to screen readers, keyboard users, and DOM automation; this renders
18
- a virtualized list of node/edge `<button>`s that drive the same selection store
19
- the canvas reads. `sr-only` by default (real apps); pass `visible` for an on-screen
20
- outline panel.
21
-
22
- **GraphRendererProvider** — Context provider that selects the active renderer
23
- (`"cytoscape"` or `"reagraph"`).
24
-
25
- **Store factories** — Create the Zustand stores the graph components need:
26
- `createGraphDataStore`, `createGraphFilterStore`, `createGraphExplorationStore`,
27
- `createSelectionStore`, `createGraphFocusStore`.
28
-
29
- **Graph utilities** — `enrichNodes`, `enrichEdges`, `buildColorPalette` for
30
- preparing raw graph data before passing it to stores.
31
-
32
- ---
3
+ Property-graph visualization for the Petrarca Sonnet component library. The
4
+ state and the transformations are renderer-independent; Cytoscape and Reagraph
5
+ are two implementations of the drawing surface, switched at runtime
6
+ ([ADR-0004](../../docs/adr/0004-graph-rendering-is-renderer-agnostic.md)).
7
+
8
+ ## What it provides
9
+
10
+ **A viewer.** `GraphVisualizer` draws the graph through the active renderer,
11
+ with selection, focus mode, hide and show, and expansion.
12
+ `GraphRendererProvider` holds the choice and reports changes so a host can
13
+ persist it; `ActionPanel` shows the selected element and its actions.
14
+
15
+ **An accessible list.** Both renderers draw outside the DOM, so `GraphA11yList`
16
+ mirrors the selectable elements as buttons driving the same selection store,
17
+ `sr-only` by default and displayable as an outline panel.
18
+
19
+ **Stores and transforms.** `createGraphDataStore`, `createGraphFilterStore`,
20
+ `createGraphExplorationStore`, `createSelectionStore`, `createGraphFocusStore`
21
+ and `createActionPanelStore`, plus `enrichNodes`, `enrichEdges`,
22
+ `normalizeGraph` and the palette builders. The consumer creates the stores, so
23
+ two graph views in one application are isolated.
24
+
25
+ **Two editors.** `GraphModelEditor` authors the metamodel -- node types, edge
26
+ types, relations -- as a graph over a controlled `value`. The `graph-edit`
27
+ surface (`GraphEditToolbar`, `NodeFormSheet`, `EdgeFormSheet`,
28
+ `DeleteNodeDialog`) edits the instance data, writing through a
29
+ `GraphMutationPort` you implement and reading schemas from a
30
+ `GraphSchemaProvider` you supply. Nothing here does I/O of its own.
33
31
 
34
32
  ## Install
35
33
 
@@ -37,108 +35,81 @@ preparing raw graph data before passing it to stores.
37
35
  pnpm add @petrarca/sonnet-graph
38
36
  ```
39
37
 
40
- ### Required peer dependencies
41
-
42
- ```bash
43
- pnpm add react@">=19" react-dom@">=19"
44
- ```
38
+ | Peer | Range | Needed for |
39
+ |---|---|---|
40
+ | `react`, `react-dom` | `>=19` | Everything |
41
+ | `lucide-react` | `>=0.300` | Toolbar and panel icons |
42
+ | `cytoscape` | `>=3` | The Cytoscape renderer |
43
+ | `cytoscape-cola`, `cytoscape-cise`, `cytoscape-cxtmenu`, `cytoscape-dagre`, `cytoscape-elk`, `cytoscape-fcose`, `cytoscape-klay` | `>=1` to `>=3` | Cytoscape layouts and the context menu |
44
+ | `reagraph` | `>=4` | The Reagraph renderer |
45
45
 
46
- ### Renderer peer dependencies
46
+ **The renderer peers are declared optional, and are not optional in practice.**
47
+ Both renderers and all seven Cytoscape plugins are statically imported at
48
+ module scope, so `peerDependenciesMeta.optional` only stops your package manager
49
+ warning at install time. Omit any one of the nine and importing
50
+ `GraphVisualizer` fails; there is no supported subset.
47
51
 
48
- Install only the renderers you use:
52
+ The plugin specifiers must also resolve from your own `node_modules`. If your
53
+ bundler resolves this package from anywhere else -- a linked checkout, a build
54
+ output outside the project, any alias pointing elsewhere -- resolution starts
55
+ from that location and there is nothing to find. Alias all seven plugin
56
+ specifiers to your own `node_modules`; a partial list fails on whichever one was
57
+ left out, when the renderer first mounts. The configuration is in
58
+ [getting started](docs/usage/getting-started.md).
49
59
 
50
- ```bash
51
- pnpm add cytoscape # Cytoscape.js renderer
52
- pnpm add reagraph # Reagraph (3D/WebGL) renderer
53
- ```
60
+ ## Usage
54
61
 
55
- If you use `@petrarca/sonnet-playground` (which includes the graph demo page),
56
- both `cytoscape` and `reagraph` are required even if your app only uses one renderer.
57
-
58
- ### Cytoscape layout plugins (optional)
59
-
60
- Install the layout algorithms you need. All are optional — the graph works
61
- without them but with fewer layout options:
62
-
63
- ```bash
64
- pnpm add cytoscape-fcose # Force-directed, compound graph
65
- pnpm add cytoscape-cola # Constraint-based
66
- pnpm add cytoscape-dagre # DAG / hierarchical
67
- pnpm add cytoscape-elk # Eclipse Layout Kernel
68
- pnpm add cytoscape-cise # Circular layout
69
- pnpm add cytoscape-klay # KLay hierarchical
70
- pnpm add cytoscape-cxtmenu # Context menu extension
71
- ```
72
-
73
- ### Local development with SONNET_UI_LOCAL=1
74
-
75
- When resolving `@petrarca/sonnet-graph` from the local dist (via Vite aliases),
76
- the Cytoscape plugins must also be aliased to the consumer's `node_modules` —
77
- Vite cannot find them relative to the dist file. Add to your `sonnet-aliases.ts`:
78
-
79
- ```ts
80
- const nm = path.resolve(baseDir, "node_modules");
81
- // ...
82
- "cytoscape-fcose": path.resolve(nm, "cytoscape-fcose"),
83
- "cytoscape-cola": path.resolve(nm, "cytoscape-cola"),
84
- "cytoscape-dagre": path.resolve(nm, "cytoscape-dagre"),
85
- "cytoscape-elk": path.resolve(nm, "cytoscape-elk"),
86
- "cytoscape-cise": path.resolve(nm, "cytoscape-cise"),
87
- "cytoscape-klay": path.resolve(nm, "cytoscape-klay"),
88
- "cytoscape-cxtmenu": path.resolve(nm, "cytoscape-cxtmenu"),
89
- ```
90
-
91
- See `sonnet-ui-starter/sonnet-aliases.ts` for a complete reference implementation.
92
-
93
- ---
94
-
95
- ## Basic usage
62
+ Create the stores once, never in a render body, and give the container a height.
96
63
 
97
64
  ```tsx
98
65
  import {
99
- GraphVisualizer,
100
- ActionPanel,
101
- GraphRendererProvider,
102
- GraphStoresContext,
103
- createGraphDataStore,
104
- createGraphFilterStore,
105
- createGraphExplorationStore,
106
- createSelectionStore,
107
- createGraphFocusStore,
108
- enrichNodes,
109
- enrichEdges,
110
- buildColorPalette,
111
- type RawGraphNode,
112
- type RawGraphEdge,
113
- type WorkspaceStores,
66
+ GraphRendererProvider, GraphStoresContext, GraphVisualizer,
67
+ createGraphDataStore, createGraphExplorationStore, createGraphFilterStore,
68
+ createGraphFocusStore, createSelectionStore, type WorkspaceStores,
114
69
  } from "@petrarca/sonnet-graph";
115
70
 
116
- // Create stores once (e.g. in a context provider)
71
+ const graphData = createGraphDataStore();
72
+ const graphFilter = createGraphFilterStore();
73
+ const selection = createSelectionStore();
74
+
75
+ // WorkspaceStores has exactly these four members. The focus store is a
76
+ // dependency of the exploration store, which requires its deps object.
117
77
  const stores: WorkspaceStores = {
118
- graphData: createGraphDataStore(),
119
- graphFilter: createGraphFilterStore(),
120
- graphExploration: createGraphExplorationStore(),
121
- selection: createSelectionStore(),
122
- graphFocus: createGraphFocusStore(),
78
+ graphData,
79
+ graphFilter,
80
+ selection,
81
+ graphExploration: createGraphExplorationStore({
82
+ graphData,
83
+ selection,
84
+ graphFilter,
85
+ graphFocus: createGraphFocusStore(),
86
+ expandNode: async () => ({ nodes: [], edges: [], has_more: false }),
87
+ getNodes: async () => [],
88
+ }),
123
89
  };
124
90
 
125
- // Render
126
- function MyGraph() {
127
- return (
128
- <GraphStoresContext.Provider value={stores}>
129
- <GraphRendererProvider defaultRenderer="cytoscape">
130
- <div style={{ display: "flex", height: 600 }}>
131
- <GraphVisualizer />
132
- <ActionPanel />
133
- </div>
134
- </GraphRendererProvider>
135
- </GraphStoresContext.Provider>
136
- );
137
- }
91
+ const GraphView = () => (
92
+ <GraphStoresContext.Provider value={stores}>
93
+ <GraphRendererProvider defaultRenderer="cytoscape">
94
+ <div className="h-[600px] w-full">
95
+ <GraphVisualizer />
96
+ </div>
97
+ </GraphRendererProvider>
98
+ </GraphStoresContext.Provider>
99
+ );
138
100
  ```
139
101
 
140
- ---
102
+ ## Documentation
103
+
104
+ - [Usage guides](docs/usage/index.md) -- getting started,
105
+ [stores and data](docs/usage/stores-and-data.md),
106
+ [exploration and selection](docs/usage/exploration-and-selection.md),
107
+ [accessibility](docs/usage/accessibility.md), and both editors:
108
+ [model](docs/usage/model-editing.md) and
109
+ [instance](docs/usage/instance-editing.md).
110
+ - [Design docs](docs/design/index.md) -- the renderer boundary and both editors.
111
+ - [Workspace documentation](../../docs/README.md) -- how the packages layer.
141
112
 
142
113
  ## License
143
114
 
144
- See [LICENSE.md](../../LICENSE.md).
115
+ Apache 2.0. See [LICENSE.md](../../LICENSE.md).