mirror of
https://github.com/overleaf/overleaf.git
synced 2024-11-29 16:13:42 -05:00
Expose ScopeValueStore via window.overleaf.unstable.store (#16404)
GitOrigin-RevId: 4b251639296405c0a9487f063e8b049687860004
This commit is contained in:
parent
e91b76a4f0
commit
fc8892e4fb
3 changed files with 34 additions and 1 deletions
|
@ -1,10 +1,13 @@
|
||||||
import { memo, useCallback, useEffect } from 'react'
|
import { memo, useCallback, useEffect } from 'react'
|
||||||
import { useCodeMirrorViewContext } from './codemirror-editor'
|
import { useCodeMirrorViewContext } from './codemirror-editor'
|
||||||
import useCodeMirrorScope from '../hooks/use-codemirror-scope'
|
import useCodeMirrorScope from '../hooks/use-codemirror-scope'
|
||||||
|
import useScopeValueSetterOnly from '@/shared/hooks/use-scope-value-setter-only'
|
||||||
|
|
||||||
function CodeMirrorView() {
|
function CodeMirrorView() {
|
||||||
const view = useCodeMirrorViewContext()
|
const view = useCodeMirrorViewContext()
|
||||||
|
|
||||||
|
const [, setView] = useScopeValueSetterOnly('editor.view')
|
||||||
|
|
||||||
// append the editor view dom to the container node when mounted
|
// append the editor view dom to the container node when mounted
|
||||||
const containerRef = useCallback(
|
const containerRef = useCallback(
|
||||||
node => {
|
node => {
|
||||||
|
@ -22,6 +25,11 @@ function CodeMirrorView() {
|
||||||
}
|
}
|
||||||
}, [view])
|
}, [view])
|
||||||
|
|
||||||
|
// add the editor view to the scope value store, so it can be accessed by external extensions
|
||||||
|
useEffect(() => {
|
||||||
|
setView(view)
|
||||||
|
}, [setView, view])
|
||||||
|
|
||||||
useCodeMirrorScope(view)
|
useCodeMirrorScope(view)
|
||||||
|
|
||||||
return <div ref={containerRef} style={{ height: '100%' }} />
|
return <div ref={containerRef} style={{ height: '100%' }} />
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
import { createContext, FC, useContext, useMemo } from 'react'
|
import { createContext, FC, useContext, useEffect, useMemo } from 'react'
|
||||||
import { ScopeValueStore } from '../../../../types/ide/scope-value-store'
|
import { ScopeValueStore } from '../../../../types/ide/scope-value-store'
|
||||||
import { Scope } from '../../../../types/angular/scope'
|
import { Scope } from '../../../../types/angular/scope'
|
||||||
import getMeta from '@/utils/meta'
|
import getMeta from '@/utils/meta'
|
||||||
|
@ -23,6 +23,25 @@ export const IdeProvider: FC<{
|
||||||
scopeStore: ScopeValueStore
|
scopeStore: ScopeValueStore
|
||||||
scopeEventEmitter: ScopeEventEmitter
|
scopeEventEmitter: ScopeEventEmitter
|
||||||
}> = ({ ide, scopeStore, scopeEventEmitter, children }) => {
|
}> = ({ ide, scopeStore, scopeEventEmitter, children }) => {
|
||||||
|
/**
|
||||||
|
* Expose scopeStore via `window.overleaf.unstable.store`, so it can be accessed by external extensions.
|
||||||
|
*
|
||||||
|
* These properties are expected to be available:
|
||||||
|
* - `editor.view`
|
||||||
|
* - `project.spellcheckLanguage`
|
||||||
|
* - `editor.open_doc_name`,
|
||||||
|
* - `editor.open_doc_id`,
|
||||||
|
*/
|
||||||
|
useEffect(() => {
|
||||||
|
window.overleaf = {
|
||||||
|
...window.overleaf,
|
||||||
|
unstable: {
|
||||||
|
...window.overleaf?.unstable,
|
||||||
|
store: scopeStore,
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}, [scopeStore])
|
||||||
|
|
||||||
const value = useMemo<IdeContextValue>(() => {
|
const value = useMemo<IdeContextValue>(() => {
|
||||||
return {
|
return {
|
||||||
...ide,
|
...ide,
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { OverallThemeMeta } from './project-settings'
|
||||||
import { User } from './user'
|
import { User } from './user'
|
||||||
import 'recurly__recurly-js'
|
import 'recurly__recurly-js'
|
||||||
import { UserSettings } from './user-settings'
|
import { UserSettings } from './user-settings'
|
||||||
|
import { ScopeValueStore } from './ide/scope-value-store'
|
||||||
|
|
||||||
declare global {
|
declare global {
|
||||||
// eslint-disable-next-line no-unused-vars
|
// eslint-disable-next-line no-unused-vars
|
||||||
|
@ -44,5 +45,10 @@ declare global {
|
||||||
expectingLinkedFileRefreshedSocketFor?: string | null
|
expectingLinkedFileRefreshedSocketFor?: string | null
|
||||||
writefull?: any
|
writefull?: any
|
||||||
io?: any
|
io?: any
|
||||||
|
overleaf: {
|
||||||
|
unstable: {
|
||||||
|
store: ScopeValueStore
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue