ngx-quill
Version:
An angular (>= v2) component for the easy use of the QuillJS richt text editor.
2 lines • 8.57 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/platform-browser"),require("@angular/core"),require("@angular/forms")):"function"==typeof define&&define.amd?define("ngx-quill",["exports","@angular/common","@angular/platform-browser","@angular/core","@angular/forms"],e):e(t["ngx-quill"]={},t.ng.common,t.ng.platformBrowser,t.ng.core,t.ng.forms)}(this,function(t,h,e,c,i){"use strict";var p={toolbar:[["bold","italic","underline","strike"],["blockquote","code-block"],[{header:1},{header:2}],[{list:"ordered"},{list:"bullet"}],[{script:"sub"},{script:"super"}],[{indent:"-1"},{indent:"+1"}],[{direction:"rtl"}],[{size:["small",!1,"large","huge"]}],[{header:[1,2,3,4,5,6,!1]}],[{color:[]},{background:[]}],[{font:[]}],[{align:[]}],["clean"],["link","image","video"]]},n=new c.InjectionToken("config"),f=null,o=function(){function t(t,e,i,n,o,r,l){var s=this;this.elementRef=t,this.domSanitizer=e,this.doc=i,this.platformId=n,this.renderer=o,this.zone=r,this.config=l,this.format="html",this.required=!1,this.customToolbarPosition="top",this.sanitize=!1,this.style=null,this.strict=!0,this.customOptions=[],this.onEditorCreated=new c.EventEmitter,this.onContentChanged=new c.EventEmitter,this.onSelectionChanged=new c.EventEmitter,this.disabled=!1,this.valueGetter=function(t,e){var i=e.children[0].innerHTML;"<p><br></p>"!==i&&"<div><br><div>"!==i||(i=null);var n=i;if("text"===s.format)n=t.getText();else if("object"===s.format)n=t.getContents();else if("json"===s.format)try{n=JSON.stringify(t.getContents())}catch(o){n=t.getText()}return n},this.valueSetter=function(t,e){if("html"===s.format)return s.sanitize&&(e=s.domSanitizer.sanitize(c.SecurityContext.HTML,e)),t.clipboard.convert(e);if("json"===s.format)try{return JSON.parse(e)}catch(i){return[{insert:e}]}return e},this.selectionChangeHandler=function(t,e,i){s.zone.run(function(){s.onSelectionChanged.emit({editor:s.quillEditor,oldRange:e,range:t,source:i}),!t&&s.onModelTouched&&s.onModelTouched()})},this.textChangeHandler=function(e,i,n){var o=s.quillEditor.getText(),r=s.quillEditor.getContents(),l=s.editorElem.children[0].innerHTML;"<p><br></p>"!==l&&"<div><br><div>"!==l||(l=null),s.zone.run(function(){var t=s.trackChanges||s.config.trackChanges;(n===f.sources.USER||t&&"all"===t)&&s.onModelChange&&s.onModelChange(s.valueGetter(s.quillEditor,s.editorElem)),s.onContentChanged.emit({content:r,delta:e,editor:s.quillEditor,html:l,oldDelta:i,source:n,text:o})})}}return t.prototype.onModelChange=function(t){},t.prototype.onModelTouched=function(){},t.prototype.ngAfterViewInit=function(){var e=this;if(!h.isPlatformServer(this.platformId)){f||(f=require("quill")),"top"===this.customToolbarPosition?this.elementRef.nativeElement.insertAdjacentHTML("beforeend","<div quill-editor-element></div>"):this.elementRef.nativeElement.insertAdjacentHTML("afterbegin","<div quill-editor-element></div>"),this.editorElem=this.elementRef.nativeElement.querySelector("[quill-editor-element]");var t=this.elementRef.nativeElement.querySelector("[quill-editor-toolbar]"),i=this.modules||this.config.modules||p;i.toolbar===undefined&&(i.toolbar=p.toolbar);var n=this.placeholder!==undefined?this.placeholder:this.config.placeholder;n===undefined&&(n="Insert text here ..."),t&&(i.toolbar=t),this.style&&Object.keys(this.style).forEach(function(t){e.renderer.setStyle(e.editorElem,t,e.style[t])}),this.customOptions.forEach(function(t){var e=f["import"](t["import"]);e.whitelist=t.whitelist,f.register(e,!0)});var o=this.bounds&&"self"===this.bounds?this.editorElem:this.bounds;o||(o=this.config.bounds?this.config.bounds:this.doc.body);var r=this.debug;!r&&!1!==r&&this.config.debug&&(r=this.config.debug);var l=this.readOnly;l||!1===this.readOnly||(l=this.config.readOnly!==undefined&&this.config.readOnly);var s=this.scrollingContainer;s||null===this.scrollingContainer||(s=null===this.config.scrollingContainer||this.config.scrollingContainer?this.config.scrollingContainer:null);var a=this.formats;if(a||a!==undefined||(a=this.config.formats||null===this.config.formats?this.config.formats:undefined),this.quillEditor=new f(this.editorElem,{bounds:o,debug:r,formats:a,modules:i,placeholder:n,readOnly:l,scrollingContainer:s,strict:this.strict,theme:this.theme||(this.config.theme?this.config.theme:"snow")}),this.content){if("object"===this.format)this.quillEditor.setContents(this.content,"silent");else if("text"===this.format)this.quillEditor.setText(this.content,"silent");else if("json"===this.format)try{this.quillEditor.setContents(JSON.parse(this.content),"silent")}catch(d){this.quillEditor.setText(this.content,"silent")}else{this.sanitize&&(this.content=this.domSanitizer.sanitize(c.SecurityContext.HTML,this.content));var u=this.quillEditor.clipboard.convert(this.content);this.quillEditor.setContents(u,"silent")}this.quillEditor.history.clear()}this.setDisabledState(),this.onEditorCreated.emit(this.quillEditor),this.quillEditor.on("selection-change",this.selectionChangeHandler),this.quillEditor.on("text-change",this.textChangeHandler)}},t.prototype.ngOnDestroy=function(){this.quillEditor&&(this.quillEditor.off("selection-change",this.selectionChangeHandler),this.quillEditor.off("text-change",this.textChangeHandler))},t.prototype.ngOnChanges=function(t){var e=this;if(this.quillEditor&&(t.readOnly&&this.quillEditor.enable(!t.readOnly.currentValue),t.placeholder&&(this.quillEditor.root.dataset.placeholder=t.placeholder.currentValue),t.style)){var i=t.style.currentValue,n=t.style.previousValue;n&&Object.keys(n).forEach(function(t){e.renderer.removeStyle(e.editorElem,t)}),i&&Object.keys(i).forEach(function(t){e.renderer.setStyle(e.editorElem,t,e.style[t])})}},t.prototype.writeValue=function(t){if(this.content=t,this.quillEditor){if(t)return void("text"===this.format?this.quillEditor.setText(t):this.quillEditor.setContents(this.valueSetter(this.quillEditor,this.content)));this.quillEditor.setText("")}},t.prototype.setDisabledState=function(t){void 0===t&&(t=this.disabled),this.disabled=t,this.quillEditor&&(t?(this.quillEditor.disable(),this.renderer.setAttribute(this.elementRef.nativeElement,"disabled","disabled")):(this.readOnly||this.quillEditor.enable(),this.renderer.removeAttribute(this.elementRef.nativeElement,"disabled")))},t.prototype.registerOnChange=function(t){this.onModelChange=t},t.prototype.registerOnTouched=function(t){this.onModelTouched=t},t.prototype.validate=function(){if(!this.quillEditor)return null;var t={},e=!0,i=this.quillEditor.getText().trim().length;return this.minLength&&i&&i<this.minLength&&(e=!(t.minLengthError={given:i,minLength:this.minLength})),this.maxLength&&i>this.maxLength&&(e=!(t.maxLengthError={given:i,maxLength:this.maxLength})),this.required&&!i&&(e=!(t.requiredError={empty:!0})),e?null:t},t.decorators=[{type:c.Component,args:[{encapsulation:c.ViewEncapsulation.None,providers:[{multi:!0,provide:i.NG_VALUE_ACCESSOR,useExisting:c.forwardRef(function(){return t})},{multi:!0,provide:i.NG_VALIDATORS,useExisting:c.forwardRef(function(){return t})}],selector:"quill-editor",template:'\n <ng-content select="[quill-editor-toolbar]"></ng-content>\n'}]}],t.ctorParameters=function(){return[{type:c.ElementRef},{type:e.DomSanitizer},{type:undefined,decorators:[{type:c.Inject,args:[h.DOCUMENT]}]},{type:Object,decorators:[{type:c.Inject,args:[c.PLATFORM_ID]}]},{type:c.Renderer2},{type:c.NgZone},{type:undefined,decorators:[{type:c.Inject,args:[n]}]}]},t.propDecorators={format:[{type:c.Input}],theme:[{type:c.Input}],modules:[{type:c.Input}],debug:[{type:c.Input}],readOnly:[{type:c.Input}],placeholder:[{type:c.Input}],maxLength:[{type:c.Input}],minLength:[{type:c.Input}],required:[{type:c.Input}],formats:[{type:c.Input}],customToolbarPosition:[{type:c.Input}],sanitize:[{type:c.Input}],style:[{type:c.Input}],strict:[{type:c.Input}],scrollingContainer:[{type:c.Input}],bounds:[{type:c.Input}],customOptions:[{type:c.Input}],trackChanges:[{type:c.Input}],onEditorCreated:[{type:c.Output}],onContentChanged:[{type:c.Output}],onSelectionChanged:[{type:c.Output}],valueGetter:[{type:c.Input}],valueSetter:[{type:c.Input}]},t}(),r={modules:p},l=function(){function e(){}return e.forRoot=function(t){return{ngModule:e,providers:[{provide:n,useValue:t||{modules:p}}]}},e.decorators=[{type:c.NgModule,args:[{declarations:[o],exports:[o],imports:[],providers:[{provide:n,useValue:r}]}]}],e}();t.QuillModule=l,t.QuillEditorComponent=o,t.QUILL_CONFIG_TOKEN=n,t.ɵa=p,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-quill.umd.min.js.map