@dxos/react-ui-attention 0.8.4-main.72ec0f3 → 0.8.4-main.74a063c4e0

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 (55) hide show
  1. package/dist/lib/browser/chunk-4SEURHOL.mjs +721 -0
  2. package/dist/lib/browser/chunk-4SEURHOL.mjs.map +7 -0
  3. package/dist/lib/browser/chunk-GMKHOVJ5.mjs +1 -0
  4. package/dist/lib/browser/chunk-GMKHOVJ5.mjs.map +7 -0
  5. package/dist/lib/browser/index.mjs +83 -11
  6. package/dist/lib/browser/index.mjs.map +4 -4
  7. package/dist/lib/browser/meta.json +1 -1
  8. package/dist/lib/browser/testing/index.mjs +18 -4
  9. package/dist/lib/browser/testing/index.mjs.map +3 -3
  10. package/dist/lib/browser/types.mjs +2 -0
  11. package/dist/lib/browser/types.mjs.map +7 -0
  12. package/dist/lib/node-esm/chunk-6PQ4P7AL.mjs +723 -0
  13. package/dist/lib/node-esm/chunk-6PQ4P7AL.mjs.map +7 -0
  14. package/dist/lib/node-esm/chunk-UHVMYYIB.mjs +2 -0
  15. package/dist/lib/node-esm/chunk-UHVMYYIB.mjs.map +7 -0
  16. package/dist/lib/node-esm/index.mjs +83 -11
  17. package/dist/lib/node-esm/index.mjs.map +4 -4
  18. package/dist/lib/node-esm/meta.json +1 -1
  19. package/dist/lib/node-esm/testing/index.mjs +18 -4
  20. package/dist/lib/node-esm/testing/index.mjs.map +3 -3
  21. package/dist/lib/node-esm/types.mjs +3 -0
  22. package/dist/lib/node-esm/types.mjs.map +7 -0
  23. package/dist/types/src/attention.d.ts +56 -20
  24. package/dist/types/src/attention.d.ts.map +1 -1
  25. package/dist/types/src/components/AttentionGlyph.d.ts.map +1 -1
  26. package/dist/types/src/components/AttentionProvider.d.ts +12 -13
  27. package/dist/types/src/components/AttentionProvider.d.ts.map +1 -1
  28. package/dist/types/src/components/AttentionProvider.stories.d.ts.map +1 -1
  29. package/dist/types/src/components/SelectionProvider.d.ts +5 -4
  30. package/dist/types/src/components/SelectionProvider.d.ts.map +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 +23 -3
  34. package/dist/types/src/selection.d.ts.map +1 -1
  35. package/dist/types/src/testing/decorators/withAttention.d.ts +5 -1
  36. package/dist/types/src/testing/decorators/withAttention.d.ts.map +1 -1
  37. package/dist/types/src/types.d.ts +9 -0
  38. package/dist/types/src/types.d.ts.map +1 -0
  39. package/dist/types/tsconfig.tsbuildinfo +1 -1
  40. package/package.json +36 -24
  41. package/src/attention.test.ts +188 -27
  42. package/src/attention.ts +175 -75
  43. package/src/components/AttentionGlyph.stories.tsx +3 -3
  44. package/src/components/AttentionGlyph.tsx +13 -6
  45. package/src/components/AttentionProvider.stories.tsx +2 -3
  46. package/src/components/AttentionProvider.tsx +69 -87
  47. package/src/components/SelectionProvider.tsx +62 -15
  48. package/src/index.ts +1 -0
  49. package/src/selection.ts +111 -71
  50. package/src/testing/decorators/withAttention.ts +20 -3
  51. package/src/types.ts +13 -0
  52. package/dist/lib/browser/chunk-MVIMDGR2.mjs +0 -662
  53. package/dist/lib/browser/chunk-MVIMDGR2.mjs.map +0 -7
  54. package/dist/lib/node-esm/chunk-NPW2V7JQ.mjs +0 -664
  55. package/dist/lib/node-esm/chunk-NPW2V7JQ.mjs.map +0 -7
