@molecule/app-feature-graph-view-solid 0.0.1-stage → 1.1.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.
Files changed (2) hide show
  1. package/README.md +411 -4
  2. package/package.json +4 -4
package/README.md CHANGED
@@ -1,11 +1,418 @@
1
+ <!--
2
+ AUTO-GENERATED — DO NOT EDIT THIS FILE.
3
+ Generated by `mlcl sync-docs` from the package's src/index.ts JSDoc + mlcl/registry.json.
4
+ Edits here are overwritten on the next commit (molecule's pre-commit hook regenerates).
5
+ To change this document, edit the module-level JSDoc in src/index.ts.
6
+ Generated: 2026-11-21T12:46:30.610Z
7
+ -->
8
+
1
9
  # @molecule/app-feature-graph-view-solid
2
10
 
3
- Force-directed graph view (Obsidian-style) for visualizing note / page linkages
11
+ Solid force-directed graph view (Obsidian-style) — the Solid counterpart of
12
+ `@molecule/app-feature-graph-view-react`: the same exports, the same props
13
+ (React names), and the same DOM for the same input.
14
+
15
+ Exports:
16
+
17
+ - `<GraphView>` — top-level node-and-edge visualization with built-in
18
+ `force`, `circular`, and `grid` layouts, click + selection support,
19
+ and pluggable node / edge renderers.
20
+ - `GraphNode`, `GraphEdge`, `GraphLayout`, `GraphPoint`, `PositionedNode`,
21
+ `GraphNodeRenderer`, `GraphEdgeRenderer`, `GraphViewProps` types.
22
+ - Pure layout helpers (`forceLayout`, `circularLayout`, `gridLayout`,
23
+ `layoutNodes`, `boundingBox`, `createRng`).
24
+
25
+ Used by note-taking and other apps to visualize page / note linkages
26
+ the same way Obsidian does — a force-directed map of which notes link
27
+ to which.
28
+
29
+ > **Auto-generated, AI-first package reference** for the [molecule.dev](https://molecule.dev) ecosystem.
30
+ > It is written to be read by coding agents as much as by people, and is generated from this
31
+ > package's source — edit `src/index.ts` JSDoc, not this file.
32
+
33
+ ## Quick Start
34
+
35
+ ```tsx
36
+ import { GraphView, type GraphEdge, type GraphNode } from '@molecule/app-feature-graph-view-solid'
37
+
38
+ export function NoteGraph(props: { notes: Note[]; links: Link[] }) {
39
+ const nodes = (): GraphNode[] =>
40
+ props.notes.map((n) => ({ id: n.id, label: n.title, weight: n.linkCount }))
41
+ const edges = (): GraphEdge[] =>
42
+ props.links.map((l) => ({ id: l.id, source: l.from, target: l.to }))
43
+ return <GraphView nodes={nodes()} edges={edges()} onNodeClick={(n) => open(n.id)} />
44
+ }
45
+ ```
46
+
47
+ ## Type
48
+
49
+ `feature`
50
+
51
+ ## Installation
52
+
53
+ ```bash
54
+ npm install @molecule/app-feature-graph-view-solid @molecule/app-solid @molecule/app-ui @molecule/app-ui-solid solid-js
55
+ ```
56
+
57
+ ## API
58
+
59
+ ### Interfaces
60
+
61
+ #### `ForceLayoutOptions`
62
+
63
+ Force-layout tunables.
64
+
65
+ ```typescript
66
+ interface ForceLayoutOptions {
67
+ /** Hard cap on iterations. Defaults to {@link DEFAULT_FORCE_ITERATIONS}. */
68
+ iterations?: number
69
+ /** Repulsive constant between every pair of nodes. */
70
+ repulsion?: number
71
+ /** Spring (Hooke) constant for edges. */
72
+ spring?: number
73
+ /** Ideal edge length (rest distance). */
74
+ restLength?: number
75
+ /** Velocity damping per step (0–1). */
76
+ damping?: number
77
+ /** Optional deterministic seed (for tests). Defaults to a fixed value. */
78
+ seed?: number
79
+ }
80
+ ```
81
+
82
+ #### `GraphPoint`
83
+
84
+ A 2-D point in graph (world) coordinates.
85
+
86
+ ```typescript
87
+ interface GraphPoint {
88
+ /** X coordinate. */
89
+ x: number
90
+ /** Y coordinate. */
91
+ y: number
92
+ }
93
+ ```
94
+
95
+ #### `GraphNode`
96
+
97
+ Single node in the graph.
98
+
99
+ `group` is an opaque grouping discriminator (e.g. tag, folder) the
100
+ caller can use for colouring; `weight` scales the rendered radius.
101
+
102
+ ```typescript
103
+ interface GraphNode {
104
+ /** Unique node id. */
105
+ id: string
106
+ /** Human-readable label rendered next to the node. */
107
+ label: string
108
+ /** Optional grouping discriminator (e.g. tag id). */
109
+ group?: string
110
+ /** Optional weight; default 1. Scales the rendered radius. */
111
+ weight?: number
112
+ }
113
+ ```
114
+
115
+ #### `GraphEdge`
116
+
117
+ Edge connecting two nodes by id.
118
+
119
+ ```typescript
120
+ interface GraphEdge {
121
+ /** Unique edge id. */
122
+ id: string
123
+ /** Source node id. */
124
+ source: string
125
+ /** Target node id. */
126
+ target: string
127
+ /** Optional weight; default 1. Stronger edges pull harder under force layout. */
128
+ weight?: number
129
+ }
130
+ ```
131
+
132
+ #### `PositionedNode`
133
+
134
+ Internal positioned node used by the renderer; the `x`/`y` coordinates
135
+ are in world (graph) space, with `(0, 0)` at the canvas centre.
136
+
137
+ ```typescript
138
+ interface PositionedNode extends GraphNode {
139
+ /** World-space X coordinate. */
140
+ x: number
141
+ /** World-space Y coordinate. */
142
+ y: number
143
+ }
144
+ ```
145
+
146
+ #### `GraphViewProps`
147
+
148
+ `<GraphView>` props.
149
+
150
+ ```typescript
151
+ interface GraphViewProps {
152
+ /** Nodes to render. */
153
+ nodes: GraphNode[]
154
+ /** Edges to render. */
155
+ edges: GraphEdge[]
156
+ /** Fired when the user clicks (or activates) a node. */
157
+ onNodeClick?: (node: GraphNode) => void
158
+ /** Currently-selected node id (highlighted in the view). */
159
+ selectedNodeId?: string
160
+ /** Layout strategy. Defaults to `'force'`. */
161
+ layout?: GraphLayout
162
+ /** Custom node renderer (overrides the default circle + label). */
163
+ nodeRenderer?: GraphNodeRenderer
164
+ /** Custom edge renderer (overrides the default `<line>`). */
165
+ edgeRenderer?: GraphEdgeRenderer
166
+ /** Force-layout tunables; ignored for non-force layouts. */
167
+ forceOptions?: ForceLayoutOptions
168
+ /** Extra classes merged onto the outer wrapper. */
169
+ className?: string
170
+ }
171
+ ```
172
+
173
+ ### Types
174
+
175
+ #### `GraphLayout`
176
+
177
+ Available layout strategies.
178
+
179
+ ```typescript
180
+ type GraphLayout = 'force' | 'circular' | 'grid'
181
+ ```
182
+
183
+ #### `GraphNodeRenderer`
184
+
185
+ Renderer for an individual node. Receives the positioned node.
186
+
187
+ ```typescript
188
+ type GraphNodeRenderer = (node: PositionedNode) => JSX.Element
189
+ ```
190
+
191
+ #### `GraphEdgeRenderer`
192
+
193
+ Renderer for an individual edge. Receives the edge plus both endpoints.
194
+
195
+ ```typescript
196
+ type GraphEdgeRenderer = (
197
+ edge: GraphEdge,
198
+ source: PositionedNode,
199
+ target: PositionedNode,
200
+ ) => JSX.Element
201
+ ```
202
+
203
+ ### Functions
204
+
205
+ #### `GraphView(props)`
206
+
207
+ Force-directed graph view (Obsidian-style).
208
+
209
+ Renders nodes + edges into an SVG, computing positions via a built-in
210
+ minimal velocity-Verlet simulation. Three layouts are supported —
211
+ `force` (default), `circular` and `grid` — and either nodes or edges
212
+ can be overridden via custom renderers.
213
+
214
+ This is the Solid counterpart of `@molecule/app-feature-graph-view-react`:
215
+ the same props (React names), the same ClassMap tokens, and the same DOM for
216
+ the same input.
217
+
218
+ Style is driven by `getClassMap()`. Inline styles are reserved for
219
+ SVG geometry — `transform`, viewBox computation, stroke widths — which
220
+ classes can't express.
221
+
222
+ ```typescript
223
+ function GraphView(props: GraphViewProps): JSX.Element
224
+ ```
225
+
226
+ - `props` — Component props (see {@link GraphViewProps}).
227
+
228
+ **Returns:** The graph-view element.
229
+
230
+ #### `createRng(seed)`
231
+
232
+ Tiny deterministic PRNG (mulberry32). Allows reproducible initial
233
+ positions in tests without depending on `Math.random()`.
234
+
235
+ ```typescript
236
+ function createRng(seed: number): () => number
237
+ ```
238
+
239
+ - `seed` — 32-bit unsigned seed.
240
+
241
+ **Returns:** A function returning floats in `[0, 1)`.
242
+
243
+ #### `circularLayout(nodes, radius)`
244
+
245
+ Place nodes evenly around the unit circle (scaled by `radius`).
246
+
247
+ ```typescript
248
+ function circularLayout(nodes: GraphNode[], radius: number): PositionedNode[]
249
+ ```
250
+
251
+ - `nodes` — Nodes to position.
252
+ - `radius` — Circle radius in world units.
253
+
254
+ **Returns:** Positioned nodes, in input order.
255
+
256
+ #### `gridLayout(nodes, spacing)`
257
+
258
+ Place nodes on a square-ish grid, centred on the origin.
259
+
260
+ ```typescript
261
+ function gridLayout(nodes: GraphNode[], spacing: number): PositionedNode[]
262
+ ```
263
+
264
+ - `nodes` — Nodes to position.
265
+ - `spacing` — Pixel spacing between adjacent grid cells.
266
+
267
+ **Returns:** Positioned nodes, in input order.
268
+
269
+ #### `forceLayout(nodes, edges, options)`
270
+
271
+ Run a minimal velocity-Verlet force-directed simulation.
4
272
 
273
+ Implements:
274
+
275
+ - Pairwise repulsion (Coulomb-like, O(n²)) between every node pair.
276
+ - Spring (Hooke) attraction along each edge toward `restLength`.
277
+ - Per-step velocity damping for stability.
278
+
279
+ Stops early once the maximum per-node displacement-squared drops below
280
+ {@link CONVERGENCE_EPSILON}, or after `iterations` steps — whichever
281
+ comes first.
282
+
283
+ ```typescript
284
+ function forceLayout(
285
+ nodes: GraphNode[],
286
+ edges: GraphEdge[],
287
+ options?: ForceLayoutOptions,
288
+ ): PositionedNode[]
5
289
  ```
6
- npm install @molecule/app-feature-graph-view-solid
290
+
291
+ - `nodes` — Nodes to lay out.
292
+ - `edges` — Edges (used only for attractive springs).
293
+ - `options` — Force-layout tunables.
294
+
295
+ **Returns:** Positioned nodes, in input order.
296
+
297
+ #### `layoutNodes(nodes, edges, layout, options)`
298
+
299
+ Compute world-space positions for every node using the chosen layout.
300
+
301
+ ```typescript
302
+ function layoutNodes(
303
+ nodes: GraphNode[],
304
+ edges: GraphEdge[],
305
+ layout: GraphLayout,
306
+ options?: ForceLayoutOptions,
307
+ ): PositionedNode[]
7
308
  ```
8
309
 
9
- Part of the [Molecule](https://www.molecule.dev) package fleet. This page carries the manifest summary; the full generated documentation ships with the package's first committed version.
310
+ - `nodes` — Nodes to position.
311
+ - `edges` — Edges (consumed only by `force`).
312
+ - `layout` — Layout strategy.
313
+ - `options` — Optional force-layout tunables (ignored for non-force).
314
+
315
+ **Returns:** Positioned nodes.
316
+
317
+ #### `boundingBox(nodes, padding)`
318
+
319
+ Compute the world-space bounding box of a set of positioned nodes,
320
+ with a small padding for visual breathing room.
321
+
322
+ ```typescript
323
+ function boundingBox(
324
+ nodes: PositionedNode[],
325
+ padding?: number,
326
+ ): { minX: number; minY: number; maxX: number; maxY: number } | null
327
+ ```
328
+
329
+ - `nodes` — Positioned nodes.
330
+ - `padding` — Padding (world units) added to every side. Default 40.
331
+
332
+ **Returns:** Bounding box `{ minX, minY, maxX, maxY }` — or `null` if empty.
333
+
334
+ ### Constants
335
+
336
+ #### `DEFAULT_FORCE_ITERATIONS`
337
+
338
+ Default cap on force-layout iterations.
339
+
340
+ ```typescript
341
+ const DEFAULT_FORCE_ITERATIONS: 200
342
+ ```
343
+
344
+ #### `DEFAULT_REPULSION`
345
+
346
+ Default repulsion strength used by `forceLayout`.
347
+
348
+ ```typescript
349
+ const DEFAULT_REPULSION: 800
350
+ ```
351
+
352
+ #### `DEFAULT_SPRING`
353
+
354
+ Default spring stiffness used by `forceLayout`.
355
+
356
+ ```typescript
357
+ const DEFAULT_SPRING: 0.05
358
+ ```
359
+
360
+ #### `DEFAULT_REST_LENGTH`
361
+
362
+ Default ideal edge length used by `forceLayout`.
363
+
364
+ ```typescript
365
+ const DEFAULT_REST_LENGTH: 80
366
+ ```
367
+
368
+ #### `DEFAULT_DAMPING`
369
+
370
+ Default velocity damping used by `forceLayout`.
371
+
372
+ ```typescript
373
+ const DEFAULT_DAMPING: 0.85
374
+ ```
375
+
376
+ #### `CONVERGENCE_EPSILON`
377
+
378
+ Convergence threshold (max per-node displacement squared).
379
+
380
+ ```typescript
381
+ const CONVERGENCE_EPSILON: 0.01
382
+ ```
383
+
384
+ ## Injection Notes
385
+
386
+ ### Requirements
387
+
388
+ Peer dependencies:
389
+
390
+ - `@molecule/app-solid` ^3.5.0
391
+ - `@molecule/app-ui` ^1.0.1
392
+ - `@molecule/app-ui-solid` ^1.1.0
393
+ - `solid-js` ^1.8.0
394
+
395
+ ### Runtime Dependencies
396
+
397
+ - `@molecule/app-solid`
398
+ - `@molecule/app-ui`
399
+ - `@molecule/app-ui-solid`
400
+ - `solid-js`
401
+
402
+ The root element fills 100% of its parent — the PARENT must have an
403
+ explicit height (e.g. a fixed-height panel or a flex/grid track) or
404
+ the graph renders zero-tall and appears blank.
405
+
406
+ Interaction surface is click / keyboard-activate + `selectedNodeId`
407
+ highlighting only. Nodes are NOT draggable and there is no built-in
408
+ pan / zoom — the SVG `viewBox` auto-fits the layout bounds. For a
409
+ pannable / zoomable surface, compose with
410
+ `@molecule/app-feature-canvas-solid` instead.
411
+
412
+ Layout is deterministic (seeded RNG), computed once per
413
+ `(nodes, edges, layout, forceOptions)` change. `forceOptions` is
414
+ ignored by the `circular` and `grid` layouts.
415
+
416
+ ## Translations
10
417
 
11
- License: Apache-2.0
418
+ Translation strings are provided by `@molecule/app-locales-feature-graph-view`.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@molecule/app-feature-graph-view-solid",
3
- "version": "0.0.1-stage",
3
+ "version": "1.1.0",
4
4
  "description": "Force-directed graph view (Obsidian-style) for visualizing note / page linkages",
5
5
  "homepage": "https://www.molecule.dev/packages/app-feature-graph-view-solid",
6
6
  "type": "module",
@@ -55,9 +55,9 @@
55
55
  "@molecule/app-framework-conformance": "0.0.0",
56
56
  "@molecule/app-i18n": "1.2.2",
57
57
  "@molecule/app-icons": "1.0.4",
58
- "@molecule/app-solid": "3.7.2",
59
- "@molecule/app-ui": "1.4.0",
60
- "@molecule/app-ui-solid": "1.1.5",
58
+ "@molecule/app-solid": "3.9.0",
59
+ "@molecule/app-ui": "1.5.0",
60
+ "@molecule/app-ui-solid": "1.2.1",
61
61
  "@types/node": "26.6.5",
62
62
  "jsdom": "30.1.3",
63
63
  "solid-js": "1.9.17",