-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathedit-by-onlyoffice.ts
More file actions
30 lines (27 loc) · 1010 Bytes
/
edit-by-onlyoffice.ts
File metadata and controls
30 lines (27 loc) · 1010 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import { FileActionExtension } from '@osf/shared/tokens/file-action-extensions.token';
export interface OnlyOfficeConfig {
editorUrl: string;
}
const SUPPORTED_EXTENSIONS = /\.(docx?|xlsx?|pptx?|odt|ods|odp)$/i;
/**
* Factory function for Edit by OnlyOffice action extension.
* Adds "Edit by OnlyOffice" option to file context menu.
*
* NOTE: This is a dummy implementation for demonstration purposes.
* The actual OnlyOffice integration requires a running OnlyOffice Document Server.
*/
export function editByOnlyOfficeExtensionFactory(config: OnlyOfficeConfig): FileActionExtension[] {
return [
{
id: 'edit-onlyoffice',
label: 'Edit by OnlyOffice',
icon: 'fas fa-edit',
command: (ctx) => {
const editorUrl = `${config.editorUrl}?fileId=${ctx.target.id}`;
window.open(editorUrl, '_blank');
},
position: 'start',
visible: (ctx) => ctx.target.kind === 'file' && ctx.canWrite && SUPPORTED_EXTENSIONS.test(ctx.target.name),
},
];
}