Replace window.prompt with custom prompt impl (#1847)

* Replace window.prompt with custom prompt impl

* Update locales [skip ci]

---------

Co-authored-by: github-actions <github-actions@github.com>
This commit is contained in:
Chenlei Hu
2024-12-08 13:55:32 -08:00
committed by GitHub
parent 1671437fb3
commit aa04ab78c1
7 changed files with 59 additions and 7 deletions

View File

@@ -14,6 +14,8 @@ import {
serialise
} from '@/extensions/core/vintageClipboard'
import type { ComfyNodeDef } from '@/types/apiTypes'
import { showPromptDialog } from '@/services/dialogService'
import { t } from '@/i18n'
type GroupNodeWorkflowData = {
external: ComfyLink[]
@@ -63,8 +65,8 @@ class GroupNodeBuilder {
this.nodes = nodes
}
build() {
const name = this.getName()
async build() {
const name = await this.getName()
if (!name) return
// Sort the nodes so they are in execution order
@@ -77,8 +79,12 @@ class GroupNodeBuilder {
return { name, nodeData: this.nodeData }
}
getName() {
const name = prompt('Enter group name')
async getName() {
const name = await showPromptDialog({
title: t('groupNode.create'),
message: t('groupNode.enterName'),
defaultValue: ''
})
if (!name) return
const used = Workflow.isInUseGroupNode(name)
switch (used) {
@@ -1379,7 +1385,7 @@ export class GroupNodeHandler {
static async fromNodes(nodes: LGraphNode[]) {
// Process the nodes into the stored workflow group node data
const builder = new GroupNodeBuilder(nodes)
const res = builder.build()
const res = await builder.build()
if (!res) return
const { name, nodeData } = res

View File

@@ -6,6 +6,8 @@ import { GroupNodeConfig, GroupNodeHandler } from './groupNode'
import { LGraphCanvas } from '@comfyorg/litegraph'
import { useToastStore } from '@/stores/toastStore'
import { deserialiseAndCreate } from '@/extensions/core/vintageClipboard'
import { showPromptDialog } from '@/services/dialogService'
import { t } from '@/i18n'
// Adds the ability to save and add multiple nodes as a template
// To save:
@@ -348,8 +350,12 @@ app.registerExtension({
options.push({
content: `Save Selected as Template`,
disabled: !Object.keys(app.canvas.selected_nodes || {}).length,
callback: () => {
const name = prompt('Enter name')
callback: async () => {
const name = await showPromptDialog({
title: t('nodeTemplates.saveAsTemplate'),
message: t('nodeTemplates.enterName'),
defaultValue: ''
})
if (!name?.trim()) return
clipboardAction(() => {