From 6fb372c5e1c68142ff08c853b55fe3883421b16f Mon Sep 17 00:00:00 2001 From: somebody Date: Sun, 11 Sep 2022 21:41:37 -0500 Subject: [PATCH] Cleanup So much for that 100px hack --- aiserver.py | 28 +++++++- static/koboldai.css | 29 +++++--- static/koboldai.js | 161 +++++++++++++++++++++++++++++++++++--------- 3 files changed, 175 insertions(+), 43 deletions(-) diff --git a/aiserver.py b/aiserver.py index 6b741875..fc45d373 100644 --- a/aiserver.py +++ b/aiserver.py @@ -7481,7 +7481,7 @@ def UI_2_import_world_info(data): koboldai_vars.worldinfo_v2.add_item_to_folder(uids[child], folder_name) @socketio.on("search_wi") -def UI_2_load_softprompt_list(data): +def UI_2_search_wi(data): query = data["query"].lower() full_data = koboldai_vars.worldinfo_v2.to_json() @@ -7502,6 +7502,32 @@ def UI_2_load_softprompt_list(data): socketio.emit("wi_results", results, broadcast=True, room="UI_2") +@socketio.on("update_wi_attribute") +def UI_2_update_wi_attribute(data): + uid, key, value = data["uid"], data["key"], data["value"] + koboldai_vars.worldinfo_v2.world_info[uid][key] = value + socketio.emit("world_info_entry", koboldai_vars.worldinfo_v2.world_info[uid], broadcast=True, room="UI_2") + +@socketio.on("update_wi_keys") +def UI_2_update_wi_attribute(data): + uid, key, is_secondary, operation = data["uid"], data["key"], data["is_secondary"], data["operation"] + + keykey = "key" if not is_secondary else "keysecondary" + key_exists = key in koboldai_vars.worldinfo_v2.world_info[uid][keykey] + + if operation == "add": + if not key_exists: + koboldai_vars.worldinfo_v2.world_info[uid][keykey].append(key) + elif operation == "remove": + if key_exists: + koboldai_vars.worldinfo_v2.world_info[uid][keykey].remove(key) + + if keykey == "keysecondary": + koboldai_vars.worldinfo_v2.world_info[uid]["selective"] = len(koboldai_vars.worldinfo_v2.world_info[uid]["keysecondary"]) > 0 + + # Send to UI + socketio.emit("world_info_entry", koboldai_vars.worldinfo_v2.world_info[uid], broadcast=True, room="UI_2") + #==================================================================# # Event triggered when user edits phrase biases diff --git a/static/koboldai.css b/static/koboldai.css index 32241fbf..23159cb4 100644 --- a/static/koboldai.css +++ b/static/koboldai.css @@ -1932,8 +1932,6 @@ body { } .finder-wi-focus { - /* This MUST be a percentage before pushing. The 100px is a workaround but - i've got to find a solution otherwiseit causes visual bugs on shorter screens */ margin-top: -100px; height: calc(100% + 100px) !important; @@ -1945,6 +1943,7 @@ body { background-color: var(--flyout_background_pinned); height: 100%; flex-grow: 1; + flex-basis: 50%; overflow-y: hidden; filter: brightness(70%); padding: 0px 7px; @@ -1970,6 +1969,10 @@ body { height: 30%; } +.finder-wi-keys { + margin-bottom: 8px; +} + .finder-wi-added-keys { display: inline-block; } @@ -1984,11 +1987,6 @@ body { .tag-text { cursor: text; } -[data-placeholder]:empty:before { - content: attr(data-placeholder); - opacity: 0.6; -} - .finder-wi-activation-header-container { display: flex; justify-content: space-between; @@ -2005,20 +2003,29 @@ body { column-gap: 5px; } +.finder-wi-blanket { + position: absolute; + /* Hack */ + width: 99%; + height: 100%; + cursor: pointer; +} + /*---------------------------------- Global ------------------------------------------------*/ .hidden { display: none; } -.block { - display: block; -} - .disabled { opacity: 0.4; pointer-events: none; } +[data-placeholder]:empty:before { + content: attr(data-placeholder); + opacity: 0.6; +} + #input_text { grid-area: textarea; background-color: var(--input_background); diff --git a/static/koboldai.js b/static/koboldai.js index e19b425d..a476dbce 100644 --- a/static/koboldai.js +++ b/static/koboldai.js @@ -44,6 +44,8 @@ var world_info_folder_data = {}; var saved_settings = {}; var finder_selection_index = -1; var on_colab; +var wi_finder_data = []; +var wi_finder_offset = 0; // name, desc, icon, func const finder_actions = [ @@ -3391,30 +3393,74 @@ function $e(tag, parent, attributes) { return element; } -function makeFinderWITag(name, container, isPrimary) { +function makeFinderWITag(name, container, isPrimary, uid) { let wiTag = $e("span", container, {classes: ["tag"]}); let wiTagIcon = $e("span", wiTag, {classes: ["finder-wi-tag-icon", "material-icons-outlined"], innerText: "close"}); let wiTagText = $e("span", wiTag, {innerText: name, contenteditable: true}); wiTagIcon.addEventListener("click", function(e) { - // TODO: Server + socket.emit( + "update_wi_keys", + {uid: parseInt(uid), key: name, is_secondary: !isPrimary, operation: "remove"} + ); wiTag.remove(); }); } -function updateWISearchListings(entry) { - const wiCarousel = document.getElementById("finder-wi-carousel"); +function updateWIInfo(event) { + // Should be a change event or something similar. This WILL send an update + // packet on each unfocus in some cases. It's not that big of a deal, right? :p - let entries = Object.values(entry).flat().slice(0, 3); + let key = event.target.getAttribute("wi-sync"); + + if ("checked" in event.target) { + // checkbox / toggle + value = event.target.checked; + } else if ("value" in event.target) { + // standard inputs + value = event.target.value; + } else { + // contenteditable + value = event.target.innerText + } + + let uid = $(event.target).closest(".finder-wi-block")[0].getAttribute("wi-uid"); + socket.emit("update_wi_attribute", {uid: parseInt(uid), key: key, value: value}); +} + +function updateWISearchListings(data) { + wi_finder_offset = 0; + wi_finder_data = Object.values(data).flat(); + renderWISearchListings(); +} + +function renderWISearchListings() { + const wiCarousel = document.getElementById("finder-wi-carousel"); + $(".finder-wi-block").remove(); + + let data = Array.from(wi_finder_data); + + // No need for excessive shifting + let realOffset = wi_finder_offset % data.length; + + // Make first be central + if (data.length > 2) realOffset--; + + // Wrap around + if (realOffset < 0) realOffset += data.length; + + // Actual data wrap + for (let i=0;i