glassbrain 0.2.0-alpha.3 → 0.2.0-alpha.5
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 +15 -11
- package/dist/chunks/{chunk-PBF4KMQB.js → chunk-3JGZ27DC.js} +10 -1
- package/dist/chunks/{chunk-WW23WBYG.js → chunk-F4HDKER4.js} +88 -23
- package/dist/chunks/{chunk-QJ4B3U76.js → chunk-G7XWVKHN.js} +1 -3
- package/dist/chunks/{chunk-H2WV3DTN.js → chunk-ISWKAU5G.js} +5 -1
- package/dist/chunks/{chunk-YGRPNAXE.js → chunk-OE5IRKWZ.js} +8 -1
- package/dist/chunks/{chunk-7C3QZVGJ.js → chunk-WUBELTBU.js} +148 -148
- package/dist/cli/glassbrain.js +693 -531
- package/dist/cli/viewer.js +51 -48
- package/dist/core.js +9 -5
- package/dist/edit.d.ts +4 -1
- package/dist/elements.d.ts +2 -0
- package/dist/index.js +12 -8
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +14 -8
- package/dist/layers.d.ts +0 -2
- package/dist/layout/engine.d.ts +3 -1
- package/dist/layout/inline-pool.js +1 -1
- package/dist/layout/order.d.ts +9 -6
- package/dist/layout/worker.js +7 -1
- package/dist/model.d.ts +5 -2
- package/dist/paint.d.ts +2 -0
- package/dist/react/DetailPanel.d.ts +2 -0
- package/dist/react/DetailPanel.js +2 -2
- package/dist/react/GraphCanvas.d.ts +10 -4
- package/dist/react/GraphCanvas.js +5 -5
- package/dist/react/Toolbar.d.ts +3 -2
- package/package.json +3 -2
- package/schema/graph.schema.json +3 -4
- package/README.zh-CN.md +0 -938
package/README.md
CHANGED
|
@@ -23,15 +23,15 @@ 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
|
-
Next to it, one colour per kind — a kind with no colour is drawn as skeleton, so `
|
|
34
|
+
Next to it, one colour per kind — a kind with no colour is drawn as skeleton, so `lint` reports
|
|
35
35
|
it as an error (forty kinds without colours look exactly like one kind):
|
|
36
36
|
|
|
37
37
|
```json
|
|
@@ -39,21 +39,25 @@ it as an error (forty kinds without colours look exactly like one kind):
|
|
|
39
39
|
"edgePalette": { "uses": "#2563eb" } }
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
-
`parent` is required on every node (null for the one root) and says what sits inside what
|
|
43
|
-
|
|
44
|
-
|
|
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 when seeding recursive sectors: the outer circle has `n+1` equal sectors for `n` children, with
|
|
45
|
+
sector 0 empty and centered at the top. Descendants subdivide their parent’s angular interval around the same
|
|
46
|
+
origin, without adding further empty sectors. Each child samples a small normal angular offset; unordered siblings also
|
|
47
|
+
shuffle sector order. Re-layout discards saved coordinates and samples a new seed. The force solver relaxes it
|
|
48
|
+
without a final rotation. A root whose children are numbered *is* the 2.5D layer view. There is no layer field.
|
|
45
49
|
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
|
|
46
|
-
agent can act on —
|
|
50
|
+
agent can act on — findings identify the problem and structural advice suggests a next step:
|
|
47
51
|
|
|
48
52
|
```text
|
|
49
|
-
$ npx glassbrain
|
|
53
|
+
$ npx glassbrain lint kg
|
|
50
54
|
error dangling-edge graph.json edge src/auth/login.ts → src/session points at the missing node src/session
|
|
51
55
|
an edge can only join nodes that exist. Add the node, or repoint the edge:
|
|
52
56
|
- { "source": "src/auth/login.ts", "target": "src/session" }
|
|
53
57
|
+ { "source": "src/auth/login.ts", "target": "EXISTING_ID" }
|
|
54
58
|
|
|
55
59
|
kg: 2 nodes, 1 edge — 1 error · 0 warnings · 0 infos
|
|
56
|
-
structure: 1 root · depth 2 · 1/2 parented ·
|
|
60
|
+
structure: 1 root · depth 2 · 1/2 parented · structure pressure 0.000 · 0 assessed / 1 unassessed
|
|
57
61
|
|
|
58
62
|
$ npx glassbrain diff kg/1-skeleton kg/2-filled
|
|
59
63
|
1-skeleton → 2-filled
|
|
@@ -65,7 +69,7 @@ changed (1)
|
|
|
65
69
|
```
|
|
66
70
|
|
|
67
71
|
Errors exit 1 (`--strict`: warnings too), `diff --exit-code` exits 1 when anything changed, and
|
|
68
|
-
`--json` gives the same as structured output. So an agent can build a graph in steps,
|
|
72
|
+
`--json` gives the same as structured output. So an agent can build a graph in steps, lint
|
|
69
73
|
each one, and check that a step did only its job.
|
|
70
74
|
|
|
71
75
|
## 2. Read it like a brain scan
|
|
@@ -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;
|
|
@@ -90,6 +90,19 @@ function originsOf(model) {
|
|
|
90
90
|
for (const n of model.nodes) for (const o of originsOfNode(n)) seen.add(o);
|
|
91
91
|
return [...seen].sort();
|
|
92
92
|
}
|
|
93
|
+
function encodeParent(parent, order) {
|
|
94
|
+
if (!parent) return null;
|
|
95
|
+
if (order === void 0) return `${parent}@-1`;
|
|
96
|
+
if (!Number.isFinite(order) || order <= 0) throw new Error("order must be finite and positive");
|
|
97
|
+
const text = String(order);
|
|
98
|
+
if (!/[eE]/.test(text)) return `${parent}@${text}`;
|
|
99
|
+
const [mantissa, exponent] = text.toLowerCase().split("e");
|
|
100
|
+
const [whole, fraction = ""] = mantissa.split(".");
|
|
101
|
+
const digits = whole + fraction;
|
|
102
|
+
const at = whole.length + Number(exponent);
|
|
103
|
+
const decimal = at <= 0 ? `0.${"0".repeat(-at)}${digits}` : at >= digits.length ? digits + "0".repeat(at - digits.length) : `${digits.slice(0, at)}.${digits.slice(at)}`;
|
|
104
|
+
return `${parent}@${decimal}`;
|
|
105
|
+
}
|
|
93
106
|
|
|
94
107
|
// src/profile.ts
|
|
95
108
|
function parsePhysical(origin, text) {
|
|
@@ -101,18 +114,29 @@ function parsePhysical(origin, text) {
|
|
|
101
114
|
}
|
|
102
115
|
if (!raw || typeof raw !== "object" || !("nodes" in raw) && !("edges" in raw)) return null;
|
|
103
116
|
const ref = (v) => typeof v === "string" || typeof v === "number" ? String(v) : void 0;
|
|
104
|
-
const
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
parent:
|
|
109
|
-
order
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
117
|
+
const parentOf = (v) => {
|
|
118
|
+
const rawParent = ref(v);
|
|
119
|
+
const at = rawParent?.lastIndexOf("@") ?? -1;
|
|
120
|
+
const tail = at > 0 ? rawParent.slice(at + 1) : "";
|
|
121
|
+
if (!/^(-1|\d+(\.\d+)?)$/.test(tail)) return { parent: rawParent, order: void 0 };
|
|
122
|
+
const order = tail === "-1" ? void 0 : Number(tail);
|
|
123
|
+
return { parent: rawParent.slice(0, at), order: order !== void 0 && order > 0 ? order : void 0 };
|
|
124
|
+
};
|
|
125
|
+
const nodes = (Array.isArray(raw.nodes) ? raw.nodes : []).filter((n) => n && typeof n === "object" && ref(n.id) !== void 0).map((n) => {
|
|
126
|
+
const { parent, order } = parentOf(n.parent);
|
|
127
|
+
return {
|
|
128
|
+
id: String(n.id),
|
|
129
|
+
label: String(n.label ?? n.name ?? n.id),
|
|
130
|
+
kind: typeof n.kind === "string" ? n.kind : void 0,
|
|
131
|
+
parent,
|
|
132
|
+
order,
|
|
133
|
+
layer: typeof n.layer === "string" ? n.layer : void 0,
|
|
134
|
+
// Marks carried by the data itself (e.g. a placeholder "with no content yet"). They are data, not derived: when the profile's
|
|
135
|
+
// `placeholderFlags` recognizes one, it is drawn as skeleton.
|
|
136
|
+
...Array.isArray(n.flags) ? { flags: n.flags.filter((f) => typeof f === "string") } : {},
|
|
137
|
+
data: n
|
|
138
|
+
};
|
|
139
|
+
});
|
|
116
140
|
const edges = (Array.isArray(raw.edges) ? raw.edges : []).filter((e) => e && typeof e === "object").map((e) => ({
|
|
117
141
|
source: String(e.source ?? e.from),
|
|
118
142
|
target: String(e.target ?? e.to),
|
|
@@ -128,8 +152,11 @@ function toPhysical(model) {
|
|
|
128
152
|
const clean = (o) => Object.fromEntries(Object.entries(o).filter(([, v]) => v !== void 0 && v !== ""));
|
|
129
153
|
return {
|
|
130
154
|
// `layer` is derived, never written: a file that gains it would freeze a view decision into the data.
|
|
131
|
-
// `parent` is always written, `null` for a root
|
|
132
|
-
nodes: model.nodes.map((n) =>
|
|
155
|
+
// `parent` is always written, `null` for a root, and carries the order: `"<id>@<order|-1>"`. `order` is never a field of its own.
|
|
156
|
+
nodes: model.nodes.map((n) => {
|
|
157
|
+
const { order: _order, layer: _layer, ...data } = n.data ?? {};
|
|
158
|
+
return clean({ ...data, id: n.id, label: n.label, kind: n.kind, parent: encodeParent(n.parent, n.order) });
|
|
159
|
+
}),
|
|
133
160
|
edges: model.edges.map((e) => clean({ ...e.data, source: e.source, target: e.target, kind: e.kind, label: e.label, weight: e.weight }))
|
|
134
161
|
};
|
|
135
162
|
}
|
|
@@ -499,6 +526,7 @@ function changedSubset(d) {
|
|
|
499
526
|
var VIRTUAL_ROOT = "__gk_root__";
|
|
500
527
|
var RESERVED_CLASSES = ["container", "crosslayer", "contains", "root", "gb-node"];
|
|
501
528
|
var cls = (s) => s.replace(/[^a-zA-Z0-9_-]/g, "_");
|
|
529
|
+
var edgeKindClass = (kind) => kind === "contains" ? "gb-relation-contains" : cls(kind);
|
|
502
530
|
function nodeClasses(n, profile, o) {
|
|
503
531
|
return [
|
|
504
532
|
"gb-node",
|
|
@@ -590,6 +618,8 @@ function buildElements(model, profile, opts = {}) {
|
|
|
590
618
|
layer,
|
|
591
619
|
origin: n.origin ?? null,
|
|
592
620
|
order: n.order ?? null,
|
|
621
|
+
// Parentage for the layout's order pass. A separate key, not `parent`: cytoscape treats `data.parent` as a compound.
|
|
622
|
+
parentId: effParent ?? null,
|
|
593
623
|
share: shareOf(n.id),
|
|
594
624
|
leaves: leavesOf(n.id),
|
|
595
625
|
detail: n.data ?? null,
|
|
@@ -626,7 +656,7 @@ function buildElements(model, profile, opts = {}) {
|
|
|
626
656
|
const { source, target } = e;
|
|
627
657
|
if (source === target) continue;
|
|
628
658
|
if (!nodeIds.has(source) || !nodeIds.has(target)) continue;
|
|
629
|
-
const id = e.id ?? `${e.kind ?? "e"}:${source}->${target}`;
|
|
659
|
+
const id = e.id ?? `${e.kind === "contains" ? "relation:contains" : e.kind ?? "e"}:${source}->${target}`;
|
|
630
660
|
if (seen.has(id)) continue;
|
|
631
661
|
seen.add(id);
|
|
632
662
|
const cross = layerOf.get(source) !== layerOf.get(target);
|
|
@@ -643,7 +673,7 @@ function buildElements(model, profile, opts = {}) {
|
|
|
643
673
|
_force: profile.layoutEdge(e)
|
|
644
674
|
},
|
|
645
675
|
classes: [
|
|
646
|
-
profile.edgeClass(e) || "plain",
|
|
676
|
+
(profile.edgeClass(e) || "plain").split(/\s+/).map(edgeKindClass).join(" "),
|
|
647
677
|
...(e.flags ?? []).map(cls),
|
|
648
678
|
cross ? "crosslayer" : ""
|
|
649
679
|
].filter(Boolean).join(" ")
|
|
@@ -681,8 +711,8 @@ function planeView(v, layers) {
|
|
|
681
711
|
if (layers.length < 2) return v.planes || v.layers ? { ...v, planes: false, layers: null } : v;
|
|
682
712
|
const stacked = v.planes !== false;
|
|
683
713
|
const picked = layers.map((l) => l.id).filter((id) => v.layers?.includes(id));
|
|
684
|
-
const want = stacked ? picked.length && picked.length < layers.length ? picked : null :
|
|
685
|
-
const same = v.planes === stacked && (want === null ? v.layers
|
|
714
|
+
const want = stacked ? picked.length && picked.length < layers.length ? picked : null : v.layers && picked.length === 1 ? picked : null;
|
|
715
|
+
const same = v.planes === stacked && (want === null ? v.layers === null : !!v.layers && want.length === v.layers.length && want.every((id, i) => id === v.layers[i]));
|
|
686
716
|
return same ? v : { ...v, planes: stacked, layers: want };
|
|
687
717
|
}
|
|
688
718
|
function isFiltering(v) {
|
|
@@ -1036,7 +1066,7 @@ function paletteStyle(profile, theme = LIGHT_THEME, nodeScale = 1) {
|
|
|
1036
1066
|
for (const [kind, raw] of Object.entries(profile.edgePalette ?? {})) {
|
|
1037
1067
|
const color = themeColor(theme, raw);
|
|
1038
1068
|
out.push({
|
|
1039
|
-
selector: `edge.${
|
|
1069
|
+
selector: `edge.${edgeKindClass(kind)}`,
|
|
1040
1070
|
style: { "line-color": color, "target-arrow-color": color, "source-arrow-color": color }
|
|
1041
1071
|
});
|
|
1042
1072
|
}
|
|
@@ -1047,7 +1077,7 @@ function paletteStyle(profile, theme = LIGHT_THEME, nodeScale = 1) {
|
|
|
1047
1077
|
out.push({ selector: `node.${cls(kind)}`, style: { width: size, height: size } });
|
|
1048
1078
|
}
|
|
1049
1079
|
for (const [kind, k] of Object.entries(profile.edgeWidth ?? {})) {
|
|
1050
|
-
if (k !== 1) out.push({ selector: `edge.${
|
|
1080
|
+
if (k !== 1) out.push({ selector: `edge.${edgeKindClass(kind)}`, style: { width: (el) => edgeWidthOf(el) * k } });
|
|
1051
1081
|
}
|
|
1052
1082
|
for (const flag of profile.placeholderFlags ?? []) {
|
|
1053
1083
|
out.push({
|
|
@@ -1243,7 +1273,10 @@ var GK_CSS = `
|
|
|
1243
1273
|
min-width:0; max-width:100%; flex:0 1 auto; }
|
|
1244
1274
|
.gb-layer-track { position:relative; display:flex; flex:1 1 auto; min-width:0; height:28px;
|
|
1245
1275
|
overflow-x:auto; overflow-y:hidden; overscroll-behavior-x:contain; touch-action:pan-x;
|
|
1246
|
-
scrollbar-width:none; }
|
|
1276
|
+
scrollbar-width:none; max-width:1000px; transition:max-width .26s ease, opacity .18s ease; }
|
|
1277
|
+
/* Floors off: the list folds away; the switch beside it does not move (same element, same place, as the legend). */
|
|
1278
|
+
.gb-layers.is-collapsed .gb-layer-track { max-width:0; opacity:0; pointer-events:none; }
|
|
1279
|
+
.gb-layers.is-collapsed .gb-sep { opacity:0; margin:0; }
|
|
1247
1280
|
.gb-layer-track::-webkit-scrollbar { display:none; }
|
|
1248
1281
|
/* Only the edge that actually has more layers is faded; a row that fits stays crisp. */
|
|
1249
1282
|
.gb-layer-track.can-right { -webkit-mask-image:linear-gradient(to right, #000 calc(100% - 18px), transparent); mask-image:linear-gradient(to right, #000 calc(100% - 18px), transparent); }
|
|
@@ -1260,7 +1293,7 @@ var GK_CSS = `
|
|
|
1260
1293
|
box-shadow: 0 1px 2px rgba(15,23,42,.08); transition: transform .3s cubic-bezier(.3,.7,.2,1), width .3s cubic-bezier(.3,.7,.2,1); }
|
|
1261
1294
|
/* Stacked layers on: layer names are multi-select, each lit on its own; no slider. */
|
|
1262
1295
|
.gb-layers.is-multi .gb-layer-track > button[data-v].on { background: var(--gb-active,var(--gb-default-active,#e0f2fe)); box-shadow: 0 1px 2px rgba(15,23,42,.08); }
|
|
1263
|
-
.gb-sep { align-self:center; width:1px; height:18px; margin:0 3px; background: var(--gb-border,var(--gb-default-border,#e2e8f0)); flex:none; }
|
|
1296
|
+
.gb-sep { align-self:center; width:1px; height:18px; margin:0 3px; background: var(--gb-border,var(--gb-default-border,#e2e8f0)); flex:none; transition:opacity .18s ease, margin .26s ease; }
|
|
1264
1297
|
.gb-layer-track > button:focus-visible { outline-offset:-2px; }
|
|
1265
1298
|
.gb-segm > button.gb-stack { display:grid; place-items:center; width:30px; padding:0; color: var(--gb-muted2,var(--gb-default-muted2,#94a3b8)); }
|
|
1266
1299
|
.gb-segm > button.gb-stack:hover:not(:disabled) { color: var(--gb-text,var(--gb-default-text,#1f2937)); background: var(--gb-tint,var(--gb-default-tint,#f1f5f9)); }
|
|
@@ -1618,6 +1651,14 @@ function checkEdit(model, op) {
|
|
|
1618
1651
|
}
|
|
1619
1652
|
return null;
|
|
1620
1653
|
};
|
|
1654
|
+
if (op.op === "addNode" || op.op === "updateNode") {
|
|
1655
|
+
const order = op.set.order;
|
|
1656
|
+
if (order != null && (!Number.isFinite(order) || order <= 0)) return "order-invalid";
|
|
1657
|
+
const current = model.index.get(op.id);
|
|
1658
|
+
const parent = op.set.parent !== void 0 ? op.set.parent : current?.parent;
|
|
1659
|
+
const value = order === null ? void 0 : order ?? current?.order;
|
|
1660
|
+
if (parent && value !== void 0 && model.nodes.some((n) => n.id !== op.id && n.parent === parent && n.order === value)) return "order-invalid";
|
|
1661
|
+
}
|
|
1621
1662
|
switch (op.op) {
|
|
1622
1663
|
case "addNode":
|
|
1623
1664
|
if (!op.id.trim()) return "id-empty";
|
|
@@ -1648,7 +1689,7 @@ function applyEdit(model, op, profile) {
|
|
|
1648
1689
|
function apply(model, op, profile) {
|
|
1649
1690
|
const layerOf = (n) => profile ? profile.layerOf(n) : n.layer;
|
|
1650
1691
|
const fields = (n, set) => {
|
|
1651
|
-
const { parent, ...rest } = set;
|
|
1692
|
+
const { parent, order, ...rest } = set;
|
|
1652
1693
|
const next = { ...n, ...rest };
|
|
1653
1694
|
if (parent !== void 0) {
|
|
1654
1695
|
if (parent) {
|
|
@@ -1656,6 +1697,8 @@ function apply(model, op, profile) {
|
|
|
1656
1697
|
next.layer = model.index.get(parent)?.layer ?? next.layer;
|
|
1657
1698
|
} else delete next.parent;
|
|
1658
1699
|
}
|
|
1700
|
+
if (order === null || parent === null) delete next.order;
|
|
1701
|
+
else if (order !== void 0) next.order = order;
|
|
1659
1702
|
next.layer = layerOf(next);
|
|
1660
1703
|
return next;
|
|
1661
1704
|
};
|
|
@@ -1710,6 +1753,25 @@ function applyEdits(model, ops, profile) {
|
|
|
1710
1753
|
}
|
|
1711
1754
|
return { model: m, skipped };
|
|
1712
1755
|
}
|
|
1756
|
+
function checkNativeEdit(model, op) {
|
|
1757
|
+
if (op.op === "addNode" && !/^[^\s@]{1,80}$/.test(op.id)) return "id-format";
|
|
1758
|
+
const basic = checkEdit(model, op);
|
|
1759
|
+
if (basic) return basic;
|
|
1760
|
+
const next = apply(model, op);
|
|
1761
|
+
const oldRoots = model.nodes.filter((n) => !n.parent).length;
|
|
1762
|
+
if (next.nodes.filter((n) => !n.parent).length > Math.max(1, oldRoots)) return "multiple-roots";
|
|
1763
|
+
const siblings = /* @__PURE__ */ new Map();
|
|
1764
|
+
for (const n of next.nodes) if (n.parent) {
|
|
1765
|
+
const xs = siblings.get(n.parent) ?? [];
|
|
1766
|
+
xs.push(n);
|
|
1767
|
+
siblings.set(n.parent, xs);
|
|
1768
|
+
}
|
|
1769
|
+
for (const xs of siblings.values()) {
|
|
1770
|
+
const count = xs.filter((n) => n.order !== void 0).length;
|
|
1771
|
+
if (count && count !== xs.length) return "order-mixed";
|
|
1772
|
+
}
|
|
1773
|
+
return null;
|
|
1774
|
+
}
|
|
1713
1775
|
|
|
1714
1776
|
// src/animate.ts
|
|
1715
1777
|
var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
|
@@ -2270,6 +2332,7 @@ export {
|
|
|
2270
2332
|
originsOfNode,
|
|
2271
2333
|
indexModel,
|
|
2272
2334
|
originsOf,
|
|
2335
|
+
encodeParent,
|
|
2273
2336
|
parsePhysical,
|
|
2274
2337
|
toPhysical,
|
|
2275
2338
|
validateStructure,
|
|
@@ -2289,6 +2352,7 @@ export {
|
|
|
2289
2352
|
VIRTUAL_ROOT,
|
|
2290
2353
|
RESERVED_CLASSES,
|
|
2291
2354
|
cls,
|
|
2355
|
+
edgeKindClass,
|
|
2292
2356
|
nodeClasses,
|
|
2293
2357
|
buildElements,
|
|
2294
2358
|
isNodeEl,
|
|
@@ -2331,6 +2395,7 @@ export {
|
|
|
2331
2395
|
edgesOf,
|
|
2332
2396
|
applyEdit,
|
|
2333
2397
|
applyEdits,
|
|
2398
|
+
checkNativeEdit,
|
|
2334
2399
|
easeOutCubic,
|
|
2335
2400
|
easeInOutCubic,
|
|
2336
2401
|
easeOutBack,
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
// src/layers.ts
|
|
2
|
-
var MAX_DERIVED_LAYERS = 8;
|
|
3
2
|
var EMPTY = { layers: [], layerOf: /* @__PURE__ */ new Map() };
|
|
4
3
|
function orderedChildren(children, id) {
|
|
5
4
|
const kids = children.get(id) ?? [];
|
|
@@ -35,7 +34,7 @@ function deriveLayers(model, colors = [], force = false) {
|
|
|
35
34
|
} else if (force && roots.length > 1) {
|
|
36
35
|
ordered = roots;
|
|
37
36
|
}
|
|
38
|
-
if (!ordered || ordered.length < 2
|
|
37
|
+
if (!ordered || ordered.length < 2) return EMPTY;
|
|
39
38
|
const layers = ordered.map((n, i) => ({
|
|
40
39
|
id: n.id,
|
|
41
40
|
label: n.label || n.id,
|
|
@@ -60,7 +59,6 @@ function layerIndexOf(derived, id) {
|
|
|
60
59
|
}
|
|
61
60
|
|
|
62
61
|
export {
|
|
63
|
-
MAX_DERIVED_LAYERS,
|
|
64
62
|
orderedChildren,
|
|
65
63
|
childrenMap,
|
|
66
64
|
deriveLayers,
|
|
@@ -54,7 +54,7 @@ var EN = {
|
|
|
54
54
|
addNode: "Add node\u2026",
|
|
55
55
|
addEdge: "Add edge\u2026",
|
|
56
56
|
relayout: "Re-layout",
|
|
57
|
-
restructure: "
|
|
57
|
+
restructure: "Re-structure",
|
|
58
58
|
edit: "Edit",
|
|
59
59
|
editNode: "Edit node",
|
|
60
60
|
newNode: "New node",
|
|
@@ -84,6 +84,10 @@ var EN = {
|
|
|
84
84
|
"no-node": "Node not found",
|
|
85
85
|
"no-parent": "Parent not found",
|
|
86
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)",
|
|
87
91
|
"has-children": "Has children \u2014 delete or move them first",
|
|
88
92
|
"no-endpoint": "Pick both ends",
|
|
89
93
|
"self-loop": "Both ends are the same node",
|
|
@@ -37,7 +37,13 @@ function runLayoutJob(job) {
|
|
|
37
37
|
return new Promise((resolve, reject) => {
|
|
38
38
|
let cy;
|
|
39
39
|
try {
|
|
40
|
-
cy = cytoscape({
|
|
40
|
+
cy = cytoscape({
|
|
41
|
+
headless: true,
|
|
42
|
+
styleEnabled: true,
|
|
43
|
+
elements: job.elements,
|
|
44
|
+
style: GEOMETRY_STYLE,
|
|
45
|
+
layout: { name: "preset", fit: false }
|
|
46
|
+
});
|
|
41
47
|
} catch (err) {
|
|
42
48
|
reject(err);
|
|
43
49
|
return;
|
|
@@ -91,5 +97,6 @@ var inlinePool = () => [{
|
|
|
91
97
|
}];
|
|
92
98
|
|
|
93
99
|
export {
|
|
100
|
+
LAYOUTS,
|
|
94
101
|
inlinePool
|
|
95
102
|
};
|