@blockquote-web-components/blockquote-controller-context-meta 1.5.2 → 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.2",
3
+ "version": "1.5.4",
4
4
  "description": "Webcomponent blockquote-controller-context-meta following open-wc recommendations",
5
5
  "keywords": [
6
6
  "lit",
@@ -48,8 +48,8 @@
48
48
  "sass:watch": "sass-style-template",
49
49
  "sort:package": "npx sort-package-json",
50
50
  "start": "concurrently -k -r \"npm:vite\" \"npm:sass:watch\"",
51
- "test": "vitest --run --browser.headless",
52
- "test:watch": "vitest",
51
+ "test": "vitest",
52
+ "test:watch": "vitest --browser.headless=false",
53
53
  "vite": "vite"
54
54
  },
55
55
  "lint-staged": {
@@ -122,11 +122,10 @@
122
122
  },
123
123
  "devDependencies": {
124
124
  "@blockquote-web-components/blockquote-base-common-dev-dependencies": "^1.12.6",
125
- "@blockquote-web-components/blockquote-base-embedded-webview": "^1.13.12"
125
+ "@blockquote-web-components/blockquote-base-embedded-webview": "^1.13.13"
126
126
  },
127
127
  "publishConfig": {
128
128
  "access": "public"
129
129
  },
130
- "customElements": "custom-elements.json",
131
- "gitHead": "f21ba4d9dc0f21f50eb164c105277027b03fc5b0"
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
  * ![Lit](https://img.shields.io/badge/lit-3.0.0-blue.svg)
6
44
  *
@@ -117,7 +155,7 @@ class ContextMeta {
117
155
  this.host = host;
118
156
 
119
157
  if (!isConsumerOnly) {
120
- this._contextMetaProvider = new ContextProvider(this.host, {
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
  }