Skip to content

Commit ad5bc8f

Browse files
authored
fix/迁移最新comfyui最新弃用api (#148)
1 parent a487ccf commit ad5bc8f

6 files changed

Lines changed: 124 additions & 8 deletions

File tree

bizyui/js/dialog/sam_edit.js

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import { api } from "../../../scripts/api.js";
22
import { ComfyApp } from "../../../scripts/app.js";
3-
import { $el, ComfyDialog, } from "../../../scripts/ui.js";
3+
import { ComfyDialog } from "../utils/dialog.js";
4+
import { $el } from "../utils/el.js";
45

56
function loadImage(imagePath) {
67
return new Promise((resolve, reject) => {
@@ -123,10 +124,16 @@ class SAMEditorDialog extends ComfyDialog {
123124

124125
is_layout_created = false;
125126
constructor() {
126-
super();
127-
this.element = $el("div.comfy-modal", { parent: document.body }, [
128-
$el("div.comfy-modal-content", [...this.createButtons()])
129-
]);
127+
super(); // super() 已经创建了 this.element,现在只需要添加按钮
128+
const content = this.element.querySelector('.comfy-modal-content');
129+
if (content) {
130+
const buttons = this.createButtons();
131+
buttons.forEach(button => {
132+
if (button instanceof Element) {
133+
content.appendChild(button);
134+
}
135+
});
136+
}
130137
}
131138
createButtons() {
132139
return [];

bizyui/js/menus.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { app } from "../../scripts/app.js";
2-
import { $el } from "../../scripts/ui.js";
2+
import { $el } from "./utils/el.js";
33
import { styleMenus } from "./subassembly/styleMenus.js";
44
import './bizyair_frontend.js'
55
class FloatingButton {

bizyui/js/subassembly/dialog.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { $el } from "../../../scripts/ui.js";
1+
import { $el } from "../utils/el.js";
22

33

44
function generateUUID() {

bizyui/js/utils/dialog.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
// 原生的 ComfyDialog 类实现,提取自 ComfyUI_frontend/src/scripts/ui/dialog.ts
2+
// 用于替代废弃的 scripts/ui.js 中的 ComfyDialog
3+
4+
import { $el } from './el.js'
5+
6+
export class ComfyDialog extends EventTarget {
7+
constructor(type = 'div', buttons = null) {
8+
super()
9+
this._buttons = buttons
10+
this.element = $el(type + '.comfy-modal', { parent: document.body }, [
11+
$el('div.comfy-modal-content', [
12+
$el('p', { $: (p) => (this.textElement = p) }),
13+
...this.createButtons()
14+
])
15+
])
16+
}
17+
18+
createButtons() {
19+
return (
20+
this._buttons ?? [
21+
$el('button', {
22+
type: 'button',
23+
textContent: 'Close',
24+
onclick: () => this.close()
25+
})
26+
]
27+
)
28+
}
29+
30+
close() {
31+
this.element.style.display = 'none'
32+
}
33+
34+
show(html) {
35+
if (typeof html === 'string') {
36+
this.textElement.innerHTML = html
37+
} else {
38+
this.textElement.replaceChildren(
39+
...(html instanceof Array ? html : [html])
40+
)
41+
}
42+
this.element.style.display = 'flex'
43+
}
44+
}
45+

bizyui/js/utils/el.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
// 原生的 $el 函数实现,提取自 ComfyUI_frontend/src/scripts/ui.ts00
2+
// 用于替代废弃的 scripts/ui.js 中的 $el
3+
4+
function $el(tag, propsOrChildren, children) {
5+
// 解析标签和类名(例如 "div.class1.class2")
6+
const split = tag.split('.')
7+
const element = document.createElement(split.shift())
8+
9+
// 添加类名
10+
if (split.length > 0) {
11+
element.classList.add(...split)
12+
}
13+
14+
if (propsOrChildren) {
15+
if (typeof propsOrChildren === 'string') {
16+
propsOrChildren = { textContent: propsOrChildren }
17+
} else if (propsOrChildren instanceof Element) {
18+
propsOrChildren = [propsOrChildren]
19+
}
20+
21+
if (Array.isArray(propsOrChildren)) {
22+
element.append(...propsOrChildren)
23+
} else {
24+
const { parent, $: cb, dataset, style, ...rest } = propsOrChildren
25+
26+
// 处理 for 属性(label 的 for 属性)
27+
if (rest.for) {
28+
element.setAttribute('for', rest.for)
29+
}
30+
31+
// 设置样式
32+
if (style) {
33+
Object.assign(element.style, style)
34+
}
35+
36+
// 设置 dataset
37+
if (dataset) {
38+
Object.assign(element.dataset, dataset)
39+
}
40+
41+
// 设置其他属性
42+
Object.assign(element, rest)
43+
44+
// 添加子元素
45+
if (children) {
46+
element.append(...(Array.isArray(children) ? children : [children]))
47+
}
48+
49+
// 添加到父元素
50+
if (parent) {
51+
parent.append(element)
52+
}
53+
54+
// 执行回调函数
55+
if (cb) {
56+
cb(element)
57+
}
58+
}
59+
}
60+
61+
return element
62+
}
63+
64+
export { $el }

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.2.78
1+
1.2.79

0 commit comments

Comments
 (0)