feat(promptlib): 1.6.4 插入变量按钮 + 封面迁移失败可见
This commit is contained in:
1 parent
e6400b35c3
commit
00f03de106
2 files changed
+32
-3
No files matched your search
+28
-3
@@ -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)
|
||||
|
||||
@@ -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}
|
||||
Reference in new issue
Block a user