File tree Expand file tree Collapse file tree 2 files changed +44
-10
lines changed Expand file tree Collapse file tree 2 files changed +44
-10
lines changed Original file line number Diff line number Diff line change @@ -298,4 +298,23 @@ const Editor = ({
298298 )
299299}
300300
301- export default Editor
301+ const tabSize = n => ( {
302+ MozTabSize : n ,
303+ tabSize : n ,
304+ } )
305+
306+ const EditorWithDebugger = ( { state, dispatch } ) => (
307+ < >
308+ < Editor
309+ state = { state }
310+ dispatch = { dispatch }
311+ />
312+ { process . env . NODE_ENV !== "production" && (
313+ < pre className = "mt-6 text-xs whitespace-pre-wrap break-words" style = { tabSize ( 2 ) } >
314+ { JSON . stringify ( state , null , "\t" ) }
315+ </ pre >
316+ ) }
317+ </ >
318+ )
319+
320+ export default EditorWithDebugger
Original file line number Diff line number Diff line change 11import { useImmerReducer } from "use-immer"
22
33const createInitialState = initialValueMarkdown => ( {
4- // ...
4+ readOnlyMode : false ,
5+
6+ focused : false ,
7+ content : [ ] ,
8+ cursors : {
9+ start : {
10+ key : "" ,
11+ offset : 0 ,
12+ } ,
13+ end : {
14+ key : "" ,
15+ offset : 0 ,
16+ } ,
17+ } ,
18+
19+ shouldRerender : 0 ,
520} )
621
722const actions = state => ( {
8- a ( ) {
9-
23+ focus ( ) {
24+ state . focused = true
1025 } ,
11- b ( ) {
12-
26+ blur ( ) {
27+ state . focused = false
1328 } ,
1429} )
1530
1631function EditorReducer ( state , action ) {
1732 switch ( action . type ) {
18- case "A " :
19- actions ( state ) . a ( )
33+ case "FOCUS " :
34+ actions ( state ) . focus ( )
2035 return
21- case "B " :
22- actions ( state ) . a ( )
36+ case "BLUR " :
37+ actions ( state ) . blur ( )
2338 return
2439 default :
2540 throw new Error ( `EditorReducer: type mismatch; action.type=${ action . type } ` )
You can’t perform that action at this time.
0 commit comments