2021-10-15 05:39:56 -04:00
|
|
|
import {
|
|
|
|
createContext,
|
|
|
|
useCallback,
|
|
|
|
useContext,
|
|
|
|
useEffect,
|
|
|
|
useMemo,
|
2022-03-03 11:28:12 -05:00
|
|
|
useRef,
|
2021-10-15 05:39:56 -04:00
|
|
|
useState,
|
|
|
|
} from 'react'
|
2021-04-19 08:38:03 -04:00
|
|
|
import PropTypes from 'prop-types'
|
2021-10-08 06:09:41 -04:00
|
|
|
import useScopeValue from '../hooks/use-scope-value'
|
2021-11-03 10:30:41 -04:00
|
|
|
import useScopeValueSetterOnly from '../hooks/use-scope-value-setter-only'
|
2021-10-15 05:39:56 -04:00
|
|
|
import usePersistedState from '../hooks/use-persisted-state'
|
|
|
|
import useAbortController from '../hooks/use-abort-controller'
|
|
|
|
import DocumentCompiler from '../../features/pdf-preview/util/compiler'
|
2022-03-31 07:22:36 -04:00
|
|
|
import {
|
|
|
|
send,
|
|
|
|
sendMBOnce,
|
|
|
|
sendMBSampled,
|
|
|
|
} from '../../infrastructure/event-tracking'
|
2021-10-15 05:39:56 -04:00
|
|
|
import {
|
|
|
|
buildLogEntryAnnotations,
|
2022-03-25 05:42:10 -04:00
|
|
|
handleLogFiles,
|
2021-10-15 05:39:56 -04:00
|
|
|
handleOutputFiles,
|
|
|
|
} from '../../features/pdf-preview/util/output-files'
|
|
|
|
import { useIdeContext } from './ide-context'
|
|
|
|
import { useProjectContext } from './project-context'
|
|
|
|
import { useEditorContext } from './editor-context'
|
2022-03-25 05:42:10 -04:00
|
|
|
import { buildFileList } from '../../features/pdf-preview/util/file-list'
|
2021-04-19 08:38:03 -04:00
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
export const LocalCompileContext = createContext()
|
2021-04-19 08:38:03 -04:00
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
export const CompileContextPropTypes = {
|
2021-04-19 08:38:03 -04:00
|
|
|
value: PropTypes.shape({
|
2021-10-15 05:39:56 -04:00
|
|
|
autoCompile: PropTypes.bool.isRequired,
|
|
|
|
clearingCache: PropTypes.bool.isRequired,
|
2021-10-08 05:51:04 -04:00
|
|
|
clsiServerId: PropTypes.string,
|
2021-10-15 05:39:56 -04:00
|
|
|
codeCheckFailed: PropTypes.bool.isRequired,
|
|
|
|
compiling: PropTypes.bool.isRequired,
|
|
|
|
draft: PropTypes.bool.isRequired,
|
|
|
|
error: PropTypes.string,
|
|
|
|
fileList: PropTypes.object,
|
|
|
|
hasChanges: PropTypes.bool.isRequired,
|
2021-10-21 06:31:51 -04:00
|
|
|
highlights: PropTypes.arrayOf(PropTypes.object),
|
2021-04-19 08:38:03 -04:00
|
|
|
logEntries: PropTypes.object,
|
2021-11-15 07:50:42 -05:00
|
|
|
logEntryAnnotations: PropTypes.object,
|
2021-10-08 05:51:04 -04:00
|
|
|
pdfDownloadUrl: PropTypes.string,
|
|
|
|
pdfUrl: PropTypes.string,
|
2021-10-21 06:31:51 -04:00
|
|
|
pdfViewer: PropTypes.string,
|
|
|
|
position: PropTypes.object,
|
2021-10-15 05:39:56 -04:00
|
|
|
rawLog: PropTypes.string,
|
|
|
|
setAutoCompile: PropTypes.func.isRequired,
|
|
|
|
setDraft: PropTypes.func.isRequired,
|
2021-10-15 05:52:07 -04:00
|
|
|
setError: PropTypes.func.isRequired,
|
2021-10-15 05:39:56 -04:00
|
|
|
setHasLintingError: PropTypes.func.isRequired, // only for storybook
|
2021-10-21 06:31:51 -04:00
|
|
|
setHighlights: PropTypes.func.isRequired,
|
|
|
|
setPosition: PropTypes.func.isRequired,
|
2021-10-15 05:39:56 -04:00
|
|
|
setShowLogs: PropTypes.func.isRequired,
|
2022-03-31 07:22:36 -04:00
|
|
|
toggleLogs: PropTypes.func.isRequired,
|
2021-10-15 05:39:56 -04:00
|
|
|
setStopOnValidationError: PropTypes.func.isRequired,
|
|
|
|
showLogs: PropTypes.bool.isRequired,
|
|
|
|
stopOnValidationError: PropTypes.bool.isRequired,
|
2021-04-27 03:52:58 -04:00
|
|
|
uncompiled: PropTypes.bool,
|
2021-10-15 05:39:56 -04:00
|
|
|
validationIssues: PropTypes.object,
|
2021-10-20 04:45:10 -04:00
|
|
|
firstRenderDone: PropTypes.func,
|
2021-11-30 09:54:14 -05:00
|
|
|
cleanupCompileResult: PropTypes.func,
|
2021-04-27 03:52:58 -04:00
|
|
|
}),
|
2021-04-19 08:38:03 -04:00
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
LocalCompileContext.Provider.propTypes = CompileContextPropTypes
|
|
|
|
|
|
|
|
export function LocalCompileProvider({ children }) {
|
2021-10-15 05:39:56 -04:00
|
|
|
const ide = useIdeContext()
|
|
|
|
|
|
|
|
const { hasPremiumCompile, isProjectOwner } = useEditorContext()
|
|
|
|
|
2022-01-10 10:47:10 -05:00
|
|
|
const { _id: projectId, rootDocId } = useProjectContext()
|
2021-10-15 05:39:56 -04:00
|
|
|
|
|
|
|
// whether a compile is in progress
|
|
|
|
const [compiling, setCompiling] = useState(false)
|
|
|
|
|
2021-10-08 05:51:04 -04:00
|
|
|
// the log entries parsed from the compile output log
|
2021-11-03 10:30:41 -04:00
|
|
|
const [logEntries, setLogEntries] = useScopeValueSetterOnly('pdf.logEntries')
|
2021-10-08 05:51:04 -04:00
|
|
|
|
|
|
|
// annotations for display in the editor, built from the log entries
|
2021-11-15 07:50:42 -05:00
|
|
|
const [logEntryAnnotations, setLogEntryAnnotations] = useScopeValue(
|
|
|
|
'pdf.logEntryAnnotations'
|
|
|
|
)
|
2021-10-08 05:51:04 -04:00
|
|
|
|
2021-10-21 06:31:51 -04:00
|
|
|
// the PDF viewer
|
|
|
|
const [pdfViewer] = useScopeValue('settings.pdfViewer')
|
|
|
|
|
2021-10-08 05:51:04 -04:00
|
|
|
// the URL for downloading the PDF
|
2022-01-10 05:23:05 -05:00
|
|
|
const [pdfDownloadUrl, setPdfDownloadUrl] =
|
|
|
|
useScopeValueSetterOnly('pdf.downloadUrl')
|
2021-10-08 05:51:04 -04:00
|
|
|
|
|
|
|
// the URL for loading the PDF in the preview pane
|
2021-11-03 10:30:41 -04:00
|
|
|
const [pdfUrl, setPdfUrl] = useScopeValueSetterOnly('pdf.url')
|
2021-10-08 05:51:04 -04:00
|
|
|
|
|
|
|
// the project is considered to be "uncompiled" if a doc has changed since the last compile started
|
2021-10-21 11:29:27 -04:00
|
|
|
const [uncompiled, setUncompiled] = useScopeValue('pdf.uncompiled')
|
2021-10-08 05:51:04 -04:00
|
|
|
|
|
|
|
// the id of the CLSI server which ran the compile
|
2021-10-21 06:31:51 -04:00
|
|
|
const [clsiServerId, setClsiServerId] = useState()
|
2021-10-08 05:51:04 -04:00
|
|
|
|
2021-10-15 05:39:56 -04:00
|
|
|
// data received in response to a compile request
|
|
|
|
const [data, setData] = useState()
|
|
|
|
|
2021-10-20 04:45:10 -04:00
|
|
|
// callback to be invoked for PdfJsMetrics
|
|
|
|
const [firstRenderDone, setFirstRenderDone] = useState()
|
|
|
|
|
2021-10-15 05:39:56 -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)
|
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
const toggleLogs = useCallback(() => {
|
|
|
|
setShowLogs(prev => {
|
|
|
|
if (!prev) {
|
|
|
|
sendMBOnce('ide-open-logs-once')
|
|
|
|
}
|
|
|
|
return !prev
|
|
|
|
})
|
|
|
|
}, [setShowLogs])
|
|
|
|
|
2021-10-15 05:39:56 -04:00
|
|
|
// 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()
|
|
|
|
|
2021-10-21 06:31:51 -04:00
|
|
|
// areas to highlight on the PDF, from synctex
|
|
|
|
const [highlights, setHighlights] = useState()
|
|
|
|
|
|
|
|
// scroll position of the PDF
|
|
|
|
const [position, setPosition] = usePersistedState(`pdf.position.${projectId}`)
|
|
|
|
|
2021-10-15 05:39:56 -04:00
|
|
|
// whether autocompile is switched on
|
2021-12-21 08:45:38 -05:00
|
|
|
const [autoCompile, setAutoCompile] = usePersistedState(
|
2021-10-15 05:39:56 -04:00
|
|
|
`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
|
|
|
|
)
|
|
|
|
|
|
|
|
// the Document currently open in the editor
|
|
|
|
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-11-03 10:30:41 -04:00
|
|
|
const cleanupCompileResult = useCallback(() => {
|
|
|
|
setPdfUrl(null)
|
|
|
|
setPdfDownloadUrl(null)
|
|
|
|
setLogEntries(null)
|
|
|
|
setLogEntryAnnotations({})
|
|
|
|
}, [setPdfUrl, setPdfDownloadUrl, setLogEntries, setLogEntryAnnotations])
|
|
|
|
|
2022-03-03 11:28:12 -05:00
|
|
|
const compilingRef = useRef(false)
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
compilingRef.current = compiling
|
|
|
|
}, [compiling])
|
|
|
|
|
2021-10-15 05:39:56 -04:00
|
|
|
// the document compiler
|
|
|
|
const [compiler] = useState(() => {
|
|
|
|
return new DocumentCompiler({
|
2022-01-10 10:47:10 -05:00
|
|
|
projectId,
|
|
|
|
rootDocId,
|
2021-10-15 05:39:56 -04:00
|
|
|
setChangedAt,
|
|
|
|
setCompiling,
|
|
|
|
setData,
|
2021-10-20 04:45:10 -04:00
|
|
|
setFirstRenderDone,
|
2021-10-15 05:39:56 -04:00
|
|
|
setError,
|
2021-11-03 10:30:41 -04:00
|
|
|
cleanupCompileResult,
|
2022-03-03 11:28:12 -05:00
|
|
|
compilingRef,
|
2021-10-15 05:39:56 -04:00
|
|
|
signal,
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
// 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])
|
|
|
|
|
|
|
|
// pass the "uncompiled" value up into the scope for use outside this context provider
|
|
|
|
useEffect(() => {
|
2022-03-15 08:47:01 -04:00
|
|
|
setUncompiled(changedAt > 0)
|
2021-10-15 05:39:56 -04:00
|
|
|
}, [setUncompiled, changedAt])
|
|
|
|
|
|
|
|
// always compile the PDF once after opening the project, after the doc has loaded
|
|
|
|
useEffect(() => {
|
|
|
|
if (!compiledOnce && currentDoc) {
|
|
|
|
setCompiledOnce(true)
|
|
|
|
compiler.compile({ isAutoCompileOnLoad: true })
|
|
|
|
}
|
|
|
|
}, [compiledOnce, currentDoc, compiler])
|
|
|
|
|
|
|
|
// handle the data returned from a compile request
|
|
|
|
// note: this should _only_ run when `data` changes,
|
|
|
|
// the other dependencies must all be static
|
|
|
|
useEffect(() => {
|
2022-03-25 05:42:10 -04:00
|
|
|
const abortController = new AbortController()
|
|
|
|
|
2021-10-15 05:39:56 -04:00
|
|
|
if (data) {
|
|
|
|
if (data.clsiServerId) {
|
|
|
|
setClsiServerId(data.clsiServerId) // set in scope, for PdfSynctexController
|
|
|
|
}
|
|
|
|
|
|
|
|
if (data.outputFiles) {
|
2022-03-25 05:42:10 -04:00
|
|
|
const outputFiles = new Map()
|
|
|
|
|
|
|
|
for (const outputFile of data.outputFiles) {
|
|
|
|
outputFiles.set(outputFile.path, outputFile)
|
|
|
|
}
|
|
|
|
|
|
|
|
// set the PDF URLs
|
2022-05-18 06:37:25 -04:00
|
|
|
const result = handleOutputFiles(outputFiles, projectId, data)
|
|
|
|
if (data.status === 'success') {
|
|
|
|
setPdfDownloadUrl(result.pdfDownloadUrl)
|
|
|
|
setPdfUrl(result.pdfUrl)
|
|
|
|
}
|
2022-03-25 05:42:10 -04:00
|
|
|
|
2022-05-18 06:37:25 -04:00
|
|
|
setFileList(
|
|
|
|
buildFileList(outputFiles, data.clsiServerId, data.compileGroup)
|
|
|
|
)
|
|
|
|
|
|
|
|
// handle log files
|
|
|
|
// asynchronous (TODO: cancel on new compile?)
|
|
|
|
setLogEntryAnnotations(null)
|
|
|
|
setLogEntries(null)
|
|
|
|
setRawLog(null)
|
|
|
|
|
|
|
|
handleLogFiles(outputFiles, data, abortController.signal).then(
|
|
|
|
result => {
|
|
|
|
setRawLog(result.log)
|
|
|
|
setLogEntries(result.logEntries)
|
|
|
|
setLogEntryAnnotations(
|
|
|
|
buildLogEntryAnnotations(
|
|
|
|
result.logEntries.all,
|
|
|
|
ide.fileTreeManager
|
|
|
|
)
|
|
|
|
)
|
|
|
|
|
|
|
|
// 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
|
2022-03-25 05:42:10 -04:00
|
|
|
)
|
|
|
|
}
|
2022-05-18 06:37:25 -04:00
|
|
|
}
|
|
|
|
)
|
2021-10-15 05:39:56 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
switch (data.status) {
|
|
|
|
case 'success':
|
|
|
|
setError(undefined)
|
|
|
|
setShowLogs(false)
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'clsi-maintenance':
|
|
|
|
case 'compile-in-progress':
|
|
|
|
case 'exited':
|
|
|
|
case 'failure':
|
|
|
|
case 'project-too-large':
|
|
|
|
case 'rate-limited':
|
|
|
|
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'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'autocompile-backoff':
|
|
|
|
if (!data.options.isAutoCompileOnLoad) {
|
|
|
|
setError('autocompile-disabled')
|
|
|
|
setAutoCompile(false)
|
|
|
|
}
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'unavailable':
|
|
|
|
setError('clsi-unavailable')
|
|
|
|
break
|
|
|
|
|
|
|
|
case 'validation-problems':
|
|
|
|
setError('validation-problems')
|
|
|
|
setValidationIssues(data.validationProblems)
|
|
|
|
break
|
|
|
|
|
|
|
|
default:
|
|
|
|
setError('error')
|
|
|
|
break
|
|
|
|
}
|
|
|
|
}
|
2022-03-25 05:42:10 -04:00
|
|
|
|
|
|
|
return () => {
|
|
|
|
abortController.abort()
|
|
|
|
}
|
2021-10-15 05:39:56 -04:00
|
|
|
}, [
|
|
|
|
data,
|
|
|
|
ide,
|
|
|
|
hasPremiumCompile,
|
|
|
|
isProjectOwner,
|
|
|
|
projectId,
|
|
|
|
setAutoCompile,
|
|
|
|
setClsiServerId,
|
|
|
|
setLogEntries,
|
|
|
|
setLogEntryAnnotations,
|
|
|
|
setPdfDownloadUrl,
|
|
|
|
setPdfUrl,
|
|
|
|
])
|
|
|
|
|
|
|
|
// switch to logs if there's an error
|
|
|
|
useEffect(() => {
|
|
|
|
if (error) {
|
|
|
|
setShowLogs(true)
|
|
|
|
}
|
|
|
|
}, [error])
|
|
|
|
|
|
|
|
// whether there has been an autocompile linting error, if syntax validation is switched on
|
|
|
|
const autoCompileLintingError = Boolean(
|
|
|
|
autoCompile && syntaxValidation && hasLintingError
|
|
|
|
)
|
|
|
|
|
|
|
|
const codeCheckFailed = stopOnValidationError && autoCompileLintingError
|
|
|
|
|
|
|
|
// the project is available for auto-compiling
|
2021-10-21 06:31:51 -04:00
|
|
|
const canAutoCompile = Boolean(autoCompile && !codeCheckFailed)
|
|
|
|
|
|
|
|
// show that the project has pending changes
|
|
|
|
const hasChanges = Boolean(canAutoCompile && uncompiled && compiledOnce)
|
2021-10-15 05:39:56 -04:00
|
|
|
|
|
|
|
// call the debounced autocompile function if the project is available for auto-compiling and it has changed
|
|
|
|
useEffect(() => {
|
2021-10-21 06:31:51 -04:00
|
|
|
if (canAutoCompile) {
|
|
|
|
if (changedAt > 0) {
|
|
|
|
compiler.debouncedAutoCompile()
|
|
|
|
}
|
2021-10-15 05:39:56 -04:00
|
|
|
} else {
|
|
|
|
compiler.debouncedAutoCompile.cancel()
|
|
|
|
}
|
|
|
|
}, [compiler, canAutoCompile, changedAt])
|
|
|
|
|
|
|
|
// cancel debounced recompile on unmount
|
|
|
|
useEffect(() => {
|
|
|
|
return () => {
|
|
|
|
compiler.debouncedAutoCompile.cancel()
|
|
|
|
}
|
|
|
|
}, [compiler])
|
|
|
|
|
|
|
|
// start a compile manually
|
2021-11-30 09:54:14 -05:00
|
|
|
const startCompile = useCallback(
|
|
|
|
options => {
|
|
|
|
compiler.compile(options)
|
|
|
|
},
|
|
|
|
[compiler]
|
|
|
|
)
|
2021-10-15 05:39:56 -04:00
|
|
|
|
|
|
|
// stop a compile manually
|
|
|
|
const stopCompile = useCallback(() => {
|
|
|
|
compiler.stopCompile()
|
|
|
|
}, [compiler])
|
|
|
|
|
|
|
|
// clear the compile cache
|
|
|
|
const clearCache = useCallback(() => {
|
|
|
|
setClearingCache(true)
|
|
|
|
|
2021-12-07 04:49:18 -05:00
|
|
|
return compiler
|
|
|
|
.clearCache()
|
|
|
|
.then(() => {
|
|
|
|
setFileList(undefined)
|
|
|
|
setPdfDownloadUrl(undefined)
|
|
|
|
setPdfUrl(undefined)
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
setClearingCache(false)
|
|
|
|
})
|
|
|
|
}, [compiler, setPdfDownloadUrl, setPdfUrl])
|
2021-10-15 05:39:56 -04:00
|
|
|
|
|
|
|
// clear the cache then run a compile, triggered by a menu item
|
|
|
|
const recompileFromScratch = useCallback(() => {
|
|
|
|
clearCache().then(() => {
|
|
|
|
compiler.compile()
|
|
|
|
})
|
|
|
|
}, [clearCache, compiler])
|
|
|
|
|
2021-10-08 05:51:04 -04:00
|
|
|
const value = useMemo(
|
|
|
|
() => ({
|
2021-10-15 05:39:56 -04:00
|
|
|
autoCompile,
|
|
|
|
clearCache,
|
|
|
|
clearingCache,
|
2021-10-08 05:51:04 -04:00
|
|
|
clsiServerId,
|
2021-10-15 05:39:56 -04:00
|
|
|
codeCheckFailed,
|
|
|
|
compiling,
|
|
|
|
draft,
|
|
|
|
error,
|
|
|
|
fileList,
|
|
|
|
hasChanges,
|
2021-10-21 06:31:51 -04:00
|
|
|
highlights,
|
2021-11-15 07:50:42 -05:00
|
|
|
logEntryAnnotations,
|
2021-10-08 05:51:04 -04:00
|
|
|
logEntries,
|
|
|
|
pdfDownloadUrl,
|
|
|
|
pdfUrl,
|
2021-10-21 06:31:51 -04:00
|
|
|
pdfViewer,
|
|
|
|
position,
|
2021-10-15 05:39:56 -04:00
|
|
|
rawLog,
|
|
|
|
recompileFromScratch,
|
|
|
|
setAutoCompile,
|
|
|
|
setCompiling,
|
|
|
|
setDraft,
|
2021-10-15 05:52:07 -04:00
|
|
|
setError,
|
2021-10-15 05:39:56 -04:00
|
|
|
setHasLintingError, // only for stories
|
2021-10-21 06:31:51 -04:00
|
|
|
setHighlights,
|
|
|
|
setPosition,
|
2021-10-15 05:39:56 -04:00
|
|
|
setShowLogs,
|
2022-03-31 07:22:36 -04:00
|
|
|
toggleLogs,
|
2021-10-15 05:39:56 -04:00
|
|
|
setStopOnValidationError,
|
|
|
|
showLogs,
|
|
|
|
startCompile,
|
|
|
|
stopCompile,
|
|
|
|
stopOnValidationError,
|
2021-10-08 05:51:04 -04:00
|
|
|
uncompiled,
|
2021-10-15 05:39:56 -04:00
|
|
|
validationIssues,
|
2021-10-20 04:45:10 -04:00
|
|
|
firstRenderDone,
|
2021-11-30 09:54:14 -05:00
|
|
|
setChangedAt,
|
|
|
|
cleanupCompileResult,
|
2021-10-08 05:51:04 -04:00
|
|
|
}),
|
|
|
|
[
|
2021-10-15 05:39:56 -04:00
|
|
|
autoCompile,
|
|
|
|
clearCache,
|
|
|
|
clearingCache,
|
2021-10-08 05:51:04 -04:00
|
|
|
clsiServerId,
|
2021-10-15 05:39:56 -04:00
|
|
|
codeCheckFailed,
|
|
|
|
compiling,
|
|
|
|
draft,
|
|
|
|
error,
|
|
|
|
fileList,
|
|
|
|
hasChanges,
|
2021-10-21 06:31:51 -04:00
|
|
|
highlights,
|
2021-10-08 05:51:04 -04:00
|
|
|
logEntries,
|
2021-11-15 07:50:42 -05:00
|
|
|
logEntryAnnotations,
|
2021-10-21 06:31:51 -04:00
|
|
|
position,
|
2021-10-08 05:51:04 -04:00
|
|
|
pdfDownloadUrl,
|
|
|
|
pdfUrl,
|
2021-10-21 06:31:51 -04:00
|
|
|
pdfViewer,
|
2021-10-15 05:39:56 -04:00
|
|
|
rawLog,
|
|
|
|
recompileFromScratch,
|
|
|
|
setAutoCompile,
|
|
|
|
setDraft,
|
2021-10-15 05:52:07 -04:00
|
|
|
setError,
|
2021-11-03 10:30:41 -04:00
|
|
|
setHasLintingError, // only for stories
|
2021-10-21 06:31:51 -04:00
|
|
|
setHighlights,
|
|
|
|
setPosition,
|
2021-10-15 05:39:56 -04:00
|
|
|
setStopOnValidationError,
|
|
|
|
showLogs,
|
|
|
|
startCompile,
|
|
|
|
stopCompile,
|
|
|
|
stopOnValidationError,
|
2021-10-08 05:51:04 -04:00
|
|
|
uncompiled,
|
2021-10-15 05:39:56 -04:00
|
|
|
validationIssues,
|
2021-10-20 04:45:10 -04:00
|
|
|
firstRenderDone,
|
2021-11-30 09:54:14 -05:00
|
|
|
setChangedAt,
|
|
|
|
cleanupCompileResult,
|
2022-03-31 07:22:36 -04:00
|
|
|
setShowLogs,
|
|
|
|
toggleLogs,
|
2021-10-08 05:51:04 -04:00
|
|
|
]
|
|
|
|
)
|
2021-04-19 08:38:03 -04:00
|
|
|
|
|
|
|
return (
|
2022-03-31 07:22:36 -04:00
|
|
|
<LocalCompileContext.Provider value={value}>
|
|
|
|
{children}
|
|
|
|
</LocalCompileContext.Provider>
|
2021-04-19 08:38:03 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
LocalCompileProvider.propTypes = {
|
2021-04-19 08:38:03 -04:00
|
|
|
children: PropTypes.any,
|
|
|
|
}
|
|
|
|
|
2022-03-31 07:22:36 -04:00
|
|
|
export function useLocalCompileContext(propTypes) {
|
|
|
|
const data = useContext(LocalCompileContext)
|
|
|
|
PropTypes.checkPropTypes(
|
|
|
|
propTypes,
|
|
|
|
data,
|
|
|
|
'data',
|
|
|
|
'LocalCompileContext.Provider'
|
|
|
|
)
|
2021-04-19 08:38:03 -04:00
|
|
|
return data
|
|
|
|
}
|