Class: ImageEditor

ImageEditor()

Creates an Image Editor component.

This class bootstraps all the necessary parts of an image editor. It only controls the state and history of the editing process, orchestrating how the different parts of the application work.

All image processing is delegated to the different image editor capability implementations. The editor provides

  • A common way of exposing the functionality.
  • Some registration points which can be used by the image editor capability implementors to provide UI controls.

Constructor

new ImageEditor()

Source:

Members

(static, non-null) STATE :Object

State definition.
Type:
  • Object
Source:

(protected) history_ :Array.<Object>

History of the different image states during editing. Every entry represents a change to the image on top of the previous one. History entries are objects with the following attributes:
  • url (optional): the URL representing the image.
  • data: the image data object of the image.
Type:
  • Array.<Object>
Source:

Methods

accept()

Accepts the current changes applied by the active control and creates a new entry in the history stack. This wipes out any stale redo states.
Source:

attached()

Source:

(protected) close_()

Notifies the opener app that the user wants to close the editor without saving the changes.
Source:

(protected) createHistoryEntry_(imageData)

Creates a new history entry state.
Parameters:
Name Type Description
imageData ImageData The image data of the new image.
Source:

discard()

Discards the current changes applied by the active control and reverts the image to its state before the control activation.
Source:

getImageEditorCanvas() → {Element}

Retrieves the editor canvas DOM node.
Source:
Returns:
The canvas element
Type
Element

getImageEditorImageBlob() → {Promise}

Retrieves the blob representation of the current image.
Source:
Returns:
A promise that resolves with the image blob.
Type
Promise

getImageEditorImageData() → {Promise}

Retrieves the image data representation of the current image.
Source:
Returns:
A promise that resolves with the image data.
Type
Promise

getPossibleControls() → {Array.<{Object}>}

Returns a list of all possible image editor capabilities.
Source:
Returns:
Type
Array.<{Object}>

normalizeCanvasMimeType_(mimeType) → {String}

Normalizes different MIME types to the most similar MIME type available to canvas implementations.
Parameters:
Name Type Description
mimeType String The original MIME type.
Source:
See:
Returns:
The normalized MIME type.
Type
String

(protected) notifySaveResult_(result)

Notifies the opener app of the result of the save action.
Parameters:
Name Type Description
result Object The server response to the save action.
Source:

redo()

Updates the image back to a previously undone state in the history. Redoing an action recovers the undone image changes and enables the undo stack in case the user wants to undo the changes again.
Source:

requestImageEditorEdit(event)

Select a control and starts its editing phase.
Parameters:
Name Type Description
event MouseEvent The mouse event.
Source:

requestImageEditorEditFilters(event)

Selects a control and starts its editing phase with filters.
Parameters:
Name Type Description
event MouseEvent The mouse event.
Source:

requestImageEditorPreview()

Queues a request for a preview process of the current image by the currently selected control.
Source:

reset()

Discards all changes and restores the original state of the image. Unlike the undo and redo methods, this method wipes out the entire history.
Source:

(protected) save_(event)

Tries to save the current image using the provided save URL.
Parameters:
Name Type Description
event MouseEvent The mouse event that triggers the save action.
Source:

(protected) setterSaveMimeTypeFn_(saveMimeTypenon-null) → {String}

Setter function for the saveMimeType state key.
Parameters:
Name Type Description
saveMimeType String The optional value for the attribute.
Source:
Returns:
The computed value for the attribute.
Type
String

(protected) showError_(message)

Displays an error message in the editor.
Parameters:
Name Type Description
message String The error message to display.
Source:

(protected) submitBlob_(imageBlob) → {Promise}

Sends a given image blob to the server for processing and storing.
Parameters:
Name Type Description
imageBlob Blob The image blob to send to the server.
Source:
Returns:
A promise that follows the XHR submission process.
Type
Promise

(protected) syncHistory_()

Syncs the image and history values after changes to the history stack.
Source:

(protected) syncImageData_(imageData)

Updates the image data displayed in the editable area.
Parameters:
Name Type Description
imageData ImageData The new image data value to display in the editor.
Source:

undo()

Reverts the image to the previous state in the history. Undoing an action brings back the previous version of the image and enables the redo stack in case the user wants to reapply the change again.
Source: