@seanyeh77/ui 0.12.0 → 0.12.1

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
@@ -2396,7 +2396,11 @@ function CommandPalette(props) {
2396
2396
  if (!said) return;
2397
2397
  const t = setTimeout(() => announce(said), 400);
2398
2398
  return () => clearTimeout(t);
2399
- }, [said]);
2399
+ }, [
2400
+ said,
2401
+ query,
2402
+ loading
2403
+ ]);
2400
2404
  return /* @__PURE__ */ jsx(Dialog$1.Root, {
2401
2405
  open,
2402
2406
  onOpenChange,
@@ -2557,6 +2561,20 @@ function Tabs({ items, value, onChange, label, unit, className }) {
2557
2561
  const [box, setBox] = React.useState(null);
2558
2562
  const [forward, setForward] = React.useState(true);
2559
2563
  const [moving, bump] = useMoving();
2564
+ const [more, setMore] = React.useState({
2565
+ left: false,
2566
+ right: false
2567
+ });
2568
+ const edges = React.useCallback(() => {
2569
+ const el = track.current;
2570
+ if (!el) return;
2571
+ const left = el.scrollLeft > 1;
2572
+ const right = el.scrollLeft + el.clientWidth < el.scrollWidth - 1;
2573
+ setMore((m) => m.left === left && m.right === right ? m : {
2574
+ left,
2575
+ right
2576
+ });
2577
+ }, []);
2560
2578
  useFocusRescue(track, () => refs.current[Math.max(0, items.findIndex((t) => t.id === value))]);
2561
2579
  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.");
2562
2580
  const idx = Math.max(0, items.findIndex((t) => t.id === value));
@@ -2564,16 +2582,25 @@ function Tabs({ items, value, onChange, label, unit, className }) {
2564
2582
  const el = refs.current[idx];
2565
2583
  const tr = track.current;
2566
2584
  if (!el || !tr) return;
2567
- const measure = () => setBox({
2568
- left: el.offsetLeft,
2569
- right: tr.clientWidth - el.offsetLeft - el.offsetWidth
2570
- });
2585
+ const measure = () => {
2586
+ setBox({
2587
+ left: el.offsetLeft,
2588
+ right: tr.clientWidth - el.offsetLeft - el.offsetWidth
2589
+ });
2590
+ edges();
2591
+ };
2571
2592
  measure();
2593
+ if (el.offsetLeft < tr.scrollLeft) tr.scrollLeft = el.offsetLeft - 4;
2594
+ else if (el.offsetLeft + el.offsetWidth > tr.scrollLeft + tr.clientWidth) tr.scrollLeft = el.offsetLeft + el.offsetWidth - tr.clientWidth + 4;
2572
2595
  const ro = new ResizeObserver(measure);
2573
2596
  ro.observe(tr);
2574
2597
  for (const t of refs.current) if (t) ro.observe(t);
2575
2598
  return () => ro.disconnect();
2576
- }, [idx, items.length]);
2599
+ }, [
2600
+ idx,
2601
+ items.length,
2602
+ edges
2603
+ ]);
2577
2604
  const go = (i) => {
2578
2605
  if (i === idx || !items[i]) return;
2579
2606
  setForward(i > idx);
@@ -2583,9 +2610,10 @@ function Tabs({ items, value, onChange, label, unit, className }) {
2583
2610
  };
2584
2611
  return /* @__PURE__ */ jsxs("div", {
2585
2612
  ref: track,
2586
- className: cx("ui-tabs", className),
2613
+ className: cx("ui-tabs", more.left && "has-more-left", more.right && "has-more-right", className),
2587
2614
  role: "tablist",
2588
2615
  "aria-label": label,
2616
+ onScroll: edges,
2589
2617
  children: [box ? /* @__PURE__ */ jsx("span", {
2590
2618
  className: "ui-tabs-ind",
2591
2619
  "aria-hidden": "true",
@@ -5348,9 +5376,20 @@ function LayerGraph(p) {
5348
5376
  ]);
5349
5377
  const hits = (x0, x1, y0, y1) => placed.some((q) => x0 < q[1] + (q[4] || 0) && q[0] < x1 + (q[4] || 0) && y0 < q[3] && q[2] < y1);
5350
5378
  const cross = (q, x0, lw, y0, y1) => x0 < q[1] - 1 && q[0] + 1 < x0 + lw && y0 < q[3] - 1 && q[2] + 1 < y1;
5351
- const alongLine = (m) => {
5379
+ const gapTo = (b, x0, lw, y0, y1) => Math.hypot(Math.max(0, b[0] - (x0 + lw), x0 - b[1]), Math.max(0, b[2] - y1, y0 - b[3]));
5380
+ const alongLine = (m, own = false) => {
5352
5381
  const pts = ptsOf[m.idx] ?? [];
5353
- const ok = (x0, lw, y0, y1) => x0 >= PAD / 2 && x0 + lw <= W - PAD / 2 && y0 >= 2 && y1 <= H - 2 && !hits(x0 - 2, x0 + lw + 2, y0 - 2, y1 + 2) && !boxRects.some((q) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : x0 < sg.box[1] + 2 && sg.box[0] < x0 + lw + 2 && y0 < sg.box[3] + 2 && sg.box[2] < y1 + 2);
5382
+ const mine = (x0, lw, y0, y1) => {
5383
+ let self = Infinity;
5384
+ let other = Infinity;
5385
+ for (const sg of segs) {
5386
+ const d = gapTo(sg.box, x0, lw, y0, y1);
5387
+ if (sg.idx === m.idx) self = Math.min(self, d);
5388
+ else other = Math.min(other, d);
5389
+ }
5390
+ return self + 4 < other && other >= 8;
5391
+ };
5392
+ const ok = (x0, lw, y0, y1) => (!own || mine(x0, lw, y0, y1)) && x0 >= PAD / 2 && x0 + lw <= W - PAD / 2 && y0 >= 2 && y1 <= H - 2 && !hits(x0 - 2, x0 + lw + 2, y0 - 2, y1 + 2) && !boxRects.some((q) => x0 < q[1] + 4 && q[0] < x0 + lw + 4 && y0 < q[3] + 4 && q[2] < y1 + 4) && !segs.some((sg) => sg.idx === m.idx ? cross(sg.box, x0, lw, y0, y1) : x0 < sg.box[1] + 2 && sg.box[0] < x0 + lw + 2 && y0 < sg.box[3] + 2 && sg.box[2] < y1 + 2);
5354
5393
  for (const lines of wraps(m.text)) {
5355
5394
  const lw = Math.ceil(Math.max(...lines.map(labelWidth)));
5356
5395
  const lh = lines.length * 16;
@@ -5431,6 +5470,23 @@ function LayerGraph(p) {
5431
5470
  return;
5432
5471
  }
5433
5472
  if (m.up) {
5473
+ const p0 = ptsOf[m.idx]?.[0];
5474
+ const near = p0 ? alongLine({
5475
+ ...m,
5476
+ tx: p0[0],
5477
+ ty: p0[1]
5478
+ }, true) : null;
5479
+ if (near) {
5480
+ placed.push([
5481
+ near.x0,
5482
+ near.x0 + near.lw,
5483
+ near.top - near.lh / 2 - 4,
5484
+ near.top + near.lh / 2 + 4,
5485
+ 6
5486
+ ]);
5487
+ labels.push(labelEl(m, near.x0, near.top, near.lines));
5488
+ return;
5489
+ }
5434
5490
  const x0Of = (lw) => Math.max(PAD / 2, Math.min(W - PAD / 2 - lw, m.left ? m.tx - lw : m.tx));
5435
5491
  const start0 = Math.max(10, Math.min(H - 10, m.ty));
5436
5492
  const find = (x0, lw, lh, withLines) => {