merge: nodeEls 渲染块拆分(app.js 8448→8315,Workbench 2303→2169)
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 4m47s
Verify (Gitea) / gate (build · unit · facts) (push) Failing after 4m47s
This commit is contained in:
commit
f8745fb55a
12 files changed
+182
-150
No files matched your search
+2
-2
@@ -102,8 +102,8 @@ IWB_WRITE_BOUNDARY_SNAPSHOT=1 node tests/architecture-boundary-guard-test.js #
|
||||
|
||||
| 守卫 | 位置 | 现在的上限 |
|
||||
|---|---|---|
|
||||
| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **8,449**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) |
|
||||
| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,303** |
|
||||
| `app.js` 总行数 | `tests/source-text-ratchet-test.js` `MAX_APP_JS_LINES` | **8,315**(另守「占总源码 ≤ 40%」,见 `MAX_APP_JS_SHARE`) |
|
||||
| `Workbench()` 行数 | 同上 `MAX_WORKBENCH_LINES` | **2,169** |
|
||||
| 单组件行数(不含 Workbench)| 同上 `MAX_APP_COMPONENT_LINES` | **423** |
|
||||
|
||||
三条都是**只减不增**。确需在 app.js 增长时,必须**同步上调上限并在 commit 里写理由**(等于显式记账,不会悄悄发生)。
|
||||
|
||||
@@ -7331,146 +7331,12 @@ const tbCenterSeed = (type, refs) => {
|
||||
...GROUP_HANDLES.map(([dir, cls]) => el('div', { key: dir, className: 'iwb-group-handle ' + cls, 'data-dir': dir, title: '拖动调整节点组外框大小', onPointerDown: startGroupResize(dir) }, null)),
|
||||
))
|
||||
}
|
||||
const nodeEls = []
|
||||
const batchSourcesById = batchSourcesMap
|
||||
for (const n of nodes) {
|
||||
if (!visibleIds.has(n.id)) continue
|
||||
// 细粒度:只传该节点相关的 busy/progress/connTarget(其他节点引用稳定,memo 跳过)
|
||||
let busySelf = nodeDerived.busyById.get(n.id) || EMPTY_OBJ
|
||||
let progSelf = nodeDerived.progById.get(n.id) || EMPTY_OBJ
|
||||
const connTargetSelf = (connTarget && connTarget.nodeId === n.id) ? connTarget : null
|
||||
const sourceBusySelf = nodeDerived.srcBusyById.get(n.id) || EMPTY_OBJ
|
||||
const sourceProgressSelf = nodeDerived.srcProgById.get(n.id) || EMPTY_OBJ
|
||||
nodeEls.push(el(NodeCardMemo, {
|
||||
key: n.id,
|
||||
node: n,
|
||||
dragging: !!refs.drag,
|
||||
sizing: !!(refs.resize && refs.resize.nodeId === n.id), // v3.87.16:正在缩放这个节点 → 冻结它的节点体
|
||||
resizing: !!refs.resize, // v3.87.16:画布正在缩放(其它节点可跳过重渲染)
|
||||
zooming: !!refs.zooming, // v3.87.39:画布正在滚轮缩放(同上,免逐帧重建 body)
|
||||
thumbRev, // v3.87.61:显示缩略图就绪的版本号(必须传进来,否则下面的比较恒等于 undefined===undefined ✗)
|
||||
typesRev, // 2026-11-14:插件节点体注册版本号(插件异步注册完 ⇒ 强制重建节点体,别停在兜底体)
|
||||
// LOD:'' / 'lite' / 'plain'(v3.24.78 两档;判据与阈值见 IWBCanvasGeometry.lodModeOf)
|
||||
// LOD(v3.25.70):15% 阈值加**滞回**(进入 0.15 / 退出 0.18),
|
||||
// 否则在阈值附近抖一下就整批节点换体,肉眼上是「一到 15% 就卡一下」。
|
||||
lodLow: (!wLodEnabled() || !CanvasGeometry || !CanvasGeometry.lodModeOf) ? '' : CanvasGeometry.lodModeOf(lodViewport(n), n, nodeWidth),
|
||||
draggingNode: !!(refs.drag && refs.drag.start && refs.drag.start[n.id]),
|
||||
selected: sel.includes(n.id),
|
||||
measuredH: refs.measuredH[n.id],
|
||||
onMeasure: nodeOnMeasure,
|
||||
busy: busySelf,
|
||||
progress: progSelf,
|
||||
sourceBusy: sourceBusySelf,
|
||||
sourceProgress: sourceProgressSelf,
|
||||
edges,
|
||||
nodes,
|
||||
batchSources: batchSourcesById.get(n.id) || null,
|
||||
config,
|
||||
onSelect: nodeOnSelect,
|
||||
onDelete: (id) => deleteNodes([id]),
|
||||
onDuplicate: (id) => duplicateNodes([id]),
|
||||
onUpdate: updateNode,
|
||||
// 显式「粘贴图片替换参考图」入口的撤销快照(updateNode 只对参数类键入栈,图片内容不在其中)
|
||||
onSnapshot: pushHistory,
|
||||
onNotice: (text) => setNotice({ type: 'err', text }),
|
||||
connTarget: connTargetSelf,
|
||||
onRun: runNode,
|
||||
onRunLayer: runLayerNode,
|
||||
// 任务条三态按钮的「等待/结束」都走这里(此前 onCancel 从未传入节点卡片 → 旧「结束」按钮点了无反应)
|
||||
onCancel: cancelRun,
|
||||
onRunOut: runOutSources,
|
||||
taskCountOf,
|
||||
generationConcurrency: generationConcurrency(config),
|
||||
onRunLlm: runLLM,
|
||||
onFavorite: addPromptToLibrary,
|
||||
onCopyRef: addRefFromUrl,
|
||||
onPreview: nodeOnPreview,
|
||||
onInPortDown: (id) => {
|
||||
if (!refs.connFrom) {
|
||||
// 反向拖线(2026-10-30):从**输入端口**往左拖,可新建上游节点(或直接连到已有节点的输出口)
|
||||
const nd = refs.nodes.find((n) => n.id === id)
|
||||
if (!nd) return
|
||||
const inP = inPortWorld(nd)
|
||||
refs.connFrom = { nodeId: id, reverse: true, portPos: inP }
|
||||
setConnTarget(null)
|
||||
setConn({ from: id, x: inP.x, y: inP.y, reverse: true })
|
||||
return
|
||||
}
|
||||
{
|
||||
const fromId = refs.connFrom.nodeId
|
||||
if (fromId !== id) {
|
||||
const bsrcId = refs.connFrom.batchSrcId || null
|
||||
// 与在线版(Web)一致:普通节点同对仅一条边;batch 多输出按来源(batchSrcId)区分,不同来源可连同一目标
|
||||
// 立即保存最新边(override 避免 setState 未提交读旧值)
|
||||
const curEdges = refs.edges
|
||||
if (!curEdges.some((ed) => ed.from === fromId && ed.to === id && (ed.batchSrcId || null) === bsrcId) && canConnect(fromId, id)) {
|
||||
// 新增入边**不清**旧结果(2026-11-03):多接一条参考图不该让输出节点的图消失;断连才清(见 deleteEdge)
|
||||
const newEdge = bsrcId ? { id: uid('e'), from: fromId, to: id, batchSrcId: bsrcId } : { id: uid('e'), from: fromId, to: id }
|
||||
const nextEdges = curEdges.concat([newEdge])
|
||||
CanvasStore.updateEdges(nextEdges, { persist: false })
|
||||
refs.edges = nextEdges // 同步镜像:连续连线/未渲染提交期间,后续保存/操作读到最新边
|
||||
saveNow({ edges: nextEdges }) // 传入最新边,避免保存旧数据(setState 未提交前 refs 旧值)
|
||||
}
|
||||
}
|
||||
refs.connFrom = null
|
||||
setConn(null)
|
||||
}
|
||||
},
|
||||
onOutPortDown: (id, batchSrcId) => {
|
||||
// 记录输出端口的世界坐标,保证拖动连接线从端口精确出发(含普通节点,与边渲染同源)
|
||||
let portPos = null
|
||||
const node = refs.nodes.find((n) => n.id === id)
|
||||
if (node) {
|
||||
if (batchSrcId) {
|
||||
const bsrcs = refs.edges.filter((e) => e.to === id).map((e) => refs.nodes.find((n) => n.id === e.from)).filter((n) => isBatchSrc(n, refs.edges, refs.nodes)).slice().sort((a, b) => (a.y - b.y) || (a.x - b.x))
|
||||
const idx = bsrcs.findIndex((s) => s.id === batchSrcId)
|
||||
if (idx >= 0) portPos = { x: node.x + nodeWidth(node), y: node.y + batchPortTop(idx, Math.max(1, bsrcs.length), hOf(node)) }
|
||||
} else {
|
||||
portPos = { x: node.x + nodeWidth(node), y: node.y + hOf(node) / 2 }
|
||||
}
|
||||
}
|
||||
refs.connFrom = { nodeId: id, batchSrcId: batchSrcId || null, portPos }
|
||||
setConnTarget(null)
|
||||
},
|
||||
onHeaderDown: (e, id, noDrag) => {
|
||||
// Shift / Ctrl(Cmd) + 点击 = 多选切换(编组/批量操作)
|
||||
// 用 selRef 读最新选择(框选后 setSel 异步,闭包 sel 可能过期导致多选丢失)
|
||||
const curSel = selRef.current
|
||||
let ids
|
||||
if (e.shiftKey || e.metaKey || e.ctrlKey) ids = curSel.includes(id) ? curSel.filter((x) => x !== id) : curSel.concat([id])
|
||||
else ids = curSel.includes(id) ? curSel.slice() : [id]
|
||||
const start = {}
|
||||
for (const x of refs.nodes) if (ids.includes(x.id)) start[x.id] = { x: x.x, y: x.y }
|
||||
// noDrag(点在文本框/按钮/端口等可交互控件上):只选中,不启动整体拖动,避免抢走控件交互
|
||||
if (!noDrag) refs.drag = { start, gx: e.clientX / uiZoom(), gy: e.clientY / uiZoom() }
|
||||
setSel(ids)
|
||||
if (!(e.shiftKey || e.metaKey || e.ctrlKey)) setSel((current) => current.length === 1 && current[0] === id ? current : [id])
|
||||
},
|
||||
// 节点体点按:先选中 + 记录按下起点;真实移动超过阈值才启动拖动(区分点击与拖拽,避免纯点击污染撤销历史)。fromGroup:sel 来自「按下组」的整组全选 → 本次点击降级为单选该节点,否则 keepGroup 会把点击吃成整组拖动,用户得先点画布空白清选才能单选
|
||||
onBodyDown: (e, id) => {
|
||||
const curSel = selRef.current, mod = e.shiftKey || e.metaKey || e.ctrlKey, fromGroup = refs.selFromGroup; refs.selFromGroup = false
|
||||
// 框选后整体移动:点击的节点已在当前选中集合内且无修饰键 → 保持整组拖动(去掉了标题栏后 body 承担组拖动)
|
||||
const keepGroup = !mod && !fromGroup && curSel.includes(id)
|
||||
const ids = mod
|
||||
? (curSel.includes(id) ? curSel.filter((x) => x !== id) : curSel.concat([id]))
|
||||
: (keepGroup ? curSel.slice() : [id])
|
||||
const start = {}
|
||||
for (const x of refs.nodes) if (ids.includes(x.id)) start[x.id] = { x: x.x, y: x.y }
|
||||
refs.bodyDown = { id, ids, start, sx: e.clientX / uiZoom(), sy: e.clientY / uiZoom(), active: false }
|
||||
// 修饰键多选必须把算好的集合写回 sel:否则高亮 / 悬浮栏 / 组气泡都不更新,看起来「Shift 点多选没反应」
|
||||
// (拖动本身读 refs.bodyDown.ids,与新 sel 同源,保持一致)。无修饰键且点在已选集合内 = 保持整组;
|
||||
// 其余情况由 NodeCard 的 onSelect 负责,这里不重复 setSel。
|
||||
if (keepGroup || mod || fromGroup) setSel(ids)
|
||||
},
|
||||
onResizeStart: (id, e) => {
|
||||
const n0 = refs.nodes.find((x) => x.id === id)
|
||||
// 缩放起始宽/高优先用实际值(未手动调整过时),避免从全局默认值开始导致一拖就跳变
|
||||
const defW = n0 ? defaultNodeBoxWidth(n0) : NODE_W
|
||||
refs.resize = { nodeId: id, sw: n0 ? (n0.w || defW) : defW, sh: n0 ? (n0.h || refs.measuredH[id] || nodeTypeH(n0.type) || 220) : 220, gx: e.clientX / uiZoom(), gy: e.clientY / uiZoom() , lw: -1, lh: -1 }
|
||||
},
|
||||
onZoomTo: zoomToNode,
|
||||
}))
|
||||
}
|
||||
const nodeEls = IWBCanvasNodes.buildNodeEls({
|
||||
CanvasGeometry, CanvasStore, EMPTY_OBJ, NODE_W, NodeCardMemo, addPromptToLibrary, addRefFromUrl, batchPortTop, batchSourcesMap, canConnect, cancelRun, config, connTarget,
|
||||
defaultNodeBoxWidth, deleteNodes, duplicateNodes, edges, el, generationConcurrency, hOf, inPortWorld, isBatchSrc, lodViewport, nodeDerived, nodeOnMeasure, nodeOnPreview,
|
||||
nodeOnSelect, nodeTypeH, nodeWidth, nodes, pushHistory, refs, runLLM, runLayerNode, runNode, runOutSources, saveNow, sel, selRef,
|
||||
setConn, setConnTarget, setNotice, setSel, taskCountOf, thumbRev, typesRev, uiZoom, uid, updateNode, visibleIds, wLodEnabled, zoomToNode,
|
||||
})
|
||||
|
||||
// Key/服务状态:仅异常时显示(逻辑在 src/runtime-workbench-logic.js.keyAnomalyOf)
|
||||
const keyAnomaly = IWWorkbenchLogic.keyAnomalyOf(config)
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
- 图片**新写入主通道 = IndexedDB Blob `{__blob}` / key `imgblob_<hash>_<len>`** (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,449 行**(**双层预算**:绝对上限 8,449 / 占总源码 ≤ 40%,现 **26.8%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,303 行**(上限 **2,303**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **114** 个模块 / 23,075 行,`sourceModules` 114 项;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,315 行**(**双层预算**:绝对上限 8,315 / 占总源码 ≤ 40%,现 **26.4%**,2026-11-12 起;此前为单一上限 8,509、零余量);`Workbench()` = **2,169 行**(上限 **2,169**,余量 0;2026-11-16 把生成取消族 `cancelRunsFor`/`cancelRun`/`cancelTaskJobs` 与工作区列表写回族 `persistWs`/`duplicateWs` 搬进 `src/runtime-workbench-logic.js`(`createCancelActions` / `createWorkspaceListActions`),并删掉全仓零调用的 `runAll`,3090 → 2,998);大量逻辑已抽到 `src/*.js`(现 **115** 个模块 / 23,233 行,`sourceModules` 115 项;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` 不引用模块全局)。**114 个模块中 59 个导出**被 `app.js` 读取;其余为未接线 / 仅测试 / 零引用(见下)。
|
||||
- **判定法**:`global.X =` / `root.X =` 判「导出」;跨文件裸引用判「读」;排除自合并(`src/runtime-constants.js:9`)。`app.js` 是**唯一生产消费者**(无 HTML 入口;`sw.js` 不引用模块全局)。**115 个模块中 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 耦合面(**94** 项)与 `sourceModules` 顺序(**114** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
|
||||
- **耦合面已冻结**:`tests/architecture-boundary-guard-test.js`(进 `npm run test:unit` 末环)冻结 app.js↔src 耦合面(**95** 项)与 `sourceModules` 顺序(**115** 项);命名例外由第 5 组冻结,新增非 `IWB` 前缀导出即打红。
|
||||
|
||||
## 12. 易踩的坑
|
||||
|
||||
@@ -254,7 +254,7 @@
|
||||
|
||||
**信任模型(必须明示)**:形态 A 的插件是**可信代码**(与核心同权限、无沙箱);启停与设置是 UX 与可维护性手段,**不是安全边界**(同 §13.27 教训:前端开关一定可被绕过)。
|
||||
|
||||
**守门与快照**:`tests/architecture-boundary-guard-test.js` 冻结「app.js ↔ src 耦合面」(**94** 项)与 `sourceModules` 顺序(**114** 项);新增模块、新增耦合、新增 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 耦合面」(**95** 项)与 `sourceModules` 顺序(**115** 项);新增模块、新增耦合、新增 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 规则三的同一失败模式)。
|
||||
|
||||
|
||||
@@ -61,6 +61,7 @@ module.exports = [
|
||||
IWBWorkspacePurge: 'readonly',
|
||||
// 由 src/boot-load.js 挂载(2026-11-26:启动加载/数据恢复/内存护栏从 app.js 收编)
|
||||
IWBBootLoad: 'readonly',
|
||||
IWBCanvasNodes: 'readonly',
|
||||
},
|
||||
},
|
||||
linterOptions: { reportUnusedDisableDirectives: true },
|
||||
|
||||
@@ -127,6 +127,7 @@ const sourceModules = [
|
||||
'runtime-plugin-backup.js',
|
||||
'ui-canvas-view.js',
|
||||
'ui-canvas-pointer.js',
|
||||
'ui-canvas-nodes.js',
|
||||
'ui-confirm.js',
|
||||
'ui-settings-sections.js',
|
||||
'ui-settings-tab-diag.js',
|
||||
|
||||
@@ -0,0 +1,157 @@
|
||||
/* ui-canvas-nodes.js —— 画布节点列表渲染(2026-11-26 从 app.js 收编)
|
||||
*
|
||||
* 纯搬移:原「nodeEls 构建」块逐字一致,外层自由变量由 ctx(渲染期传入)提供。
|
||||
* ctx 在调用点就地求值,取值与原渲染闭包相同;不涉及 effect/时序,无 TDZ 风险。
|
||||
*
|
||||
* 依赖清单由 ESLint no-undef 反推(漏项 lint 直接红)。
|
||||
*/
|
||||
;(function (global) {
|
||||
'use strict'
|
||||
|
||||
function buildNodeEls(ctx) {
|
||||
const { CanvasGeometry, CanvasStore, EMPTY_OBJ, NODE_W, NodeCardMemo, addPromptToLibrary, addRefFromUrl, batchPortTop, batchSourcesMap, canConnect, cancelRun, config, connTarget, defaultNodeBoxWidth, deleteNodes, duplicateNodes, edges, el, generationConcurrency, hOf, inPortWorld, isBatchSrc, lodViewport, nodeDerived, nodeOnMeasure, nodeOnPreview, nodeOnSelect, nodeTypeH, nodeWidth, nodes, pushHistory, refs, runLLM, runLayerNode, runNode, runOutSources, saveNow, sel, selRef, setConn, setConnTarget, setNotice, setSel, taskCountOf, thumbRev, typesRev, uiZoom, uid, updateNode, visibleIds, wLodEnabled, zoomToNode } = ctx
|
||||
const nodeEls = []
|
||||
const batchSourcesById = batchSourcesMap
|
||||
for (const n of nodes) {
|
||||
if (!visibleIds.has(n.id)) continue
|
||||
// 细粒度:只传该节点相关的 busy/progress/connTarget(其他节点引用稳定,memo 跳过)
|
||||
let busySelf = nodeDerived.busyById.get(n.id) || EMPTY_OBJ
|
||||
let progSelf = nodeDerived.progById.get(n.id) || EMPTY_OBJ
|
||||
const connTargetSelf = (connTarget && connTarget.nodeId === n.id) ? connTarget : null
|
||||
const sourceBusySelf = nodeDerived.srcBusyById.get(n.id) || EMPTY_OBJ
|
||||
const sourceProgressSelf = nodeDerived.srcProgById.get(n.id) || EMPTY_OBJ
|
||||
nodeEls.push(el(NodeCardMemo, {
|
||||
key: n.id,
|
||||
node: n,
|
||||
dragging: !!refs.drag,
|
||||
sizing: !!(refs.resize && refs.resize.nodeId === n.id), // v3.87.16:正在缩放这个节点 → 冻结它的节点体
|
||||
resizing: !!refs.resize, // v3.87.16:画布正在缩放(其它节点可跳过重渲染)
|
||||
zooming: !!refs.zooming, // v3.87.39:画布正在滚轮缩放(同上,免逐帧重建 body)
|
||||
thumbRev, // v3.87.61:显示缩略图就绪的版本号(必须传进来,否则下面的比较恒等于 undefined===undefined ✗)
|
||||
typesRev, // 2026-11-14:插件节点体注册版本号(插件异步注册完 ⇒ 强制重建节点体,别停在兜底体)
|
||||
// LOD:'' / 'lite' / 'plain'(v3.24.78 两档;判据与阈值见 IWBCanvasGeometry.lodModeOf)
|
||||
// LOD(v3.25.70):15% 阈值加**滞回**(进入 0.15 / 退出 0.18),
|
||||
// 否则在阈值附近抖一下就整批节点换体,肉眼上是「一到 15% 就卡一下」。
|
||||
lodLow: (!wLodEnabled() || !CanvasGeometry || !CanvasGeometry.lodModeOf) ? '' : CanvasGeometry.lodModeOf(lodViewport(n), n, nodeWidth),
|
||||
draggingNode: !!(refs.drag && refs.drag.start && refs.drag.start[n.id]),
|
||||
selected: sel.includes(n.id),
|
||||
measuredH: refs.measuredH[n.id],
|
||||
onMeasure: nodeOnMeasure,
|
||||
busy: busySelf,
|
||||
progress: progSelf,
|
||||
sourceBusy: sourceBusySelf,
|
||||
sourceProgress: sourceProgressSelf,
|
||||
edges,
|
||||
nodes,
|
||||
batchSources: batchSourcesById.get(n.id) || null,
|
||||
config,
|
||||
onSelect: nodeOnSelect,
|
||||
onDelete: (id) => deleteNodes([id]),
|
||||
onDuplicate: (id) => duplicateNodes([id]),
|
||||
onUpdate: updateNode,
|
||||
// 显式「粘贴图片替换参考图」入口的撤销快照(updateNode 只对参数类键入栈,图片内容不在其中)
|
||||
onSnapshot: pushHistory,
|
||||
onNotice: (text) => setNotice({ type: 'err', text }),
|
||||
connTarget: connTargetSelf,
|
||||
onRun: runNode,
|
||||
onRunLayer: runLayerNode,
|
||||
// 任务条三态按钮的「等待/结束」都走这里(此前 onCancel 从未传入节点卡片 → 旧「结束」按钮点了无反应)
|
||||
onCancel: cancelRun,
|
||||
onRunOut: runOutSources,
|
||||
taskCountOf,
|
||||
generationConcurrency: generationConcurrency(config),
|
||||
onRunLlm: runLLM,
|
||||
onFavorite: addPromptToLibrary,
|
||||
onCopyRef: addRefFromUrl,
|
||||
onPreview: nodeOnPreview,
|
||||
onInPortDown: (id) => {
|
||||
if (!refs.connFrom) {
|
||||
// 反向拖线(2026-10-30):从**输入端口**往左拖,可新建上游节点(或直接连到已有节点的输出口)
|
||||
const nd = refs.nodes.find((n) => n.id === id)
|
||||
if (!nd) return
|
||||
const inP = inPortWorld(nd)
|
||||
refs.connFrom = { nodeId: id, reverse: true, portPos: inP }
|
||||
setConnTarget(null)
|
||||
setConn({ from: id, x: inP.x, y: inP.y, reverse: true })
|
||||
return
|
||||
}
|
||||
{
|
||||
const fromId = refs.connFrom.nodeId
|
||||
if (fromId !== id) {
|
||||
const bsrcId = refs.connFrom.batchSrcId || null
|
||||
// 与在线版(Web)一致:普通节点同对仅一条边;batch 多输出按来源(batchSrcId)区分,不同来源可连同一目标
|
||||
// 立即保存最新边(override 避免 setState 未提交读旧值)
|
||||
const curEdges = refs.edges
|
||||
if (!curEdges.some((ed) => ed.from === fromId && ed.to === id && (ed.batchSrcId || null) === bsrcId) && canConnect(fromId, id)) {
|
||||
// 新增入边**不清**旧结果(2026-11-03):多接一条参考图不该让输出节点的图消失;断连才清(见 deleteEdge)
|
||||
const newEdge = bsrcId ? { id: uid('e'), from: fromId, to: id, batchSrcId: bsrcId } : { id: uid('e'), from: fromId, to: id }
|
||||
const nextEdges = curEdges.concat([newEdge])
|
||||
CanvasStore.updateEdges(nextEdges, { persist: false })
|
||||
refs.edges = nextEdges // 同步镜像:连续连线/未渲染提交期间,后续保存/操作读到最新边
|
||||
saveNow({ edges: nextEdges }) // 传入最新边,避免保存旧数据(setState 未提交前 refs 旧值)
|
||||
}
|
||||
}
|
||||
refs.connFrom = null
|
||||
setConn(null)
|
||||
}
|
||||
},
|
||||
onOutPortDown: (id, batchSrcId) => {
|
||||
// 记录输出端口的世界坐标,保证拖动连接线从端口精确出发(含普通节点,与边渲染同源)
|
||||
let portPos = null
|
||||
const node = refs.nodes.find((n) => n.id === id)
|
||||
if (node) {
|
||||
if (batchSrcId) {
|
||||
const bsrcs = refs.edges.filter((e) => e.to === id).map((e) => refs.nodes.find((n) => n.id === e.from)).filter((n) => isBatchSrc(n, refs.edges, refs.nodes)).slice().sort((a, b) => (a.y - b.y) || (a.x - b.x))
|
||||
const idx = bsrcs.findIndex((s) => s.id === batchSrcId)
|
||||
if (idx >= 0) portPos = { x: node.x + nodeWidth(node), y: node.y + batchPortTop(idx, Math.max(1, bsrcs.length), hOf(node)) }
|
||||
} else {
|
||||
portPos = { x: node.x + nodeWidth(node), y: node.y + hOf(node) / 2 }
|
||||
}
|
||||
}
|
||||
refs.connFrom = { nodeId: id, batchSrcId: batchSrcId || null, portPos }
|
||||
setConnTarget(null)
|
||||
},
|
||||
onHeaderDown: (e, id, noDrag) => {
|
||||
// Shift / Ctrl(Cmd) + 点击 = 多选切换(编组/批量操作)
|
||||
// 用 selRef 读最新选择(框选后 setSel 异步,闭包 sel 可能过期导致多选丢失)
|
||||
const curSel = selRef.current
|
||||
let ids
|
||||
if (e.shiftKey || e.metaKey || e.ctrlKey) ids = curSel.includes(id) ? curSel.filter((x) => x !== id) : curSel.concat([id])
|
||||
else ids = curSel.includes(id) ? curSel.slice() : [id]
|
||||
const start = {}
|
||||
for (const x of refs.nodes) if (ids.includes(x.id)) start[x.id] = { x: x.x, y: x.y }
|
||||
// noDrag(点在文本框/按钮/端口等可交互控件上):只选中,不启动整体拖动,避免抢走控件交互
|
||||
if (!noDrag) refs.drag = { start, gx: e.clientX / uiZoom(), gy: e.clientY / uiZoom() }
|
||||
setSel(ids)
|
||||
if (!(e.shiftKey || e.metaKey || e.ctrlKey)) setSel((current) => current.length === 1 && current[0] === id ? current : [id])
|
||||
},
|
||||
// 节点体点按:先选中 + 记录按下起点;真实移动超过阈值才启动拖动(区分点击与拖拽,避免纯点击污染撤销历史)。fromGroup:sel 来自「按下组」的整组全选 → 本次点击降级为单选该节点,否则 keepGroup 会把点击吃成整组拖动,用户得先点画布空白清选才能单选
|
||||
onBodyDown: (e, id) => {
|
||||
const curSel = selRef.current, mod = e.shiftKey || e.metaKey || e.ctrlKey, fromGroup = refs.selFromGroup; refs.selFromGroup = false
|
||||
// 框选后整体移动:点击的节点已在当前选中集合内且无修饰键 → 保持整组拖动(去掉了标题栏后 body 承担组拖动)
|
||||
const keepGroup = !mod && !fromGroup && curSel.includes(id)
|
||||
const ids = mod
|
||||
? (curSel.includes(id) ? curSel.filter((x) => x !== id) : curSel.concat([id]))
|
||||
: (keepGroup ? curSel.slice() : [id])
|
||||
const start = {}
|
||||
for (const x of refs.nodes) if (ids.includes(x.id)) start[x.id] = { x: x.x, y: x.y }
|
||||
refs.bodyDown = { id, ids, start, sx: e.clientX / uiZoom(), sy: e.clientY / uiZoom(), active: false }
|
||||
// 修饰键多选必须把算好的集合写回 sel:否则高亮 / 悬浮栏 / 组气泡都不更新,看起来「Shift 点多选没反应」
|
||||
// (拖动本身读 refs.bodyDown.ids,与新 sel 同源,保持一致)。无修饰键且点在已选集合内 = 保持整组;
|
||||
// 其余情况由 NodeCard 的 onSelect 负责,这里不重复 setSel。
|
||||
if (keepGroup || mod || fromGroup) setSel(ids)
|
||||
},
|
||||
onResizeStart: (id, e) => {
|
||||
const n0 = refs.nodes.find((x) => x.id === id)
|
||||
// 缩放起始宽/高优先用实际值(未手动调整过时),避免从全局默认值开始导致一拖就跳变
|
||||
const defW = n0 ? defaultNodeBoxWidth(n0) : NODE_W
|
||||
refs.resize = { nodeId: id, sw: n0 ? (n0.w || defW) : defW, sh: n0 ? (n0.h || refs.measuredH[id] || nodeTypeH(n0.type) || 220) : 220, gx: e.clientX / uiZoom(), gy: e.clientY / uiZoom() , lw: -1, lh: -1 }
|
||||
},
|
||||
onZoomTo: zoomToNode,
|
||||
}))
|
||||
}
|
||||
return nodeEls
|
||||
}
|
||||
|
||||
global.IWBCanvasNodes = { buildNodeEls }
|
||||
})(typeof window !== 'undefined' ? window : globalThis)
|
||||
+1
@@ -5,6 +5,7 @@
|
||||
"IWBCanvasGeometry",
|
||||
"IWBCanvasGrid",
|
||||
"IWBCanvasHistory",
|
||||
"IWBCanvasNodes",
|
||||
"IWBCanvasNormalize",
|
||||
"IWBCanvasOps",
|
||||
"IWBCanvasPointer",
|
||||
|
||||
@@ -99,6 +99,7 @@
|
||||
"runtime-plugin-backup.js",
|
||||
"ui-canvas-view.js",
|
||||
"ui-canvas-pointer.js",
|
||||
"ui-canvas-nodes.js",
|
||||
"ui-confirm.js",
|
||||
"ui-settings-sections.js",
|
||||
"ui-settings-tab-diag.js",
|
||||
|
||||
@@ -21,7 +21,9 @@ const _uiNodeCard = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-node-c
|
||||
const _uiSettingsModal = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-settings-modal.js'), 'utf8')
|
||||
// 2026-10-29:节点体渲染按类型搬到 src/ui-node-bodies.js(renderBodyInner 瘦身),断言一并覆盖新模块。
|
||||
const _uiNodeBodies = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-node-bodies.js'), 'utf8')
|
||||
const sourceAll = source + '\n' + _uiCanvasView + '\n' + _uiNodeCard + '\n' + _uiSettingsModal + '\n' + _uiNodeBodies
|
||||
// 2026-11-26:nodeEls 构建块搬至 src/ui-canvas-nodes.js,一并纳入合并文本(断言内容不变)。
|
||||
const _uiCanvasNodes = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-canvas-nodes.js'), 'utf8')
|
||||
const sourceAll = source + '\n' + _uiCanvasView + '\n' + _uiNodeCard + '\n' + _uiSettingsModal + '\n' + _uiNodeBodies + '\n' + _uiCanvasNodes
|
||||
assert.ok(sourceAll.includes("decoding: 'async', fetchPriority: 'low'"))
|
||||
assert.ok(sourceAll.includes('const nodeMap = new Map((props.nodes || []).map((n) => [n.id, n]))'))
|
||||
assert.ok(sourceAll.includes('const batchSourcesById = batchSourcesMap') || sourceAll.includes('const batchSourcesMap = React.useMemo'))
|
||||
|
||||
@@ -20,11 +20,13 @@ const pointerSrc = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-canvas-
|
||||
// P1 拆分批 3(2026-10-28):areNodeEqual(NodeCard 的 memo 比较器)已迁到 src/canvas-geometry.js。
|
||||
// 该条钉点改读新模块,保护语义不变(仍是「拖拽期间放宽数组引用比较」这条性能契约)。
|
||||
const geometrySrc = fs.readFileSync(path.join(__dirname, '..', 'src', 'canvas-geometry.js'), 'utf8')
|
||||
// 2026-11-26:nodeEls 构建块搬至 src/ui-canvas-nodes.js,NodeCard 入参断言改守该文件。
|
||||
const nodesSrc = fs.readFileSync(path.join(__dirname, '..', 'src', 'ui-canvas-nodes.js'), 'utf8')
|
||||
assert.ok(source.includes('updateNodePositions(positionMap, options)'))
|
||||
// 方案1:拖动中走 dragApplyVisual(DOM transform,不 setNodes),避免大画布每帧 O(n) 重渲染;不再逐帧 updateNodePositions
|
||||
assert.ok(pointerSrc.includes('dragApplyVisual(positions)'))
|
||||
assert.ok(!(source + pointerSrc).includes('CanvasStore.updateNodePositions(positions, { persist: false })'))
|
||||
assert.ok(geometrySrc.includes('const stableDuringDrag = prev.dragging && next.dragging && prev.node === next.node'))
|
||||
assert.ok(source.includes('dragging: !!refs.drag'))
|
||||
assert.ok(nodesSrc.includes('dragging: !!refs.drag'))
|
||||
assert.ok(!(source + pointerSrc).includes('edgeSourceFilter'))
|
||||
console.log('node drag jank checks passed')
|
||||
@@ -170,7 +170,7 @@ const MAX_SRC_COMPONENT_LINES = 531
|
||||
// · 图标解析统一(右键菜单 + 设置页走同一解析器,2 行) +2
|
||||
// 通用件(pick/grant/stat/readDataUrl/readBlob/参数校验)全部在 src/image-file-ref.js
|
||||
// 与 src/plugin-api-images.js,app.js 只做装配。
|
||||
const MAX_APP_JS_LINES = 8449 // -209(2026-11-26:启动加载/数据恢复/内存护栏 effect 209 行搬至 src/runtime-boot-load.js;app.js 8656→8448) // +15(2026-11-26 复制/粘贴通道重写:DOM copy 事件装配、pasteCtx 增补实时选择/剪贴板读写、⌘V 改为主动粘贴;逻辑在 src/clipboard-graph.js 的 bindCopy 与 src/clipboard-paste.js 的 pasteFromKey) // +1(2026-11-26 相册外部路径重启复授权装配;逻辑在 src/image-file-ref.js) // +5(2026-11-26 标注覆盖保存:桌面端不再生成死 __cache(4 行)+ 插件 saveNodeImage 装配(1 行);事务逻辑在 src/runtime-workbench-logic.js)
|
||||
const MAX_APP_JS_LINES = 8315 // -134(2026-11-26:nodeEls 构建块 140 行搬至 src/ui-canvas-nodes.js;app.js 8448→8315) // +15(2026-11-26 复制/粘贴通道重写:DOM copy 事件装配、pasteCtx 增补实时选择/剪贴板读写、⌘V 改为主动粘贴;逻辑在 src/clipboard-graph.js 的 bindCopy 与 src/clipboard-paste.js 的 pasteFromKey) // +1(2026-11-26 相册外部路径重启复授权装配;逻辑在 src/image-file-ref.js) // +5(2026-11-26 标注覆盖保存:桌面端不再生成死 __cache(4 行)+ 插件 saveNodeImage 装配(1 行);事务逻辑在 src/runtime-workbench-logic.js)
|
||||
const MAX_APP_JS_SHARE = 0.40
|
||||
|
||||
// ── 历史记账(供回溯,逐条保留)──────────────────────────────────────────────
|
||||
@@ -213,7 +213,7 @@ const MAX_APP_JS_SHARE = 0.40
|
||||
// 需要实时读 .iwb-world 变换 + 按同类型实测高度校正视觉中心;属装配层的 DOM 读取,
|
||||
// 放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js // +10(2026-11-01):背景色「悬停预览」的 DOM 补丁助手(纯 DOM,不写数据/不进撤销栈);
|
||||
// 属装配层最小的 DOM 操作,放 src 会引入新的全局读取与边界快照改动,权衡后留在 app.js
|
||||
const MAX_WORKBENCH_LINES = 2303 // -208(2026-11-26:同上,Workbench 2511→2303) // 2026-11-26 复制/粘贴通道重写(+14:refs 新增粘贴时间戳/系统剪贴板可信标记、pasteCtx 增补 ids/clipboardOf/stageClip/readNativeText、bindCopy 装配)
|
||||
const MAX_WORKBENCH_LINES = 2169 // -134(2026-11-26:同上,Workbench 2303→2169) // 2026-11-26 复制/粘贴通道重写(+14:refs 新增粘贴时间戳/系统剪贴板可信标记、pasteCtx 增补 ids/clipboardOf/stageClip/readNativeText、bindCopy 装配)
|
||||
// 2026-11-18 v3.25.21:模态层指针守卫(2 行)
|
||||
// 实测 3090 → 2998(省 92):① 生成取消族 cancelRunsFor/cancelRun/cancelTaskJobs
|
||||
// → src/runtime-workbench-logic.js 的 createCancelActions(−53);② 工作区列表写回族
|
||||
|
||||
Vendored
+1
@@ -53,6 +53,7 @@ interface Window {
|
||||
CanvasText?: any
|
||||
IWBCanvasView?: any
|
||||
IWBBootLoad?: any
|
||||
IWBCanvasNodes?: any
|
||||
IWBUIWorkspaceTabs?: any
|
||||
IWBUICanvasTopBar?: any
|
||||
IWBUIProductNav?: any
|
||||
|
||||
Reference in new issue
Block a user