> ## Documentation Index
> Fetch the complete documentation index at: https://docs.embededitor.com/llms.txt
> Use this file to discover all available pages before exploring further.

# History and Output

> Undo, redo and reset, save, make the file Save would make, and close the editor from code.

These commands do what the toolbar's buttons do. Each follows [the rules of every command](https://docs.embededitor.com/api-reference/commands/overview.md#how-every-command-behaves).

The examples call the handle `editor`. See [Get the handle](https://docs.embededitor.com/api-reference/commands/overview.md#get-the-handle).

## History

```ts theme={"dark"}
history: {
	redo: () => Promise<null>;
	reset: () => Promise<null>;
	undo: () => Promise<null>;
};
```

### undo()

Takes the last step back, as Undo on the toolbar: a command's step or the user's. The image and the view go back to how they were before it. With nothing to undo, it changes nothing.

### redo()

Brings back the step undone last, as Redo on the toolbar. With nothing to redo, it changes nothing.

### reset()

Takes every edit away, as Reset on the toolbar, without its confirm. Like that button, it takes away a `state` the editor opened with too, and keeps the crop ratio `aspectRatio` sets or `aspectRatioLocked` holds. It is one step, so `undo` brings the edits back. With nothing to reset, it changes nothing.

```ts undo.ts theme={"dark"}
await editor.history.reset(); // every edit gone
await editor.history.undo(); // the edits back, as they were
```

## Output

```ts theme={"dark"}
output: {
	exportFile: (input?: { type?: 'image/jpeg' | 'image/png' | 'image/webp' }) => Promise<File>;
	save: () => Promise<{ dest: File; state: EditState }>;
};
```

### save()

Saves, as the Save button: the file and the state go to `onProcess` (or the file downloads, with no `onProcess`), the button shows its Saved moment, the `save` event fires, and `openEditor`'s modal closes.

It resolves to `{ dest, state }`, what `onProcess` gets. It rejects with the error `onProcessError` gets (`EXPORT_FAILED`, `MARK_FAILED`), or with `EXPORT_FAILED` when `onProcess` throws, your error as its `cause`. While a fixed or required mark is still loading, it waits for it, as the button does.

```ts save.ts theme={"dark"}
const { dest, state } = await editor.output.save();
```

### exportFile()

Makes the image as Save makes it (the output size and quality, the marks) and resolves to the `File`, without saving: nothing goes to `onProcess`, nothing downloads, and no event fires.

**type** `'image/jpeg' | 'image/png' | 'image/webp'` (default: Save's type)

The type written. Left out, Save's: `outputType`, or the source's.

It waits while a fixed or required mark is loading, rejects with `MARK_FAILED` when one can't be drawn, and with `EXPORT_FAILED` when the file can't be made. Use it for what Save doesn't do, such as copying or sharing the file yourself.

```ts export-file.ts theme={"dark"}
const file = await editor.output.exportFile({ type: 'image/jpeg' });
```

## Editor

```ts theme={"dark"}
editor: {
	close: () => Promise<null>;
};
```

### close()

Closes the editor, as its Close button. On `EmbedEditor` and `mountEditor`, it calls `onClose`, and rejects with `NOT_AVAILABLE` when there is none. On `openEditor`, it closes the modal, and the handle takes no more commands.

```ts close.ts theme={"dark"}
await editor.editor.close();
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.