diff --git a/CHANGELOG.md b/CHANGELOG.md index 7491f2c..78cff85 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,25 @@ > 3. 核验正式地址版本 → 之后才移动 `stable` / `stable-verified-<日期>` 标签、更新本 CHANGELOG、写 GitHub Release(`gh release create`)。 > 测试发现问题 → 改 → 再 `deploy:test`,正式环境不受影响。回滚点 `git reset --hard stable`。 +## v3.25.35(2026-11-19)左右停靠栏(P1 布局 + P2 图标拖拽),图库独立右栏 + +**新增布局** +- 左右两条**停靠栏**(Obsidian 式):左 = 节点组 / 浏览器 / 风格库,右 = 提示词库 / 图库;默认左「浏览器」、右「图库」,两侧默认展开。 +- 每栏顶部横排图标:**点击切换**当前面板;**拖动排序**;**拖到另一栏**按鼠标位置插入移动;每栏至少保留一个面板(拖走最后一个会拒绝并提示)。 +- 每栏独立开合(左栏开关在头部最左、右栏开关在头部最右),折叠后窗口边缘保留 14px 窄条作为展开入口。 +- 宽度自由拖动、**不设上限**,最小 100px;开合 / 宽度 / 面板顺序 / 当前面板全部持久化(`iwb.dock.v1`)。 +- 画布**不位移**;底部工具栏、小地图、底部提示按 `--iwb-dock-l` / `--iwb-dock-r` 让位。停靠栏从画布顶栏下方开始,避免盖住名称/状态。 +- 顶部「资源中心」按钮与 `Esc` 继续控制右栏开合;右栏默认落在「图库」。 + +**工程** +- 新增 `src/ui-dock.js`(`IWBDockArea`),并在 `scripts/build.js` 模块清单登记;`app.js` 只保留面板装配(行数仍在 8952 上限内)。 +- 图库 / 节点组 / 提示词面板改由停靠栏承载(提示词仍可「⛶ 全屏」打开原有资源中心窗口编辑)。 +- `tests/architecture-boundary-guard-test.js` 快照与架构文档计数同步(新增 1 个模块 / 1 个耦合项);`left-resource-layout` / `single-canvas-shell` / `shell-render-behavior` 断言改为停靠栏结构。 + +**已知限制** +- 浏览器 / 风格库是插件面板:插件未注册时显示「未加载」,注册后自动可用(左栏默认仍优先「浏览器」)。 +- 网页面板是**原生子 webview**:停靠栏内为直角、无圆角裁剪;切换面板/折叠时依赖插件自身的 park 逻辑,需在客户端实测。 + ## v3.25.34(2026-11-19)自动下载只在该等的时候等归档;清理废弃字段 ### 优化 diff --git a/app.js b/app.js index a2fe7ce..ac7c023 100644 --- a/app.js +++ b/app.js @@ -5465,6 +5465,7 @@ 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 // 画布标签条(阶段一组件化 2026-11-07):纯展示组件,回调与快照值经 props 注入 const WorkspaceTabs = (props) => window.IWBUIWorkspaceTabs(Object.assign({ I }, props)) // 应用外壳 UI(阶段一组件化):画布顶栏 / 产品导航,纯展示 @@ -5639,8 +5640,8 @@ const tbCenterSeed = (type, refs) => { const t2 = setTimeout(refreshMemUi, 6000) return () => { clearTimeout(t1); clearTimeout(t2) } }, []) - const [drawerOpen, setDrawerOpenRaw] = useState(() => { try { return lsRawGet('iwb_drawer_open', null) === '1' } catch (e) { return false } }); const setDrawerOpen = (v) => { setDrawerOpenRaw(v); try { lsRawSet('iwb_drawer_open', v ? '1' : '0') } catch (e) { /* ignore */ } } // 库面板开合状态持久化:刷新后保持上次开关(2026-11-03);读写失败回退「关闭」,不阻断启动 - const [drawerTab, setDrawerTabRaw] = useState(() => { try { return lsRawGet('iwb_drawer_tab', '') || 'prompts' } catch (e) { return 'prompts' } }); const setDrawerTab = (v) => { setDrawerTabRaw(v); try { lsRawSet('iwb_drawer_tab', String(v)) } catch (e) { /* ignore */ } } // 库面板当前标签持久化:刷新后停在上次的 tab(2026-11-03) + const [drawerOpen, setDrawerOpenRaw] = useState(() => { try { return lsRawGet('iwb_drawer_open', null) !== '0' } catch (e) { return true } }); const setDrawerOpen = (v) => { setDrawerOpenRaw(v); try { lsRawSet('iwb_drawer_open', v ? '1' : '0') } catch (e) { /* ignore */ } } // 库面板开合状态持久化:刷新后保持上次开关(2026-11-03);读写失败回退「关闭」,不阻断启动 + const [drawerTab, setDrawerTabRaw] = useState(() => { try { return lsRawGet('iwb_drawer_tab', '') || 'history' } catch (e) { return 'prompts' } }); const setDrawerTab = (v) => { setDrawerTabRaw(v); try { lsRawSet('iwb_drawer_tab', String(v)) } catch (e) { /* ignore */ } } // 库面板当前标签持久化:刷新后停在上次的 tab(2026-11-03) const [enteringWs, setEnteringWs] = useState(false) // 进入画布编辑器的加载动画 const [outputs, setOutputs] = useState([]) const [outputsInfo, setOutputsInfo] = useState(null) @@ -8048,6 +8049,74 @@ const tbCenterSeed = (type, refs) => { const vw = canvasSize.w || 800, vh = canvasSize.h || 600 setViewport((v) => ({ ...v, x: vw / 2 - wx * v.scale, y: vh / 2 - wy * v.scale })) }, [canvasSize]) + // ---- 左右停靠面板(v3.25.35)---- + const dockGroupsEl = el(GroupsSidebar, { embedded: true, savedGroups, nodeGroupGroups, + onSavedGroupsChange: (list, onErr) => { setSavedGroups(list); api('groups', { groups: list, groupGroups: nodeGroupGroups }).then((r) => { if (r && r.ok === false && onErr) onErr() }).catch(() => { if (onErr) onErr() }) }, + onNodeGroupGroupsChange: setNodeGroupGroups, + onFlash: (t, ty) => { setNotice({ type: ty === 'err' ? 'err' : 'ok', text: t }); showToast(t, ty) }, + onRefresh: loadSavedGroups, onClose: () => {} }) + const dockPromptsEl = el(LibSidebar, { embedded: true, prompts, groups: promptGroups, + canvasPrompts: nodes.filter((n) => n.type === 'prompt').map((n) => ({ id: n.id, text: n.data.text || '' })), + onPromptsChange: (list) => setPrompts(list), onGroupsChange: setPromptGroups, + onInsertPrompt: (text, name) => { const id = uid('n'); const spot = findSpot('prompt'); commitCanvas(refs.nodes.concat([{ id, type: 'prompt', x: spot.x, y: spot.y, data: { text, title: name || '' } }]), undefined, undefined); setSel([id]); setNotice({ type: 'ok', text: '已插入提示词:' + (name || '') }) }, + onFlash: (t, ty) => { setNotice({ type: ty === 'err' ? 'err' : 'ok', text: t }); showToast(t, ty) } }) + const dockGalleryEl = el('div', { className: 'iwb-history-embedded' }, + el('div', { className: 'iwb-row iwb-history-head' }, + el('span', { className: 'iwb-toolbar-title' }, '图库'), + el('span', { className: 'iwb-hint' }, histFiltered.length + ' / ' + outputs.length + ' 张'), + el('span', { className: 'iwb-drawer-spacer' }, null), + el('button', { className: 'iwb-btn iwb-btn-sm', title: '全选当前图库图片', onClick: selectAllHistory }, '全选'), + el('button', { className: 'iwb-btn iwb-btn-sm', title: '反选当前图库图片', onClick: invertHistorySelection }, '反选'), + histSel.length ? el('span', { className: 'iwb-history-manage-tools' }, + el('button', { className: 'iwb-btn iwb-btn-sm iwb-btn-danger', title: '删除选中的图片', onClick: () => { deleteOutputs(histSel); setHistSel([]) } }, '删除'), + el('button', { className: 'iwb-btn iwb-btn-sm', title: '下载选中的图片到本地', onClick: downloadHistorySelected }, '下载'), + el('button', { className: 'iwb-btn iwb-btn-sm', title: '清除选择', onClick: () => setHistSel([]) }, '清除'), + ) : null, + // 紧凑版(v3.25.19):只显示档位值,前缀「插入」放进 title 与标签里,省横向空间 + el('select', { className: 'iwb-input iwb-select-compact', value: insertK, onChange: (e) => setInsertKPersist(e.target.value), title: '插入画布时的图片尺寸:原图最清晰但最大;2K/1K/0.5K 会等比压到对应边长' }, + [['orig', '原图'], ['2k', '2K'], ['1k', '1K'], ['0.5k', '0.5K']].map(([v, l]) => el('option', { key: v, value: v }, l)), + ), + el('select', { className: 'iwb-input iwb-select-compact', value: histRange, onChange: (e) => setHistRange(e.target.value), title: '按时间筛选图库' }, + [['', '全部'], ['today', '今天'], ['7d', '7 天'], ['30d', '30 天']].map(([v, l]) => el('option', { key: v, value: v }, l)), + ), + ), + el('div', { className: 'iwb-history-grid', ref: (el0) => { histGridRef.el = el0 } }, + histCols.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' + (histSel.length ? ' iwb-history-managed' : '') + (histSel.includes(f.name) ? ' iwb-history-selected' : '') }, + ((f.data || f.url)) ? el('img', { src: wDisplayThumbOf((f.data || f.url) || ''), 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) => { if (e && e.shiftKey) setHistSel((prev) => prev.includes(f.name) ? prev.filter((n) => n !== f.name) : [...prev, f.name]); else setHistSel([f.name]) }, onDoubleClick: () => { 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 === 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: async (e) => { e.stopPropagation(); let src0 = await wbCmd().refSrcOf(await wResolveOutputSrc(f), (msg) => showToast(msg, 'err')); if (typeof src0 === 'string' && src0.indexOf('data:') === 0) src0 = await shrinkForInsert(src0); const spot = findSpot('ref'); const id = uid('n'); // 2026-10-20(审计 N1):插入时**立即引用化**,不要把整张图 base64 塞进画布。 + // 原症状:插入时 data.url = 完整 base64(4K 约 10MB)⇒ 画布内存里多一份整图; + // 刷新后又被 wSanitizeWs 换成 {__blob} 引用(用户看到的「状态变了」), + // 且刷新时还要把 base64 再转回 Blob(内存数倍占用、过一会儿才回落)。 + // 修法:与「保存画布」走**同一个唯一入口** wImgRefWrite(§13.34)⇒ 画布里只留引用。 + // 写库失败时兜底用 src0(base64),保证不丢图(行为与修复前一致)。 + // ⚠️ 只有 **data: URL** 才引用化;远程图床 URL(item.url)已是字符串、 + // 不是字节,引用化无意义(wImgRefWrite 只吃 base64)⇒ 直接沿用。 + const ref0 = (typeof src0 === 'string' && src0.indexOf('data:') === 0) ? await wImgRefWrite(src0) : null; + commitCanvas(refs.nodes.concat([{ id, type: 'ref', x: spot.x, y: spot.y, data: { url: ref0 || src0 || '', data: null, name: f.name, localName: null } }]), undefined, undefined); setSel([id]); setPreview(null); showToast('已插入画布') } }, '插入'), + el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制图片到剪贴板', onClick: async (e) => { e.stopPropagation(); try { await copyImageToClipboard(await wOutputSrcForUse(f, null, true)); showToast('图片已复制(PNG)') } catch (err) { showToast(String((err && err.message) || err), 'err') } } }, '复制'), + el('button', { className: 'iwb-btn iwb-btn-sm', title: '下载到本地', onClick: async (e) => { e.stopPropagation(); downloadUrl(await wOutputSrcForUse(f), f.name) } }, '下载'), + ), + )), + )), + ), + !outputs.length ? el('div', { className: 'iwb-hint' }, '暂无图片 · 运行生图后会出现在这里') : null, + histFiltered.length > histLimit ? el('div', { className: 'iwb-history-more' }, + el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => setHistLimit((n) => n + 100) }, '显示更多(' + (histFiltered.length - histLimit) + ' 张)'), + ) : null, + el('div', { className: 'iwb-history-foot' }, + el('span', { className: 'iwb-hint' }, '自动清理:' + retentionText(outputsInfo)), + ), + ) + 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: { title: '图库', icon: 'ref', node: dockGalleryEl }, + } 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' : '') }, // 页面加载动画(加载完成后淡出) !splashDone ? el('div', { className: 'iwb-splash' + (loaded ? ' iwb-splash-fade' : '') }, @@ -8400,86 +8469,11 @@ const tbCenterSeed = (type, refs) => { measuredT: tick, onJump: mmOnJump, }) : null, - drawerOpen ? el(LibSidebar, { - resOpen: true, - resTab: drawerTab, - onResTab: setDrawerTab, - prompts, - canvasPrompts: nodes.filter((n) => n.type === 'prompt').map((n) => ({ id: n.id, text: n.data.text || '' })), - groups: promptGroups, - onPromptsChange: (list) => setPrompts(list), - onGroupsChange: setPromptGroups, - onInsertPrompt: (text, name) => { - const id = uid('n') - const spot = findSpot('prompt') - const node = { id, type: 'prompt', x: spot.x, y: spot.y, data: { text, title: name || '' } } - commitCanvas(refs.nodes.concat([node]), undefined, undefined) - setSel([id]) - setNotice({ type: 'ok', text: '已插入提示词:' + (name || '') }) - }, - onFlash: (t, ty) => { setNotice({ type: ty === 'err' ? 'err' : 'ok', text: t }); showToast(t, ty) }, - groupsContent: el(GroupsSidebar, { - embedded: true, - savedGroups, - nodeGroupGroups, - onSavedGroupsChange: (list, onErr) => { setSavedGroups(list); api('groups', { groups: list, groupGroups: nodeGroupGroups }).then((r) => { if (r && r.ok === false && onErr) onErr() }).catch(() => { if (onErr) onErr() }) }, - onNodeGroupGroupsChange: setNodeGroupGroups, - onFlash: (t, ty) => { setNotice({ type: ty === 'err' ? 'err' : 'ok', text: t }); showToast(t, ty) }, - onRefresh: loadSavedGroups, - onClose: () => setDrawerOpen(false), - }), - historyContent: el('div', { className: 'iwb-history-embedded' }, - el('div', { className: 'iwb-row iwb-history-head' }, - el('span', { className: 'iwb-toolbar-title' }, '图库'), - el('span', { className: 'iwb-hint' }, histFiltered.length + ' / ' + outputs.length + ' 张'), - el('span', { className: 'iwb-drawer-spacer' }, null), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '全选当前图库图片', onClick: selectAllHistory }, '全选'), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '反选当前图库图片', onClick: invertHistorySelection }, '反选'), - histSel.length ? el('span', { className: 'iwb-history-manage-tools' }, - el('button', { className: 'iwb-btn iwb-btn-sm iwb-btn-danger', title: '删除选中的图片', onClick: () => { deleteOutputs(histSel); setHistSel([]) } }, '删除'), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '下载选中的图片到本地', onClick: downloadHistorySelected }, '下载'), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '清除选择', onClick: () => setHistSel([]) }, '清除'), - ) : null, - // 紧凑版(v3.25.19):只显示档位值,前缀「插入」放进 title 与标签里,省横向空间 - el('select', { className: 'iwb-input iwb-select-compact', value: insertK, onChange: (e) => setInsertKPersist(e.target.value), title: '插入画布时的图片尺寸:原图最清晰但最大;2K/1K/0.5K 会等比压到对应边长' }, - [['orig', '原图'], ['2k', '2K'], ['1k', '1K'], ['0.5k', '0.5K']].map(([v, l]) => el('option', { key: v, value: v }, l)), - ), - el('select', { className: 'iwb-input iwb-select-compact', value: histRange, onChange: (e) => setHistRange(e.target.value), title: '按时间筛选图库' }, - [['', '全部'], ['today', '今天'], ['7d', '7 天'], ['30d', '30 天']].map(([v, l]) => el('option', { key: v, value: v }, l)), - ), - ), - el('div', { className: 'iwb-history-grid', ref: (el0) => { histGridRef.el = el0 } }, - histCols.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' + (histSel.length ? ' iwb-history-managed' : '') + (histSel.includes(f.name) ? ' iwb-history-selected' : '') }, - ((f.data || f.url)) ? el('img', { src: wDisplayThumbOf((f.data || f.url) || ''), 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) => { if (e && e.shiftKey) setHistSel((prev) => prev.includes(f.name) ? prev.filter((n) => n !== f.name) : [...prev, f.name]); else setHistSel([f.name]) }, onDoubleClick: () => { 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 === 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: async (e) => { e.stopPropagation(); let src0 = await wbCmd().refSrcOf(await wResolveOutputSrc(f), (msg) => showToast(msg, 'err')); if (typeof src0 === 'string' && src0.indexOf('data:') === 0) src0 = await shrinkForInsert(src0); const spot = findSpot('ref'); const id = uid('n'); // 2026-10-20(审计 N1):插入时**立即引用化**,不要把整张图 base64 塞进画布。 - // 原症状:插入时 data.url = 完整 base64(4K 约 10MB)⇒ 画布内存里多一份整图; - // 刷新后又被 wSanitizeWs 换成 {__blob} 引用(用户看到的「状态变了」), - // 且刷新时还要把 base64 再转回 Blob(内存数倍占用、过一会儿才回落)。 - // 修法:与「保存画布」走**同一个唯一入口** wImgRefWrite(§13.34)⇒ 画布里只留引用。 - // 写库失败时兜底用 src0(base64),保证不丢图(行为与修复前一致)。 - // ⚠️ 只有 **data: URL** 才引用化;远程图床 URL(item.url)已是字符串、 - // 不是字节,引用化无意义(wImgRefWrite 只吃 base64)⇒ 直接沿用。 - const ref0 = (typeof src0 === 'string' && src0.indexOf('data:') === 0) ? await wImgRefWrite(src0) : null; - commitCanvas(refs.nodes.concat([{ id, type: 'ref', x: spot.x, y: spot.y, data: { url: ref0 || src0 || '', data: null, name: f.name, localName: null } }]), undefined, undefined); setSel([id]); setPreview(null); showToast('已插入画布') } }, '插入'), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '复制图片到剪贴板', onClick: async (e) => { e.stopPropagation(); try { await copyImageToClipboard(await wOutputSrcForUse(f, null, true)); showToast('图片已复制(PNG)') } catch (err) { showToast(String((err && err.message) || err), 'err') } } }, '复制'), - el('button', { className: 'iwb-btn iwb-btn-sm', title: '下载到本地', onClick: async (e) => { e.stopPropagation(); downloadUrl(await wOutputSrcForUse(f), f.name) } }, '下载'), - ), - )), - )), - ), - !outputs.length ? el('div', { className: 'iwb-hint' }, '暂无图片 · 运行生图后会出现在这里') : null, - histFiltered.length > histLimit ? el('div', { className: 'iwb-history-more' }, - el('button', { className: 'iwb-btn iwb-btn-sm', onClick: () => setHistLimit((n) => n + 100) }, '显示更多(' + (histFiltered.length - histLimit) + ' 张)'), - ) : null, - el('div', { className: 'iwb-history-foot' }, - el('span', { className: 'iwb-hint' }, '自动清理:' + retentionText(outputsInfo)), - ), - ), - onClose: () => setDrawerOpen(false), - }) : null, + DockArea ? el(DockArea, { panels: dockPanels, renderIcon: I, storageKey: 'iwb.dock.v1', PluginHost, + pluginMount: (id) => { const p = wPluginPanels.find((x) => x.pluginId === id || x.id === id + '-panel'); return p ? p.mount : null }, + rightOpen: drawerOpen, onRightOpen: (v) => setDrawerOpen(v), rightActive: drawerTab === 'history' ? 'gallery' : 'prompts', + defaults: { left: { open: true, w: 318, list: ['groups', 'browser', 'styles'], active: 'browser' }, right: { open: true, w: 330, list: ['prompts', 'gallery'], active: 'gallery' } }, + onReject: (msg) => showToast(msg, 'err') }) : null, settingOpen ? ReactDOM.createPortal(el(SettingsModal, { initialTab: settingTabReq, BackupModal: BackupModal, diff --git a/docs/standards/architecture-current-state.md b/docs/standards/architecture-current-state.md index 54620a5..8b5eaa8 100644 --- a/docs/standards/architecture-current-state.md +++ b/docs/standards/architecture-current-state.md @@ -22,7 +22,7 @@ - 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob__`** (A) `app.js:2143`;`{__cache}`(Cache Storage)为兜底;\`ref_\`(`app.js` 内定义的 `IDB_REF_PREFIX = 'ref_'`)为 legacy 形态 (A)。 - 大图判定:`isBigDataUrl` = `data:` 且 `length > 3000` (A) `app.js:2018`;**画布保存保留阈值** `< 16384` 才原样保留 (A) `app.js:2182`。**两处阈值并存,含义不同**。 - 单测是**源码契约测试**:`tests/` 目录共 **493** 处源码文本钉点(`source.includes` / `source.indexOf` / `/re/.test(source)`),分布在 **20** 个文件(其中 `iwb-v32-web-test.js` 一个就占 **407**)→ **结构性重构会先打红测试**。**该数字已由 `tests/source-text-ratchet-test.js` 的「只减不增」棘轮守门**(2026-10-20 起守卫范围从 1 个文件扩到全目录:新增任何一处源码文本钉点都会打红)。**2026-11-12 复算**(`npm run audit:pins`,v3.24.76):二分 STRUCT **417** / NAME **76**;形态 **POS 403 / NEG 87 / COUNT 3**;难度 **易 62 / 中 316 / 难 115**。钉点减法第一批(v3.24.72)把 **537 → 505**:8 条探针钉点改为「门禁内 spec 是否真的读该计数器」、5 条改为运行时断言(生产态 `window` 上无探针)、10 条改为 DOM 断言(质量档位禁用 / 传输页无三模式按钮 / 模型项 title)、4 条改为运行时对象断言(健康检查两域、策略对象冻结)、其余 9 条有同文件 DOM 等价断言或仅剩 NEG。第二批(v3.24.76)把 **505 → 493**:94-5~7 三条「多标签释放语义」(10 处正则)换成 `tests/iwb-tabs-release.spec.js` 的 3 条真 e2e,剩 1 条「消费方契约」(断言该 spec 在门禁内且 spec 源码真的读两个探针);另 2 条 `wPurgeIntent.add` 钉点改为读 `src/workspace-purge.js`。**这一批一换就查出 3 个真缺陷**(objectURL 从未释放 / 彻底删除留孤儿标签 · session / 刷新后误回收打开标签的图)—— 见 CHANGELOG v3.24.76。 -- `app.js` = 单 IIFE **8,508 行**(**双层预算**:绝对上限 8,700 / 占总源码 ≤ 40%,现 **36.8%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,998 行**(上限 **3,030**,余量 32;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **89** 个模块 / 14,607 行,`sourceModules` 89 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 +- `app.js` = 单 IIFE **8,508 行**(**双层预算**:绝对上限 8,700 / 占总源码 ≤ 40%,现 **36.8%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,998 行**(上限 **3,030**,余量 32;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **90** 个模块 / 14,607 行,`sourceModules` 90 项;v3.24.68 新增 `clipboard-graph.js`,v3.24.74 新增 `image-admit.js`,v3.24.75 新增 `image-dedupe.js`,v3.24.76 新增 `workspace-purge.js`,v3.24.79 新增 `generation-provider-ping.js`,v3.24.80 删除无调用的 `createWBFlushViewport` 17 行)。 - 门禁:`npm run verify` = `verify:ci`(`build` → `node --check app.js` → `node --check dist/app.js` → `check-dist.js` → `lint`(ESLint 正确性规则,`src/` + `app.js`,P4-16a)→ `test:unit` → `test` → `test:facts`)+ `test:e2e` (A) `package.json`。 ## 2. 门禁与环境现状 @@ -167,7 +167,7 @@ - 同一张图被 3 个节点引用、hydrate 成 3 个不同 objectURL 时,preview/display 缓存各自 miss → 重复解码(与 F2 相邻)。 - **F10|`refs.genScheduler` 是桩** (A) → 未接线,暂无运行时影响(P3)。 - **F11|已建但未接线的模块层(2026-10-17 接线审计;2026-10-18 复核更正)** (A) - - **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**89 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。 + - **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**90 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。 - **仅被测试引用(9 模块 + 2 导出)**:`canvas-domain`、`generation-retry`、`generation-service`、`runtime-recovery-runner`、`runtime-state-bridge`、`runtime-store`、`storage-reconcile`、`storage-result`、`workspace-service`;导出 `IWBStorageHealthFactory`、`IWBPluginHostFactory`。(`storage-result` 是**存储层共享结果类型**,被 6 个存储模块读取,**非死代码**;`runtime-store` 为状态模型 epic 地基。) - **app.js 零引用(1 模块 + 3 导出)**:模块 `generation-controller`;导出 `IWBRuntimeMetricsFactory`、`IWBStorageRuntimeFactory`、`IWBUIComponents`。`canvas-relations` 已随 `06cf211` 删除(本文档早前把它列为"唯一可删者",实际已删)。零引用证据 = `grep -rn "<名字>" .`(排除 `node_modules|dist|vendor|test-results`)**只命中其自身赋值行**。 - **半接线 / 未接线**:`IWBRuntimeStateBridge` **无 app.js 引用(仅测试)**;`IWBRuntimeRunContext` **已接线**(`runNode` 读取运行上下文);`IWBGenerationController` 是完整但**从未被调用**的工厂;`ModularWorkspaceStore`(`app.js` 内)是 `storage-workspace` 的**预留接线 seam**(当前无下游使用,保留);`window.IWBImageFolder` 自注册后读回(装载路径)。 @@ -183,7 +183,7 @@ | `storage-reconcile` | 存储对账(`createReconciler`/`check`) | 内联对账 | 存储层收口 | | `runtime-recovery-runner` | 执行恢复候选(`candidate`/`valid`/`run`) | 内联恢复 | 断点恢复 | | `canvas-domain` | 画布域模型(`commit`/`updateNode`/`deleteNodes`…) | `CanvasStore` 那一套 | Workbench 解耦(P2-9) | - - **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**74** 项)与 `sourceModules` 顺序(**89** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。 + - **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**75** 项)与 `sourceModules` 顺序(**90** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。 ## 12. 易踩的坑 @@ -254,7 +254,7 @@ **信任模型(必须明示)**:形态 A 的插件是**可信代码**(与核心同权限、无沙箱);启停与设置是 UX 与可维护性手段,**不是安全边界**(同 §13.27 教训:前端开关一定可被绕过)。 -**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**74** 项)与 `sourceModules` 顺序(**89** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。 +**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**75** 项)与 `sourceModules` 顺序(**90** 项);新增模块、新增耦合、新增 dev 探针都**必须有意重生成对应快照**(`IWB_WRITE_BOUNDARY_SNAPSHOT=1`)。契约与行为的可执行验证在 `tests/plugin-host-test.js`(宿主单测)与 `tests/_plugin-host-probe.spec.js`(真实浏览器探针,`_` 前缀 + `iwb-dev-probe`,不进 34 门禁)。 **关键陷阱**:`normalizeNodes`(现位于 `src/canvas-normalize.js`)会**静默丢弃**不在 `NODE_H` 里的节点类型 ⇒ 新增节点类型必须先登记 `NODE_H`,否则节点一刷新就消失(§13.27 规则三的同一失败模式)。 diff --git a/package.json b/package.json index a74d255..41203f8 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "image-workbench-web", "private": true, - "version": "3.25.34", + "version": "3.25.35", "description": "Browser-based node canvas image workbench", "scripts": { "build": "node scripts/build.js && node scripts/copy-plugins.js", diff --git a/scripts/build.js b/scripts/build.js index f31e1bc..637fe93 100644 --- a/scripts/build.js +++ b/scripts/build.js @@ -89,6 +89,7 @@ const sourceModules = [ 'generation-results-store.js', 'ui-groups-sidebar.js', 'ui-lib-sidebar.js', + 'ui-dock.js', 'ui-desktop-shell.js', 'ui-appearance.js', 'runtime-download-auto.js', diff --git a/src-tauri/Cargo.lock b/src-tauri/Cargo.lock index a95298d..d41fb4e 100644 --- a/src-tauri/Cargo.lock +++ b/src-tauri/Cargo.lock @@ -1983,7 +1983,7 @@ dependencies = [ [[package]] name = "image-workbench" -version = "3.25.34" +version = "3.25.35" dependencies = [ "arboard", "base64 0.22.1", diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index d24337e..d5deaa3 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "image-workbench" -version = "3.25.34" +version = "3.25.35" description = "无限画布 · 生图工作台桌面版" authors = ["malongan"] license = "" diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 68d022a..d1709d4 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.34", + "version": "3.25.35", "identifier": "com.malongan.imageworkbench", "build": { "frontendDist": "../dist", diff --git a/src/ui-dock.js b/src/ui-dock.js new file mode 100644 index 0000000..3a462f0 --- /dev/null +++ b/src/ui-dock.js @@ -0,0 +1,358 @@ +/* 左右停靠栏(v3.25.35) + * + * 结构(对齐 Obsidian): + * [左栏] 头部:开关图标 + 各面板图标(横排,可点击切换 / 拖动排序 / 拖到另一栏) + * 主体:当前面板 + * 右缘:拖宽手柄 + * [右栏] 头部:各面板图标(横排)+ 开关图标(最右) + * 主体:当前面板 + * 左缘:拖宽手柄 + * 折叠后:窗口边缘保留 14px 窄条(上面的开关图标 = 展开入口) + * + * 约束(用户裁定): + * - 画布不动;只有工具栏/小地图按 --iwb-dock-l / --iwb-dock-r 让位(CSS 负责) + * - 宽度自由拖动、无上限;最小 100px + * - 每栏至少保留一个面板(拖走最后一个 → 阻止并提示) + * - 状态(开合/宽度/面板顺序/当前面板)持久化到 localStorage + */ +;(function (global) { + 'use strict' + const React = global.React + const el = React.createElement + const useState = React.useState + const useEffect = React.useEffect + const useRef = React.useRef + + const MIN_W = 100 + const STRIP_W = 14 + const DEFAULT_KEY = 'iwb.dock.v1' + + // 存储统一走 IWBStorageLocal 门面(src 内不得直调 localStorage) + const _store = () => (global.IWBStorageLocal && typeof global.IWBStorageLocal.getStore === 'function') ? global.IWBStorageLocal.getStore() : null + + function normalizeSide (side, def) { + const s = side && typeof side === 'object' ? side : {} + const list = Array.isArray(s.list) && s.list.length ? s.list.map(String) : def.list.slice() + const active = list.indexOf(String(s.active || '')) >= 0 ? String(s.active) : (list.indexOf(def.active) >= 0 ? def.active : list[0]) + return { + open: s.open === undefined ? def.open !== false : !!s.open, + w: Math.max(MIN_W, Number(s.w) || def.w || 300), + list, + active, + } + } + + function loadState (key, defaults) { + const def = { + left: normalizeSide(defaults && defaults.left, { open: true, w: 318, list: [], active: '' }), + right: normalizeSide(defaults && defaults.right, { open: true, w: 330, list: [], active: '' }), + } + try { + const st = _store() + const raw = st ? st.rawGet(key, null) : null + if (!raw) return def + const v = JSON.parse(raw) + return { left: normalizeSide(v && v.left, def.left), right: normalizeSide(v && v.right, def.right) } + } catch (e) { + return def + } + } + + function saveState (key, s) { + try { const st = _store(); if (st) st.rawSet(key, JSON.stringify(s)) } catch (e) { /* ignore */ } + } + + // 插件面板宿主:只在激活时挂载(切走即卸载)。挂载失败不影响其它面板。 + function PluginBox (props) { + const ref = useRef(null) + const mount = props.mount + useEffect(() => { + const node = ref.current + if (!node || typeof mount !== 'function') return undefined + try { mount(node) } catch (e) { /* 插件挂载异常不得冒泡 */ } + return undefined + }, [mount]) + return el('div', { className: 'iwb-dock-plugin', ref }) + } + + function IWBDockArea (props) { + const panels = props.panels || {} + const renderIcon = props.renderIcon || function () { return null } + const key = props.storageKey || DEFAULT_KEY + const defaults = props.defaults || { left: { open: true, w: 318, list: [], active: '' }, right: { open: true, w: 330, list: [], active: '' } } + const [dock, setDock] = useState(function () { return loadState(key, defaults) }) + const [dropInfo, setDropInfo] = useState(null) // { side, index } + const [ghost, setGhost] = useState(null) // { id, x, y } + const dragRef = useRef(null) + const dropRef = useRef(null) + const rootRef = useRef(null) + + // 顶部栏/Esc 控制右栏开合;外部 tab 变化时同步右栏激活面板 + useEffect(function () { + if (props.rightOpen === undefined) return + setDock(function (d) { return d.right.open === !!props.rightOpen ? d : { left: d.left, right: Object.assign({}, d.right, { open: !!props.rightOpen }) } }) + }, [props.rightOpen]) + useEffect(function () { + if (!props.rightActive) return + setDock(function (d) { return d.right.active === props.rightActive ? d : { left: d.left, right: Object.assign({}, d.right, { active: props.rightActive }) } }) + }, [props.rightActive]) + + // 面板注册可能是异步的(插件稍后注册):订阅插件宿主,注册后重渲染 + const PluginHost = props.PluginHost + const [rev, setRev] = useState(0) + useEffect(function () { + if (!PluginHost || typeof PluginHost.on !== 'function') return undefined + return PluginHost.on(function () { setRev(function (v) { return v + 1 }) }) + }, [PluginHost]) + + // 面板可用性兜底:插件是异步注册的,先给 1.2s 窗口;仍不可用才切到本栏第一个可用面板 + useEffect(function () { + const ok = function (id) { + const p = panels[id] + if (!p) return false + if (p.node) return true + return !!(p.pluginId && props.pluginMount && props.pluginMount(p.pluginId)) + } + const t = setTimeout(function () { + setDock(function (d) { + let changed = false + const next = { left: Object.assign({}, d.left), right: Object.assign({}, d.right) } + ;['left', 'right'].forEach(function (side) { + const s = next[side] + if (!ok(s.active)) { + const first = s.list.find(ok) + if (first) { s.active = first; changed = true } + } + }) + return changed ? next : d + }) + }, 1200) + return function () { clearTimeout(t) } + }, [rev, panels]) + + useEffect(function () { + // 拖宽时每帧都会变:节流写盘,避免 localStorage 同步写造成卡顿 + const t = setTimeout(function () { saveState(key, dock) }, 180) + return function () { clearTimeout(t) } + }, [dock]) + + // 顶栏高度是运行时值:停靠栏从顶栏下方开始(避免盖住 名称/缩放/节点数) + useEffect(function () { + const apply = function () { + const root = global.document && global.document.documentElement + const area = rootRef.current + if (!root || !area) return + const bar = global.document.querySelector('.iwb-canvas-topbar') + const host = area.parentElement + if (!bar || !host) return + const top = Math.max(0, Math.round(bar.getBoundingClientRect().bottom - host.getBoundingClientRect().top)) + root.style.setProperty('--iwb-dock-top', top + 'px') + } + apply() + if (global.requestAnimationFrame) global.requestAnimationFrame(apply) + global.addEventListener('resize', apply) + const t = setTimeout(apply, 600) + return function () { global.removeEventListener('resize', apply); clearTimeout(t) } + }, []) + + // 把两侧实际占位宽度写给 CSS(画布不动,只让其它浮层让位) + useEffect(function () { + const r = global.document && global.document.documentElement + if (!r) return + const lw = dock.left.open ? dock.left.w : STRIP_W + const rw = dock.right.open ? dock.right.w : STRIP_W + r.style.setProperty('--iwb-dock-l', lw + 'px') + r.style.setProperty('--iwb-dock-r', rw + 'px') + }, [dock.left.open, dock.left.w, dock.right.open, dock.right.w]) + + const setSide = function (side, patch) { + setDock(function (d) { + const next = { left: Object.assign({}, d.left), right: Object.assign({}, d.right) } + next[side] = Object.assign({}, next[side], patch) + return next + }) + } + + const toggle = function (side) { + const next = !dock[side].open + setSide(side, { open: next }) + if (side === 'right' && typeof props.onRightOpen === 'function') props.onRightOpen(next) + } + + // ---- 拖宽(内缘手柄) ---- + const startResize = function (side, e) { + e.preventDefault() + e.stopPropagation() + const startX = e.clientX + const startW = dock[side].w + const move = function (ev) { + const dx = ev.clientX - startX + const w = side === 'left' ? startW + dx : startW - dx + setSide(side, { w: Math.max(MIN_W, Math.round(w)) }) + } + const up = function () { + global.removeEventListener('pointermove', move) + global.removeEventListener('pointerup', up) + } + global.addEventListener('pointermove', move) + global.addEventListener('pointerup', up) + } + + // ---- 图标拖拽:同栏排序 + 跨栏移动(按鼠标位置插入) ---- + const iconCenters = function (side) { + const root = rootRef.current + if (!root) return [] + const nodes = root.querySelectorAll('.iwb-dock[data-side="' + side + '"] .iwb-dock-btn') + const out = [] + for (let i = 0; i < nodes.length; i++) { + const r = nodes[i].getBoundingClientRect() + out.push({ id: nodes[i].getAttribute('data-panel'), x: r.left + r.width / 2 }) + } + return out + } + + const indexForX = function (side, x) { + const arr = iconCenters(side) + for (let i = 0; i < arr.length; i++) if (x < arr[i].x) return i + return arr.length + } + + const onIconPointerDown = function (side, id, e) { + if (e.button !== 0) return + e.preventDefault() + e.stopPropagation() + const sx = e.clientX + const sy = e.clientY + let started = false + dragRef.current = { side, id } + + const move = function (ev) { + if (!started) { + if (Math.abs(ev.clientX - sx) < 4 && Math.abs(ev.clientY - sy) < 4) return + started = true + dragRef.current = { side, id, dragging: true } + } + const rect = rootRef.current ? rootRef.current.getBoundingClientRect() : { left: 0, width: global.innerWidth || 0 } + const mid = rect.left + rect.width / 2 + let target = ev.clientX < mid ? 'left' : 'right' + if (!dock[target].open) target = target === 'left' ? 'right' : 'left' + const info = { side: target, index: indexForX(target, ev.clientX) } + dropRef.current = info + setGhost({ id, x: ev.clientX, y: ev.clientY }) + setDropInfo(info) + } + + const up = function () { + global.removeEventListener('pointermove', move) + global.removeEventListener('pointerup', up) + const d = dragRef.current + dragRef.current = null + setGhost(null) + const info = dropRef.current + dropRef.current = null + setDropInfo(null) + if (!d || !d.dragging || !info) return + commitMove(d.side, d.id, info.side, info.index) + } + + global.addEventListener('pointermove', move) + global.addEventListener('pointerup', up) + } + + const commitMove = function (fromSide, id, toSide, toIndex) { + if (fromSide === toSide && dock[fromSide].list.length === 1) return + if (fromSide !== toSide && dock[fromSide].list.length === 1) { + if (props.onReject) props.onReject('该栏至少保留一个面板') + return + } + setDock(function (d) { + const next = { left: Object.assign({}, d.left, { list: d.left.list.slice() }), right: Object.assign({}, d.right, { list: d.right.list.slice() }) } + const src = next[fromSide].list + const at = src.indexOf(id) + if (at >= 0) src.splice(at, 1) + let idx = Math.max(0, Math.min(toIndex, next[toSide].list.length)) + if (fromSide === toSide && at >= 0 && at < idx) idx -= 1 + next[toSide].list.splice(idx, 0, id) + next[toSide].active = id + if (!next[fromSide].list.length) next[fromSide].list.push(id) // 双保险:绝不留空栏 + if (next[fromSide].list.indexOf(next[fromSide].active) < 0) next[fromSide].active = next[fromSide].list[0] + return next + }) + } + + const renderHead = function (side) { + const s = dock[side] + const isLeft = side === 'left' + const toggleBtn = el('button', { + key: 'toggle', + className: 'iwb-dock-btn iwb-dock-toggle', + title: isLeft ? '收起左栏' : '收起右栏', + 'aria-label': isLeft ? '收起左栏' : '收起右栏', + onClick: function () { toggle(side) }, + }, renderIcon(isLeft ? 'chevronLeft' : 'chevronRight')) + const icons = s.list.map(function (id) { + const p = panels[id] + return el('button', { + key: id, + className: 'iwb-dock-btn' + (s.active === id ? ' on' : ''), + 'data-panel': id, + 'aria-label': (p && p.title) || id, + onPointerDown: function (e) { onIconPointerDown(side, id, e) }, + onClick: function (e) { e.stopPropagation(); if (!dragRef.current) setSide(side, { active: id }) }, + }, renderIcon((p && p.icon) || 'panel')) + }) + return el('div', { className: 'iwb-dock-head' }, isLeft ? [toggleBtn].concat(icons) : icons.concat([toggleBtn])) + } + + const renderBody = function (side) { + const s = dock[side] + const p = panels[s.active] + if (!p) return el('div', { className: 'iwb-dock-empty' }, '面板加载中…') + 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 || '插件') + ' 未加载') + return el(PluginBox, { mount }) + } + return el('div', { className: 'iwb-dock-empty' }, '面板不可用') + } + + const renderDock = function (side) { + const s = dock[side] + if (!s.open) { + return el('div', { + key: side, + className: 'iwb-dock-strip ' + side, + title: side === 'left' ? '展开左栏' : '展开右栏', + onClick: function () { toggle(side) }, + }, renderIcon(side === 'left' ? 'chevronRight' : 'chevronLeft')) + } + const isLeft = side === 'left' + return el('div', { + key: side, + className: 'iwb-dock ' + side, + 'data-side': side, + style: { width: s.w }, + }, + renderHead(side), + el('div', { className: 'iwb-dock-body' }, renderBody(side)), + el('div', { className: 'iwb-dock-resize', onPointerDown: function (e) { startResize(side, e) } }), + (dropInfo && dropInfo.side === side) ? el('div', { + className: 'iwb-dock-drop', + style: { left: (8 + dropInfo.index * 30) + 'px' }, + }) : null + ) + } + + return el('div', { className: 'iwb-dockarea', ref: rootRef }, + renderDock('left'), + renderDock('right'), + ghost ? el('div', { className: 'iwb-dock-ghost', style: { left: ghost.x + 12, top: ghost.y + 12 } }, + renderIcon((panels[ghost.id] && panels[ghost.id].icon) || 'panel'), + el('span', null, (panels[ghost.id] && panels[ghost.id].title) || '') + ) : null + ) + } + + global.IWBDockArea = IWBDockArea +})(typeof window !== 'undefined' ? window : globalThis) \ No newline at end of file diff --git a/style.css b/style.css index bac66dd..2f74dc1 100644 --- a/style.css +++ b/style.css @@ -1247,7 +1247,8 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-world { will-change: transform; } /* v15:左侧资源面板展开时浮在画布上层,不移动画布位置 */ .iwb-overlay.drawer-open .iwb-canvas { left: 0 !important; } -.iwb-overlay.drawer-open .iwb-toolbar-wrap { left: 0 !important; } +/* 停靠栏时代:工具栏/小地图按 --iwb-dock-* 让位(画布仍不动) */ +.iwb-overlay.drawer-open .iwb-toolbar-wrap { left: var(--iwb-dock-l, 0px) !important; } .iwb-overlay.drawer-open .iwb-minimap { margin-left: 0 !important; } /* 画布顶栏:标题 + 实时通知 + 右侧图标组(padding-left 14px = 标签条 padding,标题左缘与房子图标对齐;52px 是左侧栏时代的遗留已废弃) */ .iwb-canvas-topbar { gap: 8px; padding: 0 14px; } @@ -2118,3 +2119,59 @@ html { scrollbar-width: thin; scrollbar-color: var(--iwb-border2) color-mix(in s .iwb-appear-range { flex: 1 1 0; min-width: 90px; max-width: 220px; } .iwb-appear-val { min-width: 52px; text-align: right; font-size: var(--fs-sm); color: var(--iwb-text2); } .iwb-appear-presets { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; } + +/* ===== 左右停靠栏(v3.25.35,Obsidian 式) ===== + * 画布始终 inset:0 不动;只有工具栏/小地图/提示条按 --iwb-dock-l/--iwb-dock-r 让位。 + */ +.iwb-dockarea { position: absolute; left: 0; right: 0; bottom: 0; top: var(--iwb-dock-top, 92px); z-index: 24; pointer-events: none; } +.iwb-dock { + position: absolute; top: 0; bottom: 0; display: flex; flex-direction: column; + background: var(--iwb-panel); pointer-events: auto; min-width: 100px; +} +.iwb-dock.left { left: 0; border-right: 1px solid var(--iwb-border2); } +.iwb-dock.right { right: 0; border-left: 1px solid var(--iwb-border2); } +.iwb-dock-head { + height: 40px; flex: 0 0 auto; display: flex; align-items: center; gap: 2px; + padding: 0 6px; border-bottom: 1px solid var(--iwb-border); background: var(--iwb-panel); +} +.iwb-dock.right .iwb-dock-head { justify-content: flex-end; } +.iwb-dock-btn { + width: 30px; height: 28px; flex: 0 0 auto; display: inline-flex; align-items: center; justify-content: center; + border: 0; border-radius: 7px; background: transparent; color: var(--iwb-text2); cursor: pointer; + position: relative; padding: 0; +} +.iwb-dock-btn:hover { background: var(--iwb-layer); color: var(--iwb-text); } +.iwb-dock-btn.on { background: var(--iwb-layer); color: var(--iwb-text); } +.iwb-dock-btn.on::after { + content: ''; position: absolute; left: 7px; right: 7px; bottom: 1px; height: 2px; + border-radius: 2px; background: var(--iwb-brand); +} +.iwb-dock-toggle { color: var(--iwb-text2); } +.iwb-dock-body { flex: 1 1 auto; min-height: 0; overflow: hidden; display: flex; flex-direction: column; } +.iwb-dock-body > * { min-height: 0; } +.iwb-dock-plugin { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; overflow: hidden; } +.iwb-dock-empty { padding: 16px; font-size: 12px; color: var(--iwb-text2); } +.iwb-dock-resize { position: absolute; top: 0; bottom: 0; width: 7px; cursor: ew-resize; z-index: 3; } +.iwb-dock.left .iwb-dock-resize { right: -4px; } +.iwb-dock.right .iwb-dock-resize { left: -4px; } +.iwb-dock-resize:hover { background: color-mix(in srgb, var(--iwb-text) 12%, transparent); } +.iwb-dock-strip { + position: absolute; top: 0; bottom: 0; width: 14px; pointer-events: auto; cursor: pointer; + display: flex; align-items: flex-start; justify-content: center; padding-top: 12px; + background: var(--iwb-panel); color: var(--iwb-text2); +} +.iwb-dock-strip.left { left: 0; border-right: 1px solid var(--iwb-border); } +.iwb-dock-strip.right { right: 0; border-left: 1px solid var(--iwb-border); } +.iwb-dock-strip:hover { color: var(--iwb-text); background: var(--iwb-layer); } +.iwb-dock-drop { position: absolute; top: 6px; bottom: 6px; width: 2px; border-radius: 2px; background: var(--iwb-brand); pointer-events: none; } +.iwb-dock-ghost { + position: fixed; z-index: 1000; pointer-events: none; display: inline-flex; align-items: center; gap: 6px; + height: 26px; padding: 0 10px; border-radius: 7px; font-size: 12px; + background: var(--iwb-panel); color: var(--iwb-text); border: 1px solid var(--iwb-border2); + box-shadow: 0 8px 24px rgba(0,0,0,.18); white-space: nowrap; +} +/* 其它浮层让位(画布不动) */ +.iwb-toolbar-wrap { left: var(--iwb-dock-l, 0px); right: calc(60px + var(--iwb-dock-r, 0px)); } +.iwb-minimap { right: calc(62px + var(--iwb-dock-r, 0px)); } +.iwb-statusbar { right: calc(62px + var(--iwb-dock-r, 0px)); } +.iwb-hint-bottom { left: calc(var(--iwb-dock-l, 0px) + (100% - var(--iwb-dock-l, 0px) - var(--iwb-dock-r, 0px)) / 2); } diff --git a/tests/fixtures/iwb-app-global-reads.json b/tests/fixtures/iwb-app-global-reads.json index 5c92cdd..d5226cc 100644 --- a/tests/fixtures/iwb-app-global-reads.json +++ b/tests/fixtures/iwb-app-global-reads.json @@ -9,6 +9,7 @@ "IWBCanvasText", "IWBCrashLog", "IWBDesktop", + "IWBDockArea", "IWBGalleryHydration", "IWBGalleryQuery", "IWBGenerationRequestShape", diff --git a/tests/fixtures/iwb-source-modules-order.json b/tests/fixtures/iwb-source-modules-order.json index 0661a4e..dea1559 100644 --- a/tests/fixtures/iwb-source-modules-order.json +++ b/tests/fixtures/iwb-source-modules-order.json @@ -61,6 +61,7 @@ "generation-results-store.js", "ui-groups-sidebar.js", "ui-lib-sidebar.js", + "ui-dock.js", "ui-desktop-shell.js", "ui-appearance.js", "runtime-download-auto.js", diff --git a/tests/left-resource-layout-test.js b/tests/left-resource-layout-test.js index d96aa4a..54f5f30 100644 --- a/tests/left-resource-layout-test.js +++ b/tests/left-resource-layout-test.js @@ -13,13 +13,14 @@ const source = uiAllSrc() // 被替换的 class:iwb-home-side / iwb-home-panel / iwb-canvas-topbar / iwb-fullmask / // iwb-res-tab / iwb-product-nav(详见 docs/history/source-pin-audit-2026-10-27.md) const css = fs.readFileSync(path.join(__dirname, '..', 'style.css'), 'utf8') -assert.ok(source.includes("resOpen: true")) +assert.ok(source.includes("panels: dockPanels")) +assert.ok(source.includes("storageKey: 'iwb.dock.v1'")) assert.ok(source.includes("title: '资源中心(提示词库/节点组/图库)'")) assert.ok(!source.includes("className: 'iwb-resource-rail'")) assert.ok(!source.includes("className: 'iwb-left-drawer'")) assert.ok(!source.includes("className: 'iwb-canvas-expand'")) assert.ok(!source.includes("className: 'iwb-resource-float'")) -assert.ok(source.includes("setDrawerOpen(true)")) +assert.ok(source.includes("onRightOpen: (v) => setDrawerOpen(v)")) assert.ok(source.includes("resourceTab === 'prompts'")) assert.ok(!css.includes('.iwb-leftrail')) assert.ok(css.includes('.iwb-res-tabs {')) diff --git a/tests/shell-render-behavior-test.js b/tests/shell-render-behavior-test.js index 3778e14..597faec 100644 --- a/tests/shell-render-behavior-test.js +++ b/tests/shell-render-behavior-test.js @@ -132,10 +132,13 @@ function hasClass(window, cls) { await sleep(1800) const res = liveClasses(window) - assert.ok(res.has('iwb-fullmask'), '打开资源中心后应出现 .iwb-fullmask(全屏遮罩),实际未出现') - assert.ok(res.has('iwb-res-tab'), '资源中心应有 .iwb-res-tab(页签:提示词库/节点组/图库),实际未出现') - assert.equal(window.document.querySelectorAll('.iwb-res-tab').length >= 1, true, - '资源中心页签数量应 ≥ 1') + assert.ok(res.has('iwb-dockarea'), '画布应渲染左右停靠栏容器 .iwb-dockarea,实际未出现') + assert.ok(res.has('iwb-dock'), '画布应渲染停靠面板 .iwb-dock,实际未出现') + const dockBtns = window.document.querySelectorAll('.iwb-dock-btn') + assert.ok(dockBtns.length >= 2, '停靠面板顶部应有面板图标(.iwb-dock-btn),实际 ' + dockBtns.length + ' 个') + // 旧的 .iwb-res-tab(资源中心页签)已由停靠栏顶部的图标取代 + assert.equal(window.document.querySelectorAll('.iwb-res-tab').length, 0, + '停靠栏模式下不应再渲染旧资源中心页签 .iwb-res-tab') // 资源中心里画布顶栏仍在(遮罩是叠在画布之上的) assert.ok(res.has('iwb-canvas-topbar'), '资源中心打开时画布顶栏应仍在 DOM 中(遮罩浮层,不是替换视图)') diff --git a/tests/single-canvas-shell-test.js b/tests/single-canvas-shell-test.js index 22d9a2a..5424864 100644 --- a/tests/single-canvas-shell-test.js +++ b/tests/single-canvas-shell-test.js @@ -22,9 +22,9 @@ assert.ok(source.includes("el('span', null, '我的画布')")) assert.ok(!allSrc.includes("'📚 资源中心('")) // 旧标签在全部源码里都不得残留 assert.ok(allSrc.includes("className: 'iwb-res-tabs'")) assert.ok(allSrc.includes("title: '资源中心(提示词库/节点组/图库)'")) // 组件化后位于 src/ui-app-chrome.js -assert.ok(source.includes("resOpen: true")) -assert.ok(source.includes("groupsContent:")) -assert.ok(source.includes("historyContent:")) +assert.ok(source.includes("panels: dockPanels")) +assert.ok(source.includes("groups: { title: '节点组'")) +assert.ok(source.includes("gallery: { title: '图库'")) assert.ok(allSrc.includes("className: 'iwb-res-tab'")) assert.ok(allSrc.includes("className: 'iwb-res-tabs'")) assert.ok(css.includes('.iwb-res-tabs {'))