Skip to content

Commit

Permalink
fix: table readonly state
Browse files Browse the repository at this point in the history
  • Loading branch information
WindRunnerMax committed Jun 11, 2024
1 parent 2b09b9e commit cc1f33f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
14 changes: 8 additions & 6 deletions packages/plugin/src/table/components/cell.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import type { BlockContext, EditorSuite } from "doc-editor-core";
import { Transforms } from "doc-editor-delta";
import { findNodePath, getNodeTupleByDepth } from "doc-editor-utils";
import { EVENT_ENUM, findNodePath, getNodeTupleByDepth } from "doc-editor-utils";
import throttle from "lodash-es/throttle";
import type { FC } from "react";

Expand Down Expand Up @@ -47,18 +47,20 @@ export const Cell: FC<{
}, 16);
const onMouseUp = () => {
document.body.style.cursor = "";
document.removeEventListener("mousemove", onMouseMove);
document.removeEventListener("mouseup", onMouseUp);
document.removeEventListener(EVENT_ENUM.MOUSE_MOVE, onMouseMove);
document.removeEventListener(EVENT_ENUM.MOUSE_UP, onMouseUp);
};
document.addEventListener("mousemove", onMouseMove);
document.addEventListener("mouseup", onMouseUp);
document.addEventListener(EVENT_ENUM.MOUSE_MOVE, onMouseMove);
document.addEventListener(EVENT_ENUM.MOUSE_UP, onMouseUp);
};

return (
<td className="table-block-cell" {...context.props.attributes}>
{/* COMPAT: 必须要从父层传递 否则会无限`ReRender` */}
{props.children}
<div contentEditable={false} onMouseDown={onMouseDown} className="table-cell-resize"></div>
{!props.readonly && (
<div contentEditable={false} onMouseDown={onMouseDown} className="table-cell-resize"></div>
)}
</td>
);
};
1 change: 1 addition & 0 deletions packages/utils/src/constant.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ export const KEYBOARD = {

export const EVENT_ENUM = {
MOUSE_UP: "mouseup",
MOUSE_MOVE: "mousemove",
MOUSE_DOWN: "mousedown",
SELECTION_CHANGE: "selectionchange",
} as const;
Expand Down

0 comments on commit cc1f33f

Please sign in to comment.