@efolusi/meridian 1.21.10 → 1.22.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.
Files changed (60) hide show
  1. package/THIRD_PARTY_NOTICES.md +1 -1
  2. package/ai/Citation.js +44 -22
  3. package/ai/Confirmation.js +2 -2
  4. package/ai/PromptComposer.d.ts +4 -0
  5. package/ai/PromptComposer.js +7 -1
  6. package/ai/RichComposer.js +3 -0
  7. package/ai/SourceCard.js +12 -4
  8. package/ai/UsageMeter.d.ts +3 -1
  9. package/ai/UsageMeter.js +8 -2
  10. package/ai/WebPreview.js +12 -4
  11. package/code/CodeBlock.js +26 -7
  12. package/code/CopyField.js +24 -9
  13. package/components.css +137 -56
  14. package/data/BarChart.d.ts +4 -0
  15. package/data/BarChart.js +28 -4
  16. package/data/Chart.d.ts +1 -1
  17. package/data/Chart.js +5 -2
  18. package/data/DonutChart.d.ts +4 -0
  19. package/data/DonutChart.js +38 -8
  20. package/data/LineChart.d.ts +4 -0
  21. package/data/LineChart.js +29 -7
  22. package/data/Table.d.ts +1 -0
  23. package/data/Table.js +35 -19
  24. package/dates/Calendar.js +43 -15
  25. package/dates/TimePicker.js +18 -3
  26. package/display/Toolbar.js +1 -0
  27. package/display/TreeList.js +20 -13
  28. package/feedback/AlertDialog.js +12 -12
  29. package/feedback/Dialog.js +17 -12
  30. package/feedback/Toast.js +5 -2
  31. package/feedback/Tooltip.js +5 -1
  32. package/files/FileDrop.d.ts +5 -1
  33. package/files/FileDrop.js +28 -1
  34. package/forms/ButtonTile.js +2 -0
  35. package/forms/Combobox.js +21 -5
  36. package/forms/NumberInput.js +21 -4
  37. package/forms/Questionnaire.js +1 -1
  38. package/forms/Slider.js +2 -1
  39. package/forms/Switch.js +14 -3
  40. package/index.js +3 -3
  41. package/navigation/NavigationMenu.js +17 -5
  42. package/navigation/PageControl.js +1 -0
  43. package/navigation/SegmentedControl.js +1 -0
  44. package/navigation/SideNav.js +2 -0
  45. package/navigation/Sidebar.js +74 -11
  46. package/navigation/SkipLink.d.ts +2 -1
  47. package/navigation/SkipLink.js +16 -4
  48. package/overlay/Command.js +1 -0
  49. package/overlay/ContextMenu.js +32 -10
  50. package/overlay/Drawer.d.ts +1 -0
  51. package/overlay/Drawer.js +19 -2
  52. package/overlay/DropdownMenu.js +32 -10
  53. package/overlay/HoverCard.js +8 -13
  54. package/overlay/Popover.js +46 -10
  55. package/overlay/Portal.js +67 -2
  56. package/package.json +1 -1
  57. package/tailwind.preset.cjs +34 -13
  58. package/tokens/base.css +5 -0
  59. package/tokens/colors.css +7 -3
  60. package/tokens.json +427 -95
@@ -9,6 +9,10 @@ export interface BarChartProps {
9
9
  labels?: string[];
10
10
  /** Hover value formatter */
11
11
  format?: (v: number) => string;
12
+ /** BCP 47 locale for number formatting (fixed default keeps server and browser output identical) @default 'en-US' */
13
+ locale?: string;
14
+ /** Accessible name for the chart (role=img); defaults to a summary of the series. A visually hidden table carries every value. */
15
+ 'aria-label'?: string;
12
16
  style?: React.CSSProperties;
13
17
  className?: string;
14
18
  }
package/data/BarChart.js CHANGED
@@ -2,23 +2,36 @@
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  import React from 'react';
4
4
  import { cssPct } from "../forms/Button.js";
