/
list-item.js
48 lines (40 loc) · 1.31 KB
/
list-item.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import Markerable from './_markerable';
import { LIST_ITEM_TYPE } from './types';
import {
normalizeTagName
} from 'mobiledoc-kit/utils/dom-utils';
import { contains } from 'mobiledoc-kit/utils/array-utils';
export const VALID_LIST_ITEM_TAGNAMES = [
'li'
].map(normalizeTagName);
export default class ListItem extends Markerable {
constructor(tagName, markers=[]) {
super(LIST_ITEM_TYPE, tagName, markers);
this.isListItem = true;
this.isNested = true;
}
isValidTagName(normalizedTagName) {
return contains(VALID_LIST_ITEM_TAGNAMES, normalizedTagName);
}
splitAtMarker(marker, offset=0) {
// FIXME need to check if we are going to split into two list items
// or a list item and a new markup section:
const isLastItem = !this.next;
const createNewSection = (!marker && offset === 0 && isLastItem);
let [beforeSection, afterSection] = [
this.builder.createListItem(),
createNewSection ? this.builder.createMarkupSection() :
this.builder.createListItem()
];
return this._redistributeMarkers(
beforeSection, afterSection, marker, offset);
}
clone() {
const item = this.builder.createListItem();
this.markers.forEach(m => item.markers.append(m.clone()));
return item;
}
get post() {
return this.section.post;
}
}