From 9739764d2fabf74e56b36bfde21e482e4ffbd4ef Mon Sep 17 00:00:00 2001 From: qiqi Date: Sun, 22 Nov 2026 22:09:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(promptlib):=20=E6=8F=92=E5=85=A5=E6=8F=90?= =?UTF-8?q?=E7=A4=BA=E8=AF=8D/=E5=B0=81=E9=9D=A2=E8=90=BD=E5=88=B0?= =?UTF-8?q?=E7=94=BB=E5=B8=83=E4=B8=AD=E5=BF=83=20+=201.6.17=20=E5=90=8C?= =?UTF-8?q?=E6=AD=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app.js | 15 +++++++++++++-- plugins/index.json | 6 +++--- plugins/promptlib/main.js | 22 ++++++++++++++++++---- plugins/promptlib/manifest.json | 6 +++--- plugins/promptlib/styles.css | 1 + 5 files changed, 38 insertions(+), 12 deletions(-) diff --git a/app.js b/app.js index 8534289..33475e9 100644 --- a/app.js +++ b/app.js @@ -5637,6 +5637,17 @@ const tbCenterSeed = (type, refs) => { return orig ? { data: String(dataUrl), url: '', orig } : { data: String(dataUrl), url: '' } } + // 插件「插入画布」落到可视区域中心:findSpot 会把节点丢到左上角(常被左侧面板遮住)。 + function promptCenterSpot(bridge, w, h) { + try { + const c = document.querySelector('.iwb-canvas') + if (!c || !bridge || typeof bridge.screenToWorld !== 'function') return null + const r = c.getBoundingClientRect() + const p = bridge.screenToWorld(r.left + r.width / 2, r.top + r.height / 2) + return p ? { x: p.x - (w || 0) / 2, y: p.y - (h || 0) / 2 } : null + } catch (e) { return null } + } + function Workbench() { // runtime-workbench-logic 模块的 app.js 模块级依赖:渲染前注入一次(常量/纯函数,无陈旧值风险) if (IWWorkbenchLogic && !IWWorkbenchLogic.__iwbInjected) { @@ -8216,7 +8227,7 @@ const tbCenterSeed = (type, refs) => { }, insert: (text, name) => { const id = uid('n') - const spot = findSpot('prompt') + const spot = promptCenterSpot(wPluginCanvasBridge, 280, 120) || findSpot('prompt') commitCanvas(refs.nodes.concat([{ id, type: 'prompt', x: spot.x, y: spot.y, data: { text: text || '', title: name || '' } }]), undefined, undefined) setSel([id]) setNotice({ type: 'ok', text: '已插入提示词:' + (name || '') }) @@ -8226,7 +8237,7 @@ const tbCenterSeed = (type, refs) => { insertImage: (cover, name) => wPromptInsertImage({ insertRefNode: (data, nm, w) => { const id = uid('n') - const spot = findSpot('ref') + const spot = promptCenterSpot(wPluginCanvasBridge, w || 280, 180) || findSpot('ref') commitCanvas(refs.nodes.concat([{ id, type: 'ref', x: spot.x, y: spot.y, w: w || 280, data: { data: data, name: nm } }]), undefined, undefined) setSel([id]) setNotice({ type: 'ok', text: '已插入封面图片' }) diff --git a/plugins/index.json b/plugins/index.json index ec1e4e9..0f66e9d 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -44,10 +44,10 @@ "dir": "promptlib", "main": "main.js", "style": "styles.css", - "version": "1.6.16", + "version": "1.6.17", "files": { - "main.js": "cc303530f758e54a185710e8c47620b7e588693adeb86a421b0833aed114a445", - "styles.css": "1d3d84220118ed97490314d2aa122126d505c9eabcf1f8bd53a627983e7d5942" + "main.js": "029d6adb976c5e41428ffbb3b5e8f3698dde2532597fcc55cc75e774b25b284e", + "styles.css": "1fdad04e2ffe1c8ba2a991a88072f780b65238096f9ccd1b5adba671ff2c9cb3" } }, { diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index b1f583b..88b8de4 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.js @@ -755,6 +755,7 @@ global.removeEventListener('pointercancel', st.onCancel, true) } catch (e) { /* ignore */ } if (st.ghost && st.ghost.parentNode) st.ghost.parentNode.removeChild(st.ghost) + try { document.body.classList.remove('iwb-plp-dragging') } catch (e) { /* ignore */ } try { st.card.classList.remove('is-dragging'); st.card.classList.remove('is-pressed') } catch (e) { /* ignore */ } if (!commit || !st.active) return try { @@ -770,18 +771,30 @@ if (!w) return var vd = varsOf(st.p) if (vd.length) { - api2.createNode('ptpl', w.x, w.y, { promptId: '', name: st.p.name || '提示词模板', tpl: st.p.text || '', vdefs: vd, vars: {}, cover: st.p.cover || '', refOn: false, text: st.p.text || '', outKind: 'prompt' }) + api2.createNode('ptpl', w.x - 210, w.y - 20, { promptId: '', name: st.p.name || '提示词模板', tpl: st.p.text || '', vdefs: vd, vars: {}, cover: st.p.cover || '', refOn: false, text: st.p.text || '', outKind: 'prompt' }) notify('已插入模板节点:' + (st.p.name || '')) } else { - api2.createNode('prompt', w.x, w.y, { text: st.p.text || '', title: st.p.name || '' }) + api2.createNode('prompt', w.x - 132, w.y - 20, { text: st.p.text || '', title: st.p.name || '' }) notify('已插入提示词:' + (st.p.name || '')) } } catch (err) { notify('拖拽插入失败:' + ((err && err.message) || err), 'err') } } + // 详情里插入节点:落到画布可视区域中心,而不是被 findSpot 丢到左侧面板下面 + function canvasCenter (w, h) { + try { + var c = document.querySelector('.iwb-canvas') + var sw = ctx.canvas && typeof ctx.canvas.screenToWorld === 'function' ? ctx.canvas.screenToWorld : null + if (!c || !sw) return null + var r = c.getBoundingClientRect() + var pt = sw(r.left + r.width / 2, r.top + r.height / 2) + return pt ? { x: pt.x - (w || 0) / 2, y: pt.y - (h || 0) / 2 } : null + } catch (e) { return null } + } function startCardDrag (e, p, card) { if (e.button !== 0) return // 不用 preventDefault:否则 WebKit 可能吞掉 click/dblclick(双击详情失效) card.classList.add('is-pressed') + try { document.body.classList.add('iwb-plp-dragging') } catch (err) { /* ignore */ } var st = { card: card, p: p, sx: e.clientX, sy: e.clientY, active: false, ghost: null } st.onMove = function (ev) { var dx = ev.clientX - st.sx, dy = ev.clientY - st.sy @@ -1284,7 +1297,8 @@ 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 id = cw.createNode('ptpl', null, null, { + 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(), }) @@ -1580,7 +1594,7 @@ global.IWBPluginHost.register({ id: 'promptlib', name: '提示词库', - version: '1.6.16', + version: '1.6.17', apiVersion: 1, capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'], data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 }, diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index f2b1a15..6bd0f33 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -1,7 +1,7 @@ { "id": "promptlib", "name": "提示词库", - "version": "1.6.16", + "version": "1.6.17", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "提示词" ], "files": { - "main.js": "cc303530f758e54a185710e8c47620b7e588693adeb86a421b0833aed114a445", - "styles.css": "1d3d84220118ed97490314d2aa122126d505c9eabcf1f8bd53a627983e7d5942" + "main.js": "029d6adb976c5e41428ffbb3b5e8f3698dde2532597fcc55cc75e774b25b284e", + "styles.css": "1fdad04e2ffe1c8ba2a991a88072f780b65238096f9ccd1b5adba671ff2c9cb3" } } diff --git a/plugins/promptlib/styles.css b/plugins/promptlib/styles.css index 0028fc0..b56cf70 100644 --- a/plugins/promptlib/styles.css +++ b/plugins/promptlib/styles.css @@ -388,3 +388,4 @@ box-shadow: 0 24px 60px rgba(0,0,0,.32); /* v1.6.13:未选中时变量输入框不拦截指针 —— 单击节点=选中/可拖动;选中后再点输入框编辑 */ .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}