ngx-quill
Version:
An angular (>= v2) component for the easy use of the QuillJS richt text editor.
2 lines • 14.7 kB
JavaScript
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("@angular/common"),require("@angular/core"),require("@angular/platform-browser"),require("@angular/forms")):"function"==typeof define&&define.amd?define("ngx-quill",["exports","@angular/common","@angular/core","@angular/platform-browser","@angular/forms"],e):e((t=t||self)["ngx-quill"]={},t.ng.common,t.ng.core,t.ng.platformBrowser,t.ng.forms)}(this,function(t,e,i,n,o){"use strict";function r(t,e,i,n){var o,r=arguments.length,s=r<3?e:null===n?n=Object.getOwnPropertyDescriptor(e,i):n;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)s=Reflect.decorate(t,e,i,n);else for(var l=t.length-1;l>=0;l--)(o=t[l])&&(s=(r<3?o(s):r>3?o(e,i,s):o(e,i))||s);return r>3&&s&&Object.defineProperty(e,i,s),s}function s(t,e){return function(i,n){e(i,n,t)}}function l(t,e){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(t,e)}var d={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"]]},u=new i.InjectionToken("config"),a=null,h=function(t,e){return t||e||"html"},c=h,p=function(){function t(t,e,n,o,r,s,l){var d=this;this.elementRef=t,this.domSanitizer=e,this.doc=n,this.platformId=o,this.renderer=r,this.zone=s,this.config=l,this.required=!1,this.customToolbarPosition="top",this.sanitize=!1,this.styles=null,this.strict=!0,this.customOptions=[],this.preserveWhitespace=!1,this.onEditorCreated=new i.EventEmitter,this.onEditorChanged=new i.EventEmitter,this.onContentChanged=new i.EventEmitter,this.onSelectionChanged=new i.EventEmitter,this.onFocus=new i.EventEmitter,this.onBlur=new i.EventEmitter,this.disabled=!1,this.valueGetter=function(t,e){var i=e.querySelector(".ql-editor").innerHTML;"<p><br></p>"!==i&&"<div><br><div>"!==i||(i=null);var n=i,o=h(d.format,d.config.format);if("text"===o)n=t.getText();else if("object"===o)n=t.getContents();else if("json"===o)try{n=JSON.stringify(t.getContents())}catch(r){n=t.getText()}return n},this.valueSetter=function(t,e){var n=h(d.format,d.config.format);if("html"===n)return d.sanitize&&(e=d.domSanitizer.sanitize(i.SecurityContext.HTML,e)),t.clipboard.convert(e);if("json"===n)try{return JSON.parse(e)}catch(o){return[{insert:e}]}return e},this.selectionChangeHandler=function(t,e,i){d.zone.run(function(){null===t?d.onBlur.emit({editor:d.quillEditor,source:i}):null===e&&d.onFocus.emit({editor:d.quillEditor,source:i}),d.onSelectionChanged.emit({editor:d.quillEditor,oldRange:e,range:t,source:i}),!t&&d.onModelTouched&&d.onModelTouched()})},this.textChangeHandler=function(t,e,i){var n=d.quillEditor.getText(),o=d.quillEditor.getContents(),r=d.editorElem.querySelector(".ql-editor").innerHTML;"<p><br></p>"!==r&&"<div><br><div>"!==r||(r=null),d.zone.run(function(){var s=d.trackChanges||d.config.trackChanges;(i===a.sources.USER||s&&"all"===s)&&d.onModelChange&&d.onModelChange(d.valueGetter(d.quillEditor,d.editorElem)),d.onContentChanged.emit({content:o,delta:t,editor:d.quillEditor,html:r,oldDelta:e,source:i,text:n})})},this.editorChangeHandler=function(t,e,i,n){if("text-change"===t){var o=d.quillEditor.getText(),r=d.quillEditor.getContents(),s=d.editorElem.querySelector(".ql-editor").innerHTML;"<p><br></p>"!==s&&"<div><br><div>"!==s||(s=null),d.zone.run(function(){d.onEditorChanged.emit({content:r,delta:e,editor:d.quillEditor,event:t,html:s,oldDelta:i,source:n,text:o})})}else d.onEditorChanged.emit({editor:d.quillEditor,event:t,oldRange:i,range:e,source:n})}}var c;return c=t,t.prototype.onModelChange=function(t){},t.prototype.onModelTouched=function(){},t.prototype.ngAfterViewInit=function(){var t=this;if(!e.isPlatformServer(this.platformId)){a||(a=require("quill")),this.elementRef.nativeElement.insertAdjacentHTML("top"===this.customToolbarPosition?"beforeend":"afterbegin",this.preserveWhitespace?"<pre quill-editor-element></pre>":"<div quill-editor-element></div>"),this.editorElem=this.elementRef.nativeElement.querySelector("[quill-editor-element]");var n=this.elementRef.nativeElement.querySelector("[quill-editor-toolbar]"),o=Object.assign({},this.modules||this.config.modules||d);n?o.toolbar=n:o.toolbar===undefined&&(o.toolbar=d.toolbar);var r=this.placeholder!==undefined?this.placeholder:this.config.placeholder;r===undefined&&(r="Insert text here ..."),this.styles&&Object.keys(this.styles).forEach(function(e){t.renderer.setStyle(t.editorElem,e,t.styles[e])}),this.customOptions.forEach(function(t){var e=a["import"](t["import"]);e.whitelist=t.whitelist,a.register(e,!0)});var s=this.bounds&&"self"===this.bounds?this.editorElem:this.bounds;s||(s=this.config.bounds?this.config.bounds:this.doc.body);var l=this.debug;!l&&!1!==l&&this.config.debug&&(l=this.config.debug);var u=this.readOnly;u||!1===this.readOnly||(u=this.config.readOnly!==undefined&&this.config.readOnly);var c=this.scrollingContainer;c||null===this.scrollingContainer||(c=null===this.config.scrollingContainer||this.config.scrollingContainer?this.config.scrollingContainer:null);var p=this.formats;if(p||p!==undefined||(p=this.config.formats?Object.assign({},this.config.formats):null===this.config.formats?null:undefined),this.quillEditor=new a(this.editorElem,{bounds:s,debug:l,formats:p,modules:o,placeholder:r,readOnly:u,scrollingContainer:c,strict:this.strict,theme:this.theme||(this.config.theme?this.config.theme:"snow")}),this.content){var g=h(this.format,this.config.format);if("object"===g)this.quillEditor.setContents(this.content,"silent");else if("text"===g)this.quillEditor.setText(this.content,"silent");else if("json"===g)try{this.quillEditor.setContents(JSON.parse(this.content),"silent")}catch(m){this.quillEditor.setText(this.content,"silent")}else{this.sanitize&&(this.content=this.domSanitizer.sanitize(i.SecurityContext.HTML,this.content));var f=this.quillEditor.clipboard.convert(this.content);this.quillEditor.setContents(f,"silent")}this.quillEditor.history.clear()}this.setDisabledState(),this.quillEditor.on("editor-change",this.editorChangeHandler),this.quillEditor.on("selection-change",this.selectionChangeHandler),this.quillEditor.on("text-change",this.textChangeHandler),setTimeout(function(){return t.onEditorCreated.emit(t.quillEditor)})}},t.prototype.ngOnDestroy=function(){this.quillEditor&&(this.quillEditor.off("selection-change",this.selectionChangeHandler),this.quillEditor.off("text-change",this.textChangeHandler),this.quillEditor.off("editor-change",this.editorChangeHandler))},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.styles)){var i=t.styles.currentValue,n=t.styles.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.styles[t])})}},t.prototype.writeValue=function(t){this.content=t;var e=h(this.format,this.config.format);if(this.quillEditor){if(t)return void("text"===e?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&&(t.minLengthError={given:i,minLength:this.minLength},e=!1),this.maxLength&&i>this.maxLength&&(t.maxLengthError={given:i,maxLength:this.maxLength},e=!1),this.required&&!i&&(t.requiredError={empty:!0},e=!1),e?null:t},r([i.Input(),l("design:type",String)],t.prototype,"format",void 0),r([i.Input(),l("design:type",String)],t.prototype,"theme",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"modules",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"debug",void 0),r([i.Input(),l("design:type",Boolean)],t.prototype,"readOnly",void 0),r([i.Input(),l("design:type",String)],t.prototype,"placeholder",void 0),r([i.Input(),l("design:type",Number)],t.prototype,"maxLength",void 0),r([i.Input(),l("design:type",Number)],t.prototype,"minLength",void 0),r([i.Input(),l("design:type",Boolean)],t.prototype,"required",void 0),r([i.Input(),l("design:type",Array)],t.prototype,"formats",void 0),r([i.Input(),l("design:type",String)],t.prototype,"customToolbarPosition",void 0),r([i.Input(),l("design:type",Boolean)],t.prototype,"sanitize",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"styles",void 0),r([i.Input(),l("design:type",Boolean)],t.prototype,"strict",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"scrollingContainer",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"bounds",void 0),r([i.Input(),l("design:type",Array)],t.prototype,"customOptions",void 0),r([i.Input(),l("design:type",String)],t.prototype,"trackChanges",void 0),r([i.Input(),l("design:type",Boolean)],t.prototype,"preserveWhitespace",void 0),r([i.Output(),l("design:type",i.EventEmitter)],t.prototype,"onEditorCreated",void 0),r([i.Output(),l("design:type",i.EventEmitter)],t.prototype,"onEditorChanged",void 0),r([i.Output(),l("design:type",i.EventEmitter)],t.prototype,"onContentChanged",void 0),r([i.Output(),l("design:type",i.EventEmitter)],t.prototype,"onSelectionChanged",void 0),r([i.Output(),l("design:type",i.EventEmitter)],t.prototype,"onFocus",void 0),r([i.Output(),l("design:type",i.EventEmitter)],t.prototype,"onBlur",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"valueGetter",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"valueSetter",void 0),t=c=r([i.Component({encapsulation:i.ViewEncapsulation.None,providers:[{multi:!0,provide:o.NG_VALUE_ACCESSOR,useExisting:i.forwardRef(function(){return c})},{multi:!0,provide:o.NG_VALIDATORS,useExisting:i.forwardRef(function(){return c})}],selector:"quill-editor",template:'\n <ng-content select="[quill-editor-toolbar]"></ng-content>\n'}),s(2,i.Inject(e.DOCUMENT)),s(3,i.Inject(i.PLATFORM_ID)),s(6,i.Inject(u)),l("design:paramtypes",[i.ElementRef,n.DomSanitizer,Object,Object,i.Renderer2,i.NgZone,Object])],t)}(),g=function(){function t(t,e){this.sanitizer=t,this.config=e,this.innerHTML="",this.themeClass="ql-snow",this.content=""}return t.prototype.ngOnChanges=function(t){if(t.theme){var e=t.theme.currentValue||(this.config.theme?this.config.theme:"snow");this.themeClass="ql-"+e+" ngx-quill-view-html"}else if(!this.theme){e=this.config.theme?this.config.theme:"snow";this.themeClass="ql-"+e+" ngx-quill-view-html"}t.content&&(this.innerHTML=this.sanitizer.bypassSecurityTrustHtml(t.content.currentValue))},r([i.Input(),l("design:type",String)],t.prototype,"content",void 0),r([i.Input(),l("design:type",String)],t.prototype,"theme",void 0),t=r([i.Component({encapsulation:i.ViewEncapsulation.None,selector:"quill-view-html",template:'\n <div class="ql-container" [ngClass]="themeClass">\n <div class="ql-editor" [innerHTML]="innerHTML">\n </div>\n </div>\n',styles:["\n.ql-container.ngx-quill-view-html {\n border: 0;\n}\n"]}),s(1,i.Inject(u)),l("design:paramtypes",[n.DomSanitizer,Object])],t)}(),f=null,m=function(t,e){return t||e||"html"},v=function(){function t(t,e,i,n){var o=this;this.platformId=t,this.config=e,this.renderer=i,this.elementRef=n,this.strict=!0,this.customOptions=[],this.preserveWhitespace=!1,this.valueSetter=function(t,e){var i=m(o.format,o.config.format),n=e;if("html"===i||"text"===i)n=t.clipboard.convert(e);else if("json"===i)try{n=JSON.parse(e)}catch(r){n=[{insert:e}]}t.setContents(n)}}return t.prototype.ngOnChanges=function(t){this.quillEditor&&t.content&&this.valueSetter(this.quillEditor,t.content.currentValue)},t.prototype.ngAfterViewInit=function(){if(!e.isPlatformServer(this.platformId)){f||(f=require("quill"));var t=Object.assign({},this.modules||this.config.modules||d);t.toolbar=!1,this.customOptions.forEach(function(t){var e=f["import"](t["import"]);e.whitelist=t.whitelist,f.register(e,!0)});var i=this.debug;!i&&!1!==i&&this.config.debug&&(i=this.config.debug);var n=this.formats;n||n!==undefined||(n=this.config.formats?Object.assign({},this.config.formats):null===this.config.formats?null:undefined);var o=this.theme||(this.config.theme?this.config.theme:"snow");this.elementRef.nativeElement.insertAdjacentHTML("afterbegin",this.preserveWhitespace?"<pre quill-view-element></pre>":"<div quill-view-element></div>"),this.editorElem=this.elementRef.nativeElement.querySelector("[quill-view-element]"),this.quillEditor=new f(this.editorElem,{debug:i,formats:n,modules:t,readOnly:!0,strict:this.strict,theme:o}),this.renderer.addClass(this.editorElem,"ngx-quill-view"),this.content&&this.valueSetter(this.quillEditor,this.content)}},r([i.Input(),l("design:type",String)],t.prototype,"format",void 0),r([i.Input(),l("design:type",String)],t.prototype,"theme",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"modules",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"debug",void 0),r([i.Input(),l("design:type",Array)],t.prototype,"formats",void 0),r([i.Input(),l("design:type",Boolean)],t.prototype,"strict",void 0),r([i.Input(),l("design:type",Object)],t.prototype,"content",void 0),r([i.Input(),l("design:type",Array)],t.prototype,"customOptions",void 0),r([i.Input(),l("design:type",Boolean)],t.prototype,"preserveWhitespace",void 0),t=r([i.Component({encapsulation:i.ViewEncapsulation.None,selector:"quill-view",template:"\n",styles:["\n.ql-container.ngx-quill-view {\n border: 0;\n}\n"]}),s(0,i.Inject(i.PLATFORM_ID)),s(1,i.Inject(u)),l("design:paramtypes",[Object,Object,i.Renderer2,i.ElementRef])],t)}(),y=function(){function t(){}var n;return n=t,t.forRoot=function(t){return{ngModule:n,providers:[{provide:u,useValue:t||{modules:d}}]}},t=n=r([i.NgModule({declarations:[p,v,g],exports:[p,v,g],imports:[e.CommonModule],providers:[]})],t)}();t.QUILL_CONFIG_TOKEN=u,t.QuillEditorComponent=p,t.QuillModule=y,t.QuillViewComponent=v,t.QuillViewHTMLComponent=g,t.defaultModules=d,t.ɵ0=c,Object.defineProperty(t,"__esModule",{value:!0})});
//# sourceMappingURL=ngx-quill.umd.min.js.map