Skip to content

Commit c473823

Browse files
authored
Merge pull request #2922 from nextcloud/feat/viewer-api
feat: add API package to register handlers in init scripts
2 parents 42ee29c + 3982ccf commit c473823

20 files changed

+404
-20
lines changed

README.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,46 @@ OCA.Viewer.close()
146146
```
147147

148148
### 🔍 Add you own file view
149+
150+
If you want to make your app compatible with this app, you can use the methods provided by the [`@nextcloud/viewer`](https://www.npmjs.com/package/@nextcloud/viewer) npm.js package:
151+
1. Create a vue component which use the `path` and `mime` props (they will be automatically passed by the viewer)
152+
2. Register your mime viewer with the following:
153+
``` js
154+
import { registerHandler } from '@nextcloud/viewer'
155+
import VideoView from 'VideoView.vue'
156+
157+
registerHandler({
158+
// unique id
159+
id: 'video',
160+
161+
// optional, it will group every view of this group and
162+
// use the proper view when building the file list
163+
// of the slideshow.
164+
// e.g. you open an image/jpeg that have the `media` group
165+
// you will be able to see the video/mpeg from the `video` handler
166+
// files that also have the `media` group set.
167+
group: 'media',
168+
169+
// the list of mimes your component is able to display
170+
mimes: [
171+
'video/mpeg',
172+
'video/ogg',
173+
'video/webm',
174+
'video/mp4'
175+
],
176+
177+
// your vue component view
178+
component: VideoView
179+
})
180+
```
181+
3. Make sure your script is loaded with `\OCP\Util::addInitScript` so that the handler is registered **before** the viewer is loaded.
182+
4. if you feel like your mime should be integrated on this repo, you can also create a pull request with your object on the `models` directory and the view on the `components` directory. Please have a look at what's already here and take example of it. 🙇‍♀️
183+
184+
185+
### Legacy handler registration
186+
> [!CAUTION]
187+
> Using OCA.Viewer for registering your handlers is not recommended as this might break depending on the script loading order
188+
149189
If you want to make your app compatible with this app, you can use the `OCA.Viewer` methods
150190
1. Create a vue component which use the `path` and `mime` props (they will be automatically passed by the viewer)
151191
2. Register your mime viewer with the following:
@@ -176,4 +216,4 @@ If you want to make your app compatible with this app, you can use the `OCA.View
176216
component: VideoView
177217
})
178218
```
179-
3. if you feel like your mime should be integrated on this repo, you can also create a pull request with your object on the `models` directory and the view on the `components` directory. Please have a look at what's already here and take example of it. 🙇‍♀️
219+
3. Make sure your script is loaded with `\OCP\Util::addScript` (in contrast to using the API package)!

css/main-JrgzHO2I.chunk.css renamed to css/main-BbtLvFSi.chunk.css

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

css/viewer-main.css

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
/* extracted by css-entry-points-plugin */
2-
@import './main-JrgzHO2I.chunk.css';
2+
@import './main-BbtLvFSi.chunk.css';
33
@import './previewUtils-6cpbKhU6.chunk.css';

cypress/e2e/actions/download.cy.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ describe(`Download ${fileName} in viewer`, function() {
4444
it('Download the image', function() {
4545
// open the menu
4646
cy.get('body > .viewer .modal-header button.action-item__menutoggle').click()
47-
// download the file
48-
cy.get('.action-link .download-icon').click()
47+
// download the
48+
cy.findByRole('menuitem', { name: 'Download' }).click()
4949
})
5050

5151
it('Compare downloaded file with asset by size', function() {

cypress/support/commands.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ import { ShareType } from '@nextcloud/sharing'
99
import { addCompareSnapshotCommand } from 'cypress-visual-regression/dist/command'
1010
import { basename } from 'path'
1111

12+
import '@testing-library/cypress/add-commands'
13+
1214
addCommands()
1315
addCompareSnapshotCommand({
1416
errorThreshold: 0.01,

cypress/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
"compilerOptions": {
55
"rootDir": "..",
66
"types": [
7+
"@testing-library/cypress",
78
"cypress",
89
"dockerode",
910
"node"

js/viewer-main.mjs

Lines changed: 2 additions & 2 deletions
Large diffs are not rendered by default.

js/viewer-main.mjs.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package-lock.json

Lines changed: 110 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@
8282
"@nextcloud/sharing": "^0.2.5",
8383
"@nextcloud/stylelint-config": "^3.1.0",
8484
"@nextcloud/vite-config": "^1.5.6",
85+
"@testing-library/cypress": "^10.0.3",
8586
"@types/dockerode": "^3.3.39",
8687
"@vue/tsconfig": "^0.5.1",
8788
"cypress": "^13.17.0",

0 commit comments

Comments
 (0)