|
|
@ -1,4 +1,4 @@ |
|
|
|
import React, { useState, useEffect, useRef, useCallback } from "react" |
|
|
|
import React, { useState, useEffect, useRef, useCallback, useMemo } from "react" |
|
|
|
import { Book, Rendition, Contents } from "epubjs" |
|
|
|
import { Book, Rendition, Contents } from "epubjs" |
|
|
|
import { debounce } from "throttle-debounce" |
|
|
|
import { debounce } from "throttle-debounce" |
|
|
|
// modules
|
|
|
|
// modules
|
|
|
@ -10,7 +10,7 @@ import { timeFormatter } from 'lib/utils/commonUtil' |
|
|
|
// styles
|
|
|
|
// styles
|
|
|
|
import viewerDefaultStyles from 'modules/reactViewer/viewerStyle' |
|
|
|
import viewerDefaultStyles from 'modules/reactViewer/viewerStyle' |
|
|
|
// types
|
|
|
|
// types
|
|
|
|
import { ReactViewerProps } from 'types' |
|
|
|
import { ReactViewerProps, ViewerRef } from 'types' |
|
|
|
import BookType, { BookStyle, BookOption } from 'types/book' |
|
|
|
import BookType, { BookStyle, BookOption } from 'types/book' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -39,7 +39,8 @@ const ReactViewer = ({ |
|
|
|
onTocChange, |
|
|
|
onTocChange, |
|
|
|
onSelection, |
|
|
|
onSelection, |
|
|
|
loadingView |
|
|
|
loadingView |
|
|
|
}: ReactViewerProps, ref: any) => { |
|
|
|
}: ReactViewerProps, ref: React.RefObject<ViewerRef> | any) => { |
|
|
|
|
|
|
|
// TODO Fix the ref type correctly instead 'any' type.
|
|
|
|
const [book, setBook] = useState<Book | null>(null); |
|
|
|
const [book, setBook] = useState<Book | null>(null); |
|
|
|
|
|
|
|
|
|
|
|
const [rendition, setRendition] = useState<Rendition | null>(null); |
|
|
|
const [rendition, setRendition] = useState<Rendition | null>(null); |
|
|
@ -95,7 +96,7 @@ const ReactViewer = ({ |
|
|
|
* Viewer resizing function |
|
|
|
* Viewer resizing function |
|
|
|
* @method |
|
|
|
* @method |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
const onResize = useCallback(debounce(250, () => { |
|
|
|
const onResize = useMemo(() => debounce(250, () => { |
|
|
|
if (!rendition) return; |
|
|
|
if (!rendition) return; |
|
|
|
|
|
|
|
|
|
|
|
const viewerLayout_ = viewerLayout || { |
|
|
|
const viewerLayout_ = viewerLayout || { |
|
|
@ -149,6 +150,7 @@ const ReactViewer = ({ |
|
|
|
if (!iframeWin) return; |
|
|
|
if (!iframeWin) return; |
|
|
|
|
|
|
|
|
|
|
|
const selection_ = iframeWin.getSelection(); |
|
|
|
const selection_ = iframeWin.getSelection(); |
|
|
|
|
|
|
|
if (!selection_) return; |
|
|
|
|
|
|
|
|
|
|
|
const selectionText = selection_.toString(); |
|
|
|
const selectionText = selection_.toString(); |
|
|
|
if (selectionText === "") return; |
|
|
|
if (selectionText === "") return; |
|
|
@ -166,6 +168,13 @@ const ReactViewer = ({ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** Ref checker */ |
|
|
|
|
|
|
|
useEffect(() => { |
|
|
|
|
|
|
|
if (!ref) { |
|
|
|
|
|
|
|
throw new Error("[React-Epub-Viewer] Put a ref argument that has a ViewerRef type."); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
}, [ref]); |
|
|
|
|
|
|
|
|
|
|
|
/** Epub parsing */ |
|
|
|
/** Epub parsing */ |
|
|
|
// TODO Fix the infinite re-rendering issue, when inlcude `onBookInfoChange` to dependencies array.
|
|
|
|
// TODO Fix the infinite re-rendering issue, when inlcude `onBookInfoChange` to dependencies array.
|
|
|
|
/* eslint-disable */ |
|
|
|
/* eslint-disable */ |
|
|
|