diff --git a/CHANGELOG.md b/CHANGELOG.md index 61557a5..0f654a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,16 @@ > 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。 > 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。 +## v3.25.52(2026-11-20)M5:图库改为**只由插件提供**,宿主删除第二份界面 + +- **宿主不再保留图库面板**(`src/ui-gallery-panel.js` / `src/ui-gallery-head.js` 删除):`app.js` 8879 行(原 8951), + 只保留 `gallery` capability(`list/thumb/preview/download/insert/remove`)与数据/索引。 +- 右栏图库固定走插件(`pluginId:'gallery'`);未安装时面板显示「图库插件未安装 · 设置 → 插件 → 市场安装」。 +- 插件仓新增 **gallery 1.0.0**:头部三行(标题/全选反选下载插入删除/三个窄下拉)、瀑布流、Shift 多选、双击预览、拖到画布; + 配置存 `ctx.data`,图片数据走 `ctx.gallery`。已发布到市场(9 个插件)。 +- `insert` 支持按插件选择的尺寸档(`insertK`)压缩后再引用化。 +- 说明:图库数据(`images/` + 索引)始终在宿主;不装插件只是**看不到**图库界面,生图仍会自动归档。 + ## v3.25.51(2026-11-20)M5 第二步:宿主 gallery capability(插件可读图库) - 新增 `src/plugin-api-gallery.js`:给插件稳定的 `ctx.gallery` 代理(`list / thumb / preview / download / insert / remove`)。 diff --git a/app.js b/app.js index d142c63..b62cee2 100644 --- a/app.js +++ b/app.js @@ -5459,8 +5459,6 @@ const tbCenterSeed = (type, refs) => { // 组件已收编到 src/ui-lib-sidebar.js(P2-9 组件抽取);宿主注入应用层助手 const LibSidebar = (props) => window.IWBUILibSidebar(Object.assign({ I, api, uid, useTextDialog, TextDialog, promptGroupsOf, PluginHost, wPluginPanels }, props)) const DockArea = (typeof window !== 'undefined') ? window.IWBDockArea : null - const GalleryHead = (typeof window !== 'undefined') ? window.IWBUIGalleryHead : null - const GalleryPanel = (typeof window !== 'undefined') ? window.IWBUIGalleryPanel : null // 画布标签条(阶段一组件化 2026-11-07):纯展示组件,回调与快照值经 props 注入 const WorkspaceTabs = (props) => window.IWBUIWorkspaceTabs(Object.assign({ I }, props)) // 应用外壳 UI(阶段一组件化):画布顶栏 / 产品导航,纯展示 @@ -5707,47 +5705,21 @@ const tbCenterSeed = (type, refs) => { const [layoutLocked, setLayoutLocked] = useState(false) const [wsMoreOpen, setWsMoreOpen] = useState(false) // 顶部 ⋯ 三点菜单(展开态) const [wsMorePos, setWsMorePos] = useState({ top: 0, left: 0 }) // 三点菜单 fixed 定位 - const [histLimit, setHistLimit] = useState(100) - // 图库分页:显示范围扩大时再按需 hydrate 对应数量的图片(首次由初始化加载,避免双请求竞态) - const histLimitFirst = useRef(true) - useEffect(() => { - if (histLimitFirst.current) { histLimitFirst.current = false; return } - refreshOutputs(histLimit) - }, [histLimit]) - const [histQuery, setHistQuery] = useState('') - const [histRange, setHistRange] = useState('') // ''全部 / today / 7d / 30d - const [histGridW, setHistGridW] = useState(300) - // 图库单张图的目标宽度(用户可调):列数由「容器宽 / 图幅」算,图幅固定 ⇒ 图片不会忽大忽小 - const [histTile, setHistTile] = useState(() => { const v = Number(lsGet('iwb.gallery.tile', 130)); return v >= 80 && v <= 400 ? v : 130 }) - const setHistTilePersist = (v) => { const t = Number(v) || 130; setHistTile(t); lsSet('iwb.gallery.tile', t) } // 图幅即点即存 - const [histGridRef] = useState(() => ({ el: null })) // 画布编辑页:标题双击重命名 + 返回按钮 const [canTitleEdit, setCanTitleEdit] = useState(false) const [canTitleName, setCanTitleName] = useState('') // 统一改名弹窗(居中,复用 .iwb-rename-modal 样式):{ title, value, placeholder, okText, onSubmit } const td = useTextDialog() const outputRequestSeq = useRef(0) - const [histSel, setHistSel] = useState([]) // 图库插入尺寸档(v3.25.18 工单 ⑤):原图 / 2k / 1k / 0.5k,记忆上次选择 const INSERT_K = { orig: 0, '2k': 2048, '1k': 1024, '0.5k': 512 } const [insertK, setInsertK] = useState(() => { try { const v = lsGet('iwb.insertSizeK', '1k'); return INSERT_K[v] === undefined ? '1k' : v } catch (e) { return '1k' } }) const setInsertKPersist = (v) => { setInsertK(v); try { lsSet('iwb.insertSizeK', v) } catch (e) { /* ignore */ } } // 按选中档位压缩插入图(算法在 src/image-compress.js 的 toMaxEdge) - const shrinkForInsert = (dataUrl) => { - if (insertK === 'orig') return Promise.resolve(dataUrl) - try { return _imgCompressFn('toMaxEdge')(dataUrl, INSERT_K[insertK], 0.9).catch(() => dataUrl) } catch (e) { return Promise.resolve(dataUrl) } - } - const selectAllHistory = () => setHistSel(histFiltered.map((f) => f.name)) - const invertHistorySelection = () => setHistSel(histFiltered.filter((f) => !histSel.includes(f.name)).map((f) => f.name)) - // 下载选中的图片:逐个取本地原图/缩略图并触发下载(间隔 220ms 防浏览器连续下载拦截) - const downloadHistorySelected = async () => { - const list = (outputs || []).filter((f) => histSel.includes(f.name)) - if (!list.length) return - for (let i = 0; i < list.length; i++) { - const src = await wResolveOutputSrc(list[i]) - if (src) downloadUrl(src, list[i].name) - if (i < list.length - 1) await new Promise((r) => setTimeout(r, 220)) - } + const shrinkForInsert = (dataUrl, k) => { + const kk = (k && INSERT_K[k] !== undefined) ? k : insertK + if (kk === 'orig') return Promise.resolve(dataUrl) + try { return _imgCompressFn('toMaxEdge')(dataUrl, INSERT_K[kk], 0.9).catch(() => dataUrl) } catch (e) { return Promise.resolve(dataUrl) } } const [boxSel, setBoxSel] = useState(null) const [preview, setPreview] = useState(null) @@ -6294,14 +6266,14 @@ const tbCenterSeed = (type, refs) => { const addNode = (...a) => wbCmd().addNode(...a) const addPluginNode = (...a) => wbCmd().addPluginNode(...a) const addRefFromUrl = (...a) => wbCmd().addRefFromUrl(...a) - const refreshOutputs = (...a) => wbCmd().refreshOutputs(...a); IWWorkbenchHooks.useOutputsSync(OUT_KEY, 'iwb_outputs_sync', () => refreshOutputs(histLimit)) + const refreshOutputs = (...a) => wbCmd().refreshOutputs(...a); IWWorkbenchHooks.useOutputsSync(OUT_KEY, 'iwb_outputs_sync', () => refreshOutputs(100)) const deleteOutputs = (...a) => wbCmd().deleteOutputs(...a) // 批量插入:把图库里选中的图片按「插入尺寸」档压缩后,作为参考图节点加到画布(与单图插入同一入口) - const insertOutputsToCanvas = async (list) => { + const insertOutputsToCanvas = async (list, k) => { const added = [] for (const f of list) { let src0 = await wbCmd().refSrcOf(await wResolveOutputSrc(f), (msg) => showToast(msg, 'err')) - if (typeof src0 === 'string' && src0.indexOf('data:') === 0) src0 = await shrinkForInsert(src0) + if (typeof src0 === 'string' && src0.indexOf('data:') === 0) src0 = await shrinkForInsert(src0, k) const ref0 = (typeof src0 === 'string' && src0.indexOf('data:') === 0) ? await wImgRefWrite(src0) : null const spot = findSpot('ref') added.push({ id: uid('n'), type: 'ref', x: spot.x, y: spot.y, data: { url: ref0 || src0 || '', data: null, name: f.name, localName: null } }) @@ -6311,11 +6283,6 @@ const tbCenterSeed = (type, refs) => { showToast('已插入 ' + added.length + ' 张到画布') return added.length } - const insertHistorySelected = async () => { - const list = (outputs || []).filter((f) => histSel.includes(f.name)) - if (!list.length) { showToast('先在图库里选中图片', 'err'); return } - await insertOutputsToCanvas(list) - } const loadDemo = (...a) => wbCmd().loadDemo(...a) const doFit = (...a) => wbCmd().doFit(...a) // 节点数据规范化(含旧版迁移)—— 纯逻辑,已收编到 src/canvas-normalize.js(P2-9 第一片) @@ -6553,7 +6520,7 @@ const tbCenterSeed = (type, refs) => { window.addEventListener('storage', onGsStorage) let gsBC = null try { if (typeof BroadcastChannel !== 'undefined') { gsBC = new BroadcastChannel('iwb_groups_sync'); gsBC.onmessage = () => loadSavedGroups() } } catch (err) { /* ignore */ } - refreshOutputs(histLimit) + refreshOutputs(100) // 初始化超时兜底:本地工作台读取异常/挂起时,保证进入已加载界面,避免 splash 一直转圈。 let wsLoadTimer = null const ensureLoaded = () => { @@ -6846,9 +6813,6 @@ const tbCenterSeed = (type, refs) => { return () => { clearTimeout(refs.saveTimer); refs.saveTimer = null } }, [nodes, edges, groups, loaded]) - // 图库容器宽度测量(逻辑在 src/runtime-workbench-logic.js.startGalleryMeasure) - useEffect(() => IWWorkbenchLogic.startGalleryMeasure({ histGridRef, setHistGridW }), [drawerOpen, drawerTab]) - // wheel 缩放 + 画布尺寸跟随(逻辑在 src/runtime-workbench-logic.js.startCanvasZoomAndSize) useEffect(() => IWWorkbenchLogic.startCanvasZoomAndSize({ canvasEl, refs, setViewport, setCanvasSize }), []) @@ -7979,21 +7943,6 @@ const tbCenterSeed = (type, refs) => { const pluginNodeVariants = React.useMemo(() => wPluginNodeVariants.map((v) => ({ id: v.id, title: v.title, defaults: v.defaults, run: v.run })), [pluginRev]) const pluginNodeActionItems = React.useMemo(() => wPluginNodeActions.map((a) => ({ id: a.id, title: a.title, icon: a.icon, appliesTo: a.appliesTo, run: a.run })), [pluginRev]) - // 图库瀑布流分列:贪心最短列,保持时间顺序;列数随容器宽度自适应 - // 图库筛选:关键词(文件名/标签)+ 时间范围 - const galleryQuery = typeof window !== 'undefined' && window.IWBGalleryQuery - const galleryResult = galleryQuery && typeof galleryQuery.queryOutputs === 'function' - ? galleryQuery.queryOutputs(outputs, { query: histQuery, range: histRange, limit: histLimit, width: histGridW, tile: histTile }) - : null - const histFilteredFallback = (() => { - const q = String(histQuery || '').trim().toLowerCase() - const now = Date.now() - const rangeMs = histRange === 'today' ? 86400e3 : histRange === '7d' ? 7 * 86400e3 : histRange === '30d' ? 30 * 86400e3 : 0 - return outputs.filter((f) => (!q || ((f.name || '') + ' ' + (f.label || '')).toLowerCase().indexOf(q) >= 0) && (!rangeMs || (now - (f.mtime || 0)) <= rangeMs)) - })() - const histFiltered = galleryResult ? galleryResult.filtered : histFilteredFallback - const histCols = galleryResult ? galleryResult.columns : IWWorkbenchLogic.computeHistColumns({ histFilteredFallback, histGridW, histLimit, histTile }) - // 左侧综合工具栏(v3.3:顶部「无限画布」标题 / 工作台分区 / 底部 文件·设置·帮助) // S12/S13:统一常驻标签栏(首页+画布视图都显示,对齐 Figma 式浏览器标签) // 最左固定"首页"图标标签 → 画布库;中间画布标签 → 切换;最右 + 新建 @@ -8076,31 +8025,15 @@ const tbCenterSeed = (type, refs) => { thumb: (name) => { const f = (outputs || []).find((x) => x.name === name); return f ? wDisplayThumbOf((f.data || f.url) || '') : '' }, preview: (name) => setPreview({ list: outputs.map((x) => ({ __gallery: true, name: x.name, origIdb: x.origIdb, idb: x.idb, url: x.url, thumb: x.data || null })), idx: Math.max(0, outputs.findIndex((x) => x.name === name)) }), download: async (names) => { let n = 0; for (const f of (outputs || [])) if (names.indexOf(f.name) >= 0) { downloadUrl(await wResolveOutputSrc(f), f.name); n++ } return { ok: true, count: n } }, - insert: async (names) => ({ ok: true, inserted: await insertOutputsToCanvas((outputs || []).filter((f) => names.indexOf(f.name) >= 0)) }), - remove: (names) => { deleteOutputs(names); setHistSel([]); return { ok: true } }, + insert: async (names, o) => ({ ok: true, inserted: await insertOutputsToCanvas((outputs || []).filter((f) => names.indexOf(f.name) >= 0), (o && o.insertK) || '1k') }), + remove: (names) => { deleteOutputs(names); return { ok: true } }, }) - const dockGalleryEl = GalleryPanel ? el(GalleryPanel, { - outputs, filtered: histFiltered, buckets: histCols.buckets, sel: histSel, limit: histLimit, - insertK, tile: histTile, range: histRange, - thumbOf: (f) => wDisplayThumbOf((f.data || f.url) || ''), - onAll: selectAllHistory, onInvert: invertHistorySelection, - onDownloadSel: () => { if (!histSel.length) { showToast('先在图库里选中图片', 'err'); return } downloadHistorySelected() }, - onInsertSel: insertHistorySelected, - onDeleteSel: () => { if (!histSel.length) return; deleteOutputs(histSel); setHistSel([]) }, - onInsertK: setInsertKPersist, onTile: setHistTilePersist, onRange: setHistRange, - onMore: () => setHistLimit((n) => n + 100), - onPick: (name, shift) => setHistSel((prev) => shift ? (prev.indexOf(name) >= 0 ? prev.filter((n) => n !== name) : prev.concat([name])) : [name]), - onPreview: (name) => setPreview({ list: outputs.map((x) => ({ __gallery: true, name: x.name, origIdb: x.origIdb, idb: x.idb, url: x.url, thumb: x.data || null })), idx: Math.max(0, outputs.findIndex((x) => x.name === name)) }), - onInsertOne: (f) => insertOutputsToCanvas([f]), - onCopyOne: async (f) => { try { await copyImageToClipboard(await wOutputSrcForUse(f, null, true)); showToast('图片已复制(PNG)') } catch (err) { showToast(String((err && err.message) || err), 'err') } }, - onDownloadOne: async (f) => { downloadUrl(await wOutputSrcForUse(f), f.name) }, - }) : null const dockPanels = { groups: { title: '节点组', icon: 'group', node: dockGroupsEl }, browser: { title: '浏览器', icon: 'globe', pluginId: 'browser' }, styles: { title: '风格库', icon: 'palette', pluginId: 'style-source' }, prompts: { title: '提示词库', icon: 'book', node: dockPromptsEl }, - gallery: wPluginPanels.some((x) => x && x.pluginId === 'gallery' && typeof x.mount === 'function') ? { title: '图库', icon: 'ref', pluginId: 'gallery', fallback: dockGalleryEl } : { title: '图库', icon: 'ref', node: dockGalleryEl }, + gallery: { title: '图库', icon: 'ref', pluginId: 'gallery', hint: '图库插件未安装 · 设置 → 插件 → 市场安装' }, } return el('div', { className: 'iwb-overlay' + (wsExpanded ? ' ws-expanded' : '') + (shellView === 'landing' ? ' iwb-view-landing' : shellView === 'home' ? ' iwb-view-home' : ' iwb-view-canvas') + (drawerOpen ? ' drawer-open' : '') + ((nodes.length && loaded) ? ' has-minimap' : '') }, // 页面加载动画(加载完成后淡出) @@ -8473,7 +8406,7 @@ const tbCenterSeed = (type, refs) => { onSaved: () => { api('config').then((r) => { if (r && Array.isArray(r.providers)) setConfig(r) }).catch(() => {}) }, - onRefreshOutputs: () => refreshOutputs(histLimit), onStorageAudit: () => wStorageAudit(), onReclaimOrphans: async () => { await wReclaimOrphansNow(); return await wStorageAudit() }, + onRefreshOutputs: () => refreshOutputs(100), onStorageAudit: () => wStorageAudit(), onReclaimOrphans: async () => { await wReclaimOrphansNow(); return await wStorageAudit() }, }), document.body) : null, helpOpen ? ReactDOM.createPortal(el('div', { className: 'iwb-modal-mask', onWheel: (e) => e.stopPropagation(), onPointerDown: (e) => { if (e.target === e.currentTarget) setHelpOpen(false) } }, el('div', { className: 'iwb-modal iwb-modal-sm iwb-help-modal' }, diff --git a/package.json b/package.json index 877c06c..c9a8d78 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "image-workbench-web", "private": true, - "version": "3.25.51", + "version": "3.25.52", "description": "Browser-based node canvas image workbench", "scripts": { "build": "node scripts/build.js && node scripts/copy-plugins.js", diff --git a/plugins/index.json b/plugins/index.json index 570e938..dcf9de9 100644 --- a/plugins/index.json +++ b/plugins/index.json @@ -17,6 +17,12 @@ "version": "1.7.0", "integrity": "sha256-gWGoKJDZZyTZCirpyJSdN6+S+UuUTNUlrcB7ZbXqtPQ=" }, + { + "id": "gallery", + "file": "plugin-gallery.64a531ebc2e2.js", + "version": "1.0.0", + "integrity": "sha256-ZKUx68LiXYmVlIyy4K3wuF3tNwtRvtwuW6nGXFiIFqU=" + }, { "id": "image-annotate", "file": "plugin-image-annotate.7a865c7c353c.js", diff --git a/plugins/meta.json b/plugins/meta.json index 53fcc93..1a408b5 100644 --- a/plugins/meta.json +++ b/plugins/meta.json @@ -86,5 +86,16 @@ "浏览器", "效率" ] + }, + "gallery": { + "name": "图库", + "desc": "右栏图片墙:筛选/多选/双击预览/插入画布/下载/删除(数据由客户端提供)", + "author": "official", + "icon": "🖼️", + "color": "#eef2f6", + "tags": [ + "资源", + "图库" + ] } } diff --git a/plugins/runtime/plugin-gallery.64a531ebc2e2.js b/plugins/runtime/plugin-gallery.64a531ebc2e2.js new file mode 100644 index 0000000..cca9c96 --- /dev/null +++ b/plugins/runtime/plugin-gallery.64a531ebc2e2.js @@ -0,0 +1,233 @@ +// iwb-plugin: 图库 —— 右栏「图库」面板(宿主只提供 ctx.gallery 数据能力,界面全部在插件里) +// +// 依赖客户端能力:gallery(list/thumb/preview/download/insert/remove)+ panels。 +// 数据:插件自己的配置(插入尺寸/图幅/时间筛选)存 ctx.data,不塞 settings。 +// 视觉:复用宿主的 .iwb-gal-* / .iwb-history-* 类名(宿主 style.css 保留这些样式)。 +;(function (global) { + 'use strict' + if (!global.IWBPluginHost) return + + var PANEL_ID = 'gallery-panel' + var DEF = { insertK: '1k', tile: 130, range: '' } + var TILES = [[110, '小'], [130, '中'], [170, '大'], [220, '特大']] + var KS = [['orig', '原图'], ['2k', '2K'], ['1k', '1K'], ['0.5k', '0.5K']] + var RANGES = [['', '全部'], ['today', '今天'], ['7d', '7 天'], ['30d', '30 天']] + + function el (tag, attrs) { + var node = document.createElement(tag) + if (attrs) { + for (var k in attrs) { + if (!Object.prototype.hasOwnProperty.call(attrs, k)) continue + var v = attrs[k] + if (v === null || v === undefined) continue + if (k === 'class') node.className = v + else if (k === 'text') node.textContent = v + else if (k === 'style') node.setAttribute('style', v) + else node.setAttribute(k, v) + } + } + // 变参子节点(第三位起),支持数组与字符串 + for (var i = 2; i < arguments.length; i++) append(node, arguments[i]) + return node + } + function append (node, v) { + if (v === null || v === undefined || v === false) return + if (Array.isArray(v)) { for (var i = 0; i < v.length; i++) append(node, v[i]); return } + node.appendChild(typeof v === 'string' ? document.createTextNode(v) : v) + } + function clear (node) { while (node.firstChild) node.removeChild(node.firstChild) } + function sel (options, value) { + var s = el('select', { class: 'iwb-input iwb-select-compact' }) + for (var i = 0; i < options.length; i++) { + var o = el('option', { value: String(options[i][0]), text: options[i][1] }) + if (String(options[i][0]) === String(value)) o.selected = true + s.appendChild(o) + } + return s + } + + function mount (host, ctx) { + clear(host) + host.classList.add('iwb-plugin-node-body') + host.style.minHeight = '0' + + var cfg = Object.assign({}, DEF) + var items = [] + var total = 0 + var limit = 100 + var picked = {} + var gridW = 320 + var raf = 0 + + var head = el('div', { class: 'iwb-gal-head' }) + var title = el('div', { class: 'iwb-gal-title' }, + el('span', { class: 'iwb-toolbar-title', text: '图库' }), + el('span', { class: 'iwb-hint', text: '0 / 0 张' }), + el('span', { class: 'iwb-gal-sel', text: '' })) + var actions = el('div', { class: 'iwb-gal-actions' }) + var opts = el('div', { class: 'iwb-gal-opts' }) + head.appendChild(title); head.appendChild(actions); head.appendChild(opts) + + var grid = el('div', { class: 'iwb-history-grid' }) + var empty = el('div', { class: 'iwb-hint', text: '暂无图片 · 运行生图后会出现在这里' }) + var more = el('div', { class: 'iwb-history-more' }) + var wrap = el('div', { class: 'iwb-history-embedded' }, [head, grid, empty, more]) + host.appendChild(wrap) + + function count () { return Object.keys(picked).length } + function pickedNames () { return Object.keys(picked) } + + function renderHead () { + clear(actions); clear(opts) + title.childNodes[1].textContent = items.length + ' / ' + total + ' 张' + title.childNodes[2].textContent = count() ? ('已选 ' + count()) : '' + var n = count() + function btn (label, title0, fn, need, danger) { + var b = el('button', { class: 'iwb-btn iwb-btn-sm' + (danger ? ' iwb-btn-danger' : '') + (need && !n ? ' iwb-gal-off' : ''), text: label, title: need && !n ? '先选中图片' : title0 }) + b.addEventListener('click', function () { if (need && !n) return; fn() }) + return b + } + actions.appendChild(btn('全选', '全选当前筛选结果', function () { for (var i = 0; i < items.length; i++) picked[items[i].name] = 1; render() })) + actions.appendChild(btn('反选', '反选当前筛选结果', function () { for (var i = 0; i < items.length; i++) { var k = items[i].name; if (picked[k]) delete picked[k]; else picked[k] = 1 } render() })) + actions.appendChild(btn('下载', '下载选中的图片', function () { ctx.gallery.download(pickedNames()).catch(function () {}) }, true)) + actions.appendChild(btn('插入', '插入选中图片到画布', function () { ctx.gallery.insert(pickedNames()).catch(function () {}) }, true)) + actions.appendChild(btn('删除', '删除选中的图片(不可恢复)', function () { + var C = global.IWBUIConfirm + var ask = C && C.askOrNative ? C.askOrNative('删除选中的 ' + n + ' 张图片?不可恢复。', { title: '删除图片', okText: '删除' }) : Promise.resolve(global.confirm('删除选中的 ' + n + ' 张图片?')) + ask.then(function (ok) { if (!ok) return; return ctx.gallery.remove(pickedNames()) }).then(function () { picked = {}; load() }).catch(function () {}) + }, true, true)) + + function field (key, options, label) { + var s = sel(options, cfg[key]) + s.title = label + s.setAttribute('aria-label', label) + s.addEventListener('change', function () { cfg[key] = s.value; saveCfg(); if (key === 'range') { limit = 100; load() } else if (key === 'tile') render() }) + return s + } + opts.appendChild(field('insertK', KS, '插入画布时的图片尺寸')) + opts.appendChild(field('tile', TILES, '图库图片显示宽度')) + opts.appendChild(field('range', RANGES, '按生成时间筛选')) + } + + function renderGrid () { + clear(grid) + var gap = 8 + var n = Math.max(1, Math.floor((gridW + gap) / (Number(cfg.tile) + gap))) + var cols = [] + var heights = [] + for (var c = 0; c < n; c++) { cols.push([]); heights.push(0) } + for (var i = 0; i < items.length; i++) { + var it = items[i] + var ratio = (it.w && it.h) ? (it.h / it.w) : 1 + var min = 0 + for (var j = 1; j < n; j++) if (heights[j] < heights[min]) min = j + cols[min].push(it) + heights[min] += ((gridW - gap * (n - 1)) / n) * ratio + gap + } + for (var ci = 0; ci < cols.length; ci++) { + var col = el('div', { class: 'iwb-history-col' }) + for (var k = 0; k < cols[ci].length; k++) col.appendChild(itemNode(cols[ci][k])) + grid.appendChild(col) + } + empty.style.display = items.length ? 'none' : '' + clear(more) + if (total > items.length) { + var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: '显示更多(' + (total - items.length) + ' 张)' }) + b.addEventListener('click', function () { limit += 100; load() }) + more.appendChild(b) + } + } + + function itemNode (it) { + var on = !!picked[it.name] + var box = el('div', { class: 'iwb-history-item' + (count() ? ' iwb-history-managed' : '') + (on ? ' iwb-history-selected' : '') }) + var url = '' + try { url = ctx.gallery.thumb(it.name) } catch (e) { url = '' } + if (url && typeof url.then === 'function') url = '' + if (url) { + var img = el('img', { src: url, loading: 'lazy', title: it.name + '(单击单选 · Shift+单击多选 · 双击放大 · 拖到画布=参考图节点)', draggable: 'true' }) + if (it.w && it.h) img.setAttribute('style', 'aspect-ratio:' + it.w + ' / ' + it.h) + img.addEventListener('click', function (e) { pick(it.name, !!(e && e.shiftKey)) }) + img.addEventListener('dblclick', function () { ctx.gallery.preview(it.name) }) + img.addEventListener('dragstart', function (e) { + try { + e.dataTransfer.setData('application/x-iwb-localref', it.name) + e.dataTransfer.setData('application/x-iwb-gallery-orig', it.name) + e.dataTransfer.effectAllowed = 'copy' + } catch (err) { /* ignore */ } + }) + box.appendChild(img) + } else { + box.appendChild(el('div', { class: 'iwb-history-missing', text: '图片已丢失' })) + } + var acts = el('div', { class: 'iwb-history-actions' }) + function act (label, title, fn) { + var b = el('button', { class: 'iwb-btn iwb-btn-sm', text: label, title: title }) + b.addEventListener('click', function (e) { e.stopPropagation(); fn() }) + return b + } + acts.appendChild(act('插入', '插入到画布(参考图节点)', function () { ctx.gallery.insert([it.name]).catch(function () {}) })) + acts.appendChild(act('下载', '下载到本地', function () { ctx.gallery.download([it.name]).catch(function () {}) })) + box.appendChild(acts) + return box + } + + function pick (name, shift) { + if (shift) { if (picked[name]) delete picked[name]; else picked[name] = 1 } else { picked = {}; picked[name] = 1 } + render() + } + + function render () { renderHead(); renderGrid() } + + function load () { + return Promise.resolve(ctx.gallery.list({ range: cfg.range, limit: limit })).then(function (r) { + items = (r && r.items) || [] + total = (r && r.total) || items.length + render() + }).catch(function () { items = []; total = 0; render() }) + } + + var saveTimer = 0 + function saveCfg () { + clearTimeout(saveTimer) + saveTimer = setTimeout(function () { + try { var p = ctx.data && ctx.data.patch({ cfg: cfg }); if (p && p.catch) p.catch(function () {}) } catch (e) { /* 配置存不下不影响使用 */ } + }, 200) + } + + // 宽度测量:列数只由「面板宽 / 图幅」决定 + function measure () { + var w = grid.clientWidth + if (w > 0 && Math.abs(w - gridW) > 1) { gridW = w; renderGrid() } + } + var ro = typeof ResizeObserver === 'function' ? new ResizeObserver(function () { measure() }) : null + if (ro) ro.observe(grid) + measure() + + // 先读配置,再拉列表 + Promise.resolve(ctx.data && ctx.data.read ? ctx.data.read() : {}).then(function (d) { + if (d && d.cfg) cfg = Object.assign({}, DEF, d.cfg) + renderHead() // 三个下拉要反映读到的配置 + return load() + }).catch(function () { load() }) + + return function dispose () { if (ro) { try { ro.disconnect() } catch (e) { /* ignore */ } } } + } + + global.IWBPluginHost.register({ + id: 'gallery', + name: '图库', + version: '1.0.0', + apiVersion: 1, + capabilities: ['panels', 'gallery'], + data: { schemaVersion: 1, maxBytes: 65536 }, + }, function (ctx) { + ctx.ui.registerPanel({ + id: PANEL_ID, + title: '图库', + icon: 'ref', + mount: function (host) { return mount(host, ctx) }, + }) + return {} + }) +})(typeof window !== 'undefined' ? window : globalThis) \ No newline at end of file diff --git a/scripts/build.js b/scripts/build.js index 41c90c1..61de0d3 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -97,8 +97,6 @@ const sourceModules = [ 'runtime-download-auto.js', 'ui-workspace-tabs.js', 'ui-app-chrome.js', - 'ui-gallery-head.js', - 'ui-gallery-panel.js', 'ui-workbench-hooks.js', 'storage-autobackup.js', 'canvas-history-store.js', diff --git a/scripts/sync-plugins-from-repo.js b/scripts/sync-plugins-from-repo.js index be11a98..4bdf593 100644 --- a/scripts/sync-plugins-from-repo.js +++ b/scripts/sync-plugins-from-repo.js @@ -10,7 +10,7 @@ const crypto = require('crypto') const root = path.resolve(__dirname, '..') const srcRoot = process.argv[2] ? path.resolve(process.argv[2]) : path.resolve(root, '..', 'iwb-plugins-desktop') const outDir = path.join(root, 'plugins', 'runtime') -const IDS = ['batch-export', 'blank-canvas', 'browser', 'image-annotate', 'image-vectorize', 'style-source', 'white-bg-800', 'xianyi-cutout'] +const IDS = ['batch-export', 'blank-canvas', 'browser', 'gallery', 'image-annotate', 'image-vectorize', 'style-source', 'white-bg-800', 'xianyi-cutout'] // v3.25.41(M1):目录化插件试点 —— 这些 id 产出 /{manifest.json,main.js},其余仍是单文件(双轨兼容) // ⚠️ 2026-11-20 修正:桌面包不随包发插件(scripts/strip-plugins.js),插件只能从市场装, // 而市场目前只支持单文件 ⇒ 目录形态暂不用于生产插件,等 M3(zip 安装)落地再启用。 diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index ab87d53..17f1a63 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1983,7 +1983,7 @@ dependencies = [ [[package]] name = "image-workbench" -version = "3.25.51" +version = "3.25.52" dependencies = [ "arboard", "base64 0.22.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index 45ad27b..3397218 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "image-workbench" -version = "3.25.51" +version = "3.25.52" description = "无限画布 · 生图工作台桌面版" authors = ["malongan"] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 1505896..f525203 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "../node_modules/@tauri-apps/cli/config.schema.json", "productName": "image-workbench", - "version": "3.25.51", + "version": "3.25.52", "identifier": "com.malongan.imageworkbench", "build": { "frontendDist": "../dist", diff --git a/src/ui-dock.js b/src/ui-dock.js index ae051b5..08ac813 100644 --- a/src/ui-dock.js +++ b/src/ui-dock.js @@ -300,7 +300,7 @@ if (p.node) return p.node if (p.pluginId) { const mount = (props.pluginMount && props.pluginMount(p.pluginId)) || null - if (!mount) return el('div', { className: 'iwb-dock-empty' }, (p.title || '插件') + ' 未加载') + if (!mount) return el('div', { className: 'iwb-dock-empty' }, p.hint || ((p.title || '插件') + ' 未加载')) return el(PluginBox, { mount, fallback: p.fallback || null }) } return el('div', { className: 'iwb-dock-empty' }, '面板不可用') diff --git a/src/ui-gallery-head.js b/src/ui-gallery-head.js deleted file mode 100644 index 8e65e9d..0000000 --- a/src/ui-gallery-head.js +++ /dev/null @@ -1,56 +0,0 @@ -/* 图库面板头部(v3.25.39) - * - * 结构(对齐用户 2026-11-20 的定稿): - * 第 1 行:标题 + 计数(标题单独一行,不与按钮并排) - * 第 2 行:全选 / 反选 / 下载 / 插入 / 删除(后三个需要先选中) - * 第 3 行:插入尺寸 · 显示大小 · 时间筛选(三个窄下拉,各带 2 字标签) - * - * 纪律:纯展示组件,只接收已算好的值与回调;不读 Workbench 内部状态。 - */ -;(function (global) { - 'use strict' - const React = global.React || {} - const el = (type, prop, ...children) => React.createElement(type, prop, ...children) - - function optPairs (list) { - return (list || []).map(([v, l]) => el('option', { key: String(v), value: String(v) }, l)) - } - - function IWBUIGalleryHead (props) { - const sel = Number(props.sel) || 0 - const act = (label, title, onClick, opts) => { - const o = opts || {} - const blocked = !!o.needSel && !sel - return el('button', { - className: 'iwb-btn iwb-btn-sm' + (o.danger ? ' iwb-btn-danger' : '') + (blocked ? ' iwb-gal-off' : ''), - title: blocked ? '先在图库里选中图片' : title, - onClick: onClick, - }, label) - } - // v3.25.40:去掉三行文字标签(省空间),含义靠 title / aria-label 承担 - const field = (label, value, onChange, pairs, title) => el('label', { className: 'iwb-gal-opt', title }, - el('select', { className: 'iwb-input iwb-select-compact', value: String(value), title, 'aria-label': label, onChange: (e) => onChange(e.target.value) }, optPairs(pairs)), - ) - return el('div', { className: 'iwb-gal-head' }, - el('div', { className: 'iwb-gal-title' }, - el('span', { className: 'iwb-toolbar-title' }, '图库'), - el('span', { className: 'iwb-hint' }, (Number(props.count) || 0) + ' / ' + (Number(props.total) || 0) + ' 张'), - sel ? el('span', { className: 'iwb-gal-sel' }, '已选 ' + sel) : null, - ), - el('div', { className: 'iwb-gal-actions' }, - act('全选', '全选当前筛选结果', props.onAll), - act('反选', '反选当前筛选结果', props.onInvert), - act('下载', '下载选中的图片到本地(多张会依次触发)', props.onDownload, { needSel: true }), - act('插入', '把选中图片插入画布(参考图节点,压缩档位见下方「插入」)', props.onInsert, { needSel: true }), - act('删除', '删除选中的图片(缩略图 + 原图 + 索引一并移除,不可恢复)', props.onDelete, { needSel: true, danger: true }), - ), - el('div', { className: 'iwb-gal-opts' }, - field('插入', props.insertK, props.onInsertK, [['orig', '原图'], ['2k', '2K'], ['1k', '1K'], ['0.5k', '0.5K']], '插入画布时的图片尺寸:原图最清晰但最大;2K/1K/0.5K 会等比压到对应边长'), - field('显示', props.tile, props.onTile, [[110, '小'], [130, '中'], [170, '大'], [220, '特大']], '图库图片显示宽度:面板变宽只增加列数,图片大小不变'), - field('时间', props.range, props.onRange, [['', '全部'], ['today', '今天'], ['7d', '7 天'], ['30d', '30 天']], '按生成时间筛选图库'), - ), - ) - } - - global.IWBUIGalleryHead = IWBUIGalleryHead -})(typeof window !== 'undefined' ? window : globalThis) \ No newline at end of file diff --git a/src/ui-gallery-panel.js b/src/ui-gallery-panel.js deleted file mode 100644 index 07e58d4..0000000 --- a/src/ui-gallery-panel.js +++ /dev/null @@ -1,64 +0,0 @@ -/* ui-gallery-panel.js —— 图库面板(右栏)视图(M5 第 1 步:从 app.js 抽出,行为不变) - * - * 为什么抽:app.js 有 8952 行硬上限,而 M5 要在这里接 `gallery` capability(+桥接代码)。 - * 先把视图搬走腾出空间,再谈插件化——视图抽干净后,插件化才有地方落。 - * - * 纪律:纯展示组件(数据 + 回调全部由 props 传入),不读 Workbench 内部状态。 - */ -;(function (global) { - 'use strict' - const React = global.React || {} - const el = (type, prop, ...children) => React.createElement(type, prop, ...children) - - function GalleryPanel (props) { - const Head = global.IWBUIGalleryHead || null - const sel = props.sel || [] - const buckets = props.buckets || [] - const outputs = props.outputs || [] - const filtered = props.filtered || [] - const limit = props.limit || 0 - return el('div', { className: 'iwb-history-embedded' }, - Head ? el(Head, { - count: filtered.length, total: outputs.length, sel: sel.length, - onAll: props.onAll, onInvert: props.onInvert, - onDownload: props.onDownloadSel, onInsert: props.onInsertSel, onDelete: props.onDeleteSel, - insertK: props.insertK, onInsertK: props.onInsertK, - tile: props.tile, onTile: props.onTile, - range: props.range, onRange: props.onRange, - }) : null, - el('div', { className: 'iwb-history-grid', ref: props.gridRef }, - buckets.map((col, ci) => el('div', { key: 'c' + ci, className: 'iwb-history-col' }, - col.map((f) => el('div', { - key: f.name, - className: 'iwb-history-item' + (sel.length ? ' iwb-history-managed' : '') + (sel.indexOf(f.name) >= 0 ? ' iwb-history-selected' : ''), - }, - (f.data || f.url) - ? el('img', { - src: props.thumbOf(f), - loading: 'lazy', - style: { aspectRatio: (f.w && f.h) ? String(f.w) + ' / ' + String(f.h) : '1 / 1' }, - title: f.name + '(单击单选 · Shift+单击多选 · 双击放大 · 拖到画布=参考图节点)', - draggable: true, - onDragStart: (e) => { try { e.dataTransfer.setData('application/x-iwb-localref', (f.data || f.url) || f.name); e.dataTransfer.setData('application/x-iwb-gallery-orig', f.name); e.dataTransfer.effectAllowed = 'copy' } catch (err) { /* ignore */ } }, - onClick: (e) => props.onPick(f.name, !!(e && e.shiftKey)), - onDoubleClick: () => props.onPreview(f.name), - }) - : el('div', { className: 'iwb-history-missing' }, '图片已丢失'), - null, - el('div', { className: 'iwb-history-actions' }, - el('button', { className: 'iwb-btn iwb-btn-sm', title: '插入到画布(参考图节点)', onClick: (e) => { e.stopPropagation(); props.onInsertOne(f) } }, '插入'), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制图片到剪贴板', onClick: (e) => { e.stopPropagation(); props.onCopyOne(f) } }, '复制'), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '下载到本地', onClick: (e) => { e.stopPropagation(); props.onDownloadOne(f) } }, '下载'), - ), - )), - )), - ), - !outputs.length ? el('div', { className: 'iwb-hint' }, '暂无图片 · 运行生图后会出现在这里') : null, - filtered.length > limit ? el('div', { className: 'iwb-history-more' }, - el('button', { className: 'iwb-btn iwb-btn-sm', onClick: props.onMore }, '显示更多(' + (filtered.length - limit) + ' 张)'), - ) : null, - ) - } - - global.IWBUIGalleryPanel = GalleryPanel -})(typeof window !== 'undefined' ? window : globalThis) \ No newline at end of file diff --git a/tests/fixtures/iwb-app-global-reads.json b/tests/fixtures/iwb-app-global-reads.json index fe13061..c69a6d1 100644 --- a/tests/fixtures/iwb-app-global-reads.json +++ b/tests/fixtures/iwb-app-global-reads.json @@ -11,7 +11,6 @@ "IWBDesktop", "IWBDockArea", "IWBGalleryHydration", - "IWBGalleryQuery", "IWBGenerationRequestShape", "IWBGenerationResults", "IWBGenerationScheduler", @@ -64,8 +63,6 @@ "IWBUICanvasView", "IWBUIConfirm", "IWBUIConnectMenu", - "IWBUIGalleryHead", - "IWBUIGalleryPanel", "IWBUIGenConfigPanel", "IWBUIGroupsSidebar", "IWBUILibSidebar", diff --git a/tests/fixtures/iwb-source-modules-order.json b/tests/fixtures/iwb-source-modules-order.json index 9875f81..3a07ddc 100644 --- a/tests/fixtures/iwb-source-modules-order.json +++ b/tests/fixtures/iwb-source-modules-order.json @@ -69,8 +69,6 @@ "runtime-download-auto.js", "ui-workspace-tabs.js", "ui-app-chrome.js", - "ui-gallery-head.js", - "ui-gallery-panel.js", "ui-workbench-hooks.js", "storage-autobackup.js", "canvas-history-store.js", diff --git a/tests/single-canvas-shell-test.js b/tests/single-canvas-shell-test.js index 3af822a..57bc865 100644 --- a/tests/single-canvas-shell-test.js +++ b/tests/single-canvas-shell-test.js @@ -26,9 +26,10 @@ assert.ok(!allSrc.includes("title: '图库(右侧栏)'")) assert.ok(allSrc.includes("title: '显示 / 隐藏右栏'")) assert.ok(source.includes("panels: dockPanels")) assert.ok(source.includes("groups: { title: '节点组'")) -// v3.25.51:gallery 面板改为「装了插件用插件、否则宿主」,断言两种分支都在 +// v3.25.52:图库只由插件提供(宿主不再保留第二份图库界面),未装时给安装提示 assert.ok(source.includes("pluginId: 'gallery'")) -assert.ok(source.includes("node: dockGalleryEl")) +assert.ok(source.includes("图库插件未安装")) +assert.ok(!source.includes("dockGalleryEl")) assert.ok(allSrc.includes("className: 'iwb-res-tab'")) assert.ok(allSrc.includes("className: 'iwb-res-tabs'")) assert.ok(css.includes('.iwb-res-tabs {'))