Replies: 1 comment
|
yeah, their documentation on here and the website is abysmal. I haven't found their react documentation helpful at all, the examples are too simplistic. anyway, @googmiss, here is a simple example of how I got the connector working (in react typescript app): I dont use any imports from OnlyOffice - rather, you need to create type interfaces to match the DocumentEditor APi, connector API, and other types and it just works. Obviously you need to have a backend handling the callbacks and sending an editor config json payload matching the spec shown in the documentation Type interfaces: /**
* OnlyOffice DocEditor instance returned by DocsAPI.DocEditor constructor
*/
export interface DocEditorInstance {
createConnector: () => ConnectorInstance;
destroyEditor: () => void;
downloadAs: (format?: string) => void;
// add other method interfaces as needed, like 'setUsers'
}
/**
* Connector API instance for 2-way communication (Developer Edition only)
* @see https://api.onlyoffice.com/docs/docs-api/usage-api/automation-api/
*/
export interface ConnectorInstance {
/**
* Execute a Document Builder script command
* @param command - Function containing Document Builder API calls
* @param recalculate - Whether to recalculate the document after execution
* @param isAsync - Whether to execute asynchronously
* @param callback - Callback function to receive the result
* @param args - Arguments to pass to the command function
*/
callCommand: (
command: (...args: unknown[]) => unknown,
recalculate?: boolean,
isAsync?: boolean,
callback?: (result: unknown) => void,
args?: unknown[]
) => void;
/**
* Execute a specific editor method
* @param method - Method name to execute
* @param args - Arguments to pass to the method
* @param callback - Callback function to receive the result
*/
executeMethod: (
method: string,
args: unknown[],
callback?: (result: unknown) => void
) => void;
/**
* Attach an event listener
* @param eventName - Name of the event to listen for
* @param callback - Callback function to handle the event
*/
attachEvent: (
eventName: string,
callback: (data: unknown) => void
) => void;
/**
* Detach an event listener
* @param eventName - Name of the event to stop listening for
*/
detachEvent: (eventName: string) => void;
/**
* Add custom context menu items
*/
addContextMenuItem: (items: ContextMenuItem[]) => void;
/**
* Update an existing context menu item
* @param id - ID of the menu item to update
* @param options - Options to update (disabled, text, icon)
* @returns void
*/
updateContextMenuItem: (id: string, options: { disabled?: boolean; text?: string; icon?: string }) => void;
/**
* Add custom toolbar menu items.
* Accepts either a flat array (legacy) or a tab-based structure that can add multiple custom tabs to the top ribbon tabs.
*/
addToolbarMenuItem: (items: ToolbarMenuItem[] | ToolbarMenuMainItem) => void;
/**
* Connect to the editor (if previously disconnected)
*/
connect: () => void;
/**
* Disconnect from the editor
*/
disconnect: () => void;
}
/**
* Context menu item configuration
* options: https://github.com/ONLYOFFICE/api.onlyoffice.com/blob/4e9cb59929e64ea1a3389ace2b98cab081992c24/site/docs/docs-api/usage-api/automation-api.md?plain=1#L33
*/
export interface ContextMenuItem {
id: string; // id of the menu item, which is used when calling `updateContextMenuItem' to update visibility of the item later
text: string; // item caption (displayed title of item)
icons?: string; // optional icon(s), must be in assets folder in subfolder for current theme (e.g., /custom-editor-plugin/resources/light/)
disabled?: boolean; // whether disabled. if disabled, item is greyed out and not clickable but still shown in ribbon menu
onClick?: (id: string) => void; //The click event callback.
/**
* Array of child items for submenus. i items are provided, the parent item shows a submenu containing the specified child items, rather than acting as a button. If no items are provided, this (the parent item) will be a regular clickable item (or disabled if disabled=true
*/
items?: ContextMenuItem[];
}usage |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
output event:
attachMouseEvents
blurFocus
createEmbedWorker
denyEditingRights
destroyEditor
detachMouseEvents
downloadAs
grabFocus
insertImage
openDocument
processMailMerge
processRightsChange
processSaveResult
refreshHistory
requestClose
serviceCommand
setActionLink
setEmailAddresses
setFavorite
setHistoryData
setMailMergeRecipients
setReferenceData
setReferenceSource
setRequestedDocument
setRequestedSpreadsheet
setRevisedFile
setSharingSettings
setUsers
showMessage
showSharingSettings
startFilling
For example, I use the DocumentEditor component. In onAppReady, I find that there is no createConnector method. Could you please tell me how to create the connector
only office serve: v8.1
The deployment method of only office is docker
docker-compose.yml:
version: '3.3'
services:
onlyoffice:
image: onlyoffice/documentserver:8.1
container_name: onlyoffice
volumes:
ports:
environment:
restart: always
All reactions