@dxos/react-ui-attention 0.8.4-main.84f28bd → 0.8.4-main.c1de068

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/react-ui-attention",
3
- "version": "0.8.4-main.84f28bd",
3
+ "version": "0.8.4-main.c1de068",
4
4
  "description": "Signifier components and providers for attention system.",
5
5
  "homepage": "https://dxos.org",
6
6
  "bugs": "https://github.com/dxos/dxos/issues",
@@ -42,12 +42,12 @@
42
42
  "@radix-ui/react-primitive": "2.0.2",
43
43
  "@radix-ui/react-slot": "1.1.2",
44
44
  "@radix-ui/react-use-controllable-state": "1.1.0",
45
- "effect": "3.16.13",
46
- "@dxos/echo-schema": "0.8.4-main.84f28bd",
47
- "@dxos/invariant": "0.8.4-main.84f28bd",
48
- "@dxos/live-object": "0.8.4-main.84f28bd",
49
- "@dxos/log": "0.8.4-main.84f28bd",
50
- "@dxos/util": "0.8.4-main.84f28bd"
45
+ "effect": "3.17.0",
46
+ "@dxos/echo-schema": "0.8.4-main.c1de068",
47
+ "@dxos/invariant": "0.8.4-main.c1de068",
48
+ "@dxos/log": "0.8.4-main.c1de068",
49
+ "@dxos/util": "0.8.4-main.c1de068",
50
+ "@dxos/live-object": "0.8.4-main.c1de068"
51
51
  },
52
52
  "devDependencies": {
53
53
  "@types/react": "~18.2.0",
@@ -55,17 +55,17 @@
55
55
  "react": "~18.2.0",
56
56
  "react-dom": "~18.2.0",
57
57
  "vite": "5.4.7",
58
- "@dxos/random": "0.8.4-main.84f28bd",
59
- "@dxos/react-ui": "0.8.4-main.84f28bd",
60
- "@dxos/react-ui-theme": "0.8.4-main.84f28bd",
61
- "@dxos/storybook-utils": "0.8.4-main.84f28bd"
58
+ "@dxos/random": "0.8.4-main.c1de068",
59
+ "@dxos/react-ui": "0.8.4-main.c1de068",
60
+ "@dxos/react-ui-theme": "0.8.4-main.c1de068",
61
+ "@dxos/storybook-utils": "0.8.4-main.c1de068"
62
62
  },
63
63
  "peerDependencies": {
64
64
  "effect": "^3.13.3",
65
65
  "react": "~18.2.0",
66
66
  "react-dom": "~18.2.0",
67
- "@dxos/react-ui": "0.8.4-main.84f28bd",
68
- "@dxos/react-ui-theme": "0.8.4-main.84f28bd"
67
+ "@dxos/react-ui": "0.8.4-main.c1de068",
68
+ "@dxos/react-ui-theme": "0.8.4-main.c1de068"
69
69
  },
