@astryxdesign/lab 0.7.8-canary.f10bc91 → 0.7.8-canary.f60d2bb

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.
@@ -1 +1 @@
1
- {"version":3,"file":"SankeyChart.d.ts","sourceRoot":"","sources":["../../src/Sankey/SankeyChart.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,EACL,KAAK,SAAS,EAKf,MAAM,OAAO,CAAC;AAIf,OAAO,KAAK,EAAC,eAAe,EAAE,eAAe,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAE5E,MAAM,WAAW,gBAAgB;IAC/B,uBAAuB;IACvB,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,uBAAuB;IACvB,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAsDD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,OAAO,EACP,MAAY,EACZ,SAAc,EACd,OAAY,EACZ,SAAS,EACT,cAAoB,EACpB,KAAsB,EACtB,QAAQ,GACT,EAAE,gBAAgB,+BAsHlB;yBAjIe,WAAW"}
1
+ {"version":3,"file":"SankeyChart.d.ts","sourceRoot":"","sources":["../../src/Sankey/SankeyChart.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAC,KAAK,SAAS,EAAiC,MAAM,OAAO,CAAC;AAIrE,OAAO,KAAK,EAAC,eAAe,EAAE,eAAe,EAAE,YAAY,EAAC,MAAM,SAAS,CAAC;AAE5E,MAAM,WAAW,gBAAgB;IAC/B,uBAAuB;IACvB,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB,uBAAuB;IACvB,KAAK,EAAE,eAAe,EAAE,CAAC;IACzB;;;;;;;OAOG;IACH,OAAO,CAAC,EAAE,YAAY,EAAE,CAAC;IACzB,wCAAwC;IACxC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,yCAAyC;IACzC,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,uDAAuD;IACvD,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB;;;;OAIG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB;;;OAGG;IACH,cAAc,CAAC,EAAE,MAAM,CAAC;IACxB;;;;;;OAMG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,qBAAqB;IACrB,QAAQ,EAAE,SAAS,CAAC;CACrB;AAsDD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,WAAW,CAAC,EAC1B,KAAK,EACL,KAAK,EACL,OAAO,EACP,MAAY,EACZ,SAAc,EACd,OAAY,EACZ,SAAS,EACT,cAAoB,EACpB,KAAsB,EACtB,QAAQ,GACT,EAAE,gBAAgB,+BAiHlB;yBA5He,WAAW"}
@@ -13,7 +13,7 @@
13
13
  * small graphs are mirrored in a visually hidden From/To/Value table.
14
14
  */
15
15
 
16
- import { useMemo, useRef, useState, useLayoutEffect } from 'react';
16
+ import { useCallback, useMemo, useState } from 'react';
17
17
  import { VisuallyHidden } from '@astryxdesign/core/VisuallyHidden';
18
18
  import { SankeyProvider } from "./SankeyContext.js";
19
19
  import { computeLayout } from "./layout.js";
@@ -100,18 +100,13 @@ export function SankeyChart({
100
100
  label = 'Sankey chart',
101
101
  children
102
102
  }) {
103
- const containerRef = useRef(null);
104
103
  const [containerWidth, setContainerWidth] = useState(0);
105
- useLayoutEffect(() => {
106
- const el = containerRef.current;
107
- if (!el) {
108
- return;
109
- }
104
+ const observeContainerWidth = useCallback(container => {
110
105
  const ro = new ResizeObserver(entries => {
111
106
  const w = entries[0]?.contentRect.width ?? 0;
112
107
  setContainerWidth(w);
113
108
  });
114
- ro.observe(el);
109
+ ro.observe(container);
115
110
  return () => ro.disconnect();
116
111
  }, []);
117
112
  const colCount = useMemo(() => resolveColumnCount(columns, nodes, links), [columns, nodes, links]);
@@ -149,7 +144,7 @@ export function SankeyChart({
149
144
  const nodeLabelById = useMemo(() => new Map(nodes.map(n => [n.id, n.label || n.id])), [nodes]);
150
145
  const showDataTable = links.length > 0 && links.length <= MAX_TABLE_LINKS;
151
146
  return /*#__PURE__*/_jsxs("div", {
152
- ref: containerRef,
147
+ ref: observeContainerWidth,
153
148
  style: {
154
149
  width: '100%'
155
150
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@astryxdesign/lab",
3
- "version": "0.7.8-canary.f10bc91",
3
+ "version": "0.7.8-canary.f60d2bb",
4
4
  "description": "Experimental Astryx components — published to npm only under the @canary dist-tag for early testing; never released as a stable (latest) version.",
5
5
  "author": "Meta Open Source",
6
6
  "license": "MIT",
@@ -49,7 +49,7 @@
49
49
  },
50
50
  "peerDependencies": {
51
51
  "@stylexjs/stylex": ">=0.10.0",
52
- "@astryxdesign/core": "0.7.8-canary.f10bc91",
52
+ "@astryxdesign/core": "0.7.8-canary.f60d2bb",
53
53
  "react": ">=19.0.0",
54
54
  "react-dom": ">=19.0.0"
55
55
  },
@@ -59,9 +59,9 @@
59
59
  "d3-shape": "^3.2.0"
60
60
  },
61
61
  "devDependencies": {
62
- "@astryxdesign/a11y-spec": "0.7.8-canary.f10bc91",
63
- "@astryxdesign/cli": "0.7.8-canary.f10bc91",
64
- "@astryxdesign/interaction-harness": "0.7.8-canary.f10bc91",
62
+ "@astryxdesign/a11y-spec": "0.7.8-canary.f60d2bb",
63
+ "@astryxdesign/cli": "0.7.8-canary.f60d2bb",
64
+ "@astryxdesign/interaction-harness": "0.7.8-canary.f60d2bb",
65
65
  "@babel/cli": "^7.29.7",
66
66
  "@babel/core": "^7.29.7",
67
67
  "@babel/preset-react": "^7.29.7",
@@ -76,6 +76,37 @@ describe('SankeyChart scroll container', () => {
76
76
  });
77
77
  });
78
78
 
79
+ describe('SankeyChart container observation', () => {
80
+ it('observes its container while mounted and stops on unmount', () => {
81
+ const observed = new Set<Element>();
82
+ vi.stubGlobal(
83
+ 'ResizeObserver',
84
+ class {
85
+ observe(element: Element) {
86
+ observed.add(element);
87
+ }
88
+ unobserve(element: Element) {
89
+ observed.delete(element);
90
+ }
91
+ disconnect() {
92
+ observed.clear();
93
+ }
94
+ },
95
+ );
96
+ const {container, unmount} = render(
97
+ <SankeyChart nodes={nodes} links={links}>
98
+ <SankeyNode />
99
+ </SankeyChart>,
100
+ );
101
+ const chartContainer = container.firstElementChild;
102
+ expect(chartContainer).not.toBeNull();
103
+ expect(observed.has(chartContainer!)).toBe(true);
104
+
105
+ unmount();
106
+ expect(observed.size).toBe(0);
107
+ });
108
+ });
109
+
79
110
  describe('SankeyChart accessible name', () => {
80
111
  it('names the svg when the chart does not scroll', () => {
81
112
  render(
@@ -13,13 +13,7 @@
13
13
  * small graphs are mirrored in a visually hidden From/To/Value table.
14
14
  */
15
15
 
16
- import {
17
- type ReactNode,
18
- useMemo,
19
- useRef,
20
- useState,
21
- useLayoutEffect,
22
- } from 'react';
16
+ import {type ReactNode, useCallback, useMemo, useState} from 'react';
23
17
  import {VisuallyHidden} from '@astryxdesign/core/VisuallyHidden';
24
18
  import {SankeyProvider} from './SankeyContext';
25
19
  import {computeLayout} from './layout';
@@ -154,19 +148,14 @@ export function SankeyChart({
154
148
  label = 'Sankey chart',
155
149
  children,
156
150
  }: SankeyChartProps) {
157
- const containerRef = useRef<HTMLDivElement>(null);
158
151
  const [containerWidth, setContainerWidth] = useState(0);
159
152
 
160
- useLayoutEffect(() => {
161
- const el = containerRef.current;
162
- if (!el) {
163
- return;
164
- }
153
+ const observeContainerWidth = useCallback((container: HTMLDivElement) => {
165
154
  const ro = new ResizeObserver(entries => {
166
155
  const w = entries[0]?.contentRect.width ?? 0;
167
156
  setContainerWidth(w);
168
157
  });
169
- ro.observe(el);
158
+ ro.observe(container);
170
159
  return () => ro.disconnect();
171
160
  }, []);
172
161
 
@@ -225,7 +214,7 @@ export function SankeyChart({
225
214
  const showDataTable = links.length > 0 && links.length <= MAX_TABLE_LINKS;
226
215
 
227
216
  return (
228
- <div ref={containerRef} style={{width: '100%'}}>
217
+ <div ref={observeContainerWidth} style={{width: '100%'}}>
229
218
  {ctx && (
230
219
  <div
231
220
  role={needsScroll ? 'group' : undefined}