UNPKG

primereact

Version:

PrimeReact is an open source UI library for React featuring a rich set of 90+ 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) 6.1 kB
import*as e from"react";import{useMountEffect as t,useUpdateEffect as r}from"primereact/hooks";import{ObjectUtils as n,DomHandler as l,classNames as a}from"primereact/utils";function o(){return o=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},o.apply(this,arguments)}function c(e){return c="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(e){return typeof e}:function(e){return e&&"function"==typeof Symbol&&e.constructor===Symbol&&e!==Symbol.prototype?"symbol":typeof e},c(e)}function u(e,t){if("object"!==c(e)||null===e)return e;var r=e[Symbol.toPrimitive];if(void 0!==r){var n=r.call(e,t||"default");if("object"!==c(n))return n;throw new TypeError("@@toPrimitive must return a primitive value.")}return("string"===t?String:Number)(e)}function i(e){var t=u(e,"string");return"symbol"===c(t)?t:String(t)}function s(e,t,r){return(t=i(t))in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}var 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,children:void 0},getProps:function(e){return n.getMergedProps(e,m.defaultProps)},getOtherProps:function(e){return n.getDiffProps(e,m.defaultProps)}};function p(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 f(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?p(Object(r),!0).forEach((function(t){s(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):p(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var d=function(){try{return Quill}catch(e){return null}}(),b=e.memo(e.forwardRef((function(n,c){var u=m.getProps(n),i=e.useRef(null),s=e.useRef(null),p=e.useRef(null),b=e.useRef(null),g=e.useRef(!1);t((function(){if(!g.current){var e={modules:f({toolbar:!!u.showHeader&&p.current},u.modules),placeholder:u.placeholder,readOnly:u.readOnly,theme:u.theme,formats:u.formats};d?(b.current=new Quill(s.current,e),v(),b.current&&b.current.getModule("toolbar")&&u.onLoad&&u.onLoad(b.current)):import("quill").then((function(t){t&&l.isExist(s.current)&&(b.current=t.default?new t.default(s.current,e):new t(s.current,e),v())})).then((function(){b.current&&b.current.getModule("toolbar")&&u.onLoad&&u.onLoad(b.current)})),g.current=!0}}));var v=function(){u.value&&b.current.setContents(b.current.clipboard.convert(u.value)),b.current.on("text-change",(function(e,t,r){var n=s.current.children[0],a=n?n.innerHTML:null,o=b.current.getText();if("<p><br></p>"===a&&(a=null),"api"===r){var c=s.current.children[0],i=document.createElement("div");if(i.innerHTML=u.value||"",l.isEqualElement(c,i))return}if(u.maxLength){var m=b.current.getLength();m>u.maxLength&&b.current.deleteText(u.maxLength,m)}u.onTextChange&&u.onTextChange({htmlValue:a,textValue:o,delta:e,source:r})})),b.current.on("selection-change",(function(e,t,r){u.onSelectionChange&&u.onSelectionChange({range:e,oldRange:t,source:r})}))};r((function(){b.current&&!b.current.hasFocus()&&(u.value?b.current.setContents(b.current.clipboard.convert(u.value)):b.current.setText(""))}),[u.value]),e.useImperativeHandle(c,(function(){return{props:u,getQuill:function(){return b.current},getElement:function(){return i.current},getContent:function(){return s.current},getToolbar:function(){return p.current}}}));var y=m.getOtherProps(u),h=a("p-component p-editor-container",u.className),E=!1===u.showHeader?null:u.headerTemplate?e.createElement("div",{ref:p,className:"p-editor-toolbar"},u.headerTemplate):e.createElement("div",{ref:p,className:"p-editor-toolbar"},e.createElement("span",{className:"ql-formats"},e.createElement("select",{className:"ql-header",defaultValue:"0"},e.createElement("option",{value:"1"},"Heading"),e.createElement("option",{value:"2"},"Subheading"),e.createElement("option",{value:"0"},"Normal")),e.createElement("select",{className:"ql-font"},e.createElement("option",null),e.createElement("option",{value:"serif"}),e.createElement("option",{value:"monospace"}))),e.createElement("span",{className:"ql-formats"},e.createElement("button",{type:"button",className:"ql-bold","aria-label":"Bold"}),e.createElement("button",{type:"button",className:"ql-italic","aria-label":"Italic"}),e.createElement("button",{type:"button",className:"ql-underline","aria-label":"Underline"})),e.createElement("span",{className:"ql-formats"},e.createElement("select",{className:"ql-color"}),e.createElement("select",{className:"ql-background"})),e.createElement("span",{className:"ql-formats"},e.createElement("button",{type:"button",className:"ql-list",value:"ordered","aria-label":"Ordered List"}),e.createElement("button",{type:"button",className:"ql-list",value:"bullet","aria-label":"Unordered List"}),e.createElement("select",{className:"ql-align"},e.createElement("option",{defaultValue:!0}),e.createElement("option",{value:"center"}),e.createElement("option",{value:"right"}),e.createElement("option",{value:"justify"}))),e.createElement("span",{className:"ql-formats"},e.createElement("button",{type:"button",className:"ql-link","aria-label":"Insert Link"}),e.createElement("button",{type:"button",className:"ql-image","aria-label":"Insert Image"}),e.createElement("button",{type:"button",className:"ql-code-block","aria-label":"Insert Code Block"})),e.createElement("span",{className:"ql-formats"},e.createElement("button",{type:"button",className:"ql-clean","aria-label":"Remove Styles"}))),N=e.createElement("div",{ref:s,className:"p-editor-content",style:u.style});return e.createElement("div",o({id:u.id,ref:i,className:h},y),E,N)})));b.displayName="Editor";export{b as Editor};