@robert-stackflow/oneui 0.6.43 → 0.6.45

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/CHANGELOG.md CHANGED
@@ -1,3 +1,13 @@
1
+ ## 0.6.45
2
+
3
+ - TableOfContents 在外层容器管理滚动时,将当前章节自动滚动到容器可见范围;窗口尺寸变化时重新检查,保留焦点并避免滚动正文,支持减少动态效果偏好。
4
+
5
+ ## 0.6.44
6
+
7
+ - Lightbox 按图片真实宽高比与可用画布尺寸显示加载骨架;窗口变化时同步适配。未提供有效尺寸时使用紧凑加载指示。
8
+ - 修正加载失败后点击重试可能被误判为滑动切图的问题。
9
+ - IconButton 支持 tooltip={false},保留可访问名称并避免紧凑浮层内重复弹出提示。
10
+
1
11
  ## 0.6.43
2
12
 
3
13
  - Lightbox 加载骨架保持矩形,避免百分比圆角形成椭圆。
package/README.md CHANGED
@@ -328,7 +328,7 @@ Menu 支持 iconOnly:`<Menu iconOnly label="更多操作" items={items} />`
328
328
 
329
329
  ### Lightbox
330
330
 
331
- `Lightbox` is a controlled image viewer: pass `open`, `items`, `index`, `onIndexChange` and `onClose`. Each item has a stable `id`, `src`, `alt` and optional `caption`, `thumbnailSrc`, `width` and `height`. The optional `sourceElement(item)` resolves the original image for Hero motion; `onLocate(item)` runs after exit and scroll unlocking. Supply `labels` for localization.
331
+ `Lightbox` is a controlled image viewer: pass `open`, `items`, `index`, `onIndexChange` and `onClose`. Each item has a stable `id`, `src`, `alt` and optional `caption`, `thumbnailSrc`, `width` and `height`. The optional `sourceElement(item)` resolves the original image for Hero motion; `onLocate(item)` runs after exit and scroll unlocking. Supply `labels` for localization. Provide valid `width` and `height` for an aspect-correct loading skeleton fitted to the canvas; images without known dimensions use a compact loading indicator.
332
332
 
333
333
  The viewer uses an opaque black canvas with light controls independently of the document color mode. It supports captions, thumbnail navigation, non-wrapping previous/next, arrow keys, Escape, original-size zoom, bounded dragging, touch pinch/swipe and manual retry of the original URL. A single image hides navigation. Only adjacent full images are preloaded. It uses native modal isolation and shared OneUI focus, scroll lock and motion; reduced motion and missing/offscreen source elements use a quiet fallback. Keep the component mounted through exit and retain the selected index. Resolve resource permissions and document anchors in the host, not inside OneUI.
334
334
 
@@ -1,5 +1,5 @@
1
1
  import type { ComponentPropsWithRef, ReactNode } from "react";
