Refactor and fix type errors in WI and script modules (#4123) * remove unnecessary arg passage from WI helper funcs * remove some typescript red from script.js * hide in shame * Add JSDoc to helper functions * Fix fav_ch_checked not updating * Move PWA mode match to firstLoadInit * Fix more type errors and deprecations * Fix the rest of type errors in script.js --------- Co-authored-by: RossAscends <124905043+RossAscends@users.noreply.github.com>
Signed| @@ -30,6 +30,11 @@ declare global { | |||
| 30 | izoomify(options?: any): JQuery; | 30 | izoomify(options?: any): JQuery; |
| 31 | } | 31 | } |
| 32 | 32 | ||
| 33 | // NPM package doesn't have the 'queue' property in the type definition | ||
| 34 | interface JQueryTransitOptions { | ||
| 35 | queue?: boolean; | ||
| 36 | } | ||
| 37 | |||
| 33 | namespace Select2 { | 38 | namespace Select2 { |
| 34 | interface Options<Result = DataFormat | GroupedDataFormat, RemoteResult = any> { | 39 | interface Options<Result = DataFormat | GroupedDataFormat, RemoteResult = any> { |
| 35 | /** | 40 | /** |
| @@ -770,21 +770,6 @@ async function getSystemMessages() { | |||
| 770 | }; | 770 | }; |
| 771 | } | 771 | } |
| 772 | 772 | ||
| 773 | // Register configuration migrations | ||
| 774 | registerPromptManagerMigration(); | ||
| 775 | |||
| 776 | $(document).ajaxError(function myErrorHandler(_, xhr) { | ||
| 777 | // Cohee: CSRF doesn't error out in multiple tabs anymore, so this is unnecessary | ||
| 778 | /* | ||
| 779 | if (xhr.status == 403) { | ||
| 780 | toastr.warning( | ||
| 781 | 'doubleCsrf errors in console are NORMAL in this case. If you want to run ST in multiple tabs, start the server with --disableCsrf option.', | ||
| 782 | 'Looks like you\'ve opened SillyTavern in another browser tab', | ||
| 783 | { timeOut: 0, extendedTimeOut: 0, preventDuplicates: true }, | ||
| 784 | ); | ||
| 785 | } */ | ||
| 786 | }); | ||
| 787 | |||
| 788 | async function getClientVersion() { | 773 | async function getClientVersion() { |
| 789 | try { | 774 | try { |
| 790 | const response = await fetch('/version'); | 775 | const response = await fetch('/version'); |
| @@ -865,7 +850,8 @@ export let create_save = { | |||
| 865 | creator: '', | 850 | creator: '', |
| 866 | personality: '', | 851 | personality: '', |
| 867 | first_message: '', | 852 | first_message: '', |
| 868 | avatar: '', | 853 | /** @type {FileList|null} */ |
| 854 | avatar: null, | ||
| 869 | scenario: '', | 855 | scenario: '', |
| 870 | mes_example: '', | 856 | mes_example: '', |
| 871 | world: '', | 857 | world: '', |
| @@ -982,6 +968,8 @@ async function firstLoadInit() { | |||
| 982 | } | 968 | } |
| 983 | 969 | ||
| 984 | showLoader(); | 970 | showLoader(); |
| 971 | registerPromptManagerMigration(); | ||
| 972 | initStandaloneMode(); | ||
| 985 | initLibraryShims(); | 973 | initLibraryShims(); |
| 986 | addShowdownPatch(showdown); | 974 | addShowdownPatch(showdown); |
| 987 | reloadMarkdownProcessor(); | 975 | reloadMarkdownProcessor(); |
| @@ -1040,6 +1028,13 @@ async function fixViewport() { | |||
| 1040 | document.body.style.position = ''; | 1028 | document.body.style.position = ''; |
| 1041 | } | 1029 | } |
| 1042 | 1030 | ||
| 1031 | function initStandaloneMode() { | ||
| 1032 | const isPwaMode = window.matchMedia('(display-mode: standalone)').matches; | ||
| 1033 | if (isPwaMode) { | ||
| 1034 | $('body').addClass('PWA'); | ||
| 1035 | } | ||
| 1036 | } | ||
| 1037 | |||
| 1043 | function cancelStatusCheck(reason = 'Manually cancelled status check') { | 1038 | function cancelStatusCheck(reason = 'Manually cancelled status check') { |
| 1044 | abortStatusCheck?.abort(new AbortReason(reason)); | 1039 | abortStatusCheck?.abort(new AbortReason(reason)); |
| 1045 | abortStatusCheck = new AbortController(); | 1040 | abortStatusCheck = new AbortController(); |
| @@ -1396,7 +1391,6 @@ export function resultCheckStatus() { | |||
| 1396 | stopStatusLoading(); | 1391 | stopStatusLoading(); |
| 1397 | } | 1392 | } |
| 1398 | 1393 | ||
| 1399 | |||
| 1400 | /** | 1394 | /** |
| 1401 | * Switches the currently selected character to the one with the given ID. (character index, not the character key!) | 1395 | * Switches the currently selected character to the one with the given ID. (character index, not the character key!) |
| 1402 | * | 1396 | * |
| @@ -3760,6 +3754,7 @@ export async function generateRaw(prompt, api, instructOverride, quietToLoud, sy | |||
| 3760 | if (responseLengthCustomized) { | 3754 | if (responseLengthCustomized) { |
| 3761 | TempResponseLength.save(api, responseLength); | 3755 | TempResponseLength.save(api, responseLength); |
| 3762 | } | 3756 | } |
| 3757 | /** @type {object|any[]} */ | ||
| 3763 | let generateData = {}; | 3758 | let generateData = {}; |
| 3764 | 3759 | ||
| 3765 | switch (api) { | 3760 | switch (api) { |
| @@ -7138,6 +7133,11 @@ export async function saveChat({ chatName, withMetadata, mesId, force = false } | |||
| 7138 | } | 7133 | } |
| 7139 | } | 7134 | } |
| 7140 | 7135 | ||
| 7136 | /** | ||
| 7137 | * Processes the avatar image from the input element, allowing the user to crop it if necessary. | ||
| 7138 | * @param {HTMLInputElement} input - The input element containing the avatar file. | ||
| 7139 | * @returns {Promise<void>} | ||
| 7140 | */ | ||
| 7141 | async function read_avatar_load(input) { | 7141 | async function read_avatar_load(input) { |
| 7142 | if (input.files && input.files[0]) { | 7142 | if (input.files && input.files[0]) { |
| 7143 | if (selected_button == 'create') { | 7143 | if (selected_button == 'create') { |
| @@ -7169,7 +7169,7 @@ async function read_avatar_load(input) { | |||
| 7169 | await createOrEditCharacter(); | 7169 | await createOrEditCharacter(); |
| 7170 | await delay(DEFAULT_SAVE_EDIT_TIMEOUT); | 7170 | await delay(DEFAULT_SAVE_EDIT_TIMEOUT); |
| 7171 | 7171 | ||
| 7172 | const formData = new FormData($('#form_create').get(0)); | 7172 | const formData = new FormData(/** @type {HTMLFormElement} */($('#form_create').get(0))); |
| 7173 | await fetch(getThumbnailUrl('avatar', formData.get('avatar_url')), { | 7173 | await fetch(getThumbnailUrl('avatar', formData.get('avatar_url')), { |
| 7174 | method: 'GET', | 7174 | method: 'GET', |
| 7175 | cache: 'no-cache', | 7175 | cache: 'no-cache', |
| @@ -7179,22 +7179,21 @@ async function read_avatar_load(input) { | |||
| 7179 | }, | 7179 | }, |
| 7180 | }); | 7180 | }); |
| 7181 | 7181 | ||
| 7182 | $('.mes').each(async function () { | 7182 | const messages = $('.mes').toArray(); |
| 7183 | const nameMatch = $(this).attr('ch_name') == formData.get('ch_name'); | 7183 | for (const el of messages) { |
| 7184 | if ($(this).attr('is_system') == 'true' && !nameMatch) { | 7184 | const $el = $(el); |
| 7185 | return; | 7185 | const nameMatch = $el.attr('ch_name') == formData.get('ch_name'); |
| 7186 | } | 7186 | if ($el.attr('is_system') == 'true' && !nameMatch) continue; |
| 7187 | if ($(this).attr('is_user') == 'true') { | 7187 | if ($el.attr('is_user') == 'true') continue; |
| 7188 | return; | 7188 | |
| 7189 | } | ||
| 7190 | if (nameMatch) { | 7189 | if (nameMatch) { |
| 7191 | const previewSrc = $('#avatar_load_preview').attr('src'); | 7190 | const previewSrc = $('#avatar_load_preview').attr('src'); |
| 7192 | const avatar = $(this).find('.avatar img'); | 7191 | const avatar = $el.find('.avatar img'); |
| 7193 | avatar.attr('src', default_avatar); | 7192 | avatar.attr('src', default_avatar); |
| 7194 | await delay(1); | 7193 | await delay(1); |
| 7195 | avatar.attr('src', previewSrc); | 7194 | avatar.attr('src', previewSrc); |
| 7196 | } | 7195 | } |
| 7197 | }); | 7196 | } |
| 7198 | 7197 | ||
| 7199 | console.log('Avatar refreshed'); | 7198 | console.log('Avatar refreshed'); |
| 7200 | } | 7199 | } |
| @@ -8044,7 +8043,7 @@ export async function getChatsFromFiles(data, isGroupChat) { | |||
| 8044 | * response is an object with an `error` property set to `true`. | 8043 | * response is an object with an `error` property set to `true`. |
| 8045 | */ | 8044 | */ |
| 8046 | export async function getPastCharacterChats(characterId = null) { | 8045 | export async function getPastCharacterChats(characterId = null) { |
| 8047 | characterId = characterId ?? this_chid; | 8046 | characterId = characterId ?? parseInt(this_chid); |
| 8048 | if (!characters[characterId]) return []; | 8047 | if (!characters[characterId]) return []; |
| 8049 | 8048 | ||
| 8050 | const response = await fetch('/api/characters/chats', { | 8049 | const response = await fetch('/api/characters/chats', { |
| @@ -8111,9 +8110,7 @@ export async function displayPastChats() { | |||
| 8111 | // UX convenience: Focus the search field when the Manage Chat Files view opens. | 8110 | // UX convenience: Focus the search field when the Manage Chat Files view opens. |
| 8112 | setTimeout(function () { | 8111 | setTimeout(function () { |
| 8113 | const textSearchElement = $('#select_chat_search'); | 8112 | const textSearchElement = $('#select_chat_search'); |
| 8114 | textSearchElement.click(); | 8113 | textSearchElement.trigger('click').trigger('focus').trigger('select'); |
| 8115 | textSearchElement.focus(); | ||
| 8116 | textSearchElement.select(); // select content (if any) for easy erasing | ||
| 8117 | }, 200); | 8114 | }, 200); |
| 8118 | } | 8115 | } |
| 8119 | 8116 | ||
| @@ -8380,11 +8377,10 @@ function select_rm_create({ switchMenu = true } = {}) { | |||
| 8380 | switchMenu && setMenuType('create'); | 8377 | switchMenu && setMenuType('create'); |
| 8381 | 8378 | ||
| 8382 | //console.log('select_rm_Create() -- selected button: '+selected_button); | 8379 | //console.log('select_rm_Create() -- selected button: '+selected_button); |
| 8383 | if (selected_button == 'create') { | 8380 | if (selected_button == 'create' && create_save.avatar) { |
| 8384 | if (create_save.avatar != '') { | 8381 | const addAvatarInput = /** @type {HTMLInputElement} */ ($('#add_avatar_button').get(0)); |
| 8385 | $('#add_avatar_button').get(0).files = create_save.avatar; | 8382 | addAvatarInput.files = create_save.avatar; |
| 8386 | read_avatar_load($('#add_avatar_button').get(0)); | 8383 | read_avatar_load(addAvatarInput); |
| 8387 | } | ||
| 8388 | } | 8384 | } |
| 8389 | 8385 | ||
| 8390 | switchMenu && selectRightMenuWithAnimation('rm_ch_create_block'); | 8386 | switchMenu && selectRightMenuWithAnimation('rm_ch_create_block'); |
| @@ -8510,11 +8506,18 @@ export function updateChatMetadata(newValues, reset) { | |||
| 8510 | chat_metadata = reset ? { ...newValues } : { ...chat_metadata, ...newValues }; | 8506 | chat_metadata = reset ? { ...newValues } : { ...chat_metadata, ...newValues }; |
| 8511 | } | 8507 | } |
| 8512 | 8508 | ||
| 8509 | |||
| 8510 | /** | ||
| 8511 | * Updates the state of the favorite button based on the provided state. | ||
| 8512 | * @param {boolean} state Whether the favorite button should be on or off. | ||
| 8513 | */ | ||
| 8513 | function updateFavButtonState(state) { | 8514 | function updateFavButtonState(state) { |
| 8515 | // Update global state of the flag | ||
| 8516 | // TODO: This is bad and needs to be refactored. | ||
| 8514 | fav_ch_checked = state; | 8517 | fav_ch_checked = state; |
| 8515 | $('#fav_checkbox').val(fav_ch_checked); | 8518 | $('#fav_checkbox').prop('checked', state); |
| 8516 | $('#favorite_button').toggleClass('fav_on', fav_ch_checked); | 8519 | $('#favorite_button').toggleClass('fav_on', state); |
| 8517 | $('#favorite_button').toggleClass('fav_off', !fav_ch_checked); | 8520 | $('#favorite_button').toggleClass('fav_off', !state); |
| 8518 | } | 8521 | } |
| 8519 | 8522 | ||
| 8520 | export async function setScenarioOverride() { | 8523 | export async function setScenarioOverride() { |
| @@ -8830,7 +8833,7 @@ function updateEditArrowClasses() { | |||
| 8830 | export function closeMessageEditor(what = 'all') { | 8833 | export function closeMessageEditor(what = 'all') { |
| 8831 | if (what === 'message' || what === 'all') { | 8834 | if (what === 'message' || what === 'all') { |
| 8832 | if (this_edit_mes_id) { | 8835 | if (this_edit_mes_id) { |
| 8833 | $(`#chat .mes[mesid="${this_edit_mes_id}"] .mes_edit_cancel`).click(); | 8836 | $(`#chat .mes[mesid="${this_edit_mes_id}"] .mes_edit_cancel`).trigger('click'); |
| 8834 | } | 8837 | } |
| 8835 | } | 8838 | } |
| 8836 | if (what === 'reasoning' || what === 'all') { | 8839 | if (what === 'reasoning' || what === 'all') { |
| @@ -8919,7 +8922,8 @@ function openCharacterWorldPopup() { | |||
| 8919 | } | 8922 | } |
| 8920 | 8923 | ||
| 8921 | function onExtraWorldInfoChanged() { | 8924 | function onExtraWorldInfoChanged() { |
| 8922 | const selectedWorlds = $('.character_extra_world_info_selector').val(); | 8925 | const selectorFieldValue = $('.character_extra_world_info_selector').val(); |
| 8926 | const selectedWorlds = Array.isArray(selectorFieldValue) ? selectorFieldValue : []; | ||
| 8923 | let charLore = world_info.charLore ?? []; | 8927 | let charLore = world_info.charLore ?? []; |
| 8924 | 8928 | ||
| 8925 | // TODO: Maybe make this utility function not use the window context? | 8929 | // TODO: Maybe make this utility function not use the window context? |
| @@ -8964,7 +8968,7 @@ function openCharacterWorldPopup() { | |||
| 8964 | // Apped to base dropdown | 8968 | // Apped to base dropdown |
| 8965 | world_names.forEach((item, i) => { | 8969 | world_names.forEach((item, i) => { |
| 8966 | const option = document.createElement('option'); | 8970 | const option = document.createElement('option'); |
| 8967 | option.value = i; | 8971 | option.value = String(i); |
| 8968 | option.innerText = item; | 8972 | option.innerText = item; |
| 8969 | option.selected = item === worldId; | 8973 | option.selected = item === worldId; |
| 8970 | select.append(option); | 8974 | select.append(option); |
| @@ -8976,7 +8980,7 @@ function openCharacterWorldPopup() { | |||
| 8976 | } | 8980 | } |
| 8977 | world_names.forEach((item, i) => { | 8981 | world_names.forEach((item, i) => { |
| 8978 | const option = document.createElement('option'); | 8982 | const option = document.createElement('option'); |
| 8979 | option.value = i; | 8983 | option.value = String(i); |
| 8980 | option.innerText = item; | 8984 | option.innerText = item; |
| 8981 | 8985 | ||
| 8982 | const existingCharLore = world_info.charLore?.find((e) => e.name === getCharaFilename()); | 8986 | const existingCharLore = world_info.charLore?.find((e) => e.name === getCharaFilename()); |
| @@ -9082,7 +9086,7 @@ function addAlternateGreeting(template, greeting, index, getArray, popup) { | |||
| 9082 | */ | 9086 | */ |
| 9083 | async function createOrEditCharacter(e) { | 9087 | async function createOrEditCharacter(e) { |
| 9084 | $('#rm_info_avatar').html(''); | 9088 | $('#rm_info_avatar').html(''); |
| 9085 | const formData = new FormData($('#form_create').get(0)); | 9089 | const formData = new FormData(/** @type {HTMLFormElement} */($('#form_create').get(0))); |
| 9086 | formData.set('fav', String(fav_ch_checked)); | 9090 | formData.set('fav', String(fav_ch_checked)); |
| 9087 | const isNewChat = e instanceof CustomEvent && e.type === 'newChat'; | 9091 | const isNewChat = e instanceof CustomEvent && e.type === 'newChat'; |
| 9088 | 9092 | ||
| @@ -9164,7 +9168,7 @@ async function createOrEditCharacter(e) { | |||
| 9164 | 9168 | ||
| 9165 | $('#character_popup-button-h3').text('Create character'); | 9169 | $('#character_popup-button-h3').text('Create character'); |
| 9166 | 9170 | ||
| 9167 | create_save.avatar = ''; | 9171 | create_save.avatar = null; |
| 9168 | 9172 | ||
| 9169 | $('#add_avatar_button').replaceWith( | 9173 | $('#add_avatar_button').replaceWith( |
| 9170 | $('#add_avatar_button').val('').clone(true), | 9174 | $('#add_avatar_button').val('').clone(true), |
| @@ -10172,9 +10176,6 @@ async function doGetChatName() { | |||
| 10172 | return getCurrentChatDetails().sessionName; | 10176 | return getCurrentChatDetails().sessionName; |
| 10173 | } | 10177 | } |
| 10174 | 10178 | ||
| 10175 | const isPwaMode = window.navigator.standalone; | ||
| 10176 | if (isPwaMode) { $('body').addClass('PWA'); } | ||
| 10177 | |||
| 10178 | function doCharListDisplaySwitch() { | 10179 | function doCharListDisplaySwitch() { |
| 10179 | power_user.charListGrid = !power_user.charListGrid; | 10180 | power_user.charListGrid = !power_user.charListGrid; |
| 10180 | document.body.classList.toggle('charListGrid', power_user.charListGrid); | 10181 | document.body.classList.toggle('charListGrid', power_user.charListGrid); |
| @@ -10759,23 +10760,23 @@ jQuery(async function () { | |||
| 10759 | 10760 | ||
| 10760 | //menu buttons setup | 10761 | //menu buttons setup |
| 10761 | 10762 | ||
| 10762 | $('#rm_button_settings').click(function () { | 10763 | $('#rm_button_settings').on('click', function () { |
| 10763 | selected_button = 'settings'; | 10764 | selected_button = 'settings'; |
| 10764 | selectRightMenuWithAnimation('rm_api_block'); | 10765 | selectRightMenuWithAnimation('rm_api_block'); |
| 10765 | }); | 10766 | }); |
| 10766 | $('#rm_button_characters').click(function () { | 10767 | $('#rm_button_characters').on('click', function () { |
| 10767 | selected_button = 'characters'; | 10768 | selected_button = 'characters'; |
| 10768 | select_rm_characters(); | 10769 | select_rm_characters(); |
| 10769 | }); | 10770 | }); |
| 10770 | $('#rm_button_back').click(function () { | 10771 | $('#rm_button_back').on('click', function () { |
| 10771 | selected_button = 'characters'; | 10772 | selected_button = 'characters'; |
| 10772 | select_rm_characters(); | 10773 | select_rm_characters(); |
| 10773 | }); | 10774 | }); |
| 10774 | $('#rm_button_create').click(function () { | 10775 | $('#rm_button_create').on('click', function () { |
| 10775 | selected_button = 'create'; | 10776 | selected_button = 'create'; |
| 10776 | select_rm_create(); | 10777 | select_rm_create(); |
| 10777 | }); | 10778 | }); |
| 10778 | $('#rm_button_selected_ch').click(function () { | 10779 | $('#rm_button_selected_ch').on('click', function () { |
| 10779 | if (selected_group) { | 10780 | if (selected_group) { |
| 10780 | select_group_chats(selected_group); | 10781 | select_group_chats(selected_group); |
| 10781 | } else { | 10782 | } else { |
| @@ -10870,7 +10871,7 @@ jQuery(async function () { | |||
| 10870 | callPopup('<h3>' + t`Delete the Chat File?` + '</h3>', 'del_chat'); | 10871 | callPopup('<h3>' + t`Delete the Chat File?` + '</h3>', 'del_chat'); |
| 10871 | }); | 10872 | }); |
| 10872 | 10873 | ||
| 10873 | $('#advanced_div').click(function () { | 10874 | $('#advanced_div').on('click', function () { |
| 10874 | if (!is_advanced_char_open) { | 10875 | if (!is_advanced_char_open) { |
| 10875 | is_advanced_char_open = true; | 10876 | is_advanced_char_open = true; |
| 10876 | $('#character_popup').css({ 'display': 'flex', 'opacity': 0.0 }).addClass('open'); | 10877 | $('#character_popup').css({ 'display': 'flex', 'opacity': 0.0 }).addClass('open'); |
| @@ -10885,7 +10886,7 @@ jQuery(async function () { | |||
| 10885 | } | 10886 | } |
| 10886 | }); | 10887 | }); |
| 10887 | 10888 | ||
| 10888 | $('#character_cross').click(function () { | 10889 | $('#character_cross').on('click', function () { |
| 10889 | is_advanced_char_open = false; | 10890 | is_advanced_char_open = false; |
| 10890 | $('#character_popup').transition({ | 10891 | $('#character_popup').transition({ |
| 10891 | opacity: 0, | 10892 | opacity: 0, |
| @@ -10895,12 +10896,12 @@ jQuery(async function () { | |||
| 10895 | setTimeout(function () { $('#character_popup').css('display', 'none'); }, animation_duration); | 10896 | setTimeout(function () { $('#character_popup').css('display', 'none'); }, animation_duration); |
| 10896 | }); | 10897 | }); |
| 10897 | 10898 | ||
| 10898 | $('#character_popup_ok').click(function () { | 10899 | $('#character_popup_ok').on('click', function () { |
| 10899 | is_advanced_char_open = false; | 10900 | is_advanced_char_open = false; |
| 10900 | $('#character_popup').css('display', 'none'); | 10901 | $('#character_popup').css('display', 'none'); |
| 10901 | }); | 10902 | }); |
| 10902 | 10903 | ||
| 10903 | $('#dialogue_popup_ok').click(async function (e, customData) { | 10904 | $('#dialogue_popup_ok').on('click', async function (_e, customData) { |
| 10904 | const fromSlashCommand = customData?.fromSlashCommand || false; | 10905 | const fromSlashCommand = customData?.fromSlashCommand || false; |
| 10905 | dialogueCloseStop = false; | 10906 | dialogueCloseStop = false; |
| 10906 | $('#shadow_popup').transition({ | 10907 | $('#shadow_popup').transition({ |
| @@ -10930,7 +10931,7 @@ jQuery(async function () { | |||
| 10930 | hideLoader(); | 10931 | hideLoader(); |
| 10931 | } else { // Open the history view again after 2 seconds (delay to avoid edge cases for deleting last chat). | 10932 | } else { // Open the history view again after 2 seconds (delay to avoid edge cases for deleting last chat). |
| 10932 | setTimeout(function () { | 10933 | setTimeout(function () { |
| 10933 | $('#option_select_chat').click(); | 10934 | $('#option_select_chat').trigger('click'); |
| 10934 | $('#options').hide(); // hide option popup menu | 10935 | $('#options').hide(); // hide option popup menu |
| 10935 | hideLoader(); | 10936 | hideLoader(); |
| 10936 | }, 2000); | 10937 | }, 2000); |
| @@ -10941,18 +10942,16 @@ jQuery(async function () { | |||
| 10941 | if (popup_type == 'input') { | 10942 | if (popup_type == 'input') { |
| 10942 | dialogueResolve($('#dialogue_popup_input').val()); | 10943 | dialogueResolve($('#dialogue_popup_input').val()); |
| 10943 | $('#dialogue_popup_input').val(''); | 10944 | $('#dialogue_popup_input').val(''); |
| 10944 | |||
| 10945 | } | 10945 | } |
| 10946 | else { | 10946 | else { |
| 10947 | dialogueResolve(true); | 10947 | dialogueResolve(true); |
| 10948 | |||
| 10949 | } | 10948 | } |
| 10950 | 10949 | ||
| 10951 | dialogueResolve = null; | 10950 | dialogueResolve = null; |
| 10952 | } | 10951 | } |
| 10953 | }); | 10952 | }); |
| 10954 | 10953 | ||
| 10955 | $('#dialogue_popup_cancel').click(function (e) { | 10954 | $('#dialogue_popup_cancel').on('click', function (e) { |
| 10956 | dialogueCloseStop = false; | 10955 | dialogueCloseStop = false; |
| 10957 | $('#shadow_popup').transition({ | 10956 | $('#shadow_popup').transition({ |
| 10958 | opacity: 0, | 10957 | opacity: 0, |
| @@ -10965,21 +10964,20 @@ jQuery(async function () { | |||
| 10965 | $('#dialogue_popup').removeClass('large_dialogue_popup'); | 10964 | $('#dialogue_popup').removeClass('large_dialogue_popup'); |
| 10966 | }, animation_duration); | 10965 | }, animation_duration); |
| 10967 | 10966 | ||
| 10968 | //$("#shadow_popup").css("opacity:", 0.0); | ||
| 10969 | popup_type = ''; | 10967 | popup_type = ''; |
| 10970 | 10968 | ||
| 10971 | if (dialogueResolve) { | 10969 | if (dialogueResolve) { |
| 10972 | dialogueResolve(false); | 10970 | dialogueResolve(false); |
| 10973 | dialogueResolve = null; | 10971 | dialogueResolve = null; |
| 10974 | } | 10972 | } |
| 10975 | |||
| 10976 | }); | 10973 | }); |
| 10977 | 10974 | ||
| 10978 | $('#add_avatar_button').change(function () { | 10975 | $('#add_avatar_button').on('change', function () { |
| 10979 | read_avatar_load(this); | 10976 | const inputElement = /** @type {HTMLInputElement} */ (this); |
| 10977 | read_avatar_load(inputElement); | ||
| 10980 | }); | 10978 | }); |
| 10981 | 10979 | ||
| 10982 | $('#form_create').submit(createOrEditCharacter); | 10980 | $('#form_create').on('submit', (e) => createOrEditCharacter(e.originalEvent)); |
| 10983 | 10981 | ||
| 10984 | $('#delete_button').on('click', async function () { | 10982 | $('#delete_button').on('click', async function () { |
| 10985 | if (this_chid === undefined || !characters[this_chid]) { | 10983 | if (this_chid === undefined || !characters[this_chid]) { |
| @@ -10990,7 +10988,7 @@ jQuery(async function () { | |||
| 10990 | let deleteChats = false; | 10988 | let deleteChats = false; |
| 10991 | 10989 | ||
| 10992 | const confirm = await Popup.show.confirm(t`Delete the character?`, await renderTemplateAsync('deleteConfirm'), { | 10990 | const confirm = await Popup.show.confirm(t`Delete the character?`, await renderTemplateAsync('deleteConfirm'), { |
| 10993 | onClose: () => deleteChats = !!$('#del_char_checkbox').prop('checked'), | 10991 | onClose: () => { deleteChats = !!$('#del_char_checkbox').prop('checked'); }, |
| 10994 | }); | 10992 | }); |
| 10995 | if (!confirm) { | 10993 | if (!confirm) { |
| 10996 | return; | 10994 | return; |
| @@ -11111,7 +11109,7 @@ jQuery(async function () { | |||
| 11111 | 11109 | ||
| 11112 | /////////////////////////////////////////////////////////////////////////////////// | 11110 | /////////////////////////////////////////////////////////////////////////////////// |
| 11113 | 11111 | ||
| 11114 | $('#api_button').click(function (e) { | 11112 | $('#api_button').on('click', function (e) { |
| 11115 | if ($('#api_url_text').val() != '') { | 11113 | if ($('#api_url_text').val() != '') { |
| 11116 | let value = formatKoboldUrl(String($('#api_url_text').val()).trim()); | 11114 | let value = formatKoboldUrl(String($('#api_url_text').val()).trim()); |
| 11117 | 11115 | ||
| @@ -11252,7 +11250,7 @@ jQuery(async function () { | |||
| 11252 | if ((selected_group || this_chid !== undefined) && !is_send_press) { | 11250 | if ((selected_group || this_chid !== undefined) && !is_send_press) { |
| 11253 | let deleteCurrentChat = false; | 11251 | let deleteCurrentChat = false; |
| 11254 | const result = await Popup.show.confirm(t`Start new chat?`, await renderTemplateAsync('newChatConfirm'), { | 11252 | const result = await Popup.show.confirm(t`Start new chat?`, await renderTemplateAsync('newChatConfirm'), { |
| 11255 | onClose: () => deleteCurrentChat = !!$('#del_chat_checkbox').prop('checked'), | 11253 | onClose: () => { deleteCurrentChat = !!$('#del_chat_checkbox').prop('checked'); }, |
| 11256 | }); | 11254 | }); |
| 11257 | if (!result) { | 11255 | if (!result) { |
| 11258 | return; | 11256 | return; |
| @@ -11356,7 +11354,7 @@ jQuery(async function () { | |||
| 11356 | ////////////////////////////////////////////////////////////////////////////////////////////// | 11354 | ////////////////////////////////////////////////////////////////////////////////////////////// |
| 11357 | 11355 | ||
| 11358 | //functionality for the cancel delete messages button, reverts to normal display of input form | 11356 | //functionality for the cancel delete messages button, reverts to normal display of input form |
| 11359 | $('#dialogue_del_mes_cancel').click(function () { | 11357 | $('#dialogue_del_mes_cancel').on('click', function () { |
| 11360 | $('#dialogue_del_mes').css('display', 'none'); | 11358 | $('#dialogue_del_mes').css('display', 'none'); |
| 11361 | $('#send_form').css('display', css_send_form_display); | 11359 | $('#send_form').css('display', css_send_form_display); |
| 11362 | $('.del_checkbox').each(function () { | 11360 | $('.del_checkbox').each(function () { |
| @@ -11496,7 +11494,7 @@ jQuery(async function () { | |||
| 11496 | 11494 | ||
| 11497 | ////////////////////////////////////////////////////////////// | 11495 | ////////////////////////////////////////////////////////////// |
| 11498 | 11496 | ||
| 11499 | $('#select_chat_cross').click(function () { | 11497 | $('#select_chat_cross').on('click', function () { |
| 11500 | $('#shadow_select_chat_popup').transition({ | 11498 | $('#shadow_select_chat_popup').transition({ |
| 11501 | opacity: 0, | 11499 | opacity: 0, |
| 11502 | duration: animation_duration, | 11500 | duration: animation_duration, |
| @@ -11590,8 +11588,10 @@ jQuery(async function () { | |||
| 11590 | edit_textarea.height(0); | 11588 | edit_textarea.height(0); |
| 11591 | edit_textarea.height(edit_textarea[0].scrollHeight); | 11589 | edit_textarea.height(edit_textarea[0].scrollHeight); |
| 11592 | } | 11590 | } |
| 11593 | edit_textarea.focus(); | 11591 | edit_textarea.trigger('focus'); |
| 11594 | edit_textarea[0].setSelectionRange( //this sets the cursor at the end of the text | 11592 | const textAreaElement = /** @type {HTMLTextAreaElement} */ (edit_textarea[0]); |
| 11593 | // Sets the cursor at the end of the text | ||
| 11594 | textAreaElement.setSelectionRange( | ||
| 11595 | String(edit_textarea.val()).length, | 11595 | String(edit_textarea.val()).length, |
| 11596 | String(edit_textarea.val()).length, | 11596 | String(edit_textarea.val()).length, |
| 11597 | ); | 11597 | ); |
| @@ -11843,8 +11843,8 @@ jQuery(async function () { | |||
| 11843 | //Select chat | 11843 | //Select chat |
| 11844 | 11844 | ||
| 11845 | //**************************CHARACTER IMPORT EXPORT*************************// | 11845 | //**************************CHARACTER IMPORT EXPORT*************************// |
| 11846 | $('#character_import_button').click(function () { | 11846 | $('#character_import_button').on('click', function () { |
| 11847 | $('#character_import_file').click(); | 11847 | $('#character_import_file').trigger('click'); |
| 11848 | }); | 11848 | }); |
| 11849 | 11849 | ||
| 11850 | $('#character_import_file').on('change', async function (e) { | 11850 | $('#character_import_file').on('change', async function (e) { |
| @@ -11912,12 +11912,16 @@ jQuery(async function () { | |||
| 11912 | } | 11912 | } |
| 11913 | }); | 11913 | }); |
| 11914 | //**************************CHAT IMPORT EXPORT*************************// | 11914 | //**************************CHAT IMPORT EXPORT*************************// |
| 11915 | $('#chat_import_button').click(function () { | 11915 | $('#chat_import_button').on('click', function () { |
| 11916 | $('#chat_import_file').click(); | 11916 | $('#chat_import_file').trigger('click'); |
| 11917 | }); | 11917 | }); |
| 11918 | 11918 | ||
| 11919 | $('#chat_import_file').on('change', async function (e) { | 11919 | $('#chat_import_file').on('change', async function (e) { |
| 11920 | const file = e.target.files[0]; | 11920 | const targetElement = /** @type {HTMLInputElement} */ (e.target); |
| 11921 | if (!(targetElement instanceof HTMLInputElement)) { | ||
| 11922 | return; | ||
| 11923 | } | ||
| 11924 | const file = targetElement.files[0]; | ||
| 11921 | 11925 | ||
| 11922 | if (!file) { | 11926 | if (!file) { |
| 11923 | return; | 11927 | return; |
| @@ -11939,7 +11943,7 @@ jQuery(async function () { | |||
| 11939 | const format = ext[1].toLowerCase(); | 11943 | const format = ext[1].toLowerCase(); |
| 11940 | $('#chat_import_file_type').val(format); | 11944 | $('#chat_import_file_type').val(format); |
| 11941 | 11945 | ||
| 11942 | const formData = new FormData($('#form_import_chat').get(0)); | 11946 | const formData = new FormData(/** @type {HTMLFormElement} */($('#form_import_chat').get(0))); |
| 11943 | formData.append('user_name', name1); | 11947 | formData.append('user_name', name1); |
| 11944 | $('#select_chat_div').html(''); | 11948 | $('#select_chat_div').html(''); |
| 11945 | 11949 | ||
| @@ -11950,12 +11954,12 @@ jQuery(async function () { | |||
| 11950 | } | 11954 | } |
| 11951 | }); | 11955 | }); |
| 11952 | 11956 | ||
| 11953 | $('#rm_button_group_chats').click(function () { | 11957 | $('#rm_button_group_chats').on('click', function () { |
| 11954 | selected_button = 'group_chats'; | 11958 | selected_button = 'group_chats'; |
| 11955 | select_group_chats(); | 11959 | select_group_chats(); |
| 11956 | }); | 11960 | }); |
| 11957 | 11961 | ||
| 11958 | $('#rm_button_back_from_group').click(function () { | 11962 | $('#rm_button_back_from_group').on('click', function () { |
| 11959 | selected_button = 'characters'; | 11963 | selected_button = 'characters'; |
| 11960 | select_rm_characters(); | 11964 | select_rm_characters(); |
| 11961 | }); | 11965 | }); |
| @@ -12025,7 +12029,7 @@ jQuery(async function () { | |||
| 12025 | } | 12029 | } |
| 12026 | }); | 12030 | }); |
| 12027 | 12031 | ||
| 12028 | $(document).on('click', '.inline-drawer-toggle', function (e) { | 12032 | $(document).on('click', '.inline-drawer-toggle', async function (e) { |
| 12029 | if ($(e.target).hasClass('text_pole')) { | 12033 | if ($(e.target).hasClass('text_pole')) { |
| 12030 | return; | 12034 | return; |
| 12031 | } | 12035 | } |
| @@ -12043,10 +12047,10 @@ jQuery(async function () { | |||
| 12043 | 12047 | ||
| 12044 | // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height | 12048 | // Set the height of "autoSetHeight" textareas within the inline-drawer to their scroll height |
| 12045 | if (!CSS.supports('field-sizing', 'content')) { | 12049 | if (!CSS.supports('field-sizing', 'content')) { |
| 12046 | drawerContent.find('textarea.autoSetHeight').each(async function () { | 12050 | const textareas = drawerContent.find('textarea.autoSetHeight'); |
| 12047 | await resetScrollHeight($(this)); | 12051 | for (const textarea of textareas) { |
| 12048 | return; | 12052 | await resetScrollHeight($(textarea)); |
| 12049 | }); | 12053 | } |
| 12050 | } | 12054 | } |
| 12051 | }); | 12055 | }); |
| 12052 | 12056 | ||
| @@ -12161,7 +12165,7 @@ jQuery(async function () { | |||
| 12161 | return; | 12165 | return; |
| 12162 | } | 12166 | } |
| 12163 | if (isEditVisible && power_user.auto_save_msg_edits === true) { | 12167 | if (isEditVisible && power_user.auto_save_msg_edits === true) { |
| 12164 | $(`#chat .mes[mesid="${this_edit_mes_id}"] .mes_edit_done`).click(); | 12168 | $(`#chat .mes[mesid="${this_edit_mes_id}"] .mes_edit_done`).trigger('click'); |
| 12165 | closeMessageEditor('reasoning'); | 12169 | closeMessageEditor('reasoning'); |
| 12166 | $('#send_textarea').focus(); | 12170 | $('#send_textarea').focus(); |
| 12167 | return; | 12171 | return; |
| @@ -12176,7 +12180,8 @@ jQuery(async function () { | |||
| 12176 | }); | 12180 | }); |
| 12177 | 12181 | ||
| 12178 | $('#char-management-dropdown').on('change', async (e) => { | 12182 | $('#char-management-dropdown').on('change', async (e) => { |
| 12179 | let target = $(e.target.selectedOptions).attr('id'); | 12183 | const targetElement = /** @type {HTMLSelectElement} */ (e.target); |
| 12184 | const target = $(targetElement.selectedOptions).attr('id'); | ||
| 12180 | switch (target) { | 12185 | switch (target) { |
| 12181 | case 'set_character_world': | 12186 | case 'set_character_world': |
| 12182 | openCharacterWorldPopup(); | 12187 | openCharacterWorldPopup(); |
| @@ -2529,7 +2529,16 @@ export function parseRegexFromString(input) { | |||
| 2529 | } | 2529 | } |
| 2530 | } | 2530 | } |
| 2531 | 2531 | ||
| 2532 | //MARK: getWorldEntry | 2532 | /** |
| 2533 | * Enables the input helper for keys in a World Info entry. | ||
| 2534 | * @param {object} params - Parameters for enabling the keys input helper. | ||
| 2535 | * @param {JQuery<HTMLElement>} params.template - The template element containing the input. | ||
| 2536 | * @param {object} params.entry - The entry object containing the keys. | ||
| 2537 | * @param {string} params.entryPropName - The property name of the entry that holds the keys. | ||
| 2538 | * @param {string} params.originalDataValueName - The name of the original data value to be set. | ||
| 2539 | * @param {string} params.name - The name of the world info entry. | ||
| 2540 | * @param {object} params.data - The data object containing entries. | ||
| 2541 | */ | ||
| 2533 | function enableKeysInputHelper({ template, entry, entryPropName, originalDataValueName, name, data }) { | 2542 | function enableKeysInputHelper({ template, entry, entryPropName, originalDataValueName, name, data }) { |
| 2534 | const isFancyInput = !isMobile() && !power_user.wi_key_input_plaintext; | 2543 | const isFancyInput = !isMobile() && !power_user.wi_key_input_plaintext; |
| 2535 | const input = isFancyInput ? template.find(`select[name="${entryPropName}"]`) : template.find(`textarea[name="${entryPropName}"]`); | 2544 | const input = isFancyInput ? template.find(`select[name="${entryPropName}"]`) : template.find(`textarea[name="${entryPropName}"]`); |
| @@ -2625,6 +2634,12 @@ function enableKeysInputHelper({ template, entry, entryPropName, originalDataVal | |||
| 2625 | 2634 | ||
| 2626 | /** | 2635 | /** |
| 2627 | * Helper to handle match checkboxes for WI entries. | 2636 | * Helper to handle match checkboxes for WI entries. |
| 2637 | * @param {object} params - Parameters for handling match checkboxes. | ||
| 2638 | * @param {JQuery<HTMLElement>} params.template - The template element containing the checkbox. | ||
| 2639 | * @param {object} params.entry - The entry object containing the checkbox state. | ||
| 2640 | * @param {string} params.fieldName - The name of the checkbox field. | ||
| 2641 | * @param {object} params.data - The data object containing entries. | ||
| 2642 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2628 | */ | 2643 | */ |
| 2629 | function handleMatchCheckboxHelper({ template, entry, fieldName, data, name }) { | 2644 | function handleMatchCheckboxHelper({ template, entry, fieldName, data, name }) { |
| 2630 | const key = originalWIDataKeyMap[fieldName]; | 2645 | const key = originalWIDataKeyMap[fieldName]; |
| @@ -2642,6 +2657,10 @@ function handleMatchCheckboxHelper({ template, entry, fieldName, data, name }) { | |||
| 2642 | 2657 | ||
| 2643 | /** | 2658 | /** |
| 2644 | * Helper to update position/order display. | 2659 | * Helper to update position/order display. |
| 2660 | * @param {object} params - Parameters for updating position/order display. | ||
| 2661 | * @param {JQuery<HTMLElement>} params.template - The template element containing the display. | ||
| 2662 | * @param {object} params.data - The data object containing entries. | ||
| 2663 | * @param {string} params.uid - The unique identifier of the entry to update. | ||
| 2645 | */ | 2664 | */ |
| 2646 | function updatePosOrdDisplayHelper({ template, data, uid }) { | 2665 | function updatePosOrdDisplayHelper({ template, data, uid }) { |
| 2647 | let entry = data.entries[uid]; | 2666 | let entry = data.entries[uid]; |
| @@ -2658,8 +2677,9 @@ function updatePosOrdDisplayHelper({ template, data, uid }) { | |||
| 2658 | 2677 | ||
| 2659 | /** | 2678 | /** |
| 2660 | * Helper to initialize character filter select2. | 2679 | * Helper to initialize character filter select2. |
| 2680 | * @param {JQuery<HTMLElement>} characterFilter - The select element for character filter. | ||
| 2661 | */ | 2681 | */ |
| 2662 | function initCharacterFilterSelect2Helper(characterFilter, t) { | 2682 | function initCharacterFilterSelect2Helper(characterFilter) { |
| 2663 | if (!isMobile()) { | 2683 | if (!isMobile()) { |
| 2664 | $(characterFilter).select2({ | 2684 | $(characterFilter).select2({ |
| 2665 | width: '100%', | 2685 | width: '100%', |
| @@ -2672,8 +2692,11 @@ function initCharacterFilterSelect2Helper(characterFilter, t) { | |||
| 2672 | 2692 | ||
| 2673 | /** | 2693 | /** |
| 2674 | * Helper to fill character and tag options for character filter. | 2694 | * Helper to fill character and tag options for character filter. |
| 2695 | * @param {object} params - Parameters for filling options. | ||
| 2696 | * @param {JQuery<HTMLElement>} params.characterFilter - The select element to fill with options. | ||
| 2697 | * @param {object} params.entry - The entry object containing character filter data. | ||
| 2675 | */ | 2698 | */ |
| 2676 | function fillCharacterAndTagOptionsHelper({ characterFilter, entry, getContext }) { | 2699 | function fillCharacterAndTagOptionsHelper({ characterFilter, entry }) { |
| 2677 | const characters = getContext().characters; | 2700 | const characters = getContext().characters; |
| 2678 | characters.forEach((character) => { | 2701 | characters.forEach((character) => { |
| 2679 | const option = document.createElement('option'); | 2702 | const option = document.createElement('option'); |
| @@ -2696,8 +2719,13 @@ function fillCharacterAndTagOptionsHelper({ characterFilter, entry, getContext } | |||
| 2696 | 2719 | ||
| 2697 | /** | 2720 | /** |
| 2698 | * Helper to handle character filter changes. | 2721 | * Helper to handle character filter changes. |
| 2722 | * @param {object} params - Parameters for handling character filter changes. | ||
| 2723 | * @param {JQuery<HTMLElement>} params.characterFilter - The select element for character filter. | ||
| 2724 | * @param {object} params.data - The data object containing entries. | ||
| 2725 | * @param {object} params.entry - The entry object to update. | ||
| 2726 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2699 | */ | 2727 | */ |
| 2700 | function handleCharacterFilterChangeHelper({ characterFilter, data, entry, name, world_names, getContext, setWIOriginalDataValue, saveWorldInfo, t }) { | 2728 | function handleCharacterFilterChangeHelper({ characterFilter, data, entry, name }) { |
| 2701 | characterFilter.on('mousedown change', async function (e) { | 2729 | characterFilter.on('mousedown change', async function (e) { |
| 2702 | if (world_names.length === 0) { | 2730 | if (world_names.length === 0) { |
| 2703 | e.preventDefault(); | 2731 | e.preventDefault(); |
| @@ -2728,8 +2756,13 @@ function handleCharacterFilterChangeHelper({ characterFilter, data, entry, name, | |||
| 2728 | 2756 | ||
| 2729 | /** | 2757 | /** |
| 2730 | * Helper to handle probability input. | 2758 | * Helper to handle probability input. |
| 2759 | * @param {object} params - Parameters for handling probability input. | ||
| 2760 | * @param {JQuery<HTMLElement>} params.probabilityInput - The input element for probability. | ||
| 2761 | * @param {object} params.data - The data object containing entries. | ||
| 2762 | * @param {object} params.entry - The entry object to update. | ||
| 2763 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2731 | */ | 2764 | */ |
| 2732 | function handleProbabilityInputHelper({ probabilityInput, data, entry, name, setWIOriginalDataValue, saveWorldInfo }) { | 2765 | function handleProbabilityInputHelper({ probabilityInput, data, entry, name }) { |
| 2733 | probabilityInput.data('uid', entry.uid); | 2766 | probabilityInput.data('uid', entry.uid); |
| 2734 | probabilityInput.on('input', async function (_, { noSave = false } = {}) { | 2767 | probabilityInput.on('input', async function (_, { noSave = false } = {}) { |
| 2735 | const uid = $(this).data('uid'); | 2768 | const uid = $(this).data('uid'); |
| @@ -2750,8 +2783,14 @@ function handleProbabilityInputHelper({ probabilityInput, data, entry, name, set | |||
| 2750 | 2783 | ||
| 2751 | /** | 2784 | /** |
| 2752 | * Helper to handle probability toggle. | 2785 | * Helper to handle probability toggle. |
| 2786 | * @param {object} params - Parameters for handling probability toggle. | ||
| 2787 | * @param {JQuery<HTMLElement>} params.probabilityToggle - The toggle element for probability. | ||
| 2788 | * @param {object} params.data - The data object containing entries. | ||
| 2789 | * @param {object} params.entry - The entry object to update. | ||
| 2790 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2791 | * @param {JQuery<HTMLElement>} params.probabilityInput - The input element for probability. | ||
| 2753 | */ | 2792 | */ |
| 2754 | function handleProbabilityToggleHelper({ probabilityToggle, data, entry, name, probabilityInput, setWIOriginalDataValue, saveWorldInfo }) { | 2793 | function handleProbabilityToggleHelper({ probabilityToggle, data, entry, name, probabilityInput }) { |
| 2755 | probabilityToggle.data('uid', entry.uid); | 2794 | probabilityToggle.data('uid', entry.uid); |
| 2756 | probabilityToggle.on('input', async function (_, { noSave = false } = {}) { | 2795 | probabilityToggle.on('input', async function (_, { noSave = false } = {}) { |
| 2757 | const uid = $(this).data('uid'); | 2796 | const uid = $(this).data('uid'); |
| @@ -2774,8 +2813,14 @@ function handleProbabilityToggleHelper({ probabilityToggle, data, entry, name, p | |||
| 2774 | 2813 | ||
| 2775 | /** | 2814 | /** |
| 2776 | * Helper to handle select2 dropdowns for boolean selects. | 2815 | * Helper to handle select2 dropdowns for boolean selects. |
| 2816 | * @param {object} params - Parameters for handling boolean selects. | ||
| 2817 | * @param {JQuery<HTMLElement>} params.selectElem - The select element for boolean values. | ||
| 2818 | * @param {object} params.entry - The entry object containing the boolean value. | ||
| 2819 | * @param {string} params.entryKey - The key in the entry object for the boolean value. | ||
| 2820 | * @param {object} params.data - The data object containing entries. | ||
| 2821 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2777 | */ | 2822 | */ |
| 2778 | function handleBooleanSelectHelper({ selectElem, entry, entryKey, data, name, setWIOriginalDataValue, saveWorldInfo }) { | 2823 | function handleBooleanSelectHelper({ selectElem, entry, entryKey, data, name }) { |
| 2779 | selectElem.data('uid', entry.uid); | 2824 | selectElem.data('uid', entry.uid); |
| 2780 | selectElem.on('input', async function (_, { noSave = false } = {}) { | 2825 | selectElem.on('input', async function (_, { noSave = false } = {}) { |
| 2781 | const uid = $(this).data('uid'); | 2826 | const uid = $(this).data('uid'); |
| @@ -2789,8 +2834,17 @@ function handleBooleanSelectHelper({ selectElem, entry, entryKey, data, name, se | |||
| 2789 | 2834 | ||
| 2790 | /** | 2835 | /** |
| 2791 | * Helper to handle input fields for numbers. | 2836 | * Helper to handle input fields for numbers. |
| 2837 | * @param {object} params - Parameters for handling number inputs. | ||
| 2838 | * @param {JQuery<HTMLElement>} params.inputElem - The input element for the number. | ||
| 2839 | * @param {object} params.entry - The entry object containing the number value. | ||
| 2840 | * @param {string} params.entryKey - The key in the entry object for the number value. | ||
| 2841 | * @param {object} params.data - The data object containing entries. | ||
| 2842 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2843 | * @param {number} params.min - The minimum value for the number input. | ||
| 2844 | * @param {number} params.max - The maximum value for the number input. | ||
| 2845 | * @param {boolean} [params.clamp=false] - Whether to clamp the value within the min and max range. | ||
| 2792 | */ | 2846 | */ |
| 2793 | function handleNumberInputHelper({ inputElem, entry, entryKey, data, name, setWIOriginalDataValue, saveWorldInfo, min, max, clamp = false }) { | 2847 | function handleNumberInputHelper({ inputElem, entry, entryKey, data, name, min, max, clamp = false }) { |
| 2794 | inputElem.data('uid', entry.uid); | 2848 | inputElem.data('uid', entry.uid); |
| 2795 | inputElem.on('input', async function (_, { noSave = false } = {}) { | 2849 | inputElem.on('input', async function (_, { noSave = false } = {}) { |
| 2796 | const uid = $(this).data('uid'); | 2850 | const uid = $(this).data('uid'); |
| @@ -2813,8 +2867,13 @@ function handleNumberInputHelper({ inputElem, entry, entryKey, data, name, setWI | |||
| 2813 | 2867 | ||
| 2814 | /** | 2868 | /** |
| 2815 | * Helper to handle tri-state selector for constant/normal/vectorized. | 2869 | * Helper to handle tri-state selector for constant/normal/vectorized. |
| 2870 | * @param {object} params - Parameters for handling the entry state selector. | ||
| 2871 | * @param {JQuery<HTMLElement>} params.entryStateSelector - The select element for entry state. | ||
| 2872 | * @param {object} params.entry - The entry object containing the state. | ||
| 2873 | * @param {object} params.data - The data object containing entries. | ||
| 2874 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2816 | */ | 2875 | */ |
| 2817 | function handleEntryStateSelectorHelper({ entryStateSelector, entry, data, name, setWIOriginalDataValue, saveWorldInfo }) { | 2876 | function handleEntryStateSelectorHelper({ entryStateSelector, entry, data, name }) { |
| 2818 | entryStateSelector.data('uid', entry.uid); | 2877 | entryStateSelector.data('uid', entry.uid); |
| 2819 | entryStateSelector.on('click', function (event) { | 2878 | entryStateSelector.on('click', function (event) { |
| 2820 | event.stopPropagation(); | 2879 | event.stopPropagation(); |
| @@ -2850,8 +2909,14 @@ function handleEntryStateSelectorHelper({ entryStateSelector, entry, data, name, | |||
| 2850 | 2909 | ||
| 2851 | /** | 2910 | /** |
| 2852 | * Helper to handle kill switch toggle. | 2911 | * Helper to handle kill switch toggle. |
| 2912 | * @param {object} params - Parameters for handling the kill switch toggle. | ||
| 2913 | * @param {JQuery<HTMLElement>} params.entryKillSwitch - The toggle element for the kill switch. | ||
| 2914 | * @param {object} params.entry - The entry object containing the state. | ||
| 2915 | * @param {object} params.data - The data object containing entries. | ||
| 2916 | * @param {string} params.name - The name of the world info to save changes to. | ||
| 2917 | * @param {JQuery<HTMLElement>} params.template - The template element for the entry. | ||
| 2853 | */ | 2918 | */ |
| 2854 | function handleEntryKillSwitchHelper({ entryKillSwitch, entry, data, name, setWIOriginalDataValue, saveWorldInfo, template }) { | 2919 | function handleEntryKillSwitchHelper({ entryKillSwitch, entry, data, name, template }) { |
| 2855 | entryKillSwitch.data('uid', entry.uid); | 2920 | entryKillSwitch.data('uid', entry.uid); |
| 2856 | entryKillSwitch.on('click', async function () { | 2921 | entryKillSwitch.on('click', async function () { |
| 2857 | const uid = entry.uid; | 2922 | const uid = entry.uid; |
| @@ -2912,13 +2977,12 @@ export async function getWorldEntry(name, data, entry) { | |||
| 2912 | orderInput.css('width', 'calc(3em + 15px)'); | 2977 | orderInput.css('width', 'calc(3em + 15px)'); |
| 2913 | 2978 | ||
| 2914 | // Probability | 2979 | // Probability |
| 2915 | handleProbabilityInputHelper({ probabilityInput: headerTemplate.find('input[name="probability"]'), data, entry, name, setWIOriginalDataValue, saveWorldInfo }); | 2980 | handleProbabilityInputHelper({ probabilityInput: headerTemplate.find('input[name="probability"]'), data, entry, name }); |
| 2916 | 2981 | ||
| 2917 | // Depth | 2982 | // Depth |
| 2918 | handleNumberInputHelper({ | 2983 | handleNumberInputHelper({ |
| 2919 | inputElem: headerTemplate.find('input[name="depth"]'), | 2984 | inputElem: headerTemplate.find('input[name="depth"]'), |
| 2920 | entry, entryKey: 'depth', data, name, setWIOriginalDataValue, saveWorldInfo, | 2985 | entry, entryKey: 'depth', data, name, min: 0, max: MAX_SCAN_DEPTH, clamp: false, |
| 2921 | min: 0, max: MAX_SCAN_DEPTH, clamp: false, | ||
| 2922 | }); | 2986 | }); |
| 2923 | headerTemplate.find('input[name="depth"]').css('width', 'calc(3em + 15px)'); | 2987 | headerTemplate.find('input[name="depth"]').css('width', 'calc(3em + 15px)'); |
| 2924 | 2988 | ||
| @@ -2954,13 +3018,13 @@ export async function getWorldEntry(name, data, entry) { | |||
| 2954 | // Tri-state selector | 3018 | // Tri-state selector |
| 2955 | handleEntryStateSelectorHelper({ | 3019 | handleEntryStateSelectorHelper({ |
| 2956 | entryStateSelector: headerTemplate.find('select[name="entryStateSelector"]'), | 3020 | entryStateSelector: headerTemplate.find('select[name="entryStateSelector"]'), |
| 2957 | entry, data, name, setWIOriginalDataValue, saveWorldInfo, | 3021 | entry, data, name, |
| 2958 | }); | 3022 | }); |
| 2959 | 3023 | ||
| 2960 | // Kill switch | 3024 | // Kill switch |
| 2961 | handleEntryKillSwitchHelper({ | 3025 | handleEntryKillSwitchHelper({ |
| 2962 | entryKillSwitch: headerTemplate.find('div[name="entryKillSwitch"]'), | 3026 | entryKillSwitch: headerTemplate.find('div[name="entryKillSwitch"]'), |
| 2963 | entry, data, name, setWIOriginalDataValue, saveWorldInfo, template: headerTemplate, | 3027 | entry, data, name, template: headerTemplate, |
| 2964 | }); | 3028 | }); |
| 2965 | 3029 | ||
| 2966 | // Duplicate/delete/move buttons | 3030 | // Duplicate/delete/move buttons |
| @@ -3087,7 +3151,6 @@ export async function getWorldEntry(name, data, entry) { | |||
| 3087 | probabilityToggle: editTemplate.find('input[name="useProbability"]'), | 3151 | probabilityToggle: editTemplate.find('input[name="useProbability"]'), |
| 3088 | data, entry, name, | 3152 | data, entry, name, |
| 3089 | probabilityInput: headerTemplate.find('input[name="probability"]'), | 3153 | probabilityInput: headerTemplate.find('input[name="probability"]'), |
| 3090 | setWIOriginalDataValue, saveWorldInfo, | ||
| 3091 | }); | 3154 | }); |
| 3092 | 3155 | ||
| 3093 | // Comment toggle | 3156 | // Comment toggle |
| @@ -3168,11 +3231,9 @@ export async function getWorldEntry(name, data, entry) { | |||
| 3168 | 3231 | ||
| 3169 | const characterFilter = editTemplate.find('select[name="characterFilter"]'); | 3232 | const characterFilter = editTemplate.find('select[name="characterFilter"]'); |
| 3170 | characterFilter.data('uid', entry.uid); | 3233 | characterFilter.data('uid', entry.uid); |
| 3171 | initCharacterFilterSelect2Helper(characterFilter, t); | 3234 | initCharacterFilterSelect2Helper(characterFilter); |
| 3172 | fillCharacterAndTagOptionsHelper({ characterFilter, entry, getContext }); | 3235 | fillCharacterAndTagOptionsHelper({ characterFilter, entry }); |
| 3173 | handleCharacterFilterChangeHelper({ | 3236 | handleCharacterFilterChangeHelper({ characterFilter, data, entry, name }); |
| 3174 | characterFilter, data, entry, name, world_names, getContext, setWIOriginalDataValue, saveWorldInfo, t, | ||
| 3175 | }); | ||
| 3176 | 3237 | ||
| 3177 | // Content | 3238 | // Content |
| 3178 | const counter = editTemplate.find('.world_entry_form_token_counter'); | 3239 | const counter = editTemplate.find('.world_entry_form_token_counter'); |
| @@ -3246,25 +3307,21 @@ export async function getWorldEntry(name, data, entry) { | |||
| 3246 | // Group weight | 3307 | // Group weight |
| 3247 | handleNumberInputHelper({ | 3308 | handleNumberInputHelper({ |
| 3248 | inputElem: editTemplate.find('input[name="groupWeight"]'), | 3309 | inputElem: editTemplate.find('input[name="groupWeight"]'), |
| 3249 | entry, entryKey: 'groupWeight', data, name, setWIOriginalDataValue, saveWorldInfo, | 3310 | entry, entryKey: 'groupWeight', data, name, min: 1, max: 10000, clamp: true, |
| 3250 | min: 1, max: 10000, clamp: true, | ||
| 3251 | }); | 3311 | }); |
| 3252 | 3312 | ||
| 3253 | // Sticky, cooldown, delay | 3313 | // Sticky, cooldown, delay |
| 3254 | handleNumberInputHelper({ | 3314 | handleNumberInputHelper({ |
| 3255 | inputElem: editTemplate.find('input[name="sticky"]'), | 3315 | inputElem: editTemplate.find('input[name="sticky"]'), |
| 3256 | entry, entryKey: 'sticky', data, name, setWIOriginalDataValue, saveWorldInfo, | 3316 | entry, entryKey: 'sticky', data, name, min: 1, max: 10000, clamp: false, |
| 3257 | min: 1, max: 10000, clamp: false, | ||
| 3258 | }); | 3317 | }); |
| 3259 | handleNumberInputHelper({ | 3318 | handleNumberInputHelper({ |
| 3260 | inputElem: editTemplate.find('input[name="cooldown"]'), | 3319 | inputElem: editTemplate.find('input[name="cooldown"]'), |
| 3261 | entry, entryKey: 'cooldown', data, name, setWIOriginalDataValue, saveWorldInfo, | 3320 | entry, entryKey: 'cooldown', data, name, min: 1, max: 10000, clamp: false, |
| 3262 | min: 1, max: 10000, clamp: false, | ||
| 3263 | }); | 3321 | }); |
| 3264 | handleNumberInputHelper({ | 3322 | handleNumberInputHelper({ |
| 3265 | inputElem: editTemplate.find('input[name="delay"]'), | 3323 | inputElem: editTemplate.find('input[name="delay"]'), |
| 3266 | entry, entryKey: 'delay', data, name, setWIOriginalDataValue, saveWorldInfo, | 3324 | entry, entryKey: 'delay', data, name, min: 1, max: 10000, clamp: false, |
| 3267 | min: 1, max: 10000, clamp: false, | ||
| 3268 | }); | 3325 | }); |
| 3269 | 3326 | ||
| 3270 | // Exclude/prevent recursion | 3327 | // Exclude/prevent recursion |
| @@ -3300,18 +3357,9 @@ export async function getWorldEntry(name, data, entry) { | |||
| 3300 | delayUntilRecursionLevelInput.val(['number', 'string'].includes(typeof entry.delayUntilRecursion) ? entry.delayUntilRecursion : '').trigger('input', { noSave: true }); | 3357 | delayUntilRecursionLevelInput.val(['number', 'string'].includes(typeof entry.delayUntilRecursion) ? entry.delayUntilRecursion : '').trigger('input', { noSave: true }); |
| 3301 | 3358 | ||
| 3302 | // Boolean selects | 3359 | // Boolean selects |
| 3303 | handleBooleanSelectHelper({ | 3360 | handleBooleanSelectHelper({ selectElem: editTemplate.find('select[name="caseSensitive"]'), entry, entryKey: 'caseSensitive', data, name }); |
| 3304 | selectElem: editTemplate.find('select[name="caseSensitive"]'), | 3361 | handleBooleanSelectHelper({ selectElem: editTemplate.find('select[name="matchWholeWords"]'), entry, entryKey: 'matchWholeWords', data, name }); |
| 3305 | entry, entryKey: 'caseSensitive', data, name, setWIOriginalDataValue, saveWorldInfo, | 3362 | handleBooleanSelectHelper({ selectElem: editTemplate.find('select[name="useGroupScoring"]'), entry, entryKey: 'useGroupScoring', data, name }); |
| 3306 | }); | ||
| 3307 | handleBooleanSelectHelper({ | ||
| 3308 | selectElem: editTemplate.find('select[name="matchWholeWords"]'), | ||
| 3309 | entry, entryKey: 'matchWholeWords', data, name, setWIOriginalDataValue, saveWorldInfo, | ||
| 3310 | }); | ||
| 3311 | handleBooleanSelectHelper({ | ||
| 3312 | selectElem: editTemplate.find('select[name="useGroupScoring"]'), | ||
| 3313 | entry, entryKey: 'useGroupScoring', data, name, setWIOriginalDataValue, saveWorldInfo, | ||
| 3314 | }); | ||
| 3315 | 3363 | ||
| 3316 | // Match checkboxes | 3364 | // Match checkboxes |
| 3317 | handleMatchCheckboxHelper({ template: editTemplate, entry, fieldName: 'matchPersonaDescription', data, name }); | 3365 | handleMatchCheckboxHelper({ template: editTemplate, entry, fieldName: 'matchPersonaDescription', data, name }); |