-
+
{children}
diff --git a/packages/resizable/src/components/ResizeHandle.tsx b/packages/resizable/src/components/ResizeHandle.tsx
index c55e95edc3..a2ea985db9 100644
--- a/packages/resizable/src/components/ResizeHandle.tsx
+++ b/packages/resizable/src/components/ResizeHandle.tsx
@@ -14,9 +14,7 @@ import { ResizeDirection, ResizeEvent } from '../types';
import { isTouchEvent } from '../utils';
export type ResizeHandleStoreState = {
- onResize: {
- fn: (event: ResizeEvent) => void;
- };
+ onResize: (event: ResizeEvent) => void;
};
const initialState: Nullable
= {
@@ -48,7 +46,7 @@ export const useResizeHandleState = ({
onHoverEnd,
}: ResizeHandleOptions) => {
const onResizeStore = useResizeHandleStore().get.onResize();
- const onResize = onResizeProp ?? onResizeStore.fn;
+ const onResize = onResizeProp ?? onResizeStore;
const [isResizing, setIsResizing] = useState(false);
const [initialPosition, setInitialPosition] = useState(0);
diff --git a/packages/tabbable/src/TabbableEffects.tsx b/packages/tabbable/src/TabbableEffects.tsx
index 262910ddc6..67b3346e67 100644
--- a/packages/tabbable/src/TabbableEffects.tsx
+++ b/packages/tabbable/src/TabbableEffects.tsx
@@ -6,7 +6,7 @@ import {
toDOMNode,
toSlateNode,
useEditorReadOnly,
- useEditorState,
+ useEditorRef,
} from '@udecode/plate-common';
import { Path } from 'slate';
import { tabbable } from 'tabbable';
@@ -16,14 +16,15 @@ import { findTabDestination } from './findTabDestination';
import { TabbableEntry, TabbablePlugin } from './types';
export function TabbableEffects() {
- const editor = useEditorState();
+ const editor = useEditorRef();
const readOnly = useEditorReadOnly();
- const { query, globalEventListener, insertTabbableEntries, isTabbable } =
- getPluginOptions(editor, KEY_TABBABLE);
useEffect(() => {
if (readOnly) return;
+ const { query, globalEventListener, insertTabbableEntries, isTabbable } =
+ getPluginOptions(editor, KEY_TABBABLE);
+
const editorDOMNode = toDOMNode(editor, editor);
if (!editorDOMNode) return;
@@ -127,14 +128,7 @@ export function TabbableEffects() {
eventListenerNode.addEventListener('keydown', handler, true);
return () =>
eventListenerNode.removeEventListener('keydown', handler, true);
- }, [
- readOnly,
- editor,
- globalEventListener,
- isTabbable,
- insertTabbableEntries,
- query,
- ]);
+ }, [readOnly, editor]);
return null;
}
diff --git a/packages/table/src/components/TableCellElement/useTableBordersDropdownMenuContentState.ts b/packages/table/src/components/TableCellElement/useTableBordersDropdownMenuContentState.ts
index 00da8b1105..4fd745d92f 100644
--- a/packages/table/src/components/TableCellElement/useTableBordersDropdownMenuContentState.ts
+++ b/packages/table/src/components/TableCellElement/useTableBordersDropdownMenuContentState.ts
@@ -1,17 +1,31 @@
-import { useEditorState } from '@udecode/plate-common';
+import { useEditorRef, useEditorSelector } from '@udecode/plate-common';
import { isTableBorderHidden } from '../../queries/index';
import { useTableStore } from '../../stores/index';
import { getOnSelectTableBorderFactory } from './getOnSelectTableBorderFactory';
export const useTableBordersDropdownMenuContentState = () => {
- const editor = useEditorState();
+ const editor = useEditorRef();
const selectedCells = useTableStore().get.selectedCells();
- const hasBottomBorder = !isTableBorderHidden(editor, 'bottom');
- const hasTopBorder = !isTableBorderHidden(editor, 'top');
- const hasLeftBorder = !isTableBorderHidden(editor, 'left');
- const hasRightBorder = !isTableBorderHidden(editor, 'right');
+ /* eslint-disable @typescript-eslint/no-shadow */
+ const hasBottomBorder = useEditorSelector(
+ (editor) => !isTableBorderHidden(editor, 'bottom'),
+ []
+ );
+ const hasTopBorder = useEditorSelector(
+ (editor) => !isTableBorderHidden(editor, 'top'),
+ []
+ );
+ const hasLeftBorder = useEditorSelector(
+ (editor) => !isTableBorderHidden(editor, 'left'),
+ []
+ );
+ const hasRightBorder = useEditorSelector(
+ (editor) => !isTableBorderHidden(editor, 'right'),
+ []
+ );
+ /* eslint-enable @typescript-eslint/no-shadow */
const hasOuterBorders =
hasBottomBorder && hasTopBorder && hasLeftBorder && hasRightBorder;
diff --git a/packages/table/src/merge/useTableMergeState.ts b/packages/table/src/merge/useTableMergeState.ts
index f142dd8f37..0ff2f09776 100644
--- a/packages/table/src/merge/useTableMergeState.ts
+++ b/packages/table/src/merge/useTableMergeState.ts
@@ -1,11 +1,9 @@
/* eslint-disable react-hooks/rules-of-hooks */
-import { useMemo } from 'react';
import {
getPluginOptions,
- isCollapsed,
- isExpanded,
+ isSelectionExpanded,
useEditorRef,
- useEditorState,
+ useEditorSelector,
} from '@udecode/plate-common';
import { useReadOnly, useSelected } from 'slate-react';
@@ -27,32 +25,27 @@ export const useTableMergeState = () => {
if (!enableMerging) return { canMerge: false, canUnmerge: false };
- const editor = useEditorState();
-
const readOnly = useReadOnly();
const selected = useSelected();
+ const selectionExpanded = useEditorSelector(isSelectionExpanded, []);
- const collapsed = !readOnly && selected && isCollapsed(editor.selection);
+ const collapsed = !readOnly && selected && !selectionExpanded;
const selectedTables = useTableStore().get.selectedTable();
const selectedTable = selectedTables?.[0];
- const selectedCellEntries = useMemo(
- () =>
+ const selectedCellEntries = useEditorSelector(
+ (editor) =>
getTableGridAbove(editor, {
format: 'cell',
}),
- // eslint-disable-next-line react-hooks/exhaustive-deps
- [editor.selection]
+ []
);
- const canMerge = useMemo(() => {
- return (
- !readOnly &&
- selected &&
- isExpanded(editor.selection) &&
- isTableRectangular(selectedTable)
- );
- }, [readOnly, selected, editor.selection, selectedTable]);
+ const canMerge =
+ !readOnly &&
+ selected &&
+ selectionExpanded &&
+ isTableRectangular(selectedTable);
const canUnmerge =
collapsed &&
diff --git a/yarn.lock b/yarn.lock
index 4ef253b3f6..ed797cb0d1 100644
--- a/yarn.lock
+++ b/yarn.lock
@@ -6194,7 +6194,7 @@ __metadata:
languageName: unknown
linkType: soft
-"@udecode/plate-comments@npm:27.0.3, @udecode/plate-comments@workspace:^, @udecode/plate-comments@workspace:packages/comments":
+"@udecode/plate-comments@npm:27.0.4, @udecode/plate-comments@workspace:^, @udecode/plate-comments@workspace:packages/comments":
version: 0.0.0-use.local
resolution: "@udecode/plate-comments@workspace:packages/comments"
dependencies:
@@ -6241,7 +6241,7 @@ __metadata:
clsx: "npm:^1.2.1"
is-hotkey: "npm:^0.2.0"
jotai: "npm:^2.6.0"
- jotai-x: "npm:^1.0.1"
+ jotai-x: "npm:^1.1.0"
lodash: "npm:^4.17.21"
nanoid: "npm:^3.3.6"
react-hotkeys-hook: "npm:^4.4.1"
@@ -6907,7 +6907,7 @@ __metadata:
"@udecode/plate-break": "npm:27.0.3"
"@udecode/plate-code-block": "npm:27.0.3"
"@udecode/plate-combobox": "npm:27.0.3"
- "@udecode/plate-comments": "npm:27.0.3"
+ "@udecode/plate-comments": "npm:27.0.4"
"@udecode/plate-common": "npm:27.0.3"
"@udecode/plate-find-replace": "npm:27.0.3"
"@udecode/plate-floating": "npm:27.0.3"
@@ -13522,9 +13522,9 @@ __metadata:
languageName: node
linkType: hard
-"jotai-x@npm:^1.0.1":
- version: 1.0.1
- resolution: "jotai-x@npm:1.0.1"
+"jotai-x@npm:^1.1.0":
+ version: 1.1.0
+ resolution: "jotai-x@npm:1.1.0"
peerDependencies:
"@types/react": ">=17.0.0"
jotai: ">=2.0.0"
@@ -13534,7 +13534,7 @@ __metadata:
optional: true
react:
optional: true
- checksum: 67cbcd3ead992765b7a6f72e369f63da4a13519474c13a9d9f4acb35f2c205ee79c3e6ed0e698d17de6662f2c6cf97eb4e89486c6cd3e0d4f266b21094eaec1d
+ checksum: 1f42e706f9f7ba28ffd713623672ba46b00afb1b5ee62507948aeacf2f58a1b9074c30445757f387bae5a278050ec0b82b624a59aafdd732403c1d3b64eb87af
languageName: node
linkType: hard