@robert-stackflow/oneui 0.6.44 → 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,7 @@
1
+ ## 0.6.45
2
+
3
+ - TableOfContents 在外层容器管理滚动时,将当前章节自动滚动到容器可见范围;窗口尺寸变化时重新检查,保留焦点并避免滚动正文,支持减少动态效果偏好。
4
+
1
5
  ## 0.6.44
2
6
 
3
7
  - Lightbox 按图片真实宽高比与可用画布尺寸显示加载骨架;窗口变化时同步适配。未提供有效尺寸时使用紧凑加载指示。
@@ -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.44",
3
+ "version": "0.6.45",
4
4
  "description": "OneUI React components, application shell and portable visual themes",
5
5
  "type": "module",
6
6
  "sideEffects": [