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

# Editor actions

Functions over `EditorModel` that a menu or ribbon calls: clipboard, links, bookmarks, notes, headers and footers, files and passwords. Guide: [Build your own skin](https://docs.reducto.ai/office/docx/ui/custom-skin.md).

## `runClipboard()`

```ts theme={null}
function runClipboard(
  model: EditorModel,
  kind: "cut" | "copy" | "paste",
  mode?: PasteMode,
): void | Promise<void>
```

Cut, Copy or Paste as a menu button does it: the browser's clipboard, with a hint when it is blocked.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `PasteMode`

Word's paste options: `keep` the source formatting (colour, size, face, headings,
alignment and lists), `merge` into the destination's (bold, italic, underline and
strike survive), or `text` only.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

```ts theme={null}
type PasteMode = "keep" | "merge" | "text"
```

## `openLinkDialog()`

```ts theme={null}
function openLinkDialog(model: EditorModel): void
```

Word's Ctrl+K: edit the link under the caret, or make one over the selection.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `selectTablePart()`

```ts theme={null}
function selectTablePart(model: EditorModel, part: TablePart): boolean
```

Word's Table Layout > Select: the caret's cell, row, column or table as a cell selection.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `TablePart`

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

```ts theme={null}
type TablePart = "cell" | "row" | "column" | "table"
```

## `addBookmark()`

```ts theme={null}
function addBookmark(model: EditorModel, name: string): Promise<void>
```

Add over the selection, out of any header or note; a name in use moves here.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `bookmarksOf()`

```ts theme={null}
function bookmarksOf(
  model: EditorModel,
  options?: { hidden?: boolean; sort?: "name" | "location" },
): EditorBookmark[]
```

Body bookmarks; Word's dialog lists hidden ones only when asked, sorted by name or by location.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `deleteBookmark()`

```ts theme={null}
function deleteBookmark(model: EditorModel, name: string): Promise<void>
```

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `goToBookmark()`

```ts theme={null}
function goToBookmark(model: EditorModel, name: string): boolean
```

Select what a bookmark spans, as Word's Go To does; false when no bookmark has the name.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `showNotes()`

```ts theme={null}
function showNotes(model: EditorModel): boolean
```

From a note, back to its mark; from the body, into the first note at or after the caret.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `stepNote()`

```ts theme={null}
function stepNote(
  model: EditorModel,
  kind: "footnote" | "endnote",
  delta: -1 | 1,
): boolean
```

The next (+1) or previous (-1) note mark of a kind from the caret; false when there is none.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `headerFooterInView()`

```ts theme={null}
function headerFooterInView(model: EditorModel): HeaderFooterInView | undefined
```

"First Page Header -Section 2-", as Word labels the band; undefined outside a header or footer.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `HeaderFooterInView`

The header or footer being edited, with the label Word shows on its band.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

```ts theme={null}
type HeaderFooterInView = HeaderFooterSlot & { label: string }
```

## `stepHeaderFooter()`

```ts theme={null}
function stepHeaderFooter(model: EditorModel, step: -1 | 1): boolean
```

Word's Previous / Next: the nearest page in that direction that shows another one of this kind.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `linkToPrevious()`

```ts theme={null}
function linkToPrevious(model: EditorModel, linked: boolean): Promise<boolean>
```

Word's Link to Previous for the header or footer being edited; the caret stays on its page.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `removeHeaderFooter()`

```ts theme={null}
function removeHeaderFooter(
  model: EditorModel,
  kind: "header" | "footer",
): Promise<boolean>
```

Word's Remove Header / Remove Footer: the one the caret's page shows is emptied to a single
paragraph; the other first-page, even and odd ones stay. False when that page shows none.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `insertTextFromFile()`

```ts theme={null}
function insertTextFromFile(model: EditorModel, file: Blob): Promise<void>
```

Insert > Object > Text from File: a whole .docx lands at the caret as one paste, styles and pictures with it.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `imageFileFrom()`

```ts theme={null}
function imageFileFrom(data: DataTransfer | null | undefined): File | null
```

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `caretPageOf()`

```ts theme={null}
function caretPageOf(ir: LayoutDocument, selection: Selection | null): number
```

