Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
feat: provide API to register sidebar sections
Signed-off-by: Ferdinand Thiessen <[email protected]>
  • Loading branch information
susnux committed Sep 1, 2025
commit e6befbb7e9a408165e9fd6690e8e923d61c0ded7
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ npm i -S @nextcloud/sharing

## Usage

There are two entry points provided:
There are three entry points provided:

- The main entry point `@nextcloud/sharing` provides general utils for file sharing
- The _public_ entry point `@nextcloud/sharing/public` provides utils for handling public file shares
- The _ui_ entry point `@nextcloud/sharing/ui` provides API bindings to interact with the files sharing interface in the files app.
2 changes: 1 addition & 1 deletion REUSE.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ SPDX-PackageSupplier = "Nextcloud GmbH <https://nextcloud.com/impressum/>"
SPDX-PackageDownloadLocation = "https://github.com/nextcloud-libraries/nextcloud-sharing"

[[annotations]]
path = ["package.json", "package-lock.json", "tsconfig.json"]
path = ["package.json", "package-lock.json", "**/tsconfig.json"]
precedence = "aggregate"
SPDX-FileCopyrightText = "2021 Nextcloud GmbH and Nextcloud contributors"
SPDX-License-Identifier = "GPL-3.0-or-later"
8 changes: 8 additions & 0 deletions lib/ui/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

export type * from './sidebar-section.ts'

export * from './sidebar-section.ts'
70 changes: 70 additions & 0 deletions lib/ui/sidebar-section.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import type { INode } from '@nextcloud/files'

export interface ISidebarSection {
/**
* Unique identifier for the section
*/
id: string

/**
* The registered identifier of the custom web component to be used.
*
* The custom elements identifier must be prefixed with your apps namespace like `oca_myapp-sharing_section`.
* Also the component must at least have a `node` property which must accept the current active node as `INode` from `@nextcloud/files`.
*
* @see https://developer.mozilla.org/en-US/docs/Web/API/Web_components
* @see https://vuejs.org/guide/extras/web-components#building-custom-elements-with-vue
*/
element: string

/**
* Order of the sidebar sections.
* A higher value means the section will be displayed first.
*/
order: number

/**
* Check if the section is enabled for the current active node
*
* @param node - The node to check
*/
enabled(node: INode): boolean
}

/**
* Register a new sidebar section inside the files sharing sidebar tab.
*
* @param section - The section to register
*/
export function registerSidebarSection(section: ISidebarSection): void {
if (!section.id) {
throw new Error('Sidebar sections must have an id')
}
if (!section.element || !section.element.startsWith('oca_') || !window.customElements.get(section.element)) {
throw new Error('Sidebar sections must provide a registered custom web component identifier')
}
if (typeof section.order !== 'number') {
throw new Error('Sidebar sections must have the order property')
}
if (typeof section.enabled !== 'function') {
throw new Error('Sidebar sections must implement the enabled method')
}

window._nc_files_sharing_sidebar_sections ??= new Map<string, ISidebarSection>()
if (window._nc_files_sharing_sidebar_sections.has(section.id)) {
throw new Error(`Sidebar section with id "${section.id}" is already registered`)
}
window._nc_files_sharing_sidebar_sections.set(section.id, section)
}

/**
* Get all registered sidebar sections for the files sharing sidebar tab.
*/
export function getSidebarSections(): ISidebarSection[] {
return [...(window._nc_files_sharing_sidebar_sections?.values() ?? [])]
}
11 changes: 11 additions & 0 deletions lib/window.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*!
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: GPL-3.0-or-later
*/

import type { ISharingSection } from './ui/index.ts'
declare global {
interface Window {
_nc_files_sharing_sidebar_sections?: Map<string, ISharingSection>
}
}
Loading