@jetbrains/ring-ui-built 8.0.0-beta.3 → 8.0.0-beta.4

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 (82) hide show
  1. package/components/_helpers/heading.js +2 -2
  2. package/components/_helpers/table.js +1 -1
  3. package/components/_helpers/theme.js +1 -1
  4. package/components/alert/alert.js +1 -1
  5. package/components/auth/iframe-flow.js +1 -1
  6. package/components/checkbox/checkbox.d.ts +1 -1
  7. package/components/collapsible-group/collapsible-group.d.ts +20 -0
  8. package/components/collapsible-group/collapsible-group.js +382 -0
  9. package/components/components/util-stories.js +63 -1
  10. package/components/data-list/data-list.js +1 -1
  11. package/components/data-list/title.js +1 -1
  12. package/components/date-picker/date-popup.js +3 -3
  13. package/components/dropdown-menu/dropdown-menu.js +6 -6
  14. package/components/editable-heading/editable-heading.js +122 -109
  15. package/components/expand/collapsible-group.d.ts +8 -20
  16. package/components/expand/collapsible-group.js +34 -365
  17. package/components/global/compose-refs.d.ts +2 -1
  18. package/components/global/compose-refs.js +44 -8
  19. package/components/global/focus-sensor-hoc.js +1 -0
  20. package/components/global/focus-with-temporary-tabindex.d.ts +11 -0
  21. package/components/global/focus-with-temporary-tabindex.js +23 -0
  22. package/components/global/intersection-observer-context.d.ts +29 -9
  23. package/components/global/intersection-observer-context.js +50 -52
  24. package/components/global/is-within-interactive-element.d.ts +6 -0
  25. package/components/global/is-within-interactive-element.js +11 -0
  26. package/components/global/is-within-navigable-element.d.ts +6 -0
  27. package/components/global/is-within-navigable-element.js +11 -0
  28. package/components/global/parse-css-duration.d.ts +5 -0
  29. package/components/global/parse-css-duration.js +14 -0
  30. package/components/global/rerender-hoc.js +1 -0
  31. package/components/global/schedule-with-cleanup.d.ts +12 -0
  32. package/components/global/schedule-with-cleanup.js +36 -0
  33. package/components/global/table-selection.js +1 -1
  34. package/components/global/theme.js +1 -1
  35. package/components/header/header.js +1 -1
  36. package/components/heading/heading.js +3 -3
  37. package/components/input/input.d.ts +1 -1
  38. package/components/internal/column-animation.js +133 -0
  39. package/components/internal/table-header.js +1109 -0
  40. package/components/{table/table-virtualize.js → internal/virtual-items.js} +108 -84
  41. package/components/legacy-table/header-cell.js +2 -2
  42. package/components/legacy-table/row-with-focus-sensor.js +1 -1
  43. package/components/legacy-table/row.d.ts +1 -1
  44. package/components/legacy-table/simple-table.js +1 -1
  45. package/components/legacy-table/smart-table.js +1 -1
  46. package/components/legacy-table/table.js +1 -1
  47. package/components/markdown/markdown.js +2 -2
  48. package/components/message/message.js +1 -1
  49. package/components/old-browsers-message/white-list.js +2 -2
  50. package/components/popup/popup.d.ts +2 -0
  51. package/components/popup/popup.js +5 -1
  52. package/components/select/select-popup.d.ts +1 -1
  53. package/components/select/select.d.ts +1 -1
  54. package/components/style.css +1 -1
  55. package/components/table/default-item-renderer.d.ts +23 -10
  56. package/components/table/default-item-renderer.js +104 -98
  57. package/components/table/internal/column-animation.d.ts +16 -0
  58. package/components/table/internal/table-header.d.ts +4 -0
  59. package/components/table/internal/virtual-items.d.ts +34 -0
  60. package/components/table/item-virtualization.d.ts +35 -0
  61. package/components/table/item-virtualization.js +71 -0
  62. package/components/table/table-const.d.ts +40 -6
  63. package/components/table/table-const.js +15 -6
  64. package/components/table/table-primitives.d.ts +9 -16
  65. package/components/table/table-primitives.js +11 -211
  66. package/components/table/table-props.d.ts +280 -0
  67. package/components/table/table-props.js +1 -0
  68. package/components/table/table.d.ts +205 -209
  69. package/components/table/table.js +356 -15
  70. package/components/tooltip/tooltip.js +1 -1
  71. package/components/user-agreement/service.js +6 -6
  72. package/components/util-stories.d.ts +26 -0
  73. package/package.json +2 -2
  74. package/components/date-picker/use-intersection-observer.d.ts +0 -6
  75. package/components/date-picker/use-intersection-observer.js +0 -93
  76. package/components/global/composeRefs.d.ts +0 -6
  77. package/components/global/composeRefs.js +0 -9
  78. package/components/table/table-component.d.ts +0 -80
  79. package/components/table/table-component.js +0 -290
  80. package/components/table/table-row-focus.d.ts +0 -4
  81. package/components/table/table-row-focus.js +0 -41
  82. package/components/table/table-virtualize.d.ts +0 -32
