diff --git a/plugins/runtime/plugin-grouplib.0f63972e5c8c.js b/plugins/grouplib/main.js similarity index 95% rename from plugins/runtime/plugin-grouplib.0f63972e5c8c.js rename to plugins/grouplib/main.js index dda190a..fc43df7 100644 --- a/plugins/runtime/plugin-grouplib.0f63972e5c8c.js +++ b/plugins/grouplib/main.js @@ -281,11 +281,10 @@ } fixed.appendChild(topRow) - // 分类胶囊:宿主的 .iwb-lib-chips-scroll 负责「单行 + 横向滚动 + 右侧渐隐」, - // 直接铺在 .iwb-lib-chips 里会被 nowrap 裁掉(分组多时右侧分类看不见) - var chips = el('div', { class: 'iwb-lib-chips' }) - var chipsScroll = el('div', { class: 'iwb-lib-chips-scroll' }) - chips.appendChild(chipsScroll) + // 分类胶囊:宿主 .iwb-lib-chips 是 nowrap(配 .iwb-lib-chips-scroll 才单行滚动), + // 分组多时右侧胶囊会被面板宽度裁掉看不见 ⇒ 这里改成「适应面板宽度自动换行」, + // 换行规则在插件自带 styles.css 的 .iwb-glp-chips 里(样式随插件发,不用等客户端发版) + var chips = el('div', { class: 'iwb-lib-chips iwb-glp-chips' }) function chip (label, value, count, extra) { var b = el('button', { class: 'iwb-chip' + (filter === value ? ' iwb-chip-active' : '') + (extra || ''), title: value === '__none__' ? '未分组;拖拽节点组卡片到此 = 移出分组' : (value === 'all' ? '' : '拖拽节点组卡片到此 = 移动到该分组') }) b.appendChild(document.createTextNode(label)) @@ -300,15 +299,15 @@ }) return b } - chipsScroll.appendChild(chip('全部', 'all', list.length)) - chipsScroll.appendChild(chip('未分组', '__none__', countOf('__none__'), ' iwb-chip-drop')) + chips.appendChild(chip('全部', 'all', list.length)) + chips.appendChild(chip('未分组', '__none__', countOf('__none__'), ' iwb-chip-drop')) gs.forEach(function (g) { chips.appendChild(chip(g.name, g.name, countOf(g.name), ' iwb-chip-drop')) }) - var addChip = el('button', { class: 'iwb-chip iwb-chip-add', title: '新建分组', text: '+' }) + var addChip = el('button', { class: 'iwb-chip iwb-glp-add iwb-chip-add', title: '新建分组', text: '+' }) addChip.addEventListener('click', function () { newOpen = !newOpen; render() }) - chipsScroll.appendChild(addChip) - var mgChip = el('button', { class: 'iwb-chip iwb-chip-add', title: '管理分组(重命名 / 排序 / 删除)', text: '⚙' }) + chips.appendChild(addChip) + var mgChip = el('button', { class: 'iwb-chip iwb-glp-add iwb-chip-add', title: '管理分组(重命名 / 排序 / 删除)', text: '⚙' }) mgChip.addEventListener('click', openManager) - chipsScroll.appendChild(mgChip) + chips.appendChild(mgChip) fixed.appendChild(chips) if (newOpen) { @@ -435,7 +434,7 @@ global.IWBPluginHost.register({ id: 'grouplib', name: '节点组', - version: '1.0.2', + version: '1.0.3', apiVersion: 1, capabilities: ['panels', 'grouplib'], data: { schemaVersion: 1, maxBytes: 65536 }, diff --git a/plugins/grouplib/manifest.json b/plugins/grouplib/manifest.json new file mode 100644 index 0000000..158c8da --- /dev/null +++ b/plugins/grouplib/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "grouplib", + "name": "节点组", + "version": "1.0.3", + "apiVersion": 1, + "main": "main.js", + "style": "styles.css", + "description": "左栏收藏的节点组:分组/改名/删除,拖到画布实例化(数据由客户端提供)", + "author": "official", + "icon": "📦", + "tags": [ + "资源", + "节点组" + ], + "files": { + "main.js": "748b23798c5a0a3ffc0d124f2904439f41345e5064b043ffd7980cd14a6f05ee", + "styles.css": "932dbf2723bd0c6bab274786784e92a1acd1dd6b4d5246c06d2240efa25d2507" + } +} diff --git a/plugins/grouplib/styles.css b/plugins/grouplib/styles.css new file mode 100644 index 0000000..1f2b7a1 --- /dev/null +++ b/plugins/grouplib/styles.css @@ -0,0 +1,17 @@ +/* grouplib(节点组)自带样式 + 作用域全部带 .iwb-glp-*,不影响宿主与其他插件;样式随插件发布,不必等客户端发版。 */ + +/* 分类胶囊「适应面板宽度」自动换行。 + 宿主的 .iwb-lib-chips 是 flex-wrap: nowrap(配合 .iwb-lib-chips-scroll 才做单行横向滚动), + 分组多时右侧胶囊会被面板宽度裁掉、看不见也用不了。 + 这里用双类选择器提高优先级(不依赖样式注入顺序),让它按宽度折行。 */ +.iwb-lib-chips.iwb-glp-chips { + flex-wrap: wrap; + row-gap: 6px; +} + +/* + / ⚙ 是动作按钮,不是分组名:不参与压缩,并与最后一个分组稍作分隔 */ +.iwb-glp-chips .iwb-glp-add { + flex: 0 0 auto; + margin-left: 2px; +} diff --git a/plugins/index.json b/plugins/index.json index 3c24c76..760f698 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -30,9 +30,14 @@ }, { "id": "grouplib", - "file": "plugin-grouplib.0f63972e5c8c.js", - "version": "1.0.2", - "integrity": "sha256-D2OXLlyMDZecVN1XpGgLHX66mfY15j0YHMoPyBIi1U0=" + "dir": "grouplib", + "main": "main.js", + "style": "styles.css", + "version": "1.0.3", + "files": { + "main.js": "748b23798c5a0a3ffc0d124f2904439f41345e5064b043ffd7980cd14a6f05ee", + "styles.css": "932dbf2723bd0c6bab274786784e92a1acd1dd6b4d5246c06d2240efa25d2507" + } }, { "id": "promptlib", diff --git a/scripts/sync-plugins-from-repo.js b/scripts/sync-plugins-from-repo.js index 78eb3f8..a11a6e2 100644 --- a/scripts/sync-plugins-from-repo.js +++ b/scripts/sync-plugins-from-repo.js @@ -14,6 +14,9 @@ const IDS = ['batch-export', 'blank-canvas', 'browser', 'gallery', 'grouplib', ' // v3.25.41(M1):目录化插件试点 —— 这些 id 产出 /{manifest.json,main.js},其余仍是单文件(双轨兼容) // ⚠️ 2026-11-20 修正:桌面包不随包发插件(scripts/strip-plugins.js),插件只能从市场装, // 而市场目前只支持单文件 ⇒ 目录形态暂不用于生产插件,等 M3(zip 安装)落地再启用。 +// 目录形态(plugins//{manifest.json,main.js[,styles.css]})的手写插件。 +// 注意:源仓里存在 /styles.css 的插件会**自动**走目录形态 —— 单文件产物带不走样式, +// 若不同步成目录,插件自带样式会被静默忽略(v1.0.3 grouplib 换行样式的坑)。 const FOLDER_IDS = ['gallery'] const sha = (buf) => crypto.createHash('sha256').update(buf).digest() @@ -32,7 +35,8 @@ for (const id of IDS) { const buf = fs.readFileSync(artifact) const pkg = JSON.parse(fs.readFileSync(path.join(srcRoot, id, 'package.json'), 'utf8')) - if (FOLDER_IDS.indexOf(id) >= 0) { + const folderMode = FOLDER_IDS.indexOf(id) >= 0 || fs.existsSync(path.join(srcRoot, id, 'styles.css')) + if (folderMode) { // 目录形态:plugins//{manifest.json,main.js} const dir = path.join(root, 'plugins', id) fs.mkdirSync(dir, { recursive: true }) diff --git a/tests/plugin-grouplib-render-test.js b/tests/plugin-grouplib-render-test.js index 7bbcc01..ee443d9 100644 --- a/tests/plugin-grouplib-render-test.js +++ b/tests/plugin-grouplib-render-test.js @@ -57,11 +57,18 @@ const wait = (ms) => new Promise((r) => setTimeout(r, ms)) const cards = () => Array.from(host.querySelectorAll('.iwb-pcard')) assert.strictEqual(cards().length, 2, '应渲染两个节点组卡片,实际 ' + cards().length) - // 胶囊必须在横向滚动容器里(否则分组多了右侧分类被裁掉) - const chipsWrap = host.querySelector('.iwb-lib-chips') - assert.ok(chipsWrap && chipsWrap.querySelector('.iwb-lib-chips-scroll'), '胶囊行应有 .iwb-lib-chips-scroll 滚动容器') - assert.ok(chipsWrap.querySelector('.iwb-lib-chips-scroll .iwb-chip'), '胶囊应放在滚动容器内') - const chips = Array.from(host.querySelectorAll('.iwb-chip')).map((c) => c.textContent) + // 胶囊行:v1.0.3 改为「适应面板宽度自动换行」(宿主 nowrap 会把右侧分组裁掉)。 + // 关键钉点:所有胶囊(含分组名)都必须是该容器的直接子节点 —— 1.0.2 曾把分组胶囊 + // append 到外层容器、其余放进滚动容器,导致分组既拿不到滚动也被裁切。 + const chipsWrap = host.querySelector('.iwb-glp-chips') + assert.ok(chipsWrap, '胶囊行应带 .iwb-glp-chips(自带换行样式的作用域类)') + assert.ok(/(^|\s)iwb-lib-chips(\s|$)/.test(chipsWrap.className), '应沿用宿主 .iwb-lib-chips') + assert.ok(!chipsWrap.querySelector('.iwb-lib-chips-scroll'), '不应再有单行滚动容器(改为换行)') + const chipEls = Array.from(chipsWrap.querySelectorAll('.iwb-chip')) + assert.ok(chipEls.length >= 4, '胶囊应至少 全部/未分组/分组/+/⚙,实际 ' + chipEls.length) + assert.ok(chipEls.every((c) => c.parentElement === chipsWrap), '全部胶囊都应是换行容器的直接子节点') + const chips = chipEls.map((c) => c.textContent) + assert.ok(chips.some((t) => t.indexOf('电商') === 0), '分组胶囊应出现在同一换行容器里:' + chips.join('|')) assert.ok(chips.some((t) => t.indexOf('全部') === 0 && /2$/.test(t)), '应有「全部 2」胶囊:' + chips.join('|')) assert.ok(chips.some((t) => t.indexOf('未分组') === 0 && /1$/.test(t)), '应有「未分组 1」胶囊:' + chips.join('|'))