From 5d68e0249ad2fa4b1c3bdc8ee1ddcc7f191d1334 Mon Sep 17 00:00:00 2001 From: qiqi Date: Sun, 22 Nov 2026 23:44:13 +0800 Subject: [PATCH] =?UTF-8?q?chore(plugins):=20promptlib=201.8.5=20=E5=B8=82?= =?UTF-8?q?=E5=9C=BA=E5=90=8C=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- plugins/index.json | 4 ++-- plugins/promptlib/main.js | 23 +++++++++++++++++++---- plugins/promptlib/manifest.json | 4 ++-- 3 files changed, 23 insertions(+), 8 deletions(-) diff --git a/plugins/index.json b/plugins/index.json index a1aa331..e666ec9 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -44,9 +44,9 @@ "dir": "promptlib", "main": "main.js", "style": "styles.css", - "version": "1.8.4", + "version": "1.8.5", "files": { - "main.js": "7fd3efe0b828786a9015e45f01c29704a4953ccdaec6a313c45d4f643f37618c", + "main.js": "710e93caae334973680e93e77e07c01437c8f63975f1479599aa3e13a79bca54", "styles.css": "b8a689aa06690b6040a0b1c36afe085b5b6ddfedf9aea1728c3fa236a9a68acf" } }, diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index a2ac71f..4e27d29 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.js @@ -95,6 +95,15 @@ }) } + // 提交给下游/生图的文本:填完变量后,把未填的 {占位} 从输出里剔除(只在编辑器里展示)。 + function outputText (tpl, vals) { + var s = fillTpl(tpl, vals) + return s.replace(/\{[^{} +]{1,24}\}/g, ' ').replace(/[ ]{2,}/g, ' ').replace(/\s* +\s*/g, ' +').trim() + } + function varsOf (p) { if (!p) return [] if (Array.isArray(p.vars) && p.vars.length) { @@ -771,7 +780,7 @@ if (!w) return var vd = varsOf(st.p) if (vd.length) { - api2.createNode('ptpl', w.x, w.y, { promptId: '', name: st.p.name || '提示词模板', tpl: st.p.text || '', vdefs: vd, vars: {}, cover: st.p.cover || '', refOn: false, text: st.p.text || '', outKind: 'prompt' }) + api2.createNode('ptpl', w.x, w.y, { promptId: '', name: st.p.name || '提示词模板', tpl: st.p.text || '', vdefs: vd, vars: {}, cover: st.p.cover || '', refOn: false, text: outputText(st.p.text || '', {}), outKind: 'prompt' }) notify('已插入模板节点:' + (st.p.name || '')) } else { api2.createNode('prompt', w.x, w.y, { text: st.p.text || '', title: st.p.name || '' }) @@ -848,7 +857,7 @@ notify('已插入封面图片') } else if (kind === 'ptpl') { var p = payload - var id2 = cw.createNode('ptpl', sw.x, sw.y, { promptId: p.id, name: p.name || '提示词模板', tpl: p.text || '', vdefs: varsOf(p), vars: {}, outKind: 'prompt', cover: p.cover || coverNameOf(p), refOn: false, text: p.text || '' }) + var id2 = cw.createNode('ptpl', sw.x, sw.y, { promptId: p.id, name: p.name || '提示词模板', tpl: p.text || '', vdefs: varsOf(p), vars: {}, outKind: 'prompt', cover: p.cover || coverNameOf(p), refOn: false, text: outputText(p.text || '', {}) }) if (!id2) { notify('插入失败', 'err'); cancelPlacement(); return } notify('已插入模板节点') } else { @@ -1749,7 +1758,7 @@ global.IWBPluginHost.register({ id: 'promptlib', name: '提示词库', - version: '1.8.4', + version: '1.8.5', apiVersion: 1, capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'], data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 }, @@ -1889,6 +1898,12 @@ st.vars.appendChild(row) }) if (!defs.length) st.vars.appendChild(el('div', { class: 'iwb-plp-nempty', text: '正文里没有 {变量}' })) + try { + var vv = {} + Object.keys(st.inputs).forEach(function (k) { vv[k] = st.inputs[k].value }) + var clean = outputText(String(d.tpl || ''), vv) + if (d.text !== clean && props && typeof props.onUpdate === 'function') props.onUpdate(node.id, { text: clean }) + } catch (e) { /* ignore */ } } // 缩略图:封面可能是 dataURL,也可能是插件文件引用 var cover = d.cover @@ -1917,7 +1932,7 @@ st.timer = setTimeout(function () { var vals = {} Object.keys(st.inputs).forEach(function (k) { vals[k] = st.inputs[k].value }) - var patch = { vars: vals, text: fillTpl(String(d.tpl || ''), vals) } + var patch = { vars: vals, text: outputText(String(d.tpl || ''), vals) } try { st.props.onUpdate(st.node.id, patch) } catch (e) { /* ignore */ } }, 300) } diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index 981bf69..9b344c6 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -1,7 +1,7 @@ { "id": "promptlib", "name": "提示词库", - "version": "1.8.4", + "version": "1.8.5", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "提示词" ], "files": { - "main.js": "7fd3efe0b828786a9015e45f01c29704a4953ccdaec6a313c45d4f643f37618c", + "main.js": "710e93caae334973680e93e77e07c01437c8f63975f1479599aa3e13a79bca54", "styles.css": "b8a689aa06690b6040a0b1c36afe085b5b6ddfedf9aea1728c3fa236a9a68acf" } }