@bovinphang/frontend-craft 2.5.0 → 2.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (156) hide show
  1. package/.claude-plugin/marketplace.json +7 -3
  2. package/.claude-plugin/plugin.json +1 -1
  3. package/CHANGELOG.md +77 -1
  4. package/CHANGELOG.zh-CN.md +77 -1
  5. package/CONTRIBUTING.md +15 -10
  6. package/CONTRIBUTING.zh-CN.md +15 -10
  7. package/README.md +69 -43
  8. package/README.openclaw.md +11 -9
  9. package/README.openclaw.zh-CN.md +11 -9
  10. package/README.zh-CN.md +69 -43
  11. package/agents/fec-typescript-reviewer.md +1 -1
  12. package/commands/fec-doc-sync.md +7 -6
  13. package/dist/bin/frontend-craft.js +30 -27
  14. package/docs/example-prompts.md +82 -69
  15. package/docs/ja-JP/README.md +110 -84
  16. package/docs/ko-KR/README.md +100 -74
  17. package/docs/project-structure.md +8 -4
  18. package/docs/runtimes/antigravity.md +1 -1
  19. package/docs/runtimes/augment.md +1 -1
  20. package/docs/runtimes/claude.md +16 -10
  21. package/docs/runtimes/claude.zh-CN.md +16 -10
  22. package/docs/runtimes/cline.md +1 -1
  23. package/docs/runtimes/codebuddy.md +1 -1
  24. package/docs/runtimes/codex.md +1 -1
  25. package/docs/runtimes/copilot.md +1 -1
  26. package/docs/runtimes/cursor.md +1 -1
  27. package/docs/runtimes/gemini.md +1 -1
  28. package/docs/runtimes/kilo.md +1 -1
  29. package/docs/runtimes/openclaw.md +1 -1
  30. package/docs/runtimes/opencode.md +1 -1
  31. package/docs/runtimes/qoder.md +1 -1
  32. package/docs/runtimes/trae.md +1 -1
  33. package/docs/runtimes/windsurf.md +1 -1
  34. package/docs/zh-CN/example-prompts.md +82 -69
  35. package/docs/zh-CN/project-structure.md +8 -4
  36. package/docs/zh-TW/README.md +88 -62
  37. package/openclaw.plugin.json +1 -1
  38. package/package.json +3 -3
  39. package/skills/eval_queries.json +179 -56
  40. package/skills/fec-accessibility-check/SKILL.md +1 -1
  41. package/skills/fec-alchemy/SKILL.md +74 -0
  42. package/skills/fec-alchemy/assets/absorption-plan-template.md +47 -0
  43. package/skills/fec-alchemy/assets/intake-template.md +55 -0
  44. package/skills/fec-alchemy/assets/review-checklist.md +31 -0
  45. package/skills/fec-alchemy/references/methodology.md +94 -0
  46. package/skills/fec-alchemy/references/originality-and-licensing.md +57 -0
  47. package/skills/fec-backend-requirements-handoff/SKILL.md +45 -0
  48. package/skills/fec-browser-storage/SKILL.md +1 -1
  49. package/skills/fec-canvas-threejs/SKILL.md +1 -1
  50. package/skills/fec-code-review/SKILL.md +11 -3
  51. package/skills/fec-data-fetching/SKILL.md +15 -15
  52. package/skills/fec-data-fetching/references/query-patterns.md +27 -1
  53. package/skills/fec-debug-framework/SKILL.md +14 -19
  54. package/skills/fec-debug-framework/references/report-template.md +58 -0
  55. package/skills/fec-doc-sync/SKILL.md +19 -17
  56. package/skills/fec-drawio-studio/SKILL.md +69 -0
  57. package/skills/fec-drawio-studio/data/THIRD_PARTY_NOTICES.md +10 -0
  58. package/skills/fec-drawio-studio/data/brand-icons.json +878 -0
  59. package/skills/fec-drawio-studio/data/shape-index.json.gz +0 -0
  60. package/skills/fec-drawio-studio/references/data-residency.md +27 -0
  61. package/skills/fec-drawio-studio/references/diagram-patterns.md +41 -0
  62. package/skills/fec-drawio-studio/references/layout-and-export.md +57 -0
  63. package/skills/fec-drawio-studio/references/troubleshooting.md +29 -0
  64. package/skills/fec-drawio-studio/references/xml-and-mermaid.md +54 -0
  65. package/skills/fec-drawio-studio/scripts/brand-symbols.mjs +99 -0
  66. package/skills/fec-drawio-studio/scripts/diagram-lint.mjs +143 -0
  67. package/skills/fec-drawio-studio/scripts/diagram-url.mjs +102 -0
  68. package/skills/fec-drawio-studio/scripts/layout-graph.mjs +107 -0
  69. package/skills/fec-drawio-studio/scripts/png-embed-fix.mjs +26 -0
  70. package/skills/fec-drawio-studio/scripts/scan-go-packages.mjs +36 -0
  71. package/skills/fec-drawio-studio/scripts/scan-js-modules.mjs +52 -0
  72. package/skills/fec-drawio-studio/scripts/scan-python-classes.mjs +30 -0
  73. package/skills/fec-drawio-studio/scripts/scan-python-modules.mjs +55 -0
  74. package/skills/fec-drawio-studio/scripts/scan-rust-modules.mjs +35 -0
  75. package/skills/fec-drawio-studio/scripts/scan-ts-modules.mjs +7 -0
  76. package/skills/fec-drawio-studio/scripts/shape-query.mjs +81 -0
  77. package/skills/fec-drawio-studio/scripts/studio-core.mjs +139 -0
  78. package/skills/fec-drawio-studio/styles/built-in/corporate.json +49 -0
  79. package/skills/fec-drawio-studio/styles/built-in/default.json +49 -0
  80. package/skills/fec-drawio-studio/styles/built-in/handdrawn.json +49 -0
  81. package/skills/fec-drawio-studio/styles/schema.json +112 -0
  82. package/skills/fec-e2e-testing/SKILL.md +5 -3
  83. package/skills/fec-e2e-testing/references/e2e-ci-reporting.md +62 -0
  84. package/skills/fec-e2e-testing/references/e2e-special-scenarios.md +52 -0
  85. package/skills/fec-e2e-testing/references/e2e-visual-regression.md +60 -0
  86. package/skills/fec-form-handling/SKILL.md +11 -11
  87. package/skills/fec-form-handling/references/advanced-form-patterns.md +34 -5
  88. package/skills/fec-image-generation/SKILL.md +56 -0
  89. package/skills/fec-image-generation/references/artifact-routing.md +80 -0
  90. package/skills/fec-image-generation/references/diagram-workflows.md +43 -0
  91. package/skills/fec-image-generation/references/png-qa-autofix.md +30 -0
  92. package/skills/fec-image-generation/scripts/png-qa.mjs +431 -0
  93. package/skills/fec-implement-from-design/SKILL.md +9 -2
  94. package/skills/fec-legacy-to-modern-migration/SKILL.md +29 -163
  95. package/skills/fec-legacy-to-modern-migration/references/migration-execution-checklist.md +110 -0
  96. package/skills/fec-legacy-to-modern-migration/references/migration-strategy-and-mapping.md +48 -0
  97. package/skills/fec-legacy-web-standard/SKILL.md +1 -1
  98. package/skills/fec-list-virtualization/SKILL.md +3 -3
  99. package/skills/fec-list-virtualization/references/virtualization-patterns.md +32 -4
  100. package/skills/fec-motion-interaction/SKILL.md +7 -0
  101. package/skills/fec-nextjs-project-standard/SKILL.md +7 -1
  102. package/skills/fec-performance-optimization/SKILL.md +9 -1
  103. package/skills/fec-performance-optimization/references/framework-performance-patterns.md +38 -0
  104. package/skills/fec-performance-optimization/references/report-template.md +59 -0
  105. package/skills/fec-pwa-implementation/SKILL.md +3 -4
  106. package/skills/fec-react-project-standard/SKILL.md +12 -4
  107. package/skills/fec-react-project-standard/references/react-performance-patterns.md +35 -0
  108. package/skills/fec-react-project-standard/references/react-project-structure.md +197 -0
  109. package/skills/fec-react-project-standard/references/react-quality-patterns.md +131 -0
  110. package/skills/fec-react-project-standard/references/react-runtime-patterns.md +293 -0
  111. package/skills/fec-refactor-clean/SKILL.md +4 -1
  112. package/skills/fec-refactor-clean/references/report-template.md +42 -0
  113. package/skills/fec-responsive-layout/references/responsive-layout-patterns.md +11 -0
  114. package/skills/fec-security-review/SKILL.md +3 -3
  115. package/skills/fec-source-driven-development/SKILL.md +26 -0
  116. package/skills/fec-state-management/SKILL.md +1 -1
  117. package/skills/fec-storybook-component-doc/SKILL.md +2 -2
  118. package/skills/fec-tailwind-design-system/references/tailwind-system-patterns.md +5 -1
  119. package/skills/fec-typescript-project-standard/SKILL.md +54 -0
  120. package/skills/{fec-typescript-type-safety → fec-typescript-project-standard}/references/type-safety-patterns.md +1 -1
  121. package/skills/{fec-typescript-type-safety/SKILL.md → fec-typescript-project-standard/references/type-safety.md} +1 -10
  122. package/skills/fec-ui-design/SKILL.md +26 -8
  123. package/skills/fec-ui-design/data/style-archetypes.json +40 -0
  124. package/skills/fec-ui-design/data/ux-quality-rules.json +35 -0
  125. package/skills/fec-ui-design/references/design-intelligence.md +66 -6
  126. package/skills/fec-ui-design/references/pre-delivery-checklist.md +6 -0
  127. package/skills/fec-ui-design/scripts/design-system.mjs +119 -1
  128. package/skills/fec-validation-fix/SKILL.md +5 -2
  129. package/skills/fec-validation-fix/references/report-template.md +43 -0
  130. package/skills/fec-vue3-project-standard/SKILL.md +12 -3
  131. package/skills/fec-vue3-project-standard/references/vue3-composables-routing.md +163 -0
  132. package/skills/fec-vue3-project-standard/references/vue3-performance-patterns.md +13 -0
  133. package/skills/fec-vue3-project-standard/references/vue3-project-structure.md +177 -0
  134. package/skills/fec-vue3-project-standard/references/vue3-state-api-quality.md +216 -0
  135. package/skills/fec-web-video-presentation/SKILL.md +61 -0
  136. package/skills/fec-web-video-presentation/data/starter-themes.json +59 -0
  137. package/skills/fec-web-video-presentation/references/chapter-craft.md +37 -0
  138. package/skills/fec-web-video-presentation/references/content-plan.md +38 -0
  139. package/skills/fec-web-video-presentation/references/recording-and-audio.md +33 -0
  140. package/skills/fec-web-video-presentation/references/theme-system.md +36 -0
  141. package/skills/fec-web-video-presentation/scripts/create-video-presentation.mjs +430 -0
  142. package/skills/fec-web-workers/SKILL.md +3 -4
  143. package/skills/metadata.json +381 -168
  144. package/skills/relations.json +136 -25
  145. package/templates/shared/rules/fec-ci-cd.md +20 -108
  146. package/templates/shared/rules/fec-design-system.md +47 -223
  147. package/templates/shared/rules/fec-error-handling.md +35 -179
  148. package/templates/shared/rules/fec-i18n.md +43 -91
  149. package/templates/shared/rules/fec-refactoring.md +4 -0
  150. package/templates/shared/rules/fec-rendering-patterns.md +28 -171
  151. package/templates/shared/rules/fec-responsive-design.md +34 -211
  152. package/templates/shared/rules/fec-state-management.md +41 -144
  153. package/templates/shared/rules/fec-typescript.md +47 -290
  154. package/skills/fec-e2e-testing/references/e2e-advanced.md +0 -176
  155. package/skills/fec-react-project-standard/references/react-project-details.md +0 -642
  156. package/skills/fec-vue3-project-standard/references/vue3-project-details.md +0 -547
