Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: 添加 md-editor 自定义渲染示例和文档 #466

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

chenshuai2144
Copy link

@chenshuai2144 chenshuai2144 commented Jan 12, 2025

Summary by CodeRabbit

  • 新功能

    • 在聊天气泡组件中添加了 Markdown 编辑器渲染功能
    • 支持在文档中展示自定义渲染的 Markdown 内容
  • 依赖变更

    • 新增 @ant-design/md-editor 开发依赖
    • 移除 react-intl 依赖
  • 文档更新

    • 为中英文文档添加了 Markdown 编辑器渲染示例

Copy link
Contributor

coderabbitai bot commented Jan 12, 2025

📝 Walkthrough

概述

演练

此次更改主要引入了一个新的 Markdown 编辑器演示,使用 Ant Design 的 Bubble 组件和 @ant-design/md-editor 库。新增了中英文文档示例,并在 stream_markdown.tsx 中创建了一个可以在聊天气泡中渲染 Markdown 内容的 React 组件。同时,在 package.json 中添加了 @ant-design/md-editor 依赖,并移除了 react-intl

变更

文件 变更概要
components/bubble/demo/stream_markdown.md 新增中英文语言描述
components/bubble/demo/stream_markdown.tsx 新增 RenderMarkdownApp 组件
components/bubble/index.en-US.md 添加新的代码示例链接
components/bubble/index.zh-CN.md 添加新的代码示例链接
package.json 添加 @ant-design/md-editor,移除 react-intl

序列图

sequenceDiagram
    participant User
    participant Bubble
    participant RenderMarkdown
    participant MarkdownEditor
    
    User->>Bubble: 触发渲染
    Bubble->>RenderMarkdown: 传入 Markdown 内容
    RenderMarkdown->>MarkdownEditor: 解析并渲染内容
    MarkdownEditor-->>RenderMarkdown: 返回渲染结果
    RenderMarkdown-->>Bubble: 显示渲染内容
Loading

可能相关的 PR

建议的审阅者

  • afc163

诗歌

🐰 代码如流水,Markdown 轻舞
气泡中跳跃,文字绽光华
编辑器闪耀,创意无限啊!
兔子微笑,技术飞翔!


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.

Copy link

github-actions bot commented Jan 12, 2025

Preview failed

Copy link

Walkthrough: This pull request introduces a new demo for rendering markdown content using @ant-design/md-editor within the Bubble component. It includes both English and Chinese documentation updates and adds the necessary dependencies to the project.

Changes:

Files Summary
components/bubble/demo/stream_markdown.md, components/bubble/demo/stream_markdown.tsx Added a new markdown rendering demo using @ant-design/md-editor.
components/bubble/index.en-US.md, components/bubble/index.zh-CN.md Updated documentation to include the new markdown rendering demo.
package.json Added @ant-design/md-editor as a dev dependency and adjusted react-intl dependency position.

@chenshuai2144 chenshuai2144 changed the title docsNew render demo docs: 添加 md-editor 自定义渲染示例和文档 Jan 12, 2025
Copy link

codecov bot commented Jan 12, 2025

Bundle Report

Bundle size has no change ✅

Copy link

socket-security bot commented Jan 12, 2025

Copy link

github-actions bot commented Jan 12, 2025

size-limit report 📦

Path Size
dist/antdx.min.js 40.29 KB

Copy link
Contributor

@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

🧹 Nitpick comments (3)
components/bubble/demo/stream_markdown.tsx (2)

7-263: 建议将示例文本内容移至单独的文件中

当前的示例文本内容较长,建议将其提取到单独的 .md 文件中,以提高代码的可维护性和可读性。

-const text = `## 创始人...`.trim();
+import demoText from './demo-content.md';
+const text = demoText.trim();

289-304: 建议使用主题变量或设计令牌来设置间距

为了保持样式的一致性和可维护性,建议使用主题变量或设计令牌来设置间距,而不是硬编码的数值。

