@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 +1,7 @@
1
- {"version":3,"names":["_element","require","_useEvent","_interopRequireDefault","useResizeObserver","callback","resizeObserverOptions","callbackEvent","useEvent","observedElementRef","useRef","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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AAPA;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACO,SAASG,iBAAiBA,CAChCC,QAAgC,EAChCC,qBAA4C,GAAG,CAAC,CAAC,EAChB;EACjC,MAAMC,aAAa,GAAG,IAAAC,iBAAQ,EAAEH,QAAS,CAAC;EAE1C,MAAMI,kBAAkB,GAAG,IAAAC,eAAM,EAAa,CAAC;EAC/C,MAAMC,iBAAiB,GAAG,IAAAD,eAAM,EAAmB,CAAC;EACpD,OAAO,IAAAF,iBAAQ,EAAII,OAAkB,IAAM;IAAA,IAAAC,qBAAA;IAC1C,IAAKD,OAAO,KAAKH,kBAAkB,CAACK,OAAO,EAAG;MAC7C;IACD;;IAEA;IACA,CAAAD,qBAAA,GAAAF,iBAAiB,CAACG,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAzBF,iBAAiB,CAACG,OAAO,GAAK,IAAIC,cAAc,CAAER,aAAc,CAAC;IACjE,MAAM;MAAEO,OAAO,EAAEE;IAAe,CAAC,GAAGL,iBAAiB;;IAErD;IACA,IAAKF,kBAAkB,CAACK,OAAO,EAAG;MACjCE,cAAc,CAACC,SAAS,CAAER,kBAAkB,CAACK,OAAQ,CAAC;IACvD;;IAEA;IACAL,kBAAkB,CAACK,OAAO,GAAGF,OAAO;IACpC,IAAKA,OAAO,EAAG;MACdI,cAAc,CAACE,OAAO,CAAEN,OAAO,EAAEN,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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAuB;AAIvB,uBAAqB;AAOd,SAAS,kBACf,UACA,wBAA+C,CAAC,GACf;AACjC,QAAM,oBAAgB,iBAAAA,SAAU,QAAS;AAEzC,QAAM,yBAAqB,uBAAmB;AAC9C,QAAM,wBAAoB,uBAAyB;AACnD,aAAO,iBAAAA,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": ["useEvent"]
7
+ }
@@ -1,94 +1,99 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_state_with_history_exports = {};
20
+ __export(use_state_with_history_exports, {
21
+ default: () => useStateWithHistory
5
22
  });
6
- exports.default = useStateWithHistory;
7
- var _undoManager = require("@wordpress/undo-manager");
8
- var _element = require("@wordpress/element");
9
- /**
10
- * WordPress dependencies
11
- */
12
-
23
+ module.exports = __toCommonJS(use_state_with_history_exports);
24
+ var import_undo_manager = require("@wordpress/undo-manager");
25
+ var import_element = require("@wordpress/element");
13
26
  function undoRedoReducer(state, action) {
14
27
  switch (action.type) {
15
- case 'UNDO':
16
- {
17
- const undoRecord = state.manager.undo();
18
- if (undoRecord) {
19
- return {
20
- ...state,
21
- value: undoRecord[0].changes.prop.from
22
- };
23
- }
24
- return state;
25
- }
26
- case 'REDO':
27
- {
28
- const redoRecord = state.manager.redo();
29
- if (redoRecord) {
30
- return {
31
- ...state,
32
- value: redoRecord[0].changes.prop.to
33
- };
34
- }
35
- return state;
28
+ case "UNDO": {
29
+ const undoRecord = state.manager.undo();
30
+ if (undoRecord) {
31
+ return {
32
+ ...state,
33
+ value: undoRecord[0].changes.prop.from
34
+ };
36
35
  }
37
- case 'RECORD':
38
- {
39
- state.manager.addRecord([{
40
- id: 'object',
41
- changes: {
42
- prop: {
43
- from: state.value,
44
- to: action.value
45
- }
46
- }
47
- }], action.isStaged);
36
+ return state;
37
+ }
38
+ case "REDO": {
39
+ const redoRecord = state.manager.redo();
40
+ if (redoRecord) {
48
41
  return {
49
42
  ...state,
50
- value: action.value
43
+ value: redoRecord[0].changes.prop.to
51
44
  };
52
45
  }
46
+ return state;
47
+ }
48
+ case "RECORD": {
49
+ state.manager.addRecord(
50
+ [
51
+ {
52
+ id: "object",
53
+ changes: {
54
+ prop: { from: state.value, to: action.value }
55
+ }
56
+ }
57
+ ],
58
+ action.isStaged
59
+ );
60
+ return {
61
+ ...state,
62
+ value: action.value
63
+ };
64
+ }
53
65
  }
54
66
  return state;
55
67
  }
56
68
  function initReducer(value) {
57
69
  return {
58
- manager: (0, _undoManager.createUndoManager)(),
70
+ manager: (0, import_undo_manager.createUndoManager)(),
59
71
  value
60
72
  };
61
73
  }
62
-
63
- /**
64
- * useState with undo/redo history.
65
- *
66
- * @param initialValue Initial value.
67
- * @return Value, setValue, hasUndo, hasRedo, undo, redo.
68
- */
69
74
  function useStateWithHistory(initialValue) {
70
- const [state, dispatch] = (0, _element.useReducer)(undoRedoReducer, initialValue, initReducer);
75
+ const [state, dispatch] = (0, import_element.useReducer)(
76
+ undoRedoReducer,
77
+ initialValue,
78
+ initReducer
79
+ );
71
80
  return {
72
81
  value: state.value,
73
- setValue: (0, _element.useCallback)((newValue, isStaged) => {
82
+ setValue: (0, import_element.useCallback)((newValue, isStaged) => {
74
83
  dispatch({
75
- type: 'RECORD',
84
+ type: "RECORD",
76
85
  value: newValue,
77
86
  isStaged
78
87
  });
79
88
  }, []),
80
89
  hasUndo: state.manager.hasUndo(),
81
90
  hasRedo: state.manager.hasRedo(),
82
- undo: (0, _element.useCallback)(() => {
83
- dispatch({
84
- type: 'UNDO'
85
- });
91
+ undo: (0, import_element.useCallback)(() => {
92
+ dispatch({ type: "UNDO" });
86
93
  }, []),
87
- redo: (0, _element.useCallback)(() => {
88
- dispatch({
89
- type: 'REDO'
90
- });
94
+ redo: (0, import_element.useCallback)(() => {
95
+ dispatch({ type: "REDO" });
91
96
  }, [])
92
97
  };
93
98
  }
94
- //# sourceMappingURL=index.js.map
99
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_undoManager","require","_element","undoRedoReducer","state","action","type","undoRecord","manager","undo","value","changes","prop","from","redoRecord","redo","to","addRecord","id","isStaged","initReducer","createUndoManager","useStateWithHistory","initialValue","dispatch","useReducer","setValue","useCallback","newValue","hasUndo","hasRedo"],"sources":["@wordpress/compose/src/hooks/use-state-with-history/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createUndoManager } from '@wordpress/undo-manager';\nimport { useCallback, useReducer } from '@wordpress/element';\nimport type { UndoManager } from '@wordpress/undo-manager';\n\ntype UndoRedoState< T > = {\n\tmanager: UndoManager< T >;\n\tvalue: T;\n};\n\nfunction undoRedoReducer< T >(\n\tstate: UndoRedoState< T >,\n\taction:\n\t\t| { type: 'UNDO' }\n\t\t| { type: 'REDO' }\n\t\t| { type: 'RECORD'; value: T; isStaged: boolean }\n): UndoRedoState< T > {\n\tswitch ( action.type ) {\n\t\tcase 'UNDO': {\n\t\t\tconst undoRecord = state.manager.undo();\n\t\t\tif ( undoRecord ) {\n\t\t\t\treturn {\n\t\t\t\t\t...state,\n\t\t\t\t\tvalue: undoRecord[ 0 ].changes.prop.from,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn state;\n\t\t}\n\t\tcase 'REDO': {\n\t\t\tconst redoRecord = state.manager.redo();\n\t\t\tif ( redoRecord ) {\n\t\t\t\treturn {\n\t\t\t\t\t...state,\n\t\t\t\t\tvalue: redoRecord[ 0 ].changes.prop.to,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn state;\n\t\t}\n\t\tcase 'RECORD': {\n\t\t\tstate.manager.addRecord(\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'object',\n\t\t\t\t\t\tchanges: {\n\t\t\t\t\t\t\tprop: { from: state.value, to: action.value },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\taction.isStaged\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tvalue: action.value,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n\nfunction initReducer< T >( value: T ) {\n\treturn {\n\t\tmanager: createUndoManager(),\n\t\tvalue,\n\t};\n}\n\n/**\n * useState with undo/redo history.\n *\n * @param initialValue Initial value.\n * @return Value, setValue, hasUndo, hasRedo, undo, redo.\n */\nexport default function useStateWithHistory< T >( initialValue: T ) {\n\tconst [ state, dispatch ] = useReducer(\n\t\tundoRedoReducer,\n\t\tinitialValue,\n\t\tinitReducer\n\t);\n\n\treturn {\n\t\tvalue: state.value,\n\t\tsetValue: useCallback( ( newValue: T, isStaged: boolean ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'RECORD',\n\t\t\t\tvalue: newValue,\n\t\t\t\tisStaged,\n\t\t\t} );\n\t\t}, [] ),\n\t\thasUndo: state.manager.hasUndo(),\n\t\thasRedo: state.manager.hasRedo(),\n\t\tundo: useCallback( () => {\n\t\t\tdispatch( { type: 'UNDO' } );\n\t\t}, [] ),\n\t\tredo: useCallback( () => {\n\t\t\tdispatch( { type: 'REDO' } );\n\t\t}, [] ),\n\t};\n}\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAUA,SAASE,eAAeA,CACvBC,KAAyB,EACzBC,MAGkD,EAC7B;EACrB,QAASA,MAAM,CAACC,IAAI;IACnB,KAAK,MAAM;MAAE;QACZ,MAAMC,UAAU,GAAGH,KAAK,CAACI,OAAO,CAACC,IAAI,CAAC,CAAC;QACvC,IAAKF,UAAU,EAAG;UACjB,OAAO;YACN,GAAGH,KAAK;YACRM,KAAK,EAAEH,UAAU,CAAE,CAAC,CAAE,CAACI,OAAO,CAACC,IAAI,CAACC;UACrC,CAAC;QACF;QACA,OAAOT,KAAK;MACb;IACA,KAAK,MAAM;MAAE;QACZ,MAAMU,UAAU,GAAGV,KAAK,CAACI,OAAO,CAACO,IAAI,CAAC,CAAC;QACvC,IAAKD,UAAU,EAAG;UACjB,OAAO;YACN,GAAGV,KAAK;YACRM,KAAK,EAAEI,UAAU,CAAE,CAAC,CAAE,CAACH,OAAO,CAACC,IAAI,CAACI;UACrC,CAAC;QACF;QACA,OAAOZ,KAAK;MACb;IACA,KAAK,QAAQ;MAAE;QACdA,KAAK,CAACI,OAAO,CAACS,SAAS,CACtB,CACC;UACCC,EAAE,EAAE,QAAQ;UACZP,OAAO,EAAE;YACRC,IAAI,EAAE;cAAEC,IAAI,EAAET,KAAK,CAACM,KAAK;cAAEM,EAAE,EAAEX,MAAM,CAACK;YAAM;UAC7C;QACD,CAAC,CACD,EACDL,MAAM,CAACc,QACR,CAAC;QACD,OAAO;UACN,GAAGf,KAAK;UACRM,KAAK,EAAEL,MAAM,CAACK;QACf,CAAC;MACF;EACD;EAEA,OAAON,KAAK;AACb;AAEA,SAASgB,WAAWA,CAAOV,KAAQ,EAAG;EACrC,OAAO;IACNF,OAAO,EAAE,IAAAa,8BAAiB,EAAC,CAAC;IAC5BX;EACD,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACe,SAASY,mBAAmBA,CAAOC,YAAe,EAAG;EACnE,MAAM,CAAEnB,KAAK,EAAEoB,QAAQ,CAAE,GAAG,IAAAC,mBAAU,EACrCtB,eAAe,EACfoB,YAAY,EACZH,WACD,CAAC;EAED,OAAO;IACNV,KAAK,EAAEN,KAAK,CAACM,KAAK;IAClBgB,QAAQ,EAAE,IAAAC,oBAAW,EAAE,CAAEC,QAAW,EAAET,QAAiB,KAAM;MAC5DK,QAAQ,CAAE;QACTlB,IAAI,EAAE,QAAQ;QACdI,KAAK,EAAEkB,QAAQ;QACfT;MACD,CAAE,CAAC;IACJ,CAAC,EAAE,EAAG,CAAC;IACPU,OAAO,EAAEzB,KAAK,CAACI,OAAO,CAACqB,OAAO,CAAC,CAAC;IAChCC,OAAO,EAAE1B,KAAK,CAACI,OAAO,CAACsB,OAAO,CAAC,CAAC;IAChCrB,IAAI,EAAE,IAAAkB,oBAAW,EAAE,MAAM;MACxBH,QAAQ,CAAE;QAAElB,IAAI,EAAE;MAAO,CAAE,CAAC;IAC7B,CAAC,EAAE,EAAG,CAAC;IACPS,IAAI,EAAE,IAAAY,oBAAW,EAAE,MAAM;MACxBH,QAAQ,CAAE;QAAElB,IAAI,EAAE;MAAO,CAAE,CAAC;IAC7B,CAAC,EAAE,EAAG;EACP,CAAC;AACF","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-state-with-history/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createUndoManager } from '@wordpress/undo-manager';\nimport { useCallback, useReducer } from '@wordpress/element';\nimport type { UndoManager } from '@wordpress/undo-manager';\n\ntype UndoRedoState< T > = {\n\tmanager: UndoManager< T >;\n\tvalue: T;\n};\n\nfunction undoRedoReducer< T >(\n\tstate: UndoRedoState< T >,\n\taction:\n\t\t| { type: 'UNDO' }\n\t\t| { type: 'REDO' }\n\t\t| { type: 'RECORD'; value: T; isStaged: boolean }\n): UndoRedoState< T > {\n\tswitch ( action.type ) {\n\t\tcase 'UNDO': {\n\t\t\tconst undoRecord = state.manager.undo();\n\t\t\tif ( undoRecord ) {\n\t\t\t\treturn {\n\t\t\t\t\t...state,\n\t\t\t\t\tvalue: undoRecord[ 0 ].changes.prop.from,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn state;\n\t\t}\n\t\tcase 'REDO': {\n\t\t\tconst redoRecord = state.manager.redo();\n\t\t\tif ( redoRecord ) {\n\t\t\t\treturn {\n\t\t\t\t\t...state,\n\t\t\t\t\tvalue: redoRecord[ 0 ].changes.prop.to,\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn state;\n\t\t}\n\t\tcase 'RECORD': {\n\t\t\tstate.manager.addRecord(\n\t\t\t\t[\n\t\t\t\t\t{\n\t\t\t\t\t\tid: 'object',\n\t\t\t\t\t\tchanges: {\n\t\t\t\t\t\t\tprop: { from: state.value, to: action.value },\n\t\t\t\t\t\t},\n\t\t\t\t\t},\n\t\t\t\t],\n\t\t\t\taction.isStaged\n\t\t\t);\n\t\t\treturn {\n\t\t\t\t...state,\n\t\t\t\tvalue: action.value,\n\t\t\t};\n\t\t}\n\t}\n\n\treturn state;\n}\n\nfunction initReducer< T >( value: T ) {\n\treturn {\n\t\tmanager: createUndoManager(),\n\t\tvalue,\n\t};\n}\n\n/**\n * useState with undo/redo history.\n *\n * @param initialValue Initial value.\n * @return Value, setValue, hasUndo, hasRedo, undo, redo.\n */\nexport default function useStateWithHistory< T >( initialValue: T ) {\n\tconst [ state, dispatch ] = useReducer(\n\t\tundoRedoReducer,\n\t\tinitialValue,\n\t\tinitReducer\n\t);\n\n\treturn {\n\t\tvalue: state.value,\n\t\tsetValue: useCallback( ( newValue: T, isStaged: boolean ) => {\n\t\t\tdispatch( {\n\t\t\t\ttype: 'RECORD',\n\t\t\t\tvalue: newValue,\n\t\t\t\tisStaged,\n\t\t\t} );\n\t\t}, [] ),\n\t\thasUndo: state.manager.hasUndo(),\n\t\thasRedo: state.manager.hasRedo(),\n\t\tundo: useCallback( () => {\n\t\t\tdispatch( { type: 'UNDO' } );\n\t\t}, [] ),\n\t\tredo: useCallback( () => {\n\t\t\tdispatch( { type: 'REDO' } );\n\t\t}, [] ),\n\t};\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAkC;AAClC,qBAAwC;AAQxC,SAAS,gBACR,OACA,QAIqB;AACrB,UAAS,OAAO,MAAO;AAAA,IACtB,KAAK,QAAQ;AACZ,YAAM,aAAa,MAAM,QAAQ,KAAK;AACtC,UAAK,YAAa;AACjB,eAAO;AAAA,UACN,GAAG;AAAA,UACH,OAAO,WAAY,CAAE,EAAE,QAAQ,KAAK;AAAA,QACrC;AAAA,MACD;AACA,aAAO;AAAA,IACR;AAAA,IACA,KAAK,QAAQ;AACZ,YAAM,aAAa,MAAM,QAAQ,KAAK;AACtC,UAAK,YAAa;AACjB,eAAO;AAAA,UACN,GAAG;AAAA,UACH,OAAO,WAAY,CAAE,EAAE,QAAQ,KAAK;AAAA,QACrC;AAAA,MACD;AACA,aAAO;AAAA,IACR;AAAA,IACA,KAAK,UAAU;AACd,YAAM,QAAQ;AAAA,QACb;AAAA,UACC;AAAA,YACC,IAAI;AAAA,YACJ,SAAS;AAAA,cACR,MAAM,EAAE,MAAM,MAAM,OAAO,IAAI,OAAO,MAAM;AAAA,YAC7C;AAAA,UACD;AAAA,QACD;AAAA,QACA,OAAO;AAAA,MACR;AACA,aAAO;AAAA,QACN,GAAG;AAAA,QACH,OAAO,OAAO;AAAA,MACf;AAAA,IACD;AAAA,EACD;AAEA,SAAO;AACR;AAEA,SAAS,YAAkB,OAAW;AACrC,SAAO;AAAA,IACN,aAAS,uCAAkB;AAAA,IAC3B;AAAA,EACD;AACD;AAQe,SAAR,oBAA2C,cAAkB;AACnE,QAAM,CAAE,OAAO,QAAS,QAAI;AAAA,IAC3B;AAAA,IACA;AAAA,IACA;AAAA,EACD;AAEA,SAAO;AAAA,IACN,OAAO,MAAM;AAAA,IACb,cAAU,4BAAa,CAAE,UAAa,aAAuB;AAC5D,eAAU;AAAA,QACT,MAAM;AAAA,QACN,OAAO;AAAA,QACP;AAAA,MACD,CAAE;AAAA,IACH,GAAG,CAAC,CAAE;AAAA,IACN,SAAS,MAAM,QAAQ,QAAQ;AAAA,IAC/B,SAAS,MAAM,QAAQ,QAAQ;AAAA,IAC/B,UAAM,4BAAa,MAAM;AACxB,eAAU,EAAE,MAAM,OAAO,CAAE;AAAA,IAC5B,GAAG,CAAC,CAAE;AAAA,IACN,UAAM,4BAAa,MAAM;AACxB,eAAU,EAAE,MAAM,OAAO,CAAE;AAAA,IAC5B,GAAG,CAAC,CAAE;AAAA,EACP;AACD;",
6
+ "names": []
7
+ }
@@ -1,42 +1,35 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_throttle_exports = {};
20
+ __export(use_throttle_exports, {
21
+ default: () => useThrottle
5
22
  });
6
- exports.default = useThrottle;
7
- var _useMemoOne = require("use-memo-one");
8
- var _element = require("@wordpress/element");
9
- var _throttle = require("../../utils/throttle");
10
- /**
11
- * External dependencies
12
- */
13
-
14
- /**
15
- * WordPress dependencies
16
- */
17
-
18
- /**
19
- * Internal dependencies
20
- */
21
-
22
- /**
23
- * Throttles a function similar to Lodash's `throttle`. A new throttled function will
24
- * be returned and any scheduled calls cancelled if any of the arguments change,
25
- * including the function to throttle, so please wrap functions created on
26
- * render in components in `useCallback`.
27
- *
28
- * @see https://lodash.com/docs/4#throttle
29
- *
30
- * @template {(...args: any[]) => void} TFunc
31
- *
32
- * @param {TFunc} fn The function to throttle.
33
- * @param {number} [wait] The number of milliseconds to throttle invocations to.
34
- * @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.
35
- * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.
36
- */
23
+ module.exports = __toCommonJS(use_throttle_exports);
24
+ var import_use_memo_one = require("use-memo-one");
25
+ var import_element = require("@wordpress/element");
26
+ var import_throttle = require("../../utils/throttle");
37
27
  function useThrottle(fn, wait, options) {
38
- const throttled = (0, _useMemoOne.useMemoOne)(() => (0, _throttle.throttle)(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]);
39
- (0, _element.useEffect)(() => () => throttled.cancel(), [throttled]);
28
+ const throttled = (0, import_use_memo_one.useMemoOne)(
29
+ () => (0, import_throttle.throttle)(fn, wait ?? 0, options),
30
+ [fn, wait, options]
31
+ );
32
+ (0, import_element.useEffect)(() => () => throttled.cancel(), [throttled]);
40
33
  return throttled;
41
34
  }
42
- //# sourceMappingURL=index.js.map
35
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_useMemoOne","require","_element","_throttle","useThrottle","fn","wait","options","throttled","useMemoOne","throttle","useEffect","cancel"],"sources":["@wordpress/compose/src/hooks/use-throttle/index.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { throttle } from '../../utils/throttle';\n\n/**\n * Throttles a function similar to Lodash's `throttle`. A new throttled function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to throttle, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#throttle\n *\n * @template {(...args: any[]) => void} TFunc\n *\n * @param {TFunc} fn The function to throttle.\n * @param {number} [wait] The number of milliseconds to throttle invocations to.\n * @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.\n * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.\n */\nexport default function useThrottle( fn, wait, options ) {\n\tconst throttled = useMemoOne(\n\t\t() => throttle( fn, wait ?? 0, options ),\n\t\t[ fn, wait, options ]\n\t);\n\tuseEffect( () => () => throttled.cancel(), [ throttled ] );\n\treturn throttled;\n}\n"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,SAAA,GAAAF,OAAA;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,WAAWA,CAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAO,EAAG;EACxD,MAAMC,SAAS,GAAG,IAAAC,sBAAU,EAC3B,MAAM,IAAAC,kBAAQ,EAAEL,EAAE,EAAEC,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAI,CAAC,EAAEC,OAAQ,CAAC,EACxC,CAAEF,EAAE,EAAEC,IAAI,EAAEC,OAAO,CACpB,CAAC;EACD,IAAAI,kBAAS,EAAE,MAAM,MAAMH,SAAS,CAACI,MAAM,CAAC,CAAC,EAAE,CAAEJ,SAAS,CAAG,CAAC;EAC1D,OAAOA,SAAS;AACjB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-throttle/index.js"],
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { throttle } from '../../utils/throttle';\n\n/**\n * Throttles a function similar to Lodash's `throttle`. A new throttled function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to throttle, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#throttle\n *\n * @template {(...args: any[]) => void} TFunc\n *\n * @param {TFunc} fn The function to throttle.\n * @param {number} [wait] The number of milliseconds to throttle invocations to.\n * @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.\n * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.\n */\nexport default function useThrottle( fn, wait, options ) {\n\tconst throttled = useMemoOne(\n\t\t() => throttle( fn, wait ?? 0, options ),\n\t\t[ fn, wait, options ]\n\t);\n\tuseEffect( () => () => throttled.cancel(), [ throttled ] );\n\treturn throttled;\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA2B;AAK3B,qBAA0B;AAK1B,sBAAyB;AAiBV,SAAR,YAA8B,IAAI,MAAM,SAAU;AACxD,QAAM,gBAAY;AAAA,IACjB,UAAM,0BAAU,IAAI,QAAQ,GAAG,OAAQ;AAAA,IACvC,CAAE,IAAI,MAAM,OAAQ;AAAA,EACrB;AACA,gCAAW,MAAM,MAAM,UAAU,OAAO,GAAG,CAAE,SAAU,CAAE;AACzD,SAAO;AACR;",
6
+ "names": []
7
+ }
@@ -1,31 +1,38 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var use_viewport_match_exports = {};
30
+ __export(use_viewport_match_exports, {
31
+ default: () => use_viewport_match_default
6
32
  });
7
- exports.default = void 0;
8
- var _element = require("@wordpress/element");
9
- var _useMediaQuery = _interopRequireDefault(require("../use-media-query"));
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- /**
19
- * @typedef {"xhuge" | "huge" | "wide" | "xlarge" | "large" | "medium" | "small" | "mobile"} WPBreakpoint
20
- */
21
-
22
- /**
23
- * Hash of breakpoint names with pixel width at which it becomes effective.
24
- *
25
- * @see _breakpoints.scss
26
- *
27
- * @type {Record<WPBreakpoint, number>}
28
- */
33
+ module.exports = __toCommonJS(use_viewport_match_exports);
34
+ var import_element = require("@wordpress/element");
35
+ var import_use_media_query = __toESM(require("../use-media-query"));
29
36
  const BREAKPOINTS = {
30
37
  xhuge: 1920,
31
38
  huge: 1440,
@@ -36,57 +43,31 @@ const BREAKPOINTS = {
36
43
  small: 600,
37
44
  mobile: 480
38
45
  };
39
-
40
- /**
41
- * @typedef {">=" | "<"} WPViewportOperator
42
- */
43
-
44
- /**
45
- * Object mapping media query operators to the condition to be used.
46
- *
47
- * @type {Record<WPViewportOperator, string>}
48
- */
49
46
  const CONDITIONS = {
50
- '>=': 'min-width',
51
- '<': 'max-width'
47
+ ">=": "min-width",
48
+ "<": "max-width"
52
49
  };
53
-
54
- /**
55
- * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.
56
- *
57
- * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}
58
- */
59
50
  const OPERATOR_EVALUATORS = {
60
- '>=': (breakpointValue, width) => width >= breakpointValue,
61
- '<': (breakpointValue, width) => width < breakpointValue
51
+ ">=": (breakpointValue, width) => width >= breakpointValue,
52
+ "<": (breakpointValue, width) => width < breakpointValue
62
53
  };
63
- const ViewportMatchWidthContext = (0, _element.createContext)(/** @type {null | number} */null);
64
- ViewportMatchWidthContext.displayName = 'ViewportMatchWidthContext';
65
-
66
- /**
67
- * Returns true if the viewport matches the given query, or false otherwise.
68
- *
69
- * @param {WPBreakpoint} breakpoint Breakpoint size name.
70
- * @param {WPViewportOperator} [operator=">="] Viewport operator.
71
- *
72
- * @example
73
- *
74
- * ```js
75
- * useViewportMatch( 'huge', '<' );
76
- * useViewportMatch( 'medium' );
77
- * ```
78
- *
79
- * @return {boolean} Whether viewport matches query.
80
- */
81
- const useViewportMatch = (breakpoint, operator = '>=') => {
82
- const simulatedWidth = (0, _element.useContext)(ViewportMatchWidthContext);
54
+ const ViewportMatchWidthContext = (0, import_element.createContext)(
55
+ /** @type {null | number} */
56
+ null
57
+ );
58
+ ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext";
59
+ const useViewportMatch = (breakpoint, operator = ">=") => {
60
+ const simulatedWidth = (0, import_element.useContext)(ViewportMatchWidthContext);
83
61
  const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
84
- const mediaQueryResult = (0, _useMediaQuery.default)(mediaQuery || undefined);
62
+ const mediaQueryResult = (0, import_use_media_query.default)(mediaQuery || void 0);
85
63
  if (simulatedWidth) {
86
- return OPERATOR_EVALUATORS[operator](BREAKPOINTS[breakpoint], simulatedWidth);
64
+ return OPERATOR_EVALUATORS[operator](
65
+ BREAKPOINTS[breakpoint],
66
+ simulatedWidth
67
+ );
87
68
  }
88
69
  return mediaQueryResult;
89
70
  };
90
71
  useViewportMatch.__experimentalWidthProvider = ViewportMatchWidthContext.Provider;
91
- var _default = exports.default = useViewportMatch;
92
- //# sourceMappingURL=index.js.map
72
+ var use_viewport_match_default = useViewportMatch;
73
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_useMediaQuery","_interopRequireDefault","BREAKPOINTS","xhuge","huge","wide","xlarge","large","medium","small","mobile","CONDITIONS","OPERATOR_EVALUATORS",">=","breakpointValue","width","<","ViewportMatchWidthContext","createContext","displayName","useViewportMatch","breakpoint","operator","simulatedWidth","useContext","mediaQuery","mediaQueryResult","useMediaQuery","undefined","__experimentalWidthProvider","Provider","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-viewport-match/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * @typedef {\"xhuge\" | \"huge\" | \"wide\" | \"xlarge\" | \"large\" | \"medium\" | \"small\" | \"mobile\"} WPBreakpoint\n */\n\n/**\n * Hash of breakpoint names with pixel width at which it becomes effective.\n *\n * @see _breakpoints.scss\n *\n * @type {Record<WPBreakpoint, number>}\n */\nconst BREAKPOINTS = {\n\txhuge: 1920,\n\thuge: 1440,\n\twide: 1280,\n\txlarge: 1080,\n\tlarge: 960,\n\tmedium: 782,\n\tsmall: 600,\n\tmobile: 480,\n};\n\n/**\n * @typedef {\">=\" | \"<\"} WPViewportOperator\n */\n\n/**\n * Object mapping media query operators to the condition to be used.\n *\n * @type {Record<WPViewportOperator, string>}\n */\nconst CONDITIONS = {\n\t'>=': 'min-width',\n\t'<': 'max-width',\n};\n\n/**\n * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.\n *\n * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}\n */\nconst OPERATOR_EVALUATORS = {\n\t'>=': ( breakpointValue, width ) => width >= breakpointValue,\n\t'<': ( breakpointValue, width ) => width < breakpointValue,\n};\n\nconst ViewportMatchWidthContext = createContext(\n\t/** @type {null | number} */ ( null )\n);\nViewportMatchWidthContext.displayName = 'ViewportMatchWidthContext';\n\n/**\n * Returns true if the viewport matches the given query, or false otherwise.\n *\n * @param {WPBreakpoint} breakpoint Breakpoint size name.\n * @param {WPViewportOperator} [operator=\">=\"] Viewport operator.\n *\n * @example\n *\n * ```js\n * useViewportMatch( 'huge', '<' );\n * useViewportMatch( 'medium' );\n * ```\n *\n * @return {boolean} Whether viewport matches query.\n */\nconst useViewportMatch = ( breakpoint, operator = '>=' ) => {\n\tconst simulatedWidth = useContext( ViewportMatchWidthContext );\n\tconst mediaQuery =\n\t\t! simulatedWidth &&\n\t\t`(${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;\n\tconst mediaQueryResult = useMediaQuery( mediaQuery || undefined );\n\tif ( simulatedWidth ) {\n\t\treturn OPERATOR_EVALUATORS[ operator ](\n\t\t\tBREAKPOINTS[ breakpoint ],\n\t\t\tsimulatedWidth\n\t\t);\n\t}\n\treturn mediaQueryResult;\n};\n\nuseViewportMatch.__experimentalWidthProvider =\n\tViewportMatchWidthContext.Provider;\n\nexport default useViewportMatch;\n"],"mappings":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAKA,IAAAC,cAAA,GAAAC,sBAAA,CAAAF,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMG,WAAW,GAAG;EACnBC,KAAK,EAAE,IAAI;EACXC,IAAI,EAAE,IAAI;EACVC,IAAI,EAAE,IAAI;EACVC,MAAM,EAAE,IAAI;EACZC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE,GAAG;EACXC,KAAK,EAAE,GAAG;EACVC,MAAM,EAAE;AACT,CAAC;;AAED;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,MAAMC,UAAU,GAAG;EAClB,IAAI,EAAE,WAAW;EACjB,GAAG,EAAE;AACN,CAAC;;AAED;AACA;AACA;AACA;AACA;AACA,MAAMC,mBAAmB,GAAG;EAC3B,IAAI,EAAEC,CAAEC,eAAe,EAAEC,KAAK,KAAMA,KAAK,IAAID,eAAe;EAC5D,GAAG,EAAEE,CAAEF,eAAe,EAAEC,KAAK,KAAMA,KAAK,GAAGD;AAC5C,CAAC;AAED,MAAMG,yBAAyB,GAAG,IAAAC,sBAAa,EAC9C,4BAA+B,IAChC,CAAC;AACDD,yBAAyB,CAACE,WAAW,GAAG,2BAA2B;;AAEnE;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,gBAAgB,GAAGA,CAAEC,UAAU,EAAEC,QAAQ,GAAG,IAAI,KAAM;EAC3D,MAAMC,cAAc,GAAG,IAAAC,mBAAU,EAAEP,yBAA0B,CAAC;EAC9D,MAAMQ,UAAU,GACf,CAAEF,cAAc,IAChB,IAAKZ,UAAU,CAAEW,QAAQ,CAAE,KAAOpB,WAAW,CAAEmB,UAAU,CAAE,KAAM;EAClE,MAAMK,gBAAgB,GAAG,IAAAC,sBAAa,EAAEF,UAAU,IAAIG,SAAU,CAAC;EACjE,IAAKL,cAAc,EAAG;IACrB,OAAOX,mBAAmB,CAAEU,QAAQ,CAAE,CACrCpB,WAAW,CAAEmB,UAAU,CAAE,EACzBE,cACD,CAAC;EACF;EACA,OAAOG,gBAAgB;AACxB,CAAC;AAEDN,gBAAgB,CAACS,2BAA2B,GAC3CZ,yBAAyB,CAACa,QAAQ;AAAC,IAAAC,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAErBb,gBAAgB","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-viewport-match/index.js"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * @typedef {\"xhuge\" | \"huge\" | \"wide\" | \"xlarge\" | \"large\" | \"medium\" | \"small\" | \"mobile\"} WPBreakpoint\n */\n\n/**\n * Hash of breakpoint names with pixel width at which it becomes effective.\n *\n * @see _breakpoints.scss\n *\n * @type {Record<WPBreakpoint, number>}\n */\nconst BREAKPOINTS = {\n\txhuge: 1920,\n\thuge: 1440,\n\twide: 1280,\n\txlarge: 1080,\n\tlarge: 960,\n\tmedium: 782,\n\tsmall: 600,\n\tmobile: 480,\n};\n\n/**\n * @typedef {\">=\" | \"<\"} WPViewportOperator\n */\n\n/**\n * Object mapping media query operators to the condition to be used.\n *\n * @type {Record<WPViewportOperator, string>}\n */\nconst CONDITIONS = {\n\t'>=': 'min-width',\n\t'<': 'max-width',\n};\n\n/**\n * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.\n *\n * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}\n */\nconst OPERATOR_EVALUATORS = {\n\t'>=': ( breakpointValue, width ) => width >= breakpointValue,\n\t'<': ( breakpointValue, width ) => width < breakpointValue,\n};\n\nconst ViewportMatchWidthContext = createContext(\n\t/** @type {null | number} */ ( null )\n);\nViewportMatchWidthContext.displayName = 'ViewportMatchWidthContext';\n\n/**\n * Returns true if the viewport matches the given query, or false otherwise.\n *\n * @param {WPBreakpoint} breakpoint Breakpoint size name.\n * @param {WPViewportOperator} [operator=\">=\"] Viewport operator.\n *\n * @example\n *\n * ```js\n * useViewportMatch( 'huge', '<' );\n * useViewportMatch( 'medium' );\n * ```\n *\n * @return {boolean} Whether viewport matches query.\n */\nconst useViewportMatch = ( breakpoint, operator = '>=' ) => {\n\tconst simulatedWidth = useContext( ViewportMatchWidthContext );\n\tconst mediaQuery =\n\t\t! simulatedWidth &&\n\t\t`(${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;\n\tconst mediaQueryResult = useMediaQuery( mediaQuery || undefined );\n\tif ( simulatedWidth ) {\n\t\treturn OPERATOR_EVALUATORS[ operator ](\n\t\t\tBREAKPOINTS[ breakpoint ],\n\t\t\tsimulatedWidth\n\t\t);\n\t}\n\treturn mediaQueryResult;\n};\n\nuseViewportMatch.__experimentalWidthProvider =\n\tViewportMatchWidthContext.Provider;\n\nexport default useViewportMatch;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0C;AAK1C,6BAA0B;AAa1B,MAAM,cAAc;AAAA,EACnB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AACT;AAWA,MAAM,aAAa;AAAA,EAClB,MAAM;AAAA,EACN,KAAK;AACN;AAOA,MAAM,sBAAsB;AAAA,EAC3B,MAAM,CAAE,iBAAiB,UAAW,SAAS;AAAA,EAC7C,KAAK,CAAE,iBAAiB,UAAW,QAAQ;AAC5C;AAEA,MAAM,gCAA4B;AAAA;AAAA,EACF;AAChC;AACA,0BAA0B,cAAc;AAiBxC,MAAM,mBAAmB,CAAE,YAAY,WAAW,SAAU;AAC3D,QAAM,qBAAiB,2BAAY,yBAA0B;AAC7D,QAAM,aACL,CAAE,kBACF,IAAK,WAAY,QAAS,CAAE,KAAM,YAAa,UAAW,CAAE;AAC7D,QAAM,uBAAmB,uBAAAA,SAAe,cAAc,MAAU;AAChE,MAAK,gBAAiB;AACrB,WAAO,oBAAqB,QAAS;AAAA,MACpC,YAAa,UAAW;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA,iBAAiB,8BAChB,0BAA0B;AAE3B,IAAO,6BAAQ;",
6
+ "names": ["useMediaQuery"]
7
+ }
@@ -1,45 +1,55 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var use_warn_on_change_exports = {};
30
+ __export(use_warn_on_change_exports, {
31
+ default: () => use_warn_on_change_default
6
32
  });
7
- exports.default = void 0;
8
- var _usePrevious = _interopRequireDefault(require("../use-previous"));
9
- /**
10
- * Internal dependencies
11
- */
12
-
13
- // Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in this case
14
- // but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript
15
- /* eslint-disable jsdoc/check-types */
16
- /**
17
- * Hook that performs a shallow comparison between the preview value of an object
18
- * and the new one, if there's a difference, it prints it to the console.
19
- * this is useful in performance related work, to check why a component re-renders.
20
- *
21
- * @example
22
- *
23
- * ```jsx
24
- * function MyComponent(props) {
25
- * useWarnOnChange(props);
26
- *
27
- * return "Something";
28
- * }
29
- * ```
30
- *
31
- * @param {object} object Object which changes to compare.
32
- * @param {string} prefix Just a prefix to show when console logging.
33
- */
34
- function useWarnOnChange(object, prefix = 'Change detection') {
35
- const previousValues = (0, _usePrevious.default)(object);
36
- Object.entries(previousValues !== null && previousValues !== void 0 ? previousValues : []).forEach(([key, value]) => {
37
- if (value !== object[(/** @type {keyof typeof object} */key)]) {
38
- // eslint-disable-next-line no-console
39
- console.warn(`${prefix}: ${key} key changed:`, value, object[(/** @type {keyof typeof object} */key)]
40
- /* eslint-enable jsdoc/check-types */);
33
+ module.exports = __toCommonJS(use_warn_on_change_exports);
34
+ var import_use_previous = __toESM(require("../use-previous"));
35
+ function useWarnOnChange(object, prefix = "Change detection") {
36
+ const previousValues = (0, import_use_previous.default)(object);
37
+ Object.entries(previousValues ?? []).forEach(([key, value]) => {
38
+ if (value !== object[
39
+ /** @type {keyof typeof object} */
40
+ key
41
+ ]) {
42
+ console.warn(
43
+ `${prefix}: ${key} key changed:`,
44
+ value,
45
+ object[
46
+ /** @type {keyof typeof object} */
47
+ key
48
+ ]
49
+ /* eslint-enable jsdoc/check-types */
50
+ );
41
51
  }
42
52
  });
43
53
  }
44
- var _default = exports.default = useWarnOnChange;
45
- //# sourceMappingURL=index.js.map
54
+ var use_warn_on_change_default = useWarnOnChange;
55
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_usePrevious","_interopRequireDefault","require","useWarnOnChange","object","prefix","previousValues","usePrevious","Object","entries","forEach","key","value","console","warn","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-warn-on-change/index.js"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in this case\n// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript\n/* eslint-disable jsdoc/check-types */\n/**\n * Hook that performs a shallow comparison between the preview value of an object\n * and the new one, if there's a difference, it prints it to the console.\n * this is useful in performance related work, to check why a component re-renders.\n *\n * @example\n *\n * ```jsx\n * function MyComponent(props) {\n * useWarnOnChange(props);\n *\n * return \"Something\";\n * }\n * ```\n *\n * @param {object} object Object which changes to compare.\n * @param {string} prefix Just a prefix to show when console logging.\n */\nfunction useWarnOnChange( object, prefix = 'Change detection' ) {\n\tconst previousValues = usePrevious( object );\n\n\tObject.entries( previousValues ?? [] ).forEach( ( [ key, value ] ) => {\n\t\tif ( value !== object[ /** @type {keyof typeof object} */ ( key ) ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`${ prefix }: ${ key } key changed:`,\n\t\t\t\tvalue,\n\t\t\t\tobject[ /** @type {keyof typeof object} */ ( key ) ]\n\t\t\t\t/* eslint-enable jsdoc/check-types */\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport default useWarnOnChange;\n"],"mappings":";;;;;;;AAGA,IAAAA,YAAA,GAAAC,sBAAA,CAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAAEC,MAAM,EAAEC,MAAM,GAAG,kBAAkB,EAAG;EAC/D,MAAMC,cAAc,GAAG,IAAAC,oBAAW,EAAEH,MAAO,CAAC;EAE5CI,MAAM,CAACC,OAAO,CAAEH,cAAc,aAAdA,cAAc,cAAdA,cAAc,GAAI,EAAG,CAAC,CAACI,OAAO,CAAE,CAAE,CAAEC,GAAG,EAAEC,KAAK,CAAE,KAAM;IACrE,IAAKA,KAAK,KAAKR,MAAM,EAAE,kCAAqCO,GAAG,EAAI,EAAG;MACrE;MACAE,OAAO,CAACC,IAAI,CACX,GAAIT,MAAM,KAAOM,GAAG,eAAgB,EACpCC,KAAK,EACLR,MAAM,EAAE,kCAAqCO,GAAG;MAChD,qCACD,CAAC;IACF;EACD,CAAE,CAAC;AACJ;AAAC,IAAAI,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcd,eAAe","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/use-warn-on-change/index.js"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n// Disable reason: Object and object are distinctly different types in TypeScript and we mean the lowercase object in this case\n// but eslint wants to force us to use `Object`. See https://stackoverflow.com/questions/49464634/difference-between-object-and-object-in-typescript\n/* eslint-disable jsdoc/check-types */\n/**\n * Hook that performs a shallow comparison between the preview value of an object\n * and the new one, if there's a difference, it prints it to the console.\n * this is useful in performance related work, to check why a component re-renders.\n *\n * @example\n *\n * ```jsx\n * function MyComponent(props) {\n * useWarnOnChange(props);\n *\n * return \"Something\";\n * }\n * ```\n *\n * @param {object} object Object which changes to compare.\n * @param {string} prefix Just a prefix to show when console logging.\n */\nfunction useWarnOnChange( object, prefix = 'Change detection' ) {\n\tconst previousValues = usePrevious( object );\n\n\tObject.entries( previousValues ?? [] ).forEach( ( [ key, value ] ) => {\n\t\tif ( value !== object[ /** @type {keyof typeof object} */ ( key ) ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`${ prefix }: ${ key } key changed:`,\n\t\t\t\tvalue,\n\t\t\t\tobject[ /** @type {keyof typeof object} */ ( key ) ]\n\t\t\t\t/* eslint-enable jsdoc/check-types */\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport default useWarnOnChange;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAwB;AAuBxB,SAAS,gBAAiB,QAAQ,SAAS,oBAAqB;AAC/D,QAAM,qBAAiB,oBAAAA,SAAa,MAAO;AAE3C,SAAO,QAAS,kBAAkB,CAAC,CAAE,EAAE,QAAS,CAAE,CAAE,KAAK,KAAM,MAAO;AACrE,QAAK,UAAU;AAAA;AAAA,MAA6C;AAAA,IAAM,GAAI;AAErE,cAAQ;AAAA,QACP,GAAI,MAAO,KAAM,GAAI;AAAA,QACrB;AAAA,QACA;AAAA;AAAA,UAA6C;AAAA,QAAM;AAAA;AAAA,MAEpD;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAEA,IAAO,6BAAQ;",
6
+ "names": ["usePrevious"]
7
+ }