@@ -0,0 +1,59 @@
1
+ # 性能分析报告模板
2
+
3
+ ```markdown
4
+ # 前端性能分析报告
5
+
6
+ > 生成时间: YYYY-MM-DD HH:mm
7
+ > 目标页面/流程: ...
8
+ > 环境: 设备、浏览器、网络、分支或版本
9
+
10
+ ## 性能目标
11
+
12
+ - 关注指标: LCP / CLS / INP / TBT / bundle size / memory / FPS
13
+ - 项目预算或目标阈值
14
+ - 用户主路径和 P95 场景
15
+
16
+ ## 基线数据
17
+
18
+ | 指标 | 当前值 | 采集方式 | 备注 |
19
+ | --- | --- | --- | --- |
20
+ | LCP | ... | Lighthouse / RUM / trace | ... |
21
+
22
+ ## 瓶颈定位
23
+
24
+ - 加载层、渲染层、数据层、主线程或资源层问题
25
+ - 关联文件、路由、chunk、组件或请求
26
+ - 支持该判断的 trace、bundle、日志或截图证据
27
+
28
+ ## 候选门禁
29
+
30
+ | 候选问题 | 指标支撑 | 定位范围 | 前端可验证性 | 结论 |
31
+ | --- | --- | --- | --- | --- |
32
+ | ... | RUM / trace / bundle / network | route / component / chunk / request | 是 / 否 / 需协作 | investigate / defer / reject |
33
+
34
+ ## 优先级
35
+
36
+ | 优先级 | 问题 | 用户影响 | 风险 |
37
+ | --- | --- | --- | --- |
38
+ | P0 / P1 / P2 | ... | ... | ... |
39
+
40
+ ## 优化方案
41
+
42
+ - 具体改法
43
+ - 替代方案
44
+ - 可维护性、可访问性和产品行为影响
45
+
46
+ ## 验证对比
47
+
48
+ | 指标 | 优化前 | 优化后 | 采集方式 |
49
+ | --- | --- | --- | --- |
50
+ | ... | ... | ... | ... |
51
+
52
+ ## 剩余风险
53
+
54
+ - 未覆盖设备、网络或浏览器
55
+ - 需要后端、设计、产品或基础设施协作的部分
56
+ - 建议监控或后续任务
57
+ ```
58
+
59
+ 分析完成后,将报告保存到 `reports/performance-review-YYYY-MM-DD-HHmmss.md`,并告知用户报告路径。
@@ -17,10 +17,10 @@ description: Use when adding or reviewing Progressive Web App capabilities such
17
17
  4. 用 Workbox 或框架插件管理 precache/runtime cache;登录、支付、权限变更等敏感请求必须走网络。
