structured-context-map-views 0.5.0 → 0.6.1
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/{ParameterControls--sD0-okx.js → ParameterControls-A1HJWyt9.js} +2 -2
- package/dist/{ParameterControls--sD0-okx.js.map → ParameterControls-A1HJWyt9.js.map} +1 -1
- package/dist/artifact.html +29 -29
- package/dist/artifact.js +116 -96
- package/dist/artifact.js.map +1 -1
- package/dist/cli.js +17 -14
- package/dist/cli.js.map +1 -1
- package/dist/index.js +2 -2
- package/dist/{node-Co_JiEZV.js → node-aizYAYlq.js} +38 -14
- package/dist/node-aizYAYlq.js.map +1 -0
- package/dist/node.js +2 -2
- package/dist/page.html +640 -0
- package/dist/page.html.d.ts +2 -0
- package/dist/{projection-CYShQhug.js → projection-C-dATsdO.js} +15 -29
- package/dist/projection-C-dATsdO.js.map +1 -0
- package/dist/types/artifact/load.d.ts +6 -13
- package/dist/types/core/annotations.d.ts +11 -20
- package/dist/types/core/format/definition-schema.d.ts +1 -1
- package/dist/types/core/format/index.d.ts +2 -2
- package/dist/types/core/format/settings.d.ts +1 -1
- package/dist/types/core/snapshot.d.ts +15 -0
- package/dist/types/node/index.d.ts +19 -2
- package/dist/types/node/page.d.ts +7 -0
- package/dist/types/node/snapshot.d.ts +2 -15
- package/dist/types/page/main.d.ts +1 -0
- package/dist/types/viewer/Viewer.d.ts +14 -0
- package/package.json +11 -6
- package/dist/node-Co_JiEZV.js.map +0 -1
- package/dist/projection-CYShQhug.js.map +0 -1
package/dist/artifact.js
CHANGED
|
@@ -1,104 +1,49 @@
|
|
|
1
|
-
import { a as annotationsFrom } from "./projection-
|
|
2
|
-
import { s as MapView, t as ParameterControls } from "./ParameterControls
|
|
1
|
+
import { a as annotationsFrom } from "./projection-C-dATsdO.js";
|
|
2
|
+
import { s as MapView, t as ParameterControls } from "./ParameterControls-A1HJWyt9.js";
|
|
3
3
|
import { useEffect, useMemo, useRef, useState } from "react";
|
|
4
4
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
5
5
|
import { createRoot } from "react-dom/client";
|
|
6
6
|
import { spaceGraphFrom } from "structured-context/browser";
|
|
7
|
-
//#region src/
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
async function loadSpaces() {
|
|
12
|
-
const claude = window.claude;
|
|
13
|
-
const db = claude ? await claude.use("db") : null;
|
|
14
|
-
if (!db) throw new Error("This page needs the artifact database, which is not available to this viewer.");
|
|
15
|
-
let timer;
|
|
16
|
-
const timeout = new Promise((_, reject) => {
|
|
17
|
-
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("Reading the artifact database timed out.")), TIMEOUT_MS);
|
|
18
|
-
});
|
|
19
|
-
const spaces = (await Promise.race([db.collection(SPACES).get(), timeout]).finally(() => clearTimeout(timer))).docs.flatMap((doc) => {
|
|
20
|
-
const data = doc.data();
|
|
21
|
-
return data ? [toSpace(doc.id, data)] : [];
|
|
22
|
-
});
|
|
23
|
-
if (spaces.length === 0) throw new Error(`Nothing to show yet: no space has been written to "${SPACES}" in the artifact database.`);
|
|
24
|
-
return spaces;
|
|
25
|
-
}
|
|
26
|
-
function toSpace(name, data) {
|
|
27
|
-
const json = (field) => {
|
|
28
|
-
const value = data[field];
|
|
29
|
-
if (typeof value !== "string") throw new Error(`Space "${name}": missing "${field}" in the artifact database.`);
|
|
30
|
-
return JSON.parse(value);
|
|
31
|
-
};
|
|
32
|
-
return {
|
|
33
|
-
name,
|
|
34
|
-
schemaId: typeof data.schemaId === "string" ? data.schemaId : void 0,
|
|
35
|
-
graph: json("graph"),
|
|
36
|
-
validation: json("validation"),
|
|
37
|
-
definitions: json("definitions")
|
|
38
|
-
};
|
|
39
|
-
}
|
|
40
|
-
//#endregion
|
|
41
|
-
//#region src/artifact/main.tsx
|
|
42
|
-
function App() {
|
|
43
|
-
const [state, setState] = useState({ status: "loading" });
|
|
44
|
-
useEffect(() => {
|
|
45
|
-
loadSpaces().then((spaces) => setState({
|
|
46
|
-
status: "ready",
|
|
47
|
-
spaces
|
|
48
|
-
}), (err) => setState({
|
|
49
|
-
status: "error",
|
|
50
|
-
message: err instanceof Error ? err.message : String(err)
|
|
51
|
-
}));
|
|
52
|
-
}, []);
|
|
53
|
-
if (state.status === "loading") return /* @__PURE__ */ jsx("p", {
|
|
54
|
-
className: "art-message",
|
|
55
|
-
children: "Loading from the artifact database…"
|
|
56
|
-
});
|
|
57
|
-
if (state.status === "error") return /* @__PURE__ */ jsx("p", {
|
|
58
|
-
className: "art-message",
|
|
59
|
-
children: state.message
|
|
60
|
-
});
|
|
61
|
-
return /* @__PURE__ */ jsx(Viewer, { spaces: state.spaces });
|
|
62
|
-
}
|
|
63
|
-
function Viewer({ spaces }) {
|
|
64
|
-
const [spaceName, setSpaceName] = useState(spaces[0].name);
|
|
65
|
-
const space = spaces.find((s) => s.name === spaceName);
|
|
7
|
+
//#region src/viewer/Viewer.tsx
|
|
8
|
+
function Viewer({ spaces, cardLabel }) {
|
|
9
|
+
const [spaceName, setSpaceName] = useState(spaces[0].space);
|
|
10
|
+
const space = spaces.find((s) => s.space === spaceName);
|
|
66
11
|
const [viewId, setViewId] = useState(space.definitions[0]?.id);
|
|
67
12
|
const definition = space.definitions.find((d) => d.id === viewId) ?? space.definitions[0];
|
|
68
13
|
const [values, setValues] = useState({});
|
|
69
14
|
const [selectedId, setSelectedId] = useState();
|
|
70
15
|
const graph = useMemo(() => spaceGraphFrom(space.graph), [space]);
|
|
71
16
|
const annotated = useMemo(() => annotationsFrom(space.validation, graph), [space, graph]);
|
|
72
|
-
const mapRef =
|
|
17
|
+
const mapRef = useCardLabels(graph, definition, cardLabel);
|
|
73
18
|
if (!definition) return /* @__PURE__ */ jsxs("p", {
|
|
74
|
-
className: "
|
|
19
|
+
className: "viewer-message",
|
|
75
20
|
children: [
|
|
76
21
|
"No map views apply to the schema of \"",
|
|
77
|
-
space.
|
|
22
|
+
space.space,
|
|
78
23
|
"\"."
|
|
79
24
|
]
|
|
80
25
|
});
|
|
81
26
|
const selected = selectedId ? graph.nodes.get(selectedId) : void 0;
|
|
82
27
|
const results = selected ? annotated.annotations.get(selected.id) ?? [] : [];
|
|
83
28
|
return /* @__PURE__ */ jsxs("div", {
|
|
84
|
-
className: "
|
|
29
|
+
className: "viewer-root",
|
|
85
30
|
children: [/* @__PURE__ */ jsxs("header", {
|
|
86
|
-
className: "
|
|
31
|
+
className: "viewer-bar",
|
|
87
32
|
children: [
|
|
88
33
|
spaces.length > 1 && /* @__PURE__ */ jsx("select", {
|
|
89
34
|
"aria-label": "Space",
|
|
90
35
|
value: spaceName,
|
|
91
36
|
onChange: (e) => {
|
|
92
|
-
const next = spaces.find((s) => s.
|
|
93
|
-
setSpaceName(next.
|
|
37
|
+
const next = spaces.find((s) => s.space === e.target.value);
|
|
38
|
+
setSpaceName(next.space);
|
|
94
39
|
setViewId(next.definitions[0]?.id);
|
|
95
40
|
setValues({});
|
|
96
41
|
setSelectedId(void 0);
|
|
97
42
|
},
|
|
98
43
|
children: spaces.map((s) => /* @__PURE__ */ jsx("option", {
|
|
99
|
-
value: s.
|
|
100
|
-
children: s.
|
|
101
|
-
}, s.
|
|
44
|
+
value: s.space,
|
|
45
|
+
children: s.space
|
|
46
|
+
}, s.space))
|
|
102
47
|
}),
|
|
103
48
|
space.definitions.length > 1 && /* @__PURE__ */ jsx("select", {
|
|
104
49
|
"aria-label": "Map view",
|
|
@@ -122,9 +67,9 @@ function Viewer({ spaces }) {
|
|
|
122
67
|
})
|
|
123
68
|
]
|
|
124
69
|
}), /* @__PURE__ */ jsxs("div", {
|
|
125
|
-
className: "
|
|
70
|
+
className: "viewer-body",
|
|
126
71
|
children: [/* @__PURE__ */ jsx("div", {
|
|
127
|
-
className: "
|
|
72
|
+
className: "viewer-map",
|
|
128
73
|
ref: mapRef,
|
|
129
74
|
children: /* @__PURE__ */ jsx(MapView, {
|
|
130
75
|
definition,
|
|
@@ -134,29 +79,29 @@ function Viewer({ spaces }) {
|
|
|
134
79
|
onNodeSelect: (node) => setSelectedId(node.id)
|
|
135
80
|
})
|
|
136
81
|
}), (selected || annotated.unattached.length > 0) && /* @__PURE__ */ jsxs("aside", {
|
|
137
|
-
className: "
|
|
82
|
+
className: "viewer-panel",
|
|
138
83
|
"aria-label": "Validation results",
|
|
139
84
|
children: [selected && /* @__PURE__ */ jsxs("section", { children: [
|
|
140
85
|
/* @__PURE__ */ jsx("button", {
|
|
141
86
|
type: "button",
|
|
142
|
-
className: "
|
|
87
|
+
className: "viewer-close",
|
|
143
88
|
"aria-label": "Close",
|
|
144
89
|
onClick: () => setSelectedId(void 0),
|
|
145
90
|
children: "×"
|
|
146
91
|
}),
|
|
147
92
|
/* @__PURE__ */ jsx("p", {
|
|
148
|
-
className: "
|
|
93
|
+
className: "viewer-type",
|
|
149
94
|
children: selected.resolvedType
|
|
150
95
|
}),
|
|
151
96
|
/* @__PURE__ */ jsx("h2", { children: selected.title }),
|
|
152
97
|
results.length > 0 && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Validation" }), /* @__PURE__ */ jsx(Results, { items: results })] }),
|
|
153
98
|
/* @__PURE__ */ jsx(Fields, { data: selected.schemaData }),
|
|
154
99
|
selected.content && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Content" }), /* @__PURE__ */ jsx("p", {
|
|
155
|
-
className: "
|
|
100
|
+
className: "viewer-content",
|
|
156
101
|
children: selected.content
|
|
157
102
|
})] }),
|
|
158
103
|
selected.source && /* @__PURE__ */ jsx("p", {
|
|
159
|
-
className: "
|
|
104
|
+
className: "viewer-muted",
|
|
160
105
|
children: selected.source.file
|
|
161
106
|
})
|
|
162
107
|
] }), annotated.unattached.length > 0 && /* @__PURE__ */ jsxs("section", { children: [/* @__PURE__ */ jsxs("h3", { children: [
|
|
@@ -180,49 +125,41 @@ function Fields({ data }) {
|
|
|
180
125
|
const fields = Object.entries(data).filter(([name, value]) => !SKIPPED_FIELDS.has(name) && !isEmpty(value));
|
|
181
126
|
if (fields.length === 0) return null;
|
|
182
127
|
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("h3", { children: "Fields" }), /* @__PURE__ */ jsx("dl", {
|
|
183
|
-
className: "
|
|
128
|
+
className: "viewer-fields",
|
|
184
129
|
children: fields.map(([name, value]) => /* @__PURE__ */ jsxs("div", { children: [/* @__PURE__ */ jsx("dt", { children: name }), /* @__PURE__ */ jsx("dd", { children: asText(value) })] }, name))
|
|
185
130
|
})] });
|
|
186
131
|
}
|
|
187
132
|
function Results({ items }) {
|
|
188
133
|
return /* @__PURE__ */ jsx("ul", {
|
|
189
|
-
className: "
|
|
134
|
+
className: "viewer-results",
|
|
190
135
|
children: items.map((a, i) => /* @__PURE__ */ jsxs("li", { children: [
|
|
191
136
|
/* @__PURE__ */ jsx("span", {
|
|
192
|
-
className: `
|
|
137
|
+
className: `viewer-severity viewer-${a.severity}`,
|
|
193
138
|
children: a.severity
|
|
194
139
|
}),
|
|
195
140
|
" ",
|
|
196
141
|
/* @__PURE__ */ jsx("span", {
|
|
197
|
-
className: "
|
|
142
|
+
className: "viewer-muted",
|
|
198
143
|
children: a.ruleId ? `${a.source} · ${a.ruleId}` : a.source
|
|
199
144
|
}),
|
|
200
145
|
a.nodeId && /* @__PURE__ */ jsxs("span", {
|
|
201
|
-
className: "
|
|
146
|
+
className: "viewer-muted",
|
|
202
147
|
children: [" · ", a.nodeId]
|
|
203
148
|
}),
|
|
204
149
|
/* @__PURE__ */ jsx("div", { children: a.message })
|
|
205
150
|
] }, i))
|
|
206
151
|
});
|
|
207
152
|
}
|
|
208
|
-
/**
|
|
209
|
-
|
|
210
|
-
* element's accessible name, which the viewer cuts at about 45 characters. Node ids are long (a file
|
|
211
|
-
* and heading), so the name leads with the node's position in the stored graph, then its title and the
|
|
212
|
-
* view: `[<index>] <title> · <view>`. An agent reading the comment takes `graph.nodes[<index>]` from the
|
|
213
|
-
* db and checks the title.
|
|
214
|
-
*/
|
|
215
|
-
function useNodeLabels(graph, definition) {
|
|
153
|
+
/** Names each card with `cardLabel`, again whenever the map view redraws its cards. */
|
|
154
|
+
function useCardLabels(graph, definition, cardLabel) {
|
|
216
155
|
const ref = useRef(null);
|
|
217
156
|
useEffect(() => {
|
|
218
157
|
const root = ref.current;
|
|
219
|
-
if (!root || !definition) return;
|
|
220
|
-
const positions = new Map([...graph.nodes.keys()].map((id, index) => [id, index]));
|
|
221
|
-
const view = definition.id.slice(definition.id.lastIndexOf("/") + 1);
|
|
158
|
+
if (!root || !definition || !cardLabel) return;
|
|
222
159
|
const stamp = () => {
|
|
223
160
|
for (const card of root.querySelectorAll("[data-node-id]")) {
|
|
224
161
|
const node = graph.nodes.get(card.dataset.nodeId);
|
|
225
|
-
if (node) card.setAttribute("aria-label",
|
|
162
|
+
if (node) card.setAttribute("aria-label", cardLabel(node, graph, definition));
|
|
226
163
|
}
|
|
227
164
|
};
|
|
228
165
|
stamp();
|
|
@@ -232,9 +169,92 @@ function useNodeLabels(graph, definition) {
|
|
|
232
169
|
subtree: true
|
|
233
170
|
});
|
|
234
171
|
return () => observer.disconnect();
|
|
235
|
-
}, [
|
|
172
|
+
}, [
|
|
173
|
+
graph,
|
|
174
|
+
definition,
|
|
175
|
+
cardLabel
|
|
176
|
+
]);
|
|
236
177
|
return ref;
|
|
237
178
|
}
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/artifact/load.ts
|
|
181
|
+
var SPACES = "spaces";
|
|
182
|
+
var TIMEOUT_MS = 1e4;
|
|
183
|
+
/**
|
|
184
|
+
* Every space written to the artifact's `spaces` collection: the `export` command's document, keyed by space
|
|
185
|
+
* name, with its parts as JSON strings. Rejects with a message fit to show the viewer.
|
|
186
|
+
*/
|
|
187
|
+
async function loadSpaces() {
|
|
188
|
+
const claude = window.claude;
|
|
189
|
+
const db = claude ? await claude.use("db") : null;
|
|
190
|
+
if (!db) throw new Error("This page needs the artifact database, which is not available to this viewer.");
|
|
191
|
+
let timer;
|
|
192
|
+
const timeout = new Promise((_, reject) => {
|
|
193
|
+
timer = setTimeout(() => reject(/* @__PURE__ */ new Error("Reading the artifact database timed out.")), TIMEOUT_MS);
|
|
194
|
+
});
|
|
195
|
+
const spaces = (await Promise.race([db.collection(SPACES).get(), timeout]).finally(() => clearTimeout(timer))).docs.flatMap((doc) => {
|
|
196
|
+
const data = doc.data();
|
|
197
|
+
return data ? [toSpace(doc.id, data)] : [];
|
|
198
|
+
});
|
|
199
|
+
if (spaces.length === 0) throw new Error(`Nothing to show yet: no space has been written to "${SPACES}" in the artifact database.`);
|
|
200
|
+
return spaces;
|
|
201
|
+
}
|
|
202
|
+
function toSpace(space, data) {
|
|
203
|
+
const json = (field) => {
|
|
204
|
+
const value = data[field];
|
|
205
|
+
if (typeof value !== "string") throw new Error(`Space "${space}": missing "${field}" in the artifact database.`);
|
|
206
|
+
return JSON.parse(value);
|
|
207
|
+
};
|
|
208
|
+
return {
|
|
209
|
+
space,
|
|
210
|
+
schemaId: typeof data.schemaId === "string" ? data.schemaId : void 0,
|
|
211
|
+
graph: json("graph"),
|
|
212
|
+
validation: json("validation"),
|
|
213
|
+
definitions: json("definitions")
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
//#endregion
|
|
217
|
+
//#region src/artifact/main.tsx
|
|
218
|
+
function App() {
|
|
219
|
+
const [state, setState] = useState({ status: "loading" });
|
|
220
|
+
useEffect(() => {
|
|
221
|
+
loadSpaces().then((spaces) => setState({
|
|
222
|
+
status: "ready",
|
|
223
|
+
spaces
|
|
224
|
+
}), (err) => setState({
|
|
225
|
+
status: "error",
|
|
226
|
+
message: err instanceof Error ? err.message : String(err)
|
|
227
|
+
}));
|
|
228
|
+
}, []);
|
|
229
|
+
if (state.status === "loading") return /* @__PURE__ */ jsx("p", {
|
|
230
|
+
className: "viewer-message",
|
|
231
|
+
children: "Loading from the artifact database…"
|
|
232
|
+
});
|
|
233
|
+
if (state.status === "error") return /* @__PURE__ */ jsx("p", {
|
|
234
|
+
className: "viewer-message",
|
|
235
|
+
children: state.message
|
|
236
|
+
});
|
|
237
|
+
return /* @__PURE__ */ jsx(Viewer, {
|
|
238
|
+
spaces: state.spaces,
|
|
239
|
+
cardLabel: commentLabel
|
|
240
|
+
});
|
|
241
|
+
}
|
|
242
|
+
var positionsByGraph = /* @__PURE__ */ new WeakMap();
|
|
243
|
+
/**
|
|
244
|
+
* The comment mode reads a comment's location from the element's accessible name, cut at about 45
|
|
245
|
+
* characters. Node ids are long (a file and heading), so the name leads with the node's position in the
|
|
246
|
+
* stored graph, then its title and the view: `[<index>] <title> · <view>`. An agent reading the comment
|
|
247
|
+
* takes `graph.nodes[<index>]` from the db and checks the title.
|
|
248
|
+
*/
|
|
249
|
+
function commentLabel(node, graph, definition) {
|
|
250
|
+
let positions = positionsByGraph.get(graph);
|
|
251
|
+
if (!positions) {
|
|
252
|
+
positions = new Map([...graph.nodes.keys()].map((id, index) => [id, index]));
|
|
253
|
+
positionsByGraph.set(graph, positions);
|
|
254
|
+
}
|
|
255
|
+
const view = definition.id.slice(definition.id.lastIndexOf("/") + 1);
|
|
256
|
+
return `[${positions.get(node.id)}] ${node.title} · ${view}`;
|
|
257
|
+
}
|
|
238
258
|
createRoot(document.getElementById("root")).render(/* @__PURE__ */ jsx(App, {}));
|
|
239
259
|
//#endregion
|
|
240
260
|
|
package/dist/artifact.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"artifact.js","names":["_Fragment"],"sources":["../src/artifact/load.ts","../src/artifact/main.tsx"],"sourcesContent":["import type { spaceGraphFrom } from 'structured-context/browser';\nimport type { ValidationInput } from '../core/annotations';\nimport type { MapViewDefinition } from '../core/definition';\n\n/** A space as the artifact's db holds it: the `export` command's document with its parts as JSON strings. */\nexport type LoadedSpace = {\n name: string;\n schemaId: string | undefined;\n graph: Parameters<typeof spaceGraphFrom>[0];\n validation: ValidationInput;\n definitions: MapViewDefinition[];\n};\n\nconst SPACES = 'spaces';\nconst TIMEOUT_MS = 10_000;\n\ntype Db = {\n collection(path: string): { get(): Promise<{ docs: { id: string; data(): Record<string, unknown> | undefined }[] }> };\n};\n\n/** Every space written to the artifact's `spaces` collection. Rejects with a message fit to show the viewer. */\nexport async function loadSpaces(): Promise<LoadedSpace[]> {\n const claude = (window as unknown as { claude?: { use(name: string): Promise<unknown> } }).claude;\n const db = (claude ? await claude.use('db') : null) as Db | null;\n if (!db) throw new Error('This page needs the artifact database, which is not available to this viewer.');\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(() => reject(new Error('Reading the artifact database timed out.')), TIMEOUT_MS);\n });\n const snapshot = await Promise.race([db.collection(SPACES).get(), timeout]).finally(() => clearTimeout(timer));\n const spaces = snapshot.docs.flatMap((doc) => {\n const data = doc.data();\n return data ? [toSpace(doc.id, data)] : [];\n });\n if (spaces.length === 0)\n throw new Error(`Nothing to show yet: no space has been written to \"${SPACES}\" in the artifact database.`);\n return spaces;\n}\n\nfunction toSpace(name: string, data: Record<string, unknown>): LoadedSpace {\n const json = (field: string) => {\n const value = data[field];\n if (typeof value !== 'string') throw new Error(`Space \"${name}\": missing \"${field}\" in the artifact database.`);\n return JSON.parse(value);\n };\n return {\n name,\n schemaId: typeof data.schemaId === 'string' ? data.schemaId : undefined,\n graph: json('graph'),\n validation: json('validation'),\n definitions: json('definitions'),\n };\n}\n","import { useEffect, useMemo, useRef, useState } from 'react';\nimport { createRoot } from 'react-dom/client';\nimport { spaceGraphFrom } from 'structured-context/browser';\nimport { annotationsFrom } from '../core/annotations';\nimport type { MapViewDefinition, ParameterValues } from '../core/definition';\nimport { MapView } from '../layouts/MapView';\nimport { ParameterControls } from '../layouts/ParameterControls';\nimport { type LoadedSpace, loadSpaces } from './load';\n\n/**\n * The host for a Claude artifact: renders the spaces the publishing agent wrote to the artifact's\n * db (the `export` command's document, one per space) with the parameter controls and a panel of\n * validation messages. It reads nothing else and ships as `dist/artifact.js`; `dist/artifact.html`\n * is the page that loads it. See docs/architecture.md.\n */\n\ntype State = { status: 'loading' } | { status: 'error'; message: string } | { status: 'ready'; spaces: LoadedSpace[] };\n\nfunction App() {\n const [state, setState] = useState<State>({ status: 'loading' });\n useEffect(() => {\n loadSpaces().then(\n (spaces) => setState({ status: 'ready', spaces }),\n (err) => setState({ status: 'error', message: err instanceof Error ? err.message : String(err) }),\n );\n }, []);\n if (state.status === 'loading') return <p className=\"art-message\">Loading from the artifact database…</p>;\n if (state.status === 'error') return <p className=\"art-message\">{state.message}</p>;\n return <Viewer spaces={state.spaces} />;\n}\n\nfunction Viewer({ spaces }: { spaces: LoadedSpace[] }) {\n const [spaceName, setSpaceName] = useState(spaces[0]!.name);\n const space = spaces.find((s) => s.name === spaceName)!;\n const [viewId, setViewId] = useState(space.definitions[0]?.id);\n const definition = space.definitions.find((d) => d.id === viewId) ?? space.definitions[0];\n const [values, setValues] = useState<ParameterValues>({});\n const [selectedId, setSelectedId] = useState<string>();\n\n const graph = useMemo(() => spaceGraphFrom(space.graph), [space]);\n const annotated = useMemo(() => annotationsFrom(space.validation, graph), [space, graph]);\n const mapRef = useNodeLabels(graph, definition);\n\n if (!definition) return <p className=\"art-message\">No map views apply to the schema of \"{space.name}\".</p>;\n const selected = selectedId ? graph.nodes.get(selectedId as never) : undefined;\n const results = selected ? (annotated.annotations.get(selected.id as never) ?? []) : [];\n\n return (\n <div className=\"art-root\">\n <header className=\"art-bar\">\n {spaces.length > 1 && (\n <select\n aria-label=\"Space\"\n value={spaceName}\n onChange={(e) => {\n const next = spaces.find((s) => s.name === e.target.value)!;\n setSpaceName(next.name);\n setViewId(next.definitions[0]?.id);\n setValues({});\n setSelectedId(undefined);\n }}\n >\n {spaces.map((s) => (\n <option key={s.name} value={s.name}>\n {s.name}\n </option>\n ))}\n </select>\n )}\n {space.definitions.length > 1 && (\n <select\n aria-label=\"Map view\"\n value={definition.id}\n onChange={(e) => {\n setViewId(e.target.value);\n setValues({});\n }}\n >\n {space.definitions.map((d) => (\n <option key={d.id} value={d.id}>\n {d.title}\n </option>\n ))}\n </select>\n )}\n <ParameterControls\n definition={definition}\n values={values}\n onChange={(name, value) => setValues((prev) => ({ ...prev, [name]: value }))}\n />\n </header>\n <div className=\"art-body\">\n <div className=\"art-map\" ref={mapRef}>\n <MapView\n definition={definition}\n graph={graph}\n values={values}\n annotations={annotated.annotations}\n onNodeSelect={(node) => setSelectedId(node.id)}\n />\n </div>\n {(selected || annotated.unattached.length > 0) && (\n <aside className=\"art-panel\" aria-label=\"Validation results\">\n {selected && (\n <section>\n <button type=\"button\" className=\"art-close\" aria-label=\"Close\" onClick={() => setSelectedId(undefined)}>\n ×\n </button>\n <p className=\"art-type\">{selected.resolvedType}</p>\n <h2>{selected.title}</h2>\n {results.length > 0 && (\n <>\n <h3>Validation</h3>\n <Results items={results} />\n </>\n )}\n <Fields data={selected.schemaData} />\n {selected.content && (\n <>\n <h3>Content</h3>\n <p className=\"art-content\">{selected.content}</p>\n </>\n )}\n {selected.source && <p className=\"art-muted\">{selected.source.file}</p>}\n </section>\n )}\n {annotated.unattached.length > 0 && (\n <section>\n <h3>Not on a node ({annotated.unattached.length})</h3>\n <Results items={annotated.unattached} />\n </section>\n )}\n </aside>\n )}\n </div>\n </div>\n );\n}\n\nconst SKIPPED_FIELDS = new Set(['title', 'type', 'content']);\nconst isEmpty = (v: unknown) => v === undefined || v === null || v === '' || (Array.isArray(v) && v.length === 0);\nconst asText = (v: unknown): string =>\n Array.isArray(v) ? v.map(asText).join(', ') : v !== null && typeof v === 'object' ? JSON.stringify(v) : String(v);\n\n/** The node's fields as a list; the title, type and body are shown elsewhere. */\nfunction Fields({ data }: { data: Record<string, unknown> }) {\n const fields = Object.entries(data).filter(([name, value]) => !SKIPPED_FIELDS.has(name) && !isEmpty(value));\n if (fields.length === 0) return null;\n return (\n <>\n <h3>Fields</h3>\n <dl className=\"art-fields\">\n {fields.map(([name, value]) => (\n <div key={name}>\n <dt>{name}</dt>\n <dd>{asText(value)}</dd>\n </div>\n ))}\n </dl>\n </>\n );\n}\n\nfunction Results({\n items,\n}: {\n items: readonly { severity: string; source: string; ruleId?: string; message: string; nodeId?: string }[];\n}) {\n return (\n <ul className=\"art-results\">\n {items.map((a, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: a static list with no stable identity beyond position.\n <li key={i}>\n <span className={`art-severity art-${a.severity}`}>{a.severity}</span>{' '}\n <span className=\"art-muted\">{a.ruleId ? `${a.source} · ${a.ruleId}` : a.source}</span>\n {a.nodeId && <span className=\"art-muted\"> · {a.nodeId}</span>}\n <div>{a.message}</div>\n </li>\n ))}\n </ul>\n );\n}\n\n/**\n * Names each card for the viewer's comment mode, which reads the location of a comment from the\n * element's accessible name, which the viewer cuts at about 45 characters. Node ids are long (a file\n * and heading), so the name leads with the node's position in the stored graph, then its title and the\n * view: `[<index>] <title> · <view>`. An agent reading the comment takes `graph.nodes[<index>]` from the\n * db and checks the title.\n */\nfunction useNodeLabels(graph: ReturnType<typeof spaceGraphFrom>, definition: MapViewDefinition | undefined) {\n const ref = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const root = ref.current;\n if (!root || !definition) return;\n const positions = new Map([...graph.nodes.keys()].map((id, index) => [id as string, index]));\n const view = definition.id.slice(definition.id.lastIndexOf('/') + 1);\n const stamp = () => {\n for (const card of root.querySelectorAll<HTMLElement>('[data-node-id]')) {\n const node = graph.nodes.get(card.dataset.nodeId as never);\n if (node) card.setAttribute('aria-label', `[${positions.get(node.id as string)}] ${node.title} · ${view}`);\n }\n };\n stamp();\n const observer = new MutationObserver(stamp);\n observer.observe(root, { childList: true, subtree: true });\n return () => observer.disconnect();\n }, [graph, definition]);\n return ref;\n}\n\ncreateRoot(document.getElementById('root')!).render(<App />);\n"],"mappings":";;;;;;;AAaA,IAAM,SAAS;AACf,IAAM,aAAa;;AAOnB,eAAsB,aAAqC;CACzD,MAAM,SAAU,OAA2E;CAC3F,MAAM,KAAM,SAAS,MAAM,OAAO,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AAM,QAAQ,KAAK,iBAA8B,gBAAgB,GAAG;IACvE,MAAM,OAAO,MAAM,MAAM,IAAI,KAAK,QAAQ,MAAe;IACzD,IAAI,MAAM,KAAK,aAAa,cAAc,IAAI,UAAU,IAAI,KAAK,EAAY,EAAE,IAAI,KAAK,MAAM,KAAK,MAAM;GAC3G;EACF;EACA,MAAM;EACN,MAAM,WAAW,IAAI,iBAAiB,KAAK;EAC3C,SAAS,QAAQ,MAAM;GAAE,WAAW;GAAM,SAAS;EAAK,CAAC;EACzD,aAAa,SAAS,WAAW;CACnC,GAAG,CAAC,OAAO,UAAU,CAAC;CACtB,OAAO;AACT;AAEA,WAAW,SAAS,eAAe,MAAM,CAAE,CAAC,CAAC,OAAO,oBAAC,KAAD,CAAM,CAAA,CAAC"}
|
|
1
|
+
{"version":3,"file":"artifact.js","names":["_Fragment"],"sources":["../src/viewer/Viewer.tsx","../src/artifact/load.ts","../src/artifact/main.tsx"],"sourcesContent":["import { useEffect, useMemo, useRef, useState } from 'react';\nimport { type SpaceGraph, type SpaceNode, spaceGraphFrom } from 'structured-context/browser';\nimport { annotationsFrom } from '../core/annotations';\nimport type { MapViewDefinition, ParameterValues } from '../core/definition';\nimport type { SpaceSnapshot } from '../core/snapshot';\nimport { MapView } from '../layouts/MapView';\nimport { ParameterControls } from '../layouts/ParameterControls';\n\n/**\n * A page-filling viewer for one or more space snapshots: a space and map view switcher, the parameter\n * controls, the map view, and a side panel with the selected node's fields and validation results. Hosts\n * supply the snapshots and anything specific to where the page is shown. See docs/architecture.md.\n */\n\nexport type ViewerProps = {\n spaces: SpaceSnapshot[];\n /** Accessible name for each card, for hosts whose surroundings read it. Cards keep their default name without it. */\n cardLabel?: (node: SpaceNode, graph: SpaceGraph, definition: MapViewDefinition) => string;\n};\n\nexport function Viewer({ spaces, cardLabel }: ViewerProps) {\n const [spaceName, setSpaceName] = useState(spaces[0]!.space);\n const space = spaces.find((s) => s.space === spaceName)!;\n const [viewId, setViewId] = useState(space.definitions[0]?.id);\n const definition = space.definitions.find((d) => d.id === viewId) ?? space.definitions[0];\n const [values, setValues] = useState<ParameterValues>({});\n const [selectedId, setSelectedId] = useState<string>();\n\n const graph = useMemo(() => spaceGraphFrom(space.graph), [space]);\n const annotated = useMemo(() => annotationsFrom(space.validation, graph), [space, graph]);\n const mapRef = useCardLabels(graph, definition, cardLabel);\n\n if (!definition) return <p className=\"viewer-message\">No map views apply to the schema of \"{space.space}\".</p>;\n const selected = selectedId ? graph.nodes.get(selectedId as never) : undefined;\n const results = selected ? (annotated.annotations.get(selected.id as never) ?? []) : [];\n\n return (\n <div className=\"viewer-root\">\n <header className=\"viewer-bar\">\n {spaces.length > 1 && (\n <select\n aria-label=\"Space\"\n value={spaceName}\n onChange={(e) => {\n const next = spaces.find((s) => s.space === e.target.value)!;\n setSpaceName(next.space);\n setViewId(next.definitions[0]?.id);\n setValues({});\n setSelectedId(undefined);\n }}\n >\n {spaces.map((s) => (\n <option key={s.space} value={s.space}>\n {s.space}\n </option>\n ))}\n </select>\n )}\n {space.definitions.length > 1 && (\n <select\n aria-label=\"Map view\"\n value={definition.id}\n onChange={(e) => {\n setViewId(e.target.value);\n setValues({});\n }}\n >\n {space.definitions.map((d) => (\n <option key={d.id} value={d.id}>\n {d.title}\n </option>\n ))}\n </select>\n )}\n <ParameterControls\n definition={definition}\n values={values}\n onChange={(name, value) => setValues((prev) => ({ ...prev, [name]: value }))}\n />\n </header>\n <div className=\"viewer-body\">\n <div className=\"viewer-map\" ref={mapRef}>\n <MapView\n definition={definition}\n graph={graph}\n values={values}\n annotations={annotated.annotations}\n onNodeSelect={(node) => setSelectedId(node.id)}\n />\n </div>\n {(selected || annotated.unattached.length > 0) && (\n <aside className=\"viewer-panel\" aria-label=\"Validation results\">\n {selected && (\n <section>\n <button\n type=\"button\"\n className=\"viewer-close\"\n aria-label=\"Close\"\n onClick={() => setSelectedId(undefined)}\n >\n ×\n </button>\n <p className=\"viewer-type\">{selected.resolvedType}</p>\n <h2>{selected.title}</h2>\n {results.length > 0 && (\n <>\n <h3>Validation</h3>\n <Results items={results} />\n </>\n )}\n <Fields data={selected.schemaData} />\n {selected.content && (\n <>\n <h3>Content</h3>\n <p className=\"viewer-content\">{selected.content}</p>\n </>\n )}\n {selected.source && <p className=\"viewer-muted\">{selected.source.file}</p>}\n </section>\n )}\n {annotated.unattached.length > 0 && (\n <section>\n <h3>Not on a node ({annotated.unattached.length})</h3>\n <Results items={annotated.unattached} />\n </section>\n )}\n </aside>\n )}\n </div>\n </div>\n );\n}\n\nconst SKIPPED_FIELDS = new Set(['title', 'type', 'content']);\nconst isEmpty = (v: unknown) => v === undefined || v === null || v === '' || (Array.isArray(v) && v.length === 0);\nconst asText = (v: unknown): string =>\n Array.isArray(v) ? v.map(asText).join(', ') : v !== null && typeof v === 'object' ? JSON.stringify(v) : String(v);\n\n/** The node's fields as a list; the title, type and body are shown elsewhere. */\nfunction Fields({ data }: { data: Record<string, unknown> }) {\n const fields = Object.entries(data).filter(([name, value]) => !SKIPPED_FIELDS.has(name) && !isEmpty(value));\n if (fields.length === 0) return null;\n return (\n <>\n <h3>Fields</h3>\n <dl className=\"viewer-fields\">\n {fields.map(([name, value]) => (\n <div key={name}>\n <dt>{name}</dt>\n <dd>{asText(value)}</dd>\n </div>\n ))}\n </dl>\n </>\n );\n}\n\nfunction Results({\n items,\n}: {\n items: readonly { severity: string; source: string; ruleId?: string; message: string; nodeId?: string }[];\n}) {\n return (\n <ul className=\"viewer-results\">\n {items.map((a, i) => (\n // biome-ignore lint/suspicious/noArrayIndexKey: a static list with no stable identity beyond position.\n <li key={i}>\n <span className={`viewer-severity viewer-${a.severity}`}>{a.severity}</span>{' '}\n <span className=\"viewer-muted\">{a.ruleId ? `${a.source} · ${a.ruleId}` : a.source}</span>\n {a.nodeId && <span className=\"viewer-muted\"> · {a.nodeId}</span>}\n <div>{a.message}</div>\n </li>\n ))}\n </ul>\n );\n}\n\n/** Names each card with `cardLabel`, again whenever the map view redraws its cards. */\nfunction useCardLabels(\n graph: SpaceGraph,\n definition: MapViewDefinition | undefined,\n cardLabel: ViewerProps['cardLabel'],\n) {\n const ref = useRef<HTMLDivElement>(null);\n useEffect(() => {\n const root = ref.current;\n if (!root || !definition || !cardLabel) return;\n const stamp = () => {\n for (const card of root.querySelectorAll<HTMLElement>('[data-node-id]')) {\n const node = graph.nodes.get(card.dataset.nodeId as never);\n if (node) card.setAttribute('aria-label', cardLabel(node, graph, definition));\n }\n };\n stamp();\n const observer = new MutationObserver(stamp);\n observer.observe(root, { childList: true, subtree: true });\n return () => observer.disconnect();\n }, [graph, definition, cardLabel]);\n return ref;\n}\n","import type { SpaceSnapshot } from '../core/snapshot';\n\nconst SPACES = 'spaces';\nconst TIMEOUT_MS = 10_000;\n\ntype Db = {\n collection(path: string): { get(): Promise<{ docs: { id: string; data(): Record<string, unknown> | undefined }[] }> };\n};\n\n/**\n * Every space written to the artifact's `spaces` collection: the `export` command's document, keyed by space\n * name, with its parts as JSON strings. Rejects with a message fit to show the viewer.\n */\nexport async function loadSpaces(): Promise<SpaceSnapshot[]> {\n const claude = (window as unknown as { claude?: { use(name: string): Promise<unknown> } }).claude;\n const db = (claude ? await claude.use('db') : null) as Db | null;\n if (!db) throw new Error('This page needs the artifact database, which is not available to this viewer.');\n\n let timer: ReturnType<typeof setTimeout> | undefined;\n const timeout = new Promise<never>((_, reject) => {\n timer = setTimeout(() => reject(new Error('Reading the artifact database timed out.')), TIMEOUT_MS);\n });\n const snapshot = await Promise.race([db.collection(SPACES).get(), timeout]).finally(() => clearTimeout(timer));\n const spaces = snapshot.docs.flatMap((doc) => {\n const data = doc.data();\n return data ? [toSpace(doc.id, data)] : [];\n });\n if (spaces.length === 0)\n throw new Error(`Nothing to show yet: no space has been written to \"${SPACES}\" in the artifact database.`);\n return spaces;\n}\n\nfunction toSpace(space: string, data: Record<string, unknown>): SpaceSnapshot {\n const json = (field: string) => {\n const value = data[field];\n if (typeof value !== 'string') throw new Error(`Space \"${space}\": missing \"${field}\" in the artifact database.`);\n return JSON.parse(value);\n };\n return {\n space,\n schemaId: typeof data.schemaId === 'string' ? data.schemaId : undefined,\n graph: json('graph'),\n validation: json('validation'),\n definitions: json('definitions'),\n };\n}\n","import { useEffect, useState } from 'react';\nimport { createRoot } from 'react-dom/client';\nimport type { SpaceGraph, SpaceNode } from 'structured-context/browser';\nimport type { MapViewDefinition } from '../core/definition';\nimport type { SpaceSnapshot } from '../core/snapshot';\nimport { Viewer } from '../viewer/Viewer';\nimport { loadSpaces } from './load';\n\n/**\n * The host for a Claude artifact: shows the spaces the publishing agent wrote to the artifact's db in the\n * viewer, and names cards for the artifact's comment mode. It ships as `dist/artifact.js`;\n * `dist/artifact.html` is the page that loads it. See docs/architecture.md.\n */\n\ntype State =\n | { status: 'loading' }\n | { status: 'error'; message: string }\n | { status: 'ready'; spaces: SpaceSnapshot[] };\n\nfunction App() {\n const [state, setState] = useState<State>({ status: 'loading' });\n useEffect(() => {\n loadSpaces().then(\n (spaces) => setState({ status: 'ready', spaces }),\n (err) => setState({ status: 'error', message: err instanceof Error ? err.message : String(err) }),\n );\n }, []);\n if (state.status === 'loading') return <p className=\"viewer-message\">Loading from the artifact database…</p>;\n if (state.status === 'error') return <p className=\"viewer-message\">{state.message}</p>;\n return <Viewer spaces={state.spaces} cardLabel={commentLabel} />;\n}\n\nconst positionsByGraph = new WeakMap<SpaceGraph, Map<string, number>>();\n\n/**\n * The comment mode reads a comment's location from the element's accessible name, cut at about 45\n * characters. Node ids are long (a file and heading), so the name leads with the node's position in the\n * stored graph, then its title and the view: `[<index>] <title> · <view>`. An agent reading the comment\n * takes `graph.nodes[<index>]` from the db and checks the title.\n */\nfunction commentLabel(node: SpaceNode, graph: SpaceGraph, definition: MapViewDefinition): string {\n let positions = positionsByGraph.get(graph);\n if (!positions) {\n positions = new Map([...graph.nodes.keys()].map((id, index) => [id as string, index]));\n positionsByGraph.set(graph, positions);\n }\n const view = definition.id.slice(definition.id.lastIndexOf('/') + 1);\n return `[${positions.get(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AAE,QAAQ;GAAS;EAAO,CAAC,IAC/C,QAAQ,SAAS;GAAE,QAAQ;GAAS,SAAS,eAAe,QAAQ,IAAI,UAAU,OAAO,GAAG;EAAE,CAAC,CAClG;CACF,GAAG,CAAC,CAAC;CACL,IAAI,MAAM,WAAW,WAAW,OAAO,oBAAC,KAAD;EAAG,WAAU;EAAiB,UAAA;CAAsC,CAAA;CAC3G,IAAI,MAAM,WAAW,SAAS,OAAO,oBAAC,KAAD;EAAG,WAAU;EAAkB,UAAA,MAAM;CAAW,CAAA;CACrF,OAAO,oBAAC,QAAD;EAAQ,QAAQ,MAAM;EAAQ,WAAW;CAAe,CAAA;AACjE;AAEA,IAAM,mCAAmB,IAAI,QAAyC;;;;;;;AAQtE,SAAS,aAAa,MAAiB,OAAmB,YAAuC;CAC/F,IAAI,YAAY,iBAAiB,IAAI,KAAK;CAC1C,IAAI,CAAC,WAAW;EACd,YAAY,IAAI,IAAI,CAAC,GAAG,MAAM,MAAM,KAAK,CAAC,CAAC,CAAC,KAAK,IAAI,UAAU,CAAC,IAAc,KAAK,CAAC,CAAC;EACrF,iBAAiB,IAAI,OAAO,SAAS;CACvC;CACA,MAAM,OAAO,WAAW,GAAG,MAAM,WAAW,GAAG,YAAY,GAAG,IAAI,CAAC;CACnE,OAAO,IAAI,UAAU,IAAI,KAAK,EAAY,EAAE,IAAI,KAAK,MAAM,KAAK;AAClE;AAEA,WAAW,SAAS,eAAe,MAAM,CAAE,CAAC,CAAC,OAAO,oBAAC,KAAD,CAAM,CAAA,CAAC"}
|
package/dist/cli.js
CHANGED
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
#!/usr/bin/env bun
|
|
2
2
|
import { n as mapViewsForSchema } from "./definition-Cp1CCigh.js";
|
|
3
|
-
import { t as loadMapViewDefinitions } from "./node-
|
|
4
|
-
import {
|
|
5
|
-
import { SctxError, assembleSpaceGraph, createSpaceContext, exportSpaceGraph, loadConfig, nodeIssues, resolveConfigPath, setConfigPath, validateSpace } from "structured-context/api";
|
|
3
|
+
import { t as loadMapViewDefinitions } from "./node-aizYAYlq.js";
|
|
4
|
+
import { SctxError, assembleSpaceGraph, createSpaceContext, exportSpaceGraph, loadConfig, resolveConfigPath, setConfigPath, validateSpace } from "structured-context/api";
|
|
6
5
|
import { Command } from "commander";
|
|
7
6
|
var package_default = {
|
|
8
7
|
name: "structured-context-map-views",
|
|
9
|
-
version: "0.
|
|
8
|
+
version: "0.6.1",
|
|
10
9
|
description: "Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.",
|
|
11
10
|
license: "MIT",
|
|
12
11
|
type: "module",
|
|
@@ -35,26 +34,31 @@ var package_default = {
|
|
|
35
34
|
"types": "./dist/types/node/index.d.ts",
|
|
36
35
|
"default": "./dist/node.js"
|
|
37
36
|
},
|
|
38
|
-
"./styles.css": "./dist/styles.css"
|
|
37
|
+
"./styles.css": "./dist/styles.css",
|
|
38
|
+
"./page.html": {
|
|
39
|
+
"types": "./dist/page.html.d.ts",
|
|
40
|
+
"default": "./dist/page.html"
|
|
41
|
+
}
|
|
39
42
|
},
|
|
40
43
|
scripts: {
|
|
41
44
|
"clean": "rm -rf dist",
|
|
42
45
|
"generate": "bun run generate:schemas && bun run generate:definitions",
|
|
43
46
|
"generate:schemas": "bun scripts/generate-schemas.ts",
|
|
44
47
|
"generate:definitions": "bun scripts/generate-definitions.ts",
|
|
45
|
-
"build": "bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/layouts/styles.css -o dist/styles.css && bun scripts/build-
|
|
48
|
+
"build:library": "bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/layouts/styles.css -o dist/styles.css && bun scripts/build-page.ts",
|
|
49
|
+
"build": "bun run build:library && bun scripts/build-artifact-page.ts",
|
|
46
50
|
"typecheck": "tsc --noEmit",
|
|
47
51
|
"capture-fixtures": "bun scripts/capture-fixtures.ts",
|
|
48
52
|
"test": "bun test",
|
|
49
53
|
"test:package": "bash scripts/test-package.sh",
|
|
50
54
|
"prepublishOnly": "bun run build",
|
|
51
|
-
"preversion": "bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run test:package",
|
|
55
|
+
"preversion": "bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run --cwd ../.. test:package",
|
|
52
56
|
"version": "bun run generate:schemas --release && git add -A"
|
|
53
57
|
},
|
|
54
58
|
peerDependencies: {
|
|
55
59
|
"react": "^19.3.0",
|
|
56
60
|
"react-dom": "^19.3.0",
|
|
57
|
-
"structured-context": "^0.
|
|
61
|
+
"structured-context": "^0.24.0"
|
|
58
62
|
},
|
|
59
63
|
dependencies: {
|
|
60
64
|
"ajv": "^8.20.0",
|
|
@@ -70,7 +74,7 @@ var package_default = {
|
|
|
70
74
|
"@vitejs/plugin-react": "^6.1.1",
|
|
71
75
|
"react": "^19.3.0",
|
|
72
76
|
"react-dom": "^19.3.0",
|
|
73
|
-
"structured-context": "^0.
|
|
77
|
+
"structured-context": "^0.24.0",
|
|
74
78
|
"tailwindcss": "^4.3.3",
|
|
75
79
|
"vite": "^8.3.2"
|
|
76
80
|
}
|
|
@@ -90,10 +94,7 @@ async function exportSnapshot(spaceName, config, configDir, validateOptions = {}
|
|
|
90
94
|
space: spaceName,
|
|
91
95
|
schemaId,
|
|
92
96
|
graph: exportSpaceGraph(graph.nodes.values(), context.schema.metadata),
|
|
93
|
-
validation: {
|
|
94
|
-
issues: nodeIssues(validation, validateOptions),
|
|
95
|
-
ruleViolations: validation.ruleViolations
|
|
96
|
-
},
|
|
97
|
+
validation: { issues: validation.issues },
|
|
97
98
|
definitions: mapViewsForSchema(loadMapViewDefinitions(config, { configDir }), schemaId)
|
|
98
99
|
};
|
|
99
100
|
}
|
|
@@ -104,7 +105,9 @@ program.name("structured-context-map-views").description("Map view tools for str
|
|
|
104
105
|
program.command("export").description("Print a JSON snapshot of a space: its graph, validation results and map view definitions").argument("<space-name>", "Space name").option("--depth <n>", "Validate only hierarchy nodes within N levels from the top", (v) => parseInt(v, 10)).option("--include-gated", "Evaluate rules even on nodes gated by an upstream failure").option("--rule-filter <dimension=values>", "Evaluate only matching rules; dimensions: category, severity, type, id (repeatable, e.g. severity=error)", (v, prev = []) => [...prev, v]).option("--semantic [provider]", "Evaluate semantic rules, with the configured model provider or the one named").action(async (spaceName, options) => {
|
|
105
106
|
setConfigPath(program.opts().config);
|
|
106
107
|
try {
|
|
107
|
-
const
|
|
108
|
+
const config = loadConfig();
|
|
109
|
+
const configDir = resolveConfigPath().root;
|
|
110
|
+
const result = await exportSnapshot(spaceName, config, configDir, options);
|
|
108
111
|
process.stdout.write(`${JSON.stringify(result)}\n`);
|
|
109
112
|
} catch (err) {
|
|
110
113
|
if (!(err instanceof SctxError)) throw err;
|
package/dist/cli.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"cli.js","names":["packageJson"],"sources":["../package.json","../src/node/snapshot.ts","../src/node/cli.ts"],"sourcesContent":["{\n \"name\": \"structured-context-map-views\",\n \"version\": \"0.
|
|
1
|
+
{"version":3,"file":"cli.js","names":["packageJson"],"sources":["../package.json","../src/node/snapshot.ts","../src/node/cli.ts"],"sourcesContent":["{\n \"name\": \"structured-context-map-views\",\n \"version\": \"0.6.1\",\n \"description\": \"Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.\",\n \"license\": \"MIT\",\n \"type\": \"module\",\n \"repository\": {\n \"type\": \"git\",\n \"url\": \"git+https://github.com/mindsocket/structured-context-map-views.git\",\n \"directory\": \"packages/map-views\"\n },\n \"homepage\": \"https://github.com/mindsocket/structured-context-map-views#readme\",\n \"bugs\": \"https://github.com/mindsocket/structured-context-map-views/issues\",\n \"keywords\": [\n \"structured-context\",\n \"visualisation\",\n \"map-view\",\n \"react\"\n ],\n \"files\": [\n \"dist/\"\n ],\n \"sideEffects\": false,\n \"bin\": {\n \"structured-context-map-views\": \"dist/cli.js\"\n },\n \"exports\": {\n \".\": {\n \"types\": \"./dist/types/index.d.ts\",\n \"default\": \"./dist/index.js\"\n },\n \"./node\": {\n \"types\": \"./dist/types/node/index.d.ts\",\n \"default\": \"./dist/node.js\"\n },\n \"./styles.css\": \"./dist/styles.css\",\n \"./page.html\": {\n \"types\": \"./dist/page.html.d.ts\",\n \"default\": \"./dist/page.html\"\n }\n },\n \"scripts\": {\n \"clean\": \"rm -rf dist\",\n \"generate\": \"bun run generate:schemas && bun run generate:definitions\",\n \"generate:schemas\": \"bun scripts/generate-schemas.ts\",\n \"generate:definitions\": \"bun scripts/generate-definitions.ts\",\n \"build:library\": \"bun run clean && bun run generate && bun --bun vite build && tsc -p tsconfig.build.json && tailwindcss -i src/layouts/styles.css -o dist/styles.css && bun scripts/build-page.ts\",\n \"build\": \"bun run build:library && bun scripts/build-artifact-page.ts\",\n \"typecheck\": \"tsc --noEmit\",\n \"capture-fixtures\": \"bun scripts/capture-fixtures.ts\",\n \"test\": \"bun test\",\n \"test:package\": \"bash scripts/test-package.sh\",\n \"prepublishOnly\": \"bun run build\",\n \"preversion\": \"bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run --cwd ../.. test:package\",\n \"version\": \"bun run generate:schemas --release && git add -A\"\n },\n \"peerDependencies\": {\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.24.0\"\n },\n \"dependencies\": {\n \"ajv\": \"^8.20.0\",\n \"commander\": \"^15.0.0\",\n \"json-schema-to-ts\": \"^3.1.1\",\n \"json5\": \"^2.2.3\"\n },\n \"devDependencies\": {\n \"@tailwindcss/cli\": \"^4.3.3\",\n \"@types/node\": \"^22.20.5\",\n \"@types/react\": \"^19.3.0\",\n \"@types/react-dom\": \"^19.3.0\",\n \"@vitejs/plugin-react\": \"^6.1.1\",\n \"react\": \"^19.3.0\",\n \"react-dom\": \"^19.3.0\",\n \"structured-context\": \"^0.24.0\",\n \"tailwindcss\": \"^4.3.3\",\n \"vite\": \"^8.3.2\"\n }\n}\n","import {\n assembleSpaceGraph,\n type Config,\n createSpaceContext,\n exportSpaceGraph,\n validateSpace,\n} from 'structured-context/api';\nimport { mapViewsForSchema } from '../core/definition';\nimport type { SpaceSnapshot } from '../core/snapshot';\nimport { loadMapViewDefinitions } from './index';\n\n/** The `validateSpace` options `export` passes through unchanged. */\nexport type ExportValidateOptions = Pick<\n NonNullable<Parameters<typeof validateSpace>[1]>,\n 'depth' | 'includeGated' | 'semantic' | 'ruleFilter'\n>;\n\n/**\n * Node-only: snapshot a space for a browser-only host. Validation is structured-context's own\n * `validateSpace`, which also decides whether a judge runs.\n */\nexport async function exportSnapshot(\n spaceName: string,\n config: Config,\n configDir?: string,\n validateOptions: ExportValidateOptions = {},\n): Promise<SpaceSnapshot> {\n const context = createSpaceContext(spaceName, config);\n const graph = await assembleSpaceGraph(context, {});\n const schemaId = context.schema.$id;\n const validation = await validateSpace(context, validateOptions);\n return {\n space: spaceName,\n schemaId,\n graph: exportSpaceGraph(graph.nodes.values(), context.schema.metadata),\n validation: { issues: validation.issues },\n definitions: mapViewsForSchema(loadMapViewDefinitions(config, { configDir }), schemaId),\n };\n}\n","#!/usr/bin/env bun\nimport { Command } from 'commander';\nimport { loadConfig, resolveConfigPath, SctxError, setConfigPath } from 'structured-context/api';\nimport packageJson from '../../package.json' with { type: 'json' };\nimport { type ExportValidateOptions, exportSnapshot } from './snapshot';\n\nconst program = new Command();\n\nprogram\n .name('structured-context-map-views')\n .description('Map view tools for structured-context spaces')\n .version(packageJson.version)\n .option('--config <path>', 'Path to config file (overrides config discovery)');\n\nprogram\n .command('export')\n .description('Print a JSON snapshot of a space: its graph, validation results and map view definitions')\n .argument('<space-name>', 'Space name')\n .option('--depth <n>', 'Validate only hierarchy nodes within N levels from the top', (v) => parseInt(v, 10))\n .option('--include-gated', 'Evaluate rules even on nodes gated by an upstream failure')\n .option(\n '--rule-filter <dimension=values>',\n 'Evaluate only matching rules; dimensions: category, severity, type, id (repeatable, e.g. severity=error)',\n (v: string, prev: string[] = []) => [...prev, v],\n )\n .option('--semantic [provider]', 'Evaluate semantic rules, with the configured model provider or the one named')\n .action(async (spaceName: string, options: ExportValidateOptions) => {\n setConfigPath(program.opts().config);\n try {\n const config = loadConfig();\n const configDir = resolveConfigPath().root;\n const result = await exportSnapshot(spaceName, config, configDir, options);\n process.stdout.write(`${JSON.stringify(result)}\\n`);\n } catch (err) {\n if (!(err instanceof SctxError)) throw err;\n console.error(`${err.code}: ${err.message}`);\n process.exitCode = 1;\n }\n });\n\nawait program.parseAsync();\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;ACqBA,eAAsB,eACpB,WACA,QACA,WACA,kBAAyC,CAAC,GAClB;CACxB,MAAM,UAAU,mBAAmB,WAAW,MAAM;CACpD,MAAM,QAAQ,MAAM,mBAAmB,SAAS,CAAC,CAAC;CAClD,MAAM,WAAW,QAAQ,OAAO;CAChC,MAAM,aAAa,MAAM,cAAc,SAAS,eAAe;CAC/D,OAAO;EACL,OAAO;EACP;EACA,OAAO,iBAAiB,MAAM,MAAM,OAAO,GAAG,QAAQ,OAAO,QAAQ;EACrE,YAAY,EAAE,QAAQ,WAAW,OAAO;EACxC,aAAa,kBAAkB,uBAAuB,QAAQ,EAAE,UAAU,CAAC,GAAG,QAAQ;CACxF;AACF;;;AChCA,IAAM,UAAU,IAAI,QAAQ;AAE5B,QACG,KAAK,8BAA8B,CAAC,CACpC,YAAY,8CAA8C,CAAC,CAC3D,QAAQA,gBAAY,OAAO,CAAC,CAC5B,OAAO,mBAAmB,kDAAkD;AAE/E,QACG,QAAQ,QAAQ,CAAC,CACjB,YAAY,0FAA0F,CAAC,CACvG,SAAS,gBAAgB,YAAY,CAAC,CACtC,OAAO,eAAe,+DAA+D,MAAM,SAAS,GAAG,EAAE,CAAC,CAAC,CAC3G,OAAO,mBAAmB,2DAA2D,CAAC,CACtF,OACC,oCACA,6GACC,GAAW,OAAiB,CAAC,MAAM,CAAC,GAAG,MAAM,CAAC,CACjD,CAAC,CACA,OAAO,yBAAyB,8EAA8E,CAAC,CAC/G,OAAO,OAAO,WAAmB,YAAmC;CACnE,cAAc,QAAQ,KAAK,CAAC,CAAC,MAAM;CACnC,IAAI;EACF,MAAM,SAAS,WAAW;EAC1B,MAAM,YAAY,kBAAkB,CAAC,CAAC;EACtC,MAAM,SAAS,MAAM,eAAe,WAAW,QAAQ,WAAW,OAAO;EACzE,QAAQ,OAAO,MAAM,GAAG,KAAK,UAAU,MAAM,EAAE,GAAG;CACpD,SAAS,KAAK;EACZ,IAAI,EAAE,eAAe,YAAY,MAAM;EACvC,QAAQ,MAAM,GAAG,IAAI,KAAK,IAAI,IAAI,SAAS;EAC3C,QAAQ,WAAW;CACrB;AACF,CAAC;AAEH,MAAM,QAAQ,WAAW"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { a as annotationsFrom, r as buildTree, s as worstSeverity } from "./projection-
|
|
1
|
+
import { a as annotationsFrom, r as buildTree, s as worstSeverity } from "./projection-C-dATsdO.js";
|
|
2
2
|
import { c as MAP_VIEW_SCHEMAS, i as resolveParameterValues, n as mapViewsForSchema, o as selectionFilter, r as parseMapViewDefinition, s as viewValidationLevel, t as MapViewDefinitionError } from "./definition-Cp1CCigh.js";
|
|
3
|
-
import { a as SelectParameterInput, i as ParameterInput, n as useParameterControls, o as ToggleParameterInput, r as MultiSelectParameterInput, s as MapView, t as ParameterControls } from "./ParameterControls
|
|
3
|
+
import { a as SelectParameterInput, i as ParameterInput, n as useParameterControls, o as ToggleParameterInput, r as MultiSelectParameterInput, s as MapView, t as ParameterControls } from "./ParameterControls-A1HJWyt9.js";
|
|
4
4
|
export { MAP_VIEW_SCHEMAS, MapView, MapViewDefinitionError, MultiSelectParameterInput, ParameterControls, ParameterInput, SelectParameterInput, ToggleParameterInput, annotationsFrom, buildTree, mapViewsForSchema, parseMapViewDefinition, resolveParameterValues, selectionFilter, useParameterControls, viewValidationLevel, worstSeverity };
|