Skip to content

Commit

Permalink
feat:Highlight & Markdown 切换为 ProEditor (#12)
Browse files Browse the repository at this point in the history
* ✨ feat: change Highlight & Markdown into ProEditor

* ✨ feat: delete lobeui

* 💚 fix: ci fixed

---------

Co-authored-by: ONLY-yours <[email protected]>
  • Loading branch information
ONLY-yours and ONLY-yours authored Nov 22, 2023
1 parent e733305 commit f742db3
Show file tree
Hide file tree
Showing 27 changed files with 149 additions and 3,055 deletions.
Binary file modified bun.lockb
Binary file not shown.
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,6 @@
"react-error-boundary": "^4",
"react-intersection-observer": "^9.5.2",
"react-layout-kit": "^1.7.1",
"react-markdown": "^8",
"rehype-katex": "^6",
"remark-gfm": "^3",
"remark-math": "^5",
"shikiji": "^0",
"swr": "^2",
"use-merge-value": "^1",
Expand All @@ -88,7 +84,6 @@
},
"devDependencies": {
"@commitlint/cli": "^17",
"@lobehub/ui": "^1",
"@testing-library/react": "^14",
"@types/chroma-js": "^2",
"@types/lodash-es": "^4",
Expand Down
2 changes: 1 addition & 1 deletion src/ActionIconGroup/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ const ActionIconGroup = memo<ActionIconGroupProps>(
items = [],
placement,
spotlight = false,
direction = 'column',
direction = 'row',
dropdownMenu = [],
onActionClick,
className,
Expand Down
79 changes: 36 additions & 43 deletions src/ChatItem/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,55 +1,48 @@
import { ActionIconGroup, ChatItem, ChatItemProps } from '@ant-design/pro-chat';
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { useState } from 'react';

import { avatar, dropdownMenu, items } from './data';

export default () => {
const [edit, setEdit] = useState(false);
const store = useCreateStore();
const control: ChatItemProps | any = useControls(
{
loading: false,
message: {
rows: true,
value:
"要使用 dayjs 的 fromNow 函数,需要先安装 dayjs 库并在代码中引入它。然后,可以使用以下语法来获取当前时间与给定时间之间的相对时间:\n\n```javascript\ndayjs().fromNow();\ndayjs('2021-05-01').fromNow();\n```",
},
placement: {
options: ['left', 'right'],
value: 'left',
},
primary: false,
showTitle: false,
time: 1_686_538_950_084,
type: {
options: ['block', 'pure'],
value: 'block',
},
const control: ChatItemProps | any = {
loading: false,
message: {
rows: true,
value:
"要使用 dayjs 的 fromNow 函数,需要先安装 dayjs 库并在代码中引入它。然后,可以使用以下语法来获取当前时间与给定时间之间的相对时间:\n\n```javascript\ndayjs().fromNow();\ndayjs('2021-05-01').fromNow();\n```",
},
{ store },
);
placement: {
options: ['left', 'right'],
value: 'left',
},
primary: false,
showTitle: false,
time: 1_686_538_950_084,
type: {
options: ['block', 'pure'],
value: 'block',
},
};

return (
<StoryBook levaStore={store}>
<ChatItem
{...control}
actions={
<ActionIconGroup
dropdownMenu={dropdownMenu}
items={items}
onActionClick={(action) => {
if (action.key === 'edit') {
setEdit(true);
}
}}
type="ghost"
/>
}
avatar={avatar}
editing={edit}
onEditingChange={setEdit}
/>
</StoryBook>
<ChatItem
{...control}
actions={
<ActionIconGroup
dropdownMenu={dropdownMenu}
items={items}
onActionClick={(action) => {
if (action.key === 'edit') {
setEdit(true);
}
}}
type="ghost"
/>
}
avatar={avatar}
editing={edit}
onEditingChange={setEdit}
/>
);
};
120 changes: 95 additions & 25 deletions src/EditableMessage/demos/index.tsx
Original file line number Diff line number Diff line change
@@ -1,36 +1,106 @@
import { EditableMessage } from '@ant-design/pro-chat';
import { StoryBook, useControls, useCreateStore } from '@lobehub/ui';
import { button } from 'leva';
import { useState } from 'react';

import { content } from '../../Markdown/demos/data';
export const content = `# This is an H1
## This is an H2
### This is an H3
#### This is an H4
##### This is an H5
The point of reference-style links is not that they’re easier to write. The point is that with reference-style links, your document source is vastly more readable. Compare the above examples: using reference-style links, the paragraph itself is only 81 characters long; with inline-style links, it’s 176 characters; and as raw \`HTML\`, it’s 234 characters. In the raw \`HTML\`, there’s more markup than there is text.
---
> This is a blockquote with two paragraphs. Lorem ipsum dolor sit amet,
> consectetuer adipiscing elit. Aliquam hendrerit mi posuere lectus.
> Vestibulum enim wisi, viverra nec, fringilla in, laoreet vitae, risus.
>
> Donec sit amet nisl. Aliquam semper ipsum sit amet velit. Suspendisse
> id sem consectetuer libero luctus adipiscing.
---
an example | *an example* | **an example**
---
1. Bird
1. McHale
1. Parish
1. Bird
1. McHale
1. Parish
---
- Red
- Green
- Blue
- Red
- Green
- Blue
---
This is [an example](http://example.com/ "Title") inline link.
<http://example.com/>
| title | title | title |
| --- | --- | --- |
| content | content | content |
\`\`\`bash
$ pnpm install
\`\`\`
\`\`\`javascript
import { renderHook } from '@testing-library/react-hooks';
import { act } from 'react-dom/test-utils';
import { useDropNodeOnCanvas } from './useDropNodeOnCanvas';
\`\`\`
---
以下是一段Markdown格式的LaTeX数学公式:
我是一个行内公式:$E=mc^2$
我是一个独立公式:
$$
\\sum_{i=1}^{n} x_i = x_1 + x_2 + \\ldots + x_n
$$
我是一个带有分式的公式:
$$
\\frac{{n!}}{{k!(n-k)!}} = \\binom{n}{k}
$$
我是一个带有上下标的公式:
$$
x^{2} + y^{2} = r^{2}
$$
我是一个带有积分符号的公式:
$$
\\int_{a}^{b} f(x) \\, dx
$$
`;

export default () => {
const [openModal, setOpenModal] = useState(false);
const [editing, setEdit] = useState(false);
const store = useCreateStore();

useControls(
{
editing: button(() => {
setEdit(true);
}),
openModal: button(() => {
setOpenModal(true);
}),
},
{ store },
);

return (
<StoryBook levaStore={store}>
<EditableMessage
editing={editing}
onEditingChange={setEdit}
onOpenChange={setOpenModal}
openModal={openModal}
value={content}
/>
</StoryBook>
<EditableMessage
editing={editing}
onEditingChange={setEdit}
onOpenChange={setOpenModal}
openModal={openModal}
value={content}
/>
);
};
6 changes: 4 additions & 2 deletions src/EditableMessage/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import { CSSProperties, memo } from 'react';
import useControlledState from 'use-merge-value';

import Markdown from '@/Markdown';
import MessageInput, { type MessageInputProps } from '@/MessageInput';
import MessageModal, { type MessageModalProps } from '@/MessageModal';
import { Markdown } from '@ant-design/pro-editor';

export interface EditableMessageProps {
/**
Expand Down Expand Up @@ -136,7 +136,9 @@ const EditableMessage = memo<EditableMessageProps>(
) : (
<Markdown
className={classNames?.markdown}
fullFeaturedCodeBlock={fullFeaturedCodeBlock}
highlight={{
containerWrapper: fullFeaturedCodeBlock,
}}
style={{
height: isAutoSize ? 'unset' : height,
overflowX: 'hidden',
Expand Down
77 changes: 0 additions & 77 deletions src/Highlighter/FullFeatured.tsx

This file was deleted.

Loading

6 comments on commit f742db3

@jiabochao
Copy link
Contributor

Choose a reason for hiding this comment

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

ProEditor在不断地流式输出Markdown代码块时,界面所有的代码块都会出现闪动,输出大段的代码块时会导致直接无法显示代码内容,感觉像是频繁渲染代码高亮导致的,有解决方法吗

@arvinxx
Copy link
Collaborator

Choose a reason for hiding this comment

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

@ONLY-yours 排查下?

@ONLY-yours
Copy link
Collaborator Author

@ONLY-yours ONLY-yours commented on f742db3 Dec 18, 2023

Choose a reason for hiding this comment

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

是的,主要就是代码块的问题,疯狂在触发 Siki 的重新计算,得仔细看看了

@ONLY-yours
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

感觉是 memo 挂掉了 - -

@ONLY-yours
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

ProEditor在不断地流式输出Markdown代码块时,界面所有的代码块都会出现闪动,输出大段的代码块时会导致直接无法显示代码内容,感觉像是频繁渲染代码高亮导致的,有解决方法吗

修了一版本,感觉应该可以了,我在 Editor 模拟了下应该ok了 ant-design/pro-editor#122 @arvinxx

@jiabochao
Copy link
Contributor

Choose a reason for hiding this comment

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

确认已修复

Please sign in to comment.