import React, { PureComponent } from 'react'; import PropTypes from 'prop-types'; import DocumentContext from './DocumentContext'; import OutlineContext from './OutlineContext'; import Ref from './Ref'; import { isDefined } from './shared/utils'; import { isPdf } from './shared/propTypes'; export class OutlineItemInternal extends PureComponent { getDestination = async () => { const { item, pdf } = this.props; if (!isDefined(this.destination)) { if (typeof item.dest === 'string') { this.destination = await pdf.getDestination(item.dest); } else { this.destination = item.dest; } } return this.destination; } getPageIndex = async () => { const { pdf } = this.props; if (!isDefined(this.pageIndex)) { const destination = await this.getDestination(); if (destination) { const [ref] = destination; this.pageIndex = await pdf.getPageIndex(new Ref(ref)); } } return this.pageIndex; } getPageNumber = async () => { if (!isDefined(this.pageNumber)) { this.pageNumber = await this.getPageIndex() + 1; } return this.pageNumber; } onClick = async (event) => { const { onClick } = this.props; event.preventDefault(); const pageIndex = await this.getPageIndex(); const pageNumber = await this.getPageNumber(); if (onClick) { onClick({ pageIndex, pageNumber, }); } } renderSubitems() { const { item, ...otherProps } = this.props; if (!item.items || !item.items.length) { return null; } const { items: subitems } = item; return (