Skip to content

Conversation

@oasis-cloud
Copy link
Collaborator

@oasis-cloud oasis-cloud commented Feb 12, 2025

Summary by CodeRabbit

  • 新功能

    • 在点击行为功能中新增了可配置事件名称(默认为“click”),提升了事件响应的灵活性。
  • 重构

    • 将原先分散的钩子函数统一迁移到专用目录,优化了模块结构和依赖管理。
    • 更新了构建配置和 TypeScript 设置,以确保新增目录的文件被正确编译和处理。

@coderabbitai
Copy link

coderabbitai bot commented Feb 12, 2025

Walkthrough

本次 PR 对构建流程和代码结构进行了改进。在构建脚本(build-taro.mjs 和 build.mjs)中,扩展了 glob 模式以包含 hooks 目录,并更新了路径映射。同时,多个源文件中的导入路径已从 @/utils/... 更改为 @/hooks/...,以确保 hooks 的正确组织和引用。部分文件还对 hook 的参数及顺序做了细微调整,且 tsconfig 配置中增加了 hooks 目录的编译处理。

Changes

文件/目录 变更说明
scripts/build-taro.mjs, scripts/build.mjs 添加了 src/hooks/**/*.{ts,tsx} glob 模式,更新了 SWC 路径映射(@/hooks/*),扩展声明文件输出。
src/hooks/* 各 hook 文件调整了导入路径(如从 ./index@/utils/ 改为 ../utils@/hooks/),部分函数签名更新(如 useClickAway 增加 eventName 参数)。
src/packages/... 多个组件文件统一更新导入路径,将 @/utils/use-xxx 改为 @/hooks/use-xxx,不改变组件的功能。
src/utils/get-rect-by-taro.ts 更新导入路径,从 ./use-client-rect 改为 ../hooks/use-client-rect
tsconfig.h5.json 在 "include" 数组中新增了 "./src/hooks" 路径。

Sequence Diagram(s)

sequenceDiagram
    participant B as 构建脚本
    participant ES as ES模块构建器
    participant D as 声明文件生成器
    B->>ES: 扫描文件并包含 hooks 目录
    ES->>D: 使用更新的路径映射进行 SWC 转换
    D-->>B: 输出包含 hooks 的声明文件
Loading
sequenceDiagram
    participant C as 组件文件
    participant R as 模块解析器
    participant H as Hooks目录
    C->>R: 请求导入 hook(如 usePropsValue)
    R->>H: 将请求解析到 '@/hooks/use-props-value'
    H-->>C: 返回目标模块
Loading

Possibly related PRs

Suggested reviewers

  • oasis-cloud
  • irisSong

Poem

小兔跳跃在代码间,
策略更新步步前。
hooks 新家搬迁忙,
构建流程清晰坚。
🐰 欢庆变更乐无边!


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 6e97437 and d21e478.

📒 Files selected for processing (5)
  • scripts/build-taro.mjs (3 hunks)
  • scripts/build.mjs (2 hunks)
  • src/packages/textarea/textarea.taro.tsx (1 hunks)
  • src/packages/textarea/textarea.tsx (1 hunks)
  • src/utils/get-rect-by-taro.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (5)
  • src/utils/get-rect-by-taro.ts
  • scripts/build.mjs
  • src/packages/textarea/textarea.tsx
  • src/packages/textarea/textarea.taro.tsx
  • scripts/build-taro.mjs
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@oasis-cloud oasis-cloud requested review from Miles-hxy and xiaoyatong and removed request for xiaoyatong February 12, 2025 11:36
@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Feb 12, 2025
@codecov
Copy link

codecov bot commented Feb 12, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 85.75%. Comparing base (ccdd594) to head (d21e478).
Report is 1 commits behind head on feat_v3.x.

Additional details and impacted files
@@            Coverage Diff             @@
##           feat_v3.x    #2987   +/-   ##
==========================================
  Coverage      85.75%   85.75%           
==========================================
  Files            277      277           
  Lines          18110    18110           
  Branches        2735     2735           
==========================================
  Hits           15531    15531           
  Misses          2574     2574           
  Partials           5        5           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🔭 Outside diff range comments (1)
src/hooks/use-click-away.ts (1)

46-56: ⚠️ Potential issue

useEffect 依赖数组不完整

useEffect 的依赖数组中缺少了 eventNamehandlerisListeneruseCapture 等依赖项,这可能会导致事件监听器不能正确更新。

   useEffect(() => {
     if (isListener) {
       window.addEventListener(eventName, handler, useCapture)
     } else {
       window.removeEventListener(eventName, handler, useCapture)
     }

     return () => {
       window.removeEventListener(eventName, handler, useCapture)
     }
-  }, [target])
+  }, [target, eventName, handler, isListener, useCapture])
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2836f0a and 81dec11.

📒 Files selected for processing (93)
  • scripts/build-taro.mjs (4 hunks)
  • scripts/build.mjs (2 hunks)
  • src/hooks/use-click-away.ts (2 hunks)
  • src/hooks/use-custom-event.ts (1 hunks)
  • src/hooks/use-lock-scoll-taro.ts (1 hunks)
  • src/hooks/use-lock-scroll.ts (1 hunks)
  • src/hooks/use-props-value.ts (1 hunks)
  • src/packages/address/address.taro.tsx (1 hunks)
  • src/packages/address/address.tsx (1 hunks)
  • src/packages/avatarcropper/avatarcropper.taro.tsx (1 hunks)
  • src/packages/avatarcropper/avatarcropper.tsx (1 hunks)
  • src/packages/calendarcard/calendarcard.taro.tsx (1 hunks)
  • src/packages/calendarcard/calendarcard.tsx (1 hunks)
  • src/packages/calendaritem/calendaritem.taro.tsx (1 hunks)
  • src/packages/calendaritem/calendaritem.tsx (1 hunks)
  • src/packages/cascader/cascader.taro.tsx (1 hunks)
  • src/packages/cascader/cascader.tsx (1 hunks)
  • src/packages/checkbox/checkbox.taro.tsx (1 hunks)
  • src/packages/checkbox/checkbox.tsx (1 hunks)
  • src/packages/checkboxgroup/checkboxgroup.taro.tsx (1 hunks)
  • src/packages/checkboxgroup/checkboxgroup.tsx (1 hunks)
  • src/packages/circleprogress/circleprogress.taro.tsx (1 hunks)
  • src/packages/collapse/collapse.taro.tsx (1 hunks)
  • src/packages/collapse/collapse.tsx (1 hunks)
  • src/packages/configprovider/configprovider.taro.tsx (1 hunks)
  • src/packages/configprovider/configprovider.tsx (1 hunks)
  • src/packages/datepicker/datepicker.taro.tsx (1 hunks)
  • src/packages/datepicker/datepicker.tsx (1 hunks)
  • src/packages/dialog/dialog.taro.tsx (1 hunks)
  • src/packages/elevator/elevator.taro.tsx (1 hunks)
  • src/packages/ellipsis/ellipsis.tsx (1 hunks)
  • src/packages/imagepreview/imagepreview.taro.tsx (1 hunks)
  • src/packages/imagepreview/imagepreview.tsx (1 hunks)
  • src/packages/input/input.taro.tsx (1 hunks)
  • src/packages/input/input.tsx (1 hunks)
  • src/packages/inputnumber/inputnumber.taro.tsx (1 hunks)
  • src/packages/inputnumber/inputnumber.tsx (1 hunks)
  • src/packages/lottie/mp.taro.tsx (1 hunks)
  • src/packages/menuitem/menuitem.taro.tsx (1 hunks)
  • src/packages/menuitem/menuitem.tsx (1 hunks)
  • src/packages/noticebar/noticebar.tsx (1 hunks)
  • src/packages/notify/notify.taro.tsx (1 hunks)
  • src/packages/overlay/overlay.taro.tsx (1 hunks)
  • src/packages/overlay/overlay.tsx (1 hunks)
  • src/packages/pagination/pagination.taro.tsx (1 hunks)
  • src/packages/pagination/pagination.tsx (1 hunks)
  • src/packages/picker/picker.taro.tsx (1 hunks)
  • src/packages/picker/picker.tsx (1 hunks)
  • src/packages/picker/pickerpanel.taro.tsx (1 hunks)
  • src/packages/picker/pickerpanel.tsx (1 hunks)
  • src/packages/popover/popover.taro.tsx (1 hunks)
  • src/packages/popover/popover.tsx (1 hunks)
  • src/packages/popup/popup.taro.tsx (1 hunks)
  • src/packages/popup/popup.tsx (1 hunks)
  • src/packages/progress/progress.taro.tsx (1 hunks)
  • src/packages/pulltorefresh/pulltorefresh.taro.tsx (1 hunks)
  • src/packages/radio/radio.taro.tsx (1 hunks)
  • src/packages/radio/radio.tsx (1 hunks)
  • src/packages/radiogroup/radiogroup.taro.tsx (1 hunks)
  • src/packages/radiogroup/radiogroup.tsx (1 hunks)
  • src/packages/range/range.taro.tsx (1 hunks)
  • src/packages/range/range.tsx (1 hunks)
  • src/packages/rate/rate.taro.tsx (1 hunks)
  • src/packages/rate/rate.tsx (1 hunks)
  • src/packages/segmented/segmented.taro.tsx (1 hunks)
  • src/packages/segmented/segmented.tsx (1 hunks)
  • src/packages/shortpassword/shortpassword.taro.tsx (1 hunks)
  • src/packages/shortpassword/shortpassword.tsx (1 hunks)
  • src/packages/sidebar/sidebar.taro.tsx (1 hunks)
  • src/packages/sidebar/sidebar.tsx (1 hunks)
  • src/packages/sticky/sticky.taro.tsx (1 hunks)
  • src/packages/sticky/sticky.tsx (1 hunks)
  • src/packages/swipe/swipe.taro.tsx (1 hunks)
  • src/packages/swipe/swipe.tsx (1 hunks)
  • src/packages/swiper/effects/focus.tsx (1 hunks)
  • src/packages/swiper/swiper.tsx (1 hunks)
  • src/packages/switch/switch.taro.tsx (1 hunks)
  • src/packages/switch/switch.tsx (1 hunks)
  • src/packages/tabbar/tabbar.taro.tsx (1 hunks)
  • src/packages/tabbar/tabbar.tsx (1 hunks)
  • src/packages/table/table.taro.tsx (1 hunks)
  • src/packages/table/table.tsx (1 hunks)
  • src/packages/tabs/tabs.taro.tsx (1 hunks)
  • src/packages/tabs/tabs.tsx (1 hunks)
  • src/packages/textarea/textarea.taro.tsx (1 hunks)
  • src/packages/textarea/textarea.tsx (1 hunks)
  • src/packages/toast/toast.taro.tsx (1 hunks)
  • src/packages/tour/tour.taro.tsx (1 hunks)
  • src/packages/tour/tour.tsx (1 hunks)
  • src/packages/uploader/uploader.taro.tsx (1 hunks)
  • src/packages/uploader/uploader.tsx (1 hunks)
  • src/utils/get-rect-by-taro.ts (1 hunks)
  • tsconfig.h5.json (1 hunks)
✅ Files skipped from review due to trivial changes (86)
  • src/packages/radio/radio.tsx
  • src/packages/cascader/cascader.taro.tsx
  • src/packages/notify/notify.taro.tsx
  • src/packages/lottie/mp.taro.tsx
  • src/packages/picker/pickerpanel.tsx
  • src/packages/datepicker/datepicker.tsx
  • src/packages/pagination/pagination.tsx
  • src/packages/switch/switch.tsx
  • src/packages/menuitem/menuitem.taro.tsx
  • src/packages/picker/pickerpanel.taro.tsx
  • src/packages/table/table.taro.tsx
  • src/hooks/use-lock-scroll.ts
  • src/packages/pagination/pagination.taro.tsx
  • src/packages/sidebar/sidebar.taro.tsx
  • src/packages/configprovider/configprovider.taro.tsx
  • src/packages/overlay/overlay.tsx
  • src/packages/radiogroup/radiogroup.taro.tsx
  • src/packages/imagepreview/imagepreview.taro.tsx
  • src/packages/imagepreview/imagepreview.tsx
  • src/packages/checkbox/checkbox.taro.tsx
  • src/packages/checkbox/checkbox.tsx
  • src/packages/picker/picker.tsx
  • src/packages/menuitem/menuitem.tsx
  • src/packages/address/address.taro.tsx
  • src/utils/get-rect-by-taro.ts
  • src/packages/noticebar/noticebar.tsx
  • src/packages/segmented/segmented.tsx
  • src/packages/circleprogress/circleprogress.taro.tsx
  • src/packages/tabbar/tabbar.tsx
  • src/packages/swipe/swipe.tsx
  • src/packages/pulltorefresh/pulltorefresh.taro.tsx
  • src/packages/address/address.tsx
  • src/packages/tour/tour.taro.tsx
  • src/packages/popup/popup.taro.tsx
  • src/packages/calendarcard/calendarcard.tsx
  • src/packages/elevator/elevator.taro.tsx
  • src/packages/radiogroup/radiogroup.tsx
  • src/packages/radio/radio.taro.tsx
  • src/packages/range/range.taro.tsx
  • src/hooks/use-custom-event.ts
  • src/packages/uploader/uploader.taro.tsx
  • src/packages/collapse/collapse.taro.tsx
  • src/packages/input/input.taro.tsx
  • src/packages/popover/popover.taro.tsx
  • src/hooks/use-props-value.ts
  • src/packages/tabs/tabs.tsx
  • src/packages/tour/tour.tsx
  • src/packages/swiper/swiper.tsx
  • src/packages/sticky/sticky.taro.tsx
  • src/packages/avatarcropper/avatarcropper.taro.tsx
  • src/packages/tabs/tabs.taro.tsx
  • src/packages/avatarcropper/avatarcropper.tsx
  • src/packages/swiper/effects/focus.tsx
  • src/packages/segmented/segmented.taro.tsx
  • src/packages/shortpassword/shortpassword.taro.tsx
  • src/packages/sidebar/sidebar.tsx
  • src/packages/calendarcard/calendarcard.taro.tsx
  • src/packages/overlay/overlay.taro.tsx
  • src/packages/popover/popover.tsx
  • src/packages/toast/toast.taro.tsx
  • src/packages/range/range.tsx
  • src/packages/cascader/cascader.tsx
  • src/packages/checkboxgroup/checkboxgroup.tsx
  • src/packages/rate/rate.taro.tsx
  • src/packages/popup/popup.tsx
  • src/packages/shortpassword/shortpassword.tsx
  • src/packages/tabbar/tabbar.taro.tsx
  • src/packages/progress/progress.taro.tsx
  • src/packages/calendaritem/calendaritem.taro.tsx
  • src/packages/sticky/sticky.tsx
  • src/packages/swipe/swipe.taro.tsx
  • src/packages/calendaritem/calendaritem.tsx
  • src/packages/textarea/textarea.tsx
  • src/packages/textarea/textarea.taro.tsx
  • src/packages/checkboxgroup/checkboxgroup.taro.tsx
  • src/packages/uploader/uploader.tsx
  • src/packages/table/table.tsx
  • src/packages/collapse/collapse.tsx
  • src/packages/inputnumber/inputnumber.tsx
  • src/packages/rate/rate.tsx
  • src/packages/input/input.tsx
  • src/packages/configprovider/configprovider.tsx
  • src/packages/datepicker/datepicker.taro.tsx
  • src/packages/switch/switch.taro.tsx
  • src/packages/inputnumber/inputnumber.taro.tsx
  • src/packages/ellipsis/ellipsis.tsx
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (7)
src/hooks/use-lock-scoll-taro.ts (1)

3-3: 导入路径更新正确!

导入路径的更改符合将 hooks 移动到专用目录的重构目标。

src/packages/dialog/dialog.taro.tsx (1)

16-17: 导入路径更新正确!

hooks 的导入路径已正确更新,符合目录结构重构的要求。

scripts/build.mjs (1)

40-40: 构建配置更新正确!

构建脚本已正确添加了 hooks 目录的 glob 模式和路径映射,确保了 hooks 可以被正确构建和引用。

Also applies to: 66-66

scripts/build-taro.mjs (2)

81-81: 构建脚本中新增了 hooks 目录的处理!

新增的 glob 模式确保了 hooks 目录下的文件能被正确构建。


107-107: 路径映射配置更新完善!

为 hooks 目录添加了别名映射 @/hooks/*,与目录结构调整保持一致。

src/packages/picker/picker.taro.tsx (1)

14-14: 导入路径更新正确!

hooks 的导入路径从 @/utils/ 更新为 @/hooks/,符合新的目录结构。

Also applies to: 17-17

tsconfig.h5.json (1)

6-6: TypeScript 配置更新完善!

在 include 数组中添加了 "./src/hooks" 路径,确保 hooks 目录下的文件能被正确编译。

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) and removed action:review This PR needs more reviews (less than 2 approvals) labels Feb 13, 2025
@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) and removed action:review This PR needs more reviews (less than 2 approvals) labels Feb 13, 2025
Copy link
Collaborator

@Miles-hxy Miles-hxy left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

utils里的相关文件需要删除吗

@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) and removed action:review This PR needs more reviews (less than 2 approvals) labels Feb 13, 2025
@github-actions github-actions bot added action:review This PR needs more reviews (less than 2 approvals) and removed action:review This PR needs more reviews (less than 2 approvals) labels Feb 13, 2025
@xiaoyatong xiaoyatong merged commit 9485fe0 into jdf2e:feat_v3.x Feb 13, 2025
8 checks passed
oasis-cloud added a commit to oasis-cloud/nutui-react that referenced this pull request Feb 20, 2025
* chore: refactor the directory structure of hooks

* fix: alias

* fix: alias configuration in the taro project

* fix: review

* fix: review
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Target branch 3.x action:review This PR needs more reviews (less than 2 approvals) size/L

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants