From 98ed47673f9c97ab8b57cd36a1754fcdb8dd107a Mon Sep 17 00:00:00 2001 From: qiqi Date: Sun, 22 Nov 2026 23:44:13 +0800 Subject: [PATCH] =?UTF-8?q?feat(promptlib):=201.8.5=20=E8=BE=93=E5=87=BA?= =?UTF-8?q?=E6=96=87=E6=9C=AC=E5=89=94=E9=99=A4=E6=9C=AA=E5=A1=AB=E5=8F=98?= =?UTF-8?q?=E9=87=8F=E5=8D=A0=E4=BD=8D=EF=BC=88=E4=BB=85=E7=BC=96=E8=BE=91?= =?UTF-8?q?=E6=97=B6=E5=B1=95=E7=A4=BA=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- promptlib/package.json | 2 +- promptlib/src/index.js | 23 +++++++++++++++++++---- 2 files changed, 20 insertions(+), 5 deletions(-) diff --git a/promptlib/package.json b/promptlib/package.json index e4d0b28..0be5963 100644 --- a/promptlib/package.json +++ b/promptlib/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/promptlib", "private": true, - "version": "1.8.4", + "version": "1.8.5", "description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供", "ibwPlugin": { "id": "promptlib", diff --git a/promptlib/src/index.js b/promptlib/src/index.js index a2ac71f..4e27d29 100644 --- a/promptlib/src/index.js +++ b/promptlib/src/index.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) }