1
1
import { isEqual } from '@technically/lodash' ;
2
- import { isVoid , type SlateEditor } from '@udecode/plate-common' ;
2
+ import { type SlateEditor } from '@udecode/plate-common' ;
3
3
import type { Element , Text , Descendant } from 'slate' ;
4
4
5
+ import type { ElementsEqualityCheckEditor } from '../plugins' ;
6
+
5
7
export function isEditorValueEqual < T extends Descendant > (
6
- editor : SlateEditor ,
8
+ editor : SlateEditor & ElementsEqualityCheckEditor ,
7
9
a : T [ ] ,
8
10
b : T [ ] ,
9
11
) : boolean {
@@ -18,7 +20,7 @@ export function isEditorValueEqual<T extends Descendant>(
18
20
if ( ! isNodeText && ! isAnotherText ) {
19
21
const equal = editor . isElementEqual ( node as Element , another as Element ) ;
20
22
if ( typeof equal !== 'undefined' ) {
21
- if ( isVoid ( editor , node ) || isVoid ( editor , another ) ) {
23
+ if ( editor . isVoid ( node ) || editor . isVoid ( another ) ) {
22
24
// Do not compare void elements children
23
25
return equal ;
24
26
}
@@ -49,14 +51,17 @@ function isText(node: Descendant): node is Text {
49
51
// CACHE
50
52
51
53
const CACHE : WeakMap <
52
- SlateEditor ,
54
+ ElementsEqualityCheckEditor ,
53
55
WeakMap < Descendant , WeakMap < Descendant , boolean > >
54
56
> = new WeakMap ( ) ;
55
57
56
- type WeakMatrix = WeakMap < SlateEditor , WeakMap < Descendant , WeakMap < Descendant , boolean > > > ;
58
+ type WeakMatrix = WeakMap <
59
+ ElementsEqualityCheckEditor ,
60
+ WeakMap < Descendant , WeakMap < Descendant , boolean > >
61
+ > ;
57
62
type NodesComparator = ( node : Descendant , another : Descendant ) => boolean ;
58
63
59
- function cached ( editor : SlateEditor , fn : NodesComparator ) : NodesComparator {
64
+ function cached ( editor : ElementsEqualityCheckEditor , fn : NodesComparator ) : NodesComparator {
60
65
return ( node , another ) => {
61
66
const cached = get ( CACHE , editor , node , another ) ?? get ( CACHE , editor , another , node ) ;
62
67
@@ -75,7 +80,7 @@ function cached(editor: SlateEditor, fn: NodesComparator): NodesComparator {
75
80
76
81
function get (
77
82
matrix : WeakMatrix ,
78
- editor : SlateEditor ,
83
+ editor : ElementsEqualityCheckEditor ,
79
84
node : Descendant ,
80
85
another : Descendant ,
81
86
) : boolean | undefined {
@@ -84,7 +89,7 @@ function get(
84
89
85
90
function set (
86
91
matrix : WeakMatrix ,
87
- editor : SlateEditor ,
92
+ editor : ElementsEqualityCheckEditor ,
88
93
node : Descendant ,
89
94
another : Descendant ,
90
95
value : boolean ,
0 commit comments