mirror of
https://github.com/DominikDoom/a1111-sd-webui-tagcomplete.git
synced 2026-01-26 11:09:54 +00:00
Add queue processing & callbacks
This commit is contained in:
@@ -39,9 +39,9 @@ var umiPreviousTags = [];
|
||||
/// Similar to a callback system, but primitive.
|
||||
|
||||
// Queues
|
||||
var afterInsertQueue = [];
|
||||
var afterSetupQueue = [];
|
||||
var afterConfigChangeQueue = [];
|
||||
const afterInsertQueue = [];
|
||||
const afterSetupQueue = [];
|
||||
const afterConfigChangeQueue = [];
|
||||
|
||||
// List of parsers to try
|
||||
var parsers = [];
|
||||
const parsers = [];
|
||||
@@ -93,4 +93,23 @@ function escapeHTML(unsafeText) {
|
||||
let div = document.createElement('div');
|
||||
div.textContent = unsafeText;
|
||||
return div.innerHTML;
|
||||
}
|
||||
|
||||
// Queue calling function to process global queues
|
||||
function processQueue(queue, context, ...args) {
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
queue[i].call(context, ...args);
|
||||
}
|
||||
}
|
||||
// The same but with return values
|
||||
function processQueueReturn(queue, context, ...args)
|
||||
{
|
||||
let results = [];
|
||||
for (let i = 0; i < queue.length; i++) {
|
||||
results.push(queue[i].call(context, ...args));
|
||||
}
|
||||
return results;
|
||||
}
|
||||
function processParsers(textArea, prompt) {
|
||||
return processQueueReturn(parsers, null, textArea, prompt);
|
||||
}
|
||||
@@ -224,6 +224,9 @@ async function syncOptions() {
|
||||
|
||||
// Apply changes
|
||||
CFG = newCFG;
|
||||
|
||||
// Callback
|
||||
processQueue(afterConfigChangeQueue, null);
|
||||
}
|
||||
|
||||
// Create the result list div and necessary styling
|
||||
@@ -359,6 +362,9 @@ function insertTextAtCursor(textArea, result, tagword) {
|
||||
}
|
||||
previousTags = tags;
|
||||
|
||||
// Callback
|
||||
processQueue(afterInsertQueue, null, tagType);
|
||||
|
||||
// If it was a yaml wildcard, also update the umiPreviousTags
|
||||
if (tagType === ResultType.yamlWildcard && originalTagword.length > 0) {
|
||||
let umiSubPrompts = [...newPrompt.matchAll(UMI_PROMPT_REGEX)];
|
||||
@@ -612,6 +618,8 @@ async function autocomplete(textArea, prompt, fixedTag = null) {
|
||||
results = [];
|
||||
tagword = tagword.toLowerCase().replace(/[\n\r]/g, "");
|
||||
|
||||
let resultCandidates = processParsers(textArea, prompt);
|
||||
|
||||
if (CFG.useWildcards && [...tagword.matchAll(WC_REGEX)].length > 0) {
|
||||
// Show wildcards from a file with that name
|
||||
wcMatch = [...tagword.matchAll(WC_REGEX)]
|
||||
@@ -1286,6 +1294,9 @@ async function setup() {
|
||||
acStyle.appendChild(document.createTextNode(css));
|
||||
}
|
||||
gradioApp().appendChild(acStyle);
|
||||
|
||||
// Callback
|
||||
processQueue(afterSetupQueue, null);
|
||||
}
|
||||
|
||||
onUiUpdate(async () => {
|
||||
|
||||
Reference in New Issue
Block a user