UNPKG

9.85 kBMarkdownView Raw
1# ngx-quill [![Build Status](https://travis-ci.org/KillerCodeMonkey/ngx-quill.svg?branch=develop)](https://travis-ci.org/KillerCodeMonkey/ngx-quill)
2
3<img src="https://cloud.githubusercontent.com/assets/2264672/20601381/a51753d4-b258-11e6-92c2-1d79efa5bede.png" width="200px">
4
5ngx-quill is an angular (>=2) component for the [Quill Rich Text Editor](https://quilljs.com/).
6
7## Donate/Support
8
9If you like my work, feel free to support it. Donations to the project are always welcomed :)
10
11PayPal: [PayPal.Me/bengtler](http://paypal.me/bengtler)
12
13BTC Wallet Address:
14`3QVyr2tpRLBCw1kBQ59sTDraV6DTswq8Li`
15
16ETH Wallet Address:
17`0x394d44f3b6e3a4f7b4d44991e7654b0cab4af68f`
18
19LTC Wallet Address:
20`MFif769WSZ1g7ReAzzDE7TJVqtkFpmoTyT`
21
22XRP Wallet Address:
23`rXieaAC3nevTKgVu2SYoShjTCS2Tfczqx?dt=159046833`
24
25## Examples
26
27- [Advanced Demo](https://github.com/killerCodeMonkey/ngx-quill-example)
28 - integration of [quill-emoji](https://github.com/contentco/quill-emoji)
29 - integration of [quill-mention](https://github.com/afconsult/quill-mention)
30 - integration of [quill-image-resize](https://github.com/kensnyder/quill-image-resize-module)
31 - custom word count module
32 - custom toolbar with custom fonts and formats, toolbar position
33 - show the differences between sanitizing and not sanitizing your content if your content format is html
34 - usage of different content formats
35 - template-driven and reactive forms
36 - code + syntax highlighting
37 - formulas
38 - custom key-bindings, e.g. shift + b for bold
39 - dynamic styles and placeholder
40 - toggle readonly
41 - bubble toolbar
42 - activate formats after editor initialisation, e.g. rtl direction
43- [Ionic v3 Demo](https://github.com/KillerCodeMonkey/ngx-quill-ionic-v3)
44
45## Compatibility to Angular Versions
46
47<table>
48 <thead>
49 <tr>
50 <th>Angular</th>
51 <th>ngx-quill</th>
52 </tr>
53 </thead>
54 <tbody>
55 <tr>
56 <td>
57 v4
58 </td>
59 <td>
60 < 1.6.0
61 </td>
62 </tr>
63 <tr>
64 <td>
65 v5
66 </td>
67 <td>
68 > 1.6.0
69 </td>
70 </tr>
71 <tr>
72 <td>
73 v6
74 </td>
75 <td>
76 >= 3.0.0
77 </td>
78 </tr>
79 <tr>
80 <td>
81 v7
82 </td>
83 <td>
84 >= 4.0.0
85 </td>
86 </tr>
87 </tbody>
88</table>
89
90## Installation
91
92- `npm install ngx-quill`
93- for projects using Angular < v5.0.0 install `npm install ngx-quill@1.6.0`
94- install `@angular/core`, `@angular/common`, `@angular/forms`, `quill` and `rxjs` - peer dependencies of ngx-quill
95- include theme stylings: bubble.css, snow.css of quilljs in your index.html, or add them in your css/scss files with `@import` statements, or add them external stylings in your build process.
96
97### For standard webpack, angular-cli and tsc builds
98
99- import `QuillModule` from `ngx-quill`:
100```
101import { QuillModule } from 'ngx-quill'
102```
103- add `QuillModule` to the imports of your NgModule:
104```
105@NgModule({
106 imports: [
107 ...,
108
109 QuillModule
110 ],
111 ...
112})
113class YourModule { ... }
114```
115- use `<quill-editor></quill-editor>` in your templates to add a default quill editor
116- do not forget to include quill + theme css in your buildprocess, module or index.html!
117- for builds with angular-cli >=6 only add quilljs to your scripts or scripts section of angular.json, if you need it as a global :)!
118
119**HINT:** *If you are using lazy loading modules, you have to add `QuillModule` to your imports in your root module to make sure the `Config` services is registered.*
120
121### For SystemJS builds (Config)
122
123- add quill and ngx-quill to your `paths`:
124```
125paths: {
126 ...
127 'ngx-quill': 'node_modules/ngx-quill/bundles/ngx-quill.umd.js',
128 'quill': 'node_modules/quill/dist/quill.js'
129}
130```
131- set format and dependencies in `packages`:
132```
133packages: {
134 'ngx-quill': {
135 format: 'cjs',
136 meta: {
137 deps: ['quill']
138 }
139 },
140 'quill': {
141 format: 'cjs'
142 }
143}
144```
145- follow the steps of **For standard webpack and tsc builds**
146
147## Hint
148
149Ngx-quill updates the ngModel or formControl for every `user` change in the editor.
150Checkout the [QuillJS Source](https://quilljs.com/docs/api/#events) parameter of the `text-change` event.
151
152If you are using the editor reference to directly manipulate the editor content and want to update the model, pass `'user'` as the source parameter to the QuillJS api methods.
153
154## Config
155
156- ngModel - set initial value or allow two-way databinding
157- readOnly (true | false) if user can edit content
158- formats - array of allowed formats/groupings
159- format - model format - default: `html`, values: `html | object | text | json`, sets the model value type - html = html string, object = quill operation object, json = quill operation json, text = plain text
160- modules - configure/disable quill modules, e.g toolbar or add custom toolbar via html element default is
161```
162{
163 toolbar: [
164 ['bold', 'italic', 'underline', 'strike'], // toggled buttons
165 ['blockquote', 'code-block'],
166
167 [{ 'header': 1 }, { 'header': 2 }], // custom button values
168 [{ 'list': 'ordered'}, { 'list': 'bullet' }],
169 [{ 'script': 'sub'}, { 'script': 'super' }], // superscript/subscript
170 [{ 'indent': '-1'}, { 'indent': '+1' }], // outdent/indent
171 [{ 'direction': 'rtl' }], // text direction
172
173 [{ 'size': ['small', false, 'large', 'huge'] }], // custom dropdown
174 [{ 'header': [1, 2, 3, 4, 5, 6, false] }],
175
176 [{ 'color': [] }, { 'background': [] }], // dropdown with defaults from theme
177 [{ 'font': [] }],
178 [{ 'align': [] }],
179
180 ['clean'], // remove formatting button
181
182 ['link', 'image', 'video'] // link and image, video
183 ]
184};
185```
186- theme - bubble/snow, default is `snow`
187- sanitize - uses angulars DomSanitizer to santize html values - default: `true`, boolean (only for format="html")
188- style - set a style object, e.g. `[style]="{height: '250px'}"`
189- placeholder - placeholder text, default is `Insert text here ...`
190- bounds - boundary of the editor, default `document.body`, pass 'self' to attach the editor element
191- maxLength - add validation for maxlength - set model state to `invalid` and add `ng-invalid` class
192- minLength - add validation for minlength - set model state to `invalid` and add `ng-invalid` class, only set invalid if editor text not empty --> if you want to check if text is required --> use the required attribute
193- required - add validation as a required field - `[required]="true"` - default: false, boolean expected (no strings!)
194- strict - default: true, sets editor in strict mode
195- scrollingContainer - default '.ql-editor', allows to set scrolling container
196- use custom-options for adding for example custom font sizes --> this overwrites this options **globally** !!!
197- possbility to create a custom toolbar via projection slot `[quill-editor-toolbar]`:
198```
199<quill-editor>
200 <div quill-editor-toolbar>
201 <span class="ql-formats">
202 <button class="ql-bold" [title]="'Bold'"></button>
203 </span>
204 <span class="ql-formats">
205 <select class="ql-align" [title]="'Aligment'">
206 <option selected></option>
207 <option value="center"></option>
208 <option value="right"></option>
209 <option value="justify"></option>
210 </select>
211 <select class="ql-align" [title]="'Aligment2'">
212 <option selected></option>
213 <option value="center"></option>
214 <option value="right"></option>
215 <option value="justify"></option>
216 </select>
217 </span>
218 </div>
219</quill-editor>
220```
221- customToolbarPosition - if you are working with a custom toolbar you can switch the position :). - default: `top`, possible values `top`, `bottom`
222- debug - set log level `warn`, `error`, `log` or `false` to deactivate logging, default: `warn`
223- trackChanges - check if only `user` (quill source user) or `all` change should be trigger model update, default `user`. Using `all` is not recommended, it cause some unexpected sideeffects.
224
225[Full Quill Toolbar HTML](https://github.com/quilljs/quill/blob/f75ff2973f068c3db44f949915eb8a74faf162a8/docs/_includes/full-toolbar.html)
226
227## Global Config
228
229It is possible to set custom default modules and Quill config options with the import of the `QuillModule`.
230
231```
232@NgModule({
233 imports: [
234 ...,
235
236 QuillModule.forRoot({
237 modules: {
238 syntax: true,
239 toolbar: [...]
240 }
241 })
242 ],
243 ...
244})
245class YourModule { ... }
246
247```
248
249If you want to use the `syntax` module follow the [Syntax Highlight Module Guide](https://quilljs.com/docs/modules/syntax/#syntax-highlighter-module).
250
251See [Quill Configuration](https://quilljs.com/docs/configuration/) for a full list of config options.
252
253The `QuillModule` exports the `defaultModules` if you want to extend them :).
254
255## Outputs
256
257- onEditorCreated - editor instance
258```
259editor // Quill
260```
261- onContentChanged - text is updated
262```
263{
264 editor: editorInstance, // Quill
265 html: html, // html string
266 text: text, // plain text string
267 content: content, // Content - operatins representation
268 delta: delta, // Delta
269 oldDelta: oldDelta, // Delta
270 source: source // ('user', 'api', 'silent' , undefined)
271}
272```
273- onSelectionChanged - selection is updated
274```
275{
276 editor: editorInstance, // Quill
277 range: range, // Range
278 oldRange: oldRange, // Range
279 source: source // ('user', 'api', 'silent' , undefined)
280}
281```
282
283## Security Hint
284
285Angular templates provide some assurance against XSS in the form of client side sanitizing of all inputs https://angular.io/guide/security#xss.
286
287Ngx-quill provides the config paramter `sanitize` to sanitize html-strings passed as `ngModel` or `formControl` to the component.
288
289It is **deactivated per default** to avoid stripping content or styling, which is not expected.
290
291But it is **recommended** to activate this option, if you are working with html strings as model values.
292