|
5 | 5 |
|
6 | 6 | import ShareVariant from '@mdi/svg/svg/share-variant.svg?raw' |
7 | 7 | import { getCSPNonce } from '@nextcloud/auth' |
| 8 | +import { registerSidebarTab } from '@nextcloud/files' |
8 | 9 | import { n, t } from '@nextcloud/l10n' |
| 10 | +import wrap from '@vue/web-component-wrapper' |
9 | 11 | import Vue from 'vue' |
| 12 | +import FilesSidebarTab from './views/FilesSidebarTab.vue' |
10 | 13 | import ExternalShareActions from './services/ExternalShareActions.js' |
11 | 14 | import ShareSearch from './services/ShareSearch.js' |
12 | 15 | import TabSections from './services/TabSections.js' |
13 | 16 |
|
14 | 17 | __webpack_nonce__ = getCSPNonce() |
15 | 18 |
|
16 | 19 | // Init Sharing Tab Service |
17 | | -if (!window.OCA.Sharing) { |
18 | | - window.OCA.Sharing = {} |
19 | | -} |
| 20 | +window.OCA.Sharing ??= {} |
20 | 21 | Object.assign(window.OCA.Sharing, { ShareSearch: new ShareSearch() }) |
21 | 22 | Object.assign(window.OCA.Sharing, { ExternalShareActions: new ExternalShareActions() }) |
22 | 23 | Object.assign(window.OCA.Sharing, { ShareTabSections: new TabSections() }) |
23 | 24 |
|
24 | 25 | Vue.prototype.t = t |
25 | 26 | Vue.prototype.n = n |
26 | 27 |
|
27 | | -// Init Sharing tab component |
28 | | -let TabInstance = null |
29 | | - |
30 | | -window.addEventListener('DOMContentLoaded', function() { |
31 | | - if (OCA.Files && OCA.Files.Sidebar) { |
32 | | - OCA.Files.Sidebar.registerTab(new OCA.Files.Sidebar.Tab({ |
33 | | - id: 'sharing', |
34 | | - name: t('files_sharing', 'Sharing'), |
35 | | - iconSvg: ShareVariant, |
36 | | - |
37 | | - async mount(el, fileInfo, context) { |
38 | | - const SharingTab = (await import('./views/SharingTab.vue')).default |
39 | | - const View = Vue.extend(SharingTab) |
40 | | - |
41 | | - if (TabInstance) { |
42 | | - TabInstance.$destroy() |
43 | | - } |
44 | | - TabInstance = new View({ |
45 | | - // Better integration with vue parent component |
46 | | - parent: context, |
47 | | - }) |
48 | | - // Only mount after we have all the info we need |
49 | | - await TabInstance.update(fileInfo) |
50 | | - TabInstance.$mount(el) |
51 | | - }, |
52 | | - |
53 | | - update(fileInfo) { |
54 | | - TabInstance.update(fileInfo) |
55 | | - }, |
56 | | - |
57 | | - destroy() { |
58 | | - if (TabInstance) { |
59 | | - TabInstance.$destroy() |
60 | | - TabInstance = null |
61 | | - } |
62 | | - }, |
63 | | - })) |
64 | | - } |
| 28 | +const tagName = 'files_sharing-sidebar-tab' |
| 29 | + |
| 30 | +registerSidebarTab({ |
| 31 | + id: 'sharing', |
| 32 | + displayName: t('files_sharing', 'Sharing'), |
| 33 | + iconSvgInline: ShareVariant, |
| 34 | + order: 10, |
| 35 | + tagName, |
| 36 | + enabled() { |
| 37 | + if (!window.customElements.get(tagName)) { |
| 38 | + setupSidebarTab() |
| 39 | + } |
| 40 | + return true |
| 41 | + }, |
65 | 42 | }) |
| 43 | + |
| 44 | +/** |
| 45 | + * Setup the sidebar tab as a web component |
| 46 | + */ |
| 47 | +function setupSidebarTab() { |
| 48 | + const webComponent = wrap(Vue, FilesSidebarTab) |
| 49 | + // In Vue 2, wrap doesn't support diseabling shadow. Disable with a hack |
| 50 | + Object.defineProperty(webComponent.prototype, 'attachShadow', { |
| 51 | + value() { return this }, |
| 52 | + }) |
| 53 | + Object.defineProperty(webComponent.prototype, 'shadowRoot', { |
| 54 | + get() { return this }, |
| 55 | + }) |
| 56 | + |
| 57 | + window.customElements.define(tagName, webComponent) |
| 58 | +} |
0 commit comments