You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit de8bc05
Browse filesBrowse the repository at this point in the historyBrowse files
Copy file name to clipboardExpand all lines: docs/api.md
+9-43Lines changed: 9 additions & 43 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -8,8 +8,6 @@ The library is pre-1.0: its exports may change between minor versions.
8
8
|`structured-context-map-views/node`| Finding definitions on disk. Node only |
9
9
|`structured-context-map-views/styles.css`| Prebuilt styles, required by the components |
10
10
11
-
React 19 and `structured-context` are peer dependencies, so the host's copy of each is the one used. Layouts, node cards, the edge overlay and the projections are internal; exports are added when a host needs one.
|`definition`|`MapViewDefinition`| A parsed definition |
28
-
|`graph`|`SpaceGraph`| The space to render, as structured-context's `assembleSpaceGraph` or `spaceGraphFrom` returns it |
29
-
|`values`|`ParameterValues`| Current parameter values, owned by the host. Missing values use defaults |
30
-
|`annotations`|`AnnotationIndex`| Validation results by node (see [Validation results](#validation-results)) |
31
-
|`onNodeSelect`|`(node: SpaceNode) => void`| Called when the reader selects a node |
32
-
33
-
`MapView` sizes to its container and scrolls within it.
34
-
35
-
### Parameter controls
21
+
`graph` is a structured-context `SpaceGraph` (see [Data](#data)); `values` and the controls' `onChange` belong to the host. Pass `annotations` to show validation results (see [Validation results](#validation-results)).
36
22
37
-
`ParameterControls` is a ready-made row of controls generated from the definition's parameters; it renders nothing when there are none. `values` holds the host's current values (missing or stale ones show as the default), and `onChange` receives the parameter name and new value.
38
-
39
-
A host that wants its own layout builds from smaller parts: `useParameterControls(definition, values, onChange)` returns each parameter with its current value and a setter, with no markup, and `ParameterInput` renders the right input for a parameter. The typed inputs (`ToggleParameterInput`, `SelectParameterInput`, `MultiSelectParameterInput`) are exported for hosts that want one kind of input without the dispatch.
23
+
A host that lays out the controls itself builds them from `useParameterControls` and `ParameterInput`.
40
24
41
25
## Definitions
42
26
43
-
-`loadMapViewDefinitions(config, { configDir? })` (from `/node`): every definition available with a structured-context config, checked for namespaced, unique `$id`s (see [where definitions are found](definitions.md#where-definitions-are-found)). The library's own definitions are embedded in the module, so it works in a host's bundle. Browser-only hosts get the result from a server.
44
-
-`parseMapViewDefinition(name, text)`: parses and validates JSON5 text (`name` labels error messages), throwing `MapViewDefinitionError` with the problems found. A `MapViewDefinition`'s `id` is its `$id`.
45
-
-`mapViewsForSchema(definitions, schemaId)`: the definitions that apply to a schema.
46
-
-`resolveParameterValues(definition, values)`: the effective value of every parameter.
47
-
-`selectionFilter(definition, values)`: the first region's `select.filter`, for a host to apply when loading the space.
48
-
-`viewValidationLevel(definition, values)`: the first region's `nodes.validation`, so a host can skip running validation when it is `off`.
49
-
-`MAP_VIEW_SCHEMAS`: the format's JSON Schemas.
27
+
A Node host loads definitions with `loadMapViewDefinitions` (from `/node`; see [where definitions are found](definitions.md#where-definitions-are-found)) and lists those for the space's schema with `mapViewsForSchema(definitions, context.schema.$id)`. Browser-only hosts get the result from a server. After the reader picks a view and its parameters, apply `selectionFilter(definition, values)` when loading the space, and skip validation when `viewValidationLevel(definition, values)` is `off`.
50
28
51
29
## Data
52
30
53
-
Map views take structured-context's `SpaceGraph`. A Node host (such as the Obsidian plugin) passes the graph `assembleSpaceGraph` returns. A host whose server and browser are separate sends the wire format: `exportSpaceGraph` on the server, `spaceGraphFrom` (from `structured-context/browser`) in the browser; see `apps/navigator/src/server/load-space.ts`. To pick definitions, hosts also need the space's schema id (`context.schema.$id`).
31
+
Map views take structured-context's `SpaceGraph`. A Node host (such as the Obsidian plugin) passes the graph `assembleSpaceGraph` returns. A host whose server and browser are separate sends the wire format: `exportSpaceGraph` on the server, `spaceGraphFrom` (from `structured-context/browser`) in the browser; see `apps/navigator/src/server/load-space.ts`.
54
32
55
33
## The `export` command
56
34
57
-
`structured-context-map-views [--config <file>] export <space> [options]` prints a JSON snapshot of a space (its graph, validation results and applicable map view definitions), so a host that can't run structured-context can render a map view from it. The validation options (see `--help`) mean what they do for `sctx validate`.
58
-
59
-
```json
60
-
{
61
-
"space": "name",
62
-
"schemaId": "sctx://…",
63
-
"graph": { "formatVersion": 1 },
64
-
"validation": { "issues": [] },
65
-
"definitions": []
66
-
}
67
-
```
35
+
`structured-context-map-views [--config <file>] export <space> [options]` prints a JSON snapshot of a space (its graph, validation results and applicable map view definitions), so a host that can't run structured-context can render a map view from it.
68
36
69
-
`graph` is the wire format described above and `validation` is what `annotationsFrom` takes.
37
+
In the output, `graph` is the wire format above and `validation` is what `annotationsFrom` takes.
70
38
71
39
## Publishing as a Claude artifact
72
40
73
-
`dist/artifact.html` is a page that needs no edits: publish it as a Claude artifact declaring the `db` capability, then write each space as `spaces/<space>` from the `export` document: `{ schemaId, graph, validation, definitions }`, the last three as JSON strings. The page lists the `spaces` collection, so one artifact can show several spaces, and refreshing is writing the documents again. The page pins this package's version (loaded from jsDelivr) and carries the styles inline. Comments on a card report its accessible name, `[<index>] <title> · <view>`; the index is the node's position in the stored graph's `nodes` array.
41
+
Publish `dist/artifact.html`, unedited, as a Claude artifact declaring the `db` capability. Write each space as `spaces/<space>` from the `export` document: `{ schemaId, graph, validation, definitions }`, the last three as JSON strings. One artifact shows every space in the collection, and refreshing is writing the documents again.
74
42
75
43
## Rendering to an HTML file
76
44
77
-
`sctx-map-views` is a structured-context plugin. Name it in a space's `plugins`, or put it in the config root's plugins folder, and `sctx render <space> map-views.html -o map.html` writes one HTML file with the page, its scripts and the space's data inlined. Definitions come from the same places as everywhere else. Validation runs with the `-d` options `semantic`, `depth`, `ruleFilter` (comma-separated) and `includeGated`.
45
+
`sctx-map-views` is a structured-context plugin. Name it in a space's `plugins`, or put it in the config root's plugins folder, and `sctx render <space> map-views.html -o map.html` writes one HTML file with the page, its scripts and the space's data inlined. Validation takes the `-d` options `semantic`, `depth`, `ruleFilter` (comma-separated) and `includeGated`.
78
46
79
47
## Validation results
80
48
81
-
`annotationsFrom(input, graph)` attaches structured-context's validation issues to the graph's nodes. Pass it a `ValidationResult` or the output of `sctx validate --json` as it is. It returns the `annotations` to pass to `MapView`, and the `unattached` issues, which have no node in the graph. The definition's `nodes.validation` and `nodes.validationSources` choose which annotations show.
49
+
`annotationsFrom(input, graph)` attaches structured-context's validation issues to the graph's nodes. Pass its `annotations` to `MapView`. The definition's `nodes.validation` and `nodes.validationSources` choose which show.
82
50
83
51
The library draws the badge, and the host lists the messages. See `AnnotationList` in `apps/navigator/src/NodeDetails.tsx`.
84
52
85
53
## Drawing a tree yourself
86
54
87
55
A host that cannot mount React, such as a Claude Code mod, can draw a tree from `buildTree(graph, regionId, dag)`, the tree layout's projection, with `annotationsFrom` for the validation results.
88
56
89
-
Importing only these from the package root pulls in neither React nor the definition parser (ajv, json5) when bundled.
90
-
91
57
## Theming
92
58
93
59
Override the `--mv-color-*` variables (`surface`, `card`, `ink`, `muted`, `edge`, `accent`, and `error`, `warning`, `info` for validation badges) on an ancestor of the map view, for example mapping them onto the host's theme variables.
0 commit comments