From e02b5f43455f1da4fecccba862ecaea344b24307 Mon Sep 17 00:00:00 2001 From: qiqi Date: Sun, 22 Nov 2026 22:28:22 +0800 Subject: [PATCH] =?UTF-8?q?feat(promptlib):=201.6.21=20=E8=AF=A6=E6=83=85?= =?UTF-8?q?=E6=8F=92=E5=85=A5=E6=94=B9=E4=B8=BA=E4=B8=A4=E6=AD=A5=E6=94=BE?= =?UTF-8?q?=E7=BD=AE=EF=BC=88=E5=B9=BD=E7=81=B5=E8=B7=9F=E9=9A=8F=EF=BC=8C?= =?UTF-8?q?=E7=82=B9=E5=87=BB=E8=90=BD=E7=82=B9=EF=BC=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- promptlib/package.json | 2 +- promptlib/src/index.js | 90 +++++++++++++++++++++++++++++++----------- promptlib/styles.css | 2 + 3 files changed, 71 insertions(+), 23 deletions(-) diff --git a/promptlib/package.json b/promptlib/package.json index 5879889..9d1c688 100644 --- a/promptlib/package.json +++ b/promptlib/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/promptlib", "private": true, - "version": "1.6.20", + "version": "1.6.21", "description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供", "ibwPlugin": { "id": "promptlib", diff --git a/promptlib/src/index.js b/promptlib/src/index.js index b738c0e..da29964 100644 --- a/promptlib/src/index.js +++ b/promptlib/src/index.js @@ -790,6 +790,69 @@ return pt ? { x: pt.x - (w || 0) / 2, y: pt.y - (h || 0) / 2 } : null } catch (e) { return null } } + // v1.6.21:详情里的「插入」改成两步放置:先出现跟手幽灵,再点画布落点。 + var placement = null + function cancelPlacement () { + var st = placement + if (!st) return + placement = null + try { + global.removeEventListener('pointermove', st.move, true) + global.removeEventListener('pointerdown', st.down, true) + global.removeEventListener('keydown', st.key, true) + } catch (e) { /* ignore */ } + if (st.ghost && st.ghost.parentNode) st.ghost.parentNode.removeChild(st.ghost) + try { document.body.style.cursor = '' } catch (e) { /* ignore */ } + } + function beginPlacement (kind, payload) { + cancelPlacement() + var ghost = makeDragGhost(payload) + ghost.classList.add('iwb-plp-placeghost') + var hint = kind === 'img' ? '点击画布放置封面图片 · Esc 取消' : (kind === 'ptpl' ? '点击画布放置模板节点 · Esc 取消' : '点击画布放置提示词 · Esc 取消') + ghost.appendChild(el('div', { class: 'iwb-plp-placehint', text: hint })) + document.body.appendChild(ghost) + var st = { ghost: ghost, kind: kind, payload: payload } + st.move = function (e) { + ghost.style.left = (e.clientX + 14) + 'px' + ghost.style.top = (e.clientY + 14) + 'px' + } + st.down = function (e) { + var c = document.querySelector('.iwb-canvas') + if (!c || !c.contains(e.target)) return + e.preventDefault(); e.stopPropagation() + st.move(e) + placeAt(st.kind, st.payload, e.clientX, e.clientY) + } + st.key = function (e) { if (e.key === 'Escape') { e.preventDefault(); cancelPlacement(); notify('已取消放置') } } + global.addEventListener('pointermove', st.move, true) + global.addEventListener('pointerdown', st.down, true) + global.addEventListener('keydown', st.key, true) + placement = st + try { document.body.style.cursor = 'copy' } catch (e) { /* ignore */ } + notify('移动鼠标到目标位置后单击放置(Esc 取消)') + } + function placeAt (kind, payload, cx, cy) { + try { + var sw = ctx.canvas && typeof ctx.canvas.screenToWorld === 'function' ? ctx.canvas.screenToWorld(cx, cy) : null + var cw = ctx.canvasWrite || ctx.canvas + if (!sw || !cw) { notify('当前宿主不支持放置', 'err'); cancelPlacement(); return } + if (kind === 'img') { + var iid = cw.createImageNode({ dataUrl: payload.dataUrl, name: payload.name || '封面图片', x: sw.x, y: sw.y }) + if (!iid) { notify('插入封面失败', 'err'); cancelPlacement(); return } + notify('已插入封面图片') + } else if (kind === 'ptpl') { + var p = payload + var id2 = cw.createNode('ptpl', sw.x, sw.y, { promptId: p.id, name: p.name || '提示词模板', tpl: p.text || '', vdefs: varsOf(p), vars: {}, outKind: 'prompt', cover: p.cover || coverNameOf(p), refOn: false, text: p.text || '' }) + if (!id2) { notify('插入失败', 'err'); cancelPlacement(); return } + notify('已插入模板节点') + } else { + var id3 = cw.createNode('prompt', sw.x, sw.y, { text: payload.text || '', title: payload.name || '' }) + if (!id3) { notify('插入失败', 'err'); cancelPlacement(); return } + notify('已插入提示词') + } + } catch (err) { notify('插入失败:' + ((err && err.message) || err), 'err') } + cancelPlacement() + } function startCardDrag (e, p, card) { if (e.button !== 0) return // 不用 preventDefault:否则 WebKit 可能吞掉 click/dblclick(双击详情失效) @@ -1296,14 +1359,7 @@ var cw = ctx.canvasWrite || ctx.canvas if (ctx.nodes && cw && typeof cw.createNode === 'function') { insTpl = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-primary', title: '插入可填变量的模板节点', text: '插入模板节点' }) - insTpl.addEventListener('click', function () { - var ctr = canvasCenter(420, 260) - var id = cw.createNode('ptpl', ctr ? ctr.x : null, ctr ? ctr.y : null, { - promptId: p.id, name: p.name || '提示词模板', tpl: p.text || '', vdefs: vlist, vars: vals, outKind: 'prompt', - cover: p.cover || coverNameOf(p), refOn: false, text: filled(), - }) - if (id) { notify('已插入模板节点'); dlg.close() } else notify('插入失败', 'err') - }) + insTpl.addEventListener('click', function () { dlg.close(); beginPlacement('ptpl', p) }) } var ins = el('button', { class: 'iwb-btn iwb-btn-sm', text: '插入画布' }) del.addEventListener('click', function () { @@ -1314,7 +1370,7 @@ }) }) cp.addEventListener('click', function () { Promise.resolve(api.copy(filled())).then(function (r) { if (r && r.ok === false) notify('复制失败', 'err'); else notify('已复制全文') }) }) - ins.addEventListener('click', function () { Promise.resolve(api.insert(filled(), p.name || '')).then(function () { notify('已插入画布:' + (p.name || '提示词')); dlg.close() }).catch(function () { notify('插入画布失败', 'err') }) }) + ins.addEventListener('click', function () { dlg.close(); beginPlacement('prompt', { text: filled(), name: p.name || '' }) }) var insImg = null if (p.cover) { insImg = el('button', { class: 'iwb-btn iwb-btn-sm', title: '把这条提示词的封面作为参考图插入画布', text: '插入图片' }) @@ -1322,19 +1378,9 @@ var covName = coverNameOf(p) var covData = (covName && FILEAPI) ? Promise.resolve(FILEAPI.get(covName)).then(function (x) { return x && x.ok ? x.url : '' }).catch(function () { return '' }) : Promise.resolve(typeof p.cover === 'string' ? p.cover : '') covData.then(function (u) { - if (!u) return { ok: false, error: '封面文件读取失败(可能文件已丢失)' } - // 优先用画布写入能力直接建参考图节点(不依赖 promptlib.insertImage 的宿主实现) - var cwImg = ctx.canvasWrite || ctx.canvas - if (cwImg && typeof cwImg.createImageNode === 'function') { - var ctr = canvasCenter(280, 180) - var nid = cwImg.createImageNode({ dataUrl: u, name: p.name || '封面图片', x: ctr ? ctr.x : undefined, y: ctr ? ctr.y : undefined }) - return nid ? { ok: true } : { ok: false, error: '插入封面失败' } - } - return api.insertImage(u, p.name || '') - }).then(function (r) { - if (r && r.ok === false) { notify((r && r.error) || '插入封面失败', 'err'); return } - notify('已插入封面图片') + if (!u) { notify('封面文件读取失败(可能文件已丢失)', 'err'); return } dlg.close() + beginPlacement('img', { dataUrl: u, name: p.name || '封面图片' }) }).catch(function () { notify('插入封面失败', 'err') }) }) } @@ -1604,7 +1650,7 @@ global.IWBPluginHost.register({ id: 'promptlib', name: '提示词库', - version: '1.6.20', + version: '1.6.21', apiVersion: 1, capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'], data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 }, diff --git a/promptlib/styles.css b/promptlib/styles.css index b56cf70..d47b280 100644 --- a/promptlib/styles.css +++ b/promptlib/styles.css @@ -389,3 +389,5 @@ box-shadow: 0 24px 60px rgba(0,0,0,.32); .iwb-plp-node:not(.is-selected) input{pointer-events:none} .iwb-plp-card{user-select:none} body.iwb-plp-dragging, body.iwb-plp-dragging *{user-select:none!important;-webkit-user-select:none!important} +.iwb-plp-placeghost{border-style:dashed!important;pointer-events:none} +.iwb-plp-placehint{font-size:10.5px;color:var(--iwb-plp-accent,#5a4bd0);margin-top:2px}