@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.d.cts CHANGED
@@ -381,6 +381,8 @@ interface ArchitectureData {
381
381
  children: ArchitectureNode[];
382
382
  edges: ArchitectureEdge[];
383
383
  layout?: 'top-down' | 'left-right' | 'bottom-up';
384
+ interactionMode?: 'modifier-key' | 'click-to-activate' | 'always';
385
+ showZoomControls?: boolean;
384
386
  }
385
387
  interface PositionedArchNode {
386
388
  id: string;
@@ -421,7 +423,7 @@ interface ArchitectureLayout {
421
423
  }
422
424
  declare function computeArchitectureLayout(data: ArchitectureData): Promise<ArchitectureLayout>;
423
425
 
424
- declare function Architecture({ data, container, }: GlyphComponentProps<ArchitectureData>): ReactElement;
426
+ declare function Architecture({ data, container, block, }: GlyphComponentProps<ArchitectureData>): ReactElement;
425
427
 
426
428
  declare const architectureDefinition: GlyphComponentDefinition<ArchitectureData>;
427
429
 
package/dist/index.d.ts CHANGED
@@ -381,6 +381,8 @@ interface ArchitectureData {
381
381
  children: ArchitectureNode[];
382
382
  edges: ArchitectureEdge[];
383
383
  layout?: 'top-down' | 'left-right' | 'bottom-up';
384
+ interactionMode?: 'modifier-key' | 'click-to-activate' | 'always';
385
+ showZoomControls?: boolean;
384
386
  }
385
387
  interface PositionedArchNode {
386
388
  id: string;
@@ -421,7 +423,7 @@ interface ArchitectureLayout {
421
423
  }
422
424
  declare function computeArchitectureLayout(data: ArchitectureData): Promise<ArchitectureLayout>;
423
425
 
424
- declare function Architecture({ data, container, }: GlyphComponentProps<ArchitectureData>): ReactElement;
426
+ declare function Architecture({ data, container, block, }: GlyphComponentProps<ArchitectureData>): ReactElement;
425
427
 
426
428
  declare const architectureDefinition: GlyphComponentDefinition<ArchitectureData>;
427
429
 
package/dist/index.js CHANGED
@@ -1607,16 +1607,16 @@ function useZoomInteraction({
1607
1607
  };
1608
1608
  }, [interactionMode, svgRef]);
1609
1609
  const zoomBehavior = useMemo(() => {
1610
- const zoom3 = d32.zoom().scaleExtent([0.1, 4]);
1611
- if (typeof zoom3.filter === "function") {
1612
- zoom3.filter(filterFunction);
1610
+ const zoom2 = d32.zoom().scaleExtent([0.1, 4]);
1611
+ if (typeof zoom2.filter === "function") {
1612
+ zoom2.filter(filterFunction);
1613
1613
  }
1614
- zoom3.on("zoom", (event) => {
1614
+ zoom2.on("zoom", (event) => {
1615
1615
  if (rootRef.current) {
1616
1616
  d32.select(rootRef.current).attr("transform", event.transform.toString());
1617
1617
  }
1618
1618
  });
1619
- return zoom3;
1619
+ return zoom2;
1620
1620
  }, [filterFunction, rootRef]);
1621
1621
  const handleActivate = useCallback(() => {
1622
1622
  if (interactionMode === "click-to-activate") {
@@ -4013,7 +4013,7 @@ function getThemeVar3(container, varName, fallback) {
4013
4013
  return getComputedStyle(container).getPropertyValue(varName).trim() || fallback;
4014
4014
  }
4015
4015
  var ARROW_MARKER_ID3 = "glyph-arch-arrowhead";
4016
- function renderArchitecture(svgElement, layout) {
4016
+ function renderArchitecture(svgElement, layout, rootRef, zoomBehavior) {
4017
4017
  const svg = d32.select(svgElement);
4018
4018
  svg.selectAll("*").remove();
4019
4019
  const width = Math.max(layout.width, 200);
@@ -4026,10 +4026,12 @@ function renderArchitecture(svgElement, layout) {
4026
4026
  const nodeStrokeWidth = getThemeVar3(container, "--glyph-node-stroke-width", "1.5");
4027
4027
  const nodeFillOpacity = getThemeVar3(container, "--glyph-node-fill-opacity", "0.85");
4028
4028
  const root = svg.append("g").attr("class", "glyph-architecture-root");
4029
- const zoomBehavior = d32.zoom().scaleExtent([0.1, 4]).on("zoom", (event) => {
4030
- root.attr("transform", event.transform.toString());
4031
- });
4032
- svg.call(zoomBehavior);
4029
+ if (rootRef) {
4030
+ rootRef.current = root.node();
4031
+ }
4032
+ if (zoomBehavior) {
4033
+ svg.call(zoomBehavior);
4034
+ }
4033
4035
  const sortedZones = [...layout.zones].sort((a, b) => a.depth - b.depth);
4034
4036
  const zoneGroup = root.append("g").attr("class", "glyph-architecture-zones");
4035
4037
  for (const zone of sortedZones) {
@@ -4097,10 +4099,19 @@ function renderArchitecture(svgElement, layout) {
4097
4099
  }
4098
4100
  function Architecture({
4099
4101
  data,
4100
- container
4102
+ container,
4103
+ block
4101
4104
  }) {
4102
4105
  const svgRef = useRef(null);
4106
+ const rootRef = useRef(null);
4107
+ const containerRef = useRef(null);
4103
4108
  const [layout, setLayout] = useState(null);
4109
+ const { overlayProps, zoomBehavior, zoomIn, zoomOut, resetZoom } = useZoomInteraction({
4110
+ svgRef,
4111
+ rootRef,
4112
+ interactionMode: data.interactionMode ?? "modifier-key",
4113
+ blockId: block.id
4114
+ });
4104
4115
  useEffect(() => {
4105
4116
  let cancelled = false;
4106
4117
  computeArchitectureLayout(data).then((result) => {
@@ -4112,62 +4123,72 @@ function Architecture({
4112
4123
  }, [data]);
4113
4124
  useEffect(() => {
4114
4125
  if (!svgRef.current || !layout) return;
4115
- renderArchitecture(svgRef.current, layout);
4116
- }, [layout]);
4126
+ renderArchitecture(svgRef.current, layout, rootRef, zoomBehavior);
4127
+ }, [layout, zoomBehavior]);
4117
4128
  const nodeCount = countLeafNodes(data.children);
4118
4129
  const edgeCount = data.edges.length;
4119
4130
  const ariaLabel = data.title ? `${data.title}: architecture diagram with ${nodeCount} nodes and ${edgeCount} connections` : `Architecture diagram with ${nodeCount} nodes and ${edgeCount} connections`;
4120
4131
  const flatNodes = flattenNodes(data.children);
4121
- return /* @__PURE__ */ jsxs("div", { className: "glyph-architecture-container", children: [
4122
- !layout && /* @__PURE__ */ jsx(
4123
- "div",
4124
- {
4125
- style: {
4126
- padding: "2rem",
4127
- textAlign: "center",
4128
- color: "var(--glyph-text-muted, #7a8599)",
4129
- fontFamily: "Inter, system-ui, sans-serif",
4130
- fontSize: "13px"
4131
- },
4132
- children: "Computing layout..."
4133
- }
4134
- ),
4135
- /* @__PURE__ */ jsx(
4136
- "svg",
4137
- {
4138
- ref: svgRef,
4139
- role: "img",
4140
- "aria-label": ariaLabel,
4141
- width: "100%",
4142
- height: "100%",
4143
- style: {
4144
- minHeight: container.tier === "compact" ? 200 : 300,
4145
- maxHeight: container.tier === "compact" ? 500 : 700,
4146
- display: layout ? "block" : "none"
4147
- }
4148
- }
4149
- ),
4150
- /* @__PURE__ */ jsxs("table", { className: "sr-only", "aria-label": "Architecture data", style: SR_ONLY_STYLE6, children: [
4151
- /* @__PURE__ */ jsx("caption", { children: "Architecture nodes and connections" }),
4152
- /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
4153
- /* @__PURE__ */ jsx("th", { scope: "col", children: "Node" }),
4154
- /* @__PURE__ */ jsx("th", { scope: "col", children: "Zone" }),
4155
- /* @__PURE__ */ jsx("th", { scope: "col", children: "Connections" })
4156
- ] }) }),
4157
- /* @__PURE__ */ jsx("tbody", { children: flatNodes.map((node) => {
4158
- const connections = data.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => {
4159
- const target = e.from === node.id ? e.to : e.from;
4160
- const dir = e.from === node.id ? "->" : "<-";
4161
- return `${dir} ${target}${e.label ? ` (${e.label})` : ""}`;
4162
- }).join(", ");
4163
- return /* @__PURE__ */ jsxs("tr", { children: [
4164
- /* @__PURE__ */ jsx("td", { children: node.label }),
4165
- /* @__PURE__ */ jsx("td", { children: node.zone ?? "" }),
4166
- /* @__PURE__ */ jsx("td", { children: connections })
4167
- ] }, node.id);
4168
- }) })
4169
- ] })
4170
- ] });
4132
+ return /* @__PURE__ */ jsxs(
4133
+ "div",
4134
+ {
4135
+ ref: containerRef,
4136
+ className: "glyph-architecture-container",
4137
+ style: { position: "relative" },
4138
+ children: [
4139
+ !layout && /* @__PURE__ */ jsx(
4140
+ "div",
4141
+ {
4142
+ style: {
4143
+ padding: "2rem",
4144
+ textAlign: "center",
4145
+ color: "var(--glyph-text-muted, #7a8599)",
4146
+ fontFamily: "Inter, system-ui, sans-serif",
4147
+ fontSize: "13px"
4148
+ },
4149
+ children: "Computing layout..."
4150
+ }
4151
+ ),
4152
+ /* @__PURE__ */ jsx(
4153
+ "svg",
4154
+ {
4155
+ ref: svgRef,
4156
+ role: "img",
4157
+ "aria-label": ariaLabel,
4158
+ width: "100%",
4159
+ height: "100%",
4160
+ style: {
4161
+ minHeight: container.tier === "compact" ? 200 : 300,
4162
+ maxHeight: container.tier === "compact" ? 500 : 700,
4163
+ display: layout ? "block" : "none"
4164
+ }
4165
+ }
4166
+ ),
4167
+ layout && overlayProps && /* @__PURE__ */ jsx(InteractionOverlay, { ...overlayProps }),
4168
+ layout && data.showZoomControls !== false && /* @__PURE__ */ jsx(ZoomControls, { onZoomIn: zoomIn, onZoomOut: zoomOut, onReset: resetZoom }),
4169
+ /* @__PURE__ */ jsxs("table", { className: "sr-only", "aria-label": "Architecture data", style: SR_ONLY_STYLE6, children: [
4170
+ /* @__PURE__ */ jsx("caption", { children: "Architecture nodes and connections" }),
4171
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsxs("tr", { children: [
4172
+ /* @__PURE__ */ jsx("th", { scope: "col", children: "Node" }),
4173
+ /* @__PURE__ */ jsx("th", { scope: "col", children: "Zone" }),
4174
+ /* @__PURE__ */ jsx("th", { scope: "col", children: "Connections" })
4175
+ ] }) }),
4176
+ /* @__PURE__ */ jsx("tbody", { children: flatNodes.map((node) => {
4177
+ const connections = data.edges.filter((e) => e.from === node.id || e.to === node.id).map((e) => {
4178
+ const target = e.from === node.id ? e.to : e.from;
4179
+ const dir = e.from === node.id ? "->" : "<-";
4180
+ return `${dir} ${target}${e.label ? ` (${e.label})` : ""}`;
4181
+ }).join(", ");
4182
+ return /* @__PURE__ */ jsxs("tr", { children: [
4183
+ /* @__PURE__ */ jsx("td", { children: node.label }),
4184
+ /* @__PURE__ */ jsx("td", { children: node.zone ?? "" }),
4185
+ /* @__PURE__ */ jsx("td", { children: connections })
4186
+ ] }, node.id);
4187
+ }) })
4188
+ ] })
4189
+ ]
4190
+ }
4191
+ );
4171
4192
  }
4172
4193
  function flattenNodes(children, zone) {
4173
4194
  const result = [];