@wordpress/compose 7.32.0 → 7.32.1-next.b8c8708f3.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 (235) hide show
  1. package/build/higher-order/compose.js +25 -20
  2. package/build/higher-order/compose.js.map +7 -1
  3. package/build/higher-order/if-condition/index.js +35 -41
  4. package/build/higher-order/if-condition/index.js.map +7 -1
  5. package/build/higher-order/pipe.js +32 -66
  6. package/build/higher-order/pipe.js.map +7 -1
  7. package/build/higher-order/pure/index.js +44 -37
  8. package/build/higher-order/pure/index.js.map +7 -1
  9. package/build/higher-order/with-global-events/index.js +64 -73
  10. package/build/higher-order/with-global-events/index.js.map +7 -1
  11. package/build/higher-order/with-global-events/listener.js +34 -21
  12. package/build/higher-order/with-global-events/listener.js.map +7 -1
  13. package/build/higher-order/with-instance-id/index.js +45 -27
  14. package/build/higher-order/with-instance-id/index.js.map +7 -1
  15. package/build/higher-order/with-safe-timeout/index.js +70 -66
  16. package/build/higher-order/with-safe-timeout/index.js.map +7 -1
  17. package/build/higher-order/with-state/index.js +52 -40
  18. package/build/higher-order/with-state/index.js.map +7 -1
  19. package/build/hooks/use-async-list/index.js +38 -42
  20. package/build/hooks/use-async-list/index.js.map +7 -1
  21. package/build/hooks/use-constrained-tabbing/index.js +54 -75
  22. package/build/hooks/use-constrained-tabbing/index.js.map +7 -1
  23. package/build/hooks/use-copy-on-click/index.js +46 -56
  24. package/build/hooks/use-copy-on-click/index.js.map +7 -1
  25. package/build/hooks/use-copy-to-clipboard/index.js +41 -51
  26. package/build/hooks/use-copy-to-clipboard/index.js.map +7 -1
  27. package/build/hooks/use-debounce/index.js +30 -37
  28. package/build/hooks/use-debounce/index.js.map +7 -1
  29. package/build/hooks/use-debounced-input/index.js +39 -27
  30. package/build/hooks/use-debounced-input/index.js.map +7 -1
  31. package/build/hooks/use-dialog/index.js +63 -55
  32. package/build/hooks/use-dialog/index.js.map +7 -1
  33. package/build/hooks/use-disabled/index.js +74 -82
  34. package/build/hooks/use-disabled/index.js.map +7 -1
  35. package/build/hooks/use-dragging/index.js +51 -48
  36. package/build/hooks/use-dragging/index.js.map +7 -1
  37. package/build/hooks/use-drop-zone/index.js +133 -168
  38. package/build/hooks/use-drop-zone/index.js.map +7 -1
  39. package/build/hooks/use-event/index.js +33 -45
  40. package/build/hooks/use-event/index.js.map +7 -1
  41. package/build/hooks/use-fixed-window-list/index.js +109 -97
  42. package/build/hooks/use-fixed-window-list/index.js.map +7 -1
  43. package/build/hooks/use-focus-on-mount/index.js +44 -57
  44. package/build/hooks/use-focus-on-mount/index.js.map +7 -1
  45. package/build/hooks/use-focus-outside/index.js +44 -102
  46. package/build/hooks/use-focus-outside/index.js.map +7 -1
  47. package/build/hooks/use-focus-return/index.js +35 -56
  48. package/build/hooks/use-focus-return/index.js.map +7 -1
  49. package/build/hooks/use-focusable-iframe/index.js +38 -35
  50. package/build/hooks/use-focusable-iframe/index.js.map +7 -1
  51. package/build/hooks/use-instance-id/index.js +26 -42
  52. package/build/hooks/use-instance-id/index.js.map +7 -1
  53. package/build/hooks/use-isomorphic-layout-effect/index.js +25 -17
  54. package/build/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  55. package/build/hooks/use-keyboard-shortcut/index.js +72 -69
  56. package/build/hooks/use-keyboard-shortcut/index.js.map +7 -1
  57. package/build/hooks/use-media-query/index.js +39 -35
  58. package/build/hooks/use-media-query/index.js.map +7 -1
  59. package/build/hooks/use-merge-refs/index.js +34 -102
  60. package/build/hooks/use-merge-refs/index.js.map +7 -1
  61. package/build/hooks/use-observable-value/index.js +31 -28
  62. package/build/hooks/use-observable-value/index.js.map +7 -1
  63. package/build/hooks/use-preferred-color-scheme/index.android.js +31 -23
  64. package/build/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  65. package/build/hooks/use-preferred-color-scheme/index.ios.js +25 -17
  66. package/build/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  67. package/build/hooks/use-previous/index.js +26 -25
  68. package/build/hooks/use-previous/index.js.map +7 -1
  69. package/build/hooks/use-reduced-motion/index.js +35 -18
  70. package/build/hooks/use-reduced-motion/index.js.map +7 -1
  71. package/build/hooks/use-ref-effect/index.js +25 -35
  72. package/build/hooks/use-ref-effect/index.js.map +7 -1
  73. package/build/hooks/use-resize-observer/index.js +35 -67
  74. package/build/hooks/use-resize-observer/index.js.map +7 -1
  75. package/build/hooks/use-resize-observer/legacy/index.js +47 -103
  76. package/build/hooks/use-resize-observer/legacy/index.js.map +7 -1
  77. package/build/hooks/use-resize-observer/use-resize-observer.js +44 -36
  78. package/build/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  79. package/build/hooks/use-state-with-history/index.js +68 -63
  80. package/build/hooks/use-state-with-history/index.js.map +7 -1
  81. package/build/hooks/use-throttle/index.js +30 -37
  82. package/build/hooks/use-throttle/index.js.map +7 -1
  83. package/build/hooks/use-viewport-match/index.js +51 -70
  84. package/build/hooks/use-viewport-match/index.js.map +7 -1
  85. package/build/hooks/use-warn-on-change/index.js +50 -40
  86. package/build/hooks/use-warn-on-change/index.js.map +7 -1
  87. package/build/index.js +156 -358
  88. package/build/index.js.map +7 -1
  89. package/build/utils/create-higher-order-component/index.js +30 -34
  90. package/build/utils/create-higher-order-component/index.js.map +7 -1
  91. package/build/utils/debounce/index.js +38 -99
  92. package/build/utils/debounce/index.js.map +7 -1
  93. package/build/utils/observable-map/index.js +29 -19
  94. package/build/utils/observable-map/index.js.map +7 -1
  95. package/build/utils/throttle/index.js +30 -81
  96. package/build/utils/throttle/index.js.map +7 -1
  97. package/build-module/higher-order/compose.js +6 -15
  98. package/build-module/higher-order/compose.js.map +7 -1
  99. package/build-module/higher-order/if-condition/index.js +16 -37
  100. package/build-module/higher-order/if-condition/index.js.map +7 -1
  101. package/build-module/higher-order/pipe.js +10 -62
  102. package/build-module/higher-order/pipe.js.map +7 -1
  103. package/build-module/higher-order/pure/index.js +12 -29
  104. package/build-module/higher-order/pure/index.js.map +7 -1
  105. package/build-module/higher-order/with-global-events/index.js +34 -67
  106. package/build-module/higher-order/with-global-events/index.js.map +7 -1
  107. package/build-module/higher-order/with-global-events/listener.js +16 -17
  108. package/build-module/higher-order/with-global-events/listener.js.map +7 -1
  109. package/build-module/higher-order/with-instance-id/index.js +17 -22
  110. package/build-module/higher-order/with-instance-id/index.js.map +7 -1
  111. package/build-module/higher-order/with-safe-timeout/index.js +52 -62
  112. package/build-module/higher-order/with-safe-timeout/index.js.map +7 -1
  113. package/build-module/higher-order/with-state/index.js +23 -35
  114. package/build-module/higher-order/with-state/index.js.map +7 -1
  115. package/build-module/hooks/use-async-list/index.js +16 -33
  116. package/build-module/hooks/use-async-list/index.js.map +7 -1
  117. package/build-module/hooks/use-constrained-tabbing/index.js +26 -70
  118. package/build-module/hooks/use-constrained-tabbing/index.js.map +7 -1
  119. package/build-module/hooks/use-copy-on-click/index.js +14 -47
  120. package/build-module/hooks/use-copy-on-click/index.js.map +7 -1
  121. package/build-module/hooks/use-copy-to-clipboard/index.js +11 -44
  122. package/build-module/hooks/use-copy-to-clipboard/index.js.map +7 -1
  123. package/build-module/hooks/use-debounce/index.js +12 -33
  124. package/build-module/hooks/use-debounce/index.js.map +7 -1
  125. package/build-module/hooks/use-debounced-input/index.js +7 -18
  126. package/build-module/hooks/use-debounced-input/index.js.map +7 -1
  127. package/build-module/hooks/use-dialog/index.js +29 -43
  128. package/build-module/hooks/use-dialog/index.js.map +7 -1
  129. package/build-module/hooks/use-disabled/index.js +47 -78
  130. package/build-module/hooks/use-disabled/index.js.map +7 -1
  131. package/build-module/hooks/use-dragging/index.js +19 -39
  132. package/build-module/hooks/use-dragging/index.js.map +7 -1
  133. package/build-module/hooks/use-drop-zone/index.js +100 -158
  134. package/build-module/hooks/use-drop-zone/index.js.map +7 -1
  135. package/build-module/hooks/use-event/index.js +13 -39
  136. package/build-module/hooks/use-event/index.js.map +7 -1
  137. package/build-module/hooks/use-fixed-window-list/index.js +86 -87
  138. package/build-module/hooks/use-fixed-window-list/index.js.map +7 -1
  139. package/build-module/hooks/use-focus-on-mount/index.js +12 -48
  140. package/build-module/hooks/use-focus-on-mount/index.js.map +7 -1
  141. package/build-module/hooks/use-focus-outside/index.js +21 -93
  142. package/build-module/hooks/use-focus-outside/index.js.map +7 -1
  143. package/build-module/hooks/use-focus-return/index.js +13 -48
  144. package/build-module/hooks/use-focus-return/index.js.map +7 -1
  145. package/build-module/hooks/use-focusable-iframe/index.js +11 -31
  146. package/build-module/hooks/use-focusable-iframe/index.js.map +7 -1
  147. package/build-module/hooks/use-instance-id/index.js +7 -36
  148. package/build-module/hooks/use-instance-id/index.js.map +7 -1
  149. package/build-module/hooks/use-isomorphic-layout-effect/index.js +7 -13
  150. package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  151. package/build-module/hooks/use-keyboard-shortcut/index.js +40 -60
  152. package/build-module/hooks/use-keyboard-shortcut/index.js.map +7 -1
  153. package/build-module/hooks/use-media-query/index.js +21 -30
  154. package/build-module/hooks/use-media-query/index.js.map +7 -1
  155. package/build-module/hooks/use-merge-refs/index.js +10 -92
  156. package/build-module/hooks/use-merge-refs/index.js.map +7 -1
  157. package/build-module/hooks/use-observable-value/index.js +13 -24
  158. package/build-module/hooks/use-observable-value/index.js.map +7 -1
  159. package/build-module/hooks/use-preferred-color-scheme/index.android.js +15 -18
  160. package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  161. package/build-module/hooks/use-preferred-color-scheme/index.ios.js +6 -12
  162. package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  163. package/build-module/hooks/use-previous/index.js +7 -20
  164. package/build-module/hooks/use-previous/index.js.map +7 -1
  165. package/build-module/hooks/use-reduced-motion/index.js +7 -13
  166. package/build-module/hooks/use-reduced-motion/index.js.map +7 -1
  167. package/build-module/hooks/use-ref-effect/index.js +7 -31
  168. package/build-module/hooks/use-ref-effect/index.js.map +7 -1
  169. package/build-module/hooks/use-resize-observer/index.js +7 -61
  170. package/build-module/hooks/use-resize-observer/index.js.map +7 -1
  171. package/build-module/hooks/use-resize-observer/legacy/index.js +28 -96
  172. package/build-module/hooks/use-resize-observer/legacy/index.js.map +7 -1
  173. package/build-module/hooks/use-resize-observer/use-resize-observer.js +10 -28
  174. package/build-module/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  175. package/build-module/hooks/use-state-with-history/index.js +47 -55
  176. package/build-module/hooks/use-state-with-history/index.js.map +7 -1
  177. package/build-module/hooks/use-throttle/index.js +12 -33
  178. package/build-module/hooks/use-throttle/index.js.map +7 -1
  179. package/build-module/hooks/use-viewport-match/index.js +22 -64
  180. package/build-module/hooks/use-viewport-match/index.js.map +7 -1
  181. package/build-module/hooks/use-warn-on-change/index.js +21 -34
  182. package/build-module/hooks/use-warn-on-change/index.js.map +7 -1
  183. package/build-module/index.js +83 -53
  184. package/build-module/index.js.map +7 -1
  185. package/build-module/utils/create-higher-order-component/index.js +9 -30
  186. package/build-module/utils/create-higher-order-component/index.js.map +7 -1
  187. package/build-module/utils/debounce/index.js +17 -95
  188. package/build-module/utils/debounce/index.js.map +7 -1
  189. package/build-module/utils/observable-map/index.js +8 -16
  190. package/build-module/utils/observable-map/index.js.map +7 -1
  191. package/build-module/utils/throttle/index.js +8 -75
  192. package/build-module/utils/throttle/index.js.map +7 -1
  193. package/package.json +17 -10
  194. package/src/hooks/use-debounce/index.js +1 -1
  195. package/tsconfig.tsbuildinfo +1 -1
  196. package/build/higher-order/with-network-connectivity/index.native.js +0 -27
  197. package/build/higher-order/with-network-connectivity/index.native.js.map +0 -1
  198. package/build/higher-order/with-preferred-color-scheme/index.native.js +0 -37
  199. package/build/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  200. package/build/hooks/use-constrained-tabbing/index.native.js +0 -20
  201. package/build/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  202. package/build/hooks/use-focus-outside/index.native.js +0 -175
  203. package/build/hooks/use-focus-outside/index.native.js.map +0 -1
  204. package/build/hooks/use-keyboard-shortcut/index.native.js +0 -9
  205. package/build/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  206. package/build/hooks/use-network-connectivity/index.native.js +0 -58
  207. package/build/hooks/use-network-connectivity/index.native.js.map +0 -1
  208. package/build/hooks/use-preferred-color-scheme-style/index.native.js +0 -42
  209. package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  210. package/build/hooks/use-resize-observer/index.native.js +0 -14
  211. package/build/hooks/use-resize-observer/index.native.js.map +0 -1
  212. package/build/hooks/use-resize-observer/legacy/index.native.js +0 -62
  213. package/build/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  214. package/build/index.native.js +0 -297
  215. package/build/index.native.js.map +0 -1
  216. package/build-module/higher-order/with-network-connectivity/index.native.js +0 -19
  217. package/build-module/higher-order/with-network-connectivity/index.native.js.map +0 -1
  218. package/build-module/higher-order/with-preferred-color-scheme/index.native.js +0 -29
  219. package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  220. package/build-module/hooks/use-constrained-tabbing/index.native.js +0 -13
  221. package/build-module/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  222. package/build-module/hooks/use-focus-outside/index.native.js +0 -169
  223. package/build-module/hooks/use-focus-outside/index.native.js.map +0 -1
  224. package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -3
  225. package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  226. package/build-module/hooks/use-network-connectivity/index.native.js +0 -52
  227. package/build-module/hooks/use-network-connectivity/index.native.js.map +0 -1
  228. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +0 -35
  229. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  230. package/build-module/hooks/use-resize-observer/index.native.js +0 -2
  231. package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
  232. package/build-module/hooks/use-resize-observer/legacy/index.native.js +0 -56
  233. package/build-module/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  234. package/build-module/index.native.js +0 -45
  235. package/build-module/index.native.js.map +0 -1
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","INPUT_BUTTON_TYPES","isFocusNormalizedButton","eventTarget","window","HTMLElement","nodeName","includes","type","useFocusOutside","onFocusOutside","currentOnFocusOutsideRef","useRef","useEffect","current","preventBlurCheckRef","blurCheckTimeoutIdRef","cancelBlurCheck","useCallback","clearTimeout","normalizeButtonFocus","event","target","isInteractionEnd","queueBlurCheck","persist","ignoreForRelatedTarget","getAttribute","relatedTarget","closest","setTimeout","document","hasFocus","preventDefault","onFocus","onMouseDown","onMouseUp","onTouchStart","onTouchEnd","onBlur"],"sources":["@wordpress/compose/src/hooks/use-focus-outside/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Input types which are classified as button types, for use in considering\n * whether element is a (focus-normalized) button.\n */\nconst INPUT_BUTTON_TYPES = [ 'button', 'submit' ];\n\n/**\n * List of HTML button elements subject to focus normalization\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n */\ntype FocusNormalizedButton =\n\t| HTMLButtonElement\n\t| HTMLLinkElement\n\t| HTMLInputElement;\n\n/**\n * Returns true if the given element is a button element subject to focus\n * normalization, or false otherwise.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n *\n * @param eventTarget The target from a mouse or touch event.\n *\n * @return Whether the element is a button element subject to focus normalization.\n */\nfunction isFocusNormalizedButton(\n\teventTarget: EventTarget\n): eventTarget is FocusNormalizedButton {\n\tif ( ! ( eventTarget instanceof window.HTMLElement ) ) {\n\t\treturn false;\n\t}\n\tswitch ( eventTarget.nodeName ) {\n\t\tcase 'A':\n\t\tcase 'BUTTON':\n\t\t\treturn true;\n\n\t\tcase 'INPUT':\n\t\t\treturn INPUT_BUTTON_TYPES.includes(\n\t\t\t\t( eventTarget as HTMLInputElement ).type\n\t\t\t);\n\t}\n\n\treturn false;\n}\n\ntype UseFocusOutsideReturn = {\n\tonFocus: React.FocusEventHandler;\n\tonMouseDown: React.MouseEventHandler;\n\tonMouseUp: React.MouseEventHandler;\n\tonTouchStart: React.TouchEventHandler;\n\tonTouchEnd: React.TouchEventHandler;\n\tonBlur: React.FocusEventHandler;\n};\n\n/**\n * A react hook that can be used to check whether focus has moved outside the\n * element the event handlers are bound to.\n *\n * @param onFocusOutside A callback triggered when focus moves outside\n * the element the event handlers are bound to.\n *\n * @return An object containing event handlers. Bind the event handlers to a\n * wrapping element element to capture when focus moves outside that element.\n */\nexport default function useFocusOutside(\n\tonFocusOutside: ( ( event: React.FocusEvent ) => void ) | undefined\n): UseFocusOutsideReturn {\n\tconst currentOnFocusOutsideRef = useRef( onFocusOutside );\n\tuseEffect( () => {\n\t\tcurrentOnFocusOutsideRef.current = onFocusOutside;\n\t}, [ onFocusOutside ] );\n\n\tconst preventBlurCheckRef = useRef( false );\n\n\tconst blurCheckTimeoutIdRef = useRef< number | undefined >();\n\n\t/**\n\t * Cancel a blur check timeout.\n\t */\n\tconst cancelBlurCheck = useCallback( () => {\n\t\tclearTimeout( blurCheckTimeoutIdRef.current );\n\t}, [] );\n\n\t// Cancel a blur check if the callback or ref is no longer provided.\n\tuseEffect( () => {\n\t\tif ( ! onFocusOutside ) {\n\t\t\tcancelBlurCheck();\n\t\t}\n\t}, [ onFocusOutside, cancelBlurCheck ] );\n\n\t/**\n\t * Handles a mousedown or mouseup event to respectively assign and\n\t * unassign a flag for preventing blur check on button elements. Some\n\t * browsers, namely Firefox and Safari, do not emit a focus event on\n\t * button elements when clicked, while others do. The logic here\n\t * intends to normalize this as treating click on buttons as focus.\n\t *\n\t * @param event\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\t */\n\tconst normalizeButtonFocus: React.EventHandler<\n\t\tReact.MouseEvent | React.TouchEvent\n\t> = useCallback( ( event ) => {\n\t\tconst { type, target } = event;\n\t\tconst isInteractionEnd = [ 'mouseup', 'touchend' ].includes( type );\n\n\t\tif ( isInteractionEnd ) {\n\t\t\tpreventBlurCheckRef.current = false;\n\t\t} else if ( isFocusNormalizedButton( target ) ) {\n\t\t\tpreventBlurCheckRef.current = true;\n\t\t}\n\t}, [] );\n\n\t/**\n\t * A callback triggered when a blur event occurs on the element the handler\n\t * is bound to.\n\t *\n\t * Calls the `onFocusOutside` callback in an immediate timeout if focus has\n\t * move outside the bound element and is still within the document.\n\t */\n\tconst queueBlurCheck: React.FocusEventHandler = useCallback( ( event ) => {\n\t\t// React does not allow using an event reference asynchronously\n\t\t// due to recycling behavior, except when explicitly persisted.\n\t\tevent.persist();\n\n\t\t// Skip blur check if clicking button. See `normalizeButtonFocus`.\n\t\tif ( preventBlurCheckRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The usage of this attribute should be avoided. The only use case\n\t\t// would be when we load modals that are not React components and\n\t\t// therefore don't exist in the React tree. An example is opening\n\t\t// the Media Library modal from another dialog.\n\t\t// This attribute should contain a selector of the related target\n\t\t// we want to ignore, because we still need to trigger the blur event\n\t\t// on all other cases.\n\t\tconst ignoreForRelatedTarget = event.target.getAttribute(\n\t\t\t'data-unstable-ignore-focus-outside-for-relatedtarget'\n\t\t);\n\t\tif (\n\t\t\tignoreForRelatedTarget &&\n\t\t\tevent.relatedTarget?.closest( ignoreForRelatedTarget )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tblurCheckTimeoutIdRef.current = setTimeout( () => {\n\t\t\t// If document is not focused then focus should remain\n\t\t\t// inside the wrapped component and therefore we cancel\n\t\t\t// this blur event thereby leaving focus in place.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.\n\t\t\tif ( ! document.hasFocus() ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( 'function' === typeof currentOnFocusOutsideRef.current ) {\n\t\t\t\tcurrentOnFocusOutsideRef.current( event );\n\t\t\t}\n\t\t}, 0 );\n\t}, [] );\n\n\treturn {\n\t\tonFocus: cancelBlurCheck,\n\t\tonMouseDown: normalizeButtonFocus,\n\t\tonMouseUp: normalizeButtonFocus,\n\t\tonTouchStart: normalizeButtonFocus,\n\t\tonTouchEnd: normalizeButtonFocus,\n\t\tonBlur: queueBlurCheck,\n\t};\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA,MAAMC,kBAAkB,GAAG,CAAE,QAAQ,EAAE,QAAQ,CAAE;;AAEjD;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAuBA,CAC/BC,WAAwB,EACe;EACvC,IAAK,EAAIA,WAAW,YAAYC,MAAM,CAACC,WAAW,CAAE,EAAG;IACtD,OAAO,KAAK;EACb;EACA,QAASF,WAAW,CAACG,QAAQ;IAC5B,KAAK,GAAG;IACR,KAAK,QAAQ;MACZ,OAAO,IAAI;IAEZ,KAAK,OAAO;MACX,OAAOL,kBAAkB,CAACM,QAAQ,CAC/BJ,WAAW,CAAuBK,IACrC,CAAC;EACH;EAEA,OAAO,KAAK;AACb;AAWA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,eAAeA,CACtCC,cAAmE,EAC3C;EACxB,MAAMC,wBAAwB,GAAG,IAAAC,eAAM,EAAEF,cAAe,CAAC;EACzD,IAAAG,kBAAS,EAAE,MAAM;IAChBF,wBAAwB,CAACG,OAAO,GAAGJ,cAAc;EAClD,CAAC,EAAE,CAAEA,cAAc,CAAG,CAAC;EAEvB,MAAMK,mBAAmB,GAAG,IAAAH,eAAM,EAAE,KAAM,CAAC;EAE3C,MAAMI,qBAAqB,GAAG,IAAAJ,eAAM,EAAuB,CAAC;;EAE5D;AACD;AACA;EACC,MAAMK,eAAe,GAAG,IAAAC,oBAAW,EAAE,MAAM;IAC1CC,YAAY,CAAEH,qBAAqB,CAACF,OAAQ,CAAC;EAC9C,CAAC,EAAE,EAAG,CAAC;;EAEP;EACA,IAAAD,kBAAS,EAAE,MAAM;IAChB,IAAK,CAAEH,cAAc,EAAG;MACvBO,eAAe,CAAC,CAAC;IAClB;EACD,CAAC,EAAE,CAAEP,cAAc,EAAEO,eAAe,CAAG,CAAC;;EAExC;AACD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;EACC,MAAMG,oBAEL,GAAG,IAAAF,oBAAW,EAAIG,KAAK,IAAM;IAC7B,MAAM;MAAEb,IAAI;MAAEc;IAAO,CAAC,GAAGD,KAAK;IAC9B,MAAME,gBAAgB,GAAG,CAAE,SAAS,EAAE,UAAU,CAAE,CAAChB,QAAQ,CAAEC,IAAK,CAAC;IAEnE,IAAKe,gBAAgB,EAAG;MACvBR,mBAAmB,CAACD,OAAO,GAAG,KAAK;IACpC,CAAC,MAAM,IAAKZ,uBAAuB,CAAEoB,MAAO,CAAC,EAAG;MAC/CP,mBAAmB,CAACD,OAAO,GAAG,IAAI;IACnC;EACD,CAAC,EAAE,EAAG,CAAC;;EAEP;AACD;AACA;AACA;AACA;AACA;AACA;EACC,MAAMU,cAAuC,GAAG,IAAAN,oBAAW,EAAIG,KAAK,IAAM;IACzE;IACA;IACAA,KAAK,CAACI,OAAO,CAAC,CAAC;;IAEf;IACA,IAAKV,mBAAmB,CAACD,OAAO,EAAG;MAClC;IACD;;IAEA;IACA;IACA;IACA;IACA;IACA;IACA;IACA,MAAMY,sBAAsB,GAAGL,KAAK,CAACC,MAAM,CAACK,YAAY,CACvD,sDACD,CAAC;IACD,IACCD,sBAAsB,IACtBL,KAAK,CAACO,aAAa,EAAEC,OAAO,CAAEH,sBAAuB,CAAC,EACrD;MACD;IACD;IAEAV,qBAAqB,CAACF,OAAO,GAAGgB,UAAU,CAAE,MAAM;MACjD;MACA;MACA;MACA;MACA,IAAK,CAAEC,QAAQ,CAACC,QAAQ,CAAC,CAAC,EAAG;QAC5BX,KAAK,CAACY,cAAc,CAAC,CAAC;QACtB;MACD;MAEA,IAAK,UAAU,KAAK,OAAOtB,wBAAwB,CAACG,OAAO,EAAG;QAC7DH,wBAAwB,CAACG,OAAO,CAAEO,KAAM,CAAC;MAC1C;IACD,CAAC,EAAE,CAAE,CAAC;EACP,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO;IACNa,OAAO,EAAEjB,eAAe;IACxBkB,WAAW,EAAEf,oBAAoB;IACjCgB,SAAS,EAAEhB,oBAAoB;IAC/BiB,YAAY,EAAEjB,oBAAoB;IAClCkB,UAAU,EAAElB,oBAAoB;IAChCmB,MAAM,EAAEf;EACT,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-focus-outside/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef } from '@wordpress/element';\n\n/**\n * Input types which are classified as button types, for use in considering\n * whether element is a (focus-normalized) button.\n */\nconst INPUT_BUTTON_TYPES = [ 'button', 'submit' ];\n\n/**\n * List of HTML button elements subject to focus normalization\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n */\ntype FocusNormalizedButton =\n\t| HTMLButtonElement\n\t| HTMLLinkElement\n\t| HTMLInputElement;\n\n/**\n * Returns true if the given element is a button element subject to focus\n * normalization, or false otherwise.\n *\n * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n *\n * @param eventTarget The target from a mouse or touch event.\n *\n * @return Whether the element is a button element subject to focus normalization.\n */\nfunction isFocusNormalizedButton(\n\teventTarget: EventTarget\n): eventTarget is FocusNormalizedButton {\n\tif ( ! ( eventTarget instanceof window.HTMLElement ) ) {\n\t\treturn false;\n\t}\n\tswitch ( eventTarget.nodeName ) {\n\t\tcase 'A':\n\t\tcase 'BUTTON':\n\t\t\treturn true;\n\n\t\tcase 'INPUT':\n\t\t\treturn INPUT_BUTTON_TYPES.includes(\n\t\t\t\t( eventTarget as HTMLInputElement ).type\n\t\t\t);\n\t}\n\n\treturn false;\n}\n\ntype UseFocusOutsideReturn = {\n\tonFocus: React.FocusEventHandler;\n\tonMouseDown: React.MouseEventHandler;\n\tonMouseUp: React.MouseEventHandler;\n\tonTouchStart: React.TouchEventHandler;\n\tonTouchEnd: React.TouchEventHandler;\n\tonBlur: React.FocusEventHandler;\n};\n\n/**\n * A react hook that can be used to check whether focus has moved outside the\n * element the event handlers are bound to.\n *\n * @param onFocusOutside A callback triggered when focus moves outside\n * the element the event handlers are bound to.\n *\n * @return An object containing event handlers. Bind the event handlers to a\n * wrapping element element to capture when focus moves outside that element.\n */\nexport default function useFocusOutside(\n\tonFocusOutside: ( ( event: React.FocusEvent ) => void ) | undefined\n): UseFocusOutsideReturn {\n\tconst currentOnFocusOutsideRef = useRef( onFocusOutside );\n\tuseEffect( () => {\n\t\tcurrentOnFocusOutsideRef.current = onFocusOutside;\n\t}, [ onFocusOutside ] );\n\n\tconst preventBlurCheckRef = useRef( false );\n\n\tconst blurCheckTimeoutIdRef = useRef< number | undefined >();\n\n\t/**\n\t * Cancel a blur check timeout.\n\t */\n\tconst cancelBlurCheck = useCallback( () => {\n\t\tclearTimeout( blurCheckTimeoutIdRef.current );\n\t}, [] );\n\n\t// Cancel a blur check if the callback or ref is no longer provided.\n\tuseEffect( () => {\n\t\tif ( ! onFocusOutside ) {\n\t\t\tcancelBlurCheck();\n\t\t}\n\t}, [ onFocusOutside, cancelBlurCheck ] );\n\n\t/**\n\t * Handles a mousedown or mouseup event to respectively assign and\n\t * unassign a flag for preventing blur check on button elements. Some\n\t * browsers, namely Firefox and Safari, do not emit a focus event on\n\t * button elements when clicked, while others do. The logic here\n\t * intends to normalize this as treating click on buttons as focus.\n\t *\n\t * @param event\n\t * @see https://developer.mozilla.org/en-US/docs/Web/HTML/Element/button#Clicking_and_focus\n\t */\n\tconst normalizeButtonFocus: React.EventHandler<\n\t\tReact.MouseEvent | React.TouchEvent\n\t> = useCallback( ( event ) => {\n\t\tconst { type, target } = event;\n\t\tconst isInteractionEnd = [ 'mouseup', 'touchend' ].includes( type );\n\n\t\tif ( isInteractionEnd ) {\n\t\t\tpreventBlurCheckRef.current = false;\n\t\t} else if ( isFocusNormalizedButton( target ) ) {\n\t\t\tpreventBlurCheckRef.current = true;\n\t\t}\n\t}, [] );\n\n\t/**\n\t * A callback triggered when a blur event occurs on the element the handler\n\t * is bound to.\n\t *\n\t * Calls the `onFocusOutside` callback in an immediate timeout if focus has\n\t * move outside the bound element and is still within the document.\n\t */\n\tconst queueBlurCheck: React.FocusEventHandler = useCallback( ( event ) => {\n\t\t// React does not allow using an event reference asynchronously\n\t\t// due to recycling behavior, except when explicitly persisted.\n\t\tevent.persist();\n\n\t\t// Skip blur check if clicking button. See `normalizeButtonFocus`.\n\t\tif ( preventBlurCheckRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// The usage of this attribute should be avoided. The only use case\n\t\t// would be when we load modals that are not React components and\n\t\t// therefore don't exist in the React tree. An example is opening\n\t\t// the Media Library modal from another dialog.\n\t\t// This attribute should contain a selector of the related target\n\t\t// we want to ignore, because we still need to trigger the blur event\n\t\t// on all other cases.\n\t\tconst ignoreForRelatedTarget = event.target.getAttribute(\n\t\t\t'data-unstable-ignore-focus-outside-for-relatedtarget'\n\t\t);\n\t\tif (\n\t\t\tignoreForRelatedTarget &&\n\t\t\tevent.relatedTarget?.closest( ignoreForRelatedTarget )\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tblurCheckTimeoutIdRef.current = setTimeout( () => {\n\t\t\t// If document is not focused then focus should remain\n\t\t\t// inside the wrapped component and therefore we cancel\n\t\t\t// this blur event thereby leaving focus in place.\n\t\t\t// https://developer.mozilla.org/en-US/docs/Web/API/Document/hasFocus.\n\t\t\tif ( ! document.hasFocus() ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif ( 'function' === typeof currentOnFocusOutsideRef.current ) {\n\t\t\t\tcurrentOnFocusOutsideRef.current( event );\n\t\t\t}\n\t\t}, 0 );\n\t}, [] );\n\n\treturn {\n\t\tonFocus: cancelBlurCheck,\n\t\tonMouseDown: normalizeButtonFocus,\n\t\tonMouseUp: normalizeButtonFocus,\n\t\tonTouchStart: normalizeButtonFocus,\n\t\tonTouchEnd: normalizeButtonFocus,\n\t\tonBlur: queueBlurCheck,\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAM/C,MAAM,qBAAqB,CAAE,UAAU,QAAS;AAsBhD,SAAS,wBACR,aACuC;AACvC,MAAK,EAAI,uBAAuB,OAAO,cAAgB;AACtD,WAAO;AAAA,EACR;AACA,UAAS,YAAY,UAAW;AAAA,IAC/B,KAAK;AAAA,IACL,KAAK;AACJ,aAAO;AAAA,IAER,KAAK;AACJ,aAAO,mBAAmB;AAAA,QACvB,YAAkC;AAAA,MACrC;AAAA,EACF;AAEA,SAAO;AACR;AAqBe,SAAR,gBACN,gBACwB;AACxB,QAAM,+BAA2B,uBAAQ,cAAe;AACxD,gCAAW,MAAM;AAChB,6BAAyB,UAAU;AAAA,EACpC,GAAG,CAAE,cAAe,CAAE;AAEtB,QAAM,0BAAsB,uBAAQ,KAAM;AAE1C,QAAM,4BAAwB,uBAA6B;AAK3D,QAAM,sBAAkB,4BAAa,MAAM;AAC1C,iBAAc,sBAAsB,OAAQ;AAAA,EAC7C,GAAG,CAAC,CAAE;AAGN,gCAAW,MAAM;AAChB,QAAK,CAAE,gBAAiB;AACvB,sBAAgB;AAAA,IACjB;AAAA,EACD,GAAG,CAAE,gBAAgB,eAAgB,CAAE;AAYvC,QAAM,2BAEF,4BAAa,CAAE,UAAW;AAC7B,UAAM,EAAE,MAAM,OAAO,IAAI;AACzB,UAAM,mBAAmB,CAAE,WAAW,UAAW,EAAE,SAAU,IAAK;AAElE,QAAK,kBAAmB;AACvB,0BAAoB,UAAU;AAAA,IAC/B,WAAY,wBAAyB,MAAO,GAAI;AAC/C,0BAAoB,UAAU;AAAA,IAC/B;AAAA,EACD,GAAG,CAAC,CAAE;AASN,QAAM,qBAA0C,4BAAa,CAAE,UAAW;AAGzE,UAAM,QAAQ;AAGd,QAAK,oBAAoB,SAAU;AAClC;AAAA,IACD;AASA,UAAM,yBAAyB,MAAM,OAAO;AAAA,MAC3C;AAAA,IACD;AACA,QACC,0BACA,MAAM,eAAe,QAAS,sBAAuB,GACpD;AACD;AAAA,IACD;AAEA,0BAAsB,UAAU,WAAY,MAAM;AAKjD,UAAK,CAAE,SAAS,SAAS,GAAI;AAC5B,cAAM,eAAe;AACrB;AAAA,MACD;AAEA,UAAK,eAAe,OAAO,yBAAyB,SAAU;AAC7D,iCAAyB,QAAS,KAAM;AAAA,MACzC;AAAA,IACD,GAAG,CAAE;AAAA,EACN,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,SAAS;AAAA,IACT,aAAa;AAAA,IACb,WAAW;AAAA,IACX,cAAc;AAAA,IACd,YAAY;AAAA,IACZ,QAAQ;AAAA,EACT;AACD;",
6
+ "names": []
7
+ }
@@ -1,80 +1,59 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_focus_return_exports = {};
20
+ __export(use_focus_return_exports, {
21
+ default: () => use_focus_return_default
5
22
  });
