2021-09-30 07:29:25 -04:00
|
|
|
import { useTranslation } from 'react-i18next'
|
2021-10-08 05:23:33 -04:00
|
|
|
import { memo } from 'react'
|
2023-02-21 09:34:35 -05:00
|
|
|
import classNames from 'classnames'
|
2022-03-31 07:22:36 -04:00
|
|
|
import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context'
|
2022-06-13 08:08:38 -04:00
|
|
|
import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error'
|
2023-02-21 09:34:35 -05:00
|
|
|
import SplitMenu from '../../../shared/components/split-menu'
|
|
|
|
import Icon from '../../../shared/components/icon'
|
|
|
|
|
|
|
|
const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl'
|
2021-10-12 04:47:46 -04:00
|
|
|
|
2021-09-30 07:29:25 -04:00
|
|
|
function PdfCompileButton() {
|
|
|
|
const {
|
2022-06-13 08:29:35 -04:00
|
|
|
animateCompileDropdownArrow,
|
2021-09-30 07:29:25 -04:00
|
|
|
autoCompile,
|
|
|
|
compiling,
|
|
|
|
draft,
|
|
|
|
hasChanges,
|
2022-06-13 08:29:35 -04:00
|
|
|
setAnimateCompileDropdownArrow,
|
2021-09-30 07:29:25 -04:00
|
|
|
setAutoCompile,
|
|
|
|
setDraft,
|
|
|
|
setStopOnValidationError,
|
2022-06-02 10:35:43 -04:00
|
|
|
stopOnFirstError,
|
2021-10-15 05:39:56 -04:00
|
|
|
stopOnValidationError,
|
2021-10-08 05:23:33 -04:00
|
|
|
startCompile,
|
2021-09-30 07:29:25 -04:00
|
|
|
stopCompile,
|
|
|
|
recompileFromScratch,
|
2021-10-15 05:39:56 -04:00
|
|
|
} = useCompileContext()
|
2022-06-13 08:08:38 -04:00
|
|
|
const { enableStopOnFirstError, disableStopOnFirstError } =
|
|
|
|
useStopOnFirstError({ eventSource: 'dropdown' })
|
2021-09-30 07:29:25 -04:00
|
|
|
|
|
|
|
const { t } = useTranslation()
|
|
|
|
|
2023-02-21 09:34:35 -05:00
|
|
|
const compileButtonLabel = compiling ? `${t('compiling')}…` : t('recompile')
|
|
|
|
const tooltipElement = (
|
|
|
|
<>
|
|
|
|
{t('recompile_pdf')}{' '}
|
|
|
|
<span className="keyboard-shortcut">({modifierKey} + Enter)</span>
|
|
|
|
</>
|
|
|
|
)
|
|
|
|
|
|
|
|
const dropdownToggleClassName = classNames({
|
|
|
|
'detach-compile-button-animate': animateCompileDropdownArrow,
|
|
|
|
'btn-striped-animated': hasChanges,
|
|
|
|
})
|
|
|
|
|
|
|
|
const buttonClassName = classNames({
|
|
|
|
'btn-striped-animated': hasChanges,
|
2023-04-11 09:17:04 -04:00
|
|
|
'no-left-radius': true,
|
2023-02-21 09:34:35 -05:00
|
|
|
})
|
|
|
|
|
2021-09-30 07:29:25 -04:00
|
|
|
return (
|
2023-02-21 09:34:35 -05:00
|
|
|
<SplitMenu
|
|
|
|
bsStyle="primary"
|
|
|
|
bsSize="xs"
|
|
|
|
disabled={compiling}
|
|
|
|
button={{
|
|
|
|
tooltip: {
|
|
|
|
description: tooltipElement,
|
|
|
|
id: 'logs-toggle',
|
|
|
|
tooltipProps: { className: 'keyboard-tooltip' },
|
|
|
|
overlayProps: { delayShow: 500 },
|
|
|
|
},
|
|
|
|
icon: { type: 'refresh', spin: compiling },
|
|
|
|
onClick: () => startCompile(),
|
|
|
|
text: compileButtonLabel,
|
|
|
|
className: buttonClassName,
|
|
|
|
}}
|
|
|
|
dropdownToggle={{
|
|
|
|
'aria-label': t('toggle_compile_options_menu'),
|
|
|
|
handleAnimationEnd: () => setAnimateCompileDropdownArrow(false),
|
|
|
|
className: dropdownToggleClassName,
|
|
|
|
}}
|
|
|
|
dropdown={{
|
|
|
|
id: 'pdf-recompile-dropdown',
|
|
|
|
}}
|
2021-09-30 07:29:25 -04:00
|
|
|
>
|
2023-02-21 09:34:35 -05:00
|
|
|
<SplitMenu.Item header>{t('auto_compile')}</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={() => setAutoCompile(true)}>
|
|
|
|
<Icon type={autoCompile ? 'check' : ''} fw />
|
|
|
|
{t('on')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={() => setAutoCompile(false)}>
|
|
|
|
<Icon type={!autoCompile ? 'check' : ''} fw />
|
|
|
|
{t('off')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item header>{t('compile_mode')}</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={() => setDraft(false)}>
|
|
|
|
<Icon type={!draft ? 'check' : ''} fw />
|
|
|
|
{t('normal')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={() => setDraft(true)}>
|
|
|
|
<Icon type={draft ? 'check' : ''} fw />
|
|
|
|
{t('fast')} <span className="subdued">[draft]</span>
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item header>Syntax Checks</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={() => setStopOnValidationError(true)}>
|
|
|
|
<Icon type={stopOnValidationError ? 'check' : ''} fw />
|
|
|
|
{t('stop_on_validation_error')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={() => setStopOnValidationError(false)}>
|
|
|
|
<Icon type={!stopOnValidationError ? 'check' : ''} fw />
|
|
|
|
{t('ignore_validation_errors')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item header>{t('compile_error_handling')}</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={enableStopOnFirstError}>
|
|
|
|
<Icon type={stopOnFirstError ? 'check' : ''} fw />
|
|
|
|
{t('stop_on_first_error')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item onSelect={disableStopOnFirstError}>
|
|
|
|
<Icon type={!stopOnFirstError ? 'check' : ''} fw />
|
|
|
|
{t('try_to_compile_despite_errors')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item divider />
|
|
|
|
|
|
|
|
<SplitMenu.Item
|
|
|
|
onSelect={() => stopCompile()}
|
|
|
|
disabled={!compiling}
|
|
|
|
aria-disabled={!compiling}
|
|
|
|
>
|
|
|
|
{t('stop_compile')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
|
|
|
|
<SplitMenu.Item
|
|
|
|
onSelect={() => recompileFromScratch()}
|
|
|
|
disabled={compiling}
|
|
|
|
aria-disabled={compiling}
|
|
|
|
>
|
|
|
|
{t('recompile_from_scratch')}
|
|
|
|
</SplitMenu.Item>
|
|
|
|
</SplitMenu>
|
2021-09-30 07:29:25 -04:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export default memo(PdfCompileButton)
|