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.78 kB
JavaScript
"use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("react"),t=require("primereact/hooks"),r=require("primereact/utils");function n(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 l=n(e);function a(){return a=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},a.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 c(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 u(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?c(Object(r),!0).forEach((function(t){o(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):c(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}var s=function(){try{return Quill}catch(e){return null}}(),i=l.memo(l.forwardRef((function(e,o){var c=l.useRef(null),m=l.useRef(null),f=l.useRef(null),d=l.useRef(null),p=l.useRef(!1);t.useMountEffect((function(){if(!p.current){var t={modules:u({toolbar:!!e.showHeader&&f.current},e.modules),placeholder:e.placeholder,readOnly:e.readOnly,theme:e.theme,formats:e.formats};s?(d.current=new Quill(m.current,t),b(),d.current&&d.current.getModule("toolbar")&&e.onLoad&&e.onLoad(d.current)):Promise.resolve().then((function(){return n(require("quill"))})).then((function(e){e&&r.DomHandler.isExist(m.current)&&(d.current=e.default?new e.default(m.current,t):new e(m.current,t),b())})).then((function(){d.current&&d.current.getModule("toolbar")&&e.onLoad&&e.onLoad(d.current)})),p.current=!0}}));var b=function(){e.value&&d.current.setContents(d.current.clipboard.convert(e.value)),d.current.on("text-change",(function(t,n,l){var a=m.current.children[0],o=a?a.innerHTML:null,c=d.current.getText();if("<p><br></p>"===o&&(o=null),"api"===l){var u=m.current.children[0],s=document.createElement("div");if(s.innerHTML=e.value||"",r.DomHandler.isEqualElement(u,s))return}if(e.maxLength){var i=d.current.getLength();i>e.maxLength&&d.current.deleteText(e.maxLength,i)}e.onTextChange&&e.onTextChange({htmlValue:o,textValue:c,delta:t,source:l})})),d.current.on("selection-change",(function(t,r,n){e.onSelectionChange&&e.onSelectionChange({range:t,oldRange:r,source:n})}))};t.useUpdateEffect((function(){d.current&&!d.current.hasFocus()&&(e.value?d.current.setContents(d.current.clipboard.convert(e.value)):d.current.setText(""))}),[e.value]),l.useImperativeHandle(o,(function(){return{props:e,getQuill:function(){return d.current},getElement:function(){return c.current},getContent:function(){return m.current},getToolbar:function(){return f.current}}}));var v=r.ObjectUtils.findDiffKeys(e,i.defaultProps),E=r.classNames("p-component p-editor-container",e.className),h=!1===e.showHeader?null:e.headerTemplate?l.createElement("div",{ref:f,className:"p-editor-toolbar"},e.headerTemplate):l.createElement("div",{ref:f,className:"p-editor-toolbar"},l.createElement("span",{className:"ql-formats"},l.createElement("select",{className:"ql-header",defaultValue:"0"},l.createElement("option",{value:"1"},"Heading"),l.createElement("option",{value:"2"},"Subheading"),l.createElement("option",{value:"0"},"Normal")),l.createElement("select",{className:"ql-font"},l.createElement("option",null),l.createElement("option",{value:"serif"}),l.createElement("option",{value:"monospace"}))),l.createElement("span",{className:"ql-formats"},l.createElement("button",{type:"button",className:"ql-bold","aria-label":"Bold"}),l.createElement("button",{type:"button",className:"ql-italic","aria-label":"Italic"}),l.createElement("button",{type:"button",className:"ql-underline","aria-label":"Underline"})),l.createElement("span",{className:"ql-formats"},l.createElement("select",{className:"ql-color"}),l.createElement("select",{className:"ql-background"})),l.createElement("span",{className:"ql-formats"},l.createElement("button",{type:"button",className:"ql-list",value:"ordered","aria-label":"Ordered List"}),l.createElement("button",{type:"button",className:"ql-list",value:"bullet","aria-label":"Unordered List"}),l.createElement("select",{className:"ql-align"},l.createElement("option",{defaultValue:!0}),l.createElement("option",{value:"center"}),l.createElement("option",{value:"right"}),l.createElement("option",{value:"justify"}))),l.createElement("span",{className:"ql-formats"},l.createElement("button",{type:"button",className:"ql-link","aria-label":"Insert Link"}),l.createElement("button",{type:"button",className:"ql-image","aria-label":"Insert Image"}),l.createElement("button",{type:"button",className:"ql-code-block","aria-label":"Insert Code Block"})),l.createElement("span",{className:"ql-formats"},l.createElement("button",{type:"button",className:"ql-clean","aria-label":"Remove Styles"}))),g=l.createElement("div",{ref:m,className:"p-editor-content",style:e.style});return l.createElement("div",a({id:e.id,ref:c,className:E},v),h,g)})));i.displayName="Editor",i.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},exports.Editor=i;