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.
@@ -0,0 +1 @@
1
+ {"version":3,"file":"html.js","names":[],"sources":["../src/node/page.ts"],"sourcesContent":["import type { SpaceSnapshot } from '../core/snapshot';\n\nexport const PAGE_SLOTS = { title: '<!--sctx-title-->', snapshots: '<!--sctx-snapshots-->' } as const;\n\n/** `template` (`dist/page.html`) with the title and snapshots written in. */\nexport function fillPage(template: string, snapshots: SpaceSnapshot[], title: string): string {\n for (const slot of Object.values(PAGE_SLOTS)) {\n if (template.split(slot).length !== 2) throw new Error(`The page template must hold ${slot} exactly once.`);\n }\n // Escaping `<` stops a string in the data ending the script element\n const json = JSON.stringify(snapshots).replaceAll('<', '\\\\u003c');\n return template.replace(PAGE_SLOTS.title, () => escapeHtml(title)).replace(PAGE_SLOTS.snapshots, () => json);\n}\n\nfunction escapeHtml(text: string): string {\n return text.replaceAll('&', '&amp;').replaceAll('<', '&lt;').replaceAll('>', '&gt;');\n}\n"],"mappings":";;AAEA,IAAa,aAAa;CAAE,OAAO;CAAqB,WAAW;AAAwB;;AAG3F,SAAgB,SAAS,UAAkB,WAA4B,OAAuB;CAC5F,KAAK,MAAM,QAAQ,OAAO,OAAO,UAAU,GACzC,IAAI,SAAS,MAAM,IAAI,CAAC,CAAC,WAAW,GAAG,MAAM,IAAI,MAAM,+BAA+B,KAAK,eAAe;CAG5G,MAAM,OAAO,KAAK,UAAU,SAAS,CAAC,CAAC,WAAW,KAAK,SAAS;CAChE,OAAO,SAAS,QAAQ,WAAW,aAAa,WAAW,KAAK,CAAC,CAAC,CAAC,QAAQ,WAAW,iBAAiB,IAAI;AAC7G;AAEA,SAAS,WAAW,MAAsB;CACxC,OAAO,KAAK,WAAW,KAAK,OAAO,CAAC,CAAC,WAAW,KAAK,MAAM,CAAC,CAAC,WAAW,KAAK,MAAM;AACrF"}
@@ -0,0 +1,78 @@
1
+ import { t as readDefinitionFolders } from "./read-definitions-DNcsxgXM.js";
2
+ import { existsSync, readFileSync, readdirSync } from "node:fs";
3
+ import { join, resolve } from "node:path";
4
+ import { PLUGIN_PREFIX, resolveConfigPath, resolvePluginDir, resourceDir } from "structured-context/api";
5
+ //#region src/node/index.ts
6
+ /**
7
+ * Node-only: finds map view definitions the way structured-context finds plugin schemas.
8
+ * Browser-only hosts receive the result from a server, like graph data.
9
+ */
10
+ var DEFINITIONS_DIR = "map-views";
11
+ var CONFIG_PLUGINS_DIR = "plugins";
12
+ /**
13
+ * Every map view definition available with `config`, from:
14
+ * - this package's embedded definitions (`sctx-map-view://core/<name>`), for structured-context's bundled schemas;
15
+ * - each plugin found from a config folder or named by a space (`sctx-map-view://<plugin>/<name>`): the
16
+ * folder named by `"sctx": { "map-views": "…" }` in its package.json, else its `map-views/` folder;
17
+ * - the `map-views` resources folder of each config root (`sctx-map-view://<name>`).
18
+ *
19
+ * Each definition's `$id` must be in the namespace of where it was found, and ids must be unique.
20
+ * Throws on the first invalid definition.
21
+ */
22
+ function loadMapViewDefinitions(config, options = {}) {
23
+ const configDir = options.configDir ?? resolveConfigPath().root;
24
+ const configDirs = [.../* @__PURE__ */ new Set([configDir, ...config.spaces.flatMap((s) => s.sourceDir ? [s.sourceDir] : [])])];
25
+ const folders = [...pluginDirs(config, configDir, configDirs).flatMap(([plugin, dir]) => {
26
+ const definitions = pluginDefinitionsDir(dir);
27
+ return definitions ? [{
28
+ dir: definitions,
29
+ source: {
30
+ kind: "plugin",
31
+ plugin
32
+ }
33
+ }] : [];
34
+ }), ...configDirs.flatMap((dir) => {
35
+ const definitions = resourceDir(dir, DEFINITIONS_DIR);
36
+ return definitions ? [{
37
+ dir: definitions,
38
+ source: { kind: "config" }
39
+ }] : [];
40
+ })];
41
+ return readDefinitionFolders(folders);
42
+ }
43
+ /** Plugin short name → root directory, for plugins in a config root's plugins folder or named by the config. */
44
+ function pluginDirs(config, configDir, configDirs) {
45
+ const found = /* @__PURE__ */ new Map();
46
+ const add = (name, fromDir) => {
47
+ const short = name.startsWith(PLUGIN_PREFIX) ? name.slice(PLUGIN_PREFIX.length) : name;
48
+ if (found.has(short)) return;
49
+ const dir = resolvePluginDir(name, fromDir);
50
+ if (dir) found.set(short, dir);
51
+ };
52
+ for (const dir of configDirs) {
53
+ const plugins = resourceDir(dir, CONFIG_PLUGINS_DIR);
54
+ if (!plugins) continue;
55
+ for (const entry of readdirSync(plugins).filter((e) => e.startsWith(PLUGIN_PREFIX)).sort()) add(entry, dir);
56
+ }
57
+ const topLevel = config.plugins ?? {};
58
+ for (const name of Object.keys(topLevel)) add(name, configDir);
59
+ for (const space of config.spaces) {
60
+ const fromDir = space.sourceDir ?? configDir;
61
+ const schemaPlugin = /^([^./][^/]*)\/./.exec(space.schema ?? "")?.[1];
62
+ if (schemaPlugin) add(schemaPlugin, fromDir);
63
+ for (const name of Object.keys(space.plugins ?? {})) add(name, fromDir);
64
+ }
65
+ return [...found];
66
+ }
67
+ function pluginDefinitionsDir(pluginDir) {
68
+ const pkgPath = join(pluginDir, "package.json");
69
+ if (existsSync(pkgPath)) {
70
+ const declared = JSON.parse(readFileSync(pkgPath, "utf8")).sctx?.[DEFINITIONS_DIR];
71
+ if (typeof declared === "string") return resolve(pluginDir, declared);
72
+ }
73
+ return join(pluginDir, DEFINITIONS_DIR);
74
+ }
75
+ //#endregion
76
+ export { loadMapViewDefinitions as t };
77
+
78
+ //# sourceMappingURL=node-B0VWZju6.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"node-B0VWZju6.js","names":[],"sources":["../src/node/index.ts"],"sourcesContent":["/// <reference types=\"node\" />\nimport { existsSync, readdirSync, readFileSync, statSync } from 'node:fs';\nimport { join, resolve } from 'node:path';\nimport { type Config, PLUGIN_PREFIX, resolveConfigPath, resolvePluginDir, resourceDir } from 'structured-context/api';\nimport type { MapViewDefinition } from '../core/definition';\nimport { type DefinitionSource, readDefinitionFolders } from './read-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 DEFINITIONS_DIR = 'map-views';\nconst CONFIG_PLUGINS_DIR = 'plugins';\n\nexport type LoadMapViewDefinitionsOptions = {\n /** Root of the main config file (`resolveConfigPath().root`). 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\": { \"map-views\": \"…\" }` in its package.json, else its `map-views/` folder;\n * - the `map-views` resources folder of each config root (`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 ?? resolveConfigPath().root;\n const configDirs = [...new Set([configDir, ...config.spaces.flatMap((s) => (s.sourceDir ? [s.sourceDir] : []))])];\n\n const folders: { dir: string; source: DefinitionSource }[] = [\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.flatMap((dir) => {\n const definitions = resourceDir(dir, DEFINITIONS_DIR);\n return definitions ? [{ dir: definitions, source: { kind: 'config' } as const }] : [];\n }),\n ];\n\n return readDefinitionFolders(folders);\n}\n\n/** Plugin short name → root directory, for plugins in a config root's plugins folder 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 = resourceDir(dir, CONFIG_PLUGINS_DIR);\n if (!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?.[DEFINITIONS_DIR];\n if (typeof declared === 'string') return resolve(pluginDir, declared);\n }\n return join(pluginDir, DEFINITIONS_DIR);\n}\n"],"mappings":";;;;;;;;;AAYA,IAAM,kBAAkB;AACxB,IAAM,qBAAqB;;;;;;;;;;;AAiB3B,SAAgB,uBACd,QACA,UAAyC,CAAC,GACrB;CACrB,MAAM,YAAY,QAAQ,aAAa,kBAAkB,CAAC,CAAC;CAC3D,MAAM,aAAa,CAAC,mBAAG,IAAI,IAAI,CAAC,WAAW,GAAG,OAAO,OAAO,SAAS,MAAO,EAAE,YAAY,CAAC,EAAE,SAAS,IAAI,CAAC,CAAE,CAAC,CAAC,CAAC;CAEhH,MAAM,UAAuD,CAC3D,GAAG,WAAW,QAAQ,WAAW,UAAU,CAAC,CAAC,SAAS,CAAC,QAAQ,SAAS;EACtE,MAAM,cAAc,qBAAqB,GAAG;EAC5C,OAAO,cAAc,CAAC;GAAE,KAAK;GAAa,QAAQ;IAAE,MAAM;IAAU;GAAO;EAAW,CAAC,IAAI,CA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AAI,WAAW,OAAO,GAAG;EACvB,MAAM,WAAW,KAAK,MAAM,aAAa,SAAS,MAAM,CAAC,CAAC,CAAC,OAAO;EAClE,IAAI,OAAO,aAAa,UAAU,OAAO,QAAQ,WAAW,QAAQ;CACtE;CACA,OAAO,KAAK,WAAW,eAAe;AACxC"}
package/dist/node.js CHANGED
@@ -1,2 +1,2 @@
1
- import { t as loadMapViewDefinitions } from "./node-Co_JiEZV.js";
1
+ import { t as loadMapViewDefinitions } from "./node-B0VWZju6.js";
2
2
  export { loadMapViewDefinitions };