Confirm custom PM prompt deletion

a408328fc666b692858ddf1d3e460d4427027b82

Cohee <18619528+Cohee1207@users.noreply.github.com>

1 files changed, +22 -18Ignore whitespace
public/scripts/PromptManager.js+22 -18
@@ -1,12 +1,13 @@
1'use strict';1'use strict';
22
3import { callPopup, event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js';3import { event_types, eventSource, is_send_press, main_api, substituteParams } from '../script.js';
4import { is_group_generating } from './group-chats.js';4import { is_group_generating } from './group-chats.js';
5import { Message, TokenHandler } from './openai.js';5import { Message, TokenHandler } from './openai.js';
6import { power_user } from './power-user.js';6import { power_user } from './power-user.js';
7import { debounce, waitUntilCondition, escapeHtml } from './utils.js';7import { debounce, waitUntilCondition, escapeHtml } from './utils.js';
8import { debounce_timeout } from './constants.js';8import { debounce_timeout } from './constants.js';
9import { renderTemplateAsync } from './templates.js';9import { renderTemplateAsync } from './templates.js';
10import { Popup } from './popup.js';
1011
11function debouncePromise(func, delay) {12function debouncePromise(func, delay) {
12 let timeoutId;13 let timeoutId;
@@ -453,21 +454,24 @@ class PromptManager {
453 };454 };
454455
455 // Delete selected prompt from list form and close edit form456 // Delete selected prompt from list form and close edit form
456 this.handleDeletePrompt = (event) => {457 this.handleDeletePrompt = async (event) => {
457 const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value;458 Popup.show.confirm('Are you sure you want to delete this prompt?', null).then((userChoice) => {
458 const prompt = this.getPromptById(promptID);459 if (!userChoice) return;
460 const promptID = document.getElementById(this.configuration.prefix + 'prompt_manager_footer_append_prompt').value;
461 const prompt = this.getPromptById(promptID);
459462
460 if (prompt && true === this.isPromptDeletionAllowed(prompt)) {463 if (prompt && true === this.isPromptDeletionAllowed(prompt)) {
461 const promptIndex = this.getPromptIndexById(promptID);464 const promptIndex = this.getPromptIndexById(promptID);
462 this.serviceSettings.prompts.splice(Number(promptIndex), 1);465 this.serviceSettings.prompts.splice(Number(promptIndex), 1);
463466
464 this.log('Deleted prompt: ' + prompt.identifier);467 this.log('Deleted prompt: ' + prompt.identifier);
465468
466 this.hidePopup();469 this.hidePopup();
467 this.clearEditForm();470 this.clearEditForm();
468 this.render();471 this.render();
469 this.saveServiceSettings();472 this.saveServiceSettings();
470 }473 }
474 });
471 };475 };
472476
473 // Create new prompt, then save it to settings and close form.477 // Create new prompt, then save it to settings and close form.
@@ -527,9 +531,9 @@ class PromptManager {
527531
528 // Import prompts for the selected character532 // Import prompts for the selected character
529 this.handleImport = () => {533 this.handleImport = () => {
530 callPopup('Existing prompts with the same ID will be overridden. Do you want to proceed?', 'confirm')534 Popup.show.confirm('Existing prompts with the same ID will be overridden. Do you want to proceed?', null)
531 .then(userChoice => {535 .then(userChoice => {
532 if (false === userChoice) return;536 if (!userChoice) return;
533537
534 const fileOpener = document.createElement('input');538 const fileOpener = document.createElement('input');
535 fileOpener.type = 'file';539 fileOpener.type = 'file';
@@ -563,9 +567,9 @@ class PromptManager {
563567
564 // Restore default state of a characters prompt order568 // Restore default state of a characters prompt order
565 this.handleCharacterReset = () => {569 this.handleCharacterReset = () => {
566 callPopup('This will reset the prompt order for this character. You will not lose any prompts.', 'confirm')570 Popup.show.confirm('This will reset the prompt order for this character. You will not lose any prompts.', null)
567 .then(userChoice => {571 .then(userChoice => {
568 if (false === userChoice) return;572 if (!userChoice) return;
569573
570 this.removePromptOrderForCharacter(this.activeCharacter);574 this.removePromptOrderForCharacter(this.activeCharacter);
571 this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder);575 this.addPromptOrderForCharacter(this.activeCharacter, promptManagerDefaultPromptOrder);
@@ -1538,7 +1542,7 @@ class PromptManager {
1538 const encodedName = escapeHtml(prompt.name);1542 const encodedName = escapeHtml(prompt.name);
1539 const isMarkerPrompt = prompt.marker && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;1543 const isMarkerPrompt = prompt.marker && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
1540 const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides;1544 const isSystemPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && !prompt.forbid_overrides;
1541 const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;1545 const isImportantPrompt = !prompt.marker && prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE && prompt.forbid_overrides;
1542 const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;1546 const isUserPrompt = !prompt.marker && !prompt.system_prompt && prompt.injection_position !== INJECTION_POSITION.ABSOLUTE;
1543 const isInjectionPrompt = prompt.injection_position === INJECTION_POSITION.ABSOLUTE;1547 const isInjectionPrompt = prompt.injection_position === INJECTION_POSITION.ABSOLUTE;
1544 const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier);1548 const isOverriddenPrompt = Array.isArray(this.overriddenPrompts) && this.overriddenPrompts.includes(prompt.identifier);