2023-07-19 21:07:50 +02:00
|
|
|
import { AskConfirmation } from '$wails/go/app/App';
|
2023-06-18 21:40:39 +02:00
|
|
|
import InputDialog from '../dialogs/input.svelte';
|
|
|
|
|
2023-06-18 21:31:55 +02:00
|
|
|
function newDialog(dialogComponent, data = {}) {
|
|
|
|
const outlet = document.createElement('div');
|
|
|
|
outlet.className = 'dialogoutlet';
|
|
|
|
document.getElementById('dialogoutlets').appendChild(outlet);
|
|
|
|
|
|
|
|
const instance = new dialogComponent({ target: outlet, props: data });
|
|
|
|
|
|
|
|
instance.$close = function() {
|
|
|
|
instance.$destroy();
|
|
|
|
outlet.remove();
|
|
|
|
};
|
|
|
|
|
|
|
|
instance.$on('close', instance.$close);
|
|
|
|
|
|
|
|
return instance;
|
|
|
|
}
|
|
|
|
|
2023-06-18 21:40:39 +02:00
|
|
|
function enterText(title = '', description = '', value = '') {
|
|
|
|
const instance = newDialog(InputDialog, { title, description, value });
|
|
|
|
|
|
|
|
return new Promise(resolve => {
|
|
|
|
instance.$on('submit', event => {
|
|
|
|
instance.$close();
|
|
|
|
resolve(event.detail.value);
|
|
|
|
});
|
2023-06-23 15:58:23 +02:00
|
|
|
instance.$on('close', () => resolve(undefined));
|
2023-06-18 21:40:39 +02:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2023-07-19 21:07:50 +02:00
|
|
|
function confirm(message = '') {
|
|
|
|
return AskConfirmation(message);
|
|
|
|
}
|
|
|
|
|
|
|
|
const dialogs = { new: newDialog, enterText, confirm };
|
2023-06-18 21:31:55 +02:00
|
|
|
|
|
|
|
export default dialogs;
|