5
+ // Fixed default locale: the runtime default would differ between server and browser.
5
6
  export function BarChart({
6
7
  data = [],
7
8
  height = 140,
8
9
  highlightLast = 0,
9
10
  labels,
10
11
  format,
12
+ locale = 'en-US',
13
+ 'aria-label': ariaLabel,
11
14
  style,
12
15
  className,
13
16
  ...rest
14
17
  }) {
15
18
  const vals = data.map(d => typeof d === 'number' ? d : d.value);
16
19
  const max = Math.max(...vals, 1);
20
+ const nf = new Intl.NumberFormat(locale);
21
+ const fmt = v => format ? format(v) : nf.format(v);
22
+ const name = i => data[i] && data[i].label || labels && labels[i] || String(i + 1);
23
+ const top = vals.reduce((best, v, i) => v > vals[best] ? i : best, 0);
24
+ const summary = ariaLabel || (vals.length ? `Bar chart, ${vals.length} bar${vals.length === 1 ? '' : 's'}, highest ${name(top)} ${fmt(vals[top])}` : 'Bar chart, no data');
17
25
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
18
26
  className: className,
19
- style: style
27
+ style: {
28
+ position: 'relative',
29
+ ...style
30
+ }
20
31
  }), /*#__PURE__*/React.createElement("div", {
21
32
  className: "ef-bars",
33
+ role: "img",
34
+ "aria-label": summary,
22
35
  style: {
23
36
  height
24
37
  }
@@ -28,9 +41,20 @@ export function BarChart({
28
41
  style: {
29
42
  height: cssPct(Math.max(2, v / max * 100))
30
43
  },
31
- title: (data[i] && data[i].label ? data[i].label + ' · ' : '') + (format ? format(v) : v.toLocaleString())
32
- }))), labels && labels.length ? /*#__PURE__*/React.createElement("div", {
33
- className: "ef-bars__labels"
44
+ title: (data[i] && data[i].label ? data[i].label + ' · ' : '') + fmt(v)
45
+ }))), vals.length ? /*#__PURE__*/React.createElement("table", {
46
+ className: "ef-bars__sr"
47
+ }, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", {
48
+ scope: "col"
49
+ }, "Label"), /*#__PURE__*/React.createElement("th", {
50
+ scope: "col"
51
+ }, "Value"))), /*#__PURE__*/React.createElement("tbody", null, vals.map((v, i) => /*#__PURE__*/React.createElement("tr", {
52
+ key: i
53
+ }, /*#__PURE__*/React.createElement("th", {
54
+ scope: "row"
55
+ }, name(i)), /*#__PURE__*/React.createElement("td", null, fmt(v)))))) : null, labels && labels.length ? /*#__PURE__*/React.createElement("div", {
56
+ className: "ef-bars__labels",
57
+ "aria-hidden": "true"
34
58
  }, labels.map((l, i) => /*#__PURE__*/React.createElement("span", {
35
59
  key: i
36
60
  }, l))) : null);
package/data/Chart.d.ts CHANGED
@@ -7,7 +7,7 @@ export interface ChartContainerProps extends React.HTMLAttributes<HTMLDivElement
7
7
  export declare const ChartContainer: React.ForwardRefExoticComponent<ChartContainerProps & React.RefAttributes<HTMLDivElement>>;
8
8
  export declare function ChartStyle(props: { id: string; config: ChartConfig }): React.JSX.Element | null;
9
9
  export declare function ChartTooltip(props: TooltipProps<any, any>): React.JSX.Element | null;
10
- export interface ChartTooltipContentProps extends Omit<DefaultTooltipContentProps<TooltipValueType, string | number>, 'accessibilityLayer'> { active?: boolean; className?: string; hideLabel?: boolean; hideIndicator?: boolean; indicator?: 'line' | 'dot' | 'dashed'; nameKey?: string; labelKey?: string; color?: string }
10
+ export interface ChartTooltipContentProps extends Omit<DefaultTooltipContentProps<TooltipValueType, string | number>, 'accessibilityLayer'> { active?: boolean; className?: string; hideLabel?: boolean; hideIndicator?: boolean; indicator?: 'line' | 'dot' | 'dashed'; nameKey?: string; labelKey?: string; color?: string; /** Number formatting locale @default 'en-US' */ locale?: string }
11
11
  export declare function ChartTooltipContent(props: ChartTooltipContentProps): React.JSX.Element | null;
12
12
  export declare function ChartLegend(props: LegendProps): React.JSX.Element | null;
13
13
  export interface ChartLegendContentProps extends DefaultLegendContentProps { className?: string; hideIcon?: boolean; nameKey?: string }
