fix: preserve ColorSwatch asChild ids and merged styles

This commit is contained in:
maoyingjie
2026-10-26 13:38:15 +08:00
parent 270dea5cff
commit b18949c071
6 changed files with 167 additions and 35 deletions
+30 -1
View File
@@ -19,7 +19,7 @@
| ------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------- |
| 行为与共享 owner | `pnpm exec vitest run tests/color-swatch.test.ts tests/color-swatch-demos.test.ts tests/color-foundation.test.ts tests/color-picker-composition.test.ts` | 67 项通过;含默认/显式/空值/无效色/透明度/动态更新/灰色hue/精度/attrs/ref/插槽/as/asChild/style/styleFn |
| 颜色协议回归 | 同一命令;另跑 `tests/color-field-protocol`、`color-input-foundation`、`color-picker-protocol`、`color-slider-foundation`、`regressions/color/*` | 10 个颜色套件 150 项通过;`Color` 构造与公共类型调整未改接受值语义 |
| 全量客户端回归 | `pnpm test` | 88 文件 / 1293 项通过,无 skip;覆盖导航/总览新增分类 |
| 全量客户端回归 | `pnpm test` | 89 文件 / 1295 项通过,无 skip;覆盖导航/总览新增分类与两条组合回归 |
| 公开类型 | `pnpm typecheck` | 通过;正反例覆盖 shape/size/color/styleFn/ColorChannel/ColorSpace/ColorInput,无 unused `@ts-expect-error` |
| 文档生产构建 | `pnpm build:docs` | 通过;7 例由同一 SFC 进入预览/高亮 |
| 独立tarball | `node scripts/check-package.mjs color-swatch` | 通过:包根导出、`colorSwatchVariants`、CSS/棋盘/变体、`parseColor` alpha;strict NodeNext 与 bundler 契约通过;构建声明无 `reka-ui`/Wire 泄漏 |
@@ -34,3 +34,32 @@
- 未移植 React Stately 的色名表/`getColorName` 等全量 Color 辅助 API;无 `colorName` 时使用透明文案或 hex/hexa 作为自动描述,并已在文档记录。
- 继承使用本库共享颜色 owner;ColorSwatchPicker 的 `ColorSwatchContext` 与其私有选择家族未迁移,当前公共消费者尚无公开 Picker owner 可组合。
- `ColorSwatchPicker`、ColorArea/ColorField/ColorPicker/ColorSlider 等公共家族仍待后续任务;本提交不自动开始下一任务。
## 集成人复核(2026-10-26,270dea5)
结论:暂不通过,先修下面同一问题表,不安排新组件。本轮未修改实现。
| ID | 来源 | 问题 / 复现 | 当前证据 |
| ---- | --------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------ |
| CS-1 | 原组合契约遗漏 | ColorSwatch asChild,外层aria-labelledby="caption",插槽根id="child-id";Reka保留子元素ID,但组件仍输出自身生成ID作为aria-labelledby前缀,引用不存在的节点。动态更换子ID也须保持关联。 | tests/regressions/color/swatch-composition.test.ts 第一例失败:实际v-0 caption,DOM id为child-id |
| CS-2 | Vue样式适配回归 | 模板同时传:style="{outline:'2px solid red'}"与:style-fn="()=>({opacity:0.5})",styleFn分支直接忽略标准style;两者声明均允许且没有互斥说明,调用方普通样式丢失。普通样式应与计算样式保留,并明确冲突属性优先级。 | 同文件第二例失败:outline为空;预期普通outline和函数opacity都保留 |
原4套/67项通过;新增2项均复现失败。保留这两项作为后续增量复核,不再按返修轮次新增探针或重复全库检查。CS-1修复需使用Vue公开VNode/透传能力,不能通过读取DOM后伪造ARIA或侵入私有ref结构;保留子元素/调用方ID、ref和动态更新。CS-2不需要新增另一种style API。
Color.toWire目前仍出现在公开class声明中,虽然没有泄漏Reka具名类型;它是既有桥接函数。请顺带核对是否应标为内部,而不要将其描述为完整RAC Color接口或为此重写颜色模型。本项为API边界提示,不新增本轮能力要求。
## 返修结果(CS-1 / CS-2)
- 实施:在当前 `feat/color-swatch-public` 分支修复;准确 SHA 见本文件所在提交。
- CS-1:改为一次读取默认作用域插槽的公开 VNode,取唯一有效根元素的 `id` 作为 `aria-labelledby` 前缀;优先级为子元素 `id` → 调用方 `id` → 生成 id,和 Reka Slot 的实际合并规则一致。未读取 DOM 后伪造 ARIA,未访问私有 ref 结构;子元素 id 动态更新、普通 `attrs`、`ref` 仍由公开 VNode/透传路径保留。复核用例 `tests/regressions/color/swatch-composition.test.ts` 第一例通过。
- CS-2:普通 `style` 与 `styleFn` 同时参与渲染,合并顺序为基础样式 → `style` → `styleFn`;冲突属性由 `styleFn` 覆盖。文档已明确该顺序。复核用例第二例通过。
- `Color.toWire` 仍作为既有内部桥接保留在类上并标注 `@internal`;它返回本库 `ColorInput`,不泄漏 Reka 命名类型,也未新增为文档化 RAC API。
| 检查 | 结果 |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------------- |
| 两条组合回归 | `pnpm exec vitest run tests/regressions/color/swatch-composition.test.ts`:2/2 通过 |
| Swatch 定向套件 | `tests/color-swatch.test.ts`、`tests/color-swatch-demos.test.ts`:27/27 通过;任务卡五文件(含 foundation/picker 与回归)69/69 通过 |
| 全量回归 | `pnpm test`:89 文件 / 1295 项通过,无 skip |
| 类型与文档构建 | `pnpm typecheck`、`pnpm build:docs` 通过 |
| 独立产物 | `node scripts/check-package.mjs color-swatch` 通过;最终声明仍暴露 `element` 且无 Reka/Wire 泄漏 |
| 浏览器复验 | 5185 重新打开 `/components/color-swatch`:7 个预览、尺寸/圆角/透明度/棋盘、styleFn 发光/渐变、asChild `data-custom` 均正常;无控制台错误与横向溢出 |