ngx-rich-text-pro 1.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +525 -0
- package/fesm2022/ngx-rich-text-editor.mjs +1973 -0
- package/fesm2022/ngx-rich-text-editor.mjs.map +1 -0
- package/fesm2022/ngx-rich-text-pro.mjs +1973 -0
- package/fesm2022/ngx-rich-text-pro.mjs.map +1 -0
- package/package.json +45 -0
- package/types/ngx-rich-text-editor.d.ts +378 -0
- package/types/ngx-rich-text-pro.d.ts +378 -0
package/README.md
ADDED
|
@@ -0,0 +1,525 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
3
|
+
# 📝 ngx-rich-text-pro
|
|
4
|
+
|
|
5
|
+
**The Modern, Lightweight, Zero-Dependency Rich Text & Social Post Editor for Angular.**
|
|
6
|
+
|
|
7
|
+
Built for modern Angular (17, 18, 19, 20, 21+), Standalone Components, Reactive Forms, Signals, and Headless Custom UI.
|
|
8
|
+
|
|
9
|
+
[](https://www.npmjs.com/package/ngx-rich-text-pro)
|
|
10
|
+
[](https://angular.dev)
|
|
11
|
+
[](LICENSE)
|
|
12
|
+
[](#)
|
|
13
|
+
[](https://www.typescriptlang.org/)
|
|
14
|
+
|
|
15
|
+
</div>
|
|
16
|
+
|
|
17
|
+
---
|
|
18
|
+
|
|
19
|
+
## ✨ Why ngx-rich-text-pro?
|
|
20
|
+
|
|
21
|
+
- 🚀 **Zero External Dependencies**: Built-in, clean vector SVG icons. No heavy FontAwesome or Material font stylesheets required.
|
|
22
|
+
- 🎯 **Modern Angular Native**: Fully standalone, zoneless/signals compatible, designed for Angular 17 through 21+.
|
|
23
|
+
- 📝 **First-Class Angular Forms**: Seamless `ControlValueAccessor` integration with Reactive Forms (`[formControl]`), `FormGroup`, and `[(ngModel)]`.
|
|
24
|
+
- 🎛️ **Array-Driven Custom Toolbar**: Pick only the tools you need with a simple array (`[tools]="['bold', 'italic', 'underline', 'bulletList', 'orderedList']"`).
|
|
25
|
+
- 🧩 **Headless / Callable API**: Don't want the default toolbar? Hide it and trigger `editor.bold()`, `editor.italic()`, `editor.insertOrderedList()` from your own custom UI anywhere in the DOM.
|
|
26
|
+
- 🏷️ **Real-Time Hashtag Highlight**: Automatically highlights `#hashtags` with customizable colors (`[hashtagColor]="'#0069FF'"`), automatic space breakout, and 100% editable/selectable text.
|
|
27
|
+
- 🔢 **Smart Collision-Free Placeholder**: The placeholder cleanly hides when lists (`1.`, `•`), tables, quotes, or code blocks are active so text never overlaps with list markers.
|
|
28
|
+
- 🎨 **Typography & Theming**: Custom font family (`'Open Sans'`, `'Poppins'`, `'Inter'`), custom font dropdown list, transparent or custom backgrounds, and CSS variables.
|
|
29
|
+
- 📊 **Live Stats & Character Limits**: Built-in word counter, character counter, and hard/soft character limit warnings.
|
|
30
|
+
- 🖼️ **Images & Links**: Insert images via URL or local file upload (automatic Base64 conversion) and insert links with new-tab toggle.
|
|
31
|
+
- ⌨️ **Keyboard Shortcuts**: Built-in support for `Ctrl+B`, `Ctrl+I`, `Ctrl+U`, `Ctrl+Z`, `Ctrl+Y`, `Ctrl+K`, `Tab`, and `Shift+Tab`.
|
|
32
|
+
|
|
33
|
+
---
|
|
34
|
+
|
|
35
|
+
## 📦 Installation
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
npm install ngx-rich-text-pro
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
---
|
|
42
|
+
|
|
43
|
+
## 🚀 Getting Started
|
|
44
|
+
|
|
45
|
+
### 1. Import the Component
|
|
46
|
+
|
|
47
|
+
Import `NgxRichTextProComponent` (or `NgxRichTextEditorComponent`) into your standalone component:
|
|
48
|
+
|
|
49
|
+
```typescript
|
|
50
|
+
import { Component } from '@angular/core';
|
|
51
|
+
import { FormControl, ReactiveFormsModule } from '@angular/forms';
|
|
52
|
+
import { NgxRichTextProComponent, ToolbarItem } from 'ngx-rich-text-pro';
|
|
53
|
+
|
|
54
|
+
@Component({
|
|
55
|
+
selector: 'app-example',
|
|
56
|
+
standalone: true,
|
|
57
|
+
imports: [ReactiveFormsModule, NgxRichTextProComponent],
|
|
58
|
+
template: `
|
|
59
|
+
<!-- Show ONLY Bold, Italic, Underline, Lists, Emoji, and a custom AI button -->
|
|
60
|
+
<ngx-rich-text-pro
|
|
61
|
+
[formControl]="contentControl"
|
|
62
|
+
[tools]="tools"
|
|
63
|
+
[maxCharacters]="3000"
|
|
64
|
+
placeholder="What do you want to talk about?"
|
|
65
|
+
></ngx-rich-text-pro>
|
|
66
|
+
`
|
|
67
|
+
})
|
|
68
|
+
export class ExampleComponent {
|
|
69
|
+
contentControl = new FormControl('');
|
|
70
|
+
|
|
71
|
+
// Define ONLY the tools you want in an array!
|
|
72
|
+
tools: ToolbarItem[] = [
|
|
73
|
+
'bold',
|
|
74
|
+
'italic',
|
|
75
|
+
'underline',
|
|
76
|
+
'bulletList',
|
|
77
|
+
'orderedList',
|
|
78
|
+
'emoji',
|
|
79
|
+
'|',
|
|
80
|
+
{
|
|
81
|
+
label: 'Write with AI',
|
|
82
|
+
icon: '✨',
|
|
83
|
+
customClass: 'btn-ai',
|
|
84
|
+
action: (editor) => editor.insertHtml('<p>✨ Smart draft from AI...</p>')
|
|
85
|
+
}
|
|
86
|
+
];
|
|
87
|
+
}
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
---
|
|
91
|
+
|
|
92
|
+
## 💡 Popular Use-Case Recipes
|
|
93
|
+
|
|
94
|
+
### Recipe 1: Social Media Post Creator (LinkedIn, Twitter/X, Threads)
|
|
95
|
+
|
|
96
|
+
Build a clean post composer with real-time blue hashtags, custom font, and transparent background:
|
|
97
|
+
|
|
98
|
+
```html
|
|
99
|
+
<ngx-rich-text-pro
|
|
100
|
+
[formControl]="postControl"
|
|
101
|
+
[tools]="['bold', 'italic', 'underline', 'orderedList', 'bulletList', 'emoji']"
|
|
102
|
+
[fontFamily]="'\'Open Sans\', sans-serif'"
|
|
103
|
+
[hashtagColor]="'#0069FF'"
|
|
104
|
+
[editorStyle]="{ 'background-color': 'transparent' }"
|
|
105
|
+
[contentStyle]="{ 'background-color': 'transparent', 'min-height': '220px' }"
|
|
106
|
+
[maxCharacters]="3000"
|
|
107
|
+
placeholder="What do you want to share today?"
|
|
108
|
+
></ngx-rich-text-pro>
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### Recipe 2: Headless / Custom External Buttons Anywhere in your UI
|
|
112
|
+
|
|
113
|
+
You can completely hide the built-in toolbar (`[showToolbar]="false"`) and trigger formatting from **your own custom buttons or modals anywhere in the DOM**:
|
|
114
|
+
|
|
115
|
+
```html
|
|
116
|
+
<!-- Your own custom toolbar layout -->
|
|
117
|
+
<div class="my-custom-toolbar">
|
|
118
|
+
<button
|
|
119
|
+
type="button"
|
|
120
|
+
[class.active]="editor.isFormatActive('bold')"
|
|
121
|
+
(mousedown)="$event.preventDefault(); editor.bold()"
|
|
122
|
+
>
|
|
123
|
+
Bold
|
|
124
|
+
</button>
|
|
125
|
+
|
|
126
|
+
<button
|
|
127
|
+
type="button"
|
|
128
|
+
[class.active]="editor.isFormatActive('italic')"
|
|
129
|
+
(mousedown)="$event.preventDefault(); editor.italic()"
|
|
130
|
+
>
|
|
131
|
+
Italic
|
|
132
|
+
</button>
|
|
133
|
+
|
|
134
|
+
<button
|
|
135
|
+
type="button"
|
|
136
|
+
[class.active]="editor.isFormatActive('underline')"
|
|
137
|
+
(mousedown)="$event.preventDefault(); editor.underline()"
|
|
138
|
+
>
|
|
139
|
+
Underline
|
|
140
|
+
</button>
|
|
141
|
+
|
|
142
|
+
<button
|
|
143
|
+
type="button"
|
|
144
|
+
[class.active]="editor.isFormatActive('insertOrderedList')"
|
|
145
|
+
(mousedown)="$event.preventDefault(); editor.insertOrderedList()"
|
|
146
|
+
>
|
|
147
|
+
1. Numbered List
|
|
148
|
+
</button>
|
|
149
|
+
|
|
150
|
+
<button
|
|
151
|
+
type="button"
|
|
152
|
+
[class.active]="editor.isFormatActive('insertUnorderedList')"
|
|
153
|
+
(mousedown)="$event.preventDefault(); editor.insertUnorderedList()"
|
|
154
|
+
>
|
|
155
|
+
• Bullet List
|
|
156
|
+
</button>
|
|
157
|
+
|
|
158
|
+
<button
|
|
159
|
+
type="button"
|
|
160
|
+
(mousedown)="$event.preventDefault(); editor.insertHtml('<strong>✨ AI Draft</strong>')"
|
|
161
|
+
>
|
|
162
|
+
Insert AI Snippet
|
|
163
|
+
</button>
|
|
164
|
+
</div>
|
|
165
|
+
|
|
166
|
+
<!-- Editor with built-in toolbar hidden -->
|
|
167
|
+
<ngx-rich-text-pro
|
|
168
|
+
#editor
|
|
169
|
+
[showToolbar]="false"
|
|
170
|
+
[showStatusBar]="false"
|
|
171
|
+
[formControl]="postControl"
|
|
172
|
+
[hashtagColor]="'#0069FF'"
|
|
173
|
+
placeholder="What do you want to talk about?"
|
|
174
|
+
></ngx-rich-text-pro>
|
|
175
|
+
```
|
|
176
|
+
|
|
177
|
+
---
|
|
178
|
+
|
|
179
|
+
## 🏷️ Real-Time Hashtag Engine
|
|
180
|
+
|
|
181
|
+
`ngx-rich-text-pro` includes a real-time hashtag parsing engine:
|
|
182
|
+
- **Instant Highlighting**: Any word preceded by `#` (e.g., `#angular`, `#developer`) is styled with `[hashtagColor]` (default: `#0069FF`).
|
|
183
|
+
- **Clean Space Breakout**: When the user presses `Space` or `Enter` after a hashtag, subsequent words automatically return to the default font color.
|
|
184
|
+
- **100% Editable & Selectable**: Unlike rigid token tags, users can freely click inside the hashtag, select letters, backspace, and fix typos just like standard text.
|
|
185
|
+
- **Smart Unwrap**: Deleting the `#` prefix immediately unwraps the word and restores regular text styling.
|
|
186
|
+
|
|
187
|
+
---
|
|
188
|
+
|
|
189
|
+
## 🔢 Collision-Free Smart Placeholder
|
|
190
|
+
|
|
191
|
+
Standard rich text editors often suffer from placeholders overlapping list numbers (e.g. `1. What do you want to share...`).
|
|
192
|
+
|
|
193
|
+
`ngx-rich-text-pro` includes smart structural detection:
|
|
194
|
+
- The placeholder displays on empty paragraphs.
|
|
195
|
+
- As soon as the user starts an ordered list (`1.`), bullet list (`•`), blockquote, code block, or table, the placeholder is **cleanly suppressed**.
|
|
196
|
+
- If the list item is deleted (e.g. pressing `Backspace`), the placeholder naturally reappears.
|
|
197
|
+
|
|
198
|
+
---
|
|
199
|
+
|
|
200
|
+
## 📦 Using with `[(ngModel)]`
|
|
201
|
+
|
|
202
|
+
```typescript
|
|
203
|
+
import { Component } from '@angular/core';
|
|
204
|
+
import { FormsModule } from '@angular/forms';
|
|
205
|
+
import { NgxRichTextProComponent } from 'ngx-rich-text-pro';
|
|
206
|
+
|
|
207
|
+
@Component({
|
|
208
|
+
selector: 'app-model-example',
|
|
209
|
+
standalone: true,
|
|
210
|
+
imports: [FormsModule, NgxRichTextProComponent],
|
|
211
|
+
template: `
|
|
212
|
+
<ngx-rich-text-pro [(ngModel)]="htmlContent"></ngx-rich-text-pro>
|
|
213
|
+
`
|
|
214
|
+
})
|
|
215
|
+
export class ModelExampleComponent {
|
|
216
|
+
htmlContent = '<p>Initial content</p>';
|
|
217
|
+
}
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
---
|
|
221
|
+
|
|
222
|
+
## ⚙️ Configuration & Customization
|
|
223
|
+
|
|
224
|
+
You can customize the toolbar and editor behavior via the `[config]` input:
|
|
225
|
+
|
|
226
|
+
```typescript
|
|
227
|
+
import { Component } from '@angular/core';
|
|
228
|
+
import { NgxRichTextProComponent, NgxEditorConfig } from 'ngx-rich-text-pro';
|
|
229
|
+
|
|
230
|
+
@Component({
|
|
231
|
+
selector: 'app-custom-editor',
|
|
232
|
+
standalone: true,
|
|
233
|
+
imports: [NgxRichTextProComponent],
|
|
234
|
+
template: `
|
|
235
|
+
<ngx-rich-text-pro [config]="customConfig"></ngx-rich-text-pro>
|
|
236
|
+
`
|
|
237
|
+
})
|
|
238
|
+
export class CustomEditorComponent {
|
|
239
|
+
customConfig: Partial<NgxEditorConfig> = {
|
|
240
|
+
placeholder: 'Write something amazing...',
|
|
241
|
+
minHeight: '300px',
|
|
242
|
+
showStatusBar: true,
|
|
243
|
+
showWordCount: true,
|
|
244
|
+
showCharCount: true,
|
|
245
|
+
toolbar: {
|
|
246
|
+
history: true,
|
|
247
|
+
format: true,
|
|
248
|
+
fontSize: true,
|
|
249
|
+
fontName: true,
|
|
250
|
+
inline: {
|
|
251
|
+
bold: true,
|
|
252
|
+
italic: true,
|
|
253
|
+
underline: true,
|
|
254
|
+
code: true
|
|
255
|
+
},
|
|
256
|
+
color: {
|
|
257
|
+
textColor: true,
|
|
258
|
+
backgroundColor: true
|
|
259
|
+
},
|
|
260
|
+
alignment: {
|
|
261
|
+
left: true,
|
|
262
|
+
center: true,
|
|
263
|
+
right: true,
|
|
264
|
+
justify: true
|
|
265
|
+
},
|
|
266
|
+
list: {
|
|
267
|
+
unordered: true,
|
|
268
|
+
ordered: true,
|
|
269
|
+
indent: true,
|
|
270
|
+
outdent: true
|
|
271
|
+
},
|
|
272
|
+
insert: {
|
|
273
|
+
link: true,
|
|
274
|
+
image: true,
|
|
275
|
+
horizontalRule: true
|
|
276
|
+
},
|
|
277
|
+
extra: {
|
|
278
|
+
clearFormat: true,
|
|
279
|
+
sourceView: true
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
```
|
|
285
|
+
|
|
286
|
+
---
|
|
287
|
+
|
|
288
|
+
## 🎨 Custom Styling & Custom Font Family
|
|
289
|
+
|
|
290
|
+
`ngx-rich-text-pro` supports full typography and styling customization out of the box.
|
|
291
|
+
|
|
292
|
+
### 1. Custom Font Family via Input
|
|
293
|
+
Apply any Google font or design system font directly to the editor:
|
|
294
|
+
|
|
295
|
+
```html
|
|
296
|
+
<ngx-rich-text-pro
|
|
297
|
+
[fontFamily]="'Poppins, sans-serif'"
|
|
298
|
+
[fontSize]="'16px'"
|
|
299
|
+
[tools]="['fontFamily', 'fontSize', '|', 'bold', 'italic', 'underline']"
|
|
300
|
+
></ngx-rich-text-pro>
|
|
301
|
+
```
|
|
302
|
+
|
|
303
|
+
### 2. Custom Font Family Dropdown List (`[fontFamilies]`)
|
|
304
|
+
Provide your own custom font families to the dropdown in the toolbar:
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
customFonts = [
|
|
308
|
+
{ label: 'Poppins (Google Font)', value: "'Poppins', sans-serif" },
|
|
309
|
+
{ label: 'Inter (UI Sans)', value: "'Inter', sans-serif" },
|
|
310
|
+
{ label: 'Playfair Display (Serif)', value: "'Playfair Display', Georgia, serif" },
|
|
311
|
+
{ label: 'Fira Code (Code)', value: "'Fira Code', monospace" },
|
|
312
|
+
{ label: 'Roboto', value: "'Roboto', sans-serif" }
|
|
313
|
+
];
|
|
314
|
+
```
|
|
315
|
+
|
|
316
|
+
In your template:
|
|
317
|
+
```html
|
|
318
|
+
<ngx-rich-text-pro
|
|
319
|
+
[fontFamilies]="customFonts"
|
|
320
|
+
[tools]="['fontFamily', 'fontSize', '|', 'bold', 'italic', 'underline']"
|
|
321
|
+
></ngx-rich-text-pro>
|
|
322
|
+
```
|
|
323
|
+
|
|
324
|
+
### 3. Custom Theming via CSS Custom Properties
|
|
325
|
+
The editor automatically inherits your app's font family by default (`inherit`), or you can define design tokens:
|
|
326
|
+
|
|
327
|
+
```scss
|
|
328
|
+
ngx-rich-text-pro {
|
|
329
|
+
--ngx-editor-font-family: 'Poppins', sans-serif;
|
|
330
|
+
--ngx-editor-font-size: 16px;
|
|
331
|
+
--ngx-editor-line-height: 1.7;
|
|
332
|
+
--ngx-editor-border: #cbd5e1;
|
|
333
|
+
--ngx-editor-border-focus: #6366f1;
|
|
334
|
+
--ngx-editor-radius: 12px;
|
|
335
|
+
--ngx-editor-bg: #ffffff;
|
|
336
|
+
--ngx-editor-text: #0f172a;
|
|
337
|
+
--ngx-editor-toolbar-bg: #f8fafc;
|
|
338
|
+
--ngx-editor-toolbar-btn-active: #e0e7ff;
|
|
339
|
+
--ngx-editor-toolbar-btn-active-color: #4338ca;
|
|
340
|
+
}
|
|
341
|
+
```
|
|
342
|
+
|
|
343
|
+
### 4. Custom Classes & Inline Styles
|
|
344
|
+
```html
|
|
345
|
+
<ngx-rich-text-pro
|
|
346
|
+
[customClass]="'my-brand-editor'"
|
|
347
|
+
[editorStyle]="{ 'border-radius': '16px', 'box-shadow': '0 4px 6px -1px rgba(0,0,0,0.1)' }"
|
|
348
|
+
[contentStyle]="{ 'min-height': '350px', 'line-height': '1.8' }"
|
|
349
|
+
></ngx-rich-text-pro>
|
|
350
|
+
```
|
|
351
|
+
|
|
352
|
+
### 5. Direct Callable API for Fonts & Colors
|
|
353
|
+
```typescript
|
|
354
|
+
// Call from anywhere:
|
|
355
|
+
editor.setFontFamily("'Poppins', sans-serif");
|
|
356
|
+
editor.setFontSize(4); // Or 1-7
|
|
357
|
+
editor.setTextColor('#4f46e5');
|
|
358
|
+
editor.setBackgroundColor('#fef08a');
|
|
359
|
+
```
|
|
360
|
+
|
|
361
|
+
---
|
|
362
|
+
|
|
363
|
+
## 📖 API Reference
|
|
364
|
+
|
|
365
|
+
### Component Inputs (`ngx-rich-text-pro`)
|
|
366
|
+
|
|
367
|
+
*(Note: `<ngx-rich-text-editor>` is also supported as an alias for backwards compatibility).*
|
|
368
|
+
|
|
369
|
+
| Input | Type | Default | Description |
|
|
370
|
+
| :--- | :--- | :--- | :--- |
|
|
371
|
+
| `value` | `string` | `''` | Initial HTML content (or bind with `formControl` / `ngModel`) |
|
|
372
|
+
| `placeholder` | `string` | `'Compose your content here...'` | Placeholder text when editor is empty |
|
|
373
|
+
| `tools` | `ToolbarItem[]` | `undefined` | Array of tools to display. Overrides default toolbar |
|
|
374
|
+
| `showToolbar` | `boolean` | `true` | Show or hide the top toolbar (set `false` for headless mode) |
|
|
375
|
+
| `showStatusBar` | `boolean` | `true` | Show or hide the bottom character/word counter bar |
|
|
376
|
+
| `fontFamily` | `string` | `''` | Custom base font family (e.g. `'Open Sans', sans-serif`) |
|
|
377
|
+
| `fontSize` | `string` | `''` | Custom base font size (e.g. `'15px'`) |
|
|
378
|
+
| `fontFamilies` | `Array<FontFamilyOption \| string>` | `DEFAULT_FONT_FAMILIES` | Font family options in the toolbar dropdown |
|
|
379
|
+
| `hashtagColor` | `string` | `'#0069FF'` | Color used for highlighted `#hashtags` |
|
|
380
|
+
| `highlightHashtags` | `boolean` | `true` | Enable or disable real-time hashtag highlighting |
|
|
381
|
+
| `maxCharacters` | `number` | `undefined` | Hard maximum character limit |
|
|
382
|
+
| `characterCountWarn` | `number` | `undefined` | Threshold to show a warning badge as limit approaches |
|
|
383
|
+
| `customClass` | `string` | `''` | Custom CSS class applied to host container |
|
|
384
|
+
| `editorStyle` | `Record<string, string> \| string` | `''` | Custom styles for editor outer container |
|
|
385
|
+
| `contentStyle` | `Record<string, string> \| string` | `''` | Custom styles for editable content area |
|
|
386
|
+
| `disabled` | `boolean` | `false` | Whether editor is disabled |
|
|
387
|
+
| `readonly` | `boolean` | `false` | Read-only mode (disables editing & toolbar) |
|
|
388
|
+
| `config` | `Partial<NgxEditorConfig>` | `{}` | Complete configuration options object |
|
|
389
|
+
|
|
390
|
+
### Component Outputs
|
|
391
|
+
|
|
392
|
+
| Output | Event Type | Description |
|
|
393
|
+
| :--- | :--- | :--- |
|
|
394
|
+
| `valueChange` | `EventEmitter<string>` | Emits updated HTML string on every change |
|
|
395
|
+
| `textChange` | `EventEmitter<{ html: string; text: string }>` | Emits both HTML and plain-text representation |
|
|
396
|
+
|
|
397
|
+
### Callable Public Methods (`#editorRef`)
|
|
398
|
+
|
|
399
|
+
| Method | Parameters | Description |
|
|
400
|
+
| :--- | :--- | :--- |
|
|
401
|
+
| `bold()` | - | Toggles bold on selection |
|
|
402
|
+
| `italic()` | - | Toggles italic on selection |
|
|
403
|
+
| `underline()` | - | Toggles underline on selection |
|
|
404
|
+
| `strike()` | - | Toggles strikethrough on selection |
|
|
405
|
+
| `subscript()` | - | Toggles subscript on selection |
|
|
406
|
+
| `superscript()` | - | Toggles superscript on selection |
|
|
407
|
+
| `insertOrderedList()` | - | Toggles numbered list (`1.`) |
|
|
408
|
+
| `insertUnorderedList()` | - | Toggles bullet list (`•`) |
|
|
409
|
+
| `indent()` | - | Indents current line/list item |
|
|
410
|
+
| `outdent()` | - | Outdents current line/list item |
|
|
411
|
+
| `alignLeft()` / `alignCenter()` / `alignRight()` / `alignJustify()` | - | Sets text alignment |
|
|
412
|
+
| `setHeading(level)` | `level: 1 \| 2 \| 3 \| 4 \| 5 \| 6` | Formats current block as heading |
|
|
413
|
+
| `setParagraph()` | - | Formats current block as paragraph |
|
|
414
|
+
| `setBlockquote()` | - | Formats current block as blockquote |
|
|
415
|
+
| `setCodeBlock()` | - | Formats current block as preformatted code |
|
|
416
|
+
| `setFontFamily(font)` | `font: string` | Applies font family to selection or editor |
|
|
417
|
+
| `setFontSize(size)` | `size: string \| number` | Applies font size to selection |
|
|
418
|
+
| `setTextColor(color)` | `color: string` | Sets text color |
|
|
419
|
+
| `setBackgroundColor(color)` | `color: string` | Sets text background/highlight color |
|
|
420
|
+
| `setHashtagColor(color)` | `color: string` | Changes the hashtag highlight color |
|
|
421
|
+
| `insertHtml(html)` | `html: string` | Inserts arbitrary HTML string at cursor |
|
|
422
|
+
| `insertText(text)` | `text: string` | Inserts plain text at cursor |
|
|
423
|
+
| `insertEmoji(emoji)` | `emoji: string` | Inserts emoji at cursor |
|
|
424
|
+
| `insertLink(url, text?, newTab?)` | `url: string, ...` | Inserts hyperlink |
|
|
425
|
+
| `removeLink()` | - | Removes link from selection |
|
|
426
|
+
| `insertImage(url, alt?)` | `url: string, ...` | Inserts image |
|
|
427
|
+
| `insertHorizontalRule()` | - | Inserts horizontal rule (`<hr>`) |
|
|
428
|
+
| `clearFormatting()` | - | Strips all formatting from selection |
|
|
429
|
+
| `undo()` / `redo()` | - | History undo / redo |
|
|
430
|
+
| `focus()` | - | Focuses the editor content area |
|
|
431
|
+
| `getHtml()` | - | Returns current HTML content |
|
|
432
|
+
| `getText()` | - | Returns plain text representation |
|
|
433
|
+
| `isFormatActive(format)` | `format: string` | Checks if a format (`'bold'`, `'italic'`, `'insertOrderedList'`, etc.) is currently active |
|
|
434
|
+
|
|
435
|
+
### Supported Toolbar Tool Identifiers
|
|
436
|
+
|
|
437
|
+
When providing an array to `[tools]`, you can use any of these identifiers:
|
|
438
|
+
|
|
439
|
+
| Identifier | Action |
|
|
440
|
+
| :--- | :--- |
|
|
441
|
+
| `'bold'` | Bold formatting button |
|
|
442
|
+
| `'italic'` | Italic formatting button |
|
|
443
|
+
| `'underline'` | Underline formatting button |
|
|
444
|
+
| `'strikeThrough'` | Strikethrough button |
|
|
445
|
+
| `'orderedList'` | Numbered list button |
|
|
446
|
+
| `'bulletList'` | Bullet list button |
|
|
447
|
+
| `'indent'` | Indent button |
|
|
448
|
+
| `'outdent'` | Outdent button |
|
|
449
|
+
| `'alignLeft'` | Align text left |
|
|
450
|
+
| `'alignCenter'` | Align text center |
|
|
451
|
+
| `'alignRight'` | Align text right |
|
|
452
|
+
| `'alignJustify'` | Justify text |
|
|
453
|
+
| `'format'` | Headings & paragraph dropdown |
|
|
454
|
+
| `'fontFamily'` | Font family selector dropdown |
|
|
455
|
+
| `'fontSize'` | Font size selector dropdown |
|
|
456
|
+
| `'textColor'` | Text color picker |
|
|
457
|
+
| `'backgroundColor'` | Background highlight color picker |
|
|
458
|
+
| `'link'` | Insert link modal |
|
|
459
|
+
| `'image'` | Insert image modal |
|
|
460
|
+
| `'emoji'` | Insert emoji picker |
|
|
461
|
+
| `'horizontalRule'` | Insert divider line |
|
|
462
|
+
| `'clear'` | Clear formatting button |
|
|
463
|
+
| `'undo'` | Undo button |
|
|
464
|
+
| `'redo'` | Redo button |
|
|
465
|
+
| `'sourceView'` | Toggle raw HTML source view |
|
|
466
|
+
| `'\|'` | Visual toolbar divider |
|
|
467
|
+
| `CustomToolbarButton` | `{ label, icon, customClass, action: (editor) => ... }` |
|
|
468
|
+
|
|
469
|
+
---
|
|
470
|
+
|
|
471
|
+
## 🎨 CSS Variables & Theming
|
|
472
|
+
|
|
473
|
+
```scss
|
|
474
|
+
ngx-rich-text-pro,
|
|
475
|
+
ngx-rich-text-editor {
|
|
476
|
+
--ngx-editor-border: #e2e8f0;
|
|
477
|
+
--ngx-editor-border-focus: #3b82f6;
|
|
478
|
+
--ngx-editor-radius: 8px;
|
|
479
|
+
--ngx-editor-bg: #ffffff;
|
|
480
|
+
--ngx-editor-text: #1e293b;
|
|
481
|
+
--ngx-editor-toolbar-bg: #f8fafc;
|
|
482
|
+
--ngx-editor-toolbar-border: #e2e8f0;
|
|
483
|
+
--ngx-editor-toolbar-btn-active: #dbeafe;
|
|
484
|
+
--ngx-editor-toolbar-btn-active-color: #1d4ed8;
|
|
485
|
+
--ngx-editor-hashtag-color: #0069FF;
|
|
486
|
+
}
|
|
487
|
+
```
|
|
488
|
+
|
|
489
|
+
---
|
|
490
|
+
|
|
491
|
+
## 🚀 How to Publish to npm
|
|
492
|
+
|
|
493
|
+
Ready to publish this package to npm? Follow these simple steps:
|
|
494
|
+
|
|
495
|
+
### 1. Login to your npm account
|
|
496
|
+
```bash
|
|
497
|
+
npm login
|
|
498
|
+
```
|
|
499
|
+
|
|
500
|
+
### 2. Build the package
|
|
501
|
+
```bash
|
|
502
|
+
npm run build:lib
|
|
503
|
+
```
|
|
504
|
+
*This compiles the Angular library into standard Angular Package Format (APF) inside the `dist/ngx-rich-text-editor` directory.*
|
|
505
|
+
|
|
506
|
+
### 3. Verify the package output (Optional)
|
|
507
|
+
```bash
|
|
508
|
+
npm run pack:lib
|
|
509
|
+
```
|
|
510
|
+
*Creates `ngx-rich-text-pro-1.0.0.tgz` for local inspection.*
|
|
511
|
+
|
|
512
|
+
### 4. Publish to npm!
|
|
513
|
+
```bash
|
|
514
|
+
cd dist/ngx-rich-text-editor
|
|
515
|
+
npm publish --access public
|
|
516
|
+
```
|
|
517
|
+
|
|
518
|
+
Your package will immediately be live on **`https://www.npmjs.com/package/ngx-rich-text-pro`**! 🎉
|
|
519
|
+
|
|
520
|
+
---
|
|
521
|
+
|
|
522
|
+
## 📄 License
|
|
523
|
+
|
|
524
|
+
MIT License © 2026. Free for commercial and personal use.
|
|
525
|
+
|