package/data/Chart.js CHANGED
@@ -26,9 +26,11 @@ export function ChartStyle({
26
26
  const value = item.theme ? item.theme[theme] : item.color;
27
27
  return value ? `--color-${key}:${value};` : '';
28
28
  }).join('\n')}\n}`).join('\n');
29
+ // Raw text inside <style>: server-rendered, a `<` in a config value could
30
+ // close the element and open a script. CSS never needs a literal `<` here.
29
31
  return /*#__PURE__*/React.createElement("style", {
30
32
  dangerouslySetInnerHTML: {
31
- __html: css
33
+ __html: css.replace(/</g, '\\3c ')
32
34
  }
33
35
  });
34
36
  }
@@ -72,6 +74,7 @@ function payloadConfig(config, payload, key) {
72
74
  export function ChartTooltipContent({
73
75
  active,
74
76
  payload,
77
+ locale = 'en-US',
75
78
  className,
76
79
  indicator = 'dot',
77
80
  hideLabel = false,
@@ -114,7 +117,7 @@ export function ChartTooltipContent({
114
117
  className: "ef-chart-tooltip__name"
115
118
  }, nestLabel ? labelNode : null, configItem?.label || item.name), item.value != null ? /*#__PURE__*/React.createElement("span", {
116
119
  className: "ef-chart-tooltip__value"
117
- }, typeof item.value === 'number' ? item.value.toLocaleString() : String(item.value)) : null));
120
+ }, typeof item.value === 'number' ? new Intl.NumberFormat(locale).format(item.value) : String(item.value)) : null));
118
121
  })));
119
122
  }
120
123
  export function ChartLegend(props) {
@@ -11,6 +11,10 @@ export interface DonutChartProps {
11
11
  centerValue?: React.ReactNode;
12
12
  /** Hover value formatter */
13
13
  format?: (value: number) => string;
14
+ /** BCP 47 locale for number formatting (fixed default keeps server and browser output identical) @default 'en-US' */
15
+ locale?: string;
16
+ /** Accessible name for the chart (role=img); defaults to a summary of the series. A visually hidden table carries every value. */
17
+ 'aria-label'?: string;
14
18
  style?: React.CSSProperties;
15
19
  className?: string;
16
20
  }
@@ -1,29 +1,41 @@
1
1
  'use client';
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  import React from 'react';
4
- const PALETTE = ['var(--brand-950)', 'var(--brand-500)', 'var(--brand-200)', 'var(--sand-400)', 'var(--sand-200)'];
4
+ // Categorical slots come from --chart-1..5 (tokens area). The fallbacks are the
5
+ // old brand/sand steps, which fail the dataviz validator; they only apply until
6
+ // the chart tokens are defined.
7
+ const PALETTE = ['var(--chart-1, var(--brand-950))', 'var(--chart-2, var(--brand-500))', 'var(--chart-3, var(--brand-200))', 'var(--chart-4, var(--sand-400))', 'var(--chart-5, var(--sand-200))'];
8
+ // Fixed default locale: the runtime default would differ between server and browser.
5
9
  export function DonutChart({
6
- data,
10
+ data = [],
7
11
  size = 140,
8
12
  thickness = 16,
9
13
  centerLabel,
10
14
  centerValue,
11
15
  format,
16
+ locale = 'en-US',
17
+ 'aria-label': ariaLabel,
12
18
  style,
13
19
  className,
14
20
  ...rest
15
21
  }) {
16
22
  const [hov, setHov] = React.useState(null);
17
23
  const total = data.reduce((s, d) => s + d.value, 0) || 1;
24
+ const nf = new Intl.NumberFormat(locale);
25
+ const fmt = v => format ? format(v) : nf.format(v);
26
+ const pct = v => Math.round(v / total * 100) + '%';
27
+ const summary = ariaLabel || (data.length ? 'Donut chart' + (centerLabel ? ', ' + centerLabel : '') + ': ' + data.map(d => `${d.label} ${pct(d.value)}`).join(', ') : 'Donut chart, no data');
18
28
  const R = 50 - thickness / 100 * 50;
19
29
  const C = 2 * Math.PI * R;
30
+ // A 2px surface gap between segments at any size (viewBox is 100 units wide).
31
+ const gap = 2 * 100 / size;
20
32
  let acc = 0;
21
33
  const segs = data.map((d, i) => {
22
34
  const frac = d.value / total;
23
35
  const seg = {
24
36
  ...d,
25
37
  i,
26
- dash: `${Math.max(frac * C - 1.5, 0.5)} ${C}`,
38
+ dash: `${Math.max(frac * C - gap, 0.5)} ${C}`,
27
39
  offset: -acc * C,
28
40
  color: d.color || PALETTE[i % PALETTE.length]
29
41
  };
@@ -32,8 +44,13 @@ export function DonutChart({
32
44
  });
33
45
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
34
46
  className: `ef-donut${className ? ' ' + className : ''}`,
35
- style: style
47
+ style: {
48
+ position: 'relative',
49
+ ...style
50
+ }
36
51
  }), /*#__PURE__*/React.createElement("div", {
52
+ role: "img",
53
+ "aria-label": summary,
37
54
  style: {
38
55
  position: 'relative',
39
56
  width: size,
@@ -80,13 +97,26 @@ export function DonutChart({
80
97
  fontWeight: 600,
81
98
  color: 'var(--text-primary)'
82
99
  }
83
- }, hov != null ? format ? format(segs[hov].value) : segs[hov].value.toLocaleString() : centerValue), /*#__PURE__*/React.createElement("span", {
100
+ }, hov != null ? fmt(segs[hov].value) : centerValue), /*#__PURE__*/React.createElement("span", {
84
101
  style: {
85
102
  fontSize: 11,
86
103
  color: 'var(--text-muted)'
87
104
  }
88
- }, hov != null ? segs[hov].label : centerLabel))), /*#__PURE__*/React.createElement("div", {
89
- className: "ef-donut__legend"
105
+ }, hov != null ? segs[hov].label : centerLabel))), data.length ? /*#__PURE__*/React.createElement("table", {
106
+ className: "ef-donut__sr"
107
+ }, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", {
108
+ scope: "col"
109
+ }, "Label"), /*#__PURE__*/React.createElement("th", {
110
+ scope: "col"
111
+ }, "Value"), /*#__PURE__*/React.createElement("th", {
112
+ scope: "col"
113
+ }, "Share"))), /*#__PURE__*/React.createElement("tbody", null, segs.map(sg => /*#__PURE__*/React.createElement("tr", {
114
+ key: sg.i
115
+ }, /*#__PURE__*/React.createElement("th", {
116
+ scope: "row"
117
+ }, sg.label), /*#__PURE__*/React.createElement("td", null, fmt(sg.value)), /*#__PURE__*/React.createElement("td", null, pct(sg.value)))))) : null, /*#__PURE__*/React.createElement("div", {
118
+ className: "ef-donut__legend",
119
+ "aria-hidden": "true"
90
120
  }, segs.map(s => /*#__PURE__*/React.createElement("span", {
91
121
  key: s.i,
92
122
  className: "ef-donut__item",
@@ -103,5 +133,5 @@ export function DonutChart({
103
133
  }
104
134
  }), s.label, /*#__PURE__*/React.createElement("span", {
105
135
  className: "ef-donut__val"
106
- }, Math.round(s.value / total * 100), "%")))));
136
+ }, pct(s.value))))));
107
137
  }
@@ -9,6 +9,10 @@ export interface LineChartProps {
9
9
  showDots?: boolean;
10
10
  /** Tooltip value formatter */
11
11
  format?: (value: number) => string;
12
+ /** BCP 47 locale for number formatting (fixed default keeps server and browser output identical) @default 'en-US' */
13
+ locale?: string;
14
+ /** Accessible name for the chart (role=img); defaults to a summary of the series. A visually hidden table carries every value. */
15
+ 'aria-label'?: string;
12
16
  style?: React.CSSProperties;
13
17
  className?: string;
14
18
  }
package/data/LineChart.js CHANGED
@@ -2,12 +2,16 @@
2
2
  function _extends() { return _extends = Object.assign ? Object.assign.bind() : function (n) { for (var e = 1; e < arguments.length; e++) { var t = arguments[e]; for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]); } return n; }, _extends.apply(null, arguments); }
3
3
  import React from 'react';
4
4
  import { cssPct } from "../forms/Button.js";
5
+ // A fixed default locale: the runtime default differs between server and
6
+ // browser and would make the first render mismatch on hydration.
5
7
  export function LineChart({
6
- data,
8
+ data = [],
7
9
  height = 150,
8
10
  showArea = true,
9
11
  showDots = false,
10
12
  format,
13
+ locale = 'en-US',
14
+ 'aria-label': ariaLabel,
11
15
  style,
12
16
  className,
13
17
  ...rest
@@ -22,13 +26,18 @@ export function LineChart({
22
26
  min = Math.min(...vals);
23
27
  const span = max - min || 1;
24
28
  const n = data.length;
29
+ const nf = new Intl.NumberFormat(locale);
30
+ const fmt = v => format ? format(v) : nf.format(v);
31
+ const name = (d, i) => d.label != null && d.label !== '' ? d.label : String(i + 1);
32
+ const summary = ariaLabel || (n ? `Line chart, ${n} point${n === 1 ? '' : 's'}: ${name(data[0], 0)} ${fmt(data[0].value)} to ${name(data[n - 1], n - 1)} ${fmt(data[n - 1].value)}, low ${fmt(min)}, high ${fmt(max)}` : 'Line chart, no data');
25
33
  const x = i => PAD + (n === 1 ? 0.5 : i / (n - 1)) * (W - PAD * 2);
26
34
  const y = v => n === 1 ? H / 2 : H - PAD - (v - min) / span * (H - PAD * 2);
27
35
  // One reading has no left-to-right span; draw it as a flat line across the
28
36
  // middle instead of dividing by zero, which put NaN in the path.
29
- const path = n === 1 ? `M${PAD.toFixed(1)},${y(data[0].value).toFixed(1)} L${(W - PAD).toFixed(1)},${y(data[0].value).toFixed(1)}` : data.map((d, i) => (i ? 'L' : 'M') + x(i).toFixed(1) + ',' + y(d.value).toFixed(1)).join(' ');
30
- const area = n === 1 ? `${path} L${(W - PAD).toFixed(1)},${(H - PAD).toFixed(1)} L${PAD.toFixed(1)},${(H - PAD).toFixed(1)} Z` : path + ` L${x(data.length - 1).toFixed(1)},${H - PAD} L${x(0).toFixed(1)},${H - PAD} Z`;
37
+ const path = n === 0 ? '' : n === 1 ? `M${PAD.toFixed(1)},${y(data[0].value).toFixed(1)} L${(W - PAD).toFixed(1)},${y(data[0].value).toFixed(1)}` : data.map((d, i) => (i ? 'L' : 'M') + x(i).toFixed(1) + ',' + y(d.value).toFixed(1)).join(' ');
38
+ const area = n === 0 ? '' : n === 1 ? `${path} L${(W - PAD).toFixed(1)},${(H - PAD).toFixed(1)} L${PAD.toFixed(1)},${(H - PAD).toFixed(1)} Z` : path + ` L${x(data.length - 1).toFixed(1)},${H - PAD} L${x(0).toFixed(1)},${H - PAD} Z`;
31
39
  const move = e => {
40
+ if (!n) return;
32
41
  const r = ref.current.getBoundingClientRect();
33
42
  const i = Math.round((e.clientX - r.left) / r.width * (data.length - 1));
34
43
  setHov(Math.max(0, Math.min(data.length - 1, i)));
@@ -40,6 +49,8 @@ export function LineChart({
40
49
  onMouseMove: move,
41
50
  onMouseLeave: () => setHov(null)
42
51
  }), /*#__PURE__*/React.createElement("svg", {
52
+ role: "img",
53
+ "aria-label": summary,
43
54
  viewBox: `0 0 ${W} ${H}`,
44
55
  width: "100%",
45
56
  height: H,
@@ -47,11 +58,11 @@ export function LineChart({
47
58
  style: {
48
59
  display: 'block'
49
60
  }
50
- }, showArea && /*#__PURE__*/React.createElement("path", {
61
+ }, showArea && area && /*#__PURE__*/React.createElement("path", {
51
62
  d: area,
52
63
  fill: "var(--accent)",
53
64
  opacity: ".07"
54
- }), /*#__PURE__*/React.createElement("path", {
65
+ }), path && /*#__PURE__*/React.createElement("path", {
55
66
  d: path,
56
67
  fill: "none",
57
68
  stroke: "var(--accent)",
@@ -74,11 +85,22 @@ export function LineChart({
74
85
  stroke: "var(--border-strong)",
75
86
  strokeDasharray: "3 3",
76
87
  vectorEffect: "non-scaling-stroke"
77
- })), hov != null && /*#__PURE__*/React.createElement("div", {
88
+ })), n ? /*#__PURE__*/React.createElement("table", {
89
+ className: "ef-linechart__sr"
90
+ }, /*#__PURE__*/React.createElement("thead", null, /*#__PURE__*/React.createElement("tr", null, /*#__PURE__*/React.createElement("th", {
91
+ scope: "col"
92
+ }, "Label"), /*#__PURE__*/React.createElement("th", {
93
+ scope: "col"
94
+ }, "Value"))), /*#__PURE__*/React.createElement("tbody", null, data.map((d, i) => /*#__PURE__*/React.createElement("tr", {
95
+ key: i
96
+ }, /*#__PURE__*/React.createElement("th", {
97
+ scope: "row"
98
+ }, name(d, i)), /*#__PURE__*/React.createElement("td", null, fmt(d.value)))))) : null, hov != null && /*#__PURE__*/React.createElement("div", {
99
+ "aria-hidden": "true",
78
100
  className: "ef-linechart__tip",
79
101
  style: {
80
102
  left: cssPct(x(hov) / W * 100),
81
103
  top: cssPct(y(data[hov].value) / H * 100)
82
104
  }
83
- }, data[hov].label, data[hov].label ? ' · ' : '', format ? format(data[hov].value) : data[hov].value.toLocaleString()));
105
+ }, data[hov].label, data[hov].label ? ' · ' : '', fmt(data[hov].value)));
84
106
  }
package/data/Table.d.ts CHANGED
@@ -22,6 +22,7 @@ export interface TableProps extends React.TableHTMLAttributes<HTMLTableElement>
22
22
  rows?: any[];
23
23
  /** Field name or fn for React keys @default index */
24
24
  rowKey?: string | ((row: any) => string);
25
+ /** Makes rows clickable and focusable (tabIndex 0); Enter or Space on a focused row also calls it. */
25
26
  onRowClick?: (row: any) => void;
26
27
  dense?: boolean;
27
28
  /** Controlled sort. Omit and the table sorts itself. */
package/data/Table.js CHANGED
@@ -36,19 +36,9 @@ export const Table = /*#__PURE__*/React.forwardRef(function Table({
36
36
  className,
37
37
  ...rest
38
38
  }, ref) {
39
- if (!columns || !rows) {
40
- return /*#__PURE__*/React.createElement("div", {
41
- "data-slot": "table-container",
42
- className: "ef-table-wrap"
43
- }, /*#__PURE__*/React.createElement("table", _extends({
44
- ref: ref
45
- }, rest, {
46
- "data-slot": "table",
47
- className: `ef-table${dense ? ' ef-table--dense' : ''}${className ? ' ' + className : ''}`,
48
- style: style
49
- }), children));
50
- }
51
- const key = (row, i) => rowKey ? typeof rowKey === 'function' ? rowKey(row) : row[rowKey] : i;
39
+ // Hooks first: the composition branch below returns early, and hooks after
40
+ // it would drop sort and selection state whenever a table passes through it.
41
+
52
42
  const [innerSort, setInnerSort] = React.useState(defaultSort || null);
53
43
  const sort = sortProp !== undefined ? sortProp : innerSort;
54
44
  const applySort = next => {
@@ -71,14 +61,33 @@ export const Table = /*#__PURE__*/React.forwardRef(function Table({
71
61
 
72
62
  // Sorting is applied here, not expected of the caller: a table that renders
73
63
  // a sort affordance it does not honour is worse than one with no affordance.
74
- const sorted = React.useMemo(() => {
75
- if (!sort || !sort.key) return rows;
64
+ // Sort positions, not row objects: without rowKey a row's key is its index in
65
+ // `rows`, so a selection stays on the same row when the sort changes, and a
66
+ // row object listed twice still gets two keys.
67
+ const order = React.useMemo(() => {
68
+ const idx = (rows || []).map((_, i) => i);
69
+ if (!rows || !columns || !sort || !sort.key) return idx;
76
70
  const col = columns.find(c => c.key === sort.key);
77
- if (!col) return rows;
71
+ if (!col) return idx;
78
72
  const get = col.sortAccessor || (row => row[col.key]);
79
- const out = rows.slice().sort((x, y) => compare(get(x), get(y)));
80
- return sort.direction === 'desc' ? out.reverse() : out;
73
+ // Negate rather than reverse, so rows with equal keys keep their order.
74
+ const sign = sort.direction === 'desc' ? -1 : 1;
75
+ return idx.sort((x, y) => sign * compare(get(rows[x]), get(rows[y])));
81
76
  }, [rows, columns, sort]);
77
+ const sorted = rows ? order.map(i => rows[i]) : rows;
78
+ const key = (row, pos) => rowKey ? typeof rowKey === 'function' ? rowKey(row) : row[rowKey] : order[pos];
79
+ if (!columns || !rows) {
80
+ return /*#__PURE__*/React.createElement("div", {
81
+ "data-slot": "table-container",
82
+ className: "ef-table-wrap"
83
+ }, /*#__PURE__*/React.createElement("table", _extends({
84
+ ref: ref
85
+ }, rest, {
86
+ "data-slot": "table",
87
+ className: `ef-table${dense ? ' ef-table--dense' : ''}${className ? ' ' + className : ''}`,
88
+ style: style
89
+ }), children));
90
+ }
82
91
  const allKeys = sorted.map((r, i) => key(r, i));
83
92
  const allOn = allKeys.length > 0 && allKeys.every(k => selected.includes(k));
84
93
  const someOn = !allOn && allKeys.some(k => selected.includes(k));
@@ -141,7 +150,14 @@ export const Table = /*#__PURE__*/React.forwardRef(function Table({
141
150
  return /*#__PURE__*/React.createElement("tr", {
142
151
  key: k,
143
152
  className: `${onRowClick ? 'ef-table__row--click' : ''}${isSel ? ' ef-table__row--sel' : ''}`.trim() || undefined,
144
- onClick: onRowClick ? () => onRowClick(row) : undefined
153
+ onClick: onRowClick ? () => onRowClick(row) : undefined,
154
+ tabIndex: onRowClick ? 0 : undefined,
155
+ onKeyDown: onRowClick ? e => {
156
+ // Only the row itself: Enter on a button or link inside it is that control's.
157
+ if (e.target !== e.currentTarget || e.key !== 'Enter' && e.key !== ' ') return;
158
+ e.preventDefault();
159
+ onRowClick(row);
160
+ } : undefined
145
161
  }, selectable ? /*#__PURE__*/React.createElement("td", {
146
162
  className: "ef-table__sel",
147
163
  onClick: e => e.stopPropagation()
package/dates/Calendar.js CHANGED
@@ -76,7 +76,10 @@ export function Calendar({
76
76
  const [innerMonth, setInnerMonth] = React.useState(() => new Date(initial.getFullYear(), initial.getMonth(), 1));
77
77
  const visibleMonth = controlledMonth || innerMonth;
78
78
  const DayButton = components.DayButton || CalendarDayButton;
79
- const gridRef = React.useRef(null);
79
+ const monthsRef = React.useRef(null);
80
+ // Set by keyboard navigation only, so the calendar never pulls focus to
81
+ // itself on mount or when a month button changes the view.
82
+ const keyboardMove = React.useRef(false);
80
83
  const selectedStart = mode === 'range' ? selected?.from : mode === 'multiple' ? selected?.[0] : selected;
81
84
  const [focusDate, setFocusDate] = React.useState(() => startDay(selectedStart || new Date()));
82
85
  const setMonth = next => {
@@ -110,16 +113,41 @@ export function Calendar({
110
113
  const monthViews = Array.from({
111
114
  length: numberOfMonths
112
115
  }, (_, index) => addMonths(visibleMonth, index));
113
- const moveFocus = amount => {
114
- const next = addDays(focusDate, amount);
116
+ const monthIndex = date => date.getFullYear() * 12 + date.getMonth();
117
+ const firstShown = monthIndex(visibleMonth);
118
+ const lastShown = firstShown + numberOfMonths - 1;
119
+ const isShown = date => monthIndex(date) >= firstShown && monthIndex(date) <= lastShown;
120
+ const usable = date => isShown(date) && !matcherHit(disabled, date);
121
+ // The one day that carries tabIndex=0. It has to be a real, enabled day in
122
+ // a shown month, or the grid drops out of the tab order altogether.
123
+ const tabDate = (() => {
124
+ if (usable(focusDate)) return focusDate;
125
+ const picked = mode === 'range' ? [selected?.from, selected?.to] : mode === 'multiple' ? selected || [] : [selected];
126
+ const candidate = picked.filter(Boolean).map(startDay).find(usable) || [startDay(new Date())].find(usable);
127
+ if (candidate) return candidate;
128
+ for (let day = new Date(visibleMonth.getFullYear(), visibleMonth.getMonth(), 1); isShown(day); day = addDays(day, 1)) if (!matcherHit(disabled, day)) return day;
129
+ return focusDate;
130
+ })();
131
+ const inBounds = date => (!startMonth || monthIndex(date) >= monthIndex(startMonth)) && (!endMonth || monthIndex(date) <= monthIndex(endMonth));
132
+ // Move to `target`, stepping on by `skip` days past disabled ones, and page
133
+ // the view only when the day falls outside every shown month.
134
+ const focusOn = (target, skip) => {
135
+ let next = target;
136
+ for (let tries = 0; matcherHit(disabled, next) && tries < 62; tries += 1) next = addDays(next, skip);
137
+ if (matcherHit(disabled, next) || !inBounds(next)) return;
138
+ keyboardMove.current = true;
115
139
  setFocusDate(next);
116
- if (next.getMonth() !== visibleMonth.getMonth() || next.getFullYear() !== visibleMonth.getFullYear()) setMonth(new Date(next.getFullYear(), next.getMonth(), 1));
140
+ if (monthIndex(next) < firstShown) setMonth(new Date(next.getFullYear(), next.getMonth(), 1));else if (monthIndex(next) > lastShown) setMonth(new Date(next.getFullYear(), next.getMonth() - numberOfMonths + 1, 1));
117
141
  };
118
142
  React.useEffect(() => {
119
- const target = gridRef.current?.querySelector(`[data-key="${dayKey(focusDate)}"]`);
120
- if (target && (gridRef.current.contains(document.activeElement) || document.activeElement === document.body)) target.focus();
143
+ if (!keyboardMove.current) return;
144
+ keyboardMove.current = false;
145
+ const key = dayKey(focusDate);
146
+ const target = monthsRef.current?.querySelector(`[data-key="${key}"]:not([data-outside="true"])`) || monthsRef.current?.querySelector(`[data-key="${key}"]`);
147
+ target?.focus();
121
148
  }, [focusDate, visibleMonth]);
122
149
  const keydown = event => {
150
+ const from = tabDate;
123
151
  const horizontal = direction === 'rtl' ? {
124
152
  ArrowLeft: 1,
125
153
  ArrowRight: -1
@@ -129,18 +157,18 @@ export function Calendar({
129
157
  };
130
158
  if (horizontal[event.key]) {
131
159
  event.preventDefault();
132
- moveFocus(horizontal[event.key]);
160
+ focusOn(addDays(from, horizontal[event.key]), horizontal[event.key]);
133
161
  } else if (event.key === 'ArrowUp' || event.key === 'ArrowDown') {
162
+ const amount = event.key === 'ArrowUp' ? -7 : 7;
134
163
  event.preventDefault();
135
- moveFocus(event.key === 'ArrowUp' ? -7 : 7);
164
+ focusOn(addDays(from, amount), amount);
136
165
  } else if (event.key === 'Home' || event.key === 'End') {
137
166
  event.preventDefault();
138
- moveFocus((event.key === 'Home' ? 0 : 6) - focusDate.getDay());
167
+ focusOn(addDays(from, (event.key === 'Home' ? 0 : 6) - from.getDay()), event.key === 'Home' ? 1 : -1);
139
168
  } else if (event.key === 'PageUp' || event.key === 'PageDown') {
140
169
  event.preventDefault();
141
- const next = addMonths(focusDate, event.key === 'PageUp' ? -1 : 1);
142
- setFocusDate(new Date(next.getFullYear(), next.getMonth(), Math.min(focusDate.getDate(), new Date(next.getFullYear(), next.getMonth() + 1, 0).getDate())));
143
- setMonth(next);
170
+ const next = addMonths(from, event.key === 'PageUp' ? -1 : 1);
171
+ focusOn(new Date(next.getFullYear(), next.getMonth(), Math.min(from.getDate(), new Date(next.getFullYear(), next.getMonth() + 1, 0).getDate())), 1);
144
172
  }
145
173
  };
146
174
  const monthLabel = date => formatters.formatCaption?.(date) || new Intl.DateTimeFormat(localeCode, {
@@ -159,6 +187,7 @@ export function Calendar({
159
187
  className: `ef-cal${className ? ` ${className}` : ''}`,
160
188
  style: style
161
189
  }), /*#__PURE__*/React.createElement("div", {
190
+ ref: monthsRef,
162
191
  className: `ef-cal__months${classNames.months ? ` ${classNames.months}` : ''}`
163
192
  }, monthViews.map((view, viewIndex) => {
164
193
  const first = new Date(view.getFullYear(), view.getMonth(), 1);
@@ -210,7 +239,6 @@ export function Calendar({
210
239
  onClick: () => setMonth(addMonths(visibleMonth, 1))
211
240
  }) : null), /*#__PURE__*/React.createElement("div", {
212
241
  role: "grid",
213
- ref: viewIndex === 0 ? gridRef : undefined,
214
242
  onKeyDown: keydown,
215
243
  "aria-label": monthLabel(view),
216
244
  className: "ef-cal__grid"
@@ -239,7 +267,7 @@ export function Calendar({
239
267
  });
240
268
  const rangeStart = mode === 'range' && sameDay(date, selected?.from);
241
269
  const rangeEnd = mode === 'range' && sameDay(date, selected?.to);
242
- const rangeMiddle = mode === 'range' && selected?.from && selected?.to && date > selected.from && date < selected.to;
270
+ const rangeMiddle = mode === 'range' && selected?.from && selected?.to && date > startDay(selected.from) && date < startDay(selected.to);
243
271
  const modifiers = {
244
272
  selected: isSelected(date),
245
273
  today: sameDay(date, new Date()),
@@ -258,7 +286,7 @@ export function Calendar({
258
286
  locale: locale,
259
287
  role: "gridcell",
260
288
  "data-key": dayKey(date),
261
- tabIndex: sameDay(date, focusDate) ? 0 : -1,
289
+ tabIndex: !outside && sameDay(date, tabDate) ? 0 : -1,
262
290
  "aria-label": date.toLocaleDateString(localeCode, {
263
291
  dateStyle: 'long'
264
292
  }),
@@ -43,14 +43,22 @@ export function TimePicker({
43
43
  invalid,
44
44
  style,
45
45
  className,
46
+ id,
47
+ 'aria-label': ariaLabel,
48
+ 'aria-labelledby': ariaLabelledBy,
49
+ 'aria-describedby': ariaDescribedBy,
46
50
  ...rest
47
51
  }) {
48
52
  // Picks up id / aria wiring when nested in a Field; standalone this is a no-op.
49
53
  const field = useFieldProps({
50
54
  invalid,
51
- id: rest.id,
52
- 'aria-describedby': rest['aria-describedby']
55
+ id,
56
+ 'aria-describedby': ariaDescribedBy
53
57
  });
58
+ const uid = React.useId();
59
+ const inputId = field.id || (label ? `${uid}i` : undefined);
60
+ const hintId = hint ? `${uid}h` : undefined;
61
+ const describedBy = [...new Set([field.controlProps['aria-describedby'], hintId].filter(Boolean))].join(' ') || undefined;
54
62
  const bad = field.invalid;
55
63
  const [open, setOpen] = React.useState(false);
56
64
  const [q, setQ] = React.useState(null); // null = not editing, input mirrors `value`
@@ -123,6 +131,7 @@ export function TimePicker({
123
131
  setOpen(false);
124
132
  };
125
133
  const onKey = e => {
134
+ if (e.nativeEvent.isComposing || e.keyCode === 229) return;
126
135
  if (e.key === 'ArrowDown') {
127
136
  e.preventDefault();
128
137
  if (!open) openList();else setHi(h => Math.min(h + 1, shown.length - 1));
@@ -141,6 +150,10 @@ export function TimePicker({
141
150
  ref: ref,
142
151
  className: `ef-timepicker${bad ? ' ef-timepicker--invalid' : ''}`
143
152
  }, /*#__PURE__*/React.createElement("input", _extends({}, field.controlProps, {
153
+ id: inputId,
154
+ "aria-label": ariaLabel,
155
+ "aria-labelledby": ariaLabelledBy,
156
+ "aria-describedby": describedBy,
144
157
  className: "ef-timepicker__input",
145
158
  role: "combobox",
146
159
  "aria-expanded": open,
@@ -197,9 +210,11 @@ export function TimePicker({
197
210
  return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
198
211
  className: `ef-field${className ? ' ' + className : ''}`,
199
212
  style: style
200
- }), label ? /*#__PURE__*/React.createElement("span", {
213
+ }), label ? /*#__PURE__*/React.createElement("label", {
214
+ htmlFor: inputId,
201
215
  className: "ef-field__label"
202
216
  }, label) : null, control, hint ? /*#__PURE__*/React.createElement("span", {
217
+ id: hintId,
203
218
  className: "ef-field__hint"
204
219
  }, hint) : null);
205
220
  }
@@ -25,6 +25,7 @@ export function Toolbar({
25
25
  });
26
26
  const btn = /*#__PURE__*/React.createElement("button", {
27
27
  key: it.id,
28
+ type: "button",
28
29
  disabled: it.disabled,
29
30
  "aria-pressed": active.includes(it.id) || undefined,
30
31
  className: `ef-toolbar__btn${active.includes(it.id) ? ' ef-toolbar__btn--active' : ''}`,
@@ -13,10 +13,13 @@ function Node({
13
13
  const kids = node.children || [];
14
14
  const isOpen = open.includes(node.id);
15
15
  return /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
16
+ type: "button",
16
17
  className: `ef-tree__row${sel === node.id ? ' ef-tree__row--sel' : ''}`,
17
18
  style: {
18
19
  paddingInlineStart: 8 + depth * 18
19
20
  },
21
+ "aria-expanded": kids.length ? isOpen : undefined,
22
+ "aria-current": sel === node.id ? 'true' : undefined,
20
23
  onClick: () => {
21
24
  if (kids.length) toggle(node.id);
22
25
  select(node.id, node);
@@ -71,17 +74,21 @@ export function TreeList({
71
74
  if (value == null) setInnerSel(id);
72
75
  onChange?.(id, node);
73
76
  };
74
- return /*#__PURE__*/React.createElement("div", _extends({}, rest, {
75
- role: "tree",
76
- className: `ef-tree${className ? ' ' + className : ''}`,
77
- style: style
78
- }), nodes.map(n => /*#__PURE__*/React.createElement(Node, {
79
- key: n.id,
80
- node: n,
81
- depth: 0,
82
- open: open,
83
- sel: sel,
84
- toggle: toggle,
85
- select: select
86
- })));
77
+ return (
78
+ /*#__PURE__*/
79
+ // Plain disclosure buttons, not role="tree": a tree promises treeitems and
80
+ // arrow-key navigation, which this list does not implement.
81
+ React.createElement("div", _extends({}, rest, {
82
+ className: `ef-tree${className ? ' ' + className : ''}`,
83
+ style: style
84
+ }), nodes.map(n => /*#__PURE__*/React.createElement(Node, {
85
+ key: n.id,
86
+ node: n,
87
+ depth: 0,
88
+ open: open,
89
+ sel: sel,
90
+ toggle: toggle,
91
+ select: select
92
+ })))
93
+ );
87
94
  }