1
0
mirror of https://github.com/garraflavatra/rolens.git synced 2025-07-13 20:24:06 +00:00
Files
rolens/frontend/src/lib/dialogs.js

46 lines
1.1 KiB
JavaScript
Raw Normal View History

2023-08-07 18:21:45 +02:00
import { AskConfirmation } from '$wails/go/app/App.js';
2023-06-18 21:40:39 +02:00
import InputDialog from '../dialogs/input.svelte';
function newDialog(dialogComponent, data = {}) {
const outlet = document.createElement('div');
outlet.className = 'dialogoutlet';
document.getElementById('dialogoutlets').appendChild(outlet);
2023-12-23 14:17:39 +01:00
const instance = new dialogComponent({
target: outlet,
intro: true,
props: data,
});
instance.$close = function() {
2023-12-23 14:17:39 +01:00
setTimeout(() => {
instance.$destroy();
outlet.remove();
}, 200);
};
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
});
}
function confirm(message = '') {
return AskConfirmation(message);
}
const dialogs = { new: newDialog, enterText, confirm };
export default dialogs;