raonkeditor-react
Version:
React component for RAON K Editor
5 lines (4 loc) • 13.5 kB
JavaScript
/**
* @license Copyright (c) 2003-2022, RAONWIZ DevTeam. All rights reserved.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports,require("react")):"function"==typeof define&&define.amd?define(["exports","react"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self).RAONKEditorReact={},e.React)}(this,(function(e,t){"use strict";function n(e){if(e&&e.__esModule)return e;var t=Object.create(null);return e&&Object.keys(e).forEach((function(n){if("default"!==n){var o=Object.getOwnPropertyDescriptor(e,n);Object.defineProperty(t,n,o.get?o:{enumerable:!0,get:function(){return e[n]}})}})),t.default=e,Object.freeze(t)}var o=n(t),r=function(){return r=Object.assign||function(e){for(var t,n=1,o=arguments.length;n<o;n++)for(var r in t=arguments[n])Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r]);return e},r.apply(this,arguments)};function a(e,t,n){if(n||2===arguments.length)for(var o,r=0,a=t.length;r<a;r++)!o&&r in t||(o||(o=Array.prototype.slice.call(t,0,r)),o[r]=t[r]);return e.concat(o||Array.prototype.slice.call(t))}"function"==typeof SuppressedError&&SuppressedError;var c=["loaded","creationComplete","destroy","afterChangeMode","onError","onLanguageDefinition","afterPopupShow","agentInstall","beforeInsertUrl","mouse","command","key","resized","documentEditComplete","pasteImage","wordCount","beforePaste","customAction","fullScreen","setComplete","setInsertComplete","closeInstallPopup","setForbiddenWordComplete","drag","focus","dialogLoaded","beforeInsertHyperlink"],i=["beforeLoad","namespaceLoaded"],d=a(a([],c,!0),i,!0),s="__RKE__";function u(e){return"".concat(s).concat(e)}function l(e){return e.substr(s.length)}function p(e){var t=e.substr(0,1).toUpperCase()+e.substr(1);return"on".concat(t)}function f(e){return e.substr(2,1).toLowerCase()+e.substr(3)}var O=a(a([],c,!0),i,!0).reduce((function(e,t){var n;return r(r({},e),((n={})[t]=u(t),n))}),{});function E(e){var t=e.debug,n=e.component,o=e.evtName,r=e.handler,a=t&&Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5),c=r;return t&&(c=function(e){return console.log({logType:"RAONWIZ Log - invoke",operation:"invoke",component:n,componentName:n.object.ID,evtName:o,handlerId:a,eventInfo:e.eventInfo}),r(e)}),t&&console.log({logType:"RAONWIZ Log - register",operation:"register",component:n,componentName:n.object.ID,evtName:o,handlerId:a}),RAONKEDITOR._ExternalAttachEvents(n.object,o,c),function(){t&&console.log({logType:"RAONWIZ Log - unregister",operation:"unregister",component:n,componentName:n.object.ID,evtName:o,handlerId:a})}}var m,v={};function y(e,t){e.onload=function(){this.onerror=this.onload=null,t(null,e)},e.onerror=function(){this.onerror=this.onload=null,t(new Error("Failed to load "+this.src),e)}}function R(e,t){e.onreadystatechange=function(){"complete"!=this.readyState&&"loaded"!=this.readyState||(this.onreadystatechange=null,t(null,e))}}function I(e,t,n){if("string"!=typeof e||e.length<1)return Promise.reject(new TypeError("Component TYPE must be a non-empty string."));if(e in window){var o=null;switch(e){case"RAONKUPLOAD":o=RAONKUPLOAD;break;case"RAONKEDITOR":o=RAONKEDITOR;break;case"DEXT5UPLOAD":o=DEXT5UPLOAD;break;case"DEXT5":o=DEXT5}return Promise.resolve(o)}return"string"!=typeof t||t.length<1?Promise.reject(new TypeError("Component URL must be a non-empty string.")):(m||(m=I.scriptLoader(e,t).then((function(e){return n&&n(e),e}))),m)}Object.defineProperty(v,"__esModule",{value:!0}),I.scriptLoader=function(e,t){return new Promise((function(n,o){var r,a,c,i,d;r=t,a=function(t){m=void 0;var r=null;switch(e){case"RAONKUPLOAD":r=window.RAONKUPLOAD;break;case"RAONKEDITOR":r=window.RAONKEDITOR;break;case"DEXT5UPLOAD":r=window.DEXT5UPLOAD;break;case"DEXT5":r=window.DEXT5}return t?o(t):r?void n(r):o(new Error("Script loaded from componentUrl doesn't provide Component namespace."))},i=document.head||document.getElementsByTagName("head")[0],d=document.createElement("script"),"function"==typeof a&&(c=a,a={}),a=a||{},c=c||function(){},d.type=a.type||"text/javascript",d.charset=a.charset||"utf8",d.async=!("async"in a)||!!a.async,d.src=r,a.attrs&&function(e,t){for(var n in t)e.setAttribute(n,t[n])}(d,a.attrs),a.text&&(d.text=String(a.text)),("onload"in d?y:R)(d,c),d.onload||y(d,c),i.appendChild(d)}))},v.debounce=function(e,t){var n,o=arguments.length>2&&void 0!==arguments[2]?arguments[2]:{};return function(){clearTimeout(n);for(var r=arguments.length,a=new Array(r),c=0;c<r;c++)a[c]=arguments[c];n=setTimeout(e.bind.apply(e,[o].concat(a)),t)}};var D=v.getRaonwizComponentNamespace=I,g=o.useEffect,b=o.useReducer,T=o.useRef,h="RAONKEDITOR",N="/raonkeditor/js/raonkeditor.js",_={};function A(e){var t=e.debug,n=e.element,o=e.config,r=e.componentUrl,a=e.runtimes,c=void 0===a?"html5":a,u=e.dispatchEvent,l=e.subscribeTo,p=void 0===l?d:l,f=T(r||N),m=T(null!=p?p:d),v=T(t),y=T(u),R=T(o||_),I=T(c),A=b(x,{component:void 0,hookStatus:"init"}),K=A[0],j=K.component,C=K.hookStatus,M=A[1];return g((function(){if(n&&!j){M({type:"loading"});D(h,f.current,(function(e){var t;-1!==m.current.indexOf("namespaceLoaded")&&(null===(t=y.current)||void 0===t||t.call(y,{type:O.namespaceLoaded,payload:e}))})).then((function(e){var o,r="view"===R.current.Mode,a=R.current.ReadOnly;-1!==m.current.indexOf("beforeLoad")&&(null===(o=y.current)||void 0===o||o.call(y,{type:O.beforeLoad,payload:e})),void 0===e._ExternalMakeComponent&&function(e){e._ExternalMakeComponent=function(t,n){void 0===RAONKEDITOR._ExternalLoadedEventMap&&(RAONKEDITOR._ExternalLoadedEventMap=new Map),void 0===RAONKEDITOR._ExternalCreationCompleteEventMap&&(RAONKEDITOR._ExternalCreationCompleteEventMap=new Map),void 0===RAONKEDITOR._ExternalDestroyEventMap&&(RAONKEDITOR._ExternalDestroyEventMap=new Map),RAONKEDITOR._ExternalLoadedEventMap.set(t.id,[]),RAONKEDITOR._ExternalCreationCompleteEventMap.set(t.id,[]),RAONKEDITOR._ExternalDestroyEventMap.set(t.id,[]),e._ExternalDestroy=!0;var o={Id:t.id,EditorHolder:t.id};return o=e.util.objectExtend(!0,n,o),{object:new RAONKEditor(o),status:"ready"}}}(e),void 0===e._ExternalSetDestroyEvent&&function(e){e._ExternalSetDestroyEvent=function(e){var t,n;"function"==typeof MutationObserver?(t=(n=document.getElementById("raonk_frame_holder"+e))||document.getElementById("raonk_frame_"+e))&&new MutationObserver((function(){var t=RAONKEDITOR._ExternalDestroyEventMap.get(e),n=RAONKEDITOR.GetEditorByName(e);if(void 0!==t&&t.length>0)for(var o=0,r=t.length;o<r;o++)try{t[o]({eventInfo:{componentName:e,paramObj:void 0}})}catch(e){}else if(n&&void 0!==n._config&&"function"==typeof n._config.event.destroy)try{n._config.event.destroy({eventInfo:{componentName:e,paramObj:void 0}})}catch(e){}else if("function"==typeof KEDITORTOP.KEDITORWIN.RAONKEDITOR_Destroy)try{KEDITORTOP.KEDITORWIN.RAONKEDITOR_Destroy({eventInfo:{componentName:e,paramObj:void 0}})}catch(e){}})).observe(t,{childList:!0}):((n=document.getElementById("raonk_frame_"+e))&&(t=n),t&&t.addEventListener("DOMNodeRemoved",(function(t){var n=RAONKEDITOR._ExternalDestroyEventMap.get(e);if(void 0!==n&&n.length>0)for(var o=0,r=n.length;o<r;o++)try{n[o]({eventInfo:{componentName:e,paramObj:void 0}})}catch(t){}else if(KEDITORTOP.G_CURRKEDITOR&&void 0!==KEDITORTOP.G_CURRKEDITOR._config&&"function"==typeof KEDITORTOP.G_CURRKEDITOR._config.event.destroy)try{KEDITORTOP.G_CURRKEDITOR._config.event.destroy({eventInfo:{componentName:e,paramObj:void 0}})}catch(t){}else if("function"==typeof KEDITORTOP.KEDITORWIN.RAONKEDITOR_Destroy)try{KEDITORTOP.KEDITORWIN.RAONKEDITOR_Destroy({eventInfo:{componentName:e,paramObj:void 0}})}catch(t){}}),!1))}}(e),void 0===e._ExternalAttachEvents&&function(e){e._ExternalAttachEvents=function(t,n,o){var r=t._config,a=o;switch(n){case"loaded":var c=RAONKEDITOR._ExternalLoadedEventMap.get(t.ID);c.push(a),RAONKEDITOR._ExternalLoadedEventMap.set(t.ID,c);break;case"creationComplete":if("function"==typeof r.event[n])break;var i=RAONKEDITOR._ExternalCreationCompleteEventMap.get(t.ID);i.push(a),RAONKEDITOR._ExternalCreationCompleteEventMap.set(t.ID,i);var d=function(n,o){for(var r=RAONKEDITOR._ExternalLoadedEventMap.get(t.ID),a=0,c=r.length;a<c;a++)try{r[a]({eventInfo:{componentName:n,paramObj:o}})}catch(e){}var i=RAONKEDITOR._ExternalCreationCompleteEventMap.get(t.ID);for(a=0,c=i.length;a<c;a++)try{i[a]({eventInfo:{componentName:n,paramObj:o}})}catch(e){}e._ExternalSetDestroyEvent(t.ID)};r.event[n]=d;break;case"destroy":var s=RAONKEDITOR._ExternalDestroyEventMap.get(t.ID);s.push(a),RAONKEDITOR._ExternalDestroyEventMap.set(t.ID,s);break;default:var u=function(e,t){if(a)try{return a({eventInfo:{componentName:e,paramObj:t}})}catch(e){}};r.event[n]=u}}}(e),void 0!==I.current&&(R.current.Runtimes=I.current),t&&console.log({logType:"RAONWIZ Log - initComponent",operation:"makeComponent config",configRef:R.current,runtimesRef:I.current,componentName:n.id});var c=e._ExternalMakeComponent(n,R.current);m.current.filter((function(e){return-1===i.indexOf(e)})).forEach((function(e){E({debug:v.current,component:c,evtName:e,handler:function(t){var n;return null===(n=y.current)||void 0===n?void 0:n.call(y,{type:"".concat(s).concat(e),payload:t})}})})),E({debug:v.current,component:c,evtName:"loaded",handler:function(){M({type:"loaded"})}}),E({debug:v.current,component:c,evtName:"creationComplete",handler:function(e){e.component,M({type:"ready"}),r||RAONKEDITOR.SetReadOnly(a,n.id)}}),E({debug:v.current,component:c,evtName:"destroy",handler:function(){M({type:"destroyed"})}}),M({type:"unloaded",payload:c})})).catch((function(e){console.error(e),M({type:"error"})}))}return function(){j&&j.object&&j.object.ID&&null===document.getElementById(j.object.ID)&&RAONKEDITOR&&(RAONKEDITOR._ExternalLoadedEventMap.has(j.object.ID)&&RAONKEDITOR._ExternalLoadedEventMap.delete(j.object.ID),RAONKEDITOR._ExternalCreationCompleteEventMap.has(j.object.ID)&&RAONKEDITOR._ExternalCreationCompleteEventMap.delete(j.object.ID),RAONKEDITOR._ExternalDestroyEventMap.has(j.object.ID)&&RAONKEDITOR._ExternalDestroyEventMap.delete(j.object.ID),RAONKEDITOR.Destroy(j.object.ID,!1))}}),[j,n]),{component:j,status:null==j?void 0:j.status,error:"error"===C,loading:"loading"===C}}function x(e,t){switch(t.type){case"init":return r(r({},e),{hookStatus:"init"});case"loading":return r(r({},e),{hookStatus:"loading"});case"unloaded":return{component:t.payload,hookStatus:"unloaded"};case"loaded":return r(r({},e),{hookStatus:"loaded"});case"ready":return r(r({},e),{hookStatus:"ready"});case"destroyed":return{component:void 0,hookStatus:"destroyed"};case"error":return{component:void 0,hookStatus:"error"};default:return e}}var K,j,C,M,L={exports:{}};L.exports=function(){if(M)return C;M=1;var e=j?K:(j=1,K="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");function t(){}function n(){}return n.resetWarningCache=t,C=function(){function o(t,n,o,r,a,c){if(c!==e){var i=new Error("Calling PropTypes validators directly is not supported by the `prop-types` package. Use PropTypes.checkPropTypes() to call them. Read more at http://fb.me/use-check-prop-types");throw i.name="Invariant Violation",i}}function r(){return o}o.isRequired=o;var a={array:o,bigint:o,bool:o,func:o,number:o,object:o,string:o,symbol:o,any:o,arrayOf:r,element:o,elementType:o,instanceOf:r,node:o,objectOf:r,oneOf:r,oneOfType:r,shape:r,exact:r,checkPropTypes:n,resetWarningCache:t};return a.PropTypes=a,a}}()();var k=o.useEffect,P=o.useRef,w=o.useState;function S(e){var t=e.debug,n=e.id,r=void 0===n?"raonkeditor_"+Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5):n,a=e.config,c=void 0===a?{}:a,i=e.componentUrl,d=e.runtimes,s=e.mode,u=e.readOnly,O=function(e,t){var n={};for(var o in e)Object.prototype.hasOwnProperty.call(e,o)&&t.indexOf(o)<0&&(n[o]=e[o]);if(null!=e&&"function"==typeof Object.getOwnPropertySymbols){var r=0;for(o=Object.getOwnPropertySymbols(e);r<o.length;r++)t.indexOf(o[r])<0&&Object.prototype.propertyIsEnumerable.call(e,o[r])&&(n[o[r]]=e[o[r]])}return n}(e,["debug","id","config","componentUrl","runtimes","mode","readOnly"]),E=w(null),m=E[0],v=E[1],y=P(O);c&&"boolean"==typeof u&&(c.ReadOnly=u),c&&"string"==typeof s&&(c.Mode=s);var R=A({debug:t,element:m,config:c,componentUrl:i,runtimes:d,dispatchEvent:function(e){var t=e.type,n=e.payload,o=p(l(t)),r=y.current[o];if(r)return r(n)},subscribeTo:Object.keys(O).filter((function(e){return 0===e.indexOf("on")})).map(f)}),I=R.component,D=R.status;return k((function(){if(I&&"ready"===D&&"string"==typeof s){var e=RAONKEDITOR.IsLoadedEditorEx(I.object.ID);t&&console.log({logType:"RAONWIZ Log - useEffect",operation:"useEffect",component:I,componentName:I.object.ID,mode:s,status:D,IsLoadedComponentEx:e}),e&&RAONKEDITOR.SetEditorMode(s,I.object.ID)}}),[I,D,s]),k((function(){if(I&&"ready"===D&&"boolean"==typeof u){var e=RAONKEDITOR.IsLoadedEditorEx(I.object.ID);t&&console.log({logType:"RAONWIZ Log - useEffect",operation:"useEffect",component:I,componentName:I.object.ID,readOnly:u,status:D,IsLoadedComponentEx:e}),e&&RAONKEDITOR.SetReadOnly(u,I.object.ID)}}),[I,D,u]),o.createElement("div",{id:null!=r?r:void 0,ref:v})}var U=r({config:L.exports.object,debug:L.exports.bool,componentUrl:L.exports.string,id:L.exports.string,mode:L.exports.oneOf(["edit","view"]),readOnly:L.exports.bool,runtimes:L.exports.oneOf(["html5","agent"])},d.reduce((function(e,t){var n;return r(r({},e),((n={})[p(t)]=L.exports.func,n))}),{}));S.propTypes=U,e.ComponentEventAction=O,e.RaonkEditor=S,e.prefixEventName=u,e.registerComponentEventHandler=E,e.stripPrefix=l,e.useRaonkEditor=A,Object.defineProperty(e,"__esModule",{value:!0})}));