{"version":3,"file":"workspace-action.element-CA06XwSM.js","sources":["../../../src/packages/core/workspace/components/workspace-action/default/workspace-action.element.ts"],"sourcesContent":["import type { UmbWorkspaceAction } from '../workspace-action.interface.js';\nimport { UmbActionExecutedEvent } from '@umbraco-cms/backoffice/event';\nimport { html, customElement, property, state, ifDefined, when } from '@umbraco-cms/backoffice/external/lit';\nimport type { UUIButtonState } from '@umbraco-cms/backoffice/external/uui';\nimport { UmbLitElement } from '@umbraco-cms/backoffice/lit-element';\nimport {\n\tumbExtensionsRegistry,\n\ttype ManifestWorkspaceAction,\n\ttype ManifestWorkspaceActionMenuItem,\n\ttype MetaWorkspaceActionDefaultKind,\n} from '@umbraco-cms/backoffice/extension-registry';\nimport {\n\ttype UmbExtensionElementAndApiInitializer,\n\tUmbExtensionsElementAndApiInitializer,\n} from '@umbraco-cms/backoffice/extension-api';\n\nimport '../../workspace-action-menu/index.js';\n\n@customElement('umb-workspace-action')\nexport class UmbWorkspaceActionElement<\n\tMetaType extends MetaWorkspaceActionDefaultKind = MetaWorkspaceActionDefaultKind,\n\tApiType extends UmbWorkspaceAction = UmbWorkspaceAction,\n> extends UmbLitElement {\n\t#manifest?: ManifestWorkspaceAction;\n\t#api?: ApiType;\n\t#extensionsController?: UmbExtensionsElementAndApiInitializer<\n\t\tManifestWorkspaceActionMenuItem,\n\t\t'workspaceActionMenuItem',\n\t\tManifestWorkspaceActionMenuItem\n\t>;\n\n\t@state()\n\tprivate _buttonState?: UUIButtonState;\n\n\t@state()\n\t_href?: string;\n\n\t@state()\n\t_isDisabled = false;\n\n\t@property({ type: Object, attribute: false })\n\tpublic set manifest(value: ManifestWorkspaceAction | undefined) {\n\t\tif (!value) return;\n\t\tconst oldValue = this.#manifest;\n\t\tthis.#manifest = value;\n\t\tif (oldValue !== this.#manifest) {\n\t\t\tthis.#createAliases();\n\t\t\tthis.requestUpdate('manifest', oldValue);\n\t\t}\n\t}\n\tpublic get manifest() {\n\t\treturn this.#manifest;\n\t}\n\n\t@property({ attribute: false })\n\tpublic set api(api: ApiType | undefined) {\n\t\tthis.#api = api;\n\n\t\t// TODO: Fix so when we use a HREF it does not refresh the page?\n\t\tthis.#api?.getHref?.().then((href) => {\n\t\t\tthis._href = href;\n\t\t\t// TODO: Do we need to update the component here? [NL]\n\t\t});\n\n\t\tthis.#observeIsDisabled();\n\t}\n\tpublic get api(): ApiType | undefined {\n\t\treturn this.#api;\n\t}\n\n\t@state()\n\tprivate _items: Array> = [];\n\n\t/**\n\t * Create a list of original and overwritten aliases of workspace actions for the action.\n\t */\n\tasync #createAliases() {\n\t\tif (!this.#manifest) return;\n\t\tconst aliases = new Set();\n\t\tif (this.#manifest) {\n\t\t\taliases.add(this.#manifest.alias);\n\n\t\t\t// TODO: This works on one level for now, which will be enough for the current use case. However, you can overwrite the overwrites, so we need to make this recursive. Perhaps we could move this to the extensions initializer.\n\t\t\t// Add overwrites so that we can show any previously registered actions on the original workspace action\n\t\t\tif (this.#manifest.overwrites) {\n\t\t\t\tfor (const alias of this.#manifest.overwrites) {\n\t\t\t\t\taliases.add(alias);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\n\t\tthis.#observeExtensions(Array.from(aliases));\n\t}\n\n\tprivate async _onClick(event: MouseEvent) {\n\t\tif (this._href) {\n\t\t\tevent.stopPropagation();\n\t\t}\n\n\t\tthis._buttonState = 'waiting';\n\n\t\ttry {\n\t\t\tif (!this.#api) throw new Error('No api defined');\n\t\t\tawait this.#api.execute();\n\t\t\tthis._buttonState = 'success';\n\t\t} catch {\n\t\t\tthis._buttonState = 'failed';\n\t\t}\n\n\t\tthis.dispatchEvent(new UmbActionExecutedEvent());\n\t}\n\n\t#observeIsDisabled() {\n\t\tthis.observe(\n\t\t\tthis.#api?.isDisabled,\n\t\t\t(isDisabled) => {\n\t\t\t\tthis._isDisabled = isDisabled || false;\n\t\t\t},\n\t\t\t'isDisabledObserver',\n\t\t);\n\t}\n\n\t#observeExtensions(aliases: string[]): void {\n\t\tthis.#extensionsController?.destroy();\n\t\tthis.#extensionsController = new UmbExtensionsElementAndApiInitializer<\n\t\t\tManifestWorkspaceActionMenuItem,\n\t\t\t'workspaceActionMenuItem',\n\t\t\tManifestWorkspaceActionMenuItem\n\t\t>(\n\t\t\tthis,\n\t\t\tumbExtensionsRegistry,\n\t\t\t'workspaceActionMenuItem',\n\t\t\tExtensionApiArgsMethod,\n\t\t\t(action) => {\n\t\t\t\treturn Array.isArray(action.forWorkspaceActions)\n\t\t\t\t\t? action.forWorkspaceActions.some((alias) => aliases.includes(alias))\n\t\t\t\t\t: aliases.includes(action.forWorkspaceActions);\n\t\t\t},\n\t\t\t(extensionControllers) => {\n\t\t\t\tthis._items = extensionControllers;\n\t\t\t},\n\t\t\tundefined, // We can leave the alias to undefined, as we destroy this our selfs.\n\t\t);\n\t}\n\n\t#renderButton() {\n\t\treturn html`\n\t\t\t\n\t\t`;\n\t}\n\n\t#renderActionMenu() {\n\t\treturn html`\n\t\t\t\n\t\t`;\n\t}\n\n\toverride render() {\n\t\treturn when(\n\t\t\tthis._items.length,\n\t\t\t() => html` ${this.#renderButton()} ${this.#renderActionMenu()} `,\n\t\t\t() => this.#renderButton(),\n\t\t);\n\t}\n}\n\nexport default UmbWorkspaceActionElement;\n\ndeclare global {\n\tinterface HTMLElementTagNameMap {\n\t\t'umb-workspace-action': UmbWorkspaceActionElement;\n\t}\n}\n\n/**\n *\n * @param manifest\n * @returns An array of arguments to pass to the extension API initializer.\n */\nfunction ExtensionApiArgsMethod(manifest: ManifestWorkspaceActionMenuItem) {\n\treturn [{ meta: manifest.meta }];\n}\n"],"names":["_manifest","_api","_extensionsController","_UmbWorkspaceActionElement_instances","createAliases_fn","observeIsDisabled_fn","observeExtensions_fn","renderButton_fn","renderActionMenu_fn","UmbWorkspaceActionElement","UmbLitElement","__privateAdd","value","oldValue","__privateGet","__privateSet","__privateMethod","api","href","event","UmbActionExecutedEvent","when","html","aliases","alias","isDisabled","UmbExtensionsElementAndApiInitializer","umbExtensionsRegistry","ExtensionApiArgsMethod","action","extensionControllers","ifDefined","__decorateClass","state","property","customElement","UmbWorkspaceActionElement$1","manifest"],"mappings":";;;;;;;;;;;;wXAAAA,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC,GAAAC;AAmBa,IAAAC,IAAN,cAGGC,EAAc;AAAA,EAHjB,cAAA;AAAA,UAAA,GAAA,SAAA,GAAAC,EAAA,MAAAR,CAAA,GAINQ,EAAA,MAAAX,CAAA,GACAW,EAAA,MAAAV,CAAA,GACAU,EAAA,MAAAT,CAAA,GAac,KAAA,cAAA,IAiCd,KAAQ,SAAuF;EAAC;AAAA,EA9BhG,IAAW,SAASU,GAAsD;AACzE,QAAI,CAACA,EAAO;AACZ,UAAMC,IAAWC,EAAK,MAAAd,CAAA;AACtB,IAAAe,EAAA,MAAKf,GAAYY,CAAA,GACbC,MAAaC,QAAKd,CAAW,MAChCgB,EAAA,MAAKb,GAALC,CAAA,EAAA,KAAA,IAAA,GACK,KAAA,cAAc,YAAYS,CAAQ;AAAA,EAEzC;AAAA,EACA,IAAW,WAAW;AACrB,WAAOC,EAAK,MAAAd,CAAA;AAAA,EACb;AAAA,EAGA,IAAW,IAAIiB,GAA0B;AACxC,IAAAF,EAAA,MAAKd,GAAOgB,CAAA,GAGZH,EAAA,MAAKb,CAAM,GAAA,UAAA,EAAY,KAAK,CAACiB,MAAS;AACrC,WAAK,QAAQA;AAAA,IAAA,CAEb,GAEDF,EAAA,MAAKb,GAALE,CAAA,EAAA,KAAA,IAAA;AAAA,EACD;AAAA,EACA,IAAW,MAA2B;AACrC,WAAOS,EAAK,MAAAb,CAAA;AAAA,EACb;AAAA,EA0BA,MAAc,SAASkB,GAAmB;AACzC,IAAI,KAAK,SACRA,EAAM,gBAAgB,GAGvB,KAAK,eAAe;AAEhB,QAAA;AACH,UAAI,CAACL,EAAK,MAAAb,CAAA,EAAY,OAAA,IAAI,MAAM,gBAAgB;AAC1C,YAAAa,EAAA,MAAKb,GAAK,QAAQ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