diff --git a/docs/standards/plugin-node-outkind.md b/docs/standards/plugin-node-outkind.md new file mode 100644 index 0000000..03b59c8 --- /dev/null +++ b/docs/standards/plugin-node-outkind.md @@ -0,0 +1,34 @@ +# 插件节点的下游连线声明(outKind) + +> 适用:任何需要在画布上输出「一段文本/提示词」的插件节点(示例:风格库样式节点、提示词库模板节点)。 + +## 1. 为什么需要声明 + +宿主的连线白名单(`src/canvas-geometry.js`)按**节点语义**判断能否连到下游(生图 / 润色 / 文本 / 组合 / 连接)。 +插件节点的 `type` 是运行时注册的 `plugin:<插件id>:<变体id>`,宿主静态表里没有,无法预知它输出什么。 + +因此约定一个显式声明: + +```js +node.data.outKind = 'prompt' // 这一路输出的是提示词 +``` + +声明后,该节点在连线规则里**等同内置提示词节点**:可直接连到生图 / 润色 / 文本 / 组合 / 连接; +不声明则只能通过「中继」节点转接。 + +## 2. 怎么声明(插件侧) + +三处都要覆盖,缺一处就会出现「新拖的能连、旧节点不能连」: + +1. **注册默认值**(所有 `ctx.canvas.createNode` 路径生效): + ```js + ctx.nodes.register({ id: 'ptpl', defaults: { outKind: 'prompt' }, … }) + ``` +2. **宿主拖拽落点**:拖拽 payload 里带 `outKind`,宿主创建节点时写入 `data.outKind`。 +3. **旧节点自愈**:节点 `render` 时若 `data.outKind !== 'prompt'`,调 `props.onUpdate(id, { outKind: 'prompt' })` 补一次。 + +## 3. 宿主侧约束 + +- 白名单数组(`canvas-geometry.js` 的 7 条规则)是**宿主所有**,插件不得修改;插件只声明语义。 +- `outKind` 目前只支持 `'prompt'`;新增语义(如图片、分组)需先在宿主补规则并写测试。 +- 声明缺失时行为保持旧状(只能中继),不会破坏已有画布。 diff --git a/docs/standards/plugin-theme.md b/docs/standards/plugin-theme.md index e1650d3..89d9a5d 100644 --- a/docs/standards/plugin-theme.md +++ b/docs/standards/plugin-theme.md @@ -62,3 +62,7 @@ ## 相关规范 - 原生浮层(面板内嵌浏览器 / 画布网页节点)的生命周期见 `docs/standards/native-overlay-lifecycle.md`(先 park 再 close,禁止把隐藏放进定时器)。 + +## 相关规范 + +- 插件节点要直连下游(生图/润色/文本…)需声明 `data.outKind = 'prompt'`,见 `docs/standards/plugin-node-outkind.md`。 diff --git a/plugins/index.json b/plugins/index.json index b4b8ee0..38057e4 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -44,10 +44,10 @@ "dir": "promptlib", "main": "main.js", "style": "styles.css", - "version": "1.6.6", + "version": "1.6.7", "files": { - "main.js": "530b4bc021e0730f14505f666203c8c9c165bf9ea6bef9765ec7e9ebcda95c54", - "styles.css": "872ceeded7eb67599dfa159c86be1b1e1724f7cd1e04cae1d79d939bb0e1ebdf" + "main.js": "f9e01566764d03620e0be89e8b7ee28b28a1761e378be613aeb8703b3a893a4f", + "styles.css": "a89fe82ade71c9caf19b61abbaf65ae8784877b546f2138e27391cd559ab6294" } }, { diff --git a/plugins/promptlib/main.js b/plugins/promptlib/main.js index 4104229..ec3aa26 100644 --- a/plugins/promptlib/main.js +++ b/plugins/promptlib/main.js @@ -313,6 +313,22 @@ var modalHost = null var loadError = '' var saveTimer = 0 + // 长按武装拖拽:短按=点击详情,按住 180ms 后卡片才允许原生拖拽 + var armedCard = null + var armTimer = 0 + function disarmCard () { + if (armTimer) { clearTimeout(armTimer); armTimer = 0 } + if (armedCard) { + armedCard.draggable = false + armedCard.classList.remove('is-armed') + armedCard = null + } + } + try { + document.addEventListener('pointerup', disarmCard, true) + document.addEventListener('pointercancel', disarmCard, true) + global.addEventListener('blur', function () { disarmCard(); var d = wrap.querySelectorAll('.iwb-plp-card.is-dragging'); for (var i = 0; i < d.length; i++) d[i].classList.remove('is-dragging') }) + } catch (e) { /* ignore */ } function notify (t, ty) { try { api.notify && api.notify(t, ty || 'ok') } catch (e) { /* ignore */ } } @@ -1195,7 +1211,7 @@ 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, { - promptId: p.id, name: p.name || '提示词模板', tpl: p.text || '', vdefs: vlist, vars: vals, + promptId: p.id, name: p.name || '提示词模板', tpl: p.text || '', vdefs: vlist, vars: vals, outKind: 'prompt', cover: p.cover || coverNameOf(p), refOn: false, text: filled(), }) if (id) { notify('已插入模板节点'); dlg.close() } else notify('插入失败', 'err') @@ -1445,11 +1461,24 @@ 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: '单击查看详情 · 按住拖到画布插入 · 右键移动到分组' }) card.style.background = coverUrl ? 'var(--iwb-plugin-inset)' : gradOf(p) if (coverUrl) card.appendChild(el('img', { class: 'iwb-plp-cover', src: coverUrl, alt: '', draggable: 'false' })) card.appendChild(el('div', { class: 'iwb-plp-t', text: p.name || '未命名' })) + card.addEventListener('pointerdown', function (e) { + if (e.button !== 0) return + disarmCard() + armedCard = card + card.classList.add('is-armed') + armTimer = setTimeout(function () { + if (armedCard === card) card.draggable = true + }, 180) + }) + card.addEventListener('pointerleave', function () { + if (!card.draggable) disarmCard() + }) card.addEventListener('dragstart', function (e) { + card.classList.add('is-dragging') try { e.stopPropagation() var vd = varsOf(p) @@ -1465,6 +1494,11 @@ } catch (err) { /* ignore */ } }) card.addEventListener('click', function (e) { e.stopPropagation(); try { openDetailModal(p) } catch (err) { notify('详情打开失败:' + ((err && err.message) || err), 'err'); console.error('[promptlib] detail failed', err) } }) + card.addEventListener('dragend', function () { + card.classList.remove('is-dragging') + disarmCard() + }) + card.addEventListener('pointerup', function () { disarmCard() }) card.addEventListener('contextmenu', function (e) { openMenu(e, p) }) cards.appendChild(card) }) @@ -1499,7 +1533,7 @@ global.IWBPluginHost.register({ id: 'promptlib', name: '提示词库', - version: '1.6.6', + version: '1.6.7', apiVersion: 1, capabilities: ['panels', 'promptlib', 'nodeTypes', 'canvasWrite'], data: { schemaVersion: 3, maxBytes: 4 * 1024 * 1024 }, @@ -1562,6 +1596,10 @@ // ===== v1.5.0:提示词模板节点(与风格节点同一套机制)===== // 只出不入:被连入边会让上游文本顶掉模板;变量填完由下游生图节点取 data.text。 function renderTplNode (node, props, host) { + // 旧节点缺少 outKind ⇒ 宿主连线白名单只当普通插件节点(只能中继)。这里自愈,无需用户重拖。 + if (node && node.data && node.data.outKind !== 'prompt') { + try { props.onUpdate(node.id, { outKind: 'prompt' }) } catch (e) { /* ignore */ } + } var st = host.__plp if (!st) { host.textContent = ''; st = host.__plp = buildTplSkeleton(host) } st.node = node @@ -1668,7 +1706,7 @@ } if (ctx.nodes && typeof ctx.nodes.register === 'function') { try { - ctx.nodes.register({ id: 'ptpl', title: '提示词模板', defaults: {}, ports: { in: false, out: true }, height: 360, render: renderTplNode }) + ctx.nodes.register({ id: 'ptpl', title: '提示词模板', defaults: { outKind: 'prompt' }, ports: { in: false, out: true }, height: 360, render: renderTplNode }) } catch (e) { try { ctx.storage && ctx.storage.set('lastError', 'node:' + String((e && e.message) || e)) } catch (e2) { /* ignore */ } } diff --git a/plugins/promptlib/manifest.json b/plugins/promptlib/manifest.json index 5ae2d7f..dc84926 100644 --- a/plugins/promptlib/manifest.json +++ b/plugins/promptlib/manifest.json @@ -1,7 +1,7 @@ { "id": "promptlib", "name": "提示词库", - "version": "1.6.6", + "version": "1.6.7", "apiVersion": 1, "main": "main.js", "style": "styles.css", @@ -13,7 +13,7 @@ "提示词" ], "files": { - "main.js": "530b4bc021e0730f14505f666203c8c9c165bf9ea6bef9765ec7e9ebcda95c54", - "styles.css": "872ceeded7eb67599dfa159c86be1b1e1724f7cd1e04cae1d79d939bb0e1ebdf" + "main.js": "f9e01566764d03620e0be89e8b7ee28b28a1761e378be613aeb8703b3a893a4f", + "styles.css": "a89fe82ade71c9caf19b61abbaf65ae8784877b546f2138e27391cd559ab6294" } } diff --git a/plugins/promptlib/styles.css b/plugins/promptlib/styles.css index f828593..7d6aa76 100644 --- a/plugins/promptlib/styles.css +++ b/plugins/promptlib/styles.css @@ -351,3 +351,8 @@ margin-top: 2px; .iwb-plp-mask.iwb-mask-ghost .iwb-settings-modal { box-shadow: 0 24px 60px rgba(0,0,0,.32); } + +/* v1.6.7:卡片长按可拖的视觉反馈 */ +.iwb-plp-card{cursor:grab} +.iwb-plp-card.is-armed{border-color:var(--iwb-plp-accent,#7c4dff);box-shadow:0 0 0 2px color-mix(in srgb,var(--iwb-plp-accent,#7c4dff) 20%,transparent)} +.iwb-plp-card.is-dragging{opacity:.55;transform:scale(.98);cursor:grabbing} diff --git a/src/runtime-workbench-logic.js b/src/runtime-workbench-logic.js index 35f38af..a5e03fd 100644 --- a/src/runtime-workbench-logic.js +++ b/src/runtime-workbench-logic.js @@ -1097,7 +1097,7 @@ data: { promptId: '', name: obj.name || '提示词模板', tpl: obj.text || '', vdefs: Array.isArray(obj.vdefs) ? obj.vdefs : [], - vars: {}, cover: obj.cover || '', refOn: false, text: obj.text || '', + vars: {}, cover: obj.cover || '', refOn: false, text: obj.text || '', outKind: 'prompt', }, } : { id, type: 'prompt', x: Math.round(wx - 132), y: Math.round(wy - 20), data: { text: obj.text || '', title: obj.name || '' } }