Skip to content

feat(demoblock): code block scrolling behavior, CodesandBox function and copyCode styles - #3106

Merged
xiaoyatong merged 4 commits into
jdf2e:feat_v3.xfrom
Miles-hxy:fix_site_style
Mar 25, 2025
Merged

xiaoyatong merged 4 commits into
jdf2e:feat_v3.xfrom
Miles-hxy:fix_site_style

Conversation

@Miles-hxy

@Miles-hxy Miles-hxy commented Mar 20, 2025

Copy link
Copy Markdown
Collaborator

🤔 这个变动的性质是?

  • 新特性提交
  • 日常 bug 修复
  • 站点、文档改进
  • 演示代码改进
  • 组件样式/交互改进
  • TypeScript 定义更新
  • 包体积优化
  • 性能优化
  • 功能增强
  • 国际化改进
  • 重构
  • 代码风格优化
  • 测试用例
  • 分支合并
  • 其他改动(是关于什么的改动?)

🔗 相关 Issue

💡 需求背景和解决方案

☑️ 请求合并前的自查清单

⚠️ 请自检并全部勾选全部选项⚠️

  • 文档已补充或无须补充
  • 代码演示已提供或无须提供
  • TypeScript 定义已补充或无须补充
  • fork仓库代码是否为最新避免文件冲突
  • Files changed 没有 package.json lock 等无关文件

Summary by CodeRabbit

  • 样式

    • 为演示区代码块增加了自定义样式(包括固定最大高度与定制滚动条),提升了阅读和浏览体验。
  • 新功能

    • 优化了演示组件的渲染逻辑,使在线预览功能更加流畅。
    • 新增了支持CodeSandbox在线编辑和预览的文件,提供更好的互动体验。
  • 杂项

    • 添加了新的依赖项,以增强CodeSandbox集成功能。

@coderabbitai

coderabbitai Bot commented Mar 20, 2025

Copy link
Copy Markdown

Walkthrough

此次改动主要涉及 DemoBlock 组件相关样式和逻辑的更新。在样式文件中,为 .demo-block code 添加了最大高度和定制滚动条样式。组件文件中移除了不再使用的 compressText 导入,加入了 codesandbox 所需的导入,并重构了 useEffect 钩子,采用 createRoot 进行渲染,同时调整了输出结构。主项目的 package.json 中新增了 codesandbox 依赖,同时还新增了用于 CodeSandbox 环境的 index.html 与 package.json 文件。

Changes

