@payloadcms/ui 3.69.0-internal.424436e → 3.69.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 (241) hide show
  1. package/dist/elements/AppHeader/index.js +1 -2
  2. package/dist/elements/AppHeader/index.js.map +1 -1
  3. package/dist/elements/AppHeader/index.scss +0 -1
  4. package/dist/elements/ArrayAction/index.d.ts +6 -6
  5. package/dist/elements/ArrayAction/index.d.ts.map +1 -1
  6. package/dist/elements/ArrayAction/index.js +8 -8
  7. package/dist/elements/ArrayAction/index.js.map +1 -1
  8. package/dist/elements/Autosave/index.d.ts.map +1 -1
  9. package/dist/elements/Autosave/index.js +20 -5
  10. package/dist/elements/Autosave/index.js.map +1 -1
  11. package/dist/elements/BulkUpload/FormsManager/index.d.ts.map +1 -1
  12. package/dist/elements/BulkUpload/FormsManager/index.js +10 -6
  13. package/dist/elements/BulkUpload/FormsManager/index.js.map +1 -1
  14. package/dist/elements/CopyLocaleData/index.d.ts.map +1 -1
  15. package/dist/elements/CopyLocaleData/index.js +36 -39
  16. package/dist/elements/CopyLocaleData/index.js.map +1 -1
  17. package/dist/elements/DefaultListViewTabs/index.d.ts.map +1 -1
  18. package/dist/elements/DefaultListViewTabs/index.js +1 -2
  19. package/dist/elements/DefaultListViewTabs/index.js.map +1 -1
  20. package/dist/elements/DeleteDocument/index.d.ts.map +1 -1
  21. package/dist/elements/DeleteDocument/index.js +9 -7
  22. package/dist/elements/DeleteDocument/index.js.map +1 -1
  23. package/dist/elements/DeleteMany/index.d.ts.map +1 -1
  24. package/dist/elements/DeleteMany/index.js +19 -16
  25. package/dist/elements/DeleteMany/index.js.map +1 -1
  26. package/dist/elements/DocumentControls/index.d.ts.map +1 -1
  27. package/dist/elements/DocumentControls/index.js +2 -4
  28. package/dist/elements/DocumentControls/index.js.map +1 -1
  29. package/dist/elements/DuplicateDocument/index.d.ts.map +1 -1
  30. package/dist/elements/DuplicateDocument/index.js +4 -6
  31. package/dist/elements/DuplicateDocument/index.js.map +1 -1
  32. package/dist/elements/EditMany/DrawerContent.d.ts.map +1 -1
  33. package/dist/elements/EditMany/DrawerContent.js +8 -12
  34. package/dist/elements/EditMany/DrawerContent.js.map +1 -1
  35. package/dist/elements/FolderView/BrowseByFolderButton/index.d.ts.map +1 -1
  36. package/dist/elements/FolderView/BrowseByFolderButton/index.js +2 -4
  37. package/dist/elements/FolderView/BrowseByFolderButton/index.js.map +1 -1
  38. package/dist/elements/FolderView/Cell/index.client.d.ts.map +1 -1
  39. package/dist/elements/FolderView/Cell/index.client.js +9 -2
  40. package/dist/elements/FolderView/Cell/index.client.js.map +1 -1
  41. package/dist/elements/FolderView/CurrentFolderActions/index.d.ts.map +1 -1
  42. package/dist/elements/FolderView/CurrentFolderActions/index.js +7 -4
  43. package/dist/elements/FolderView/CurrentFolderActions/index.js.map +1 -1
  44. package/dist/elements/FolderView/MoveDocToFolder/index.d.ts +1 -1
  45. package/dist/elements/FolderView/MoveDocToFolder/index.d.ts.map +1 -1
  46. package/dist/elements/FolderView/MoveDocToFolder/index.js +5 -1
  47. package/dist/elements/FolderView/MoveDocToFolder/index.js.map +1 -1
  48. package/dist/elements/IDLabel/index.d.ts.map +1 -1
  49. package/dist/elements/IDLabel/index.js +11 -14
  50. package/dist/elements/IDLabel/index.js.map +1 -1
  51. package/dist/elements/ItemsDrawer/ItemSearch/index.d.ts +8 -0
  52. package/dist/elements/ItemsDrawer/ItemSearch/index.d.ts.map +1 -0
  53. package/dist/elements/ItemsDrawer/ItemSearch/index.js +56 -0
  54. package/dist/elements/ItemsDrawer/ItemSearch/index.js.map +1 -0
  55. package/dist/elements/ItemsDrawer/ItemSearch/index.scss +38 -0
  56. package/dist/elements/ItemsDrawer/index.d.ts +15 -0
  57. package/dist/elements/ItemsDrawer/index.d.ts.map +1 -0
  58. package/dist/elements/ItemsDrawer/index.js +195 -0
  59. package/dist/elements/ItemsDrawer/index.js.map +1 -0
  60. package/dist/elements/ItemsDrawer/index.scss +102 -0
  61. package/dist/elements/Link/index.d.ts.map +1 -1
  62. package/dist/elements/Link/index.js +5 -3
  63. package/dist/elements/Link/index.js.map +1 -1
  64. package/dist/elements/ListControls/index.d.ts.map +1 -1
  65. package/dist/elements/ListControls/index.js +6 -4
  66. package/dist/elements/ListControls/index.js.map +1 -1
  67. package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.d.ts.map +1 -1
  68. package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js +9 -2
  69. package/dist/elements/ListHeader/TitleActions/ListEmptyTrashButton.js.map +1 -1
  70. package/dist/elements/Logout/index.d.ts.map +1 -1
  71. package/dist/elements/Logout/index.js +8 -11
  72. package/dist/elements/Logout/index.js.map +1 -1
  73. package/dist/elements/PermanentlyDeleteButton/index.d.ts.map +1 -1
  74. package/dist/elements/PermanentlyDeleteButton/index.js +19 -14
  75. package/dist/elements/PermanentlyDeleteButton/index.js.map +1 -1
  76. package/dist/elements/Popup/PopupButtonList/index.scss +1 -0
  77. package/dist/elements/Popup/PopupTrigger/index.d.ts +1 -1
  78. package/dist/elements/Popup/PopupTrigger/index.d.ts.map +1 -1
  79. package/dist/elements/Popup/PopupTrigger/index.js +24 -92
  80. package/dist/elements/Popup/PopupTrigger/index.js.map +1 -1
  81. package/dist/elements/Popup/index.d.ts +32 -1
  82. package/dist/elements/Popup/index.d.ts.map +1 -1
  83. package/dist/elements/Popup/index.js +249 -122
  84. package/dist/elements/Popup/index.js.map +1 -1
  85. package/dist/elements/Popup/index.scss +49 -231
  86. package/dist/elements/PublishButton/ScheduleDrawer/index.d.ts.map +1 -1
  87. package/dist/elements/PublishButton/ScheduleDrawer/index.js +6 -2
  88. package/dist/elements/PublishButton/ScheduleDrawer/index.js.map +1 -1
  89. package/dist/elements/PublishButton/index.d.ts.map +1 -1
  90. package/dist/elements/PublishButton/index.js +14 -4
  91. package/dist/elements/PublishButton/index.js.map +1 -1
  92. package/dist/elements/PublishMany/DrawerContent.d.ts.map +1 -1
  93. package/dist/elements/PublishMany/DrawerContent.js +8 -5
  94. package/dist/elements/PublishMany/DrawerContent.js.map +1 -1
  95. package/dist/elements/QueryPresets/QueryPresetBar/index.d.ts.map +1 -1
  96. package/dist/elements/QueryPresets/QueryPresetBar/index.js +7 -9
  97. package/dist/elements/QueryPresets/QueryPresetBar/index.js.map +1 -1
  98. package/dist/elements/RestoreButton/index.d.ts.map +1 -1
  99. package/dist/elements/RestoreButton/index.js +19 -14
  100. package/dist/elements/RestoreButton/index.js.map +1 -1
  101. package/dist/elements/RestoreMany/index.d.ts.map +1 -1
  102. package/dist/elements/RestoreMany/index.js +17 -14
  103. package/dist/elements/RestoreMany/index.js.map +1 -1
  104. package/dist/elements/SaveDraftButton/index.d.ts.map +1 -1
  105. package/dist/elements/SaveDraftButton/index.js +11 -5
  106. package/dist/elements/SaveDraftButton/index.js.map +1 -1
  107. package/dist/elements/Status/index.d.ts.map +1 -1
  108. package/dist/elements/Status/index.js +11 -5
  109. package/dist/elements/Status/index.js.map +1 -1
  110. package/dist/elements/StayLoggedIn/index.d.ts.map +1 -1
  111. package/dist/elements/StayLoggedIn/index.js +17 -20
  112. package/dist/elements/StayLoggedIn/index.js.map +1 -1
  113. package/dist/elements/StepNav/context.d.ts.map +1 -1
  114. package/dist/elements/StepNav/context.js +9 -1
  115. package/dist/elements/StepNav/context.js.map +1 -1
  116. package/dist/elements/StepNav/index.scss +0 -1
  117. package/dist/elements/Table/DefaultCell/fields/Relationship/index.d.ts.map +1 -1
  118. package/dist/elements/Table/DefaultCell/fields/Relationship/index.js +39 -41
  119. package/dist/elements/Table/DefaultCell/fields/Relationship/index.js.map +1 -1
  120. package/dist/elements/Table/DefaultCell/index.d.ts.map +1 -1
  121. package/dist/elements/Table/DefaultCell/index.js +9 -12
  122. package/dist/elements/Table/DefaultCell/index.js.map +1 -1
  123. package/dist/elements/Table/OrderableTable.d.ts.map +1 -1
  124. package/dist/elements/Table/OrderableTable.js +5 -1
  125. package/dist/elements/Table/OrderableTable.js.map +1 -1
  126. package/dist/elements/Table/RelationshipProvider/index.d.ts.map +1 -1
  127. package/dist/elements/Table/RelationshipProvider/index.js +25 -24
  128. package/dist/elements/Table/RelationshipProvider/index.js.map +1 -1
  129. package/dist/elements/UnpublishMany/DrawerContent.d.ts.map +1 -1
  130. package/dist/elements/UnpublishMany/DrawerContent.js +8 -5
  131. package/dist/elements/UnpublishMany/DrawerContent.js.map +1 -1
  132. package/dist/elements/Upload/index.d.ts.map +1 -1
  133. package/dist/elements/Upload/index.js +7 -5
  134. package/dist/elements/Upload/index.js.map +1 -1
  135. package/dist/elements/WhereBuilder/Condition/Relationship/index.d.ts.map +1 -1
  136. package/dist/elements/WhereBuilder/Condition/Relationship/index.js +14 -8
  137. package/dist/elements/WhereBuilder/Condition/Relationship/index.js.map +1 -1
  138. package/dist/elements/withMergedProps/index.d.ts +1 -1
  139. package/dist/elements/withMergedProps/index.js +1 -1
  140. package/dist/elements/withMergedProps/index.js.map +1 -1
  141. package/dist/exports/client/index.d.ts +1 -2
  142. package/dist/exports/client/index.d.ts.map +1 -1
  143. package/dist/exports/client/index.js +12 -12
  144. package/dist/exports/client/index.js.map +4 -4
  145. package/dist/exports/rsc/index.d.ts +1 -0
  146. package/dist/exports/rsc/index.d.ts.map +1 -1
  147. package/dist/exports/rsc/index.js +1 -0
  148. package/dist/exports/rsc/index.js.map +1 -1
  149. package/dist/exports/shared/index.d.ts +3 -0
  150. package/dist/exports/shared/index.d.ts.map +1 -1
  151. package/dist/exports/shared/index.js +2 -2
  152. package/dist/exports/shared/index.js.map +4 -4
  153. package/dist/fields/Array/ArrayRow.d.ts +7 -18
  154. package/dist/fields/Array/ArrayRow.d.ts.map +1 -1
  155. package/dist/fields/Array/ArrayRow.js +133 -65
  156. package/dist/fields/Array/ArrayRow.js.map +1 -1
  157. package/dist/fields/Array/index.d.ts.map +1 -1
  158. package/dist/fields/Array/index.js +3 -10
  159. package/dist/fields/Array/index.js.map +1 -1
  160. package/dist/fields/Relationship/Input.d.ts.map +1 -1
  161. package/dist/fields/Relationship/Input.js +9 -3
  162. package/dist/fields/Relationship/Input.js.map +1 -1
  163. package/dist/fields/Upload/Input.d.ts.map +1 -1
  164. package/dist/fields/Upload/Input.js +7 -3
  165. package/dist/fields/Upload/Input.js.map +1 -1
  166. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.js +8 -1
  167. package/dist/forms/fieldSchemasToFormState/fieldSchemasToFormState.spec.js.map +1 -1
  168. package/dist/graphics/Account/index.d.ts.map +1 -1
  169. package/dist/graphics/Account/index.js +2 -4
  170. package/dist/graphics/Account/index.js.map +1 -1
  171. package/dist/providers/Auth/index.d.ts.map +1 -1
  172. package/dist/providers/Auth/index.js +23 -26
  173. package/dist/providers/Auth/index.js.map +1 -1
  174. package/dist/providers/DocumentInfo/index.d.ts +1 -1
  175. package/dist/providers/DocumentInfo/index.d.ts.map +1 -1
  176. package/dist/providers/DocumentInfo/index.js +16 -15
  177. package/dist/providers/DocumentInfo/index.js.map +1 -1
  178. package/dist/providers/DocumentInfo/useGetDocPermissions.d.ts +1 -2
  179. package/dist/providers/DocumentInfo/useGetDocPermissions.d.ts.map +1 -1
  180. package/dist/providers/DocumentInfo/useGetDocPermissions.js +16 -6
  181. package/dist/providers/DocumentInfo/useGetDocPermissions.js.map +1 -1
  182. package/dist/providers/Folders/index.d.ts.map +1 -1
  183. package/dist/providers/Folders/index.js +14 -11
  184. package/dist/providers/Folders/index.js.map +1 -1
  185. package/dist/providers/Locale/index.d.ts.map +1 -1
  186. package/dist/providers/Locale/index.js +45 -34
  187. package/dist/providers/Locale/index.js.map +1 -1
  188. package/dist/providers/Preferences/index.d.ts.map +1 -1
  189. package/dist/providers/Preferences/index.js +16 -7
  190. package/dist/providers/Preferences/index.js.map +1 -1
  191. package/dist/providers/RouteTransition/index.d.ts.map +1 -1
  192. package/dist/providers/RouteTransition/index.js +6 -1
  193. package/dist/providers/RouteTransition/index.js.map +1 -1
  194. package/dist/providers/TableColumns/buildColumnState/renderCell.d.ts.map +1 -1
  195. package/dist/providers/TableColumns/buildColumnState/renderCell.js +1 -2
  196. package/dist/providers/TableColumns/buildColumnState/renderCell.js.map +1 -1
  197. package/dist/scss/app.scss +14 -1
  198. package/dist/styles.css +1 -1
  199. package/dist/utilities/getGlobalData.d.ts +11 -0
  200. package/dist/utilities/getGlobalData.d.ts.map +1 -0
  201. package/dist/utilities/getGlobalData.js +49 -0
  202. package/dist/utilities/getGlobalData.js.map +1 -0
  203. package/dist/utilities/getNavGroups.d.ts +5 -0
  204. package/dist/utilities/getNavGroups.d.ts.map +1 -0
  205. package/dist/utilities/getNavGroups.js +22 -0
  206. package/dist/utilities/getNavGroups.js.map +1 -0
  207. package/dist/utilities/getVisibleEntities.d.ts +5 -0
  208. package/dist/utilities/getVisibleEntities.d.ts.map +1 -0
  209. package/dist/utilities/getVisibleEntities.js +31 -0
  210. package/dist/utilities/getVisibleEntities.js.map +1 -0
  211. package/dist/utilities/groupNavItems.d.ts +3 -0
  212. package/dist/utilities/groupNavItems.d.ts.map +1 -1
  213. package/dist/utilities/groupNavItems.js +3 -0
  214. package/dist/utilities/groupNavItems.js.map +1 -1
  215. package/dist/utilities/handleBackToDashboard.js +1 -1
  216. package/dist/utilities/handleBackToDashboard.js.map +1 -1
  217. package/dist/utilities/handleGoBack.d.ts.map +1 -1
  218. package/dist/utilities/handleGoBack.js +1 -2
  219. package/dist/utilities/handleGoBack.js.map +1 -1
  220. package/dist/utilities/normalizeRelationshipValue.spec.js +1 -1
  221. package/dist/utilities/normalizeRelationshipValue.spec.js.map +1 -1
  222. package/dist/views/CollectionFolder/index.js +2 -4
  223. package/dist/views/CollectionFolder/index.js.map +1 -1
  224. package/dist/views/Edit/Auth/index.d.ts.map +1 -1
  225. package/dist/views/Edit/Auth/index.js +22 -21
  226. package/dist/views/Edit/Auth/index.js.map +1 -1
  227. package/dist/views/Edit/SetDocumentStepNav/index.d.ts.map +1 -1
  228. package/dist/views/Edit/SetDocumentStepNav/index.js +36 -22
  229. package/dist/views/Edit/SetDocumentStepNav/index.js.map +1 -1
  230. package/dist/views/Edit/index.d.ts.map +1 -1
  231. package/dist/views/Edit/index.js +2 -3
  232. package/dist/views/Edit/index.js.map +1 -1
  233. package/dist/views/List/index.d.ts.map +1 -1
  234. package/dist/views/List/index.js +1 -2
  235. package/dist/views/List/index.js.map +1 -1
  236. package/dist/widgets/CollectionCards/index.d.ts +5 -0
  237. package/dist/widgets/CollectionCards/index.d.ts.map +1 -0
  238. package/dist/widgets/CollectionCards/index.js +135 -0
  239. package/dist/widgets/CollectionCards/index.js.map +1 -0
  240. package/dist/widgets/CollectionCards/index.scss +70 -0
  241. package/package.json +5 -5
