@seanyeh77/ui 0.4.1 → 0.5.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 +8 -8
- package/dist/bundle.js.map +1 -1
- package/dist/{format-entry-DDglckmU.js → format-entry-BWjH_kB_.js} +4 -1
- package/dist/format-entry-BWjH_kB_.js.map +1 -0
- package/dist/format.js +1 -1
- package/dist/index.d.ts +19 -6
- package/dist/index.js +264 -179
- package/dist/index.js.map +1 -1
- package/dist/styles.css +81 -23
- package/docs/CodeView.md +2 -1
- package/docs/DataTable.md +4 -4
- package/docs/LayerGraph.md +5 -4
- package/docs/Tabs.md +1 -1
- package/docs/Tooltip.md +1 -0
- package/docs/guidelines.md +7 -6
- package/package.json +2 -2
- package/dist/format-entry-DDglckmU.js.map +0 -1
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-
|
|
2
|
+
import { a as parseDate, c as addMessages, i as format, l as setLocale, n as fileSize, o as sameDay, r as fmtDate, s as I18N, t as dayAdd, u as tr } from "./format-entry-BWjH_kB_.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";
|
|
@@ -576,29 +576,32 @@ function Breadcrumb({ items, className }) {
|
|
|
576
576
|
}
|
|
577
577
|
// src/components/Tooltip/Tooltip.tsx
|
|
578
578
|
/** Dark label above the element (below when there is no room), with an arrow. Appears at once on hover and focus. */
|
|
579
|
-
function Tooltip({ label, side = "top", describe = true, children }) {
|
|
579
|
+
function Tooltip({ label, side = "top", describe = true, wrap = false, disabled = false, children }) {
|
|
580
580
|
const id = React.useId();
|
|
581
|
-
return /* @__PURE__ */ jsxs(Tooltip$1.Root, {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
className: "ui-tooltip",
|
|
598
|
-
children:
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
581
|
+
return /* @__PURE__ */ jsxs(Tooltip$1.Root, {
|
|
582
|
+
disabled,
|
|
583
|
+
children: [
|
|
584
|
+
/* @__PURE__ */ jsx(Tooltip$1.Trigger, {
|
|
585
|
+
delay: 0,
|
|
586
|
+
render: children,
|
|
587
|
+
"aria-describedby": describe && !disabled ? id : void 0
|
|
588
|
+
}),
|
|
589
|
+
describe && !disabled ? /* @__PURE__ */ jsx("span", {
|
|
590
|
+
id,
|
|
591
|
+
hidden: true,
|
|
592
|
+
children: label
|
|
593
|
+
}) : null,
|
|
594
|
+
/* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
|
|
595
|
+
side,
|
|
596
|
+
sideOffset: 8,
|
|
597
|
+
className: "ui-tooltip-positioner",
|
|
598
|
+
children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
|
|
599
|
+
className: wrap ? "ui-tooltip is-wrap" : "ui-tooltip",
|
|
600
|
+
children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
|
|
601
|
+
})
|
|
602
|
+
}) })
|
|
603
|
+
]
|
|
604
|
+
});
|
|
602
605
|
}
|
|
603
606
|
// src/components/IconButton/IconButton.tsx
|
|
604
607
|
/** A square icon-only button with a tooltip. */
|
|
@@ -1768,8 +1771,9 @@ function languageOf(file) {
|
|
|
1768
1771
|
const m = /\.([A-Za-z0-9]+)$/.exec(file || "");
|
|
1769
1772
|
return m && EXT[m[1].toLowerCase()] || "plain";
|
|
1770
1773
|
}
|
|
1774
|
+
/** Header labels. A bare 「C」 reads like a button, so C is 「C 語言」. */
|
|
1771
1775
|
const LANGUAGE_NAMES = {
|
|
1772
|
-
c: "C",
|
|
1776
|
+
c: "C 語言",
|
|
1773
1777
|
js: "JavaScript",
|
|
1774
1778
|
py: "Python",
|
|
1775
1779
|
sh: "Shell"
|
|
@@ -1876,9 +1880,12 @@ function CodeView({ code, start = 1, target, context = 2, file, fileHref, onFile
|
|
|
1876
1880
|
}) : /* @__PURE__ */ jsx("span", {
|
|
1877
1881
|
className: "ui-cv-title",
|
|
1878
1882
|
children: title
|
|
1879
|
-
}), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */
|
|
1883
|
+
}), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
|
|
1880
1884
|
className: "ui-cv-lang",
|
|
1881
|
-
children:
|
|
1885
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
1886
|
+
className: "ui-visually-hidden",
|
|
1887
|
+
children: [tr("程式語言"), ":"]
|
|
1888
|
+
}), tr(languageLabel || LANGUAGE_NAMES[lang] || lang)]
|
|
1882
1889
|
}) : null]
|
|
1883
1890
|
}) : null;
|
|
1884
1891
|
return /* @__PURE__ */ jsxs("div", {
|
|
@@ -2161,12 +2168,13 @@ function SearchField({ value, onChange, className, label, ...native }) {
|
|
|
2161
2168
|
}
|
|
2162
2169
|
// src/components/Tabs/Tabs.tsx
|
|
2163
2170
|
/** Views of the same content. The underline moves like a droplet; arrow keys move between tabs. */
|
|
2164
|
-
function Tabs({ items, value, onChange, label, className }) {
|
|
2171
|
+
function Tabs({ items, value, onChange, label, unit, className }) {
|
|
2165
2172
|
const refs = React.useRef([]);
|
|
2166
2173
|
const track = React.useRef(null);
|
|
2167
2174
|
const [box, setBox] = React.useState(null);
|
|
2168
2175
|
const [forward, setForward] = React.useState(true);
|
|
2169
2176
|
const [moving, bump] = useMoving();
|
|
2177
|
+
devWarn(items.some((t) => t.count != null && !(t.unit || unit)), "Tabs", "a count has no unit, so it reads as a bare number. Pass unit, e.g. unit: '筆', on Tabs or on the item.");
|
|
2170
2178
|
const idx = Math.max(0, items.findIndex((t) => t.id === value));
|
|
2171
2179
|
React.useLayoutEffect(() => {
|
|
2172
2180
|
const el = refs.current[idx];
|
|
@@ -2219,13 +2227,64 @@ function Tabs({ items, value, onChange, label, className }) {
|
|
|
2219
2227
|
refs.current[to]?.focus();
|
|
2220
2228
|
go(to);
|
|
2221
2229
|
},
|
|
2222
|
-
children: [t.label, t.count != null ? /* @__PURE__ */
|
|
2230
|
+
children: [t.label, t.count != null ? /* @__PURE__ */ jsxs("span", {
|
|
2223
2231
|
className: "ui-tab-count",
|
|
2224
|
-
children: format.number(t.count)
|
|
2232
|
+
children: [format.number(t.count), t.unit || unit ? /* @__PURE__ */ jsxs("span", {
|
|
2233
|
+
className: "ui-unit",
|
|
2234
|
+
children: [" ", tr(t.unit || unit || "")]
|
|
2235
|
+
}) : null]
|
|
2225
2236
|
}) : null]
|
|
2226
2237
|
}, t.id))]
|
|
2227
2238
|
});
|
|
2228
2239
|
}
|
|
2240
|
+
// src/internal/scrollHint.tsx
|
|
2241
|
+
/** A box that may be wider than its container: whether it overflows, whether more is to the right, and whether the
|
|
2242
|
+
* person has scrolled yet. Used by LayerGraph and DataTable for the right-edge fade and the 「左右滑動」 hint. */
|
|
2243
|
+
function useScrollHint() {
|
|
2244
|
+
const ref = React.useRef(null);
|
|
2245
|
+
const [more, setMore] = React.useState(false);
|
|
2246
|
+
const [scrolled, setScrolled] = React.useState(false);
|
|
2247
|
+
const [overflows, setOverflows] = React.useState(false);
|
|
2248
|
+
const measure = React.useCallback(() => {
|
|
2249
|
+
const el = ref.current;
|
|
2250
|
+
if (!el) return;
|
|
2251
|
+
const wide = el.scrollWidth > el.clientWidth + 1;
|
|
2252
|
+
setOverflows(wide);
|
|
2253
|
+
setMore(wide && el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
|
|
2254
|
+
}, []);
|
|
2255
|
+
React.useLayoutEffect(() => {
|
|
2256
|
+
const el = ref.current;
|
|
2257
|
+
if (!el) return;
|
|
2258
|
+
measure();
|
|
2259
|
+
const ro = new ResizeObserver(measure);
|
|
2260
|
+
ro.observe(el);
|
|
2261
|
+
if (el.firstElementChild) ro.observe(el.firstElementChild);
|
|
2262
|
+
return () => ro.disconnect();
|
|
2263
|
+
}, [measure]);
|
|
2264
|
+
return {
|
|
2265
|
+
ref,
|
|
2266
|
+
more,
|
|
2267
|
+
overflows,
|
|
2268
|
+
scrolled,
|
|
2269
|
+
onScroll: React.useCallback(() => {
|
|
2270
|
+
const el = ref.current;
|
|
2271
|
+
if (el && el.scrollLeft > 0) setScrolled(true);
|
|
2272
|
+
measure();
|
|
2273
|
+
}, [measure]),
|
|
2274
|
+
measure
|
|
2275
|
+
};
|
|
2276
|
+
}
|
|
2277
|
+
/** 「→ 左右滑動」 under the box, right-aligned. Hidden after the first sideways scroll but keeps its line, so nothing below jumps. */
|
|
2278
|
+
function ScrollHint({ show, done }) {
|
|
2279
|
+
return show ? /* @__PURE__ */ jsxs("span", {
|
|
2280
|
+
className: cx("ui-scroll-hint", done && "is-done"),
|
|
2281
|
+
"aria-hidden": "true",
|
|
2282
|
+
children: [/* @__PURE__ */ jsx(Icon, {
|
|
2283
|
+
name: "arrow-right",
|
|
2284
|
+
size: 14
|
|
2285
|
+
}), tr("左右滑動")]
|
|
2286
|
+
}) : null;
|
|
2287
|
+
}
|
|
2229
2288
|
// src/components/DataTable/filters.ts
|
|
2230
2289
|
const field = (row, key) => row[key];
|
|
2231
2290
|
/** Cell text: money as NT$ 1,280, dates as 2026/11/04(三), numbers with their unit after them. */
|
|
@@ -2528,26 +2587,41 @@ function FilterButton({ filters, values, activeCount, count, onChange, onClear }
|
|
|
2528
2587
|
})]
|
|
2529
2588
|
});
|
|
2530
2589
|
}
|
|
2531
|
-
/** Long text in a cell
|
|
2590
|
+
/** Long text in a cell. Phone cards: at most 2 lines with 「顯示全部」. Desktop: one line; when it is cut off, hover or
|
|
2591
|
+
* focus shows the whole text in a Tooltip. */
|
|
2532
2592
|
function LongText({ children }) {
|
|
2593
|
+
const box = React.useRef(null);
|
|
2533
2594
|
const ref = React.useRef(null);
|
|
2595
|
+
const narrow = useNarrow();
|
|
2534
2596
|
const [open, setOpen] = React.useState(false);
|
|
2535
2597
|
const [over, setOver] = React.useState(false);
|
|
2598
|
+
const [cut, setCut] = React.useState("");
|
|
2536
2599
|
React.useLayoutEffect(() => {
|
|
2537
2600
|
const el = ref.current;
|
|
2538
|
-
|
|
2539
|
-
|
|
2601
|
+
const outer = box.current;
|
|
2602
|
+
if (!el || !outer || open) return;
|
|
2603
|
+
const check = () => {
|
|
2604
|
+
setOver(el.scrollHeight > el.clientHeight + 1);
|
|
2605
|
+
setCut(!narrow && outer.scrollWidth > outer.clientWidth + 1 ? outer.textContent ?? "" : "");
|
|
2606
|
+
};
|
|
2540
2607
|
check();
|
|
2541
|
-
|
|
2542
|
-
|
|
2543
|
-
|
|
2544
|
-
|
|
2545
|
-
|
|
2608
|
+
const ro = new ResizeObserver(check);
|
|
2609
|
+
ro.observe(outer);
|
|
2610
|
+
return () => ro.disconnect();
|
|
2611
|
+
}, [
|
|
2612
|
+
open,
|
|
2613
|
+
children,
|
|
2614
|
+
narrow
|
|
2615
|
+
]);
|
|
2616
|
+
const body = /* @__PURE__ */ jsxs("span", {
|
|
2617
|
+
ref: box,
|
|
2618
|
+
className: cx("ui-dt-long", !!cut && "is-cut"),
|
|
2619
|
+
tabIndex: cut ? 0 : void 0,
|
|
2546
2620
|
children: [/* @__PURE__ */ jsx("span", {
|
|
2547
2621
|
ref,
|
|
2548
2622
|
className: cx("ui-dt-long-text", !open && "is-clamped"),
|
|
2549
2623
|
children
|
|
2550
|
-
}), over || open ? /* @__PURE__ */ jsx("button", {
|
|
2624
|
+
}), narrow && (over || open) ? /* @__PURE__ */ jsx("button", {
|
|
2551
2625
|
type: "button",
|
|
2552
2626
|
className: "ui-dt-more",
|
|
2553
2627
|
onClick: (e) => {
|
|
@@ -2557,6 +2631,12 @@ function LongText({ children }) {
|
|
|
2557
2631
|
children: open ? tr("收合") : tr("顯示全部")
|
|
2558
2632
|
}) : null]
|
|
2559
2633
|
});
|
|
2634
|
+
return /* @__PURE__ */ jsx(Tooltip, {
|
|
2635
|
+
label: cut,
|
|
2636
|
+
wrap: true,
|
|
2637
|
+
disabled: !cut,
|
|
2638
|
+
children: body
|
|
2639
|
+
});
|
|
2560
2640
|
}
|
|
2561
2641
|
// src/components/DataTable/DataTable.tsx
|
|
2562
2642
|
const MOVE = {
|
|
@@ -2638,6 +2718,7 @@ function DataTable(p) {
|
|
|
2638
2718
|
devWarn(cols.some((c) => c.format === "percent" && !c.unit), "DataTable", "format: 'percent' sets 1 decimal and shows no % sign; add unit: '%' to that column.");
|
|
2639
2719
|
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.");
|
|
2640
2720
|
const shownCols = cols.filter((c, i) => i === 0 || !hidden[c.key]);
|
|
2721
|
+
const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
|
|
2641
2722
|
const bodyRef = React.useRef(null);
|
|
2642
2723
|
const rowEls = React.useRef({});
|
|
2643
2724
|
const snap = React.useRef(null);
|
|
@@ -2949,9 +3030,12 @@ function DataTable(p) {
|
|
|
2949
3030
|
setView(v.id);
|
|
2950
3031
|
setPage(0);
|
|
2951
3032
|
},
|
|
2952
|
-
children: [v.label, /* @__PURE__ */
|
|
3033
|
+
children: [v.label, /* @__PURE__ */ jsxs("span", {
|
|
2953
3034
|
className: "ui-dt-view-n",
|
|
2954
|
-
children: format.number(rows.filter((r) => !v.filter || v.filter(r)).length)
|
|
3035
|
+
children: [format.number(rows.filter((r) => !v.filter || v.filter(r)).length), /* @__PURE__ */ jsxs("span", {
|
|
3036
|
+
className: "ui-unit",
|
|
3037
|
+
children: [" ", tr("筆")]
|
|
3038
|
+
})]
|
|
2955
3039
|
})]
|
|
2956
3040
|
}, v.id);
|
|
2957
3041
|
})
|
|
@@ -2959,6 +3043,7 @@ function DataTable(p) {
|
|
|
2959
3043
|
summary ? /* @__PURE__ */ jsx(Tabs, {
|
|
2960
3044
|
className: "ui-dt-summary",
|
|
2961
3045
|
label: summary.label || tr("依狀態篩選"),
|
|
3046
|
+
unit: summary.unit || "筆",
|
|
2962
3047
|
value: sumVal,
|
|
2963
3048
|
onChange: (v) => {
|
|
2964
3049
|
capture("sort");
|
|
@@ -3023,85 +3108,94 @@ function DataTable(p) {
|
|
|
3023
3108
|
]
|
|
3024
3109
|
}),
|
|
3025
3110
|
/* @__PURE__ */ jsx("div", {
|
|
3026
|
-
className: "ui-dt-
|
|
3027
|
-
children: /* @__PURE__ */
|
|
3028
|
-
className: "ui-dt-
|
|
3029
|
-
|
|
3030
|
-
|
|
3031
|
-
children:
|
|
3032
|
-
|
|
3033
|
-
|
|
3034
|
-
|
|
3035
|
-
|
|
3036
|
-
|
|
3037
|
-
|
|
3038
|
-
|
|
3039
|
-
|
|
3040
|
-
|
|
3041
|
-
|
|
3042
|
-
|
|
3043
|
-
|
|
3044
|
-
|
|
3045
|
-
|
|
3046
|
-
|
|
3047
|
-
|
|
3048
|
-
|
|
3049
|
-
|
|
3050
|
-
|
|
3051
|
-
|
|
3052
|
-
|
|
3053
|
-
|
|
3054
|
-
|
|
3055
|
-
|
|
3056
|
-
|
|
3057
|
-
|
|
3058
|
-
|
|
3059
|
-
|
|
3060
|
-
|
|
3061
|
-
|
|
3062
|
-
|
|
3063
|
-
|
|
3064
|
-
|
|
3065
|
-
|
|
3066
|
-
|
|
3067
|
-
|
|
3068
|
-
|
|
3069
|
-
|
|
3070
|
-
|
|
3071
|
-
|
|
3072
|
-
|
|
3073
|
-
|
|
3074
|
-
|
|
3075
|
-
|
|
3076
|
-
|
|
3077
|
-
|
|
3078
|
-
|
|
3079
|
-
|
|
3080
|
-
|
|
3081
|
-
|
|
3082
|
-
|
|
3083
|
-
|
|
3084
|
-
|
|
3085
|
-
|
|
3086
|
-
|
|
3087
|
-
|
|
3088
|
-
|
|
3089
|
-
|
|
3090
|
-
|
|
3091
|
-
|
|
3092
|
-
|
|
3093
|
-
|
|
3094
|
-
|
|
3095
|
-
|
|
3096
|
-
|
|
3097
|
-
|
|
3098
|
-
|
|
3099
|
-
|
|
3100
|
-
|
|
3101
|
-
|
|
3111
|
+
className: cx("ui-dt-scroller", scrollMore && "has-more"),
|
|
3112
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
3113
|
+
className: "ui-dt-scroll",
|
|
3114
|
+
ref: scrollRef,
|
|
3115
|
+
onScroll,
|
|
3116
|
+
children: /* @__PURE__ */ jsxs("div", {
|
|
3117
|
+
className: "ui-dt-table",
|
|
3118
|
+
role: "table",
|
|
3119
|
+
"aria-label": p.label || p.caption,
|
|
3120
|
+
children: [
|
|
3121
|
+
head,
|
|
3122
|
+
/* @__PURE__ */ jsx("div", {
|
|
3123
|
+
ref: bodyRef,
|
|
3124
|
+
className: "ui-dt-body",
|
|
3125
|
+
role: "rowgroup",
|
|
3126
|
+
children: vis.length ? vis.map((x, i) => {
|
|
3127
|
+
const id = visIds[i];
|
|
3128
|
+
const on = !!sel[id];
|
|
3129
|
+
return /* @__PURE__ */ jsxs("div", {
|
|
3130
|
+
"data-rid": id,
|
|
3131
|
+
ref: (el) => {
|
|
3132
|
+
rowEls.current[id] = el;
|
|
3133
|
+
},
|
|
3134
|
+
role: "row",
|
|
3135
|
+
className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
|
|
3136
|
+
style: gridStyle,
|
|
3137
|
+
children: [
|
|
3138
|
+
selectable ? /* @__PURE__ */ jsx("div", {
|
|
3139
|
+
className: "ui-dt-cell ui-dt-sel",
|
|
3140
|
+
role: "cell",
|
|
3141
|
+
children: /* @__PURE__ */ jsx(RowCheck, {
|
|
3142
|
+
v: on,
|
|
3143
|
+
label: tr("選取第 {n} 筆", { n: start + i + 1 }),
|
|
3144
|
+
onClick: () => toggle([id], !on)
|
|
3145
|
+
})
|
|
3146
|
+
}) : null,
|
|
3147
|
+
shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
|
|
3148
|
+
role: "cell",
|
|
3149
|
+
"data-label": c.label,
|
|
3150
|
+
className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
|
|
3151
|
+
style: stickyStyle(ci),
|
|
3152
|
+
children: cell(x.r, c)
|
|
3153
|
+
}, c.key)),
|
|
3154
|
+
hasAct ? /* @__PURE__ */ jsx("div", {
|
|
3155
|
+
className: "ui-dt-cell ui-dt-acts",
|
|
3156
|
+
role: "cell",
|
|
3157
|
+
children: p.rowActions?.(x.r)
|
|
3158
|
+
}) : null
|
|
3159
|
+
]
|
|
3160
|
+
}, id);
|
|
3161
|
+
}) : /* @__PURE__ */ jsxs("div", {
|
|
3162
|
+
className: "ui-dt-empty",
|
|
3163
|
+
children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
|
|
3164
|
+
onClick: clearFilters,
|
|
3165
|
+
children: tr("清除篩選")
|
|
3166
|
+
}) }) : null]
|
|
3167
|
+
})
|
|
3168
|
+
}),
|
|
3169
|
+
p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
|
|
3170
|
+
className: "ui-dt-row ui-dt-total",
|
|
3171
|
+
role: "row",
|
|
3172
|
+
style: gridStyle,
|
|
3173
|
+
children: [
|
|
3174
|
+
selectable ? /* @__PURE__ */ jsx("div", {
|
|
3175
|
+
className: "ui-dt-cell",
|
|
3176
|
+
role: "cell"
|
|
3177
|
+
}) : null,
|
|
3178
|
+
shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
|
|
3179
|
+
role: "cell",
|
|
3180
|
+
className: cellClass(c, ci),
|
|
3181
|
+
style: stickyStyle(ci),
|
|
3182
|
+
children: total(c, ci)
|
|
3183
|
+
}, c.key)),
|
|
3184
|
+
hasAct ? /* @__PURE__ */ jsx("div", {
|
|
3185
|
+
className: "ui-dt-cell",
|
|
3186
|
+
role: "cell"
|
|
3187
|
+
}) : null
|
|
3188
|
+
]
|
|
3189
|
+
}) : null
|
|
3190
|
+
]
|
|
3191
|
+
})
|
|
3102
3192
|
})
|
|
3103
3193
|
}),
|
|
3104
|
-
|
|
3194
|
+
/* @__PURE__ */ jsx(ScrollHint, {
|
|
3195
|
+
show: overflows,
|
|
3196
|
+
done: scrolled
|
|
3197
|
+
}),
|
|
3198
|
+
pages > 1 ? /* @__PURE__ */ jsxs("div", {
|
|
3105
3199
|
className: "ui-dt-foot",
|
|
3106
3200
|
children: [/* @__PURE__ */ jsx("span", {
|
|
3107
3201
|
className: "ui-dt-range",
|
|
@@ -3114,7 +3208,7 @@ function DataTable(p) {
|
|
|
3114
3208
|
Math.min(list.length, start + pageSize),
|
|
3115
3209
|
format.number(list.length)
|
|
3116
3210
|
])
|
|
3117
|
-
}),
|
|
3211
|
+
}), /* @__PURE__ */ jsxs("nav", {
|
|
3118
3212
|
className: "ui-dt-pages",
|
|
3119
3213
|
"aria-label": tr("分頁"),
|
|
3120
3214
|
children: [
|
|
@@ -3142,7 +3236,7 @@ function DataTable(p) {
|
|
|
3142
3236
|
children: "›"
|
|
3143
3237
|
})
|
|
3144
3238
|
]
|
|
3145
|
-
})
|
|
3239
|
+
})]
|
|
3146
3240
|
}) : null
|
|
3147
3241
|
]
|
|
3148
3242
|
});
|
|
@@ -3885,30 +3979,18 @@ function LayerGraph(p) {
|
|
|
3885
3979
|
const edgeId = (e) => e.id ?? `${e.from}->${e.to}`;
|
|
3886
3980
|
const pickEdge = p.onSelectEdge;
|
|
3887
3981
|
const [hover, setHover] = React.useState(null);
|
|
3888
|
-
const
|
|
3889
|
-
const [more, setMore] = React.useState(false);
|
|
3890
|
-
const [scrolled, setScrolled] = React.useState(false);
|
|
3891
|
-
const [overflows, setOverflows] = React.useState(false);
|
|
3892
|
-
const measureScroll = React.useCallback(() => {
|
|
3893
|
-
const el = scroller.current;
|
|
3894
|
-
if (!el) return;
|
|
3895
|
-
const wide = el.scrollWidth > el.clientWidth + 1;
|
|
3896
|
-
setOverflows(wide);
|
|
3897
|
-
setMore(wide && el.scrollLeft + el.clientWidth < el.scrollWidth - 1);
|
|
3898
|
-
}, []);
|
|
3899
|
-
React.useLayoutEffect(() => {
|
|
3900
|
-
const el = scroller.current;
|
|
3901
|
-
if (!el) return;
|
|
3902
|
-
measureScroll();
|
|
3903
|
-
const ro = new ResizeObserver(measureScroll);
|
|
3904
|
-
ro.observe(el);
|
|
3905
|
-
if (el.firstElementChild) ro.observe(el.firstElementChild);
|
|
3906
|
-
return () => ro.disconnect();
|
|
3907
|
-
}, [measureScroll]);
|
|
3982
|
+
const { ref: scrollRef, more: scrollMore, overflows, scrolled, onScroll } = useScrollHint();
|
|
3908
3983
|
const selEdge = pickEdge && edges.find((e) => edgeId(e) === p.selectedEdge) || null;
|
|
3909
|
-
const
|
|
3984
|
+
const uses = {};
|
|
3985
|
+
for (const e of p.edges) if (sharedIds.has(e.to) && !sharedIds.has(e.from)) (uses[e.to] ??= {})[e.from] = (uses[e.to]?.[e.from] ?? 0) + (e.count || 0);
|
|
3986
|
+
const selShared = !selEdge && sel != null && sharedIds.has(sel) ? sel : null;
|
|
3987
|
+
const related = (e) => selEdge ? e === selEdge : !!sel && !selShared && (e.from === sel || e.to === sel);
|
|
3910
3988
|
const focus = !!sel || !!selEdge;
|
|
3911
|
-
const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
|
|
3989
|
+
const near = (id) => selEdge ? id === selEdge.from || id === selEdge.to : selShared ? id === selShared || id in (uses[selShared] ?? {}) : !sel || id === sel || edges.some((e) => related(e) && (e.from === id || e.to === id));
|
|
3990
|
+
const pick = (id, on) => {
|
|
3991
|
+
if (!on && p.selectedEdge != null) pickEdge?.(null);
|
|
3992
|
+
p.onSelect?.(on ? null : id);
|
|
3993
|
+
};
|
|
3912
3994
|
const nameOf = (id) => all.find((n) => n.id === id)?.name || id;
|
|
3913
3995
|
const countText = (e) => (p.countLabel ?? tr("{n} 次")).replace("{n}", String(e.count ?? 0));
|
|
3914
3996
|
const choose = (e) => {
|
|
@@ -3974,7 +4056,7 @@ function LayerGraph(p) {
|
|
|
3974
4056
|
d,
|
|
3975
4057
|
role: "button",
|
|
3976
4058
|
tabIndex: 0,
|
|
3977
|
-
"aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)}`,
|
|
4059
|
+
"aria-label": `${nameOf(e.from)} → ${nameOf(e.to)},${(e.inferred ? e.label || p.inferredLabel || tr("推測") : countText(e)).replace(/`/g, "")}`,
|
|
3978
4060
|
"aria-pressed": picked,
|
|
3979
4061
|
onClick: (ev) => {
|
|
3980
4062
|
ev.stopPropagation();
|
|
@@ -4047,10 +4129,12 @@ function LayerGraph(p) {
|
|
|
4047
4129
|
}, "l" + m.idx));
|
|
4048
4130
|
});
|
|
4049
4131
|
const sizeText = p.sizeLabel ?? tr("{n} 個項目");
|
|
4132
|
+
const useText = p.useLabel ?? tr("使用 {n} 次");
|
|
4050
4133
|
const nodes = main.map((n) => {
|
|
4051
4134
|
const q = pos[n.id];
|
|
4052
4135
|
const on = n.id === sel;
|
|
4053
4136
|
const size = sizeOf(n);
|
|
4137
|
+
const used = selShared ? uses[selShared]?.[n.id] : void 0;
|
|
4054
4138
|
return /* @__PURE__ */ jsxs("button", {
|
|
4055
4139
|
type: "button",
|
|
4056
4140
|
className: cx("ui-lg-node", on && "is-selected", !near(n.id) && "is-dim"),
|
|
@@ -4061,13 +4145,16 @@ function LayerGraph(p) {
|
|
|
4061
4145
|
height: NH
|
|
4062
4146
|
},
|
|
4063
4147
|
"aria-pressed": p.onSelect ? on : void 0,
|
|
4064
|
-
onClick: p.onSelect ? () =>
|
|
4065
|
-
|
|
4066
|
-
|
|
4067
|
-
|
|
4068
|
-
|
|
4069
|
-
|
|
4070
|
-
|
|
4148
|
+
onClick: p.onSelect ? () => pick(n.id, on) : void 0,
|
|
4149
|
+
children: [/* @__PURE__ */ jsxs("span", {
|
|
4150
|
+
className: "ui-lg-head",
|
|
4151
|
+
children: [/* @__PURE__ */ jsx("span", {
|
|
4152
|
+
className: "ui-lg-name",
|
|
4153
|
+
children: n.name || n.id
|
|
4154
|
+
}), used ? /* @__PURE__ */ jsx("span", {
|
|
4155
|
+
className: "ui-lg-use",
|
|
4156
|
+
children: monoNums(useText.replace("{n}", ""), [used])
|
|
4157
|
+
}) : null]
|
|
4071
4158
|
}), size != null ? /* @__PURE__ */ jsxs("span", {
|
|
4072
4159
|
className: "ui-lg-size",
|
|
4073
4160
|
children: [/* @__PURE__ */ jsx("span", {
|
|
@@ -4082,36 +4169,34 @@ function LayerGraph(p) {
|
|
|
4082
4169
|
}, n.id);
|
|
4083
4170
|
});
|
|
4084
4171
|
const sharedMeta = p.sharedMeta ?? tr("{a} 個項目使用,共 {b} 次");
|
|
4085
|
-
const
|
|
4086
|
-
const
|
|
4087
|
-
|
|
4088
|
-
|
|
4089
|
-
|
|
4090
|
-
|
|
4091
|
-
|
|
4092
|
-
|
|
4093
|
-
|
|
4172
|
+
const sharedBoxes = shared.map((s) => {
|
|
4173
|
+
const by = uses[s.id] ?? {};
|
|
4174
|
+
const total = Object.values(by).reduce((a, b) => a + b, 0);
|
|
4175
|
+
const on = s.id === sel;
|
|
4176
|
+
const dim = !!selEdge || sel != null && !on && (selShared != null || !(sel in by));
|
|
4177
|
+
return /* @__PURE__ */ jsxs("button", {
|
|
4178
|
+
type: "button",
|
|
4179
|
+
className: cx("ui-lg-node", "ui-lg-chip", on && "is-selected", dim && "is-dim"),
|
|
4180
|
+
"aria-pressed": p.onSelect ? on : void 0,
|
|
4181
|
+
onClick: p.onSelect ? () => pick(s.id, on) : void 0,
|
|
4094
4182
|
children: [/* @__PURE__ */ jsx("span", {
|
|
4095
4183
|
className: "ui-lg-name",
|
|
4096
4184
|
children: s.name || s.id
|
|
4097
4185
|
}), /* @__PURE__ */ jsx("span", {
|
|
4098
4186
|
className: "ui-lg-shared-meta",
|
|
4099
|
-
children: monoNums(sharedMeta.replace("{a}", "").replace("{b}", ""), [
|
|
4187
|
+
children: monoNums(sharedMeta.replace("{a}", "").replace("{b}", ""), [Object.keys(by).length, total])
|
|
4100
4188
|
})]
|
|
4101
4189
|
}, s.id);
|
|
4102
4190
|
});
|
|
4103
4191
|
return /* @__PURE__ */ jsxs("div", {
|
|
4104
4192
|
className: cx("ui-graph ui-lg", p.className),
|
|
4105
4193
|
children: [
|
|
4106
|
-
/* @__PURE__ */
|
|
4107
|
-
className: cx("ui-lg-scroller",
|
|
4108
|
-
children:
|
|
4194
|
+
/* @__PURE__ */ jsx("div", {
|
|
4195
|
+
className: cx("ui-lg-scroller", scrollMore && "has-more"),
|
|
4196
|
+
children: /* @__PURE__ */ jsx("div", {
|
|
4109
4197
|
className: "ui-lg-scroll",
|
|
4110
|
-
ref:
|
|
4111
|
-
onScroll
|
|
4112
|
-
setScrolled(true);
|
|
4113
|
-
measureScroll();
|
|
4114
|
-
},
|
|
4198
|
+
ref: scrollRef,
|
|
4199
|
+
onScroll,
|
|
4115
4200
|
children: /* @__PURE__ */ jsxs("div", {
|
|
4116
4201
|
className: "ui-lg-canvas",
|
|
4117
4202
|
style: {
|
|
@@ -4140,30 +4225,30 @@ function LayerGraph(p) {
|
|
|
4140
4225
|
}) : null
|
|
4141
4226
|
]
|
|
4142
4227
|
})
|
|
4143
|
-
})
|
|
4144
|
-
|
|
4145
|
-
|
|
4146
|
-
|
|
4147
|
-
|
|
4148
|
-
size: 14
|
|
4149
|
-
}), tr("左右滑動")]
|
|
4150
|
-
}) : null]
|
|
4228
|
+
})
|
|
4229
|
+
}),
|
|
4230
|
+
/* @__PURE__ */ jsx(ScrollHint, {
|
|
4231
|
+
show: overflows,
|
|
4232
|
+
done: scrolled
|
|
4151
4233
|
}),
|
|
4152
4234
|
shared.length ? /* @__PURE__ */ jsxs("div", {
|
|
4153
4235
|
className: "ui-lg-shared",
|
|
4154
4236
|
children: [/* @__PURE__ */ jsx("div", {
|
|
4155
4237
|
className: "ui-lg-shared-title",
|
|
4156
4238
|
children: p.sharedLabel || tr("共用項目")
|
|
4157
|
-
}),
|
|
4239
|
+
}), /* @__PURE__ */ jsx("div", {
|
|
4240
|
+
className: "ui-lg-chips",
|
|
4241
|
+
children: sharedBoxes
|
|
4242
|
+
})]
|
|
4158
4243
|
}) : null,
|
|
4159
|
-
p.legend === false ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [{
|
|
4244
|
+
p.legend === false || !p.legendItems && !edges.some((e) => pos[e.from] && pos[e.to]) ? null : /* @__PURE__ */ jsx(GraphLegend, { items: p.legendItems || [...edges.some((e) => !e.inferred && pos[e.from] && pos[e.to]) ? [{
|
|
4160
4245
|
type: "weight",
|
|
4161
4246
|
label: "次數越多線越粗"
|
|
4162
|
-
}, {
|
|
4247
|
+
}] : [], ...edges.some((e) => e.inferred && pos[e.from] && pos[e.to]) ? [{
|
|
4163
4248
|
type: "inferred",
|
|
4164
4249
|
label: p.inferredLabel || "推測的關係",
|
|
4165
4250
|
text: p.inferredText
|
|
4166
|
-
}] })
|
|
4251
|
+
}] : []] })
|
|
4167
4252
|
]
|
|
4168
4253
|
});
|
|
4169
4254
|
}
|