refactor(gallery): 图库面板抽成 src/ui-gallery-panel.js(M5 第 1 步,行为不变)v3.25.50
- 视图 props 化,app.js 8951→8937,为 gallery capability 腾行数 - 插入画布抽 insertOutputsToCanvas(list),单图/批量共用 - 边界快照同步(IWBUIGalleryPanel / ui-gallery-panel.js)
This commit is contained in:
1 parent
210d6c5290
commit
9b9ad5cc37
10 files changed
+102
-43
No files matched your search
@@ -0,0 +1,64 @@
|
||||
/* 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)
|
||||
Reference in new issue
Block a user