UNPKG

arch-editor

Version:

Rich text editor with a high degree of customization.

2 lines 10.7 kB
/*! For license information please see index.js.LICENSE.txt */ !function(){"use strict";var e={619:function(e,t){t.Z={container:"ArchEditor-container","popover-button-group":"ArchEditor-popover-button-group",popoverButtonGroup:"ArchEditor-popover-button-group",large:"ArchEditor-large","popover-button":"ArchEditor-popover-button",popoverButton:"ArchEditor-popover-button","popover-divider":"ArchEditor-popover-divider",popoverDivider:"ArchEditor-popover-divider","edit-toolbar":"ArchEditor-edit-toolbar",editToolbar:"ArchEditor-edit-toolbar",danger:"ArchEditor-danger"}},131:function(e){e.exports=require("./AtomicFormula")},172:function(e){e.exports=require("./AtomicImage")},86:function(e){e.exports=require("./AtomicTable")},510:function(e){e.exports=require("./BlockToolbar")},296:function(e){e.exports=require("./ErrorBoundary")},89:function(e){e.exports=require("./Icon")},565:function(e){e.exports=require("./InlineToolbar")},94:function(e){e.exports=require("./Provider")},309:function(e){e.exports=require("./atomic")},6:function(e){e.exports=require("./default")},567:function(e){e.exports=require("./draftUtils")},634:function(e){e.exports=require("./iconfont")},466:function(e){e.exports=require("classnames/bind")},583:function(e){e.exports=require("draft-js")},23:function(e){e.exports=require("prop-types")},497:function(e){e.exports=require("react")}},t={};function r(n){var o=t[n];if(void 0!==o)return o.exports;var i=t[n]={exports:{}};return e[n](i,i.exports,r),i.exports}r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,{a:t}),t},r.d=function(e,t){for(var n in t)r.o(t,n)&&!r.o(e,n)&&Object.defineProperty(e,n,{enumerable:!0,get:t[n]})},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})};var n={};!function(){r.r(n),r.d(n,{ArchEditor:function(){return W},ArchEditorProvider:function(){return s.ArchEditorProvider},BlockToolbar:function(){return E.a},Icon:function(){return h.a}}),r(634);var e=r(23),t=r.n(e),o=r(497),i=r.n(o),a=r(583),u=r(466),c=r.n(u),l=r(567),d=r(6),s=r(94),f=r(309),p=r(89),h=r.n(p),y=r(565),b=r.n(y),v=r(296),m=r.n(v),g=r(510),E=r.n(g),O=r(86),S=r.n(O),P=r(172),C=r.n(P),x=r(131),T=r.n(x),w=r(619),A={};for(var R in a)["default","ArchEditor","ArchEditorProvider","BlockToolbar","Icon"].indexOf(R)<0&&(A[R]=function(e){return a[e]}.bind(0,R));for(var R in r.d(n,A),A={},d)["default","ArchEditor","ArchEditorProvider","BlockToolbar","Icon"].indexOf(R)<0&&(A[R]=function(e){return d[e]}.bind(0,R));for(var R in r.d(n,A),A={},l)["default","ArchEditor","ArchEditorProvider","BlockToolbar","Icon"].indexOf(R)<0&&(A[R]=function(e){return l[e]}.bind(0,R));for(var R in r.d(n,A),A={},f)["default","ArchEditor","ArchEditorProvider","BlockToolbar","Icon"].indexOf(R)<0&&(A[R]=function(e){return f[e]}.bind(0,R));function k(e){return(k="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})(e)}r.d(n,A);var _=["editorState","onChange","readOnly","blockRendererFn","className","showInlineToolbar","popoverClassName","inlineBars"];function j(){return(j=Object.assign||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}).apply(this,arguments)}function q(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 I(e){for(var t=1;t<arguments.length;t++){var r=null!=arguments[t]?arguments[t]:{};t%2?q(Object(r),!0).forEach((function(t){B(e,t,r[t])})):Object.getOwnPropertyDescriptors?Object.defineProperties(e,Object.getOwnPropertyDescriptors(r)):q(Object(r)).forEach((function(t){Object.defineProperty(e,t,Object.getOwnPropertyDescriptor(r,t))}))}return e}function B(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}function F(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function K(e,t){return(K=Object.setPrototypeOf||function(e,t){return e.__proto__=t,e})(e,t)}function D(e,t){if(t&&("object"===k(t)||"function"==typeof t))return t;if(void 0!==t)throw new TypeError("Derived constructors may only return object or undefined");return M(e)}function M(e){if(void 0===e)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return e}function N(e){return(N=Object.setPrototypeOf?Object.getPrototypeOf:function(e){return e.__proto__||Object.getPrototypeOf(e)})(e)}var U=c().bind(w.Z),L=(0,f.atomic)(T()),G=(0,f.atomic)(C()),Z=(0,f.atomic)(S()),W=function(e){!function(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}}),t&&K(e,t)}(f,e);var t,r,n,u,c,s=(u=f,c=function(){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}}(),function(){var e,t=N(u);if(c){var r=N(this).constructor;e=Reflect.construct(t,arguments,r)}else e=t.apply(this,arguments);return D(this,e)});function f(e){var t;return function(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}(this,f),(t=s.call(this,e)).state={editorState:d.defaultEditorState,innerEditorState:d.defaultEditorState,innerReadOnly:!1,showPopover:!1,activeEntityKey:""},t.editor=(0,o.createRef)(null),t.setActiveEntityKey=t._setActiveEntityKey.bind(M(t)),t.computedEditorState=t._computedEditorState.bind(M(t)),t.handleChange=t._handleChange.bind(M(t)),t.handleKeyCommand=t._handleKeyCommand.bind(M(t)),t.handleRequestClose=t._handleRequestClose.bind(M(t)),t.selectionListener=t._selectionListener.bind(M(t)),t.getEditorRaw=t._getEditorRaw.bind(M(t)),t.getPlainText=t._getPlainText.bind(M(t)),t.blockRendererFn=t._blockRendererFn.bind(M(t)),t.focus=function(){return t.editor.current.focus()},t.blur=function(){return t.editor.current.blur()},t.getInlineToolbarUpdate=function(e){t.updateInlineToolbar=e},t}return t=f,n=[{key:"getDerivedStateFromProps",value:function(e,t){var r=e.readOnly;return void 0!==r?I(I({},t),{},{innerReadOnly:r}):null}}],(r=[{key:"componentDidUpdate",value:function(e,t){this.selectionListener(),this.computedEditorState(t)}},{key:"componentWillUnmount",value:function(){this.timerMountIT&&clearTimeout(this.timerMountIT)}},{key:"_computedEditorState",value:function(e){var t,r=this.props.editorState,n=e.editorState,o=this.state.innerEditorState,i=this.context.contextEditorState;t=r||i||o;var a=n._immutable,u=t._immutable;a&&a.equals&&a.equals(u)||this.setState({editorState:t})}},{key:"_handleChange",value:function(e){var t=this.props,r=t.editorState,n=t.onChange,o=this.context.setContextEditorState;r&&n?n(e):o?o(e):this.setState({innerEditorState:e})}},{key:"_handleRequestClose",value:function(){this.state.showPopover&&this.setState({showPopover:!1})}},{key:"_setActiveEntityKey",value:function(e,t){var r=this.state.editorState;this.setState({activeEntityKey:e,innerReadOnly:Boolean(e)},t);var n=(0,l.forceReRender)(r);this.handleChange(n)}},{key:"_getEditorRaw",value:function(){var e=this.state.editorState.getCurrentContent();return(0,a.convertToRaw)(e)}},{key:"_getPlainText",value:function(e){var t=this.state.editorState;return(void 0===t?e:t).getCurrentContent().getPlainText()}},{key:"_selectionListener",value:function(){var e=this;if(this.props.showInlineToolbar){var t=this.state.editorState,r=t.getSelection(),n=r.isCollapsed(),o=r.getStartOffset(),i=r.getEndOffset(),a=this.prevPosS===o&&this.prevPosE===i;if(this.prevPosS=o,this.prevPosE=i,!a){var u=(0,l.validateSelection)(t);!n&&u&&(this.timerMountIT=setTimeout((function(){e.updateInlineToolbar&&e.updateInlineToolbar(),e.setState({showPopover:!0})}),150))}}}},{key:"_handleKeyCommand",value:function(e,t){var r=(0,d.getDefaultKeyCommandState)(e,t);return r?(this.handleChange(r),"handled"):"not-handled"}},{key:"_blockRendererFn",value:function(e){var t=this.state,r=t.editorState,n=t.innerReadOnly,o=t.activeEntityKey,i=this.props,a=i.atomicRendererFn,u=i.blockRendererFn,c=i.readOnly;if("atomic"===e.getType()){var l,d,s=e.getEntityAt(0);if(s){var p=r.getCurrentContent().getEntity(s);l=p.getType(),d=p.getData()}var h={data:d,readOnly:c,editorState:r,setEditorState:this.handleChange,entityKey:s,activeEntityKey:o,setActiveEntityKey:this.setActiveEntityKey};return"TABLE"===l?{component:Z,editable:!1,props:I(I({},h),{},{Editor:f})}:"FORMULA"===l?{component:L,editable:!1,props:h}:"IMAGE"===l?{component:G,editable:!n,props:h}:a?a(I(I({},h),{},{type:l})):null}return u?u(e):null}},{key:"render",value:function(){var e=this.props,t=(e.editorState,e.onChange,e.readOnly,e.blockRendererFn,e.className),r=e.showInlineToolbar,n=e.popoverClassName,o=e.inlineBars,u=function(e,t){if(null==e)return{};var r,n,o=function(e,t){if(null==e)return{};var r,n,o={},i=Object.keys(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||(o[r]=e[r]);return o}(e,t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(e);for(n=0;n<i.length;n++)r=i[n],t.indexOf(r)>=0||Object.prototype.propertyIsEnumerable.call(e,r)&&(o[r]=e[r])}return o}(e,_),c=this.state,l=c.innerReadOnly,s=c.editorState,f=c.showPopover;return i().createElement(m(),null,i().createElement("div",{className:U("container",B({},t,!!t))},r&&i().createElement(b(),{visible:f,bars:o,editorState:s,onChange:this.handleChange,popoverClassName:n,getUpdateFn:this.getInlineToolbarUpdate,onRequestClose:this.handleRequestClose}),i().createElement(a.Editor,j({ref:this.editor,readOnly:l,editorState:s,onChange:this.handleChange,customStyleMap:d.defaultCustomStyleMap,keyBindingFn:d.defaultKeyBindingFn,handleKeyCommand:this.handleKeyCommand,blockRendererFn:this.blockRendererFn},u))))}}])&&F(t.prototype,r),n&&F(t,n),f}(o.Component);W.contextType=s.ArchEditorContext,W.defaultProps={showInlineToolbar:!0},W.propTypes={editorState:t().any,onChange:t().func,onFocus:t().func,onBlur:t().func,readOnly:t().bool,blockRendererFn:t().func,className:t().string,popoverClassName:t().string,showInlineToolbar:t().bool,inlineBars:t().arrayOf(t().string),atomicRendererFn:t().func}}(),module.exports=n}();