@@ -1,382 +1,51 @@
1
1
  import { c } from 'react/compiler-runtime';
2
- import { useState, use } from 'react';
3
- import classNames from 'classnames';
4
- import chevronRightIcon from '@jetbrains/icons/chevron-12px-right';
5
- import chevron12pxDown from '@jetbrains/icons/chevron-12px-down';
6
- import Icon from '../icon/icon.js';
7
- import { Collapse } from '../collapse/collapse.js';
8
- import { CollapseContent } from '../collapse/collapse-content.js';
9
- import { CollapseContext } from '../collapse/collapse-context.js';
10
- import { jsx, jsxs } from 'react/jsx-runtime';
11
- import 'util-deprecate';
2
+ import { forwardRef } from 'react';
3
+ import deprecate from 'util-deprecate';
4
+ import CollapsibleGroup from '../collapsible-group/collapsible-group.js';
5
+ import { jsx } from 'react/jsx-runtime';
6
+ import 'classnames';
7
+ import '@jetbrains/icons/chevron-12px-right';
8
+ import '@jetbrains/icons/chevron-12px-down';
9
+ import '../icon/icon.js';
12
10
  import '../icon/icon.constants.js';
13
11
  import '../_helpers/icon-svg.js';
14
12
  import '../global/memoize.js';
13
+ import '../collapse/collapse.js';
14
+ import '../collapse/collapse-context.js';
15
15
  import '../collapse/consts.js';
16
+ import '../collapse/collapse-content.js';
16
17
  import '../global/data-tests.js';
17
18
  import '../global/dom.js';
18
19
  import '../collapse/utils.js';
19
20
 