18
18
  5. 提供 offline fallback 页面和安装提示 UI,并验证首次加载、离线访问、更新激活、卸载重装。
19
19
 
20
- ## Detailed References
20
+ ## 详细参考
21
21
 
22
- - Load [references/manifest-and-icons.md](references/manifest-and-icons.md) for manifest fields, HTML links, icon requirements, screenshots, and iOS notes.
23
- - Load [references/service-worker-workbox.md](references/service-worker-workbox.md) for Service Worker registration, Workbox strategies, Vite integration, offline fallback, and update flow.
22
+ - 需要 manifest 字段、HTML 引用、图标要求、截图和 iOS 注意事项时,加载 [references/manifest-and-icons.md](references/manifest-and-icons.md)。
23
+ - 需要 Service Worker 注册、Workbox 策略、Vite 集成、离线兜底和更新流程时,加载 [references/service-worker-workbox.md](references/service-worker-workbox.md)。
24
24
 
25
25
  ## Constraints
26
26
 
@@ -33,4 +33,3 @@ description: Use when adding or reviewing Progressive Web App capabilities such
33
33
  ## Expected Output
34
34
 
35
35
  产出可安装的 Web 应用、离线 fallback、可见更新提示和明确缓存策略。验证 Lighthouse PWA、DevTools Application 面板、离线模式、更新发布和移动端安装流程。
