@dxos/react-ui-attention 0.9.0 → 0.9.1-staging.ee54ba693a

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.
Files changed (83) hide show
  1. package/dist/lib/browser/chunk-4HYAJ4IO.mjs +434 -0
  2. package/dist/lib/browser/chunk-4HYAJ4IO.mjs.map +7 -0
  3. package/dist/lib/browser/{chunk-I4VO2RQM.mjs → chunk-I4FDY4AZ.mjs} +92 -111
  4. package/dist/lib/browser/chunk-I4FDY4AZ.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +36 -15
  6. package/dist/lib/browser/index.mjs.map +3 -3
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +4 -4
  9. package/dist/lib/browser/testing/index.mjs.map +2 -2
  10. package/dist/lib/browser/types/index.mjs +19 -5
  11. package/dist/lib/node-esm/{chunk-ZTUVSH4P.mjs → chunk-DLBZMHST.mjs} +92 -111
  12. package/dist/lib/node-esm/chunk-DLBZMHST.mjs.map +7 -0
  13. package/dist/lib/node-esm/chunk-HWN7KJDX.mjs +436 -0
  14. package/dist/lib/node-esm/chunk-HWN7KJDX.mjs.map +7 -0
  15. package/dist/lib/node-esm/index.mjs +36 -15
  16. package/dist/lib/node-esm/index.mjs.map +3 -3
  17. package/dist/lib/node-esm/meta.json +1 -1
  18. package/dist/lib/node-esm/testing/index.mjs +4 -4
  19. package/dist/lib/node-esm/testing/index.mjs.map +2 -2
  20. package/dist/lib/node-esm/types/index.mjs +19 -5
  21. package/dist/types/src/components/AttentionGlyph/AttentionGlyph.d.ts.map +1 -1
  22. package/dist/types/src/components/AttentionProvider/AttentionProvider.d.ts +1 -1
  23. package/dist/types/src/components/AttentionProvider/AttentionProvider.d.ts.map +1 -1
  24. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.d.ts +31 -0
  25. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.d.ts.map +1 -0
  26. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.test.d.ts +2 -0
  27. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.test.d.ts.map +1 -0
  28. package/dist/types/src/components/ViewStateProvider/index.d.ts +2 -0
  29. package/dist/types/src/components/ViewStateProvider/index.d.ts.map +1 -0
  30. package/dist/types/src/components/index.d.ts +1 -1
  31. package/dist/types/src/index.d.ts +1 -0
  32. package/dist/types/src/index.d.ts.map +1 -1
  33. package/dist/types/src/selection.d.ts +10 -40
  34. package/dist/types/src/selection.d.ts.map +1 -1
  35. package/dist/types/src/selection.test.d.ts +2 -0
  36. package/dist/types/src/selection.test.d.ts.map +1 -0
  37. package/dist/types/src/types/index.d.ts +1 -0
  38. package/dist/types/src/types/index.d.ts.map +1 -1
  39. package/dist/types/src/useArticleKeyboardNavigation.d.ts.map +1 -1
  40. package/dist/types/src/view-state/backends.d.ts +24 -0
  41. package/dist/types/src/view-state/backends.d.ts.map +1 -0
  42. package/dist/types/src/view-state/backends.test.d.ts +2 -0
  43. package/dist/types/src/view-state/backends.test.d.ts.map +1 -0
  44. package/dist/types/src/view-state/index.d.ts +3 -0
  45. package/dist/types/src/view-state/index.d.ts.map +1 -0
  46. package/dist/types/src/view-state/view-state.d.ts +54 -0
  47. package/dist/types/src/view-state/view-state.d.ts.map +1 -0
  48. package/dist/types/src/view-state/view-state.test.d.ts +2 -0
  49. package/dist/types/src/view-state/view-state.test.d.ts.map +1 -0
  50. package/dist/types/src/vitest-setup.d.ts +2 -0
  51. package/dist/types/src/vitest-setup.d.ts.map +1 -0
  52. package/dist/types/tsconfig.tsbuildinfo +1 -1
  53. package/package.json +22 -20
  54. package/src/components/AttentionGlyph/AttentionGlyph.tsx +1 -1
  55. package/src/components/AttentionProvider/AttentionProvider.tsx +3 -3
  56. package/src/components/ViewStateProvider/ViewStateProvider.test.tsx +45 -0
  57. package/src/components/ViewStateProvider/ViewStateProvider.tsx +129 -0
  58. package/src/components/ViewStateProvider/index.ts +5 -0
  59. package/src/components/index.ts +1 -1
  60. package/src/index.ts +1 -0
  61. package/src/selection.test.ts +67 -0
  62. package/src/selection.ts +39 -169
  63. package/src/testing/decorators/withAttention.ts +2 -2
  64. package/src/types/index.ts +1 -0
  65. package/src/useArticleKeyboardNavigation.ts +5 -4
  66. package/src/view-state/backends.test.ts +104 -0
  67. package/src/view-state/backends.ts +145 -0
  68. package/src/view-state/index.ts +6 -0
  69. package/src/view-state/view-state.test.ts +54 -0
  70. package/src/view-state/view-state.ts +91 -0
  71. package/src/vitest-setup.ts +6 -0
  72. package/dist/lib/browser/chunk-D2BLVJ6Z.mjs +0 -421
  73. package/dist/lib/browser/chunk-D2BLVJ6Z.mjs.map +0 -7
  74. package/dist/lib/browser/chunk-I4VO2RQM.mjs.map +0 -7
  75. package/dist/lib/node-esm/chunk-6INLBC62.mjs +0 -423
  76. package/dist/lib/node-esm/chunk-6INLBC62.mjs.map +0 -7
  77. package/dist/lib/node-esm/chunk-ZTUVSH4P.mjs.map +0 -7
  78. package/dist/types/src/components/SelectionProvider/SelectionProvider.d.ts +0 -28
  79. package/dist/types/src/components/SelectionProvider/SelectionProvider.d.ts.map +0 -1
  80. package/dist/types/src/components/SelectionProvider/index.d.ts +0 -2
  81. package/dist/types/src/components/SelectionProvider/index.d.ts.map +0 -1
  82. package/src/components/SelectionProvider/SelectionProvider.tsx +0 -174
  83. package/src/components/SelectionProvider/index.ts +0 -5
