# Embed the workspace

Mount a file in your page and connect its lifecycle, templates and business drafts to your system.

## Run the repository example

In a workspace with access to QuireKit OFD Editor, use the repository's Node 22 and pnpm versions. The following starts the editor at `http://127.0.0.1:8998/`. The application entry is supplied through the commercial workspace.

```sh
pnpm install
pnpm --filter @quirekit/ofd-editor-demo dev
```

## Mount into a page

Give the host an empty element with a defined height. The browser entry uses Vue, Vite and UnoCSS. Use the QuireKit preset and source-scanning configuration from the preview application. Call `mountFile(element, file)` once the DOM exists, then call the returned cleanup when removing the element or leaving the route. With SSR, load this module during client mount.

### recipes/mount.ts

```ts
import { Editor, type OFDEditorOptions } from "@quirekit/ofd-editor";

/**
 * Opens an authorized file in a host element and gives its owner a teardown function.
 * @param target - Empty element sized by the host.
 * @param file - File chosen by the user.
 * @param options - Host services and session observer.
 * @returns Cleanup to run when leaving the document or removing the element.
 */
export function mountFile(target: HTMLElement, file: File, options: OFDEditorOptions = {}): () => void {
  const editor = new Editor({
    ...options,
    initialDocument: {
      name: file.name,
      /** @param signal - Cancelled when the host leaves the file. @returns The selected file bytes. */
      async read(signal) {
        signal.throwIfAborted();
        const bytes = new Uint8Array(await file.arrayBuffer());
        signal.throwIfAborted();
        return bytes;
      },
    },
  }).mount(target);
  return () => editor.destroy();
}

```

`initialDocument.read(signal)` can also fetch bytes through your existing authenticated transport. Respect cancellation when the document changes or the workspace closes. Omitting `initialDocument` starts a blank document. `onSessionChange` publishes the current `editor` and `view` and receives `undefined` on teardown.

## Connect host services

| Option | Host responsibility |
| --- | --- |
| `documentTemplates` / `templatePresets` | Writable versioned library and optional read-only catalog |
| `drafts` / `batch` / `sheetMappings` | Business records, bulk creation and shared column mappings |
| `printService` | Authorized queue and receipts |
| `loadSigning` / `licenseKey` | Signing service and seal sources, and the deployment license key |

Use the mounted session for template operations and `printDocument()`. The latter commits active text and field values before capturing a native print input. Configure `drafts` to write back to the business system. When `openBusinessDraft` returns `pending`, let the workspace resolve unsaved changes before treating the switch as complete. [Session API](/en/api) · [Workstation HTTP](/en/integration/http)
