@primer/react 0.0.0-20260218182540 → 0.0.0-20260218182609
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 +2 -2
- package/dist/ActionList/Item.d.ts.map +1 -1
- package/dist/ActionList/Item.js +591 -182
- package/dist/ActionList/List.d.ts.map +1 -1
- package/dist/ActionList/List.js +6 -5
- package/dist/hooks/useSlots.d.ts +6 -50
- package/dist/hooks/useSlots.d.ts.map +1 -1
- package/dist/hooks/useSlots.js +36 -114
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
# @primer/react
|
|
2
2
|
|
|
3
|
-
## 0.0.0-
|
|
3
|
+
## 0.0.0-20260218182609
|
|
4
4
|
|
|
5
5
|
### Minor Changes
|
|
6
6
|
|
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
|
|
21
21
|
- Fake entry to force publishing
|
|
22
22
|
|
|
23
|
-
- [#
|
|
23
|
+
- [#7554](https://github.com/primer/react/pull/7554) [`38e18ea`](https://github.com/primer/react/commit/38e18eaa0e965dba05f29422d7724e694d5ff4c4) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(ActionList): memoize context values, menuItemProps, and aria attributes
|
|
24
24
|
|
|
25
25
|
- [#7548](https://github.com/primer/react/pull/7548) [`d4b32c3`](https://github.com/primer/react/commit/d4b32c3672d3d5421711324654c1028527dcdf38) Thanks [@hectahertz](https://github.com/hectahertz)! - perf(useIsMacOS): replace useState+useEffect with useSyncExternalStore to eliminate unnecessary re-render
|
|
26
26
|
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAqUD,QAAA,MAAM,IAAI,IAhSa,EAAE,SAAS,KAAK,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAmSjD,CAAA;AAEF,OAAO,EAAC,IAAI,EAAC,CAAA"}
|
package/dist/ActionList/Item.js
CHANGED
|
@@ -108,50 +108,132 @@ const DivItemContainerNoBox = /*#__PURE__*/React.forwardRef((t0, forwardedRef) =
|
|
|
108
108
|
}
|
|
109
109
|
return t2;
|
|
110
110
|
});
|
|
111
|
-
const
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
handleAddItem: _handleAddItem,
|
|
127
|
-
...props
|
|
128
|
-
}, forwardedRef) => {
|
|
111
|
+
const baseSlots = {
|
|
112
|
+
leadingVisual: LeadingVisual,
|
|
113
|
+
trailingVisual: TrailingVisual,
|
|
114
|
+
trailingAction: TrailingAction,
|
|
115
|
+
subItem: SubItem
|
|
116
|
+
};
|
|
117
|
+
const slotsConfig = {
|
|
118
|
+
...baseSlots,
|
|
119
|
+
description: Description
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
// Pre-allocated array for selectableRoles check, avoids per-render allocation
|
|
123
|
+
const selectableRoles = ['menuitemradio', 'menuitemcheckbox', 'option'];
|
|
124
|
+
const listRoleTypes = ['listbox', 'menu', 'list'];
|
|
125
|
+
const UnwrappedItem = (t0, forwardedRef) => {
|
|
129
126
|
var _slots$trailingVisual, _slots$description$pr, _slots$description;
|
|
130
|
-
const
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
127
|
+
const $ = c(151);
|
|
128
|
+
let _PrivateItemWrapper;
|
|
129
|
+
let className;
|
|
130
|
+
let id;
|
|
131
|
+
let inactiveText;
|
|
132
|
+
let loading;
|
|
133
|
+
let onSelectUser;
|
|
134
|
+
let props;
|
|
135
|
+
let role;
|
|
136
|
+
let t1;
|
|
137
|
+
let t2;
|
|
138
|
+
let t3;
|
|
139
|
+
let t4;
|
|
140
|
+
let t5;
|
|
141
|
+
if ($[0] !== t0) {
|
|
142
|
+
const {
|
|
143
|
+
variant: t6,
|
|
144
|
+
size: t7,
|
|
145
|
+
disabled: t8,
|
|
146
|
+
inactiveText: t9,
|
|
147
|
+
selected: t10,
|
|
148
|
+
active: t11,
|
|
149
|
+
onSelect: t12,
|
|
150
|
+
id: t13,
|
|
151
|
+
role: t14,
|
|
152
|
+
loading: t15,
|
|
153
|
+
_PrivateItemWrapper: t16,
|
|
154
|
+
className: t17,
|
|
155
|
+
groupId: _groupId,
|
|
156
|
+
renderItem: _renderItem,
|
|
157
|
+
handleAddItem: _handleAddItem,
|
|
158
|
+
...t18
|
|
159
|
+
} = t0;
|
|
160
|
+
t1 = t6;
|
|
161
|
+
t2 = t7;
|
|
162
|
+
t3 = t8;
|
|
163
|
+
inactiveText = t9;
|
|
164
|
+
t4 = t10;
|
|
165
|
+
t5 = t11;
|
|
166
|
+
onSelectUser = t12;
|
|
167
|
+
id = t13;
|
|
168
|
+
role = t14;
|
|
169
|
+
loading = t15;
|
|
170
|
+
_PrivateItemWrapper = t16;
|
|
171
|
+
className = t17;
|
|
172
|
+
props = t18;
|
|
173
|
+
$[0] = t0;
|
|
174
|
+
$[1] = _PrivateItemWrapper;
|
|
175
|
+
$[2] = className;
|
|
176
|
+
$[3] = id;
|
|
177
|
+
$[4] = inactiveText;
|
|
178
|
+
$[5] = loading;
|
|
179
|
+
$[6] = onSelectUser;
|
|
180
|
+
$[7] = props;
|
|
181
|
+
$[8] = role;
|
|
182
|
+
$[9] = t1;
|
|
183
|
+
$[10] = t2;
|
|
184
|
+
$[11] = t3;
|
|
185
|
+
$[12] = t4;
|
|
186
|
+
$[13] = t5;
|
|
187
|
+
} else {
|
|
188
|
+
_PrivateItemWrapper = $[1];
|
|
189
|
+
className = $[2];
|
|
190
|
+
id = $[3];
|
|
191
|
+
inactiveText = $[4];
|
|
192
|
+
loading = $[5];
|
|
193
|
+
onSelectUser = $[6];
|
|
194
|
+
props = $[7];
|
|
195
|
+
role = $[8];
|
|
196
|
+
t1 = $[9];
|
|
197
|
+
t2 = $[10];
|
|
198
|
+
t3 = $[11];
|
|
199
|
+
t4 = $[12];
|
|
200
|
+
t5 = $[13];
|
|
201
|
+
}
|
|
202
|
+
const variant = t1 === undefined ? "default" : t1;
|
|
203
|
+
const size = t2 === undefined ? "medium" : t2;
|
|
204
|
+
const disabled = t3 === undefined ? false : t3;
|
|
205
|
+
const selected = t4 === undefined ? undefined : t4;
|
|
206
|
+
const active = t5 === undefined ? false : t5;
|
|
207
|
+
const [partialSlots, childrenWithoutSlots] = useSlots(props.children, slotsConfig);
|
|
208
|
+
let t6;
|
|
209
|
+
if ($[14] !== partialSlots) {
|
|
210
|
+
t6 = {
|
|
211
|
+
description: undefined,
|
|
212
|
+
...partialSlots
|
|
213
|
+
};
|
|
214
|
+
$[14] = partialSlots;
|
|
215
|
+
$[15] = t6;
|
|
216
|
+
} else {
|
|
217
|
+
t6 = $[15];
|
|
218
|
+
}
|
|
219
|
+
const slots = t6;
|
|
144
220
|
const {
|
|
145
221
|
container,
|
|
146
222
|
afterSelect,
|
|
147
223
|
selectionAttribute,
|
|
148
224
|
defaultTrailingVisual
|
|
149
225
|
} = React.useContext(ActionListContainerContext);
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
226
|
+
let t7;
|
|
227
|
+
if ($[16] !== defaultTrailingVisual) {
|
|
228
|
+
t7 = defaultTrailingVisual ? /*#__PURE__*/jsx(TrailingVisual, {
|
|
229
|
+
children: defaultTrailingVisual
|
|
230
|
+
}) : null;
|
|
231
|
+
$[16] = defaultTrailingVisual;
|
|
232
|
+
$[17] = t7;
|
|
233
|
+
} else {
|
|
234
|
+
t7 = $[17];
|
|
235
|
+
}
|
|
236
|
+
const wrappedDefaultTrailingVisual = t7;
|
|
155
237
|
const trailingVisual = (_slots$trailingVisual = slots.trailingVisual) !== null && _slots$trailingVisual !== void 0 ? _slots$trailingVisual : wrappedDefaultTrailingVisual;
|
|
156
238
|
const {
|
|
157
239
|
role: listRole,
|
|
@@ -161,57 +243,127 @@ const UnwrappedItem = ({
|
|
|
161
243
|
selectionVariant: groupSelectionVariant
|
|
162
244
|
} = React.useContext(GroupContext);
|
|
163
245
|
const inactive = Boolean(inactiveText);
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
246
|
+
const menuContext = container === "ActionMenu" || container === "SelectPanel" || container === "FilteredActionList";
|
|
247
|
+
let t8;
|
|
248
|
+
if ($[18] !== inactive || $[19] !== listRole) {
|
|
249
|
+
t8 = inactive && !(listRole !== undefined && ["menu", "listbox"].includes(listRole));
|
|
250
|
+
$[18] = inactive;
|
|
251
|
+
$[19] = listRole;
|
|
252
|
+
$[20] = t8;
|
|
253
|
+
} else {
|
|
254
|
+
t8 = $[20];
|
|
255
|
+
}
|
|
256
|
+
const showInactiveIndicator = t8;
|
|
257
|
+
let t9;
|
|
258
|
+
if ($[21] !== onSelectUser) {
|
|
259
|
+
t9 = (event, afterSelect_0) => {
|
|
260
|
+
if (typeof onSelectUser === "function") {
|
|
261
|
+
onSelectUser(event);
|
|
262
|
+
}
|
|
263
|
+
if (event.defaultPrevented) {
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
if (typeof afterSelect_0 === "function") {
|
|
267
|
+
afterSelect_0(event);
|
|
268
|
+
}
|
|
269
|
+
};
|
|
270
|
+
$[21] = onSelectUser;
|
|
271
|
+
$[22] = t9;
|
|
272
|
+
} else {
|
|
273
|
+
t9 = $[22];
|
|
274
|
+
}
|
|
275
|
+
const onSelect = t9;
|
|
174
276
|
const selectionVariant = groupSelectionVariant ? groupSelectionVariant : listSelectionVariant;
|
|
175
|
-
|
|
176
|
-
/** Infer item role based on the container */
|
|
177
277
|
let inferredItemRole;
|
|
178
|
-
if (container ===
|
|
179
|
-
if (selectionVariant ===
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
278
|
+
if (container === "ActionMenu") {
|
|
279
|
+
if (selectionVariant === "single") {
|
|
280
|
+
inferredItemRole = "menuitemradio";
|
|
281
|
+
} else {
|
|
282
|
+
if (selectionVariant === "multiple") {
|
|
283
|
+
inferredItemRole = "menuitemcheckbox";
|
|
284
|
+
} else {
|
|
285
|
+
inferredItemRole = "menuitem";
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
} else {
|
|
289
|
+
if (listRole === "listbox") {
|
|
290
|
+
if (selectionVariant !== undefined && !role) {
|
|
291
|
+
inferredItemRole = "option";
|
|
292
|
+
}
|
|
293
|
+
} else {
|
|
294
|
+
if (listRole === "tablist") {
|
|
295
|
+
inferredItemRole = "tab";
|
|
296
|
+
}
|
|
297
|
+
}
|
|
184
298
|
}
|
|
185
299
|
const itemRole = role || inferredItemRole;
|
|
186
300
|
if (slots.trailingAction) {
|
|
187
|
-
!!menuContext ? process.env.NODE_ENV !== "production" ? invariant(false,
|
|
301
|
+
!!menuContext ? process.env.NODE_ENV !== "production" ? invariant(false, "ActionList.TrailingAction can not be used within a list with an ARIA role of \"menu\" or \"listbox\".") : invariant(false) : void 0;
|
|
188
302
|
}
|
|
189
|
-
|
|
190
|
-
/** Infer the proper selection attribute based on the item's role */
|
|
191
303
|
let inferredSelectionAttribute;
|
|
192
|
-
if (itemRole ===
|
|
304
|
+
if (itemRole === "menuitemradio" || itemRole === "menuitemcheckbox") {
|
|
305
|
+
inferredSelectionAttribute = "aria-checked";
|
|
306
|
+
} else {
|
|
307
|
+
if (itemRole === "option") {
|
|
308
|
+
inferredSelectionAttribute = "aria-selected";
|
|
309
|
+
}
|
|
310
|
+
}
|
|
193
311
|
const itemSelectionAttribute = selectionAttribute || inferredSelectionAttribute;
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
312
|
+
const listItemSemantics = itemRole === "option" || itemRole === "menuitem" || itemRole === "menuitemradio" || itemRole === "menuitemcheckbox" || itemRole === "tab";
|
|
313
|
+
let t10;
|
|
314
|
+
if ($[23] !== inactive || $[24] !== listItemSemantics || $[25] !== listRole) {
|
|
315
|
+
t10 = listRole && listRoleTypes.includes(listRole) || inactive || listItemSemantics;
|
|
316
|
+
$[23] = inactive;
|
|
317
|
+
$[24] = listItemSemantics;
|
|
318
|
+
$[25] = listRole;
|
|
319
|
+
$[26] = t10;
|
|
320
|
+
} else {
|
|
321
|
+
t10 = $[26];
|
|
322
|
+
}
|
|
323
|
+
const listSemantics = t10;
|
|
198
324
|
const buttonSemantics = !listSemantics && !_PrivateItemWrapper;
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
if (disabled || inactive || loading) return;
|
|
205
|
-
if ([' ', 'Enter'].includes(event_1.key)) {
|
|
206
|
-
if (event_1.key === ' ') {
|
|
207
|
-
event_1.preventDefault(); // prevent scrolling on Space
|
|
208
|
-
// immediately reset defaultPrevented once its job is done
|
|
209
|
-
// so as to not disturb the functions that use that event after this
|
|
210
|
-
event_1.defaultPrevented = false;
|
|
325
|
+
let t11;
|
|
326
|
+
if ($[27] !== afterSelect || $[28] !== disabled || $[29] !== inactive || $[30] !== loading || $[31] !== onSelect) {
|
|
327
|
+
t11 = event_0 => {
|
|
328
|
+
if (disabled || inactive || loading) {
|
|
329
|
+
return;
|
|
211
330
|
}
|
|
212
|
-
onSelect(
|
|
213
|
-
}
|
|
214
|
-
|
|
331
|
+
onSelect(event_0, afterSelect);
|
|
332
|
+
};
|
|
333
|
+
$[27] = afterSelect;
|
|
334
|
+
$[28] = disabled;
|
|
335
|
+
$[29] = inactive;
|
|
336
|
+
$[30] = loading;
|
|
337
|
+
$[31] = onSelect;
|
|
338
|
+
$[32] = t11;
|
|
339
|
+
} else {
|
|
340
|
+
t11 = $[32];
|
|
341
|
+
}
|
|
342
|
+
const clickHandler = t11;
|
|
343
|
+
let t12;
|
|
344
|
+
if ($[33] !== afterSelect || $[34] !== disabled || $[35] !== inactive || $[36] !== loading || $[37] !== onSelect) {
|
|
345
|
+
t12 = event_1 => {
|
|
346
|
+
if (disabled || inactive || loading) {
|
|
347
|
+
return;
|
|
348
|
+
}
|
|
349
|
+
if (event_1.key === " " || event_1.key === "Enter") {
|
|
350
|
+
if (event_1.key === " ") {
|
|
351
|
+
event_1.preventDefault();
|
|
352
|
+
event_1.defaultPrevented = false;
|
|
353
|
+
}
|
|
354
|
+
onSelect(event_1, afterSelect);
|
|
355
|
+
}
|
|
356
|
+
};
|
|
357
|
+
$[33] = afterSelect;
|
|
358
|
+
$[34] = disabled;
|
|
359
|
+
$[35] = inactive;
|
|
360
|
+
$[36] = loading;
|
|
361
|
+
$[37] = onSelect;
|
|
362
|
+
$[38] = t12;
|
|
363
|
+
} else {
|
|
364
|
+
t12 = $[38];
|
|
365
|
+
}
|
|
366
|
+
const keyPressHandler = t12;
|
|
215
367
|
const itemId = useId(id);
|
|
216
368
|
const labelId = `${itemId}--label`;
|
|
217
369
|
const inlineDescriptionId = `${itemId}--inline-description`;
|
|
@@ -220,120 +372,377 @@ const UnwrappedItem = ({
|
|
|
220
372
|
const inactiveWarningId = inactive && !showInactiveIndicator ? `${itemId}--warning-message` : undefined;
|
|
221
373
|
const DefaultItemWrapper = listSemantics ? DivItemContainerNoBox : ButtonItemContainerNoBox;
|
|
222
374
|
const ItemWrapper = _PrivateItemWrapper || DefaultItemWrapper;
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
375
|
+
let t13;
|
|
376
|
+
if ($[39] !== itemRole || $[40] !== itemSelectionAttribute) {
|
|
377
|
+
t13 = itemSelectionAttribute && itemRole && selectableRoles.includes(itemRole);
|
|
378
|
+
$[39] = itemRole;
|
|
379
|
+
$[40] = itemSelectionAttribute;
|
|
380
|
+
$[41] = t13;
|
|
381
|
+
} else {
|
|
382
|
+
t13 = $[41];
|
|
230
383
|
}
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
const descriptionVariant = (_slots$description$pr = (_slots$description = slots.description) === null || _slots$description === void 0 ? void 0 : _slots$description.props.variant) !== null && _slots$description$pr !== void 0 ? _slots$description$pr :
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
384
|
+
const includeSelectionAttribute = t13;
|
|
385
|
+
const focusable = showInactiveIndicator ? true : undefined;
|
|
386
|
+
const descriptionVariant = (_slots$description$pr = (_slots$description = slots.description) === null || _slots$description === void 0 ? void 0 : _slots$description.props.variant) !== null && _slots$description$pr !== void 0 ? _slots$description$pr : "inline";
|
|
387
|
+
const hasTrailingVisualSlot = Boolean(slots.trailingVisual);
|
|
388
|
+
const hasDescriptionSlot = Boolean(slots.description);
|
|
389
|
+
let parts;
|
|
390
|
+
if ($[42] !== descriptionVariant || $[43] !== hasDescriptionSlot || $[44] !== hasTrailingVisualSlot || $[45] !== inlineDescriptionId || $[46] !== labelId || $[47] !== trailingVisualId) {
|
|
391
|
+
parts = [labelId];
|
|
392
|
+
if (hasTrailingVisualSlot) {
|
|
393
|
+
parts.push(trailingVisualId);
|
|
394
|
+
}
|
|
395
|
+
if (hasDescriptionSlot && descriptionVariant === "inline") {
|
|
396
|
+
parts.push(inlineDescriptionId);
|
|
397
|
+
}
|
|
398
|
+
$[42] = descriptionVariant;
|
|
399
|
+
$[43] = hasDescriptionSlot;
|
|
400
|
+
$[44] = hasTrailingVisualSlot;
|
|
401
|
+
$[45] = inlineDescriptionId;
|
|
402
|
+
$[46] = labelId;
|
|
403
|
+
$[47] = trailingVisualId;
|
|
404
|
+
$[48] = parts;
|
|
405
|
+
} else {
|
|
406
|
+
parts = $[48];
|
|
407
|
+
}
|
|
408
|
+
const ariaLabelledBy = parts.join(" ");
|
|
409
|
+
let parts_0;
|
|
410
|
+
if ($[49] !== blockDescriptionId || $[50] !== descriptionVariant || $[51] !== hasDescriptionSlot || $[52] !== inactiveWarningId) {
|
|
411
|
+
parts_0 = [];
|
|
412
|
+
if (hasDescriptionSlot && descriptionVariant === "block") {
|
|
413
|
+
parts_0.push(blockDescriptionId);
|
|
414
|
+
}
|
|
415
|
+
if (inactiveWarningId) {
|
|
416
|
+
parts_0.push(inactiveWarningId);
|
|
417
|
+
}
|
|
418
|
+
$[49] = blockDescriptionId;
|
|
419
|
+
$[50] = descriptionVariant;
|
|
420
|
+
$[51] = hasDescriptionSlot;
|
|
421
|
+
$[52] = inactiveWarningId;
|
|
422
|
+
$[53] = parts_0;
|
|
423
|
+
} else {
|
|
424
|
+
parts_0 = $[53];
|
|
425
|
+
}
|
|
426
|
+
const ariaDescribedBy = parts_0.length > 0 ? parts_0.join(" ") : undefined;
|
|
427
|
+
const t14 = !buttonSemantics ? keyPressHandler : undefined;
|
|
428
|
+
const t15 = disabled ? true : undefined;
|
|
429
|
+
const t16 = inactive ? true : undefined;
|
|
430
|
+
const t17 = loading && !inactive ? true : undefined;
|
|
431
|
+
const t18 = focusable ? undefined : 0;
|
|
432
|
+
let t19;
|
|
433
|
+
if ($[54] !== includeSelectionAttribute || $[55] !== itemSelectionAttribute || $[56] !== selected) {
|
|
434
|
+
t19 = includeSelectionAttribute && {
|
|
244
435
|
[itemSelectionAttribute]: selected
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
}
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
436
|
+
};
|
|
437
|
+
$[54] = includeSelectionAttribute;
|
|
438
|
+
$[55] = itemSelectionAttribute;
|
|
439
|
+
$[56] = selected;
|
|
440
|
+
$[57] = t19;
|
|
441
|
+
} else {
|
|
442
|
+
t19 = $[57];
|
|
443
|
+
}
|
|
444
|
+
let t20;
|
|
445
|
+
if ($[58] !== ariaDescribedBy || $[59] !== ariaLabelledBy || $[60] !== clickHandler || $[61] !== itemId || $[62] !== itemRole || $[63] !== t14 || $[64] !== t15 || $[65] !== t16 || $[66] !== t17 || $[67] !== t18 || $[68] !== t19) {
|
|
446
|
+
t20 = {
|
|
447
|
+
onClick: clickHandler,
|
|
448
|
+
onKeyPress: t14,
|
|
449
|
+
"aria-disabled": t15,
|
|
450
|
+
"data-inactive": t16,
|
|
451
|
+
"data-loading": t17,
|
|
452
|
+
tabIndex: t18,
|
|
453
|
+
"aria-labelledby": ariaLabelledBy,
|
|
454
|
+
"aria-describedby": ariaDescribedBy,
|
|
455
|
+
...t19,
|
|
456
|
+
role: itemRole,
|
|
457
|
+
id: itemId
|
|
458
|
+
};
|
|
459
|
+
$[58] = ariaDescribedBy;
|
|
460
|
+
$[59] = ariaLabelledBy;
|
|
461
|
+
$[60] = clickHandler;
|
|
462
|
+
$[61] = itemId;
|
|
463
|
+
$[62] = itemRole;
|
|
464
|
+
$[63] = t14;
|
|
465
|
+
$[64] = t15;
|
|
466
|
+
$[65] = t16;
|
|
467
|
+
$[66] = t17;
|
|
468
|
+
$[67] = t18;
|
|
469
|
+
$[68] = t19;
|
|
470
|
+
$[69] = t20;
|
|
471
|
+
} else {
|
|
472
|
+
t20 = $[69];
|
|
473
|
+
}
|
|
474
|
+
const menuItemProps = t20;
|
|
475
|
+
let t21;
|
|
476
|
+
if ($[70] !== _PrivateItemWrapper || $[71] !== forwardedRef || $[72] !== itemRole || $[73] !== listSemantics || $[74] !== menuItemProps || $[75] !== props) {
|
|
477
|
+
t21 = _PrivateItemWrapper ? {
|
|
478
|
+
role: itemRole ? "none" : undefined,
|
|
479
|
+
...props
|
|
480
|
+
} : listSemantics && {
|
|
481
|
+
...menuItemProps,
|
|
482
|
+
...props,
|
|
483
|
+
ref: forwardedRef
|
|
484
|
+
} || {};
|
|
485
|
+
$[70] = _PrivateItemWrapper;
|
|
486
|
+
$[71] = forwardedRef;
|
|
487
|
+
$[72] = itemRole;
|
|
488
|
+
$[73] = listSemantics;
|
|
489
|
+
$[74] = menuItemProps;
|
|
490
|
+
$[75] = props;
|
|
491
|
+
$[76] = t21;
|
|
492
|
+
} else {
|
|
493
|
+
t21 = $[76];
|
|
494
|
+
}
|
|
495
|
+
const containerProps = t21;
|
|
496
|
+
let t22;
|
|
497
|
+
if ($[77] !== _PrivateItemWrapper || $[78] !== forwardedRef || $[79] !== listSemantics || $[80] !== menuItemProps || $[81] !== props) {
|
|
498
|
+
t22 = _PrivateItemWrapper ? menuItemProps : !listSemantics && {
|
|
499
|
+
...menuItemProps,
|
|
500
|
+
...props,
|
|
501
|
+
ref: forwardedRef
|
|
502
|
+
};
|
|
503
|
+
$[77] = _PrivateItemWrapper;
|
|
504
|
+
$[78] = forwardedRef;
|
|
505
|
+
$[79] = listSemantics;
|
|
506
|
+
$[80] = menuItemProps;
|
|
507
|
+
$[81] = props;
|
|
508
|
+
$[82] = t22;
|
|
509
|
+
} else {
|
|
510
|
+
t22 = $[82];
|
|
511
|
+
}
|
|
512
|
+
const wrapperProps = t22;
|
|
513
|
+
const t23 = Boolean(inactiveText);
|
|
514
|
+
let t24;
|
|
515
|
+
if ($[83] !== blockDescriptionId || $[84] !== disabled || $[85] !== inlineDescriptionId || $[86] !== size || $[87] !== t23 || $[88] !== trailingVisualId || $[89] !== variant) {
|
|
516
|
+
t24 = {
|
|
266
517
|
variant,
|
|
267
518
|
size,
|
|
268
519
|
disabled,
|
|
269
|
-
inactive:
|
|
520
|
+
inactive: t23,
|
|
270
521
|
inlineDescriptionId,
|
|
271
522
|
blockDescriptionId,
|
|
272
523
|
trailingVisualId
|
|
273
|
-
}
|
|
274
|
-
|
|
524
|
+
};
|
|
525
|
+
$[83] = blockDescriptionId;
|
|
526
|
+
$[84] = disabled;
|
|
527
|
+
$[85] = inlineDescriptionId;
|
|
528
|
+
$[86] = size;
|
|
529
|
+
$[87] = t23;
|
|
530
|
+
$[88] = trailingVisualId;
|
|
531
|
+
$[89] = variant;
|
|
532
|
+
$[90] = t24;
|
|
533
|
+
} else {
|
|
534
|
+
t24 = $[90];
|
|
535
|
+
}
|
|
536
|
+
const itemContextValue = t24;
|
|
537
|
+
const t25 = listSemantics ? forwardedRef : null;
|
|
538
|
+
const t26 = variant === "danger" ? variant : undefined;
|
|
539
|
+
const t27 = active ? true : undefined;
|
|
540
|
+
const t28 = inactiveText ? true : undefined;
|
|
541
|
+
const t29 = slots.subItem ? true : undefined;
|
|
542
|
+
const t30 = slots.description ? true : false;
|
|
543
|
+
let t31;
|
|
544
|
+
if ($[91] !== className) {
|
|
545
|
+
t31 = clsx(classes.ActionListItem, className);
|
|
546
|
+
$[91] = className;
|
|
547
|
+
$[92] = t31;
|
|
548
|
+
} else {
|
|
549
|
+
t31 = $[92];
|
|
550
|
+
}
|
|
551
|
+
let t32;
|
|
552
|
+
if ($[93] === Symbol.for("react.memo_cache_sentinel")) {
|
|
553
|
+
t32 = /*#__PURE__*/jsx("span", {
|
|
554
|
+
className: classes.Spacer
|
|
555
|
+
});
|
|
556
|
+
$[93] = t32;
|
|
557
|
+
} else {
|
|
558
|
+
t32 = $[93];
|
|
559
|
+
}
|
|
560
|
+
let t33;
|
|
561
|
+
if ($[94] !== selected) {
|
|
562
|
+
t33 = /*#__PURE__*/jsx(Selection, {
|
|
563
|
+
selected: selected,
|
|
564
|
+
className: classes.LeadingAction
|
|
565
|
+
});
|
|
566
|
+
$[94] = selected;
|
|
567
|
+
$[95] = t33;
|
|
568
|
+
} else {
|
|
569
|
+
t33 = $[95];
|
|
570
|
+
}
|
|
571
|
+
const t34 = showInactiveIndicator ? inactiveText : undefined;
|
|
572
|
+
const t35 = Boolean(slots.leadingVisual);
|
|
573
|
+
let t36;
|
|
574
|
+
if ($[96] !== labelId || $[97] !== loading || $[98] !== slots.leadingVisual || $[99] !== t34 || $[100] !== t35) {
|
|
575
|
+
t36 = /*#__PURE__*/jsx(VisualOrIndicator, {
|
|
576
|
+
inactiveText: t34,
|
|
577
|
+
itemHasLeadingVisual: t35,
|
|
578
|
+
labelId: labelId,
|
|
579
|
+
loading: loading,
|
|
580
|
+
position: "leading",
|
|
581
|
+
children: slots.leadingVisual
|
|
582
|
+
});
|
|
583
|
+
$[96] = labelId;
|
|
584
|
+
$[97] = loading;
|
|
585
|
+
$[98] = slots.leadingVisual;
|
|
586
|
+
$[99] = t34;
|
|
587
|
+
$[100] = t35;
|
|
588
|
+
$[101] = t36;
|
|
589
|
+
} else {
|
|
590
|
+
t36 = $[101];
|
|
591
|
+
}
|
|
592
|
+
const t37 = !!slots.description;
|
|
593
|
+
let t38;
|
|
594
|
+
if ($[102] !== inactive || $[103] !== loading) {
|
|
595
|
+
t38 = loading === true && !inactive && /*#__PURE__*/jsx(VisuallyHidden, {
|
|
596
|
+
children: "Loading"
|
|
597
|
+
});
|
|
598
|
+
$[102] = inactive;
|
|
599
|
+
$[103] = loading;
|
|
600
|
+
$[104] = t38;
|
|
601
|
+
} else {
|
|
602
|
+
t38 = $[104];
|
|
603
|
+
}
|
|
604
|
+
let t39;
|
|
605
|
+
if ($[105] !== childrenWithoutSlots || $[106] !== labelId || $[107] !== t38) {
|
|
606
|
+
t39 = /*#__PURE__*/jsxs("span", {
|
|
607
|
+
id: labelId,
|
|
608
|
+
className: classes.ItemLabel,
|
|
609
|
+
children: [childrenWithoutSlots, t38]
|
|
610
|
+
});
|
|
611
|
+
$[105] = childrenWithoutSlots;
|
|
612
|
+
$[106] = labelId;
|
|
613
|
+
$[107] = t38;
|
|
614
|
+
$[108] = t39;
|
|
615
|
+
} else {
|
|
616
|
+
t39 = $[108];
|
|
617
|
+
}
|
|
618
|
+
let t40;
|
|
619
|
+
if ($[109] !== descriptionVariant || $[110] !== slots.description || $[111] !== t37 || $[112] !== t39) {
|
|
620
|
+
t40 = /*#__PURE__*/jsxs(ConditionalWrapper, {
|
|
621
|
+
if: t37,
|
|
622
|
+
className: classes.ItemDescriptionWrap,
|
|
623
|
+
"data-description-variant": descriptionVariant,
|
|
624
|
+
children: [t39, slots.description]
|
|
625
|
+
});
|
|
626
|
+
$[109] = descriptionVariant;
|
|
627
|
+
$[110] = slots.description;
|
|
628
|
+
$[111] = t37;
|
|
629
|
+
$[112] = t39;
|
|
630
|
+
$[113] = t40;
|
|
631
|
+
} else {
|
|
632
|
+
t40 = $[113];
|
|
633
|
+
}
|
|
634
|
+
const t41 = showInactiveIndicator ? inactiveText : undefined;
|
|
635
|
+
const t42 = Boolean(slots.leadingVisual);
|
|
636
|
+
let t43;
|
|
637
|
+
if ($[114] !== labelId || $[115] !== loading || $[116] !== t41 || $[117] !== t42 || $[118] !== trailingVisual) {
|
|
638
|
+
t43 = /*#__PURE__*/jsx(VisualOrIndicator, {
|
|
639
|
+
inactiveText: t41,
|
|
640
|
+
itemHasLeadingVisual: t42,
|
|
641
|
+
labelId: labelId,
|
|
642
|
+
loading: loading,
|
|
643
|
+
position: "trailing",
|
|
644
|
+
children: trailingVisual
|
|
645
|
+
});
|
|
646
|
+
$[114] = labelId;
|
|
647
|
+
$[115] = loading;
|
|
648
|
+
$[116] = t41;
|
|
649
|
+
$[117] = t42;
|
|
650
|
+
$[118] = trailingVisual;
|
|
651
|
+
$[119] = t43;
|
|
652
|
+
} else {
|
|
653
|
+
t43 = $[119];
|
|
654
|
+
}
|
|
655
|
+
let t44;
|
|
656
|
+
if ($[120] !== inactiveText || $[121] !== inactiveWarningId || $[122] !== showInactiveIndicator) {
|
|
657
|
+
t44 = !showInactiveIndicator && inactiveText ? /*#__PURE__*/jsx("span", {
|
|
658
|
+
className: classes.InactiveWarning,
|
|
659
|
+
id: inactiveWarningId,
|
|
660
|
+
children: inactiveText
|
|
661
|
+
}) : null;
|
|
662
|
+
$[120] = inactiveText;
|
|
663
|
+
$[121] = inactiveWarningId;
|
|
664
|
+
$[122] = showInactiveIndicator;
|
|
665
|
+
$[123] = t44;
|
|
666
|
+
} else {
|
|
667
|
+
t44 = $[123];
|
|
668
|
+
}
|
|
669
|
+
let t45;
|
|
670
|
+
if ($[124] !== t40 || $[125] !== t43 || $[126] !== t44) {
|
|
671
|
+
t45 = /*#__PURE__*/jsxs("span", {
|
|
672
|
+
className: classes.ActionListSubContent,
|
|
673
|
+
"data-component": "ActionList.Item--DividerContainer",
|
|
674
|
+
children: [t40, t43, t44]
|
|
675
|
+
});
|
|
676
|
+
$[124] = t40;
|
|
677
|
+
$[125] = t43;
|
|
678
|
+
$[126] = t44;
|
|
679
|
+
$[127] = t45;
|
|
680
|
+
} else {
|
|
681
|
+
t45 = $[127];
|
|
682
|
+
}
|
|
683
|
+
let t46;
|
|
684
|
+
if ($[128] !== ItemWrapper || $[129] !== forwardedRef || $[130] !== size || $[131] !== t33 || $[132] !== t36 || $[133] !== t45 || $[134] !== wrapperProps) {
|
|
685
|
+
t46 = /*#__PURE__*/jsxs(ItemWrapper, {
|
|
686
|
+
...wrapperProps,
|
|
687
|
+
className: classes.ActionListContent,
|
|
688
|
+
"data-size": size,
|
|
689
|
+
ref: forwardedRef,
|
|
690
|
+
children: [t32, t33, t36, t45]
|
|
691
|
+
});
|
|
692
|
+
$[128] = ItemWrapper;
|
|
693
|
+
$[129] = forwardedRef;
|
|
694
|
+
$[130] = size;
|
|
695
|
+
$[131] = t33;
|
|
696
|
+
$[132] = t36;
|
|
697
|
+
$[133] = t45;
|
|
698
|
+
$[134] = wrapperProps;
|
|
699
|
+
$[135] = t46;
|
|
700
|
+
} else {
|
|
701
|
+
t46 = $[135];
|
|
702
|
+
}
|
|
703
|
+
const t47 = !inactive && !loading && !menuContext && Boolean(slots.trailingAction) && slots.trailingAction;
|
|
704
|
+
let t48;
|
|
705
|
+
if ($[136] !== containerProps || $[137] !== slots.subItem || $[138] !== t25 || $[139] !== t26 || $[140] !== t27 || $[141] !== t28 || $[142] !== t29 || $[143] !== t30 || $[144] !== t31 || $[145] !== t46 || $[146] !== t47) {
|
|
706
|
+
t48 = /*#__PURE__*/jsxs("li", {
|
|
275
707
|
...containerProps,
|
|
276
|
-
ref:
|
|
277
|
-
"data-variant":
|
|
278
|
-
"data-active":
|
|
279
|
-
"data-inactive":
|
|
280
|
-
"data-has-subitem":
|
|
281
|
-
"data-has-description":
|
|
282
|
-
className:
|
|
283
|
-
children: [
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
children: "Loading"
|
|
314
|
-
})]
|
|
315
|
-
}), slots.description]
|
|
316
|
-
}), /*#__PURE__*/jsx(VisualOrIndicator, {
|
|
317
|
-
inactiveText: showInactiveIndicator ? inactiveText : undefined,
|
|
318
|
-
itemHasLeadingVisual: Boolean(slots.leadingVisual),
|
|
319
|
-
labelId: labelId,
|
|
320
|
-
loading: loading,
|
|
321
|
-
position: "trailing",
|
|
322
|
-
children: trailingVisual
|
|
323
|
-
}),
|
|
324
|
-
// If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
|
|
325
|
-
// render the inactive warning message directly in the item.
|
|
326
|
-
!showInactiveIndicator && inactiveText ? /*#__PURE__*/jsx("span", {
|
|
327
|
-
className: classes.InactiveWarning,
|
|
328
|
-
id: inactiveWarningId,
|
|
329
|
-
children: inactiveText
|
|
330
|
-
}) : null]
|
|
331
|
-
})]
|
|
332
|
-
}), !inactive && !loading && !menuContext && Boolean(slots.trailingAction) && slots.trailingAction, slots.subItem]
|
|
333
|
-
})
|
|
334
|
-
});
|
|
708
|
+
ref: t25,
|
|
709
|
+
"data-variant": t26,
|
|
710
|
+
"data-active": t27,
|
|
711
|
+
"data-inactive": t28,
|
|
712
|
+
"data-has-subitem": t29,
|
|
713
|
+
"data-has-description": t30,
|
|
714
|
+
className: t31,
|
|
715
|
+
children: [t46, t47, slots.subItem]
|
|
716
|
+
});
|
|
717
|
+
$[136] = containerProps;
|
|
718
|
+
$[137] = slots.subItem;
|
|
719
|
+
$[138] = t25;
|
|
720
|
+
$[139] = t26;
|
|
721
|
+
$[140] = t27;
|
|
722
|
+
$[141] = t28;
|
|
723
|
+
$[142] = t29;
|
|
724
|
+
$[143] = t30;
|
|
725
|
+
$[144] = t31;
|
|
726
|
+
$[145] = t46;
|
|
727
|
+
$[146] = t47;
|
|
728
|
+
$[147] = t48;
|
|
729
|
+
} else {
|
|
730
|
+
t48 = $[147];
|
|
731
|
+
}
|
|
732
|
+
let t49;
|
|
733
|
+
if ($[148] !== itemContextValue || $[149] !== t48) {
|
|
734
|
+
t49 = /*#__PURE__*/jsx(ItemContext.Provider, {
|
|
735
|
+
value: itemContextValue,
|
|
736
|
+
children: t48
|
|
737
|
+
});
|
|
738
|
+
$[148] = itemContextValue;
|
|
739
|
+
$[149] = t48;
|
|
740
|
+
$[150] = t49;
|
|
741
|
+
} else {
|
|
742
|
+
t49 = $[150];
|
|
743
|
+
}
|
|
744
|
+
return t49;
|
|
335
745
|
};
|
|
336
|
-
UnwrappedItem.displayName = "UnwrappedItem";
|
|
337
746
|
const Item = Object.assign(fixedForwardRef(UnwrappedItem), {
|
|
338
747
|
displayName: 'ActionList.Item',
|
|
339
748
|
__SLOT__: Symbol('ActionList.Item')
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/ActionList/List.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAA;
|
|
1
|
+
{"version":3,"file":"List.d.ts","sourceRoot":"","sources":["../../src/ActionList/List.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAiB,MAAM,OAAO,CAAA;AAuFrC,QAAA,MAAM,IAAI,GA3Ea,EAAE,SAAS,KAAK,CAAC,WAAW;;;;;;;;;;;;;;;;;;;;oDA2ER,CAAA;AAI3C,OAAO,EAAC,IAAI,EAAC,CAAA"}
|
package/dist/ActionList/List.js
CHANGED
|
@@ -131,6 +131,7 @@ const UnwrappedList = (props, forwardedRef) => {
|
|
|
131
131
|
} else {
|
|
132
132
|
t9 = $[20];
|
|
133
133
|
}
|
|
134
|
+
const listContextValue = t9;
|
|
134
135
|
const t10 = slots.heading;
|
|
135
136
|
let t11;
|
|
136
137
|
if ($[21] !== className) {
|
|
@@ -166,14 +167,14 @@ const UnwrappedList = (props, forwardedRef) => {
|
|
|
166
167
|
t12 = $[32];
|
|
167
168
|
}
|
|
168
169
|
let t13;
|
|
169
|
-
if ($[33] !==
|
|
170
|
+
if ($[33] !== listContextValue || $[34] !== slots.heading || $[35] !== t12) {
|
|
170
171
|
t13 = /*#__PURE__*/jsxs(ListContext.Provider, {
|
|
171
|
-
value:
|
|
172
|
+
value: listContextValue,
|
|
172
173
|
children: [t10, t12]
|
|
173
174
|
});
|
|
174
|
-
$[33] =
|
|
175
|
-
$[34] =
|
|
176
|
-
$[35] =
|
|
175
|
+
$[33] = listContextValue;
|
|
176
|
+
$[34] = slots.heading;
|
|
177
|
+
$[35] = t12;
|
|
177
178
|
$[36] = t13;
|
|
178
179
|
} else {
|
|
179
180
|
t13 = $[36];
|
package/dist/hooks/useSlots.d.ts
CHANGED
|
@@ -1,56 +1,8 @@
|
|
|
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;
|
|
51
2
|
type ComponentMatcher = React.ElementType<Props>;
|
|
52
3
|
type ComponentAndPropsMatcher = [ComponentMatcher, (props: Props) => boolean];
|
|
53
4
|
export type SlotConfig = Record<string, ComponentMatcher | ComponentAndPropsMatcher>;
|
|
5
|
+
type Props = any;
|
|
54
6
|
type SlotElements<Config extends SlotConfig> = {
|
|
55
7
|
[Property in keyof Config]: SlotValue<Config, Property>;
|
|
56
8
|
};
|
|
@@ -58,7 +10,11 @@ type SlotValue<Config, Property extends keyof Config> = Config[Property] extends
|
|
|
58
10
|
infer ElementType extends React.ElementType,
|
|
59
11
|
infer _testFn
|
|
60
12
|
] ? React.ReactElement<React.ComponentPropsWithoutRef<ElementType>, ElementType> : never;
|
|
61
|
-
/**
|
|
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
|
+
*/
|
|
62
18
|
export declare function useSlots<Config extends SlotConfig>(children: React.ReactNode, config: Config): [Partial<SlotElements<Config>>, React.ReactNode[]];
|
|
63
19
|
export {};
|
|
64
20
|
//# 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;AAOzB,KAAK,gBAAgB,GAAG,KAAK,CAAC,WAAW,CAAC,KAAK,CAAC,CAAA;AAEhD,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;AAIpF,KAAK,KAAK,GAAG,GAAG,CAAA;AAEhB,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;;;;GAIG;AACH,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,CA8CpD"}
|
package/dist/hooks/useSlots.js
CHANGED
|
@@ -2,85 +2,29 @@ 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
|
-
|
|
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
|
-
*/
|
|
5
|
+
// slot config allows 2 options:
|
|
6
|
+
// 1. Component to match, example: { leadingVisual: LeadingVisual }
|
|
53
7
|
|
|
54
|
-
//
|
|
8
|
+
// 2. Component to match + a test function, example: { blockDescription: [Description, props => props.variant === 'block'] }
|
|
55
9
|
|
|
10
|
+
// We don't know what the props are yet, we set them later based on slot config
|
|
56
11
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
57
12
|
|
|
58
|
-
//
|
|
59
|
-
|
|
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
|
-
}
|
|
68
|
-
|
|
69
|
-
// --- Hook ---
|
|
13
|
+
// useful for narrowing types, third option is not possible
|
|
70
14
|
|
|
71
|
-
/**
|
|
15
|
+
/**
|
|
16
|
+
* Extract components from `children` so we can render them in different places,
|
|
17
|
+
* allowing us to implement components with SSR-compatible slot APIs.
|
|
18
|
+
* Note: We can only extract direct children, not nested ones.
|
|
19
|
+
*/
|
|
72
20
|
function useSlots(children, config) {
|
|
21
|
+
// Object mapping slot names to their elements
|
|
22
|
+
const slots = mapValues(config, () => undefined);
|
|
23
|
+
|
|
24
|
+
// Array of elements that are not slots
|
|
73
25
|
const rest = [];
|
|
74
26
|
const keys = Object.keys(config);
|
|
75
27
|
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;
|
|
84
28
|
|
|
85
29
|
// eslint-disable-next-line github/array-foreach
|
|
86
30
|
React.Children.forEach(children, child => {
|
|
@@ -88,63 +32,41 @@ function useSlots(children, config) {
|
|
|
88
32
|
rest.push(child);
|
|
89
33
|
return;
|
|
90
34
|
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
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);
|
|
96
41
|
}
|
|
97
|
-
|
|
98
|
-
return;
|
|
99
|
-
}
|
|
42
|
+
});
|
|
100
43
|
|
|
101
|
-
//
|
|
102
|
-
|
|
103
|
-
if (matchedIndex === -1) {
|
|
44
|
+
// If the child is not a slot, add it to the `rest` array
|
|
45
|
+
if (index === -1) {
|
|
104
46
|
rest.push(child);
|
|
105
47
|
return;
|
|
106
48
|
}
|
|
107
|
-
const slotKey = keys[
|
|
49
|
+
const slotKey = keys[index];
|
|
108
50
|
|
|
109
|
-
//
|
|
110
|
-
if (slots[slotKey]
|
|
111
|
-
|
|
112
|
-
process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(slotKey)}" slot. Only the first will be rendered.`) : void 0;
|
|
113
|
-
}
|
|
51
|
+
// If slot is already filled, ignore duplicates
|
|
52
|
+
if (slots[slotKey]) {
|
|
53
|
+
process.env.NODE_ENV !== "production" ? warning(true, `Found duplicate "${String(slotKey)}" slot. Only the first will be rendered.`) : void 0;
|
|
114
54
|
return;
|
|
115
55
|
}
|
|
56
|
+
|
|
57
|
+
// If the child is a slot, add it to the `slots` object
|
|
58
|
+
|
|
116
59
|
slots[slotKey] = child;
|
|
117
|
-
slotsFound++;
|
|
118
60
|
});
|
|
119
61
|
return [slots, rest];
|
|
120
62
|
}
|
|
121
63
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
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;
|
|
64
|
+
/** Map the values of an object */
|
|
65
|
+
function mapValues(obj, fn) {
|
|
66
|
+
return Object.keys(obj).reduce((result, key) => {
|
|
67
|
+
result[key] = fn(obj[key]);
|
|
68
|
+
return result;
|
|
69
|
+
}, {});
|
|
148
70
|
}
|
|
149
71
|
|
|
150
72
|
export { useSlots };
|
package/package.json
CHANGED