diff --git a/promptlib/package.json b/promptlib/package.json index 9fc3535..24b4367 100644 --- a/promptlib/package.json +++ b/promptlib/package.json @@ -1,7 +1,7 @@ { "name": "@iwb-plugin/promptlib", "private": true, - "version": "1.6.15", + "version": "1.6.16", "description": "提示词库:右栏提示词列表(搜索/分组/收藏/新建编辑/插入画布/复制/删除),数据由宿主 promptlib 能力提供", "ibwPlugin": { "id": "promptlib", diff --git a/promptlib/src/index.js b/promptlib/src/index.js index 4f307bc..b1f583b 100644 --- a/promptlib/src/index.js +++ b/promptlib/src/index.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) {