import type { HybridView, HybridViewMethods, HybridViewProps } from 'react-native-nitro-modules'; export interface NativeTokenStyle { color: string; bold: boolean; italic: boolean; } export interface NativeTheme { background: string; foreground: string; gutterBackground: string; gutterForeground: string; gutterActiveForeground: string; activeLine: string; selection: string; cursor: string; matchingBracket: string; searchMatch: string; searchMatchActive: string; tokens: Record; } export interface NativeInsets { top?: number; bottom?: number; left?: number; right?: number; } export interface NativeSelection { anchor: number; head: number; revision: number; } export interface NativePosition { line: number; column: number; } export interface NativeRect { x: number; y: number; width: number; height: number; } export interface NativeVisibleLines { first: number; last: number; } export interface NativeScrollEvent { x: number; y: number; contentWidth: number; contentHeight: number; } // In dp, contentInsets included: the view size at which nothing scrolls. export interface NativeContentSize { width: number; height: number; } export type NativeCaretDirection = | 'left' | 'right' | 'wordLeft' | 'wordRight' | 'lineStart' | 'lineEnd' | 'documentStart' | 'documentEnd' | 'up' | 'down' | 'pageUp' | 'pageDown'; export type NativeChangeOrigin = 'input' | 'api' | 'undo' | 'redo'; export type NativeSuggestions = 'off' | 'forceOff' | 'on'; export interface NativeChangeEvent { start: number; end: number; text: string; origin: NativeChangeOrigin; revision: number; } export interface NativeSearchQuery { text: string; regex: boolean; caseSensitive: boolean; wholeWord: boolean; } // A total of 0 means no match. export interface NativeSearchHit { index: number; total: number; } // limited: a regex hit PCRE2's match limit, so the count stops there. export interface NativeSearchResult { count: number; limited: boolean; } export type NativeDecorationKind = 'underline' | 'gap' | 'lineBackground'; export type NativeUnderlineStyle = 'solid' | 'wavy'; // One flat struct per item, since Nitro cannot tell a variant of structs apart. Unused fields hold -1, 0 or "". export interface NativeDecoration { kind: NativeDecorationKind; start: number; end: number; line: number; rows: number; color: string; style: NativeUnderlineStyle; thickness: number; offset: number; } export interface NativeGap { line: number; rect: NativeRect; } export interface CodeEditorViewProps extends HybridViewProps { initialValue?: string; language?: string; theme?: NativeTheme; fontFamily?: string; fontSize?: number; lineHeight?: number; lineNumbers?: boolean; softWrap?: boolean; readOnly?: boolean; highlightActiveLine?: boolean; matchBrackets?: boolean; placeholder?: string; scrollEnabled?: boolean; contentInsets?: NativeInsets; textPadding?: number; avoidKeyboard?: boolean; suggestions?: NativeSuggestions; autoFocus?: boolean; tabSize?: number; insertSpaces?: boolean; autoIndent?: boolean; autoCloseBrackets?: boolean; onReady?: () => void; onScroll?: (e: NativeScrollEvent) => void; onSelectionChange?: (s: NativeSelection) => void; onChange?: (e: NativeChangeEvent) => void; onChangeText?: (text: string) => void; // Not onFocus and onBlur: those names already exist on ViewProps with an event argument. onEditorFocus?: () => void; onEditorBlur?: () => void; onContentSizeChange?: (size: NativeContentSize) => void; decorations?: NativeDecoration[]; // Below zero for the current text. decorationsRevision?: number; onGapLayout?: (gaps: NativeGap[]) => void; } export interface CodeEditorViewMethods extends HybridViewMethods { getText(): string; getLength(): number; getLineCount(): number; getLine(index: number): string; getRevision(): number; getSelection(): NativeSelection; getTextInRange(start: number, end: number): string; offsetToPosition(offset: number): NativePosition; positionToOffset(line: number, column: number): number; getCursorRect(): NativeRect | undefined; getGapRect(line: number): NativeRect | undefined; getVisibleLines(): NativeVisibleLines; isFocused(): boolean; canUndo(): boolean; canRedo(): boolean; setText(text: string, keepHistory: boolean): Promise; setSelection(anchor: number, head: number): Promise; selectAll(): Promise; scrollToLine(line: number, animated: boolean): Promise; revealSelection(): Promise; insertText(text: string): Promise; replaceRange(start: number, end: number, text: string): Promise; undo(): Promise; redo(): Promise; indent(): Promise; outdent(): Promise; cut(): Promise; copy(): Promise; paste(): Promise; focus(): Promise; blur(): Promise; setSearch(query: NativeSearchQuery): Promise; findNext(): Promise; findPrevious(): Promise; replaceCurrent(text: string): Promise; replaceAll(text: string): Promise; clearSearch(): Promise; moveCaret(direction: NativeCaretDirection, select: boolean): Promise; typeText(text: string): Promise; deleteBackward(): Promise; deleteForward(): Promise; } export type CodeEditorView = HybridView;