|
| 1 | +/** |
| 2 | + * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors |
| 3 | + * SPDX-License-Identifier: AGPL-3.0-or-later |
| 4 | + */ |
| 5 | + |
| 6 | +import MessageReplyText from '@mdi/svg/svg/message-reply-text.svg?raw' |
| 7 | +import { getCSPNonce } from '@nextcloud/auth' |
| 8 | +import { registerSidebarTab } from '@nextcloud/files' |
| 9 | +import { loadState } from '@nextcloud/initial-state' |
| 10 | +import { t } from '@nextcloud/l10n' |
| 11 | +import wrap from '@vue/web-component-wrapper' |
| 12 | +import { createPinia, PiniaVuePlugin } from 'pinia' |
| 13 | +import Vue from 'vue' |
| 14 | +import FilesSidebarTab from './views/FilesSidebarTab.vue' |
| 15 | +import { registerCommentsPlugins } from './comments-activity-tab.ts' |
| 16 | + |
| 17 | +__webpack_nonce__ = getCSPNonce() |
| 18 | + |
| 19 | +const tagName = 'comments_files-sidebar-tab' |
| 20 | + |
| 21 | +if (loadState('comments', 'activityEnabled', false) && OCA?.Activity?.registerSidebarAction !== undefined) { |
| 22 | + // Do not mount own tab but mount into activity |
| 23 | + window.addEventListener('DOMContentLoaded', function() { |
| 24 | + registerCommentsPlugins() |
| 25 | + }) |
| 26 | +} else { |
| 27 | + registerSidebarTab({ |
| 28 | + id: 'comments', |
| 29 | + displayName: t('comments', 'Comments'), |
| 30 | + iconSvgInline: MessageReplyText, |
| 31 | + order: 50, |
| 32 | + tagName, |
| 33 | + enabled() { |
| 34 | + if (!window.customElements.get(tagName)) { |
| 35 | + setupSidebarTab() |
| 36 | + } |
| 37 | + return true |
| 38 | + }, |
| 39 | + }) |
| 40 | +} |
| 41 | + |
| 42 | +/** |
| 43 | + * Setup the sidebar tab as a web component |
| 44 | + */ |
| 45 | +function setupSidebarTab() { |
| 46 | + Vue.use(PiniaVuePlugin) |
| 47 | + Vue.mixin({ pinia: createPinia() }) |
| 48 | + const webComponent = wrap(Vue, FilesSidebarTab) |
| 49 | + // In Vue 2, wrap doesn't support disabling 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 | + window.customElements.define(tagName, webComponent) |
| 57 | +} |
0 commit comments