# UnifiedWriter Programable File Payload API v5.67.0

This document records the implementation of the single-file processing policy v1.3.

## Direction separation

`OpenFile(request, context)` and `SaveFile(payload, context)` are callbacks from WorkbenchControl or package commands to the Host. They ask the Host to choose/read/write files.

`EditorControl.openFile(payload, context)`, `saveFile(payload, context)`, `saveAsFile(payload, context)`, and `exportFile(payload, context)` are Programable Editing Control APIs called by the Host, WorkbenchControl, OneEditor, or OneViewer to operate on an already-created EditorControl.

## HostFilePayload/v1

```js
control.openFile({
  payloadType: 'HostFilePayload/v1',
  operation: 'open',
  fileName: 'sample.uwpsx',
  mimeType: 'application/x-uwpsx+zip',
  file: file,          // or blob / arrayBuffer / text
  source: 'Host.Open'
}, context);
```

## HostSavePayload/v1

```js
const payload = await control.saveFile({
  payloadType: 'HostSavePayload/v1',
  operation: 'save',
  fileName: 'sample.uwpsx'
}, context);

await SaveFile(payload, context);
```

`payload.data` contains the generated Blob / ArrayBuffer / Text. The Host still owns destination selection and writing.

## Save / Save As / Export

- `saveFile()` uses the current file context by default.
- `saveAsFile()` uses `payload.fileName` or `payload.format` and only accepts writable formats.
- `exportFile()` generates external output and keeps the main file context unchanged.
- PDF export now supports a Blob payload through `exportPdfBlob()` when jsPDF and html2canvas are loaded.

## OneEditor / OneViewer

OneEditor should call `openFile()` after file type routing and call `saveFile()`, `saveAsFile()`, or `exportFile()` before passing the returned payload to its Host save adapter.

OneViewer should call `openFile()` for read-only display and may call `exportFile()` for download/print workflows.


## dev-5.67.2 Demo Local Disk Save update

Demo pages now implement Host-side Local Disk file selection for OpenFile / SaveFile callbacks.  On browsers with the File System Access API, Open uses `showOpenFilePicker()` and Save / Save As uses `showSaveFilePicker()` plus writable file handles.  `HostSavePayload/v1.payload.data` is the only write source.  FileSaver/download is kept only as an unsupported-browser fallback.
