Creates a new editor with a new, empty document.
Options that configure the new editor's features.
Sets or gets the caret position.
Returns whether the document is currently in the middle of an edit operation. This is true, for example, when a compound edit has begun but not yet ended. Example:
editor.beginCompoundEdit();
try {
console.log(editor.inCompoundEdit); // true
} finally {
editor.endCompoundEdit();
}
Provides access to the document's metadata, such as its title and memory cell contents.
Sets or gets whether the user can change the editor's content. When false, commands that modify the document will not be applicable: canApply will return false for them and they will have no effect if applied. This does not prevent the document from being modified directly: for example, the document can be replaced by setting the value property.
Sets or gets the selection range. Setting this to null will clear the selection, if any. If the selection is set to a range that does not contain the caret position, the caret will be moved to the end of the selection.
Returns a token that changes to a different unique value each time the document is edited, the caret is moved, or the selection changes. Compound edits count as a single combined state change, the the token changes as soon as the edit begins. Changes to the document metadata do not affect the state token. The state token can be used to determine whether a previously validated action still applies. For example, if an Action requires an asynchronous step, such as awaiting data from a server, an implementation can compare the state token value from when the action was approved to the state token value after the data is received. If they are different, the action should either be revalidated or cancelled.
Sets or gets the content of the editor. Setting this to null
replaces the content with a new, empty document. This property accepts and returns strings in the Math I Can Do document format.
Adds a listener for the specified type of event.
A string naming the event type. For example, the "change"
type is used to listen for document modifications.
The event listener to call when the event occurs.
Applies the specified command if possible.
The name of the command.
True if the command could be applied.
Begins a compound edit operation that lasts until endCompoundEdit is called. Changes to the document made between these calls, such as by applying commands, are combined into a single macro edit. Views will not update until the edit is completed, and the entire macro edit will form a single entry in the edit history. This call can be nested; the compound edit will not be complete until a matching number of calls are made to endCompoundEdit.
Returns whether the specified command can currently be applied.
The name of the command.
True if the command could be applied.
Returns whether there is an edit in the edit history that can be redone.
Returns true if redo is possible.
Returns whether there is an edit in the edit history that can be undone.
Returns true if undo is possible.
Clears the current selection, if any.
Downloads an image of the document content asynchronously. If a title is set in the document metadata, it will be used for the download's file name if possible. Image conversion may fail if the content is so large that it exceeds reasonable limits on image size or memory use.
If true, uses the selection instead of the whole document if possible.
Options that control the image format and features.
Ends a compound edit operation started by a previous beginCompoundEdit. Because compound edits nest, it is vital that calls to this method are placed in a finally
clause to ensure that "begins" and "ends" are always executed in pairs. Otherwise, an error during the compound operation may result in the editor becoming unusable. Example:
editor.beginCompoundEdit();
try {
// ... edits ...
} finally {
editor.endCompoundEdit();
}
Replaces the content of this editor by converting the supplied semantic object into the internal document format.
The root of the semantic document structure.
An array, possibly empty, of any errors encountered during the import process.
Returns whether the editor has an active selection.
Returns true if content is selected in the editor.
Returns whether the editor has any content. If true, the document consists of a single empty line.
True if the document is empty.
Redoes an edit, if possible. Otherwise does nothing.
Removes a previously added listener for the specified type of event. This method does nothing if the listener was never added.
A string naming the event type.
The event listener to stop notifying when the event occurs.
Returns a Promise that resolves to an image representation of the document content. The form that the image takes depends on the container
property of the supplied options, if any. By default, the promise will resolve to a data URL for the image. It can also be supplied as a Blob, or, if the image format is SVG, as a string. Other options allow the caller to specify colours, size, margins, and other features.
Image conversion may fail if the content or scale causes the image to exceed reasonable limits on image size or memory use. Because the conversion process relies on the host platform's rendering capabilities, results will vary by device and browser.
If true, uses the selection instead of the whole document if possible.
Options that control the image format and features.
A Promise that resolves to a URL, Blob, or SVG document for the image.
Returns a Promise that resolves to a LaTeX representation of the document content.
If true, uses the selection instead of the whole document if possible.
Options that control the conversion.
A Promise that resolves to the converted string of LaTeX.
Returns a Promise that resolves to a MathML representation of the document content.
If true, uses the selection instead of the whole document if possible.
Options that affect the conversion.
A Promise that resolves to the converted string of MathML.
Converts the content of the editor into a semantic object, a high-level representation useful for processing and conversion.
The root of a semantic representation of the document.
Undoes an edit, if possible. Otherwise does nothing.
This API is still under development and is subject to change. Copyright © Math I Can Do Solutions Incorporated and/or its licensors.
Editors manage and manipulate math content, track the caret position and selection, support the execution of commands, and enable serialization and conversion of the content under their control.
Each editor is responsible for maintaining a model of its content, the math document. In order to ensure that the document remains consistent, it cannot be accessed or mutated directly. The most common way to manipulate the document model is by applying commands. To implement more complex operations, a Walker can be used to safely and efficiently examine or modify the document.
The editor also manages access to the document's metadata, a string map of key and value pairs that can be used to store both standard and user-defined keys as part of the document.
An editor does not include a user interface. To present the contents of an editor to the end user and/or allow them to edit its content, create a View for it.
Example: Create an editor, apply a command to it, and view the result