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.
@@ -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-WW23WBYG.js";
56
+ } from "./chunk-F4HDKER4.js";
56
57
  import {
57
58
  DetailPanel,
58
59
  I,
59
60
  Icon,
60
61
  StringsContext,
61
62
  useStrings
62
- } from "./chunk-PBF4KMQB.js";
63
+ } from "./chunk-3JGZ27DC.js";
63
64
  import {
64
65
  EN
65
- } from "./chunk-H2WV3DTN.js";
66
+ } from "./chunk-ISWKAU5G.js";
66
67
  import {
68
+ LAYOUTS,
67
69
  inlinePool
68
- } from "./chunk-YGRPNAXE.js";
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 (muteKinds.edges.has(e.ele.data("kind")) || out.has(e.src.id) || out.has(e.tgt.id)) out.add(e.id);
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.data.kind === "contains" && e.data.source !== VIRTUAL_ROOT) {
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
  }
@@ -912,19 +915,26 @@ function resolveOverlaps(boxes, o = {}) {
912
915
  }
913
916
 
914
917
  // src/layout/order.ts
918
+ var VIRTUAL_PARENT = "";
915
919
  function readOrder(elements) {
916
- const parentOf = /* @__PURE__ */ new Map();
917
- const kids = /* @__PURE__ */ new Map();
918
920
  const nodeIds = /* @__PURE__ */ new Set();
921
+ const rawParent = /* @__PURE__ */ new Map();
922
+ const rawOrder = /* @__PURE__ */ new Map();
919
923
  for (const el of elements) {
920
924
  const id = el.data.id;
921
925
  if (!id || el.data.source) continue;
922
926
  nodeIds.add(id);
923
- const parent = el.data.parent;
924
- if (!parent) continue;
925
- parentOf.set(id, parent);
927
+ const p = el.data.parentId ?? el.data.parent;
928
+ if (p) rawParent.set(id, p);
926
929
  const raw = el.data.order;
927
- const order = typeof raw === "number" && Number.isFinite(raw) ? raw : null;
930
+ rawOrder.set(id, typeof raw === "number" && Number.isFinite(raw) && raw > 0 ? raw : null);
931
+ }
932
+ const parentOf = /* @__PURE__ */ new Map();
933
+ const kids = /* @__PURE__ */ new Map();
934
+ for (const [id, p] of rawParent) {
935
+ const parent = nodeIds.has(p) ? p : VIRTUAL_PARENT;
936
+ parentOf.set(id, parent);
937
+ const order = rawOrder.get(id) ?? null;
928
938
  const arr = kids.get(parent);
929
939
  arr ? arr.push({ id, order }) : kids.set(parent, [{ id, order }]);
930
940
  }
@@ -946,126 +956,73 @@ function readOrder(elements) {
946
956
  orderedKids.set(parent, sorted);
947
957
  any = true;
948
958
  }
949
- return any ? { parentOf, orderedKids, nodeIds, any } : null;
950
- }
951
- function hash01(id) {
952
- let h = 2166136261;
953
- for (let i = 0; i < id.length; i++) {
954
- h ^= id.charCodeAt(i);
955
- h = Math.imul(h, 16777619);
956
- }
957
- return (h >>> 0) % 1e5 / 1e5;
959
+ return nodeIds.size ? { parentOf, orderedKids, nodeIds, any } : null;
958
960
  }
