-
Notifications
You must be signed in to change notification settings - Fork 159
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
docs: add documentation for viewer and editor apps (#10592)
* docs: add documentation for viewer and editor apps * docs: apply text suggestions from code review * docs: add referer to the new docs section * docs: refer to the web service docs for integration
- Loading branch information
1 parent
da4841a
commit e2deda3
Showing
2 changed files
with
122 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
--- | ||
title: 'Viewer and editor apps' | ||
date: 2024-03-12T00:00:00+00:00 | ||
weight: 60 | ||
geekdocRepo: https://github.com/owncloud/web | ||
geekdocEditPath: edit/master/docs/extension-system | ||
geekdocFilePath: viewer-editor-apps.md | ||
geekdocCollapseSection: true | ||
--- | ||
|
||
{{< toc >}} | ||
|
||
## Viewer and editor apps | ||
|
||
ownCloud Web allows developers to implement apps for viewing and editing specific file types. For instance, the built-in preview app serves as the default application for opening media files like images, videos, or audio. | ||
|
||
This section will guide you through the process of implementing such an app within ownCloud Web. | ||
|
||
### Basic app structure | ||
|
||
An app is essentially a distinct package that must be specified as an external application in the Web configuration. | ||
|
||
The structure of an app is quite simple and straightforward. Consider, for example, the [draw.io app](https://github.com/owncloud/web/tree/master/packages/web-app-draw-io). It consists of a `package.json` file, a `src` directory containing all the source code, and a `l10n` directory for translations. Optionally, you may also include a `tests` directory if your application requires testing. | ||
|
||
To learn more about apps in general, please refer to the [Web app docs]({{< ref "_index.md#apps" >}}). | ||
|
||
### App setup | ||
|
||
Inside the `src` folder you will need an `index.ts` file that sets up the app so it can be registered by the Web runtime. It follows the basic structure as described in [the apps section]({{< ref "_index.md#apps" >}}), so it may look like this: | ||
|
||
```typescript | ||
import { AppWrapperRoute, defineWebApplication } from '@ownclouders/web-pkg' | ||
import translations from '../l10n/translations.json' | ||
import { useGettext } from 'vue3-gettext' | ||
|
||
// This is the base component of your app. | ||
import App from './App.vue' | ||
|
||
export default defineWebApplication({ | ||
setup() { | ||
// The ID of your app. | ||
const appId = 'advanced-pdf-viewer' | ||
|
||
const { $gettext } = useGettext() | ||
|
||
// This creates a route under which your app can be opened. | ||
// Later, this route will be bound to one or more file extensions. | ||
const routes = [ | ||
{ | ||
name: 'advanced-pdf-viewer', | ||
path: '/:driveAliasAndItem(.*)?', | ||
component: AppWrapperRoute(App, { | ||
applicationId: appId | ||
}), | ||
meta: { | ||
authContext: 'hybrid', | ||
title: $gettext('Advanced PDF Viewer'), | ||
patchCleanPath: true | ||
} | ||
} | ||
] | ||
|
||
return { | ||
appInfo: { | ||
name: 'Advanced PDF Viewer', | ||
id: appId, | ||
defaultExtension: 'pdf', | ||
isFileEditor: true, | ||
extensions: [ | ||
// This makes sure all files with the "pdf" extension will be routed to your app when being opened. | ||
// See the `ApplicationFileExtension` interface down below for a list of all possible properties. | ||
{ | ||
extension: 'pdf', | ||
routeName: 'advanced-pdf-viewer', | ||
|
||
// Add this if you want your app to be present in the "New" file menu. | ||
newFileMenu: { | ||
menuTitle() { | ||
return $gettext('PDF document') | ||
} | ||
} | ||
} | ||
], | ||
|
||
// Add this if you want your app to be present in the app menu on the top left. | ||
applicationMenu: { | ||
enabled: () => true, | ||
openAsEditor: true, | ||
priority: 10 | ||
} | ||
}, | ||
routes, | ||
translations | ||
} | ||
} | ||
}) | ||
``` | ||
|
||
Here is the interface defining the `extensions` property of the `appInfo` object. | ||
|
||
```typescript | ||
interface ApplicationFileExtension { | ||
app?: string | ||
extension?: string | ||
createFileHandler?: (arg: { | ||
fileName: string | ||
space: SpaceResource | ||
currentFolder: Resource | ||
}) => Promise<Resource> | ||
hasPriority?: boolean | ||
label?: string | ||
name?: string | ||
icon?: string | ||
mimeType?: string | ||
newFileMenu?: { menuTitle: () => string } | ||
routeName?: string | ||
} | ||
``` |