@seanyeh77/ui 0.20.0 → 0.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -1,10 +1,11 @@
1
1
  "use client";
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-CfCwMZuE.js";
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-CKLBdBpY.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";
6
6
  import { Dialog as Dialog$1 } from "@base-ui/react/dialog";
7
7
  import { Menu as Menu$1 } from "@base-ui/react/menu";
8
+ import { PreviewCard } from "@base-ui/react/preview-card";
8
9
  import { Popover as Popover$1 } from "@base-ui/react/popover";
9
10
  import { Combobox } from "@base-ui/react/combobox";
10
11
  import { Select as Select$1 } from "@base-ui/react/select";
@@ -21,6 +22,7 @@ const PH = {
21
22
  "arrows-clockwise": "<path d=\"M224,48V96a8,8,0,0,1-8,8H168a8,8,0,0,1,0-16h28.69L182.06,73.37a79.56,79.56,0,0,0-56.13-23.43h-.45A79.52,79.52,0,0,0,69.59,72.71,8,8,0,0,1,58.41,61.27a96,96,0,0,1,135,.79L208,76.69V48a8,8,0,0,1,16,0ZM186.41,183.29a80,80,0,0,1-112.47-.66L59.31,168H88a8,8,0,0,0,0-16H40a8,8,0,0,0-8,8v48a8,8,0,0,0,16,0V179.31l14.63,14.63A95.43,95.43,0,0,0,130,222.06h.53a95.36,95.36,0,0,0,67.07-27.33,8,8,0,0,0-11.18-11.44Z\"/>",
22
23
  "arrows-in-line-vertical": "<path d=\"M224,128a8,8,0,0,1-8,8H40a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM122.34,101.66a8,8,0,0,0,11.32,0l32-32a8,8,0,0,0-11.32-11.32L136,76.69V16a8,8,0,0,0-16,0V76.69L101.66,58.34A8,8,0,0,0,90.34,69.66Zm11.32,52.68a8,8,0,0,0-11.32,0l-32,32a8,8,0,0,0,11.32,11.32L120,179.31V240a8,8,0,0,0,16,0V179.31l18.34,18.35a8,8,0,0,0,11.32-11.32Z\"/>",
23
24
  "arrows-out-line-vertical": "<path d=\"M224,128a8,8,0,0,1-8,8H40a8,8,0,0,1,0-16H216A8,8,0,0,1,224,128ZM101.66,53.66,120,35.31V96a8,8,0,0,0,16,0V35.31l18.34,18.35a8,8,0,0,0,11.32-11.32l-32-32a8,8,0,0,0-11.32,0l-32,32a8,8,0,0,0,11.32,11.32Zm52.68,148.68L136,220.69V160a8,8,0,0,0-16,0v60.69l-18.34-18.35a8,8,0,0,0-11.32,11.32l32,32a8,8,0,0,0,11.32,0l32-32a8,8,0,0,0-11.32-11.32Z\"/>",
25
+ "corners-out": "<path d=\"M216,48V88a8,8,0,0,1-16,0V56H168a8,8,0,0,1,0-16h40A8,8,0,0,1,216,48ZM88,200H56V168a8,8,0,0,0-16,0v40a8,8,0,0,0,8,8H88a8,8,0,0,0,0-16Zm120-40a8,8,0,0,0-8,8v32H168a8,8,0,0,0,0,16h40a8,8,0,0,0,8-8V168A8,8,0,0,0,208,160ZM88,40H48a8,8,0,0,0-8,8V88a8,8,0,0,0,16,0V56H88a8,8,0,0,0,0-16Z\"/>",
24
26
  bell: "<path d=\"M221.8,175.94C216.25,166.38,208,139.33,208,104a80,80,0,1,0-160,0c0,35.34-8.26,62.38-13.81,71.94A16,16,0,0,0,48,200H88.81a40,40,0,0,0,78.38,0H208a16,16,0,0,0,13.8-24.06ZM128,216a24,24,0,0,1-22.62-16h45.24A24,24,0,0,1,128,216ZM48,184c7.7-13.24,16-43.92,16-80a64,64,0,1,1,128,0c0,36.05,8.28,66.73,16,80Z\"/>",
25
27
  "calendar-blank": "<path d=\"M208,32H184V24a8,8,0,0,0-16,0v8H88V24a8,8,0,0,0-16,0v8H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32ZM72,48v8a8,8,0,0,0,16,0V48h80v8a8,8,0,0,0,16,0V48h24V80H48V48ZM208,208H48V96H208V208Z\"/>",
26
28
  "caret-down": "<path d=\"M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,53.66,90.34L128,164.69l74.34-74.35a8,8,0,0,1,11.32,11.32Z\"/>",
@@ -116,6 +118,7 @@ const PH_FILL = {
116
118
  "arrows-clockwise": "<path d=\"M224,48V96a8,8,0,0,1-8,8H168a8,8,0,0,1-5.66-13.66L180.65,72a79.48,79.48,0,0,0-54.72-22.09h-.45A79.52,79.52,0,0,0,69.59,72.71,8,8,0,0,1,58.41,61.27,96,96,0,0,1,192,60.7l18.36-18.36A8,8,0,0,1,224,48ZM186.41,183.29A80,80,0,0,1,75.35,184l18.31-18.31A8,8,0,0,0,88,152H40a8,8,0,0,0-8,8v48a8,8,0,0,0,13.66,5.66L64,195.3a95.42,95.42,0,0,0,66,26.76h.53a95.36,95.36,0,0,0,67.07-27.33,8,8,0,0,0-11.18-11.44Z\"/>",
117
119
  "arrows-in-line-vertical": "<path d=\"M90.34,69.66A8,8,0,0,1,96,56h24V16a8,8,0,0,1,16,0V56h24a8,8,0,0,1,5.66,13.66l-32,32a8,8,0,0,1-11.32,0Zm43.32,84.68a8,8,0,0,0-11.32,0l-32,32A8,8,0,0,0,96,200h24v40a8,8,0,0,0,16,0V200h24a8,8,0,0,0,5.66-13.66ZM216,120H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Z\"/>",
118
120
  "arrows-out-line-vertical": "<path d=\"M88.61,51.06a8,8,0,0,1,1.73-8.72l32-32a8,8,0,0,1,11.32,0l32,32A8,8,0,0,1,160,56H136V96a8,8,0,0,1-16,0V56H96A8,8,0,0,1,88.61,51.06ZM216,120H40a8,8,0,0,0,0,16H216a8,8,0,0,0,0-16Zm-56,80H136V160a8,8,0,0,0-16,0v40H96a8,8,0,0,0-5.66,13.66l32,32a8,8,0,0,0,11.32,0l32-32A8,8,0,0,0,160,200Z\"/>",
121
+ "corners-out": "<path d=\"M93.66,202.34A8,8,0,0,1,88,216H48a8,8,0,0,1-8-8V168a8,8,0,0,1,13.66-5.66ZM88,40H48a8,8,0,0,0-8,8V88a8,8,0,0,0,13.66,5.66l40-40A8,8,0,0,0,88,40ZM211.06,160.61a8,8,0,0,0-8.72,1.73l-40,40A8,8,0,0,0,168,216h40a8,8,0,0,0,8-8V168A8,8,0,0,0,211.06,160.61ZM208,40H168a8,8,0,0,0-5.66,13.66l40,40A8,8,0,0,0,216,88V48A8,8,0,0,0,208,40Z\"/>",
119
122
  bell: "<path d=\"M221.8,175.94C216.25,166.38,208,139.33,208,104a80,80,0,1,0-160,0c0,35.34-8.26,62.38-13.81,71.94A16,16,0,0,0,48,200H88.81a40,40,0,0,0,78.38,0H208a16,16,0,0,0,13.8-24.06ZM128,216a24,24,0,0,1-22.62-16h45.24A24,24,0,0,1,128,216Z\"/>",
120
123
  "calendar-blank": "<path d=\"M208,32H184V24a8,8,0,0,0-16,0v8H88V24a8,8,0,0,0-16,0v8H48A16,16,0,0,0,32,48V208a16,16,0,0,0,16,16H208a16,16,0,0,0,16-16V48A16,16,0,0,0,208,32Zm0,48H48V48H72v8a8,8,0,0,0,16,0V48h80v8a8,8,0,0,0,16,0V48h24Z\"/>",
121
124
  "caret-down": "<path d=\"M213.66,101.66l-80,80a8,8,0,0,1-11.32,0l-80-80A8,8,0,0,1,48,88H208a8,8,0,0,1,5.66,13.66Z\"/>",
@@ -2155,7 +2158,7 @@ const AFTER = /([,.([{;])/;
2155
2158
  /** A piece of code with soft break points after commas, dots and opening brackets, and operators kept together. */
2156
2159
  const PATH_IN_CODE = /(?<![\w./-])((?:\.{1,2}\/)?(?:[\w.-]+\/)+[\w.-]+\.[A-Za-z0-9]+(?::\d+(?:-\d+)?)?|[\w.-]+\.[A-Za-z0-9]+:\d+(?:-\d+)?)(?![\w/])/g;
2157
2160
  /** The paths in a comment or string as links (refHref, onRef); the rest stays text. */
2158
- function withPaths(text, refHref, onRef) {
2161
+ function withPaths(text, refHref, onRef, tab) {
2159
2162
  const out = [];
2160
2163
  let at = 0;
2161
2164
  for (const m of text.matchAll(PATH_IN_CODE)) {
@@ -2172,11 +2175,13 @@ function withPaths(text, refHref, onRef) {
2172
2175
  className: "ui-cv-ref",
2173
2176
  href,
2174
2177
  onClick: click,
2178
+ tabIndex: tab,
2175
2179
  children: v
2176
2180
  }, m.index) : /* @__PURE__ */ jsx("button", {
2177
2181
  type: "button",
2178
2182
  className: "ui-cv-ref",
2179
2183
  onClick: click,
2184
+ tabIndex: tab,
2180
2185
  children: v
2181
2186
  }, m.index));
2182
2187
  at = m.index + v.length;
@@ -2205,8 +2210,62 @@ function breakable(text) {
2205
2210
  });
2206
2211
  return out;
2207
2212
  }
2213
+ const NAME_CHAR = /[\p{L}\p{N}_$]/u;
2214
+ /** UTF-16 index of a 1-based column counted in code points; -1 past the end. */
2215
+ function colIndex(s, col) {
2216
+ let i = 0;
2217
+ for (let c = 1; c < col; c++) {
2218
+ if (i >= s.length) return -1;
2219
+ i += (s.codePointAt(i) ?? 0) > 65535 ? 2 : 1;
2220
+ }
2221
+ return i;
2222
+ }
2223
+ /** The first whole `text` on the line: not inside a longer name, and not the tail of a dotted one (x.runtime.deploy). */
2224
+ function findName(s, text) {
2225
+ for (let i = s.indexOf(text); i >= 0; i = s.indexOf(text, i + 1)) {
2226
+ const before = s[i - 1] ?? "";
2227
+ const after = s[i + text.length] ?? "";
2228
+ if (!NAME_CHAR.test(before) && before !== "." && !NAME_CHAR.test(after)) return i;
2229
+ }
2230
+ return -1;
2231
+ }
2232
+ /** Each line's links, sorted, without overlaps; what does not match is left out with a development warning. */
2233
+ function matchLinks(lines, start, links) {
2234
+ const out = /* @__PURE__ */ new Map();
2235
+ links?.forEach((l, i) => {
2236
+ const s = lines[l.line - start];
2237
+ if (s == null) {
2238
+ devWarn(true, "CodeView", `第 ${l.line} 行不在程式碼裡,連結「${l.text}」沒有加上。line 和 target 一樣從 start(${start})算起。`);
2239
+ return;
2240
+ }
2241
+ let from = -1;
2242
+ if (l.col != null) {
2243
+ const at = colIndex(s, l.col);
2244
+ if (at >= 0 && s.startsWith(l.text, at)) from = at;
2245
+ else devWarn(true, "CodeView", `第 ${l.line} 行第 ${l.col} 欄不是「${l.text}」,連結沒有加上。col 從 1 開始、以字元計;位元組或 UTF-16 位置要先換算。`);
2246
+ } else {
2247
+ from = findName(s, l.text);
2248
+ devWarn(from < 0, "CodeView", `第 ${l.line} 行找不到完整的「${l.text}」,連結沒有加上。text 要和程式碼一字不差(整個帶點的名稱),或給 col。`);
2249
+ }
2250
+ if (from < 0) return;
2251
+ const hit = {
2252
+ from,
2253
+ to: from + l.text.length,
2254
+ i
2255
+ };
2256
+ const list = out.get(l.line) ?? [];
2257
+ if (list.some((h) => h.from < hit.to && hit.from < h.to)) {
2258
+ devWarn(true, "CodeView", `第 ${l.line} 行的「${l.text}」和另一個連結重疊,沒有加上。同一行出現兩次的名稱,第二個要給 col。`);
2259
+ return;
2260
+ }
2261
+ list.push(hit);
2262
+ out.set(l.line, list);
2263
+ });
2264
+ for (const list of out.values()) list.sort((a, b) => a.from - b.from);
2265
+ return out;
2266
+ }
2208
2267
  /** Source with line numbers and an optional target line: soft accent background, long lines wrap, light syntax colors. */
2209
- function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, maxHeight, sections, copy, lineNumbers = true, onCopy, onCopyError, className, ref }) {
2268
+ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile, title, language, languageLabel, highlight = true, tokenizer = tokenize, refHref, onRef, links, onLink, preview, maxHeight, sections, copy, lineNumbers = true, onCopy, onCopyError, className, ref }) {
2210
2269
  const lines = React.useMemo(() => String(code || "").replace(/\n$/, "").split("\n"), [code]);
2211
2270
  const lang = language || languageOf(file);
2212
2271
  const toks = React.useMemo(() => highlight ? tokenizer(lines, lang) : lines.map((l) => [["", l]]), [
@@ -2215,6 +2274,71 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2215
2274
  highlight,
2216
2275
  tokenizer
2217
2276
  ]);
2277
+ const hits = React.useMemo(() => matchLinks(lines, start, links), [
2278
+ lines,
2279
+ start,
2280
+ links
2281
+ ]);
2282
+ const nav = hits.size > 0;
2283
+ const [armed, setArmed] = React.useState(false);
2284
+ const inside = React.useRef(false);
2285
+ React.useEffect(() => {
2286
+ if (!nav) return;
2287
+ const key = (e) => {
2288
+ if (e.key === "Control" || e.key === "Meta") setArmed(e.type === "keydown" && inside.current);
2289
+ };
2290
+ const off = () => setArmed(false);
2291
+ window.addEventListener("keydown", key);
2292
+ window.addEventListener("keyup", key);
2293
+ window.addEventListener("blur", off);
2294
+ return () => {
2295
+ window.removeEventListener("keydown", key);
2296
+ window.removeEventListener("keyup", key);
2297
+ window.removeEventListener("blur", off);
2298
+ };
2299
+ }, [nav]);
2300
+ const [pv, setPv] = React.useState(null);
2301
+ const pvId = React.useId();
2302
+ const showTimer = React.useRef(void 0);
2303
+ const hideTimer = React.useRef(void 0);
2304
+ React.useEffect(() => () => {
2305
+ clearTimeout(showTimer.current);
2306
+ clearTimeout(hideTimer.current);
2307
+ }, []);
2308
+ const pvSoon = (el) => {
2309
+ if (!preview) return;
2310
+ clearTimeout(hideTimer.current);
2311
+ clearTimeout(showTimer.current);
2312
+ if (pv?.el === el) return;
2313
+ showTimer.current = setTimeout(() => setPv({
2314
+ i: Number(el.dataset.link),
2315
+ el
2316
+ }), 500);
2317
+ };
2318
+ const pvLater = () => {
2319
+ clearTimeout(showTimer.current);
2320
+ clearTimeout(hideTimer.current);
2321
+ hideTimer.current = setTimeout(() => setPv(null), 200);
2322
+ };
2323
+ const pvKeep = () => clearTimeout(hideTimer.current);
2324
+ const linkEl = (t) => t instanceof Element ? t.closest(".ui-cv-name") : null;
2325
+ const open = (el, e) => {
2326
+ const link = links?.[Number(el.dataset.link)];
2327
+ if (!link) return;
2328
+ clearTimeout(showTimer.current);
2329
+ setPv(null);
2330
+ if (onLink) onLink(link, e);
2331
+ else if (link.href) window.location.assign(link.href);
2332
+ };
2333
+ const onLinkClick = (e) => {
2334
+ const el = linkEl(e.target);
2335
+ if (!el) return;
2336
+ const href = links?.[Number(el.dataset.link)]?.href;
2337
+ if (e.shiftKey && href) return;
2338
+ e.preventDefault();
2339
+ const type = e.nativeEvent.pointerType;
2340
+ if (e.detail === 0 || type === "touch" || type === "pen" || e.ctrlKey || e.metaKey) open(el, e);
2341
+ };
2218
2342
  const [ta, tb] = target == null ? [null, null] : Array.isArray(target) ? target : [target, target];
2219
2343
  const narrow = useNarrow();
2220
2344
  const [all, setAll] = React.useState(false);
@@ -2243,6 +2367,64 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2243
2367
  if (b && el && b.scrollHeight > b.clientHeight) b.scrollTop += el.getBoundingClientRect().top - b.getBoundingClientRect().top - b.clientHeight / 2 + el.offsetHeight / 2;
2244
2368
  }, [ta, code]);
