@primer/react 0.0.0-20260219212149 → 0.0.0-20260219220306
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/CHANGELOG.md +3 -3
- package/dist/ActionList/Description.d.ts.map +1 -1
- package/dist/ActionList/Description.js +40 -76
- package/dist/ActionList/Item.d.ts.map +1 -1
- package/dist/ActionList/Item.js +63 -108
- package/dist/ActionList/shared.d.ts +0 -1
- package/dist/ActionList/shared.d.ts.map +1 -1
- package/dist/hooks/useSlots.d.ts +50 -6
- package/dist/hooks/useSlots.d.ts.map +1 -1
- package/dist/hooks/useSlots.js +114 -36
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260219220306
|
|
4
4
|
|
|
5
5
|
### Patch Changes
|
|
6
6
|
|
|
7
|
-
- [#7529](https://github.com/primer/react/pull/7529) [`7b11c23`](https://github.com/primer/react/commit/7b11c23088e9887608d28b8198f3370425f4cd8a) Thanks [@liuliu-dev](https://github.com/liuliu-dev)! - Add keyboard-accessible tooltip for truncated ActionList.Description
|
|
8
|
-
|
|
9
7
|
- Fake entry to force publishing
|
|
10
8
|
|
|
9
|
+
- [#7555](https://github.com/primer/react/pull/7555) [`91ac722`](https://github.com/primer/react/commit/91ac722ad4d2706d15d984aa5985aaf172911ce5) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(useSlots): short-circuit iteration and skip filled slots
|
|
10
|
+
|
|
11
11
|
## 38.13.0
|
|
12
12
|
|
|
13
13
|
### Minor Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Description.d.ts","sourceRoot":"","sources":["../../src/ActionList/Description.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAA;AAE1D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IAE5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,
|
|
1
|
+
{"version":3,"file":"Description.d.ts","sourceRoot":"","sources":["../../src/ActionList/Description.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,sBAAsB,CAAA;AAE1D,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;OAKG;IACH,OAAO,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IAE5B,SAAS,CAAC,EAAE,MAAM,CAAA;IAClB,KAAK,CAAC,EAAE,KAAK,CAAC,aAAa,CAAA;IAC3B;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,EAAE,gBAAgB,CAAC,KAAK,CAAC,iBAAiB,CAAC,0BAA0B,CAAC,CAgD7F,CAAA"}
|
|
@@ -7,7 +7,7 @@ import { jsx } from 'react/jsx-runtime';
|
|
|
7
7
|
import Truncate from '../Truncate/Truncate.js';
|
|
8
8
|
|
|
9
9
|
const Description = t0 => {
|
|
10
|
-
const $ = c(
|
|
10
|
+
const $ = c(26);
|
|
11
11
|
let className;
|
|
12
12
|
let props;
|
|
13
13
|
let style;
|
|
@@ -37,8 +37,7 @@ const Description = t0 => {
|
|
|
37
37
|
const variant = t1 === undefined ? "inline" : t1;
|
|
38
38
|
const {
|
|
39
39
|
blockDescriptionId,
|
|
40
|
-
inlineDescriptionId
|
|
41
|
-
setTruncatedText
|
|
40
|
+
inlineDescriptionId
|
|
42
41
|
} = React.useContext(ItemContext);
|
|
43
42
|
const containerRef = React.useRef(null);
|
|
44
43
|
const [computedTitle, setComputedTitle] = React.useState("");
|
|
@@ -66,101 +65,66 @@ const Description = t0 => {
|
|
|
66
65
|
}
|
|
67
66
|
React.useEffect(t2, t3);
|
|
68
67
|
const effectiveTitle = typeof props.children === "string" ? props.children : computedTitle;
|
|
69
|
-
let t4;
|
|
70
|
-
let t5;
|
|
71
|
-
if ($[11] !== effectiveTitle || $[12] !== setTruncatedText || $[13] !== truncate) {
|
|
72
|
-
t4 = () => {
|
|
73
|
-
if (!truncate || !containerRef.current || !setTruncatedText) {
|
|
74
|
-
return;
|
|
75
|
-
}
|
|
76
|
-
const isContentTruncated = function isContentTruncated() {
|
|
77
|
-
const el = containerRef.current;
|
|
78
|
-
if (!el) {
|
|
79
|
-
return false;
|
|
80
|
-
}
|
|
81
|
-
return el.scrollWidth > el.clientWidth;
|
|
82
|
-
};
|
|
83
|
-
setTruncatedText(isContentTruncated() ? effectiveTitle : undefined);
|
|
84
|
-
const observer = new ResizeObserver(() => {
|
|
85
|
-
setTruncatedText(isContentTruncated() ? effectiveTitle : undefined);
|
|
86
|
-
});
|
|
87
|
-
observer.observe(containerRef.current);
|
|
88
|
-
return () => {
|
|
89
|
-
observer.disconnect();
|
|
90
|
-
};
|
|
91
|
-
};
|
|
92
|
-
t5 = [truncate, effectiveTitle, setTruncatedText];
|
|
93
|
-
$[11] = effectiveTitle;
|
|
94
|
-
$[12] = setTruncatedText;
|
|
95
|
-
$[13] = truncate;
|
|
96
|
-
$[14] = t4;
|
|
97
|
-
$[15] = t5;
|
|
98
|
-
} else {
|
|
99
|
-
t4 = $[14];
|
|
100
|
-
t5 = $[15];
|
|
101
|
-
}
|
|
102
|
-
React.useEffect(t4, t5);
|
|
103
68
|
if (variant === "block" || !truncate) {
|
|
104
|
-
const
|
|
105
|
-
let
|
|
106
|
-
if ($[
|
|
107
|
-
|
|
108
|
-
$[
|
|
109
|
-
$[
|
|
69
|
+
const t4 = variant === "block" ? blockDescriptionId : inlineDescriptionId;
|
|
70
|
+
let t5;
|
|
71
|
+
if ($[11] !== className) {
|
|
72
|
+
t5 = clsx(className, classes.Description);
|
|
73
|
+
$[11] = className;
|
|
74
|
+
$[12] = t5;
|
|
110
75
|
} else {
|
|
111
|
-
|
|
76
|
+
t5 = $[12];
|
|
112
77
|
}
|
|
113
|
-
let
|
|
114
|
-
if ($[
|
|
115
|
-
|
|
116
|
-
id:
|
|
117
|
-
className:
|
|
78
|
+
let t6;
|
|
79
|
+
if ($[13] !== props.children || $[14] !== style || $[15] !== t4 || $[16] !== t5) {
|
|
80
|
+
t6 = /*#__PURE__*/jsx("span", {
|
|
81
|
+
id: t4,
|
|
82
|
+
className: t5,
|
|
118
83
|
style: style,
|
|
119
84
|
"data-component": "ActionList.Description",
|
|
120
85
|
children: props.children
|
|
121
86
|
});
|
|
122
|
-
$[
|
|
123
|
-
$[
|
|
124
|
-
$[
|
|
125
|
-
$[
|
|
126
|
-
$[
|
|
87
|
+
$[13] = props.children;
|
|
88
|
+
$[14] = style;
|
|
89
|
+
$[15] = t4;
|
|
90
|
+
$[16] = t5;
|
|
91
|
+
$[17] = t6;
|
|
127
92
|
} else {
|
|
128
|
-
|
|
93
|
+
t6 = $[17];
|
|
129
94
|
}
|
|
130
|
-
return
|
|
95
|
+
return t6;
|
|
131
96
|
} else {
|
|
132
|
-
let
|
|
133
|
-
if ($[
|
|
134
|
-
|
|
135
|
-
$[
|
|
136
|
-
$[
|
|
97
|
+
let t4;
|
|
98
|
+
if ($[18] !== className) {
|
|
99
|
+
t4 = clsx(className, classes.Description);
|
|
100
|
+
$[18] = className;
|
|
101
|
+
$[19] = t4;
|
|
137
102
|
} else {
|
|
138
|
-
|
|
103
|
+
t4 = $[19];
|
|
139
104
|
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
t8 = /*#__PURE__*/jsx(Truncate, {
|
|
105
|
+
let t5;
|
|
106
|
+
if ($[20] !== effectiveTitle || $[21] !== inlineDescriptionId || $[22] !== props.children || $[23] !== style || $[24] !== t4) {
|
|
107
|
+
t5 = /*#__PURE__*/jsx(Truncate, {
|
|
144
108
|
ref: containerRef,
|
|
145
109
|
id: inlineDescriptionId,
|
|
146
|
-
className:
|
|
110
|
+
className: t4,
|
|
147
111
|
style: style,
|
|
148
|
-
title:
|
|
112
|
+
title: effectiveTitle,
|
|
149
113
|
inline: true,
|
|
150
114
|
maxWidth: "100%",
|
|
151
115
|
"data-component": "ActionList.Description",
|
|
152
116
|
children: props.children
|
|
153
117
|
});
|
|
154
|
-
$[
|
|
155
|
-
$[
|
|
156
|
-
$[
|
|
157
|
-
$[
|
|
158
|
-
$[
|
|
159
|
-
$[
|
|
118
|
+
$[20] = effectiveTitle;
|
|
119
|
+
$[21] = inlineDescriptionId;
|
|
120
|
+
$[22] = props.children;
|
|
121
|
+
$[23] = style;
|
|
122
|
+
$[24] = t4;
|
|
123
|
+
$[25] = t5;
|
|
160
124
|
} else {
|
|
161
|
-
|
|
125
|
+
t5 = $[25];
|
|
162
126
|
}
|
|
163
|
-
return
|
|
127
|
+
return t5;
|
|
164
128
|
}
|
|
165
129
|
};
|
|
166
130
|
Description.__SLOT__ = Symbol('ActionList.Description');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../src/ActionList/Item.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"Item.d.ts","sourceRoot":"","sources":["../../src/ActionList/Item.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAA;AAmBrC,KAAK,sBAAsB,GAAG;IAC5B,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;CAC3B,CAAA;AAED,eAAO,MAAM,OAAO,EAAE,KAAK,CAAC,EAAE,CAAC,sBAAsB,CAEpD,CAAA;AA0SD,QAAA,MAAM,IAAI,IAlRa,EAAE,SAAS,KAAK,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqRjD,CAAA;AAEF,OAAO,EAAC,IAAI,EAAC,CAAA"}
|
package/dist/ActionList/Item.js
CHANGED
|
@@ -15,44 +15,8 @@ import VisuallyHidden from '../_VisuallyHidden.js';
|
|
|
15
15
|
import classes from './ActionList.module.css.js';
|
|
16
16
|
import { clsx } from 'clsx';
|
|
17
17
|
import { fixedForwardRef } from '../utils/modern-polymorphic.js';
|
|
18
|
-
import { TooltipContext, Tooltip } from '../TooltipV2/Tooltip.js';
|
|
19
18
|
import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
|
|
20
19
|
|
|
21
|
-
/**
|
|
22
|
-
* Stable wrapper that keeps Tooltip in the tree for button-semantic items
|
|
23
|
-
* to avoid remount cycles when truncation state changes.
|
|
24
|
-
* For non-button-semantic items, renders children directly.
|
|
25
|
-
*/
|
|
26
|
-
function ConditionalTooltip(t0) {
|
|
27
|
-
const $ = c(4);
|
|
28
|
-
const {
|
|
29
|
-
text,
|
|
30
|
-
enabled,
|
|
31
|
-
children
|
|
32
|
-
} = t0;
|
|
33
|
-
if (!enabled) {
|
|
34
|
-
return children;
|
|
35
|
-
}
|
|
36
|
-
const t1 = text || "";
|
|
37
|
-
const t2 = !text;
|
|
38
|
-
let t3;
|
|
39
|
-
if ($[0] !== children || $[1] !== t1 || $[2] !== t2) {
|
|
40
|
-
t3 = /*#__PURE__*/jsx(Tooltip, {
|
|
41
|
-
text: t1,
|
|
42
|
-
direction: "e",
|
|
43
|
-
delay: "medium",
|
|
44
|
-
_privateDisableTooltip: t2,
|
|
45
|
-
children: children
|
|
46
|
-
});
|
|
47
|
-
$[0] = children;
|
|
48
|
-
$[1] = t1;
|
|
49
|
-
$[2] = t2;
|
|
50
|
-
$[3] = t3;
|
|
51
|
-
} else {
|
|
52
|
-
t3 = $[3];
|
|
53
|
-
}
|
|
54
|
-
return t3;
|
|
55
|
-
}
|
|
56
20
|
const SubItem = t0 => {
|
|
57
21
|
const $ = c(2);
|
|
58
22
|
const {
|
|
@@ -254,7 +218,6 @@ const UnwrappedItem = ({
|
|
|
254
218
|
const blockDescriptionId = `${itemId}--block-description`;
|
|
255
219
|
const trailingVisualId = `${itemId}--trailing-visual`;
|
|
256
220
|
const inactiveWarningId = inactive && !showInactiveIndicator ? `${itemId}--warning-message` : undefined;
|
|
257
|
-
const [truncatedText, setTruncatedText] = React.useState(undefined);
|
|
258
221
|
const DefaultItemWrapper = listSemantics ? DivItemContainerNoBox : ButtonItemContainerNoBox;
|
|
259
222
|
const ItemWrapper = _PrivateItemWrapper || DefaultItemWrapper;
|
|
260
223
|
|
|
@@ -275,8 +238,8 @@ const UnwrappedItem = ({
|
|
|
275
238
|
'data-inactive': inactive ? true : undefined,
|
|
276
239
|
'data-loading': loading && !inactive ? true : undefined,
|
|
277
240
|
tabIndex: focusable ? undefined : 0,
|
|
278
|
-
'aria-labelledby': `${labelId} ${slots.trailingVisual ? trailingVisualId : ''}`,
|
|
279
|
-
'aria-describedby': [slots.description && descriptionVariant === 'block' ? blockDescriptionId : undefined,
|
|
241
|
+
'aria-labelledby': `${labelId} ${slots.trailingVisual ? trailingVisualId : ''} ${slots.description && descriptionVariant === 'inline' ? inlineDescriptionId : ''}`,
|
|
242
|
+
'aria-describedby': [slots.description && descriptionVariant === 'block' ? blockDescriptionId : undefined, inactiveWarningId !== null && inactiveWarningId !== void 0 ? inactiveWarningId : undefined].filter(String).join(' ').trim() || undefined,
|
|
280
243
|
...(includeSelectionAttribute && {
|
|
281
244
|
[itemSelectionAttribute]: selected
|
|
282
245
|
}),
|
|
@@ -306,76 +269,68 @@ const UnwrappedItem = ({
|
|
|
306
269
|
inactive: Boolean(inactiveText),
|
|
307
270
|
inlineDescriptionId,
|
|
308
271
|
blockDescriptionId,
|
|
309
|
-
trailingVisualId
|
|
310
|
-
setTruncatedText: buttonSemantics ? setTruncatedText : undefined
|
|
272
|
+
trailingVisualId
|
|
311
273
|
},
|
|
312
|
-
children: /*#__PURE__*/
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
className:
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
"
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
id: inactiveWarningId,
|
|
373
|
-
children: inactiveText
|
|
374
|
-
}) : null]
|
|
375
|
-
})]
|
|
376
|
-
}), !inactive && !loading && !menuContext && Boolean(slots.trailingAction) && slots.trailingAction, slots.subItem]
|
|
377
|
-
})
|
|
378
|
-
})
|
|
274
|
+
children: /*#__PURE__*/jsxs("li", {
|
|
275
|
+
...containerProps,
|
|
276
|
+
ref: listSemantics ? forwardedRef : null,
|
|
277
|
+
"data-variant": variant === 'danger' ? variant : undefined,
|
|
278
|
+
"data-active": active ? true : undefined,
|
|
279
|
+
"data-inactive": inactiveText ? true : undefined,
|
|
280
|
+
"data-is-disabled": disabled ? true : undefined,
|
|
281
|
+
"data-has-subitem": slots.subItem ? true : undefined,
|
|
282
|
+
"data-has-description": slots.description ? true : false,
|
|
283
|
+
className: clsx(classes.ActionListItem, className),
|
|
284
|
+
children: [/*#__PURE__*/jsxs(ItemWrapper, {
|
|
285
|
+
...wrapperProps,
|
|
286
|
+
className: classes.ActionListContent,
|
|
287
|
+
"data-size": size
|
|
288
|
+
// @ts-ignore: ItemWrapper is polymorphic and the ref type depends on the rendered element ('button' or 'li')
|
|
289
|
+
,
|
|
290
|
+
ref: forwardedRef,
|
|
291
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
292
|
+
className: classes.Spacer
|
|
293
|
+
}), /*#__PURE__*/jsx(Selection, {
|
|
294
|
+
selected: selected,
|
|
295
|
+
className: classes.LeadingAction
|
|
296
|
+
}), /*#__PURE__*/jsx(VisualOrIndicator, {
|
|
297
|
+
inactiveText: showInactiveIndicator ? inactiveText : undefined,
|
|
298
|
+
itemHasLeadingVisual: Boolean(slots.leadingVisual),
|
|
299
|
+
labelId: labelId,
|
|
300
|
+
loading: loading,
|
|
301
|
+
position: "leading",
|
|
302
|
+
children: slots.leadingVisual
|
|
303
|
+
}), /*#__PURE__*/jsxs("span", {
|
|
304
|
+
className: classes.ActionListSubContent,
|
|
305
|
+
"data-component": "ActionList.Item--DividerContainer",
|
|
306
|
+
children: [/*#__PURE__*/jsxs(ConditionalWrapper, {
|
|
307
|
+
if: !!slots.description,
|
|
308
|
+
className: classes.ItemDescriptionWrap,
|
|
309
|
+
"data-description-variant": descriptionVariant,
|
|
310
|
+
children: [/*#__PURE__*/jsxs("span", {
|
|
311
|
+
id: labelId,
|
|
312
|
+
className: classes.ItemLabel,
|
|
313
|
+
children: [childrenWithoutSlots, loading === true && !inactive && /*#__PURE__*/jsx(VisuallyHidden, {
|
|
314
|
+
children: "Loading"
|
|
315
|
+
})]
|
|
316
|
+
}), slots.description]
|
|
317
|
+
}), /*#__PURE__*/jsx(VisualOrIndicator, {
|
|
318
|
+
inactiveText: showInactiveIndicator ? inactiveText : undefined,
|
|
319
|
+
itemHasLeadingVisual: Boolean(slots.leadingVisual),
|
|
320
|
+
labelId: labelId,
|
|
321
|
+
loading: loading,
|
|
322
|
+
position: "trailing",
|
|
323
|
+
children: trailingVisual
|
|
324
|
+
}),
|
|
325
|
+
// If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
|
|
326
|
+
// render the inactive warning message directly in the item.
|
|
327
|
+
!showInactiveIndicator && inactiveText ? /*#__PURE__*/jsx("span", {
|
|
328
|
+
className: classes.InactiveWarning,
|
|
329
|
+
id: inactiveWarningId,
|
|
330
|
+
children: inactiveText
|
|
331
|
+
}) : null]
|
|
332
|
+
})]
|
|
333
|
+
}), !inactive && !loading && !menuContext && Boolean(slots.trailingAction) && slots.trailingAction, slots.subItem]
|
|
379
334
|
})
|
|
380
335
|
});
|
|
381
336
|
};
|
|
@@ -77,7 +77,6 @@ export type ItemContext = Pick<ActionListItemProps<React.ElementType>, 'variant'
|
|
|
77
77
|
blockDescriptionId?: string;
|
|
78
78
|
trailingVisualId?: string;
|
|
79
79
|
inactive?: boolean;
|
|
80
|
-
setTruncatedText?: (text: string | undefined) => void;
|
|
81
80
|
};
|
|
82
81
|
export declare const ItemContext: React.Context<ItemContext>;
|
|
83
82
|
export declare const getVariantStyles: (variant: ActionListItemProps<React.ElementType>["variant"], disabled: ActionListItemProps<React.ElementType>["disabled"], inactive?: boolean) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/ActionList/shared.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,KAAK,EAAC,QAAQ,EAAC,MAAM,gBAAgB,CAAA;AAC5C,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAA;AAIjE,KAAK,yBAAyB,CAAC,CAAC,IAAI,CAAC,SAAS,GAAG,GAAG,IAAI,CAAC,C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ACF,IAAI,EACJ,KAAK,CAAC,iBAAiB,CAAC;IACtB;;OAEG;IACH,OAAO,CAAC,EAAE,OAAO,GAAG,kBAAkB,GAAG,MAAM,CAAA;IAC/C;;OAEG;IACH,gBAAgB,CAAC,EAAE,QAAQ,GAAG,OAAO,GAAG,UAAU,CAAA;IAClD;;OAEG;IACH,YAAY,CAAC,EAAE,OAAO,CAAA;IACtB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf;;OAEG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAA;IAC1B,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAC,CACH,CAAA;AAED,KAAK,YAAY,GAAG,IAAI,CACtB,eAAe,CAAC,KAAK,CAAC,WAAW,CAAC,EAClC,SAAS,GAAG,kBAAkB,GAAG,cAAc,GAAG,MAAM,CACzD,GAAG;IACF,SAAS,CAAC,EAAE,MAAM,CAAA;CACnB,CAAA;AAED,eAAO,MAAM,WAAW,6BAAwC,CAAA"}
|
package/dist/hooks/useSlots.d.ts
CHANGED
|
@@ -1,8 +1,56 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
/**
|
|
3
|
+
* useSlots - Extract slot components from children for SSR-compatible slot APIs.
|
|
4
|
+
*
|
|
5
|
+
* Given a list of children and a config mapping slot names to component types,
|
|
6
|
+
* separates children into two groups: matched slots and the rest.
|
|
7
|
+
*
|
|
8
|
+
* Config: { leadingVisual: LeadingVisual, description: Description }
|
|
9
|
+
*
|
|
10
|
+
* Children: Matching: Output:
|
|
11
|
+
* +----------------+ slots = {
|
|
12
|
+
* | LeadingVisual | -> matches slot 0 --> leadingVisual: <LeadingVisual />
|
|
13
|
+
* | "Project name" | -> no match --> description: <Description />
|
|
14
|
+
* | Description | -> matches slot 1 --> }
|
|
15
|
+
* | TrailingVisual | -> no match --> rest = ["Project name", <TrailingVisual />]
|
|
16
|
+
* +----------------+
|
|
17
|
+
*
|
|
18
|
+
* Performance-sensitive: called per item in lists (e.g. 100-item ActionList
|
|
19
|
+
* calls this 101 times per render).
|
|
20
|
+
*
|
|
21
|
+
* Once all slots are filled, remaining children skip matching entirely in
|
|
22
|
+
* production (single integer comparison). In dev, we still scan for duplicates
|
|
23
|
+
* to emit a warning.
|
|
24
|
+
*
|
|
25
|
+
* Flow per child:
|
|
26
|
+
*
|
|
27
|
+
* child ──> isValidElement? ──no──> rest[]
|
|
28
|
+
* |
|
|
29
|
+
* yes
|
|
30
|
+
* |
|
|
31
|
+
* v
|
|
32
|
+
* all slots filled? ──yes──> rest[] (prod)
|
|
33
|
+
* | |
|
|
34
|
+
* no [dev: check for
|
|
35
|
+
* | duplicate warning]
|
|
36
|
+
* v
|
|
37
|
+
* match against unfilled slots
|
|
38
|
+
* |
|
|
39
|
+
* found match? ──no──> rest[]
|
|
40
|
+
* |
|
|
41
|
+
* yes
|
|
42
|
+
* |
|
|
43
|
+
* v
|
|
44
|
+
* slots[key] = child, slotsFound++
|
|
45
|
+
*
|
|
46
|
+
* Slot config supports two matcher styles:
|
|
47
|
+
* 1. Component reference: { visual: LeadingVisual }
|
|
48
|
+
* 2. Component + test fn: { block: [Description, props => props.variant === 'block'] }
|
|
49
|
+
*/
|
|
50
|
+
type Props = any;
|
|
2
51
|
type ComponentMatcher = React.ElementType<Props>;
|
|
3
52
|
type ComponentAndPropsMatcher = [ComponentMatcher, (props: Props) => boolean];
|
|
4
53
|
export type SlotConfig = Record<string, ComponentMatcher | ComponentAndPropsMatcher>;
|
|
5
|
-
type Props = any;
|
|
6
54
|
type SlotElements<Config extends SlotConfig> = {
|
|
7
55
|
[Property in keyof Config]: SlotValue<Config, Property>;
|
|
8
56
|
};
|
|
@@ -10,11 +58,7 @@ type SlotValue<Config, Property extends keyof Config> = Config[Property] extends
|
|
|
10
58
|
infer ElementType extends React.ElementType,
|
|
11
59
|
infer _testFn
|
|
12
60
|
] ? React.ReactElement<React.ComponentPropsWithoutRef<ElementType>, ElementType> : never;
|
|
13
|
-
/**
|
|
14
|
-
* Extract components from `children` so we can render them in different places,
|
|
15
|
-
* allowing us to implement components with SSR-compatible slot APIs.
|
|
16
|
-
* Note: We can only extract direct children, not nested ones.
|
|
17
|
-
*/
|
|
61
|
+
/** Extract slot components from children. See file header for details. */
|
|
18
62
|
export declare function useSlots<Config extends SlotConfig>(children: React.ReactNode, config: Config): [Partial<SlotElements<Config>>, React.ReactNode[]];
|
|
19
63
|
export {};
|
|
20
64
|
//# sourceMappingURL=useSlots.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSlots.d.ts","sourceRoot":"","sources":["../../src/hooks/useSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"useSlots.d.ts","sourceRoot":"","sources":["../../src/hooks/useSlots.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAA;AAKzB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AAKH,KAAK,KAAK,GAAG,GAAG,CAAA;AAChB,KAAK,gBAAgB,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AAChD,KAAK,wBAAwB,GAAG,CAAC,gBAAgB,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,OAAO,CAAC,CAAA;AAE7E,MAAM,MAAM,UAAU,GAAG,MAAM,CAAC,MAAM,EAAE,gBAAgB,GAAG,wBAAwB,CAAC,CAAA;AAEpF,KAAK,YAAY,CAAC,MAAM,SAAS,UAAU,IAAI;KAC5C,QAAQ,IAAI,MAAM,MAAM,GAAG,SAAS,CAAC,MAAM,EAAE,QAAQ,CAAC;CACxD,CAAA;AAED,KAAK,SAAS,CAAC,MAAM,EAAE,QAAQ,SAAS,MAAM,MAAM,IAAI,MAAM,CAAC,QAAQ,CAAC,SAAS,KAAK,CAAC,WAAW,GAC9F,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,wBAAwB,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,EAAE,MAAM,CAAC,QAAQ,CAAC,CAAC,GACtF,MAAM,CAAC,QAAQ,CAAC,SAAS,SAAS;IAC9B,MAAM,WAAW,SAAS,KAAK,CAAC,WAAW;IAE3C,MAAM,OAAO;CACd,GACD,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,wBAAwB,CAAC,WAAW,CAAC,EAAE,WAAW,CAAC,GAC5E,KAAK,CAAA;AAeX,0EAA0E;AAC1E,wBAAgB,QAAQ,CAAC,MAAM,SAAS,UAAU,EAChD,QAAQ,EAAE,KAAK,CAAC,SAAS,EACzB,MAAM,EAAE,MAAM,GACb,CAAC,OAAO,CAAC,YAAY,CAAC,MAAM,CAAC,CAAC,EAAE,KAAK,CAAC,SAAS,EAAE,CAAC,CAqDpD"}
|
package/dist/hooks/useSlots.js
CHANGED
|
@@ -2,29 +2,85 @@ import React from 'react';
|
|
|
2
2
|
import { warning } from '../utils/warning.js';
|
|
3
3
|
import { isSlot } from '../utils/is-slot.js';
|
|
4
4
|
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
/**
|
|
6
|
+
* useSlots - Extract slot components from children for SSR-compatible slot APIs.
|
|
7
|
+
*
|
|
8
|
+
* Given a list of children and a config mapping slot names to component types,
|
|
9
|
+
* separates children into two groups: matched slots and the rest.
|
|
10
|
+
*
|
|
11
|
+
* Config: { leadingVisual: LeadingVisual, description: Description }
|
|
12
|
+
*
|
|
13
|
+
* Children: Matching: Output:
|
|
14
|
+
* +----------------+ slots = {
|
|
15
|
+
* | LeadingVisual | -> matches slot 0 --> leadingVisual: <LeadingVisual />
|
|
16
|
+
* | "Project name" | -> no match --> description: <Description />
|
|
17
|
+
* | Description | -> matches slot 1 --> }
|
|
18
|
+
* | TrailingVisual | -> no match --> rest = ["Project name", <TrailingVisual />]
|
|
19
|
+
* +----------------+
|
|
20
|
+
*
|
|
21
|
+
* Performance-sensitive: called per item in lists (e.g. 100-item ActionList
|
|
22
|
+
* calls this 101 times per render).
|
|
23
|
+
*
|
|
24
|
+
* Once all slots are filled, remaining children skip matching entirely in
|
|
25
|
+
* production (single integer comparison). In dev, we still scan for duplicates
|
|
26
|
+
* to emit a warning.
|
|
27
|
+
*
|
|
28
|
+
* Flow per child:
|
|
29
|
+
*
|
|
30
|
+
* child ──> isValidElement? ──no──> rest[]
|
|
31
|
+
* |
|
|
32
|
+
* yes
|
|
33
|
+
* |
|
|
34
|
+
* v
|
|
35
|
+
* all slots filled? ──yes──> rest[] (prod)
|
|
36
|
+
* | |
|
|
37
|
+
* no [dev: check for
|
|
38
|
+
* | duplicate warning]
|
|
39
|
+
* v
|
|
40
|
+
* match against unfilled slots
|
|
41
|
+
* |
|
|
42
|
+
* found match? ──no──> rest[]
|
|
43
|
+
* |
|
|
44
|
+
* yes
|
|
45
|
+
* |
|
|
46
|
+
* v
|
|
47
|
+
* slots[key] = child, slotsFound++
|
|
48
|
+
*
|
|
49
|
+
* Slot config supports two matcher styles:
|
|
50
|
+
* 1. Component reference: { visual: LeadingVisual }
|
|
51
|
+
* 2. Component + test fn: { block: [Description, props => props.variant === 'block'] }
|
|
52
|
+
*/
|
|
7
53
|
|
|
8
|
-
//
|
|
54
|
+
// --- Types ---
|
|
9
55
|
|
|
10
|
-
// We don't know what the props are yet, we set them later based on slot config
|
|
11
56
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
12
57
|
|
|
13
|
-
//
|
|
58
|
+
// --- Matching ---
|
|
14
59
|
|
|
15
|
-
/**
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
60
|
+
/** Check if a child element matches a slot config entry, either by direct type comparison or slot symbol. */
|
|
61
|
+
function childMatchesSlot(child, slotValue) {
|
|
62
|
+
if (Array.isArray(slotValue)) {
|
|
63
|
+
const [component, testFn] = slotValue;
|
|
64
|
+
return (child.type === component || isSlot(child, component)) && testFn(child.props);
|
|
65
|
+
}
|
|
66
|
+
return child.type === slotValue || isSlot(child, slotValue);
|
|
67
|
+
}
|
|
23
68
|
|
|
24
|
-
|
|
69
|
+
// --- Hook ---
|
|
70
|
+
|
|
71
|
+
/** Extract slot components from children. See file header for details. */
|
|
72
|
+
function useSlots(children, config) {
|
|
25
73
|
const rest = [];
|
|
26
74
|
const keys = Object.keys(config);
|
|
27
75
|
const values = Object.values(config);
|
|
76
|
+
const totalSlots = keys.length;
|
|
77
|
+
|
|
78
|
+
// Initialize all slot keys to undefined so callers can check `slots.x === undefined`
|
|
79
|
+
const slots = {};
|
|
80
|
+
for (let i = 0; i < totalSlots; i++) {
|
|
81
|
+
slots[keys[i]] = undefined;
|
|
82
|
+
}
|
|
83
|
+
let slotsFound = 0;
|
|
28
84
|
|
|
29
85
|
// eslint-disable-next-line github/array-foreach
|
|
30
86
|
React.Children.forEach(children, child => {
|
|
@@ -32,41 +88,63 @@ function useSlots(children, config) {
|
|
|
32
88
|
rest.push(child);
|
|
33
89
|
return;
|
|
34
90
|
}
|
|
35
|
-
const index = values.findIndex(value => {
|
|
36
|
-
if (Array.isArray(value)) {
|
|
37
|
-
const [component, testFn] = value;
|
|
38
|
-
return (child.type === component || isSlot(child, component)) && testFn(child.props);
|
|
39
|
-
} else {
|
|
40
|
-
return child.type === value || isSlot(child, value);
|
|
41
|
-
}
|
|
42
|
-
});
|
|
43
91
|
|
|
44
|
-
//
|
|
45
|
-
if (
|
|
92
|
+
// Short-circuit: all slots filled, no more matching needed
|
|
93
|
+
if (slotsFound === totalSlots) {
|
|
94
|
+
if (process.env.NODE_ENV !== "production" && warnIfDuplicate(child, keys, values, totalSlots)) {
|
|
95
|
+
return;
|
|
96
|
+
}
|
|
46
97
|
rest.push(child);
|
|
47
98
|
return;
|
|
48
99
|
}
|
|
49
|
-
const slotKey = keys[index];
|
|
50
100
|
|
|
51
|
-
//
|
|
52
|
-
|
|
53
|
-
|
|
101
|
+
// Try to match child against a slot
|
|
102
|
+
const matchedIndex = findMatchingSlot(child, values, totalSlots);
|
|
103
|
+
if (matchedIndex === -1) {
|
|
104
|
+
rest.push(child);
|
|
54
105
|
return;
|
|
55
106
|
}
|
|
107
|
+
const slotKey = keys[matchedIndex];
|
|
56
108
|
|
|
57
|
-
//
|
|
58
|
-
|
|
109
|
+
// Duplicate: slot already filled by an earlier child
|
|
110
|
+
if (slots[slotKey] !== undefined) {
|
|
111
|
+
if (process.env.NODE_ENV !== "production") {
|
|
112
|
+
process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(slotKey)}" slot. Only the first will be rendered.`) : void 0;
|
|
113
|
+
}
|
|
114
|
+
return;
|
|
115
|
+
}
|
|
59
116
|
slots[slotKey] = child;
|
|
117
|
+
slotsFound++;
|
|
60
118
|
});
|
|
61
119
|
return [slots, rest];
|
|
62
120
|
}
|
|
63
121
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
122
|
+
// --- Helpers ---
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* Find the first slot config entry matching this child.
|
|
126
|
+
* Returns the config index, or -1 if no match.
|
|
127
|
+
*/
|
|
128
|
+
function findMatchingSlot(child, values, totalSlots) {
|
|
129
|
+
for (let i = 0; i < totalSlots; i++) {
|
|
130
|
+
if (childMatchesSlot(child, values[i])) return i;
|
|
131
|
+
}
|
|
132
|
+
return -1;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/**
|
|
136
|
+
* Dev-only: check if a child duplicates an already-filled slot.
|
|
137
|
+
* Returns true (and warns) if a duplicate is found, false otherwise.
|
|
138
|
+
* Used in the short-circuit path where all slots are already filled.
|
|
139
|
+
*/
|
|
140
|
+
function warnIfDuplicate(child, keys, values, totalSlots) {
|
|
141
|
+
for (let i = 0; i < totalSlots; i++) {
|
|
142
|
+
if (childMatchesSlot(child, values[i])) {
|
|
143
|
+
process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(keys[i])}" slot. Only the first will be rendered.`) : void 0;
|
|
144
|
+
return true;
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
return false;
|
|
70
148
|
}
|
|
71
149
|
|
|
72
150
|
export { useSlots };
|
package/package.json
CHANGED