global type definition

This commit is contained in:
Niels Lyngsø
2024-09-13 13:32:12 +02:00
parent ed32302c39
commit 5201dd6ca0
6 changed files with 42 additions and 15 deletions

View File

@@ -12,11 +12,6 @@ import type {
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';
import type { UmbDocumentUserPermissionConditionConfig } from '@umbraco-cms/backoffice/document';
/* TODO: in theory should't the core package import from other packages.
Are there any other way we can do this?
Niels: Sadly I don't see any other solutions currently. But are very open for ideas :-) now that I think about it maybe there is some ability to extend a global type, similar to the 'declare global' trick we use on Elements.
*/
// temp location to avoid circular dependencies
export type BlockWorkspaceHasSettingsConditionConfig =
UmbConditionConfigBase<'Umb.Condition.BlockWorkspaceHasSettings'>;
@@ -38,3 +33,36 @@ export type ConditionTypes =
| WorkspaceAliasConditionConfig
| WorkspaceContentTypeAliasConditionConfig
| WorkspaceEntityTypeConditionConfig;
type UnionOfProperties<T> = T extends object ? T[keyof T] : never;
declare global {
/**
* This global type allows to declare condition types from its own module.
* @example
```js
declare global {
interface UmbExtensionConditionMap {
My_UNIQUE_CONDITION_NAME: MyExtensionConditionType;
}
}
```
If you have multiple types, you can declare them in this way:
```js
declare global {
interface UmbExtensionConditionMap {
My_UNIQUE_CONDITION_NAME: MyExtensionConditionTypeA | MyExtensionConditionTypeB;
}
}
```
*/
interface UmbExtensionConditionMap {
UMB_CORE: ConditionTypes;
}
/**
* This global type provides a union of all declared manifest types.
* If this is a local package that declares additional Manifest Types, then these will also be included in this union.
*/
type UmbExtensionCondition = UnionOfProperties<UmbExtensionConditionMap>;
}

View File

@@ -1,4 +1,3 @@
import type { ConditionTypes } from '../conditions/types.js';
import type { ManifestElementAndApi, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api';
/**
@@ -6,7 +5,9 @@ import type { ManifestElementAndApi, ManifestWithDynamicConditions } from '@umbr
* For example for content you may wish to create a new document etc
*/
// TODO: create interface for API
export interface ManifestCollectionAction extends ManifestElementAndApi, ManifestWithDynamicConditions<ConditionTypes> {
export interface ManifestCollectionAction
extends ManifestElementAndApi,
ManifestWithDynamicConditions<UmbExtensionCondition> {
type: 'collectionAction';
meta: MetaCollectionAction;
}

View File

@@ -1,7 +1,6 @@
import type { ConditionTypes } from '../conditions/types.js';
import type { ManifestElement, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api';
export interface ManifestCollectionView extends ManifestElement, ManifestWithDynamicConditions<ConditionTypes> {
export interface ManifestCollectionView extends ManifestElement, ManifestWithDynamicConditions<UmbExtensionCondition> {
type: 'collectionView';
meta: MetaCollectionView;
}

View File

@@ -1,7 +1,8 @@
import type { ConditionTypes } from '../conditions/types.js';
import type { ManifestElementAndApi, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api';
export interface ManifestCollection extends ManifestElementAndApi, ManifestWithDynamicConditions<ConditionTypes> {
export interface ManifestCollection
extends ManifestElementAndApi,
ManifestWithDynamicConditions<UmbExtensionCondition> {
type: 'collection';
meta: MetaCollection;
}

View File

@@ -1,4 +1,3 @@
import type { ConditionTypes } from '../conditions/types.js';
import type { UmbAction } from '../../action/action.interface.js';
import type { UmbControllerHostElement } from '@umbraco-cms/backoffice/controller-api';
import type { ManifestElementAndApi, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api';
@@ -24,7 +23,7 @@ export interface UmbCurrentUserAction<ArgsMetaType = never> extends UmbAction<Um
export interface ManifestCurrentUserAction<MetaType extends MetaCurrentUserAction = MetaCurrentUserAction>
extends ManifestElementAndApi<UmbControllerHostElement, UmbCurrentUserAction<MetaType>>,
ManifestWithDynamicConditions<ConditionTypes> {
ManifestWithDynamicConditions<UmbExtensionCondition> {
type: 'currentUserAction';
meta: MetaType;
}

View File

@@ -1,10 +1,9 @@
import type { ConditionTypes } from '../conditions/types.js';
import type { UmbDashboardElement } from '../interfaces/index.js';
import type { ManifestElement, ManifestWithDynamicConditions } from '@umbraco-cms/backoffice/extension-api';
export interface ManifestDashboard
extends ManifestElement<UmbDashboardElement>,
ManifestWithDynamicConditions<ConditionTypes> {
ManifestWithDynamicConditions<UmbExtensionCondition> {
type: 'dashboard';
meta: MetaDashboard;
}