primereact
Version:
PrimeReact is an open source UI library for React featuring a rich set of 80+ components, a theme designer, various theme alternatives such as Material, Bootstrap, Tailwind, premium templates and professional support. In addition, it integrates with Prime
2 lines (1 loc) • 5.77 kB
JavaScript
this.primereact=this.primereact||{},this.primereact.editor=function(e,t,r,n){"use strict";function l(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(r){if("default"!==r){var n=Object.getOwnPropertyDescriptor(e,r);Object.defineProperty(t,r,n.get?n:{enumerable:!0,get:function(){return e[r]}})}})),t.default=e,Object.freeze(t)}var a=l(t);function c(){return c=Object.assign?Object.assign.bind():function(e){for(var t=1;t<arguments.length;t++){var r=arguments[t];for(var n in r)Object.prototype.hasOwnProperty.call(r,n)&&(e[n]=r[n])}return e},c.apply(this,arguments)}function o(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function u(e,t){var r=Object.keys(e);if(Object.getOwnPropertySymbols){var n=Object.getOwnPropertySymbols(e);t&&(n=n.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),r.push.apply(r,n)}return r}function s(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?u(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):u(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var i=function(){try{return Quill}catch(e){return null}}(),m=a.memo(a.forwardRef((function(e,t){var l=a.useRef(null),o=a.useRef(null),u=a.useRef(null),d=a.useRef(null),f=a.useRef(!1);r.useMountEffect((function(){if(!f.current){var t={modules:s({toolbar:!!e.showHeader&&u.current},e.modules),placeholder:e.placeholder,readOnly:e.readOnly,theme:e.theme,formats:e.formats};i?(d.current=new Quill(o.current,t),p(),d.current&&d.current.getModule("toolbar")&&e.onLoad&&e.onLoad(d.current)):import("quill").then((function(e){e&&n.DomHandler.isExist(o.current)&&(d.current=e.default?new e.default(o.current,t):new e(o.current,t),p())})).then((function(){d.current&&d.current.getModule("toolbar")&&e.onLoad&&e.onLoad(d.current)})),f.current=!0}}));var p=function(){e.value&&d.current.setContents(d.current.clipboard.convert(e.value)),d.current.on("text-change",(function(t,r,l){var a=o.current.children[0],c=a?a.innerHTML:null,u=d.current.getText();if("<p><br></p>"===c&&(c=null),"api"===l){var s=o.current.children[0],i=document.createElement("div");if(i.innerHTML=e.value||"",n.DomHandler.isEqualElement(s,i))return}if(e.maxLength){var m=d.current.getLength();m>e.maxLength&&d.current.deleteText(e.maxLength,m)}e.onTextChange&&e.onTextChange({htmlValue:c,textValue:u,delta:t,source:l})})),d.current.on("selection-change",(function(t,r,n){e.onSelectionChange&&e.onSelectionChange({range:t,oldRange:r,source:n})}))};r.useUpdateEffect((function(){d.current&&!d.current.hasFocus()&&(e.value?d.current.setContents(d.current.clipboard.convert(e.value)):d.current.setText(""))}),[e.value]),a.useImperativeHandle(t,(function(){return{props:e,getQuill:function(){return d.current},getElement:function(){return l.current},getContent:function(){return o.current},getToolbar:function(){return u.current}}}));var b=n.ObjectUtils.findDiffKeys(e,m.defaultProps),E=n.classNames("p-component p-editor-container",e.className),h=!1===e.showHeader?null:e.headerTemplate?a.createElement("div",{ref:u,className:"p-editor-toolbar"},e.headerTemplate):a.createElement("div",{ref:u,className:"p-editor-toolbar"},a.createElement("span",{className:"ql-formats"},a.createElement("select",{className:"ql-header",defaultValue:"0"},a.createElement("option",{value:"1"},"Heading"),a.createElement("option",{value:"2"},"Subheading"),a.createElement("option",{value:"0"},"Normal")),a.createElement("select",{className:"ql-font"},a.createElement("option",null),a.createElement("option",{value:"serif"}),a.createElement("option",{value:"monospace"}))),a.createElement("span",{className:"ql-formats"},a.createElement("button",{type:"button",className:"ql-bold","aria-label":"Bold"}),a.createElement("button",{type:"button",className:"ql-italic","aria-label":"Italic"}),a.createElement("button",{type:"button",className:"ql-underline","aria-label":"Underline"})),a.createElement("span",{className:"ql-formats"},a.createElement("select",{className:"ql-color"}),a.createElement("select",{className:"ql-background"})),a.createElement("span",{className:"ql-formats"},a.createElement("button",{type:"button",className:"ql-list",value:"ordered","aria-label":"Ordered List"}),a.createElement("button",{type:"button",className:"ql-list",value:"bullet","aria-label":"Unordered List"}),a.createElement("select",{className:"ql-align"},a.createElement("option",{defaultValue:!0}),a.createElement("option",{value:"center"}),a.createElement("option",{value:"right"}),a.createElement("option",{value:"justify"}))),a.createElement("span",{className:"ql-formats"},a.createElement("button",{type:"button",className:"ql-link","aria-label":"Insert Link"}),a.createElement("button",{type:"button",className:"ql-image","aria-label":"Insert Image"}),a.createElement("button",{type:"button",className:"ql-code-block","aria-label":"Insert Code Block"})),a.createElement("span",{className:"ql-formats"},a.createElement("button",{type:"button",className:"ql-clean","aria-label":"Remove Styles"}))),v=a.createElement("div",{ref:o,className:"p-editor-content",style:e.style});return a.createElement("div",c({id:e.id,ref:l,className:E},b),h,v)})));return m.displayName="Editor",m.defaultProps={__TYPE:"Editor",id:null,value:null,style:null,className:null,placeholder:null,readOnly:!1,modules:null,formats:null,theme:"snow",showHeader:!0,headerTemplate:null,onTextChange:null,onSelectionChange:null,onLoad:null,maxLength:null},e.Editor=m,Object.defineProperty(e,"__esModule",{value:!0}),e}({},React,primereact.hooks,primereact.utils);