@bccampus/ui-components 0.4.2 → 0.5.0

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 (165) hide show
  1. package/dist/_chunks/CompositeDataItem.js +204 -0
  2. package/dist/_chunks/createLucideIcon.js +103 -0
  3. package/dist/_chunks/index.js +125 -0
  4. package/dist/_chunks/index2.js +44 -0
  5. package/dist/_chunks/index3.js +533 -0
  6. package/dist/{utils-CRiPKpXj.js → _chunks/utils.js} +754 -526
  7. package/dist/components/index.d.ts +16 -0
  8. package/dist/components/index.js +84 -0
  9. package/dist/components/ui/banner.d.ts +10 -0
  10. package/dist/components/ui/banner.js +45 -0
  11. package/dist/components/ui/button.d.ts +11 -0
  12. package/dist/{button.js → components/ui/button.js} +11 -10
  13. package/dist/components/ui/card.d.ts +27 -0
  14. package/dist/components/ui/card.js +109 -0
  15. package/dist/components/ui/composite/CompositeData.d.ts +20 -0
  16. package/dist/components/ui/composite/CompositeData.js +89 -0
  17. package/dist/components/ui/composite/CompositeDataItem.d.ts +28 -0
  18. package/dist/components/ui/composite/CompositeDataItem.js +5 -0
  19. package/dist/components/ui/composite/FocusProvider/AbstractFocusProvider.d.ts +41 -0
  20. package/dist/components/ui/composite/FocusProvider/AbstractFocusProvider.js +35 -0
  21. package/dist/components/ui/composite/FocusProvider/ListboxFocusProvider.d.ts +16 -0
  22. package/dist/components/ui/composite/FocusProvider/ListboxFocusProvider.js +67 -0
  23. package/dist/components/ui/composite/FocusProvider/index.d.ts +2 -0
  24. package/dist/components/ui/composite/FocusProvider/index.js +6 -0
  25. package/dist/components/ui/composite/SelectionProvider/AbstractSelectionProvider.d.ts +23 -0
  26. package/dist/components/ui/composite/SelectionProvider/AbstractSelectionProvider.js +20 -0
  27. package/dist/components/ui/composite/SelectionProvider/MultipleSelectionProvider.d.ts +9 -0
  28. package/dist/components/ui/composite/SelectionProvider/MultipleSelectionProvider.js +20 -0
  29. package/dist/components/ui/composite/SelectionProvider/SingleSelectionProvider.d.ts +9 -0
  30. package/dist/components/ui/composite/SelectionProvider/SingleSelectionProvider.js +25 -0
  31. package/dist/components/ui/composite/SelectionProvider/index.d.ts +3 -0
  32. package/dist/components/ui/composite/SelectionProvider/index.js +8 -0
  33. package/dist/components/ui/composite/composite-component-item.d.ts +2 -0
  34. package/dist/components/ui/composite/composite-component-item.js +74 -0
  35. package/dist/components/ui/composite/composite-component.d.ts +2 -0
  36. package/dist/components/ui/composite/composite-component.js +66 -0
  37. package/dist/components/ui/composite/index.d.ts +7 -0
  38. package/dist/components/ui/composite/index.js +22 -0
  39. package/dist/components/ui/composite/listbox.d.ts +2 -0
  40. package/dist/components/ui/composite/listbox.js +58 -0
  41. package/dist/components/ui/composite/types.d.ts +82 -0
  42. package/dist/components/ui/composite/types.js +1 -0
  43. package/dist/components/ui/horizontal-list.d.ts +10 -0
  44. package/dist/components/ui/horizontal-list.js +82 -0
  45. package/dist/components/ui/icon-generator/generate-tiles.d.ts +4 -0
  46. package/dist/components/ui/icon-generator/generate-tiles.js +223 -0
  47. package/dist/components/ui/icon-generator/icon-generator.d.ts +3 -0
  48. package/dist/components/ui/icon-generator/icon-generator.js +82 -0
  49. package/dist/components/ui/icon-generator/index.d.ts +4 -0
  50. package/dist/components/ui/icon-generator/index.js +11 -0
  51. package/dist/components/ui/icon-generator/masked-image-generator.d.ts +3 -0
  52. package/dist/components/ui/icon-generator/masked-image-generator.js +31 -0
  53. package/dist/{masked-image-generator.d.ts → components/ui/icon-generator/types.d.ts} +48 -58
  54. package/dist/components/ui/icon-generator/types.js +30 -0
  55. package/dist/components/ui/input.d.ts +3 -0
  56. package/dist/{input.js → components/ui/input.js} +8 -8
  57. package/dist/components/ui/navigation-menu.d.ts +16 -0
  58. package/dist/components/ui/navigation-menu.js +1041 -0
  59. package/dist/components/ui/overlay.d.ts +7 -0
  60. package/dist/{overlay.js → components/ui/overlay.js} +7 -7
  61. package/dist/components/ui/page-header.d.ts +5 -0
  62. package/dist/{page-header.js → components/ui/page-header.js} +189 -181
  63. package/dist/components/ui/page-section.d.ts +8 -0
  64. package/dist/{page-section.js → components/ui/page-section.js} +7 -7
  65. package/dist/components/ui/page.d.ts +3 -0
  66. package/dist/components/ui/page.js +8 -0
  67. package/dist/components/ui/popover.d.ts +7 -0
  68. package/dist/components/ui/popover.js +3532 -0
  69. package/dist/components/ui/search-input.d.ts +3 -0
  70. package/dist/components/ui/search-input.js +24 -0
  71. package/dist/components/ui/tag.d.ts +10 -0
  72. package/dist/{tag.js → components/ui/tag.js} +10 -9
  73. package/dist/components/ui/typography/caption.d.ts +8 -0
  74. package/dist/components/ui/typography/caption.js +28 -0
  75. package/dist/components/ui/typography/index.d.ts +1 -0
  76. package/dist/components/ui/typography/index.js +5 -0
  77. package/dist/hooks/index.d.ts +3 -0
  78. package/dist/hooks/index.js +9 -0
  79. package/dist/hooks/use-effect-after-mount.d.ts +2 -0
  80. package/dist/hooks/use-effect-after-mount.js +24 -0
  81. package/dist/hooks/use-id.d.ts +1 -0
  82. package/dist/hooks/use-id.js +7 -0
  83. package/dist/hooks/use-keyboard-event.d.ts +59 -0
  84. package/dist/hooks/use-keyboard-event.js +52 -0
  85. package/dist/lib/index.d.ts +3 -0
  86. package/dist/lib/index.js +16 -0
  87. package/dist/lib/object.d.ts +5 -0
  88. package/dist/lib/object.js +38 -0
  89. package/dist/lib/set-operations.d.ts +5 -0
  90. package/dist/lib/set-operations.js +51 -0
  91. package/dist/{utils.d.ts → lib/utils.d.ts} +2 -5
  92. package/dist/lib/utils.js +4 -0
  93. package/package.json +9 -76
  94. package/src/components/index.ts +17 -0
  95. package/src/components/ui/composite/FocusProvider/index.ts +2 -0
  96. package/src/components/ui/composite/SelectionProvider/MultipleSelectionProvider.ts +1 -1
  97. package/src/components/ui/composite/SelectionProvider/index.ts +3 -0
  98. package/src/components/ui/composite/index.ts +5 -5
  99. package/src/components/ui/icon-generator/index.ts +2 -0
  100. package/src/components/ui/typography/index.ts +1 -0
  101. package/src/hooks/index.ts +3 -0
  102. package/src/index.ts +3 -0
  103. package/src/lib/index.ts +3 -0
  104. package/tsconfig.lib.json +44 -0
  105. package/vite.config.ts +28 -31
  106. package/dist/AbstractFocusProvider-CxvlcEki.js +0 -29
  107. package/dist/AbstractSelectionProvider-BtaROstC.js +0 -30
  108. package/dist/CompositeDataItem-DuHOHCWy.js +0 -158
  109. package/dist/ListboxFocusProvider.d.ts +0 -149
  110. package/dist/ListboxFocusProvider.js +0 -53
  111. package/dist/MultipleSelectionProvider.d.ts +0 -141
  112. package/dist/MultipleSelectionProvider.js +0 -19
  113. package/dist/SingleSelectionProvider.d.ts +0 -141
  114. package/dist/SingleSelectionProvider.js +0 -23
  115. package/dist/banner.d.ts +0 -16
  116. package/dist/banner.js +0 -42
  117. package/dist/button.d.ts +0 -17
  118. package/dist/caption.d.ts +0 -13
  119. package/dist/caption.js +0 -27
  120. package/dist/card.d.ts +0 -46
  121. package/dist/card.js +0 -108
  122. package/dist/composite-component-DSUbd1XS.js +0 -122
  123. package/dist/composite.d.ts +0 -208
  124. package/dist/composite.js +0 -82
  125. package/dist/createLucideIcon-CzehbSja.js +0 -94
  126. package/dist/generate-tiles-DuagGD1d.js +0 -244
  127. package/dist/generate-tiles.d.ts +0 -43
  128. package/dist/generate-tiles.js +0 -7
  129. package/dist/horizontal-list.d.ts +0 -16
  130. package/dist/horizontal-list.js +0 -77
  131. package/dist/icon-generator-tuhuqdpL.js +0 -76
  132. package/dist/icon-generator.d.ts +0 -58
  133. package/dist/icon-generator.js +0 -6
  134. package/dist/index-CQhYMnjT.js +0 -34
  135. package/dist/index-U7DVCmS_.js +0 -76
  136. package/dist/input.d.ts +0 -7
  137. package/dist/listbox.d.ts +0 -171
  138. package/dist/listbox.js +0 -76
  139. package/dist/masked-image-generator.js +0 -29
  140. package/dist/navigation-menu.d.ts +0 -27
  141. package/dist/navigation-menu.js +0 -1139
  142. package/dist/overlay.d.ts +0 -13
  143. package/dist/page-header.d.ts +0 -9
  144. package/dist/page-section.d.ts +0 -14
  145. package/dist/page.d.ts +0 -7
  146. package/dist/page.js +0 -8
  147. package/dist/search-input.d.ts +0 -7
  148. package/dist/search-input.js +0 -23
  149. package/dist/tag.d.ts +0 -16
  150. package/dist/ui-components.d.ts +0 -215
  151. package/dist/ui-components.js +0 -54
  152. package/dist/utils.js +0 -4
  153. package/src/assets/icons/icon_01.svg +0 -6
  154. package/src/assets/icons/icon_02.svg +0 -6
  155. package/src/assets/icons/icon_03.svg +0 -6
  156. package/src/assets/icons/icon_04.svg +0 -6
  157. package/src/assets/icons/icon_05.svg +0 -4
  158. package/src/assets/icons/icon_06.svg +0 -4
  159. package/src/assets/images/image_01.jpg +0 -0
  160. package/src/assets/images/image_02.jpg +0 -0
  161. package/src/assets/images/image_03.webp +0 -0
  162. package/src/assets/images/image_04.png +0 -0
  163. package/src/assets/images/image_05.jpg +0 -0
  164. package/src/assets/images/image_06.jpg +0 -0
  165. package/src/components/ui/index.ts +0 -15