文件路径 改动概述
src/.../demoblock.scss 新增 .demo-block code 样式:设置最大高度(580px)、启用垂直滚动及自定义滚动条(6px 宽、高、透明背景、#ccc 颜色和 4px 圆角)
src/.../demoblock.tsx 更新 DemoBlock 组件:移除 compressText 导入,添加 getParameters 及原始文件导入;重构 useEffect 使用 createRoot 渲染 Demo 组件,并将子元素包裹于 <div class="demo-block">
package.json 主项目中新增依赖 "codesandbox": "^2.2.3"
src/.../codesandbox/index.html
src/.../codesandbox/package.json
新增 CodeSandbox 相关文件:index.html 文件定义基础网页结构,package.json 文件配置了 React 项目所需的依赖、脚本及浏览器兼容性设置

Sequence Diagram(s)

sequenceDiagram
    participant DB as DemoBlock 组件
    participant CR as createRoot (react-dom/client)
    participant CSB as CodeSandbox API

    DB->>CR: 调用 createRoot 挂载 Demo 组件
    CR->>DB: 完成组件渲染
    DB->>CSB: 使用 getParameters 生成 onlineUrl
Loading

Suggested reviewers

  • oasis-cloud
  • xiaoyatong

Poem

我是一只跳跃的小兔子,
在代码丛林中巡游嬉戏。
滚动条轻盈绘出新画面,
DemoBlock 在阳光下焕然一新。
依赖与逻辑交织成诗,
我欢庆这段优美的代码旅程!

✨ Finishing Touches
  • 📝 Generate Docstrings

🪧 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.
  • @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.

@github-actions github-actions Bot added action:review This PR needs more reviews (less than 2 approvals) 3.x Target branch 3.x labels Mar 20, 2025
@codecov

codecov Bot commented Mar 20, 2025

Copy link
Copy Markdown

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 86.95%. Comparing base (2a74f0f) to head (1ee7002).
Report is 7 commits behind head on feat_v3.x.

Additional details and impacted files
@@              Coverage Diff              @@
##           feat_v3.x    #3106      +/-   ##
=============================================
+ Coverage      86.49%   86.95%   +0.46%     
=============================================
  Files            280      280              
  Lines          18492    18456      -36     
  Branches        2774     2785      +11     
=============================================
+ Hits           15994    16049      +55     
+ Misses          2493     2402      -91     
  Partials           5        5              

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

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/sites/sites-react/doc/components/demoblock/demoblock.scss (2)

51-59: 关于滚动条样式的兼容性建议

当前滚动条样式仅使用了 -webkit- 前缀,这只能在基于 WebKit 和 Blink 的浏览器(如 Chrome、Safari、Edge 等)中生效。为了提升跨浏览器兼容性,建议同时添加 Firefox 和标准滚动条样式支持。

.demo-block code {
  max-height: 580px;
  overflow-y: auto;
  &::-webkit-scrollbar {
    width: 6px;
    height: 6px;
    background: transparent;
  }
  &::-webkit-scrollbar-thumb {
    background: #ccc;
    border-radius: 4px;
  }
+  /* Firefox 滚动条样式 */
+  scrollbar-width: thin;
+  scrollbar-color: #ccc transparent;
}

48-50: 考虑添加水平滚动处理

当前样式只处理了垂直方向的滚动,但代码块中可能有超宽内容需要水平滚动。建议考虑为水平方向添加类似的处理,确保长行代码也能得到良好显示。

.demo-block code {
  max-height: 580px;
  overflow-y: auto;
+  overflow-x: auto;
+  white-space: pre;
  ...
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 2a74f0f and 5ee32f2.

📒 Files selected for processing (2)
  • src/sites/sites-react/doc/components/demoblock/demoblock.scss (1 hunks)
  • src/sites/sites-react/doc/components/demoblock/demoblock.tsx (1 hunks)
🔇 Additional comments (2)
src/sites/sites-react/doc/components/demoblock/demoblock.tsx (1)

38-38: 将 props.children 包装在带有类名的 div 中是一个很好的改进

props.children 包装在带有 demo-block 类名的 div 中,为代码块提供了一个可样式化的容器。这个修改与 SCSS 文件中的样式变更相匹配,使得可以对代码块应用滚动行为和自定义样式。

这种结构性的改变有利于统一管理内容区域的布局和行为,符合组件化设计的最佳实践。

src/sites/sites-react/doc/components/demoblock/demoblock.scss (1)

48-60: 代码块滚动行为优化得当

这段 CSS 规则为 .demo-block code 元素添加了:

  1. 最大高度限制,避免代码块占用过多屏幕空间
  2. 垂直滚动条,方便查看长代码
  3. 自定义滚动条样式,提升用户体验

这些样式变更完美地配合 TSX 文件中结构的改变,共同优化了代码块的展示和交互体验。滚动条宽度适中,圆角设计也符合现代 UI 审美需求。

@Miles-hxy
Miles-hxy requested a review from oasis-cloud March 20, 2025 08:36
@oasis-cloud

Copy link
Copy Markdown
Collaborator

在线调试接入的不对,看 2.0 的在线调试接入,或者扩展个别的接入

@xiaoyatong

Copy link
Copy Markdown
Collaborator

1、复制代码后的提示太重了,可以简化为 一个 toast,或者 直接在 复制代码 的icon部分 增加 一个 ✅
2、跳转调试,不对~

@pull-request-size pull-request-size Bot added size/L and removed size/S labels Mar 24, 2025

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (2)
src/sites/sites-react/doc/components/demoblock/demoblock.tsx (1)

54-59: 可以改进复制代码的用户反馈

目前使用alert('复制成功')提示用户复制成功,这种方式可能会中断用户的操作流程。

建议将alert提示改为更现代的Toast通知或直接在复制图标上显示一个✅标记,以提供更好的用户体验:

- alert('复制成功')
+ // 使用Toast组件或其他非阻塞提示
+ // 例如:Toast.success('复制成功')
src/sites/sites-react/doc/components/demoblock/codesandbox/package.json (1)

1-27: CodeSandbox配置文件需要更新标题

这个配置文件为CodeSandbox在线调试功能提供了必要的依赖和配置,但是有一个细节需要注意:

文件中的title属性"语法糖 - antd@5.24.4"提到了antd,但实际上项目使用的是NutUI组件库。建议更新为更准确的描述:

- "title": "语法糖 - antd@5.24.4"
+ "title": "语法糖 - NutUI React"

根据PR评论,可能需要检查这个配置是否与版本2.0对齐。请确认当前的依赖版本是否与项目的目标版本一致。

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between bb7ce30 and 92cefa9.

📒 Files selected for processing (3)
  • src/sites/sites-react/doc/components/demoblock/codesandbox/index.html (1 hunks)
  • src/sites/sites-react/doc/components/demoblock/codesandbox/package.json (1 hunks)
  • src/sites/sites-react/doc/components/demoblock/demoblock.tsx (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • src/sites/sites-react/doc/components/demoblock/codesandbox/index.html
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (4)
src/sites/sites-react/doc/components/demoblock/demoblock.tsx (4)

2-7: 导入依赖的改动符合功能需求

引入了CodeSandbox相关的API和资源文件,删除了不再使用的compressText导入,这些变更与代码块在线调试功能的优化相符。


16-24: 升级了React 18渲染方式

将旧版的ReactDOM.render替换为React 18推荐的createRoot方法,符合React的最新实践。


25-52: 优化了在线调试的实现方式

使用getParameters方法构建了更完善的CodeSandbox参数结构,包含了完整的项目文件结构,这比之前的实现更加健壮。

确认一下在线调试功能是否正常工作?基于PR评论中的反馈,可能存在"跳转调试功能有问题"的情况。


62-62: 优化了组件结构

将children包裹在带有"demo-block"类名的div中,这样可以更好地应用样式,特别是滚动行为的样式。

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/sites/sites-react/doc/components/demoblock/demoblock.tsx (1)

57-60: 复制成功反馈优化

使用状态变量和定时器来显示复制成功反馈是一个好的用户体验改进。不过,根据 PR 评论,可以考虑进一步简化这个交互:

  1. 可以考虑使用 toast 提示替代文字变化
  2. 或者在复制图标上直接添加一个对勾标记 (✓) 来表示复制成功
- setCopyText('复制成功')
- setTimeout(() => {
-   setCopyText('复制代码')
- }, 2000)
+ // 使用 Toast 组件(假设已有)
+ Toast.show('复制成功')
+ // 或者更新图标状态
+ setIconState('success')
+ setTimeout(() => {
+   setIconState('default')
+ }, 1500)
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 92cefa9 and 1ee7002.

📒 Files selected for processing (1)
  • src/sites/sites-react/doc/components/demoblock/demoblock.tsx (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (6)
src/sites/sites-react/doc/components/demoblock/demoblock.tsx (6)

2-7: 导入依赖优化

将不再使用的 compressText 移除,并添加了 CodeSandbox 相关的依赖导入。使用 ?raw 导入静态文件是一个好的做法,可以让这些资源在构建时直接被内联到代码中。


15-15: 使用状态管理复制反馈提示

使用 copyText 状态来管理复制按钮文本是一个好的改进,比之前使用的 alert 提示更为友好。


17-25: 升级到 React 18 渲染方式

ReactDOM.render 升级到 React 18 的 createRoot API 是一个好的做法,符合 React 最新的推荐用法。


27-52: CodeSandbox 集成优化

使用 getParameters 函数构建包含多个文件的沙箱是一个不错的改进,这样可以提供更完整的在线调试环境。然而,有以下几点需要注意:

  1. 建议检查 CodeSandbox 集成是否与 NutUI React 2.0 版本兼容(根据 PR 评论反馈)
  2. 在线调试功能可能存在问题,需要进一步验证

请确认在线调试功能是否正常工作,特别是与 NutUI React 2.0 版本的兼容性。


65-65: 组件结构优化

props.children 包装在带有 demo-block 类名的 div 中,可以更好地控制样式和滚动行为。这与 PR 标题 "优化代码块滚动行为" 相符。


82-82: 动态复制按钮文本

使用状态变量动态更新复制按钮文本是一个很好的改进。不过,如上面建议的,可以考虑使用更简洁的反馈方式。

@Miles-hxy Miles-hxy changed the title fix(demoblock): optimize code block scrolling behavior feat(demoblock): code block scrolling behavior, CodesandBox function and copyCode styles Mar 24, 2025
@Miles-hxy
Miles-hxy requested a review from xiaoyatong March 24, 2025 08:08
@xiaoyatong
xiaoyatong merged commit e7349fc into jdf2e:feat_v3.x Mar 25, 2025
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