structured-context-map-views 0.6.0 → 0.6.2
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/artifact.html +29 -29
- package/dist/artifact.js +114 -94
- package/dist/artifact.js.map +1 -1
- package/dist/cli.js +19 -9
- package/dist/cli.js.map +1 -1
- package/dist/html.js +19 -0
- package/dist/html.js.map +1 -0
- package/dist/node-B0VWZju6.js +78 -0
- package/dist/node-B0VWZju6.js.map +1 -0
- package/dist/node.js +1 -1
- package/dist/page.html +640 -0
- package/dist/page.html.d.ts +2 -0
- package/dist/read-definitions-DNcsxgXM.js +46 -0
- package/dist/read-definitions-DNcsxgXM.js.map +1 -0
- package/dist/types/artifact/load.d.ts +6 -13
- package/dist/types/core/snapshot.d.ts +15 -0
- package/dist/types/node/html.d.ts +6 -0
- package/dist/types/node/index.d.ts +4 -4
- package/dist/types/node/page.d.ts +7 -0
- package/dist/types/node/read-definitions.d.ts +17 -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 +15 -6
- package/dist/node-Co_JiEZV.js +0 -106
- package/dist/node-Co_JiEZV.js.map +0 -1
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { r as parseMapViewDefinition } from "./definition-Cp1CCigh.js";
|
|
2
|
+
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
//#region src/node/bundled-definitions.ts
|
|
5
|
+
var BUNDLED_DEFINITIONS = { "strategy-tree.json5": "// Strategy stack as a tree: vision → mission → goals → opportunities → solutions → experiments.\n{\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\n $id: 'sctx-map-view://core/strategy-tree',\n title: 'Strategy tree',\n schema: 'sctx://core/strategy_general',\n parameters: {\n orientation: { $ref: 'settings.json#/$defs/orientation', default: 'vertical' },\n nodeStyle: { $ref: 'settings.json#/$defs/nodeStyle', default: 'card' },\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\n cardFields: {\n title: 'Card fields',\n type: 'array',\n items: { enum: ['status', 'priority', 'summary'] },\n default: ['status'],\n },\n },\n regions: [\n {\n id: 'main',\n layout: { type: 'tree', orientation: { $param: 'orientation' } },\n nodes: { style: { $param: 'nodeStyle' }, fields: { $param: 'cardFields' }, validation: { $param: 'validation' } },\n edges: { show: true },\n },\n ],\n}\n" };
|
|
6
|
+
//#endregion
|
|
7
|
+
//#region src/node/read-definitions.ts
|
|
8
|
+
var SCHEME = "sctx-map-view://";
|
|
9
|
+
var PACKAGE_NAME = "structured-context-map-views";
|
|
10
|
+
/**
|
|
11
|
+
* Definitions in `folders` and this package's embedded ones, each checked against the namespace of its source.
|
|
12
|
+
* Throws on the first invalid definition or a repeated id.
|
|
13
|
+
*/
|
|
14
|
+
function readDefinitionFolders(folders) {
|
|
15
|
+
const foundAt = /* @__PURE__ */ new Map();
|
|
16
|
+
const definitions = [];
|
|
17
|
+
const add = (label, text, source) => {
|
|
18
|
+
const definition = parseMapViewDefinition(label, text);
|
|
19
|
+
assertIdNamespace(definition.id, source, label);
|
|
20
|
+
const existing = foundAt.get(definition.id);
|
|
21
|
+
if (existing) throw new Error(`Map view id "${definition.id}" is defined by both ${existing} and ${label}.`);
|
|
22
|
+
foundAt.set(definition.id, label);
|
|
23
|
+
definitions.push(definition);
|
|
24
|
+
};
|
|
25
|
+
for (const [file, text] of Object.entries(BUNDLED_DEFINITIONS)) add(`${PACKAGE_NAME}/${file}`, text, { kind: "core" });
|
|
26
|
+
for (const { dir, source } of folders) {
|
|
27
|
+
if (!isDirectory(dir)) continue;
|
|
28
|
+
for (const file of readdirSync(dir).filter((f) => f.endsWith(".json5")).sort()) {
|
|
29
|
+
const path = join(dir, file);
|
|
30
|
+
add(path, readFileSync(path, "utf8"), source);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
return definitions;
|
|
34
|
+
}
|
|
35
|
+
function assertIdNamespace(id, source, path) {
|
|
36
|
+
const segments = id.slice(16).split("/");
|
|
37
|
+
const expected = source.kind === "core" ? `${SCHEME}core/<name>` : source.kind === "plugin" ? `${SCHEME}${source.plugin}/<name>` : `${SCHEME}<name>`;
|
|
38
|
+
if (!(source.kind === "config" ? segments.length === 1 : segments.length === 2 && segments[0] === (source.kind === "core" ? "core" : source.plugin)) || source.kind === "plugin" && source.plugin === "core") throw new Error(`Map view namespace violation: ${path} has $id "${id}". Use the form "${expected}".`);
|
|
39
|
+
}
|
|
40
|
+
function isDirectory(path) {
|
|
41
|
+
return existsSync(path) && statSync(path).isDirectory();
|
|
42
|
+
}
|
|
43
|
+
//#endregion
|
|
44
|
+
export { readDefinitionFolders as t };
|
|
45
|
+
|
|
46
|
+
//# sourceMappingURL=read-definitions-DNcsxgXM.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"read-definitions-DNcsxgXM.js","names":[],"sources":["../src/node/bundled-definitions.ts","../src/node/read-definitions.ts"],"sourcesContent":["// Generated by scripts/generate-definitions.ts from map-views/*.json5. Do not edit.\nexport const BUNDLED_DEFINITIONS: Record<string, string> = {\n \"strategy-tree.json5\": \"// Strategy stack as a tree: vision → mission → goals → opportunities → solutions → experiments.\\n{\\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\\n $id: 'sctx-map-view://core/strategy-tree',\\n title: 'Strategy tree',\\n schema: 'sctx://core/strategy_general',\\n parameters: {\\n orientation: { $ref: 'settings.json#/$defs/orientation', default: 'vertical' },\\n nodeStyle: { $ref: 'settings.json#/$defs/nodeStyle', default: 'card' },\\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\\n cardFields: {\\n title: 'Card fields',\\n type: 'array',\\n items: { enum: ['status', 'priority', 'summary'] },\\n default: ['status'],\\n },\\n },\\n regions: [\\n {\\n id: 'main',\\n layout: { type: 'tree', orientation: { $param: 'orientation' } },\\n nodes: { style: { $param: 'nodeStyle' }, fields: { $param: 'cardFields' }, validation: { $param: 'validation' } },\\n edges: { show: true },\\n },\\n ],\\n}\\n\",\n};\n","import { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { join } from 'node:path';\nimport { type MapViewDefinition, parseMapViewDefinition } from '../core/definition';\nimport { BUNDLED_DEFINITIONS } from './bundled-definitions';\n\nconst SCHEME = 'sctx-map-view://';\nconst PACKAGE_NAME = 'structured-context-map-views';\n\nexport type DefinitionSource = { kind: 'core' } | { kind: 'plugin'; plugin: string } | { kind: 'config' };\n\n/**\n * Definitions in `folders` and this package's embedded ones, each checked against the namespace of its source.\n * Throws on the first invalid definition or a repeated id.\n */\nexport function readDefinitionFolders(folders: { dir: string; source: DefinitionSource }[]): MapViewDefinition[] {\n const foundAt = new Map<string, string>();\n const definitions: MapViewDefinition[] = [];\n const add = (label: string, text: string, source: DefinitionSource) => {\n const definition = parseMapViewDefinition(label, text);\n assertIdNamespace(definition.id, source, label);\n const existing = foundAt.get(definition.id);\n if (existing) throw new Error(`Map view id \"${definition.id}\" is defined by both ${existing} and ${label}.`);\n foundAt.set(definition.id, label);\n definitions.push(definition);\n };\n\n for (const [file, text] of Object.entries(BUNDLED_DEFINITIONS))\n add(`${PACKAGE_NAME}/${file}`, text, { kind: 'core' });\n for (const { dir, source } of folders) {\n if (!isDirectory(dir)) continue;\n for (const file of readdirSync(dir)\n .filter((f) => f.endsWith('.json5'))\n .sort()) {\n const path = join(dir, file);\n add(path, readFileSync(path, 'utf8'), source);\n }\n }\n return definitions;\n}\n\nfunction assertIdNamespace(id: string, source: DefinitionSource, path: string): void {\n const segments = id.slice(SCHEME.length).split('/');\n const expected =\n source.kind === 'core'\n ? `${SCHEME}core/<name>`\n : source.kind === 'plugin'\n ? `${SCHEME}${source.plugin}/<name>`\n : `${SCHEME}<name>`;\n const ok =\n source.kind === 'config'\n ? segments.length === 1\n : segments.length === 2 && segments[0] === (source.kind === 'core' ? 'core' : source.plugin);\n if (!ok || (source.kind === 'plugin' && source.plugin === 'core')) {\n throw new Error(`Map view namespace violation: ${path} has $id \"${id}\". Use the form \"${expected}\".`);\n }\n}\n\nfunction isDirectory(path: string): boolean {\n return existsSync(path) && statSync(path).isDirectory();\n}\n"],"mappings":";;;;AACA,IAAa,sBAA8C,EACzD,uBAAuB,8iCACzB;;;ACEA,IAAM,SAAS;AACf,IAAM,eAAe;;;;;AAQrB,SAAgB,sBAAsB,SAA2E;CAC/G,MAAM,0BAAU,IAAI,IAAoB;CACxC,MAAM,cAAmC,CAAC;CAC1C,MAAM,OAAO,OAAe,MAAc,WAA6B;EACrE,MAAM,aAAa,uBAAuB,OAAO,IAAI;EACrD,kBAAkB,WAAW,IAAI,QAAQ,KAAK;EAC9C,MAAM,WAAW,QAAQ,IAAI,WAAW,EAAE;EAC1C,IAAI,UAAU,MAAM,IAAI,MAAM,gBAAgB,WAAW,GAAG,uBAAuB,SAAS,OAAO,MAAM,EAAE;EAC3G,QAAQ,IAAI,WAAW,IAAI,KAAK;EAChC,YAAY,KAAK,UAAU;CAC7B;CAEA,KAAK,MAAM,CAAC,MAAM,SAAS,OAAO,QAAQ,mBAAmB,GAC3D,IAAI,GAAG,aAAa,GAAG,QAAQ,MAAM,EAAE,MAAM,OAAO,CAAC;CACvD,KAAK,MAAM,EAAE,KAAK,YAAY,SAAS;EACrC,IAAI,CAAC,YAAY,GAAG,GAAG;EACvB,KAAK,MAAM,QAAQ,YAAY,GAAG,CAAC,CAChC,QAAQ,MAAM,EAAE,SAAS,QAAQ,CAAC,CAAC,CACnC,KAAK,GAAG;GACT,MAAM,OAAO,KAAK,KAAK,IAAI;GAC3B,IAAI,MAAM,aAAa,MAAM,MAAM,GAAG,MAAM;EAC9C;CACF;CACA,OAAO;AACT;AAEA,SAAS,kBAAkB,IAAY,QAA0B,MAAoB;CACnF,MAAM,WAAW,GAAG,MAAM,EAAa,CAAC,CAAC,MAAM,GAAG;CAClD,MAAM,WACJ,OAAO,SAAS,SACZ,GAAG,OAAO,eACV,OAAO,SAAS,WACd,GAAG,SAAS,OAAO,OAAO,WAC1B,GAAG,OAAO;CAKlB,IAAI,EAHF,OAAO,SAAS,WACZ,SAAS,WAAW,IACpB,SAAS,WAAW,KAAK,SAAS,QAAQ,OAAO,SAAS,SAAS,SAAS,OAAO,YAC7E,OAAO,SAAS,YAAY,OAAO,WAAW,QACxD,MAAM,IAAI,MAAM,iCAAiC,KAAK,YAAY,GAAG,mBAAmB,SAAS,GAAG;AAExG;AAEA,SAAS,YAAY,MAAuB;CAC1C,OAAO,WAAW,IAAI,KAAK,SAAS,IAAI,CAAC,CAAC,YAAY;AACxD"}
|
|
@@ -1,13 +1,6 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
schemaId: string | undefined;
|
|
8
|
-
graph: Parameters<typeof spaceGraphFrom>[0];
|
|
9
|
-
validation: ValidationInput;
|
|
10
|
-
definitions: MapViewDefinition[];
|
|
11
|
-
};
|
|
12
|
-
/** Every space written to the artifact's `spaces` collection. Rejects with a message fit to show the viewer. */
|
|
13
|
-
export declare function loadSpaces(): Promise<LoadedSpace[]>;
|
|
1
|
+
import type { SpaceSnapshot } from '../core/snapshot';
|
|
2
|
+
/**
|
|
3
|
+
* Every space written to the artifact's `spaces` collection: the `export` command's document, keyed by space
|
|
4
|
+
* name, with its parts as JSON strings. Rejects with a message fit to show the viewer.
|
|
5
|
+
*/
|
|
6
|
+
export declare function loadSpaces(): Promise<SpaceSnapshot[]>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { spaceGraphFrom } from 'structured-context/browser';
|
|
2
|
+
import type { ValidationInput } from './annotations';
|
|
3
|
+
import type { MapViewDefinition } from './definition';
|
|
4
|
+
/**
|
|
5
|
+
* Everything a host without filesystem access needs to render a space: its graph, the validation
|
|
6
|
+
* results that attach to nodes, and the map view definitions that apply to its schema. Plain JSON.
|
|
7
|
+
*/
|
|
8
|
+
export type SpaceSnapshot = {
|
|
9
|
+
space: string;
|
|
10
|
+
schemaId: string | undefined;
|
|
11
|
+
graph: Parameters<typeof spaceGraphFrom>[0];
|
|
12
|
+
/** What `annotationsFrom` attaches */
|
|
13
|
+
validation: ValidationInput;
|
|
14
|
+
definitions: MapViewDefinition[];
|
|
15
|
+
};
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { type Config } from 'structured-context/api';
|
|
2
|
-
import {
|
|
2
|
+
import type { MapViewDefinition } from '../core/definition';
|
|
3
3
|
export type LoadMapViewDefinitionsOptions = {
|
|
4
|
-
/**
|
|
4
|
+
/** Root of the main config file (`resolveConfigPath().root`). Defaults to where structured-context finds it. */
|
|
5
5
|
configDir?: string;
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* Every map view definition available with `config`, from:
|
|
9
9
|
* - this package's embedded definitions (`sctx-map-view://core/<name>`), for structured-context's bundled schemas;
|
|
10
10
|
* - each plugin found from a config folder or named by a space (`sctx-map-view://<plugin>/<name>`): the
|
|
11
|
-
* folder named by `"sctx": { "
|
|
12
|
-
* -
|
|
11
|
+
* folder named by `"sctx": { "map-views": "…" }` in its package.json, else its `map-views/` folder;
|
|
12
|
+
* - the `map-views` resources folder of each config root (`sctx-map-view://<name>`).
|
|
13
13
|
*
|
|
14
14
|
* Each definition's `$id` must be in the namespace of where it was found, and ids must be unique.
|
|
15
15
|
* Throws on the first invalid definition.
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { SpaceSnapshot } from '../core/snapshot';
|
|
2
|
+
export declare const PAGE_SLOTS: {
|
|
3
|
+
readonly title: '<!--sctx-title-->';
|
|
4
|
+
readonly snapshots: '<!--sctx-snapshots-->';
|
|
5
|
+
};
|
|
6
|
+
/** `template` (`dist/page.html`) with the title and snapshots written in. */
|
|
7
|
+
export declare function fillPage(template: string, snapshots: SpaceSnapshot[], title: string): string;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { type MapViewDefinition } from '../core/definition';
|
|
2
|
+
export type DefinitionSource = {
|
|
3
|
+
kind: 'core';
|
|
4
|
+
} | {
|
|
5
|
+
kind: 'plugin';
|
|
6
|
+
plugin: string;
|
|
7
|
+
} | {
|
|
8
|
+
kind: 'config';
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Definitions in `folders` and this package's embedded ones, each checked against the namespace of its source.
|
|
12
|
+
* Throws on the first invalid definition or a repeated id.
|
|
13
|
+
*/
|
|
14
|
+
export declare function readDefinitionFolders(folders: {
|
|
15
|
+
dir: string;
|
|
16
|
+
source: DefinitionSource;
|
|
17
|
+
}[]): MapViewDefinition[];
|
|
@@ -1,18 +1,5 @@
|
|
|
1
|
-
import { type Config,
|
|
2
|
-
import type {
|
|
3
|
-
import { type MapViewDefinition } from '../core/definition';
|
|
4
|
-
/**
|
|
5
|
-
* Everything a host without filesystem access needs to render a space: its graph, the validation
|
|
6
|
-
* results that attach to nodes, and the map view definitions that apply to its schema. Plain JSON.
|
|
7
|
-
*/
|
|
8
|
-
export type SpaceSnapshot = {
|
|
9
|
-
space: string;
|
|
10
|
-
schemaId: string | undefined;
|
|
11
|
-
graph: ReturnType<typeof exportSpaceGraph>;
|
|
12
|
-
/** What `annotationsFrom` attaches */
|
|
13
|
-
validation: ValidationInput;
|
|
14
|
-
definitions: MapViewDefinition[];
|
|
15
|
-
};
|
|
1
|
+
import { type Config, validateSpace } from 'structured-context/api';
|
|
2
|
+
import type { SpaceSnapshot } from '../core/snapshot';
|
|
16
3
|
/** The `validateSpace` options `export` passes through unchanged. */
|
|
17
4
|
export type ExportValidateOptions = Pick<NonNullable<Parameters<typeof validateSpace>[1]>, 'depth' | 'includeGated' | 'semantic' | 'ruleFilter'>;
|
|
18
5
|
/**
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { type SpaceGraph, type SpaceNode } from 'structured-context/browser';
|
|
2
|
+
import type { MapViewDefinition } from '../core/definition';
|
|
3
|
+
import type { SpaceSnapshot } from '../core/snapshot';
|
|
4
|
+
/**
|
|
5
|
+
* A page-filling viewer for one or more space snapshots: a space and map view switcher, the parameter
|
|
6
|
+
* controls, the map view, and a side panel with the selected node's fields and validation results. Hosts
|
|
7
|
+
* supply the snapshots and anything specific to where the page is shown. See docs/architecture.md.
|
|
8
|
+
*/
|
|
9
|
+
export type ViewerProps = {
|
|
10
|
+
spaces: SpaceSnapshot[];
|
|
11
|
+
/** Accessible name for each card, for hosts whose surroundings read it. Cards keep their default name without it. */
|
|
12
|
+
cardLabel?: (node: SpaceNode, graph: SpaceGraph, definition: MapViewDefinition) => string;
|
|
13
|
+
};
|
|
14
|
+
export declare function Viewer({ spaces, cardLabel }: ViewerProps): import("react").JSX.Element;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "structured-context-map-views",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.2",
|
|
4
4
|
"description": "Declarative map views of structured-context spaces: render a space as a tree, nested containers or an XY plot from a short definition.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"type": "module",
|
|
@@ -33,26 +33,35 @@
|
|
|
33
33
|
"types": "./dist/types/node/index.d.ts",
|
|
34
34
|
"default": "./dist/node.js"
|
|
35
35
|
},
|
|
36
|
-
"./
|
|
36
|
+
"./html": {
|
|
37
|
+
"types": "./dist/types/node/html.d.ts",
|
|
38
|
+
"default": "./dist/html.js"
|
|
39
|
+
},
|
|
40
|
+
"./styles.css": "./dist/styles.css",
|
|
41
|
+
"./page.html": {
|
|
42
|
+
"types": "./dist/page.html.d.ts",
|
|
43
|
+
"default": "./dist/page.html"
|
|
44
|
+
}
|
|
37
45
|
},
|
|
38
46
|
"scripts": {
|
|
39
47
|
"clean": "rm -rf dist",
|
|
40
48
|
"generate": "bun run generate:schemas && bun run generate:definitions",
|
|
41
49
|
"generate:schemas": "bun scripts/generate-schemas.ts",
|
|
42
50
|
"generate:definitions": "bun scripts/generate-definitions.ts",
|
|
43
|
-
"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-
|
|
51
|
+
"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",
|
|
52
|
+
"build": "bun run build:library && bun scripts/build-artifact-page.ts",
|
|
44
53
|
"typecheck": "tsc --noEmit",
|
|
45
54
|
"capture-fixtures": "bun scripts/capture-fixtures.ts",
|
|
46
55
|
"test": "bun test",
|
|
47
56
|
"test:package": "bash scripts/test-package.sh",
|
|
48
57
|
"prepublishOnly": "bun run build",
|
|
49
|
-
"preversion": "bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run test:package",
|
|
58
|
+
"preversion": "bun run generate && bun run --cwd ../.. lint:fix && bun run --cwd ../.. test && bun run --cwd ../.. test:package",
|
|
50
59
|
"version": "bun run generate:schemas --release && git add -A"
|
|
51
60
|
},
|
|
52
61
|
"peerDependencies": {
|
|
53
62
|
"react": "^19.3.0",
|
|
54
63
|
"react-dom": "^19.3.0",
|
|
55
|
-
"structured-context": "^0.
|
|
64
|
+
"structured-context": "^0.24.0"
|
|
56
65
|
},
|
|
57
66
|
"dependencies": {
|
|
58
67
|
"ajv": "^8.20.0",
|
|
@@ -68,7 +77,7 @@
|
|
|
68
77
|
"@vitejs/plugin-react": "^6.1.1",
|
|
69
78
|
"react": "^19.3.0",
|
|
70
79
|
"react-dom": "^19.3.0",
|
|
71
|
-
"structured-context": "^0.
|
|
80
|
+
"structured-context": "^0.24.0",
|
|
72
81
|
"tailwindcss": "^4.3.3",
|
|
73
82
|
"vite": "^8.3.2"
|
|
74
83
|
}
|
package/dist/node-Co_JiEZV.js
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { r as parseMapViewDefinition } from "./definition-Cp1CCigh.js";
|
|
2
|
-
import { existsSync, readFileSync, readdirSync, statSync } from "node:fs";
|
|
3
|
-
import { dirname, join, resolve } from "node:path";
|
|
4
|
-
import { PLUGIN_PREFIX, resolveConfigPath, resolvePluginDir } from "structured-context/api";
|
|
5
|
-
//#region src/node/bundled-definitions.ts
|
|
6
|
-
var BUNDLED_DEFINITIONS = { "strategy-tree.json5": "// Strategy stack as a tree: vision → mission → goals → opportunities → solutions → experiments.\n{\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\n $id: 'sctx-map-view://core/strategy-tree',\n title: 'Strategy tree',\n schema: 'sctx://core/strategy_general',\n parameters: {\n orientation: { $ref: 'settings.json#/$defs/orientation', default: 'vertical' },\n nodeStyle: { $ref: 'settings.json#/$defs/nodeStyle', default: 'card' },\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\n cardFields: {\n title: 'Card fields',\n type: 'array',\n items: { enum: ['status', 'priority', 'summary'] },\n default: ['status'],\n },\n },\n regions: [\n {\n id: 'main',\n layout: { type: 'tree', orientation: { $param: 'orientation' } },\n nodes: { style: { $param: 'nodeStyle' }, fields: { $param: 'cardFields' }, validation: { $param: 'validation' } },\n edges: { show: true },\n },\n ],\n}\n" };
|
|
7
|
-
//#endregion
|
|
8
|
-
//#region src/node/index.ts
|
|
9
|
-
/**
|
|
10
|
-
* Node-only: finds map view definitions the way structured-context finds plugin schemas.
|
|
11
|
-
* Browser-only hosts receive the result from a server, like graph data.
|
|
12
|
-
*/
|
|
13
|
-
var SCHEME = "sctx-map-view://";
|
|
14
|
-
var DEFINITIONS_DIR = "map-views";
|
|
15
|
-
var CONFIG_PLUGINS_DIR = "plugins";
|
|
16
|
-
var PACKAGE_NAME = "structured-context-map-views";
|
|
17
|
-
/**
|
|
18
|
-
* Every map view definition available with `config`, from:
|
|
19
|
-
* - this package's embedded definitions (`sctx-map-view://core/<name>`), for structured-context's bundled schemas;
|
|
20
|
-
* - each plugin found from a config folder or named by a space (`sctx-map-view://<plugin>/<name>`): the
|
|
21
|
-
* folder named by `"sctx": { "mapViews": "…" }` in its package.json, else its `map-views/` folder;
|
|
22
|
-
* - a `map-views/` folder next to each config file (`sctx-map-view://<name>`).
|
|
23
|
-
*
|
|
24
|
-
* Each definition's `$id` must be in the namespace of where it was found, and ids must be unique.
|
|
25
|
-
* Throws on the first invalid definition.
|
|
26
|
-
*/
|
|
27
|
-
function loadMapViewDefinitions(config, options = {}) {
|
|
28
|
-
const configDir = options.configDir ?? dirname(resolve(resolveConfigPath().path));
|
|
29
|
-
const configDirs = [.../* @__PURE__ */ new Set([configDir, ...config.spaces.flatMap((s) => s.sourceDir ? [s.sourceDir] : [])])];
|
|
30
|
-
const folders = [...pluginDirs(config, configDir, configDirs).flatMap(([plugin, dir]) => {
|
|
31
|
-
const definitions = pluginDefinitionsDir(dir);
|
|
32
|
-
return definitions ? [{
|
|
33
|
-
dir: definitions,
|
|
34
|
-
source: {
|
|
35
|
-
kind: "plugin",
|
|
36
|
-
plugin
|
|
37
|
-
}
|
|
38
|
-
}] : [];
|
|
39
|
-
}), ...configDirs.map((dir) => ({
|
|
40
|
-
dir: join(dir, DEFINITIONS_DIR),
|
|
41
|
-
source: { kind: "config" }
|
|
42
|
-
}))];
|
|
43
|
-
const foundAt = /* @__PURE__ */ new Map();
|
|
44
|
-
const definitions = [];
|
|
45
|
-
const add = (label, text, source) => {
|
|
46
|
-
const definition = parseMapViewDefinition(label, text);
|
|
47
|
-
assertIdNamespace(definition.id, source, label);
|
|
48
|
-
const existing = foundAt.get(definition.id);
|
|
49
|
-
if (existing) throw new Error(`Map view id "${definition.id}" is defined by both ${existing} and ${label}.`);
|
|
50
|
-
foundAt.set(definition.id, label);
|
|
51
|
-
definitions.push(definition);
|
|
52
|
-
};
|
|
53
|
-
for (const [file, text] of Object.entries(BUNDLED_DEFINITIONS)) add(`${PACKAGE_NAME}/${file}`, text, { kind: "core" });
|
|
54
|
-
for (const { dir, source } of folders) {
|
|
55
|
-
if (!isDirectory(dir)) continue;
|
|
56
|
-
for (const file of readdirSync(dir).filter((f) => f.endsWith(".json5")).sort()) {
|
|
57
|
-
const path = join(dir, file);
|
|
58
|
-
add(path, readFileSync(path, "utf8"), source);
|
|
59
|
-
}
|
|
60
|
-
}
|
|
61
|
-
return definitions;
|
|
62
|
-
}
|
|
63
|
-
/** Plugin short name → root directory, for plugins in a config folder's `plugins/` or named by the config. */
|
|
64
|
-
function pluginDirs(config, configDir, configDirs) {
|
|
65
|
-
const found = /* @__PURE__ */ new Map();
|
|
66
|
-
const add = (name, fromDir) => {
|
|
67
|
-
const short = name.startsWith(PLUGIN_PREFIX) ? name.slice(PLUGIN_PREFIX.length) : name;
|
|
68
|
-
if (found.has(short)) return;
|
|
69
|
-
const dir = resolvePluginDir(name, fromDir);
|
|
70
|
-
if (dir) found.set(short, dir);
|
|
71
|
-
};
|
|
72
|
-
for (const dir of configDirs) {
|
|
73
|
-
const plugins = join(dir, CONFIG_PLUGINS_DIR);
|
|
74
|
-
if (!isDirectory(plugins)) continue;
|
|
75
|
-
for (const entry of readdirSync(plugins).filter((e) => e.startsWith(PLUGIN_PREFIX)).sort()) add(entry, dir);
|
|
76
|
-
}
|
|
77
|
-
const topLevel = config.plugins ?? {};
|
|
78
|
-
for (const name of Object.keys(topLevel)) add(name, configDir);
|
|
79
|
-
for (const space of config.spaces) {
|
|
80
|
-
const fromDir = space.sourceDir ?? configDir;
|
|
81
|
-
const schemaPlugin = /^([^./][^/]*)\/./.exec(space.schema ?? "")?.[1];
|
|
82
|
-
if (schemaPlugin) add(schemaPlugin, fromDir);
|
|
83
|
-
for (const name of Object.keys(space.plugins ?? {})) add(name, fromDir);
|
|
84
|
-
}
|
|
85
|
-
return [...found];
|
|
86
|
-
}
|
|
87
|
-
function pluginDefinitionsDir(pluginDir) {
|
|
88
|
-
const pkgPath = join(pluginDir, "package.json");
|
|
89
|
-
if (existsSync(pkgPath)) {
|
|
90
|
-
const declared = JSON.parse(readFileSync(pkgPath, "utf8")).sctx?.mapViews;
|
|
91
|
-
if (typeof declared === "string") return resolve(pluginDir, declared);
|
|
92
|
-
}
|
|
93
|
-
return join(pluginDir, DEFINITIONS_DIR);
|
|
94
|
-
}
|
|
95
|
-
function assertIdNamespace(id, source, path) {
|
|
96
|
-
const segments = id.slice(16).split("/");
|
|
97
|
-
const expected = source.kind === "core" ? `${SCHEME}core/<name>` : source.kind === "plugin" ? `${SCHEME}${source.plugin}/<name>` : `${SCHEME}<name>`;
|
|
98
|
-
if (!(source.kind === "config" ? segments.length === 1 : segments.length === 2 && segments[0] === (source.kind === "core" ? "core" : source.plugin)) || source.kind === "plugin" && source.plugin === "core") throw new Error(`Map view namespace violation: ${path} has $id "${id}". Use the form "${expected}".`);
|
|
99
|
-
}
|
|
100
|
-
function isDirectory(path) {
|
|
101
|
-
return existsSync(path) && statSync(path).isDirectory();
|
|
102
|
-
}
|
|
103
|
-
//#endregion
|
|
104
|
-
export { loadMapViewDefinitions as t };
|
|
105
|
-
|
|
106
|
-
//# sourceMappingURL=node-Co_JiEZV.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"node-Co_JiEZV.js","names":[],"sources":["../src/node/bundled-definitions.ts","../src/node/index.ts"],"sourcesContent":["// Generated by scripts/generate-definitions.ts from map-views/*.json5. Do not edit.\nexport const BUNDLED_DEFINITIONS: Record<string, string> = {\n \"strategy-tree.json5\": \"// Strategy stack as a tree: vision → mission → goals → opportunities → solutions → experiments.\\n{\\n $schema: 'https://raw.githubusercontent.com/mindsocket/structured-context-map-views/main/schemas/generated/latest/definition.json',\\n $id: 'sctx-map-view://core/strategy-tree',\\n title: 'Strategy tree',\\n schema: 'sctx://core/strategy_general',\\n parameters: {\\n orientation: { $ref: 'settings.json#/$defs/orientation', default: 'vertical' },\\n nodeStyle: { $ref: 'settings.json#/$defs/nodeStyle', default: 'card' },\\n validation: { $ref: 'settings.json#/$defs/validationLevel', default: 'off' },\\n cardFields: {\\n title: 'Card fields',\\n type: 'array',\\n items: { enum: ['status', 'priority', 'summary'] },\\n default: ['status'],\\n },\\n },\\n regions: [\\n {\\n id: 'main',\\n layout: { type: 'tree', orientation: { $param: 'orientation' } },\\n nodes: { style: { $param: 'nodeStyle' }, fields: { $param: 'cardFields' }, validation: { $param: 'validation' } },\\n edges: { show: true },\\n },\\n ],\\n}\\n\",\n};\n","/// <reference types=\"node\" />\nimport { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { dirname, join, resolve } from 'node:path';\nimport { type Config, PLUGIN_PREFIX, resolveConfigPath, resolvePluginDir } from 'structured-context/api';\nimport { type MapViewDefinition, parseMapViewDefinition } from '../core/definition';\nimport { BUNDLED_DEFINITIONS } from './bundled-definitions';\n\n/**\n * Node-only: finds map view definitions the way structured-context finds plugin schemas.\n * Browser-only hosts receive the result from a server, like graph data.\n */\n\nconst SCHEME = 'sctx-map-view://';\nconst DEFINITIONS_DIR = 'map-views';\nconst CONFIG_PLUGINS_DIR = 'plugins';\nconst PACKAGE_NAME = 'structured-context-map-views';\n\ntype Source = { kind: 'core' } | { kind: 'plugin'; plugin: string } | { kind: 'config' };\n\nexport type LoadMapViewDefinitionsOptions = {\n /** Directory of the main config file. Defaults to where structured-context finds it. */\n configDir?: string;\n};\n\n/**\n * Every map view definition available with `config`, from:\n * - this package's embedded definitions (`sctx-map-view://core/<name>`), for structured-context's bundled schemas;\n * - each plugin found from a config folder or named by a space (`sctx-map-view://<plugin>/<name>`): the\n * folder named by `\"sctx\": { \"mapViews\": \"…\" }` in its package.json, else its `map-views/` folder;\n * - a `map-views/` folder next to each config file (`sctx-map-view://<name>`).\n *\n * Each definition's `$id` must be in the namespace of where it was found, and ids must be unique.\n * Throws on the first invalid definition.\n */\nexport function loadMapViewDefinitions(\n config: Config,\n options: LoadMapViewDefinitionsOptions = {},\n): MapViewDefinition[] {\n const configDir = options.configDir ?? dirname(resolve(resolveConfigPath().path));\n const configDirs = [...new Set([configDir, ...config.spaces.flatMap((s) => (s.sourceDir ? [s.sourceDir] : []))])];\n\n const folders: { dir: string; source: Source }[] = [\n ...pluginDirs(config, configDir, configDirs).flatMap(([plugin, dir]) => {\n const definitions = pluginDefinitionsDir(dir);\n return definitions ? [{ dir: definitions, source: { kind: 'plugin', plugin } as const }] : [];\n }),\n ...configDirs.map((dir) => ({ dir: join(dir, DEFINITIONS_DIR), source: { kind: 'config' } as const })),\n ];\n\n const foundAt = new Map<string, string>();\n const definitions: MapViewDefinition[] = [];\n const add = (label: string, text: string, source: Source) => {\n const definition = parseMapViewDefinition(label, text);\n assertIdNamespace(definition.id, source, label);\n const existing = foundAt.get(definition.id);\n if (existing) throw new Error(`Map view id \"${definition.id}\" is defined by both ${existing} and ${label}.`);\n foundAt.set(definition.id, label);\n definitions.push(definition);\n };\n\n for (const [file, text] of Object.entries(BUNDLED_DEFINITIONS))\n add(`${PACKAGE_NAME}/${file}`, text, { kind: 'core' });\n for (const { dir, source } of folders) {\n if (!isDirectory(dir)) continue;\n for (const file of readdirSync(dir)\n .filter((f) => f.endsWith('.json5'))\n .sort()) {\n const path = join(dir, file);\n add(path, readFileSync(path, 'utf8'), source);\n }\n }\n return definitions;\n}\n\n/** Plugin short name → root directory, for plugins in a config folder's `plugins/` or named by the config. */\nfunction pluginDirs(config: Config, configDir: string, configDirs: string[]): [string, string][] {\n const found = new Map<string, string>();\n const add = (name: string, fromDir: string) => {\n const short = name.startsWith(PLUGIN_PREFIX) ? name.slice(PLUGIN_PREFIX.length) : name;\n if (found.has(short)) return;\n const dir = resolvePluginDir(name, fromDir);\n if (dir) found.set(short, dir);\n };\n\n for (const dir of configDirs) {\n const plugins = join(dir, CONFIG_PLUGINS_DIR);\n if (!isDirectory(plugins)) continue;\n for (const entry of readdirSync(plugins)\n .filter((e) => e.startsWith(PLUGIN_PREFIX))\n .sort())\n add(entry, dir);\n }\n const topLevel = (config as { plugins?: Record<string, unknown> }).plugins ?? {};\n for (const name of Object.keys(topLevel)) add(name, configDir);\n for (const space of config.spaces) {\n const fromDir = space.sourceDir ?? configDir;\n // A schema named through a plugin, e.g. \"sctx-wardley-mapping/wardley_map.json\".\n const schemaPlugin = /^([^./][^/]*)\\/./.exec(space.schema ?? '')?.[1];\n if (schemaPlugin) add(schemaPlugin, fromDir);\n for (const name of Object.keys(space.plugins ?? {})) add(name, fromDir);\n }\n return [...found];\n}\n\nfunction pluginDefinitionsDir(pluginDir: string): string | undefined {\n const pkgPath = join(pluginDir, 'package.json');\n if (existsSync(pkgPath)) {\n const declared = JSON.parse(readFileSync(pkgPath, 'utf8')).sctx?.mapViews;\n if (typeof declared === 'string') return resolve(pluginDir, declared);\n }\n return join(pluginDir, DEFINITIONS_DIR);\n}\n\nfunction assertIdNamespace(id: string, source: Source, path: string): void {\n const segments = id.slice(SCHEME.length).split('/');\n const expected =\n source.kind === 'core'\n ? `${SCHEME}core/<name>`\n : source.kind === 'plugin'\n ? `${SCHEME}${source.plugin}/<name>`\n : `${SCHEME}<name>`;\n const ok =\n source.kind === 'config'\n ? segments.length === 1\n : segments.length === 2 && segments[0] === (source.kind === 'core' ? 'core' : source.plugin);\n if (!ok || (source.kind === 'plugin' && source.plugin === 'core')) {\n throw new Error(`Map view namespace violation: ${path} has $id \"${id}\". Use the form \"${expected}\".`);\n }\n}\n\nfunction isDirectory(path: string): boolean {\n return existsSync(path) && statSync(path).isDirectory();\n}\n"],"mappings":";;;;;AACA,IAAa,sBAA8C,EACzD,uBAAuB,8iCACzB;;;;;;;ACSA,IAAM,SAAS;AACf,IAAM,kBAAkB;AACxB,IAAM,qBAAqB;AAC3B,IAAM,eAAe;;;;;;;;;;;AAmBrB,SAAgB,uBACd,QACA,UAAyC,CAAC,GACrB;CACrB,MAAM,YAAY,QAAQ,aAAa,QAAQ,QAAQ,kBAAkB,CAAC,CAAC,IAAI,CAAC;CAChF,MAAM,aAAa,CAAC,mBAAG,IAAI,IAAI,CAAC,WAAW,GAAG,OAAO,OAAO,S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