@wordpress/compose 7.31.1-next.f56bd8138.0 → 7.32.1-next.47f435fc9.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 (236) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/higher-order/compose.js +25 -20
  3. package/build/higher-order/compose.js.map +7 -1
  4. package/build/higher-order/if-condition/index.js +35 -41
  5. package/build/higher-order/if-condition/index.js.map +7 -1
  6. package/build/higher-order/pipe.js +32 -66
  7. package/build/higher-order/pipe.js.map +7 -1
  8. package/build/higher-order/pure/index.js +44 -37
  9. package/build/higher-order/pure/index.js.map +7 -1
  10. package/build/higher-order/with-global-events/index.js +64 -73
  11. package/build/higher-order/with-global-events/index.js.map +7 -1
  12. package/build/higher-order/with-global-events/listener.js +34 -21
  13. package/build/higher-order/with-global-events/listener.js.map +7 -1
  14. package/build/higher-order/with-instance-id/index.js +45 -27
  15. package/build/higher-order/with-instance-id/index.js.map +7 -1
  16. package/build/higher-order/with-safe-timeout/index.js +70 -66
  17. package/build/higher-order/with-safe-timeout/index.js.map +7 -1
  18. package/build/higher-order/with-state/index.js +52 -40
  19. package/build/higher-order/with-state/index.js.map +7 -1
  20. package/build/hooks/use-async-list/index.js +38 -42
  21. package/build/hooks/use-async-list/index.js.map +7 -1
  22. package/build/hooks/use-constrained-tabbing/index.js +54 -75
  23. package/build/hooks/use-constrained-tabbing/index.js.map +7 -1
  24. package/build/hooks/use-copy-on-click/index.js +46 -56
  25. package/build/hooks/use-copy-on-click/index.js.map +7 -1
  26. package/build/hooks/use-copy-to-clipboard/index.js +41 -51
  27. package/build/hooks/use-copy-to-clipboard/index.js.map +7 -1
  28. package/build/hooks/use-debounce/index.js +30 -37
  29. package/build/hooks/use-debounce/index.js.map +7 -1
  30. package/build/hooks/use-debounced-input/index.js +39 -27
  31. package/build/hooks/use-debounced-input/index.js.map +7 -1
  32. package/build/hooks/use-dialog/index.js +63 -55
  33. package/build/hooks/use-dialog/index.js.map +7 -1
  34. package/build/hooks/use-disabled/index.js +74 -82
  35. package/build/hooks/use-disabled/index.js.map +7 -1
  36. package/build/hooks/use-dragging/index.js +51 -48
  37. package/build/hooks/use-dragging/index.js.map +7 -1
  38. package/build/hooks/use-drop-zone/index.js +133 -168
  39. package/build/hooks/use-drop-zone/index.js.map +7 -1
  40. package/build/hooks/use-event/index.js +33 -45
  41. package/build/hooks/use-event/index.js.map +7 -1
  42. package/build/hooks/use-fixed-window-list/index.js +109 -97
  43. package/build/hooks/use-fixed-window-list/index.js.map +7 -1
  44. package/build/hooks/use-focus-on-mount/index.js +44 -57
  45. package/build/hooks/use-focus-on-mount/index.js.map +7 -1
  46. package/build/hooks/use-focus-outside/index.js +44 -102
  47. package/build/hooks/use-focus-outside/index.js.map +7 -1
  48. package/build/hooks/use-focus-return/index.js +35 -56
  49. package/build/hooks/use-focus-return/index.js.map +7 -1
  50. package/build/hooks/use-focusable-iframe/index.js +38 -35
  51. package/build/hooks/use-focusable-iframe/index.js.map +7 -1
  52. package/build/hooks/use-instance-id/index.js +26 -42
  53. package/build/hooks/use-instance-id/index.js.map +7 -1
  54. package/build/hooks/use-isomorphic-layout-effect/index.js +25 -17
  55. package/build/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  56. package/build/hooks/use-keyboard-shortcut/index.js +72 -69
  57. package/build/hooks/use-keyboard-shortcut/index.js.map +7 -1
  58. package/build/hooks/use-media-query/index.js +39 -35
  59. package/build/hooks/use-media-query/index.js.map +7 -1
  60. package/build/hooks/use-merge-refs/index.js +34 -102
  61. package/build/hooks/use-merge-refs/index.js.map +7 -1
  62. package/build/hooks/use-observable-value/index.js +31 -28
  63. package/build/hooks/use-observable-value/index.js.map +7 -1
  64. package/build/hooks/use-preferred-color-scheme/index.android.js +31 -23
  65. package/build/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  66. package/build/hooks/use-preferred-color-scheme/index.ios.js +25 -17
  67. package/build/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  68. package/build/hooks/use-previous/index.js +26 -25
  69. package/build/hooks/use-previous/index.js.map +7 -1
  70. package/build/hooks/use-reduced-motion/index.js +35 -18
  71. package/build/hooks/use-reduced-motion/index.js.map +7 -1
  72. package/build/hooks/use-ref-effect/index.js +25 -35
  73. package/build/hooks/use-ref-effect/index.js.map +7 -1
  74. package/build/hooks/use-resize-observer/index.js +35 -67
  75. package/build/hooks/use-resize-observer/index.js.map +7 -1
  76. package/build/hooks/use-resize-observer/legacy/index.js +47 -103
  77. package/build/hooks/use-resize-observer/legacy/index.js.map +7 -1
  78. package/build/hooks/use-resize-observer/use-resize-observer.js +44 -36
  79. package/build/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  80. package/build/hooks/use-state-with-history/index.js +68 -63
  81. package/build/hooks/use-state-with-history/index.js.map +7 -1
  82. package/build/hooks/use-throttle/index.js +30 -37
  83. package/build/hooks/use-throttle/index.js.map +7 -1
  84. package/build/hooks/use-viewport-match/index.js +51 -70
  85. package/build/hooks/use-viewport-match/index.js.map +7 -1
  86. package/build/hooks/use-warn-on-change/index.js +50 -40
  87. package/build/hooks/use-warn-on-change/index.js.map +7 -1
  88. package/build/index.js +156 -358
  89. package/build/index.js.map +7 -1
  90. package/build/utils/create-higher-order-component/index.js +30 -34
  91. package/build/utils/create-higher-order-component/index.js.map +7 -1
  92. package/build/utils/debounce/index.js +38 -99
  93. package/build/utils/debounce/index.js.map +7 -1
  94. package/build/utils/observable-map/index.js +29 -19
  95. package/build/utils/observable-map/index.js.map +7 -1
  96. package/build/utils/throttle/index.js +30 -81
  97. package/build/utils/throttle/index.js.map +7 -1
  98. package/build-module/higher-order/compose.js +6 -15
  99. package/build-module/higher-order/compose.js.map +7 -1
  100. package/build-module/higher-order/if-condition/index.js +16 -37
  101. package/build-module/higher-order/if-condition/index.js.map +7 -1
  102. package/build-module/higher-order/pipe.js +10 -62
  103. package/build-module/higher-order/pipe.js.map +7 -1
  104. package/build-module/higher-order/pure/index.js +12 -29
  105. package/build-module/higher-order/pure/index.js.map +7 -1
  106. package/build-module/higher-order/with-global-events/index.js +34 -67
  107. package/build-module/higher-order/with-global-events/index.js.map +7 -1
  108. package/build-module/higher-order/with-global-events/listener.js +16 -17
  109. package/build-module/higher-order/with-global-events/listener.js.map +7 -1
  110. package/build-module/higher-order/with-instance-id/index.js +17 -22
  111. package/build-module/higher-order/with-instance-id/index.js.map +7 -1
  112. package/build-module/higher-order/with-safe-timeout/index.js +52 -62
  113. package/build-module/higher-order/with-safe-timeout/index.js.map +7 -1
  114. package/build-module/higher-order/with-state/index.js +23 -35
  115. package/build-module/higher-order/with-state/index.js.map +7 -1
  116. package/build-module/hooks/use-async-list/index.js +16 -33
  117. package/build-module/hooks/use-async-list/index.js.map +7 -1
  118. package/build-module/hooks/use-constrained-tabbing/index.js +26 -70
  119. package/build-module/hooks/use-constrained-tabbing/index.js.map +7 -1
  120. package/build-module/hooks/use-copy-on-click/index.js +14 -47
  121. package/build-module/hooks/use-copy-on-click/index.js.map +7 -1
  122. package/build-module/hooks/use-copy-to-clipboard/index.js +11 -44
  123. package/build-module/hooks/use-copy-to-clipboard/index.js.map +7 -1
  124. package/build-module/hooks/use-debounce/index.js +12 -33
  125. package/build-module/hooks/use-debounce/index.js.map +7 -1
  126. package/build-module/hooks/use-debounced-input/index.js +7 -18
  127. package/build-module/hooks/use-debounced-input/index.js.map +7 -1
  128. package/build-module/hooks/use-dialog/index.js +29 -43
  129. package/build-module/hooks/use-dialog/index.js.map +7 -1
  130. package/build-module/hooks/use-disabled/index.js +47 -78
  131. package/build-module/hooks/use-disabled/index.js.map +7 -1
  132. package/build-module/hooks/use-dragging/index.js +19 -39
  133. package/build-module/hooks/use-dragging/index.js.map +7 -1
  134. package/build-module/hooks/use-drop-zone/index.js +100 -158
  135. package/build-module/hooks/use-drop-zone/index.js.map +7 -1
  136. package/build-module/hooks/use-event/index.js +13 -39
  137. package/build-module/hooks/use-event/index.js.map +7 -1
  138. package/build-module/hooks/use-fixed-window-list/index.js +86 -87
  139. package/build-module/hooks/use-fixed-window-list/index.js.map +7 -1
  140. package/build-module/hooks/use-focus-on-mount/index.js +12 -48
  141. package/build-module/hooks/use-focus-on-mount/index.js.map +7 -1
  142. package/build-module/hooks/use-focus-outside/index.js +21 -93
  143. package/build-module/hooks/use-focus-outside/index.js.map +7 -1
  144. package/build-module/hooks/use-focus-return/index.js +13 -48
  145. package/build-module/hooks/use-focus-return/index.js.map +7 -1
  146. package/build-module/hooks/use-focusable-iframe/index.js +11 -31
  147. package/build-module/hooks/use-focusable-iframe/index.js.map +7 -1
  148. package/build-module/hooks/use-instance-id/index.js +7 -36
  149. package/build-module/hooks/use-instance-id/index.js.map +7 -1
  150. package/build-module/hooks/use-isomorphic-layout-effect/index.js +7 -13
  151. package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  152. package/build-module/hooks/use-keyboard-shortcut/index.js +40 -60
  153. package/build-module/hooks/use-keyboard-shortcut/index.js.map +7 -1
  154. package/build-module/hooks/use-media-query/index.js +21 -30
  155. package/build-module/hooks/use-media-query/index.js.map +7 -1
  156. package/build-module/hooks/use-merge-refs/index.js +10 -92
  157. package/build-module/hooks/use-merge-refs/index.js.map +7 -1
  158. package/build-module/hooks/use-observable-value/index.js +13 -24
  159. package/build-module/hooks/use-observable-value/index.js.map +7 -1
  160. package/build-module/hooks/use-preferred-color-scheme/index.android.js +15 -18
  161. package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  162. package/build-module/hooks/use-preferred-color-scheme/index.ios.js +6 -12
  163. package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  164. package/build-module/hooks/use-previous/index.js +7 -20
  165. package/build-module/hooks/use-previous/index.js.map +7 -1
  166. package/build-module/hooks/use-reduced-motion/index.js +7 -13
  167. package/build-module/hooks/use-reduced-motion/index.js.map +7 -1
  168. package/build-module/hooks/use-ref-effect/index.js +7 -31
  169. package/build-module/hooks/use-ref-effect/index.js.map +7 -1
  170. package/build-module/hooks/use-resize-observer/index.js +7 -61
  171. package/build-module/hooks/use-resize-observer/index.js.map +7 -1
  172. package/build-module/hooks/use-resize-observer/legacy/index.js +28 -96
  173. package/build-module/hooks/use-resize-observer/legacy/index.js.map +7 -1
  174. package/build-module/hooks/use-resize-observer/use-resize-observer.js +10 -28
  175. package/build-module/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  176. package/build-module/hooks/use-state-with-history/index.js +47 -55
  177. package/build-module/hooks/use-state-with-history/index.js.map +7 -1
  178. package/build-module/hooks/use-throttle/index.js +12 -33
  179. package/build-module/hooks/use-throttle/index.js.map +7 -1
  180. package/build-module/hooks/use-viewport-match/index.js +22 -64
  181. package/build-module/hooks/use-viewport-match/index.js.map +7 -1
  182. package/build-module/hooks/use-warn-on-change/index.js +21 -34
  183. package/build-module/hooks/use-warn-on-change/index.js.map +7 -1
  184. package/build-module/index.js +83 -53
  185. package/build-module/index.js.map +7 -1
  186. package/build-module/utils/create-higher-order-component/index.js +9 -30
  187. package/build-module/utils/create-higher-order-component/index.js.map +7 -1
  188. package/build-module/utils/debounce/index.js +17 -95
  189. package/build-module/utils/debounce/index.js.map +7 -1
  190. package/build-module/utils/observable-map/index.js +8 -16
  191. package/build-module/utils/observable-map/index.js.map +7 -1
  192. package/build-module/utils/throttle/index.js +8 -75
  193. package/build-module/utils/throttle/index.js.map +7 -1
  194. package/package.json +17 -10
  195. package/src/hooks/use-debounce/index.js +1 -1
  196. package/tsconfig.tsbuildinfo +1 -1
  197. package/build/higher-order/with-network-connectivity/index.native.js +0 -27
  198. package/build/higher-order/with-network-connectivity/index.native.js.map +0 -1
  199. package/build/higher-order/with-preferred-color-scheme/index.native.js +0 -37
  200. package/build/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  201. package/build/hooks/use-constrained-tabbing/index.native.js +0 -20
  202. package/build/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  203. package/build/hooks/use-focus-outside/index.native.js +0 -175
  204. package/build/hooks/use-focus-outside/index.native.js.map +0 -1
  205. package/build/hooks/use-keyboard-shortcut/index.native.js +0 -9
  206. package/build/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  207. package/build/hooks/use-network-connectivity/index.native.js +0 -58
  208. package/build/hooks/use-network-connectivity/index.native.js.map +0 -1
  209. package/build/hooks/use-preferred-color-scheme-style/index.native.js +0 -42
  210. package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  211. package/build/hooks/use-resize-observer/index.native.js +0 -14
  212. package/build/hooks/use-resize-observer/index.native.js.map +0 -1
  213. package/build/hooks/use-resize-observer/legacy/index.native.js +0 -62
  214. package/build/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  215. package/build/index.native.js +0 -297
  216. package/build/index.native.js.map +0 -1
  217. package/build-module/higher-order/with-network-connectivity/index.native.js +0 -19
  218. package/build-module/higher-order/with-network-connectivity/index.native.js.map +0 -1
  219. package/build-module/higher-order/with-preferred-color-scheme/index.native.js +0 -29
  220. package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  221. package/build-module/hooks/use-constrained-tabbing/index.native.js +0 -13
  222. package/build-module/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  223. package/build-module/hooks/use-focus-outside/index.native.js +0 -169
  224. package/build-module/hooks/use-focus-outside/index.native.js.map +0 -1
  225. package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -3
  226. package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  227. package/build-module/hooks/use-network-connectivity/index.native.js +0 -52
  228. package/build-module/hooks/use-network-connectivity/index.native.js.map +0 -1
  229. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +0 -35
  230. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  231. package/build-module/hooks/use-resize-observer/index.native.js +0 -2
  232. package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
  233. package/build-module/hooks/use-resize-observer/legacy/index.native.js +0 -56
  234. package/build-module/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  235. package/build-module/index.native.js +0 -45
  236. package/build-module/index.native.js.map +0 -1
