|
1 | 1 | // Copyright 2026 ledoent — Don Kendall |
2 | 2 | // License LGPL-3.0 or later (http://www.gnu.org/licenses/lgpl). |
3 | 3 |
|
4 | | -// Extension point for DMS file preview handlers. |
| 4 | +// =========================================================================== |
| 5 | +// Extension point for DMS file preview handlers |
| 6 | +// =========================================================================== |
5 | 7 | // |
6 | | -// Modules like `dms_onlyoffice` register additional handlers via: |
| 8 | +// The `dms` module ships in-browser preview handlers for the formats that |
| 9 | +// every modern browser already understands: images, PDF, audio, video. Office |
| 10 | +// formats (.doc/.docx/.odt/.xlsx/...) fall through to a download + Google |
| 11 | +// Viewer affordance because there is no in-browser viewer in base. Modules |
| 12 | +// like a future `dms_onlyoffice 19.0` plug in here to add native handlers. |
7 | 13 | // |
| 14 | +// --------------------------------------------------------------------------- |
| 15 | +// Contract |
| 16 | +// --------------------------------------------------------------------------- |
| 17 | +// |
| 18 | +// A handler is a plain object registered against this category: |
| 19 | +// |
| 20 | +// { |
| 21 | +// component: OwlComponent, // receives {file: {id, name, mimetype, |
| 22 | +// // write_date, human_size}} as a prop |
| 23 | +// match: (mimetype) => bool, // OPTIONAL — predicate; if omitted, |
| 24 | +// // the registry key is used as an |
| 25 | +// // exact mimetype match |
| 26 | +// score: 10, // OPTIONAL — higher wins on ties; |
| 27 | +// // built-ins use 0; download is -100 |
| 28 | +// } |
| 29 | +// |
| 30 | +// Registering from an external module looks like this: |
| 31 | +// |
| 32 | +// // dms_onlyoffice/static/src/js/onlyoffice_preview_handler.esm.js |
8 | 33 | // import {registry} from "@web/core/registry"; |
9 | | -// registry.category("dms.preview_handlers").add("application/msword", { |
| 34 | +// import {OnlyOfficePreview} from "./onlyoffice_preview.esm"; |
| 35 | +// |
| 36 | +// const OFFICE_MIMETYPES = new Set([ |
| 37 | +// "application/msword", |
| 38 | +// "application/vnd.openxmlformats-officedocument.wordprocessingml.document", |
| 39 | +// "application/vnd.oasis.opendocument.text", |
| 40 | +// // ... etc |
| 41 | +// ]); |
| 42 | +// |
| 43 | +// registry.category("dms.preview_handlers").add("onlyoffice", { |
10 | 44 | // component: OnlyOfficePreview, |
11 | | -// match: (mt) => mt === "application/msword", |
12 | | -// score: 10, |
| 45 | +// match: (mt) => OFFICE_MIMETYPES.has(mt), |
| 46 | +// score: 10, // beats the built-in Google Viewer fallback (score 0) |
13 | 47 | // }); |
14 | 48 | // |
15 | | -// Lookup is by mimetype. `match` is an optional predicate for glob-style |
16 | | -// matching ("image/*"). `score` breaks ties (higher wins); built-ins use 0, |
17 | | -// so any extending module's handler with score>=0 will override the default. |
| 49 | +// The registered component must: |
| 50 | +// - declare `static template = "..."` and `static props = {file: Object}` |
| 51 | +// - render content that fits inside `.o_dms_preview_pane__body` |
| 52 | +// (no min-height required; the container handles overflow) |
| 53 | +// |
| 54 | +// --------------------------------------------------------------------------- |
| 55 | +// Lookup semantics |
| 56 | +// --------------------------------------------------------------------------- |
| 57 | +// |
| 58 | +// `getPreviewHandler(mimetype)` returns the highest-scored handler whose |
| 59 | +// `match` predicate accepts the mimetype (or whose registry key equals it, |
| 60 | +// if no `match` is provided). The built-in `__download__` handler matches |
| 61 | +// everything at score -100, so the function always returns something for any |
| 62 | +// non-empty mimetype. |
18 | 63 |
|
19 | 64 | import {registry} from "@web/core/registry"; |
20 | 65 |
|
|
0 commit comments