UNPKG

raonkupload-react

Version:

React component for RAON K Upload

5 lines (4 loc) 12.9 kB
/** * @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).RAONKUploadReact={},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","beforeAddFile","afterAddFile","afterAddAllFile","beforeDeleteFile","afterDeleteFile","deleteAllFile","beforeUpload","uploadComplete","beforeDownloadFile","beforeOpenFile","downloadCompleteFile","downloadCompleteAllFile","onError","uploadingCancel","downloadCancel","selectItem","customAction","alert"],i=["beforeLoad","namespaceLoaded"],l=a(a([],c,!0),i,!0),d="__RKU__";function u(e){return"".concat(d).concat(e)}function p(e){return e.substr(d.length)}function s(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 m(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}),RAONKUPLOAD._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 v,y={};function A(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 D(e,t){e.onreadystatechange=function(){"complete"!=this.readyState&&"loaded"!=this.readyState||(this.onreadystatechange=null,t(null,e))}}function E(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.")):(v||(v=E.scriptLoader(e,t).then((function(e){return n&&n(e),e}))),v)}Object.defineProperty(y,"__esModule",{value:!0}),E.scriptLoader=function(e,t){return new Promise((function(n,o){var r,a,c,i,l;r=t,a=function(t){v=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],l=document.createElement("script"),"function"==typeof a&&(c=a,a={}),a=a||{},c=c||function(){},l.type=a.type||"text/javascript",l.charset=a.charset||"utf8",l.async=!("async"in a)||!!a.async,l.src=r,a.attrs&&function(e,t){for(var n in t)e.setAttribute(n,t[n])}(l,a.attrs),a.text&&(l.text=String(a.text)),("onload"in l?A:D)(l,c),l.onload||A(l,c),i.appendChild(l)}))},y.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 g=y.getRaonwizComponentNamespace=E,b=o.useEffect,h=o.useReducer,L=o.useRef,P="RAONKUPLOAD",R="/raonkupload/js/raonkupload.js",U={};function N(e){var t=e.debug,n=e.element,o=e.config,r=e.componentUrl,a=e.runtimes,c=e.dispatchEvent,u=e.subscribeTo,p=void 0===u?l:u,s=L(r||R),f=L(null!=p?p:l),v=L(t),y=L(c),A=L(o||U),D=L(a),E=h(_,{component:void 0,hookStatus:"init"}),N=E[0],I=N.component,x=N.hookStatus,K=E[1];return b((function(){if(n&&!I){K({type:"loading"});g(P,s.current,(function(e){var t;-1!==f.current.indexOf("namespaceLoaded")&&(null===(t=y.current)||void 0===t||t.call(y,{type:O.namespaceLoaded,payload:e}))})).then((function(e){var o;-1!==f.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===RAONKUPLOAD._ExternalCreationCompleteEventMap&&(RAONKUPLOAD._ExternalLoadedEventMap=new Map),void 0===RAONKUPLOAD._ExternalCreationCompleteEventMap&&(RAONKUPLOAD._ExternalCreationCompleteEventMap=new Map),void 0===RAONKUPLOAD._ExternalDestroyEventMap&&(RAONKUPLOAD._ExternalDestroyEventMap=new Map),RAONKUPLOAD._ExternalLoadedEventMap.set(t.id,[]),RAONKUPLOAD._ExternalCreationCompleteEventMap.set(t.id,[]),RAONKUPLOAD._ExternalDestroyEventMap.set(t.id,[]),e._ExternalDestroy=!0;var o={Id:t.id,UploadHolder:t.id};return o=e.util.objectExtend(!0,n,o),{object:new RAONKUpload(o),status:"ready"}}}(e),void 0===e._ExternalSetDestroyEvent&&function(e){e._ExternalSetDestroyEvent=function(e){var t,n;"function"==typeof MutationObserver?(t=(n=document.getElementById("raonkuploader_holder_"+e))||document.getElementById("raonkuploader_frame_"+e))&&new MutationObserver((function(){var t=RAONKUPLOAD._ExternalDestroyEventMap.get(e),n=RAONKUPLOAD.GetUploadByName(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 KUPLOADTOP.KUPLOADWIN.RAONKUPLOAD_Destroy)try{KUPLOADTOP.KUPLOADWIN.RAONKUPLOAD_Destroy({eventInfo:{componentName:e,paramObj:void 0}})}catch(e){}})).observe(t,{childList:!0}):((n=document.getElementById("raonkuploader_frame_"+e))&&(t=n),t&&t.addEventListener("DOMNodeRemoved",(function(t){var n=RAONKUPLOAD._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(KUPLOADTOP.G_CURRKUPLOADER&&void 0!==KUPLOADTOP.G_CURRKUPLOADER._config&&"function"==typeof KUPLOADTOP.G_CURRKUPLOADER._config.event.destroy)try{KUPLOADTOP.G_CURRKUPLOADER._config.event.destroy({eventInfo:{componentName:e,paramObj:void 0}})}catch(t){}else if("function"==typeof KUPLOADTOP.KUPLOADWIN.RAONKUPLOAD_Destroy)try{KUPLOADTOP.KUPLOADWIN.RAONKUPLOAD_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=RAONKUPLOAD._ExternalLoadedEventMap.get(t.ID);c.push(a),RAONKUPLOAD._ExternalLoadedEventMap.set(t.ID,c);break;case"creationComplete":if("function"==typeof r.event[n])break;var i=RAONKUPLOAD._ExternalCreationCompleteEventMap.get(t.ID);i.push(a),RAONKUPLOAD._ExternalCreationCompleteEventMap.set(t.ID,i);var l=function(n,o){for(var r=RAONKUPLOAD._ExternalLoadedEventMap.get(t.ID),a=0,c=r.length;a<c;a++)try{r[a]({eventInfo:{componentName:n,paramObj:o}})}catch(e){}var i=RAONKUPLOAD._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]=l;break;default:var d=function(e,t){if(a)try{return a({eventInfo:{componentName:e,paramObj:t}})}catch(e){}};r.event[n]=d}}}(e),void 0!==D.current&&(A.current.Runtimes=D.current),t&&console.log({logType:"RAONWIZ Log - initComponent",operation:"makeComponent config",configRef:A.current,runtimesRef:D.current,componentName:n.id});var r=e._ExternalMakeComponent(n,A.current);f.current.filter((function(e){return-1===i.indexOf(e)})).forEach((function(e){m({debug:v.current,component:r,evtName:e,handler:function(t){var n;return null===(n=y.current)||void 0===n?void 0:n.call(y,{type:"".concat(d).concat(e),payload:t})}})})),m({debug:v.current,component:r,evtName:"loaded",handler:function(){K({type:"loaded"})}}),m({debug:v.current,component:r,evtName:"creationComplete",handler:function(e){e.component,K({type:"ready"})}}),m({debug:v.current,component:r,evtName:"destroy",handler:function(){K({type:"destroyed"})}}),K({type:"unloaded",payload:r})})).catch((function(e){console.error(e),K({type:"error"})}))}return function(){I&&I.object&&I.object.ID&&null===document.getElementById(I.object.ID)&&RAONKUPLOAD&&(RAONKUPLOAD._ExternalLoadedEventMap.has(I.object.ID)&&RAONKUPLOAD._ExternalLoadedEventMap.delete(I.object.ID),RAONKUPLOAD._ExternalCreationCompleteEventMap.has(I.object.ID)&&RAONKUPLOAD._ExternalCreationCompleteEventMap.delete(I.object.ID),RAONKUPLOAD._ExternalDestroyEventMap.has(I.object.ID)&&RAONKUPLOAD._ExternalDestroyEventMap.delete(I.object.ID),RAONKUPLOAD.Destroy(I.object.ID,!0))}}),[I,n]),{component:I,status:null==I?void 0:I.status,error:"error"===x,loading:"loading"===x}}function _(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 I,x,K,j,C={exports:{}};C.exports=function(){if(j)return K;j=1;var e=x?I:(x=1,I="SECRET_DO_NOT_PASS_THIS_OR_YOU_WILL_BE_FIRED");function t(){}function n(){}return n.resetWarningCache=t,K=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 T=o.useEffect,w=o.useRef,M=o.useState;function k(e){var t=e.debug,n=e.id,r=void 0===n?"raonkupload_"+Math.random().toString(36).replace(/[^a-z]+/g,"").substr(0,5):n,a=e.config,c=void 0===a?{}:a,i=e.componentUrl,l=e.runtimes,d=e.mode,u=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"]),O=M(null),m=O[0],v=O[1],y=w(u);c&&"string"==typeof d&&(c.Mode=d);var A=N({debug:t,element:m,config:c,componentUrl:i,runtimes:l,dispatchEvent:function(e){var t=e.type,n=e.payload,o=s(p(t)),r=y.current[o];if(r)return r(n)},subscribeTo:Object.keys(u).filter((function(e){return 0===e.indexOf("on")})).map(f)}),D=A.component,E=A.status;return T((function(){if(D&&"ready"===E&&"string"==typeof d){var e=RAONKUPLOAD.IsLoadedUploadEx(D.object.ID);t&&console.log({logType:"RAONWIZ Log - useEffect",operation:"useEffect",component:D,componentName:D.object.ID,mode:d,status:E,IsLoadedComponentEx:e}),e&&RAONKUPLOAD.SetUploadMode(d,D.object.ID)}}),[D,E,d]),o.createElement("div",{id:null!=r?r:void 0,ref:v})}var S=r({config:C.exports.object,debug:C.exports.bool,componentUrl:C.exports.string,id:C.exports.string,mode:C.exports.oneOf(["edit","view"]),runtimes:C.exports.oneOf(["html5","agent"])},l.reduce((function(e,t){var n;return r(r({},e),((n={})[s(t)]=C.exports.func,n))}),{}));k.propTypes=S,e.ComponentEventAction=O,e.RaonkUpload=k,e.prefixEventName=u,e.registerComponentEventHandler=m,e.stripPrefix=p,e.useRaonkUpload=N,Object.defineProperty(e,"__esModule",{value:!0})}));