UNPKG

@wangeditor-next/editor-for-react

Version:
3 lines (2 loc) 2.22 kB
import e,{useRef as t,useState as r,useEffect as n}from"react";import*as o from"@wangeditor-next/editor";import{createEditor as l}from"@wangeditor-next/editor";var a=function(){return a=Object.assign||function(e){for(var t,r=1,n=arguments.length;r<n;r++)for(var o in t=arguments[r])Object.prototype.hasOwnProperty.call(t,o)&&(e[o]=t[o]);return e},a.apply(this,arguments)};function i(e,t){var r="function"==typeof Symbol&&e[Symbol.iterator];if(!r)return e;var n,o,l=r.call(e),a=[];try{for(;(void 0===t||t-- >0)&&!(n=l.next()).done;)a.push(n.value)}catch(e){o={error:e}}finally{try{n&&!n.done&&(r=l.return)&&r.call(l)}finally{if(o)throw o.error}}return a}function u(o){var u=o.defaultContent,c=void 0===u?[]:u,d=o.onCreated,f=o.defaultHtml,v=void 0===f?"":f,s=o.value,m=void 0===s?"":s,y=o.onChange,g=o.defaultConfig,p=void 0===g?{}:g,h=o.mode,b=void 0===h?"default":h,C=o.style,_=void 0===C?{}:C,w=o.className,x=t(null),E=i(r(null),2),N=E[0],S=E[1],H=i(r(""),2),O=H[0],j=H[1],A=function(e){d&&d(e);var t=p.onCreated;t&&t(e)},D=function(e){var t=p.onDestroyed;S(null),t&&t(e)};return n((function(){null!=N&&(N.__react_on_change=function(e){j(e.getHtml()),y&&y(e);var t=p.onChange;t&&t(e)})}),[N,p]),n((function(){if(null!=N&&m!==O)try{N.setHtml(m)}catch(e){console.error(e)}}),[m]),n((function(){var e;if(null!=x.current&&null==N&&!(null===(e=x.current)||void 0===e?void 0:e.getAttribute("data-w-e-textarea"))){var t=l({selector:x.current,config:a(a({},p),{onCreated:A,onChange:function(e){var r;return null===(r=null==t?void 0:t.__react_on_change)||void 0===r?void 0:r.call(t,e)},onDestroyed:D}),content:c,html:v||m,mode:b});S(t)}}),[N]),e.createElement("div",{style:_,ref:x,className:w})}function c(r){var l=r.editor,a=r.defaultConfig,i=void 0===a?{}:a,u=r.mode,c=void 0===u?"default":u,d=r.style,f=void 0===d?{}:d,v=r.className,s=t(null);return n((function(){var e;null!=s.current&&null!=l&&((null===(e=s.current)||void 0===e?void 0:e.getAttribute("data-w-e-toolbar"))||o.createToolbar({editor:l,selector:s.current,config:i,mode:c}))}),[l]),e.createElement("div",{style:f,ref:s,className:v})}"function"==typeof SuppressedError&&SuppressedError;export{u as Editor,c as Toolbar}; //# sourceMappingURL=index.esm.js.map