@primer/react 0.0.0-20260303210348 → 0.0.0-20260303220535
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -7
- package/dist/ActionBar/ActionBar.d.ts.map +1 -1
- package/dist/ActionBar/ActionBar.js +431 -281
- package/dist/ActionMenu/ActionMenu.d.ts.map +1 -1
- package/dist/ActionMenu/ActionMenu.js +9 -1
- package/dist/AnchoredOverlay/AnchoredOverlay-b61b19da.css +2 -0
- package/dist/AnchoredOverlay/AnchoredOverlay-b61b19da.css.map +1 -0
- package/dist/AnchoredOverlay/AnchoredOverlay.d.ts.map +1 -1
- package/dist/AnchoredOverlay/AnchoredOverlay.js +34 -9
- package/dist/AnchoredOverlay/AnchoredOverlay.module.css.js +2 -2
- package/dist/FeatureFlags/DefaultFeatureFlags.d.ts.map +1 -1
- package/dist/FeatureFlags/DefaultFeatureFlags.js +1 -0
- package/dist/Overlay/Overlay-b2e98ec4.css +2 -0
- package/dist/Overlay/Overlay-b2e98ec4.css.map +1 -0
- package/dist/Overlay/Overlay.d.ts.map +1 -1
- package/dist/Overlay/Overlay.js +26 -17
- package/dist/Overlay/Overlay.module.css.js +1 -1
- package/dist/Timeline/{Timeline-19bef8c5.css → Timeline-116393ee.css} +2 -2
- package/dist/Timeline/{Timeline-19bef8c5.css.map → Timeline-116393ee.css.map} +1 -1
- package/dist/Timeline/Timeline.module.css.js +1 -1
- package/package.json +2 -1
- package/dist/AnchoredOverlay/AnchoredOverlay-73c1b2d1.css +0 -2
- package/dist/AnchoredOverlay/AnchoredOverlay-73c1b2d1.css.map +0 -1
- package/dist/Overlay/Overlay-15519c09.css +0 -2
- package/dist/Overlay/Overlay-15519c09.css.map +0 -1
- package/dist/utils/descendant-registry.d.ts +0 -32
- package/dist/utils/descendant-registry.d.ts.map +0 -1
- package/dist/utils/descendant-registry.js +0 -222
|
@@ -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 };
|