Compare commits

...
Author SHA1 Message Date
Niels Lyngsø 6292fc80f8 type hack 2026-01-16 11:15:39 +01:00
Niels Lyngsø 188c01e70f content tree item condition 2026-01-16 11:12:34 +01:00
Niels Lyngsø 163d787996 interface 2026-01-16 10:58:52 +01:00
6 changed files with 62 additions and 0 deletions
@@ -0,0 +1 @@
export const UMB_CONTENT_TREE_ITEM_TYPE_UNIQUE_CONDITION_ALIAS = 'Umb.Condition.Content.TreeItem.TypeUnique';
@@ -0,0 +1,38 @@
import type { UmbContentTreeItemTypeUniqueConditionConfig } from './types.js';
import { UmbConditionBase } from '@umbraco-cms/backoffice/extension-registry';
import { UMB_TREE_ITEM_CONTEXT } from '@umbraco-cms/backoffice/tree';
import type { UmbConditionControllerArguments, UmbExtensionCondition } from '@umbraco-cms/backoffice/extension-api';
import type { UmbControllerHost } from '@umbraco-cms/backoffice/controller-api';
export class UmbContentTreeItemTypeUniqueCondition
extends UmbConditionBase<UmbContentTreeItemTypeUniqueConditionConfig>
implements UmbExtensionCondition
{
constructor(
host: UmbControllerHost,
args: UmbConditionControllerArguments<UmbContentTreeItemTypeUniqueConditionConfig>,
) {
super(host, args);
this.consumeContext(UMB_TREE_ITEM_CONTEXT, (context) => {
this.observe((context as any)?.typeUnique, this.#check, '_UmbContentTreeItemTypeUniqueCondition');
});
}
#check = (value: string | undefined) => {
if (value === undefined) {
this.permitted = false;
return;
}
// if the config has a match, we only check that
if (this.config.match !== undefined) {
this.permitted = value === this.config.match;
return;
}
this.permitted = this.config.oneOf?.some((configValue) => configValue === value) ?? false;
};
}
export { UmbContentTreeItemTypeUniqueCondition as api };
@@ -0,0 +1,15 @@
import type { UMB_CONTENT_TREE_ITEM_TYPE_UNIQUE_CONDITION_ALIAS } from './constants.js';
import type { UmbConditionConfigBase } from '@umbraco-cms/backoffice/extension-api';
export type UmbContentTreeItemTypeUniqueConditionConfig = UmbConditionConfigBase<
typeof UMB_CONTENT_TREE_ITEM_TYPE_UNIQUE_CONDITION_ALIAS
> & {
match?: string;
oneOf?: Array<string>;
};
declare global {
interface UmbExtensionConditionConfigMap {
UmbContentTreeItemTypeUniqueConditionConfig: UmbContentTreeItemTypeUniqueConditionConfig;
}
}
@@ -0,0 +1,6 @@
import type { Observable } from '@umbraco-cms/backoffice/observable-api';
import type { UmbTreeItemContext } from '@umbraco-cms/backoffice/tree';
export interface UmbContentTreeItemContext extends UmbTreeItemContext {
typeUnique: Observable<string | undefined>;
}
@@ -0,0 +1 @@
export type * from './content-tree-item-context.interface.js';
@@ -2,6 +2,7 @@ import type { UmbEntityModel } from '@umbraco-cms/backoffice/entity';
import type { UmbTreeItemModel } from '@umbraco-cms/backoffice/tree';
export type * from './sort-children-of-content/types.js';
export type * from './tree-item/types.js';
export interface UmbContentTreeItemModel extends UmbTreeItemModel {
ancestors: Array<UmbEntityModel>;