@@ -45,9 +45,10 @@ function getTypeInfo(component) {
4545 return [ types , typeMap ]
4646}
4747
48- // Decorates components; sets component.typePos to
49- // "at-start", "at-center", or "at-end" for common types.
50- function decorateTypePos ( components ) {
48+ // Decorates components; sets component.pos to "at-start",
49+ // "at-center", or "at-end" for common types.
50+
51+ function decoratePos ( components ) {
5152 for ( let x = 0 ; x < components . length ; x ++ ) {
5253 if ( ! x || typeof components [ x ] === "string" ) {
5354 // No-op
@@ -57,22 +58,25 @@ function decorateTypePos(components) {
5758 const [ types2 , typeMap2 ] = getTypeInfo ( components [ x ] )
5859 const common = types1 . filter ( a => types2 . some ( b => a === b ) )
5960 for ( const type of common ) {
60- typeMap1 [ type ] . props . typePos = ! typeMap1 [ type ] . props . typePos ? "at-start" : "at-center"
61- typeMap2 [ type ] . props . typePos = "at-end"
61+ typeMap1 [ type ] . props . pos = ! typeMap1 [ type ] . props . pos ? "at-start" : "at-center"
62+ typeMap2 [ type ] . props . pos = "at-end"
6263 }
6364 }
6465}
6566
66- // Parses spans.
67+ // Parses spans to psuedo-React elements .
6768function parseSpans ( spans ) {
68- const components = [ ]
69+ // if (!spans.length) {
70+ // return null
71+ // }
72+ const elements = [ ]
6973 for ( const span of spans ) {
7074 if ( ! span . formats . length ) {
71- components . push ( span . content )
75+ elements . push ( span . content )
7276 continue
7377 }
74- const component = { }
75- let lastRef = component
78+ const element = { }
79+ let lastRef = element
7680 let ref = lastRef
7781 for ( const format of span . formats . sort ( ) ) {
7882 Object . assign ( ref , { // <- lastRef
@@ -86,10 +90,10 @@ function parseSpans(spans) {
8690 ref = ref . props . children
8791 }
8892 lastRef . props . children = span . content
89- components . push ( component )
93+ elements . push ( element )
9094 }
91- decorateTypePos ( components )
92- return components
95+ decoratePos ( elements )
96+ return elements
9397}
9498
9599const ReactRenderer = ( { state, dispatch, renderableMap } ) => (
@@ -122,41 +126,41 @@ const Editor = () => {
122126 type : Paragraph ,
123127 uuid : uuidv4 ( ) ,
124128 spans : [
125- {
126- content : "Hey, " ,
127- formats : [ formatsEnum . strong ] ,
128- } ,
129- {
130- content : "Russ" ,
131- formats : [ formatsEnum . strong , formatsEnum . emphasis ] ,
132- } ,
133- {
134- content : "!" ,
135- formats : [ formatsEnum . strong ] ,
136- } ,
137- {
138- content : " I’m making some " ,
139- formats : [ formatsEnum . strong ] ,
140- } ,
141- {
142- content : "progress " ,
143- formats : [ formatsEnum . code ] ,
144- } ,
145- {
146- content : " on making a " ,
147- formats : [ ] ,
148- } ,
149- {
150- content : "WYSIWYG" ,
151- formats : [ formatsEnum . anchor ] ,
152- [ formatsEnum . anchor ] : {
153- href : "https://heroicons.dev" ,
154- } ,
155- } ,
156- {
157- content : " editor." ,
158- formats : [ ] ,
159- } ,
129+ // {
130+ // content: "Hey, ",
131+ // formats: [formatsEnum.strong],
132+ // },
133+ // {
134+ // content: "Russ",
135+ // formats: [formatsEnum.strong, formatsEnum.emphasis],
136+ // },
137+ // {
138+ // content: "!",
139+ // formats: [formatsEnum.strong],
140+ // },
141+ // {
142+ // content: " I’m making some ",
143+ // formats: [formatsEnum.strong],
144+ // },
145+ // {
146+ // content: "progress ",
147+ // formats: [formatsEnum.code],
148+ // },
149+ // {
150+ // content: " on making a ",
151+ // formats: [],
152+ // },
153+ // {
154+ // content: "WYSIWYG",
155+ // formats: [formatsEnum.anchor],
156+ // [formatsEnum.anchor]: {
157+ // href: "https://heroicons.dev",
158+ // },
159+ // },
160+ // {
161+ // content: " editor.",
162+ // formats: [],
163+ // },
160164 ] ,
161165 } ,
162166 ] )
@@ -204,6 +208,7 @@ const Editor = () => {
204208
205209 return (
206210 < div >
211+
207212 < article
208213 ref = { ref }
209214
@@ -213,10 +218,6 @@ const Editor = () => {
213218 onBlur = { dispatch . blur }
214219 onSelect = { ( ) => {
215220 const cursors = computeCursors ( )
216- // if (!cursors) {
217- // // No-op
218- // return
219- // }
220221 dispatch . select ( cursors )
221222 } }
222223 onPointerDown = { ( ) => {
@@ -228,10 +229,6 @@ const Editor = () => {
228229 return
229230 }
230231 const cursors = computeCursors ( )
231- // if (!cursors) {
232- // // No-op
233- // return
234- // }
235232 dispatch . select ( cursors )
236233 } }
237234 onPointerUp = { ( ) => {
@@ -324,8 +321,14 @@ const Editor = () => {
324321 data-codex-root
325322 />
326323
324+ { /* Debugger */ }
327325 < div className = "mt-6 whitespace-pre font-mono text-xs leading-tight" style = { { tabSize : 2 } } >
328- { JSON . stringify ( state , null , "\t" ) }
326+ { JSON . stringify ( state , ( key , value ) => {
327+ if ( key === "formats" ) {
328+ return value
329+ }
330+ return value
331+ } , "\t" ) }
329332 </ div >
330333
331334 </ div >
0 commit comments