@@ -0,0 +1,104 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { Registry } from '@effect-atom/atom-react';
6
+ import * as Schema from 'effect/Schema';
7
+ import { afterEach, describe, test } from 'vitest';
8
+
9
+ import { LocalBackend } from './backends';
10
+ import { ViewStateManager, defineViewState } from './view-state';
11
+
12
+ const Editor = defineViewState({
13
+ key: 'editor',
14
+ backend: 'local',
15
+ schema: Schema.Struct({ scrollTo: Schema.optional(Schema.Number) }).pipe(Schema.mutable),
16
+ defaultValue: () => ({}),
17
+ });
18
+
19
+ // Minimal in-memory Storage stand-in (no real localStorage in the test runner).
20
+ const fakeStorage = (): Storage => {
21
+ const map = new Map<string, string>();
22
+ return {
23
+ get length() {
24
+ return map.size;
25
+ },
26
+ clear: () => map.clear(),
27
+ getItem: (key) => (map.has(key) ? map.get(key)! : null),
28
+ key: (index) => [...map.keys()][index] ?? null,
29
+ removeItem: (key) => void map.delete(key),
30
+ setItem: (key, value) => void map.set(key, value),
31
+ };
32
+ };
33
+
34
+ describe('LocalBackend', () => {
35
+ // Dispose every backend after each test so its global `storage` listener does not leak across the suite.
36
+ const disposables: LocalBackend[] = [];
37
+ afterEach(() => {
38
+ disposables.splice(0).forEach((backend) => backend.dispose());
39
+ });
40
+
41
+ const make = () => {
42
+ const registry = Registry.make();
43
+ const storage = fakeStorage();
44
+ const local = new LocalBackend({ registry, storage });
45
+ disposables.push(local);
46
+ const manager = new ViewStateManager({ registry, backends: { memory: local, local } });
47
+ return { manager, storage };
48
+ };
49
+
50
+ test('default until written', ({ expect }) => {
51
+ const { manager } = make();
52
+ expect(manager.get(Editor, 'doc-1')).toEqual({});
53
+ });
54
+
55
+ test('set persists encoded JSON under the namespaced key', ({ expect }) => {
56
+ const { manager, storage } = make();
57
+ manager.set(Editor, 'doc-1', { scrollTo: 42 });
58
+ expect(JSON.parse(storage.getItem('dxos:view-state:editor:doc-1')!)).toEqual({ scrollTo: 42 });
59
+ });
60
+
61
+ test('reading does not write defaults to storage', ({ expect }) => {
62
+ const { manager, storage } = make();
63
+ manager.get(Editor, 'doc-1');
64
+ expect(storage.getItem('dxos:view-state:editor:doc-1')).toBeNull();
65
+ });
66
+
67
+ test('seeds atom from pre-existing storage value', ({ expect }) => {
68
+ const { manager, storage } = make();
69
+ storage.setItem('dxos:view-state:editor:doc-2', JSON.stringify({ scrollTo: 7 }));
70
+ expect(manager.get(Editor, 'doc-2')).toEqual({ scrollTo: 7 });
71
+ });
72
+
73
+ test('falls back to default on unparseable storage value', ({ expect }) => {
74
+ const { manager, storage } = make();
75
+ storage.setItem('dxos:view-state:editor:doc-3', '{not json');
76
+ expect(manager.get(Editor, 'doc-3')).toEqual({});
77
+ });
78
+
79
+ test('contexts enumerates persisted contexts', ({ expect }) => {
80
+ const { manager } = make();
81
+ manager.set(Editor, 'doc-1', { scrollTo: 1 });
82
+ manager.set(Editor, 'doc-2', { scrollTo: 2 });
83
+ expect(new Set(manager.contexts(Editor))).toEqual(new Set(['doc-1', 'doc-2']));
84
+ });
85
+
86
+ test('a cross-tab storage event re-reads the atom from storage', ({ expect }) => {
87
+ const registry = Registry.make();
88
+ const storage = fakeStorage();
89
+ const local = new LocalBackend({ registry, storage });
90
+ const manager = new ViewStateManager({ registry, backends: { memory: local, local } });
91
+
92
+ // Touch the context so its atom is registered and observed by the storage listener.
93
+ const key = 'dxos:view-state:editor:doc-4';
94
+ expect(manager.get(Editor, 'doc-4')).toEqual({});
95
+
96
+ // Simulate another tab's write: update storage, then fire the `storage` event (the listener
97
+ // re-reads from storage rather than trusting the event payload).
98
+ storage.setItem(key, JSON.stringify({ scrollTo: 99 }));
99
+ globalThis.dispatchEvent(new StorageEvent('storage', { key, newValue: storage.getItem(key) }));
100
+
101
+ expect(manager.get(Editor, 'doc-4')).toEqual({ scrollTo: 99 });
102
+ local.dispose();
103
+ });
104
+ });
@@ -0,0 +1,145 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { Atom, type Registry } from '@effect-atom/atom-react';
6
+ import * as Schema from 'effect/Schema';
7
+
8
+ import { type AspectDef, type BackendName, type ViewStateBackend } from './view-state';
9
+
10
+ // Only the stable `key` string is needed to form the map key; avoids variance issues with AspectDef<T>.
11
+ const cacheKey = (aspect: { key: string }, contextId: string) => `${aspect.key}:${contextId}`;
12
+
13
+ /** In-memory backend: state is ephemeral and scoped to the session (never persisted). */
14
+ export class MemoryBackend implements ViewStateBackend {
15
+ readonly #atoms = new Map<string, Atom.Writable<unknown>>();
16
+
17
+ atom<T>(aspect: AspectDef<T>, contextId: string): Atom.Writable<T> {
18
+ const key = cacheKey(aspect, contextId);
19
+ let atom = this.#atoms.get(key);
20
+ if (!atom) {
21
+ atom = Atom.make<unknown>(aspect.defaultValue());
22
+ this.#atoms.set(key, atom);
23
+ }
24
+ // Cast bridges the per-aspect value type erased by the shared atom map; safe by construction.
25
+ return atom as Atom.Writable<T>;
26
+ }
27
+
28
+ contexts<T>(aspect: AspectDef<T>): string[] {
29
+ const prefix = `${aspect.key}:`;
30
+ return [...this.#atoms.keys()].filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length));
31
+ }
32
+ }
33
+
34
+ const STORAGE_PREFIX = 'dxos:view-state:';
35
+
36
+ const storageKeyFor = (aspect: { key: string }, contextId: string) => `${STORAGE_PREFIX}${aspect.key}:${contextId}`;
37
+
38
+ // Accessing `globalThis.localStorage` can throw a SecurityError in sandboxed iframes or when
39
+ // storage is blocked; degrade to in-memory behaviour instead of crashing.
40
+ const safeLocalStorage = (): Storage | undefined => {
41
+ try {
42
+ return globalThis.localStorage;
43
+ } catch {
44
+ return undefined;
45
+ }
46
+ };
47
+
48
+ export interface LocalBackendOptions {
49
+ readonly registry: Registry.Registry;
50
+ /** Injectable for tests; defaults to `window.localStorage`. */
51
+ readonly storage?: Storage;
52
+ }
53
+
54
+ /** localStorage-backed backend: seeds atoms from storage, persists on set, syncs across tabs. */
55
+ export class LocalBackend implements ViewStateBackend {
56
+ readonly #registry: Registry.Registry;
57
+ // Absent in non-browser contexts (SSR/tests without injection); the backend then degrades to
58
+ // ephemeral, in-memory behaviour rather than crashing on a missing `localStorage`.
59
+ readonly #storage: Storage | undefined;
60
+ readonly #atoms = new Map<string, Atom.Writable<unknown>>();
61
+ // Reverse map: storage key -> (aspect, contextId) so `storage` events can target the right atom.
62
+ readonly #byStorageKey = new Map<string, { aspect: AspectDef<unknown>; contextId: string }>();
63
+ #storageListener?: (event: StorageEvent) => void;
64
+
65
+ constructor({ registry, storage }: LocalBackendOptions) {
66
+ this.#registry = registry;
67
+ this.#storage = storage ?? safeLocalStorage();
68
+ if (this.#storage && typeof globalThis.addEventListener === 'function') {
69
+ this.#storageListener = (event) => {
70
+ if (!event.key || !event.key.startsWith(STORAGE_PREFIX)) {
71
+ return;
72
+ }
73
+ const entry = this.#byStorageKey.get(event.key);
74
+ const atom = entry && this.#atoms.get(cacheKey(entry.aspect, entry.contextId));
75
+ if (entry && atom) {
76
+ this.#registry.set(atom, this.#read(entry.aspect, event.key));
77
+ }
78
+ };
79
+ globalThis.addEventListener('storage', this.#storageListener);
80
+ }
81
+ }
82
+
83
+ atom<T>(aspect: AspectDef<T>, contextId: string): Atom.Writable<T> {
84
+ const key = cacheKey(aspect, contextId);
85
+ let atom = this.#atoms.get(key);
86
+ if (!atom) {
87
+ const storageKey = storageKeyFor(aspect, contextId);
88
+ atom = Atom.make<unknown>(this.#read(aspect, storageKey));
89
+ this.#atoms.set(key, atom);
90
+ // Cast erases the per-aspect value type so the reverse map can hold aspects of any `T`; the
91
+ // stored aspect is only used to re-read/decode its own value, so the erasure is safe.
92
+ this.#byStorageKey.set(storageKey, { aspect: aspect as AspectDef<unknown>, contextId });
93
+ }
94
+ // Cast bridges the per-aspect value type erased by the shared atom map; safe by construction.
95
+ return atom as Atom.Writable<T>;
96
+ }
97
+
98
+ persist<T>(aspect: AspectDef<T>, contextId: string, value: T): void {
99
+ this.#storage?.setItem(storageKeyFor(aspect, contextId), JSON.stringify(Schema.encodeSync(aspect.schema)(value)));
100
+ }
101
+
102
+ contexts<T>(aspect: AspectDef<T>): string[] {
103
+ if (!this.#storage) {
104
+ // No persistent storage: fall back to the in-memory atoms (mirrors `atom()`'s ephemeral path).
105
+ const prefix = `${aspect.key}:`;
106
+ return [...this.#atoms.keys()].filter((key) => key.startsWith(prefix)).map((key) => key.slice(prefix.length));
107
+ }
108
+ const prefix = storageKeyFor(aspect, '');
109
+ const ids: string[] = [];
110
+ for (let index = 0; index < this.#storage.length; index++) {
111
+ const key = this.#storage.key(index);
112
+ if (key?.startsWith(prefix)) {
113
+ ids.push(key.slice(prefix.length));
114
+ }
115
+ }
116
+ return ids;
117
+ }
118
+
119
+ dispose(): void {
120
+ if (this.#storageListener && typeof globalThis.removeEventListener === 'function') {
121
+ globalThis.removeEventListener('storage', this.#storageListener);
122
+ }
123
+ // Allow safe reuse after disposal: drop cached atoms and their reverse-key entries.
124
+ this.#atoms.clear();
125
+ this.#byStorageKey.clear();
126
+ }
127
+
128
+ #read<T>(aspect: AspectDef<T>, storageKey: string): T {
129
+ const raw = this.#storage?.getItem(storageKey);
130
+ if (raw == null) {
131
+ return aspect.defaultValue();
132
+ }
133
+ try {
134
+ return Schema.decodeUnknownSync(aspect.schema)(JSON.parse(raw));
135
+ } catch {
136
+ // Tolerate stale/corrupt entries (e.g. a prior schema shape) by falling back to the default.
137
+ return aspect.defaultValue();
138
+ }
139
+ }
140
+ }
141
+
142
+ export const createDefaultBackends = (registry: Registry.Registry): Record<BackendName, ViewStateBackend> => ({
143
+ memory: new MemoryBackend(),
144
+ local: new LocalBackend({ registry }),
145
+ });
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ export * from './view-state';
6
+ export * from './backends';
@@ -0,0 +1,54 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { Registry } from '@effect-atom/atom-react';
6
+ import * as Schema from 'effect/Schema';
7
+ import { describe, test } from 'vitest';
8
+
9
+ import { createDefaultBackends } from './backends';
10
+ import { ViewStateManager, defineViewState } from './view-state';
11
+
12
+ const Counter = defineViewState({
13
+ key: 'counter',
14
+ backend: 'memory',
15
+ schema: Schema.Struct({ value: Schema.Number }).pipe(Schema.mutable),
16
+ defaultValue: () => ({ value: 0 }),
17
+ });
18
+
19
+ describe('ViewStateManager', () => {
20
+ const make = () => {
21
+ const registry = Registry.make();
22
+ return new ViewStateManager({ registry, backends: createDefaultBackends(registry) });
23
+ };
24
+
25
+ test('returns the aspect default for an unwritten context', ({ expect }) => {
26
+ const manager = make();
27
+ expect(manager.get(Counter, 'a')).toEqual({ value: 0 });
28
+ });
29
+
30
+ test('set then get round-trips per context', ({ expect }) => {
31
+ const manager = make();
32
+ manager.set(Counter, 'a', { value: 5 });
33
+ expect(manager.get(Counter, 'a')).toEqual({ value: 5 });
34
+ expect(manager.get(Counter, 'b')).toEqual({ value: 0 });
35
+ });
36
+
37
+ test('subscribe fires on change for that context', ({ expect }) => {
38
+ const manager = make();
39
+ let calls = 0;
40
+ const dispose = manager.subscribe(Counter, 'a', () => {
41
+ calls++;
42
+ });
43
+ manager.set(Counter, 'a', { value: 1 });
44
+ expect(calls).toBeGreaterThan(0);
45
+ dispose();
46
+ });
47
+
48
+ test('contexts enumerates touched contexts for an aspect', ({ expect }) => {
49
+ const manager = make();
50
+ manager.set(Counter, 'a', { value: 1 });
51
+ manager.set(Counter, 'b', { value: 2 });
52
+ expect(new Set(manager.contexts(Counter))).toEqual(new Set(['a', 'b']));
53
+ });
54
+ });
@@ -0,0 +1,91 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ import { type Atom, type Registry } from '@effect-atom/atom-react';
6
+ import type * as Schema from 'effect/Schema';
7
+
8
+ /**
9
+ * Persistence backend identifier. `personal` (ECHO/personal-space) is reserved for a future backend.
10
+ */
11
+ export type BackendName = 'memory' | 'local';
12
+
13
+ /**
14
+ * Declares a kind of per-context UI state. The value type `T` is inferred from the schema.
15
+ */
16
+ export interface AspectDef<T> {
17
+ readonly key: string;
18
+ readonly backend: BackendName;
19
+ // Encoded type is intentionally unconstrained: persisted backends serialize `T` through the
20
+ // schema to an arbitrary wire form, and only the decoded `T` matters to consumers.
21
+ readonly schema: Schema.Schema<T, any>;
22
+ readonly defaultValue: () => T;
23
+ }
24
+
25
+ /**
26
+ * Identity helper that pins the value type from the schema while keeping the literal `key`/`backend`.
27
+ */
28
+ export const defineViewState = <T>(def: AspectDef<T>): AspectDef<T> => def;
29
+
30
+ /**
31
+ * A backend produces a reactive, writable atom for each `(aspect, contextId)` pair. Backends may
32
+ * hydrate asynchronously (an ECHO backend would), yielding `aspect.defaultValue()` until loaded;
33
+ * the memory and local backends resolve synchronously.
34
+ */
35
+ export interface ViewStateBackend {
36
+ /** Stable atom for the pair; created (and seeded) on first access, cached thereafter. */
37
+ atom: <T>(aspect: AspectDef<T>, contextId: string) => Atom.Writable<T>;
38
+ /** Persist a value after the atom is updated. No-op for in-memory backends. */
39
+ persist?: <T>(aspect: AspectDef<T>, contextId: string, value: T) => void;
40
+ /** Context ids that currently hold a value for the aspect. */
41
+ contexts: <T>(aspect: AspectDef<T>) => string[];
42
+ /** Release listeners/timers (used by tests; app-lifetime managers do not call this). */
43
+ dispose?: () => void;
44
+ }
45
+
46
+ export interface ViewStateManagerOptions {
47
+ readonly registry: Registry.Registry;
48
+ readonly backends: Record<BackendName, ViewStateBackend>;
49
+ }
50
+
51
+ /**
52
+ * Routes per-context UI state to the backend declared by each aspect. Reads/writes go through the
53
+ * effect-atom registry so React hooks and graph atoms observe changes uniformly.
54
+ */
55
+ export class ViewStateManager {
56
+ readonly #registry: Registry.Registry;
57
+ readonly #backends: Record<BackendName, ViewStateBackend>;
58
+
59
+ constructor({ registry, backends }: ViewStateManagerOptions) {
60
+ this.#registry = registry;
61
+ this.#backends = backends;
62
+ }
63
+
64
+ /** Reactive atom for `(aspect, contextId)`; pass to `registry.get` inside derived atoms/hooks. */
65
+ atom<T>(aspect: AspectDef<T>, contextId: string): Atom.Writable<T> {
66
+ return this.#backends[aspect.backend].atom(aspect, contextId);
67
+ }
68
+
69
+ get<T>(aspect: AspectDef<T>, contextId: string): T {
70
+ return this.#registry.get(this.atom(aspect, contextId));
71
+ }
72
+
73
+ set<T>(aspect: AspectDef<T>, contextId: string, value: T): void {
74
+ const backend = this.#backends[aspect.backend];
75
+ this.#registry.set(backend.atom(aspect, contextId), value);
76
+ backend.persist?.(aspect, contextId, value);
77
+ }
78
+
79
+ update<T>(aspect: AspectDef<T>, contextId: string, fn: (prev: T) => T): void {
80
+ this.set(aspect, contextId, fn(this.get(aspect, contextId)));
81
+ }
82
+
83
+ subscribe<T>(aspect: AspectDef<T>, contextId: string, cb: (value: T) => void): () => void {
84
+ const atom = this.atom(aspect, contextId);
85
+ return this.#registry.subscribe(atom, () => cb(this.#registry.get(atom)));
86
+ }
87
+
88
+ contexts<T>(aspect: AspectDef<T>): string[] {
89
+ return this.#backends[aspect.backend].contexts(aspect);
90
+ }
91
+ }
@@ -0,0 +1,6 @@
1
+ //
2
+ // Copyright 2026 DXOS.org
3
+ //
4
+
5
+ // https://github.com/testing-library/jest-dom#with-vitest
6
+ import '@testing-library/jest-dom/vitest';