959
- var TAU = Math.PI * 2;
960
- var RING = 320;
961
- function orderSeed(elements, info) {
962
- const children = /* @__PURE__ */ new Map();
963
- for (const [id, parent] of info.parentOf) {
964
- const arr = children.get(parent);
965
- arr ? arr.push(id) : children.set(parent, [id]);
966
- }
967
- const roots = [...info.nodeIds].filter((id) => !info.parentOf.has(id));
968
- const weight = /* @__PURE__ */ new Map();
969
- const weigh = (id, seen = /* @__PURE__ */ new Set()) => {
970
- const hit = weight.get(id);
971
- if (hit != null) return hit;
972
- if (seen.has(id)) return 1;
973
- seen.add(id);
974
- let n = 1;
975
- for (const k of children.get(id) ?? []) n += weigh(k, seen);
976
- weight.set(id, n);
977
- return n;
978
- };
979
- for (const id of info.nodeIds) weigh(id);
980
- const out = {};
981
- const place = (id, cx, cy, from, to, level) => {
982
- const r = level * RING;
983
- const mid = (from + to) / 2;
984
- out[id] = { x: cx + Math.cos(mid) * r, y: cy + Math.sin(mid) * r };
985
- const kids = children.get(id) ?? [];
986
- if (!kids.length) return;
987
- const ordered = info.orderedKids.get(id);
988
- const list = ordered ?? kids;
989
- const total = list.reduce((s, k) => s + weigh(k), 0) || 1;
990
- let at = from;
991
- for (const k of list) {
992
- const span = (to - from) * weigh(k) / total;
993
- const jitter = ordered ? 0 : (hash01(k) - 0.5) * span * 0.6;
994
- const a = at + jitter;
995
- place(k, cx, cy, a, a + span, level + 1);
996
- at += span;
997
- }
998
- };
999
- if (roots.length === 1) place(roots[0], 0, 0, -Math.PI / 2, Math.PI * 1.5, 0);
1000
- else {
1001
- roots.forEach((root, i) => {
1002
- const from = -Math.PI / 2 + TAU * i / roots.length;
1003
- place(root, 0, 0, from, from + TAU / roots.length, 0);
1004
- });
961
+ function shuffled(ids, random) {
962
+ const out = [...ids].sort();
963
+ for (let i = out.length - 1; i > 0; i--) {
964
+ const j = Math.floor(random() * (i + 1));
965
+ [out[i], out[j]] = [out[j], out[i]];
1005
966
  }
1006
967
  return out;
1007
968
  }
1008
- var angle = (p) => Math.atan2(p.y, p.x);
1009
- function enforceOrder(elements, info, positions) {
969
+ var TAU = Math.PI * 2;
970
+ function orderSeed(elements, info, dims = {}, random = Math.random) {
971
+ const gap = LAYOUTS["cose-bilkent"].opts.idealEdgeLength;
1010
972
  const children = /* @__PURE__ */ new Map();
1011
973
  for (const [id, parent] of info.parentOf) {
1012
- const arr = children.get(parent);
1013
- arr ? arr.push(id) : children.set(parent, [id]);
974
+ const list = children.get(parent);
975
+ list ? list.push(id) : children.set(parent, [id]);
1014
976
  }
1015
- const out = {};
1016
- for (const [id, p] of Object.entries(positions)) out[id] = { ...p };
1017
- const weight = /* @__PURE__ */ new Map();
1018
- const weigh = (id, seen = /* @__PURE__ */ new Set()) => {
1019
- const hit = weight.get(id);
1020
- if (hit != null) return hit;
1021
- if (seen.has(id)) return 1;
1022
- seen.add(id);
1023
- let n = 1;
1024
- for (const k of children.get(id) ?? []) n += weigh(k, seen);
1025
- weight.set(id, n);
1026
- return n;
977
+ const diameter = (id) => {
978
+ const d = dims[id];
979
+ return d ? Math.hypot(d.w, d.h) : gap;
1027
980
  };
1028
- const subtree = (id, acc = []) => {
1029
- acc.push(id);
1030
- for (const k of children.get(id) ?? []) subtree(k, acc);
1031
- return acc;
981
+ const widths = /* @__PURE__ */ new Map();
982
+ const width = (id) => {
983
+ const cached = widths.get(id);
984
+ if (cached !== void 0) return cached;
985
+ const value = Math.max(
986
+ diameter(id) + gap,
987
+ (children.get(id) ?? []).reduce((sum, child) => sum + width(child), 0)
988
+ );
989
+ widths.set(id, value);
990
+ return value;
1032
991
  };
1033
- const rotate = (ids, pivot, delta) => {
1034
- if (Math.abs(delta) < 1e-6) return;
1035
- const c = Math.cos(delta), s = Math.sin(delta);
1036
- for (const id of ids) {
1037
- const p = out[id];
1038
- if (!p) continue;
1039
- const dx = p.x - pivot.x, dy = p.y - pivot.y;
1040
- out[id] = { x: pivot.x + dx * c - dy * s, y: pivot.y + dx * s + dy * c };
1041
- }
992
+ const offset = (span) => {
993
+ const z = Math.sqrt(-2 * Math.log(1 - random())) * Math.cos(TAU * random());
994
+ return Math.max(-3, Math.min(3, z)) * span / 8;
1042
995
  };
1043
- const settle = (parent) => {
1044
- const list = info.orderedKids.get(parent);
1045
- const pivot = out[parent];
1046
- if (!list || !pivot) return;
1047
- const present = list.filter((id) => out[id]);
1048
- if (present.length < 2) return;
1049
- const total = present.reduce((s, id) => s + weigh(id), 0) || 1;
1050
- let at = angle({ x: out[present[0]].x - pivot.x, y: out[present[0]].y - pivot.y });
1051
- for (const id of present) {
1052
- const p = out[id];
1053
- const cur = angle({ x: p.x - pivot.x, y: p.y - pivot.y });
1054
- let delta = at - cur;
1055
- while (delta > Math.PI) delta -= TAU;
1056
- while (delta < -Math.PI) delta += TAU;
1057
- rotate(subtree(id), pivot, delta);
1058
- at += TAU * weigh(id) / total;
1059
- }
1060
- for (const id of present) settle(id);
996
+ const out = {};
997
+ const placeChildren = (parent, ids, parentRadius, sector) => {
998
+ const list = (parent === null ? void 0 : info.orderedKids.get(parent)) ?? shuffled(ids, random);
999
+ if (!list.length) return;
1000
+ const span = sector ? (sector.to - sector.from) / list.length : TAU / (list.length + 1);
1001
+ list.forEach((id, i) => {
1002
+ const middle2 = sector ? sector.from + (i + 0.5) * span : -Math.PI / 2 + (i + 1) * span;
1003
+ const angle = middle2 + offset(span);
1004
+ const clearance = gap + (diameter(parent ?? VIRTUAL_PARENT) + diameter(id)) / 2;
1005
+ const radius = Math.max(parentRadius + clearance, width(id) / span);
1006
+ const p = { x: Math.cos(angle) * radius, y: Math.sin(angle) * radius };
1007
+ out[id] = p;
1008
+ placeChildren(id, children.get(id) ?? [], radius, { from: middle2 - span / 2, to: middle2 + span / 2 });
1009
+ });
1061
1010
  };
1062
1011
  const roots = [...info.nodeIds].filter((id) => !info.parentOf.has(id));
1063
- for (const root of roots) settle(root);
1012
+ if (children.has(VIRTUAL_PARENT)) roots.push(VIRTUAL_PARENT);
1013
+ if (roots.length === 1) {
1014
+ const root = roots[0];
1015
+ out[root] = { x: 0, y: 0 };
1016
+ placeChildren(root, children.get(root) ?? [], 0);
1017
+ } else {
1018
+ placeChildren(null, roots, 0);
1019
+ }
1020
+ delete out[VIRTUAL_PARENT];
1064
1021
  return out;
1065
1022
  }
1066
1023
 
1067
1024
  // src/layout/engine.ts
1068
- var CACHE_PREFIX = "gb:pos:v3:";
1025
+ var CACHE_PREFIX = "gb:pos:v6:";
1069
1026
  var CACHE_KEEP = 16;
1070
1027
  function shapeHash(elements, salt) {
1071
1028
  const parts = [];
@@ -1190,6 +1147,18 @@ async function runDivide(req, aborted) {
1190
1147
  }
1191
1148
  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
1149
  const coarseEls = buildCoarseElements(comps, compOf, req.elements, (k) => byKey.get(k).bbox, rootDims);
1150
+ if (req.seed) {
1151
+ const seed2 = req.seed;
1152
+ const compByKey = new Map(comps.map((c) => [c.key, c]));
1153
+ 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;
1154
+ for (const el of coarseEls) {
1155
+ if (el.data.source) continue;
1156
+ const key = el.data.id;
1157
+ const pts = key === VIRTUAL_ROOT ? Object.values(seed2) : (compByKey.get(key)?.nodes ?? []).map((n) => seed2[n.data.id]).filter(Boolean);
1158
+ const p = mid(pts);
1159
+ if (p) el.position = p;
1160
+ }
1161
+ }
1193
1162
  const avgSize = comps.reduce((s, c) => {
1194
1163
  const b = byKey.get(c.key).bbox;
1195
1164
  return s + (b.w + b.h) / 2;
@@ -1277,11 +1246,7 @@ async function runWhole(req, aborted) {
1277
1246
  if (el.data.source) {
1278
1247
  if (el.data._force !== false) edges.push({ data: el.data, classes: el.classes });
1279
1248
  } else {
1280
- const d = req.dims[el.data.id];
1281
- nodes.push({
1282
- data: { ...el.data, detail: void 0, ...d ? { _w: d.w, _h: d.h } : {} },
1283
- classes: el.classes
1284
- });
1249
+ nodes.push(toJobNode(el, req.dims, req.seed));
1285
1250
  }
1286
1251
  }
1287
1252
  const [runner] = req.pool(1);
@@ -1315,16 +1280,18 @@ function computeLayout(req) {
1315
1280
  const current = inflight.get(owner);
1316
1281
  if (current) current.superseded = true;
1317
1282
  const order = readOrder(req.elements);
1318
- const job = order && !req.seed ? { ...req, seed: orderSeed(req.elements, order) } : req;
1283
+ const known = req.force ? void 0 : req.seed;
1284
+ const complete = order && known && [...order.nodeIds].every((id) => known[id]);
1285
+ const seed = complete ? known : { ...order ? orderSeed(req.elements, order, req.dims) : {}, ...known };
1286
+ const job = { ...req, seed };
1319
1287
  const run = { hash, superseded: false, promise: null };
1320
1288
  const runner = mode === "whole" ? runWhole : runDivide;
1321
1289
  run.promise = runner(job, () => run.superseded).then((pos) => {
1322
- const settled = order ? enforceOrder(req.elements, order, pos) : pos;
1323
1290
  if (!run.stale) {
1324
- cachePut(hash, settled);
1325
- lastByNs.set(ns, { hash, pos: settled });
1291
+ cachePut(hash, pos);
1292
+ lastByNs.set(ns, { hash, pos });
1326
1293
  }
1327
- return settled;
1294
+ return pos;
1328
1295
  }).finally(() => {
1329
1296
  if (inflight.get(owner) === run) inflight.delete(owner);
1330
1297
  });
@@ -1717,7 +1684,7 @@ function Hl({ text, re }) {
1717
1684
  out.push(text.slice(last));
1718
1685
  return /* @__PURE__ */ jsx(Fragment, { children: out });
1719
1686
  }
1720
- function LayerPicker({ layers, view, setView, disabled }) {
1687
+ function LayerPicker({ layers, view, setView, disabled, collapsed }) {
1721
1688
  const t = useStrings();
1722
1689
  const box = useRef(null);
1723
1690
  const [thumb, setThumb] = useState2(null);
@@ -1727,7 +1694,7 @@ function LayerPicker({ layers, view, setView, disabled }) {
1727
1694
  const single = stacked ? null : view.layers?.[0] ?? layers[0].id;
1728
1695
  useLayoutEffect2(() => {
1729
1696
  const root = box.current;
1730
- if (!root || single == null) {
1697
+ if (collapsed || !root || single == null) {
1731
1698
  setThumb(null);
1732
1699
  return;
1733
1700
  }
@@ -1767,8 +1734,8 @@ function LayerPicker({ layers, view, setView, disabled }) {
1767
1734
  const next = layers.map((l) => l.id).filter((l) => l === id ? !on.has(l) : on.has(l));
1768
1735
  setView({ layers: next });
1769
1736
  };
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: [
1737
+ return /* @__PURE__ */ jsxs("div", { className: `gb-segm gb-layers${stacked ? " is-multi" : ""}${collapsed ? " is-collapsed" : ""}`, role: stacked ? "group" : "radiogroup", children: [
1738
+ /* @__PURE__ */ jsxs("div", { className: `gb-layer-track${edges.left ? " can-left" : ""}${edges.right ? " can-right" : ""}`, ref: box, "aria-hidden": collapsed, children: [
1772
1739
  thumb && /* @__PURE__ */ jsx("i", { className: "gb-thumb", style: { transform: `translateX(${thumb.x}px)`, width: thumb.w } }),
1773
1740
  layers.map((l) => {
1774
1741
  const lit = stacked ? on.has(l.id) : l.id === single;
@@ -1796,7 +1763,7 @@ function LayerPicker({ layers, view, setView, disabled }) {
1796
1763
  disabled,
1797
1764
  "aria-label": t.stack,
1798
1765
  title: t.stackTip(stacked),
1799
- onClick: () => setView(stacked ? { planes: false } : { planes: true, layers: null }),
1766
+ onClick: () => setView(stacked ? { planes: false, layers: null } : { planes: true, layers: null }),
1800
1767
  children: /* @__PURE__ */ jsx(Icon, { d: I.stack })
1801
1768
  }
1802
1769
  )
@@ -2013,7 +1980,7 @@ function ViewMenu(p) {
2013
1980
  "data-y": pop.placement?.side,
2014
1981
  style: pop.placement ? { left: pop.placement.left, top: pop.placement.top, right: "auto", bottom: "auto" } : { visibility: "hidden" },
2015
1982
  onClick: (e) => {
2016
- if (e.target.closest(".gb-menu-item")) pop.setOpen(false);
1983
+ if (e.target.closest(".gb-menu-item") && !e.target.closest("[data-menu-keep-open]")) pop.setOpen(false);
2017
1984
  },
2018
1985
  onChange: (e) => {
2019
1986
  if (e.target.tagName === "SELECT") pop.setOpen(false);
@@ -2047,7 +2014,7 @@ function Toolbar(p) {
2047
2014
  inputRef: p.inputRef
2048
2015
  }
2049
2016
  ),
2050
- multi && /* @__PURE__ */ jsx(LayerPicker, { layers: p.layers, view, setView, disabled: p.busy }),
2017
+ multi && /* @__PURE__ */ jsx(LayerPicker, { layers: p.layers, view, setView, disabled: p.busy, collapsed: !view.planes }),
2051
2018
  controls.layers && !multi && /* @__PURE__ */ jsx(LayerUnavailable, { reason: p.layerIssue ?? "", onForce: p.onForceLayers }),
2052
2019
  originPick && view.origins?.length === 1 && /* Filtering by source: the state is in plain sight, and one × returns to everything. */
2053
2020
  /* @__PURE__ */ jsxs("span", { className: "gb-chip", title: view.origins[0], children: [
@@ -2077,7 +2044,8 @@ function Toolbar(p) {
2077
2044
  ] }),
2078
2045
  (p.onRelayout || p.onRestructure) && /* @__PURE__ */ jsxs("div", { className: "gb-panel-sec gb-menu-list", children: [
2079
2046
  p.onRelayout && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: p.onRelayout, disabled: p.busy, children: t.relayout }),
2080
- p.onRestructure && /* @__PURE__ */ jsx("button", { className: "gb-menu-item", onClick: p.onRestructure, disabled: p.busy, children: t.restructure })
2047
+ 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 }),
2048
+ p.restructureContent
2081
2049
  ] })
2082
2050
  ] })
2083
2051
  ] });
@@ -2642,6 +2610,7 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2642
2610
  [node]
2643
2611
  );
2644
2612
  const [text, setText] = useState3(initial);
2613
+ const [orderText, setOrderText] = useState3(node?.order?.toString() ?? "");
2645
2614
  const [confirming, setConfirming] = useState3(false);
2646
2615
  const idErr = creating && id ? checkEdit(model, { op: "addNode", id, set: {} }) : null;
2647
2616
  const below = useMemo2(() => {
@@ -2665,8 +2634,9 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2665
2634
  setError(t.badJson);
2666
2635
  return;
2667
2636
  }
2637
+ const order = parent && orderText.trim() ? Number(orderText) : null;
2668
2638
  if (creating) {
2669
- if (submit({ op: "addNode", id: id.trim(), set: { ...content, parent } })) onCancel();
2639
+ if (submit({ op: "addNode", id: id.trim(), set: { ...content, parent, order } })) onCancel();
2670
2640
  return;
2671
2641
  }
2672
2642
  const set = {};
@@ -2674,6 +2644,7 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2674
2644
  if ((content.kind ?? void 0) !== node.kind) set.kind = content.kind;
2675
2645
  if (pretty(content.data ?? {}) !== pretty(node.data ?? {})) set.data = content.data ?? {};
2676
2646
  if (parent !== (node.parent ?? null)) set.parent = parent;
2647
+ if (order !== (node.order ?? null)) set.order = order;
2677
2648
  if (!Object.keys(set).length) {
2678
2649
  onCancel();
2679
2650
  return;
@@ -2739,6 +2710,23 @@ function NodeForm({ target, model, onSubmit, onCancel, onRetarget, renderEditor,
2739
2710
  }
2740
2711
  )
2741
2712
  ] }),
2713
+ /* @__PURE__ */ jsxs2("div", { className: "gb-fld", children: [
2714
+ /* @__PURE__ */ jsx2("label", { className: "gb-k", htmlFor: `${uid}-order`, children: "Order" }),
2715
+ /* @__PURE__ */ jsx2(
2716
+ "input",
2717
+ {
2718
+ id: `${uid}-order`,
2719
+ className: "gb-input",
2720
+ type: "number",
2721
+ min: "0",
2722
+ step: "any",
2723
+ disabled: !parent,
2724
+ placeholder: "Unordered",
2725
+ value: orderText,
2726
+ onChange: (e) => setOrderText(e.target.value)
2727
+ }
2728
+ )
2729
+ ] }),
2742
2730
  /* @__PURE__ */ jsxs2("div", { className: "gb-fld gb-grow", children: [
2743
2731
  /* @__PURE__ */ jsxs2("label", { className: "gb-k", htmlFor: `${uid}-json`, children: [
2744
2732
  t.content,
@@ -2875,7 +2863,7 @@ function readMarks(c, cy, style, nodeKinds, edgeKinds) {
2875
2863
  }
2876
2864
  for (const k of edgeKinds) {
2877
2865
  if (c.strokes.has(k) || !live) continue;
2878
- const e = cy.edges(`.${cls(k)}`)[0];
2866
+ const e = cy.edges(`.${edgeKindClass(k)}`)[0];
2879
2867
  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) });
2880
2868
  }
2881
2869
  return {
@@ -3515,8 +3503,7 @@ function hideEdgesByKind(cy, hn, he, prev) {
3515
3503
  const off = /* @__PURE__ */ new Set();
3516
3504
  if (hn.size || he.size) {
3517
3505
  cy.edges().forEach((e) => {
3518
- if (e.hasClass("contains")) return;
3519
- if (he.has(e.data("kind")) || hn.has(e.source().data("kind")) || hn.has(e.target().data("kind"))) off.add(e.id());
3506
+ 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());
3520
3507
  });
3521
3508
  }
3522
3509
  for (const id of prev) if (!off.has(id)) cy.$id(id).style("display", "element");
@@ -3669,12 +3656,13 @@ function presenceGroups(cy, live, marks) {
3669
3656
  graft: cy.collection(bucket.graft)
3670
3657
  };
3671
3658
  }
3672
- function seatOrphans(pos, built) {
3659
+ function seatOrphans(pos, built, excluded = /* @__PURE__ */ new Set()) {
3673
3660
  const missing = [];
3674
3661
  let sx = 0, sy = 0, n = 0;
3675
3662
  for (const el of built.elements) {
3676
3663
  if (el.data.source) continue;
3677
3664
  const id = el.data.id;
3665
+ if (excluded.has(id)) continue;
3678
3666
  const p = pos[id];
3679
3667
  if (p) {
3680
3668
  sx += p.x;
@@ -3781,6 +3769,7 @@ function GraphCanvas(props) {
3781
3769
  renderEditor,
3782
3770
  resolveUrl,
3783
3771
  onRestructure,
3772
+ restructureContent,
3784
3773
  layerIssue,
3785
3774
  onForceLayers,
3786
3775
  animate = true,
@@ -3889,6 +3878,9 @@ function GraphCanvas(props) {
3889
3878
  const searchInputRef = useRef4(null);
3890
3879
  const [selected, setSelected] = useState5(null);
3891
3880
  const [editing, setEditing] = useState5(null);
3881
+ const editingModel = props.editModel ?? model;
3882
+ const modelRef = useRef4(model);
3883
+ modelRef.current = model;
3892
3884
  const editable = !!onEdit && !diff;
3893
3885
  const onEditRef = useRef4(onEdit);
3894
3886
  onEditRef.current = onEdit;
@@ -4631,7 +4623,9 @@ function GraphCanvas(props) {
4631
4623
  origin: d.origin,
4632
4624
  container: builtRef.current.containers.has(d.id),
4633
4625
  flags: el.classes().filter((c) => !["gb-node", "flat", "container", "gb-hit", "gb-preview", "gb-preview-hop", d.kind].includes(c)),
4634
- detail: d.detail ?? null
4626
+ detail: d.detail ?? null,
4627
+ parent: modelRef.current.index.get(d.id)?.parent,
4628
+ order: modelRef.current.index.get(d.id)?.order
4635
4629
  });
4636
4630
  }, []);
4637
4631
  const selectTouch = useCallback2((target) => {
@@ -4769,10 +4763,10 @@ function GraphCanvas(props) {
4769
4763
  const v0 = cam();
4770
4764
  const leftBefore = leftRef.current;
4771
4765
  applyPositions(cy, union, false);
4772
- leftRef.current = /* @__PURE__ */ new Set();
4766
+ leftRef.current = leftBefore;
4773
4767
  fitAll(cy);
4774
4768
  const vU = cam();
4775
- leftRef.current = t.leaving;
4769
+ leftRef.current = /* @__PURE__ */ new Set([...leftBefore, ...t.leaving]);
4776
4770
  fitAll(cy);
4777
4771
  const v1 = cam();
4778
4772
  leftRef.current = leftBefore;
@@ -4869,6 +4863,7 @@ function GraphCanvas(props) {
4869
4863
  worn.push([el, Object.fromEntries(SKIN_SIZE_PROPS.map((p) => [p, el.style(p)]))]);
4870
4864
  });
4871
4865
  }
4866
+ const hiddenBeforeMeasure = cy.nodes().filter((n) => n.style("display") === "none");
4872
4867
  cy.batch(() => {
4873
4868
  for (const [el] of worn) el.removeStyle(sizeProps);
4874
4869
  cy.nodes().style("display", "none");
@@ -4877,13 +4872,14 @@ function GraphCanvas(props) {
4877
4872
  const dims = {};
4878
4873
  cy.nodes(":childless").forEach((n) => {
4879
4874
  const d = n.layoutDimensions({ nodeDimensionsIncludeLabels: true });
4880
- dims[n.id()] = { w: d.w, h: d.h };
4875
+ dims[n.id()] = { w: Math.round(d.w * 64) / 64, h: Math.round(d.h * 64) / 64 };
4881
4876
  });
4882
4877
  dimsRef.current = dims;
4883
4878
  if (scaled) cy.style(sheetFor(false));
4884
4879
  if (worn.length) cy.batch(() => {
4885
4880
  for (const [el, v] of worn) el.style(v);
4886
4881
  });
4882
+ hiddenBeforeMeasure.style("display", "none");
4887
4883
  if (diffRef.current) hideGhosts(cy);
4888
4884
  const run = ++runRef.current;
4889
4885
  if (owedLayoutRef.current && (force || !owedLayoutRef.current.force)) owedLayoutRef.current = null;
@@ -4970,7 +4966,7 @@ function GraphCanvas(props) {
4970
4966
  onLayoutRef.current(own, { source: layoutSource, ms: layoutMsRef.current });
4971
4967
  }
4972
4968
  const stay = [...leaving].filter((id) => !positions[id] && dispRef.current[id]);
4973
- seatOrphans(positions, built);
4969
+ seatOrphans(positions, built, /* @__PURE__ */ new Set([...leftRef.current, ...leaving]));
4974
4970
  rawRef.current = positions;
4975
4971
  layerOfRef.current = layerOf;
4976
4972
  const t = viewRef.current.planes ? 1 : 0;
@@ -5548,6 +5544,8 @@ ${lt}`;
5548
5544
  if (!s || !n) return null;
5549
5545
  return {
5550
5546
  ...s,
5547
+ parent: n.parent,
5548
+ order: n.order,
5551
5549
  label: n.label,
5552
5550
  kind: n.kind ?? "",
5553
5551
  layer: n.layer,
@@ -5564,14 +5562,14 @@ ${lt}`;
5564
5562
  const submitEdit = useCallback2((input) => {
5565
5563
  const only = view.origins?.length === 1 ? view.origins[0] : void 0;
5566
5564
  const op = input.op === "addNode" && only && !input.origin ? { ...input, origin: only } : input;
5567
- const err = checkEdit(model, op);
5565
+ const err = checkEdit(editingModel, op) ?? props.validateEdit?.(op);
5568
5566
  if (err) return err;
5569
5567
  if (op.op === "addNode") pendingPickRef.current = op.id;
5570
5568
  else if (op.op === "removeNode") setSelected(null);
5571
5569
  else keepSelRef.current = selected?.id ?? null;
5572
5570
  onEditRef.current?.(op);
5573
5571
  return null;
5574
- }, [model, selected, view.origins]);
5572
+ }, [editingModel, selected, view.origins, props.validateEdit]);
5575
5573
  const startAdd = useCallback2((what) => {
5576
5574
  setEditing(what === "node" ? { what, parent: selected?.id ?? null } : { what, source: selected?.id });
5577
5575
  }, [selected]);
@@ -5579,7 +5577,7 @@ ${lt}`;
5579
5577
  EditPanel,
5580
5578
  {
5581
5579
  target: editing,
5582
- model,
5580
+ model: editingModel,
5583
5581
  onSubmit: submitEdit,
5584
5582
  renderEditor,
5585
5583
  colorOf,
@@ -5726,6 +5724,7 @@ ${lt}`;
5726
5724
  onAdd: editable ? startAdd : void 0,
5727
5725
  onRelayout: controls.relayout && !diff ? relayout : void 0,
5728
5726
  onRestructure: controls.relayout && !diff ? onRestructure : void 0,
5727
+ restructureContent: controls.relayout && !diff ? restructureContent : void 0,
5729
5728
  layerIssue,
5730
5729
  onForceLayers
5731
5730
  }
@@ -5832,6 +5831,7 @@ export {
5832
5831
  reachOf,
5833
5832
  hittable,
5834
5833
  detailed,
5834
+ edgeKindHidden,
5835
5835
  shapeOf,
5836
5836
  arrowOf,
5837
5837
  relaxOverlaps,