36
-
@@ -36,7 +36,7 @@ description: Use when designing or reviewing React + TypeScript project structur
36
36
  - 哪些逻辑应下沉为通用能力
37
37
  - 哪些状态应本地管理,哪些应交给 store / query / URL
38
38
  - 状态归属复杂时使用状态管理流程先做状态清单
39
- - DTO、公共 props 或泛型组件复杂时使用 TypeScript 类型安全流程先收敛类型契约
39
+ - DTO、公共 props、泛型组件或 `tsconfig` 边界复杂时,先使用 TypeScript 项目规范流程收敛跨框架类型契约
40
40
 
41
41
  4. 输出时补齐关键质量项
42
42
  - loading / error / empty / data 状态
@@ -49,10 +49,16 @@ description: Use when designing or reviewing React + TypeScript project structur
49
49
  - 图片、视频、字体等资源是否本地化、可缓存,并避免占位 URL 进入交付
50
50
  - 页面级 Error Boundary、模块级 fallback、API 错误映射和用户可恢复动作是否一致
51
51
  - Tailwind token/variant 或响应式布局需求是否应分流到对应专项 skill
52
+ - 对明显架构性能风险做轻量筛查,如重型依赖边界、过宽 Context、高频派生值和懒加载 fallback;需要指标证据时进入性能优化 workflow
52
53
 
53
- ## Detailed References
54
+ ## 详细参考
54
55
 
55
- 需要具体 React 项目结构、组件模式、Hooks、路由、状态归属、API 层形状、错误处理、样式默认值、TypeScript 约定或审查清单时,加载 [references/react-project-details.md](references/react-project-details.md)。
56
+ 按需要加载更细的参考文件:
57
+
58
+ - 项目目录、组件分层、组件边界和组件目录建议:加载 [references/react-project-structure.md](references/react-project-structure.md)。
59
+ - 组件模式、Hooks、路由、状态归属、API 层、错误处理和 Suspense/懒加载:加载 [references/react-runtime-patterns.md](references/react-runtime-patterns.md)。
60
+ - 样式、注释、TypeScript、测试、反模式和输出检查清单:加载 [references/react-quality-patterns.md](references/react-quality-patterns.md)。
61
+ - React 项目规范层面的轻量性能约定:加载 [references/react-performance-patterns.md](references/react-performance-patterns.md)。
56
62
 
57
63
  ## Constraints
58
64
 
@@ -66,11 +72,12 @@ description: Use when designing or reviewing React + TypeScript project structur
66
72
  - 不在通用页面组件里同步引入 GSAP、Three.js、Lottie、富文本编辑器或地图 SDK;需要时用动态导入、路由级分包或叶子组件隔离。
67
73
  - 不在 React 组件中散落裸 `fetch`、API URL、token refresh 或上传流程;跨边界请求应收敛到 API 集成层。
