@@ -6,8 +6,11 @@ import {
66 Transforms ,
77 type BaseEditor ,
88 type Node ,
9+ type Operation ,
910 type Path ,
1011 type Point ,
12+ type RangeRef ,
13+ type Text ,
1114} from '../../slate'
1215import type { TextDiff } from '../utils/diff-text'
1316import {
@@ -32,18 +35,11 @@ import {
3235import { IS_ANDROID , IS_CHROME , IS_FIREFOX } from '../utils/environment'
3336import { Key } from '../utils/key'
3437import {
35- EDITOR_TO_ELEMENT ,
36- EDITOR_TO_KEY_TO_ELEMENT ,
37- EDITOR_TO_PENDING_DIFFS ,
38- EDITOR_TO_SCHEDULE_FLUSH ,
39- EDITOR_TO_WINDOW ,
4038 ELEMENT_TO_NODE ,
41- IS_COMPOSING ,
42- IS_FOCUSED ,
43- IS_READ_ONLY ,
4439 NODE_TO_INDEX ,
4540 NODE_TO_KEY ,
4641 NODE_TO_PARENT ,
42+ type Action ,
4743} from '../utils/weak-maps'
4844
4945/**
@@ -69,6 +65,25 @@ export interface DOMEditor extends BaseEditor {
6965 data : DataTransfer ,
7066 originEvent ?: 'drag' | 'copy' | 'cut' ,
7167 ) => void
68+
69+ isNodeMapDirty : boolean
70+ domWindow : Window | null
71+ domElement : HTMLElement | null
72+ domPlaceholder : string
73+ domPlaceholderElement : HTMLElement | null
74+ keyToElement : WeakMap < Key , HTMLElement >
75+ readOnly : boolean
76+ focused : boolean
77+ composing : boolean
78+ userSelection : RangeRef | null
79+ onContextChange : ( ( options ?: { operation ?: Operation } ) => void ) | null
80+ scheduleFlush : ( ( ) => void ) | null
81+ pendingInsertionMarks : Partial < Text > | null
82+ userMarks : Partial < Text > | null
83+ pendingDiffs : TextDiff [ ]
84+ pendingAction : Action | null
85+ pendingSelection : Range | null
86+ forceRender : ( ( ) => void ) | null
7287}
7388
7489export interface DOMEditorInterface {
@@ -258,16 +273,16 @@ export interface DOMEditorInterface {
258273
259274// eslint-disable-next-line no-redeclare
260275export const DOMEditor : DOMEditorInterface = {
261- androidPendingDiffs : ( editor ) => EDITOR_TO_PENDING_DIFFS . get ( editor ) ,
276+ androidPendingDiffs : ( editor ) => editor . pendingDiffs ,
262277
263278 androidScheduleFlush : ( editor ) => {
264- EDITOR_TO_SCHEDULE_FLUSH . get ( editor ) ?.( )
279+ editor . scheduleFlush ?.( )
265280 } ,
266281
267282 blur : ( editor ) => {
268283 const el = DOMEditor . toDOMNode ( editor , editor )
269284 const root = DOMEditor . findDocumentOrShadowRoot ( editor )
270- IS_FOCUSED . set ( editor , false )
285+ editor . focused = false
271286
272287 if ( root . activeElement === el ) {
273288 el . blur ( )
@@ -407,13 +422,13 @@ export const DOMEditor: DOMEditorInterface = {
407422
408423 focus : ( editor , options = { retries : 5 } ) => {
409424 // Return if already focused
410- if ( IS_FOCUSED . get ( editor ) ) {
425+ if ( editor . focused ) {
411426 return
412427 }
413428
414429 // Return if no dom node is associated with the editor, which means the editor is not yet mounted
415430 // or has been unmounted. This can happen especially, while retrying to focus the editor.
416- if ( ! EDITOR_TO_ELEMENT . get ( editor ) ) {
431+ if ( ! editor . domElement ) {
417432 return
418433 }
419434
@@ -448,13 +463,13 @@ export const DOMEditor: DOMEditorInterface = {
448463 }
449464 // IS_FOCUSED should be set before calling el.focus() to ensure that
450465 // FocusedContext is updated to the correct value
451- IS_FOCUSED . set ( editor , true )
466+ editor . focused = true
452467 el . focus ( { preventScroll : true } )
453468 }
454469 } ,
455470
456471 getWindow : ( editor ) => {
457- const window = EDITOR_TO_WINDOW . get ( editor )
472+ const window = editor . domWindow
458473 if ( ! window ) {
459474 throw new Error ( 'Unable to find a host window element for this editor' )
460475 }
@@ -525,15 +540,15 @@ export const DOMEditor: DOMEditorInterface = {
525540 insertTextData : ( editor , data ) => editor . insertTextData ( data ) ,
526541
527542 isComposing : ( editor ) => {
528- return ! ! IS_COMPOSING . get ( editor )
543+ return ! ! editor . composing
529544 } ,
530545
531- isFocused : ( editor ) => ! ! IS_FOCUSED . get ( editor ) ,
546+ isFocused : ( editor ) => ! ! editor . focused ,
532547
533- isReadOnly : ( editor ) => ! ! IS_READ_ONLY . get ( editor ) ,
548+ isReadOnly : ( editor ) => ! ! editor . readOnly ,
534549
535550 isTargetInsideNonReadonlyVoid : ( editor , target ) => {
536- if ( IS_READ_ONLY . get ( editor ) ) {
551+ if ( editor . readOnly ) {
537552 return false
538553 }
539554
@@ -547,10 +562,9 @@ export const DOMEditor: DOMEditorInterface = {
547562 editor . setFragmentData ( data , originEvent ) ,
548563
549564 toDOMNode : ( editor , node ) => {
550- const KEY_TO_ELEMENT = EDITOR_TO_KEY_TO_ELEMENT . get ( editor )
551565 const domNode = Editor . isEditor ( node )
552- ? EDITOR_TO_ELEMENT . get ( editor )
553- : KEY_TO_ELEMENT ?. get ( DOMEditor . findKey ( editor , node ) )
566+ ? editor . domElement
567+ : editor . keyToElement ?. get ( DOMEditor . findKey ( editor , node ) )
554568
555569 if ( ! domNode ) {
556570 throw new Error (
0 commit comments