diff --git a/apps/readest-app/next.config.mjs b/apps/readest-app/next.config.mjs index 1be4cb08..699dd9ae 100644 --- a/apps/readest-app/next.config.mjs +++ b/apps/readest-app/next.config.mjs @@ -1,5 +1,6 @@ import withPWA from 'next-pwa'; +const isDev = process.env['NODE_ENV'] === 'development'; const appPlatform = process.env['NEXT_PUBLIC_APP_PLATFORM']; /** @type {import('next').NextConfig} */ @@ -22,7 +23,7 @@ const nextConfig = { export default withPWA({ dest: 'public', - disable: appPlatform !== 'web', + disable: isDev || appPlatform !== 'web', register: true, skipWaiting: true, })(nextConfig); diff --git a/apps/readest-app/src/app/reader/components/annotator/AnnotationPopup.tsx b/apps/readest-app/src/app/reader/components/annotator/AnnotationPopup.tsx index 3fc134cb..b4108aaa 100644 --- a/apps/readest-app/src/app/reader/components/annotator/AnnotationPopup.tsx +++ b/apps/readest-app/src/app/reader/components/annotator/AnnotationPopup.tsx @@ -4,6 +4,7 @@ import PopupButton from './PopupButton'; import HighlightOptions from './HighlightOptions'; import { Position } from '@/utils/sel'; import { HighlightColor, HighlightStyle } from '@/types/book'; +import { useResponsiveSize } from '@/hooks/useResponsiveSize'; interface AnnotationPopupProps { buttons: Array<{ tooltipText: string; Icon: React.ElementType; onClick: () => void }>; @@ -17,8 +18,8 @@ interface AnnotationPopupProps { onHighlight: (update?: boolean) => void; } -const highlightOptionsHeightPx = 28; -const highlightOptionsPaddingPx = 16; +const OPTIONS_HEIGHT_PIX = 28; +const OPTIONS_PADDING_PIX = 16; const AnnotationPopup: React.FC = ({ buttons, @@ -31,6 +32,8 @@ const AnnotationPopup: React.FC = ({ popupHeight, onHighlight, }) => { + const highlightOptionsHeightPx = useResponsiveSize(OPTIONS_HEIGHT_PIX); + const highlightOptionsPaddingPx = useResponsiveSize(OPTIONS_PADDING_PIX); return (
= ({ bookKey }) => { const { settings } = useSettingsStore(); const { getConfig, saveConfig, getBookData, updateBooknotes } = useBookDataStore(); const { getProgress, getView, getViewsById, getViewSettings } = useReaderStore(); - const { isNotebookPinned, isNotebookVisible } = useNotebookStore(); const { setNotebookVisible, setNotebookNewAnnotation } = useNotebookStore(); useNotesSync(bookKey); @@ -48,6 +47,7 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { const isShowingPopup = useRef(false); const isTextSelected = useRef(false); + const isClickToShowPopup = useRef(false); const [selection, setSelection] = useState(); const [showAnnotPopup, setShowAnnotPopup] = useState(false); const [showWiktionaryPopup, setShowWiktionaryPopup] = useState(false); @@ -86,8 +86,12 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { setSelection({ key: bookKey, text: sel.toString(), range: sel.getRangeAt(0), index }); } }; + const handleTouchmove = () => { + setShowAnnotPopup(false); + }; if (bookData.book?.format !== 'PDF') { detail.doc?.addEventListener('pointerup', handlePointerup); + detail.doc?.addEventListener('touchmove', handleTouchmove); } }; @@ -116,6 +120,7 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { const annotation = annotations.find((annotation) => annotation.cfi === cfi); if (!annotation) return; const selection = { key: bookKey, annotated: true, text: annotation.text ?? '', range, index }; + isClickToShowPopup.current = true; setSelectedStyle(annotation.style!); setSelectedColor(annotation.color!); setSelection(selection); @@ -140,12 +145,16 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { useEffect(() => { const handleSingleClick = (): boolean => { + if (isClickToShowPopup.current) { + isClickToShowPopup.current = false; + return true; + } if (isTextSelected.current) { - view?.deselect(); - isTextSelected.current = false; + handleDismissPopupAndSelection(); return true; } if (showAnnotPopup || isShowingPopup.current) { + handleDismissPopup(); return true; } return false; @@ -229,7 +238,7 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { }); const { booknotes: annotations = [] } = config; - if (selection) navigator.clipboard.writeText(selection.text); + if (selection) navigator.clipboard?.writeText(selection.text); const cfi = view?.getCFI(selection.index, selection.range); if (!cfi) return; const annotation: BookNote = { @@ -363,14 +372,6 @@ const Annotator: React.FC<{ bookKey: string }> = ({ bookKey }) => { return (
- {(showAnnotPopup || showWiktionaryPopup || showWikipediaPopup || showDeepLPopup) && - (!isNotebookVisible || isNotebookPinned) && ( -
- )} {showWiktionaryPopup && trianglePosition && dictPopupPosition && ( = ({ const globalReadSettings = settings.globalReadSettings; const [selectedStyle, setSelectedStyle] = React.useState(_selectedStyle); const [selectedColor, setSelectedColor] = React.useState(_selectedColor); - const iconSize16 = useResponsiveSize(16); + const size16 = useResponsiveSize(16); + const size18 = useResponsiveSize(18); + const size28 = useResponsiveSize(28); const handleSelectStyle = (style: HighlightStyle) => { globalReadSettings.highlightStyle = style; @@ -42,18 +44,19 @@ const HighlightOptions: React.FC = ({ onHandleHighlight(true); }; return ( -
-
+
+
{styles.map((style) => ( ))} diff --git a/packages/foliate-js b/packages/foliate-js index b9347d80..45d676ba 160000 --- a/packages/foliate-js +++ b/packages/foliate-js @@ -1 +1 @@ -Subproject commit b9347d80e8df7ba91e599899289f55f1ec2f5cdc +Subproject commit 45d676baab0c49a90d470707b622e031f53f3073