@seanyeh77/ui 0.6.1 → 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/bundle.js +9 -9
- package/dist/bundle.js.map +1 -1
- package/dist/{format-entry-CDWxD999.js → format-entry-B2xJlA9l.js} +18 -1
- package/dist/format-entry-B2xJlA9l.js.map +1 -0
- package/dist/format.js +1 -1
- package/dist/index.d.ts +34 -6
- package/dist/index.js +462 -100
- package/dist/index.js.map +1 -1
- package/dist/styles.css +109 -1
- package/docs/ActionBar.md +4 -0
- package/docs/AppShell.md +9 -2
- package/docs/CodeView.md +5 -0
- package/docs/CommandPalette.md +5 -0
- package/docs/DataTable.md +4 -0
- package/docs/Drawer.md +1 -0
- package/docs/LayerGraph.md +4 -1
- package/docs/Tabs.md +5 -0
- package/docs/Term.md +2 -0
- package/docs/Tooltip.md +1 -0
- package/docs/TopBar.md +1 -0
- package/docs/Tour.md +5 -0
- package/docs/TreeList.md +6 -0
- package/docs/guidelines.md +10 -1
- package/docs/layout.md +1 -1
- package/package.json +2 -2
- package/dist/format-entry-CDWxD999.js.map +0 -1
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-
|
|
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
|
|
@@ -843,7 +905,7 @@ function Dialog(props) {
|
|
|
843
905
|
}
|
|
844
906
|
// src/components/Drawer/Drawer.tsx
|
|
845
907
|
/** A 400 px panel from the right for editing one item without leaving the page. */
|
|
846
|
-
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 }) {
|
|
847
909
|
const [asking, setAsking] = React.useState(false);
|
|
848
910
|
const request = () => dirty ? setAsking(true) : onClose();
|
|
849
911
|
const panel = React.useRef(null);
|
|
@@ -854,7 +916,7 @@ function Drawer({ open, onClose, title, actions, dirty, width, confirmTitle, con
|
|
|
854
916
|
children: /* @__PURE__ */ jsxs(Dialog$1.Portal, { children: [/* @__PURE__ */ jsx(Dialog$1.Backdrop, { className: "ui-drawer-backdrop" }), /* @__PURE__ */ jsxs(Dialog$1.Popup, {
|
|
855
917
|
ref: panel,
|
|
856
918
|
initialFocus: firstField,
|
|
857
|
-
className: "ui-drawer",
|
|
919
|
+
className: side === "left" ? "ui-drawer is-left" : "ui-drawer",
|
|
858
920
|
style: width ? { width } : void 0,
|
|
859
921
|
children: [
|
|
860
922
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -895,16 +957,28 @@ function Drawer({ open, onClose, title, actions, dirty, width, confirmTitle, con
|
|
|
895
957
|
})] })
|
|
896
958
|
});
|
|
897
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
|
+
}
|
|
898
971
|
// src/components/AppShell/AppShell.tsx
|
|
899
972
|
const COLLAPSE_KEY = "ui-nav-collapsed";
|
|
900
973
|
const MORE = "\0more";
|
|
901
|
-
/** The dashboard frame: sidebar (240 px, 72 px collapsed
|
|
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.
|
|
902
976
|
* The top bar hides while scrolling down and returns when scrolling up. */
|
|
903
977
|
function AppShell({ nav, value, onNavigate, brand, title, breadcrumb, onSearch, actions, children, className }) {
|
|
904
978
|
const phone = useNarrow();
|
|
905
|
-
const tablet = useMedia("(min-width: 600px) and (max-width:
|
|
979
|
+
const tablet = useMedia("(min-width: 600px) and (max-width: 1024px)");
|
|
906
980
|
const [userCollapsed, setUserCollapsed] = React.useState(() => store(COLLAPSE_KEY) === "1");
|
|
907
|
-
const collapsed =
|
|
981
|
+
const collapsed = userCollapsed;
|
|
908
982
|
const top = nav.flatMap((s) => s.items);
|
|
909
983
|
const parentOf = (id) => top.find((it) => it.children?.some((c) => c.id === id));
|
|
910
984
|
const withIcon = top.filter((it) => !!it.icon);
|
|
@@ -943,54 +1017,73 @@ function AppShell({ nav, value, onNavigate, brand, title, breadcrumb, onSearch,
|
|
|
943
1017
|
el.addEventListener("scroll", onScroll, { passive: true });
|
|
944
1018
|
return () => el.removeEventListener("scroll", onScroll);
|
|
945
1019
|
}, []);
|
|
1020
|
+
React.useEffect(() => {
|
|
1021
|
+
ensureAnnouncer();
|
|
1022
|
+
}, []);
|
|
946
1023
|
return /* @__PURE__ */ jsxs("div", {
|
|
947
1024
|
className: cx("ui-shell", phone && "is-phone", className),
|
|
948
|
-
children: [
|
|
949
|
-
|
|
950
|
-
|
|
951
|
-
|
|
952
|
-
|
|
953
|
-
|
|
954
|
-
|
|
955
|
-
|
|
956
|
-
|
|
957
|
-
}
|
|
958
|
-
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
|
|
965
|
-
|
|
966
|
-
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
|
|
973
|
-
|
|
974
|
-
|
|
975
|
-
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
|
|
979
|
-
|
|
980
|
-
|
|
981
|
-
|
|
982
|
-
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
986
|
-
|
|
987
|
-
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
})
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
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
|
+
]
|
|
994
1087
|
});
|
|
995
1088
|
}
|
|
996
1089
|
// src/components/Grid/Grid.tsx
|
|
@@ -1091,6 +1184,7 @@ let following = false;
|
|
|
1091
1184
|
/** Applies the stored theme and accent; call once when the page starts. */
|
|
1092
1185
|
function initTheme() {
|
|
1093
1186
|
setTheme(storedTheme());
|
|
1187
|
+
ensureAnnouncer();
|
|
1094
1188
|
if (following || typeof window.matchMedia !== "function") return;
|
|
1095
1189
|
following = true;
|
|
1096
1190
|
window.matchMedia("(prefers-color-scheme: dark)").addEventListener("change", () => {
|
|
@@ -1176,6 +1270,73 @@ function AccentPicker({ value, onChange, label, className }) {
|
|
|
1176
1270
|
})]
|
|
1177
1271
|
});
|
|
1178
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
|
+
}
|
|
1179
1340
|
// src/components/Menu/Menu.tsx
|
|
1180
1341
|
/** The ⋯ button and its list of actions. Danger items go last, in red, after a divider, and are confirmed. */
|
|
1181
1342
|
function Menu({ items, label, icon = "dots-three", align = "end", triggerClassName }) {
|
|
@@ -1243,6 +1404,8 @@ function Menu({ items, label, icon = "dots-three", align = "end", triggerClassNa
|
|
|
1243
1404
|
// src/components/ActionBar/ActionBar.tsx
|
|
1244
1405
|
/** A card's actions in a row. Under 600 px the primary one fills the width and the rest go into 「更多」. */
|
|
1245
1406
|
function ActionBar({ actions, className }) {
|
|
1407
|
+
const box = React.useRef(null);
|
|
1408
|
+
useFocusRescue(box);
|
|
1246
1409
|
const main = actions.find((a) => a.primary) ?? actions.find((a) => !a.danger);
|
|
1247
1410
|
const others = actions.filter((a) => a !== main);
|
|
1248
1411
|
const button = (a, i, wide) => a.danger ? /* @__PURE__ */ jsx(Button, {
|
|
@@ -1274,6 +1437,7 @@ function ActionBar({ actions, className }) {
|
|
|
1274
1437
|
disabled: a.disabled
|
|
1275
1438
|
});
|
|
1276
1439
|
return /* @__PURE__ */ jsxs("div", {
|
|
1440
|
+
ref: box,
|
|
1277
1441
|
className: cx("ui-actbar", className),
|
|
1278
1442
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1279
1443
|
className: "ui-actbar-wide",
|
|
@@ -1856,7 +2020,7 @@ function breakable(text) {
|
|
|
1856
2020
|
return out;
|
|
1857
2021
|
}
|
|
1858
2022
|
/** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
|
|
1859
|
-
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 }) {
|
|
1860
2024
|
const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
|
|
1861
2025
|
const lang = language || languageOf(file);
|
|
1862
2026
|
const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
|
|
@@ -1886,6 +2050,7 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
1886
2050
|
const from = windowed ? Math.max(0, ta - start - context) : 0;
|
|
1887
2051
|
const to = windowed ? Math.min(lines.length, tb - start + context + 1) : lines.length;
|
|
1888
2052
|
const body = React.useRef(null);
|
|
2053
|
+
React.useImperativeHandle(ref, () => ({ focusTarget: () => body.current?.querySelector(".is-target")?.focus() }));
|
|
1889
2054
|
React.useEffect(() => {
|
|
1890
2055
|
const b = body.current;
|
|
1891
2056
|
const el = b?.querySelector(".is-target");
|
|
@@ -1897,18 +2062,24 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
1897
2062
|
const n = start + i;
|
|
1898
2063
|
const on = ta != null && tb != null && n >= ta && n <= tb;
|
|
1899
2064
|
rows.push(/* @__PURE__ */ jsxs("div", {
|
|
2065
|
+
role: "listitem",
|
|
1900
2066
|
className: cx("ui-cv-line", on && "is-target"),
|
|
1901
2067
|
"aria-current": on && n === ta ? "location" : void 0,
|
|
2068
|
+
tabIndex: on && n === ta ? -1 : void 0,
|
|
1902
2069
|
children: [/* @__PURE__ */ jsx("span", {
|
|
1903
2070
|
className: "ui-cv-num",
|
|
1904
2071
|
style: { width: digits + 2 + "ch" },
|
|
2072
|
+
"aria-hidden": "true",
|
|
1905
2073
|
children: n
|
|
1906
|
-
}), /* @__PURE__ */
|
|
2074
|
+
}), /* @__PURE__ */ jsxs("span", {
|
|
1907
2075
|
className: "ui-cv-text",
|
|
1908
|
-
children:
|
|
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", {
|
|
1909
2080
|
className: cls,
|
|
1910
2081
|
children: breakable(text)
|
|
1911
|
-
}, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))
|
|
2082
|
+
}, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))]
|
|
1912
2083
|
})]
|
|
1913
2084
|
}, i));
|
|
1914
2085
|
}
|
|
@@ -1944,7 +2115,11 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
1944
2115
|
className: "ui-cv-body",
|
|
1945
2116
|
style: maxHeight ? { maxHeight } : void 0,
|
|
1946
2117
|
tabIndex: 0,
|
|
1947
|
-
|
|
2118
|
+
"aria-label": tr("程式碼"),
|
|
2119
|
+
children: /* @__PURE__ */ jsx("code", {
|
|
2120
|
+
role: "list",
|
|
2121
|
+
children: rows
|
|
2122
|
+
})
|
|
1948
2123
|
}),
|
|
1949
2124
|
narrow && canWindow ? /* @__PURE__ */ jsx("button", {
|
|
1950
2125
|
type: "button",
|
|
@@ -1978,6 +2153,7 @@ function CommandPalette(props) {
|
|
|
1978
2153
|
const { open, onOpenChange, items, onSelect, placeholder, recent, recentLabel, emptyText, kinds, filter = true, onQueryChange, loading, limit = 50, hotkey = true, defaultQuery = "", label } = props;
|
|
1979
2154
|
const [q, setQ] = React.useState(defaultQuery);
|
|
1980
2155
|
const [active, setActive] = React.useState(0);
|
|
2156
|
+
useReturnFocus(open);
|
|
1981
2157
|
const [wasOpen, setWasOpen] = React.useState(open);
|
|
1982
2158
|
if (open !== wasOpen) {
|
|
1983
2159
|
setWasOpen(open);
|
|
@@ -2058,6 +2234,12 @@ function CommandPalette(props) {
|
|
|
2058
2234
|
});
|
|
2059
2235
|
};
|
|
2060
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]);
|
|
2061
2243
|
return /* @__PURE__ */ jsx(Dialog$1.Root, {
|
|
2062
2244
|
open,
|
|
2063
2245
|
onOpenChange,
|
|
@@ -2139,7 +2321,6 @@ function CommandPalette(props) {
|
|
|
2139
2321
|
}, it.id ?? i))
|
|
2140
2322
|
}) : /* @__PURE__ */ jsx("p", {
|
|
2141
2323
|
className: "ui-pal-empty",
|
|
2142
|
-
role: "status",
|
|
2143
2324
|
children: loading ? tr("搜尋中") : empty
|
|
2144
2325
|
}),
|
|
2145
2326
|
/* @__PURE__ */ jsxs("div", {
|
|
@@ -2219,6 +2400,7 @@ function Tabs({ items, value, onChange, label, unit, className }) {
|
|
|
2219
2400
|
const [box, setBox] = React.useState(null);
|
|
2220
2401
|
const [forward, setForward] = React.useState(true);
|
|
2221
2402
|
const [moving, bump] = useMoving();
|
|
2403
|
+
useFocusRescue(track, () => refs.current[Math.max(0, items.findIndex((t) => t.id === value))]);
|
|
2222
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.");
|
|
2223
2405
|
const idx = Math.max(0, items.findIndex((t) => t.id === value));
|
|
2224
2406
|
React.useLayoutEffect(() => {
|
|
@@ -2240,6 +2422,7 @@ function Tabs({ items, value, onChange, label, unit, className }) {
|
|
|
2240
2422
|
setForward(i > idx);
|
|
2241
2423
|
bump();
|
|
2242
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 || "") : "") : ""));
|
|
2243
2426
|
};
|
|
2244
2427
|
return /* @__PURE__ */ jsxs("div", {
|
|
2245
2428
|
ref: track,
|
|
@@ -2272,13 +2455,17 @@ function Tabs({ items, value, onChange, label, unit, className }) {
|
|
|
2272
2455
|
refs.current[to]?.focus();
|
|
2273
2456
|
go(to);
|
|
2274
2457
|
},
|
|
2275
|
-
children: [
|
|
2276
|
-
|
|
2277
|
-
|
|
2278
|
-
|
|
2279
|
-
|
|
2280
|
-
|
|
2281
|
-
|
|
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
|
+
]
|
|
2282
2469
|
}, t.id))]
|
|
2283
2470
|
});
|
|
2284
2471
|
}
|
|
@@ -2794,6 +2981,15 @@ function DataTable(p) {
|
|
|
2794
2981
|
return (typeof x === "number" && typeof y === "number" ? x - y : String(x).localeCompare(String(y), "zh-Hant")) * d || a.i - b.i;
|
|
2795
2982
|
});
|
|
2796
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]);
|
|
2797
2993
|
const pages = Math.max(1, Math.ceil(list.length / pageSize));
|
|
2798
2994
|
const pageNow = Math.min(page, pages - 1);
|
|
2799
2995
|
const start = pageNow * pageSize;
|
|
@@ -3079,10 +3275,14 @@ function DataTable(p) {
|
|
|
3079
3275
|
},
|
|
3080
3276
|
children: [v.label, /* @__PURE__ */ jsxs("span", {
|
|
3081
3277
|
className: "ui-dt-view-n",
|
|
3082
|
-
children: [
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
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
|
+
]
|
|
3086
3286
|
})]
|
|
3087
3287
|
}, v.id);
|
|
3088
3288
|
})
|
|
@@ -3684,15 +3884,15 @@ function Term({ children, title, text, content, code, action, refHref, onRef, is
|
|
|
3684
3884
|
ref,
|
|
3685
3885
|
className: cx("ui-term", inline && "is-inline", open && "is-open", className),
|
|
3686
3886
|
children: [
|
|
3887
|
+
/* @__PURE__ */ jsx("span", {
|
|
3888
|
+
className: "ui-visually-hidden",
|
|
3889
|
+
children: tr("說明") + " "
|
|
3890
|
+
}),
|
|
3687
3891
|
children,
|
|
3688
3892
|
/* @__PURE__ */ jsx(Icon, {
|
|
3689
3893
|
name: "question",
|
|
3690
3894
|
size: 14,
|
|
3691
3895
|
className: "ui-term-q"
|
|
3692
|
-
}),
|
|
3693
|
-
/* @__PURE__ */ jsx("span", {
|
|
3694
|
-
className: "ui-visually-hidden",
|
|
3695
|
-
children: tr("(說明)")
|
|
3696
3896
|
})
|
|
3697
3897
|
]
|
|
3698
3898
|
});
|
|
@@ -3924,6 +4124,7 @@ function KpiCard(props) {
|
|
|
3924
4124
|
});
|
|
3925
4125
|
}
|
|
3926
4126
|
// src/components/LayerGraph/LayerGraph.tsx
|
|
4127
|
+
const scrollMemory = /* @__PURE__ */ new Map();
|
|
3927
4128
|
let measure;
|
|
3928
4129
|
const SPLIT = /(`[^`]+`|\d[\d,.]*)/;
|
|
3929
4130
|
function labelWidth(text) {
|
|
@@ -4044,6 +4245,23 @@ function LayerGraph(p) {
|
|
|
4044
4245
|
const pickEdge = p.onSelectEdge;
|
|
4045
4246
|
const [hover, setHover] = React.useState(null);
|
|
4046
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
|
+
};
|
|
4047
4265
|
const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
|
|
4048
4266
|
const uses = {};
|
|
4049
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);
|
|
@@ -4057,10 +4275,9 @@ function LayerGraph(p) {
|
|
|
4057
4275
|
};
|
|
4058
4276
|
const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
|
|
4059
4277
|
const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
|
|
4060
|
-
const upW = (list) => Math.max(0, ...list.map((e) => Math.ceil(Math.max(labelWidth(e.inferred ? e.label || p.inferredLabel || tr("推測") : ""), labelWidth(countText(e))))));
|
|
4061
4278
|
if (upsL.length) {
|
|
4062
4279
|
const left0 = Math.min(...main.map((n) => pos[n.id].x));
|
|
4063
|
-
const shift = Math.max(0, PAD +
|
|
4280
|
+
const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
|
|
4064
4281
|
for (const id in pos) pos[id] = {
|
|
4065
4282
|
x: pos[id].x + shift,
|
|
4066
4283
|
y: pos[id].y
|
|
@@ -4070,9 +4287,9 @@ function LayerGraph(p) {
|
|
|
4070
4287
|
const boxesLeft = Math.min(...main.map((n) => pos[n.id].x));
|
|
4071
4288
|
const boxesRight = Math.max(0, ...main.map((n) => pos[n.id].x + NW));
|
|
4072
4289
|
const laneX = (e) => onLeft(e) ? boxesLeft - LANE - upsL.indexOf(e) * LANE_STEP : boxesRight + LANE + upsR.indexOf(e) * LANE_STEP;
|
|
4073
|
-
const upLabelX =
|
|
4074
|
-
const upLabelEndL =
|
|
4075
|
-
if (upsR.length) W = Math.max(W,
|
|
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);
|
|
4076
4293
|
const choose = (e) => {
|
|
4077
4294
|
const id = edgeId(e);
|
|
4078
4295
|
const next = p.selectedEdge === id ? null : id;
|
|
@@ -4083,6 +4300,7 @@ function LayerGraph(p) {
|
|
|
4083
4300
|
const labels = [];
|
|
4084
4301
|
const marks = [];
|
|
4085
4302
|
const runs = [];
|
|
4303
|
+
const segs = [];
|
|
4086
4304
|
const arrows = [];
|
|
4087
4305
|
const hitPaths = [];
|
|
4088
4306
|
edges.forEach((e, idx) => {
|
|
@@ -4177,9 +4395,9 @@ function LayerGraph(p) {
|
|
|
4177
4395
|
idx,
|
|
4178
4396
|
e,
|
|
4179
4397
|
text,
|
|
4180
|
-
tx: L ?
|
|
4398
|
+
tx: L ? upLabelX : upLabelEndL,
|
|
4181
4399
|
ty: Math.round((y0 + y1) / 2),
|
|
4182
|
-
left: L,
|
|
4400
|
+
left: !L,
|
|
4183
4401
|
r,
|
|
4184
4402
|
dim,
|
|
4185
4403
|
up: true
|
|
@@ -4225,7 +4443,21 @@ function LayerGraph(p) {
|
|
|
4225
4443
|
]);
|
|
4226
4444
|
}
|
|
4227
4445
|
const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
|
|
4228
|
-
const
|
|
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);
|
|
4229
4461
|
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4230
4462
|
className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
|
|
4231
4463
|
d,
|
|
@@ -4271,8 +4503,15 @@ function LayerGraph(p) {
|
|
|
4271
4503
|
}
|
|
4272
4504
|
});
|
|
4273
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
|
+
]);
|
|
4274
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);
|
|
4275
4513
|
const labelEl = (m, x0, top) => /* @__PURE__ */ jsx("span", {
|
|
4514
|
+
"aria-hidden": pickEdge ? true : void 0,
|
|
4276
4515
|
className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
|
|
4277
4516
|
style: {
|
|
4278
4517
|
left: x0,
|
|
@@ -4289,10 +4528,19 @@ function LayerGraph(p) {
|
|
|
4289
4528
|
marks.sort((m, n) => m.ty - n.ty || m.tx - n.tx).forEach((m) => {
|
|
4290
4529
|
const w = Math.ceil(labelWidth(m.text));
|
|
4291
4530
|
if (m.up) {
|
|
4292
|
-
const x0 = m.left ? m.tx - w : m.tx;
|
|
4293
|
-
|
|
4294
|
-
|
|
4295
|
-
|
|
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;
|
|
4296
4544
|
placed.push([
|
|
4297
4545
|
x0,
|
|
4298
4546
|
x0 + w,
|
|
@@ -4379,15 +4627,87 @@ function LayerGraph(p) {
|
|
|
4379
4627
|
})]
|
|
4380
4628
|
}, s.id);
|
|
4381
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";
|
|
4382
4686
|
return /* @__PURE__ */ jsxs("div", {
|
|
4383
4687
|
className: cx("ui-graph ui-lg", p.className),
|
|
4384
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,
|
|
4385
4705
|
/* @__PURE__ */ jsx("div", {
|
|
4386
|
-
className: cx("ui-lg-scroller", scrollMore && "has-more"),
|
|
4706
|
+
className: cx("ui-lg-scroller", scrollMore && "has-more", showList && "is-hidden"),
|
|
4387
4707
|
children: /* @__PURE__ */ jsx("div", {
|
|
4388
4708
|
className: "ui-lg-scroll",
|
|
4389
4709
|
ref: scrollRef,
|
|
4390
|
-
onScroll,
|
|
4710
|
+
onScroll: onScrollKeep,
|
|
4391
4711
|
children: /* @__PURE__ */ jsxs("div", {
|
|
4392
4712
|
className: "ui-lg-canvas",
|
|
4393
4713
|
style: {
|
|
@@ -4412,17 +4732,19 @@ function LayerGraph(p) {
|
|
|
4412
4732
|
width: W,
|
|
4413
4733
|
height: H,
|
|
4414
4734
|
viewBox: `0 0 ${W} ${H}`,
|
|
4735
|
+
role: "group",
|
|
4736
|
+
"aria-label": tr("關係"),
|
|
4415
4737
|
children: hitPaths
|
|
4416
4738
|
}) : null
|
|
4417
4739
|
]
|
|
4418
4740
|
})
|
|
4419
4741
|
})
|
|
4420
4742
|
}),
|
|
4421
|
-
/* @__PURE__ */ jsx(ScrollHint, {
|
|
4743
|
+
showList ? null : /* @__PURE__ */ jsx(ScrollHint, {
|
|
4422
4744
|
show: overflows,
|
|
4423
4745
|
done: scrolled
|
|
4424
4746
|
}),
|
|
4425
|
-
shared.length ? /* @__PURE__ */ jsxs("div", {
|
|
4747
|
+
shared.length && !showList ? /* @__PURE__ */ jsxs("div", {
|
|
4426
4748
|
className: "ui-lg-shared",
|
|
4427
4749
|
children: [/* @__PURE__ */ jsx("div", {
|
|
4428
4750
|
className: "ui-lg-shared-title",
|
|
@@ -4432,7 +4754,7 @@ function LayerGraph(p) {
|
|
|
4432
4754
|
children: sharedBoxes
|
|
4433
4755
|
})]
|
|
4434
4756
|
}) : null,
|
|
4435
|
-
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]) ? [{
|
|
4436
4758
|
type: "weight",
|
|
4437
4759
|
label: "次數越多線越粗"
|
|
4438
4760
|
}] : [], ...edges.some((e) => e.inferred && pos[e.from] && pos[e.to]) ? [{
|
|
@@ -5598,6 +5920,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
|
|
|
5598
5920
|
if (controlled == null) setInner(n);
|
|
5599
5921
|
};
|
|
5600
5922
|
const end = (why) => onClose?.(why);
|
|
5923
|
+
useReturnFocus(open);
|
|
5601
5924
|
const target = step?.target;
|
|
5602
5925
|
const pad = step?.padding ?? 6;
|
|
5603
5926
|
const hasStep = !!step;
|
|
@@ -5703,12 +6026,21 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
|
|
|
5703
6026
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
5704
6027
|
className: "ui-tour-body",
|
|
5705
6028
|
children: [
|
|
5706
|
-
/* @__PURE__ */
|
|
6029
|
+
/* @__PURE__ */ jsxs("div", {
|
|
5707
6030
|
className: "ui-tour-count",
|
|
5708
|
-
children:
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
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
|
+
})]
|
|
5712
6044
|
}),
|
|
5713
6045
|
/* @__PURE__ */ jsx(Popover$1.Title, {
|
|
5714
6046
|
className: "ui-tour-title",
|
|
@@ -5913,6 +6245,7 @@ function TreeList(p) {
|
|
|
5913
6245
|
if (!p.selected) setOwnSel(v);
|
|
5914
6246
|
p.onSelectChange?.(v);
|
|
5915
6247
|
};
|
|
6248
|
+
const uid = React.useId().replace(/:/g, "");
|
|
5916
6249
|
const [focusId, setFocusId] = React.useState(null);
|
|
5917
6250
|
const refs = React.useRef({});
|
|
5918
6251
|
const want = React.useRef(null);
|
|
@@ -5941,6 +6274,8 @@ function TreeList(p) {
|
|
|
5941
6274
|
if (will) load(n);
|
|
5942
6275
|
p.onToggle?.(n, will, Object.keys(o).filter((k) => o[k]));
|
|
5943
6276
|
if (!p.open) setOwnOpen(o);
|
|
6277
|
+
const c = will ? kids(n) : null;
|
|
6278
|
+
announce(will ? c ? tr("已展開,{n} 個子項目", { n: c.length }) : tr("已展開") : tr("已收合"));
|
|
5944
6279
|
};
|
|
5945
6280
|
const checkState = (n) => {
|
|
5946
6281
|
const fl = filesUnder(n);
|
|
@@ -6042,6 +6377,7 @@ function TreeList(p) {
|
|
|
6042
6377
|
"aria-posinset": r.pos,
|
|
6043
6378
|
"aria-setsize": r.size,
|
|
6044
6379
|
"aria-expanded": r.isF ? r.open : void 0,
|
|
6380
|
+
"aria-owns": r.isF && r.open ? `${uid}-g-${r.n.id}` : void 0,
|
|
6045
6381
|
style: vars({ "--d": r.depth }),
|
|
6046
6382
|
onFocus: () => focusId !== r.n.id && setFocusId(r.n.id)
|
|
6047
6383
|
});
|
|
@@ -6051,6 +6387,11 @@ function TreeList(p) {
|
|
|
6051
6387
|
const meta = n.meta ?? (n.path ? format.path(n.path) : "");
|
|
6052
6388
|
return /* @__PURE__ */ jsxs("div", {
|
|
6053
6389
|
...itemProps(r, idx),
|
|
6390
|
+
"aria-label": [
|
|
6391
|
+
n.name,
|
|
6392
|
+
n.meta,
|
|
6393
|
+
n.path
|
|
6394
|
+
].filter(Boolean).join(","),
|
|
6054
6395
|
"aria-selected": p.onSelect ? on : void 0,
|
|
6055
6396
|
className: cx("ui-tree-row", "is-plain", on && "is-current", n.muted && "is-muted", r.fresh && "ui-tree-in"),
|
|
6056
6397
|
onClick: () => {
|
|
@@ -6064,7 +6405,7 @@ function TreeList(p) {
|
|
|
6064
6405
|
type: "button",
|
|
6065
6406
|
tabIndex: -1,
|
|
6066
6407
|
className: cx("ui-tree-caret", "ui-tree-caretbtn", r.open && "is-open", !isF && "is-leaf"),
|
|
6067
|
-
"aria-
|
|
6408
|
+
"aria-hidden": "true",
|
|
6068
6409
|
onClick: (e) => {
|
|
6069
6410
|
e.stopPropagation();
|
|
6070
6411
|
if (isF) toggle(n);
|
|
@@ -6332,6 +6673,27 @@ function TreeList(p) {
|
|
|
6332
6673
|
}) : null, p.actions ?? null]
|
|
6333
6674
|
})]
|
|
6334
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
|
+
};
|
|
6335
6697
|
return /* @__PURE__ */ jsxs("section", {
|
|
6336
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),
|
|
6337
6699
|
"aria-label": p.title ? void 0 : p.label,
|
|
@@ -6342,13 +6704,13 @@ function TreeList(p) {
|
|
|
6342
6704
|
"aria-multiselectable": selectable || void 0,
|
|
6343
6705
|
className: "ui-tree-list",
|
|
6344
6706
|
onKeyDown: onKey,
|
|
6345
|
-
children:
|
|
6707
|
+
children: nest(0, 0)[0]
|
|
6346
6708
|
}) : /* @__PURE__ */ jsx("p", {
|
|
6347
6709
|
className: "ui-tree-empty",
|
|
6348
6710
|
children: p.emptyText || (plain ? tr("沒有項目") : tr("這裡還沒有檔案"))
|
|
6349
6711
|
})]
|
|
6350
6712
|
});
|
|
6351
6713
|
}
|
|
6352
|
-
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 };
|
|
6353
6715
|
|
|
6354
6716
|
//# sourceMappingURL=index.js.map
|