glassbrain 0.2.0-alpha.2 → 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/README.md +19 -11
- package/dist/adapters/graphify.d.ts +3 -0
- package/dist/adapters/understand.d.ts +3 -0
- package/dist/adapters.js +18 -3
- package/dist/chunks/{chunk-ZHPUQDOJ.js → chunk-3JGZ27DC.js} +10 -1
- package/dist/chunks/chunk-G7XWVKHN.js +66 -0
- package/dist/chunks/{chunk-F3DN7SLR.js → chunk-ISWKAU5G.js} +9 -1
- package/dist/chunks/{chunk-TM27EXYP.js → chunk-R2CQA4OJ.js} +136 -31
- package/dist/chunks/{chunk-7R6PO7AE.js → chunk-SEOAVI3E.js} +82 -18
- package/dist/cli/glassbrain.js +784 -541
- package/dist/cli/viewer.js +47 -44
- package/dist/core.d.ts +1 -0
- package/dist/core.js +16 -3
- package/dist/edit.d.ts +4 -1
- package/dist/index.js +18 -5
- package/dist/internal.js +18 -5
- package/dist/layers.d.ts +1 -3
- package/dist/layout/order.d.ts +0 -1
- package/dist/model.d.ts +5 -2
- package/dist/react/DetailPanel.d.ts +2 -0
- package/dist/react/DetailPanel.js +2 -2
- package/dist/react/GraphCanvas.d.ts +9 -2
- package/dist/react/GraphCanvas.js +4 -4
- package/dist/react/Toolbar.d.ts +4 -1
- package/dist/strings.d.ts +4 -0
- package/package.json +3 -2
- package/schema/graph.schema.json +3 -4
- package/README.zh-CN.md +0 -938
- package/dist/chunks/chunk-LEYJCT6O.js +0 -0
package/README.md
CHANGED
|
@@ -23,29 +23,37 @@ lets you read one at a glance, and when the agent learns something, shows you ex
|
|
|
23
23
|
{
|
|
24
24
|
"nodes": [
|
|
25
25
|
{ "id": "src", "label": "src", "kind": "folder", "parent": null },
|
|
26
|
-
{ "id": "src/auth", "label": "auth", "kind": "folder", "parent": "src"
|
|
27
|
-
{ "id": "src/auth/login.ts", "label": "login.ts", "kind": "file", "parent": "src/auth" },
|
|
28
|
-
{ "id": "src/db.ts", "label": "db.ts", "kind": "file", "parent": "src"
|
|
26
|
+
{ "id": "src/auth", "label": "auth", "kind": "folder", "parent": "src@1" },
|
|
27
|
+
{ "id": "src/auth/login.ts", "label": "login.ts", "kind": "file", "parent": "src/auth@-1" },
|
|
28
|
+
{ "id": "src/db.ts", "label": "db.ts", "kind": "file", "parent": "src@2" }
|
|
29
29
|
],
|
|
30
30
|
"edges": [{ "source": "src/auth/login.ts", "target": "src/db.ts", "kind": "uses" }]
|
|
31
31
|
}
|
|
32
32
|
```
|
|
33
33
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
34
|
+
Next to it, one colour per kind — a kind with no colour is drawn as skeleton, so `lint` reports
|
|
35
|
+
it as an error (forty kinds without colours look exactly like one kind):
|
|
36
|
+
|
|
37
|
+
```json
|
|
38
|
+
{ "nodePalette": { "folder": "#94a3b8", "file": "#6366f1" },
|
|
39
|
+
"edgePalette": { "uses": "#2563eb" } }
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
`parent` is required on every node (null for the one root) and says what sits inside what **and where
|
|
43
|
+
it sits**: `id@order`, or `id@-1` for an explicitly unordered set. The layout reads the numbers
|
|
44
|
+
clockwise, and a root whose children are numbered *is* the 2.5D layer view. There is no layer field.
|
|
37
45
|
A [JSON Schema](https://github.com/voidixyn/glassbrain/blob/main/schema/graph.schema.json) describes every field, and the CLI answers in a form an
|
|
38
|
-
agent can act on —
|
|
46
|
+
agent can act on — findings identify the problem and structural advice suggests a next step:
|
|
39
47
|
|
|
40
48
|
```text
|
|
41
|
-
$ npx glassbrain
|
|
49
|
+
$ npx glassbrain lint kg
|
|
42
50
|
error dangling-edge graph.json edge src/auth/login.ts → src/session points at the missing node src/session
|
|
43
51
|
an edge can only join nodes that exist. Add the node, or repoint the edge:
|
|
44
52
|
- { "source": "src/auth/login.ts", "target": "src/session" }
|
|
45
53
|
+ { "source": "src/auth/login.ts", "target": "EXISTING_ID" }
|
|
46
54
|
|
|
47
|
-
kg:
|
|
48
|
-
structure: 1 root · depth 2 · 1/
|
|
55
|
+
kg: 2 nodes, 1 edge — 1 error · 0 warnings · 0 infos
|
|
56
|
+
structure: 1 root · depth 2 · 1/2 parented · structure pressure 0.000 · 0 assessed / 1 unassessed
|
|
49
57
|
|
|
50
58
|
$ npx glassbrain diff kg/1-skeleton kg/2-filled
|
|
51
59
|
1-skeleton → 2-filled
|
|
@@ -57,7 +65,7 @@ changed (1)
|
|
|
57
65
|
```
|
|
58
66
|
|
|
59
67
|
Errors exit 1 (`--strict`: warnings too), `diff --exit-code` exits 1 when anything changed, and
|
|
60
|
-
`--json` gives the same as structured output. So an agent can build a graph in steps,
|
|
68
|
+
`--json` gives the same as structured output. So an agent can build a graph in steps, lint
|
|
61
69
|
each one, and check that a step did only its job.
|
|
62
70
|
|
|
63
71
|
## 2. Read it like a brain scan
|
package/dist/adapters.js
CHANGED
|
@@ -103,7 +103,18 @@ function convertGraphify(d, name) {
|
|
|
103
103
|
var score = (l) => typeof l.confidence_score === "number" ? l.confidence_score : typeof l.weight === "number" ? Math.min(1, l.weight) : void 0;
|
|
104
104
|
var groupLabel = (t) => ({ concept: "Concepts", rationale: "Rationale", document: "Documents" })[t] ?? t;
|
|
105
105
|
var PROFILE = {
|
|
106
|
-
|
|
106
|
+
// The adapter invents these three while building the folder / file boxes, so it must colour them too.
|
|
107
|
+
nodePalette: {
|
|
108
|
+
symbol: "#6366f1",
|
|
109
|
+
concept: "#e63b7a",
|
|
110
|
+
rationale: "#f59e0b",
|
|
111
|
+
document: "#0891b2",
|
|
112
|
+
paper: "#0891b2",
|
|
113
|
+
image: "#16a34a",
|
|
114
|
+
folder: "#94a3b8",
|
|
115
|
+
file: "#64748b",
|
|
116
|
+
group: "#a855f7"
|
|
117
|
+
},
|
|
107
118
|
edgePalette: {
|
|
108
119
|
calls: "#6366f1",
|
|
109
120
|
imports: "#94a3b8",
|
|
@@ -318,7 +329,8 @@ var obsidian = {
|
|
|
318
329
|
return {
|
|
319
330
|
sources,
|
|
320
331
|
profile: {
|
|
321
|
-
|
|
332
|
+
// `folder` is invented by the walk, not present in frontmatter kinds: colour it here.
|
|
333
|
+
nodePalette: { ...autoPalette(kinds), folder: "#94a3b8" },
|
|
322
334
|
edgePalette: { link: "#94a3b8" },
|
|
323
335
|
kindLabels: { folder: "Folder", note: "Note", link: "link" },
|
|
324
336
|
detail: { line: [{ key: "path", label: "File" }], list: [{ key: "tags", label: "Tags" }] },
|
|
@@ -409,7 +421,10 @@ var PROFILE2 = {
|
|
|
409
421
|
source: "#64748b",
|
|
410
422
|
screen: "#0891b2",
|
|
411
423
|
component: "#6366f1",
|
|
412
|
-
token: "#f59e0b"
|
|
424
|
+
token: "#f59e0b",
|
|
425
|
+
layer: "#a855f7",
|
|
426
|
+
folder: "#94a3b8",
|
|
427
|
+
file: "#64748b"
|
|
413
428
|
},
|
|
414
429
|
edgePalette: {
|
|
415
430
|
imports: "#94a3b8",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
EN
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-ISWKAU5G.js";
|
|
4
4
|
|
|
5
5
|
// src/react/i18n.ts
|
|
6
6
|
import { createContext, useContext } from "react";
|
|
@@ -174,6 +174,7 @@ function DetailPanel({ node, spec, kindLabels, onClose, renderText, onEdit, colo
|
|
|
174
174
|
"id",
|
|
175
175
|
"label",
|
|
176
176
|
"parent",
|
|
177
|
+
"order",
|
|
177
178
|
"layer",
|
|
178
179
|
"flags"
|
|
179
180
|
]);
|
|
@@ -195,6 +196,14 @@ function DetailPanel({ node, spec, kindLabels, onClose, renderText, onEdit, colo
|
|
|
195
196
|
] }),
|
|
196
197
|
/* @__PURE__ */ jsxs("div", { className: "gb-db", children: [
|
|
197
198
|
/* @__PURE__ */ jsx3("div", { className: "gb-dt", children: node.label }),
|
|
199
|
+
/* @__PURE__ */ jsxs("div", { className: "gb-line", children: [
|
|
200
|
+
/* @__PURE__ */ jsx3("span", { className: "gb-k", children: t.parent }),
|
|
201
|
+
/* @__PURE__ */ jsx3("span", { children: node.parent ?? "Root" })
|
|
202
|
+
] }),
|
|
203
|
+
node.parent && /* @__PURE__ */ jsxs("div", { className: "gb-line", children: [
|
|
204
|
+
/* @__PURE__ */ jsx3("span", { className: "gb-k", children: "Order" }),
|
|
205
|
+
/* @__PURE__ */ jsx3("span", { children: node.order ?? "Unordered" })
|
|
206
|
+
] }),
|
|
198
207
|
node.flags.map((f) => {
|
|
199
208
|
const note = spec.flagNotes?.[f];
|
|
200
209
|
return note ? /* @__PURE__ */ jsx3("div", { className: "gb-flag", children: note }, f) : null;
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
// src/layers.ts
|
|
2
|
+
var EMPTY = { layers: [], layerOf: /* @__PURE__ */ new Map() };
|
|
3
|
+
function orderedChildren(children, id) {
|
|
4
|
+
const kids = children.get(id) ?? [];
|
|
5
|
+
if (kids.length < 2) return null;
|
|
6
|
+
const withOrder = kids.filter((n) => typeof n.order === "number" && Number.isFinite(n.order));
|
|
7
|
+
if (withOrder.length !== kids.length) return null;
|
|
8
|
+
const seen = /* @__PURE__ */ new Set();
|
|
9
|
+
for (const k of withOrder) {
|
|
10
|
+
if (seen.has(k.order)) return null;
|
|
11
|
+
seen.add(k.order);
|
|
12
|
+
}
|
|
13
|
+
return [...kids].sort((a, b) => a.order - b.order);
|
|
14
|
+
}
|
|
15
|
+
function childrenMap(model) {
|
|
16
|
+
const out = /* @__PURE__ */ new Map();
|
|
17
|
+
for (const n of model.nodes) {
|
|
18
|
+
if (!n.parent || !model.index.has(n.parent)) continue;
|
|
19
|
+
const arr = out.get(n.parent);
|
|
20
|
+
arr ? arr.push(n) : out.set(n.parent, [n]);
|
|
21
|
+
}
|
|
22
|
+
return out;
|
|
23
|
+
}
|
|
24
|
+
function deriveLayers(model, colors = [], force = false) {
|
|
25
|
+
if (!model.nodes.length) return EMPTY;
|
|
26
|
+
const children = childrenMap(model);
|
|
27
|
+
const roots = model.nodes.filter((n) => !n.parent || !model.index.has(n.parent));
|
|
28
|
+
let ordered = null;
|
|
29
|
+
let anchor;
|
|
30
|
+
if (roots.length === 1) {
|
|
31
|
+
anchor = roots[0];
|
|
32
|
+
ordered = orderedChildren(children, anchor.id);
|
|
33
|
+
if (!ordered && force) ordered = children.get(anchor.id) ?? null;
|
|
34
|
+
} else if (force && roots.length > 1) {
|
|
35
|
+
ordered = roots;
|
|
36
|
+
}
|
|
37
|
+
if (!ordered || ordered.length < 2) return EMPTY;
|
|
38
|
+
const layers = ordered.map((n, i) => ({
|
|
39
|
+
id: n.id,
|
|
40
|
+
label: n.label || n.id,
|
|
41
|
+
z: i,
|
|
42
|
+
...colors[i] ? { color: colors[i] } : {}
|
|
43
|
+
}));
|
|
44
|
+
const layerOf = /* @__PURE__ */ new Map();
|
|
45
|
+
for (const [i, layer] of ordered.entries()) {
|
|
46
|
+
const stack = [layer.id];
|
|
47
|
+
while (stack.length) {
|
|
48
|
+
const id = stack.pop();
|
|
49
|
+
layerOf.set(id, layers[i].id);
|
|
50
|
+
for (const k of children.get(id) ?? []) stack.push(k.id);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
if (anchor) layerOf.set(anchor.id, layers[0].id);
|
|
54
|
+
return { layers, layerOf, anchor: anchor?.id };
|
|
55
|
+
}
|
|
56
|
+
function layerIndexOf(derived, id) {
|
|
57
|
+
const lid = derived.layerOf.get(id);
|
|
58
|
+
return lid ? derived.layers.findIndex((l) => l.id === lid) : -1;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
export {
|
|
62
|
+
orderedChildren,
|
|
63
|
+
childrenMap,
|
|
64
|
+
deriveLayers,
|
|
65
|
+
layerIndexOf
|
|
66
|
+
};
|
|
@@ -22,6 +22,9 @@ var EN = {
|
|
|
22
22
|
stackLayer: (l, on) => `${on ? "Hide" : "Stack"} \u201C${l}\u201D`,
|
|
23
23
|
stack: "Stack layers",
|
|
24
24
|
stackTip: (on) => on ? "Stacked (turn off to view one layer at a time)" : "Stack layers (2.5D)",
|
|
25
|
+
layersOff: "Layers are off",
|
|
26
|
+
forceLayers: "Open the floors anyway",
|
|
27
|
+
ok: "OK",
|
|
25
28
|
more: "More",
|
|
26
29
|
origins: "Source",
|
|
27
30
|
allOrigins: "All sources",
|
|
@@ -34,6 +37,7 @@ var EN = {
|
|
|
34
37
|
fit: "Fit (0)",
|
|
35
38
|
legend: "Legend",
|
|
36
39
|
legendPlainName: "Default",
|
|
40
|
+
noColor: "no colour set",
|
|
37
41
|
legendPlain: "Nodes without a color of their own: containers and placeholders, shaded by how much hangs under them",
|
|
38
42
|
legendContainsName: "Contains",
|
|
39
43
|
legendHint: "Hover an item: color, hide, size",
|
|
@@ -50,7 +54,7 @@ var EN = {
|
|
|
50
54
|
addNode: "Add node\u2026",
|
|
51
55
|
addEdge: "Add edge\u2026",
|
|
52
56
|
relayout: "Re-layout",
|
|
53
|
-
restructure: "
|
|
57
|
+
restructure: "Re-structure",
|
|
54
58
|
edit: "Edit",
|
|
55
59
|
editNode: "Edit node",
|
|
56
60
|
newNode: "New node",
|
|
@@ -80,6 +84,10 @@ var EN = {
|
|
|
80
84
|
"no-node": "Node not found",
|
|
81
85
|
"no-parent": "Parent not found",
|
|
82
86
|
cycle: "Cannot be placed inside itself",
|
|
87
|
+
"id-format": "Use 1\u201380 characters without spaces or @",
|
|
88
|
+
"multiple-roots": "Keep one root: choose an existing parent",
|
|
89
|
+
"order-mixed": "Siblings must all be numbered or all unordered",
|
|
90
|
+
"order-invalid": "Order must be positive and unique among siblings (blank = unordered)",
|
|
83
91
|
"has-children": "Has children \u2014 delete or move them first",
|
|
84
92
|
"no-endpoint": "Pick both ends",
|
|
85
93
|
"self-loop": "Both ends are the same node",
|
|
@@ -52,17 +52,17 @@ import {
|
|
|
52
52
|
unionSides,
|
|
53
53
|
untheme,
|
|
54
54
|
validateModel
|
|
55
|
-
} from "./chunk-
|
|
55
|
+
} from "./chunk-SEOAVI3E.js";
|
|
56
56
|
import {
|
|
57
57
|
DetailPanel,
|
|
58
58
|
I,
|
|
59
59
|
Icon,
|
|
60
60
|
StringsContext,
|
|
61
61
|
useStrings
|
|
62
|
-
} from "./chunk-
|
|
62
|
+
} from "./chunk-3JGZ27DC.js";
|
|
63
63
|
import {
|
|
64
64
|
EN
|
|
65
|
-
} from "./chunk-
|
|
65
|
+
} from "./chunk-ISWKAU5G.js";
|
|
66
66
|
import {
|
|
67
67
|
inlinePool
|
|
68
68
|
} from "./chunk-YGRPNAXE.js";
|
|
@@ -912,19 +912,26 @@ function resolveOverlaps(boxes, o = {}) {
|
|
|
912
912
|
}
|
|
913
913
|
|
|
914
914
|
// src/layout/order.ts
|
|
915
|
+
var VIRTUAL_PARENT = "";
|
|
915
916
|
function readOrder(elements) {
|
|
916
|
-
const parentOf = /* @__PURE__ */ new Map();
|
|
917
|
-
const kids = /* @__PURE__ */ new Map();
|
|
918
917
|
const nodeIds = /* @__PURE__ */ new Set();
|
|
918
|
+
const rawParent = /* @__PURE__ */ new Map();
|
|
919
|
+
const rawOrder = /* @__PURE__ */ new Map();
|
|
919
920
|
for (const el of elements) {
|
|
920
921
|
const id = el.data.id;
|
|
921
922
|
if (!id || el.data.source) continue;
|
|
922
923
|
nodeIds.add(id);
|
|
923
|
-
const
|
|
924
|
-
if (
|
|
925
|
-
parentOf.set(id, parent);
|
|
924
|
+
const p = el.data.parentId ?? el.data.parent;
|
|
925
|
+
if (p) rawParent.set(id, p);
|
|
926
926
|
const raw = el.data.order;
|
|
927
|
-
|
|
927
|
+
rawOrder.set(id, typeof raw === "number" && Number.isFinite(raw) ? raw : null);
|
|
928
|
+
}
|
|
929
|
+
const parentOf = /* @__PURE__ */ new Map();
|
|
930
|
+
const kids = /* @__PURE__ */ new Map();
|
|
931
|
+
for (const [id, p] of rawParent) {
|
|
932
|
+
const parent = nodeIds.has(p) ? p : VIRTUAL_PARENT;
|
|
933
|
+
parentOf.set(id, parent);
|
|
934
|
+
const order = rawOrder.get(id) ?? null;
|
|
928
935
|
const arr = kids.get(parent);
|
|
929
936
|
arr ? arr.push({ id, order }) : kids.set(parent, [{ id, order }]);
|
|
930
937
|
}
|
|
@@ -997,12 +1004,16 @@ function orderSeed(elements, info) {
|
|
|
997
1004
|
}
|
|
998
1005
|
};
|
|
999
1006
|
if (roots.length === 1) place(roots[0], 0, 0, -Math.PI / 2, Math.PI * 1.5, 0);
|
|
1000
|
-
else {
|
|
1007
|
+
else if (roots.length > 1) {
|
|
1001
1008
|
roots.forEach((root, i) => {
|
|
1002
1009
|
const from = -Math.PI / 2 + TAU * i / roots.length;
|
|
1003
1010
|
place(root, 0, 0, from, from + TAU / roots.length, 0);
|
|
1004
1011
|
});
|
|
1005
1012
|
}
|
|
1013
|
+
if ((children.get(VIRTUAL_PARENT) ?? []).length) {
|
|
1014
|
+
place(VIRTUAL_PARENT, 0, 0, -Math.PI / 2, Math.PI * 1.5, 0);
|
|
1015
|
+
delete out[VIRTUAL_PARENT];
|
|
1016
|
+
}
|
|
1006
1017
|
return out;
|
|
1007
1018
|
}
|
|
1008
1019
|
var angle = (p) => Math.atan2(p.y, p.x);
|
|
@@ -1042,10 +1053,16 @@ function enforceOrder(elements, info, positions) {
|
|
|
1042
1053
|
};
|
|
1043
1054
|
const settle = (parent) => {
|
|
1044
1055
|
const list = info.orderedKids.get(parent);
|
|
1045
|
-
|
|
1046
|
-
|
|
1056
|
+
if (!list) {
|
|
1057
|
+
for (const id of children.get(parent) ?? []) settle(id);
|
|
1058
|
+
return;
|
|
1059
|
+
}
|
|
1047
1060
|
const present = list.filter((id) => out[id]);
|
|
1048
1061
|
if (present.length < 2) return;
|
|
1062
|
+
const pivot = out[parent] ?? {
|
|
1063
|
+
x: present.reduce((s, id) => s + out[id].x, 0) / present.length,
|
|
1064
|
+
y: present.reduce((s, id) => s + out[id].y, 0) / present.length
|
|
1065
|
+
};
|
|
1049
1066
|
const total = present.reduce((s, id) => s + weigh(id), 0) || 1;
|
|
1050
1067
|
let at = angle({ x: out[present[0]].x - pivot.x, y: out[present[0]].y - pivot.y });
|
|
1051
1068
|
for (const id of present) {
|
|
@@ -1061,6 +1078,7 @@ function enforceOrder(elements, info, positions) {
|
|
|
1061
1078
|
};
|
|
1062
1079
|
const roots = [...info.nodeIds].filter((id) => !info.parentOf.has(id));
|
|
1063
1080
|
for (const root of roots) settle(root);
|
|
1081
|
+
if (children.has(VIRTUAL_PARENT)) settle(VIRTUAL_PARENT);
|
|
1064
1082
|
return out;
|
|
1065
1083
|
}
|
|
1066
1084
|
|
|
@@ -1190,6 +1208,18 @@ async function runDivide(req, aborted) {
|
|
|
1190
1208
|
}
|
|
1191
1209
|
const rootDims = req.elements.some((e) => e.data.id === VIRTUAL_ROOT && !e.data.source) && req.dims[VIRTUAL_ROOT] ? req.dims[VIRTUAL_ROOT] : void 0;
|
|
1192
1210
|
const coarseEls = buildCoarseElements(comps, compOf, req.elements, (k) => byKey.get(k).bbox, rootDims);
|
|
1211
|
+
if (req.seed) {
|
|
1212
|
+
const seed2 = req.seed;
|
|
1213
|
+
const compByKey = new Map(comps.map((c) => [c.key, c]));
|
|
1214
|
+
const mid = (pts) => pts.length ? { x: pts.reduce((s, q2) => s + q2.x, 0) / pts.length, y: pts.reduce((s, q2) => s + q2.y, 0) / pts.length } : void 0;
|
|
1215
|
+
for (const el of coarseEls) {
|
|
1216
|
+
if (el.data.source) continue;
|
|
1217
|
+
const key = el.data.id;
|
|
1218
|
+
const pts = key === VIRTUAL_ROOT ? Object.values(seed2) : (compByKey.get(key)?.nodes ?? []).map((n) => seed2[n.data.id]).filter(Boolean);
|
|
1219
|
+
const p = mid(pts);
|
|
1220
|
+
if (p) el.position = p;
|
|
1221
|
+
}
|
|
1222
|
+
}
|
|
1193
1223
|
const avgSize = comps.reduce((s, c) => {
|
|
1194
1224
|
const b = byKey.get(c.key).bbox;
|
|
1195
1225
|
return s + (b.w + b.h) / 2;
|
|
@@ -1717,7 +1747,7 @@ function Hl({ text, re }) {
|
|
|
1717
1747
|
out.push(text.slice(last));
|
|
1718
1748
|
return /* @__PURE__ */ jsx(Fragment, { children: out });
|
|
1719
1749
|
}
|
|
1720
|
-
function LayerPicker({ layers, view, setView, disabled }) {
|
|
1750
|
+
function LayerPicker({ layers, view, setView, disabled, collapsed }) {
|
|
1721
1751
|
const t = useStrings();
|
|
1722
1752
|
const box = useRef(null);
|
|
1723
1753
|
const [thumb, setThumb] = useState2(null);
|
|
@@ -1727,7 +1757,7 @@ function LayerPicker({ layers, view, setView, disabled }) {
|
|
|
1727
1757
|
const single = stacked ? null : view.layers?.[0] ?? layers[0].id;
|
|
1728
1758
|
useLayoutEffect2(() => {
|
|
1729
1759
|
const root = box.current;
|
|
1730
|
-
if (!root || single == null) {
|
|
1760
|
+
if (collapsed || !root || single == null) {
|
|
1731
1761
|
setThumb(null);
|
|
1732
1762
|
return;
|
|
1733
1763
|
}
|
|
@@ -1767,8 +1797,8 @@ function LayerPicker({ layers, view, setView, disabled }) {
|
|
|
1767
1797
|
const next = layers.map((l) => l.id).filter((l) => l === id ? !on.has(l) : on.has(l));
|
|
1768
1798
|
setView({ layers: next });
|
|
1769
1799
|
};
|
|
1770
|
-
return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-layers${stacked ? " is-multi" : ""}`, role: stacked ? "group" : "radiogroup", children: [
|
|
1771
|
-
/* @__PURE__ */ jsxs("div", { className: `gb-layer-track${edges.left ? " can-left" : ""}${edges.right ? " can-right" : ""}`, ref: box, children: [
|
|
1800
|
+
return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-layers${stacked ? " is-multi" : ""}${collapsed ? " is-collapsed" : ""}`, role: stacked ? "group" : "radiogroup", children: [
|
|
1801
|
+
/* @__PURE__ */ jsxs("div", { className: `gb-layer-track${edges.left ? " can-left" : ""}${edges.right ? " can-right" : ""}`, ref: box, "aria-hidden": collapsed, children: [
|
|
1772
1802
|
thumb && /* @__PURE__ */ jsx("i", { className: "gb-thumb", style: { transform: `translateX(${thumb.x}px)`, width: thumb.w } }),
|
|
1773
1803
|
layers.map((l) => {
|
|
1774
1804
|
const lit = stacked ? on.has(l.id) : l.id === single;
|
|
@@ -1796,9 +1826,51 @@ function LayerPicker({ layers, view, setView, disabled }) {
|
|
|
1796
1826
|
disabled,
|
|
1797
1827
|
"aria-label": t.stack,
|
|
1798
1828
|
title: t.stackTip(stacked),
|
|
1799
|
-
onClick: () => setView(stacked ? { planes: false } : { planes: true, layers: null }),
|
|
1829
|
+
onClick: () => setView(stacked ? { planes: false, layers: null } : { planes: true, layers: null }),
|
|
1830
|
+
children: /* @__PURE__ */ jsx(Icon, { d: I.stack })
|
|
1831
|
+
}
|
|
1832
|
+
)
|
|
1833
|
+
] });
|
|
1834
|
+
}
|
|
1835
|
+
function LayerUnavailable(p) {
|
|
1836
|
+
const t = useStrings();
|
|
1837
|
+
const pop = usePopover(MENU_PLACE);
|
|
1838
|
+
return /* @__PURE__ */ jsxs("div", { className: "gb-menu", ref: pop.ref, children: [
|
|
1839
|
+
/* @__PURE__ */ jsx(
|
|
1840
|
+
"button",
|
|
1841
|
+
{
|
|
1842
|
+
className: "gb-icon-btn",
|
|
1843
|
+
style: { opacity: 0.45 },
|
|
1844
|
+
"aria-label": t.layersOff,
|
|
1845
|
+
title: t.layersOff,
|
|
1846
|
+
"aria-expanded": pop.open,
|
|
1847
|
+
onClick: () => pop.setOpen(!pop.open),
|
|
1800
1848
|
children: /* @__PURE__ */ jsx(Icon, { d: I.stack })
|
|
1801
1849
|
}
|
|
1850
|
+
),
|
|
1851
|
+
pop.open && /* @__PURE__ */ jsxs(
|
|
1852
|
+
"div",
|
|
1853
|
+
{
|
|
1854
|
+
ref: pop.panelRef,
|
|
1855
|
+
className: "gb-panel",
|
|
1856
|
+
role: "dialog",
|
|
1857
|
+
"data-x": pop.placement?.align,
|
|
1858
|
+
"data-y": pop.placement?.side,
|
|
1859
|
+
style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
|
|
1860
|
+
children: [
|
|
1861
|
+
/* @__PURE__ */ jsxs("div", { className: "gb-panel-sec", children: [
|
|
1862
|
+
/* @__PURE__ */ jsx("div", { className: "gb-panel-h", children: t.layersOff }),
|
|
1863
|
+
/* @__PURE__ */ jsx("p", { style: { margin: "4px 0 0", maxWidth: 260, fontSize: 12, lineHeight: 1.45, opacity: 0.75 }, children: p.reason })
|
|
1864
|
+
] }),
|
|
1865
|
+
/* @__PURE__ */ jsxs("div", { className: "gb-panel-sec gb-menu-list", children: [
|
|
1866
|
+
p.onForce && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: () => {
|
|
1867
|
+
pop.setOpen(false);
|
|
1868
|
+
p.onForce();
|
|
1869
|
+
}, children: t.forceLayers }),
|
|
1870
|
+
/* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: () => pop.setOpen(false), children: t.ok })
|
|
1871
|
+
] })
|
|
1872
|
+
]
|
|
1873
|
+
}
|
|
1802
1874
|
)
|
|
1803
1875
|
] });
|
|
1804
1876
|
}
|
|
@@ -2005,7 +2077,8 @@ function Toolbar(p) {
|
|
|
2005
2077
|
inputRef: p.inputRef
|
|
2006
2078
|
}
|
|
2007
2079
|
),
|
|
2008
|
-
multi && /* @__PURE__ */ jsx(LayerPicker, { layers: p.layers, view, setView, disabled: p.busy }),
|
|
2080
|
+
multi && /* @__PURE__ */ jsx(LayerPicker, { layers: p.layers, view, setView, disabled: p.busy, collapsed: !view.planes }),
|
|
2081
|
+
controls.layers && !multi && /* @__PURE__ */ jsx(LayerUnavailable, { reason: p.layerIssue ?? "", onForce: p.onForceLayers }),
|
|
2009
2082
|
originPick && view.origins?.length === 1 && /* Filtering by source: the state is in plain sight, and one × returns to everything. */
|
|
2010
2083
|
/* @__PURE__ */ jsxs("span", { className: "gb-chip", title: view.origins[0], children: [
|
|
2011
2084
|
/* @__PURE__ */ jsx(Icon, { d: I.file, size: 13 }),
|
|
@@ -2599,6 +2672,7 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2599
2672
|
[node]
|
|
2600
2673
|
);
|
|
2601
2674
|
const [text, setText] = useState3(initial);
|
|
2675
|
+
const [orderText, setOrderText] = useState3(node?.order?.toString() ?? "");
|
|
2602
2676
|
const [confirming, setConfirming] = useState3(false);
|
|
2603
2677
|
const idErr = creating && id ? checkEdit(model, { op: "addNode", id, set: {} }) : null;
|
|
2604
2678
|
const below = useMemo2(() => {
|
|
@@ -2622,8 +2696,9 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2622
2696
|
setError(t.badJson);
|
|
2623
2697
|
return;
|
|
2624
2698
|
}
|
|
2699
|
+
const order = parent && orderText.trim() ? Number(orderText) : null;
|
|
2625
2700
|
if (creating) {
|
|
2626
|
-
if (submit({ op: "addNode", id: id.trim(), set: { ...content, parent } })) onCancel();
|
|
2701
|
+
if (submit({ op: "addNode", id: id.trim(), set: { ...content, parent, order } })) onCancel();
|
|
2627
2702
|
return;
|
|
2628
2703
|
}
|
|
2629
2704
|
const set = {};
|
|
@@ -2631,6 +2706,7 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2631
2706
|
if ((content.kind ?? void 0) !== node.kind) set.kind = content.kind;
|
|
2632
2707
|
if (pretty(content.data ?? {}) !== pretty(node.data ?? {})) set.data = content.data ?? {};
|
|
2633
2708
|
if (parent !== (node.parent ?? null)) set.parent = parent;
|
|
2709
|
+
if (order !== (node.order ?? null)) set.order = order;
|
|
2634
2710
|
if (!Object.keys(set).length) {
|
|
2635
2711
|
onCancel();
|
|
2636
2712
|
return;
|
|
@@ -2696,6 +2772,23 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2696
2772
|
}
|
|
2697
2773
|
)
|
|
2698
2774
|
] }),
|
|
2775
|
+
/* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
|
|
2776
|
+
/* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-order`, children: "Order" }),
|
|
2777
|
+
/* @__PURE__ */ jsx2(
|
|
2778
|
+
"input",
|
|
2779
|
+
{
|
|
2780
|
+
id: `${uid}-order`,
|
|
2781
|
+
className: "gb-input",
|
|
2782
|
+
type: "number",
|
|
2783
|
+
min: "0",
|
|
2784
|
+
step: "any",
|
|
2785
|
+
disabled: !parent,
|
|
2786
|
+
placeholder: "Unordered",
|
|
2787
|
+
value: orderText,
|
|
2788
|
+
onChange: (e) => setOrderText(e.target.value)
|
|
2789
|
+
}
|
|
2790
|
+
)
|
|
2791
|
+
] }),
|
|
2699
2792
|
/* @__PURE__ */ jsxs2("div", { className: "gb-fld gb-grow", children: [
|
|
2700
2793
|
/* @__PURE__ */ jsxs2("label", { className: "gb-k", htmlFor: `${uid}-json`, children: [
|
|
2701
2794
|
t.content,
|
|
@@ -2846,7 +2939,7 @@ function tally(model, profile) {
|
|
|
2846
2939
|
let plain = 0;
|
|
2847
2940
|
for (const n of model.nodes) {
|
|
2848
2941
|
const hollow = !!n.flags?.some((f) => profile.placeholderFlags.includes(f));
|
|
2849
|
-
if (!hollow && n.kind
|
|
2942
|
+
if (!hollow && n.kind) nodes[n.kind] = (nodes[n.kind] ?? 0) + 1;
|
|
2850
2943
|
else plain++;
|
|
2851
2944
|
}
|
|
2852
2945
|
for (const e of model.edges) if (e.kind && e.kind in profile.edgePalette) edges[e.kind] = (edges[e.kind] ?? 0) + 1;
|
|
@@ -3155,7 +3248,7 @@ function Legend(p) {
|
|
|
3155
3248
|
picking: (on) => setPicking(on)
|
|
3156
3249
|
}), [close]);
|
|
3157
3250
|
const slot = (key) => ({ k: key, open: open === key, ctl });
|
|
3158
|
-
const nodeKinds = Object.keys(
|
|
3251
|
+
const nodeKinds = Object.keys(count.nodes).sort((a, b) => count.nodes[b] - count.nodes[a] || a.localeCompare(b));
|
|
3159
3252
|
const edgeKinds = Object.keys(profile.edgePalette).filter((k) => count.edges[k]);
|
|
3160
3253
|
const markCache = useRef3({ cy: null, style: null, shapes: /* @__PURE__ */ new Map(), strokes: /* @__PURE__ */ new Map() });
|
|
3161
3254
|
const marks = readMarks(markCache.current, p.cy, profile.style, nodeKinds, edgeKinds);
|
|
@@ -3169,6 +3262,7 @@ function Legend(p) {
|
|
|
3169
3262
|
const set = (key, kind, v) => onLook({ ...look, [key]: { ...look[key], [kind]: v } });
|
|
3170
3263
|
const setSkeleton = (c) => onLook({ ...look, skeleton: c });
|
|
3171
3264
|
const name = (k) => profile.kindLabels[k] ?? k;
|
|
3265
|
+
const colorOfKind = (k) => profile.nodePalette[k] ?? theme.skeleton;
|
|
3172
3266
|
const shown = (c) => themeColor(theme, c);
|
|
3173
3267
|
const content = p.collapsed ? /* @__PURE__ */ jsx3(
|
|
3174
3268
|
"button",
|
|
@@ -3185,7 +3279,7 @@ function Legend(p) {
|
|
|
3185
3279
|
/* @__PURE__ */ jsxs3("div", { className: "gb-lg-body", children: [
|
|
3186
3280
|
p.caption && /* @__PURE__ */ jsx3("div", { className: "gb-lg-cap", children: p.caption }),
|
|
3187
3281
|
/* @__PURE__ */ jsxs3("div", { className: "gb-lg-row", children: [
|
|
3188
|
-
/* @__PURE__ */ jsx3(
|
|
3282
|
+
count.plain > 0 && /* @__PURE__ */ jsx3(
|
|
3189
3283
|
Item,
|
|
3190
3284
|
{
|
|
3191
3285
|
...slot("n:"),
|
|
@@ -3204,15 +3298,15 @@ function Legend(p) {
|
|
|
3204
3298
|
Item,
|
|
3205
3299
|
{
|
|
3206
3300
|
...slot(`n:${k}`),
|
|
3207
|
-
color: shown(
|
|
3208
|
-
title: name(k)
|
|
3301
|
+
color: shown(colorOfKind(k)),
|
|
3302
|
+
title: profile.nodePalette[k] ? name(k) : `${name(k)} \u2014 ${t.noColor}`,
|
|
3209
3303
|
off,
|
|
3210
3304
|
onToggle: () => p.onToggle("nodes", k),
|
|
3211
3305
|
onPick: (c) => set("nodePalette", k, untheme(theme, c)),
|
|
3212
3306
|
scale,
|
|
3213
3307
|
glyph: "dot",
|
|
3214
3308
|
onScale: (s) => set("nodeSize", k, s),
|
|
3215
|
-
mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(
|
|
3309
|
+
mark: /* @__PURE__ */ jsx3(NodeMark, { color: shown(colorOfKind(k)), shape: marks.shape(k), ring: theme.canvas, off, scale }),
|
|
3216
3310
|
label: name(k),
|
|
3217
3311
|
count: count.nodes[k]
|
|
3218
3312
|
},
|
|
@@ -3737,6 +3831,8 @@ function GraphCanvas(props) {
|
|
|
3737
3831
|
renderEditor,
|
|
3738
3832
|
resolveUrl,
|
|
3739
3833
|
onRestructure,
|
|
3834
|
+
layerIssue,
|
|
3835
|
+
onForceLayers,
|
|
3740
3836
|
animate = true,
|
|
3741
3837
|
matchKey,
|
|
3742
3838
|
onTransition,
|
|
@@ -3843,6 +3939,9 @@ function GraphCanvas(props) {
|
|
|
3843
3939
|
const searchInputRef = useRef4(null);
|
|
3844
3940
|
const [selected, setSelected] = useState5(null);
|
|
3845
3941
|
const [editing, setEditing] = useState5(null);
|
|
3942
|
+
const editingModel = props.editModel ?? model;
|
|
3943
|
+
const modelRef = useRef4(model);
|
|
3944
|
+
modelRef.current = model;
|
|
3846
3945
|
const editable = !!onEdit && !diff;
|
|
3847
3946
|
const onEditRef = useRef4(onEdit);
|
|
3848
3947
|
onEditRef.current = onEdit;
|
|
@@ -4585,7 +4684,9 @@ function GraphCanvas(props) {
|
|
|
4585
4684
|
origin: d.origin,
|
|
4586
4685
|
container: builtRef.current.containers.has(d.id),
|
|
4587
4686
|
flags: el.classes().filter((c) => !["gb-node", "flat", "container", "gb-hit", "gb-preview", "gb-preview-hop", d.kind].includes(c)),
|
|
4588
|
-
detail: d.detail ?? null
|
|
4687
|
+
detail: d.detail ?? null,
|
|
4688
|
+
parent: modelRef.current.index.get(d.id)?.parent,
|
|
4689
|
+
order: modelRef.current.index.get(d.id)?.order
|
|
4589
4690
|
});
|
|
4590
4691
|
}, []);
|
|
4591
4692
|
const selectTouch = useCallback2((target) => {
|
|
@@ -4861,7 +4962,7 @@ function GraphCanvas(props) {
|
|
|
4861
4962
|
return { positions, source: "preset" };
|
|
4862
4963
|
}
|
|
4863
4964
|
let known;
|
|
4864
|
-
if (
|
|
4965
|
+
if (force || layoutModeRef.current === "continue") {
|
|
4865
4966
|
const all = { ...preset, ...rawRef.current };
|
|
4866
4967
|
known = {};
|
|
4867
4968
|
for (const id of ids) if (all[id]) known[id] = all[id];
|
|
@@ -5502,6 +5603,8 @@ ${lt}`;
|
|
|
5502
5603
|
if (!s || !n) return null;
|
|
5503
5604
|
return {
|
|
5504
5605
|
...s,
|
|
5606
|
+
parent: n.parent,
|
|
5607
|
+
order: n.order,
|
|
5505
5608
|
label: n.label,
|
|
5506
5609
|
kind: n.kind ?? "",
|
|
5507
5610
|
layer: n.layer,
|
|
@@ -5518,14 +5621,14 @@ ${lt}`;
|
|
|
5518
5621
|
const submitEdit = useCallback2((input) => {
|
|
5519
5622
|
const only = view.origins?.length === 1 ? view.origins[0] : void 0;
|
|
5520
5623
|
const op = input.op === "addNode" && only && !input.origin ? { ...input, origin: only } : input;
|
|
5521
|
-
const err = checkEdit(
|
|
5624
|
+
const err = checkEdit(editingModel, op) ?? props.validateEdit?.(op);
|
|
5522
5625
|
if (err) return err;
|
|
5523
5626
|
if (op.op === "addNode") pendingPickRef.current = op.id;
|
|
5524
5627
|
else if (op.op === "removeNode") setSelected(null);
|
|
5525
5628
|
else keepSelRef.current = selected?.id ?? null;
|
|
5526
5629
|
onEditRef.current?.(op);
|
|
5527
5630
|
return null;
|
|
5528
|
-
}, [
|
|
5631
|
+
}, [editingModel, selected, view.origins, props.validateEdit]);
|
|
5529
5632
|
const startAdd = useCallback2((what) => {
|
|
5530
5633
|
setEditing(what === "node" ? { what, parent: selected?.id ?? null } : { what, source: selected?.id });
|
|
5531
5634
|
}, [selected]);
|
|
@@ -5533,7 +5636,7 @@ ${lt}`;
|
|
|
5533
5636
|
EditPanel,
|
|
5534
5637
|
{
|
|
5535
5638
|
target: editing,
|
|
5536
|
-
model,
|
|
5639
|
+
model: editingModel,
|
|
5537
5640
|
onSubmit: submitEdit,
|
|
5538
5641
|
renderEditor,
|
|
5539
5642
|
colorOf,
|
|
@@ -5679,7 +5782,9 @@ ${lt}`;
|
|
|
5679
5782
|
inputRef: searchInputRef,
|
|
5680
5783
|
onAdd: editable ? startAdd : void 0,
|
|
5681
5784
|
onRelayout: controls.relayout && !diff ? relayout : void 0,
|
|
5682
|
-
onRestructure: controls.relayout && !diff ? onRestructure : void 0
|
|
5785
|
+
onRestructure: controls.relayout && !diff ? onRestructure : void 0,
|
|
5786
|
+
layerIssue,
|
|
5787
|
+
onForceLayers
|
|
5683
5788
|
}
|
|
5684
5789
|
),
|
|
5685
5790
|
(note || model.errors.length > 0 || legend && !compact) && /* Bottom left: the host's caption (if any) on top, the legend below. Top left is tools, bottom right is the camera. */
|