@seanyeh77/ui 0.10.0 → 0.12.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-Cvq4QsNK.d.ts → format-entry-BJI8MU2K.d.ts} +4 -1
- package/dist/{format-entry-BoMMgOww.js → format-entry-jAIdVjUz.js} +23 -4
- package/dist/format-entry-jAIdVjUz.js.map +1 -0
- package/dist/format.d.ts +2 -2
- package/dist/format.js +1 -1
- package/dist/index.d.ts +68 -45
- package/dist/index.js +549 -108
- package/dist/index.js.map +1 -1
- package/dist/styles.css +119 -29
- package/dist/tokens.css +16 -0
- package/docs/BarChart.md +1 -0
- package/docs/Calendar.md +1 -0
- package/docs/CodeView.md +1 -0
- package/docs/CommandPalette.md +1 -1
- package/docs/DataTable.md +6 -4
- package/docs/DatePicker.md +1 -1
- package/docs/FileUpload.md +1 -0
- package/docs/Graph.md +1 -1
- package/docs/LayerGraph.md +10 -5
- package/docs/LineChart.md +1 -0
- package/docs/Tabs.md +2 -1
- package/docs/TopBar.md +1 -1
- package/docs/Tour.md +2 -0
- package/docs/guidelines.md +9 -3
- package/package.json +2 -2
- package/dist/format-entry-BoMMgOww.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, d as unitFor, 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-jAIdVjUz.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";
|
|
@@ -239,23 +239,31 @@ const PH_ALIAS = {
|
|
|
239
239
|
"message-square": "chat-centered"
|
|
240
240
|
};
|
|
241
241
|
// src/internal/util.tsx
|
|
242
|
+
/** A value (a row or node id, a file path) as part of an element id: no spaces, so aria-owns, aria-controls and
|
|
243
|
+
* aria-labelledby, which split their value at spaces, still find it. */
|
|
244
|
+
const idPart = (s) => encodeURIComponent(s);
|
|
242
245
|
/** Joins the truthy class names. */
|
|
243
246
|
function cx(...names) {
|
|
244
247
|
return names.filter(Boolean).join(" ");
|
|
245
248
|
}
|
|
246
|
-
function
|
|
247
|
-
|
|
249
|
+
function seenOnly(text, nums) {
|
|
250
|
+
return splitMarks(text).map(([t, k], i) => /* @__PURE__ */ jsx("span", {
|
|
251
|
+
className: cx("ui-seen", k >= 0 && "ui-num"),
|
|
252
|
+
"data-text": k >= 0 ? nums[k] : t
|
|
253
|
+
}, i));
|
|
254
|
+
}
|
|
255
|
+
function splitMarks(text) {
|
|
256
|
+
return text.split(/(\u0001|\u0002|\u0003)/).filter(Boolean).map((t) => [t, [
|
|
248
257
|
"",
|
|
249
258
|
"",
|
|
250
259
|
""
|
|
251
|
-
];
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
});
|
|
260
|
+
].indexOf(t)]);
|
|
261
|
+
}
|
|
262
|
+
function monoNums(text, nums) {
|
|
263
|
+
return splitMarks(text).map(([t, k], i) => k >= 0 ? /* @__PURE__ */ jsx("span", {
|
|
264
|
+
className: "ui-num",
|
|
265
|
+
children: nums[k]
|
|
266
|
+
}, i) : t);
|
|
259
267
|
}
|
|
260
268
|
/** localStorage get (no value) or set; null when storage is blocked. */
|
|
261
269
|
function store(key, value) {
|
|
@@ -1026,6 +1034,7 @@ function AppShell({ nav, value, onNavigate, brand, title, breadcrumb, onSearch,
|
|
|
1026
1034
|
icon: "dots-three"
|
|
1027
1035
|
});
|
|
1028
1036
|
const [moreOpen, setMoreOpen] = React.useState(false);
|
|
1037
|
+
if (moreOpen && !phone && !tablet) setMoreOpen(false);
|
|
1029
1038
|
devWarn(phone && withIcon.length < 2, "AppShell", "phones show the top-level nav items as bottom tabs; give at least 2 of them an icon.");
|
|
1030
1039
|
const current = parentOf(value)?.id ?? value;
|
|
1031
1040
|
const tabValue = tabs.some((t) => t.id === current) ? current : MORE;
|
|
@@ -1355,7 +1364,7 @@ function useFocusRescue(ref, fallback) {
|
|
|
1355
1364
|
const onIn = (e) => {
|
|
1356
1365
|
if (!(e.target instanceof HTMLElement)) return;
|
|
1357
1366
|
last = e.target;
|
|
1358
|
-
index =
|
|
1367
|
+
index = list().indexOf(last);
|
|
1359
1368
|
};
|
|
1360
1369
|
const rescue = () => {
|
|
1361
1370
|
const now = list();
|
|
@@ -1443,7 +1452,7 @@ function Menu({ items, label, icon = "dots-three", align = "end", triggerClassNa
|
|
|
1443
1452
|
}) })] }), danger.length ? /* @__PURE__ */ jsx(Dialog, {
|
|
1444
1453
|
open: !!asking,
|
|
1445
1454
|
onClose: () => setAsking(null),
|
|
1446
|
-
title: asking ? asking.confirm?.title ?? asking.label
|
|
1455
|
+
title: asking ? asking.confirm?.title ?? tr("{label}?", { label: asking.label }) : "",
|
|
1447
1456
|
tone: "danger",
|
|
1448
1457
|
confirmLabel: asking?.confirm?.confirmLabel ?? asking?.label ?? "",
|
|
1449
1458
|
onConfirm: () => {
|
|
@@ -1718,19 +1727,39 @@ function niceMax(v) {
|
|
|
1718
1727
|
const n = Math.ceil(v / e);
|
|
1719
1728
|
return (n <= 2 ? 2 : n <= 4 ? 4 : n <= 5 ? 5 : n <= 8 ? 8 : 10) * e;
|
|
1720
1729
|
}
|
|
1730
|
+
/** ← → (and Home, End) on a chart: the item to show next, or null for any other key. */
|
|
1731
|
+
function chartKey(e, at, n) {
|
|
1732
|
+
if (e.altKey || e.metaKey || e.ctrlKey || !n) return null;
|
|
1733
|
+
const i = Math.max(0, at);
|
|
1734
|
+
const to = e.key === "ArrowRight" ? Math.min(n - 1, i + 1) : e.key === "ArrowLeft" ? Math.max(0, i - 1) : e.key === "Home" ? 0 : e.key === "End" ? n - 1 : null;
|
|
1735
|
+
if (to != null) e.preventDefault();
|
|
1736
|
+
return to;
|
|
1737
|
+
}
|
|
1721
1738
|
// src/components/BarChart/BarChart.tsx
|
|
1722
1739
|
/** Compares a few categories: rounded bars that grow in, a tooltip on hover. */
|
|
1723
1740
|
function BarChart({ data, label, unit, decimals, max, className }) {
|
|
1724
1741
|
const [hi, setHi] = React.useState(-1);
|
|
1725
1742
|
const top = max || niceMax(Math.max(1, ...data.map((d) => d.value)));
|
|
1726
1743
|
const suffix = unit ? " " + unit : "";
|
|
1744
|
+
const show = (i) => {
|
|
1745
|
+
setHi(i);
|
|
1746
|
+
announce(data[i].label + tr(":") + format.number(data[i].value, decimals) + suffix);
|
|
1747
|
+
};
|
|
1727
1748
|
return /* @__PURE__ */ jsxs("div", {
|
|
1728
1749
|
className: cx("ui-chart", className),
|
|
1729
1750
|
children: [/* @__PURE__ */ jsxs("div", {
|
|
1730
1751
|
className: "ui-bars",
|
|
1731
1752
|
role: "img",
|
|
1732
1753
|
"aria-label": label,
|
|
1754
|
+
"aria-description": tr("左右方向鍵查看每一項的數值"),
|
|
1755
|
+
tabIndex: data.length ? 0 : void 0,
|
|
1733
1756
|
onMouseLeave: () => setHi(-1),
|
|
1757
|
+
onFocus: () => hi < 0 && data.length && show(0),
|
|
1758
|
+
onBlur: () => setHi(-1),
|
|
1759
|
+
onKeyDown: (e) => {
|
|
1760
|
+
const to = chartKey(e, hi, data.length);
|
|
1761
|
+
if (to != null) show(to);
|
|
1762
|
+
},
|
|
1734
1763
|
children: [TICKS.map((f, i) => /* @__PURE__ */ jsx("div", {
|
|
1735
1764
|
className: cx("ui-bars-grid", !i && "is-axis"),
|
|
1736
1765
|
style: { bottom: f * 100 + "%" },
|
|
@@ -1783,6 +1812,44 @@ function Calendar({ focus, onPick, onHover, dayState }) {
|
|
|
1783
1812
|
const today = /* @__PURE__ */ new Date();
|
|
1784
1813
|
const y = month.getFullYear();
|
|
1785
1814
|
const m = month.getMonth();
|
|
1815
|
+
const [active, setActive] = React.useState(() => focus || today);
|
|
1816
|
+
const cur = active.getFullYear() === y && active.getMonth() === m ? active : new Date(y, m, Math.min(active.getDate(), new Date(y, m + 1, 0).getDate()));
|
|
1817
|
+
const grid = React.useRef(null);
|
|
1818
|
+
const moveTo = React.useRef(false);
|
|
1819
|
+
React.useEffect(() => {
|
|
1820
|
+
if (!moveTo.current) return;
|
|
1821
|
+
moveTo.current = false;
|
|
1822
|
+
grid.current?.querySelector(".ui-cal-day[tabindex=\"0\"]")?.focus();
|
|
1823
|
+
});
|
|
1824
|
+
const go = (d) => {
|
|
1825
|
+
const step = d < cur ? -1 : 1;
|
|
1826
|
+
for (let k = 0; k < 31 && dayState?.(d)?.disabled; k++) d = dayAdd(d, step);
|
|
1827
|
+
setActive(d);
|
|
1828
|
+
if (d.getMonth() !== m || d.getFullYear() !== y) setMonth(new Date(d.getFullYear(), d.getMonth(), 1));
|
|
1829
|
+
moveTo.current = true;
|
|
1830
|
+
onHover?.(d);
|
|
1831
|
+
};
|
|
1832
|
+
const onKey = (e) => {
|
|
1833
|
+
if (browserKey(e)) return;
|
|
1834
|
+
const wd = (cur.getDay() - format.firstDay() + 7) % 7;
|
|
1835
|
+
const sameDayIn = (dm) => {
|
|
1836
|
+
const last = new Date(cur.getFullYear(), cur.getMonth() + dm + 1, 0).getDate();
|
|
1837
|
+
return new Date(cur.getFullYear(), cur.getMonth() + dm, Math.min(cur.getDate(), last));
|
|
1838
|
+
};
|
|
1839
|
+
const to = {
|
|
1840
|
+
ArrowLeft: () => dayAdd(cur, -1),
|
|
1841
|
+
ArrowRight: () => dayAdd(cur, 1),
|
|
1842
|
+
ArrowUp: () => dayAdd(cur, -7),
|
|
1843
|
+
ArrowDown: () => dayAdd(cur, 7),
|
|
1844
|
+
Home: () => dayAdd(cur, -wd),
|
|
1845
|
+
End: () => dayAdd(cur, 6 - wd),
|
|
1846
|
+
PageUp: () => sameDayIn(-1),
|
|
1847
|
+
PageDown: () => sameDayIn(1)
|
|
1848
|
+
};
|
|
1849
|
+
if (!to[e.key]) return;
|
|
1850
|
+
e.preventDefault();
|
|
1851
|
+
go(to[e.key]());
|
|
1852
|
+
};
|
|
1786
1853
|
const start = (new Date(y, m, 1).getDay() - format.firstDay() + 7) % 7;
|
|
1787
1854
|
const days = new Date(y, m + 1, 0).getDate();
|
|
1788
1855
|
const cells = [...Array(start).fill(null), ...Array.from({ length: days }, (_, i) => new Date(y, m, i + 1))];
|
|
@@ -1818,9 +1885,11 @@ function Calendar({ focus, onPick, onHover, dayState }) {
|
|
|
1818
1885
|
})
|
|
1819
1886
|
]
|
|
1820
1887
|
}), /* @__PURE__ */ jsxs("div", {
|
|
1888
|
+
ref: grid,
|
|
1821
1889
|
className: "ui-cal-grid",
|
|
1822
1890
|
role: "group",
|
|
1823
1891
|
"aria-label": format.month(month),
|
|
1892
|
+
onKeyDown: onKey,
|
|
1824
1893
|
children: [format.weekdays().map((w, i) => /* @__PURE__ */ jsx("span", {
|
|
1825
1894
|
className: "ui-cal-wk",
|
|
1826
1895
|
"aria-hidden": "true",
|
|
@@ -1838,6 +1907,8 @@ function Calendar({ focus, onPick, onHover, dayState }) {
|
|
|
1838
1907
|
weekday: false,
|
|
1839
1908
|
long: true
|
|
1840
1909
|
}) + (isToday ? tr("(今天)") : ""),
|
|
1910
|
+
tabIndex: sameDay(c, cur) ? 0 : -1,
|
|
1911
|
+
onFocus: () => !sameDay(c, cur) && setActive(c),
|
|
1841
1912
|
onClick: () => onPick?.(c),
|
|
1842
1913
|
onMouseEnter: onHover ? () => onHover(c) : void 0,
|
|
1843
1914
|
children: c.getDate()
|
|
@@ -2052,6 +2123,38 @@ const tokenize = (lines, lang) => {
|
|
|
2052
2123
|
const OPS = /(->|::|==|!=|<=|>=|&&|\|\||\+\+|--|<<|>>|=>|\+=|-=|\*=|\/=)/;
|
|
2053
2124
|
const AFTER = /([,.([{;])/;
|
|
2054
2125
|
/** A piece of code with soft break points after commas, dots and opening brackets, and operators kept together. */
|
|
2126
|
+
const PATH_IN_CODE = /(?<![\w./-])((?:\.{1,2}\/)?(?:[\w.-]+\/)+[\w.-]+\.[A-Za-z0-9]+(?::\d+(?:-\d+)?)?|[\w.-]+\.[A-Za-z0-9]+:\d+(?:-\d+)?)(?![\w/])/g;
|
|
2127
|
+
/** The paths in a comment or string as links (refHref, onRef); the rest stays text. */
|
|
2128
|
+
function withPaths(text, refHref, onRef) {
|
|
2129
|
+
const out = [];
|
|
2130
|
+
let at = 0;
|
|
2131
|
+
for (const m of text.matchAll(PATH_IN_CODE)) {
|
|
2132
|
+
const v = m[1];
|
|
2133
|
+
const href = refHref ? refHref(v) || void 0 : void 0;
|
|
2134
|
+
if (refHref ? !href : !onRef) continue;
|
|
2135
|
+
if (m.index > at) out.push(breakable(text.slice(at, m.index)));
|
|
2136
|
+
const click = onRef ? (e) => {
|
|
2137
|
+
if (href && (e.metaKey || e.ctrlKey || e.shiftKey || e.button === 1)) return;
|
|
2138
|
+
e.preventDefault();
|
|
2139
|
+
onRef(v, e);
|
|
2140
|
+
} : void 0;
|
|
2141
|
+
out.push(href ? /* @__PURE__ */ jsx("a", {
|
|
2142
|
+
className: "ui-cv-ref",
|
|
2143
|
+
href,
|
|
2144
|
+
onClick: click,
|
|
2145
|
+
children: v
|
|
2146
|
+
}, m.index) : /* @__PURE__ */ jsx("button", {
|
|
2147
|
+
type: "button",
|
|
2148
|
+
className: "ui-cv-ref",
|
|
2149
|
+
onClick: click,
|
|
2150
|
+
children: v
|
|
2151
|
+
}, m.index));
|
|
2152
|
+
at = m.index + v.length;
|
|
2153
|
+
}
|
|
2154
|
+
if (!out.length) return breakable(text);
|
|
2155
|
+
if (at < text.length) out.push(breakable(text.slice(at)));
|
|
2156
|
+
return out;
|
|
2157
|
+
}
|
|
2055
2158
|
function breakable(text) {
|
|
2056
2159
|
if (!OPS.test(text) && !AFTER.test(text)) return text;
|
|
2057
2160
|
const out = [];
|
|
@@ -2073,7 +2176,7 @@ function breakable(text) {
|
|
|
2073
2176
|
return out;
|
|
2074
2177
|
}
|
|
2075
2178
|
/** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
|
|
2076
|
-
function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, maxHeight, className, ref }) {
|
|
2179
|
+
function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, maxHeight, className, ref }) {
|
|
2077
2180
|
const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
|
|
2078
2181
|
const lang = language || languageOf(file);
|
|
2079
2182
|
const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
|
|
@@ -2128,10 +2231,10 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2128
2231
|
className: "ui-cv-text",
|
|
2129
2232
|
children: [/* @__PURE__ */ jsx("span", {
|
|
2130
2233
|
className: "ui-visually-hidden ui-cv-sr",
|
|
2131
|
-
children: tr("第 {n} 行", { n }) + ":"
|
|
2234
|
+
children: tr("第 {n} 行", { n }) + tr(":")
|
|
2132
2235
|
}), toks[i].map(([cls, text], j) => cls ? /* @__PURE__ */ jsx("span", {
|
|
2133
2236
|
className: cls,
|
|
2134
|
-
children: breakable(text)
|
|
2237
|
+
children: (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef) : breakable(text)
|
|
2135
2238
|
}, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))]
|
|
2136
2239
|
})]
|
|
2137
2240
|
}, i));
|
|
@@ -2151,9 +2254,9 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
2151
2254
|
children: title
|
|
2152
2255
|
}), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
|
|
2153
2256
|
className: "ui-cv-lang",
|
|
2154
|
-
children: [/* @__PURE__ */
|
|
2257
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
2155
2258
|
className: "ui-visually-hidden",
|
|
2156
|
-
children:
|
|
2259
|
+
children: tr("程式語言") + tr(":")
|
|
2157
2260
|
}), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
|
|
2158
2261
|
}) : null]
|
|
2159
2262
|
}) : null;
|
|
@@ -2203,7 +2306,7 @@ function score(it, q) {
|
|
|
2203
2306
|
}
|
|
2204
2307
|
/** One search for everything, opened with Ctrl K (⌘K). A panel in the middle of the screen; results sorted by relevance. */
|
|
2205
2308
|
function CommandPalette(props) {
|
|
2206
|
-
const { open, onOpenChange, items, onSelect, placeholder, recent, recentLabel, emptyText, kinds, filter = true, onQueryChange, loading, limit = 50, hotkey = true, defaultQuery = "", label } = props;
|
|
2309
|
+
const { open, onOpenChange, items, onSelect, placeholder, recent, recentLabel, emptyText, noResultsText, kinds, filter = true, onQueryChange, loading, limit = 50, hotkey = true, defaultQuery = "", label } = props;
|
|
2207
2310
|
const [q, setQ] = React.useState(defaultQuery);
|
|
2208
2311
|
const [active, setActive] = React.useState(0);
|
|
2209
2312
|
useReturnFocus(open);
|
|
@@ -2286,7 +2389,8 @@ function CommandPalette(props) {
|
|
|
2286
2389
|
] }) : t
|
|
2287
2390
|
});
|
|
2288
2391
|
};
|
|
2289
|
-
const
|
|
2392
|
+
const none = (t) => typeof noResultsText === "function" ? noResultsText(t) : (noResultsText ?? tr("找不到符合「{q}」的結果")).replace("{q}", t);
|
|
2393
|
+
const empty = query ? none(q.trim()) : emptyText || tr("輸入名稱開始搜尋");
|
|
2290
2394
|
const said = !open ? "" : !query ? "" : loading ? tr("搜尋中") : shown.length ? tr("找到 {n} 筆結果", { n: shown.length }) : empty;
|
|
2291
2395
|
React.useEffect(() => {
|
|
2292
2396
|
if (!said) return;
|
|
@@ -2406,7 +2510,7 @@ function DangerZone({ title, description, actionLabel, onAction, confirm, classN
|
|
|
2406
2510
|
className: "ui-danger-row",
|
|
2407
2511
|
children: [/* @__PURE__ */ jsx("p", { children: description }), /* @__PURE__ */ jsx(Button, {
|
|
2408
2512
|
variant: "danger",
|
|
2409
|
-
confirm: confirm ?? { title:
|
|
2513
|
+
confirm: confirm ?? { title: tr("{label}?", { label }) },
|
|
2410
2514
|
onClick: onAction,
|
|
2411
2515
|
children: label
|
|
2412
2516
|
})]
|
|
@@ -2475,7 +2579,7 @@ function Tabs({ items, value, onChange, label, unit, className }) {
|
|
|
2475
2579
|
setForward(i > idx);
|
|
2476
2580
|
bump();
|
|
2477
2581
|
onChange?.(items[i].id);
|
|
2478
|
-
announce(items[i].label + (items[i].count != null ? " " + format.number(items[i].count ?? 0) + (items[i].unit || unit ? " " +
|
|
2582
|
+
announce(items[i].label + (items[i].count != null ? " " + format.number(items[i].count ?? 0) + (items[i].unit || unit ? " " + unitFor(items[i].unit || unit, items[i].count ?? 0) : "") : ""));
|
|
2479
2583
|
};
|
|
2480
2584
|
return /* @__PURE__ */ jsxs("div", {
|
|
2481
2585
|
ref: track,
|
|
@@ -2516,7 +2620,7 @@ function Tabs({ items, value, onChange, label, unit, className }) {
|
|
|
2516
2620
|
className: "ui-tab-count",
|
|
2517
2621
|
children: [format.number(t.count), t.unit || unit ? /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("span", {
|
|
2518
2622
|
className: "ui-unit",
|
|
2519
|
-
children:
|
|
2623
|
+
children: unitFor(t.unit || unit, t.count)
|
|
2520
2624
|
})] }) : null]
|
|
2521
2625
|
}) : null
|
|
2522
2626
|
]
|
|
@@ -2907,12 +3011,9 @@ function FullText({ text, children }) {
|
|
|
2907
3011
|
wrap: true,
|
|
2908
3012
|
describe: false,
|
|
2909
3013
|
disabled: touch || !text,
|
|
2910
|
-
children: /* @__PURE__ */
|
|
3014
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
2911
3015
|
className: "ui-dt-full",
|
|
2912
|
-
children
|
|
2913
|
-
className: "ui-visually-hidden",
|
|
2914
|
-
children: tr(",") + text
|
|
2915
|
-
}) : null]
|
|
3016
|
+
children
|
|
2916
3017
|
})
|
|
2917
3018
|
});
|
|
2918
3019
|
}
|
|
@@ -3034,6 +3135,7 @@ function DataTable(p) {
|
|
|
3034
3135
|
const rootRef = React.useRef(null);
|
|
3035
3136
|
const [sel, setSel] = React.useState({});
|
|
3036
3137
|
const [sumVal, setSumVal] = React.useState("all");
|
|
3138
|
+
const [fit, setFit] = React.useState({});
|
|
3037
3139
|
const [resetKey, setResetKey] = React.useState(p.resetKey);
|
|
3038
3140
|
const resetting = resetKey !== p.resetKey;
|
|
3039
3141
|
if (resetting) {
|
|
@@ -3049,6 +3151,7 @@ function DataTable(p) {
|
|
|
3049
3151
|
});
|
|
3050
3152
|
setToggled({});
|
|
3051
3153
|
setOpened({});
|
|
3154
|
+
setFit({});
|
|
3052
3155
|
}
|
|
3053
3156
|
const valuesKey = JSON.stringify(values);
|
|
3054
3157
|
React.useEffect(() => {
|
|
@@ -3244,17 +3347,54 @@ function DataTable(p) {
|
|
|
3244
3347
|
const longCols = shownCols.filter((c) => c.long || c.fullText);
|
|
3245
3348
|
const expander = longCols.length > 0 && !narrow;
|
|
3246
3349
|
const EXP = 40;
|
|
3350
|
+
const minOf = (c) => Math.max(c.width || (c.numeric ? 96 : 120), fit[c.key] || 0);
|
|
3247
3351
|
const template = [
|
|
3248
3352
|
expander ? "40px" : null,
|
|
3249
3353
|
selectable ? "46px" : null,
|
|
3250
|
-
...shownCols.map((c) =>
|
|
3354
|
+
...shownCols.map((c) => `minmax(${minOf(c)}px, ${c.grow || (c.width ? 1 : c.numeric ? .8 : 1)}fr)`),
|
|
3251
3355
|
hasAct ? actW + "px" : null
|
|
3252
3356
|
].filter(Boolean).join(" ");
|
|
3253
|
-
const minW = (expander ? EXP : 0) + (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + (c
|
|
3357
|
+
const minW = (expander ? EXP : 0) + (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + minOf(c), 0) + (hasAct ? actW : 0);
|
|
3254
3358
|
const gridStyle = {
|
|
3255
3359
|
gridTemplateColumns: template,
|
|
3256
3360
|
minWidth: minW
|
|
3257
3361
|
};
|
|
3362
|
+
React.useLayoutEffect(() => {
|
|
3363
|
+
const root = rootRef.current;
|
|
3364
|
+
if (!root || narrow) return;
|
|
3365
|
+
const measure = () => {
|
|
3366
|
+
const need = {};
|
|
3367
|
+
for (const el of root.querySelectorAll(".ui-dt-body .ui-dt-cell[data-col]:not(.is-long)")) {
|
|
3368
|
+
const over = el.scrollWidth - el.clientWidth;
|
|
3369
|
+
const key = el.dataset.col;
|
|
3370
|
+
if (over > 1 && key) need[key] = Math.max(need[key] ?? 0, Math.ceil(el.getBoundingClientRect().width + over));
|
|
3371
|
+
}
|
|
3372
|
+
setFit((f) => {
|
|
3373
|
+
const grow = Object.entries(need).filter(([k, w]) => w > (f[k] ?? 0));
|
|
3374
|
+
return grow.length ? {
|
|
3375
|
+
...f,
|
|
3376
|
+
...Object.fromEntries(grow)
|
|
3377
|
+
} : f;
|
|
3378
|
+
});
|
|
3379
|
+
};
|
|
3380
|
+
measure();
|
|
3381
|
+
let frame = 0;
|
|
3382
|
+
const later = () => {
|
|
3383
|
+
cancelAnimationFrame(frame);
|
|
3384
|
+
frame = requestAnimationFrame(measure);
|
|
3385
|
+
};
|
|
3386
|
+
const mo = new MutationObserver(later);
|
|
3387
|
+
mo.observe(root, {
|
|
3388
|
+
childList: true,
|
|
3389
|
+
subtree: true,
|
|
3390
|
+
characterData: true
|
|
3391
|
+
});
|
|
3392
|
+
document.fonts?.ready.then(later).catch(() => {});
|
|
3393
|
+
return () => {
|
|
3394
|
+
mo.disconnect();
|
|
3395
|
+
cancelAnimationFrame(frame);
|
|
3396
|
+
};
|
|
3397
|
+
}, [narrow, resetKey]);
|
|
3258
3398
|
const stickyStyle = (ci) => ci === 0 && sticky ? { left: (expander ? EXP : 0) + (selectable ? 46 : 0) } : void 0;
|
|
3259
3399
|
const cellClass = (c, ci, ...more) => cx("ui-dt-cell", isNum(c) && "is-num", ci === 0 && sticky && "is-sticky", ...more);
|
|
3260
3400
|
const head = selectable && selIds.length && p.bulkActions ? /* @__PURE__ */ jsxs("div", {
|
|
@@ -3390,6 +3530,7 @@ function DataTable(p) {
|
|
|
3390
3530
|
"aria-label": tr("檢視"),
|
|
3391
3531
|
children: p.views.map((v) => {
|
|
3392
3532
|
const on = v.id === view;
|
|
3533
|
+
const vn = rows.filter((r) => !v.filter || v.filter(r)).length;
|
|
3393
3534
|
return /* @__PURE__ */ jsxs("button", {
|
|
3394
3535
|
type: "button",
|
|
3395
3536
|
role: "tab",
|
|
@@ -3402,11 +3543,11 @@ function DataTable(p) {
|
|
|
3402
3543
|
children: [v.label, /* @__PURE__ */ jsxs("span", {
|
|
3403
3544
|
className: "ui-dt-view-n",
|
|
3404
3545
|
children: [
|
|
3405
|
-
format.number(
|
|
3546
|
+
format.number(vn),
|
|
3406
3547
|
" ",
|
|
3407
3548
|
/* @__PURE__ */ jsx("span", {
|
|
3408
3549
|
className: "ui-unit",
|
|
3409
|
-
children:
|
|
3550
|
+
children: unitFor("筆", vn)
|
|
3410
3551
|
})
|
|
3411
3552
|
]
|
|
3412
3553
|
})]
|
|
@@ -3468,7 +3609,7 @@ function DataTable(p) {
|
|
|
3468
3609
|
className: "ui-dt-result",
|
|
3469
3610
|
children: [/* @__PURE__ */ jsx("span", {
|
|
3470
3611
|
"aria-hidden": "true",
|
|
3471
|
-
children:
|
|
3612
|
+
children: seenOnly(tr("{n} / {total} 筆", {
|
|
3472
3613
|
n: "",
|
|
3473
3614
|
total: ""
|
|
3474
3615
|
}), [format.number(list.length), format.number(baseCount)])
|
|
@@ -3507,7 +3648,7 @@ function DataTable(p) {
|
|
|
3507
3648
|
const id = visIds[i];
|
|
3508
3649
|
const on = !!sel[id];
|
|
3509
3650
|
const open = expander && !!opened[id];
|
|
3510
|
-
const detailId = `${uid}-d-${id}`;
|
|
3651
|
+
const detailId = `${uid}-d-${idPart(id)}`;
|
|
3511
3652
|
const rowName = shownCols[0] ? String(cellText(shownCols[0], get(x.r, shownCols[0].key)) ?? "") : "";
|
|
3512
3653
|
return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsxs("div", {
|
|
3513
3654
|
"data-rid": id,
|
|
@@ -3515,6 +3656,7 @@ function DataTable(p) {
|
|
|
3515
3656
|
rowEls.current[id] = el;
|
|
3516
3657
|
},
|
|
3517
3658
|
role: "row",
|
|
3659
|
+
"aria-labelledby": shownCols.length ? `${uid}-n-${start + i}` : void 0,
|
|
3518
3660
|
className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
|
|
3519
3661
|
style: gridStyle,
|
|
3520
3662
|
onClick: expander ? (e) => {
|
|
@@ -3557,7 +3699,10 @@ function DataTable(p) {
|
|
|
3557
3699
|
}) : null,
|
|
3558
3700
|
shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
|
|
3559
3701
|
role: "cell",
|
|
3702
|
+
id: ci === 0 ? `${uid}-n-${start + i}` : void 0,
|
|
3703
|
+
"aria-description": c.fullText ? c.fullText(x.r) || void 0 : void 0,
|
|
3560
3704
|
"data-label": c.label,
|
|
3705
|
+
"data-col": c.key,
|
|
3561
3706
|
className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
|
|
3562
3707
|
style: stickyStyle(ci),
|
|
3563
3708
|
children: cell(x.r, c)
|
|
@@ -3683,9 +3828,12 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
|
|
|
3683
3828
|
const [open, setOpen] = React.useState(false);
|
|
3684
3829
|
const [typed, setTyped] = React.useState(null);
|
|
3685
3830
|
const field = React.useRef(null);
|
|
3686
|
-
const
|
|
3831
|
+
const wrong = typed !== null && typed !== "" && !parseDate(typed);
|
|
3832
|
+
const [left, setLeft] = React.useState(false);
|
|
3833
|
+
const bad = wrong && left;
|
|
3687
3834
|
const commit = (d) => {
|
|
3688
3835
|
setTyped(null);
|
|
3836
|
+
setLeft(false);
|
|
3689
3837
|
onChange(d);
|
|
3690
3838
|
setOpen(false);
|
|
3691
3839
|
};
|
|
@@ -3705,6 +3853,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
|
|
|
3705
3853
|
className: "ui-datefield-input",
|
|
3706
3854
|
value: typed ?? fmtDate(value),
|
|
3707
3855
|
placeholder: "YYYY/MM/DD",
|
|
3856
|
+
"aria-required": required || void 0,
|
|
3708
3857
|
"aria-invalid": bad || void 0,
|
|
3709
3858
|
onChange: (e) => {
|
|
3710
3859
|
const t = e.target.value;
|
|
@@ -3713,7 +3862,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
|
|
|
3713
3862
|
if (d) onChange(d);
|
|
3714
3863
|
else if (t === "") onChange(null);
|
|
3715
3864
|
},
|
|
3716
|
-
onBlur: () =>
|
|
3865
|
+
onBlur: () => wrong ? setLeft(true) : setTyped(null)
|
|
3717
3866
|
}), /* @__PURE__ */ jsxs(FloatingPanel, {
|
|
3718
3867
|
open,
|
|
3719
3868
|
onOpenChange: setOpen,
|
|
@@ -3758,6 +3907,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
|
|
|
3758
3907
|
}
|
|
3759
3908
|
// src/components/DateRangePicker/DateRangePicker.tsx
|
|
3760
3909
|
/** A period: quick ranges (今天、最近 7 天、最近 30 天、本月、上個月) beside one month. Click a start day, then an end day. */
|
|
3910
|
+
const day = (d) => format.date(d, { weekday: false });
|
|
3761
3911
|
function DateRangePicker({ label, value, onChange, placeholder, className }) {
|
|
3762
3912
|
const [open, setOpen] = React.useState(false);
|
|
3763
3913
|
const [first, setFirst] = React.useState(null);
|
|
@@ -3795,13 +3945,13 @@ function DateRangePicker({ label, value, onChange, placeholder, className }) {
|
|
|
3795
3945
|
className: cx("ui-datefield", "ui-rangefield", open && "is-open"),
|
|
3796
3946
|
"aria-label": value[0] ? tr("{label}:{a} 到 {b}", {
|
|
3797
3947
|
label: label || tr("期間"),
|
|
3798
|
-
a:
|
|
3799
|
-
b:
|
|
3800
|
-
}) : `${label || tr("期間")}
|
|
3948
|
+
a: day(value[0]),
|
|
3949
|
+
b: day(value[1])
|
|
3950
|
+
}) : `${label || tr("期間")}${tr(":")}${placeholder || tr("選擇期間")}`,
|
|
3801
3951
|
children: [/* @__PURE__ */ jsx(Icon, {
|
|
3802
3952
|
name: "calendar-blank",
|
|
3803
3953
|
size: 18
|
|
3804
|
-
}), /* @__PURE__ */ jsx("span", { children: value[0] ? `${
|
|
3954
|
+
}), /* @__PURE__ */ jsx("span", { children: value[0] ? `${day(value[0])} – ${day(value[1])}` : placeholder || tr("選擇期間") })]
|
|
3805
3955
|
}),
|
|
3806
3956
|
children: [/* @__PURE__ */ jsx("div", {
|
|
3807
3957
|
className: "ui-quick",
|
|
@@ -4041,7 +4191,7 @@ function ErrorPage({ code, title, description, onBack, onHome, homeHref = "/", c
|
|
|
4041
4191
|
}
|
|
4042
4192
|
// src/components/ProgressBar/ProgressBar.tsx
|
|
4043
4193
|
/** Progress of a task with a known end, with the percentage after the bar. */
|
|
4044
|
-
function ProgressBar({ value, label, className }) {
|
|
4194
|
+
function ProgressBar({ value, label, className, ...aria }) {
|
|
4045
4195
|
const v = Math.max(0, Math.min(100, value || 0));
|
|
4046
4196
|
const done = v >= 100;
|
|
4047
4197
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -4057,7 +4207,7 @@ function ProgressBar({ value, label, className }) {
|
|
|
4057
4207
|
"aria-valuemin": 0,
|
|
4058
4208
|
"aria-valuemax": 100,
|
|
4059
4209
|
"aria-valuenow": Math.round(v),
|
|
4060
|
-
"aria-label": label,
|
|
4210
|
+
"aria-label": label || aria["aria-label"],
|
|
4061
4211
|
children: /* @__PURE__ */ jsx("div", {
|
|
4062
4212
|
className: "ui-progress-fill",
|
|
4063
4213
|
style: { width: v + "%" }
|
|
@@ -4149,7 +4299,10 @@ function FileUpload({ label, files = [], onAdd, onRemove, onRetry, limitText, ac
|
|
|
4149
4299
|
className: "ui-upload-size",
|
|
4150
4300
|
children: fl.size
|
|
4151
4301
|
}) : null]
|
|
4152
|
-
}), !fail ? /* @__PURE__ */ jsx(ProgressBar, {
|
|
4302
|
+
}), !fail ? /* @__PURE__ */ jsx(ProgressBar, {
|
|
4303
|
+
value: fl.status === "done" ? 100 : fl.progress || 0,
|
|
4304
|
+
"aria-label": tr("{name} 上傳進度", { name: fl.name })
|
|
4305
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
4153
4306
|
className: "ui-upload-error",
|
|
4154
4307
|
role: "alert",
|
|
4155
4308
|
children: [fl.error || tr("上傳失敗,請再試一次。"), onRetry ? /* @__PURE__ */ jsx("button", {
|
|
@@ -4350,7 +4503,7 @@ function Swatch({ type }) {
|
|
|
4350
4503
|
y1: 4,
|
|
4351
4504
|
x2: 28,
|
|
4352
4505
|
y2: 4,
|
|
4353
|
-
className: cx("ui-graph-edge", type === "inferred" && "is-inferred")
|
|
4506
|
+
className: cx("ui-graph-edge", type === "inferred" && "is-inferred", type === "declared" && "is-declared")
|
|
4354
4507
|
})
|
|
4355
4508
|
});
|
|
4356
4509
|
}
|
|
@@ -4455,6 +4608,20 @@ function KpiCard(props) {
|
|
|
4455
4608
|
const scrollMemory = /* @__PURE__ */ new Map();
|
|
4456
4609
|
let measure;
|
|
4457
4610
|
const SPLIT = /(`[^`]+`|\d[\d,.]*)/;
|
|
4611
|
+
/** A label with a number: {n} in a string, or a function of the number; the number comes back as \u0001 (monoNums). */
|
|
4612
|
+
function withNum(label, n, fallback) {
|
|
4613
|
+
if (typeof label === "function") {
|
|
4614
|
+
const t = label(n);
|
|
4615
|
+
for (const s of [format.number(n), String(n)]) if (t.includes(s)) return t.replace(s, "");
|
|
4616
|
+
return t;
|
|
4617
|
+
}
|
|
4618
|
+
return (label ?? fallback(n)).replace("{n}", "");
|
|
4619
|
+
}
|
|
4620
|
+
/** The default for one (「1 call」) where the language has its own word for it, else the {n} form. */
|
|
4621
|
+
function byCount(n, one, many) {
|
|
4622
|
+
const t = n === 1 ? tr(one) : "";
|
|
4623
|
+
return t && t !== one ? t : tr(many);
|
|
4624
|
+
}
|
|
4458
4625
|
function labelWidth(text) {
|
|
4459
4626
|
const parts = text.split(SPLIT).filter(Boolean);
|
|
4460
4627
|
if (measure === void 0) measure = document.createElement("canvas").getContext("2d");
|
|
@@ -4481,7 +4648,7 @@ function wraps(text) {
|
|
|
4481
4648
|
for (const t of text.match(/`[^`]+`|[A-Za-z0-9_./:#@-]+|\s+|[\s\S]/gu) ?? []) {
|
|
4482
4649
|
const prev = atoms[atoms.length - 1];
|
|
4483
4650
|
const unit = /\d\s*$/.test(prev ?? "") && !/^[A-Za-z0-9_]/.test(t);
|
|
4484
|
-
if (prev != null && (unit || /^[)」』、,。:;!?)\]]/.test(t) || /[(「『([]$/.test(prev))) atoms[atoms.length - 1] = prev + t;
|
|
4651
|
+
if (prev != null && (unit || /^[)」』、,。:;!?)\],;!?]/.test(t) || /[(「『([]$/.test(prev))) atoms[atoms.length - 1] = prev + t;
|
|
4485
4652
|
else atoms.push(t);
|
|
4486
4653
|
}
|
|
4487
4654
|
const fill = (max) => {
|
|
@@ -4551,7 +4718,7 @@ const clean = (pts) => pts.filter((q, i) => {
|
|
|
4551
4718
|
});
|
|
4552
4719
|
/** Architecture as layers of boxes with arrows. Line width shows how often; inferred relations are dashed and labelled;
|
|
4553
4720
|
* shared items are listed under the diagram instead of drawn. Wider than its box: the boxes narrow (down to 120 px),
|
|
4554
|
-
* then the whole diagram scales down (to 0.75 at least); past that it scrolls sideways (PM). */
|
|
4721
|
+
* then the whole diagram scales down (to 0.75 at least); past that it scrolls sideways at full width (PM, WA). */
|
|
4555
4722
|
function LayerGraph(p) {
|
|
4556
4723
|
const [avail, setAvail] = React.useState(0);
|
|
4557
4724
|
const [fit, setFit] = React.useState(null);
|
|
@@ -4559,7 +4726,13 @@ function LayerGraph(p) {
|
|
|
4559
4726
|
const NW = fitted?.nw ?? (p.nodeWidth || 200);
|
|
4560
4727
|
const NH = 60;
|
|
4561
4728
|
const GAP = 56;
|
|
4562
|
-
const
|
|
4729
|
+
const spreadKey = avail + "#" + p.nodes.map((n) => n.id).join("|") + "#" + p.edges.map((e) => e.from + ">" + e.to + ":" + (e.label ?? "")).join("|");
|
|
4730
|
+
const [spreadAt, setSpread] = React.useState({
|
|
4731
|
+
key: "",
|
|
4732
|
+
n: 0
|
|
4733
|
+
});
|
|
4734
|
+
const spread = spreadAt.key === spreadKey ? spreadAt.n : 0;
|
|
4735
|
+
const COL = (fitted?.col ?? 40) + spread * 24;
|
|
4563
4736
|
const scale = fitted?.scale ?? 1;
|
|
4564
4737
|
const PAD = 16;
|
|
4565
4738
|
const all = p.nodes;
|
|
@@ -4571,6 +4744,7 @@ function LayerGraph(p) {
|
|
|
4571
4744
|
const main = all.filter((n) => !n.shared);
|
|
4572
4745
|
const shared = all.filter((n) => n.shared);
|
|
4573
4746
|
const edges = p.edges.filter((e) => !sharedIds.has(e.from) && !sharedIds.has(e.to));
|
|
4747
|
+
const lab = (e) => !!(e.inferred || e.declared);
|
|
4574
4748
|
const byLayer = /* @__PURE__ */ new Map();
|
|
4575
4749
|
const EXTERNAL = Number.NEGATIVE_INFINITY;
|
|
4576
4750
|
for (const n of main) {
|
|
@@ -4596,13 +4770,25 @@ function LayerGraph(p) {
|
|
|
4596
4770
|
});
|
|
4597
4771
|
});
|
|
4598
4772
|
const rowTop = (k) => PAD + k * NH + gaps.slice(0, k).reduce((a, b) => a + b, 0);
|
|
4773
|
+
const extRow = byLayer.get(EXTERNAL) ?? [];
|
|
4774
|
+
const extW = Math.max(NW, Math.min(p.nodeWidth || 200, W - PAD));
|
|
4775
|
+
const boxOf = (id) => {
|
|
4776
|
+
const wide = extRow.length === 1 && extRow[0].id === id ? extW : NW;
|
|
4777
|
+
return {
|
|
4778
|
+
x: pos[id].x + (NW - wide) / 2,
|
|
4779
|
+
w: wide
|
|
4780
|
+
};
|
|
4781
|
+
};
|
|
4599
4782
|
const placeRows = () => {
|
|
4600
4783
|
for (const id in pos) pos[id].y = rowTop(layerIndex[id]);
|
|
4601
|
-
H = rowTop(layers.length - 1) + NH + PAD;
|
|
4784
|
+
H = rowTop(layers.length - 1) + NH + PAD + (flatRow[layers.length - 1]?.length ? FLAT_ROOM : 0);
|
|
4602
4785
|
};
|
|
4603
4786
|
const maxSize = Math.max(1, ...main.map((n) => sizeOf(n) || 0));
|
|
4604
4787
|
const maxCount = Math.max(1, ...edges.map((e) => e.count || 0));
|
|
4605
4788
|
const isUp = (e) => !!pos[e.from] && !!pos[e.to] && layerIndex[e.to] < layerIndex[e.from];
|
|
4789
|
+
const isFlat = (e) => !!pos[e.from] && !!pos[e.to] && e.from !== e.to && layerIndex[e.to] === layerIndex[e.from];
|
|
4790
|
+
const flatIn = {};
|
|
4791
|
+
const flatRow = {};
|
|
4606
4792
|
const outs = {};
|
|
4607
4793
|
const ins = {};
|
|
4608
4794
|
const upOut = {};
|
|
@@ -4615,8 +4801,14 @@ function LayerGraph(p) {
|
|
|
4615
4801
|
continue;
|
|
4616
4802
|
}
|
|
4617
4803
|
(outs[e.from] ??= []).push(e);
|
|
4804
|
+
if (isFlat(e)) {
|
|
4805
|
+
(flatIn[e.to] ??= []).push(e);
|
|
4806
|
+
(flatRow[layerIndex[e.from]] ??= []).push(e);
|
|
4807
|
+
continue;
|
|
4808
|
+
}
|
|
4618
4809
|
(ins[e.to] ??= []).push(e);
|
|
4619
4810
|
}
|
|
4811
|
+
const FLAT_ROOM = 20 + 10 * Math.max(0, (flatRow[layers.length - 1]?.length ?? 0) - 1);
|
|
4620
4812
|
const ups = edges.filter(isUp);
|
|
4621
4813
|
const rowOf = (id) => byLayer.get(layers[layerIndex[id]]) ?? [];
|
|
4622
4814
|
const rightmost = (id) => rowOf(id)[rowOf(id).length - 1]?.id === id;
|
|
@@ -4677,8 +4869,19 @@ function LayerGraph(p) {
|
|
|
4677
4869
|
p.onSelect?.(on ? null : id);
|
|
4678
4870
|
};
|
|
4679
4871
|
const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
|
|
4680
|
-
const countText = (e) =>
|
|
4681
|
-
|
|
4872
|
+
const countText = (e) => {
|
|
4873
|
+
const n = e.count ?? 0;
|
|
4874
|
+
return typeof p.countLabel === "function" ? p.countLabel(n) : (p.countLabel ?? byCount(n, "1 次", "{n} 次")).replace("{n}", format.number(n));
|
|
4875
|
+
};
|
|
4876
|
+
const midSentence = (t) => /^[A-Z][a-z]/.test(t) && !/^zh/i.test(format.locale()) ? t[0].toLowerCase() + t.slice(1) : t;
|
|
4877
|
+
const sameLabel = /* @__PURE__ */ new Map();
|
|
4878
|
+
for (const e of edges) if (lab(e) && e.label && pos[e.from] && pos[e.to]) sameLabel.set(e.label, (sameLabel.get(e.label) ?? 0) + 1);
|
|
4879
|
+
const kindWord = (e) => e.declared ? p.declaredLabel || tr("宣告") : p.inferredLabel || tr("推測");
|
|
4880
|
+
const inferredText = (e) => e.label && (sameLabel.get(e.label) ?? 0) > 1 ? tr("來自 {from},{label}", {
|
|
4881
|
+
from: nameOf(e.from),
|
|
4882
|
+
label: midSentence(e.label)
|
|
4883
|
+
}) : e.label || kindWord(e);
|
|
4884
|
+
const markText = (e) => lab(e) ? inferredText(e) : countText(e);
|
|
4682
4885
|
if (upsL.length) {
|
|
4683
4886
|
const left0 = Math.min(...main.map((n) => pos[n.id].x));
|
|
4684
4887
|
const shift = Math.max(0, PAD + (upsL.length - 1) * LANE_STEP + LANE - left0);
|
|
@@ -4706,7 +4909,7 @@ function LayerGraph(p) {
|
|
|
4706
4909
|
const laneCount = {};
|
|
4707
4910
|
{
|
|
4708
4911
|
const into = {};
|
|
4709
|
-
for (const e of edges) if (ins[e.to]?.includes(e) && (e
|
|
4912
|
+
for (const e of edges) if (ins[e.to]?.includes(e) && (lab(e) || related(e))) (into[e.to] ??= []).push(e);
|
|
4710
4913
|
for (const id in into) {
|
|
4711
4914
|
if (into[id].length < 2) continue;
|
|
4712
4915
|
laneGroups[id] = into[id].sort((a, b) => txOf(b) - txOf(a));
|
|
@@ -4718,12 +4921,13 @@ function LayerGraph(p) {
|
|
|
4718
4921
|
const labels = [];
|
|
4719
4922
|
const need = /* @__PURE__ */ new Set();
|
|
4720
4923
|
const crowd = /* @__PURE__ */ new Set();
|
|
4924
|
+
let covered = 0;
|
|
4721
4925
|
const geomOf = (e) => {
|
|
4722
4926
|
const a = pos[e.from];
|
|
4723
4927
|
const b = pos[e.to];
|
|
4724
4928
|
const oi = outs[e.from].indexOf(e);
|
|
4725
4929
|
const on = outs[e.from].length;
|
|
4726
|
-
const sx =
|
|
4930
|
+
const sx = outX(a.x, oi, on);
|
|
4727
4931
|
const sy = a.y + NH;
|
|
4728
4932
|
const tx = txOf(e);
|
|
4729
4933
|
const ty = b.y;
|
|
@@ -4751,12 +4955,81 @@ function LayerGraph(p) {
|
|
|
4751
4955
|
};
|
|
4752
4956
|
};
|
|
4753
4957
|
const lanes = /* @__PURE__ */ new Map();
|
|
4958
|
+
const outX = (x, i, n) => Math.round(n < 2 ? x + NW / 2 : x + 16 + (NW - 32) * i / (n - 1));
|
|
4959
|
+
const flatOf = (e) => {
|
|
4960
|
+
const a = pos[e.from];
|
|
4961
|
+
const b = pos[e.to];
|
|
4962
|
+
const oi = outs[e.from].indexOf(e);
|
|
4963
|
+
const on = outs[e.from].length;
|
|
4964
|
+
const sx = outX(a.x, oi, on);
|
|
4965
|
+
const j = flatRow[layerIndex[e.from]].indexOf(e);
|
|
4966
|
+
const ti = flatIn[e.to].indexOf(e);
|
|
4967
|
+
const tx = Math.round(b.x + NW - 24 - ti * 12);
|
|
4968
|
+
return {
|
|
4969
|
+
sx,
|
|
4970
|
+
sy: a.y + NH,
|
|
4971
|
+
y: a.y + NH + 14 + j * 10,
|
|
4972
|
+
tx,
|
|
4973
|
+
ty: b.y + NH
|
|
4974
|
+
};
|
|
4975
|
+
};
|
|
4976
|
+
const vertsOf = (e) => {
|
|
4977
|
+
if (isFlat(e)) {
|
|
4978
|
+
const f = flatOf(e);
|
|
4979
|
+
return [{
|
|
4980
|
+
x: f.sx,
|
|
4981
|
+
y0: f.sy,
|
|
4982
|
+
y1: f.y
|
|
4983
|
+
}, {
|
|
4984
|
+
x: f.tx,
|
|
4985
|
+
y0: f.ty,
|
|
4986
|
+
y1: f.y
|
|
4987
|
+
}];
|
|
4988
|
+
}
|
|
4989
|
+
if (isUp(e)) return [{
|
|
4990
|
+
x: laneX(e),
|
|
4991
|
+
y0: pos[e.to].y,
|
|
4992
|
+
y1: pos[e.from].y + NH
|
|
4993
|
+
}];
|
|
4994
|
+
const g = geomOf(e);
|
|
4995
|
+
if (!g.skip) return [{
|
|
4996
|
+
x: g.sx,
|
|
4997
|
+
y0: g.sy,
|
|
4998
|
+
y1: g.y1
|
|
4999
|
+
}, {
|
|
5000
|
+
x: g.tx,
|
|
5001
|
+
y0: g.y1,
|
|
5002
|
+
y1: g.ty
|
|
5003
|
+
}];
|
|
5004
|
+
const y2 = g.ty - gaps[layerIndex[e.to] - 1] / 2 + g.off;
|
|
5005
|
+
return [
|
|
5006
|
+
{
|
|
5007
|
+
x: g.sx,
|
|
5008
|
+
y0: g.sy,
|
|
5009
|
+
y1: g.y1
|
|
5010
|
+
},
|
|
5011
|
+
{
|
|
5012
|
+
x: g.chx,
|
|
5013
|
+
y0: g.y1,
|
|
5014
|
+
y1: y2
|
|
5015
|
+
},
|
|
5016
|
+
{
|
|
5017
|
+
x: g.tx,
|
|
5018
|
+
y0: y2,
|
|
5019
|
+
y1: g.ty
|
|
5020
|
+
}
|
|
5021
|
+
];
|
|
5022
|
+
};
|
|
4754
5023
|
for (const id in laneGroups) {
|
|
4755
5024
|
const group = laneGroups[id].map((e) => ({
|
|
4756
5025
|
e,
|
|
4757
5026
|
g: geomOf(e),
|
|
4758
5027
|
w: Math.ceil(labelWidth(markText(e)))
|
|
4759
5028
|
}));
|
|
5029
|
+
const others = edges.filter((e) => !laneGroups[id].includes(e) && pos[e.from] && pos[e.to]).flatMap((e) => vertsOf(e).map((v) => ({
|
|
5030
|
+
k: -1,
|
|
5031
|
+
...v
|
|
5032
|
+
})));
|
|
4760
5033
|
const n = group.length;
|
|
4761
5034
|
const laneY = (j) => group[0].g.ty - 8 - 16 - j * LANE_H;
|
|
4762
5035
|
const perms = [];
|
|
@@ -4770,7 +5043,7 @@ function LayerGraph(p) {
|
|
|
4770
5043
|
for (const perm of perms) {
|
|
4771
5044
|
const ys = [];
|
|
4772
5045
|
perm.forEach((k, j) => ys[k] = laneY(j));
|
|
4773
|
-
const verts = group.flatMap((q, k) => [{
|
|
5046
|
+
const verts = [...group.flatMap((q, k) => [{
|
|
4774
5047
|
k,
|
|
4775
5048
|
x: q.g.from,
|
|
4776
5049
|
y0: q.g.startY,
|
|
@@ -4780,7 +5053,7 @@ function LayerGraph(p) {
|
|
|
4780
5053
|
x: q.g.tx,
|
|
4781
5054
|
y0: ys[k],
|
|
4782
5055
|
y1: q.g.ty - 8
|
|
4783
|
-
}]);
|
|
5056
|
+
}]), ...others];
|
|
4784
5057
|
const free = (k, x0, x1) => verts.every((v) => v.k === k ? !(v.x > x0 - 1 && v.x < x1 + 1 && v.y0 < ys[k] + 7 && v.y1 > ys[k] - 7) : !(v.x > x0 - 5 && v.x < x1 + 5 && v.y0 < ys[k] + 10 && v.y1 > ys[k] - 10));
|
|
4785
5058
|
let fails = 0;
|
|
4786
5059
|
const sides = [];
|
|
@@ -4811,6 +5084,7 @@ function LayerGraph(p) {
|
|
|
4811
5084
|
let least = 0;
|
|
4812
5085
|
const runs = [];
|
|
4813
5086
|
const segs = [];
|
|
5087
|
+
const ptsOf = {};
|
|
4814
5088
|
const arrows = [];
|
|
4815
5089
|
const hitPaths = [];
|
|
4816
5090
|
edges.forEach((e, idx) => {
|
|
@@ -4902,8 +5176,8 @@ function LayerGraph(p) {
|
|
|
4902
5176
|
y0 - 3,
|
|
4903
5177
|
y0 + 3
|
|
4904
5178
|
]);
|
|
4905
|
-
if (e
|
|
4906
|
-
const text =
|
|
5179
|
+
if (lab(e) || r) {
|
|
5180
|
+
const text = markText(e);
|
|
4907
5181
|
marks.push({
|
|
4908
5182
|
idx,
|
|
4909
5183
|
e,
|
|
@@ -4916,6 +5190,43 @@ function LayerGraph(p) {
|
|
|
4916
5190
|
up: true
|
|
4917
5191
|
});
|
|
4918
5192
|
}
|
|
5193
|
+
} else if (isFlat(e)) {
|
|
5194
|
+
const f = flatOf(e);
|
|
5195
|
+
tx = f.tx;
|
|
5196
|
+
ty = f.ty;
|
|
5197
|
+
pts = [
|
|
5198
|
+
[f.sx, f.sy],
|
|
5199
|
+
[f.sx, f.y],
|
|
5200
|
+
[f.tx, f.y],
|
|
5201
|
+
[f.tx, f.ty + 9]
|
|
5202
|
+
];
|
|
5203
|
+
arrow = `M${tx - 5} ${ty + 9} L${tx + 5} ${ty + 9} L${tx} ${ty} Z`;
|
|
5204
|
+
arrows.push([
|
|
5205
|
+
tx - 5,
|
|
5206
|
+
tx + 5,
|
|
5207
|
+
ty,
|
|
5208
|
+
ty + 9
|
|
5209
|
+
]);
|
|
5210
|
+
runs.push([
|
|
5211
|
+
Math.min(f.sx, f.tx),
|
|
5212
|
+
Math.max(f.sx, f.tx),
|
|
5213
|
+
f.y - 3,
|
|
5214
|
+
f.y + 3
|
|
5215
|
+
]);
|
|
5216
|
+
if (lab(e) || r) {
|
|
5217
|
+
const text = markText(e);
|
|
5218
|
+
marks.push({
|
|
5219
|
+
idx,
|
|
5220
|
+
e,
|
|
5221
|
+
text,
|
|
5222
|
+
tx: Math.round((f.sx + f.tx) / 2),
|
|
5223
|
+
ty: f.y,
|
|
5224
|
+
left: false,
|
|
5225
|
+
r,
|
|
5226
|
+
dim,
|
|
5227
|
+
flat: true
|
|
5228
|
+
});
|
|
5229
|
+
}
|
|
4919
5230
|
} else {
|
|
4920
5231
|
inn = ins[e.to].length;
|
|
4921
5232
|
const g = geomOf(e);
|
|
@@ -4952,8 +5263,9 @@ function LayerGraph(p) {
|
|
|
4952
5263
|
ty
|
|
4953
5264
|
]);
|
|
4954
5265
|
}
|
|
4955
|
-
const w = (e
|
|
5266
|
+
const w = (lab(e) ? 1.5 : 1.5 + 5.5 * ((e.count || 0) / maxCount)) + (picked ? 1.5 : 0) + (hovered ? 2 : 0);
|
|
4956
5267
|
const cpts = clean(pts);
|
|
5268
|
+
ptsOf[idx] = cpts;
|
|
4957
5269
|
for (let k = 1; k < cpts.length; k++) {
|
|
4958
5270
|
const [ax, ay] = cpts[k - 1];
|
|
4959
5271
|
const [bx, by] = cpts[k];
|
|
@@ -4969,7 +5281,7 @@ function LayerGraph(p) {
|
|
|
4969
5281
|
}
|
|
4970
5282
|
const d = route(cpts, 10);
|
|
4971
5283
|
paths.push(/* @__PURE__ */ jsx("path", {
|
|
4972
|
-
className: cx("ui-lg-edge", e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
|
|
5284
|
+
className: cx("ui-lg-edge", e.declared ? "is-declared" : e.inferred && "is-inferred", r && "is-related", dim && "is-dim", hovered && "is-hover"),
|
|
4973
5285
|
d,
|
|
4974
5286
|
strokeWidth: w
|
|
4975
5287
|
}, "p" + idx));
|
|
@@ -4988,7 +5300,7 @@ function LayerGraph(p) {
|
|
|
4988
5300
|
"aria-label": tr("{from} → {to},{what}", {
|
|
4989
5301
|
from: nameOf(e.from),
|
|
4990
5302
|
to: nameOf(e.to),
|
|
4991
|
-
what: (e
|
|
5303
|
+
what: markText(e).replace(/`/g, "")
|
|
4992
5304
|
}),
|
|
4993
5305
|
"aria-pressed": picked,
|
|
4994
5306
|
onClick: (ev) => {
|
|
@@ -5010,8 +5322,8 @@ function LayerGraph(p) {
|
|
|
5010
5322
|
className: cx("ui-lg-arrow", r && "is-related", dim && "is-dim"),
|
|
5011
5323
|
d: arrow
|
|
5012
5324
|
}, "a" + idx));
|
|
5013
|
-
if (!up && (e
|
|
5014
|
-
const text =
|
|
5325
|
+
if (!up && !isFlat(e) && (lab(e) || r)) {
|
|
5326
|
+
const text = markText(e);
|
|
5015
5327
|
marks.push({
|
|
5016
5328
|
idx,
|
|
5017
5329
|
e,
|
|
@@ -5029,16 +5341,52 @@ function LayerGraph(p) {
|
|
|
5029
5341
|
});
|
|
5030
5342
|
const placed = [...arrows, ...runs];
|
|
5031
5343
|
const boxRects = main.map((n) => [
|
|
5032
|
-
|
|
5033
|
-
|
|
5344
|
+
boxOf(n.id).x,
|
|
5345
|
+
boxOf(n.id).x + boxOf(n.id).w,
|
|
5034
5346
|
pos[n.id].y,
|
|
5035
5347
|
pos[n.id].y + NH
|
|
5036
5348
|
]);
|
|
5037
5349
|
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);
|
|
5038
5350
|
const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
|
|
5039
|
-
const
|
|
5351
|
+
const alongLine = (m) => {
|
|
5352
|
+
const pts = ptsOf[m.idx] ?? [];
|
|
5353
|
+
const ok = (x0, lw, y0, y1) => x0 >= PAD / 2 && x0 + lw <= W - PAD / 2 && y0 >= 2 && y1 <= H - 2 && !hits(x0 - 2, x0 + lw + 2, y0 - 2, y1 + 2) && !boxRects.some((q) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : x0 < sg.box[1] + 2 && sg.box[0] < x0 + lw + 2 && y0 < sg.box[3] + 2 && sg.box[2] < y1 + 2);
|
|
5354
|
+
for (const lines of wraps(m.text)) {
|
|
5355
|
+
const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
|
|
5356
|
+
const lh = lines.length * 16;
|
|
5357
|
+
let best = null;
|
|
5358
|
+
for (let k = 1; k < pts.length; k++) {
|
|
5359
|
+
const [ax, ay] = pts[k - 1];
|
|
5360
|
+
const [bx, by] = pts[k];
|
|
5361
|
+
const len = Math.hypot(bx - ax, by - ay);
|
|
5362
|
+
for (let t = 0; t <= len; t += 6) {
|
|
5363
|
+
const x = ax + (bx - ax) * t / len;
|
|
5364
|
+
const y = ay + (by - ay) * t / len;
|
|
5365
|
+
const cands = ax === bx ? [[x + 8, y], [x - 8 - lw, y]] : [[x - lw / 2, y - 6 - lh / 2], [x - lw / 2, y + 6 + lh / 2]];
|
|
5366
|
+
for (const [x0, top] of cands) {
|
|
5367
|
+
const d = Math.hypot(x0 + lw / 2 - m.tx, top - m.ty);
|
|
5368
|
+
if (best && d >= best.d) continue;
|
|
5369
|
+
if (ok(x0, lw, top - lh / 2, top + lh / 2)) best = {
|
|
5370
|
+
x0,
|
|
5371
|
+
top,
|
|
5372
|
+
d
|
|
5373
|
+
};
|
|
5374
|
+
}
|
|
5375
|
+
}
|
|
5376
|
+
}
|
|
5377
|
+
if (best) return {
|
|
5378
|
+
x0: Math.round(best.x0),
|
|
5379
|
+
top: Math.round(best.top),
|
|
5380
|
+
lw,
|
|
5381
|
+
lh,
|
|
5382
|
+
lines
|
|
5383
|
+
};
|
|
5384
|
+
}
|
|
5385
|
+
return null;
|
|
5386
|
+
};
|
|
5387
|
+
const labelEl = (m, x0, top, lines = [m.text], over = false) => /* @__PURE__ */ jsx("span", {
|
|
5040
5388
|
"aria-hidden": pickEdge ? true : void 0,
|
|
5041
|
-
className: cx("ui-lg-label", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim", peek && !m.r && hover !== edgeId(m.e) && m.e !== selEdge && "is-quiet"),
|
|
5389
|
+
className: cx("ui-lg-label", over && "is-over", pickEdge && "is-clickable", pickEdge && hover === edgeId(m.e) && "is-hover", m.r && "is-related", m.dim && "is-dim", peek && !m.r && hover !== edgeId(m.e) && m.e !== selEdge && "is-quiet"),
|
|
5042
5390
|
style: {
|
|
5043
5391
|
left: x0,
|
|
5044
5392
|
top
|
|
@@ -5051,8 +5399,37 @@ function LayerGraph(p) {
|
|
|
5051
5399
|
onPointerLeave: pickEdge ? () => setHover(null) : void 0,
|
|
5052
5400
|
children: lines.map((t, i) => /* @__PURE__ */ jsxs(React.Fragment, { children: [i ? /* @__PURE__ */ jsx("br", {}) : null, labelParts(t)] }, i))
|
|
5053
5401
|
}, "l" + m.idx);
|
|
5054
|
-
|
|
5402
|
+
const later = [];
|
|
5403
|
+
const place = (m, last) => {
|
|
5055
5404
|
const w = Math.ceil(labelWidth(m.text));
|
|
5405
|
+
if (m.flat) {
|
|
5406
|
+
let spot = alongLine(m);
|
|
5407
|
+
if (!spot) {
|
|
5408
|
+
const g = layerIndex[m.e.from];
|
|
5409
|
+
if (g < layers.length - 1) need.add(g);
|
|
5410
|
+
covered++;
|
|
5411
|
+
const x0 = Math.max(PAD / 2, Math.min(W - PAD / 2 - w, m.tx - w / 2));
|
|
5412
|
+
const taken = (t) => hits(x0, x0 + w, t - 10, t + 10) || boxRects.some((q) => x0 < q[1] + 2 && q[0] < x0 + w + 2 && t - 10 < q[3] && q[2] < t + 10);
|
|
5413
|
+
let top = m.ty + 14;
|
|
5414
|
+
for (let k = 0; k < 8 && taken(top); k++) top += 18;
|
|
5415
|
+
spot = {
|
|
5416
|
+
x0,
|
|
5417
|
+
top,
|
|
5418
|
+
lw: w,
|
|
5419
|
+
lh: 16,
|
|
5420
|
+
lines: [m.text]
|
|
5421
|
+
};
|
|
5422
|
+
}
|
|
5423
|
+
placed.push([
|
|
5424
|
+
spot.x0,
|
|
5425
|
+
spot.x0 + spot.lw,
|
|
5426
|
+
spot.top - spot.lh / 2 - 4,
|
|
5427
|
+
spot.top + spot.lh / 2 + 4,
|
|
5428
|
+
6
|
|
5429
|
+
]);
|
|
5430
|
+
labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
|
|
5431
|
+
return;
|
|
5432
|
+
}
|
|
5056
5433
|
if (m.up) {
|
|
5057
5434
|
const x0Of = (lw) => Math.max(PAD / 2, Math.min(W - PAD / 2 - lw, m.left ? m.tx - lw : m.tx));
|
|
5058
5435
|
const start0 = Math.max(10, Math.min(H - 10, m.ty));
|
|
@@ -5082,9 +5459,11 @@ function LayerGraph(p) {
|
|
|
5082
5459
|
break;
|
|
5083
5460
|
}
|
|
5084
5461
|
}
|
|
5462
|
+
if (!spot) spot = alongLine(m);
|
|
5085
5463
|
if (!spot) {
|
|
5086
5464
|
const g = Math.max(0, Math.min(layers.length - 2, layers.findIndex((_, k) => k < layers.length - 1 && m.ty < rowTop(k + 1))));
|
|
5087
5465
|
need.add(g);
|
|
5466
|
+
covered++;
|
|
5088
5467
|
const x0 = x0Of(w);
|
|
5089
5468
|
const top = find(x0, w, 16, false);
|
|
5090
5469
|
if (top == null) crowd.add(g);
|
|
@@ -5159,8 +5538,15 @@ function LayerGraph(p) {
|
|
|
5159
5538
|
}
|
|
5160
5539
|
if (spot) break;
|
|
5161
5540
|
}
|
|
5541
|
+
if (!spot) spot = alongLine(m);
|
|
5542
|
+
if (!spot && !last) {
|
|
5543
|
+
later.push(m);
|
|
5544
|
+
return;
|
|
5545
|
+
}
|
|
5546
|
+
const over = !spot;
|
|
5162
5547
|
if (!spot) {
|
|
5163
5548
|
if (g >= 0) need.add(g);
|
|
5549
|
+
covered++;
|
|
5164
5550
|
const offBoxes = (x0, lw, y0, y1) => !hits(x0, x0 + lw, y0, y1) && !boxRects.some((q) => x0 < q[1] + 2 && q[0] < x0 + lw + 2 && y0 < q[3] + 2 && q[2] < y1 + 2);
|
|
5165
5551
|
for (const lines of wraps(m.text)) {
|
|
5166
5552
|
const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
|
|
@@ -5201,14 +5587,16 @@ function LayerGraph(p) {
|
|
|
5201
5587
|
placed.push([
|
|
5202
5588
|
spot.x0,
|
|
5203
5589
|
spot.x0 + spot.lw,
|
|
5204
|
-
spot.top - spot.lh / 2,
|
|
5205
|
-
spot.top + spot.lh / 2,
|
|
5590
|
+
spot.top - spot.lh / 2 - 4,
|
|
5591
|
+
spot.top + spot.lh / 2 + 4,
|
|
5206
5592
|
6
|
|
5207
5593
|
]);
|
|
5208
5594
|
wide = Math.max(wide, spot.x0 + spot.lw + PAD / 2 + 4);
|
|
5209
5595
|
least = Math.min(least, spot.x0 - PAD / 2 - 4);
|
|
5210
|
-
labels.push(labelEl(m, spot.x0, spot.top, spot.lines));
|
|
5211
|
-
}
|
|
5596
|
+
labels.push(labelEl(m, spot.x0, spot.top, spot.lines, over));
|
|
5597
|
+
};
|
|
5598
|
+
marks.sort((m, n) => Number(!!m.up) - Number(!!n.up) || m.ty - n.ty || m.tx - n.tx).forEach((m) => place(m, false));
|
|
5599
|
+
later.forEach((m) => place(m, true));
|
|
5212
5600
|
return {
|
|
5213
5601
|
paths,
|
|
5214
5602
|
labels,
|
|
@@ -5216,7 +5604,8 @@ function LayerGraph(p) {
|
|
|
5216
5604
|
need,
|
|
5217
5605
|
crowd,
|
|
5218
5606
|
wide,
|
|
5219
|
-
least
|
|
5607
|
+
least,
|
|
5608
|
+
covered
|
|
5220
5609
|
};
|
|
5221
5610
|
};
|
|
5222
5611
|
for (const id in laneCount) {
|
|
@@ -5255,7 +5644,7 @@ function LayerGraph(p) {
|
|
|
5255
5644
|
drawn = draw();
|
|
5256
5645
|
}
|
|
5257
5646
|
const { paths, labels, hitPaths } = drawn;
|
|
5258
|
-
const sizeText = p.sizeLabel
|
|
5647
|
+
const sizeText = (n) => withNum(p.sizeLabel, n, () => byCount(n, "1 個項目", "{n} 個項目"));
|
|
5259
5648
|
const externalText = p.externalLabel ?? tr("repo 外");
|
|
5260
5649
|
const useText = p.useLabel ?? tr("使用 {n} 次");
|
|
5261
5650
|
const nodes = main.map((n) => {
|
|
@@ -5267,9 +5656,9 @@ function LayerGraph(p) {
|
|
|
5267
5656
|
type: "button",
|
|
5268
5657
|
className: cx("ui-lg-node", n.external && "is-external", on && "is-selected", !near(n.id) && "is-dim"),
|
|
5269
5658
|
style: {
|
|
5270
|
-
left:
|
|
5659
|
+
left: boxOf(n.id).x,
|
|
5271
5660
|
top: q.y,
|
|
5272
|
-
width:
|
|
5661
|
+
width: boxOf(n.id).w,
|
|
5273
5662
|
height: NH
|
|
5274
5663
|
},
|
|
5275
5664
|
"aria-pressed": p.onSelect ? on : void 0,
|
|
@@ -5297,7 +5686,7 @@ function LayerGraph(p) {
|
|
|
5297
5686
|
children: /* @__PURE__ */ jsx("span", { style: { width: Math.round(size / maxSize * 100) + "%" } })
|
|
5298
5687
|
}), /* @__PURE__ */ jsx("span", {
|
|
5299
5688
|
className: "ui-lg-count",
|
|
5300
|
-
children: monoNums(sizeText
|
|
5689
|
+
children: monoNums(sizeText(size), [format.number(size)])
|
|
5301
5690
|
})]
|
|
5302
5691
|
}) : null
|
|
5303
5692
|
]
|
|
@@ -5323,10 +5712,10 @@ function LayerGraph(p) {
|
|
|
5323
5712
|
})]
|
|
5324
5713
|
}, s.id);
|
|
5325
5714
|
});
|
|
5326
|
-
const edgeText = (e) => e
|
|
5715
|
+
const edgeText = (e) => lab(e) ? e.label ? tr("{label}({inferred})", {
|
|
5327
5716
|
label: e.label,
|
|
5328
|
-
inferred:
|
|
5329
|
-
}) :
|
|
5717
|
+
inferred: kindWord(e)
|
|
5718
|
+
}) : kindWord(e) : countText(e);
|
|
5330
5719
|
const listItem = (key, on, dim, onClick, head, rest) => /* @__PURE__ */ jsxs("li", {
|
|
5331
5720
|
className: cx("ui-lg-li", dim && "is-dim"),
|
|
5332
5721
|
children: [onClick ? /* @__PURE__ */ jsx("button", {
|
|
@@ -5359,7 +5748,7 @@ function LayerGraph(p) {
|
|
|
5359
5748
|
children: [tr(","), externalText]
|
|
5360
5749
|
}) : size != null ? /* @__PURE__ */ jsxs("span", {
|
|
5361
5750
|
className: "ui-lg-limeta",
|
|
5362
|
-
children: [tr(","), monoNums(sizeText
|
|
5751
|
+
children: [tr(","), monoNums(sizeText(size), [format.number(size)])]
|
|
5363
5752
|
}) : null);
|
|
5364
5753
|
}) })]
|
|
5365
5754
|
}), /* @__PURE__ */ jsxs("section", {
|
|
@@ -5377,15 +5766,16 @@ function LayerGraph(p) {
|
|
|
5377
5766
|
/* @__PURE__ */ jsx("span", {
|
|
5378
5767
|
className: "ui-lg-code",
|
|
5379
5768
|
children: nameOf(e.to)
|
|
5769
|
+
}),
|
|
5770
|
+
/* @__PURE__ */ jsxs("span", {
|
|
5771
|
+
className: "ui-lg-limeta",
|
|
5772
|
+
children: [tr(":"), labelParts(edgeText(e))]
|
|
5380
5773
|
})
|
|
5381
|
-
] }),
|
|
5382
|
-
className: "ui-lg-limeta",
|
|
5383
|
-
children: [tr(":"), labelParts(edgeText(e))]
|
|
5384
|
-
}))) })]
|
|
5774
|
+
] }), null)) })]
|
|
5385
5775
|
})]
|
|
5386
5776
|
});
|
|
5387
5777
|
const showList = p.listView !== false && view === "list";
|
|
5388
|
-
const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => e
|
|
5778
|
+
const toggleShown = p.labelToggle !== false && !showList && p.edges.some((e) => lab(e));
|
|
5389
5779
|
React.useLayoutEffect(() => {
|
|
5390
5780
|
const el = scrollRef.current;
|
|
5391
5781
|
if (!el) return;
|
|
@@ -5410,11 +5800,22 @@ function LayerGraph(p) {
|
|
|
5410
5800
|
});
|
|
5411
5801
|
return;
|
|
5412
5802
|
}
|
|
5413
|
-
if (fitted.
|
|
5414
|
-
const s = avail / W;
|
|
5415
|
-
if (s
|
|
5803
|
+
if (fitted.full) return;
|
|
5804
|
+
const s = Math.floor(avail / W * 1e3) / 1e3;
|
|
5805
|
+
if (W > avail + .5 && s < .75) {
|
|
5806
|
+
setFit({
|
|
5807
|
+
...fitted,
|
|
5808
|
+
nw: p.nodeWidth || 200,
|
|
5809
|
+
col: 40,
|
|
5810
|
+
scale: 1,
|
|
5811
|
+
full: true
|
|
5812
|
+
});
|
|
5813
|
+
return;
|
|
5814
|
+
}
|
|
5815
|
+
const want = W <= avail + .5 ? 1 : s;
|
|
5816
|
+
if (want !== fitted.scale) setFit({
|
|
5416
5817
|
...fitted,
|
|
5417
|
-
scale:
|
|
5818
|
+
scale: want
|
|
5418
5819
|
});
|
|
5419
5820
|
}, [
|
|
5420
5821
|
avail,
|
|
@@ -5424,6 +5825,17 @@ function LayerGraph(p) {
|
|
|
5424
5825
|
p.nodeWidth,
|
|
5425
5826
|
cols
|
|
5426
5827
|
]);
|
|
5828
|
+
const coveredNow = drawn.covered;
|
|
5829
|
+
React.useLayoutEffect(() => {
|
|
5830
|
+
if (coveredNow && spread < 5) setSpread({
|
|
5831
|
+
key: spreadKey,
|
|
5832
|
+
n: spread + 1
|
|
5833
|
+
});
|
|
5834
|
+
}, [
|
|
5835
|
+
coveredNow,
|
|
5836
|
+
spread,
|
|
5837
|
+
spreadKey
|
|
5838
|
+
]);
|
|
5427
5839
|
return /* @__PURE__ */ jsxs("div", {
|
|
5428
5840
|
className: cx("ui-graph ui-lg", p.className),
|
|
5429
5841
|
children: [
|
|
@@ -5517,14 +5929,22 @@ function LayerGraph(p) {
|
|
|
5517
5929
|
children: sharedBoxes
|
|
5518
5930
|
})]
|
|
5519
5931
|
}) : null,
|
|
5520
|
-
showList || p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
|
|
5932
|
+
showList || p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [
|
|
5933
|
+
...edges.some((e) => !lab(e) && pos[e.from] && pos[e.to]) ? [{
|
|
5934
|
+
type: "weight",
|
|
5935
|
+
label: "次數越多線越粗"
|
|
5936
|
+
}] : [],
|
|
5937
|
+
...edges.some((e) => e.inferred && !e.declared && pos[e.from] && pos[e.to]) ? [{
|
|
5938
|
+
type: "inferred",
|
|
5939
|
+
label: p.inferredLabel || "推測的關係",
|
|
5940
|
+
text: p.inferredText
|
|
5941
|
+
}] : [],
|
|
5942
|
+
...edges.some((e) => e.declared && pos[e.from] && pos[e.to]) ? [{
|
|
5943
|
+
type: "declared",
|
|
5944
|
+
label: p.declaredLegend || "專案宣告的關係",
|
|
5945
|
+
text: p.declaredText
|
|
5946
|
+
}] : []
|
|
5947
|
+
] })
|
|
5528
5948
|
]
|
|
5529
5949
|
});
|
|
5530
5950
|
}
|
|
@@ -5542,6 +5962,10 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
|
|
|
5542
5962
|
const Y = (v) => B - v / top * 200;
|
|
5543
5963
|
const ticks = TICKS.map((f) => f * top);
|
|
5544
5964
|
const suffix = unit ? " " + unit : "";
|
|
5965
|
+
const show = (j) => {
|
|
5966
|
+
setHi(j);
|
|
5967
|
+
announce(labels[j] + tr(":") + series.map((s) => (series.length > 1 ? s.name + " " : "") + format.number(s.values[j], decimals) + suffix).join(tr(",")));
|
|
5968
|
+
};
|
|
5545
5969
|
const edge = {
|
|
5546
5970
|
left: (L - step / 2) / 640 * 100 + "%",
|
|
5547
5971
|
right: (10 - step / 2) / 640 * 100 + "%"
|
|
@@ -5558,13 +5982,22 @@ function LineChart({ series, labels, label, unit, decimals, max, labelEvery = 1,
|
|
|
5558
5982
|
}) : null,
|
|
5559
5983
|
/* @__PURE__ */ jsxs("div", {
|
|
5560
5984
|
className: "ui-chart-plot",
|
|
5985
|
+
tabIndex: n ? 0 : void 0,
|
|
5986
|
+
role: "group",
|
|
5987
|
+
"aria-label": label,
|
|
5988
|
+
"aria-description": tr("左右方向鍵查看每一個時間點的數值"),
|
|
5561
5989
|
onMouseLeave: () => setHi(-1),
|
|
5990
|
+
onFocus: () => hi < 0 && n && show(0),
|
|
5991
|
+
onBlur: () => setHi(-1),
|
|
5992
|
+
onKeyDown: (e) => {
|
|
5993
|
+
const to = chartKey(e, hi, n);
|
|
5994
|
+
if (to != null) show(to);
|
|
5995
|
+
},
|
|
5562
5996
|
children: [
|
|
5563
5997
|
/* @__PURE__ */ jsxs("svg", {
|
|
5564
5998
|
viewBox: "0 0 640 240",
|
|
5565
5999
|
width: "100%",
|
|
5566
|
-
|
|
5567
|
-
"aria-label": label,
|
|
6000
|
+
"aria-hidden": "true",
|
|
5568
6001
|
children: [ticks.map((v, i) => /* @__PURE__ */ jsxs("g", { children: [/* @__PURE__ */ jsx("line", {
|
|
5569
6002
|
x1: L,
|
|
5570
6003
|
x2: R,
|
|
@@ -5923,10 +6356,13 @@ function NotificationBell({ items, onOpen, onReadAll, emptyText }) {
|
|
|
5923
6356
|
type: "button",
|
|
5924
6357
|
className: cx("ui-noti-item", !it.read && "is-unread"),
|
|
5925
6358
|
onClick: () => onOpen?.(it),
|
|
5926
|
-
children: [!it.read ? /* @__PURE__ */ jsx("span", {
|
|
6359
|
+
children: [!it.read ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
5927
6360
|
className: "ui-noti-dot",
|
|
5928
|
-
"aria-
|
|
5929
|
-
})
|
|
6361
|
+
"aria-hidden": "true"
|
|
6362
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
6363
|
+
className: "ui-visually-hidden",
|
|
6364
|
+
children: tr("未讀") + tr(",")
|
|
6365
|
+
})] }) : null, /* @__PURE__ */ jsxs("span", {
|
|
5930
6366
|
className: "ui-noti-text",
|
|
5931
6367
|
children: [
|
|
5932
6368
|
/* @__PURE__ */ jsx("span", {
|
|
@@ -6451,6 +6887,7 @@ function Switch({ checked, onChange, label, disabled, className }) {
|
|
|
6451
6887
|
onPointerDown: () => setPressing(true),
|
|
6452
6888
|
onPointerUp: () => setPressing(false),
|
|
6453
6889
|
onPointerLeave: () => setPressing(false),
|
|
6890
|
+
onPointerCancel: () => setPressing(false),
|
|
6454
6891
|
children: /* @__PURE__ */ jsx("span", {
|
|
6455
6892
|
className: "ui-switch-thumb",
|
|
6456
6893
|
style: {
|
|
@@ -6523,7 +6960,10 @@ function TextArea({ label, hint, value, onChange, maxLength = 200, className, id
|
|
|
6523
6960
|
className: "ui-count",
|
|
6524
6961
|
children: [/* @__PURE__ */ jsx("span", {
|
|
6525
6962
|
"aria-hidden": "true",
|
|
6526
|
-
children:
|
|
6963
|
+
children: /* @__PURE__ */ jsx("span", {
|
|
6964
|
+
className: "ui-seen",
|
|
6965
|
+
"data-text": format.fraction((value || "").length, maxLength)
|
|
6966
|
+
})
|
|
6527
6967
|
}), /* @__PURE__ */ jsx("span", {
|
|
6528
6968
|
className: "ui-visually-hidden",
|
|
6529
6969
|
children: format.fractionLabel((value || "").length, maxLength, tr("字"))
|
|
@@ -6747,6 +7187,7 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
|
|
|
6747
7187
|
if (!open || !hasStep) return;
|
|
6748
7188
|
let el = findTarget(target);
|
|
6749
7189
|
const tall = (el?.getBoundingClientRect().height ?? 0) > window.innerHeight;
|
|
7190
|
+
devWarn(el && el.getBoundingClientRect().height > window.innerHeight * .7, "Tour", `第 ${i + 1} 步的目標「${target}」比視窗的 70% 高,說明卡只能蓋住它的一部分。請把 data-tour 放在較小的元素上,例如要說明的那張卡片或那一列,而不是整頁。`);
|
|
6750
7191
|
if (el instanceof HTMLElement && narrowNow()) {
|
|
6751
7192
|
const keep = el.style.scrollMarginTop;
|
|
6752
7193
|
el.style.scrollMarginTop = bounds(el).top + edge() + pad + "px";
|
|
@@ -6886,10 +7327,10 @@ function Tour({ open, steps, onClose, skippable = true, step: controlled, onStep
|
|
|
6886
7327
|
className: "ui-tour-count",
|
|
6887
7328
|
children: [/* @__PURE__ */ jsx("span", {
|
|
6888
7329
|
"aria-hidden": "true",
|
|
6889
|
-
children:
|
|
7330
|
+
children: seenOnly(tr("{n} / {total}", {
|
|
6890
7331
|
n: "",
|
|
6891
7332
|
total: ""
|
|
6892
|
-
}), [i + 1, steps.length])
|
|
7333
|
+
}), [String(i + 1), String(steps.length)])
|
|
6893
7334
|
}), /* @__PURE__ */ jsx("span", {
|
|
6894
7335
|
className: "ui-visually-hidden",
|
|
6895
7336
|
children: tr("第 {a} 步,共 {b} 步", {
|
|
@@ -7235,7 +7676,7 @@ function TreeList(p) {
|
|
|
7235
7676
|
"aria-posinset": r.pos,
|
|
7236
7677
|
"aria-setsize": r.size,
|
|
7237
7678
|
"aria-expanded": r.isF ? r.open : void 0,
|
|
7238
|
-
"aria-owns": r.isF && r.open ? `${uid}-g-${r.n.id}` : void 0,
|
|
7679
|
+
"aria-owns": r.isF && r.open ? `${uid}-g-${idPart(r.n.id)}` : void 0,
|
|
7239
7680
|
style: vars({ "--d": r.depth }),
|
|
7240
7681
|
onFocus: () => focusId !== r.n.id && setFocusId(r.n.id)
|
|
7241
7682
|
});
|
|
@@ -7336,8 +7777,8 @@ function TreeList(p) {
|
|
|
7336
7777
|
role: "alert",
|
|
7337
7778
|
children: [
|
|
7338
7779
|
tr("無法載入 {name} 的子項目", { name: r.n.name }),
|
|
7339
|
-
r.error ? ":" + r.error : "",
|
|
7340
|
-
"。"
|
|
7780
|
+
r.error ? tr(":") + r.error : "",
|
|
7781
|
+
tr("。").trim()
|
|
7341
7782
|
]
|
|
7342
7783
|
}), /* @__PURE__ */ jsx("button", {
|
|
7343
7784
|
type: "button",
|
|
@@ -7544,7 +7985,7 @@ function TreeList(p) {
|
|
|
7544
7985
|
if (!r.x && r.open && i < every.length && every[i].depth > depth) {
|
|
7545
7986
|
const [kidsOut, next] = nest(i, depth + 1);
|
|
7546
7987
|
out.push(/* @__PURE__ */ jsx("div", {
|
|
7547
|
-
id: `${uid}-g-${r.n.id}`,
|
|
7988
|
+
id: `${uid}-g-${idPart(r.n.id)}`,
|
|
7548
7989
|
role: "group",
|
|
7549
7990
|
className: "ui-tree-group",
|
|
7550
7991
|
children: kidsOut
|