chore(plugins): 内置 promptlib 同步 1.12.2(搜索框常驻修中文输入 + 变量标签定宽 6 字)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 53s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 53s
This commit is contained in:
1 parent
6291d51bcc
commit
7035d8fad2
5 files changed
+62
-23
No files matched your search
+3
-3
@@ -44,10 +44,10 @@
|
||||
"dir": "promptlib",
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
"version": "1.12.0",
|
||||
"version": "1.12.2",
|
||||
"files": {
|
||||
"main.js": "bd2a4d160114e8acb0dc7f7eff550287886131c59cbef847f86eb4a64660c4f6",
|
||||
"styles.css": "8aa37f323137ab42dc6e053cf5cf97bc04138358d987bee7bc414a666d217b0e"
|
||||
"main.js": "f61a34394338b3f3f7e6980cb1436a0a16bcbf6f03b80fa1d4996e478a330741",
|
||||
"styles.css": "08fb52128281b4d90411ce1ad96c088e5e6d82ad0a4aba2e7bd4913c2b31f412"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
||||
+50
-14
@@ -1191,7 +1191,7 @@
|
||||
if (longVarKey(v.key)) {
|
||||
item.appendChild(el('div', { class: 'iwb-plp-vtip', text: '这个变量的占位符是正文里的一整句,已把原句放进「内容」;建议把「占位符」改成短名(如 变量1),正文会同步替换。' }))
|
||||
}
|
||||
var nameIn = el('input', { class: 'iwb-input iwb-plp-vname', placeholder: '变量名称(如:顶部金色边)' })
|
||||
var nameIn = el('input', { class: 'iwb-input iwb-plp-vname', placeholder: '变量名称(节点上最多显示 6 字)' })
|
||||
nameIn.value = v.label || ''
|
||||
nameIn.addEventListener('input', function () { v.label = nameIn.value })
|
||||
item.appendChild(field('名称', nameIn))
|
||||
@@ -1972,19 +1972,39 @@
|
||||
},
|
||||
})
|
||||
}
|
||||
function render () {
|
||||
clear(fixed); clear(scrollBox)
|
||||
var gs = groupsOf()
|
||||
|
||||
// 搜索行
|
||||
var top = el('div', { class: 'iwb-row' })
|
||||
var search = el('input', { class: 'iwb-input iwb-grow', placeholder: '搜索名称 / 内容 / 标签…', value: query })
|
||||
search.addEventListener('input', function () { query = search.value; render(); var n = wrap.querySelector('input.iwb-input'); if (n) { n.focus(); try { n.setSelectionRange(n.value.length, n.value.length) } catch (e) { /* ignore */ } } })
|
||||
// ---- v1.12.2:搜索框常驻 ----
|
||||
// 旧实现把搜索框写在 render() 里,而 render() 第一件事是 clear(fixed) —— 每敲一个键都把
|
||||
// 搜索框自身销毁重建。英文/数字勉强能用(重建后重新 focus、光标扔到末尾),但中文输入法
|
||||
// 在组合态(compositionstart → compositionend)被打断 ⇒ 拼音打不出字、候选词消失。
|
||||
// 现在:搜索框只创建一次;render() 只重建其余节点;组合态期间不重排,只记 query。
|
||||
var searchRow = null
|
||||
var searchEl = null
|
||||
var composing = false
|
||||
var searchTimer = 0
|
||||
function scheduleResults () {
|
||||
if (searchTimer) clearTimeout(searchTimer)
|
||||
searchTimer = setTimeout(function () { searchTimer = 0; render() }, 120)
|
||||
}
|
||||
function ensureSearchRow () {
|
||||
if (searchRow) return searchRow
|
||||
searchRow = el('div', { class: 'iwb-row' })
|
||||
searchEl = el('input', { class: 'iwb-input iwb-grow', placeholder: '搜索名称 / 内容 / 标签…' })
|
||||
searchEl.addEventListener('compositionstart', function () { composing = true })
|
||||
searchEl.addEventListener('compositionend', function () {
|
||||
composing = false
|
||||
query = searchEl.value
|
||||
scheduleResults()
|
||||
})
|
||||
searchEl.addEventListener('input', function (e) {
|
||||
query = searchEl.value
|
||||
// 组合中的拼音不是搜索词:不重排,等上屏后由 compositionend 触发一次
|
||||
if (composing || (e && e.isComposing)) return
|
||||
scheduleResults()
|
||||
})
|
||||
// v1.10.0:顶部三入口 = 文件(从分享文件导入)/ 文本(从剪贴板导入)/ 新建。
|
||||
var fileBtn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '从分享文件导入词例', text: '文件' })
|
||||
var textBtn = el('button', { class: 'iwb-btn iwb-btn-sm', title: '从剪贴板导入词例', text: '文本' })
|
||||
var newBtn = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-primary', title: '新建词例', text: '新建' })
|
||||
|
||||
fileBtn.addEventListener('click', function () {
|
||||
fileBtn.disabled = true
|
||||
importShareFromFile().then(function (r) {
|
||||
@@ -2002,14 +2022,29 @@
|
||||
}).catch(function (e) { textBtn.disabled = false; notify('导入失败:' + ((e && e.message) || e), 'err') })
|
||||
})
|
||||
newBtn.addEventListener('click', function () { openEditModal(null, true) })
|
||||
top.appendChild(search); top.appendChild(fileBtn); top.appendChild(textBtn); top.appendChild(newBtn)
|
||||
fixed.appendChild(top)
|
||||
searchRow.appendChild(searchEl); searchRow.appendChild(fileBtn)
|
||||
searchRow.appendChild(textBtn); searchRow.appendChild(newBtn)
|
||||
return searchRow
|
||||
}
|
||||
|
||||
function render () {
|
||||
// 搜索行必须留下:清掉它会让输入法组合中断、光标丢失(中文打不进字的直接原因)
|
||||
var row = ensureSearchRow()
|
||||
Array.prototype.slice.call(fixed.children).forEach(function (c) { if (c !== row) fixed.removeChild(c) })
|
||||
if (fixed.firstChild !== row) fixed.insertBefore(row, fixed.firstChild)
|
||||
if (searchEl && !composing && searchEl.value !== query) searchEl.value = query
|
||||
clear(scrollBox)
|
||||
var gs = groupsOf()
|
||||
|
||||
|
||||
if (words().length) {
|
||||
var scope = el('div', { class: 'iwb-lib-searchscope-line' },
|
||||
el('span', { class: 'iwb-lib-searchscope', title: '搜索会跨全部分组进行' }, '在全部中搜索'),
|
||||
el('button', { class: 'iwb-lib-searchscope-back', title: '清空搜索,回到分组筛选', text: '×' }))
|
||||
scope.querySelector('.iwb-lib-searchscope-back').addEventListener('click', function () { query = ''; render() })
|
||||
scope.querySelector('.iwb-lib-searchscope-back').addEventListener('click', function () {
|
||||
query = ''; render()
|
||||
if (searchEl) { try { searchEl.focus() } catch (e) { /* ignore */ } }
|
||||
})
|
||||
fixed.appendChild(scope)
|
||||
}
|
||||
|
||||
@@ -2108,6 +2143,7 @@
|
||||
load()
|
||||
|
||||
return function dispose () {
|
||||
if (searchTimer) { clearTimeout(searchTimer); searchTimer = 0 }
|
||||
document.removeEventListener('keydown', onKey, true)
|
||||
try { if (typeof off === 'function') off() } catch (e) { /* ignore */ }
|
||||
closeMenu(); closeEditor(); closeManager()
|
||||
@@ -2117,7 +2153,7 @@
|
||||
global.IWBPluginHost.register({
|
||||
id: 'promptlib',
|
||||
name: '提示词库',
|
||||
version: '1.12.0',
|
||||
version: '1.12.2',
|
||||
apiVersion: 1,
|
||||
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'],
|
||||
data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 },
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"id": "promptlib",
|
||||
"name": "提示词库",
|
||||
"version": "1.12.0",
|
||||
"version": "1.12.2",
|
||||
"apiVersion": 1,
|
||||
"main": "main.js",
|
||||
"style": "styles.css",
|
||||
@@ -13,7 +13,7 @@
|
||||
"提示词"
|
||||
],
|
||||
"files": {
|
||||
"main.js": "bd2a4d160114e8acb0dc7f7eff550287886131c59cbef847f86eb4a64660c4f6",
|
||||
"styles.css": "8aa37f323137ab42dc6e053cf5cf97bc04138358d987bee7bc414a666d217b0e"
|
||||
"main.js": "f61a34394338b3f3f7e6980cb1436a0a16bcbf6f03b80fa1d4996e478a330741",
|
||||
"styles.css": "08fb52128281b4d90411ce1ad96c088e5e6d82ad0a4aba2e7bd4913c2b31f412"
|
||||
}
|
||||
}
|
||||
@@ -147,9 +147,12 @@
|
||||
.iwb-plp-ntitle{font-weight:600;font-size: 13px;line-height:1.3;overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical}
|
||||
.iwb-plp-nvars{display:flex;flex-direction:column;gap:4px}
|
||||
/* v1.12.0:变量行从固定 26px 单行改为「上限 5 行自适应」—— 标签贴首行顶部对齐,
|
||||
输入框换 textarea 后由 autoGrowArea() 写 height,这里只兜底最小高度。 */
|
||||
输入框换 textarea 后由 autoGrowArea() 写 height,这里只兜底最小高度。
|
||||
v1.12.1:标签列定宽 76px(12px 字号 × 6 字 + 4px 余量)。此前是 flex:0 0 auto,
|
||||
宽度跟着名称长短变 ⇒ 每个变量输入框左边缘错位(用户截图指出不美观)。
|
||||
超过 6 字的名称省略号截断,完整名称在 title 里。 */
|
||||
.iwb-plp-nrow{display:flex;align-items:flex-start;gap:6px;min-height:26px}
|
||||
.iwb-plp-nk{flex:0 0 auto;max-width:96px;padding-top:4px;color:var(--iwb-text2,#5b6472);font-size: 12px;line-height:1.35;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.iwb-plp-nk{flex:0 0 76px;width:76px;max-width:76px;padding-top:4px;color:var(--iwb-text2,#5b6472);font-size: 12px;line-height:1.35;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
|
||||
.iwb-plp-nin{flex:1 1 auto;min-width:0;height:auto;min-height:24px;padding:2px 8px;line-height:1.5;font-size: 12px;resize:none;overflow-y:hidden}
|
||||
.iwb-plp-nref{display:flex;align-items:center;gap:6px;font-size: 12px;color:var(--iwb-text2,#5b6472);border-top:1px dashed var(--iwb-border,#e3e5e9);padding-top:6px}
|
||||
.iwb-plp-nref em{font-style:normal;color:var(--iwb-text2,#8b929c)}
|
||||
|
||||
@@ -85,7 +85,7 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
||||
const search = host.querySelector('input.iwb-input')
|
||||
search.value = '收藏'
|
||||
search.dispatchEvent(new window.Event('input', { bubbles: true }))
|
||||
await wait(40)
|
||||
await wait(200) // v1.12.2:搜索重排改为 120ms 防抖(打字不再逐键全量重建,中文输入法组合态才不被打断)
|
||||
assert.ok(host.querySelector('.iwb-lib-searchscope'), '搜索时应显示「在全部中搜索」范围提示')
|
||||
assert.ok(cards().length >= 1, '搜索应跨分组命中(实际 ' + cards().length + ')')
|
||||
const active = host.querySelector('.iwb-chip-active')
|
||||
|
||||
Reference in new issue
Block a user