|
| 1 | +<p align="center" class="intro"> |
| 2 | + <img alt="NGX Codemirror Logo" src="https://raw.githubusercontent.com/fsegurai/ngx-codemirror/main/public/ngx-codemirror.png"> |
| 3 | +</p> |
| 4 | + |
| 5 | +<p align="center" class="intro"> |
| 6 | + <a href="https://github.com/fsegurai/ngx-codemirror"> |
| 7 | + <img src="https://img.shields.io/azure-devops/build/fsegurai/93779823-473d-4fb3-a5b1-27aaa1a88ea2/22/main?label=Build%20Status&" |
| 8 | + alt="Build Main Status"> |
| 9 | + </a> |
| 10 | + <a href="https://github.com/fsegurai/ngx-codemirror/releases/latest"> |
| 11 | + <img src="https://img.shields.io/github/v/release/fsegurai/ngx-codemirror" |
| 12 | + alt="Latest Release"> |
| 13 | + </a> |
| 14 | + <br> |
| 15 | + <img alt="GitHub contributors" src="https://img.shields.io/github/contributors/fsegurai/ngx-codemirror"> |
| 16 | + <img alt="Dependency status for repo" src="https://img.shields.io/librariesio/github/fsegurai/ngx-codemirror"> |
| 17 | + <a href="https://opensource.org/licenses/MIT"> |
| 18 | + <img alt="GitHub License" src="https://img.shields.io/github/license/fsegurai/ngx-codemirror"> |
| 19 | + </a> |
| 20 | + <br> |
| 21 | + <img alt="Stars" src="https://img.shields.io/github/stars/fsegurai/ngx-codemirror?style=square&labelColor=343b41"/> |
| 22 | + <img alt="Forks" src="https://img.shields.io/github/forks/fsegurai/ngx-codemirror?style=square&labelColor=343b41"/> |
| 23 | + <a href="https://www.npmjs.com/package/@fsegurai/ngx-codemirror"> |
| 24 | + <img alt="NPM Downloads" src="https://img.shields.io/npm/dt/@fsegurai/ngx-codemirror"> |
| 25 | + </a> |
| 26 | +</p> |
| 27 | + |
| 28 | +`@fsegurai/ngx-codemirror` is an [Angular](https://angular.dev/) library that combines... |
| 29 | + |
| 30 | +- [CodeMirror](https://codemirror.net/) to provide a versatile text editor implemented in JavaScript for the browser |
| 31 | +- [Diff CodeMirror](https://codemirror.net/) to provide a diff editor that allows you to compare two pieces of text side by side. |
| 32 | +- [Unified Diff](https://codemirror.net/) to provide a unified diff editor that allows you to compare two pieces of text side by side. |
| 33 | + |
| 34 | +### Table of contents |
| 35 | + |
| 36 | +- [Installation](#installation) |
| 37 | +- [Usage](#usage) |
| 38 | + - [Basic Usage](#basic-usage) |
| 39 | + - [Configuration Options](#configuration-options) |
| 40 | +- [Demo application](#demo-application) |
| 41 | +- [License](#license) |
| 42 | + |
| 43 | +## Installation |
| 44 | + |
| 45 | +### @fsegurai/ngx-codemirror |
| 46 | + |
| 47 | +To add `@fsegurai/ngx-codemirror` along with the required codemirror library to your `package.json` use the following |
| 48 | +commands. |
| 49 | + |
| 50 | +```bash |
| 51 | +npm install @fsegurai/ngx-codemirror --save |
| 52 | +``` |
| 53 | + |
| 54 | +## Usage |
| 55 | + |
| 56 | +### Basic Usage |
| 57 | + |
| 58 | +Import `CodemirrorModule` / `CodeDiffEditorComponent` or `CodeEditorComponent` in your Angular project as shown below: |
| 59 | + |
| 60 | + For Not-Standalone mode, you need to import the `CodemirrorModule` in your Angular module. |
| 61 | + |
| 62 | +```typescript |
| 63 | +import { CodeEditorComponent } from '@fsegurai/ngx-codemirror'; |
| 64 | + |
| 65 | +@Component({ |
| 66 | + selector: 'app-root', |
| 67 | + imports: [CodeEditorComponent], |
| 68 | + templateUrl: './app.component.html', |
| 69 | +}) |
| 70 | +export class AppComponent { |
| 71 | + editorContent = ''; |
| 72 | + selectedTheme = 'forest'; |
| 73 | + selectedLanguage = 'javascript'; |
| 74 | + editorSetup = 'basic'; |
| 75 | + |
| 76 | + onEditorChange(content: string) { |
| 77 | + console.log('Editor Content:', content); |
| 78 | + } |
| 79 | +} |
| 80 | +``` |
| 81 | + |
| 82 | + You can customize themes, languages, and editor behavior dynamically. |
| 83 | + |
| 84 | +```html |
| 85 | +<ngx-code-editor |
| 86 | + [value]="editorContent" // or [(ngModel)]="editorContent" |
| 87 | + [theme]="selectedTheme" |
| 88 | + [language]="selectedLanguage" |
| 89 | + [setup]="editorSetup" |
| 90 | + [indentWithTab]="true" |
| 91 | + [lineWrapping]="true" |
| 92 | + (ngModelChange)="onEditorChange($event)"> |
| 93 | +</ngx-code-editor> |
| 94 | +``` |
| 95 | + |
| 96 | +### Configuration Options |
| 97 | + |
| 98 | +The library provides a customizable editor component with various inputs and outputs for flexible usage. |
| 99 | + |
| 100 | +#### ===== CodeEditorComponent ===== |
| 101 | + |
| 102 | +##### Inputs |
| 103 | + |
| 104 | +- `root` - Specifies the DOM root element for the editor (either Document or ShadowRoot; doesn't support dynamic changes) |
| 105 | +- `autoFocus` - Sets whether the editor should focus on initialization (doesn't support dynamic changes) |
| 106 | +- `value` - The editor's content value |
| 107 | +- `disabled` - Whether the editor is disabled (two-way bindable) |
| 108 | +- `readonly` - Whether the editor is read-only |
| 109 | +- `theme` - The editor's theme ('light' by default) |
| 110 | +- `placeholder` - Placeholder text shown when the editor is empty |
| 111 | +- `indentWithTab` - Whether a Tab key creates indentation |
| 112 | +- `indentUnit` - Number of spaces used for indentation |
| 113 | +- `lineWrapping` - Whether text lines should wrap |
| 114 | +- `highlightWhitespace` - Whether to highlight whitespace characters |
| 115 | +- `languages` - Array of language descriptions for syntax highlighting (doesn't support dynamic changes) |
| 116 | +- `language` - The programming language for syntax highlighting |
| 117 | +- `setup` - The editor's built-in configuration ('basic,' 'minimal,' or null) |
| 118 | +- `extensions` - Additional CodeMirror extensions to append to the configuration |
| 119 | + |
| 120 | +##### Outputs |
| 121 | + |
| 122 | +- `change` - Event emitted when the editor's content changes |
| 123 | +- `focus` - Event emitted when the editor gains focus |
| 124 | +- `blur` - Event emitted when the editor loses focus |
| 125 | + |
| 126 | +#### ===== CodeDiffEditorComponent ===== |
| 127 | + |
| 128 | +##### Inputs |
| 129 | + |
| 130 | +- `theme` - The editor's theme ('light' by default) |
| 131 | +- `setup` - The editor's built-in configuration ('basic,' 'minimal,' or null; doesn't support dynamic changes) |
| 132 | +- `originalValue` - The content shown in the original (left) editor panel |
| 133 | +- `originalExtensions` - Extensions for the original editor (doesn't support dynamic changes) |
| 134 | +- `modifiedValue` - The content shown in the modified (right) editor panel |
| 135 | +- `modifiedExtensions` - Extensions for the modified editor |
| 136 | +- `orientation` - Controls whether editor A or B is shown first |
| 137 | +- `revertControls` - Controls whether revert controls are shown between changed chunks |
| 138 | +- `renderRevertControl` - Function to customize rendering of revert buttons |
| 139 | +- `highlightChanges` - Whether to highlight inserted and deleted text in changed chunks (true by default) |
| 140 | +- `gutter` - Controls whether a gutter marker is shown next to changed lines (true by default) |
| 141 | +- `disabled` - Whether the diff editor is disabled (two-way bindable) |
| 142 | +- `collapseUnchanged` - Configuration for collapsing unchanged text sections |
| 143 | +- `diffConfig` - Options passed to the diff algorithm |
| 144 | + |
| 145 | +##### Outputs |
| 146 | + |
| 147 | +- `originalValueChange` - Event emitted when the original editor's content changes |
| 148 | +- `originalFocus` - Event emitted when focus is on the original editor |
| 149 | +- `originalBlur` - Event emitted when original editor loses focus |
| 150 | +- `modifiedValueChange` - Event emitted when the modified editor's content changes |
| 151 | +- `modifiedFocus` - Event emitted when focus is on the modified editor |
| 152 | +- `modifiedBlur` - Event emitted when modified editor loses focus |
| 153 | + |
| 154 | +## Demo application |
| 155 | + |
| 156 | +To see the components in action, check out the [[DEMO]](https://fsegurai.github.io/ngx-codemirror). |
| 157 | + |
| 158 | +To set up the demo locally, follow the next steps: |
| 159 | + |
| 160 | +```bash |
| 161 | +git clone https://github.com/fsegurai/ngx-codemirror.git |
| 162 | +bun install |
| 163 | +bun start |
| 164 | +``` |
| 165 | + |
| 166 | +This will serve the application locally at [http://localhost:4200](http://localhost:4200). |
| 167 | + |
| 168 | +## License |
| 169 | + |
| 170 | +Licensed under [MIT](https://opensource.org/licenses/MIT). |
0 commit comments