Skip to content

Commit 21adaf1

Browse files
committed
[DEV-19139] Fix inaccurate types
1 parent 131a3dc commit 21adaf1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

packages/slate-editor/src/modules/editor/lib/isEditorValueEqual.ts

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import { isEqual } from '@technically/lodash';
2-
import { isVoid, type SlateEditor } from '@udecode/plate-common';
2+
import { type SlateEditor } from '@udecode/plate-common';
33
import type { Element, Text, Descendant } from 'slate';
44

5+
import type { ElementsEqualityCheckEditor } from '../plugins';
6+
57
export function isEditorValueEqual<T extends Descendant>(
6-
editor: SlateEditor,
8+
editor: SlateEditor & ElementsEqualityCheckEditor,
79
a: T[],
810
b: T[],
911
): boolean {
@@ -18,7 +20,7 @@ export function isEditorValueEqual<T extends Descendant>(
1820
if (!isNodeText && !isAnotherText) {
1921
const equal = editor.isElementEqual(node as Element, another as Element);
2022
if (typeof equal !== 'undefined') {
21-
if (isVoid(editor, node) || isVoid(editor, another)) {
23+
if (editor.isVoid(node) || editor.isVoid(another)) {
2224
// Do not compare void elements children
2325
return equal;
2426
}
@@ -49,14 +51,17 @@ function isText(node: Descendant): node is Text {
4951
// CACHE
5052

5153
const CACHE: WeakMap<
52-
SlateEditor,
54+
ElementsEqualityCheckEditor,
5355
WeakMap<Descendant, WeakMap<Descendant, boolean>>
5456
> = new WeakMap();
5557

56-
type WeakMatrix = WeakMap<SlateEditor, WeakMap<Descendant, WeakMap<Descendant, boolean>>>;
58+
type WeakMatrix = WeakMap<
59+
ElementsEqualityCheckEditor,
60+
WeakMap<Descendant, WeakMap<Descendant, boolean>>
61+
>;
5762
type NodesComparator = (node: Descendant, another: Descendant) => boolean;
5863

59-
function cached(editor: SlateEditor, fn: NodesComparator): NodesComparator {
64+
function cached(editor: ElementsEqualityCheckEditor, fn: NodesComparator): NodesComparator {
6065
return (node, another) => {
6166
const cached = get(CACHE, editor, node, another) ?? get(CACHE, editor, another, node);
6267

@@ -75,7 +80,7 @@ function cached(editor: SlateEditor, fn: NodesComparator): NodesComparator {
7580

7681
function get(
7782
matrix: WeakMatrix,
78-
editor: SlateEditor,
83+
editor: ElementsEqualityCheckEditor,
7984
node: Descendant,
8085
another: Descendant,
8186
): boolean | undefined {
@@ -84,7 +89,7 @@ function get(
8489

8590
function set(
8691
matrix: WeakMatrix,
87-
editor: SlateEditor,
92+
editor: ElementsEqualityCheckEditor,
8893
node: Descendant,
8994
another: Descendant,
9095
value: boolean,

0 commit comments

Comments
 (0)