UNPKG

@yuntijs/ui

Version:

☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps

72 lines (71 loc) 3.33 kB
import { Monaco } from '@monaco-editor/loader'; import type { editor as IEditor } from 'monaco-editor'; import React, { CSSProperties } from 'react'; import { themeMap } from "../../hooks/themeMap"; /** * @see https://microsoft.github.io/monaco-editor/api/index.html */ export type IEditorInstance = IEditor.IStandaloneCodeEditor | IEditor.IStandaloneDiffEditor; export type EditorEnhancer = (monaco: Monaco, editorIns: IEditorInstance) => any; export type ThemeProps = (typeof themeMap)[number]; export interface IGeneralManacoEditorProps { /** [Monaco editor options](https://microsoft.github.io/monaco-editor/) */ options?: Record<string, any>; /** callback after monaco's loaded and after editor's loaded */ editorDidMount?: (monaco: Monaco, editor: IEditorInstance) => void; /** callback after monaco's loaded and before editor's loaded */ editorWillMount?: (monaco: Monaco) => void; /** path of the current model, useful when creating a multi-model editor */ path?: string; /** whether to save the models' view states between model changes or not */ saveViewState?: boolean; /** language of the editor @see https://microsoft.github.io/monaco-editor/ for available languages */ language?: string; /** theme of the editor */ theme?: ThemeProps; /** [config passing to require](https://github.com/suren-atoyan/monaco-react#loader-config), can be used to upgrade monaco-editor */ requireConfig?: Record<string, any>; /** value, controlled */ value?: string; /** defaultValue for creating model, uncontrolled */ defaultValue?: string; /** className of wrapper */ className?: string; /** width of wrapper */ width?: number | string; /** height of wrapper */ height?: number | string; /** whether to enable outline of wrapper or not */ enableOutline?: boolean; /** style of wrapper */ style?: CSSProperties; enhancers?: EditorEnhancer[]; placeholder?: string; } export interface ISingleMonacoEditorProps extends IGeneralManacoEditorProps { onChange?: (input: string, event: IEditor.IModelContentChangedEvent) => void; onBlur?: (input: string, event: any) => void; supportFullScreen?: boolean; onFullScreenChange?: (isFullScreen: boolean) => void; } export interface IDiffMonacoEditorProps extends IGeneralManacoEditorProps { onChange?: (input: string, event: IEditor.IModelContentChangedEvent) => void; supportFullScreen?: boolean; onFullScreenChange?: (isFullScreen: boolean) => void; original?: string; } export declare const WORD_EDITOR_INITIALIZING: string; export declare const INITIAL_OPTIONS: IEditor.IStandaloneEditorConstructionOptions; export declare const useEditor: <T = IEditorInstance>(type: 'single' | 'diff', props: IGeneralManacoEditorProps) => { readonly isEditorReady: boolean; readonly focused: boolean; readonly loading: boolean; readonly containerRef: React.RefObject<HTMLDivElement | null>; readonly monacoRef: React.RefObject<typeof import("monaco-editor") | null>; readonly editorRef: React.MutableRefObject<T>; readonly valueRef: React.RefObject<string | undefined>; }; export declare const useFullScreen: (editor?: IEditor.IStandaloneCodeEditor) => { isFullScreen: boolean; fullScreen: () => void; };