@kodaris/krubble-app-components 1.0.66 → 1.0.67
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/krubble-app.bundled.js +17 -1
- package/dist/krubble-app.bundled.js.map +1 -1
- package/dist/krubble-app.bundled.min.js +6 -6
- package/dist/krubble-app.bundled.min.js.map +1 -1
- package/dist/krubble-app.umd.js +17 -1
- package/dist/krubble-app.umd.js.map +1 -1
- package/dist/krubble-app.umd.min.js +3 -3
- package/dist/krubble-app.umd.min.js.map +1 -1
- package/dist/scaffold.d.ts +6 -0
- package/dist/scaffold.d.ts.map +1 -1
- package/dist/scaffold.js +17 -1
- package/dist/scaffold.js.map +1 -1
- package/package.json +1 -1
|
@@ -14,7 +14,7 @@ import{KRContextMenu as t,KRDialog as e}from"@kodaris/krubble-components";import
|
|
|
14
14
|
* Copyright 2017 Google LLC
|
|
15
15
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
16
16
|
*/
|
|
17
|
-
const E=globalThis,I=E.trustedTypes,S=I?I.createPolicy("lit-html",{createHTML:t=>t}):void 0,A="$lit$",C=`lit$${Math.random().toFixed(9).slice(2)}$`,N="?"+C,z=`<${N}>`,D=document,M=()=>D.createComment(""),
|
|
17
|
+
const E=globalThis,I=E.trustedTypes,S=I?I.createPolicy("lit-html",{createHTML:t=>t}):void 0,A="$lit$",C=`lit$${Math.random().toFixed(9).slice(2)}$`,N="?"+C,z=`<${N}>`,D=document,M=()=>D.createComment(""),T=t=>null===t||"object"!=typeof t&&"function"!=typeof t,P=Array.isArray,R="[ \t\n\f\r]",U=/<(?:(!--|\/[^a-zA-Z])|(\/?[a-zA-Z][^>\s]*)|(\/?$))/g,O=/-->/g,L=/>/g,H=RegExp(`>|${R}(?:([^\\s"'>=/]+)(${R}*=${R}*(?:[^ \t\n\f\r"'\`<>=]|("|')|))|$)`,"g"),j=/'/g,q=/"/g,X=/^(?:script|style|textarea|title)$/i,B=(t=>(e,...i)=>({_$litType$:t,strings:e,values:i}))(1),F=Symbol.for("lit-noChange"),W=Symbol.for("lit-nothing"),Y=new WeakMap,V=D.createTreeWalker(D,129);function K(t,e){if(!P(t)||!t.hasOwnProperty("raw"))throw Error("invalid template strings array");return void 0!==S?S.createHTML(e):e}const Q=(t,e)=>{const i=t.length-1,s=[];let a,r=2===e?"<svg>":3===e?"<math>":"",n=U;for(let e=0;e<i;e++){const i=t[e];let o,l,d=-1,c=0;for(;c<i.length&&(n.lastIndex=c,l=n.exec(i),null!==l);)c=n.lastIndex,n===U?"!--"===l[1]?n=O:void 0!==l[1]?n=L:void 0!==l[2]?(X.test(l[2])&&(a=RegExp("</"+l[2],"g")),n=H):void 0!==l[3]&&(n=H):n===H?">"===l[0]?(n=a??U,d=-1):void 0===l[1]?d=-2:(d=n.lastIndex-l[2].length,o=l[1],n=void 0===l[3]?H:'"'===l[3]?q:j):n===q||n===j?n=H:n===O||n===L?n=U:(n=H,a=void 0);const h=n===H&&t[e+1].startsWith("/>")?" ":"";r+=n===U?i+z:d>=0?(s.push(o),i.slice(0,d)+A+i.slice(d)+C+h):i+C+(-2===d?e:h)}return[K(t,r+(t[i]||"<?>")+(2===e?"</svg>":3===e?"</math>":"")),s]};class G{constructor({strings:t,_$litType$:e},i){let s;this.parts=[];let a=0,r=0;const n=t.length-1,o=this.parts,[l,d]=Q(t,e);if(this.el=G.createElement(l,i),V.currentNode=this.el.content,2===e||3===e){const t=this.el.content.firstChild;t.replaceWith(...t.childNodes)}for(;null!==(s=V.nextNode())&&o.length<n;){if(1===s.nodeType){if(s.hasAttributes())for(const t of s.getAttributeNames())if(t.endsWith(A)){const e=d[r++],i=s.getAttribute(t).split(C),n=/([.?@])?(.*)/.exec(e);o.push({type:1,index:a,name:n[2],strings:i,ctor:"."===n[1]?it:"?"===n[1]?st:"@"===n[1]?at:et}),s.removeAttribute(t)}else t.startsWith(C)&&(o.push({type:6,index:a}),s.removeAttribute(t));if(X.test(s.tagName)){const t=s.textContent.split(C),e=t.length-1;if(e>0){s.textContent=I?I.emptyScript:"";for(let i=0;i<e;i++)s.append(t[i],M()),V.nextNode(),o.push({type:2,index:++a});s.append(t[e],M())}}}else if(8===s.nodeType)if(s.data===N)o.push({type:2,index:a});else{let t=-1;for(;-1!==(t=s.data.indexOf(C,t+1));)o.push({type:7,index:a}),t+=C.length-1}a++}}static createElement(t,e){const i=D.createElement("template");return i.innerHTML=t,i}}function J(t,e,i=t,s){if(e===F)return e;let a=void 0!==s?i._$Co?.[s]:i._$Cl;const r=T(e)?void 0:e._$litDirective$;return a?.constructor!==r&&(a?._$AO?.(!1),void 0===r?a=void 0:(a=new r(t),a._$AT(t,i,s)),void 0!==s?(i._$Co??=[])[s]=a:i._$Cl=a),void 0!==a&&(e=J(t,a._$AS(t,e.values),a,s)),e}class Z{constructor(t,e){this._$AV=[],this._$AN=void 0,this._$AD=t,this._$AM=e}get parentNode(){return this._$AM.parentNode}get _$AU(){return this._$AM._$AU}u(t){const{el:{content:e},parts:i}=this._$AD,s=(t?.creationScope??D).importNode(e,!0);V.currentNode=s;let a=V.nextNode(),r=0,n=0,o=i[0];for(;void 0!==o;){if(r===o.index){let e;2===o.type?e=new tt(a,a.nextSibling,this,t):1===o.type?e=new o.ctor(a,o.name,o.strings,this,t):6===o.type&&(e=new rt(a,this,t)),this._$AV.push(e),o=i[++n]}r!==o?.index&&(a=V.nextNode(),r++)}return V.currentNode=D,s}p(t){let e=0;for(const i of this._$AV)void 0!==i&&(void 0!==i.strings?(i._$AI(t,i,e),e+=i.strings.length-2):i._$AI(t[e])),e++}}class tt{get _$AU(){return this._$AM?._$AU??this._$Cv}constructor(t,e,i,s){this.type=2,this._$AH=W,this._$AN=void 0,this._$AA=t,this._$AB=e,this._$AM=i,this.options=s,this._$Cv=s?.isConnected??!0}get parentNode(){let t=this._$AA.parentNode;const e=this._$AM;return void 0!==e&&11===t?.nodeType&&(t=e.parentNode),t}get startNode(){return this._$AA}get endNode(){return this._$AB}_$AI(t,e=this){t=J(this,t,e),T(t)?t===W||null==t||""===t?(this._$AH!==W&&this._$AR(),this._$AH=W):t!==this._$AH&&t!==F&&this._(t):void 0!==t._$litType$?this.$(t):void 0!==t.nodeType?this.T(t):(t=>P(t)||"function"==typeof t?.[Symbol.iterator])(t)?this.k(t):this._(t)}O(t){return this._$AA.parentNode.insertBefore(t,this._$AB)}T(t){this._$AH!==t&&(this._$AR(),this._$AH=this.O(t))}_(t){this._$AH!==W&&T(this._$AH)?this._$AA.nextSibling.data=t:this.T(D.createTextNode(t)),this._$AH=t}$(t){const{values:e,_$litType$:i}=t,s="number"==typeof i?this._$AC(t):(void 0===i.el&&(i.el=G.createElement(K(i.h,i.h[0]),this.options)),i);if(this._$AH?._$AD===s)this._$AH.p(e);else{const t=new Z(s,this),i=t.u(this.options);t.p(e),this.T(i),this._$AH=t}}_$AC(t){let e=Y.get(t.strings);return void 0===e&&Y.set(t.strings,e=new G(t)),e}k(t){P(this._$AH)||(this._$AH=[],this._$AR());const e=this._$AH;let i,s=0;for(const a of t)s===e.length?e.push(i=new tt(this.O(M()),this.O(M()),this,this.options)):i=e[s],i._$AI(a),s++;s<e.length&&(this._$AR(i&&i._$AB.nextSibling,s),e.length=s)}_$AR(t=this._$AA.nextSibling,e){for(this._$AP?.(!1,!0,e);t!==this._$AB;){const e=t.nextSibling;t.remove(),t=e}}setConnected(t){void 0===this._$AM&&(this._$Cv=t,this._$AP?.(t))}}class et{get tagName(){return this.element.tagName}get _$AU(){return this._$AM._$AU}constructor(t,e,i,s,a){this.type=1,this._$AH=W,this._$AN=void 0,this.element=t,this.name=e,this._$AM=s,this.options=a,i.length>2||""!==i[0]||""!==i[1]?(this._$AH=Array(i.length-1).fill(new String),this.strings=i):this._$AH=W}_$AI(t,e=this,i,s){const a=this.strings;let r=!1;if(void 0===a)t=J(this,t,e,0),r=!T(t)||t!==this._$AH&&t!==F,r&&(this._$AH=t);else{const s=t;let n,o;for(t=a[0],n=0;n<a.length-1;n++)o=J(this,s[i+n],e,n),o===F&&(o=this._$AH[n]),r||=!T(o)||o!==this._$AH[n],o===W?t=W:t!==W&&(t+=(o??"")+a[n+1]),this._$AH[n]=o}r&&!s&&this.j(t)}j(t){t===W?this.element.removeAttribute(this.name):this.element.setAttribute(this.name,t??"")}}class it extends et{constructor(){super(...arguments),this.type=3}j(t){this.element[this.name]=t===W?void 0:t}}class st extends et{constructor(){super(...arguments),this.type=4}j(t){this.element.toggleAttribute(this.name,!!t&&t!==W)}}class at extends et{constructor(t,e,i,s,a){super(t,e,i,s,a),this.type=5}_$AI(t,e=this){if((t=J(this,t,e,0)??W)===F)return;const i=this._$AH,s=t===W&&i!==W||t.capture!==i.capture||t.once!==i.once||t.passive!==i.passive,a=t!==W&&(i===W||s);s&&this.element.removeEventListener(this.name,this,i),a&&this.element.addEventListener(this.name,this,t),this._$AH=t}handleEvent(t){"function"==typeof this._$AH?this._$AH.call(this.options?.host??this.element,t):this._$AH.handleEvent(t)}}class rt{constructor(t,e,i){this.element=t,this.type=6,this._$AN=void 0,this._$AM=e,this.options=i}get _$AU(){return this._$AM._$AU}_$AI(t){J(this,t)}}const nt=E.litHtmlPolyfillSupport;nt?.(G,tt),(E.litHtmlVersions??=[]).push("3.3.2");const ot=globalThis;
|
|
18
18
|
/**
|
|
19
19
|
* @license
|
|
20
20
|
* Copyright 2017 Google LLC
|
|
@@ -198,7 +198,7 @@ function vt(t,e){return(e,i,s)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Ref
|
|
|
198
198
|
.btn-save:hover {
|
|
199
199
|
background: #d4f472;
|
|
200
200
|
}
|
|
201
|
-
`,kt([gt()],$t.prototype,"label",void 0),kt([gt()],$t.prototype,"icon",void 0),kt([gt()],$t.prototype,"url",void 0),kt([gt()],$t.prototype,"active",void 0),$t=kt([ct("kr-nav-item-edit")],$t);var Et=function(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let It=class extends lt{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.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.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.breadcrumbs=[],this.boundHandleMouseMove=this.handleMouseMove.bind(this),this.boundHandleMouseUp=this.handleMouseUp.bind(this)}connectedCallback(){super.connectedCallback(),this.loadPref(),this.installFetchInterceptor()}updated(t){super.updated(t),t.has("nav")&&this.nav.length>0&&(this.updateActiveNavItem(),this.navExpanded&&!this.navInitialized&&(this.navInitialized=!0,this.getComputedNav().filter((t=>"group"===t.type)).forEach((t=>this.navItemsExpanded.add(t.id)))))}disconnectedCallback(){super.disconnectedCallback(),this.uninstallFetchInterceptor()}installFetchInterceptor(){if(this.originalFetch)return;const t=this;this.originalFetch=window.fetch.bind(window);const e=this.originalFetch;window.fetch=function(...i){return t.pendingRequests++,e(...i).finally((()=>{t.pendingRequests--}))},this.originalXhrOpen=XMLHttpRequest.prototype.open;const i=this.originalXhrOpen;XMLHttpRequest.prototype.open=function(e,s,a=!0,r,n){return t.pendingRequests++,this.addEventListener("loadend",(()=>{t.pendingRequests--}),{once:!0}),i.call(this,e,s,a,r,n)}}uninstallFetchInterceptor(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null),this.originalXhrOpen&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,this.originalXhrOpen=null)}resolveUrl(t){if(!t.url)return"#";if(t.external)return t.url;const e=t.url.startsWith("/")?t.url.slice(1):t.url,i=document.querySelector("base")?.getAttribute("href")||"/";return(i.endsWith("/")?i:i+"/")+e}getComputedNav(){const t=[];return this.nav.forEach(((e,i)=>{const s=this.pref.nav[e.id];t.push({...e,...s,order:s?.order??e.order??i,parentId:s?.parentId??null}),"group"===e.type&&e.children&&e.children.forEach(((i,s)=>{const a=this.pref.nav[i.id];t.push({...i,...a,order:a?.order??i.order??s,parentId:void 0!==a?.parentId?a.parentId:e.id})}))})),Object.entries(this.pref.nav).forEach((([e,i])=>{e.startsWith("custom")&&i.type&&i.label&&t.push({id:e,type:i.type,label:i.label,icon:i.icon,url:i.url,active:i.active,order:i.order??t.length,parentId:i.parentId??null})})),t}getNavItemChildren(t){let e=this.getComputedNav().filter((e=>e.parentId===t)).sort(((t,e)=>t.order-e.order));if(this.isEditing||(e=e.filter((t=>!1!==t.active))),this.navQuery){const i=this.navQuery.toLowerCase(),s=this.getComputedNav();if(null!==t){const a=s.find((e=>e.id===t));if(a?.label.toLowerCase().includes(i))return e}e=e.filter((t=>"group"===t.type?t.label.toLowerCase().includes(i)||s.some((e=>e.parentId===t.id&&!1!==e.active&&e.label.toLowerCase().includes(i))):t.label.toLowerCase().includes(i)))}return e}handleNavQueryChange(t){this.navQuery=t.target.value,this.navQuery?this.getComputedNav().forEach((t=>{"group"===t.type&&this.navItemsExpanded.add(t.id)})):this.navItemsExpanded.clear()}handleNavQueryClear(){this.navQuery="",this.navItemsExpanded.clear()}handleMenuClick(){this.isNavOpened=!this.isNavOpened,localStorage.setItem("kr-scaffold-nav-opened",String(this.isNavOpened))}handleNavHeaderClick(){this.activeNavItemId=null;const t=new CustomEvent("nav-item-click",{detail:{item:{url:this.homeUrl}},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(t),t.defaultPrevented||(window.location.href=this.homeUrl)}handleNavScroll(t){this.isNavScrolled=t.target.scrollTop>0}toggleNavItem(t){const e=this.shadowRoot?.querySelector(`.nav-item[data-id="${t}"]`),i=e?.nextElementSibling;i&&(this.navItemsExpanded.has(t)?(this.navItemsExpanded.delete(t),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),i.classList.add("nav-group--expanded"),i.animate([{height:"0px"},{height:`${i.scrollHeight}px`}],{duration:300,easing:"ease-in-out"})),this.requestUpdate())}handleNavItemClick(t,e){if("group"===e.type)this.toggleNavItem(e.id);else{if(t.ctrlKey||t.metaKey||1===t.button)return;this.activeNavItemId=e.id;const i=new CustomEvent("nav-item-click",{detail:{item:e},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i),i.defaultPrevented&&t.preventDefault()}}updateActiveNavItem(){const t=window.location.pathname,e=this.getComputedNav().filter((t=>"item"===t.type&&t.url));let i=null,s=0;for(const a of e){const e=this.resolveUrl(a);t.startsWith(e)&&e.length>s&&(i=a,s=e.length)}i?(this.activeNavItemId=i.id,i.parentId&&this.navItemsExpanded.add(i.parentId)):this.activeNavItemId=null}startEditing(){this.isEditing=!0}cancelEditing(){this.isEditing=!1,this.loadPref()}resetPref(){this.pref.nav={}}savePref(){const t=this.pref.uuid?`/api/system/preference/json/scaffold/${this.pref.uuid}?global=true`:"/api/system/preference/json/scaffold?global=true";i.fetch({url:t,method:this.pref.uuid?"PUT":"POST",body:JSON.stringify({nav:this.pref.nav})}).then((t=>t.json())).then((t=>{this.pref=t.data,this.isEditing=!1})).catch((t=>{console.error("Failed to save nav customizations:",t)}))}loadPref(){i.fetch({url:"/api/system/preference/json/scaffold?global=true",method:"GET"}).then((t=>t.json())).then((t=>{const e=t?.data?.[0];e&&(this.pref=e)})).catch((()=>{}))}handleNavItemContextMenu(e,i){this.isEditing&&(e.preventDefault(),t.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((t=>{if(t)switch(t.id){case"edit":this.openNavItemEdit(i);break;case"add-above":this.addNavItem(i,"above");break;case"add-below":this.addNavItem(i,"below")}})))}openNavItemEdit(t){e.open($t,{data:t}).afterClosed().then((e=>{const i=e;i&&(this.pref.nav[t.id]||(this.pref.nav[t.id]={}),this.pref.nav[t.id]={...this.pref.nav[t.id],...i},this.requestUpdate())}))}addNavItem(t,e){const i=`custom-${Date.now()}`,s=this.getComputedNav().filter((e=>e.parentId===t.parentId)).sort(((t,e)=>t.order-e.order)),a=s.findIndex((e=>e.id===t.id)),r="above"===e?a:a+1;s.forEach(((t,e)=>{e>=r&&(this.pref.nav[t.id]||(this.pref.nav[t.id]={}),this.pref.nav[t.id].order=e+1)}));const n={id:i,type:"item",label:"New Item",order:r,parentId:t.parentId,active:!0};this.pref.nav[i]=n,this.requestUpdate(),this.openNavItemEdit(n)}handleNavItemMouseDown(t,e){this.isEditing&&(t.preventDefault(),this.draggedNavItemId=e.id,this.navItemDragStartY=t.clientY,this.isNavItemDragging=!1,document.addEventListener("mousemove",this.boundHandleMouseMove),document.addEventListener("mouseup",this.boundHandleMouseUp))}handleMouseMove(t){if(this.draggedNavItemId){if(!this.isNavItemDragging&&Math.abs(t.clientY-this.navItemDragStartY)>5){this.isNavItemDragging=!0,this.classList.add("kr-scaffold--dragging");const e=this.getComputedNav().find((t=>t.id===this.draggedNavItemId));e&&(this.navItemDragPreview=document.createElement("div"),this.navItemDragPreview.className="nav-item-drag-preview",this.navItemDragPreview.textContent=e.label,this.navItemDragPreview.style.left=`${t.clientX+10}px`,this.navItemDragPreview.style.top=t.clientY-20+"px",this.shadowRoot?.appendChild(this.navItemDragPreview))}this.isNavItemDragging&&(this.navItemDragPreview&&(this.navItemDragPreview.style.left=`${t.clientX+10}px`,this.navItemDragPreview.style.top=t.clientY-20+"px"),this.updateNavItemDropTarget(t))}}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(t){const e=this.shadowRoot?.querySelectorAll(".nav-item[data-id]");if(!e)return;let i=!1;e.forEach((e=>{const s=e.getBoundingClientRect(),a=e.getAttribute("data-id");if(!a||a===this.draggedNavItemId)return;if(t.clientX<s.left||t.clientX>s.right||t.clientY<s.top||t.clientY>s.bottom)return;const r=this.getComputedNav().find((t=>t.id===a));if(!r)return;const n=t.clientY-s.top;let o;"group"===r.type?n<s.height/3?(o="above",this.clearNavItemDragExpandTimeout()):n>2*s.height/3?(o="below",this.clearNavItemDragExpandTimeout()):(o="center",this.navItemsExpanded.has(r.id)||this.navItemDragExpandTimeout||this.expandNavGroupOnDrag(r.id)):(o=n<s.height/2?"above":"below",this.clearNavItemDragExpandTimeout());const l="center"===o?r.id:r.parentId,d=this.getComputedNav().find((t=>t.id===this.draggedNavItemId));if(l===this.draggedNavItemId||"group"===d?.type&&null!==l)return this.navItemDropTargetId=null,void this.clearNavItemDragExpandTimeout();this.navItemDropTargetId=r.id,this.navItemDropPosition=o,i=!0})),i||(this.navItemDropTargetId=null,this.clearNavItemDragExpandTimeout()),this.requestUpdate()}clearNavItemDragExpandTimeout(){this.navItemDragExpandTimeout&&(clearTimeout(this.navItemDragExpandTimeout),this.navItemDragExpandTimeout=null)}expandNavGroupOnDrag(t){this.navItemDragExpandTimeout=window.setTimeout((()=>{this.navItemDropTargetId===t&&"center"===this.navItemDropPosition&&(this.navItemsExpanded.add(t),this.requestUpdate()),this.navItemDragExpandTimeout=null}),500)}executeNavItemDrop(){if(!this.draggedNavItemId||!this.navItemDropTargetId)return;const t=this.getComputedNav(),e=t.find((t=>t.id===this.draggedNavItemId)),i=t.find((t=>t.id===this.navItemDropTargetId));if(!e||!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 a=t.filter((t=>t.parentId===s&&t.id!==this.draggedNavItemId)).sort(((t,e)=>t.order-e.order)),r=this.pref.nav;let n;if("center"===this.navItemDropPosition)n=a.length>0?Math.max(...a.map((t=>t.order)))+1:0;else{const t=a.findIndex((t=>t.id===i.id));n=-1===t?0:"above"===this.navItemDropPosition?t:t+1,a.forEach(((t,e)=>{r[t.id]||(r[t.id]={}),r[t.id].order=e>=n?e+1:e}))}r[this.draggedNavItemId]||(r[this.draggedNavItemId]={}),r[this.draggedNavItemId].order=n,r[this.draggedNavItemId].parentId=s,this.pref.nav=r,this.requestUpdate()}toggleUserMenu(){this.isUserMenuOpen=!this.isUserMenuOpen}closeUserMenu(){this.isUserMenuOpen=!1}handleCustomize(){this.closeUserMenu(),this.startEditing()}renderNormalFooter(){if(!this.user)return W;const t=this.user.name.split(" ").map((t=>t[0])).join("").toUpperCase().slice(0,2);return B`
|
|
201
|
+
`,kt([gt()],$t.prototype,"label",void 0),kt([gt()],$t.prototype,"icon",void 0),kt([gt()],$t.prototype,"url",void 0),kt([gt()],$t.prototype,"active",void 0),$t=kt([ct("kr-nav-item-edit")],$t);var Et=function(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let It=class extends lt{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.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.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.boundHandleMouseMove=this.handleMouseMove.bind(this),this.boundHandleMouseUp=this.handleMouseUp.bind(this)}connectedCallback(){super.connectedCallback(),this.installFetchInterceptor()}firstUpdated(){this.loadPref()}updated(t){super.updated(t),t.has("nav")&&this.nav.length>0&&(this.updateActiveNavItem(),this.navExpanded&&!this.navInitialized&&(this.navInitialized=!0,this.getComputedNav().filter((t=>"group"===t.type)).forEach((t=>this.navItemsExpanded.add(t.id)))))}disconnectedCallback(){super.disconnectedCallback(),this.uninstallFetchInterceptor()}installFetchInterceptor(){if(this.originalFetch)return;const t=this;this.originalFetch=window.fetch.bind(window);const e=this.originalFetch;window.fetch=function(...i){return t.pendingRequests++,e(...i).finally((()=>{t.pendingRequests--}))},this.originalXhrOpen=XMLHttpRequest.prototype.open;const i=this.originalXhrOpen;XMLHttpRequest.prototype.open=function(e,s,a=!0,r,n){return t.pendingRequests++,this.addEventListener("loadend",(()=>{t.pendingRequests--}),{once:!0}),i.call(this,e,s,a,r,n)}}uninstallFetchInterceptor(){this.originalFetch&&(window.fetch=this.originalFetch,this.originalFetch=null),this.originalXhrOpen&&(XMLHttpRequest.prototype.open=this.originalXhrOpen,this.originalXhrOpen=null)}resolveUrl(t){if(!t.url)return"#";if(t.external)return t.url;const e=t.url.startsWith("/")?t.url.slice(1):t.url,i=document.querySelector("base")?.getAttribute("href")||"/";return(i.endsWith("/")?i:i+"/")+e}getComputedNav(){const t=[];return this.nav.forEach(((e,i)=>{const s=this.pref.nav[e.id];t.push({...e,...s,order:s?.order??e.order??i,parentId:s?.parentId??null}),"group"===e.type&&e.children&&e.children.forEach(((i,s)=>{const a=this.pref.nav[i.id];t.push({...i,...a,order:a?.order??i.order??s,parentId:void 0!==a?.parentId?a.parentId:e.id})}))})),Object.entries(this.pref.nav).forEach((([e,i])=>{e.startsWith("custom")&&i.type&&i.label&&t.push({id:e,type:i.type,label:i.label,icon:i.icon,url:i.url,active:i.active,order:i.order??t.length,parentId:i.parentId??null})})),t}getNavItemChildren(t){let e=this.getComputedNav().filter((e=>e.parentId===t)).sort(((t,e)=>t.order-e.order));if(this.isEditing||(e=e.filter((t=>!1!==t.active))),this.navQuery){const i=this.navQuery.toLowerCase(),s=this.getComputedNav();if(null!==t){const a=s.find((e=>e.id===t));if(a?.label.toLowerCase().includes(i))return e}e=e.filter((t=>"group"===t.type?t.label.toLowerCase().includes(i)||s.some((e=>e.parentId===t.id&&!1!==e.active&&e.label.toLowerCase().includes(i))):t.label.toLowerCase().includes(i)))}return e}handleNavQueryChange(t){this.navQuery=t.target.value,this.navQuery?this.getComputedNav().forEach((t=>{"group"===t.type&&this.navItemsExpanded.add(t.id)})):this.navItemsExpanded.clear()}handleNavQueryClear(){this.navQuery="",this.navItemsExpanded.clear()}handleMenuClick(){this.isNavOpened=!this.isNavOpened,localStorage.setItem("kr-scaffold-nav-opened",String(this.isNavOpened))}handleNavHeaderClick(){this.activeNavItemId=null;const t=new CustomEvent("nav-item-click",{detail:{item:{url:this.homeUrl}},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(t),t.defaultPrevented||(window.location.href=this.homeUrl)}handleNavScroll(t){this.isNavScrolled=t.target.scrollTop>0}toggleNavItem(t){const e=this.shadowRoot?.querySelector(`.nav-item[data-id="${t}"]`),i=e?.nextElementSibling;i&&(this.navItemsExpanded.has(t)?(this.navItemsExpanded.delete(t),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),i.classList.add("nav-group--expanded"),i.animate([{height:"0px"},{height:`${i.scrollHeight}px`}],{duration:300,easing:"ease-in-out"})),this.requestUpdate())}handleNavItemClick(t,e){if("group"===e.type)this.toggleNavItem(e.id);else{if(t.ctrlKey||t.metaKey||1===t.button)return;this.activeNavItemId=e.id;const i=new CustomEvent("nav-item-click",{detail:{item:e},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i),i.defaultPrevented&&t.preventDefault()}}updateActiveNavItem(){const t=window.location.pathname,e=this.getComputedNav().filter((t=>"item"===t.type&&t.url));let i=null,s=0;for(const a of e){const e=this.resolveUrl(a);t.startsWith(e)&&e.length>s&&(i=a,s=e.length)}i?(this.activeNavItemId=i.id,i.parentId&&this.navItemsExpanded.add(i.parentId)):this.activeNavItemId=null}startEditing(){this.isEditing=!0}cancelEditing(){this.isEditing=!1,this.loadPref()}resetPref(){this.pref.nav={}}savePref(){if("customer"===this.userType)return;const t=this.pref.uuid?`/api/system/preference/json/scaffold/${this.pref.uuid}?global=true`:"/api/system/preference/json/scaffold?global=true";i.fetch({url:t,method:this.pref.uuid?"PUT":"POST",body:JSON.stringify({nav:this.pref.nav})}).then((t=>t.json())).then((t=>{this.pref=t.data,this.isEditing=!1})).catch((t=>{console.error("Failed to save nav customizations:",t)}))}loadPref(){"customer"!==this.userType&&i.fetch({url:"/api/system/preference/json/scaffold?global=true",method:"GET"}).then((t=>t.json())).then((t=>{const e=t?.data?.[0];e&&(this.pref=e)})).catch((()=>{}))}handleNavItemContextMenu(e,i){this.isEditing&&(e.preventDefault(),t.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((t=>{if(t)switch(t.id){case"edit":this.openNavItemEdit(i);break;case"add-above":this.addNavItem(i,"above");break;case"add-below":this.addNavItem(i,"below")}})))}openNavItemEdit(t){e.open($t,{data:t}).afterClosed().then((e=>{const i=e;i&&(this.pref.nav[t.id]||(this.pref.nav[t.id]={}),this.pref.nav[t.id]={...this.pref.nav[t.id],...i},this.requestUpdate())}))}addNavItem(t,e){const i=`custom-${Date.now()}`,s=this.getComputedNav().filter((e=>e.parentId===t.parentId)).sort(((t,e)=>t.order-e.order)),a=s.findIndex((e=>e.id===t.id)),r="above"===e?a:a+1;s.forEach(((t,e)=>{e>=r&&(this.pref.nav[t.id]||(this.pref.nav[t.id]={}),this.pref.nav[t.id].order=e+1)}));const n={id:i,type:"item",label:"New Item",order:r,parentId:t.parentId,active:!0};this.pref.nav[i]=n,this.requestUpdate(),this.openNavItemEdit(n)}handleNavItemMouseDown(t,e){this.isEditing&&(t.preventDefault(),this.draggedNavItemId=e.id,this.navItemDragStartY=t.clientY,this.isNavItemDragging=!1,document.addEventListener("mousemove",this.boundHandleMouseMove),document.addEventListener("mouseup",this.boundHandleMouseUp))}handleMouseMove(t){if(this.draggedNavItemId){if(!this.isNavItemDragging&&Math.abs(t.clientY-this.navItemDragStartY)>5){this.isNavItemDragging=!0,this.classList.add("kr-scaffold--dragging");const e=this.getComputedNav().find((t=>t.id===this.draggedNavItemId));e&&(this.navItemDragPreview=document.createElement("div"),this.navItemDragPreview.className="nav-item-drag-preview",this.navItemDragPreview.textContent=e.label,this.navItemDragPreview.style.left=`${t.clientX+10}px`,this.navItemDragPreview.style.top=t.clientY-20+"px",this.shadowRoot?.appendChild(this.navItemDragPreview))}this.isNavItemDragging&&(this.navItemDragPreview&&(this.navItemDragPreview.style.left=`${t.clientX+10}px`,this.navItemDragPreview.style.top=t.clientY-20+"px"),this.updateNavItemDropTarget(t))}}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(t){const e=this.shadowRoot?.querySelectorAll(".nav-item[data-id]");if(!e)return;let i=!1;e.forEach((e=>{const s=e.getBoundingClientRect(),a=e.getAttribute("data-id");if(!a||a===this.draggedNavItemId)return;if(t.clientX<s.left||t.clientX>s.right||t.clientY<s.top||t.clientY>s.bottom)return;const r=this.getComputedNav().find((t=>t.id===a));if(!r)return;const n=t.clientY-s.top;let o;"group"===r.type?n<s.height/3?(o="above",this.clearNavItemDragExpandTimeout()):n>2*s.height/3?(o="below",this.clearNavItemDragExpandTimeout()):(o="center",this.navItemsExpanded.has(r.id)||this.navItemDragExpandTimeout||this.expandNavGroupOnDrag(r.id)):(o=n<s.height/2?"above":"below",this.clearNavItemDragExpandTimeout());const l="center"===o?r.id:r.parentId,d=this.getComputedNav().find((t=>t.id===this.draggedNavItemId));if(l===this.draggedNavItemId||"group"===d?.type&&null!==l)return this.navItemDropTargetId=null,void this.clearNavItemDragExpandTimeout();this.navItemDropTargetId=r.id,this.navItemDropPosition=o,i=!0})),i||(this.navItemDropTargetId=null,this.clearNavItemDragExpandTimeout()),this.requestUpdate()}clearNavItemDragExpandTimeout(){this.navItemDragExpandTimeout&&(clearTimeout(this.navItemDragExpandTimeout),this.navItemDragExpandTimeout=null)}expandNavGroupOnDrag(t){this.navItemDragExpandTimeout=window.setTimeout((()=>{this.navItemDropTargetId===t&&"center"===this.navItemDropPosition&&(this.navItemsExpanded.add(t),this.requestUpdate()),this.navItemDragExpandTimeout=null}),500)}executeNavItemDrop(){if(!this.draggedNavItemId||!this.navItemDropTargetId)return;const t=this.getComputedNav(),e=t.find((t=>t.id===this.draggedNavItemId)),i=t.find((t=>t.id===this.navItemDropTargetId));if(!e||!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 a=t.filter((t=>t.parentId===s&&t.id!==this.draggedNavItemId)).sort(((t,e)=>t.order-e.order)),r=this.pref.nav;let n;if("center"===this.navItemDropPosition)n=a.length>0?Math.max(...a.map((t=>t.order)))+1:0;else{const t=a.findIndex((t=>t.id===i.id));n=-1===t?0:"above"===this.navItemDropPosition?t:t+1,a.forEach(((t,e)=>{r[t.id]||(r[t.id]={}),r[t.id].order=e>=n?e+1:e}))}r[this.draggedNavItemId]||(r[this.draggedNavItemId]={}),r[this.draggedNavItemId].order=n,r[this.draggedNavItemId].parentId=s,this.pref.nav=r,this.requestUpdate()}toggleUserMenu(){this.isUserMenuOpen=!this.isUserMenuOpen}closeUserMenu(){this.isUserMenuOpen=!1}handleCustomize(){this.closeUserMenu(),this.startEditing()}renderNormalFooter(){if(!this.user)return W;const t=this.user.name.split(" ").map((t=>t[0])).join("").toUpperCase().slice(0,2);return B`
|
|
202
202
|
<div class="user-menu-container">
|
|
203
203
|
${this.isUserMenuOpen?B`
|
|
204
204
|
<div class="user-menu">
|
|
@@ -1058,7 +1058,7 @@ function vt(t,e){return(e,i,s)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Ref
|
|
|
1058
1058
|
transform: scaleX(0.08);
|
|
1059
1059
|
}
|
|
1060
1060
|
}
|
|
1061
|
-
`,Et([gt()],It.prototype,"navItemsExpanded",void 0),Et([gt()],It.prototype,"navQuery",void 0),Et([gt()],It.prototype,"activeNavItemId",void 0),Et([gt()],It.prototype,"isNavScrolled",void 0),Et([gt()],It.prototype,"isNavOpened",void 0),Et([gt()],It.prototype,"isEditing",void 0),Et([gt()],It.prototype,"isUserMenuOpen",void 0),Et([gt()],It.prototype,"pref",void 0),Et([gt()],It.prototype,"draggedNavItemId",void 0),Et([gt()],It.prototype,"navItemDropTargetId",void 0),Et([gt()],It.prototype,"navItemDropPosition",void 0),Et([gt()],It.prototype,"pendingRequests",void 0),Et([ut({type:String})],It.prototype,"logo",void 0),Et([ut({type:String})],It.prototype,"label",void 0),Et([ut({type:String,attribute:"home-url"})],It.prototype,"homeUrl",void 0),Et([ut({type:String,reflect:!0})],It.prototype,"scheme",void 0),Et([ut({type:Array})],It.prototype,"nav",void 0),Et([ut({type:Boolean,attribute:"nav-icons-displayed",reflect:!0})],It.prototype,"navIconsDisplayed",void 0),Et([ut({type:Boolean,attribute:"nav-expanded"})],It.prototype,"navExpanded",void 0),Et([ut({type:Object})],It.prototype,"user",void 0),Et([ut({type:Boolean})],It.prototype,"subbar",void 0),Et([ut({type:Boolean,attribute:"nav-enabled"})],It.prototype,"navEnabled",void 0),Et([ut({type:Array})],It.prototype,"breadcrumbs",void 0),It=Et([ct("kr-scaffold")],It);var St=function(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let At=class extends lt{constructor(){super(...arguments),this.label="",this.subLabel="",this.navItems=[],this.activeId="",this.handlePopstate=()=>{this.syncActiveFromUrl()}}connectedCallback(){super.connectedCallback(),requestAnimationFrame((()=>this.syncActiveFromUrl())),window.addEventListener("popstate",this.handlePopstate)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("popstate",this.handlePopstate)}handleNavItemClick(t,e){const i=new CustomEvent("nav-item-click",{detail:{item:e},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i),i.defaultPrevented&&t.preventDefault(),this.activeId=e.id}syncActiveFromUrl(){const t=window.location.pathname,e=this.navItems.find((e=>!!e.url&&(e.url.startsWith("/")?t===e.url:t.endsWith("/"+e.url))));e&&(this.activeId=e.id)}render(){return B`
|
|
1061
|
+
`,Et([gt()],It.prototype,"navItemsExpanded",void 0),Et([gt()],It.prototype,"navQuery",void 0),Et([gt()],It.prototype,"activeNavItemId",void 0),Et([gt()],It.prototype,"isNavScrolled",void 0),Et([gt()],It.prototype,"isNavOpened",void 0),Et([gt()],It.prototype,"isEditing",void 0),Et([gt()],It.prototype,"isUserMenuOpen",void 0),Et([gt()],It.prototype,"pref",void 0),Et([gt()],It.prototype,"draggedNavItemId",void 0),Et([gt()],It.prototype,"navItemDropTargetId",void 0),Et([gt()],It.prototype,"navItemDropPosition",void 0),Et([gt()],It.prototype,"pendingRequests",void 0),Et([ut({type:String})],It.prototype,"logo",void 0),Et([ut({type:String})],It.prototype,"label",void 0),Et([ut({type:String,attribute:"home-url"})],It.prototype,"homeUrl",void 0),Et([ut({type:String,reflect:!0})],It.prototype,"scheme",void 0),Et([ut({type:Array})],It.prototype,"nav",void 0),Et([ut({type:Boolean,attribute:"nav-icons-displayed",reflect:!0})],It.prototype,"navIconsDisplayed",void 0),Et([ut({type:Boolean,attribute:"nav-expanded"})],It.prototype,"navExpanded",void 0),Et([ut({type:Object})],It.prototype,"user",void 0),Et([ut({type:Boolean})],It.prototype,"subbar",void 0),Et([ut({type:Boolean,attribute:"nav-enabled"})],It.prototype,"navEnabled",void 0),Et([ut({type:String,attribute:"user-type"})],It.prototype,"userType",void 0),Et([ut({type:Array})],It.prototype,"breadcrumbs",void 0),It=Et([ct("kr-scaffold")],It);var St=function(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let At=class extends lt{constructor(){super(...arguments),this.label="",this.subLabel="",this.navItems=[],this.activeId="",this.handlePopstate=()=>{this.syncActiveFromUrl()}}connectedCallback(){super.connectedCallback(),requestAnimationFrame((()=>this.syncActiveFromUrl())),window.addEventListener("popstate",this.handlePopstate)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("popstate",this.handlePopstate)}handleNavItemClick(t,e){const i=new CustomEvent("nav-item-click",{detail:{item:e},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(i),i.defaultPrevented&&t.preventDefault(),this.activeId=e.id}syncActiveFromUrl(){const t=window.location.pathname,e=this.navItems.find((e=>!!e.url&&(e.url.startsWith("/")?t===e.url:t.endsWith("/"+e.url))));e&&(this.activeId=e.id)}render(){return B`
|
|
1062
1062
|
<nav class="nav">
|
|
1063
1063
|
${this.label?B`
|
|
1064
1064
|
<div class="nav-header">
|
|
@@ -1324,12 +1324,12 @@ function vt(t,e){return(e,i,s)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Ref
|
|
|
1324
1324
|
width: 18px;
|
|
1325
1325
|
height: 18px;
|
|
1326
1326
|
}
|
|
1327
|
-
`,zt([ut({type:Array})],Dt.prototype,"breadcrumbs",void 0),zt([ut({type:Boolean})],Dt.prototype,"menu",void 0),Dt=zt([ct("kr-subbar")],Dt);var Mt=function(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};class
|
|
1327
|
+
`,zt([ut({type:Array})],Dt.prototype,"breadcrumbs",void 0),zt([ut({type:Boolean})],Dt.prototype,"menu",void 0),Dt=zt([ct("kr-subbar")],Dt);var Mt=function(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};class Tt{static configure(t){Tt.base=t.base,Tt.routes=t.routes,window.addEventListener("click",(t=>{const e=t.composedPath().find((t=>t instanceof HTMLAnchorElement));e&&e.origin===window.location.origin&&e.pathname.startsWith(Tt.base)&&(t.preventDefault(),Tt.navigate(e.pathname))}))}static navigate(t){let e=t;t.startsWith("/")||(e=Tt.base+"/"+t),window.history.pushState({},"",e),window.dispatchEvent(new PopStateEvent("popstate"))}static getParams(){const t=Tt.matchAll(),e={};for(const i of t)for(const t in i.params)e[t]=decodeURIComponent(i.params[t]);return e}static outlet(t){const e=Tt.matchAll();if(t>=e.length)return null;const i=e[t].route.component,s=Tt.elementCache.get(t+":"+i);if(s)return s;for(const e of Tt.elementCache.keys())e.startsWith(t+":")&&Tt.elementCache.delete(e);const a=document.createElement(i);return Tt.elementCache.set(t+":"+i,a),a}static matchAll(){const t=window.location.pathname;let e=t;t.startsWith(Tt.base)&&(e=t.slice(Tt.base.length));const i=e.split("/").filter((t=>t));return Tt.matchRoutes(Tt.routes,i)}static matchRoutes(t,e){for(const i of t){const t=i.path.split("/").filter((t=>t));if(0===t.length&&0===e.length)return[{route:i,params:{}}];if(0===t.length)continue;if(e.length<t.length)continue;const s={};let a=!0;for(let i=0;i<t.length;i++)if(t[i].startsWith(":"))s[t[i].slice(1)]=e[i];else if(t[i]!==e[i]){a=!1;break}if(!a)continue;const r=e.slice(t.length);if(r.length>0&&!i.children)continue;const n=[{route:i,params:s}];if(i.children&&r.length>0){const t=Tt.matchRoutes(i.children,r);if(t.length>0)return n.push(...t),n}if(i.children&&0===r.length&&i.default){window.history.replaceState({},"",window.location.pathname+"/"+i.default);const t=Tt.matchRoutes(i.children,[i.default]);if(t.length>0)return n.push(...t),n}return n}return[]}}Tt.base="",Tt.routes=[],Tt.elementCache=new Map;let Pt=class extends lt{constructor(){super(...arguments),this.level=-1,this.handlePopState=()=>{this.requestUpdate()}}connectedCallback(){super.connectedCallback(),this.level=this.detectLevel(),window.addEventListener("popstate",this.handlePopState)}disconnectedCallback(){super.disconnectedCallback(),window.removeEventListener("popstate",this.handlePopState)}detectLevel(){let t=0,e=this;for(;e;)e instanceof ShadowRoot?e=e.host:(e instanceof HTMLElement&&"KR-ROUTER-OUTLET"===e.tagName&&e!==this&&t++,e=e instanceof HTMLElement?e.parentNode:null);return t}render(){const t=Tt.outlet(this.level);return t?B`${t}`:B``}};Pt.styles=l`
|
|
1328
1328
|
:host {
|
|
1329
1329
|
display: block;
|
|
1330
1330
|
height: 100%;
|
|
1331
1331
|
}
|
|
1332
|
-
`,
|
|
1332
|
+
`,Pt=Mt([ct("kr-router-outlet")],Pt);var Rt=function(t,e,i,s){var a,r=arguments.length,n=r<3?e:null===s?s=Object.getOwnPropertyDescriptor(e,i):s;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)n=Reflect.decorate(t,e,i,s);else for(var o=t.length-1;o>=0;o--)(a=t[o])&&(n=(r<3?a(n):r>3?a(e,i,n):a(e,i))||n);return r>3&&n&&Object.defineProperty(e,i,n),n};let Ut=class extends lt{constructor(){super(...arguments),this._reader=null,this._decoder=new TextDecoder,this._buffer="",this._userHasScrolledUp=!1,this._isDragging=!1,this._isResizing=!1,this._resizeDir="",this._dragStartX=0,this._dragStartY=0,this._dragStartLeft=0,this._dragStartTop=0,this._resizeStartW=0,this._resizeStartH=0,this.send=null,this.clear=null,this.messages=[],this.title="AI Assistant",this.subtitle="",this.placeholder="Type a message...",this.opened=!1,this._inputValue="",this._isStreaming=!1,this._statusText="",this._error="",this._handleMouseMove=t=>{if(this._isDragging){let e=this._dragStartLeft+(t.clientX-this._dragStartX),i=this._dragStartTop+(t.clientY-this._dragStartY);const s=this._panelEl.offsetWidth,a=this._panelEl.offsetHeight;e=Math.max(48-s,Math.min(e,window.innerWidth-48)),i=Math.max(48-a,Math.min(i,window.innerHeight-48)),this._panelEl.style.left=e+"px",this._panelEl.style.top=i+"px"}else if(this._isResizing){const e=t.clientX-this._dragStartX,i=t.clientY-this._dragStartY,s=340,a=380,r=.9*window.innerWidth,n=window.innerHeight-72;let o=this._resizeStartW,l=this._resizeStartH,d=this._dragStartLeft,c=this._dragStartTop;if(this._resizeDir.includes("e")&&(o=Math.max(s,Math.min(this._resizeStartW+e,r))),this._resizeDir.includes("w")){const t=this._resizeStartW-e;t>=s&&t<=r&&(o=t,d=this._dragStartLeft+e)}if(this._resizeDir.includes("s")&&(l=Math.max(a,Math.min(this._resizeStartH+i,n))),this._resizeDir.includes("n")){const t=this._resizeStartH-i;t>=a&&t<=n&&(l=t,c=this._dragStartTop+i)}d=Math.max(0,d),c=Math.max(0,c),this._panelEl.style.width=o+"px",this._panelEl.style.height=l+"px",this._panelEl.style.left=d+"px",this._panelEl.style.top=c+"px"}},this._handleMouseUp=()=>{this._isDragging&&(this._isDragging=!1,this._panelEl.classList.remove("chatbot__panel--dragging")),this._isResizing&&(this._isResizing=!1,this._panelEl.classList.remove("chatbot__panel--resizing")),document.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp)}}disconnectedCallback(){super.disconnectedCallback(),this._reader&&(this._reader.cancel(),this._reader=null),document.removeEventListener("mousemove",this._handleMouseMove),document.removeEventListener("mouseup",this._handleMouseUp)}updated(t){(t.has("messages")||t.has("_statusText"))&&!this._userHasScrolledUp&&this._messagesEl&&requestAnimationFrame((()=>{this._messagesEl&&(this._messagesEl.scrollTop=this._messagesEl.scrollHeight)})),t.has("opened")&&this.opened&&this._inputEl&&setTimeout((()=>{this._inputEl&&this._inputEl.focus()}),200)}stop(){this._handleStop()}_handleHeaderMouseDown(t){if(t.target.closest("button"))return;if(!this._panelEl)return;this._isDragging=!0,this._panelEl.classList.add("chatbot__panel--dragging");const e=this._panelEl.getBoundingClientRect();this._panelEl.style.left=e.left+"px",this._panelEl.style.top=e.top+"px",this._panelEl.style.right="auto",this._panelEl.style.bottom="auto",this._panelEl.style.position="fixed",this._dragStartX=t.clientX,this._dragStartY=t.clientY,this._dragStartLeft=e.left,this._dragStartTop=e.top,t.preventDefault(),document.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)}_handleResizeMouseDown(t){if(!this._panelEl)return;this._isResizing=!0,this._resizeDir=t.currentTarget.dataset.dir||"",this._panelEl.classList.add("chatbot__panel--resizing");const e=this._panelEl.getBoundingClientRect();this._panelEl.style.left=e.left+"px",this._panelEl.style.top=e.top+"px",this._panelEl.style.right="auto",this._panelEl.style.bottom="auto",this._panelEl.style.position="fixed",this._dragStartX=t.clientX,this._dragStartY=t.clientY,this._dragStartLeft=e.left,this._dragStartTop=e.top,this._resizeStartW=e.width,this._resizeStartH=e.height,t.preventDefault(),t.stopPropagation(),document.addEventListener("mousemove",this._handleMouseMove),document.addEventListener("mouseup",this._handleMouseUp)}_handleToggle(){this.opened=!this.opened,this.opened&&this._panelEl&&(this._panelEl.style.left="",this._panelEl.style.top="",this._panelEl.style.right="",this._panelEl.style.bottom="",this._panelEl.style.width="",this._panelEl.style.height="",this._panelEl.style.position="")}_handleInputChange(t){this._inputValue=t.target.value;const e=t.target;e.style.height="auto",e.style.height=Math.min(e.scrollHeight,120)+"px"}_handleKeyDown(t){"Enter"!==t.key||t.shiftKey||(t.preventDefault(),this._handleSubmit())}_handleSubmit(){if(!this._inputValue.trim()||!this.send||this._isStreaming)return;const t=this._inputValue.trim(),e=new CustomEvent("message-submit",{detail:{message:t},bubbles:!0,composed:!0,cancelable:!0});this.dispatchEvent(e),e.defaultPrevented||(this.messages=[...this.messages,{role:"user",content:t}],this._inputValue="",this._error="",this._userHasScrolledUp=!1,this._inputEl&&(this._inputEl.style.height="auto"),this.messages=[...this.messages,{role:"assistant",content:""}],this._isStreaming=!0,this._statusText="",this.send({message:t,messages:this.messages.slice(0,-1)}).then((t=>{t.ok?t.body?(this._reader=t.body.getReader(),this._decoder=new TextDecoder,this._buffer="",this._readStreamChunk()):this._handleStreamError("No response body"):this._handleStreamError("Request failed: "+t.status)})).catch((t=>{"AbortError"!==t.name&&this._handleStreamError(t.message)})))}_handleStop(){this._reader&&(this._reader.cancel(),this._reader=null),this._isStreaming=!1,this._statusText=""}_handleClear(){this.clear&&this.clear().then((()=>{this._reader&&(this._reader.cancel(),this._reader=null),this.messages=[],this._isStreaming=!1,this._statusText="",this._error="",this._inputValue="",this._userHasScrolledUp=!1}))}_handleMessagesScroll(t){const e=t.target,i=e.scrollHeight-e.scrollTop-e.clientHeight;this._userHasScrolledUp=i>50}_handleErrorDismiss(){this._error=""}_readStreamChunk(){this._reader&&this._reader.read().then((t=>{if(t.done)return this._isStreaming=!1,this._statusText="",void(this._reader=null);this._buffer=this._buffer+this._decoder.decode(t.value,{stream:!0});const e=this._buffer.split("\n\n");this._buffer=e.pop()||"";for(let t=0;t<e.length;t++){if(!e[t].trim())continue;const i=e[t].split("\n");for(let t=0;t<i.length;t++){if(!i[t].startsWith("data:"))continue;const e=i[t].slice(5).trim();if(!e)continue;let s;try{s=JSON.parse(e)}catch{continue}if(this.dispatchEvent(new CustomEvent("stream-event",{detail:s,bubbles:!0,composed:!0})),"STATUS"===s.type)s.message&&(this._statusText=String(s.message));else if("REASONING_PART"===s.type){if(s.message){const t=this.messages.length-1;t>=0&&"assistant"===this.messages[t].role&&(this.messages[t].reasoning||(this.messages[t].reasoning=""),this.messages[t].reasoning+=String(s.message),this.requestUpdate())}}else if("RESPONSE_PART"===s.type){if(s.message){this._statusText="";const t=this.messages.length-1;t>=0&&"assistant"===this.messages[t].role&&(this.messages[t].content+=String(s.message),this.requestUpdate())}}else if("ACTION"===s.type){const t=s,e=new CustomEvent("action",{detail:{action:t},bubbles:!0,composed:!0,cancelable:!0});if(this.dispatchEvent(e),!e.defaultPrevented)if("RELOAD"===t.action)location.reload();else if("NAVIGATE"===t.action)t.data&&t.data.url&&(window.location.href=t.data.url);else if("OPEN_TAB"===t.action)t.data&&t.data.url&&window.open(t.data.url,"_blank");else if("UPDATE_HTML"===t.action){if(t.data&&t.data.selector&&t.data.html){const e=document.querySelector(t.data.selector);e&&(e.innerHTML=t.data.html)}}else if("SCROLL_TO"===t.action&&t.data&&t.data.selector){const e=document.querySelector(t.data.selector);e&&e.scrollIntoView({behavior:"smooth"})}}else"ERROR"===s.type&&this._handleStreamError(String(s.message||"Unknown error"));s.finished&&(this._isStreaming=!1,this._statusText="",this._reader=null)}}this._readStreamChunk()})).catch((t=>{"AbortError"!==t.name&&this._handleStreamError(t.message)}))}_handleStreamError(t){if(this._isStreaming=!1,this._statusText="",this._error=t,this._reader&&(this._reader.cancel(),this._reader=null),this.messages.length>0){const t=this.messages[this.messages.length-1];"assistant"!==t.role||t.content||(this.messages=this.messages.slice(0,-1))}}_formatAssistantContent(t){let e=t.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'");e=e.replace(/```(\w*)\n?([\s\S]*?)```/g,"<pre><code>$2</code></pre>"),e=e.replace(/`([^`]+)`/g,"<code>$1</code>"),e=e.replace(/\*\*([^*]+)\*\*/g,"<strong>$1</strong>");const i=e.split(/(<pre><code>[\s\S]*?<\/code><\/pre>)/g);for(let t=0;t<i.length;t++)t%2==0&&(i[t]=i[t].replace(/\n\n/g,"</p><p>"),i[t]=i[t].replace(/\n/g,"<br>"));return e=i.join(""),e.includes("</p><p>")&&(e="<p>"+e+"</p>"),e}render(){return B`
|
|
1333
1333
|
<button
|
|
1334
1334
|
class=${wt({chatbot__toggle:!0,"chatbot__toggle--hidden":this.opened})}
|
|
1335
1335
|
@click=${this._handleToggle}
|
|
@@ -2037,5 +2037,5 @@ function vt(t,e){return(e,i,s)=>((t,e,i)=>(i.configurable=!0,i.enumerable=!0,Ref
|
|
|
2037
2037
|
border-bottom: 2px solid rgba(0, 0, 0, 0.12);
|
|
2038
2038
|
border-radius: 0 0 3px 0;
|
|
2039
2039
|
}
|
|
2040
|
-
`,Rt([ut({attribute:!1})],Ut.prototype,"send",void 0),Rt([ut({attribute:!1})],Ut.prototype,"clear",void 0),Rt([ut({attribute:!1})],Ut.prototype,"messages",void 0),Rt([ut({type:String})],Ut.prototype,"title",void 0),Rt([ut({type:String})],Ut.prototype,"subtitle",void 0),Rt([ut({type:String})],Ut.prototype,"placeholder",void 0),Rt([ut({type:Boolean,reflect:!0})],Ut.prototype,"opened",void 0),Rt([gt()],Ut.prototype,"_inputValue",void 0),Rt([gt()],Ut.prototype,"_isStreaming",void 0),Rt([gt()],Ut.prototype,"_statusText",void 0),Rt([gt()],Ut.prototype,"_error",void 0),Rt([vt(".chatbot__panel")],Ut.prototype,"_panelEl",void 0),Rt([vt(".chatbot__messages")],Ut.prototype,"_messagesEl",void 0),Rt([vt(".chatbot__input")],Ut.prototype,"_inputEl",void 0),Ut=Rt([ct("kr-chatbot")],Ut);export{Ut as KRChatbot,
|
|
2040
|
+
`,Rt([ut({attribute:!1})],Ut.prototype,"send",void 0),Rt([ut({attribute:!1})],Ut.prototype,"clear",void 0),Rt([ut({attribute:!1})],Ut.prototype,"messages",void 0),Rt([ut({type:String})],Ut.prototype,"title",void 0),Rt([ut({type:String})],Ut.prototype,"subtitle",void 0),Rt([ut({type:String})],Ut.prototype,"placeholder",void 0),Rt([ut({type:Boolean,reflect:!0})],Ut.prototype,"opened",void 0),Rt([gt()],Ut.prototype,"_inputValue",void 0),Rt([gt()],Ut.prototype,"_isStreaming",void 0),Rt([gt()],Ut.prototype,"_statusText",void 0),Rt([gt()],Ut.prototype,"_error",void 0),Rt([vt(".chatbot__panel")],Ut.prototype,"_panelEl",void 0),Rt([vt(".chatbot__messages")],Ut.prototype,"_messagesEl",void 0),Rt([vt(".chatbot__input")],Ut.prototype,"_inputEl",void 0),Ut=Rt([ct("kr-chatbot")],Ut);export{Ut as KRChatbot,Tt as KRRouter,Pt as KRRouterOutlet,It as KRScaffold,Nt as KRScreenDetail,At as KRScreenNav,Dt as KRSubbar};
|
|
2041
2041
|
//# sourceMappingURL=krubble-app.bundled.min.js.map
|