import type { Context, ContextType } from '@lit/context'; import type { ReactiveController, ReactiveControllerHost } from 'lit'; export declare const contextMetaSymbol: unique symbol; /** * ![Lit](https://img.shields.io/badge/lit-3.0.0-blue.svg) * * `BlockquoteControllerContextMeta` is a Lit Reactive Controller that encapsulates the controllers provided by [@lit/context](https://lit.dev/docs/data/context/) * * **Features:** * - Allows a component to act simultaneously as a provider and a consumer. * - Delays consumer initialization until after the first update, minimizing the risk of a consumer in the Light DOM requesting a context before a provider is available. *
* * ### Demo * * [![Open in StackBlitz](https://developer.stackblitz.com/img/open_in_stackblitz.svg)](https://stackblitz.com/github/oscarmarina/blockquote-web-components/tree/main/packages/controllers/blockquote-controller-context-meta) * * ### Usage * - [Lit examples context-basics](https://lit.dev/playground/#sample=examples/context-basics) * ```js * * import { html, LitElement, css } from 'lit'; * import { BlockquoteControllerContextMeta } from '@blockquote-web-components/blockquote-controller-context-meta'; * * export class ProviderEl extends LitElement { * static styles = css` * slot { * display: block; * border: dashed 4px grey; * padding: 10px; * } * * :host { * display: block; * border: solid 4px gainsboro; * padding: 2px; * } * * h3 { * margin-top: 0; * } * `; * * static properties = { * data: {}, * }; * * constructor() { * super(); * this._provider = new BlockquoteControllerContextMeta(this, { * context: Symbol.for('contextKey') * }); * * this.data = 'Initial'; * } * * // `data` will be provided to any consumer that is in the DOM tree below it. * set data(value) { * this._data = value; * this._provider.setValue(value); * } * * get data() { * return this._data; * } * * render() { * return html` *

Provider's data: ${this.data}

* * `; * } * } * customElements.define('provider-el', ProviderEl); * * export class ConsumerEl extends LitElement { * _consumer = new BlockquoteControllerContextMeta(this, { * context: Symbol.for('contextKey') * callback: (v) => { * this.setAttribute('data-callback', v); * }, * }); * * * // `providedData` will be populated by the first ancestor element which * // provides a value for `context`. * * get providedData() { * return this._consumer.value; * } * * render() { * return html`

Consumer data: ${this.providedData}

*
* `; * } * } * customElements.define('consumer-el', ConsumerEl); * ``` * *
*/ declare class ContextMeta, HostElement extends ReactiveControllerHost & HTMLElement> implements ReactiveController { private host; private context; private initialValue?; private callback?; private _contextMetaProvider?; private _contextMetaConsumer?; constructor(host: HostElement, { context, initialValue, callback, }: { context?: unknown; initialValue?: ContextType; callback?: (value: ContextType, dispose?: () => void) => void; }, isConsumerOnly?: boolean); get value(): ContextType | undefined; setValue(v: ContextType, force?: boolean): void; hostConnected(): Promise; } export { ContextMeta as BlockquoteControllerContextMeta };