Rework reasoning CSS selectors and fixes - Remove reliance on :empty state of reasoning textbox, now using the actual css class on mes (".mes.reasoning") - Fix reasoning add not working when Auto-Expand is not enabled - Clean setting of dataset attributes, now removing when null
| @@ -13,7 +13,7 @@ import { ARGUMENT_TYPE, SlashCommandArgument, SlashCommandNamedArgument } from ' | |||
| 13 | import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; | 13 | import { commonEnumProviders } from './slash-commands/SlashCommandCommonEnumsProvider.js'; |
| 14 | import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; | 14 | import { SlashCommandParser } from './slash-commands/SlashCommandParser.js'; |
| 15 | import { textgen_types, textgenerationwebui_settings } from './textgen-settings.js'; | 15 | import { textgen_types, textgenerationwebui_settings } from './textgen-settings.js'; |
| 16 | import { copyText, escapeRegex, isFalseBoolean } from './utils.js'; | 16 | import { copyText, escapeRegex, isFalseBoolean, setDatasetProperty } from './utils.js'; |
| 17 | 17 | ||
| 18 | /** | 18 | /** |
| 19 | * Gets a message from a jQuery element. | 19 | * Gets a message from a jQuery element. |
| @@ -323,8 +323,8 @@ export class ReasoningHandler { | |||
| 323 | this.messageDom.classList.toggle('reasoning', this.state !== ReasoningState.None); | 323 | this.messageDom.classList.toggle('reasoning', this.state !== ReasoningState.None); |
| 324 | 324 | ||
| 325 | // Update states to the relevant DOM elements | 325 | // Update states to the relevant DOM elements |
| 326 | this.messageDom.dataset.reasoningState = this.state !== ReasoningState.None ? this.state : null; | 326 | setDatasetProperty(this.messageDom, 'reasoningState', this.state !== ReasoningState.None ? this.state : null); |
| 327 | this.messageReasoningDetailsDom.dataset.state = this.state; | 327 | setDatasetProperty(this.messageReasoningDetailsDom, 'state', this.state); |
| 328 | 328 | ||
| 329 | // Update the reasoning message | 329 | // Update the reasoning message |
| 330 | const reasoning = power_user.trim_spaces ? this.reasoning.trim() : this.reasoning; | 330 | const reasoning = power_user.trim_spaces ? this.reasoning.trim() : this.reasoning; |
| @@ -391,8 +391,8 @@ export class ReasoningHandler { | |||
| 391 | data = null; | 391 | data = null; |
| 392 | } | 392 | } |
| 393 | 393 | ||
| 394 | this.messageReasoningDetailsDom.dataset.duration = data; | 394 | setDatasetProperty(this.messageReasoningDetailsDom, 'duration', data); |
| 395 | element.dataset.duration = data; | 395 | setDatasetProperty(element, 'duration', data); |
| 396 | } | 396 | } |
| 397 | } | 397 | } |
| 398 | 398 | ||
| @@ -698,10 +698,9 @@ function setReasoningEventHandlers() { | |||
| 698 | const textarea = messageBlock.find('.reasoning_edit_textarea'); | 698 | const textarea = messageBlock.find('.reasoning_edit_textarea'); |
| 699 | textarea.remove(); | 699 | textarea.remove(); |
| 700 | 700 | ||
| 701 | // Make sure we remove the fake placeholder from the reasoning string | 701 | // If we cancel, we might have to remove the reasong class again if this is an unsaved empty reasoning |
| 702 | const text = messageBlock.find('.mes_reasoning').text(); | 702 | if (!messageBlock.attr('data--reasoning-state')) { |
| 703 | if (text === PromptReasoning.REASONING_UI_PLACEHOLDER) { | 703 | messageBlock.removeClass('reasoning'); |
| 704 | messageBlock.find('.mes_reasoning').text(''); | ||
| 705 | } | 704 | } |
| 706 | 705 | ||
| 707 | messageBlock.find('.mes_reasoning_edit_cancel:visible').trigger('click'); | 706 | messageBlock.find('.mes_reasoning_edit_cancel:visible').trigger('click'); |
| @@ -718,9 +717,10 @@ function setReasoningEventHandlers() { | |||
| 718 | return; | 717 | return; |
| 719 | } | 718 | } |
| 720 | 719 | ||
| 721 | // To be able to edit, we need to "fake" content being there inside the reasoning string | 720 | messageBlock.addClass('reasoning'); |
| 722 | messageBlock.find('.mes_reasoning').text(PromptReasoning.REASONING_UI_PLACEHOLDER); | ||
| 723 | 721 | ||
| 722 | // Open the reasoning area so we can actually edit it | ||
| 723 | messageBlock.find('.mes_reasoning_details').attr('open', ''); | ||
| 724 | messageBlock.find('.mes_reasoning_edit').trigger('click'); | 724 | messageBlock.find('.mes_reasoning_edit').trigger('click'); |
| 725 | await saveChatConditional(); | 725 | await saveChatConditional(); |
| 726 | }); | 726 | }); |
| @@ -2059,6 +2059,23 @@ export function toggleDrawer(drawer, expand = true) { | |||
| 2059 | } | 2059 | } |
| 2060 | } | 2060 | } |
| 2061 | 2061 | ||
| 2062 | /** | ||
| 2063 | * Sets or removes a dataset property on an HTMLElement | ||
| 2064 | * | ||
| 2065 | * Utility function to make it easier to reset dataset properties on null, without them being "null" as value. | ||
| 2066 | * | ||
| 2067 | * @param {HTMLElement} element - The element to modify | ||
| 2068 | * @param {string} name - The name of the dataset property | ||
| 2069 | * @param {string|null} value - The value to set - If null, the dataset property will be removed | ||
| 2070 | */ | ||
| 2071 | export function setDatasetProperty(element, name, value) { | ||
| 2072 | if (value === null) { | ||
| 2073 | delete element.dataset[name]; | ||
| 2074 | } else { | ||
| 2075 | element.dataset[name] = value; | ||
| 2076 | } | ||
| 2077 | } | ||
| 2078 | |||
| 2062 | export async function fetchFaFile(name) { | 2079 | export async function fetchFaFile(name) { |
| 2063 | const style = document.createElement('style'); | 2080 | const style = document.createElement('style'); |
| 2064 | style.innerHTML = await (await fetch(`/css/${name}`)).text(); | 2081 | style.innerHTML = await (await fetch(`/css/${name}`)).text(); |
| @@ -410,17 +410,17 @@ input[type='checkbox']:focus-visible { | |||
| 410 | } | 410 | } |
| 411 | 411 | ||
| 412 | .mes_bias:empty, | 412 | .mes_bias:empty, |
| 413 | .mes_reasoning:empty, | 413 | .mes:not(.reasoning) .mes_reasoning_details, |
| 414 | .mes_reasoning_details:has(.mes_reasoning:empty), | ||
| 415 | .mes_reasoning_details:not([open]) .mes_reasoning_actions, | 414 | .mes_reasoning_details:not([open]) .mes_reasoning_actions, |
| 416 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning, | 415 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning, |
| 417 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning_header, | 416 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning_header, |
| 418 | .mes_reasoning_details:not(:has(.reasoning_edit_textarea)) .mes_reasoning_actions .edit_button, | ||
| 419 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning_actions .mes_button:not(.edit_button), | 417 | .mes_reasoning_details:has(.reasoning_edit_textarea) .mes_reasoning_actions .mes_button:not(.edit_button), |
| 418 | .mes_reasoning_details:not(:has(.reasoning_edit_textarea)) .mes_reasoning_actions .edit_button, | ||
| 420 | .mes_block:has(.edit_textarea):has(.reasoning_edit_textarea) .mes_reasoning_actions, | 419 | .mes_block:has(.edit_textarea):has(.reasoning_edit_textarea) .mes_reasoning_actions, |
| 421 | .mes.reasoning:not([data-reasoning-state="none"]) .mes_edit_add_reasoning, | 420 | .mes.reasoning .mes_edit_add_reasoning, |
| 422 | .mes[data-reasoning-state="none"] .mes_reasoning_arrow, | 421 | .mes[data-reasoning-state="hidden"] .mes_reasoning_arrow, |
| 423 | .mes[data-reasoning-state="none"] .mes_reasoning_actions { | 422 | .mes[data-reasoning-state="hidden"] .mes_reasoning, |
| 423 | .mes[data-reasoning-state="hidden"] .mes_reasoning_copy { | ||
| 424 | display: none; | 424 | display: none; |
| 425 | } | 425 | } |
| 426 | 426 | ||