diff --git a/front_end/primere_keywords.js b/front_end/primere_keywords.js index bbab6d3..27cf8fc 100644 --- a/front_end/primere_keywords.js +++ b/front_end/primere_keywords.js @@ -7,76 +7,9 @@ let CKPTLoaderName = null; app.registerExtension({ name: "Primere.PrimereKeywords", - async init(app) { + /* async init(app) { - /* const lcg = LGraphCanvas.prototype.processNodeWidgets; - LGraphCanvas.prototype.processNodeWidgets = function(node, pos, event, active_widget) { - if (event.type != LiteGraph.pointerevents_method + "up") { - return lcg.call(this, node, pos, event, active_widget); - } - - if (!node.widgets || !node.widgets.length || (!this.allow_interaction && !node.flags.allow_interaction)) { - return lcg.call(this, node, pos, event, active_widget); - } - - if (node.type != CKPTLoaderName) { - return lcg.call(this, node, pos, event, active_widget); - } - - var x = pos[0] - node.pos[0]; - var y = pos[1] - node.pos[1]; - var width = node.size[0]; - var that = this; - var ref_window = this.getCanvasWindow(); - - for (var i = 0; i < node.widgets.length; ++i) { - var w = node.widgets[i]; - if (!w || w.disabled) - continue; - - var widget_height = w.computeSize ? w.computeSize(width)[1] : LiteGraph.NODE_WIDGET_HEIGHT; - var widget_width = w.width || width; - - if (w.name != 'base_model') { - return lcg.call(this, node, pos, event, active_widget); - } - - if (w != active_widget && (x < 6 || x > widget_width - 12 || y < w.last_y || y > w.last_y + widget_height || w.last_y === undefined)) - continue - - if (w == active_widget || (x > 6 && x < widget_width - 12 && y > w.last_y && y < w.last_y + widget_height)) { - var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0; - if (delta) - continue; - - var values = w.options.values; - if (values && values.constructor === Function) { - values = w.options.values(w, node); - } - - if (typeof values != 'undefined') { - function inner_clicked(v, option, event) { - sendPOSTModelName(v) - this.value = v; - that.dirty_canvas = true; - - return false; - } - - new LiteGraph.ContextMenu(values, { - scale: Math.max(1, this.ds.scale), - event: event, - className: "dark", - callback: inner_clicked.bind(w), - node: node, - widget: w, - }, ref_window); - } - } - } - return lcg.call(this, node, pos, event, active_widget); - } */ - }, + }, */ async setup(app) { await sleep(100); diff --git a/front_end/primere_output.js b/front_end/primere_output.js index bb9b010..ce38e07 100644 --- a/front_end/primere_output.js +++ b/front_end/primere_output.js @@ -67,6 +67,7 @@ app.registerExtension({ nodeType.prototype.onExecuted = function (message) { onExecuted === null || onExecuted === void 0 ? void 0 : onExecuted.apply(this, [message]); this.showValueWidget.value = message.text[0]; + app.canvas.setDirty(true) }; } @@ -226,7 +227,7 @@ api.addEventListener("getVisualTargets", VisualDataReceiver); async function VisualDataReceiver(event) { // 01 WorkflowData = event.detail - await sleep(1000); + //await sleep(1000); var img = document.querySelector('img') function loaded() { @@ -490,12 +491,6 @@ function ButtonLabelCreator(node, url = false) { PreviewExist = false; } - /* if (PreviewExist === true) { - node.addWidget("button", "View preview", null, () => { - return false; - }); - } */ - var imgExistLink = ""; if (PreviewExist === true) { let splittedMode = PrwSaveMode.split(' '); @@ -550,6 +545,7 @@ function applyWidgetValues(LoadedNode, buttontitle, TargetSelValues) { } } } + app.canvas.setDirty(true) } // ************************* sendPOSTmessage PreviewSaveResponse diff --git a/front_end/primere_visuals.js b/front_end/primere_visuals.js index 8539914..6bbc784 100644 --- a/front_end/primere_visuals.js +++ b/front_end/primere_visuals.js @@ -43,399 +43,19 @@ let RawImageDataResponse = {}; app.registerExtension({ name: "Primere.VisualMenu", - init() { - /* Promise.all([ + /* init() { + Promise.all([ fetch('extensions/Primere/keywords/lora-keyword.txt').then(x => x.text()), fetch('extensions/Primere/keywords/model-keyword.txt').then(x => x.text()) ]).then(([Lora, Model]) => { console.log(Lora); console.log(Model); - }); */ + }); + }, */ - /* let callbackfunct = null; - let modaltitle = ''; - let nodematch = ''; - let isnumeric_end = false; + /* async setup() { - const lcg = LGraphCanvas.prototype.processNodeWidgets; - LGraphCanvas.prototype.processNodeWidgets = function (node, pos, event, active_widget) { // 01 - if (event.type == 'pointermove' && validClasses.includes(node.type)) { - return false; - } - - if (!node.widgets || !node.widgets.length || (!this.allow_interaction && !node.flags.allow_interaction)) { - return lcg.call(this, node, pos, event, active_widget); - } - - if (event.type != LiteGraph.pointerevents_method + "down") { - return lcg.call(this, node, pos, event, active_widget); - } - - if (!validClasses.includes(node.type)) { - return lcg.call(this, node, pos, event, active_widget); - } - - if (stackedClasses.includes(node.type)) { - isnumeric_end = true; - } else { - isnumeric_end = false; - } - - currentClass = node.type; - - var x = pos[0] - node.pos[0]; - var y = pos[1] - node.pos[1]; - var width = node.size[0]; - var that = this; - var ShowModal = false; - - AutoFilter = null; - StackVersion = null; - ModelVersion = null; - - for (var p = 0; p < node.widgets.length; ++p) { - if (node.widgets[p].name == 'show_hidden') { - ShowHidden = node.widgets[p].value; - } - if (node.widgets[p].name == 'show_modal') { - ShowModal = node.widgets[p].value; - } - if (node.widgets[p].name == 'preview_path') { - PreviewPath = node.widgets[p].value; - } - if (node.widgets[p].name == 'aescore_percent_min') { - if (node.widgets[p].value >= 0) { - aeScoreMin = node.widgets[p].value; - } - } - if (node.widgets[p].name == 'aescore_percent_max') { - if (node.widgets[p].value > 0) { - aeScoreMax = node.widgets[p].value; - } - } - if (node.widgets[p].name == 'auto_filter') { - AutoFilter = node.widgets[p].value; - } - if (node.widgets[p].name == 'stack_version') { - StackVersion = node.widgets[p].value; - } - if (node.widgets[p].name == 'model_version') { - ModelVersion = node.widgets[p].value; - } - } - - if (ShowModal === false) { - return lcg.call(this, node, pos, event, active_widget); - } - - nodeHelper = hiddenWidgets[currentClass] - source_subdirname = nodeHelper['subdir']; - cache_key = nodeHelper['cache_key']; - - if (eventListenerInit == false) { - ModalHandler(); - } - - if ($('div.primere-modal-content div.visual-ckpt').length) { - $('div.primere-modal-content.ckpt-container').empty(); - } - - for (var i = 0; i < node.widgets.length; ++i) { - var w = node.widgets[i]; - if (!w || w.disabled) - continue; - - if (w.type != "combo") - continue; - - var widget_height = w.computeSize ? w.computeSize(width)[1] : LiteGraph.NODE_WIDGET_HEIGHT; - var widget_width = w.width || width; - widget_name = node.widgets[i].name; - - if (w != active_widget && (x < 6 || x > widget_width - 12 || y < w.last_y || y > w.last_y + widget_height || w.last_y === undefined)) - continue - - if (w == active_widget || (x > 6 && x < widget_width - 12 && y > w.last_y && y < w.last_y + widget_height)) { - var delta = x < 40 ? -1 : x > widget_width - 40 ? 1 : 0; - if (delta) - continue; - - if (widget_name.match(nodematch) && $.isNumeric(widget_name.substr(-1)) === isnumeric_end) { - SelectedModel = node.widgets[i].value; - setup_visual_modal(modaltitle, 'AllModels', ShowHidden, SelectedModel, source_subdirname, node, PreviewPath); - - callbackfunct = inner_clicked.bind(w); - function inner_clicked(v, option, event) { - inner_value_change(this, v); - that.dirty_canvas = true; - return false; - } - - function inner_value_change(widget, value) { - if (typeof nodeHelper['sortbuttons'] === "object" && typeof nodeHelper['sortbuttons'][0] === "object" && nodeHelper['sortbuttons'][0].indexOf("Path") == -1) { - for (var i = 0; i < node.widgets.length; ++i) { - var widget_type = node.widgets[i].type; - var widget_value = node.widgets[i].value; - if (widget_type == 'combo' && widget_value != 'None') { - widget_name = node.widgets[i].name; - node.widgets[i].value = 'None'; - } - } - } - if (widget.type == "number") { - value = Number(value); - } - widget.value = value; - if (widget.options && widget.options.property && node.properties[widget.options.property] !== undefined) { - node.setProperty(widget.options.property, value); - } - if (widget.callback) { - widget.callback(widget.value, that, node, pos, event); - } - } - return null; - } - } - } - - function ModalHandler() { // 02 - eventListenerInit = true; - let head = document.getElementsByTagName('HEAD')[0]; - //let link = document.createElement('link'); - //link.rel = 'stylesheet'; - //link.type = 'text/css'; - //link.href = realPath + '/css/visual.css'; - //head.appendChild(link); - - let js = document.createElement("script"); - js.src = realPath + "/jquery/jquery-1.9.0.min.js"; - head.appendChild(js); - - js.onload = function(e) { - $(document).ready(function () { - var modal = null; - - $('body').on("click", 'button.modal-closer', async function () { // modal close - modal = document.getElementById("primere_visual_modal"); - modal.setAttribute('style', 'display: none; width: 80%; height: 70%;') - var lastDirValue = 'All' - if (lastDirObject.hasOwnProperty(currentClass) === true) { - lastDirValue = lastDirObject[currentClass]; - } - - if (typeof nodeHelper['sortbuttons'] !== "object" || typeof nodeHelper['sortbuttons'][0] !== "object" || nodeHelper['sortbuttons'][0].indexOf("Path") > -1) { - if (AutoFilter !== true) { - await categoryHandler(lastDirValue, 'add', 'last_visual_category' + '_' + cache_key); - await categoryHandler(FilterType, 'add', 'last_visual_category_type' + '_' + cache_key); - var filter = $('body div.subdirtab input').val(); - await categoryHandler(filter, 'add', 'last_visual_filter' + '_' + cache_key); - await categoryHandler(sortType, 'add', 'last_visual_sort_type' + '_' + cache_key); - await categoryHandler(operator, 'add', 'last_visual_sort_operator' + '_' + cache_key); - } - } - }); - - $('body').on("click", 'div.primere-modal-content div.visual-ckpt img', async function () { // image choosen - var ckptName = $(this).data('ckptname'); - modal = document.getElementById("primere_visual_modal"); - modal.setAttribute('style', 'display: none; width: 80%; height: 70%;') - var lastDirValue = 'All' - if (lastDirObject.hasOwnProperty(currentClass) === true) { - lastDirValue = lastDirObject[currentClass]; - } - - if (source_subdirname == 'styles') { - let pathLastIndex = ckptName.lastIndexOf('\\'); - ckptName = ckptName.substring(pathLastIndex + 1); - } - - apply_modal(ckptName); - - if (typeof nodeHelper['sortbuttons'] !== "object" || typeof nodeHelper['sortbuttons'][0] !== "object" || nodeHelper['sortbuttons'][0].indexOf("Path") > -1) { - if (AutoFilter !== true) { - await categoryHandler(lastDirValue, 'add', 'last_visual_category' + '_' + cache_key); - await categoryHandler(FilterType, 'add', 'last_visual_category_type' + '_' + cache_key); - var filter = $('body div.subdirtab input').val(); - await categoryHandler(filter, 'add', 'last_visual_filter' + '_' + cache_key); - await categoryHandler(sortType, 'add', 'last_visual_sort_type' + '_' + cache_key); - await categoryHandler(operator, 'add', 'last_visual_sort_operator' + '_' + cache_key); - } - } - }); - - var subdirName = 'All'; - var filteredCheckpoints = 0; - $('body').on("click", 'div.subdirtab button.subdirfilter', async function () { // subdir filter - $('div.subdirtab input').val(''); - subdirName = $(this).data('ckptsubdir'); - if (currentClass !== false) { - lastDirObject[currentClass] = subdirName - } - - var imageContainers = $('div.primere-modal-content div.visual-ckpt'); - filteredCheckpoints = 0; - $(imageContainers).each(function (cont_index, cont_obj) { - if ($(cont_obj).find('img').parent().closest(".visual-ckpt-selected").length === 0) { - cont_obj.remove(); - } - }); - - if (source_subdirname != 'styles') { - ModelsByVersion = await getModelData(cache_key + '_version'); - } - ModelList = await getModelDatabyPath(source_subdirname, subdirName); - - if (source_subdirname == 'styles') { - if (ModelList.includes(SelectedModel) || ModelList.includes(subdirName + '\\' + SelectedModel)) { - var index_pre = (ModelList.indexOf(SelectedModel) + ModelList.indexOf(subdirName + '\\' + SelectedModel)) + 1; - if (index_pre !== -1) { - await ModelList.splice(index_pre, 1); - } - } - } - - for (var checkpoint of ModelList) { - //$(ModelList).each(async function (checkpoint_index, checkpoint) { - let firstletter = checkpoint.charAt(0); - - var filterpass = true; - if (SelectedModel == checkpoint) { - filterpass = false; - } - - if (((firstletter === '.' && ShowHidden === true) || firstletter !== '.') && ((checkpoint.match('^NSFW') && ShowHidden === true) || !checkpoint.match('^NSFW')) && filterpass == true) { - let pathLastIndex = checkpoint.lastIndexOf('\\'); - let ckptName_full = checkpoint.substring(pathLastIndex + 1); - let dotLastIndex = ckptName_full.lastIndexOf('.'); - var ckptName = ckptName_full.substring(0, dotLastIndex); - var CategoryName = 'Unknown'; - - $.each(ModelsByVersion, function (ver_index, ver_value) { - if (ver_value.includes(ckptName)) { - CategoryName = ver_index - } - }); - - var container = $('div.primere-modal-content.ckpt-container')[0]; - if (subdirName === 'Root') { - let isSubdirExist = checkpoint.lastIndexOf('\\'); - if (isSubdirExist < 0) { - filteredCheckpoints++; - await createCardElement(checkpoint, container, SelectedModel, source_subdirname, CategoryName) - } - } else { - filteredCheckpoints++; - await createCardElement(checkpoint, container, SelectedModel, source_subdirname, CategoryName) - } - } - $('div#primere_visual_modal div.modal_header label.ckpt-counter').text(filteredCheckpoints); - } - //await sleep(600); - previewSorter(operator, sortType); - - $('div#primere_visual_modal div.modal_header label.ckpt-name').text(subdirName); - $('div#primere_visual_modal div.modal_header label.ckpt-ver').text('Subdir'); - $('div.subdirtab button').not('button.preview_sort').not('button.preview_sort_direction').removeClass("selected_path"); - $(this).addClass('selected_path'); - FilterType = 'Subdir'; - }); - - $('body').on("click", 'div.subdirtab button.verfilter', async function () { // model version filter - $('div.subdirtab input').val(''); - var versionName = $(this).data('ckptver'); - if (currentClass !== false) { - lastDirObject[currentClass] = versionName - } - var imageContainers = $('div.primere-modal-content div.visual-ckpt'); - filteredCheckpoints = 0; - $(imageContainers).each(function (cont_index, cont_obj) { - if ($(cont_obj).find('img').parent().closest(".visual-ckpt-selected").length === 0) { - cont_obj.remove(); - } - }); - - ModelList = await getModelDatabyVersion(source_subdirname, cache_key + '_version', versionName); - - for (var checkpoint of ModelList) { - let firstletter = checkpoint.charAt(0); - var filterpass = true; - if (SelectedModel == checkpoint) { - filterpass = false; - } - if (((firstletter === '.' && ShowHidden === true) || firstletter !== '.') && ((checkpoint.match('^NSFW') && ShowHidden === true) || !checkpoint.match('^NSFW')) && filterpass == true) { - filteredCheckpoints++; - var container = $('div.primere-modal-content.ckpt-container')[0]; - await createCardElement(checkpoint, container, SelectedModel, source_subdirname, versionName) - } - $('div#primere_visual_modal div.modal_header label.ckpt-counter').text(filteredCheckpoints); - } - - //await sleep(600); - previewSorter(operator, sortType); - - $('div#primere_visual_modal div.modal_header label.ckpt-name').text(versionName); - $('div#primere_visual_modal div.modal_header label.ckpt-ver').text('Version'); - $('div.subdirtab button').not('button.preview_sort').not('button.preview_sort_direction').removeClass("selected_path"); - $(this).addClass('selected_path'); - FilterType = 'Version'; - }); - - $('body').on("keyup", 'div.subdirtab input', function() { // keyword filter - var filter = $(this).val(); - previewFilter(filter); - }); - - $('body').on("click", 'div.subdirtab button.filter_clear', function() { // keyword inut clear - $('div.subdirtab input').val(''); - var imageContainers = $('div.primere-modal-content div.visual-ckpt'); - filteredCheckpoints = 0; - $(imageContainers).find('img').each(function (img_index, img_obj) { - $(img_obj).parent().show(); - filteredCheckpoints++; - }); - $('div#primere_visual_modal div.modal_header label.ckpt-counter').text(filteredCheckpoints - 1); - }); - - $('body').on("click", 'div.subdirtab button.preview_sort', function() { // preview sort type - sortType = $(this).data('sortsource'); - operator = $('button.preview_sort_direction').text(); - previewSorter(operator, sortType); - $('div.subdirtab button.preview_sort').removeClass("selected_path"); - $(this).addClass('selected_path'); - }); - - $('body').on("click", 'div.subdirtab button.preview_sort_direction', function () { // preview sort direction - operator = $('button.preview_sort_direction').text(); - if (operator == 'ASC') { - $('button.preview_sort_direction').text('DESC'); - operator = 'DESC'; - $('div.subdirtab button.preview_sort_direction').addClass("selected_path"); - } else { - $('button.preview_sort_direction').text('ASC'); - operator = 'ASC'; - $('div.subdirtab button.preview_sort_direction').removeClass("selected_path"); - } - previewSorter(operator, sortType); - }); - }); - }; - } - - function apply_modal(Selected) { // apply - if (Selected && typeof callbackfunct == 'function') { - callbackfunct(Selected); - sendPOSTModelName(Selected); - return false; - } - } - - return lcg.call(this, node, pos, event, active_widget); - } */ - }, - - async setup() { - - }, + }, */ async beforeRegisterNodeDef(nodeType, nodeData, app) { // 0 if (validClasses.includes(nodeData.name)) { @@ -541,7 +161,7 @@ class ModalControl { callbackfunct = inner_clicked.bind(widget_object); function inner_clicked(value, option, event) { inner_value_change(widget_object, value); - //this.dirty_canvas = true; + app.canvas.setDirty(true) return false; } @@ -549,7 +169,6 @@ class ModalControl { if (typeof nodeHelper['sortbuttons'] === "object" && typeof nodeHelper['sortbuttons'][0] === "object" && nodeHelper['sortbuttons'][0].indexOf("Path") == -1) { for (var ic = 0; ic < node_object.widgets.length; ++ic) { if (node_object.widgets[ic].type == 'combo' && node_object.widgets[ic].value != 'None') { - //widget_name = node.widgets[i].name; node_object.widgets[ic].value = 'None'; } }