glassbrain 0.2.0-alpha.4 → 0.2.0-alpha.6
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 +18 -8
- package/dist/adapters.js +25 -1
- package/dist/chunks/{chunk-3JGZ27DC.js → chunk-3P34XHQ2.js} +4 -3
- package/dist/chunks/{chunk-SEOAVI3E.js → chunk-3SAL4526.js} +259 -94
- package/dist/chunks/{chunk-ISWKAU5G.js → chunk-5DEN6HXJ.js} +1 -3
- package/dist/chunks/{chunk-R2CQA4OJ.js → chunk-LMYD4QHC.js} +107 -163
- package/dist/chunks/{chunk-G7XWVKHN.js → chunk-M3MAM2VD.js} +5 -4
- package/dist/chunks/{chunk-YGRPNAXE.js → chunk-OE5IRKWZ.js} +8 -1
- package/dist/cli/glassbrain.js +438 -272
- package/dist/cli/viewer.js +45 -45
- package/dist/core.js +7 -5
- package/dist/edit.d.ts +5 -3
- package/dist/elements.d.ts +2 -0
- package/dist/index.js +10 -8
- package/dist/internal.d.ts +1 -1
- package/dist/internal.js +12 -8
- package/dist/layers.d.ts +1 -1
- package/dist/layout/engine.d.ts +3 -1
- package/dist/layout/inline-pool.js +1 -1
- package/dist/layout/order.d.ts +9 -5
- package/dist/layout/worker.js +7 -1
- package/dist/model.d.ts +15 -5
- package/dist/paint.d.ts +2 -0
- package/dist/profile.d.ts +9 -1
- package/dist/react/DetailPanel.js +2 -2
- package/dist/react/GraphCanvas.d.ts +5 -2
- package/dist/react/GraphCanvas.js +5 -5
- package/dist/react/Toolbar.d.ts +2 -1
- package/dist/tree.d.ts +11 -0
- package/package.json +1 -1
- package/schema/graph.schema.json +125 -23
|
@@ -24,6 +24,7 @@ import {
|
|
|
24
24
|
diffModels,
|
|
25
25
|
diffSkinStyle,
|
|
26
26
|
edgeFade,
|
|
27
|
+
edgeKindClass,
|
|
27
28
|
edgeTraffic,
|
|
28
29
|
edgesOf,
|
|
29
30
|
graphStyle,
|
|
@@ -52,20 +53,21 @@ import {
|
|
|
52
53
|
unionSides,
|
|
53
54
|
untheme,
|
|
54
55
|
validateModel
|
|
55
|
-
} from "./chunk-
|
|
56
|
+
} from "./chunk-3SAL4526.js";
|
|
56
57
|
import {
|
|
57
58
|
DetailPanel,
|
|
58
59
|
I,
|
|
59
60
|
Icon,
|
|
60
61
|
StringsContext,
|
|
61
62
|
useStrings
|
|
62
|
-
} from "./chunk-
|
|
63
|
+
} from "./chunk-3P34XHQ2.js";
|
|
63
64
|
import {
|
|
64
65
|
EN
|
|
65
|
-
} from "./chunk-
|
|
66
|
+
} from "./chunk-5DEN6HXJ.js";
|
|
66
67
|
import {
|
|
68
|
+
LAYOUTS,
|
|
67
69
|
inlinePool
|
|
68
|
-
} from "./chunk-
|
|
70
|
+
} from "./chunk-OE5IRKWZ.js";
|
|
69
71
|
import {
|
|
70
72
|
__publicField
|
|
71
73
|
} from "./chunk-ZA47FP7C.js";
|
|
@@ -129,6 +131,7 @@ var EDGE_REACH = 0.5;
|
|
|
129
131
|
var reachOf = (vis, lineW, touch = false, base = EDGE_REACH) => (base * (touch ? 2.4 : 1) + lineW / 2) * vis;
|
|
130
132
|
var hittable = (reach) => reach * 2 >= 1;
|
|
131
133
|
var detailed = (leafPx) => leafPx >= DETAIL_LEAF;
|
|
134
|
+
var edgeKindHidden = (skeleton, kind, hidden) => !skeleton && hidden.has(kind);
|
|
132
135
|
var shapeOf = (name) => /hexagon|octagon|pentagon|heptagon/.test(name) ? "hexagon" : /diamond/.test(name) ? "diamond" : /rectangle|square|barrel|tag/.test(name) ? "rect" : "circle";
|
|
133
136
|
var arrowOf = (name) => name === "none" ? "none" : name === "tee" ? "tee" : "triangle";
|
|
134
137
|
function installPainter(cy, opts) {
|
|
@@ -260,7 +263,7 @@ function installPainter(cy, opts) {
|
|
|
260
263
|
if (!muteKinds.nodes.size && !muteKinds.edges.size) return out;
|
|
261
264
|
for (const n of [...nodes, ...parents]) if (muteKinds.nodes.has(n.ele.data("kind"))) out.add(n.id);
|
|
262
265
|
for (const e of edges) {
|
|
263
|
-
if (
|
|
266
|
+
if (edgeKindHidden(e.skeleton, e.ele.data("kind"), muteKinds.edges) || out.has(e.src.id) || out.has(e.tgt.id)) out.add(e.id);
|
|
264
267
|
}
|
|
265
268
|
return out;
|
|
266
269
|
};
|
|
@@ -773,11 +776,11 @@ function partitionElements(elements) {
|
|
|
773
776
|
const attached = new Set(nodes.filter(isAttached).map((n) => n.data.id));
|
|
774
777
|
const parentOf = /* @__PURE__ */ new Map();
|
|
775
778
|
for (const n of nodes) {
|
|
776
|
-
const p = n.data.parent;
|
|
779
|
+
const p = n.data.parentId ?? n.data.parent;
|
|
777
780
|
if (p && p !== VIRTUAL_ROOT) parentOf.set(n.data.id, p);
|
|
778
781
|
}
|
|
779
782
|
for (const e of edges) {
|
|
780
|
-
if (e.
|
|
783
|
+
if (e.classes?.split(/\s+/).includes("contains") && e.data.source !== VIRTUAL_ROOT && !parentOf.has(e.data.target)) {
|
|
781
784
|
parentOf.set(e.data.target, e.data.source);
|
|
782
785
|
}
|
|
783
786
|
}
|
|
@@ -924,7 +927,7 @@ function readOrder(elements) {
|
|
|
924
927
|
const p = el.data.parentId ?? el.data.parent;
|
|
925
928
|
if (p) rawParent.set(id, p);
|
|
926
929
|
const raw = el.data.order;
|
|
927
|
-
rawOrder.set(id, typeof raw === "number" && Number.isFinite(raw) ? raw : null);
|
|
930
|
+
rawOrder.set(id, typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : null);
|
|
928
931
|
}
|
|
929
932
|
const parentOf = /* @__PURE__ */ new Map();
|
|
930
933
|
const kids = /* @__PURE__ */ new Map();
|
|
@@ -953,137 +956,78 @@ function readOrder(elements) {
|
|
|
953
956
|
orderedKids.set(parent, sorted);
|
|
954
957
|
any = true;
|
|
955
958
|
}
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
for (let i = 0; i < id.length; i++) {
|
|
961
|
-
h ^= id.charCodeAt(i);
|
|
962
|
-
h = Math.imul(h, 16777619);
|
|
959
|
+
const roots = [...nodeIds].filter((id) => !rawParent.has(id));
|
|
960
|
+
if (roots.length > 1 && roots.every((id) => rawOrder.get(id) !== null) && new Set(roots.map((id) => rawOrder.get(id))).size === roots.length) {
|
|
961
|
+
orderedKids.set(VIRTUAL_PARENT, roots.sort((a, b) => rawOrder.get(a) - rawOrder.get(b)));
|
|
962
|
+
any = true;
|
|
963
963
|
}
|
|
964
|
-
return
|
|
964
|
+
return nodeIds.size ? { parentOf, orderedKids, nodeIds, any } : null;
|
|
965
965
|
}
|
|
966
|
-
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
const arr = children.get(parent);
|
|
972
|
-
arr ? arr.push(id) : children.set(parent, [id]);
|
|
973
|
-
}
|
|
974
|
-
const roots = [...info.nodeIds].filter((id) => !info.parentOf.has(id));
|
|
975
|
-
const weight = /* @__PURE__ */ new Map();
|
|
976
|
-
const weigh = (id, seen = /* @__PURE__ */ new Set()) => {
|
|
977
|
-
const hit = weight.get(id);
|
|
978
|
-
if (hit != null) return hit;
|
|
979
|
-
if (seen.has(id)) return 1;
|
|
980
|
-
seen.add(id);
|
|
981
|
-
let n = 1;
|
|
982
|
-
for (const k of children.get(id) ?? []) n += weigh(k, seen);
|
|
983
|
-
weight.set(id, n);
|
|
984
|
-
return n;
|
|
985
|
-
};
|
|
986
|
-
for (const id of info.nodeIds) weigh(id);
|
|
987
|
-
const out = {};
|
|
988
|
-
const place = (id, cx, cy, from, to, level) => {
|
|
989
|
-
const r = level * RING;
|
|
990
|
-
const mid = (from + to) / 2;
|
|
991
|
-
out[id] = { x: cx + Math.cos(mid) * r, y: cy + Math.sin(mid) * r };
|
|
992
|
-
const kids = children.get(id) ?? [];
|
|
993
|
-
if (!kids.length) return;
|
|
994
|
-
const ordered = info.orderedKids.get(id);
|
|
995
|
-
const list = ordered ?? kids;
|
|
996
|
-
const total = list.reduce((s, k) => s + weigh(k), 0) || 1;
|
|
997
|
-
let at = from;
|
|
998
|
-
for (const k of list) {
|
|
999
|
-
const span = (to - from) * weigh(k) / total;
|
|
1000
|
-
const jitter = ordered ? 0 : (hash01(k) - 0.5) * span * 0.6;
|
|
1001
|
-
const a = at + jitter;
|
|
1002
|
-
place(k, cx, cy, a, a + span, level + 1);
|
|
1003
|
-
at += span;
|
|
1004
|
-
}
|
|
1005
|
-
};
|
|
1006
|
-
if (roots.length === 1) place(roots[0], 0, 0, -Math.PI / 2, Math.PI * 1.5, 0);
|
|
1007
|
-
else if (roots.length > 1) {
|
|
1008
|
-
roots.forEach((root, i) => {
|
|
1009
|
-
const from = -Math.PI / 2 + TAU * i / roots.length;
|
|
1010
|
-
place(root, 0, 0, from, from + TAU / roots.length, 0);
|
|
1011
|
-
});
|
|
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];
|
|
966
|
+
function shuffled(ids, random) {
|
|
967
|
+
const out = [...ids].sort();
|
|
968
|
+
for (let i = out.length - 1; i > 0; i--) {
|
|
969
|
+
const j = Math.floor(random() * (i + 1));
|
|
970
|
+
[out[i], out[j]] = [out[j], out[i]];
|
|
1016
971
|
}
|
|
1017
972
|
return out;
|
|
1018
973
|
}
|
|
1019
|
-
var
|
|
1020
|
-
function
|
|
974
|
+
var TAU = Math.PI * 2;
|
|
975
|
+
function orderSeed(elements, info, dims = {}, random = Math.random) {
|
|
976
|
+
const gap = LAYOUTS["cose-bilkent"].opts.idealEdgeLength;
|
|
1021
977
|
const children = /* @__PURE__ */ new Map();
|
|
1022
978
|
for (const [id, parent] of info.parentOf) {
|
|
1023
|
-
const
|
|
1024
|
-
|
|
979
|
+
const list = children.get(parent);
|
|
980
|
+
list ? list.push(id) : children.set(parent, [id]);
|
|
1025
981
|
}
|
|
1026
|
-
const
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
const weigh = (id, seen = /* @__PURE__ */ new Set()) => {
|
|
1030
|
-
const hit = weight.get(id);
|
|
1031
|
-
if (hit != null) return hit;
|
|
1032
|
-
if (seen.has(id)) return 1;
|
|
1033
|
-
seen.add(id);
|
|
1034
|
-
let n = 1;
|
|
1035
|
-
for (const k of children.get(id) ?? []) n += weigh(k, seen);
|
|
1036
|
-
weight.set(id, n);
|
|
1037
|
-
return n;
|
|
982
|
+
const diameter = (id) => {
|
|
983
|
+
const d = dims[id];
|
|
984
|
+
return d ? Math.hypot(d.w, d.h) : gap;
|
|
1038
985
|
};
|
|
1039
|
-
const
|
|
1040
|
-
|
|
1041
|
-
|
|
1042
|
-
return
|
|
986
|
+
const widths = /* @__PURE__ */ new Map();
|
|
987
|
+
const width = (id) => {
|
|
988
|
+
const cached = widths.get(id);
|
|
989
|
+
if (cached !== void 0) return cached;
|
|
990
|
+
const value = Math.max(
|
|
991
|
+
diameter(id) + gap,
|
|
992
|
+
(children.get(id) ?? []).reduce((sum, child) => sum + width(child), 0)
|
|
993
|
+
);
|
|
994
|
+
widths.set(id, value);
|
|
995
|
+
return value;
|
|
1043
996
|
};
|
|
1044
|
-
const
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
for (const id of ids) {
|
|
1048
|
-
const p = out[id];
|
|
1049
|
-
if (!p) continue;
|
|
1050
|
-
const dx = p.x - pivot.x, dy = p.y - pivot.y;
|
|
1051
|
-
out[id] = { x: pivot.x + dx * c - dy * s, y: pivot.y + dx * s + dy * c };
|
|
1052
|
-
}
|
|
997
|
+
const offset = (span) => {
|
|
998
|
+
const z = Math.sqrt(-2 * Math.log(1 - random())) * Math.cos(TAU * random());
|
|
999
|
+
return Math.max(-3, Math.min(3, z)) * span / 8;
|
|
1053
1000
|
};
|
|
1054
|
-
const
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
for (const id of present) {
|
|
1069
|
-
const p = out[id];
|
|
1070
|
-
const cur = angle({ x: p.x - pivot.x, y: p.y - pivot.y });
|
|
1071
|
-
let delta = at - cur;
|
|
1072
|
-
while (delta > Math.PI) delta -= TAU;
|
|
1073
|
-
while (delta < -Math.PI) delta += TAU;
|
|
1074
|
-
rotate(subtree(id), pivot, delta);
|
|
1075
|
-
at += TAU * weigh(id) / total;
|
|
1076
|
-
}
|
|
1077
|
-
for (const id of present) settle(id);
|
|
1001
|
+
const out = {};
|
|
1002
|
+
const placeChildren = (parent, ids, parentRadius, sector) => {
|
|
1003
|
+
const list = info.orderedKids.get(parent ?? VIRTUAL_PARENT) ?? shuffled(ids, random);
|
|
1004
|
+
if (!list.length) return;
|
|
1005
|
+
const span = sector ? (sector.to - sector.from) / list.length : TAU / (list.length + 1);
|
|
1006
|
+
list.forEach((id, i) => {
|
|
1007
|
+
const middle2 = sector ? sector.from + (i + 0.5) * span : -Math.PI / 2 + (i + 1) * span;
|
|
1008
|
+
const angle = middle2 + offset(span);
|
|
1009
|
+
const clearance = gap + (diameter(parent ?? VIRTUAL_PARENT) + diameter(id)) / 2;
|
|
1010
|
+
const radius = Math.max(parentRadius + clearance, width(id) / span);
|
|
1011
|
+
const p = { x: Math.cos(angle) * radius, y: Math.sin(angle) * radius };
|
|
1012
|
+
out[id] = p;
|
|
1013
|
+
placeChildren(id, children.get(id) ?? [], radius, { from: middle2 - span / 2, to: middle2 + span / 2 });
|
|
1014
|
+
});
|
|
1078
1015
|
};
|
|
1079
1016
|
const roots = [...info.nodeIds].filter((id) => !info.parentOf.has(id));
|
|
1080
|
-
|
|
1081
|
-
if (
|
|
1017
|
+
if (children.has(VIRTUAL_PARENT)) roots.push(VIRTUAL_PARENT);
|
|
1018
|
+
if (roots.length === 1) {
|
|
1019
|
+
const root = roots[0];
|
|
1020
|
+
out[root] = { x: 0, y: 0 };
|
|
1021
|
+
placeChildren(root, children.get(root) ?? [], 0);
|
|
1022
|
+
} else {
|
|
1023
|
+
placeChildren(null, roots, 0);
|
|
1024
|
+
}
|
|
1025
|
+
delete out[VIRTUAL_PARENT];
|
|
1082
1026
|
return out;
|
|
1083
1027
|
}
|
|
1084
1028
|
|
|
1085
1029
|
// src/layout/engine.ts
|
|
1086
|
-
var CACHE_PREFIX = "gb:pos:
|
|
1030
|
+
var CACHE_PREFIX = "gb:pos:v7:";
|
|
1087
1031
|
var CACHE_KEEP = 16;
|
|
1088
1032
|
function shapeHash(elements, salt) {
|
|
1089
1033
|
const parts = [];
|
|
@@ -1307,11 +1251,7 @@ async function runWhole(req, aborted) {
|
|
|
1307
1251
|
if (el.data.source) {
|
|
1308
1252
|
if (el.data._force !== false) edges.push({ data: el.data, classes: el.classes });
|
|
1309
1253
|
} else {
|
|
1310
|
-
|
|
1311
|
-
nodes.push({
|
|
1312
|
-
data: { ...el.data, detail: void 0, ...d ? { _w: d.w, _h: d.h } : {} },
|
|
1313
|
-
classes: el.classes
|
|
1314
|
-
});
|
|
1254
|
+
nodes.push(toJobNode(el, req.dims, req.seed));
|
|
1315
1255
|
}
|
|
1316
1256
|
}
|
|
1317
1257
|
const [runner] = req.pool(1);
|
|
@@ -1345,16 +1285,18 @@ function computeLayout(req) {
|
|
|
1345
1285
|
const current = inflight.get(owner);
|
|
1346
1286
|
if (current) current.superseded = true;
|
|
1347
1287
|
const order = readOrder(req.elements);
|
|
1348
|
-
const
|
|
1288
|
+
const known = req.force ? void 0 : req.seed;
|
|
1289
|
+
const complete = order && known && [...order.nodeIds].every((id) => known[id]);
|
|
1290
|
+
const seed = complete ? known : { ...order ? orderSeed(req.elements, order, req.dims) : {}, ...known };
|
|
1291
|
+
const job = { ...req, seed };
|
|
1349
1292
|
const run = { hash, superseded: false, promise: null };
|
|
1350
1293
|
const runner = mode === "whole" ? runWhole : runDivide;
|
|
1351
1294
|
run.promise = runner(job, () => run.superseded).then((pos) => {
|
|
1352
|
-
const settled = order ? enforceOrder(req.elements, order, pos) : pos;
|
|
1353
1295
|
if (!run.stale) {
|
|
1354
|
-
cachePut(hash,
|
|
1355
|
-
lastByNs.set(ns, { hash, pos
|
|
1296
|
+
cachePut(hash, pos);
|
|
1297
|
+
lastByNs.set(ns, { hash, pos });
|
|
1356
1298
|
}
|
|
1357
|
-
return
|
|
1299
|
+
return pos;
|
|
1358
1300
|
}).finally(() => {
|
|
1359
1301
|
if (inflight.get(owner) === run) inflight.delete(owner);
|
|
1360
1302
|
});
|
|
@@ -2043,7 +1985,7 @@ function ViewMenu(p) {
|
|
|
2043
1985
|
"data-y": pop.placement?.side,
|
|
2044
1986
|
style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
|
|
2045
1987
|
onClick: (e) => {
|
|
2046
|
-
if (e.target.closest(".gb-menu-item")) pop.setOpen(false);
|
|
1988
|
+
if (e.target.closest(".gb-menu-item") && !e.target.closest("[data-menu-keep-open]")) pop.setOpen(false);
|
|
2047
1989
|
},
|
|
2048
1990
|
onChange: (e) => {
|
|
2049
1991
|
if (e.target.tagName === "SELECT") pop.setOpen(false);
|
|
@@ -2107,7 +2049,8 @@ function Toolbar(p) {
|
|
|
2107
2049
|
] }),
|
|
2108
2050
|
(p.onRelayout || p.onRestructure) && /* @__PURE__ */ jsxs("div", { className: "gb-panel-sec gb-menu-list", children: [
|
|
2109
2051
|
p.onRelayout && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: p.onRelayout, disabled: p.busy, children: t.relayout }),
|
|
2110
|
-
p.onRestructure && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: p.onRestructure, disabled: p.busy, children: t.restructure })
|
|
2052
|
+
p.onRestructure && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", "data-menu-keep-open": p.restructureContent ? true : void 0, onClick: p.onRestructure, disabled: p.busy, children: t.restructure }),
|
|
2053
|
+
p.restructureContent
|
|
2111
2054
|
] })
|
|
2112
2055
|
] })
|
|
2113
2056
|
] });
|
|
@@ -2672,7 +2615,11 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2672
2615
|
[node]
|
|
2673
2616
|
);
|
|
2674
2617
|
const [text, setText] = useState3(initial);
|
|
2675
|
-
const
|
|
2618
|
+
const initialBefore = useMemo2(() => {
|
|
2619
|
+
const siblings = model.nodes.filter((n) => (n.parent ?? null) === (node?.parent ?? target.parent ?? null)).sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
|
|
2620
|
+
return node ? siblings[siblings.findIndex((n) => n.id === node.id) + 1]?.id ?? null : null;
|
|
2621
|
+
}, [model, node, target.parent]);
|
|
2622
|
+
const [before, setBefore] = useState3(initialBefore);
|
|
2676
2623
|
const [confirming, setConfirming] = useState3(false);
|
|
2677
2624
|
const idErr = creating && id ? checkEdit(model, { op: "addNode", id, set: {} }) : null;
|
|
2678
2625
|
const below = useMemo2(() => {
|
|
@@ -2696,9 +2643,8 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2696
2643
|
setError(t.badJson);
|
|
2697
2644
|
return;
|
|
2698
2645
|
}
|
|
2699
|
-
const order = parent && orderText.trim() ? Number(orderText) : null;
|
|
2700
2646
|
if (creating) {
|
|
2701
|
-
if (submit({ op: "addNode", id: id.trim(), set: { ...content, parent,
|
|
2647
|
+
if (submit({ op: "addNode", id: id.trim(), set: { ...content, parent, before } })) onCancel();
|
|
2702
2648
|
return;
|
|
2703
2649
|
}
|
|
2704
2650
|
const set = {};
|
|
@@ -2706,7 +2652,7 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2706
2652
|
if ((content.kind ?? void 0) !== node.kind) set.kind = content.kind;
|
|
2707
2653
|
if (pretty(content.data ?? {}) !== pretty(node.data ?? {})) set.data = content.data ?? {};
|
|
2708
2654
|
if (parent !== (node.parent ?? null)) set.parent = parent;
|
|
2709
|
-
if (
|
|
2655
|
+
if (before !== initialBefore || parent !== (node.parent ?? null)) set.before = before;
|
|
2710
2656
|
if (!Object.keys(set).length) {
|
|
2711
2657
|
onCancel();
|
|
2712
2658
|
return;
|
|
@@ -2764,7 +2710,10 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2764
2710
|
id: `${uid}-parent`,
|
|
2765
2711
|
model,
|
|
2766
2712
|
value: parent,
|
|
2767
|
-
onChange:
|
|
2713
|
+
onChange: (id2) => {
|
|
2714
|
+
setParent(id2);
|
|
2715
|
+
setBefore(null);
|
|
2716
|
+
},
|
|
2768
2717
|
empty: t.noParent,
|
|
2769
2718
|
label: t.parent,
|
|
2770
2719
|
exclude: below ? (x) => below.has(x) : void 0,
|
|
@@ -2773,21 +2722,11 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
|
|
|
2773
2722
|
)
|
|
2774
2723
|
] }),
|
|
2775
2724
|
/* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
|
|
2776
|
-
/* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-
|
|
2777
|
-
/* @__PURE__ */
|
|
2778
|
-
"
|
|
2779
|
-
{
|
|
2780
|
-
|
|
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
|
-
)
|
|
2725
|
+
/* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-before`, children: "Before" }),
|
|
2726
|
+
/* @__PURE__ */ jsxs2("select", { id: `${uid}-before`, className: "gb-input", value: before ?? "", onChange: (e) => setBefore(e.target.value || null), children: [
|
|
2727
|
+
/* @__PURE__ */ jsx2("option", { value: "", children: "Last" }),
|
|
2728
|
+
model.nodes.filter((n) => n.id !== node?.id && (n.parent ?? null) === parent).sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity)).map((n) => /* @__PURE__ */ jsx2("option", { value: n.id, children: n.label }, n.id))
|
|
2729
|
+
] })
|
|
2791
2730
|
] }),
|
|
2792
2731
|
/* @__PURE__ */ jsxs2("div", { className: "gb-fld gb-grow", children: [
|
|
2793
2732
|
/* @__PURE__ */ jsxs2("label", { className: "gb-k", htmlFor: `${uid}-json`, children: [
|
|
@@ -2925,7 +2864,7 @@ function readMarks(c, cy, style, nodeKinds, edgeKinds) {
|
|
|
2925
2864
|
}
|
|
2926
2865
|
for (const k of edgeKinds) {
|
|
2927
2866
|
if (c.strokes.has(k) || !live) continue;
|
|
2928
|
-
const e = cy.edges(`.${
|
|
2867
|
+
const e = cy.edges(`.${edgeKindClass(k)}`)[0];
|
|
2929
2868
|
if (e) c.strokes.set(k, { dash: e.pstyle("line-style").value, head: arrowOf(e.pstyle("target-arrow-shape").value), tail: arrowOf(e.pstyle("source-arrow-shape").value) });
|
|
2930
2869
|
}
|
|
2931
2870
|
return {
|
|
@@ -3565,8 +3504,7 @@ function hideEdgesByKind(cy, hn, he, prev) {
|
|
|
3565
3504
|
const off = /* @__PURE__ */ new Set();
|
|
3566
3505
|
if (hn.size || he.size) {
|
|
3567
3506
|
cy.edges().forEach((e) => {
|
|
3568
|
-
if (e.hasClass("contains"))
|
|
3569
|
-
if (he.has(e.data("kind")) || hn.has(e.source().data("kind")) || hn.has(e.target().data("kind"))) off.add(e.id());
|
|
3507
|
+
if (edgeKindHidden(e.hasClass("contains"), e.data("kind"), he) || hn.has(e.source().data("kind")) || hn.has(e.target().data("kind"))) off.add(e.id());
|
|
3570
3508
|
});
|
|
3571
3509
|
}
|
|
3572
3510
|
for (const id of prev) if (!off.has(id)) cy.$id(id).style("display", "element");
|
|
@@ -3719,12 +3657,13 @@ function presenceGroups(cy, live, marks) {
|
|
|
3719
3657
|
graft: cy.collection(bucket.graft)
|
|
3720
3658
|
};
|
|
3721
3659
|
}
|
|
3722
|
-
function seatOrphans(pos, built) {
|
|
3660
|
+
function seatOrphans(pos, built, excluded = /* @__PURE__ */ new Set()) {
|
|
3723
3661
|
const missing = [];
|
|
3724
3662
|
let sx = 0, sy = 0, n = 0;
|
|
3725
3663
|
for (const el of built.elements) {
|
|
3726
3664
|
if (el.data.source) continue;
|
|
3727
3665
|
const id = el.data.id;
|
|
3666
|
+
if (excluded.has(id)) continue;
|
|
3728
3667
|
const p = pos[id];
|
|
3729
3668
|
if (p) {
|
|
3730
3669
|
sx += p.x;
|
|
@@ -3831,6 +3770,7 @@ function GraphCanvas(props) {
|
|
|
3831
3770
|
renderEditor,
|
|
3832
3771
|
resolveUrl,
|
|
3833
3772
|
onRestructure,
|
|
3773
|
+
restructureContent,
|
|
3834
3774
|
layerIssue,
|
|
3835
3775
|
onForceLayers,
|
|
3836
3776
|
animate = true,
|
|
@@ -4824,10 +4764,10 @@ function GraphCanvas(props) {
|
|
|
4824
4764
|
const v0 = cam();
|
|
4825
4765
|
const leftBefore = leftRef.current;
|
|
4826
4766
|
applyPositions(cy, union, false);
|
|
4827
|
-
leftRef.current =
|
|
4767
|
+
leftRef.current = leftBefore;
|
|
4828
4768
|
fitAll(cy);
|
|
4829
4769
|
const vU = cam();
|
|
4830
|
-
leftRef.current = t.leaving;
|
|
4770
|
+
leftRef.current = /* @__PURE__ */ new Set([...leftBefore, ...t.leaving]);
|
|
4831
4771
|
fitAll(cy);
|
|
4832
4772
|
const v1 = cam();
|
|
4833
4773
|
leftRef.current = leftBefore;
|
|
@@ -4924,6 +4864,7 @@ function GraphCanvas(props) {
|
|
|
4924
4864
|
worn.push([el, Object.fromEntries(SKIN_SIZE_PROPS.map((p) => [p, el.style(p)]))]);
|
|
4925
4865
|
});
|
|
4926
4866
|
}
|
|
4867
|
+
const hiddenBeforeMeasure = cy.nodes().filter((n) => n.style("display") === "none");
|
|
4927
4868
|
cy.batch(() => {
|
|
4928
4869
|
for (const [el] of worn) el.removeStyle(sizeProps);
|
|
4929
4870
|
cy.nodes().style("display", "none");
|
|
@@ -4932,13 +4873,14 @@ function GraphCanvas(props) {
|
|
|
4932
4873
|
const dims = {};
|
|
4933
4874
|
cy.nodes(":childless").forEach((n) => {
|
|
4934
4875
|
const d = n.layoutDimensions({ nodeDimensionsIncludeLabels: true });
|
|
4935
|
-
dims[n.id()] = { w: d.w, h: d.h };
|
|
4876
|
+
dims[n.id()] = { w: Math.round(d.w * 64) / 64, h: Math.round(d.h * 64) / 64 };
|
|
4936
4877
|
});
|
|
4937
4878
|
dimsRef.current = dims;
|
|
4938
4879
|
if (scaled) cy.style(sheetFor(false));
|
|
4939
4880
|
if (worn.length) cy.batch(() => {
|
|
4940
4881
|
for (const [el, v] of worn) el.style(v);
|
|
4941
4882
|
});
|
|
4883
|
+
hiddenBeforeMeasure.style("display", "none");
|
|
4942
4884
|
if (diffRef.current) hideGhosts(cy);
|
|
4943
4885
|
const run = ++runRef.current;
|
|
4944
4886
|
if (owedLayoutRef.current && (force || !owedLayoutRef.current.force)) owedLayoutRef.current = null;
|
|
@@ -4962,7 +4904,7 @@ function GraphCanvas(props) {
|
|
|
4962
4904
|
return { positions, source: "preset" };
|
|
4963
4905
|
}
|
|
4964
4906
|
let known;
|
|
4965
|
-
if (force
|
|
4907
|
+
if (!force && layoutModeRef.current === "continue") {
|
|
4966
4908
|
const all = { ...preset, ...rawRef.current };
|
|
4967
4909
|
known = {};
|
|
4968
4910
|
for (const id of ids) if (all[id]) known[id] = all[id];
|
|
@@ -5025,7 +4967,7 @@ function GraphCanvas(props) {
|
|
|
5025
4967
|
onLayoutRef.current(own, { source: layoutSource, ms: layoutMsRef.current });
|
|
5026
4968
|
}
|
|
5027
4969
|
const stay = [...leaving].filter((id) => !positions[id] && dispRef.current[id]);
|
|
5028
|
-
seatOrphans(positions, built);
|
|
4970
|
+
seatOrphans(positions, built, /* @__PURE__ */ new Set([...leftRef.current, ...leaving]));
|
|
5029
4971
|
rawRef.current = positions;
|
|
5030
4972
|
layerOfRef.current = layerOf;
|
|
5031
4973
|
const t = viewRef.current.planes ? 1 : 0;
|
|
@@ -5783,6 +5725,7 @@ ${lt}`;
|
|
|
5783
5725
|
onAdd: editable ? startAdd : void 0,
|
|
5784
5726
|
onRelayout: controls.relayout && !diff ? relayout : void 0,
|
|
5785
5727
|
onRestructure: controls.relayout && !diff ? onRestructure : void 0,
|
|
5728
|
+
restructureContent: controls.relayout && !diff ? restructureContent : void 0,
|
|
5786
5729
|
layerIssue,
|
|
5787
5730
|
onForceLayers
|
|
5788
5731
|
}
|
|
@@ -5889,6 +5832,7 @@ export {
|
|
|
5889
5832
|
reachOf,
|
|
5890
5833
|
hittable,
|
|
5891
5834
|
detailed,
|
|
5835
|
+
edgeKindHidden,
|
|
5892
5836
|
shapeOf,
|
|
5893
5837
|
arrowOf,
|
|
5894
5838
|
relaxOverlaps,
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// src/layers.ts
|
|
2
2
|
var EMPTY = { layers: [], layerOf: /* @__PURE__ */ new Map() };
|
|
3
|
-
function orderedChildren(children, id) {
|
|
3
|
+
function orderedChildren(children, id, unordered = false) {
|
|
4
|
+
if (unordered) return null;
|
|
4
5
|
const kids = children.get(id) ?? [];
|
|
5
6
|
if (kids.length < 2) return null;
|
|
6
7
|
const withOrder = kids.filter((n) => typeof n.order === "number" && Number.isFinite(n.order));
|
|
@@ -29,10 +30,10 @@ function deriveLayers(model, colors = [], force = false) {
|
|
|
29
30
|
let anchor;
|
|
30
31
|
if (roots.length === 1) {
|
|
31
32
|
anchor = roots[0];
|
|
32
|
-
ordered = orderedChildren(children, anchor.id);
|
|
33
|
+
ordered = orderedChildren(children, anchor.id, anchor.data?.unordered === true);
|
|
33
34
|
if (!ordered && force) ordered = children.get(anchor.id) ?? null;
|
|
34
|
-
} else if (
|
|
35
|
-
ordered = roots;
|
|
35
|
+
} else if (roots.length > 1 && (force || roots.every((n) => n.order !== void 0))) {
|
|
36
|
+
ordered = [...roots].sort((a, b) => (a.order ?? Infinity) - (b.order ?? Infinity));
|
|
36
37
|
}
|
|
37
38
|
if (!ordered || ordered.length < 2) return EMPTY;
|
|
38
39
|
const layers = ordered.map((n, i) => ({
|
|
@@ -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
|
};
|