2022-11-29 13:00:10 -05:00
|
|
|
import { createContext, useContext, useMemo } from 'react'
|
|
|
|
import type { PropsWithChildren } from 'react'
|
|
|
|
import type {
|
|
|
|
FontFamily,
|
|
|
|
LineHeight,
|
|
|
|
OverallTheme,
|
|
|
|
} from '../../../../../modules/source-editor/frontend/js/extensions/theme'
|
|
|
|
import type {
|
|
|
|
Keybindings,
|
|
|
|
PdfViewer,
|
|
|
|
ProjectCompiler,
|
|
|
|
} from '../../../../../types/project-settings'
|
2022-12-22 13:42:28 -05:00
|
|
|
import useSetProjectWideSettings from '../hooks/use-set-project-wide-settings'
|
2022-12-22 19:41:16 -05:00
|
|
|
import useSetUserWideSettings from '../hooks/use-set-user-wide-settings'
|
2022-11-29 13:00:10 -05:00
|
|
|
|
|
|
|
type ProjectSettingsContextValue = {
|
2022-12-22 13:42:28 -05:00
|
|
|
compiler?: ProjectCompiler
|
2022-11-29 13:00:10 -05:00
|
|
|
setCompiler: (compiler: ProjectCompiler) => void
|
2022-12-22 13:42:28 -05:00
|
|
|
imageName?: string
|
2022-11-29 13:00:10 -05:00
|
|
|
setImageName: (imageName: string) => void
|
2022-12-22 13:42:28 -05:00
|
|
|
rootDocId?: string
|
2022-11-29 13:00:10 -05:00
|
|
|
setRootDocId: (rootDocId: string) => void
|
2022-12-22 13:42:28 -05:00
|
|
|
spellCheckLanguage?: string
|
2022-11-29 13:00:10 -05:00
|
|
|
setSpellCheckLanguage: (spellCheckLanguage: string) => void
|
|
|
|
autoComplete: boolean
|
|
|
|
setAutoComplete: (autoComplete: boolean) => void
|
|
|
|
autoPairDelimiters: boolean
|
|
|
|
setAutoPairDelimiters: (autoPairDelimiters: boolean) => void
|
|
|
|
syntaxValidation: boolean
|
|
|
|
setSyntaxValidation: (syntaxValidation: boolean) => void
|
|
|
|
mode: Keybindings
|
|
|
|
setMode: (mode: Keybindings) => void
|
|
|
|
editorTheme: string
|
|
|
|
setEditorTheme: (editorTheme: string) => void
|
|
|
|
overallTheme: OverallTheme
|
|
|
|
setOverallTheme: (overallTheme: OverallTheme) => void
|
|
|
|
fontSize: string
|
|
|
|
setFontSize: (fontSize: string) => void
|
|
|
|
fontFamily: FontFamily
|
|
|
|
setFontFamily: (fontFamily: FontFamily) => void
|
|
|
|
lineHeight: LineHeight
|
|
|
|
setLineHeight: (lineHeight: LineHeight) => void
|
|
|
|
pdfViewer: PdfViewer
|
|
|
|
setPdfViewer: (pdfViewer: PdfViewer) => void
|
|
|
|
}
|
|
|
|
|
|
|
|
export const ProjectSettingsContext = createContext<
|
|
|
|
ProjectSettingsContextValue | undefined
|
|
|
|
>(undefined)
|
|
|
|
|
|
|
|
export function ProjectSettingsProvider({
|
|
|
|
children,
|
|
|
|
}: PropsWithChildren<Record<string, never>>) {
|
2022-12-22 13:42:28 -05:00
|
|
|
const {
|
|
|
|
compiler,
|
|
|
|
setCompiler,
|
|
|
|
imageName,
|
|
|
|
setImageName,
|
|
|
|
rootDocId,
|
|
|
|
setRootDocId,
|
|
|
|
spellCheckLanguage,
|
|
|
|
setSpellCheckLanguage,
|
|
|
|
} = useSetProjectWideSettings()
|
|
|
|
|
2022-12-22 19:41:16 -05:00
|
|
|
const {
|
|
|
|
autoComplete,
|
|
|
|
setAutoComplete,
|
|
|
|
autoPairDelimiters,
|
|
|
|
setAutoPairDelimiters,
|
|
|
|
syntaxValidation,
|
|
|
|
setSyntaxValidation,
|
|
|
|
editorTheme,
|
|
|
|
setEditorTheme,
|
|
|
|
overallTheme,
|
|
|
|
setOverallTheme,
|
|
|
|
mode,
|
|
|
|
setMode,
|
|
|
|
fontSize,
|
|
|
|
setFontSize,
|
|
|
|
fontFamily,
|
|
|
|
setFontFamily,
|
|
|
|
lineHeight,
|
|
|
|
setLineHeight,
|
|
|
|
pdfViewer,
|
|
|
|
setPdfViewer,
|
|
|
|
} = useSetUserWideSettings()
|
2022-11-29 13:00:10 -05:00
|
|
|
|
|
|
|
const value: ProjectSettingsContextValue = useMemo(
|
|
|
|
() => ({
|
|
|
|
compiler,
|
|
|
|
setCompiler,
|
|
|
|
imageName,
|
|
|
|
setImageName,
|
|
|
|
rootDocId,
|
|
|
|
setRootDocId,
|
|
|
|
spellCheckLanguage,
|
|
|
|
setSpellCheckLanguage,
|
|
|
|
autoComplete,
|
|
|
|
setAutoComplete,
|
|
|
|
autoPairDelimiters,
|
|
|
|
setAutoPairDelimiters,
|
|
|
|
syntaxValidation,
|
|
|
|
setSyntaxValidation,
|
|
|
|
editorTheme,
|
|
|
|
setEditorTheme,
|
|
|
|
overallTheme,
|
|
|
|
setOverallTheme,
|
|
|
|
mode,
|
|
|
|
setMode,
|
|
|
|
fontSize,
|
|
|
|
setFontSize,
|
|
|
|
fontFamily,
|
|
|
|
setFontFamily,
|
|
|
|
lineHeight,
|
|
|
|
setLineHeight,
|
|
|
|
pdfViewer,
|
|
|
|
setPdfViewer,
|
|
|
|
}),
|
|
|
|
[
|
|
|
|
compiler,
|
|
|
|
setCompiler,
|
|
|
|
imageName,
|
|
|
|
setImageName,
|
|
|
|
rootDocId,
|
|
|
|
setRootDocId,
|
|
|
|
spellCheckLanguage,
|
|
|
|
setSpellCheckLanguage,
|
|
|
|
autoComplete,
|
|
|
|
setAutoComplete,
|
|
|
|
autoPairDelimiters,
|
|
|
|
setAutoPairDelimiters,
|
|
|
|
syntaxValidation,
|
|
|
|
setSyntaxValidation,
|
|
|
|
editorTheme,
|
|
|
|
setEditorTheme,
|
|
|
|
overallTheme,
|
|
|
|
setOverallTheme,
|
|
|
|
mode,
|
|
|
|
setMode,
|
|
|
|
fontSize,
|
|
|
|
setFontSize,
|
|
|
|
fontFamily,
|
|
|
|
setFontFamily,
|
|
|
|
lineHeight,
|
|
|
|
setLineHeight,
|
|
|
|
pdfViewer,
|
|
|
|
setPdfViewer,
|
|
|
|
]
|
|
|
|
)
|
|
|
|
|
|
|
|
return (
|
|
|
|
<ProjectSettingsContext.Provider value={value}>
|
|
|
|
{children}
|
|
|
|
</ProjectSettingsContext.Provider>
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useProjectSettingsContext() {
|
|
|
|
const context = useContext(ProjectSettingsContext)
|
|
|
|
|
|
|
|
if (!context) {
|
|
|
|
throw new Error(
|
|
|
|
'useProjectSettingsContext is only available inside ProjectSettingsProvider'
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
return context
|
|
|
|
}
|