The 0-based page the selection's focus sits on.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `editorPaletteCommands()`

```ts theme={null}
function editorPaletteCommands(model: EditorModel): PaletteCommand[]
```

Every palette row the editor can service right now: the context-menu leaves
(clipboard, links, breaks, review threads, picture wrap) plus the full
formatting tree. Menu branches the tree already covers are skipped.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `peerColor()`

```ts theme={null}
function peerColor(name: string): string
```

One colour per name, the same in every tab.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `isEncryptedDocx()`

```ts theme={null}
function isEncryptedDocx(bytes: Uint8Array): boolean
```

True when the bytes are an Office password-to-open container, not a zip.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`, `@reductoai/docx/browser`.

## `decryptDocx()`

```ts theme={null}
function decryptDocx(bytes: Uint8Array, password: string): Uint8Array
```

The .docx bytes of a password-to-open file; throws DocxPasswordError on a wrong password.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`, `@reductoai/docx/browser`.

## `encryptDocx()`

```ts theme={null}
function encryptDocx(bytes: Uint8Array, password: string): Uint8Array
```

The .docx bytes inside Word's password-to-open container, as Word 2010+ writes it.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`, `@reductoai/docx/browser`.

## `modifyPasswordMatches()`

```ts theme={null}
function modifyPasswordMatches(
  protection: WriteProtection | undefined,
  password: string,
): boolean
```

True when `password` is the password to modify; a hash Word 16 would not write never matches.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `DocxPasswordError`

A password that does not open the file, or a file that is not an encrypted package.

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`, `@reductoai/docx/browser`.

### DocxPasswordError properties

| Name | Type | Description |
| - | - | - |
| `stackTraceLimit` | `number` | static The `Error.stackTraceLimit` property specifies the number of stack frames collected by a stack trace (whether generated by `new Error().stack` or `Error.captureStackTrace(obj)`). The default value is `10` but may be set to any valid JavaScript number. Changes will affect any stack trace captured *after* the value has been changed. If set to a non-number value, or set to a negative number, stack traces will not capture any frames. |
| `cause?` | `unknown` | |
| `message` | `string` | |
| `name` | `string` | |
| `stack?` | `string` | |

### `DocxPasswordError.captureStackTrace()`

```ts theme={null}
static captureStackTrace(targetObject: object, constructorOpt?: Function): void
```

Creates a `.stack` property on `targetObject`, which when accessed returns
a string representing the location in the code at which
`Error.captureStackTrace()` was called.

```js theme={null}
const myObject = {};
Error.captureStackTrace(myObject);
myObject.stack;  // Similar to `new Error().stack`
```

The first line of the trace will be prefixed with
`${myObject.name}: ${myObject.message}`.

The optional `constructorOpt` argument accepts a function. If given, all frames
above `constructorOpt`, including `constructorOpt`, will be omitted from the
generated stack trace.

The `constructorOpt` argument is useful for hiding implementation
details of error generation from the user. For instance:

```js theme={null}
function a() {
  b();
}

function b() {
  c();
}

function c() {
  // Create an error without stack trace to avoid calculating the stack trace twice.
  const { stackTraceLimit } = Error;
  Error.stackTraceLimit = 0;
  const error = new Error();
  Error.stackTraceLimit = stackTraceLimit;

  // Capture the stack trace above function b
  Error.captureStackTrace(error, b); // Neither function c, nor b is included in the stack trace
  throw error;
}

a();
```

### `DocxPasswordError.prepareStackTrace()`

```ts theme={null}
static prepareStackTrace(err: Error, stackTraces: CallSite[]): any
```

See [https://v8.dev/docs/stack-trace-api#customizing-stack-traces](https://v8.dev/docs/stack-trace-api#customizing-stack-traces)

## `DOCX_MIME`

```ts theme={null}
const DOCX_MIME: "application/vnd.openxmlformats-officedocument.wordprocessingml.document" = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
```

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.

## `PDF_MIME`

```ts theme={null}
const PDF_MIME: "application/pdf" = "application/pdf"
```

Import from `@reductoai/docx-editor`, `@reductoai/docx-editor/model`.
