fix(promptlib): 插入提示词/封面落到画布中心 + 1.6.17 同步

This commit is contained in:
qiqi committed 2026-11-22 22:09:32 +08:00
1 parent 3483cc4174
commit 9739764d2f
5 files changed
+38 -12

No files matched your search

+13 -2
View File
@@ -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: '已插入封面图片' })
+3 -3
View File
@@ -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"
}
},
{
+18 -4
View File
@@ -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 },
+3 -3
View File
@@ -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"
}
}
+1
View File
@@ -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}