feat(promptlib): 1.6.15 指针拖拽插入(对齐风格库,绕开原生 DnD 焦点残留)

This commit is contained in:
qiqi committed 2026-11-22 21:09:24 +08:00
1 parent 4f92ec12dc
commit c9d06b8388
3 files changed
+71 -30

No files matched your search

+1 -1
View File
@@ -1,7 +1,7 @@
{
"name": "@iwb-plugin/promptlib",
"private": true,
"version": "1.6.14",
"version": "1.6.15",
"description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供",
"ibwPlugin": {
"id": "promptlib",
+69 -29
View File
@@ -732,10 +732,76 @@
box.appendChild(el('div', { class: 'iwb-plp-ghosthint', text: vd.length ? ('模板节点 · ' + vd.length + ' 个变量') : '文本节点' }))
g.appendChild(box)
g.style.position = 'fixed'; g.style.left = '-9999px'; g.style.top = '0'
g.classList.add('is-live')
document.body.appendChild(g)
return g
}
// v1.6.15:改成和风格库一样的「指针拖拽插入」,不再用原生 HTML5 drag&drop。
// 原生拖放在 WKWebView 里会吞掉 pointerup,落点节点会带着“焦点/编辑态”,第一次点击拖不动。
var cardDrag = null
function moveGhostTo (x, y) {
if (!cardDrag || !cardDrag.ghost) return
cardDrag.ghost.style.left = (x + 14) + 'px'
cardDrag.ghost.style.top = (y + 14) + 'px'
}
function endCardDrag (commit, x, y) {
var st = cardDrag
if (!st) return
cardDrag = null
try {
global.removeEventListener('pointermove', st.onMove, true)
global.removeEventListener('pointerup', st.onUp, true)
global.removeEventListener('pointercancel', st.onCancel, true)
} catch (e) { /* ignore */ }
if (st.ghost && st.ghost.parentNode) st.ghost.parentNode.removeChild(st.ghost)
try { st.card.classList.remove('is-dragging'); st.card.classList.remove('is-pressed') } catch (e) { /* ignore */ }
if (!commit || !st.active) return
try {
var api2 = ctx.canvas
var cnv = document.querySelector('.iwb-canvas')
if (cnv) {
var rc = cnv.getBoundingClientRect()
if (x < rc.left || x > rc.right || y < rc.top || y > rc.bottom) return
}
if (!api2 || typeof api2.screenToWorld !== 'function' || typeof api2.createNode !== 'function') { notify('当前宿主不支持拖拽插入', 'err'); return }
var w = api2.screenToWorld(x, y)
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' })
notify('已插入模板节点:' + (st.p.name || ''))
} else {
api2.createNode('prompt', w.x, w.y, { text: st.p.text || '', title: st.p.name || '' })
notify('已插入提示词:' + (st.p.name || ''))
}
} catch (err) { notify('拖拽插入失败:' + ((err && err.message) || err), 'err') }
}
function startCardDrag (e, p, card) {
if (e.button !== 0) return
// 不用 preventDefault:否则 WebKit 可能吞掉 click/dblclick(双击详情失效)
card.classList.add('is-pressed')
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
if (!st.active && Math.hypot(dx, dy) < 5) return
if (!st.active) {
st.active = true
card.classList.add('is-dragging')
try { st.ghost = makeDragGhost(p) } catch (err) { st.ghost = null }
}
moveGhostTo(ev.clientX, ev.clientY)
}
st.onUp = function (ev) { endCardDrag(true, ev.clientX, ev.clientY) }
st.onCancel = function () { endCardDrag(false, 0, 0) }
try {
global.addEventListener('pointermove', st.onMove, true)
global.addEventListener('pointerup', st.onUp, true)
global.addEventListener('pointercancel', st.onCancel, true)
} catch (err) { /* ignore */ }
cardDrag = st
}
function openDetail (id) { view.mode = 'detail'; view.id = String(id || ''); render(); try { scrollBox.scrollTop = 0 } catch (e) { /* ignore */ } }
function backToList () { view.mode = 'list'; view.id = ''; render() }
@@ -1470,40 +1536,14 @@
items.forEach(function (p) {
var starred = (p.group || '') === '收藏'
var coverUrl = coverOf(p)
var card = el('div', { class: 'iwb-plp-card' + (p.cover ? ' has-cover' : ' no-cover'), draggable: 'true', title: '双击查看详情 · 拖到画布插入 · 右键移动到分组' })
var card = el('div', { class: 'iwb-plp-card' + (p.cover ? ' has-cover' : ' no-cover'), title: '双击查看详情 · 拖到画布插入 · 右键移动到分组' })
var bg = el('div', { class: 'iwb-plp-bg' })
bg.style.background = coverUrl ? 'var(--iwb-plugin-inset)' : gradOf(p)
if (coverUrl) bg.appendChild(el('img', { class: 'iwb-plp-cover', src: coverUrl, alt: '', draggable: 'false' }))
card.appendChild(bg)
card.appendChild(el('div', { class: 'iwb-plp-t', text: p.name || '未命名' }))
card.addEventListener('pointerdown', function (e) {
if (e.button !== 0) return
card.classList.add('is-pressed')
})
card.addEventListener('dragstart', function (e) {
card.classList.add('is-dragging')
var ghost = null
try { ghost = makeDragGhost(p); if (e.dataTransfer && e.dataTransfer.setDragImage) e.dataTransfer.setDragImage(ghost, 26, 26) } catch (err) { /* ignore */ }
setTimeout(function () { if (ghost && ghost.parentNode) ghost.parentNode.removeChild(ghost) }, 0)
try {
e.stopPropagation()
var vd = varsOf(p)
e.dataTransfer.setData('application/x-iwb-prompt', JSON.stringify({
text: p.text || '', name: p.name || '',
vars: vd.map(function (v) { return v.key }),
vdefs: vd,
cover: p.cover || '', pluginId: ctx.id, nodeType: 'ptpl',
}))
e.dataTransfer.setData('application/x-iwb-promptid', p.id)
e.dataTransfer.setData('text/plain', (p.text || '').slice(0, 200))
e.dataTransfer.effectAllowed = 'copy'
} catch (err) { /* ignore */ }
})
card.addEventListener('pointerdown', function (e) { startCardDrag(e, p, card) })
card.addEventListener('dblclick', function (e) { e.stopPropagation(); try { openDetailModal(p) } catch (err) { notify('详情打开失败:' + ((err && err.message) || err), 'err') } })
card.addEventListener('dragend', function () {
card.classList.remove('is-dragging'); card.classList.remove('is-pressed')
})
card.addEventListener('pointerup', function () { card.classList.remove('is-pressed') })
card.addEventListener('contextmenu', function (e) { openMenu(e, p) })
cards.appendChild(card)
})
@@ -1538,7 +1578,7 @@
global.IWBPluginHost.register({
id: 'promptlib',
name: '提示词库',
version: '1.6.14',
version: '1.6.15',
apiVersion: 1,
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvasWrite'],
data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 },
+1
View File
@@ -387,3 +387,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}