@@ -1,13 +1,7 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useEffect, useLayoutEffect } from '@wordpress/element';
5
-
6
- /**
7
- * Preferred over direct usage of `useLayoutEffect` when supporting
8
- * server rendered components (SSR) because currently React
9
- * throws a warning when using useLayoutEffect in that environment.
10
- */
11
- const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
12
- export default useIsomorphicLayoutEffect;
13
- //# sourceMappingURL=index.js.map
1
+ import { useEffect, useLayoutEffect } from "@wordpress/element";
2
+ const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
3
+ var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
4
+ export {
5
+ use_isomorphic_layout_effect_default as default
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useEffect","useLayoutEffect","useIsomorphicLayoutEffect","window"],"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":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,eAAe,QAAQ,oBAAoB;;AAE/D;AACA;AACA;AACA;AACA;AACA,MAAMC,yBAAyB,GAC9B,OAAOC,MAAM,KAAK,WAAW,GAAGF,eAAe,GAAGD,SAAS;AAE5D,eAAeE,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": "AAGA,SAAS,WAAW,uBAAuB;AAO3C,MAAM,4BACL,OAAO,WAAW,cAAc,kBAAkB;AAEnD,IAAO,uCAAQ;",
6
+ "names": []
7
+ }
@@ -1,40 +1,10 @@
1
- /**
2
- * External dependencies
3
- */
4
- import Mousetrap from 'mousetrap';
5
- import 'mousetrap/plugins/global-bind/mousetrap-global-bind';
6
-
7
- /**
8
- * WordPress dependencies
9
- */
10
- import { useEffect, useRef } from '@wordpress/element';
11
- import { isAppleOS } from '@wordpress/keycodes';
12
-
13
- /**
14
- * A block selection object.
15
- *
16
- * @typedef {Object} WPKeyboardShortcutConfig
17
- *
18
- * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.
19
- * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.
20
- * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.
21
- * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.
22
- */
23
-
24
- /* eslint-disable jsdoc/valid-types */
25
- /**
26
- * Attach a keyboard shortcut handler.
27
- *
28
- * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.
29
- *
30
- * @param {string[]|string} shortcuts Keyboard Shortcuts.
31
- * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.
32
- * @param {WPKeyboardShortcutConfig} options Shortcut options.
33
- */
34
- function useKeyboardShortcut(/* eslint-enable jsdoc/valid-types */
35
- shortcuts, callback, {
1
+ import Mousetrap from "mousetrap";
2
+ import "mousetrap/plugins/global-bind/mousetrap-global-bind";
3
+ import { useEffect, useRef } from "@wordpress/element";
4
+ import { isAppleOS } from "@wordpress/keycodes";
5
+ function useKeyboardShortcut(shortcuts, callback, {
36
6
  bindGlobal = false,
37
- eventName = 'keydown',
7
+ eventName = "keydown",
38
8
  isDisabled = false,
39
9
  // This is important for performance considerations.
40
10
  target
@@ -47,36 +17,46 @@ shortcuts, callback, {
47
17
  if (isDisabled) {
48
18
  return;
49
19
  }
50
- const mousetrap = new Mousetrap(target && target.current ? target.current :
51
- // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
52
- // 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
53
- // necessary to maintain the existing behavior.
54
- /** @type {Element} */ /** @type {unknown} */
55
- document);
20
+ const mousetrap = new Mousetrap(
21
+ target && target.current ? target.current : (
22
+ // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
23
+ // 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
24
+ // necessary to maintain the existing behavior.
25
+ /** @type {Element} */
26
+ /** @type {unknown} */
27
+ document
28
+ )
29
+ );
56
30
  const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
57
- shortcutsArray.forEach(shortcut => {
58
- const keys = shortcut.split('+');
59
- // Determines whether a key is a modifier by the length of the string.
60
- // E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that
61
- // the modifiers are Shift and Cmd because they're not a single character.
62
- const modifiers = new Set(keys.filter(value => value.length > 1));
63
- const hasAlt = modifiers.has('alt');
64
- const hasShift = modifiers.has('shift');
65
-
66
- // This should be better moved to the shortcut registration instead.
31
+ shortcutsArray.forEach((shortcut) => {
32
+ const keys = shortcut.split("+");
33
+ const modifiers = new Set(
34
+ keys.filter((value) => value.length > 1)
35
+ );
36
+ const hasAlt = modifiers.has("alt");
37
+ const hasShift = modifiers.has("shift");
67
38
  if (isAppleOS() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
68
- throw new Error(`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`);
39
+ throw new Error(
40
+ `Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`
41
+ );
69
42
  }
70
- const bindFn = bindGlobal ? 'bindGlobal' : 'bind';
71
- // @ts-ignore `bindGlobal` is an undocumented property
72
- mousetrap[bindFn](shortcut, (/* eslint-disable jsdoc/valid-types */
73
- /** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */...args) => /* eslint-enable jsdoc/valid-types */
74
- currentCallbackRef.current(...args), eventName);
43
+ const bindFn = bindGlobal ? "bindGlobal" : "bind";
44
+ mousetrap[bindFn](
45
+ shortcut,
46
+ (...args) => (
47
+ /* eslint-enable jsdoc/valid-types */
48
+ currentCallbackRef.current(...args)
49
+ ),
50
+ eventName
51
+ );
75
52
  });
76
53
  return () => {
77
54
  mousetrap.reset();
78
55
  };
79
56
  }, [shortcuts, bindGlobal, eventName, target, isDisabled]);
80
57
  }
81
- export default useKeyboardShortcut;
82
- //# sourceMappingURL=index.js.map
58
+ var use_keyboard_shortcut_default = useKeyboardShortcut;
59
+ export {
60
+ use_keyboard_shortcut_default as default
61
+ };
62
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["Mousetrap","useEffect","useRef","isAppleOS","useKeyboardShortcut","shortcuts","callback","bindGlobal","eventName","isDisabled","target","currentCallbackRef","current","mousetrap","document","shortcutsArray","Array","isArray","forEach","shortcut","keys","split","modifiers","Set","filter","value","length","hasAlt","has","hasShift","size","Error","bindFn","args","reset"],"sources":["@wordpress/compose/src/hooks/use-keyboard-shortcut/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport Mousetrap from 'mousetrap';\nimport 'mousetrap/plugins/global-bind/mousetrap-global-bind';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * A block selection object.\n *\n * @typedef {Object} WPKeyboardShortcutConfig\n *\n * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.\n * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.\n * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.\n * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Attach a keyboard shortcut handler.\n *\n * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.\n *\n * @param {string[]|string} shortcuts Keyboard Shortcuts.\n * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.\n * @param {WPKeyboardShortcutConfig} options Shortcut options.\n */\nfunction useKeyboardShortcut(\n\t/* eslint-enable jsdoc/valid-types */\n\tshortcuts,\n\tcallback,\n\t{\n\t\tbindGlobal = false,\n\t\teventName = 'keydown',\n\t\tisDisabled = false, // This is important for performance considerations.\n\t\ttarget,\n\t} = {}\n) {\n\tconst currentCallbackRef = useRef( callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = callback;\n\t}, [ callback ] );\n\n\tuseEffect( () => {\n\t\tif ( isDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst mousetrap = new Mousetrap(\n\t\t\ttarget && target.current\n\t\t\t\t? target.current\n\t\t\t\t: // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.\n\t\t\t\t // 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\n\t\t\t\t // necessary to maintain the existing behavior.\n\t\t\t\t /** @type {Element} */ ( /** @type {unknown} */ ( document ) )\n\t\t);\n\t\tconst shortcutsArray = Array.isArray( shortcuts )\n\t\t\t? shortcuts\n\t\t\t: [ shortcuts ];\n\t\tshortcutsArray.forEach( ( shortcut ) => {\n\t\t\tconst keys = shortcut.split( '+' );\n\t\t\t// Determines whether a key is a modifier by the length of the string.\n\t\t\t// E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that\n\t\t\t// the modifiers are Shift and Cmd because they're not a single character.\n\t\t\tconst modifiers = new Set(\n\t\t\t\tkeys.filter( ( value ) => value.length > 1 )\n\t\t\t);\n\t\t\tconst hasAlt = modifiers.has( 'alt' );\n\t\t\tconst hasShift = modifiers.has( 'shift' );\n\n\t\t\t// This should be better moved to the shortcut registration instead.\n\t\t\tif (\n\t\t\t\tisAppleOS() &&\n\t\t\t\t( ( modifiers.size === 1 && hasAlt ) ||\n\t\t\t\t\t( modifiers.size === 2 && hasAlt && hasShift ) )\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot bind ${ shortcut }. Alt and Shift+Alt modifiers are reserved for character input.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst bindFn = bindGlobal ? 'bindGlobal' : 'bind';\n\t\t\t// @ts-ignore `bindGlobal` is an undocumented property\n\t\t\tmousetrap[ bindFn ](\n\t\t\t\tshortcut,\n\t\t\t\t(\n\t\t\t\t\t/* eslint-disable jsdoc/valid-types */\n\t\t\t\t\t/** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */ ...args\n\t\t\t\t) =>\n\t\t\t\t\t/* eslint-enable jsdoc/valid-types */\n\t\t\t\t\tcurrentCallbackRef.current( ...args ),\n\t\t\t\teventName\n\t\t\t);\n\t\t} );\n\n\t\treturn () => {\n\t\t\tmousetrap.reset();\n\t\t};\n\t}, [ shortcuts, bindGlobal, eventName, target, isDisabled ] );\n}\n\nexport default useKeyboardShortcut;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;AACjC,OAAO,qDAAqD;;AAE5D;AACA;AACA;AACA,SAASC,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;AACtD,SAASC,SAAS,QAAQ,qBAAqB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,mBAAmBA,CAC3B;AACAC,SAAS,EACTC,QAAQ,EACR;EACCC,UAAU,GAAG,KAAK;EAClBC,SAAS,GAAG,SAAS;EACrBC,UAAU,GAAG,KAAK;EAAE;EACpBC;AACD,CAAC,GAAG,CAAC,CAAC,EACL;EACD,MAAMC,kBAAkB,GAAGT,MAAM,CAAEI,QAAS,CAAC;EAC7CL,SAAS,CAAE,MAAM;IAChBU,kBAAkB,CAACC,OAAO,GAAGN,QAAQ;EACtC,CAAC,EAAE,CAAEA,QAAQ,CAAG,CAAC;EAEjBL,SAAS,CAAE,MAAM;IAChB,IAAKQ,UAAU,EAAG;MACjB;IACD;IACA,MAAMI,SAAS,GAAG,IAAIb,SAAS,CAC9BU,MAAM,IAAIA,MAAM,CAACE,OAAO,GACrBF,MAAM,CAACE,OAAO;IACd;IACA;IACA;IACA,uBAAyB;IAAyBE,QACtD,CAAC;IACD,MAAMC,cAAc,GAAGC,KAAK,CAACC,OAAO,CAAEZ,SAAU,CAAC,GAC9CA,SAAS,GACT,CAAEA,SAAS,CAAE;IAChBU,cAAc,CAACG,OAAO,CAAIC,QAAQ,IAAM;MACvC,MAAMC,IAAI,GAAGD,QAAQ,CAACE,KAAK,CAAE,GAAI,CAAC;MAClC;MACA;MACA;MACA,MAAMC,SAAS,GAAG,IAAIC,GAAG,CACxBH,IAAI,CAACI,MAAM,CAAIC,KAAK,IAAMA,KAAK,CAACC,MAAM,GAAG,CAAE,CAC5C,CAAC;MACD,MAAMC,MAAM,GAAGL,SAAS,CAACM,GAAG,CAAE,KAAM,CAAC;MACrC,MAAMC,QAAQ,GAAGP,SAAS,CAACM,GAAG,CAAE,OAAQ,CAAC;;MAEzC;MACA,IACCzB,SAAS,CAAC,CAAC,KACPmB,SAAS,CAACQ,IAAI,KAAK,CAAC,IAAIH,MAAM,IAC/BL,SAAS,CAACQ,IAAI,KAAK,CAAC,IAAIH,MAAM,IAAIE,QAAU,CAAE,EAChD;QACD,MAAM,IAAIE,KAAK,CACd,eAAgBZ,QAAQ,iEACzB,CAAC;MACF;MAEA,MAAMa,MAAM,GAAGzB,UAAU,GAAG,YAAY,GAAG,MAAM;MACjD;MACAM,SAAS,CAAEmB,MAAM,CAAE,CAClBb,QAAQ,EACR,CACC;MACA,4EAA6E,GAAGc,IAAI,KAEpF;MACAtB,kBAAkB,CAACC,OAAO,CAAE,GAAGqB,IAAK,CAAC,EACtCzB,SACD,CAAC;IACF,CAAE,CAAC;IAEH,OAAO,MAAM;MACZK,SAAS,CAACqB,KAAK,CAAC,CAAC;IAClB,CAAC;EACF,CAAC,EAAE,CAAE7B,SAAS,EAAEE,UAAU,EAAEC,SAAS,EAAEE,MAAM,EAAED,UAAU,CAAG,CAAC;AAC9D;AAEA,eAAeL,mBAAmB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-keyboard-shortcut/index.js"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport Mousetrap from 'mousetrap';\nimport 'mousetrap/plugins/global-bind/mousetrap-global-bind';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * A block selection object.\n *\n * @typedef {Object} WPKeyboardShortcutConfig\n *\n * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.\n * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.\n * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.\n * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.\n */\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * Attach a keyboard shortcut handler.\n *\n * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.\n *\n * @param {string[]|string} shortcuts Keyboard Shortcuts.\n * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.\n * @param {WPKeyboardShortcutConfig} options Shortcut options.\n */\nfunction useKeyboardShortcut(\n\t/* eslint-enable jsdoc/valid-types */\n\tshortcuts,\n\tcallback,\n\t{\n\t\tbindGlobal = false,\n\t\teventName = 'keydown',\n\t\tisDisabled = false, // This is important for performance considerations.\n\t\ttarget,\n\t} = {}\n) {\n\tconst currentCallbackRef = useRef( callback );\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = callback;\n\t}, [ callback ] );\n\n\tuseEffect( () => {\n\t\tif ( isDisabled ) {\n\t\t\treturn;\n\t\t}\n\t\tconst mousetrap = new Mousetrap(\n\t\t\ttarget && target.current\n\t\t\t\t? target.current\n\t\t\t\t: // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.\n\t\t\t\t // 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\n\t\t\t\t // necessary to maintain the existing behavior.\n\t\t\t\t /** @type {Element} */ ( /** @type {unknown} */ ( document ) )\n\t\t);\n\t\tconst shortcutsArray = Array.isArray( shortcuts )\n\t\t\t? shortcuts\n\t\t\t: [ shortcuts ];\n\t\tshortcutsArray.forEach( ( shortcut ) => {\n\t\t\tconst keys = shortcut.split( '+' );\n\t\t\t// Determines whether a key is a modifier by the length of the string.\n\t\t\t// E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that\n\t\t\t// the modifiers are Shift and Cmd because they're not a single character.\n\t\t\tconst modifiers = new Set(\n\t\t\t\tkeys.filter( ( value ) => value.length > 1 )\n\t\t\t);\n\t\t\tconst hasAlt = modifiers.has( 'alt' );\n\t\t\tconst hasShift = modifiers.has( 'shift' );\n\n\t\t\t// This should be better moved to the shortcut registration instead.\n\t\t\tif (\n\t\t\t\tisAppleOS() &&\n\t\t\t\t( ( modifiers.size === 1 && hasAlt ) ||\n\t\t\t\t\t( modifiers.size === 2 && hasAlt && hasShift ) )\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot bind ${ shortcut }. Alt and Shift+Alt modifiers are reserved for character input.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst bindFn = bindGlobal ? 'bindGlobal' : 'bind';\n\t\t\t// @ts-ignore `bindGlobal` is an undocumented property\n\t\t\tmousetrap[ bindFn ](\n\t\t\t\tshortcut,\n\t\t\t\t(\n\t\t\t\t\t/* eslint-disable jsdoc/valid-types */\n\t\t\t\t\t/** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */ ...args\n\t\t\t\t) =>\n\t\t\t\t\t/* eslint-enable jsdoc/valid-types */\n\t\t\t\t\tcurrentCallbackRef.current( ...args ),\n\t\t\t\teventName\n\t\t\t);\n\t\t} );\n\n\t\treturn () => {\n\t\t\tmousetrap.reset();\n\t\t};\n\t}, [ shortcuts, bindGlobal, eventName, target, isDisabled ] );\n}\n\nexport default useKeyboardShortcut;\n"],
5
+ "mappings": "AAGA,OAAO,eAAe;AACtB,OAAO;AAKP,SAAS,WAAW,cAAc;AAClC,SAAS,iBAAiB;AAuB1B,SAAS,oBAER,WACA,UACA;AAAA,EACC,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA;AAAA,EACb;AACD,IAAI,CAAC,GACJ;AACD,QAAM,qBAAqB,OAAQ,QAAS;AAC5C,YAAW,MAAM;AAChB,uBAAmB,UAAU;AAAA,EAC9B,GAAG,CAAE,QAAS,CAAE;AAEhB,YAAW,MAAM;AAChB,QAAK,YAAa;AACjB;AAAA,IACD;AACA,UAAM,YAAY,IAAI;AAAA,MACrB,UAAU,OAAO,UACd,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAI2C;AAAA;AAAA,IACtD;AACA,UAAM,iBAAiB,MAAM,QAAS,SAAU,IAC7C,YACA,CAAE,SAAU;AACf,mBAAe,QAAS,CAAE,aAAc;AACvC,YAAM,OAAO,SAAS,MAAO,GAAI;AAIjC,YAAM,YAAY,IAAI;AAAA,QACrB,KAAK,OAAQ,CAAE,UAAW,MAAM,SAAS,CAAE;AAAA,MAC5C;AACA,YAAM,SAAS,UAAU,IAAK,KAAM;AACpC,YAAM,WAAW,UAAU,IAAK,OAAQ;AAGxC,UACC,UAAU,MACN,UAAU,SAAS,KAAK,UACzB,UAAU,SAAS,KAAK,UAAU,WACpC;AACD,cAAM,IAAI;AAAA,UACT,eAAgB,QAAS;AAAA,QAC1B;AAAA,MACD;AAEA,YAAM,SAAS,aAAa,eAAe;AAE3C,gBAAW,MAAO;AAAA,QACjB;AAAA,QACA,IAEiF;AAAA;AAAA,UAGhF,mBAAmB,QAAS,GAAG,IAAK;AAAA;AAAA,QACrC;AAAA,MACD;AAAA,IACD,CAAE;AAEF,WAAO,MAAM;AACZ,gBAAU,MAAM;AAAA,IACjB;AAAA,EACD,GAAG,CAAE,WAAW,YAAY,WAAW,QAAQ,UAAW,CAAE;AAC7D;AAEA,IAAO,gCAAQ;",
6
+ "names": []
7
+ }
@@ -1,15 +1,5 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useMemo, useSyncExternalStore } from '@wordpress/element';
5
- const matchMediaCache = new Map();
6
-
7
- /**
8
- * A new MediaQueryList object for the media query
9
- *
10
- * @param {string} [query] Media Query.
11
- * @return {MediaQueryList|null} A new object for the media query
12
- */
1
+ import { useMemo, useSyncExternalStore } from "@wordpress/element";
2
+ const matchMediaCache = /* @__PURE__ */ new Map();
13
3
  function getMediaQueryList(query) {
14
4
  if (!query) {
15
5
  return null;
@@ -18,42 +8,43 @@ function getMediaQueryList(query) {
18
8
  if (match) {
19
9
  return match;
20
10
  }
21
- if (typeof window !== 'undefined' && typeof window.matchMedia === 'function') {
11
+ if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
22
12
  match = window.matchMedia(query);
23
13
  matchMediaCache.set(query, match);
24
14
  return match;
25
15
  }
26
16
  return null;
27
17
  }
28
-
29
- /**
30
- * Runs a media query and returns its value when it changes.
31
- *
32
- * @param {string} [query] Media Query.
33
- * @return {boolean} return value of the media query.
34
- */
35
- export default function useMediaQuery(query) {
18
+ function useMediaQuery(query) {
36
19
  const source = useMemo(() => {
37
20
  const mediaQueryList = getMediaQueryList(query);
38
21
  return {
39
22
  /** @type {(onStoreChange: () => void) => () => void} */
40
23
  subscribe(onStoreChange) {
41
24
  if (!mediaQueryList) {
42
- return () => {};
25
+ return () => {
26
+ };
43
27
  }
44
-
45
- // Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.
46
- mediaQueryList.addEventListener?.('change', onStoreChange);
28
+ mediaQueryList.addEventListener?.("change", onStoreChange);
47
29
  return () => {
48
- mediaQueryList.removeEventListener?.('change', onStoreChange);
30
+ mediaQueryList.removeEventListener?.(
31
+ "change",
32
+ onStoreChange
33
+ );
49
34
  };
50
35
  },
51
36
  getValue() {
52
- var _mediaQueryList$match;
53
- return (_mediaQueryList$match = mediaQueryList?.matches) !== null && _mediaQueryList$match !== void 0 ? _mediaQueryList$match : false;
37
+ return mediaQueryList?.matches ?? false;
54
38
  }
55
39
  };
56
40
  }, [query]);
57
- return useSyncExternalStore(source.subscribe, source.getValue, () => false);
41
+ return useSyncExternalStore(
42
+ source.subscribe,
43
+ source.getValue,
44
+ () => false
45
+ );
58
46
  }
59
- //# sourceMappingURL=index.js.map
47
+ export {
48
+ useMediaQuery as default
49
+ };
50
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useMemo","useSyncExternalStore","matchMediaCache","Map","getMediaQueryList","query","match","get","window","matchMedia","set","useMediaQuery","source","mediaQueryList","subscribe","onStoreChange","addEventListener","removeEventListener","getValue","_mediaQueryList$match","matches"],"sources":["@wordpress/compose/src/hooks/use-media-query/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\nconst matchMediaCache = new Map();\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif ( ! query ) {\n\t\treturn null;\n\t}\n\n\tlet match = matchMediaCache.get( query );\n\n\tif ( match ) {\n\t\treturn match;\n\t}\n\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\tmatch = window.matchMedia( query );\n\t\tmatchMediaCache.set( query, match );\n\t\treturn match;\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,oBAAoB,QAAQ,oBAAoB;AAElE,MAAMC,eAAe,GAAG,IAAIC,GAAG,CAAC,CAAC;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,iBAAiBA,CAAEC,KAAK,EAAG;EACnC,IAAK,CAAEA,KAAK,EAAG;IACd,OAAO,IAAI;EACZ;EAEA,IAAIC,KAAK,GAAGJ,eAAe,CAACK,GAAG,CAAEF,KAAM,CAAC;EAExC,IAAKC,KAAK,EAAG;IACZ,OAAOA,KAAK;EACb;EAEA,IACC,OAAOE,MAAM,KAAK,WAAW,IAC7B,OAAOA,MAAM,CAACC,UAAU,KAAK,UAAU,EACtC;IACDH,KAAK,GAAGE,MAAM,CAACC,UAAU,CAAEJ,KAAM,CAAC;IAClCH,eAAe,CAACQ,GAAG,CAAEL,KAAK,EAAEC,KAAM,CAAC;IACnC,OAAOA,KAAK;EACb;EAEA,OAAO,IAAI;AACZ;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASK,aAAaA,CAAEN,KAAK,EAAG;EAC9C,MAAMO,MAAM,GAAGZ,OAAO,CAAE,MAAM;IAC7B,MAAMa,cAAc,GAAGT,iBAAiB,CAAEC,KAAM,CAAC;IAEjD,OAAO;MACN;MACAS,SAASA,CAAEC,aAAa,EAAG;QAC1B,IAAK,CAAEF,cAAc,EAAG;UACvB,OAAO,MAAM,CAAC,CAAC;QAChB;;QAEA;QACAA,cAAc,CAACG,gBAAgB,GAAI,QAAQ,EAAED,aAAc,CAAC;QAC5D,OAAO,MAAM;UACZF,cAAc,CAACI,mBAAmB,GACjC,QAAQ,EACRF,aACD,CAAC;QACF,CAAC;MACF,CAAC;MACDG,QAAQA,CAAA,EAAG;QAAA,IAAAC,qBAAA;QACV,QAAAA,qBAAA,GAAON,cAAc,EAAEO,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAI,KAAK;MACxC;IACD,CAAC;EACF,CAAC,EAAE,CAAEd,KAAK,CAAG,CAAC;EAEd,OAAOJ,oBAAoB,CAC1BW,MAAM,CAACE,SAAS,EAChBF,MAAM,CAACM,QAAQ,EACf,MAAM,KACP,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-media-query/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\nconst matchMediaCache = new Map();\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif ( ! query ) {\n\t\treturn null;\n\t}\n\n\tlet match = matchMediaCache.get( query );\n\n\tif ( match ) {\n\t\treturn match;\n\t}\n\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\tmatch = window.matchMedia( query );\n\t\tmatchMediaCache.set( query, match );\n\t\treturn match;\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],
5
+ "mappings": "AAGA,SAAS,SAAS,4BAA4B;AAE9C,MAAM,kBAAkB,oBAAI,IAAI;AAQhC,SAAS,kBAAmB,OAAQ;AACnC,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,MAAI,QAAQ,gBAAgB,IAAK,KAAM;AAEvC,MAAK,OAAQ;AACZ,WAAO;AAAA,EACR;AAEA,MACC,OAAO,WAAW,eAClB,OAAO,OAAO,eAAe,YAC5B;AACD,YAAQ,OAAO,WAAY,KAAM;AACjC,oBAAgB,IAAK,OAAO,KAAM;AAClC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAQe,SAAR,cAAgC,OAAQ;AAC9C,QAAM,SAAS,QAAS,MAAM;AAC7B,UAAM,iBAAiB,kBAAmB,KAAM;AAEhD,WAAO;AAAA;AAAA,MAEN,UAAW,eAAgB;AAC1B,YAAK,CAAE,gBAAiB;AACvB,iBAAO,MAAM;AAAA,UAAC;AAAA,QACf;AAGA,uBAAe,mBAAoB,UAAU,aAAc;AAC3D,eAAO,MAAM;AACZ,yBAAe;AAAA,YACd;AAAA,YACA;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,WAAW;AACV,eAAO,gBAAgB,WAAW;AAAA,MACnC;AAAA,IACD;AAAA,EACD,GAAG,CAAE,KAAM,CAAE;AAEb,SAAO;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,MAAM;AAAA,EACP;AACD;",
6
+ "names": []
7
+ }
@@ -1,90 +1,18 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useRef, useCallback, useLayoutEffect } from '@wordpress/element';
5
-
6
- /* eslint-disable jsdoc/valid-types */
7
- /**
8
- * @template T
9
- * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef
10
- */
11
- /* eslint-enable jsdoc/valid-types */
12
-
13
- /**
14
- * @template T
15
- * @param {import('react').Ref<T>} ref
16
- * @param {T} value
17
- */
1
+ import { useRef, useCallback, useLayoutEffect } from "@wordpress/element";
18
2
  function assignRef(ref, value) {
19
- if (typeof ref === 'function') {
3
+ if (typeof ref === "function") {
20
4
  ref(value);
21
- } else if (ref && ref.hasOwnProperty('current')) {
22
- /* eslint-disable jsdoc/no-undefined-types */
23
- /** @type {import('react').MutableRefObject<T>} */ref.current = value;
24
- /* eslint-enable jsdoc/no-undefined-types */
5
+ } else if (ref && ref.hasOwnProperty("current")) {
6
+ ref.current = value;
25
7
  }
26
8
  }
27
-
28
- /**
29
- * Merges refs into one ref callback.
30
- *
31
- * It also ensures that the merged ref callbacks are only called when they
32
- * change (as a result of a `useCallback` dependency update) OR when the ref
33
- * value changes, just as React does when passing a single ref callback to the
34
- * component.
35
- *
36
- * As expected, if you pass a new function on every render, the ref callback
37
- * will be called after every render.
38
- *
39
- * If you don't wish a ref callback to be called after every render, wrap it
40
- * with `useCallback( callback, dependencies )`. When a dependency changes, the
41
- * old ref callback will be called with `null` and the new ref callback will be
42
- * called with the same value.
43
- *
44
- * To make ref callbacks easier to use, you can also pass the result of
45
- * `useRefEffect`, which makes cleanup easier by allowing you to return a
46
- * cleanup function instead of handling `null`.
47
- *
48
- * It's also possible to _disable_ a ref (and its behaviour) by simply not
49
- * passing the ref.
50
- *
51
- * ```jsx
52
- * const ref = useRefEffect( ( node ) => {
53
- * node.addEventListener( ... );
54
- * return () => {
55
- * node.removeEventListener( ... );
56
- * };
57
- * }, [ ...dependencies ] );
58
- * const otherRef = useRef();
59
- * const mergedRefs useMergeRefs( [
60
- * enabled && ref,
61
- * otherRef,
62
- * ] );
63
- * return <div ref={ mergedRefs } />;
64
- * ```
65
- *
66
- * @template {import('react').Ref<any>} TRef
67
- * @param {Array<TRef>} refs The refs to be merged.
68
- *
69
- * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.
70
- */
71
- export default function useMergeRefs(refs) {
9
+ function useMergeRefs(refs) {
72
10
  const element = useRef();
73
11
  const isAttachedRef = useRef(false);
74
12
  const didElementChangeRef = useRef(false);
75
- /* eslint-disable jsdoc/no-undefined-types */
76
- /** @type {import('react').MutableRefObject<TRef[]>} */
77
- /* eslint-enable jsdoc/no-undefined-types */
78
13
  const previousRefsRef = useRef([]);
79
14
  const currentRefsRef = useRef(refs);
80
-
81
- // Update on render before the ref callback is called, so the ref callback
82
- // always has access to the current refs.
83
15
  currentRefsRef.current = refs;
84
-
85
- // If any of the refs change, call the previous ref with `null` and the new
86
- // ref with the node, except when the element changes in the same cycle, in
87
- // which case the ref callbacks will already have been called.
88
16
  useLayoutEffect(() => {
89
17
  if (didElementChangeRef.current === false && isAttachedRef.current === true) {
90
18
  refs.forEach((ref, index) => {
@@ -97,30 +25,20 @@ export default function useMergeRefs(refs) {
97
25
  }
98
26
  previousRefsRef.current = refs;
99
27
  }, refs);
100
-
101
- // No dependencies, must be reset after every render so ref callbacks are
102
- // correctly called after a ref change.
103
28
  useLayoutEffect(() => {
104
29
  didElementChangeRef.current = false;
105
30
  });
106
-
107
- // There should be no dependencies so that `callback` is only called when
108
- // the node changes.
109
- return useCallback(value => {
110
- // Update the element so it can be used when calling ref callbacks on a
111
- // dependency change.
31
+ return useCallback((value) => {
112
32
  assignRef(element, value);
113
33
  didElementChangeRef.current = true;
114
34
  isAttachedRef.current = value !== null;
115
-
116
- // When an element changes, the current ref callback should be called
117
- // with the new element and the previous one with `null`.
118
35
  const refsToAssign = value ? currentRefsRef.current : previousRefsRef.current;
119
-
120
- // Update the latest refs.
121
36
  for (const ref of refsToAssign) {
122
37
  assignRef(ref, value);
123
38
  }
124
39
  }, []);
125
40
  }
126
- //# sourceMappingURL=index.js.map
41
+ export {
42
+ useMergeRefs as default
43
+ };
44
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useRef","useCallback","useLayoutEffect","assignRef","ref","value","hasOwnProperty","current","useMergeRefs","refs","element","isAttachedRef","didElementChangeRef","previousRefsRef","currentRefsRef","forEach","index","previousRef","refsToAssign"],"sources":["@wordpress/compose/src/hooks/use-merge-refs/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useCallback, useLayoutEffect } from '@wordpress/element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef\n */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * @template T\n * @param {import('react').Ref<T>} ref\n * @param {T} value\n */\nfunction assignRef( ref, value ) {\n\tif ( typeof ref === 'function' ) {\n\t\tref( value );\n\t} else if ( ref && ref.hasOwnProperty( 'current' ) ) {\n\t\t/* eslint-disable jsdoc/no-undefined-types */\n\t\t/** @type {import('react').MutableRefObject<T>} */ ( ref ).current =\n\t\t\tvalue;\n\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t}\n}\n\n/**\n * Merges refs into one ref callback.\n *\n * It also ensures that the merged ref callbacks are only called when they\n * change (as a result of a `useCallback` dependency update) OR when the ref\n * value changes, just as React does when passing a single ref callback to the\n * component.\n *\n * As expected, if you pass a new function on every render, the ref callback\n * will be called after every render.\n *\n * If you don't wish a ref callback to be called after every render, wrap it\n * with `useCallback( callback, dependencies )`. When a dependency changes, the\n * old ref callback will be called with `null` and the new ref callback will be\n * called with the same value.\n *\n * To make ref callbacks easier to use, you can also pass the result of\n * `useRefEffect`, which makes cleanup easier by allowing you to return a\n * cleanup function instead of handling `null`.\n *\n * It's also possible to _disable_ a ref (and its behaviour) by simply not\n * passing the ref.\n *\n * ```jsx\n * const ref = useRefEffect( ( node ) => {\n * node.addEventListener( ... );\n * return () => {\n * node.removeEventListener( ... );\n * };\n * }, [ ...dependencies ] );\n * const otherRef = useRef();\n * const mergedRefs useMergeRefs( [\n * enabled && ref,\n * otherRef,\n * ] );\n * return <div ref={ mergedRefs } />;\n * ```\n *\n * @template {import('react').Ref<any>} TRef\n * @param {Array<TRef>} refs The refs to be merged.\n *\n * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.\n */\nexport default function useMergeRefs( refs ) {\n\tconst element = useRef();\n\tconst isAttachedRef = useRef( false );\n\tconst didElementChangeRef = useRef( false );\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<TRef[]>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst previousRefsRef = useRef( [] );\n\tconst currentRefsRef = useRef( refs );\n\n\t// Update on render before the ref callback is called, so the ref callback\n\t// always has access to the current refs.\n\tcurrentRefsRef.current = refs;\n\n\t// If any of the refs change, call the previous ref with `null` and the new\n\t// ref with the node, except when the element changes in the same cycle, in\n\t// which case the ref callbacks will already have been called.\n\tuseLayoutEffect( () => {\n\t\tif (\n\t\t\tdidElementChangeRef.current === false &&\n\t\t\tisAttachedRef.current === true\n\t\t) {\n\t\t\trefs.forEach( ( ref, index ) => {\n\t\t\t\tconst previousRef = previousRefsRef.current[ index ];\n\t\t\t\tif ( ref !== previousRef ) {\n\t\t\t\t\tassignRef( previousRef, null );\n\t\t\t\t\tassignRef( ref, element.current );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tpreviousRefsRef.current = refs;\n\t}, refs );\n\n\t// No dependencies, must be reset after every render so ref callbacks are\n\t// correctly called after a ref change.\n\tuseLayoutEffect( () => {\n\t\tdidElementChangeRef.current = false;\n\t} );\n\n\t// There should be no dependencies so that `callback` is only called when\n\t// the node changes.\n\treturn useCallback( ( value ) => {\n\t\t// Update the element so it can be used when calling ref callbacks on a\n\t\t// dependency change.\n\t\tassignRef( element, value );\n\n\t\tdidElementChangeRef.current = true;\n\t\tisAttachedRef.current = value !== null;\n\n\t\t// When an element changes, the current ref callback should be called\n\t\t// with the new element and the previous one with `null`.\n\t\tconst refsToAssign = value\n\t\t\t? currentRefsRef.current\n\t\t\t: previousRefsRef.current;\n\n\t\t// Update the latest refs.\n\t\tfor ( const ref of refsToAssign ) {\n\t\t\tassignRef( ref, value );\n\t\t}\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,WAAW,EAAEC,eAAe,QAAQ,oBAAoB;;AAEzE;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,GAAG,EAAEC,KAAK,EAAG;EAChC,IAAK,OAAOD,GAAG,KAAK,UAAU,EAAG;IAChCA,GAAG,CAAEC,KAAM,CAAC;EACb,CAAC,MAAM,IAAKD,GAAG,IAAIA,GAAG,CAACE,cAAc,CAAE,SAAU,CAAC,EAAG;IACpD;IACA,kDAAqDF,GAAG,CAAGG,OAAO,GACjEF,KAAK;IACN;EACD;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASG,YAAYA,CAAEC,IAAI,EAAG;EAC5C,MAAMC,OAAO,GAAGV,MAAM,CAAC,CAAC;EACxB,MAAMW,aAAa,GAAGX,MAAM,CAAE,KAAM,CAAC;EACrC,MAAMY,mBAAmB,GAAGZ,MAAM,CAAE,KAAM,CAAC;EAC3C;EACA;EACA;EACA,MAAMa,eAAe,GAAGb,MAAM,CAAE,EAAG,CAAC;EACpC,MAAMc,cAAc,GAAGd,MAAM,CAAES,IAAK,CAAC;;EAErC;EACA;EACAK,cAAc,CAACP,OAAO,GAAGE,IAAI;;EAE7B;EACA;EACA;EACAP,eAAe,CAAE,MAAM;IACtB,IACCU,mBAAmB,CAACL,OAAO,KAAK,KAAK,IACrCI,aAAa,CAACJ,OAAO,KAAK,IAAI,EAC7B;MACDE,IAAI,CAACM,OAAO,CAAE,CAAEX,GAAG,EAAEY,KAAK,KAAM;QAC/B,MAAMC,WAAW,GAAGJ,eAAe,CAACN,OAAO,CAAES,KAAK,CAAE;QACpD,IAAKZ,GAAG,KAAKa,WAAW,EAAG;UAC1Bd,SAAS,CAAEc,WAAW,EAAE,IAAK,CAAC;UAC9Bd,SAAS,CAAEC,GAAG,EAAEM,OAAO,CAACH,OAAQ,CAAC;QAClC;MACD,CAAE,CAAC;IACJ;IAEAM,eAAe,CAACN,OAAO,GAAGE,IAAI;EAC/B,CAAC,EAAEA,IAAK,CAAC;;EAET;EACA;EACAP,eAAe,CAAE,MAAM;IACtBU,mBAAmB,CAACL,OAAO,GAAG,KAAK;EACpC,CAAE,CAAC;;EAEH;EACA;EACA,OAAON,WAAW,CAAII,KAAK,IAAM;IAChC;IACA;IACAF,SAAS,CAAEO,OAAO,EAAEL,KAAM,CAAC;IAE3BO,mBAAmB,CAACL,OAAO,GAAG,IAAI;IAClCI,aAAa,CAACJ,OAAO,GAAGF,KAAK,KAAK,IAAI;;IAEtC;IACA;IACA,MAAMa,YAAY,GAAGb,KAAK,GACvBS,cAAc,CAACP,OAAO,GACtBM,eAAe,CAACN,OAAO;;IAE1B;IACA,KAAM,MAAMH,GAAG,IAAIc,YAAY,EAAG;MACjCf,SAAS,CAAEC,GAAG,EAAEC,KAAM,CAAC;IACxB;EACD,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-merge-refs/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useCallback, useLayoutEffect } from '@wordpress/element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef\n */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * @template T\n * @param {import('react').Ref<T>} ref\n * @param {T} value\n */\nfunction assignRef( ref, value ) {\n\tif ( typeof ref === 'function' ) {\n\t\tref( value );\n\t} else if ( ref && ref.hasOwnProperty( 'current' ) ) {\n\t\t/* eslint-disable jsdoc/no-undefined-types */\n\t\t/** @type {import('react').MutableRefObject<T>} */ ( ref ).current =\n\t\t\tvalue;\n\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t}\n}\n\n/**\n * Merges refs into one ref callback.\n *\n * It also ensures that the merged ref callbacks are only called when they\n * change (as a result of a `useCallback` dependency update) OR when the ref\n * value changes, just as React does when passing a single ref callback to the\n * component.\n *\n * As expected, if you pass a new function on every render, the ref callback\n * will be called after every render.\n *\n * If you don't wish a ref callback to be called after every render, wrap it\n * with `useCallback( callback, dependencies )`. When a dependency changes, the\n * old ref callback will be called with `null` and the new ref callback will be\n * called with the same value.\n *\n * To make ref callbacks easier to use, you can also pass the result of\n * `useRefEffect`, which makes cleanup easier by allowing you to return a\n * cleanup function instead of handling `null`.\n *\n * It's also possible to _disable_ a ref (and its behaviour) by simply not\n * passing the ref.\n *\n * ```jsx\n * const ref = useRefEffect( ( node ) => {\n * node.addEventListener( ... );\n * return () => {\n * node.removeEventListener( ... );\n * };\n * }, [ ...dependencies ] );\n * const otherRef = useRef();\n * const mergedRefs useMergeRefs( [\n * enabled && ref,\n * otherRef,\n * ] );\n * return <div ref={ mergedRefs } />;\n * ```\n *\n * @template {import('react').Ref<any>} TRef\n * @param {Array<TRef>} refs The refs to be merged.\n *\n * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.\n */\nexport default function useMergeRefs( refs ) {\n\tconst element = useRef();\n\tconst isAttachedRef = useRef( false );\n\tconst didElementChangeRef = useRef( false );\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<TRef[]>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst previousRefsRef = useRef( [] );\n\tconst currentRefsRef = useRef( refs );\n\n\t// Update on render before the ref callback is called, so the ref callback\n\t// always has access to the current refs.\n\tcurrentRefsRef.current = refs;\n\n\t// If any of the refs change, call the previous ref with `null` and the new\n\t// ref with the node, except when the element changes in the same cycle, in\n\t// which case the ref callbacks will already have been called.\n\tuseLayoutEffect( () => {\n\t\tif (\n\t\t\tdidElementChangeRef.current === false &&\n\t\t\tisAttachedRef.current === true\n\t\t) {\n\t\t\trefs.forEach( ( ref, index ) => {\n\t\t\t\tconst previousRef = previousRefsRef.current[ index ];\n\t\t\t\tif ( ref !== previousRef ) {\n\t\t\t\t\tassignRef( previousRef, null );\n\t\t\t\t\tassignRef( ref, element.current );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tpreviousRefsRef.current = refs;\n\t}, refs );\n\n\t// No dependencies, must be reset after every render so ref callbacks are\n\t// correctly called after a ref change.\n\tuseLayoutEffect( () => {\n\t\tdidElementChangeRef.current = false;\n\t} );\n\n\t// There should be no dependencies so that `callback` is only called when\n\t// the node changes.\n\treturn useCallback( ( value ) => {\n\t\t// Update the element so it can be used when calling ref callbacks on a\n\t\t// dependency change.\n\t\tassignRef( element, value );\n\n\t\tdidElementChangeRef.current = true;\n\t\tisAttachedRef.current = value !== null;\n\n\t\t// When an element changes, the current ref callback should be called\n\t\t// with the new element and the previous one with `null`.\n\t\tconst refsToAssign = value\n\t\t\t? currentRefsRef.current\n\t\t\t: previousRefsRef.current;\n\n\t\t// Update the latest refs.\n\t\tfor ( const ref of refsToAssign ) {\n\t\t\tassignRef( ref, value );\n\t\t}\n\t}, [] );\n}\n"],
5
+ "mappings": "AAGA,SAAS,QAAQ,aAAa,uBAAuB;AAcrD,SAAS,UAAW,KAAK,OAAQ;AAChC,MAAK,OAAO,QAAQ,YAAa;AAChC,QAAK,KAAM;AAAA,EACZ,WAAY,OAAO,IAAI,eAAgB,SAAU,GAAI;AAED,IAAE,IAAM,UAC1D;AAAA,EAEF;AACD;AA6Ce,SAAR,aAA+B,MAAO;AAC5C,QAAM,UAAU,OAAO;AACvB,QAAM,gBAAgB,OAAQ,KAAM;AACpC,QAAM,sBAAsB,OAAQ,KAAM;AAI1C,QAAM,kBAAkB,OAAQ,CAAC,CAAE;AACnC,QAAM,iBAAiB,OAAQ,IAAK;AAIpC,iBAAe,UAAU;AAKzB,kBAAiB,MAAM;AACtB,QACC,oBAAoB,YAAY,SAChC,cAAc,YAAY,MACzB;AACD,WAAK,QAAS,CAAE,KAAK,UAAW;AAC/B,cAAM,cAAc,gBAAgB,QAAS,KAAM;AACnD,YAAK,QAAQ,aAAc;AAC1B,oBAAW,aAAa,IAAK;AAC7B,oBAAW,KAAK,QAAQ,OAAQ;AAAA,QACjC;AAAA,MACD,CAAE;AAAA,IACH;AAEA,oBAAgB,UAAU;AAAA,EAC3B,GAAG,IAAK;AAIR,kBAAiB,MAAM;AACtB,wBAAoB,UAAU;AAAA,EAC/B,CAAE;AAIF,SAAO,YAAa,CAAE,UAAW;AAGhC,cAAW,SAAS,KAAM;AAE1B,wBAAoB,UAAU;AAC9B,kBAAc,UAAU,UAAU;AAIlC,UAAM,eAAe,QAClB,eAAe,UACf,gBAAgB;AAGnB,eAAY,OAAO,cAAe;AACjC,gBAAW,KAAK,KAAM;AAAA,IACvB;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
6
+ "names": []
7
+ }
@@ -1,26 +1,15 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useMemo, useSyncExternalStore } from '@wordpress/element';
5
-
6
- /**
7
- * Internal dependencies
8
- */
9
-
10
- /**
11
- * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the
12
- * current value corresponding to the key, or `undefined` when there is no value stored.
13
- * It also observes changes to the value and triggers an update of the calling component
14
- * in case the value changes.
15
- *
16
- * @template K The type of the keys in the map.
17
- * @template V The type of the values in the map.
18
- * @param map The `ObservableMap` to observe.
19
- * @param name The map key to observe.
20
- * @return The value corresponding to the map key requested.
21
- */
22
- export default function useObservableValue(map, name) {
23
- const [subscribe, getValue] = useMemo(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]);
1
+ import { useMemo, useSyncExternalStore } from "@wordpress/element";
2
+ function useObservableValue(map, name) {
3
+ const [subscribe, getValue] = useMemo(
4
+ () => [
5
+ (listener) => map.subscribe(name, listener),
6
+ () => map.get(name)
7
+ ],
8
+ [map, name]
9
+ );
24
10
  return useSyncExternalStore(subscribe, getValue, getValue);
25
11
  }
26
- //# sourceMappingURL=index.js.map
12
+ export {
13
+ useObservableValue as default
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useMemo","useSyncExternalStore","useObservableValue","map","name","subscribe","getValue","listener","get"],"sources":["@wordpress/compose/src/hooks/use-observable-value/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ObservableMap } from '../../utils/observable-map';\n\n/**\n * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the\n * current value corresponding to the key, or `undefined` when there is no value stored.\n * It also observes changes to the value and triggers an update of the calling component\n * in case the value changes.\n *\n * @template K The type of the keys in the map.\n * @template V The type of the values in the map.\n * @param map The `ObservableMap` to observe.\n * @param name The map key to observe.\n * @return The value corresponding to the map key requested.\n */\nexport default function useObservableValue< K, V >(\n\tmap: ObservableMap< K, V >,\n\tname: K\n): V | undefined {\n\tconst [ subscribe, getValue ] = useMemo(\n\t\t() => [\n\t\t\t( listener: () => void ) => map.subscribe( name, listener ),\n\t\t\t() => map.get( name ),\n\t\t],\n\t\t[ map, name ]\n\t);\n\treturn useSyncExternalStore( subscribe, getValue, getValue );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,OAAO,EAAEC,oBAAoB,QAAQ,oBAAoB;;AAElE;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,kBAAkBA,CACzCC,GAA0B,EAC1BC,IAAO,EACS;EAChB,MAAM,CAAEC,SAAS,EAAEC,QAAQ,CAAE,GAAGN,OAAO,CACtC,MAAM,CACHO,QAAoB,IAAMJ,GAAG,CAACE,SAAS,CAAED,IAAI,EAAEG,QAAS,CAAC,EAC3D,MAAMJ,GAAG,CAACK,GAAG,CAAEJ,IAAK,CAAC,CACrB,EACD,CAAED,GAAG,EAAEC,IAAI,CACZ,CAAC;EACD,OAAOH,oBAAoB,CAAEI,SAAS,EAAEC,QAAQ,EAAEA,QAAS,CAAC;AAC7D","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-observable-value/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ObservableMap } from '../../utils/observable-map';\n\n/**\n * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the\n * current value corresponding to the key, or `undefined` when there is no value stored.\n * It also observes changes to the value and triggers an update of the calling component\n * in case the value changes.\n *\n * @template K The type of the keys in the map.\n * @template V The type of the values in the map.\n * @param map The `ObservableMap` to observe.\n * @param name The map key to observe.\n * @return The value corresponding to the map key requested.\n */\nexport default function useObservableValue< K, V >(\n\tmap: ObservableMap< K, V >,\n\tname: K\n): V | undefined {\n\tconst [ subscribe, getValue ] = useMemo(\n\t\t() => [\n\t\t\t( listener: () => void ) => map.subscribe( name, listener ),\n\t\t\t() => map.get( name ),\n\t\t],\n\t\t[ map, name ]\n\t);\n\treturn useSyncExternalStore( subscribe, getValue, getValue );\n}\n"],
5
+ "mappings": "AAGA,SAAS,SAAS,4BAA4B;AAmB/B,SAAR,mBACN,KACA,MACgB;AAChB,QAAM,CAAE,WAAW,QAAS,IAAI;AAAA,IAC/B,MAAM;AAAA,MACL,CAAE,aAA0B,IAAI,UAAW,MAAM,QAAS;AAAA,MAC1D,MAAM,IAAI,IAAK,IAAK;AAAA,IACrB;AAAA,IACA,CAAE,KAAK,IAAK;AAAA,EACb;AACA,SAAO,qBAAsB,WAAW,UAAU,QAAS;AAC5D;",
6
+ "names": []
7
+ }
@@ -1,21 +1,15 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useState, useEffect } from '@wordpress/element';
5
- import { subscribePreferredColorScheme, isInitialColorSchemeDark } from '@wordpress/react-native-bridge';
6
-
7
- /**
8
- * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]
9
- *
10
- * @return {string} return current color scheme.
11
- */
1
+ import { useState, useEffect } from "@wordpress/element";
2
+ import {
3
+ subscribePreferredColorScheme,
4
+ isInitialColorSchemeDark
5
+ } from "@wordpress/react-native-bridge";
12
6
  function usePreferredColorScheme() {
13
- const [currentColorScheme, setCurrentColorScheme] = useState(isInitialColorSchemeDark ? 'dark' : 'light');
7
+ const [currentColorScheme, setCurrentColorScheme] = useState(
8
+ isInitialColorSchemeDark ? "dark" : "light"
9
+ );
14
10
  useEffect(() => {
15
- subscribePreferredColorScheme(({
16
- isPreferredColorSchemeDark
17
- }) => {
18
- const colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';
11
+ subscribePreferredColorScheme(({ isPreferredColorSchemeDark }) => {
12
+ const colorScheme = isPreferredColorSchemeDark ? "dark" : "light";
19
13
  if (colorScheme !== currentColorScheme) {
20
14
  setCurrentColorScheme(colorScheme);
21
15
  }
@@ -23,5 +17,8 @@ function usePreferredColorScheme() {
23
17
  });
24
18
  return currentColorScheme;
25
19
  }
26
- export default usePreferredColorScheme;
27
- //# sourceMappingURL=index.android.js.map
20
+ var index_android_default = usePreferredColorScheme;
21
+ export {
22
+ index_android_default as default
23
+ };
24
+ //# sourceMappingURL=index.android.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useState","useEffect","subscribePreferredColorScheme","isInitialColorSchemeDark","usePreferredColorScheme","currentColorScheme","setCurrentColorScheme","isPreferredColorSchemeDark","colorScheme"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.android.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tsubscribePreferredColorScheme,\n\tisInitialColorSchemeDark,\n} from '@wordpress/react-native-bridge';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nfunction usePreferredColorScheme() {\n\tconst [ currentColorScheme, setCurrentColorScheme ] = useState(\n\t\tisInitialColorSchemeDark ? 'dark' : 'light'\n\t);\n\tuseEffect( () => {\n\t\tsubscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {\n\t\t\tconst colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';\n\t\t\tif ( colorScheme !== currentColorScheme ) {\n\t\t\t\tsetCurrentColorScheme( colorScheme );\n\t\t\t}\n\t\t} );\n\t} );\n\treturn currentColorScheme;\n}\n\nexport default usePreferredColorScheme;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,EAAEC,SAAS,QAAQ,oBAAoB;AACxD,SACCC,6BAA6B,EAC7BC,wBAAwB,QAClB,gCAAgC;;AAEvC;AACA;AACA;AACA;AACA;AACA,SAASC,uBAAuBA,CAAA,EAAG;EAClC,MAAM,CAAEC,kBAAkB,EAAEC,qBAAqB,CAAE,GAAGN,QAAQ,CAC7DG,wBAAwB,GAAG,MAAM,GAAG,OACrC,CAAC;EACDF,SAAS,CAAE,MAAM;IAChBC,6BAA6B,CAAE,CAAE;MAAEK;IAA2B,CAAC,KAAM;MACpE,MAAMC,WAAW,GAAGD,0BAA0B,GAAG,MAAM,GAAG,OAAO;MACjE,IAAKC,WAAW,KAAKH,kBAAkB,EAAG;QACzCC,qBAAqB,CAAEE,WAAY,CAAC;MACrC;IACD,CAAE,CAAC;EACJ,CAAE,CAAC;EACH,OAAOH,kBAAkB;AAC1B;AAEA,eAAeD,uBAAuB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-preferred-color-scheme/index.android.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tsubscribePreferredColorScheme,\n\tisInitialColorSchemeDark,\n} from '@wordpress/react-native-bridge';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nfunction usePreferredColorScheme() {\n\tconst [ currentColorScheme, setCurrentColorScheme ] = useState(\n\t\tisInitialColorSchemeDark ? 'dark' : 'light'\n\t);\n\tuseEffect( () => {\n\t\tsubscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {\n\t\t\tconst colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';\n\t\t\tif ( colorScheme !== currentColorScheme ) {\n\t\t\t\tsetCurrentColorScheme( colorScheme );\n\t\t\t}\n\t\t} );\n\t} );\n\treturn currentColorScheme;\n}\n\nexport default usePreferredColorScheme;\n"],
5
+ "mappings": "AAGA,SAAS,UAAU,iBAAiB;AACpC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAOP,SAAS,0BAA0B;AAClC,QAAM,CAAE,oBAAoB,qBAAsB,IAAI;AAAA,IACrD,2BAA2B,SAAS;AAAA,EACrC;AACA,YAAW,MAAM;AAChB,kCAA+B,CAAE,EAAE,2BAA2B,MAAO;AACpE,YAAM,cAAc,6BAA6B,SAAS;AAC1D,UAAK,gBAAgB,oBAAqB;AACzC,8BAAuB,WAAY;AAAA,MACpC;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AACF,SAAO;AACR;AAEA,IAAO,wBAAQ;",
6
+ "names": []
7
+ }
@@ -1,13 +1,7 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { useColorScheme } from 'react-native';
5
-
6
- /**
7
- * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]
8
- *
9
- * @return {string} return current color scheme.
10
- */
1
+ import { useColorScheme } from "react-native";
11
2
  const usePreferredColorScheme = useColorScheme;
12
- export default usePreferredColorScheme;
13
- //# sourceMappingURL=index.ios.js.map
3
+ var index_ios_default = usePreferredColorScheme;
4
+ export {
5
+ index_ios_default as default
6
+ };
7
+ //# sourceMappingURL=index.ios.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useColorScheme","usePreferredColorScheme"],"sources":["@wordpress/compose/src/hooks/use-preferred-color-scheme/index.ios.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { useColorScheme } from 'react-native';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nconst usePreferredColorScheme = useColorScheme;\n\nexport default usePreferredColorScheme;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,cAAc,QAAQ,cAAc;;AAE7C;AACA;AACA;AACA;AACA;AACA,MAAMC,uBAAuB,GAAGD,cAAc;AAE9C,eAAeC,uBAAuB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-preferred-color-scheme/index.ios.js"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { useColorScheme } from 'react-native';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nconst usePreferredColorScheme = useColorScheme;\n\nexport default usePreferredColorScheme;\n"],
5
+ "mappings": "AAGA,SAAS,sBAAsB;AAO/B,MAAM,0BAA0B;AAEhC,IAAO,oBAAQ;",
6
+ "names": []
7
+ }