test(promptlib): canvasWrite 插入断言 + 1.6.16 同步

This commit is contained in:
qiqi committed 2026-11-22 21:20:13 +08:00
1 parent de85aff6df
commit e2b7c9919a
4 files changed
+17 -12

No files matched your search

+2 -2
View File
@@ -44,9 +44,9 @@
"dir": "promptlib",
"main": "main.js",
"style": "styles.css",
"version": "1.6.15",
"version": "1.6.16",
"files": {
"main.js": "6a6eeb564ccd3a7d8024a2d4f49271ff442416e3cf53d7c810d10ecbeb75736e",
"main.js": "cc303530f758e54a185710e8c47620b7e588693adeb86a421b0833aed114a445",
"styles.css": "1d3d84220118ed97490314d2aa122126d505c9eabcf1f8bd53a627983e7d5942"
}
},
+9 -7
View File
@@ -758,14 +758,15 @@
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 api2 = ctx.canvasWrite || ctx.canvas
var sw = ctx.canvas && typeof ctx.canvas.screenToWorld === 'function' ? ctx.canvas.screenToWorld : null
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 (!api2 || typeof api2.createNode !== 'function' || !sw) { notify('当前宿主不支持拖拽插入', 'err'); return }
var w = sw(x, y)
if (!w) return
var vd = varsOf(st.p)
if (vd.length) {
@@ -1279,10 +1280,11 @@
var del = el('button', { class: 'iwb-btn iwb-btn-sm iwb-btn-danger', text: '删除' })
var cp = el('button', { class: 'iwb-btn iwb-btn-sm', text: '复制全文' })
var insTpl = null
if (ctx.nodes && ctx.canvas && typeof ctx.canvas.createNode === 'function') {
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 id = ctx.canvas.createNode('ptpl', null, null, {
var id = cw.createNode('ptpl', null, 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(),
})
@@ -1578,9 +1580,9 @@
global.IWBPluginHost.register({
id: 'promptlib',
name: '提示词库',
version: '1.6.15',
version: '1.6.16',
apiVersion: 1,
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvasWrite'],
capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvas', 'canvasWrite'],
data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 },
settings: { panel: { type: 'custom', label: '分组与备份', render: renderPluginSettings } },
}, function (ctx) {
+2 -2
View File
@@ -1,7 +1,7 @@
{
"id": "promptlib",
"name": "提示词库",
"version": "1.6.15",
"version": "1.6.16",
"apiVersion": 1,
"main": "main.js",
"style": "styles.css",
@@ -13,7 +13,7 @@
"提示词"
],
"files": {
"main.js": "6a6eeb564ccd3a7d8024a2d4f49271ff442416e3cf53d7c810d10ecbeb75736e",
"main.js": "cc303530f758e54a185710e8c47620b7e588693adeb86a421b0833aed114a445",
"styles.css": "1d3d84220118ed97490314d2aa122126d505c9eabcf1f8bd53a627983e7d5942"
}
}
+4 -1
View File
@@ -46,9 +46,12 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms))
notify: (t, ty) => { calls.notify.push([t, ty]) },
onChanged: () => () => {},
},
canvasWrite: {
createNode: (type, x, y, data) => { calls.create.push({ type, x, y, data }); return 'n1' },
},
canvas: {
screenToWorld: (x, y) => ({ x, y }),
createNode: (type, x, y, data) => { calls.create.push({ type, x, y, data }); return 'n1' },
},
}
registered.f(ctx)