import { ReactNode } from 'react'; import { BasicEvent, Event, IDisposable, IRange, ISelection, MaybeNull, MaybePromise, URI } from '@opensumi/ide-core-browser'; import { IContextMenu } from '@opensumi/ide-core-browser/lib/menu/next'; import { IThemeColor } from '@opensumi/ide-core-common'; import { editor } from '@opensumi/ide-monaco'; import { DragOverPosition, EditorOpenType, IDecorationRenderOptions, IEditor, IEditorGroup, IEditorOpenType, IResource, ITextEditorDecorationType, OverviewRulerLane, ResourceService, TrackedRangeStickiness } from '../common'; import { IMultiDiffSourceResolverService } from '../common/multi-diff'; import { IEditorDocumentModelContentRegistry } from './doc-model/types'; import { EditorGroup } from './workbench-editor.service'; export * from '../common'; export type ReactEditorComponent = React.ComponentType<{ resource: IResource; }>; export interface IEditorComponent { uid: string; component: ReactEditorComponent; scheme?: string; renderMode?: EditorComponentRenderMode; /** * 有关该 component 的额外信息 */ metadata?: Record; } export type EditorSide = 'bottom' | 'top'; export interface IEditorSideWidget { /** * id, 需要唯一,会作为react组件的key */ id: string; /** * TODO: 当前仅支持bottom */ side?: EditorSide; /** * 组件元素 */ component: ReactEditorComponent; /** * 排序因子, 默认10 */ weight?: number; /** * 是否要在某个resource显示 */ displaysOnResource: (resource: IResource) => boolean; /** * editorSide view 组件传入的props */ initialProps?: unknown; } /** * 默认值: ONE_PER_GROUP * ONE_PER_RESOURCE - 每个资源只初始化一次组件 * ONE_PER_GROUP - 每个资源在同个 Group 下只初始化一次组件 * ONE_PER_WORKBENCH - 整个渲染过程复用同一个组件,即组件仅会初始化一次 */ export declare enum EditorComponentRenderMode { ONE_PER_RESOURCE = 1, ONE_PER_GROUP = 2, ONE_PER_WORKBENCH = 3 } /** * 注册编辑器组件 Resolver 时触发 */ export declare class RegisterEditorComponentResolverEvent extends BasicEvent { } /** * 注册编辑器组件时触发 */ export declare class RegisterEditorComponentEvent extends BasicEvent { } export declare abstract class EditorComponentRegistry { abstract registerEditorComponent(component: IEditorComponent, initialProps?: any): IDisposable; abstract registerEditorComponentResolver(handlesScheme: string | ((scheme: string) => number), // handlesScheme 返回权重, 小于 0 表示不处理 resolver: IEditorComponentResolver): IDisposable; abstract resolveEditorComponent(resource: IResource): Promise; abstract getEditorComponent(id: string): IEditorComponent | null; abstract getEditorInitialProps(id: string): any; abstract clearPerWorkbenchComponentCache(componentId: string): void; /** * 注册一个编辑器的边缘组件(目前只开放了bottom、top) * @param widget */ abstract registerEditorSideWidget(widget: IEditorSideWidget): IDisposable; abstract getSideWidgets(side: EditorSide, resource: IResource): IEditorSideWidget[]; } /** * 打开资源的处理委派函数 * @param resource 要打开的资源 * @param results 在执行此责任委派函数前,已经支持的打开方式 * @param resolve 调用这个函数,传入结果可结束责任链直接返回支持的打开方式 */ export type IEditorComponentResolver = (resource: IResource, results: IEditorOpenType[], resolve: (results: IEditorOpenType[]) => void) => MaybePromise; export declare const BrowserEditorContribution: unique symbol; export interface BrowserEditorContribution { /** * 用来在合适的时机向 `ResourceService` 注册可以在编辑器内打开的资源。 * * 为了让一个 uri 能够在编辑器中被打开,首先需要向 `ResourceService` 注册一个用于解析 uri 至一个编辑器资源(`IResource`) 的 `IResourceProvider`。 * 它的主要职责是在这个 uri 在编辑器标签 Tab 上显示时提供它的名称、图标、是否被编辑等状态,以及相应这个 tab 被关闭时的回调等等。 * * @param resourceService */ registerResource?(resourceService: ResourceService): void; /** * 用来在合适的时机向 `EditorComponentRegistry` 注册编辑器组件、打开方式等功能。 * * 一个 uri 对应的编辑器资源 (`IResource`) 需要能够在编辑器中展示,还需要为它注册对应的一个或者多个打开方式,以及对应打开方式使用的 React 组件。 * @param editorComponentRegistry */ registerEditorComponent?(editorComponentRegistry: EditorComponentRegistry): void; registerEditorDocumentModelContentProvider?(registry: IEditorDocumentModelContentRegistry): void; /** * @deprecated * @param editorActionRegistry */ registerEditorActions?(editorActionRegistry: IEditorActionRegistry): void; /** * 当进入 IDE 时,编辑器会尝试恢复上一次打开的编辑器组和组内打开的文件 * 完成后会执行 onDidRestoreState 这个 hook */ onDidRestoreState?(): void; registerEditorFeature?(registry: IEditorFeatureRegistry): any; } export declare const MultiDiffSourceContribution: unique symbol; export interface MultiDiffSourceContribution { registerMultiDiffSourceResolver(resolverService: IMultiDiffSourceResolverService): IDisposable; } export interface IGridResizeEventPayload { gridId: string; } export declare class GridResizeEvent extends BasicEvent { static createDirective(uid: string): string; } export declare class EditorGroupOpenEvent extends BasicEvent<{ group: IEditorGroup; resource: IResource; }> { } export declare class EditorGroupCloseEvent extends BasicEvent<{ group: IEditorGroup; resource: IResource; }> { } export declare class EditorGroupDisposeEvent extends BasicEvent<{ group: IEditorGroup; }> { } export declare class EditorGroupChangeEvent extends BasicEvent { } export declare class EditorActiveResourceStateChangedEvent extends BasicEvent<{ resource: MaybeNull; openType: MaybeNull; editorUri?: MaybeNull; }> { } export interface IEditorGroupChangePayload { group: IEditorGroup; oldResource: MaybeNull; newResource: MaybeNull; oldOpenType: MaybeNull; newOpenType: MaybeNull; } export declare class EditorGroupFileDropEvent extends BasicEvent { } export interface IEditorGroupFileDropPayload { files: FileList; group: IEditorGroup; /** * 如果目标在tab上, drop目标tab的位置 * -1表示在tab的空位置 */ tabIndex?: number; /** * 如果扔在编辑器主体,扔的位置 */ position?: DragOverPosition; } export interface IEditorDecorationCollectionService { createTextEditorDecorationType(options: IDecorationRenderOptions, key?: string): IBrowserTextEditorDecorationType; getTextEditorDecorationType(key: any): IBrowserTextEditorDecorationType | undefined; registerDecorationProvider(provider: IEditorDecorationProvider): IDisposable; getDecorationFromProvider(uri: URI, key?: string): Promise<{ [key: string]: editor.IModelDeltaDecoration[]; }>; } export interface IBrowserTextEditorDecorationType extends ITextEditorDecorationType { property: IDynamicModelDecorationProperty; } export interface IDynamicModelDecorationProperty extends IDisposable { default: IThemedCssStyle; light: IThemedCssStyle | null; dark: IThemedCssStyle | null; rangeBehavior?: TrackedRangeStickiness; overviewRulerLane?: OverviewRulerLane; isWholeLine: boolean; } export interface IThemedCssStyle extends IDisposable { glyphMarginClassName?: string; className?: string; inlineClassName?: string; afterContentClassName?: string; beforeContentClassName?: string; overviewRulerColor?: string | IThemeColor; } export interface IThemedCssStyleCollection { default: IThemedCssStyle; light: IThemedCssStyle | null; dark: IThemedCssStyle | null; dispose(): void; } export declare const IEditorDecorationCollectionService: unique symbol; export declare class EditorSelectionChangeEvent extends BasicEvent { } export interface IEditorSelectionChangeEventPayload { group: IEditorGroup; resource: IResource; selections: ISelection[]; source: string | undefined; editorUri: URI; side?: 'original' | 'modified'; } export declare class EditorVisibleChangeEvent extends BasicEvent { } export interface IEditorVisibleChangeEventPayload { group: IEditorGroup; resource: IResource; visibleRanges: IRange[]; editorUri: URI; } export declare class EditorConfigurationChangedEvent extends BasicEvent { } export interface IEditorConfigurationChangedEventPayload { group: IEditorGroup; resource: IResource; editorUri: URI; } export declare class EditorGroupIndexChangedEvent extends BasicEvent { } export interface IEditorGroupIndexChangeEventPayload { group: IEditorGroup; index: number; } export declare class EditorGroupsResetSizeEvent extends BasicEvent { } export declare class RegisterEditorSideComponentEvent extends BasicEvent { } export interface IEditorDecorationProvider { schemes?: string[]; key: string; provideEditorDecoration(uri: URI): MaybePromise; onDidDecorationChange: Event; } export declare class EditorDecorationProviderRegistrationEvent extends BasicEvent { } export declare class EditorDecorationChangeEvent extends BasicEvent<{ uri: URI; key: string; }> { } export declare class EditorDecorationTypeRemovedEvent extends BasicEvent { } export interface IEditorActionRegistry { /** * 请不要再使用,暂时除了tip相关和isVisible仍然兼容 * @deprecated * @param */ registerEditorAction(action: IEditorActionItem): IDisposable; getMenu(group: IEditorGroup): IContextMenu; } export interface IEditorActionItem { title: string; iconClass: string; tip?: string; tipWhen?: string; tipClass?: string; /** * @deprecated 现在无效 */ isVisible?: (resource: MaybeNull, editorGroup: IEditorGroup) => boolean; /** * @deprecated 现在会自动转为临时command */ onClick: (resource: MaybeNull, editorGroup: IEditorGroup) => void; when?: string; } export interface IVisibleAction { item: IEditorActionItem; tipVisible: boolean; closeTip(): void; } export declare const IEditorActionRegistry: unique symbol; export interface ICompareService { /** * 在编辑器中compare两个文件 */ compare(original: URI, modified: URI, name: string): Promise; } export declare const ICompareService: unique symbol; export declare enum CompareResult { revert = "revert",// original -> modified accept = "accept",// modified -> original cancel = "cancel" } export interface IBreadCrumbService { registerBreadCrumbProvider(provider: IBreadCrumbProvider): IDisposable; getBreadCrumbs(uri: URI, editor?: MaybeNull, editorGroup?: EditorGroup): IBreadCrumbPart[] | undefined; disposeCrumb(uri: URI): void; onDidUpdateBreadCrumbResults: Event<{ editor: MaybeNull; uri: URI; }>; } export declare const IBreadCrumbService: unique symbol; export interface IBreadCrumbProvider { handlesUri(URI: URI): boolean; provideBreadCrumbForUri(uri: URI, editor?: MaybeNull): IBreadCrumbPart[]; onDidUpdateBreadCrumb: Event; } export interface IBreadCrumbPart { name: string; icon?: string; uri?: URI; isSymbol?: boolean; getSiblings?(): MaybePromise<{ parts: IBreadCrumbPart[]; currentIndex: number; }>; getChildren?(): MaybePromise; onClick?(): void; } export declare const IEditorFeatureRegistry: unique symbol; export interface IEditorFeatureRegistry { /** * 注册一个用来加强编辑器能力的Contribution * @param contribution */ registerEditorFeatureContribution(contribution: IEditorFeatureContribution): IDisposable; /** * 运行 contrbute */ runContributions(editor: IEditor): void; /** * 运行 provideEditorOptionsForUri */ runProvideEditorOptionsForUri(uri: URI): MaybePromise; } export interface IConvertedMonacoOptions { editorOptions: Partial; modelOptions: Partial; diffOptions: Partial; } export interface IEditorFeatureContribution { /** * 当一个编辑器被创建时,会调用这个API,返回的Disposable会在编辑器被销毁时执行 * @param editor */ contribute(editor: IEditor): IDisposable; /** * 用来对 uri 进行 options 的修改 * @param editor */ provideEditorOptionsForUri?(uri: URI): MaybePromise>; } export declare class ResourceOpenTypeChangedEvent extends BasicEvent { } export declare class EditorComponentDisposeEvent extends BasicEvent { } export declare class CodeEditorDidVisibleEvent extends BasicEvent<{ type: EditorOpenType.code | EditorOpenType.diff; groupName: string; editorId: string; }> { } export declare class ResoucesOfActiveComponentChangedEvent extends BasicEvent<{ component: IEditorComponent; resources: IResource[]; }> { } export declare const IEditorTabService: unique symbol; export interface IEditorTabService { renderEditorTab(component: ReactNode, isCurrent?: boolean): ReactNode; renderTabCloseComponent(component: ReactNode): ReactNode; } //# sourceMappingURL=types.d.ts.map