From ad8d1f77dfd175a0bc34e9fc5e04722a7cde9c8f Mon Sep 17 00:00:00 2001 From: patriceac <48073125+patriceac@users.noreply.github.com> Date: Wed, 28 Dec 2022 13:41:36 -0800 Subject: [PATCH] Proper restoration of inactive image modifiers Inactive image modifiers (right click on image tag) are not properly restored by Use Settings and Copy/Paste settings. This PR fixes that. --- ui/media/js/dnd.js | 7 +++++++ ui/media/js/image-modifiers.js | 20 ++++++++++++++++++++ ui/media/js/main.js | 3 ++- 3 files changed, 29 insertions(+), 1 deletion(-) diff --git a/ui/media/js/dnd.js b/ui/media/js/dnd.js index 4d3f8af8..8a5f9c6a 100644 --- a/ui/media/js/dnd.js +++ b/ui/media/js/dnd.js @@ -59,6 +59,13 @@ const TASK_MAPPING = { readUI: () => activeTags.map(x => x.name), parse: (val) => val }, + inactive_tags: { name: "Inactive Image Modifiers", + setUI: (inactive_tags) => { + refreshInactiveTags(inactive_tags) + }, + readUI: () => activeTags.filter(tag => tag.inactive === true).map(x => x.name), + parse: (val) => val + }, width: { name: 'Width', setUI: (width) => { const oldVal = widthField.value diff --git a/ui/media/js/image-modifiers.js b/ui/media/js/image-modifiers.js index 8927a3d6..0d611602 100644 --- a/ui/media/js/image-modifiers.js +++ b/ui/media/js/image-modifiers.js @@ -204,6 +204,26 @@ function refreshModifiersState(newTags) { refreshTagsList() } +function refreshInactiveTags(inactiveTags) { + // update inactive tags + if (inactiveTags !== undefined && inactiveTags.length > 0) { + activeTags.forEach (tag => { + if (inactiveTags.find(element => element === tag.name) !== undefined) { + tag.inactive = true + } + }) + } + + // update cards + let overlays = document.querySelector('#editor-inputs-tags-list').querySelectorAll('.modifier-card-overlay') + overlays.forEach (i => { + let modifierName = i.parentElement.getElementsByClassName('modifier-card-label')[0].getElementsByTagName("p")[0].innerText + if (inactiveTags.find(element => element === modifierName) !== undefined) { + i.parentElement.classList.add('modifier-toggle-inactive') + } + }) +} + function refreshTagsList() { editorModifierTagsList.innerHTML = '' diff --git a/ui/media/js/main.js b/ui/media/js/main.js index 07bd2e5f..7d70233e 100644 --- a/ui/media/js/main.js +++ b/ui/media/js/main.js @@ -940,7 +940,8 @@ function getCurrentUserRequest() { output_quality: parseInt(outputQualityField.value), metadata_output_format: document.querySelector('#metadata_output_format').value, original_prompt: promptField.value, - active_tags: (activeTags.map(x => x.name)) + active_tags: (activeTags.map(x => x.name)), + inactive_tags: (activeTags.filter(tag => tag.inactive === true).map(x => x.name)) } } if (IMAGE_REGEX.test(initImagePreview.src)) {