You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
BlockquoteControllerContextMeta is a Lit Reactive Controller that encapsulates the controllers provided by @lit/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.
import{html,LitElement,css}from'lit';import{BlockquoteControllerContextMeta}from'@blockquote-web-components/blockquote-controller-context-meta';exportclassProviderElextendsLitElement{staticstyles=css` slot { display: block; border: dashed 4px grey; padding: 10px; } :host { display: block; border: solid 4px gainsboro; padding: 2px; } h3 { margin-top: 0; } `;staticproperties={data: {},};constructor(){super();this._provider=newBlockquoteControllerContextMeta(this,{context: Symbol.for('contextKey')});this.data='Initial';}// `data` will be provided to any consumer that is in the DOM tree below it.setdata(value){this._data=value;this._provider.setValue(value);}getdata(){returnthis._data;}render(){returnhtml`<h3>Provider's data: <code>${this.data}</code></h3><slot></slot> `;}}customElements.define('provider-el',ProviderEl);exportclassConsumerElextendsLitElement{_consumer=newBlockquoteControllerContextMeta(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`.getprovidedData(){returnthis._consumer.value;}render(){returnhtml`<h3>Consumer data: <code>${this.providedData}</code></h3><hr/><slot></slot>`;}}customElements.define('consumer-el',ConsumerEl);
src/BlockquoteControllerContextMeta.js:
class: ContextMeta
Fields
Name
Privacy
Type
Default
Description
Inherited From
value
context
initialValue
initialValue
callback
callback
host
host
Methods
Name
Privacy
Description
Parameters
Return
Inherited From
setValue
v, force
hostConnected
Variables
Name
Description
Type
contextMetaSymbol
Exports
Kind
Name
Declaration
Module
Package
js
contextMetaSymbol
contextMetaSymbol
src/BlockquoteControllerContextMeta.js
js
BlockquoteControllerContextMeta
ContextMeta
src/BlockquoteControllerContextMeta.js
src/index.js:
Exports
Kind
Name
Declaration
Module
Package
js
BlockquoteControllerContextMeta
BlockquoteControllerContextMeta
./BlockquoteControllerContextMeta.js
js
BaseContextMetaElement
BaseContextMetaElement
./BaseContextMetaElement.js
js
contextMetaProvider
contextMetaProvider
./directives/context-meta-provider.js
js
cacheContextMetaProvider
cacheContextMetaProvider
./directives/cache-context-meta-provider.js
contextMetaProviderDirective is a Lit directive that enables normal DOM elements to act as context providers.
You can use this directive in both attribute and element bindings in Lit templates.
Usage:
This directive transforms a DOM element into a Lit context provider using the BlockquoteControllerContextMeta class, a
Lit Reactive Controller that encapsulates controllers provided by @lit/context.
Utilizes BlockquoteControllerContextMeta, a Lit Reactive Controller for managing context.
<div${contextMetaProviderDirective(someValue,myContext)}>
<!-- Children can consume the provided context -->
</div>//<divdata-info="${contextMetaProviderDirective(someValue, myContext)}">
<!-- Children can consume the provided context -->
</div>
src/directives/context-meta-provider.js:
class: README
Variables
Name
Description
Type
contextMetaProvider
Exports
Kind
Name
Declaration
Module
Package
js
README
README
src/directives/context-meta-provider.js
js
contextMetaProvider
contextMetaProvider
src/directives/context-meta-provider.js
src/directives/cache-context-meta-provider.js:
Functions
Name
Description
Parameters
Return
cacheContextMetaProvider
Return or create a cached BlockquoteControllerContextMeta for (element, context).
This function memoizes BlockquoteControllerContextMeta instances per (element, contextKey).
If a BlockquoteControllerContextMeta already exists for the given element and context, it is
returned; otherwise a new BlockquoteControllerContextMeta is created, cached and returned.
BaseContextMetaElement emulates the behavior of a flow element using ARIA, preserving standard HTML functionality while enhancing its features.
Demo
Features
Acts as a structural element that follows HTML flow content rules.
Provides a default ARIA role (none) to avoid unintended semantics.
Can be used as a wrapper for contextual metadata.
Accessibility
By default, BaseContextMetaElementassigns the role="none",
ensuring that it does not introduce unintended semantics in assistive technologies.
This behavior can be overridden by explicitly setting a different role.