2245
2369
  const digits = String(start + lines.length - 1).length;
2370
+ const piece = (cls, text, key, inLink) => cls ? /* @__PURE__ */ jsx("span", {
2371
+ className: cls,
2372
+ children: !inLink && (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef, nav ? -1 : void 0) : breakable(text)
2373
+ }, key) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, key);
2374
+ const nameLink = (hit, kids) => {
2375
+ const link = links?.[hit.i];
2376
+ if (!link) return null;
2377
+ return /* @__PURE__ */ jsx("a", {
2378
+ className: "ui-cv-name",
2379
+ href: link.href,
2380
+ role: link.href ? void 0 : "link",
2381
+ tabIndex: -1,
2382
+ draggable: false,
2383
+ "data-link": hit.i,
2384
+ "aria-label": link.label,
2385
+ "aria-describedby": pv?.i === hit.i ? pvId : void 0,
2386
+ title: preview ? void 0 : link.label,
2387
+ children: kids
2388
+ }, "n" + hit.i);
2389
+ };
2390
+ const lineContent = (line, lineHits) => {
2391
+ if (!lineHits) return line.map(([cls, text], j) => piece(cls, text, String(j), false));
2392
+ const out = [];
2393
+ let group = [];
2394
+ let open = null;
2395
+ const flush = () => {
2396
+ if (open) out.push(nameLink(open, group));
2397
+ open = null;
2398
+ group = [];
2399
+ };
2400
+ let pos = 0;
2401
+ let h = 0;
2402
+ line.forEach(([cls, text], j) => {
2403
+ let k = 0;
2404
+ while (k < text.length) {
2405
+ const at = pos + k;
2406
+ while (h < lineHits.length && lineHits[h].to <= at) h++;
2407
+ const next = lineHits[h];
2408
+ const hit = next && next.from <= at ? next : null;
2409
+ const end = Math.min(pos + text.length, hit ? hit.to : next ? next.from : Infinity);
2410
+ const key = j + "." + k;
2411
+ if (hit) {
2412
+ if (open !== hit) {
2413
+ flush();
2414
+ open = hit;
2415
+ }
2416
+ group.push(piece(cls, text.slice(k, end - pos), key, true));
2417
+ } else {
2418
+ flush();
2419
+ out.push(piece(cls, text.slice(k, end - pos), key, false));
2420
+ }
2421
+ k = end - pos;
2422
+ }
2423
+ pos += text.length;
2424
+ });
2425
+ flush();
2426
+ return out;
2427
+ };
2246
2428
  const rows = [];
