diff --git a/plugins/index.json b/plugins/index.json index 98fe842..937eaae 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -55,9 +55,9 @@ "dir": "promptlib", "main": "main.js", "style": "styles.css", - "version": "1.14.12", + "version": "1.14.13", "files": { - "main.js": "f6e763c72a6c2e6afd2cec31e6b08e040ad203ae865b746ba54fd11719d473a8", + "main.js": "32808c2b9586fbf011ad3cbf2f3e6a2506d22cb1768d1f7b867fac8daa31568c", "styles.css": "a086b172cc8261b9f346e612b5f76cc085d5a1e486657d0c656cb87c675f238c" } }, diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index 9382e01..72e7b48 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.js @@ -1152,9 +1152,17 @@ function up () { global.removeEventListener('pointermove', mv); global.removeEventListener('pointerup', up); saveDlg(key, live) } global.addEventListener('pointermove', mv); global.addEventListener('pointerup', up) }) - mask.addEventListener('pointerdown', function (e) { if (e.target === mask) close() }) + // 2026-12-03:关闭前给调用方一次拦截机会(编辑词例用它做「未保存确认」); + // maskClose:false 时点空白不关闭(防止误点丢编辑)。 + function requestClose () { + if (typeof opts.confirmClose === 'function') { + try { opts.confirmClose(close); return } catch (e) { /* 回退到直接关闭 */ } + } + close() + } + mask.addEventListener('pointerdown', function (e) { if (opts.maskClose !== false && e.target === mask) requestClose() }) function onKey (e) { - if (e.key === 'Escape') { e.stopPropagation(); close() } else if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && opts.onSaveKey) { e.preventDefault(); opts.onSaveKey() } + if (e.key === 'Escape') { e.stopPropagation(); requestClose() } else if ((e.metaKey || e.ctrlKey) && e.key === 'Enter' && opts.onSaveKey) { e.preventDefault(); opts.onSaveKey() } } function close () { saveDlg(key, live) @@ -1819,11 +1827,17 @@ var cancelBtn = el('button', { class: 'iwb-btn iwb-btn-sm', text: '取消' }) var saveBtn = el('button', { class: 'iwb-btn iwb-btn-primary iwb-btn-sm', text: isNew ? '创建' : '保存' }) var dirty = false + function closeWithGuard (done) { + if (!dirty) { done(); return } + ask('有未保存的修改,确定放弃?', { title: '放弃修改', okText: '放弃' }).then(function (ok) { if (ok) done() }) + } openDialog({ key: 'edit', title: isNew ? '新建词例' : '编辑词例', width: 880, height: 640, actions: [cancelBtn, saveBtn], + maskClose: false, + confirmClose: function (done) { closeWithGuard(done) }, onSaveKey: function () { doSave() }, build: function (bodyEl, footEl, close) { var left = el('div', { class: 'iwb-plp-eleft' }) @@ -2027,7 +2041,9 @@ }).catch(function () { saveBtn.disabled = false; notify('保存失败', 'err') }) } saveBtn.addEventListener('click', doSave) - cancelBtn.addEventListener('click', function () { close(); if (!isNew && p) { try { openDetailModal(p) } catch (e) { /* ignore */ } } }) + cancelBtn.addEventListener('click', function () { + closeWithGuard(function () { close(); if (!isNew && p) { try { openDetailModal(p) } catch (e) { /* ignore */ } } }) + }) dupBtn.addEventListener('click', function () { var c = collect() close() @@ -2254,7 +2270,7 @@ global.IWBPluginHost.register({ id: 'promptlib', name: '提示词库', - version: '1.14.12', + version: '1.14.13', apiVersion: 1, capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite', 'nodeActions', 'commands'], data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 }, @@ -2408,9 +2424,18 @@ if (!st.refreshH) st.refreshH = {} var cell = el('div', { class: 'iwb-plp-ncell' }, inp, more) var refreshH = function () { + var has = String(inp.value || '') !== '' + // 空值的高度靠灰字提示撑:浏览器不把 placeholder 计入 scrollHeight, + // 未聚焦时临时塞进 value 量一次再恢复(沿用旧 autoGrowArea 的做法,不打断输入法)。 + var restore = '' + if (!has && (typeof document === 'undefined' || document.activeElement !== inp)) { + var ph = '' + try { ph = String(inp.getAttribute('placeholder') || '') } catch (e0) { ph = '' } + if (ph) { restore = ph; inp.value = ph } + } inp.style.height = 'auto' var full = Number(inp.scrollHeight) || 0 - var has = String(inp.value || '') !== '' + if (restore) inp.value = '' var expanded = !!st.expanded[v.key] var max = has ? NIN_MAX : NIN_PH_MAX inp.style.height = Math.min(full, expanded ? full : max) + 'px' @@ -2420,6 +2445,19 @@ more.textContent = expanded ? '收起' : ('展开(共 ' + String(inp.value || '').length + ' 字)') } else more.style.display = 'none' } + // 宽度变化(拖对话框 / 改节点宽度 / 窗口缩放)时重测;只认宽度,避免高度变化自己触发自己。 + st.__lastW = st.__lastW || {} + if (typeof ResizeObserver !== 'undefined') { + try { + var ro = new ResizeObserver(function () { + var w = inp.clientWidth + if (w === st.__lastW[v.key]) return + st.__lastW[v.key] = w + refreshH() + }) + ro.observe(inp) + } catch (eRO) { /* ignore */ } + } st.refreshH[v.key] = refreshH more.addEventListener('pointerdown', function (e) { e.stopPropagation() }) more.addEventListener('click', function (e) { @@ -2458,6 +2496,9 @@ // 必须 append 之后再量:脱离文档的元素 scrollHeight 不可靠(会量不到 placeholder 的折行) refreshH() setTimeout(refreshH, 0) + // 字体/布局晚一拍才定下来:再补两次,避免「打开时偏矮、点一下才对」 + try { (typeof requestAnimationFrame === 'function' ? requestAnimationFrame : function (f) { setTimeout(f, 16) })(refreshH) } catch (e1) { /* ignore */ } + setTimeout(refreshH, 120) }) if (!defs.length) st.vars.appendChild(el('div', { class: 'iwb-plp-nempty', text: '正文里没有 {变量}' })) try { diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index f5ff313..e95a2ea 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -1,7 +1,7 @@ { "id": "promptlib", "name": "提示词库", - "version": "1.14.12", + "version": "1.14.13", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "提示词" ], "files": { - "main.js": "f6e763c72a6c2e6afd2cec31e6b08e040ad203ae865b746ba54fd11719d473a8", + "main.js": "32808c2b9586fbf011ad3cbf2f3e6a2506d22cb1768d1f7b867fac8daa31568c", "styles.css": "a086b172cc8261b9f346e612b5f76cc085d5a1e486657d0c656cb87c675f238c" } } diff --git a/site/dev/index.html b/site/dev/index.html index 347974f..fb30104 100644 --- a/site/dev/index.html +++ b/site/dev/index.html @@ -3,7 +3,7 @@