@@ -0,0 +1,533 @@
1
+ import * as React from "react";
2
+ import { jsx } from "react/jsx-runtime";
3
+ import { c as createSlot, u as useComposedRefs } from "./index.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
+ var NODES = [
71
+ "a",
72
+ "button",
73
+ "div",
74
+ "form",
75
+ "h2",
76
+ "h3",
77
+ "img",
78
+ "input",
79
+ "label",
80
+ "li",
81
+ "nav",
82
+ "ol",
83
+ "p",
84
+ "select",
85
+ "span",
86
+ "svg",
87
+ "ul"
88
+ ];
89
+ var Primitive = NODES.reduce((primitive, node) => {
90
+ const Slot = createSlot(`Primitive.${node}`);
91
+ const Node = React.forwardRef((props, forwardedRef) => {
92
+ const { asChild, ...primitiveProps } = props;
93
+ const Comp = asChild ? Slot : node;
94
+ if (typeof window !== "undefined") {
95
+ window[Symbol.for("radix-ui")] = true;
96
+ }
97
+ return /* @__PURE__ */ jsx(Comp, { ...primitiveProps, ref: forwardedRef });
98
+ });
99
+ Node.displayName = `Primitive.${node}`;
100
+ return { ...primitive, [node]: Node };
101
+ }, {});
102
+ function dispatchDiscreteCustomEvent(target, event) {
103
+ if (target) ReactDOM.flushSync(() => target.dispatchEvent(event));
104
+ }
105
+ var useLayoutEffect2 = globalThis?.document ? React.useLayoutEffect : () => {
106
+ };
107
+ var useInsertionEffect = React[" useInsertionEffect ".trim().toString()] || useLayoutEffect2;
108
+ function useControllableState({
109
+ prop,
110
+ defaultProp,
111
+ onChange = () => {
112
+ },
113
+ caller
114
+ }) {
115
+ const [uncontrolledProp, setUncontrolledProp, onChangeRef] = useUncontrolledState({
116
+ defaultProp,
117
+ onChange
118
+ });
119
+ const isControlled = prop !== void 0;
120
+ const value = isControlled ? prop : uncontrolledProp;
121
+ {
122
+ const isControlledRef = React.useRef(prop !== void 0);
123
+ React.useEffect(() => {
124
+ const wasControlled = isControlledRef.current;
125
+ if (wasControlled !== isControlled) {
126
+ const from = wasControlled ? "controlled" : "uncontrolled";
127
+ const to = isControlled ? "controlled" : "uncontrolled";
128
+ console.warn(
129
+ `${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.`
130
+ );
131
+ }
132
+ isControlledRef.current = isControlled;
133
+ }, [isControlled, caller]);
134
+ }
135
+ const setValue = React.useCallback(
136
+ (nextValue) => {
137
+ if (isControlled) {
138
+ const value2 = isFunction(nextValue) ? nextValue(prop) : nextValue;
139
+ if (value2 !== prop) {
140
+ onChangeRef.current?.(value2);
141
+ }
142
+ } else {
143
+ setUncontrolledProp(nextValue);
144
+ }
145
+ },
146
+ [isControlled, prop, setUncontrolledProp, onChangeRef]
147
+ );
148
+ return [value, setValue];
149
+ }
150
+ function useUncontrolledState({
151
+ defaultProp,
152
+ onChange
153
+ }) {
154
+ const [value, setValue] = React.useState(defaultProp);
155
+ const prevValueRef = React.useRef(value);
156
+ const onChangeRef = React.useRef(onChange);
157
+ useInsertionEffect(() => {
158
+ onChangeRef.current = onChange;
159
+ }, [onChange]);
160
+ React.useEffect(() => {
161
+ if (prevValueRef.current !== value) {
162
+ onChangeRef.current?.(value);
163
+ prevValueRef.current = value;
164
+ }
165
+ }, [value, prevValueRef]);
166
+ return [value, setValue, onChangeRef];
167
+ }
168
+ function isFunction(value) {
169
+ return typeof value === "function";
170
+ }
171
+ function useStateMachine(initialState, machine) {
172
+ return React.useReducer((state, event) => {
173
+ const nextState = machine[state][event];
174
+ return nextState ?? state;
175
+ }, initialState);
176
+ }
177
+ var Presence = (props) => {
178
+ const { present, children } = props;
179
+ const presence = usePresence(present);
180
+ const child = typeof children === "function" ? children({ present: presence.isPresent }) : React.Children.only(children);
181
+ const ref = useComposedRefs(presence.ref, getElementRef(child));
182
+ const forceMount = typeof children === "function";
183
+ return forceMount || presence.isPresent ? React.cloneElement(child, { ref }) : null;
184
+ };
185
+ Presence.displayName = "Presence";
186
+ function usePresence(present) {
187
+ const [node, setNode] = React.useState();
188
+ const stylesRef = React.useRef(null);
189
+ const prevPresentRef = React.useRef(present);
190
+ const prevAnimationNameRef = React.useRef("none");
191
+ const initialState = present ? "mounted" : "unmounted";
192
+ const [state, send] = useStateMachine(initialState, {
193
+ mounted: {
194
+ UNMOUNT: "unmounted",
195
+ ANIMATION_OUT: "unmountSuspended"
196
+ },
197
+ unmountSuspended: {
198
+ MOUNT: "mounted",
199
+ ANIMATION_END: "unmounted"
200
+ },
201
+ unmounted: {
202
+ MOUNT: "mounted"
203
+ }
204
+ });
205
+ React.useEffect(() => {
206
+ const currentAnimationName = getAnimationName(stylesRef.current);
207
+ prevAnimationNameRef.current = state === "mounted" ? currentAnimationName : "none";
208
+ }, [state]);
209
+ useLayoutEffect2(() => {
210
+ const styles = stylesRef.current;
211
+ const wasPresent = prevPresentRef.current;
212
+ const hasPresentChanged = wasPresent !== present;
213
+ if (hasPresentChanged) {
214
+ const prevAnimationName = prevAnimationNameRef.current;
215
+ const currentAnimationName = getAnimationName(styles);
216
+ if (present) {
217
+ send("MOUNT");
218
+ } else if (currentAnimationName === "none" || styles?.display === "none") {
219
+ send("UNMOUNT");
220
+ } else {
221
+ const isAnimating = prevAnimationName !== currentAnimationName;
222
+ if (wasPresent && isAnimating) {
223
+ send("ANIMATION_OUT");
224
+ } else {
225
+ send("UNMOUNT");
226
+ }
227
+ }
228
+ prevPresentRef.current = present;
229
+ }
230
+ }, [present, send]);
231
+ useLayoutEffect2(() => {
232
+ if (node) {
233
+ let timeoutId;
234
+ const ownerWindow = node.ownerDocument.defaultView ?? window;
235
+ const handleAnimationEnd = (event) => {
236
+ const currentAnimationName = getAnimationName(stylesRef.current);
237
+ const isCurrentAnimation = currentAnimationName.includes(CSS.escape(event.animationName));
238
+ if (event.target === node && isCurrentAnimation) {
239
+ send("ANIMATION_END");
240
+ if (!prevPresentRef.current) {
241
+ const currentFillMode = node.style.animationFillMode;
242
+ node.style.animationFillMode = "forwards";
243
+ timeoutId = ownerWindow.setTimeout(() => {
244
+ if (node.style.animationFillMode === "forwards") {
245
+ node.style.animationFillMode = currentFillMode;
246
+ }
247
+ });
248
+ }
249
+ }
250
+ };
251
+ const handleAnimationStart = (event) => {
252
+ if (event.target === node) {
253
+ prevAnimationNameRef.current = getAnimationName(stylesRef.current);
254
+ }
255
+ };
256
+ node.addEventListener("animationstart", handleAnimationStart);
257
+ node.addEventListener("animationcancel", handleAnimationEnd);
258
+ node.addEventListener("animationend", handleAnimationEnd);
259
+ return () => {
260
+ ownerWindow.clearTimeout(timeoutId);
261
+ node.removeEventListener("animationstart", handleAnimationStart);
262
+ node.removeEventListener("animationcancel", handleAnimationEnd);
263
+ node.removeEventListener("animationend", handleAnimationEnd);
264
+ };
265
+ } else {
266
+ send("ANIMATION_END");
267
+ }
268
+ }, [node, send]);
269
+ return {
270
+ isPresent: ["mounted", "unmountSuspended"].includes(state),
271
+ ref: React.useCallback((node2) => {
272
+ stylesRef.current = node2 ? getComputedStyle(node2) : null;
273
+ setNode(node2);
274
+ }, [])
275
+ };
276
+ }
277
+ function getAnimationName(styles) {
278
+ return styles?.animationName || "none";
279
+ }
280
+ function getElementRef(element) {
281
+ let getter = Object.getOwnPropertyDescriptor(element.props, "ref")?.get;
282
+ let mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
283
+ if (mayWarn) {
284
+ return element.ref;
285
+ }
286
+ getter = Object.getOwnPropertyDescriptor(element, "ref")?.get;
287
+ mayWarn = getter && "isReactWarning" in getter && getter.isReactWarning;
288
+ if (mayWarn) {
289
+ return element.props.ref;
290
+ }
291
+ return element.props.ref || element.ref;
292
+ }
293
+ var useReactId = React[" useId ".trim().toString()] || (() => void 0);
294
+ var count = 0;
295
+ function useId(deterministicId) {
296
+ const [id, setId] = React.useState(useReactId());
297
+ useLayoutEffect2(() => {
298
+ setId((reactId) => reactId ?? String(count++));
299
+ }, [deterministicId]);
300
+ return id ? `radix-${id}` : "";
301
+ }
302
+ function useCallbackRef(callback) {
303
+ const callbackRef = React.useRef(callback);
304
+ React.useEffect(() => {
305
+ callbackRef.current = callback;
306
+ });
307
+ return React.useMemo(() => (...args) => callbackRef.current?.(...args), []);
308
+ }
309
+ function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
310
+ const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
311
+ React.useEffect(() => {
312
+ const handleKeyDown = (event) => {
313
+ if (event.key === "Escape") {
314
+ onEscapeKeyDown(event);
315
+ }
316
+ };
317
+ ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
318
+ return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
319
+ }, [onEscapeKeyDown, ownerDocument]);
320
+ }
321
+ var DISMISSABLE_LAYER_NAME = "DismissableLayer";
322
+ var CONTEXT_UPDATE = "dismissableLayer.update";
323
+ var POINTER_DOWN_OUTSIDE = "dismissableLayer.pointerDownOutside";
324
+ var FOCUS_OUTSIDE = "dismissableLayer.focusOutside";
325
+ var originalBodyPointerEvents;
326
+ var DismissableLayerContext = React.createContext({
327
+ layers: /* @__PURE__ */ new Set(),
328
+ layersWithOutsidePointerEventsDisabled: /* @__PURE__ */ new Set(),
329
+ branches: /* @__PURE__ */ new Set()
330
+ });
331
+ var DismissableLayer = React.forwardRef(
332
+ (props, forwardedRef) => {
333
+ const {
334
+ disableOutsidePointerEvents = false,
335
+ onEscapeKeyDown,
336
+ onPointerDownOutside,
337
+ onFocusOutside,
338
+ onInteractOutside,
339
+ onDismiss,
340
+ ...layerProps
341
+ } = props;
342
+ const context = React.useContext(DismissableLayerContext);
343
+ const [node, setNode] = React.useState(null);
344
+ const ownerDocument = node?.ownerDocument ?? globalThis?.document;
345
+ const [, force] = React.useState({});
346
+ const composedRefs = useComposedRefs(forwardedRef, (node2) => setNode(node2));
347
+ const layers = Array.from(context.layers);
348
+ const [highestLayerWithOutsidePointerEventsDisabled] = [...context.layersWithOutsidePointerEventsDisabled].slice(-1);
349
+ const highestLayerWithOutsidePointerEventsDisabledIndex = layers.indexOf(highestLayerWithOutsidePointerEventsDisabled);
350
+ const index = node ? layers.indexOf(node) : -1;
351
+ const isBodyPointerEventsDisabled = context.layersWithOutsidePointerEventsDisabled.size > 0;
352
+ const isPointerEventsEnabled = index >= highestLayerWithOutsidePointerEventsDisabledIndex;
353
+ const pointerDownOutside = usePointerDownOutside((event) => {
354
+ const target = event.target;
355
+ const isPointerDownOnBranch = [...context.branches].some((branch) => branch.contains(target));
356
+ if (!isPointerEventsEnabled || isPointerDownOnBranch) return;
357
+ onPointerDownOutside?.(event);
358
+ onInteractOutside?.(event);
359
+ if (!event.defaultPrevented) onDismiss?.();
360
+ }, ownerDocument);
361
+ const focusOutside = useFocusOutside((event) => {
362
+ const target = event.target;
363
+ const isFocusInBranch = [...context.branches].some((branch) => branch.contains(target));
364
+ if (isFocusInBranch) return;
365
+ onFocusOutside?.(event);
366
+ onInteractOutside?.(event);
367
+ if (!event.defaultPrevented) onDismiss?.();
368
+ }, ownerDocument);
369
+ useEscapeKeydown((event) => {
370
+ const isHighestLayer = index === context.layers.size - 1;
371
+ if (!isHighestLayer) return;
372
+ onEscapeKeyDown?.(event);
373
+ if (!event.defaultPrevented && onDismiss) {
374
+ event.preventDefault();
375
+ onDismiss();
376
+ }
377
+ }, ownerDocument);
378
+ React.useEffect(() => {
379
+ if (!node) return;
380
+ if (disableOutsidePointerEvents) {
381
+ if (context.layersWithOutsidePointerEventsDisabled.size === 0) {
382
+ originalBodyPointerEvents = ownerDocument.body.style.pointerEvents;
383
+ ownerDocument.body.style.pointerEvents = "none";
384
+ }
385
+ context.layersWithOutsidePointerEventsDisabled.add(node);
386
+ }
387
+ context.layers.add(node);
388
+ dispatchUpdate();
389
+ return () => {
390
+ if (disableOutsidePointerEvents && context.layersWithOutsidePointerEventsDisabled.size === 1) {
391
+ ownerDocument.body.style.pointerEvents = originalBodyPointerEvents;
392
+ }
393
+ };
394
+ }, [node, ownerDocument, disableOutsidePointerEvents, context]);
395
+ React.useEffect(() => {
396
+ return () => {
397
+ if (!node) return;
398
+ context.layers.delete(node);
399
+ context.layersWithOutsidePointerEventsDisabled.delete(node);
400
+ dispatchUpdate();
401
+ };
402
+ }, [node, context]);
403
+ React.useEffect(() => {
404
+ const handleUpdate = () => force({});
405
+ document.addEventListener(CONTEXT_UPDATE, handleUpdate);
406
+ return () => document.removeEventListener(CONTEXT_UPDATE, handleUpdate);
407
+ }, []);
408
+ return /* @__PURE__ */ jsx(
409
+ Primitive.div,
410
+ {
411
+ ...layerProps,
412
+ ref: composedRefs,
413
+ style: {
414
+ pointerEvents: isBodyPointerEventsDisabled ? isPointerEventsEnabled ? "auto" : "none" : void 0,
415
+ ...props.style
416
+ },
417
+ onFocusCapture: composeEventHandlers(props.onFocusCapture, focusOutside.onFocusCapture),
418
+ onBlurCapture: composeEventHandlers(props.onBlurCapture, focusOutside.onBlurCapture),
419
+ onPointerDownCapture: composeEventHandlers(
420
+ props.onPointerDownCapture,
421
+ pointerDownOutside.onPointerDownCapture
422
+ )
423
+ }
424
+ );
425
+ }
426
+ );
427
+ DismissableLayer.displayName = DISMISSABLE_LAYER_NAME;
428
+ var BRANCH_NAME = "DismissableLayerBranch";
429
+ var DismissableLayerBranch = React.forwardRef((props, forwardedRef) => {
430
+ const context = React.useContext(DismissableLayerContext);
431
+ const ref = React.useRef(null);
432
+ const composedRefs = useComposedRefs(forwardedRef, ref);
433
+ React.useEffect(() => {
434
+ const node = ref.current;
435
+ if (node) {
436
+ context.branches.add(node);
437
+ return () => {
438
+ context.branches.delete(node);
439
+ };
440
+ }
441
+ }, [context.branches]);
442
+ return /* @__PURE__ */ jsx(Primitive.div, { ...props, ref: composedRefs });
443
+ });
444
+ DismissableLayerBranch.displayName = BRANCH_NAME;
445
+ function usePointerDownOutside(onPointerDownOutside, ownerDocument = globalThis?.document) {
446
+ const handlePointerDownOutside = useCallbackRef(onPointerDownOutside);
447
+ const isPointerInsideReactTreeRef = React.useRef(false);
448
+ const handleClickRef = React.useRef(() => {
449
+ });
450
+ React.useEffect(() => {
451
+ const handlePointerDown = (event) => {
452
+ if (event.target && !isPointerInsideReactTreeRef.current) {
453
+ let handleAndDispatchPointerDownOutsideEvent2 = function() {
454
+ handleAndDispatchCustomEvent(
455
+ POINTER_DOWN_OUTSIDE,
456
+ handlePointerDownOutside,
457
+ eventDetail,
458
+ { discrete: true }
459
+ );
460
+ };
461
+ const eventDetail = { originalEvent: event };
462
+ if (event.pointerType === "touch") {
463
+ ownerDocument.removeEventListener("click", handleClickRef.current);
464
+ handleClickRef.current = handleAndDispatchPointerDownOutsideEvent2;
465
+ ownerDocument.addEventListener("click", handleClickRef.current, { once: true });
466
+ } else {
467
+ handleAndDispatchPointerDownOutsideEvent2();
468
+ }
469
+ } else {
470
+ ownerDocument.removeEventListener("click", handleClickRef.current);
471
+ }
472
+ isPointerInsideReactTreeRef.current = false;
473
+ };
474
+ const timerId = window.setTimeout(() => {
475
+ ownerDocument.addEventListener("pointerdown", handlePointerDown);
476
+ }, 0);
477
+ return () => {
478
+ window.clearTimeout(timerId);
479
+ ownerDocument.removeEventListener("pointerdown", handlePointerDown);
480
+ ownerDocument.removeEventListener("click", handleClickRef.current);
481
+ };
482
+ }, [ownerDocument, handlePointerDownOutside]);
483
+ return {
484
+ // ensures we check React component tree (not just DOM tree)
485
+ onPointerDownCapture: () => isPointerInsideReactTreeRef.current = true
486
+ };
487
+ }
488
+ function useFocusOutside(onFocusOutside, ownerDocument = globalThis?.document) {
489
+ const handleFocusOutside = useCallbackRef(onFocusOutside);
490
+ const isFocusInsideReactTreeRef = React.useRef(false);
491
+ React.useEffect(() => {
492
+ const handleFocus = (event) => {
493
+ if (event.target && !isFocusInsideReactTreeRef.current) {
494
+ const eventDetail = { originalEvent: event };
495
+ handleAndDispatchCustomEvent(FOCUS_OUTSIDE, handleFocusOutside, eventDetail, {
496
+ discrete: false
497
+ });
498
+ }
499
+ };
500
+ ownerDocument.addEventListener("focusin", handleFocus);
501
+ return () => ownerDocument.removeEventListener("focusin", handleFocus);
502
+ }, [ownerDocument, handleFocusOutside]);
503
+ return {
504
+ onFocusCapture: () => isFocusInsideReactTreeRef.current = true,
505
+ onBlurCapture: () => isFocusInsideReactTreeRef.current = false
506
+ };
507
+ }
508
+ function dispatchUpdate() {
509
+ const event = new CustomEvent(CONTEXT_UPDATE);
510
+ document.dispatchEvent(event);
511
+ }
512
+ function handleAndDispatchCustomEvent(name, handler, detail, { discrete }) {
513
+ const target = detail.originalEvent.target;
514
+ const event = new CustomEvent(name, { bubbles: false, cancelable: true, detail });
515
+ if (handler) target.addEventListener(name, handler, { once: true });
516
+ if (discrete) {
517
+ dispatchDiscreteCustomEvent(target, event);
518
+ } else {
519
+ target.dispatchEvent(event);
520
+ }
521
+ }
522
+ export {
523
+ DismissableLayer as D,
524
+ Primitive as P,
525
+ useId as a,
526
+ Presence as b,
527
+ createContextScope as c,
528
+ composeEventHandlers as d,
529
+ useCallbackRef as e,
530
+ useLayoutEffect2 as f,
531
+ dispatchDiscreteCustomEvent as g,
532
+ useControllableState as u
533
+ };