2247
2429
  for (let i = from; i < to; i++) {
2248
2430
  const n = start + i;
@@ -2263,14 +2445,33 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2263
2445
  children: [/* @__PURE__ */ jsx("span", {
2264
2446
  className: "ui-visually-hidden ui-cv-sr",
2265
2447
  children: tr("第 {n} 行", { n }) + indentText(lines[i]) + tr(":")
2266
- }), toks[i].map(([cls, text], j) => cls ? /* @__PURE__ */ jsx("span", {
2267
- className: cls,
2268
- children: (refHref || onRef) && (cls === "is-comment" || cls === "is-string") ? withPaths(text, refHref, onRef) : breakable(text)
2269
- }, j) : /* @__PURE__ */ jsx(React.Fragment, { children: breakable(text) }, j))]
2448
+ }), lineContent(toks[i], hits.get(n))]
2270
2449
  })]
2271
2450
  }, i));
2272
2451
  }
2273
2452
  const keys = [
2453
+ ...nav ? [
2454
+ {
2455
+ k: "ArrowUp ArrowDown",
2456
+ label: "↑↓",
2457
+ what: tr("上一行/下一行")
2458
+ },
2459
+ {
2460
+ k: "ArrowLeft ArrowRight",
2461
+ label: "←→",
2462
+ what: tr("上一個/下一個連結")
2463
+ },
2464
+ {
2465
+ k: "Enter",
2466
+ label: "Enter",
2467
+ what: tr("開啟")
2468
+ },
2469
+ {
2470
+ k: "Escape",
2471
+ label: "Esc",
2472
+ what: tr("回到這一行")
2473
+ }
2474
+ ] : [],
2274
2475
  {
2275
2476
  k: "Home",
2276
2477
  label: "Home",
@@ -2303,11 +2504,55 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2303
2504
  ];
2304
2505
  const onMove = (e) => {
2305
2506
  if (e.altKey || e.ctrlKey || e.metaKey) return;
2306
- const items = [...e.currentTarget.querySelectorAll("[role=\"listitem\"]")];
2507
+ const pre = e.currentTarget;
2508
+ const items = [...pre.querySelectorAll("[role=\"listitem\"]")];
2307
2509
  if (!items.length) return;
2308
2510
  const nOf = (el) => Number(el.dataset.n);
2309
- const at = items.indexOf(document.activeElement instanceof HTMLElement ? document.activeElement : items[0]);
2511
+ const act = document.activeElement instanceof HTMLElement ? document.activeElement : null;
2512
+ const curLine = act && act !== pre ? act.closest("[role=\"listitem\"]") : null;
2513
+ const at = curLine ? items.indexOf(curLine) : -1;
2310
2514
  const now = at < 0 ? -1 : at;
2515
+ const focusLine = (el) => {
2516
+ if (!el) return;
2517
+ el.tabIndex = -1;
2518
+ el.focus();
2519
+ };
2520
+ if (nav) {
2521
+ const stops = [...pre.querySelectorAll(".ui-cv-name, .ui-cv-ref")];
2522
+ const onStop = act ? stops.indexOf(act) : -1;
2523
+ if (e.key === "Escape") {
2524
+ if (pv) setPv(null);
2525
+ else if (onStop >= 0) focusLine(curLine ?? void 0);
2526
+ else if (curLine) pre.focus();
2527
+ else return;
2528
+ e.preventDefault();
2529
+ return;
2530
+ }
2531
+ if (e.key === "Enter" && act && onStop >= 0 && act.classList.contains("ui-cv-name") && !act.hasAttribute("href")) {
2532
+ e.preventDefault();
2533
+ open(act, e);
2534
+ return;
2535
+ }
2536
+ if (e.key === "ArrowUp" || e.key === "ArrowDown") {
2537
+ e.preventDefault();
2538
+ if (now < 0) focusLine(items.find((el) => el.classList.contains("is-target")) ?? items[0]);
2539
+ else focusLine(items[Math.max(0, Math.min(items.length - 1, now + (e.key === "ArrowDown" ? 1 : -1)))]);
2540
+ return;
2541
+ }
2542
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
2543
+ e.preventDefault();
2544
+ const fwd = e.key === "ArrowRight";
2545
+ let to;
2546
+ if (onStop >= 0) to = stops[onStop + (fwd ? 1 : -1)];
2547
+ else {
2548
+ const n = curLine ? nOf(curLine) : ta ?? nOf(items[0]);
2549
+ const lineOf = (el) => Number(el.closest("[role=\"listitem\"]")?.dataset.n);
2550
+ to = fwd ? stops.find((el) => lineOf(el) >= n) : stops.filter((el) => lineOf(el) <= n).pop();
2551
+ }
2552
+ to?.focus();
2553
+ return;
2554
+ }
2555
+ }
2311
2556
  let to = -1;
2312
2557
  let said = "";
2313
2558
  if (e.key === "Home") to = 0;
@@ -2383,17 +2628,62 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
2383
2628
  head,
2384
2629
  /* @__PURE__ */ jsx("pre", {
2385
2630
  ref: body,
2386
- className: "ui-cv-body",
2387
2631
  style: maxHeight ? { maxHeight } : void 0,
2388
2632
  tabIndex: 0,
2389
2633
  "aria-label": tr("程式碼"),
2390
2634
  "aria-keyshortcuts": keys.map((k) => k.k).join(" "),
2391
2635
  onKeyDown: onMove,
2636
+ ...nav ? {
2637
+ onClick: onLinkClick,
2638
+ onPointerEnter: () => inside.current = true,
2639
+ onPointerLeave: () => {
2640
+ inside.current = false;
2641
+ setArmed(false);
2642
+ },
2643
+ onPointerMove: (e) => {
2644
+ const held = e.ctrlKey || e.metaKey;
2645
+ if (held !== armed) setArmed(held);
2646
+ },
2647
+ onPointerOver: (e) => {
2648
+ const el = linkEl(e.target);
2649
+ if (el && e.pointerType === "mouse") pvSoon(el);
2650
+ },
2651
+ onPointerOut: (e) => {
2652
+ const el = linkEl(e.target);
2653
+ if (el && !el.contains(e.relatedTarget)) pvLater();
2654
+ },
2655
+ onFocus: (e) => {
2656
+ const el = linkEl(e.target);
2657
+ if (el && el.matches(":focus-visible")) pvSoon(el);
2658
+ },
2659
+ onBlur: (e) => {
2660
+ if (linkEl(e.target)) pvLater();
2661
+ }
2662
+ } : null,
2663
+ className: cx("ui-cv-body", armed && "is-armed"),
2392
2664
  children: /* @__PURE__ */ jsx("code", {
2393
2665
  role: "list",
2394
2666
  children: rows
2395
2667
  })
2396
2668
  }),
2669
+ preview && pv && links?.[pv.i] ? /* @__PURE__ */ jsx(PreviewCard.Root, {
2670
+ open: true,
2671
+ onOpenChange: (o) => o ? void 0 : setPv(null),
2672
+ children: /* @__PURE__ */ jsx(PreviewCard.Portal, { children: /* @__PURE__ */ jsx(PreviewCard.Positioner, {
2673
+ anchor: pv.el,
2674
+ side: "bottom",
2675
+ align: "start",
2676
+ sideOffset: 6,
2677
+ className: "ui-float",
2678
+ children: /* @__PURE__ */ jsx(PreviewCard.Popup, {
2679
+ id: pvId,
2680
+ className: "ui-popover ui-cv-preview",
2681
+ onPointerEnter: pvKeep,
2682
+ onPointerLeave: pvLater,
2683
+ children: preview(links[pv.i])
2684
+ })
2685
+ }) })
2686
+ }) : null,
2397
2687
  /* @__PURE__ */ jsx("div", {
2398
2688
  className: "ui-cv-keys",
2399
2689
  "aria-hidden": "true",
@@ -2857,6 +3147,121 @@ function ScrollHint({ show, done }) {
2857
3147
  }), touch ? tr("左右滑動") : tr("向右捲動")]
2858
3148
  }) : null;
2859
3149
  }
