@blockquote-web-components/blockquote-controller-context-meta 1.5.3 → 1.5.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@blockquote-web-components/blockquote-controller-context-meta",
|
|
3
|
-
"version": "1.5.
|
|
3
|
+
"version": "1.5.4",
|
|
4
4
|
"description": "Webcomponent blockquote-controller-context-meta following open-wc recommendations",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"lit",
|
|
@@ -127,6 +127,5 @@
|
|
|
127
127
|
"publishConfig": {
|
|
128
128
|
"access": "public"
|
|
129
129
|
},
|
|
130
|
-
"customElements": "custom-elements.json"
|
|
131
|
-
"gitHead": "e51976ff34663ccf6848bfaa1efbd55cde17c55f"
|
|
130
|
+
"customElements": "custom-elements.json"
|
|
132
131
|
}
|
|
@@ -1,6 +1,44 @@
|
|
|
1
1
|
import {createContext, ContextProvider, ContextConsumer} from '@lit/context';
|
|
2
2
|
|
|
3
3
|
export const contextMetaSymbol = Symbol.for('context-meta-symbol');
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* https://github.com/lit/lit/issues/5116
|
|
7
|
+
* https://discord.com/channels/1012791295170859069/1424796337433612379/1425587605503869030
|
|
8
|
+
*
|
|
9
|
+
* @extends {ContextProvider<*, *>}
|
|
10
|
+
*/
|
|
11
|
+
// @ts-ignore
|
|
12
|
+
class ContextProviderHs extends ContextProvider {
|
|
13
|
+
// @ts-ignore
|
|
14
|
+
attachListeners() {
|
|
15
|
+
this.host.addEventListener('context-request', this.onContextRequest);
|
|
16
|
+
let pending = false;
|
|
17
|
+
/* v8 ignore next */
|
|
18
|
+
this.host.addEventListener('context-provider', (/** @type {*} */ ev) => {
|
|
19
|
+
if (!this.host.hasUpdated) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
if (ev.context !== this.context) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
const childProviderHost = ev.contextTarget ?? ev.composedPath()[0];
|
|
27
|
+
if (childProviderHost === this.host) {
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
ev.stopPropagation();
|
|
31
|
+
if (pending) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
pending = true;
|
|
35
|
+
this.host.updateComplete.then(() => {
|
|
36
|
+
this.onProviderRequest(ev);
|
|
37
|
+
pending = false;
|
|
38
|
+
});
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
}
|
|
4
42
|
/**
|
|
5
43
|
* 
|
|
6
44
|
*
|
|
@@ -117,7 +155,7 @@ class ContextMeta {
|
|
|
117
155
|
this.host = host;
|
|
118
156
|
|
|
119
157
|
if (!isConsumerOnly) {
|
|
120
|
-
this._contextMetaProvider = new
|
|
158
|
+
this._contextMetaProvider = new ContextProviderHs(this.host, {
|
|
121
159
|
context: this.context,
|
|
122
160
|
initialValue: this.initialValue,
|
|
123
161
|
});
|
|
@@ -130,6 +168,10 @@ class ContextMeta {
|
|
|
130
168
|
return this._contextMetaConsumer?.value;
|
|
131
169
|
}
|
|
132
170
|
|
|
171
|
+
/**
|
|
172
|
+
* @param {any} v
|
|
173
|
+
* @param {boolean} [force=false]
|
|
174
|
+
*/
|
|
133
175
|
setValue(v, force = false) {
|
|
134
176
|
this._contextMetaProvider?.setValue?.(v, force);
|
|
135
177
|
}
|