6
- exports.default = void 0;
7
- var _element = require("@wordpress/element");
8
- /**
9
- * WordPress dependencies
10
- */
11
-
12
- /** @type {Element|null} */
23
+ module.exports = __toCommonJS(use_focus_return_exports);
24
+ var import_element = require("@wordpress/element");
13
25
  let origin = null;
14
-
15
- /**
16
- * Adds the unmount behavior of returning focus to the element which had it
17
- * previously as is expected for roles like menus or dialogs.
18
- *
19
- * @param {() => void} [onFocusReturn] Overrides the default return behavior.
20
- * @return {import('react').RefCallback<HTMLElement>} Element Ref.
21
- *
22
- * @example
23
- * ```js
24
- * import { useFocusReturn } from '@wordpress/compose';
25
- *
26
- * const WithFocusReturn = () => {
27
- * const ref = useFocusReturn()
28
- * return (
29
- * <div ref={ ref }>
30
- * <Button />
31
- * <Button />
32
- * </div>
33
- * );
34
- * }
35
- * ```
36
- */
37
26
  function useFocusReturn(onFocusReturn) {
38
- /** @type {import('react').MutableRefObject<null | HTMLElement>} */
39
- const ref = (0, _element.useRef)(null);
40
- /** @type {import('react').MutableRefObject<null | Element>} */
41
- const focusedBeforeMount = (0, _element.useRef)(null);
42
- const onFocusReturnRef = (0, _element.useRef)(onFocusReturn);
43
- (0, _element.useEffect)(() => {
27
+ const ref = (0, import_element.useRef)(null);
28
+ const focusedBeforeMount = (0, import_element.useRef)(null);
29
+ const onFocusReturnRef = (0, import_element.useRef)(onFocusReturn);
30
+ (0, import_element.useEffect)(() => {
44
31
  onFocusReturnRef.current = onFocusReturn;
45
32
  }, [onFocusReturn]);
46
- return (0, _element.useCallback)(node => {
33
+ return (0, import_element.useCallback)((node) => {
47
34
  if (node) {
48
- var _activeDocument$activ;
49
- // Set ref to be used when unmounting.
50
35
  ref.current = node;
51
-
52
- // Only set when the node mounts.
53
36
  if (focusedBeforeMount.current) {
54
37
  return;
55
38
  }
56
39
  const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument;
57
- focusedBeforeMount.current = (_activeDocument$activ = activeDocument?.activeElement) !== null && _activeDocument$activ !== void 0 ? _activeDocument$activ : null;
40
+ focusedBeforeMount.current = activeDocument?.activeElement ?? null;
58
41
  } else if (focusedBeforeMount.current) {
59
- const isFocused = ref.current?.contains(ref.current?.ownerDocument.activeElement);
42
+ const isFocused = ref.current?.contains(
43
+ ref.current?.ownerDocument.activeElement
44
+ );
60
45
  if (ref.current?.isConnected && !isFocused) {
61
- var _origin;
62
- (_origin = origin) !== null && _origin !== void 0 ? _origin : origin = focusedBeforeMount.current;
46
+ origin ??= focusedBeforeMount.current;
63
47
  return;
64
48
  }
65
-
66
- // Defer to the component's own explicit focus return behavior, if
67
- // specified. This allows for support that the `onFocusReturn`
68
- // decides to allow the default behavior to occur under some
69
- // conditions.
70
49
  if (onFocusReturnRef.current) {
71
50
  onFocusReturnRef.current();
72
51
  } else {
73
- /** @type {null|HTMLElement} */(!focusedBeforeMount.current.isConnected ? origin : focusedBeforeMount.current)?.focus();
52
+ (!focusedBeforeMount.current.isConnected ? origin : focusedBeforeMount.current)?.focus();
74
53
  }
75
54
  origin = null;
76
55
  }
77
56
  }, []);
78
57
  }
79
- var _default = exports.default = useFocusReturn;
80
- //# sourceMappingURL=index.js.map
58
+ var use_focus_return_default = useFocusReturn;
59
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","origin","useFocusReturn","onFocusReturn","ref","useRef","focusedBeforeMount","onFocusReturnRef","useEffect","current","useCallback","node","_activeDocument$activ","activeDocument","ownerDocument","activeElement","window","HTMLIFrameElement","contentDocument","isFocused","contains","isConnected","_origin","focus","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-focus-return/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\n/** @type {Element|null} */\nlet origin = null;\n\n/**\n * Adds the unmount behavior of returning focus to the element which had it\n * previously as is expected for roles like menus or dialogs.\n *\n * @param {() => void} [onFocusReturn] Overrides the default return behavior.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useFocusReturn } from '@wordpress/compose';\n *\n * const WithFocusReturn = () => {\n * const ref = useFocusReturn()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useFocusReturn( onFocusReturn ) {\n\t/** @type {import('react').MutableRefObject<null | HTMLElement>} */\n\tconst ref = useRef( null );\n\t/** @type {import('react').MutableRefObject<null | Element>} */\n\tconst focusedBeforeMount = useRef( null );\n\tconst onFocusReturnRef = useRef( onFocusReturn );\n\tuseEffect( () => {\n\t\tonFocusReturnRef.current = onFocusReturn;\n\t}, [ onFocusReturn ] );\n\n\treturn useCallback( ( node ) => {\n\t\tif ( node ) {\n\t\t\t// Set ref to be used when unmounting.\n\t\t\tref.current = node;\n\n\t\t\t// Only set when the node mounts.\n\t\t\tif ( focusedBeforeMount.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst activeDocument =\n\t\t\t\tnode.ownerDocument.activeElement instanceof\n\t\t\t\twindow.HTMLIFrameElement\n\t\t\t\t\t? node.ownerDocument.activeElement.contentDocument\n\t\t\t\t\t: node.ownerDocument;\n\n\t\t\tfocusedBeforeMount.current = activeDocument?.activeElement ?? null;\n\t\t} else if ( focusedBeforeMount.current ) {\n\t\t\tconst isFocused = ref.current?.contains(\n\t\t\t\tref.current?.ownerDocument.activeElement\n\t\t\t);\n\n\t\t\tif ( ref.current?.isConnected && ! isFocused ) {\n\t\t\t\torigin ??= focusedBeforeMount.current;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Defer to the component's own explicit focus return behavior, if\n\t\t\t// specified. This allows for support that the `onFocusReturn`\n\t\t\t// decides to allow the default behavior to occur under some\n\t\t\t// conditions.\n\t\t\tif ( onFocusReturnRef.current ) {\n\t\t\t\tonFocusReturnRef.current();\n\t\t\t} else {\n\t\t\t\t/** @type {null|HTMLElement} */ (\n\t\t\t\t\t! focusedBeforeMount.current.isConnected\n\t\t\t\t\t\t? origin\n\t\t\t\t\t\t: focusedBeforeMount.current\n\t\t\t\t)?.focus();\n\t\t\t}\n\t\t\torigin = null;\n\t\t}\n\t}, [] );\n}\n\nexport default useFocusReturn;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA,IAAIC,MAAM,GAAG,IAAI;;AAEjB;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,cAAcA,CAAEC,aAAa,EAAG;EACxC;EACA,MAAMC,GAAG,GAAG,IAAAC,eAAM,EAAE,IAAK,CAAC;EAC1B;EACA,MAAMC,kBAAkB,GAAG,IAAAD,eAAM,EAAE,IAAK,CAAC;EACzC,MAAME,gBAAgB,GAAG,IAAAF,eAAM,EAAEF,aAAc,CAAC;EAChD,IAAAK,kBAAS,EAAE,MAAM;IAChBD,gBAAgB,CAACE,OAAO,GAAGN,aAAa;EACzC,CAAC,EAAE,CAAEA,aAAa,CAAG,CAAC;EAEtB,OAAO,IAAAO,oBAAW,EAAIC,IAAI,IAAM;IAC/B,IAAKA,IAAI,EAAG;MAAA,IAAAC,qBAAA;MACX;MACAR,GAAG,CAACK,OAAO,GAAGE,IAAI;;MAElB;MACA,IAAKL,kBAAkB,CAACG,OAAO,EAAG;QACjC;MACD;MAEA,MAAMI,cAAc,GACnBF,IAAI,CAACG,aAAa,CAACC,aAAa,YAChCC,MAAM,CAACC,iBAAiB,GACrBN,IAAI,CAACG,aAAa,CAACC,aAAa,CAACG,eAAe,GAChDP,IAAI,CAACG,aAAa;MAEtBR,kBAAkB,CAACG,OAAO,IAAAG,qBAAA,GAAGC,cAAc,EAAEE,aAAa,cAAAH,qBAAA,cAAAA,qBAAA,GAAI,IAAI;IACnE,CAAC,MAAM,IAAKN,kBAAkB,CAACG,OAAO,EAAG;MACxC,MAAMU,SAAS,GAAGf,GAAG,CAACK,OAAO,EAAEW,QAAQ,CACtChB,GAAG,CAACK,OAAO,EAAEK,aAAa,CAACC,aAC5B,CAAC;MAED,IAAKX,GAAG,CAACK,OAAO,EAAEY,WAAW,IAAI,CAAEF,SAAS,EAAG;QAAA,IAAAG,OAAA;QAC9C,CAAAA,OAAA,GAAArB,MAAM,cAAAqB,OAAA,cAAAA,OAAA,GAANrB,MAAM,GAAKK,kBAAkB,CAACG,OAAO;QACrC;MACD;;MAEA;MACA;MACA;MACA;MACA,IAAKF,gBAAgB,CAACE,OAAO,EAAG;QAC/BF,gBAAgB,CAACE,OAAO,CAAC,CAAC;MAC3B,CAAC,MAAM;QACN,+BAAgC,CAC/B,CAAEH,kBAAkB,CAACG,OAAO,CAACY,WAAW,GACrCpB,MAAM,GACNK,kBAAkB,CAACG,OAAO,GAC3Bc,KAAK,CAAC,CAAC;MACX;MACAtB,MAAM,GAAG,IAAI;IACd;EACD,CAAC,EAAE,EAAG,CAAC;AACR;AAAC,IAAAuB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcxB,cAAc","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-focus-return/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\n/** @type {Element|null} */\nlet origin = null;\n\n/**\n * Adds the unmount behavior of returning focus to the element which had it\n * previously as is expected for roles like menus or dialogs.\n *\n * @param {() => void} [onFocusReturn] Overrides the default return behavior.\n * @return {import('react').RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useFocusReturn } from '@wordpress/compose';\n *\n * const WithFocusReturn = () => {\n * const ref = useFocusReturn()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useFocusReturn( onFocusReturn ) {\n\t/** @type {import('react').MutableRefObject<null | HTMLElement>} */\n\tconst ref = useRef( null );\n\t/** @type {import('react').MutableRefObject<null | Element>} */\n\tconst focusedBeforeMount = useRef( null );\n\tconst onFocusReturnRef = useRef( onFocusReturn );\n\tuseEffect( () => {\n\t\tonFocusReturnRef.current = onFocusReturn;\n\t}, [ onFocusReturn ] );\n\n\treturn useCallback( ( node ) => {\n\t\tif ( node ) {\n\t\t\t// Set ref to be used when unmounting.\n\t\t\tref.current = node;\n\n\t\t\t// Only set when the node mounts.\n\t\t\tif ( focusedBeforeMount.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst activeDocument =\n\t\t\t\tnode.ownerDocument.activeElement instanceof\n\t\t\t\twindow.HTMLIFrameElement\n\t\t\t\t\t? node.ownerDocument.activeElement.contentDocument\n\t\t\t\t\t: node.ownerDocument;\n\n\t\t\tfocusedBeforeMount.current = activeDocument?.activeElement ?? null;\n\t\t} else if ( focusedBeforeMount.current ) {\n\t\t\tconst isFocused = ref.current?.contains(\n\t\t\t\tref.current?.ownerDocument.activeElement\n\t\t\t);\n\n\t\t\tif ( ref.current?.isConnected && ! isFocused ) {\n\t\t\t\torigin ??= focusedBeforeMount.current;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Defer to the component's own explicit focus return behavior, if\n\t\t\t// specified. This allows for support that the `onFocusReturn`\n\t\t\t// decides to allow the default behavior to occur under some\n\t\t\t// conditions.\n\t\t\tif ( onFocusReturnRef.current ) {\n\t\t\t\tonFocusReturnRef.current();\n\t\t\t} else {\n\t\t\t\t/** @type {null|HTMLElement} */ (\n\t\t\t\t\t! focusedBeforeMount.current.isConnected\n\t\t\t\t\t\t? origin\n\t\t\t\t\t\t: focusedBeforeMount.current\n\t\t\t\t)?.focus();\n\t\t\t}\n\t\t\torigin = null;\n\t\t}\n\t}, [] );\n}\n\nexport default useFocusReturn;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAG/C,IAAI,SAAS;AAwBb,SAAS,eAAgB,eAAgB;AAExC,QAAM,UAAM,uBAAQ,IAAK;AAEzB,QAAM,yBAAqB,uBAAQ,IAAK;AACxC,QAAM,uBAAmB,uBAAQ,aAAc;AAC/C,gCAAW,MAAM;AAChB,qBAAiB,UAAU;AAAA,EAC5B,GAAG,CAAE,aAAc,CAAE;AAErB,aAAO,4BAAa,CAAE,SAAU;AAC/B,QAAK,MAAO;AAEX,UAAI,UAAU;AAGd,UAAK,mBAAmB,SAAU;AACjC;AAAA,MACD;AAEA,YAAM,iBACL,KAAK,cAAc,yBACnB,OAAO,oBACJ,KAAK,cAAc,cAAc,kBACjC,KAAK;AAET,yBAAmB,UAAU,gBAAgB,iBAAiB;AAAA,IAC/D,WAAY,mBAAmB,SAAU;AACxC,YAAM,YAAY,IAAI,SAAS;AAAA,QAC9B,IAAI,SAAS,cAAc;AAAA,MAC5B;AAEA,UAAK,IAAI,SAAS,eAAe,CAAE,WAAY;AAC9C,mBAAW,mBAAmB;AAC9B;AAAA,MACD;AAMA,UAAK,iBAAiB,SAAU;AAC/B,yBAAiB,QAAQ;AAAA,MAC1B,OAAO;AAC0B,SAC/B,CAAE,mBAAmB,QAAQ,cAC1B,SACA,mBAAmB,UACpB,MAAM;AAAA,MACV;AACA,eAAS;AAAA,IACV;AAAA,EACD,GAAG,CAAC,CAAE;AACP;AAEA,IAAO,2BAAQ;",
6
+ "names": []
7
+ }
@@ -1,53 +1,56 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var use_focusable_iframe_exports = {};
30
+ __export(use_focusable_iframe_exports, {
31
+ default: () => useFocusableIframe
6
32
  });
7
- exports.default = useFocusableIframe;
8
- var _useRefEffect = _interopRequireDefault(require("../use-ref-effect"));
9
- /**
10
- * External dependencies
11
- */
12
-
13
- /**
14
- * Internal dependencies
15
- */
16
-
17
- /**
18
- * Dispatches a bubbling focus event when the iframe receives focus. Use
19
- * `onFocus` as usual on the iframe or a parent element.
20
- *
21
- * @return Ref to pass to the iframe.
22
- */
33
+ module.exports = __toCommonJS(use_focusable_iframe_exports);
34
+ var import_use_ref_effect = __toESM(require("../use-ref-effect"));
23
35
  function useFocusableIframe() {
24
- return (0, _useRefEffect.default)(element => {
25
- const {
26
- ownerDocument
27
- } = element;
36
+ return (0, import_use_ref_effect.default)((element) => {
37
+ const { ownerDocument } = element;
28
38
  if (!ownerDocument) {
29
39
  return;
30
40
  }
31
- const {
32
- defaultView
33
- } = ownerDocument;
41
+ const { defaultView } = ownerDocument;
34
42
  if (!defaultView) {
35
43
  return;
36
44
  }
37
-
38
- /**
39
- * Checks whether the iframe is the activeElement, inferring that it has
40
- * then received focus, and dispatches a focus event.
41
- */
42
45
  function checkFocus() {
43
46
  if (ownerDocument && ownerDocument.activeElement === element) {
44
47
  element.focus();
45
48
  }
46
49
  }
47
- defaultView.addEventListener('blur', checkFocus);
50
+ defaultView.addEventListener("blur", checkFocus);
48
51
  return () => {
49
- defaultView.removeEventListener('blur', checkFocus);
52
+ defaultView.removeEventListener("blur", checkFocus);
50
53
  };
51
54
  }, []);
52
55
  }
53
- //# sourceMappingURL=index.js.map
56
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_useRefEffect","_interopRequireDefault","require","useFocusableIframe","useRefEffect","element","ownerDocument","defaultView","checkFocus","activeElement","focus","addEventListener","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-focusable-iframe/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Dispatches a bubbling focus event when the iframe receives focus. Use\n * `onFocus` as usual on the iframe or a parent element.\n *\n * @return Ref to pass to the iframe.\n */\nexport default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {\n\treturn useRefEffect( ( element ) => {\n\t\tconst { ownerDocument } = element;\n\t\tif ( ! ownerDocument ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { defaultView } = ownerDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Checks whether the iframe is the activeElement, inferring that it has\n\t\t * then received focus, and dispatches a focus event.\n\t\t */\n\t\tfunction checkFocus() {\n\t\t\tif ( ownerDocument && ownerDocument.activeElement === element ) {\n\t\t\t\t( element as HTMLElement ).focus();\n\t\t\t}\n\t\t}\n\n\t\tdefaultView.addEventListener( 'blur', checkFocus );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'blur', checkFocus );\n\t\t};\n\t}, [] );\n}\n"],"mappings":";;;;;;;AAQA,IAAAA,aAAA,GAAAC,sBAAA,CAAAC,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,kBAAkBA,CAAA,EAAqC;EAC9E,OAAO,IAAAC,qBAAY,EAAIC,OAAO,IAAM;IACnC,MAAM;MAAEC;IAAc,CAAC,GAAGD,OAAO;IACjC,IAAK,CAAEC,aAAa,EAAG;MACtB;IACD;IACA,MAAM;MAAEC;IAAY,CAAC,GAAGD,aAAa;IACrC,IAAK,CAAEC,WAAW,EAAG;MACpB;IACD;;IAEA;AACF;AACA;AACA;IACE,SAASC,UAAUA,CAAA,EAAG;MACrB,IAAKF,aAAa,IAAIA,aAAa,CAACG,aAAa,KAAKJ,OAAO,EAAG;QAC7DA,OAAO,CAAkBK,KAAK,CAAC,CAAC;MACnC;IACD;IAEAH,WAAW,CAACI,gBAAgB,CAAE,MAAM,EAAEH,UAAW,CAAC;IAClD,OAAO,MAAM;MACZD,WAAW,CAACK,mBAAmB,CAAE,MAAM,EAAEJ,UAAW,CAAC;IACtD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-focusable-iframe/index.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Dispatches a bubbling focus event when the iframe receives focus. Use\n * `onFocus` as usual on the iframe or a parent element.\n *\n * @return Ref to pass to the iframe.\n */\nexport default function useFocusableIframe(): RefCallback< HTMLIFrameElement > {\n\treturn useRefEffect( ( element ) => {\n\t\tconst { ownerDocument } = element;\n\t\tif ( ! ownerDocument ) {\n\t\t\treturn;\n\t\t}\n\t\tconst { defaultView } = ownerDocument;\n\t\tif ( ! defaultView ) {\n\t\t\treturn;\n\t\t}\n\n\t\t/**\n\t\t * Checks whether the iframe is the activeElement, inferring that it has\n\t\t * then received focus, and dispatches a focus event.\n\t\t */\n\t\tfunction checkFocus() {\n\t\t\tif ( ownerDocument && ownerDocument.activeElement === element ) {\n\t\t\t\t( element as HTMLElement ).focus();\n\t\t\t}\n\t\t}\n\n\t\tdefaultView.addEventListener( 'blur', checkFocus );\n\t\treturn () => {\n\t\t\tdefaultView.removeEventListener( 'blur', checkFocus );\n\t\t};\n\t}, [] );\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,4BAAyB;AAQV,SAAR,qBAAwE;AAC9E,aAAO,sBAAAA,SAAc,CAAE,YAAa;AACnC,UAAM,EAAE,cAAc,IAAI;AAC1B,QAAK,CAAE,eAAgB;AACtB;AAAA,IACD;AACA,UAAM,EAAE,YAAY,IAAI;AACxB,QAAK,CAAE,aAAc;AACpB;AAAA,IACD;AAMA,aAAS,aAAa;AACrB,UAAK,iBAAiB,cAAc,kBAAkB,SAAU;AAC/D,QAAE,QAAyB,MAAM;AAAA,MAClC;AAAA,IACD;AAEA,gBAAY,iBAAkB,QAAQ,UAAW;AACjD,WAAO,MAAM;AACZ,kBAAY,oBAAqB,QAAQ,UAAW;AAAA,IACrD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
6
+ "names": ["useRefEffect"]
7
+ }
@@ -1,51 +1,35 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_instance_id_exports = {};
20
+ __export(use_instance_id_exports, {
21
+ default: () => use_instance_id_default
5
22
  });
6
- exports.default = void 0;
7
- var _element = require("@wordpress/element");
8
- /**
9
- * WordPress dependencies
10
- */
11
-
12
- const instanceMap = new WeakMap();
13
-
14
- /**
15
- * Creates a new id for a given object.
16
- *
17
- * @param object Object reference to create an id for.
18
- * @return The instance id (index).
19
- */
23
+ module.exports = __toCommonJS(use_instance_id_exports);
24
+ var import_element = require("@wordpress/element");
25
+ const instanceMap = /* @__PURE__ */ new WeakMap();
20
26
  function createId(object) {
21
27
  const instances = instanceMap.get(object) || 0;
22
28
  instanceMap.set(object, instances + 1);
23
29
  return instances;
24
30
  }
25
-
26
- /**
27
- * Specify the useInstanceId *function* signatures.
28
- *
29
- * More accurately, useInstanceId distinguishes between three different
30
- * signatures:
31
- *
32
- * 1. When only object is given, the returned value is a number
33
- * 2. When object and prefix is given, the returned value is a string
34
- * 3. When preferredId is given, the returned value is the type of preferredId
35
- *
36
- * @param object Object reference to create an id for.
37
- */
38
-
39
- /**
40
- * Provides a unique instance ID.
41
- *
42
- * @param object Object reference to create an id for.
43
- * @param [prefix] Prefix for the unique id.
44
- * @param [preferredId] Default ID to use.
45
- * @return The unique instance id.
46
- */
47
31
  function useInstanceId(object, prefix, preferredId) {
48
- return (0, _element.useMemo)(() => {
32
+ return (0, import_element.useMemo)(() => {
49
33
  if (preferredId) {
50
34
  return preferredId;
51
35
  }
@@ -53,5 +37,5 @@ function useInstanceId(object, prefix, preferredId) {
53
37
  return prefix ? `${prefix}-${id}` : id;
54
38
  }, [object, preferredId, prefix]);
55
39
  }
56
- var _default = exports.default = useInstanceId;
57
- //# sourceMappingURL=index.js.map
40
+ var use_instance_id_default = useInstanceId;
41
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","instanceMap","WeakMap","createId","object","instances","get","set","useInstanceId","prefix","preferredId","useMemo","id","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-instance-id/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n *\n * @param object Object reference to create an id for.\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) {\n\t\t\treturn preferredId;\n\t\t}\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object, preferredId, prefix ] );\n}\n\nexport default useInstanceId;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,MAAMC,WAAW,GAAG,IAAIC,OAAO,CAAmB,CAAC;;AAEnD;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,QAAQA,CAAEC,MAAc,EAAW;EAC3C,MAAMC,SAAS,GAAGJ,WAAW,CAACK,GAAG,CAAEF,MAAO,CAAC,IAAI,CAAC;EAChDH,WAAW,CAACM,GAAG,CAAEH,MAAM,EAAEC,SAAS,GAAG,CAAE,CAAC;EACxC,OAAOA,SAAS;AACjB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AASA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CACrBJ,MAAc,EACdK,MAAe,EACfC,WAA6B,EACX;EAClB,OAAO,IAAAC,gBAAO,EAAE,MAAM;IACrB,IAAKD,WAAW,EAAG;MAClB,OAAOA,WAAW;IACnB;IACA,MAAME,EAAE,GAAGT,QAAQ,CAAEC,MAAO,CAAC;IAE7B,OAAOK,MAAM,GAAG,GAAIA,MAAM,IAAMG,EAAE,EAAG,GAAGA,EAAE;EAC3C,CAAC,EAAE,CAAER,MAAM,EAAEM,WAAW,EAAED,MAAM,CAAG,CAAC;AACrC;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcP,aAAa","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-instance-id/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo } from '@wordpress/element';\n\nconst instanceMap = new WeakMap< object, number >();\n\n/**\n * Creates a new id for a given object.\n *\n * @param object Object reference to create an id for.\n * @return The instance id (index).\n */\nfunction createId( object: object ): number {\n\tconst instances = instanceMap.get( object ) || 0;\n\tinstanceMap.set( object, instances + 1 );\n\treturn instances;\n}\n\n/**\n * Specify the useInstanceId *function* signatures.\n *\n * More accurately, useInstanceId distinguishes between three different\n * signatures:\n *\n * 1. When only object is given, the returned value is a number\n * 2. When object and prefix is given, the returned value is a string\n * 3. When preferredId is given, the returned value is the type of preferredId\n *\n * @param object Object reference to create an id for.\n */\nfunction useInstanceId( object: object ): number;\nfunction useInstanceId( object: object, prefix: string ): string;\nfunction useInstanceId< T extends string | number >(\n\tobject: object,\n\tprefix: string,\n\tpreferredId?: T\n): T;\n\n/**\n * Provides a unique instance ID.\n *\n * @param object Object reference to create an id for.\n * @param [prefix] Prefix for the unique id.\n * @param [preferredId] Default ID to use.\n * @return The unique instance id.\n */\nfunction useInstanceId(\n\tobject: object,\n\tprefix?: string,\n\tpreferredId?: string | number\n): string | number {\n\treturn useMemo( () => {\n\t\tif ( preferredId ) {\n\t\t\treturn preferredId;\n\t\t}\n\t\tconst id = createId( object );\n\n\t\treturn prefix ? `${ prefix }-${ id }` : id;\n\t}, [ object, preferredId, prefix ] );\n}\n\nexport default useInstanceId;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAwB;AAExB,MAAM,cAAc,oBAAI,QAA0B;AAQlD,SAAS,SAAU,QAAyB;AAC3C,QAAM,YAAY,YAAY,IAAK,MAAO,KAAK;AAC/C,cAAY,IAAK,QAAQ,YAAY,CAAE;AACvC,SAAO;AACR;AA8BA,SAAS,cACR,QACA,QACA,aACkB;AAClB,aAAO,wBAAS,MAAM;AACrB,QAAK,aAAc;AAClB,aAAO;AAAA,IACR;AACA,UAAM,KAAK,SAAU,MAAO;AAE5B,WAAO,SAAS,GAAI,MAAO,IAAK,EAAG,KAAK;AAAA,EACzC,GAAG,CAAE,QAAQ,aAAa,MAAO,CAAE;AACpC;AAEA,IAAO,0BAAQ;",
6
+ "names": []
7
+ }
@@ -1,19 +1,27 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_isomorphic_layout_effect_exports = {};
20
+ __export(use_isomorphic_layout_effect_exports, {
21
+ default: () => use_isomorphic_layout_effect_default
5
22
  });
6
- exports.default = void 0;
7
- var _element = require("@wordpress/element");
8
- /**
9
- * WordPress dependencies
10
- */
11
-
12
- /**
13
- * Preferred over direct usage of `useLayoutEffect` when supporting
14
- * server rendered components (SSR) because currently React
15
- * throws a warning when using useLayoutEffect in that environment.
16
- */
17
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? _element.useLayoutEffect : _element.useEffect;
18
- var _default = exports.default = useIsomorphicLayoutEffect;
19
- //# sourceMappingURL=index.js.map
23
+ module.exports = __toCommonJS(use_isomorphic_layout_effect_exports);
24
+ var import_element = require("@wordpress/element");
25
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? import_element.useLayoutEffect : import_element.useEffect;
26
+ var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
27
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","useIsomorphicLayoutEffect","window","useLayoutEffect","useEffect","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-isomorphic-layout-effect/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useLayoutEffect } from '@wordpress/element';\n\n/**\n * Preferred over direct usage of `useLayoutEffect` when supporting\n * server rendered components (SSR) because currently React\n * throws a warning when using useLayoutEffect in that environment.\n */\nconst useIsomorphicLayoutEffect =\n\ttypeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,GAC9B,OAAOC,MAAM,KAAK,WAAW,GAAGC,wBAAe,GAAGC,kBAAS;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAE9CN,yBAAyB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-isomorphic-layout-effect/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useLayoutEffect } from '@wordpress/element';\n\n/**\n * Preferred over direct usage of `useLayoutEffect` when supporting\n * server rendered components (SSR) because currently React\n * throws a warning when using useLayoutEffect in that environment.\n */\nconst useIsomorphicLayoutEffect =\n\ttypeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2C;AAO3C,MAAM,4BACL,OAAO,WAAW,cAAc,iCAAkB;AAEnD,IAAO,uCAAQ;",
6
+ "names": []
7
+ }
@@ -1,89 +1,92 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var use_keyboard_shortcut_exports = {};
30
+ __export(use_keyboard_shortcut_exports, {
31
+ default: () => use_keyboard_shortcut_default
6
32
  });
7
- exports.default = void 0;
8
- var _mousetrap = _interopRequireDefault(require("mousetrap"));
9
- require("mousetrap/plugins/global-bind/mousetrap-global-bind");
10
- var _element = require("@wordpress/element");
11
- var _keycodes = require("@wordpress/keycodes");
12
- /**
13
- * External dependencies
14
- */
15
-
16
- /**
17
- * WordPress dependencies
18
- */
19
-
20
- /**
21
- * A block selection object.
22
- *
23
- * @typedef {Object} WPKeyboardShortcutConfig
24
- *
25
- * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.
26
- * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.
27
- * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.
28
- * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.
29
- */
30
-
31
- /* eslint-disable jsdoc/valid-types */
32
- /**
33
- * Attach a keyboard shortcut handler.
34
- *
35
- * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.
36
- *
37
- * @param {string[]|string} shortcuts Keyboard Shortcuts.
38
- * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.
39
- * @param {WPKeyboardShortcutConfig} options Shortcut options.
40
- */
41
- function useKeyboardShortcut(/* eslint-enable jsdoc/valid-types */
42
- shortcuts, callback, {
33
+ module.exports = __toCommonJS(use_keyboard_shortcut_exports);
34
+ var import_mousetrap = __toESM(require("mousetrap"));
35
+ var import_mousetrap_global_bind = require("mousetrap/plugins/global-bind/mousetrap-global-bind");
36
+ var import_element = require("@wordpress/element");
37
+ var import_keycodes = require("@wordpress/keycodes");
38
+ function useKeyboardShortcut(shortcuts, callback, {
43
39
  bindGlobal = false,
44
- eventName = 'keydown',
40
+ eventName = "keydown",
45
41
  isDisabled = false,
46
42
  // This is important for performance considerations.
47
43
  target
48
44
  } = {}) {
49
- const currentCallbackRef = (0, _element.useRef)(callback);
50
- (0, _element.useEffect)(() => {
45
+ const currentCallbackRef = (0, import_element.useRef)(callback);
46
+ (0, import_element.useEffect)(() => {
51
47
  currentCallbackRef.current = callback;
52
48
  }, [callback]);
53
- (0, _element.useEffect)(() => {
49
+ (0, import_element.useEffect)(() => {
54
50
  if (isDisabled) {
55
51
  return;
56
52
  }
57
- const mousetrap = new _mousetrap.default(target && target.current ? target.current :
58
- // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
59
- // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's
60
- // necessary to maintain the existing behavior.
61
- /** @type {Element} */ /** @type {unknown} */
62
- document);
53
+ const mousetrap = new import_mousetrap.default(
54
+ target && target.current ? target.current : (
55
+ // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
56
+ // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's
57
+ // necessary to maintain the existing behavior.
58
+ /** @type {Element} */
59
+ /** @type {unknown} */
60
+ document
61
+ )
62
+ );
63
63
  const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
64
- shortcutsArray.forEach(shortcut => {
65
- const keys = shortcut.split('+');
66
- // Determines whether a key is a modifier by the length of the string.
67
- // E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that
68
- // the modifiers are Shift and Cmd because they're not a single character.
69
- const modifiers = new Set(keys.filter(value => value.length > 1));
70
- const hasAlt = modifiers.has('alt');
71
- const hasShift = modifiers.has('shift');
72
-
73
- // This should be better moved to the shortcut registration instead.
74
- if ((0, _keycodes.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
75
- throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`);
64
+ shortcutsArray.forEach((shortcut) => {
65
+ const keys = shortcut.split("+");
66
+ const modifiers = new Set(
67
+ keys.filter((value) => value.length > 1)
68
+ );
69
+ const hasAlt = modifiers.has("alt");
70
+ const hasShift = modifiers.has("shift");
71
+ if ((0, import_keycodes.isAppleOS)() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
72
+ throw new Error(
73
+ `Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`
74
+ );
76
75
  }
77
- const bindFn = bindGlobal ? 'bindGlobal' : 'bind';
78
- // @ts-ignore `bindGlobal` is an undocumented property
79
- mousetrap[bindFn](shortcut, (/* eslint-disable jsdoc/valid-types */
80
- /** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */...args) => /* eslint-enable jsdoc/valid-types */
81
- currentCallbackRef.current(...args), eventName);
76
+ const bindFn = bindGlobal ? "bindGlobal" : "bind";
77
+ mousetrap[bindFn](
78
+ shortcut,
79
+ (...args) => (
80
+ /* eslint-enable jsdoc/valid-types */
81
+ currentCallbackRef.current(...args)
82
+ ),
83
+ eventName
84
+ );
82
85
  });
83
86
  return () => {
84
87
  mousetrap.reset();
85
88
  };
86
89
  }, [shortcuts, bindGlobal, eventName, target, isDisabled]);
87
90
  }
88
- var _default = exports.default = useKeyboardShortcut;
89
- //# sourceMappingURL=index.js.map
91
+ var use_keyboard_shortcut_default = useKeyboardShortcut;
92
+ //# sourceMappingURL=index.js.map