/** * vue-codemirror6 * * @description CodeMirror6 Component for vue2 and vue3. * @author Logue * @license MIT * @version 1.8.0 * @see {@link https://github.com/logue/vue-codemirror6} */ import { type LanguageSupport } from '@codemirror/language'; import { type LintSource } from '@codemirror/lint'; import { EditorSelection, EditorState, type Extension, type SelectionRange, type StateField, type Text } from '@codemirror/state'; import { EditorView, type KeyBinding, type ViewUpdate } from '@codemirror/view'; import { type ExtractPropTypes, type PropType, type Ref, type ShallowRef, type WritableComputedRef } from 'vue-demi'; import type { StyleSpec } from 'style-mod'; /** `CodeMirror` component props definition. */ export declare const codeMirrorProps: { /** Model value */ readonly modelValue: { readonly type: PropType; readonly default: ''; }; /** * Theme * * @see {@link https://codemirror.net/docs/ref/#view.EditorView^theme} */ readonly theme: { readonly type: PropType>; readonly default: () => {}; }; /** Dark Mode */ readonly dark: { readonly type: BooleanConstructor; readonly default: false; }; /** * Use Basic Setup * * This will enable the basic setup for the editor. * * @see {@link https://codemirror.net/docs/ref/#codemirror.basicSetup} */ readonly basic: { readonly type: BooleanConstructor; readonly default: false; }; /** * Use Minimal Setup (The basic setting has priority.) * * @see {@link https://codemirror.net/docs/ref/#codemirror.minimalSetup} */ readonly minimal: { readonly type: BooleanConstructor; readonly default: false; }; /** * Placeholder * * @see {@link https://codemirror.net/docs/ref/#view.placeholder} */ readonly placeholder: { readonly type: PropType; readonly default: undefined; }; /** * Line wrapping * * An extension that enables line wrapping in the editor (by setting CSS white-space to pre-wrap in the content). * * @see {@link https://codemirror.net/docs/ref/#view.EditorView%5ElineWrapping} */ readonly wrap: { readonly type: BooleanConstructor; readonly default: false; }; /** * Allow tab key indent. * * This will enable the tab key to indent the current line or selection. * * @see {@link https://codemirror.net/examples/tab/} */ readonly tab: { readonly type: BooleanConstructor; readonly default: false; }; /** * Tab character * * This is the unit of indentation used when the editor is configured to indent with tabs. * It is also used to determine the size of the tab character when the editor is configured to use tabs for indentation.. * * @see {@link https://codemirror.net/docs/ref/#state.EditorState^indentUnit} */ readonly indentUnit: { readonly type: StringConstructor; readonly default: undefined; }; /** * Allow Multiple Selection. * * This allows the editor to have multiple selections at the same time. * This is useful for editing multiple parts of the document at once. * If this is set to true, the editor will allow multiple selections. * If this is set to false, the editor will only allow a single selection. * * @see {@link https://codemirror.net/docs/ref/#state.EditorState^allowMultipleSelections} */ readonly allowMultipleSelections: { readonly type: BooleanConstructor; readonly default: false; }; /** * Tab size * * This is the number of spaces that a tab character represents in the editor. * It is used to determine the size of the tab character when the editor is configured to use tabs for indentation. * If this is set to a number, the editor will use that number of spaces for each tab character. * * @see {@link https://codemirror.net/docs/ref/#state.EditorState^tabSize} */ readonly tabSize: { readonly type: NumberConstructor; readonly default: undefined; }; /** * Set line break (separetor) char. * * This is the character that is used to separate lines in the editor. * It is used to determine the line break character when the editor is configured to use a specific line break character. * * @see {@link https://codemirror.net/docs/ref/#state.EditorState^lineSeparator} */ readonly lineSeparator: { readonly type: StringConstructor; readonly default: undefined; }; /** * Readonly * * This is a CodeMirror Facet that allows you to set the editor to read-only mode. * When this is set to true, the editor will not allow any changes to be made to the document. * This is useful for displaying code that should not be edited, such as documentation or examples. * If this is set to false, the editor will allow changes to be made to the document. * * @see {@link https://codemirror.net/docs/ref/#state.EditorState^readOnly} */ readonly readonly: { readonly type: BooleanConstructor; readonly default: false; }; /** * Disable input. * * This is the reversed value of the CodeMirror editable. * Similar to `readonly`, but setting this value to true disables dragging. * * @see {@link https://codemirror.net/docs/ref/#view.EditorView^editable} */ readonly disabled: { readonly type: BooleanConstructor; readonly default: false; }; /** * Additional Extension * * You can use this to add any additional extensions that you want to use in the editor. * * @see {@link https://codemirror.net/docs/ref/#state.Extension} */ readonly extensions: { readonly type: PropType; readonly default: () => never[]; }; /** * Language Phreses * * This is a CodeMirror Facet that allows you to define custom phrases for the editor. * It can be used to override default phrases or add new ones. * This is useful for translating the editor to different languages or for customizing the editor's UI. * * @see {@link https://codemirror.net/examples/translate/} */ readonly phrases: { readonly type: PropType>; readonly default: undefined; }; /** * CodeMirror Language * * This is a CodeMirror Facet that allows you to define the language of the editor. * It can be used to enable syntax highlighting and other language-specific features. * It is useful for displaying code in a specific language, such as JavaScript, Python, or HTML. * * @see {@link https://codemirror.net/docs/ref/#language} */ readonly lang: { readonly type: PropType; readonly default: undefined; }; /** * CodeMirror Linter * * This is a CodeMirror Facet that allows you to define a linter for the editor. * It can be used to check the code for errors and warnings, and to provide feedback to the user. * It is useful for displaying code in a specific language, such as JavaScript, Python, or HTML. * This is useful for providing feedback to the user about the code they are writing. * * @see {@link https://codemirror.net/docs/ref/#lint.linter} */ readonly linter: { readonly type: PropType; readonly default: undefined; }; /** * Linter Config * * This is a CodeMirror Facet that allows you to define the configuration for the linter. * It can be used to specify options for the linter, such as the severity of errors and warnings, and to customize the behavior of the linter. * This is useful for providing feedback to the user about the code they are writing. * * @see {@link https://codemirror.net/docs/ref/#lint.linter^config} */ readonly linterConfig: { readonly type: ObjectConstructor; readonly default: () => {}; }; /** * Forces any linters configured to run when the editor is idle to run right away. * * This is useful for running linters on the initial load of the editor, or when the user has made changes to the code and wants to see the results immediately. * * @see {@link https://codemirror.net/docs/ref/#lint.forceLinting} */ readonly forceLinting: { readonly type: BooleanConstructor; readonly default: false; }; /** * Show Linter Gutter * * An area to 🔴 the lines with errors will be displayed. * This feature is not enabled if `linter` is not specified. * * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter} */ readonly gutter: { readonly type: BooleanConstructor; readonly default: false; }; /** * Gutter Config * * This is a CodeMirror Facet that allows you to define the configuration for the gutter. * It can be used to specify options for the gutter, such as the size of the gutter, the position of the gutter, and to customize the behavior of the gutter. * This is useful for providing feedback to the user about the code they are writing. * * @see {@link https://codemirror.net/docs/ref/#lint.lintGutter^config} */ readonly gutterConfig: { readonly type: ObjectConstructor; readonly default: undefined; }; /** * Using tag */ readonly tag: { readonly type: StringConstructor; readonly default: 'div'; }; /** * Allows an external update to scroll the form. * * This is useful for scrolling the editor to a specific position when the user has made changes to the code and wants to see the results immediately. * If this is set to true, the editor will scroll to the position specified in the transaction. * If this is set to false, the editor will not scroll to the position specified in the transaction. * * @see {@link https://codemirror.net/docs/ref/#state.TransactionSpec.scrollIntoView} */ readonly scrollIntoView: { readonly type: BooleanConstructor; readonly default: true; }; /** * Preserve the current scroll position on external updates. * * This keeps the editor's own scroll container from jumping when * `modelValue` is updated from outside the component. * * @see {@link https://codemirror.net/docs/ref/#view.EditorView.scrollSnapshot} */ readonly preserveScrollPosition: { readonly type: BooleanConstructor; readonly default: false; }; /** * Key map * This is a CodeMirror Facet that allows you to define custom key bindings. * It can be used to override default key bindings or add new ones. * * @see {@link https://codemirror.net/docs/ref/#view.keymap} */ readonly keymap: { readonly type: PropType; readonly default: () => never[]; }; }; /** Resolved prop types for {@link codeMirrorProps}. */ export type CodeMirrorProps = ExtractPropTypes; /** `CodeMirror` component emits definition. */ export declare const codeMirrorEmits: { /** Model Update */ 'update:modelValue': (_value?: string | Text) => boolean; /** CodeMirror ViewUpdate */ update: (_value: ViewUpdate) => boolean; /** CodeMirror onReady */ ready: (_value: { view: EditorView; state: EditorState; container: HTMLElement; }) => boolean; /** CodeMirror onFocus */ focus: (_value: boolean) => boolean; /** State Changed */ change: (_value: EditorState) => boolean; /** CodeMirror onDestroy */ destroy: () => boolean; }; /** Typed `emit` function matching {@link codeMirrorEmits}. */ export type CodeMirrorEmit = { (event: 'update:modelValue', value: string | Text): void; (event: 'update', value: ViewUpdate): void; (event: 'ready', value: { view: EditorView; state: EditorState; container: HTMLElement; }): void; (event: 'focus', value: boolean): void; (event: 'change', value: EditorState): void; (event: 'destroy'): void; }; /** * Sets up a CodeMirror 6 editor instance bound to `props` and reports * changes back through `emit`. * * This encapsulates all editor lifecycle, reactivity, and command logic so * it can be reused outside of the `CodeMirror` component (e.g. in a custom * render function or another component). * * @param props - Resolved `CodeMirror` component props. * @param emit - Typed emit function. */ export declare function useCodeMirror(props: CodeMirrorProps, emit: CodeMirrorEmit): { editor: Ref; view: ShallowRef; cursor: WritableComputedRef; selection: WritableComputedRef; focus: WritableComputedRef; length: Ref; json: WritableComputedRef> | undefined, Record> | undefined>; diagnosticCount: Ref; dom: HTMLElement | undefined; lint: () => void; forceReconfigure: () => void; getRange: (from?: number, to?: number) => string | undefined; getLine: (number: number) => string | undefined; lineCount: () => number; getCursor: () => number; listSelections: () => readonly SelectionRange[]; getSelection: () => string; getSelections: () => string[]; somethingSelected: () => boolean; replaceRange: (replacement: string | Text, from: number, to: number) => void; replaceSelection: (replacement: string | Text) => void; setCursor: (position: number) => void; setSelection: (anchor: number, head?: number) => void; setSelections: (ranges: readonly SelectionRange[], primary?: number) => void; extendSelectionsBy: (f: (range: SelectionRange) => number) => void; };