# UnifiedWriter Integration

UnifiedWriter is a Host-embeddable AMD package. The package itself does not include any fixed internal HTTPS URL. Host code receives a Package Root URL and maps it to the `UnifiedWriter` RequireJS alias.

```js
var packageRootUrl = '<PackageRootUrl>';
require.config({
  paths: { 'UnifiedWriter': packageRootUrl + '/scripts' }
});
require(['UnifiedWriter/main'], function(UnifiedWriter) {
  var control = UnifiedWriter.createWorkbenchControl({
    container: '#target',
    language: 'ja',
    theme: 'light',
    OpenFile: hostOpenFile,
    SaveFile: hostSaveFile
  });
});
```

## Control choices

```js
// Body-only editor surface for OneEditor-like integrated Hosts.
UnifiedWriter.createEditorControl({ container:'#frame', mode:'edit', hostProfile:'oneEditor' });

// Body-only read-only surface for OneViewer-like integrated Hosts.
UnifiedWriter.createEditorControl({ container:'#frame', mode:'view', readOnly:true, hostProfile:'oneViewer' });

// Composite package surface for standalone or page-embedded usage.
UnifiedWriter.createWorkbenchControl({ container:'#frame', mode:'edit', showMenuBar:true, showToolbar:true });
```

## File menu ownership

UnifiedWriter keeps package-owned storage-neutral File commands under `writer.file.*`. WorkbenchControl may render a package File menu and call those commands directly.

OneEditor / OneViewer may use a different integration profile: hide the Workbench File menu, render Host File UI, and delegate to `writer.file.*` commands after New/Open determines the active file type. This profile is not a universal rule for every Host.

## Contribution APIs

```js
var commands = control.getCommandRegistry({ mode:'edit' });
var menus = control.getMenuContributions({ mode:'edit', surface:'oneEditor' });
var toolbars = control.getToolbarContributions({ mode:'edit', surface:'oneEditor' });
var files = control.getFileCapabilities();
```

## v5.66.3 UnifiedControl Framework dependency

UnifiedWriter now requires the common UnifiedControl Framework as a peer AMD package.  The Host or Demo must configure both RequireJS aliases before loading `UnifiedWriter/main`.

```javascript
require.config({
  paths: {
    'UnifiedControl': 'https://cdn.skylarkjs.com/itoolkits/developments/UnifiedControl/scripts',
    'UnifiedWriter': '<UnifiedWriter package root>/scripts'
  }
});
```

The application ZIP does not contain a copy of UnifiedControl.  The dependency is declared in `PACKAGE_MANIFEST.json` as `requiredPackages.UnifiedControl` with API range `>=0.7 <1.0`.

The public Control classes are:

- `UnifiedWriter.EditorControl` from `scripts/controls/editor_control.js`
- `UnifiedWriter.WorkbenchControl` from `scripts/controls/workbench_control.js`

Both inherit `UnifiedControl.Control`.  Factories remain the recommended entry point:

```javascript
var editor = UnifiedWriter.createEditorControl({ container:'#frame', mode:'edit' });
var viewer = UnifiedWriter.createEditorControl({ container:'#frame', mode:'view', readOnly:true });
var workbench = UnifiedWriter.createWorkbenchControl({ container:'#frame', showMenuBar:true });
```

`createViewerControl()` is retained only as a compatibility alias for older callers.


## v5.66.3 UnifiedControl direct base Control import
UnifiedWriter still treats UnifiedControl as a peer package referenced by package root URL and does not copy it into the Writer ZIP. To avoid loading optional UnifiedControl Content/Designer modules during app boot, EditorControl imports the required base class from `UnifiedControl/controls/control` rather than `UnifiedControl/main`. Host/Demo RequireJS aliases remain the same: `UnifiedControl` points to `<UnifiedControl package root>/scripts` and `UnifiedWriter` points to `<UnifiedWriter package root>/scripts`.


## v5.67.0 CSS / Theme / Manifest loading

Host shells must read `PACKAGE_MANIFEST.json`, load `styles.required`, then load the selected `styles.themes[theme]` before mounting the Control. The root class is `.uwriter`, and package CSS is delivered as `themes/base/unified_writer.css` plus optional theme CSS.

## v5.67.0 Programable file API

OneEditor / OneViewer / Host code should use `EditorControl.openFile(payload, context)`, `saveFile(payload, context)`, `saveAsFile(payload, context)`, and `exportFile(payload, context)` for direct file payload operations. `OpenFile` / `SaveFile` remain Host callbacks used by WorkbenchControl and commands.