68
74
  - 不用 Error Boundary 处理普通 API 失败;请求错误应优先落到 loading/error/empty/data 状态和可恢复操作。
75
+ - 不把 React 性能建议写成无证据的全局 memo 化;先定位请求瀑布、bundle 边界、重复渲染或 effect 误用。
69
76
 
70
77
  ## Expected Output
71
78
 
72
79
  - 组件边界清晰,pages/features/components 分层明确
73
- - Props 类型完整且明确,无 `any` 滥用
80
+ - Props 类型完整且明确;复杂公共类型或外部数据收窄已分流到 TypeScript 项目规范流程
74
81
  - 可复用逻辑已提取为 hooks,loading/error/empty/data 状态齐全
75
82
  - API 层具备类型约束和统一错误处理,状态管理符合就近原则
76
83
  - URL 状态、服务端状态、表单状态和全局客户端状态边界明确
@@ -81,3 +88,4 @@ description: Use when designing or reviewing React + TypeScript project structur
81
88
  - 必要时说明为什么这样分层
82
89
  - 对新增模块,优先输出最小可落地结构,而不是一次性过度设计
83
90
  - 对重构任务,优先保证可迁移性和风险可控
91
+ - 对性能相关 React 变更,说明触发的风险类别、证据来源和验证命令
@@ -0,0 +1,35 @@
1
+ # React performance patterns
2
+
3
+ This file keeps lightweight React project-standard performance guidance. Use the frontend performance workflow when the task needs metrics, traces, profiles, bundle analysis, network evidence, or a formal performance report.
4
+
5
+ ### 性能(与「性能优化」一节配合)
6
+
7
+ - **useMemo**:昂贵派生、大列表排序/过滤;注意不可变数据,例如 `useMemo(() => [...list].sort(...), [list])`,避免直接 `sort` 可变原数组。
8
+ - **useCallback**:传给 **`React.memo`** 子组件或作为其他 Hook 依赖的回调,在确有稳定引用需求时使用。
9
+ - **React.memo**:纯展示、props 浅比较可接受的组件;不要全局套 memo。
10
+ - **虚拟列表**:超长列表用 **TanStack Virtual**、**react-window** 等,只渲染视区内节点(路由级与组件级懒加载仍见「Suspense 与懒加载」)。
11
+
12
+ ## 性能优化
13
+
14
+ 在以下场景考虑性能优化:
15
+
16
+ - 大列表 / 大表格
17
+ - 高频重渲染组件
18
+ - 大量 props 传递的复杂树
19
+ - 重型第三方组件
20
+ - 高频变化 context
21
+
22
+ ### 推荐手段
23
+
24
+ - 合理使用 `React.memo`
25
+ - 只在必要时使用 `useMemo` / `useCallback`
26
+ - 列表使用稳定 `key`
27
+ - 大列表使用虚拟滚动
28
+ - 路由级做 code splitting
29
+ - 避免将高频变化值放进顶层 context
30
+ - 避免在 render 中无意义创建大量新对象 / 新函数 / 新数组
31
+ - 重型图表、编辑器、地图、3D 和媒体处理能力放到叶子组件或路由级懒加载边界
32
+ - 懒加载组件必须配套 loading、error、empty 或降级 UI,避免只优化包体却破坏用户状态
33
+
34
+ ---
35
+
@@ -0,0 +1,197 @@
1
+ # React project structure and component boundaries
2
+
3
+ ## 项目结构(推荐参考)
4
+
5
+ 以下为中大型 React 项目的业界最佳实践结构,按项目实际情况裁剪:
6
+
7
+ ```text
8
+ src/
9
+ ├── app/ # 应用入口与全局配置
10
+ │ ├── App.tsx # 根组件(Provider 组合)
11
+ │ ├── routes.tsx # 路由配置
12
+ │ └── providers.tsx # 全局 Provider 组装
13
+ │
14
+ ├── pages/ # 页面组件(与路由一一对应)
15
+ │ ├── Dashboard/
16
+ │ │ ├── DashboardPage.tsx
17
+ │ │ ├── components/ # 页面私有组件
18
+ │ │ └── hooks/ # 页面私有 hooks
19
+ │ ├── UserList/
20
+ │ └── Settings/
21
+ │
22
+ ├── layouts/ # 布局组件
23
+ │ ├── MainLayout.tsx # 主布局(侧边栏 + 顶栏 + 内容区)
24
+ │ ├── AuthLayout.tsx # 登录/注册页布局
25
+ │ └── BlankLayout.tsx # 空白布局(错误页等)
26
+ │
27
+ ├── features/ # 功能模块(按业务领域划分)
28
+ │ ├── auth/
29
+ │ │ ├── components/ # 模块组件
30
+ │ │ ├── hooks/ # 模块 hooks
31
+ │ │ ├── api.ts # 模块 API 调用
32
+ │ │ ├── types.ts # 模块类型定义
33
+ │ │ ├── constants.ts # 模块常量
34
+ │ │ └── index.ts # 模块公开导出
35
+ │ └── order/
36
+ │
37
+ ├── components/ # 全局共享 UI 组件
38
+ │ ├── Button/
39
+ │ │ ├── Button.tsx
40
+ │ │ ├── Button.styles.css
41
+ │ │ └── __tests__/
42
+ │ ├── Modal/
43
+ │ ├── Form/
44
+ │ └── ErrorBoundary/ # 对 react-error-boundary 等的薄封装(函数组件)
45
+ │
46
+ ├── hooks/ # 全局共享 hooks
47
+ │ ├── useAuth.ts
48
+ │ ├── useDebounce.ts
49
+ │ └── useMediaQuery.ts
50
+ │
51
+ ├── services/ # API 基础层
52
+ │ ├── request.ts # Axios/fetch 实例与拦截器
53
+ │ └── endpoints/ # API 端点定义(如按领域拆分)
54
+ │
55
+ ├── stores/ # 全局状态管理
56
+ │ ├── authStore.ts
57
+ │ └── uiStore.ts
58
+ │
59
+ ├── locales/ # 国际化语言包
60
+ │ ├── zh-CN.json # 中文
61
+ │ ├── en-US.json # 英文
62
+ │ └── index.ts # i18n 实例初始化(i18next / react-intl)
63
+ │
64
+ ├── assets/ # 静态资源
65
+ │ ├── images/ # 图片(PNG、JPG、WebP)
66
+ │ ├── icons/ # SVG 图标
67
+ │ └── fonts/ # 自定义字体
68
+ │
69
+ ├── config/ # 应用配置
70
+ │ ├── env.ts # 环境变量类型化封装
71
+ │ └── features.ts # Feature Flags 管理
72
+ │
73
+ ├── types/ # 全局共享类型
74
+ │ ├── api.ts # API 响应/请求通用类型
75
+ │ ├── models.ts # 业务实体类型
76
+ │ └── global.d.ts # 全局类型扩展(图片模块声明等)
77
+ │
78
+ ├── utils/ # 纯工具函数
79
+ │ ├── format.ts # 日期、数字、货币格式化
80
+ │ ├── validators.ts # 表单校验规则
81
+ │ └── storage.ts # LocalStorage / SessionStorage 封装
82
+ │
83
+ ├── styles/ # 全局样式与主题
84
+ │ ├── global.css # 全局基础样式(reset / normalize)
85
+ │ ├── variables.css # CSS 变量(颜色、间距、字号)
86
+ │ ├── breakpoints.ts # 响应式断点常量
87
+ │ └── themes/ # 主题定义
88
+ │ ├── light.css # 亮色主题变量
89
+ │ ├── dark.css # 暗色主题变量
90
+ │ └── index.ts # 主题切换逻辑
91
+ │
92
+ └── constants/ # 全局常量
93
+ ├── routes.ts # 路由路径常量
94
+ └── config.ts # 业务常量(分页大小、超时时间等)
95
+ ```
96
+
97
+ ### 关键原则
98
+
99
+ - `pages/` 做路由映射和页面编排,不承载大块可复用业务逻辑
100
+ - `layouts/` 负责页面骨架和布局容器,由路由配置引用
101
+ - `features/` 按业务领域划分,模块内尽量自包含
102
+ - `components/` 仅放跨页面、跨模块复用的通用组件
103
+ - `hooks/` 仅放全局通用 hooks;业务 hooks 优先放回对应 feature 或 page
104
+ - `locales/` 存放语言包 JSON 文件,组件中使用 `t('key')` 而非硬编码文案
105
+ - `assets/` 存放静态资源,图标优先使用 SVG,图片优先使用 WebP/AVIF
106
+ - `services/` 负责请求基础设施,不堆叠业务细节
107
+ - `config/` 统一封装环境变量和特性开关,禁止组件中直接读取 `import.meta.env`
108
+ - `styles/` 和主题变量统一管理,避免颜色和尺寸散落在业务代码中
109
+ - 每个模块通过 `index.ts` 管控对外公开 API,避免深层路径导入
110
+
111
+ ---
112
+
113
+ ## 组件与模块分层
114
+
115
+ 推荐分层:
116
+
117
+ ```text
118
+ 页面组件 (Pages) → 路由映射、布局组合、页面编排
119
+ └── 容器/编排层 → 数据获取、状态组织、事件编排
120
+ └── 业务组件 → 领域逻辑展示
121
+ └── 通用组件 → 无业务耦合、可跨模块复用
122
+ ```
123
+
124
+ ### 什么时候放到 `pages/`
125
+
126
+ 适合放:
127
+
128
+ - 路由入口组件
129
+ - 页面级布局组合
130
+ - 页面私有的轻量编排逻辑
131
+
132
+ 不适合放:
133
+
134
+ - 大量领域逻辑
135
+ - 可复用于多个页面的复杂业务块
136
+ - 与某个业务域强绑定的 API / hooks / types
137
+
138
+ ### 什么时候放到 `features/`
139
+
140
+ 适合放:
141
+
142
+ - 某个业务域的组件、hooks、api、types
143
+ - 可被多个页面共享但带业务语义的逻辑
144
+ - 一个完整业务单元的自包含实现
145
+
146
+ ### 什么时候放到 `components/`
147
+
148
+ 适合放:
149
+
150
+ - 按钮、弹窗、表单项、表格壳子、空态、错误态等通用 UI
151
+ - 与具体业务无关、可跨模块复用的组件
152
+
153
+ ---
154
+
155
+ ## 组件设计规范
156
+
157
+ - 使用**函数组件**、Hooks 与 TypeScript;**不要**新增类组件(Error Boundary 用 `react-error-boundary` 等库,见下文)
158
+ - **单文件规模**与拆分原则见 `templates/shared/rules/fec-react.md`「**组件文件规模**」(约 300 行内为佳,逾 500 行或复杂度过高拆子组件、Hooks、utils、类型)
159
+ - 保持组件职责单一、可组合
160
+ - 将可复用逻辑提取到 hooks
161
+ - 在合适场景优先使用受控组件 API
162
+ - props 定义清晰且类型明确
163
+ - 优先复用现有设计系统组件
164
+ - 保持可访问性与键盘交互
165
+ - 避免过深的 JSX 嵌套和重复分支
166
+ - 对可推导的值不要额外存 state
167
+
168
+ ---
169
+
170
+
171
+ ## 组件目录建议
172
+
173
+ 当组件复杂度较低时,可只保留一个文件。
174
+ 当组件包含样式、子组件、hooks、测试时,推荐使用如下结构:
175
+
176
+ ```text
177
+ ComponentName/
178
+ ├── ComponentName.tsx
179
+ ├── ComponentName.types.ts
180
+ ├── ComponentName.styles.css
181
+ ├── hooks/
182
+ │ └── useComponentLogic.ts
183
+ ├── components/
184
+ │ └── SubComponent.tsx
185
+ └── __tests__/
186
+ └── ComponentName.spec.tsx
187
+ ```
188
+
189
+ 说明:
190
+
191
+ - 类型复杂时再拆 `ComponentName.types.ts`
192
+ - 存在局部逻辑复用时再拆 `hooks/`
193
+ - 子组件仅在当前组件内部使用时,放到当前目录 `components/`
194
+ - 测试是否就近放置,应遵循仓库现有约定
195
+
196
+ ---
197
+
@@ -0,0 +1,131 @@
1
+ # React quality patterns
2
+
3
+ ## 样式接入
4
+
5
+ 本 skill 不强制具体样式方案,默认遵循仓库现状。
6
+
7
+ 适配时注意:
8
+
9
+ - Tailwind 项目继续使用 Tailwind
10
+ - CSS Modules 项目保持命名与文件组织一致
11
+ - styled-components 项目继续沿用其模式
12
+ - 主题、颜色、字号、间距等优先复用仓库 token / CSS 变量
13
+ - 避免在组件内硬编码大量视觉常量
14
+ - 禁止内联样式(除动态值外)
15
+ - 响应式处理需与项目断点约定一致
16
+
17
+ ---
18
+
19
+ ## 注释规范
20
+
21
+ - **优先使用中文**:解释「为什么这样做」、业务约束、边界情况、非显而易见的权衡时,优先用中文撰写注释,便于团队与业务方阅读。
22
+ - **与代码语言一致时的例外**:对接第三方协议字段名、HTTP 头、规范中的英文术语时,注释里可保留英文专有名词,必要时中英文并列说明。
23
+ - **少而精**:能通过清晰命名与类型表达清楚的逻辑不写废话注释;复杂分支、临时兼容、性能取舍必须写清意图。
24
+ - **公开 API**:模块或 hooks 的对外契约可用 JSDoc(`@param` / `@returns` / `@example`),说明用中文即可,除非仓库统一要求英文。
25
+
26
+ ---
27
+
28
+ ## TypeScript 规范
29
+
30
+ 通用 TypeScript 工程规则由 `fec-typescript-project-standard` 负责,包括 `tsconfig`、strictness、DTO / view model 边界、`unknown` 收窄、public API 类型、声明产物和类型测试。
31
+
32
+ React 规范只补充组件、Props、事件和 TSX 泛型写法;复杂类型建模或跨框架类型契约先分流到 `fec-typescript-project-standard`。
33
+
34
+ ### React 项目补充约定
35
+
36
+ - Props interface 命名: `ComponentNameProps`
37
+ - 事件处理函数: `handle` 前缀(如 `handleClick`)
38
+ - 回调 Props: `on` 前缀(如 `onChange`、`onSubmit`)
39
+ - 组件优先写显式 props 与返回值类型(`JSX.Element` / `React.ReactElement`),避免依赖 `React.FC` 的隐式 `children` 等行为差异
40
+ - 泛型组件使用 `<T>` 约束,保持调用处类型推导;回调与事件类型优先使用 DOM / React 自带类型(如 `React.ChangeEvent<HTMLInputElement>`)
41
+
42
+ ```tsx
43
+ interface TableProps<T extends Record<string, unknown>> {
44
+ data: T[];
45
+ columns: ColumnDef<T>[];
46
+ onRowClick?: (row: T) => void;
47
+ }
48
+ ```
49
+
50
+ ---
51
+
52
+ ## 测试规范
53
+
54
+ ### 应优先覆盖的内容
55
+
56
+ - 核心交互行为(点击、输入、提交)
57
+ - 条件渲染(loading / error / empty / data)
58
+ - 关键 hooks 的返回值和副作用
59
+ - API 调用 mock 与模块级集成测试
60
+
61
+ ### 推荐风格
62
+
63
+ - 测试用户行为,而不是实现细节
64
+ - 优先使用 `screen.getByRole`、`getByLabelText`
65
+ - 避免围绕内部 state 写脆弱测试
66
+ - 只测关键行为,不机械追求覆盖率数字
67
+
68
+ ### 示例
69
+
70
+ ```tsx
71
+ describe("UserForm", () => {
72
+ it("should submit with valid data", async () => {
73
+ const onSubmit = vi.fn();
74
+ render(<UserForm onSubmit={onSubmit} />);
75
+
76
+ await userEvent.type(screen.getByLabelText("用户名"), "test");
77
+ await userEvent.click(screen.getByRole("button", { name: "提交" }));
78
+
79
+ expect(onSubmit).toHaveBeenCalledWith({ username: "test" });
80
+ });
81
+
82
+ it("should show error on invalid input", async () => {
83
+ render(<UserForm onSubmit={vi.fn()} />);
84
+ await userEvent.click(screen.getByRole("button", { name: "提交" }));
85
+ expect(screen.getByText("用户名不能为空")).toBeInTheDocument();
86
+ });
87
+ });
88
+ ```
89
+
90
+ ---
91
+
92
+
93
+ ## 常见反模式
94
+
95
+ 避免:
96
+
97
+ - prop drilling 过深却不考虑组合或局部封装
98
+ - 对局部问题过度使用 context
99
+ - 把数据请求、视图渲染、命令式 DOM 操作全塞进一个文件
100
+ - 在 useEffect 中做可以在事件处理函数中完成的事
101
+ - 用 `useEffect + setState` 模拟本可直接计算的派生值
102
+ - 将所有状态都推进全局 store
103
+ - 在 `components/` 中放业务耦合组件
104
+ - 直接绕过模块出口,从 feature 深层路径导入
105
+ - 没有明显收益却提前做复杂优化
106
+ - **新增类组件**或手写类式 Error Boundary(应函数组件 + `react-error-boundary` 等)
107
+
108
+ ---
109
+
110
+ ## 输出检查清单
111
+
112
+ 输出 React 代码或方案时,至少检查:
113
+
114
+ - [ ] 是否先对齐了仓库现有约定
115
+ - [ ] 页面 / feature / 通用组件边界是否清晰
116
+ - [ ] 目录结构是否与模块复杂度匹配
117
+ - [ ] Props 类型完整且明确
118
+ - [ ] 解释性注释是否优先使用中文且点到要害
119
+ - [ ] 可复用逻辑是否已提取为 hooks
120
+ - [ ] loading / error / empty / data 状态是否齐全
121
+ - [ ] API 层是否具备类型约束和统一错误处理
122
+ - [ ] 复杂 DTO、外部数据收窄、公共类型或 `tsconfig` 问题是否已分流到 `fec-typescript-project-standard`
123
+ - [ ] 状态管理是否符合就近原则
124
+ - [ ] 路由级或重型模块是否考虑懒加载
125
+ - [ ] 样式方案是否与仓库保持一致
126
+ - [ ] 关键行为是否有测试覆盖
127
+ - [ ] 关键模块已用 **`react-error-boundary`**(等)包裹,且未手写类组件式 Boundary
128
+ - [ ] 超长列表是否评估虚拟化;弹窗/复合组件是否具备键盘与焦点约定
129
+ - [ ] 是否引入了不必要的新依赖或新范式
130
+
131
+ ---