2
- export declare function IconButton({ label, loading, children, text, variant, size, disclosure, ...props }: ComponentPropsWithRef<"button"> & {
2
+ export declare function IconButton({ label, loading, children, text, variant, size, disclosure, tooltip, ...props }: ComponentPropsWithRef<"button"> & {
3
3
  label: string;
4
4
  loading?: boolean;
5
5
  /** Visible text or count inside the same hover, focus and click target as the icon. */
@@ -8,4 +8,6 @@ export declare function IconButton({ label, loading, children, text, variant, si
8
8
  size?: "small" | "normal";
9
9
  /** Add a spaced disclosure chevron, driven by aria-expanded. */
10
10
  disclosure?: boolean;
11
+ /** Keep the accessible label while omitting redundant hover text in compact surfaces. */
12
+ tooltip?: boolean;
11
13
  }): import("react").JSX.Element;
@@ -12,9 +12,10 @@ function IconButton({
12
12
  variant = "ghost",
13
13
  size = "normal",
14
14
  disclosure = false,
15
+ tooltip = true,
15
16
  ...props
16
17
  }) {
17
- return /* @__PURE__ */ jsx(Tooltip, { content: label, children: /* @__PURE__ */ jsxs(
18
+ return /* @__PURE__ */ jsx(Tooltip, { content: label, disabled: !tooltip, children: /* @__PURE__ */ jsxs(
18
19
  "button",
19
20
  {
20
21
  type: "button",
@@ -19,6 +19,7 @@ import {
19
19
  } from "lucide-react";
20
20
  import { IconButton } from "./IconButton.js";
21
21
  import { Skeleton } from "./Skeleton.js";
22
+ import { Spinner } from "./Spinner.js";
22
23
  import { usePortalRoot } from "./usePortalRoot.js";
23
24
  import { useModalScrollLock } from "./useModalScrollLock.js";
24
25
  import { useModalFocus } from "./useModalFocus.js";
@@ -70,6 +71,34 @@ function Lightbox(props) {
70
71
  const [closing, setClosing] = useState(false), [status, setStatus] = useState("loading");
71
72
  const [zoom, setZoom] = useState(1), [pan, setPan] = useState({ x: 0, y: 0 });
72
73
  const itemKey = item ? item.id + item.src : "";
74
+ const [loadingSize, setLoadingSize] = useState(null);
75
+ useLayoutEffect(() => {
76
+ const stage = stageRef.current;
77
+ const width = item?.width, height = item?.height;
78
+ if (!open || !stage || !width || !height || !Number.isFinite(width) || !Number.isFinite(height) || width <= 0 || height <= 0) {
79
+ setLoadingSize(null);
80
+ return;
81
+ }
82
+ const measure = () => {
83
+ const scale = Math.min(
84
+ 1,
85
+ stage.clientWidth / width,
86
+ stage.clientHeight / height
87
+ );
88
+ const next = {
89
+ key: itemKey,
90
+ width: width * scale,
91
+ height: height * scale
92
+ };
93
+ setLoadingSize(
94
+ (previous) => previous?.key === next.key && previous.width === next.width && previous.height === next.height ? previous : next
95
+ );
96
+ };
97
+ measure();
98
+ const observer = new ResizeObserver(measure);
99
+ observer.observe(stage);
100
+ return () => observer.disconnect();
101
+ }, [open, portal, itemKey, item?.width, item?.height]);
73
102
  const [slide, setSlide] = useState({ key: itemKey, index, current: item, direction: 0 });
74
103
  if (slide.key !== itemKey)
75
104
  setSlide({
@@ -370,6 +399,7 @@ function Lightbox(props) {
370
399
  );
371
400
  };
372
401
  const pointerEnd = (event) => {
402
+ if (!pointers.current.has(event.pointerId)) return;
373
403
  const start = gesture.current, dx = event.clientX - start.x, dy = event.clientY - start.y;
374
404
  pointers.current.delete(event.pointerId);
375
405
  if (event.type !== "pointercancel" && !start.multi && zoom === 1 && Math.abs(dx) > 64 && Math.abs(dx) > Math.abs(dy) * 1.2)
@@ -501,7 +531,17 @@ function Lightbox(props) {
501
531
  );
502
532
  }
503
533
  ),
504
- status === "loading" && /* @__PURE__ */ jsx("div", { className: s.feedback, role: "status", "aria-label": t.loading, children: /* @__PURE__ */ jsx(Skeleton, { width: "min(55vw, 560px)", height: "min(45vh, 360px)" }) }),
534
+ status === "loading" && /* @__PURE__ */ jsx("div", { className: s.feedback, role: "status", "aria-label": t.loading, children: loadingSize?.key === itemKey ? /* @__PURE__ */ jsx(
535
+ "div",
536
+ {
537
+ className: s.loadingImage,
538
+ style: {
539
+ width: loadingSize.width,
540
+ height: loadingSize.height
541
+ },
542
+ children: /* @__PURE__ */ jsx(Skeleton, { width: "100%", height: "100%" })
543
+ }
544
+ ) : /* @__PURE__ */ jsx(Spinner, { size: 22, decorative: true }) }),
505
545
  status === "error" && /* @__PURE__ */ jsxs("div", { className: s.feedback, role: "status", children: [
506
546
  /* @__PURE__ */ jsx("span", { children: t.error }),
507
547
  /* @__PURE__ */ jsx(
@@ -119,6 +119,11 @@
119
119
  text-align: center;
120
120
  overflow-wrap: anywhere;
121
121
  }
122
+ .loadingImage {
123
+ flex-shrink: 0;
124
+ max-width: 100%;
125
+ max-height: 100%;
126
+ }
122
127
  .thumbnails {
123
128
  position: relative;
124
129
  display: flex;
@@ -220,19 +220,31 @@ function TableOfContents({
220
220
  }
221
221
  }, [diagram.path, variant, railLayout]);
222
222
  useLayoutEffect(() => {
223
- const node = list.current, viewport = node?.parentElement;
224
- if (!viewport || !first || !last || !open && variant === "rail") return;
225
- if (first.top < viewport.scrollTop)
226
- viewport.scrollTo({
227
- top: Math.max(0, first.top - 12),
228
- behavior: reducedMotion() ? "auto" : "smooth"
229
- });
230
- else if (last.bottom > viewport.scrollTop + viewport.clientHeight)
231
- viewport.scrollTo({
232
- top: last.bottom - viewport.clientHeight + 12,
233
- behavior: reducedMotion() ? "auto" : "smooth"
234
- });
235
- }, [first, last, open, variant]);
223
+ const node = list.current;
224
+ if (!node || !open && variant === "rail") return;
225
+ const viewport = scrollable ? node.parentElement : scrollParent(node);
226
+ const selected = node.querySelector(
227
+ '[aria-current="location"]'
228
+ );
229
+ if (!viewport || !selected) return;
230
+ const reveal = () => {
231
+ if (!viewport.clientHeight || !selected.getClientRects().length) return;
232
+ const bounds = viewport.getBoundingClientRect();
233
+ const item = selected.getBoundingClientRect();
234
+ const top = bounds.top + viewport.clientTop + 12;
235
+ const bottom = bounds.top + viewport.clientTop + viewport.clientHeight - 12;
236
+ const delta = item.top < top ? item.top - top : item.bottom > bottom ? item.bottom - bottom : 0;
237
+ if (delta)
238
+ viewport.scrollTo({
239
+ top: viewport.scrollTop + delta,
240
+ behavior: reducedMotion() ? "auto" : "smooth"
241
+ });
242
+ };
243
+ reveal();
244
+ const resize = new ResizeObserver(reveal);
245
+ resize.observe(viewport);
246
+ return () => resize.disconnect();
247
+ }, [current, diagram.path, open, variant, scrollable]);
236
248
  useLayoutEffect(() => {
237
249
  if (variant !== "rail" || railLayout !== "preview" || !open) return;
238
250
  const node = list.current, viewport = node?.parentElement;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@robert-stackflow/oneui",
3
- "version": "0.6.43",
3
+ "version": "0.6.45",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [