sync from work
This commit is contained in:
@ -1,6 +1,6 @@
|
||||
import "../../css/popup.scss";
|
||||
import { createElement } from "../functions";
|
||||
import { r } from "../utility";
|
||||
import { r, nullOrEmpty } from "../utility";
|
||||
import { createIcon } from "./icon";
|
||||
|
||||
class Popup {
|
||||
@ -63,7 +63,11 @@ class Popup {
|
||||
if (typeof b.trigger === 'function') {
|
||||
const result = b.trigger(this);
|
||||
if (typeof result?.then === 'function') {
|
||||
result.then(r => r !== false && close()).catch(() => { });
|
||||
result.then(r => {
|
||||
if (r !== false) {
|
||||
close();
|
||||
}
|
||||
}).catch(() => { });
|
||||
} else if (result !== false) {
|
||||
close();
|
||||
}
|
||||
@ -147,19 +151,40 @@ export function showAlert(title, message, iconType = 'info', parent = document.b
|
||||
}
|
||||
|
||||
export function showConfirm(title, content, buttons, iconType = 'question', parent = document.body) {
|
||||
return new Promise(resolve => {
|
||||
return new Promise((resolve, reject) => {
|
||||
const wrapper = createElement('div', 'message-wrapper');
|
||||
if (!nullOrEmpty(iconType)) {
|
||||
wrapper.appendChild(createIcon('fa-solid', iconTypes[iconType] ?? 'question-circle'));
|
||||
}
|
||||
wrapper.appendChild(content instanceof HTMLElement ?
|
||||
content :
|
||||
createElement('span', span => span.innerText = content));
|
||||
const popup = new Popup({
|
||||
title,
|
||||
content: createElement('div', 'message-wrapper',
|
||||
createIcon('fa-solid', iconTypes[iconType] ?? 'question-circle'),
|
||||
createElement('span', null, content)
|
||||
),
|
||||
content: wrapper,
|
||||
buttons: buttons?.map(b => {
|
||||
return {
|
||||
text: b.text, trigger: p => resolve({
|
||||
key: b.key,
|
||||
popup: p
|
||||
})
|
||||
text: b.text,
|
||||
trigger: p => {
|
||||
let result;
|
||||
if (typeof b.trigger === 'function') {
|
||||
result = b.trigger(p, b);
|
||||
if (typeof result?.then === 'function') {
|
||||
return result.then(r => {
|
||||
r !== false && resolve(r);
|
||||
return r;
|
||||
});
|
||||
}
|
||||
result !== false && resolve(result);
|
||||
} else {
|
||||
result = {
|
||||
key: b.key,
|
||||
popup: p
|
||||
};
|
||||
resolve(result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
};
|
||||
}) ??
|
||||
[
|
||||
|
Reference in New Issue
Block a user