20
- var styles = {"expand":"ring-collapsible-group-expand","collapseRoot":"ring-collapsible-group-collapseRoot","hovered":"ring-collapsible-group-hovered","expanded":"ring-collapsible-group-expanded","focused":"ring-collapsible-group-focused","header":"ring-collapsible-group-header","headerButton":"ring-collapsible-group-headerButton","headerStatic":"ring-collapsible-group-headerStatic","headerContent":"ring-collapsible-group-headerContent","avatarGroup":"ring-collapsible-group-avatarGroup","title":"ring-collapsible-group-title","subtitleGroup":"ring-collapsible-group-subtitleGroup","subtitle":"ring-collapsible-group-subtitle","subtitleChevron":"ring-collapsible-group-subtitleChevron","toggle":"ring-collapsible-group-toggle","toggleIcon":"ring-collapsible-group-toggleIcon","body":"ring-collapsible-group-body"};
21
-
22
- function CollapsibleGroupHeaderContent(t0) {
23
- const $ = c(16);
24
- if ($[0] !== "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768") {
25
- for (let $i = 0; $i < 16; $i += 1) {
26
- $[$i] = Symbol.for("react.memo_cache_sentinel");
27
- }
28
- $[0] = "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768";
29
- }
30
- const {
31
- avatar,
32
- titleContent,
33
- subtitle
34
- } = t0;
35
- const {
36
- collapsed
37
- } = use(CollapseContext);
38
- let t1;
39
- if ($[1] !== titleContent) {
40
- t1 = /*#__PURE__*/jsx("span", {
41
- className: styles.title,
42
- children: titleContent
43
- });
44
- $[1] = titleContent;
45
- $[2] = t1;
46
- } else {
47
- t1 = $[2];
48
- }
49
- let t2;
50
- if ($[3] !== avatar || $[4] !== t1) {
51
- t2 = /*#__PURE__*/jsxs("span", {
52
- className: styles.avatarGroup,
53
- children: [avatar, t1]
54
- });
55
- $[3] = avatar;
56
- $[4] = t1;
57
- $[5] = t2;
58
- } else {
59
- t2 = $[5];
60
- }
61
- let t3;
62
- if ($[6] !== subtitle) {
63
- t3 = subtitle ? /*#__PURE__*/jsxs("span", {
64
- className: styles.subtitleGroup,
65
- children: [/*#__PURE__*/jsx(Icon, {
66
- className: styles.subtitleChevron,
67
- glyph: chevronRightIcon,
68
- "aria-hidden": true
69
- }), /*#__PURE__*/jsx("span", {
70
- className: styles.subtitle,
71
- children: subtitle
72
- })]
73
- }) : null;
74
- $[6] = subtitle;
75
- $[7] = t3;
76
- } else {
77
- t3 = $[7];
78
- }
79
- let t4;
80
- if ($[8] !== t2 || $[9] !== t3) {
81
- t4 = /*#__PURE__*/jsxs("span", {
82
- className: styles.headerContent,
83
- children: [t2, t3]
84
- });
85
- $[8] = t2;
86
- $[9] = t3;
87
- $[10] = t4;
88
- } else {
89
- t4 = $[10];
90
- }
91
- const t5 = collapsed ? chevronRightIcon : chevron12pxDown;
92
- let t6;
93
- if ($[11] !== t5) {
94
- t6 = /*#__PURE__*/jsx("span", {
95
- className: styles.toggle,
96
- "aria-hidden": true,
97
- children: /*#__PURE__*/jsx(Icon, {
98
- className: styles.toggleIcon,
99
- glyph: t5
100
- })
101
- });
102
- $[11] = t5;
103
- $[12] = t6;
104
- } else {
105
- t6 = $[12];
106
- }
107
- let t7;
108
- if ($[13] !== t4 || $[14] !== t6) {
109
- t7 = /*#__PURE__*/jsxs("span", {
110
- className: styles.header,
111
- children: [t4, t6]
112
- });
113
- $[13] = t4;
114
- $[14] = t6;
115
- $[15] = t7;
116
- } else {
117
- t7 = $[15];
118
- }
119
- return t7;
120
- }
121
- function CollapsibleGroupHeader(t0) {
122
- const $ = c(16);
123
- if ($[0] !== "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768") {
124
- for (let $i = 0; $i < 16; $i += 1) {
125
- $[$i] = Symbol.for("react.memo_cache_sentinel");
126
- }
127
- $[0] = "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768";
128
- }
129
- let avatar;
130
- let buttonProps;
131
- let subtitle;
132
- let titleContent;
133
- if ($[1] !== t0) {
134
- ({
135
- avatar,
136
- titleContent,
137
- subtitle,
138
- ...buttonProps
139
- } = t0);
140
- $[1] = t0;
141
- $[2] = avatar;
142
- $[3] = buttonProps;
143
- $[4] = subtitle;
144
- $[5] = titleContent;
145
- } else {
146
- avatar = $[2];
147
- buttonProps = $[3];
148
- subtitle = $[4];
149
- titleContent = $[5];
150
- }
151
- const {
152
- setCollapsed,
153
- collapsed,
154
- id
155
- } = use(CollapseContext);
156
- const t1 = `collapse-content-${id}`;
157
- const t2 = !collapsed;
158
- let t3;
159
- if ($[6] !== avatar || $[7] !== subtitle || $[8] !== titleContent) {
160
- t3 = /*#__PURE__*/jsx(CollapsibleGroupHeaderContent, {
161
- avatar: avatar,
162
- titleContent: titleContent,
163
- subtitle: subtitle
164
- });
165
- $[6] = avatar;
166
- $[7] = subtitle;
167
- $[8] = titleContent;
168
- $[9] = t3;
169
- } else {
170
- t3 = $[9];
171
- }
172
- let t4;
173
- if ($[10] !== buttonProps || $[11] !== setCollapsed || $[12] !== t1 || $[13] !== t2 || $[14] !== t3) {
174
- t4 = /*#__PURE__*/jsx("button", {
175
- type: "button",
176
- ...buttonProps,
177
- className: styles.headerButton,
178
- onClick: setCollapsed,
179
- "aria-controls": t1,
180
- "aria-expanded": t2,
181
- children: t3
182
- });
183
- $[10] = buttonProps;
184
- $[11] = setCollapsed;
185
- $[12] = t1;
186
- $[13] = t2;
187
- $[14] = t3;
188
- $[15] = t4;
189
- } else {
190
- t4 = $[15];
191
- }
192
- return t4;
193
- }
194
- function CollapsibleGroupHeaderStatic(t0) {
195
- const $ = c(5);
196
- if ($[0] !== "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768") {
197
- for (let $i = 0; $i < 5; $i += 1) {
198
- $[$i] = Symbol.for("react.memo_cache_sentinel");
199
- }
200
- $[0] = "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768";
201
- }
202
- const {
203
- avatar,
204
- titleContent,
205
- subtitle
206
- } = t0;
207
- let t1;
208
- if ($[1] !== avatar || $[2] !== subtitle || $[3] !== titleContent) {
209
- t1 = /*#__PURE__*/jsx("span", {
210
- className: styles.headerStatic,
211
- children: /*#__PURE__*/jsx(CollapsibleGroupHeaderContent, {
212
- avatar: avatar,
213
- titleContent: titleContent,
214
- subtitle: subtitle
215
- })
216
- });
217
- $[1] = avatar;
218
- $[2] = subtitle;
219
- $[3] = titleContent;
220
- $[4] = t1;
221
- } else {
222
- t1 = $[4];
223
- }
224
- return t1;
225
- }
226
- const CollapsibleGroup = t0 => {
227
- const $ = c(29);
228
- if ($[0] !== "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768") {
229
- for (let $i = 0; $i < 29; $i += 1) {
21
+ const warnDeprecation = deprecate(() => {}, '`CollapsibleGroup` from `@jetbrains/ring-ui/components/expand/collapsible-group` is deprecated and will be removed in Ring UI 8.0. Import it from `@jetbrains/ring-ui/components/collapsible-group/collapsible-group` instead.');
22
+ /**
23
+ * @deprecated The `expand` module has been renamed to `collapsible-group`. This re-export will be removed in
24
+ * Ring UI 8.0. Use `CollapsibleGroup` from `@jetbrains/ring-ui/components/collapsible-group/collapsible-group` instead.
25
+ */
26
+ const DeprecatedCollapsibleGroup = /*#__PURE__*/forwardRef((props, ref) => {
27
+ const $ = c(4);
28
+ if ($[0] !== "dc9f603c6e591e91f020cc5faed8f169e693dd93fe948fc345146a82715c1a34") {
29
+ for (let $i = 0; $i < 4; $i += 1) {
230
30
  $[$i] = Symbol.for("react.memo_cache_sentinel");
231
31
  }
232
- $[0] = "0b0104270833ca27f2118e72fd68547a84ef5bf33921c0d276e95941f6f80768";
233
- }
234
- const {
235
- ref,
236
- avatar,
237
- title,
238
- subtitle,
239
- children,
240
- className,
241
- defaultExpanded: t1,
242
- expanded: t2,
243
- onChange: t3,
244
- disableAnimation: t4,
245
- interactive: t5,
246
- "data-test": dataTest
247
- } = t0;
248
- const defaultExpanded = t1 === undefined ? false : t1;
249
- const expanded = t2 === undefined ? null : t2;
250
- const onChange = t3 === undefined ? _temp : t3;
251
- const disableAnimation = t4 === undefined ? false : t4;
252
- const interactive = t5 === undefined ? true : t5;
253
- const [innerExpanded, setInnerExpanded] = useState(defaultExpanded);
254
- const [hovered, setHovered] = useState(false);
255
- const [focused, setFocused] = useState(false);
256
- const isExpanded = expanded !== null && expanded !== void 0 ? expanded : innerExpanded;
257
- let t6;
258
- if ($[1] !== expanded || $[2] !== onChange) {
259
- t6 = collapsed => {
260
- const nextExpanded = !collapsed;
261
- if (expanded == null) {
262
- setInnerExpanded(nextExpanded);
263
- }
264
- onChange(nextExpanded);
265
- };
266
- $[1] = expanded;
267
- $[2] = onChange;
268
- $[3] = t6;
269
- } else {
270
- t6 = $[3];
271
- }
272
- const handleChange = t6;
273
- let t7;
274
- if ($[4] === Symbol.for("react.memo_cache_sentinel")) {
275
- t7 = event => {
276
- const nextTarget = event.relatedTarget;
277
- if (nextTarget instanceof Node && event.currentTarget.contains(nextTarget)) {
278
- return;
279
- }
280
- setFocused(false);
281
- };
282
- $[4] = t7;
283
- } else {
284
- t7 = $[4];
285
- }
286
- const onBlur = t7;
287
- let t8;
288
- if ($[5] !== className || $[6] !== focused || $[7] !== hovered || $[8] !== isExpanded) {
289
- t8 = classNames(styles.expand, className, {
290
- [styles.hovered]: hovered,
291
- [styles.expanded]: isExpanded,
292
- [styles.focused]: focused
293
- });
294
- $[5] = className;
295
- $[6] = focused;
296
- $[7] = hovered;
297
- $[8] = isExpanded;
298
- $[9] = t8;
299
- } else {
300
- t8 = $[9];
301
- }
302
- const classes = t8;
303
- const t9 = !defaultExpanded;
304
- const t10 = expanded == null ? null : !expanded;
305
- let t11;
306
- if ($[10] !== avatar || $[11] !== interactive || $[12] !== subtitle || $[13] !== title) {
307
- t11 = interactive ? /*#__PURE__*/jsx(CollapsibleGroupHeader, {
308
- avatar: avatar,
309
- titleContent: title,
310
- subtitle: subtitle,
311
- onMouseEnter: () => setHovered(true),
312
- onMouseLeave: () => setHovered(false),
313
- onFocus: () => setFocused(true),
314
- onBlur: onBlur
315
- }) : /*#__PURE__*/jsx(CollapsibleGroupHeaderStatic, {
316
- avatar: avatar,
317
- titleContent: title,
318
- subtitle: subtitle
319
- });
320
- $[10] = avatar;
321
- $[11] = interactive;
322
- $[12] = subtitle;
323
- $[13] = title;
324
- $[14] = t11;
325
- } else {
326
- t11 = $[14];
327
- }
328
- let t12;
329
- if ($[15] !== children) {
330
- t12 = /*#__PURE__*/jsx(CollapseContent, {
331
- children: /*#__PURE__*/jsx("div", {
332
- className: styles.body,
333
- children: children
334
- })
335
- });
336
- $[15] = children;
337
- $[16] = t12;
338
- } else {
339
- t12 = $[16];
340
- }
341
- let t13;
342
- if ($[17] !== disableAnimation || $[18] !== handleChange || $[19] !== t10 || $[20] !== t11 || $[21] !== t12 || $[22] !== t9) {
343
- t13 = /*#__PURE__*/jsxs(Collapse, {
344
- defaultCollapsed: t9,
345
- collapsed: t10,
346
- onChange: handleChange,
347
- disableAnimation: disableAnimation,
348
- className: styles.collapseRoot,
349
- children: [t11, t12]
350
- });
351
- $[17] = disableAnimation;
352
- $[18] = handleChange;
353
- $[19] = t10;
354
- $[20] = t11;
355
- $[21] = t12;
356
- $[22] = t9;
357
- $[23] = t13;
358
- } else {
359
- t13 = $[23];
32
+ $[0] = "dc9f603c6e591e91f020cc5faed8f169e693dd93fe948fc345146a82715c1a34";
360
33
  }
361
- let t14;
362
- if ($[24] !== classes || $[25] !== dataTest || $[26] !== ref || $[27] !== t13) {
363
- t14 = /*#__PURE__*/jsx("div", {
34
+ warnDeprecation();
35
+ let t0;
36
+ if ($[1] !== props || $[2] !== ref) {
37
+ t0 = /*#__PURE__*/jsx(CollapsibleGroup, {
364
38
  ref: ref,
365
- className: classes,
366
- "data-test": dataTest,
367
- children: t13
39
+ ...props
368
40
  });
369
- $[24] = classes;
370
- $[25] = dataTest;
371
- $[26] = ref;
372
- $[27] = t13;
373
- $[28] = t14;
41
+ $[1] = props;
42
+ $[2] = ref;
43
+ $[3] = t0;
374
44
  } else {
375
- t14 = $[28];
45
+ t0 = $[3];
376
46
  }
377
- return t14;
378
- };
379
- CollapsibleGroup.displayName = 'CollapsibleGroup';
380
- function _temp() {}
47
+ return t0;
48
+ });
49
+ DeprecatedCollapsibleGroup.displayName = 'CollapsibleGroup';
381
50
 
382
- export { CollapsibleGroup as default };
51
+ export { DeprecatedCollapsibleGroup as default };
@@ -1,2 +1,3 @@
1
1
  import { type Ref } from 'react';
2
- export declare function createComposedRef<T>(): import("memoize-one").MemoizedFn<(...refs: (Ref<T> | undefined)[]) => (value: T | null) => void>;
2
+ export declare function createComposedRef<T>(): import("memoize-one").MemoizedFn<(...refs: (Ref<T> | undefined)[]) => (value: T | null) => () => void>;
3
+ export declare function useComposedRef<T>(...refs: (Ref<T> | undefined)[]): Ref<T>;
@@ -1,16 +1,52 @@
1
+ import { c } from 'react/compiler-runtime';
2
+ import 'react';
1
3
  import memoizeOne from 'memoize-one';
2
4
 
3
5
  function composeRefs(...refs) {
4
- return value => refs.forEach(ref => {
5
- if (typeof ref === 'function') {
6
- ref(value);
7
- } else if (ref) {
8
- ref.current = value;
9
- }
10
- });
6
+ return value => {
7
+ const cleanups = [];
8
+ refs.forEach(ref => {
9
+ if (typeof ref === 'function') {
10
+ const cleanup = ref(value);
11
+ if (typeof cleanup === 'function') {
12
+ cleanups.push(cleanup);
13
+ }
14
+ } else if (ref) {
15
+ ref.current = value;
16
+ }
17
+ });
18
+ return () => cleanups.forEach(cleanup => cleanup());
19
+ };
11
20
  }
12
21
  function createComposedRef() {
13
22
  return memoizeOne(composeRefs);
14
23
  }
24
+ function useComposedRef(...t0) {
25
+ const $ = c(4);
26
+ if ($[0] !== "27d6e427dad1098fabcf040df3e7a3018e96f8cc69541f012bb950b976d64df8") {
27
+ for (let $i = 0; $i < 4; $i += 1) {
28
+ $[$i] = Symbol.for("react.memo_cache_sentinel");
29
+ }
30
+ $[0] = "27d6e427dad1098fabcf040df3e7a3018e96f8cc69541f012bb950b976d64df8";
31
+ }
32
+ const refs = t0;
33
+ let t1;
34
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
35
+ t1 = createComposedRef();
36
+ $[1] = t1;
37
+ } else {
38
+ t1 = $[1];
39
+ }
40
+ const composer = t1;
41
+ let t2;
42
+ if ($[2] !== refs) {
43
+ t2 = composer(...refs);
44
+ $[2] = refs;
45
+ $[3] = t2;
46
+ } else {
47
+ t2 = $[3];
48
+ }
49
+ return t2;
50
+ }
15
51
 
16
- export { createComposedRef };
52
+ export { createComposedRef, useComposedRef };
@@ -1,6 +1,7 @@
1
1
  import { Component } from 'react';
2
2
  import { createComposedRef } from './compose-refs.js';
3
3
  import { jsx } from 'react/jsx-runtime';
4
+ import 'react/compiler-runtime';
4
5
  import 'memoize-one';
5
6
 
6
7
  function focusSensorHOC(ComposedComponent) {
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Focuses an element, temporarily adding `tabindex="0"` if necessary.
3
+ *
4
+ * If the element does not already have a `tabindex` attribute, one is
5
+ * added before focusing and automatically removed when the element loses
6
+ * focus.
7
+ *
8
+ * This is useful when implementing roving tabindex patterns on elements
9
+ * that are not normally focusable.
10
+ */
11
+ export declare function focusWithTemporaryTabIndex(element: HTMLElement): void;
@@ -0,0 +1,23 @@
1
+ /**
2
+ * Focuses an element, temporarily adding `tabindex="0"` if necessary.
3
+ *
4
+ * If the element does not already have a `tabindex` attribute, one is
5
+ * added before focusing and automatically removed when the element loses
6
+ * focus.
7
+ *
8
+ * This is useful when implementing roving tabindex patterns on elements
9
+ * that are not normally focusable.
10
+ */
11
+ function focusWithTemporaryTabIndex(element) {
12
+ if (!element.hasAttribute('tabindex')) {
13
+ element.tabIndex = 0;
14
+ function onBlur() {
15
+ element.removeAttribute('tabindex');
16
+ element.removeEventListener('blur', onBlur);
17
+ }
18
+ element.addEventListener('blur', onBlur);
19
+ }
20
+ element.focus();
21
+ }
22
+
23
+ export { focusWithTemporaryTabIndex };
@@ -1,5 +1,21 @@
1
1
  import { type RefObject } from 'react';
2
2
  /**
3
+ * Provides access to a shared `IntersectionObserver` instance
4
+ * via the {@link IntersectionObserverContext} context.
5
+ *
6
+ * @see IntersectionObserverContext
7
+ */
8
+ export interface IntersectionObserverHandle {
9
+ /**
10
+ * Starts observing an element.
11
+ *
12
+ * Returns a cleanup function that stops observing it.
13
+ */
14
+ observe(element: Element, isIntersecting: (isIntersecting: boolean) => void): () => void;
15
+ }
16
+ /**
17
+ * Multiple components can share a single `IntersectionObserver` instance through this context.
18
+ *
3
19
  * Usage:
4
20
  *
5
21
  * ```tsx
@@ -10,17 +26,21 @@ import { type RefObject } from 'react';
10
26
  * function YourComponent() {
11
27
  * // Contains the current isIntersecting value
12
28
  * const isIntersecting = useIsIntersecting(elementRef);
13
- * // Or, to get updates instead:
14
- * useIsIntersectingListener(elementRef, newIsIntersecting => {
15
- * // ...
29
+ *
30
+ * // Or, to manually work with the IntersectionObserverHandle:
31
+ * const handle = use(IntersectionObserverContext);
32
+ * useEffect(() => {
33
+ * return handle.observe(elementRef.current, isIntersecting => { ... })
16
34
  * })
17
35
  * }
18
36
  * ```
19
37
  */
20
- export declare const IntersectionObserverContext: import("react").Context<IntersectionObserverHandle | null>;
21
- export declare function useIntersectionObserverHandle(rootRef?: RefObject<HTMLElement | null>, rootMargin?: number, scrollMargin?: number): IntersectionObserverHandle | null;
22
- export interface IntersectionObserverHandle {
23
- observe(element: Element, setIsIntersecting: (isIntersecting: boolean) => void): () => void;
24
- }
38
+ export declare const IntersectionObserverContext: import("react").Context<IntersectionObserverHandle>;
39
+ /**
40
+ * Creates an IntersectionObserverHandle suitable for {@link IntersectionObserverContext}.
41
+ */
42
+ export declare function useIntersectionObserverHandle(rootRef?: RefObject<HTMLElement | null>, rootMargin?: number, scrollMargin?: number): IntersectionObserverHandle;
43
+ /**
44
+ * Returns whether the referenced element is currently intersecting.
45
+ */
25
46
  export declare function useIsIntersecting(elementRef: RefObject<Element | null>): boolean;
26
- export declare function useIsIntersectingListener(elementRef: RefObject<Element | null>, onChange: (isIntersecting: boolean) => void): void;