import type { ChangeSet, Extension, Range, StateCommand, StateEffectType, Text } from '@codemirror/state'; import { EditorState, StateField } from '@codemirror/state'; import type { Command, DecorationSet, ViewUpdate } from '@codemirror/view'; import { Decoration, EditorView } from '@codemirror/view'; import type { EditorState as LibroEditorState, ICoordinate, IEditor, IEditorConfig, IEditorOptions, IEditorSelectionStyle, IModel, IPosition, IRange, ITextSelection, IToken, KeydownHandler, SearchMatch } from '@difizen/libro-code-editor'; import type { LSPProvider } from '@difizen/libro-lsp'; import { Deferred, Disposable, Emitter } from '@difizen/mana-app'; import type { CodeMirrorConfig } from './config.js'; import { EditorConfiguration } from './config.js'; /** * The time that a collaborator name hover persists. */ /** * The default configuration options for an editor. */ export declare const codeMirrorDefaultConfig: Required; export declare class CodeMirrorEditor implements IEditor { protected editorReadyDeferred: Deferred; editorReady: Promise; protected highlightEffect: StateEffectType<{ matches: SearchMatch[]; currentIndex: number | undefined; }>; protected highlightMark: Decoration; protected selectedMatchMark: Decoration; protected highlightField: StateField; protected editorState: LibroEditorState; /** * Construct a CodeMirror editor. */ constructor(options: IOptions); getState(): LibroEditorState; /** * Initialize the editor binding. */ save: () => void; /** * A signal emitted when either the top or bottom edge is requested. */ readonly edgeRequestedEmitter: Emitter; readonly edgeRequested: import("@difizen/mana-app").Event; /** * The DOM node that hosts the editor. */ readonly host: HTMLElement; /** * The uuid of this editor; */ get uuid(): string; set uuid(value: string); protected modalChangeEmitter: Emitter; get onModalChange(): import("@difizen/mana-app").Event; /** * The selection style of this editor. */ get selectionStyle(): IEditorSelectionStyle; set selectionStyle(value: IEditorSelectionStyle); /** * Get the codemirror editor wrapped by the editor. */ get editor(): EditorView; /** * Get the codemirror doc wrapped by the widget. */ get doc(): Text; /** * Get the number of lines in the editor. */ get lineCount(): number; /** * Returns a model for this editor. */ get model(): IModel; /** * The height of a line in the editor in pixels. */ get lineHeight(): number; /** * The widget of a character in the editor in pixels. */ get charWidth(): number; /** * Tests whether the editor is disposed. */ get disposed(): boolean; /** * Dispose of the resources held by the widget. */ dispose: () => void; /** * Get a config option for the editor. */ getOption(option: K): IConfig[K]; /** * Set a config option for the editor. */ setOption(option: K, value: IEditorConfig[K]): void; /** * Set config options for the editor. * * This method is preferred when setting several options. The * options are set within an operation, which only performs * the costly update at the end, and not after every option * is set. */ setOptions(options: Partial): void; injectExtension(ext: Extension): void; /** * Returns the content for the given line number. */ getLine(line: number): string | undefined; /** * Find an offset for the given position. */ getOffsetAt(position: IPosition): number; /** * Find a position for the given offset. */ getPositionAt(offset: number): IPosition; /** * Undo one edit (if any undo events are stored). */ undo(): void; /** * Redo one undone edit. */ redo(): void; /** * Clear the undo history. */ clearHistory(): void; /** * Brings browser focus to this editor text. */ focus(): void; /** * Test whether the editor has keyboard focus. */ hasFocus(): boolean; /** * Explicitly blur the editor. */ blur(): void; /** * Refresh the editor if it is focused; * otherwise postpone refreshing till focusing. */ resizeToFit(): void; get state(): EditorState; firstLine(): number; lastLine(): number; cursorCoords(where: boolean): { left: number; top: number; bottom: number; }; getRange(from: { line: number; ch: number; }, to: { line: number; ch: number; }): string; getSelectionValue(range?: IRange): string; /** * Add a keydown handler to the editor. * * @param handler - A keydown handler. * * @returns A disposable that can be used to remove the handler. */ addKeydownHandler(handler: KeydownHandler): Disposable; /** * Reveal the given position in the editor. */ revealPosition(position: IPosition): void; /** * Reveal the given selection in the editor. */ revealSelection(selection: IRange): void; /** * Get the window coordinates given a cursor position. */ getCoordinateForPosition(position: IPosition): ICoordinate; /** * Get the cursor position given window coordinates. * * @param coordinate - The desired coordinate. * * @returns The position of the coordinates, or null if not * contained in the editor. */ getPositionForCoordinate(coordinate: ICoordinate): IPosition | null; /** * Returns the primary position of the cursor, never `null`. */ getCursorPosition(): IPosition; /** * Set the primary position of the cursor. * * #### Notes * This will remove any secondary cursors. */ setCursorPosition(position: IPosition): void; /** * Returns the primary selection, never `null`. */ getSelection(): ITextSelection; /** * Set the primary selection. This will remove any secondary cursors. */ setSelection(selection: IRange): void; /** * Gets the selections for all the cursors, never `null` or empty. */ getSelections(): ITextSelection[]; /** * Sets the selections for all the cursors, should not be empty. * Cursors will be removed or added, as necessary. * Passing an empty array resets a cursor position to the start of a document. */ setSelections(selections: IRange[]): void; /** * Replaces the current selection with the given text. * * @param text The text to be inserted. */ replaceSelection(text: string, range: IRange): void; replaceSelections(edits: { text: string; range: IRange; }[]): void; highlightMatches(matches: SearchMatch[], currentIndex: number | undefined): void; handleTooltipChange: (val: boolean) => void; /** * Get a list of tokens for the current editor text content. */ getTokens(): IToken[]; /** * Get the token at a given editor position. */ getTokenAt(offset: number): IToken; /** * Get the token a the cursor position. */ getTokenAtCursor(): IToken; /** * Insert a new indented line at the current cursor position. */ newIndentedLine(): void; /** * Execute a codemirror command on the editor. * * @param command - The name of the command to execute. */ execCommand(command: Command | StateCommand): void; format: () => void; /** * Handle keydown events from the editor. */ protected onKeydown(event: KeyboardEvent): boolean; /** * Handles a mime type change. */ protected _onMimeTypeChanged(): void; /** * Handles a selections change. */ protected _onSelectionsChanged(args: ITextSelection[]): void; /** * Clean selections for the given uuid. */ protected _cleanSelections(uuid: string): void; protected _buildMarkDecoration(uuid: string, selections: ISelectionText[]): Range[]; /** * Converts the selection style to a text marker options. */ /** * Construct a caret element representing the position * of a collaborator's cursor. */ /** * Marks selections. */ protected _markSelections(uuid: string, selections: ITextSelection[]): void; /** * Handles a cursor activity event. */ protected _onCursorActivity(): void; /** * Converts a code mirror selection to an editor selection. */ protected _toSelection(selection: { anchor: { line: number; ch: number; }; head: { line: number; ch: number; }; }): ITextSelection; /** * Convert a code mirror position to an editor position. */ protected _toPosition(position: { line: number; ch: number; }): { line: number; column: number; }; /** * Convert an editor position to a code mirror position. */ protected _toCodeMirrorPosition(position: IPosition): { line: number; ch: number; }; /** * Handles document changes. */ protected _onDocChanged(update: ViewUpdate): void; /** * Handle the DOM events for the editor. * * @param event - The DOM event sent to the editor. * * #### Notes * This method implements the DOM `EventListener` interface and is * called in response to events on the editor's DOM node. It should * not be called directly by user code. */ handleEvent(event: Event): void; /** * Handle `focus` events for the editor. */ protected _evtFocus(): void; /** * Handle `blur` events for the editor. */ protected _evtBlur(): void; /** * Handle `scroll` events for the editor. */ protected _evtScroll(): void; /** * Clear the hover for a caret, due to things like * scrolling, resizing, deactivation, etc, where * the position is no longer valid. */ protected _clearHover(): void; /** * Check for an out of sync editor. */ protected _checkSync(): void; protected _model: IModel; protected _editor: EditorView; protected _selectionMarkers: Record[]>; protected _caretHover: HTMLElement | null; protected _config: IConfig; protected _hoverTimeout: number; protected _hoverId: string; protected _keydownHandlers: KeydownHandler[]; protected _selectionStyle: IEditorSelectionStyle; protected _uuid: string; protected _isDisposed: boolean; protected _lastChange: ChangeSet | null; protected _editorConfig: EditorConfiguration; protected _addMark: StateEffectType; protected _removeMark: StateEffectType; protected _markField: StateField; } export type IConfig = CodeMirrorConfig; export interface IOptions extends IEditorOptions { lspProvider?: LSPProvider; /** * The configuration options for the editor. */ config?: Partial; state?: LibroEditorState; } export declare function createEditor(host: HTMLElement, config: IConfig, value: string, editorConfig: EditorConfiguration, additionalExtensions: Extension[]): EditorView; export interface ISelectionText { from: number; to: number; style: IEditorSelectionStyle; } export interface ICollabSelectionText { uuid: string; selections: ISelectionText[]; } export interface ICollabDecorationSet { uuid: string; decorations: Range[]; } //# sourceMappingURL=editor.d.ts.map