Constructor
new Editor(optionsopt)
Parameters:
Name | Type | Attributes | Description | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
options |
Object |
<optional> |
Properties
|
- Source:
Members
activeMarkups :Array.<Markup>
Type:
- Array.<Markup>
- Source:
activeSections :Array.<Section>
The sections from the cursor's selection start to the selection end
Type:
- Array.<Section>
- Source:
builder :PostNodeBuilder
The editor's instance of a post node builder.
Type:
- Source:
range
Return the current range for the editor (may be cached). The #_resetRange method forces a re-read of the range from DOM.
- Source:
Methods
cursorDidChange(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | This callback will be called every time the cursor position (or selection) changes. |
- Source:
destroy()
Tears down the editor's attached event listeners and views.
- Source:
didRender(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | This callback will be called after the editor is rendered. |
- Source:
didUpdatePost(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Called with |
- Source:
disableEditing()
Keep the user from directly editing the post using the keyboard and mouse. Modification via the programmatic API is still permitted.
- Source:
- See:
disableLogging()
Disable all logging
- Source:
displayCard(cardSection)
Change a cardSection into display mode If called before the card has been rendered, it will be marked so that it is rendered in display mode when it gets rendered.
Parameters:
Name | Type | Description |
---|---|---|
cardSection |
CardSection |
- Source:
Returns:
undefined
editCard(cardSection)
Change a cardSection into edit mode If called before the card has been rendered, it will be marked so that it is rendered in edit mode when it gets rendered.
Parameters:
Name | Type | Description |
---|---|---|
cardSection |
CardSection |
- Source:
enableEditing()
Allow the user to directly interact with editing a post via keyboard and mouse input. Editor instances are editable by default. Use this method to re-enable editing after disabling it.
- Source:
- See:
enableLogging(logTypesopt)
Turns on verbose logging for the editor.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
logTypes |
Array |
<optional> |
[] | If present, only the given log types will be logged. |
- Source:
hasActiveMarkup(markup) → {boolean}
Parameters:
Name | Type | Description |
---|---|---|
markup |
Markup | String | A markup instance, or a string (e.g. "b") |
- Source:
Returns:
- Type
- boolean
hasCursor() → {boolean}
Whether the editor has a cursor (or a selected range). It is possible for the editor to be focused but not have a selection. In this case, key events will fire but the editor will not be able to determine a cursor position, so they will be ignored.
- Source:
Returns:
- Type
- boolean
inputModeDidChange(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Called when the editor's state (active markups or active sections) has changed, either via user input or programmatically |
- Source:
insertAtom(atomName, atomTextopt, atomPayloadopt)
Inserts an atom at the current cursor position. If the editor has no current cursor position, nothing will be inserted. If the editor's range is not collapsed, it will be deleted before insertion.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
atomName |
String | |||
atomText |
String |
<optional> |
'' | |
atomPayload |
Object |
<optional> |
{} |
- Source:
insertCard(cardName, cardPayloadopt, inEditModeopt)
Inserts a card at the section after the current cursor position. If the editor has no current cursor position, nothing will be inserted. If the editor's range is not collapsed, it will be deleted before insertion. If the cursor is in a blank section, it will be replaced with a card section. The editor's cursor will be placed at the end of the inserted card.
Parameters:
Name | Type | Attributes | Default | Description |
---|---|---|---|---|
cardName |
String | |||
cardPayload |
Object |
<optional> |
{} | |
inEditMode |
Boolean |
<optional> |
false | Whether the card should be inserted in edit mode. |
- Source:
insertText(text)
Inserts the text at the current cursor position. If the editor has no current cursor position, nothing will be inserted. If the editor's range is not collapsed, it will be deleted before insertion.
Parameters:
Name | Type | Description |
---|---|---|
text |
String |
- Source:
on()
- Deprecated:
- since 0.9.1
- Source:
onTextInput(inputHandler)
Register a handler that will be invoked by the editor after the user enters matching text.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
inputHandler |
Object |
Properties
|
- Source:
positionAtPoint(x, y) → {Position|null}
Parameters:
Name | Type | Description |
---|---|---|
x |
integer | x-position in viewport |
y |
integer | y-position in viewport |
- Source:
Returns:
- Type
- Position | null
postDidChange(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Called when the post has changed, either via user input or programmatically. Use with Editor#serialize to retrieve the post in portable mobiledoc format. |
- Source:
registerExpansion(expansion)
Prefer Editor#onTextInput to registerExpansion
.
Parameters:
Name | Type | Description | ||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
expansion |
Object |
Properties
|
- Deprecated:
- since v0.9.3
- Source:
registerKeyCommand(keyCommand)
Parameters:
Name | Type | Description |
---|---|---|
keyCommand |
Object | The key command to register. It must specify a
modifier key (meta, ctrl, etc), a string representing the ascii key, and
a |
- Source:
render(element)
Parameters:
Name | Type | Description |
---|---|---|
element |
Element | The DOM element to render into. Its contents will be replaced by the editor's rendered post. |
- Source:
run(callback) → {Mixed}
Run a new post editing session. Yields a block with a new PostEditor instance. This instance can be used to interact with the post abstract. Rendering will be deferred until after the callback is completed.
Usage:
let markerRange = this.range;
editor.run((postEditor) => {
postEditor.deleteRange(markerRange);
// editing surface not updated yet
postEditor.schedule(() => {
console.log('logs during rerender flush');
});
// logging not yet flushed
});
// editing surface now updated.
// logging now flushed
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | Called with an instance of PostEditor as its argument. |
- Source:
Returns:
The return value of callback
.
- Type
- Mixed
selectRange(range)
Selects the given range. If range is collapsed, this positions the cursor at the range's position, otherwise a selection is created in the editor surface.
Parameters:
Name | Type | Description |
---|---|---|
range |
Range |
- Source:
serialize(version) → {Mobiledoc}
Parameters:
Name | Type | Description |
---|---|---|
version |
String | The mobiledoc version to serialize to. |
- Source:
Returns:
Serialized mobiledoc
- Type
- Mobiledoc
serializeTo(format) → {Object|String}
Serialize the editor's post to the requested format. Note that only mobiledoc format is lossless. If cards or atoms are present in the post, the html and text formats will omit them in output because the editor does not have access to the html and text versions of the cards/atoms.
Parameters:
Name | Type | Description |
---|---|---|
format |
string | The format to serialize ('mobiledoc', 'text', 'html') |
- Source:
Returns:
The editor's post, serialized to {format}
- Type
- Object | String
toggleMarkup(markup)
Toggles the given markup at the editor's current Range. If the range is collapsed this changes the editor's state so that the next characters typed will be affected. If there is text selected (aka a non-collapsed range), the selections' markup will be toggled. If the editor is not focused and has no active range, nothing happens.
Parameters:
Name | Type | Description |
---|---|---|
markup |
String | E.g. "b", "em", "a" |
- Source:
- See:
toggleSection(tagName)
Toggles the tagName for the current active section(s). This will skip non-markerable sections. E.g. if the editor's range includes a "P" MarkupSection and a CardSection, only the MarkupSection will be toggled.
Parameters:
Name | Type | Description |
---|---|---|
tagName |
String | The new tagname to change to. |
- Source:
- See:
willRender(callback)
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | This callback will be called before the editor is rendered. |
- Source: