33 * SPDX-License-Identifier: AGPL-3.0-or-later
44 */
55
6+ import type { INode } from '../node/node.ts'
7+ import type { ISidebarAction } from './SidebarAction.ts'
68import type { ISidebarContext , ISidebarTab } from './SidebarTab.ts'
79
8- import { getSidebarTabs , registerSidebarTab } from './SidebarTab.ts'
10+ import { registerSidebarAction } from './SidebarAction.ts'
11+ import { registerSidebarTab } from './SidebarTab.ts'
912
1013export interface ISidebar {
1114 /**
@@ -17,17 +20,47 @@ export interface ISidebar {
1720 /**
1821 * The current open state of the sidebar
1922 */
20- readonly open : boolean
23+ readonly isOpen : boolean
2124
2225 /**
23- * Open or close the sidebar
26+ * The currently active sidebar tab id
27+ */
28+ readonly activeTab ?: string
29+
30+ /**
31+ * The currently opened node in the sidebar
32+ */
33+ readonly node ?: INode
34+
35+ /**
36+ * Open the sidebar for a specific node.
37+ *
38+ * When the sidebar is fully opened the `files:sidebar:opened` event is emitted,
39+ * see also `@nextcloud/event-bus`.
40+ *
41+ * @param node - The node to open the sidebar for
42+ * @param tab - The tab to open by default
43+ */
44+ open ( node : INode , tab ?: string ) : void
45+
46+ /**
47+ * Close the sidebar.
2448 *
25- * @param open - The new open state
49+ * When the sidebar is fully closed the `files:sidebar:closed` event is emitted,
50+ * see also `@nextcloud/event-bus`.
2651 */
27- setOpen ( open : boolean ) : void
52+ close ( ) : void
2853
2954 /**
30- * Register a new sidebar tab
55+ * Set the active sidebar tab
56+ *
57+ * @param tabId - The tab to set active
58+ */
59+ setActiveTab ( tabId : string ) : void
60+
61+ /**
62+ * Register a new sidebar tab.
63+ * This should ideally be done on app initialization using Nextcloud init scripts.
3164 *
3265 * @param tab - The sidebar tab to register
3366 */
@@ -38,6 +71,22 @@ export interface ISidebar {
3871 * If a node is passed only the enabled tabs are retrieved.
3972 */
4073 getTabs ( context ?: ISidebarContext ) : ISidebarTab [ ]
74+
75+ /**
76+ * Get all registered sidebar actions.
77+ *
78+ * If a context is provided only the enabled actions are returned.
79+ *
80+ * @param context - The context
81+ */
82+ getActions ( context ?: ISidebarContext ) : ISidebarAction [ ]
83+
84+ /**
85+ * Register a new sidebar action.
86+ *
87+ * @param action - The action to register
88+ */
89+ registerAction ( action : ISidebarAction ) : void
4190}
4291
4392/**
@@ -50,36 +99,52 @@ export interface ISidebar {
5099 */
51100class SidebarProxy implements ISidebar {
52101
102+ get #impl( ) : Omit < ISidebar , 'available' | 'registerTab' | 'registerAction' > | undefined {
103+ return window . OCA ?. Files ?. _sidebar ?.( )
104+ }
105+
53106 get available ( ) : boolean {
54- return ! ! window . OCA ?. Files ?. Sidebar
107+ return ! ! this . #impl
108+ }
109+
110+ get isOpen ( ) : boolean {
111+ return this . #impl?. isOpen ?? false
112+ }
113+
114+ get activeTab ( ) : string | undefined {
115+ return this . #impl?. activeTab
116+ }
117+
118+ get node ( ) : INode | undefined {
119+ return this . #impl?. node
55120 }
56121
57- get open ( ) : boolean {
58- return ! ! window . OCA ?. Files ?. Sidebar ?. state . file
122+ open ( node : INode , tab ?: string ) : void {
123+ this . #impl ?. open ( node , tab )
59124 }
60125
61- setOpen ( open : boolean ) : void {
62- if ( open ) {
63- window . OCA ?. Files ?. Sidebar ?. open ( )
64- } else {
65- window . OCA ?. Files ?. Sidebar ?. close ( )
66- }
126+ close ( ) : void {
127+ this . #impl?. close ( )
67128 }
68129
69130 setActiveTab ( tabId : string ) : void {
70- window . OCA ?. Files ?. Sidebar ?. setActiveTab ( tabId )
131+ this . #impl ?. setActiveTab ( tabId )
71132 }
72133
73134 registerTab ( tab : ISidebarTab ) : void {
74135 registerSidebarTab ( tab )
75136 }
76137
77138 getTabs ( context ?: ISidebarContext ) : ISidebarTab [ ] {
78- const tabs = getSidebarTabs ( )
79- if ( context ) {
80- return tabs . filter ( ( tab ) => tab . enabled ( context ) )
81- }
82- return tabs
139+ return this . #impl?. getTabs ( context ) ?? [ ]
140+ }
141+
142+ getActions ( context ?: ISidebarContext ) : ISidebarAction [ ] {
143+ return this . #impl?. getActions ( context ) ?? [ ]
144+ }
145+
146+ registerAction ( action : ISidebarAction ) : void {
147+ registerSidebarAction ( action )
83148 }
84149
85150}
0 commit comments