/** * Dialog Component Module */ globalThis.Component.register('Dialog', globalThis.Component.getSetupFunction('Modal'), globalThis.Util.makeDom(/*html*/` `)) , globalThis.Util.makeDom(/*html*/` `) let _dialogCount = 0 globalThis.Dialog = { show({ title = '', message = '', buttons = ['{#Close#}'], type = 'body' }) { const d = document.body.appendChild(document.createElement('Dialog')) d.style.zIndex = 2000 + ++_dialogCount Promise.resolve().then(() => { Object.assign(d.state, { message, title, type, buttons }) d.show() }) return new Promise((resolve) => { d.addEventListener('change', e => { _dialogCount-- resolve(d.result || 0) d.remove() }) }) }, alert(message, options = {}) { return this.show({ message, ...options }) }, confirm(message, options = {}) { return new Promise(resolve => this.show({ message, buttons: ['{#Cancel#}', '{#Confirm#}'], ...options }).then(index => resolve(index >= 2)).catch(() => resolve(false))) } }