@dashadmin/dash-utils 1.3.17 → 1.3.21
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/components/LazyAppLoader.js +1 -0
- package/dist/components/MinimalLayout.js +1 -0
- package/dist/components/RouterComponent.js +1 -0
- package/dist/components/index.js +1 -0
- package/dist/contexts/IPCMessageBrokerContext.js +1 -0
- package/dist/hooks/useCapacitorAppStateRefresh.js +1 -0
- package/dist/hooks/useCapacitorKeyboard.js +1 -0
- package/dist/hooks/useDeviceStorageSync.js +1 -0
- package/dist/hooks/useDraggable.js +1 -0
- package/dist/hooks/useMenuStateInit.js +1 -0
- package/dist/hooks/useMobileDetection.js +1 -0
- package/dist/hooks/useNotifications.js +1 -0
- package/dist/hooks/useQuickSearch.js +1 -0
- package/dist/hooks/useWindowSize.js +1 -0
- package/dist/utils/authProviderUtils.js +1 -0
- package/dist/utils/dashBootstrapApp.js +1 -0
- package/dist/utils/dashDtorage.js +1 -0
- package/dist/utils/dashDtorage.tsx.old +78 -0
- package/dist/utils/dashIPCService.js +1 -0
- package/dist/utils/dataProviderUtils.js +1 -0
- package/dist/utils/electronStoreSync.js +1 -0
- package/dist/utils/envUtils.js +1 -0
- package/dist/utils/environmentBodyClasses.js +1 -0
- package/dist/utils/isDev.js +1 -0
- package/dist/utils/notificationPermission.js +1 -0
- package/dist/utils/platformDetection.js +1 -0
- package/dist/utils/priceFormatter.js +1 -0
- package/dist/utils/resourceLoader.js +1 -0
- package/dist/utils/storedTheme.js +1 -0
- package/dist/utils/updateDomCssVariables.js +1 -0
- package/dist/utils/validation.js +1 -0
- package/package.json +14 -3
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as i,jsxs as m}from"react/jsx-runtime";import n from"react";const d=({message:e="Failed to load application"})=>m("div",{style:{display:"flex",justifyContent:"center",alignItems:"center",height:"100vh",background:"linear-gradient(to bottom, var(--bodybg-primary), var(--bodybg-secondary))",color:"#ff4444",flexDirection:"column",gap:"16px"},children:[i("div",{style:{fontSize:"18px"},children:e}),i("button",{onClick:()=>window.location.reload(),style:{padding:"10px 20px",backgroundColor:"#007bff",color:"white",border:"none",borderRadius:"4px",cursor:"pointer"},children:"Reload Page"})]}),p=e=>{const{importFn:t,initDelay:l=150,fallbackComponent:a,onError:c}=e;return n.lazy(()=>new Promise(r=>{setTimeout(()=>{t().then(o=>{r({default:o.default})}).catch(o=>{console.error("Failed to load app component:",o),c?.(o),r({default:a?()=>n.createElement(a):()=>n.createElement(d,{message:`Failed to load: ${o.message}`})})})},l)}))},f=(e,t=150)=>p({importFn:e,initDelay:t});var C=p;export{d as DefaultLoadFailedComponent,p as createLazyAppComponent,f as createSimpleLazyApp,C as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as a,jsx as e}from"react/jsx-runtime";const o=({children:t})=>e(a,{children:t});var c=o;export{o as MinimalLayout,c as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{Fragment as g,jsx as t}from"react/jsx-runtime";import{Suspense as N}from"react";import{BrowserRouter as u,HashRouter as i,Routes as P}from"react-router-dom";import{getEnv as c}from"../utils/envUtils";const C=(e,o)=>e==="desktop"||o==="electron",T=({publicRoutes:e,loader:o,className:r,children:s})=>{if(!e)return t(g,{children:s});let a;return typeof e=="function"?a=e():a=e,t("div",{className:r,children:t(N,{fallback:o||t("div",{children:"Loading..."}),children:t(P,{children:a})})})},R=({children:e,forceType:o,basename:r,platformType:s,platform:a,loader:m,publicRoutes:d,className:l="dash-public-app"})=>{const f=s??c("PLATFORM_TYPE"),h=a??c("PLATFORM"),p=r??c("BASE_PATH")??"/",n=t(T,{publicRoutes:d,loader:m,className:l,children:e});return o==="hash"?t(i,{basename:"",children:n}):o==="browser"?t(u,{basename:p,children:n}):C(f,h)?t(i,{basename:"",children:n}):t(u,{basename:p,children:n})},L=e=>({children:r})=>t(R,{platformType:e.PLATFORM_TYPE,platform:e.PLATFORM,children:r}),x=R;var M=R;export{R as DashRouterComponent,x as RouterComponent,L as createRouterComponent,M as default,C as shouldUseHashRouter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{MinimalLayout as t}from"./MinimalLayout";import{DashRouterComponent as p,RouterComponent as n,shouldUseHashRouter as m,createRouterComponent as u}from"./RouterComponent";export{p as DashRouterComponent,t as MinimalLayout,n as RouterComponent,u as createRouterComponent,m as shouldUseHashRouter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{jsx as G}from"react/jsx-runtime";import{useState as n,useRef as R,useEffect as v,createContext as F,useContext as $}from"react";const q={idleTime:180*1e3,resuscitationTime:360*1e3,maxLogMessages:100,maxSubprocessOutputs:100,maxInitAttempts:5,initRetryDelay:500},P=F({lastMessage:void 0,idleStatus:!1,logMessages:[],subprocessOutputs:[],isElectronAvailable:!1}),V=()=>$(P),z=({children:b,config:M})=>{const s={...q,...M},[x,T]=n(),[l,d]=n(!1),[a,w]=n(null),[y,O]=n([]),[h,D]=n([]),[L,k]=n(!1),g=R(0),u=()=>{d(!1),a&&clearTimeout(a),w(setTimeout(()=>{d(!0)},s.idleTime))},c=(t,o,p=null)=>t&&typeof t[o]=="function"?t[o].bind(t):(console.warn(`Method ${o} is not available on DashIPCService`),p),f=()=>{if(typeof window>"u")return!1;if(!window.DashIPCService)return console.log(`DashIPCService not available yet. Attempt ${g.current+1}/${s.maxInitAttempts}`),g.current+=1,g.current<s.maxInitAttempts?setTimeout(f,s.initRetryDelay):console.warn("Failed to initialize DashIPCService after multiple attempts"),!1;console.log("DashIPCService is available, setting up listeners"),k(!0);const t=e=>{T(e),u()},o=e=>{console.log("Log message received:",e),O(r=>[...r.slice(-(s.maxLogMessages-1)),e]),u()},p=e=>{console.log("Subprocess output received:",e),D(r=>[...r.slice(-(s.maxSubprocessOutputs-1)),e]),u()},S=c(window.DashIPCService,"onServiceMessage"),m=c(window.DashIPCService,"onElectronLog"),C=c(window.DashIPCService,"onSubprocessOutput"),I=c(window.DashIPCService,"onStdout");return S&&S(e=>{t(e)}),m&&m(e=>{o(e)}),C&&C(e=>{p(e)}),!m&&I&&I(e=>{try{if(e.includes("{")&&e.includes("}")){const r=e.indexOf("{"),A=e.lastIndexOf("}")+1,E=e.substring(r,A),i=JSON.parse(E);if(i.level&&i.message){o({level:i.level,message:i.message,timestamp:i.timestamp||new Date().toISOString()});return}}}catch{}o({level:"info",message:e,timestamp:new Date().toISOString()})}),u(),!0};v(()=>(f(),()=>{a&&clearTimeout(a)}),[]),v(()=>{if(l&&window.DashIPCService&&typeof window.DashIPCService.action=="function"){const t=setTimeout(()=>{window.DashIPCService.action("resuscitate",null)},s.resuscitationTime-s.idleTime);return()=>{clearTimeout(t)}}},[l,s.resuscitationTime,s.idleTime]);const B={lastMessage:x,idleStatus:l,logMessages:y,subprocessOutputs:h,isElectronAvailable:L};return G(P.Provider,{value:B,children:b})};var W=z;export{P as IPCMessageBrokerContext,z as IPCMessageBrokerProvider,W as default,V as useIPCMessageBroker};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as o}from"react";const r=t=>{o(()=>{const e=window?.Capacitor?.Plugins?.App;if(console.log("[useCapacitorAppStateRefresh] Checking for Capacitor App plugin:",!!e),!e)return;const p=a=>{console.log("[useCapacitorAppStateRefresh] App state changed:",a),a.isActive&&(console.log("[useCapacitorAppStateRefresh] App is resuming, triggering callback"),t?.())};return e.addListener("appStateChange",p),console.log("[useCapacitorAppStateRefresh] Added appStateChange listener"),()=>{e.removeAllListeners?.(),console.log("[useCapacitorAppStateRefresh] Removed all Capacitor App listeners")}},[t])};var i=r;export{i as default,r as useCapacitorAppStateRefresh};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as u,useState as H,useCallback as p}from"react";const d=()=>{const l=!!window?.Capacitor?.Plugins?.Keyboard,s=!!window?.CapacitorKeyboard;return l||s},c=()=>window?.Capacitor?.Plugins?.Keyboard||window?.CapacitorKeyboard,v=(l={})=>{const{disableAccessoryBar:s=!0,resizeMode:K="body",debug:g=!1}=l,[w,t]=H({isKeyboardOpen:!1,keyboardHeight:0}),e=p((r,o)=>{g&&console.log(`[useCapacitorKeyboard] ${r}`,o||"")},[g]),f=p(async()=>{if(d()){const r=c();if(r?.hide)try{e("Hiding keyboard..."),await r.hide()}catch(o){e("Error hiding keyboard:",o)}}},[e]),k=p(async()=>{if(d()){const r=c();if(r?.show)try{e("Showing keyboard..."),await r.show()}catch(o){e("Error showing keyboard:",o)}}},[e]);return u(()=>{(async()=>{if(d()){const o=c();if(o)try{e("Configuring Capacitor Keyboard..."),o.setAccessoryBarVisible&&await o.setAccessoryBarVisible({isVisible:!s}),o.setResizeMode&&await o.setResizeMode({mode:K}),e("Capacitor Keyboard configured successfully")}catch(a){e("Error configuring Capacitor Keyboard:",a)}}})()},[s,K,e]),u(()=>{if(d()){const a=c();if(a){e("Using Capacitor Keyboard API");const n=y=>{e("Keyboard will show",{height:y.keyboardHeight}),t({isKeyboardOpen:!0,keyboardHeight:y.keyboardHeight})},h=y=>{t({isKeyboardOpen:!0,keyboardHeight:y.keyboardHeight})},i=()=>{e("Keyboard will hide"),t({isKeyboardOpen:!1,keyboardHeight:0})},b=()=>{t({isKeyboardOpen:!1,keyboardHeight:0})};return a.addListener("keyboardWillShow",n),a.addListener("keyboardDidShow",h),a.addListener("keyboardWillHide",i),a.addListener("keyboardDidHide",b),()=>{a.removeAllListeners?.()}}}e("Using fallback viewport-based keyboard detection");let r=window.visualViewport?.height||window.innerHeight;const o=()=>{const a=window.visualViewport?.height||window.innerHeight,n=window.screen.height,h=n*.75,i=a<h;if(i!==w.isKeyboardOpen){const b=i?n-a:0;e(i?"Keyboard opened (fallback)":"Keyboard closed (fallback)",{height:b}),t({isKeyboardOpen:i,keyboardHeight:b})}r=a};return window.addEventListener("resize",o),window.visualViewport&&window.visualViewport.addEventListener("resize",o),()=>{window.removeEventListener("resize",o),window.visualViewport&&window.visualViewport.removeEventListener("resize",o)}},[e,w.isKeyboardOpen]),{...w,hideKeyboard:f,showKeyboard:k,isCapacitorAvailable:d()}};var O=v;export{O as default,c as getCapacitorKeyboard,d as isCapacitorKeyboardAvailable,v as useCapacitorKeyboard};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as r}from"react";const a=()=>{r(()=>{(async()=>{const e=window.electronStore;e&&e.getAll&&console.log("[useDeviceStorageSync] Electron store detected")})()},[])},l=async()=>{const o=window.electronStore;if(o&&o.getAll)try{const e=await o.getAll();if(e&&typeof e=="object"){for(const[t,c]of Object.entries(e))window.localStorage.setItem(t,JSON.stringify(c));console.log("[syncDeviceStoreToLocalStorage] Synced electron-store to localStorage")}}catch(e){console.error("[syncDeviceStoreToLocalStorage] Failed to sync:",e)}},s=async()=>{const o=window.electronStore;if(o&&o.set)try{for(let e=0;e<window.localStorage.length;e++){const t=window.localStorage.key(e);if(t){const c=window.localStorage.getItem(t);if(c!==null)try{await o.set(t,JSON.parse(c))}catch{await o.set(t,c)}}}console.log("[syncLocalStorageToDeviceStore] Synced localStorage to electron-store")}catch(e){console.error("[syncLocalStorageToDeviceStore] Failed to sync:",e)}};var i=a;export{i as default,l as syncDeviceStoreToLocalStorage,s as syncLocalStorageToDeviceStore,a as useDeviceStorageSync};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as m,useCallback as t,useEffect as w}from"react";const S=(P={})=>{const{initialPosition:o={x:0,y:0},minX:l=0,minY:c=0,maxX:a,maxY:s,elementWidth:f=400,elementHeight:b=200,onPositionChange:D,onDragStart:x,onDragEnd:p}=P,[i,r]=m(o),[n,v]=m(!1),[u,E]=m({x:0,y:0}),h=t(()=>a!==void 0?a:typeof window<"u"?window.innerWidth-f:1e3,[a,f]),M=t(()=>s!==void 0?s:typeof window<"u"?window.innerHeight-b:800,[s,b]),X=t(e=>{e.target.closest(".drag-handle")&&(e.preventDefault(),v(!0),E({x:e.clientX-i.x,y:e.clientY-i.y}),x?.())},[i,x]),g=t(e=>{if(n){e.preventDefault();const Y=Math.max(l,Math.min(h(),e.clientX-u.x)),L=Math.max(c,Math.min(M(),e.clientY-u.y)),y={x:Y,y:L};r(y),D?.(y)}},[n,u,l,c,h,M,D]),d=t(()=>{n&&(v(!1),p?.())},[n,p]);return w(()=>{if(n)return document.addEventListener("mousemove",g),document.addEventListener("mouseup",d),document.body.style.userSelect="none",()=>{document.removeEventListener("mousemove",g),document.removeEventListener("mouseup",d),document.body.style.userSelect=""}},[n,g,d]),w(()=>{r(o)},[o.x,o.y]),{position:i,isDragging:n,handleMouseDown:X,setPosition:r}};var H=S;export{H as default,S as useDraggable};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as o}from"react";import{useDispatch as i}from"react-redux";import{dashStorage as r}from"../utils/dashDtorage";const c={navExpandedKey:"dashNavExpanded",navSizeKey:"dashNavSize"},d=(t={})=>{const e=i(),{navExpandedKey:s=c.navExpandedKey,setNavExpandedAction:n}=t;o(()=>{if(n)try{const a=r.getItem(s);a!==null&&e(n(a==="true"))}catch(a){console.error("Error accessing localStorage:",a)}},[e,s,n])},g=(t="dashNavExpanded")=>{try{const e=r.getItem(t);return e!==null?e==="true":!0}catch(e){return console.error("Error accessing localStorage:",e),!0}},S=(t="dashNavSize")=>{try{return r.getItem(t)||"small"}catch(e){return console.error("Error accessing localStorage:",e),"small"}};var x=d;export{x as default,g as getInitialMenuState,S as getInitialNavSize,d as useMenuStateInit};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useEffect as c,useState as w,useCallback as p}from"react";const l=(e=700)=>{const o=document.body.className,s=o.includes("webview")||o.includes("android")||o.includes("ios")||o.includes("mobile"),r=window.innerWidth<e;return s||r},d=()=>{const e=navigator.userAgent.toLowerCase();return/(webview|wv)/.test(e)||/android.*(wv|.net)/.test(e)||/iphone|ipod|ipad.*applewebkit(?!.*safari)/i.test(e)},b=()=>/android/i.test(navigator.userAgent.toLowerCase()),u=()=>/iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase()),f=()=>{try{return globalThis.process?.platform==="win32"?!0:navigator.userAgent.toLowerCase().includes("windows")}catch{return!1}},m=()=>{try{return globalThis.process?.platform==="darwin"?!0:/macintosh|mac os x/i.test(navigator.userAgent.toLowerCase())}catch{return!1}},v=()=>{try{return globalThis.process?.platform==="linux"?!0:/linux/i.test(navigator.userAgent.toLowerCase())}catch{return!1}},h=(e={})=>{const{mobileBreakpoint:o=700,debug:s=!1}=e,[t,r]=w(()=>({isMobile:l(o),isAndroid:b(),isIOS:u(),isWebView:d(),screenWidth:window.innerWidth})),a=p((n,i)=>{s&&console.log(`[useMobileDetection] ${n}`,i||"")},[s]);return c(()=>{const n=()=>{const i={isMobile:l(o),isAndroid:b(),isIOS:u(),isWebView:d(),screenWidth:window.innerWidth};(i.isMobile!==t.isMobile||i.screenWidth!==t.screenWidth)&&(a("Mobile detection state changed",i),r(i))};return window.addEventListener("resize",n),window.addEventListener("orientationchange",n),()=>{window.removeEventListener("resize",n),window.removeEventListener("orientationchange",n)}},[o,t.isMobile,t.screenWidth,a]),c(()=>{a("Initial mobile detection",t)},[]),t};var M=h;export{l as checkMobileDevice,M as default,b as isAndroid,u as isIOS,v as isLinux,m as isMacOS,d as isWebView,f as isWindows,h as useMobileDetection};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as c,useCallback as s}from"react";const u=()=>`${Date.now()}-${Math.random().toString(36).substr(2,9)}`,C=(p={})=>{const{maxNotifications:m=50,initialZIndex:e=1e5,toastAutoDismiss:S=8e3}=p,[g,a]=c([]),[x,N]=c([]),[D,r]=c([]),[U,b]=c(e),I=g.filter(i=>!i.isRead).length,d=s(i=>{const t={...i,id:u(),timestamp:new Date().toISOString(),isRead:!1};return a(o=>[t,...o.slice(0,m-1)]),t},[m]),R=s(i=>{const t=`toast-${u()}`;return N(o=>[...o,{...i,id:t}]),t},[]),v=s(i=>{const t=d(i);let o;return r(n=>{const l=n.length,k=20,Z=typeof window<"u"?window.innerHeight-250:500,z=l*-220;return o={...t,position:{x:k,y:Z+z},zIndex:e+l+1},[...n,o]}),b(n=>n+1),o},[d,e]),f=s(i=>{a(t=>t.map(o=>o.id===i?{...o,isRead:!0}:o))},[]),P=s(()=>{a(i=>i.map(t=>({...t,isRead:!0})))},[]),T=s(i=>{a(t=>t.filter(o=>o.id!==i))},[]),A=s(()=>{a([])},[]),O=s(i=>{N(t=>t.filter(o=>o.id!==i))},[]),w=s(i=>{r(t=>t.filter(o=>o.id!==i)),f(i)},[f]),y=s(i=>{r(t=>{const o=Math.max(...t.map(n=>n.zIndex),e);return t.map(n=>n.id===i?{...n,zIndex:o+1}:n)})},[e]),h=s((i,t)=>{r(o=>o.map(n=>n.id===i?{...n,position:t}:n))},[]);return{notifications:g,toastNotifications:x,dialogNotifications:D,unreadCount:I,addNotification:d,addToast:R,addDialogNotification:v,markAsRead:f,markAllAsRead:P,removeNotification:T,clearAllNotifications:A,removeToast:O,removeDialogNotification:w,bringDialogToFront:y,updateDialogPosition:h}};var M=C;export{M as default,C as useNotifications};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as r,useEffect as c}from"react";const a=()=>{const t=r(null),i=e=>{typeof window<"u"&&window.dispatchEvent(new MessageEvent("quickSearch",{data:{value:e}}))},n=e=>{t[1](e.data?.value??null)};return c(()=>{if(typeof window<"u")return window.addEventListener("quickSearch",n),()=>{window.removeEventListener("quickSearch",n)}},[]),{quickSearchUseState:t,sendQuickSearchEvent:i}};var u=a;export{u as default,a as useQuickSearch};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{useState as d,useEffect as t}from"react";const o=()=>{const[i,n]=d({width:void 0,height:void 0});return t(()=>{function e(){n({width:window.innerWidth,height:window.innerHeight})}return window.addEventListener("resize",e),e(),()=>window.removeEventListener("resize",e)},[]),i};export{o as useWindowSize};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{dashStorage as t}from"./dashDtorage";const s=["token","authenticated","user","roles","tenant_id","user_id"],i=["token","tenant_id","user_id"],u=(e={})=>async r=>{console.log("\u{1F513} logoutFromStorage called:",r||"no reason provided");try{e.clearAuthPersistence&&e.clearAuthPersistence(),[...s,...e.additionalKeys||[]].forEach(o=>{t.removeItem(o)}),e.removeCookies&&e.removeCookies(i),e.syncToDeviceStore&&await e.syncToDeviceStore(),console.log("\u2705 Auth data cleared successfully")}catch(n){console.error("\u274C Error clearing auth data:",n)}},a=()=>{try{const e=JSON.parse(t.getItem("authenticated")||"false"),r=JSON.parse(t.getItem("user")||"null");return e&&r?.id}catch{return!1}},c=()=>{try{return JSON.parse(t.getItem("user")||"null")}catch{return null}},d=()=>t.getItem("token"),l=()=>t.getItem("tenant_id"),g=()=>{try{return JSON.parse(t.getItem("roles")||"[]")}catch{return[]}},m=e=>{e.token!==void 0&&t.setItem("token",e.token),e.user!==void 0&&t.setItem("user",JSON.stringify(e.user)),e.roles!==void 0&&t.setItem("roles",JSON.stringify(e.roles)),e.authenticated!==void 0&&t.setItem("authenticated",JSON.stringify(e.authenticated)),e.tenant_id!==void 0&&t.setItem("tenant_id",e.tenant_id),e.user_id!==void 0&&t.setItem("user_id",e.user_id)};var h={createLogoutFromStorage:u,isUserAuthenticated:a,getCurrentUser:c,getAuthToken:d,getTenantId:l,getUserRoles:g,setAuthData:m};export{u as createLogoutFromStorage,h as default,d as getAuthToken,c as getCurrentUser,l as getTenantId,g as getUserRoles,a as isUserAuthenticated,m as setAuthData};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{syncElectronStore as o}from"./electronStoreSync";import{applyPlatformBodyClasses as t}from"./platformDetection";import{requestNotificationPermission as i}from"./notificationPermission";const c=async(e={})=>{const{requestNotifications:a=!0,syncElectron:s=!0,applyPlatformClasses:r=!0}=e;s&&await o(),r&&t(),a&&await i()},n=()=>{o(),t(),i()};var m=n;export{n as dashBootstrapApp,c as dashInitializeApp,m as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var s=Object.defineProperty;var l=(r,e,t)=>e in r?s(r,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):r[e]=t;var i=(r,e,t)=>l(r,typeof e!="symbol"?e+"":e,t);class o{getItem(e){const t=window.localStorage.getItem(e);if(!t)return null;try{return JSON.parse(t)}catch{return t}}setItem(e,t){window.localStorage.setItem(e,JSON.stringify(t))}removeItem(e){window.localStorage.removeItem(e)}clear(){window.localStorage.clear()}}const a=class a{static get layer(){return a.localLayer}static getItem(e){return this.layer.getItem(e)}static setItem(e,t){this.layer.setItem(e,t)}static removeItem(e){this.layer.removeItem(e)}static clear(){this.layer.clear()}};i(a,"localLayer",new o);let n=a;export{n as dashStorage};
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { getEnv } from "./envUtils";
|
|
2
|
+
|
|
3
|
+
type StorageType = 'localStorage' | 'electronStore';
|
|
4
|
+
|
|
5
|
+
interface PersistanceLayer {
|
|
6
|
+
getItem<T = any>(key: string): T | null;
|
|
7
|
+
setItem<T = any>(key: string, value: T): void;
|
|
8
|
+
removeItem(key: string): void;
|
|
9
|
+
clear(): void;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
class LocalStorageLayer implements PersistanceLayer {
|
|
13
|
+
/*getItem<T = any>(key: string): T | null {
|
|
14
|
+
const item = window.localStorage.getItem(key);
|
|
15
|
+
return item ? JSON.parse(item) : null;
|
|
16
|
+
}*/
|
|
17
|
+
getItem<T = any>(key: string): T | null {
|
|
18
|
+
const item = window.localStorage.getItem(key);
|
|
19
|
+
if (!item) return null;
|
|
20
|
+
try {
|
|
21
|
+
return JSON.parse(item);
|
|
22
|
+
} catch {
|
|
23
|
+
// Return as string if not valid JSON
|
|
24
|
+
return item as any;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
setItem<T = any>(key: string, value: T): void {
|
|
28
|
+
window.localStorage.setItem(key, JSON.stringify(value));
|
|
29
|
+
}
|
|
30
|
+
removeItem(key: string): void {
|
|
31
|
+
window.localStorage.removeItem(key);
|
|
32
|
+
}
|
|
33
|
+
clear(): void {
|
|
34
|
+
window.localStorage.clear();
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
class ElectronStoreLayer implements PersistanceLayer {
|
|
39
|
+
getItem<T = any>(key: string): T | null {
|
|
40
|
+
return (window as any).electronStore?.get(key) ?? null;
|
|
41
|
+
}
|
|
42
|
+
setItem<T = any>(key: string, value: T): void {
|
|
43
|
+
(window as any).electronStore?.set(key, value);
|
|
44
|
+
}
|
|
45
|
+
removeItem(key: string): void {
|
|
46
|
+
(window as any).electronStore?.delete(key);
|
|
47
|
+
}
|
|
48
|
+
clear(): void {
|
|
49
|
+
(window as any).electronStore?.clear();
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export class dashStorage {
|
|
54
|
+
private static get layer(): PersistanceLayer {
|
|
55
|
+
const storageType = (getEnv('APP_STORAGE_TYPE') as StorageType) || 'localStorage';
|
|
56
|
+
if (storageType === 'electronStore' && (window as any).electronStore) {
|
|
57
|
+
return dashStorage.electronLayer;
|
|
58
|
+
} else {
|
|
59
|
+
return dashStorage.localLayer;
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
private static localLayer = new LocalStorageLayer();
|
|
64
|
+
private static electronLayer = new ElectronStoreLayer();
|
|
65
|
+
|
|
66
|
+
static getItem<T = any>(key: string): T | null {
|
|
67
|
+
return this.layer.getItem<T>(key);
|
|
68
|
+
}
|
|
69
|
+
static setItem<T = any>(key: string, value: T): void {
|
|
70
|
+
this.layer.setItem<T>(key, value);
|
|
71
|
+
}
|
|
72
|
+
static removeItem(key: string): void {
|
|
73
|
+
this.layer.removeItem(key);
|
|
74
|
+
}
|
|
75
|
+
static clear(): void {
|
|
76
|
+
this.layer.clear();
|
|
77
|
+
}
|
|
78
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=()=>typeof window<"u"&&!!window.DashIPCService,i=()=>r(),o=()=>{if(typeof window<"u")return window.DashIPCService},a=t=>{const e=o();return e?(e.windowControls(t),!0):!1},s=()=>{const t=o();return t?(t.startDrag(),!0):!1},c=(t,e)=>{const n=o();return n?(n.action(t,e),!0):!1},d=t=>{const e=o();return e&&e.onStdout?(e.onStdout(t),!0):!1},l=t=>{const e=o();return e&&e.onElectronLog?(e.onElectronLog(t),!0):!1},u=t=>{const e=o();return e&&e.onSubprocessOutput?(e.onSubprocessOutput(t),!0):!1},p=()=>{const t=o();return{isAvailable:r(),isElectron:i(),service:t,windowControl:a,startWindowDrag:s,executeAction:c,onStdout:d,onElectronLog:l,onSubprocessOutput:u}};var g={isDashIPCServiceAvailable:r,isElectron:i,getDashIPCService:o,windowControl:a,startWindowDrag:s,executeIPCAction:c,onIPCStdout:d,onElectronLog:l,onSubprocessOutput:u,useDashIPCService:p};export{g as default,c as executeIPCAction,o as getDashIPCService,r as isDashIPCServiceAvailable,i as isElectron,l as onElectronLog,d as onIPCStdout,u as onSubprocessOutput,s as startWindowDrag,p as useDashIPCService,a as windowControl};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
var l=Object.defineProperty;var C=(r,e,n)=>e in r?l(r,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):r[e]=n;var R=(r,e,n)=>C(r,typeof e!="symbol"?e+"":e,n);class T{constructor(){R(this,"configs",[])}setConfigs(e){this.configs=e}getConfigs(){return this.configs}getConfig(e){const n=this.configs.find(t=>t.model===e);return n||this.configs.find(t=>{const s=t.model||"";return e.startsWith(s)||s.startsWith(e)})}clear(){this.configs=[]}}let c=null;const g=()=>(c||(c=new T),c),m=r=>{g().setConfigs(r)},d=r=>g().getConfig(r),F=(r,e,n)=>{const t=d(r);let s={...e};return Object.keys(s).forEach(o=>{s[o]===void 0&&delete s[o]}),t?.dataTransform&&(s=t.dataTransform(s,n)),s},h=(r,e)=>{const n=new FormData,t=(s,o,p="")=>{const a=p?`${p}[${s}]`:s;o!=null&&(o instanceof File?n.append(a,o):typeof FileList<"u"&&o instanceof FileList?Array.from(o).forEach((i,f)=>{n.append(`${a}[${f}]`,i)}):Array.isArray(o)?o.forEach((i,f)=>{typeof i=="object"&&!(i instanceof File)?Object.keys(i).forEach(u=>{t(u,i[u],`${a}[${f}]`)}):n.append(`${a}[${f}]`,i)}):typeof o=="object"&&!(o instanceof Date)?o.rawFile&&o.rawFile instanceof File?n.append(a,o.rawFile):Object.keys(o).forEach(i=>{t(i,o[i],a)}):typeof o=="boolean"?n.append(a,o?"1":"0"):n.append(a,String(o)))};return Object.keys(e).forEach(s=>{t(s,e[s])}),n},y=r=>{const e=new URLSearchParams;return Object.keys(r).forEach(n=>{const t=r[n];t!=null&&(Array.isArray(t)?t.forEach(s=>{e.append(`${n}[]`,String(s))}):typeof t=="object"?e.append(n,JSON.stringify(t)):e.append(n,String(t)))}),e.toString()},D=(r,e)=>d(r)?.isFormData===!0||e?.data?.isFormData===!0||e?.meta?.isFormData===!0;var x={getResourceConfigManager:g,setResourceConfigs:m,getResourceConfig:d,processPostData:F,processFormData:h,buildQueryString:y,isFormDataResource:D};export{y as buildQueryString,x as default,d as getResourceConfig,g as getResourceConfigManager,D as isFormDataResource,h as processFormData,F as processPostData,m as setResourceConfigs};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=async()=>{if(!(typeof window>"u"||!window.electronStore))try{const o=await window.electronStore.syncToLocalStorage();Object.entries(o).forEach(([e,t])=>{window.localStorage.setItem(e,JSON.stringify(t))}),console.log("Electron store synced to localStorage")}catch(o){console.error("Failed to sync Electron store:",o)}},n=()=>typeof window<"u"&&!!window.electronStore;var c=r;export{c as default,n as hasElectronStore,r as syncElectronStore};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=n=>process.env[n]||null,s=n=>{const e=process.env.ENV_PREFIX||process.env.NEXT_PUBLIC_ENV_PREFIX||process.env.VITE_ENV_PREFIX||process.env.REACT_ENV_PREFIX||"VITE_";return e==="NEXT_PUBLIC_"?r(e+n):process.env[e+n]||null};export{s as getEnv};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const r=n=>{if(typeof document>"u")return()=>{};const{PLATFORM_TYPE:o,IS_ELECTRON:e,IS_MAC:t,IS_WINDOWS:d,IS_LINUX:i}=n,s=[];return o&&(document.body.classList.add(o),s.push(o)),e&&(document.body.classList.add("electron"),s.push("electron")),t&&(document.body.classList.add("mac"),s.push("mac")),d&&(document.body.classList.add("windows"),s.push("windows")),i&&(document.body.classList.add("linux"),s.push("linux")),()=>{s.forEach(a=>{document.body.classList.remove(a)})}},c=n=>{};var u=r;export{u as default,r as setupEnvironmentBodyClasses,c as useEnvironmentBodyClasses};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=()=>{try{if(typeof globalThis<"u"&&globalThis.process?.env?.NODE_ENV)return globalThis.process.env.NODE_ENV}catch{}},t=()=>{if(typeof window>"u")return n()==="development";const{hostname:e}=window.location;return e==="localhost"||e==="127.0.0.1"||e.startsWith("192.168.")||e.endsWith(".local")||e.includes("dev.")},r=()=>!t(),o=()=>n()==="test",s=()=>o()?"test":t()?"development":"production";var i=t;export{i as default,s as getEnvironment,t as isDev,r as isProd,o as isTest};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const i=async()=>"Notification"in window&&Notification.permission==="default"?await Notification.requestPermission():Notification.permission??null,o=()=>"Notification"in window,n=()=>"Notification"in window&&Notification.permission==="granted",t=()=>"Notification"in window&&Notification.permission==="denied",e=()=>"Notification"in window?Notification.permission:null;export{e as getNotificationPermission,n as hasNotificationPermission,t as isNotificationDenied,o as isNotificationSupported,i as requestNotificationPermission};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const t=()=>{if(typeof navigator>"u")return!1;const e=navigator.userAgent.toLowerCase();return console.log("userAgent",e),/(webview|wv)/.test(e)||/android.*(wv|.net)/.test(e)||/iphone|ipod|ipad.*applewebkit(?!.*safari)/i.test(e)},n=()=>typeof navigator>"u"?!1:/android/i.test(navigator.userAgent.toLowerCase()),r=()=>typeof navigator>"u"?!1:/iphone|ipad|ipod/i.test(navigator.userAgent.toLowerCase()),s=()=>{try{return globalThis.process?.platform==="win32"||typeof navigator<"u"&&navigator.userAgent.toLowerCase().includes("windows")}catch(e){return console.error("Error checking Windows platform:",e),!1}},a=()=>{if(!(typeof document>"u")&&(s()&&document.body.classList.add("windows"),t()&&(console.log("webview"),document.body.classList.add("webview"),n()&&document.body.classList.add("android"),r()&&document.body.classList.add("ios")),typeof navigator<"u"&&navigator.userAgent)){const o=navigator.userAgent.toLowerCase().replace(/[^a-z0-9]/g,"-").replace(/-+/g,"-").replace(/^-|-$/g,"").substring(0,100);o&&document.body.classList.add(`ua-${o}`)}};var i={isWebView:t,isAndroid:n,isIOS:r,isWindows:s,applyPlatformBodyClasses:a};export{a as applyPlatformBodyClasses,i as default,n as isAndroid,r as isIOS,t as isWebView,s as isWindows};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const n=(r,e="CLP")=>{const t=typeof r=="number"?r:parseFloat(String(r));return isNaN(t)?"$0":e==="CLP"?`$${Math.round(t).toLocaleString("es-CL")}`:Number.isInteger(t)?`$${t.toLocaleString("en-US")}`:`$${t.toLocaleString("en-US",{minimumFractionDigits:2,maximumFractionDigits:2})}`};var o=n;export{o as default,n as priceFormatter};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const s=l=>{let e=null,r=null;return{getResources:async()=>e||r||(r=l().then(o=>(e=o,r=null,o)).catch(o=>{throw r=null,console.error("Failed to load resources:",o),o}),r),resources:[],clearCache:()=>{e=null,r=null},isLoaded:()=>e!==null}},a=l=>{let e=null;return async()=>e||(e=await l(),e)};var i=s;export{s as createResourceLoader,a as createSimpleResourceLoader,i as default};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import{dashStorage as t}from"./dashDtorage";const m=()=>t.getItem("theme"),r=e=>{t.setItem("theme",e),typeof document<"u"&&document.documentElement.setAttribute("data-theme",e)},d=e=>{const o=m(),n=o||e;return typeof document<"u"&&document.documentElement.setAttribute("data-theme",n),o||t.setItem("theme",e),n},i=()=>{t.removeItem("theme"),typeof document<"u"&&document.documentElement.removeAttribute("data-theme")};var u={getStoredTheme:m,setStoredTheme:r,initializeStoredTheme:d,clearStoredTheme:i};export{i as clearStoredTheme,u as default,m as getStoredTheme,d as initializeStoredTheme,r as setStoredTheme};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function h(a){return getComputedStyle(document.documentElement).getPropertyValue(`--${a}`).trim()||void 0}function y(a=document.styleSheets){const t=new Set;for(let c=0;c<a.length;c++){const g=a[c];let s;try{s=g.cssRules}catch{continue}if(s)for(let r=0;r<s.length;r++){const n=s[r];if("style"in n&&n.style){const i=n.style;for(let l=0;l<i.length;l++){const o=i[l];o.startsWith("--")&&t.add(o)}}}}return Array.from(t)}function S(){const a={};for(let t=0;t<document.styleSheets.length;t++){const c=document.styleSheets[t];if(c.ownerNode?.id!=="dash-theme-variables")try{const s=c.cssRules;if(!s)continue;for(let r=0;r<s.length;r++){const n=s[r];if("selectorText"in n&&n.selectorText===":root"){const i=n.style;for(let l=0;l<i.length;l++){const o=i[l];o.startsWith("--")&&(a[o]=i.getPropertyValue(o).trim())}}}}catch{continue}}return a}const m=(a,t,c)=>{const s=`--${a}`,r=["primary-color--light","primary-color--dark","primary-contrast--light","primary-contrast--dark"];let n=document.getElementById("dash-theme-variables");n||(n=document.createElement("style"),n.id="dash-theme-variables"),document.head.appendChild(n);let i="";c&&Object.entries(c).forEach(([e,u])=>{i+=`--${e}: ${u}; `});const l=t?void 0:S(),o=new Set;t?Object.keys(t).forEach(e=>o.add(e)):Object.keys(l).forEach(e=>{o.add(e.slice(2))}),r.forEach(e=>o.add(e)),o.forEach(e=>{let u=t?.[e];if(!u&&l&&(u=l[`--${e}`]),u||(u=h(e)),u){const f=e.includes("--"),d=e.endsWith(s);(!f||d)&&(i+=`--${e}: ${u}; `,r.includes(e))}if(e.endsWith(s)){const f=e.slice(0,-s.length);let d=t?.[e];!d&&l&&(d=l[`--${e}`]),d||(d=h(e)),d&&(i+=`--${f}: ${d}; `,r.includes(`${f}${s}`))}}),n.textContent=`:root { ${i} }`};var $=m;export{$ as default,m as updateDomCssVariables};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const l=/^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/,u=t=>!t||typeof t!="string"?!1:l.test(t.trim()),g=/^\+?[\d\s\-()]{7,20}$/,p=t=>!t||typeof t!="string"?!1:g.test(t.trim()),c=/^(https?:\/\/)?([\da-z.-]+)\.([a-z.]{2,6})([/\w .-]*)*\/?$/i,d=t=>!t||typeof t!="string"?!1:c.test(t.trim()),h=t=>{if(!t)return"weak";let e=0;return t.length>=8&&e++,t.length>=12&&e++,/[a-z]/.test(t)&&e++,/[A-Z]/.test(t)&&e++,/[0-9]/.test(t)&&e++,/[^a-zA-Z0-9]/.test(t)&&e++,e<=2?"weak":e<=3?"fair":e<=4?"good":"strong"},x=t=>t==null?!1:typeof t=="string"?t.trim().length>0:Array.isArray(t)?t.length>0:!0,y=(t,e)=>!t||typeof t!="string"?!1:t.trim().length>=e,A=(t,e)=>!t||typeof t!="string"?!0:t.trim().length<=e,z=t=>{if(!t||typeof t!="string")return!1;const e=t.replace(/[.-]/g,"").toUpperCase();if(e.length<2)return!1;const s=e.slice(0,-1),f=e.slice(-1);let a=0,r=2;for(let o=s.length-1;o>=0;o--)a+=parseInt(s[o],10)*r,r=r===7?2:r+1;const i=11-a%11;let n;return i===11?n="0":i===10?n="K":n=i.toString(),f===n};export{l as EMAIL_REGEX,g as PHONE_REGEX,c as URL_REGEX,h as checkPasswordStrength,u as validateEmail,A as validateMaxLength,y as validateMinLength,p as validatePhone,x as validateRequired,z as validateRut,d as validateUrl};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@dashadmin/dash-utils",
|
|
3
|
-
"version": "1.3.
|
|
3
|
+
"version": "1.3.21",
|
|
4
4
|
"private": false,
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"main": "src/index.ts",
|
|
@@ -38,13 +38,24 @@
|
|
|
38
38
|
"exports": {
|
|
39
39
|
".": {
|
|
40
40
|
"import": "./dist/index.js"
|
|
41
|
+
},
|
|
42
|
+
"./src/*": {
|
|
43
|
+
"import": "./dist/*.js"
|
|
41
44
|
}
|
|
42
45
|
}
|
|
43
46
|
},
|
|
44
47
|
"scripts": {
|
|
45
|
-
"build": "vite build"
|
|
48
|
+
"build": "rm -rf dist && node ../dash-build/compile.mjs && vite build"
|
|
46
49
|
},
|
|
47
50
|
"files": [
|
|
48
51
|
"dist"
|
|
49
|
-
]
|
|
52
|
+
],
|
|
53
|
+
"exports": {
|
|
54
|
+
".": {
|
|
55
|
+
"import": "./src/index.ts"
|
|
56
|
+
},
|
|
57
|
+
"./src/*": {
|
|
58
|
+
"import": "./src/*"
|
|
59
|
+
}
|
|
60
|
+
}
|
|
50
61
|
}
|