-
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.
* Remove Marker#offsetInParent, add Markerable#offsetOfMarker * remove createBlankX methods from post node builder * Refactor List commands to work with embed intent * Test for inserting a list
- Loading branch information
Showing
18 changed files
with
304 additions
and
326 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,40 +1,36 @@ | ||
import TextFormatCommand from './text-format'; | ||
import { getSelectionBlockElement, selectNode, getSelectionTagName } from '../utils/selection-utils'; | ||
import { inherit } from 'content-kit-utils'; | ||
|
||
function ListCommand(options) { | ||
TextFormatCommand.call(this, options); | ||
} | ||
inherit(ListCommand, TextFormatCommand); | ||
|
||
ListCommand.prototype.exec = function() { | ||
ListCommand._super.prototype.exec.call(this); | ||
|
||
// After creation, lists need to be unwrapped | ||
// TODO: eventually can remove this when direct model manipulation is ready | ||
var listElement = getSelectionBlockElement(); | ||
var wrapperNode = listElement.parentNode; | ||
if (wrapperNode.firstChild === listElement) { | ||
var editorNode = wrapperNode.parentNode; | ||
editorNode.insertBefore(listElement, wrapperNode); | ||
editorNode.removeChild(wrapperNode); | ||
selectNode(listElement); | ||
export default class ListCommand extends TextFormatCommand { | ||
constructor(editor, options) { | ||
super(options); | ||
this.editor = editor; | ||
} | ||
|
||
isActive() { | ||
return false; | ||
} | ||
}; | ||
|
||
ListCommand.prototype.checkAutoFormat = function(node) { | ||
// Creates unordered lists when node starts with '- ' | ||
// or ordered list if node starts with '1. ' | ||
var regex = this.autoFormatRegex, text; | ||
if (node && regex) { | ||
text = node.textContent; | ||
if ('li' !== getSelectionTagName() && regex.test(text)) { | ||
this.exec(); | ||
window.getSelection().anchorNode.textContent = text.replace(regex, ''); | ||
return true; | ||
} | ||
|
||
exec() { | ||
const { editor } = this, | ||
{ cursor } = editor; | ||
|
||
const { head: {section:currentSection} } = cursor.offsets; | ||
|
||
const listItem = editor.run(postEditor => { | ||
const { builder } = postEditor; | ||
const tagName = this.tag; | ||
const listSection = builder.createListSection(tagName); | ||
const listItem = builder.createListItem(); | ||
listSection.items.append(listItem); | ||
|
||
postEditor.replaceSection(currentSection, listSection); | ||
return listItem; | ||
}); | ||
|
||
editor.cursor.moveToSection(listItem); | ||
} | ||
return false; | ||
}; | ||
|
||
export default ListCommand; | ||
unexec() { | ||
throw new Error('Cannot unexec a ListCommand'); | ||
} | ||
} |
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import ListCommand from './list'; | ||
import { inherit } from 'content-kit-utils'; | ||
|
||
function OrderedListCommand() { | ||
ListCommand.call(this, { | ||
name: 'ordered list', | ||
tag: 'ol', | ||
action: 'insertOrderedList' | ||
}); | ||
export default class UnorderedListCommand extends ListCommand { | ||
constructor(editor) { | ||
super(editor, { | ||
name: 'Ordered List', | ||
tag: 'ol', | ||
button: '<i>ol</i>' | ||
}); | ||
} | ||
} | ||
inherit(OrderedListCommand, ListCommand); | ||
|
||
OrderedListCommand.prototype.autoFormatRegex = /^1\.\s/; | ||
|
||
export default OrderedListCommand; |
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 |
---|---|---|
@@ -1,15 +1,11 @@ | ||
import ListCommand from './list'; | ||
import { inherit } from 'content-kit-utils'; | ||
|
||
function UnorderedListCommand() { | ||
ListCommand.call(this, { | ||
name: 'list', | ||
tag: 'ul', | ||
action: 'insertUnorderedList' | ||
}); | ||
export default class UnorderedListCommand extends ListCommand { | ||
constructor(editor) { | ||
super(editor, { | ||
name: 'Unordered List', | ||
tag: 'ul', | ||
button: '<i>ul</i>' | ||
}); | ||
} | ||
} | ||
inherit(UnorderedListCommand, ListCommand); | ||
|
||
UnorderedListCommand.prototype.autoFormatRegex = /^[-*]\s/; | ||
|
||
export default UnorderedListCommand; |
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
Oops, something went wrong.