@dxos/react-ui-attention 0.9.0 → 0.9.1-main.c7dcc2e112

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 (76) 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-KCQFVRZ6.mjs} +88 -112
  4. package/dist/lib/browser/chunk-KCQFVRZ6.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +29 -11
  6. package/dist/lib/browser/index.mjs.map +1 -1
  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-5JUZQDCR.mjs} +88 -112
  12. package/dist/lib/node-esm/chunk-5JUZQDCR.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 +29 -11
  16. package/dist/lib/node-esm/index.mjs.map +1 -1
  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/ViewStateProvider/ViewStateProvider.d.ts +29 -0
  22. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.d.ts.map +1 -0
  23. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.test.d.ts +2 -0
  24. package/dist/types/src/components/ViewStateProvider/ViewStateProvider.test.d.ts.map +1 -0
  25. package/dist/types/src/components/ViewStateProvider/index.d.ts +2 -0
  26. package/dist/types/src/components/ViewStateProvider/index.d.ts.map +1 -0
  27. package/dist/types/src/components/index.d.ts +1 -1
  28. package/dist/types/src/index.d.ts +1 -0
  29. package/dist/types/src/index.d.ts.map +1 -1
  30. package/dist/types/src/selection.d.ts +10 -40
  31. package/dist/types/src/selection.d.ts.map +1 -1
  32. package/dist/types/src/selection.test.d.ts +2 -0
  33. package/dist/types/src/selection.test.d.ts.map +1 -0
  34. package/dist/types/src/types/index.d.ts +1 -0
  35. package/dist/types/src/types/index.d.ts.map +1 -1
  36. package/dist/types/src/view-state/backends.d.ts +24 -0
  37. package/dist/types/src/view-state/backends.d.ts.map +1 -0
  38. package/dist/types/src/view-state/backends.test.d.ts +2 -0
  39. package/dist/types/src/view-state/backends.test.d.ts.map +1 -0
  40. package/dist/types/src/view-state/index.d.ts +3 -0
  41. package/dist/types/src/view-state/index.d.ts.map +1 -0
  42. package/dist/types/src/view-state/view-state.d.ts +54 -0
  43. package/dist/types/src/view-state/view-state.d.ts.map +1 -0
  44. package/dist/types/src/view-state/view-state.test.d.ts +2 -0
  45. package/dist/types/src/view-state/view-state.test.d.ts.map +1 -0
  46. package/dist/types/src/vitest-setup.d.ts +2 -0
  47. package/dist/types/src/vitest-setup.d.ts.map +1 -0
  48. package/dist/types/tsconfig.tsbuildinfo +1 -1
  49. package/package.json +15 -13
  50. package/src/components/ViewStateProvider/ViewStateProvider.test.tsx +45 -0
  51. package/src/components/ViewStateProvider/ViewStateProvider.tsx +123 -0
  52. package/src/components/ViewStateProvider/index.ts +5 -0
  53. package/src/components/index.ts +1 -1
  54. package/src/index.ts +1 -0
  55. package/src/selection.test.ts +67 -0
  56. package/src/selection.ts +39 -169
  57. package/src/testing/decorators/withAttention.ts +2 -2
  58. package/src/types/index.ts +1 -0
  59. package/src/view-state/backends.test.ts +104 -0
  60. package/src/view-state/backends.ts +145 -0
  61. package/src/view-state/index.ts +6 -0
  62. package/src/view-state/view-state.test.ts +54 -0
  63. package/src/view-state/view-state.ts +91 -0
  64. package/src/vitest-setup.ts +6 -0
  65. package/dist/lib/browser/chunk-D2BLVJ6Z.mjs +0 -421
  66. package/dist/lib/browser/chunk-D2BLVJ6Z.mjs.map +0 -7
  67. package/dist/lib/browser/chunk-I4VO2RQM.mjs.map +0 -7
  68. package/dist/lib/node-esm/chunk-6INLBC62.mjs +0 -423
  69. package/dist/lib/node-esm/chunk-6INLBC62.mjs.map +0 -7
  70. package/dist/lib/node-esm/chunk-ZTUVSH4P.mjs.map +0 -7
  71. package/dist/types/src/components/SelectionProvider/SelectionProvider.d.ts +0 -28
  72. package/dist/types/src/components/SelectionProvider/SelectionProvider.d.ts.map +0 -1
  73. package/dist/types/src/components/SelectionProvider/index.d.ts +0 -2
  74. package/dist/types/src/components/SelectionProvider/index.d.ts.map +0 -1
  75. package/src/components/SelectionProvider/SelectionProvider.tsx +0 -174
  76. package/src/components/SelectionProvider/index.ts +0 -5
