monaco-editor-vue3
Version:
   
425 lines (375 loc) • 13.3 kB
TypeScript
import { ComponentOptionsMixin } from 'vue';
import { DefineComponent } from 'vue';
import type { editor } from '../node_modules/monaco-editor/esm/vs/editor/editor.api.js';
import { PropType as PropType_2 } from 'vue';
import { PublicProps } from 'vue';
import type { Ref as Ref_2 } from 'vue';
declare const __VLS_component: DefineComponent<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
width: string;
height: string;
language: string;
theme: string;
value: string;
options: () => {};
showProgress: boolean;
showErrorBoundary: boolean;
retryable: boolean;
useDefaultLoading: boolean;
useDefaultErrorBoundary: boolean;
}>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
loading: (...args: any[]) => void;
error: (...args: any[]) => void;
editorWillMount: (...args: any[]) => void;
editorDidMount: (...args: any[]) => void;
change: (...args: any[]) => void;
"update:value": (...args: any[]) => void;
ready: (...args: any[]) => void;
}, string, PublicProps, Readonly<globalThis.ExtractPropTypes<__VLS_WithDefaults<__VLS_TypePropsToRuntimeProps<Props>, {
width: string;
height: string;
language: string;
theme: string;
value: string;
options: () => {};
showProgress: boolean;
showErrorBoundary: boolean;
retryable: boolean;
useDefaultLoading: boolean;
useDefaultErrorBoundary: boolean;
}>>> & {
onReady?: ((...args: any[]) => any) | undefined;
onError?: ((...args: any[]) => any) | undefined;
onChange?: ((...args: any[]) => any) | undefined;
onLoading?: ((...args: any[]) => any) | undefined;
onEditorWillMount?: ((...args: any[]) => any) | undefined;
onEditorDidMount?: ((...args: any[]) => any) | undefined;
"onUpdate:value"?: ((...args: any[]) => any) | undefined;
}, {
value: string;
language: string;
theme: string;
showErrorBoundary: boolean;
retryable: boolean;
showProgress: boolean;
width: string | number;
height: string | number;
useDefaultLoading: boolean;
useDefaultErrorBoundary: boolean;
options: EditorOptions;
}, {}>;
declare const __VLS_component_2: DefineComponent<__VLS_WithDefaults_2<__VLS_TypePropsToRuntimeProps_2<Props_2>, {
width: string;
height: string;
language: string;
theme: string;
value: string;
original: string;
options: () => {};
showProgress: boolean;
showErrorBoundary: boolean;
retryable: boolean;
useDefaultLoading: boolean;
useDefaultErrorBoundary: boolean;
}>, {}, unknown, {}, {}, ComponentOptionsMixin, ComponentOptionsMixin, {
loading: (...args: any[]) => void;
error: (...args: any[]) => void;
editorWillMount: (...args: any[]) => void;
editorDidMount: (...args: any[]) => void;
change: (...args: any[]) => void;
"update:value": (...args: any[]) => void;
ready: (...args: any[]) => void;
}, string, PublicProps, Readonly<globalThis.ExtractPropTypes<__VLS_WithDefaults_2<__VLS_TypePropsToRuntimeProps_2<Props_2>, {
width: string;
height: string;
language: string;
theme: string;
value: string;
original: string;
options: () => {};
showProgress: boolean;
showErrorBoundary: boolean;
retryable: boolean;
useDefaultLoading: boolean;
useDefaultErrorBoundary: boolean;
}>>> & {
onReady?: ((...args: any[]) => any) | undefined;
onError?: ((...args: any[]) => any) | undefined;
onChange?: ((...args: any[]) => any) | undefined;
onLoading?: ((...args: any[]) => any) | undefined;
onEditorWillMount?: ((...args: any[]) => any) | undefined;
onEditorDidMount?: ((...args: any[]) => any) | undefined;
"onUpdate:value"?: ((...args: any[]) => any) | undefined;
}, {
value: string;
language: string;
theme: string;
original: string;
showErrorBoundary: boolean;
retryable: boolean;
showProgress: boolean;
width: string | number;
height: string | number;
useDefaultLoading: boolean;
useDefaultErrorBoundary: boolean;
options: EditorOptions;
}, {}>;
declare type __VLS_NonUndefinedable<T> = T extends undefined ? never : T;
declare type __VLS_NonUndefinedable_2<T> = T extends undefined ? never : T;
declare type __VLS_Prettify<T> = {
[K in keyof T]: T[K];
} & {};
declare type __VLS_Prettify_2<T> = {
[K in keyof T]: T[K];
} & {};
declare function __VLS_template(): {
loading?(_: {
loading: EditorLoadingState;
loadingText: string | undefined;
progress: number | undefined;
showProgress: boolean;
}): any;
error?(_: {
error: EditorError;
retry: () => void;
retryable: boolean;
}): any;
};
declare function __VLS_template_2(): {
loading?(_: {
loading: EditorLoadingState;
loadingText: string | undefined;
progress: number | undefined;
showProgress: boolean;
}): any;
error?(_: {
error: EditorError;
retry: () => void;
retryable: boolean;
}): any;
};
declare type __VLS_TypePropsToRuntimeProps<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? {
type: PropType_2<__VLS_NonUndefinedable<T[K]>>;
} : {
type: PropType_2<T[K]>;
required: true;
};
};
declare type __VLS_TypePropsToRuntimeProps_2<T> = {
[K in keyof T]-?: {} extends Pick<T, K> ? {
type: PropType_2<__VLS_NonUndefinedable_2<T[K]>>;
} : {
type: PropType_2<T[K]>;
required: true;
};
};
declare type __VLS_WithDefaults<P, D> = {
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify<P[K] & {
default: D[K];
}> : P[K];
};
declare type __VLS_WithDefaults_2<P, D> = {
[K in keyof Pick<P, keyof P>]: K extends keyof D ? __VLS_Prettify_2<P[K] & {
default: D[K];
}> : P[K];
};
declare type __VLS_WithTemplateSlots<T, S> = T & {
new (): {
$slots: S;
};
};
declare type __VLS_WithTemplateSlots_2<T, S> = T & {
new (): {
$slots: S;
};
};
export declare interface BaseEditorEvents {
editorWillMount: () => void;
change: (value: string, event: editor.IModelContentChangedEvent) => void;
'update:value': (value: string) => void;
}
export declare interface BaseEditorProps {
width?: string | number;
height?: string | number;
theme?: string;
language?: string;
options?: EditorOptions;
}
export declare interface CodeEditorEvents extends BaseEditorEvents {
editorDidMount: (editor: editor.IStandaloneCodeEditor) => void;
}
export declare interface CodeEditorProps extends BaseEditorProps {
value?: string;
}
/**
* 创建 monaco editor 实例的默认配置
* @param language 语言类型
* @returns 默认配置对象
*/
export declare const createDefaultOptions: (language?: string) => editor.IStandaloneEditorConstructionOptions;
/**
* 深度合并对象
* @param target 目标对象
* @param source 源对象
* @returns 合并后的对象
*/
export declare const deepMerge: <T extends Record<string, unknown>>(target: T, source: Partial<T>) => T;
declare const _default: __VLS_WithTemplateSlots<typeof __VLS_component, ReturnType<typeof __VLS_template>>;
export { _default as CodeEditor }
export default _default;
export declare const DiffEditor: __VLS_WithTemplateSlots_2<typeof __VLS_component_2, ReturnType<typeof __VLS_template_2>>;
export declare interface DiffEditorEvents extends BaseEditorEvents {
editorDidMount: (editor: editor.IStandaloneDiffEditor) => void;
}
export declare interface DiffEditorProps extends BaseEditorProps {
value?: string;
original?: string;
}
declare interface EditorError {
code: string;
message: string;
details?: string;
recoverable?: boolean;
}
declare interface EditorLifecycleHooks {
beforeCreate?: () => void | Promise<void>;
onCreating?: () => void;
onCreated?: (editor: editor.IStandaloneCodeEditor | editor.IStandaloneDiffEditor) => void;
onReady?: (editor: editor.IStandaloneCodeEditor | editor.IStandaloneDiffEditor) => void;
beforeDestroy?: () => void | Promise<void>;
onDestroyed?: () => void;
onError?: (error: EditorError) => void;
onRecover?: () => void;
}
declare interface EditorLoadingState {
isLoading: boolean;
loadingText?: string;
progress?: number;
}
export declare interface EditorManager {
getEditor: () => editor.IStandaloneCodeEditor | editor.IStandaloneDiffEditor | null;
getValue: () => string;
setValue: (value: string) => void;
focus: () => void;
dispose: () => void;
updateOptions: (options: EditorOptions) => void;
}
export declare interface EditorOptions extends editor.IStandaloneEditorConstructionOptions {
[key: string]: unknown;
}
export declare interface EditorPlugin {
name: string;
install: (editor: editor.IStandaloneCodeEditor | editor.IStandaloneDiffEditor) => void;
uninstall?: (editor: editor.IStandaloneCodeEditor | editor.IStandaloneDiffEditor) => void;
}
export declare type EditorSize = string | number;
export declare interface EditorState {
isReady: boolean;
hasError: boolean;
errorMessage?: string;
value: string;
}
export declare type EditorTheme = 'vs' | 'vs-dark' | 'hc-black' | 'hc-light' | string;
/**
* 检查是否为有效的尺寸值
* @param value 尺寸值
* @returns 格式化后的尺寸值
*/
export declare const formatSize: (value: string | number) => string;
/**
* 验证语言是否被 Monaco Editor 支持
* @param language 语言标识符
* @returns 是否支持该语言
*/
export declare const isSupportedLanguage: (language: string) => boolean;
export declare interface MonacoEditorConfig {
theme?: EditorTheme;
language?: SupportedLanguage;
readOnly?: boolean;
automaticLayout?: boolean;
minimap?: {
enabled: boolean;
};
fontSize?: number;
lineHeight?: number;
tabSize?: number;
wordWrap?: 'off' | 'on' | 'wordWrapColumn' | 'bounded';
}
export declare type MonacoEditorProps = DiffEditorProps;
declare interface Props extends CodeEditorProps {
loadingText?: string;
showProgress?: boolean;
showErrorBoundary?: boolean;
retryable?: boolean;
lifecycle?: EditorLifecycleHooks;
useDefaultLoading?: boolean;
useDefaultErrorBoundary?: boolean;
}
declare interface Props_2 extends DiffEditorProps {
loadingText?: string;
showProgress?: boolean;
showErrorBoundary?: boolean;
retryable?: boolean;
lifecycle?: EditorLifecycleHooks;
useDefaultLoading?: boolean;
useDefaultErrorBoundary?: boolean;
}
export declare type SupportedLanguage = 'javascript' | 'typescript' | 'json' | 'html' | 'css' | 'scss' | 'less' | 'python' | 'java' | 'csharp' | 'cpp' | 'php' | 'ruby' | 'go' | 'rust' | 'sql' | 'markdown' | 'xml' | 'yaml' | 'dockerfile' | 'shell' | 'powershell' | string;
export declare const useCodeEditor: (props: CodeEditorProps & {
lifecycle?: EditorLifecycleHooks;
}, emit: (event: string, ...args: unknown[]) => void) => UseCodeEditorReturn;
export declare interface UseCodeEditorReturn {
editorInstance: editor.IStandaloneCodeEditor | null;
container: Ref_2<HTMLElement | undefined>;
loading: Ref_2<EditorLoadingState>;
error: Ref_2<EditorError | null>;
isReady: Ref_2<boolean>;
retry: () => void;
destroy: () => Promise<void>;
}
export declare const useCommonEditor: () => void;
export declare const useDiffEditor: (props: MonacoEditorProps & {
lifecycle?: EditorLifecycleHooks;
}, emit: (event: string, ...args: unknown[]) => void) => UseDiffEditorReturn;
export declare interface UseDiffEditorReturn {
editorInstance: editor.IStandaloneDiffEditor | null;
container: Ref_2<HTMLElement | undefined>;
loading: Ref_2<EditorLoadingState>;
error: Ref_2<EditorError | null>;
isReady: Ref_2<boolean>;
retry: () => void;
destroy: () => Promise<void>;
}
/**
* 生命周期钩子管理
*/
export declare const useEditorLifecycle: (hooks?: EditorLifecycleHooks) => {
executeHook: (hookName: keyof EditorLifecycleHooks, ...args: any[]) => Promise<void>;
};
/**
* 通用编辑器错误处理和状态管理 Hook
*/
export declare const useEditorState: () => {
loading: globalThis.Ref<{
isLoading: boolean;
loadingText?: string | undefined;
progress?: number | undefined;
}>;
error: globalThis.Ref<{
code: string;
message: string;
details?: string | undefined;
recoverable?: boolean | undefined;
} | null>;
isReady: globalThis.Ref<boolean>;
setLoading: (state: Partial<EditorLoadingState>) => void;
setError: (err: EditorError | null) => void;
clearError: () => void;
setReady: (ready: boolean) => void;
};
/**
* 输出警告信息
* @param msg 警告消息
*/
export declare const warnMsg: (msg: string) => void;
export { }