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
|
@@ -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,7 +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
|
-
|
|
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
|
+
}),
|
|
132
160
|
edges: model.edges.map((e) => clean({ ...e.data, source: e.source, target: e.target, kind: e.kind, label: e.label, weight: e.weight }))
|
|
133
161
|
};
|
|
134
162
|
}
|
|
@@ -589,6 +617,8 @@ function buildElements(model, profile, opts = {}) {
|
|
|
589
617
|
layer,
|
|
590
618
|
origin: n.origin ?? null,
|
|
591
619
|
order: n.order ?? null,
|
|
620
|
+
// Parentage for the layout's order pass. A separate key, not `parent`: cytoscape treats `data.parent` as a compound.
|
|
621
|
+
parentId: effParent ?? null,
|
|
592
622
|
share: shareOf(n.id),
|
|
593
623
|
leaves: leavesOf(n.id),
|
|
594
624
|
detail: n.data ?? null,
|
|
@@ -680,8 +710,8 @@ function planeView(v, layers) {
|
|
|
680
710
|
if (layers.length < 2) return v.planes || v.layers ? { ...v, planes: false, layers: null } : v;
|
|
681
711
|
const stacked = v.planes !== false;
|
|
682
712
|
const picked = layers.map((l) => l.id).filter((id) => v.layers?.includes(id));
|
|
683
|
-
const want = stacked ? picked.length && picked.length < layers.length ? picked : null :
|
|
684
|
-
const same = v.planes === stacked && (want === null ? v.layers
|
|
713
|
+
const want = stacked ? picked.length && picked.length < layers.length ? picked : null : v.layers && picked.length === 1 ? picked : null;
|
|
714
|
+
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]));
|
|
685
715
|
return same ? v : { ...v, planes: stacked, layers: want };
|
|
686
716
|
}
|
|
687
717
|
function isFiltering(v) {
|
|
@@ -1242,7 +1272,10 @@ var GK_CSS = `
|
|
|
1242
1272
|
min-width:0; max-width:100%; flex:0 1 auto; }
|
|
1243
1273
|
.gb-layer-track { position:relative; display:flex; flex:1 1 auto; min-width:0; height:28px;
|
|
1244
1274
|
overflow-x:auto; overflow-y:hidden; overscroll-behavior-x:contain; touch-action:pan-x;
|
|
1245
|
-
scrollbar-width:none; }
|
|
1275
|
+
scrollbar-width:none; max-width:1000px; transition:max-width .26s ease, opacity .18s ease; }
|
|
1276
|
+
/* Floors off: the list folds away; the switch beside it does not move (same element, same place, as the legend). */
|
|
1277
|
+
.gb-layers.is-collapsed .gb-layer-track { max-width:0; opacity:0; pointer-events:none; }
|
|
1278
|
+
.gb-layers.is-collapsed .gb-sep { opacity:0; margin:0; }
|
|
1246
1279
|
.gb-layer-track::-webkit-scrollbar { display:none; }
|
|
1247
1280
|
/* Only the edge that actually has more layers is faded; a row that fits stays crisp. */
|
|
1248
1281
|
.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); }
|
|
@@ -1259,7 +1292,7 @@ var GK_CSS = `
|
|
|
1259
1292
|
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); }
|
|
1260
1293
|
/* Stacked layers on: layer names are multi-select, each lit on its own; no slider. */
|
|
1261
1294
|
.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); }
|
|
1262
|
-
.gb-sep { align-self:center; width:1px; height:18px; margin:0 3px; background: var(--gb-border,var(--gb-default-border,#e2e8f0)); flex:none; }
|
|
1295
|
+
.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; }
|
|
1263
1296
|
.gb-layer-track > button:focus-visible { outline-offset:-2px; }
|
|
1264
1297
|
.gb-segm > button.gb-stack { display:grid; place-items:center; width:30px; padding:0; color: var(--gb-muted2,var(--gb-default-muted2,#94a3b8)); }
|
|
1265
1298
|
.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)); }
|
|
@@ -1617,6 +1650,14 @@ function checkEdit(model, op) {
|
|
|
1617
1650
|
}
|
|
1618
1651
|
return null;
|
|
1619
1652
|
};
|
|
1653
|
+
if (op.op === "addNode" || op.op === "updateNode") {
|
|
1654
|
+
const order = op.set.order;
|
|
1655
|
+
if (order != null && (!Number.isFinite(order) || order <= 0)) return "order-invalid";
|
|
1656
|
+
const current = model.index.get(op.id);
|
|
1657
|
+
const parent = op.set.parent !== void 0 ? op.set.parent : current?.parent;
|
|
1658
|
+
const value = order === null ? void 0 : order ?? current?.order;
|
|
1659
|
+
if (parent && value !== void 0 && model.nodes.some((n) => n.id !== op.id && n.parent === parent && n.order === value)) return "order-invalid";
|
|
1660
|
+
}
|
|
1620
1661
|
switch (op.op) {
|
|
1621
1662
|
case "addNode":
|
|
1622
1663
|
if (!op.id.trim()) return "id-empty";
|
|
@@ -1647,7 +1688,7 @@ function applyEdit(model, op, profile) {
|
|
|
1647
1688
|
function apply(model, op, profile) {
|
|
1648
1689
|
const layerOf = (n) => profile ? profile.layerOf(n) : n.layer;
|
|
1649
1690
|
const fields = (n, set) => {
|
|
1650
|
-
const { parent, ...rest } = set;
|
|
1691
|
+
const { parent, order, ...rest } = set;
|
|
1651
1692
|
const next = { ...n, ...rest };
|
|
1652
1693
|
if (parent !== void 0) {
|
|
1653
1694
|
if (parent) {
|
|
@@ -1655,6 +1696,8 @@ function apply(model, op, profile) {
|
|
|
1655
1696
|
next.layer = model.index.get(parent)?.layer ?? next.layer;
|
|
1656
1697
|
} else delete next.parent;
|
|
1657
1698
|
}
|
|
1699
|
+
if (order === null || parent === null) delete next.order;
|
|
1700
|
+
else if (order !== void 0) next.order = order;
|
|
1658
1701
|
next.layer = layerOf(next);
|
|
1659
1702
|
return next;
|
|
1660
1703
|
};
|
|
@@ -1709,6 +1752,25 @@ function applyEdits(model, ops, profile) {
|
|
|
1709
1752
|
}
|
|
1710
1753
|
return { model: m, skipped };
|
|
1711
1754
|
}
|
|
1755
|
+
function checkNativeEdit(model, op) {
|
|
1756
|
+
if (op.op === "addNode" && !/^[^\s@]{1,80}$/.test(op.id)) return "id-format";
|
|
1757
|
+
const basic = checkEdit(model, op);
|
|
1758
|
+
if (basic) return basic;
|
|
1759
|
+
const next = apply(model, op);
|
|
1760
|
+
const oldRoots = model.nodes.filter((n) => !n.parent).length;
|
|
1761
|
+
if (next.nodes.filter((n) => !n.parent).length > Math.max(1, oldRoots)) return "multiple-roots";
|
|
1762
|
+
const siblings = /* @__PURE__ */ new Map();
|
|
1763
|
+
for (const n of next.nodes) if (n.parent) {
|
|
1764
|
+
const xs = siblings.get(n.parent) ?? [];
|
|
1765
|
+
xs.push(n);
|
|
1766
|
+
siblings.set(n.parent, xs);
|
|
1767
|
+
}
|
|
1768
|
+
for (const xs of siblings.values()) {
|
|
1769
|
+
const count = xs.filter((n) => n.order !== void 0).length;
|
|
1770
|
+
if (count && count !== xs.length) return "order-mixed";
|
|
1771
|
+
}
|
|
1772
|
+
return null;
|
|
1773
|
+
}
|
|
1712
1774
|
|
|
1713
1775
|
// src/animate.ts
|
|
1714
1776
|
var easeOutCubic = (t) => 1 - Math.pow(1 - t, 3);
|
|
@@ -2269,6 +2331,7 @@ export {
|
|
|
2269
2331
|
originsOfNode,
|
|
2270
2332
|
indexModel,
|
|
2271
2333
|
originsOf,
|
|
2334
|
+
encodeParent,
|
|
2272
2335
|
parsePhysical,
|
|
2273
2336
|
toPhysical,
|
|
2274
2337
|
validateStructure,
|
|
@@ -2330,6 +2393,7 @@ export {
|
|
|
2330
2393
|
edgesOf,
|
|
2331
2394
|
applyEdit,
|
|
2332
2395
|
applyEdits,
|
|
2396
|
+
checkNativeEdit,
|
|
2333
2397
|
easeOutCubic,
|
|
2334
2398
|
easeInOutCubic,
|
|
2335
2399
|
easeOutBack,
|