3150
+ /** The right border of a header cell, dragged to set the column's width. ← → 16 px, Enter or a double-click back
3151
+ * to the widths by content. Hidden on touch screens (CSS), where 「放大表格」 shows the whole table instead. */
3152
+ function ColResize(p) {
3153
+ const [on, setOn] = React.useState(false);
3154
+ const from = React.useRef(null);
3155
+ const min = p.min ?? 48;
3156
+ const set = (w) => p.onWidth(Math.max(min, Math.round(w)));
3157
+ const drag = (v) => {
3158
+ setOn(v);
3159
+ p.onDragging?.(v);
3160
+ };
3161
+ return /* @__PURE__ */ jsx("span", {
3162
+ className: cx("ui-col-resize", on && "is-dragging"),
3163
+ role: "separator",
3164
+ "aria-orientation": "vertical",
3165
+ "aria-label": tr("調整「{name}」欄寬", { name: p.name }),
3166
+ "aria-valuenow": Math.round(p.width),
3167
+ "aria-valuemin": min,
3168
+ tabIndex: 0,
3169
+ onClick: (e) => e.stopPropagation(),
3170
+ onPointerDown: (e) => {
3171
+ if (e.button !== 0) return;
3172
+ e.preventDefault();
3173
+ e.stopPropagation();
3174
+ e.currentTarget.setPointerCapture(e.pointerId);
3175
+ from.current = {
3176
+ x: e.clientX,
3177
+ w: p.start()
3178
+ };
3179
+ drag(true);
3180
+ },
3181
+ onPointerMove: (e) => {
3182
+ if (from.current) set(from.current.w + e.clientX - from.current.x);
3183
+ },
3184
+ onPointerUp: () => {
3185
+ from.current = null;
3186
+ drag(false);
3187
+ },
3188
+ onPointerCancel: () => {
3189
+ from.current = null;
3190
+ drag(false);
3191
+ },
3192
+ onDoubleClick: (e) => {
3193
+ e.stopPropagation();
3194
+ p.onReset();
3195
+ },
3196
+ onKeyDown: (e) => {
3197
+ if (e.altKey || e.metaKey || e.ctrlKey) return;
3198
+ if (e.key === "ArrowLeft" || e.key === "ArrowRight") {
3199
+ e.preventDefault();
3200
+ e.stopPropagation();
3201
+ set(p.start() + (e.key === "ArrowRight" ? 16 : -16));
3202
+ } else if (e.key === "Enter") {
3203
+ e.preventDefault();
3204
+ e.stopPropagation();
3205
+ p.onReset();
3206
+ }
3207
+ }
3208
+ });
3209
+ }
3210
+ /** The 「放大表格」 icon: 32 px, no border, at the table's top right. */
3211
+ function ZoomButton({ onClick }) {
3212
+ return /* @__PURE__ */ jsx(IconButton, {
3213
+ className: "ui-table-zoom",
3214
+ icon: "corners-out",
3215
+ label: tr("放大表格"),
3216
+ onClick
3217
+ });
3218
+ }
3219
+ /** The whole table in a wide dialog (at most 1200 px). A plain click on a link inside (a function, a path) closes the
3220
+ * dialog after the link has done its job; Ctrl, ⌘, Shift or the middle button open a new tab and keep it open. */
3221
+ function TableDialog(p) {
3222
+ if (!p.open) return null;
3223
+ return /* @__PURE__ */ jsx(Dialog, {
3224
+ open: true,
3225
+ onClose: p.onClose,
3226
+ title: p.title || tr("表格"),
3227
+ className: "ui-table-dialog",
3228
+ children: /* @__PURE__ */ jsx("div", {
3229
+ className: "ui-table-dialog-body",
3230
+ onClick: (e) => {
3231
+ if (e.metaKey || e.ctrlKey || e.shiftKey || e.button !== 0) return;
3232
+ const link = e.target.closest("a[href], [role=\"link\"], .ui-code.is-link, .ui-md-link");
3233
+ if (link && e.currentTarget.contains(link)) p.onClose();
3234
+ },
3235
+ children: p.children
3236
+ })
3237
+ });
3238
+ }
3239
+ /** The 「複製成 Markdown」 icon: copies the text, turns into a check for 2 s and says 「已複製」, as CodeView's copy. */
3240
+ function CopyMarkdownButton(p) {
3241
+ const [done, setDone] = React.useState(false);
3242
+ const timer = React.useRef(void 0);
3243
+ React.useEffect(() => () => clearTimeout(timer.current), []);
3244
+ return /* @__PURE__ */ jsx(IconButton, {
3245
+ className: cx("ui-table-copy", done && "is-copied", p.className),
3246
+ icon: done ? CHECK : "copy",
3247
+ label: done ? tr("已複製") : tr("複製成 Markdown"),
3248
+ onClick: () => copyText(p.text()).then(() => {
3249
+ setDone(true);
3250
+ announce(tr("已複製"));
3251
+ clearTimeout(timer.current);
3252
+ timer.current = setTimeout(() => setDone(false), 2e3);
3253
+ }, () => p.onCopyError?.())
3254
+ });
3255
+ }
3256
+ /** A table as GitHub Markdown: | in a cell is escaped, line breaks become spaces. */
3257
+ function markdownTable(heads, rows) {
3258
+ const cell = (s) => s.replace(/\r?\n/g, " ").replace(/\|/g, "\\|").trim();
3259
+ return [
3260
+ `| ${heads.map(cell).join(" | ")} |`,
3261
+ `|${heads.map(() => "---").join("|")}|`,
3262
+ ...rows.map((r) => `| ${r.map(cell).join(" | ")} |`)
3263
+ ].join("\n");
3264
+ }
2860
3265
  // src/components/DataTable/filters.ts
2861
3266
  const field = (row, key) => row[key];
2862
3267
  /** Cell text: money as NT$ 1,280, dates as 2026/11/04(三), numbers with their unit after them. */
