@primer/react 0.0.0-20260302165340 → 0.0.0-20260302192736

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.
@@ -15,8 +15,44 @@ 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';
18
19
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
19
20
 
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
+ }
20
56
  const SubItem = t0 => {
21
57
  const $ = c(2);
22
58
  const {
@@ -218,6 +254,7 @@ const UnwrappedItem = ({
218
254
  const blockDescriptionId = `${itemId}--block-description`;
219
255
  const trailingVisualId = `${itemId}--trailing-visual`;
220
256
  const inactiveWarningId = inactive && !showInactiveIndicator ? `${itemId}--warning-message` : undefined;
257
+ const [truncatedText, setTruncatedText] = React.useState(undefined);
221
258
  const DefaultItemWrapper = listSemantics ? DivItemContainerNoBox : ButtonItemContainerNoBox;
222
259
  const ItemWrapper = _PrivateItemWrapper || DefaultItemWrapper;
223
260
 
@@ -238,8 +275,8 @@ const UnwrappedItem = ({
238
275
  'data-inactive': inactive ? true : undefined,
239
276
  'data-loading': loading && !inactive ? true : undefined,
240
277
  tabIndex: focusable ? undefined : 0,
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,
278
+ 'aria-labelledby': `${labelId} ${slots.trailingVisual ? trailingVisualId : ''}`,
279
+ 'aria-describedby': [slots.description && descriptionVariant === 'block' ? blockDescriptionId : undefined, slots.description && descriptionVariant === 'inline' ? inlineDescriptionId : undefined, inactiveWarningId !== null && inactiveWarningId !== void 0 ? inactiveWarningId : undefined].filter(String).join(' ').trim() || undefined,
243
280
  ...(includeSelectionAttribute && {
244
281
  [itemSelectionAttribute]: selected
245
282
  }),
@@ -269,7 +306,8 @@ const UnwrappedItem = ({
269
306
  inactive: Boolean(inactiveText),
270
307
  inlineDescriptionId,
271
308
  blockDescriptionId,
272
- trailingVisualId
309
+ trailingVisualId,
310
+ setTruncatedText: buttonSemantics ? setTruncatedText : undefined
273
311
  },
274
312
  children: /*#__PURE__*/jsxs("li", {
275
313
  ...containerProps,
@@ -281,55 +319,62 @@ const UnwrappedItem = ({
281
319
  "data-has-subitem": slots.subItem ? true : undefined,
282
320
  "data-has-description": slots.description ? true : false,
283
321
  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
- })]
322
+ children: [/*#__PURE__*/jsx(ConditionalTooltip, {
323
+ text: truncatedText,
324
+ enabled: buttonSemantics,
325
+ children: /*#__PURE__*/jsx(ItemWrapper, {
326
+ ...wrapperProps,
327
+ className: classes.ActionListContent,
328
+ "data-size": size
329
+ // @ts-ignore: ItemWrapper is polymorphic and the ref type depends on the rendered element ('button' or 'li')
330
+ ,
331
+ ref: forwardedRef,
332
+ children: /*#__PURE__*/jsxs(TooltipContext.Provider, {
333
+ value: {},
334
+ children: [/*#__PURE__*/jsx("span", {
335
+ className: classes.Spacer
336
+ }), /*#__PURE__*/jsx(Selection, {
337
+ selected: selected,
338
+ className: classes.LeadingAction
339
+ }), /*#__PURE__*/jsx(VisualOrIndicator, {
340
+ inactiveText: showInactiveIndicator ? inactiveText : undefined,
341
+ itemHasLeadingVisual: Boolean(slots.leadingVisual),
342
+ labelId: labelId,
343
+ loading: loading,
344
+ position: "leading",
345
+ children: slots.leadingVisual
346
+ }), /*#__PURE__*/jsxs("span", {
347
+ className: classes.ActionListSubContent,
348
+ "data-component": "ActionList.Item--DividerContainer",
349
+ children: [/*#__PURE__*/jsxs(ConditionalWrapper, {
350
+ if: !!slots.description,
351
+ className: classes.ItemDescriptionWrap,
352
+ "data-description-variant": descriptionVariant,
353
+ children: [/*#__PURE__*/jsxs("span", {
354
+ id: labelId,
355
+ className: classes.ItemLabel,
356
+ children: [childrenWithoutSlots, loading === true && !inactive && /*#__PURE__*/jsx(VisuallyHidden, {
357
+ children: "Loading"
358
+ })]
359
+ }), slots.description]
360
+ }), /*#__PURE__*/jsx(VisualOrIndicator, {
361
+ inactiveText: showInactiveIndicator ? inactiveText : undefined,
362
+ itemHasLeadingVisual: Boolean(slots.leadingVisual),
363
+ labelId: labelId,
364
+ loading: loading,
365
+ position: "trailing",
366
+ children: trailingVisual
367
+ }),
368
+ // If the item is inactive, but it's not in an overlay (e.g. ActionMenu, SelectPanel),
369
+ // render the inactive warning message directly in the item.
370
+ !showInactiveIndicator && inactiveText ? /*#__PURE__*/jsx("span", {
371
+ className: classes.InactiveWarning,
372
+ id: inactiveWarningId,
373
+ children: inactiveText
374
+ }) : null]
375
+ })]
376
+ })
377
+ })
333
378
  }), !inactive && !loading && !menuContext && Boolean(slots.trailingAction) && slots.trailingAction, slots.subItem]
334
379
  })
335
380
  });
@@ -77,6 +77,7 @@ 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;
80
81
  };
81
82
  export declare const ItemContext: React.Context<ItemContext>;
82
83
  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,CAAC,EAAE,UAAU,CAAC,GAAG,KAAK,CAAA;AAE/E,MAAM,MAAM,mBAAmB,CAAC,EAAE,SAAS,KAAK,CAAC,WAAW,GAAG,IAAI,IAAI,yBAAyB,CAC9F,gBAAgB,CAAC,EAAE,EAAE,IAAI,CAAC,CAC3B,GAAG;IACF;;OAEG;IACH,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAA;IAC1B;;;OAGG;IACH,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,UAAU,CAAC,WAAW,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,KAAK,IAAI,CAAA;IAC5F;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB;;;;;OAKG;IACH,OAAO,CAAC,EAAE,SAAS,GAAG,QAAQ,CAAA;IAC9B,IAAI,CAAC,EAAE,QAAQ,GAAG,OAAO,CAAA;IACzB;;OAEG;IACH,QAAQ,CAAC,EAAE,OAAO,CAAA;IAClB;;OAEG;IACH,IAAI,CAAC,EAAE,QAAQ,CAAA;IACf;;OAEG;IACH,EAAE,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,iBAAiB,CAAC;IACjD,SAAS,CAAC,EAAE,gBAAgB,CAAA;IAC5B,IAAI,EAAE,MAAM,CAAA;IACZ,IAAI,CAAC,EAAE,OAAO,GAAG,aAAa,CAAA;IAC9B,cAAc,CAAC,EAAE,mBAAmB,CAAC,MAAM,CAAC,CAAA;IAC5C;;;;;OAKG;IACH,KAAK,CAAC,EAAE,OAAO,GAAG,QAAQ,GAAG,MAAM,CAAA;IACnC;;;;;;;;OAQG;IACH,sBAAsB,CAAC,EAAE,OAAO,CAAA;CACjC,CAAC,GACA,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,CAAA;AAiEnC,eAAO,MAAM,cAAc;gBAAoC,MAAM;EAAM,CAAA;AAE3E,eAAO,MAAM,OAAO,EAAE,yBAAyB,CAC7C,KAAK,CAAC,eAAe,CAAC,YAAY,CAAC,GAAG,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,CACvE,GACC,UAwRD,CAAA"}
@@ -7,6 +7,7 @@ import { clsx } from 'clsx';
7
7
  import classes from './Tooltip.module.css.js';
8
8
  import VisuallyHidden from '../_VisuallyHidden.js';
9
9
  import useSafeTimeout from '../hooks/useSafeTimeout.js';
10
+ import { useMergedRefs } from '../internal/hooks/useMergedRefs.js';
10
11
  import { jsx, jsxs, Fragment } from 'react/jsx-runtime';
11
12
  import { useId } from '../hooks/useId.js';
12
13
  import { useProvidedRefOrCreate } from '../hooks/useProvidedRefOrCreate.js';
@@ -88,6 +89,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
88
89
  _privateDisableTooltip = false,
89
90
  ...rest
90
91
  }, forwardedRef) => {
92
+ var _props$ref;
91
93
  const tooltipId = useId(id);
92
94
  const child = Children.only(children);
93
95
  const triggerRef = useProvidedRefOrCreate(forwardedRef);
@@ -196,6 +198,8 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
196
198
  }, [isPopoverOpen]);
