mirror of
https://github.com/SillyTavern/SillyTavern.git
synced 2025-02-13 10:42:55 +01:00
Update some WI confirm/input popups to new popup
This commit is contained in:
parent
717c524b01
commit
cd9013cf73
@ -74,6 +74,22 @@ const showPopupHelper = {
|
|||||||
const value = await popup.show();
|
const value = await popup.show();
|
||||||
return value ? String(value) : null;
|
return value ? String(value) : null;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Asynchronously displays a confirmation popup with the given header and text, returning the clicked result button value.
|
||||||
|
*
|
||||||
|
* @param {string} header - The header text for the popup.
|
||||||
|
* @param {string} text - The main text for the popup.
|
||||||
|
* @param {PopupOptions} [popupOptions={}] - Options for the popup.
|
||||||
|
* @return {Promise<POPUP_RESULT>} A Promise that resolves with the result of the user's interaction.
|
||||||
|
*/
|
||||||
|
confirm: async (header, text, popupOptions = {}) => {
|
||||||
|
const content = PopupUtils.BuildTextWithHeader(header, text);
|
||||||
|
const popup = new Popup(content, POPUP_TYPE.CONFIRM, null, popupOptions);
|
||||||
|
const result = await popup.show();
|
||||||
|
if (typeof result === 'string' || typeof result === 'boolean') throw new Error(`Invalid popup result. CONFIRM popups only support numbers, or null. Result: ${result}`);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
export class Popup {
|
export class Popup {
|
||||||
|
@ -16,6 +16,7 @@ import { SlashCommandEnumValue, enumTypes } from './slash-commands/SlashCommandE
|
|||||||
import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
import { commonEnumProviders, enumIcons } from './slash-commands/SlashCommandCommonEnumsProvider.js';
|
||||||
import { SlashCommandExecutor } from './slash-commands/SlashCommandExecutor.js';
|
import { SlashCommandExecutor } from './slash-commands/SlashCommandExecutor.js';
|
||||||
import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
|
import { SlashCommandClosure } from './slash-commands/SlashCommandClosure.js';
|
||||||
|
import { Popup } from './popup.js';
|
||||||
|
|
||||||
export {
|
export {
|
||||||
world_info,
|
world_info,
|
||||||
@ -1684,8 +1685,7 @@ function displayWorldEntries(name, data, navigation = navigation_option.none, fl
|
|||||||
// Regardless of whether success is displayed or not. Make sure the delete button is available.
|
// Regardless of whether success is displayed or not. Make sure the delete button is available.
|
||||||
// Do not put this code behind.
|
// Do not put this code behind.
|
||||||
$('#world_popup_delete').off('click').on('click', async () => {
|
$('#world_popup_delete').off('click').on('click', async () => {
|
||||||
const confirmation = await callPopup(`<h3>Delete the World/Lorebook: "${name}"?</h3>This action is irreversible!`, 'confirm');
|
const confirmation = await Popup.show.confirm(`Delete the World/Lorebook: "${name}"?`, `This action is irreversible!`);
|
||||||
|
|
||||||
if (!confirmation) {
|
if (!confirmation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1862,7 +1862,7 @@ function displayWorldEntries(name, data, navigation = navigation_option.none, fl
|
|||||||
|
|
||||||
$('#world_duplicate').off('click').on('click', async () => {
|
$('#world_duplicate').off('click').on('click', async () => {
|
||||||
const tempName = getFreeWorldName();
|
const tempName = getFreeWorldName();
|
||||||
const finalName = await callPopup('<h3>Create a new World Info?</h3>Enter a name for the new file:', 'input', tempName);
|
const finalName = await Popup.show.input('Create a new World Info?', 'Enter a name for the new file:', tempName);
|
||||||
|
|
||||||
if (finalName) {
|
if (finalName) {
|
||||||
await saveWorldInfo(finalName, data, true);
|
await saveWorldInfo(finalName, data, true);
|
||||||
@ -3190,7 +3190,7 @@ async function saveWorldInfo(name, data, immediately) {
|
|||||||
|
|
||||||
async function renameWorldInfo(name, data) {
|
async function renameWorldInfo(name, data) {
|
||||||
const oldName = name;
|
const oldName = name;
|
||||||
const newName = await callPopup('<h3>Rename World Info</h3>Enter a new name:', 'input', oldName);
|
const newName = await Popup.show.input('Rename World Info', 'Enter a new name:', oldName);
|
||||||
|
|
||||||
if (oldName === newName || !newName) {
|
if (oldName === newName || !newName) {
|
||||||
console.debug('World info rename cancelled');
|
console.debug('World info rename cancelled');
|
||||||
@ -4138,11 +4138,9 @@ export async function importEmbeddedWorldInfo(skipPopup = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const bookName = characters[chid]?.data?.character_book?.name || `${characters[chid]?.name}'s Lorebook`;
|
const bookName = characters[chid]?.data?.character_book?.name || `${characters[chid]?.name}'s Lorebook`;
|
||||||
const confirmationText = (`<h3>Are you sure you want to import "${bookName}"?</h3>`) + (world_names.includes(bookName) ? 'It will overwrite the World/Lorebook with the same name.' : '');
|
|
||||||
|
|
||||||
if (!skipPopup) {
|
if (!skipPopup) {
|
||||||
const confirmation = await callPopup(confirmationText, 'confirm');
|
const confirmation = await Popup.show.confirm(`Are you sure you want to import "${bookName}"?`, world_names.includes(bookName) ? 'It will overwrite the World/Lorebook with the same name.' : '');
|
||||||
|
|
||||||
if (!confirmation) {
|
if (!confirmation) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -4382,7 +4380,7 @@ jQuery(() => {
|
|||||||
|
|
||||||
$('#world_create_button').on('click', async () => {
|
$('#world_create_button').on('click', async () => {
|
||||||
const tempName = getFreeWorldName();
|
const tempName = getFreeWorldName();
|
||||||
const finalName = await callPopup('<h3>Create a new World Info?</h3>Enter a name for the new file:', 'input', tempName);
|
const finalName = await Popup.show.input('Create a new World Info', 'Enter a name for the new file:', tempName);
|
||||||
|
|
||||||
if (finalName) {
|
if (finalName) {
|
||||||
await createNewWorldInfo(finalName, { interactive: true });
|
await createNewWorldInfo(finalName, { interactive: true });
|
||||||
|
Loading…
x
Reference in New Issue
Block a user