glassbrain 0.2.0-alpha.3 → 0.2.0-alpha.4

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/core.js CHANGED
@@ -1,10 +1,9 @@
1
1
  import {
2
- MAX_DERIVED_LAYERS,
3
2
  childrenMap,
4
3
  deriveLayers,
5
4
  layerIndexOf,
6
5
  orderedChildren
7
- } from "./chunks/chunk-QJ4B3U76.js";
6
+ } from "./chunks/chunk-G7XWVKHN.js";
8
7
  import {
9
8
  CONTENT_SCALE,
10
9
  DARK_THEME,
@@ -35,6 +34,7 @@ import {
35
34
  buildModel,
36
35
  changedSubset,
37
36
  checkEdit,
37
+ checkNativeEdit,
38
38
  chromeStyle,
39
39
  cls,
40
40
  countByKind,
@@ -44,6 +44,7 @@ import {
44
44
  diffModels,
45
45
  diffStyle,
46
46
  edgesOf,
47
+ encodeParent,
47
48
  graphStyle,
48
49
  hasChanges,
49
50
  indexModel,
@@ -76,10 +77,10 @@ import {
76
77
  untheme,
77
78
  validateModel,
78
79
  validateStructure
79
- } from "./chunks/chunk-WW23WBYG.js";
80
+ } from "./chunks/chunk-SEOAVI3E.js";
80
81
  import {
81
82
  EN
82
- } from "./chunks/chunk-H2WV3DTN.js";
83
+ } from "./chunks/chunk-ISWKAU5G.js";
83
84
  import "./chunks/chunk-ZA47FP7C.js";
84
85
  export {
85
86
  CONTENT_SCALE,
@@ -97,7 +98,6 @@ export {
97
98
  KEPT_FLAG,
98
99
  LABEL_MAX_EM,
99
100
  LIGHT_THEME,
100
- MAX_DERIVED_LAYERS,
101
101
  NODE_BASE,
102
102
  PAST_KINDS,
103
103
  PLANE_HUES,
@@ -113,6 +113,7 @@ export {
113
113
  buildModel,
114
114
  changedSubset,
115
115
  checkEdit,
116
+ checkNativeEdit,
116
117
  childrenMap,
117
118
  chromeStyle,
118
119
  cls,
@@ -124,6 +125,7 @@ export {
124
125
  diffModels,
125
126
  diffStyle,
126
127
  edgesOf,
128
+ encodeParent,
127
129
  graphStyle,
128
130
  hasChanges,
129
131
  indexModel,
package/dist/edit.d.ts CHANGED
@@ -5,6 +5,7 @@ export interface NodeFields {
5
5
  label?: string;
6
6
  kind?: string;
7
7
  parent?: string | null;
8
+ order?: number | null;
8
9
  data?: Record<string, unknown>;
9
10
  }
10
11
  export interface EdgeRef {
@@ -37,7 +38,7 @@ export type EditOp =
37
38
  op: 'removeEdge';
38
39
  edge: EdgeRef;
39
40
  };
40
- export type EditError = 'id-empty' | 'id-taken' | 'no-node' | 'no-parent' | 'cycle' | 'has-children' | 'no-endpoint' | 'self-loop' | 'edge-exists' | 'no-edge';
41
+ export type EditError = 'id-format' | 'multiple-roots' | 'order-mixed' | 'order-invalid' | 'id-empty' | 'id-taken' | 'no-node' | 'no-parent' | 'cycle' | 'has-children' | 'no-endpoint' | 'self-loop' | 'edge-exists' | 'no-edge';
41
42
  /** Whether this op can be applied. null = yes; otherwise the reason (the UI looks it up in `strings.error`). */
42
43
  export declare function checkEdit(model: GraphModel, op: EditOp): EditError | null;
43
44
  /** How many edges hang on a node (the ones that go with it when it is deleted). */
@@ -56,3 +57,5 @@ export declare function applyEdits(model: GraphModel, ops: EditOp[], profile?: G
56
57
  error: EditError;
57
58
  }[];
58
59
  };
60
+ /** Native CLI edits must remain exportable under the parent/order contract. */
61
+ export declare function checkNativeEdit(model: GraphModel, op: EditOp): EditError | null;
package/dist/index.js CHANGED
@@ -1,12 +1,11 @@
1
1
  'use client';
2
2
  import "./chunks/chunk-SA6RSWZP.js";
3
3
  import {
4
- MAX_DERIVED_LAYERS,
5
4
  childrenMap,
6
5
  deriveLayers,
7
6
  layerIndexOf,
8
7
  orderedChildren
9
- } from "./chunks/chunk-QJ4B3U76.js";
8
+ } from "./chunks/chunk-G7XWVKHN.js";
10
9
  import {
11
10
  ALL_CONTROLS,
12
11
  DEFAULT_PLANES,
@@ -15,7 +14,7 @@ import {
15
14
  clearLayoutCache,
16
15
  computeLayout,
17
16
  projectPlanes
18
- } from "./chunks/chunk-7C3QZVGJ.js";
17
+ } from "./chunks/chunk-R2CQA4OJ.js";
19
18
  import {
20
19
  CONTENT_SCALE,
21
20
  DARK_THEME,
@@ -46,6 +45,7 @@ import {
46
45
  buildModel,
47
46
  changedSubset,
48
47
  checkEdit,
48
+ checkNativeEdit,
49
49
  chromeStyle,
50
50
  cls,
51
51
  countByKind,
@@ -55,6 +55,7 @@ import {
55
55
  diffModels,
56
56
  diffStyle,
57
57
  edgesOf,
58
+ encodeParent,
58
59
  graphStyle,
59
60
  hasChanges,
60
61
  indexModel,
@@ -87,15 +88,15 @@ import {
87
88
  untheme,
88
89
  validateModel,
89
90
  validateStructure
90
- } from "./chunks/chunk-WW23WBYG.js";
91
+ } from "./chunks/chunk-SEOAVI3E.js";
91
92
  import {
92
93
  DetailPanel,
93
94
  renderInline,
94
95
  renderMarkdown
95
- } from "./chunks/chunk-PBF4KMQB.js";
96
+ } from "./chunks/chunk-3JGZ27DC.js";
96
97
  import {
97
98
  EN
98
- } from "./chunks/chunk-H2WV3DTN.js";
99
+ } from "./chunks/chunk-ISWKAU5G.js";
99
100
  import "./chunks/chunk-YGRPNAXE.js";
100
101
  import "./chunks/chunk-ZA47FP7C.js";
101
102
  export {
@@ -118,7 +119,6 @@ export {
118
119
  KEPT_FLAG,
119
120
  LABEL_MAX_EM,
120
121
  LIGHT_THEME,
121
- MAX_DERIVED_LAYERS,
122
122
  NODE_BASE,
123
123
  PAST_KINDS,
124
124
  PLANE_HUES,
@@ -135,6 +135,7 @@ export {
135
135
  buildModel,
136
136
  changedSubset,
137
137
  checkEdit,
138
+ checkNativeEdit,
138
139
  childrenMap,
139
140
  chromeStyle,
140
141
  clearLayoutCache,
@@ -148,6 +149,7 @@ export {
148
149
  diffModels,
149
150
  diffStyle,
150
151
  edgesOf,
152
+ encodeParent,
151
153
  graphStyle,
152
154
  hasChanges,
153
155
  indexModel,
package/dist/internal.js CHANGED
@@ -1,12 +1,11 @@
1
1
  'use client';
2
2
  import "./chunks/chunk-SA6RSWZP.js";
3
3
  import {
4
- MAX_DERIVED_LAYERS,
5
4
  childrenMap,
6
5
  deriveLayers,
7
6
  layerIndexOf,
8
7
  orderedChildren
9
- } from "./chunks/chunk-QJ4B3U76.js";
8
+ } from "./chunks/chunk-G7XWVKHN.js";
10
9
  import {
11
10
  ALL_CONTROLS,
12
11
  DEFAULT_PLANES,
@@ -48,7 +47,7 @@ import {
48
47
  shapeOf,
49
48
  skeletonLineOf,
50
49
  touchGestures
51
- } from "./chunks/chunk-7C3QZVGJ.js";
50
+ } from "./chunks/chunk-R2CQA4OJ.js";
52
51
  import {
53
52
  CONTENT_SCALE,
54
53
  DARK_THEME,
@@ -85,6 +84,7 @@ import {
85
84
  buildModel,
86
85
  changedSubset,
87
86
  checkEdit,
87
+ checkNativeEdit,
88
88
  chromeStyle,
89
89
  cls,
90
90
  countByKind,
@@ -102,6 +102,7 @@ import {
102
102
  edgeFade,
103
103
  edgeTraffic,
104
104
  edgesOf,
105
+ encodeParent,
105
106
  fadeAt,
106
107
  graphStyle,
107
108
  hasChanges,
@@ -145,15 +146,15 @@ import {
145
146
  untheme,
146
147
  validateModel,
147
148
  validateStructure
148
- } from "./chunks/chunk-WW23WBYG.js";
149
+ } from "./chunks/chunk-SEOAVI3E.js";
149
150
  import {
150
151
  DetailPanel,
151
152
  renderInline,
152
153
  renderMarkdown
153
- } from "./chunks/chunk-PBF4KMQB.js";
154
+ } from "./chunks/chunk-3JGZ27DC.js";
154
155
  import {
155
156
  EN
156
- } from "./chunks/chunk-H2WV3DTN.js";
157
+ } from "./chunks/chunk-ISWKAU5G.js";
157
158
  import "./chunks/chunk-YGRPNAXE.js";
158
159
  import "./chunks/chunk-ZA47FP7C.js";
159
160
  export {
@@ -186,7 +187,6 @@ export {
186
187
  KEPT_FLAG,
187
188
  LABEL_MAX_EM,
188
189
  LIGHT_THEME,
189
- MAX_DERIVED_LAYERS,
190
190
  MIN_DOT,
191
191
  MIN_LINE,
192
192
  NODE_BASE,
@@ -214,6 +214,7 @@ export {
214
214
  buildModel,
215
215
  changedSubset,
216
216
  checkEdit,
217
+ checkNativeEdit,
217
218
  childrenMap,
218
219
  chromeStyle,
219
220
  clearLayoutCache,
@@ -238,6 +239,7 @@ export {
238
239
  edgeFade,
239
240
  edgeTraffic,
240
241
  edgesOf,
242
+ encodeParent,
241
243
  fadeAt,
242
244
  focusAlphaOf,
243
245
  gapOf,
package/dist/layers.d.ts CHANGED
@@ -1,7 +1,5 @@
1
1
  import type { GraphModel, GraphNode } from './model.js';
2
2
  import type { LayerSpec } from './profile.js';
3
- /** Beyond this many ordered children the planes stop being an outline and become a stack of cards. */
4
- export declare const MAX_DERIVED_LAYERS = 8;
5
3
  export interface DerivedLayers {
6
4
  /** Empty when the graph has no ordered siblings at the top of a single root. */
7
5
  layers: LayerSpec[];
@@ -10,7 +10,6 @@ export interface OrderInfo {
10
10
  /** At least one run is numbered (otherwise there is nothing to do). */
11
11
  any: boolean;
12
12
  }
13
- /** Read `order` off the elements. Returns null when nothing is numbered: the layout then stays exactly as it was. */
14
13
  export declare function readOrder(elements: CyElement[]): OrderInfo | null;
15
14
  /** Pre-solve positions: ordered runs on arcs (clockwise, first at 12 o'clock), the rest by hash. */
16
15
  export declare function orderSeed(elements: CyElement[], info: OrderInfo): Positions;
package/dist/model.d.ts CHANGED
@@ -6,8 +6,9 @@ export interface GraphNode {
6
6
  kind?: string;
7
7
  /** Compound parent node id: expresses "nested inside", the only source of structural hierarchy. */
8
8
  parent?: string;
9
- /** Position among its siblings: every child of a parent carries one, or none does. The layout reads it
10
- * clockwise, and a run of ordered siblings is what opens the layer view. */
9
+ /** Position among its siblings: every child of a parent carries one, or none does. **The file format writes it as the
10
+ * `@<order>` tail of `parent`** (`"<id>@<order>"`; `@-1` means explicitly unordered and parses to undefined). The layout
11
+ * reads it clockwise, and a run of ordered siblings is what opens the layer view. */
11
12
  order?: number;
12
13
  /** **Where it hung in the previous version** (filled by `diffModels`, only `moved` nodes in a union have it).
13
14
  *
@@ -94,3 +95,5 @@ export interface GraphIndex {
94
95
  export declare function indexModel(model: GraphModel): GraphIndex;
95
96
  /** The sources that appear in the model (data for the subgraph / view dropdown). */
96
97
  export declare function originsOf(model: GraphModel): string[];
98
+ /** Canonical decimal encoding: Number.toString uses exponents for tiny/large orders. */
99
+ export declare function encodeParent(parent: string | null | undefined, order?: number): string | null;
@@ -6,6 +6,8 @@ export interface SelectedNode {
6
6
  label: string;
7
7
  kind: string;
8
8
  layer?: string;
9
+ parent?: string;
10
+ order?: number;
9
11
  origin?: string | null;
10
12
  /** Has children. */
11
13
  container?: boolean;
@@ -2,8 +2,8 @@
2
2
  "use client";
3
3
  import {
4
4
  DetailPanel
5
- } from "../chunks/chunk-PBF4KMQB.js";
6
- import "../chunks/chunk-H2WV3DTN.js";
5
+ } from "../chunks/chunk-3JGZ27DC.js";
6
+ import "../chunks/chunk-ISWKAU5G.js";
7
7
  import "../chunks/chunk-ZA47FP7C.js";
8
8
  export {
9
9
  DetailPanel as default
@@ -28,7 +28,7 @@ import { type ControlId } from './Toolbar.js';
28
28
  import { type SelectedNode } from './DetailPanel.js';
29
29
  import { type RenderEditor } from './EditPanel.js';
30
30
  import { type GraphLook } from './Legend.js';
31
- import { type EditOp } from '../edit.js';
31
+ import { type EditError, type EditOp } from '../edit.js';
32
32
  import { type GraphStrings } from '../strings.js';
33
33
  /** Where a layout came from (as `onLayout` reports it):
34
34
  * `preset` the host's `layout` covered everything · `cache` nothing was computed, an existing result was reused (local cache, or the one already on screen) ·
@@ -187,9 +187,12 @@ export interface GraphCanvasProps {
187
187
  * with `applyEdit` to its own model and passes it back, and the transition shows the change. Not editable in compare mode. See edit.ts.
188
188
  */
189
189
  onEdit?: (op: EditOp) => void;
190
+ /** Full editable graph when the drawn model omits a layer anchor. */
191
+ editModel?: GraphModel;
192
+ validateEdit?: (op: EditOp) => EditError | null;
190
193
  /** Replace the free-form part of the edit panel (label / kind / data, JSON) with the host's own editor. */
191
194
  renderEditor?: RenderEditor;
192
- /** "Restructure" in ⋯: the host re-hangs and renumbers the graph (see cli/restructure.ts) and hands back a new model.
195
+ /** "Re-structure" in ⋯: the host re-hangs and renumbers the graph (see cli/restructure.ts) and hands back a new model.
193
196
  * Without it the item is absent. Pure callback: the library never edits. */
194
197
  onRestructure?: () => void;
195
198
  /** Why the layer button is grey. The button is always shown; this text goes in its popover. */
@@ -2,10 +2,10 @@
2
2
  "use client";
3
3
  import {
4
4
  GraphCanvas
5
- } from "../chunks/chunk-7C3QZVGJ.js";
6
- import "../chunks/chunk-WW23WBYG.js";
7
- import "../chunks/chunk-PBF4KMQB.js";
8
- import "../chunks/chunk-H2WV3DTN.js";
5
+ } from "../chunks/chunk-R2CQA4OJ.js";
6
+ import "../chunks/chunk-SEOAVI3E.js";
7
+ import "../chunks/chunk-3JGZ27DC.js";
8
+ import "../chunks/chunk-ISWKAU5G.js";
9
9
  import "../chunks/chunk-YGRPNAXE.js";
10
10
  import "../chunks/chunk-ZA47FP7C.js";
11
11
  export {
@@ -37,7 +37,7 @@ export interface ToolbarProps {
37
37
  onAdd?: (what: 'node' | 'edge') => void;
38
38
  /** "Relayout" in ⋯: another arrangement of the same data. Without it the item is absent. */
39
39
  onRelayout?: () => void;
40
- /** "Restructure" in ⋯: re-hang and renumber to raise the shape score. Without it the item is absent. */
40
+ /** "Re-structure" in ⋯: repair containment and ordering while preserving content. Without it the item is absent. */
41
41
  onRestructure?: () => void;
42
42
  /** Why the layer button is grey (it is always shown). `onForceLayers` adds "open the floors anyway". */
43
43
  layerIssue?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "glassbrain",
3
- "version": "0.2.0-alpha.3",
3
+ "version": "0.2.0-alpha.4",
4
4
  "description": "Know what your agent knows: open, diff and review the knowledge graphs agents write. Plain JSON in, one html file out.",
5
5
  "keywords": [
6
6
  "knowledge-graph",
@@ -88,7 +88,8 @@
88
88
  "demo:public": "node demo/build.mjs --public",
89
89
  "bench": "node demo/build.mjs && node scripts/bench.mjs",
90
90
  "pretest": "npm run build",
91
- "test": "node --test \"test/*.test.ts\""
91
+ "test": "node --test \"test/*.test.ts\"",
92
+ "release:alpha": "node scripts/release-alpha.mjs"
92
93
  },
93
94
  "peerDependencies": {
94
95
  "cytoscape": "^3.30.0",
@@ -2,7 +2,7 @@
2
2
  "$schema": "https://json-schema.org/draft/2020-12/schema",
3
3
  "$id": "https://unpkg.com/glassbrain/schema/graph.schema.json",
4
4
  "title": "glassbrain graph",
5
- "description": "One file of a glassbrain knowledge graph. A graph is nodes plus edges; structure comes from `parent` (containment), not from edges. Every node carries `parent`: a node id, or null for the root. Several files in one folder are merged into one graph (same id = same node). Unknown fields are kept and shown in the detail panel.",
5
+ "description": "One file of a glassbrain knowledge graph. A graph is nodes plus edges; structure comes from `parent` (containment), not from edges. Every node carries `parent`: null for the root, otherwise `\"<id>@<order>\"` where `order` is a positive number or -1 for explicitly unordered. Several files in one folder are merged into one graph (same id = same node). Unknown fields are kept and shown in the detail panel.",
6
6
  "type": "object",
7
7
  "anyOf": [{ "required": ["nodes"] }, { "required": ["edges"] }],
8
8
  "properties": {
@@ -22,12 +22,11 @@
22
22
  "type": "object",
23
23
  "required": ["id", "parent"],
24
24
  "properties": {
25
- "id": { "type": ["string", "number"], "description": "Stable identity. Keep it the same across versions: that is how a diff knows it is the same thing." },
25
+ "id": { "type": ["string", "number"], "pattern": "^[^\\s@]{1,80}$", "description": "Stable identity. Keep it the same across versions: that is how a diff knows it is the same thing. No `@` and no whitespace, at most 80 characters; prefer a short code (`a-z0-9_`, under 20)." },
26
26
  "label": { "type": "string", "description": "Display name. Falls back to `name`, then `id`." },
27
27
  "name": { "type": "string", "description": "Alias of `label`." },
28
28
  "kind": { "type": "string", "description": "What sort of thing this is. Colors come from the profile's `nodePalette[kind]`; kinds not in the palette are drawn as skeleton." },
29
- "parent": { "type": ["string", "null"], "description": "Id of the node this one sits inside; null for the root. Required: the only source of structure, and the layout, the layers and the outline are all built from it." },
30
- "order": { "type": "number", "exclusiveMinimum": 0, "description": "Position among its siblings (1, 2, 3…; 3.5 inserts between 3 and 4). Either every child of a parent has one or none does, and no two siblings share one." },
29
+ "parent": { "type": ["string", "null"], "pattern": "^[^\\s@]{1,80}@(-1|[1-9]\\d*(\\.\\d+)?|0\\.\\d*[1-9]\\d*)$", "description": "`\"<id>@<order>\"`: the id of the node this one sits inside, then its position among the siblings (1, 2, 3…; 3.5 inserts between 3 and 4), or -1 for explicitly unordered. null for the root. Required: the only source of structure, and the layout, the layers and the outline are all built from it." },
31
30
  "flags": { "type": "array", "items": { "type": "string" }, "description": "Boolean markers; each becomes a CSS-like class. A flag listed in the profile's `placeholderFlags` draws the node as a placeholder." },
32
31
  "description": { "type": "string", "description": "Markdown shown in the detail panel. `[text](node:<id>)` links jump to another node." }
33
32
  },