@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/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-DDglckmU.js";
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, { children: [
582
- /* @__PURE__ */ jsx(Tooltip$1.Trigger, {
583
- delay: 0,
584
- render: children,
585
- "aria-describedby": describe ? id : void 0
586
- }),
587
- describe ? /* @__PURE__ */ jsx("span", {
588
- id,
589
- hidden: true,
590
- children: label
591
- }) : null,
592
- /* @__PURE__ */ jsx(Tooltip$1.Portal, { children: /* @__PURE__ */ jsx(Tooltip$1.Positioner, {
593
- side,
594
- sideOffset: 8,
595
- className: "ui-tooltip-positioner",
596
- children: /* @__PURE__ */ jsxs(Tooltip$1.Popup, {
597
- className: "ui-tooltip",
598
- children: [label, /* @__PURE__ */ jsx(Tooltip$1.Arrow, { className: "ui-tooltip-arrow" })]
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__ */ jsx("span", {
1883
+ }), languageLabel !== false && lang !== "plain" ? /* @__PURE__ */ jsxs("span", {
1880
1884
  className: "ui-cv-lang",
1881
- children: languageLabel || LANGUAGE_NAMES[lang] || lang
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__ */ jsx("span", {
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: on phone cards at most 2 lines with 「顯示全部」. */
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
- if (!el || open) return;
2539
- const check = () => setOver(el.scrollHeight > el.clientHeight + 1);
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
- window.addEventListener("resize", check);
2542
- return () => window.removeEventListener("resize", check);
2543
- }, [open, children]);
2544
- return /* @__PURE__ */ jsxs("span", {
2545
- className: "ui-dt-long",
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__ */ jsx("span", {
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-scroll",
3027
- children: /* @__PURE__ */ jsxs("div", {
3028
- className: "ui-dt-table",
3029
- role: "table",
3030
- "aria-label": p.label || p.caption,
3031
- children: [
3032
- head,
3033
- /* @__PURE__ */ jsx("div", {
3034
- ref: bodyRef,
3035
- className: "ui-dt-body",
3036
- role: "rowgroup",
3037
- children: vis.length ? vis.map((x, i) => {
3038
- const id = visIds[i];
3039
- const on = !!sel[id];
3040
- return /* @__PURE__ */ jsxs("div", {
3041
- "data-rid": id,
3042
- ref: (el) => {
3043
- rowEls.current[id] = el;
3044
- },
3045
- role: "row",
3046
- className: cx("ui-dt-row", i % 2 && "is-even", on && "is-selected", selectable && "has-sel"),
3047
- style: gridStyle,
3048
- children: [
3049
- selectable ? /* @__PURE__ */ jsx("div", {
3050
- className: "ui-dt-cell ui-dt-sel",
3051
- role: "cell",
3052
- children: /* @__PURE__ */ jsx(RowCheck, {
3053
- v: on,
3054
- label: tr("選取第 {n} 筆", { n: start + i + 1 }),
3055
- onClick: () => toggle([id], !on)
3056
- })
3057
- }) : null,
3058
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3059
- role: "cell",
3060
- "data-label": c.label,
3061
- className: cellClass(c, ci, c.long && "is-long", mobileClass(c, ci)),
3062
- style: stickyStyle(ci),
3063
- children: cell(x.r, c)
3064
- }, c.key)),
3065
- hasAct ? /* @__PURE__ */ jsx("div", {
3066
- className: "ui-dt-cell ui-dt-acts",
3067
- role: "cell",
3068
- children: p.rowActions?.(x.r)
3069
- }) : null
3070
- ]
3071
- }, id);
3072
- }) : /* @__PURE__ */ jsxs("div", {
3073
- className: "ui-dt-empty",
3074
- children: [p.emptyText || tr("沒有符合的資料"), q || activeN ? /* @__PURE__ */ jsx("div", { children: /* @__PURE__ */ jsx(Button, {
3075
- onClick: clearFilters,
3076
- children: tr("清除篩選")
3077
- }) }) : null]
3078
- })
3079
- }),
3080
- p.totals && list.length ? /* @__PURE__ */ jsxs("div", {
3081
- className: "ui-dt-row ui-dt-total",
3082
- role: "row",
3083
- style: gridStyle,
3084
- children: [
3085
- selectable ? /* @__PURE__ */ jsx("div", {
3086
- className: "ui-dt-cell",
3087
- role: "cell"
3088
- }) : null,
3089
- shownCols.map((c, ci) => /* @__PURE__ */ jsx("div", {
3090
- role: "cell",
3091
- className: cellClass(c, ci),
3092
- style: stickyStyle(ci),
3093
- children: total(c, ci)
3094
- }, c.key)),
3095
- hasAct ? /* @__PURE__ */ jsx("div", {
3096
- className: "ui-dt-cell",
3097
- role: "cell"
3098
- }) : null
3099
- ]
3100
- }) : null
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
- list.length > 0 ? /* @__PURE__ */ jsxs("div", {
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
- }), pages > 1 ? /* @__PURE__ */ jsxs("nav", {
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
- }) : null]
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 scroller = React.useRef(null);
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 related = (e) => selEdge ? e === selEdge : !!sel && (e.from === sel || e.to === sel);
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
- if (!on && p.selectedEdge != null) pickEdge?.(null);
4066
- p.onSelect?.(on ? null : n.id);
4067
- } : void 0,
4068
- children: [/* @__PURE__ */ jsx("span", {
4069
- className: "ui-lg-name",
4070
- children: n.name || n.id
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 sharedRows = shared.map((s) => {
4086
- const callers = /* @__PURE__ */ new Set();
4087
- let total = 0;
4088
- for (const e of p.edges) if (e.to === s.id && !sharedIds.has(e.from)) {
4089
- callers.add(e.from);
4090
- total += e.count || 0;
4091
- }
4092
- return /* @__PURE__ */ jsxs("div", {
4093
- className: "ui-lg-shared-row",
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}", ""), [callers.size, total])
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__ */ jsxs("div", {
4107
- className: cx("ui-lg-scroller", more && "has-more"),
4108
- children: [/* @__PURE__ */ jsx("div", {
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: scroller,
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
- }), overflows && !scrolled ? /* @__PURE__ */ jsxs("span", {
4144
- className: "ui-lg-hint",
4145
- "aria-hidden": "true",
4146
- children: [/* @__PURE__ */ jsx(Icon, {
4147
- name: "arrow-right",
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
- }), sharedRows]
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
  }