dome-embedded-app-sdk
Version:
Build Dome cards and document viewers with a single SDK. Cards let you extend a dome with custom functionality, while viewers let you render and edit documents inside Dome.
51 lines (38 loc) • 1.3 kB
Markdown
# Viewer SDK Guide
The Viewer SDK lets you build custom viewers/editors for documents inside Dome.
## Install
```bash
npm install dome-embedded-app-sdk
```
## Initialize
```JavaScript
import { ViewerSdk } from "dome-embedded-app-sdk";
ViewerSdk.init({
onInitialData: ({ doc, ui }) => {
console.debug("Initial data", doc, ui);
},
onDataChange: ({ doc }) => {
console.debug("Doc changed", doc);
},
onCloseRequest: () => {
console.debug("Close requested");
},
onSaveRequest: () => {
console.debug("Save requested");
}
});
```
## Events
- `onInitialData({ doc, ui, isNewFile, perms, config })`: Initial payload for the viewer.
- `onDataChange({ doc, perms, userConsent })`: Updates when the document changes.
- `onCloseRequest()`: Parent requests close.
- `onSaveRequest()`: Parent requests save.
## Permissions
- `canRead(perms)`: Returns true if read is allowed.
- `canWrite(perms)`: Returns true if write is allowed.
## Viewer actions
- `requestInitialData()`: Ask the host to resend initial data.
- `requestSave(doc, isDataDirty)`: Ask the host to save and return a status promise.
- `setDirty(isDirty)`: Notify the host about dirty state.
- `sendClose(doc, isDataDirty)`: Notify the host to close.
- `sendException(error)`: Report an exception to the host.