@primer/react 0.0.0-20260223214708 → 0.0.0-20260223221323

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (76) hide show
  1. package/CHANGELOG.md +2 -38
  2. package/dist/ActionBar/ActionBar.d.ts.map +1 -1
  3. package/dist/ActionBar/ActionBar.js +302 -396
  4. package/dist/ActionList/ActionList-f4ac3b54.css +2 -0
  5. package/dist/ActionList/ActionList-f4ac3b54.css.map +1 -0
  6. package/dist/ActionList/ActionList.module.css.js +1 -1
  7. package/dist/ActionList/Item.d.ts.map +1 -1
  8. package/dist/ActionList/Item.js +0 -1
  9. package/dist/Autocomplete/Autocomplete.js +159 -76
  10. package/dist/Autocomplete/AutocompleteMenu.js +333 -128
  11. package/dist/Autocomplete/AutocompleteOverlay.js +130 -49
  12. package/dist/Banner/Banner.js +238 -64
  13. package/dist/Blankslate/{Blankslate-a039d79a.css → Blankslate-f5a9755a.css} +2 -2
  14. package/dist/Blankslate/Blankslate-f5a9755a.css.map +1 -0
  15. package/dist/Blankslate/Blankslate.module.css.js +1 -1
  16. package/dist/Button/ButtonBase.d.ts.map +1 -1
  17. package/dist/Button/ButtonBase.js +14 -9
  18. package/dist/Checkbox/Checkbox.js +163 -55
  19. package/dist/Dialog/Dialog.js +347 -105
  20. package/dist/FilteredActionList/FilteredActionList-f6c2dc7a.css +2 -0
  21. package/dist/FilteredActionList/FilteredActionList-f6c2dc7a.css.map +1 -0
  22. package/dist/FilteredActionList/FilteredActionList.d.ts +1 -16
  23. package/dist/FilteredActionList/FilteredActionList.d.ts.map +1 -1
  24. package/dist/FilteredActionList/FilteredActionList.js +42 -147
  25. package/dist/FilteredActionList/FilteredActionList.module.css.js +2 -2
  26. package/dist/Overlay/Overlay-43cda449.css +2 -0
  27. package/dist/Overlay/Overlay-43cda449.css.map +1 -0
  28. package/dist/Overlay/Overlay.module.css.js +1 -1
  29. package/dist/PageLayout/PageLayout-cb491b47.css +2 -0
  30. package/dist/PageLayout/PageLayout-cb491b47.css.map +1 -0
  31. package/dist/PageLayout/PageLayout.d.ts +2 -72
  32. package/dist/PageLayout/PageLayout.d.ts.map +1 -1
  33. package/dist/PageLayout/PageLayout.js +1235 -750
  34. package/dist/PageLayout/PageLayout.module.css.js +2 -2
  35. package/dist/PageLayout/usePaneWidth.d.ts +6 -18
  36. package/dist/PageLayout/usePaneWidth.d.ts.map +1 -1
  37. package/dist/PageLayout/usePaneWidth.js +112 -126
  38. package/dist/SelectPanel/SelectPanel.d.ts +1 -1
  39. package/dist/SelectPanel/SelectPanel.d.ts.map +1 -1
  40. package/dist/SelectPanel/SelectPanel.js +33 -85
  41. package/dist/SplitPageLayout/SplitPageLayout.d.ts +1 -4
  42. package/dist/SplitPageLayout/SplitPageLayout.d.ts.map +1 -1
  43. package/dist/SplitPageLayout/SplitPageLayout.js +2 -54
  44. package/dist/Text/Text.d.ts +1 -1
  45. package/dist/Text/Text.d.ts.map +1 -1
  46. package/dist/Text/Text.js +13 -10
  47. package/dist/UnderlineNav/UnderlineNavItem.js +149 -56
  48. package/dist/experimental/SelectPanel2/SelectPanel-1f8c23b5.css +2 -0
  49. package/dist/experimental/SelectPanel2/{SelectPanel-f0c4b9ca.css.map → SelectPanel-1f8c23b5.css.map} +1 -1
  50. package/dist/experimental/SelectPanel2/SelectPanel.js +593 -209
  51. package/dist/experimental/SelectPanel2/SelectPanel.module.css.js +1 -1
  52. package/dist/hooks/useRefObjectAsForwardedRef.d.ts.map +1 -1
  53. package/dist/hooks/useRefObjectAsForwardedRef.js +2 -10
  54. package/dist/hooks/useScrollFlash.d.ts.map +1 -1
  55. package/dist/hooks/useScrollFlash.js +22 -14
  56. package/dist/hooks/useSlots.d.ts +6 -50
  57. package/dist/hooks/useSlots.d.ts.map +1 -1
  58. package/dist/hooks/useSlots.js +36 -114
  59. package/dist/live-region/Announce.d.ts.map +1 -1
  60. package/dist/live-region/Announce.js +4 -7
  61. package/dist/utils/descendant-registry.d.ts +29 -0
  62. package/dist/utils/descendant-registry.d.ts.map +1 -0
  63. package/dist/utils/descendant-registry.js +188 -0
  64. package/generated/components.json +5 -197
  65. package/package.json +4 -4
  66. package/dist/ActionList/ActionList-c04a02d6.css +0 -2
  67. package/dist/ActionList/ActionList-c04a02d6.css.map +0 -1
  68. package/dist/Blankslate/Blankslate-a039d79a.css.map +0 -1
  69. package/dist/FilteredActionList/FilteredActionList-02db90c6.css +0 -2
  70. package/dist/FilteredActionList/FilteredActionList-02db90c6.css.map +0 -1
  71. package/dist/Overlay/Overlay-15519c09.css +0 -2
  72. package/dist/Overlay/Overlay-15519c09.css.map +0 -1
  73. package/dist/PageLayout/PageLayout-3444a142.css +0 -2
  74. package/dist/PageLayout/PageLayout-3444a142.css.map +0 -1
  75. package/dist/experimental/SelectPanel2/SelectPanel-f0c4b9ca.css +0 -2
  76. package/dist/utils/environment.js +0 -9
