From aa04ab78c1f6406b55420103efca3a83e00917df Mon Sep 17 00:00:00 2001 From: Chenlei Hu Date: Sun, 8 Dec 2024 13:55:32 -0800 Subject: [PATCH] Replace window.prompt with custom prompt impl (#1847) * Replace window.prompt with custom prompt impl * Update locales [skip ci] --------- Co-authored-by: github-actions --- src/extensions/core/groupNode.ts | 16 +++++++++++----- src/extensions/core/nodeTemplates.ts | 10 ++++++++-- src/locales/en.json | 8 ++++++++ src/locales/ja.json | 8 ++++++++ src/locales/ko.json | 8 ++++++++ src/locales/ru.json | 8 ++++++++ src/locales/zh.json | 8 ++++++++ 7 files changed, 59 insertions(+), 7 deletions(-) diff --git a/src/extensions/core/groupNode.ts b/src/extensions/core/groupNode.ts index 8aeec594a..e6c739519 100644 --- a/src/extensions/core/groupNode.ts +++ b/src/extensions/core/groupNode.ts @@ -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 diff --git a/src/extensions/core/nodeTemplates.ts b/src/extensions/core/nodeTemplates.ts index 43522a4b4..adebc7996 100644 --- a/src/extensions/core/nodeTemplates.ts +++ b/src/extensions/core/nodeTemplates.ts @@ -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(() => { diff --git a/src/locales/en.json b/src/locales/en.json index adad4f8ad..2cb6dad5f 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -543,6 +543,14 @@ "panMode": "Pan Mode", "toggleLinkVisibility": "Toggle Link Visibility" }, + "groupNode": { + "create": "Create group node", + "enterName": "Enter name" + }, + "nodeTemplates": { + "saveAsTemplate": "Save as template", + "enterName": "Enter name" + }, "electronFileDownload": { "inProgress": "In Progress", "pause": "Pause Download", diff --git a/src/locales/ja.json b/src/locales/ja.json index 536124e6a..e5cf06bbf 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -99,6 +99,10 @@ "zoomIn": "拡大", "zoomOut": "縮小" }, + "groupNode": { + "create": "グループノードを作成", + "enterName": "名前を入力" + }, "icon": { "bookmark": "ブックマーク", "box": "ボックス", @@ -1087,6 +1091,10 @@ "display_name": "unCLIP条件付け" } }, + "nodeTemplates": { + "enterName": "名前を入力", + "saveAsTemplate": "テンプレートとして保存" + }, "notSupported": { "continue": "続ける", "continueTooltip": "私のデバイスはサポートされていると確信しています", diff --git a/src/locales/ko.json b/src/locales/ko.json index 56981b0aa..d373b9c63 100644 --- a/src/locales/ko.json +++ b/src/locales/ko.json @@ -91,6 +91,10 @@ "zoomIn": "확대", "zoomOut": "축소" }, + "groupNode": { + "create": "그룹 노드 만들기", + "enterName": "이름 입력" + }, "icon": "아이콘", "install": { "appDataLocationTooltip": "ComfyUI의 앱 데이터 디렉토리. 저장소:\n- 로그\n- 서버 구성", @@ -1070,6 +1074,10 @@ "display_name": "unCLIP 조건 설정" } }, + "nodeTemplates": { + "enterName": "이름 입력", + "saveAsTemplate": "템플릿으로 저장" + }, "notSupported": { "continue": "계속", "continueTooltip": "내 장치가 지원되는 장치가 확실합니다.", diff --git a/src/locales/ru.json b/src/locales/ru.json index 023dcdca1..34111de4c 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -99,6 +99,10 @@ "zoomIn": "Увеличить", "zoomOut": "Уменьшить" }, + "groupNode": { + "create": "Создать узел группы", + "enterName": "Введите имя" + }, "icon": { "bookmark": "Закладка", "box": "Коробка", @@ -1087,6 +1091,10 @@ "display_name": "unCLIP кондиционирование" } }, + "nodeTemplates": { + "enterName": "Введите имя", + "saveAsTemplate": "Сохранить как шаблон" + }, "notSupported": { "continue": "Продолжить", "continueTooltip": "Я уверен, что мое устройство поддерживается", diff --git a/src/locales/zh.json b/src/locales/zh.json index f517214c1..a6fa8cb0a 100644 --- a/src/locales/zh.json +++ b/src/locales/zh.json @@ -99,6 +99,10 @@ "zoomIn": "放大", "zoomOut": "缩小" }, + "groupNode": { + "create": "创建组节点", + "enterName": "输入名称" + }, "icon": { "bookmark": "书签", "box": "盒子", @@ -1087,6 +1091,10 @@ "display_name": "unCLIP条件" } }, + "nodeTemplates": { + "enterName": "输入名称", + "saveAsTemplate": "另存为模板" + }, "notSupported": { "continue": "继续", "continueTooltip": "我确定我的设备是受支持的",