@open-slide/core 1.13.6 → 1.14.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/{build-OAZ8maw5.js → build-Dx-qTg82.js} +1 -1
- package/dist/cli/bin.js +3 -3
- package/dist/{config-CvzwK0tq.d.ts → config-CE2sKgqH.d.ts} +1 -1
- package/dist/{config-CU_NISD6.js → config-DvRA48y9.js} +37 -2
- package/dist/dev-BGXWqVUZ.js +94 -0
- package/dist/{format-CXtO6ORA.js → format-afijk371.js} +140 -8
- package/dist/index.d.ts +7 -7
- package/dist/index.js +4 -2
- package/dist/locale/index.d.ts +1 -1
- package/dist/locale/index.js +1 -1
- package/dist/{preview-DZLZ3L9v.js → preview-CdQnIB39.js} +1 -1
- package/dist/{types-DucrShh9.d.ts → types-GA4ekcYB.d.ts} +37 -0
- package/dist/vite/index.d.ts +2 -2
- package/dist/vite/index.js +1 -1
- package/package.json +1 -1
- package/src/app/components/asset-view.tsx +743 -63
- package/src/app/components/sidebar/sidebar-footer.tsx +98 -29
- package/src/app/components/thumbnail-rail-scroll.test.ts +60 -0
- package/src/app/components/thumbnail-rail-scroll.ts +33 -0
- package/src/app/components/thumbnail-rail.tsx +200 -35
- package/src/app/lib/asset-filter.test.ts +176 -0
- package/src/app/lib/asset-filter.ts +80 -0
- package/src/app/lib/assets.ts +19 -4
- package/src/locale/en.ts +34 -1
- package/src/locale/ja.ts +34 -2
- package/src/locale/types.ts +37 -0
- package/src/locale/zh-cn.ts +34 -1
- package/src/locale/zh-tw.ts +34 -1
- package/dist/dev-C78J1TLR.js +0 -20
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import config from 'virtual:open-slide/config';
|
|
2
|
-
import { Loader2, RefreshCw } from 'lucide-react';
|
|
2
|
+
import { Loader2, RefreshCw, RotateCw } from 'lucide-react';
|
|
3
3
|
import { useEffect, useState } from 'react';
|
|
4
4
|
import { toast } from 'sonner';
|
|
5
5
|
import { Button } from '@/components/ui/button';
|
|
@@ -7,12 +7,25 @@ import { Tooltip, TooltipContent, TooltipProvider, TooltipTrigger } from '@/comp
|
|
|
7
7
|
import { format, useLocale } from '@/lib/use-locale';
|
|
8
8
|
|
|
9
9
|
type UpdateCheck = { current: string; latest: string | null; outdated: boolean };
|
|
10
|
+
type ServerStatus = { executionId: string; canRestart: boolean };
|
|
10
11
|
type UpdateStatus = 'idle' | 'running' | 'done' | 'error';
|
|
11
12
|
|
|
13
|
+
const buttonClassName =
|
|
14
|
+
'h-6 w-fit rounded-[5px] border border-background/15 bg-background/8 px-2 text-[11px] text-background shadow-none hover:bg-background/14';
|
|
15
|
+
|
|
16
|
+
async function fetchServerStatus(): Promise<ServerStatus | null> {
|
|
17
|
+
const res = await fetch('/__server-status');
|
|
18
|
+
if (!res.ok) return null;
|
|
19
|
+
return (await res.json()) as ServerStatus;
|
|
20
|
+
}
|
|
21
|
+
|
|
12
22
|
export function SidebarFooter() {
|
|
13
23
|
const t = useLocale();
|
|
14
24
|
const [update, setUpdate] = useState<UpdateCheck | null>(null);
|
|
15
25
|
const [updateStatus, setUpdateStatus] = useState<UpdateStatus>('idle');
|
|
26
|
+
const [canRestart, setCanRestart] = useState(false);
|
|
27
|
+
const [restarting, setRestarting] = useState(false);
|
|
28
|
+
const [open, setOpen] = useState(false);
|
|
16
29
|
|
|
17
30
|
useEffect(() => {
|
|
18
31
|
if (!import.meta.env.DEV) return;
|
|
@@ -23,6 +36,11 @@ export function SidebarFooter() {
|
|
|
23
36
|
if (!cancelled && data?.outdated) setUpdate(data);
|
|
24
37
|
})
|
|
25
38
|
.catch(() => {});
|
|
39
|
+
fetchServerStatus()
|
|
40
|
+
.then((status) => {
|
|
41
|
+
if (!cancelled && status) setCanRestart(status.canRestart);
|
|
42
|
+
})
|
|
43
|
+
.catch(() => {});
|
|
26
44
|
return () => {
|
|
27
45
|
cancelled = true;
|
|
28
46
|
};
|
|
@@ -30,10 +48,12 @@ export function SidebarFooter() {
|
|
|
30
48
|
|
|
31
49
|
const label = `v${config.version}`;
|
|
32
50
|
const isUpdating = updateStatus === 'running';
|
|
51
|
+
const keepOpen = updateStatus === 'running' || restarting;
|
|
33
52
|
|
|
34
53
|
async function updatePackage() {
|
|
35
54
|
if (isUpdating) return;
|
|
36
55
|
setUpdateStatus('running');
|
|
56
|
+
setOpen(true);
|
|
37
57
|
try {
|
|
38
58
|
const res = await fetch('/__update-package', { method: 'POST' });
|
|
39
59
|
if (!res.ok) throw new Error('update failed');
|
|
@@ -45,6 +65,29 @@ export function SidebarFooter() {
|
|
|
45
65
|
}
|
|
46
66
|
}
|
|
47
67
|
|
|
68
|
+
async function restartServer() {
|
|
69
|
+
if (restarting) return;
|
|
70
|
+
setRestarting(true);
|
|
71
|
+
try {
|
|
72
|
+
const before = await fetchServerStatus();
|
|
73
|
+
if (!before) throw new Error('server status unavailable');
|
|
74
|
+
const res = await fetch('/__restart-server', { method: 'POST' });
|
|
75
|
+
if (!res.ok) throw new Error('restart failed');
|
|
76
|
+
for (let attempt = 0; attempt < 30; attempt++) {
|
|
77
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
78
|
+
const status = await fetchServerStatus().catch(() => null);
|
|
79
|
+
if (status && status.executionId !== before.executionId) {
|
|
80
|
+
window.location.reload();
|
|
81
|
+
return;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
throw new Error('restart timed out');
|
|
85
|
+
} catch {
|
|
86
|
+
setRestarting(false);
|
|
87
|
+
toast.error(t.home.restartServerFailed);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
48
91
|
const versionRow = (
|
|
49
92
|
<span className="inline-flex cursor-default items-center gap-1.5">
|
|
50
93
|
{update?.latest && <span className="size-1.5 rounded-full bg-brand" aria-hidden />}
|
|
@@ -56,7 +99,13 @@ export function SidebarFooter() {
|
|
|
56
99
|
<div className="px-4 py-3 text-[11px] text-muted-foreground/70 tabular-nums">
|
|
57
100
|
{update?.latest ? (
|
|
58
101
|
<TooltipProvider delayDuration={200}>
|
|
59
|
-
<Tooltip
|
|
102
|
+
<Tooltip
|
|
103
|
+
open={open}
|
|
104
|
+
onOpenChange={(next) => {
|
|
105
|
+
if (!next && keepOpen) return;
|
|
106
|
+
setOpen(next);
|
|
107
|
+
}}
|
|
108
|
+
>
|
|
60
109
|
<TooltipTrigger asChild>{versionRow}</TooltipTrigger>
|
|
61
110
|
<TooltipContent
|
|
62
111
|
side="top"
|
|
@@ -66,33 +115,53 @@ export function SidebarFooter() {
|
|
|
66
115
|
collisionPadding={12}
|
|
67
116
|
className="flex w-[232px] max-w-[calc(100vw-24px)] flex-col gap-2.5 rounded-[8px] border border-background/10 bg-foreground/95 p-2.5 text-[11.5px] leading-4 shadow-[0_12px_32px_oklch(0_0_0/0.28)] backdrop-blur"
|
|
68
117
|
>
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
118
|
+
{updateStatus === 'done' ? (
|
|
119
|
+
<>
|
|
120
|
+
<span className="pr-1 text-background/92">{t.home.updatePackageDone}</span>
|
|
121
|
+
{canRestart && (
|
|
122
|
+
<Button
|
|
123
|
+
type="button"
|
|
124
|
+
size="xs"
|
|
125
|
+
variant="secondary"
|
|
126
|
+
className={buttonClassName}
|
|
127
|
+
disabled={restarting}
|
|
128
|
+
onClick={restartServer}
|
|
129
|
+
>
|
|
130
|
+
{restarting ? (
|
|
131
|
+
<Loader2 className="animate-spin" aria-hidden />
|
|
132
|
+
) : (
|
|
133
|
+
<RotateCw aria-hidden />
|
|
134
|
+
)}
|
|
135
|
+
{restarting ? t.home.restartingServer : t.home.restartServer}
|
|
136
|
+
</Button>
|
|
137
|
+
)}
|
|
138
|
+
</>
|
|
139
|
+
) : (
|
|
140
|
+
<>
|
|
141
|
+
<span className="pr-1 text-background/92">
|
|
142
|
+
{format(t.home.updateAvailable, { version: update.latest })}
|
|
143
|
+
</span>
|
|
144
|
+
<Button
|
|
145
|
+
type="button"
|
|
146
|
+
size="xs"
|
|
147
|
+
variant="secondary"
|
|
148
|
+
className={buttonClassName}
|
|
149
|
+
disabled={isUpdating}
|
|
150
|
+
onClick={updatePackage}
|
|
151
|
+
>
|
|
152
|
+
{isUpdating ? (
|
|
153
|
+
<Loader2 className="animate-spin" aria-hidden />
|
|
154
|
+
) : (
|
|
155
|
+
<RefreshCw aria-hidden />
|
|
156
|
+
)}
|
|
157
|
+
{isUpdating ? t.home.updatingPackage : t.home.updatePackage}
|
|
158
|
+
</Button>
|
|
159
|
+
{updateStatus === 'error' && (
|
|
160
|
+
<span className="text-[11px] leading-4 text-background/65">
|
|
161
|
+
{t.home.updatePackageFailed}
|
|
162
|
+
</span>
|
|
163
|
+
)}
|
|
164
|
+
</>
|
|
96
165
|
)}
|
|
97
166
|
</TooltipContent>
|
|
98
167
|
</Tooltip>
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
import { describe, expect, it } from 'vitest';
|
|
2
|
+
import {
|
|
3
|
+
getCenteredThumbnailScrollTop,
|
|
4
|
+
getThumbnailOffscreenDirection,
|
|
5
|
+
} from './thumbnail-rail-scroll';
|
|
6
|
+
|
|
7
|
+
describe('getThumbnailOffscreenDirection', () => {
|
|
8
|
+
const visibleBounds = { visibleTop: 40, visibleBottom: 540 };
|
|
9
|
+
|
|
10
|
+
it('reports a thumbnail fully above the visible area', () => {
|
|
11
|
+
expect(getThumbnailOffscreenDirection({ itemTop: -80, itemBottom: 40, ...visibleBounds })).toBe(
|
|
12
|
+
'above',
|
|
13
|
+
);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('reports a thumbnail fully below the visible area', () => {
|
|
17
|
+
expect(
|
|
18
|
+
getThumbnailOffscreenDirection({ itemTop: 540, itemBottom: 660, ...visibleBounds }),
|
|
19
|
+
).toBe('below');
|
|
20
|
+
});
|
|
21
|
+
|
|
22
|
+
it('keeps the control hidden while a thumbnail is fully visible', () => {
|
|
23
|
+
expect(
|
|
24
|
+
getThumbnailOffscreenDirection({ itemTop: 120, itemBottom: 240, ...visibleBounds }),
|
|
25
|
+
).toBeNull();
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
it('keeps the control hidden while either edge remains visible', () => {
|
|
29
|
+
expect(
|
|
30
|
+
getThumbnailOffscreenDirection({ itemTop: 20, itemBottom: 80, ...visibleBounds }),
|
|
31
|
+
).toBeNull();
|
|
32
|
+
expect(
|
|
33
|
+
getThumbnailOffscreenDirection({ itemTop: 500, itemBottom: 580, ...visibleBounds }),
|
|
34
|
+
).toBeNull();
|
|
35
|
+
});
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
describe('getCenteredThumbnailScrollTop', () => {
|
|
39
|
+
it('centers the thumbnail inside the unobscured viewport', () => {
|
|
40
|
+
expect(
|
|
41
|
+
getCenteredThumbnailScrollTop({
|
|
42
|
+
itemTop: 1040,
|
|
43
|
+
itemHeight: 120,
|
|
44
|
+
viewportHeight: 600,
|
|
45
|
+
topInset: 40,
|
|
46
|
+
}),
|
|
47
|
+
).toBe(780);
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it('does not scroll before the start of the list', () => {
|
|
51
|
+
expect(
|
|
52
|
+
getCenteredThumbnailScrollTop({
|
|
53
|
+
itemTop: 40,
|
|
54
|
+
itemHeight: 120,
|
|
55
|
+
viewportHeight: 600,
|
|
56
|
+
topInset: 40,
|
|
57
|
+
}),
|
|
58
|
+
).toBe(0);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
export type ThumbnailOffscreenDirection = 'above' | 'below' | null;
|
|
2
|
+
|
|
3
|
+
export function getThumbnailOffscreenDirection({
|
|
4
|
+
itemTop,
|
|
5
|
+
itemBottom,
|
|
6
|
+
visibleTop,
|
|
7
|
+
visibleBottom,
|
|
8
|
+
}: {
|
|
9
|
+
itemTop: number;
|
|
10
|
+
itemBottom: number;
|
|
11
|
+
visibleTop: number;
|
|
12
|
+
visibleBottom: number;
|
|
13
|
+
}): ThumbnailOffscreenDirection {
|
|
14
|
+
if (itemBottom <= visibleTop) return 'above';
|
|
15
|
+
if (itemTop >= visibleBottom) return 'below';
|
|
16
|
+
return null;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export function getCenteredThumbnailScrollTop({
|
|
20
|
+
itemTop,
|
|
21
|
+
itemHeight,
|
|
22
|
+
viewportHeight,
|
|
23
|
+
topInset,
|
|
24
|
+
}: {
|
|
25
|
+
itemTop: number;
|
|
26
|
+
itemHeight: number;
|
|
27
|
+
viewportHeight: number;
|
|
28
|
+
topInset: number;
|
|
29
|
+
}): number {
|
|
30
|
+
const visibleHeight = Math.max(0, viewportHeight - topInset);
|
|
31
|
+
const centerOffset = Math.max(0, (visibleHeight - itemHeight) / 2);
|
|
32
|
+
return Math.max(0, itemTop - topInset - centerOffset);
|
|
33
|
+
}
|
|
@@ -15,8 +15,18 @@ import {
|
|
|
15
15
|
verticalListSortingStrategy,
|
|
16
16
|
} from '@dnd-kit/sortable';
|
|
17
17
|
import { CSS } from '@dnd-kit/utilities';
|
|
18
|
-
import {
|
|
18
|
+
import {
|
|
19
|
+
ChevronDown,
|
|
20
|
+
ChevronUp,
|
|
21
|
+
Copy,
|
|
22
|
+
Grid2x2,
|
|
23
|
+
ListOrdered,
|
|
24
|
+
type LucideIcon,
|
|
25
|
+
Sparkles,
|
|
26
|
+
Trash2,
|
|
27
|
+
} from 'lucide-react';
|
|
19
28
|
import { Fragment, useCallback, useEffect, useLayoutEffect, useRef, useState } from 'react';
|
|
29
|
+
import { Button } from '@/components/ui/button';
|
|
20
30
|
import {
|
|
21
31
|
ContextMenu,
|
|
22
32
|
ContextMenuContent,
|
|
@@ -34,6 +44,11 @@ import type { Page } from '../lib/sdk';
|
|
|
34
44
|
import { CANVAS_HEIGHT, CANVAS_WIDTH } from '../lib/sdk';
|
|
35
45
|
import type { SlideTransition } from '../lib/transition';
|
|
36
46
|
import { SlideCanvas } from './slide-canvas';
|
|
47
|
+
import {
|
|
48
|
+
getCenteredThumbnailScrollTop,
|
|
49
|
+
getThumbnailOffscreenDirection,
|
|
50
|
+
type ThumbnailOffscreenDirection,
|
|
51
|
+
} from './thumbnail-rail-scroll';
|
|
37
52
|
|
|
38
53
|
type Orientation = 'vertical' | 'horizontal';
|
|
39
54
|
|
|
@@ -84,18 +99,23 @@ export function ThumbnailRail({
|
|
|
84
99
|
onOverview,
|
|
85
100
|
}: Props) {
|
|
86
101
|
const activeRef = useRef<HTMLButtonElement | null>(null);
|
|
102
|
+
const virtualListRef = useRef<HTMLDivElement | null>(null);
|
|
103
|
+
const verticalViewportRef = useRef<HTMLElement | null>(null);
|
|
104
|
+
const focusCurrentAfterScrollRef = useRef(false);
|
|
105
|
+
const [currentPosition, setCurrentPosition] = useState<ThumbnailOffscreenDirection>(null);
|
|
87
106
|
const t = useLocale();
|
|
88
107
|
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
108
|
+
const setVerticalScrollElements = useCallback(
|
|
109
|
+
(viewport: HTMLElement | null, root: HTMLDivElement | null) => {
|
|
110
|
+
verticalViewportRef.current = viewport;
|
|
111
|
+
virtualListRef.current = root;
|
|
112
|
+
},
|
|
113
|
+
[],
|
|
114
|
+
);
|
|
92
115
|
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
behavior: reduceMotion ? 'auto' : 'smooth',
|
|
97
|
-
});
|
|
98
|
-
}, [current]);
|
|
116
|
+
const cancelPendingFocus = useCallback(() => {
|
|
117
|
+
focusCurrentAfterScrollRef.current = false;
|
|
118
|
+
}, []);
|
|
99
119
|
|
|
100
120
|
const thumbWidth =
|
|
101
121
|
width != null
|
|
@@ -105,6 +125,52 @@ export function ThumbnailRail({
|
|
|
105
125
|
const height = CANVAS_HEIGHT * scale;
|
|
106
126
|
const rowHeight = height + VERTICAL_THUMB_PADDING_Y + VERTICAL_THUMB_GAP;
|
|
107
127
|
|
|
128
|
+
const scrollToCurrent = useCallback(
|
|
129
|
+
(focusCurrent: boolean) => {
|
|
130
|
+
const viewport = verticalViewportRef.current;
|
|
131
|
+
const root = virtualListRef.current;
|
|
132
|
+
if (!viewport || !root || pages.length <= 0) return;
|
|
133
|
+
|
|
134
|
+
focusCurrentAfterScrollRef.current = focusCurrent;
|
|
135
|
+
const clampedCurrent = Math.min(Math.max(current, 0), pages.length - 1);
|
|
136
|
+
const topInset = root.offsetTop;
|
|
137
|
+
const itemTop = topInset + clampedCurrent * rowHeight;
|
|
138
|
+
viewport.scrollTo({
|
|
139
|
+
top: getCenteredThumbnailScrollTop({
|
|
140
|
+
itemTop,
|
|
141
|
+
itemHeight: rowHeight,
|
|
142
|
+
viewportHeight: viewport.clientHeight,
|
|
143
|
+
topInset,
|
|
144
|
+
}),
|
|
145
|
+
behavior: scrollBehavior(),
|
|
146
|
+
});
|
|
147
|
+
},
|
|
148
|
+
[current, pages.length, rowHeight],
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
useEffect(() => {
|
|
152
|
+
if (currentPosition !== null || !focusCurrentAfterScrollRef.current) return;
|
|
153
|
+
let frame = 0;
|
|
154
|
+
let attempts = 0;
|
|
155
|
+
const focusCurrent = () => {
|
|
156
|
+
if (!focusCurrentAfterScrollRef.current) return;
|
|
157
|
+
const active = activeRef.current;
|
|
158
|
+
if (active) {
|
|
159
|
+
active.focus({ preventScroll: true });
|
|
160
|
+
focusCurrentAfterScrollRef.current = false;
|
|
161
|
+
return;
|
|
162
|
+
}
|
|
163
|
+
attempts += 1;
|
|
164
|
+
if (attempts < 4) {
|
|
165
|
+
frame = requestAnimationFrame(focusCurrent);
|
|
166
|
+
} else {
|
|
167
|
+
focusCurrentAfterScrollRef.current = false;
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
frame = requestAnimationFrame(focusCurrent);
|
|
171
|
+
return () => cancelAnimationFrame(frame);
|
|
172
|
+
}, [currentPosition]);
|
|
173
|
+
|
|
108
174
|
const renderThumb = useCallback(
|
|
109
175
|
(PageComp: Page, i: number) => {
|
|
110
176
|
const active = i === current;
|
|
@@ -138,7 +204,7 @@ export function ThumbnailRail({
|
|
|
138
204
|
ref={active ? activeRef : undefined}
|
|
139
205
|
onClick={() => onSelect(i)}
|
|
140
206
|
aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
|
|
141
|
-
aria-current={active ? '
|
|
207
|
+
aria-current={active ? 'page' : undefined}
|
|
142
208
|
className={thumbButtonClass(active)}
|
|
143
209
|
>
|
|
144
210
|
{inner}
|
|
@@ -233,36 +299,102 @@ export function ThumbnailRail({
|
|
|
233
299
|
current={current}
|
|
234
300
|
rowHeight={rowHeight}
|
|
235
301
|
activeRef={activeRef}
|
|
302
|
+
onScrollElementsChange={setVerticalScrollElements}
|
|
303
|
+
onScrollInteraction={cancelPendingFocus}
|
|
304
|
+
onCurrentPositionChange={setCurrentPosition}
|
|
236
305
|
renderThumb={renderThumb}
|
|
237
306
|
/>
|
|
238
307
|
</aside>
|
|
239
308
|
);
|
|
240
309
|
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
);
|
|
249
|
-
}
|
|
310
|
+
const scrollAreaContents = onReorder ? (
|
|
311
|
+
<SortableRail pages={pages} onReorder={onReorder} onSelect={onSelect}>
|
|
312
|
+
{list}
|
|
313
|
+
</SortableRail>
|
|
314
|
+
) : (
|
|
315
|
+
list
|
|
316
|
+
);
|
|
250
317
|
|
|
251
318
|
return (
|
|
252
319
|
<TooltipProvider delayDuration={200}>
|
|
253
|
-
<
|
|
254
|
-
<
|
|
255
|
-
{
|
|
256
|
-
</
|
|
257
|
-
|
|
320
|
+
<div className="relative h-full">
|
|
321
|
+
<ScrollArea className="h-full border-r border-hairline bg-sidebar [&_[data-slot=scroll-area-scrollbar]]:z-20">
|
|
322
|
+
{scrollAreaContents}
|
|
323
|
+
</ScrollArea>
|
|
324
|
+
{currentPosition && (
|
|
325
|
+
<CurrentThumbnailButton
|
|
326
|
+
direction={currentPosition}
|
|
327
|
+
label={format(
|
|
328
|
+
currentPosition === 'above'
|
|
329
|
+
? t.thumbnailRail.scrollUpToCurrentPage
|
|
330
|
+
: t.thumbnailRail.scrollDownToCurrentPage,
|
|
331
|
+
{ n: current + 1 },
|
|
332
|
+
)}
|
|
333
|
+
onActivate={scrollToCurrent}
|
|
334
|
+
/>
|
|
335
|
+
)}
|
|
336
|
+
</div>
|
|
258
337
|
</TooltipProvider>
|
|
259
338
|
);
|
|
260
339
|
}
|
|
261
340
|
|
|
341
|
+
function CurrentThumbnailButton({
|
|
342
|
+
direction,
|
|
343
|
+
label,
|
|
344
|
+
onActivate,
|
|
345
|
+
}: {
|
|
346
|
+
direction: Exclude<ThumbnailOffscreenDirection, null>;
|
|
347
|
+
label: string;
|
|
348
|
+
onActivate: (focusCurrent: boolean) => void;
|
|
349
|
+
}) {
|
|
350
|
+
const Icon = direction === 'above' ? ChevronUp : ChevronDown;
|
|
351
|
+
return (
|
|
352
|
+
<Tooltip>
|
|
353
|
+
<TooltipTrigger asChild>
|
|
354
|
+
<Button
|
|
355
|
+
type="button"
|
|
356
|
+
variant="outline"
|
|
357
|
+
size="icon-sm"
|
|
358
|
+
aria-label={label}
|
|
359
|
+
onClick={(event) => onActivate(event.detail === 0)}
|
|
360
|
+
onKeyDown={(event) => {
|
|
361
|
+
if (event.key === ' ') {
|
|
362
|
+
event.preventDefault();
|
|
363
|
+
event.stopPropagation();
|
|
364
|
+
return;
|
|
365
|
+
}
|
|
366
|
+
if (event.key !== 'Enter') return;
|
|
367
|
+
event.preventDefault();
|
|
368
|
+
event.stopPropagation();
|
|
369
|
+
onActivate(true);
|
|
370
|
+
}}
|
|
371
|
+
onKeyUp={(event) => {
|
|
372
|
+
if (event.key !== ' ') return;
|
|
373
|
+
event.preventDefault();
|
|
374
|
+
event.stopPropagation();
|
|
375
|
+
onActivate(true);
|
|
376
|
+
}}
|
|
377
|
+
className={cn(
|
|
378
|
+
'pointer-events-auto absolute left-1/2 z-30 -translate-x-1/2 bg-card/95 shadow-floating backdrop-blur-sm',
|
|
379
|
+
'motion-safe:animate-in motion-safe:fade-in-0 motion-safe:zoom-in-95 motion-safe:duration-150',
|
|
380
|
+
direction === 'above' ? 'top-10' : 'bottom-3',
|
|
381
|
+
)}
|
|
382
|
+
>
|
|
383
|
+
<Icon className="size-3.5" strokeWidth={1.75} aria-hidden />
|
|
384
|
+
</Button>
|
|
385
|
+
</TooltipTrigger>
|
|
386
|
+
<TooltipContent side={direction === 'above' ? 'bottom' : 'top'} sideOffset={6}>
|
|
387
|
+
{label}
|
|
388
|
+
</TooltipContent>
|
|
389
|
+
</Tooltip>
|
|
390
|
+
);
|
|
391
|
+
}
|
|
392
|
+
|
|
262
393
|
function thumbButtonClass(active: boolean): string {
|
|
263
394
|
return cn(
|
|
264
|
-
'group/thumb flex w-full items-start gap-2.5 rounded-[6px] p-1.5 text-left motion-safe:transition-colors',
|
|
395
|
+
'group/thumb flex w-full items-start gap-2.5 rounded-[6px] p-1.5 text-left outline-none motion-safe:transition-colors',
|
|
265
396
|
'hover:bg-muted/60',
|
|
397
|
+
'focus-visible:ring-1 focus-visible:ring-brand focus-visible:ring-offset-1 focus-visible:ring-offset-sidebar',
|
|
266
398
|
active && 'bg-muted',
|
|
267
399
|
);
|
|
268
400
|
}
|
|
@@ -362,7 +494,7 @@ function HorizontalVirtualThumbList({
|
|
|
362
494
|
ref={active ? activeRef : undefined}
|
|
363
495
|
onClick={() => onSelect(i)}
|
|
364
496
|
aria-label={format(t.thumbnailRail.goToPageAria, { n: i + 1 })}
|
|
365
|
-
aria-current={active ? '
|
|
497
|
+
aria-current={active ? 'page' : undefined}
|
|
366
498
|
className={cn('group/thumb relative flex shrink-0 flex-col items-center gap-1.5')}
|
|
367
499
|
>
|
|
368
500
|
<span
|
|
@@ -432,12 +564,18 @@ function VirtualThumbList({
|
|
|
432
564
|
current,
|
|
433
565
|
rowHeight,
|
|
434
566
|
activeRef,
|
|
567
|
+
onScrollElementsChange,
|
|
568
|
+
onScrollInteraction,
|
|
569
|
+
onCurrentPositionChange,
|
|
435
570
|
renderThumb,
|
|
436
571
|
}: {
|
|
437
572
|
pages: Page[];
|
|
438
573
|
current: number;
|
|
439
574
|
rowHeight: number;
|
|
440
575
|
activeRef: React.MutableRefObject<HTMLButtonElement | null>;
|
|
576
|
+
onScrollElementsChange: (viewport: HTMLElement | null, root: HTMLDivElement | null) => void;
|
|
577
|
+
onScrollInteraction: () => void;
|
|
578
|
+
onCurrentPositionChange: (position: ThumbnailOffscreenDirection) => void;
|
|
441
579
|
renderThumb: (page: Page, index: number) => React.ReactNode;
|
|
442
580
|
}) {
|
|
443
581
|
const rootRef = useRef<HTMLDivElement | null>(null);
|
|
@@ -450,14 +588,32 @@ function VirtualThumbList({
|
|
|
450
588
|
if (!viewport || !root) return;
|
|
451
589
|
const scrollTop = Math.max(0, viewport.scrollTop - root.offsetTop);
|
|
452
590
|
setRange(getVisibleRange(scrollTop, pages.length, viewport.clientHeight, rowHeight));
|
|
453
|
-
|
|
591
|
+
|
|
592
|
+
if (pages.length <= 0) {
|
|
593
|
+
onCurrentPositionChange(null);
|
|
594
|
+
return;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
const clampedCurrent = Math.min(Math.max(current, 0), pages.length - 1);
|
|
598
|
+
const itemTop = root.offsetTop + clampedCurrent * rowHeight;
|
|
599
|
+
onCurrentPositionChange(
|
|
600
|
+
getThumbnailOffscreenDirection({
|
|
601
|
+
itemTop,
|
|
602
|
+
itemBottom: itemTop + rowHeight,
|
|
603
|
+
visibleTop: viewport.scrollTop + root.offsetTop,
|
|
604
|
+
visibleBottom: viewport.scrollTop + viewport.clientHeight,
|
|
605
|
+
}),
|
|
606
|
+
);
|
|
607
|
+
}, [current, onCurrentPositionChange, pages.length, rowHeight]);
|
|
454
608
|
|
|
455
609
|
useEffect(() => {
|
|
456
610
|
const root = rootRef.current;
|
|
457
611
|
if (!root) return;
|
|
458
612
|
const viewport = root.closest('[data-slot="scroll-area-viewport"]') as HTMLElement | null;
|
|
459
613
|
if (!viewport) return;
|
|
614
|
+
const scrollArea = viewport.parentElement;
|
|
460
615
|
viewportRef.current = viewport;
|
|
616
|
+
onScrollElementsChange(viewport, root);
|
|
461
617
|
|
|
462
618
|
let frame = 0;
|
|
463
619
|
const scheduleUpdate = () => {
|
|
@@ -467,29 +623,38 @@ function VirtualThumbList({
|
|
|
467
623
|
const resizeObserver = new ResizeObserver(scheduleUpdate);
|
|
468
624
|
|
|
469
625
|
viewport.addEventListener('scroll', scheduleUpdate, { passive: true });
|
|
626
|
+
scrollArea?.addEventListener('wheel', onScrollInteraction, { passive: true });
|
|
627
|
+
scrollArea?.addEventListener('touchstart', onScrollInteraction, { passive: true });
|
|
628
|
+
scrollArea?.addEventListener('pointerdown', onScrollInteraction, { passive: true });
|
|
470
629
|
resizeObserver.observe(viewport);
|
|
471
630
|
scheduleUpdate();
|
|
472
631
|
|
|
473
632
|
return () => {
|
|
474
633
|
cancelAnimationFrame(frame);
|
|
475
634
|
viewport.removeEventListener('scroll', scheduleUpdate);
|
|
635
|
+
scrollArea?.removeEventListener('wheel', onScrollInteraction);
|
|
636
|
+
scrollArea?.removeEventListener('touchstart', onScrollInteraction);
|
|
637
|
+
scrollArea?.removeEventListener('pointerdown', onScrollInteraction);
|
|
476
638
|
resizeObserver.disconnect();
|
|
477
639
|
if (viewportRef.current === viewport) viewportRef.current = null;
|
|
640
|
+
onScrollElementsChange(null, null);
|
|
478
641
|
};
|
|
479
|
-
}, [updateRange]);
|
|
642
|
+
}, [onScrollElementsChange, onScrollInteraction, updateRange]);
|
|
480
643
|
|
|
481
644
|
useEffect(() => {
|
|
482
645
|
const viewport = viewportRef.current;
|
|
483
646
|
const root = rootRef.current;
|
|
484
647
|
if (!viewport || !root) return;
|
|
485
648
|
|
|
486
|
-
|
|
649
|
+
if (pages.length <= 0) return;
|
|
650
|
+
const clampedCurrent = Math.min(Math.max(current, 0), pages.length - 1);
|
|
651
|
+
const top = root.offsetTop + clampedCurrent * rowHeight;
|
|
487
652
|
const bottom = top + rowHeight;
|
|
488
|
-
const viewportTop = viewport.scrollTop;
|
|
489
|
-
const viewportBottom =
|
|
653
|
+
const viewportTop = viewport.scrollTop + root.offsetTop;
|
|
654
|
+
const viewportBottom = viewport.scrollTop + viewport.clientHeight;
|
|
490
655
|
|
|
491
656
|
if (top < viewportTop) {
|
|
492
|
-
viewport.scrollTo({ top, behavior: scrollBehavior() });
|
|
657
|
+
viewport.scrollTo({ top: top - root.offsetTop, behavior: scrollBehavior() });
|
|
493
658
|
} else if (bottom > viewportBottom) {
|
|
494
659
|
viewport.scrollTo({ top: bottom - viewport.clientHeight, behavior: scrollBehavior() });
|
|
495
660
|
} else {
|
|
@@ -499,7 +664,7 @@ function VirtualThumbList({
|
|
|
499
664
|
behavior: scrollBehavior(),
|
|
500
665
|
});
|
|
501
666
|
}
|
|
502
|
-
}, [activeRef, current, rowHeight]);
|
|
667
|
+
}, [activeRef, current, pages.length, rowHeight]);
|
|
503
668
|
|
|
504
669
|
const visibleRange = clampVisibleRange(range, current, pages.length);
|
|
505
670
|
const visible = [];
|
|
@@ -786,7 +951,7 @@ function SortableThumb({
|
|
|
786
951
|
type="button"
|
|
787
952
|
onClick={onSelect}
|
|
788
953
|
aria-label={ariaLabel}
|
|
789
|
-
aria-current={active ? '
|
|
954
|
+
aria-current={active ? 'page' : undefined}
|
|
790
955
|
style={{
|
|
791
956
|
transform: CSS.Transform.toString(yOnlyTransform),
|
|
792
957
|
transition,
|