mirror of
https://github.com/yu-i-i/overleaf-cep.git
synced 2026-11-14 22:23:42 +01:00
[web] Recreate workbench with Overleaf styles (#29651)
GitOrigin-RevId: 52ca336f70b29edf6e39cf95aa164f3ae32c0a79
This commit is contained in:
committed by
Copybot
parent
b1009d3b1f
commit
7b331b0222
@@ -0,0 +1,47 @@
|
||||
import {
|
||||
createContext,
|
||||
type Dispatch,
|
||||
type FC,
|
||||
type PropsWithChildren,
|
||||
type SetStateAction,
|
||||
useContext,
|
||||
useMemo,
|
||||
useState,
|
||||
} from 'react'
|
||||
import type { EditorSelection } from '@codemirror/state'
|
||||
|
||||
export const EditorSelectionContext = createContext<
|
||||
| {
|
||||
editorSelection: EditorSelection | undefined
|
||||
setEditorSelection: Dispatch<SetStateAction<EditorSelection | undefined>>
|
||||
}
|
||||
| undefined
|
||||
>(undefined)
|
||||
|
||||
export const EditorSelectionProvider: FC<PropsWithChildren> = ({
|
||||
children,
|
||||
}) => {
|
||||
const [editorSelection, setEditorSelection] = useState<EditorSelection>()
|
||||
|
||||
const value = useMemo(() => {
|
||||
return { editorSelection, setEditorSelection }
|
||||
}, [editorSelection])
|
||||
|
||||
return (
|
||||
<EditorSelectionContext.Provider value={value}>
|
||||
{children}
|
||||
</EditorSelectionContext.Provider>
|
||||
)
|
||||
}
|
||||
|
||||
export const useEditorSelectionContext = () => {
|
||||
const context = useContext(EditorSelectionContext)
|
||||
|
||||
if (!context) {
|
||||
throw new Error(
|
||||
'useEditorSelectionContext is only available inside EditorSelectionProvider'
|
||||
)
|
||||
}
|
||||
|
||||
return context
|
||||
}
|
||||
Reference in New Issue
Block a user