@@ -33,13 +33,27 @@ const Render = ({ renderable }) => (
3333 ) )
3434)
3535
36+ // Exposes:
37+ //
38+ // onFocus
39+ // onBlur
40+ // onSelect
41+ // onKeyDown
42+ // onCompositionEnd
43+ // onInput
44+ // onCut
45+ // onCopy
46+ // onPaste
47+ //
3648const Editor = ( {
3749 id,
3850 className,
3951 style,
4052
4153 state,
4254 dispatch,
55+
56+ ...props
4357} ) => {
4458 const articleRef = React . useRef ( null )
4559 const isPointerDownRef = React . useRef ( false )
@@ -88,12 +102,19 @@ const Editor = ({
88102 style = { style }
89103
90104 onFocus = { e => {
105+ if ( props . onFocus && typeof props . onFocus === "function" ) {
106+ props . onFocus ( e )
107+ }
108+ run ( props . onFocus )
91109 dispatch ( {
92110 type : "FOCUS" ,
93111 } )
94112 } }
95113
96114 onBlur = { e => {
115+ if ( props . onBlur && typeof props . onBlur === "function" ) {
116+ props . onBlur ( e )
117+ }
97118 dispatch ( {
98119 type : "BLUR" ,
99120 } )
@@ -132,6 +153,9 @@ const Editor = ({
132153 // TODO: Add COMPAT guard for select-all or prevent
133154 // default?
134155 onSelect = { e => {
156+ if ( props . onSelect && typeof props . onSelect === "function" ) {
157+ props . onSelect ( e )
158+ }
135159 try {
136160 const range = computeEditorRangeFromCurrentDOMRange ( articleRef . current )
137161 if ( ! range ) {
@@ -148,6 +172,10 @@ const Editor = ({
148172 } }
149173
150174 // onKeyDown={e => {
175+ // if (props.onKeyDown && typeof props.onKeyDown === "function") {
176+ // props.onKeyDown(e)
177+ // }
178+ //
151179 // let formatType = ""
152180 // let text = ""
153181 // let deleteType = ""
@@ -279,6 +307,9 @@ const Editor = ({
279307 // }}
280308
281309 // onCompositionEnd={e => {
310+ // if (props.onCompositionEnd && typeof props.onCompositionEnd === "function") {
311+ // props.onCompositionEnd(e)
312+ // }
282313 // const range = computeEditorRangeFromCurrentDOMRange(articleRef.current)
283314 // const children = parseRenderedChildren(document.getElementById(range.start.key))
284315 // dispatch({
@@ -290,6 +321,9 @@ const Editor = ({
290321 // }}
291322
292323 // onInput={e => {
324+ // if (props.onInput && typeof props.onInput === "function") {
325+ // props.onInput(e)
326+ // }
293327 // const range = computeEditorRangeFromCurrentDOMRange(articleRef.current)
294328 // const children = parseRenderedChildren(document.getElementById(range.start.key))
295329 // dispatch({
@@ -301,15 +335,24 @@ const Editor = ({
301335 // }}
302336
303337 // onCut={e => {
304- // // TODO
338+ // if (props.onCut && typeof props.onCut === "function") {
339+ // props.onCut(e)
340+ // }
341+ // // ...
305342 // }}
306343
307344 // onCopy={e => {
308- // // TODO
345+ // if (props.onCopy && typeof props.onCopy === "function") {
346+ // props.onCopy(e)
347+ // }
348+ // // ...
309349 // }}
310350
311351 // onPaste={e => {
312- // // TODO
352+ // if (props.onPaste && typeof props.onPaste === "function") {
353+ // props.onPaste(e)
354+ // }
355+ // // ...
313356 // }}
314357
315358 onDragStart = { e => {
@@ -319,23 +362,26 @@ const Editor = ({
319362 contentEditable
320363 suppressContentEditableWarning
321364
322- data-codex- root
365+ data-type = " root"
323366 />
324367 )
325368}
326369
327370const EditorWithDebugger = ( { state, dispatch, ...props } ) => (
328371 < >
372+
329373 < Editor
330374 state = { state }
331375 dispatch = { dispatch }
332376 { ...props }
333377 />
378+
334379 { process . env . NODE_ENV !== "production" && (
335380 < pre className = "mt-6 text-xs whitespace-pre-wrap break-words" style = { { MozTabSize : 2 , tabSize : 2 } } >
336381 { JSON . stringify ( state , null , "\t" ) }
337382 </ pre >
338383 ) }
384+
339385 </ >
340386)
341387
0 commit comments