@acrodata/code-editor
Version:
CodeMirror 6 wrapper for Angular
127 lines (126 loc) • 5.92 kB
TypeScript
import { ElementRef, EventEmitter, OnChanges, OnDestroy, OnInit, SimpleChanges } from '@angular/core';
import { ControlValueAccessor } from '@angular/forms';
import { LanguageDescription } from '@codemirror/language';
import { Extension } from '@codemirror/state';
import { EditorView } from '@codemirror/view';
import * as i0 from "@angular/core";
export type Theme = 'light' | 'dark' | Extension;
export type Setup = 'basic' | 'minimal' | null;
export declare const External: import("@codemirror/state").AnnotationType<boolean>;
export declare class CodeEditor implements OnChanges, OnInit, OnDestroy, ControlValueAccessor {
private _elementRef;
/**
* EditorView's [root](https://codemirror.net/docs/ref/#view.EditorView.root).
*
* Don't support change dynamically!
*/
root?: Document | ShadowRoot;
/**
* Whether focus on the editor after init.
*
* Don't support change dynamically!
*/
autoFocus: boolean;
/** The editor's value. */
value: string;
/** Whether the editor is disabled. */
disabled: boolean;
/** Whether the editor is readonly. */
readonly: boolean;
/** The editor's theme. */
theme: Theme;
/** The editor's placecholder. */
placeholder: string;
/** Whether indent with Tab key. */
indentWithTab: boolean;
/** Should be a string consisting either entirely of the same whitespace character. */
indentUnit: string;
/** Whether the editor wraps lines. */
lineWrapping: boolean;
/** Whether highlight the whitespace. */
highlightWhitespace: boolean;
/**
* An array of language descriptions for known
* [language-data](https://github.com/codemirror/language-data/blob/main/src/language-data.ts).
*
* Don't support change dynamically!
*/
languages: LanguageDescription[];
/** The editor's language. You should set the `languages` prop at first. */
language: string;
/**
* The editor's built-in setup. The value can be set to
* [`basic`](https://codemirror.net/docs/ref/#codemirror.basicSetup),
* [`minimal`](https://codemirror.net/docs/ref/#codemirror.minimalSetup) or `null`.
*/
setup: Setup;
/**
* It will be appended to the root
* [extensions](https://codemirror.net/docs/ref/#state.EditorStateConfig.extensions).
*/
extensions: Extension[];
/** Event emitted when the editor's value changes. */
change: EventEmitter<string>;
/** Event emitted when focus on the editor. */
focus: EventEmitter<void>;
/** Event emitted when the editor has lost focus. */
blur: EventEmitter<void>;
private _onChange;
private _onTouched;
constructor(_elementRef: ElementRef<Element>);
/**
* The instance of [EditorView](https://codemirror.net/docs/ref/#view.EditorView).
*/
view?: EditorView;
private _updateListener;
private _editableConf;
private _readonlyConf;
private _themeConf;
private _placeholderConf;
private _indentWithTabConf;
private _indentUnitConf;
private _lineWrappingConf;
private _highlightWhitespaceConf;
private _languageConf;
private _getAllExtensions;
ngOnChanges(changes: SimpleChanges): void;
ngOnInit(): void;
ngOnDestroy(): void;
writeValue(value: string): void;
registerOnChange(fn: (value: string) => void): void;
registerOnTouched(fn: () => void): void;
setDisabledState(isDisabled: boolean): void;
/** Sets editor's value. */
setValue(value: string): void;
private _dispatchEffects;
/** Sets the root extensions of the editor. */
setExtensions(value: Extension[]): void;
/** Sets editor's editable state. */
setEditable(value: boolean): void;
/** Sets editor's readonly state. */
setReadonly(value: boolean): void;
/** Sets editor's theme. */
setTheme(value: Theme): void;
/** Sets editor's placeholder. */
setPlaceholder(value: string): void;
/** Sets editor' indentWithTab. */
setIndentWithTab(value: boolean): void;
/** Sets editor's indentUnit. */
setIndentUnit(value: string): void;
/** Sets editor's lineWrapping. */
setLineWrapping(value: boolean): void;
/** Sets editor's highlightWhitespace. */
setHighlightWhitespace(value: boolean): void;
/** Sets editor's language dynamically. */
setLanguage(lang: string): void;
/** Find the language's extension by its name. Case insensitive. */
private _findLanguage;
static ɵfac: i0.ɵɵFactoryDeclaration<CodeEditor, never>;
static ɵcmp: i0.ɵɵComponentDeclaration<CodeEditor, "code-editor", never, { "root": { "alias": "root"; "required": false; }; "autoFocus": { "alias": "autoFocus"; "required": false; }; "value": { "alias": "value"; "required": false; }; "disabled": { "alias": "disabled"; "required": false; }; "readonly": { "alias": "readonly"; "required": false; }; "theme": { "alias": "theme"; "required": false; }; "placeholder": { "alias": "placeholder"; "required": false; }; "indentWithTab": { "alias": "indentWithTab"; "required": false; }; "indentUnit": { "alias": "indentUnit"; "required": false; }; "lineWrapping": { "alias": "lineWrapping"; "required": false; }; "highlightWhitespace": { "alias": "highlightWhitespace"; "required": false; }; "languages": { "alias": "languages"; "required": false; }; "language": { "alias": "language"; "required": false; }; "setup": { "alias": "setup"; "required": false; }; "extensions": { "alias": "extensions"; "required": false; }; }, { "change": "change"; "focus": "focus"; "blur": "blur"; }, never, never, true, never>;
static ngAcceptInputType_autoFocus: unknown;
static ngAcceptInputType_disabled: unknown;
static ngAcceptInputType_readonly: unknown;
static ngAcceptInputType_indentWithTab: unknown;
static ngAcceptInputType_lineWrapping: unknown;
static ngAcceptInputType_highlightWhitespace: unknown;
}