@dxos/react-ui-attention 0.8.4-main.f9ba587 → 0.8.4-main.fd6878d

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 (31) hide show
  1. package/dist/lib/browser/{chunk-QPEFFJ4E.mjs → chunk-PXMGIYAQ.mjs} +58 -24
  2. package/dist/lib/{node-esm/chunk-F2JRKDYV.mjs.map → browser/chunk-PXMGIYAQ.mjs.map} +3 -3
  3. package/dist/lib/browser/index.mjs +3 -1
  4. package/dist/lib/browser/meta.json +1 -1
  5. package/dist/lib/browser/testing/index.mjs +2 -4
  6. package/dist/lib/browser/testing/index.mjs.map +3 -3
  7. package/dist/lib/node-esm/{chunk-F2JRKDYV.mjs → chunk-V2PNA7ZV.mjs} +58 -24
  8. package/dist/lib/{browser/chunk-QPEFFJ4E.mjs.map → node-esm/chunk-V2PNA7ZV.mjs.map} +3 -3
  9. package/dist/lib/node-esm/index.mjs +3 -1
  10. package/dist/lib/node-esm/meta.json +1 -1
  11. package/dist/lib/node-esm/testing/index.mjs +2 -4
  12. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  13. package/dist/types/src/attention.d.ts.map +1 -1
  14. package/dist/types/src/components/AttentionGlyph.d.ts.map +1 -1
  15. package/dist/types/src/components/AttentionProvider.d.ts +1 -1
  16. package/dist/types/src/components/AttentionProvider.d.ts.map +1 -1
  17. package/dist/types/src/components/AttentionProvider.stories.d.ts.map +1 -1
  18. package/dist/types/src/components/SelectionProvider.d.ts +1 -1
  19. package/dist/types/src/components/SelectionProvider.d.ts.map +1 -1
  20. package/dist/types/src/selection.d.ts +26 -14
  21. package/dist/types/src/selection.d.ts.map +1 -1
  22. package/dist/types/tsconfig.tsbuildinfo +1 -1
  23. package/package.json +15 -13
  24. package/src/attention.test.ts +1 -1
  25. package/src/attention.ts +1 -1
  26. package/src/components/AttentionGlyph.tsx +1 -1
  27. package/src/components/AttentionProvider.stories.tsx +2 -1
  28. package/src/components/AttentionProvider.tsx +3 -3
  29. package/src/components/SelectionProvider.tsx +4 -4
  30. package/src/selection.ts +45 -16
  31. package/src/testing/decorators/withAttention.ts +1 -1
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dxos/react-ui-attention",
3
- "version": "0.8.4-main.f9ba587",
3
+ "version": "0.8.4-main.fd6878d",
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",
@@ -10,11 +10,13 @@
10
10
  "type": "module",
