@bccampus/ui-components 0.5.0 → 0.5.2
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/.yarn/install-state.gz +0 -0
- package/.yarn/releases/yarn-4.10.3.cjs +942 -0
- package/.yarnrc.yml +3 -0
- package/dist/_chunks/createLucideIcon.js +0 -24
- package/dist/_chunks/index.js +16 -38
- package/dist/_chunks/index3.js +26 -520
- package/dist/_chunks/index4.js +615 -0
- package/dist/_chunks/utils.js +199 -143
- package/dist/components/index.js +2 -2
- package/dist/components/ui/banner.js +0 -6
- package/dist/components/ui/composite/CompositeData.js +1 -1
- package/dist/components/ui/composite/CompositeDataItem.js +109 -3
- package/dist/components/ui/composite/FocusProvider/AbstractFocusProvider.js +2 -1
- package/dist/components/ui/composite/SelectionProvider/AbstractSelectionProvider.js +2 -1
- package/dist/components/ui/composite/SelectionProvider/MultipleSelectionProvider.js +1 -1
- package/dist/components/ui/composite/SelectionProvider/SingleSelectionProvider.js +1 -1
- package/dist/components/ui/composite/composite-component-item.js +2 -24
- package/dist/components/ui/composite/index.d.ts +1 -0
- package/dist/components/ui/composite/index.js +2 -2
- package/dist/components/ui/composite/listbox.js +1 -0
- package/dist/components/ui/horizontal-list.js +0 -12
- package/dist/components/ui/navigation-menu.js +86 -10
- package/dist/components/ui/popover.js +85 -3
- package/dist/components/ui/search-input.js +0 -6
- package/package.json +75 -67
- package/src/App.tsx +44 -14
- package/src/components/ui/composite/index.ts +2 -1
- package/src/components/ui/page-header.tsx +6 -9
- package/src/main.tsx +12 -12
- package/vite.config.ts +6 -2
- package/dist/_chunks/CompositeDataItem.js +0 -204
|
@@ -0,0 +1,615 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { jsx } from "react/jsx-runtime";
|
|
3
|
+
import { c as composeRefs, u as useComposedRefs } from "./index3.js";
|
|
4
|
+
import * as ReactDOM from "react-dom";
|
|
5
|
+
function createContextScope(scopeName, createContextScopeDeps = []) {
|
|
6
|
+
let defaultContexts = [];
|
|
7
|
+
function createContext3(rootComponentName, defaultContext) {
|
|
8
|
+
const BaseContext = React.createContext(defaultContext);
|
|
9
|
+
const index = defaultContexts.length;
|
|
10
|
+
defaultContexts = [...defaultContexts, defaultContext];
|
|
11
|
+
const Provider = (props) => {
|
|
12
|
+
const { scope, children, ...context } = props;
|
|
13
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
14
|
+
const value = React.useMemo(() => context, Object.values(context));
|
|
15
|
+
return /* @__PURE__ */ jsx(Context.Provider, { value, children });
|
|
16
|
+
};
|
|
17
|
+
Provider.displayName = rootComponentName + "Provider";
|
|
18
|
+
function useContext2(consumerName, scope) {
|
|
19
|
+
const Context = scope?.[scopeName]?.[index] || BaseContext;
|
|
20
|
+
const context = React.useContext(Context);
|
|
21
|
+
if (context) return context;
|
|
22
|
+
if (defaultContext !== void 0) return defaultContext;
|
|
23
|
+
throw new Error(`\`${consumerName}\` must be used within \`${rootComponentName}\``);
|
|
24
|
+
}
|
|
25
|
+
return [Provider, useContext2];
|
|
26
|
+
}
|
|
27
|
+
const createScope = () => {
|
|
28
|
+
const scopeContexts = defaultContexts.map((defaultContext) => {
|
|
29
|
+
return React.createContext(defaultContext);
|
|
30
|
+
});
|
|
31
|
+
return function useScope(scope) {
|
|
32
|
+
const contexts = scope?.[scopeName] || scopeContexts;
|
|
33
|
+
return React.useMemo(
|
|
34
|
+
() => ({ [`__scope${scopeName}`]: { ...scope, [scopeName]: contexts } }),
|
|
35
|
+
[scope, contexts]
|
|
36
|
+
);
|
|
37
|
+
};
|
|
38
|
+
};
|
|
39
|
+
createScope.scopeName = scopeName;
|
|
40
|
+
return [createContext3, composeContextScopes(createScope, ...createContextScopeDeps)];
|
|
41
|
+
}
|
|
42
|
+
function composeContextScopes(...scopes) {
|
|
43
|
+
const baseScope = scopes[0];
|
|
44
|
+
if (scopes.length === 1) return baseScope;
|
|
45
|
+
const createScope = () => {
|
|
46
|
+
const scopeHooks = scopes.map((createScope2) => ({
|
|
47
|
+
useScope: createScope2(),
|
|
48
|
+
scopeName: createScope2.scopeName
|
|
49
|
+
}));
|
|
50
|
+
return function useComposedScopes(overrideScopes) {
|
|
51
|
+
const nextScopes = scopeHooks.reduce((nextScopes2, { useScope, scopeName }) => {
|
|
52
|
+
const scopeProps = useScope(overrideScopes);
|
|
53
|
+
const currentScope = scopeProps[`__scope${scopeName}`];
|
|
54
|
+
return { ...nextScopes2, ...currentScope };
|
|
55
|
+
}, {});
|
|
56
|
+
return React.useMemo(() => ({ [`__scope${baseScope.scopeName}`]: nextScopes }), [nextScopes]);
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
createScope.scopeName = baseScope.scopeName;
|
|
60
|
+
return createScope;
|
|
61
|
+
}
|
|
62
|
+
function composeEventHandlers(originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) {
|
|
63
|
+
return function handleEvent(event) {
|
|
64
|
+
originalEventHandler?.(event);
|
|
65
|
+
if (checkForDefaultPrevented === false || !event.defaultPrevented) {
|
|
66
|
+
return ourEventHandler?.(event);
|
|
67
|
+
}
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
// @__NO_SIDE_EFFECTS__
|
|
71
|
+
function createSlot(ownerName) {
|
|
72
|
+
const SlotClone = /* @__PURE__ */ createSlotClone(ownerName);
|
|
73
|
+
const Slot2 = React.forwardRef((props, forwardedRef) => {
|
|
74
|
+
const { children, ...slotProps } = props;
|
|
75
|
+
const childrenArray = React.Children.toArray(children);
|
|
76
|
+
const slottable = childrenArray.find(isSlottable);
|
|
77
|
+
if (slottable) {
|
|
78
|
+
const newElement = slottable.props.children;
|
|
79
|
+
const newChildren = childrenArray.map((child) => {
|
|
80
|
+
if (child === slottable) {
|
|
81
|
+
if (React.Children.count(newElement) > 1) return React.Children.only(null);
|
|
82
|
+
return React.isValidElement(newElement) ? newElement.props.children : null;
|
|
83
|
+
} else {
|
|
84
|
+
return child;
|
|
85
|
+
}
|
|
86
|
+
});
|
|
87
|
+
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children: React.isValidElement(newElement) ? React.cloneElement(newElement, void 0, newChildren) : null });
|
|
88
|
+
}
|
|
89
|
+
return /* @__PURE__ */ jsx(SlotClone, { ...slotProps, ref: forwardedRef, children });
|
|
90
|
+
});
|
|
91
|
+
Slot2.displayName = `${ownerName}.Slot`;
|
|
92
|
+
return Slot2;
|
|
93
|
+
}
|
|
94
|
+
// @__NO_SIDE_EFFECTS__
|
|
95
|
+
function createSlotClone(ownerName) {
|
|
96
|
+
const SlotClone = React.forwardRef((props, forwardedRef) => {
|
|
97
|
+
const { children, ...slotProps } = props;
|
|
98
|
+
if (React.isValidElement(children)) {
|
|
99
|
+
const childrenRef = getElementRef$1(children);
|
|
100
|
+
const props2 = mergeProps(slotProps, children.props);
|
|
101
|
+
if (children.type !== React.Fragment) {
|
|
102
|
+
props2.ref = forwardedRef ? composeRefs(forwardedRef, childrenRef) : childrenRef;
|
|
103
|
+
}
|
|
104
|
+
return React.cloneElement(children, props2);
|
|
105
|
+
}
|
|
106
|
+
return React.Children.count(children) > 1 ? React.Children.only(null) : null;
|
|
107
|
+
});
|
|
108
|
+
SlotClone.displayName = `${ownerName}.SlotClone`;
|
|
109
|
+
return SlotClone;
|
|
110
|
+
}
|
|
111
|
+
var SLOTTABLE_IDENTIFIER = Symbol("radix.slottable");
|
|
112
|
+
function isSlottable(child) {
|
|
113
|
+
return React.isValidElement(child) && typeof child.type === "function" && "__radixId" in child.type && child.type.__radixId === SLOTTABLE_IDENTIFIER;
|
|
114
|
+
}
|
|
115
|
+
function mergeProps(slotProps, childProps) {
|
|
116
|
+
const overrideProps = { ...childProps };
|
|
117
|
+
for (const propName in childProps) {
|
|
118
|
+
const slotPropValue = slotProps[propName];
|
|
119
|
+
const childPropValue = childProps[propName];
|
|
120
|
+
const isHandler = /^on[A-Z]/.test(propName);
|
|
121
|
+
if (isHandler) {
|
|
122
|
+
if (slotPropValue && childPropValue) {
|
|
123
|
+
overrideProps[propName] = (...args) => {
|
|
124
|
+
const result = childPropValue(...args);
|
|
125
|
+
slotPropValue(...args);
|
|
126
|
+
return result;
|
|
127
|
+
};
|
|
128
|
+
} else if (slotPropValue) {
|
|
129
|
+
overrideProps[propName] = slotPropValue;
|
|
130
|
+
}
|
|
131
|
+
} else if (propName === "style") {
|
|
132
|
+
overrideProps[propName] = { ...slotPropValue, ...childPropValue };
|
|
133
|
+
} else if (propName === "className") {
|
|
134
|
+
overrideProps[propName] = [slotPropValue, childPropValue].filter(Boolean).join(" ");
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { ...slotProps, ...overrideProps };
|
|
138
|
+
}
|
|
139
|
+
function getElementRef$1(element) {
|
|
140
|
+
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
|
|
141
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
142
|
+
if (mayWarn) {
|
|
143
|
+
return element.ref;
|
|
144
|
+
}
|
|
145
|
+
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
|
|
146
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
147
|
+
if (mayWarn) {
|
|
148
|
+
return element.props.ref;
|
|
149
|
+
}
|
|
150
|
+
return element.props.ref || element.ref;
|
|
151
|
+
}
|
|
152
|
+
var NODES = [
|
|
153
|
+
"a",
|
|
154
|
+
"button",
|
|
155
|
+
"div",
|
|
156
|
+
"form",
|
|
157
|
+
"h2",
|
|
158
|
+
"h3",
|
|
159
|
+
"img",
|
|
160
|
+
"input",
|
|
161
|
+
"label",
|
|
162
|
+
"li",
|
|
163
|
+
"nav",
|
|
164
|
+
"ol",
|
|
165
|
+
"p",
|
|
166
|
+
"select",
|
|
167
|
+
"span",
|
|
168
|
+
"svg",
|
|
169
|
+
"ul"
|
|
170
|
+
];
|
|
171
|
+
var Primitive = NODES.reduce((primitive, node) => {
|
|
172
|
+
const Slot = /* @__PURE__ */ createSlot(`Primitive.${node}`);
|
|
173
|
+
const Node = React.forwardRef((props, forwardedRef) => {
|
|
174
|
+
const { asChild, ...primitiveProps } = props;
|
|
175
|
+
const Comp = asChild ? Slot : node;
|
|
176
|
+
if (typeof window !== "undefined") {
|
|
177
|
+
window[Symbol.for("radix-ui")] = true;
|
|
178
|
+
}
|
|
179
|
+
return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
|
|
180
|
+
});
|
|
181
|
+
Node.displayName = `Primitive.${node}`;
|
|
182
|
+
return { ...primitive, [node]: Node };
|
|
183
|
+
}, {});
|
|
184
|
+
function dispatchDiscreteCustomEvent(target, event) {
|
|
185
|
+
if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
|
|
186
|
+
}
|
|
187
|
+
var useLayoutEffect2 = globalThis?.document ? React.useLayoutEffect : () => {
|
|
188
|
+
};
|
|
189
|
+
var useInsertionEffect = React[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
|
|
190
|
+
function useControllableState({
|
|
191
|
+
prop,
|
|
192
|
+
defaultProp,
|
|
193
|
+
onChange = () => {
|
|
194
|
+
},
|
|
195
|
+
caller
|
|
196
|
+
}) {
|
|
197
|
+
const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
|
|
198
|
+
defaultProp,
|
|
199
|
+
onChange
|
|
200
|
+
});
|
|
201
|
+
const isControlled = prop !== void 0;
|
|
202
|
+
const value = isControlled ? prop : uncontrolledProp;
|
|
203
|
+
{
|
|
204
|
+
const isControlledRef = React.useRef(prop !== void 0);
|
|
205
|
+
React.useEffect(() => {
|
|
206
|
+
const wasControlled = isControlledRef.current;
|
|
207
|
+
if (wasControlled !== isControlled) {
|
|
208
|
+
const from = wasControlled ? "controlled" : "uncontrolled";
|
|
209
|
+
const to = isControlled ? "controlled" : "uncontrolled";
|
|
210
|
+
console.warn(
|
|
211
|
+
`${caller} is changing from ${from} to ${to}. Components should not switch from controlled to uncontrolled (or vice versa). Decide between using a controlled or uncontrolled value for the lifetime of the component.`
|
|
212
|
+
);
|
|
213
|
+
}
|
|
214
|
+
isControlledRef.current = isControlled;
|
|
215
|
+
}, [isControlled, caller]);
|
|
216
|
+
}
|
|
217
|
+
const setValue = React.useCallback(
|
|
218
|
+
(nextValue) => {
|
|
219
|
+
if (isControlled) {
|
|
220
|
+
const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
|
|
221
|
+
if (value2 !== prop) {
|
|
222
|
+
onChangeRef.current?.(value2);
|
|
223
|
+
}
|
|
224
|
+
} else {
|
|
225
|
+
setUncontrolledProp(nextValue);
|
|
226
|
+
}
|
|
227
|
+
},
|
|
228
|
+
[isControlled, prop, setUncontrolledProp, onChangeRef]
|
|
229
|
+
);
|
|
230
|
+
return [value, setValue];
|
|
231
|
+
}
|
|
232
|
+
function useUncontrolledState({
|
|
233
|
+
defaultProp,
|
|
234
|
+
onChange
|
|
235
|
+
}) {
|
|
236
|
+
const [value, setValue] = React.useState(defaultProp);
|
|
237
|
+
const prevValueRef = React.useRef(value);
|
|
238
|
+
const onChangeRef = React.useRef(onChange);
|
|
239
|
+
useInsertionEffect(() => {
|
|
240
|
+
onChangeRef.current = onChange;
|
|
241
|
+
}, [onChange]);
|
|
242
|
+
React.useEffect(() => {
|
|
243
|
+
if (prevValueRef.current !== value) {
|
|
244
|
+
onChangeRef.current?.(value);
|
|
245
|
+
prevValueRef.current = value;
|
|
246
|
+
}
|
|
247
|
+
}, [value, prevValueRef]);
|
|
248
|
+
return [value, setValue, onChangeRef];
|
|
249
|
+
}
|
|
250
|
+
function isFunction(value) {
|
|
251
|
+
return typeof value === "function";
|
|
252
|
+
}
|
|
253
|
+
function useStateMachine(initialState, machine) {
|
|
254
|
+
return React.useReducer((state, event) => {
|
|
255
|
+
const nextState = machine[state][event];
|
|
256
|
+
return nextState ?? state;
|
|
257
|
+
}, initialState);
|
|
258
|
+
}
|
|
259
|
+
var Presence = (props) => {
|
|
260
|
+
const { present, children } = props;
|
|
261
|
+
const presence = usePresence(present);
|
|
262
|
+
const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
|
|
263
|
+
const ref = useComposedRefs(presence.ref, getElementRef(child));
|
|
264
|
+
const forceMount = typeof children === "function";
|
|
265
|
+
return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
|
|
266
|
+
};
|
|
267
|
+
Presence.displayName = "Presence";
|
|
268
|
+
function usePresence(present) {
|
|
269
|
+
const [node, setNode] = React.useState();
|
|
270
|
+
const stylesRef = React.useRef(null);
|
|
271
|
+
const prevPresentRef = React.useRef(present);
|
|
272
|
+
const prevAnimationNameRef = React.useRef("none");
|
|
273
|
+
const initialState = present ? "mounted" : "unmounted";
|
|
274
|
+
const [state, send] = useStateMachine(initialState, {
|
|
275
|
+
mounted: {
|
|
276
|
+
UNMOUNT: "unmounted",
|
|
277
|
+
ANIMATION_OUT: "unmountSuspended"
|
|
278
|
+
},
|
|
279
|
+
unmountSuspended: {
|
|
280
|
+
MOUNT: "mounted",
|
|
281
|
+
ANIMATION_END: "unmounted"
|
|
282
|
+
},
|
|
283
|
+
unmounted: {
|
|
284
|
+
MOUNT: "mounted"
|
|
285
|
+
}
|
|
286
|
+
});
|
|
287
|
+
React.useEffect(() => {
|
|
288
|
+
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
289
|
+
prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
|
|
290
|
+
}, [state]);
|
|
291
|
+
useLayoutEffect2(() => {
|
|
292
|
+
const styles = stylesRef.current;
|
|
293
|
+
const wasPresent = prevPresentRef.current;
|
|
294
|
+
const hasPresentChanged = wasPresent !== present;
|
|
295
|
+
if (hasPresentChanged) {
|
|
296
|
+
const prevAnimationName = prevAnimationNameRef.current;
|
|
297
|
+
const currentAnimationName = getAnimationName(styles);
|
|
298
|
+
if (present) {
|
|
299
|
+
send("MOUNT");
|
|
300
|
+
} else if (currentAnimationName === "none" || styles?.display === "none") {
|
|
301
|
+
send("UNMOUNT");
|
|
302
|
+
} else {
|
|
303
|
+
const isAnimating = prevAnimationName !== currentAnimationName;
|
|
304
|
+
if (wasPresent && isAnimating) {
|
|
305
|
+
send("ANIMATION_OUT");
|
|
306
|
+
} else {
|
|
307
|
+
send("UNMOUNT");
|
|
308
|
+
}
|
|
309
|
+
}
|
|
310
|
+
prevPresentRef.current = present;
|
|
311
|
+
}
|
|
312
|
+
}, [present, send]);
|
|
313
|
+
useLayoutEffect2(() => {
|
|
314
|
+
if (node) {
|
|
315
|
+
let timeoutId;
|
|
316
|
+
const ownerWindow = node.ownerDocument.defaultView ?? window;
|
|
317
|
+
const handleAnimationEnd = (event) => {
|
|
318
|
+
const currentAnimationName = getAnimationName(stylesRef.current);
|
|
319
|
+
const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
|
|
320
|
+
if (event.target === node && isCurrentAnimation) {
|
|
321
|
+
send("ANIMATION_END");
|
|
322
|
+
if (!prevPresentRef.current) {
|
|
323
|
+
const currentFillMode = node.style.animationFillMode;
|
|
324
|
+
node.style.animationFillMode = "forwards";
|
|
325
|
+
timeoutId = ownerWindow.setTimeout(() => {
|
|
326
|
+
if (node.style.animationFillMode === "forwards") {
|
|
327
|
+
node.style.animationFillMode = currentFillMode;
|
|
328
|
+
}
|
|
329
|
+
});
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
};
|
|
333
|
+
const handleAnimationStart = (event) => {
|
|
334
|
+
if (event.target === node) {
|
|
335
|
+
prevAnimationNameRef.current = getAnimationName(stylesRef.current);
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
node.addEventListener("animationstart", handleAnimationStart);
|
|
339
|
+
node.addEventListener("animationcancel", handleAnimationEnd);
|
|
340
|
+
node.addEventListener("animationend", handleAnimationEnd);
|
|
341
|
+
return () => {
|
|
342
|
+
ownerWindow.clearTimeout(timeoutId);
|
|
343
|
+
node.removeEventListener("animationstart", handleAnimationStart);
|
|
344
|
+
node.removeEventListener("animationcancel", handleAnimationEnd);
|
|
345
|
+
node.removeEventListener("animationend", handleAnimationEnd);
|
|
346
|
+
};
|
|
347
|
+
} else {
|
|
348
|
+
send("ANIMATION_END");
|
|
349
|
+
}
|
|
350
|
+
}, [node, send]);
|
|
351
|
+
return {
|
|
352
|
+
isPresent: ["mounted", "unmountSuspended"].includes(state),
|
|
353
|
+
ref: React.useCallback((node2) => {
|
|
354
|
+
stylesRef.current = node2 ? getComputedStyle(node2) : null;
|
|
355
|
+
setNode(node2);
|
|
356
|
+
}, [])
|
|
357
|
+
};
|
|
358
|
+
}
|
|
359
|
+
function getAnimationName(styles) {
|
|
360
|
+
return styles?.animationName || "none";
|
|
361
|
+
}
|
|
362
|
+
function getElementRef(element) {
|
|
363
|
+
let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
|
|
364
|
+
let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
365
|
+
if (mayWarn) {
|
|
366
|
+
return element.ref;
|
|
367
|
+
}
|
|
368
|
+
getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
|
|
369
|
+
mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
|
|
370
|
+
if (mayWarn) {
|
|
371
|
+
return element.props.ref;
|
|
372
|
+
}
|
|
373
|
+
return element.props.ref || element.ref;
|
|
374
|
+
}
|
|
375
|
+
var useReactId = React[" useId ".trim().toString()] || (() => void 0);
|
|
376
|
+
var count = 0;
|
|
377
|
+
function useId(deterministicId) {
|
|
378
|
+
const [id, setId] = React.useState(useReactId());
|
|
379
|
+
useLayoutEffect2(() => {
|
|
380
|
+
setId((reactId) => reactId ?? String(count++));
|
|
381
|
+
}, [deterministicId]);
|
|
382
|
+
return id ? `radix-${id}` : "";
|
|
383
|
+
}
|
|
384
|
+
function useCallbackRef(callback) {
|
|
385
|
+
const callbackRef = React.useRef(callback);
|
|
386
|
+
React.useEffect(() => {
|
|
387
|
+
callbackRef.current = callback;
|
|
388
|
+
});
|
|
389
|
+
return React.useMemo(() => (...args) => callbackRef.current?.(...args), []);
|
|
390
|
+
}
|
|
391
|
+
function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
|
|
392
|
+
const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
|
|
393
|
+
React.useEffect(() => {
|
|
394
|
+
const handleKeyDown = (event) => {
|
|
395
|
+
if (event.key === "Escape") {
|
|
396
|
+
onEscapeKeyDown(event);
|
|
397
|
+
}
|
|
398
|
+
};
|
|
399
|
+
ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
|
|
400
|
+
return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
|
|
401
|
+
}, [onEscapeKeyDown, ownerDocument]);
|
|
402
|
+
}
|
|
403
|
+
var DISMISSABLE_LAYER_NAME = "DismissableLayer";
|
|
404
|
+
var CONTEXT_UPDATE = "dismissableLayer.update";
|
|
405
|
+
var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
|
|
406
|
+
var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
|
|
407
|
+
var originalBodyPointerEvents;
|
|
408
|
+
var DismissableLayerContext = React.createContext({
|
|
409
|
+
layers: /* @__PURE__ */ new Set(),
|
|
410
|
+
layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
|
|
411
|
+
branches: /* @__PURE__ */ new Set()
|
|
412
|
+
});
|
|
413
|
+
var DismissableLayer = React.forwardRef(
|
|
414
|
+
(props, forwardedRef) => {
|
|
415
|
+
const {
|
|
416
|
+
disableOutsidePointerEvents = false,
|
|
417
|
+
onEscapeKeyDown,
|
|
418
|
+
onPointerDownOutside,
|
|
419
|
+
onFocusOutside,
|
|
420
|
+
onInteractOutside,
|
|
421
|
+
onDismiss,
|
|
422
|
+
...layerProps
|
|
423
|
+
} = props;
|
|
424
|
+
const context = React.useContext(DismissableLayerContext);
|
|
425
|
+
const [node, setNode] = React.useState(null);
|
|
426
|
+
const ownerDocument = node?.ownerDocument ?? globalThis?.document;
|
|
427
|
+
const [, force] = React.useState({});
|
|
428
|
+
const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
|
|
429
|
+
const layers = Array.from(context.layers);
|
|
430
|
+
const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
|
|
431
|
+
const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
|
|
432
|
+
const index = node ? layers.indexOf(node) : -1;
|
|
433
|
+
const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
|
|
434
|
+
const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
|
|
435
|
+
const pointerDownOutside = usePointerDownOutside((event) => {
|
|
436
|
+
const target = event.target;
|
|
437
|
+
const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
438
|
+
if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
|
|
439
|
+
onPointerDownOutside?.(event);
|
|
440
|
+
onInteractOutside?.(event);
|
|
441
|
+
if (!event.defaultPrevented) onDismiss?.();
|
|
442
|
+
}, ownerDocument);
|
|
443
|
+
const focusOutside = useFocusOutside((event) => {
|
|
444
|
+
const target = event.target;
|
|
445
|
+
const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
|
|
446
|
+
if (isFocusInBranch) return;
|
|
447
|
+
onFocusOutside?.(event);
|
|
448
|
+
onInteractOutside?.(event);
|
|
449
|
+
if (!event.defaultPrevented) onDismiss?.();
|
|
450
|
+
}, ownerDocument);
|
|
451
|
+
useEscapeKeydown((event) => {
|
|
452
|
+
const isHighestLayer = index === context.layers.size - 1;
|
|
453
|
+
if (!isHighestLayer) return;
|
|
454
|
+
onEscapeKeyDown?.(event);
|
|
455
|
+
if (!event.defaultPrevented && onDismiss) {
|
|
456
|
+
event.preventDefault();
|
|
457
|
+
onDismiss();
|
|
458
|
+
}
|
|
459
|
+
}, ownerDocument);
|
|
460
|
+
React.useEffect(() => {
|
|
461
|
+
if (!node) return;
|
|
462
|
+
if (disableOutsidePointerEvents) {
|
|
463
|
+
if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
|
|
464
|
+
originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
|
|
465
|
+
ownerDocument.body.style.pointerEvents = "none";
|
|
466
|
+
}
|
|
467
|
+
context.layersWithOutsidePointerEventsDisabled.add(node);
|
|
468
|
+
}
|
|
469
|
+
context.layers.add(node);
|
|
470
|
+
dispatchUpdate();
|
|
471
|
+
return () => {
|
|
472
|
+
if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
|
|
473
|
+
ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
|
|
474
|
+
}
|
|
475
|
+
};
|
|
476
|
+
}, [node, ownerDocument, disableOutsidePointerEvents, context]);
|
|
477
|
+
React.useEffect(() => {
|
|
478
|
+
return () => {
|
|
479
|
+
if (!node) return;
|
|
480
|
+
context.layers.delete(node);
|
|
481
|
+
context.layersWithOutsidePointerEventsDisabled.delete(node);
|
|
482
|
+
dispatchUpdate();
|
|
483
|
+
};
|
|
484
|
+
}, [node, context]);
|
|
485
|
+
React.useEffect(() => {
|
|
486
|
+
const handleUpdate = () => force({});
|
|
487
|
+
document.addEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
488
|
+
return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
|
|
489
|
+
}, []);
|
|
490
|
+
return /* @__PURE__ */ jsx(
|
|
491
|
+
Primitive.div,
|
|
492
|
+
{
|
|
493
|
+
...layerProps,
|
|
494
|
+
ref: composedRefs,
|
|
495
|
+
style: {
|
|
496
|
+
pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
|
|
497
|
+
...props.style
|
|
498
|
+
},
|
|
499
|
+
onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
|
|
500
|
+
onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
|
|
501
|
+
onPointerDownCapture: composeEventHandlers(
|
|
502
|
+
props.onPointerDownCapture,
|
|
503
|
+
pointerDownOutside.onPointerDownCapture
|
|
504
|
+
)
|
|
505
|
+
}
|
|
506
|
+
);
|
|
507
|
+
}
|
|
508
|
+
);
|
|
509
|
+
DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
|
|
510
|
+
var BRANCH_NAME = "DismissableLayerBranch";
|
|
511
|
+
var DismissableLayerBranch = React.forwardRef((props, forwardedRef) => {
|
|
512
|
+
const context = React.useContext(DismissableLayerContext);
|
|
513
|
+
const ref = React.useRef(null);
|
|
514
|
+
const composedRefs = useComposedRefs(forwardedRef, ref);
|
|
515
|
+
React.useEffect(() => {
|
|
516
|
+
const node = ref.current;
|
|
517
|
+
if (node) {
|
|
518
|
+
context.branches.add(node);
|
|
519
|
+
return () => {
|
|
520
|
+
context.branches.delete(node);
|
|
521
|
+
};
|
|
522
|
+
}
|
|
523
|
+
}, [context.branches]);
|
|
524
|
+
return /* @__PURE__ */ jsx(Primitive.div, { ...props, ref: composedRefs });
|
|
525
|
+
});
|
|
526
|
+
DismissableLayerBranch.displayName = BRANCH_NAME;
|
|
527
|
+
function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
|
|
528
|
+
const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
|
|
529
|
+
const isPointerInsideReactTreeRef = React.useRef(false);
|
|
530
|
+
const handleClickRef = React.useRef(() => {
|
|
531
|
+
});
|
|
532
|
+
React.useEffect(() => {
|
|
533
|
+
const handlePointerDown = (event) => {
|
|
534
|
+
if (event.target && !isPointerInsideReactTreeRef.current) {
|
|
535
|
+
let handleAndDispatchPointerDownOutsideEvent2 = function() {
|
|
536
|
+
handleAndDispatchCustomEvent(
|
|
537
|
+
POINTER_DOWN_OUTSIDE,
|
|
538
|
+
handlePointerDownOutside,
|
|
539
|
+
eventDetail,
|
|
540
|
+
{ discrete: true }
|
|
541
|
+
);
|
|
542
|
+
};
|
|
543
|
+
const eventDetail = { originalEvent: event };
|
|
544
|
+
if (event.pointerType === "touch") {
|
|
545
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
546
|
+
handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
|
|
547
|
+
ownerDocument.addEventListener("click", handleClickRef.current, { once: true });
|
|
548
|
+
} else {
|
|
549
|
+
handleAndDispatchPointerDownOutsideEvent2();
|
|
550
|
+
}
|
|
551
|
+
} else {
|
|
552
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
553
|
+
}
|
|
554
|
+
isPointerInsideReactTreeRef.current = false;
|
|
555
|
+
};
|
|
556
|
+
const timerId = window.setTimeout(() => {
|
|
557
|
+
ownerDocument.addEventListener("pointerdown", handlePointerDown);
|
|
558
|
+
}, 0);
|
|
559
|
+
return () => {
|
|
560
|
+
window.clearTimeout(timerId);
|
|
561
|
+
ownerDocument.removeEventListener("pointerdown", handlePointerDown);
|
|
562
|
+
ownerDocument.removeEventListener("click", handleClickRef.current);
|
|
563
|
+
};
|
|
564
|
+
}, [ownerDocument, handlePointerDownOutside]);
|
|
565
|
+
return {
|
|
566
|
+
// ensures we check React component tree (not just DOM tree)
|
|
567
|
+
onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
|
|
568
|
+
};
|
|
569
|
+
}
|
|
570
|
+
function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
|
|
571
|
+
const handleFocusOutside = useCallbackRef(onFocusOutside);
|
|
572
|
+
const isFocusInsideReactTreeRef = React.useRef(false);
|
|
573
|
+
React.useEffect(() => {
|
|
574
|
+
const handleFocus = (event) => {
|
|
575
|
+
if (event.target && !isFocusInsideReactTreeRef.current) {
|
|
576
|
+
const eventDetail = { originalEvent: event };
|
|
577
|
+
handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
|
|
578
|
+
discrete: false
|
|
579
|
+
});
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
ownerDocument.addEventListener("focusin", handleFocus);
|
|
583
|
+
return () => ownerDocument.removeEventListener("focusin", handleFocus);
|
|
584
|
+
}, [ownerDocument, handleFocusOutside]);
|
|
585
|
+
return {
|
|
586
|
+
onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
|
|
587
|
+
onBlurCapture: () => isFocusInsideReactTreeRef.current = false
|
|
588
|
+
};
|
|
589
|
+
}
|
|
590
|
+
function dispatchUpdate() {
|
|
591
|
+
const event = new CustomEvent(CONTEXT_UPDATE);
|
|
592
|
+
document.dispatchEvent(event);
|
|
593
|
+
}
|
|
594
|
+
function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
|
|
595
|
+
const target = detail.originalEvent.target;
|
|
596
|
+
const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
|
|
597
|
+
if (handler) target.addEventListener(name, handler, { once: true });
|
|
598
|
+
if (discrete) {
|
|
599
|
+
dispatchDiscreteCustomEvent(target, event);
|
|
600
|
+
} else {
|
|
601
|
+
target.dispatchEvent(event);
|
|
602
|
+
}
|
|
603
|
+
}
|
|
604
|
+
export {
|
|
605
|
+
DismissableLayer as D,
|
|
606
|
+
Primitive as P,
|
|
607
|
+
useId as a,
|
|
608
|
+
Presence as b,
|
|
609
|
+
createContextScope as c,
|
|
610
|
+
composeEventHandlers as d,
|
|
611
|
+
useCallbackRef as e,
|
|
612
|
+
useLayoutEffect2 as f,
|
|
613
|
+
dispatchDiscreteCustomEvent as g,
|
|
614
|
+
useControllableState as u
|
|
615
|
+
};
|