@@ -19,6 +19,20 @@ export const getSelectionIndices = (selection, parentPath) => {
1919 return sorted ;
2020} ;
2121
22+ const gatherListForAlignmentCheck = block => {
23+ if ( block . type === "li" ) {
24+ const listChildren = block . children ?. filter (
25+ child => child . type === "ul" || child . type === "ol"
26+ ) ;
27+ return listChildren ?. length
28+ ? [ block , ...listChildren . map ( gatherListForAlignmentCheck ) ]
29+ : block ;
30+ }
31+ if ( block . type === "ul" || block . type === "ol" ) {
32+ return block . children ?. map ( gatherListForAlignmentCheck ) ?? [ ] ;
33+ }
34+ } ;
35+
2236const gatherNodesForAlignmentCheck = block => {
2337 if ( ! block ) return [ ] ;
2438
@@ -28,7 +42,7 @@ const gatherNodesForAlignmentCheck = block => {
2842
2943 if ( hasInlineChildren && ! block . slateOnly ) return block ;
3044
31- // if (isRangeEnd && block.type === "li") return block;
45+ if ( block . type === "li" ) return gatherListForAlignmentCheck ( block ) ;
3246
3347 if ( block . children ?. length )
3448 return block . children . map ( c => gatherNodesForAlignmentCheck ( c ) ) ;
@@ -66,22 +80,45 @@ export const getActiveAlignment = (selection, block, path) => {
6680 : null ;
6781} ;
6882
83+ const applyClassNameToNestedList = ( editor , block , path , style ) => {
84+ if ( block . type === "li" ) {
85+ setBlockClassName ( {
86+ editor,
87+ block,
88+ path,
89+ className : getClassNameWithAlign ( block , style )
90+ } ) ;
91+ }
92+
93+ const hasInlineChildren = block . children ?. [ 0 ]
94+ ? Object . hasOwn ( block . children ?. [ 0 ] , "text" )
95+ : false ;
96+
97+ if ( hasInlineChildren ) return ;
98+
99+ if ( block . children ?. length )
100+ block . children . map ( ( childBlock , i ) =>
101+ applyClassNameToNestedList ( editor , childBlock , [ ...path , i ] , style )
102+ ) ;
103+ } ;
104+
69105export const maybeApplyNestedBlockClassName = ( editor , block , path , style ) => {
70106 if ( ! block ) return ;
71107
108+ if ( block . type === "li" )
109+ return applyClassNameToNestedList ( editor , block , path , style ) ;
110+
72111 const hasInlineChildren = block . children ?. [ 0 ]
73112 ? Object . hasOwn ( block . children ?. [ 0 ] , "text" )
74113 : false ;
75114
76- if ( ( hasInlineChildren && ! block . slateOnly ) || block . type === "li" ) {
77- setBlockClassName ( {
115+ if ( hasInlineChildren && ! block . slateOnly ) {
116+ return setBlockClassName ( {
78117 editor,
79118 block,
80119 path,
81120 className : getClassNameWithAlign ( block , style )
82121 } ) ;
83-
84- if ( block . type !== "li" ) return ;
85122 }
86123
87124 if ( block . children ?. length )
0 commit comments