@@ -3300,6 +3705,26 @@ function DataTable(p) {
3300
3705
  const [sel, setSel] = React.useState({});
3301
3706
  const [sumVal, setSumVal] = React.useState("all");
3302
3707
  const [fit, setFit] = React.useState({});
3708
+ const [widths, setWidthsState] = React.useState(() => {
3709
+ if (!p.widthKey) return null;
3710
+ try {
3711
+ const v = JSON.parse(localStorage.getItem("ui-dt-width:" + p.widthKey) || "null");
3712
+ return v && typeof v === "object" ? v : null;
3713
+ } catch {
3714
+ return null;
3715
+ }
3716
+ });
3717
+ const setWidths = (w) => {
3718
+ setWidthsState(w);
3719
+ if (!p.widthKey) return;
3720
+ try {
3721
+ if (w) localStorage.setItem("ui-dt-width:" + p.widthKey, JSON.stringify(w));
3722
+ else localStorage.removeItem("ui-dt-width:" + p.widthKey);
3723
+ } catch {}
3724
+ };
3725
+ const [zoomed, setZoomed] = React.useState(false);
3726
+ const [zoomWidths, setZoomWidths] = React.useState(null);
3727
+ const zoomRef = React.useRef(null);
3303
3728
  const [resetKey, setResetKey] = React.useState(p.resetKey);
3304
3729
  const resetting = resetKey !== p.resetKey;
3305
3730
  if (resetting) {
@@ -3512,16 +3937,31 @@ function DataTable(p) {
3512
3937
  const expander = longCols.length > 0 && !narrow;
3513
3938
  const EXP = 40;
3514
3939
  const minOf = (c) => Math.max(c.width || (c.numeric ? 96 : 120), fit[c.key] || 0);
3515
- const template = [
3516
- expander ? "40px" : null,
3517
- selectable ? "46px" : null,
3518
- ...shownCols.map((c) => `minmax(${minOf(c)}px, ${c.grow || (c.width ? 1 : c.numeric ? .8 : 1)}fr)`),
3519
- hasAct ? actW + "px" : null
3520
- ].filter(Boolean).join(" ");
3521
- const minW = (expander ? EXP : 0) + (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + minOf(c), 0) + (hasAct ? actW : 0);
3522
- const gridStyle = {
3523
- gridTemplateColumns: template,
3524
- minWidth: minW
3940
+ const layout = (w) => {
3941
+ const colW = (c) => w ? `${w[c.key] ?? minOf(c)}px` : `minmax(${minOf(c)}px, ${c.grow || (c.width ? 1 : c.numeric ? .8 : 1)}fr)`;
3942
+ return {
3943
+ gridTemplateColumns: [
3944
+ expander ? "40px" : null,
3945
+ selectable ? "46px" : null,
3946
+ ...shownCols.map(colW),
3947
+ hasAct ? actW + "px" : null
3948
+ ].filter(Boolean).join(" "),
3949
+ minWidth: (expander ? EXP : 0) + (selectable ? 46 : 0) + shownCols.reduce((a, c) => a + (w ? w[c.key] ?? minOf(c) : minOf(c)), 0) + (hasAct ? actW : 0)
3950
+ };
3951
+ };
3952
+ const pageGrid = layout(widths);
3953
+ const zoomGrid = layout(zoomWidths);
3954
+ const drawn = (root) => {
3955
+ const out = {};
3956
+ for (const c of shownCols) {
3957
+ const el = root?.querySelector(`.ui-dt-head [data-col="${CSS.escape(c.key)}"]`);
3958
+ out[c.key] = el ? Math.ceil(el.getBoundingClientRect().width) : minOf(c);
3959
+ }
3960
+ return out;
3961
+ };
3962
+ const headMin = (root, key) => {
3963
+ const el = root?.querySelector(`.ui-dt-head [data-col="${CSS.escape(key)}"] > :first-child`);
3964
+ return Math.max(48, el ? Math.ceil(el.getBoundingClientRect().width) + 24 : 48);
3525
3965
  };
3526
3966
  React.useLayoutEffect(() => {
3527
3967
  const root = rootRef.current;
@@ -3561,84 +4001,101 @@ function DataTable(p) {
3561
4001
  }, [narrow, resetKey]);
3562
4002
  const stickyStyle = (ci) => ci === 0 && sticky ? { left: (expander ? EXP : 0) + (selectable ? 46 : 0) } : void 0;
3563
4003
  const cellClass = (c, ci, ...more) => cx("ui-dt-cell", isNum(c) && "is-num", ci === 0 && sticky && "is-sticky", ...more);
3564
- const head = selectable && selIds.length && p.bulkActions ? /* @__PURE__ */ jsxs("div", {
3565
- className: "ui-dt-row ui-dt-head ui-dt-bulk",
3566
- role: "row",
3567
- style: { minWidth: minW },
3568
- children: [
3569
- /* @__PURE__ */ jsx("div", {
3570
- className: "ui-dt-cell",
3571
- role: "columnheader",
3572
- children: /* @__PURE__ */ jsx(RowCheck, {
3573
- v: allOn ? true : "mixed",
3574
- label: tr("全選"),
3575
- onClick: () => toggle(visIds, !allOn)
3576
- })
3577
- }),
3578
- /* @__PURE__ */ jsx("span", {
3579
- className: "ui-dt-bulk-count",
3580
- children: tr("已選 {n} 筆", { n: selIds.length })
3581
- }),
3582
- /* @__PURE__ */ jsx("span", {
3583
- className: "ui-dt-bulk-actions",
3584
- children: p.bulkActions(selIds, clear)
3585
- }),
3586
- /* @__PURE__ */ jsx("button", {
3587
- type: "button",
3588
- className: "ui-dt-bulk-close",
3589
- "aria-label": tr("取消選取"),
3590
- onClick: clear,
3591
- children: /* @__PURE__ */ jsx(Icon, {
3592
- name: "x",
3593
- size: 14
3594
- })
3595
- })
3596
- ]
3597
- }) : /* @__PURE__ */ jsxs("div", {
3598
- className: "ui-dt-row ui-dt-head",
3599
- role: "row",
3600
- style: gridStyle,
3601
- children: [
3602
- expander ? /* @__PURE__ */ jsx("div", {
3603
- className: "ui-dt-cell ui-dt-exp",
3604
- role: "columnheader",
3605
- "aria-label": tr("詳細")
3606
- }) : null,
3607
- selectable ? /* @__PURE__ */ jsx("div", {
3608
- className: "ui-dt-cell ui-dt-sel",
3609
- role: "columnheader",
3610
- children: /* @__PURE__ */ jsx(RowCheck, {
3611
- v: allOn ? true : mixed ? "mixed" : false,
3612
- label: tr("全選"),
3613
- onClick: () => toggle(visIds, !allOn)
4004
+ const headOf = (inZoom) => {
4005
+ const gridStyle = inZoom ? zoomGrid : pageGrid;
4006
+ const minW = gridStyle.minWidth;
4007
+ const w = inZoom ? zoomWidths : widths;
4008
+ const setW = inZoom ? setZoomWidths : setWidths;
4009
+ const root = () => inZoom ? zoomRef.current : rootRef.current;
4010
+ return selectable && selIds.length && p.bulkActions ? /* @__PURE__ */ jsxs("div", {
4011
+ className: "ui-dt-row ui-dt-head ui-dt-bulk",
4012
+ role: "row",
4013
+ style: { minWidth: minW },
4014
+ children: [
4015
+ /* @__PURE__ */ jsx("div", {
4016
+ className: "ui-dt-cell",
4017
+ role: "columnheader",
4018
+ children: /* @__PURE__ */ jsx(RowCheck, {
4019
+ v: allOn ? true : "mixed",
4020
+ label: tr("全選"),
4021
+ onClick: () => toggle(visIds, !allOn)
4022
+ })
4023
+ }),
4024
+ /* @__PURE__ */ jsx("span", {
4025
+ className: "ui-dt-bulk-count",
4026
+ children: tr("已選 {n} 筆", { n: selIds.length })
4027
+ }),
4028
+ /* @__PURE__ */ jsx("span", {
4029
+ className: "ui-dt-bulk-actions",
4030
+ children: p.bulkActions(selIds, clear)
4031
+ }),
4032
+ /* @__PURE__ */ jsx("button", {
4033
+ type: "button",
4034
+ className: "ui-dt-bulk-close",
4035
+ "aria-label": tr("取消選取"),
4036
+ onClick: clear,
4037
+ children: /* @__PURE__ */ jsx(Icon, {
4038
+ name: "x",
4039
+ size: 14
4040
+ })
3614
4041
  })
3615
- }) : null,
3616
- shownCols.map((c, ci) => {
3617
- const cur = sort.key === c.key;
3618
- return /* @__PURE__ */ jsx("div", {
4042
+ ]
4043
+ }) : /* @__PURE__ */ jsxs("div", {
4044
+ className: "ui-dt-row ui-dt-head",
4045
+ role: "row",
4046
+ style: gridStyle,
4047
+ children: [
4048
+ expander ? /* @__PURE__ */ jsx("div", {
4049
+ className: "ui-dt-cell ui-dt-exp",
3619
4050
  role: "columnheader",
3620
- "aria-sort": cur ? sort.dir === "asc" ? "ascending" : "descending" : "none",
3621
- className: cellClass(c, ci),
3622
- style: stickyStyle(ci),
3623
- children: c.sortable === false ? c.label : /* @__PURE__ */ jsxs("button", {
3624
- type: "button",
3625
- className: cx("ui-dt-sort", cur && "is-on"),
3626
- onClick: () => sortBy(c),
3627
- children: [/* @__PURE__ */ jsx("span", { children: c.label }), /* @__PURE__ */ jsx(Icon, {
3628
- d: ARROWS[cur ? sort.dir : "none"],
3629
- size: 14,
3630
- className: "ui-dt-arrow"
3631
- })]
4051
+ "aria-label": tr("詳細")
4052
+ }) : null,
4053
+ selectable ? /* @__PURE__ */ jsx("div", {
4054
+ className: "ui-dt-cell ui-dt-sel",
4055
+ role: "columnheader",
4056
+ children: /* @__PURE__ */ jsx(RowCheck, {
4057
+ v: allOn ? true : mixed ? "mixed" : false,
4058
+ label: tr("全選"),
4059
+ onClick: () => toggle(visIds, !allOn)
3632
4060
  })
3633
- }, c.key);
3634
- }),
3635
- hasAct ? /* @__PURE__ */ jsx("div", {
3636
- className: "ui-dt-cell",
3637
- role: "columnheader",
3638
- "aria-label": tr("操作")
3639
- }) : null
3640
- ]
3641
- });
4061
+ }) : null,
4062
+ shownCols.map((c, ci) => {
4063
+ const cur = sort.key === c.key;
4064
+ return /* @__PURE__ */ jsxs("div", {
4065
+ role: "columnheader",
4066
+ "aria-sort": cur ? sort.dir === "asc" ? "ascending" : "descending" : "none",
4067
+ className: cellClass(c, ci),
4068
+ style: stickyStyle(ci),
4069
+ "data-col": c.key,
4070
+ children: [c.sortable === false ? c.label : /* @__PURE__ */ jsxs("button", {
4071
+ type: "button",
4072
+ className: cx("ui-dt-sort", cur && "is-on"),
4073
+ onClick: () => sortBy(c),
4074
+ children: [/* @__PURE__ */ jsx("span", { children: c.label }), /* @__PURE__ */ jsx(Icon, {
4075
+ d: ARROWS[cur ? sort.dir : "none"],
4076
+ size: 14,
4077
+ className: "ui-dt-arrow"
4078
+ })]
4079
+ }), narrow ? null : /* @__PURE__ */ jsx(ColResize, {
4080
+ name: c.label,
4081
+ width: w?.[c.key] ?? minOf(c),
4082
+ start: () => (w ?? drawn(root()))[c.key] ?? minOf(c),
4083
+ onWidth: (px) => setW({
4084
+ ...w ?? drawn(root()),
4085
+ [c.key]: Math.max(headMin(root(), c.key), px)
4086
+ }),
4087
+ onReset: () => setW(null)
4088
+ })]
4089
+ }, c.key);
4090
+ }),
4091
+ hasAct ? /* @__PURE__ */ jsx("div", {
4092
+ className: "ui-dt-cell",
4093
+ role: "columnheader",
4094
+ "aria-label": tr("操作")
4095
+ }) : null
4096
+ ]
4097
+ });
4098
+ };
3642
4099
  const mark = searching ? q : "";
3643
4100
  const cellInner = (r, c) => {
3644
4101
  const raw = get(r, c.key);
@@ -3680,6 +4137,259 @@ function DataTable(p) {
3680
4137
  }
3681
4138
  return "";
3682
4139
  };
4140
+ const copyMarkdown = () => {
4141
+ const all = list.map((x) => x.r);
4142
+ if (p.copyText) return p.copyText(all);
4143
+ return markdownTable(shownCols.map((c) => c.label), all.map((r) => shownCols.map((c) => String(c.fullText?.(r) ?? c.searchText?.(r) ?? cellText(c, get(r, c.key)) ?? ""))));
4144
+ };
4145
+ const toolsView = (inZoom) => /* @__PURE__ */ jsxs("div", {
4146
+ className: "ui-dt-tools",
4147
+ children: [
4148
+ search !== false ? /* @__PURE__ */ jsx(SearchField, {
4149
+ value: q,
4150
+ onChange: (v) => {
4151
+ setQ(v);
4152
+ setPage(0);
4153
+ },
4154
+ placeholder: search.placeholder || tr("搜尋"),
4155
+ label: search.placeholder || tr("搜尋"),
4156
+ className: "ui-dt-search"
4157
+ }) : null,
4158
+ filters.length ? /* @__PURE__ */ jsx(FilterButton, {
4159
+ boundary: inZoom ? zoomRef : rootRef,
4160
+ filters,
4161
+ values,
4162
+ activeCount: activeN,
4163
+ count: (f, v) => all.filter((x) => passes(x.r, f.key) && matches(f, x.r, f.type === "list" ? [v] : void 0)).length,
4164
+ onChange: (key, v) => {
4165
+ setValues({
4166
+ ...values,
4167
+ [key]: v
4168
+ });
4169
+ setPage(0);
4170
+ },
4171
+ onClear: () => {
4172
+ setValues({});
4173
+ setPage(0);
4174
+ }
4175
+ }) : null,
4176
+ /* @__PURE__ */ jsxs("span", {
4177
+ className: "ui-dt-result",
4178
+ children: [/* @__PURE__ */ jsx("span", {
4179
+ "aria-hidden": "true",
4180
+ children: seenOnly(tr("{n} / {total} 筆", {
4181
+ n: "",
4182
+ total: ""
4183
+ }), [format.number(list.length), format.number(baseCount)])
4184
+ }), /* @__PURE__ */ jsx("span", {
4185
+ className: "ui-visually-hidden",
4186
+ children: format.fractionLabel(list.length, baseCount, tr("筆"))
4187
+ })]
4188
+ }),
4189
+ p.copy !== false ? /* @__PURE__ */ jsx(CopyMarkdownButton, {
4190
+ text: copyMarkdown,
4191
+ onCopyError: p.onCopyError
4192
+ }) : null,
4193
+ p.columnMenu !== false && cols.length > 2 ? /* @__PURE__ */ jsx(ColumnMenu, {
4194
+ cols,
4195
+ hidden,
4196
+ onToggle: (k) => setToggled({
4197
+ ...toggled,
4198
+ [k]: !hidden[k]
4199
+ })
4200
+ }) : null
4201
+ ]
4202
+ });
4203
+ const tableView = (inZoom) => {
4204
+ const grid = inZoom ? zoomGrid : pageGrid;
4205
+ const pfx = inZoom ? uid + "z" : uid;
4206
+ return /* @__PURE__ */ jsx("div", {
4207
+ className: cx("ui-dt-scroller", scrollMore && !inZoom && "has-more"),
4208
+ children: /* @__PURE__ */ jsx("div", {
4209
+ className: "ui-dt-scroll",
4210
+ ref: inZoom ? void 0 : scrollRef,
4211
+ onScroll: inZoom ? void 0 : onScroll,
4212
+ children: /* @__PURE__ */ jsxs("div", {
4213
+ className: "ui-dt-table",
4214
+ role: "table",
4215
+ "aria-label": p.label || p.caption,
4216
+ children: [
4217
+ headOf(inZoom),
4218
+ /* @__PURE__ */ jsx("div", {
4219
+ ref: inZoom ? void 0 : bodyRef,
4220
+ className: "ui-dt-body",
4221
+ role: "rowgroup",
4222
+ children: vis.length ? vis.map((x, i) => {
4223
+ const id = visIds[i];
4224
+ const on = !!sel[id];
4225
+ const open = expander && !!opened[id];
4226
+ const detailId = `${pfx}-d-${idPart(id)}`;
4227
+ const rowName = shownCols[0] ? String(cellText(shownCols[0], get(x.r, shownCols[0].key)) ?? "") : "";
4228
+ return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsxs("div", {
4229
+ "data-rid": id,
4230
+ ref: inZoom ? void 0 : (el) => {
4231
+ rowEls.current[id] = el;
4232
+ },
4233
+ role: "row",
4234
+ "aria-labelledby": shownCols.length ? `${pfx}-n-${start + i}` : void 0,
4235
+ className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
4236
+ style: grid,
4237
+ onClick: expander ? (e) => {
4238
+ const t = e.target;
4239
+ if (t.closest(ROW_CONTROLS) && t.closest(ROW_CONTROLS) !== e.currentTarget) return;
4240
+ if (String(window.getSelection() ?? "")) return;
4241
+ setOpened({
4242
+ ...opened,
4243
+ [id]: !open
4244
+ });
4245
+ } : void 0,
4246
+ children: [
4247
+ expander ? /* @__PURE__ */ jsx("div", {
4248
+ className: "ui-dt-cell ui-dt-exp",
4249
+ role: "cell",
4250
+ children: /* @__PURE__ */ jsx("button", {
4251
+ type: "button",
4252
+ className: cx("ui-dt-exp-btn", open && "is-open"),
4253
+ "aria-expanded": open,
4254
+ "aria-controls": open ? detailId : void 0,
4255
+ "aria-label": tr(open ? "收合 {name}" : "展開 {name}", { name: rowName }),
4256
+ onClick: () => setOpened({
4257
+ ...opened,
4258
+ [id]: !open
4259
+ }),
4260
+ children: /* @__PURE__ */ jsx(Icon, {
4261
+ name: "caret-right",
4262
+ size: 16
4263
+ })
4264
+ })
4265
+ }) : null,
4266
+ selectable ? /* @__PURE__ */ jsx("div", {
4267
+ className: "ui-dt-cell ui-dt-sel",
4268
+ role: "cell",
4269
+ children: /* @__PURE__ */ jsx(RowCheck, {
4270
+ v: on,
4271
+ label: tr("選取第 {n} 筆", { n: start + i + 1 }),
4272
+ onClick: () => toggle([id], !on)
4273
+ })
4274
+ }) : null,
4275
+ shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
4276
+ role: "cell",
4277
+ id: ci === 0 ? `${pfx}-n-${start + i}` : void 0,
4278
+ "aria-description": c.fullText ? c.fullText(x.r) || void 0 : void 0,
4279
+ "data-label": c.label,
4280
+ "data-col": c.key,
4281
+ className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
4282
+ style: stickyStyle(ci),
4283
+ children: cell(x.r, c)
4284
+ }, c.key)),
4285
+ hasAct ? /* @__PURE__ */ jsx("div", {
4286
+ className: "ui-dt-cell ui-dt-acts",
4287
+ role: "cell",
4288
+ children: p.rowActions?.(x.r)
4289
+ }) : null
4290
+ ]
4291
+ }), open ? /* @__PURE__ */ jsx("div", {
4292
+ id: detailId,
4293
+ role: "row",
4294
+ className: cx("ui-dt-detail", i % 2 && "is-even"),
4295
+ style: { minWidth: grid.minWidth },
4296
+ children: /* @__PURE__ */ jsx("div", {
4297
+ role: "cell",
4298
+ className: "ui-dt-detail-cell",
4299
+ style: { paddingLeft: EXP + (selectable ? 46 : 0) + 12 },
4300
+ children: longCols.map((c) => /* @__PURE__ */ jsxs("div", {
4301
+ className: "ui-dt-detail-item",
4302
+ children: [/* @__PURE__ */ jsx("div", {
4303
+ className: "ui-dt-detail-label",
4304
+ children: c.label
4305
+ }), /* @__PURE__ */ jsx("div", {
4306
+ className: "ui-dt-detail-text",
4307
+ children: c.fullText ? c.fullText(x.r) : cellInner(x.r, c)
4308
+ })]
4309
+ }, c.key))
4310
+ })
4311
+ }) : null] }, id);
4312
+ }) : /* @__PURE__ */ jsxs("div", {
4313
+ className: "ui-dt-empty",
4314
+ children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
4315
+ onClick: clearFilters,
4316
+ children: tr("清除篩選")
4317
+ }) }) : null]
4318
+ })
4319
+ }),
4320
+ p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
4321
+ className: "ui-dt-row ui-dt-total",
4322
+ role: "row",
4323
+ style: grid,
4324
+ children: [
4325
+ expander ? /* @__PURE__ */ jsx("div", {
4326
+ className: "ui-dt-cell",
4327
+ role: "cell"
4328
+ }) : null,
4329
+ selectable ? /* @__PURE__ */ jsx("div", {
4330
+ className: "ui-dt-cell",
4331
+ role: "cell"
4332
+ }) : null,
4333
+ shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
4334
+ role: "cell",
4335
+ className: cellClass(c, ci),
4336
+ style: stickyStyle(ci),
4337
+ children: total(c, ci)
4338
+ }, c.key)),
4339
+ hasAct ? /* @__PURE__ */ jsx("div", {
4340
+ className: "ui-dt-cell",
4341
+ role: "cell"
4342
+ }) : null
4343
+ ]
4344
+ }) : null
4345
+ ]
4346
+ })
4347
+ })
4348
+ });
4349
+ };
4350
+ const footView = /* @__PURE__ */ jsx(Fragment, { children: pages > 1 ? /* @__PURE__ */ jsxs("div", {
4351
+ className: "ui-dt-foot",
4352
+ children: [/* @__PURE__ */ jsx("span", {
4353
+ className: "ui-dt-range",
4354
+ children: monoNums(tr("第 {a}–{b} 筆,共 {n} 筆", {
4355
+ a: "",
4356
+ b: "",
4357
+ n: ""
4358
+ }), [
4359
+ start + 1,
4360
+ Math.min(list.length, start + pageSize),
4361
+ format.number(list.length)
4362
+ ])
4363
+ }), /* @__PURE__ */ jsxs("nav", {
4364
+ className: "ui-dt-pages",
4365
+ "aria-label": tr("分頁"),
4366
+ children: [
4367
+ /* @__PURE__ */ jsx("button", {
4368
+ type: "button",
4369
+ className: "ui-dt-page",
4370
+ "aria-label": tr("上一頁"),
4371
+ disabled: pageNow === 0,
4372
+ onClick: () => goPage(pageNow - 1),
4373
+ children: "‹"
4374
+ }),
4375
+ Array.from({ length: pages }, (_, i) => /* @__PURE__ */ jsx("button", {
4376
+ type: "button",
4377
+ className: cx("ui-dt-page", i === pageNow && "is-on"),
4378
+ "aria-current": i === pageNow ? "page" : void 0,
4379
+ onClick: () => goPage(i),
4380
+ children: String(i + 1)
4381
+ }, i)),
4382
+ /* @__PURE__ */ jsx("button", {
4383
+ type: "button",
4384
+ className: "ui-dt-page",
4385
+ "aria-label": tr("下一頁"),
4386
+ disabled: pageNow >= pages - 1,
4387
+ onClick: () => goPage(pageNow + 1),
4388
+ children: "›"
4389
+ })
4390
+ ]
4391
+ })]
4392
+ }) : null });
3683
4393
  return /* @__PURE__ */ jsxs("div", {
3684
4394
  ref: rootRef,
3685
4395
  className: cx("ui-dt", selIds.length && "has-sel", p.className),
@@ -3738,250 +4448,31 @@ function DataTable(p) {
3738
4448
  count: sumAll.filter((x) => String(get(x.r, summary.key)) === String(it.value)).length
3739
4449
  }))]
