web-mojo 2.2.48 → 2.2.49
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/admin.cjs.js +1 -1
- package/dist/admin.es.js +13 -13
- 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 +4 -4
- package/dist/chunks/{ChatView-D9ZaC_gN.js → ChatView-BUfkeVnX.js} +7 -7
- package/dist/chunks/{ChatView-D9ZaC_gN.js.map → ChatView-BUfkeVnX.js.map} +1 -1
- package/dist/chunks/{ChatView-Ds4cJWJI.js → ChatView-Tj1Kb9Hf.js} +2 -2
- package/dist/chunks/{ChatView-Ds4cJWJI.js.map → ChatView-Tj1Kb9Hf.js.map} +1 -1
- package/dist/chunks/{Collection-Wr1qdfrB.js → Collection-D3K_bEJN.js} +2 -2
- package/dist/chunks/{Collection-Wr1qdfrB.js.map → Collection-D3K_bEJN.js.map} +1 -1
- package/dist/chunks/{Collection-B8r3o6bK.js → Collection-DpUI5_9f.js} +2 -2
- package/dist/chunks/{Collection-B8r3o6bK.js.map → Collection-DpUI5_9f.js.map} +1 -1
- package/dist/chunks/{ContextMenu-DXtMvkaN.js → ContextMenu-BSlbXHBy.js} +2 -2
- package/dist/chunks/{ContextMenu-DXtMvkaN.js.map → ContextMenu-BSlbXHBy.js.map} +1 -1
- package/dist/chunks/{ContextMenu-Bu4Sw_GS.js → ContextMenu-sdxDECHa.js} +3 -3
- package/dist/chunks/{ContextMenu-Bu4Sw_GS.js.map → ContextMenu-sdxDECHa.js.map} +1 -1
- package/dist/chunks/{DataView-GAorw2F1.js → DataView-CACdHJV9.js} +2 -2
- package/dist/chunks/{DataView-GAorw2F1.js.map → DataView-CACdHJV9.js.map} +1 -1
- package/dist/chunks/{DataView-DhG_EmV-.js → DataView-DUOJRtqo.js} +2 -2
- package/dist/chunks/{DataView-DhG_EmV-.js.map → DataView-DUOJRtqo.js.map} +1 -1
- package/dist/chunks/{Dialog-fb2ecL0p.js → Dialog-BVDLaVFL.js} +5 -5
- package/dist/chunks/{Dialog-fb2ecL0p.js.map → Dialog-BVDLaVFL.js.map} +1 -1
- package/dist/chunks/{Dialog-rbzUvwyM.js → Dialog-BmkbDDol.js} +2 -2
- package/dist/chunks/{Dialog-rbzUvwyM.js.map → Dialog-BmkbDDol.js.map} +1 -1
- package/dist/chunks/{FormView-CI-mS8ei.js → FormView-CqiU2UkE.js} +3 -3
- package/dist/chunks/{FormView-CI-mS8ei.js.map → FormView-CqiU2UkE.js.map} +1 -1
- package/dist/chunks/{FormView-nAFrSOID.js → FormView-Cuqamyp7.js} +3 -3
- package/dist/chunks/{FormView-nAFrSOID.js.map → FormView-Cuqamyp7.js.map} +1 -1
- package/dist/chunks/{ListView-CVdyqY9B.js → ListView-B7_jgGeh.js} +2 -2
- package/dist/chunks/{ListView-CVdyqY9B.js.map → ListView-B7_jgGeh.js.map} +1 -1
- package/dist/chunks/{ListView-Dh9FHFip.js → ListView-ChN3NCAY.js} +3 -3
- package/dist/chunks/{ListView-Dh9FHFip.js.map → ListView-ChN3NCAY.js.map} +1 -1
- package/dist/chunks/{MetricsCountryMapView-CvvZhGXI.js → MetricsCountryMapView-BDdS4s7L.js} +2 -2
- package/dist/chunks/{MetricsCountryMapView-CvvZhGXI.js.map → MetricsCountryMapView-BDdS4s7L.js.map} +1 -1
- package/dist/chunks/{MetricsCountryMapView-qU41DcSP.js → MetricsCountryMapView-Pu1VZIJT.js} +2 -2
- package/dist/chunks/{MetricsCountryMapView-qU41DcSP.js.map → MetricsCountryMapView-Pu1VZIJT.js.map} +1 -1
- package/dist/chunks/{MetricsMiniChartWidget-mKq4dgZs.js → MetricsMiniChartWidget-BVS-pJks.js} +4 -4
- package/dist/chunks/{MetricsMiniChartWidget-mKq4dgZs.js.map → MetricsMiniChartWidget-BVS-pJks.js.map} +1 -1
- package/dist/chunks/{MetricsMiniChartWidget-C7AhQWjP.js → MetricsMiniChartWidget-ZqmLtt06.js} +2 -2
- package/dist/chunks/{MetricsMiniChartWidget-C7AhQWjP.js.map → MetricsMiniChartWidget-ZqmLtt06.js.map} +1 -1
- package/dist/chunks/{PDFViewer-B7nrzZli.js → PDFViewer-Byo3kf7Z.js} +3 -3
- package/dist/chunks/{PDFViewer-B7nrzZli.js.map → PDFViewer-Byo3kf7Z.js.map} +1 -1
- package/dist/chunks/{PDFViewer-Be9x6dIX.js → PDFViewer-CCW5ZvRb.js} +2 -2
- package/dist/chunks/{PDFViewer-Be9x6dIX.js.map → PDFViewer-CCW5ZvRb.js.map} +1 -1
- package/dist/chunks/Rest-BSz7rF0G.js +2 -0
- package/dist/chunks/Rest-BSz7rF0G.js.map +1 -0
- package/dist/chunks/{Rest-Bq0Qmce8.js → Rest-DSzjaYYe.js} +60 -15
- package/dist/chunks/Rest-DSzjaYYe.js.map +1 -0
- package/dist/chunks/{TokenManager-BJ92Oaf0.js → TokenManager-C07o8g1O.js} +2 -2
- package/dist/chunks/{TokenManager-BJ92Oaf0.js.map → TokenManager-C07o8g1O.js.map} +1 -1
- package/dist/chunks/{TokenManager-DHm_MUpV.js → TokenManager-DNwuLDw6.js} +5 -5
- package/dist/chunks/{TokenManager-DHm_MUpV.js.map → TokenManager-DNwuLDw6.js.map} +1 -1
- package/dist/chunks/{WebApp-BgKy6_WI.js → WebApp-1HetrsR0.js} +2 -2
- package/dist/chunks/{WebApp-BgKy6_WI.js.map → WebApp-1HetrsR0.js.map} +1 -1
- package/dist/chunks/{WebApp-YAw6Prrk.js → WebApp-Do2IaAGx.js} +12 -12
- package/dist/chunks/{WebApp-YAw6Prrk.js.map → WebApp-Do2IaAGx.js.map} +1 -1
- package/dist/chunks/{WebSocketClient-eCM6D3qg.js → WebSocketClient-BlBSBvYP.js} +2 -2
- package/dist/chunks/{WebSocketClient-eCM6D3qg.js.map → WebSocketClient-BlBSBvYP.js.map} +1 -1
- package/dist/chunks/{WebSocketClient-D4xOzuC5.js → WebSocketClient-BvwLDqeR.js} +2 -2
- package/dist/chunks/{WebSocketClient-D4xOzuC5.js.map → WebSocketClient-BvwLDqeR.js.map} +1 -1
- package/dist/chunks/{version-D9rXuJAi.js → version-DXeLxR_3.js} +4 -4
- package/dist/chunks/{version-D9rXuJAi.js.map → version-DXeLxR_3.js.map} +1 -1
- package/dist/chunks/{version-BiGS3nz0.js → version-e7n3DAiW.js} +2 -2
- package/dist/chunks/{version-BiGS3nz0.js.map → version-e7n3DAiW.js.map} +1 -1
- package/dist/docit.cjs.js +1 -1
- package/dist/docit.es.js +6 -6
- package/dist/index.cjs.js +1 -1
- package/dist/index.cjs.js.map +1 -1
- package/dist/index.es.js +70 -17
- package/dist/index.es.js.map +1 -1
- package/dist/lightbox.cjs.js +1 -1
- package/dist/lightbox.es.js +5 -5
- package/dist/map.cjs.js +1 -1
- package/dist/map.es.js +5 -5
- package/dist/timeline.cjs.js +1 -1
- package/dist/timeline.es.js +4 -4
- package/dist/web-mojo.lite.css +154 -0
- package/dist/web-mojo.lite.iife.js +21760 -0
- package/dist/web-mojo.lite.iife.js.map +1 -0
- package/dist/web-mojo.lite.iife.min.js +1765 -0
- package/dist/web-mojo.lite.iife.min.js.map +1 -0
- package/package.json +4 -3
- package/dist/chunks/Rest-Bq0Qmce8.js.map +0 -1
- package/dist/chunks/Rest-CpEc4pkD.js +0 -2
- package/dist/chunks/Rest-CpEc4pkD.js.map +0 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Rest-CpEc4pkD.js");class Dialog extends e.View{static _openDialogs=[];static _baseZIndex={backdrop:1050,modal:1055};static getFullscreenAwareZIndex(){return document.querySelector(".table-fullscreen")?{backdrop:10040,modal:10050}:this._baseZIndex}static _busyIndicator=null;static _busyCounter=0;static _busyTimeout=null;static fixAllBackdropStacking(){const e=document.querySelectorAll(".modal-backdrop"),t=Dialog._openDialogs;if(0===e.length||0===t.length)return;const i=[...t].sort((e,t)=>(e._dialogZIndex||0)-(t._dialogZIndex||0));e.forEach((e,t)=>{if(t<i.length){const o=i[t]._dialogZIndex-5;e.style.zIndex=o;const s=document.querySelector(".table-fullscreen")||document.body;e.parentNode!==s&&s.appendChild(e)}})}static updateAllBackdropStacking(){Dialog.fixAllBackdropStacking()}static showBusy(e={}){const{timeout:t=3e4,message:i="Loading..."}=e;if(this._busyCounter++,1===this._busyCounter){if(this._busyTimeout&&clearTimeout(this._busyTimeout),!this._busyIndicator){const e=this.getFullscreenAwareZIndex().modal+1e3;this._busyIndicator=document.createElement("div"),this._busyIndicator.className="mojo-busy-indicator",this._busyIndicator.innerHTML=`\n <div class="mojo-busy-spinner">\n <div class="spinner-border text-light" role="status">\n <span class="visually-hidden">Loading...</span>\n </div>\n <p class="mojo-busy-message mt-3 text-light">${i}</p>\n </div>\n <style>\n .mojo-busy-indicator {\n position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;\n background-color: rgba(0, 0, 0, 0.5); z-index: ${e};\n display: flex; align-items: center; justify-content: center;\n opacity: 0; transition: opacity 0.15s linear;\n }\n .mojo-busy-indicator.show { opacity: 1; }\n .mojo-busy-spinner .spinner-border { width: 3rem; height: 3rem; }\n </style>\n `,document.body.appendChild(this._busyIndicator)}const e=this._busyIndicator.querySelector(".mojo-busy-message");e&&(e.textContent=i),setTimeout(()=>this._busyIndicator.classList.add("show"),10),this._busyTimeout=setTimeout(()=>{console.error("Busy indicator timed out."),this.hideBusy(!0),this.alert({title:"Operation Timed Out",message:"The operation took too long. Please check your connection and try again.",type:"danger"})},t)}}static hideBusy(e=!1){e?this._busyCounter=0:this._busyCounter--,this._busyCounter<=0&&(this._busyCounter=0,this._busyTimeout&&(clearTimeout(this._busyTimeout),this._busyTimeout=null),this._busyIndicator&&(this._busyIndicator.classList.remove("show"),setTimeout(()=>{this._busyIndicator&&0===this._busyCounter&&(this._busyIndicator.remove(),this._busyIndicator=null)},150)))}constructor(e={}){const t=e.id||`modal-${Date.now()}`;super({...e,id:t,tagName:"div",className:`modal ${!1!==e.fade?"fade":""} ${e.className||""}`,attributes:{tabindex:"-1","aria-hidden":"true","aria-labelledby":e.labelledBy||`${t}-label`,"aria-describedby":e.describedBy||null,...e.attributes}}),this.modalId=t,this.title=e.title||"",this.titleId=`${this.modalId}-label`,this.size=e.size||"",this.centered=void 0!==e.centered&&e.centered,this.scrollable=void 0!==e.scrollable&&e.scrollable,this.autoSize=e.autoSize||"auto"===e.size,this.backdrop=void 0===e.backdrop||e.backdrop,this.keyboard=void 0===e.keyboard||e.keyboard,this.focus=void 0===e.focus||e.focus,this.header=void 0===e.header||e.header,this.headerContent=e.headerContent||null,this.headerView=null,this.closeButton=void 0===e.closeButton||e.closeButton,this.contextMenu=e.contextMenu||null,this._processHeaderContent(this.headerContent),this.body=e.body||e.content||"",this.bodyView=null,this.bodyClass=e.bodyClass||"",this.noBodyPadding=e.noBodyPadding||!1,this.minWidth=e.minWidth||300,this.minHeight=e.minHeight||200,e.maxHeight&&(this.maxHeight=e.maxHeight),this.maxWidthPercent=e.maxWidthPercent||.9,this.maxHeightPercent=e.maxHeightPercent||.8,this._processBodyContent(this.body),this.footer=e.footer||null,this.footerView=null,this.footerClass=e.footerClass||"",this._processFooterContent(this.footer),this.buttons=e.buttons||null,this.onShow=e.onShow||null,this.onShown=e.onShown||null,this.onHide=e.onHide||null,this.onHidden=e.onHidden||null,this.onHidePrevented=e.onHidePrevented||null,this.autoShow=void 0!==e.autoShow&&e.autoShow,this.modal=null,this.relatedTarget=e.relatedTarget||null}_processBodyContent(t){if(t&&t.render)this.bodyView=t,this.body="",this.addChild(this.bodyView);else if("function"==typeof t)try{const i=t();i instanceof e.View?(this.bodyView=i,this.body="",this.addChild(this.bodyView)):i instanceof Promise?(this.bodyPromise=i,this.body='<div class="text-center"><div class="spinner-border spinner-border-sm"></div></div>'):this.body=i}catch(i){console.error("Error processing body function:",i),this.body=t}else this.body=t}_processHeaderContent(t){if(t instanceof e.View)this.headerView=t,this.headerContent=null,this.addChild(this.headerView);else if("function"==typeof t)try{const i=t();i instanceof e.View?(this.headerView=i,this.headerContent=null,this.addChild(this.headerView)):i instanceof Promise?(this.headerPromise=i,this.headerContent='<div class="text-center"><div class="spinner-border spinner-border-sm"></div></div>'):this.headerContent=i}catch(i){console.error("Error processing headerContent function:",i),this.headerContent=t}else this.headerContent=t}_processFooterContent(t){if(t instanceof e.View)this.footerView=t,this.footer=null,this.addChild(this.footerView);else if("function"==typeof t)try{const i=t();i instanceof e.View?(this.footerView=i,this.footer=null,this.addChild(this.footerView)):i instanceof Promise?(this.footerPromise=i,this.footer='<div class="text-center"><div class="spinner-border spinner-border-sm"></div></div>'):this.footer=i}catch(i){console.error("Error processing footer function:",i),this.footer=t}else this.footer=t}async getTemplate(){const e=["modal-dialog"];return this.size&&"auto"!==this.size&&(this.size.startsWith("fullscreen")?e.push(`modal-${this.size}`):["sm","lg","xl","xxl"].includes(this.size)&&(e.push(`modal-${this.size}`),["lg","xl","xxl"].includes(this.size)&&e.push("modal-fullscreen-sm-down"))),this.centered&&e.push("modal-dialog-centered"),this.scrollable&&(this.maxHeight?e.push("overflow-hidden"):e.push("modal-dialog-scrollable")),`\n <div class="${e.join(" ")}">\n <div class="modal-content">\n ${await this.buildHeader()}\n ${await this.buildBody()}\n ${await this.buildFooter()}\n </div>\n </div>\n `}async buildHeader(){if(!this.header)return"";if(this.headerView)return this.headerView.replaceById=!0,`<div class="modal-header" data-view-container="header">\n \x3c!-- View will be mounted here --\x3e\n <div id="${this.headerView.id}"></div>\n </div>`;if(this.headerContent)return`<div class="modal-header">${this.headerContent}</div>`;let e="";return this.contextMenu&&this.contextMenu.items&&this.contextMenu.items.length>0?e=await this.buildContextMenu():this.closeButton&&(e='<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>'),`\n <div class="modal-header">\n ${this.title?`<h5 class="modal-title" id="${this.titleId}">${this.title}</h5>`:""}\n ${e}\n </div>\n `}async buildContextMenu(){const e=await this.filterContextMenuItems();if(0===e.length)return this.closeButton?'<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>':"";const t=this.contextMenu.icon||"bi-three-dots-vertical";return`\n <div class="dropdown">\n <button class="${this.contextMenu.buttonClass||"btn btn-link p-1 mojo-modal-context-menu-btn"}" type="button" data-bs-toggle="dropdown" aria-expanded="false">\n <i class="${t}"></i>\n </button>\n <ul class="dropdown-menu dropdown-menu-end">\n ${e.map(e=>{if("divider"===e.type)return'<li><hr class="dropdown-divider"></li>';const t=e.icon?`<i class="${e.icon} me-2"></i>`:"",i=e.label||"";if(e.href)return`<li><a class="dropdown-item" href="${e.href}"${e.target?` target="${e.target}"`:""}>${t}${i}</a></li>`;if(e.action){const o=Object.keys(e).filter(e=>e.startsWith("data-")).map(t=>`${t}="${e[t]}"`).join(" ");return`<li><a class="dropdown-item" data-action="${e.action}" ${o}>${t}${i}</a></li>`}return""}).join("")}\n </ul>\n </div>\n `}async filterContextMenuItems(){if(!this.contextMenu||!this.contextMenu.items)return[];const e=[];for(const o of this.contextMenu.items)if("divider"!==o.type){if(o.permissions)try{const e=this.getApp?.();let i=null;if(e&&(i=e.activeUser||e.getState?.("activeUser")),!i&&"undefined"!=typeof window&&window.getApp)try{const e=window.getApp();i=e?.activeUser}catch(t){}if(!i||!i.hasPermission)continue;if(!i.hasPermission(o.permissions))continue}catch(i){console.warn("Error checking permissions for context menu item:",i);continue}e.push(o)}else e.push(o);return e}async buildBody(){return this.bodyView?(this.bodyView.replaceById=!0,`<div class="${this.noBodyPadding?`modal-body p-0 ${this.bodyClass}`:`modal-body ${this.bodyClass}`}" data-view-container="body">\n \x3c!-- View will be mounted here --\x3e\n <div id="${this.bodyView.id}"></div>\n </div>`):this.body||""===this.body?`\n <div class="${this.noBodyPadding?`modal-body p-0 ${this.bodyClass}`:`modal-body ${this.bodyClass}`}">\n ${this.body}\n </div>\n `:""}async buildFooter(){if(this.footerView)return`<div class="modal-footer ${this.footerClass}" data-view-container="footer"></div>`;if(null!==this.footer&&"string"==typeof this.footer)return`<div class="modal-footer ${this.footerClass}">${this.footer}</div>`;if(this.buttons&&this.buttons.length>0){const e=this.buttons.map(e=>{const t=e.dismiss?'data-bs-dismiss="modal"':"",i=e.action?`data-action="${e.action}"`:"",o=e.id?`id="${e.id}"`:"",s=e.disabled?"disabled":"";return`\n <button type="${e.type||"button"}"\n class="btn ${e.class||"btn-secondary"}"\n ${o}\n ${t}\n ${i}\n ${s}>\n ${e.icon?`<i class="bi ${e.icon} me-1"></i>`:""}\n ${e.text||"Button"}\n </button>\n `}).join("");return`<div class="modal-footer ${this.footerClass}">${e}</div>`}return""}async mount(e=null){if(!this.mounted&&!this.destroyed){if(!this.element)throw new Error("Cannot mount dialog without element");return await this.onBeforeMount(),(document.querySelector(".table-fullscreen")||document.body).appendChild(this.element),this.bindEvents(),this.mounted=!0,await this.onAfterMount(),this.emit("mounted",{view:this}),this}}async onAfterRender(){if(await super.onAfterRender(),window.Prism&&this.element&&this.element.querySelectorAll("pre code").length>0&&window.Prism.highlightAllUnder(this.element),this.autoSize)this.setupAutoSizing();else if(this.maxHeight){const e=this.element.querySelector(".modal-body");e&&(e.style.maxHeight=`${this.maxHeight}px`)}}async onAfterMount(){await super.onAfterMount(),"undefined"!=typeof window&&window.bootstrap&&window.bootstrap.Modal&&("static"===this.backdrop&&this.element.setAttribute("data-bs-backdrop","static"),this.keyboard||this.element.setAttribute("data-bs-keyboard","false"),this.modal=new window.bootstrap.Modal(this.element,{backdrop:this.backdrop,keyboard:this.keyboard,focus:this.focus}),this.bindBootstrapEvents(),this.autoShow&&this.show(this.relatedTarget))}setupAutoSizing(){this.element&&(this.element.addEventListener("shown.bs.modal",()=>{this.applyAutoSizing()},{once:!0}),setTimeout(()=>{this.isShown()&&this.applyAutoSizing()},100))}applyAutoSizing(){if(this.element)try{const e=this.element.querySelector(".modal-dialog"),t=this.element.querySelector(".modal-content"),i=this.element.querySelector(".modal-body");if(!e||!t||!i)return void console.warn("Dialog auto-sizing: Required elements not found");if(this.bodyView&&!this.bodyView.element)return void setTimeout(()=>this.applyAutoSizing(),50);const o={dialogMaxWidth:e.style.maxWidth,dialogWidth:e.style.width,contentWidth:t.style.width,contentMaxHeight:t.style.maxHeight,hadScrollableClass:e.classList.contains("modal-dialog-scrollable")};e.style.maxWidth="none",e.style.width="auto",t.style.width="auto",t.style.maxHeight="none",t.offsetHeight;const s=t.getBoundingClientRect(),n=40,a=Math.min(window.innerWidth*this.maxWidthPercent,window.innerWidth-n);let l=Math.min(window.innerHeight*this.maxHeightPercent,window.innerHeight-n),r=Math.max(this.minWidth,Math.ceil(s.width+20)),d=Math.max(this.minHeight,Math.ceil(s.height));this.maxHeight&&(l=Math.min(this.maxHeight,l),e.style.maxHeight=`${l}px`),r=Math.min(r,a);const c=s.height>l;e.style.maxWidth=`${r}px`,e.style.width=`${r}px`,c&&(e.classList.contains("modal-dialog-scrollable")||e.classList.add("modal-dialog-scrollable"),t.style.maxHeight=`${l}px`,d=l),this.autoSizedWidth=r,this.autoSizedHeight=d,this._originalStyles=o}catch(e){console.error("Error in dialog auto-sizing:",e),this.element.querySelector(".modal-dialog").style.maxWidth=""}}resetAutoSizing(){if(this.autoSize&&this._originalStyles&&this.element)try{const e=this.element.querySelector(".modal-dialog"),t=this.element.querySelector(".modal-content"),i=this.element.querySelector(".modal-body");e&&t&&i&&(e.style.maxWidth=this._originalStyles.dialogMaxWidth||"",e.style.width=this._originalStyles.dialogWidth||"",t.style.width=this._originalStyles.contentWidth||"",t.style.maxHeight=this._originalStyles.contentMaxHeight||"",!this._originalStyles.hadScrollableClass&&e.classList.contains("modal-dialog-scrollable")&&e.classList.remove("modal-dialog-scrollable"),delete this.autoSizedWidth,delete this.autoSizedHeight,delete this._originalStyles)}catch(e){console.error("Error resetting dialog auto-sizing:",e)}}bindBootstrapEvents(){this.element.addEventListener("show.bs.modal",e=>{const t=Dialog._openDialogs.length,i=Dialog.getFullscreenAwareZIndex().modal+20*t;this.element.style.zIndex=i,this._dialogZIndex=i,this._backdropZIndex=i-10,Dialog._openDialogs.push(this),this.onShow&&this.onShow(e),this.emit("show",{dialog:this,relatedTarget:e.relatedTarget})}),this.element.addEventListener("shown.bs.modal",e=>{if(setTimeout(()=>{Dialog.fixAllBackdropStacking()},50),this.onShown&&this.onShown(e),this.emit("shown",{dialog:this,relatedTarget:e.relatedTarget}),this.focus){const e=this.element.querySelector('input:not([type="hidden"]), textarea, select');e&&e.focus()}}),this.element.addEventListener("hide.bs.modal",e=>{const t=this.element.querySelector(":focus");t&&t.blur(),this.onHide&&!1===this.onHide(e)?e.preventDefault():this.emit("hide",{dialog:this})}),this.element.addEventListener("hidden.bs.modal",e=>{const t=Dialog._openDialogs.indexOf(this);t>-1&&Dialog._openDialogs.splice(t,1),Dialog._openDialogs.length>0&&(document.body.classList.add("modal-open"),setTimeout(()=>{Dialog.fixAllBackdropStacking()},50)),this.previousFocus&&document.body.contains(this.previousFocus)&&this.previousFocus.focus(),this.onHidden&&this.onHidden(e),this.emit("hidden",{dialog:this})}),this.element.addEventListener("hidePrevented.bs.modal",e=>{this.onHidePrevented&&this.onHidePrevented(e),this.emit("hidePrevented",{dialog:this})})}show(e=null){this.previousFocus=document.activeElement,window.lastDialog=this,this.modal&&this.modal.show(e)}hide(){const e=this.element?.querySelector(":focus");e&&e.blur(),this.modal&&this.modal.hide()}toggle(e=null){this.modal&&this.modal.toggle(e)}async destroy(){if(this.modal){const e=this.element?.querySelector(":focus");e&&e.blur(),this.modal.dispose(),this.modal=null}this.previousFocus&&document.body.contains(this.previousFocus)&&(this.previousFocus.focus(),this.previousFocus=null),this.autoSize&&this.resetAutoSizing(),await super.destroy()}handleUpdate(){this.modal&&this.modal.handleUpdate()}async setContent(t){if(t instanceof e.View){this.bodyView&&(await this.bodyView.destroy(),this.removeChild(this.bodyView)),this.bodyView=t,this.body="",this.addChild(this.bodyView);const e=this.element?.querySelector(".modal-body");e&&(e.innerHTML="",await this.bodyView.render(e))}else{this.body=t;const e=this.element?.querySelector(".modal-body");e&&(e.innerHTML=t)}this.handleUpdate()}setTitle(e){this.title=e;const t=this.element?.querySelector(".modal-title");t&&(t.textContent=e)}setLoading(e=!0,t="Loading..."){const i=this.element?.querySelector(".modal-body");i&&(e?i.innerHTML=`\n <div class="text-center py-4">\n <div class="spinner-border text-primary mb-3" role="status">\n <span class="visually-hidden">Loading...</span>\n </div>\n <p>${t}</p>\n </div>\n `:this.bodyView&&i.replaceChildren(this.bodyView.element))}async onBeforeDestroy(){this.headerView&&await this.headerView.destroy(),this.bodyView&&await this.bodyView.destroy(),this.footerView&&await this.footerView.destroy(),await super.onBeforeDestroy(),this.modal&&(this.modal.dispose(),this.modal=null)}static async showCode(e={}){const t=new Dialog({title:e.title||"Source Code",size:e.size||"lg",scrollable:!0,body:Dialog.formatCode(e.code,e.language),buttons:[{text:"Copy to Clipboard",class:"btn-primary",icon:"bi-clipboard",action:"copy"},{text:"Close",class:"btn-secondary",dismiss:!0}]});t.on("action:copy",async()=>{if(navigator.clipboard)try{await navigator.clipboard.writeText(e.code),t.showCopySuccess()}catch(i){console.error("Failed to copy:",i)}});const i=document.querySelector(".table-fullscreen")||document.body;return await t.render(!0,i),window.Prism&&t.element&&window.Prism.highlightAllUnder(t.element),t.show(),t.on("hidden",()=>{t.destroy(),t.element.remove()}),t}static formatCode(e,t="javascript"){let i;i=window.Prism&&window.Prism.languages[t]?window.Prism.highlight(e,window.Prism.languages[t],t):e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'");const o=window.Prism?`language-${t}`:"";return`\n <style>\n /* Custom Prism theme overrides for Dialog */\n .dialog-code-block .token.comment { color: #6a9955; }\n .dialog-code-block .token.string { color: #ce9178; }\n .dialog-code-block .token.keyword { color: #569cd6; }\n .dialog-code-block .token.function { color: #dcdcaa; }\n .dialog-code-block .token.number { color: #b5cea8; }\n .dialog-code-block .token.operator { color: #d4d4d4; }\n .dialog-code-block .token.class-name { color: #4ec9b0; }\n .dialog-code-block .token.punctuation { color: #d4d4d4; }\n .dialog-code-block .token.boolean { color: #569cd6; }\n .dialog-code-block .token.property { color: #9cdcfe; }\n .dialog-code-block .token.tag { color: #569cd6; }\n .dialog-code-block .token.attr-name { color: #9cdcfe; }\n .dialog-code-block .token.attr-value { color: #ce9178; }\n .dialog-code-block ::selection { background: #264f78; }\n </style>\n <pre class="${o} dialog-code-block" style="${"\n max-height: 60vh;\n overflow-y: auto;\n background: #1e1e1e;\n color: #d4d4d4;\n padding: 1.25rem;\n border-radius: 0.5rem;\n margin: 0;\n font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', 'Monaco', monospace;\n font-size: 0.9rem;\n line-height: 1.6;\n border: 1px solid #2d2d30;\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);\n ".replace(/\s+/g," ").trim()}">\n <code class="${o}" style="color: inherit; background: transparent; text-shadow: none;">${i}</code>\n </pre>\n `}static highlightCodeBlocks(e=document){window.Prism&&window.Prism.highlightAllUnder&&window.Prism.highlightAllUnder(e)}showCopySuccess(){const e=this.element.querySelector('[data-action="copy"]');if(e){const t=e.innerHTML;e.innerHTML='<i class="bi bi-check me-1"></i>Copied!',e.classList.remove("btn-primary"),e.classList.add("btn-success"),e.disabled=!0,setTimeout(()=>{e.innerHTML=t,e.classList.remove("btn-success"),e.classList.add("btn-primary"),e.disabled=!1},2e3)}}static async showHtmlPreview(e={}){const t=e.html||e.content||"",i=e.title||"HTML Preview",o=e.size||"lg",s=e.height||500,n=new Dialog({title:i,size:o,scrollable:!1,body:`\n <div class="html-preview-container">\n <div class="d-flex justify-content-between align-items-center mb-2">\n <small class="text-muted">Preview (sandboxed)</small>\n <button type="button" class="btn btn-sm btn-outline-secondary" data-action="refresh-preview">\n <i class="bi bi-arrow-clockwise"></i> Refresh\n </button>\n </div>\n <iframe \n id="html-preview-frame"\n class="border rounded w-100" \n style="height: ${s}px; background: white;"\n sandbox="allow-same-origin"\n frameborder="0"\n ></iframe>\n </div>\n `,buttons:[{text:"Close",class:"btn-secondary",dismiss:!0}]});n.on("action:refresh-preview",async e=>{const i=n.element.querySelector("#html-preview-frame");if(!i)return;const o=i.contentDocument||i.contentWindow.document;o.open(),o.write(t),o.close()});const a=document.querySelector(".table-fullscreen")||document.body;await n.render(!0,a);const l=n.element.querySelector("#html-preview-frame");if(l){const e=l.contentDocument||l.contentWindow.document;e.open(),e.write(t),e.close()}return n.show(),n.on("hidden",()=>{n.destroy(),n.element.remove()}),n}static async showDialog(e={}){"string"==typeof e&&(e={...arguments[2]||{},body:arguments[0],title:arguments[1]||"Alert"});const{title:t="Dialog",content:i,body:o=i||"",size:s="md",centered:n=!0,buttons:a=[{text:"OK",class:"btn-primary",value:!0}],rejectOnDismiss:l=!1,...r}=e,d=new Dialog({title:t,body:o,size:s,centered:n,buttons:a,...r}),c=document.querySelector(".table-fullscreen")||document.body;return await d.render(!0,c),new Promise((e,t)=>{let i=!1;d.element.querySelectorAll(".modal-footer button").forEach((t,o)=>{const s=a[o];s&&t.addEventListener("click",async t=>{if(i)return;const n=void 0!==s.value?s.value:s.action??o;if("function"==typeof s.handler)try{const a=await s.handler({dialog:d,button:s,index:o,event:t});if(null===a||!1===a)return;const l=!0===a||void 0===a?n:a;i=!0,s.dismiss||d.hide(),e(l)}catch(a){return void console.error("Dialog button handler error:",a)}else i=!0,s.dismiss||d.hide(),e(n)})}),d.on("hidden",()=>{i||(i=!0,l?t(new Error("Dialog dismissed")):e(null)),setTimeout(()=>{d.destroy(),d.element.remove()},100)}),d.show()})}static async alert(e={}){"string"==typeof e&&(e={message:e,title:"Alert"});const{message:t="",title:i="Alert",type:o="info",...s}=e;let n="",a="";switch(o){case"success":n='<i class="bi bi-check-circle-fill text-success me-2"></i>',a="text-success";break;case"warning":n='<i class="bi bi-exclamation-triangle-fill text-warning me-2"></i>',a="text-warning";break;case"danger":case"error":n='<i class="bi bi-x-circle-fill text-danger me-2"></i>',a="text-danger";break;default:n='<i class="bi bi-info-circle-fill text-info me-2"></i>',a="text-info"}return Dialog.showDialog({title:`<span class="${a}">${n}${i}</span>`,body:`<p>${t}</p>`,size:"sm",centered:!0,buttons:[{text:"OK",class:"btn-primary",value:!0}],...s})}static async confirm(e,t="Confirm",i={}){"object"==typeof e&&(e=(i=e).message,t=i.title||t);const o=new Dialog({title:t,body:`<p>${e}</p>`,size:i.size||"sm",centered:!0,backdrop:"static",buttons:[{text:i.cancelText||"Cancel",class:"btn-secondary",dismiss:!0,action:"cancel"},{text:i.confirmText||"Confirm",class:i.confirmClass||"btn-primary",action:"confirm"}],...i}),s=document.querySelector(".table-fullscreen")||document.body;return await o.render(!0,s),o.show(),new Promise(e=>{let t=!1;o.on("action:confirm",()=>{t=!0,o.hide()}),o.on("hidden",()=>{o.destroy(),o.element.remove(),e(t)})})}static async prompt(e,t="Input",i={}){const o=`prompt-input-${Date.now()}`,s=i.defaultValue||"",n=i.inputType||"text",a=i.placeholder||"",l=new Dialog({title:t,body:`\n <p>${e}</p>\n <input type="${n}"\n class="form-control"\n id="${o}"\n value="${s}"\n placeholder="${a}">\n `,size:i.size||"sm",centered:!0,backdrop:"static",buttons:[{text:"Cancel",class:"btn-secondary",dismiss:!0},{text:"OK",class:"btn-primary",action:"ok"}],...i}),r=document.querySelector(".table-fullscreen")||document.body;return await l.render(!0,r),l.show(),l.on("shown",()=>{const e=l.element.querySelector(`#${o}`);e&&(e.focus(),e.select())}),new Promise(e=>{let t=null;l.on("action:ok",()=>{const e=l.element.querySelector(`#${o}`);t=e?e.value:null,l.hide()}),l.on("hidden",()=>{l.destroy(),l.element.remove(),e(t)})})}getModal(){return this.modal}isShown(){return this.element?.classList.contains("show")||!1}static async showForm(e={}){const{title:t="Form",formConfig:i={},size:o="md",centered:s=!0,submitText:n="Submit",cancelText:a="Cancel",...l}=e,r=new(0,(await Promise.resolve().then(()=>require("./FormView-CI-mS8ei.js")).then(e=>e.FormView$1)).default)({fileHandling:e.fileHandling||"base64",data:e.data,defaults:e.defaults,model:e.model,formConfig:{fields:i.fields||e.fields,...i,submitButton:!1,resetButton:!1}}),d=new Dialog({title:t,body:r,size:o,centered:s,buttons:[{text:a,class:"btn-secondary",action:"cancel"},{text:n,class:"btn-primary",action:"submit"}],...l}),c=document.querySelector(".table-fullscreen")||document.body;return await d.render(!0,c),d.show(),new Promise(t=>{let i=!1;d.on("action:submit",async()=>{if(!i)if(r.validate()){if(e.autoSave&&e.model){d.setLoading(!0);const e=await r.saveModel();if(!e.success)return d.setLoading(!1),d.render(),void d.getApp().toast.error(e.message);i=!0,d.hide(),t(e)}try{const e=await r.getFormData();i=!0,d.hide(),t(e)}catch(o){console.error("Error collecting form data:",o),r.showError("Error collecting form data")}}else r.focusFirstError()}),d.on("action:cancel",()=>{i||(i=!0,d.hide(),t(null))}),d.on("hidden",()=>{i||(i=!0,t(null)),setTimeout(()=>{r.destroy(),d.destroy()},100)})})}static async showModelForm(e={}){const{title:t="Edit",formConfig:i={},size:o="md",centered:s=!0,submitText:n="Save",cancelText:a="Cancel",model:l,fields:r,...d}=e;if(!l)throw new Error("showModelForm requires a model");const c=new(0,(await Promise.resolve().then(()=>require("./FormView-CI-mS8ei.js")).then(e=>e.FormView$1)).default)({fileHandling:e.fileHandling||"base64",model:l,data:e.data,defaults:e.defaults,formConfig:{fields:r||i.fields||[],...i,submitButton:!1,resetButton:!1}}),h=new Dialog({title:t,body:c,size:o,centered:s,buttons:[{text:a,class:"btn-secondary",action:"cancel"},{text:n,class:"btn-primary",action:"submit"}],...d}),u=document.querySelector(".table-fullscreen")||document.body;return await h.render(!0,u),h.show(),new Promise(e=>{let t=!1;h.on("action:submit",async()=>{if(!t){h.setLoading(!0,"Saving...");try{const i=await c.handleSubmit();if(i.success)t=!0,h.hide(),e(i);else{h.setLoading(!1);let e=i.error;i.data&&i.data.error&&(e=i.data.error),h.getApp().toast.error(e)}}catch(i){console.error("Error saving form:",i),await h.setContent(c),c.showError(i.message||"An error occurred while saving")}}}),h.on("action:cancel",()=>{t||(t=!0,h.hide(),e(null))}),h.on("hidden",()=>{t||(t=!0,e(null)),setTimeout(()=>{c.destroy(),h.destroy()},100)})})}static async showData(e={}){const{title:t="Data View",data:i={},model:o=null,fields:s=[],columns:n=2,responsive:a=!0,showEmptyValues:l=!1,emptyValueText:r="—",size:d="lg",centered:c=!0,closeText:h="Close",...u}=e,m=new(0,(await Promise.resolve().then(()=>require("./DataView-GAorw2F1.js"))).default)({data:i,model:o,fields:s,columns:n,responsive:a,showEmptyValues:l,emptyValueText:r}),b=new Dialog({title:t,body:m,size:d,centered:c,buttons:[{text:h,class:"btn-secondary",value:"close"}],...u}),y=document.querySelector(".table-fullscreen")||document.body;return await b.render(!0,y),b.show(),new Promise(e=>{let t=!1;const i=b.element.querySelector(".modal-footer button");i?.addEventListener("click",()=>{t||(t=!0,b.hide(),e(!0))}),b.on("hidden",()=>{t||(t=!0,e(!0)),setTimeout(()=>{m.destroy(),b.destroy(),b.element.remove()},100)}),m.on("field:click",e=>{b.emit("dataview:field:click",e)}),m.on("error",e=>{b.emit("dataview:error",e)})})}}Dialog.showConfirm=Dialog.confirm,Dialog.showError=Dialog.alert,exports.default=Dialog;
|
|
2
|
-
//# sourceMappingURL=Dialog-
|
|
1
|
+
"use strict";Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const e=require("./Rest-BSz7rF0G.js");class Dialog extends e.View{static _openDialogs=[];static _baseZIndex={backdrop:1050,modal:1055};static getFullscreenAwareZIndex(){return document.querySelector(".table-fullscreen")?{backdrop:10040,modal:10050}:this._baseZIndex}static _busyIndicator=null;static _busyCounter=0;static _busyTimeout=null;static fixAllBackdropStacking(){const e=document.querySelectorAll(".modal-backdrop"),t=Dialog._openDialogs;if(0===e.length||0===t.length)return;const i=[...t].sort((e,t)=>(e._dialogZIndex||0)-(t._dialogZIndex||0));e.forEach((e,t)=>{if(t<i.length){const o=i[t]._dialogZIndex-5;e.style.zIndex=o;const s=document.querySelector(".table-fullscreen")||document.body;e.parentNode!==s&&s.appendChild(e)}})}static updateAllBackdropStacking(){Dialog.fixAllBackdropStacking()}static showBusy(e={}){const{timeout:t=3e4,message:i="Loading..."}=e;if(this._busyCounter++,1===this._busyCounter){if(this._busyTimeout&&clearTimeout(this._busyTimeout),!this._busyIndicator){const e=this.getFullscreenAwareZIndex().modal+1e3;this._busyIndicator=document.createElement("div"),this._busyIndicator.className="mojo-busy-indicator",this._busyIndicator.innerHTML=`\n <div class="mojo-busy-spinner">\n <div class="spinner-border text-light" role="status">\n <span class="visually-hidden">Loading...</span>\n </div>\n <p class="mojo-busy-message mt-3 text-light">${i}</p>\n </div>\n <style>\n .mojo-busy-indicator {\n position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;\n background-color: rgba(0, 0, 0, 0.5); z-index: ${e};\n display: flex; align-items: center; justify-content: center;\n opacity: 0; transition: opacity 0.15s linear;\n }\n .mojo-busy-indicator.show { opacity: 1; }\n .mojo-busy-spinner .spinner-border { width: 3rem; height: 3rem; }\n </style>\n `,document.body.appendChild(this._busyIndicator)}const e=this._busyIndicator.querySelector(".mojo-busy-message");e&&(e.textContent=i),setTimeout(()=>this._busyIndicator.classList.add("show"),10),this._busyTimeout=setTimeout(()=>{console.error("Busy indicator timed out."),this.hideBusy(!0),this.alert({title:"Operation Timed Out",message:"The operation took too long. Please check your connection and try again.",type:"danger"})},t)}}static hideBusy(e=!1){e?this._busyCounter=0:this._busyCounter--,this._busyCounter<=0&&(this._busyCounter=0,this._busyTimeout&&(clearTimeout(this._busyTimeout),this._busyTimeout=null),this._busyIndicator&&(this._busyIndicator.classList.remove("show"),setTimeout(()=>{this._busyIndicator&&0===this._busyCounter&&(this._busyIndicator.remove(),this._busyIndicator=null)},150)))}constructor(e={}){const t=e.id||`modal-${Date.now()}`;super({...e,id:t,tagName:"div",className:`modal ${!1!==e.fade?"fade":""} ${e.className||""}`,attributes:{tabindex:"-1","aria-hidden":"true","aria-labelledby":e.labelledBy||`${t}-label`,"aria-describedby":e.describedBy||null,...e.attributes}}),this.modalId=t,this.title=e.title||"",this.titleId=`${this.modalId}-label`,this.size=e.size||"",this.centered=void 0!==e.centered&&e.centered,this.scrollable=void 0!==e.scrollable&&e.scrollable,this.autoSize=e.autoSize||"auto"===e.size,this.backdrop=void 0===e.backdrop||e.backdrop,this.keyboard=void 0===e.keyboard||e.keyboard,this.focus=void 0===e.focus||e.focus,this.header=void 0===e.header||e.header,this.headerContent=e.headerContent||null,this.headerView=null,this.closeButton=void 0===e.closeButton||e.closeButton,this.contextMenu=e.contextMenu||null,this._processHeaderContent(this.headerContent),this.body=e.body||e.content||"",this.bodyView=null,this.bodyClass=e.bodyClass||"",this.noBodyPadding=e.noBodyPadding||!1,this.minWidth=e.minWidth||300,this.minHeight=e.minHeight||200,e.maxHeight&&(this.maxHeight=e.maxHeight),this.maxWidthPercent=e.maxWidthPercent||.9,this.maxHeightPercent=e.maxHeightPercent||.8,this._processBodyContent(this.body),this.footer=e.footer||null,this.footerView=null,this.footerClass=e.footerClass||"",this._processFooterContent(this.footer),this.buttons=e.buttons||null,this.onShow=e.onShow||null,this.onShown=e.onShown||null,this.onHide=e.onHide||null,this.onHidden=e.onHidden||null,this.onHidePrevented=e.onHidePrevented||null,this.autoShow=void 0!==e.autoShow&&e.autoShow,this.modal=null,this.relatedTarget=e.relatedTarget||null}_processBodyContent(t){if(t&&t.render)this.bodyView=t,this.body="",this.addChild(this.bodyView);else if("function"==typeof t)try{const i=t();i instanceof e.View?(this.bodyView=i,this.body="",this.addChild(this.bodyView)):i instanceof Promise?(this.bodyPromise=i,this.body='<div class="text-center"><div class="spinner-border spinner-border-sm"></div></div>'):this.body=i}catch(i){console.error("Error processing body function:",i),this.body=t}else this.body=t}_processHeaderContent(t){if(t instanceof e.View)this.headerView=t,this.headerContent=null,this.addChild(this.headerView);else if("function"==typeof t)try{const i=t();i instanceof e.View?(this.headerView=i,this.headerContent=null,this.addChild(this.headerView)):i instanceof Promise?(this.headerPromise=i,this.headerContent='<div class="text-center"><div class="spinner-border spinner-border-sm"></div></div>'):this.headerContent=i}catch(i){console.error("Error processing headerContent function:",i),this.headerContent=t}else this.headerContent=t}_processFooterContent(t){if(t instanceof e.View)this.footerView=t,this.footer=null,this.addChild(this.footerView);else if("function"==typeof t)try{const i=t();i instanceof e.View?(this.footerView=i,this.footer=null,this.addChild(this.footerView)):i instanceof Promise?(this.footerPromise=i,this.footer='<div class="text-center"><div class="spinner-border spinner-border-sm"></div></div>'):this.footer=i}catch(i){console.error("Error processing footer function:",i),this.footer=t}else this.footer=t}async getTemplate(){const e=["modal-dialog"];return this.size&&"auto"!==this.size&&(this.size.startsWith("fullscreen")?e.push(`modal-${this.size}`):["sm","lg","xl","xxl"].includes(this.size)&&(e.push(`modal-${this.size}`),["lg","xl","xxl"].includes(this.size)&&e.push("modal-fullscreen-sm-down"))),this.centered&&e.push("modal-dialog-centered"),this.scrollable&&(this.maxHeight?e.push("overflow-hidden"):e.push("modal-dialog-scrollable")),`\n <div class="${e.join(" ")}">\n <div class="modal-content">\n ${await this.buildHeader()}\n ${await this.buildBody()}\n ${await this.buildFooter()}\n </div>\n </div>\n `}async buildHeader(){if(!this.header)return"";if(this.headerView)return this.headerView.replaceById=!0,`<div class="modal-header" data-view-container="header">\n \x3c!-- View will be mounted here --\x3e\n <div id="${this.headerView.id}"></div>\n </div>`;if(this.headerContent)return`<div class="modal-header">${this.headerContent}</div>`;let e="";return this.contextMenu&&this.contextMenu.items&&this.contextMenu.items.length>0?e=await this.buildContextMenu():this.closeButton&&(e='<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>'),`\n <div class="modal-header">\n ${this.title?`<h5 class="modal-title" id="${this.titleId}">${this.title}</h5>`:""}\n ${e}\n </div>\n `}async buildContextMenu(){const e=await this.filterContextMenuItems();if(0===e.length)return this.closeButton?'<button type="button" class="btn-close" data-bs-dismiss="modal" aria-label="Close"></button>':"";const t=this.contextMenu.icon||"bi-three-dots-vertical";return`\n <div class="dropdown">\n <button class="${this.contextMenu.buttonClass||"btn btn-link p-1 mojo-modal-context-menu-btn"}" type="button" data-bs-toggle="dropdown" aria-expanded="false">\n <i class="${t}"></i>\n </button>\n <ul class="dropdown-menu dropdown-menu-end">\n ${e.map(e=>{if("divider"===e.type)return'<li><hr class="dropdown-divider"></li>';const t=e.icon?`<i class="${e.icon} me-2"></i>`:"",i=e.label||"";if(e.href)return`<li><a class="dropdown-item" href="${e.href}"${e.target?` target="${e.target}"`:""}>${t}${i}</a></li>`;if(e.action){const o=Object.keys(e).filter(e=>e.startsWith("data-")).map(t=>`${t}="${e[t]}"`).join(" ");return`<li><a class="dropdown-item" data-action="${e.action}" ${o}>${t}${i}</a></li>`}return""}).join("")}\n </ul>\n </div>\n `}async filterContextMenuItems(){if(!this.contextMenu||!this.contextMenu.items)return[];const e=[];for(const o of this.contextMenu.items)if("divider"!==o.type){if(o.permissions)try{const e=this.getApp?.();let i=null;if(e&&(i=e.activeUser||e.getState?.("activeUser")),!i&&"undefined"!=typeof window&&window.getApp)try{const e=window.getApp();i=e?.activeUser}catch(t){}if(!i||!i.hasPermission)continue;if(!i.hasPermission(o.permissions))continue}catch(i){console.warn("Error checking permissions for context menu item:",i);continue}e.push(o)}else e.push(o);return e}async buildBody(){return this.bodyView?(this.bodyView.replaceById=!0,`<div class="${this.noBodyPadding?`modal-body p-0 ${this.bodyClass}`:`modal-body ${this.bodyClass}`}" data-view-container="body">\n \x3c!-- View will be mounted here --\x3e\n <div id="${this.bodyView.id}"></div>\n </div>`):this.body||""===this.body?`\n <div class="${this.noBodyPadding?`modal-body p-0 ${this.bodyClass}`:`modal-body ${this.bodyClass}`}">\n ${this.body}\n </div>\n `:""}async buildFooter(){if(this.footerView)return`<div class="modal-footer ${this.footerClass}" data-view-container="footer"></div>`;if(null!==this.footer&&"string"==typeof this.footer)return`<div class="modal-footer ${this.footerClass}">${this.footer}</div>`;if(this.buttons&&this.buttons.length>0){const e=this.buttons.map(e=>{const t=e.dismiss?'data-bs-dismiss="modal"':"",i=e.action?`data-action="${e.action}"`:"",o=e.id?`id="${e.id}"`:"",s=e.disabled?"disabled":"";return`\n <button type="${e.type||"button"}"\n class="btn ${e.class||"btn-secondary"}"\n ${o}\n ${t}\n ${i}\n ${s}>\n ${e.icon?`<i class="bi ${e.icon} me-1"></i>`:""}\n ${e.text||"Button"}\n </button>\n `}).join("");return`<div class="modal-footer ${this.footerClass}">${e}</div>`}return""}async mount(e=null){if(!this.mounted&&!this.destroyed){if(!this.element)throw new Error("Cannot mount dialog without element");return await this.onBeforeMount(),(document.querySelector(".table-fullscreen")||document.body).appendChild(this.element),this.bindEvents(),this.mounted=!0,await this.onAfterMount(),this.emit("mounted",{view:this}),this}}async onAfterRender(){if(await super.onAfterRender(),window.Prism&&this.element&&this.element.querySelectorAll("pre code").length>0&&window.Prism.highlightAllUnder(this.element),this.autoSize)this.setupAutoSizing();else if(this.maxHeight){const e=this.element.querySelector(".modal-body");e&&(e.style.maxHeight=`${this.maxHeight}px`)}}async onAfterMount(){await super.onAfterMount(),"undefined"!=typeof window&&window.bootstrap&&window.bootstrap.Modal&&("static"===this.backdrop&&this.element.setAttribute("data-bs-backdrop","static"),this.keyboard||this.element.setAttribute("data-bs-keyboard","false"),this.modal=new window.bootstrap.Modal(this.element,{backdrop:this.backdrop,keyboard:this.keyboard,focus:this.focus}),this.bindBootstrapEvents(),this.autoShow&&this.show(this.relatedTarget))}setupAutoSizing(){this.element&&(this.element.addEventListener("shown.bs.modal",()=>{this.applyAutoSizing()},{once:!0}),setTimeout(()=>{this.isShown()&&this.applyAutoSizing()},100))}applyAutoSizing(){if(this.element)try{const e=this.element.querySelector(".modal-dialog"),t=this.element.querySelector(".modal-content"),i=this.element.querySelector(".modal-body");if(!e||!t||!i)return void console.warn("Dialog auto-sizing: Required elements not found");if(this.bodyView&&!this.bodyView.element)return void setTimeout(()=>this.applyAutoSizing(),50);const o={dialogMaxWidth:e.style.maxWidth,dialogWidth:e.style.width,contentWidth:t.style.width,contentMaxHeight:t.style.maxHeight,hadScrollableClass:e.classList.contains("modal-dialog-scrollable")};e.style.maxWidth="none",e.style.width="auto",t.style.width="auto",t.style.maxHeight="none",t.offsetHeight;const s=t.getBoundingClientRect(),n=40,a=Math.min(window.innerWidth*this.maxWidthPercent,window.innerWidth-n);let l=Math.min(window.innerHeight*this.maxHeightPercent,window.innerHeight-n),r=Math.max(this.minWidth,Math.ceil(s.width+20)),d=Math.max(this.minHeight,Math.ceil(s.height));this.maxHeight&&(l=Math.min(this.maxHeight,l),e.style.maxHeight=`${l}px`),r=Math.min(r,a);const c=s.height>l;e.style.maxWidth=`${r}px`,e.style.width=`${r}px`,c&&(e.classList.contains("modal-dialog-scrollable")||e.classList.add("modal-dialog-scrollable"),t.style.maxHeight=`${l}px`,d=l),this.autoSizedWidth=r,this.autoSizedHeight=d,this._originalStyles=o}catch(e){console.error("Error in dialog auto-sizing:",e),this.element.querySelector(".modal-dialog").style.maxWidth=""}}resetAutoSizing(){if(this.autoSize&&this._originalStyles&&this.element)try{const e=this.element.querySelector(".modal-dialog"),t=this.element.querySelector(".modal-content"),i=this.element.querySelector(".modal-body");e&&t&&i&&(e.style.maxWidth=this._originalStyles.dialogMaxWidth||"",e.style.width=this._originalStyles.dialogWidth||"",t.style.width=this._originalStyles.contentWidth||"",t.style.maxHeight=this._originalStyles.contentMaxHeight||"",!this._originalStyles.hadScrollableClass&&e.classList.contains("modal-dialog-scrollable")&&e.classList.remove("modal-dialog-scrollable"),delete this.autoSizedWidth,delete this.autoSizedHeight,delete this._originalStyles)}catch(e){console.error("Error resetting dialog auto-sizing:",e)}}bindBootstrapEvents(){this.element.addEventListener("show.bs.modal",e=>{const t=Dialog._openDialogs.length,i=Dialog.getFullscreenAwareZIndex().modal+20*t;this.element.style.zIndex=i,this._dialogZIndex=i,this._backdropZIndex=i-10,Dialog._openDialogs.push(this),this.onShow&&this.onShow(e),this.emit("show",{dialog:this,relatedTarget:e.relatedTarget})}),this.element.addEventListener("shown.bs.modal",e=>{if(setTimeout(()=>{Dialog.fixAllBackdropStacking()},50),this.onShown&&this.onShown(e),this.emit("shown",{dialog:this,relatedTarget:e.relatedTarget}),this.focus){const e=this.element.querySelector('input:not([type="hidden"]), textarea, select');e&&e.focus()}}),this.element.addEventListener("hide.bs.modal",e=>{const t=this.element.querySelector(":focus");t&&t.blur(),this.onHide&&!1===this.onHide(e)?e.preventDefault():this.emit("hide",{dialog:this})}),this.element.addEventListener("hidden.bs.modal",e=>{const t=Dialog._openDialogs.indexOf(this);t>-1&&Dialog._openDialogs.splice(t,1),Dialog._openDialogs.length>0&&(document.body.classList.add("modal-open"),setTimeout(()=>{Dialog.fixAllBackdropStacking()},50)),this.previousFocus&&document.body.contains(this.previousFocus)&&this.previousFocus.focus(),this.onHidden&&this.onHidden(e),this.emit("hidden",{dialog:this})}),this.element.addEventListener("hidePrevented.bs.modal",e=>{this.onHidePrevented&&this.onHidePrevented(e),this.emit("hidePrevented",{dialog:this})})}show(e=null){this.previousFocus=document.activeElement,window.lastDialog=this,this.modal&&this.modal.show(e)}hide(){const e=this.element?.querySelector(":focus");e&&e.blur(),this.modal&&this.modal.hide()}toggle(e=null){this.modal&&this.modal.toggle(e)}async destroy(){if(this.modal){const e=this.element?.querySelector(":focus");e&&e.blur(),this.modal.dispose(),this.modal=null}this.previousFocus&&document.body.contains(this.previousFocus)&&(this.previousFocus.focus(),this.previousFocus=null),this.autoSize&&this.resetAutoSizing(),await super.destroy()}handleUpdate(){this.modal&&this.modal.handleUpdate()}async setContent(t){if(t instanceof e.View){this.bodyView&&(await this.bodyView.destroy(),this.removeChild(this.bodyView)),this.bodyView=t,this.body="",this.addChild(this.bodyView);const e=this.element?.querySelector(".modal-body");e&&(e.innerHTML="",await this.bodyView.render(e))}else{this.body=t;const e=this.element?.querySelector(".modal-body");e&&(e.innerHTML=t)}this.handleUpdate()}setTitle(e){this.title=e;const t=this.element?.querySelector(".modal-title");t&&(t.textContent=e)}setLoading(e=!0,t="Loading..."){const i=this.element?.querySelector(".modal-body");i&&(e?i.innerHTML=`\n <div class="text-center py-4">\n <div class="spinner-border text-primary mb-3" role="status">\n <span class="visually-hidden">Loading...</span>\n </div>\n <p>${t}</p>\n </div>\n `:this.bodyView&&i.replaceChildren(this.bodyView.element))}async onBeforeDestroy(){this.headerView&&await this.headerView.destroy(),this.bodyView&&await this.bodyView.destroy(),this.footerView&&await this.footerView.destroy(),await super.onBeforeDestroy(),this.modal&&(this.modal.dispose(),this.modal=null)}static async showCode(e={}){const t=new Dialog({title:e.title||"Source Code",size:e.size||"lg",scrollable:!0,body:Dialog.formatCode(e.code,e.language),buttons:[{text:"Copy to Clipboard",class:"btn-primary",icon:"bi-clipboard",action:"copy"},{text:"Close",class:"btn-secondary",dismiss:!0}]});t.on("action:copy",async()=>{if(navigator.clipboard)try{await navigator.clipboard.writeText(e.code),t.showCopySuccess()}catch(i){console.error("Failed to copy:",i)}});const i=document.querySelector(".table-fullscreen")||document.body;return await t.render(!0,i),window.Prism&&t.element&&window.Prism.highlightAllUnder(t.element),t.show(),t.on("hidden",()=>{t.destroy(),t.element.remove()}),t}static formatCode(e,t="javascript"){let i;i=window.Prism&&window.Prism.languages[t]?window.Prism.highlight(e,window.Prism.languages[t],t):e.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/'/g,"'");const o=window.Prism?`language-${t}`:"";return`\n <style>\n /* Custom Prism theme overrides for Dialog */\n .dialog-code-block .token.comment { color: #6a9955; }\n .dialog-code-block .token.string { color: #ce9178; }\n .dialog-code-block .token.keyword { color: #569cd6; }\n .dialog-code-block .token.function { color: #dcdcaa; }\n .dialog-code-block .token.number { color: #b5cea8; }\n .dialog-code-block .token.operator { color: #d4d4d4; }\n .dialog-code-block .token.class-name { color: #4ec9b0; }\n .dialog-code-block .token.punctuation { color: #d4d4d4; }\n .dialog-code-block .token.boolean { color: #569cd6; }\n .dialog-code-block .token.property { color: #9cdcfe; }\n .dialog-code-block .token.tag { color: #569cd6; }\n .dialog-code-block .token.attr-name { color: #9cdcfe; }\n .dialog-code-block .token.attr-value { color: #ce9178; }\n .dialog-code-block ::selection { background: #264f78; }\n </style>\n <pre class="${o} dialog-code-block" style="${"\n max-height: 60vh;\n overflow-y: auto;\n background: #1e1e1e;\n color: #d4d4d4;\n padding: 1.25rem;\n border-radius: 0.5rem;\n margin: 0;\n font-family: 'Cascadia Code', 'Fira Code', 'JetBrains Mono', 'Consolas', 'Monaco', monospace;\n font-size: 0.9rem;\n line-height: 1.6;\n border: 1px solid #2d2d30;\n box-shadow: 0 4px 6px rgba(0, 0, 0, 0.3);\n ".replace(/\s+/g," ").trim()}">\n <code class="${o}" style="color: inherit; background: transparent; text-shadow: none;">${i}</code>\n </pre>\n `}static highlightCodeBlocks(e=document){window.Prism&&window.Prism.highlightAllUnder&&window.Prism.highlightAllUnder(e)}showCopySuccess(){const e=this.element.querySelector('[data-action="copy"]');if(e){const t=e.innerHTML;e.innerHTML='<i class="bi bi-check me-1"></i>Copied!',e.classList.remove("btn-primary"),e.classList.add("btn-success"),e.disabled=!0,setTimeout(()=>{e.innerHTML=t,e.classList.remove("btn-success"),e.classList.add("btn-primary"),e.disabled=!1},2e3)}}static async showHtmlPreview(e={}){const t=e.html||e.content||"",i=e.title||"HTML Preview",o=e.size||"lg",s=e.height||500,n=new Dialog({title:i,size:o,scrollable:!1,body:`\n <div class="html-preview-container">\n <div class="d-flex justify-content-between align-items-center mb-2">\n <small class="text-muted">Preview (sandboxed)</small>\n <button type="button" class="btn btn-sm btn-outline-secondary" data-action="refresh-preview">\n <i class="bi bi-arrow-clockwise"></i> Refresh\n </button>\n </div>\n <iframe \n id="html-preview-frame"\n class="border rounded w-100" \n style="height: ${s}px; background: white;"\n sandbox="allow-same-origin"\n frameborder="0"\n ></iframe>\n </div>\n `,buttons:[{text:"Close",class:"btn-secondary",dismiss:!0}]});n.on("action:refresh-preview",async e=>{const i=n.element.querySelector("#html-preview-frame");if(!i)return;const o=i.contentDocument||i.contentWindow.document;o.open(),o.write(t),o.close()});const a=document.querySelector(".table-fullscreen")||document.body;await n.render(!0,a);const l=n.element.querySelector("#html-preview-frame");if(l){const e=l.contentDocument||l.contentWindow.document;e.open(),e.write(t),e.close()}return n.show(),n.on("hidden",()=>{n.destroy(),n.element.remove()}),n}static async showDialog(e={}){"string"==typeof e&&(e={...arguments[2]||{},body:arguments[0],title:arguments[1]||"Alert"});const{title:t="Dialog",content:i,body:o=i||"",size:s="md",centered:n=!0,buttons:a=[{text:"OK",class:"btn-primary",value:!0}],rejectOnDismiss:l=!1,...r}=e,d=new Dialog({title:t,body:o,size:s,centered:n,buttons:a,...r}),c=document.querySelector(".table-fullscreen")||document.body;return await d.render(!0,c),new Promise((e,t)=>{let i=!1;d.element.querySelectorAll(".modal-footer button").forEach((t,o)=>{const s=a[o];s&&t.addEventListener("click",async t=>{if(i)return;const n=void 0!==s.value?s.value:s.action??o;if("function"==typeof s.handler)try{const a=await s.handler({dialog:d,button:s,index:o,event:t});if(null===a||!1===a)return;const l=!0===a||void 0===a?n:a;i=!0,s.dismiss||d.hide(),e(l)}catch(a){return void console.error("Dialog button handler error:",a)}else i=!0,s.dismiss||d.hide(),e(n)})}),d.on("hidden",()=>{i||(i=!0,l?t(new Error("Dialog dismissed")):e(null)),setTimeout(()=>{d.destroy(),d.element.remove()},100)}),d.show()})}static async alert(e={}){"string"==typeof e&&(e={message:e,title:"Alert"});const{message:t="",title:i="Alert",type:o="info",...s}=e;let n="",a="";switch(o){case"success":n='<i class="bi bi-check-circle-fill text-success me-2"></i>',a="text-success";break;case"warning":n='<i class="bi bi-exclamation-triangle-fill text-warning me-2"></i>',a="text-warning";break;case"danger":case"error":n='<i class="bi bi-x-circle-fill text-danger me-2"></i>',a="text-danger";break;default:n='<i class="bi bi-info-circle-fill text-info me-2"></i>',a="text-info"}return Dialog.showDialog({title:`<span class="${a}">${n}${i}</span>`,body:`<p>${t}</p>`,size:"sm",centered:!0,buttons:[{text:"OK",class:"btn-primary",value:!0}],...s})}static async confirm(e,t="Confirm",i={}){"object"==typeof e&&(e=(i=e).message,t=i.title||t);const o=new Dialog({title:t,body:`<p>${e}</p>`,size:i.size||"sm",centered:!0,backdrop:"static",buttons:[{text:i.cancelText||"Cancel",class:"btn-secondary",dismiss:!0,action:"cancel"},{text:i.confirmText||"Confirm",class:i.confirmClass||"btn-primary",action:"confirm"}],...i}),s=document.querySelector(".table-fullscreen")||document.body;return await o.render(!0,s),o.show(),new Promise(e=>{let t=!1;o.on("action:confirm",()=>{t=!0,o.hide()}),o.on("hidden",()=>{o.destroy(),o.element.remove(),e(t)})})}static async prompt(e,t="Input",i={}){const o=`prompt-input-${Date.now()}`,s=i.defaultValue||"",n=i.inputType||"text",a=i.placeholder||"",l=new Dialog({title:t,body:`\n <p>${e}</p>\n <input type="${n}"\n class="form-control"\n id="${o}"\n value="${s}"\n placeholder="${a}">\n `,size:i.size||"sm",centered:!0,backdrop:"static",buttons:[{text:"Cancel",class:"btn-secondary",dismiss:!0},{text:"OK",class:"btn-primary",action:"ok"}],...i}),r=document.querySelector(".table-fullscreen")||document.body;return await l.render(!0,r),l.show(),l.on("shown",()=>{const e=l.element.querySelector(`#${o}`);e&&(e.focus(),e.select())}),new Promise(e=>{let t=null;l.on("action:ok",()=>{const e=l.element.querySelector(`#${o}`);t=e?e.value:null,l.hide()}),l.on("hidden",()=>{l.destroy(),l.element.remove(),e(t)})})}getModal(){return this.modal}isShown(){return this.element?.classList.contains("show")||!1}static async showForm(e={}){const{title:t="Form",formConfig:i={},size:o="md",centered:s=!0,submitText:n="Submit",cancelText:a="Cancel",...l}=e,r=new(0,(await Promise.resolve().then(()=>require("./FormView-CqiU2UkE.js")).then(e=>e.FormView$1)).default)({fileHandling:e.fileHandling||"base64",data:e.data,defaults:e.defaults,model:e.model,formConfig:{fields:i.fields||e.fields,...i,submitButton:!1,resetButton:!1}}),d=new Dialog({title:t,body:r,size:o,centered:s,buttons:[{text:a,class:"btn-secondary",action:"cancel"},{text:n,class:"btn-primary",action:"submit"}],...l}),c=document.querySelector(".table-fullscreen")||document.body;return await d.render(!0,c),d.show(),new Promise(t=>{let i=!1;d.on("action:submit",async()=>{if(!i)if(r.validate()){if(e.autoSave&&e.model){d.setLoading(!0);const e=await r.saveModel();if(!e.success)return d.setLoading(!1),d.render(),void d.getApp().toast.error(e.message);i=!0,d.hide(),t(e)}try{const e=await r.getFormData();i=!0,d.hide(),t(e)}catch(o){console.error("Error collecting form data:",o),r.showError("Error collecting form data")}}else r.focusFirstError()}),d.on("action:cancel",()=>{i||(i=!0,d.hide(),t(null))}),d.on("hidden",()=>{i||(i=!0,t(null)),setTimeout(()=>{r.destroy(),d.destroy()},100)})})}static async showModelForm(e={}){const{title:t="Edit",formConfig:i={},size:o="md",centered:s=!0,submitText:n="Save",cancelText:a="Cancel",model:l,fields:r,...d}=e;if(!l)throw new Error("showModelForm requires a model");const c=new(0,(await Promise.resolve().then(()=>require("./FormView-CqiU2UkE.js")).then(e=>e.FormView$1)).default)({fileHandling:e.fileHandling||"base64",model:l,data:e.data,defaults:e.defaults,formConfig:{fields:r||i.fields||[],...i,submitButton:!1,resetButton:!1}}),h=new Dialog({title:t,body:c,size:o,centered:s,buttons:[{text:a,class:"btn-secondary",action:"cancel"},{text:n,class:"btn-primary",action:"submit"}],...d}),u=document.querySelector(".table-fullscreen")||document.body;return await h.render(!0,u),h.show(),new Promise(e=>{let t=!1;h.on("action:submit",async()=>{if(!t){h.setLoading(!0,"Saving...");try{const i=await c.handleSubmit();if(i.success)t=!0,h.hide(),e(i);else{h.setLoading(!1);let e=i.error;i.data&&i.data.error&&(e=i.data.error),h.getApp().toast.error(e)}}catch(i){console.error("Error saving form:",i),await h.setContent(c),c.showError(i.message||"An error occurred while saving")}}}),h.on("action:cancel",()=>{t||(t=!0,h.hide(),e(null))}),h.on("hidden",()=>{t||(t=!0,e(null)),setTimeout(()=>{c.destroy(),h.destroy()},100)})})}static async showData(e={}){const{title:t="Data View",data:i={},model:o=null,fields:s=[],columns:n=2,responsive:a=!0,showEmptyValues:l=!1,emptyValueText:r="—",size:d="lg",centered:c=!0,closeText:h="Close",...u}=e,m=new(0,(await Promise.resolve().then(()=>require("./DataView-CACdHJV9.js"))).default)({data:i,model:o,fields:s,columns:n,responsive:a,showEmptyValues:l,emptyValueText:r}),b=new Dialog({title:t,body:m,size:d,centered:c,buttons:[{text:h,class:"btn-secondary",value:"close"}],...u}),y=document.querySelector(".table-fullscreen")||document.body;return await b.render(!0,y),b.show(),new Promise(e=>{let t=!1;const i=b.element.querySelector(".modal-footer button");i?.addEventListener("click",()=>{t||(t=!0,b.hide(),e(!0))}),b.on("hidden",()=>{t||(t=!0,e(!0)),setTimeout(()=>{m.destroy(),b.destroy(),b.element.remove()},100)}),m.on("field:click",e=>{b.emit("dataview:field:click",e)}),m.on("error",e=>{b.emit("dataview:error",e)})})}}Dialog.showConfirm=Dialog.confirm,Dialog.showError=Dialog.alert,exports.default=Dialog;
|
|
2
|
+
//# sourceMappingURL=Dialog-BmkbDDol.js.map
|