@seanyeh77/ui 0.6.1 → 0.7.1
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 +817 -312
- 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 +6 -2
- 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) {
|
|
@@ -3940,6 +4141,50 @@ function labelWidth(text) {
|
|
|
3940
4141
|
return w + c.measureText(t[0] === "`" ? t.slice(1, -1) : t).width;
|
|
3941
4142
|
}, 0);
|
|
3942
4143
|
}
|
|
4144
|
+
const GROW = 24;
|
|
4145
|
+
const GROW_MAX = 144;
|
|
4146
|
+
/** The label on 1 line, then wrapped onto 2, 3 and 4 lines as evenly as it goes. Breaks between Chinese characters
|
|
4147
|
+
* and at spaces; never inside `code`, a word or a number, between a number and the word after it, before a closing
|
|
4148
|
+
* mark or after an opening one. */
|
|
4149
|
+
function wraps(text) {
|
|
4150
|
+
const atoms = [];
|
|
4151
|
+
for (const t of text.match(/`[^`]+`|[A-Za-z0-9_./:#@-]+|\s+|[\s\S]/gu) ?? []) {
|
|
4152
|
+
const prev = atoms[atoms.length - 1];
|
|
4153
|
+
const unit = /\d\s*$/.test(prev ?? "") && !/^[A-Za-z0-9_]/.test(t);
|
|
4154
|
+
if (prev != null && (unit || /^[)」』、,。:;!?)\]]/.test(t) || /[(「『([]$/.test(prev))) atoms[atoms.length - 1] = prev + t;
|
|
4155
|
+
else atoms.push(t);
|
|
4156
|
+
}
|
|
4157
|
+
const fill = (max) => {
|
|
4158
|
+
const lines = [];
|
|
4159
|
+
let cur = "";
|
|
4160
|
+
for (const a of atoms) {
|
|
4161
|
+
if (/^\s+$/.test(a)) {
|
|
4162
|
+
if (cur) cur += a;
|
|
4163
|
+
continue;
|
|
4164
|
+
}
|
|
4165
|
+
if (cur && labelWidth(cur.trimEnd() + a) > max) {
|
|
4166
|
+
lines.push(cur.trimEnd());
|
|
4167
|
+
cur = a;
|
|
4168
|
+
} else cur += a;
|
|
4169
|
+
}
|
|
4170
|
+
if (cur.trim()) lines.push(cur.trimEnd());
|
|
4171
|
+
return lines;
|
|
4172
|
+
};
|
|
4173
|
+
const full = labelWidth(text);
|
|
4174
|
+
const out = [[text]];
|
|
4175
|
+
for (let n = 2; n <= 4; n++) {
|
|
4176
|
+
let lo = Math.max(...atoms.filter((a) => a.trim()).map(labelWidth)) - 1;
|
|
4177
|
+
let hi = full;
|
|
4178
|
+
while (hi - lo > 1) {
|
|
4179
|
+
const mid = (lo + hi) / 2;
|
|
4180
|
+
if (fill(mid).length <= n) hi = mid;
|
|
4181
|
+
else lo = mid;
|
|
4182
|
+
}
|
|
4183
|
+
const lines = fill(hi);
|
|
4184
|
+
if (lines.length > out[out.length - 1].length) out.push(lines);
|
|
4185
|
+
}
|
|
4186
|
+
return out;
|
|
4187
|
+
}
|
|
3943
4188
|
function labelParts(text) {
|
|
3944
4189
|
return text.split(SPLIT).filter(Boolean).map((t, i) => t[0] === "`" || /^\d/.test(t) ? /* @__PURE__ */ jsx("span", {
|
|
3945
4190
|
className: "ui-lg-code",
|
|
@@ -3998,7 +4243,8 @@ function LayerGraph(p) {
|
|
|
3998
4243
|
const layers = [...byLayer.keys()].sort((a, b) => a - b);
|
|
3999
4244
|
const cols = Math.max(1, ...layers.map((l) => byLayer.get(l)?.length ?? 0));
|
|
4000
4245
|
let W = 32 + cols * NW + (cols - 1) * COL;
|
|
4001
|
-
const
|
|
4246
|
+
const gaps = layers.map(() => GAP);
|
|
4247
|
+
let H = 0;
|
|
4002
4248
|
const pos = {};
|
|
4003
4249
|
const layerIndex = {};
|
|
4004
4250
|
layers.forEach((l, k) => {
|
|
@@ -4007,11 +4253,16 @@ function LayerGraph(p) {
|
|
|
4007
4253
|
row.forEach((n, i) => {
|
|
4008
4254
|
pos[n.id] = {
|
|
4009
4255
|
x: off + i * (NW + COL),
|
|
4010
|
-
y:
|
|
4256
|
+
y: 0
|
|
4011
4257
|
};
|
|
4012
4258
|
layerIndex[n.id] = k;
|
|
4013
4259
|
});
|
|
4014
4260
|
});
|
|
4261
|
+
const rowTop = (k) => PAD + k * NH + gaps.slice(0, k).reduce((a, b) => a + b, 0);
|
|
4262
|
+
const placeRows = () => {
|
|
4263
|
+
for (const id in pos) pos[id].y = rowTop(layerIndex[id]);
|
|
4264
|
+
H = rowTop(layers.length - 1) + NH + PAD;
|
|
4265
|
+
};
|
|
4015
4266
|
const maxSize = Math.max(1, ...main.map((n) => sizeOf(n) || 0));
|
|
4016
4267
|
const maxCount = Math.max(1, ...edges.map((e) => e.count || 0));
|
|
4017
4268
|
const isUp = (e) => !!pos[e.from] && !!pos[e.to] && layerIndex[e.to] < layerIndex[e.from];
|
|
@@ -4044,6 +4295,23 @@ function LayerGraph(p) {
|
|
|
4044
4295
|
const pickEdge = p.onSelectEdge;
|
|
4045
4296
|
const [hover, setHover] = React.useState(null);
|
|
4046
4297
|
const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
|
|
4298
|
+
const uid = React.useId().replace(/:/g, "");
|
|
4299
|
+
const [view, setView] = React.useState("graph");
|
|
4300
|
+
const memKey = p.scrollKey ?? all.map((n) => n.id).join("|");
|
|
4301
|
+
React.useLayoutEffect(() => {
|
|
4302
|
+
const el = scrollRef.current;
|
|
4303
|
+
const x = scrollMemory.get(memKey);
|
|
4304
|
+
if (el && x) el.scrollLeft = x;
|
|
4305
|
+
}, [
|
|
4306
|
+
memKey,
|
|
4307
|
+
view,
|
|
4308
|
+
scrollRef
|
|
4309
|
+
]);
|
|
4310
|
+
const onScrollKeep = () => {
|
|
4311
|
+
const el = scrollRef.current;
|
|
4312
|
+
if (el) scrollMemory.set(memKey, el.scrollLeft);
|
|
4313
|
+
onScroll();
|
|
4314
|
+
};
|
|
4047
4315
|
const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
|
|
4048
4316
|
const uses = {};
|
|
4049
4317
|
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 +4325,9 @@ function LayerGraph(p) {
|
|
|
4057
4325
|
};
|
|
4058
4326
|
const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
|
|
4059
4327
|
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
4328
|
if (upsL.length) {
|
|
4062
4329
|
const left0 = Math.min(...main.map((n) => pos[n.id].x));
|
|
4063
|
-
const shift = Math.max(0, PAD +
|
|
4330
|
+
const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
|
|
4064
4331
|
for (const id in pos) pos[id] = {
|
|
4065
4332
|
x: pos[id].x + shift,
|
|
4066
4333
|
y: pos[id].y
|
|
@@ -4070,255 +4337,379 @@ function LayerGraph(p) {
|
|
|
4070
4337
|
const boxesLeft = Math.min(...main.map((n) => pos[n.id].x));
|
|
4071
4338
|
const boxesRight = Math.max(0, ...main.map((n) => pos[n.id].x + NW));
|
|
4072
4339
|
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,
|
|
4340
|
+
const upLabelX = boxesLeft - LANE + 8;
|
|
4341
|
+
const upLabelEndL = boxesRight + LANE - 8;
|
|
4342
|
+
if (upsR.length) W = Math.max(W, boxesRight + LANE + (upsR.length - 1) * LANE_STEP + PAD);
|
|
4076
4343
|
const choose = (e) => {
|
|
4077
4344
|
const id = edgeId(e);
|
|
4078
4345
|
const next = p.selectedEdge === id ? null : id;
|
|
4079
4346
|
if (next && sel != null) p.onSelect?.(null);
|
|
4080
4347
|
pickEdge?.(next);
|
|
4081
4348
|
};
|
|
4082
|
-
const
|
|
4083
|
-
|
|
4084
|
-
|
|
4085
|
-
|
|
4086
|
-
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
const
|
|
4090
|
-
const
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4094
|
-
|
|
4095
|
-
|
|
4096
|
-
|
|
4097
|
-
|
|
4098
|
-
|
|
4099
|
-
|
|
4100
|
-
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4106
|
-
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4110
|
-
|
|
4111
|
-
|
|
4112
|
-
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
|
|
4117
|
-
|
|
4118
|
-
|
|
4119
|
-
|
|
4120
|
-
|
|
4121
|
-
|
|
4122
|
-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
[
|
|
4129
|
-
|
|
4130
|
-
|
|
4131
|
-
|
|
4132
|
-
|
|
4133
|
-
|
|
4134
|
-
|
|
4135
|
-
|
|
4136
|
-
|
|
4349
|
+
const draw = () => {
|
|
4350
|
+
const paths = [];
|
|
4351
|
+
const labels = [];
|
|
4352
|
+
const need = /* @__PURE__ */ new Set();
|
|
4353
|
+
const marks = [];
|
|
4354
|
+
const runs = [];
|
|
4355
|
+
const segs = [];
|
|
4356
|
+
const arrows = [];
|
|
4357
|
+
const hitPaths = [];
|
|
4358
|
+
edges.forEach((e, idx) => {
|
|
4359
|
+
const a = pos[e.from];
|
|
4360
|
+
const b = pos[e.to];
|
|
4361
|
+
if (!a || !b) return;
|
|
4362
|
+
const r = related(e);
|
|
4363
|
+
const dim = focus && !r;
|
|
4364
|
+
const picked = e === selEdge;
|
|
4365
|
+
const hovered = !!pickEdge && hover === edgeId(e) && !r;
|
|
4366
|
+
const up = isUp(e);
|
|
4367
|
+
let pts;
|
|
4368
|
+
let tx;
|
|
4369
|
+
let ty;
|
|
4370
|
+
let arrow;
|
|
4371
|
+
let inn = 1;
|
|
4372
|
+
if (up) {
|
|
4373
|
+
const lx = laneX(e);
|
|
4374
|
+
const L = onLeft(e);
|
|
4375
|
+
const si = upOut[e.from].indexOf(e);
|
|
4376
|
+
const sn = upOut[e.from].length;
|
|
4377
|
+
const ti = upIn[e.to].indexOf(e);
|
|
4378
|
+
const tn = upIn[e.to].length;
|
|
4379
|
+
const start = [];
|
|
4380
|
+
let y0;
|
|
4381
|
+
if (L ? leftmost(e.from) : rightmost(e.from)) {
|
|
4382
|
+
y0 = Math.round(a.y + NH / 2 + (si - (sn - 1) / 2) * 10);
|
|
4383
|
+
start.push([L ? a.x : a.x + NW, y0], [lx, y0]);
|
|
4384
|
+
} else {
|
|
4385
|
+
const px = L ? a.x + 20 + si * 10 : a.x + NW - 20 - si * 10;
|
|
4386
|
+
y0 = a.y - 12 - si * 6;
|
|
4387
|
+
start.push([px, a.y], [px, y0], [lx, y0]);
|
|
4388
|
+
}
|
|
4389
|
+
let y1;
|
|
4390
|
+
if (L || rightmost(e.to)) {
|
|
4391
|
+
y1 = Math.round(b.y + NH / 2 + (ti - (tn - 1) / 2) * 10);
|
|
4392
|
+
tx = L ? b.x : b.x + NW;
|
|
4393
|
+
ty = y1;
|
|
4394
|
+
const back = L ? tx - 9 : tx + 9;
|
|
4395
|
+
pts = [
|
|
4396
|
+
...start,
|
|
4397
|
+
[lx, y1],
|
|
4398
|
+
[back, y1]
|
|
4399
|
+
];
|
|
4400
|
+
arrow = `M${back} ${ty - 5} L${back} ${ty + 5} L${tx} ${ty} Z`;
|
|
4401
|
+
arrows.push([
|
|
4402
|
+
Math.min(tx, back),
|
|
4403
|
+
Math.max(tx, back),
|
|
4404
|
+
ty - 5,
|
|
4405
|
+
ty + 5
|
|
4406
|
+
]);
|
|
4407
|
+
runs.push([
|
|
4408
|
+
Math.min(tx, lx),
|
|
4409
|
+
Math.max(tx, lx),
|
|
4410
|
+
y1 - 3,
|
|
4411
|
+
y1 + 3
|
|
4412
|
+
]);
|
|
4413
|
+
} else {
|
|
4414
|
+
tx = b.x + NW - 20 - ti * 10;
|
|
4415
|
+
y1 = b.y + NH + 12 + ti * 6;
|
|
4416
|
+
ty = b.y + NH;
|
|
4417
|
+
pts = [
|
|
4418
|
+
...start,
|
|
4419
|
+
[lx, y1],
|
|
4420
|
+
[tx, y1],
|
|
4421
|
+
[tx, ty + 9]
|
|
4422
|
+
];
|
|
4423
|
+
arrow = `M${tx - 5} ${ty + 9} L${tx + 5} ${ty + 9} L${tx} ${ty} Z`;
|
|
4424
|
+
arrows.push([
|
|
4425
|
+
tx - 5,
|
|
4426
|
+
tx + 5,
|
|
4427
|
+
ty,
|
|
4428
|
+
ty + 9
|
|
4429
|
+
]);
|
|
4430
|
+
runs.push([
|
|
4431
|
+
tx,
|
|
4432
|
+
lx,
|
|
4433
|
+
y1 - 3,
|
|
4434
|
+
y1 + 3
|
|
4435
|
+
]);
|
|
4436
|
+
}
|
|
4437
|
+
const sx0 = start[start.length - 2][0];
|
|
4137
4438
|
runs.push([
|
|
4138
|
-
Math.min(
|
|
4139
|
-
Math.max(
|
|
4140
|
-
|
|
4141
|
-
|
|
4439
|
+
Math.min(sx0, lx),
|
|
4440
|
+
Math.max(sx0, lx),
|
|
4441
|
+
y0 - 3,
|
|
4442
|
+
y0 + 3
|
|
4142
4443
|
]);
|
|
4444
|
+
if (e.inferred || r) {
|
|
4445
|
+
const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
|
|
4446
|
+
marks.push({
|
|
4447
|
+
idx,
|
|
4448
|
+
e,
|
|
4449
|
+
text,
|
|
4450
|
+
tx: L ? upLabelX : upLabelEndL,
|
|
4451
|
+
ty: Math.round((y0 + y1) / 2),
|
|
4452
|
+
left: !L,
|
|
4453
|
+
r,
|
|
4454
|
+
dim,
|
|
4455
|
+
up: true
|
|
4456
|
+
});
|
|
4457
|
+
}
|
|
4143
4458
|
} else {
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
|
|
4149
|
-
|
|
4459
|
+
const oi = outs[e.from].indexOf(e);
|
|
4460
|
+
const on = outs[e.from].length;
|
|
4461
|
+
const ii = ins[e.to].indexOf(e);
|
|
4462
|
+
inn = ins[e.to].length;
|
|
4463
|
+
const sx = Math.round(a.x + NW * (oi + 1) / (on + 1));
|
|
4464
|
+
const sy = a.y + NH;
|
|
4465
|
+
tx = Math.round(b.x + NW * (ii + 1) / (inn + 1));
|
|
4466
|
+
ty = b.y;
|
|
4467
|
+
const off = (oi - (on - 1) / 2) * 6;
|
|
4468
|
+
const y1 = sy + gaps[layerIndex[e.from]] / 2 + off;
|
|
4469
|
+
if (layerIndex[e.to] - layerIndex[e.from] > 1) {
|
|
4470
|
+
const next = (byLayer.get(layers[layerIndex[e.from] + 1]) ?? []).map((n) => pos[n.id]);
|
|
4471
|
+
const mid = (sx + tx) / 2;
|
|
4472
|
+
const chans = [next[0].x - COL / 2, ...next.map((q) => q.x + NW + COL / 2)].map((c) => Math.max(PAD / 2, Math.min(W - PAD / 2, c)));
|
|
4473
|
+
const chx = chans.reduce((best, c) => Math.abs(c - mid) < Math.abs(best - mid) ? c : best, chans[0]) + off;
|
|
4474
|
+
const y2 = ty - gaps[layerIndex[e.to] - 1] / 2 + off;
|
|
4475
|
+
pts = [
|
|
4476
|
+
[sx, sy],
|
|
4477
|
+
[sx, y1],
|
|
4478
|
+
[chx, y1],
|
|
4479
|
+
[chx, y2],
|
|
4480
|
+
[tx, y2],
|
|
4481
|
+
[tx, ty - 8]
|
|
4482
|
+
];
|
|
4483
|
+
} else pts = [
|
|
4484
|
+
[sx, sy],
|
|
4485
|
+
[sx, y1],
|
|
4150
4486
|
[tx, y1],
|
|
4151
|
-
[tx, ty
|
|
4487
|
+
[tx, ty - 8]
|
|
4152
4488
|
];
|
|
4153
|
-
arrow = `M${tx - 5} ${ty
|
|
4489
|
+
arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
|
|
4154
4490
|
arrows.push([
|
|
4155
4491
|
tx - 5,
|
|
4156
4492
|
tx + 5,
|
|
4157
|
-
ty,
|
|
4158
|
-
ty
|
|
4159
|
-
]);
|
|
4160
|
-
runs.push([
|
|
4161
|
-
tx,
|
|
4162
|
-
lx,
|
|
4163
|
-
y1 - 3,
|
|
4164
|
-
y1 + 3
|
|
4493
|
+
ty - 9,
|
|
4494
|
+
ty
|
|
4165
4495
|
]);
|
|
4166
4496
|
}
|
|
4167
|
-
const
|
|
4168
|
-
|
|
4169
|
-
|
|
4170
|
-
|
|
4171
|
-
|
|
4172
|
-
|
|
4173
|
-
|
|
4174
|
-
|
|
4497
|
+
const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
|
|
4498
|
+
const cpts = clean(pts);
|
|
4499
|
+
for (let k = 1; k < cpts.length; k++) {
|
|
4500
|
+
const [ax, ay] = cpts[k - 1];
|
|
4501
|
+
const [bx, by] = cpts[k];
|
|
4502
|
+
segs.push({
|
|
4503
|
+
idx,
|
|
4504
|
+
box: [
|
|
4505
|
+
Math.min(ax, bx) - 3,
|
|
4506
|
+
Math.max(ax, bx) + 3,
|
|
4507
|
+
Math.min(ay, by) - 3,
|
|
4508
|
+
Math.max(ay, by) + 3
|
|
4509
|
+
]
|
|
4510
|
+
});
|
|
4511
|
+
}
|
|
4512
|
+
const d = route(cpts, 10);
|
|
4513
|
+
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4514
|
+
className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
|
|
4515
|
+
d,
|
|
4516
|
+
strokeWidth: w
|
|
4517
|
+
}, "p" + idx));
|
|
4518
|
+
if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
|
|
4519
|
+
className: "ui-lg-hit",
|
|
4520
|
+
"data-edge": edgeId(e),
|
|
4521
|
+
d,
|
|
4522
|
+
role: "button",
|
|
4523
|
+
tabIndex: 0,
|
|
4524
|
+
"aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
|
|
4525
|
+
"aria-pressed": picked,
|
|
4526
|
+
onClick: (ev) => {
|
|
4527
|
+
ev.stopPropagation();
|
|
4528
|
+
choose(e);
|
|
4529
|
+
},
|
|
4530
|
+
onPointerEnter: () => setHover(edgeId(e)),
|
|
4531
|
+
onPointerLeave: () => setHover(null),
|
|
4532
|
+
onKeyDown: (ev) => {
|
|
4533
|
+
if (ev.key === "Enter" || ev.key === " ") {
|
|
4534
|
+
ev.preventDefault();
|
|
4535
|
+
choose(e);
|
|
4536
|
+
} else if (ev.key === "Escape" && picked) pickEdge(null);
|
|
4537
|
+
}
|
|
4538
|
+
}, "h" + idx));
|
|
4539
|
+
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4540
|
+
className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
|
|
4541
|
+
d: arrow
|
|
4542
|
+
}, "a" + idx));
|
|
4543
|
+
if (!up && (e.inferred || r)) {
|
|
4175
4544
|
const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
|
|
4176
4545
|
marks.push({
|
|
4177
4546
|
idx,
|
|
4178
4547
|
e,
|
|
4179
4548
|
text,
|
|
4180
|
-
tx
|
|
4181
|
-
ty
|
|
4182
|
-
left:
|
|
4549
|
+
tx,
|
|
4550
|
+
ty,
|
|
4551
|
+
left: inn > 1 && tx < b.x + NW / 2,
|
|
4183
4552
|
r,
|
|
4184
|
-
dim
|
|
4185
|
-
up: true
|
|
4553
|
+
dim
|
|
4186
4554
|
});
|
|
4187
4555
|
}
|
|
4188
|
-
}
|
|
4189
|
-
|
|
4190
|
-
|
|
4191
|
-
|
|
4192
|
-
|
|
4193
|
-
|
|
4194
|
-
|
|
4195
|
-
|
|
4196
|
-
|
|
4197
|
-
|
|
4198
|
-
|
|
4199
|
-
|
|
4200
|
-
|
|
4201
|
-
|
|
4202
|
-
|
|
4203
|
-
|
|
4204
|
-
const y2 = ty - GAP / 2 + off;
|
|
4205
|
-
pts = [
|
|
4206
|
-
[sx, sy],
|
|
4207
|
-
[sx, y1],
|
|
4208
|
-
[chx, y1],
|
|
4209
|
-
[chx, y2],
|
|
4210
|
-
[tx, y2],
|
|
4211
|
-
[tx, ty - 8]
|
|
4212
|
-
];
|
|
4213
|
-
} else pts = [
|
|
4214
|
-
[sx, sy],
|
|
4215
|
-
[sx, y1],
|
|
4216
|
-
[tx, y1],
|
|
4217
|
-
[tx, ty - 8]
|
|
4218
|
-
];
|
|
4219
|
-
arrow = `M${tx - 5} ${ty - 9} L${tx + 5} ${ty - 9} L${tx} ${ty} Z`;
|
|
4220
|
-
arrows.push([
|
|
4221
|
-
tx - 5,
|
|
4222
|
-
tx + 5,
|
|
4223
|
-
ty - 9,
|
|
4224
|
-
ty
|
|
4225
|
-
]);
|
|
4226
|
-
}
|
|
4227
|
-
const w = (e.inferred ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
|
|
4228
|
-
const d = route(clean(pts), 10);
|
|
4229
|
-
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4230
|
-
className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
|
|
4231
|
-
d,
|
|
4232
|
-
strokeWidth: w
|
|
4233
|
-
}, "p" + idx));
|
|
4234
|
-
if (pickEdge) hitPaths.push(/* @__PURE__ */ jsx("path", {
|
|
4235
|
-
className: "ui-lg-hit",
|
|
4236
|
-
"data-edge": edgeId(e),
|
|
4237
|
-
d,
|
|
4238
|
-
role: "button",
|
|
4239
|
-
tabIndex: 0,
|
|
4240
|
-
"aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
|
|
4241
|
-
"aria-pressed": picked,
|
|
4242
|
-
onClick: (ev) => {
|
|
4243
|
-
ev.stopPropagation();
|
|
4244
|
-
choose(e);
|
|
4556
|
+
});
|
|
4557
|
+
const placed = [...arrows, ...runs];
|
|
4558
|
+
const boxRects = main.map((n) => [
|
|
4559
|
+
pos[n.id].x,
|
|
4560
|
+
pos[n.id].x + NW,
|
|
4561
|
+
pos[n.id].y,
|
|
4562
|
+
pos[n.id].y + NH
|
|
4563
|
+
]);
|
|
4564
|
+
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);
|
|
4565
|
+
const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
|
|
4566
|
+
const labelEl = (m, x0, top, lines = [m.text]) => /* @__PURE__ */ jsx("span", {
|
|
4567
|
+
"aria-hidden": pickEdge ? true : void 0,
|
|
4568
|
+
className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
|
|
4569
|
+
style: {
|
|
4570
|
+
left: x0,
|
|
4571
|
+
top
|
|
4245
4572
|
},
|
|
4246
|
-
|
|
4247
|
-
|
|
4248
|
-
|
|
4249
|
-
|
|
4250
|
-
|
|
4251
|
-
|
|
4252
|
-
|
|
4573
|
+
onClick: pickEdge ? (ev) => {
|
|
4574
|
+
ev.stopPropagation();
|
|
4575
|
+
choose(m.e);
|
|
4576
|
+
} : void 0,
|
|
4577
|
+
onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
|
|
4578
|
+
onPointerLeave: pickEdge ? () => setHover(null) : void 0,
|
|
4579
|
+
children: lines.map((t, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i ? /* @__PURE__ */ jsx("br", {}) : null, labelParts(t)] }, i))
|
|
4580
|
+
}, "l" + m.idx);
|
|
4581
|
+
marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => {
|
|
4582
|
+
const w = Math.ceil(labelWidth(m.text));
|
|
4583
|
+
if (m.up) {
|
|
4584
|
+
const x0Of = (lw) => Math.max(PAD / 2, Math.min(W - PAD / 2 - lw, m.left ? m.tx - lw : m.tx));
|
|
4585
|
+
const start0 = Math.max(10, Math.min(H - 10, m.ty));
|
|
4586
|
+
const find = (x0, lw, lh, withLines) => {
|
|
4587
|
+
const over = (q, y0, y1) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4;
|
|
4588
|
+
const bad = (y0, y1) => hits(x0, x0 + lw, y0 - 4, y1 + 4) || boxRects.some((q) => over(q, y0, y1)) || withLines && segs.some((g) => g.idx === m.idx ? cross(g.box, x0, lw, y0, y1) : over(g.box, y0, y1));
|
|
4589
|
+
for (let k = 0; k <= 16; k++) for (const dir of k ? [-1, 1] : [0]) {
|
|
4590
|
+
const t = start0 + dir * k * 18;
|
|
4591
|
+
if (t - lh / 2 >= 2 && t + lh / 2 <= H - 2 && !bad(t - lh / 2, t + lh / 2)) return t;
|
|
4592
|
+
}
|
|
4593
|
+
return null;
|
|
4594
|
+
};
|
|
4595
|
+
let spot = null;
|
|
4596
|
+
for (const lines of wraps(m.text)) {
|
|
4597
|
+
const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
|
|
4598
|
+
const lh = lines.length * 16;
|
|
4599
|
+
const x0 = x0Of(lw);
|
|
4600
|
+
const top = find(x0, lw, lh, true);
|
|
4601
|
+
if (top != null) {
|
|
4602
|
+
spot = {
|
|
4603
|
+
x0,
|
|
4604
|
+
top,
|
|
4605
|
+
lw,
|
|
4606
|
+
lh,
|
|
4607
|
+
lines
|
|
4608
|
+
};
|
|
4609
|
+
break;
|
|
4610
|
+
}
|
|
4611
|
+
}
|
|
4612
|
+
if (!spot) {
|
|
4613
|
+
const g = Math.max(0, Math.min(layers.length - 2, layers.findIndex((_, k) => k < layers.length - 1 && m.ty < rowTop(k + 1))));
|
|
4614
|
+
need.add(g);
|
|
4615
|
+
const x0 = x0Of(w);
|
|
4616
|
+
spot = {
|
|
4617
|
+
x0,
|
|
4618
|
+
top: find(x0, w, 16, false) ?? start0,
|
|
4619
|
+
lw: w,
|
|
4620
|
+
lh: 16,
|
|
4621
|
+
lines: [m.text]
|
|
4622
|
+
};
|
|
4623
|
+
}
|
|
4624
|
+
placed.push([
|
|
4625
|
+
spot.x0,
|
|
4626
|
+
spot.x0 + spot.lw,
|
|
4627
|
+
spot.top - spot.lh / 2 - 4,
|
|
4628
|
+
spot.top + spot.lh / 2 + 4,
|
|
4629
|
+
6
|
|
4630
|
+
]);
|
|
4631
|
+
labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
|
|
4632
|
+
return;
|
|
4633
|
+
}
|
|
4634
|
+
const g = layerIndex[m.e.to] - 1;
|
|
4635
|
+
const sideOf = (lw) => {
|
|
4636
|
+
let left = m.left;
|
|
4637
|
+
if (left && m.tx - 8 - lw < 0) left = false;
|
|
4638
|
+
else if (!left && m.tx + 8 + lw > W) left = m.tx - 8 - lw >= 0;
|
|
4639
|
+
return left;
|
|
4640
|
+
};
|
|
4641
|
+
const at = (left, lw) => left ? m.tx - 8 - lw : Math.min(m.tx + 8, W - lw);
|
|
4642
|
+
const clear = (x0, lw, y0, y1) => {
|
|
4643
|
+
const over = (q) => x0 < q[1] + 2 && q[0] < x0 + lw + 2 && y0 < q[3] + 2 && q[2] < y1 + 2;
|
|
4644
|
+
return !hits(x0, x0 + lw, y0, y1) && !boxRects.some(over) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : over(sg.box));
|
|
4645
|
+
};
|
|
4646
|
+
let spot = null;
|
|
4647
|
+
for (const lines of wraps(m.text)) {
|
|
4648
|
+
const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
|
|
4649
|
+
const lh = lines.length * 16;
|
|
4650
|
+
const pref = sideOf(lw);
|
|
4651
|
+
for (const left of [pref, !pref]) {
|
|
4652
|
+
const x0 = at(left, lw);
|
|
4653
|
+
if (x0 < 0 || x0 + lw > W) continue;
|
|
4654
|
+
for (let k = 0; k < 8 && !spot; k++) {
|
|
4655
|
+
const top = m.ty - 8 - lh / 2 - k * 18;
|
|
4656
|
+
if (top - lh / 2 < 2) break;
|
|
4657
|
+
if (clear(x0, lw, top - lh / 2, top + lh / 2)) spot = {
|
|
4658
|
+
x0,
|
|
4659
|
+
top,
|
|
4660
|
+
lw,
|
|
4661
|
+
lh,
|
|
4662
|
+
lines
|
|
4663
|
+
};
|
|
4664
|
+
}
|
|
4665
|
+
if (spot) break;
|
|
4666
|
+
}
|
|
4667
|
+
if (spot) break;
|
|
4668
|
+
}
|
|
4669
|
+
if (!spot) {
|
|
4670
|
+
if (g >= 0) need.add(g);
|
|
4671
|
+
const x0 = at(sideOf(w), w);
|
|
4672
|
+
let top = m.ty - 16;
|
|
4673
|
+
for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8); k++) top -= 18;
|
|
4674
|
+
spot = {
|
|
4675
|
+
x0,
|
|
4676
|
+
top,
|
|
4677
|
+
lw: w,
|
|
4678
|
+
lh: 16,
|
|
4679
|
+
lines: [m.text]
|
|
4680
|
+
};
|
|
4253
4681
|
}
|
|
4254
|
-
}, "h" + idx));
|
|
4255
|
-
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4256
|
-
className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
|
|
4257
|
-
d: arrow
|
|
4258
|
-
}, "a" + idx));
|
|
4259
|
-
if (!up && (e.inferred || r)) {
|
|
4260
|
-
const text = e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e);
|
|
4261
|
-
marks.push({
|
|
4262
|
-
idx,
|
|
4263
|
-
e,
|
|
4264
|
-
text,
|
|
4265
|
-
tx,
|
|
4266
|
-
ty,
|
|
4267
|
-
left: inn > 1 && tx < b.x + NW / 2,
|
|
4268
|
-
r,
|
|
4269
|
-
dim
|
|
4270
|
-
});
|
|
4271
|
-
}
|
|
4272
|
-
});
|
|
4273
|
-
const placed = [...arrows, ...runs];
|
|
4274
|
-
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
|
-
const labelEl = (m, x0, top) => /* @__PURE__ */ jsx("span", {
|
|
4276
|
-
className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim"),
|
|
4277
|
-
style: {
|
|
4278
|
-
left: x0,
|
|
4279
|
-
top
|
|
4280
|
-
},
|
|
4281
|
-
onClick: pickEdge ? (ev) => {
|
|
4282
|
-
ev.stopPropagation();
|
|
4283
|
-
choose(m.e);
|
|
4284
|
-
} : void 0,
|
|
4285
|
-
onPointerEnter: pickEdge ? () => setHover(edgeId(m.e)) : void 0,
|
|
4286
|
-
onPointerLeave: pickEdge ? () => setHover(null) : void 0,
|
|
4287
|
-
children: labelParts(m.text)
|
|
4288
|
-
}, "l" + m.idx);
|
|
4289
|
-
marks.sort((m, n) => m.ty - n.ty || m.tx - n.tx).forEach((m) => {
|
|
4290
|
-
const w = Math.ceil(labelWidth(m.text));
|
|
4291
|
-
if (m.up) {
|
|
4292
|
-
const x0 = m.left ? m.tx - w : m.tx;
|
|
4293
|
-
let top = Math.max(10, Math.min(H - 10, m.ty));
|
|
4294
|
-
for (let k = 0; k < 8 && hits(x0, x0 + w, top - 8, top + 8) && top - 18 >= 10; k++) top -= 18;
|
|
4295
|
-
for (let k = 0; k < 16 && hits(x0, x0 + w, top - 8, top + 8) && top + 18 <= H - 10; k++) top += 18;
|
|
4296
4682
|
placed.push([
|
|
4297
|
-
x0,
|
|
4298
|
-
x0 +
|
|
4299
|
-
top -
|
|
4300
|
-
top +
|
|
4683
|
+
spot.x0,
|
|
4684
|
+
spot.x0 + spot.lw,
|
|
4685
|
+
spot.top - spot.lh / 2,
|
|
4686
|
+
spot.top + spot.lh / 2,
|
|
4301
4687
|
6
|
|
4302
4688
|
]);
|
|
4303
|
-
labels.push(labelEl(m, x0, top));
|
|
4304
|
-
|
|
4305
|
-
|
|
4306
|
-
|
|
4307
|
-
|
|
4308
|
-
|
|
4309
|
-
|
|
4310
|
-
|
|
4311
|
-
|
|
4312
|
-
|
|
4313
|
-
|
|
4314
|
-
|
|
4315
|
-
|
|
4316
|
-
|
|
4317
|
-
|
|
4318
|
-
|
|
4319
|
-
|
|
4320
|
-
|
|
4321
|
-
|
|
4689
|
+
labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
|
|
4690
|
+
});
|
|
4691
|
+
return {
|
|
4692
|
+
paths,
|
|
4693
|
+
labels,
|
|
4694
|
+
hitPaths,
|
|
4695
|
+
need
|
|
4696
|
+
};
|
|
4697
|
+
};
|
|
4698
|
+
placeRows();
|
|
4699
|
+
let drawn = draw();
|
|
4700
|
+
const grows = () => [...drawn.need].filter((g) => gaps[g] < 200);
|
|
4701
|
+
for (let k = 0; k < GROW_MAX / GROW && grows().length; k++) {
|
|
4702
|
+
for (const g of grows()) gaps[g] = Math.min(200, gaps[g] + GROW);
|
|
4703
|
+
placeRows();
|
|
4704
|
+
drawn = draw();
|
|
4705
|
+
}
|
|
4706
|
+
const stuck = [...drawn.need].filter((g) => gaps[g] >= 200);
|
|
4707
|
+
if (stuck.length) {
|
|
4708
|
+
for (const g of stuck) gaps[g] = GAP;
|
|
4709
|
+
placeRows();
|
|
4710
|
+
drawn = draw();
|
|
4711
|
+
}
|
|
4712
|
+
const { paths, labels, hitPaths } = drawn;
|
|
4322
4713
|
const sizeText = p.sizeLabel ?? tr("{n} 個項目");
|
|
4323
4714
|
const useText = p.useLabel ?? tr("使用 {n} 次");
|
|
4324
4715
|
const nodes = main.map((n) => {
|
|
@@ -4379,15 +4770,87 @@ function LayerGraph(p) {
|
|
|
4379
4770
|
})]
|
|
4380
4771
|
}, s.id);
|
|
4381
4772
|
});
|
|
4773
|
+
const edgeText = (e) => e.inferred ? e.label ? `${e.label}(${p.inferredLabel || tr("推測")})` : p.inferredLabel || tr("推測") : countText(e);
|
|
4774
|
+
const listItem = (key, on, dim, onClick, head, rest) => /* @__PURE__ */ jsxs("li", {
|
|
4775
|
+
className: cx("ui-lg-li", dim && "is-dim"),
|
|
4776
|
+
children: [onClick ? /* @__PURE__ */ jsx("button", {
|
|
4777
|
+
type: "button",
|
|
4778
|
+
className: cx("ui-lg-libtn", on && "is-selected"),
|
|
4779
|
+
"aria-pressed": on,
|
|
4780
|
+
onClick,
|
|
4781
|
+
children: head
|
|
4782
|
+
}) : /* @__PURE__ */ jsx("span", {
|
|
4783
|
+
className: "ui-lg-lihead",
|
|
4784
|
+
children: head
|
|
4785
|
+
}), rest]
|
|
4786
|
+
}, key);
|
|
4787
|
+
const nodeIds = new Set(all.map((n) => n.id));
|
|
4788
|
+
const list = /* @__PURE__ */ jsxs("div", {
|
|
4789
|
+
className: "ui-lg-list",
|
|
4790
|
+
children: [/* @__PURE__ */ jsxs("section", {
|
|
4791
|
+
"aria-labelledby": `${uid}-ln`,
|
|
4792
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
4793
|
+
id: `${uid}-ln`,
|
|
4794
|
+
className: "ui-lg-listtitle",
|
|
4795
|
+
children: p.listLabels?.nodes ?? tr("項目")
|
|
4796
|
+
}), /* @__PURE__ */ jsx("ul", { children: all.map((n) => {
|
|
4797
|
+
const size = sizeOf(n);
|
|
4798
|
+
return listItem(n.id, n.id === sel, !near(n.id), p.onSelect ? () => pick(n.id, n.id === sel) : void 0, /* @__PURE__ */ jsx("span", {
|
|
4799
|
+
className: "ui-lg-code",
|
|
4800
|
+
children: n.name || n.id
|
|
4801
|
+
}), size != null ? /* @__PURE__ */ jsxs("span", {
|
|
4802
|
+
className: "ui-lg-limeta",
|
|
4803
|
+
children: [",", monoNums(sizeText.replace("{n}", ""), [size])]
|
|
4804
|
+
}) : null);
|
|
4805
|
+
}) })]
|
|
4806
|
+
}), /* @__PURE__ */ jsxs("section", {
|
|
4807
|
+
"aria-labelledby": `${uid}-le`,
|
|
4808
|
+
children: [/* @__PURE__ */ jsx("h3", {
|
|
4809
|
+
id: `${uid}-le`,
|
|
4810
|
+
className: "ui-lg-listtitle",
|
|
4811
|
+
children: p.listLabels?.edges ?? tr("關係")
|
|
4812
|
+
}), /* @__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: [
|
|
4813
|
+
/* @__PURE__ */ jsx("span", {
|
|
4814
|
+
className: "ui-lg-code",
|
|
4815
|
+
children: nameOf(e.from)
|
|
4816
|
+
}),
|
|
4817
|
+
" → ",
|
|
4818
|
+
/* @__PURE__ */ jsx("span", {
|
|
4819
|
+
className: "ui-lg-code",
|
|
4820
|
+
children: nameOf(e.to)
|
|
4821
|
+
})
|
|
4822
|
+
] }), /* @__PURE__ */ jsxs("span", {
|
|
4823
|
+
className: "ui-lg-limeta",
|
|
4824
|
+
children: [":", labelParts(edgeText(e))]
|
|
4825
|
+
}))) })]
|
|
4826
|
+
})]
|
|
4827
|
+
});
|
|
4828
|
+
const showList = p.listView !== false && view === "list";
|
|
4382
4829
|
return /* @__PURE__ */ jsxs("div", {
|
|
4383
4830
|
className: cx("ui-graph ui-lg", p.className),
|
|
4384
4831
|
children: [
|
|
4832
|
+
p.listView === false ? null : /* @__PURE__ */ jsx("div", {
|
|
4833
|
+
className: "ui-lg-bar",
|
|
4834
|
+
children: /* @__PURE__ */ jsx(Tabs, {
|
|
4835
|
+
label: tr("顯示方式"),
|
|
4836
|
+
value: view,
|
|
4837
|
+
onChange: setView,
|
|
4838
|
+
items: [{
|
|
4839
|
+
id: "graph",
|
|
4840
|
+
label: tr("圖")
|
|
4841
|
+
}, {
|
|
4842
|
+
id: "list",
|
|
4843
|
+
label: tr("清單")
|
|
4844
|
+
}]
|
|
4845
|
+
})
|
|
4846
|
+
}),
|
|
4847
|
+
showList ? list : null,
|
|
4385
4848
|
/* @__PURE__ */ jsx("div", {
|
|
4386
|
-
className: cx("ui-lg-scroller", scrollMore && "has-more"),
|
|
4849
|
+
className: cx("ui-lg-scroller", scrollMore && "has-more", showList && "is-hidden"),
|
|
4387
4850
|
children: /* @__PURE__ */ jsx("div", {
|
|
4388
4851
|
className: "ui-lg-scroll",
|
|
4389
4852
|
ref: scrollRef,
|
|
4390
|
-
onScroll,
|
|
4853
|
+
onScroll: onScrollKeep,
|
|
4391
4854
|
children: /* @__PURE__ */ jsxs("div", {
|
|
4392
4855
|
className: "ui-lg-canvas",
|
|
4393
4856
|
style: {
|
|
@@ -4412,17 +4875,19 @@ function LayerGraph(p) {
|
|
|
4412
4875
|
width: W,
|
|
4413
4876
|
height: H,
|
|
4414
4877
|
viewBox: `0 0 ${W} ${H}`,
|
|
4878
|
+
role: "group",
|
|
4879
|
+
"aria-label": tr("關係"),
|
|
4415
4880
|
children: hitPaths
|
|
4416
4881
|
}) : null
|
|
4417
4882
|
]
|
|
4418
4883
|
})
|
|
4419
4884
|
})
|
|
4420
4885
|
}),
|
|
4421
|
-
/* @__PURE__ */ jsx(ScrollHint, {
|
|
4886
|
+
showList ? null : /* @__PURE__ */ jsx(ScrollHint, {
|
|
4422
4887
|
show: overflows,
|
|
4423
4888
|
done: scrolled
|
|
4424
4889
|
}),
|
|
4425
|
-
shared.length ? /* @__PURE__ */ jsxs("div", {
|
|
4890
|
+
shared.length && !showList ? /* @__PURE__ */ jsxs("div", {
|
|
4426
4891
|
className: "ui-lg-shared",
|
|
4427
4892
|
children: [/* @__PURE__ */ jsx("div", {
|
|
4428
4893
|
className: "ui-lg-shared-title",
|
|
@@ -4432,7 +4897,7 @@ function LayerGraph(p) {
|
|
|
4432
4897
|
children: sharedBoxes
|
|
4433
4898
|
})]
|
|
4434
4899
|
}) : 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]) ? [{
|
|
4900
|
+
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
4901
|
type: "weight",
|
|
4437
4902
|
label: "次數越多線越粗"
|
|
4438
4903
|
}] : [], ...edges.some((e) => e.inferred && pos[e.from] && pos[e.to]) ? [{
|
|
@@ -5598,6 +6063,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
|
|
|
5598
6063
|
if (controlled == null) setInner(n);
|
|
5599
6064
|
};
|
|
5600
6065
|
const end = (why) => onClose?.(why);
|
|
6066
|
+
useReturnFocus(open);
|
|
5601
6067
|
const target = step?.target;
|
|
5602
6068
|
const pad = step?.padding ?? 6;
|
|
5603
6069
|
const hasStep = !!step;
|
|
@@ -5703,12 +6169,21 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
|
|
|
5703
6169
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
5704
6170
|
className: "ui-tour-body",
|
|
5705
6171
|
children: [
|
|
5706
|
-
/* @__PURE__ */
|
|
6172
|
+
/* @__PURE__ */ jsxs("div", {
|
|
5707
6173
|
className: "ui-tour-count",
|
|
5708
|
-
children:
|
|
5709
|
-
|
|
5710
|
-
|
|
5711
|
-
|
|
6174
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
6175
|
+
"aria-hidden": "true",
|
|
6176
|
+
children: monoNums(tr("{n} / {total}", {
|
|
6177
|
+
n: "",
|
|
6178
|
+
total: ""
|
|
6179
|
+
}), [i + 1, steps.length])
|
|
6180
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
6181
|
+
className: "ui-visually-hidden",
|
|
6182
|
+
children: tr("第 {a} 步,共 {b} 步", {
|
|
6183
|
+
a: i + 1,
|
|
6184
|
+
b: steps.length
|
|
6185
|
+
})
|
|
6186
|
+
})]
|
|
5712
6187
|
}),
|
|
5713
6188
|
/* @__PURE__ */ jsx(Popover$1.Title, {
|
|
5714
6189
|
className: "ui-tour-title",
|
|
@@ -5913,6 +6388,7 @@ function TreeList(p) {
|
|
|
5913
6388
|
if (!p.selected) setOwnSel(v);
|
|
5914
6389
|
p.onSelectChange?.(v);
|
|
5915
6390
|
};
|
|
6391
|
+
const uid = React.useId().replace(/:/g, "");
|
|
5916
6392
|
const [focusId, setFocusId] = React.useState(null);
|
|
5917
6393
|
const refs = React.useRef({});
|
|
5918
6394
|
const want = React.useRef(null);
|
|
@@ -5941,6 +6417,8 @@ function TreeList(p) {
|
|
|
5941
6417
|
if (will) load(n);
|
|
5942
6418
|
p.onToggle?.(n, will, Object.keys(o).filter((k) => o[k]));
|
|
5943
6419
|
if (!p.open) setOwnOpen(o);
|
|
6420
|
+
const c = will ? kids(n) : null;
|
|
6421
|
+
announce(will ? c ? tr("已展開,{n} 個子項目", { n: c.length }) : tr("已展開") : tr("已收合"));
|
|
5944
6422
|
};
|
|
5945
6423
|
const checkState = (n) => {
|
|
5946
6424
|
const fl = filesUnder(n);
|
|
@@ -6042,6 +6520,7 @@ function TreeList(p) {
|
|
|
6042
6520
|
"aria-posinset": r.pos,
|
|
6043
6521
|
"aria-setsize": r.size,
|
|
6044
6522
|
"aria-expanded": r.isF ? r.open : void 0,
|
|
6523
|
+
"aria-owns": r.isF && r.open ? `${uid}-g-${r.n.id}` : void 0,
|
|
6045
6524
|
style: vars({ "--d": r.depth }),
|
|
6046
6525
|
onFocus: () => focusId !== r.n.id && setFocusId(r.n.id)
|
|
6047
6526
|
});
|
|
@@ -6051,6 +6530,11 @@ function TreeList(p) {
|
|
|
6051
6530
|
const meta = n.meta ?? (n.path ? format.path(n.path) : "");
|
|
6052
6531
|
return /* @__PURE__ */ jsxs("div", {
|
|
6053
6532
|
...itemProps(r, idx),
|
|
6533
|
+
"aria-label": [
|
|
6534
|
+
n.name,
|
|
6535
|
+
n.meta,
|
|
6536
|
+
n.path
|
|
6537
|
+
].filter(Boolean).join(","),
|
|
6054
6538
|
"aria-selected": p.onSelect ? on : void 0,
|
|
6055
6539
|
className: cx("ui-tree-row", "is-plain", on && "is-current", n.muted && "is-muted", r.fresh && "ui-tree-in"),
|
|
6056
6540
|
onClick: () => {
|
|
@@ -6064,7 +6548,7 @@ function TreeList(p) {
|
|
|
6064
6548
|
type: "button",
|
|
6065
6549
|
tabIndex: -1,
|
|
6066
6550
|
className: cx("ui-tree-caret", "ui-tree-caretbtn", r.open && "is-open", !isF && "is-leaf"),
|
|
6067
|
-
"aria-
|
|
6551
|
+
"aria-hidden": "true",
|
|
6068
6552
|
onClick: (e) => {
|
|
6069
6553
|
e.stopPropagation();
|
|
6070
6554
|
if (isF) toggle(n);
|
|
@@ -6332,6 +6816,27 @@ function TreeList(p) {
|
|
|
6332
6816
|
}) : null, p.actions ?? null]
|
|
6333
6817
|
})]
|
|
6334
6818
|
}) : null;
|
|
6819
|
+
const render1 = (r) => r.x ? extraRow(r) : plain ? plainRow(r, rows.indexOf(r)) : fileRow(r, rows.indexOf(r));
|
|
6820
|
+
const nest = (start, depth) => {
|
|
6821
|
+
const out = [];
|
|
6822
|
+
let i = start;
|
|
6823
|
+
while (i < every.length && every[i].depth >= depth) {
|
|
6824
|
+
const r = every[i];
|
|
6825
|
+
out.push(render1(r));
|
|
6826
|
+
i++;
|
|
6827
|
+
if (!r.x && r.open && i < every.length && every[i].depth > depth) {
|
|
6828
|
+
const [kidsOut, next] = nest(i, depth + 1);
|
|
6829
|
+
out.push(/* @__PURE__ */ jsx("div", {
|
|
6830
|
+
id: `${uid}-g-${r.n.id}`,
|
|
6831
|
+
role: "group",
|
|
6832
|
+
className: "ui-tree-group",
|
|
6833
|
+
children: kidsOut
|
|
6834
|
+
}, "g-" + r.n.id));
|
|
6835
|
+
i = next;
|
|
6836
|
+
}
|
|
6837
|
+
}
|
|
6838
|
+
return [out, i];
|
|
6839
|
+
};
|
|
6335
6840
|
return /* @__PURE__ */ jsxs("section", {
|
|
6336
6841
|
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
6842
|
"aria-label": p.title ? void 0 : p.label,
|
|
@@ -6342,13 +6847,13 @@ function TreeList(p) {
|
|
|
6342
6847
|
"aria-multiselectable": selectable || void 0,
|
|
6343
6848
|
className: "ui-tree-list",
|
|
6344
6849
|
onKeyDown: onKey,
|
|
6345
|
-
children:
|
|
6850
|
+
children: nest(0, 0)[0]
|
|
6346
6851
|
}) : /* @__PURE__ */ jsx("p", {
|
|
6347
6852
|
className: "ui-tree-empty",
|
|
6348
6853
|
children: p.emptyText || (plain ? tr("沒有項目") : tr("這裡還沒有檔案"))
|
|
6349
6854
|
})]
|
|
6350
6855
|
});
|
|
6351
6856
|
}
|
|
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 };
|
|
6857
|
+
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
6858
|
|
|
6354
6859
|
//# sourceMappingURL=index.js.map
|