feat(promptlib): 1.5.6 模板节点参照风格节点(封面缩略图/变量行/参考图开关/未填提示,去掉正文预览)

This commit is contained in:
qiqi committed 2026-11-22 16:57:50 +08:00
1 parent 8078f6495e
commit 2fb6372252
2 files changed
+50 -32

No files matched your search

+42 -32
View File
@@ -696,7 +696,7 @@
insTpl.addEventListener('click', function () {
var id = ctx.canvas.createNode('ptpl', null, null, {
promptId: p.id, name: p.name || '提示词模板', tpl: p.text || '', vdefs: vlist, vars: vals,
cover: coverNameOf(p), refOn: false, text: filled(),
cover: p.cover || coverNameOf(p), refOn: false, text: filled(),
})
if (id) { notify('已插入模板节点'); dlg.close() } else notify('插入失败', 'err')
})
@@ -1050,18 +1050,35 @@
var head = el('div', { class: 'iwb-plp-nhead' })
var thumb = el('img', { class: 'iwb-plp-nthumb', alt: '' })
thumb.style.display = 'none'
var titleBox = el('div', { class: 'iwb-plp-ntitlebox' })
var title = el('div', { class: 'iwb-plp-ntitle' })
head.appendChild(thumb); head.appendChild(title)
var meta = el('div', { class: 'iwb-plp-nmeta' })
titleBox.appendChild(title); titleBox.appendChild(meta)
head.appendChild(thumb); head.appendChild(titleBox)
var vars = el('div', { class: 'iwb-plp-nvars' })
var refRow = el('label', { class: 'iwb-plp-nref' })
var refChk = el('input', { type: 'checkbox' })
var refTxt = el('span', { text: '封面作参考图' })
var refNum = el('em', { text: '0' })
refRow.appendChild(refChk); refRow.appendChild(refTxt); refRow.appendChild(refNum)
var prev = el('div', { class: 'iwb-plp-nprev' })
root.appendChild(head); root.appendChild(vars); root.appendChild(refRow); root.appendChild(prev)
var warn = el('div', { class: 'iwb-plp-nwarn' })
root.appendChild(head); root.appendChild(vars); root.appendChild(refRow); root.appendChild(warn)
host.appendChild(root)
return { root: root, thumb: thumb, title: title, vars: vars, refChk: refChk, refNum: refNum, prev: prev, inputs: {}, key: '' }
var st = { root: root, thumb: thumb, title: title, meta: meta, vars: vars, warn: warn, refChk: refChk, refNum: refNum, inputs: {}, key: '' }
refChk.addEventListener('change', function () {
var on = Boolean(refChk.checked)
var cover = st.node && st.node.data ? st.node.data.cover : ''
var key = typeof cover === 'string' ? cover : (cover && cover.img) ? String(cover.img) : ''
var done = function (url) {
try { st.props.onUpdate(st.node.id, { refOn: on, refUrl: on ? String(url || '') : '' }) } catch (e) { /* ignore */ }
refNum.textContent = on ? '1 张' : '0'
}
if (!on || !key) { done(''); return }
if (typeof cover === 'string' && cover.indexOf('data:') === 0) { done(cover); return }
if (ctx.files) Promise.resolve(ctx.files.get(key)).then(function (r) { done(r && r.ok ? r.url : '') }).catch(function () { done('') })
else done('')
})
return st
}
function syncTplNode (st, d) {
var name = String(d.name || '提示词模板')
@@ -1077,6 +1094,7 @@
}
return out
})()
st.meta.textContent = defs.length ? (defs.length + ' 个变量') : '无变量'
var key = tpl + '|' + defs.map(function (v) { return v.key }).join(',')
if (st.key !== key) {
st.key = key
@@ -1085,44 +1103,36 @@
defs.forEach(function (v) {
var row = el('div', { class: 'iwb-plp-nrow' })
row.appendChild(el('span', { class: 'iwb-plp-nk', text: v.label || v.key }))
var inp = el('input', { class: 'iwb-input iwb-plp-nin', placeholder: v.def || '' })
var inp = el('input', { class: 'iwb-input iwb-plp-nin', placeholder: v.def || ('填写 ' + (v.label || v.key)) })
inp.value = String((d.vars && d.vars[v.key]) || v.def || '')
inp.addEventListener('input', function () { scheduleUpdate(st, d) })
st.inputs[v.key] = inp
row.appendChild(inp)
st.vars.appendChild(row)
})
if (!defs.length) st.vars.appendChild(el('div', { class: 'iwb-plp-nempty', text: '正文里没有 {变量}' }))
}
// 缩略图:封面存插件文件,按名字读一次
var cover = String(d.cover || '')
if (cover && ctx.files && st.thumbSrc !== cover) {
st.thumbSrc = cover
Promise.resolve(ctx.files.get(cover)).then(function (r) {
if (r && r.ok && r.url) { st.thumb.src = r.url; st.thumb.style.display = '' }
else st.thumb.style.display = 'none'
}).catch(function () { st.thumb.style.display = 'none' })
}
if (!cover) st.thumb.style.display = 'none'
if (!st.refBound) {
st.refBound = true
st.refChk.addEventListener('change', function () {
var on = Boolean(st.refChk.checked)
var cover = String((st.node && st.node.data && st.node.data.cover) || '')
var done = function (url) {
try { st.props.onUpdate(st.node.id, { refOn: on, refUrl: on ? String(url || '') : '' }) } catch (e) { /* ignore */ }
st.refNum.textContent = on ? '1 张' : '0'
}
if (!on || !cover || !ctx.files) { done(''); return }
Promise.resolve(ctx.files.get(cover)).then(function (r) { done(r && r.ok ? r.url : '') }).catch(function () { done('') })
})
// 缩略图:封面可能是 dataURL,也可能是插件文件引用
var cover = d.cover
var coverKey = typeof cover === 'string' ? cover : (cover && cover.img) ? String(cover.img) : ''
if (coverKey && st.thumbSrc !== coverKey) {
st.thumbSrc = coverKey
var show = function (url) {
if (url) { st.thumb.src = url; st.thumb.style.display = '' } else st.thumb.style.display = 'none'
}
if (typeof cover === 'string' && cover.indexOf('data:') === 0) show(cover)
else if (coverKey && ctx.files) Promise.resolve(ctx.files.get(coverKey)).then(function (r) { show(r && r.ok ? r.url : '') }).catch(function () { show('') })
else show('')
}
if (!coverKey) st.thumb.style.display = 'none'
var refOn = d.refOn === true
if (st.refChk.checked !== refOn) st.refChk.checked = refOn
st.refNum.textContent = refOn ? '1 张' : '0'
var vals = {}
Object.keys(st.inputs).forEach(function (k) { vals[k] = st.inputs[k].value })
var text = fillTpl(tpl, vals)
st.prev.textContent = text
// 未填变量提示(与风格节点一致:留空的保留 {原名})
var missing = 0
Object.keys(st.inputs).forEach(function (k) { if (!String(st.inputs[k].value || '').trim()) missing++ })
if (missing) { st.warn.style.display = ''; st.warn.textContent = '还有 ' + missing + ' 个变量没填(留空的保留 {原样})' }
else st.warn.style.display = 'none'
}
function scheduleUpdate (st, d) {
if (st.timer) clearTimeout(st.timer)
+8
View File
@@ -166,3 +166,11 @@
.iwb-plp-vin{flex:1;height:26px;font-size:11.5px}
.iwb-plp-vprev{margin-top:2px;border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px;font-size:11.5px;line-height:1.6;color:var(--iwb-text2,#5b6472);max-height:72px;overflow:auto;white-space:pre-wrap}
.iwb-plp-dvars{display:flex;flex-direction:column;gap:5px;border:1px solid var(--iwb-border,#e3e5e9);border-radius:10px;padding:8px 10px}
/* v1.5.6:模板节点参照风格节点 —— 封面 + 名称 + 变量,正文不再铺开 */
.iwb-plp-nthumb{width:56px;height:56px;border-radius:8px;object-fit:cover;flex:0 0 auto}
.iwb-plp-ntitlebox{min-width:0;display:flex;flex-direction:column;gap:2px}
.iwb-plp-ntitle{font-weight:600;font-size:12.5px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
.iwb-plp-nmeta{font-size:10.5px;color:var(--iwb-text2,#8b929c)}
.iwb-plp-nempty{font-size:11px;color:var(--iwb-text2,#8b929c);padding:2px 0}
.iwb-plp-nwarn{font-size:11px;line-height:1.5;color:var(--iwb-warn,#d97706)}