Files
overleaf-cep/services/web/frontend/js/features/ide-react/scope-adapters/editor-manager-context-adapter.ts
Tim Down 904fac958d Merge pull request #26326 from overleaf/td-clean-up-scope-store
Create separate window.overleaf.unstable.store based on React context values

GitOrigin-RevId: 68f070a6fc5e2965a82720024d91b16fa622b28b
2025-07-02 08:05:53 +00:00

55 lines
1.4 KiB
TypeScript

import { ReactScopeValueStore } from '@/features/ide-react/scope-value-store/react-scope-value-store'
import customLocalStorage from '@/infrastructure/local-storage'
import { DocumentContainer } from '@/features/ide-react/editor/document-container'
export type EditorScopeValue = {
showSymbolPalette: false
toggleSymbolPalette: () => void
sharejs_doc: DocumentContainer | null
opening: boolean
trackChanges: boolean
wantTrackChanges: boolean
showVisual: boolean
error_state: boolean
}
export function populateEditorScope(
store: ReactScopeValueStore,
projectId: string
) {
store.set('project.name', null)
const editor: Omit<EditorScopeValue, 'showVisual'> = {
showSymbolPalette: false,
toggleSymbolPalette: () => {},
sharejs_doc: null,
opening: true,
trackChanges: false,
wantTrackChanges: false,
error_state: false,
}
store.set('editor', editor)
store.persisted(
'editor.showVisual',
showVisualFallbackValue(projectId),
`editor.lastUsedMode`,
{
toPersisted: showVisual => (showVisual ? 'visual' : 'code'),
fromPersisted: mode => mode === 'visual',
}
)
}
function showVisualFallbackValue(projectId: string) {
const editorModeKey = `editor.mode.${projectId}`
const editorModeVal = customLocalStorage.getItem(editorModeKey)
if (editorModeVal) {
// clean up the old key
customLocalStorage.removeItem(editorModeKey)
}
return editorModeVal === 'rich-text'
}