import type { UmbContextToken } from '../token/index.js'; import type { UmbContextMinimal } from '../types.js'; import type { UmbContextCallback } from './context-request.event.js'; export interface UmbConsumeOptions { /** * The context to consume, either as a string alias or an UmbContextToken. */ context: string | UmbContextToken; /** * An optional callback that is invoked when the context value is set or changes. * Note, the class instance is probably not fully constructed when this is first invoked. * If you need to ensure the class is fully constructed, consider using a setter on the property instead. */ callback?: UmbContextCallback; /** * If true, the context consumer will stay active and invoke the callback on context changes. * If false, the context consumer will use asPromise() to get the value once and then clean up. * @default true */ subscribe?: boolean; } /** * A property decorator that adds an UmbContextConsumerController to the component * which will try and retrieve a value for the property via the Umbraco Context API. * * This decorator supports both modern "standard" decorators (Stage 3 TC39 proposal) and * legacy TypeScript experimental decorators for backward compatibility. * @param {UmbConsumeOptions} options Configuration object containing context, callback, and subscribe options * @example * ```ts * import {consumeContext} from '../index.js'; * import {UMB_WORKSPACE_CONTEXT} from './workspace.context-token.js'; * * class MyElement extends UmbLitElement { * // Standard decorators (with 'accessor' keyword) - Modern approach * @consumeContext({context: UMB_WORKSPACE_CONTEXT}) * accessor workspaceContext?: UmbWorkspaceContext; * * // Legacy decorators (without 'accessor') - Works with @state/@property * @consumeContext({context: UMB_USER_CONTEXT, subscribe: false}) * @state() * currentUser?: UmbUserContext; * } * ``` * @returns {ConsumeDecorator} A property decorator function */ export declare function consumeContext(options: UmbConsumeOptions): ConsumeDecorator; /** * Generates a public interface type that removes private and protected fields. * This allows accepting otherwise incompatible versions of the type (e.g. from * multiple copies of the same package in `node_modules`). */ type Interface = { [K in keyof T]: T[K]; }; declare class ReactiveElement { static addInitializer?: (initializer: (instance: any) => void) => void; } declare class ReactiveController { hostConnected?: () => void; } /** * A type representing the base class of which the decorator should work * requiring either addInitializer (UmbLitElement) or hostConnected (UmbController). */ type ReactiveEntity = ReactiveElement | ReactiveController; type ConsumeDecorator = { >(protoOrDescriptor: Proto, name?: K): FieldMustMatchProvidedType; , V extends ValueType>(value: ClassAccessorDecoratorTarget, context: ClassAccessorDecoratorContext): void; }; type DecoratorReturn = void | any; type FieldMustMatchProvidedType = Obj extends Record ? [ ProvidedType ] extends [ConsumingType] ? DecoratorReturn : { message: 'provided type not assignable to consuming field'; provided: ProvidedType; consuming: ConsumingType; } : Obj extends Partial> ? [ ProvidedType ] extends [ConsumingType | undefined] ? DecoratorReturn : { message: 'provided type not assignable to consuming field'; provided: ProvidedType; consuming: ConsumingType | undefined; } : DecoratorReturn; export {};