3740
4450
  }) : null,
3741
- /* @__PURE__ */ jsxs("div", {
3742
- className: "ui-dt-tools",
3743
- children: [
3744
- search !== false ? /* @__PURE__ */ jsx(SearchField, {
3745
- value: q,
3746
- onChange: (v) => {
3747
- setQ(v);
3748
- setPage(0);
3749
- },
3750
- placeholder: search.placeholder || tr("搜尋"),
3751
- label: search.placeholder || tr("搜尋"),
3752
- className: "ui-dt-search"
3753
- }) : null,
3754
- filters.length ? /* @__PURE__ */ jsx(FilterButton, {
3755
- boundary: rootRef,
3756
- filters,
3757
- values,
3758
- activeCount: activeN,
3759
- count: (f, v) => all.filter((x) => passes(x.r, f.key) && matches(f, x.r, f.type === "list" ? [v] : void 0)).length,
3760
- onChange: (key, v) => {
3761
- setValues({
3762
- ...values,
3763
- [key]: v
3764
- });
3765
- setPage(0);
3766
- },
3767
- onClear: () => {
3768
- setValues({});
3769
- setPage(0);
3770
- }
3771
- }) : null,
3772
- /* @__PURE__ */ jsxs("span", {
3773
- className: "ui-dt-result",
3774
- children: [/* @__PURE__ */ jsx("span", {
3775
- "aria-hidden": "true",
3776
- children: seenOnly(tr("{n} / {total} 筆", {
3777
- n: "",
3778
- total: ""
3779
- }), [format.number(list.length), format.number(baseCount)])
3780
- }), /* @__PURE__ */ jsx("span", {
3781
- className: "ui-visually-hidden",
3782
- children: format.fractionLabel(list.length, baseCount, tr("筆"))
3783
- })]
3784
- }),
3785
- p.columnMenu !== false && cols.length > 2 ? /* @__PURE__ */ jsx(ColumnMenu, {
3786
- cols,
3787
- hidden,
3788
- onToggle: (k) => setToggled({
3789
- ...toggled,
3790
- [k]: !hidden[k]
3791
- })
3792
- }) : null
3793
- ]
3794
- }),
3795
- /* @__PURE__ */ jsx("div", {
3796
- className: cx("ui-dt-scroller", scrollMore && "has-more"),
3797
- children: /* @__PURE__ */ jsx("div", {
3798
- className: "ui-dt-scroll",
3799
- ref: scrollRef,
3800
- onScroll,
3801
- children: /* @__PURE__ */ jsxs("div", {
3802
- className: "ui-dt-table",
3803
- role: "table",
3804
- "aria-label": p.label || p.caption,
3805
- children: [
3806
- head,
3807
- /* @__PURE__ */ jsx("div", {
3808
- ref: bodyRef,
3809
- className: "ui-dt-body",
3810
- role: "rowgroup",
3811
- children: vis.length ? vis.map((x, i) => {
3812
- const id = visIds[i];
3813
- const on = !!sel[id];
3814
- const open = expander && !!opened[id];
3815
- const detailId = `${uid}-d-${idPart(id)}`;
3816
- const rowName = shownCols[0] ? String(cellText(shownCols[0], get(x.r, shownCols[0].key)) ?? "") : "";
3817
- return /* @__PURE__ */ jsxs(React.Fragment, { children: [/* @__PURE__ */ jsxs("div", {
3818
- "data-rid": id,
3819
- ref: (el) => {
3820
- rowEls.current[id] = el;
3821
- },
3822
- role: "row",
3823
- "aria-labelledby": shownCols.length ? `${uid}-n-${start + i}` : void 0,
3824
- className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
3825
- style: gridStyle,
3826
- onClick: expander ? (e) => {
3827
- const t = e.target;
3828
- if (t.closest(ROW_CONTROLS) && t.closest(ROW_CONTROLS) !== e.currentTarget) return;
3829
- if (String(window.getSelection() ?? "")) return;
3830
- setOpened({
3831
- ...opened,
3832
- [id]: !open
3833
- });
3834
- } : void 0,
3835
- children: [
3836
- expander ? /* @__PURE__ */ jsx("div", {
3837
- className: "ui-dt-cell ui-dt-exp",
3838
- role: "cell",
3839
- children: /* @__PURE__ */ jsx("button", {
3840
- type: "button",
3841
- className: cx("ui-dt-exp-btn", open && "is-open"),
3842
- "aria-expanded": open,
3843
- "aria-controls": open ? detailId : void 0,
3844
- "aria-label": tr(open ? "收合 {name}" : "展開 {name}", { name: rowName }),
3845
- onClick: () => setOpened({
3846
- ...opened,
3847
- [id]: !open
3848
- }),
3849
- children: /* @__PURE__ */ jsx(Icon, {
3850
- name: "caret-right",
3851
- size: 16
3852
- })
3853
- })
3854
- }) : null,
3855
- selectable ? /* @__PURE__ */ jsx("div", {
3856
- className: "ui-dt-cell ui-dt-sel",
3857
- role: "cell",
3858
- children: /* @__PURE__ */ jsx(RowCheck, {
3859
- v: on,
3860
- label: tr("選取第 {n} 筆", { n: start + i + 1 }),
3861
- onClick: () => toggle([id], !on)
3862
- })
3863
- }) : null,
3864
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3865
- role: "cell",
3866
- id: ci === 0 ? `${uid}-n-${start + i}` : void 0,
3867
- "aria-description": c.fullText ? c.fullText(x.r) || void 0 : void 0,
3868
- "data-label": c.label,
3869
- "data-col": c.key,
3870
- className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3871
- style: stickyStyle(ci),
3872
- children: cell(x.r, c)
3873
- }, c.key)),
3874
- hasAct ? /* @__PURE__ */ jsx("div", {
3875
- className: "ui-dt-cell ui-dt-acts",
3876
- role: "cell",
3877
- children: p.rowActions?.(x.r)
3878
- }) : null
3879
- ]
3880
- }), open ? /* @__PURE__ */ jsx("div", {
3881
- id: detailId,
3882
- role: "row",
3883
- className: cx("ui-dt-detail", i % 2 && "is-even"),
3884
- style: { minWidth: minW },
3885
- children: /* @__PURE__ */ jsx("div", {
3886
- role: "cell",
3887
- className: "ui-dt-detail-cell",
3888
- style: { paddingLeft: EXP + (selectable ? 46 : 0) + 12 },
3889
- children: longCols.map((c) => /* @__PURE__ */ jsxs("div", {
3890
- className: "ui-dt-detail-item",
3891
- children: [/* @__PURE__ */ jsx("div", {
3892
- className: "ui-dt-detail-label",
3893
- children: c.label
3894
- }), /* @__PURE__ */ jsx("div", {
3895
- className: "ui-dt-detail-text",
3896
- children: c.fullText ? c.fullText(x.r) : cellInner(x.r, c)
3897
- })]
3898
- }, c.key))
3899
- })
3900
- }) : null] }, id);
3901
- }) : /* @__PURE__ */ jsxs("div", {
3902
- className: "ui-dt-empty",
3903
- children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
3904
- onClick: clearFilters,
3905
- children: tr("清除篩選")
3906
- }) }) : null]
3907
- })
3908
- }),
3909
- p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
3910
- className: "ui-dt-row ui-dt-total",
3911
- role: "row",
3912
- style: gridStyle,
3913
- children: [
3914
- expander ? /* @__PURE__ */ jsx("div", {
3915
- className: "ui-dt-cell",
3916
- role: "cell"
3917
- }) : null,
3918
- selectable ? /* @__PURE__ */ jsx("div", {
3919
- className: "ui-dt-cell",
3920
- role: "cell"
3921
- }) : null,
3922
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3923
- role: "cell",
3924
- className: cellClass(c, ci),
3925
- style: stickyStyle(ci),
3926
- children: total(c, ci)
3927
- }, c.key)),
3928
- hasAct ? /* @__PURE__ */ jsx("div", {
3929
- className: "ui-dt-cell",
3930
- role: "cell"
3931
- }) : null
3932
- ]
3933
- }) : null
3934
- ]
3935
- })
3936
- })
3937
- }),
4451
+ toolsView(false),
4452
+ p.zoom !== false && !narrow ? /* @__PURE__ */ jsx("div", {
4453
+ className: "ui-dt-zoom",
4454
+ children: /* @__PURE__ */ jsx(ZoomButton, { onClick: () => setZoomed(true) })
4455
+ }) : null,
4456
+ tableView(false),
3938
4457
  /* @__PURE__ */ jsx(ScrollHint, {
3939
4458
  show: overflows,
3940
4459
  done: scrolled
3941
4460
  }),
