Skip to content

Commit

Permalink
feat: 添加对lodash-es的支持,优化Markdown编辑器的性能和样式
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Feb 18, 2025
1 parent 6237293 commit 26b0b01
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 47 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
"katex": "^0.16.21",
"kd-tree-javascript": "^1.0.3",
"lodash": "^4.17.21",
"lodash-es": "^4.17.21",
"mermaid": "^11.4.1",
"mobx": "^6.13.6",
"mobx-react": "^9.2.0",
Expand Down Expand Up @@ -92,6 +93,7 @@
"@types/jsdom": "^21.1.7",
"@types/kd-tree-javascript": "^1.0.3",
"@types/lodash": "^4.17.15",
"@types/lodash-es": "^4.17.12",
"@types/mdast": "^4.0.4",
"@types/react": "^18.3.18",
"@types/react-dom": "^18.3.5",
Expand Down
13 changes: 13 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

43 changes: 0 additions & 43 deletions src/MarkdownEditor/demos/minPreview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -39,49 +39,6 @@ export default () => {
overflow: 'auto',
}}
>
<MarkdownEditor
toc={false}
toolBar={{
enable: true,
hideTools: ['code', 'inline-code'],
extra: [
<Button key="save" type="primary" size="small">
Save
</Button>,
],
}}
comment={{
enable: true,
}}
readonly
reportMode
image={{
upload: async (fileList) => {
return new Promise((resolve) => {
const file = fileList[0];
if (typeof file === 'string') {
fetch(file)
.then((res) => res.blob())
.then((blob) => {
console.log(blob);
const url = URL.createObjectURL(blob);
resolve(url);
});
} else {
const url = URL.createObjectURL(file);
resolve(url);
}
});
},
}}
style={{
width: '80%',
margin: '0 auto',
border: '1px solid #e8e8e8',
height: 'calc(100vh - 400px)',
}}
initValue={defaultValue}
/>
<MarkdownEditor
toc={false}
toolBar={{
Expand Down
1 change: 1 addition & 0 deletions src/MarkdownEditor/editor/Editor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -675,6 +675,7 @@ export const MEditor = observer(
});
}
}, 160);
console.log(readonly);
return wrapSSR(
<Slate
editor={markdownEditorRef.current}
Expand Down
3 changes: 3 additions & 0 deletions src/MarkdownEditor/editor/plugins/withMarkdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ export const withMarkdown = (editor: Editor) => {
};

editor.apply = (operation) => {
if (operation.type === 'set_selection' && operation.newProperties) {
console.log('set_selection', operation);
}
if (
operation.type === 'merge_node' &&
operation.properties?.type === 'table-cell'
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
/* eslint-disable @typescript-eslint/no-use-before-define */
import getDirection from 'direction';
import { debounce, throttle } from 'lodash-es';
import React, {
ForwardedRef,
forwardRef,
Expand Down Expand Up @@ -61,7 +62,6 @@ import {
PLACEHOLDER_SYMBOL,
TRIPLE_CLICK,
} from 'slate-dom';
import { debounce, throttle } from '../../utils';
import { AndroidInputManager } from '../hooks/android-input-manager/android-input-manager';
import { useAndroidInputManager } from '../hooks/android-input-manager/use-android-input-manager';
import useChildren from '../hooks/use-children';
Expand Down
4 changes: 2 additions & 2 deletions src/MarkdownEditor/editor/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,9 @@ const genStyle: GenerateStyle<ChatTokenType> = (token) => {
paddingTop: '.25em',
paddingBottom: '.25em',
fontSize: '1em',
lineHeight: '1.5em',
lineHeight: '1em',
marginTop: '0',
marginBottom: '0.8em',
marginBottom: '0.5em',
},
'h1,h2,h3,h4,h5,h6': {
position: 'relative',
Expand Down
1 change: 0 additions & 1 deletion src/MarkdownEditor/editor/utils/keyboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,6 @@ export class KeyboardTask {
}

list(mode: 'ordered' | 'unordered' | 'task') {
console.log('run list');
const [node] = this.curNodes;
if (node && ['paragraph'].includes(node[0].type)) {
const parent = Editor.parent(this.editor, node[1]);
Expand Down

1 comment on commit 26b0b01

@vercel
Copy link

@vercel vercel bot commented on 26b0b01 Feb 18, 2025

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.