-    <div style={{ minHeight: 100, margin: 24 }}>
+    <div style={{ minHeight: 100, margin: token.marginLG }}>
package.json (1)

100-100: 建议锁定依赖版本

为了确保构建的稳定性,建议使用固定版本而不是 caret range。

-    "@ant-design/md-editor": "^1.12.31",
+    "@ant-design/md-editor": "1.12.31",
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 209ec6f and 26ecf2b.

📒 Files selected for processing (5)
  • components/bubble/demo/stream_markdown.md (1 hunks)
  • components/bubble/demo/stream_markdown.tsx (1 hunks)
  • components/bubble/index.en-US.md (1 hunks)
  • components/bubble/index.zh-CN.md (1 hunks)
  • package.json (3 hunks)
✅ Files skipped from review due to trivial changes (1)
  • components/bubble/demo/stream_markdown.md
⏰ Context from checks skipped due to timeout of 90000ms (7)
  • GitHub Check: Socket Security: Pull Request Alerts
  • GitHub Check: test / react component workflow
  • GitHub Check: build preview
  • GitHub Check: size
  • GitHub Check: Analyze (javascript-typescript)
  • GitHub Check: test / react component workflow
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (4)
components/bubble/demo/stream_markdown.tsx (1)

285-287: 实现正确且简洁

renderMarkdown 函数的实现符合 React 最佳实践。

components/bubble/index.zh-CN.md (1)

29-29: 文档更新准确且完整

新增的示例文档条目清晰地展示了 md-editor 的用法。

components/bubble/index.en-US.md (1)

28-28: 文档同步更新正确

英文文档的更新与中文文档保持一致,维护了良好的多语言支持。

package.json (1)

237-237: 请确认移除 react-intl 的影响

移除 react-intl 依赖可能会影响项目中的国际化功能,请确认:

  1. 是否有其他组件仍在使用 react-intl
  2. 是否已经迁移到其他国际化解决方案

components/bubble/demo/stream_markdown.tsx Outdated Show resolved Hide resolved
Copy link

cloudflare-workers-and-pages bot commented Jan 12, 2025

Deploying ant-design-x with  Cloudflare Pages  Cloudflare Pages

Latest commit: b74aa85
Status:🚫  Build failed.

View logs

Copy link
Contributor

@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: 2

🧹 Nitpick comments (2)
components/bubble/demo/stream_markdown.tsx (2)

290-290: 建议将样式值提取为常量

建议将固定的样式值提取为命名常量,以提高代码的可维护性。

+ const CONTAINER_STYLES = {
+   minHeight: 100,
+   margin: 24,
+ };

- <div style={{ minHeight: 100, margin: 24 }}>
+ <div style={CONTAINER_STYLES}>
🧰 Tools
🪛 GitHub Actions: ✅ test

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.


292-295: 建议调整打字动画的速度

当前的打字速度(每50ms打印10个字符)可能过快,不利于用户阅读。建议降低速度以提供更好的阅读体验。

        typing={{
-         step: 10,
-         interval: 50,
+         step: 5,
+         interval: 100,
        }}
🧰 Tools
🪛 GitHub Actions: ✅ test

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 26ecf2b and b74aa85.

