mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-21 20:47:08 -05:00
Merge pull request #20381 from overleaf/ae-api-settings
Add "settings" object to global scope store GitOrigin-RevId: 1d5c7c3a1b417be0726c4a5e95e611ded47c13c4
This commit is contained in:
parent
9e15c73228
commit
2c6aa3d4a7
8 changed files with 29 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { Keybindings } from '../../../../../../types/project-settings'
|
import type { Keybindings } from '../../../../../../types/user-settings'
|
||||||
import { useProjectSettingsContext } from '../../context/project-settings-context'
|
import { useProjectSettingsContext } from '../../context/project-settings-context'
|
||||||
import SettingsMenuSelect from './settings-menu-select'
|
import SettingsMenuSelect from './settings-menu-select'
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
import { useTranslation } from 'react-i18next'
|
import { useTranslation } from 'react-i18next'
|
||||||
import type { PdfViewer } from '../../../../../../types/project-settings'
|
import type { PdfViewer } from '../../../../../../types/user-settings'
|
||||||
import { useProjectSettingsContext } from '../../context/project-settings-context'
|
import { useProjectSettingsContext } from '../../context/project-settings-context'
|
||||||
import SettingsMenuSelect from './settings-menu-select'
|
import SettingsMenuSelect from './settings-menu-select'
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,7 @@ export const IdeReactContext = createContext<IdeReactContextValue | undefined>(
|
||||||
)
|
)
|
||||||
|
|
||||||
function populateIdeReactScope(store: ReactScopeValueStore) {
|
function populateIdeReactScope(store: ReactScopeValueStore) {
|
||||||
|
store.set('settings', {})
|
||||||
store.set('sync_tex_error', false)
|
store.set('sync_tex_error', false)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -27,6 +27,8 @@ export const IdeProvider: FC<{
|
||||||
* - `project.spellcheckLanguage`
|
* - `project.spellcheckLanguage`
|
||||||
* - `editor.open_doc_name`,
|
* - `editor.open_doc_name`,
|
||||||
* - `editor.open_doc_id`,
|
* - `editor.open_doc_id`,
|
||||||
|
* - `settings.theme`
|
||||||
|
* - `settings.keybindings`
|
||||||
*/
|
*/
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
window.overleaf = {
|
window.overleaf = {
|
||||||
|
|
|
@ -9,8 +9,9 @@ import {
|
||||||
useEffect,
|
useEffect,
|
||||||
} from 'react'
|
} from 'react'
|
||||||
|
|
||||||
import { UserSettings } from '../../../../types/user-settings'
|
import { UserSettings, Keybindings } from '../../../../types/user-settings'
|
||||||
import getMeta from '@/utils/meta'
|
import getMeta from '@/utils/meta'
|
||||||
|
import useScopeValue from '@/shared/hooks/use-scope-value'
|
||||||
|
|
||||||
const defaultSettings: UserSettings = {
|
const defaultSettings: UserSettings = {
|
||||||
pdfViewer: 'pdfjs',
|
pdfViewer: 'pdfjs',
|
||||||
|
@ -33,14 +34,28 @@ type UserSettingsContextValue = {
|
||||||
>
|
>
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type ScopeSettings = {
|
||||||
|
overallTheme: 'light' | 'dark'
|
||||||
|
keybindings: Keybindings
|
||||||
|
}
|
||||||
|
|
||||||
export const UserSettingsContext = createContext<
|
export const UserSettingsContext = createContext<
|
||||||
UserSettingsContextValue | undefined
|
UserSettingsContextValue | undefined
|
||||||
>(undefined)
|
>(undefined)
|
||||||
|
|
||||||
export const UserSettingsProvider: FC = ({ children }) => {
|
export const UserSettingsProvider: FC = ({ children }) => {
|
||||||
const [userSettings, setUserSettings] = useState<
|
const [userSettings, setUserSettings] = useState<UserSettings>(
|
||||||
UserSettingsContextValue['userSettings']
|
() => getMeta('ol-userSettings') || defaultSettings
|
||||||
>(() => getMeta('ol-userSettings') || defaultSettings)
|
)
|
||||||
|
|
||||||
|
// update the global scope 'settings' value, for extensions
|
||||||
|
const [, setScopeSettings] = useScopeValue<ScopeSettings>('settings')
|
||||||
|
useEffect(() => {
|
||||||
|
setScopeSettings({
|
||||||
|
overallTheme: userSettings.overallTheme === 'light-' ? 'light' : 'dark',
|
||||||
|
keybindings: userSettings.mode === 'none' ? 'default' : userSettings.mode,
|
||||||
|
})
|
||||||
|
}, [setScopeSettings, userSettings])
|
||||||
|
|
||||||
const value = useMemo<UserSettingsContextValue>(
|
const value = useMemo<UserSettingsContextValue>(
|
||||||
() => ({
|
() => ({
|
||||||
|
@ -50,13 +65,6 @@ export const UserSettingsProvider: FC = ({ children }) => {
|
||||||
[userSettings, setUserSettings]
|
[userSettings, setUserSettings]
|
||||||
)
|
)
|
||||||
|
|
||||||
// Fire an event to inform non-React code of settings changes
|
|
||||||
useEffect(() => {
|
|
||||||
window.dispatchEvent(
|
|
||||||
new CustomEvent('settings:change', { detail: userSettings })
|
|
||||||
)
|
|
||||||
}, [userSettings])
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<UserSettingsContext.Provider value={value}>
|
<UserSettingsContext.Provider value={value}>
|
||||||
{children}
|
{children}
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
import { MainDocument, PdfViewer } from '../../../../types/project-settings'
|
import { MainDocument } from '../../../../types/project-settings'
|
||||||
|
import { PdfViewer } from '../../../../types/user-settings'
|
||||||
|
|
||||||
type Scope = {
|
type Scope = {
|
||||||
settings?: {
|
settings?: {
|
||||||
|
|
|
@ -17,16 +17,12 @@ export type MainDocument = {
|
||||||
|
|
||||||
export type ProjectCompiler = 'pdflatex' | 'latex' | 'xelatex' | 'lualatex'
|
export type ProjectCompiler = 'pdflatex' | 'latex' | 'xelatex' | 'lualatex'
|
||||||
|
|
||||||
export type Keybindings = 'default' | 'vim' | 'emacs'
|
|
||||||
|
|
||||||
export type OverallThemeMeta = {
|
export type OverallThemeMeta = {
|
||||||
name: string
|
name: string
|
||||||
path: string
|
path: string
|
||||||
val: OverallTheme
|
val: OverallTheme
|
||||||
}
|
}
|
||||||
|
|
||||||
export type PdfViewer = 'pdfjs' | 'native'
|
|
||||||
|
|
||||||
export type SpellCheckLanguage = {
|
export type SpellCheckLanguage = {
|
||||||
name: string
|
name: string
|
||||||
code: string
|
code: string
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
import { Keybindings, PdfViewer } from './project-settings'
|
|
||||||
import {
|
import {
|
||||||
FontFamily,
|
FontFamily,
|
||||||
LineHeight,
|
LineHeight,
|
||||||
OverallTheme,
|
OverallTheme,
|
||||||
} from '@/features/source-editor/extensions/theme'
|
} from '@/features/source-editor/extensions/theme'
|
||||||
|
|
||||||
|
export type Keybindings = 'none' | 'default' | 'vim' | 'emacs'
|
||||||
|
export type PdfViewer = 'pdfjs' | 'native'
|
||||||
|
|
||||||
export type UserSettings = {
|
export type UserSettings = {
|
||||||
pdfViewer: PdfViewer
|
pdfViewer: PdfViewer
|
||||||
autoComplete: boolean
|
autoComplete: boolean
|
||||||
|
|
Loading…
Reference in a new issue