3942
- pages > 1 ? /* @__PURE__ */ jsxs("div", {
3943
- className: "ui-dt-foot",
3944
- children: [/* @__PURE__ */ jsx("span", {
3945
- className: "ui-dt-range",
3946
- children: monoNums(tr("第 {a}–{b} 筆,共 {n} 筆", {
3947
- a: "",
3948
- b: "",
3949
- n: ""
3950
- }), [
3951
- start + 1,
3952
- Math.min(list.length, start + pageSize),
3953
- format.number(list.length)
3954
- ])
3955
- }), /* @__PURE__ */ jsxs("nav", {
3956
- className: "ui-dt-pages",
3957
- "aria-label": tr("分頁"),
4461
+ footView,
4462
+ /* @__PURE__ */ jsx(TableDialog, {
4463
+ open: zoomed,
4464
+ onClose: () => setZoomed(false),
4465
+ title: p.caption || p.label,
4466
+ children: /* @__PURE__ */ jsxs("div", {
4467
+ ref: zoomRef,
4468
+ className: "ui-dt ui-dt-zoomed",
3958
4469
  children: [
3959
- /* @__PURE__ */ jsx("button", {
3960
- type: "button",
3961
- className: "ui-dt-page",
3962
- "aria-label": tr("上一頁"),
3963
- disabled: pageNow === 0,
3964
- onClick: () => goPage(pageNow - 1),
3965
- children: "‹"
3966
- }),
3967
- Array.from({ length: pages }, (_, i) => /* @__PURE__ */ jsx("button", {
3968
- type: "button",
3969
- className: cx("ui-dt-page", i === pageNow && "is-on"),
3970
- "aria-current": i === pageNow ? "page" : void 0,
3971
- onClick: () => goPage(i),
3972
- children: String(i + 1)
3973
- }, i)),
3974
- /* @__PURE__ */ jsx("button", {
3975
- type: "button",
3976
- className: "ui-dt-page",
3977
- "aria-label": tr("下一頁"),
3978
- disabled: pageNow >= pages - 1,
3979
- onClick: () => goPage(pageNow + 1),
3980
- children: "›"
3981
- })
4470
+ toolsView(true),
4471
+ tableView(true),
4472
+ footView
3982
4473
  ]
3983
- })]
3984
- }) : null
4474
+ })
4475
+ })
3985
4476
  ]
3986
4477
  });
3987
4478
  }
@@ -5170,23 +5661,13 @@ function Markdown(p) {
5170
5661
  const a = b.align[j] ?? (numeric[j] ? "right" : null);
5171
5662
  return a ? { textAlign: a } : void 0;
5172
5663
  };
5173
- return /* @__PURE__ */ jsx("div", {
5174
- className: "ui-md-table-wrap",
5175
- tabIndex: 0,
5176
- role: "region",
5177
- "aria-label": b.head.join("、"),
5178
- children: /* @__PURE__ */ jsxs("table", {
5179
- className: "ui-md-table",
5180
- children: [/* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: b.head.map((h, j) => /* @__PURE__ */ jsx("th", {
5181
- style: align(j),
5182
- children: inline(h, c)
5183
- }, j)) }) }), /* @__PURE__ */ jsx("tbody", { children: b.rows.map((r, ri) => /* @__PURE__ */ jsx("tr", { children: Array.from({ length: n }, (_, j) => /* @__PURE__ */ jsx("td", {
5184
- className: numeric[j] ? "is-num" : void 0,
5185
- style: align(j),
5186
- "data-label": plain(b.head[j] ?? ""),
5187
- children: inline(r[j] ?? "", c)
5188
- }, j)) }, ri)) })]
5189
- })
5664
+ return /* @__PURE__ */ jsx(MdTable, {
5665
+ label: b.head.map(plain).join("、"),
5666
+ heads: b.head.map((h) => inline(h, c)),
5667
+ headText: b.head.map(plain),
5668
+ rows: b.rows.map((r) => Array.from({ length: n }, (_, j) => inline(r[j] ?? "", c))),
5669
+ numeric,
5670
+ align
5190
5671
  }, c.k());
