Files
apes-sidebar/src/client/use-auto-animate.ts
T
Menghuan1918 9ccc147e00 feat(tasks): 第二轮真机反馈——聚合条动作行、模式 chip、弹窗用量/耗时、原生侧栏转录、动效
用户在自己跑的 3080 实例上测完报回六条,逐条修:

1. 「已完成的聚合卡下方空荡荡」= 上一轮把计数收进徽标后那条只剩一个
   chevron(我的取舍造成)。小条改为动作行:组图标 + 「展开」(新词条
   tasksFoldExpandShort × 20 词典)+ 出错尾注 + 展开箭头。
2. 「展开后的子代理点不回去」= 真缺陷:expandedGroups 压过了 foldedIds,
   展开组内卡片的 chevron 失效。改成手动折叠优先(手动 → 页级规则 →
   组展开),补模型 + 组件两层判别性用例。
3. 「一次性一直显示」→ 模式词搬进徽标行成 chip(用户口径)。智能体卡不再
   有 mono 元信息行,卡片高度预算拆成 GRAPH_AGENT_NODE_H / GRAPH_NODE_H
   (只有 workflow run 卡保留元信息行),rowStrideFor(nodes) 按模型里有没有
   run 选行距。
4. 动效:接入 @formkit/auto-animate(用户选定,~3KB、无依赖无安装脚本)+
   useAutoAnimateRef 包装(WAAPI 守卫 → jsdom 空转、尊重 reduced-motion),
   挂到画布卡片层 / 树视图 / 任务抽屉;详情卡另加 140ms 入场关键帧。核心
   bundle +56KB(未压缩 CJS)。
5. 弹窗多两项:Token 用量(宿主 tokenUsage 四桶求和,悬停给明细)+ 耗时
   (宿主 subagentTiming,按 3s 轮询刷新)。SidebarProjectionSnapshot 镜像
   补两个键、模型新增 metrics 入参;**按存在性渲染**,没有测量就不显示这一
   行(0 是投影初始态,与「没工作过」不可区分)。
6. 「查看转录」改为在原生右侧栏打开:宿主 ui-subagent 的 subagentchat tab
   类型(宿主自己的子代理列表就是点行=主窗、点 chevron=侧栏)。插件照抄其
   地址公式并调 openResource(..., { kind, preferNewPane: true }),三级降级回
   主窗;页脚变「主按钮 + caret 菜单(在主窗口中打开)」。

测试 2238 passed / 17 skipped(191 文件)、tsc 0 错误、eslint 0 错误、构建
通过;新构建已装进 sidebar-test profile,:3080 上挂载正常、0 pageerror。
动效观感与真实数据的两行数值未在真机逐帧核验(右栏在无头上下文里被
transform 移出视口,合成点击不稳)——已如实记进设计文档的第二轮偏差段。
2026-10-11 23:15:40 +08:00

43 lines
1.8 KiB
TypeScript

/**
* The Tasks page's motion host: `@formkit/auto-animate` (FLIP) attached through
* ONE guarded hook, so every animated container in the page behaves the same and
* the test / non-WAAPI environments stay inert.
*
* What it buys: cards animate in and out when a group folds or expands, siblings
* slide to their new slots, and a tree row / job row never pops. The library
* needs `Element.prototype.animate` (Web Animations API — the plugin already
* requires modern Chromium for the native sidebar) and a real layout pass, so
* the hook attaches to nothing when either is missing: jsdom renders the same
* DOM without motion, and no test has to stub an animation engine.
*
* The library respects `prefers-reduced-motion` on its own (its
* `disrespectUserMotionPreference` option defaults to false), which is the same
* contract the bar's sweep keeps in CSS.
*/
import autoAnimate from '@formkit/auto-animate'
import { useEffect, type RefObject } from 'react'
/** Whether this environment can run FLIP animations at all. */
function canAnimate(): boolean {
return typeof Element !== 'undefined'
&& typeof Element.prototype.animate === 'function'
&& typeof document !== 'undefined'
}
/**
* Animate one container's children.
*
* @param ref - the container whose DIRECT children are animated. Layout changes
* below the direct children (a card's own rows) are not animated — that is the
* library's own scope rule, and the page keeps one host per list it wants
* animated.
*/
export function useAutoAnimateRef<T extends HTMLElement>(ref: RefObject<T | null>): void {
useEffect(() => {
const element = ref.current
if (element === null || !canAnimate()) return
const controller = autoAnimate(element)
return () => { controller.destroy?.() }
}, [ref])
}