2 lines
6.4 KiB
JavaScript
2 lines
6.4 KiB
JavaScript
import e,{Component as t}from"react";import{DomHandler as n,classNames as r}from"primereact/utils";function l(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function o(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function a(e,t){return a=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e},a(e,t)}function c(e,t){if("function"!=typeof t&&null!==t)throw new TypeError("Super expression must either be null or a function");e.prototype=Object.create(t&&t.prototype,{constructor:{value:e,writable:!0,configurable:!0}}),Object.defineProperty(e,"prototype",{writable:!1}),t&&a(e,t)}function i(e){return i="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},i(e)}function s(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function u(e,t){if(t&&("object"===i(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return s(e)}function p(e){return p=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)},p(e)}function m(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}function f(e,t){var n=Object.keys(e);if(Object.getOwnPropertySymbols){var r=Object.getOwnPropertySymbols(e);t&&(r=r.filter((function(t){return Object.getOwnPropertyDescriptor(e,t).enumerable}))),n.push.apply(n,r)}return n}function b(e){for(var t=1;t<arguments.length;t++){var n=null!=arguments[t]?arguments[t]:{};t%2?f(Object(n),!0).forEach((function(t){m(e,t,n[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(n)):f(Object(n)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(n,t))}))}return e}function d(){if("undefined"==typeof Reflect||!Reflect.construct)return!1;if(Reflect.construct.sham)return!1;if("function"==typeof Proxy)return!0;try{return Boolean.prototype.valueOf.call(Reflect.construct(Boolean,[],(function(){}))),!0}catch(e){return!1}}var y=function(a){c(v,t);var i,s,m,f,y,h=(i=v,s=d(),function(){var e,t=p(i);if(s){var n=p(this).constructor;e=Reflect.construct(t,arguments,n)}else e=t.apply(this,arguments);return u(this,e)});function v(){return l(this,v),h.apply(this,arguments)}return m=v,(f=[{key:"getQuill",value:function(){return this.quill}},{key:"componentDidMount",value:function(){var e=this;import("quill").then((function(t){t&&t.default&&n.isExist(e.editorElement)&&(e.quill=new t.default(e.editorElement,{modules:b({toolbar:!!e.props.showHeader&&e.toolbarElement},e.props.modules),placeholder:e.props.placeholder,readOnly:e.props.readOnly,theme:e.props.theme,formats:e.props.formats}),e.props.value&&e.quill.setContents(e.quill.clipboard.convert(e.props.value)),e.quill.on("text-change",(function(t,n){var r=e.editorElement.children[0].innerHTML,l=e.quill.getText();"<p><br></p>"===r&&(r=null),e.props.onTextChange&&e.props.onTextChange({htmlValue:r,textValue:l,delta:t,source:n})})),e.quill.on("selection-change",(function(t,n,r){e.props.onSelectionChange&&e.props.onSelectionChange({range:t,oldRange:n,source:r})})))})).then((function(){e.quill&&e.quill.getModule("toolbar")&&e.props.onLoad&&e.props.onLoad(e.quill)}))}},{key:"componentDidUpdate",value:function(e){this.props.value!==e.value&&this.quill&&!this.quill.hasFocus()&&(this.props.value?this.quill.setContents(this.quill.clipboard.convert(this.props.value)):this.quill.setText(""))}},{key:"render",value:function(){var t=this,n=r("p-component p-editor-container",this.props.className),l=null;return!1===this.props.showHeader?(l="",this.toolbarElement=void 0):l=this.props.headerTemplate?e.createElement("div",{ref:function(e){return t.toolbarElement=e},className:"p-editor-toolbar"},this.props.headerTemplate):e.createElement("div",{ref:function(e){return t.toolbarElement=e},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"}))),e.createElement("div",{id:this.props.id,className:n},l,e.createElement("div",{ref:function(e){return t.editorElement=e},className:"p-editor-content",style:this.props.style}))}}])&&o(m.prototype,f),y&&o(m,y),Object.defineProperty(m,"prototype",{writable:!1}),v}();m(y,"defaultProps",{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});export{y as Editor};
|