@@ -1,423 +0,0 @@
1
- import { createRequire } from 'node:module';const require = createRequire(import.meta.url);
2
-
3
- // src/attention.ts
4
- import { Atom } from "@effect-atom/atom-react";
5
- var AttentionManager = class {
6
- _registry;
7
- _map = /* @__PURE__ */ new Map();
8
- _currentAtom;
9
- constructor(_registry, initial = []) {
10
- this._registry = _registry;
11
- this._currentAtom = Atom.make([]).pipe(Atom.keepAlive);
12
- if (initial.length > 0) {
13
- this.update(initial);
14
- }
15
- }
16
- /**
17
- * Atom for the currently attended element IDs.
18
- */
19
- get current() {
20
- return this._currentAtom;
21
- }
22
- /**
23
- * Gets the currently attended element IDs.
24
- */
25
- getCurrent() {
26
- return this._registry.get(this._currentAtom);
27
- }
28
- /**
29
- * Subscribe to changes in the current attention IDs.
30
- */
31
- subscribeCurrent(cb) {
32
- this._registry.get(this._currentAtom);
33
- return this._registry.subscribe(this._currentAtom, () => {
34
- cb(this._registry.get(this._currentAtom));
35
- });
36
- }
37
- /**
38
- * All tracked qualified IDs.
39
- */
40
- keys() {
41
- return Array.from(this._map.keys());
42
- }
43
- /**
44
- * Get the attention state for a given qualified ID.
45
- */
46
- get(id) {
47
- const atom = this._getAtom(id);
48
- return this._registry.get(atom);
49
- }
50
- /**
51
- * Subscribe to changes in the attention state for a given qualified ID.
52
- */
53
- subscribe(id, cb) {
54
- const atom = this._getAtom(id);
55
- this._registry.get(atom);
56
- return this._registry.subscribe(atom, () => {
57
- cb(this._registry.get(atom));
58
- });
59
- }
60
- _getAtom(id) {
61
- const existing = this._map.get(id);
62
- if (existing) {
63
- return existing;
64
- }
65
- const newAtom = Atom.make({
66
- hasAttention: false,
67
- isAncestor: false,
68
- isRelated: false
69
- }).pipe(Atom.keepAlive);
70
- this._map.set(id, newAtom);
71
- return newAtom;
72
- }
73
- /**
74
- * Update the currently attended element.
75
- * Takes the array of qualified IDs collected from the DOM; the first element is the primary attended item.
76
- * Ancestry is derived from the progressive prefixes of the primary ID.
77
- * Relatedness is derived from the segment ID: any tracked key whose last `/` segment matches the
78
- * attended ID's segment ID is marked `isRelated`. Additionally, if the primary ID is a linked segment
79
- * (starts with `~`), its immediate parent gets `isRelated` alongside `isAncestor`.
80
- *
81
- * @internal
82
- */
83
- update(nextIds) {
84
- const primaryId = nextIds[0];
85
- if (!primaryId) {
86
- return;
87
- }
88
- const currentIds = this.getCurrent();
89
- const prevPrimaryId = currentIds[0];
90
- if (prevPrimaryId) {
91
- const prevPrefixes = expandAttendableId(prevPrimaryId);
92
- for (const prefix of prevPrefixes) {
93
- this._set(prefix, {});
94
- }
95
- const prevSegmentId = getSegmentId(prevPrimaryId);
96
- for (const key of this.keys()) {
97
- if (getSegmentId(key) === prevSegmentId) {
98
- this._set(key, {});
99
- }
100
- }
101
- }
102
- this._registry.set(this._currentAtom, nextIds);
103
- const prefixes = expandAttendableId(primaryId);
104
- const prefixSet = new Set(prefixes);
105
- const linkedParent = isLinkedSegment(primaryId) ? getParentId(primaryId) : void 0;
106
- for (const prefix of prefixes) {
107
- if (prefix === primaryId) {
108
- this._set(prefix, {
109
- hasAttention: true
110
- });
111
- } else if (prefix === linkedParent) {
112
- this._set(prefix, {
113
- isAncestor: true,
114
- isRelated: true
115
- });
116
- } else {
117
- this._set(prefix, {
118
- isAncestor: true
119
- });
120
- }
121
- }
122
- const segmentId = getSegmentId(primaryId);
123
- for (const key of this.keys()) {
124
- if (!prefixSet.has(key) && getSegmentId(key) === segmentId) {
125
- this._set(key, {
126
- isRelated: true
127
- });
128
- }
129
- }
130
- }
131
- _set(id, attention) {
132
- const atom = this._getAtom(id);
133
- this._registry.set(atom, {
134
- hasAttention: attention.hasAttention ?? false,
135
- isAncestor: attention.isAncestor ?? false,
136
- isRelated: attention.isRelated ?? false
137
- });
138
- }
139
- };
140
- var getAttendables = (selector, cursor, acc = []) => {
141
- const closestAttendable = cursor.closest(selector);
142
- if (closestAttendable) {
143
- const attendableId = closestAttendable.getAttribute("data-attendable-id");
144
- if (!attendableId) {
145
- const trigger = document.querySelector(`[aria-controls="${closestAttendable.getAttribute("id")}"]`);
146
- if (!trigger) {
147
- return acc;
148
- } else {
149
- return getAttendables(selector, trigger, acc);
150
- }
151
- } else {
152
- acc.push(attendableId);
153
- return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);
154
- }
155
- }
156
- return [
157
- ...new Set(acc)
158
- ];
159
- };
160
- var LINKED_PREFIX = "~";
161
- var expandAttendableId = (qualifiedId) => {
162
- const segments = qualifiedId.split("/");
163
- return segments.map((_, index) => segments.slice(0, index + 1).join("/"));
164
- };
165
- var isLinkedSegment = (qualifiedId) => {
166
- const lastSegment = qualifiedId.split("/").pop() ?? "";
167
- return lastSegment.startsWith(LINKED_PREFIX);
168
- };
169
- var linkedSegment = (variant) => `${LINKED_PREFIX}${variant}`;
170
- var getLinkedVariant = (qualifiedId) => {
171
- const lastSegment = qualifiedId.split("/").pop() ?? "";
172
- return lastSegment.startsWith(LINKED_PREFIX) ? lastSegment.slice(LINKED_PREFIX.length) : lastSegment;
173
- };
174
- var getParentId = (qualifiedId) => {
175
- if (!qualifiedId) {
176
- return void 0;
177
- }
178
- const lastSlash = qualifiedId.lastIndexOf("/");
179
- return lastSlash > 0 ? qualifiedId.slice(0, lastSlash) : void 0;
180
- };
181
- var getSegmentId = (qualifiedId) => {
182
- return qualifiedId.split("/").pop() ?? qualifiedId;
183
- };
184
-
185
- // src/selection.ts
186
- import { Atom as Atom2 } from "@effect-atom/atom-react";
187
- import * as Match from "effect/Match";
188
- import * as Schema from "effect/Schema";
189
- import { invariant } from "@dxos/invariant";
190
- var __dxlog_file = "/__w/dxos/dxos/packages/ui/react-ui-attention/src/selection.ts";
191
- var SelectionSchema = Schema.Union(Schema.Struct({
192
- mode: Schema.Literal("single"),
193
- id: Schema.optional(Schema.String)
194
- }).pipe(Schema.mutable), Schema.Struct({
195
- mode: Schema.Literal("multi"),
196
- ids: Schema.Array(Schema.String).pipe(Schema.mutable)
197
- }).pipe(Schema.mutable), Schema.Struct({
198
- mode: Schema.Literal("range"),
199
- from: Schema.optional(Schema.String),
200
- to: Schema.optional(Schema.String)
201
- }).pipe(Schema.mutable), Schema.Struct({
202
- mode: Schema.Literal("multi-range"),
203
- ranges: Schema.Array(Schema.Struct({
204
- from: Schema.String,
205
- to: Schema.String
206
- })).pipe(Schema.mutable)
207
- }).pipe(Schema.mutable)).pipe(Schema.mutable);
208
- var defaultSelection = Match.type().pipe(Match.withReturnType(), Match.when("single", () => ({
209
- mode: "single"
210
- })), Match.when("multi", () => ({
211
- mode: "multi",
212
- ids: []
213
- })), Match.when("range", () => ({
214
- mode: "range"
215
- })), Match.when("multi-range", () => ({
216
- mode: "multi-range",
217
- ranges: []
218
- })), Match.exhaustive);
219
- var getSelectionSet = (selectionManager, contextId) => {
220
- const ids = new Set(contextId ? [
221
- contextId
222
- ] : []);
223
- for (const context of selectionManager.getSelectionContexts()) {
224
- const selection = selectionManager.getSelection(context);
225
- if (selection?.mode === "multi") {
226
- for (const id of selection.ids) {
227
- ids.add(id);
228
- }
229
- }
230
- }
231
- return ids;
232
- };
233
- var SelectionManager = class {
234
- _registry;
235
- _state;
236
- constructor(_registry, initial = {}) {
237
- this._registry = _registry;
238
- this._state = Atom2.make({
239
- selections: {
240
- ...initial
241
- }
242
- });
243
- }
244
- /**
245
- * Get the state atom for reactive access in the graph system.
246
- */
247
- get state() {
248
- return this._state;
249
- }
250
- /**
251
- * Gets the current state.
252
- */
253
- getState() {
254
- return this._registry.get(this._state);
255
- }
256
- /**
257
- * Subscribe to changes in the selection state.
258
- */
259
- subscribe(cb) {
260
- this._registry.get(this._state);
261
- return this._registry.subscribe(this._state, () => {
262
- cb(this._registry.get(this._state));
263
- });
264
- }
265
- getSelectionContexts() {
266
- return Object.keys(this._registry.get(this._state).selections);
267
- }
268
- getSelection(contextId, mode = void 0) {
269
- const state = this._registry.get(this._state);
270
- const selection = state.selections[contextId];
271
- if (!mode || selection) {
272
- return selection;
273
- }
274
- const newSelection = defaultSelection(mode);
275
- this._registry.update(this._state, (state2) => ({
276
- selections: {
277
- ...state2.selections,
278
- [contextId]: newSelection
279
- }
280
- }));
281
- return newSelection;
282
- }
283
- getSelected(contextId, mode = "multi") {
284
- const selection = this.getSelection(contextId, mode);
285
- invariant(selection?.mode === mode, "Selection mode mismatch", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 103, S: this, A: ["selection?.mode === mode", "'Selection mode mismatch'"] });
286
- return Match.type().pipe(Match.when({
287
- mode: "single"
288
- }, (s) => s.id), Match.when({
289
- mode: "multi"
290
- }, (s) => s.ids), Match.when({
291
- mode: "range"
292
- }, (s) => s.from && s.to ? {
293
- from: s.from,
294
- to: s.to
295
- } : void 0), Match.when({
296
- mode: "multi-range"
297
- }, (s) => s.ranges), Match.exhaustive)(selection);
298
- }
299
- updateSingle(contextId, id) {
300
- const selection = this.getSelection(contextId, "single");
301
- invariant(selection?.mode === "single", "Selection mode is not single", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 120, S: this, A: ["selection?.mode === 'single'", "'Selection mode is not single'"] });
302
- this._registry.update(this._state, (state) => ({
303
- selections: {
304
- ...state.selections,
305
- [contextId]: {
306
- ...selection,
307
- id
308
- }
309
- }
310
- }));
311
- }
312
- updateMulti(contextId, ids) {
313
- const selection = this.getSelection(contextId, "multi");
314
- invariant(selection?.mode === "multi", "Selection mode is not multi", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 133, S: this, A: ["selection?.mode === 'multi'", "'Selection mode is not multi'"] });
315
- this._registry.update(this._state, (state) => ({
316
- selections: {
317
- ...state.selections,
318
- [contextId]: {
319
- ...selection,
320
- ids: [
321
- ...ids
322
- ]
323
- }
324
- }
325
- }));
326
- }
327
- updateRange(contextId, from, to) {
328
- const selection = this.getSelection(contextId, "range");
329
- invariant(selection?.mode === "range", "Selection mode is not range", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 148, S: this, A: ["selection?.mode === 'range'", "'Selection mode is not range'"] });
330
- this._registry.update(this._state, (state) => ({
331
- selections: {
332
- ...state.selections,
333
- [contextId]: {
334
- ...selection,
335
- from,
336
- to
337
- }
338
- }
339
- }));
340
- }
341
- updateMultiRange(contextId, ranges) {
342
- const selection = this.getSelection(contextId, "multi-range");
343
- invariant(selection?.mode === "multi-range", "Selection mode is not multi-range", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 162, S: this, A: ["selection?.mode === 'multi-range'", "'Selection mode is not multi-range'"] });
344
- this._registry.update(this._state, (state) => ({
345
- selections: {
346
- ...state.selections,
347
- [contextId]: {
348
- ...selection,
349
- ranges: [
350
- ...ranges
351
- ]
352
- }
353
- }
354
- }));
355
- }
356
- clearSelection(contextId) {
357
- const selection = this.getSelection(contextId);
358
- if (!selection) {
359
- return;
360
- }
361
- const clearedSelection = Match.type().pipe(Match.when({
362
- mode: "single"
363
- }, (s) => ({
364
- ...s,
365
- id: void 0
366
- })), Match.when({
367
- mode: "multi"
368
- }, (s) => ({
369
- ...s,
370
- ids: []
371
- })), Match.when({
372
- mode: "range"
373
- }, (s) => ({
374
- ...s,
375
- from: void 0,
376
- to: void 0
377
- })), Match.when({
378
- mode: "multi-range"
379
- }, (s) => ({
380
- ...s,
381
- ranges: []
382
- })), Match.exhaustive)(selection);
383
- this._registry.update(this._state, (state) => ({
384
- selections: {
385
- ...state.selections,
386
- [contextId]: clearedSelection
387
- }
388
- }));
389
- }
390
- toggleSelection(contextId, id) {
391
- const selection = this.getSelection(contextId, "multi");
392
- invariant(selection?.mode === "multi", "Selection mode is not multi", { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 211, S: this, A: ["selection?.mode === 'multi'", "'Selection mode is not multi'"] });
393
- const newIds = selection.ids.includes(id) ? selection.ids.filter((existingId) => existingId !== id) : [
394
- ...selection.ids,
395
- id
396
- ];
397
- this._registry.update(this._state, (state) => ({
398
- selections: {
399
- ...state.selections,
400
- [contextId]: {
401
- ...selection,
402
- ids: newIds
403
- }
404
- }
405
- }));
406
- }
407
- };
408
-
409
- export {
410
- AttentionManager,
411
- getAttendables,
412
- expandAttendableId,
413
- isLinkedSegment,
414
- linkedSegment,
415
- getLinkedVariant,
416
- getParentId,
417
- getSegmentId,
418
- SelectionSchema,
419
- defaultSelection,
420
- getSelectionSet,
421
- SelectionManager
422
- };
423
- //# sourceMappingURL=chunk-6INLBC62.mjs.map
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/attention.ts", "../../../src/selection.ts"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { Atom, type Registry } from '@effect-atom/atom-react';\n\nexport type Attention = {\n hasAttention: boolean;\n isAncestor: boolean;\n isRelated: boolean;\n};\n\n/**\n * Manages attention state for an application.\n * Attention keys are slash-qualified graph IDs; ancestry is derived from progressive prefixes.\n */\nexport class AttentionManager {\n private readonly _map = new Map<string, Atom.Writable<Attention>>();\n private readonly _currentAtom: Atom.Writable<string[]>;\n\n constructor(\n private readonly _registry: Registry.Registry,\n initial: string[] = [],\n ) {\n this._currentAtom = Atom.make<string[]>([]).pipe(Atom.keepAlive);\n if (initial.length > 0) {\n this.update(initial);\n }\n }\n\n /**\n * Atom for the currently attended element IDs.\n */\n get current(): Atom.Atom<string[]> {\n return this._currentAtom;\n }\n\n /**\n * Gets the currently attended element IDs.\n */\n getCurrent(): readonly string[] {\n return this._registry.get(this._currentAtom);\n }\n\n /**\n * Subscribe to changes in the current attention IDs.\n */\n subscribeCurrent(cb: (current: readonly string[]) => void): () => void {\n this._registry.get(this._currentAtom);\n return this._registry.subscribe(this._currentAtom, () => {\n cb(this._registry.get(this._currentAtom));\n });\n }\n\n /**\n * All tracked qualified IDs.\n */\n keys(): string[] {\n return Array.from(this._map.keys());\n }\n\n /**\n * Get the attention state for a given qualified ID.\n */\n get(id: string): Attention {\n const atom = this._getAtom(id);\n return this._registry.get(atom);\n }\n\n /**\n * Subscribe to changes in the attention state for a given qualified ID.\n */\n subscribe(id: string, cb: (attention: Attention) => void): () => void {\n const atom = this._getAtom(id);\n this._registry.get(atom);\n return this._registry.subscribe(atom, () => {\n cb(this._registry.get(atom));\n });\n }\n\n private _getAtom(id: string): Atom.Writable<Attention> {\n const existing = this._map.get(id);\n if (existing) {\n return existing;\n }\n\n const newAtom = Atom.make<Attention>({ hasAttention: false, isAncestor: false, isRelated: false }).pipe(\n Atom.keepAlive,\n );\n this._map.set(id, newAtom);\n return newAtom;\n }\n\n /**\n * Update the currently attended element.\n * Takes the array of qualified IDs collected from the DOM; the first element is the primary attended item.\n * Ancestry is derived from the progressive prefixes of the primary ID.\n * Relatedness is derived from the segment ID: any tracked key whose last `/` segment matches the\n * attended ID's segment ID is marked `isRelated`. Additionally, if the primary ID is a linked segment\n * (starts with `~`), its immediate parent gets `isRelated` alongside `isAncestor`.\n *\n * @internal\n */\n update(nextIds: string[]): void {\n const primaryId = nextIds[0];\n if (!primaryId) {\n return;\n }\n\n const currentIds = this.getCurrent();\n const prevPrimaryId = currentIds[0];\n // Clear previous attention state: ancestors, primary, and related keys.\n if (prevPrimaryId) {\n const prevPrefixes = expandAttendableId(prevPrimaryId);\n for (const prefix of prevPrefixes) {\n this._set(prefix, {});\n }\n const prevSegmentId = getSegmentId(prevPrimaryId);\n for (const key of this.keys()) {\n if (getSegmentId(key) === prevSegmentId) {\n this._set(key, {});\n }\n }\n }\n\n this._registry.set(this._currentAtom, nextIds);\n\n // Set ancestors and primary.\n const prefixes = expandAttendableId(primaryId);\n const prefixSet = new Set(prefixes);\n const linkedParent = isLinkedSegment(primaryId) ? getParentId(primaryId) : undefined;\n\n for (const prefix of prefixes) {\n if (prefix === primaryId) {\n this._set(prefix, { hasAttention: true });\n } else if (prefix === linkedParent) {\n this._set(prefix, { isAncestor: true, isRelated: true });\n } else {\n this._set(prefix, { isAncestor: true });\n }\n }\n\n // Set related keys: any tracked key sharing the same segment ID.\n const segmentId = getSegmentId(primaryId);\n for (const key of this.keys()) {\n if (!prefixSet.has(key) && getSegmentId(key) === segmentId) {\n this._set(key, { isRelated: true });\n }\n }\n }\n\n private _set(id: string, attention: Partial<Attention>): void {\n const atom = this._getAtom(id);\n this._registry.set(atom, {\n hasAttention: attention.hasAttention ?? false,\n isAncestor: attention.isAncestor ?? false,\n isRelated: attention.isRelated ?? false,\n });\n }\n}\n\n/**\n * Accumulates all attendable IDs between the element provided and the root, inclusive.\n * Each `data-attendable-id` value is treated as a single qualified ID (no splitting).\n */\nexport const getAttendables = (selector: string, cursor: Element, acc: string[] = []): string[] => {\n // Find the closest element with `data-attendable-id`, if any; start from cursor and move up the DOM tree.\n const closestAttendable = cursor.closest(selector);\n if (closestAttendable) {\n const attendableId = closestAttendable.getAttribute('data-attendable-id');\n if (!attendableId) {\n // This has an id of an aria-controls elsewhere on the page, move cursor to that trigger.\n const trigger = document.querySelector(`[aria-controls=\"${closestAttendable.getAttribute('id')}\"]`);\n if (!trigger) {\n return acc;\n } else {\n return getAttendables(selector, trigger, acc);\n }\n } else {\n acc.push(attendableId);\n return !closestAttendable.parentElement ? acc : getAttendables(selector, closestAttendable.parentElement, acc);\n }\n }\n\n return [...new Set(acc)];\n};\n\nexport type AttendableId = { attendableId?: string };\n\nexport type Related = { related?: boolean };\n\n/**\n * Prefix for linked segments. A linked segment's attention state is shared with its parent:\n * when a linked node has attention, the parent is marked as both ancestor and related.\n */\nconst LINKED_PREFIX = '~';\n\n/**\n * Decompose a qualified graph ID into progressive prefixes for ancestry tracking.\n * e.g. `root/a/b/c` yields `['root', 'root/a', 'root/a/b', 'root/a/b/c']`.\n */\nexport const expandAttendableId = (qualifiedId: string): string[] => {\n const segments = qualifiedId.split('/');\n return segments.map((_, index) => segments.slice(0, index + 1).join('/'));\n};\n\n/**\n * Whether the last segment of a qualified ID is a linked segment (starts with `~`).\n * Linked segments share their attention state with the parent node.\n */\nexport const isLinkedSegment = (qualifiedId: string): boolean => {\n const lastSegment = qualifiedId.split('/').pop() ?? '';\n return lastSegment.startsWith(LINKED_PREFIX);\n};\n\n/**\n * Build a linked segment ID from a variant name (e.g., `'settings'` -> `'~settings'`).\n * Nodes identified by linked segments share their attention state with the parent node.\n */\nexport const linkedSegment = (variant: string): string => `${LINKED_PREFIX}${variant}`;\n\n/**\n * Extract the variant name from the last segment of a qualified ID, stripping the linked prefix.\n * e.g. `'root/space/obj/~settings'` -> `'settings'`.\n * If the segment is not linked (no `~` prefix), returns the segment as-is.\n */\nexport const getLinkedVariant = (qualifiedId: string): string => {\n const lastSegment = qualifiedId.split('/').pop() ?? '';\n return lastSegment.startsWith(LINKED_PREFIX) ? lastSegment.slice(LINKED_PREFIX.length) : lastSegment;\n};\n\n/**\n * Get the parent qualified ID (everything before the last `/` segment).\n */\nexport const getParentId = (qualifiedId: string | undefined): string | undefined => {\n if (!qualifiedId) {\n return undefined;\n }\n\n const lastSlash = qualifiedId.lastIndexOf('/');\n return lastSlash > 0 ? qualifiedId.slice(0, lastSlash) : undefined;\n};\n\n/**\n * Extract the segment ID (last segment) of a qualified ID.\n */\nexport const getSegmentId = (qualifiedId: string): string => {\n return qualifiedId.split('/').pop() ?? qualifiedId;\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { Atom, type Registry } from '@effect-atom/atom-react';\nimport * as Match from 'effect/Match';\nimport * as Schema from 'effect/Schema';\n\nimport { invariant } from '@dxos/invariant';\n\nexport type SelectionMode = 'single' | 'multi' | 'range' | 'multi-range';\n\nexport const SelectionSchema = Schema.Union(\n Schema.Struct({\n mode: Schema.Literal('single'),\n id: Schema.optional(Schema.String),\n }).pipe(Schema.mutable),\n Schema.Struct({\n mode: Schema.Literal('multi'),\n ids: Schema.Array(Schema.String).pipe(Schema.mutable),\n }).pipe(Schema.mutable),\n Schema.Struct({\n mode: Schema.Literal('range'),\n from: Schema.optional(Schema.String),\n to: Schema.optional(Schema.String),\n }).pipe(Schema.mutable),\n Schema.Struct({\n mode: Schema.Literal('multi-range'),\n ranges: Schema.Array(Schema.Struct({ from: Schema.String, to: Schema.String })).pipe(Schema.mutable),\n }).pipe(Schema.mutable),\n).pipe(Schema.mutable);\n\nexport type Selection = Schema.Schema.Type<typeof SelectionSchema>;\n\nexport const defaultSelection = Match.type<SelectionMode>().pipe(\n Match.withReturnType<Selection>(),\n Match.when('single', () => ({ mode: 'single' })),\n Match.when('multi', () => ({ mode: 'multi', ids: [] })),\n Match.when('range', () => ({ mode: 'range' })),\n Match.when('multi-range', () => ({ mode: 'multi-range', ranges: [] })),\n Match.exhaustive,\n);\n\nexport type SelectionResult<T extends SelectionMode> = T extends 'single'\n ? string | undefined\n : T extends 'multi'\n ? string[]\n : T extends 'range'\n ? { from: string; to: string } | undefined\n : T extends 'multi-range'\n ? { from: string; to: string }[]\n : never;\n\nexport const getSelectionSet = (selectionManager: SelectionManager, contextId?: string) => {\n const ids = new Set<string>(contextId ? [contextId] : []);\n for (const context of selectionManager.getSelectionContexts()) {\n const selection = selectionManager.getSelection(context);\n if (selection?.mode === 'multi') {\n for (const id of selection.ids) {\n ids.add(id);\n }\n }\n }\n\n return ids;\n};\n\n/**\n * Manages selection state for different contexts.\n * Each context maintains its own selection mode and state.\n */\nexport class SelectionManager {\n private readonly _state: Atom.Writable<{ selections: Record<string, Selection> }>;\n\n constructor(\n private readonly _registry: Registry.Registry,\n initial: Record<string, Selection> = {},\n ) {\n this._state = Atom.make<{ selections: Record<string, Selection> }>({\n selections: { ...initial },\n });\n }\n\n /**\n * Get the state atom for reactive access in the graph system.\n */\n get state(): Atom.Atom<{ selections: Record<string, Selection> }> {\n return this._state;\n }\n\n /**\n * Gets the current state.\n */\n getState(): { selections: Record<string, Selection> } {\n return this._registry.get(this._state);\n }\n\n /**\n * Subscribe to changes in the selection state.\n */\n subscribe(cb: (state: { selections: Record<string, Selection> }) => void): () => void {\n this._registry.get(this._state);\n return this._registry.subscribe(this._state, () => {\n cb(this._registry.get(this._state));\n });\n }\n\n getSelectionContexts(): string[] {\n return Object.keys(this._registry.get(this._state).selections);\n }\n\n getSelection(contextId: string): Selection | undefined;\n getSelection<T extends SelectionMode>(contextId: string, mode: T): Selection;\n getSelection<T extends SelectionMode | undefined>(\n contextId: string,\n mode: T = undefined as T,\n ): Selection | undefined {\n const state = this._registry.get(this._state);\n const selection = state.selections[contextId];\n if (!mode || selection) {\n return selection;\n }\n\n // Create new selection for the context.\n const newSelection = defaultSelection(mode);\n this._registry.update(this._state, (state) => ({\n selections: { ...state.selections, [contextId]: newSelection },\n }));\n\n return newSelection;\n }\n\n getSelected<T extends SelectionMode>(contextId: string, mode: T = 'multi' as T): SelectionResult<T> {\n const selection = this.getSelection(contextId, mode);\n invariant(selection?.mode === mode, 'Selection mode mismatch');\n\n // Cast required because TypeScript can't infer the relationship between T and the matched result.\n return Match.type<Selection>().pipe(\n Match.when({ mode: 'single' }, (s) => s.id),\n Match.when({ mode: 'multi' }, (s) => s.ids),\n Match.when({ mode: 'range' }, (s) => (s.from && s.to ? { from: s.from, to: s.to } : undefined)),\n Match.when({ mode: 'multi-range' }, (s) => s.ranges),\n Match.exhaustive,\n )(selection) as SelectionResult<T>;\n }\n\n updateSingle(contextId: string, id: string): void {\n const selection = this.getSelection(contextId, 'single');\n invariant(selection?.mode === 'single', 'Selection mode is not single');\n this._registry.update(this._state, (state) => ({\n selections: {\n ...state.selections,\n [contextId]: { ...selection, id },\n },\n }));\n }\n\n updateMulti(contextId: string, ids: string[]) {\n const selection = this.getSelection(contextId, 'multi');\n invariant(selection?.mode === 'multi', 'Selection mode is not multi');\n this._registry.update(this._state, (state) => ({\n selections: {\n ...state.selections,\n [contextId]: { ...selection, ids: [...ids] },\n },\n }));\n }\n\n updateRange(contextId: string, from: string, to: string) {\n const selection = this.getSelection(contextId, 'range');\n invariant(selection?.mode === 'range', 'Selection mode is not range');\n this._registry.update(this._state, (state) => ({\n selections: {\n ...state.selections,\n [contextId]: { ...selection, from, to },\n },\n }));\n }\n\n updateMultiRange(contextId: string, ranges: { from: string; to: string }[]) {\n const selection = this.getSelection(contextId, 'multi-range');\n invariant(selection?.mode === 'multi-range', 'Selection mode is not multi-range');\n this._registry.update(this._state, (state) => ({\n selections: {\n ...state.selections,\n [contextId]: { ...selection, ranges: [...ranges] },\n },\n }));\n }\n\n clearSelection(contextId: string): void {\n const selection = this.getSelection(contextId);\n if (!selection) {\n return;\n }\n\n const clearedSelection = Match.type<Selection>().pipe(\n Match.when({ mode: 'single' }, (s) => ({ ...s, id: undefined })),\n Match.when({ mode: 'multi' }, (s) => ({ ...s, ids: [] })),\n Match.when({ mode: 'range' }, (s) => ({ ...s, from: undefined, to: undefined })),\n Match.when({ mode: 'multi-range' }, (s) => ({ ...s, ranges: [] })),\n Match.exhaustive,\n )(selection);\n\n this._registry.update(this._state, (state) => ({\n selections: {\n ...state.selections,\n [contextId]: clearedSelection,\n },\n }));\n }\n\n toggleSelection(contextId: string, id: string): void {\n const selection = this.getSelection(contextId, 'multi');\n invariant(selection?.mode === 'multi', 'Selection mode is not multi');\n\n const newIds = selection.ids.includes(id)\n ? selection.ids.filter((existingId) => existingId !== id)\n : [...selection.ids, id];\n\n this._registry.update(this._state, (state) => ({\n selections: {\n ...state.selections,\n [contextId]: { ...selection, ids: newIds },\n },\n }));\n }\n}\n"],
5
- "mappings": ";;;AAIA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,WAAa,SAAA,SAAA,+BAAA,EAAA,YAAA,YAAA,GAAA,cAAA,GAAA,KAAA,GAAA,MAAA,GAAA,CAAA,+BAAA,+BAAA,EAAA,CAAA;UAAEf,SAAAA,UAAAA,IAAAA,SAAAA,EAAAA,IAAAA,UAAAA,IAAAA,OAAAA,CAAAA,eAAAA,eAAAA,EAAAA,IAAAA;MAAG,GAAA,UAAA;MAEtB;;mBAEG0B,OAAMR,KAAAA,QAAU,CAAA,WAAA;kBAClBJ;iBAAiBC;kBAAgBwB,GAAAA;UAAO,GAAA;UAC3C,KAAA;QACF;MACF;IACF,EAAA;;;",
6
- "names": ["Atom", "AttentionManager", "_map", "Map", "_currentAtom", "_registry", "initial", "make", "pipe", "keepAlive", "length", "update", "current", "getCurrent", "get", "subscribeCurrent", "cb", "subscribe", "keys", "Array", "from", "id", "atom", "_getAtom", "existing", "newAtom", "hasAttention", "isAncestor", "isRelated", "set", "nextIds", "primaryId", "currentIds", "prevPrimaryId", "prevPrefixes", "expandAttendableId", "prefix", "_set", "prevSegmentId", "getSegmentId", "key", "prefixes", "prefixSet", "Set", "linkedParent", "isLinkedSegment", "getParentId", "undefined", "segmentId", "has", "attention", "getAttendables", "selector", "cursor", "acc", "closestAttendable", "closest", "attendableId", "getAttribute", "trigger", "document", "querySelector", "push", "parentElement", "LINKED_PREFIX", "qualifiedId", "segments", "split", "map", "_", "index", "slice", "join", "lastSegment", "pop", "startsWith", "linkedSegment", "variant", "getLinkedVariant", "lastSlash", "lastIndexOf", "Atom", "Match", "Schema", "invariant", "SelectionSchema", "id", "pipe", "mutable", "Struct", "mode", "String", "optional", "to", "Array", "defaultSelection", "when", "ranges", "getSelectionSet", "ids", "contextId", "selection", "_state", "make", "selections", "initial", "_registry", "cb", "get", "getSelectionContexts", "getSelection", "undefined", "state", "newSelection", "getSelected", "s", "from", "exhaustive", "updateSingle", "update", "updateMulti", "updateRange", "updateMultiRange", "clearSelection", "toggleSelection", "newIds", "includes"]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "version": 3,
3
- "sources": ["../../../src/components/AttentionProvider/AttentionProvider.tsx", "../../../src/components/SelectionProvider/SelectionProvider.tsx"],
4
- "sourcesContent": ["//\n// Copyright 2024 DXOS.org\n//\n\nimport { RegistryContext } from '@effect-atom/atom-react';\nimport { createContext } from '@radix-ui/react-context';\nimport { Primitive } from '@radix-ui/react-primitive';\nimport { Slot } from '@radix-ui/react-slot';\nimport React, {\n type ComponentPropsWithRef,\n type FocusEvent,\n type PropsWithChildren,\n forwardRef,\n useCallback,\n useContext,\n useEffect,\n useMemo,\n useState,\n} from 'react';\n\nimport { log } from '@dxos/log';\nimport { useDefaultValue } from '@dxos/react-hooks';\nimport { type ThemedClassName } from '@dxos/react-ui';\nimport { mx } from '@dxos/ui-theme';\n\nimport { type Attention, AttentionManager, getAttendables } from '../../attention';\n\nconst ATTENTION_NAME = 'Attention';\nconst ATTENDABLE_ATTRIBUTE = 'data-attendable-id';\nconst ATTENTION_SOURCE_ATTRIBUTE = 'data-w-attention-source';\n\ntype AttentionContextValue = {\n attention: AttentionManager;\n};\n\nconst [AttentionContextProvider, useAttentionContext] = createContext<AttentionContextValue>(ATTENTION_NAME, {\n attention: undefined as unknown as AttentionManager,\n});\n\nconst UNKNOWN_ATTENDABLE = { hasAttention: false, isAncestor: false, isRelated: false } as Attention;\n\n/**\n * Subscribe to the attention state for a qualified graph ID.\n */\n// TODO(burdon): Unify with seleciton and change to contextId?\nconst useAttention = (attendableId?: string): Attention => {\n const { attention } = useAttentionContext(ATTENTION_NAME);\n const [state, setState] = useState<Attention>(UNKNOWN_ATTENDABLE);\n useEffect(() => {\n if (!attendableId || !attention) {\n setState(UNKNOWN_ATTENDABLE);\n return;\n }\n\n const currentState = attention.get(attendableId);\n setState(currentState);\n\n return attention.subscribe(attendableId, (newState) => {\n setState(newState);\n });\n }, [attention, attendableId]);\n\n return state;\n};\n\nconst useAttended = () => {\n const { attention } = useAttentionContext(ATTENTION_NAME);\n const [current, setCurrent] = useState<readonly string[]>([]);\n useEffect(() => {\n if (!attention) {\n return;\n }\n\n setCurrent(attention.getCurrent());\n\n return attention.subscribeCurrent((newCurrent) => {\n setCurrent(newCurrent);\n });\n }, [attention]);\n\n return current;\n};\n\n/**\n * Computes HTML element attributes to apply so the attention system can detect changes.\n */\nconst useAttentionAttributes = (attendableId?: string) => {\n const { hasAttention } = useAttention(attendableId);\n return useMemo(() => {\n const attributes: Record<string, string | undefined> = { [ATTENDABLE_ATTRIBUTE]: attendableId };\n if (hasAttention) {\n attributes[ATTENTION_SOURCE_ATTRIBUTE] = 'true';\n }\n\n return attributes;\n }, [attendableId, hasAttention]);\n};\n\ntype RootAttentionProviderProps = PropsWithChildren<{\n attention?: AttentionManager;\n onChange?: (nextAttended: string[]) => void;\n}>;\n\nconst RootAttentionProvider = ({ children, attention: propsAttention, onChange }: RootAttentionProviderProps) => {\n const registry = useContext(RegistryContext);\n const attention = useDefaultValue(propsAttention, () => new AttentionManager(registry));\n\n const handleFocus = useCallback(\n (event: FocusEvent) => {\n // NOTE(thure): Use the following to debug focus movement across the app:\n log('focus', { related: event.relatedTarget, target: event.target });\n\n const selector = [\n '[data-attendable-id]',\n ...Array.from(document.querySelectorAll('[aria-controls]')).map(\n (el) => `[id=\"${el.getAttribute('aria-controls')}\"]`,\n ),\n ].join(',');\n const prev = attention.getCurrent();\n const next = getAttendables(selector, event.target);\n // TODO(wittjosiah): Not allowing empty state means that the attended item is not strictly guaranteed to be in the DOM.\n // Currently this depends on the deck in order to ensure that when the attended item is removed something else is attended.\n // Only update state if the result is different and not empty.\n if (next.length > 0 && (prev.length !== next.length || !!prev.find((id, index) => next[index] !== id))) {\n attention.update(next);\n onChange?.(next);\n }\n },\n [attention, onChange],\n );\n\n return (\n <AttentionContextProvider attention={attention}>\n <div className='contents' onFocusCapture={handleFocus}>\n {children}\n </div>\n </AttentionContextProvider>\n );\n};\n\nexport type AttendableContainerProps = ThemedClassName<\n ComponentPropsWithRef<'div'> & { id: string; asChild?: boolean }\n>;\n\n/**\n * Note that DeckPlugin and StackPlugin both handle attention on their own,\n * and when rendering content in those cases it is not necessary to also render an `AttendableContainer`.\n * This component is primarily for Storybook stories and other testing scenarios,\n * or the rare cases where an attendable entity is rendered outside of either of those plugins.\n */\nconst AttendableContainer = forwardRef<HTMLDivElement, AttendableContainerProps>(\n ({ id, classNames, children, asChild, ...props }, forwardedRef) => {\n const attentionAttrs = useAttentionAttributes(id);\n const Comp = asChild ? Slot : Primitive.div;\n return (\n <Comp\n role='none'\n {...props}\n {...attentionAttrs}\n className={mx('dx-attention-surface', props.tabIndex === 0 && 'dx-focus-ring-inset-over-all', classNames)}\n ref={forwardedRef}\n >\n {children}\n </Comp>\n );\n },\n);\n\nexport {\n RootAttentionProvider,\n AttendableContainer,\n useAttentionContext,\n useAttention,\n useAttended,\n useAttentionAttributes,\n};\n", "//\n// Copyright 2025 DXOS.org\n//\n\nimport { RegistryContext } from '@effect-atom/atom-react';\nimport { createContext } from '@radix-ui/react-context';\nimport * as Match from 'effect/Match';\nimport React, { type PropsWithChildren, useCallback, useContext, useEffect, useMemo, useState } from 'react';\n\nimport { useDefaultValue } from '@dxos/react-hooks';\n\nimport {\n type Selection,\n SelectionManager,\n type SelectionMode,\n type SelectionResult,\n defaultSelection,\n} from '../../selection';\n\nconst SELECTION_NAME = 'Selection';\n\ntype SelectionContextValue = {\n selection: SelectionManager;\n};\n\n// Default value lets consumers like `useSelected` render outside a\n// `SelectionProvider` (e.g. isolated stories) without throwing —\n// `selection` reads as `undefined` and the hook falls back to the\n// per-mode default result. Without this default, Radix `createContext`\n// throws \"Selection must be used within Selection\" on every consumer.\nconst [SelectionContextProvider, useSelectionContext] = createContext<SelectionContextValue>(SELECTION_NAME, {\n selection: undefined as unknown as SelectionManager,\n});\n\n/**\n * Manages selection state across the app for multiple contexts.\n */\nexport const SelectionProvider = ({\n children,\n selection: selectionProp,\n}: PropsWithChildren<{ selection?: SelectionManager }>) => {\n const registry = useContext(RegistryContext);\n const selection = useDefaultValue(selectionProp, () => new SelectionManager(registry));\n\n return <SelectionContextProvider selection={selection}>{children}</SelectionContextProvider>;\n};\n\n/**\n * Get the selection contexts.\n */\nexport const useSelectionManager = (): SelectionManager => {\n const { selection } = useSelectionContext(SELECTION_NAME);\n return selection;\n};\n\nconst getDefaultResult = <T extends SelectionMode>(mode: T): SelectionResult<T> => {\n return Match.type<Selection>().pipe(\n Match.when({ mode: 'single' }, (selection) => selection.id),\n Match.when({ mode: 'multi' }, (selection) => selection.ids),\n Match.when({ mode: 'range' }, (selection) =>\n selection.from && selection.to ? { from: selection.from, to: selection.to } : undefined,\n ),\n Match.when({ mode: 'multi-range' }, (selection) => selection.ranges),\n Match.exhaustive,\n )(defaultSelection(mode)) as SelectionResult<T>;\n};\n\n/**\n * Get the selected objects for a given context.\n */\nexport const useSelected = <T extends SelectionMode>(\n contextId?: string,\n mode: T = 'multi' as T,\n): SelectionResult<T> => {\n const { selection } = useSelectionContext(SELECTION_NAME);\n const [state, setState] = useState<SelectionResult<T>>(() =>\n contextId && selection ? selection.getSelected(contextId, mode) : getDefaultResult(mode),\n );\n\n useEffect(() => {\n if (!contextId || !selection) {\n setState(getDefaultResult(mode));\n return;\n }\n\n // Set initial state.\n setState(selection.getSelected(contextId, mode));\n\n // Subscribe to changes.\n return selection.subscribe(() => {\n setState(selection.getSelected(contextId, mode));\n });\n }, [selection, contextId, mode]);\n\n return state;\n};\n\nexport type UseSelectionActions = {\n singleSelect: (id: string) => void;\n multiSelect: (ids: string[]) => void;\n rangeSelect: (from: string, to: string) => void;\n toggle: (id: string) => void;\n clear: () => void;\n};\n\n/**\n * Provides functions to manage the selection state for multiple contexts.\n */\nexport const useSelectionActions = (contextIds: string[]): UseSelectionActions => {\n const stableContextIds = useMemo(() => contextIds, [JSON.stringify(contextIds)]);\n const { selection } = useSelectionContext(SELECTION_NAME);\n\n // No-op when rendered outside a `SelectionProvider` (e.g. an isolated\n // story or a test harness) — `selection` is `undefined` from the\n // context default value. Matches the pre-co-locate behaviour.\n const singleSelect = useCallback(\n (id: string) => {\n if (!selection) {\n return;\n }\n for (const contextId of stableContextIds) {\n selection.updateSingle(contextId, id);\n }\n },\n [selection, stableContextIds],\n );\n\n const multiSelect = useCallback(\n (ids: string[]) => {\n if (!selection) {\n return;\n }\n for (const contextId of stableContextIds) {\n selection.updateMulti(contextId, ids);\n }\n },\n [selection, stableContextIds],\n );\n\n const rangeSelect = useCallback(\n (from: string, to: string) => {\n if (!selection) {\n return;\n }\n for (const contextId of stableContextIds) {\n selection.updateRange(contextId, from, to);\n }\n },\n [selection, stableContextIds],\n );\n\n const toggle = useCallback(\n (id: string) => {\n if (!selection) {\n return;\n }\n for (const contextId of stableContextIds) {\n selection.toggleSelection(contextId, id);\n }\n },\n [selection, stableContextIds],\n );\n\n const clear = useCallback(() => {\n if (!selection) {\n return;\n }\n for (const contextId of stableContextIds) {\n selection.clearSelection(contextId);\n }\n }, [selection, stableContextIds]);\n\n return { singleSelect, multiSelect, rangeSelect, toggle, clear };\n};\n"],
5
- "mappings": ";;;;;;;;;AAIA,SAASA,uBAAuB;AAChC,SAASC,qBAAqB;AAC9B,SAASC,iBAAiB;AAC1B,SAASC,YAAY;AACrB,OAAOC,SAILC,YACAC,aACAC,YACAC,WACAC,SACAC,gBACK;AAEP,SAASC,WAAW;AACpB,SAASC,uBAAuB;AAEhC,SAASC,UAAU;AAInB,IAAA,eAAMC;AAEN,IAAMC,iBAAAA;AAMN,IAAM,uBAACC;IACLC,6BAAWC;AACb,IAAA,CAAA,0BAAA,mBAAA,IAAA,cAAA,gBAAA;EAEA,WAAMC;;IAA4CC,qBAAY;EAAOC,cAAW;EAAM,YAAA;EAEtF,WAAA;;IAME,eAAcC,CAAAA,iBAAYC;AAC1BC,QAAAA,EAAAA,UAAU,IAAA,oBAAA,cAAA;QACR,CAAA,OAAKC,QAAAA,IAAiBR,SAAAA,kBAAW;YAC/BK,MAAAA;QACA,CAAA,gBAAA,CAAA,WAAA;AACF,eAAA,k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A;GAAY;AAC/E,QAAM,EAAEjC,UAAS,IAAKF,oBAAoBF,cAAAA;AAK1C,QAAM0C,eAAeC,aACnB,CAACtB,OAAAA;AACC,QAAI,CAACjB,WAAW;AACd;IACF;AACA,eAAWyB,aAAaS,kBAAkB;AACxClC,gBAAUwC,aAAaf,WAAWR,EAAAA;IACpC;EACF,GACA;IAACjB;IAAWkC;GAAiB;AAG/B,QAAMO,cAAcF,aAClB,CAACrB,QAAAA;AACC,QAAI,CAAClB,WAAW;AACd;IACF;AACA,eAAWyB,aAAaS,kBAAkB;AACxClC,gBAAU0C,YAAYjB,WAAWP,GAAAA;IACnC;EACF,GACA;IAAClB;IAAWkC;GAAiB;AAG/B,QAAMS,cAAcJ,aAClB,CAACpB,MAAcC,OAAAA;AACb,QAAI,CAACpB,WAAW;AACd;IACF;AACA,eAAWyB,aAAaS,kBAAkB;AACxClC,gBAAU4C,YAAYnB,WAAWN,MAAMC,EAAAA;IACzC;EACF,GACA;IAACpB;IAAWkC;GAAiB;AAG/B,QAAMW,SAASN,aACb,CAACtB,OAAAA;AACC,QAAI,CAACjB,WAAW;AACd;IACF;AACA,eAAWyB,aAAaS,kBAAkB;AACxClC,gBAAU8C,gBAAgBrB,WAAWR,EAAAA;IACvC;EACF,GACA;IAACjB;IAAWkC;GAAiB;AAG/B,QAAMa,QAAQR,aAAY,MAAA;AACxB,QAAI,CAACvC,WAAW;AACd;IACF;AACA,eAAWyB,aAAaS,kBAAkB;AACxClC,gBAAUgD,eAAevB,SAAAA;IAC3B;EACF,GAAG;IAACzB;IAAWkC;GAAiB;AAEhC,SAAO;IAAEI;IAAcG;IAAaE;IAAaE;IAAQE;EAAM;AACjE;",
6
- "names": ["RegistryContext", "createContext", "Primitive", "Slot", "React", "forwardRef", "useCallback", "useContext", "useEffect", "useMemo", "useState", "log", "useDefaultValue", "mx", "ATTENTION_NAME", "ATTENTION_SOURCE_ATTRIBUTE", "AttentionContextProvider", "attention", "undefined", "UNKNOWN_ATTENDABLE", "isAncestor", "isRelated", "setState", "useState", "useEffect", "attendableId", "subscribe", "newState", "useAttended", "setCurrent", "newCurrent", "attributes", "ATTENDABLE_ATTRIBUTE", "hasAttention", "useDefaultValue", "propsAttention", "AttentionManager", "registry", "handleFocus", "useCallback", "event", "log", "target", "selector", "join", "prev", "getCurrent", "next", "onChange", "div", "className", "onFocusCapture", "children", "Comp", "role", "attentionAttrs", "ref", "RootAttentionProvider", "RegistryContext", "createContext", "Match", "React", "useCallback", "useContext", "useEffect", "useMemo", "useState", "useDefaultValue", "SELECTION_NAME", "SelectionContextProvider", "useSelectionContext", "createContext", "selection", "undefined", "SelectionProvider", "children", "selectionProp", "registry", "useContext", "RegistryContext", "useDefaultValue", "SelectionManager", "React", "useSelectionManager", "getDefaultResult", "mode", "type", "pipe", "when", "id", "ids", "from", "to", "ranges", "exhaustive", "defaultSelection", "useSelected", "contextId", "state", "setState", "useState", "getSelected", "useEffect", "subscribe", "useSelectionActions", "contextIds", "stableContextIds", "useMemo", "JSON", "stringify", "singleSelect", "useCallback", "updateSingle", "multiSelect", "updateMulti", "rangeSelect", "updateRange", "toggle", "toggleSelection", "clear", "clearSelection"]
7
- }
@@ -1,28 +0,0 @@
1
- import React, { type PropsWithChildren } from 'react';
2
- import { SelectionManager, type SelectionMode, type SelectionResult } from '../../selection';
3
- /**
4
- * Manages selection state across the app for multiple contexts.
5
- */
6
- export declare const SelectionProvider: ({ children, selection: selectionProp, }: PropsWithChildren<{
7
- selection?: SelectionManager;
8
- }>) => React.JSX.Element;
9
- /**
10
- * Get the selection contexts.
11
- */
12
- export declare const useSelectionManager: () => SelectionManager;
13
- /**
14
- * Get the selected objects for a given context.
15
- */
16
- export declare const useSelected: <T extends SelectionMode>(contextId?: string, mode?: T) => SelectionResult<T>;
17
- export type UseSelectionActions = {
18
- singleSelect: (id: string) => void;
19
- multiSelect: (ids: string[]) => void;
20
- rangeSelect: (from: string, to: string) => void;
21
- toggle: (id: string) => void;
22
- clear: () => void;
23
- };
24
- /**
25
- * Provides functions to manage the selection state for multiple contexts.
26
- */
27
- export declare const useSelectionActions: (contextIds: string[]) => UseSelectionActions;
28
- //# sourceMappingURL=SelectionProvider.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SelectionProvider.d.ts","sourceRoot":"","sources":["../../../../../src/components/SelectionProvider/SelectionProvider.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,EAAE,KAAK,iBAAiB,EAAyD,MAAM,OAAO,CAAC;AAI7G,OAAO,EAEL,gBAAgB,EAChB,KAAK,aAAa,EAClB,KAAK,eAAe,EAErB,MAAM,iBAAiB,CAAC;AAiBzB;;GAEG;AACH,eAAO,MAAM,iBAAiB,4CAG3B,iBAAiB,CAAC;IAAE,SAAS,CAAC,EAAE,gBAAgB,CAAA;CAAE,CAAC,sBAKrD,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,QAAO,gBAGtC,CAAC;AAcF;;GAEG;AACH,eAAO,MAAM,WAAW,GAAI,CAAC,SAAS,aAAa,cACrC,MAAM,SACZ,CAAC,KACN,eAAe,CAAC,CAAC,CAsBnB,CAAC;AAEF,MAAM,MAAM,mBAAmB,GAAG;IAChC,YAAY,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,IAAI,CAAC;IACrC,WAAW,EAAE,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAChD,MAAM,EAAE,CAAC,EAAE,EAAE,MAAM,KAAK,IAAI,CAAC;IAC7B,KAAK,EAAE,MAAM,IAAI,CAAC;CACnB,CAAC;AAEF;;GAEG;AACH,eAAO,MAAM,mBAAmB,eAAgB,MAAM,EAAE,KAAG,mBAiE1D,CAAC"}
@@ -1,2 +0,0 @@
1
- export * from './SelectionProvider';
2
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/components/SelectionProvider/index.ts"],"names":[],"mappings":"AAIA,cAAc,qBAAqB,CAAC"}