2022-03-31 07:22:36 -04:00
|
|
|
import { createContext, useContext, useMemo } from 'react'
|
|
|
|
import PropTypes from 'prop-types'
|
|
|
|
import {
|
|
|
|
useLocalCompileContext,
|
|
|
|
CompileContextPropTypes,
|
|
|
|
} from './local-compile-context'
|
|
|
|
import useDetachStateWatcher from '../hooks/use-detach-state-watcher'
|
|
|
|
import useDetachAction from '../hooks/use-detach-action'
|
|
|
|
|
|
|
|
export const DetachCompileContext = createContext()
|
|
|
|
|
|
|
|
DetachCompileContext.Provider.propTypes = CompileContextPropTypes
|
|
|
|
|
|
|
|
export function DetachCompileProvider({ children }) {
|
|
|
|
const localCompileContext = useLocalCompileContext()
|
|
|
|
if (!localCompileContext) {
|
|
|
|
throw new Error(
|
|
|
|
'DetachCompileProvider is only available inside LocalCompileProvider'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
const {
|
2022-06-13 08:29:35 -04:00
|
|
|
animateCompileDropdownArrow: _animateCompileDropdownArrow,
|
2022-03-31 07:22:36 -04:00
|
|
|
autoCompile: _autoCompile,
|
|
|
|
clearingCache: _clearingCache,
|
|
|
|
clsiServerId: _clsiServerId,
|
|
|
|
codeCheckFailed: _codeCheckFailed,
|
|
|
|
compiling: _compiling,
|
2022-06-21 08:15:26 -04:00
|
|
|
deliveryLatencies: _deliveryLatencies,
|
2022-03-31 07:22:36 -04:00
|
|
|
draft: _draft,
|
|
|
|
error: _error,
|
|
|
|
fileList: _fileList,
|
|
|
|
hasChanges: _hasChanges,
|
|
|
|
highlights: _highlights,
|
2022-06-09 10:47:53 -04:00
|
|
|
lastCompileOptions: _lastCompileOptions,
|
2022-03-31 07:22:36 -04:00
|
|
|
logEntries: _logEntries,
|
|
|
|
logEntryAnnotations: _logEntryAnnotations,
|
2022-07-06 07:06:53 -04:00
|
|
|
pdfFile: _pdfFile,
|
2022-03-31 07:22:36 -04:00
|
|
|
pdfViewer: _pdfViewer,
|
|
|
|
position: _position,
|
|
|
|
rawLog: _rawLog,
|
2022-06-13 08:29:35 -04:00
|
|
|
setAnimateCompileDropdownArrow: _setAnimateCompileDropdownArrow,
|
2022-03-31 07:22:36 -04:00
|
|
|
setAutoCompile: _setAutoCompile,
|
|
|
|
setDraft: _setDraft,
|
|
|
|
setError: _setError,
|
|
|
|
setHasLintingError: _setHasLintingError,
|
|
|
|
setHighlights: _setHighlights,
|
|
|
|
setPosition: _setPosition,
|
2022-07-13 04:33:47 -04:00
|
|
|
setShowCompileTimeWarning: _setShowCompileTimeWarning,
|
2022-03-31 07:22:36 -04:00
|
|
|
setShowLogs: _setShowLogs,
|
|
|
|
toggleLogs: _toggleLogs,
|
2022-06-02 10:35:43 -04:00
|
|
|
setStopOnFirstError: _setStopOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
setStopOnValidationError: _setStopOnValidationError,
|
|
|
|
showLogs: _showLogs,
|
2022-07-13 04:33:47 -04:00
|
|
|
showCompileTimeWarning: _showCompileTimeWarning,
|
2022-06-21 08:15:26 -04:00
|
|
|
showFasterCompilesFeedbackUI: _showFasterCompilesFeedbackUI,
|
2022-06-02 10:35:43 -04:00
|
|
|
stopOnFirstError: _stopOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
stopOnValidationError: _stopOnValidationError,
|
2022-06-07 07:55:48 -04:00
|
|
|
stoppedOnFirstError: _stoppedOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
uncompiled: _uncompiled,
|
|
|
|
validationIssues: _validationIssues,
|
|
|
|
firstRenderDone: _firstRenderDone,
|
|
|
|
cleanupCompileResult: _cleanupCompileResult,
|
|
|
|
recompileFromScratch: _recompileFromScratch,
|
|
|
|
setCompiling: _setCompiling,
|
|
|
|
startCompile: _startCompile,
|
|
|
|
stopCompile: _stopCompile,
|
|
|
|
setChangedAt: _setChangedAt,
|
|
|
|
clearCache: _clearCache,
|
|
|
|
} = localCompileContext
|
|
|
|
|
2022-06-13 08:29:35 -04:00
|
|
|
const [animateCompileDropdownArrow] = useDetachStateWatcher(
|
|
|
|
'animateCompileDropdownArrow',
|
|
|
|
_animateCompileDropdownArrow,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const [autoCompile] = useDetachStateWatcher(
|
|
|
|
'autoCompile',
|
|
|
|
_autoCompile,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [clearingCache] = useDetachStateWatcher(
|
|
|
|
'clearingCache',
|
|
|
|
_clearingCache,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [clsiServerId] = useDetachStateWatcher(
|
|
|
|
'clsiServerId',
|
|
|
|
_clsiServerId,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [codeCheckFailed] = useDetachStateWatcher(
|
|
|
|
'codeCheckFailed',
|
|
|
|
_codeCheckFailed,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [compiling] = useDetachStateWatcher(
|
|
|
|
'compiling',
|
|
|
|
_compiling,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-06-21 08:15:26 -04:00
|
|
|
const [deliveryLatencies] = useDetachStateWatcher(
|
|
|
|
'deliveryLatencies',
|
|
|
|
_deliveryLatencies,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const [draft] = useDetachStateWatcher('draft', _draft, 'detacher', 'detached')
|
|
|
|
const [error] = useDetachStateWatcher('error', _error, 'detacher', 'detached')
|
|
|
|
const [fileList] = useDetachStateWatcher(
|
|
|
|
'fileList',
|
|
|
|
_fileList,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [hasChanges] = useDetachStateWatcher(
|
|
|
|
'hasChanges',
|
|
|
|
_hasChanges,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [highlights] = useDetachStateWatcher(
|
|
|
|
'highlights',
|
|
|
|
_highlights,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-06-09 10:47:53 -04:00
|
|
|
const [lastCompileOptions] = useDetachStateWatcher(
|
|
|
|
'lastCompileOptions',
|
|
|
|
_lastCompileOptions,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const [logEntries] = useDetachStateWatcher(
|
|
|
|
'logEntries',
|
|
|
|
_logEntries,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [logEntryAnnotations] = useDetachStateWatcher(
|
|
|
|
'logEntryAnnotations',
|
|
|
|
_logEntryAnnotations,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-07-06 07:06:53 -04:00
|
|
|
const [pdfFile] = useDetachStateWatcher(
|
|
|
|
'pdfFile',
|
|
|
|
_pdfFile,
|
2022-06-21 08:15:26 -04:00
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const [pdfViewer] = useDetachStateWatcher(
|
|
|
|
'pdfViewer',
|
|
|
|
_pdfViewer,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [position] = useDetachStateWatcher(
|
|
|
|
'position',
|
|
|
|
_position,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [rawLog] = useDetachStateWatcher(
|
|
|
|
'rawLog',
|
|
|
|
_rawLog,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-07-13 04:33:47 -04:00
|
|
|
const [showCompileTimeWarning] = useDetachStateWatcher(
|
|
|
|
'showCompileTimeWarning',
|
|
|
|
_showCompileTimeWarning,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const [showLogs] = useDetachStateWatcher(
|
|
|
|
'showLogs',
|
|
|
|
_showLogs,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-06-21 08:15:26 -04:00
|
|
|
const [showFasterCompilesFeedbackUI] = useDetachStateWatcher(
|
|
|
|
'showFasterCompilesFeedbackUI',
|
|
|
|
_showFasterCompilesFeedbackUI,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-06-02 10:35:43 -04:00
|
|
|
const [stopOnFirstError] = useDetachStateWatcher(
|
|
|
|
'stopOnFirstError',
|
|
|
|
_stopOnFirstError,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const [stopOnValidationError] = useDetachStateWatcher(
|
|
|
|
'stopOnValidationError',
|
|
|
|
_stopOnValidationError,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-06-07 07:55:48 -04:00
|
|
|
const [stoppedOnFirstError] = useDetachStateWatcher(
|
|
|
|
'stoppedOnFirstError',
|
|
|
|
_stoppedOnFirstError,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const [uncompiled] = useDetachStateWatcher(
|
|
|
|
'uncompiled',
|
|
|
|
_uncompiled,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const [validationIssues] = useDetachStateWatcher(
|
|
|
|
'validationIssues',
|
|
|
|
_validationIssues,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
|
2022-06-13 08:29:35 -04:00
|
|
|
const setAnimateCompileDropdownArrow = useDetachAction(
|
|
|
|
'setAnimateCompileDropdownArrow',
|
|
|
|
_setAnimateCompileDropdownArrow,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const setAutoCompile = useDetachAction(
|
|
|
|
'setAutoCompile',
|
|
|
|
_setAutoCompile,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const setDraft = useDetachAction(
|
|
|
|
'setDraft',
|
|
|
|
_setDraft,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const setError = useDetachAction(
|
|
|
|
'setError',
|
|
|
|
_setError,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const setPosition = useDetachAction(
|
|
|
|
'setPosition',
|
|
|
|
_setPosition,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const firstRenderDone = useDetachAction(
|
|
|
|
'firstRenderDone',
|
|
|
|
_firstRenderDone,
|
2022-07-13 05:06:41 -04:00
|
|
|
'detached',
|
|
|
|
'detacher'
|
2022-03-31 07:22:36 -04:00
|
|
|
)
|
|
|
|
const setHasLintingError = useDetachAction(
|
|
|
|
'setHasLintingError',
|
|
|
|
_setHasLintingError,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const setHighlights = useDetachAction(
|
|
|
|
'setHighlights',
|
|
|
|
_setHighlights,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
2022-07-13 04:33:47 -04:00
|
|
|
const setShowCompileTimeWarning = useDetachAction(
|
|
|
|
'setShowCompileTimeWarning',
|
|
|
|
_setShowCompileTimeWarning,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const setShowLogs = useDetachAction(
|
|
|
|
'setShowLogs',
|
|
|
|
_setShowLogs,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const toggleLogs = useDetachAction(
|
|
|
|
'toggleLogs',
|
|
|
|
_toggleLogs,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
2022-06-02 10:35:43 -04:00
|
|
|
const setStopOnFirstError = useDetachAction(
|
|
|
|
'setStopOnFirstError',
|
|
|
|
_setStopOnFirstError,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
2022-03-31 07:22:36 -04:00
|
|
|
const setStopOnValidationError = useDetachAction(
|
|
|
|
'setStopOnValidationError',
|
|
|
|
_setStopOnValidationError,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const cleanupCompileResult = useDetachAction(
|
|
|
|
'cleanupCompileResult',
|
|
|
|
_cleanupCompileResult,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const recompileFromScratch = useDetachAction(
|
|
|
|
'recompileFromScratch',
|
|
|
|
_recompileFromScratch,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const setCompiling = useDetachAction(
|
|
|
|
'setCompiling',
|
|
|
|
_setCompiling,
|
|
|
|
'detacher',
|
|
|
|
'detached'
|
|
|
|
)
|
|
|
|
const startCompile = useDetachAction(
|
|
|
|
'startCompile',
|
|
|
|
_startCompile,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const stopCompile = useDetachAction(
|
|
|
|
'stopCompile',
|
|
|
|
_stopCompile,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const setChangedAt = useDetachAction(
|
|
|
|
'setChangedAt',
|
|
|
|
_setChangedAt,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
const clearCache = useDetachAction(
|
|
|
|
'clearCache',
|
|
|
|
_clearCache,
|
|
|
|
'detached',
|
|
|
|
'detacher'
|
|
|
|
)
|
|
|
|
|
|
|
|
const value = useMemo(
|
|
|
|
() => ({
|
2022-06-13 08:29:35 -04:00
|
|
|
animateCompileDropdownArrow,
|
2022-03-31 07:22:36 -04:00
|
|
|
autoCompile,
|
|
|
|
clearCache,
|
|
|
|
clearingCache,
|
|
|
|
clsiServerId,
|
|
|
|
codeCheckFailed,
|
|
|
|
compiling,
|
2022-06-21 08:15:26 -04:00
|
|
|
deliveryLatencies,
|
2022-03-31 07:22:36 -04:00
|
|
|
draft,
|
|
|
|
error,
|
|
|
|
fileList,
|
|
|
|
hasChanges,
|
|
|
|
highlights,
|
2022-06-09 10:47:53 -04:00
|
|
|
lastCompileOptions,
|
2022-03-31 07:22:36 -04:00
|
|
|
logEntryAnnotations,
|
|
|
|
logEntries,
|
2022-07-13 08:56:30 -04:00
|
|
|
pdfDownloadUrl: pdfFile?.pdfDownloadUrl,
|
2022-07-06 07:06:53 -04:00
|
|
|
pdfFile,
|
2022-07-13 08:56:30 -04:00
|
|
|
pdfUrl: pdfFile?.pdfUrl,
|
2022-03-31 07:22:36 -04:00
|
|
|
pdfViewer,
|
|
|
|
position,
|
|
|
|
rawLog,
|
|
|
|
recompileFromScratch,
|
2022-06-13 08:29:35 -04:00
|
|
|
setAnimateCompileDropdownArrow,
|
2022-03-31 07:22:36 -04:00
|
|
|
setAutoCompile,
|
|
|
|
setCompiling,
|
|
|
|
setDraft,
|
|
|
|
setError,
|
|
|
|
setHasLintingError,
|
|
|
|
setHighlights,
|
|
|
|
setPosition,
|
2022-07-13 04:33:47 -04:00
|
|
|
setShowCompileTimeWarning,
|
2022-03-31 07:22:36 -04:00
|
|
|
setShowLogs,
|
|
|
|
toggleLogs,
|
2022-06-02 10:35:43 -04:00
|
|
|
setStopOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
setStopOnValidationError,
|
|
|
|
showLogs,
|
2022-07-13 04:33:47 -04:00
|
|
|
showCompileTimeWarning,
|
2022-06-21 08:15:26 -04:00
|
|
|
showFasterCompilesFeedbackUI,
|
2022-03-31 07:22:36 -04:00
|
|
|
startCompile,
|
|
|
|
stopCompile,
|
2022-06-02 10:35:43 -04:00
|
|
|
stopOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
stopOnValidationError,
|
2022-06-07 07:55:48 -04:00
|
|
|
stoppedOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
uncompiled,
|
|
|
|
validationIssues,
|
|
|
|
firstRenderDone,
|
|
|
|
setChangedAt,
|
|
|
|
cleanupCompileResult,
|
|
|
|
}),
|
|
|
|
[
|
2022-06-13 08:29:35 -04:00
|
|
|
animateCompileDropdownArrow,
|
2022-03-31 07:22:36 -04:00
|
|
|
autoCompile,
|
|
|
|
clearCache,
|
|
|
|
clearingCache,
|
|
|
|
clsiServerId,
|
|
|
|
codeCheckFailed,
|
|
|
|
compiling,
|
2022-06-21 08:15:26 -04:00
|
|
|
deliveryLatencies,
|
2022-03-31 07:22:36 -04:00
|
|
|
draft,
|
|
|
|
error,
|
|
|
|
fileList,
|
|
|
|
hasChanges,
|
|
|
|
highlights,
|
2022-06-09 10:47:53 -04:00
|
|
|
lastCompileOptions,
|
2022-03-31 07:22:36 -04:00
|
|
|
logEntryAnnotations,
|
|
|
|
logEntries,
|
2022-07-06 07:06:53 -04:00
|
|
|
pdfFile,
|
2022-03-31 07:22:36 -04:00
|
|
|
pdfViewer,
|
|
|
|
position,
|
|
|
|
rawLog,
|
|
|
|
recompileFromScratch,
|
2022-06-13 08:29:35 -04:00
|
|
|
setAnimateCompileDropdownArrow,
|
2022-03-31 07:22:36 -04:00
|
|
|
setAutoCompile,
|
|
|
|
setCompiling,
|
|
|
|
setDraft,
|
|
|
|
setError,
|
|
|
|
setHasLintingError,
|
|
|
|
setHighlights,
|
|
|
|
setPosition,
|
2022-07-13 04:33:47 -04:00
|
|
|
setShowCompileTimeWarning,
|
2022-03-31 07:22:36 -04:00
|
|
|
setShowLogs,
|
|
|
|
toggleLogs,
|
2022-06-02 10:35:43 -04:00
|
|
|
setStopOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
setStopOnValidationError,
|
2022-07-13 04:33:47 -04:00
|
|
|
showCompileTimeWarning,
|
2022-03-31 07:22:36 -04:00
|
|
|
showLogs,
|
2022-06-21 08:15:26 -04:00
|
|
|
showFasterCompilesFeedbackUI,
|
2022-03-31 07:22:36 -04:00
|
|
|
startCompile,
|
|
|
|
stopCompile,
|
2022-06-02 10:35:43 -04:00
|
|
|
stopOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
stopOnValidationError,
|
2022-06-07 07:55:48 -04:00
|
|
|
stoppedOnFirstError,
|
2022-03-31 07:22:36 -04:00
|
|
|
uncompiled,
|
|
|
|
validationIssues,
|
|
|
|
firstRenderDone,
|
|
|
|
setChangedAt,
|
|
|
|
cleanupCompileResult,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<DetachCompileContext.Provider value={value}>
|
|
|
|
{children}
|
|
|
|
</DetachCompileContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
DetachCompileProvider.propTypes = {
|
|
|
|
children: PropTypes.any,
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useDetachCompileContext(propTypes) {
|
|
|
|
const data = useContext(DetachCompileContext)
|
|
|
|
PropTypes.checkPropTypes(
|
|
|
|
propTypes,
|
|
|
|
data,
|
|
|
|
'data',
|
|
|
|
'DetachCompileContext.Provider'
|
|
|
|
)
|
|
|
|
return data
|
|
|
|
}
|