feat: Initial clean release of CHM
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
一些检查失败了
automerge / automerge (push) Has been cancelled
react-native-android-build-apk / AssembleRelease (push) Has been cancelled
Build macOS M1 / Main (push) Has been cancelled
Joplin Continuous Integration / Main (macos-15-intel) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / Main (ubuntu-22.04-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-11-vs2026-arm) (push) Has been cancelled
Joplin Continuous Integration / Main (windows-2025) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04) (push) Has been cancelled
Joplin Continuous Integration / ServerDockerImage (ubuntu-22.04-arm) (push) Has been cancelled
Joplin UI tests / Main (ubuntu-22.04) (push) Has been cancelled
Joplin UI tests / Main (windows-2025) (push) Has been cancelled
Joplin UI tests / Mobile (push) Has been cancelled
Close stale issues / ProcessStaleIssues (push) Has been cancelled
这个提交包含在:
@@ -0,0 +1,56 @@
|
||||
import { useRef, useState, MutableRefObject } from 'react';
|
||||
import useAsyncEffect, { AsyncEffectEvent } from '@joplin/lib/hooks/useAsyncEffect';
|
||||
import PdfDocument from '../PdfDocument';
|
||||
import { ScaledSize } from '../types';
|
||||
|
||||
export interface ScaledSizeParams {
|
||||
pdfDocument: PdfDocument;
|
||||
pdfId: string;
|
||||
containerWidth: number;
|
||||
rememberScroll: boolean;
|
||||
anchorPage: number;
|
||||
container: MutableRefObject<HTMLElement>;
|
||||
innerContainerEl: MutableRefObject<HTMLElement>;
|
||||
pageGap: number;
|
||||
zoom: number;
|
||||
}
|
||||
|
||||
const useScaledSize = ({ pdfDocument, pdfId, containerWidth, rememberScroll, anchorPage, container, innerContainerEl, pageGap, zoom }: ScaledSizeParams) => {
|
||||
const [scaledSize, setScaledSize] = useState<ScaledSize>(null);
|
||||
const currentScaleSize = useRef(scaledSize);
|
||||
|
||||
useAsyncEffect(async (event: AsyncEffectEvent) => {
|
||||
if (!pdfDocument || !containerWidth) return;
|
||||
// console.log('scaledSize calculation triggered');
|
||||
const effectiveWidth = Math.min(containerWidth - 20, 900) * (zoom || 1);
|
||||
const scaledSize_ = await pdfDocument.getScaledSize(null, effectiveWidth);
|
||||
if (event.cancelled) return;
|
||||
|
||||
const oldScaleSize = currentScaleSize.current;
|
||||
const oldScrollTop = container.current.scrollTop;
|
||||
|
||||
innerContainerEl.current.style.height = `${(scaledSize_.height + pageGap) * pdfDocument.pageCount}px`;
|
||||
|
||||
// Adjust scroll position after window resize to keep the same page visible
|
||||
if (oldScaleSize && container.current) {
|
||||
container.current.scrollTop = oldScrollTop * (scaledSize_.scale / oldScaleSize.scale);
|
||||
}
|
||||
|
||||
currentScaleSize.current = scaledSize_;
|
||||
setScaledSize(scaledSize_);
|
||||
|
||||
// If loading after note rerender, try to retrieve the old scroll position
|
||||
if (rememberScroll && pdfId && !oldScaleSize && !anchorPage) {
|
||||
const scrollOffset = parseInt(sessionStorage.getItem(`pdf.${pdfId}.scrollTop`), 10) || null;
|
||||
if (scrollOffset) {
|
||||
// Adjusting it according to the new scale
|
||||
container.current.scrollTop = scrollOffset * scaledSize_.scale;
|
||||
// console.log('scroll set',container.current.scrollTop);
|
||||
}
|
||||
}
|
||||
}, [pdfDocument, pdfId, rememberScroll, anchorPage, containerWidth, zoom]);
|
||||
|
||||
return scaledSize;
|
||||
};
|
||||
|
||||
export default useScaledSize;
|
||||
在新工单中引用
屏蔽一个用户