1- import { normalizeTagName } from '../utils/dom-utils'
21import LinkedItem from '../utils/linked-item'
32import assert from '../utils/assert'
43import Position from '../utils/cursor/position'
5- import LinkedList from '../utils/linked-list '
4+ import Range from '../utils/cursor/range '
65import Marker from './marker'
76import RenderNode from './render-node'
87import Post from './post'
8+ import { isListSection } from './is-list-section'
9+ import PostNodeBuilder from './post-node-builder'
10+ import { Type } from './types'
911
10- export default abstract class Section extends LinkedItem < Section > {
11- type : string
12- isSection : boolean
13- isMarkerable : boolean
14- isNested : boolean
15- isLeafSection : boolean
12+ export default class Section extends LinkedItem {
13+ type : Type
14+
15+ isSection = true
16+ isMarkerable = false
17+ isNested = false
18+ isListItem = false
19+ isListSection = false
20+ isLeafSection = true
21+ isCardSection = false
1622
1723 post ?: Post | null
18- parent : Section | null = null
1924 renderNode : RenderNode | null = null
20- _tagName : string | null = null
2125
22- constructor ( type : string ) {
26+ parent : Section | null = null
27+ builder ! : PostNodeBuilder
28+
29+ constructor ( type : Type ) {
2330 super ( )
2431 assert ( 'Cannot create section without type' , ! ! type )
2532 this . type = type
26- this . isSection = true
27- this . isMarkerable = false
28- this . isNested = false
29- this . isLeafSection = true
30- }
31-
32- set tagName ( val : string ) {
33- let normalizedTagName = normalizeTagName ( val )
34- assert ( `Cannot set section tagName to ${ val } ` , this . isValidTagName ( normalizedTagName ) )
35- this . _tagName = normalizedTagName
3633 }
3734
38- get tagName ( ) {
39- return this . _tagName as string
35+ get isBlank ( ) {
36+ return false
4037 }
4138
4239 get length ( ) {
4340 return 0
4441 }
4542
46- abstract get isBlank ( ) : boolean
47- abstract isValidTagName ( _normalizedTagName : string ) : boolean
48- abstract clone ( ) : Section
49- abstract canJoin ( otherSection : Section ) : boolean
50- abstract textUntil ( position : Position ) : string
51-
5243 /**
5344 * @return {Position } The position at the start of this section
5445 * @public
5546 */
56- headPosition ( ) {
47+ headPosition ( ) : Position {
5748 return this . toPosition ( 0 )
5849 }
5950
6051 /**
6152 * @return {Position } The position at the end of this section
6253 * @public
6354 */
64- tailPosition ( ) {
55+ tailPosition ( ) : Position {
6556 return this . toPosition ( this . length )
6657 }
6758
@@ -70,7 +61,7 @@ export default abstract class Section extends LinkedItem<Section> {
7061 * @return {Position } The position in this section at the given offset
7162 * @public
7263 */
73- toPosition ( offset : number ) {
64+ toPosition ( offset : number ) : Position {
7465 assert ( 'Must pass number to `toPosition`' , typeof offset === 'number' )
7566 assert ( 'Cannot call `toPosition` with offset > length' , offset <= this . length )
7667
@@ -81,7 +72,7 @@ export default abstract class Section extends LinkedItem<Section> {
8172 * @return {Range } A range from this section's head to tail positions
8273 * @public
8374 */
84- toRange ( ) {
75+ toRange ( ) : Range {
8576 return this . headPosition ( ) . toRange ( this . tailPosition ( ) )
8677 }
8778
@@ -136,11 +127,3 @@ export default abstract class Section extends LinkedItem<Section> {
136127 return null
137128 }
138129}
139-
140- interface ListSection {
141- items : LinkedList < Section >
142- }
143-
144- function isListSection ( item : any ) : item is ListSection {
145- return 'items' in item && item . items
146- }
0 commit comments