@robert-stackflow/oneui 0.6.44 → 0.6.46
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 +8 -0
- package/components/TableOfContents.js +77 -51
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,11 @@
|
|
|
1
|
+
## 0.6.46
|
|
2
|
+
|
|
3
|
+
- TableOfContents 修复快速滚动跨过多个标题、或处在长章节之间时高亮停留旧章节的问题;滚动事件按动画帧合并,与章节观察器共用同步逻辑。
|
|
4
|
+
|
|
5
|
+
## 0.6.45
|
|
6
|
+
|
|
7
|
+
- TableOfContents 在外层容器管理滚动时,将当前章节自动滚动到容器可见范围;窗口尺寸变化时重新检查,保留焦点并避免滚动正文,支持减少动态效果偏好。
|
|
8
|
+
|
|
1
9
|
## 0.6.44
|
|
2
10
|
|
|
3
11
|
- Lightbox 按图片真实宽高比与可用画布尺寸显示加载骨架;窗口变化时同步适配。未提供有效尺寸时使用紧凑加载指示。
|
|
@@ -116,46 +116,60 @@ function TableOfContents({
|
|
|
116
116
|
const headings = entries.map((entry) => document.getElementById(entry.id)).filter((node) => Boolean(node));
|
|
117
117
|
if (!headings.length) return;
|
|
118
118
|
const root = scrollParent(headings[0]);
|
|
119
|
-
const intersections = /* @__PURE__ */ new Set();
|
|
120
119
|
let previous = { first: 0, last: 0, up: false };
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
120
|
+
let frame = 0;
|
|
121
|
+
const sync = () => {
|
|
122
|
+
const bounds = root?.getBoundingClientRect();
|
|
123
|
+
const viewTop = (bounds?.top ?? 0) + scrollOffset + 2;
|
|
124
|
+
const viewBottom = bounds ? bounds.top + root.clientHeight - 12 : innerHeight - 12;
|
|
125
|
+
const positions = headings.map((heading) => ({
|
|
126
|
+
heading,
|
|
127
|
+
bounds: heading.getBoundingClientRect()
|
|
128
|
+
}));
|
|
129
|
+
let primary = headings[0].id;
|
|
130
|
+
for (const position of positions)
|
|
131
|
+
if (position.bounds.top <= viewTop) primary = position.heading.id;
|
|
132
|
+
if (root && root.scrollHeight > root.clientHeight + 1 && root.scrollTop + root.clientHeight >= root.scrollHeight - 2)
|
|
133
|
+
primary = headings.at(-1).id;
|
|
134
|
+
const visible2 = positions.filter(
|
|
135
|
+
(position) => position.bounds.bottom > viewTop && position.bounds.top < viewBottom
|
|
136
|
+
).map((position) => position.heading.id);
|
|
137
|
+
const ids = visible2.length ? visible2 : [primary];
|
|
138
|
+
const first2 = entries.findIndex((entry) => entry.id === ids[0]);
|
|
139
|
+
const last2 = entries.findIndex((entry) => entry.id === ids.at(-1));
|
|
140
|
+
const isUp = first2 < previous.first || last2 < previous.last || first2 === previous.first && last2 === previous.last && previous.up;
|
|
141
|
+
previous = { first: first2, last: last2, up: isUp };
|
|
142
|
+
setUp(isUp);
|
|
143
|
+
setVisible((old) => old.join("\0") === ids.join("\0") ? old : ids);
|
|
144
|
+
setInternal(primary);
|
|
145
|
+
if (lastActive.current !== primary) {
|
|
146
|
+
lastActive.current = primary;
|
|
147
|
+
change.current?.(primary);
|
|
148
|
+
}
|
|
149
|
+
};
|
|
150
|
+
const schedule = () => {
|
|
151
|
+
if (frame) return;
|
|
152
|
+
frame = requestAnimationFrame(() => {
|
|
153
|
+
frame = 0;
|
|
154
|
+
sync();
|
|
155
|
+
});
|
|
156
|
+
};
|
|
157
|
+
const observer = new IntersectionObserver(schedule, {
|
|
158
|
+
root,
|
|
159
|
+
rootMargin: `-${scrollOffset}px 0px -12px 0px`,
|
|
160
|
+
threshold: 0
|
|
161
|
+
});
|
|
157
162
|
headings.forEach((heading) => observer.observe(heading));
|
|
158
|
-
|
|
163
|
+
const source = root ?? window;
|
|
164
|
+
source.addEventListener("scroll", schedule, { passive: true });
|
|
165
|
+
window.addEventListener("resize", schedule);
|
|
166
|
+
sync();
|
|
167
|
+
return () => {
|
|
168
|
+
observer.disconnect();
|
|
169
|
+
source.removeEventListener("scroll", schedule);
|
|
170
|
+
window.removeEventListener("resize", schedule);
|
|
171
|
+
cancelAnimationFrame(frame);
|
|
172
|
+
};
|
|
159
173
|
}, [entries, scrollOffset]);
|
|
160
174
|
useLayoutEffect(() => {
|
|
161
175
|
const node = list.current;
|
|
@@ -220,19 +234,31 @@ function TableOfContents({
|
|
|
220
234
|
}
|
|
221
235
|
}, [diagram.path, variant, railLayout]);
|
|
222
236
|
useLayoutEffect(() => {
|
|
223
|
-
const node = list.current
|
|
224
|
-
if (!
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
viewport.
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
237
|
+
const node = list.current;
|
|
238
|
+
if (!node || !open && variant === "rail") return;
|
|
239
|
+
const viewport = scrollable ? node.parentElement : scrollParent(node);
|
|
240
|
+
const selected = node.querySelector(
|
|
241
|
+
'[aria-current="location"]'
|
|
242
|
+
);
|
|
243
|
+
if (!viewport || !selected) return;
|
|
244
|
+
const reveal = () => {
|
|
245
|
+
if (!viewport.clientHeight || !selected.getClientRects().length) return;
|
|
246
|
+
const bounds = viewport.getBoundingClientRect();
|
|
247
|
+
const item = selected.getBoundingClientRect();
|
|
248
|
+
const top = bounds.top + viewport.clientTop + 12;
|
|
249
|
+
const bottom = bounds.top + viewport.clientTop + viewport.clientHeight - 12;
|
|
250
|
+
const delta = item.top < top ? item.top - top : item.bottom > bottom ? item.bottom - bottom : 0;
|
|
251
|
+
if (delta)
|
|
252
|
+
viewport.scrollTo({
|
|
253
|
+
top: viewport.scrollTop + delta,
|
|
254
|
+
behavior: reducedMotion() ? "auto" : "smooth"
|
|
255
|
+
});
|
|
256
|
+
};
|
|
257
|
+
reveal();
|
|
258
|
+
const resize = new ResizeObserver(reveal);
|
|
259
|
+
resize.observe(viewport);
|
|
260
|
+
return () => resize.disconnect();
|
|
261
|
+
}, [current, diagram.path, open, variant, scrollable]);
|
|
236
262
|
useLayoutEffect(() => {
|
|
237
263
|
if (variant !== "rail" || railLayout !== "preview" || !open) return;
|
|
238
264
|
const node = list.current, viewport = node?.parentElement;
|