11
11
  "exports": {
12
12
  ".": {
13
+ "source": "./src/index.ts",
13
14
  "types": "./dist/types/src/index.d.ts",
14
15
  "browser": "./dist/lib/browser/index.mjs",
15
16
  "node": "./dist/lib/node-esm/index.mjs"
16
17
  },
17
18
  "./testing": {
19
+ "source": "./src/testing/index.ts",
18
20
  "types": "./dist/types/src/testing/index.d.ts",
19
21
  "browser": "./dist/lib/browser/testing/index.mjs",
20
22
  "node": "./dist/lib/node-esm/testing/index.mjs"
@@ -42,12 +44,12 @@
42
44
  "@radix-ui/react-primitive": "2.0.2",
43
45
  "@radix-ui/react-slot": "1.1.2",
44
46
  "@radix-ui/react-use-controllable-state": "1.1.0",
45
- "effect": "3.16.13",
46
- "@dxos/invariant": "0.8.4-main.f9ba587",
47
- "@dxos/echo-schema": "0.8.4-main.f9ba587",
48
- "@dxos/live-object": "0.8.4-main.f9ba587",
49
- "@dxos/log": "0.8.4-main.f9ba587",
50
- "@dxos/util": "0.8.4-main.f9ba587"
47
+ "effect": "3.17.7",
48
+ "@dxos/echo-schema": "0.8.4-main.fd6878d",
49
+ "@dxos/live-object": "0.8.4-main.fd6878d",
50
+ "@dxos/invariant": "0.8.4-main.fd6878d",
51
+ "@dxos/util": "0.8.4-main.fd6878d",
52
+ "@dxos/log": "0.8.4-main.fd6878d"
51
53
  },
52
54
  "devDependencies": {
53
55
  "@types/react": "~18.2.0",
@@ -55,17 +57,17 @@
55
57
  "react": "~18.2.0",
56
58
  "react-dom": "~18.2.0",
57
59
  "vite": "5.4.7",
58
- "@dxos/react-ui": "0.8.4-main.f9ba587",
59
- "@dxos/react-ui-theme": "0.8.4-main.f9ba587",
60
- "@dxos/random": "0.8.4-main.f9ba587",
61
- "@dxos/storybook-utils": "0.8.4-main.f9ba587"
60
+ "@dxos/random": "0.8.4-main.fd6878d",
61
+ "@dxos/react-ui-theme": "0.8.4-main.fd6878d",
62
+ "@dxos/storybook-utils": "0.8.4-main.fd6878d",
63
+ "@dxos/react-ui": "0.8.4-main.fd6878d"
62
64
  },
63
65
  "peerDependencies": {
64
66
  "effect": "^3.13.3",
65
67
  "react": "~18.2.0",
66
68
  "react-dom": "~18.2.0",
67
- "@dxos/react-ui": "0.8.4-main.f9ba587",
68
- "@dxos/react-ui-theme": "0.8.4-main.f9ba587"
69
+ "@dxos/react-ui": "0.8.4-main.fd6878d",
70
+ "@dxos/react-ui-theme": "0.8.4-main.fd6878d"
69
71
  },
70
72
  "publishConfig": {
71
73
  "access": "public"
@@ -2,7 +2,7 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
- import { describe, test, expect } from 'vitest';
5
+ import { describe, expect, test } from 'vitest';
6
6
 
7
7
  import { AttentionManager } from './attention';
8
8
 
package/src/attention.ts CHANGED
@@ -5,7 +5,7 @@
5
5
  import { untracked } from '@preact/signals-core';
6
6
  import { Schema } from 'effect';
7
7
 
8
- import { live, type Live } from '@dxos/live-object';
8
+ import { type Live, live } from '@dxos/live-object';
9
9
  import { ComplexMap } from '@dxos/util';
10
10
 
11
11
  // NOTE: Chosen from RFC 1738’s `safe` characters: http://www.faqs.org/rfcs/rfc1738.html
@@ -3,7 +3,7 @@
3
3
  //
4
4
 
5
5
  import { type Primitive } from '@radix-ui/react-primitive';
6
- import React, { type ComponentPropsWithRef, type CSSProperties, forwardRef, useMemo } from 'react';
6
+ import React, { type CSSProperties, type ComponentPropsWithRef, forwardRef, useMemo } from 'react';
7
7
 
8
8
  import { Icon, type ThemedClassName } from '@dxos/react-ui';
9
9
  import { mx } from '@dxos/react-ui-theme';
@@ -8,9 +8,10 @@ import React from 'react';
8
8
 
9
9
  import { withTheme } from '@dxos/storybook-utils';
10
10
 
11
- import { useAttentionAttributes } from './AttentionProvider';
12
11
  import { withAttention } from '../testing';
13
12
 
13
+ import { useAttentionAttributes } from './AttentionProvider';
14
+
14
15
  const Attendable = ({ id }: { id: string }) => {
15
16
  const attentionAttrs = useAttentionAttributes(id);
16
17
 
@@ -5,12 +5,12 @@
5
5
  // NOTE(thure): The following unused imports quell TS2742 (“likely not portable”).
6
6
 
7
7
  // eslint-disable-next-line unused-imports/no-unused-imports
8
- import { createContext, type Scope, type CreateScope } from '@radix-ui/react-context';
8
+ import { type CreateScope, type Scope, createContext } from '@radix-ui/react-context';
9
9
  import { Primitive } from '@radix-ui/react-primitive';
10
10
  import { Slot } from '@radix-ui/react-slot';
11
- import React, { useMemo, type FocusEvent, type PropsWithChildren, type ComponentPropsWithRef, forwardRef } from 'react';
11
+ import React, { type ComponentPropsWithRef, type FocusEvent, type PropsWithChildren, forwardRef, useMemo } from 'react';
12
12
 
13
- import { useDefaultValue, type ThemedClassName } from '@dxos/react-ui';
13
+ import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
14
14
  import { mx } from '@dxos/react-ui-theme';
15
15
 
16
16
  import { ATTENDABLE_PATH_SEPARATOR, type Attention, AttentionManager, getAttendables } from '../attention';
@@ -4,16 +4,16 @@
4
4
 
5
5
  import { createContext } from '@radix-ui/react-context';
6
6
  import { Match } from 'effect';
7
- import React, { useCallback, useMemo, type PropsWithChildren } from 'react';
7
+ import React, { type PropsWithChildren, useCallback, useMemo } from 'react';
8
8
 
9
9
  import { useDefaultValue } from '@dxos/react-ui';
10
10
 
11
11
  import {
12
- defaultSelection,
13
- SelectionManager,
14
- type SelectionResult,
15
12
  type Selection,
13
+ SelectionManager,
16
14
  type SelectionMode,
15
+ type SelectionResult,
16
+ defaultSelection,
17
17
  } from '../selection';
18
18
 
19
19
  const SELECTION_NAME = 'Selection';
package/src/selection.ts CHANGED
@@ -3,26 +3,39 @@
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
- import { live, type Live } from '@dxos/live-object';
9
+ import { type Live, live } from '@dxos/live-object';
10
10
 
11
11
  // TODO(burdon): Reconcile with @dxos/graph.
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
  };