1
1
import type { UmbWorkspaceAction } from '../workspace-action.interface.js' ;
2
2
import { UmbActionExecutedEvent } from '@umbraco-cms/backoffice/event' ;
3
- import { html , customElement , property , state , ifDefined } from '@umbraco-cms/backoffice/external/lit' ;
3
+ import { html , customElement , property , state , ifDefined , when } from '@umbraco-cms/backoffice/external/lit' ;
4
4
import type { UUIButtonState } from '@umbraco-cms/backoffice/external/uui' ;
5
5
import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
6
- import type {
7
- ManifestWorkspaceAction ,
8
- MetaWorkspaceActionDefaultKind ,
6
+ import {
7
+ umbExtensionsRegistry ,
8
+ type ManifestWorkspaceAction ,
9
+ type ManifestWorkspaceActionMenuItem ,
10
+ type MetaWorkspaceActionDefaultKind ,
9
11
} from '@umbraco-cms/backoffice/extension-registry' ;
12
+ import {
13
+ type UmbExtensionElementAndApiInitializer ,
14
+ UmbExtensionsElementAndApiInitializer ,
15
+ } from '@umbraco-cms/backoffice/extension-api' ;
10
16
11
17
import '../../workspace-action-menu/index.js' ;
12
18
@@ -17,13 +23,15 @@ export class UmbWorkspaceActionElement<
17
23
> extends UmbLitElement {
18
24
#manifest?: ManifestWorkspaceAction < MetaType > ;
19
25
#api?: ApiType ;
26
+ #extensionsController?: UmbExtensionsElementAndApiInitializer <
27
+ ManifestWorkspaceActionMenuItem ,
28
+ 'workspaceActionMenuItem' ,
29
+ ManifestWorkspaceActionMenuItem
30
+ > ;
20
31
21
32
@state ( )
22
33
private _buttonState ?: UUIButtonState ;
23
34
24
- @state ( )
25
- private _aliases : Array < string > = [ ] ;
26
-
27
35
@state ( )
28
36
_href ?: string ;
29
37
@@ -60,6 +68,9 @@ export class UmbWorkspaceActionElement<
60
68
return this . #api;
61
69
}
62
70
71
+ @state ( )
72
+ private _items : Array < UmbExtensionElementAndApiInitializer < ManifestWorkspaceActionMenuItem > > = [ ] ;
73
+
63
74
/**
64
75
* Create a list of original and overwritten aliases of workspace actions for the action.
65
76
*/
@@ -77,7 +88,8 @@ export class UmbWorkspaceActionElement<
77
88
}
78
89
}
79
90
}
80
- this . _aliases = Array . from ( aliases ) ;
91
+
92
+ this . #observeExtensions( Array . from ( aliases ) ) ;
81
93
}
82
94
83
95
private async _onClick ( event : MouseEvent ) {
@@ -108,27 +120,61 @@ export class UmbWorkspaceActionElement<
108
120
) ;
109
121
}
110
122
111
- override render ( ) {
123
+ #observeExtensions( aliases : string [ ] ) : void {
124
+ this . #extensionsController?. destroy ( ) ;
125
+ this . #extensionsController = new UmbExtensionsElementAndApiInitializer <
126
+ ManifestWorkspaceActionMenuItem ,
127
+ 'workspaceActionMenuItem' ,
128
+ ManifestWorkspaceActionMenuItem
129
+ > (
130
+ this ,
131
+ umbExtensionsRegistry ,
132
+ 'workspaceActionMenuItem' ,
133
+ ExtensionApiArgsMethod ,
134
+ ( action ) => {
135
+ return Array . isArray ( action . forWorkspaceActions )
136
+ ? action . forWorkspaceActions . some ( ( alias ) => aliases . includes ( alias ) )
137
+ : aliases . includes ( action . forWorkspaceActions ) ;
138
+ } ,
139
+ ( extensionControllers ) => {
140
+ this . _items = extensionControllers ;
141
+ } ,
142
+ undefined , // We can leave the alias to undefined, as we destroy this our selfs.
143
+ ) ;
144
+ }
145
+
146
+ #renderButton( ) {
112
147
return html `
113
- < uui-button-group >
114
- < uui-button
115
- id ="action-button "
116
- .href =${ this . _href }
117
- @click =${ this . _onClick }
118
- look=${ this . #manifest?. meta . look || 'default' }
119
- color=${ this . #manifest?. meta . color || 'default' }
120
- label=${ ifDefined (
121
- this . #manifest?. meta . label ? this . localize . string ( this . #manifest. meta . label ) : this . #manifest?. name ,
122
- ) }
123
- .disabled=${ this . _isDisabled }
124
- .state=${ this . _buttonState } > </ uui-button >
125
- < umb-workspace-action-menu
126
- .forWorkspaceActions =${ this . _aliases }
127
- color ="${ this . #manifest?. meta . color || 'default' } "
128
- look="${ this . #manifest?. meta . look || 'default' } "> </ umb-workspace-action-menu >
129
- </ uui-button-group >
148
+ < uui-button
149
+ id ="action-button "
150
+ .href =${ this . _href }
151
+ @click =${ this . _onClick }
152
+ look=${ this . #manifest?. meta . look || 'default' }
153
+ color=${ this . #manifest?. meta . color || 'default' }
154
+ label=${ ifDefined (
155
+ this . #manifest?. meta . label ? this . localize . string ( this . #manifest. meta . label ) : this . #manifest?. name ,
156
+ ) }
157
+ .disabled=${ this . _isDisabled }
158
+ .state=${ this . _buttonState } > </ uui-button >
130
159
` ;
131
160
}
161
+
162
+ #renderActionMenu( ) {
163
+ return html `
164
+ < umb-workspace-action-menu
165
+ .items =${ this . _items }
166
+ color ="${ this . #manifest?. meta . color || 'default' } "
167
+ look="${ this . #manifest?. meta . look || 'default' } "> </ umb-workspace-action-menu >
168
+ ` ;
169
+ }
170
+
171
+ override render ( ) {
172
+ return when (
173
+ this . _items . length ,
174
+ ( ) => html ` < uui-button-group > ${ this . #renderButton( ) } ${ this . #renderActionMenu( ) } </ uui-button-group > ` ,
175
+ ( ) => this . #renderButton( ) ,
176
+ ) ;
177
+ }
132
178
}
133
179
134
180
export default UmbWorkspaceActionElement ;
@@ -138,3 +184,7 @@ declare global {
138
184
'umb-workspace-action' : UmbWorkspaceActionElement ;
139
185
}
140
186
}
187
+
188
+ function ExtensionApiArgsMethod ( manifest : ManifestWorkspaceActionMenuItem ) {
189
+ return [ { meta : manifest . meta } ] ;
190
+ }
0 commit comments