From 00f03de1061c46aa5a557179469b8de6acbfff3f Mon Sep 17 00:00:00 2001 From: qiqi Date: Sun, 22 Nov 2026 19:40:45 +0800 Subject: [PATCH] =?UTF-8?q?feat(promptlib):=201.6.4=20=E6=8F=92=E5=85=A5?= =?UTF-8?q?=E5=8F=98=E9=87=8F=E6=8C=89=E9=92=AE=20+=20=E5=B0=81=E9=9D=A2?= =?UTF-8?q?=E8=BF=81=E7=A7=BB=E5=A4=B1=E8=B4=A5=E5=8F=AF=E8=A7=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- promptlib/src/index.js | 31 ++++++++++++++++++++++++++++--- promptlib/styles.css | 4 ++++ 2 files changed, 32 insertions(+), 3 deletions(-) diff --git a/promptlib/src/index.js b/promptlib/src/index.js index 97e7b35..bc9acf9 100644 --- a/promptlib/src/index.js +++ b/promptlib/src/index.js @@ -405,7 +405,10 @@ // 失败就等 1.5s 重试(最多 6 次);只有全部成功才落盘,避免把 dataURL 又写回去。 function convertInlineCovers (attempt) { attempt = attempt || 0 - if (!FILEAPI) return + if (!FILEAPI) { + if (attempt === 0) notify('封面迁移:文件能力不可用(ctx.promptlib.filePut=' + (ctx.promptlib && typeof ctx.promptlib.filePut) + ')', 'err') + return + } var need = prompts.filter(function (p) { return p && typeof p.cover === 'string' && p.cover.indexOf('data:') === 0 }) if (!need.length) return var failed = 0 @@ -417,13 +420,18 @@ return Promise.resolve(FILEAPI.put(name, c)).then(function (r) { if (r && r.ok) return { id: p.id, item: Object.assign({}, p, { cover: { img: name } }) } failed++ - return { id: p.id, item: p } - }).catch(function () { failed++; return { id: p.id, item: p } }) + return { id: p.id, item: p, err: (r && r.error) || '' } + }).catch(function (e) { failed++; return { id: p.id, item: p, err: String((e && e.message) || e) } }) })).then(function (rows) { if (failed && attempt < 6) { setTimeout(function () { convertInlineCovers(attempt + 1) }, 1500) return } + if (failed) { + var err = '' + rows.some(function (x) { if (x && x.err) { err = x.err; return true } return false }) + notify('封面转文件失败 ' + failed + ' 张:' + (err || '未知原因') + '(不影响使用)', 'err') + } if (!failed) { var map = {} rows.forEach(function (x) { map[x.id] = x.item }) @@ -1289,7 +1297,24 @@ if (syncTimer) clearTimeout(syncTimer) syncTimer = setTimeout(function () { varEd.sync(textIn.value) }, 200) }) + // v1.6.2:正文上方「插入变量」——在光标处插入 {变量} 并选中变量名,直接打字即可替换 + var insVarBtn = el('button', { class: 'iwb-btn iwb-btn-sm iwb-plp-insvar', title: '在光标处插入 {变量}', text: '+ 插入变量' }) + insVarBtn.addEventListener('click', function () { + var v = textIn.value + var s = (typeof textIn.selectionStart === 'number') ? textIn.selectionStart : v.length + var e = (typeof textIn.selectionEnd === 'number') ? textIn.selectionEnd : v.length + var name = s !== e ? String(v.slice(s, e)).replace(/\s+/g, '').slice(0, 24) : '新变量' + if (!name) name = '新变量' + var ins = '{' + name + '}' + textIn.value = v.slice(0, s) + ins + v.slice(e) + textIn.selectionStart = s + 1 + textIn.selectionEnd = s + 1 + name.length + textIn.focus() + dirty = true + varEd.sync(textIn.value) + }) var mid = el('div', { class: 'iwb-plp-emid' }) + mid.appendChild(el('div', { class: 'iwb-plp-etool' }, insVarBtn, el('span', { class: 'iwb-hint', text: '在光标处插入 {变量},并自动聚焦变量名' }))) mid.appendChild(textIn) mid.appendChild(varEd.node) bodyEl.appendChild(left); bodyEl.appendChild(mid) diff --git a/promptlib/styles.css b/promptlib/styles.css index 9c1bd69..d059a6c 100644 --- a/promptlib/styles.css +++ b/promptlib/styles.css @@ -189,3 +189,7 @@ .iwb-plp-sbtns{display:flex;gap:8px;align-items:center} .iwb-plp-sopt{display:flex;gap:8px;align-items:center;font-size:12px;color:var(--iwb-text2,#4d5668)} .iwb-plp-settings{max-height:calc(100vh - 230px);overflow:auto;padding-right:4px} + +/* v1.6.2:正文上方工具行 */ +.iwb-plp-etool{display:flex;align-items:center;gap:8px} +.iwb-plp-insvar{border:1px solid var(--iwb-plp-accent,#d9d3ff);background:color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 8%,transparent);color:var(--iwb-plp-accent,#5a4bd0);font-weight:600}