5191
5672
  }
5192
5673
  }
@@ -5237,6 +5718,89 @@ function MdDetails({ summary, children }) {
5237
5718
  })]
5238
5719
  });
5239
5720
  }
5721
+ /** A Markdown table: column borders in the header drag; the corner button shows the whole table in a wide dialog.
5722
+ * Under 480 px every row is a card instead, without either. The border, the dialog and the copy icon are the same as
5723
+ * DataTable's (internal/tableTools). */
5724
+ function MdTable(p) {
5725
+ const [widths, setWidths] = React.useState(null);
5726
+ const [big, setBig] = React.useState(false);
5727
+ const [dragging, setDragging] = React.useState(false);
5728
+ const table = React.useRef(null);
5729
+ const measure = () => [...table.current?.querySelectorAll("thead th") ?? []].map((th) => Math.ceil(th.getBoundingClientRect().width));
5730
+ const [measured, setMeasured] = React.useState([]);
5731
+ React.useLayoutEffect(() => {
5732
+ const el = table.current;
5733
+ if (!el) return;
5734
+ const update = () => {
5735
+ const m = [...el.querySelectorAll("thead th")].map((th) => Math.ceil(th.getBoundingClientRect().width));
5736
+ setMeasured((old) => old.length === m.length && old.every((v, i) => v === m[i]) ? old : m);
5737
+ };
5738
+ update();
5739
+ const ro = new ResizeObserver(update);
5740
+ ro.observe(el);
5741
+ return () => ro.disconnect();
5742
+ }, []);
5743
+ const body = (resize) => /* @__PURE__ */ jsxs("table", {
5744
+ ref: resize ? table : void 0,
5745
+ className: "ui-md-table",
5746
+ style: resize && widths ? {
5747
+ width: widths.reduce((a, b) => a + b, 0),
5748
+ tableLayout: "fixed",
5749
+ minWidth: 0
5750
+ } : void 0,
5751
+ children: [
5752
+ resize && widths ? /* @__PURE__ */ jsx("colgroup", { children: widths.map((w, j) => /* @__PURE__ */ jsx("col", { style: { width: w } }, j)) }) : null,
5753
+ /* @__PURE__ */ jsx("thead", { children: /* @__PURE__ */ jsx("tr", { children: p.heads.map((h, j) => /* @__PURE__ */ jsxs("th", {
5754
+ style: p.align(j),
5755
+ children: [h, resize ? /* @__PURE__ */ jsx(ColResize, {
5756
+ name: p.headText[j],
5757
+ width: widths?.[j] ?? measured[j] ?? 0,
5758
+ start: () => (widths ?? measure())[j],
5759
+ onWidth: (w) => {
5760
+ const next = (widths ?? measure()).slice();
5761
+ next[j] = w;
5762
+ setWidths(next);
5763
+ },
5764
+ onReset: () => setWidths(null),
5765
+ onDragging: setDragging
5766
+ }) : null]
5767
+ }, j)) }) }),
5768
+ /* @__PURE__ */ jsx("tbody", { children: p.rows.map((r, ri) => /* @__PURE__ */ jsx("tr", { children: r.map((cell, j) => /* @__PURE__ */ jsx("td", {
5769
+ className: p.numeric[j] ? "is-num" : void 0,
5770
+ style: p.align(j),
5771
+ "data-label": p.headText[j],
5772
+ children: cell
5773
+ }, j)) }, ri)) })
5774
+ ]
5775
+ });
5776
+ return /* @__PURE__ */ jsxs("div", {
5777
+ className: cx("ui-md-tablebox", dragging && "is-resizing"),
5778
+ children: [
5779
+ /* @__PURE__ */ jsx("div", {
5780
+ className: "ui-md-table-tools",
5781
+ children: /* @__PURE__ */ jsx(ZoomButton, { onClick: () => setBig(true) })
5782
+ }),
5783
+ /* @__PURE__ */ jsx("div", {
5784
+ className: "ui-md-table-wrap",
5785
+ tabIndex: 0,
5786
+ role: "region",
5787
+ "aria-label": p.label,
5788
+ children: body(true)
5789
+ }),
5790
+ /* @__PURE__ */ jsx(TableDialog, {
5791
+ open: big,
5792
+ onClose: () => setBig(false),
5793
+ children: /* @__PURE__ */ jsx("div", {
5794
+ className: "ui-md ui-md-table-wrap",
5795
+ tabIndex: 0,
5796
+ role: "region",
5797
+ "aria-label": p.label,
5798
+ children: body(false)
5799
+ })
5800
+ })
5801
+ ]
5802
+ });
5803
+ }
5240
5804
  // src/components/Section/Section.tsx
5241
5805
  const Group = React.createContext(null);
5242
5806
  const MOVE_MS = 260;
@@ -5390,9 +5954,9 @@ function Section(p) {
5390
5954
  })]
5391
5955
  });
5392
5956
  }
5393
- /** A run of Sections with 「全部展開」 and 「全部收合」 above them. */
5394
- function SectionGroup({ children, actions, className }) {
5395
- const [all, setAll] = React.useState({
5957
+ /** A run of Sections with one 「全部展開/全部收合」 icon button. */
5958
+ function SectionGroup({ children, actions, bar = true, className }) {
5959
+ const [all, setAllState] = React.useState({
5396
5960
  n: 0,
5397
5961
  open: false
5398
5962
  });
@@ -5406,40 +5970,45 @@ function SectionGroup({ children, actions, className }) {
5406
5970
  };
5407
5971
  });
5408
5972
  }, []);
5973
+ const setAll = React.useCallback((open) => setAllState((a) => ({
5974
+ n: a.n + 1,
5975
+ open
5976
+ })), []);
5977
+ const vals = Object.values(states);
5978
+ const anyClosed = vals.length === 0 || vals.some((v) => !v);
5409
5979
  const ctx = React.useMemo(() => ({
5410
5980
  all,
5411
- report
5412
- }), [all, report]);
5413
- const vals = Object.values(states);
5414
- return /* @__PURE__ */ jsxs("div", {
5415
- className: cx("ui-sec-group", className),
5416
- children: [/* @__PURE__ */ jsxs("div", {
5417
- className: "ui-sec-bar",
5418
- children: [
5419
- actions ?? null,
5420
- /* @__PURE__ */ jsx(Button, {
5421
- icon: "arrows-out-line-vertical",
5422
- disabled: vals.length > 0 && vals.every(Boolean),
5423
- onClick: () => setAll((a) => ({
5424
- n: a.n + 1,
5425
- open: true
5426
- })),
5427
- children: tr("全部展開")
5428
- }),
5429
- /* @__PURE__ */ jsx(Button, {
5430
- icon: "arrows-in-line-vertical",
5431
- disabled: !vals.some(Boolean),
5432
- onClick: () => setAll((a) => ({
5433
- n: a.n + 1,
5434
- open: false
5435
- })),
5436
- children: tr("全部收合")
5437
- })
5438
- ]
5439
- }), /* @__PURE__ */ jsx(Group.Provider, {
5440
- value: ctx,
5441
- children
5442
- })]
5981
+ report,
5982
+ anyClosed,
5983
+ setAll
5984
+ }), [
5985
+ all,
5986
+ report,
5987
+ anyClosed,
5988
+ setAll
5989
+ ]);
5990
+ return /* @__PURE__ */ jsx(Group.Provider, {
5991
+ value: ctx,
5992
+ children: /* @__PURE__ */ jsxs("div", {
5993
+ className: cx("ui-sec-group", className),
5994
+ children: [bar ? /* @__PURE__ */ jsxs("div", {
5995
+ className: "ui-sec-bar",
5996
+ children: [actions ?? null, /* @__PURE__ */ jsx(SectionGroupToggle, {})]
5997
+ }) : null, children]
5998
+ })
5999
+ });
6000
+ }
6001
+ /** GB: the 「全部展開/全部收合」 icon button of the SectionGroup around it, for a place of your own (with bar={false}).
6002
+ * Opens every section while any is closed, else closes them all; its tooltip and name say which. */
6003
+ function SectionGroupToggle({ className }) {
6004
+ const g = React.useContext(Group);
6005
+ if (!g) return null;
6006
+ const open = g.anyClosed;
6007
+ return /* @__PURE__ */ jsx(IconButton, {
6008
+ className: cx("ui-sec-toggle", className),
6009
+ icon: open ? "arrows-out-line-vertical" : "arrows-in-line-vertical",
6010
+ label: open ? tr("全部展開") : tr("全部收合"),
6011
+ onClick: () => g.setAll(open)
5443
6012
  });
5444
6013
  }
5445
6014
  // src/components/KpiCard/KpiCard.tsx
@@ -9283,6 +9852,6 @@ function TreeList(p) {
9283
9852
  })]
9284
9853
  });
9285
9854
  }
9286
- 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, Markdown, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, addMessages, announce, focusMain, format, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, useTour };
9855
+ 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, Markdown, Menu, MobileTabBar, MultiSelect, NotificationBell, Page, Popover, ProgressBar, ProgressRing, ProjectSwitcher, RadioGroup, SearchField, Section, SectionGroup, SectionGroupToggle, Select, SettingsLayout, SettingsSection, SideNav, Skeleton, SplitPane, Suggestion, Switch, Tabs, Tag, Term, TextArea, TextField, ThemePicker, Toast, Tooltip, TopBar, Tour, TreeList, addMessages, announce, focusMain, format, icons, initTheme, isCodeRef, safeHref, setAccent, setLocale, setTheme, tr as t, useTour };
9287
9856
 
9288
9857
  //# sourceMappingURL=index.js.map