import { useTranslation } from 'react-i18next' import { memo } from 'react' import classNames from 'classnames' import { useDetachCompileContext as useCompileContext } from '../../../shared/context/detach-compile-context' import { useStopOnFirstError } from '../../../shared/hooks/use-stop-on-first-error' import SplitMenu from '../../../shared/components/split-menu' import Icon from '../../../shared/components/icon' import * as eventTracking from '../../../infrastructure/event-tracking' import BootstrapVersionSwitcher from '@/features/ui/components/bootstrap-5/bootstrap-version-switcher' import OLTooltip from '@/features/ui/components/ol/ol-tooltip' import { DropdownToggleCustom, Dropdown, DropdownDivider, DropdownHeader, DropdownItem, DropdownMenu, DropdownToggle, } from '@/features/ui/components/bootstrap-5/dropdown-menu' import OLButton from '@/features/ui/components/ol/ol-button' import OLButtonGroup from '@/features/ui/components/ol/ol-button-group' import { bsVersion, isBootstrap5 } from '@/features/utils/bootstrap-5' import { useLayoutContext } from '@/shared/context/layout-context' const modifierKey = /Mac/i.test(navigator.platform) ? 'Cmd' : 'Ctrl' function sendEventAndSet( value: T, setter: (value: T) => void, settingName: string ) { eventTracking.sendMB('recompile-setting-changed', { setting: settingName, settingVal: value, }) setter(value) } function PdfCompileButton() { const { animateCompileDropdownArrow, autoCompile, compiling, draft, hasChanges, setAnimateCompileDropdownArrow, setAutoCompile, setDraft, setStopOnValidationError, stopOnFirstError, stopOnValidationError, startCompile, stopCompile, recompileFromScratch, } = useCompileContext() const { enableStopOnFirstError, disableStopOnFirstError } = useStopOnFirstError({ eventSource: 'dropdown' }) const { t } = useTranslation() const { detachRole } = useLayoutContext() const fromScratchWithEvent = () => { eventTracking.sendMB('recompile-setting-changed', { setting: 'from-scratch', }) recompileFromScratch() } const compileButtonLabel = compiling ? `${t('compiling')}…` : t('recompile') const tooltipElement = ( <> {t('recompile_pdf')}{' '} ({modifierKey} + Enter) ) const dropdownToggleClassName = classNames( { 'detach-compile-button-animate': animateCompileDropdownArrow, 'btn-striped-animated': hasChanges, }, 'no-left-border', bsVersion({ bs5: 'dropdown-button-toggle' }) ) const buttonClassName = classNames( { 'btn-striped-animated': hasChanges, 'align-items-center py-0': isBootstrap5(), }, 'no-left-radius px-3' ) return ( startCompile(), text: compileButtonLabel, className: buttonClassName, }} dropdownToggle={{ 'aria-label': t('toggle_compile_options_menu'), handleAnimationEnd: () => setAnimateCompileDropdownArrow(false), className: dropdownToggleClassName, }} dropdown={{ id: 'pdf-recompile-dropdown', }} > {t('auto_compile')} sendEventAndSet(true, setAutoCompile, 'auto-compile') } > {t('on')} sendEventAndSet(false, setAutoCompile, 'auto-compile') } > {t('off')} {t('compile_mode')} sendEventAndSet(false, setDraft, 'compile-mode')} > {t('normal')} sendEventAndSet(true, setDraft, 'compile-mode')} > {t('fast')} [draft] Syntax Checks sendEventAndSet(true, setStopOnValidationError, 'syntax-check') } > {t('stop_on_validation_error')} sendEventAndSet(false, setStopOnValidationError, 'syntax-check') } > {t('ignore_validation_errors')} {t('compile_error_handling')} {t('stop_on_first_error')} {t('try_to_compile_despite_errors')} stopCompile()} disabled={!compiling} aria-disabled={!compiling} > {t('stop_compile')} {t('recompile_from_scratch')} } bs5={ startCompile()} className={buttonClassName} > {t('recompile')} {t('auto_compile')}
  • sendEventAndSet(true, setAutoCompile, 'auto-compile') } trailingIcon={autoCompile ? 'check' : null} > {t('on')}
  • sendEventAndSet(false, setAutoCompile, 'auto-compile') } trailingIcon={!autoCompile ? 'check' : null} > {t('off')}
  • {t('compile_mode')}
  • sendEventAndSet(false, setDraft, 'compile-mode')} trailingIcon={!draft ? 'check' : null} > {t('normal')}
  • sendEventAndSet(true, setDraft, 'compile-mode')} trailingIcon={draft ? 'check' : null} > {t('fast')} [draft]
  • Syntax Checks
  • sendEventAndSet( true, setStopOnValidationError, 'syntax-check' ) } trailingIcon={stopOnValidationError ? 'check' : null} > {t('stop_on_validation_error')}
  • sendEventAndSet( false, setStopOnValidationError, 'syntax-check' ) } trailingIcon={!stopOnValidationError ? 'check' : null} > {t('ignore_validation_errors')}
  • {t('compile_error_handling')}
  • {t('stop_on_first_error')}
  • {t('try_to_compile_despite_errors')}
  • stopCompile()} disabled={!compiling} aria-disabled={!compiling} > {t('stop_compile')}
  • {t('recompile_from_scratch')}
  • } /> ) } export default memo(PdfCompileButton)