@dxos/lit-ui 0.10.0 → 0.11.0

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": "@dxos/lit-ui",
3
- "version": "0.10.0",
3
+ "version": "0.11.0",
4
4
  "description": "Web Components for DXOS using Lit",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -35,13 +35,13 @@
35
35
  ],
36
36
  "dependencies": {
37
37
  "@lit/react": "^1.0.8",
38
- "lit": "^3.3.1",
39
- "@dxos/react-hooks": "0.10.0",
40
- "@dxos/ui-types": "0.10.0",
41
- "@dxos/util": "0.10.0"
38
+ "lit": "^3.3.3",
39
+ "@dxos/react-hooks": "0.11.0",
40
+ "@dxos/ui-types": "0.11.0",
41
+ "@dxos/util": "0.11.0"
42
42
  },
43
43
  "devDependencies": {
44
- "@dxos/test-utils": "0.10.0"
44
+ "@dxos/test-utils": "0.11.0"
45
45
  },
46
46
  "publishConfig": {
47
47
  "access": "public"
@@ -7,7 +7,18 @@ import { customElement, property } from 'lit/decorators.js';
7
7
 
8
8
  import { type Size } from '../defs';
9
9
 
10
- const ICONS_URL = '/icons.svg';
10
+ // Shared with @dxos/react-ui's IconRegistry; see IconRegistry.tsx for the bridge contract.
11
+ const REGISTRY_GLOBAL = '__dxIconRegistry';
12
+
13
+ type IconRegistry = {
14
+ hasIcon(name: string): boolean;
15
+ requestIcon(name: string): void;
16
+ subscribe(listener: () => void): () => void;
17
+ };
18
+
19
+ type RegistryHost = { [REGISTRY_GLOBAL]?: IconRegistry };
20
+
21
+ const getRegistry = (): IconRegistry | undefined => (globalThis as unknown as RegistryHost)[REGISTRY_GLOBAL];
11
22
 
12
23
  @customElement('dx-icon')
13
24
  export class DxIcon extends LitElement {
@@ -18,16 +29,44 @@ export class DxIcon extends LitElement {
18
29
  @property({ type: String })
19
30
  icon: string = 'ph--circle-dashed--regular';
20
31
 
21
- @property({ type: Boolean })
22
- noCache: boolean = true;
32
+ #unsubscribe?: () => void;
33
+
34
+ override disconnectedCallback(): void {
35
+ super.disconnectedCallback();
36
+ this.#unwatchRegistry();
37
+ }
23
38
 
24
39
  override render() {
25
- const url = this.noCache ? `${ICONS_URL}?nocache=${new Date().getMinutes()}` : ICONS_URL;
26
- const href = `${url}#${this.icon}`;
40
+ const registry = getRegistry();
41
+ if (registry && !registry.hasIcon(this.icon)) {
42
+ registry.requestIcon(this.icon);
43
+ // Omit the <use> while unresolved, mirroring useIconHref: the subscription re-renders
44
+ // once the symbol lands rather than leaving a transient broken ref in the DOM.
45
+ this.#watchRegistry(registry);
46
+ return svg`<svg class="dx-icon" data-size=${this.size}></svg>`;
47
+ }
48
+ this.#unwatchRegistry();
49
+ const href = `#${this.icon}`;
27
50
  return svg`<svg class="dx-icon" data-size=${this.size}><use href=${href} /></svg>`;
28
51
  }
29
52
 
30
53
  override createRenderRoot(): this {
31
54
  return this;
32
55
  }
56
+
57
+ #watchRegistry(registry: IconRegistry): void {
58
+ if (this.#unsubscribe) {
59
+ return;
60
+ }
61
+ this.#unsubscribe = registry.subscribe(() => {
62
+ if (registry.hasIcon(this.icon)) {
63
+ this.requestUpdate();
64
+ }
65
+ });
66
+ }
67
+
68
+ #unwatchRegistry(): void {
69
+ this.#unsubscribe?.();
70
+ this.#unsubscribe = undefined;
71
+ }
33
72
  }