@seanyeh77/ui 0.6.0 → 0.7.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.js CHANGED
@@ -1,5 +1,5 @@
1
1
  "use client";
2
- import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-CDWxD999.js";
2
+ import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-B2xJlA9l.js";
3
3
  import * as React from "react";
4
4
  import { Fragment, jsx, jsxs } from "react/jsx-runtime";
5
5
  import { Tooltip as Tooltip$1 } from "@base-ui/react/tooltip";
@@ -417,6 +417,37 @@ function useMoving() {
417
417
  React.useEffect(() => () => clearTimeout(t.current), []);
418
418
  return [moving, start];
419
419
  }
420
+ // src/announce.ts
421
+ let region = null;
422
+ let timer;
423
+ /** Creates the live region if it is not on the page yet. A region that exists before its text changes is read more
424
+ * reliably, so AppShell and initTheme call this early. */
425
+ function ensureAnnouncer() {
426
+ if (typeof document === "undefined") return null;
427
+ if (region?.isConnected) return region;
428
+ region = document.querySelector("[data-ui-announcer]");
429
+ if (!region) {
430
+ region = document.createElement("div");
431
+ region.className = "ui-visually-hidden";
432
+ region.setAttribute("role", "status");
433
+ region.setAttribute("aria-live", "polite");
434
+ region.setAttribute("aria-atomic", "true");
435
+ region.setAttribute("data-ui-announcer", "");
436
+ document.body.appendChild(region);
437
+ }
438
+ return region;
439
+ }
440
+ /** Says text to screen readers through the page's polite live region, without moving focus: 「顯示 6 筆」.
441
+ * A second call before the first is read replaces it. */
442
+ function announce(text) {
443
+ const el = ensureAnnouncer();
444
+ if (!el || !text) return;
445
+ el.textContent = "";
446
+ if (timer) clearTimeout(timer);
447
+ timer = setTimeout(() => {
448
+ el.textContent = text;
449
+ }, 60);
450
+ }
420
451
  // src/components/SideNav/SideNav.tsx
421
452
  /** The 240 px dashboard sidebar (72 px collapsed). The selection bar moves like a droplet. */