@@ -1,4 +1,4 @@
1
- import './SelectPanel-f0c4b9ca.css';
1
+ import './SelectPanel-1f8c23b5.css';
2
2
 
3
3
  var classes = {"Overlay":"prc-SelectPanel2-Overlay--Q-FI","Form":"prc-SelectPanel2-Form-bZ9HS","Container":"prc-SelectPanel2-Container-e5e6-","HeaderContent":"prc-SelectPanel2-HeaderContent-MsaAS","TitleWrapper":"prc-SelectPanel2-TitleWrapper-HzPu3","TextInput":"prc-SelectPanel2-TextInput-lHH1n","Checkbox":"prc-SelectPanel2-Checkbox-AYR38","FlexBox":"prc-SelectPanel2-FlexBox-gWPRg","Title":"prc-SelectPanel2-Title-T-h3f","Description":"prc-SelectPanel2-Description-qTXfi","ClearAction":"prc-SelectPanel2-ClearAction-tQj-f","Footer":"prc-SelectPanel2-Footer-TibV0","FooterContent":"prc-SelectPanel2-FooterContent-UjAOM","FooterActions":"prc-SelectPanel2-FooterActions-T6yQR","SecondaryCheckbox":"prc-SelectPanel2-SecondaryCheckbox-omkf-","SmallText":"prc-SelectPanel2-SmallText-c42ay","SelectPanelLoading":"prc-SelectPanel2-SelectPanelLoading-mtyhD","LoadingText":"prc-SelectPanel2-LoadingText-DB0wN","MessageFull":"prc-SelectPanel2-MessageFull-nY-qF","Octicon":"prc-SelectPanel2-Octicon-zt-zU","Error":"prc-SelectPanel2-Error-ZrZQQ","Warning":"prc-SelectPanel2-Warning-PDsVF","MessageTitle":"prc-SelectPanel2-MessageTitle-T7v9d","MessageContent":"prc-SelectPanel2-MessageContent-UZ9vY","MessageInline":"prc-SelectPanel2-MessageInline-sErQf","Header":"prc-SelectPanel2-Header-LKyEJ"};
4
4
 