197
199
  const isMacOS = useIsMacOS();
198
200
  const hasAriaLabel = 'aria-label' in rest;
201
+ const childRef = (_props$ref = child.props.ref) !== null && _props$ref !== void 0 ? _props$ref : null;
202
+ const setTriggerRef = useMergedRefs(triggerRef, childRef, forwardedRef);
199
203
  return /*#__PURE__*/jsx(TooltipContext.Provider, {
200
204
  value: value,
201
205
  children: /*#__PURE__*/jsxs(Fragment, {
@@ -203,8 +207,7 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
203
207
  /*#__PURE__*/
204
208
  // eslint-disable-next-line react-hooks/refs
205
209
  React.cloneElement(child, {
206
- // @ts-expect-error it needs a non nullable ref
207
- ref: triggerRef,
210
+ ref: setTriggerRef,
208
211
  // If it is a type description, we use tooltip to describe the trigger
209
212
  'aria-describedby': (() => {
210
213
  // If tooltip is not a description type, keep the original aria-describedby
@@ -212,6 +215,12 @@ const Tooltip = /*#__PURE__*/React.forwardRef(({
212
215
  return child.props['aria-describedby'];
213
216
  }
214
217
 
218
+ // When the tooltip is disabled, don't add its ID to aria-describedby
219
+ // to avoid an empty string polluting the accessible description
220
+ if (_privateDisableTooltip) {
221
+ return child.props['aria-describedby'];
222
+ }
223
+
215
224
  // If tooltip is a description type, append our tooltipId
216
225
  const existingDescribedBy = child.props['aria-describedby'];
217
226
  if (existingDescribedBy) {
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@primer/react",
3
3
  "type": "module",
4
- "version": "0.0.0-20260302165340",
4
+ "version": "0.0.0-20260302192736",
5
5
  "description": "An implementation of GitHub's Primer Design System using React",
6
6
  "main": "./dist/index.js",
7
7
  "module": "./dist/index.js",
@@ -1,32 +0,0 @@
1
- import { type Dispatch, type ReactNode } from 'react';
2
- export interface ProviderProps<T> {
3
- children: ReactNode;
4
- /** State setter from `useRegistryState`. */
5
- setRegistry: Dispatch<React.SetStateAction<ReadonlyMap<string, T> | undefined>>;
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
- * @note Note that this pattern is not SSR compatible. It won't raise errors or hydration mismatches, but the
23
- * registry will not be available during SSR. The registry is built during the effect phase, so it will be populated
24
- * after hydration on the client. The initial `undefined` value can be used to safely show loading UI during SSR/initial
25
- * render if necessary.
26
- */
27
- export declare function createDescendantRegistry<T>(): {
28
- Provider: ({ children, setRegistry }: ProviderProps<T>) => import("react").JSX.Element;
29
- useRegistryState: () => [ReadonlyMap<string, T> | undefined, Dispatch<import("react").SetStateAction<ReadonlyMap<string, T> | undefined>>];
30
- useRegisterDescendant: (value: T) => string;
31
- };
32
- //# sourceMappingURL=descendant-registry.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"descendant-registry.d.ts","sourceRoot":"","sources":["../../src/utils/descendant-registry.tsx"],"names":[],"mappings":"AAAA,OAAO,EAUL,KAAK,QAAQ,EACb,KAAK,SAAS,EACf,MAAM,OAAO,CAAA;AAGd,MAAM,WAAW,aAAa,CAAC,CAAC;IAC9B,QAAQ,EAAE,SAAS,CAAA;IACnB,4CAA4C;IAC5C,WAAW,EAAE,QAAQ,CAAC,KAAK,CAAC,cAAc,CAAC,WAAW,CAAC,MAAM,EAAE,CAAC,CAAC,GAAG,SAAS,CAAC,CAAC,CAAA;CAChF;AAQD;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,wBAAwB,CAAC,CAAC;0CAgCG,aAAa,CAAC,CAAC,CAAC;;mCAfrB,CAAC;EA8FxC"}
@@ -1,222 +0,0 @@
1
- import { c } from 'react-compiler-runtime';
2
- import { useContext, useId, useEffect, useState, useRef, useReducer, 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
- * @note Note that this pattern is not SSR compatible. It won't raise errors or hydration mismatches, but the
22
- * registry will not be available during SSR. The registry is built during the effect phase, so it will be populated
23
- * after hydration on the client. The initial `undefined` value can be used to safely show loading UI during SSR/initial
24
- * render if necessary.
25
- */
26
- function createDescendantRegistry() {
27
- const Context = /*#__PURE__*/createContext({
28
- register: () => () => {},
29
- updateValue: () => {},
30
- key: -1
31
- });
32
-
33
- /**
34
- * Instantiate descendant registry state. The initial value will be `undefined`, indicating that the registry hasn't
35
- * been built yet.
36
- */
37
- function useRegistryState() {
38
- return useState();
39
- }
40
-
41
- /** Register a descendant component with the registry. */
42
- function useRegisterDescendant(value) {
43
- const $ = c(16);
44
- const {
45
- register,
46
- updateValue,
47
- key
48
- } = useContext(Context);
49
- const id = useId();
50
- let t0;
51
- if ($[0] !== id || $[1] !== register) {
52
- t0 = () => register(id);
53
- $[0] = id;
54
- $[1] = register;
55
- $[2] = t0;
56
- } else {
57
- t0 = $[2];
58
- }
59
- let t1;
60
- if ($[3] !== id || $[4] !== key || $[5] !== register) {
61
- t1 = [register, id, key];
62
- $[3] = id;
63
- $[4] = key;
64
- $[5] = register;
65
- $[6] = t1;
66
- } else {
67
- t1 = $[6];
68
- }
69
- useEffect(t0, t1);
70
- let t2;
71
- if ($[7] !== id || $[8] !== updateValue || $[9] !== value) {
72
- t2 = () => updateValue(id, value);
73
- $[7] = id;
74
- $[8] = updateValue;
75
- $[9] = value;
76
- $[10] = t2;
77
- } else {
78
- t2 = $[10];
79
- }
80
- let t3;
81
- if ($[11] !== id || $[12] !== key || $[13] !== updateValue || $[14] !== value) {
82
- t3 = [updateValue, id, value, key];
83
- $[11] = id;
84
- $[12] = key;
85
- $[13] = updateValue;
86
- $[14] = value;
87
- $[15] = t3;
88
- } else {
89
- t3 = $[15];
90
- }
91
- useEffect(t2, t3);
92
- return id;
93
- }
94
- const unsetValue = Symbol('unset');
95
-
96
- /** Provide context for registering descendant components. This only needs to wrap `children`. */
97
- function Provider(t0) {
98
- const $ = c(14);
99
- const {
100
- children,
101
- setRegistry
102
- } = t0;
103
- const workingRegistryRef = useRef("queued");
104
- const [key, rebuildRegistry] = useReducer(_temp, 0);
105
- let t1;
106
- if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
107
- t1 = function instantiateNewRegistry() {
108
- if (workingRegistryRef.current === "queued") {
109
- workingRegistryRef.current = new Map();
110
- }
111
- };
112
- $[0] = t1;
113
- } else {
114
- t1 = $[0];
115
- }
116
- useIsomorphicLayoutEffect(t1);
117
- let t2;
118
- if ($[1] !== setRegistry) {
119
- t2 = id => {
120
- if (workingRegistryRef.current instanceof Map) {
121
- workingRegistryRef.current.set(id, unsetValue);
122
- } else {
123
- if (workingRegistryRef.current === "idle") {
124
- workingRegistryRef.current = "queued";
125
- rebuildRegistry();
126
- }
127
- }
128
- return function unregister() {
129
- if (workingRegistryRef.current instanceof Map) {
130
- workingRegistryRef.current.delete(id);
131
- } else {
132
- if (workingRegistryRef.current === "idle") {
133
- setRegistry(prev_0 => {
134
- const copy = new Map(prev_0);
135
- copy.delete(id);
136
- return copy;
137
- });
138
- }
139
- }
140
- };
141
- };
142
- $[1] = setRegistry;
143
- $[2] = t2;
144
- } else {
145
- t2 = $[2];
146
- }
147
- const register = t2;
148
- let t3;
149
- if ($[3] !== setRegistry) {
150
- t3 = (id_0, value) => {
151
- if (workingRegistryRef.current instanceof Map) {
152
- workingRegistryRef.current.set(id_0, value);
153
- } else {
154
- if (workingRegistryRef.current === "idle") {
155
- setRegistry(prev_1 => new Map(prev_1).set(id_0, value));
156
- }
157
- }
158
- };
159
- $[3] = setRegistry;
160
- $[4] = t3;
161
- } else {
162
- t3 = $[4];
163
- }
164
- const updateValue = t3;
165
- let t4;
166
- if ($[5] !== setRegistry) {
167
- t4 = function commitWorkingRegistry() {
168
- if (workingRegistryRef.current instanceof Map) {
169
- const setEntries = Array.from(workingRegistryRef.current.entries()).filter(_temp2);
170
- setRegistry(new Map(setEntries));
171
- workingRegistryRef.current = "idle";
172
- }
173
- };
174
- $[5] = setRegistry;
175
- $[6] = t4;
176
- } else {
177
- t4 = $[6];
178
- }
179
- useEffect(t4);
180
- let t5;
181
- if ($[7] !== key || $[8] !== register || $[9] !== updateValue) {
182
- t5 = {
183
- register,
184
- updateValue,
185
- key
186
- };
187
- $[7] = key;
188
- $[8] = register;
189
- $[9] = updateValue;
190
- $[10] = t5;
191
- } else {
192
- t5 = $[10];
193
- }
194
- const contextValue = t5;
195
- let t6;
196
- if ($[11] !== children || $[12] !== contextValue) {
197
- t6 = /*#__PURE__*/jsx(Context.Provider, {
198
- value: contextValue,
199
- children: children
200
- });
201
- $[11] = children;
202
- $[12] = contextValue;
203
- $[13] = t6;
204
- } else {
205
- t6 = $[13];
206
- }
207
- return t6;
208
- }
209
- function _temp2(entry) {
210
- return entry[1] !== unsetValue;
211
- }
212
- function _temp(prev) {
213
- return prev + 1;
214
- }
215
- return {
216
- Provider,
217
- useRegistryState,
218
- useRegisterDescendant
219
- };
220
- }
221
-
222
- export { createDescendantRegistry };