@@ -2,16 +2,25 @@
2
2
 
3
3
  import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
4
4
  export * as PopupList from './PopupButtonList/index.js';
5
- import { useWindowInfo } from '@faceless-ui/window-info';
6
5
  import React, { useCallback, useEffect, useRef, useState } from 'react';
7
- import { useIntersect } from '../../hooks/useIntersect.js';
8
- import { PopupTrigger } from './PopupTrigger/index.js';
6
+ import { createPortal } from 'react-dom';
7
+ import { useEffectEvent } from '../../hooks/useEffectEvent.js';
9
8
  import './index.scss';
9
+ import { PopupTrigger } from './PopupTrigger/index.js';
10
10
  const baseClass = 'popup';
11
+ /**
12
+ * Selector for all elements the browser considers tabbable.
13
+ */
14
+ const TABBABLE_SELECTOR = ['a[href]', 'button:not(:disabled)', 'input:not(:disabled):not([type="hidden"])', 'select:not(:disabled)', 'textarea:not(:disabled)', '[tabindex]', '[contenteditable]:not([contenteditable="false"])', 'audio[controls]', 'video[controls]', 'summary'].map(s => `${s}:not([tabindex="-1"])`).join(', ');
15
+ /**
16
+ * Component that renders a popup, as well as a button that triggers the popup.
17
+ *
18
+ * The popup is rendered in a portal, and is automatically positioned above / below the trigger,
19
+ * depending on the verticalAlign prop and the space available.
20
+ */
11
21
  export const Popup = props => {
12
22
  const {
13
23
  id,
14
- boundingRef,
15
24
  button,
16
25
  buttonClassName,
17
26
  buttonSize,
@@ -21,7 +30,7 @@ export const Popup = props => {
21
30
  className,
22
31
  disabled,
23
32
  forceOpen,
24
- horizontalAlign: horizontalAlignFromProps = 'left',
33
+ horizontalAlign = 'left',
25
34
  initActive = false,
26
35
  noBackground,
27
36
  onToggleClose,
@@ -30,104 +39,239 @@ export const Popup = props => {
30
39
  showOnHover = false,
31
40
  showScrollbar = false,
32
41
  size = 'medium',
33
- verticalAlign: verticalAlignFromProps = 'top'
42
+ verticalAlign = 'bottom'
34
43
  } = props;
35
- const {
36
- height: windowHeight,
37
- width: windowWidth
38
- } = useWindowInfo();
39
- const [intersectionRef, intersectionEntry] = useIntersect({
40
- root: boundingRef?.current || null,
41
- rootMargin: '-100px 0px 0px 0px',
42
- threshold: 1
43
- });
44
- const contentRef = useRef(null);
44
+ const popupRef = useRef(null);
45
45
  const triggerRef = useRef(null);
46
- const [active, setActive_Internal] = useState(initActive);
47
- const [verticalAlign, setVerticalAlign] = useState(verticalAlignFromProps);
48
- const [horizontalAlign, setHorizontalAlign] = useState(horizontalAlignFromProps);
49
- const setActive = React.useCallback(active_0 => {
50
- if (active_0 && typeof onToggleOpen === 'function') {
51
- onToggleOpen(true);
52
- }
53
- if (!active_0 && typeof onToggleClose === 'function') {
54
- onToggleClose();
46
+ /**
47
+ * Keeps track of whether the popup was opened via keyboard.
48
+ * This is used to determine whether to autofocus the first element in the popup.
49
+ * If the popup was opened via mouse, we do not want to autofocus the first element.
50
+ */
51
+ const openedViaKeyboardRef = useRef(false);
52
+ const [mounted, setMounted] = useState(false);
53
+ const [active, setActiveInternal] = useState(initActive);
54
+ const [isOnTop, setIsOnTop] = useState(verticalAlign === 'top');
55
+ // Track when component is mounted to avoid SSR/client hydration mismatch
56
+ useEffect(() => {
57
+ setMounted(true);
58
+ }, []);
59
+ const setActive = useCallback((isActive, viaKeyboard = false) => {
60
+ if (isActive) {
61
+ openedViaKeyboardRef.current = viaKeyboard;
62
+ onToggleOpen?.(true);
63
+ } else {
64
+ onToggleClose?.();
55
65
  }
56
- setActive_Internal(active_0);
66
+ setActiveInternal(isActive);
57
67
  }, [onToggleClose, onToggleOpen]);
58
- const setPosition = useCallback(({
59
- horizontal = false,
60
- vertical = false
61
- }) => {
62
- if (contentRef.current) {
63
- const bounds = contentRef.current.getBoundingClientRect();
64
- const {
65
- bottom: contentBottomPos,
66
- left: contentLeftPos,
67
- right: contentRightPos,
68
- top: contentTopPos
69
- } = bounds;
70
- let boundingTopPos = 100;
71
- let boundingRightPos = document.documentElement.clientWidth;
72
- let boundingBottomPos = document.documentElement.clientHeight;
73
- let boundingLeftPos = 0;
74
- if (boundingRef?.current) {
75
- ;
76
- ({
77
- bottom: boundingBottomPos,
78
- left: boundingLeftPos,
79
- right: boundingRightPos,
80
- top: boundingTopPos
81
- } = boundingRef.current.getBoundingClientRect());
82
- }
83
- if (horizontal) {
84
- if (contentRightPos > boundingRightPos && contentLeftPos > boundingLeftPos) {
85
- setHorizontalAlign('right');
86
- } else if (contentLeftPos < boundingLeftPos && contentRightPos < boundingRightPos) {
87
- setHorizontalAlign('left');
88
- }
68
+ // /////////////////////////////////////
69
+ // Position Calculation
70
+ //
71
+ // Calculates and applies popup position relative to trigger.
72
+ // Always checks viewport bounds (for flipping), but only updates
73
+ // styles if the calculated position differs from current position.
74
+ // /////////////////////////////////////
75
+ const updatePosition = useEffectEvent(() => {
76
+ const trigger = triggerRef.current;
77
+ const popup = popupRef.current;
78
+ if (!trigger || !popup) {
79
+ return;
80
+ }
81
+ const triggerRect = trigger.getBoundingClientRect();
82
+ const popupRect = popup.getBoundingClientRect();
83
+ // Gap between the popup and the trigger/viewport edges (in pixels)
84
+ const offset = 10;
85
+ // /////////////////////////////////////
86
+ // Vertical Positioning
87
+ // Calculates the `top` position in absolute page coordinates.
88
+ // Uses `verticalAlign` prop as the preferred direction, but flips
89
+ // to the opposite side if there's not enough viewport space.
90
+ // /////////////////////////////////////
91
+ let top;
92
+ let onTop = verticalAlign === 'top';
93
+ if (verticalAlign === 'bottom') {
94
+ top = triggerRect.bottom + window.scrollY + offset;
95
+ if (triggerRect.bottom + popupRect.height + offset > window.innerHeight) {
96
+ top = triggerRect.top + window.scrollY - popupRect.height - offset;
97
+ onTop = true;
89
98
  }
90
- if (vertical) {
91
- if (contentTopPos < boundingTopPos && contentBottomPos < boundingBottomPos) {
92
- setVerticalAlign('bottom');
93
- } else if (contentBottomPos > boundingBottomPos && contentTopPos > boundingTopPos) {
94
- setVerticalAlign('top');
95
- }
99
+ } else {
100
+ top = triggerRect.top + window.scrollY - popupRect.height - offset;
101
+ if (triggerRect.top - popupRect.height - offset < 0) {
102
+ top = triggerRect.bottom + window.scrollY + offset;
103
+ onTop = false;
96
104
  }
97
105
  }
98
- }, [boundingRef]);
99
- const handleClickOutside = useCallback(e => {
100
- if (contentRef.current.contains(e.target) || triggerRef.current.contains(e.target)) {
106
+ setIsOnTop(onTop);
107
+ // /////////////////////////////////////
108
+ // Horizontal Positioning
109
+ // Calculates the `left` position based on `horizontalAlign` prop:
110
+ // - 'left': aligns popup's left edge with trigger's left edge
111
+ // - 'right': aligns popup's right edge with trigger's right edge
112
+ // - 'center': centers popup horizontally relative to trigger
113
+ // Then clamps to keep the popup within viewport bounds.
114
+ // /////////////////////////////////////
115
+ let left = horizontalAlign === 'right' ? triggerRect.right - popupRect.width : horizontalAlign === 'center' ? triggerRect.left + triggerRect.width / 2 - popupRect.width / 2 : triggerRect.left;
116
+ left = Math.max(offset, Math.min(left, window.innerWidth - popupRect.width - offset));
117
+ // /////////////////////////////////////
118
+ // Caret Positioning
119
+ // Positions the caret arrow to point at the trigger's horizontal center.
120
+ // Clamps between 12px from edges to prevent caret from overflowing the popup.
121
+ // /////////////////////////////////////
122
+ const triggerCenter = triggerRect.left + triggerRect.width / 2;
123
+ const caretLeft = Math.max(12, Math.min(triggerCenter - left, popupRect.width - 12));
124
+ // /////////////////////////////////////
125
+ // Apply Styles (only if changed)
126
+ // Compares calculated position with current styles to avoid unnecessary
127
+ // DOM updates during scroll. This prevents visual lag by relying on the absolute
128
+ // positioning where possible (popup slightly lags behind when scrolling really fast),
129
+ // while still allowing position changes when needed (e.g., sticky parent, viewport flip).
130
+ // Values are rounded to match browser's CSS precision and avoid false updates.
131
+ // /////////////////////////////////////
132
+ const newTop = `${Math.round(top)}px`;
133
+ const newLeft = `${Math.round(left + window.scrollX)}px`;
134
+ const newCaretLeft = `${Math.round(caretLeft)}px`;
135
+ if (popup.style.top !== newTop) {
136
+ popup.style.top = newTop;
137
+ }
138
+ if (popup.style.left !== newLeft) {
139
+ popup.style.left = newLeft;
140
+ }
141
+ if (popup.style.getPropertyValue('--caret-left') !== newCaretLeft) {
142
+ popup.style.setProperty('--caret-left', newCaretLeft);
143
+ }
144
+ });
145
+ // /////////////////////////////////////
146
+ // Click Outside Handler
147
+ // Closes popup when clicking outside both the popup and trigger.
148
+ // /////////////////////////////////////
149
+ const handleClickOutside = useEffectEvent(e => {
150
+ const isOutsidePopup = !popupRef.current?.contains(e.target);
151
+ const isOutsideTrigger = !triggerRef.current?.contains(e.target);
152
+ if (isOutsidePopup && isOutsideTrigger) {
153
+ setActive(false);
154
+ }
155
+ });
156
+ // /////////////////////////////////////
157
+ // Keyboard Navigation
158
+ // Handles keyboard interactions when popup is open:
159
+ // - Escape: closes popup and returns focus to trigger
160
+ // - Tab/Shift+Tab: cycles through focusable items with wrapping
161
+ // - ArrowUp/ArrowDown: same as Shift+Tab/Tab for menu-style navigation
162
+ // Focus is managed manually to support elements the browser might skip.
163
+ // /////////////////////////////////////
164
+ const handleKeyDown = useEffectEvent(e_0 => {
165
+ const popup_0 = popupRef.current;
166
+ if (!popup_0 || !active) {
101
167
  return;
102
168
  }
103
- setActive(false);
104
- }, [contentRef, setActive]);
105
- useEffect(() => {
106
- setPosition({
107
- horizontal: true
108
- });
109
- }, [intersectionEntry, setPosition, windowWidth]);
110
- useEffect(() => {
111
- setPosition({
112
- vertical: true
113
- });
114
- }, [intersectionEntry, setPosition, windowHeight]);
169
+ if (e_0.key === 'Escape') {
170
+ e_0.preventDefault();
171
+ setActive(false);
172
+ triggerRef.current?.querySelector('button, [tabindex="0"]')?.focus();
173
+ return;
174
+ }
175
+ if (e_0.key === 'Tab' || e_0.key === 'ArrowDown' || e_0.key === 'ArrowUp') {
176
+ const focusable = Array.from(popup_0.querySelectorAll(TABBABLE_SELECTOR));
177
+ if (focusable.length === 0) {
178
+ return;
179
+ }
180
+ e_0.preventDefault();
181
+ const currentIndex = focusable.findIndex(el => el === document.activeElement);
182
+ const goBackward = e_0.key === 'ArrowUp' || e_0.key === 'Tab' && e_0.shiftKey;
183
+ let nextIndex;
184
+ if (currentIndex === -1) {
185
+ nextIndex = goBackward ? focusable.length - 1 : 0;
186
+ } else if (goBackward) {
187
+ nextIndex = currentIndex === 0 ? focusable.length - 1 : currentIndex - 1;
188
+ } else {
189
+ nextIndex = currentIndex === focusable.length - 1 ? 0 : currentIndex + 1;
190
+ }
191
+ focusable[nextIndex].focus();
192
+ }
193
+ });
194
+ // /////////////////////////////////////
195
+ // Click Handler for Actionable Elements
196
+ // Closes popup when buttons/links inside are clicked (includes Enter/Space activation).
197
+ // /////////////////////////////////////
198
+ const handleActionableClick = useEffectEvent(e_1 => {
199
+ const target = e_1.target;
200
+ // Check if the clicked element or any ancestor is an actionable element
201
+ const actionable = target.closest('button, a[href], [role="button"], [role="menuitem"]');
202
+ if (actionable && popupRef.current?.contains(actionable)) {
203
+ setActive(false);
204
+ }
205
+ });
206
+ // /////////////////////////////////////
207
+ // Effect: Setup/Teardown position and focus management
208
+ // /////////////////////////////////////
115
209
  useEffect(() => {
116
- if (active) {
117
- document.addEventListener('mousedown', handleClickOutside);
118
- } else {
119
- document.removeEventListener('mousedown', handleClickOutside);
210
+ if (!active) {
211
+ return;
212
+ }
213
+ const popup_1 = popupRef.current;
214
+ if (!popup_1) {
215
+ return;
120
216
  }
217
+ // /////////////////////////////////////
218
+ // Initial Position
219
+ // Calculate and apply popup position immediately on open.
220
+ // /////////////////////////////////////
221
+ updatePosition();
222
+ // /////////////////////////////////////
223
+ // Focus Management
224
+ // When opened via keyboard, autofocus the first focusable button.
225
+ // When opened via mouse, skip autofocus to avoid unwanted highlights.
226
+ // /////////////////////////////////////
227
+ if (openedViaKeyboardRef.current) {
228
+ // Use requestAnimationFrame to ensure DOM is ready.
229
+ requestAnimationFrame(() => {
230
+ const firstFocusable = popup_1.querySelector(TABBABLE_SELECTOR);
231
+ firstFocusable?.focus();
232
+ });
233
+ }
234
+ // /////////////////////////////////////
235
+ // Event Listeners
236
+ // - resize/scroll: recalculate position (only applies styles if changed)
237
+ // - mousedown: detect clicks outside to close
238
+ // - keydown: handle keyboard navigation
239
+ // /////////////////////////////////////
240
+ window.addEventListener('resize', updatePosition);
241
+ window.addEventListener('scroll', updatePosition, {
242
+ capture: true,
243
+ passive: true
244
+ });
245
+ document.addEventListener('mousedown', handleClickOutside);
246
+ document.addEventListener('keydown', handleKeyDown);
247
+ popup_1.addEventListener('click', handleActionableClick);
121
248
  return () => {
249
+ window.removeEventListener('resize', updatePosition);
250
+ window.removeEventListener('scroll', updatePosition, {
251
+ capture: true
252
+ });
122
253
  document.removeEventListener('mousedown', handleClickOutside);
254
+ document.removeEventListener('keydown', handleKeyDown);
255
+ popup_1.removeEventListener('click', handleActionableClick);
123
256
  };
124
- }, [active, handleClickOutside, onToggleOpen]);
257
+ }, [active]);
125
258
  useEffect(() => {
126
- setActive(forceOpen);
259
+ if (forceOpen !== undefined) {
260
+ setActive(forceOpen);
261
+ }
127
262
  }, [forceOpen, setActive]);
128
- const classes = [baseClass, className, `${baseClass}--size-${size}`, buttonSize && `${baseClass}--button-size-${buttonSize}`, `${baseClass}--v-align-${verticalAlign}`, `${baseClass}--h-align-${horizontalAlign}`, active && `${baseClass}--active`, showScrollbar && `${baseClass}--show-scrollbar`].filter(Boolean).join(' ');
263
+ const Trigger = /*#__PURE__*/_jsx(PopupTrigger, {
264
+ active: active,
265
+ button: button,
266
+ buttonType: buttonType,
267
+ className: buttonClassName,
268
+ disabled: disabled,
269
+ noBackground: noBackground,
270
+ setActive: setActive,
271
+ size: buttonSize
272
+ });
129
273
  return /*#__PURE__*/_jsxs("div", {
130
- className: classes,
274
+ className: [baseClass, className].filter(Boolean).join(' '),
131
275
  id: id,
132
276
  children: [/*#__PURE__*/_jsx("div", {
133
277
  className: `${baseClass}__trigger-wrap`,
@@ -138,45 +282,28 @@ export const Popup = props => {
138
282
  onMouseLeave: () => setActive(false),
139
283
  role: "button",
140
284
  tabIndex: 0,
141
- children: /*#__PURE__*/_jsx(PopupTrigger, {
142
- active,
143
- button,
144
- buttonType,
145
- className: buttonClassName,
146
- disabled,
147
- noBackground,
148
- setActive,
149
- size: buttonSize
150
- })
151
- }) : /*#__PURE__*/_jsx(PopupTrigger, {
152
- active,
153
- button,
154
- buttonType,
155
- className: buttonClassName,
156
- disabled,
157
- noBackground,
158
- setActive,
159
- size: buttonSize
160
- })
161
- }), /*#__PURE__*/_jsxs("div", {
162
- className: `${baseClass}__content`,
163
- ref: contentRef,
164
- children: [/*#__PURE__*/_jsx("div", {
165
- className: `${baseClass}__hide-scrollbar`,
166
- ref: intersectionRef,
167
- children: /*#__PURE__*/_jsx("div", {
168
- className: `${baseClass}__scroll-container`,
169
- children: /*#__PURE__*/_jsxs("div", {
170
- className: `${baseClass}__scroll-content`,
171
- children: [render && render({
172
- close: () => setActive(false)
173
- }), children]
174
- })
175
- })
285
+ children: Trigger
286
+ }) : Trigger
287
+ }), mounted ?
288
+ // This ensures that components within the popup, like modals, do not unmount when the popup closes.
289
+ // Otherwise, modals opened from the popup will close unexpectedly when clicking within the modal, since
290
+ // that closes the popup due to the click outside handler.
291
+ /*#__PURE__*/
292
+ createPortal(/*#__PURE__*/_jsxs("div", {
293
+ className: active ? [`${baseClass}__content`, `${baseClass}--size-${size}`, isOnTop ? `${baseClass}--v-top` : `${baseClass}--v-bottom`].filter(Boolean).join(' ') :
294
+ // tests do not accidentally target inactive popups.
295
+ `${baseClass}__hidden-content`,
296
+ "data-popup-id": id || undefined,
297
+ ref: popupRef,
298
+ children: [/*#__PURE__*/_jsxs("div", {
299
+ className: `${baseClass}__scroll-container${showScrollbar ? ` ${baseClass}__scroll-container--show-scrollbar` : ''}`,
300
+ children: [render?.({
301
+ close: () => setActive(false)
302
+ }), children]
176
303
  }), caret && /*#__PURE__*/_jsx("div", {
177
304
  className: `${baseClass}__caret`
178
305
  })]
179
- })]
306
+ }), document.body) : null]
180
307
  });
181
308
  };
182
309
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["PopupList","useWindowInfo","React","useCallback","useEffect","useRef","useState","useIntersect","PopupTrigger","baseClass","Popup","props","id","boundingRef","button","buttonClassName","buttonSize","buttonType","caret","children","className","disabled","forceOpen","horizontalAlign","horizontalAlignFromProps","initActive","noBackground","onToggleClose","onToggleOpen","render","showOnHover","showScrollbar","size","verticalAlign","verticalAlignFromProps","height","windowHeight","width","windowWidth","intersectionRef","intersectionEntry","root","current","rootMargin","threshold","contentRef","triggerRef","active","setActive_Internal","setVerticalAlign","setHorizontalAlign","setActive","setPosition","horizontal","vertical","bounds","getBoundingClientRect","bottom","contentBottomPos","left","contentLeftPos","right","contentRightPos","top","contentTopPos","boundingTopPos","boundingRightPos","document","documentElement","clientWidth","boundingBottomPos","clientHeight","boundingLeftPos","handleClickOutside","e","contains","target","addEventListener","removeEventListener","classes","filter","Boolean","join","_jsxs","_jsx","ref","onMouseEnter","onMouseLeave","role","tabIndex","close"],"sources":["../../../src/elements/Popup/index.tsx"],"sourcesContent":["'use client'\nimport type { CSSProperties } from 'react'\n\nexport * as PopupList from './PopupButtonList/index.js'\n\nimport { useWindowInfo } from '@faceless-ui/window-info'\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\n\nimport { useIntersect } from '../../hooks/useIntersect.js'\nimport { PopupTrigger } from './PopupTrigger/index.js'\nimport './index.scss'\n\nconst baseClass = 'popup'\n\nexport type PopupProps = {\n backgroundColor?: CSSProperties['backgroundColor']\n boundingRef?: React.RefObject<HTMLElement>\n button?: React.ReactNode\n buttonClassName?: string\n buttonSize?: 'large' | 'medium' | 'small' | 'xsmall'\n buttonType?: 'custom' | 'default' | 'none'\n caret?: boolean\n children?: React.ReactNode\n className?: string\n disabled?: boolean\n forceOpen?: boolean\n horizontalAlign?: 'center' | 'left' | 'right'\n id?: string\n initActive?: boolean\n noBackground?: boolean\n onToggleClose?: () => void\n onToggleOpen?: (active: boolean) => void\n render?: (any) => React.ReactNode\n showOnHover?: boolean\n showScrollbar?: boolean\n size?: 'fit-content' | 'large' | 'medium' | 'small'\n verticalAlign?: 'bottom' | 'top'\n}\n\nexport const Popup: React.FC<PopupProps> = (props) => {\n const {\n id,\n boundingRef,\n button,\n buttonClassName,\n buttonSize,\n buttonType = 'default',\n caret = true,\n children,\n className,\n disabled,\n forceOpen,\n horizontalAlign: horizontalAlignFromProps = 'left',\n initActive = false,\n noBackground,\n onToggleClose,\n onToggleOpen,\n render,\n showOnHover = false,\n showScrollbar = false,\n size = 'medium',\n verticalAlign: verticalAlignFromProps = 'top',\n } = props\n const { height: windowHeight, width: windowWidth } = useWindowInfo()\n\n const [intersectionRef, intersectionEntry] = useIntersect({\n root: boundingRef?.current || null,\n rootMargin: '-100px 0px 0px 0px',\n threshold: 1,\n })\n\n const contentRef = useRef(null)\n const triggerRef = useRef(null)\n const [active, setActive_Internal] = useState(initActive)\n const [verticalAlign, setVerticalAlign] = useState(verticalAlignFromProps)\n const [horizontalAlign, setHorizontalAlign] = useState(horizontalAlignFromProps)\n\n const setActive = React.useCallback(\n (active: boolean) => {\n if (active && typeof onToggleOpen === 'function') {\n onToggleOpen(true)\n }\n if (!active && typeof onToggleClose === 'function') {\n onToggleClose()\n }\n setActive_Internal(active)\n },\n [onToggleClose, onToggleOpen],\n )\n\n const setPosition = useCallback(\n ({ horizontal = false, vertical = false }) => {\n if (contentRef.current) {\n const bounds = contentRef.current.getBoundingClientRect()\n\n const {\n bottom: contentBottomPos,\n left: contentLeftPos,\n right: contentRightPos,\n top: contentTopPos,\n } = bounds\n\n let boundingTopPos = 100\n let boundingRightPos = document.documentElement.clientWidth\n let boundingBottomPos = document.documentElement.clientHeight\n let boundingLeftPos = 0\n\n if (boundingRef?.current) {\n ;({\n bottom: boundingBottomPos,\n left: boundingLeftPos,\n right: boundingRightPos,\n top: boundingTopPos,\n } = boundingRef.current.getBoundingClientRect())\n }\n\n if (horizontal) {\n if (contentRightPos > boundingRightPos && contentLeftPos > boundingLeftPos) {\n setHorizontalAlign('right')\n } else if (contentLeftPos < boundingLeftPos && contentRightPos < boundingRightPos) {\n setHorizontalAlign('left')\n }\n }\n\n if (vertical) {\n if (contentTopPos < boundingTopPos && contentBottomPos < boundingBottomPos) {\n setVerticalAlign('bottom')\n } else if (contentBottomPos > boundingBottomPos && contentTopPos > boundingTopPos) {\n setVerticalAlign('top')\n }\n }\n }\n },\n [boundingRef],\n )\n\n const handleClickOutside = useCallback(\n (e) => {\n if (contentRef.current.contains(e.target) || triggerRef.current.contains(e.target)) {\n return\n }\n\n setActive(false)\n },\n [contentRef, setActive],\n )\n\n useEffect(() => {\n setPosition({ horizontal: true })\n }, [intersectionEntry, setPosition, windowWidth])\n\n useEffect(() => {\n setPosition({ vertical: true })\n }, [intersectionEntry, setPosition, windowHeight])\n\n useEffect(() => {\n if (active) {\n document.addEventListener('mousedown', handleClickOutside)\n } else {\n document.removeEventListener('mousedown', handleClickOutside)\n }\n\n return () => {\n document.removeEventListener('mousedown', handleClickOutside)\n }\n }, [active, handleClickOutside, onToggleOpen])\n\n useEffect(() => {\n setActive(forceOpen)\n }, [forceOpen, setActive])\n\n const classes = [\n baseClass,\n className,\n `${baseClass}--size-${size}`,\n buttonSize && `${baseClass}--button-size-${buttonSize}`,\n `${baseClass}--v-align-${verticalAlign}`,\n `${baseClass}--h-align-${horizontalAlign}`,\n active && `${baseClass}--active`,\n showScrollbar && `${baseClass}--show-scrollbar`,\n ]\n .filter(Boolean)\n .join(' ')\n\n return (\n <div className={classes} id={id}>\n <div className={`${baseClass}__trigger-wrap`} ref={triggerRef}>\n {showOnHover ? (\n <div\n className={`${baseClass}__on-hover-watch`}\n onMouseEnter={() => setActive(true)}\n onMouseLeave={() => setActive(false)}\n role=\"button\"\n tabIndex={0}\n >\n <PopupTrigger\n {...{\n active,\n button,\n buttonType,\n className: buttonClassName,\n disabled,\n noBackground,\n setActive,\n size: buttonSize,\n }}\n />\n </div>\n ) : (\n <PopupTrigger\n {...{\n active,\n button,\n buttonType,\n className: buttonClassName,\n disabled,\n noBackground,\n setActive,\n size: buttonSize,\n }}\n />\n )}\n </div>\n\n <div className={`${baseClass}__content`} ref={contentRef}>\n <div className={`${baseClass}__hide-scrollbar`} ref={intersectionRef}>\n <div className={`${baseClass}__scroll-container`}>\n <div className={`${baseClass}__scroll-content`}>\n {render && render({ close: () => setActive(false) })}\n {children}\n </div>\n </div>\n </div>\n\n {caret && <div className={`${baseClass}__caret`} />}\n </div>\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,SAAS,MAAM;AAE3B,SAASC,aAAa,QAAQ;AAC9B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAEhE,SAASC,YAAY,QAAQ;AAC7B,SAASC,YAAY,QAAQ;AAC7B,OAAO;AAEP,MAAMC,SAAA,GAAY;AA2BlB,OAAO,MAAMC,KAAA,GAA+BC,KAAA;EAC1C,MAAM;IACJC,EAAE;IACFC,WAAW;IACXC,MAAM;IACNC,eAAe;IACfC,UAAU;IACVC,UAAA,GAAa,SAAS;IACtBC,KAAA,GAAQ,IAAI;IACZC,QAAQ;IACRC,SAAS;IACTC,QAAQ;IACRC,SAAS;IACTC,eAAA,EAAiBC,wBAAA,GAA2B,MAAM;IAClDC,UAAA,GAAa,KAAK;IAClBC,YAAY;IACZC,aAAa;IACbC,YAAY;IACZC,MAAM;IACNC,WAAA,GAAc,KAAK;IACn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W,GAAGX,SAAA,kBAA2B;QACzC6E,YAAA,EAAcA,CAAA,KAAMnC,SAAA,CAAU;QAC9BoC,YAAA,EAAcA,CAAA,KAAMpC,SAAA,CAAU;QAC9BqC,IAAA,EAAK;QACLC,QAAA,EAAU;kBAEV,aAAAL,IAAA,CAAC5E,YAAA;UAEGuC,MAAA;UACAjC,MAAA;UACAG,UAAA;UACAG,SAAA,EAAWL,eAAA;UACXM,QAAA;UACAK,YAAA;UACAyB,SAAA;UACAnB,IAAA,EAAMhB;;wBAKZoE,IAAA,CAAC5E,YAAA;QAEGuC,MAAA;QACAjC,MAAA;QACAG,UAAA;QACAG,SAAA,EAAWL,eAAA;QACXM,QAAA;QACAK,YAAA;QACAyB,SAAA;QACAnB,IAAA,EAAMhB;;qBAMdmE,KAAA,CAAC;MAAI/D,SAAA,EAAW,GAAGX,SAAA,WAAoB;MAAE4E,GAAA,EAAKxC,UAAA;8BAC5CuC,IAAA,CAAC;QAAIhE,SAAA,EAAW,GAAGX,SAAA,kBAA2B;QAAE4E,GAAA,EAAK9C,eAAA;kBACnD,aAAA6C,IAAA,CAAC;UAAIhE,SAAA,EAAW,GAAGX,SAAA,oBAA6B;oBAC9C,aAAA0E,KAAA,CAAC;YAAI/D,SAAA,EAAW,GAAGX,SAAA,kBAA2B;uBAC3CoB,MAAA,IAAUA,MAAA,CAAO;cAAE6D,KAAA,EAAOA,CAAA,KAAMvC,SAAA,CAAU;YAAO,IACjDhC,QAAA;;;UAKND,KAAA,iBAASkE,IAAA,CAAC;QAAIhE,SAAA,EAAW,GAAGX,SAAA;;;;AAIrC","ignoreList":[]}
1
+ {"version":3,"file":"index.js","names":["PopupList","React","useCallback","useEffect","useRef","useState","createPortal","useEffectEvent","PopupTrigger","baseClass","TABBABLE_SELECTOR","map","s","join","Popup","props","id","button","buttonClassName","buttonSize","buttonType","caret","children","className","disabled","forceOpen","horizontalAlign","initActive","noBackground","onToggleClose","onToggleOpen","render","showOnHover","showScrollbar","size","verticalAlign","popupRef","triggerRef","openedViaKeyboardRef","mounted","setMounted","active","setActiveInternal","isOnTop","setIsOnTop","setActive","isActive","viaKeyboard","current","updatePosition","trigger","popup","triggerRect","getBoundingClientRect","popupRect","offset","top","onTop","bottom","window","scrollY","height","innerHeight","left","right","width","Math","max","min","innerWidth","triggerCenter","caretLeft","newTop","round","newLeft","scrollX","newCaretLeft","style","getPropertyValue","setProperty","handleClickOutside","e","isOutsidePopup","contains","target","isOutsideTrigger","handleKeyDown","key","preventDefault","querySelector","focus","focusable","Array","from","querySelectorAll","length","currentIndex","findIndex","el","document","activeElement","goBackward","shiftKey","nextIndex","handleActionableClick","actionable","closest","requestAnimationFrame","firstFocusable","addEventListener","capture","passive","removeEventListener","undefined","Trigger","_jsx","_jsxs","filter","Boolean","ref","onMouseEnter","onMouseLeave","role","tabIndex","close","body"],"sources":["../../../src/elements/Popup/index.tsx"],"sourcesContent":["'use client'\nimport type { CSSProperties } from 'react'\n\nexport * as PopupList from './PopupButtonList/index.js'\n\nimport React, { useCallback, useEffect, useRef, useState } from 'react'\nimport { createPortal } from 'react-dom'\n\nimport { useEffectEvent } from '../../hooks/useEffectEvent.js'\nimport './index.scss'\nimport { PopupTrigger } from './PopupTrigger/index.js'\n\nconst baseClass = 'popup'\n\n/**\n * Selector for all elements the browser considers tabbable.\n */\nconst TABBABLE_SELECTOR = [\n 'a[href]',\n 'button:not(:disabled)',\n 'input:not(:disabled):not([type=\"hidden\"])',\n 'select:not(:disabled)',\n 'textarea:not(:disabled)',\n '[tabindex]',\n '[contenteditable]:not([contenteditable=\"false\"])',\n 'audio[controls]',\n 'video[controls]',\n 'summary',\n]\n .map((s) => `${s}:not([tabindex=\"-1\"])`)\n .join(', ')\n\nexport type PopupProps = {\n backgroundColor?: CSSProperties['backgroundColor']\n boundingRef?: React.RefObject<HTMLElement>\n button?: React.ReactNode\n buttonClassName?: string\n buttonSize?: 'large' | 'medium' | 'small' | 'xsmall'\n buttonType?: 'custom' | 'default' | 'none'\n caret?: boolean\n children?: React.ReactNode\n className?: string\n disabled?: boolean\n /**\n * Force control the open state of the popup, regardless of the trigger.\n */\n forceOpen?: boolean\n /**\n * Preferred horizontal alignment of the popup, if there is enough space available.\n *\n * @default 'left'\n */\n horizontalAlign?: 'center' | 'left' | 'right'\n id?: string\n initActive?: boolean\n noBackground?: boolean\n onToggleClose?: () => void\n onToggleOpen?: (active: boolean) => void\n render?: (args: { close: () => void }) => React.ReactNode\n showOnHover?: boolean\n /**\n * By default, the scrollbar is hidden. If you want to show it, set this to true.\n * In both cases, the container is still scrollable.\n *\n * @default false\n */\n showScrollbar?: boolean\n size?: 'fit-content' | 'large' | 'medium' | 'small'\n /**\n * Preferred vertical alignment of the popup (position below or above the trigger),\n * if there is enough space available.\n *\n * If the popup is too close to the edge of the viewport, it will flip to the opposite side\n * regardless of the preferred vertical alignment.\n *\n * @default 'bottom'\n */\n verticalAlign?: 'bottom' | 'top'\n}\n\n/**\n * Component that renders a popup, as well as a button that triggers the popup.\n *\n * The popup is rendered in a portal, and is automatically positioned above / below the trigger,\n * depending on the verticalAlign prop and the space available.\n */\nexport const Popup: React.FC<PopupProps> = (props) => {\n const {\n id,\n button,\n buttonClassName,\n buttonSize,\n buttonType = 'default',\n caret = true,\n children,\n className,\n disabled,\n forceOpen,\n horizontalAlign = 'left',\n initActive = false,\n noBackground,\n onToggleClose,\n onToggleOpen,\n render,\n showOnHover = false,\n showScrollbar = false,\n size = 'medium',\n verticalAlign = 'bottom',\n } = props\n\n const popupRef = useRef<HTMLDivElement>(null)\n const triggerRef = useRef<HTMLDivElement>(null)\n\n /**\n * Keeps track of whether the popup was opened via keyboard.\n * This is used to determine whether to autofocus the first element in the popup.\n * If the popup was opened via mouse, we do not want to autofocus the first element.\n */\n const openedViaKeyboardRef = useRef(false)\n\n const [mounted, setMounted] = useState(false)\n const [active, setActiveInternal] = useState(initActive)\n const [isOnTop, setIsOnTop] = useState(verticalAlign === 'top')\n\n // Track when component is mounted to avoid SSR/client hydration mismatch\n useEffect(() => {\n setMounted(true)\n }, [])\n\n const setActive = useCallback(\n (isActive: boolean, viaKeyboard = false) => {\n if (isActive) {\n openedViaKeyboardRef.current = viaKeyboard\n onToggleOpen?.(true)\n } else {\n onToggleClose?.()\n }\n setActiveInternal(isActive)\n },\n [onToggleClose, onToggleOpen],\n )\n\n // /////////////////////////////////////\n // Position Calculation\n //\n // Calculates and applies popup position relative to trigger.\n // Always checks viewport bounds (for flipping), but only updates\n // styles if the calculated position differs from current position.\n // /////////////////////////////////////\n\n const updatePosition = useEffectEvent(() => {\n const trigger = triggerRef.current\n const popup = popupRef.current\n if (!trigger || !popup) {\n return\n }\n\n const triggerRect = trigger.getBoundingClientRect()\n const popupRect = popup.getBoundingClientRect()\n\n // Gap between the popup and the trigger/viewport edges (in pixels)\n const offset = 10\n\n // /////////////////////////////////////\n // Vertical Positioning\n // Calculates the `top` position in absolute page coordinates.\n // Uses `verticalAlign` prop as the preferred direction, but flips\n // to the opposite side if there's not enough viewport space.\n // /////////////////////////////////////\n\n let top: number\n let onTop = verticalAlign === 'top'\n\n if (verticalAlign === 'bottom') {\n top = triggerRect.bottom + window.scrollY + offset\n\n if (triggerRect.bottom + popupRect.height + offset > window.innerHeight) {\n top = triggerRect.top + window.scrollY - popupRect.height - offset\n onTop = true\n }\n } else {\n top = triggerRect.top + window.scrollY - popupRect.height - offset\n\n if (triggerRect.top - popupRect.height - offset < 0) {\n top = triggerRect.bottom + window.scrollY + offset\n onTop = false\n }\n }\n\n setIsOnTop(onTop)\n\n // /////////////////////////////////////\n // Horizontal Positioning\n // Calculates the `left` position based on `horizontalAlign` prop:\n // - 'left': aligns popup's left edge with trigger's left edge\n // - 'right': aligns popup's right edge with trigger's right edge\n // - 'center': centers popup horizontally relative to trigger\n // Then clamps to keep the popup within viewport bounds.\n // /////////////////////////////////////\n\n let left =\n horizontalAlign === 'right'\n ? triggerRect.right - popupRect.width\n : horizontalAlign === 'center'\n ? triggerRect.left + triggerRect.width / 2 - popupRect.width / 2\n : triggerRect.left\n\n left = Math.max(offset, Math.min(left, window.innerWidth - popupRect.width - offset))\n\n // /////////////////////////////////////\n // Caret Positioning\n // Positions the caret arrow to point at the trigger's horizontal center.\n // Clamps between 12px from edges to prevent caret from overflowing the popup.\n // /////////////////////////////////////\n\n const triggerCenter = triggerRect.left + triggerRect.width / 2\n const caretLeft = Math.max(12, Math.min(triggerCenter - left, popupRect.width - 12))\n\n // /////////////////////////////////////\n // Apply Styles (only if changed)\n // Compares calculated position with current styles to avoid unnecessary\n // DOM updates during scroll. This prevents visual lag by relying on the absolute\n // positioning where possible (popup slightly lags behind when scrolling really fast),\n // while still allowing position changes when needed (e.g., sticky parent, viewport flip).\n // Values are rounded to match browser's CSS precision and avoid false updates.\n // /////////////////////////////////////\n\n const newTop = `${Math.round(top)}px`\n const newLeft = `${Math.round(left + window.scrollX)}px`\n const newCaretLeft = `${Math.round(caretLeft)}px`\n\n if (popup.style.top !== newTop) {\n popup.style.top = newTop\n }\n if (popup.style.left !== newLeft) {\n popup.style.left = newLeft\n }\n if (popup.style.getPropertyValue('--caret-left') !== newCaretLeft) {\n popup.style.setProperty('--caret-left', newCaretLeft)\n }\n })\n\n // /////////////////////////////////////\n // Click Outside Handler\n // Closes popup when clicking outside both the popup and trigger.\n // /////////////////////////////////////\n\n const handleClickOutside = useEffectEvent((e: MouseEvent) => {\n const isOutsidePopup = !popupRef.current?.contains(e.target as Node)\n const isOutsideTrigger = !triggerRef.current?.contains(e.target as Node)\n\n if (isOutsidePopup && isOutsideTrigger) {\n setActive(false)\n }\n })\n\n // /////////////////////////////////////\n // Keyboard Navigation\n // Handles keyboard interactions when popup is open:\n // - Escape: closes popup and returns focus to trigger\n // - Tab/Shift+Tab: cycles through focusable items with wrapping\n // - ArrowUp/ArrowDown: same as Shift+Tab/Tab for menu-style navigation\n // Focus is managed manually to support elements the browser might skip.\n // /////////////////////////////////////\n\n const handleKeyDown = useEffectEvent((e: KeyboardEvent) => {\n const popup = popupRef.current\n if (!popup || !active) {\n return\n }\n\n if (e.key === 'Escape') {\n e.preventDefault()\n setActive(false)\n triggerRef.current?.querySelector<HTMLElement>('button, [tabindex=\"0\"]')?.focus()\n return\n }\n\n if (e.key === 'Tab' || e.key === 'ArrowDown' || e.key === 'ArrowUp') {\n const focusable = Array.from(popup.querySelectorAll<HTMLElement>(TABBABLE_SELECTOR))\n if (focusable.length === 0) {\n return\n }\n\n e.preventDefault()\n\n const currentIndex = focusable.findIndex((el) => el === document.activeElement)\n const goBackward = e.key === 'ArrowUp' || (e.key === 'Tab' && e.shiftKey)\n\n let nextIndex: number\n if (currentIndex === -1) {\n nextIndex = goBackward ? focusable.length - 1 : 0\n } else if (goBackward) {\n nextIndex = currentIndex === 0 ? focusable.length - 1 : currentIndex - 1\n } else {\n nextIndex = currentIndex === focusable.length - 1 ? 0 : currentIndex + 1\n }\n\n focusable[nextIndex].focus()\n }\n })\n\n // /////////////////////////////////////\n // Click Handler for Actionable Elements\n // Closes popup when buttons/links inside are clicked (includes Enter/Space activation).\n // /////////////////////////////////////\n\n const handleActionableClick = useEffectEvent((e: MouseEvent) => {\n const target = e.target as HTMLElement\n // Check if the clicked element or any ancestor is an actionable element\n const actionable = target.closest('button, a[href], [role=\"button\"], [role=\"menuitem\"]')\n if (actionable && popupRef.current?.contains(actionable)) {\n setActive(false)\n }\n })\n\n // /////////////////////////////////////\n // Effect: Setup/Teardown position and focus management\n // /////////////////////////////////////\n\n useEffect(() => {\n if (!active) {\n return\n }\n\n const popup = popupRef.current\n if (!popup) {\n return\n }\n\n // /////////////////////////////////////\n // Initial Position\n // Calculate and apply popup position immediately on open.\n // /////////////////////////////////////\n\n updatePosition()\n\n // /////////////////////////////////////\n // Focus Management\n // When opened via keyboard, autofocus the first focusable button.\n // When opened via mouse, skip autofocus to avoid unwanted highlights.\n // /////////////////////////////////////\n\n if (openedViaKeyboardRef.current) {\n // Use requestAnimationFrame to ensure DOM is ready.\n requestAnimationFrame(() => {\n const firstFocusable = popup.querySelector<HTMLElement>(TABBABLE_SELECTOR)\n firstFocusable?.focus()\n })\n }\n\n // /////////////////////////////////////\n // Event Listeners\n // - resize/scroll: recalculate position (only applies styles if changed)\n // - mousedown: detect clicks outside to close\n // - keydown: handle keyboard navigation\n // /////////////////////////////////////\n\n window.addEventListener('resize', updatePosition)\n window.addEventListener('scroll', updatePosition, { capture: true, passive: true })\n document.addEventListener('mousedown', handleClickOutside)\n document.addEventListener('keydown', handleKeyDown)\n popup.addEventListener('click', handleActionableClick)\n\n return () => {\n window.removeEventListener('resize', updatePosition)\n window.removeEventListener('scroll', updatePosition, { capture: true })\n document.removeEventListener('mousedown', handleClickOutside)\n document.removeEventListener('keydown', handleKeyDown)\n popup.removeEventListener('click', handleActionableClick)\n }\n }, [active])\n\n useEffect(() => {\n if (forceOpen !== undefined) {\n setActive(forceOpen)\n }\n }, [forceOpen, setActive])\n\n const Trigger = (\n <PopupTrigger\n active={active}\n button={button}\n buttonType={buttonType}\n className={buttonClassName}\n disabled={disabled}\n noBackground={noBackground}\n setActive={setActive}\n size={buttonSize}\n />\n )\n\n return (\n <div className={[baseClass, className].filter(Boolean).join(' ')} id={id}>\n <div className={`${baseClass}__trigger-wrap`} ref={triggerRef}>\n {showOnHover ? (\n <div\n className={`${baseClass}__on-hover-watch`}\n onMouseEnter={() => setActive(true)}\n onMouseLeave={() => setActive(false)}\n role=\"button\"\n tabIndex={0}\n >\n {Trigger}\n </div>\n ) : (\n Trigger\n )}\n </div>\n\n {mounted\n ? // We need to make sure the popup is part of the DOM (although invisible), even if it's not active.\n // This ensures that components within the popup, like modals, do not unmount when the popup closes.\n // Otherwise, modals opened from the popup will close unexpectedly when clicking within the modal, since\n // that closes the popup due to the click outside handler.\n createPortal(\n <div\n className={\n active\n ? [\n `${baseClass}__content`,\n `${baseClass}--size-${size}`,\n isOnTop ? `${baseClass}--v-top` : `${baseClass}--v-bottom`,\n ]\n .filter(Boolean)\n .join(' ')\n : // Do not share any class names between active and disabled popups, to make sure\n // tests do not accidentally target inactive popups.\n `${baseClass}__hidden-content`\n }\n data-popup-id={id || undefined}\n ref={popupRef}\n >\n <div\n className={`${baseClass}__scroll-container${showScrollbar ? ` ${baseClass}__scroll-container--show-scrollbar` : ''}`}\n >\n {render?.({ close: () => setActive(false) })}\n {children}\n </div>\n {caret && <div className={`${baseClass}__caret`} />}\n </div>,\n document.body,\n )\n : null}\n </div>\n )\n}\n"],"mappings":"AAAA;;;AAGA,OAAO,KAAKA,SAAS,MAAM;AAE3B,OAAOC,KAAA,IAASC,WAAW,EAAEC,SAAS,EAAEC,MAAM,EAAEC,QAAQ,QAAQ;AAChE,SAASC,YAAY,QAAQ;AAE7B,SAASC,cAAc,QAAQ;AAC/B,OAAO;AACP,SAASC,YAAY,QAAQ;AAE7B,MAAMC,SAAA,GAAY;AAElB;;;AAGA,MAAMC,iBAAA,GAAoB,CACxB,WACA,yBACA,6CACA,yBACA,2BACA,cACA,oDACA,mBACA,mBACA,UACD,CACEC,GAAG,CAAEC,CAAA,IAAM,GAAGA,CAAA,uBAAwB,EACtCC,IAAI,CAAC;AAkDR;;;;;;AAMA,OAAO,MAAMC,KAAA,GAA+BC,KAAA;EAC1C,MAAM;IACJC,EAAE;IACFC,MAAM;IACNC,eAAe;IACfC,UAAU;IACVC,UAAA,GAAa,SAAS;IACtBC,KAAA,GAAQ,IAAI;IACZC,QAAQ;IACRC,SAAS;IACTC,QAAQ;IACRC,SAAS;IACTC,eAAA,GAAkB,MAAM;IACxBC,UAAA,GAAa,KAAK;IAClBC,YAAY;IACZC,aAAa;IACbC,YAAY;IACZC,MAAM;IACNC,WAAA,GAAc,KAAK;IACnBC,aAAA,GAAgB,KAAK;IACrBC,IAAA,GAAO,QAAQ;IACfC,aAAA,GAAgB;EAAQ,CACzB,GAAGpB,KAAA;EAEJ,MAAMqB,QAAA,GAAWhC,MAAA,CAAuB;EACxC,MAAMiC,UAAA,GAAajC,MAAA,CAAuB;EAE1C;;;;;EAKA,MAAMkC,oBAAA,GAAuBlC,MAAA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