19.3.0 • Published 5 months ago
@fsegurai/ngx-codemirror v19.3.0
@fsegurai/ngx-codemirror is an Angular library that combines...
- CodeMirror to provide a versatile text editor implemented in JavaScript for the browser
Table of contents
Installation
@fsegurai/ngx-codemirror
To add @fsegurai/ngx-codemirror along with the required codemirror library to your package.json use the following
commands.
npm install @fsegurai/ngx-codemirror --saveUsage
Basic Usage
Import CodemirrorModule / CodeDiffEditorComponent or CodeEditorComponent in your Angular project as shown below:
For Not-Standalone mode, you need to import the `CodemirrorModule` in your Angular module.import { CodeEditorComponent } from '@fsegurai/ngx-codemirror';
@Component({
selector: 'app-root',
imports: [CodeEditorComponent],
templateUrl: './app.component.html',
})
export class AppComponent {
editorContent = '';
selectedTheme = 'forest';
selectedLanguage = 'javascript';
editorSetup = 'basic';
onEditorChange(content: string) {
console.log('Editor Content:', content);
}
}You can customize themes, languages, and editor behavior dynamically.<ngx-code-editor
[value]="editorContent" // or [(ngModel)]="editorContent"
[theme]="selectedTheme"
[language]="selectedLanguage"
[setup]="editorSetup"
[indentWithTab]="true"
[lineWrapping]="true"
(ngModelChange)="onEditorChange($event)">
</ngx-code-editor>Configuration Options
The library provides a customizable editor component with various inputs and outputs for flexible usage.
===== CodeEditorComponent =====
Inputs
root- Specifies the DOM root element for the editor (either Document or ShadowRoot; doesn't support dynamic changes)autoFocus- Sets whether the editor should focus on initialization (doesn't support dynamic changes)value- The editor's content valuedisabled- Whether the editor is disabled (two-way bindable)readonly- Whether the editor is read-onlytheme- The editor's theme ('light' by default)placeholder- Placeholder text shown when the editor is emptyindentWithTab- Whether a Tab key creates indentationindentUnit- Number of spaces used for indentationlineWrapping- Whether text lines should wraphighlightWhitespace- Whether to highlight whitespace characterslanguages- Array of language descriptions for syntax highlighting (doesn't support dynamic changes)language- The programming language for syntax highlightingsetup- The editor's built-in configuration ('basic,' 'minimal,' or null)extensions- Additional CodeMirror extensions to append to the configuration
Outputs
change- Event emitted when the editor's content changesfocus- Event emitted when the editor gains focusblur- Event emitted when the editor loses focus
===== CodeDiffEditorComponent =====
Inputs
theme- The editor's theme ('light' by default)setup- The editor's built-in configuration ('basic,' 'minimal,' or null; doesn't support dynamic changes)originalValue- The content shown in the original (left) editor paneloriginalExtensions- Extensions for the original editor (doesn't support dynamic changes)modifiedValue- The content shown in the modified (right) editor panelmodifiedExtensions- Extensions for the modified editororientation- Controls whether editor A or B is shown firstrevertControls- Controls whether revert controls are shown between changed chunksrenderRevertControl- Function to customize rendering of revert buttonshighlightChanges- Whether to highlight inserted and deleted text in changed chunks (true by default)gutter- Controls whether a gutter marker is shown next to changed lines (true by default)disabled- Whether the diff editor is disabled (two-way bindable)collapseUnchanged- Configuration for collapsing unchanged text sectionsdiffConfig- Options passed to the diff algorithm
Outputs
originalValueChange- Event emitted when the original editor's content changesoriginalFocus- Event emitted when focus is on the original editororiginalBlur- Event emitted when original editor loses focusmodifiedValueChange- Event emitted when the modified editor's content changesmodifiedFocus- Event emitted when focus is on the modified editormodifiedBlur- Event emitted when modified editor loses focus
Demo application
To see the components in action, check out the [DEMO].
To set up the demo locally, follow the next steps:
git clone https://github.com/fsegurai/ngx-codemirror.git
bun install
bun startThis will serve the application locally at http://localhost:4200.
License
Licensed under MIT.
19.3.0
5 months ago
19.3.0-beta.1
5 months ago
19.3.0-beta.0
5 months ago
19.2.0
8 months ago
19.1.0
11 months ago
19.0.0
11 months ago
19.0.0-beta.1
11 months ago