diff --git a/html/extra-networks-tree-button.html b/html/extra-networks-tree-button.html
index 920330f7a..9fb0ec799 100644
--- a/html/extra-networks-tree-button.html
+++ b/html/extra-networks-tree-button.html
@@ -1,11 +1,22 @@
{search_terms}
-
- 🗎
- {name}
-
- {copy_path_button}{metadata_button}{edit_button}
+
+ {action_list_item_action_leading}
+
+
+ {action_list_item_visual_leading}
+
+
+ {action_list_item_label}
+
+
+ {action_list_item_visual_trailing}
+
+
+ {action_list_item_action_trailing}
\ No newline at end of file
diff --git a/javascript/extraNetworks.js b/javascript/extraNetworks.js
index 97a97d61f..56c9dc4c3 100644
--- a/javascript/extraNetworks.js
+++ b/javascript/extraNetworks.js
@@ -267,7 +267,7 @@ function extraNetworksTreeProcessFileClick(event, btn, tabname, tab_id) {
* Processes `onclick` events when user clicks on files in tree.
*
* @param event The generated event.
- * @param btn The clicked `action-list-item` button.
+ * @param btn The clicked `tree-list-item` button.
* @param tabname The name of the active tab in the sd webui. Ex: txt2img, img2img, etc.
* @param tab_id The id of the active extraNetworks tab. Ex: lora, checkpoints, etc.
*/
@@ -288,7 +288,7 @@ function extraNetworksTreeProcessDirectoryClick(event, btn, tabname, tab_id) {
* chevron is clicked: Directory is expanded or collapsed. Selected state unchanged.
*
* @param event The generated event.
- * @param btn The clicked `action-list-item` button.
+ * @param btn The clicked `tree-list-item` button.
* @param tabname The name of the active tab in the sd webui. Ex: txt2img, img2img, etc.
* @param tab_id The id of the active extraNetworks tab. Ex: lora, checkpoints, etc.
*/
@@ -310,7 +310,7 @@ function extraNetworksTreeProcessDirectoryClick(event, btn, tabname, tab_id) {
function _remove_selected_from_all() {
// Removes the `selected` attribute from all buttons.
- var sels = document.querySelectorAll("button.action-list-content");
+ var sels = document.querySelectorAll("button.tree-list-content");
[...sels].forEach(el => {
el.removeAttribute("selected");
});
@@ -331,7 +331,7 @@ function extraNetworksTreeProcessDirectoryClick(event, btn, tabname, tab_id) {
// If user clicks on the chevron, then we do not select the folder.
- if (true_targ.matches(".action-list-item-action--leading, .action-list-item-action-chevron")) {
+ if (true_targ.matches(".tree-list-item-action--leading, .tree-list-item-action-chevron")) {
_expand_or_collapse(ul, btn);
} else {
// User clicked anywhere else on the button.
@@ -356,7 +356,7 @@ function extraNetworksTreeProcessDirectoryClick(event, btn, tabname, tab_id) {
function extraNetworksTreeOnClick(event, tabname, tab_id) {
/**
- * Handles `onclick` events for buttons within an `extra-network-tree .action-list--tree`.
+ * Handles `onclick` events for buttons within an `extra-network-tree .tree-list--tree`.
*
* Determines whether the clicked button in the tree is for a file entry or a directory
* then calls the appropriate function.
diff --git a/modules/ui_extra_networks.py b/modules/ui_extra_networks.py
index 9cf5b57fb..a49c6c1c5 100644
--- a/modules/ui_extra_networks.py
+++ b/modules/ui_extra_networks.py
@@ -20,28 +20,28 @@ allowed_dirs = set()
default_allowed_preview_extensions = ["png", "jpg", "jpeg", "webp", "gif"]
tree_tpl = (
- "
"
+ "
"
" "
"
"
- "
"
+ ""
)
tree_ul_tpl = (
- ""
+ ""
)
tree_li_dir_tpl = (
""
"{content}"
@@ -50,59 +50,19 @@ tree_li_dir_tpl = (
tree_li_file_tpl = (
" "
"{content}"
" "
)
-tree_btn_dir_tpl = (
- ""
- ""
- " "
+action_list_item_action_leading = (
+ ""
+ " "
" "
- "🗀 "
- "{label} "
- " "
)
-tree_btn_file_action_buttons_tpl = (
- ""
- "
"
- ""
- "
"
- ""
- "
"
-)
-
-tree_btn_file_tpl = (
- "{filter} "
- ""
- "🗎 "
- "{label} "
- "{buttons} "
- " "
-)
-
-
@functools.cache
def allowed_preview_extensions_with_extra(extra_extensions=None):
return set(default_allowed_preview_extensions) | set(extra_extensions or [])
@@ -243,7 +203,6 @@ class ExtraNetworksPage:
self.id_page = self.name.replace(" ", "_")
self.extra_networks_pane_template = shared.html("extra-networks-pane.html")
self.card_page_template = shared.html("extra-networks-card.html")
- self.card_page_minimal_template = shared.html("extra-networks-card-minimal.html")
self.tree_button_template = shared.html("extra-networks-tree-button.html")
self.allow_prompt = True
self.allow_negative_prompt = False
@@ -278,7 +237,12 @@ class ExtraNetworksPage:
return ""
- def create_item_html(self, tabname: str, item: dict, template: Optional[str] = None) -> str:
+ def create_item_html(
+ self,
+ tabname: str,
+ item: dict,
+ template: Optional[str] = None,
+ ) -> Union[str, dict]:
"""Generates HTML for a single ExtraNetworks Item
Args:
@@ -301,19 +265,32 @@ class ExtraNetworksPage:
width = f"width: {shared.opts.extra_networks_card_width}px;" if shared.opts.extra_networks_card_width else ''
background_image = f' ' if preview else ''
+
onclick = item.get("onclick", None)
if onclick is None:
- if "negative_prompt" in item:
- onclick = '"' + html.escape(f"""return cardClicked({quote_js(tabname)}, {item["prompt"]}, {item["negative_prompt"]}, {"true" if self.allow_negative_prompt else "false"})""") + '"'
- else:
- onclick = '"' + html.escape(f"""return cardClicked({quote_js(tabname)}, {item["prompt"]}, {'""'}, {"true" if self.allow_negative_prompt else "false"})""") + '"'
-
+ print("HERE")
+ print("TABNAME:", tabname)
+ print("PROMPT:", item["prompt"])
+ print("NEG_PROMPT:", item.get("negative_prompt", ""))
+ print("ALLOW_NEG:", self.allow_negative_prompt)
+ onclick_js_tpl = "cardClicked('{tabname}', '{prompt}', '{neg_prompt}', '{allow_neg}');"
+ onclick = onclick_js_tpl.format(
+ **{
+ "tabname": tabname,
+ "prompt": item["prompt"],
+ "neg_prompt": item.get("negative_prompt", ""),
+ "allow_neg": "true" if self.allow_negative_prompt else "false"
+ }
+ )
+ onclick = html.escape(onclick)
+
+
copy_path_button = f"
"
metadata_button = ""
metadata = item.get("metadata")
if metadata:
- metadata_button = f"
"
+ metadata_button = f"
"
edit_button = f"
"
@@ -335,7 +312,12 @@ class ExtraNetworksPage:
if search_only and shared.opts.extra_networks_hidden_models == "Never":
return ""
- sort_keys = " ".join([f'data-sort-{k}="{html.escape(str(v))}"' for k, v in item.get("sort_keys", {}).items()]).strip()
+ sort_keys = " ".join(
+ [
+ f'data-sort-{k}="{html.escape(str(v))}"'
+ for k, v in item.get("sort_keys", {}).items()
+ ]
+ ).strip()
search_terms_html = ""
search_term_template = "{search_term} "
@@ -366,13 +348,12 @@ class ExtraNetworksPage:
"style": f"'display: none; {height}{width}; font-size: {shared.opts.extra_networks_card_text_scale*100}%'",
"tabname": tabname,
"tab_id": self.id_page,
-
}
if template:
return template.format(**args)
else:
- return self.card_page.format(**args)
+ return args
def create_tree_view_html(self, tabname: str) -> str:
"""Generates HTML for displaying folders in a tree view.
@@ -393,73 +374,94 @@ class ExtraNetworksPage:
if not tree:
return res
- def _build_tree(data: Optional[dict[str, ExtraNetworksItem]] = None) -> str:
+ def _build_tree(data: Optional[dict[str, ExtraNetworksItem]] = None) -> Optional[str]:
"""Recursively builds HTML for a tree."""
- _res = ""
if not data:
- return (
- ""
- "Directory is empty "
- " "
- )
+ return None
+
+ # Lists for storing items html for directories and files separately.
+ _dir_li = []
+ _file_li = []
for k, v in sorted(data.items(), key=lambda x: shared.natural_sort_key(x[0])):
if isinstance(v, (ExtraNetworksItem,)):
- _action_buttons = tree_btn_file_action_buttons_tpl.format(
- **{
- "path": quote_js(k),
- "filename": quote_js(v.item["name"]),
- "tabname": quote_js(tabname),
- "tab_id": quote_js(self.id_page),
- }
+ _item_html_args = self.create_item_html(tabname, v.item)
+ _action_buttons = "".join(
+ [
+ _item_html_args["copy_path_button"],
+ _item_html_args["metadata_button"],
+ _item_html_args["edit_button"],
+ ]
)
- _btn = tree_btn_file_tpl.format(
+ _action_buttons = f"{_action_buttons}
"
+ _btn = self.tree_button_template.format(
**{
- "label": v.item["name"],
- "filter": v.item["search_terms"],
+ "search_terms": "",
+ "subclass": "tree-list-content-file",
"tabname": tabname,
"tab_id": self.id_page,
- "buttons": _action_buttons,
+ "onclick_extra": _item_html_args["card_clicked"],
+ "action_list_item_action_leading": action_list_item_action_leading,
+ "action_list_item_visual_leading": "🗎",
+ "action_list_item_label": v.item["name"],
+ "action_list_item_visual_trailing": "",
+ "action_list_item_action_trailing": _action_buttons,
}
)
+
_li = tree_li_file_tpl.format(
**{
"hash": v.item["shorthash"],
"path": k,
"type": "file",
- #"content": _btn,
- "content": self.create_item_html(tabname, v.item, self.tree_button_template),
+ "content": _btn,
}
)
- _res += _li
- #item_html = self.create_item_html(tabname, v.item, self.card_page_minimal_template)
- #_res += file_template.format(**{"card": item_html})
+ _file_li.append(_li)
else:
- _btn = tree_btn_dir_tpl.format(
+ _btn = self.tree_button_template.format(
**{
- "label": os.path.basename(k),
+ "search_terms": "",
+ "subclass": "tree-list-content-dir",
"tabname": tabname,
"tab_id": self.id_page,
+ "onclick_extra": "",
+ "action_list_item_action_leading": action_list_item_action_leading,
+ "action_list_item_visual_leading": "🗀",
+ "action_list_item_label": os.path.basename(k),
+ "action_list_item_visual_trailing": "",
+ "action_list_item_action_trailing": "",
}
)
_ul = tree_ul_tpl.format(**{"content": _build_tree(v)})
_li = tree_li_dir_tpl.format(**{"content": _btn + _ul, "path": k})
- _res += _li
- return _res
+ _dir_li.append(_li)
+
+ # Directories should always be displayed before files.
+ return "".join(_dir_li) + "".join(_file_li)
# Add each root directory to the tree.
for k, v in sorted(tree.items(), key=lambda x: shared.natural_sort_key(x[0])):
# If root is empty, append the "disabled" attribute to the template details tag.
- btn = tree_btn_dir_tpl.format(
+ btn = self.tree_button_template.format(
**{
- "label": os.path.basename(k),
+ "search_terms": "",
+ "subclass": "tree-list-content-dir",
"tabname": tabname,
"tab_id": self.id_page,
+ "onclick_extra": "",
+ "action_list_item_action_leading": action_list_item_action_leading,
+ "action_list_item_visual_leading": "🗀",
+ "action_list_item_label": os.path.basename(k),
+ "action_list_item_visual_trailing": "",
+ "action_list_item_action_trailing": "",
}
)
- ul = tree_ul_tpl.format(**{"content": _build_tree(v)})
- li = tree_li_dir_tpl.format(**{"content": btn + ul, "path": k})
- res += li
+ subtree = _build_tree(v)
+ if subtree:
+ ul = tree_ul_tpl.format(**{"content": _build_tree(v)})
+ li = tree_li_dir_tpl.format(**{"content": btn + ul, "path": k})
+ res += li
return tree_tpl.format(
**{
@@ -473,6 +475,7 @@ class ExtraNetworksPage:
res = ""
self.items = {x["name"]: x for x in self.list_items()}
for item in self.items.values():
+ print("HEEEERRE:", item)
res += self.create_item_html(tabname, item, self.card_page_template)
if res == "":
diff --git a/style.css b/style.css
index 8aa41088d..2dafe97fd 100644
--- a/style.css
+++ b/style.css
@@ -929,7 +929,7 @@ footer {
margin-left: 0.5em;
}
-.extra-network-pane :is(.card, .card-minimal) .button-row{
+.extra-network-pane .card .button-row{
display: inline-flex;
visibility: hidden;
color: white;
@@ -941,13 +941,7 @@ footer {
z-index: 1;
}
-.extra-network-pane .card-minimal .button-row {
- padding-left: 0.5rem;
- padding-right: 0.5rem;
- align-items: center;
-}
-
-.extra-network-pane :is(.card:hover, .card-minimal:hover) .button-row{
+.extra-network-pane .card:hover .button-row{
visibility: visible;
}
@@ -1110,9 +1104,6 @@ div.block.gradio-box.edit-user-metadata {
margin-top: 1.5em;
}
-
-
-
div.block.gradio-box.popup-dialog, .popup-dialog {
width: 56em;
background: var(--body-background-fill);
@@ -1205,7 +1196,7 @@ body.resizing .resize-handle {
overflow: hidden;
}
-.extra-network-tree .action-list--tree {
+.extra-network-tree .tree-list--tree {
cursor: pointer;
-webkit-user-select: none;
-moz-user-select: none;
@@ -1213,43 +1204,42 @@ body.resizing .resize-handle {
user-select: none;
margin: 0;
padding: 0;
+ margin-left: 0.25rem;
}
/* Remove auto indentation from tree. Will be overridden later. */
-.extra-network-tree .action-list--subgroup {
+.extra-network-tree .tree-list--subgroup {
margin: 0 !important;
padding: 0 !important;
- box-shadow: 0.6rem 0 0 var(--body-background-fill) inset,
- 0.8rem 0 0 var(--neutral-800) inset;
+ box-shadow: 0.5rem 0 0 var(--body-background-fill) inset,
+ 0.7rem 0 0 var(--neutral-800) inset;
}
/* Set indentation for each depth of tree. */
-.extra-network-tree .action-list--subgroup > .action-list-item {
+.extra-network-tree .tree-list--subgroup > .tree-list-item {
margin-left: 0.4rem !important;
padding-left: 0.4rem !important;
}
/* Styles for tree elements. */
-.extra-network-tree .action-list {
-
-}
+.extra-network-tree .tree-list {}
/* Styles for tree elements. */
-.extra-network-tree .action-list-item {
+.extra-network-tree .tree-list-item {
list-style: none;
position: relative;
background-color: transparent;
}
-/* Directory */
-.extra-network-tree .action-list-content[expanded=false]+.action-list--subgroup {
+/* Directory visibility based on expanded attribute. */
+.extra-network-tree .tree-list-content[expanded=false]+.tree-list--subgroup {
height: 0;
overflow: hidden;
visibility: hidden;
opacity: 0;
}
-.extra-network-tree .action-list-content[expanded=true]+.action-list--subgroup {
+.extra-network-tree .tree-list-content[expanded=true]+.tree-list--subgroup {
height: auto;
overflow: visible;
visibility: visible;
@@ -1257,20 +1247,25 @@ body.resizing .resize-handle {
}
/* File */
-.extra-network-tree .action-list-item--subitem {
+.extra-network-tree .tree-list-item--subitem {
+ padding-top: 0 !important;
+ padding-bottom: 0 !important;
+ margin-top: 0 !important;
+ margin-bottom: 0 !important;
}
/* containing