UNPKG

use-monaco

Version:

[![npm](https://img.shields.io/npm/v/use-monaco)](https://npm.im/use-monaco)

42 lines (41 loc) 2.02 kB
import React from 'react'; import type * as monacoApi from 'monaco-editor'; import { basicLanguagePlugins } from '../monaco'; import { pluginMap } from '../plugins'; declare global { interface Window { monaco: typeof monacoApi; } } declare type Monaco = typeof monacoApi; export declare type MonacoProp = { monaco?: Monaco | undefined | null; }; declare type PromiseOrNot<T> = Promise<T> | T; export interface UseMonacoOptions extends Partial<Omit<monacoApi.LoaderOptions, 'plugins' | 'languages'>> { onLoad?: (monaco: typeof monacoApi) => PromiseOrNot<monacoApi.IDisposable | monacoApi.IDisposable[] | void | undefined>; themes?: any; defaultEditorOptions?: monacoApi.editor.IEditorOptions; plugins?: (keyof typeof pluginMap | [keyof typeof pluginMap, any] | monacoApi.plugin.IPlugin)[]; languages?: (keyof typeof basicLanguagePlugins | [keyof typeof basicLanguagePlugins, any] | monacoApi.plugin.IPlugin)[]; onThemeChange?: (theme: any, monaco: typeof monacoApi) => PromiseOrNot<void>; theme?: string | monacoApi.editor.IStandaloneThemeData | (() => PromiseOrNot<monacoApi.editor.IStandaloneThemeData>); } declare const MonacoProvider: React.FC<React.PropsWithChildren<UseMonacoOptions>>; export { MonacoProvider }; export declare function useMonacoContext(): { useMonacoEffect: (effect: (obj: typeof monacoApi) => void, deps: any[]) => void; monaco: typeof monacoApi; isLoading: boolean; defaultEditorOptions?: monacoApi.editor.IEditorOptions; }; export declare const useMonaco: ({ themes, onThemeChange, onLoad, defaultEditorOptions, theme, plugins, languages, ...loaderOptions }?: UseMonacoOptions) => { useMonacoEffect: (effect: (obj: Monaco) => void, deps: any[]) => void; monaco: Monaco; isLoading: boolean; defaultEditorOptions?: monacoApi.editor.IEditorOptions; }; export declare function useRefWithEffect<T>(initialValue: T): [ React.MutableRefObject<T | undefined>, (effect: (obj: T) => void, deps: any[]) => void ];