@seanyeh77/ui 0.39.0 → 0.41.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 +19 -19
- package/dist/bundle.js.map +1 -1
- package/dist/{format-entry-BJI8MU2K.d.ts → format-entry-CgMBtkni.d.ts} +4 -0
- package/dist/{format-entry-C7iBqN3J.js → format-entry-CyChe8bk.js} +24 -6
- package/dist/format-entry-CyChe8bk.js.map +1 -0
- package/dist/format.d.ts +1 -1
- package/dist/format.js +1 -1
- package/dist/index.d.ts +64 -26
- package/dist/index.js +1152 -519
- package/dist/index.js.map +1 -1
- package/dist/styles.css +900 -683
- package/dist/tokens.css +74 -19
- package/docs/AccentPicker.md +17 -2
- package/docs/ActionBar.md +6 -4
- package/docs/AiMark.md +12 -6
- package/docs/Alert.md +17 -5
- package/docs/AppShell.md +20 -11
- package/docs/Badge.md +20 -9
- package/docs/BarChart.md +21 -3
- package/docs/Breadcrumb.md +9 -4
- package/docs/Button.md +18 -8
- package/docs/Calendar.md +10 -5
- package/docs/Card.md +17 -9
- package/docs/Checkbox.md +15 -4
- package/docs/CodeView.md +16 -13
- package/docs/CommandPalette.md +18 -10
- package/docs/ConsoleLayout.md +25 -3
- package/docs/DangerZone.md +9 -3
- package/docs/DataColors.md +11 -4
- package/docs/DataTable.md +77 -28
- package/docs/DatePicker.md +16 -2
- package/docs/DateRangePicker.md +13 -1
- package/docs/DetailList.md +17 -12
- package/docs/Dialog.md +11 -6
- package/docs/Drawer.md +13 -7
- package/docs/EmptyState.md +13 -1
- package/docs/ErrorPage.md +6 -0
- package/docs/EventTimeline.md +11 -5
- package/docs/FileUpload.md +21 -5
- package/docs/FormGrid.md +11 -2
- package/docs/Format.md +19 -1
- package/docs/Graph.md +17 -2
- package/docs/Grid.md +13 -4
- package/docs/IconButton.md +16 -13
- package/docs/InlineCode.md +18 -8
- package/docs/KpiCard.md +21 -7
- package/docs/LayerGraph.md +36 -23
- package/docs/LineChart.md +22 -1
- package/docs/LoadingBar.md +7 -1
- package/docs/LoginCard.md +19 -3
- package/docs/Markdown.md +18 -2
- package/docs/Menu.md +13 -7
- package/docs/Meter.md +12 -5
- package/docs/MobileTabBar.md +18 -2
- package/docs/MultiSelect.md +13 -3
- package/docs/NotificationBell.md +13 -3
- package/docs/Popover.md +12 -2
- package/docs/ProgressBar.md +8 -2
- package/docs/ProgressRing.md +8 -2
- package/docs/ProjectSwitcher.md +15 -9
- package/docs/RadioGroup.md +21 -3
- package/docs/SearchField.md +8 -2
- package/docs/Section.md +16 -4
- package/docs/SegmentedControl.md +21 -19
- package/docs/Select.md +16 -1
- package/docs/SettingsLayout.md +19 -4
- package/docs/SideNav.md +20 -2
- package/docs/Skeleton.md +7 -1
- package/docs/SplitPane.md +7 -1
- package/docs/StatusBand.md +12 -6
- package/docs/Suggestion.md +12 -5
- package/docs/Switch.md +15 -2
- package/docs/Tabs.md +25 -6
- package/docs/Tag.md +16 -12
- package/docs/Term.md +18 -1
- package/docs/TextArea.md +12 -1
- package/docs/TextField.md +15 -5
- package/docs/ThemePicker.md +16 -4
- package/docs/TimeControl.md +10 -5
- package/docs/Toast.md +13 -3
- package/docs/Tooltip.md +17 -5
- package/docs/TopBar.md +16 -3
- package/docs/Tour.md +25 -1
- package/docs/TreeList.md +16 -9
- package/docs/Workbench.md +12 -6
- package/docs/ZoneMap.md +17 -9
- package/docs/code.md +28 -0
- package/docs/data.md +45 -0
- package/docs/forms.md +29 -0
- package/docs/guidelines.md +56 -307
- package/docs/layout.md +24 -4
- package/docs/monitoring.md +30 -0
- package/docs/motion.md +1 -1
- package/docs/theme.md +104 -0
- package/package.json +3 -3
- package/dist/format-entry-C7iBqN3J.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, 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-
|
|
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-CyChe8bk.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";
|
|
@@ -454,9 +454,9 @@ const MOTION = {
|
|
|
454
454
|
};
|
|
455
455
|
/** Transition for an indicator whose leading edge moves first and trailing edge catches up (the droplet stretch). */
|
|
456
456
|
function dropTransition(axisA, axisB, forward) {
|
|
457
|
-
const lead = MOTION.dur * .6 + "ms
|
|
457
|
+
const lead = MOTION.dur * .6 + "ms var(--ease-standard)";
|
|
458
458
|
const follow = MOTION.dur * MOTION.stretch + "ms cubic-bezier(.65,0,.25,1.15)";
|
|
459
|
-
return axisA + " " + (forward ? follow : lead) + ", " + axisB + " " + (forward ? lead : follow) + ", transform
|
|
459
|
+
return axisA + " " + (forward ? follow : lead) + ", " + axisB + " " + (forward ? lead : follow) + ", transform var(--dur-hover) ease";
|
|
460
460
|
}
|
|
461
461
|
/** [moving, start]: true from start() until the droplet has settled. */
|
|
462
462
|
function useMoving() {
|
|
@@ -518,6 +518,68 @@ function devWarn(cond, component, message) {
|
|
|
518
518
|
seen.add(text);
|
|
519
519
|
console.warn(text);
|
|
520
520
|
}
|
|
521
|
+
// src/components/Tooltip/Tooltip.tsx
|
|
522
|
+
const openNow = /* @__PURE__ */ new Set();
|
|
523
|
+
/** Dark label above the element (below when there is no room), with an arrow. Appears at once on hover and focus. */
|
|
524
|
+
function Tooltip({ label, side = "top", describe = true, wrap = false, disabled = false, children }) {
|
|
525
|
+
const id = React.useId();
|
|
526
|
+
const [open, setOpen] = React.useState(false);
|
|
527
|
+
const close = React.useCallback(() => setOpen(false), []);
|
|
528
|
+
const shown = open && !disabled;
|
|
529
|
+
React.useEffect(() => {
|
|
530
|
+
if (!shown) return;
|
|
531
|
+
const away = (e) => {
|
|
532
|
+
const t = e.target;
|
|
533
|
+
if (!(t instanceof Element) || !t.closest(`[data-ui-tip="${id}"]`)) close();
|
|
534
|
+
};
|
|
535
|
+
document.addEventListener("pointerdown", away, true);
|
|
536
|
+
document.addEventListener("scroll", close, true);
|
|
537
|
+
return () => {
|
|
538
|
+
document.removeEventListener("pointerdown", away, true);
|
|
539
|
+
document.removeEventListener("scroll", close, true);
|
|
540
|
+
};
|
|
541
|
+
}, [
|
|
542
|
+
shown,
|
|
543
|
+
close,
|
|
544
|
+
id
|
|
545
|
+
]);
|
|
546
|
+
React.useEffect(() => {
|
|
547
|
+
if (!shown) return;
|
|
548
|
+
for (const other of openNow) if (other !== close) other();
|
|
549
|
+
openNow.add(close);
|
|
550
|
+
return () => {
|
|
551
|
+
openNow.delete(close);
|
|
552
|
+
};
|
|
553
|
+
}, [shown, close]);
|
|
554
|
+
return /* @__PURE__ */ jsxs(Tooltip$1.Root, {
|
|
555
|
+
disabled,
|
|
556
|
+
open: shown,
|
|
557
|
+
onOpenChange: setOpen,
|
|
558
|
+
children: [
|
|
559
|
+
/* @__PURE__ */ jsx(Tooltip$1.Trigger, {
|
|
560
|
+
delay: 0,
|
|
561
|
+
render: children,
|
|
562
|
+
"aria-describedby": describe && !disabled ? id : void 0,
|
|
563
|
+
onBlur: close,
|
|
564
|
+
"data-ui-tip": id
|
|
565
|
+
}),
|
|
566
|
+
describe && !disabled ? /* @__PURE__ */ jsx("span", {
|
|
567
|
+
id,
|
|
568
|
+
hidden: true,
|
|
569
|
+
children: label
|
|
570
|
+
}) : null,
|
|
571
|
+
/* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
|
|
572
|
+
side,
|
|
573
|
+
sideOffset: 8,
|
|
574
|
+
className: "ui-tooltip-positioner",
|
|
575
|
+
children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
|
|
576
|
+
className: wrap ? "ui-tooltip is-wrap" : "ui-tooltip",
|
|
577
|
+
children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
|
|
578
|
+
})
|
|
579
|
+
}) })
|
|
580
|
+
]
|
|
581
|
+
});
|
|
582
|
+
}
|
|
521
583
|
// src/components/SideNav/SideNav.tsx
|
|
522
584
|
const isBrand = (b) => !!b && typeof b === "object" && !React.isValidElement(b) && !Array.isArray(b) && typeof b.name === "string";
|
|
523
585
|
function NavBrandRow({ brand, collapsed }) {
|
|
@@ -690,27 +752,35 @@ function SideNav({ sections, value, onChange, collapsed = false, onToggle, onPin
|
|
|
690
752
|
}),
|
|
691
753
|
onToggle || onPin ? /* @__PURE__ */ jsxs("div", {
|
|
692
754
|
className: "ui-nav-foot",
|
|
693
|
-
children: [onPin ? /* @__PURE__ */ jsx(
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
|
|
697
|
-
|
|
698
|
-
|
|
699
|
-
|
|
700
|
-
|
|
701
|
-
|
|
702
|
-
|
|
703
|
-
|
|
755
|
+
children: [onPin ? /* @__PURE__ */ jsx(Tooltip, {
|
|
756
|
+
label: pinned ? tr("取消釘選") : tr("釘選側邊欄"),
|
|
757
|
+
side: "right",
|
|
758
|
+
describe: false,
|
|
759
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
760
|
+
type: "button",
|
|
761
|
+
className: cx("ui-nav-collapse", "ui-nav-pin", pinned && "is-on"),
|
|
762
|
+
"aria-pressed": pinned,
|
|
763
|
+
"aria-label": pinned ? tr("取消釘選") : tr("釘選側邊欄"),
|
|
764
|
+
onClick: onPin,
|
|
765
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
766
|
+
name: "push-pin",
|
|
767
|
+
size: 20,
|
|
768
|
+
filled: pinned
|
|
769
|
+
})
|
|
704
770
|
})
|
|
705
|
-
}) : null, onToggle ? /* @__PURE__ */ jsx(
|
|
706
|
-
|
|
707
|
-
|
|
708
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
771
|
+
}) : null, onToggle ? /* @__PURE__ */ jsx(Tooltip, {
|
|
772
|
+
label: toggleLabel,
|
|
773
|
+
side: "right",
|
|
774
|
+
describe: false,
|
|
775
|
+
children: /* @__PURE__ */ jsx("button", {
|
|
776
|
+
type: "button",
|
|
777
|
+
className: "ui-nav-collapse",
|
|
778
|
+
"aria-label": toggleLabel,
|
|
779
|
+
onClick: onToggle,
|
|
780
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
781
|
+
name: "sidebar-simple",
|
|
782
|
+
size: 20
|
|
783
|
+
})
|
|
714
784
|
})
|
|
715
785
|
}) : null]
|
|
716
786
|
}) : null
|
|
@@ -739,68 +809,6 @@ function Breadcrumb({ items, className }) {
|
|
|
739
809
|
}) })
|
|
740
810
|
});
|
|
741
811
|
}
|
|
742
|
-
// src/components/Tooltip/Tooltip.tsx
|
|
743
|
-
const openNow = /* @__PURE__ */ new Set();
|
|
744
|
-
/** Dark label above the element (below when there is no room), with an arrow. Appears at once on hover and focus. */
|
|
745
|
-
function Tooltip({ label, side = "top", describe = true, wrap = false, disabled = false, children }) {
|
|
746
|
-
const id = React.useId();
|
|
747
|
-
const [open, setOpen] = React.useState(false);
|
|
748
|
-
const close = React.useCallback(() => setOpen(false), []);
|
|
749
|
-
const shown = open && !disabled;
|
|
750
|
-
React.useEffect(() => {
|
|
751
|
-
if (!shown) return;
|
|
752
|
-
const away = (e) => {
|
|
753
|
-
const t = e.target;
|
|
754
|
-
if (!(t instanceof Element) || !t.closest(`[data-ui-tip="${id}"]`)) close();
|
|
755
|
-
};
|
|
756
|
-
document.addEventListener("pointerdown", away, true);
|
|
757
|
-
document.addEventListener("scroll", close, true);
|
|
758
|
-
return () => {
|
|
759
|
-
document.removeEventListener("pointerdown", away, true);
|
|
760
|
-
document.removeEventListener("scroll", close, true);
|
|
761
|
-
};
|
|
762
|
-
}, [
|
|
763
|
-
shown,
|
|
764
|
-
close,
|
|
765
|
-
id
|
|
766
|
-
]);
|
|
767
|
-
React.useEffect(() => {
|
|
768
|
-
if (!shown) return;
|
|
769
|
-
for (const other of openNow) if (other !== close) other();
|
|
770
|
-
openNow.add(close);
|
|
771
|
-
return () => {
|
|
772
|
-
openNow.delete(close);
|
|
773
|
-
};
|
|
774
|
-
}, [shown, close]);
|
|
775
|
-
return /* @__PURE__ */ jsxs(Tooltip$1.Root, {
|
|
776
|
-
disabled,
|
|
777
|
-
open: shown,
|
|
778
|
-
onOpenChange: setOpen,
|
|
779
|
-
children: [
|
|
780
|
-
/* @__PURE__ */ jsx(Tooltip$1.Trigger, {
|
|
781
|
-
delay: 0,
|
|
782
|
-
render: children,
|
|
783
|
-
"aria-describedby": describe && !disabled ? id : void 0,
|
|
784
|
-
onBlur: close,
|
|
785
|
-
"data-ui-tip": id
|
|
786
|
-
}),
|
|
787
|
-
describe && !disabled ? /* @__PURE__ */ jsx("span", {
|
|
788
|
-
id,
|
|
789
|
-
hidden: true,
|
|
790
|
-
children: label
|
|
791
|
-
}) : null,
|
|
792
|
-
/* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
|
|
793
|
-
side,
|
|
794
|
-
sideOffset: 8,
|
|
795
|
-
className: "ui-tooltip-positioner",
|
|
796
|
-
children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
|
|
797
|
-
className: wrap ? "ui-tooltip is-wrap" : "ui-tooltip",
|
|
798
|
-
children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
|
|
799
|
-
})
|
|
800
|
-
}) })
|
|
801
|
-
]
|
|
802
|
-
});
|
|
803
|
-
}
|
|
804
812
|
// src/components/IconButton/IconButton.tsx
|
|
805
813
|
/** A square icon-only button with a tooltip. */
|
|
806
814
|
function IconButton({ label, icon, className, tooltip = true, filled, hint, variant, ...native }) {
|
|
@@ -1365,6 +1373,7 @@ function Page({ children, className }) {
|
|
|
1365
1373
|
// src/theme.ts
|
|
1366
1374
|
const THEME_KEY = "ui-theme";
|
|
1367
1375
|
const ACCENT_KEY = "ui-accent";
|
|
1376
|
+
const DEFAULT_ACCENT = "#2457d6";
|
|
1368
1377
|
const isSetting = (v) => v === "auto" || v === "light" || v === "dark";
|
|
1369
1378
|
/** The stored theme setting, 'auto' when there is none. */
|
|
1370
1379
|
function storedTheme() {
|
|
@@ -1387,7 +1396,24 @@ function setTheme(t) {
|
|
|
1387
1396
|
root.setAttribute("data-theme", resolveTheme(t));
|
|
1388
1397
|
root.setAttribute("data-theme-setting", t);
|
|
1389
1398
|
store(THEME_KEY, t);
|
|
1390
|
-
setAccent(
|
|
1399
|
+
setAccent(storedAccent(), true);
|
|
1400
|
+
}
|
|
1401
|
+
/** Swatches whose color changed so they read as text on every ground: a stored old value moves to the new one. */
|
|
1402
|
+
const RENAMED_SWATCHES = {
|
|
1403
|
+
"#8a4fd6": "#864ad1",
|
|
1404
|
+
"#c2407a": "#ba3873",
|
|
1405
|
+
"#cd3a2f": "#c53228",
|
|
1406
|
+
"#b85a0e": "#ab5101",
|
|
1407
|
+
"#1a844a": "#077b42",
|
|
1408
|
+
"#0e827d": "#027874"
|
|
1409
|
+
};
|
|
1410
|
+
/** The stored accent, with an old swatch value moved to its current one (and stored again). */
|
|
1411
|
+
function storedAccent() {
|
|
1412
|
+
const v = store(ACCENT_KEY);
|
|
1413
|
+
if (!v) return DEFAULT_ACCENT;
|
|
1414
|
+
const now = RENAMED_SWATCHES[v.toLowerCase()];
|
|
1415
|
+
if (now) store(ACCENT_KEY, now);
|
|
1416
|
+
return now ?? v;
|
|
1391
1417
|
}
|
|
1392
1418
|
const hexRgb = (x) => [
|
|
1393
1419
|
1,
|
|
@@ -1431,21 +1457,60 @@ function contrast(a, b) {
|
|
|
1431
1457
|
const y = lum(b);
|
|
1432
1458
|
return (Math.max(x, y) + .05) / (Math.min(x, y) + .05);
|
|
1433
1459
|
}
|
|
1434
|
-
/** The accent's text color (accent-text): the accent itself when it reads
|
|
1435
|
-
*
|
|
1436
|
-
*
|
|
1437
|
-
function accentText(hex, dark, bg, surface) {
|
|
1438
|
-
const
|
|
1439
|
-
|
|
1440
|
-
|
|
1441
|
-
|
|
1460
|
+
/** The accent's text color (accent-text, and the focus outline): the accent itself when it reads (4.5:1) on bg,
|
|
1461
|
+
* surface and every extra ground passed (setAccent passes surface-sub, surface-chrome and accent-soft); else, in
|
|
1462
|
+
* light, the accent mixed with black 4 % at a time, in dark with white 5 % at a time, until it reads on all of them. */
|
|
1463
|
+
function accentText(hex, dark, bg, surface, ...grounds) {
|
|
1464
|
+
const all = [
|
|
1465
|
+
bg,
|
|
1466
|
+
surface,
|
|
1467
|
+
...grounds
|
|
1468
|
+
].map(toHex);
|
|
1469
|
+
if (all.some((g) => !g)) return hex;
|
|
1470
|
+
const reads = (c) => all.every((g) => contrast(c, g) >= 4.5);
|
|
1442
1471
|
const toward = dark ? "#ffffff" : "#000000";
|
|
1443
1472
|
const step = dark ? .05 : .04;
|
|
1444
1473
|
let text = hex;
|
|
1445
1474
|
for (let k = 1; k * step <= 1 && !reads(text); k++) text = mixHex(hex, toward, k * step);
|
|
1446
1475
|
return text;
|
|
1447
1476
|
}
|
|
1448
|
-
|
|
1477
|
+
const INK = "#171512";
|
|
1478
|
+
/** The text on an accent fill (on-accent): white or the near-black ink (#171512), whichever contrasts more. */
|
|
1479
|
+
function onFill(fill) {
|
|
1480
|
+
return contrast("#ffffff", fill) >= contrast(INK, fill) ? "#ffffff" : INK;
|
|
1481
|
+
}
|
|
1482
|
+
/** The accent's fill color (accent: buttons, switches, progress, selected marks): the accent itself when it reaches
|
|
1483
|
+
* 3:1 on bg, surface and every extra ground passed (setAccent passes surface-sub, surface-chrome and accent-soft) and
|
|
1484
|
+
* its on-accent text reaches 4.5:1 on it; else, in light, the accent mixed with black 4 % at a time, in dark with
|
|
1485
|
+
* white 5 % at a time, until both hold. The preset swatches pass in light as they are. */
|
|
1486
|
+
function accentFill(hex, dark, bg, surface, ...grounds) {
|
|
1487
|
+
const all = [
|
|
1488
|
+
bg,
|
|
1489
|
+
surface,
|
|
1490
|
+
...grounds
|
|
1491
|
+
].map(toHex);
|
|
1492
|
+
if (all.some((g) => !g)) return hex;
|
|
1493
|
+
const ok = (c) => all.every((g) => contrast(c, g) >= 3) && contrast(onFill(c), c) >= 4.5;
|
|
1494
|
+
const toward = dark ? "#ffffff" : "#000000";
|
|
1495
|
+
const step = dark ? .05 : .04;
|
|
1496
|
+
let fill = hex;
|
|
1497
|
+
for (let k = 1; k * step <= 1 && !ok(fill); k++) fill = mixHex(hex, toward, k * step);
|
|
1498
|
+
return fill;
|
|
1499
|
+
}
|
|
1500
|
+
/** The preset swatches of AccentPicker. In light (and the teaching preset) each one reads as text by itself (4.5:1 on
|
|
1501
|
+
* bg, surface, surface-sub, surface-chrome and its own accent-soft), so accentText returns it unchanged; white text
|
|
1502
|
+
* reads on it (4.5:1). In dark, accentText lightens it. Checked in tokens-contrast.test.tsx. */
|
|
1503
|
+
const ACCENT_SWATCHES = [
|
|
1504
|
+
["藍", "#2457d6"],
|
|
1505
|
+
["靛", "#5b4fd6"],
|
|
1506
|
+
["紫", "#864ad1"],
|
|
1507
|
+
["桃紅", "#ba3873"],
|
|
1508
|
+
["紅", "#c53228"],
|
|
1509
|
+
["橘", "#ab5101"],
|
|
1510
|
+
["綠", "#077b42"],
|
|
1511
|
+
["青", "#027874"]
|
|
1512
|
+
];
|
|
1513
|
+
/** Derives every accent token from one color (自訂強調色的換算 in docs/theme.md).
|
|
1449
1514
|
* Returns false for anything but #rrggbb. quiet: apply without storing. */
|
|
1450
1515
|
function setAccent(hex, quiet = false) {
|
|
1451
1516
|
if (!/^#[0-9a-fA-F]{6}$/.test(hex)) return false;
|
|
@@ -1455,16 +1520,21 @@ function setAccent(hex, quiet = false) {
|
|
|
1455
1520
|
const cs = getComputedStyle(root);
|
|
1456
1521
|
const surface = toHex(cs.getPropertyValue("--surface")) ?? (dark ? "#393530" : "#ffffff");
|
|
1457
1522
|
const bg = toHex(cs.getPropertyValue("--bg")) ?? (dark ? "#2f2a25" : "#fcfbfb");
|
|
1458
|
-
const
|
|
1459
|
-
const
|
|
1523
|
+
const sub = toHex(cs.getPropertyValue("--surface-sub")) ?? (dark ? "#443f3b" : "#f6f5f4");
|
|
1524
|
+
const chrome = toHex(cs.getPropertyValue("--surface-chrome")) ?? (dark ? "#3d3834" : "#ffffff");
|
|
1525
|
+
const soft = dark ? mixHex(surface, hex, .22) : mixHex("#ffffff", hex, .12);
|
|
1526
|
+
const text = accentText(hex, dark, bg, surface, sub, chrome, soft);
|
|
1527
|
+
const fill = accentFill(hex, dark, bg, surface, sub, chrome, soft);
|
|
1528
|
+
const away = dark ? "#ffffff" : "#000000";
|
|
1460
1529
|
const vars = {
|
|
1461
|
-
"--accent":
|
|
1462
|
-
"--accent-hover": mixHex(
|
|
1463
|
-
"--accent-press": mixHex(
|
|
1464
|
-
"--accent-soft":
|
|
1530
|
+
"--accent": fill,
|
|
1531
|
+
"--accent-hover": mixHex(fill, away, .12),
|
|
1532
|
+
"--accent-press": mixHex(fill, away, .22),
|
|
1533
|
+
"--accent-soft": soft,
|
|
1465
1534
|
"--accent-text": text,
|
|
1466
|
-
"--on-accent":
|
|
1467
|
-
"--focus
|
|
1535
|
+
"--on-accent": onFill(fill),
|
|
1536
|
+
"--focus": text,
|
|
1537
|
+
"--focus-ring": text
|
|
1468
1538
|
};
|
|
1469
1539
|
for (const [k, v] of Object.entries(vars)) root.style.setProperty(k, v);
|
|
1470
1540
|
if (!quiet) store(ACCENT_KEY, hex);
|
|
@@ -1505,20 +1575,11 @@ function divergeToken(diff, limits) {
|
|
|
1505
1575
|
return diff < 0 ? strong ? "diverge-neg-strong" : "diverge-neg" : strong ? "diverge-pos-strong" : "diverge-pos";
|
|
1506
1576
|
}
|
|
1507
1577
|
// src/components/AccentPicker/AccentPicker.tsx
|
|
1508
|
-
const SWATCHES =
|
|
1509
|
-
["藍", "#2457d6"],
|
|
1510
|
-
["靛", "#5b4fd6"],
|
|
1511
|
-
["紫", "#8a4fd6"],
|
|
1512
|
-
["桃紅", "#c2407a"],
|
|
1513
|
-
["紅", "#cd3a2f"],
|
|
1514
|
-
["橘", "#b85a0e"],
|
|
1515
|
-
["綠", "#1a844a"],
|
|
1516
|
-
["青", "#0e827d"]
|
|
1517
|
-
];
|
|
1578
|
+
const SWATCHES = ACCENT_SWATCHES;
|
|
1518
1579
|
const HEX = /^#[0-9a-fA-F]{6}$/;
|
|
1519
1580
|
/** 8 swatches plus a hex field for any color. */
|
|
1520
1581
|
function AccentPicker({ value, onChange, label, className }) {
|
|
1521
|
-
const [own, setOwn] = React.useState(() => (value ||
|
|
1582
|
+
const [own, setOwn] = React.useState(() => (value || storedAccent()).toLowerCase());
|
|
1522
1583
|
const [hexIn, setHexIn] = React.useState("");
|
|
1523
1584
|
const cur = (value || own).toLowerCase();
|
|
1524
1585
|
const pick = (c) => {
|
|
@@ -1527,18 +1588,24 @@ function AccentPicker({ value, onChange, label, className }) {
|
|
|
1527
1588
|
else setAccent(c);
|
|
1528
1589
|
};
|
|
1529
1590
|
const bad = !!hexIn && !HEX.test(hexIn);
|
|
1591
|
+
const refs = React.useRef([]);
|
|
1592
|
+
const tabStop = Math.max(0, SWATCHES.findIndex(([, hex]) => hex === cur));
|
|
1530
1593
|
return /* @__PURE__ */ jsxs("div", {
|
|
1531
1594
|
className: cx("ui-accentpick", className),
|
|
1532
1595
|
children: [/* @__PURE__ */ jsx("div", {
|
|
1533
1596
|
role: "radiogroup",
|
|
1534
1597
|
"aria-label": label || tr("強調色"),
|
|
1535
1598
|
className: "ui-accentpick-swatches",
|
|
1536
|
-
children: SWATCHES.map(([name, hex]) => {
|
|
1599
|
+
children: SWATCHES.map(([name, hex], i) => {
|
|
1537
1600
|
const on = cur === hex;
|
|
1538
1601
|
return /* @__PURE__ */ jsx("button", {
|
|
1602
|
+
ref: (el) => {
|
|
1603
|
+
refs.current[i] = el;
|
|
1604
|
+
},
|
|
1539
1605
|
type: "button",
|
|
1540
1606
|
role: "radio",
|
|
1541
1607
|
"aria-checked": on,
|
|
1608
|
+
tabIndex: i === tabStop ? 0 : -1,
|
|
1542
1609
|
"aria-label": tr(name),
|
|
1543
1610
|
title: tr(name),
|
|
1544
1611
|
className: cx("ui-swatch", on && "is-on"),
|
|
@@ -1550,6 +1617,16 @@ function AccentPicker({ value, onChange, label, className }) {
|
|
|
1550
1617
|
setHexIn("");
|
|
1551
1618
|
pick(hex);
|
|
1552
1619
|
},
|
|
1620
|
+
onKeyDown: (e) => {
|
|
1621
|
+
if (browserKey(e)) return;
|
|
1622
|
+
const n = SWATCHES.length;
|
|
1623
|
+
const to = e.key === "ArrowRight" || e.key === "ArrowDown" ? (i + 1) % n : e.key === "ArrowLeft" || e.key === "ArrowUp" ? (i - 1 + n) % n : -1;
|
|
1624
|
+
if (to < 0) return;
|
|
1625
|
+
e.preventDefault();
|
|
1626
|
+
refs.current[to]?.focus();
|
|
1627
|
+
setHexIn("");
|
|
1628
|
+
pick(SWATCHES[to][1]);
|
|
1629
|
+
},
|
|
1553
1630
|
children: on ? /* @__PURE__ */ jsx(Icon, {
|
|
1554
1631
|
name: "check",
|
|
1555
1632
|
size: 14
|
|
@@ -2206,7 +2283,7 @@ function Card({ as: Tag = "section", title, actions, padding = true, className,
|
|
|
2206
2283
|
children: [title ? /* @__PURE__ */ jsx("h2", {
|
|
2207
2284
|
className: "ui-card-title",
|
|
2208
2285
|
children: title
|
|
2209
|
-
}) :
|
|
2286
|
+
}) : null, actions ? /* @__PURE__ */ jsx("div", {
|
|
2210
2287
|
className: "ui-card-actions",
|
|
2211
2288
|
children: actions
|
|
2212
2289
|
}) : null]
|
|
@@ -2253,6 +2330,30 @@ function CheckMark({ v }) {
|
|
|
2253
2330
|
children: /* @__PURE__ */ jsx("path", { d: CHECK })
|
|
2254
2331
|
});
|
|
2255
2332
|
}
|
|
2333
|
+
/** The error mark inside a field with an error: a red warning circle at the field's right end (TextField and every other
|
|
2334
|
+
* field type, so an error always shows the red border and this icon). `inline` sits in a flex row before the field's
|
|
2335
|
+
* own trailing button (show password, calendar, caret) instead of over the input. */
|
|
2336
|
+
function FieldErrorIcon({ inline }) {
|
|
2337
|
+
return /* @__PURE__ */ jsx(Icon, {
|
|
2338
|
+
name: "warning-circle",
|
|
2339
|
+
className: cx("ui-field-icon", inline && "is-inline")
|
|
2340
|
+
});
|
|
2341
|
+
}
|
|
2342
|
+
/** The line under a field: the error (cause and fix) when there is one, otherwise the hint. The error is inserted only
|
|
2343
|
+
* while there is one, keyed by its text: a new error is a new alert node, announced once; the hint never announces. */
|
|
2344
|
+
function FieldMessage({ id, error, hint, className }) {
|
|
2345
|
+
if (error) return /* @__PURE__ */ jsx("div", {
|
|
2346
|
+
id,
|
|
2347
|
+
className: cx("ui-field-error", className),
|
|
2348
|
+
role: "alert",
|
|
2349
|
+
children: error
|
|
2350
|
+
}, error);
|
|
2351
|
+
return hint ? /* @__PURE__ */ jsx("div", {
|
|
2352
|
+
id,
|
|
2353
|
+
className: cx("ui-field-hint", className),
|
|
2354
|
+
children: hint
|
|
2355
|
+
}) : null;
|
|
2356
|
+
}
|
|
2256
2357
|
// src/components/Checkbox/Checkbox.tsx
|
|
2257
2358
|
/** A check box with a drawn check mark. The whole row is the touch target. */
|
|
2258
2359
|
function Checkbox({ checked, onChange, label, disabled, className, ...aria }) {
|
|
@@ -3643,6 +3744,7 @@ function DangerZone({ title, description, actionLabel, onAction, confirm, classN
|
|
|
3643
3744
|
// src/components/SearchField/SearchField.tsx
|
|
3644
3745
|
/** A search box with a clear button. Filter as the person types. */
|
|
3645
3746
|
function SearchField({ value, onChange, className, label, ...native }) {
|
|
3747
|
+
const input = React.useRef(null);
|
|
3646
3748
|
return /* @__PURE__ */ jsxs("div", {
|
|
3647
3749
|
className: cx("ui-searchfield", className),
|
|
3648
3750
|
children: [
|
|
@@ -3652,6 +3754,7 @@ function SearchField({ value, onChange, className, label, ...native }) {
|
|
|
3652
3754
|
className: "ui-searchfield-icon"
|
|
3653
3755
|
}),
|
|
3654
3756
|
/* @__PURE__ */ jsx("input", {
|
|
3757
|
+
ref: input,
|
|
3655
3758
|
type: "search",
|
|
3656
3759
|
"aria-label": label || tr("搜尋"),
|
|
3657
3760
|
...native,
|
|
@@ -3663,7 +3766,10 @@ function SearchField({ value, onChange, className, label, ...native }) {
|
|
|
3663
3766
|
type: "button",
|
|
3664
3767
|
className: "ui-searchfield-clear",
|
|
3665
3768
|
"aria-label": tr("清除搜尋"),
|
|
3666
|
-
onClick: () =>
|
|
3769
|
+
onClick: () => {
|
|
3770
|
+
onChange("");
|
|
3771
|
+
input.current?.focus();
|
|
3772
|
+
},
|
|
3667
3773
|
children: /* @__PURE__ */ jsx(Icon, {
|
|
3668
3774
|
name: "x",
|
|
3669
3775
|
size: 12
|
|
@@ -3930,23 +4036,6 @@ function TableDialog(p) {
|
|
|
3930
4036
|
})
|
|
3931
4037
|
});
|
|
3932
4038
|
}
|
|
3933
|
-
/** The 「複製成 Markdown」 icon: copies the text, turns into a check for 2 s and says 「已複製」, as CodeView's copy. */
|
|
3934
|
-
function CopyMarkdownButton(p) {
|
|
3935
|
-
const [done, setDone] = React.useState(false);
|
|
3936
|
-
const timer = React.useRef(void 0);
|
|
3937
|
-
React.useEffect(() => () => clearTimeout(timer.current), []);
|
|
3938
|
-
return /* @__PURE__ */ jsx(IconButton, {
|
|
3939
|
-
className: cx("ui-table-copy", done && "is-copied", p.className),
|
|
3940
|
-
icon: done ? CHECK : "copy",
|
|
3941
|
-
label: done ? tr("已複製") : tr("複製成 Markdown"),
|
|
3942
|
-
onClick: () => copyText(p.text()).then(() => {
|
|
3943
|
-
setDone(true);
|
|
3944
|
-
announce(tr("已複製"));
|
|
3945
|
-
clearTimeout(timer.current);
|
|
3946
|
-
timer.current = setTimeout(() => setDone(false), 2e3);
|
|
3947
|
-
}, () => p.onCopyError?.())
|
|
3948
|
-
});
|
|
3949
|
-
}
|
|
3950
4039
|
/** A table as GitHub Markdown: | in a cell is escaped, line breaks become spaces. */
|
|
3951
4040
|
function markdownTable(heads, rows) {
|
|
3952
4041
|
const cell = (s) => s.replace(/\r?\n/g, " ").replace(/\|/g, "\\|").trim();
|
|
@@ -3966,9 +4055,23 @@ function cellText(c, v) {
|
|
|
3966
4055
|
if (c.format === "date") return format.date(asDate());
|
|
3967
4056
|
if (c.format === "datetime") return format.dateTime(asDate());
|
|
3968
4057
|
if (c.format === "relative") return format.relative(asDate());
|
|
4058
|
+
if (c.format === "duration") return format.duration(Number(v));
|
|
3969
4059
|
const n = c.format === "percent" ? format.number(Number(v), c.decimals ?? "percent") : c.numeric && typeof v === "number" ? format.number(v, c.decimals ?? (c.unit === "GB" || c.unit === "MB" ? "size" : 0)) : String(v);
|
|
3970
4060
|
return c.unit ? `${n} ${c.unit}` : n;
|
|
3971
4061
|
}
|
|
4062
|
+
/** Date formats: shown as dates, written as <time>, sorted by time. */
|
|
4063
|
+
const DATE_FORMATS = [
|
|
4064
|
+
"date",
|
|
4065
|
+
"datetime",
|
|
4066
|
+
"relative"
|
|
4067
|
+
];
|
|
4068
|
+
const isDateCol = (c) => DATE_FORMATS.includes(c.format ?? "");
|
|
4069
|
+
/** A cell value as a Date, or null when it is missing or not a date. */
|
|
4070
|
+
function asDate(v) {
|
|
4071
|
+
if (v === null || v === void 0 || v === "") return null;
|
|
4072
|
+
const d = v instanceof Date ? v : new Date(v);
|
|
4073
|
+
return Number.isNaN(d.getTime()) ? null : d;
|
|
4074
|
+
}
|
|
3972
4075
|
/** The filters with defaults: list type, multiple, and options from the rows' distinct values. */
|
|
3973
4076
|
function resolveFilters(filters, rows) {
|
|
3974
4077
|
return filters.map((f) => {
|
|
@@ -4022,6 +4125,7 @@ function searchHit(row, cols, filters, q, keys) {
|
|
|
4022
4125
|
const opt = filters.find((x) => x.key === c.key)?.options.find((o) => o.value === String(raw));
|
|
4023
4126
|
if (opt) t += " " + opt.label;
|
|
4024
4127
|
if (!t && c.render) t = raw == null ? "" : String(raw);
|
|
4128
|
+
if (c.secondary) t += " " + nodeText(c.secondary(row));
|
|
4025
4129
|
return t.toLowerCase().includes(ql);
|
|
4026
4130
|
});
|
|
4027
4131
|
}
|
|
@@ -4097,48 +4201,158 @@ function markMatch(text, q) {
|
|
|
4097
4201
|
text.slice(i + q.length)
|
|
4098
4202
|
] });
|
|
4099
4203
|
}
|
|
4100
|
-
/**
|
|
4101
|
-
|
|
4102
|
-
|
|
4103
|
-
|
|
4104
|
-
|
|
4105
|
-
|
|
4204
|
+
/** The toolbar's 「⋯」 (更多表格操作): the secondary tools in one menu. 「欄位」 opens a submenu of checkboxes (the first
|
|
4205
|
+
* column cannot be hidden) with 「還原預設」 at its end; 「複製成 Markdown」 and 「放大表格」 follow. A tool that is off
|
|
4206
|
+
* is left out; with none the button is not drawn. Keyboard: Base UI Menu (↑ ↓, → opens the submenu, Esc closes). */
|
|
4207
|
+
function MoreMenu({ columns, onCopy, onZoom }) {
|
|
4208
|
+
if (!columns && !onCopy && !onZoom) return null;
|
|
4209
|
+
const label = tr("更多表格操作");
|
|
4210
|
+
return /* @__PURE__ */ jsxs(Menu$1.Root, { children: [/* @__PURE__ */ jsx(Tooltip, {
|
|
4211
|
+
label,
|
|
4212
|
+
describe: false,
|
|
4213
|
+
children: /* @__PURE__ */ jsx(Menu$1.Trigger, {
|
|
4214
|
+
className: cx("ui-iconbtn", "is-quiet", "ui-menu-trigger", "ui-dt-menubtn"),
|
|
4215
|
+
"aria-label": label,
|
|
4216
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
4217
|
+
name: "dots-three",
|
|
4218
|
+
size: 20
|
|
4219
|
+
})
|
|
4220
|
+
})
|
|
4221
|
+
}), /* @__PURE__ */ jsx(Menu$1.Portal, { children: /* @__PURE__ */ jsx(Menu$1.Positioner, {
|
|
4222
|
+
className: "ui-float",
|
|
4223
|
+
side: "bottom",
|
|
4106
4224
|
align: "end",
|
|
4107
|
-
|
|
4108
|
-
|
|
4109
|
-
|
|
4225
|
+
sideOffset: 4,
|
|
4226
|
+
children: /* @__PURE__ */ jsxs(Menu$1.Popup, {
|
|
4227
|
+
className: "ui-menu ui-dt-moremenu",
|
|
4228
|
+
children: [
|
|
4229
|
+
columns ? /* @__PURE__ */ jsxs(Menu$1.SubmenuRoot, { children: [/* @__PURE__ */ jsxs(Menu$1.SubmenuTrigger, {
|
|
4230
|
+
className: "ui-menu-item",
|
|
4231
|
+
children: [
|
|
4232
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
4233
|
+
name: "columns",
|
|
4234
|
+
size: 16
|
|
4235
|
+
}),
|
|
4236
|
+
/* @__PURE__ */ jsx("span", {
|
|
4237
|
+
className: "ui-menu-label",
|
|
4238
|
+
children: tr("欄位")
|
|
4239
|
+
}),
|
|
4240
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
4241
|
+
name: "caret-right",
|
|
4242
|
+
size: 16,
|
|
4243
|
+
className: "ui-dt-subcaret"
|
|
4244
|
+
})
|
|
4245
|
+
]
|
|
4246
|
+
}), /* @__PURE__ */ jsx(Menu$1.Portal, { children: /* @__PURE__ */ jsx(Menu$1.Positioner, {
|
|
4247
|
+
className: "ui-float",
|
|
4248
|
+
side: "left",
|
|
4249
|
+
align: "start",
|
|
4250
|
+
sideOffset: 4,
|
|
4251
|
+
alignOffset: -6,
|
|
4252
|
+
children: /* @__PURE__ */ jsxs(Menu$1.Popup, {
|
|
4253
|
+
className: "ui-menu ui-dt-colmenu",
|
|
4254
|
+
"aria-label": tr("顯示的欄位"),
|
|
4255
|
+
children: [
|
|
4256
|
+
/* @__PURE__ */ jsxs(Menu$1.Group, { children: [/* @__PURE__ */ jsx(Menu$1.GroupLabel, {
|
|
4257
|
+
className: "ui-noti-group",
|
|
4258
|
+
children: tr("顯示的欄位")
|
|
4259
|
+
}), columns.cols.map((c, i) => {
|
|
4260
|
+
const on = i === 0 || !columns.hidden[c.key];
|
|
4261
|
+
return /* @__PURE__ */ jsxs(Menu$1.CheckboxItem, {
|
|
4262
|
+
checked: on,
|
|
4263
|
+
disabled: i === 0,
|
|
4264
|
+
closeOnClick: false,
|
|
4265
|
+
className: "ui-menu-item",
|
|
4266
|
+
onCheckedChange: () => columns.onToggle(c.key),
|
|
4267
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4268
|
+
className: cx("ui-check-box", on && "is-on"),
|
|
4269
|
+
"aria-hidden": "true",
|
|
4270
|
+
children: /* @__PURE__ */ jsx(CheckMark, { v: on })
|
|
4271
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4272
|
+
className: "ui-menu-label",
|
|
4273
|
+
children: c.label
|
|
4274
|
+
})]
|
|
4275
|
+
}, c.key);
|
|
4276
|
+
})] }),
|
|
4277
|
+
/* @__PURE__ */ jsx(Menu$1.Separator, { className: "ui-menu-sep" }),
|
|
4278
|
+
/* @__PURE__ */ jsxs(Menu$1.Item, {
|
|
4279
|
+
className: "ui-menu-item",
|
|
4280
|
+
closeOnClick: false,
|
|
4281
|
+
onClick: columns.onReset,
|
|
4282
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
4283
|
+
name: "arrow-u-up-left",
|
|
4284
|
+
size: 16
|
|
4285
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4286
|
+
className: "ui-menu-label",
|
|
4287
|
+
children: tr("還原預設")
|
|
4288
|
+
})]
|
|
4289
|
+
})
|
|
4290
|
+
]
|
|
4291
|
+
})
|
|
4292
|
+
}) })] }) : null,
|
|
4293
|
+
onCopy ? /* @__PURE__ */ jsxs(Menu$1.Item, {
|
|
4294
|
+
className: "ui-menu-item",
|
|
4295
|
+
onClick: onCopy,
|
|
4296
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
4297
|
+
name: "copy",
|
|
4298
|
+
size: 16
|
|
4299
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4300
|
+
className: "ui-menu-label",
|
|
4301
|
+
children: tr("複製成 Markdown")
|
|
4302
|
+
})]
|
|
4303
|
+
}) : null,
|
|
4304
|
+
onZoom ? /* @__PURE__ */ jsxs(Menu$1.Item, {
|
|
4305
|
+
className: "ui-menu-item",
|
|
4306
|
+
onClick: onZoom,
|
|
4307
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
4308
|
+
name: "corners-out",
|
|
4309
|
+
size: 16
|
|
4310
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
4311
|
+
className: "ui-menu-label",
|
|
4312
|
+
children: tr("放大表格")
|
|
4313
|
+
})]
|
|
4314
|
+
}) : null
|
|
4315
|
+
]
|
|
4316
|
+
})
|
|
4317
|
+
}) })] });
|
|
4318
|
+
}
|
|
4319
|
+
/** The applied conditions under the toolbar, each removable, and 「清除全部」; nothing when no condition is applied.
|
|
4320
|
+
* Removing one moves focus to the next chip (or the previous, or 「篩選」 when none is left). */
|
|
4321
|
+
function FilterChips({ chips, onClear, filterButton }) {
|
|
4322
|
+
const box = React.useRef(null);
|
|
4323
|
+
if (!chips.length) return null;
|
|
4324
|
+
const focusAfter = (i) => requestAnimationFrame(() => {
|
|
4325
|
+
const left = box.current?.querySelectorAll(".ui-dt-chip");
|
|
4326
|
+
(left?.[Math.min(i, left.length - 1)] ?? filterButton())?.focus();
|
|
4327
|
+
});
|
|
4328
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
4329
|
+
ref: box,
|
|
4330
|
+
className: "ui-dt-chips",
|
|
4331
|
+
role: "group",
|
|
4332
|
+
"aria-label": tr("套用的篩選"),
|
|
4333
|
+
children: [chips.map((c, i) => /* @__PURE__ */ jsxs("button", {
|
|
4110
4334
|
type: "button",
|
|
4111
|
-
className:
|
|
4112
|
-
"aria-label": tr("
|
|
4113
|
-
|
|
4114
|
-
|
|
4115
|
-
|
|
4116
|
-
}
|
|
4117
|
-
|
|
4118
|
-
|
|
4335
|
+
className: "ui-dt-chip",
|
|
4336
|
+
"aria-label": tr("移除篩選:{name}", { name: c.text }),
|
|
4337
|
+
onClick: () => {
|
|
4338
|
+
c.remove();
|
|
4339
|
+
focusAfter(i);
|
|
4340
|
+
},
|
|
4341
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4342
|
+
className: "ui-dt-chip-text",
|
|
4343
|
+
children: c.text
|
|
4344
|
+
}), /* @__PURE__ */ jsx(Icon, {
|
|
4345
|
+
name: "x",
|
|
4346
|
+
size: 16
|
|
4119
4347
|
})]
|
|
4120
|
-
}),
|
|
4121
|
-
|
|
4122
|
-
className: "ui-
|
|
4123
|
-
|
|
4124
|
-
|
|
4125
|
-
|
|
4126
|
-
|
|
4127
|
-
|
|
4128
|
-
role: "checkbox",
|
|
4129
|
-
"aria-checked": on,
|
|
4130
|
-
disabled: i === 0,
|
|
4131
|
-
className: "ui-menu-item",
|
|
4132
|
-
onClick: () => onToggle(c.key),
|
|
4133
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
4134
|
-
className: cx("ui-check-box", on && "is-on"),
|
|
4135
|
-
"aria-hidden": "true",
|
|
4136
|
-
children: /* @__PURE__ */ jsx(CheckMark, { v: on })
|
|
4137
|
-
}), /* @__PURE__ */ jsx("span", {
|
|
4138
|
-
className: "ui-menu-label",
|
|
4139
|
-
children: c.label
|
|
4140
|
-
})]
|
|
4141
|
-
}, c.key);
|
|
4348
|
+
}, c.id)), /* @__PURE__ */ jsx("button", {
|
|
4349
|
+
type: "button",
|
|
4350
|
+
className: "ui-link-btn ui-dt-chipclear",
|
|
4351
|
+
onClick: () => {
|
|
4352
|
+
onClear();
|
|
4353
|
+
requestAnimationFrame(() => filterButton()?.focus());
|
|
4354
|
+
},
|
|
4355
|
+
children: tr("清除全部")
|
|
4142
4356
|
})]
|
|
4143
4357
|
});
|
|
4144
4358
|
}
|
|
@@ -4153,11 +4367,12 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear,
|
|
|
4153
4367
|
"aria-label": tr("篩選"),
|
|
4154
4368
|
trigger: /* @__PURE__ */ jsxs("button", {
|
|
4155
4369
|
type: "button",
|
|
4156
|
-
className: cx("ui-btn", "ui-btn-secondary", "ui-dt-filterbtn", open && "is-open"),
|
|
4370
|
+
className: cx("ui-btn", "ui-btn-secondary", "ui-dt-filterbtn", open && "is-open", activeCount > 0 && "is-active"),
|
|
4371
|
+
"aria-label": activeCount ? tr("篩選,已套用 {n} 個條件", { n: activeCount }) : void 0,
|
|
4157
4372
|
children: [
|
|
4158
4373
|
/* @__PURE__ */ jsx(Icon, {
|
|
4159
4374
|
name: "funnel",
|
|
4160
|
-
size:
|
|
4375
|
+
size: 20
|
|
4161
4376
|
}),
|
|
4162
4377
|
/* @__PURE__ */ jsx("span", {
|
|
4163
4378
|
className: "ui-dt-btntext",
|
|
@@ -4382,7 +4597,7 @@ function SortButton({ cols, levels, max, onChange, boundary }) {
|
|
|
4382
4597
|
children: [
|
|
4383
4598
|
/* @__PURE__ */ jsx(Icon, {
|
|
4384
4599
|
name: "sort-ascending",
|
|
4385
|
-
size:
|
|
4600
|
+
size: 20
|
|
4386
4601
|
}),
|
|
4387
4602
|
/* @__PURE__ */ jsx("span", {
|
|
4388
4603
|
className: "ui-dt-sortbtn-text",
|
|
@@ -4554,7 +4769,79 @@ const ARROWS = {
|
|
|
4554
4769
|
none: "M8 9l4-4 4 4M8 15l4 4 4-4"
|
|
4555
4770
|
};
|
|
4556
4771
|
const get = (row, key) => row[key];
|
|
4557
|
-
const isNum = (c) => c.numeric || c.format === "money" || c.format === "percent";
|
|
4772
|
+
const isNum = (c) => c.numeric || c.format === "money" || c.format === "percent" || c.format === "duration";
|
|
4773
|
+
const isShort = (c) => isNum(c) || !!c.unit || isDateCol(c) || c.mobile === "status";
|
|
4774
|
+
const TEXT_HUG_MAX = 280;
|
|
4775
|
+
const HUG_START = 96;
|
|
4776
|
+
const CELL_PAD = 25;
|
|
4777
|
+
const isoOf = (d, dateOnly) => dateOnly ? `${d.getFullYear()}-${String(d.getMonth() + 1).padStart(2, "0")}-${String(d.getDate()).padStart(2, "0")}` : d.toISOString();
|
|
4778
|
+
/** The width of what an element holds (its text and children, not absolutely placed parts such as the column border). */
|
|
4779
|
+
function contentWidth(el) {
|
|
4780
|
+
let left = Infinity;
|
|
4781
|
+
let right = -Infinity;
|
|
4782
|
+
const range = document.createRange();
|
|
4783
|
+
for (const n of el.childNodes) {
|
|
4784
|
+
let r = null;
|
|
4785
|
+
if (n instanceof HTMLElement) {
|
|
4786
|
+
if (n.classList.contains("ui-col-resize") || getComputedStyle(n).position === "absolute") continue;
|
|
4787
|
+
r = n.getBoundingClientRect();
|
|
4788
|
+
} else if (n.nodeType === Node.TEXT_NODE && n.textContent?.trim()) {
|
|
4789
|
+
range.selectNodeContents(n);
|
|
4790
|
+
r = range.getBoundingClientRect();
|
|
4791
|
+
}
|
|
4792
|
+
if (r && r.width) {
|
|
4793
|
+
left = Math.min(left, r.left);
|
|
4794
|
+
right = Math.max(right, r.right);
|
|
4795
|
+
}
|
|
4796
|
+
}
|
|
4797
|
+
return right > left ? right - left : 0;
|
|
4798
|
+
}
|
|
4799
|
+
const shortcutTables = /* @__PURE__ */ new Set();
|
|
4800
|
+
const shortcutListeners = /* @__PURE__ */ new Set();
|
|
4801
|
+
let shortcutSizes = null;
|
|
4802
|
+
const notifyShortcut = () => shortcutListeners.forEach((f) => f());
|
|
4803
|
+
/** Rendered and not hidden: not display: none (itself or an ancestor), not visibility: hidden, not inert or aria-hidden. */
|
|
4804
|
+
function isShown(el) {
|
|
4805
|
+
if (!el.isConnected || el.closest("[inert], [aria-hidden=\"true\"]")) return false;
|
|
4806
|
+
const check = el.checkVisibility;
|
|
4807
|
+
if (typeof check === "function") return check.call(el, {
|
|
4808
|
+
checkVisibilityCSS: true,
|
|
4809
|
+
visibilityProperty: true
|
|
4810
|
+
});
|
|
4811
|
+
return el.getClientRects().length > 0 && getComputedStyle(el).visibility !== "hidden";
|
|
4812
|
+
}
|
|
4813
|
+
const shortcutInput = (el) => el.querySelector(":scope > .ui-dt-tools .ui-dt-search input");
|
|
4814
|
+
const firstShortcutTable = () => [...shortcutTables].filter((el) => isShown(el) && !!shortcutInput(el)).sort((a, b) => a.compareDocumentPosition(b) & Node.DOCUMENT_POSITION_FOLLOWING ? -1 : 1)[0] ?? null;
|
|
4815
|
+
const SLASH_OWNERS = "input, textarea, select, [contenteditable]:not([contenteditable=\"false\"]), [role=\"textbox\"], [role=\"searchbox\"], [role=\"combobox\"], [role=\"listbox\"], [role=\"grid\"], [role=\"treegrid\"], [role=\"tree\"], [role=\"menu\"], [role=\"menubar\"], [role=\"dialog\"], [role=\"alertdialog\"], dialog";
|
|
4816
|
+
function onSlash(e) {
|
|
4817
|
+
if (e.key !== "/" || e.ctrlKey || e.metaKey || e.altKey || e.defaultPrevented || e.isComposing) return;
|
|
4818
|
+
if ((e.target instanceof Element ? e.target : null)?.closest(SLASH_OWNERS)) return;
|
|
4819
|
+
const table = firstShortcutTable();
|
|
4820
|
+
const input = table ? shortcutInput(table) : null;
|
|
4821
|
+
if (!input) return;
|
|
4822
|
+
input.focus();
|
|
4823
|
+
if (document.activeElement === input) e.preventDefault();
|
|
4824
|
+
}
|
|
4825
|
+
function registerShortcut(el, changed) {
|
|
4826
|
+
if (!shortcutTables.size) document.addEventListener("keydown", onSlash);
|
|
4827
|
+
if (!shortcutSizes && typeof ResizeObserver !== "undefined") shortcutSizes = new ResizeObserver(notifyShortcut);
|
|
4828
|
+
shortcutTables.add(el);
|
|
4829
|
+
shortcutListeners.add(changed);
|
|
4830
|
+
shortcutSizes?.observe(el);
|
|
4831
|
+
notifyShortcut();
|
|
4832
|
+
return () => {
|
|
4833
|
+
shortcutTables.delete(el);
|
|
4834
|
+
shortcutListeners.delete(changed);
|
|
4835
|
+
shortcutSizes?.unobserve(el);
|
|
4836
|
+
if (!shortcutTables.size) {
|
|
4837
|
+
document.removeEventListener("keydown", onSlash);
|
|
4838
|
+
shortcutSizes?.disconnect();
|
|
4839
|
+
shortcutSizes = null;
|
|
4840
|
+
}
|
|
4841
|
+
notifyShortcut();
|
|
4842
|
+
};
|
|
4843
|
+
}
|
|
4844
|
+
const newTab = (e) => e.ctrlKey || e.metaKey || e.shiftKey || e.button === 1;
|
|
4558
4845
|
const ROW_CONTROLS = "a, button, input, select, textarea, label, [role=\"checkbox\"], [role=\"button\"], [role=\"menuitem\"], [role=\"link\"], [contenteditable]";
|
|
4559
4846
|
function RowCheck({ v, label, onClick }) {
|
|
4560
4847
|
return /* @__PURE__ */ jsx("button", {
|
|
@@ -4563,9 +4850,10 @@ function RowCheck({ v, label, onClick }) {
|
|
|
4563
4850
|
"aria-checked": v,
|
|
4564
4851
|
"aria-label": label,
|
|
4565
4852
|
className: cx("ui-check-box", "ui-dt-check", v && "is-on"),
|
|
4853
|
+
onMouseDown: (e) => e.shiftKey && e.preventDefault(),
|
|
4566
4854
|
onClick: (e) => {
|
|
4567
4855
|
e.stopPropagation();
|
|
4568
|
-
onClick();
|
|
4856
|
+
onClick(e);
|
|
4569
4857
|
},
|
|
4570
4858
|
children: /* @__PURE__ */ jsx(CheckMark, { v })
|
|
4571
4859
|
});
|
|
@@ -4595,7 +4883,7 @@ function DataTable(p) {
|
|
|
4595
4883
|
const sortCols = cols.filter((c) => c.sortable !== false).map((c) => ({
|
|
4596
4884
|
key: c.key,
|
|
4597
4885
|
label: c.label,
|
|
4598
|
-
numeric: c
|
|
4886
|
+
numeric: isNum(c)
|
|
4599
4887
|
}));
|
|
4600
4888
|
const firstDir = (key) => sortCols.find((c) => c.key === key)?.numeric ? "desc" : "asc";
|
|
4601
4889
|
const validSort = (l) => l.filter((x, i) => sortCols.some((c) => c.key === x.key) && l.findIndex((y) => y.key === x.key) === i).slice(0, maxSort).map((x) => ({
|
|
@@ -4608,9 +4896,27 @@ function DataTable(p) {
|
|
|
4608
4896
|
const [q, setQ] = React.useState(() => fromUrl().q);
|
|
4609
4897
|
const [values, setValues] = React.useState(() => fromUrl().values);
|
|
4610
4898
|
const [view, setView] = React.useState(p.views?.[0]?.id ?? null);
|
|
4611
|
-
const
|
|
4899
|
+
const colsKey = p.widthKey ? "ui-dt-cols:" + p.widthKey : null;
|
|
4900
|
+
const [toggled, setToggledState] = React.useState(() => {
|
|
4901
|
+
if (!colsKey) return {};
|
|
4902
|
+
try {
|
|
4903
|
+
const v = JSON.parse(localStorage.getItem(colsKey) || "null");
|
|
4904
|
+
return v && typeof v === "object" ? v : {};
|
|
4905
|
+
} catch {
|
|
4906
|
+
return {};
|
|
4907
|
+
}
|
|
4908
|
+
});
|
|
4909
|
+
const setToggled = (t) => {
|
|
4910
|
+
setToggledState(t);
|
|
4911
|
+
if (!colsKey) return;
|
|
4912
|
+
try {
|
|
4913
|
+
if (Object.keys(t).length) localStorage.setItem(colsKey, JSON.stringify(t));
|
|
4914
|
+
else localStorage.removeItem(colsKey);
|
|
4915
|
+
} catch {}
|
|
4916
|
+
};
|
|
4612
4917
|
const [opened, setOpened] = React.useState({});
|
|
4613
4918
|
const narrow = useNarrow();
|
|
4919
|
+
const touch = useMedia(TOUCH_ONLY);
|
|
4614
4920
|
const uid = React.useId();
|
|
4615
4921
|
const rootRef = React.useRef(null);
|
|
4616
4922
|
const [sel, setSel] = React.useState({});
|
|
@@ -4652,7 +4958,7 @@ function DataTable(p) {
|
|
|
4652
4958
|
setSel({});
|
|
4653
4959
|
setSumVal("all");
|
|
4654
4960
|
setSort(initialSort);
|
|
4655
|
-
|
|
4961
|
+
if (!colsKey) setToggledState({});
|
|
4656
4962
|
setOpened({});
|
|
4657
4963
|
setFit({});
|
|
4658
4964
|
}
|
|
@@ -4668,6 +4974,22 @@ function DataTable(p) {
|
|
|
4668
4974
|
devWarn(rows.length > 1 && rows.every((r) => get(r, "id") == null) && selectable, "DataTable", "rows have no id, so a selection follows the position, not the row. Add an id to each row.");
|
|
4669
4975
|
devWarn(!!cols[0]?.hidden, "DataTable", "the first column is always shown, so its hidden: true does nothing. Move the column, or drop hidden.");
|
|
4670
4976
|
devWarn((p.columnMenu === false || cols.length <= 2) && cols.some((c, i) => i > 0 && c.hidden), "DataTable", "a column has hidden: true but there is no 「欄位」 menu (columnMenu is false, or the table has 2 columns or fewer), so nobody can turn it on. Turn the menu on, or leave the column out.");
|
|
4977
|
+
const sumKey = p.summary?.key;
|
|
4978
|
+
const twiceFilter = sumKey ? filters.find((f) => f.key === sumKey) : void 0;
|
|
4979
|
+
devWarn(twiceFilter, "DataTable", `the filter 「${twiceFilter?.label}」 filters ${String(sumKey)}, which the summary tabs already filter, so the same condition is in two places. Drop it from filters (or drop summary).`);
|
|
4980
|
+
const twiceView = sumKey && rows.length ? p.views?.find((v) => {
|
|
4981
|
+
if (!v.filter) return false;
|
|
4982
|
+
const kept = rows.filter((r) => v.filter?.(r));
|
|
4983
|
+
if (!kept.length || kept.length === rows.length) return false;
|
|
4984
|
+
const val = String(get(kept[0], sumKey));
|
|
4985
|
+
return kept.every((r) => String(get(r, sumKey)) === val) && rows.filter((r) => String(get(r, sumKey)) === val).length === kept.length;
|
|
4986
|
+
}) : void 0;
|
|
4987
|
+
devWarn(twiceView, "DataTable", `the view 「${twiceView?.label}」 keeps exactly the rows of one ${String(sumKey)} value, which a summary tab already picks, so the same condition is in two places. Drop the view (or drop summary).`);
|
|
4988
|
+
for (const c of cols) {
|
|
4989
|
+
if (!c.unit && !c.numeric) continue;
|
|
4990
|
+
const bad = rows.map((r) => get(r, c.key)).find((v) => typeof v === "string" && /\d/.test(v) && (c.unit ? v.includes(c.unit) : !/^\s*-?[\d,]*\.?\d+\s*$/.test(v)));
|
|
4991
|
+
devWarn(bad !== void 0, "DataTable", `column 「${c.label}」 got the string 「${String(bad)}」. Pass a number${c.unit ? "" : " and the unit in unit"} (e.g. { numeric: true, unit: '${c.unit || "字"}' } with 1234), so it is formatted, right-aligned and sorted as a number.`);
|
|
4992
|
+
}
|
|
4671
4993
|
const hidden = {};
|
|
4672
4994
|
cols.forEach((c, i) => hidden[c.key] = i > 0 && (toggled[c.key] ?? !!c.hidden));
|
|
4673
4995
|
const shownCols = cols.filter((c) => !hidden[c.key]);
|
|
@@ -4692,8 +5014,14 @@ function DataTable(p) {
|
|
|
4692
5014
|
if (sort.length) {
|
|
4693
5015
|
const by = sort.map((l) => {
|
|
4694
5016
|
const col = cols.find((c) => c.key === l.key);
|
|
5017
|
+
const val = (r) => {
|
|
5018
|
+
if (col?.sortValue) return col.sortValue(r);
|
|
5019
|
+
const v = get(r, l.key);
|
|
5020
|
+
if (v instanceof Date || col && isDateCol(col)) return asDate(v)?.getTime() ?? -Infinity;
|
|
5021
|
+
return v;
|
|
5022
|
+
};
|
|
4695
5023
|
return {
|
|
4696
|
-
val
|
|
5024
|
+
val,
|
|
4697
5025
|
d: l.dir === "asc" ? 1 : -1
|
|
4698
5026
|
};
|
|
4699
5027
|
});
|
|
@@ -4863,6 +5191,24 @@ function DataTable(p) {
|
|
|
4863
5191
|
...Object.fromEntries(ids.map((id) => [id, v]))
|
|
4864
5192
|
});
|
|
4865
5193
|
const clear = () => setSel({});
|
|
5194
|
+
const lastPick = React.useRef(null);
|
|
5195
|
+
const anchorKey = `${shownKey}|${sortKey}|${pageSize}`;
|
|
5196
|
+
React.useEffect(() => {
|
|
5197
|
+
lastPick.current = null;
|
|
5198
|
+
}, [anchorKey]);
|
|
5199
|
+
const pickRow = (id, on, shift) => {
|
|
5200
|
+
const ids = list.map(idOf);
|
|
5201
|
+
const from = shift && lastPick.current ? ids.indexOf(lastPick.current) : -1;
|
|
5202
|
+
const to = ids.indexOf(id);
|
|
5203
|
+
lastPick.current = id;
|
|
5204
|
+
if (from < 0 || to < 0 || from === to) return toggle([id], !on);
|
|
5205
|
+
const next = {
|
|
5206
|
+
...sel,
|
|
5207
|
+
...Object.fromEntries(ids.slice(Math.min(from, to), Math.max(from, to) + 1).map((k) => [k, !on]))
|
|
5208
|
+
};
|
|
5209
|
+
setSel(next);
|
|
5210
|
+
announce(tr("已選 {n} 筆", { n: ids.filter((k) => next[k]).length }));
|
|
5211
|
+
};
|
|
4866
5212
|
const clearFilters = () => {
|
|
4867
5213
|
setValues({});
|
|
4868
5214
|
setQ("");
|
|
@@ -4878,9 +5224,15 @@ function DataTable(p) {
|
|
|
4878
5224
|
const longCols = shownCols.filter((c) => c.long || c.fullText);
|
|
4879
5225
|
const expander = longCols.length > 0 && !narrow;
|
|
4880
5226
|
const EXP = 40;
|
|
4881
|
-
const
|
|
5227
|
+
const mainKey = (shownCols.find((c) => !isShort(c) && !c.long && c.grow !== 0) ?? shownCols[0])?.key;
|
|
5228
|
+
const grows = (c) => c.grow != null ? c.grow > 0 : c.long || c.key === mainKey;
|
|
5229
|
+
const minOf = (c) => {
|
|
5230
|
+
if (grows(c)) return Math.max(c.width || (isNum(c) ? 96 : 120), fit[c.key] || 0);
|
|
5231
|
+
const cap = c.width == null && !isShort(c) ? TEXT_HUG_MAX : Infinity;
|
|
5232
|
+
return Math.max(c.width || 0, 48, Math.min(fit[c.key] ?? c.width ?? HUG_START, cap));
|
|
5233
|
+
};
|
|
4882
5234
|
const layout = (w) => {
|
|
4883
|
-
const colW = (c) => w ? `${w[c.key] ?? minOf(c)}px` : `minmax(${minOf(c)}px, ${c.grow ||
|
|
5235
|
+
const colW = (c) => w ? `${w[c.key] ?? minOf(c)}px` : grows(c) ? `minmax(${minOf(c)}px, ${c.grow || 1}fr)` : `${minOf(c)}px`;
|
|
4884
5236
|
return {
|
|
4885
5237
|
gridTemplateColumns: [
|
|
4886
5238
|
expander ? "40px" : null,
|
|
@@ -4905,16 +5257,27 @@ function DataTable(p) {
|
|
|
4905
5257
|
const el = root?.querySelector(`.ui-dt-head [data-col="${CSS.escape(key)}"] > :first-child`);
|
|
4906
5258
|
return Math.max(48, el ? Math.ceil(el.getBoundingClientRect().width) + 24 : 48);
|
|
4907
5259
|
};
|
|
5260
|
+
const measureRef = React.useRef(() => {});
|
|
4908
5261
|
React.useLayoutEffect(() => {
|
|
4909
5262
|
const root = rootRef.current;
|
|
4910
5263
|
if (!root || narrow) return;
|
|
4911
5264
|
const measure = () => {
|
|
4912
5265
|
const need = {};
|
|
4913
|
-
for (const el of root.querySelectorAll(".ui-dt-body .ui-dt-cell[data-col]:not(.is-long)")) {
|
|
5266
|
+
for (const el of root.querySelectorAll(":scope > .ui-dt-scroller .ui-dt-body .ui-dt-cell[data-col]:not(.is-long):not(.is-hug)")) {
|
|
4914
5267
|
const over = el.scrollWidth - el.clientWidth;
|
|
4915
5268
|
const key = el.dataset.col;
|
|
4916
5269
|
if (over > 1 && key) need[key] = Math.max(need[key] ?? 0, Math.ceil(el.getBoundingClientRect().width + over));
|
|
4917
5270
|
}
|
|
5271
|
+
const hugs = root.querySelectorAll(":scope > .ui-dt-scroller .ui-dt-cell.is-hug[data-col]");
|
|
5272
|
+
if (hugs.length) {
|
|
5273
|
+
root.classList.add("is-measuring");
|
|
5274
|
+
for (const el of hugs) {
|
|
5275
|
+
const key = el.dataset.col;
|
|
5276
|
+
const inner = el.querySelector(":scope > .ui-dt-stack > .ui-dt-main") ?? el;
|
|
5277
|
+
if (key) need[key] = Math.max(need[key] ?? 0, Math.ceil(contentWidth(inner) + CELL_PAD));
|
|
5278
|
+
}
|
|
5279
|
+
root.classList.remove("is-measuring");
|
|
5280
|
+
}
|
|
4918
5281
|
setFit((f) => {
|
|
4919
5282
|
const grow = Object.entries(need).filter(([k, w]) => w > (f[k] ?? 0));
|
|
4920
5283
|
return grow.length ? {
|
|
@@ -4923,26 +5286,38 @@ function DataTable(p) {
|
|
|
4923
5286
|
} : f;
|
|
4924
5287
|
});
|
|
4925
5288
|
};
|
|
4926
|
-
measure();
|
|
4927
5289
|
let frame = 0;
|
|
4928
5290
|
const later = () => {
|
|
4929
|
-
|
|
4930
|
-
frame = requestAnimationFrame(
|
|
5291
|
+
if (frame) return;
|
|
5292
|
+
frame = requestAnimationFrame(() => {
|
|
5293
|
+
frame = 0;
|
|
5294
|
+
measure();
|
|
5295
|
+
});
|
|
4931
5296
|
};
|
|
5297
|
+
measureRef.current = later;
|
|
5298
|
+
measure();
|
|
4932
5299
|
const mo = new MutationObserver(later);
|
|
4933
|
-
mo.observe(
|
|
4934
|
-
childList: true,
|
|
4935
|
-
subtree: true,
|
|
4936
|
-
characterData: true
|
|
4937
|
-
});
|
|
5300
|
+
for (const el of root.querySelectorAll(":scope > .ui-dt-scroller .ui-dt-table, :scope > .ui-dt-scroller .ui-dt-body")) mo.observe(el, { childList: true });
|
|
4938
5301
|
document.fonts?.ready.then(later).catch(() => {});
|
|
4939
5302
|
return () => {
|
|
4940
5303
|
mo.disconnect();
|
|
4941
5304
|
cancelAnimationFrame(frame);
|
|
5305
|
+
measureRef.current = () => {};
|
|
4942
5306
|
};
|
|
4943
5307
|
}, [narrow, resetKey]);
|
|
5308
|
+
const contentKey = `${visIds.join("")}|${shownCols.map((c) => c.key).join(",")}|${list.length}|${q}|${!!p.totals}`;
|
|
5309
|
+
React.useLayoutEffect(() => {
|
|
5310
|
+
measureRef.current();
|
|
5311
|
+
}, [contentKey, rows]);
|
|
4944
5312
|
const stickyStyle = (ci) => ci === 0 && sticky ? { left: (expander ? EXP : 0) + (selectable ? 46 : 0) } : void 0;
|
|
4945
|
-
const cellClass = (c, ci, ...more) => cx("ui-dt-cell", isNum(c) && "is-num", ci === 0 && sticky && "is-sticky", ...more);
|
|
5313
|
+
const cellClass = (c, ci, ...more) => cx("ui-dt-cell", isNum(c) && "is-num", !grows(c) && "is-hug", ci === 0 && sticky && "is-sticky is-sticky-end", ...more);
|
|
5314
|
+
const lead = (what) => sticky ? {
|
|
5315
|
+
className: "is-sticky",
|
|
5316
|
+
style: { left: what === "sel" && expander ? EXP : 0 }
|
|
5317
|
+
} : {
|
|
5318
|
+
className: void 0,
|
|
5319
|
+
style: void 0
|
|
5320
|
+
};
|
|
4946
5321
|
const headOf = (inZoom) => {
|
|
4947
5322
|
const gridStyle = inZoom ? zoomGrid : pageGrid;
|
|
4948
5323
|
const minW = gridStyle.minWidth;
|
|
@@ -4988,12 +5363,14 @@ function DataTable(p) {
|
|
|
4988
5363
|
style: gridStyle,
|
|
4989
5364
|
children: [
|
|
4990
5365
|
expander ? /* @__PURE__ */ jsx("div", {
|
|
4991
|
-
className: "ui-dt-cell ui-dt-exp",
|
|
5366
|
+
className: cx("ui-dt-cell ui-dt-exp", lead("exp").className),
|
|
5367
|
+
style: lead("exp").style,
|
|
4992
5368
|
role: "columnheader",
|
|
4993
5369
|
"aria-label": tr("詳細")
|
|
4994
5370
|
}) : null,
|
|
4995
5371
|
selectable ? /* @__PURE__ */ jsx("div", {
|
|
4996
|
-
className: "ui-dt-cell ui-dt-sel",
|
|
5372
|
+
className: cx("ui-dt-cell ui-dt-sel", lead("sel").className),
|
|
5373
|
+
style: lead("sel").style,
|
|
4997
5374
|
role: "columnheader",
|
|
4998
5375
|
children: /* @__PURE__ */ jsx(RowCheck, {
|
|
4999
5376
|
v: allOn ? true : mixed ? "mixed" : false,
|
|
@@ -5061,11 +5438,31 @@ function DataTable(p) {
|
|
|
5061
5438
|
});
|
|
5062
5439
|
};
|
|
5063
5440
|
const mark = searching ? q : "";
|
|
5441
|
+
const absDate = (r, c) => {
|
|
5442
|
+
if (c.format !== "relative" || c.render) return "";
|
|
5443
|
+
const d = asDate(get(r, c.key));
|
|
5444
|
+
const abs = d ? format.dateTime(d) : "";
|
|
5445
|
+
return abs && abs !== format.relative(d) ? abs : "";
|
|
5446
|
+
};
|
|
5064
5447
|
const cellInner = (r, c) => {
|
|
5065
5448
|
const raw = get(r, c.key);
|
|
5066
5449
|
let v;
|
|
5067
5450
|
if (c.render) v = c.render(r);
|
|
5068
|
-
else if (c
|
|
5451
|
+
else if (isDateCol(c) && asDate(raw)) {
|
|
5452
|
+
const d = asDate(raw);
|
|
5453
|
+
const abs = absDate(r, c);
|
|
5454
|
+
const t = /* @__PURE__ */ jsx("time", {
|
|
5455
|
+
className: "ui-dt-time",
|
|
5456
|
+
dateTime: isoOf(d, c.format === "date"),
|
|
5457
|
+
children: markMatch(cellText(c, raw), mark)
|
|
5458
|
+
});
|
|
5459
|
+
v = abs ? /* @__PURE__ */ jsx(Tooltip, {
|
|
5460
|
+
label: abs,
|
|
5461
|
+
describe: false,
|
|
5462
|
+
disabled: touch,
|
|
5463
|
+
children: t
|
|
5464
|
+
}) : t;
|
|
5465
|
+
} else if (c.unit && raw !== null && raw !== void 0 && raw !== "") v = /* @__PURE__ */ jsxs("span", {
|
|
5069
5466
|
className: "ui-dt-qty",
|
|
5070
5467
|
children: [
|
|
5071
5468
|
markMatch(cellText({
|
|
@@ -5082,25 +5479,82 @@ function DataTable(p) {
|
|
|
5082
5479
|
else v = markMatch(cellText(c, raw), mark);
|
|
5083
5480
|
return v;
|
|
5084
5481
|
};
|
|
5085
|
-
const
|
|
5086
|
-
const
|
|
5087
|
-
|
|
5482
|
+
const rowClick = (e) => {
|
|
5483
|
+
const ctl = e.target.closest(ROW_CONTROLS);
|
|
5484
|
+
if (ctl && ctl !== e.currentTarget) return false;
|
|
5485
|
+
const s = window.getSelection();
|
|
5486
|
+
return !(s && !s.isCollapsed && String(s).trim());
|
|
5487
|
+
};
|
|
5488
|
+
const openRow = (r, e) => {
|
|
5489
|
+
const href = p.rowHref?.(r);
|
|
5490
|
+
if (href == null) return;
|
|
5491
|
+
if (newTab(e)) {
|
|
5492
|
+
e.preventDefault();
|
|
5493
|
+
window.open(href, "_blank", "noopener");
|
|
5494
|
+
} else if (p.onRowOpen) p.onRowOpen(r, e);
|
|
5495
|
+
else e.currentTarget.querySelector("a.ui-dt-rowlink")?.click();
|
|
5496
|
+
};
|
|
5497
|
+
const cell = (r, c, ci) => {
|
|
5498
|
+
let v = c.long ? /* @__PURE__ */ jsx(LongText, { children: cellInner(r, c) }) : cellInner(r, c);
|
|
5499
|
+
if (c.fullText) v = /* @__PURE__ */ jsx(FullText, {
|
|
5088
5500
|
text: c.fullText(r),
|
|
5089
5501
|
children: v
|
|
5090
|
-
})
|
|
5502
|
+
});
|
|
5503
|
+
if (ci === 0 && p.rowHref) v = /* @__PURE__ */ jsx("a", {
|
|
5504
|
+
className: "ui-dt-rowlink",
|
|
5505
|
+
href: p.rowHref(r),
|
|
5506
|
+
onClick: p.onRowOpen ? (e) => {
|
|
5507
|
+
if (newTab(e)) return;
|
|
5508
|
+
e.preventDefault();
|
|
5509
|
+
p.onRowOpen?.(r, e);
|
|
5510
|
+
} : void 0,
|
|
5511
|
+
children: v
|
|
5512
|
+
});
|
|
5513
|
+
const sub = c.secondary?.(r);
|
|
5514
|
+
if (sub == null || sub === "" || sub === false) return v;
|
|
5515
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
5516
|
+
className: "ui-dt-stack",
|
|
5517
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
5518
|
+
className: "ui-dt-main",
|
|
5519
|
+
children: v
|
|
5520
|
+
}), /* @__PURE__ */ jsx("span", {
|
|
5521
|
+
className: "ui-dt-sub",
|
|
5522
|
+
children: sub
|
|
5523
|
+
})]
|
|
5524
|
+
});
|
|
5091
5525
|
};
|
|
5092
5526
|
const total = (c, ci) => {
|
|
5093
5527
|
const how = p.totals?.[c.key];
|
|
5094
5528
|
const rowsAll = list.map((x) => x.r);
|
|
5095
|
-
if (ci === 0 && !how) return
|
|
5529
|
+
if (ci === 0 && !how) return /* @__PURE__ */ jsx("span", {
|
|
5530
|
+
className: "ui-dt-qty",
|
|
5531
|
+
children: monoNums(tr("合計 {n} 筆", { n: "" }), [format.number(rowsAll.length)])
|
|
5532
|
+
});
|
|
5096
5533
|
if (typeof how === "function") return how(rowsAll);
|
|
5097
5534
|
if (how === "sum" || how === "avg") {
|
|
5098
5535
|
const sum = rowsAll.reduce((a, r) => a + (Number(get(r, c.key)) || 0), 0);
|
|
5099
5536
|
const val = how === "sum" ? sum : sum / (rowsAll.length || 1);
|
|
5100
|
-
|
|
5101
|
-
...c
|
|
5102
|
-
|
|
5103
|
-
|
|
5537
|
+
const num = cellText({
|
|
5538
|
+
...how === "avg" && !c.format ? {
|
|
5539
|
+
...c,
|
|
5540
|
+
decimals: 1
|
|
5541
|
+
} : c,
|
|
5542
|
+
unit: void 0
|
|
5543
|
+
}, val);
|
|
5544
|
+
return /* @__PURE__ */ jsxs("span", {
|
|
5545
|
+
className: "ui-dt-qty",
|
|
5546
|
+
children: [
|
|
5547
|
+
how === "avg" ? /* @__PURE__ */ jsxs("span", {
|
|
5548
|
+
className: "ui-unit",
|
|
5549
|
+
children: [tr("平均"), " "]
|
|
5550
|
+
}) : null,
|
|
5551
|
+
num,
|
|
5552
|
+
c.unit ? /* @__PURE__ */ jsxs(Fragment, { children: [" ", /* @__PURE__ */ jsx("span", {
|
|
5553
|
+
className: "ui-unit",
|
|
5554
|
+
children: c.unit
|
|
5555
|
+
})] }) : null
|
|
5556
|
+
]
|
|
5557
|
+
});
|
|
5104
5558
|
}
|
|
5105
5559
|
return "";
|
|
5106
5560
|
};
|
|
@@ -5109,6 +5563,67 @@ function DataTable(p) {
|
|
|
5109
5563
|
if (p.copyText) return p.copyText(all);
|
|
5110
5564
|
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)) ?? ""))));
|
|
5111
5565
|
};
|
|
5566
|
+
const [copied, setCopied] = React.useState(false);
|
|
5567
|
+
const copiedTimer = React.useRef(void 0);
|
|
5568
|
+
React.useEffect(() => () => clearTimeout(copiedTimer.current), []);
|
|
5569
|
+
const doCopy = () => copyText(copyMarkdown()).then(() => {
|
|
5570
|
+
setCopied(true);
|
|
5571
|
+
announce(tr("已複製"));
|
|
5572
|
+
clearTimeout(copiedTimer.current);
|
|
5573
|
+
copiedTimer.current = setTimeout(() => setCopied(false), 2e3);
|
|
5574
|
+
}, () => p.onCopyError?.());
|
|
5575
|
+
const slash = search !== false && p.searchShortcut !== false;
|
|
5576
|
+
const [slashOwner, setSlashOwner] = React.useState(false);
|
|
5577
|
+
React.useEffect(() => {
|
|
5578
|
+
const el = rootRef.current;
|
|
5579
|
+
if (!slash || !el) return;
|
|
5580
|
+
const changed = () => setSlashOwner(firstShortcutTable() === el);
|
|
5581
|
+
const off = registerShortcut(el, changed);
|
|
5582
|
+
return () => {
|
|
5583
|
+
off();
|
|
5584
|
+
setSlashOwner(false);
|
|
5585
|
+
};
|
|
5586
|
+
}, [slash]);
|
|
5587
|
+
const [searchFocus, setSearchFocus] = React.useState(false);
|
|
5588
|
+
const setFilter = (key, v) => {
|
|
5589
|
+
setValues(v === void 0 ? Object.fromEntries(Object.entries(values).filter(([k]) => k !== key)) : {
|
|
5590
|
+
...values,
|
|
5591
|
+
[key]: v
|
|
5592
|
+
});
|
|
5593
|
+
setPage(0);
|
|
5594
|
+
};
|
|
5595
|
+
const chips = [];
|
|
5596
|
+
for (const f of filters) {
|
|
5597
|
+
const v = values[f.key];
|
|
5598
|
+
if (!v || !isActive(v)) continue;
|
|
5599
|
+
if (Array.isArray(v)) for (const val of v) chips.push({
|
|
5600
|
+
id: f.key + "=" + val,
|
|
5601
|
+
text: tr("{name}:{value}", {
|
|
5602
|
+
name: f.label,
|
|
5603
|
+
value: f.options.find((o) => String(o.value) === val)?.label ?? val
|
|
5604
|
+
}),
|
|
5605
|
+
remove: () => setFilter(f.key, v.filter((x) => x !== val))
|
|
5606
|
+
});
|
|
5607
|
+
else {
|
|
5608
|
+
const range = v.min && v.max ? `${v.min}–${v.max}` : v.min ? `≥ ${v.min}` : `≤ ${v.max}`;
|
|
5609
|
+
chips.push({
|
|
5610
|
+
id: f.key,
|
|
5611
|
+
text: tr("{name}:{value}", {
|
|
5612
|
+
name: f.label,
|
|
5613
|
+
value: range
|
|
5614
|
+
}),
|
|
5615
|
+
remove: () => setFilter(f.key, void 0)
|
|
5616
|
+
});
|
|
5617
|
+
}
|
|
5618
|
+
}
|
|
5619
|
+
const chipsView = (inZoom) => /* @__PURE__ */ jsx(FilterChips, {
|
|
5620
|
+
chips,
|
|
5621
|
+
onClear: () => {
|
|
5622
|
+
setValues({});
|
|
5623
|
+
setPage(0);
|
|
5624
|
+
},
|
|
5625
|
+
filterButton: () => (inZoom ? zoomRef : rootRef).current?.querySelector(".ui-dt-filterbtn") ?? null
|
|
5626
|
+
});
|
|
5112
5627
|
const toolsView = (inZoom, inHead = false) => /* @__PURE__ */ jsxs("div", {
|
|
5113
5628
|
className: cx("ui-dt-tools", inHead && "is-inhead"),
|
|
5114
5629
|
children: [
|
|
@@ -5116,15 +5631,25 @@ function DataTable(p) {
|
|
|
5116
5631
|
className: "ui-dt-caption",
|
|
5117
5632
|
children: p.caption
|
|
5118
5633
|
}) : null,
|
|
5119
|
-
search !== false ? /* @__PURE__ */
|
|
5120
|
-
|
|
5121
|
-
|
|
5122
|
-
|
|
5123
|
-
|
|
5124
|
-
|
|
5125
|
-
|
|
5126
|
-
|
|
5127
|
-
|
|
5634
|
+
search !== false ? /* @__PURE__ */ jsxs("div", {
|
|
5635
|
+
className: "ui-dt-search",
|
|
5636
|
+
onFocus: () => setSearchFocus(true),
|
|
5637
|
+
onBlur: () => setSearchFocus(false),
|
|
5638
|
+
children: [/* @__PURE__ */ jsx(SearchField, {
|
|
5639
|
+
value: q,
|
|
5640
|
+
onChange: (v) => {
|
|
5641
|
+
setQ(v);
|
|
5642
|
+
setPage(0);
|
|
5643
|
+
},
|
|
5644
|
+
placeholder: search.placeholder || tr("搜尋"),
|
|
5645
|
+
label: search.placeholder || tr("搜尋"),
|
|
5646
|
+
"aria-keyshortcuts": slashOwner && !inZoom ? "/" : void 0,
|
|
5647
|
+
className: "ui-dt-searchfield"
|
|
5648
|
+
}), slashOwner && !inZoom && !narrow && !q && !searchFocus ? /* @__PURE__ */ jsx("kbd", {
|
|
5649
|
+
className: "ui-dt-kbd",
|
|
5650
|
+
"aria-hidden": "true",
|
|
5651
|
+
children: "/"
|
|
5652
|
+
}) : null]
|
|
5128
5653
|
}) : null,
|
|
5129
5654
|
/* @__PURE__ */ jsxs("div", {
|
|
5130
5655
|
className: "ui-dt-actions",
|
|
@@ -5135,13 +5660,7 @@ function DataTable(p) {
|
|
|
5135
5660
|
values,
|
|
5136
5661
|
activeCount: activeN,
|
|
5137
5662
|
count: (f, v) => all.filter((x) => passes(x.r, f.key) && matches(f, x.r, f.type === "list" ? [v] : void 0)).length,
|
|
5138
|
-
onChange: (key, v) =>
|
|
5139
|
-
setValues({
|
|
5140
|
-
...values,
|
|
5141
|
-
[key]: v
|
|
5142
|
-
});
|
|
5143
|
-
setPage(0);
|
|
5144
|
-
},
|
|
5663
|
+
onChange: (key, v) => setFilter(key, v),
|
|
5145
5664
|
onClear: () => {
|
|
5146
5665
|
setValues({});
|
|
5147
5666
|
setPage(0);
|
|
@@ -5160,10 +5679,6 @@ function DataTable(p) {
|
|
|
5160
5679
|
children: format.fractionLabel(list.length, baseCount, tr("筆"))
|
|
5161
5680
|
})]
|
|
5162
5681
|
}),
|
|
5163
|
-
p.copy !== false && !narrow ? /* @__PURE__ */ jsx(CopyMarkdownButton, {
|
|
5164
|
-
text: copyMarkdown,
|
|
5165
|
-
onCopyError: p.onCopyError
|
|
5166
|
-
}) : null,
|
|
5167
5682
|
sortCols.length ? /* @__PURE__ */ jsx(SortButton, {
|
|
5168
5683
|
cols: sortCols,
|
|
5169
5684
|
levels: sort,
|
|
@@ -5171,17 +5686,31 @@ function DataTable(p) {
|
|
|
5171
5686
|
onChange: changeSort,
|
|
5172
5687
|
boundary: inZoom ? zoomRef : rootRef
|
|
5173
5688
|
}) : null,
|
|
5174
|
-
|
|
5175
|
-
cols
|
|
5176
|
-
|
|
5177
|
-
|
|
5178
|
-
|
|
5179
|
-
|
|
5180
|
-
|
|
5181
|
-
|
|
5182
|
-
|
|
5183
|
-
|
|
5184
|
-
|
|
5689
|
+
narrow ? null : /* @__PURE__ */ jsx(MoreMenu, {
|
|
5690
|
+
columns: p.columnMenu !== false && cols.length > 2 ? {
|
|
5691
|
+
cols,
|
|
5692
|
+
hidden,
|
|
5693
|
+
onToggle: (k) => setToggled({
|
|
5694
|
+
...toggled,
|
|
5695
|
+
[k]: !hidden[k]
|
|
5696
|
+
}),
|
|
5697
|
+
onReset: () => {
|
|
5698
|
+
setToggled({});
|
|
5699
|
+
setWidths(null);
|
|
5700
|
+
setZoomWidths(null);
|
|
5701
|
+
announce(tr("已還原預設的欄位與欄寬"));
|
|
5702
|
+
}
|
|
5703
|
+
} : void 0,
|
|
5704
|
+
onCopy: p.copy !== false ? doCopy : void 0,
|
|
5705
|
+
onZoom: p.zoom !== false && !inZoom ? () => setZoomed(true) : void 0
|
|
5706
|
+
}),
|
|
5707
|
+
copied && !narrow ? /* @__PURE__ */ jsxs("span", {
|
|
5708
|
+
className: "ui-dt-copied",
|
|
5709
|
+
"aria-hidden": "true",
|
|
5710
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
5711
|
+
name: "check",
|
|
5712
|
+
size: 16
|
|
5713
|
+
}), tr("已複製")]
|
|
5185
5714
|
}) : null
|
|
5186
5715
|
]
|
|
5187
5716
|
})
|
|
@@ -5219,20 +5748,26 @@ function DataTable(p) {
|
|
|
5219
5748
|
},
|
|
5220
5749
|
role: "row",
|
|
5221
5750
|
"aria-labelledby": shownCols.length ? `${pfx}-n-${start + i}` : void 0,
|
|
5222
|
-
className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && "has-exp"),
|
|
5751
|
+
className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel", expander && !p.rowHref && "has-exp", p.rowHref && "has-href"),
|
|
5223
5752
|
style: grid,
|
|
5224
|
-
onClick: expander ? (e) => {
|
|
5225
|
-
|
|
5226
|
-
if (
|
|
5227
|
-
if (String(window.getSelection() ?? "")) return;
|
|
5753
|
+
onClick: expander || p.rowHref ? (e) => {
|
|
5754
|
+
if (!rowClick(e)) return;
|
|
5755
|
+
if (p.rowHref) return openRow(x.r, e);
|
|
5228
5756
|
setOpened({
|
|
5229
5757
|
...opened,
|
|
5230
5758
|
[id]: !open
|
|
5231
5759
|
});
|
|
5232
5760
|
} : void 0,
|
|
5761
|
+
onMouseDown: p.rowHref ? (e) => {
|
|
5762
|
+
if ((e.shiftKey || e.button === 1) && !e.target.closest(ROW_CONTROLS)) e.preventDefault();
|
|
5763
|
+
} : void 0,
|
|
5764
|
+
onAuxClick: p.rowHref ? (e) => {
|
|
5765
|
+
if (e.button === 1 && rowClick(e)) openRow(x.r, e);
|
|
5766
|
+
} : void 0,
|
|
5233
5767
|
children: [
|
|
5234
5768
|
expander ? /* @__PURE__ */ jsx("div", {
|
|
5235
|
-
className: "ui-dt-cell ui-dt-exp",
|
|
5769
|
+
className: cx("ui-dt-cell ui-dt-exp", lead("exp").className),
|
|
5770
|
+
style: lead("exp").style,
|
|
5236
5771
|
role: "cell",
|
|
5237
5772
|
children: /* @__PURE__ */ jsx("button", {
|
|
5238
5773
|
type: "button",
|
|
@@ -5251,23 +5786,24 @@ function DataTable(p) {
|
|
|
5251
5786
|
})
|
|
5252
5787
|
}) : null,
|
|
5253
5788
|
selectable ? /* @__PURE__ */ jsx("div", {
|
|
5254
|
-
className: "ui-dt-cell ui-dt-sel",
|
|
5789
|
+
className: cx("ui-dt-cell ui-dt-sel", lead("sel").className),
|
|
5790
|
+
style: lead("sel").style,
|
|
5255
5791
|
role: "cell",
|
|
5256
5792
|
children: /* @__PURE__ */ jsx(RowCheck, {
|
|
5257
5793
|
v: on,
|
|
5258
5794
|
label: tr("選取第 {n} 筆", { n: start + i + 1 }),
|
|
5259
|
-
onClick: () =>
|
|
5795
|
+
onClick: (e) => pickRow(id, on, e.shiftKey)
|
|
5260
5796
|
})
|
|
5261
5797
|
}) : null,
|
|
5262
5798
|
shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
|
|
5263
5799
|
role: "cell",
|
|
5264
5800
|
id: ci === 0 ? `${pfx}-n-${start + i}` : void 0,
|
|
5265
|
-
"aria-description": c.fullText
|
|
5801
|
+
"aria-description": [c.fullText?.(x.r), absDate(x.r, c)].filter(Boolean).join(",") || void 0,
|
|
5266
5802
|
"data-label": c.label,
|
|
5267
5803
|
"data-col": c.key,
|
|
5268
5804
|
className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
|
|
5269
5805
|
style: stickyStyle(ci),
|
|
5270
|
-
children: cell(x.r, c)
|
|
5806
|
+
children: cell(x.r, c, ci)
|
|
5271
5807
|
}, c.key)),
|
|
5272
5808
|
hasAct ? /* @__PURE__ */ jsx("div", {
|
|
5273
5809
|
className: "ui-dt-cell ui-dt-acts",
|
|
@@ -5310,17 +5846,21 @@ function DataTable(p) {
|
|
|
5310
5846
|
style: grid,
|
|
5311
5847
|
children: [
|
|
5312
5848
|
expander ? /* @__PURE__ */ jsx("div", {
|
|
5313
|
-
className: "ui-dt-cell",
|
|
5849
|
+
className: cx("ui-dt-cell", lead("exp").className),
|
|
5850
|
+
style: lead("exp").style,
|
|
5314
5851
|
role: "cell"
|
|
5315
5852
|
}) : null,
|
|
5316
5853
|
selectable ? /* @__PURE__ */ jsx("div", {
|
|
5317
|
-
className: "ui-dt-cell",
|
|
5854
|
+
className: cx("ui-dt-cell", lead("sel").className),
|
|
5855
|
+
style: lead("sel").style,
|
|
5318
5856
|
role: "cell"
|
|
5319
5857
|
}) : null,
|
|
5320
5858
|
shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
|
|
5321
5859
|
role: "cell",
|
|
5322
5860
|
className: cellClass(c, ci),
|
|
5323
5861
|
style: stickyStyle(ci),
|
|
5862
|
+
"data-col": c.key,
|
|
5863
|
+
"data-label": ci > 0 && p.totals?.[c.key] ? c.label : void 0,
|
|
5324
5864
|
children: total(c, ci)
|
|
5325
5865
|
}, c.key)),
|
|
5326
5866
|
hasAct ? /* @__PURE__ */ jsx("div", {
|
|
@@ -5436,6 +5976,7 @@ function DataTable(p) {
|
|
|
5436
5976
|
}))]
|
|
5437
5977
|
}) : null,
|
|
5438
5978
|
headSlot ? createPortal(toolsView(false, true), headSlot) : toolsView(false),
|
|
5979
|
+
chipsView(false),
|
|
5439
5980
|
tableView(false),
|
|
5440
5981
|
/* @__PURE__ */ jsx(ScrollHint, {
|
|
5441
5982
|
show: overflows,
|
|
@@ -5451,6 +5992,7 @@ function DataTable(p) {
|
|
|
5451
5992
|
className: "ui-dt ui-dt-zoomed",
|
|
5452
5993
|
children: [
|
|
5453
5994
|
toolsView(true),
|
|
5995
|
+
chipsView(true),
|
|
5454
5996
|
tableView(true),
|
|
5455
5997
|
footView
|
|
5456
5998
|
]
|
|
@@ -5461,14 +6003,15 @@ function DataTable(p) {
|
|
|
5461
6003
|
}
|
|
5462
6004
|
// src/components/DatePicker/DatePicker.tsx
|
|
5463
6005
|
/** A date field: type YYYY/MM/DD, or pick from the calendar button's month grid. */
|
|
5464
|
-
function DatePicker({ label, value, onChange, hint, required, className }) {
|
|
6006
|
+
function DatePicker({ label, value, onChange, hint, required, error, className }) {
|
|
5465
6007
|
const id = React.useId();
|
|
5466
6008
|
const [open, setOpen] = React.useState(false);
|
|
5467
6009
|
const [typed, setTyped] = React.useState(null);
|
|
5468
6010
|
const field = React.useRef(null);
|
|
5469
6011
|
const wrong = typed !== null && typed !== "" && !parseDate(typed);
|
|
5470
6012
|
const [left, setLeft] = React.useState(false);
|
|
5471
|
-
const
|
|
6013
|
+
const errText = wrong && left ? tr("日期格式不正確,請寫成 2026/11/14") : error;
|
|
6014
|
+
const msgId = id + "-msg";
|
|
5472
6015
|
const commit = (d) => {
|
|
5473
6016
|
setTyped(null);
|
|
5474
6017
|
setLeft(false);
|
|
@@ -5476,7 +6019,7 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
|
|
|
5476
6019
|
setOpen(false);
|
|
5477
6020
|
};
|
|
5478
6021
|
return /* @__PURE__ */ jsxs("div", {
|
|
5479
|
-
className: cx("ui-field", className),
|
|
6022
|
+
className: cx("ui-field", errText && "has-error", className),
|
|
5480
6023
|
children: [
|
|
5481
6024
|
label ? /* @__PURE__ */ jsx(FieldLabel, {
|
|
5482
6025
|
htmlFor: id,
|
|
@@ -5485,60 +6028,66 @@ function DatePicker({ label, value, onChange, hint, required, className }) {
|
|
|
5485
6028
|
}) : null,
|
|
5486
6029
|
/* @__PURE__ */ jsxs("div", {
|
|
5487
6030
|
ref: field,
|
|
5488
|
-
className: cx("ui-datefield",
|
|
5489
|
-
children: [
|
|
5490
|
-
|
|
5491
|
-
|
|
5492
|
-
|
|
5493
|
-
|
|
5494
|
-
|
|
5495
|
-
|
|
5496
|
-
|
|
5497
|
-
|
|
5498
|
-
|
|
5499
|
-
|
|
5500
|
-
|
|
5501
|
-
|
|
5502
|
-
|
|
5503
|
-
|
|
5504
|
-
|
|
5505
|
-
|
|
5506
|
-
onOpenChange: setOpen,
|
|
5507
|
-
anchor: field,
|
|
5508
|
-
className: "ui-datepop",
|
|
5509
|
-
"aria-label": tr("選擇日期"),
|
|
5510
|
-
trigger: /* @__PURE__ */ jsx("button", {
|
|
5511
|
-
type: "button",
|
|
5512
|
-
className: "ui-datefield-btn",
|
|
5513
|
-
"aria-label": tr("開啟日曆"),
|
|
5514
|
-
children: /* @__PURE__ */ jsx(Icon, {
|
|
5515
|
-
name: "calendar-blank",
|
|
5516
|
-
size: 18
|
|
5517
|
-
})
|
|
6031
|
+
className: cx("ui-datefield", errText && "is-invalid"),
|
|
6032
|
+
children: [
|
|
6033
|
+
/* @__PURE__ */ jsx("input", {
|
|
6034
|
+
id,
|
|
6035
|
+
className: "ui-datefield-input",
|
|
6036
|
+
value: typed ?? fmtDate(value),
|
|
6037
|
+
placeholder: "YYYY/MM/DD",
|
|
6038
|
+
"aria-required": required || void 0,
|
|
6039
|
+
"aria-invalid": errText ? true : void 0,
|
|
6040
|
+
"aria-describedby": msgId,
|
|
6041
|
+
onChange: (e) => {
|
|
6042
|
+
const t = e.target.value;
|
|
6043
|
+
setTyped(t);
|
|
6044
|
+
const d = parseDate(t);
|
|
6045
|
+
if (d) onChange(d);
|
|
6046
|
+
else if (t === "") onChange(null);
|
|
6047
|
+
},
|
|
6048
|
+
onBlur: () => wrong ? setLeft(true) : setTyped(null)
|
|
5518
6049
|
}),
|
|
5519
|
-
|
|
5520
|
-
|
|
5521
|
-
|
|
5522
|
-
|
|
5523
|
-
|
|
5524
|
-
className: "ui-datepop
|
|
5525
|
-
|
|
5526
|
-
|
|
5527
|
-
className: "ui-link-btn",
|
|
5528
|
-
onClick: () => commit(new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0))),
|
|
5529
|
-
children: tr("今天")
|
|
5530
|
-
}), /* @__PURE__ */ jsx("button", {
|
|
6050
|
+
errText ? /* @__PURE__ */ jsx(FieldErrorIcon, { inline: true }) : null,
|
|
6051
|
+
/* @__PURE__ */ jsxs(FloatingPanel, {
|
|
6052
|
+
open,
|
|
6053
|
+
onOpenChange: setOpen,
|
|
6054
|
+
anchor: field,
|
|
6055
|
+
className: "ui-datepop",
|
|
6056
|
+
"aria-label": tr("選擇日期"),
|
|
6057
|
+
trigger: /* @__PURE__ */ jsx("button", {
|
|
5531
6058
|
type: "button",
|
|
5532
|
-
className: "ui-
|
|
5533
|
-
|
|
5534
|
-
children:
|
|
6059
|
+
className: "ui-datefield-btn",
|
|
6060
|
+
"aria-label": tr("開啟日曆"),
|
|
6061
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
6062
|
+
name: "calendar-blank",
|
|
6063
|
+
size: 18
|
|
6064
|
+
})
|
|
6065
|
+
}),
|
|
6066
|
+
children: [/* @__PURE__ */ jsx(Calendar, {
|
|
6067
|
+
focus: value,
|
|
6068
|
+
dayState: (d) => ({ selected: sameDay(d, value) }),
|
|
6069
|
+
onPick: commit
|
|
6070
|
+
}), /* @__PURE__ */ jsxs("div", {
|
|
6071
|
+
className: "ui-datepop-foot",
|
|
6072
|
+
children: [/* @__PURE__ */ jsx("button", {
|
|
6073
|
+
type: "button",
|
|
6074
|
+
className: "ui-link-btn",
|
|
6075
|
+
onClick: () => commit(new Date((/* @__PURE__ */ new Date()).setHours(0, 0, 0, 0))),
|
|
6076
|
+
children: tr("今天")
|
|
6077
|
+
}), /* @__PURE__ */ jsx("button", {
|
|
6078
|
+
type: "button",
|
|
6079
|
+
className: "ui-link-btn is-muted",
|
|
6080
|
+
onClick: () => commit(null),
|
|
6081
|
+
children: tr("清除")
|
|
6082
|
+
})]
|
|
5535
6083
|
})]
|
|
5536
|
-
})
|
|
5537
|
-
|
|
6084
|
+
})
|
|
6085
|
+
]
|
|
5538
6086
|
}),
|
|
5539
|
-
/* @__PURE__ */ jsx(
|
|
5540
|
-
|
|
5541
|
-
|
|
6087
|
+
/* @__PURE__ */ jsx(FieldMessage, {
|
|
6088
|
+
id: msgId,
|
|
6089
|
+
error: errText,
|
|
6090
|
+
hint: hint || tr("可以直接輸入,例如 2026/11/14")
|
|
5542
6091
|
})
|
|
5543
6092
|
]
|
|
5544
6093
|
});
|
|
@@ -5779,6 +6328,7 @@ function EmptyState({ title, description, steps = [], current = 0, action }) {
|
|
|
5779
6328
|
className: "ui-steps",
|
|
5780
6329
|
children: steps.map((s, i) => /* @__PURE__ */ jsxs("li", {
|
|
5781
6330
|
className: i === current ? "is-current" : void 0,
|
|
6331
|
+
"aria-current": i === current ? "step" : void 0,
|
|
5782
6332
|
children: [/* @__PURE__ */ jsx("span", {
|
|
5783
6333
|
className: "ui-step-num",
|
|
5784
6334
|
children: i + 1
|
|
@@ -6557,6 +7107,7 @@ const FENCE_LANG = {
|
|
|
6557
7107
|
"c++": "c"
|
|
6558
7108
|
};
|
|
6559
7109
|
const fenceLang = (l) => FENCE_LANG[l] ?? (languageOf("x." + l) !== "plain" ? languageOf("x." + l) : l || "plain");
|
|
7110
|
+
const NUM_UNIT = /^([-+]?(?:NT\$\s?)?[\d,]+(?:\.\d+)?)(\s?)(%|[A-Za-z]{1,3}|\p{Script=Han}{1,2})$/u;
|
|
6560
7111
|
const NUM = /^[-+]?(?:NT\$\s?)?[\d,]+(?:\.\d+)?\s?(?:%|[A-Za-z]{1,3}|\p{Script=Han}{1,2})?$/u;
|
|
6561
7112
|
/** Markdown from project documents and code comments, in the system's own type, code and table styles. Never runs HTML:
|
|
6562
7113
|
* tags are dropped and their text kept; links only to http, https, mailto and relative addresses. */
|
|
@@ -6633,7 +7184,17 @@ function Markdown(p) {
|
|
|
6633
7184
|
label: b.head.map(plain).join("、"),
|
|
6634
7185
|
heads: b.head.map((h) => inline(h, noTerms(c))),
|
|
6635
7186
|
headText: b.head.map(plain),
|
|
6636
|
-
rows: b.rows.map((r) => Array.from({ length: n }, (_, j) =>
|
|
7187
|
+
rows: b.rows.map((r) => Array.from({ length: n }, (_, j) => {
|
|
7188
|
+
const u = numeric[j] ? NUM_UNIT.exec(r[j] ?? "") : null;
|
|
7189
|
+
return u ? /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
7190
|
+
inline(u[1], block(c)),
|
|
7191
|
+
u[2],
|
|
7192
|
+
/* @__PURE__ */ jsx("span", {
|
|
7193
|
+
className: "ui-unit",
|
|
7194
|
+
children: u[3]
|
|
7195
|
+
})
|
|
7196
|
+
] }) : inline(r[j] ?? "", block(c));
|
|
7197
|
+
})),
|
|
6637
7198
|
numeric,
|
|
6638
7199
|
align
|
|
6639
7200
|
}, c.k());
|
|
@@ -6980,6 +7541,13 @@ function SectionGroupToggle({ className }) {
|
|
|
6980
7541
|
});
|
|
6981
7542
|
}
|
|
6982
7543
|
// src/components/KpiCard/KpiCard.tsx
|
|
7544
|
+
/** Chinese in a figure (the 萬 and 億 of an abbreviated number) in the text font; Geist Mono stays on the digits. */
|
|
7545
|
+
function sansCjk(text) {
|
|
7546
|
+
return text.split(/([\u2e80-\u9fff\uff00-\uffef]+)/).map((t, i) => i % 2 ? /* @__PURE__ */ jsx("span", {
|
|
7547
|
+
className: "ui-kpi-cjk",
|
|
7548
|
+
children: t
|
|
7549
|
+
}, i) : t);
|
|
7550
|
+
}
|
|
6983
7551
|
/** One figure with its change and a sparkline. It is a card: put several in a grid, not inside another Card. */
|
|
6984
7552
|
function KpiCard(props) {
|
|
6985
7553
|
const { label, value, unit, decimals = 0, delta, deltaUnit, good, spark, compareLabel, size = "default", verdict, target, className } = props;
|
|
@@ -7024,10 +7592,10 @@ function KpiCard(props) {
|
|
|
7024
7592
|
"aria-hidden": "true",
|
|
7025
7593
|
children: [/* @__PURE__ */ jsx("span", {
|
|
7026
7594
|
className: "ui-kpi-sizer",
|
|
7027
|
-
children: kpiText(value, props, decimals)
|
|
7595
|
+
children: sansCjk(kpiText(value, props, decimals))
|
|
7028
7596
|
}), /* @__PURE__ */ jsx("span", {
|
|
7029
7597
|
className: "ui-kpi-live",
|
|
7030
|
-
children: kpiText(value * t, props, decimals)
|
|
7598
|
+
children: sansCjk(kpiText(value * t, props, decimals))
|
|
7031
7599
|
})]
|
|
7032
7600
|
}), showUnit ? /* @__PURE__ */ jsx("span", {
|
|
7033
7601
|
className: "ui-kpi-unit",
|
|
@@ -7108,7 +7676,7 @@ function Switch({ checked, onChange, label, disabled, className }) {
|
|
|
7108
7676
|
right,
|
|
7109
7677
|
height: th,
|
|
7110
7678
|
marginTop: -th / 2,
|
|
7111
|
-
transition: `${dropTransition("left", "right", on)}, height
|
|
7679
|
+
transition: `${dropTransition("left", "right", on)}, height var(--dur-hover) ease, margin-top var(--dur-hover) ease, background-color var(--dur-nav) ease`
|
|
7112
7680
|
},
|
|
7113
7681
|
children: /* @__PURE__ */ jsx("svg", {
|
|
7114
7682
|
width: 12,
|
|
@@ -7143,6 +7711,14 @@ function byCount(n, one, many) {
|
|
|
7143
7711
|
const t = n === 1 ? tr(one) : "";
|
|
7144
7712
|
return t && t !== one ? t : tr(many);
|
|
7145
7713
|
}
|
|
7714
|
+
/** A box reached with the keyboard while partly scrolled out of the diagram's frame (phones): scroll it fully into view,
|
|
7715
|
+
* with its focus outline (scroll-margin in styles.css). The browser scrolls only boxes that are wholly out of view. */
|
|
7716
|
+
function showWhole(e) {
|
|
7717
|
+
if (e.currentTarget.matches(":focus-visible")) e.currentTarget.scrollIntoView({
|
|
7718
|
+
block: "nearest",
|
|
7719
|
+
inline: "nearest"
|
|
7720
|
+
});
|
|
7721
|
+
}
|
|
7146
7722
|
/** The width of text in a font (`600 13px` and mono or sans), measured on a canvas. */
|
|
7147
7723
|
function textWidth(text, size, code) {
|
|
7148
7724
|
if (measure === void 0) measure = document.createElement("canvas").getContext("2d");
|
|
@@ -7352,7 +7928,7 @@ function LayerGraph(p) {
|
|
|
7352
7928
|
if (!n.tag) return false;
|
|
7353
7929
|
const name = n.name || n.id;
|
|
7354
7930
|
const tagW = textWidth(n.tag, 12, false) + 12 + (n.tagTone === "warning" ? 15 : 0);
|
|
7355
|
-
return NW - (n.external ? 24 : 28) - 6 - tagW < textWidth(name.slice(0, TAG_KEEP), 13,
|
|
7931
|
+
return NW - (n.external ? 24 : 28) - 6 - tagW < textWidth(name.slice(0, TAG_KEEP), 13, !!n.code) + (name.length > TAG_KEEP ? 1 : 0);
|
|
7356
7932
|
});
|
|
7357
7933
|
const NH = tagLine ? 76 : 60;
|
|
7358
7934
|
const shared = all.filter((n) => n.shared);
|
|
@@ -8364,6 +8940,7 @@ function LayerGraph(p) {
|
|
|
8364
8940
|
return /* @__PURE__ */ jsxs("button", {
|
|
8365
8941
|
type: "button",
|
|
8366
8942
|
className: cx("ui-lg-node", n.external && "is-external", on && "is-selected", !near(n.id) && "is-dim"),
|
|
8943
|
+
onFocus: showWhole,
|
|
8367
8944
|
style: {
|
|
8368
8945
|
left: boxOf(n.id).x,
|
|
8369
8946
|
top: q.y,
|
|
@@ -8377,7 +8954,7 @@ function LayerGraph(p) {
|
|
|
8377
8954
|
className: "ui-lg-head",
|
|
8378
8955
|
children: [
|
|
8379
8956
|
/* @__PURE__ */ jsx("span", {
|
|
8380
|
-
className: "ui-lg-name",
|
|
8957
|
+
className: cx("ui-lg-name", n.code && "is-code"),
|
|
8381
8958
|
children: n.name || n.id
|
|
8382
8959
|
}),
|
|
8383
8960
|
tagLine ? null : tagOf(n),
|
|
@@ -8415,12 +8992,13 @@ function LayerGraph(p) {
|
|
|
8415
8992
|
return /* @__PURE__ */ jsxs("button", {
|
|
8416
8993
|
type: "button",
|
|
8417
8994
|
className: cx("ui-lg-node", "ui-lg-chip", on && "is-selected", dim && "is-dim"),
|
|
8995
|
+
onFocus: showWhole,
|
|
8418
8996
|
"aria-pressed": p.onSelect ? on : void 0,
|
|
8419
8997
|
onClick: p.onSelect ? () => pick(s.id, on) : void 0,
|
|
8420
8998
|
children: [/* @__PURE__ */ jsxs("span", {
|
|
8421
8999
|
className: "ui-lg-head",
|
|
8422
9000
|
children: [/* @__PURE__ */ jsx("span", {
|
|
8423
|
-
className: "ui-lg-name",
|
|
9001
|
+
className: cx("ui-lg-name", s.code && "is-code"),
|
|
8424
9002
|
children: s.name || s.id
|
|
8425
9003
|
}), tagOf(s)]
|
|
8426
9004
|
}), /* @__PURE__ */ jsx("span", {
|
|
@@ -8458,7 +9036,7 @@ function LayerGraph(p) {
|
|
|
8458
9036
|
}), /* @__PURE__ */ jsx("ul", { children: all.map((n) => {
|
|
8459
9037
|
const size = sizeOf(n);
|
|
8460
9038
|
return listItem(n.id, n.id === sel, !near(n.id), p.onSelect ? () => pick(n.id, n.id === sel) : void 0, /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", {
|
|
8461
|
-
className: "ui-lg-code",
|
|
9039
|
+
className: cx("ui-lg-liname", n.code && "ui-lg-code"),
|
|
8462
9040
|
children: n.name || n.id
|
|
8463
9041
|
}), tagOf(n)] }), n.external && !n.shared ? /* @__PURE__ */ jsxs("span", {
|
|
8464
9042
|
className: "ui-lg-limeta",
|
|
@@ -9219,14 +9797,14 @@ function Meter({ label, value, min, max, warn, limit, unit, decimals = 0, classN
|
|
|
9219
9797
|
* and one detail line. Zones are buttons: Tab moves between them, Enter or Space selects. The selected zone has an
|
|
9220
9798
|
* ink outline outside it; a zone needing attention has a 4 px warning or danger border and 「⚠」 in its state. */
|
|
9221
9799
|
const DATA_TOKEN = /^(heat-[1-7]|diverge-(neg|pos)(-strong)?|diverge-zero|chart-[1-4])$/;
|
|
9222
|
-
function ZoneMap({ zones, label, columns = 4, rowHeight = 120, min = 20, max = 30, selectedId, onSelect, className }) {
|
|
9800
|
+
function ZoneMap({ zones, label, columns = 4, rowHeight = 120, fill = false, min = 20, max = 30, selectedId, onSelect, className }) {
|
|
9223
9801
|
return /* @__PURE__ */ jsx("div", {
|
|
9224
|
-
className: cx("ui-zonemap", className),
|
|
9802
|
+
className: cx("ui-zonemap", fill && "is-fill", className),
|
|
9225
9803
|
role: "group",
|
|
9226
9804
|
"aria-label": label,
|
|
9227
9805
|
style: {
|
|
9228
9806
|
"--zone-cols": columns,
|
|
9229
|
-
gridAutoRows: rowHeight + "px"
|
|
9807
|
+
gridAutoRows: fill ? `minmax(${rowHeight}px, 1fr)` : rowHeight + "px"
|
|
9230
9808
|
},
|
|
9231
9809
|
children: zones.map((z) => {
|
|
9232
9810
|
const place = z.area ? {
|
|
@@ -9512,7 +10090,7 @@ function LoadingBar({ label, className }) {
|
|
|
9512
10090
|
function TextField({ label, hint, error, id, className, required, disabled, ...native }) {
|
|
9513
10091
|
const auto = React.useId();
|
|
9514
10092
|
const fieldId = id || auto;
|
|
9515
|
-
const desc = error
|
|
10093
|
+
const desc = error ? fieldId + "-err" : hint ? fieldId + "-hint" : void 0;
|
|
9516
10094
|
return /* @__PURE__ */ jsxs("div", {
|
|
9517
10095
|
className: cx("ui-field", error && "has-error", disabled && "is-disabled", className),
|
|
9518
10096
|
children: [
|
|
@@ -9532,15 +10110,12 @@ function TextField({ label, hint, error, id, className, required, disabled, ...n
|
|
|
9532
10110
|
className: "ui-input",
|
|
9533
10111
|
"aria-invalid": error ? true : void 0,
|
|
9534
10112
|
"aria-describedby": desc
|
|
9535
|
-
}), error ? /* @__PURE__ */ jsx(
|
|
9536
|
-
name: "warning-circle",
|
|
9537
|
-
className: "ui-field-icon"
|
|
9538
|
-
}) : null]
|
|
10113
|
+
}), error ? /* @__PURE__ */ jsx(FieldErrorIcon, {}) : null]
|
|
9539
10114
|
}),
|
|
9540
|
-
desc ? /* @__PURE__ */ jsx(
|
|
10115
|
+
desc ? /* @__PURE__ */ jsx(FieldMessage, {
|
|
9541
10116
|
id: desc,
|
|
9542
|
-
|
|
9543
|
-
|
|
10117
|
+
error,
|
|
10118
|
+
hint
|
|
9544
10119
|
}) : null
|
|
9545
10120
|
]
|
|
9546
10121
|
});
|
|
@@ -9589,7 +10164,7 @@ function LoginCard(p) {
|
|
|
9589
10164
|
error: uErr
|
|
9590
10165
|
}),
|
|
9591
10166
|
/* @__PURE__ */ jsxs("div", {
|
|
9592
|
-
className: "ui-field",
|
|
10167
|
+
className: cx("ui-field", pErr && "has-error"),
|
|
9593
10168
|
children: [
|
|
9594
10169
|
/* @__PURE__ */ jsxs("div", {
|
|
9595
10170
|
className: "ui-login-pwlabel",
|
|
@@ -9599,38 +10174,40 @@ function LoginCard(p) {
|
|
|
9599
10174
|
}), p.forgotHref ? /* @__PURE__ */ jsx("a", {
|
|
9600
10175
|
href: p.forgotHref,
|
|
9601
10176
|
className: "ui-link",
|
|
9602
|
-
children: tr("
|
|
10177
|
+
children: tr("忘記密碼")
|
|
9603
10178
|
}) : null]
|
|
9604
10179
|
}),
|
|
9605
10180
|
/* @__PURE__ */ jsxs("div", {
|
|
9606
10181
|
className: cx("ui-pwfield", pErr && "is-invalid"),
|
|
9607
|
-
children: [
|
|
9608
|
-
|
|
9609
|
-
|
|
9610
|
-
|
|
9611
|
-
|
|
9612
|
-
|
|
9613
|
-
|
|
9614
|
-
|
|
9615
|
-
|
|
9616
|
-
|
|
9617
|
-
|
|
9618
|
-
|
|
9619
|
-
|
|
9620
|
-
|
|
9621
|
-
|
|
9622
|
-
|
|
9623
|
-
|
|
9624
|
-
|
|
10182
|
+
children: [
|
|
10183
|
+
/* @__PURE__ */ jsx("input", {
|
|
10184
|
+
id: pwId,
|
|
10185
|
+
className: "ui-pwfield-input",
|
|
10186
|
+
type: show ? "text" : "password",
|
|
10187
|
+
value: pass,
|
|
10188
|
+
autoComplete: "current-password",
|
|
10189
|
+
"aria-invalid": pErr ? true : void 0,
|
|
10190
|
+
"aria-describedby": pErr ? pwId + "-err" : void 0,
|
|
10191
|
+
onChange: (e) => setPass(e.target.value)
|
|
10192
|
+
}),
|
|
10193
|
+
pErr ? /* @__PURE__ */ jsx(FieldErrorIcon, { inline: true }) : null,
|
|
10194
|
+
/* @__PURE__ */ jsx("button", {
|
|
10195
|
+
type: "button",
|
|
10196
|
+
className: "ui-datefield-btn",
|
|
10197
|
+
"aria-label": show ? tr("隱藏密碼") : tr("顯示密碼"),
|
|
10198
|
+
"aria-pressed": show,
|
|
10199
|
+
onClick: () => setShow(!show),
|
|
10200
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
10201
|
+
name: show ? "eye-slash" : "eye",
|
|
10202
|
+
size: 18
|
|
10203
|
+
})
|
|
9625
10204
|
})
|
|
9626
|
-
|
|
10205
|
+
]
|
|
9627
10206
|
}),
|
|
9628
|
-
|
|
10207
|
+
/* @__PURE__ */ jsx(FieldMessage, {
|
|
9629
10208
|
id: pwId + "-err",
|
|
9630
|
-
|
|
9631
|
-
|
|
9632
|
-
children: pErr
|
|
9633
|
-
}) : null
|
|
10209
|
+
error: pErr
|
|
10210
|
+
})
|
|
9634
10211
|
]
|
|
9635
10212
|
}),
|
|
9636
10213
|
/* @__PURE__ */ jsx(Button, {
|
|
@@ -9647,7 +10224,7 @@ function LoginCard(p) {
|
|
|
9647
10224
|
// src/components/MultiSelect/MultiSelect.tsx
|
|
9648
10225
|
const CREATE = "\0create:";
|
|
9649
10226
|
/** Pick several options: chips inside the field, type to filter, Backspace removes the last chip. */
|
|
9650
|
-
function MultiSelect({ label, options, value, onChange, creatable, maxChips = 2, placeholder, emptyText, className }) {
|
|
10227
|
+
function MultiSelect({ label, options, value, onChange, creatable, maxChips = 2, placeholder, emptyText, error, className }) {
|
|
9651
10228
|
const id = React.useId();
|
|
9652
10229
|
const [query, setQuery] = React.useState("");
|
|
9653
10230
|
const labels = React.useMemo(() => new Map(options.map((o) => [o.value, o.label])), [options]);
|
|
@@ -9662,82 +10239,91 @@ function MultiSelect({ label, options, value, onChange, creatable, maxChips = 2,
|
|
|
9662
10239
|
const shown = value.slice(0, maxChips);
|
|
9663
10240
|
const more = value.length - shown.length;
|
|
9664
10241
|
return /* @__PURE__ */ jsxs("div", {
|
|
9665
|
-
className: cx("ui-field", className),
|
|
9666
|
-
children: [
|
|
9667
|
-
|
|
9668
|
-
|
|
9669
|
-
|
|
9670
|
-
|
|
9671
|
-
|
|
9672
|
-
|
|
9673
|
-
|
|
9674
|
-
|
|
9675
|
-
|
|
9676
|
-
|
|
9677
|
-
|
|
9678
|
-
|
|
9679
|
-
|
|
9680
|
-
|
|
9681
|
-
|
|
9682
|
-
|
|
9683
|
-
children: /* @__PURE__ */ jsxs(Combobox.
|
|
9684
|
-
className: "ui-ms-
|
|
9685
|
-
children: [
|
|
9686
|
-
|
|
9687
|
-
|
|
9688
|
-
|
|
9689
|
-
|
|
9690
|
-
|
|
9691
|
-
|
|
9692
|
-
|
|
9693
|
-
|
|
9694
|
-
|
|
9695
|
-
|
|
9696
|
-
|
|
9697
|
-
|
|
9698
|
-
|
|
9699
|
-
|
|
9700
|
-
|
|
9701
|
-
|
|
9702
|
-
|
|
9703
|
-
|
|
9704
|
-
|
|
9705
|
-
|
|
9706
|
-
|
|
9707
|
-
|
|
9708
|
-
|
|
9709
|
-
|
|
9710
|
-
|
|
10242
|
+
className: cx("ui-field", error && "has-error", className),
|
|
10243
|
+
children: [
|
|
10244
|
+
label ? /* @__PURE__ */ jsx(FieldLabel, {
|
|
10245
|
+
htmlFor: id,
|
|
10246
|
+
children: label
|
|
10247
|
+
}) : null,
|
|
10248
|
+
/* @__PURE__ */ jsxs(Combobox.Root, {
|
|
10249
|
+
multiple: true,
|
|
10250
|
+
autoHighlight: true,
|
|
10251
|
+
items,
|
|
10252
|
+
value,
|
|
10253
|
+
inputValue: query,
|
|
10254
|
+
onInputValueChange: setQuery,
|
|
10255
|
+
itemToStringLabel: labelOf,
|
|
10256
|
+
onValueChange: (next) => {
|
|
10257
|
+
onChange(next.map((v) => v.startsWith(CREATE) ? v.slice(8) : v));
|
|
10258
|
+
setQuery("");
|
|
10259
|
+
},
|
|
10260
|
+
children: [/* @__PURE__ */ jsxs(Combobox.InputGroup, {
|
|
10261
|
+
className: cx("ui-ms", error && "is-invalid"),
|
|
10262
|
+
children: [/* @__PURE__ */ jsxs(Combobox.Chips, {
|
|
10263
|
+
className: "ui-ms-chips",
|
|
10264
|
+
children: [
|
|
10265
|
+
shown.map((v) => /* @__PURE__ */ jsxs(Combobox.Chip, {
|
|
10266
|
+
className: "ui-chip",
|
|
10267
|
+
"aria-label": labelOf(v),
|
|
10268
|
+
children: [labelOf(v), /* @__PURE__ */ jsx(Combobox.ChipRemove, {
|
|
10269
|
+
className: "ui-chip-x",
|
|
10270
|
+
"aria-label": tr("移除 {name}", { name: labelOf(v) }),
|
|
10271
|
+
children: /* @__PURE__ */ jsx(Icon, {
|
|
10272
|
+
name: "x",
|
|
10273
|
+
size: 12
|
|
10274
|
+
})
|
|
10275
|
+
})]
|
|
10276
|
+
}, v)),
|
|
10277
|
+
more > 0 ? /* @__PURE__ */ jsx("span", {
|
|
10278
|
+
className: "ui-chip-more",
|
|
10279
|
+
title: value.slice(maxChips).map(labelOf).join("、"),
|
|
10280
|
+
children: "+" + more
|
|
10281
|
+
}) : null,
|
|
10282
|
+
/* @__PURE__ */ jsx(Combobox.Input, {
|
|
10283
|
+
id,
|
|
10284
|
+
className: "ui-ms-input",
|
|
10285
|
+
"aria-invalid": error ? true : void 0,
|
|
10286
|
+
"aria-describedby": error ? id + "-err" : void 0,
|
|
10287
|
+
placeholder: value.length ? "" : placeholder || tr("搜尋"),
|
|
10288
|
+
onKeyDown: (e) => {
|
|
10289
|
+
if (e.key === "Backspace" && !query && value.length) {
|
|
10290
|
+
e.preventBaseUIHandler();
|
|
10291
|
+
onChange(value.slice(0, -1));
|
|
10292
|
+
}
|
|
9711
10293
|
}
|
|
9712
|
-
}
|
|
9713
|
-
|
|
9714
|
-
]
|
|
9715
|
-
})
|
|
9716
|
-
|
|
9717
|
-
|
|
9718
|
-
|
|
9719
|
-
|
|
9720
|
-
|
|
9721
|
-
|
|
9722
|
-
|
|
9723
|
-
|
|
9724
|
-
children:
|
|
9725
|
-
|
|
9726
|
-
|
|
9727
|
-
|
|
9728
|
-
|
|
9729
|
-
|
|
9730
|
-
|
|
9731
|
-
|
|
9732
|
-
|
|
9733
|
-
|
|
9734
|
-
|
|
9735
|
-
|
|
9736
|
-
}
|
|
9737
|
-
}
|
|
9738
|
-
})
|
|
9739
|
-
})
|
|
9740
|
-
|
|
10294
|
+
})
|
|
10295
|
+
]
|
|
10296
|
+
}), error ? /* @__PURE__ */ jsx(FieldErrorIcon, { inline: true }) : null]
|
|
10297
|
+
}), /* @__PURE__ */ jsx(Combobox.Portal, { children: /* @__PURE__ */ jsx(Combobox.Positioner, {
|
|
10298
|
+
className: "ui-float is-match",
|
|
10299
|
+
align: "start",
|
|
10300
|
+
sideOffset: 6,
|
|
10301
|
+
children: /* @__PURE__ */ jsxs(Combobox.Popup, {
|
|
10302
|
+
className: "ui-select-menu ui-ms-menu",
|
|
10303
|
+
children: [/* @__PURE__ */ jsx(Combobox.Empty, {
|
|
10304
|
+
className: "ui-select-empty",
|
|
10305
|
+
children: emptyText || tr("找不到符合的選項")
|
|
10306
|
+
}), /* @__PURE__ */ jsx(Combobox.List, { children: (v) => v.startsWith(CREATE) ? /* @__PURE__ */ jsx(Combobox.Item, {
|
|
10307
|
+
value: v,
|
|
10308
|
+
className: "ui-select-opt ui-ms-create",
|
|
10309
|
+
children: labelOf(v)
|
|
10310
|
+
}, v) : /* @__PURE__ */ jsxs(Combobox.Item, {
|
|
10311
|
+
value: v,
|
|
10312
|
+
className: cx("ui-select-opt", "ui-ms-opt", value.includes(v) && "is-on"),
|
|
10313
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
10314
|
+
className: cx("ui-check-box", value.includes(v) && "is-on"),
|
|
10315
|
+
"aria-hidden": "true",
|
|
10316
|
+
children: /* @__PURE__ */ jsx(CheckMark, { v: value.includes(v) })
|
|
10317
|
+
}), /* @__PURE__ */ jsx("span", { children: labelOf(v) })]
|
|
10318
|
+
}, v) })]
|
|
10319
|
+
})
|
|
10320
|
+
}) })]
|
|
10321
|
+
}),
|
|
10322
|
+
/* @__PURE__ */ jsx(FieldMessage, {
|
|
10323
|
+
id: id + "-err",
|
|
10324
|
+
error
|
|
10325
|
+
})
|
|
10326
|
+
]
|
|
9741
10327
|
});
|
|
9742
10328
|
}
|
|
9743
10329
|
// src/components/NotificationBell/NotificationBell.tsx
|
|
@@ -10053,7 +10639,7 @@ function RadioGroup({ label, value, onChange, options, disabled, className }) {
|
|
|
10053
10639
|
// src/components/Select/Select.tsx
|
|
10054
10640
|
/** Pick one option from a list. Use it instead of a native <select>; a search box appears above 8 options. */
|
|
10055
10641
|
function Select(props) {
|
|
10056
|
-
const { label, value, onChange, options, searchable = options.length > 8, placeholder, searchPlaceholder, required, disabled, name, className } = props;
|
|
10642
|
+
const { label, value, onChange, options, searchable = options.length > 8, placeholder, searchPlaceholder, required, disabled, error, name, className } = props;
|
|
10057
10643
|
const labelId = React.useId();
|
|
10058
10644
|
const current = options.find((o) => o.value === value) ?? null;
|
|
10059
10645
|
const head = label ? /* @__PURE__ */ jsx(FieldLabel, {
|
|
@@ -10061,99 +10647,119 @@ function Select(props) {
|
|
|
10061
10647
|
required,
|
|
10062
10648
|
children: label
|
|
10063
10649
|
}) : null;
|
|
10064
|
-
const trigger = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10065
|
-
|
|
10066
|
-
|
|
10067
|
-
|
|
10068
|
-
|
|
10069
|
-
|
|
10070
|
-
|
|
10071
|
-
|
|
10650
|
+
const trigger = /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
10651
|
+
/* @__PURE__ */ jsx("span", {
|
|
10652
|
+
className: cx(!current && "is-placeholder"),
|
|
10653
|
+
children: current ? current.label : placeholder || tr("請選擇")
|
|
10654
|
+
}),
|
|
10655
|
+
error ? /* @__PURE__ */ jsx(FieldErrorIcon, { inline: true }) : null,
|
|
10656
|
+
/* @__PURE__ */ jsx(Icon, {
|
|
10657
|
+
name: "caret-down",
|
|
10658
|
+
size: 16,
|
|
10659
|
+
className: "ui-select-chev"
|
|
10660
|
+
})
|
|
10661
|
+
] });
|
|
10662
|
+
const errId = labelId + "-err";
|
|
10663
|
+
const message = /* @__PURE__ */ jsx(FieldMessage, {
|
|
10664
|
+
id: errId,
|
|
10665
|
+
error
|
|
10666
|
+
});
|
|
10072
10667
|
const optionBody = (o, on) => /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("span", { children: o.label }), on ? /* @__PURE__ */ jsx(Icon, {
|
|
10073
10668
|
name: "check",
|
|
10074
10669
|
size: 16
|
|
10075
10670
|
}) : null] });
|
|
10076
10671
|
const labelling = {
|
|
10077
10672
|
"aria-labelledby": label ? labelId : void 0,
|
|
10078
|
-
"aria-label": label ? void 0 : props["aria-label"]
|
|
10673
|
+
"aria-label": label ? void 0 : props["aria-label"],
|
|
10674
|
+
"aria-invalid": error ? true : void 0,
|
|
10675
|
+
"aria-describedby": error ? errId : void 0
|
|
10079
10676
|
};
|
|
10677
|
+
const triggerClass = cx("ui-select-trigger", error && "is-invalid");
|
|
10080
10678
|
if (searchable) return /* @__PURE__ */ jsxs("div", {
|
|
10081
10679
|
className: cx("ui-select", className),
|
|
10082
|
-
children: [
|
|
10083
|
-
|
|
10084
|
-
|
|
10085
|
-
|
|
10086
|
-
|
|
10087
|
-
|
|
10088
|
-
|
|
10089
|
-
|
|
10090
|
-
|
|
10091
|
-
|
|
10092
|
-
|
|
10093
|
-
|
|
10094
|
-
|
|
10095
|
-
|
|
10096
|
-
|
|
10097
|
-
|
|
10098
|
-
|
|
10099
|
-
|
|
10100
|
-
|
|
10101
|
-
|
|
10102
|
-
|
|
10103
|
-
|
|
10104
|
-
|
|
10105
|
-
|
|
10106
|
-
|
|
10107
|
-
|
|
10108
|
-
|
|
10109
|
-
|
|
10110
|
-
|
|
10111
|
-
|
|
10112
|
-
|
|
10113
|
-
|
|
10114
|
-
|
|
10115
|
-
|
|
10116
|
-
|
|
10117
|
-
|
|
10118
|
-
|
|
10119
|
-
|
|
10120
|
-
|
|
10121
|
-
|
|
10122
|
-
|
|
10123
|
-
|
|
10124
|
-
|
|
10125
|
-
|
|
10126
|
-
|
|
10680
|
+
children: [
|
|
10681
|
+
head,
|
|
10682
|
+
/* @__PURE__ */ jsxs(Combobox.Root, {
|
|
10683
|
+
items: options,
|
|
10684
|
+
value: current,
|
|
10685
|
+
onValueChange: (o) => o && onChange?.(o.value),
|
|
10686
|
+
itemToStringLabel: (o) => o.label,
|
|
10687
|
+
isItemEqualToValue: (a, b) => a.value === b.value,
|
|
10688
|
+
disabled,
|
|
10689
|
+
required,
|
|
10690
|
+
name,
|
|
10691
|
+
children: [/* @__PURE__ */ jsx(Combobox.Trigger, {
|
|
10692
|
+
className: triggerClass,
|
|
10693
|
+
...labelling,
|
|
10694
|
+
children: trigger
|
|
10695
|
+
}), /* @__PURE__ */ jsx(Combobox.Portal, { children: /* @__PURE__ */ jsx(Combobox.Positioner, {
|
|
10696
|
+
className: "ui-select-positioner",
|
|
10697
|
+
align: "start",
|
|
10698
|
+
sideOffset: 6,
|
|
10699
|
+
children: /* @__PURE__ */ jsxs(Combobox.Popup, {
|
|
10700
|
+
className: "ui-select-menu",
|
|
10701
|
+
"aria-label": label || props["aria-label"],
|
|
10702
|
+
children: [
|
|
10703
|
+
/* @__PURE__ */ jsxs("div", {
|
|
10704
|
+
className: "ui-select-search",
|
|
10705
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
10706
|
+
name: "magnifying-glass",
|
|
10707
|
+
size: 14
|
|
10708
|
+
}), /* @__PURE__ */ jsx(Combobox.Input, {
|
|
10709
|
+
placeholder: searchPlaceholder || tr("搜尋"),
|
|
10710
|
+
"aria-label": searchPlaceholder || tr("搜尋")
|
|
10711
|
+
})]
|
|
10712
|
+
}),
|
|
10713
|
+
/* @__PURE__ */ jsx(Combobox.Empty, {
|
|
10714
|
+
className: "ui-select-empty",
|
|
10715
|
+
children: tr("找不到符合的選項")
|
|
10716
|
+
}),
|
|
10717
|
+
/* @__PURE__ */ jsx(Combobox.List, { children: (o) => /* @__PURE__ */ jsx(Combobox.Item, {
|
|
10718
|
+
value: o,
|
|
10719
|
+
disabled: o.disabled,
|
|
10720
|
+
className: cx("ui-select-opt", o.value === value && "is-on"),
|
|
10721
|
+
children: optionBody(o, o.value === value)
|
|
10722
|
+
}, o.value) })
|
|
10723
|
+
]
|
|
10724
|
+
})
|
|
10725
|
+
}) })]
|
|
10726
|
+
}),
|
|
10727
|
+
message
|
|
10728
|
+
]
|
|
10127
10729
|
});
|
|
10128
10730
|
return /* @__PURE__ */ jsxs("div", {
|
|
10129
10731
|
className: cx("ui-select", className),
|
|
10130
|
-
children: [
|
|
10131
|
-
|
|
10132
|
-
|
|
10133
|
-
|
|
10134
|
-
|
|
10135
|
-
|
|
10136
|
-
|
|
10137
|
-
|
|
10138
|
-
|
|
10139
|
-
|
|
10140
|
-
|
|
10141
|
-
|
|
10142
|
-
|
|
10143
|
-
|
|
10144
|
-
|
|
10145
|
-
|
|
10146
|
-
|
|
10147
|
-
|
|
10148
|
-
children: /* @__PURE__ */ jsx(Select$1.
|
|
10149
|
-
|
|
10150
|
-
|
|
10151
|
-
|
|
10152
|
-
|
|
10153
|
-
|
|
10154
|
-
|
|
10155
|
-
|
|
10156
|
-
|
|
10732
|
+
children: [
|
|
10733
|
+
head,
|
|
10734
|
+
/* @__PURE__ */ jsxs(Select$1.Root, {
|
|
10735
|
+
items: options,
|
|
10736
|
+
value: value ?? null,
|
|
10737
|
+
onValueChange: (v) => v != null && onChange?.(v),
|
|
10738
|
+
disabled,
|
|
10739
|
+
required,
|
|
10740
|
+
name,
|
|
10741
|
+
children: [/* @__PURE__ */ jsx(Select$1.Trigger, {
|
|
10742
|
+
className: triggerClass,
|
|
10743
|
+
...labelling,
|
|
10744
|
+
children: trigger
|
|
10745
|
+
}), /* @__PURE__ */ jsx(Select$1.Portal, { children: /* @__PURE__ */ jsx(Select$1.Positioner, {
|
|
10746
|
+
className: "ui-select-positioner",
|
|
10747
|
+
alignItemWithTrigger: false,
|
|
10748
|
+
align: "start",
|
|
10749
|
+
sideOffset: 6,
|
|
10750
|
+
children: /* @__PURE__ */ jsx(Select$1.Popup, {
|
|
10751
|
+
className: "ui-select-menu",
|
|
10752
|
+
children: /* @__PURE__ */ jsx(Select$1.List, { children: options.map((o) => /* @__PURE__ */ jsx(Select$1.Item, {
|
|
10753
|
+
value: o.value,
|
|
10754
|
+
disabled: o.disabled,
|
|
10755
|
+
className: cx("ui-select-opt", o.value === value && "is-on"),
|
|
10756
|
+
children: optionBody(o, o.value === value)
|
|
10757
|
+
}, o.value)) })
|
|
10758
|
+
})
|
|
10759
|
+
}) })]
|
|
10760
|
+
}),
|
|
10761
|
+
message
|
|
10762
|
+
]
|
|
10157
10763
|
});
|
|
10158
10764
|
}
|
|
10159
10765
|
// src/components/Toast/Toast.tsx
|
|
@@ -10402,9 +11008,10 @@ function Tag({ children, variant = "plain", className }) {
|
|
|
10402
11008
|
}
|
|
10403
11009
|
// src/components/TextArea/TextArea.tsx
|
|
10404
11010
|
/** Multi-line text that grows up to 8 lines, with a character counter. */
|
|
10405
|
-
function TextArea({ label, hint, value, onChange, maxLength = 200, className, id, required, ...native }) {
|
|
11011
|
+
function TextArea({ label, hint, error, value, onChange, maxLength = 200, className, id, required, ...native }) {
|
|
10406
11012
|
const auto = React.useId();
|
|
10407
11013
|
const fieldId = id || auto;
|
|
11014
|
+
const hintId = error ? fieldId + "-err" : hint ? fieldId + "-hint" : void 0;
|
|
10408
11015
|
const ref = React.useRef(null);
|
|
10409
11016
|
React.useLayoutEffect(() => {
|
|
10410
11017
|
const el = ref.current;
|
|
@@ -10413,27 +11020,38 @@ function TextArea({ label, hint, value, onChange, maxLength = 200, className, id
|
|
|
10413
11020
|
el.style.height = Math.min(el.scrollHeight + 2, 230) + "px";
|
|
10414
11021
|
}, [value]);
|
|
10415
11022
|
return /* @__PURE__ */ jsxs("div", {
|
|
10416
|
-
className: cx("ui-field", className),
|
|
11023
|
+
className: cx("ui-field", error && "has-error", className),
|
|
10417
11024
|
children: [
|
|
10418
11025
|
label ? /* @__PURE__ */ jsx(FieldLabel, {
|
|
10419
11026
|
htmlFor: fieldId,
|
|
10420
11027
|
required,
|
|
10421
11028
|
children: label
|
|
10422
11029
|
}) : null,
|
|
10423
|
-
/* @__PURE__ */
|
|
10424
|
-
|
|
10425
|
-
|
|
10426
|
-
|
|
10427
|
-
|
|
10428
|
-
|
|
10429
|
-
|
|
10430
|
-
|
|
10431
|
-
|
|
10432
|
-
|
|
11030
|
+
/* @__PURE__ */ jsxs("div", {
|
|
11031
|
+
className: "ui-field-box",
|
|
11032
|
+
children: [/* @__PURE__ */ jsx("textarea", {
|
|
11033
|
+
rows: 3,
|
|
11034
|
+
...native,
|
|
11035
|
+
ref,
|
|
11036
|
+
id: fieldId,
|
|
11037
|
+
className: "ui-input ui-textarea",
|
|
11038
|
+
maxLength,
|
|
11039
|
+
value: value || "",
|
|
11040
|
+
"aria-required": required || void 0,
|
|
11041
|
+
"aria-describedby": [native["aria-describedby"], hintId].filter(Boolean).join(" ") || void 0,
|
|
11042
|
+
"aria-invalid": error ? true : void 0,
|
|
11043
|
+
onChange: (e) => onChange(e.target.value)
|
|
11044
|
+
}), error ? /* @__PURE__ */ jsx(FieldErrorIcon, {}) : null]
|
|
10433
11045
|
}),
|
|
10434
11046
|
/* @__PURE__ */ jsxs("div", {
|
|
10435
11047
|
className: "ui-field-foot",
|
|
10436
|
-
children: [/* @__PURE__ */ jsx("span", {
|
|
11048
|
+
children: [error ? /* @__PURE__ */ jsx("span", {
|
|
11049
|
+
id: hintId,
|
|
11050
|
+
className: "ui-field-error",
|
|
11051
|
+
role: "alert",
|
|
11052
|
+
children: error
|
|
11053
|
+
}, error) : /* @__PURE__ */ jsx("span", {
|
|
11054
|
+
id: hintId,
|
|
10437
11055
|
className: "ui-field-hint",
|
|
10438
11056
|
children: hint || ""
|
|
10439
11057
|
}), /* @__PURE__ */ jsxs("span", {
|
|
@@ -10472,21 +11090,36 @@ const THEMES = [
|
|
|
10472
11090
|
function ThemePicker({ value, onChange, label, className }) {
|
|
10473
11091
|
const [own, setOwn] = React.useState(() => value ?? storedTheme());
|
|
10474
11092
|
const cur = value ?? own;
|
|
11093
|
+
const refs = React.useRef([]);
|
|
10475
11094
|
const pick = (id) => {
|
|
10476
11095
|
setOwn(id);
|
|
10477
11096
|
if (onChange) onChange(id);
|
|
10478
11097
|
else setTheme(id);
|
|
10479
11098
|
};
|
|
11099
|
+
const tabStop = Math.max(0, THEMES.findIndex((t) => t.id === cur));
|
|
10480
11100
|
return /* @__PURE__ */ jsx("div", {
|
|
10481
11101
|
role: "radiogroup",
|
|
10482
11102
|
"aria-label": label || tr("主題"),
|
|
10483
11103
|
className: cx("ui-themepick", className),
|
|
10484
|
-
children: THEMES.map((t) => /* @__PURE__ */ jsxs("button", {
|
|
11104
|
+
children: THEMES.map((t, i) => /* @__PURE__ */ jsxs("button", {
|
|
11105
|
+
ref: (el) => {
|
|
11106
|
+
refs.current[i] = el;
|
|
11107
|
+
},
|
|
10485
11108
|
type: "button",
|
|
10486
11109
|
role: "radio",
|
|
10487
11110
|
"aria-checked": cur === t.id,
|
|
11111
|
+
tabIndex: i === tabStop ? 0 : -1,
|
|
10488
11112
|
className: cx("ui-themepick-opt", cur === t.id && "is-on"),
|
|
10489
11113
|
onClick: () => pick(t.id),
|
|
11114
|
+
onKeyDown: (e) => {
|
|
11115
|
+
if (browserKey(e)) return;
|
|
11116
|
+
const n = THEMES.length;
|
|
11117
|
+
const to = e.key === "ArrowRight" || e.key === "ArrowDown" ? (i + 1) % n : e.key === "ArrowLeft" || e.key === "ArrowUp" ? (i - 1 + n) % n : -1;
|
|
11118
|
+
if (to < 0) return;
|
|
11119
|
+
e.preventDefault();
|
|
11120
|
+
refs.current[to]?.focus();
|
|
11121
|
+
pick(THEMES[to].id);
|
|
11122
|
+
},
|
|
10490
11123
|
children: [/* @__PURE__ */ jsxs("span", {
|
|
10491
11124
|
className: "ui-themepick-mini is-" + t.id,
|
|
10492
11125
|
"aria-hidden": "true",
|