1- import type { ManifestPreviewOption } from '../preview-option/preview-option.extension.js' ;
1+ import type { ManifestPreviewOption , MetaPreviewOption } from '../preview-option/preview-option.extension.js' ;
2+ import type { UmbPreviewOptionActionBase } from '../preview-option/preview-option-action-base.controller.js' ;
23import { customElement , html , property , state , when } from '@umbraco-cms/backoffice/external/lit' ;
34import { UmbActionExecutedEvent } from '@umbraco-cms/backoffice/event' ;
45import { umbExtensionsRegistry } from '@umbraco-cms/backoffice/extension-registry' ;
5- import { UmbExtensionsElementAndApiInitializer } from '@umbraco-cms/backoffice/extension-api' ;
6+ import { createExtensionApi , UmbExtensionsElementAndApiInitializer } from '@umbraco-cms/backoffice/extension-api' ;
67import { UmbLitElement } from '@umbraco-cms/backoffice/lit-element' ;
78import type { UmbWorkspaceAction } from '@umbraco-cms/backoffice/workspace' ;
89import type { UmbExtensionElementAndApiInitializer } from '@umbraco-cms/backoffice/extension-api' ;
@@ -51,14 +52,18 @@ export class UmbSaveAndPreviewWorkspaceActionElement extends UmbLitElement {
5152 @state ( )
5253 private _actions : Array < UmbExtensionElementAndApiInitializer < ManifestPreviewOption > > = [ ] ;
5354
54- private _primaryAction ?: UmbExtensionElementAndApiInitializer < ManifestPreviewOption > ;
55+ @state ( )
56+ private _firstActionManifest ?: ManifestPreviewOption ;
57+
58+ @state ( )
59+ private _firstActionApi ?: UmbPreviewOptionActionBase < MetaPreviewOption > ;
5560
5661 async #onClick( ) {
5762 this . _buttonState = 'waiting' ;
5863
5964 try {
60- if ( ! this . _primaryAction ?. api ) throw new Error ( 'No api defined' ) ;
61- await this . _primaryAction . api . execute ( ) . catch ( ( ) => { } ) ;
65+ if ( ! this . _firstActionApi ) throw new Error ( 'No api defined' ) ;
66+ await this . _firstActionApi . execute ( ) . catch ( ( ) => { } ) ;
6267 this . _buttonState = 'success' ;
6368 } catch ( reason ) {
6469 if ( reason ) {
@@ -101,14 +106,23 @@ export class UmbSaveAndPreviewWorkspaceActionElement extends UmbLitElement {
101106 ManifestPreviewOption ,
102107 'previewOption' ,
103108 ManifestPreviewOption
104- > ( this , umbExtensionsRegistry , 'previewOption' , [ ] , undefined , ( extensionControllers ) => {
105- this . _primaryAction = extensionControllers . shift ( ) ;
106- this . _actions = extensionControllers ;
109+ > ( this , umbExtensionsRegistry , 'previewOption' , [ ] , undefined , async ( actions ) => {
110+ const firstAction = actions . shift ( ) ;
111+
112+ if ( firstAction ) {
113+ this . _firstActionManifest = firstAction . manifest ;
114+ this . _firstActionApi = await createExtensionApi ( this , firstAction . manifest , [ ] ) ;
115+ if ( this . _firstActionApi ) {
116+ ( this . _firstActionApi as any ) . manifest = this . _firstActionManifest ;
117+ }
118+ }
119+
120+ this . _actions = actions ;
107121 } ) ;
108122 }
109123
110124 #renderButton( ) {
111- const label = this . _primaryAction ?. manifest ?. meta . label || this . #manifest?. meta . label || this . #manifest?. name ;
125+ const label = this . _firstActionManifest ?. meta . label || this . #manifest?. meta . label || this . #manifest?. name ;
112126 return html `
113127 < uui-button
114128 data-mark ="workspace-action: ${ this . #manifest?. alias } "
@@ -132,6 +146,7 @@ export class UmbSaveAndPreviewWorkspaceActionElement extends UmbLitElement {
132146 }
133147
134148 override render ( ) {
149+ if ( ! this . _firstActionManifest || ! this . _actions . length ) return ;
135150 return when (
136151 this . _actions . length ,
137152 ( ) => html `< uui-button-group > ${ this . #renderButton( ) } ${ this . #renderActionMenu( ) } </ uui-button-group > ` ,
0 commit comments