Skip to content

Commit

Permalink
简化表格组件中的上下文菜单处理逻辑,移除不必要的回调函数
Browse files Browse the repository at this point in the history
  • Loading branch information
chenshuai2144 committed Dec 20, 2024
1 parent 5951706 commit 0fb2238
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 17 deletions.
9 changes: 1 addition & 8 deletions src/MarkdownEditor/editor/elements/column/index.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
import { ConfigProvider } from 'antd';
import classNames from 'classnames';
import React, { useCallback, useContext, useMemo } from 'react';
import React, { useContext, useMemo } from 'react';
import { RenderElementProps } from 'slate-react/dist/components/editable';
import { useEditorStore } from '../../store';
import { DragHandle } from '../../tools/DragHandle';
import { useStyle } from './style';

export function ColumnCell(props: RenderElementProps) {
const { store } = useEditorStore();
const contextFn = useCallback((e: React.MouseEvent, head?: boolean) => {
store.openTableMenus(e, head);
}, []);
const context = useContext(ConfigProvider.ConfigContext);
const baseCls = context.getPrefixCls('md-editor-column-group-cell');
return React.useMemo(() => {
Expand All @@ -19,9 +15,6 @@ export function ColumnCell(props: RenderElementProps) {
{...props.attributes}
data-be={'column-group-cell'}
className={baseCls}
onContextMenu={(e) => {
contextFn(e);
}}
>
{props.children}
</div>
Expand Down
7 changes: 0 additions & 7 deletions src/MarkdownEditor/editor/elements/table.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ export function TableCell(props: RenderElementProps) {
const { store, readonly } = useEditorStore();
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_] = useSelStatus(props.element);
const context = useCallback((e: React.MouseEvent, head?: boolean) => {
store.openTableMenus(e, head);
}, []);

return React.useMemo(() => {
const domWidth = stringWidth(Node.string(props.element)) * 8 + 20;
Expand All @@ -58,7 +55,6 @@ export function TableCell(props: RenderElementProps) {
{...props.attributes}
style={{ textAlign: props.element.align }}
data-be={'th'}
onContextMenu={(e) => context(e, true)}
>
<div
style={{
Expand All @@ -76,9 +72,6 @@ export function TableCell(props: RenderElementProps) {
style={{ textAlign: props.element.align }}
data-be={'td'}
className={classNames('group')}
onContextMenu={(e) => {
context(e);
}}
>
{readonly && domWidth > 200 ? (
<Popover
Expand Down
4 changes: 2 additions & 2 deletions src/MarkdownEditor/editor/tools/Leading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -127,9 +127,9 @@ export const TocHeading = observer(({ note }: { note: IEditor }) => {
cache.clear();
getHeading();
setState({ active: '' });
}, [note]);
}, [store?.container, note]);

useDebounce(getHeading, 100, [note, note?.refresh]);
useDebounce(getHeading, 100, [note]);

useEffect(() => {
const div = box.current;
Expand Down

1 comment on commit 0fb2238

@vercel
Copy link

@vercel vercel bot commented on 0fb2238 Dec 20, 2024

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.