@jetbrains/ring-ui 8.0.0-beta.3 → 8.0.0-beta.5
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/components/alert/alert-actions.d.ts +4 -0
- package/components/alert/alert-actions.js +5 -0
- package/components/alert/alert-heading.d.ts +4 -0
- package/components/alert/alert-heading.js +6 -0
- package/components/alert/alert.css +63 -22
- package/components/alert/alert.d.ts +14 -1
- package/components/alert/alert.js +34 -19
- package/components/alert/container.css +1 -2
- package/components/alert-service/alert-service.d.ts +2 -1
- package/components/alert-service/alert-service.js +8 -4
- package/components/auth/auth-core.d.ts +5 -9
- package/components/auth/auth-core.js +56 -15
- package/components/button-group/button-group.css +5 -5
- package/components/checkbox/checkbox.d.ts +1 -1
- package/components/collapsible-group/collapsible-group.css +138 -0
- package/components/collapsible-group/collapsible-group.d.ts +20 -0
- package/components/collapsible-group/collapsible-group.js +73 -0
- package/components/date-picker/consts.d.ts +1 -0
- package/components/date-picker/date-input.js +6 -2
- package/components/editable-heading/editable-heading.js +14 -14
- package/components/expand/collapsible-group.css +23 -89
- package/components/expand/collapsible-group.d.ts +8 -20
- package/components/expand/collapsible-group.js +14 -73
- package/components/global/compose-refs.d.ts +2 -1
- package/components/global/compose-refs.js +24 -8
- package/components/global/focus-with-temporary-tabindex.d.ts +11 -0
- package/components/global/focus-with-temporary-tabindex.js +21 -0
- package/components/global/intersection-observer-context.d.ts +29 -9
- package/components/global/intersection-observer-context.js +43 -24
- package/components/global/is-within-interactive-element.d.ts +6 -0
- package/components/global/is-within-interactive-element.js +26 -0
- package/components/global/is-within-navigable-element.d.ts +6 -0
- package/components/global/is-within-navigable-element.js +27 -0
- package/components/global/parse-css-duration.d.ts +5 -0
- package/components/global/parse-css-duration.js +13 -0
- package/components/global/schedule-with-cleanup.d.ts +12 -0
- package/components/global/schedule-with-cleanup.js +34 -0
- package/components/global/table-selection.js +1 -1
- package/components/header/header.css +3 -3
- package/components/http/http.d.ts +2 -2
- package/components/http/http.js +2 -2
- package/components/i18n/i18n.d.ts +1 -0
- package/components/i18n/messages.json +1 -0
- package/components/input/input.d.ts +1 -1
- package/components/legacy-table/row.d.ts +1 -1
- package/components/popup/popup.d.ts +2 -0
- package/components/popup/popup.js +2 -2
- package/components/select/select-popup.d.ts +1 -1
- package/components/select/select.d.ts +1 -1
- package/components/table/default-item-renderer.d.ts +29 -10
- package/components/table/default-item-renderer.js +53 -19
- package/components/table/internal/reorder-animation-context.d.ts +21 -0
- package/components/table/internal/reorder-animation-context.js +60 -0
- package/components/table/internal/reorder-handle.d.ts +9 -0
- package/components/table/internal/reorder-handle.js +334 -0
- package/components/table/internal/reorder-layout-context.d.ts +16 -0
- package/components/table/internal/reorder-layout-context.js +69 -0
- package/components/table/internal/table-header.d.ts +1 -0
- package/components/table/internal/table-header.js +143 -0
- package/components/table/internal/virtualization.d.ts +41 -0
- package/components/table/{table-virtualize.js → internal/virtualization.js} +74 -37
- package/components/table/item-virtualization.d.ts +37 -0
- package/components/table/item-virtualization.js +26 -0
- package/components/table/reorder-animation.d.ts +37 -0
- package/components/table/reorder-animation.js +11 -0
- package/components/table/reorder-item-layout.d.ts +32 -0
- package/components/table/reorder-item-layout.js +23 -0
- package/components/table/table-const.d.ts +8 -6
- package/components/table/table-const.js +7 -5
- package/components/table/table-primitives.d.ts +52 -16
- package/components/table/table-primitives.js +15 -60
- package/components/table/table-props.d.ts +304 -0
- package/components/table/table-props.js +1 -0
- package/components/table/table.css +179 -67
- package/components/table/table.d.ts +231 -209
- package/components/table/table.js +327 -2
- package/components/user-card/smart-user-card-tooltip.d.ts +1 -1
- package/components/util-stories.d.ts +26 -0
- package/components/util-stories.js +61 -0
- package/package.json +35 -36
- package/components/date-picker/use-intersection-observer.d.ts +0 -6
- package/components/date-picker/use-intersection-observer.js +0 -48
- package/components/global/composeRefs.d.ts +0 -6
- package/components/global/composeRefs.js +0 -7
- package/components/table/table-component.d.ts +0 -80
- package/components/table/table-component.js +0 -130
- package/components/table/table-row-focus.d.ts +0 -4
- package/components/table/table-row-focus.js +0 -42
- package/components/table/table-virtualize.d.ts +0 -32
|
@@ -1,2 +1,327 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import React, { Fragment, useRef } from 'react';
|
|
2
|
+
import classNames from 'classnames';
|
|
3
|
+
import { SpacerRow, useVirtualItems, VirtualizationContext } from './internal/virtualization';
|
|
4
|
+
import { DefaultItemRenderer } from './default-item-renderer';
|
|
5
|
+
import { defaultRowHeight, TablePropsContext } from './table-const';
|
|
6
|
+
import { focusWithTemporaryTabIndex } from '../global/focus-with-temporary-tabindex';
|
|
7
|
+
import { ReorderAnimationContext, useReorderAnimationContextValue } from './internal/reorder-animation-context';
|
|
8
|
+
import { useComposedRef } from '../global/compose-refs';
|
|
9
|
+
import { TableHeader } from './internal/table-header';
|
|
10
|
+
import { keyboardFocusableAttrName } from './table-primitives';
|
|
11
|
+
import { isWithinNavigableElement } from '../global/is-within-navigable-element';
|
|
12
|
+
import { ReorderLayoutContext, useReorderLayoutContextValue } from './internal/reorder-layout-context';
|
|
13
|
+
import styles from './table.css';
|
|
14
|
+
/**
|
|
15
|
+
* Table component replacing the tables in the `legacy-table` folder.
|
|
16
|
+
*
|
|
17
|
+
* This documentation provides an overview of the most common usage patterns.
|
|
18
|
+
* See individual props and exported components for detailed behavior.
|
|
19
|
+
*
|
|
20
|
+
* ## Minimal usage
|
|
21
|
+
*
|
|
22
|
+
* You need the following props:
|
|
23
|
+
* - `data`
|
|
24
|
+
* - `getKey`
|
|
25
|
+
* - `columns`
|
|
26
|
+
* - `key`
|
|
27
|
+
* - `name` (optional but needed in most cases)
|
|
28
|
+
* - `renderCell` (optional but needed in most cases)
|
|
29
|
+
*
|
|
30
|
+
* ## Item rendering
|
|
31
|
+
*
|
|
32
|
+
* If `renderItem` is not specified, each item is rendered using
|
|
33
|
+
* `DefaultItemRenderer` (from `table/default-item-renderer`)
|
|
34
|
+
* as if the following code were used:
|
|
35
|
+
*
|
|
36
|
+
* ```tsx
|
|
37
|
+
* <Table
|
|
38
|
+
* renderItem={(_item, index, _items) => (
|
|
39
|
+
* <DefaultItemRenderer index={index} />
|
|
40
|
+
* )}
|
|
41
|
+
* />
|
|
42
|
+
* ```
|
|
43
|
+
*
|
|
44
|
+
* `DefaultItemRenderer` renders a table row using the column definitions
|
|
45
|
+
* (`Column.renderCell`) and provides built-in support for features such as
|
|
46
|
+
* selection, keyboard navigation, and virtualization. It also accepts all
|
|
47
|
+
* standard `tr` attributes, including `ref`.
|
|
48
|
+
*
|
|
49
|
+
* Use `renderItem` to configure `DefaultItemRenderer` for each item:
|
|
50
|
+
*
|
|
51
|
+
* ```tsx
|
|
52
|
+
* <Table
|
|
53
|
+
* renderItem={(item, index, items) => (
|
|
54
|
+
* <DefaultItemRenderer
|
|
55
|
+
* index={index}
|
|
56
|
+
* keyboardFocusable
|
|
57
|
+
* className='my-item'
|
|
58
|
+
* onClick={e => handleClick(e, item, items)}
|
|
59
|
+
* />
|
|
60
|
+
* )}
|
|
61
|
+
* />
|
|
62
|
+
* ```
|
|
63
|
+
*
|
|
64
|
+
* If you need complete control over rendering, `renderItem` can instead
|
|
65
|
+
* return your own table rows. See "Custom item rendering" below.
|
|
66
|
+
*
|
|
67
|
+
* ## Selection
|
|
68
|
+
*
|
|
69
|
+
* Selection is typically implemented using the following props
|
|
70
|
+
* of the `DefaultItemRenderer`:
|
|
71
|
+
*
|
|
72
|
+
* - `clickable`
|
|
73
|
+
* - `selected`
|
|
74
|
+
* - `onClick` or `onPointerUp`, etc.
|
|
75
|
+
*
|
|
76
|
+
* The following utilities (from `global`) may come in handy:
|
|
77
|
+
*
|
|
78
|
+
* - `TableSelection` class to manage selection state
|
|
79
|
+
* - An alternative approach is to keep a `selected` field on each item
|
|
80
|
+
* - `isWithinInteractiveElement()` to check if a click was made on a control
|
|
81
|
+
* or on "empty space"
|
|
82
|
+
*
|
|
83
|
+
* ```tsx
|
|
84
|
+
* <Table
|
|
85
|
+
* renderItem={(item, index) => (
|
|
86
|
+
* <DefaultItemRenderer
|
|
87
|
+
* index={index}
|
|
88
|
+
* clickable
|
|
89
|
+
* selected={selection.isSelected(item)}
|
|
90
|
+
* onClick={e => {
|
|
91
|
+
* if (!isWithinInteractiveElement(e)) {
|
|
92
|
+
* setSelection(selection.toggleSelection(item));
|
|
93
|
+
* }
|
|
94
|
+
* }}
|
|
95
|
+
* />
|
|
96
|
+
* )}
|
|
97
|
+
* />
|
|
98
|
+
* ```
|
|
99
|
+
*
|
|
100
|
+
* Note that for accessibility reasons, you should have a cell with a checkbox
|
|
101
|
+
* to display and toggle item selection.
|
|
102
|
+
*
|
|
103
|
+
* ## Row focus
|
|
104
|
+
*
|
|
105
|
+
* The table implements the ["roving tabindex"](https://developer.mozilla.org/en-US/docs/Web/Accessibility/Guides/Keyboard-navigable_JavaScript_widgets#technique_1_roving_tabindex)
|
|
106
|
+
* technique to focus rows with the up/down arrow keys.
|
|
107
|
+
* Rows can also be focused on click or other pointer events.
|
|
108
|
+
* To support it, use the following props of the `DefaultItemRenderer`:
|
|
109
|
+
*
|
|
110
|
+
* - `keyboardFocusable`
|
|
111
|
+
* - `clickable`, if you want to react to hover
|
|
112
|
+
* - `onClick`, if you want to focus on click
|
|
113
|
+
*
|
|
114
|
+
* Useful utils:
|
|
115
|
+
* - `focusWithTemporaryTabIndex()` from `global` to focus a row temporarily
|
|
116
|
+
* patching its `tabindex`.
|
|
117
|
+
*
|
|
118
|
+
* ```tsx
|
|
119
|
+
* <Table
|
|
120
|
+
* renderItem={(item, index) => (
|
|
121
|
+
* <DefaultItemRenderer
|
|
122
|
+
* index={index}
|
|
123
|
+
* clickable
|
|
124
|
+
* keyboardFocusable
|
|
125
|
+
* onClick={e => {
|
|
126
|
+
* if (!isWithinInteractiveElement(e)) {
|
|
127
|
+
* focusWithTemporaryTabIndex(e.currentTarget);
|
|
128
|
+
* }
|
|
129
|
+
* }}
|
|
130
|
+
* />
|
|
131
|
+
* )}
|
|
132
|
+
* />
|
|
133
|
+
* ```
|
|
134
|
+
*
|
|
135
|
+
* Note that the table does not implement standard accessibility patterns such
|
|
136
|
+
* as `grid` or `treegrid`, so row focus is not announced by screen readers.
|
|
137
|
+
* Make sure all essential actions remain available without row focus, for
|
|
138
|
+
* example via standard Tab navigation.
|
|
139
|
+
*
|
|
140
|
+
* ## Sorting
|
|
141
|
+
*
|
|
142
|
+
* You need the following to support sorting:
|
|
143
|
+
*
|
|
144
|
+
* - Set `Column.sortOrder` to `'none'`, `'ascending'` or `'descending'`
|
|
145
|
+
* to render the sort button, `aria-sort`, and indicate the current
|
|
146
|
+
* sort order.
|
|
147
|
+
* - Handle `TableProps.onSort` callback in the client code.
|
|
148
|
+
*
|
|
149
|
+
* ## Deleting columns
|
|
150
|
+
*
|
|
151
|
+
* You need the following to support deleting columns:
|
|
152
|
+
*
|
|
153
|
+
* - Set `Column.deletable` to `true`. This will render a delete button in the
|
|
154
|
+
* column header.
|
|
155
|
+
* - Make sure the `column` has a proper `name` or `key` prop, which will be
|
|
156
|
+
* automatically included in the aria-label of the column delete button.
|
|
157
|
+
* - Handle `TableProps.onColumnDelete` callback in the client code. It is
|
|
158
|
+
* expected to update `columns` by removing the corresponding column.
|
|
159
|
+
*
|
|
160
|
+
* ## Moving columns
|
|
161
|
+
*
|
|
162
|
+
* - Set `Column.canReorder` to `true` or to predicate specifying possible
|
|
163
|
+
* insertion targets.
|
|
164
|
+
* This will render a reorder button in the column header.
|
|
165
|
+
* - Make sure the `column` has a proper `name` or `key` prop, which will be
|
|
166
|
+
* automatically included in the aria-label of the column reorder button.
|
|
167
|
+
* - Handle `TableProps.onColumnReorder` callback in the client code. It is
|
|
168
|
+
* expected to update `columns` by moving the corresponding column to the
|
|
169
|
+
* new position.
|
|
170
|
+
*
|
|
171
|
+
* ## Item reorder
|
|
172
|
+
*
|
|
173
|
+
* To allow the user to reorder rows by dragging:
|
|
174
|
+
*
|
|
175
|
+
* - Place `ItemReorderHandle` (from `table/table-primitives`) anywhere inside
|
|
176
|
+
* a cell. It renders a drag icon button the user can grab to reorder the row.
|
|
177
|
+
* - Handle `TableProps.onItemReorder`. It is expected to update `data` by
|
|
178
|
+
* moving the item to the new position.
|
|
179
|
+
* - Optionally, set `TableProps.canReorderItem` to restrict which positions
|
|
180
|
+
* an item may be dropped into.
|
|
181
|
+
*
|
|
182
|
+
* By default, dragging shows a drag frame (a border around the dragged row)
|
|
183
|
+
* and an insertion indicator (a line between rows showing where the item will
|
|
184
|
+
* land). To implement fully custom drag visuals, set `noDragFrame` and
|
|
185
|
+
* `noHandleTranslate` on `ItemReorderHandle` and use its `onUserDrag` callback
|
|
186
|
+
* to track the drag lifecycle.
|
|
187
|
+
*
|
|
188
|
+
* ## Row virtualization
|
|
189
|
+
*
|
|
190
|
+
* To render only rows near the viewport while replacing off-screen rows with
|
|
191
|
+
* spacers, use:
|
|
192
|
+
*
|
|
193
|
+
* - `virtualizeRows` prop set to `true`
|
|
194
|
+
* - `scrollerRef` — required when the scrollable container is not the whole
|
|
195
|
+
* document
|
|
196
|
+
* - `estimateHeight` — recommended when rows are expected to be taller than
|
|
197
|
+
* the default height (e.g. multiline or custom content)
|
|
198
|
+
* - Fine-tuning props: `lookaheadPx`, `retentionMarginPx`,
|
|
199
|
+
* `minScrollAndResizeDeltaPx`
|
|
200
|
+
*
|
|
201
|
+
* ## Custom item rendering
|
|
202
|
+
*
|
|
203
|
+
* Use the `renderItem` prop to render an item in a completely custom way.
|
|
204
|
+
* The prop is expected to return one or more table rows for the item.
|
|
205
|
+
* Use `TableRow` and `TableCell` from `table/table-primitives` to apply
|
|
206
|
+
* the default row and cell styles.
|
|
207
|
+
*
|
|
208
|
+
* ### Focus
|
|
209
|
+
*
|
|
210
|
+
* Just like `DefaultItemRenderer`, `TableRow` accepts the
|
|
211
|
+
* `keyboardFocusable` prop.
|
|
212
|
+
*
|
|
213
|
+
* Focusable rows rendered by either component form a single keyboard
|
|
214
|
+
* navigation sequence.
|
|
215
|
+
*
|
|
216
|
+
* ### Virtualization
|
|
217
|
+
*
|
|
218
|
+
* If `Table.virtualizeRows` is set to `true`, you need to handle visibility
|
|
219
|
+
* for your custom-rendered component yourself with the
|
|
220
|
+
* `useItemVirtualization()` hook (from `table/item-virtualization`). The hook
|
|
221
|
+
* allows observing the intersection of one or multiple elements rendered for
|
|
222
|
+
* the item, and, based on their intersection status, reporting the item as
|
|
223
|
+
* eligible for virtualization.
|
|
224
|
+
*
|
|
225
|
+
* If you use `DefaultItemRenderer` as part of your custom row renderer,
|
|
226
|
+
* set the `noItemVirtualization` prop to `true`, otherwise it will also try
|
|
227
|
+
* to control the virtualization, possibly reporting incorrect item height.
|
|
228
|
+
*
|
|
229
|
+
* ### Item reorder
|
|
230
|
+
*
|
|
231
|
+
* If `TableProps.onItemReorder` is set and your item spans multiple rows, call
|
|
232
|
+
* `useReorderItemLayout()` (from `table/reorder-item-layout`) to register the
|
|
233
|
+
* item's boundaries so the insertion indicator and insertion point calculation
|
|
234
|
+
* are correct. If `DefaultItemRenderer` is included inside your custom renderer,
|
|
235
|
+
* set its `noReorderLayout` prop to `true` to prevent double registration.
|
|
236
|
+
*
|
|
237
|
+
* ### Reorder animation
|
|
238
|
+
*
|
|
239
|
+
* After a column or item is reordered, the table briefly highlights the moved
|
|
240
|
+
* element. To apply the same animation in your custom-rendered rows, use
|
|
241
|
+
* `useReorderAnimation()` (from `table/reorder-animation`) to get information
|
|
242
|
+
* about the currently animated column or item.
|
|
243
|
+
*/
|
|
244
|
+
export default function Table(props) {
|
|
245
|
+
const { data, columns, getKey, noHeader, stickyHeader, onSort, onColumnDelete, onColumnReorder, noColumnReorderAnimation, canReorderItem, onItemReorder, noItemReorderAnimation, renderItem, virtualizeRows = false, scrollerRef, estimateHeight = () => defaultRowHeight,
|
|
246
|
+
// eslint-disable-next-line no-magic-numbers
|
|
247
|
+
lookaheadPx = 400,
|
|
248
|
+
// eslint-disable-next-line no-magic-numbers
|
|
249
|
+
retentionMarginPx = 450,
|
|
250
|
+
// eslint-disable-next-line no-magic-numbers
|
|
251
|
+
minScrollAndResizeDeltaPx = 50, columnEditing, onColumnEditingRequest, columnEditButton, theadClassName, theadTrClassName, tbodyClassName, ref: userRef, className, ...restProps } = props;
|
|
252
|
+
const localRef = useRef(null);
|
|
253
|
+
const reorderAnimationContextValue = useReorderAnimationContextValue({
|
|
254
|
+
noColumnReorderAnimation,
|
|
255
|
+
noItemReorderAnimation,
|
|
256
|
+
tableRef: localRef,
|
|
257
|
+
data,
|
|
258
|
+
columns,
|
|
259
|
+
});
|
|
260
|
+
function handleRowNavigation(e) {
|
|
261
|
+
if (e.defaultPrevented || isWithinNavigableElement(e.target))
|
|
262
|
+
return;
|
|
263
|
+
const arrowUp = e.key === 'ArrowUp';
|
|
264
|
+
const arrowDown = e.key === 'ArrowDown';
|
|
265
|
+
if (!arrowUp && !arrowDown)
|
|
266
|
+
return;
|
|
267
|
+
const currentRow = e.target.closest('tr');
|
|
268
|
+
if (currentRow?.parentElement?.parentElement !== localRef.current) {
|
|
269
|
+
return;
|
|
270
|
+
}
|
|
271
|
+
let candidate = currentRow;
|
|
272
|
+
while (candidate) {
|
|
273
|
+
candidate = (arrowUp ? candidate.previousElementSibling : candidate.nextElementSibling);
|
|
274
|
+
if (candidate?.hasAttribute(keyboardFocusableAttrName)) {
|
|
275
|
+
focusWithTemporaryTabIndex(candidate);
|
|
276
|
+
e.preventDefault();
|
|
277
|
+
return;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
const { virtualItems, virtualizationContextValue } = useVirtualItems({
|
|
282
|
+
enabled: virtualizeRows,
|
|
283
|
+
data,
|
|
284
|
+
scrollerRef,
|
|
285
|
+
tableRef: localRef,
|
|
286
|
+
estimateHeight,
|
|
287
|
+
lookaheadPx,
|
|
288
|
+
retentionMarginPx,
|
|
289
|
+
minScrollAndResizeDeltaPx,
|
|
290
|
+
});
|
|
291
|
+
const itemReorderLayoutContextValue = useReorderLayoutContextValue();
|
|
292
|
+
return (<TablePropsContext value={props}>
|
|
293
|
+
<ReorderAnimationContext value={reorderAnimationContextValue}>
|
|
294
|
+
<table className={classNames(styles.table, className)} ref={useComposedRef(userRef, localRef)} {...restProps}>
|
|
295
|
+
<TableHeader />
|
|
296
|
+
{/* eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions */}
|
|
297
|
+
<tbody className={tbodyClassName} onKeyDown={handleRowNavigation}>
|
|
298
|
+
<VirtualizationContext value={virtualizationContextValue}>
|
|
299
|
+
<ReorderLayoutContext value={itemReorderLayoutContextValue}>
|
|
300
|
+
{(virtualizeRows ? virtualItems : data).map((item, index) => {
|
|
301
|
+
let dataItem;
|
|
302
|
+
let dataItemIndex;
|
|
303
|
+
if (virtualizeRows) {
|
|
304
|
+
const virtualItem = item;
|
|
305
|
+
if (virtualItem.type === 'spacer') {
|
|
306
|
+
return <SpacerRow key={virtualItem.key} spacer={virtualItem} colSpan={columns.length}/>;
|
|
307
|
+
}
|
|
308
|
+
dataItemIndex = virtualItem.index;
|
|
309
|
+
if (dataItemIndex < 0 || dataItemIndex >= data.length)
|
|
310
|
+
return null;
|
|
311
|
+
dataItem = data[dataItemIndex];
|
|
312
|
+
}
|
|
313
|
+
else {
|
|
314
|
+
dataItem = item;
|
|
315
|
+
dataItemIndex = index;
|
|
316
|
+
}
|
|
317
|
+
return (<Fragment key={getKey(dataItem, dataItemIndex, data)}>
|
|
318
|
+
{renderItem ? (renderItem(dataItem, dataItemIndex, data)) : (<DefaultItemRenderer index={dataItemIndex}/>)}
|
|
319
|
+
</Fragment>);
|
|
320
|
+
})}
|
|
321
|
+
</ReorderLayoutContext>
|
|
322
|
+
</VirtualizationContext>
|
|
323
|
+
</tbody>
|
|
324
|
+
</table>
|
|
325
|
+
</ReorderAnimationContext>
|
|
326
|
+
</TablePropsContext>);
|
|
327
|
+
}
|
|
@@ -10,6 +10,6 @@ export default class SmartUserCardTooltip extends Component<SmartUserCardTooltip
|
|
|
10
10
|
loading: boolean;
|
|
11
11
|
};
|
|
12
12
|
loadUser: () => Promise<void>;
|
|
13
|
-
renderNoUser: () =>
|
|
13
|
+
renderNoUser: () => import("react").JSX.Element | "";
|
|
14
14
|
render(): import("react").JSX.Element;
|
|
15
15
|
}
|
|
@@ -1 +1,27 @@
|
|
|
1
1
|
export declare const hideAddonsPanelParam = "hideAddonsPanel";
|
|
2
|
+
export declare function createRandom(seed: bigint): {
|
|
3
|
+
/**
|
|
4
|
+
* Fractional in [0, 1)
|
|
5
|
+
*/
|
|
6
|
+
(): number;
|
|
7
|
+
/**
|
|
8
|
+
* Integer in [0, to)
|
|
9
|
+
*/
|
|
10
|
+
(to: number): number;
|
|
11
|
+
/**
|
|
12
|
+
* Integer in [from, to)
|
|
13
|
+
*/
|
|
14
|
+
(from: number, to: number): number;
|
|
15
|
+
/**
|
|
16
|
+
* Date in [from, to)
|
|
17
|
+
*/
|
|
18
|
+
(from: Date, to: Date): Date;
|
|
19
|
+
/**
|
|
20
|
+
* Up to random n items (in random order) from the array
|
|
21
|
+
*/
|
|
22
|
+
<T>(array: readonly T[], n: number): T[];
|
|
23
|
+
/**
|
|
24
|
+
* Random item from the array
|
|
25
|
+
*/
|
|
26
|
+
<T>(array: readonly T[]): T;
|
|
27
|
+
};
|
|
@@ -1 +1,62 @@
|
|
|
1
|
+
/* eslint-disable no-magic-numbers */
|
|
1
2
|
export const hideAddonsPanelParam = 'hideAddonsPanel';
|
|
3
|
+
export function createRandom(seed) {
|
|
4
|
+
const u64Mask = 2n ** 64n - 1n;
|
|
5
|
+
const u64Range = 2n ** 64n;
|
|
6
|
+
const scrambleConst = 2685821657736338717n;
|
|
7
|
+
let x = seed & u64Mask;
|
|
8
|
+
if (!x)
|
|
9
|
+
throw new Error('Seed must be non-zero');
|
|
10
|
+
function nextFractional() {
|
|
11
|
+
x ^= x >> 12n;
|
|
12
|
+
x ^= (x << 25n) & u64Mask;
|
|
13
|
+
x ^= x >> 27n;
|
|
14
|
+
const scrambled = (x * scrambleConst) & u64Mask;
|
|
15
|
+
return Number(scrambled) / Number(u64Range);
|
|
16
|
+
}
|
|
17
|
+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
18
|
+
return (...args) => {
|
|
19
|
+
if (!args.length) {
|
|
20
|
+
return nextFractional();
|
|
21
|
+
}
|
|
22
|
+
if (args.length === 1) {
|
|
23
|
+
const [a] = args;
|
|
24
|
+
if (typeof a === 'number') {
|
|
25
|
+
return Math.floor(nextFractional() * a);
|
|
26
|
+
}
|
|
27
|
+
if (Array.isArray(a)) {
|
|
28
|
+
return a[Math.floor(nextFractional() * a.length)];
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (args.length === 2) {
|
|
32
|
+
const [a, b] = args;
|
|
33
|
+
let fromNum;
|
|
34
|
+
let toNum;
|
|
35
|
+
let isDate = false;
|
|
36
|
+
if (typeof a === 'number' && typeof b === 'number') {
|
|
37
|
+
fromNum = a;
|
|
38
|
+
toNum = b;
|
|
39
|
+
}
|
|
40
|
+
if (a instanceof Date && b instanceof Date) {
|
|
41
|
+
fromNum = a.getTime();
|
|
42
|
+
toNum = b.getTime();
|
|
43
|
+
isDate = true;
|
|
44
|
+
}
|
|
45
|
+
if (fromNum != null && toNum != null && fromNum < toNum) {
|
|
46
|
+
const r = Math.floor(nextFractional() * (toNum - fromNum)) + fromNum;
|
|
47
|
+
return isDate ? new Date(r) : r;
|
|
48
|
+
}
|
|
49
|
+
if (Array.isArray(a) && typeof b === 'number') {
|
|
50
|
+
const aIndices = Array.from({ length: a.length }, (_, i) => i);
|
|
51
|
+
const sample = [];
|
|
52
|
+
for (let i = 0; i < b && aIndices.length; i++) {
|
|
53
|
+
const indexIndex = Math.floor(nextFractional() * aIndices.length);
|
|
54
|
+
const [aIndex] = aIndices.splice(indexIndex, 1);
|
|
55
|
+
sample.push(a[aIndex]);
|
|
56
|
+
}
|
|
57
|
+
return sample;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
throw new Error(`Bad args: ${JSON.stringify(args)}`);
|
|
61
|
+
};
|
|
62
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jetbrains/ring-ui",
|
|
3
|
-
"version": "8.0.0-beta.
|
|
3
|
+
"version": "8.0.0-beta.5",
|
|
4
4
|
"description": "JetBrains UI library",
|
|
5
5
|
"author": {
|
|
6
6
|
"name": "JetBrains"
|
|
@@ -99,29 +99,29 @@
|
|
|
99
99
|
},
|
|
100
100
|
"readmeFilename": "README.md",
|
|
101
101
|
"devDependencies": {
|
|
102
|
-
"@babel/cli": "^
|
|
102
|
+
"@babel/cli": "^8.0.1",
|
|
103
103
|
"@babel/eslint-parser": "^7.29.7",
|
|
104
104
|
"@csstools/css-parser-algorithms": "^4.0.0",
|
|
105
105
|
"@csstools/stylelint-no-at-nest-rule": "^5.0.0",
|
|
106
106
|
"@eslint/compat": "^2.1.0",
|
|
107
107
|
"@eslint/eslintrc": "^3.3.5",
|
|
108
108
|
"@eslint/js": "^10.0.1",
|
|
109
|
-
"@figma/code-connect": "^1.4.
|
|
109
|
+
"@figma/code-connect": "^1.4.8",
|
|
110
110
|
"@jetbrains/eslint-config": "^6.0.5",
|
|
111
111
|
"@jetbrains/logos": "3.0.0-canary.734b213.0",
|
|
112
112
|
"@jetbrains/rollup-css-plugin": "./packages/rollup-css-plugin",
|
|
113
113
|
"@jetbrains/stylelint-config": "^4.0.2",
|
|
114
114
|
"@jetbrains/typescript-plugin-css-modules": "^5.3.1",
|
|
115
|
-
"@primer/octicons": "^19.28.
|
|
115
|
+
"@primer/octicons": "^19.28.1",
|
|
116
116
|
"@rollup/plugin-babel": "^7.1.0",
|
|
117
117
|
"@rollup/plugin-json": "^6.1.0",
|
|
118
118
|
"@rollup/plugin-node-resolve": "^16.0.3",
|
|
119
119
|
"@rollup/plugin-replace": "^6.0.3",
|
|
120
|
-
"@storybook/addon-a11y": "10.4.
|
|
121
|
-
"@storybook/addon-docs": "^10.4.
|
|
122
|
-
"@storybook/addon-themes": "^10.4.
|
|
120
|
+
"@storybook/addon-a11y": "10.4.6",
|
|
121
|
+
"@storybook/addon-docs": "^10.4.6",
|
|
122
|
+
"@storybook/addon-themes": "^10.4.6",
|
|
123
123
|
"@storybook/csf": "^0.1.13",
|
|
124
|
-
"@storybook/react-webpack5": "10.4.
|
|
124
|
+
"@storybook/react-webpack5": "10.4.6",
|
|
125
125
|
"@storybook/test-runner": "^0.24.4",
|
|
126
126
|
"@testing-library/dom": "^10.4.1",
|
|
127
127
|
"@testing-library/react": "^16.3.2",
|
|
@@ -129,36 +129,36 @@
|
|
|
129
129
|
"@types/chai-as-promised": "^8.0.2",
|
|
130
130
|
"@types/chai-dom": "1.11.3",
|
|
131
131
|
"@types/markdown-it": "^14.1.2",
|
|
132
|
-
"@types/react": "^19.2.
|
|
132
|
+
"@types/react": "^19.2.17",
|
|
133
133
|
"@types/react-dom": "^19.2.3",
|
|
134
134
|
"@types/webpack-env": "^1.18.8",
|
|
135
|
-
"@vitejs/plugin-react": "^6.0.
|
|
136
|
-
"@vitest/eslint-plugin": "^1.6.
|
|
137
|
-
"acorn": "^8.
|
|
135
|
+
"@vitejs/plugin-react": "^6.0.3",
|
|
136
|
+
"@vitest/eslint-plugin": "^1.6.20",
|
|
137
|
+
"acorn": "^8.17.0",
|
|
138
138
|
"babel-plugin-require-context-hook": "^1.0.0",
|
|
139
|
-
"caniuse-lite": "^1.0.
|
|
139
|
+
"caniuse-lite": "^1.0.30001799",
|
|
140
140
|
"chai-as-promised": "^8.0.2",
|
|
141
141
|
"chai-dom": "^1.12.1",
|
|
142
142
|
"cheerio": "^1.2.0",
|
|
143
143
|
"core-js": "^3.49.0",
|
|
144
144
|
"cpy-cli": "^7.0.0",
|
|
145
145
|
"dotenv-cli": "^11.0.0",
|
|
146
|
-
"eslint": "^9.39.
|
|
146
|
+
"eslint": "^9.39.4",
|
|
147
147
|
"eslint-config-prettier": "^10.1.8",
|
|
148
148
|
"eslint-formatter-jslint-xml": "^9.0.1",
|
|
149
149
|
"eslint-import-resolver-exports": "^1.0.0-beta.5",
|
|
150
|
-
"eslint-import-resolver-typescript": "^4.4.
|
|
150
|
+
"eslint-import-resolver-typescript": "^4.4.5",
|
|
151
151
|
"eslint-import-resolver-webpack": "^0.13.11",
|
|
152
152
|
"eslint-plugin-import": "^2.32.0",
|
|
153
153
|
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
154
154
|
"eslint-plugin-prettier": "^5.5.6",
|
|
155
155
|
"eslint-plugin-react": "^7.37.5",
|
|
156
156
|
"eslint-plugin-react-hooks": "^7.1.1",
|
|
157
|
-
"eslint-plugin-storybook": "^10.4.
|
|
158
|
-
"eslint-plugin-unicorn": "^
|
|
157
|
+
"eslint-plugin-storybook": "^10.4.6",
|
|
158
|
+
"eslint-plugin-unicorn": "^70.0.0",
|
|
159
159
|
"events": "^3.3.0",
|
|
160
160
|
"glob": "^13.0.6",
|
|
161
|
-
"globals": "^17.
|
|
161
|
+
"globals": "^17.7.0",
|
|
162
162
|
"html-webpack-plugin": "^5.6.7",
|
|
163
163
|
"http-server": "^14.1.1",
|
|
164
164
|
"husky": "^9.1.7",
|
|
@@ -166,33 +166,33 @@
|
|
|
166
166
|
"jest": "~30.4.2",
|
|
167
167
|
"jest-environment-jsdom": "^30.4.1",
|
|
168
168
|
"jest-teamcity": "^1.12.0",
|
|
169
|
-
"lint-staged": "^17.0.
|
|
169
|
+
"lint-staged": "^17.0.8",
|
|
170
170
|
"markdown-it": "^14.2.0",
|
|
171
171
|
"merge-options": "^3.0.4",
|
|
172
172
|
"pinst": "^3.0.0",
|
|
173
|
-
"prettier": "^3.
|
|
173
|
+
"prettier": "^3.9.4",
|
|
174
174
|
"raw-loader": "^4.0.2",
|
|
175
|
-
"react": "^19.2.
|
|
176
|
-
"react-dom": "^19.2.
|
|
175
|
+
"react": "^19.2.7",
|
|
176
|
+
"react-dom": "^19.2.7",
|
|
177
177
|
"regenerator-runtime": "^0.14.1",
|
|
178
178
|
"rimraf": "^6.1.3",
|
|
179
|
-
"rollup": "^4.
|
|
179
|
+
"rollup": "^4.62.2",
|
|
180
180
|
"rollup-plugin-clear": "^2.0.7",
|
|
181
181
|
"storage-mock": "^2.1.0",
|
|
182
|
-
"storybook": "10.4.
|
|
183
|
-
"stylelint": "^17.
|
|
182
|
+
"storybook": "10.4.6",
|
|
183
|
+
"stylelint": "^17.14.0",
|
|
184
184
|
"stylelint-config-sass-guidelines": "^13.0.0",
|
|
185
185
|
"svg-inline-loader": "^0.8.2",
|
|
186
186
|
"teamcity-service-messages": "^0.1.14",
|
|
187
187
|
"terser-webpack-plugin": "^5.6.1",
|
|
188
188
|
"typed-css-modules": "^0.9.1",
|
|
189
189
|
"typescript": "~6.0.3",
|
|
190
|
-
"typescript-eslint": "^8.
|
|
191
|
-
"vite": "^8.0
|
|
192
|
-
"vitest": "^4.1.
|
|
190
|
+
"typescript-eslint": "^8.62.1",
|
|
191
|
+
"vite": "^8.1.0",
|
|
192
|
+
"vitest": "^4.1.9",
|
|
193
193
|
"vitest-teamcity-reporter": "^0.4.1",
|
|
194
|
-
"webpack": "^5.
|
|
195
|
-
"webpack-cli": "^7.0
|
|
194
|
+
"webpack": "^5.108.1",
|
|
195
|
+
"webpack-cli": "^7.1.0",
|
|
196
196
|
"xmlappend": "^1.0.4"
|
|
197
197
|
},
|
|
198
198
|
"peerDependencies": {
|
|
@@ -216,9 +216,9 @@
|
|
|
216
216
|
},
|
|
217
217
|
"dependencies": {
|
|
218
218
|
"@babel/core": "^7.29.7",
|
|
219
|
-
"@babel/preset-typescript": "^
|
|
219
|
+
"@babel/preset-typescript": "^8.0.1",
|
|
220
220
|
"@jetbrains/babel-preset-jetbrains": "^2.4.0",
|
|
221
|
-
"@jetbrains/icons": "^5.
|
|
221
|
+
"@jetbrains/icons": "^5.23.0",
|
|
222
222
|
"@jetbrains/postcss-require-hover": "^0.2.0",
|
|
223
223
|
"@types/combokeys": "^2.4.9",
|
|
224
224
|
"@types/element-resize-detector": "^1.1.6",
|
|
@@ -227,7 +227,7 @@
|
|
|
227
227
|
"babel-loader": "10.1.1",
|
|
228
228
|
"babel-plugin-react-compiler": "^1.0.0",
|
|
229
229
|
"babel-plugin-transform-define": "^2.1.4",
|
|
230
|
-
"browserslist": "^4.28.
|
|
230
|
+
"browserslist": "^4.28.4",
|
|
231
231
|
"change-case": "^4.1.1",
|
|
232
232
|
"classnames": "^2.5.1",
|
|
233
233
|
"combokeys": "^3.0.1",
|
|
@@ -238,7 +238,7 @@
|
|
|
238
238
|
"element-resize-detector": "^1.2.4",
|
|
239
239
|
"fastdom": "^1.0.12",
|
|
240
240
|
"file-loader": "^6.2.0",
|
|
241
|
-
"focus-trap": "^8.2.
|
|
241
|
+
"focus-trap": "^8.2.2",
|
|
242
242
|
"highlight.js": "^10.7.2",
|
|
243
243
|
"just-debounce-it": "^3.2.0",
|
|
244
244
|
"memoize-one": "^6.0.0",
|
|
@@ -247,9 +247,8 @@
|
|
|
247
247
|
"postcss-font-family-system-ui": "^5.0.0",
|
|
248
248
|
"postcss-loader": "^8.2.1",
|
|
249
249
|
"postcss-modules-values-replace": "^4.2.2",
|
|
250
|
-
"postcss-preset-env": "^11.3.
|
|
250
|
+
"postcss-preset-env": "^11.3.1",
|
|
251
251
|
"react-compiler-runtime": "^1.0.0",
|
|
252
|
-
"react-merge-refs": "^3.0.2",
|
|
253
252
|
"react-movable": "^3.4.1",
|
|
254
253
|
"react-virtualized": "^9.22.6",
|
|
255
254
|
"react-waypoint": "^10.3.0",
|
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
import { type RefObject } from 'react';
|
|
2
|
-
export declare function useIntersectionObserver(containerRef: RefObject<HTMLElement | null>, scrollMargin?: number): IntersectionObserverHandle | null;
|
|
3
|
-
export interface IntersectionObserverHandle {
|
|
4
|
-
observeVisibility(element: Element, setVisible: (isVisible: boolean) => void): () => void;
|
|
5
|
-
}
|
|
6
|
-
export declare function useVisibility(handle: IntersectionObserverHandle | null, elementRef: RefObject<Element | null>): boolean;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import { useEffect, useState } from 'react';
|
|
2
|
-
export function useIntersectionObserver(containerRef, scrollMargin = 0) {
|
|
3
|
-
const [handle, setHandle] = useState(null);
|
|
4
|
-
useEffect(() => {
|
|
5
|
-
const container = containerRef.current;
|
|
6
|
-
if (!container)
|
|
7
|
-
return;
|
|
8
|
-
const elementToSetVisible = new Map();
|
|
9
|
-
const observer = new IntersectionObserver(entries => {
|
|
10
|
-
for (const entry of entries) {
|
|
11
|
-
const setVisible = elementToSetVisible.get(entry.target);
|
|
12
|
-
setVisible?.(entry.isIntersecting);
|
|
13
|
-
}
|
|
14
|
-
}, {
|
|
15
|
-
root: container,
|
|
16
|
-
...(scrollMargin
|
|
17
|
-
? {
|
|
18
|
-
scrollMargin: `${scrollMargin}px`,
|
|
19
|
-
}
|
|
20
|
-
: {}),
|
|
21
|
-
});
|
|
22
|
-
setHandle({
|
|
23
|
-
observeVisibility(element, setVisible) {
|
|
24
|
-
elementToSetVisible.set(element, setVisible);
|
|
25
|
-
observer.observe(element);
|
|
26
|
-
return () => {
|
|
27
|
-
elementToSetVisible.delete(element);
|
|
28
|
-
observer.unobserve(element);
|
|
29
|
-
};
|
|
30
|
-
},
|
|
31
|
-
});
|
|
32
|
-
return () => {
|
|
33
|
-
observer.disconnect();
|
|
34
|
-
setHandle(null);
|
|
35
|
-
};
|
|
36
|
-
}, [containerRef, scrollMargin]);
|
|
37
|
-
return handle;
|
|
38
|
-
}
|
|
39
|
-
export function useVisibility(handle, elementRef) {
|
|
40
|
-
const [isVisible, setIsVisible] = useState(false);
|
|
41
|
-
useEffect(() => {
|
|
42
|
-
const element = elementRef.current;
|
|
43
|
-
if (!element || !handle)
|
|
44
|
-
return;
|
|
45
|
-
return handle.observeVisibility(element, setIsVisible);
|
|
46
|
-
}, [handle, elementRef, setIsVisible]);
|
|
47
|
-
return isVisible;
|
|
48
|
-
}
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
/* eslint-disable unicorn/filename-case */
|
|
2
|
-
import { createComposedRef as _createComposedRef } from './compose-refs';
|
|
3
|
-
/**
|
|
4
|
-
* @deprecated Use createComposedRef from './compose-refs' instead
|
|
5
|
-
*/
|
|
6
|
-
const createComposedRef = _createComposedRef;
|
|
7
|
-
export { createComposedRef };
|