1
- import type { ContentModelBlockGroup , ContentModelListItem } from 'roosterjs-content-model-types' ;
1
+ import type {
2
+ ContentModelBlockGroup ,
3
+ ContentModelListItem ,
4
+ ReadonlyContentModelBlockGroup ,
5
+ ReadonlyContentModelListItem ,
6
+ } from 'roosterjs-content-model-types' ;
2
7
3
8
/**
9
+ * Search for all list items in the same thread as the current list item
4
10
* @param model The content model
5
11
* @param currentItem The current list item
6
- * Search for all list items in the same thread as the current list item
7
12
*/
8
13
export function findListItemsInSameThread (
9
14
group : ContentModelBlockGroup ,
10
15
currentItem : ContentModelListItem
11
- ) : ContentModelListItem [ ] {
16
+ ) : ContentModelListItem [ ] ;
17
+
18
+ /**
19
+ * Search for all list items in the same thread as the current list item (Readonly)
20
+ * @param model The content model
21
+ * @param currentItem The current list item
22
+ */
23
+ export function findListItemsInSameThread (
24
+ group : ReadonlyContentModelBlockGroup ,
25
+ currentItem : ReadonlyContentModelListItem
26
+ ) : ReadonlyContentModelListItem [ ] ;
27
+
28
+ export function findListItemsInSameThread (
29
+ group : ReadonlyContentModelBlockGroup ,
30
+ currentItem : ReadonlyContentModelListItem
31
+ ) : ReadonlyContentModelListItem [ ] {
12
32
const items : ( ContentModelListItem | null ) [ ] = [ ] ;
13
33
14
34
findListItems ( group , items ) ;
15
35
16
36
return filterListItems ( items , currentItem ) ;
17
37
}
18
38
19
- function findListItems ( group : ContentModelBlockGroup , result : ( ContentModelListItem | null ) [ ] ) {
39
+ function findListItems (
40
+ group : ReadonlyContentModelBlockGroup ,
41
+ result : ( ReadonlyContentModelListItem | null ) [ ]
42
+ ) {
20
43
group . blocks . forEach ( block => {
21
44
switch ( block . blockType ) {
22
45
case 'BlockGroup' :
@@ -56,7 +79,7 @@ function findListItems(group: ContentModelBlockGroup, result: (ContentModelListI
56
79
} ) ;
57
80
}
58
81
59
- function pushNullIfNecessary ( result : ( ContentModelListItem | null ) [ ] ) {
82
+ function pushNullIfNecessary ( result : ( ReadonlyContentModelListItem | null ) [ ] ) {
60
83
const last = result [ result . length - 1 ] ;
61
84
62
85
if ( ! last || last !== null ) {
@@ -65,10 +88,10 @@ function pushNullIfNecessary(result: (ContentModelListItem | null)[]) {
65
88
}
66
89
67
90
function filterListItems (
68
- items : ( ContentModelListItem | null ) [ ] ,
69
- currentItem : ContentModelListItem
91
+ items : ( ReadonlyContentModelListItem | null ) [ ] ,
92
+ currentItem : ReadonlyContentModelListItem
70
93
) {
71
- const result : ContentModelListItem [ ] = [ ] ;
94
+ const result : ReadonlyContentModelListItem [ ] = [ ] ;
72
95
const currentIndex = items . indexOf ( currentItem ) ;
73
96
const levelLength = currentItem . levels . length ;
74
97
const isOrderedList = currentItem . levels [ levelLength - 1 ] ?. listType == 'OL' ;
@@ -131,7 +154,7 @@ function filterListItems(
131
154
}
132
155
133
156
function areListTypesCompatible (
134
- listItems : ( ContentModelListItem | null ) [ ] ,
157
+ listItems : ( ReadonlyContentModelListItem | null ) [ ] ,
135
158
currentIndex : number ,
136
159
compareToIndex : number
137
160
) : boolean {
@@ -146,7 +169,7 @@ function areListTypesCompatible(
146
169
) ;
147
170
}
148
171
149
- function hasStartNumberOverride ( item : ContentModelListItem , levelLength : number ) : boolean {
172
+ function hasStartNumberOverride ( item : ReadonlyContentModelListItem , levelLength : number ) : boolean {
150
173
return item . levels
151
174
. slice ( 0 , levelLength )
152
175
. some ( level => level . format . startNumberOverride !== undefined ) ;
0 commit comments