Skip to content

Commit 92f5da7

Browse files
authored
Migrate ui/settings.js (#7)
* Migrate ui/settings.js * nit
1 parent cefa452 commit 92f5da7

File tree

3 files changed

+23
-11
lines changed

3 files changed

+23
-11
lines changed

src/scripts/logging.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ export class ComfyLogging {
298298
$el("button", {
299299
textContent: "View Logs",
300300
onclick: () => {
301-
// TODO: Remove this ts-ignore when settings dialog
302-
// is migrated.
303-
// @ts-ignore
304301
this.app.ui.settings.element.close();
305302
this.dialog.show();
306303
},

src/scripts/ui.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import { api } from "./api.js";
22
import { ComfyDialog as _ComfyDialog } from "./ui/dialog.js";
33
import { toggleSwitch } from "./ui/toggleSwitch.js";
4-
import { ComfySettingsDialog } from "./ui/settings.js";
4+
import { ComfySettingsDialog } from "./ui/settings";
55

66
export const ComfyDialog = _ComfyDialog;
77

@@ -15,8 +15,8 @@ export const ComfyDialog = _ComfyDialog;
1515
* style?: CSSStyleDeclaration,
1616
* for?: string
1717
* ...any
18-
* } | undefined } propsOrChildren
19-
* @param { Element[] | undefined } [children]
18+
* } | undefined } [propsOrChildren]
19+
* @param { Element[] | Element | undefined } [children]
2020
* @returns
2121
*/
2222
export function $el(tag, propsOrChildren, children) {

src/scripts/ui/settings.js renamed to src/scripts/ui/settings.ts

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,21 @@
11
import { $el } from "../ui.js";
22
import { api } from "../api.js";
33
import { ComfyDialog } from "./dialog.js";
4+
import type { ComfyApp } from "../app.js";
5+
6+
interface Setting {
7+
id: string;
8+
onChange?: (value: any, oldValue?: any) => void;
9+
name: string;
10+
render: () => HTMLElement;
11+
}
412

513
export class ComfySettingsDialog extends ComfyDialog {
14+
app: ComfyApp;
15+
settingsValues: any;
16+
settingsLookup: Record<string, Setting>;
17+
declare element: HTMLDialogElement;
18+
619
constructor(app) {
720
super();
821
this.app = app;
@@ -40,7 +53,7 @@ export class ComfySettingsDialog extends ComfyDialog {
4053
}),
4154
]),
4255
]
43-
);
56+
) as HTMLDialogElement;
4457
}
4558

4659
get settings() {
@@ -67,10 +80,10 @@ export class ComfySettingsDialog extends ComfyDialog {
6780
return id;
6881
}
6982

70-
getSettingValue(id, defaultValue) {
83+
getSettingValue(id, defaultValue?) {
7184
let value = this.settingsValues[this.getId(id)];
72-
if(value != null) {
73-
if(this.app.storageLocation === "browser") {
85+
if (value != null) {
86+
if (this.app.storageLocation === "browser") {
7487
try {
7588
value = JSON.parse(value);
7689
} catch (error) {
@@ -288,7 +301,7 @@ export class ComfySettingsDialog extends ComfyDialog {
288301

289302
return element;
290303
},
291-
};
304+
} as Setting;
292305

293306
const self = this;
294307
return {
@@ -308,6 +321,8 @@ export class ComfySettingsDialog extends ComfyDialog {
308321
{
309322
style: { display: "none" },
310323
},
324+
// TODO remove this once ui.js is migrated.
325+
// @ts-ignore
311326
[$el("th"), $el("th", { style: { width: "33%" } })]
312327
),
313328
...this.settings.sort((a, b) => a.name.localeCompare(b.name)).map((s) => s.render())

0 commit comments

Comments
 (0)