@@ -1 +1 @@
1
- {"version":3,"file":"useRefObjectAsForwardedRef.d.ts","sourceRoot":"","sources":["../../src/hooks/useRefObjectAsForwardedRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,OAAO,CAAA;AAGlD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAIjH"}
1
+ {"version":3,"file":"useRefObjectAsForwardedRef.d.ts","sourceRoot":"","sources":["../../src/hooks/useRefObjectAsForwardedRef.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAC,YAAY,EAAE,SAAS,EAAC,MAAM,OAAO,CAAA;AAGlD;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CAAC,CAAC,EAAE,YAAY,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,SAAS,CAAC,CAAC,GAAG,IAAI,CAAC,GAAG,IAAI,CAEjH"}
@@ -9,7 +9,7 @@ import { useImperativeHandle } from 'react';
9
9
  * **NOTE**: The `refObject` should be passed to the underlying element, NOT the `forwardedRef`.
10
10
  */
11
11
  function useRefObjectAsForwardedRef(forwardedRef, refObject) {
12
- const $ = c(4);
12
+ const $ = c(2);
13
13
  let t0;
14
14
  if ($[0] !== refObject.current) {
15
15
  t0 = () => refObject.current;
@@ -18,15 +18,7 @@ function useRefObjectAsForwardedRef(forwardedRef, refObject) {
18
18
  } else {
19
19
  t0 = $[1];
20
20
  }
21
- let t1;
22
- if ($[2] !== refObject) {
23
- t1 = [refObject];
24
- $[2] = refObject;
25
- $[3] = t1;
26
- } else {
27
- t1 = $[3];
28
- }
29
- useImperativeHandle(forwardedRef, t0, t1);
21
+ useImperativeHandle(forwardedRef, t0);
30
22
  }
31
23
 
32
24
  export { useRefObjectAsForwardedRef };
@@ -1 +1 @@
1
- {"version":3,"file":"useScrollFlash.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollFlash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,kBAAkB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,QAoB7F"}
1
+ {"version":3,"file":"useScrollFlash.d.ts","sourceRoot":"","sources":["../../src/hooks/useScrollFlash.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAE9B;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,kBAAkB,EAAE,KAAK,CAAC,SAAS,CAAC,WAAW,GAAG,IAAI,CAAC,QAe7F"}
@@ -1,3 +1,4 @@
1
+ import { c } from 'react-compiler-runtime';
1
2
  import { useEffect } from 'react';
2
3
 
3
4
  /**
@@ -5,23 +6,30 @@ import { useEffect } from 'react';
5
6
  * @param scrollContainerRef The ref of the scrollable content
6
7
  */
7
8
  function useScrollFlash(scrollContainerRef) {
8
- // https://adxlv.computer/projects/flash-scrollers/
9
- useEffect(() => {
10
- const scrollContainer = scrollContainerRef.current;
11
- if (!scrollContainer) {
12
- return;
13
- }
14
-
15
- // Defer to the next frame to avoid forcing a synchronous reflow
16
- // when the effect runs immediately after React commits DOM changes.
17
- const id = requestAnimationFrame(() => {
9
+ const $ = c(3);
10
+ let t0;
11
+ let t1;
12
+ if ($[0] !== scrollContainerRef) {
13
+ t0 = () => {
14
+ const scrollContainer = scrollContainerRef.current;
15
+ if (!scrollContainer) {
16
+ return;
17
+ }
18
18
  const currentScroll = scrollContainer.scrollTop;
19
- const altScroll = currentScroll < 1 ? currentScroll + 1 : currentScroll - 1;
19
+ const maxScroll = scrollContainer.scrollHeight;
20
+ const altScroll = currentScroll < Math.min(1, maxScroll) ? currentScroll + 1 : currentScroll - 1;
20
21
  scrollContainer.scrollTop = altScroll;
21
22
  scrollContainer.scrollTop = currentScroll;
22
- });
23
- return () => cancelAnimationFrame(id);
24
- }, [scrollContainerRef]);
23
+ };
24
+ t1 = [scrollContainerRef];
25
+ $[0] = scrollContainerRef;
26
+ $[1] = t0;
27
+ $[2] = t1;
28
+ } else {
29
+ t0 = $[1];
30
+ t1 = $[2];
31
+ }
32
+ useEffect(t0, t1);
25
33
  }
26
34
 
27
35
  export { useScrollFlash as default };
@@ -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
- /** Extract slot components from children. See file header for details. */
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;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"}
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"}
@@ -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
- * 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
- */
5
+ // slot config allows 2 options:
6
+ // 1. Component to match, example: { leadingVisual: LeadingVisual }
53
7
 
54
- // --- Types ---
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
- // --- Matching ---
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
- /** Extract slot components from children. See file header for details. */
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
- // 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;
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
- rest.push(child);
98
- return;
99
- }
42
+ });
100
43
 
101
- // Try to match child against a slot
102
- const matchedIndex = findMatchingSlot(child, values, totalSlots);
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[matchedIndex];
49
+ const slotKey = keys[index];
108
50
 
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
- }
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
- // --- 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;
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 };
@@ -1 +1 @@
1
- {"version":3,"file":"Announce.d.ts","sourceRoot":"","sources":["../../src/live-region/Announce.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAA;AAEjE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,IAAI,gBAAgB,CACxE,EAAE,EACF,KAAK,EACL;IACE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CACpC,CACF,CAAA;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,qBAwGtF"}
1
+ {"version":3,"file":"Announce.d.ts","sourceRoot":"","sources":["../../src/live-region/Announce.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAA;AAI9B,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,6BAA6B,CAAA;AAEjE,MAAM,MAAM,aAAa,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,IAAI,gBAAgB,CACxE,EAAE,EACF,KAAK,EACL;IACE;;;;OAIG;IACH,cAAc,CAAC,EAAE,OAAO,CAAA;IAExB;;;OAGG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAEhB;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,CAAA;IAEhB;;;OAGG;IACH,UAAU,CAAC,EAAE,WAAW,GAAG,QAAQ,CAAA;CACpC,CACF,CAAA;AAED;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,KAAK,EAAE,KAAK,EAAE,aAAa,CAAC,EAAE,CAAC,qBAgGtF"}
@@ -66,13 +66,6 @@ function Announce(props) {
66
66
  if (hidden) {
67
67
  return;
68
68
  }
69
- const textContent = getTextContent(element);
70
- if (!textContent) {
71
- return;
72
- }
73
- if (textContent === previousAnnouncementText) {
74
- return;
75
- }
76
69
  const style = window.getComputedStyle(element);
77
70
  if (style.display === "none") {
78
71
  return;
@@ -80,6 +73,10 @@ function Announce(props) {
80
73
  if (style.visibility === "hidden") {
81
74
  return;
82
75
  }
76
+ const textContent = getTextContent(element);
77
+ if (textContent === previousAnnouncementText) {
78
+ return;
79
+ }
83
80
  (_savedAnnouncement$cu = savedAnnouncement.current) === null || _savedAnnouncement$cu === void 0 ? void 0 : _savedAnnouncement$cu.cancel();
84
81
  savedAnnouncement.current = announceFromElement(element, politeness === "assertive" ? {
85
82
  politeness
@@ -0,0 +1,29 @@
1
+ import { type Dispatch, type ReactNode } from 'react';
2
+ interface ProviderProps<T> {
3
+ children: ReactNode;
4
+ /** State setter from `useRegistryState`. */
5
+ setRegistry: Dispatch<React.SetStateAction<Map<string, T>>>;
6
+ }
7
+ /**
8
+ * Create a "descendant registry" for a component. This allows a parent to store and track an ordered registry of
9
+ * child components, even if they are deeply nested in the tree. For example, a menu component can use this to track
10
+ * every menu item inside of it, including menu items inside of fragments and subcomponents. The order of the resulting
11
+ * `Map` will match the render order in the React tree.
12
+ *
13
+ * Usage:
14
+ * 1. Create a registry at the file level in a similar manner to creating a new React context. Set `T` to the data type
15
+ * of the registry - this can be anything **except** a function.
16
+ * 2. In the parent component, instantiate the registry state via `useRegistryState`. Then wrap `children` in the
17
+ * registry context `Provider` with `setRegistry` set to the state setter function.
18
+ * 3. Register child components via `useRegisterDescendant` or `useRegisterDescendantCallback`.
19
+ * 4. Access the registered data using the value from `useRegistryState`. This will be a map of `string` to `T`, where
20
+ * the string key is a unique and stable identifier for each component which can be used as a `key` if necessary.
21
+ */
22
+ export declare function createDescendantRegistry<T>(): {
23
+ Provider: ({ children, setRegistry }: ProviderProps<T>) => import("react").JSX.Element;
24
+ useRegistryState: () => [Map<string, T>, Dispatch<import("react").SetStateAction<Map<string, T>>>];
25
+ useRegisterDescendant: (value: T) => string;
26
+ useRegisterDescendantCallback: (valueCallback: () => T) => string;
27
+ };
28
+ export {};
29
+ //# sourceMappingURL=descendant-registry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"descendant-registry.d.ts","sourceRoot":"","sources":["../../src/utils/descendant-registry.tsx"],"names":[],"mappings":"AAAA,OAAO,EASL,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAGd,UAAU,aAAa,CAAC,CAAC;IACvB,QAAQ,EAAE,SAAS,CAAA;IACnB,4CAA4C;IAC5C,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,MAAM,EAAE,CAAC,CAAC,CAAC,CAAC,CAAA;CAC5D;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,wBAAwB,CAAC,CAAC;0CAsCG,aAAa,CAAC,CAAC,CAAC;;mCAPrB,CAAC;mDAXe,MAAM,CAAC;EAyE9D"}
@@ -0,0 +1,188 @@
1
+ import { c } from 'react-compiler-runtime';
2
+ import { useContext, useId, useEffect, useState, useRef, createContext } from 'react';
3
+ import useIsomorphicLayoutEffect from './useIsomorphicLayoutEffect.js';
4
+ import { jsx } from 'react/jsx-runtime';
5
+
6
+ /**
7
+ * Create a "descendant registry" for a component. This allows a parent to store and track an ordered registry of
8
+ * child components, even if they are deeply nested in the tree. For example, a menu component can use this to track
9
+ * every menu item inside of it, including menu items inside of fragments and subcomponents. The order of the resulting
10
+ * `Map` will match the render order in the React tree.
11
+ *
12
+ * Usage:
13
+ * 1. Create a registry at the file level in a similar manner to creating a new React context. Set `T` to the data type
14
+ * of the registry - this can be anything **except** a function.
15
+ * 2. In the parent component, instantiate the registry state via `useRegistryState`. Then wrap `children` in the
16
+ * registry context `Provider` with `setRegistry` set to the state setter function.
17
+ * 3. Register child components via `useRegisterDescendant` or `useRegisterDescendantCallback`.
18
+ * 4. Access the registered data using the value from `useRegistryState`. This will be a map of `string` to `T`, where
19
+ * the string key is a unique and stable identifier for each component which can be used as a `key` if necessary.
20
+ */
21
+ function createDescendantRegistry() {
22
+ const Context = /*#__PURE__*/createContext({
23
+ register: () => () => {},
24
+ key: -1
25
+ });
26
+
27
+ /** Instantiate descendant registry state. */
28
+ function useRegistryState() {
29
+ return useState(_temp);
30
+ }
31
+
32
+ /**
33
+ * Register a descendant component with the registry, using a callback to get the data. Use this instead of
34
+ * `useRegisterDescendant` when you need to access a ref value or do some calculation to get the data that you want
35
+ * to register. The callback will be called during the effect phase. Ensure the callback is stable (`useCallback`).
36
+ */
37
+ function _temp() {
38
+ return new Map();
39
+ }
40
+ function useRegisterDescendantCallback(valueCallback) {
41
+ const $ = c(9);
42
+ const {
43
+ register,
44
+ key
45
+ } = useContext(Context);
46
+ const id = useId();
47
+ let t0;
48
+ if ($[0] !== id || $[1] !== register || $[2] !== valueCallback) {
49
+ t0 = () => register(id, valueCallback());
50
+ $[0] = id;
51
+ $[1] = register;
52
+ $[2] = valueCallback;
53
+ $[3] = t0;
54
+ } else {
55
+ t0 = $[3];
56
+ }
57
+ let t1;
58
+ if ($[4] !== id || $[5] !== key || $[6] !== register || $[7] !== valueCallback) {
59
+ t1 = [register, id, valueCallback, key];
60
+ $[4] = id;
61
+ $[5] = key;
62
+ $[6] = register;
63
+ $[7] = valueCallback;
64
+ $[8] = t1;
65
+ } else {
66
+ t1 = $[8];
67
+ }
68
+ useEffect(t0, t1);
69
+ return id;
70
+ }
71
+
72
+ /** Simplified version of `useRegisterDescendantCallback` that allows directly passing a memoized value. */
73
+ function useRegisterDescendant(value) {
74
+ const $ = c(2);
75
+ let t0;
76
+ if ($[0] !== value) {
77
+ t0 = () => value;
78
+ $[0] = value;
79
+ $[1] = t0;
80
+ } else {
81
+ t0 = $[1];
82
+ }
83
+ const valueCallback = t0;
84
+ return useRegisterDescendantCallback(valueCallback);
85
+ }
86
+
87
+ /** Provide context for registering descendant components. This only needs to wrap `children`. */
88
+ function Provider(t0) {
89
+ const $ = c(9);
90
+ const {
91
+ children,
92
+ setRegistry
93
+ } = t0;
94
+ const workingRegistryRef = useRef("queued");
95
+ const [key, setKey] = useState(0);
96
+ let t1;
97
+ if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
98
+ t1 = function instantiateNewRegistry() {
99
+ if (workingRegistryRef.current === "queued") {
100
+ workingRegistryRef.current = new Map();
101
+ }
102
+ };
103
+ $[0] = t1;
104
+ } else {
105
+ t1 = $[0];
106
+ }
107
+ useIsomorphicLayoutEffect(t1);
108
+ let t2;
109
+ if ($[1] === Symbol.for("react.memo_cache_sentinel")) {
110
+ t2 = (id, value) => {
111
+ const queueRebuild = function queueRebuild() {
112
+ workingRegistryRef.current = "queued";
113
+ setKey(_temp2);
114
+ };
115
+ if (workingRegistryRef.current instanceof Map) {
116
+ workingRegistryRef.current.set(id, value);
117
+ } else {
118
+ if (workingRegistryRef.current === "idle") {
119
+ queueRebuild();
120
+ }
121
+ }
122
+ return () => {
123
+ if (workingRegistryRef.current instanceof Map) {
124
+ workingRegistryRef.current.delete(id);
125
+ } else {
126
+ if (workingRegistryRef.current === "idle") {
127
+ queueRebuild();
128
+ }
129
+ }
130
+ };
131
+ };
132
+ $[1] = t2;
133
+ } else {
134
+ t2 = $[1];
135
+ }
136
+ const register = t2;
137
+ let t3;
138
+ if ($[2] !== setRegistry) {
139
+ t3 = function commitWorkingRegistry() {
140
+ if (workingRegistryRef.current instanceof Map) {
141
+ setRegistry(workingRegistryRef.current);
142
+ workingRegistryRef.current = "idle";
143
+ }
144
+ };
145
+ $[2] = setRegistry;
146
+ $[3] = t3;
147
+ } else {
148
+ t3 = $[3];
149
+ }
150
+ useEffect(t3);
151
+ let t4;
152
+ if ($[4] !== key) {
153
+ t4 = {
154
+ register,
155
+ key
156
+ };
157
+ $[4] = key;
158
+ $[5] = t4;
159
+ } else {
160
+ t4 = $[5];
161
+ }
162
+ const contextValue = t4;
163
+ let t5;
164
+ if ($[6] !== children || $[7] !== contextValue) {
165
+ t5 = /*#__PURE__*/jsx(Context.Provider, {
166
+ value: contextValue,
167
+ children: children
168
+ });
169
+ $[6] = children;
170
+ $[7] = contextValue;
171
+ $[8] = t5;
172
+ } else {
173
+ t5 = $[8];
174
+ }
175
+ return t5;
176
+ }
177
+ function _temp2(prev) {
178
+ return prev + 1;
179
+ }
180
+ return {
181
+ Provider,
182
+ useRegistryState,
183
+ useRegisterDescendant,
184
+ useRegisterDescendantCallback
185
+ };
186
+ }
187
+
188
+ export { createDescendantRegistry };