⛔ Files ignored due to path filters (7)
  • components/attachments/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • components/attachments/__tests__/__snapshots__/demo.test.tsx.snap is excluded by !**/*.snap
  • components/bubble/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • components/bubble/__tests__/__snapshots__/demo.test.ts.snap is excluded by !**/*.snap
  • components/sender/__tests__/__snapshots__/index.test.tsx.snap is excluded by !**/*.snap
  • components/thought-chain/__tests__/__snapshots__/demo-extend.test.ts.snap is excluded by !**/*.snap
  • components/thought-chain/__tests__/__snapshots__/demo.test.ts.snap is excluded by !**/*.snap
📒 Files selected for processing (1)
  • components/bubble/demo/stream_markdown.tsx (1 hunks)
🧰 Additional context used
🪛 GitHub Actions: ✅ test
components/bubble/demo/stream_markdown.tsx

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.

⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: Cloudflare Pages
🔇 Additional comments (3)
components/bubble/demo/stream_markdown.tsx (3)

271-280: 需要优化 MarkdownEditor 的宽度设置

使用 80vw 作为固定宽度可能会在不同设备上造成布局问题,建议使用更灵活的布局方案。

-      width={'80vw'}
+      width={'100%'}
🧰 Tools
🪛 GitHub Actions: ✅ test

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.


284-286: 代码实现简洁清晰

函数实现遵循了函数式编程的原则,代码结构清晰。

🧰 Tools
🪛 GitHub Actions: ✅ test

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.


305-305: 导出实现正确

默认导出的实现符合最佳实践。

🧰 Tools
🪛 GitHub Actions: ✅ test

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.

Comment on lines +7 to +263
"rules": [{ "required": true, "message": "此项为必填项" }]
},
"width": "md"
},
{
"title": "状态",
"dataIndex": "state",
"valueType": "select",
"width": "md"
},
{ "title": "标签", "dataIndex": "labels", "width": "md" },
{
"valueType": "switch",
"title": "开关",
"dataIndex": "Switch",
"fieldProps": { "style": { "width": "200px" } },
"width": "md"
},
{
"title": "创建时间",
"key": "showTime",
"dataIndex": "createName",
"width": "md"
},
{ "title": "更新时间", "dataIndex": "updateName" },
{
"title": "分组",
"valueType": "group",
"columns": [
{
"title": "状态",
"dataIndex": "groupState",
"valueType": "select",
"width": "xs",
"colProps": { "xs": 12 }
},
{
"title": "标题",
"width": "md",
"dataIndex": "groupTitle",
"colProps": { "xs": 12 },
"formItemProps": {
"rules": [{ "required": true, "message": "此项为必填项" }]
}
}
]
},
{
"title": "列表",
"valueType": "formList",
"dataIndex": "list",
"columns": [
{
"valueType": "group",
"columns": [
{
"title": "状态",
"dataIndex": "state",
"valueType": "select",
"colProps": { "xs": 24, "sm": 12 },
"width": "xs"
},
{
"title": "标题",
"dataIndex": "title",
"width": "md",
"formItemProps": {
"rules": [{ "required": true, "message": "此项为必填项" }]
},
"colProps": { "xs": 24, "sm": 12 }
}
]
},
{ "valueType": "dateTime", "dataIndex": "currentTime", "width": "md" }
]
},
{
"title": "创建时间",
"dataIndex": "created_at",
"valueType": "dateRange",
"width": "md"
}
]
\`\`\`


## 代码

\`\`\`java
Class A {
main() {
System.out.println("Hello World");
}
}
\`\`\`

## 删除线
~~腾讯六大事业群腾讯六大事业群腾讯六大事业群~~

`.trim();
Copy link
Contributor

Choose a reason for hiding this comment

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

🛠️ Refactor suggestion

建议使用示例数据替换敏感业务数据

当前示例中包含了大量真实的业务数据(如财务数据、人员信息等)。建议使用虚构的示例数据来展示功能。

🧰 Tools
🪛 GitHub Actions: ✅ test

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.

Comment on lines +1 to +2
import { UserOutlined } from '@ant-design/icons';
import { MarkdownEditor, MarkdownEditorInstance, parserMdToSchema } from '@ant-design/md-editor';
Copy link
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

缺少必要的依赖项

需要在项目的 package.json 中添加 @ant-design/md-editor 依赖。

// package.json
{
  "dependencies": {
+   "@ant-design/md-editor": "^1.12.31"
  }
}

Committable suggestion skipped: line range outside the PR's diff.

🧰 Tools
🪛 GitHub Actions: ✅ test

[error] Cannot find module '@ant-design/md-editor'. Missing dependency in the project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant