2021-09-30 07:29:25 -04:00
|
|
|
import {
|
|
|
|
createContext,
|
|
|
|
useCallback,
|
|
|
|
useContext,
|
|
|
|
useEffect,
|
|
|
|
useMemo,
|
|
|
|
useState,
|
|
|
|
} from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
2021-10-08 06:09:41 -04:00
|
|
|
import useScopeValue from '../../../shared/hooks/use-scope-value'
|
2021-09-30 07:29:25 -04:00
|
|
|
import { useProjectContext } from '../../../shared/context/project-context'
|
|
|
|
import usePersistedState from '../../../shared/hooks/use-persisted-state'
|
|
|
|
import {
|
|
|
|
buildLogEntryAnnotations,
|
|
|
|
handleOutputFiles,
|
|
|
|
} from '../util/output-files'
|
|
|
|
import {
|
|
|
|
send,
|
|
|
|
sendMB,
|
|
|
|
sendMBSampled,
|
|
|
|
} from '../../../infrastructure/event-tracking'
|
|
|
|
import { useEditorContext } from '../../../shared/context/editor-context'
|
|
|
|
import useAbortController from '../../../shared/hooks/use-abort-controller'
|
2021-10-08 05:23:33 -04:00
|
|
|
import DocumentCompiler from '../util/compiler'
|
|
|
|
import { useIdeContext } from '../../../shared/context/ide-context'
|
2021-10-08 05:51:04 -04:00
|
|
|
import { useLayoutContext } from '../../../shared/context/layout-context'
|
|
|
|
import { useCompileContext } from '../../../shared/context/compile-context'
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
export const PdfPreviewContext = createContext(undefined)
|
|
|
|
|
|
|
|
PdfPreviewProvider.propTypes = {
|
|
|
|
children: PropTypes.any,
|
|
|
|
}
|
|
|
|
|
|
|
|
export default function PdfPreviewProvider({ children }) {
|
|
|
|
const ide = useIdeContext()
|
|
|
|
|
2021-10-08 05:51:04 -04:00
|
|
|
const { pdfHidden, pdfLayout, setPdfLayout, setView } = useLayoutContext()
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
const project = useProjectContext()
|
|
|
|
|
|
|
|
const projectId = project._id
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const { hasPremiumCompile, isProjectOwner } = useEditorContext()
|
|
|
|
|
2021-10-08 05:51:04 -04:00
|
|
|
const {
|
|
|
|
logEntries,
|
|
|
|
pdfDownloadUrl,
|
|
|
|
pdfUrl,
|
|
|
|
setClsiServerId,
|
|
|
|
setLogEntries,
|
|
|
|
setLogEntryAnnotations,
|
|
|
|
setPdfDownloadUrl,
|
|
|
|
setPdfUrl,
|
|
|
|
setUncompiled,
|
|
|
|
uncompiled,
|
|
|
|
} = useCompileContext()
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// whether a compile is in progress
|
|
|
|
const [compiling, setCompiling] = useState(false)
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// data received in response to a compile request
|
|
|
|
const [data, setData] = useState()
|
|
|
|
|
2021-09-30 07:29:25 -04:00
|
|
|
// whether the project has been compiled yet
|
|
|
|
const [compiledOnce, setCompiledOnce] = useState(false)
|
|
|
|
|
|
|
|
// whether the cache is being cleared
|
|
|
|
const [clearingCache, setClearingCache] = useState(false)
|
|
|
|
|
|
|
|
// whether the logs should be visible
|
|
|
|
const [showLogs, setShowLogs] = useState(false)
|
|
|
|
|
|
|
|
// an error that occurred
|
|
|
|
const [error, setError] = useState()
|
|
|
|
|
|
|
|
// the list of files that can be downloaded
|
|
|
|
const [fileList, setFileList] = useState()
|
|
|
|
|
|
|
|
// the raw contents of the log file
|
|
|
|
const [rawLog, setRawLog] = useState()
|
|
|
|
|
|
|
|
// validation issues from CLSI
|
|
|
|
const [validationIssues, setValidationIssues] = useState()
|
|
|
|
|
|
|
|
// whether autocompile is switched on
|
|
|
|
const [autoCompile, _setAutoCompile] = usePersistedState(
|
|
|
|
`autocompile_enabled:${projectId}`,
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
|
|
|
// whether the compile should run in draft mode
|
|
|
|
const [draft, setDraft] = usePersistedState(`draft:${projectId}`, false, true)
|
|
|
|
|
|
|
|
// whether compiling should be prevented if there are linting errors
|
|
|
|
const [stopOnValidationError, setStopOnValidationError] = usePersistedState(
|
|
|
|
`stop_on_validation_error:${projectId}`,
|
|
|
|
true,
|
|
|
|
true
|
|
|
|
)
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// the Document currently open in the editor
|
2021-09-30 07:29:25 -04:00
|
|
|
const [currentDoc] = useScopeValue('editor.sharejs_doc')
|
|
|
|
|
|
|
|
// whether the editor linter found errors
|
|
|
|
const [hasLintingError, setHasLintingError] = useScopeValue('hasLintingError')
|
|
|
|
|
|
|
|
// whether syntax validation is enabled globally
|
|
|
|
const [syntaxValidation] = useScopeValue('settings.syntaxValidation')
|
|
|
|
|
|
|
|
// the timestamp that a doc was last changed or saved
|
|
|
|
const [changedAt, setChangedAt] = useState(0)
|
|
|
|
|
|
|
|
const { signal } = useAbortController()
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// the document compiler
|
|
|
|
const [compiler] = useState(() => {
|
|
|
|
return new DocumentCompiler({
|
|
|
|
project,
|
|
|
|
setChangedAt,
|
|
|
|
setCompiling,
|
|
|
|
setData,
|
|
|
|
setError,
|
|
|
|
signal,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// clean up the compiler on unmount
|
|
|
|
useEffect(() => {
|
|
|
|
return () => {
|
|
|
|
compiler.destroy()
|
|
|
|
}
|
|
|
|
}, [compiler])
|
|
|
|
|
|
|
|
// keep currentDoc in sync with the compiler
|
|
|
|
useEffect(() => {
|
|
|
|
compiler.currentDoc = currentDoc
|
|
|
|
}, [compiler, currentDoc])
|
|
|
|
|
|
|
|
// keep draft setting in sync with the compiler
|
|
|
|
useEffect(() => {
|
|
|
|
compiler.draft = draft
|
|
|
|
}, [compiler, draft])
|
|
|
|
|
2021-09-30 07:29:25 -04:00
|
|
|
// pass the "uncompiled" value up into the scope for use outside this context provider
|
|
|
|
useEffect(() => {
|
|
|
|
setUncompiled(changedAt > 0)
|
|
|
|
}, [setUncompiled, changedAt])
|
|
|
|
|
|
|
|
// record changes to the autocompile setting
|
|
|
|
const setAutoCompile = useCallback(
|
|
|
|
value => {
|
|
|
|
_setAutoCompile(value)
|
|
|
|
sendMB('autocompile-setting-changed', { value })
|
|
|
|
},
|
|
|
|
[_setAutoCompile]
|
|
|
|
)
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// always compile the PDF once after opening the project, after the doc has loaded
|
|
|
|
useEffect(() => {
|
|
|
|
if (!compiledOnce && currentDoc) {
|
|
|
|
setCompiledOnce(true)
|
|
|
|
compiler.compile({ isAutoCompileOnLoad: true })
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
2021-10-08 05:23:33 -04:00
|
|
|
}, [compiledOnce, currentDoc, compiler])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// handle the data returned from a compile request
|
2021-10-08 05:23:33 -04:00
|
|
|
// note: this should _only_ run when `data` changes,
|
|
|
|
// the other dependencies must all be static
|
|
|
|
useEffect(() => {
|
|
|
|
if (data) {
|
2021-09-30 07:29:25 -04:00
|
|
|
if (data.clsiServerId) {
|
2021-10-08 05:23:33 -04:00
|
|
|
setClsiServerId(data.clsiServerId) // set in scope, for PdfSynctexController
|
|
|
|
compiler.clsiServerId = data.clsiServerId
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.compileGroup) {
|
2021-10-08 05:23:33 -04:00
|
|
|
compiler.compileGroup = data.compileGroup
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
if (data.outputFiles) {
|
|
|
|
handleOutputFiles(projectId, data).then(result => {
|
|
|
|
setLogEntryAnnotations(
|
|
|
|
buildLogEntryAnnotations(result.logEntries.all, ide.fileTreeManager)
|
|
|
|
)
|
|
|
|
setLogEntries(result.logEntries)
|
|
|
|
setFileList(result.fileList)
|
|
|
|
setPdfDownloadUrl(result.pdfDownloadUrl)
|
|
|
|
setPdfUrl(result.pdfUrl)
|
|
|
|
setRawLog(result.log)
|
2021-10-08 05:23:33 -04:00
|
|
|
|
|
|
|
// sample compile stats for real users
|
|
|
|
if (!window.user.alphaProgram && data.status === 'success') {
|
|
|
|
sendMBSampled(
|
|
|
|
'compile-result',
|
|
|
|
{
|
|
|
|
errors: result.logEntries.errors.length,
|
|
|
|
warnings: result.logEntries.warnings.length,
|
|
|
|
typesetting: result.logEntries.typesetting.length,
|
|
|
|
newPdfPreview: true, // TODO: is this useful?
|
|
|
|
},
|
|
|
|
0.01
|
|
|
|
)
|
|
|
|
}
|
2021-09-30 07:29:25 -04:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (data.status) {
|
|
|
|
case 'success':
|
|
|
|
setError(undefined)
|
2021-10-08 05:23:33 -04:00
|
|
|
setShowLogs(false)
|
2021-09-30 07:29:25 -04:00
|
|
|
break
|
|
|
|
|
|
|
|
case 'clsi-maintenance':
|
|
|
|
case 'compile-in-progress':
|
|
|
|
case 'exited':
|
|
|
|
case 'failure':
|
|
|
|
case 'project-too-large':
|
|
|
|
case 'terminated':
|
|
|
|
case 'too-recently-compiled':
|
|
|
|
setError(data.status)
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'timedout':
|
|
|
|
setError('timedout')
|
|
|
|
|
|
|
|
if (!hasPremiumCompile && isProjectOwner) {
|
|
|
|
send(
|
|
|
|
'subscription-funnel',
|
|
|
|
'editor-click-feature',
|
|
|
|
'compile-timeout'
|
|
|
|
)
|
|
|
|
sendMB('paywall-prompt', {
|
|
|
|
'paywall-type': 'compile-timeout',
|
|
|
|
})
|
|
|
|
}
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'autocompile-backoff':
|
2021-10-08 05:23:33 -04:00
|
|
|
if (!data.options.isAutoCompileOnLoad) {
|
2021-09-30 07:29:25 -04:00
|
|
|
setError('autocompile-disabled')
|
|
|
|
setAutoCompile(false)
|
|
|
|
sendMB('autocompile-rate-limited', { hasPremiumCompile })
|
|
|
|
}
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'unavailable':
|
|
|
|
setError('clsi-unavailable')
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'validation-problems':
|
|
|
|
setError('validation-problems')
|
|
|
|
setValidationIssues(data.validationProblems)
|
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
|
|
|
setError('error')
|
|
|
|
break
|
|
|
|
}
|
2021-10-08 05:23:33 -04:00
|
|
|
}
|
|
|
|
}, [
|
|
|
|
compiler,
|
|
|
|
data,
|
|
|
|
ide,
|
|
|
|
hasPremiumCompile,
|
|
|
|
isProjectOwner,
|
|
|
|
projectId,
|
|
|
|
setAutoCompile,
|
|
|
|
setClsiServerId,
|
|
|
|
setLogEntries,
|
|
|
|
setLogEntryAnnotations,
|
|
|
|
setPdfDownloadUrl,
|
|
|
|
setPdfUrl,
|
|
|
|
])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// switch to logs if there's an error
|
|
|
|
useEffect(() => {
|
|
|
|
if (error) {
|
|
|
|
setShowLogs(true)
|
|
|
|
}
|
|
|
|
}, [error])
|
|
|
|
|
|
|
|
// recompile on key press
|
|
|
|
useEffect(() => {
|
|
|
|
const listener = event => {
|
2021-10-08 05:23:33 -04:00
|
|
|
compiler.compile(event.detail)
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('pdf:recompile', listener)
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener('pdf:recompile', listener)
|
|
|
|
}
|
2021-10-08 05:23:33 -04:00
|
|
|
}, [compiler])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// whether there has been an autocompile linting error, if syntax validation is switched on
|
|
|
|
const autoCompileLintingError = Boolean(
|
|
|
|
autoCompile && syntaxValidation && hasLintingError
|
|
|
|
)
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
const codeCheckFailed = stopOnValidationError && autoCompileLintingError
|
|
|
|
|
|
|
|
// show that the project has pending changes
|
2021-09-30 07:29:25 -04:00
|
|
|
const hasChanges = Boolean(
|
2021-10-08 05:23:33 -04:00
|
|
|
autoCompile && uncompiled && compiledOnce && !codeCheckFailed
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
// the project is available for auto-compiling
|
|
|
|
const canAutoCompile = Boolean(
|
2021-10-08 05:23:33 -04:00
|
|
|
autoCompile && !compiling && !pdfHidden && !codeCheckFailed
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// call the debounced autocompile function if the project is available for auto-compiling and it has changed
|
2021-09-30 07:29:25 -04:00
|
|
|
useEffect(() => {
|
|
|
|
if (canAutoCompile && changedAt > 0) {
|
2021-10-08 05:23:33 -04:00
|
|
|
compiler.debouncedAutoCompile()
|
2021-09-30 07:29:25 -04:00
|
|
|
} else {
|
2021-10-08 05:23:33 -04:00
|
|
|
compiler.debouncedAutoCompile.cancel()
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
2021-10-08 05:23:33 -04:00
|
|
|
}, [compiler, canAutoCompile, changedAt])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// cancel debounced recompile on unmount
|
|
|
|
useEffect(() => {
|
|
|
|
return () => {
|
2021-10-08 05:23:33 -04:00
|
|
|
compiler.debouncedAutoCompile.cancel()
|
2021-09-30 07:29:25 -04:00
|
|
|
}
|
2021-10-08 05:23:33 -04:00
|
|
|
}, [compiler])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// record doc changes when notified by the editor
|
|
|
|
useEffect(() => {
|
|
|
|
const listener = () => {
|
|
|
|
setChangedAt(Date.now())
|
|
|
|
}
|
|
|
|
|
|
|
|
window.addEventListener('doc:changed', listener)
|
|
|
|
window.addEventListener('doc:saved', listener)
|
|
|
|
|
|
|
|
return () => {
|
|
|
|
window.removeEventListener('doc:changed', listener)
|
|
|
|
window.removeEventListener('doc:saved', listener)
|
|
|
|
}
|
|
|
|
}, [])
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// start a compile manually
|
|
|
|
const startCompile = useCallback(() => {
|
|
|
|
compiler.compile()
|
|
|
|
}, [compiler])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// stop a compile manually
|
|
|
|
const stopCompile = useCallback(() => {
|
|
|
|
compiler.stopCompile()
|
|
|
|
}, [compiler])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
// clear the compile cache
|
2021-09-30 07:29:25 -04:00
|
|
|
const clearCache = useCallback(() => {
|
|
|
|
setClearingCache(true)
|
|
|
|
|
2021-10-08 05:23:33 -04:00
|
|
|
return compiler.clearCache().finally(() => {
|
|
|
|
setClearingCache(false)
|
|
|
|
})
|
|
|
|
}, [compiler])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// clear the cache then run a compile, triggered by a menu item
|
|
|
|
const recompileFromScratch = useCallback(() => {
|
|
|
|
clearCache().then(() => {
|
2021-10-08 05:23:33 -04:00
|
|
|
compiler.compile()
|
2021-09-30 07:29:25 -04:00
|
|
|
})
|
2021-10-08 05:23:33 -04:00
|
|
|
}, [clearCache, compiler])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// switch to either side-by-side or flat (full-width) layout
|
2021-10-08 05:51:04 -04:00
|
|
|
// TODO: move this into LayoutContext?
|
2021-09-30 07:29:25 -04:00
|
|
|
const switchLayout = useCallback(() => {
|
|
|
|
setPdfLayout(layout => {
|
|
|
|
const newLayout = layout === 'sideBySide' ? 'flat' : 'sideBySide'
|
2021-10-08 05:51:04 -04:00
|
|
|
setView(newLayout === 'sideBySide' ? 'editor' : 'pdf')
|
2021-09-30 07:29:25 -04:00
|
|
|
setPdfLayout(newLayout)
|
|
|
|
window.localStorage.setItem('pdf.layout', newLayout)
|
|
|
|
})
|
2021-10-08 05:51:04 -04:00
|
|
|
}, [setPdfLayout, setView])
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
// the context value, memoized to minimize re-rendering
|
|
|
|
const value = useMemo(() => {
|
|
|
|
return {
|
|
|
|
autoCompile,
|
2021-10-08 05:23:33 -04:00
|
|
|
codeCheckFailed,
|
2021-09-30 07:29:25 -04:00
|
|
|
clearCache,
|
|
|
|
clearingCache,
|
|
|
|
compiling,
|
|
|
|
draft,
|
|
|
|
error,
|
|
|
|
fileList,
|
|
|
|
hasChanges,
|
|
|
|
hasLintingError,
|
|
|
|
logEntries,
|
|
|
|
pdfDownloadUrl,
|
|
|
|
pdfLayout,
|
|
|
|
pdfUrl,
|
|
|
|
rawLog,
|
|
|
|
recompileFromScratch,
|
|
|
|
setAutoCompile,
|
|
|
|
setDraft,
|
2021-10-08 05:23:33 -04:00
|
|
|
setHasLintingError, // only for stories
|
2021-09-30 07:29:25 -04:00
|
|
|
setShowLogs,
|
|
|
|
setStopOnValidationError,
|
|
|
|
showLogs,
|
2021-10-08 05:23:33 -04:00
|
|
|
startCompile,
|
2021-09-30 07:29:25 -04:00
|
|
|
stopCompile,
|
|
|
|
stopOnValidationError,
|
|
|
|
switchLayout,
|
|
|
|
uncompiled,
|
|
|
|
validationIssues,
|
|
|
|
}
|
|
|
|
}, [
|
|
|
|
autoCompile,
|
2021-10-08 05:23:33 -04:00
|
|
|
codeCheckFailed,
|
2021-09-30 07:29:25 -04:00
|
|
|
clearCache,
|
|
|
|
clearingCache,
|
|
|
|
compiling,
|
|
|
|
draft,
|
|
|
|
error,
|
|
|
|
fileList,
|
|
|
|
hasChanges,
|
|
|
|
hasLintingError,
|
|
|
|
logEntries,
|
|
|
|
pdfDownloadUrl,
|
|
|
|
pdfLayout,
|
|
|
|
pdfUrl,
|
|
|
|
rawLog,
|
|
|
|
recompileFromScratch,
|
|
|
|
setAutoCompile,
|
|
|
|
setDraft,
|
2021-10-08 05:23:33 -04:00
|
|
|
setHasLintingError, // only for stories
|
2021-09-30 07:29:25 -04:00
|
|
|
setStopOnValidationError,
|
|
|
|
showLogs,
|
2021-10-08 05:23:33 -04:00
|
|
|
startCompile,
|
2021-09-30 07:29:25 -04:00
|
|
|
stopCompile,
|
|
|
|
stopOnValidationError,
|
|
|
|
switchLayout,
|
|
|
|
uncompiled,
|
|
|
|
validationIssues,
|
|
|
|
])
|
|
|
|
|
|
|
|
return (
|
|
|
|
<PdfPreviewContext.Provider value={value}>
|
|
|
|
{children}
|
|
|
|
</PdfPreviewContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
PdfPreviewContext.Provider.propTypes = {
|
|
|
|
value: PropTypes.shape({
|
|
|
|
autoCompile: PropTypes.bool.isRequired,
|
|
|
|
clearCache: PropTypes.func.isRequired,
|
|
|
|
clearingCache: PropTypes.bool.isRequired,
|
2021-10-08 05:23:33 -04:00
|
|
|
codeCheckFailed: PropTypes.bool.isRequired,
|
2021-09-30 07:29:25 -04:00
|
|
|
compiling: PropTypes.bool.isRequired,
|
|
|
|
draft: PropTypes.bool.isRequired,
|
|
|
|
error: PropTypes.string,
|
|
|
|
fileList: PropTypes.object,
|
|
|
|
hasChanges: PropTypes.bool.isRequired,
|
|
|
|
hasLintingError: PropTypes.bool,
|
|
|
|
logEntries: PropTypes.object,
|
|
|
|
pdfDownloadUrl: PropTypes.string,
|
|
|
|
pdfLayout: PropTypes.string,
|
|
|
|
pdfUrl: PropTypes.string,
|
|
|
|
rawLog: PropTypes.string,
|
|
|
|
recompileFromScratch: PropTypes.func.isRequired,
|
|
|
|
setAutoCompile: PropTypes.func.isRequired,
|
|
|
|
setDraft: PropTypes.func.isRequired,
|
|
|
|
setHasLintingError: PropTypes.func.isRequired, // only for storybook
|
|
|
|
setShowLogs: PropTypes.func.isRequired,
|
|
|
|
setStopOnValidationError: PropTypes.func.isRequired,
|
|
|
|
showLogs: PropTypes.bool.isRequired,
|
2021-10-08 05:23:33 -04:00
|
|
|
startCompile: PropTypes.func.isRequired,
|
2021-09-30 07:29:25 -04:00
|
|
|
stopCompile: PropTypes.func.isRequired,
|
|
|
|
stopOnValidationError: PropTypes.bool.isRequired,
|
|
|
|
switchLayout: PropTypes.func.isRequired,
|
|
|
|
uncompiled: PropTypes.bool,
|
|
|
|
validationIssues: PropTypes.object,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
|
|
|
|
export function usePdfPreviewContext() {
|
|
|
|
const context = useContext(PdfPreviewContext)
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
throw new Error(
|
|
|
|
'usePdfPreviewContext is only available inside PdfPreviewProvider'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|