|
| 1 | +import { ComfyWidgets } from "../../scripts/widgets.js"; |
| 2 | +import { app } from "../../scripts/app.js"; |
| 3 | +import * as shared from "./comfy_shared.js"; |
| 4 | + |
| 5 | + |
| 6 | +class DragNUWAImageCanvas extends LiteGraph.LGraghNode { |
| 7 | + title = "DragNUWACanvas" |
| 8 | + category = "komojini/image" |
| 9 | + |
| 10 | + color = LGraphCanvas.node_colors.yellow.color |
| 11 | + bgcolor = LGraphCanvas.node_colors.yellow.bgcolor |
| 12 | + groupcolor = LGraphCanvas.node_colors.yellow.groupcolor |
| 13 | + |
| 14 | + constructor() { |
| 15 | + super() |
| 16 | + this.uuid = shared.makeUUID() |
| 17 | + |
| 18 | + shared.log(`Constructing DRAGNUWACanvas instance`) |
| 19 | + |
| 20 | + this.collapsable = true |
| 21 | + this.isVirtualNode = true |
| 22 | + this.shape = LiteGraph.BOX_SHAPE |
| 23 | + this.serialize_widgets = true |
| 24 | + |
| 25 | + const inner = document.createElement("div") |
| 26 | + inner.style.margin = "0" |
| 27 | + inner.style.padding = "0" |
| 28 | + inner.style.pointerEvents = "none" |
| 29 | + |
| 30 | + this.calculatedHeight = 0 |
| 31 | + |
| 32 | + this.htmlWidget = this.addDOMWidget("HTML", "html", inner, { |
| 33 | + setValue: (val) => { |
| 34 | + this._raw_html = val |
| 35 | + }, |
| 36 | + getValue: () => this._raw_html, |
| 37 | + getMinHeight: () => this.calculatedHeight, |
| 38 | + hideOnZoom: false, |
| 39 | + }) |
| 40 | + |
| 41 | + this.setupDialog() |
| 42 | + } |
| 43 | + |
| 44 | + setupDialog() { |
| 45 | + this.dialog = new app.ui.dialog.constructor() |
| 46 | + this.dialog.element.classList.add('comfy-settings') |
| 47 | + |
| 48 | + const closeButton = this.dialog.element.querySelector('button') |
| 49 | + closeButton.textContent = 'CANCEL' |
| 50 | + const saveButton = document.createElement('button') |
| 51 | + saveButton.textContent = 'SAVE' |
| 52 | + saveButton.onclick = () => { |
| 53 | + this.closeEditorDialog(true) |
| 54 | + } |
| 55 | + closeButton.onclick = () => { |
| 56 | + this.closeEditorDialog(false) |
| 57 | + } |
| 58 | + closeButton.before(saveButton) |
| 59 | + } |
| 60 | + |
| 61 | + openEditorDialog() { |
| 62 | + const container = document.createElement("div") |
| 63 | + |
| 64 | + Object.assign(container.style, { |
| 65 | + display: 'flex', |
| 66 | + gap: '10px', |
| 67 | + flexDirection: 'column', |
| 68 | + }) |
| 69 | + |
| 70 | + const editorsContainer = document.createElement('div') |
| 71 | + Object.assign(editorsContainer.style, { |
| 72 | + display: 'flex', |
| 73 | + gap: '10px', |
| 74 | + flexDirection: 'row', |
| 75 | + }) |
| 76 | + |
| 77 | + container.append(editorsContainer) |
| 78 | + |
| 79 | + this.dialog.show('') |
| 80 | + this.dialog.textElement.append(container) |
| 81 | + } |
| 82 | + |
| 83 | + onCreate() {} |
| 84 | + onNodeCreated() {} |
| 85 | + onRemoved() {} |
| 86 | + getExtraMenuOptions() {} |
| 87 | + setMode(mode) {} |
| 88 | + |
| 89 | +} |
| 90 | + |
| 91 | +const komojiniCanvas = { |
| 92 | + name: "komojini.image", |
| 93 | + init: async () => {}, |
| 94 | + setup: () => {}, |
| 95 | + async beforeRegisterNodeDef(nodeType, nodeData, app) {}, |
| 96 | + |
| 97 | + registerCustomNodes() { |
| 98 | + |
| 99 | + LiteGraph.registerNodeType("DragNUWAImageCanvas", DragNUWAImageCanvas) |
| 100 | + |
| 101 | + DragNUWAImageCanvas.title_mode = LiteGraph.NO_TITLE |
| 102 | + |
| 103 | + TestNode.category = "komojini.canvas"; |
| 104 | + }, |
| 105 | +} |
| 106 | + |
| 107 | +app.registerExtension(komojiniCanvas) |
0 commit comments