1
1
import { Fun , Optional } from '@ephox/katamari' ;
2
2
import { SugarElement , SugarNode } from '@ephox/sugar' ;
3
3
import * as React from 'react' ;
4
+ import * as ReactDOMClient from 'react-dom/client' ;
4
5
import { Editor , IAllProps , IProps , Version } from '../../../main/ts/components/Editor' ;
5
6
import { Editor as TinyMCEEditor } from 'tinymce' ;
6
7
import { before , context } from '@ephox/bedrock-client' ;
7
8
import { VersionLoader } from '@tinymce/miniature' ;
8
- import { createRoot } from 'react-dom/client' ;
9
9
10
10
// @ts -expect-error Remove when dispose polyfill is not needed
11
11
Symbol . dispose ??= Symbol ( 'Symbol.dispose' ) ;
@@ -33,7 +33,7 @@ export const render = async (props: Partial<IAllProps> = {}, container: HTMLElem
33
33
const originalInit = props . init || { } ;
34
34
const originalSetup = originalInit . setup || Fun . noop ;
35
35
const ref = React . createRef < Editor > ( ) ;
36
- const root = createRoot ( container ) ;
36
+ const root = ReactDOMClient . createRoot ( container ) ;
37
37
38
38
const ctx = await new Promise < Context > ( ( resolve , reject ) => {
39
39
const init : IProps [ 'init' ] = {
@@ -44,17 +44,18 @@ export const render = async (props: Partial<IAllProps> = {}, container: HTMLElem
44
44
editor . on ( 'SkinLoaded' , ( ) => {
45
45
setTimeout ( ( ) => {
46
46
Optional . from ( ref . current )
47
- . map ( ( editorInstance ) => editorInstance . editor ?. targetElm as HTMLElement )
47
+ . bind ( ( editorInstance ) => Optional . from ( editorInstance . editor ?. targetElm ) )
48
+ . filter ( ( elm ) => elm instanceof window . HTMLElement )
48
49
. map ( SugarElement . fromDom )
49
50
. filter ( SugarNode . isHTMLElement )
50
51
. map ( ( val ) => val . dom )
51
- . fold ( ( ) =>
52
- reject ( 'Could not find editor element' ) ,
53
- ( DOMNode ) => resolve ( {
54
- ref : ref as React . RefObject < Editor > ,
55
- editor ,
56
- DOMNode
57
- } )
52
+ . fold ( ( ) => reject ( 'Could not find DOMNode' ) , ( DOMNode ) => {
53
+ resolve ( {
54
+ ref : ref as React . RefObject < Editor > ,
55
+ editor ,
56
+ DOMNode ,
57
+ } ) ;
58
+ }
58
59
) ;
59
60
} , 0 ) ;
60
61
} ) ;
0 commit comments