diff --git a/plugins/index.json b/plugins/index.json index 493f075..ec1e4e9 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -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" } }, diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index 4f307bc..b1f583b 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.js @@ -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) { diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index 73c9e05..f2b1a15 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -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" } } diff --git a/tests/plugin-promptlib-render-test.js b/tests/plugin-promptlib-render-test.js index 0b7e0d4..9eb45f4 100644 --- a/tests/plugin-promptlib-render-test.js +++ b/tests/plugin-promptlib-render-test.js @@ -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)