70
70
  "publishConfig": {
71
71
  "access": "public"
package/src/selection.ts CHANGED
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { untracked } from '@preact/signals-core';
6
- import { Match } from 'effect';
6
+ import { Match, Schema } from 'effect';
7
7
 
8
8
  import { invariant } from '@dxos/invariant';
9
9
  import { live, type Live } from '@dxos/live-object';
@@ -12,17 +12,30 @@ import { live, type Live } from '@dxos/live-object';
12
12
 
13
13
  export type SelectionMode = 'single' | 'multi' | 'range' | 'multi-range';
14
14
 
15
- export type Selection =
16
- | { mode: 'single'; id?: string }
17
- | { mode: 'multi'; ids: string[] }
18
- | { mode: 'range'; from?: string; to?: string }
19
- | { mode: 'multi-range'; ranges: { from: string; to: string }[] };
15
+ export const SelectionSchema = Schema.Union(
16
+ Schema.Struct({ mode: Schema.Literal('single'), id: Schema.optional(Schema.String) }).pipe(Schema.mutable),
17
+ Schema.Struct({ mode: Schema.Literal('multi'), ids: Schema.Array(Schema.String).pipe(Schema.mutable) }).pipe(
18
+ Schema.mutable,
19
+ ),
20
+ Schema.Struct({
21
+ mode: Schema.Literal('range'),
22
+ from: Schema.optional(Schema.String),
23
+ to: Schema.optional(Schema.String),
24
+ }).pipe(Schema.mutable),
25
+ Schema.Struct({
26
+ mode: Schema.Literal('multi-range'),
27
+ ranges: Schema.Array(Schema.Struct({ from: Schema.String, to: Schema.String })).pipe(Schema.mutable),
28
+ }).pipe(Schema.mutable),
29
+ ).pipe(Schema.mutable);
30
+
31
+ export type Selection = Schema.Schema.Type<typeof SelectionSchema>;
20
32
 
21
33
  export const defaultSelection = Match.type<SelectionMode>().pipe(
22
- Match.when('single', () => ({ mode: 'single' }) as Selection),
23
- Match.when('multi', () => ({ mode: 'multi', ids: [] }) as Selection),
24
- Match.when('range', () => ({ mode: 'range' }) as Selection),
25
- Match.when('multi-range', () => ({ mode: 'multi-range', ranges: [] }) as Selection),
34
+ Match.withReturnType<Selection>(),
35
+ Match.when('single', () => ({ mode: 'single' })),
36
+ Match.when('multi', () => ({ mode: 'multi', ids: [] })),
37
+ Match.when('range', () => ({ mode: 'range' })),
38
+ Match.when('multi-range', () => ({ mode: 'multi-range', ranges: [] })),
26
39
  Match.exhaustive,
27
40
  );
28
41
 
@@ -110,7 +123,7 @@ export class SelectionManager {
110
123
  untracked(() => {
111
124
  const selection = this.getSelection(contextId, 'multi');
112
125
  invariant(selection?.mode === 'multi', 'Selection mode is not multi');
113
- selection.ids = ids;
126
+ selection.ids.splice(0, selection.ids.length, ...ids);
114
127
  });
115
128
  }
116
129
 
@@ -127,16 +140,32 @@ export class SelectionManager {
127
140
  untracked(() => {
128
141
  const selection = this.getSelection(contextId, 'multi-range');
129
142
  invariant(selection?.mode === 'multi-range', 'Selection mode is not multi-range');
130
- selection.ranges = ranges;
143
+ selection.ranges.splice(0, selection.ranges.length, ...ranges);
131
144
  });
132
145
  }
133
146
 
134
147
  clearSelection(contextId: string): void {
135
148
  untracked(() => {
136
149
  const selection = this.getSelection(contextId);
137
- if (selection) {
138
- this._state.selections[contextId] = defaultSelection(selection.mode);
139
- }
150
+ Match.type<Selection | undefined>().pipe(
151
+ Match.when(undefined, () => {
152
+ // No-op.
153
+ }),
154
+ Match.when({ mode: 'single' }, (s) => {
155
+ s.id = undefined;
156
+ }),
157
+ Match.when({ mode: 'multi' }, (s) => {
158
+ s.ids.splice(0, s.ids.length);
159
+ }),
160
+ Match.when({ mode: 'range' }, (s) => {
161
+ s.from = undefined;
162
+ s.to = undefined;
163
+ }),
164
+ Match.when({ mode: 'multi-range' }, (s) => {
165
+ s.ranges.splice(0, s.ranges.length);
166
+ }),
167
+ Match.exhaustive,
168
+ )(selection);
140
169
  });
141
170
  }
142
171
 
@@ -8,5 +8,5 @@ import { createElement } from 'react';
8
8
  import { RootAttentionProvider } from '../../components';
9
9
 
10
10
  export const withAttention: Decorator = (Story) => {
11
- return createElement(RootAttentionProvider, { children: createElement(Story) });
11
+ return createElement(RootAttentionProvider, {}, createElement(Story));
12
12
  };