base/dist/base.min.js

2 lines
24 KiB
JavaScript
Raw Normal View History

!function(){"use strict";!function(e){const{Component:t,Util:s,$:a}=e,i={};t.register("Modal",e=>{e.modal=new bootstrap.Modal(e),e.addEventListener("bind",t=>{t.detail?e.modal.show():e.modal.hide()}),e.addEventListener("hide.bs.modal",()=>{var t;null==(t=document.activeElement)||t.blur(),e.dispatchEvent(new CustomEvent("change",{bubbles:!1,detail:!1}))}),s.copyFunction(e,e.modal,"show","hide")},s.makeDom('\n<div class="modal fade" data-bs-backdrop="static">\n <div class="modal-dialog modal-dialog-centered">\n <div $class="modal-content border-${this.state?.type || \'primary\'} border-2 shadow-lg">\n <div slot-id="header" class="modal-header py-2 px-3 bg-light">\n <h6 $class="modal-title fw-bold text-${this.state?.type || \'primary\'}" $text="this.state?.title"></h6>\n <button type="button" class="btn btn-link ms-2 bi bi-x-lg link-reset p-0" style="color:inherit; text-decoration:none" data-bs-dismiss="modal"></button>\n </div>\n <div slot-id="body" class="modal-body p-3"></div>\n <div slot-id="footer" class="modal-footer py-2 px-3 bg-light"></div>\n </div>\n </div>\n</div>\n')),t.register("Dialog",t.getSetupFunction("Modal"),s.makeDom('\n<div class="modal fade" data-bs-backdrop="static">\n <div class="modal-dialog modal-dialog-centered">\n <div $class="modal-content border-${this.state?.type || \'primary\'} border-2 shadow-lg">\n <template $if="this.state?.title">\n <div $class="modal-header py-2 px-3 bg-light fw-bold text-${this.state?.type || \'primary\'}" $text="this.state?.title"></div>\n </template>\n <div slot-id="body" class="modal-body p-4"><div $html="this.state?.message"></div></div>\n <div class="modal-footer py-2 px-3 bg-light">\n <template $each="this.state?.buttons || [\'{#Close#}\']">\n <button type="button" $class="btn btn-sm px-3 btn-${index === (this.state?.buttons || []).length - 1 ? (this.state?.type && this.state?.type !== \'body\' ? this.state?.type : \'primary\') : \'outline-secondary border\'}" $onclick="this.result=index+1;this.hide()" $text="${item}"></button>\n </template>\n </div>\n </div>\n </div>\n</div>\n'));let n=0;i.showDialog=function({title:e="",message:t="",buttons:s=["{#Close#}"],type:a="body"}){const i=document.body.appendChild(document.createElement("Dialog"));return i.style.zIndex=2e3+ ++n,Promise.resolve().then(()=>{Object.assign(i.state,{message:t,title:e,type:a,buttons:s}),i.show()}),new Promise(e=>{i.addEventListener("change",t=>{n--,e(i.result||0),i.remove()})})},i.alert=function(e,t={}){return i.showDialog({message:e,...t})},i.confirm=function(e,t={}){return new Promise(s=>i.showDialog({message:e,buttons:["{#Cancel#}","{#Confirm#}"],...t}).then(e=>s(e>=2)).catch(()=>s(!1)))},t.register("Toast",e=>{e.toast=new bootstrap.Toast(e,{autohide:e.state.delay>0}),s.copyFunction(e,e.toast,"show","hide"),e.addEventListener("show.bs.toast",()=>{if(e.state.delay>0){let t;const s=()=>{e.state.left=e.state.delay/1e3,t=setInterval(()=>{(!e.isConnected||--e.state.left<=0)&&clearInterval(t)},1e3)};s(),e.addEventListener("mouseenter",()=>{clearInterval(t),e.state.left=void 0}),e.addEventListener("mouseleave",s)}})},s.makeDom('\n<div class="toast align-items-center border-0 m-1">\n <div $class="toast-body rounded p-3 text-bg-${this.state?.type}">\n <div class="d-flex align-items-center">\n <div class="flex-grow-1">\n <span style="white-space:pre-wrap" class="fs-6" $text="this.state?.message"></span>\n <template $if="this.state?.left !== undefined">\n <span class="small text-dim ms-2" $text="${this.state?.left}s"></span>\n </template>\n </div>\n <button type="button" class="btn btn-link ms-3 bi bi-x-lg link-reset" style="color:inherit" data-bs-dismiss="toast"></button>\n </div>\n <div class="d-flex justify-content-end gap-3">\n <template $each="this.state?.buttons || [\'{#Close#}\']">\n <button type="button" $class="btn btn-sm btn-${this.state?.type} mt-2" data-bs-dismiss="toast" $onclick="this.result=index+1" $text="item"></bu