@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,25 +1,12 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useEffect, useRef } from '@wordpress/element';
5
-
6
- /**
7
- * Use something's value from the previous render.
8
- * Based on https://usehooks.com/usePrevious/.
9
- *
10
- * @param value The value to track.
11
- *
12
- * @return The value from the previous render.
13
- */
14
- export default function usePrevious(value) {
1
+ import { useEffect, useRef } from "@wordpress/element";
2
+ function usePrevious(value) {
15
3
  const ref = useRef();
16
-
17
- // Store current value in ref.
18
4
  useEffect(() => {
19
5
  ref.current = value;
20
- }, [value]); // Re-run when value changes.
21
-
22
- // Return previous value (happens before update in useEffect above).
6
+ }, [value]);
23
7
  return ref.current;
24
8
  }
25
- //# sourceMappingURL=index.js.map
9
+ export {
10
+ usePrevious as default
11
+ };
12
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useEffect","useRef","usePrevious","value","ref","current"],"sources":["@wordpress/compose/src/hooks/use-previous/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\n\n/**\n * Use something's value from the previous render.\n * Based on https://usehooks.com/usePrevious/.\n *\n * @param value The value to track.\n *\n * @return The value from the previous render.\n */\nexport default function usePrevious< T >( value: T ): T | undefined {\n\tconst ref = useRef< T >();\n\n\t// Store current value in ref.\n\tuseEffect( () => {\n\t\tref.current = value;\n\t}, [ value ] ); // Re-run when value changes.\n\n\t// Return previous value (happens before update in useEffect above).\n\treturn ref.current;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,MAAM,QAAQ,oBAAoB;;AAEtD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,WAAWA,CAAOC,KAAQ,EAAkB;EACnE,MAAMC,GAAG,GAAGH,MAAM,CAAM,CAAC;;EAEzB;EACAD,SAAS,CAAE,MAAM;IAChBI,GAAG,CAACC,OAAO,GAAGF,KAAK;EACpB,CAAC,EAAE,CAAEA,KAAK,CAAG,CAAC,CAAC,CAAC;;EAEhB;EACA,OAAOC,GAAG,CAACC,OAAO;AACnB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-previous/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\n\n/**\n * Use something's value from the previous render.\n * Based on https://usehooks.com/usePrevious/.\n *\n * @param value The value to track.\n *\n * @return The value from the previous render.\n */\nexport default function usePrevious< T >( value: T ): T | undefined {\n\tconst ref = useRef< T >();\n\n\t// Store current value in ref.\n\tuseEffect( () => {\n\t\tref.current = value;\n\t}, [ value ] ); // Re-run when value changes.\n\n\t// Return previous value (happens before update in useEffect above).\n\treturn ref.current;\n}\n"],
5
+ "mappings": "AAGA,SAAS,WAAW,cAAc;AAUnB,SAAR,YAAmC,OAA0B;AACnE,QAAM,MAAM,OAAY;AAGxB,YAAW,MAAM;AAChB,QAAI,UAAU;AAAA,EACf,GAAG,CAAE,KAAM,CAAE;AAGb,SAAO,IAAI;AACZ;",
6
+ "names": []
7
+ }
@@ -1,13 +1,7 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import useMediaQuery from '../use-media-query';
5
-
6
- /**
7
- * Hook returning whether the user has a preference for reduced motion.
8
- *
9
- * @return {boolean} Reduced motion preference value.
10
- */
11
- const useReducedMotion = () => useMediaQuery('(prefers-reduced-motion: reduce)');
12
- export default useReducedMotion;
13
- //# sourceMappingURL=index.js.map
1
+ import useMediaQuery from "../use-media-query";
2
+ const useReducedMotion = () => useMediaQuery("(prefers-reduced-motion: reduce)");
3
+ var use_reduced_motion_default = useReducedMotion;
4
+ export {
5
+ use_reduced_motion_default as default
6
+ };
7
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useMediaQuery","useReducedMotion"],"sources":["@wordpress/compose/src/hooks/use-reduced-motion/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * Hook returning whether the user has a preference for reduced motion.\n *\n * @return {boolean} Reduced motion preference value.\n */\nconst useReducedMotion = () =>\n\tuseMediaQuery( '(prefers-reduced-motion: reduce)' );\n\nexport default useReducedMotion;\n"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,aAAa,MAAM,oBAAoB;;AAE9C;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAA,KACxBD,aAAa,CAAE,kCAAmC,CAAC;AAEpD,eAAeC,gBAAgB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-reduced-motion/index.js"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * Hook returning whether the user has a preference for reduced motion.\n *\n * @return {boolean} Reduced motion preference value.\n */\nconst useReducedMotion = () =>\n\tuseMediaQuery( '(prefers-reduced-motion: reduce)' );\n\nexport default useReducedMotion;\n"],
5
+ "mappings": "AAGA,OAAO,mBAAmB;AAO1B,MAAM,mBAAmB,MACxB,cAAe,kCAAmC;AAEnD,IAAO,6BAAQ;",
6
+ "names": []
7
+ }
@@ -1,34 +1,7 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
- /**
6
- * WordPress dependencies
7
- */
8
- import { useCallback, useRef } from '@wordpress/element';
9
-
10
- /**
11
- * Effect-like ref callback. Just like with `useEffect`, this allows you to
12
- * return a cleanup function to be run if the ref changes or one of the
13
- * dependencies changes. The ref is provided as an argument to the callback
14
- * functions. The main difference between this and `useEffect` is that
15
- * the `useEffect` callback is not called when the ref changes, but this is.
16
- * Pass the returned ref callback as the component's ref and merge multiple refs
17
- * with `useMergeRefs`.
18
- *
19
- * It's worth noting that if the dependencies array is empty, there's not
20
- * strictly a need to clean up event handlers for example, because the node is
21
- * to be removed. It *is* necessary if you add dependencies because the ref
22
- * callback will be called multiple times for the same node.
23
- *
24
- * @param callback Callback with ref as argument.
25
- * @param dependencies Dependencies of the callback.
26
- *
27
- * @return Ref callback.
28
- */
29
- export default function useRefEffect(callback, dependencies) {
1
+ import { useCallback, useRef } from "@wordpress/element";
2
+ function useRefEffect(callback, dependencies) {
30
3
  const cleanupRef = useRef();
31
- return useCallback(node => {
4
+ return useCallback((node) => {
32
5
  if (node) {
33
6
  cleanupRef.current = callback(node);
34
7
  } else if (cleanupRef.current) {
@@ -36,4 +9,7 @@ export default function useRefEffect(callback, dependencies) {
36
9
  }
37
10
  }, dependencies);
38
11
  }
39
- //# sourceMappingURL=index.js.map
12
+ export {
13
+ useRefEffect as default
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useCallback","useRef","useRefEffect","callback","dependencies","cleanupRef","node","current"],"sources":["@wordpress/compose/src/hooks/use-ref-effect/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { DependencyList, RefCallback } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useRef } from '@wordpress/element';\n\n/**\n * Effect-like ref callback. Just like with `useEffect`, this allows you to\n * return a cleanup function to be run if the ref changes or one of the\n * dependencies changes. The ref is provided as an argument to the callback\n * functions. The main difference between this and `useEffect` is that\n * the `useEffect` callback is not called when the ref changes, but this is.\n * Pass the returned ref callback as the component's ref and merge multiple refs\n * with `useMergeRefs`.\n *\n * It's worth noting that if the dependencies array is empty, there's not\n * strictly a need to clean up event handlers for example, because the node is\n * to be removed. It *is* necessary if you add dependencies because the ref\n * callback will be called multiple times for the same node.\n *\n * @param callback Callback with ref as argument.\n * @param dependencies Dependencies of the callback.\n *\n * @return Ref callback.\n */\nexport default function useRefEffect< TElement = Node >(\n\tcallback: ( node: TElement ) => ( () => void ) | void,\n\tdependencies: DependencyList\n): RefCallback< TElement | null > {\n\tconst cleanupRef = useRef< ( () => void ) | void >();\n\treturn useCallback( ( node: TElement | null ) => {\n\t\tif ( node ) {\n\t\t\tcleanupRef.current = callback( node );\n\t\t} else if ( cleanupRef.current ) {\n\t\t\tcleanupRef.current();\n\t\t}\n\t}, dependencies );\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,MAAM,QAAQ,oBAAoB;;AAExD;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,YAAYA,CACnCC,QAAqD,EACrDC,YAA4B,EACK;EACjC,MAAMC,UAAU,GAAGJ,MAAM,CAA0B,CAAC;EACpD,OAAOD,WAAW,CAAIM,IAAqB,IAAM;IAChD,IAAKA,IAAI,EAAG;MACXD,UAAU,CAACE,OAAO,GAAGJ,QAAQ,CAAEG,IAAK,CAAC;IACtC,CAAC,MAAM,IAAKD,UAAU,CAACE,OAAO,EAAG;MAChCF,UAAU,CAACE,OAAO,CAAC,CAAC;IACrB;EACD,CAAC,EAAEH,YAAa,CAAC;AAClB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-ref-effect/index.ts"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { DependencyList, RefCallback } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useRef } from '@wordpress/element';\n\n/**\n * Effect-like ref callback. Just like with `useEffect`, this allows you to\n * return a cleanup function to be run if the ref changes or one of the\n * dependencies changes. The ref is provided as an argument to the callback\n * functions. The main difference between this and `useEffect` is that\n * the `useEffect` callback is not called when the ref changes, but this is.\n * Pass the returned ref callback as the component's ref and merge multiple refs\n * with `useMergeRefs`.\n *\n * It's worth noting that if the dependencies array is empty, there's not\n * strictly a need to clean up event handlers for example, because the node is\n * to be removed. It *is* necessary if you add dependencies because the ref\n * callback will be called multiple times for the same node.\n *\n * @param callback Callback with ref as argument.\n * @param dependencies Dependencies of the callback.\n *\n * @return Ref callback.\n */\nexport default function useRefEffect< TElement = Node >(\n\tcallback: ( node: TElement ) => ( () => void ) | void,\n\tdependencies: DependencyList\n): RefCallback< TElement | null > {\n\tconst cleanupRef = useRef< ( () => void ) | void >();\n\treturn useCallback( ( node: TElement | null ) => {\n\t\tif ( node ) {\n\t\t\tcleanupRef.current = callback( node );\n\t\t} else if ( cleanupRef.current ) {\n\t\t\tcleanupRef.current();\n\t\t}\n\t}, dependencies );\n}\n"],
5
+ "mappings": "AAQA,SAAS,aAAa,cAAc;AAqBrB,SAAR,aACN,UACA,cACiC;AACjC,QAAM,aAAa,OAAgC;AACnD,SAAO,YAAa,CAAE,SAA2B;AAChD,QAAK,MAAO;AACX,iBAAW,UAAU,SAAU,IAAK;AAAA,IACrC,WAAY,WAAW,SAAU;AAChC,iBAAW,QAAQ;AAAA,IACpB;AAAA,EACD,GAAG,YAAa;AACjB;",
6
+ "names": []
7
+ }
@@ -1,63 +1,9 @@
1
- /**
2
- * Internal dependencies
3
- */
4
- import { useResizeObserver as _useResizeObserver } from './use-resize-observer';
5
- import _useLegacyResizeObserver from './legacy';
6
- /**
7
- * External dependencies
8
- */
9
-
10
- /**
11
- * Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API)
12
- * for an HTML or SVG element.
13
- *
14
- * Pass the returned setter as a callback ref to the React element you want
15
- * to observe, or use it in layout effects for advanced use cases.
16
- *
17
- * @example
18
- *
19
- * ```tsx
20
- * const setElement = useResizeObserver(
21
- * ( resizeObserverEntries ) => console.log( resizeObserverEntries ),
22
- * { box: 'border-box' }
23
- * );
24
- * <div ref={ setElement } />;
25
- *
26
- * // The setter can be used in other ways, for example:
27
- * useLayoutEffect( () => {
28
- * setElement( document.querySelector( `data-element-id="${ elementId }"` ) );
29
- * }, [ elementId ] );
30
- * ```
31
- *
32
- * @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).
33
- * @param options Options passed to `ResizeObserver.observe` when called - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options). Changes will be ignored.
34
- */
35
-
36
- /**
37
- * **This is a legacy API and should not be used.**
38
- *
39
- * @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`.
40
- *
41
- * Hook which allows to listen to the resize event of any target element when it changes size.
42
- * _Note: `useResizeObserver` will report `null` sizes until after first render.
43
- *
44
- * @example
45
- *
46
- * ```js
47
- * const App = () => {
48
- * const [ resizeListener, sizes ] = useResizeObserver();
49
- *
50
- * return (
51
- * <div>
52
- * { resizeListener }
53
- * Your content here
54
- * </div>
55
- * );
56
- * };
57
- * ```
58
- */
59
-
60
- export default function useResizeObserver(callback, options = {}) {
1
+ import { useResizeObserver as _useResizeObserver } from "./use-resize-observer";
2
+ import _useLegacyResizeObserver from "./legacy";
3
+ function useResizeObserver(callback, options = {}) {
61
4
  return callback ? _useResizeObserver(callback, options) : _useLegacyResizeObserver();
62
5
  }
63
- //# sourceMappingURL=index.js.map
6
+ export {
7
+ useResizeObserver as default
8
+ };
9
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useResizeObserver","_useResizeObserver","_useLegacyResizeObserver","callback","options"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.ts"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport { useResizeObserver as _useResizeObserver } from './use-resize-observer';\nimport type { ObservedSize } from './legacy';\nimport _useLegacyResizeObserver from './legacy';\n/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API)\n * for an HTML or SVG element.\n *\n * Pass the returned setter as a callback ref to the React element you want\n * to observe, or use it in layout effects for advanced use cases.\n *\n * @example\n *\n * ```tsx\n * const setElement = useResizeObserver(\n * \t( resizeObserverEntries ) => console.log( resizeObserverEntries ),\n * \t{ box: 'border-box' }\n * );\n * <div ref={ setElement } />;\n *\n * // The setter can be used in other ways, for example:\n * useLayoutEffect( () => {\n * \tsetElement( document.querySelector( `data-element-id=\"${ elementId }\"` ) );\n * }, [ elementId ] );\n * ```\n *\n * @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).\n * @param options Options passed to `ResizeObserver.observe` when called - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options). Changes will be ignored.\n */\nexport default function useResizeObserver< T extends Element >(\n\t/**\n\t * The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).\n\t */\n\tcallback: ResizeObserverCallback,\n\t/**\n\t * Options passed to `ResizeObserver.observe` when called - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options). Changes will be ignored.\n\t */\n\toptions?: ResizeObserverOptions\n): ( element?: T | null ) => void;\n\n/**\n * **This is a legacy API and should not be used.**\n *\n * @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`.\n *\n * Hook which allows to listen to the resize event of any target element when it changes size.\n * _Note: `useResizeObserver` will report `null` sizes until after first render.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nexport default function useResizeObserver(): [ ReactElement, ObservedSize ];\n\nexport default function useResizeObserver< T extends HTMLElement >(\n\tcallback?: ResizeObserverCallback,\n\toptions: ResizeObserverOptions = {}\n): ( ( element?: T | null ) => void ) | [ ReactElement, ObservedSize ] {\n\treturn callback\n\t\t? _useResizeObserver( callback, options )\n\t\t: _useLegacyResizeObserver();\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,iBAAiB,IAAIC,kBAAkB,QAAQ,uBAAuB;AAE/E,OAAOC,wBAAwB,MAAM,UAAU;AAC/C;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,eAAe,SAASF,iBAAiBA,CACxCG,QAAiC,EACjCC,OAA8B,GAAG,CAAC,CAAC,EACmC;EACtE,OAAOD,QAAQ,GACZF,kBAAkB,CAAEE,QAAQ,EAAEC,OAAQ,CAAC,GACvCF,wBAAwB,CAAC,CAAC;AAC9B","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-resize-observer/index.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { useResizeObserver as _useResizeObserver } from './use-resize-observer';\nimport type { ObservedSize } from './legacy';\nimport _useLegacyResizeObserver from './legacy';\n/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API)\n * for an HTML or SVG element.\n *\n * Pass the returned setter as a callback ref to the React element you want\n * to observe, or use it in layout effects for advanced use cases.\n *\n * @example\n *\n * ```tsx\n * const setElement = useResizeObserver(\n * \t( resizeObserverEntries ) => console.log( resizeObserverEntries ),\n * \t{ box: 'border-box' }\n * );\n * <div ref={ setElement } />;\n *\n * // The setter can be used in other ways, for example:\n * useLayoutEffect( () => {\n * \tsetElement( document.querySelector( `data-element-id=\"${ elementId }\"` ) );\n * }, [ elementId ] );\n * ```\n *\n * @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).\n * @param options Options passed to `ResizeObserver.observe` when called - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options). Changes will be ignored.\n */\nexport default function useResizeObserver< T extends Element >(\n\t/**\n\t * The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).\n\t */\n\tcallback: ResizeObserverCallback,\n\t/**\n\t * Options passed to `ResizeObserver.observe` when called - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/observe#options). Changes will be ignored.\n\t */\n\toptions?: ResizeObserverOptions\n): ( element?: T | null ) => void;\n\n/**\n * **This is a legacy API and should not be used.**\n *\n * @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`.\n *\n * Hook which allows to listen to the resize event of any target element when it changes size.\n * _Note: `useResizeObserver` will report `null` sizes until after first render.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nexport default function useResizeObserver(): [ ReactElement, ObservedSize ];\n\nexport default function useResizeObserver< T extends HTMLElement >(\n\tcallback?: ResizeObserverCallback,\n\toptions: ResizeObserverOptions = {}\n): ( ( element?: T | null ) => void ) | [ ReactElement, ObservedSize ] {\n\treturn callback\n\t\t? _useResizeObserver( callback, options )\n\t\t: _useLegacyResizeObserver();\n}\n"],
5
+ "mappings": "AAGA,SAAS,qBAAqB,0BAA0B;AAExD,OAAO,8BAA8B;AAmEtB,SAAR,kBACN,UACA,UAAiC,CAAC,GACoC;AACtE,SAAO,WACJ,mBAAoB,UAAU,OAAQ,IACtC,yBAAyB;AAC7B;",
6
+ "names": []
7
+ }
@@ -1,130 +1,62 @@
1
- /**
2
- * External dependencies
3
- */
4
-
5
- /**
6
- * WordPress dependencies
7
- */
8
- import { useCallback, useRef, useState } from '@wordpress/element';
9
- /**
10
- * Internal dependencies
11
- */
12
- import { useResizeObserver } from '../use-resize-observer';
13
- import { jsx as _jsx } from "react/jsx-runtime";
14
- // We're only using the first element of the size sequences, until future versions of the spec solidify on how
15
- // exactly it'll be used for fragments in multi-column scenarios:
16
- // From the spec:
17
- // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,
18
- // > which occur in multi-column scenarios. However the current definitions of content rect and border box do not
19
- // > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single
20
- // > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.
21
- // > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.
22
- // (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)
23
- //
24
- // Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,
25
- // regardless of the "box" option.
26
- // The spec states the following on this:
27
- // > This does not have any impact on which box dimensions are returned to the defined callback when the event
28
- // > is fired, it solely defines which box the author wishes to observe layout changes on.
29
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
30
- // I'm not exactly clear on what this means, especially when you consider a later section stating the following:
31
- // > This section is non-normative. An author may desire to observe more than one CSS box.
32
- // > In this case, author will need to use multiple ResizeObservers.
33
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
34
- // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.
35
- // For this reason I decided to only return the requested size,
36
- // even though it seems we have access to results for all box types.
37
- // This also means that we get to keep the current api, being able to return a simple { width, height } pair,
38
- // regardless of box option.
39
- const extractSize = entry => {
1
+ import { jsx } from "react/jsx-runtime";
2
+ import { useCallback, useRef, useState } from "@wordpress/element";
3
+ import { useResizeObserver } from "../use-resize-observer";
4
+ const extractSize = (entry) => {
40
5
  let entrySize;
41
6
  if (!entry.contentBoxSize) {
42
- // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.
43
- // See the 6th step in the description for the RO algorithm:
44
- // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h
45
- // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box".
46
- // In real browser implementations of course these objects differ, but the width/height values should be equivalent.
47
7
  entrySize = [entry.contentRect.width, entry.contentRect.height];
48
8
  } else if (entry.contentBoxSize[0]) {
49
9
  const contentBoxSize = entry.contentBoxSize[0];
50
10
  entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
51
11
  } else {
52
- // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy
53
- // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.
54
12
  const contentBoxSize = entry.contentBoxSize;
55
13
  entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
56
14
  }
57
- const [width, height] = entrySize.map(d => Math.round(d));
58
- return {
59
- width,
60
- height
61
- };
15
+ const [width, height] = entrySize.map((d) => Math.round(d));
16
+ return { width, height };
62
17
  };
63
18
  const RESIZE_ELEMENT_STYLES = {
64
- position: 'absolute',
19
+ position: "absolute",
65
20
  top: 0,
66
21
  left: 0,
67
22
  right: 0,
68
23
  bottom: 0,
69
- pointerEvents: 'none',
24
+ pointerEvents: "none",
70
25
  opacity: 0,
71
- overflow: 'hidden',
26
+ overflow: "hidden",
72
27
  zIndex: -1
73
28
  };
74
- function ResizeElement({
75
- onResize
76
- }) {
77
- const resizeElementRef = useResizeObserver(entries => {
78
- const newSize = extractSize(entries.at(-1)); // Entries are never empty.
29
+ function ResizeElement({ onResize }) {
30
+ const resizeElementRef = useResizeObserver((entries) => {
31
+ const newSize = extractSize(entries.at(-1));
79
32
  onResize(newSize);
80
33
  });
81
- return /*#__PURE__*/_jsx("div", {
82
- ref: resizeElementRef,
83
- style: RESIZE_ELEMENT_STYLES,
84
- "aria-hidden": "true"
85
- });
34
+ return /* @__PURE__ */ jsx(
35
+ "div",
36
+ {
37
+ ref: resizeElementRef,
38
+ style: RESIZE_ELEMENT_STYLES,
39
+ "aria-hidden": "true"
40
+ }
41
+ );
86
42
  }
87
43
  function sizeEquals(a, b) {
88
44
  return a.width === b.width && a.height === b.height;
89
45
  }
90
- const NULL_SIZE = {
91
- width: null,
92
- height: null
93
- };
94
-
95
- /**
96
- * Hook which allows to listen to the resize event of any target element when it changes size.
97
- * _Note: `useResizeObserver` will report `null` sizes until after first render.
98
- *
99
- * @example
100
- *
101
- * ```js
102
- * const App = () => {
103
- * const [ resizeListener, sizes ] = useResizeObserver();
104
- *
105
- * return (
106
- * <div>
107
- * { resizeListener }
108
- * Your content here
109
- * </div>
110
- * );
111
- * };
112
- * ```
113
- */
114
- export default function useLegacyResizeObserver() {
46
+ const NULL_SIZE = { width: null, height: null };
47
+ function useLegacyResizeObserver() {
115
48
  const [size, setSize] = useState(NULL_SIZE);
116
-
117
- // Using a ref to track the previous width / height to avoid unnecessary renders.
118
49
  const previousSizeRef = useRef(NULL_SIZE);
119
- const handleResize = useCallback(newSize => {
50
+ const handleResize = useCallback((newSize) => {
120
51
  if (!sizeEquals(previousSizeRef.current, newSize)) {
121
52
  previousSizeRef.current = newSize;
122
53
  setSize(newSize);
123
54
  }
124
55
  }, []);
125
- const resizeElement = /*#__PURE__*/_jsx(ResizeElement, {
126
- onResize: handleResize
127
- });
56
+ const resizeElement = /* @__PURE__ */ jsx(ResizeElement, { onResize: handleResize });
128
57
  return [resizeElement, size];
129
58
  }
130
- //# sourceMappingURL=index.js.map
59
+ export {
60
+ useLegacyResizeObserver as default
61
+ };
62
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useCallback","useRef","useState","useResizeObserver","jsx","_jsx","extractSize","entry","entrySize","contentBoxSize","contentRect","width","height","inlineSize","blockSize","map","d","Math","round","RESIZE_ELEMENT_STYLES","position","top","left","right","bottom","pointerEvents","opacity","overflow","zIndex","ResizeElement","onResize","resizeElementRef","entries","newSize","at","ref","style","sizeEquals","a","b","NULL_SIZE","useLegacyResizeObserver","size","setSize","previousSizeRef","handleResize","current","resizeElement"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/legacy/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useRef, useState } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport { useResizeObserver } from '../use-resize-observer';\n\nexport type ObservedSize = {\n\twidth: number | null;\n\theight: number | null;\n};\n\n// We're only using the first element of the size sequences, until future versions of the spec solidify on how\n// exactly it'll be used for fragments in multi-column scenarios:\n// From the spec:\n// > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,\n// > which occur in multi-column scenarios. However the current definitions of content rect and border box do not\n// > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single\n// > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.\n// > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)\n//\n// Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,\n// regardless of the \"box\" option.\n// The spec states the following on this:\n// > This does not have any impact on which box dimensions are returned to the defined callback when the event\n// > is fired, it solely defines which box the author wishes to observe layout changes on.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// I'm not exactly clear on what this means, especially when you consider a later section stating the following:\n// > This section is non-normative. An author may desire to observe more than one CSS box.\n// > In this case, author will need to use multiple ResizeObservers.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.\n// For this reason I decided to only return the requested size,\n// even though it seems we have access to results for all box types.\n// This also means that we get to keep the current api, being able to return a simple { width, height } pair,\n// regardless of box option.\nconst extractSize = ( entry: ResizeObserverEntry ): ObservedSize => {\n\tlet entrySize;\n\tif ( ! entry.contentBoxSize ) {\n\t\t// The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.\n\t\t// See the 6th step in the description for the RO algorithm:\n\t\t// https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h\n\t\t// > Set this.contentRect to logical this.contentBoxSize given target and observedBox of \"content-box\".\n\t\t// In real browser implementations of course these objects differ, but the width/height values should be equivalent.\n\t\tentrySize = [ entry.contentRect.width, entry.contentRect.height ];\n\t} else if ( entry.contentBoxSize[ 0 ] ) {\n\t\tconst contentBoxSize = entry.contentBoxSize[ 0 ];\n\t\tentrySize = [ contentBoxSize.inlineSize, contentBoxSize.blockSize ];\n\t} else {\n\t\t// TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy\n\t\t// behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.\n\t\tconst contentBoxSize =\n\t\t\tentry.contentBoxSize as unknown as ResizeObserverSize;\n\t\tentrySize = [ contentBoxSize.inlineSize, contentBoxSize.blockSize ];\n\t}\n\n\tconst [ width, height ] = entrySize.map( ( d ) => Math.round( d ) );\n\treturn { width, height };\n};\n\nconst RESIZE_ELEMENT_STYLES = {\n\tposition: 'absolute',\n\ttop: 0,\n\tleft: 0,\n\tright: 0,\n\tbottom: 0,\n\tpointerEvents: 'none',\n\topacity: 0,\n\toverflow: 'hidden',\n\tzIndex: -1,\n} as const;\n\ntype ResizeElementProps = {\n\tonResize: ( s: ObservedSize ) => void;\n};\n\nfunction ResizeElement( { onResize }: ResizeElementProps ) {\n\tconst resizeElementRef = useResizeObserver( ( entries ) => {\n\t\tconst newSize = extractSize( entries.at( -1 )! ); // Entries are never empty.\n\t\tonResize( newSize );\n\t} );\n\n\treturn (\n\t\t<div\n\t\t\tref={ resizeElementRef }\n\t\t\tstyle={ RESIZE_ELEMENT_STYLES }\n\t\t\taria-hidden=\"true\"\n\t\t/>\n\t);\n}\n\nfunction sizeEquals( a: ObservedSize, b: ObservedSize ) {\n\treturn a.width === b.width && a.height === b.height;\n}\n\nconst NULL_SIZE: ObservedSize = { width: null, height: null };\n\n/**\n * Hook which allows to listen to the resize event of any target element when it changes size.\n * _Note: `useResizeObserver` will report `null` sizes until after first render.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nexport default function useLegacyResizeObserver(): [\n\tReactElement,\n\tObservedSize,\n] {\n\tconst [ size, setSize ] = useState( NULL_SIZE );\n\n\t// Using a ref to track the previous width / height to avoid unnecessary renders.\n\tconst previousSizeRef = useRef( NULL_SIZE );\n\n\tconst handleResize = useCallback( ( newSize: ObservedSize ) => {\n\t\tif ( ! sizeEquals( previousSizeRef.current, newSize ) ) {\n\t\t\tpreviousSizeRef.current = newSize;\n\t\t\tsetSize( newSize );\n\t\t}\n\t}, [] );\n\n\tconst resizeElement = <ResizeElement onResize={ handleResize } />;\n\treturn [ resizeElement, size ];\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,oBAAoB;AAClE;AACA;AACA;AACA,SAASC,iBAAiB,QAAQ,wBAAwB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAO3D;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,MAAMC,WAAW,GAAKC,KAA0B,IAAoB;EACnE,IAAIC,SAAS;EACb,IAAK,CAAED,KAAK,CAACE,cAAc,EAAG;IAC7B;IACA;IACA;IACA;IACA;IACAD,SAAS,GAAG,CAAED,KAAK,CAACG,WAAW,CAACC,KAAK,EAAEJ,KAAK,CAACG,WAAW,CAACE,MAAM,CAAE;EAClE,CAAC,MAAM,IAAKL,KAAK,CAACE,cAAc,CAAE,CAAC,CAAE,EAAG;IACvC,MAAMA,cAAc,GAAGF,KAAK,CAACE,cAAc,CAAE,CAAC,CAAE;IAChDD,SAAS,GAAG,CAAEC,cAAc,CAACI,UAAU,EAAEJ,cAAc,CAACK,SAAS,CAAE;EACpE,CAAC,MAAM;IACN;IACA;IACA,MAAML,cAAc,GACnBF,KAAK,CAACE,cAA+C;IACtDD,SAAS,GAAG,CAAEC,cAAc,CAACI,UAAU,EAAEJ,cAAc,CAACK,SAAS,CAAE;EACpE;EAEA,MAAM,CAAEH,KAAK,EAAEC,MAAM,CAAE,GAAGJ,SAAS,CAACO,GAAG,CAAIC,CAAC,IAAMC,IAAI,CAACC,KAAK,CAAEF,CAAE,CAAE,CAAC;EACnE,OAAO;IAAEL,KAAK;IAAEC;EAAO,CAAC;AACzB,CAAC;AAED,MAAMO,qBAAqB,GAAG;EAC7BC,QAAQ,EAAE,UAAU;EACpBC,GAAG,EAAE,CAAC;EACNC,IAAI,EAAE,CAAC;EACPC,KAAK,EAAE,CAAC;EACRC,MAAM,EAAE,CAAC;EACTC,aAAa,EAAE,MAAM;EACrBC,OAAO,EAAE,CAAC;EACVC,QAAQ,EAAE,QAAQ;EAClBC,MAAM,EAAE,CAAC;AACV,CAAU;AAMV,SAASC,aAAaA,CAAE;EAAEC;AAA6B,CAAC,EAAG;EAC1D,MAAMC,gBAAgB,GAAG5B,iBAAiB,CAAI6B,OAAO,IAAM;IAC1D,MAAMC,OAAO,GAAG3B,WAAW,CAAE0B,OAAO,CAACE,EAAE,CAAE,CAAC,CAAE,CAAG,CAAC,CAAC,CAAC;IAClDJ,QAAQ,CAAEG,OAAQ,CAAC;EACpB,CAAE,CAAC;EAEH,oBACC5B,IAAA;IACC8B,GAAG,EAAGJ,gBAAkB;IACxBK,KAAK,EAAGjB,qBAAuB;IAC/B,eAAY;EAAM,CAClB,CAAC;AAEJ;AAEA,SAASkB,UAAUA,CAAEC,CAAe,EAAEC,CAAe,EAAG;EACvD,OAAOD,CAAC,CAAC3B,KAAK,KAAK4B,CAAC,CAAC5B,KAAK,IAAI2B,CAAC,CAAC1B,MAAM,KAAK2B,CAAC,CAAC3B,MAAM;AACpD;AAEA,MAAM4B,SAAuB,GAAG;EAAE7B,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE;AAAK,CAAC;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAAS6B,uBAAuBA,CAAA,EAG7C;EACD,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAAGzC,QAAQ,CAAEsC,SAAU,CAAC;;EAE/C;EACA,MAAMI,eAAe,GAAG3C,MAAM,CAAEuC,SAAU,CAAC;EAE3C,MAAMK,YAAY,GAAG7C,WAAW,CAAIiC,OAAqB,IAAM;IAC9D,IAAK,CAAEI,UAAU,CAAEO,eAAe,CAACE,OAAO,EAAEb,OAAQ,CAAC,EAAG;MACvDW,eAAe,CAACE,OAAO,GAAGb,OAAO;MACjCU,OAAO,CAAEV,OAAQ,CAAC;IACnB;EACD,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMc,aAAa,gBAAG1C,IAAA,CAACwB,aAAa;IAACC,QAAQ,EAAGe;EAAc,CAAE,CAAC;EACjE,OAAO,CAAEE,aAAa,EAAEL,IAAI,CAAE;AAC/B","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/hooks/use-resize-observer/legacy/index.tsx"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useRef, useState } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport { useResizeObserver } from '../use-resize-observer';\n\nexport type ObservedSize = {\n\twidth: number | null;\n\theight: number | null;\n};\n\n// We're only using the first element of the size sequences, until future versions of the spec solidify on how\n// exactly it'll be used for fragments in multi-column scenarios:\n// From the spec:\n// > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,\n// > which occur in multi-column scenarios. However the current definitions of content rect and border box do not\n// > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single\n// > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.\n// > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)\n//\n// Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,\n// regardless of the \"box\" option.\n// The spec states the following on this:\n// > This does not have any impact on which box dimensions are returned to the defined callback when the event\n// > is fired, it solely defines which box the author wishes to observe layout changes on.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// I'm not exactly clear on what this means, especially when you consider a later section stating the following:\n// > This section is non-normative. An author may desire to observe more than one CSS box.\n// > In this case, author will need to use multiple ResizeObservers.\n// (https://drafts.csswg.org/resize-observer/#resize-observer-interface)\n// Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.\n// For this reason I decided to only return the requested size,\n// even though it seems we have access to results for all box types.\n// This also means that we get to keep the current api, being able to return a simple { width, height } pair,\n// regardless of box option.\nconst extractSize = ( entry: ResizeObserverEntry ): ObservedSize => {\n\tlet entrySize;\n\tif ( ! entry.contentBoxSize ) {\n\t\t// The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.\n\t\t// See the 6th step in the description for the RO algorithm:\n\t\t// https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h\n\t\t// > Set this.contentRect to logical this.contentBoxSize given target and observedBox of \"content-box\".\n\t\t// In real browser implementations of course these objects differ, but the width/height values should be equivalent.\n\t\tentrySize = [ entry.contentRect.width, entry.contentRect.height ];\n\t} else if ( entry.contentBoxSize[ 0 ] ) {\n\t\tconst contentBoxSize = entry.contentBoxSize[ 0 ];\n\t\tentrySize = [ contentBoxSize.inlineSize, contentBoxSize.blockSize ];\n\t} else {\n\t\t// TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy\n\t\t// behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.\n\t\tconst contentBoxSize =\n\t\t\tentry.contentBoxSize as unknown as ResizeObserverSize;\n\t\tentrySize = [ contentBoxSize.inlineSize, contentBoxSize.blockSize ];\n\t}\n\n\tconst [ width, height ] = entrySize.map( ( d ) => Math.round( d ) );\n\treturn { width, height };\n};\n\nconst RESIZE_ELEMENT_STYLES = {\n\tposition: 'absolute',\n\ttop: 0,\n\tleft: 0,\n\tright: 0,\n\tbottom: 0,\n\tpointerEvents: 'none',\n\topacity: 0,\n\toverflow: 'hidden',\n\tzIndex: -1,\n} as const;\n\ntype ResizeElementProps = {\n\tonResize: ( s: ObservedSize ) => void;\n};\n\nfunction ResizeElement( { onResize }: ResizeElementProps ) {\n\tconst resizeElementRef = useResizeObserver( ( entries ) => {\n\t\tconst newSize = extractSize( entries.at( -1 )! ); // Entries are never empty.\n\t\tonResize( newSize );\n\t} );\n\n\treturn (\n\t\t<div\n\t\t\tref={ resizeElementRef }\n\t\t\tstyle={ RESIZE_ELEMENT_STYLES }\n\t\t\taria-hidden=\"true\"\n\t\t/>\n\t);\n}\n\nfunction sizeEquals( a: ObservedSize, b: ObservedSize ) {\n\treturn a.width === b.width && a.height === b.height;\n}\n\nconst NULL_SIZE: ObservedSize = { width: null, height: null };\n\n/**\n * Hook which allows to listen to the resize event of any target element when it changes size.\n * _Note: `useResizeObserver` will report `null` sizes until after first render.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<div>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</div>\n * \t);\n * };\n * ```\n */\nexport default function useLegacyResizeObserver(): [\n\tReactElement,\n\tObservedSize,\n] {\n\tconst [ size, setSize ] = useState( NULL_SIZE );\n\n\t// Using a ref to track the previous width / height to avoid unnecessary renders.\n\tconst previousSizeRef = useRef( NULL_SIZE );\n\n\tconst handleResize = useCallback( ( newSize: ObservedSize ) => {\n\t\tif ( ! sizeEquals( previousSizeRef.current, newSize ) ) {\n\t\t\tpreviousSizeRef.current = newSize;\n\t\t\tsetSize( newSize );\n\t\t}\n\t}, [] );\n\n\tconst resizeElement = <ResizeElement onResize={ handleResize } />;\n\treturn [ resizeElement, size ];\n}\n"],
5
+ "mappings": "AA2FE;AAnFF,SAAS,aAAa,QAAQ,gBAAgB;AAI9C,SAAS,yBAAyB;AAgClC,MAAM,cAAc,CAAE,UAA8C;AACnE,MAAI;AACJ,MAAK,CAAE,MAAM,gBAAiB;AAM7B,gBAAY,CAAE,MAAM,YAAY,OAAO,MAAM,YAAY,MAAO;AAAA,EACjE,WAAY,MAAM,eAAgB,CAAE,GAAI;AACvC,UAAM,iBAAiB,MAAM,eAAgB,CAAE;AAC/C,gBAAY,CAAE,eAAe,YAAY,eAAe,SAAU;AAAA,EACnE,OAAO;AAGN,UAAM,iBACL,MAAM;AACP,gBAAY,CAAE,eAAe,YAAY,eAAe,SAAU;AAAA,EACnE;AAEA,QAAM,CAAE,OAAO,MAAO,IAAI,UAAU,IAAK,CAAE,MAAO,KAAK,MAAO,CAAE,CAAE;AAClE,SAAO,EAAE,OAAO,OAAO;AACxB;AAEA,MAAM,wBAAwB;AAAA,EAC7B,UAAU;AAAA,EACV,KAAK;AAAA,EACL,MAAM;AAAA,EACN,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,eAAe;AAAA,EACf,SAAS;AAAA,EACT,UAAU;AAAA,EACV,QAAQ;AACT;AAMA,SAAS,cAAe,EAAE,SAAS,GAAwB;AAC1D,QAAM,mBAAmB,kBAAmB,CAAE,YAAa;AAC1D,UAAM,UAAU,YAAa,QAAQ,GAAI,EAAG,CAAG;AAC/C,aAAU,OAAQ;AAAA,EACnB,CAAE;AAEF,SACC;AAAA,IAAC;AAAA;AAAA,MACA,KAAM;AAAA,MACN,OAAQ;AAAA,MACR,eAAY;AAAA;AAAA,EACb;AAEF;AAEA,SAAS,WAAY,GAAiB,GAAkB;AACvD,SAAO,EAAE,UAAU,EAAE,SAAS,EAAE,WAAW,EAAE;AAC9C;AAEA,MAAM,YAA0B,EAAE,OAAO,MAAM,QAAQ,KAAK;AAqB7C,SAAR,0BAGL;AACD,QAAM,CAAE,MAAM,OAAQ,IAAI,SAAU,SAAU;AAG9C,QAAM,kBAAkB,OAAQ,SAAU;AAE1C,QAAM,eAAe,YAAa,CAAE,YAA2B;AAC9D,QAAK,CAAE,WAAY,gBAAgB,SAAS,OAAQ,GAAI;AACvD,sBAAgB,UAAU;AAC1B,cAAS,OAAQ;AAAA,IAClB;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,QAAM,gBAAgB,oBAAC,iBAAc,UAAW,cAAe;AAC/D,SAAO,CAAE,eAAe,IAAK;AAC9B;",
6
+ "names": []
7
+ }
@@ -1,43 +1,25 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useRef } from '@wordpress/element';
5
- /**
6
- * Internal dependencies
7
- */
8
- import useEvent from '../use-event';
9
-
10
- // This is the current implementation of `useResizeObserver`.
11
- //
12
- // The legacy implementation is still supported for backwards compatibility.
13
- // This is achieved by overloading the exported function with both signatures,
14
- // and detecting which API is being used at runtime.
15
- export function useResizeObserver(callback, resizeObserverOptions = {}) {
1
+ import { useRef } from "@wordpress/element";
2
+ import useEvent from "../use-event";
3
+ function useResizeObserver(callback, resizeObserverOptions = {}) {
16
4
  const callbackEvent = useEvent(callback);
17
5
  const observedElementRef = useRef();
18
6
  const resizeObserverRef = useRef();
19
- return useEvent(element => {
20
- var _resizeObserverRef$cu;
7
+ return useEvent((element) => {
21
8
  if (element === observedElementRef.current) {
22
9
  return;
23
10
  }
24
-
25
- // Set up `ResizeObserver`.
26
- (_resizeObserverRef$cu = resizeObserverRef.current) !== null && _resizeObserverRef$cu !== void 0 ? _resizeObserverRef$cu : resizeObserverRef.current = new ResizeObserver(callbackEvent);
27
- const {
28
- current: resizeObserver
29
- } = resizeObserverRef;
30
-
31
- // Unobserve previous element.
11
+ resizeObserverRef.current ??= new ResizeObserver(callbackEvent);
12
+ const { current: resizeObserver } = resizeObserverRef;
32
13
  if (observedElementRef.current) {
33
14
  resizeObserver.unobserve(observedElementRef.current);
34
15
  }
35
-
36
- // Observe new element.
37
16
  observedElementRef.current = element;
38
17
  if (element) {
39
18
  resizeObserver.observe(element, resizeObserverOptions);
40
19
  }
41
20
  });
42
21
  }
43
- //# sourceMappingURL=use-resize-observer.js.map
22
+ export {
23
+ useResizeObserver
24
+ };
25
+ //# sourceMappingURL=use-resize-observer.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useRef","useEvent","useResizeObserver","callback","resizeObserverOptions","callbackEvent","observedElementRef","resizeObserverRef","element","_resizeObserverRef$cu","current","ResizeObserver","resizeObserver","unobserve","observe"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/use-resize-observer.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport useEvent from '../use-event';\n\n// This is the current implementation of `useResizeObserver`.\n//\n// The legacy implementation is still supported for backwards compatibility.\n// This is achieved by overloading the exported function with both signatures,\n// and detecting which API is being used at runtime.\nexport function useResizeObserver< T extends HTMLElement >(\n\tcallback: ResizeObserverCallback,\n\tresizeObserverOptions: ResizeObserverOptions = {}\n): ( element?: T | null ) => void {\n\tconst callbackEvent = useEvent( callback );\n\n\tconst observedElementRef = useRef< T | null >();\n\tconst resizeObserverRef = useRef< ResizeObserver >();\n\treturn useEvent( ( element?: T | null ) => {\n\t\tif ( element === observedElementRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Set up `ResizeObserver`.\n\t\tresizeObserverRef.current ??= new ResizeObserver( callbackEvent );\n\t\tconst { current: resizeObserver } = resizeObserverRef;\n\n\t\t// Unobserve previous element.\n\t\tif ( observedElementRef.current ) {\n\t\t\tresizeObserver.unobserve( observedElementRef.current );\n\t\t}\n\n\t\t// Observe new element.\n\t\tobservedElementRef.current = element;\n\t\tif ( element ) {\n\t\t\tresizeObserver.observe( element, resizeObserverOptions );\n\t\t}\n\t} );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,oBAAoB;AAC3C;AACA;AACA;AACA,OAAOC,QAAQ,MAAM,cAAc;;AAEnC;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,iBAAiBA,CAChCC,QAAgC,EAChCC,qBAA4C,GAAG,CAAC,CAAC,EAChB;EACjC,MAAMC,aAAa,GAAGJ,QAAQ,CAAEE,QAAS,CAAC;EAE1C,MAAMG,kBAAkB,GAAGN,MAAM,CAAa,CAAC;EAC/C,MAAMO,iBAAiB,GAAGP,MAAM,CAAmB,CAAC;EACpD,OAAOC,QAAQ,CAAIO,OAAkB,IAAM;IAAA,IAAAC,qBAAA;IAC1C,IAAKD,OAAO,KAAKF,kBAAkB,CAACI,OAAO,EAAG;MAC7C;IACD;;IAEA;IACA,CAAAD,qBAAA,GAAAF,iBAAiB,CAACG,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAzBF,iBAAiB,CAACG,OAAO,GAAK,IAAIC,cAAc,CAAEN,aAAc,CAAC;IACjE,MAAM;MAAEK,OAAO,EAAEE;IAAe,CAAC,GAAGL,iBAAiB;;IAErD;IACA,IAAKD,kBAAkB,CAACI,OAAO,EAAG;MACjCE,cAAc,CAACC,SAAS,CAAEP,kBAAkB,CAACI,OAAQ,CAAC;IACvD;;IAEA;IACAJ,kBAAkB,CAACI,OAAO,GAAGF,OAAO;IACpC,IAAKA,OAAO,EAAG;MACdI,cAAc,CAACE,OAAO,CAAEN,OAAO,EAAEJ,qBAAsB,CAAC;IACzD;EACD,CAAE,CAAC;AACJ","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-resize-observer/use-resize-observer.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport useEvent from '../use-event';\n\n// This is the current implementation of `useResizeObserver`.\n//\n// The legacy implementation is still supported for backwards compatibility.\n// This is achieved by overloading the exported function with both signatures,\n// and detecting which API is being used at runtime.\nexport function useResizeObserver< T extends HTMLElement >(\n\tcallback: ResizeObserverCallback,\n\tresizeObserverOptions: ResizeObserverOptions = {}\n): ( element?: T | null ) => void {\n\tconst callbackEvent = useEvent( callback );\n\n\tconst observedElementRef = useRef< T | null >();\n\tconst resizeObserverRef = useRef< ResizeObserver >();\n\treturn useEvent( ( element?: T | null ) => {\n\t\tif ( element === observedElementRef.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Set up `ResizeObserver`.\n\t\tresizeObserverRef.current ??= new ResizeObserver( callbackEvent );\n\t\tconst { current: resizeObserver } = resizeObserverRef;\n\n\t\t// Unobserve previous element.\n\t\tif ( observedElementRef.current ) {\n\t\t\tresizeObserver.unobserve( observedElementRef.current );\n\t\t}\n\n\t\t// Observe new element.\n\t\tobservedElementRef.current = element;\n\t\tif ( element ) {\n\t\t\tresizeObserver.observe( element, resizeObserverOptions );\n\t\t}\n\t} );\n}\n"],
5
+ "mappings": "AAGA,SAAS,cAAc;AAIvB,OAAO,cAAc;AAOd,SAAS,kBACf,UACA,wBAA+C,CAAC,GACf;AACjC,QAAM,gBAAgB,SAAU,QAAS;AAEzC,QAAM,qBAAqB,OAAmB;AAC9C,QAAM,oBAAoB,OAAyB;AACnD,SAAO,SAAU,CAAE,YAAwB;AAC1C,QAAK,YAAY,mBAAmB,SAAU;AAC7C;AAAA,IACD;AAGA,sBAAkB,YAAY,IAAI,eAAgB,aAAc;AAChE,UAAM,EAAE,SAAS,eAAe,IAAI;AAGpC,QAAK,mBAAmB,SAAU;AACjC,qBAAe,UAAW,mBAAmB,OAAQ;AAAA,IACtD;AAGA,uBAAmB,UAAU;AAC7B,QAAK,SAAU;AACd,qBAAe,QAAS,SAAS,qBAAsB;AAAA,IACxD;AAAA,EACD,CAAE;AACH;",
6
+ "names": []
7
+ }