Skip to content

Commit de8bc05

Browse files
claudemindsocket
authored andcommitted
docs(api): trim to what code and types don't say; ship the page template's types from the library
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_019XphpeFwEYm8K11SoT9ewz
1 parent a312226 commit de8bc05

4 files changed

Lines changed: 15 additions & 48 deletions

File tree

‎docs/api.md‎

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@ The library is pre-1.0: its exports may change between minor versions.
88
| `structured-context-map-views/node` | Finding definitions on disk. Node only |
99
| `structured-context-map-views/styles.css` | Prebuilt styles, required by the components |
1010

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.
12-
1311
## Rendering a map view
1412

1513
```tsx
@@ -20,74 +18,42 @@ import 'structured-context-map-views/styles.css';
2018
<MapView definition={definition} graph={graph} values={values} onNodeSelect={(node) => open(node)} />
2119
```
2220

23-
### `MapView`
24-
25-
| Prop | Type | Meaning |
26-
|---|---|---|
27-
| `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)).
3622

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`.
4024

4125
## Definitions
4226

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`.
5028

5129
## Data
5230

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`.
5432

5533
## The `export` command
5634

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.
6836

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.
7038

7139
## Publishing as a Claude artifact
7240

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.
7442

7543
## Rendering to an HTML file
7644

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`.
7846

7947
## Validation results
8048

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.
8250

8351
The library draws the badge, and the host lists the messages. See `AnnotationList` in `apps/navigator/src/NodeDetails.tsx`.
8452

8553
## Drawing a tree yourself
8654

8755
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.
8856

89-
Importing only these from the package root pulls in neither React nor the definition parser (ajv, json5) when bundled.
90-
9157
## Theming
9258

9359
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.

‎packages/map-views/package.json‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,10 @@
3434
"default": "./dist/node.js"
3535
},
3636
"./styles.css": "./dist/styles.css",
37-
"./page.html": "./dist/page.html"
37+
"./page.html": {
38+
"types": "./dist/page.html.d.ts",
39+
"default": "./dist/page.html"
40+
}
3841
},
3942
"scripts": {
4043
"clean": "rm -rf dist",

‎packages/map-views/scripts/build-page.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,6 @@ ${css}
4141
</html>
4242
`;
4343
writeFileSync(join(root, 'dist/page.html'), page);
44+
// TypeScript can't type an import of an HTML file; this tells consumers it is the page text.
45+
writeFileSync(join(root, 'dist/page.html.d.ts'), 'declare const page: string;\nexport default page;\n');
4446
console.log(`dist/page.html: ${(page.length / 1024).toFixed(0)} KB`);

‎packages/sctx-map-views/src/html.d.ts‎

Lines changed: 0 additions & 4 deletions
This file was deleted.

0 commit comments

Comments
 (0)