@bgscore/react-core 0.0.3 → 0.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _moment = require('moment'); var _moment2 = _interopRequireDefault(_moment);var _react = require('react'); var _react2 = _interopRequireDefault(_react);function $e(){let e=()=>Math.random()*16%16|0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>(t==="x"?e():e()&3|8).toString(16))}function je(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch (e2){return!1}}var Ve=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&(e[t]=null)}),e);function ze(e,t){let n=!1;return e&&typeof e=="object"&&Array.isArray(e)&&(typeof t=="number"?e.length>t&&(n=!0):n=!0),n}function q(e){return!(e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===0)}var X={camelCase:(e="")=>(e=e.split(".").map(t=>(t=t.charAt(0).toUpperCase()+t.slice(1),t)).join(" "),e=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),e.charAt(0).toUpperCase()+e.slice(1)),snackCase:(e="")=>{let n=e.replace(/_([a-z])/g,(o,a)=>a.toUpperCase()).replace(/([A-Z])/g," $1");return n=n.charAt(0).toUpperCase()+n.slice(1),n},changeAll:(e="",t=!1)=>{let n="";try{e=_optionalChain([e, 'optionalAccess', _2 => _2.split, 'call', _3 => _3("."), 'access', _4 => _4[_optionalChain([e, 'optionalAccess', _5 => _5.split, 'call', _6 => _6("."), 'optionalAccess', _7 => _7.length])-1]]),e=_optionalChain([e, 'optionalAccess', _8 => _8.split, 'call', _9 => _9("[]"), 'access', _10 => _10[_optionalChain([e, 'optionalAccess', _11 => _11.split, 'call', _12 => _12("[]"), 'optionalAccess', _13 => _13.length])-1]]),n=X.snackCase(X.camelCase(e)),t&&(n=_optionalChain([n, 'optionalAccess', _14 => _14.split, 'call', _15 => _15(" "), 'optionalAccess', _16 => _16.map, 'call', _17 => _17(o=>_optionalChain([o, 'optionalAccess', _18 => _18.length])<=3?_optionalChain([o, 'optionalAccess', _19 => _19.toUpperCase, 'call', _20 => _20()]):o), 'optionalAccess', _21 => _21.join, 'call', _22 => _22(" ")]))}catch (e3){}return _optionalChain([n, 'optionalAccess', _23 => _23.trim, 'call', _24 => _24()])}};function Je(e,t){return typeof e=="function"?e(t):e}var O=(e,t,n="")=>{if(!e)return n;if(e.hasOwnProperty(t))return e[t];let o=t.replace(/\[(\d+)\]/g,".$1").split("."),a=e;for(let r of o){if(a==null)return n;a=a[r]}return a===void 0?n:a},We= exports.sorting ={desc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(n,t):"";return a<r?1:-1}else return n<o?1:-1})),asc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(o,t):"";return a>r?1:-1}else return n>o?1:-1}))},Ge= exports.summary =(e,t)=>{Array.isArray(e)||(e=[]);let n=[];return n=e.map(o=>Number(t?O(o,t)||0:o||0)),n.reduce((o,a)=>(o||0)+(a||0),0)||0};function Xe(e){try{return e&&JSON.parse(JSON.stringify(e))}catch (e4){return e}}function me(e){let t=new WeakSet;return _nullishCoalesce(JSON.stringify(e,function(n,o){return o!==null&&typeof o=="object"?t.has(o)?void 0:(t.add(o),Object.keys(o).sort().reduce((a,r)=>(a[r]=o[r],a),{})):o}), () => (""))}function _(e,t){return me([_nullishCoalesce(t, () => ("undefined")),_nullishCoalesce(e, () => ("undefined"))])}var _jsxruntime = require('react/jsx-runtime');var Z=_react.createContext.call(void 0, void 0);function N(){let e=_react.useContext.call(void 0, Z);return e||{}}var ge=({children:e,value:t})=>{let n={...t};return _jsxruntime.jsx.call(void 0, Z.Provider,{value:n,children:e})};var _aes = require('crypto-js/aes'); var _aes2 = _interopRequireDefault(_aes);var _pbkdf2 = require('crypto-js/pbkdf2'); var _pbkdf22 = _interopRequireDefault(_pbkdf2);var _encutf8 = require('crypto-js/enc-utf8'); var _encutf82 = _interopRequireDefault(_encutf8);var _encbase64 = require('crypto-js/enc-base64'); var _encbase642 = _interopRequireDefault(_encbase64);var _libtypedarrays = require('crypto-js/lib-typedarrays'); var _libtypedarrays2 = _interopRequireDefault(_libtypedarrays);function I(e,t){let n=_libtypedarrays2.default.random(16),o=_libtypedarrays2.default.random(16),a=_pbkdf22.default.call(void 0, t,n,{keySize:256/32,iterations:1e3}),r=_aes2.default.encrypt(JSON.stringify(e),a,{iv:o}).toString();return{salt:n.toString(_encbase642.default),iv:o.toString(_encbase642.default),encrypted:r}}function H(e,t){let{salt:n,iv:o,encrypted:a}=e,r=_pbkdf22.default.call(void 0, t,_encbase642.default.parse(n),{keySize:256/32,iterations:1e3}),i=_aes2.default.decrypt(a,r,{iv:_encbase642.default.parse(o)}).toString(_encutf82.default);return JSON.parse(i)}function te(e,t){return JSON.stringify(I(e,t))}function re(e,t){return H(JSON.parse(e),t)}function M(){let{passphrase:e}=N();return{passphrase:e,encrypt(t,n){return I(t,n||e)},decrypt(t,n){return H(t,n||e)},encryptString(t,n){return te(t,n||e)},decryptString(t,n){return re(t,n||e)}}}var ne=()=>{let{encrypt:e,decrypt:t}=M(),n=_react.useCallback.call(void 0, (c,i)=>{try{let d=e(i);localStorage.setItem(c,JSON.stringify(d))}catch(d){console.error("Failed to save to storage:",d)}},[e]),o=_react.useCallback.call(void 0, c=>{try{let i=localStorage.getItem(c);return i?t(JSON.parse(i)):null}catch(i){return console.error("Failed to get from storage:",i),null}},[t]),a=c=>{let[i,d]=_react.useState.call(void 0, ()=>{try{let l=localStorage.getItem(c);return l?t(JSON.parse(l)):null}catch(l){return console.error("Failed to parse localStorage value",l),null}});return _react.useEffect.call(void 0, ()=>{let l=R=>{if(R.key===c)if(R.newValue)try{d(t(JSON.parse(R.newValue)))}catch(S){console.error("Decrypt error from storage event",S)}else d(null)};return window.addEventListener("storage",l),()=>window.removeEventListener("storage",l)},[c,t]),i},r=_react.useCallback.call(void 0, c=>{c?localStorage.removeItem(c):localStorage.clear()},[]);return{save:n,get:o,clear:r,useWatchStorage:a}};function oe(e){let t=e,n=new Set;function o(){return t}function a(i){return n.add(i),()=>n.delete(i)}function r(i){typeof i=="function"?t=i(t):t=i,n.forEach(d=>d())}function c(i){return _react.useSyncExternalStore.call(void 0, a,()=>i?i(t):t,()=>i?i(t):t)}return{getSnapshot:o,subscribe:a,setState:r,useStore:c}}var $=new Map;function F(e){return $.has(e)||$.set(e,oe([null,{}])),$.get(e)}function Se(e,t,n){let o=arguments.length===3,a=o?t:void 0,r=o?n:t,{storageKey:c,cache:i}=N(),d=ne(),[l,R]=_react.useState.call(void 0, !1),[S,b]=_react.useState.call(void 0, !1),[T,C]=_react.useState.call(void 0, ),g=_react.useRef.call(void 0, void 0),x=_react.useRef.call(void 0, null),{cacheName:P,cacheKey:A,timeout:J,timeoutUnit:W,persistence:G}=_react.useMemo.call(void 0, ()=>{let p=c?d.get(c):void 0,s=typeof _optionalChain([r, 'optionalAccess', _25 => _25.cache])=="object"?_nullishCoalesce(_optionalChain([r, 'optionalAccess', _26 => _26.cache, 'optionalAccess', _27 => _27.cacheName]), () => (e.name)):e.name,f=_({...a,session:p},typeof _optionalChain([r, 'optionalAccess', _28 => _28.cache])=="object"?_optionalChain([r, 'optionalAccess', _29 => _29.cache, 'optionalAccess', _30 => _30.cacheKey]):void 0),y=!1;typeof _optionalChain([i, 'optionalAccess', _31 => _31.persistence])=="boolean"&&(y=_optionalChain([i, 'optionalAccess', _32 => _32.persistence])),typeof _optionalChain([r, 'optionalAccess', _33 => _33.cache])=="object"&&typeof _optionalChain([r, 'optionalAccess', _34 => _34.cache, 'optionalAccess', _35 => _35.persistence])=="boolean"&&(y=_nullishCoalesce(_optionalChain([r, 'optionalAccess', _36 => _36.cache, 'optionalAccess', _37 => _37.persistence]), () => (!1)));let h=60*5,u="s";return q(_optionalChain([i, 'optionalAccess', _38 => _38.timeout]))&&(typeof _optionalChain([i, 'optionalAccess', _39 => _39.timeout])=="number"?(h=i.timeout,u="s"):typeof _optionalChain([i, 'optionalAccess', _40 => _40.timeout])=="object"&&(h=_optionalChain([i, 'optionalAccess', _41 => _41.timeout, 'access', _42 => _42.value]),u=_optionalChain([i, 'optionalAccess', _43 => _43.timeout, 'access', _44 => _44.unit]))),_optionalChain([r, 'optionalAccess', _45 => _45.cache])&&typeof r.cache!="boolean"&&(typeof r.cache.timeout=="number"?(h=r.cache.timeout,u="s"):typeof r.cache.timeout=="object"&&(h=r.cache.timeout.value,u=r.cache.timeout.unit)),{cacheName:s,cacheKey:f,timeout:h,timeoutUnit:u,persistence:y}},[_optionalChain([r, 'optionalAccess', _46 => _46.cache]),c,i]);_react.useEffect.call(void 0, ()=>{let p=JSON.stringify(q(g.current)?g.current:""),s=JSON.stringify(q(a)?a:""),f=g.current===void 0;(p!==s||f)&&!_optionalChain([r, 'optionalAccess', _47 => _47.hold])&&(C(null),U(),g.current=a),_optionalChain([r, 'optionalAccess', _48 => _48.onChange])&&_optionalChain([r, 'optionalAccess', _49 => _49.onChange, 'call', _50 => _50(a,m)])},[a,_optionalChain([r, 'optionalAccess', _51 => _51.hold]),..._optionalChain([r, 'optionalAccess', _52 => _52.trigger])||[]]),_react.useEffect.call(void 0, ()=>{let p=async()=>{!G&&P&&A&&(await caches.open(P)).delete(A)};return window.addEventListener("beforeunload",p),()=>{window.removeEventListener("beforeunload",p),_optionalChain([x, 'access', _53 => _53.current, 'optionalAccess', _54 => _54.abort, 'call', _55 => _55()])}},[]);let U=_react.useCallback.call(void 0, async p=>{let s=a;if(_optionalChain([r, 'optionalAccess', _56 => _56.hold])&&_optionalChain([r, 'optionalAccess', _57 => _57.logging])&&console.log("Hold active"),_optionalChain([r, 'optionalAccess', _58 => _58.beforeRequest])&&(s=_optionalChain([r, 'optionalAccess', _59 => _59.beforeRequest, 'call', _60 => _60(a)])),_optionalChain([r, 'optionalAccess', _61 => _61.cache])&&!p&&!S){R(!0),_optionalChain([r, 'optionalAccess', _62 => _62.onBeforeRequest])&&_optionalChain([r, 'optionalAccess', _63 => _63.onBeforeRequest, 'call', _64 => _64(a)]);let f=await caches.open(P),h=awaitawait _asyncOptionalChain([(await f.match(A)), 'optionalAccess', async _65 => _65.json, 'call', async _66 => _66()]);if(h){let{data:u,expired:w}=h;if(_moment2.default.call(void 0, ).isAfter(w))await f.delete(A);else{_optionalChain([r, 'optionalAccess', _67 => _67.afterResponse])&&_optionalChain([u, 'optionalAccess', _68 => _68.data])&&(u.data=_optionalChain([r, 'optionalAccess', _69 => _69.afterResponse, 'call', _70 => _70(u.data)])),_optionalChain([r, 'optionalAccess', _71 => _71.logging])&&console.log("After request: Using Cache",u),_optionalChain([r, 'optionalAccess', _72 => _72.onAfterResponse])&&_optionalChain([r, 'optionalAccess', _73 => _73.onAfterResponse, 'call', _74 => _74(u)]),R(!1),C(u);return}}}if(typeof e=="function"){_optionalChain([x, 'access', _75 => _75.current, 'optionalAccess', _76 => _76.abort, 'call', _77 => _77()]);let f=new AbortController;x.current=f,R(!0),_optionalChain([r, 'optionalAccess', _78 => _78.logging])&&console.log("Before request",a),_optionalChain([r, 'optionalAccess', _79 => _79.onBeforeRequest])&&_optionalChain([r, 'optionalAccess', _80 => _80.onBeforeRequest, 'call', _81 => _81(a)]);let y=o?await e(s,void 0,{...r,signal:f.signal}):await e(void 0,{...r,signal:f.signal});if(_optionalChain([r, 'optionalAccess', _82 => _82.afterResponse])&&_optionalChain([y, 'optionalAccess', _83 => _83.data])&&(y.data=_optionalChain([r, 'optionalAccess', _84 => _84.afterResponse, 'call', _85 => _85(y.data)])),_optionalChain([r, 'optionalAccess', _86 => _86.logging])&&console.log("After request",y),_optionalChain([r, 'optionalAccess', _87 => _87.onAfterResponse])&&_optionalChain([r, 'optionalAccess', _88 => _88.onAfterResponse, 'call', _89 => _89(y)]),R(!1),C(y),b(!1),_optionalChain([r, 'optionalAccess', _90 => _90.cache])&&y.status){let h=_moment2.default.call(void 0, ).add(J,W).toISOString(),u={data:y,expired:h},w=await caches.open(P),v=new Response(JSON.stringify(u));await w.put(A,v)}}},[a,e,r]);_react.useEffect.call(void 0, ()=>{if(_optionalChain([r, 'optionalAccess', _91 => _91.refreshInterval])){let p=typeof r.refreshInterval=="number"?r.refreshInterval:r.refreshInterval.value,s=typeof r.refreshInterval=="number"?"s":r.refreshInterval.unit,f=setInterval(()=>{U()},_moment2.default.duration(p,s).asMilliseconds());return()=>clearInterval(f)}return()=>{}},[_optionalChain([r, 'optionalAccess', _92 => _92.refreshInterval]),U]),_react.useEffect.call(void 0, ()=>{if(!_optionalChain([r, 'optionalAccess', _93 => _93.refetchOnWindowFocus]))return;let p=()=>{U()};return window.addEventListener("focus",p),()=>{window.removeEventListener("focus",p)}},[_optionalChain([r, 'optionalAccess', _94 => _94.refetchOnWindowFocus]),U]);let m={...T,loading:l,refresh:U,abort:()=>{_optionalChain([x, 'access', _95 => _95.current, 'optionalAccess', _96 => _96.abort, 'call', _97 => _97()]),x.current=null,R(!1),b(!0)},clear:()=>{R(!1),C(null)},response:T,isCancel:S,clone:(p,s)=>Se(e,p,s)};return _react.useEffect.call(void 0, ()=>{_optionalChain([r, 'optionalAccess', _98 => _98.storeName])&&F(_optionalChain([r, 'optionalAccess', _99 => _99.storeName])).setState([_optionalChain([T, 'optionalAccess', _100 => _100.data]),m])},[T,m,_optionalChain([r, 'optionalAccess', _101 => _101.storeName])]),[_optionalChain([T, 'optionalAccess', _102 => _102.data]),m]}async function St(e,t=()=>{}){let n=e*1e3;return new Promise(o=>{let a=0,r=setInterval(()=>{t(),a===9&&clearInterval(r)},1e3);setTimeout(async()=>{await t(),o(!0)},n)})}var ae=(r=>(r.POST="POST",r.PUT="PUT",r.PATCH="PATCH",r.DELETE="DELETE",r.GET="GET",r))(ae||{}),ie= exports.DataTypeEnum =(s=>(s.number="number",s.currency="currency",s.percent="percent",s.date="date",s.dateTime="dateTime",s.month="month",s.year="year",s.time="time",s.timestamp="timestamp",s.string="string",s.textarea="textarea",s.code="code",s.password="password",s.boolean="boolean",s.toggle="toggle",s.email="email",s.phone="phone",s.url="url",s.json="json",s.file="file",s.image="image",s.array="array",s.object="object",s.enum="enum",s.user="user",s.department="department",s.status="status",s))(ie||{});var vt=(e,t,n)=>{let{format:o}=N();return t==="number"?we(e,{thouSep:o.number.thouSep,decDigits:o.number.decDigits,decSep:o.number.decSep,...n}):["date","dateTime","month","year","time"].includes(t)?Ue(e,{display:_optionalChain([o, 'access', _103 => _103[t], 'optionalAccess', _104 => _104.display]),value:_optionalChain([o, 'access', _105 => _105[t], 'optionalAccess', _106 => _106.value]),...n}):t==="boolean"?Oe(e,n):t==="string"?qe(e,n):_nullishCoalesce(_optionalChain([e, 'optionalAccess', _107 => _107.toString, 'call', _108 => _108()]), () => (""))};function Oe(e,t){let n=typeof e=="string"?e==="true":!!e,o=_nullishCoalesce(_optionalChain([t, 'optionalAccess', _109 => _109.trueLabel]), () => ("Yes")),a=_nullishCoalesce(_optionalChain([t, 'optionalAccess', _110 => _110.falseLabel]), () => ("No"));return n?o:a}function qe(e,t){if(!q(e))return"";let n=String(e);return _optionalChain([t, 'optionalAccess', _111 => _111.capitalize])&&(n=n.charAt(0).toUpperCase()+n.slice(1)),_optionalChain([t, 'optionalAccess', _112 => _112.ellipsis])&&n.length>t.ellipsis&&(n=n.slice(0,t.ellipsis)+"..."),n}function we(e,{thouSep:t,decSep:n,decDigits:o,method:a}){if(e==null||isNaN(Number(e)))return"";let r=typeof e=="string"?parseFloat(e):e;if(a)if(typeof o=="number"){let l=Math.pow(10,o);r=Math[a](r*l)/l}else r=Math[a](r);else if(typeof o=="number"){let l=Math.pow(10,o);r=Math.floor(r*l)/l}let c=0;if(o==="auto"){let l=r.toString(),R=l.indexOf(".");R!==-1&&(c=l.length-R-1)}let i={style:"decimal",useGrouping:!0,minimumFractionDigits:o==="auto"?c:o||0,maximumFractionDigits:o==="auto"?c:o||0,minimumIntegerDigits:1};return r.toLocaleString("en-US",i).replace(/\./g,"decSep").replace(/,/g,"thouSep").replace(/decSep/g,n).replace(/thouSep/g,t)}function Ue(e,{display:t,value:n}){if(!q(e))return e;let o=_moment2.default.call(void 0, e,n);return o.isValid()?o.format(t):e}function Mt(e,{interval:t,lead:n}){let o=_react.useRef.call(void 0, null);_react.useEffect.call(void 0, ()=>{o.current=e},[e]),_react.useEffect.call(void 0, ()=>{let a=()=>o.current();if(n&&a(),t!==null){let r=setInterval(a,t);return()=>clearInterval(r)}},[t])}function It(e,t,n){let[o,a]=_react.useState.call(void 0, !1),r=(l,R)=>typeof e=="string"&&l===e||typeof e=="number"&&R===e,c=l=>l!==null&&(["INPUT","TEXTAREA","SELECT","BUTTON"].includes(l.tagName)||l.hasAttribute("contentEditable")),i=l=>{let{key:R,keyCode:S}=l,b=l.ctrlKey,T=l.altKey,C=l.shiftKey;if(!c(document.activeElement))if(t)if(typeof t=="string")r(R,S)&&(t==="ctrl"&&b||t==="alt"&&T||t==="shift"&&C)&&(l.preventDefault(),n&&l.stopPropagation(),a(!o));else{let g=t.every(x=>x==="ctrl"?b:x==="alt"?T:x==="shift"?C:!1);r(R,S)&&g&&(l.preventDefault(),n&&l.stopPropagation(),a(!o))}else r(R,S)&&(l.preventDefault(),n&&l.stopPropagation(),a(!o))},d=({key:l,keyCode:R})=>{r(l,R)&&a(!1)};return _react.useEffect.call(void 0, ()=>(window.addEventListener("keydown",i),window.addEventListener("keyup",d),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",d)}),[]),o}var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);var er=({url:e,token:t,beforeRequest:n,onCallback:o,headers:a,onUnauthorized:r,handleToast:c,handleAuthorization:i,disabledToastWhenCancel:d,withCredentials:l,encryptRequest:R,encryptResponse:S,passphrase:b})=>{let{encrypt:T,decrypt:C,passphrase:g}=M(),x=(m,p,s,f)=>{let y=_optionalChain([f, 'optionalAccess', _113 => _113.code])==="ERR_CANCELED",h=m.status===401,u=_optionalChain([m, 'optionalAccess', _114 => _114.data]);if((typeof _optionalChain([s, 'optionalAccess', _115 => _115.encryptResponse])=="boolean"?_optionalChain([s, 'optionalAccess', _116 => _116.encryptResponse]):S)&&u){let E=_optionalChain([s, 'optionalAccess', _117 => _117.passphrase])?typeof s.passphrase=="boolean"&&s.passphrase?g:s.passphrase:b;try{u=C(u,E)}catch (e5){try{u=C(u,g)}catch (e6){}}}let D={...o({...m,data:u,isCancel:y,isUnauthorization:h},f),isCancel:y,isUnauthorization:h,httpCode:m.status},B=typeof _optionalChain([s, 'optionalAccess', _118 => _118.disabledToastWhenCancel])=="boolean"?_optionalChain([s, 'optionalAccess', _119 => _119.disabledToastWhenCancel]):d,de=i?i(D,s):!h;if((_optionalChain([s, 'optionalAccess', _120 => _120.infoSuccess])&&D.status||_optionalChain([s, 'optionalAccess', _121 => _121.infoError])&&!D.status)&&c&&(!y||!B)&&c(D),!de&&(!y||!_optionalChain([s, 'optionalAccess', _122 => _122.disabledHandleUnauthorized]))){let E=_optionalChain([s, 'optionalAccess', _123 => _123.onUnauthorized])||r;E&&E(D)}if(p)p(D);else return D},P=(m,p=()=>{})=>_axios2.default.create({baseURL:`${e}`,withCredentials:typeof m.withCredentials=="boolean"?m.withCredentials:l})(m).then(p).catch(f=>p(f.response,f)),A=(m,p,s,f,y)=>{let u={...{token:!0,infoError:!0,infoSuccess:!0,responseType:"json"},...y},w={"Content-Type":"application/json",...a,...u.headers};if(u.token&&(typeof u.token=="boolean"?t&&(w.Authorization=`Bearer ${t}`):u.token&&(w.Authorization=`Bearer ${u.token}`)),n&&(s=n(s)),(typeof _optionalChain([u, 'optionalAccess', _124 => _124.encryptRequest])=="boolean"?_optionalChain([u, 'optionalAccess', _125 => _125.encryptRequest]):R)&&s){let D=_optionalChain([y, 'optionalAccess', _126 => _126.passphrase])?typeof y.passphrase=="boolean"&&y.passphrase?g:y.passphrase:b;s=T(s,D)}return P({url:p,method:m,data:s,headers:w,responseType:u.responseType,signal:u.signal,withCredentials:u.withCredentials,onUploadProgress:D=>{_optionalChain([u, 'optionalAccess', _127 => _127.onUploadProgress])&&_optionalChain([u, 'optionalAccess', _128 => _128.onUploadProgress, 'call', _129 => _129(D)])}},(D,B)=>x(D,f,u,B))};return{client:P,post:(m,p,s,f)=>A("POST",`${m}`,p,s,f),put:(m,p,s,f)=>A("PUT",`${m}`,p,s,f),patch:(m,p,s,f)=>A("PATCH",`${m}`,p,s,f),delete:(m,p,s)=>A("DELETE",`${m}`,null,p,s),get:(m,p,s)=>A("GET",`${m}`,null,p,s),upload:(m,p,s,f)=>{let y=new FormData;return Object.keys(p).forEach(h=>y.append(h,p[h])),A("POST",`${m}`,y,s,{infoSuccess:!1,...f,headers:{"Content-Type":"multipart/form-data",..._optionalChain([f, 'optionalAccess', _130 => _130.headers])}})}}};function or(e,t){let[n,o]=_react.useState.call(void 0, !1),[a,r]=_react.useState.call(void 0, ),[c,i]=_react.useState.call(void 0, 0),d=_react.useRef.call(void 0, null);return _react.useEffect.call(void 0, ()=>{if(_optionalChain([t, 'optionalAccess', _131 => _131.abortOnUnmount]))return()=>{_optionalChain([d, 'access', _132 => _132.current, 'optionalAccess', _133 => _133.abort, 'call', _134 => _134()])}},[]),[async b=>{_optionalChain([d, 'access', _135 => _135.current, 'optionalAccess', _136 => _136.abort, 'call', _137 => _137()]);let T=new AbortController;d.current=T,o(!0),_optionalChain([t, 'optionalAccess', _138 => _138.beforeRequest])&&(b=_optionalChain([t, 'optionalAccess', _139 => _139.beforeRequest, 'call', _140 => _140(b)])),_optionalChain([t, 'optionalAccess', _141 => _141.logging])&&console.log("Before request",b);let C={...t,signal:T.signal,onUploadProgress:x=>{let P=Math.round(x.loaded*100/(x.total||1));i(P)}},g=q(b)?await e(b,void 0,C):await e(void 0,C);_optionalChain([t, 'optionalAccess', _142 => _142.logging])&&console.log("After response",g),r(g),o(!1),i(0),g.status&&_optionalChain([t, 'optionalAccess', _143 => _143.onSuccess])&&_optionalChain([t, 'optionalAccess', _144 => _144.onSuccess, 'call', _145 => _145(g)]),!g.status&&_optionalChain([t, 'optionalAccess', _146 => _146.onError])&&_optionalChain([t, 'optionalAccess', _147 => _147.onError, 'call', _148 => _148(g)]),_optionalChain([t, 'optionalAccess', _149 => _149.afterResponse])&&_optionalChain([t, 'optionalAccess', _150 => _150.afterResponse, 'call', _151 => _151(g)])},{...a,loading:n,abort:()=>{_optionalChain([d, 'access', _152 => _152.current, 'optionalAccess', _153 => _153.abort, 'call', _154 => _154()]),d.current=null,o(!1),i(0)},progress:c,reset:()=>{o(!1),i(0),r(null)}}]}function ir(e="vertical"){let t=_react.useRef.call(void 0, null),[n,o]=_react.useState.call(void 0, !1),[a,r]=_react.useState.call(void 0, !1),c=_react.useCallback.call(void 0, ()=>{let i=t.current;if(i)if(e==="vertical"){let d=Math.ceil(i.scrollTop+i.clientHeight),l=Math.floor(i.scrollHeight);o(i.scrollTop>0),r(d<l)}else{let d=Math.ceil(i.scrollLeft+i.clientWidth),l=Math.floor(i.scrollWidth);o(i.scrollLeft>0),r(d<l)}},[e]);return _react.useEffect.call(void 0, ()=>{let i=t.current;if(i)return c(),i.addEventListener("scroll",c),()=>i.removeEventListener("scroll",c)},[c]),{ref:t,showStartShadow:n,showEndShadow:a}}var cr=(e,t)=>F(t).useStore();var dr=(e,t)=>{let n=o=>e(o);return n.displayName=t,n},mr= exports.splitElement =(e,t)=>{let n={};n.others=[];let o=a=>{_react2.default.Children.forEach(a,r=>{if(_react2.default.isValidElement(r)){let c=r.type.displayName;if(t.includes(c))n[c]=r;else{let i=r;_optionalChain([i, 'access', _155 => _155.props, 'optionalAccess', _156 => _156.children])?o(i.props.children):n.others.push(r)}}else n.others.push(r)})};return o(e),n};exports.BgsCoreProvider = ge; exports.DataTypeEnum = ie; exports.HttpMethod = ae; exports.createApiHelper = er; exports.createElement = dr; exports.decrypt = H; exports.decryptString = re; exports.diffJson = je; exports.encrypt = I; exports.encryptString = te; exports.generateCacheKey = _; exports.generateUUID = $e; exports.getFieldValue = O; exports.isArray = ze; exports.isNotEmpty = q; exports.jsonCopy = Xe; exports.labelFormatter = X; exports.mappingUndefinedtoNull = Ve; exports.renderChildren = Je; exports.sorting = We; exports.splitElement = mr; exports.stableStringify = me; exports.summary = Ge; exports.useApiLoad = Se; exports.useApiSend = or; exports.useApiStore = cr; exports.useBgsCore = N; exports.useCrypto = M; exports.useDelay = St; exports.useFormatted = vt; exports.useInterval = Mt; exports.useKeyPress = It; exports.useScroll = ir; exports.useStorage = ne;
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } async function _asyncOptionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var _moment = require('moment'); var _moment2 = _interopRequireDefault(_moment);var _react = require('react'); var _react2 = _interopRequireDefault(_react);function $e(){let e=()=>Math.random()*16%16|0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>(t==="x"?e():e()&3|8).toString(16))}function je(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch (e2){return!1}}var Ve=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&(e[t]=null)}),e);function ze(e,t){let n=!1;return e&&typeof e=="object"&&Array.isArray(e)&&(typeof t=="number"?e.length>t&&(n=!0):n=!0),n}function q(e){return!(e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===0)}var X={camelCase:(e="")=>(e=e.split(".").map(t=>(t=t.charAt(0).toUpperCase()+t.slice(1),t)).join(" "),e=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),e.charAt(0).toUpperCase()+e.slice(1)),snackCase:(e="")=>{let n=e.replace(/_([a-z])/g,(o,a)=>a.toUpperCase()).replace(/([A-Z])/g," $1");return n=n.charAt(0).toUpperCase()+n.slice(1),n},changeAll:(e="",t=!1)=>{let n="";try{e=_optionalChain([e, 'optionalAccess', _2 => _2.split, 'call', _3 => _3("."), 'access', _4 => _4[_optionalChain([e, 'optionalAccess', _5 => _5.split, 'call', _6 => _6("."), 'optionalAccess', _7 => _7.length])-1]]),e=_optionalChain([e, 'optionalAccess', _8 => _8.split, 'call', _9 => _9("[]"), 'access', _10 => _10[_optionalChain([e, 'optionalAccess', _11 => _11.split, 'call', _12 => _12("[]"), 'optionalAccess', _13 => _13.length])-1]]),n=X.snackCase(X.camelCase(e)),t&&(n=_optionalChain([n, 'optionalAccess', _14 => _14.split, 'call', _15 => _15(" "), 'optionalAccess', _16 => _16.map, 'call', _17 => _17(o=>_optionalChain([o, 'optionalAccess', _18 => _18.length])<=3?_optionalChain([o, 'optionalAccess', _19 => _19.toUpperCase, 'call', _20 => _20()]):o), 'optionalAccess', _21 => _21.join, 'call', _22 => _22(" ")]))}catch (e3){}return _optionalChain([n, 'optionalAccess', _23 => _23.trim, 'call', _24 => _24()])}};function Je(e,t){return typeof e=="function"?e(t):e}var O=(e,t,n="")=>{if(!e)return n;if(e.hasOwnProperty(t))return e[t];let o=t.replace(/\[(\d+)\]/g,".$1").split("."),a=e;for(let r of o){if(a==null)return n;a=a[r]}return a===void 0?n:a},We= exports.sorting ={desc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(n,t):"";return a<r?1:-1}else return n<o?1:-1})),asc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(o,t):"";return a>r?1:-1}else return n>o?1:-1}))},Ge= exports.summary =(e,t)=>{Array.isArray(e)||(e=[]);let n=[];return n=e.map(o=>Number(t?O(o,t)||0:o||0)),n.reduce((o,a)=>(o||0)+(a||0),0)||0};function Xe(e){try{return e&&JSON.parse(JSON.stringify(e))}catch (e4){return e}}function me(e){let t=new WeakSet;return _nullishCoalesce(JSON.stringify(e,function(n,o){return o!==null&&typeof o=="object"?t.has(o)?void 0:(t.add(o),Object.keys(o).sort().reduce((a,r)=>(a[r]=o[r],a),{})):o}), () => (""))}function _(e,t){return me([_nullishCoalesce(t, () => ("undefined")),_nullishCoalesce(e, () => ("undefined"))])}var _jsxruntime = require('react/jsx-runtime');var Z=_react.createContext.call(void 0, void 0);function N(){let e=_react.useContext.call(void 0, Z);return e||{}}var ge=({children:e,value:t})=>{let n={...t};return _jsxruntime.jsx.call(void 0, Z.Provider,{value:n,children:e})};var _aes = require('crypto-js/aes'); var _aes2 = _interopRequireDefault(_aes);var _pbkdf2 = require('crypto-js/pbkdf2'); var _pbkdf22 = _interopRequireDefault(_pbkdf2);var _encutf8 = require('crypto-js/enc-utf8'); var _encutf82 = _interopRequireDefault(_encutf8);var _encbase64 = require('crypto-js/enc-base64'); var _encbase642 = _interopRequireDefault(_encbase64);var _libtypedarrays = require('crypto-js/lib-typedarrays'); var _libtypedarrays2 = _interopRequireDefault(_libtypedarrays);function I(e,t){let n=_libtypedarrays2.default.random(16),o=_libtypedarrays2.default.random(16),a=_pbkdf22.default.call(void 0, t,n,{keySize:256/32,iterations:1e3}),r=_aes2.default.encrypt(JSON.stringify(e),a,{iv:o}).toString();return{salt:n.toString(_encbase642.default),iv:o.toString(_encbase642.default),encrypted:r}}function L(e,t){let{salt:n,iv:o,encrypted:a}=e,r=_pbkdf22.default.call(void 0, t,_encbase642.default.parse(n),{keySize:256/32,iterations:1e3}),i=_aes2.default.decrypt(a,r,{iv:_encbase642.default.parse(o)}).toString(_encutf82.default);return JSON.parse(i)}function te(e,t){return JSON.stringify(I(e,t))}function re(e,t){return L(JSON.parse(e),t)}function M(){let{passphrase:e}=N();return{passphrase:e,encrypt(t,n){return I(t,n||e)},decrypt(t,n){return L(t,n||e)},encryptString(t,n){return te(t,n||e)},decryptString(t,n){return re(t,n||e)}}}var ne=()=>{let{encrypt:e,decrypt:t}=M(),n=_react.useCallback.call(void 0, (c,i)=>{try{let d=e(i);localStorage.setItem(c,JSON.stringify(d))}catch(d){console.error("Failed to save to storage:",d)}},[e]),o=_react.useCallback.call(void 0, c=>{try{let i=localStorage.getItem(c);return i?t(JSON.parse(i)):null}catch(i){return console.error("Failed to get from storage:",i),null}},[t]),a=c=>{let[i,d]=_react.useState.call(void 0, ()=>{try{let p=localStorage.getItem(c);return p?t(JSON.parse(p)):null}catch(p){return console.error("Failed to parse localStorage value",p),null}});return _react.useEffect.call(void 0, ()=>{let p=R=>{if(R.key===c)if(R.newValue)try{d(t(JSON.parse(R.newValue)))}catch(S){console.error("Decrypt error from storage event",S)}else d(null)};return window.addEventListener("storage",p),()=>window.removeEventListener("storage",p)},[c,t]),i},r=_react.useCallback.call(void 0, c=>{c?localStorage.removeItem(c):localStorage.clear()},[]);return{save:n,get:o,clear:r,useWatchStorage:a}};function oe(e){let t=e,n=new Set;function o(){return t}function a(i){return n.add(i),()=>n.delete(i)}function r(i){typeof i=="function"?t=i(t):t=i,n.forEach(d=>d())}function c(i){return _react.useSyncExternalStore.call(void 0, a,()=>i?i(t):t,()=>i?i(t):t)}return{getSnapshot:o,subscribe:a,setState:r,useStore:c}}var $=new Map;function F(e){return $.has(e)||$.set(e,oe([null,{}])),$.get(e)}function Se(e,t,n){let o=arguments.length===3,a=o?t:void 0,r=o?n:t,{storageKey:c,cache:i}=N(),d=ne(),[p,R]=_react.useState.call(void 0, !1),[S,b]=_react.useState.call(void 0, !1),[T,C]=_react.useState.call(void 0, ),g=_react.useRef.call(void 0, void 0),x=_react.useRef.call(void 0, null),{cacheName:P,cacheKey:A,timeout:J,timeoutUnit:W,persistence:G}=_react.useMemo.call(void 0, ()=>{let l=c?d.get(c):void 0,s=typeof _optionalChain([r, 'optionalAccess', _25 => _25.cache])=="object"?_nullishCoalesce(_optionalChain([r, 'optionalAccess', _26 => _26.cache, 'optionalAccess', _27 => _27.cacheName]), () => (e.name)):e.name,f=_({...a,session:l},typeof _optionalChain([r, 'optionalAccess', _28 => _28.cache])=="object"?_optionalChain([r, 'optionalAccess', _29 => _29.cache, 'optionalAccess', _30 => _30.cacheKey]):void 0),y=!1;typeof _optionalChain([i, 'optionalAccess', _31 => _31.persistence])=="boolean"&&(y=_optionalChain([i, 'optionalAccess', _32 => _32.persistence])),typeof _optionalChain([r, 'optionalAccess', _33 => _33.cache])=="object"&&typeof _optionalChain([r, 'optionalAccess', _34 => _34.cache, 'optionalAccess', _35 => _35.persistence])=="boolean"&&(y=_nullishCoalesce(_optionalChain([r, 'optionalAccess', _36 => _36.cache, 'optionalAccess', _37 => _37.persistence]), () => (!1)));let h=60*5,u="s";return q(_optionalChain([i, 'optionalAccess', _38 => _38.timeout]))&&(typeof _optionalChain([i, 'optionalAccess', _39 => _39.timeout])=="number"?(h=i.timeout,u="s"):typeof _optionalChain([i, 'optionalAccess', _40 => _40.timeout])=="object"&&(h=_optionalChain([i, 'optionalAccess', _41 => _41.timeout, 'access', _42 => _42.value]),u=_optionalChain([i, 'optionalAccess', _43 => _43.timeout, 'access', _44 => _44.unit]))),_optionalChain([r, 'optionalAccess', _45 => _45.cache])&&typeof r.cache!="boolean"&&(typeof r.cache.timeout=="number"?(h=r.cache.timeout,u="s"):typeof r.cache.timeout=="object"&&(h=r.cache.timeout.value,u=r.cache.timeout.unit)),{cacheName:s,cacheKey:f,timeout:h,timeoutUnit:u,persistence:y}},[_optionalChain([r, 'optionalAccess', _46 => _46.cache]),c,i]);_react.useEffect.call(void 0, ()=>{let l=JSON.stringify(q(g.current)?g.current:""),s=JSON.stringify(q(a)?a:""),f=g.current===void 0;(l!==s||f)&&!_optionalChain([r, 'optionalAccess', _47 => _47.hold])&&(C(null),U(),g.current=a),_optionalChain([r, 'optionalAccess', _48 => _48.onChange])&&_optionalChain([r, 'optionalAccess', _49 => _49.onChange, 'call', _50 => _50(a,m)])},[a,_optionalChain([r, 'optionalAccess', _51 => _51.hold]),..._optionalChain([r, 'optionalAccess', _52 => _52.trigger])||[]]),_react.useEffect.call(void 0, ()=>{let l=async()=>{!G&&P&&A&&(await caches.open(P)).delete(A)};return window.addEventListener("beforeunload",l),()=>{window.removeEventListener("beforeunload",l),_optionalChain([x, 'access', _53 => _53.current, 'optionalAccess', _54 => _54.abort, 'call', _55 => _55()])}},[]);let U=_react.useCallback.call(void 0, async l=>{let s=a;if(_optionalChain([r, 'optionalAccess', _56 => _56.hold])&&_optionalChain([r, 'optionalAccess', _57 => _57.logging])&&console.log("Hold active"),_optionalChain([r, 'optionalAccess', _58 => _58.beforeRequest])&&(s=_optionalChain([r, 'optionalAccess', _59 => _59.beforeRequest, 'call', _60 => _60(a)])),_optionalChain([r, 'optionalAccess', _61 => _61.cache])&&!l&&!S){R(!0),_optionalChain([r, 'optionalAccess', _62 => _62.onBeforeRequest])&&_optionalChain([r, 'optionalAccess', _63 => _63.onBeforeRequest, 'call', _64 => _64(a)]);let f=await caches.open(P),h=awaitawait _asyncOptionalChain([(await f.match(A)), 'optionalAccess', async _65 => _65.json, 'call', async _66 => _66()]);if(h){let{data:u,expired:w}=h;if(_moment2.default.call(void 0, ).isAfter(w))await f.delete(A);else{_optionalChain([r, 'optionalAccess', _67 => _67.afterResponse])&&_optionalChain([u, 'optionalAccess', _68 => _68.data])&&(u.data=_optionalChain([r, 'optionalAccess', _69 => _69.afterResponse, 'call', _70 => _70(u.data)])),_optionalChain([r, 'optionalAccess', _71 => _71.logging])&&console.log("After request: Using Cache",u),_optionalChain([r, 'optionalAccess', _72 => _72.onAfterResponse])&&_optionalChain([r, 'optionalAccess', _73 => _73.onAfterResponse, 'call', _74 => _74(u)]),R(!1),C(u);return}}}if(typeof e=="function"){_optionalChain([x, 'access', _75 => _75.current, 'optionalAccess', _76 => _76.abort, 'call', _77 => _77()]);let f=new AbortController;x.current=f,R(!0),_optionalChain([r, 'optionalAccess', _78 => _78.logging])&&console.log("Before request",a),_optionalChain([r, 'optionalAccess', _79 => _79.onBeforeRequest])&&_optionalChain([r, 'optionalAccess', _80 => _80.onBeforeRequest, 'call', _81 => _81(a)]);let y=o?await e(s,void 0,{...r,signal:f.signal}):await e(void 0,{...r,signal:f.signal});if(_optionalChain([r, 'optionalAccess', _82 => _82.afterResponse])&&_optionalChain([y, 'optionalAccess', _83 => _83.data])&&(y.data=_optionalChain([r, 'optionalAccess', _84 => _84.afterResponse, 'call', _85 => _85(y.data)])),_optionalChain([r, 'optionalAccess', _86 => _86.logging])&&console.log("After request",y),_optionalChain([r, 'optionalAccess', _87 => _87.onAfterResponse])&&_optionalChain([r, 'optionalAccess', _88 => _88.onAfterResponse, 'call', _89 => _89(y)]),R(!1),C(y),b(!1),_optionalChain([r, 'optionalAccess', _90 => _90.cache])&&y.status){let h=_moment2.default.call(void 0, ).add(J,W).toISOString(),u={data:y,expired:h},w=await caches.open(P),v=new Response(JSON.stringify(u));await w.put(A,v)}}},[a,e,r]);_react.useEffect.call(void 0, ()=>{if(_optionalChain([r, 'optionalAccess', _91 => _91.refreshInterval])){let l=typeof r.refreshInterval=="number"?r.refreshInterval:r.refreshInterval.value,s=typeof r.refreshInterval=="number"?"s":r.refreshInterval.unit,f=setInterval(()=>{U()},_moment2.default.duration(l,s).asMilliseconds());return()=>clearInterval(f)}return()=>{}},[_optionalChain([r, 'optionalAccess', _92 => _92.refreshInterval]),U]),_react.useEffect.call(void 0, ()=>{if(!_optionalChain([r, 'optionalAccess', _93 => _93.refetchOnWindowFocus]))return;let l=()=>{U()};return window.addEventListener("focus",l),()=>{window.removeEventListener("focus",l)}},[_optionalChain([r, 'optionalAccess', _94 => _94.refetchOnWindowFocus]),U]);let m={...T,loading:p,refresh:U,abort:()=>{_optionalChain([x, 'access', _95 => _95.current, 'optionalAccess', _96 => _96.abort, 'call', _97 => _97()]),x.current=null,R(!1),b(!0)},clear:()=>{R(!1),C(null)},response:T,isCancel:S,clone:(l,s)=>Se(e,l,s)};return _react.useEffect.call(void 0, ()=>{_optionalChain([r, 'optionalAccess', _98 => _98.storeName])&&F(_optionalChain([r, 'optionalAccess', _99 => _99.storeName])).setState([_optionalChain([T, 'optionalAccess', _100 => _100.data]),m])},[T,m,_optionalChain([r, 'optionalAccess', _101 => _101.storeName])]),[_optionalChain([T, 'optionalAccess', _102 => _102.data]),m]}async function St(e,t=()=>{}){let n=e*1e3;return new Promise(o=>{let a=0,r=setInterval(()=>{t(),a===9&&clearInterval(r)},1e3);setTimeout(async()=>{await t(),o(!0)},n)})}var ae=(r=>(r.POST="POST",r.PUT="PUT",r.PATCH="PATCH",r.DELETE="DELETE",r.GET="GET",r))(ae||{}),ie= exports.DataTypeEnum =(s=>(s.number="number",s.currency="currency",s.percent="percent",s.date="date",s.dateTime="dateTime",s.month="month",s.year="year",s.time="time",s.timestamp="timestamp",s.string="string",s.textarea="textarea",s.code="code",s.password="password",s.boolean="boolean",s.toggle="toggle",s.email="email",s.phone="phone",s.url="url",s.json="json",s.file="file",s.image="image",s.array="array",s.object="object",s.enum="enum",s.user="user",s.department="department",s.status="status",s))(ie||{});var Et=(e,t,n)=>{let{format:o}=N();return t==="number"?we(e,{thouSep:o.number.thouSep,decDigits:o.number.decDigits,decSep:o.number.decSep,...n}):["date","dateTime","month","year","time"].includes(t)?Ue(e,{display:_optionalChain([o, 'access', _103 => _103[t], 'optionalAccess', _104 => _104.display]),value:_optionalChain([o, 'access', _105 => _105[t], 'optionalAccess', _106 => _106.value]),...n}):t==="boolean"?Oe(e,n):t==="string"?qe(e,n):_nullishCoalesce(_optionalChain([e, 'optionalAccess', _107 => _107.toString, 'call', _108 => _108()]), () => (""))};function Oe(e,t){let n=typeof e=="string"?e==="true":!!e,o=_nullishCoalesce(_optionalChain([t, 'optionalAccess', _109 => _109.trueLabel]), () => ("Yes")),a=_nullishCoalesce(_optionalChain([t, 'optionalAccess', _110 => _110.falseLabel]), () => ("No"));return n?o:a}function qe(e,t){if(!q(e))return"";let n=String(e);if(_optionalChain([t, 'optionalAccess', _111 => _111.textTransform]))switch(_optionalChain([t, 'optionalAccess', _112 => _112.textTransform])){case"capitalize":n=n.charAt(0).toUpperCase()+n.slice(1);break;case"uppercase":n=n.toUpperCase();break;case"lowercase":n=n.toLowerCase();break}return _optionalChain([t, 'optionalAccess', _113 => _113.ellipsis])&&n.length>t.ellipsis&&(n=n.slice(0,t.ellipsis)+"..."),n}function we(e,{thouSep:t,decSep:n,decDigits:o,method:a}){if(e==null||isNaN(Number(e)))return"";let r=typeof e=="string"?parseFloat(e):e;if(a)if(typeof o=="number"){let p=Math.pow(10,o);r=Math[a](r*p)/p}else r=Math[a](r);else if(typeof o=="number"){let p=Math.pow(10,o);r=Math.floor(r*p)/p}let c=0;if(o==="auto"){let p=r.toString(),R=p.indexOf(".");R!==-1&&(c=p.length-R-1)}let i={style:"decimal",useGrouping:!0,minimumFractionDigits:o==="auto"?c:o||0,maximumFractionDigits:o==="auto"?c:o||0,minimumIntegerDigits:1};return r.toLocaleString("en-US",i).replace(/\./g,"decSep").replace(/,/g,"thouSep").replace(/decSep/g,n).replace(/thouSep/g,t)}function Ue(e,{display:t,value:n}){if(!q(e))return e;let o=_moment2.default.call(void 0, e,n);return o.isValid()?o.format(t):e}function Ft(e,{interval:t,lead:n}){let o=_react.useRef.call(void 0, null);_react.useEffect.call(void 0, ()=>{o.current=e},[e]),_react.useEffect.call(void 0, ()=>{let a=()=>o.current();if(n&&a(),t!==null){let r=setInterval(a,t);return()=>clearInterval(r)}},[t])}function Lt(e,t,n){let[o,a]=_react.useState.call(void 0, !1),r=(p,R)=>typeof e=="string"&&p===e||typeof e=="number"&&R===e,c=p=>p!==null&&(["INPUT","TEXTAREA","SELECT","BUTTON"].includes(p.tagName)||p.hasAttribute("contentEditable")),i=p=>{let{key:R,keyCode:S}=p,b=p.ctrlKey,T=p.altKey,C=p.shiftKey;if(!c(document.activeElement))if(t)if(typeof t=="string")r(R,S)&&(t==="ctrl"&&b||t==="alt"&&T||t==="shift"&&C)&&(p.preventDefault(),n&&p.stopPropagation(),a(!o));else{let g=t.every(x=>x==="ctrl"?b:x==="alt"?T:x==="shift"?C:!1);r(R,S)&&g&&(p.preventDefault(),n&&p.stopPropagation(),a(!o))}else r(R,S)&&(p.preventDefault(),n&&p.stopPropagation(),a(!o))},d=({key:p,keyCode:R})=>{r(p,R)&&a(!1)};return _react.useEffect.call(void 0, ()=>(window.addEventListener("keydown",i),window.addEventListener("keyup",d),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",d)}),[]),o}var _axios = require('axios'); var _axios2 = _interopRequireDefault(_axios);var tr=({url:e,token:t,beforeRequest:n,onCallback:o,headers:a,onUnauthorized:r,handleToast:c,handleAuthorization:i,disabledToastWhenCancel:d,withCredentials:p,encryptRequest:R,encryptResponse:S,passphrase:b})=>{let{encrypt:T,decrypt:C,passphrase:g}=M(),x=(m,l,s,f)=>{let y=_optionalChain([f, 'optionalAccess', _114 => _114.code])==="ERR_CANCELED",h=m.status===401,u=_optionalChain([m, 'optionalAccess', _115 => _115.data]);if((typeof _optionalChain([s, 'optionalAccess', _116 => _116.encryptResponse])=="boolean"?_optionalChain([s, 'optionalAccess', _117 => _117.encryptResponse]):S)&&u){let E=_optionalChain([s, 'optionalAccess', _118 => _118.passphrase])?typeof s.passphrase=="boolean"&&s.passphrase?g:s.passphrase:b;try{u=C(u,E)}catch (e5){try{u=C(u,g)}catch (e6){}}}let D={...o({...m,data:u,isCancel:y,isUnauthorization:h},f),isCancel:y,isUnauthorization:h,httpCode:m.status},B=typeof _optionalChain([s, 'optionalAccess', _119 => _119.disabledToastWhenCancel])=="boolean"?_optionalChain([s, 'optionalAccess', _120 => _120.disabledToastWhenCancel]):d,de=i?i(D,s):!h;if((_optionalChain([s, 'optionalAccess', _121 => _121.infoSuccess])&&D.status||_optionalChain([s, 'optionalAccess', _122 => _122.infoError])&&!D.status)&&c&&(!y||!B)&&c(D),!de&&(!y||!_optionalChain([s, 'optionalAccess', _123 => _123.disabledHandleUnauthorized]))){let E=_optionalChain([s, 'optionalAccess', _124 => _124.onUnauthorized])||r;E&&E(D)}if(l)l(D);else return D},P=(m,l=()=>{})=>_axios2.default.create({baseURL:`${e}`,withCredentials:typeof m.withCredentials=="boolean"?m.withCredentials:p})(m).then(l).catch(f=>l(f.response,f)),A=(m,l,s,f,y)=>{let u={...{token:!0,infoError:!0,infoSuccess:!0,responseType:"json"},...y},w={"Content-Type":"application/json",...a,...u.headers};if(u.token&&(typeof u.token=="boolean"?t&&(w.Authorization=`Bearer ${t}`):u.token&&(w.Authorization=`Bearer ${u.token}`)),n&&(s=n(s)),(typeof _optionalChain([u, 'optionalAccess', _125 => _125.encryptRequest])=="boolean"?_optionalChain([u, 'optionalAccess', _126 => _126.encryptRequest]):R)&&s){let D=_optionalChain([y, 'optionalAccess', _127 => _127.passphrase])?typeof y.passphrase=="boolean"&&y.passphrase?g:y.passphrase:b;s=T(s,D)}return P({url:l,method:m,data:s,headers:w,responseType:u.responseType,signal:u.signal,withCredentials:u.withCredentials,onUploadProgress:D=>{_optionalChain([u, 'optionalAccess', _128 => _128.onUploadProgress])&&_optionalChain([u, 'optionalAccess', _129 => _129.onUploadProgress, 'call', _130 => _130(D)])}},(D,B)=>x(D,f,u,B))};return{client:P,post:(m,l,s,f)=>A("POST",`${m}`,l,s,f),put:(m,l,s,f)=>A("PUT",`${m}`,l,s,f),patch:(m,l,s,f)=>A("PATCH",`${m}`,l,s,f),delete:(m,l,s)=>A("DELETE",`${m}`,null,l,s),get:(m,l,s)=>A("GET",`${m}`,null,l,s),upload:(m,l,s,f)=>{let y=new FormData;return Object.keys(l).forEach(h=>y.append(h,l[h])),A("POST",`${m}`,y,s,{infoSuccess:!1,...f,headers:{"Content-Type":"multipart/form-data",..._optionalChain([f, 'optionalAccess', _131 => _131.headers])}})}}};function sr(e,t){let[n,o]=_react.useState.call(void 0, !1),[a,r]=_react.useState.call(void 0, ),[c,i]=_react.useState.call(void 0, 0),d=_react.useRef.call(void 0, null);return _react.useEffect.call(void 0, ()=>{if(_optionalChain([t, 'optionalAccess', _132 => _132.abortOnUnmount]))return()=>{_optionalChain([d, 'access', _133 => _133.current, 'optionalAccess', _134 => _134.abort, 'call', _135 => _135()])}},[]),[async b=>{_optionalChain([d, 'access', _136 => _136.current, 'optionalAccess', _137 => _137.abort, 'call', _138 => _138()]);let T=new AbortController;d.current=T,o(!0),_optionalChain([t, 'optionalAccess', _139 => _139.beforeRequest])&&(b=_optionalChain([t, 'optionalAccess', _140 => _140.beforeRequest, 'call', _141 => _141(b)])),_optionalChain([t, 'optionalAccess', _142 => _142.logging])&&console.log("Before request",b);let C={...t,signal:T.signal,onUploadProgress:x=>{let P=Math.round(x.loaded*100/(x.total||1));i(P)}},g=q(b)?await e(b,void 0,C):await e(void 0,C);_optionalChain([t, 'optionalAccess', _143 => _143.logging])&&console.log("After response",g),r(g),o(!1),i(0),g.status&&_optionalChain([t, 'optionalAccess', _144 => _144.onSuccess])&&_optionalChain([t, 'optionalAccess', _145 => _145.onSuccess, 'call', _146 => _146(g)]),!g.status&&_optionalChain([t, 'optionalAccess', _147 => _147.onError])&&_optionalChain([t, 'optionalAccess', _148 => _148.onError, 'call', _149 => _149(g)]),_optionalChain([t, 'optionalAccess', _150 => _150.afterResponse])&&_optionalChain([t, 'optionalAccess', _151 => _151.afterResponse, 'call', _152 => _152(g)])},{...a,loading:n,abort:()=>{_optionalChain([d, 'access', _153 => _153.current, 'optionalAccess', _154 => _154.abort, 'call', _155 => _155()]),d.current=null,o(!1),i(0)},progress:c,reset:()=>{o(!1),i(0),r(null)}}]}function pr(e="vertical"){let t=_react.useRef.call(void 0, null),[n,o]=_react.useState.call(void 0, !1),[a,r]=_react.useState.call(void 0, !1),c=_react.useCallback.call(void 0, ()=>{let i=t.current;if(i)if(e==="vertical"){let d=Math.ceil(i.scrollTop+i.clientHeight),p=Math.floor(i.scrollHeight);o(i.scrollTop>0),r(d<p)}else{let d=Math.ceil(i.scrollLeft+i.clientWidth),p=Math.floor(i.scrollWidth);o(i.scrollLeft>0),r(d<p)}},[e]);return _react.useEffect.call(void 0, ()=>{let i=t.current;if(i)return c(),i.addEventListener("scroll",c),()=>i.removeEventListener("scroll",c)},[c]),{ref:t,showStartShadow:n,showEndShadow:a}}var ur=(e,t)=>F(t).useStore();var mr=(e,t)=>{let n=o=>e(o);return n.displayName=t,n},yr= exports.splitElement =(e,t)=>{let n={};n.others=[];let o=a=>{_react2.default.Children.forEach(a,r=>{if(_react2.default.isValidElement(r)){let c=r.type.displayName;if(t.includes(c))n[c]=r;else{let i=r;_optionalChain([i, 'access', _156 => _156.props, 'optionalAccess', _157 => _157.children])?o(i.props.children):n.others.push(r)}}else n.others.push(r)})};return o(e),n};exports.BgsCoreProvider = ge; exports.DataTypeEnum = ie; exports.HttpMethod = ae; exports.createApiHelper = tr; exports.createElement = mr; exports.decrypt = L; exports.decryptString = re; exports.diffJson = je; exports.encrypt = I; exports.encryptString = te; exports.generateCacheKey = _; exports.generateUUID = $e; exports.getFieldValue = O; exports.isArray = ze; exports.isNotEmpty = q; exports.jsonCopy = Xe; exports.labelFormatter = X; exports.mappingUndefinedtoNull = Ve; exports.renderChildren = Je; exports.sorting = We; exports.splitElement = yr; exports.stableStringify = me; exports.summary = Ge; exports.useApiLoad = Se; exports.useApiSend = sr; exports.useApiStore = ur; exports.useBgsCore = N; exports.useCrypto = M; exports.useDelay = St; exports.useFormatted = Et; exports.useInterval = Ft; exports.useKeyPress = Lt; exports.useScroll = pr; exports.useStorage = ne;
package/dist/index.d.cts CHANGED
@@ -338,6 +338,7 @@ type NestedKeyOf<T> = T extends object ? T extends Array<infer U> ? `${number}`
338
338
  }[keyof T] : never;
339
339
  type PathValue<T, P extends string> = P extends `${infer K}[${infer I}].${infer R}` ? K extends keyof T ? T[K] extends Array<infer U> ? PathValue<U, R> : never : never : P extends `${infer K}[${infer I}]` ? K extends keyof T ? T[K] extends Array<infer U> ? U : never : never : P extends `${infer K}.${infer R}` ? K extends keyof T ? PathValue<T[K], R> : never : P extends keyof T ? T[P] : never;
340
340
  type SelectedNested<T> = Partial<Record<NestedKeyOf<T>, any>>;
341
+ type TextTransform = "capitalize" | "uppercase" | "lowercase";
341
342
 
342
343
  declare function useApiLoad<DRes>(api: ApiMethodVoid<DRes>, options?: Partial<UseCallOptionsProps<undefined, DRes>>): UseCallReturnType<undefined, DRes>;
343
344
  declare function useApiLoad<DReq, DRes>(api: ApiMethod<DReq, DRes>, data: DReq, options?: Partial<UseCallOptionsProps<DReq, DRes>>): UseCallReturnType<DReq, DRes>;
@@ -366,7 +367,7 @@ type OptionsBoolean = {
366
367
  };
367
368
  type OptionsString = {
368
369
  dataType: Extract<DataType, "string">;
369
- capitalize?: boolean;
370
+ textTransform?: TextTransform;
370
371
  ellipsis?: number;
371
372
  };
372
373
  type UseFormattedOptions<T extends DataType> = T extends "number" ? Partial<OptionsNumber> : T extends DataTypeDateGroup ? Partial<OptionsDate> : T extends "boolean" ? Partial<OptionsBoolean> : T extends "string" ? Partial<OptionsString> : never;
@@ -485,4 +486,4 @@ interface BgsCoreProviderProps {
485
486
  }
486
487
  declare const BgsCoreProvider: ({ children, value: options }: PropsWithChildren<BgsCoreProviderProps>) => react_jsx_runtime.JSX.Element;
487
488
 
488
- export { type ApiActionState, type ApiDefaultFetch, type ApiDefaultMethod, type ApiMethod, type ApiMethodVoid, type ApiResponse, type BgsCoreProps, BgsCoreProvider, type CacheData, type CacheProps, type CallbackHelper, type Children, type ClientCallback, type CombinationType, type CreateElementProps, type DataType, DataTypeEnum, type EncryptedPayload, HttpMethod, type NestedKeyOf, type OptionsCallReturn, type OptionsHelper, type OptionsNumberProps, type PaginationMeta, type PathValue, type ResponseType, type SelectedNested, type SplitElementResult, type UseApiSendProps, type UseApiSendReturnType, type UseCallOptionsProps, type UseCallReturnType, type UseHelperProps, createApiHelper, createElement, decrypt, decryptString, diffJson, encrypt, encryptString, generateCacheKey, generateUUID, getFieldValue, isArray, isNotEmpty, jsonCopy, labelFormatter, mappingUndefinedtoNull, renderChildren, sorting, splitElement, stableStringify, summary, useApiLoad, useApiSend, useApiStore, useBgsCore, useCrypto, useDelay, useFormatted, useInterval, useKeyPress, useScroll, useStorage };
489
+ export { type ApiActionState, type ApiDefaultFetch, type ApiDefaultMethod, type ApiMethod, type ApiMethodVoid, type ApiResponse, type BgsCoreProps, BgsCoreProvider, type CacheData, type CacheProps, type CallbackHelper, type Children, type ClientCallback, type CombinationType, type CreateElementProps, type DataType, DataTypeEnum, type EncryptedPayload, HttpMethod, type NestedKeyOf, type OptionsCallReturn, type OptionsHelper, type OptionsNumberProps, type PaginationMeta, type PathValue, type ResponseType, type SelectedNested, type SplitElementResult, type TextTransform, type UseApiSendProps, type UseApiSendReturnType, type UseCallOptionsProps, type UseCallReturnType, type UseHelperProps, createApiHelper, createElement, decrypt, decryptString, diffJson, encrypt, encryptString, generateCacheKey, generateUUID, getFieldValue, isArray, isNotEmpty, jsonCopy, labelFormatter, mappingUndefinedtoNull, renderChildren, sorting, splitElement, stableStringify, summary, useApiLoad, useApiSend, useApiStore, useBgsCore, useCrypto, useDelay, useFormatted, useInterval, useKeyPress, useScroll, useStorage };
package/dist/index.d.ts CHANGED
@@ -338,6 +338,7 @@ type NestedKeyOf<T> = T extends object ? T extends Array<infer U> ? `${number}`
338
338
  }[keyof T] : never;
339
339
  type PathValue<T, P extends string> = P extends `${infer K}[${infer I}].${infer R}` ? K extends keyof T ? T[K] extends Array<infer U> ? PathValue<U, R> : never : never : P extends `${infer K}[${infer I}]` ? K extends keyof T ? T[K] extends Array<infer U> ? U : never : never : P extends `${infer K}.${infer R}` ? K extends keyof T ? PathValue<T[K], R> : never : P extends keyof T ? T[P] : never;
340
340
  type SelectedNested<T> = Partial<Record<NestedKeyOf<T>, any>>;
341
+ type TextTransform = "capitalize" | "uppercase" | "lowercase";
341
342
 
342
343
  declare function useApiLoad<DRes>(api: ApiMethodVoid<DRes>, options?: Partial<UseCallOptionsProps<undefined, DRes>>): UseCallReturnType<undefined, DRes>;
343
344
  declare function useApiLoad<DReq, DRes>(api: ApiMethod<DReq, DRes>, data: DReq, options?: Partial<UseCallOptionsProps<DReq, DRes>>): UseCallReturnType<DReq, DRes>;
@@ -366,7 +367,7 @@ type OptionsBoolean = {
366
367
  };
367
368
  type OptionsString = {
368
369
  dataType: Extract<DataType, "string">;
369
- capitalize?: boolean;
370
+ textTransform?: TextTransform;
370
371
  ellipsis?: number;
371
372
  };
372
373
  type UseFormattedOptions<T extends DataType> = T extends "number" ? Partial<OptionsNumber> : T extends DataTypeDateGroup ? Partial<OptionsDate> : T extends "boolean" ? Partial<OptionsBoolean> : T extends "string" ? Partial<OptionsString> : never;
@@ -485,4 +486,4 @@ interface BgsCoreProviderProps {
485
486
  }
486
487
  declare const BgsCoreProvider: ({ children, value: options }: PropsWithChildren<BgsCoreProviderProps>) => react_jsx_runtime.JSX.Element;
487
488
 
488
- export { type ApiActionState, type ApiDefaultFetch, type ApiDefaultMethod, type ApiMethod, type ApiMethodVoid, type ApiResponse, type BgsCoreProps, BgsCoreProvider, type CacheData, type CacheProps, type CallbackHelper, type Children, type ClientCallback, type CombinationType, type CreateElementProps, type DataType, DataTypeEnum, type EncryptedPayload, HttpMethod, type NestedKeyOf, type OptionsCallReturn, type OptionsHelper, type OptionsNumberProps, type PaginationMeta, type PathValue, type ResponseType, type SelectedNested, type SplitElementResult, type UseApiSendProps, type UseApiSendReturnType, type UseCallOptionsProps, type UseCallReturnType, type UseHelperProps, createApiHelper, createElement, decrypt, decryptString, diffJson, encrypt, encryptString, generateCacheKey, generateUUID, getFieldValue, isArray, isNotEmpty, jsonCopy, labelFormatter, mappingUndefinedtoNull, renderChildren, sorting, splitElement, stableStringify, summary, useApiLoad, useApiSend, useApiStore, useBgsCore, useCrypto, useDelay, useFormatted, useInterval, useKeyPress, useScroll, useStorage };
489
+ export { type ApiActionState, type ApiDefaultFetch, type ApiDefaultMethod, type ApiMethod, type ApiMethodVoid, type ApiResponse, type BgsCoreProps, BgsCoreProvider, type CacheData, type CacheProps, type CallbackHelper, type Children, type ClientCallback, type CombinationType, type CreateElementProps, type DataType, DataTypeEnum, type EncryptedPayload, HttpMethod, type NestedKeyOf, type OptionsCallReturn, type OptionsHelper, type OptionsNumberProps, type PaginationMeta, type PathValue, type ResponseType, type SelectedNested, type SplitElementResult, type TextTransform, type UseApiSendProps, type UseApiSendReturnType, type UseCallOptionsProps, type UseCallReturnType, type UseHelperProps, createApiHelper, createElement, decrypt, decryptString, diffJson, encrypt, encryptString, generateCacheKey, generateUUID, getFieldValue, isArray, isNotEmpty, jsonCopy, labelFormatter, mappingUndefinedtoNull, renderChildren, sorting, splitElement, stableStringify, summary, useApiLoad, useApiSend, useApiStore, useBgsCore, useCrypto, useDelay, useFormatted, useInterval, useKeyPress, useScroll, useStorage };
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- import j from"moment";import{useCallback as De,useEffect as k,useMemo as Ae,useRef as se,useState as V}from"react";function $e(){let e=()=>Math.random()*16%16|0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>(t==="x"?e():e()&3|8).toString(16))}function je(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch{return!1}}var Ve=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&(e[t]=null)}),e);function ze(e,t){let n=!1;return e&&typeof e=="object"&&Array.isArray(e)&&(typeof t=="number"?e.length>t&&(n=!0):n=!0),n}function q(e){return!(e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===0)}var X={camelCase:(e="")=>(e=e.split(".").map(t=>(t=t.charAt(0).toUpperCase()+t.slice(1),t)).join(" "),e=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),e.charAt(0).toUpperCase()+e.slice(1)),snackCase:(e="")=>{let n=e.replace(/_([a-z])/g,(o,a)=>a.toUpperCase()).replace(/([A-Z])/g," $1");return n=n.charAt(0).toUpperCase()+n.slice(1),n},changeAll:(e="",t=!1)=>{let n="";try{e=e?.split(".")[e?.split(".")?.length-1],e=e?.split("[]")[e?.split("[]")?.length-1],n=X.snackCase(X.camelCase(e)),t&&(n=n?.split(" ")?.map(o=>o?.length<=3?o?.toUpperCase():o)?.join(" "))}catch{}return n?.trim()}};function Je(e,t){return typeof e=="function"?e(t):e}var O=(e,t,n="")=>{if(!e)return n;if(e.hasOwnProperty(t))return e[t];let o=t.replace(/\[(\d+)\]/g,".$1").split("."),a=e;for(let r of o){if(a==null)return n;a=a[r]}return a===void 0?n:a},We={desc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(n,t):"";return a<r?1:-1}else return n<o?1:-1})),asc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(o,t):"";return a>r?1:-1}else return n>o?1:-1}))},Ge=(e,t)=>{Array.isArray(e)||(e=[]);let n=[];return n=e.map(o=>Number(t?O(o,t)||0:o||0)),n.reduce((o,a)=>(o||0)+(a||0),0)||0};function Xe(e){try{return e&&JSON.parse(JSON.stringify(e))}catch{return e}}function me(e){let t=new WeakSet;return JSON.stringify(e,function(n,o){return o!==null&&typeof o=="object"?t.has(o)?void 0:(t.add(o),Object.keys(o).sort().reduce((a,r)=>(a[r]=o[r],a),{})):o})??""}function _(e,t){return me([t??"undefined",e??"undefined"])}import{createContext as ye,useContext as Re}from"react";import{jsx as he}from"react/jsx-runtime";var Z=ye(void 0);function N(){let e=Re(Z);return e||{}}var ge=({children:e,value:t})=>{let n={...t};return he(Z.Provider,{value:n,children:e})};import{useCallback as L,useEffect as xe,useState as Te}from"react";import Q from"crypto-js/aes";import ee from"crypto-js/pbkdf2";import be from"crypto-js/enc-utf8";import K from"crypto-js/enc-base64";import Y from"crypto-js/lib-typedarrays";function I(e,t){let n=Y.random(16),o=Y.random(16),a=ee(t,n,{keySize:256/32,iterations:1e3}),r=Q.encrypt(JSON.stringify(e),a,{iv:o}).toString();return{salt:n.toString(K),iv:o.toString(K),encrypted:r}}function H(e,t){let{salt:n,iv:o,encrypted:a}=e,r=ee(t,K.parse(n),{keySize:256/32,iterations:1e3}),i=Q.decrypt(a,r,{iv:K.parse(o)}).toString(be);return JSON.parse(i)}function te(e,t){return JSON.stringify(I(e,t))}function re(e,t){return H(JSON.parse(e),t)}function M(){let{passphrase:e}=N();return{passphrase:e,encrypt(t,n){return I(t,n||e)},decrypt(t,n){return H(t,n||e)},encryptString(t,n){return te(t,n||e)},decryptString(t,n){return re(t,n||e)}}}var ne=()=>{let{encrypt:e,decrypt:t}=M(),n=L((c,i)=>{try{let d=e(i);localStorage.setItem(c,JSON.stringify(d))}catch(d){console.error("Failed to save to storage:",d)}},[e]),o=L(c=>{try{let i=localStorage.getItem(c);return i?t(JSON.parse(i)):null}catch(i){return console.error("Failed to get from storage:",i),null}},[t]),a=c=>{let[i,d]=Te(()=>{try{let l=localStorage.getItem(c);return l?t(JSON.parse(l)):null}catch(l){return console.error("Failed to parse localStorage value",l),null}});return xe(()=>{let l=R=>{if(R.key===c)if(R.newValue)try{d(t(JSON.parse(R.newValue)))}catch(S){console.error("Decrypt error from storage event",S)}else d(null)};return window.addEventListener("storage",l),()=>window.removeEventListener("storage",l)},[c,t]),i},r=L(c=>{c?localStorage.removeItem(c):localStorage.clear()},[]);return{save:n,get:o,clear:r,useWatchStorage:a}};import{useSyncExternalStore as Ce}from"react";function oe(e){let t=e,n=new Set;function o(){return t}function a(i){return n.add(i),()=>n.delete(i)}function r(i){typeof i=="function"?t=i(t):t=i,n.forEach(d=>d())}function c(i){return Ce(a,()=>i?i(t):t,()=>i?i(t):t)}return{getSnapshot:o,subscribe:a,setState:r,useStore:c}}var $=new Map;function F(e){return $.has(e)||$.set(e,oe([null,{}])),$.get(e)}function Se(e,t,n){let o=arguments.length===3,a=o?t:void 0,r=o?n:t,{storageKey:c,cache:i}=N(),d=ne(),[l,R]=V(!1),[S,b]=V(!1),[T,C]=V(),g=se(void 0),x=se(null),{cacheName:P,cacheKey:A,timeout:J,timeoutUnit:W,persistence:G}=Ae(()=>{let p=c?d.get(c):void 0,s=typeof r?.cache=="object"?r?.cache?.cacheName??e.name:e.name,f=_({...a,session:p},typeof r?.cache=="object"?r?.cache?.cacheKey:void 0),y=!1;typeof i?.persistence=="boolean"&&(y=i?.persistence),typeof r?.cache=="object"&&typeof r?.cache?.persistence=="boolean"&&(y=r?.cache?.persistence??!1);let h=60*5,u="s";return q(i?.timeout)&&(typeof i?.timeout=="number"?(h=i.timeout,u="s"):typeof i?.timeout=="object"&&(h=i?.timeout.value,u=i?.timeout.unit)),r?.cache&&typeof r.cache!="boolean"&&(typeof r.cache.timeout=="number"?(h=r.cache.timeout,u="s"):typeof r.cache.timeout=="object"&&(h=r.cache.timeout.value,u=r.cache.timeout.unit)),{cacheName:s,cacheKey:f,timeout:h,timeoutUnit:u,persistence:y}},[r?.cache,c,i]);k(()=>{let p=JSON.stringify(q(g.current)?g.current:""),s=JSON.stringify(q(a)?a:""),f=g.current===void 0;(p!==s||f)&&!r?.hold&&(C(null),U(),g.current=a),r?.onChange&&r?.onChange(a,m)},[a,r?.hold,...r?.trigger||[]]),k(()=>{let p=async()=>{!G&&P&&A&&(await caches.open(P)).delete(A)};return window.addEventListener("beforeunload",p),()=>{window.removeEventListener("beforeunload",p),x.current?.abort()}},[]);let U=De(async p=>{let s=a;if(r?.hold&&r?.logging&&console.log("Hold active"),r?.beforeRequest&&(s=r?.beforeRequest(a)),r?.cache&&!p&&!S){R(!0),r?.onBeforeRequest&&r?.onBeforeRequest(a);let f=await caches.open(P),h=await(await f.match(A))?.json();if(h){let{data:u,expired:w}=h;if(j().isAfter(w))await f.delete(A);else{r?.afterResponse&&u?.data&&(u.data=r?.afterResponse(u.data)),r?.logging&&console.log("After request: Using Cache",u),r?.onAfterResponse&&r?.onAfterResponse(u),R(!1),C(u);return}}}if(typeof e=="function"){x.current?.abort();let f=new AbortController;x.current=f,R(!0),r?.logging&&console.log("Before request",a),r?.onBeforeRequest&&r?.onBeforeRequest(a);let y=o?await e(s,void 0,{...r,signal:f.signal}):await e(void 0,{...r,signal:f.signal});if(r?.afterResponse&&y?.data&&(y.data=r?.afterResponse(y.data)),r?.logging&&console.log("After request",y),r?.onAfterResponse&&r?.onAfterResponse(y),R(!1),C(y),b(!1),r?.cache&&y.status){let h=j().add(J,W).toISOString(),u={data:y,expired:h},w=await caches.open(P),v=new Response(JSON.stringify(u));await w.put(A,v)}}},[a,e,r]);k(()=>{if(r?.refreshInterval){let p=typeof r.refreshInterval=="number"?r.refreshInterval:r.refreshInterval.value,s=typeof r.refreshInterval=="number"?"s":r.refreshInterval.unit,f=setInterval(()=>{U()},j.duration(p,s).asMilliseconds());return()=>clearInterval(f)}return()=>{}},[r?.refreshInterval,U]),k(()=>{if(!r?.refetchOnWindowFocus)return;let p=()=>{U()};return window.addEventListener("focus",p),()=>{window.removeEventListener("focus",p)}},[r?.refetchOnWindowFocus,U]);let m={...T,loading:l,refresh:U,abort:()=>{x.current?.abort(),x.current=null,R(!1),b(!0)},clear:()=>{R(!1),C(null)},response:T,isCancel:S,clone:(p,s)=>Se(e,p,s)};return k(()=>{r?.storeName&&F(r?.storeName).setState([T?.data,m])},[T,m,r?.storeName]),[T?.data,m]}async function St(e,t=()=>{}){let n=e*1e3;return new Promise(o=>{let a=0,r=setInterval(()=>{t(),a===9&&clearInterval(r)},1e3);setTimeout(async()=>{await t(),o(!0)},n)})}import Pe from"moment";var ae=(r=>(r.POST="POST",r.PUT="PUT",r.PATCH="PATCH",r.DELETE="DELETE",r.GET="GET",r))(ae||{}),ie=(s=>(s.number="number",s.currency="currency",s.percent="percent",s.date="date",s.dateTime="dateTime",s.month="month",s.year="year",s.time="time",s.timestamp="timestamp",s.string="string",s.textarea="textarea",s.code="code",s.password="password",s.boolean="boolean",s.toggle="toggle",s.email="email",s.phone="phone",s.url="url",s.json="json",s.file="file",s.image="image",s.array="array",s.object="object",s.enum="enum",s.user="user",s.department="department",s.status="status",s))(ie||{});var vt=(e,t,n)=>{let{format:o}=N();return t==="number"?we(e,{thouSep:o.number.thouSep,decDigits:o.number.decDigits,decSep:o.number.decSep,...n}):["date","dateTime","month","year","time"].includes(t)?Ue(e,{display:o[t]?.display,value:o[t]?.value,...n}):t==="boolean"?Oe(e,n):t==="string"?qe(e,n):e?.toString()??""};function Oe(e,t){let n=typeof e=="string"?e==="true":!!e,o=t?.trueLabel??"Yes",a=t?.falseLabel??"No";return n?o:a}function qe(e,t){if(!q(e))return"";let n=String(e);return t?.capitalize&&(n=n.charAt(0).toUpperCase()+n.slice(1)),t?.ellipsis&&n.length>t.ellipsis&&(n=n.slice(0,t.ellipsis)+"..."),n}function we(e,{thouSep:t,decSep:n,decDigits:o,method:a}){if(e==null||isNaN(Number(e)))return"";let r=typeof e=="string"?parseFloat(e):e;if(a)if(typeof o=="number"){let l=Math.pow(10,o);r=Math[a](r*l)/l}else r=Math[a](r);else if(typeof o=="number"){let l=Math.pow(10,o);r=Math.floor(r*l)/l}let c=0;if(o==="auto"){let l=r.toString(),R=l.indexOf(".");R!==-1&&(c=l.length-R-1)}let i={style:"decimal",useGrouping:!0,minimumFractionDigits:o==="auto"?c:o||0,maximumFractionDigits:o==="auto"?c:o||0,minimumIntegerDigits:1};return r.toLocaleString("en-US",i).replace(/\./g,"decSep").replace(/,/g,"thouSep").replace(/decSep/g,n).replace(/thouSep/g,t)}function Ue(e,{display:t,value:n}){if(!q(e))return e;let o=Pe(e,n);return o.isValid()?o.format(t):e}import{useEffect as le,useRef as Ne}from"react";function Mt(e,{interval:t,lead:n}){let o=Ne(null);le(()=>{o.current=e},[e]),le(()=>{let a=()=>o.current();if(n&&a(),t!==null){let r=setInterval(a,t);return()=>clearInterval(r)}},[t])}import{useEffect as ke,useState as ve}from"react";function It(e,t,n){let[o,a]=ve(!1),r=(l,R)=>typeof e=="string"&&l===e||typeof e=="number"&&R===e,c=l=>l!==null&&(["INPUT","TEXTAREA","SELECT","BUTTON"].includes(l.tagName)||l.hasAttribute("contentEditable")),i=l=>{let{key:R,keyCode:S}=l,b=l.ctrlKey,T=l.altKey,C=l.shiftKey;if(!c(document.activeElement))if(t)if(typeof t=="string")r(R,S)&&(t==="ctrl"&&b||t==="alt"&&T||t==="shift"&&C)&&(l.preventDefault(),n&&l.stopPropagation(),a(!o));else{let g=t.every(x=>x==="ctrl"?b:x==="alt"?T:x==="shift"?C:!1);r(R,S)&&g&&(l.preventDefault(),n&&l.stopPropagation(),a(!o))}else r(R,S)&&(l.preventDefault(),n&&l.stopPropagation(),a(!o))},d=({key:l,keyCode:R})=>{r(l,R)&&a(!1)};return ke(()=>(window.addEventListener("keydown",i),window.addEventListener("keyup",d),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",d)}),[]),o}import Ee from"axios";var er=({url:e,token:t,beforeRequest:n,onCallback:o,headers:a,onUnauthorized:r,handleToast:c,handleAuthorization:i,disabledToastWhenCancel:d,withCredentials:l,encryptRequest:R,encryptResponse:S,passphrase:b})=>{let{encrypt:T,decrypt:C,passphrase:g}=M(),x=(m,p,s,f)=>{let y=f?.code==="ERR_CANCELED",h=m.status===401,u=m?.data;if((typeof s?.encryptResponse=="boolean"?s?.encryptResponse:S)&&u){let E=s?.passphrase?typeof s.passphrase=="boolean"&&s.passphrase?g:s.passphrase:b;try{u=C(u,E)}catch{try{u=C(u,g)}catch{}}}let D={...o({...m,data:u,isCancel:y,isUnauthorization:h},f),isCancel:y,isUnauthorization:h,httpCode:m.status},B=typeof s?.disabledToastWhenCancel=="boolean"?s?.disabledToastWhenCancel:d,de=i?i(D,s):!h;if((s?.infoSuccess&&D.status||s?.infoError&&!D.status)&&c&&(!y||!B)&&c(D),!de&&(!y||!s?.disabledHandleUnauthorized)){let E=s?.onUnauthorized||r;E&&E(D)}if(p)p(D);else return D},P=(m,p=()=>{})=>Ee.create({baseURL:`${e}`,withCredentials:typeof m.withCredentials=="boolean"?m.withCredentials:l})(m).then(p).catch(f=>p(f.response,f)),A=(m,p,s,f,y)=>{let u={...{token:!0,infoError:!0,infoSuccess:!0,responseType:"json"},...y},w={"Content-Type":"application/json",...a,...u.headers};if(u.token&&(typeof u.token=="boolean"?t&&(w.Authorization=`Bearer ${t}`):u.token&&(w.Authorization=`Bearer ${u.token}`)),n&&(s=n(s)),(typeof u?.encryptRequest=="boolean"?u?.encryptRequest:R)&&s){let D=y?.passphrase?typeof y.passphrase=="boolean"&&y.passphrase?g:y.passphrase:b;s=T(s,D)}return P({url:p,method:m,data:s,headers:w,responseType:u.responseType,signal:u.signal,withCredentials:u.withCredentials,onUploadProgress:D=>{u?.onUploadProgress&&u?.onUploadProgress(D)}},(D,B)=>x(D,f,u,B))};return{client:P,post:(m,p,s,f)=>A("POST",`${m}`,p,s,f),put:(m,p,s,f)=>A("PUT",`${m}`,p,s,f),patch:(m,p,s,f)=>A("PATCH",`${m}`,p,s,f),delete:(m,p,s)=>A("DELETE",`${m}`,null,p,s),get:(m,p,s)=>A("GET",`${m}`,null,p,s),upload:(m,p,s,f)=>{let y=new FormData;return Object.keys(p).forEach(h=>y.append(h,p[h])),A("POST",`${m}`,y,s,{infoSuccess:!1,...f,headers:{"Content-Type":"multipart/form-data",...f?.headers}})}}};import{useEffect as Ke,useRef as Me,useState as z}from"react";function or(e,t){let[n,o]=z(!1),[a,r]=z(),[c,i]=z(0),d=Me(null);return Ke(()=>{if(t?.abortOnUnmount)return()=>{d.current?.abort()}},[]),[async b=>{d.current?.abort();let T=new AbortController;d.current=T,o(!0),t?.beforeRequest&&(b=t?.beforeRequest(b)),t?.logging&&console.log("Before request",b);let C={...t,signal:T.signal,onUploadProgress:x=>{let P=Math.round(x.loaded*100/(x.total||1));i(P)}},g=q(b)?await e(b,void 0,C):await e(void 0,C);t?.logging&&console.log("After response",g),r(g),o(!1),i(0),g.status&&t?.onSuccess&&t?.onSuccess(g),!g.status&&t?.onError&&t?.onError(g),t?.afterResponse&&t?.afterResponse(g)},{...a,loading:n,abort:()=>{d.current?.abort(),d.current=null,o(!1),i(0)},progress:c,reset:()=>{o(!1),i(0),r(null)}}]}import{useCallback as Fe,useEffect as Be,useRef as Ie,useState as pe}from"react";function ir(e="vertical"){let t=Ie(null),[n,o]=pe(!1),[a,r]=pe(!1),c=Fe(()=>{let i=t.current;if(i)if(e==="vertical"){let d=Math.ceil(i.scrollTop+i.clientHeight),l=Math.floor(i.scrollHeight);o(i.scrollTop>0),r(d<l)}else{let d=Math.ceil(i.scrollLeft+i.clientWidth),l=Math.floor(i.scrollWidth);o(i.scrollLeft>0),r(d<l)}},[e]);return Be(()=>{let i=t.current;if(i)return c(),i.addEventListener("scroll",c),()=>i.removeEventListener("scroll",c)},[c]),{ref:t,showStartShadow:n,showEndShadow:a}}var cr=(e,t)=>F(t).useStore();import ce from"react";var dr=(e,t)=>{let n=o=>e(o);return n.displayName=t,n},mr=(e,t)=>{let n={};n.others=[];let o=a=>{ce.Children.forEach(a,r=>{if(ce.isValidElement(r)){let c=r.type.displayName;if(t.includes(c))n[c]=r;else{let i=r;i.props?.children?o(i.props.children):n.others.push(r)}}else n.others.push(r)})};return o(e),n};export{ge as BgsCoreProvider,ie as DataTypeEnum,ae as HttpMethod,er as createApiHelper,dr as createElement,H as decrypt,re as decryptString,je as diffJson,I as encrypt,te as encryptString,_ as generateCacheKey,$e as generateUUID,O as getFieldValue,ze as isArray,q as isNotEmpty,Xe as jsonCopy,X as labelFormatter,Ve as mappingUndefinedtoNull,Je as renderChildren,We as sorting,mr as splitElement,me as stableStringify,Ge as summary,Se as useApiLoad,or as useApiSend,cr as useApiStore,N as useBgsCore,M as useCrypto,St as useDelay,vt as useFormatted,Mt as useInterval,It as useKeyPress,ir as useScroll,ne as useStorage};
1
+ import j from"moment";import{useCallback as De,useEffect as k,useMemo as Ae,useRef as se,useState as V}from"react";function $e(){let e=()=>Math.random()*16%16|0;return"xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx".replace(/[xy]/g,t=>(t==="x"?e():e()&3|8).toString(16))}function je(e,t){try{return JSON.stringify(e)!==JSON.stringify(t)}catch{return!1}}var Ve=e=>(Object.keys(e).forEach(t=>{e[t]===void 0&&(e[t]=null)}),e);function ze(e,t){let n=!1;return e&&typeof e=="object"&&Array.isArray(e)&&(typeof t=="number"?e.length>t&&(n=!0):n=!0),n}function q(e){return!(e==null||typeof e=="string"&&e.trim()===""||Array.isArray(e)&&e.length===0||typeof e=="object"&&e!==null&&!Array.isArray(e)&&Object.keys(e).length===0)}var X={camelCase:(e="")=>(e=e.split(".").map(t=>(t=t.charAt(0).toUpperCase()+t.slice(1),t)).join(" "),e=e.replace(/([a-z0-9])([A-Z])/g,"$1 $2"),e.charAt(0).toUpperCase()+e.slice(1)),snackCase:(e="")=>{let n=e.replace(/_([a-z])/g,(o,a)=>a.toUpperCase()).replace(/([A-Z])/g," $1");return n=n.charAt(0).toUpperCase()+n.slice(1),n},changeAll:(e="",t=!1)=>{let n="";try{e=e?.split(".")[e?.split(".")?.length-1],e=e?.split("[]")[e?.split("[]")?.length-1],n=X.snackCase(X.camelCase(e)),t&&(n=n?.split(" ")?.map(o=>o?.length<=3?o?.toUpperCase():o)?.join(" "))}catch{}return n?.trim()}};function Je(e,t){return typeof e=="function"?e(t):e}var O=(e,t,n="")=>{if(!e)return n;if(e.hasOwnProperty(t))return e[t];let o=t.replace(/\[(\d+)\]/g,".$1").split("."),a=e;for(let r of o){if(a==null)return n;a=a[r]}return a===void 0?n:a},We={desc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(n,t):"";return a<r?1:-1}else return n<o?1:-1})),asc:(e,t)=>(e||(e=[]),e.sort((n,o)=>{if(t){let a=O(n,t)?O(n,t):"",r=O(o,t)?O(o,t):"";return a>r?1:-1}else return n>o?1:-1}))},Ge=(e,t)=>{Array.isArray(e)||(e=[]);let n=[];return n=e.map(o=>Number(t?O(o,t)||0:o||0)),n.reduce((o,a)=>(o||0)+(a||0),0)||0};function Xe(e){try{return e&&JSON.parse(JSON.stringify(e))}catch{return e}}function me(e){let t=new WeakSet;return JSON.stringify(e,function(n,o){return o!==null&&typeof o=="object"?t.has(o)?void 0:(t.add(o),Object.keys(o).sort().reduce((a,r)=>(a[r]=o[r],a),{})):o})??""}function _(e,t){return me([t??"undefined",e??"undefined"])}import{createContext as ye,useContext as Re}from"react";import{jsx as he}from"react/jsx-runtime";var Z=ye(void 0);function N(){let e=Re(Z);return e||{}}var ge=({children:e,value:t})=>{let n={...t};return he(Z.Provider,{value:n,children:e})};import{useCallback as H,useEffect as xe,useState as Te}from"react";import Q from"crypto-js/aes";import ee from"crypto-js/pbkdf2";import be from"crypto-js/enc-utf8";import K from"crypto-js/enc-base64";import Y from"crypto-js/lib-typedarrays";function I(e,t){let n=Y.random(16),o=Y.random(16),a=ee(t,n,{keySize:256/32,iterations:1e3}),r=Q.encrypt(JSON.stringify(e),a,{iv:o}).toString();return{salt:n.toString(K),iv:o.toString(K),encrypted:r}}function L(e,t){let{salt:n,iv:o,encrypted:a}=e,r=ee(t,K.parse(n),{keySize:256/32,iterations:1e3}),i=Q.decrypt(a,r,{iv:K.parse(o)}).toString(be);return JSON.parse(i)}function te(e,t){return JSON.stringify(I(e,t))}function re(e,t){return L(JSON.parse(e),t)}function M(){let{passphrase:e}=N();return{passphrase:e,encrypt(t,n){return I(t,n||e)},decrypt(t,n){return L(t,n||e)},encryptString(t,n){return te(t,n||e)},decryptString(t,n){return re(t,n||e)}}}var ne=()=>{let{encrypt:e,decrypt:t}=M(),n=H((c,i)=>{try{let d=e(i);localStorage.setItem(c,JSON.stringify(d))}catch(d){console.error("Failed to save to storage:",d)}},[e]),o=H(c=>{try{let i=localStorage.getItem(c);return i?t(JSON.parse(i)):null}catch(i){return console.error("Failed to get from storage:",i),null}},[t]),a=c=>{let[i,d]=Te(()=>{try{let p=localStorage.getItem(c);return p?t(JSON.parse(p)):null}catch(p){return console.error("Failed to parse localStorage value",p),null}});return xe(()=>{let p=R=>{if(R.key===c)if(R.newValue)try{d(t(JSON.parse(R.newValue)))}catch(S){console.error("Decrypt error from storage event",S)}else d(null)};return window.addEventListener("storage",p),()=>window.removeEventListener("storage",p)},[c,t]),i},r=H(c=>{c?localStorage.removeItem(c):localStorage.clear()},[]);return{save:n,get:o,clear:r,useWatchStorage:a}};import{useSyncExternalStore as Ce}from"react";function oe(e){let t=e,n=new Set;function o(){return t}function a(i){return n.add(i),()=>n.delete(i)}function r(i){typeof i=="function"?t=i(t):t=i,n.forEach(d=>d())}function c(i){return Ce(a,()=>i?i(t):t,()=>i?i(t):t)}return{getSnapshot:o,subscribe:a,setState:r,useStore:c}}var $=new Map;function F(e){return $.has(e)||$.set(e,oe([null,{}])),$.get(e)}function Se(e,t,n){let o=arguments.length===3,a=o?t:void 0,r=o?n:t,{storageKey:c,cache:i}=N(),d=ne(),[p,R]=V(!1),[S,b]=V(!1),[T,C]=V(),g=se(void 0),x=se(null),{cacheName:P,cacheKey:A,timeout:J,timeoutUnit:W,persistence:G}=Ae(()=>{let l=c?d.get(c):void 0,s=typeof r?.cache=="object"?r?.cache?.cacheName??e.name:e.name,f=_({...a,session:l},typeof r?.cache=="object"?r?.cache?.cacheKey:void 0),y=!1;typeof i?.persistence=="boolean"&&(y=i?.persistence),typeof r?.cache=="object"&&typeof r?.cache?.persistence=="boolean"&&(y=r?.cache?.persistence??!1);let h=60*5,u="s";return q(i?.timeout)&&(typeof i?.timeout=="number"?(h=i.timeout,u="s"):typeof i?.timeout=="object"&&(h=i?.timeout.value,u=i?.timeout.unit)),r?.cache&&typeof r.cache!="boolean"&&(typeof r.cache.timeout=="number"?(h=r.cache.timeout,u="s"):typeof r.cache.timeout=="object"&&(h=r.cache.timeout.value,u=r.cache.timeout.unit)),{cacheName:s,cacheKey:f,timeout:h,timeoutUnit:u,persistence:y}},[r?.cache,c,i]);k(()=>{let l=JSON.stringify(q(g.current)?g.current:""),s=JSON.stringify(q(a)?a:""),f=g.current===void 0;(l!==s||f)&&!r?.hold&&(C(null),U(),g.current=a),r?.onChange&&r?.onChange(a,m)},[a,r?.hold,...r?.trigger||[]]),k(()=>{let l=async()=>{!G&&P&&A&&(await caches.open(P)).delete(A)};return window.addEventListener("beforeunload",l),()=>{window.removeEventListener("beforeunload",l),x.current?.abort()}},[]);let U=De(async l=>{let s=a;if(r?.hold&&r?.logging&&console.log("Hold active"),r?.beforeRequest&&(s=r?.beforeRequest(a)),r?.cache&&!l&&!S){R(!0),r?.onBeforeRequest&&r?.onBeforeRequest(a);let f=await caches.open(P),h=await(await f.match(A))?.json();if(h){let{data:u,expired:w}=h;if(j().isAfter(w))await f.delete(A);else{r?.afterResponse&&u?.data&&(u.data=r?.afterResponse(u.data)),r?.logging&&console.log("After request: Using Cache",u),r?.onAfterResponse&&r?.onAfterResponse(u),R(!1),C(u);return}}}if(typeof e=="function"){x.current?.abort();let f=new AbortController;x.current=f,R(!0),r?.logging&&console.log("Before request",a),r?.onBeforeRequest&&r?.onBeforeRequest(a);let y=o?await e(s,void 0,{...r,signal:f.signal}):await e(void 0,{...r,signal:f.signal});if(r?.afterResponse&&y?.data&&(y.data=r?.afterResponse(y.data)),r?.logging&&console.log("After request",y),r?.onAfterResponse&&r?.onAfterResponse(y),R(!1),C(y),b(!1),r?.cache&&y.status){let h=j().add(J,W).toISOString(),u={data:y,expired:h},w=await caches.open(P),v=new Response(JSON.stringify(u));await w.put(A,v)}}},[a,e,r]);k(()=>{if(r?.refreshInterval){let l=typeof r.refreshInterval=="number"?r.refreshInterval:r.refreshInterval.value,s=typeof r.refreshInterval=="number"?"s":r.refreshInterval.unit,f=setInterval(()=>{U()},j.duration(l,s).asMilliseconds());return()=>clearInterval(f)}return()=>{}},[r?.refreshInterval,U]),k(()=>{if(!r?.refetchOnWindowFocus)return;let l=()=>{U()};return window.addEventListener("focus",l),()=>{window.removeEventListener("focus",l)}},[r?.refetchOnWindowFocus,U]);let m={...T,loading:p,refresh:U,abort:()=>{x.current?.abort(),x.current=null,R(!1),b(!0)},clear:()=>{R(!1),C(null)},response:T,isCancel:S,clone:(l,s)=>Se(e,l,s)};return k(()=>{r?.storeName&&F(r?.storeName).setState([T?.data,m])},[T,m,r?.storeName]),[T?.data,m]}async function St(e,t=()=>{}){let n=e*1e3;return new Promise(o=>{let a=0,r=setInterval(()=>{t(),a===9&&clearInterval(r)},1e3);setTimeout(async()=>{await t(),o(!0)},n)})}import Pe from"moment";var ae=(r=>(r.POST="POST",r.PUT="PUT",r.PATCH="PATCH",r.DELETE="DELETE",r.GET="GET",r))(ae||{}),ie=(s=>(s.number="number",s.currency="currency",s.percent="percent",s.date="date",s.dateTime="dateTime",s.month="month",s.year="year",s.time="time",s.timestamp="timestamp",s.string="string",s.textarea="textarea",s.code="code",s.password="password",s.boolean="boolean",s.toggle="toggle",s.email="email",s.phone="phone",s.url="url",s.json="json",s.file="file",s.image="image",s.array="array",s.object="object",s.enum="enum",s.user="user",s.department="department",s.status="status",s))(ie||{});var Et=(e,t,n)=>{let{format:o}=N();return t==="number"?we(e,{thouSep:o.number.thouSep,decDigits:o.number.decDigits,decSep:o.number.decSep,...n}):["date","dateTime","month","year","time"].includes(t)?Ue(e,{display:o[t]?.display,value:o[t]?.value,...n}):t==="boolean"?Oe(e,n):t==="string"?qe(e,n):e?.toString()??""};function Oe(e,t){let n=typeof e=="string"?e==="true":!!e,o=t?.trueLabel??"Yes",a=t?.falseLabel??"No";return n?o:a}function qe(e,t){if(!q(e))return"";let n=String(e);if(t?.textTransform)switch(t?.textTransform){case"capitalize":n=n.charAt(0).toUpperCase()+n.slice(1);break;case"uppercase":n=n.toUpperCase();break;case"lowercase":n=n.toLowerCase();break}return t?.ellipsis&&n.length>t.ellipsis&&(n=n.slice(0,t.ellipsis)+"..."),n}function we(e,{thouSep:t,decSep:n,decDigits:o,method:a}){if(e==null||isNaN(Number(e)))return"";let r=typeof e=="string"?parseFloat(e):e;if(a)if(typeof o=="number"){let p=Math.pow(10,o);r=Math[a](r*p)/p}else r=Math[a](r);else if(typeof o=="number"){let p=Math.pow(10,o);r=Math.floor(r*p)/p}let c=0;if(o==="auto"){let p=r.toString(),R=p.indexOf(".");R!==-1&&(c=p.length-R-1)}let i={style:"decimal",useGrouping:!0,minimumFractionDigits:o==="auto"?c:o||0,maximumFractionDigits:o==="auto"?c:o||0,minimumIntegerDigits:1};return r.toLocaleString("en-US",i).replace(/\./g,"decSep").replace(/,/g,"thouSep").replace(/decSep/g,n).replace(/thouSep/g,t)}function Ue(e,{display:t,value:n}){if(!q(e))return e;let o=Pe(e,n);return o.isValid()?o.format(t):e}import{useEffect as pe,useRef as Ne}from"react";function Ft(e,{interval:t,lead:n}){let o=Ne(null);pe(()=>{o.current=e},[e]),pe(()=>{let a=()=>o.current();if(n&&a(),t!==null){let r=setInterval(a,t);return()=>clearInterval(r)}},[t])}import{useEffect as ke,useState as ve}from"react";function Lt(e,t,n){let[o,a]=ve(!1),r=(p,R)=>typeof e=="string"&&p===e||typeof e=="number"&&R===e,c=p=>p!==null&&(["INPUT","TEXTAREA","SELECT","BUTTON"].includes(p.tagName)||p.hasAttribute("contentEditable")),i=p=>{let{key:R,keyCode:S}=p,b=p.ctrlKey,T=p.altKey,C=p.shiftKey;if(!c(document.activeElement))if(t)if(typeof t=="string")r(R,S)&&(t==="ctrl"&&b||t==="alt"&&T||t==="shift"&&C)&&(p.preventDefault(),n&&p.stopPropagation(),a(!o));else{let g=t.every(x=>x==="ctrl"?b:x==="alt"?T:x==="shift"?C:!1);r(R,S)&&g&&(p.preventDefault(),n&&p.stopPropagation(),a(!o))}else r(R,S)&&(p.preventDefault(),n&&p.stopPropagation(),a(!o))},d=({key:p,keyCode:R})=>{r(p,R)&&a(!1)};return ke(()=>(window.addEventListener("keydown",i),window.addEventListener("keyup",d),()=>{window.removeEventListener("keydown",i),window.removeEventListener("keyup",d)}),[]),o}import Ee from"axios";var tr=({url:e,token:t,beforeRequest:n,onCallback:o,headers:a,onUnauthorized:r,handleToast:c,handleAuthorization:i,disabledToastWhenCancel:d,withCredentials:p,encryptRequest:R,encryptResponse:S,passphrase:b})=>{let{encrypt:T,decrypt:C,passphrase:g}=M(),x=(m,l,s,f)=>{let y=f?.code==="ERR_CANCELED",h=m.status===401,u=m?.data;if((typeof s?.encryptResponse=="boolean"?s?.encryptResponse:S)&&u){let E=s?.passphrase?typeof s.passphrase=="boolean"&&s.passphrase?g:s.passphrase:b;try{u=C(u,E)}catch{try{u=C(u,g)}catch{}}}let D={...o({...m,data:u,isCancel:y,isUnauthorization:h},f),isCancel:y,isUnauthorization:h,httpCode:m.status},B=typeof s?.disabledToastWhenCancel=="boolean"?s?.disabledToastWhenCancel:d,de=i?i(D,s):!h;if((s?.infoSuccess&&D.status||s?.infoError&&!D.status)&&c&&(!y||!B)&&c(D),!de&&(!y||!s?.disabledHandleUnauthorized)){let E=s?.onUnauthorized||r;E&&E(D)}if(l)l(D);else return D},P=(m,l=()=>{})=>Ee.create({baseURL:`${e}`,withCredentials:typeof m.withCredentials=="boolean"?m.withCredentials:p})(m).then(l).catch(f=>l(f.response,f)),A=(m,l,s,f,y)=>{let u={...{token:!0,infoError:!0,infoSuccess:!0,responseType:"json"},...y},w={"Content-Type":"application/json",...a,...u.headers};if(u.token&&(typeof u.token=="boolean"?t&&(w.Authorization=`Bearer ${t}`):u.token&&(w.Authorization=`Bearer ${u.token}`)),n&&(s=n(s)),(typeof u?.encryptRequest=="boolean"?u?.encryptRequest:R)&&s){let D=y?.passphrase?typeof y.passphrase=="boolean"&&y.passphrase?g:y.passphrase:b;s=T(s,D)}return P({url:l,method:m,data:s,headers:w,responseType:u.responseType,signal:u.signal,withCredentials:u.withCredentials,onUploadProgress:D=>{u?.onUploadProgress&&u?.onUploadProgress(D)}},(D,B)=>x(D,f,u,B))};return{client:P,post:(m,l,s,f)=>A("POST",`${m}`,l,s,f),put:(m,l,s,f)=>A("PUT",`${m}`,l,s,f),patch:(m,l,s,f)=>A("PATCH",`${m}`,l,s,f),delete:(m,l,s)=>A("DELETE",`${m}`,null,l,s),get:(m,l,s)=>A("GET",`${m}`,null,l,s),upload:(m,l,s,f)=>{let y=new FormData;return Object.keys(l).forEach(h=>y.append(h,l[h])),A("POST",`${m}`,y,s,{infoSuccess:!1,...f,headers:{"Content-Type":"multipart/form-data",...f?.headers}})}}};import{useEffect as Ke,useRef as Me,useState as z}from"react";function sr(e,t){let[n,o]=z(!1),[a,r]=z(),[c,i]=z(0),d=Me(null);return Ke(()=>{if(t?.abortOnUnmount)return()=>{d.current?.abort()}},[]),[async b=>{d.current?.abort();let T=new AbortController;d.current=T,o(!0),t?.beforeRequest&&(b=t?.beforeRequest(b)),t?.logging&&console.log("Before request",b);let C={...t,signal:T.signal,onUploadProgress:x=>{let P=Math.round(x.loaded*100/(x.total||1));i(P)}},g=q(b)?await e(b,void 0,C):await e(void 0,C);t?.logging&&console.log("After response",g),r(g),o(!1),i(0),g.status&&t?.onSuccess&&t?.onSuccess(g),!g.status&&t?.onError&&t?.onError(g),t?.afterResponse&&t?.afterResponse(g)},{...a,loading:n,abort:()=>{d.current?.abort(),d.current=null,o(!1),i(0)},progress:c,reset:()=>{o(!1),i(0),r(null)}}]}import{useCallback as Fe,useEffect as Be,useRef as Ie,useState as le}from"react";function pr(e="vertical"){let t=Ie(null),[n,o]=le(!1),[a,r]=le(!1),c=Fe(()=>{let i=t.current;if(i)if(e==="vertical"){let d=Math.ceil(i.scrollTop+i.clientHeight),p=Math.floor(i.scrollHeight);o(i.scrollTop>0),r(d<p)}else{let d=Math.ceil(i.scrollLeft+i.clientWidth),p=Math.floor(i.scrollWidth);o(i.scrollLeft>0),r(d<p)}},[e]);return Be(()=>{let i=t.current;if(i)return c(),i.addEventListener("scroll",c),()=>i.removeEventListener("scroll",c)},[c]),{ref:t,showStartShadow:n,showEndShadow:a}}var ur=(e,t)=>F(t).useStore();import ce from"react";var mr=(e,t)=>{let n=o=>e(o);return n.displayName=t,n},yr=(e,t)=>{let n={};n.others=[];let o=a=>{ce.Children.forEach(a,r=>{if(ce.isValidElement(r)){let c=r.type.displayName;if(t.includes(c))n[c]=r;else{let i=r;i.props?.children?o(i.props.children):n.others.push(r)}}else n.others.push(r)})};return o(e),n};export{ge as BgsCoreProvider,ie as DataTypeEnum,ae as HttpMethod,tr as createApiHelper,mr as createElement,L as decrypt,re as decryptString,je as diffJson,I as encrypt,te as encryptString,_ as generateCacheKey,$e as generateUUID,O as getFieldValue,ze as isArray,q as isNotEmpty,Xe as jsonCopy,X as labelFormatter,Ve as mappingUndefinedtoNull,Je as renderChildren,We as sorting,yr as splitElement,me as stableStringify,Ge as summary,Se as useApiLoad,sr as useApiSend,ur as useApiStore,N as useBgsCore,M as useCrypto,St as useDelay,Et as useFormatted,Ft as useInterval,Lt as useKeyPress,pr as useScroll,ne as useStorage};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bgscore/react-core",
3
- "version": "0.0.3",
3
+ "version": "0.0.4",
4
4
  "description": "A React utility library that provides advanced API hooks (fetch, mutation, caching). Built for scalable and flexible data handling in modern React applications.",
5
5
  "main": "dist/index.cjs",
6
6
  "module": "dist/index.js",