@kodaris/krubble-app-components 1.0.122 → 1.0.123

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.
@@ -3051,7 +3051,7 @@ function fe(e,t){return(t,i,s)=>((e,t,i)=>(i.configurable=!0,i.enumerable=!0,Ref
3051
3051
  height: 32px;
3052
3052
  }
3053
3053
 
3054
- `,Xt([ge({attribute:!1})],Jt.prototype,"send",void 0),Xt([ge({attribute:!1})],Jt.prototype,"load",void 0),Xt([ge({attribute:!1})],Jt.prototype,"messages",void 0),Xt([ge({type:String})],Jt.prototype,"label",void 0),Xt([ge({type:String})],Jt.prototype,"placeholder",void 0),Xt([ge({type:Boolean,reflect:!0})],Jt.prototype,"opened",void 0),Xt([ge({type:Boolean,attribute:"hide-toggle",reflect:!0})],Jt.prototype,"hideToggle",void 0),Xt([ge({type:String,reflect:!0})],Jt.prototype,"variant",void 0),Xt([ge({type:Number,attribute:"conversation-id",reflect:!0})],Jt.prototype,"conversationId",void 0),Xt([me()],Jt.prototype,"_inputValue",void 0),Xt([me()],Jt.prototype,"_isStreaming",void 0),Xt([me()],Jt.prototype,"_error",void 0),Xt([me()],Jt.prototype,"_contextWarning",void 0),Xt([me()],Jt.prototype,"_contextLimitReached",void 0),Xt([me()],Jt.prototype,"_contextLimitMessage",void 0),Xt([me()],Jt.prototype,"_pendingActions",void 0),Xt([me()],Jt.prototype,"_confirmationHighlighted",void 0),Xt([me()],Jt.prototype,"_confirmationInFlight",void 0),Xt([me()],Jt.prototype,"_telemetry",void 0),Xt([me()],Jt.prototype,"_iterationLog",void 0),Xt([me()],Jt.prototype,"_cacheCheckpoints",void 0),Xt([me()],Jt.prototype,"_drawerOpen",void 0),Xt([me()],Jt.prototype,"_drawerView",void 0),Xt([me()],Jt.prototype,"_toolDetail",void 0),Xt([me()],Jt.prototype,"_toolDetailCopied",void 0),Xt([me()],Jt.prototype,"_toolDetailInputOpen",void 0),Xt([me()],Jt.prototype,"_toolDetailOutputOpen",void 0),Xt([me()],Jt.prototype,"_drawerWidth",void 0),Xt([me()],Jt.prototype,"_isDrawerResizing",void 0),Xt([me()],Jt.prototype,"_pendingConversationFiles",void 0),Xt([me()],Jt.prototype,"_isDraggingFile",void 0),Xt([me()],Jt.prototype,"_skillMenuOpened",void 0),Xt([me()],Jt.prototype,"_skillQuery",void 0),Xt([me()],Jt.prototype,"_orgSkills",void 0),Xt([me()],Jt.prototype,"_globalSkills",void 0),Xt([me()],Jt.prototype,"_invocableSkills",void 0),Xt([me()],Jt.prototype,"_aiFrameworkConfig",void 0),Xt([me()],Jt.prototype,"_skillHighlighted",void 0),Xt([me()],Jt.prototype,"_copiedIndex",void 0),Xt([me()],Jt.prototype,"_skillBrowseOpened",void 0),Xt([me()],Jt.prototype,"_skillBrowseSource",void 0),Xt([me()],Jt.prototype,"_skillBrowseQuery",void 0),Xt([me()],Jt.prototype,"_isDictating",void 0),Xt([me()],Jt.prototype,"_mode",void 0),Xt([me()],Jt.prototype,"_modeMenuOpened",void 0),Xt([me()],Jt.prototype,"_showTools",void 0),Xt([me()],Jt.prototype,"_showToolInputs",void 0),Xt([me()],Jt.prototype,"_showConfirmationInput",void 0),Xt([fe(".panel")],Jt.prototype,"_panelEl",void 0),Xt([fe(".messages")],Jt.prototype,"_messagesEl",void 0),Xt([fe(".input")],Jt.prototype,"_inputEl",void 0),Xt([fe(".file-input")],Jt.prototype,"_fileInputEl",void 0),Xt([fe(".input-wrapper")],Jt.prototype,"_inputWrapperEl",void 0),Xt([fe(".skill-menu")],Jt.prototype,"_skillMenuEl",void 0),Xt([fe(".drawer__body")],Jt.prototype,"_drawerBodyEl",void 0),customElements.get("kr-chatbot")||customElements.define("kr-chatbot",Jt);var Gt=function(e,t,i,s){var n,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(o<3?n(r):o>3?n(t,i,r):n(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};class ei extends de{constructor(){super(),this.defaultNavItemIcon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="10"/></svg>',this.originalFetch=null,this.originalXhrOpen=null,this.navItemDragPreview=null,this.navItemDragStartY=0,this.isNavItemDragging=!1,this.navItemDragExpandTimeout=null,this.navInitialized=!1,this.logo="",this.label="",this.homeUrl="/",this.scheme="light",this.nav=[],this.navIconsDisplayed=!1,this.navExpanded=!1,this.user=null,this.subbar=!1,this.navEnabled=!0,this.userType="employee",this.breadcrumbs=[],this.isDev="localhost"===window.location.hostname,this.navItemsExpanded=new Set,this.navQuery="",this.activeNavItemId=null,this.isNavScrolled=!1,this.isNavOpened="false"!==localStorage.getItem("kr-scaffold-nav-opened"),this.isEditing=!1,this.isUserMenuOpen=!1,this.pref={nav:{}},this.draggedNavItemId=null,this.navItemDropTargetId=null,this.navItemDropPosition="above",this.pendingRequests=0,this.boundHandleMouseMove=this.handleMouseMove.bind(this),this.boundHandleMouseUp=this.handleMouseUp.bind(this)}connectedCallback(){super.connectedCallback(),this.installFetchInterceptor()}firstUpdated(){this.loadPref()}updated(e){super.updated(e),e.has("nav")&&this.nav.length>0&&(this.updateActiveNavItem(),this.navExpanded&&!this.navInitialized&&(this.navInitialized=!0,this.getComputedNav().filter((e=>"group"===e.type)).forEach((e=>this.navItemsExpanded.add(e.id)))))}disconnectedCallback(){super.disconnectedCallback(),this.uninstallFetchInterceptor()}installFetchInterceptor(){if(this.originalFetch)return;const e=this;this.originalFetch=window.fetch.bind(window);const t=this.originalFetch;window.fetch=function(...i){return e.pendingRequests++,t(...i).finally((()=>{e.pendingRequests--}))},this.originalXhrOpen=XMLHttpRequest.prototype.open;const i=this.originalXhrOpen;XMLHttpRequest.prototype.open=function(t,s,n=!0,o,r){return e.pendingRequests++,this.addEventListener("loadend",(()=>{e.pendingRequests--}),{once:!0}),i.call(this,t,s,n,o,r)}}uninstallFetchInterceptor(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null),this.originalXhrOpen&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,this.originalXhrOpen=null)}resolveUrl(e){if(!e.url)return"#";if(e.external)return e.url;let t=e.url;e.url.startsWith("/")&&(t=e.url.slice(1));const i=document.querySelector("base")?.getAttribute("href")||"/";return i.endsWith("/")?i+t:i+"/"+t}getComputedNav(){const e=[];return this.nav.forEach(((t,i)=>{const s=this.pref.nav[t.id];e.push({...t,...s,order:s?.order??t.order??i,parentId:s?.parentId??null}),"group"===t.type&&t.children&&t.children.forEach(((i,s)=>{const n=this.pref.nav[i.id];let o=t.id;void 0!==n?.parentId&&(o=n.parentId),e.push({...i,...n,order:n?.order??i.order??s,parentId:o})}))})),Object.entries(this.pref.nav).forEach((([t,i])=>{t.startsWith("custom")&&i.type&&i.label&&e.push({id:t,type:i.type,label:i.label,icon:i.icon,url:i.url,active:i.active,order:i.order??e.length,parentId:i.parentId??null})})),e}getNavItemChildren(e){let t=this.getComputedNav().filter((t=>t.parentId===e)).sort(((e,t)=>e.order-t.order));if(this.isEditing||(t=t.filter((e=>!1!==e.active))),this.navQuery){const i=this.navQuery.toLowerCase(),s=this.getComputedNav();if(null!==e){const n=s.find((t=>t.id===e));if(n?.label.toLowerCase().includes(i))return t}t=t.filter((e=>"group"===e.type?e.label.toLowerCase().includes(i)||s.some((t=>t.parentId===e.id&&!1!==t.active&&t.label.toLowerCase().includes(i))):e.label.toLowerCase().includes(i)))}return t}handleNavQueryChange(e){this.navQuery=e.target.value,this.navQuery?this.getComputedNav().forEach((e=>{"group"===e.type&&this.navItemsExpanded.add(e.id)})):this.navItemsExpanded.clear()}handleNavQueryClear(){this.navQuery="",this.navItemsExpanded.clear()}handleMenuClick(){this.isNavOpened=!this.isNavOpened,localStorage.setItem("kr-scaffold-nav-opened",String(this.isNavOpened))}handleDevChatClick(){this.renderRoot.querySelector("kr-chatbot")?.toggle()}handleNavHeaderClick(){this.activeNavItemId=null;const e=new CustomEvent("nav-item-click",{detail:{item:{url:this.homeUrl}},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(e),e.defaultPrevented||(window.location.href=this.homeUrl)}handleNavScroll(e){this.isNavScrolled=e.target.scrollTop>0}expandNavGroup(e){this.navItemsExpanded.has(e)||(this.navItemsExpanded.add(e),this.requestUpdate())}handleNavItemClick(e,t){if("group"===t.type){const e=this.shadowRoot?.querySelector(`.nav-item[data-id="${t.id}"]`),i=e?.nextElementSibling;if(!i)return;this.navItemsExpanded.has(t.id)?(this.navItemsExpanded.delete(t.id),i.animate([{height:`${i.scrollHeight}px`},{height:"0px"}],{duration:300,easing:"ease-in-out"}).onfinish=()=>{i.classList.remove("nav-group--expanded")}):(this.navItemsExpanded.add(t.id),i.classList.add("nav-group--expanded"),i.animate([{height:"0px"},{height:`${i.scrollHeight}px`}],{duration:300,easing:"ease-in-out"})),this.requestUpdate()}else{if(e.ctrlKey||e.metaKey||1===e.button)return;this.activeNavItemId=t.id;const i=new CustomEvent("nav-item-click",{detail:{item:t},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i),i.defaultPrevented&&e.preventDefault()}}updateActiveNavItem(){const e=window.location.pathname,t=this.getComputedNav().filter((e=>"item"===e.type&&e.url));let i=null,s=0;for(const n of t){const t=this.resolveUrl(n);e.startsWith(t)&&t.length>s&&(i=n,s=t.length)}i?(this.activeNavItemId=i.id,i.parentId&&this.navItemsExpanded.add(i.parentId)):this.activeNavItemId=null}handleEditCancel(){this.isEditing=!1,this.loadPref()}handlePrefReset(){this.pref.nav={}}handlePrefSave(){if("customer"===this.userType)return;let e="/api/system/preference/json/scaffold?global=true",t="POST";this.pref.uuid&&(e=`/api/system/preference/json/scaffold/${this.pref.uuid}?global=true`,t="PUT"),n.fetch({url:e,method:t,body:JSON.stringify({nav:this.pref.nav})}).then((e=>e.json())).then((e=>{this.pref=e.data,this.isEditing=!1})).catch((e=>{console.error("Failed to save nav customizations:",e)}))}loadPref(){"customer"!==this.userType&&n.fetch({url:"/api/system/preference/json/scaffold?global=true",method:"GET"}).then((e=>e.json())).then((e=>{const t=e?.data?.[0];t&&(this.pref=t)})).catch((()=>{}))}handleNavItemContextMenu(e,t){this.isEditing&&(e.preventDefault(),i.open({x:e.clientX,y:e.clientY,items:[{id:"edit",label:"Edit Item"},{id:"divider-1",label:"",divider:!0},{id:"add-above",label:"Add Item Above"},{id:"add-below",label:"Add Item Below"}]}).then((e=>{if(e)switch(e.id){case"edit":this.openNavItemEdit(t);break;case"add-above":this.addNavItem(t,"above");break;case"add-below":this.addNavItem(t,"below")}})))}openNavItemEdit(e){s.open(Se,{data:e}).afterClosed().then((t=>{const i=t;i&&(this.pref.nav[e.id]||(this.pref.nav[e.id]={}),this.pref.nav[e.id]={...this.pref.nav[e.id],...i},this.requestUpdate())}))}addNavItem(e,t){const i=`custom-${Date.now()}`,s=this.getComputedNav().filter((t=>t.parentId===e.parentId)).sort(((e,t)=>e.order-t.order)),n=s.findIndex((t=>t.id===e.id));let o;o="above"===t?n:n+1,s.forEach(((e,t)=>{t>=o&&(this.pref.nav[e.id]||(this.pref.nav[e.id]={}),this.pref.nav[e.id].order=t+1)}));const r={id:i,type:"item",label:"New Item",order:o,parentId:e.parentId,active:!0};this.pref.nav[i]=r,this.requestUpdate(),this.openNavItemEdit(r)}handleNavItemMouseDown(e,t){this.isEditing&&(e.preventDefault(),this.draggedNavItemId=t.id,this.navItemDragStartY=e.clientY,this.isNavItemDragging=!1,document.addEventListener("mousemove",this.boundHandleMouseMove),document.addEventListener("mouseup",this.boundHandleMouseUp))}handleMouseMove(e){if(this.draggedNavItemId){if(!this.isNavItemDragging&&Math.abs(e.clientY-this.navItemDragStartY)>5){this.isNavItemDragging=!0,this.classList.add("kr-scaffold--dragging");const t=this.getComputedNav().find((e=>e.id===this.draggedNavItemId));t&&(this.navItemDragPreview=document.createElement("div"),this.navItemDragPreview.className="nav-item-drag-preview",this.navItemDragPreview.textContent=t.label,this.navItemDragPreview.style.left=`${e.clientX+10}px`,this.navItemDragPreview.style.top=e.clientY-20+"px",this.shadowRoot?.appendChild(this.navItemDragPreview))}this.isNavItemDragging&&(this.navItemDragPreview&&(this.navItemDragPreview.style.left=`${e.clientX+10}px`,this.navItemDragPreview.style.top=e.clientY-20+"px"),this.updateNavItemDropTarget(e))}}handleMouseUp(){document.removeEventListener("mousemove",this.boundHandleMouseMove),document.removeEventListener("mouseup",this.boundHandleMouseUp),this.isNavItemDragging&&this.navItemDropTargetId&&this.executeNavItemDrop(),this.draggedNavItemId=null,this.navItemDropTargetId=null,this.isNavItemDragging=!1,this.classList.remove("kr-scaffold--dragging"),this.navItemDragPreview&&(this.navItemDragPreview.remove(),this.navItemDragPreview=null),this.clearNavItemDragExpandTimeout(),this.requestUpdate()}updateNavItemDropTarget(e){const t=this.shadowRoot?.querySelectorAll(".nav-item[data-id]");if(!t)return;let i=!1;t.forEach((t=>{const s=t.getBoundingClientRect(),n=t.getAttribute("data-id");if(!n||n===this.draggedNavItemId)return;if(e.clientX<s.left||e.clientX>s.right||e.clientY<s.top||e.clientY>s.bottom)return;const o=this.getComputedNav().find((e=>e.id===n));if(!o)return;const r=e.clientY-s.top;let a,l;"group"===o.type?r<s.height/3?(a="above",this.clearNavItemDragExpandTimeout()):r>2*s.height/3?(a="below",this.clearNavItemDragExpandTimeout()):(a="center",this.navItemsExpanded.has(o.id)||this.navItemDragExpandTimeout||(this.navItemDragExpandTimeout=window.setTimeout((()=>{this.navItemDropTargetId===o.id&&"center"===this.navItemDropPosition&&(this.navItemsExpanded.add(o.id),this.requestUpdate()),this.navItemDragExpandTimeout=null}),500))):(a=r<s.height/2?"above":"below",this.clearNavItemDragExpandTimeout()),l="center"===a?o.id:o.parentId;const h=this.getComputedNav().find((e=>e.id===this.draggedNavItemId));if(l===this.draggedNavItemId||"group"===h?.type&&null!==l)return this.navItemDropTargetId=null,void this.clearNavItemDragExpandTimeout();this.navItemDropTargetId=o.id,this.navItemDropPosition=a,i=!0})),i||(this.navItemDropTargetId=null,this.clearNavItemDragExpandTimeout()),this.requestUpdate()}clearNavItemDragExpandTimeout(){this.navItemDragExpandTimeout&&(clearTimeout(this.navItemDragExpandTimeout),this.navItemDragExpandTimeout=null)}executeNavItemDrop(){if(!this.draggedNavItemId||!this.navItemDropTargetId)return;const e=this.getComputedNav(),t=e.find((e=>e.id===this.draggedNavItemId)),i=e.find((e=>e.id===this.navItemDropTargetId));if(!t||!i)return;let s;if("center"===this.navItemDropPosition&&"group"===i.type){if(i.id===this.draggedNavItemId)return;s=i.id}else s=i.parentId;if(s===this.draggedNavItemId)return;const n=e.filter((e=>e.parentId===s&&e.id!==this.draggedNavItemId)).sort(((e,t)=>e.order-t.order)),o=this.pref.nav;let r;if("center"===this.navItemDropPosition)r=n.length>0?Math.max(...n.map((e=>e.order)))+1:0;else{const e=n.findIndex((e=>e.id===i.id));r=-1===e?0:"above"===this.navItemDropPosition?e:e+1,n.forEach(((e,t)=>{o[e.id]||(o[e.id]={}),o[e.id].order=t>=r?t+1:t}))}o[this.draggedNavItemId]||(o[this.draggedNavItemId]={}),o[this.draggedNavItemId].order=r,o[this.draggedNavItemId].parentId=s,this.pref.nav=o,this.requestUpdate()}handleUserMenuToggle(){this.isUserMenuOpen=!this.isUserMenuOpen}handleCustomize(){this.isUserMenuOpen=!1,this.isEditing=!0}renderNormalFooter(){if(!this.user)return Q;const e=this.user.name.split(" ").map((e=>e[0])).join("").toUpperCase().slice(0,2);return V`
3054
+ `,Xt([ge({attribute:!1})],Jt.prototype,"send",void 0),Xt([ge({attribute:!1})],Jt.prototype,"load",void 0),Xt([ge({attribute:!1})],Jt.prototype,"messages",void 0),Xt([ge({type:String})],Jt.prototype,"label",void 0),Xt([ge({type:String})],Jt.prototype,"placeholder",void 0),Xt([ge({type:Boolean,reflect:!0})],Jt.prototype,"opened",void 0),Xt([ge({type:Boolean,attribute:"hide-toggle",reflect:!0})],Jt.prototype,"hideToggle",void 0),Xt([ge({type:String,reflect:!0})],Jt.prototype,"variant",void 0),Xt([ge({type:Number,attribute:"conversation-id",reflect:!0})],Jt.prototype,"conversationId",void 0),Xt([me()],Jt.prototype,"_inputValue",void 0),Xt([me()],Jt.prototype,"_isStreaming",void 0),Xt([me()],Jt.prototype,"_error",void 0),Xt([me()],Jt.prototype,"_contextWarning",void 0),Xt([me()],Jt.prototype,"_contextLimitReached",void 0),Xt([me()],Jt.prototype,"_contextLimitMessage",void 0),Xt([me()],Jt.prototype,"_pendingActions",void 0),Xt([me()],Jt.prototype,"_confirmationHighlighted",void 0),Xt([me()],Jt.prototype,"_confirmationInFlight",void 0),Xt([me()],Jt.prototype,"_telemetry",void 0),Xt([me()],Jt.prototype,"_iterationLog",void 0),Xt([me()],Jt.prototype,"_cacheCheckpoints",void 0),Xt([me()],Jt.prototype,"_drawerOpen",void 0),Xt([me()],Jt.prototype,"_drawerView",void 0),Xt([me()],Jt.prototype,"_toolDetail",void 0),Xt([me()],Jt.prototype,"_toolDetailCopied",void 0),Xt([me()],Jt.prototype,"_toolDetailInputOpen",void 0),Xt([me()],Jt.prototype,"_toolDetailOutputOpen",void 0),Xt([me()],Jt.prototype,"_drawerWidth",void 0),Xt([me()],Jt.prototype,"_isDrawerResizing",void 0),Xt([me()],Jt.prototype,"_pendingConversationFiles",void 0),Xt([me()],Jt.prototype,"_isDraggingFile",void 0),Xt([me()],Jt.prototype,"_skillMenuOpened",void 0),Xt([me()],Jt.prototype,"_skillQuery",void 0),Xt([me()],Jt.prototype,"_orgSkills",void 0),Xt([me()],Jt.prototype,"_globalSkills",void 0),Xt([me()],Jt.prototype,"_invocableSkills",void 0),Xt([me()],Jt.prototype,"_aiFrameworkConfig",void 0),Xt([me()],Jt.prototype,"_skillHighlighted",void 0),Xt([me()],Jt.prototype,"_copiedIndex",void 0),Xt([me()],Jt.prototype,"_skillBrowseOpened",void 0),Xt([me()],Jt.prototype,"_skillBrowseSource",void 0),Xt([me()],Jt.prototype,"_skillBrowseQuery",void 0),Xt([me()],Jt.prototype,"_isDictating",void 0),Xt([me()],Jt.prototype,"_mode",void 0),Xt([me()],Jt.prototype,"_modeMenuOpened",void 0),Xt([me()],Jt.prototype,"_showTools",void 0),Xt([me()],Jt.prototype,"_showToolInputs",void 0),Xt([me()],Jt.prototype,"_showConfirmationInput",void 0),Xt([fe(".panel")],Jt.prototype,"_panelEl",void 0),Xt([fe(".messages")],Jt.prototype,"_messagesEl",void 0),Xt([fe(".input")],Jt.prototype,"_inputEl",void 0),Xt([fe(".file-input")],Jt.prototype,"_fileInputEl",void 0),Xt([fe(".input-wrapper")],Jt.prototype,"_inputWrapperEl",void 0),Xt([fe(".skill-menu")],Jt.prototype,"_skillMenuEl",void 0),Xt([fe(".drawer__body")],Jt.prototype,"_drawerBodyEl",void 0),customElements.get("kr-chatbot")||customElements.define("kr-chatbot",Jt);var Gt=function(e,t,i,s){var n,o=arguments.length,r=o<3?t:null===s?s=Object.getOwnPropertyDescriptor(t,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)r=Reflect.decorate(e,t,i,s);else for(var a=e.length-1;a>=0;a--)(n=e[a])&&(r=(o<3?n(r):o>3?n(t,i,r):n(t,i))||r);return o>3&&r&&Object.defineProperty(t,i,r),r};class ei extends de{constructor(){super(),this.defaultNavItemIcon='<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" fill="currentColor"><circle cx="12" cy="12" r="10"/></svg>',this.originalFetch=null,this.originalXhrOpen=null,this.navItemDragPreview=null,this.navItemDragStartY=0,this.isNavItemDragging=!1,this.navItemDragExpandTimeout=null,this.navInitialized=!1,this.logo="",this.label="",this.homeUrl="/",this.scheme="light",this.nav=[],this.navIconsDisplayed=!1,this.navExpanded=!1,this.user=null,this.subbar=!1,this.navEnabled=!0,this.userType="employee",this.breadcrumbs=[],this.isDev="localhost"===window.location.hostname&&"8080"!==window.location.port,this.navItemsExpanded=new Set,this.navQuery="",this.activeNavItemId=null,this.isNavScrolled=!1,this.isNavOpened="false"!==localStorage.getItem("kr-scaffold-nav-opened"),this.isEditing=!1,this.isUserMenuOpen=!1,this.pref={nav:{}},this.draggedNavItemId=null,this.navItemDropTargetId=null,this.navItemDropPosition="above",this.pendingRequests=0,this.boundHandleMouseMove=this.handleMouseMove.bind(this),this.boundHandleMouseUp=this.handleMouseUp.bind(this)}connectedCallback(){super.connectedCallback(),this.installFetchInterceptor()}firstUpdated(){this.loadPref()}updated(e){super.updated(e),e.has("nav")&&this.nav.length>0&&(this.updateActiveNavItem(),this.navExpanded&&!this.navInitialized&&(this.navInitialized=!0,this.getComputedNav().filter((e=>"group"===e.type)).forEach((e=>this.navItemsExpanded.add(e.id)))))}disconnectedCallback(){super.disconnectedCallback(),this.uninstallFetchInterceptor()}installFetchInterceptor(){if(this.originalFetch)return;const e=this;this.originalFetch=window.fetch.bind(window);const t=this.originalFetch;window.fetch=function(...i){return e.pendingRequests++,t(...i).finally((()=>{e.pendingRequests--}))},this.originalXhrOpen=XMLHttpRequest.prototype.open;const i=this.originalXhrOpen;XMLHttpRequest.prototype.open=function(t,s,n=!0,o,r){return e.pendingRequests++,this.addEventListener("loadend",(()=>{e.pendingRequests--}),{once:!0}),i.call(this,t,s,n,o,r)}}uninstallFetchInterceptor(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null),this.originalXhrOpen&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,this.originalXhrOpen=null)}resolveUrl(e){if(!e.url)return"#";if(e.external)return e.url;let t=e.url;e.url.startsWith("/")&&(t=e.url.slice(1));const i=document.querySelector("base")?.getAttribute("href")||"/";return i.endsWith("/")?i+t:i+"/"+t}getComputedNav(){const e=[];return this.nav.forEach(((t,i)=>{const s=this.pref.nav[t.id];e.push({...t,...s,order:s?.order??t.order??i,parentId:s?.parentId??null}),"group"===t.type&&t.children&&t.children.forEach(((i,s)=>{const n=this.pref.nav[i.id];let o=t.id;void 0!==n?.parentId&&(o=n.parentId),e.push({...i,...n,order:n?.order??i.order??s,parentId:o})}))})),Object.entries(this.pref.nav).forEach((([t,i])=>{t.startsWith("custom")&&i.type&&i.label&&e.push({id:t,type:i.type,label:i.label,icon:i.icon,url:i.url,active:i.active,order:i.order??e.length,parentId:i.parentId??null})})),e}getNavItemChildren(e){let t=this.getComputedNav().filter((t=>t.parentId===e)).sort(((e,t)=>e.order-t.order));if(this.isEditing||(t=t.filter((e=>!1!==e.active))),this.navQuery){const i=this.navQuery.toLowerCase(),s=this.getComputedNav();if(null!==e){const n=s.find((t=>t.id===e));if(n?.label.toLowerCase().includes(i))return t}t=t.filter((e=>"group"===e.type?e.label.toLowerCase().includes(i)||s.some((t=>t.parentId===e.id&&!1!==t.active&&t.label.toLowerCase().includes(i))):e.label.toLowerCase().includes(i)))}return t}handleNavQueryChange(e){this.navQuery=e.target.value,this.navQuery?this.getComputedNav().forEach((e=>{"group"===e.type&&this.navItemsExpanded.add(e.id)})):this.navItemsExpanded.clear()}handleNavQueryClear(){this.navQuery="",this.navItemsExpanded.clear()}handleMenuClick(){this.isNavOpened=!this.isNavOpened,localStorage.setItem("kr-scaffold-nav-opened",String(this.isNavOpened))}handleDevChatClick(){this.renderRoot.querySelector("kr-chatbot")?.toggle()}handleNavHeaderClick(){this.activeNavItemId=null;const e=new CustomEvent("nav-item-click",{detail:{item:{url:this.homeUrl}},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(e),e.defaultPrevented||(window.location.href=this.homeUrl)}handleNavScroll(e){this.isNavScrolled=e.target.scrollTop>0}expandNavGroup(e){this.navItemsExpanded.has(e)||(this.navItemsExpanded.add(e),this.requestUpdate())}handleNavItemClick(e,t){if("group"===t.type){const e=this.shadowRoot?.querySelector(`.nav-item[data-id="${t.id}"]`),i=e?.nextElementSibling;if(!i)return;this.navItemsExpanded.has(t.id)?(this.navItemsExpanded.delete(t.id),i.animate([{height:`${i.scrollHeight}px`},{height:"0px"}],{duration:300,easing:"ease-in-out"}).onfinish=()=>{i.classList.remove("nav-group--expanded")}):(this.navItemsExpanded.add(t.id),i.classList.add("nav-group--expanded"),i.animate([{height:"0px"},{height:`${i.scrollHeight}px`}],{duration:300,easing:"ease-in-out"})),this.requestUpdate()}else{if(e.ctrlKey||e.metaKey||1===e.button)return;this.activeNavItemId=t.id;const i=new CustomEvent("nav-item-click",{detail:{item:t},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i),i.defaultPrevented&&e.preventDefault()}}updateActiveNavItem(){const e=window.location.pathname,t=this.getComputedNav().filter((e=>"item"===e.type&&e.url));let i=null,s=0;for(const n of t){const t=this.resolveUrl(n);e.startsWith(t)&&t.length>s&&(i=n,s=t.length)}i?(this.activeNavItemId=i.id,i.parentId&&this.navItemsExpanded.add(i.parentId)):this.activeNavItemId=null}handleEditCancel(){this.isEditing=!1,this.loadPref()}handlePrefReset(){this.pref.nav={}}handlePrefSave(){if("customer"===this.userType)return;let e="/api/system/preference/json/scaffold?global=true",t="POST";this.pref.uuid&&(e=`/api/system/preference/json/scaffold/${this.pref.uuid}?global=true`,t="PUT"),n.fetch({url:e,method:t,body:JSON.stringify({nav:this.pref.nav})}).then((e=>e.json())).then((e=>{this.pref=e.data,this.isEditing=!1})).catch((e=>{console.error("Failed to save nav customizations:",e)}))}loadPref(){"customer"!==this.userType&&n.fetch({url:"/api/system/preference/json/scaffold?global=true",method:"GET"}).then((e=>e.json())).then((e=>{const t=e?.data?.[0];t&&(this.pref=t)})).catch((()=>{}))}handleNavItemContextMenu(e,t){this.isEditing&&(e.preventDefault(),i.open({x:e.clientX,y:e.clientY,items:[{id:"edit",label:"Edit Item"},{id:"divider-1",label:"",divider:!0},{id:"add-above",label:"Add Item Above"},{id:"add-below",label:"Add Item Below"}]}).then((e=>{if(e)switch(e.id){case"edit":this.openNavItemEdit(t);break;case"add-above":this.addNavItem(t,"above");break;case"add-below":this.addNavItem(t,"below")}})))}openNavItemEdit(e){s.open(Se,{data:e}).afterClosed().then((t=>{const i=t;i&&(this.pref.nav[e.id]||(this.pref.nav[e.id]={}),this.pref.nav[e.id]={...this.pref.nav[e.id],...i},this.requestUpdate())}))}addNavItem(e,t){const i=`custom-${Date.now()}`,s=this.getComputedNav().filter((t=>t.parentId===e.parentId)).sort(((e,t)=>e.order-t.order)),n=s.findIndex((t=>t.id===e.id));let o;o="above"===t?n:n+1,s.forEach(((e,t)=>{t>=o&&(this.pref.nav[e.id]||(this.pref.nav[e.id]={}),this.pref.nav[e.id].order=t+1)}));const r={id:i,type:"item",label:"New Item",order:o,parentId:e.parentId,active:!0};this.pref.nav[i]=r,this.requestUpdate(),this.openNavItemEdit(r)}handleNavItemMouseDown(e,t){this.isEditing&&(e.preventDefault(),this.draggedNavItemId=t.id,this.navItemDragStartY=e.clientY,this.isNavItemDragging=!1,document.addEventListener("mousemove",this.boundHandleMouseMove),document.addEventListener("mouseup",this.boundHandleMouseUp))}handleMouseMove(e){if(this.draggedNavItemId){if(!this.isNavItemDragging&&Math.abs(e.clientY-this.navItemDragStartY)>5){this.isNavItemDragging=!0,this.classList.add("kr-scaffold--dragging");const t=this.getComputedNav().find((e=>e.id===this.draggedNavItemId));t&&(this.navItemDragPreview=document.createElement("div"),this.navItemDragPreview.className="nav-item-drag-preview",this.navItemDragPreview.textContent=t.label,this.navItemDragPreview.style.left=`${e.clientX+10}px`,this.navItemDragPreview.style.top=e.clientY-20+"px",this.shadowRoot?.appendChild(this.navItemDragPreview))}this.isNavItemDragging&&(this.navItemDragPreview&&(this.navItemDragPreview.style.left=`${e.clientX+10}px`,this.navItemDragPreview.style.top=e.clientY-20+"px"),this.updateNavItemDropTarget(e))}}handleMouseUp(){document.removeEventListener("mousemove",this.boundHandleMouseMove),document.removeEventListener("mouseup",this.boundHandleMouseUp),this.isNavItemDragging&&this.navItemDropTargetId&&this.executeNavItemDrop(),this.draggedNavItemId=null,this.navItemDropTargetId=null,this.isNavItemDragging=!1,this.classList.remove("kr-scaffold--dragging"),this.navItemDragPreview&&(this.navItemDragPreview.remove(),this.navItemDragPreview=null),this.clearNavItemDragExpandTimeout(),this.requestUpdate()}updateNavItemDropTarget(e){const t=this.shadowRoot?.querySelectorAll(".nav-item[data-id]");if(!t)return;let i=!1;t.forEach((t=>{const s=t.getBoundingClientRect(),n=t.getAttribute("data-id");if(!n||n===this.draggedNavItemId)return;if(e.clientX<s.left||e.clientX>s.right||e.clientY<s.top||e.clientY>s.bottom)return;const o=this.getComputedNav().find((e=>e.id===n));if(!o)return;const r=e.clientY-s.top;let a,l;"group"===o.type?r<s.height/3?(a="above",this.clearNavItemDragExpandTimeout()):r>2*s.height/3?(a="below",this.clearNavItemDragExpandTimeout()):(a="center",this.navItemsExpanded.has(o.id)||this.navItemDragExpandTimeout||(this.navItemDragExpandTimeout=window.setTimeout((()=>{this.navItemDropTargetId===o.id&&"center"===this.navItemDropPosition&&(this.navItemsExpanded.add(o.id),this.requestUpdate()),this.navItemDragExpandTimeout=null}),500))):(a=r<s.height/2?"above":"below",this.clearNavItemDragExpandTimeout()),l="center"===a?o.id:o.parentId;const h=this.getComputedNav().find((e=>e.id===this.draggedNavItemId));if(l===this.draggedNavItemId||"group"===h?.type&&null!==l)return this.navItemDropTargetId=null,void this.clearNavItemDragExpandTimeout();this.navItemDropTargetId=o.id,this.navItemDropPosition=a,i=!0})),i||(this.navItemDropTargetId=null,this.clearNavItemDragExpandTimeout()),this.requestUpdate()}clearNavItemDragExpandTimeout(){this.navItemDragExpandTimeout&&(clearTimeout(this.navItemDragExpandTimeout),this.navItemDragExpandTimeout=null)}executeNavItemDrop(){if(!this.draggedNavItemId||!this.navItemDropTargetId)return;const e=this.getComputedNav(),t=e.find((e=>e.id===this.draggedNavItemId)),i=e.find((e=>e.id===this.navItemDropTargetId));if(!t||!i)return;let s;if("center"===this.navItemDropPosition&&"group"===i.type){if(i.id===this.draggedNavItemId)return;s=i.id}else s=i.parentId;if(s===this.draggedNavItemId)return;const n=e.filter((e=>e.parentId===s&&e.id!==this.draggedNavItemId)).sort(((e,t)=>e.order-t.order)),o=this.pref.nav;let r;if("center"===this.navItemDropPosition)r=n.length>0?Math.max(...n.map((e=>e.order)))+1:0;else{const e=n.findIndex((e=>e.id===i.id));r=-1===e?0:"above"===this.navItemDropPosition?e:e+1,n.forEach(((e,t)=>{o[e.id]||(o[e.id]={}),o[e.id].order=t>=r?t+1:t}))}o[this.draggedNavItemId]||(o[this.draggedNavItemId]={}),o[this.draggedNavItemId].order=r,o[this.draggedNavItemId].parentId=s,this.pref.nav=o,this.requestUpdate()}handleUserMenuToggle(){this.isUserMenuOpen=!this.isUserMenuOpen}handleCustomize(){this.isUserMenuOpen=!1,this.isEditing=!0}renderNormalFooter(){if(!this.user)return Q;const e=this.user.name.split(" ").map((e=>e[0])).join("").toUpperCase().slice(0,2);return V`
3055
3055
  <div class="user-menu-container">
3056
3056
  ${this.isUserMenuOpen?V`
3057
3057
  <div class="user-menu">