@glyphjs/components 0.5.1 → 0.6.0

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/dist/index.cjs CHANGED
@@ -1632,16 +1632,16 @@ function useZoomInteraction({
1632
1632
  };
1633
1633
  }, [interactionMode, svgRef]);
1634
1634
  const zoomBehavior = react.useMemo(() => {
1635
- const zoom3 = d32__namespace.zoom().scaleExtent([0.1, 4]);
1636
- if (typeof zoom3.filter === "function") {
1637
- zoom3.filter(filterFunction);
1635
+ const zoom2 = d32__namespace.zoom().scaleExtent([0.1, 4]);
1636
+ if (typeof zoom2.filter === "function") {
1637
+ zoom2.filter(filterFunction);
1638
1638
  }
1639
- zoom3.on("zoom", (event) => {
1639
+ zoom2.on("zoom", (event) => {
1640
1640
  if (rootRef.current) {
1641
1641
  d32__namespace.select(rootRef.current).attr("transform", event.transform.toString());
1642
1642
  }
1643
1643
  });
1644
- return zoom3;
1644
+ return zoom2;
1645
1645
  }, [filterFunction, rootRef]);
1646
1646
  const handleActivate = react.useCallback(() => {
1647
1647
  if (interactionMode === "click-to-activate") {
@@ -4038,7 +4038,7 @@ function getThemeVar3(container, varName, fallback) {
4038
4038
  return getComputedStyle(container).getPropertyValue(varName).trim() || fallback;
4039
4039
  }
4040
4040
  var ARROW_MARKER_ID3 = "glyph-arch-arrowhead";
4041
- function renderArchitecture(svgElement, layout) {
4041
+ function renderArchitecture(svgElement, layout, rootRef, zoomBehavior) {
4042
4042
  const svg = d32__namespace.select(svgElement);
4043
4043
  svg.selectAll("*").remove();
4044
4044
  const width = Math.max(layout.width, 200);
@@ -4051,10 +4051,12 @@ function renderArchitecture(svgElement, layout) {
4051
4051
  const nodeStrokeWidth = getThemeVar3(container, "--glyph-node-stroke-width", "1.5");
4052
4052
  const nodeFillOpacity = getThemeVar3(container, "--glyph-node-fill-opacity", "0.85");
4053
4053
  const root = svg.append("g").attr("class", "glyph-architecture-root");
4054
- const zoomBehavior = d32__namespace.zoom().scaleExtent([0.1, 4]).on("zoom", (event) => {
4055
- root.attr("transform", event.transform.toString());
4056
- });
4057
- svg.call(zoomBehavior);
4054
+ if (rootRef) {
4055
+ rootRef.current = root.node();
4056
+ }
4057
+ if (zoomBehavior) {
4058
+ svg.call(zoomBehavior);
4059
+ }
4058
4060
  const sortedZones = [...layout.zones].sort((a, b) => a.depth - b.depth);
4059
4061
  const zoneGroup = root.append("g").attr("class", "glyph-architecture-zones");
4060
4062
  for (const zone of sortedZones) {
@@ -4122,10 +4124,19 @@ function renderArchitecture(svgElement, layout) {
4122
4124
  }
4123
4125
  function Architecture({
4124
4126
  data,
4125
- container
4127
+ container,
4128
+ block
4126
4129
  }) {
4127
4130
  const svgRef = react.useRef(null);
4131
+ const rootRef = react.useRef(null);
4132
+ const containerRef = react.useRef(null);
4128
4133
  const [layout, setLayout] = react.useState(null);
4134
+ const { overlayProps, zoomBehavior, zoomIn, zoomOut, resetZoom } = useZoomInteraction({
4135
+ svgRef,
4136
+ rootRef,
4137
+ interactionMode: data.interactionMode ?? "modifier-key",
4138
+ blockId: block.id
4139
+ });
4129
4140
  react.useEffect(() => {
4130
4141
  let cancelled = false;
4131
4142
  computeArchitectureLayout(data).then((result) => {
@@ -4137,62 +4148,72 @@ function Architecture({
4137
4148
  }, [data]);
4138
4149
  react.useEffect(() => {
4139
4150
  if (!svgRef.current || !layout) return;
4140
- renderArchitecture(svgRef.current, layout);
4141
- }, [layout]);
4151
+ renderArchitecture(svgRef.current, layout, rootRef, zoomBehavior);
4152
+ }, [layout, zoomBehavior]);
4142
4153
  const nodeCount = countLeafNodes(data.children);
4143
4154
  const edgeCount = data.edges.length;
4144
4155
  const ariaLabel = data.title ? `${data.title}: architecture diagram with ${nodeCount} nodes and ${edgeCount} connections` : `Architecture diagram with ${nodeCount} nodes and ${edgeCount} connections`;
4145
4156
  const flatNodes = flattenNodes(data.children);
4146
- return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "glyph-architecture-container", children: [
4147
- !layout && /* @__PURE__ */ jsxRuntime.jsx(
4148
- "div",
4149
- {
4150
- style: {
4151
- padding: "2rem",
4152
- textAlign: "center",
4153
- color: "var(--glyph-text-muted, #7a8599)",
4154
- fontFamily: "Inter, system-ui, sans-serif",
4155
- fontSize: "13px"
4156
- },
4157
- children: "Computing layout..."
4158
- }
4159
- ),
4160
- /* @__PURE__ */ jsxRuntime.jsx(
4161
- "svg",
4162
- {
4163
- ref: svgRef,
4164
- role: "img",
4165
- "aria-label": ariaLabel,
4166
- width: "100%",
4167
- height: "100%",
4168
- style: {
4169
- minHeight: container.tier === "compact" ? 200 : 300,
4170
- maxHeight: container.tier === "compact" ? 500 : 700,
4171
- display: layout ? "block" : "none"
4172
- }
4173
- }
4174
- ),
4175
- /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "sr-only", "aria-label": "Architecture data", style: SR_ONLY_STYLE6, children: [
4176
- /* @__PURE__ */ jsxRuntime.jsx("caption", { children: "Architecture nodes and connections" }),
4177
- /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4178
- /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Node" }),
4179
- /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Zone" }),
4180
- /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Connections" })
4181
- ] }) }),
4182
- /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: flatNodes.map((node) => {
4183
- const connections = data.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => {
4184
- const target = e.from === node.id ? e.to : e.from;
4185
- const dir = e.from === node.id ? "->" : "<-";
4186
- return `${dir} ${target}${e.label ? ` (${e.label})` : ""}`;
4187
- }).join(", ");
4188
- return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4189
- /* @__PURE__ */ jsxRuntime.jsx("td", { children: node.label }),
4190
- /* @__PURE__ */ jsxRuntime.jsx("td", { children: node.zone ?? "" }),
4191
- /* @__PURE__ */ jsxRuntime.jsx("td", { children: connections })
4192
- ] }, node.id);
4193
- }) })
4194
- ] })
4195
- ] });
4157
+ return /* @__PURE__ */ jsxRuntime.jsxs(
4158
+ "div",
4159
+ {
4160
+ ref: containerRef,
4161
+ className: "glyph-architecture-container",
4162
+ style: { position: "relative" },
4163
+ children: [
4164
+ !layout && /* @__PURE__ */ jsxRuntime.jsx(
4165
+ "div",
4166
+ {
4167
+ style: {
4168
+ padding: "2rem",
4169
+ textAlign: "center",
4170
+ color: "var(--glyph-text-muted, #7a8599)",
4171
+ fontFamily: "Inter, system-ui, sans-serif",
4172
+ fontSize: "13px"
4173
+ },
4174
+ children: "Computing layout..."
4175
+ }
4176
+ ),
4177
+ /* @__PURE__ */ jsxRuntime.jsx(
4178
+ "svg",
4179
+ {
4180
+ ref: svgRef,
4181
+ role: "img",
4182
+ "aria-label": ariaLabel,
4183
+ width: "100%",
4184
+ height: "100%",
4185
+ style: {
4186
+ minHeight: container.tier === "compact" ? 200 : 300,
4187
+ maxHeight: container.tier === "compact" ? 500 : 700,
4188
+ display: layout ? "block" : "none"
4189
+ }
4190
+ }
4191
+ ),
4192
+ layout && overlayProps && /* @__PURE__ */ jsxRuntime.jsx(InteractionOverlay, { ...overlayProps }),
4193
+ layout && data.showZoomControls !== false && /* @__PURE__ */ jsxRuntime.jsx(ZoomControls, { onZoomIn: zoomIn, onZoomOut: zoomOut, onReset: resetZoom }),
4194
+ /* @__PURE__ */ jsxRuntime.jsxs("table", { className: "sr-only", "aria-label": "Architecture data", style: SR_ONLY_STYLE6, children: [
4195
+ /* @__PURE__ */ jsxRuntime.jsx("caption", { children: "Architecture nodes and connections" }),
4196
+ /* @__PURE__ */ jsxRuntime.jsx("thead", { children: /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4197
+ /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Node" }),
4198
+ /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Zone" }),
4199
+ /* @__PURE__ */ jsxRuntime.jsx("th", { scope: "col", children: "Connections" })
4200
+ ] }) }),
4201
+ /* @__PURE__ */ jsxRuntime.jsx("tbody", { children: flatNodes.map((node) => {
4202
+ const connections = data.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => {
4203
+ const target = e.from === node.id ? e.to : e.from;
4204
+ const dir = e.from === node.id ? "->" : "<-";
4205
+ return `${dir} ${target}${e.label ? ` (${e.label})` : ""}`;
4206
+ }).join(", ");
4207
+ return /* @__PURE__ */ jsxRuntime.jsxs("tr", { children: [
4208
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: node.label }),
4209
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: node.zone ?? "" }),
4210
+ /* @__PURE__ */ jsxRuntime.jsx("td", { children: connections })
4211
+ ] }, node.id);
4212
+ }) })
4213
+ ] })
4214
+ ]
4215
+ }
4216
+ );
4196
4217
  }
4197
4218
  function flattenNodes(children, zone) {
4198
4219
  const result = [];