-
Notifications
You must be signed in to change notification settings - Fork 152
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add ListSection, ListItem, bump MOBILEDOC_VERSION -> 0.2.0
* simplify editor reparse * update post parser to reparse list sections * hit enter to split a list item * can delete to exit a list * hitting enter in empty list item exits list section altogether * Use Helpers.dom.build rather than `makeDOM` * Test to ensure that hitting enter in a list exits the list appropriately
- Loading branch information
Showing
31 changed files
with
1,006 additions
and
302 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import Section from './markup-section'; | ||
import LinkedList from '../utils/linked-list'; | ||
|
||
export const LIST_ITEM_TYPE = 'list-item'; | ||
|
||
export default class ListItem extends Section { | ||
constructor(tagName, markers=[]) { | ||
super(tagName); | ||
this.type = LIST_ITEM_TYPE; | ||
|
||
this.markers = new LinkedList({ | ||
adoptItem: m => m.section = m.parent = this, | ||
freeItem: m => m.section = m.parent = null | ||
}); | ||
|
||
markers.forEach(m => this.markers.append(m)); | ||
} | ||
|
||
splitAtMarker(marker, offset=0) { | ||
// FIXME need to check if we are goign to split into two list items | ||
// or a list item and a new markup section: | ||
const isLastItem = !this.next; | ||
const createNewSection = | ||
(marker.isEmpty && offset === 0) && isLastItem; | ||
|
||
// FIXME splitAtMarker for listItem duplicates its superclass logic | ||
let [beforeSection, afterSection] = [ | ||
this.builder.createListItem(), | ||
createNewSection ? this.builder.createMarkupSection('p') : this.builder.createListItem() | ||
]; | ||
|
||
// for the postEditor to know how to `insertBefore` these sections, | ||
// they must have a parent specified | ||
beforeSection.parent = this.parent; | ||
afterSection.parent = createNewSection ? this.parent.parent : // the post | ||
this.parent; // the list section | ||
|
||
return this._redistributeMarkers(beforeSection, afterSection, marker, offset); | ||
} | ||
|
||
splitIntoSections() { | ||
return this.parent.splitAtListItem(this); | ||
} | ||
|
||
clone() { | ||
const item = this.builder.createListItem(); | ||
this.markers.forEach(m => item.markers.append(m.clone())); | ||
return item; | ||
} | ||
} | ||
|
Oops, something went wrong.