@@ -13,7 +13,7 @@ import { AttentionGlyph, type AttentionGlyphProps } from './AttentionGlyph';
13
13
 
14
14
  const DefaultStory = (props: AttentionGlyphProps) => {
15
15
  return (
16
- <ul className='flex gap-2 mbe-2'>
16
+ <ul className='flex gap-2 mb-2'>
17
17
  <li>
18
18
  <AttentionGlyph presence='none' {...props} />
19
19
  </li>
@@ -31,7 +31,7 @@ const meta = {
31
31
  title: 'ui/react-ui-attention/AttentionGlyph',
32
32
  component: AttentionGlyph as any,
33
33
  render: DefaultStory,
34
- decorators: [withTheme],
34
+ decorators: [withTheme()],
35
35
  } satisfies Meta<typeof DefaultStory>;
36
36
 
37
37
  export default meta;
@@ -76,7 +76,7 @@ export const Syncing: Story = {
76
76
  });
77
77
 
78
78
  return (
79
- <div className='flex flex-col p-2 is-[200px]'>
79
+ <div className='flex flex-col p-2 w-[200px]'>
80
80
  <Button onClick={handleChangeAttended}>Change attended</Button>
81
81
  {Array.from(spaces.entries()).map(([space, sync]) => (
82
82
  <div key={space} className='flex items-center'>
@@ -6,13 +6,20 @@ import { type Primitive } from '@radix-ui/react-primitive';
6
6
  import React, { type CSSProperties, type ComponentPropsWithRef, forwardRef, useMemo } from 'react';
7
7
 
8
8
  import { Icon, type ThemedClassName } from '@dxos/react-ui';
9
- import { mx } from '@dxos/react-ui-theme';
9
+ import { mx } from '@dxos/ui-theme';
10
10
 
11
- const attentionGlyphStyles =
12
- 'inline-block rounded-sm is-3 bs-3 bg-transparent text-accentText transition-colors [[data-contains-attended=true]_&]:bg-attentionRelated [[data-attention=true]_&]:bg-accentSurface [[data-attention=true]_&]:text-accentSurfaceText [[aria-current][data-attention=true]_&]:bg-accentSurface [[aria-current][data-attention=true]_&]:text-accentSurfaceText';
11
+ const attentionGlyphStyles = mx(
12
+ 'inline-block rounded-xs w-3 h-3 bg-transparent text-accent-text transition-colors',
13
+ '[[data-contains-attended=true]_&]:bg-attention-contains',
14
+ '[[data-attention=true]_&]:bg-accent-surface',
15
+ '[[data-attention=true]_&]:text-accent-surface-text',
16
+ '[[aria-current][data-attention=true]_&]:bg-accent-surface',
17
+ '[[aria-current][data-attention=true]_&]:text-accent-surface-text',
18
+ '[[aria-selected="true"][data-attention=true]_&]:bg-accent-surface',
19
+ '[[aria-selected="true"][data-attention=true]_&]:text-accent-surface-text',
20
+ );
13
21
 
14
- const presenceIconStyles =
15
- 'is-3 bs-3 group-[[aria-current]_&:hover]/attentionGlyphButton:hidden group-[[aria-current]_&:focus]/attentionGlyphButton:hidden group-[[data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[data-attention=true]_&:focus]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:hover]/attentionGlyphButton:hidden group-[[aria-current][data-attention=true]_&:focus]/attentionGlyphButton:hidden';
22
+ const presenceIconStyles = mx('w-3 h-3');
16
23
 
17
24
  const PresenceOne = () => {
18
25
  return (
@@ -87,7 +94,7 @@ export const AttentionGlyph = forwardRef<HTMLSpanElement, AttentionGlyphProps>(
87
94
  ) : null;
88
95
 
89
96
  return (
90
- <div role='none' className='flex' data-attention={attended} data-contains-attended={containsAttended}>
97
+ <div role='none' className='flex group' data-attention={attended} data-contains-attended={containsAttended}>
91
98
  <span role='none' {...props} className={mx(attentionGlyphStyles, classNames)} ref={forwardedRef}>
92
99
  {icon}
93
100
  </span>
@@ -8,7 +8,6 @@ import React from 'react';
8
8
  import { withTheme } from '@dxos/react-ui/testing';
9
9
 
10
10
  import { withAttention } from '../testing';
11
-
12
11
  import { useAttentionAttributes } from './AttentionProvider';
13
12
 
14
13
  const Attendable = ({ id }: { id: string }) => {
@@ -16,7 +15,7 @@ const Attendable = ({ id }: { id: string }) => {
16
15
 
17
16
  return (
18
17
  <div {...attentionAttrs}>
19
- <textarea className='attention-surface resize-none' placeholder={id} />
18
+ <textarea className='dx-attention-surface resize-none' placeholder={id} />
20
19
  </div>
21
20
  );
22
21
  };
@@ -35,7 +34,7 @@ const Story = () => {
35
34
  const meta = {
36
35
  title: 'ui/react-ui-attention/AttentionProvider',
37
36
  render: Story,
38
- decorators: [withTheme, withAttention],
37
+ decorators: [withTheme(), withAttention()],
39
38
  } satisfies Meta;
40
39
 
41
40
  export default meta;
@@ -2,51 +2,88 @@
2
2
  // Copyright 2024 DXOS.org
3
3
  //
4
4
 
5
+ import { RegistryContext } from '@effect-atom/atom-react';
5
6
  import { createContext } from '@radix-ui/react-context';
6
7
  import { Primitive } from '@radix-ui/react-primitive';
7
8
  import { Slot } from '@radix-ui/react-slot';
8
- import React, { type ComponentPropsWithRef, type FocusEvent, type PropsWithChildren, forwardRef, useMemo } from 'react';
9
+ import React, {
10
+ type ComponentPropsWithRef,
11
+ type FocusEvent,
12
+ type PropsWithChildren,
13
+ forwardRef,
14
+ useContext,
15
+ useEffect,
16
+ useMemo,
17
+ useState,
18
+ } from 'react';
9
19
 
10
20
  import { log } from '@dxos/log';
11
- import { type ThemedClassName, useDefaultValue } from '@dxos/react-ui';
12
- import { mx } from '@dxos/react-ui-theme';
21
+ import { useDefaultValue } from '@dxos/react-hooks';
22
+ import { type ThemedClassName } from '@dxos/react-ui';
23
+ import { mx } from '@dxos/ui-theme';
13
24
 
14
- import { ATTENDABLE_PATH_SEPARATOR, type Attention, AttentionManager, getAttendables } from '../attention';
25
+ import { AttentionManager, getAttendables } from '../attention';
26
+ import { type Attention } from '../types';
15
27
 
16
28
  const ATTENTION_NAME = 'Attention';
17
29
  const ATTENDABLE_ATTRIBUTE = 'data-attendable-id';
18
- const ATTENTION_SOURCE_ATTRIBUTE = 'data-is-attention-source';
30
+ const ATTENTION_SOURCE_ATTRIBUTE = 'data-w-attention-source';
19
31
 
20
32
  type AttentionContextValue = {
21
33
  attention: AttentionManager;
22
- path: string[];
23
34
  };
24
35
 
25
36
  const [AttentionContextProvider, useAttentionContext] = createContext<AttentionContextValue>(ATTENTION_NAME, {
26
- attention: new AttentionManager(),
27
- path: [],
37
+ attention: undefined as unknown as AttentionManager,
28
38
  });
29
39
 
30
- const UNKNOWN_ATTENDABLE: Attention = { hasAttention: false, isAncestor: false, isRelated: false };
40
+ const UNKNOWN_ATTENDABLE = { hasAttention: false, isAncestor: false, isRelated: false } as Attention;
31
41
 
42
+ /**
43
+ * Subscribe to the attention state for a qualified graph ID.
44
+ */
32
45
  const useAttention = (attendableId?: string): Attention => {
33
- const { attention, path } = useAttentionContext(ATTENTION_NAME);
34
- if (!attendableId) {
35
- return UNKNOWN_ATTENDABLE;
36
- }
46
+ const { attention } = useAttentionContext(ATTENTION_NAME);
47
+ const [state, setState] = useState<Attention>(UNKNOWN_ATTENDABLE);
48
+
49
+ useEffect(() => {
50
+ if (!attendableId || !attention) {
51
+ setState(UNKNOWN_ATTENDABLE);
52
+ return;
53
+ }
54
+
55
+ const currentState = attention.get(attendableId);
56
+ setState(currentState);
57
+
58
+ return attention.subscribe(attendableId, (newState) => {
59
+ setState(newState);
60
+ });
61
+ }, [attention, attendableId]);
37
62
 
38
- const current = [...attendableId.split(ATTENDABLE_PATH_SEPARATOR), ...path];
39
- return attention.get(current);
63
+ return state;
40
64
  };
41
65
 
42
66
  const useAttended = () => {
43
67
  const { attention } = useAttentionContext(ATTENTION_NAME);
44
- return attention.current;
68
+ const [current, setCurrent] = useState<readonly string[]>([]);
69
+
70
+ useEffect(() => {
71
+ if (!attention) {
72
+ return;
73
+ }
74
+
75
+ setCurrent(attention.getCurrent());
76
+
77
+ return attention.subscribeCurrent((newCurrent) => {
78
+ setCurrent(newCurrent);
79
+ });
80
+ }, [attention]);
81
+
82
+ return current;
45
83
  };
46
84
 
47
85
  /**
48
86
  * Computes HTML element attributes to apply so the attention system can detect changes.
49
- * @param attendableId
50
87
  */
51
88
  const useAttentionAttributes = (attendableId?: string) => {
52
89
  const { hasAttention } = useAttention(attendableId);
@@ -60,11 +97,6 @@ const useAttentionAttributes = (attendableId?: string) => {
60
97
  }, [attendableId, hasAttention]);
61
98
  };
62
99
 
63
- const useAttentionPath = () => {
64
- const { path } = useAttentionContext(ATTENTION_NAME);
65
- return path;
66
- };
67
-
68
100
  const RootAttentionProvider = ({
69
101
  children,
70
102
  attention: propsAttention,
@@ -75,7 +107,9 @@ const RootAttentionProvider = ({
75
107
  onChange: (nextAttended: string[]) => void;
76
108
  }>
77
109
  >) => {
78
- const attention = useDefaultValue(propsAttention, () => new AttentionManager());
110
+ const registry = useContext(RegistryContext);
111
+ const attention = useDefaultValue(propsAttention, () => new AttentionManager(registry));
112
+
79
113
  const handleFocus = (event: FocusEvent) => {
80
114
  // NOTE(thure): Use the following to debug focus movement across the app:
81
115
  log('focus', { related: event.relatedTarget, target: event.target });
@@ -86,7 +120,7 @@ const RootAttentionProvider = ({
86
120
  (el) => `[id="${el.getAttribute('aria-controls')}"]`,
87
121
  ),
88
122
  ].join(',');
89
- const prev = attention.current;
123
+ const prev = attention.getCurrent();
90
124
  const next = getAttendables(selector, event.target);
91
125
  // TODO(wittjosiah): Not allowing empty state means that the attended item is not strictly guaranteed to be in the DOM.
92
126
  // Currently this depends on the deck in order to ensure that when the attended item is removed something else is attended.
@@ -97,102 +131,50 @@ const RootAttentionProvider = ({
97
131
  }
98
132
  };
99
133
 
100
- // NOTE(thure): Use the following to debug the macOS package issue #8540:
101
-
102
- // const [startEl, setStartEl] = useState<HTMLElement | null>(null);
103
- // const [endEl, setEndEl] = useState<HTMLElement | null>(null);
104
- //
105
- // const handleEventDebug = useCallback((event: any) => {
106
- // console.log(`[${event.type}]`, event.target, event.currentTarget, [event.clientX, event.clientY]);
107
- // }, []);
108
- //
109
- // const handleStartDebug = useCallback(
110
- // (event: any) => {
111
- // setStartEl(event.target);
112
- // handleEventDebug(event);
113
- // },
114
- // [handleEventDebug],
115
- // );
116
- //
117
- // const handleEndDebug = useCallback(
118
- // (event: any) => {
119
- // setEndEl(event.target);
120
- // handleEventDebug(event);
121
- // },
122
- // [handleEventDebug],
123
- // );
124
- //
125
- // const handleClickDebug = useCallback(
126
- // (event: any) => {
127
- // console.log('[click compare]', startEl, endEl, startEl === endEl);
128
- // handleEventDebug(event);
129
- // },
130
- // [startEl, endEl, handleEventDebug],
131
- // );
132
-
133
134
  return (
134
- <AttentionContextProvider attention={attention} path={[]}>
135
- <div
136
- role='none'
137
- className='contents'
138
- onFocusCapture={handleFocus}
139
- // onClick={handleClickDebug}
140
- // onMouseDown={handleStartDebug}
141
- // onMouseUp={handleEndDebug}
142
- >
135
+ <AttentionContextProvider attention={attention}>
136
+ <div role='none' className='contents' onFocusCapture={handleFocus}>
143
137
  {children}
144
138
  </div>
145
139
  </AttentionContextProvider>
146
140
  );
147
141
  };
148
142
 
149
- const AttentionProvider = ({ id, children }: PropsWithChildren<{ id: string }>) => {
150
- const { attention, path } = useAttentionContext(ATTENTION_NAME);
151
- const nextPath = useMemo(() => [id, ...path], [id, path]);
152
-
153
- return (
154
- <AttentionContextProvider attention={attention} path={nextPath}>
155
- {children}
156
- </AttentionContextProvider>
157
- );
158
- };
159
-
160
143
  export type AttendableContainerProps = ThemedClassName<
161
144
  ComponentPropsWithRef<'div'> & { id: string; asChild?: boolean }
162
145
  >;
163
146
 
164
147
  /**
165
- * Note that DeckPlugin and StackPlugin both handle attention on their own, and when rendering content in those cases it
166
- * is not necessary to also render an `AttendableContainer`. This component is primarily for Storybook stories and other
167
- * testing scenarios, or the rare cases where an attendable entity is rendered outside of either of those plugins.
148
+ * Note that DeckPlugin and StackPlugin both handle attention on their own,
149
+ * and when rendering content in those cases it is not necessary to also render an `AttendableContainer`.
150
+ * This component is primarily for Storybook stories and other testing scenarios,
151
+ * or the rare cases where an attendable entity is rendered outside of either of those plugins.
168
152
  */
169
153
  const AttendableContainer = forwardRef<HTMLDivElement, AttendableContainerProps>(
170
154
  ({ id, classNames, children, asChild, ...props }, forwardedRef) => {
171
155
  const attentionAttrs = useAttentionAttributes(id);
172
- const Root = asChild ? Slot : Primitive.div;
156
+ const Comp = asChild ? Slot : Primitive.div;
173
157
  return (
174
- <Root
158
+ <Comp
175
159
  role='none'
176
- {...attentionAttrs}
177
160
  {...props}
178
- className={mx('attention-surface', props.tabIndex === 0 && 'dx-focus-ring-inset-over-all', classNames)}
161
+ {...attentionAttrs}
162
+ className={mx('dx-attention-surface', props.tabIndex === 0 && 'dx-focus-ring-inset-over-all', classNames)}
179
163
  ref={forwardedRef}
180
164
  >
181
165
  {children}
182
- </Root>
166
+ </Comp>
183
167
  );
184
168
  },
185
169
  );
186
170
 
187
171
  export {
188
172
  RootAttentionProvider,
189
- AttentionProvider,
190
173
  AttendableContainer,
191
174
  useAttentionContext,
192
175
  useAttention,
193
176
  useAttended,
194
177
  useAttentionAttributes,
195
- useAttentionPath,
196
178
  ATTENTION_NAME,
197
179
  ATTENDABLE_ATTRIBUTE,
198
180
  ATTENTION_SOURCE_ATTRIBUTE,
@@ -2,11 +2,12 @@
2
2
  // Copyright 2025 DXOS.org
3
3
  //
4
4
 
5
+ import { RegistryContext } from '@effect-atom/atom-react';
5
6
  import { createContext } from '@radix-ui/react-context';
6
7
  import * as Match from 'effect/Match';
7
- import React, { type PropsWithChildren, useCallback, useMemo } from 'react';
8
+ import React, { type PropsWithChildren, useCallback, useContext, useEffect, useMemo, useState } from 'react';
8
9
 
9
- import { useDefaultValue } from '@dxos/react-ui';
10
+ import { useDefaultValue } from '@dxos/react-hooks';
10
11
 
11
12
  import {
12
13
  type Selection,
@@ -23,7 +24,7 @@ type SelectionContextValue = {
23
24
  };
24
25
 
25
26
  const [SelectionContextProvider, useSelectionContext] = createContext<SelectionContextValue>(SELECTION_NAME, {
26
- selection: new SelectionManager(),
27
+ selection: undefined as unknown as SelectionManager,
27
28
  });
28
29
 
29
30
  /**
@@ -34,7 +35,8 @@ export const SelectionProvider = ({
34
35
  children,
35
36
  selection: propsSelection,
36
37
  }: PropsWithChildren<{ selection?: SelectionManager }>) => {
37
- const selection = useDefaultValue(propsSelection, () => new SelectionManager());
38
+ const registry = useContext(RegistryContext);
39
+ const selection = useDefaultValue(propsSelection, () => new SelectionManager(registry));
38
40
  return <SelectionContextProvider selection={selection}>{children}</SelectionContextProvider>;
39
41
  };
40
42
 
@@ -46,6 +48,18 @@ export const useSelectionManager = () => {
46
48
  return selection;
47
49
  };
48
50
 
51
+ const getDefaultResult = <T extends SelectionMode>(mode: T): SelectionResult<T> => {
52
+ return Match.type<Selection>().pipe(
53
+ Match.when({ mode: 'single' }, (selection) => selection.id),
54
+ Match.when({ mode: 'multi' }, (selection) => selection.ids),
55
+ Match.when({ mode: 'range' }, (selection) =>
56
+ selection.from && selection.to ? { from: selection.from, to: selection.to } : undefined,
57
+ ),
58
+ Match.when({ mode: 'multi-range' }, (selection) => selection.ranges),
59
+ Match.exhaustive,
60
+ )(defaultSelection(mode)) as SelectionResult<T>;
61
+ };
62
+
49
63
  /**
50
64
  * Get the selected objects for a given context.
51
65
  */
@@ -54,28 +68,49 @@ export const useSelected = <T extends SelectionMode>(
54
68
  mode: T = 'multi' as T,
55
69
  ): SelectionResult<T> => {
56
70
  const { selection } = useSelectionContext(SELECTION_NAME);
57
- if (contextId) {
58
- return selection.getSelected(contextId, mode);
59
- }
71
+ const [state, setState] = useState<SelectionResult<T>>(() =>
72
+ contextId && selection ? selection.getSelected(contextId, mode) : getDefaultResult(mode),
73
+ );
60
74
 
61
- return Match.type<Selection>().pipe(
62
- Match.when({ mode: 'single' }, (s) => s.id),
63
- Match.when({ mode: 'multi' }, (s) => s.ids),
64
- Match.when({ mode: 'range' }, (s) => (s.from && s.to ? { from: s.from, to: s.to } : undefined)),
65
- Match.when({ mode: 'multi-range' }, (s) => s.ranges),
66
- Match.exhaustive,
67
- )(defaultSelection(mode)) as any;
75
+ useEffect(() => {
76
+ if (!contextId || !selection) {
77
+ setState(getDefaultResult(mode));
78
+ return;
79
+ }
80
+
81
+ // Set initial state.
82
+ setState(selection.getSelected(contextId, mode));
83
+
84
+ // Subscribe to changes.
85
+ return selection.subscribe(() => {
86
+ setState(selection.getSelected(contextId, mode));
87
+ });
88
+ }, [selection, contextId, mode]);
89
+
90
+ return state;
91
+ };
92
+
93
+ export type UseSelectionActions = {
94
+ singleSelect: (id: string) => void;
95
+ multiSelect: (ids: string[]) => void;
96
+ rangeSelect: (from: string, to: string) => void;
97
+ toggle: (id: string) => void;
98
+ clear: () => void;
68
99
  };
69
100
 
70
101
  /**
71
102
  * Provides functions to manage the selection state for multiple contexts.
72
103
  */
73
- export const useSelectionActions = (contextIds: string[], mode: SelectionMode = 'multi') => {
104
+ // TODO(burdon): Mode not used.
105
+ export const useSelectionActions = (contextIds: string[], mode: SelectionMode = 'multi'): UseSelectionActions => {
74
106
  const stableContextIds = useMemo(() => contextIds, [JSON.stringify(contextIds)]); // TODO(burdon): Avoid stringify.
75
107
  const { selection } = useSelectionContext(SELECTION_NAME);
76
108
 
77
109
  const singleSelect = useCallback(
78
110
  (id: string) => {
111
+ if (!selection) {
112
+ return;
113
+ }
79
114
  for (const contextId of stableContextIds) {
80
115
  selection.updateSingle(contextId, id);
81
116
  }
@@ -85,6 +120,9 @@ export const useSelectionActions = (contextIds: string[], mode: SelectionMode =
85
120
 
86
121
  const multiSelect = useCallback(
87
122
  (ids: string[]) => {
123
+ if (!selection) {
124
+ return;
125
+ }
88
126
  for (const contextId of stableContextIds) {
89
127
  selection.updateMulti(contextId, ids);
90
128
  }
@@ -94,6 +132,9 @@ export const useSelectionActions = (contextIds: string[], mode: SelectionMode =
94
132
 
95
133
  const rangeSelect = useCallback(
96
134
  (from: string, to: string) => {
135
+ if (!selection) {
136
+ return;
137
+ }
97
138
  for (const contextId of stableContextIds) {
98
139
  selection.updateRange(contextId, from, to);
99
140
  }
@@ -103,6 +144,9 @@ export const useSelectionActions = (contextIds: string[], mode: SelectionMode =
103
144
 
104
145
  const toggle = useCallback(
105
146
  (id: string) => {
147
+ if (!selection) {
148
+ return;
149
+ }
106
150
  for (const contextId of stableContextIds) {
107
151
  selection.toggleSelection(contextId, id);
108
152
  }
@@ -111,6 +155,9 @@ export const useSelectionActions = (contextIds: string[], mode: SelectionMode =
111
155
  );
112
156
 
113
157
  const clear = useCallback(() => {
158
+ if (!selection) {
159
+ return;
160
+ }
114
161
  for (const contextId of stableContextIds) {
115
162
  selection.clearSelection(contextId);
116
163
  }
package/src/index.ts CHANGED
@@ -5,3 +5,4 @@
5
5
  export * from './attention';
6
6
  export * from './components';
7
7
  export * from './selection';
8
+ export * from './types';