web-mojo 2.3.2 → 2.3.5
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/CHANGELOG.md +192 -5
- package/dist/admin-models.cjs.js +1 -1
- package/dist/admin-models.es.js +1 -1
- package/dist/admin.cjs.js +1 -1
- package/dist/admin.es.js +1 -1
- package/dist/auth.cjs.js +1 -1
- package/dist/auth.es.js +1 -1
- package/dist/charts.cjs.js +1 -1
- package/dist/charts.es.js +1 -1
- package/dist/chunks/{AssistantPanelView-D-0f5hZS.js → AssistantPanelView-CvjzGGS8.js} +2 -2
- package/dist/chunks/{AssistantPanelView-D-0f5hZS.js.map → AssistantPanelView-CvjzGGS8.js.map} +1 -1
- package/dist/chunks/{AssistantPanelView-72i9d6rq.js → AssistantPanelView-D3WCWj5q.js} +2 -2
- package/dist/chunks/{AssistantPanelView-72i9d6rq.js.map → AssistantPanelView-D3WCWj5q.js.map} +1 -1
- package/dist/chunks/{ChatView-ys5MIiBf.js → ChatView-B-2JVhM3.js} +2 -2
- package/dist/chunks/{ChatView-ys5MIiBf.js.map → ChatView-B-2JVhM3.js.map} +1 -1
- package/dist/chunks/{ChatView-CXykdAV1.js → ChatView-oZ9FggEo.js} +2 -2
- package/dist/chunks/{ChatView-CXykdAV1.js.map → ChatView-oZ9FggEo.js.map} +1 -1
- package/dist/chunks/{Collection-CY6BblFn.js → Collection-BtSHP_BV.js} +2 -2
- package/dist/chunks/{Collection-CY6BblFn.js.map → Collection-BtSHP_BV.js.map} +1 -1
- package/dist/chunks/{Collection-BpUmNuDZ.js → Collection-CtSGTegm.js} +2 -2
- package/dist/chunks/{Collection-BpUmNuDZ.js.map → Collection-CtSGTegm.js.map} +1 -1
- package/dist/chunks/{ContextMenu-XQVFU0mL.js → ContextMenu-0KtfqyQm.js} +2 -2
- package/dist/chunks/{ContextMenu-XQVFU0mL.js.map → ContextMenu-0KtfqyQm.js.map} +1 -1
- package/dist/chunks/{ContextMenu-PtN50qH2.js → ContextMenu-DvQTJA49.js} +2 -2
- package/dist/chunks/{ContextMenu-PtN50qH2.js.map → ContextMenu-DvQTJA49.js.map} +1 -1
- package/dist/chunks/{DataView-BTi_BZHx.js → DataView-DJMOmlKN.js} +2 -2
- package/dist/chunks/{DataView-BTi_BZHx.js.map → DataView-DJMOmlKN.js.map} +1 -1
- package/dist/chunks/{DataView-WHRh1o6E.js → DataView-jHxX-6Gh.js} +2 -2
- package/dist/chunks/{DataView-WHRh1o6E.js.map → DataView-jHxX-6Gh.js.map} +1 -1
- package/dist/chunks/{FormView-DTD-Zy22.js → FormView-C_7xQuI4.js} +3 -3
- package/dist/chunks/{FormView-DTD-Zy22.js.map → FormView-C_7xQuI4.js.map} +1 -1
- package/dist/chunks/{FormView-BzaGMf5_.js → FormView-D8YrH2V4.js} +3 -3
- package/dist/chunks/{FormView-BzaGMf5_.js.map → FormView-D8YrH2V4.js.map} +1 -1
- package/dist/chunks/{ListView-BsnnTcmC.js → ListView-CjJ-4gD7.js} +2 -2
- package/dist/chunks/{ListView-BsnnTcmC.js.map → ListView-CjJ-4gD7.js.map} +1 -1
- package/dist/chunks/{ListView-Xf7kO6Me.js → ListView-mr1Kmuj-.js} +2 -2
- package/dist/chunks/{ListView-Xf7kO6Me.js.map → ListView-mr1Kmuj-.js.map} +1 -1
- package/dist/chunks/{MetricsCountryMapView-BzGOi1d2.js → MetricsCountryMapView-BIsfmvE0.js} +2 -2
- package/dist/chunks/{MetricsCountryMapView-BzGOi1d2.js.map → MetricsCountryMapView-BIsfmvE0.js.map} +1 -1
- package/dist/chunks/{MetricsCountryMapView-C-S00Wiw.js → MetricsCountryMapView-D9J4Gwdi.js} +2 -2
- package/dist/chunks/{MetricsCountryMapView-C-S00Wiw.js.map → MetricsCountryMapView-D9J4Gwdi.js.map} +1 -1
- package/dist/chunks/Modal-DF98u_sN.js +3 -0
- package/dist/chunks/Modal-DF98u_sN.js.map +1 -0
- package/dist/chunks/Modal-DYJadSN8.js +3 -0
- package/dist/chunks/Modal-DYJadSN8.js.map +1 -0
- package/dist/chunks/Passkeys-8ko7Rg8G.js +2 -0
- package/dist/chunks/Passkeys-8ko7Rg8G.js.map +1 -0
- package/dist/chunks/Passkeys-CD8RKUl8.js +2 -0
- package/dist/chunks/Passkeys-CD8RKUl8.js.map +1 -0
- package/dist/chunks/TokenManager-B-xR8zPl.js +2 -0
- package/dist/chunks/TokenManager-B-xR8zPl.js.map +1 -0
- package/dist/chunks/TokenManager-CZTL4OqZ.js +2 -0
- package/dist/chunks/TokenManager-CZTL4OqZ.js.map +1 -0
- package/dist/chunks/{User-KTBU_5cr.js → User-C6Tbn6vZ.js} +2 -2
- package/dist/chunks/User-C6Tbn6vZ.js.map +1 -0
- package/dist/chunks/{User-B_Urf7U7.js → User-DRbw-wOB.js} +2 -2
- package/dist/chunks/User-DRbw-wOB.js.map +1 -0
- package/dist/chunks/{UserProfileView-BmduMJ86.js → UserProfileView-DC70hRer.js} +2 -2
- package/dist/chunks/{UserProfileView-COxSyPB0.js.map → UserProfileView-DC70hRer.js.map} +1 -1
- package/dist/chunks/{UserProfileView-COxSyPB0.js → UserProfileView-TQ9BqUE2.js} +2 -2
- package/dist/chunks/{UserProfileView-BmduMJ86.js.map → UserProfileView-TQ9BqUE2.js.map} +1 -1
- package/dist/chunks/{View-C8UWvaSM.js → View-BWOE7WJm.js} +2 -2
- package/dist/chunks/{View-C8UWvaSM.js.map → View-BWOE7WJm.js.map} +1 -1
- package/dist/chunks/{View-Cvs2TY7b.js → View-D6Ug7M6k.js} +2 -2
- package/dist/chunks/{View-Cvs2TY7b.js.map → View-D6Ug7M6k.js.map} +1 -1
- package/dist/chunks/{WebApp-kbRq7dM_.js → WebApp-By80XfTK.js} +2 -2
- package/dist/chunks/{WebApp-kbRq7dM_.js.map → WebApp-By80XfTK.js.map} +1 -1
- package/dist/chunks/{WebApp-DuwanN2O.js → WebApp-CLTFSbto.js} +2 -2
- package/dist/chunks/{WebApp-DuwanN2O.js.map → WebApp-CLTFSbto.js.map} +1 -1
- package/dist/chunks/{admin-BcJ_hgzn.js → admin-CXA-Vkhf.js} +2 -2
- package/dist/chunks/{admin-BcJ_hgzn.js.map → admin-CXA-Vkhf.js.map} +1 -1
- package/dist/chunks/{admin-DtjMWe6R.js → admin-DcLy2QC2.js} +2 -2
- package/dist/chunks/{admin-DtjMWe6R.js.map → admin-DcLy2QC2.js.map} +1 -1
- package/dist/chunks/{exportChart-Dn2pioNl.js → exportChart-BQXkqsxe.js} +2 -2
- package/dist/chunks/{exportChart-Dn2pioNl.js.map → exportChart-BQXkqsxe.js.map} +1 -1
- package/dist/chunks/{exportChart-Bkxr7mCe.js → exportChart-UQ5nq_mR.js} +2 -2
- package/dist/chunks/{exportChart-Bkxr7mCe.js.map → exportChart-UQ5nq_mR.js.map} +1 -1
- package/dist/chunks/{index-CJeTVskY.js → index-C9wf7N-j.js} +2 -2
- package/dist/chunks/{index-CJeTVskY.js.map → index-C9wf7N-j.js.map} +1 -1
- package/dist/chunks/{index-BCWkcyOy.js → index-TqW1pAMX.js} +2 -2
- package/dist/chunks/{index-BCWkcyOy.js.map → index-TqW1pAMX.js.map} +1 -1
- package/dist/chunks/{version-DkxW4rIi.js → version-Bdrq2emC.js} +2 -2
- package/dist/chunks/{version-DkxW4rIi.js.map → version-Bdrq2emC.js.map} +1 -1
- package/dist/chunks/{version-CB0Ssm9c.js → version-xpJSWoyH.js} +2 -2
- package/dist/chunks/{version-CB0Ssm9c.js.map → version-xpJSWoyH.js.map} +1 -1
- package/dist/core.css +68 -209
- package/dist/css/web-mojo.css +1 -1
- package/dist/docit.cjs.js +1 -1
- package/dist/docit.es.js +1 -1
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +1 -1
- package/dist/index.es.js.map +1 -1
- package/dist/lightbox.cjs.js +1 -1
- package/dist/lightbox.es.js +1 -1
- package/dist/map.cjs.js +1 -1
- package/dist/map.es.js +1 -1
- package/dist/timeline.cjs.js +1 -1
- package/dist/timeline.es.js +1 -1
- package/dist/user-profile.cjs.js +1 -1
- package/dist/user-profile.es.js +1 -1
- package/dist/web-mojo.lite.iife.js +95 -168
- package/dist/web-mojo.lite.iife.js.map +1 -1
- package/dist/web-mojo.lite.iife.min.js +98 -98
- package/dist/web-mojo.lite.iife.min.js.map +1 -1
- package/package.json +3 -1
- package/dist/chunks/Modal-GWjyfcz5.js +0 -3
- package/dist/chunks/Modal-GWjyfcz5.js.map +0 -1
- package/dist/chunks/Modal-wrfWfQhv.js +0 -3
- package/dist/chunks/Modal-wrfWfQhv.js.map +0 -1
- package/dist/chunks/Passkeys-BviQX3_5.js +0 -2
- package/dist/chunks/Passkeys-BviQX3_5.js.map +0 -1
- package/dist/chunks/Passkeys-gXR1Rc6C.js +0 -2
- package/dist/chunks/Passkeys-gXR1Rc6C.js.map +0 -1
- package/dist/chunks/TokenManager-C6aXkRaI.js +0 -2
- package/dist/chunks/TokenManager-C6aXkRaI.js.map +0 -1
- package/dist/chunks/TokenManager-DgvhhTqN.js +0 -2
- package/dist/chunks/TokenManager-DgvhhTqN.js.map +0 -1
- package/dist/chunks/User-B_Urf7U7.js.map +0 -1
- package/dist/chunks/User-KTBU_5cr.js.map +0 -1
package/dist/auth.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{B as e,V as s,a as t,b as n,c as o,d as r}from"./chunks/version-CB0Ssm9c.js";function a({baseURL:e,fetchImpl:s=("undefined"!=typeof fetch?fetch.bind(window):null),storage:t=("undefined"!=typeof localStorage?localStorage:null),endpoints:n={}}={}){if(!e)throw new Error("createAuthClient: baseURL is required");if(!s)throw new Error("createAuthClient: fetch implementation is not available in this environment");if(!t)throw new Error("createAuthClient: storage (localStorage) is not available in this environment");const o="access_token",r="refresh_token",a="user",i={login:"/login",forgot:"/auth/forgot",resetCode:"/auth/password/reset/code",resetToken:"/auth/password/reset/token",exchange:"/auth/exchange",...n};let l=null;async function d(t,n){const o=await s(`${e}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n||{})});let r={};try{r=await o.json()}catch(a){}if(!o.ok)throw r||{message:`Request failed with status ${o.status}`};return r}function c(e){return e&&e.data&&e.data.data||e&&e.data||e}function u(e){const s=c(e);if(!s||!s.access_token)throw new Error("No access_token in response.");t.setItem(o,s.access_token),s.refresh_token&&t.setItem(r,s.refresh_token),s.user&&t.setItem(a,JSON.stringify(s.user))}return{async login(e,s){const t=await d(i.login,{username:e,password:s});return u(t),c(t)},forgot:async({email:e,method:s})=>d(i.forgot,{email:e,method:s}),async resetWithCode({email:e,code:s,newPassword:t}){const n=await d(i.resetCode,{email:e,code:s,new_password:t});return u(n),c(n)},async resetWithToken({token:e,newPassword:s}){const t=await d(i.resetToken,{token:e,new_password:s});return u(t),c(t)},exchangeAuthCode:async e=>l||(l=(async()=>{try{const s=await d(i.exchange,{code:e});return u(s),c(s)}finally{l=null}})(),l),async handleAuthCodeFromURL(){if("undefined"==typeof window||!window.location)return null;const e=new URLSearchParams(window.location.search),s=e.get("auth_code");if(!s)return null;e.delete("auth_code");const t=window.location.pathname+(e.toString()?`?${e.toString()}`:"")+(window.location.hash||"");return window.history.replaceState({},"",t),this.exchangeAuthCode(s)},logout(){t.removeItem(o),t.removeItem(r),t.removeItem(a)},isAuthenticated:()=>!!t.getItem(o),getToken:()=>t.getItem(o),getUser(){const e=t.getItem(a);try{return e?JSON.parse(e):null}catch{return null}},getAuthHeader(){const e=t.getItem(o);return e?`Bearer ${e}`:null},getErrorMessage:function(e){return e?.message||e?.error||Array.isArray(e?.errors)&&e.errors[0]?.message||"An error occurred. Please try again."},parseResponse:c}}function i(e,s={}){if(!(e&&e instanceof Element))throw new Error("mountAuth: container must be a DOM Element");const{baseURL:t,onSuccessRedirect:n,allowRedirectOrigins:o,branding:r={},theme:i,endpoints:l,providers:d,texts:c={}}=s;if(!t)throw new Error("mountAuth: baseURL is required");const u=new URLSearchParams(window.location.search),m=u.get("redirect")||u.get("next")||u.get("returnTo"),p=String(n||m||"/");function w(){!function(e){if(!o||0===o.length)return!0;try{const s=new URL(e,window.location.origin);return o.includes(s.origin)}catch{return!1}}(p)?window.location.href="/":window.location.href=p.startsWith("http")?p:new URL(p,window.location.origin).href}const g=a({baseURL:t,endpoints:l}),b=r.title||"Sign In",f=r.subtitle||"Sign in to your account",h=r.logoUrl||"",y={emailOrUsername:c.emailOrUsername||"Email or Username",password:c.password||"Password",signIn:c.signIn||"Sign In",forgotPassword:c.forgotPassword||"Forgot password?",resetYourPassword:c.resetYourPassword||"Reset Your Password",emailAddress:c.emailAddress||"Email Address",resetMethod:c.resetMethod||"Reset Method",emailCode:c.emailCode||"Email me a code",emailLink:c.emailLink||"Email me a magic link",sendReset:c.sendReset||"Send Reset",back:c.back||"Back",enterResetCode:c.enterResetCode||"Enter Reset Code",weSentCodeTo:c.weSentCodeTo||"We sent a code to",resetCode:c.resetCode||"Reset Code",newPassword:c.newPassword||"New Password",confirmPassword:c.confirmPassword||"Confirm Password",resetPassword:c.resetPassword||"Reset Password",setYourNewPassword:c.setYourNewPassword||"Set Your New Password",setPassword:c.setPassword||"Set Password",invalidCredentials:c.invalidCredentials||"Invalid credentials.",successRedirecting:c.successRedirecting||"Success! Redirecting...",pleaseFillAllFields:c.pleaseFillAllFields||"Please fill in all fields.",passwordsDoNotMatch:c.passwordsDoNotMatch||"Passwords do not match."},v=`\n <div class="auth-container">\n <div class="auth-card">\n <div class="auth-header">\n ${h?`<img src="${h}" alt="${b}" style="max-height:60px;margin-bottom:10px" />`:""}\n <h1 class="auth-title">${b}</h1>\n <p class="auth-subtitle">${f}</p>\n </div>\n\n <div id="status-message" class="alert" role="status" style="display:none;"></div>\n\n \x3c!-- Sign In View --\x3e\n <div id="view-signin" class="auth-view">\n <form id="form-signin" novalidate>\n <div class="mb-3">\n <label for="signin-username" class="form-label">${y.emailOrUsername}</label>\n <input type="text" class="form-control" id="signin-username" placeholder="${y.emailOrUsername}" autocomplete="username" required />\n </div>\n <div class="mb-3">\n <label for="signin-password" class="form-label">${y.password}</label>\n <input type="password" class="form-control" id="signin-password" placeholder="${y.password}" autocomplete="current-password" required />\n </div>\n <button type="submit" class="btn btn-primary w-100 mb-3" id="btn-signin">\n <span class="btn-text">${y.signIn}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n <div class="text-center">\n <a href="#" id="link-forgot" class="text-decoration-none">${y.forgotPassword}</a>\n </div>\n\n ${d&&(d.google||d.passkey)?`\n <div class="position-relative my-3">\n <hr class="text-muted" />\n <span class="position-absolute top-50 start-50 translate-middle bg-white px-3 text-muted small">OR</span>\n </div>\n <div class="d-grid gap-2">\n ${d.google?'<button type="button" class="btn btn-outline-primary" id="btn-google"><i class="bi bi-google me-2"></i>Continue with Google</button>':""}\n ${d.passkey?'<button type="button" class="btn btn-outline-secondary" id="btn-passkey"><i class="bi bi-fingerprint me-2"></i>Sign in with Passkey</button>':""}\n </div>\n `:""}\n </form>\n </div>\n\n \x3c!-- Forgot Password View --\x3e\n <div id="view-forgot" class="auth-view" style="display:none;">\n <button type="button" class="btn btn-link p-0 mb-3" id="btn-back-signin">\n <span aria-hidden="true">←</span> ${y.back}\n </button>\n <h2 class="h5 mb-3">${y.resetYourPassword}</h2>\n <form id="form-forgot" novalidate>\n <div class="mb-3">\n <label for="forgot-email" class="form-label">${y.emailAddress}</label>\n <input type="email" class="form-control" id="forgot-email" placeholder="${y.emailAddress}" autocomplete="email" required />\n </div>\n <div class="mb-3">\n <label class="form-label">${y.resetMethod}</label>\n <div class="form-check">\n <input class="form-check-input" type="radio" name="reset-method" id="method-code" value="code" checked />\n <label class="form-check-label" for="method-code">${y.emailCode}</label>\n </div>\n <div class="form-check">\n <input class="form-check-input" type="radio" name="reset-method" id="method-link" value="link" />\n <label class="form-check-label" for="method-link">${y.emailLink}</label>\n </div>\n </div>\n <button type="submit" class="btn btn-primary w-100" id="btn-forgot">\n <span class="btn-text">${y.sendReset}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n </form>\n </div>\n\n \x3c!-- Reset with Code View --\x3e\n <div id="view-reset-code" class="auth-view" style="display:none;">\n <button type="button" class="btn btn-link p-0 mb-3" id="btn-back-forgot">\n <span aria-hidden="true">←</span> ${y.back}\n </button>\n <h2 class="h5 mb-3">${y.enterResetCode}</h2>\n <p class="text-muted small mb-3">${y.weSentCodeTo} <strong id="reset-email-display"></strong></p>\n <form id="form-reset-code" novalidate>\n <div class="mb-3">\n <label for="reset-code" class="form-label">${y.resetCode}</label>\n <input type="text" class="form-control" id="reset-code" placeholder="${y.resetCode}" required />\n </div>\n <div class="mb-3">\n <label for="reset-password" class="form-label">${y.newPassword}</label>\n <input type="password" class="form-control" id="reset-password" placeholder="${y.newPassword}" autocomplete="new-password" required />\n </div>\n <div class="mb-3">\n <label for="reset-password-confirm" class="form-label">${y.confirmPassword}</label>\n <input type="password" class="form-control" id="reset-password-confirm" placeholder="${y.confirmPassword}" autocomplete="new-password" required />\n </div>\n <button type="submit" class="btn btn-primary w-100" id="btn-reset-code">\n <span class="btn-text">${y.resetPassword}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n </form>\n </div>\n\n \x3c!-- Set Password via Magic Link View --\x3e\n <div id="view-set-password" class="auth-view" style="display:none;">\n <h2 class="h5 mb-3">${y.setYourNewPassword}</h2>\n <form id="form-set-password" novalidate>\n <div class="mb-3">\n <label for="set-password" class="form-label">${y.newPassword}</label>\n <input type="password" class="form-control" id="set-password" placeholder="${y.newPassword}" autocomplete="new-password" required />\n </div>\n <div class="mb-3">\n <label for="set-password-confirm" class="form-label">${y.confirmPassword}</label>\n <input type="password" class="form-control" id="set-password-confirm" placeholder="${y.confirmPassword}" autocomplete="new-password" required />\n </div>\n <button type="submit" class="btn btn-primary w-100" id="btn-set-password">\n <span class="btn-text">${y.setPassword}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n </form>\n </div>\n </div>\n </div>\n `;e.innerHTML=v,i&&e.classList.add(String(i));const k={views:{signin:e.querySelector("#view-signin"),forgot:e.querySelector("#view-forgot"),resetCode:e.querySelector("#view-reset-code"),setPassword:e.querySelector("#view-set-password")},forms:{signin:e.querySelector("#form-signin"),forgot:e.querySelector("#form-forgot"),resetCode:e.querySelector("#form-reset-code"),setPassword:e.querySelector("#form-set-password")},buttons:{signin:e.querySelector("#btn-signin"),forgot:e.querySelector("#btn-forgot"),resetCode:e.querySelector("#btn-reset-code"),setPassword:e.querySelector("#btn-set-password"),backSignin:e.querySelector("#btn-back-signin"),backForgot:e.querySelector("#btn-back-forgot"),google:e.querySelector("#btn-google"),passkey:e.querySelector("#btn-passkey")},inputs:{signinUsername:e.querySelector("#signin-username"),signinPassword:e.querySelector("#signin-password"),forgotEmail:e.querySelector("#forgot-email"),resetCode:e.querySelector("#reset-code"),resetPassword:e.querySelector("#reset-password"),resetPasswordConfirm:e.querySelector("#reset-password-confirm"),setPassword:e.querySelector("#set-password"),setPasswordConfirm:e.querySelector("#set-password-confirm")},radios:{resetMethodCode:e.querySelector("#method-code"),resetMethodLink:e.querySelector("#method-link")},labels:{resetEmailDisplay:e.querySelector("#reset-email-display")},links:{forgot:e.querySelector("#link-forgot")},message:e.querySelector("#status-message")};function S(e){Object.entries(k.views).forEach(([s,t])=>{t&&(t.style.display=s===e?"block":"none")}),setTimeout(()=>{const s=k.views[e],t=s?.querySelector("h1, h2, .auth-title, .h5");if(t)t.setAttribute("tabindex","-1"),t.focus?.();else{const e=s?.querySelector("input, button");e?.focus?.()}},60)}function P(e,s="info"){const t=k.message;t&&(t.textContent=e,t.className=`alert alert-${s}`,t.style.display="block",t.setAttribute("role","danger"===s?"alert":"status"))}function C(){const e=k.message;e&&(e.style.display="none")}function E(e,s){if(!e)return;const t=e.querySelector(".btn-text"),n=e.querySelector(".btn-spinner");e.disabled=!!s,t&&(t.style.display=s?"none":"inline"),n&&(n.style.display=s?"inline-block":"none")}async function $(e){e?.preventDefault?.(),C();const s=k.inputs.signinUsername?.value?.trim(),t=k.inputs.signinPassword?.value;if(s&&t){E(k.buttons.signin,!0);try{await g.login(s,t),P(`${y.successRedirecting}`,"success"),setTimeout(w,350)}catch(n){P(g.getErrorMessage(n)||y.invalidCredentials,"danger"),E(k.buttons.signin,!1)}}else P("Please enter both username and password.","danger")}async function q(e){e?.preventDefault?.(),C();const s=k.inputs.forgotEmail?.value?.trim(),t=k.radios.resetMethodCode?.checked?"code":k.radios.resetMethodLink?.checked?"link":"code";if(s){E(k.buttons.forgot,!0);try{await g.forgot({email:s,method:t}),"code"===t?(sessionStorage.setItem("reset_email",s),sessionStorage.setItem("reset_method",t),k.labels.resetEmailDisplay&&(k.labels.resetEmailDisplay.textContent=s),S("resetCode"),P("Reset code sent! Check your email.","success")):P("Magic link sent! Check your email and click the link.","success")}catch(n){P(g.getErrorMessage(n)||"Something went wrong. Please try again.","danger")}finally{E(k.buttons.forgot,!1)}}else P("Please enter your email address.","danger")}async function R(e){e?.preventDefault?.(),C();const s=k.inputs.resetCode?.value?.trim(),t=k.inputs.resetPassword?.value,n=k.inputs.resetPasswordConfirm?.value,o=sessionStorage.getItem("reset_email");if(!o)return P("Session expired. Please restart the password reset process.","danger"),void S("forgot");if(s&&t)if(t===n){E(k.buttons.resetCode,!0);try{await g.resetWithCode({email:o,code:s,newPassword:t}),sessionStorage.removeItem("reset_email"),sessionStorage.removeItem("reset_method"),P(y.successRedirecting,"success"),setTimeout(w,350)}catch(r){P(g.getErrorMessage(r)||"Invalid code or code expired.","danger"),E(k.buttons.resetCode,!1)}}else P(y.passwordsDoNotMatch,"danger");else P(y.pleaseFillAllFields,"danger")}async function I(e){e?.preventDefault?.(),C();const s=k.inputs.setPassword?.value,t=k.inputs.setPasswordConfirm?.value,n=sessionStorage.getItem("login_token");if(!n)return P("Invalid or expired link. Please request a new one.","danger"),void S("forgot");if(s)if(s===t){E(k.buttons.setPassword,!0);try{await g.resetWithToken({token:n,newPassword:s}),sessionStorage.removeItem("login_token"),P(y.successRedirecting,"success"),setTimeout(w,350)}catch(o){P(g.getErrorMessage(o)||"Invalid or expired link.","danger"),E(k.buttons.setPassword,!1)}}else P(y.passwordsDoNotMatch,"danger");else P("Please enter a new password.","danger")}function x(e){e?.preventDefault?.(),C(),S("forgot")}function L(){C(),S("signin")}function _(){C(),S("forgot")}return k.forms.signin?.addEventListener("submit",$),k.forms.forgot?.addEventListener("submit",q),k.forms.resetCode?.addEventListener("submit",R),k.forms.setPassword?.addEventListener("submit",I),k.links.forgot?.addEventListener("click",x),k.buttons.backSignin?.addEventListener("click",L),k.buttons.backForgot?.addEventListener("click",_),d?.google&&k.buttons.google&&k.buttons.google.addEventListener("click",s=>{s?.preventDefault?.(),d.google.onClick?.({container:e,auth:g,redirect:w,showMessage:P})}),d?.passkey&&k.buttons.passkey&&k.buttons.passkey.addEventListener("click",s=>{s?.preventDefault?.(),d.passkey.onClick?.({container:e,auth:g,redirect:w,showMessage:P})}),function(){const e=new URLSearchParams(window.location.search),s=e.get("login_token");if(s){sessionStorage.setItem("login_token",s),e.delete("login_token");const t=e.toString()?`${window.location.pathname}?${e.toString()}`:window.location.pathname;return window.history.replaceState({},"",t),S("setPassword"),void P("Please set your new password.","info")}const t=sessionStorage.getItem("reset_email");if(t)return k.labels.resetEmailDisplay&&(k.labels.resetEmailDisplay.textContent=t),void S("resetCode");S("signin")}(),{destroy(){k.forms.signin?.removeEventListener("submit",$),k.forms.forgot?.removeEventListener("submit",q),k.forms.resetCode?.removeEventListener("submit",R),k.forms.setPassword?.removeEventListener("submit",I),k.links.forgot?.removeEventListener("click",x),k.buttons.backSignin?.removeEventListener("click",L),k.buttons.backForgot?.removeEventListener("click",_),d?.google&&k.buttons.google&&k.buttons.google.replaceWith(k.buttons.google.cloneNode(!0)),d?.passkey&&k.buttons.passkey&&k.buttons.passkey.replaceWith(k.buttons.passkey.cloneNode(!0)),e.innerHTML=""}}}const l={mountAuth:i,createAuthClient:a},d=/* @__PURE__ */Object.freeze(/* @__PURE__ */Object.defineProperty({__proto__:null,createAuthClient:a,default:l,mountAuth:i},Symbol.toStringTag,{value:"Module"}));export{e as BUILD_TIME,s as VERSION,t as VERSION_INFO,n as VERSION_MAJOR,o as VERSION_MINOR,r as VERSION_REVISION,a as createAuthClient,d as default,i as mountAuth};
|
|
1
|
+
import{B as e,V as s,a as t,b as n,c as o,d as r}from"./chunks/version-xpJSWoyH.js";function a({baseURL:e,fetchImpl:s=("undefined"!=typeof fetch?fetch.bind(window):null),storage:t=("undefined"!=typeof localStorage?localStorage:null),endpoints:n={}}={}){if(!e)throw new Error("createAuthClient: baseURL is required");if(!s)throw new Error("createAuthClient: fetch implementation is not available in this environment");if(!t)throw new Error("createAuthClient: storage (localStorage) is not available in this environment");const o="access_token",r="refresh_token",a="user",i={login:"/login",forgot:"/auth/forgot",resetCode:"/auth/password/reset/code",resetToken:"/auth/password/reset/token",exchange:"/auth/exchange",...n};let l=null;async function d(t,n){const o=await s(`${e}${t}`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(n||{})});let r={};try{r=await o.json()}catch(a){}if(!o.ok)throw r||{message:`Request failed with status ${o.status}`};return r}function c(e){return e&&e.data&&e.data.data||e&&e.data||e}function u(e){const s=c(e);if(!s||!s.access_token)throw new Error("No access_token in response.");t.setItem(o,s.access_token),s.refresh_token&&t.setItem(r,s.refresh_token),s.user&&t.setItem(a,JSON.stringify(s.user))}return{async login(e,s){const t=await d(i.login,{username:e,password:s});return u(t),c(t)},forgot:async({email:e,method:s})=>d(i.forgot,{email:e,method:s}),async resetWithCode({email:e,code:s,newPassword:t}){const n=await d(i.resetCode,{email:e,code:s,new_password:t});return u(n),c(n)},async resetWithToken({token:e,newPassword:s}){const t=await d(i.resetToken,{token:e,new_password:s});return u(t),c(t)},exchangeAuthCode:async e=>l||(l=(async()=>{try{const s=await d(i.exchange,{code:e});return u(s),c(s)}finally{l=null}})(),l),async handleAuthCodeFromURL(){if("undefined"==typeof window||!window.location)return null;const e=new URLSearchParams(window.location.search),s=e.get("auth_code");if(!s)return null;e.delete("auth_code");const t=window.location.pathname+(e.toString()?`?${e.toString()}`:"")+(window.location.hash||"");return window.history.replaceState({},"",t),this.exchangeAuthCode(s)},logout(){t.removeItem(o),t.removeItem(r),t.removeItem(a)},isAuthenticated:()=>!!t.getItem(o),getToken:()=>t.getItem(o),getUser(){const e=t.getItem(a);try{return e?JSON.parse(e):null}catch{return null}},getAuthHeader(){const e=t.getItem(o);return e?`Bearer ${e}`:null},getErrorMessage:function(e){return e?.message||e?.error||Array.isArray(e?.errors)&&e.errors[0]?.message||"An error occurred. Please try again."},parseResponse:c}}function i(e,s={}){if(!(e&&e instanceof Element))throw new Error("mountAuth: container must be a DOM Element");const{baseURL:t,onSuccessRedirect:n,allowRedirectOrigins:o,branding:r={},theme:i,endpoints:l,providers:d,texts:c={}}=s;if(!t)throw new Error("mountAuth: baseURL is required");const u=new URLSearchParams(window.location.search),m=u.get("redirect")||u.get("next")||u.get("returnTo"),p=String(n||m||"/");function w(){!function(e){if(!o||0===o.length)return!0;try{const s=new URL(e,window.location.origin);return o.includes(s.origin)}catch{return!1}}(p)?window.location.href="/":window.location.href=p.startsWith("http")?p:new URL(p,window.location.origin).href}const g=a({baseURL:t,endpoints:l}),b=r.title||"Sign In",f=r.subtitle||"Sign in to your account",h=r.logoUrl||"",y={emailOrUsername:c.emailOrUsername||"Email or Username",password:c.password||"Password",signIn:c.signIn||"Sign In",forgotPassword:c.forgotPassword||"Forgot password?",resetYourPassword:c.resetYourPassword||"Reset Your Password",emailAddress:c.emailAddress||"Email Address",resetMethod:c.resetMethod||"Reset Method",emailCode:c.emailCode||"Email me a code",emailLink:c.emailLink||"Email me a magic link",sendReset:c.sendReset||"Send Reset",back:c.back||"Back",enterResetCode:c.enterResetCode||"Enter Reset Code",weSentCodeTo:c.weSentCodeTo||"We sent a code to",resetCode:c.resetCode||"Reset Code",newPassword:c.newPassword||"New Password",confirmPassword:c.confirmPassword||"Confirm Password",resetPassword:c.resetPassword||"Reset Password",setYourNewPassword:c.setYourNewPassword||"Set Your New Password",setPassword:c.setPassword||"Set Password",invalidCredentials:c.invalidCredentials||"Invalid credentials.",successRedirecting:c.successRedirecting||"Success! Redirecting...",pleaseFillAllFields:c.pleaseFillAllFields||"Please fill in all fields.",passwordsDoNotMatch:c.passwordsDoNotMatch||"Passwords do not match."},v=`\n <div class="auth-container">\n <div class="auth-card">\n <div class="auth-header">\n ${h?`<img src="${h}" alt="${b}" style="max-height:60px;margin-bottom:10px" />`:""}\n <h1 class="auth-title">${b}</h1>\n <p class="auth-subtitle">${f}</p>\n </div>\n\n <div id="status-message" class="alert" role="status" style="display:none;"></div>\n\n \x3c!-- Sign In View --\x3e\n <div id="view-signin" class="auth-view">\n <form id="form-signin" novalidate>\n <div class="mb-3">\n <label for="signin-username" class="form-label">${y.emailOrUsername}</label>\n <input type="text" class="form-control" id="signin-username" placeholder="${y.emailOrUsername}" autocomplete="username" required />\n </div>\n <div class="mb-3">\n <label for="signin-password" class="form-label">${y.password}</label>\n <input type="password" class="form-control" id="signin-password" placeholder="${y.password}" autocomplete="current-password" required />\n </div>\n <button type="submit" class="btn btn-primary w-100 mb-3" id="btn-signin">\n <span class="btn-text">${y.signIn}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n <div class="text-center">\n <a href="#" id="link-forgot" class="text-decoration-none">${y.forgotPassword}</a>\n </div>\n\n ${d&&(d.google||d.passkey)?`\n <div class="position-relative my-3">\n <hr class="text-muted" />\n <span class="position-absolute top-50 start-50 translate-middle bg-white px-3 text-muted small">OR</span>\n </div>\n <div class="d-grid gap-2">\n ${d.google?'<button type="button" class="btn btn-outline-primary" id="btn-google"><i class="bi bi-google me-2"></i>Continue with Google</button>':""}\n ${d.passkey?'<button type="button" class="btn btn-outline-secondary" id="btn-passkey"><i class="bi bi-fingerprint me-2"></i>Sign in with Passkey</button>':""}\n </div>\n `:""}\n </form>\n </div>\n\n \x3c!-- Forgot Password View --\x3e\n <div id="view-forgot" class="auth-view" style="display:none;">\n <button type="button" class="btn btn-link p-0 mb-3" id="btn-back-signin">\n <span aria-hidden="true">←</span> ${y.back}\n </button>\n <h2 class="h5 mb-3">${y.resetYourPassword}</h2>\n <form id="form-forgot" novalidate>\n <div class="mb-3">\n <label for="forgot-email" class="form-label">${y.emailAddress}</label>\n <input type="email" class="form-control" id="forgot-email" placeholder="${y.emailAddress}" autocomplete="email" required />\n </div>\n <div class="mb-3">\n <label class="form-label">${y.resetMethod}</label>\n <div class="form-check">\n <input class="form-check-input" type="radio" name="reset-method" id="method-code" value="code" checked />\n <label class="form-check-label" for="method-code">${y.emailCode}</label>\n </div>\n <div class="form-check">\n <input class="form-check-input" type="radio" name="reset-method" id="method-link" value="link" />\n <label class="form-check-label" for="method-link">${y.emailLink}</label>\n </div>\n </div>\n <button type="submit" class="btn btn-primary w-100" id="btn-forgot">\n <span class="btn-text">${y.sendReset}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n </form>\n </div>\n\n \x3c!-- Reset with Code View --\x3e\n <div id="view-reset-code" class="auth-view" style="display:none;">\n <button type="button" class="btn btn-link p-0 mb-3" id="btn-back-forgot">\n <span aria-hidden="true">←</span> ${y.back}\n </button>\n <h2 class="h5 mb-3">${y.enterResetCode}</h2>\n <p class="text-muted small mb-3">${y.weSentCodeTo} <strong id="reset-email-display"></strong></p>\n <form id="form-reset-code" novalidate>\n <div class="mb-3">\n <label for="reset-code" class="form-label">${y.resetCode}</label>\n <input type="text" class="form-control" id="reset-code" placeholder="${y.resetCode}" required />\n </div>\n <div class="mb-3">\n <label for="reset-password" class="form-label">${y.newPassword}</label>\n <input type="password" class="form-control" id="reset-password" placeholder="${y.newPassword}" autocomplete="new-password" required />\n </div>\n <div class="mb-3">\n <label for="reset-password-confirm" class="form-label">${y.confirmPassword}</label>\n <input type="password" class="form-control" id="reset-password-confirm" placeholder="${y.confirmPassword}" autocomplete="new-password" required />\n </div>\n <button type="submit" class="btn btn-primary w-100" id="btn-reset-code">\n <span class="btn-text">${y.resetPassword}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n </form>\n </div>\n\n \x3c!-- Set Password via Magic Link View --\x3e\n <div id="view-set-password" class="auth-view" style="display:none;">\n <h2 class="h5 mb-3">${y.setYourNewPassword}</h2>\n <form id="form-set-password" novalidate>\n <div class="mb-3">\n <label for="set-password" class="form-label">${y.newPassword}</label>\n <input type="password" class="form-control" id="set-password" placeholder="${y.newPassword}" autocomplete="new-password" required />\n </div>\n <div class="mb-3">\n <label for="set-password-confirm" class="form-label">${y.confirmPassword}</label>\n <input type="password" class="form-control" id="set-password-confirm" placeholder="${y.confirmPassword}" autocomplete="new-password" required />\n </div>\n <button type="submit" class="btn btn-primary w-100" id="btn-set-password">\n <span class="btn-text">${y.setPassword}</span>\n <span class="btn-spinner spinner-border spinner-border-sm" style="display:none;"></span>\n </button>\n </form>\n </div>\n </div>\n </div>\n `;e.innerHTML=v,i&&e.classList.add(String(i));const k={views:{signin:e.querySelector("#view-signin"),forgot:e.querySelector("#view-forgot"),resetCode:e.querySelector("#view-reset-code"),setPassword:e.querySelector("#view-set-password")},forms:{signin:e.querySelector("#form-signin"),forgot:e.querySelector("#form-forgot"),resetCode:e.querySelector("#form-reset-code"),setPassword:e.querySelector("#form-set-password")},buttons:{signin:e.querySelector("#btn-signin"),forgot:e.querySelector("#btn-forgot"),resetCode:e.querySelector("#btn-reset-code"),setPassword:e.querySelector("#btn-set-password"),backSignin:e.querySelector("#btn-back-signin"),backForgot:e.querySelector("#btn-back-forgot"),google:e.querySelector("#btn-google"),passkey:e.querySelector("#btn-passkey")},inputs:{signinUsername:e.querySelector("#signin-username"),signinPassword:e.querySelector("#signin-password"),forgotEmail:e.querySelector("#forgot-email"),resetCode:e.querySelector("#reset-code"),resetPassword:e.querySelector("#reset-password"),resetPasswordConfirm:e.querySelector("#reset-password-confirm"),setPassword:e.querySelector("#set-password"),setPasswordConfirm:e.querySelector("#set-password-confirm")},radios:{resetMethodCode:e.querySelector("#method-code"),resetMethodLink:e.querySelector("#method-link")},labels:{resetEmailDisplay:e.querySelector("#reset-email-display")},links:{forgot:e.querySelector("#link-forgot")},message:e.querySelector("#status-message")};function S(e){Object.entries(k.views).forEach(([s,t])=>{t&&(t.style.display=s===e?"block":"none")}),setTimeout(()=>{const s=k.views[e],t=s?.querySelector("h1, h2, .auth-title, .h5");if(t)t.setAttribute("tabindex","-1"),t.focus?.();else{const e=s?.querySelector("input, button");e?.focus?.()}},60)}function P(e,s="info"){const t=k.message;t&&(t.textContent=e,t.className=`alert alert-${s}`,t.style.display="block",t.setAttribute("role","danger"===s?"alert":"status"))}function C(){const e=k.message;e&&(e.style.display="none")}function E(e,s){if(!e)return;const t=e.querySelector(".btn-text"),n=e.querySelector(".btn-spinner");e.disabled=!!s,t&&(t.style.display=s?"none":"inline"),n&&(n.style.display=s?"inline-block":"none")}async function $(e){e?.preventDefault?.(),C();const s=k.inputs.signinUsername?.value?.trim(),t=k.inputs.signinPassword?.value;if(s&&t){E(k.buttons.signin,!0);try{await g.login(s,t),P(`${y.successRedirecting}`,"success"),setTimeout(w,350)}catch(n){P(g.getErrorMessage(n)||y.invalidCredentials,"danger"),E(k.buttons.signin,!1)}}else P("Please enter both username and password.","danger")}async function q(e){e?.preventDefault?.(),C();const s=k.inputs.forgotEmail?.value?.trim(),t=k.radios.resetMethodCode?.checked?"code":k.radios.resetMethodLink?.checked?"link":"code";if(s){E(k.buttons.forgot,!0);try{await g.forgot({email:s,method:t}),"code"===t?(sessionStorage.setItem("reset_email",s),sessionStorage.setItem("reset_method",t),k.labels.resetEmailDisplay&&(k.labels.resetEmailDisplay.textContent=s),S("resetCode"),P("Reset code sent! Check your email.","success")):P("Magic link sent! Check your email and click the link.","success")}catch(n){P(g.getErrorMessage(n)||"Something went wrong. Please try again.","danger")}finally{E(k.buttons.forgot,!1)}}else P("Please enter your email address.","danger")}async function R(e){e?.preventDefault?.(),C();const s=k.inputs.resetCode?.value?.trim(),t=k.inputs.resetPassword?.value,n=k.inputs.resetPasswordConfirm?.value,o=sessionStorage.getItem("reset_email");if(!o)return P("Session expired. Please restart the password reset process.","danger"),void S("forgot");if(s&&t)if(t===n){E(k.buttons.resetCode,!0);try{await g.resetWithCode({email:o,code:s,newPassword:t}),sessionStorage.removeItem("reset_email"),sessionStorage.removeItem("reset_method"),P(y.successRedirecting,"success"),setTimeout(w,350)}catch(r){P(g.getErrorMessage(r)||"Invalid code or code expired.","danger"),E(k.buttons.resetCode,!1)}}else P(y.passwordsDoNotMatch,"danger");else P(y.pleaseFillAllFields,"danger")}async function I(e){e?.preventDefault?.(),C();const s=k.inputs.setPassword?.value,t=k.inputs.setPasswordConfirm?.value,n=sessionStorage.getItem("login_token");if(!n)return P("Invalid or expired link. Please request a new one.","danger"),void S("forgot");if(s)if(s===t){E(k.buttons.setPassword,!0);try{await g.resetWithToken({token:n,newPassword:s}),sessionStorage.removeItem("login_token"),P(y.successRedirecting,"success"),setTimeout(w,350)}catch(o){P(g.getErrorMessage(o)||"Invalid or expired link.","danger"),E(k.buttons.setPassword,!1)}}else P(y.passwordsDoNotMatch,"danger");else P("Please enter a new password.","danger")}function x(e){e?.preventDefault?.(),C(),S("forgot")}function L(){C(),S("signin")}function _(){C(),S("forgot")}return k.forms.signin?.addEventListener("submit",$),k.forms.forgot?.addEventListener("submit",q),k.forms.resetCode?.addEventListener("submit",R),k.forms.setPassword?.addEventListener("submit",I),k.links.forgot?.addEventListener("click",x),k.buttons.backSignin?.addEventListener("click",L),k.buttons.backForgot?.addEventListener("click",_),d?.google&&k.buttons.google&&k.buttons.google.addEventListener("click",s=>{s?.preventDefault?.(),d.google.onClick?.({container:e,auth:g,redirect:w,showMessage:P})}),d?.passkey&&k.buttons.passkey&&k.buttons.passkey.addEventListener("click",s=>{s?.preventDefault?.(),d.passkey.onClick?.({container:e,auth:g,redirect:w,showMessage:P})}),function(){const e=new URLSearchParams(window.location.search),s=e.get("login_token");if(s){sessionStorage.setItem("login_token",s),e.delete("login_token");const t=e.toString()?`${window.location.pathname}?${e.toString()}`:window.location.pathname;return window.history.replaceState({},"",t),S("setPassword"),void P("Please set your new password.","info")}const t=sessionStorage.getItem("reset_email");if(t)return k.labels.resetEmailDisplay&&(k.labels.resetEmailDisplay.textContent=t),void S("resetCode");S("signin")}(),{destroy(){k.forms.signin?.removeEventListener("submit",$),k.forms.forgot?.removeEventListener("submit",q),k.forms.resetCode?.removeEventListener("submit",R),k.forms.setPassword?.removeEventListener("submit",I),k.links.forgot?.removeEventListener("click",x),k.buttons.backSignin?.removeEventListener("click",L),k.buttons.backForgot?.removeEventListener("click",_),d?.google&&k.buttons.google&&k.buttons.google.replaceWith(k.buttons.google.cloneNode(!0)),d?.passkey&&k.buttons.passkey&&k.buttons.passkey.replaceWith(k.buttons.passkey.cloneNode(!0)),e.innerHTML=""}}}const l={mountAuth:i,createAuthClient:a},d=/* @__PURE__ */Object.freeze(/* @__PURE__ */Object.defineProperty({__proto__:null,createAuthClient:a,default:l,mountAuth:i},Symbol.toStringTag,{value:"Module"}));export{e as BUILD_TIME,s as VERSION,t as VERSION_INFO,n as VERSION_MAJOR,o as VERSION_MINOR,r as VERSION_REVISION,a as createAuthClient,d as default,i as mountAuth};
|
|
2
2
|
//# sourceMappingURL=auth.es.js.map
|
package/dist/charts.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/exportChart-Bkxr7mCe.js"),e=require("./chunks/View-C8UWvaSM.js"),s=require("./chunks/Collection-BpUmNuDZ.js"),i=require("./chunks/WebApp-kbRq7dM_.js"),r=require("./chunks/version-DkxW4rIi.js");class CircularProgress extends e.View{constructor(t={}){super({className:`circular-progress ${t.className||""}`,...t}),this.SIZE_PRESETS={xs:40,sm:60,md:80,lg:120,xl:180},this.STROKE_PRESETS={xs:4,sm:6,md:8,lg:12,xl:16},this.value=void 0!==t.value?t.value:0,this.min=void 0!==t.min?t.min:0,this.max=void 0!==t.max?t.max:100,this.sizePreset="string"==typeof t.size&&this.SIZE_PRESETS[t.size]?t.size:null,this.size=this.resolveSize(void 0!==t.size?t.size:"md"),this.strokeWidth="auto"===t.strokeWidth||void 0===t.strokeWidth?this.getAutoStrokeWidth(t.size):t.strokeWidth,this.theme=t.theme||"basic",this.variant=t.variant||"default",this.color=t.color,this.trackColor=t.trackColor,this.textColor=t.textColor,this.gradientColors=t.gradientColors||null,this.applyTheme(),this.applyVariant(),this.rotation=void 0!==t.rotation?t.rotation:-90,this.gap=t.gap||0,this.showValue=!1!==t.showValue,this.valueFormat=t.valueFormat||"percentage",this.valueFormatter=t.valueFormatter||null,this.label=t.label||null,this.labelHtml=t.labelHtml||null,this.icon=t.icon||null,this.animate=!1!==t.animate,this.animationDuration=t.animationDuration||600,this.animationEasing=t.animationEasing||"ease-out",this.rounded=!1!==t.rounded,this.shadow=t.shadow||!1,this.clickable=t.clickable||!1,this.tooltip=t.tooltip||null,this.tooltipPlacement=t.tooltipPlacement||"top",this.segments=t.segments||null,this.segmentGap=t.segmentGap||2,this.dataFormatter=s.dataFormatter,this.svg=null,this.centerElement=null,this.popover=null,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`}resolveSize(t){return"string"==typeof t&&this.SIZE_PRESETS[t]?this.SIZE_PRESETS[t]:"number"==typeof t?t:this.SIZE_PRESETS.md}getAutoStrokeWidth(t){if("string"==typeof t&&this.STROKE_PRESETS[t])return this.STROKE_PRESETS[t];const e=this.resolveSize(t);return e<=40?4:e<=60?6:e<=80?8:e<=120?12:16}applyTheme(){const t={basic:{trackColor:"#e9ecef",textColor:null,backgroundColor:null},shadowed:{trackColor:"#d1d5db",textColor:null,backgroundColor:null,shadow:!0},dark:{trackColor:"#374151",textColor:"#e5e7eb",backgroundColor:"#1f2937"},light:{trackColor:"#f3f4f6",textColor:"#111827",backgroundColor:"#ffffff"}},e=t[this.theme]||t.basic;this.trackColor||(this.trackColor=e.trackColor),!this.textColor&&e.textColor&&(this.textColor=e.textColor),e.shadow&&!1===this.shadow&&(this.shadow=e.shadow)}applyVariant(){const t={success:{color:"#198754",trackColor:"rgba(25, 135, 84, 0.1)"},danger:{color:"#dc3545",trackColor:"rgba(220, 53, 69, 0.1)"},warning:{color:"#ffc107",trackColor:"rgba(255, 193, 7, 0.1)"},info:{color:"#0dcaf0",trackColor:"rgba(13, 202, 240, 0.1)"},default:{color:"#0d6efd"}};if(t[this.variant]){const e=t[this.variant];this.color||(this.color=e.color),e.trackColor&&this.trackColor===this.applyTheme.trackColor&&(this.trackColor=e.trackColor)}this.color||(this.color="#0d6efd")}getTemplate(){const t=this.sizePreset?`circular-progress-${this.sizePreset}`:"",e="default"!==this.variant?`circular-progress-${this.variant}`:"",s="basic"!==this.theme?`circular-progress-theme-${this.theme}`:"",i=this.clickable?"circular-progress-clickable":"",r=this.shadow?"circular-progress-shadow":"",o=this.textColor?`color: ${this.textColor};`:"";return`\n <div class="circular-progress-container ${t} ${e} ${s} ${i} ${r}"\n style="width: ${this.size}px; height: ${this.size}px;">\n <svg class="circular-progress-svg" \n width="${this.size}" \n height="${this.size}"\n viewBox="0 0 ${this.size} ${this.size}">\n </svg>\n <div class="circular-progress-center" style="${o}">\n <div class="circular-progress-content"></div>\n </div>\n </div>\n `}async onAfterRender(){this.svg=this.element.querySelector(".circular-progress-svg"),this.centerElement=this.element.querySelector(".circular-progress-content"),this.containerElement=this.element.querySelector(".circular-progress-container"),this.renderProgress(),this.renderCenterContent(),this.clickable&&this.setupClickHandler(),this.tooltip&&this.clickable&&this.setupTooltip()}renderProgress(){if(!this.svg)return;this.svg.innerHTML="";const t=this.size/2,e=(this.size-this.strokeWidth)/2,s=2*Math.PI*e;this.gradientColors&&this.gradientColors.length>1&&this.createGradient(),this.segments&&Array.isArray(this.segments)&&this.segments.length>0?this.renderSegments(t,e,s):this.renderSingleProgress(t,e,s)}renderSingleProgress(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r);const o=i-this.getPercentage()/100*i,a=this.gradientColors?`url(#${this.gradientId})`:this.color,n=this.createCircle(t,e,{stroke:a,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${i} ${s}`,strokeDashoffset:this.animate?i:o,transform:`rotate(${this.rotation} ${t} ${t})`,class:"circular-progress-bar"});this.svg.appendChild(n),this.animate&&this.animateProgress(n,o)}renderSegments(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r),this.segments.reduce((t,e)=>t+(e.value||0),0)>this.max&&console.warn("CircularProgress: Segment total exceeds max value. Clamping to max.");let o=0;this.segments.forEach((r,a)=>{const n=(r.value||0)/(this.max-this.min)*100/100*i,h=this.segmentGap/360*s;if(n>0){const l=this.createCircle(t,e,{stroke:r.color||this.color,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${n} ${s}`,strokeDashoffset:this.animate?i:-o,transform:`rotate(${this.rotation} ${t} ${t})`,class:`circular-progress-segment circular-progress-segment-${a}`,"data-segment-index":a});this.svg.appendChild(l),this.animate&&this.animateProgress(l,-o,100*a),o+=n+h}})}createCircle(t,e,s={}){const i=document.createElementNS("http://www.w3.org/2000/svg","circle");return i.setAttribute("cx",t),i.setAttribute("cy",t),i.setAttribute("r",e),Object.entries(s).forEach(([t,e])=>{"strokeWidth"===t?i.setAttribute("stroke-width",e):"strokeLinecap"===t?i.setAttribute("stroke-linecap",e):"strokeDasharray"===t?i.setAttribute("stroke-dasharray",e):"strokeDashoffset"===t?i.setAttribute("stroke-dashoffset",e):i.setAttribute(t,e)}),i}createGradient(){const t=document.createElementNS("http://www.w3.org/2000/svg","defs"),e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",this.gradientId),e.setAttribute("x1","0%"),e.setAttribute("y1","0%"),e.setAttribute("x2","100%"),e.setAttribute("y2","100%"),this.gradientColors.forEach((t,s)=>{const i=document.createElementNS("http://www.w3.org/2000/svg","stop"),r=s/(this.gradientColors.length-1)*100;i.setAttribute("offset",`${r}%`),i.setAttribute("stop-color",t),e.appendChild(i)}),t.appendChild(e),this.svg.appendChild(t)}animateProgress(t,e,s=0){setTimeout(()=>{t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=e},s)}renderCenterContent(){if(this.centerElement)if(this.labelHtml)this.centerElement.innerHTML=this.labelHtml;else if(this.icon)this.centerElement.innerHTML=`<i class="${this.icon}"></i>`;else if(this.showValue){let t=`<div class="circular-progress-value">${this.getFormattedValue()}</div>`;this.label&&(t+=`<div class="circular-progress-label">${this.label}</div>`),this.centerElement.innerHTML=t}}getFormattedValue(){const t=this.value,e=this.min,s=this.max;if(this.valueFormatter&&"function"==typeof this.valueFormatter)return this.valueFormatter(t,e,s);switch(this.valueFormat){case"percentage":return`${Math.round(this.getPercentage())}%`;case"fraction":return`${t}/${s}`;case"value":return t.toString();default:if(this.dataFormatter)try{return this.dataFormatter.pipe(t,this.valueFormat)}catch(i){return console.warn("CircularProgress: DataFormatter error, falling back to percentage",i),`${Math.round(this.getPercentage())}%`}return`${Math.round(this.getPercentage())}%`}}getPercentage(){const t=this.max-this.min;return 0===t?0:(this.value-this.min)/t*100}setupClickHandler(){this.containerElement&&(this.containerElement.style.cursor="pointer",this.containerElement.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=this.getPercentage();this.emit("progress:clicked",{value:this.value,percentage:e,min:this.min,max:this.max}),this.tooltip&&this.togglePopover()}))}setupTooltip(){}togglePopover(){if(this.containerElement&&void 0!==window.bootstrap){if(!this.popover){const t=this.getTooltipContent(),e="object"==typeof this.tooltip&&this.tooltip.title?this.tooltip.title:void 0,s={content:t,html:!0,placement:this.tooltipPlacement,trigger:"manual",container:"body"};e&&(s.title=e),this.popover=new window.bootstrap.Popover(this.containerElement,s)}window.bootstrap.Popover.getInstance(this.containerElement)&&this.containerElement.getAttribute("aria-describedby")?this.popover.hide():(this.popover.setContent({".popover-body":this.getTooltipContent()}),this.popover.show())}else console.warn("CircularProgress: Bootstrap is required for tooltip support")}getTooltipContent(){return"function"==typeof this.tooltip?this.tooltip(this.value,{min:this.min,max:this.max,percentage:this.getPercentage()}):"object"==typeof this.tooltip?this.tooltip.html||this.tooltip.content||"":this.tooltip||""}setValue(t,e=!0){if(this.value,this.value=Math.max(this.min,Math.min(this.max,t)),this.renderCenterContent(),this.svg&&!this.segments){const t=this.svg.querySelector(".circular-progress-bar");if(t){const s=this.size/2-this.strokeWidth/2,i=2*Math.PI*s,r=(this.gap>0?360-this.gap:360)/360*i,o=r-this.getPercentage()/100*r;e?(t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=o):(t.style.transition="none",t.style.strokeDashoffset=o)}}else{const t=this.animate;this.animate=e,this.renderProgress(),this.animate=t}}setRange(t,e){this.min=t,this.max=e,this.renderProgress(),this.renderCenterContent()}increment(t=1){this.setValue(this.value+t)}decrement(t=1){this.setValue(this.value-t)}setColor(t){if(this.color=t,this.gradientColors=null,this.svg&&!this.segments){const e=this.svg.querySelector(".circular-progress-bar");e&&e.setAttribute("stroke",t)}else this.renderProgress()}setGradient(t){Array.isArray(t)&&t.length>1&&(this.gradientColors=t,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`,this.renderProgress())}setSize(t){this.containerElement&&this.sizePreset&&this.containerElement.classList.remove(`circular-progress-${this.sizePreset}`),this.sizePreset="string"==typeof t&&this.SIZE_PRESETS[t]?t:null,this.size=this.resolveSize(t),this.strokeWidth=this.getAutoStrokeWidth(t),this.containerElement&&(this.containerElement.style.width=`${this.size}px`,this.containerElement.style.height=`${this.size}px`,this.sizePreset&&this.containerElement.classList.add(`circular-progress-${this.sizePreset}`)),this.svg&&(this.svg.setAttribute("width",this.size),this.svg.setAttribute("height",this.size),this.svg.setAttribute("viewBox",`0 0 ${this.size} ${this.size}`)),this.renderProgress()}animateTo(t,e=1e3){const s=this.value,i=t-s,r=performance.now(),o=a=>{const n=a-r,h=Math.min(n/e,1),l=1-Math.pow(1-h,3),c=s+i*l;this.setValue(c,!1),h<1?requestAnimationFrame(o):this.setValue(t,!1)};requestAnimationFrame(o)}pulse(){this.containerElement&&(this.containerElement.style.animation="none",setTimeout(()=>{this.containerElement.style.animation="circular-progress-pulse 0.5s ease-out"},10),setTimeout(()=>{this.containerElement.style.animation=""},500))}complete(){this.variant="success",this.applyVariant(),this.setValue(this.max),this.pulse()}reset(){this.setValue(this.min)}hide(){this.element&&(this.element.style.display="none")}show(){this.element&&(this.element.style.display="")}getValue(){return this.value}getPercentageValue(){return this.getPercentage()}async onBeforeDestroy(){this.popover&&(this.popover.dispose(),this.popover=null),await super.onBeforeDestroy()}}exports.MetricsChart=t.MetricsChart,exports.MetricsMiniChart=t.MetricsMiniChart,exports.MetricsMiniChartWidget=t.MetricsMiniChartWidget,exports.MiniChart=t.MiniChart,exports.PieChart=t.PieChart,exports.SeriesChart=t.SeriesChart,exports.exportChartPng=t.exportChartPng,exports.WebApp=i.WebApp,exports.BUILD_TIME=r.BUILD_TIME,exports.VERSION=r.VERSION,exports.VERSION_INFO=r.VERSION_INFO,exports.VERSION_MAJOR=r.VERSION_MAJOR,exports.VERSION_MINOR=r.VERSION_MINOR,exports.VERSION_REVISION=r.VERSION_REVISION,exports.CircularProgress=CircularProgress;
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const t=require("./chunks/exportChart-UQ5nq_mR.js"),e=require("./chunks/View-BWOE7WJm.js"),s=require("./chunks/Collection-CtSGTegm.js"),i=require("./chunks/WebApp-By80XfTK.js"),r=require("./chunks/version-Bdrq2emC.js");class CircularProgress extends e.View{constructor(t={}){super({className:`circular-progress ${t.className||""}`,...t}),this.SIZE_PRESETS={xs:40,sm:60,md:80,lg:120,xl:180},this.STROKE_PRESETS={xs:4,sm:6,md:8,lg:12,xl:16},this.value=void 0!==t.value?t.value:0,this.min=void 0!==t.min?t.min:0,this.max=void 0!==t.max?t.max:100,this.sizePreset="string"==typeof t.size&&this.SIZE_PRESETS[t.size]?t.size:null,this.size=this.resolveSize(void 0!==t.size?t.size:"md"),this.strokeWidth="auto"===t.strokeWidth||void 0===t.strokeWidth?this.getAutoStrokeWidth(t.size):t.strokeWidth,this.theme=t.theme||"basic",this.variant=t.variant||"default",this.color=t.color,this.trackColor=t.trackColor,this.textColor=t.textColor,this.gradientColors=t.gradientColors||null,this.applyTheme(),this.applyVariant(),this.rotation=void 0!==t.rotation?t.rotation:-90,this.gap=t.gap||0,this.showValue=!1!==t.showValue,this.valueFormat=t.valueFormat||"percentage",this.valueFormatter=t.valueFormatter||null,this.label=t.label||null,this.labelHtml=t.labelHtml||null,this.icon=t.icon||null,this.animate=!1!==t.animate,this.animationDuration=t.animationDuration||600,this.animationEasing=t.animationEasing||"ease-out",this.rounded=!1!==t.rounded,this.shadow=t.shadow||!1,this.clickable=t.clickable||!1,this.tooltip=t.tooltip||null,this.tooltipPlacement=t.tooltipPlacement||"top",this.segments=t.segments||null,this.segmentGap=t.segmentGap||2,this.dataFormatter=s.dataFormatter,this.svg=null,this.centerElement=null,this.popover=null,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`}resolveSize(t){return"string"==typeof t&&this.SIZE_PRESETS[t]?this.SIZE_PRESETS[t]:"number"==typeof t?t:this.SIZE_PRESETS.md}getAutoStrokeWidth(t){if("string"==typeof t&&this.STROKE_PRESETS[t])return this.STROKE_PRESETS[t];const e=this.resolveSize(t);return e<=40?4:e<=60?6:e<=80?8:e<=120?12:16}applyTheme(){const t={basic:{trackColor:"#e9ecef",textColor:null,backgroundColor:null},shadowed:{trackColor:"#d1d5db",textColor:null,backgroundColor:null,shadow:!0},dark:{trackColor:"#374151",textColor:"#e5e7eb",backgroundColor:"#1f2937"},light:{trackColor:"#f3f4f6",textColor:"#111827",backgroundColor:"#ffffff"}},e=t[this.theme]||t.basic;this.trackColor||(this.trackColor=e.trackColor),!this.textColor&&e.textColor&&(this.textColor=e.textColor),e.shadow&&!1===this.shadow&&(this.shadow=e.shadow)}applyVariant(){const t={success:{color:"#198754",trackColor:"rgba(25, 135, 84, 0.1)"},danger:{color:"#dc3545",trackColor:"rgba(220, 53, 69, 0.1)"},warning:{color:"#ffc107",trackColor:"rgba(255, 193, 7, 0.1)"},info:{color:"#0dcaf0",trackColor:"rgba(13, 202, 240, 0.1)"},default:{color:"#0d6efd"}};if(t[this.variant]){const e=t[this.variant];this.color||(this.color=e.color),e.trackColor&&this.trackColor===this.applyTheme.trackColor&&(this.trackColor=e.trackColor)}this.color||(this.color="#0d6efd")}getTemplate(){const t=this.sizePreset?`circular-progress-${this.sizePreset}`:"",e="default"!==this.variant?`circular-progress-${this.variant}`:"",s="basic"!==this.theme?`circular-progress-theme-${this.theme}`:"",i=this.clickable?"circular-progress-clickable":"",r=this.shadow?"circular-progress-shadow":"",o=this.textColor?`color: ${this.textColor};`:"";return`\n <div class="circular-progress-container ${t} ${e} ${s} ${i} ${r}"\n style="width: ${this.size}px; height: ${this.size}px;">\n <svg class="circular-progress-svg" \n width="${this.size}" \n height="${this.size}"\n viewBox="0 0 ${this.size} ${this.size}">\n </svg>\n <div class="circular-progress-center" style="${o}">\n <div class="circular-progress-content"></div>\n </div>\n </div>\n `}async onAfterRender(){this.svg=this.element.querySelector(".circular-progress-svg"),this.centerElement=this.element.querySelector(".circular-progress-content"),this.containerElement=this.element.querySelector(".circular-progress-container"),this.renderProgress(),this.renderCenterContent(),this.clickable&&this.setupClickHandler(),this.tooltip&&this.clickable&&this.setupTooltip()}renderProgress(){if(!this.svg)return;this.svg.innerHTML="";const t=this.size/2,e=(this.size-this.strokeWidth)/2,s=2*Math.PI*e;this.gradientColors&&this.gradientColors.length>1&&this.createGradient(),this.segments&&Array.isArray(this.segments)&&this.segments.length>0?this.renderSegments(t,e,s):this.renderSingleProgress(t,e,s)}renderSingleProgress(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r);const o=i-this.getPercentage()/100*i,a=this.gradientColors?`url(#${this.gradientId})`:this.color,n=this.createCircle(t,e,{stroke:a,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${i} ${s}`,strokeDashoffset:this.animate?i:o,transform:`rotate(${this.rotation} ${t} ${t})`,class:"circular-progress-bar"});this.svg.appendChild(n),this.animate&&this.animateProgress(n,o)}renderSegments(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r),this.segments.reduce((t,e)=>t+(e.value||0),0)>this.max&&console.warn("CircularProgress: Segment total exceeds max value. Clamping to max.");let o=0;this.segments.forEach((r,a)=>{const n=(r.value||0)/(this.max-this.min)*100/100*i,h=this.segmentGap/360*s;if(n>0){const l=this.createCircle(t,e,{stroke:r.color||this.color,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${n} ${s}`,strokeDashoffset:this.animate?i:-o,transform:`rotate(${this.rotation} ${t} ${t})`,class:`circular-progress-segment circular-progress-segment-${a}`,"data-segment-index":a});this.svg.appendChild(l),this.animate&&this.animateProgress(l,-o,100*a),o+=n+h}})}createCircle(t,e,s={}){const i=document.createElementNS("http://www.w3.org/2000/svg","circle");return i.setAttribute("cx",t),i.setAttribute("cy",t),i.setAttribute("r",e),Object.entries(s).forEach(([t,e])=>{"strokeWidth"===t?i.setAttribute("stroke-width",e):"strokeLinecap"===t?i.setAttribute("stroke-linecap",e):"strokeDasharray"===t?i.setAttribute("stroke-dasharray",e):"strokeDashoffset"===t?i.setAttribute("stroke-dashoffset",e):i.setAttribute(t,e)}),i}createGradient(){const t=document.createElementNS("http://www.w3.org/2000/svg","defs"),e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",this.gradientId),e.setAttribute("x1","0%"),e.setAttribute("y1","0%"),e.setAttribute("x2","100%"),e.setAttribute("y2","100%"),this.gradientColors.forEach((t,s)=>{const i=document.createElementNS("http://www.w3.org/2000/svg","stop"),r=s/(this.gradientColors.length-1)*100;i.setAttribute("offset",`${r}%`),i.setAttribute("stop-color",t),e.appendChild(i)}),t.appendChild(e),this.svg.appendChild(t)}animateProgress(t,e,s=0){setTimeout(()=>{t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=e},s)}renderCenterContent(){if(this.centerElement)if(this.labelHtml)this.centerElement.innerHTML=this.labelHtml;else if(this.icon)this.centerElement.innerHTML=`<i class="${this.icon}"></i>`;else if(this.showValue){let t=`<div class="circular-progress-value">${this.getFormattedValue()}</div>`;this.label&&(t+=`<div class="circular-progress-label">${this.label}</div>`),this.centerElement.innerHTML=t}}getFormattedValue(){const t=this.value,e=this.min,s=this.max;if(this.valueFormatter&&"function"==typeof this.valueFormatter)return this.valueFormatter(t,e,s);switch(this.valueFormat){case"percentage":return`${Math.round(this.getPercentage())}%`;case"fraction":return`${t}/${s}`;case"value":return t.toString();default:if(this.dataFormatter)try{return this.dataFormatter.pipe(t,this.valueFormat)}catch(i){return console.warn("CircularProgress: DataFormatter error, falling back to percentage",i),`${Math.round(this.getPercentage())}%`}return`${Math.round(this.getPercentage())}%`}}getPercentage(){const t=this.max-this.min;return 0===t?0:(this.value-this.min)/t*100}setupClickHandler(){this.containerElement&&(this.containerElement.style.cursor="pointer",this.containerElement.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=this.getPercentage();this.emit("progress:clicked",{value:this.value,percentage:e,min:this.min,max:this.max}),this.tooltip&&this.togglePopover()}))}setupTooltip(){}togglePopover(){if(this.containerElement&&void 0!==window.bootstrap){if(!this.popover){const t=this.getTooltipContent(),e="object"==typeof this.tooltip&&this.tooltip.title?this.tooltip.title:void 0,s={content:t,html:!0,placement:this.tooltipPlacement,trigger:"manual",container:"body"};e&&(s.title=e),this.popover=new window.bootstrap.Popover(this.containerElement,s)}window.bootstrap.Popover.getInstance(this.containerElement)&&this.containerElement.getAttribute("aria-describedby")?this.popover.hide():(this.popover.setContent({".popover-body":this.getTooltipContent()}),this.popover.show())}else console.warn("CircularProgress: Bootstrap is required for tooltip support")}getTooltipContent(){return"function"==typeof this.tooltip?this.tooltip(this.value,{min:this.min,max:this.max,percentage:this.getPercentage()}):"object"==typeof this.tooltip?this.tooltip.html||this.tooltip.content||"":this.tooltip||""}setValue(t,e=!0){if(this.value,this.value=Math.max(this.min,Math.min(this.max,t)),this.renderCenterContent(),this.svg&&!this.segments){const t=this.svg.querySelector(".circular-progress-bar");if(t){const s=this.size/2-this.strokeWidth/2,i=2*Math.PI*s,r=(this.gap>0?360-this.gap:360)/360*i,o=r-this.getPercentage()/100*r;e?(t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=o):(t.style.transition="none",t.style.strokeDashoffset=o)}}else{const t=this.animate;this.animate=e,this.renderProgress(),this.animate=t}}setRange(t,e){this.min=t,this.max=e,this.renderProgress(),this.renderCenterContent()}increment(t=1){this.setValue(this.value+t)}decrement(t=1){this.setValue(this.value-t)}setColor(t){if(this.color=t,this.gradientColors=null,this.svg&&!this.segments){const e=this.svg.querySelector(".circular-progress-bar");e&&e.setAttribute("stroke",t)}else this.renderProgress()}setGradient(t){Array.isArray(t)&&t.length>1&&(this.gradientColors=t,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`,this.renderProgress())}setSize(t){this.containerElement&&this.sizePreset&&this.containerElement.classList.remove(`circular-progress-${this.sizePreset}`),this.sizePreset="string"==typeof t&&this.SIZE_PRESETS[t]?t:null,this.size=this.resolveSize(t),this.strokeWidth=this.getAutoStrokeWidth(t),this.containerElement&&(this.containerElement.style.width=`${this.size}px`,this.containerElement.style.height=`${this.size}px`,this.sizePreset&&this.containerElement.classList.add(`circular-progress-${this.sizePreset}`)),this.svg&&(this.svg.setAttribute("width",this.size),this.svg.setAttribute("height",this.size),this.svg.setAttribute("viewBox",`0 0 ${this.size} ${this.size}`)),this.renderProgress()}animateTo(t,e=1e3){const s=this.value,i=t-s,r=performance.now(),o=a=>{const n=a-r,h=Math.min(n/e,1),l=1-Math.pow(1-h,3),c=s+i*l;this.setValue(c,!1),h<1?requestAnimationFrame(o):this.setValue(t,!1)};requestAnimationFrame(o)}pulse(){this.containerElement&&(this.containerElement.style.animation="none",setTimeout(()=>{this.containerElement.style.animation="circular-progress-pulse 0.5s ease-out"},10),setTimeout(()=>{this.containerElement.style.animation=""},500))}complete(){this.variant="success",this.applyVariant(),this.setValue(this.max),this.pulse()}reset(){this.setValue(this.min)}hide(){this.element&&(this.element.style.display="none")}show(){this.element&&(this.element.style.display="")}getValue(){return this.value}getPercentageValue(){return this.getPercentage()}async onBeforeDestroy(){this.popover&&(this.popover.dispose(),this.popover=null),await super.onBeforeDestroy()}}exports.MetricsChart=t.MetricsChart,exports.MetricsMiniChart=t.MetricsMiniChart,exports.MetricsMiniChartWidget=t.MetricsMiniChartWidget,exports.MiniChart=t.MiniChart,exports.PieChart=t.PieChart,exports.SeriesChart=t.SeriesChart,exports.exportChartPng=t.exportChartPng,exports.WebApp=i.WebApp,exports.BUILD_TIME=r.BUILD_TIME,exports.VERSION=r.VERSION,exports.VERSION_INFO=r.VERSION_INFO,exports.VERSION_MAJOR=r.VERSION_MAJOR,exports.VERSION_MINOR=r.VERSION_MINOR,exports.VERSION_REVISION=r.VERSION_REVISION,exports.CircularProgress=CircularProgress;
|
|
2
2
|
//# sourceMappingURL=charts.cjs.js.map
|
package/dist/charts.es.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{M as t,a as e,b as s,c as i,P as r,S as o,e as a}from"./chunks/exportChart-Dn2pioNl.js";import{V as n}from"./chunks/View-Cvs2TY7b.js";import{d as h}from"./chunks/Collection-CY6BblFn.js";import{W as l}from"./chunks/WebApp-DuwanN2O.js";import{B as c,V as u,a as g,b as d,c as m,d as p}from"./chunks/version-CB0Ssm9c.js";class CircularProgress extends n{constructor(t={}){super({className:`circular-progress ${t.className||""}`,...t}),this.SIZE_PRESETS={xs:40,sm:60,md:80,lg:120,xl:180},this.STROKE_PRESETS={xs:4,sm:6,md:8,lg:12,xl:16},this.value=void 0!==t.value?t.value:0,this.min=void 0!==t.min?t.min:0,this.max=void 0!==t.max?t.max:100,this.sizePreset="string"==typeof t.size&&this.SIZE_PRESETS[t.size]?t.size:null,this.size=this.resolveSize(void 0!==t.size?t.size:"md"),this.strokeWidth="auto"===t.strokeWidth||void 0===t.strokeWidth?this.getAutoStrokeWidth(t.size):t.strokeWidth,this.theme=t.theme||"basic",this.variant=t.variant||"default",this.color=t.color,this.trackColor=t.trackColor,this.textColor=t.textColor,this.gradientColors=t.gradientColors||null,this.applyTheme(),this.applyVariant(),this.rotation=void 0!==t.rotation?t.rotation:-90,this.gap=t.gap||0,this.showValue=!1!==t.showValue,this.valueFormat=t.valueFormat||"percentage",this.valueFormatter=t.valueFormatter||null,this.label=t.label||null,this.labelHtml=t.labelHtml||null,this.icon=t.icon||null,this.animate=!1!==t.animate,this.animationDuration=t.animationDuration||600,this.animationEasing=t.animationEasing||"ease-out",this.rounded=!1!==t.rounded,this.shadow=t.shadow||!1,this.clickable=t.clickable||!1,this.tooltip=t.tooltip||null,this.tooltipPlacement=t.tooltipPlacement||"top",this.segments=t.segments||null,this.segmentGap=t.segmentGap||2,this.dataFormatter=h,this.svg=null,this.centerElement=null,this.popover=null,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`}resolveSize(t){return"string"==typeof t&&this.SIZE_PRESETS[t]?this.SIZE_PRESETS[t]:"number"==typeof t?t:this.SIZE_PRESETS.md}getAutoStrokeWidth(t){if("string"==typeof t&&this.STROKE_PRESETS[t])return this.STROKE_PRESETS[t];const e=this.resolveSize(t);return e<=40?4:e<=60?6:e<=80?8:e<=120?12:16}applyTheme(){const t={basic:{trackColor:"#e9ecef",textColor:null,backgroundColor:null},shadowed:{trackColor:"#d1d5db",textColor:null,backgroundColor:null,shadow:!0},dark:{trackColor:"#374151",textColor:"#e5e7eb",backgroundColor:"#1f2937"},light:{trackColor:"#f3f4f6",textColor:"#111827",backgroundColor:"#ffffff"}},e=t[this.theme]||t.basic;this.trackColor||(this.trackColor=e.trackColor),!this.textColor&&e.textColor&&(this.textColor=e.textColor),e.shadow&&!1===this.shadow&&(this.shadow=e.shadow)}applyVariant(){const t={success:{color:"#198754",trackColor:"rgba(25, 135, 84, 0.1)"},danger:{color:"#dc3545",trackColor:"rgba(220, 53, 69, 0.1)"},warning:{color:"#ffc107",trackColor:"rgba(255, 193, 7, 0.1)"},info:{color:"#0dcaf0",trackColor:"rgba(13, 202, 240, 0.1)"},default:{color:"#0d6efd"}};if(t[this.variant]){const e=t[this.variant];this.color||(this.color=e.color),e.trackColor&&this.trackColor===this.applyTheme.trackColor&&(this.trackColor=e.trackColor)}this.color||(this.color="#0d6efd")}getTemplate(){const t=this.sizePreset?`circular-progress-${this.sizePreset}`:"",e="default"!==this.variant?`circular-progress-${this.variant}`:"",s="basic"!==this.theme?`circular-progress-theme-${this.theme}`:"",i=this.clickable?"circular-progress-clickable":"",r=this.shadow?"circular-progress-shadow":"",o=this.textColor?`color: ${this.textColor};`:"";return`\n <div class="circular-progress-container ${t} ${e} ${s} ${i} ${r}"\n style="width: ${this.size}px; height: ${this.size}px;">\n <svg class="circular-progress-svg" \n width="${this.size}" \n height="${this.size}"\n viewBox="0 0 ${this.size} ${this.size}">\n </svg>\n <div class="circular-progress-center" style="${o}">\n <div class="circular-progress-content"></div>\n </div>\n </div>\n `}async onAfterRender(){this.svg=this.element.querySelector(".circular-progress-svg"),this.centerElement=this.element.querySelector(".circular-progress-content"),this.containerElement=this.element.querySelector(".circular-progress-container"),this.renderProgress(),this.renderCenterContent(),this.clickable&&this.setupClickHandler(),this.tooltip&&this.clickable&&this.setupTooltip()}renderProgress(){if(!this.svg)return;this.svg.innerHTML="";const t=this.size/2,e=(this.size-this.strokeWidth)/2,s=2*Math.PI*e;this.gradientColors&&this.gradientColors.length>1&&this.createGradient(),this.segments&&Array.isArray(this.segments)&&this.segments.length>0?this.renderSegments(t,e,s):this.renderSingleProgress(t,e,s)}renderSingleProgress(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r);const o=i-this.getPercentage()/100*i,a=this.gradientColors?`url(#${this.gradientId})`:this.color,n=this.createCircle(t,e,{stroke:a,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${i} ${s}`,strokeDashoffset:this.animate?i:o,transform:`rotate(${this.rotation} ${t} ${t})`,class:"circular-progress-bar"});this.svg.appendChild(n),this.animate&&this.animateProgress(n,o)}renderSegments(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r),this.segments.reduce((t,e)=>t+(e.value||0),0)>this.max&&console.warn("CircularProgress: Segment total exceeds max value. Clamping to max.");let o=0;this.segments.forEach((r,a)=>{const n=(r.value||0)/(this.max-this.min)*100/100*i,h=this.segmentGap/360*s;if(n>0){const l=this.createCircle(t,e,{stroke:r.color||this.color,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${n} ${s}`,strokeDashoffset:this.animate?i:-o,transform:`rotate(${this.rotation} ${t} ${t})`,class:`circular-progress-segment circular-progress-segment-${a}`,"data-segment-index":a});this.svg.appendChild(l),this.animate&&this.animateProgress(l,-o,100*a),o+=n+h}})}createCircle(t,e,s={}){const i=document.createElementNS("http://www.w3.org/2000/svg","circle");return i.setAttribute("cx",t),i.setAttribute("cy",t),i.setAttribute("r",e),Object.entries(s).forEach(([t,e])=>{"strokeWidth"===t?i.setAttribute("stroke-width",e):"strokeLinecap"===t?i.setAttribute("stroke-linecap",e):"strokeDasharray"===t?i.setAttribute("stroke-dasharray",e):"strokeDashoffset"===t?i.setAttribute("stroke-dashoffset",e):i.setAttribute(t,e)}),i}createGradient(){const t=document.createElementNS("http://www.w3.org/2000/svg","defs"),e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",this.gradientId),e.setAttribute("x1","0%"),e.setAttribute("y1","0%"),e.setAttribute("x2","100%"),e.setAttribute("y2","100%"),this.gradientColors.forEach((t,s)=>{const i=document.createElementNS("http://www.w3.org/2000/svg","stop"),r=s/(this.gradientColors.length-1)*100;i.setAttribute("offset",`${r}%`),i.setAttribute("stop-color",t),e.appendChild(i)}),t.appendChild(e),this.svg.appendChild(t)}animateProgress(t,e,s=0){setTimeout(()=>{t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=e},s)}renderCenterContent(){if(this.centerElement)if(this.labelHtml)this.centerElement.innerHTML=this.labelHtml;else if(this.icon)this.centerElement.innerHTML=`<i class="${this.icon}"></i>`;else if(this.showValue){let t=`<div class="circular-progress-value">${this.getFormattedValue()}</div>`;this.label&&(t+=`<div class="circular-progress-label">${this.label}</div>`),this.centerElement.innerHTML=t}}getFormattedValue(){const t=this.value,e=this.min,s=this.max;if(this.valueFormatter&&"function"==typeof this.valueFormatter)return this.valueFormatter(t,e,s);switch(this.valueFormat){case"percentage":return`${Math.round(this.getPercentage())}%`;case"fraction":return`${t}/${s}`;case"value":return t.toString();default:if(this.dataFormatter)try{return this.dataFormatter.pipe(t,this.valueFormat)}catch(i){return console.warn("CircularProgress: DataFormatter error, falling back to percentage",i),`${Math.round(this.getPercentage())}%`}return`${Math.round(this.getPercentage())}%`}}getPercentage(){const t=this.max-this.min;return 0===t?0:(this.value-this.min)/t*100}setupClickHandler(){this.containerElement&&(this.containerElement.style.cursor="pointer",this.containerElement.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=this.getPercentage();this.emit("progress:clicked",{value:this.value,percentage:e,min:this.min,max:this.max}),this.tooltip&&this.togglePopover()}))}setupTooltip(){}togglePopover(){if(this.containerElement&&void 0!==window.bootstrap){if(!this.popover){const t=this.getTooltipContent(),e="object"==typeof this.tooltip&&this.tooltip.title?this.tooltip.title:void 0,s={content:t,html:!0,placement:this.tooltipPlacement,trigger:"manual",container:"body"};e&&(s.title=e),this.popover=new window.bootstrap.Popover(this.containerElement,s)}window.bootstrap.Popover.getInstance(this.containerElement)&&this.containerElement.getAttribute("aria-describedby")?this.popover.hide():(this.popover.setContent({".popover-body":this.getTooltipContent()}),this.popover.show())}else console.warn("CircularProgress: Bootstrap is required for tooltip support")}getTooltipContent(){return"function"==typeof this.tooltip?this.tooltip(this.value,{min:this.min,max:this.max,percentage:this.getPercentage()}):"object"==typeof this.tooltip?this.tooltip.html||this.tooltip.content||"":this.tooltip||""}setValue(t,e=!0){if(this.value,this.value=Math.max(this.min,Math.min(this.max,t)),this.renderCenterContent(),this.svg&&!this.segments){const t=this.svg.querySelector(".circular-progress-bar");if(t){const s=this.size/2-this.strokeWidth/2,i=2*Math.PI*s,r=(this.gap>0?360-this.gap:360)/360*i,o=r-this.getPercentage()/100*r;e?(t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=o):(t.style.transition="none",t.style.strokeDashoffset=o)}}else{const t=this.animate;this.animate=e,this.renderProgress(),this.animate=t}}setRange(t,e){this.min=t,this.max=e,this.renderProgress(),this.renderCenterContent()}increment(t=1){this.setValue(this.value+t)}decrement(t=1){this.setValue(this.value-t)}setColor(t){if(this.color=t,this.gradientColors=null,this.svg&&!this.segments){const e=this.svg.querySelector(".circular-progress-bar");e&&e.setAttribute("stroke",t)}else this.renderProgress()}setGradient(t){Array.isArray(t)&&t.length>1&&(this.gradientColors=t,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`,this.renderProgress())}setSize(t){this.containerElement&&this.sizePreset&&this.containerElement.classList.remove(`circular-progress-${this.sizePreset}`),this.sizePreset="string"==typeof t&&this.SIZE_PRESETS[t]?t:null,this.size=this.resolveSize(t),this.strokeWidth=this.getAutoStrokeWidth(t),this.containerElement&&(this.containerElement.style.width=`${this.size}px`,this.containerElement.style.height=`${this.size}px`,this.sizePreset&&this.containerElement.classList.add(`circular-progress-${this.sizePreset}`)),this.svg&&(this.svg.setAttribute("width",this.size),this.svg.setAttribute("height",this.size),this.svg.setAttribute("viewBox",`0 0 ${this.size} ${this.size}`)),this.renderProgress()}animateTo(t,e=1e3){const s=this.value,i=t-s,r=performance.now(),o=a=>{const n=a-r,h=Math.min(n/e,1),l=1-Math.pow(1-h,3),c=s+i*l;this.setValue(c,!1),h<1?requestAnimationFrame(o):this.setValue(t,!1)};requestAnimationFrame(o)}pulse(){this.containerElement&&(this.containerElement.style.animation="none",setTimeout(()=>{this.containerElement.style.animation="circular-progress-pulse 0.5s ease-out"},10),setTimeout(()=>{this.containerElement.style.animation=""},500))}complete(){this.variant="success",this.applyVariant(),this.setValue(this.max),this.pulse()}reset(){this.setValue(this.min)}hide(){this.element&&(this.element.style.display="none")}show(){this.element&&(this.element.style.display="")}getValue(){return this.value}getPercentageValue(){return this.getPercentage()}async onBeforeDestroy(){this.popover&&(this.popover.dispose(),this.popover=null),await super.onBeforeDestroy()}}export{c as BUILD_TIME,CircularProgress,t as MetricsChart,e as MetricsMiniChart,s as MetricsMiniChartWidget,i as MiniChart,r as PieChart,o as SeriesChart,u as VERSION,g as VERSION_INFO,d as VERSION_MAJOR,m as VERSION_MINOR,p as VERSION_REVISION,l as WebApp,a as exportChartPng};
|
|
1
|
+
import{M as t,a as e,b as s,c as i,P as r,S as o,e as a}from"./chunks/exportChart-BQXkqsxe.js";import{V as n}from"./chunks/View-D6Ug7M6k.js";import{d as h}from"./chunks/Collection-BtSHP_BV.js";import{W as l}from"./chunks/WebApp-CLTFSbto.js";import{B as c,V as u,a as g,b as d,c as m,d as p}from"./chunks/version-xpJSWoyH.js";class CircularProgress extends n{constructor(t={}){super({className:`circular-progress ${t.className||""}`,...t}),this.SIZE_PRESETS={xs:40,sm:60,md:80,lg:120,xl:180},this.STROKE_PRESETS={xs:4,sm:6,md:8,lg:12,xl:16},this.value=void 0!==t.value?t.value:0,this.min=void 0!==t.min?t.min:0,this.max=void 0!==t.max?t.max:100,this.sizePreset="string"==typeof t.size&&this.SIZE_PRESETS[t.size]?t.size:null,this.size=this.resolveSize(void 0!==t.size?t.size:"md"),this.strokeWidth="auto"===t.strokeWidth||void 0===t.strokeWidth?this.getAutoStrokeWidth(t.size):t.strokeWidth,this.theme=t.theme||"basic",this.variant=t.variant||"default",this.color=t.color,this.trackColor=t.trackColor,this.textColor=t.textColor,this.gradientColors=t.gradientColors||null,this.applyTheme(),this.applyVariant(),this.rotation=void 0!==t.rotation?t.rotation:-90,this.gap=t.gap||0,this.showValue=!1!==t.showValue,this.valueFormat=t.valueFormat||"percentage",this.valueFormatter=t.valueFormatter||null,this.label=t.label||null,this.labelHtml=t.labelHtml||null,this.icon=t.icon||null,this.animate=!1!==t.animate,this.animationDuration=t.animationDuration||600,this.animationEasing=t.animationEasing||"ease-out",this.rounded=!1!==t.rounded,this.shadow=t.shadow||!1,this.clickable=t.clickable||!1,this.tooltip=t.tooltip||null,this.tooltipPlacement=t.tooltipPlacement||"top",this.segments=t.segments||null,this.segmentGap=t.segmentGap||2,this.dataFormatter=h,this.svg=null,this.centerElement=null,this.popover=null,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`}resolveSize(t){return"string"==typeof t&&this.SIZE_PRESETS[t]?this.SIZE_PRESETS[t]:"number"==typeof t?t:this.SIZE_PRESETS.md}getAutoStrokeWidth(t){if("string"==typeof t&&this.STROKE_PRESETS[t])return this.STROKE_PRESETS[t];const e=this.resolveSize(t);return e<=40?4:e<=60?6:e<=80?8:e<=120?12:16}applyTheme(){const t={basic:{trackColor:"#e9ecef",textColor:null,backgroundColor:null},shadowed:{trackColor:"#d1d5db",textColor:null,backgroundColor:null,shadow:!0},dark:{trackColor:"#374151",textColor:"#e5e7eb",backgroundColor:"#1f2937"},light:{trackColor:"#f3f4f6",textColor:"#111827",backgroundColor:"#ffffff"}},e=t[this.theme]||t.basic;this.trackColor||(this.trackColor=e.trackColor),!this.textColor&&e.textColor&&(this.textColor=e.textColor),e.shadow&&!1===this.shadow&&(this.shadow=e.shadow)}applyVariant(){const t={success:{color:"#198754",trackColor:"rgba(25, 135, 84, 0.1)"},danger:{color:"#dc3545",trackColor:"rgba(220, 53, 69, 0.1)"},warning:{color:"#ffc107",trackColor:"rgba(255, 193, 7, 0.1)"},info:{color:"#0dcaf0",trackColor:"rgba(13, 202, 240, 0.1)"},default:{color:"#0d6efd"}};if(t[this.variant]){const e=t[this.variant];this.color||(this.color=e.color),e.trackColor&&this.trackColor===this.applyTheme.trackColor&&(this.trackColor=e.trackColor)}this.color||(this.color="#0d6efd")}getTemplate(){const t=this.sizePreset?`circular-progress-${this.sizePreset}`:"",e="default"!==this.variant?`circular-progress-${this.variant}`:"",s="basic"!==this.theme?`circular-progress-theme-${this.theme}`:"",i=this.clickable?"circular-progress-clickable":"",r=this.shadow?"circular-progress-shadow":"",o=this.textColor?`color: ${this.textColor};`:"";return`\n <div class="circular-progress-container ${t} ${e} ${s} ${i} ${r}"\n style="width: ${this.size}px; height: ${this.size}px;">\n <svg class="circular-progress-svg" \n width="${this.size}" \n height="${this.size}"\n viewBox="0 0 ${this.size} ${this.size}">\n </svg>\n <div class="circular-progress-center" style="${o}">\n <div class="circular-progress-content"></div>\n </div>\n </div>\n `}async onAfterRender(){this.svg=this.element.querySelector(".circular-progress-svg"),this.centerElement=this.element.querySelector(".circular-progress-content"),this.containerElement=this.element.querySelector(".circular-progress-container"),this.renderProgress(),this.renderCenterContent(),this.clickable&&this.setupClickHandler(),this.tooltip&&this.clickable&&this.setupTooltip()}renderProgress(){if(!this.svg)return;this.svg.innerHTML="";const t=this.size/2,e=(this.size-this.strokeWidth)/2,s=2*Math.PI*e;this.gradientColors&&this.gradientColors.length>1&&this.createGradient(),this.segments&&Array.isArray(this.segments)&&this.segments.length>0?this.renderSegments(t,e,s):this.renderSingleProgress(t,e,s)}renderSingleProgress(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r);const o=i-this.getPercentage()/100*i,a=this.gradientColors?`url(#${this.gradientId})`:this.color,n=this.createCircle(t,e,{stroke:a,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${i} ${s}`,strokeDashoffset:this.animate?i:o,transform:`rotate(${this.rotation} ${t} ${t})`,class:"circular-progress-bar"});this.svg.appendChild(n),this.animate&&this.animateProgress(n,o)}renderSegments(t,e,s){const i=(this.gap>0?360-this.gap:360)/360*s,r=this.createCircle(t,e,{stroke:this.trackColor,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:this.gap>0?`${i} ${s}`:"none",transform:`rotate(${this.rotation} ${t} ${t})`});this.svg.appendChild(r),this.segments.reduce((t,e)=>t+(e.value||0),0)>this.max&&console.warn("CircularProgress: Segment total exceeds max value. Clamping to max.");let o=0;this.segments.forEach((r,a)=>{const n=(r.value||0)/(this.max-this.min)*100/100*i,h=this.segmentGap/360*s;if(n>0){const l=this.createCircle(t,e,{stroke:r.color||this.color,strokeWidth:this.strokeWidth,fill:"none",strokeLinecap:this.rounded?"round":"butt",strokeDasharray:`${n} ${s}`,strokeDashoffset:this.animate?i:-o,transform:`rotate(${this.rotation} ${t} ${t})`,class:`circular-progress-segment circular-progress-segment-${a}`,"data-segment-index":a});this.svg.appendChild(l),this.animate&&this.animateProgress(l,-o,100*a),o+=n+h}})}createCircle(t,e,s={}){const i=document.createElementNS("http://www.w3.org/2000/svg","circle");return i.setAttribute("cx",t),i.setAttribute("cy",t),i.setAttribute("r",e),Object.entries(s).forEach(([t,e])=>{"strokeWidth"===t?i.setAttribute("stroke-width",e):"strokeLinecap"===t?i.setAttribute("stroke-linecap",e):"strokeDasharray"===t?i.setAttribute("stroke-dasharray",e):"strokeDashoffset"===t?i.setAttribute("stroke-dashoffset",e):i.setAttribute(t,e)}),i}createGradient(){const t=document.createElementNS("http://www.w3.org/2000/svg","defs"),e=document.createElementNS("http://www.w3.org/2000/svg","linearGradient");e.setAttribute("id",this.gradientId),e.setAttribute("x1","0%"),e.setAttribute("y1","0%"),e.setAttribute("x2","100%"),e.setAttribute("y2","100%"),this.gradientColors.forEach((t,s)=>{const i=document.createElementNS("http://www.w3.org/2000/svg","stop"),r=s/(this.gradientColors.length-1)*100;i.setAttribute("offset",`${r}%`),i.setAttribute("stop-color",t),e.appendChild(i)}),t.appendChild(e),this.svg.appendChild(t)}animateProgress(t,e,s=0){setTimeout(()=>{t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=e},s)}renderCenterContent(){if(this.centerElement)if(this.labelHtml)this.centerElement.innerHTML=this.labelHtml;else if(this.icon)this.centerElement.innerHTML=`<i class="${this.icon}"></i>`;else if(this.showValue){let t=`<div class="circular-progress-value">${this.getFormattedValue()}</div>`;this.label&&(t+=`<div class="circular-progress-label">${this.label}</div>`),this.centerElement.innerHTML=t}}getFormattedValue(){const t=this.value,e=this.min,s=this.max;if(this.valueFormatter&&"function"==typeof this.valueFormatter)return this.valueFormatter(t,e,s);switch(this.valueFormat){case"percentage":return`${Math.round(this.getPercentage())}%`;case"fraction":return`${t}/${s}`;case"value":return t.toString();default:if(this.dataFormatter)try{return this.dataFormatter.pipe(t,this.valueFormat)}catch(i){return console.warn("CircularProgress: DataFormatter error, falling back to percentage",i),`${Math.round(this.getPercentage())}%`}return`${Math.round(this.getPercentage())}%`}}getPercentage(){const t=this.max-this.min;return 0===t?0:(this.value-this.min)/t*100}setupClickHandler(){this.containerElement&&(this.containerElement.style.cursor="pointer",this.containerElement.addEventListener("click",t=>{t.preventDefault(),t.stopPropagation();const e=this.getPercentage();this.emit("progress:clicked",{value:this.value,percentage:e,min:this.min,max:this.max}),this.tooltip&&this.togglePopover()}))}setupTooltip(){}togglePopover(){if(this.containerElement&&void 0!==window.bootstrap){if(!this.popover){const t=this.getTooltipContent(),e="object"==typeof this.tooltip&&this.tooltip.title?this.tooltip.title:void 0,s={content:t,html:!0,placement:this.tooltipPlacement,trigger:"manual",container:"body"};e&&(s.title=e),this.popover=new window.bootstrap.Popover(this.containerElement,s)}window.bootstrap.Popover.getInstance(this.containerElement)&&this.containerElement.getAttribute("aria-describedby")?this.popover.hide():(this.popover.setContent({".popover-body":this.getTooltipContent()}),this.popover.show())}else console.warn("CircularProgress: Bootstrap is required for tooltip support")}getTooltipContent(){return"function"==typeof this.tooltip?this.tooltip(this.value,{min:this.min,max:this.max,percentage:this.getPercentage()}):"object"==typeof this.tooltip?this.tooltip.html||this.tooltip.content||"":this.tooltip||""}setValue(t,e=!0){if(this.value,this.value=Math.max(this.min,Math.min(this.max,t)),this.renderCenterContent(),this.svg&&!this.segments){const t=this.svg.querySelector(".circular-progress-bar");if(t){const s=this.size/2-this.strokeWidth/2,i=2*Math.PI*s,r=(this.gap>0?360-this.gap:360)/360*i,o=r-this.getPercentage()/100*r;e?(t.style.transition=`stroke-dashoffset ${this.animationDuration}ms ${this.animationEasing}`,t.style.strokeDashoffset=o):(t.style.transition="none",t.style.strokeDashoffset=o)}}else{const t=this.animate;this.animate=e,this.renderProgress(),this.animate=t}}setRange(t,e){this.min=t,this.max=e,this.renderProgress(),this.renderCenterContent()}increment(t=1){this.setValue(this.value+t)}decrement(t=1){this.setValue(this.value-t)}setColor(t){if(this.color=t,this.gradientColors=null,this.svg&&!this.segments){const e=this.svg.querySelector(".circular-progress-bar");e&&e.setAttribute("stroke",t)}else this.renderProgress()}setGradient(t){Array.isArray(t)&&t.length>1&&(this.gradientColors=t,this.gradientId=`gradient-${Math.random().toString(36).substr(2,9)}`,this.renderProgress())}setSize(t){this.containerElement&&this.sizePreset&&this.containerElement.classList.remove(`circular-progress-${this.sizePreset}`),this.sizePreset="string"==typeof t&&this.SIZE_PRESETS[t]?t:null,this.size=this.resolveSize(t),this.strokeWidth=this.getAutoStrokeWidth(t),this.containerElement&&(this.containerElement.style.width=`${this.size}px`,this.containerElement.style.height=`${this.size}px`,this.sizePreset&&this.containerElement.classList.add(`circular-progress-${this.sizePreset}`)),this.svg&&(this.svg.setAttribute("width",this.size),this.svg.setAttribute("height",this.size),this.svg.setAttribute("viewBox",`0 0 ${this.size} ${this.size}`)),this.renderProgress()}animateTo(t,e=1e3){const s=this.value,i=t-s,r=performance.now(),o=a=>{const n=a-r,h=Math.min(n/e,1),l=1-Math.pow(1-h,3),c=s+i*l;this.setValue(c,!1),h<1?requestAnimationFrame(o):this.setValue(t,!1)};requestAnimationFrame(o)}pulse(){this.containerElement&&(this.containerElement.style.animation="none",setTimeout(()=>{this.containerElement.style.animation="circular-progress-pulse 0.5s ease-out"},10),setTimeout(()=>{this.containerElement.style.animation=""},500))}complete(){this.variant="success",this.applyVariant(),this.setValue(this.max),this.pulse()}reset(){this.setValue(this.min)}hide(){this.element&&(this.element.style.display="none")}show(){this.element&&(this.element.style.display="")}getValue(){return this.value}getPercentageValue(){return this.getPercentage()}async onBeforeDestroy(){this.popover&&(this.popover.dispose(),this.popover=null),await super.onBeforeDestroy()}}export{c as BUILD_TIME,CircularProgress,t as MetricsChart,e as MetricsMiniChart,s as MetricsMiniChartWidget,i as MiniChart,r as PieChart,o as SeriesChart,u as VERSION,g as VERSION_INFO,d as VERSION_MAJOR,m as VERSION_MINOR,p as VERSION_REVISION,l as WebApp,a as exportChartPng};
|
|
2
2
|
//# sourceMappingURL=charts.es.js.map
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import{V as t}from"./View-Cvs2TY7b.js";import{C as s}from"./ChatView-ys5MIiBf.js";import{AssistantConversationList as e,Assistant as n}from"../admin-models.es.js";import{A as i,a,b as o}from"./admin-DtjMWe6R.js";class AssistantPanelView extends t{constructor(t={}){super({className:"assistant-panel-view",...t}),this.app=t.app,this.ws=this.app?.ws,this.conversationId=t.conversationId||this.app?._assistantConversationId||null,this._wsHandlers={},this._messageIdCounter=0,this._hasMessages=!1,this._activePlans={},this._requestStartTime=null,this._showingHistory=!1}getTemplate(){return`\n <div class="assistant-panel-resize-handle" data-ref="resize-handle"></div>\n <div class="assistant-panel-layout">\n <div class="assistant-panel-header">\n <button class="assistant-panel-header-btn" data-action="toggle-history" type="button" title="Conversation history">\n <i class="bi bi-list"></i>\n </button>\n <span class="assistant-panel-title text-truncate" data-ref="panel-title">New conversation</span>\n <div class="d-flex gap-1 ms-auto">\n <button class="assistant-panel-header-btn" data-action="new-conversation" type="button" title="New conversation">\n <i class="bi bi-plus-lg"></i>\n </button>\n <button class="assistant-panel-header-btn" data-action="fullscreen" type="button" title="Open fullscreen">\n <i class="bi bi-arrows-fullscreen"></i>\n </button>\n <button class="assistant-panel-header-btn" data-action="pop-out" type="button" title="Open in popup window">\n <i class="bi bi-box-arrow-up-right"></i>\n </button>\n <button class="assistant-panel-header-btn" data-action="close-panel" type="button" title="Close">\n <i class="bi bi-x-lg"></i>\n </button>\n </div>\n </div>\n\n <div class="assistant-panel-history d-none" data-ref="history" data-container="conversation-list"></div>\n\n <div class="assistant-panel-chat" data-ref="chat-wrapper">\n <div class="assistant-welcome" data-ref="welcome">\n <div class="assistant-welcome-content">\n <div class="assistant-welcome-icon">\n <i class="bi bi-stars"></i>\n </div>\n <h3 class="assistant-welcome-title">Hi ${this._escapeHtml(this.app?.activeUser?.get("first_name")||"there")}</h3>\n <p class="assistant-welcome-subtitle">How can I help you today?</p>\n <div class="assistant-suggestions">\n <button class="assistant-suggestion" data-action="use-suggestion" data-text="Show me a summary of recent activity">\n <i class="bi bi-activity"></i>\n <span>Recent activity summary</span>\n </button>\n <button class="assistant-suggestion" data-action="use-suggestion" data-text="How many active users are there?">\n <i class="bi bi-people"></i>\n <span>Active user count</span>\n </button>\n </div>\n </div>\n </div>\n <div class="assistant-chat-area" data-container="chat-area"></div>\n <div class="assistant-input-wrapper">\n <div class="assistant-input-status d-none" data-ref="input-status"></div>\n <div class="assistant-input-box">\n <textarea class="assistant-input" placeholder="Message the assistant..." rows="1" data-ref="input"></textarea>\n <button class="assistant-send-btn" data-action="send" type="button" title="Send message" data-ref="send-btn">\n <i class="bi bi-arrow-up"></i>\n </button>\n <button class="assistant-stop-btn d-none" data-action="stop" type="button" title="Stop generating" data-ref="stop-btn">\n <i class="bi bi-stop-fill"></i>\n </button>\n </div>\n <div class="assistant-input-footer">\n <span class="assistant-connection-indicator" data-ref="status">\n <span class="status-dot connected"></span>\n </span>\n <span class="text-muted">Enter to send</span>\n </div>\n </div>\n </div>\n </div>\n `}async onInit(){this.conversations=new e,this.conversations.params.user=this.app?.activeUser?.id,this.conversationListView=new i({containerId:"conversation-list",collection:this.conversations}),this.addChild(this.conversationListView),this.chatView=new s({containerId:"chat-area",theme:"compact",messageViewClass:a,currentUserId:this.app?.activeUser?.id,showFileInput:!1,showInput:!1,adapter:this._createAdapter()}),this.addChild(this.chatView);const t=this.chatView.addMessage.bind(this.chatView);this.chatView.addMessage=(s,e)=>{t(s,e),"assistant"===s.role&&(s.content||s.blocks?.length)&&(this.chatView.hideThinking(),this._setInputEnabled(!0))},this.conversationListView.on("conversation:select",t=>{this._onConversationSelect(t),this._toggleHistory(!1)}),this.conversationListView.on("conversation:new",()=>{this._onNewConversation(),this._toggleHistory(!1)}),this.conversationListView.on("conversation:deleted",t=>this._onConversationDeleted(t)),this._subscribeWS()}async onAfterRender(){await super.onAfterRender();const t=this.element.querySelector('[data-ref="input"]');t&&(t.addEventListener("input",()=>this._autoResize(t)),t.addEventListener("keydown",t=>this._handleKeydown(t)),setTimeout(()=>t.focus(),100)),this.conversationId&&(this._showChatArea(),await this.chatView.refresh()),this._updateConnectionStatus(),this._updateTitle(),this._setupResizeHandle()}_setupResizeHandle(){const t=this.element?.querySelector('[data-ref="resize-handle"]');if(!t)return;const s="mojo:assistant_panel_width",e=localStorage.getItem(s);if(e){const t=parseInt(e,10);if(t>=300&&t<=700){const s=document.getElementById("assistant-panel");s&&(s.style.width=t+"px")}}let n,i;const a=t=>{const s=n-t.clientX,e=Math.min(700,Math.max(300,i+s)),a=document.getElementById("assistant-panel");a&&(a.style.width=e+"px")},o=()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",o),document.body.style.cursor="",document.body.style.userSelect="";const t=document.getElementById("assistant-panel");t&&localStorage.setItem(s,parseInt(t.style.width,10))};t.addEventListener("mousedown",t=>{t.preventDefault(),n=t.clientX;const s=document.getElementById("assistant-panel");i=s?s.offsetWidth:500,document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",a),document.addEventListener("mouseup",o)})}onActionToggleHistory(){this._toggleHistory(!this._showingHistory)}onActionNewConversation(){this._onNewConversation(),this._showingHistory&&this._toggleHistory(!1)}onActionClosePanel(){this.emit("panel:close")}onActionFullscreen(){this.emit("panel:fullscreen",{conversationId:this.conversationId})}onActionPopOut(){this.emit("panel:popout",{conversationId:this.conversationId})}onActionUseSuggestion(t,s){const e=s.dataset.text||s.closest("[data-text]")?.dataset.text;if(!e)return;const n=this.element.querySelector('[data-ref="input"]');n&&(n.value=e,this._autoResize(n)),this._sendMessage()}onActionSend(){this._sendMessage()}onActionStop(){this.chatView.hideThinking(),this._setInputEnabled(!0),this._showSystemMessage("Response cancelled.");const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}_toggleHistory(t){this._showingHistory=t;const s=this.element?.querySelector('[data-ref="history"]'),e=this.element?.querySelector('[data-ref="chat-wrapper"]'),n=this.element?.querySelector('[data-action="toggle-history"] i');s&&s.classList.toggle("d-none",!t),e&&e.classList.toggle("d-none",t),n&&(n.className=t?"bi bi-chat-dots":"bi bi-list"),t&&this.conversationListView.refresh()}_autoResize(t){t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px"}_handleKeydown(t){"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this._sendMessage())}async _sendMessage(){const t=this.element.querySelector('[data-ref="input"]');if(!t)return;const s=t.value.trim();s&&(t.value="",t.style.height="auto",this._showChatArea(),await this.chatView.adapter.addNote({text:s,files:[]}))}_showChatArea(){if(this._hasMessages)return;this._hasMessages=!0;const t=this.element.querySelector('[data-ref="welcome"]'),s=this.element.querySelector('[data-container="chat-area"]');t&&t.classList.add("d-none"),s&&s.classList.remove("d-none")}_showWelcome(){this._hasMessages=!1;const t=this.element.querySelector('[data-ref="welcome"]'),s=this.element.querySelector('[data-container="chat-area"]');t&&t.classList.remove("d-none"),s&&s.classList.add("d-none")}_setInputEnabled(t,s){const e=this.element?.querySelector('[data-ref="input"]'),n=this.element?.querySelector('[data-ref="send-btn"]'),i=this.element?.querySelector('[data-ref="stop-btn"]');e&&(e.disabled=!t),n&&n.classList.toggle("d-none",!t),i&&i.classList.toggle("d-none",t),this._setInputStatus(t?null:s),this._responseTimeout&&clearTimeout(this._responseTimeout),t?this._requestStartTime=null:this._responseTimeout=setTimeout(()=>this._onResponseTimeout(),6e4)}_setInputStatus(t){const s=this.element?.querySelector('[data-ref="input-status"]');s&&(t?(s.innerHTML=`${this._escapeHtml(t)} <span class="assistant-input-status-dismiss">Click to dismiss</span>`,s.classList.remove("d-none"),s._hasDismiss||(s._hasDismiss=!0,s.addEventListener("click",()=>{this.chatView.hideThinking(),this._setInputEnabled(!0);const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}))):(s.classList.add("d-none"),s.innerHTML=""))}_onResponseTimeout(){this._responseTimeout=null,this.chatView.hideThinking(),this._setInputEnabled(!0),this._showSystemMessage("Request timed out. Please try again.")}_updateTitle(t){const s=this.element?.querySelector('[data-ref="panel-title"]');s&&(s.textContent=t||(this.conversationId?"Assistant":"New conversation"))}_createAdapter(){return{fetch:async()=>{if(!this.conversationId)return[];try{const t=new n({id:this.conversationId});await t.fetch({graph:"detail"});const s=t.get("title")||t.get("summary");s&&this._updateTitle(s);const e=(t.get("messages")||[]).map(t=>this._transformMessage(t)).filter(Boolean);return o._collapseMessages(e)}catch(t){return 404===t.status&&(this._onNewConversation(),this._showSystemMessage("Conversation not found.")),[]}},addNote:async t=>{if(!t.text||!t.text.trim())return{success:!1};const s={id:"local-"+ ++this._messageIdCounter,role:"user",author:{id:this.app?.activeUser?.id,name:this.app?.activeUser?.get("display_name")||"You"},content:t.text,timestamp:/* @__PURE__ */(new Date).toISOString()};if(this.chatView.addMessage(s),this.chatView.showThinking("Thinking..."),this._requestStartTime=Date.now(),this._setInputEnabled(!1,"Waiting for response…"),this.ws&&this.ws.isConnected)this.ws.send({type:"assistant_message",message:t.text,conversation_id:this.conversationId});else try{const s=await this.app.rest.post("/api/assistant",{message:t.text,conversation_id:this.conversationId}),e=s?.data?.data||s?.data||s;e.conversation_id&&(this.conversationId=e.conversation_id,this.app._assistantConversationId=this.conversationId),e.response&&this.chatView.addMessage(this._transformMessage(e.response)),this._setInputEnabled(!0)}catch(e){this._handleAPIError(e)}return{success:!0}}}}_subscribeWS(){this.ws&&(this._wsHandlers={thinking:t=>this._onThinking(t),text:t=>this._onText(t),tool_call:t=>this._onToolCall(t),response:t=>this._onResponse(t),error:t=>this._onError(t),plan:t=>this._onPlan(t),plan_update:t=>this._onPlanUpdate(t),message:t=>this._dispatchWSMessage(t),connected:()=>this._updateConnectionStatus(),disconnected:()=>this._updateConnectionStatus(),reconnecting:()=>this._updateConnectionStatus()},this.ws.on("message:assistant_thinking",this._wsHandlers.thinking),this.ws.on("message:assistant_text",this._wsHandlers.text),this.ws.on("message:assistant_tool_call",this._wsHandlers.tool_call),this.ws.on("message:assistant_response",this._wsHandlers.response),this.ws.on("message:assistant_error",this._wsHandlers.error),this.ws.on("message:assistant_plan",this._wsHandlers.plan),this.ws.on("message:assistant_plan_update",this._wsHandlers.plan_update),this.ws.on("message:message",this._wsHandlers.message),this.ws.on("connected",this._wsHandlers.connected),this.ws.on("disconnected",this._wsHandlers.disconnected),this.ws.on("reconnecting",this._wsHandlers.reconnecting))}_unsubscribeWS(){this.ws&&this._wsHandlers&&(this.ws.off("message:assistant_thinking",this._wsHandlers.thinking),this.ws.off("message:assistant_text",this._wsHandlers.text),this.ws.off("message:assistant_tool_call",this._wsHandlers.tool_call),this.ws.off("message:assistant_response",this._wsHandlers.response),this.ws.off("message:assistant_error",this._wsHandlers.error),this.ws.off("message:assistant_plan",this._wsHandlers.plan),this.ws.off("message:assistant_plan_update",this._wsHandlers.plan_update),this.ws.off("message:message",this._wsHandlers.message),this.ws.off("connected",this._wsHandlers.connected),this.ws.off("disconnected",this._wsHandlers.disconnected),this.ws.off("reconnecting",this._wsHandlers.reconnecting),this._wsHandlers={})}_dispatchWSMessage(t){const s=t?.data;if(s?.type)switch(s.type){case"assistant_thinking":this._onThinking(s);break;case"assistant_text":this._onText(s);break;case"assistant_tool_call":this._onToolCall(s);break;case"assistant_response":this._onResponse(s);break;case"assistant_error":this._onError(s);break;case"assistant_plan":this._onPlan(s);break;case"assistant_plan_update":this._onPlanUpdate(s)}}_isMyConversation(t){return!t.conversation_id||!this.conversationId||String(t.conversation_id)===String(this.conversationId)}_adoptConversationId(t){t.conversation_id&&!this.conversationId&&(this.conversationId=t.conversation_id,this.app._assistantConversationId=this.conversationId)}_onThinking(t){this._isMyConversation(t)&&(this._adoptConversationId(t),this._showChatArea(),this.chatView.showThinking("Thinking..."),this._setInputEnabled(!1,"Assistant is thinking…"))}_onText(t){if(!this._isMyConversation(t))return;this._adoptConversationId(t),this._resetResponseTimeout();const s=this._transformMessage({id:t.message_id||"text-"+ ++this._messageIdCounter,role:"assistant",content:t.text||"",blocks:t.blocks||[],tool_calls:[],created:t.created||t.timestamp||/* @__PURE__ */(new Date).toISOString()});s&&(s.content||s.blocks?.length)&&this.chatView.addMessage(s)}_onToolCall(t){this._isMyConversation(t)&&(this.chatView.showThinking(`Using ${t.tool||t.name||"tool"}...`),this._resetResponseTimeout())}_resetResponseTimeout(){if(this._responseTimeout){if(this._requestStartTime&&Date.now()-this._requestStartTime>=3e5)return void this._onResponseTimeout();clearTimeout(this._responseTimeout),this._responseTimeout=setTimeout(()=>this._onResponseTimeout(),6e4)}}_onResponse(t){if(!this._isMyConversation(t))return;this.chatView.hideThinking(),this._setInputEnabled(!0),this._adoptConversationId(t);const s=this.element?.querySelector('[data-ref="input"]');s&&s.focus();const e=this._transformMessage({id:t.message_id||"resp-"+ ++this._messageIdCounter,role:"assistant",content:t.response||t.content||t.message||"",blocks:t.blocks||[],tool_calls:t.tool_calls_made||t.tool_calls||[],created:t.created||t.timestamp||/* @__PURE__ */(new Date).toISOString()});e&&(e.content||e.blocks?.length||e.tool_calls?.length)&&this.chatView.addMessage(e)}_onError(t){if(!this._isMyConversation(t))return;this.chatView.hideThinking(),this._setInputEnabled(!0),this._adoptConversationId(t);const s=t.error||t.message||"An error occurred";this._showSystemMessage(s)}_onPlan(t){if(!this._isMyConversation(t))return;this._adoptConversationId(t),this._showChatArea();const s=t.plan;s&&(this._activePlans[s.plan_id]=s,this.chatView.addMessage({id:`plan-${s.plan_id}`,role:"assistant",author:{name:"Assistant"},content:"",timestamp:/* @__PURE__ */(new Date).toISOString(),blocks:[{type:"progress",...s}],tool_calls:[]}))}_onPlanUpdate(t){if(!this._isMyConversation(t))return;const s=this._activePlans[t.plan_id];if(s){const e=s.steps.find(s=>s.id===t.step_id);e&&(e.status=t.status,e.summary=t.summary)}const e=this.chatView.messageViews.get(`plan-${t.plan_id}`);e?.updateProgressStep&&e.updateProgressStep(t.plan_id,t.step_id,t.status,t.summary),this._resetResponseTimeout()}async _onConversationSelect(t){this.conversationId=t.id,this.app._assistantConversationId=this.conversationId,this.conversationListView.setActive(t.id),this._showChatArea(),this._updateTitle(t.model?.get("title")||t.model?.get("summary")),await this.chatView.refresh()}_onNewConversation(){this.conversationId=null,this.app._assistantConversationId=null,this.conversationListView.setActive(null),this.chatView.clearMessages(),this._setInputEnabled(!0),this._showWelcome(),this._updateTitle();const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}_onConversationDeleted(t){String(t.id)===String(this.conversationId)&&this._onNewConversation()}_transformMessage(t){if("tool_result"===t.role)return null;let s=t.content||t.text||"",e=t.blocks||[],n=t.tool_calls||[];if(n.length>0){n=n.map(t=>!t.type&&t.tool?{type:"tool_use",name:t.tool,input:t.input}:t);const t=n.filter(t=>"text"===t.type&&t.text).map(t=>t.text);!s&&t.length>0&&(s=t.join("\n\n")),n=n.filter(t=>"tool_use"===t.type).filter(t=>!o.INTERNAL_TOOLS.has(t.name))}if(0===e.length&&s.includes("assistant_block")){const t=o._parseBlocks(s);s=t.content,e=t.blocks}const i=this.app?.activeUser?.id;return{id:t.id,role:t.role||"user",author:"assistant"===t.role?{name:"Assistant"}:t.author||{name:t.user?.display_name||this.app?.activeUser?.get("display_name")||"You",id:t.user?.id||i},content:s,timestamp:t.created||t.timestamp,blocks:e,tool_calls:n,_conversationId:this.conversationId}}_showSystemMessage(t){this._showChatArea(),this.chatView.addMessage({id:"sys-"+ ++this._messageIdCounter,type:"system_event",content:t,timestamp:/* @__PURE__ */(new Date).toISOString()})}_handleAPIError(t){404===t.status?this._showSystemMessage("Assistant is not enabled on this server."):503===t.status?this._showSystemMessage("LLM API key not configured. Contact your administrator."):this._showSystemMessage("Failed to send message. Please try again."),this._setInputEnabled(!0)}_updateConnectionStatus(){const t=this.element?.querySelector(".status-dot");t&&(this.ws?.isConnected?(t.className="status-dot connected",t.title="Connected",this._responseTimeout?this._setInputEnabled(!1,"Waiting for response…"):this._setInputEnabled(!0)):this.ws?.isReconnecting?(t.className="status-dot reconnecting",t.title="Reconnecting...",this._setInputEnabled(!1,"Reconnecting…"),this._responseTimeout&&(clearTimeout(this._responseTimeout),this._responseTimeout=null)):(t.className="status-dot disconnected",t.title="Disconnected",this._setInputEnabled(!1,"Disconnected — reconnecting…"),this._responseTimeout&&(clearTimeout(this._responseTimeout),this._responseTimeout=null)))}_escapeHtml(t){const s=document.createElement("div");return s.textContent=t,s.innerHTML}focusInput(){const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}async onBeforeDestroy(){this._unsubscribeWS(),this._responseTimeout&&(clearTimeout(this._responseTimeout),this._responseTimeout=null)}}export{AssistantPanelView as default};
|
|
2
|
-
//# sourceMappingURL=AssistantPanelView-
|
|
1
|
+
import{V as t}from"./View-D6Ug7M6k.js";import{C as s}from"./ChatView-B-2JVhM3.js";import{AssistantConversationList as e,Assistant as n}from"../admin-models.es.js";import{A as i,a,b as o}from"./admin-DcLy2QC2.js";class AssistantPanelView extends t{constructor(t={}){super({className:"assistant-panel-view",...t}),this.app=t.app,this.ws=this.app?.ws,this.conversationId=t.conversationId||this.app?._assistantConversationId||null,this._wsHandlers={},this._messageIdCounter=0,this._hasMessages=!1,this._activePlans={},this._requestStartTime=null,this._showingHistory=!1}getTemplate(){return`\n <div class="assistant-panel-resize-handle" data-ref="resize-handle"></div>\n <div class="assistant-panel-layout">\n <div class="assistant-panel-header">\n <button class="assistant-panel-header-btn" data-action="toggle-history" type="button" title="Conversation history">\n <i class="bi bi-list"></i>\n </button>\n <span class="assistant-panel-title text-truncate" data-ref="panel-title">New conversation</span>\n <div class="d-flex gap-1 ms-auto">\n <button class="assistant-panel-header-btn" data-action="new-conversation" type="button" title="New conversation">\n <i class="bi bi-plus-lg"></i>\n </button>\n <button class="assistant-panel-header-btn" data-action="fullscreen" type="button" title="Open fullscreen">\n <i class="bi bi-arrows-fullscreen"></i>\n </button>\n <button class="assistant-panel-header-btn" data-action="pop-out" type="button" title="Open in popup window">\n <i class="bi bi-box-arrow-up-right"></i>\n </button>\n <button class="assistant-panel-header-btn" data-action="close-panel" type="button" title="Close">\n <i class="bi bi-x-lg"></i>\n </button>\n </div>\n </div>\n\n <div class="assistant-panel-history d-none" data-ref="history" data-container="conversation-list"></div>\n\n <div class="assistant-panel-chat" data-ref="chat-wrapper">\n <div class="assistant-welcome" data-ref="welcome">\n <div class="assistant-welcome-content">\n <div class="assistant-welcome-icon">\n <i class="bi bi-stars"></i>\n </div>\n <h3 class="assistant-welcome-title">Hi ${this._escapeHtml(this.app?.activeUser?.get("first_name")||"there")}</h3>\n <p class="assistant-welcome-subtitle">How can I help you today?</p>\n <div class="assistant-suggestions">\n <button class="assistant-suggestion" data-action="use-suggestion" data-text="Show me a summary of recent activity">\n <i class="bi bi-activity"></i>\n <span>Recent activity summary</span>\n </button>\n <button class="assistant-suggestion" data-action="use-suggestion" data-text="How many active users are there?">\n <i class="bi bi-people"></i>\n <span>Active user count</span>\n </button>\n </div>\n </div>\n </div>\n <div class="assistant-chat-area" data-container="chat-area"></div>\n <div class="assistant-input-wrapper">\n <div class="assistant-input-status d-none" data-ref="input-status"></div>\n <div class="assistant-input-box">\n <textarea class="assistant-input" placeholder="Message the assistant..." rows="1" data-ref="input"></textarea>\n <button class="assistant-send-btn" data-action="send" type="button" title="Send message" data-ref="send-btn">\n <i class="bi bi-arrow-up"></i>\n </button>\n <button class="assistant-stop-btn d-none" data-action="stop" type="button" title="Stop generating" data-ref="stop-btn">\n <i class="bi bi-stop-fill"></i>\n </button>\n </div>\n <div class="assistant-input-footer">\n <span class="assistant-connection-indicator" data-ref="status">\n <span class="status-dot connected"></span>\n </span>\n <span class="text-muted">Enter to send</span>\n </div>\n </div>\n </div>\n </div>\n `}async onInit(){this.conversations=new e,this.conversations.params.user=this.app?.activeUser?.id,this.conversationListView=new i({containerId:"conversation-list",collection:this.conversations}),this.addChild(this.conversationListView),this.chatView=new s({containerId:"chat-area",theme:"compact",messageViewClass:a,currentUserId:this.app?.activeUser?.id,showFileInput:!1,showInput:!1,adapter:this._createAdapter()}),this.addChild(this.chatView);const t=this.chatView.addMessage.bind(this.chatView);this.chatView.addMessage=(s,e)=>{t(s,e),"assistant"===s.role&&(s.content||s.blocks?.length)&&(this.chatView.hideThinking(),this._setInputEnabled(!0))},this.conversationListView.on("conversation:select",t=>{this._onConversationSelect(t),this._toggleHistory(!1)}),this.conversationListView.on("conversation:new",()=>{this._onNewConversation(),this._toggleHistory(!1)}),this.conversationListView.on("conversation:deleted",t=>this._onConversationDeleted(t)),this._subscribeWS()}async onAfterRender(){await super.onAfterRender();const t=this.element.querySelector('[data-ref="input"]');t&&(t.addEventListener("input",()=>this._autoResize(t)),t.addEventListener("keydown",t=>this._handleKeydown(t)),setTimeout(()=>t.focus(),100)),this.conversationId&&(this._showChatArea(),await this.chatView.refresh()),this._updateConnectionStatus(),this._updateTitle(),this._setupResizeHandle()}_setupResizeHandle(){const t=this.element?.querySelector('[data-ref="resize-handle"]');if(!t)return;const s="mojo:assistant_panel_width",e=localStorage.getItem(s);if(e){const t=parseInt(e,10);if(t>=300&&t<=700){const s=document.getElementById("assistant-panel");s&&(s.style.width=t+"px")}}let n,i;const a=t=>{const s=n-t.clientX,e=Math.min(700,Math.max(300,i+s)),a=document.getElementById("assistant-panel");a&&(a.style.width=e+"px")},o=()=>{document.removeEventListener("mousemove",a),document.removeEventListener("mouseup",o),document.body.style.cursor="",document.body.style.userSelect="";const t=document.getElementById("assistant-panel");t&&localStorage.setItem(s,parseInt(t.style.width,10))};t.addEventListener("mousedown",t=>{t.preventDefault(),n=t.clientX;const s=document.getElementById("assistant-panel");i=s?s.offsetWidth:500,document.body.style.cursor="col-resize",document.body.style.userSelect="none",document.addEventListener("mousemove",a),document.addEventListener("mouseup",o)})}onActionToggleHistory(){this._toggleHistory(!this._showingHistory)}onActionNewConversation(){this._onNewConversation(),this._showingHistory&&this._toggleHistory(!1)}onActionClosePanel(){this.emit("panel:close")}onActionFullscreen(){this.emit("panel:fullscreen",{conversationId:this.conversationId})}onActionPopOut(){this.emit("panel:popout",{conversationId:this.conversationId})}onActionUseSuggestion(t,s){const e=s.dataset.text||s.closest("[data-text]")?.dataset.text;if(!e)return;const n=this.element.querySelector('[data-ref="input"]');n&&(n.value=e,this._autoResize(n)),this._sendMessage()}onActionSend(){this._sendMessage()}onActionStop(){this.chatView.hideThinking(),this._setInputEnabled(!0),this._showSystemMessage("Response cancelled.");const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}_toggleHistory(t){this._showingHistory=t;const s=this.element?.querySelector('[data-ref="history"]'),e=this.element?.querySelector('[data-ref="chat-wrapper"]'),n=this.element?.querySelector('[data-action="toggle-history"] i');s&&s.classList.toggle("d-none",!t),e&&e.classList.toggle("d-none",t),n&&(n.className=t?"bi bi-chat-dots":"bi bi-list"),t&&this.conversationListView.refresh()}_autoResize(t){t.style.height="auto",t.style.height=Math.min(t.scrollHeight,200)+"px"}_handleKeydown(t){"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this._sendMessage())}async _sendMessage(){const t=this.element.querySelector('[data-ref="input"]');if(!t)return;const s=t.value.trim();s&&(t.value="",t.style.height="auto",this._showChatArea(),await this.chatView.adapter.addNote({text:s,files:[]}))}_showChatArea(){if(this._hasMessages)return;this._hasMessages=!0;const t=this.element.querySelector('[data-ref="welcome"]'),s=this.element.querySelector('[data-container="chat-area"]');t&&t.classList.add("d-none"),s&&s.classList.remove("d-none")}_showWelcome(){this._hasMessages=!1;const t=this.element.querySelector('[data-ref="welcome"]'),s=this.element.querySelector('[data-container="chat-area"]');t&&t.classList.remove("d-none"),s&&s.classList.add("d-none")}_setInputEnabled(t,s){const e=this.element?.querySelector('[data-ref="input"]'),n=this.element?.querySelector('[data-ref="send-btn"]'),i=this.element?.querySelector('[data-ref="stop-btn"]');e&&(e.disabled=!t),n&&n.classList.toggle("d-none",!t),i&&i.classList.toggle("d-none",t),this._setInputStatus(t?null:s),this._responseTimeout&&clearTimeout(this._responseTimeout),t?this._requestStartTime=null:this._responseTimeout=setTimeout(()=>this._onResponseTimeout(),6e4)}_setInputStatus(t){const s=this.element?.querySelector('[data-ref="input-status"]');s&&(t?(s.innerHTML=`${this._escapeHtml(t)} <span class="assistant-input-status-dismiss">Click to dismiss</span>`,s.classList.remove("d-none"),s._hasDismiss||(s._hasDismiss=!0,s.addEventListener("click",()=>{this.chatView.hideThinking(),this._setInputEnabled(!0);const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}))):(s.classList.add("d-none"),s.innerHTML=""))}_onResponseTimeout(){this._responseTimeout=null,this.chatView.hideThinking(),this._setInputEnabled(!0),this._showSystemMessage("Request timed out. Please try again.")}_updateTitle(t){const s=this.element?.querySelector('[data-ref="panel-title"]');s&&(s.textContent=t||(this.conversationId?"Assistant":"New conversation"))}_createAdapter(){return{fetch:async()=>{if(!this.conversationId)return[];try{const t=new n({id:this.conversationId});await t.fetch({graph:"detail"});const s=t.get("title")||t.get("summary");s&&this._updateTitle(s);const e=(t.get("messages")||[]).map(t=>this._transformMessage(t)).filter(Boolean);return o._collapseMessages(e)}catch(t){return 404===t.status&&(this._onNewConversation(),this._showSystemMessage("Conversation not found.")),[]}},addNote:async t=>{if(!t.text||!t.text.trim())return{success:!1};const s={id:"local-"+ ++this._messageIdCounter,role:"user",author:{id:this.app?.activeUser?.id,name:this.app?.activeUser?.get("display_name")||"You"},content:t.text,timestamp:/* @__PURE__ */(new Date).toISOString()};if(this.chatView.addMessage(s),this.chatView.showThinking("Thinking..."),this._requestStartTime=Date.now(),this._setInputEnabled(!1,"Waiting for response…"),this.ws&&this.ws.isConnected)this.ws.send({type:"assistant_message",message:t.text,conversation_id:this.conversationId});else try{const s=await this.app.rest.post("/api/assistant",{message:t.text,conversation_id:this.conversationId}),e=s?.data?.data||s?.data||s;e.conversation_id&&(this.conversationId=e.conversation_id,this.app._assistantConversationId=this.conversationId),e.response&&this.chatView.addMessage(this._transformMessage(e.response)),this._setInputEnabled(!0)}catch(e){this._handleAPIError(e)}return{success:!0}}}}_subscribeWS(){this.ws&&(this._wsHandlers={thinking:t=>this._onThinking(t),text:t=>this._onText(t),tool_call:t=>this._onToolCall(t),response:t=>this._onResponse(t),error:t=>this._onError(t),plan:t=>this._onPlan(t),plan_update:t=>this._onPlanUpdate(t),message:t=>this._dispatchWSMessage(t),connected:()=>this._updateConnectionStatus(),disconnected:()=>this._updateConnectionStatus(),reconnecting:()=>this._updateConnectionStatus()},this.ws.on("message:assistant_thinking",this._wsHandlers.thinking),this.ws.on("message:assistant_text",this._wsHandlers.text),this.ws.on("message:assistant_tool_call",this._wsHandlers.tool_call),this.ws.on("message:assistant_response",this._wsHandlers.response),this.ws.on("message:assistant_error",this._wsHandlers.error),this.ws.on("message:assistant_plan",this._wsHandlers.plan),this.ws.on("message:assistant_plan_update",this._wsHandlers.plan_update),this.ws.on("message:message",this._wsHandlers.message),this.ws.on("connected",this._wsHandlers.connected),this.ws.on("disconnected",this._wsHandlers.disconnected),this.ws.on("reconnecting",this._wsHandlers.reconnecting))}_unsubscribeWS(){this.ws&&this._wsHandlers&&(this.ws.off("message:assistant_thinking",this._wsHandlers.thinking),this.ws.off("message:assistant_text",this._wsHandlers.text),this.ws.off("message:assistant_tool_call",this._wsHandlers.tool_call),this.ws.off("message:assistant_response",this._wsHandlers.response),this.ws.off("message:assistant_error",this._wsHandlers.error),this.ws.off("message:assistant_plan",this._wsHandlers.plan),this.ws.off("message:assistant_plan_update",this._wsHandlers.plan_update),this.ws.off("message:message",this._wsHandlers.message),this.ws.off("connected",this._wsHandlers.connected),this.ws.off("disconnected",this._wsHandlers.disconnected),this.ws.off("reconnecting",this._wsHandlers.reconnecting),this._wsHandlers={})}_dispatchWSMessage(t){const s=t?.data;if(s?.type)switch(s.type){case"assistant_thinking":this._onThinking(s);break;case"assistant_text":this._onText(s);break;case"assistant_tool_call":this._onToolCall(s);break;case"assistant_response":this._onResponse(s);break;case"assistant_error":this._onError(s);break;case"assistant_plan":this._onPlan(s);break;case"assistant_plan_update":this._onPlanUpdate(s)}}_isMyConversation(t){return!t.conversation_id||!this.conversationId||String(t.conversation_id)===String(this.conversationId)}_adoptConversationId(t){t.conversation_id&&!this.conversationId&&(this.conversationId=t.conversation_id,this.app._assistantConversationId=this.conversationId)}_onThinking(t){this._isMyConversation(t)&&(this._adoptConversationId(t),this._showChatArea(),this.chatView.showThinking("Thinking..."),this._setInputEnabled(!1,"Assistant is thinking…"))}_onText(t){if(!this._isMyConversation(t))return;this._adoptConversationId(t),this._resetResponseTimeout();const s=this._transformMessage({id:t.message_id||"text-"+ ++this._messageIdCounter,role:"assistant",content:t.text||"",blocks:t.blocks||[],tool_calls:[],created:t.created||t.timestamp||/* @__PURE__ */(new Date).toISOString()});s&&(s.content||s.blocks?.length)&&this.chatView.addMessage(s)}_onToolCall(t){this._isMyConversation(t)&&(this.chatView.showThinking(`Using ${t.tool||t.name||"tool"}...`),this._resetResponseTimeout())}_resetResponseTimeout(){if(this._responseTimeout){if(this._requestStartTime&&Date.now()-this._requestStartTime>=3e5)return void this._onResponseTimeout();clearTimeout(this._responseTimeout),this._responseTimeout=setTimeout(()=>this._onResponseTimeout(),6e4)}}_onResponse(t){if(!this._isMyConversation(t))return;this.chatView.hideThinking(),this._setInputEnabled(!0),this._adoptConversationId(t);const s=this.element?.querySelector('[data-ref="input"]');s&&s.focus();const e=this._transformMessage({id:t.message_id||"resp-"+ ++this._messageIdCounter,role:"assistant",content:t.response||t.content||t.message||"",blocks:t.blocks||[],tool_calls:t.tool_calls_made||t.tool_calls||[],created:t.created||t.timestamp||/* @__PURE__ */(new Date).toISOString()});e&&(e.content||e.blocks?.length||e.tool_calls?.length)&&this.chatView.addMessage(e)}_onError(t){if(!this._isMyConversation(t))return;this.chatView.hideThinking(),this._setInputEnabled(!0),this._adoptConversationId(t);const s=t.error||t.message||"An error occurred";this._showSystemMessage(s)}_onPlan(t){if(!this._isMyConversation(t))return;this._adoptConversationId(t),this._showChatArea();const s=t.plan;s&&(this._activePlans[s.plan_id]=s,this.chatView.addMessage({id:`plan-${s.plan_id}`,role:"assistant",author:{name:"Assistant"},content:"",timestamp:/* @__PURE__ */(new Date).toISOString(),blocks:[{type:"progress",...s}],tool_calls:[]}))}_onPlanUpdate(t){if(!this._isMyConversation(t))return;const s=this._activePlans[t.plan_id];if(s){const e=s.steps.find(s=>s.id===t.step_id);e&&(e.status=t.status,e.summary=t.summary)}const e=this.chatView.messageViews.get(`plan-${t.plan_id}`);e?.updateProgressStep&&e.updateProgressStep(t.plan_id,t.step_id,t.status,t.summary),this._resetResponseTimeout()}async _onConversationSelect(t){this.conversationId=t.id,this.app._assistantConversationId=this.conversationId,this.conversationListView.setActive(t.id),this._showChatArea(),this._updateTitle(t.model?.get("title")||t.model?.get("summary")),await this.chatView.refresh()}_onNewConversation(){this.conversationId=null,this.app._assistantConversationId=null,this.conversationListView.setActive(null),this.chatView.clearMessages(),this._setInputEnabled(!0),this._showWelcome(),this._updateTitle();const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}_onConversationDeleted(t){String(t.id)===String(this.conversationId)&&this._onNewConversation()}_transformMessage(t){if("tool_result"===t.role)return null;let s=t.content||t.text||"",e=t.blocks||[],n=t.tool_calls||[];if(n.length>0){n=n.map(t=>!t.type&&t.tool?{type:"tool_use",name:t.tool,input:t.input}:t);const t=n.filter(t=>"text"===t.type&&t.text).map(t=>t.text);!s&&t.length>0&&(s=t.join("\n\n")),n=n.filter(t=>"tool_use"===t.type).filter(t=>!o.INTERNAL_TOOLS.has(t.name))}if(0===e.length&&s.includes("assistant_block")){const t=o._parseBlocks(s);s=t.content,e=t.blocks}const i=this.app?.activeUser?.id;return{id:t.id,role:t.role||"user",author:"assistant"===t.role?{name:"Assistant"}:t.author||{name:t.user?.display_name||this.app?.activeUser?.get("display_name")||"You",id:t.user?.id||i},content:s,timestamp:t.created||t.timestamp,blocks:e,tool_calls:n,_conversationId:this.conversationId}}_showSystemMessage(t){this._showChatArea(),this.chatView.addMessage({id:"sys-"+ ++this._messageIdCounter,type:"system_event",content:t,timestamp:/* @__PURE__ */(new Date).toISOString()})}_handleAPIError(t){404===t.status?this._showSystemMessage("Assistant is not enabled on this server."):503===t.status?this._showSystemMessage("LLM API key not configured. Contact your administrator."):this._showSystemMessage("Failed to send message. Please try again."),this._setInputEnabled(!0)}_updateConnectionStatus(){const t=this.element?.querySelector(".status-dot");t&&(this.ws?.isConnected?(t.className="status-dot connected",t.title="Connected",this._responseTimeout?this._setInputEnabled(!1,"Waiting for response…"):this._setInputEnabled(!0)):this.ws?.isReconnecting?(t.className="status-dot reconnecting",t.title="Reconnecting...",this._setInputEnabled(!1,"Reconnecting…"),this._responseTimeout&&(clearTimeout(this._responseTimeout),this._responseTimeout=null)):(t.className="status-dot disconnected",t.title="Disconnected",this._setInputEnabled(!1,"Disconnected — reconnecting…"),this._responseTimeout&&(clearTimeout(this._responseTimeout),this._responseTimeout=null)))}_escapeHtml(t){const s=document.createElement("div");return s.textContent=t,s.innerHTML}focusInput(){const t=this.element?.querySelector('[data-ref="input"]');t&&t.focus()}async onBeforeDestroy(){this._unsubscribeWS(),this._responseTimeout&&(clearTimeout(this._responseTimeout),this._responseTimeout=null)}}export{AssistantPanelView as default};
|
|
2
|
+
//# sourceMappingURL=AssistantPanelView-CvjzGGS8.js.map
|