import { Binding, type Subscription } from "@akala/core"; import type { IScope } from "../scope.js"; import type { Composer } from "../template.js"; import { AttributeComposer } from "./shared.js"; import { type Expressions, TypedExpression } from "@akala/core/expressions"; type Scope = IScope; export type IDataContext = Partial> = { context: Scope; controller: TController; }; /** * @class DataContext * @implements {Composer} * @description Manages and propagates data contexts within a DOM tree. */ export declare class DataContext implements Composer { /** * @readonly * @static * @description Properties that should be propagated. */ static readonly propagateProperties: string[]; /** * @static * @description Defines a data context for the given item and context. * @param {Element | ShadowRoot} item - The DOM element or shadow root to define the context for. * @param {object} context - The context to define. */ static define(item: Element | ShadowRoot): Binding; static define(item: Element | ShadowRoot, context?: T, newContextPath?: string | TypedExpression): Binding; /** * @static * @description Directly defines a data context for the given item and context. * @param {Element | ShadowRoot} item - The DOM element or shadow root to define the context for. * @param {Binding} context - The context to define. */ static defineDirect(item: Element | ShadowRoot, context: Binding): void; /** * @static * @description Extends the source context with additional options and a new context path. * @param {Binding} sourceContext - The source context to extend. * @param {object} options - Additional options to extend the context with. * @param {string} [newContextPath] - The new context path. * @returns {Binding} The extended context. */ static extend(sourceContext: Binding): Binding; static extend(sourceContext: Binding, options?: T, newContextPath?: string | TypedExpression): Binding; /** * @private * @readonly * @static * @description The data context expression. */ private static readonly dataContextExpression; /** * @constructor * @description Creates an instance of DataContext. */ constructor(); /** * @readonly * @description The CSS selector for elements with a data context. */ readonly selector: string; /** * @description Gets options for the context. * @param {object} options - The options to get. * @returns {{ context: Scope; controller: Partial; }} The context and controller options. */ optionGetter(options: IDataContext): IDataContext; /** * @description Applies the data context to the given item. * @param {HTMLElement} item - The item to apply the context to. * @param {{ context: Scope, controller: Partial }} [options] - The context options. * @param {HTMLElement | ShadowRoot} [root] - The root element or shadow root. * @returns {Disposable} The applied context. */ apply(item: HTMLElement, options?: { context: Scope; controller: Partial; }, root?: HTMLElement | ShadowRoot): Disposable; /** * @description Gets the data context for the given element. * @param {Element | ShadowRoot} element - The element to get the context for. * @param {true} alwaysDefined - Whether the context should always be defined. * @returns {Binding} The data context. */ static get(element: Element | ShadowRoot, alwaysDefined: true): Binding; static get(element: Element | ShadowRoot, alwaysDefined?: false): Binding | undefined; /** * @description Finds the data context for the given element. * @param {Element | ShadowRoot} element - The element to find the context for. * @returns {Binding} The found data context. */ static find(element: Element | ShadowRoot): Binding; } /** * Interface representing a plugin for data binding. */ export interface DataBindPlugin { /** * The CSS selector used to identify elements that this plugin applies to. */ selector: string; /** * Retrieves the bindings for a given element. * * @param item - The DOM element to get bindings for. * @param binding - The binding object associated with the element. * @param context - The context in which the binding is applied. * @param member - The member of the binding to retrieve. * @param source - The source expressions with length. * @returns A subscription to the bindings. */ getBindings(item: Element, binding: Binding, context: Binding, member: TKey, source: Expressions): Subscription; } /** * Represents a DataBind class that extends AttributeComposer and implements Composer. * This class provides methods for extending objects, binding data to elements, and applying bindings to elements. * * @template T - A type that extends Partial. */ export declare class DataBind> extends AttributeComposer implements Composer { /** * An array of DataBindPlugin instances. * @type {DataBindPlugin[]} */ static readonly plugins: DataBindPlugin[]; /** * Creates an instance of DataBind. */ constructor(); /** * Extends the target object with the properties from the extension object. * * @template T - A type that extends object. * @param {T} target - The target object to extend. * @param {Partial} extension - The extension object containing properties to add to the target. * @returns {T} - The extended target object. * @throws {Error} - Throws an error if a non-string key or value is encountered when extending a NamedNodeMap. */ static extend(target: T, extension: Partial): T; /** * Gets the data context for the specified HTML element. * * @param {HTMLElement} item - The HTML element to get the context for. * @param {T} [options] - Optional options to use when getting the context. * @returns {DataContext} - The data context for the specified HTML element. */ getContext(item: HTMLElement, options?: T): Binding>>; /** * The name of the option used for the controller. * @type {string} */ optionName: string; /** * Binds the specified options to the specified element. * * @template T - A type that extends object. * @param {Element} item - The element to bind the options to. * @param {T} options - The options to bind to the element. * @returns {() => void} - A function that can be called to dispose of the bindings. */ static bind(item: Element, options: T): Subscription; /** * Applies the specified options to the specified HTML element and root element. * * @param {HTMLElement} item - The HTML element to apply the options to. * @param {T} options - The options to apply to the element. * @param {Element | ShadowRoot} root - The root element to apply the options to. * @returns {{ [Symbol.dispose](): void }} - An object with a dispose method to clean up the applied options. */ apply(item: HTMLElement, options: T, root: Element | ShadowRoot): { [Symbol.dispose](): void; }; /** * Gets the bindings for the specified element, options, context, member, and source. * * @template TKey - A type that extends PropertyKey. * @param {Element} item - The element to get the bindings for. * @param {T} options - The options to use when getting the bindings. * @param {Binding} context - The binding context. * @param {TKey} member - The member to get the bindings for. * @param {ExpressionsWithLength} source - The source expressions. * @returns {readonly [TKey, Binding unknown> | ((...args: unknown[]) => unknown)>]} - The bindings for the specified element. */ getBindings(item: Element, options: T, context: Binding, member: TKey, source: Expressions): readonly [TKey, Binding unknown> | ((...args: unknown[]) => unknown)>]; /** * Applies the specified value to the specified sub-item of the specified element. * * @template TKey - A type that extends PropertyKey. * @param {Element} item - The element to apply the value to. * @param {T} options - The options to use when applying the value. * @param {TKey} subItem - The sub-item to apply the value to. * @param {unknown} value - The value to apply. * @returns {Subscription | void} - A subscription or void. */ applyInternal(item: Element, options: T, subItem: TKey, value: unknown): Subscription | void; /** * Applies the specified value to the specified sub-item of the specified element. * * @template TKey - A type that extends PropertyKey. * @template T - A type parameter. * @param {Element} item - The element to apply the value to. * @param {TKey} subItem - The sub-item to apply the value to. * @param {unknown} value - The value to apply. * @returns {Subscription | void} - A subscription or void. */ static applyInternal(item: Element, subItem: TKey, value: unknown): Subscription | void; } export {};