import React, { createContext } from 'react' import type { Editor } from '../editor/Editor' import { IdProvider } from './useSafeId' /** @public */ export const EditorContext = createContext(null) /** @public */ export function useEditor(): Editor { const editor = React.useContext(EditorContext) if (!editor) { throw new Error( 'useEditor must be used inside of the or components' ) } return editor } /** @public */ export function useMaybeEditor(): Editor | null { return React.useContext(EditorContext) } /** @public */ export interface EditorProviderProps { editor: Editor children: React.ReactNode } /** @public @react */ export function EditorProvider({ editor, children }: EditorProviderProps) { return ( {children} ) }