422
453
  function SideNav({ sections, value, onChange, collapsed = false, onToggle, brand, label, className }) {
@@ -430,6 +461,13 @@ function SideNav({ sections, value, onChange, collapsed = false, onToggle, brand
430
461
  });
431
462
  const last = React.useRef(null);
432
463
  const [moving, bump] = useMoving();
464
+ const firstValue = React.useRef(value);
465
+ React.useEffect(() => {
466
+ if (value === firstValue.current) return;
467
+ firstValue.current = void 0;
468
+ const it = sections.flatMap((sec) => sec.items.flatMap((it) => [it, ...it.children ?? []])).find((x) => x.id === value);
469
+ if (it) announce(it.label);
470
+ }, [value]);
433
471
  const [closed, setClosed] = React.useState({});
434
472
  const closedKey = Object.keys(closed).filter((k) => closed[k]).join();
435
473
  React.useLayoutEffect(() => {
@@ -582,6 +620,23 @@ function Tooltip({ label, side = "top", describe = true, wrap = false, disabled
582
620
  const [open, setOpen] = React.useState(false);
583
621
  const close = React.useCallback(() => setOpen(false), []);
584
622
  const shown = open && !disabled;
623
+ React.useEffect(() => {
624
+ if (!shown) return;
625
+ const away = (e) => {
626
+ const t = e.target;
627
+ if (!(t instanceof Element) || !t.closest(`[data-ui-tip="${id}"]`)) close();
628
+ };
629
+ document.addEventListener("pointerdown", away, true);
630
+ document.addEventListener("scroll", close, true);
631
+ return () => {
632
+ document.removeEventListener("pointerdown", away, true);
633
+ document.removeEventListener("scroll", close, true);
634
+ };
635
+ }, [
636
+ shown,
637
+ close,
638
+ id
639
+ ]);
585
640
  React.useEffect(() => {
586
641
  if (!shown) return;
587
642
  for (const other of openNow) if (other !== close) other();
@@ -599,7 +654,8 @@ function Tooltip({ label, side = "top", describe = true, wrap = false, disabled
599
654
  delay: 0,
600
655
  render: children,
601
656
  "aria-describedby": describe && !disabled ? id : void 0,
602
- onBlur: close
657
+ onBlur: close,
658
+ "data-ui-tip": id
603
659
  }),
604
660
  describe && !disabled ? /* @__PURE__ */ jsx("span", {
605
661
  id,
@@ -636,10 +692,16 @@ function IconButton({ label, icon, className, tooltip = true, ...native }) {
636
692
  }
637
693
  // src/components/TopBar/TopBar.tsx
638
694
  /** The bar at the top of a dashboard page: title or breadcrumb on the left, search and tools on the right. */
639
- function TopBar({ title, breadcrumb, onSearch, searchLabel, children, className }) {
695
+ function TopBar({ title, breadcrumb, onSearch, searchLabel, children, onMenu, className }) {
640
696
  return /* @__PURE__ */ jsxs("header", {
641
697
  className: cx("ui-topbar", className),
642
698
  children: [
699
+ onMenu ? /* @__PURE__ */ jsx(IconButton, {
700
+ className: "ui-topbar-menu",
701
+ icon: "list-bullets",
702
+ label: tr("開啟導覽"),
703
+ onClick: onMenu
704
+ }) : null,
643
705
  title ? /* @__PURE__ */ jsx("h1", {
644
706
  className: "ui-topbar-title",
645
707
  children: title
@@ -689,22 +751,20 @@ function MobileTabBar({ items, value, onChange, label, className }) {
689
751
  right: `calc(${100 - idx * w - w / 2}% - 28px)`,
690
752
  transition: dropTransition("left", "right", forward)
691
753
  }
692
- }), items.map((t, i) => /* @__PURE__ */ jsxs("button", {
754
+ }), items.map((t, i) => /* @__PURE__ */ jsx("button", {
693
755
  type: "button",
694
756
  className: cx("ui-tabbar-item", i === idx && "is-selected"),
757
+ "aria-label": t.label,
695
758
  "aria-current": i === idx ? "page" : void 0,
696
759
  onClick: () => {
697
760
  if (i !== idx) setForward(i > idx);
698
761
  onChange?.(t.id);
699
762
  },
700
- children: [/* @__PURE__ */ jsx(IconOf, {
763
+ children: /* @__PURE__ */ jsx(IconOf, {
701
764
  icon: t.icon,
702
765
  size: 22,
703
766
  filled: i === idx
704
- }), /* @__PURE__ */ jsx("span", {
705
- className: "ui-tabbar-label",
706
- children: t.label
707
- })]
767
+ })
708
768
  }, t.id))]
709
769
  });
710
770
  }
@@ -845,7 +905,7 @@ function Dialog(props) {
845
905
  }
846
906
  // src/components/Drawer/Drawer.tsx
847
907
  /** A 400 px panel from the right for editing one item without leaving the page. */
848
- function Drawer({ open, onClose, title, actions, dirty, width, confirmTitle, confirmText, children }) {
908
+ function Drawer({ open, onClose, title, actions, dirty, width, side = "right", confirmTitle, confirmText, children }) {
849
909
  const [asking, setAsking] = React.useState(false);
850
910
  const request = () => dirty ? setAsking(true) : onClose();
851
911
  const panel = React.useRef(null);
@@ -856,7 +916,7 @@ function Drawer({ open, onClose, title, actions, dirty, width, confirmTitle, con
856
916
  children: /* @__PURE__ */ jsxs(Dialog$1.Portal, { children: [/* @__PURE__ */ jsx(Dialog$1.Backdrop, { className: "ui-drawer-backdrop" }), /* @__PURE__ */ jsxs(Dialog$1.Popup, {
857
917
  ref: panel,
858
918
  initialFocus: firstField,
859
- className: "ui-drawer",
919
+ className: side === "left" ? "ui-drawer is-left" : "ui-drawer",
860
920
  style: width ? { width } : void 0,
861
921
  children: [
862
922
  /* @__PURE__ */ jsxs("div", {
@@ -897,16 +957,28 @@ function Drawer({ open, onClose, title, actions, dirty, width, confirmTitle, con
897
957
  })] })
898
958
  });
899
959
  }
960
+ // src/internal/focusMain.ts
961
+ /** Moves keyboard and screen-reader focus to the page's content: its first heading inside main (or the top bar's title),
962
+ * else main itself. Call it after the app changes page, e.g. when a CommandPalette result opens another page. */
963
+ function focusMain() {
964
+ if (typeof document === "undefined") return;
965
+ const main = document.querySelector("main");
966
+ const target = main?.querySelector("h1, h2") ?? document.querySelector(".ui-topbar-title") ?? main;
967
+ if (!target) return;
968
+ if (target.tabIndex < 0 && !target.hasAttribute("tabindex")) target.setAttribute("tabindex", "-1");
969
+ target.focus();
970
+ }
900
971
  // src/components/AppShell/AppShell.tsx
901
972
  const COLLAPSE_KEY = "ui-nav-collapsed";
902
973
  const MORE = "\0more";
903
- /** The dashboard frame: sidebar (240 px, 72 px collapsed and on tablets), top bar, and bottom tabs on phones.
974
+ /** The dashboard frame: sidebar (240 px, 72 px collapsed) above 1024 px, a drawer from the top bar's menu button from
975
+ * 600 to 1024 px, and bottom tabs on phones.
904
976
  * The top bar hides while scrolling down and returns when scrolling up. */
905
977
  function AppShell({ nav, value, onNavigate, brand, title, breadcrumb, onSearch, actions, children, className }) {
906
978
  const phone = useNarrow();
907
- const tablet = useMedia("(min-width: 600px) and (max-width: 959px)");
979
+ const tablet = useMedia("(min-width: 600px) and (max-width: 1024px)");
908
980
  const [userCollapsed, setUserCollapsed] = React.useState(() => store(COLLAPSE_KEY) === "1");
909
- const collapsed = tablet || userCollapsed;
981
+ const collapsed = userCollapsed;
910
982
  const top = nav.flatMap((s) => s.items);
911
983
  const parentOf = (id) => top.find((it) => it.children?.some((c) => c.id === id));
912
984
  const withIcon = top.filter((it) => !!it.icon);
@@ -945,54 +1017,73 @@ function AppShell({ nav, value, onNavigate, brand, title, breadcrumb, onSearch,
945
1017
  el.addEventListener("scroll", onScroll, { passive: true });
946
1018
  return () => el.removeEventListener("scroll", onScroll);
947
1019
  }, []);
1020
+ React.useEffect(() => {
1021
+ ensureAnnouncer();
1022
+ }, []);
948
1023
  return /* @__PURE__ */ jsxs("div", {
949
1024
  className: cx("ui-shell", phone && "is-phone", className),
950
- children: [phone ? null : /* @__PURE__ */ jsx(SideNav, {
951
- sections: nav,
952
- value,
953
- onChange: onNavigate,
954
- brand,
955
- collapsed,
956
- onToggle: tablet ? void 0 : () => {
957
- store(COLLAPSE_KEY, userCollapsed ? "0" : "1");
958
- setUserCollapsed(!userCollapsed);
959
- }
960
- }), /* @__PURE__ */ jsxs("div", {
961
- className: "ui-shell-body",
962
- children: [
963
- /* @__PURE__ */ jsx(TopBar, {
964
- className: cx("ui-shell-top", hidden && "is-hidden"),
965
- title,
966
- breadcrumb,
967
- onSearch: onSearch ?? false,
968
- children: actions
969
- }),
970
- /* @__PURE__ */ jsx("main", {
971
- ref: main,
972
- className: "ui-shell-main",
973
- children
974
- }),
975
- phone && tabs.length ? /* @__PURE__ */ jsx(MobileTabBar, {
976
- items: tabs,
977
- value: tabValue,
978
- onChange: onTab
979
- }) : null,
980
- phone ? /* @__PURE__ */ jsx(Drawer, {
981
- open: moreOpen,
982
- onClose: () => setMoreOpen(false),
983
- title: tr("全部頁面"),
984
- children: /* @__PURE__ */ jsx(SideNav, {
985
- className: "ui-shell-allnav",
986
- sections: nav,
987
- value,
988
- onChange: (id) => {
989
- setMoreOpen(false);
990
- onNavigate(id);
991
- }
992
- })
993
- }) : null
994
- ]
995
- })]
1025
+ children: [
1026
+ /* @__PURE__ */ jsx("a", {
1027
+ className: "ui-skip",
1028
+ href: "#main",
1029
+ onClick: (e) => {
1030
+ e.preventDefault();
1031
+ focusMain();
1032
+ },
1033
+ children: tr("跳到主要內容")
1034
+ }),
1035
+ phone || tablet ? null : /* @__PURE__ */ jsx(SideNav, {
1036
+ sections: nav,
1037
+ value,
1038
+ onChange: onNavigate,
1039
+ brand,
1040
+ collapsed,
1041
+ onToggle: () => {
1042
+ store(COLLAPSE_KEY, userCollapsed ? "0" : "1");
1043
+ setUserCollapsed(!userCollapsed);
1044
+ }
1045
+ }),
1046
+ /* @__PURE__ */ jsxs("div", {
1047
+ className: "ui-shell-body",
1048
+ children: [
1049
+ /* @__PURE__ */ jsx(TopBar, {
1050
+ className: cx("ui-shell-top", hidden && "is-hidden"),
1051
+ title,
1052
+ breadcrumb,
1053
+ onSearch: onSearch ?? false,
1054
+ onMenu: tablet ? () => setMoreOpen(true) : void 0,
1055
+ children: actions
1056
+ }),
1057
+ /* @__PURE__ */ jsx("main", {
1058
+ ref: main,
1059
+ className: "ui-shell-main",
1060
+ tabIndex: -1,
1061
+ children
1062
+ }),
1063
+ phone && tabs.length ? /* @__PURE__ */ jsx(MobileTabBar, {
1064
+ items: tabs,
1065
+ value: tabValue,
1066
+ onChange: onTab
1067
+ }) : null,
1068
+ phone || tablet ? /* @__PURE__ */ jsx(Drawer, {
1069
+ open: moreOpen,
1070
+ onClose: () => setMoreOpen(false),
1071
+ title: tr("全部頁面"),
1072
+ side: tablet ? "left" : "right",
1073
+ width: tablet ? 300 : void 0,
1074
+ children: /* @__PURE__ */ jsx(SideNav, {
1075
+ className: "ui-shell-allnav",
1076
+ sections: nav,
1077
+ value,
1078
+ onChange: (id) => {
1079
+ setMoreOpen(false);
1080
+ onNavigate(id);
1081
+ }
1082
+ })
1083
+ }) : null
1084
+ ]
1085
+ })
1086
+ ]
996
1087
  });
997
1088
  }
998
1089
  // src/components/Grid/Grid.tsx
@@ -1093,6 +1184,7 @@ let following = false;
1093
1184
  /** Applies the stored theme and accent; call once when the page starts. */
1094
1185
  function initTheme() {
1095
1186
  setTheme(storedTheme());
1187
+ ensureAnnouncer();
1096
1188
  if (following || typeof window.matchMedia !== "function") return;
1097
1189
  following = true;
1098
1190
  window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
@@ -1178,6 +1270,73 @@ function AccentPicker({ value, onChange, label, className }) {
1178
1270
  })]
1179
1271
  });
1180
1272
  }
1273
+ // src/internal/focus.tsx
1274
+ /** True when focus has fallen out of the page's content: nothing focused, or the body. */
1275
+ const lost = () => !document.activeElement || document.activeElement === document.body;
1276
+ /** For a dialog-like overlay opened by the open prop: remembers what had focus when it opened and gives focus back
1277
+ * when it closes. When that element is gone (the app changed page), focus goes to the main content. */
1278
+ function useReturnFocus(open) {
1279
+ const opener = React.useRef(null);
1280
+ const wasOpen = React.useRef(false);
1281
+ React.useEffect(() => {
1282
+ if (open && !wasOpen.current) {
1283
+ const a = document.activeElement;
1284
+ opener.current = a instanceof HTMLElement && a !== document.body ? a : null;
1285
+ }
1286
+ if (!open && wasOpen.current) {
1287
+ const back = opener.current;
1288
+ opener.current = null;
1289
+ const t = setTimeout(() => {
1290
+ if (!lost()) return;
1291
+ if (back?.isConnected) back.focus();
1292
+ else focusMain();
1293
+ }, 0);
1294
+ wasOpen.current = open;
1295
+ return () => clearTimeout(t);
1296
+ }
1297
+ wasOpen.current = open;
1298
+ }, [open]);
1299
+ }
1300
+ const FOCUSABLE = "button:not([disabled]), a[href], [tabindex]:not([tabindex=\"-1\"]), input:not([disabled]), [role=\"tab\"]";
1301
+ /** When the focused control inside the container is removed or replaced (a button that turns into another), focus
1302
+ * moves to the control now at its place, else the one before it, else `fallback()`, instead of falling to the body. */
1303
+ function useFocusRescue(ref, fallback) {
1304
+ const fb = React.useRef(fallback);
1305
+ React.useEffect(() => {
1306
+ fb.current = fallback;
1307
+ });
1308
+ React.useEffect(() => {
1309
+ const box = ref.current;
1310
+ if (!box) return;
1311
+ let last = null;
1312
+ let index = -1;
1313
+ const list = () => Array.from(box.querySelectorAll(FOCUSABLE)).filter((e) => e.getClientRects().length > 0 && !e.matches(":disabled"));
1314
+ const onIn = (e) => {
1315
+ if (!(e.target instanceof HTMLElement)) return;
1316
+ last = e.target;
1317
+ index = Array.from(box.querySelectorAll(FOCUSABLE)).indexOf(last);
1318
+ };
1319
+ const mo = new MutationObserver(() => {
1320
+ if (!last || last.isConnected && !last.matches(":disabled") || !lost()) return;
1321
+ const now = list();
1322
+ const next = fb.current?.() ?? now[Math.min(index, now.length - 1)] ?? null;
1323
+ last = null;
1324
+ if (next) next.focus();
1325
+ else focusMain();
1326
+ });
1327
+ box.addEventListener("focusin", onIn);
1328
+ mo.observe(box, {
1329
+ childList: true,
1330
+ subtree: true,
1331
+ attributes: true,
1332
+ attributeFilter: ["disabled"]
1333
+ });
1334
+ return () => {
1335
+ box.removeEventListener("focusin", onIn);
1336
+ mo.disconnect();
1337
+ };
1338
+ }, [ref]);
1339
+ }
1181
1340
  // src/components/Menu/Menu.tsx
1182
1341
  /** The ⋯ button and its list of actions. Danger items go last, in red, after a divider, and are confirmed. */
1183
1342
  function Menu({ items, label, icon = "dots-three", align = "end", triggerClassName }) {
@@ -1245,6 +1404,8 @@ function Menu({ items, label, icon = "dots-three", align = "end", triggerClassNa
1245
1404
  // src/components/ActionBar/ActionBar.tsx
1246
1405
  /** A card's actions in a row. Under 600 px the primary one fills the width and the rest go into 「更多」. */
1247
1406
  function ActionBar({ actions, className }) {
1407
+ const box = React.useRef(null);
1408
+ useFocusRescue(box);
1248
1409
  const main = actions.find((a) => a.primary) ?? actions.find((a) => !a.danger);
1249
1410
  const others = actions.filter((a) => a !== main);
1250
1411
  const button = (a, i, wide) => a.danger ? /* @__PURE__ */ jsx(Button, {
@@ -1276,6 +1437,7 @@ function ActionBar({ actions, className }) {
1276
1437
  disabled: a.disabled
1277
1438
  });
1278
1439
  return /* @__PURE__ */ jsxs("div", {
1440
+ ref: box,
1279
1441
  className: cx("ui-actbar", className),
1280
1442
  children: [/* @__PURE__ */ jsx("div", {
1281
1443
  className: "ui-actbar-wide",
@@ -1858,7 +2020,7 @@ function breakable(text) {
1858
2020
  return out;
1859
2021
  }
1860
2022
  /** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
1861
- function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, maxHeight, className }) {
2023
+ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, maxHeight, className, ref }) {
1862
2024
  const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
1863
2025
  const lang = language || languageOf(file);
1864
2026
  const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
@@ -1888,6 +2050,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
1888
2050
  const from = windowed ? Math.max(0, ta - start - context) : 0;
1889
2051
  const to = windowed ? Math.min(lines.length, tb - start + context + 1) : lines.length;
1890
2052
  const body = React.useRef(null);
2053
+ React.useImperativeHandle(ref, () => ({ focusTarget: () => body.current?.querySelector(".is-target")?.focus() }));
1891
2054
  React.useEffect(() => {
1892
2055
  const b = body.current;
1893
2056
  const el = b?.querySelector(".is-target");
@@ -1899,18 +2062,24 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
1899
2062
  const n = start + i;
1900
2063
  const on = ta != null && tb != null && n >= ta && n <= tb;
1901
2064
  rows.push(/* @__PURE__ */ jsxs("div", {
2065
+ role: "listitem",
1902
2066
  className: cx("ui-cv-line", on && "is-target"),
1903
2067
  "aria-current": on && n === ta ? "location" : void 0,
2068
+ tabIndex: on && n === ta ? -1 : void 0,
1904
2069
  children: [/* @__PURE__ */ jsx("span", {
1905
2070
  className: "ui-cv-num",
1906
2071
  style: { width: digits + 2 + "ch" },
2072
+ "aria-hidden": "true",
1907
2073
  children: n
1908
- }), /* @__PURE__ */ jsx("span", {
2074
+ }), /* @__PURE__ */ jsxs("span", {
1909
2075
  className: "ui-cv-text",
1910
- children: toks[i].map(([cls, text], j) => cls ? /* @__PURE__ */ jsx("span", {
2076
+ children: [/* @__PURE__ */ jsx("span", {
2077
+ className: "ui-visually-hidden ui-cv-sr",
2078
+ children: tr("第 {n} 行", { n }) + ":"
2079
+ }), toks[i].map(([cls, text], j) => cls ? /* @__PURE__ */ jsx("span", {
1911
2080
  className: cls,
1912
2081
  children: breakable(text)
1913
- }, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))
2082
+ }, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))]
1914
2083
  })]
1915
2084
  }, i));
1916
2085
  }
@@ -1946,7 +2115,11 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
1946
2115
  className: "ui-cv-body",
1947
2116
  style: maxHeight ? { maxHeight } : void 0,
1948
2117
  tabIndex: 0,
1949
- children: /* @__PURE__ */ jsx("code", { children: rows })
2118
+ "aria-label": tr("程式碼"),
2119
+ children: /* @__PURE__ */ jsx("code", {
2120
+ role: "list",
2121
+ children: rows
2122
+ })
1950
2123
  }),
1951
2124
  narrow && canWindow ? /* @__PURE__ */ jsx("button", {
1952
2125
  type: "button",
@@ -1980,6 +2153,7 @@ function CommandPalette(props) {
1980
2153
  const { open, onOpenChange, items, onSelect, placeholder, recent, recentLabel, emptyText, kinds, filter = true, onQueryChange, loading, limit = 50, hotkey = true, defaultQuery = "", label } = props;
1981
2154
  const [q, setQ] = React.useState(defaultQuery);
1982
2155
  const [active, setActive] = React.useState(0);
2156
+ useReturnFocus(open);
1983
2157
  const [wasOpen, setWasOpen] = React.useState(open);
1984
2158
  if (open !== wasOpen) {
1985
2159
  setWasOpen(open);
@@ -2060,6 +2234,12 @@ function CommandPalette(props) {
2060
2234
  });
2061
2235
  };
2062
2236
  const empty = query ? tr("找不到符合「{q}」的結果", { q: q.trim() }) : emptyText || tr("輸入名稱開始搜尋");
2237
+ const said = !open ? "" : !query ? "" : loading ? tr("搜尋中") : shown.length ? tr("找到 {n} 筆結果", { n: shown.length }) : empty;
2238
+ React.useEffect(() => {
2239
+ if (!said) return;
2240
+ const t = setTimeout(() => announce(said), 400);
2241
+ return () => clearTimeout(t);
2242
+ }, [said]);
2063
2243
  return /* @__PURE__ */ jsx(Dialog$1.Root, {
2064
2244
  open,
2065
2245
  onOpenChange,
@@ -2141,7 +2321,6 @@ function CommandPalette(props) {
2141
2321
  }, it.id ?? i))
2142
2322
  }) : /* @__PURE__ */ jsx("p", {
2143
2323
  className: "ui-pal-empty",
2144
- role: "status",
2145
2324
  children: loading ? tr("搜尋中") : empty
2146
2325
  }),
2147
2326
  /* @__PURE__ */ jsxs("div", {
@@ -2221,6 +2400,7 @@ function Tabs({ items, value, onChange, label, unit, className }) {
2221
2400
  const [box, setBox] = React.useState(null);
2222
2401
  const [forward, setForward] = React.useState(true);
2223
2402
  const [moving, bump] = useMoving();
2403
+ useFocusRescue(track, () => refs.current[Math.max(0, items.findIndex((t) => t.id === value))]);
2224
2404
  devWarn(items.some((t) => t.count != null && !(t.unit || unit)), "Tabs", "a count has no unit, so it reads as a bare number. Pass unit, e.g. unit: '筆', on Tabs or on the item.");
2225
2405
  const idx = Math.max(0, items.findIndex((t) => t.id === value));
2226
2406
  React.useLayoutEffect(() => {
@@ -2242,6 +2422,7 @@ function Tabs({ items, value, onChange, label, unit, className }) {
2242
2422
  setForward(i > idx);
2243
2423
  bump();
2244
2424
  onChange?.(items[i].id);
2425
+ announce(items[i].label + (items[i].count != null ? " " + format.number(items[i].count ?? 0) + (items[i].unit || unit ? " " + tr(items[i].unit || unit || "") : "") : ""));
2245
2426
  };
2246
2427
  return /* @__PURE__ */ jsxs("div", {
2247
2428
  ref: track,
@@ -2274,13 +2455,17 @@ function Tabs({ items, value, onChange, label, unit, className }) {
2274
2455
  refs.current[to]?.focus();
2275
2456
  go(to);
2276
2457
  },
2277
- children: [t.label, t.count != null ? /* @__PURE__ */ jsxs("span", {
2278
- className: "ui-tab-count",
2279
- children: [format.number(t.count), t.unit || unit ? /* @__PURE__ */ jsxs("span", {
2280
- className: "ui-unit",
2281
- children: [" ", tr(t.unit || unit || "")]
2282
- }) : null]
2283
- }) : null]
2458
+ children: [
2459
+ t.label,
2460
+ t.count != null ? " " : null,
2461
+ t.count != null ? /* @__PURE__ */ jsxs("span", {
2462
+ className: "ui-tab-count",
2463
+ children: [format.number(t.count), t.unit || unit ? /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("span", {
2464
+ className: "ui-unit",
2465
+ children: tr(t.unit || unit || "")
2466
+ })] }) : null]
2467
+ }) : null
2468
+ ]
2284
2469
  }, t.id))]
2285
2470
  });
2286
2471
  }
@@ -2796,6 +2981,15 @@ function DataTable(p) {
2796
2981
  return (typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), "zh-Hant")) * d || a.i - b.i;
2797
2982
  });
2798
2983
  }
2984
+ const shownKey = `${q}|${valuesKey}|${sumVal}|${view}`;
2985
+ const firstKey = React.useRef(shownKey);
2986
+ const shownN = list.length;
2987
+ React.useEffect(() => {
2988
+ if (shownKey === firstKey.current) return;
2989
+ firstKey.current = "";
2990
+ const t = setTimeout(() => announce(tr("顯示 {n} 筆", { n: format.number(shownN) })), 400);
2991
+ return () => clearTimeout(t);
2992
+ }, [shownKey, shownN]);
2799
2993
  const pages = Math.max(1, Math.ceil(list.length / pageSize));
2800
2994
  const pageNow = Math.min(page, pages - 1);
2801
2995
  const start = pageNow * pageSize;
@@ -3081,10 +3275,14 @@ function DataTable(p) {
3081
3275
  },
3082
3276
  children: [v.label, /* @__PURE__ */ jsxs("span", {
3083
3277
  className: "ui-dt-view-n",
3084
- children: [format.number(rows.filter((r) => !v.filter || v.filter(r)).length), /* @__PURE__ */ jsxs("span", {
3085
- className: "ui-unit",
3086
- children: [" ", tr("筆")]
3087
- })]
3278
+ children: [
3279
+ format.number(rows.filter((r) => !v.filter || v.filter(r)).length),
3280
+ " ",
3281
+ /* @__PURE__ */ jsx("span", {
3282
+ className: "ui-unit",
3283
+ children: tr("筆")
3284
+ })
3285
+ ]
3088
3286
  })]
3089
3287
  }, v.id);
3090
3288
  })
@@ -3686,15 +3884,15 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
3686
3884
  ref,
3687
3885
  className: cx("ui-term", inline && "is-inline", open && "is-open", className),
3688
3886
  children: [
3887
+ /* @__PURE__ */ jsx("span", {
3888
+ className: "ui-visually-hidden",
3889
+ children: tr("說明") + " "
3890
+ }),
3689
3891
  children,
3690
3892
  /* @__PURE__ */ jsx(Icon, {
3691
3893
  name: "question",
3692
3894
  size: 14,
3693
3895
  className: "ui-term-q"
3694
- }),
3695
- /* @__PURE__ */ jsx("span", {
3696
- className: "ui-visually-hidden",
3697
- children: tr("(說明)")
3698
3896
  })
3699
3897
  ]
3700
3898
  });
@@ -3926,6 +4124,7 @@ function KpiCard(props) {
3926
4124
  });
3927
4125
  }
3928
4126
  // src/components/LayerGraph/LayerGraph.tsx
4127
+ const scrollMemory = /* @__PURE__ */ new Map();
3929
4128
  let measure;
3930
4129
  const SPLIT = /(`[^`]+`|\d[\d,.]*)/;
3931
4130
  function labelWidth(text) {
@@ -4046,6 +4245,23 @@ function LayerGraph(p) {
4046
4245
  const pickEdge = p.onSelectEdge;
4047
4246
  const [hover, setHover] = React.useState(null);
4048
4247
  const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
4248
+ const uid = React.useId().replace(/:/g, "");
4249
+ const [view, setView] = React.useState("graph");
4250
+ const memKey = p.scrollKey ?? all.map((n) => n.id).join("|");
4251
+ React.useLayoutEffect(() => {
4252
+ const el = scrollRef.current;
4253
+ const x = scrollMemory.get(memKey);
4254
+ if (el && x) el.scrollLeft = x;
4255
+ }, [
4256
+ memKey,
4257
+ view,
4258
+ scrollRef
4259
+ ]);
4260
+ const onScrollKeep = () => {
4261
+ const el = scrollRef.current;
4262
+ if (el) scrollMemory.set(memKey, el.scrollLeft);
4263
+ onScroll();
4264
+ };
4049
4265
  const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
4050
4266
  const uses = {};
4051
4267
  for (const e of p.edges) if (sharedIds.has(e.to) && !sharedIds.has(e.from)) (uses[e.to] ??= {})[e.from] = (uses[e.to]?.[e.from] ?? 0) + (e.count || 0);
@@ -4059,10 +4275,9 @@ function LayerGraph(p) {
4059
4275
  };
4060
4276
  const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
4061
4277
  const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
4062
- const upW = (list) => Math.max(0, ...list.map((e) => Math.ceil(Math.max(labelWidth(e.inferred ? e.label || p.inferredLabel || tr("推測") : ""), labelWidth(countText(e))))));
4063
4278
  if (upsL.length) {
4064
4279
  const left0 = Math.min(...main.map((n) => pos[n.id].x));
4065
- const shift = Math.max(0, PAD + upW(upsL) + 8 + (upsL.length - 1) * LANE_STEP + LANE - left0);
4280
+ const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
4066
4281
  for (const id in pos) pos[id] = {
4067
4282
  x: pos[id].x + shift,
4068
4283
  y: pos[id].y
@@ -4072,9 +4287,9 @@ function LayerGraph(p) {
4072
4287
  const boxesLeft = Math.min(...main.map((n) => pos[n.id].x));
4073
4288
  const boxesRight = Math.max(0, ...main.map((n) => pos[n.id].x + NW));
4074
4289
  const laneX = (e) => onLeft(e) ? boxesLeft - LANE - upsL.indexOf(e) * LANE_STEP : boxesRight + LANE + upsR.indexOf(e) * LANE_STEP;
4075
- const upLabelX = boxesRight + LANE + Math.max(0, upsR.length - 1) * LANE_STEP + 8;
4076
- const upLabelEndL = boxesLeft - LANE - Math.max(0, upsL.length - 1) * LANE_STEP - 8;
4077
- if (upsR.length) W = Math.max(W, upLabelX + upW(upsR) + PAD);
4290
+ const upLabelX = boxesLeft - LANE + 8;
4291
+ const upLabelEndL = boxesRight + LANE - 8;
4292
+ if (upsR.length) W = Math.max(W, boxesRight + LANE + (upsR.length - 1) * LANE_STEP + PAD);
4078
4293
  const choose = (e) => {
4079
4294
  const id = edgeId(e);
4080
4295
  const next = p.selectedEdge === id ? null : id;
@@ -4085,6 +4300,7 @@ function LayerGraph(p) {
4085
4300
  const labels = [];
4086
4301
  const marks = [];
4087
4302
  const runs = [];
4303
+ const segs = [];
4088
4304
  const arrows = [];
4089
4305
  const hitPaths = [];
4090
4306
  edges.forEach((e, idx) => {
@@ -4179,9 +4395,9 @@ function LayerGraph(p) {
4179
4395
  idx,
4180
4396
  e,
4181
4397
  text,
4182
- tx: L ? upLabelEndL : upLabelX,
4398
+ tx: L ? upLabelX : upLabelEndL,
4183
4399
  ty: Math.round((y0 + y1) / 2),
4184
- left: L,
4400
+ left: !L,
4185
4401
  r,
4186
4402
  dim,
4187
4403
  up: true
@@ -4227,7 +4443,21 @@ function LayerGraph(p) {
4227
4443
  ]);
4228
4444
  }
4229
4445
  const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
4230
- const d = route(clean(pts), 10);
4446
+ const cpts = clean(pts);
4447
+ for (let k = 1; k < cpts.length; k++) {
4448
+ const [ax, ay] = cpts[k - 1];
4449
+ const [bx, by] = cpts[k];
4450
+ segs.push({
4451
+ idx,
4452
+ box: [
4453
+ Math.min(ax, bx) - 3,
4454
+ Math.max(ax, bx) + 3,
4455
+ Math.min(ay, by) - 3,
4456
+ Math.max(ay, by) + 3
4457
+ ]
4458
+ });
4459
+ }
4460
+ const d = route(cpts, 10);
4231
4461
  paths.push(/* @__PURE__ */ jsx("path", {
4232
4462
  className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
4233
4463
  d,
@@ -4273,8 +4503,15 @@ function LayerGraph(p) {
4273
4503
  }
4274
4504
  });
4275
4505
  const placed = [...arrows, ...runs];
4506
+ const boxRects = main.map((n) => [
4507
+ pos[n.id].x,
4508
+ pos[n.id].x + NW,
4509
+ pos[n.id].y,
4510
+ pos[n.id].y + NH
4511
+ ]);
4276
4512
  const hits = (x0, x1, y0, y1) => placed.some((q) => x0 < q[1] + (q[4] || 0) && q[0] < x1 + (q[4] || 0) && y0 < q[3] && q[2] < y1);
4277
4513
  const labelEl = (m, x0, top) => /* @__PURE__ */ jsx("span", {
4514
+ "aria-hidden": pickEdge ? true : void 0,
4278
4515
  className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
4279
4516
  style: {
4280
4517
  left: x0,
@@ -4291,10 +4528,19 @@ function LayerGraph(p) {
4291
4528
  marks.sort((m, n) => m.ty - n.ty || m.tx - n.tx).forEach((m) => {
4292
4529
  const w = Math.ceil(labelWidth(m.text));
4293
4530
  if (m.up) {
4294
- const x0 = m.left ? m.tx - w : m.tx;
4295
- let top = Math.max(10, Math.min(H - 10, m.ty));
4296
- for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8) && top - 18 >= 10; k++) top -= 18;
4297
- for (let k = 0; k < 16 && hits(x0, x0 + w, top - 8, top + 8) && top + 18 <= H - 10; k++) top += 18;
4531
+ const x0 = Math.max(PAD / 2, Math.min(W - PAD / 2 - w, m.left ? m.tx - w : m.tx));
4532
+ const over = (q, y0, y1) => x0 < q[1] + 4 && q[0] < x0 + w + 4 && y0 < q[3] + 4 && q[2] < y1 + 4;
4533
+ const blocked = (y0, y1) => hits(x0, x0 + w, y0, y1) || boxRects.some((q) => over(q, y0, y1));
4534
+ const crosses = (y0, y1) => segs.some((g) => g.idx !== m.idx && over(g.box, y0, y1));
4535
+ const start = Math.max(10, Math.min(H - 10, m.ty));
4536
+ const find = (bad) => {
4537
+ for (let k = 0; k <= 16; k++) for (const dir of k ? [-1, 1] : [0]) {
4538
+ const t = start + dir * k * 18;
4539
+ if (t >= 10 && t <= H - 10 && !bad(t - 8, t + 8)) return t;
4540
+ }
4541
+ return null;
4542
+ };
4543
+ const top = find((y0, y1) => blocked(y0, y1) || crosses(y0, y1)) ?? find(blocked) ?? start;
4298
4544
  placed.push([
4299
4545
  x0,
4300
4546
  x0 + w,
@@ -4381,15 +4627,87 @@ function LayerGraph(p) {
4381
4627
  })]
4382
4628
  }, s.id);
4383
4629
  });
4630
+ const edgeText = (e) => e.inferred ? e.label ? `${e.label}(${p.inferredLabel || tr("推測")})` : p.inferredLabel || tr("推測") : countText(e);
4631
+ const listItem = (key, on, dim, onClick, head, rest) => /* @__PURE__ */ jsxs("li", {
4632
+ className: cx("ui-lg-li", dim && "is-dim"),
4633
+ children: [onClick ? /* @__PURE__ */ jsx("button", {
4634
+ type: "button",
4635
+ className: cx("ui-lg-libtn", on && "is-selected"),
4636
+ "aria-pressed": on,
4637
+ onClick,
4638
+ children: head
4639
+ }) : /* @__PURE__ */ jsx("span", {
4640
+ className: "ui-lg-lihead",
4641
+ children: head
4642
+ }), rest]
4643
+ }, key);
4644
+ const nodeIds = new Set(all.map((n) => n.id));
4645
+ const list = /* @__PURE__ */ jsxs("div", {
4646
+ className: "ui-lg-list",
4647
+ children: [/* @__PURE__ */ jsxs("section", {
4648
+ "aria-labelledby": `${uid}-ln`,
4649
+ children: [/* @__PURE__ */ jsx("h3", {
4650
+ id: `${uid}-ln`,
4651
+ className: "ui-lg-listtitle",
4652
+ children: p.listLabels?.nodes ?? tr("項目")
4653
+ }), /* @__PURE__ */ jsx("ul", { children: all.map((n) => {
4654
+ const size = sizeOf(n);
4655
+ return listItem(n.id, n.id === sel, !near(n.id), p.onSelect ? () => pick(n.id, n.id === sel) : void 0, /* @__PURE__ */ jsx("span", {
4656
+ className: "ui-lg-code",
4657
+ children: n.name || n.id
4658
+ }), size != null ? /* @__PURE__ */ jsxs("span", {
4659
+ className: "ui-lg-limeta",
4660
+ children: [",", monoNums(sizeText.replace("{n}", ""), [size])]
4661
+ }) : null);
4662
+ }) })]
4663
+ }), /* @__PURE__ */ jsxs("section", {
4664
+ "aria-labelledby": `${uid}-le`,
4665
+ children: [/* @__PURE__ */ jsx("h3", {
4666
+ id: `${uid}-le`,
4667
+ className: "ui-lg-listtitle",
4668
+ children: p.listLabels?.edges ?? tr("關係")
4669
+ }), /* @__PURE__ */ jsx("ul", { children: p.edges.filter((e) => nodeIds.has(e.from) && nodeIds.has(e.to)).map((e, i) => listItem(edgeId(e) + ":" + i, e === selEdge, focus && !related(e) && !(selShared && e.to === selShared), pickEdge && edges.includes(e) ? () => choose(e) : void 0, /* @__PURE__ */ jsxs(Fragment, { children: [
4670
+ /* @__PURE__ */ jsx("span", {
4671
+ className: "ui-lg-code",
4672
+ children: nameOf(e.from)
4673
+ }),
4674
+ " → ",
4675
+ /* @__PURE__ */ jsx("span", {
4676
+ className: "ui-lg-code",
4677
+ children: nameOf(e.to)
4678
+ })
4679
+ ] }), /* @__PURE__ */ jsxs("span", {
4680
+ className: "ui-lg-limeta",
4681
+ children: [":", labelParts(edgeText(e))]
4682
+ }))) })]
4683
+ })]
4684
+ });
4685
+ const showList = p.listView !== false && view === "list";
4384
4686
  return /* @__PURE__ */ jsxs("div", {
4385
4687
  className: cx("ui-graph ui-lg", p.className),
4386
4688
  children: [
4689
+ p.listView === false ? null : /* @__PURE__ */ jsx("div", {
4690
+ className: "ui-lg-bar",
4691
+ children: /* @__PURE__ */ jsx(Tabs, {
4692
+ label: tr("顯示方式"),
4693
+ value: view,
4694
+ onChange: setView,
4695
+ items: [{
4696
+ id: "graph",
4697
+ label: tr("圖")
4698
+ }, {
4699
+ id: "list",
4700
+ label: tr("清單")
4701
+ }]
4702
+ })
4703
+ }),
4704
+ showList ? list : null,
4387
4705
  /* @__PURE__ */ jsx("div", {
4388
- className: cx("ui-lg-scroller", scrollMore && "has-more"),
4706
+ className: cx("ui-lg-scroller", scrollMore && "has-more", showList && "is-hidden"),
4389
4707
  children: /* @__PURE__ */ jsx("div", {
4390
4708
  className: "ui-lg-scroll",
4391
4709
  ref: scrollRef,
4392
- onScroll,
4710
+ onScroll: onScrollKeep,
4393
4711
  children: /* @__PURE__ */ jsxs("div", {
4394
4712
  className: "ui-lg-canvas",
4395
4713
  style: {
@@ -4414,17 +4732,19 @@ function LayerGraph(p) {
4414
4732
  width: W,
4415
4733
  height: H,
4416
4734
  viewBox: `0 0 ${W} ${H}`,
4735
+ role: "group",
4736
+ "aria-label": tr("關係"),
4417
4737
  children: hitPaths
4418
4738
  }) : null
4419
4739
  ]
4420
4740
  })
4421
4741
  })
4422
4742
  }),
4423
- /* @__PURE__ */ jsx(ScrollHint, {
4743
+ showList ? null : /* @__PURE__ */ jsx(ScrollHint, {
4424
4744
  show: overflows,
4425
4745
  done: scrolled
4426
4746
  }),
4427
- shared.length ? /* @__PURE__ */ jsxs("div", {
4747
+ shared.length && !showList ? /* @__PURE__ */ jsxs("div", {
4428
4748
  className: "ui-lg-shared",
4429
4749
  children: [/* @__PURE__ */ jsx("div", {
4430
4750
  className: "ui-lg-shared-title",
@@ -4434,7 +4754,7 @@ function LayerGraph(p) {
4434
4754
  children: sharedBoxes
4435
4755
  })]
4436
4756
  }) : null,
4437
- p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [...edges.some((e) => !e.inferred && pos[e.from] && pos[e.to]) ? [{
4757
+ showList || p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [...edges.some((e) => !e.inferred && pos[e.from] && pos[e.to]) ? [{
4438
4758
  type: "weight",
4439
4759
  label: "次數越多線越粗"
4440
4760
  }] : [], ...edges.some((e) => e.inferred && pos[e.from] && pos[e.to]) ? [{
@@ -5600,6 +5920,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5600
5920
  if (controlled == null) setInner(n);
5601
5921
  };
5602
5922
  const end = (why) => onClose?.(why);
5923
+ useReturnFocus(open);
5603
5924
  const target = step?.target;
5604
5925
  const pad = step?.padding ?? 6;
5605
5926
  const hasStep = !!step;
@@ -5705,12 +6026,21 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
5705
6026
  children: [/* @__PURE__ */ jsxs("div", {
5706
6027
  className: "ui-tour-body",
5707
6028
  children: [
5708
- /* @__PURE__ */ jsx("div", {
6029
+ /* @__PURE__ */ jsxs("div", {
5709
6030
  className: "ui-tour-count",
5710
- children: monoNums(tr("{n} / {total}", {
5711
- n: "",
5712
- total: ""
5713
- }), [i + 1, steps.length])
6031
+ children: [/* @__PURE__ */ jsx("span", {
6032
+ "aria-hidden": "true",
6033
+ children: monoNums(tr("{n} / {total}", {
6034
+ n: "",
6035
+ total: ""
6036
+ }), [i + 1, steps.length])
6037
+ }), /* @__PURE__ */ jsx("span", {
6038
+ className: "ui-visually-hidden",
6039
+ children: tr("第 {a} 步,共 {b} 步", {
6040
+ a: i + 1,
6041
+ b: steps.length
6042
+ })
6043
+ })]
5714
6044
  }),
5715
6045
  /* @__PURE__ */ jsx(Popover$1.Title, {
5716
6046
  className: "ui-tour-title",
@@ -5915,6 +6245,7 @@ function TreeList(p) {
5915
6245
  if (!p.selected) setOwnSel(v);
5916
6246
  p.onSelectChange?.(v);
5917
6247
  };
6248
+ const uid = React.useId().replace(/:/g, "");
5918
6249
  const [focusId, setFocusId] = React.useState(null);
5919
6250
  const refs = React.useRef({});
5920
6251
  const want = React.useRef(null);
@@ -5943,6 +6274,8 @@ function TreeList(p) {
5943
6274
  if (will) load(n);
5944
6275
  p.onToggle?.(n, will, Object.keys(o).filter((k) => o[k]));
5945
6276
  if (!p.open) setOwnOpen(o);
6277
+ const c = will ? kids(n) : null;
6278
+ announce(will ? c ? tr("已展開,{n} 個子項目", { n: c.length }) : tr("已展開") : tr("已收合"));
5946
6279
  };
5947
6280
  const checkState = (n) => {
5948
6281
  const fl = filesUnder(n);
@@ -6044,6 +6377,7 @@ function TreeList(p) {
6044
6377
  "aria-posinset": r.pos,
6045
6378
  "aria-setsize": r.size,
6046
6379
  "aria-expanded": r.isF ? r.open : void 0,
6380
+ "aria-owns": r.isF && r.open ? `${uid}-g-${r.n.id}` : void 0,
6047
6381
  style: vars({ "--d": r.depth }),
6048
6382
  onFocus: () => focusId !== r.n.id && setFocusId(r.n.id)
6049
6383
  });
@@ -6053,6 +6387,11 @@ function TreeList(p) {
6053
6387
  const meta = n.meta ?? (n.path ? format.path(n.path) : "");
6054
6388
  return /* @__PURE__ */ jsxs("div", {
6055
6389
  ...itemProps(r, idx),
6390
+ "aria-label": [
6391
+ n.name,
6392
+ n.meta,
6393
+ n.path
6394
+ ].filter(Boolean).join(","),
6056
6395
  "aria-selected": p.onSelect ? on : void 0,
6057
6396
  className: cx("ui-tree-row", "is-plain", on && "is-current", n.muted && "is-muted", r.fresh && "ui-tree-in"),
6058
6397
  onClick: () => {
@@ -6066,7 +6405,7 @@ function TreeList(p) {
6066
6405
  type: "button",
6067
6406
  tabIndex: -1,
6068
6407
  className: cx("ui-tree-caret", "ui-tree-caretbtn", r.open && "is-open", !isF && "is-leaf"),
6069
- "aria-label": `${r.open ? tr("收合") : tr("展開")} ${n.name}`,
6408
+ "aria-hidden": "true",
6070
6409
  onClick: (e) => {
6071
6410
  e.stopPropagation();
6072
6411
  if (isF) toggle(n);
@@ -6334,6 +6673,27 @@ function TreeList(p) {
6334
6673
  }) : null, p.actions ?? null]
6335
6674
  })]
6336
6675
  }) : null;
6676
+ const render1 = (r) => r.x ? extraRow(r) : plain ? plainRow(r, rows.indexOf(r)) : fileRow(r, rows.indexOf(r));
6677
+ const nest = (start, depth) => {
6678
+ const out = [];
6679
+ let i = start;
6680
+ while (i < every.length && every[i].depth >= depth) {
6681
+ const r = every[i];
6682
+ out.push(render1(r));
6683
+ i++;
6684
+ if (!r.x && r.open && i < every.length && every[i].depth > depth) {
6685
+ const [kidsOut, next] = nest(i, depth + 1);
6686
+ out.push(/* @__PURE__ */ jsx("div", {
6687
+ id: `${uid}-g-${r.n.id}`,
6688
+ role: "group",
6689
+ className: "ui-tree-group",
6690
+ children: kidsOut
6691
+ }, "g-" + r.n.id));
6692
+ i = next;
6693
+ }
6694
+ }
6695
+ return [out, i];
6696
+ };
6337
6697
  return /* @__PURE__ */ jsxs("section", {
6338
6698
  className: cx("ui-tree", plain && "is-plain", selectable && "is-selectable", selFiles.length && "has-sel", p.bare && "is-bare", p.height != null && "has-height", p.className),
6339
6699
  "aria-label": p.title ? void 0 : p.label,
@@ -6344,13 +6704,13 @@ function TreeList(p) {
6344
6704
  "aria-multiselectable": selectable || void 0,
6345
6705
  className: "ui-tree-list",
6346
6706
  onKeyDown: onKey,
6347
- children: every.map((r) => r.x ? extraRow(r) : plain ? plainRow(r, rows.indexOf(r)) : fileRow(r, rows.indexOf(r)))
6707
+ children: nest(0, 0)[0]
6348
6708
  }) : /* @__PURE__ */ jsx("p", {
6349
6709
  className: "ui-tree-empty",
6350
6710
  children: p.emptyText || (plain ? tr("沒有項目") : tr("這裡還沒有檔案"))
6351
6711
  })]
6352
6712
  });
6353
6713
  }
6354
- export { AccentPicker, ActionBar, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, addMessages, format, icons, initTheme, isCodeRef, setAccent, setLocale, setTheme, tr as t, useTour };
6714
+ export { AccentPicker, ActionBar, Alert, AppShell, Badge, BarChart, Breadcrumb, Button, Calendar, Card, Checkbox, CodeText, CodeView, CommandPalette, DangerZone, DataTable, DatePicker, DateRangePicker, DetailList, Dialog, Drawer, EmptyState, ErrorPage, FileUpload, FormGrid, GraphDefs, GraphLegend, Grid, Icon, IconButton, InlineCode, KpiCard, LayerGraph, LineChart, LoadingBar, LoginCard, MOTION, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, addMessages, announce, focusMain, format, icons, initTheme, isCodeRef, setAccent, setLocale, setTheme, tr as t, useTour };
6355
6715
 
6356
6716
  //# sourceMappingURL=index.js.map