# UnifiedWriter Control Variants and Host Integration Standard (v5.65.0)

UnifiedWriter is a reusable file-processing Control package. It does not define an application by itself. The application concept belongs to the Host layer, such as OneEditor, OneViewer, a Desktop-style Host, or a normal business web page.

## Control variants

v5.65.0 keeps the v5.64.2 decision that removes `ViewerControl` as an official separate Control. The same `EditorControl` body is used in either edit mode or view/read-only mode.

| Control | Responsibility | Typical Host |
|---|---|---|
| EditorControl | Body Control. Owns DocumentModel, Selection, CommandRegistry, Undo/Redo and file/document commands. Supports `mode: "edit"` and `mode: "view"`. | OneEditor uses edit mode. OneViewer uses view mode. |
| WorkbenchControl | Reusable shell that composes EditorControl with optional menu bar, toolbar, panes and status bar. | Standalone demo, embedded web page, simple Host |

WorkbenchControl is not an app. It is a Control surface that can be used standalone or embedded in a web system page. Menu, toolbar and pane visibility must be parameter-driven.

## EditorControl modes

| Mode | Purpose | Command contribution policy |
|---|---|---|
| `edit` | Full editing body for OneEditor | File commands, Edit, View, Insert, Format/書式, Review, Tools and contextual commands |
| `view` | Read-only body for OneViewer | Storage-neutral file open/export/print/properties, View, Find/Search, Outline and other read-only commands only |

`ViewerControl` is no longer required because `EditorControl({ mode: "view" })` provides the read-only body and read-only command subset.

## Menu and command ownership

UnifiedWriter owns file-format-specific File commands/capabilities. WorkbenchControl may render File and Help menus for standalone or page-embedded use. OneEditor / OneViewer may instead own the global File and Help menu UI as a specific integration profile and delegate file-type-specific operations to the active package.

| Menu / command area | UI owner | Command/capability owner |
|---|---|---|
| File menu UI | WorkbenchControl or integrated Host profile | Workbench calls writer.file.* directly; OneEditor/OneViewer routes to active package after file type is resolved |
| New / Open flow | Workbench or integrated Host profile | Active package provides `writer.file.newDocument` / `writer.file.openPackage`; OneEditor decides file type before package loading |
| Save / Save As / Export | Workbench or integrated Host profile; save target via callback/adapter | Active package creates package/export Blob through `writer.file.*` |
| Print | Host / Workbench UI | Active package provides print target through `writer.file.printContent` |
| Help menu UI | Host / Workbench shell | Control may provide help/diagnostic items for Host to render |
| Edit | Host renders contribution | EditorControl contribution; view mode exposes only read-only items such as Find |
| View | Host + Control contribution | EditorControl contribution |
| Insert | Host renders contribution | EditorControl edit mode contribution |
| Format / 書式 | Host renders contribution | EditorControl edit mode contribution |
| Tools | Host + Control contribution | EditorControl contribution; view mode is read-only only |
| Review | Host renders contribution | EditorControl edit mode contribution |

The active surface decides where file-open, save, save-as and export UI appears. WorkbenchControl can render the package File menu; an integrated Host can hide that menu and delegate from Host UI. The storage provider is still selected through callback/adapter injection. UnifiedWriter still exposes `writer.file.*` commands and Import/Export capabilities because only the package knows how to create, parse, serialize, export, print and inspect its own document model.

## Public creation APIs

```javascript
UnifiedWriter.createEditorControl({
  container: '#frame',
  mode: 'edit',
  OpenFile: hostOpenFile,
  SaveFile: hostSaveFile
});

UnifiedWriter.createEditorControl({
  container: '#frame',
  mode: 'view'
});

UnifiedWriter.createWorkbenchControl({
  container: '#writerPage',
  mode: 'edit',
  showMenuBar: true,
  showToolbar: true,
  menuVisibility: {
    file: false,
    help: false,
    edit: true,
    view: true,
    insert: true,
    format: true,
    tools: true,
    development: true
  }
});
```

`createViewerControl()` may remain as a compatibility alias during transition, but it returns an EditorControl-compatible API in `mode: "view"`. New Host integrations should not depend on a separate ViewerControl concept.

## Contribution APIs

EditorControl exposes declarative metadata that WorkbenchControl, OneEditor / OneViewer, or another Host surface can compose into its own menu and toolbar surfaces.

```javascript
control.getCommandRegistry();        // mode-sensitive writer.file.* and document commands
control.getMenuContributions();      // edit/view filtered menu contributions
control.getToolbarContributions();   // edit/view filtered toolbar contributions
control.getContextMenuContributions();
control.getImportCapabilities();
control.getExportCapabilities();
control.executeCommand('writer.format.bold');
```

Menus and toolbars are UI only. The command system belongs to EditorControl. WorkbenchControl only renders shell UI around EditorControl and dispatches command IDs to it.

## v5.66.0 implementation file mapping

The Control variant policy is now reflected in concrete files:

| Control | File | Base | Notes |
|---|---|---|---|
| EditorControl | `scripts/controls/editor_control.js` | `UnifiedControl.Control` | Public body Control for edit and view/readOnly mode. |
| WorkbenchControl | `scripts/controls/workbench_control.js` | `UnifiedControl.Control` through `EditorControl` | Composite surface with package MenuBar / Toolbar / panes / status bar. |
| LegacyRuntime | `scripts/controls/legacy_runtime.js` | internal bridge | Bridges the existing model-first jQuery editor runtime. Host code must not call it directly. |

`UnifiedControl` is a required peer package supplied by Host/Demo RequireJS alias. It is not bundled or copied under UnifiedWriter.
