@wordpress/compose 7.6.0 → 7.8.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 (78) hide show
  1. package/CHANGELOG.md +11 -2
  2. package/README.md +41 -11
  3. package/build/hooks/use-copy-on-click/index.js +5 -5
  4. package/build/hooks/use-copy-on-click/index.js.map +1 -1
  5. package/build/hooks/use-drop-zone/index.js +1 -0
  6. package/build/hooks/use-drop-zone/index.js.map +1 -1
  7. package/build/hooks/use-event/index.js +51 -0
  8. package/build/hooks/use-event/index.js.map +1 -0
  9. package/build/hooks/use-focus-on-mount/index.js +11 -11
  10. package/build/hooks/use-focus-on-mount/index.js.map +1 -1
  11. package/build/hooks/use-focus-outside/index.js +11 -11
  12. package/build/hooks/use-focus-outside/index.js.map +1 -1
  13. package/build/hooks/use-keyboard-shortcut/index.js +3 -3
  14. package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
  15. package/build/hooks/use-merge-refs/index.js +12 -12
  16. package/build/hooks/use-merge-refs/index.js.map +1 -1
  17. package/build/hooks/use-ref-effect/index.js +4 -4
  18. package/build/hooks/use-ref-effect/index.js.map +1 -1
  19. package/build/hooks/use-resize-observer/_legacy/index.js +139 -0
  20. package/build/hooks/use-resize-observer/_legacy/index.js.map +1 -0
  21. package/build/hooks/use-resize-observer/_legacy/index.native.js.map +1 -0
  22. package/build/hooks/use-resize-observer/index.js +70 -212
  23. package/build/hooks/use-resize-observer/index.js.map +1 -1
  24. package/build/index.js +8 -0
  25. package/build/index.js.map +1 -1
  26. package/build-module/hooks/use-copy-on-click/index.js +5 -5
  27. package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
  28. package/build-module/hooks/use-drop-zone/index.js +1 -0
  29. package/build-module/hooks/use-drop-zone/index.js.map +1 -1
  30. package/build-module/hooks/use-event/index.js +45 -0
  31. package/build-module/hooks/use-event/index.js.map +1 -0
  32. package/build-module/hooks/use-focus-on-mount/index.js +11 -11
  33. package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
  34. package/build-module/hooks/use-focus-outside/index.js +11 -11
  35. package/build-module/hooks/use-focus-outside/index.js.map +1 -1
  36. package/build-module/hooks/use-keyboard-shortcut/index.js +3 -3
  37. package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
  38. package/build-module/hooks/use-merge-refs/index.js +12 -12
  39. package/build-module/hooks/use-merge-refs/index.js.map +1 -1
  40. package/build-module/hooks/use-ref-effect/index.js +4 -4
  41. package/build-module/hooks/use-ref-effect/index.js.map +1 -1
  42. package/build-module/hooks/use-resize-observer/_legacy/index.js +130 -0
  43. package/build-module/hooks/use-resize-observer/_legacy/index.js.map +1 -0
  44. package/build-module/hooks/use-resize-observer/_legacy/index.native.js.map +1 -0
  45. package/build-module/hooks/use-resize-observer/index.js +69 -213
  46. package/build-module/hooks/use-resize-observer/index.js.map +1 -1
  47. package/build-module/index.js +1 -0
  48. package/build-module/index.js.map +1 -1
  49. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  50. package/build-types/hooks/use-event/index.d.ts +32 -0
  51. package/build-types/hooks/use-event/index.d.ts.map +1 -0
  52. package/build-types/hooks/use-focus-on-mount/index.d.ts.map +1 -1
  53. package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
  54. package/build-types/hooks/use-resize-observer/_legacy/index.d.ts +32 -0
  55. package/build-types/hooks/use-resize-observer/_legacy/index.d.ts.map +1 -0
  56. package/build-types/hooks/use-resize-observer/index.d.ts +42 -14
  57. package/build-types/hooks/use-resize-observer/index.d.ts.map +1 -1
  58. package/build-types/index.d.ts +1 -0
  59. package/package.json +9 -9
  60. package/src/hooks/use-copy-on-click/index.js +5 -5
  61. package/src/hooks/use-drop-zone/index.js +2 -0
  62. package/src/hooks/use-event/index.ts +51 -0
  63. package/src/hooks/use-focus-on-mount/index.js +11 -13
  64. package/src/hooks/use-focus-outside/index.ts +11 -11
  65. package/src/hooks/use-keyboard-shortcut/index.js +3 -3
  66. package/src/hooks/use-merge-refs/index.js +15 -13
  67. package/src/hooks/use-ref-effect/index.ts +4 -4
  68. package/src/hooks/use-resize-observer/_legacy/index.tsx +143 -0
  69. package/src/hooks/use-resize-observer/{test → _legacy/test}/index.native.js +1 -1
  70. package/src/hooks/use-resize-observer/index.ts +119 -0
  71. package/src/index.js +1 -0
  72. package/tsconfig.tsbuildinfo +1 -1
  73. package/build/hooks/use-resize-observer/index.native.js.map +0 -1
  74. package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
  75. package/src/hooks/use-resize-observer/index.tsx +0 -362
  76. /package/build/hooks/use-resize-observer/{index.native.js → _legacy/index.native.js} +0 -0
  77. /package/build-module/hooks/use-resize-observer/{index.native.js → _legacy/index.native.js} +0 -0
  78. /package/src/hooks/use-resize-observer/{index.native.js → _legacy/index.native.js} +0 -0
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","assignRef","ref","value","hasOwnProperty","current","useMergeRefs","refs","element","useRef","isAttached","didElementChange","previousRefs","currentRefs","useLayoutEffect","forEach","index","previousRef","useCallback","refsToAssign"],"sources":["@wordpress/compose/src/hooks/use-merge-refs/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useCallback, useLayoutEffect } from '@wordpress/element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef\n */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * @template T\n * @param {import('react').Ref<T>} ref\n * @param {T} value\n */\nfunction assignRef( ref, value ) {\n\tif ( typeof ref === 'function' ) {\n\t\tref( value );\n\t} else if ( ref && ref.hasOwnProperty( 'current' ) ) {\n\t\t/* eslint-disable jsdoc/no-undefined-types */\n\t\t/** @type {import('react').MutableRefObject<T>} */ ( ref ).current =\n\t\t\tvalue;\n\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t}\n}\n\n/**\n * Merges refs into one ref callback.\n *\n * It also ensures that the merged ref callbacks are only called when they\n * change (as a result of a `useCallback` dependency update) OR when the ref\n * value changes, just as React does when passing a single ref callback to the\n * component.\n *\n * As expected, if you pass a new function on every render, the ref callback\n * will be called after every render.\n *\n * If you don't wish a ref callback to be called after every render, wrap it\n * with `useCallback( callback, dependencies )`. When a dependency changes, the\n * old ref callback will be called with `null` and the new ref callback will be\n * called with the same value.\n *\n * To make ref callbacks easier to use, you can also pass the result of\n * `useRefEffect`, which makes cleanup easier by allowing you to return a\n * cleanup function instead of handling `null`.\n *\n * It's also possible to _disable_ a ref (and its behaviour) by simply not\n * passing the ref.\n *\n * ```jsx\n * const ref = useRefEffect( ( node ) => {\n * node.addEventListener( ... );\n * return () => {\n * node.removeEventListener( ... );\n * };\n * }, [ ...dependencies ] );\n * const otherRef = useRef();\n * const mergedRefs useMergeRefs( [\n * enabled && ref,\n * otherRef,\n * ] );\n * return <div ref={ mergedRefs } />;\n * ```\n *\n * @template {import('react').Ref<any>} TRef\n * @param {Array<TRef>} refs The refs to be merged.\n *\n * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.\n */\nexport default function useMergeRefs( refs ) {\n\tconst element = useRef();\n\tconst isAttached = useRef( false );\n\tconst didElementChange = useRef( false );\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<TRef[]>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst previousRefs = useRef( [] );\n\tconst currentRefs = useRef( refs );\n\n\t// Update on render before the ref callback is called, so the ref callback\n\t// always has access to the current refs.\n\tcurrentRefs.current = refs;\n\n\t// If any of the refs change, call the previous ref with `null` and the new\n\t// ref with the node, except when the element changes in the same cycle, in\n\t// which case the ref callbacks will already have been called.\n\tuseLayoutEffect( () => {\n\t\tif (\n\t\t\tdidElementChange.current === false &&\n\t\t\tisAttached.current === true\n\t\t) {\n\t\t\trefs.forEach( ( ref, index ) => {\n\t\t\t\tconst previousRef = previousRefs.current[ index ];\n\t\t\t\tif ( ref !== previousRef ) {\n\t\t\t\t\tassignRef( previousRef, null );\n\t\t\t\t\tassignRef( ref, element.current );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tpreviousRefs.current = refs;\n\t}, refs );\n\n\t// No dependencies, must be reset after every render so ref callbacks are\n\t// correctly called after a ref change.\n\tuseLayoutEffect( () => {\n\t\tdidElementChange.current = false;\n\t} );\n\n\t// There should be no dependencies so that `callback` is only called when\n\t// the node changes.\n\treturn useCallback( ( value ) => {\n\t\t// Update the element so it can be used when calling ref callbacks on a\n\t\t// dependency change.\n\t\tassignRef( element, value );\n\n\t\tdidElementChange.current = true;\n\t\tisAttached.current = value !== null;\n\n\t\t// When an element changes, the current ref callback should be called\n\t\t// with the new element and the previous one with `null`.\n\t\tconst refsToAssign = value ? currentRefs.current : previousRefs.current;\n\n\t\t// Update the latest refs.\n\t\tfor ( const ref of refsToAssign ) {\n\t\t\tassignRef( ref, value );\n\t\t}\n\t}, [] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,GAAG,EAAEC,KAAK,EAAG;EAChC,IAAK,OAAOD,GAAG,KAAK,UAAU,EAAG;IAChCA,GAAG,CAAEC,KAAM,CAAC;EACb,CAAC,MAAM,IAAKD,GAAG,IAAIA,GAAG,CAACE,cAAc,CAAE,SAAU,CAAC,EAAG;IACpD;IACA,kDAAqDF,GAAG,CAAGG,OAAO,GACjEF,KAAK;IACN;EACD;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,YAAYA,CAAEC,IAAI,EAAG;EAC5C,MAAMC,OAAO,GAAG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OAAO;;IAEvE;IACA,KAAM,MAAMH,GAAG,IAAIiB,YAAY,EAAG;MACjClB,SAAS,CAAEC,GAAG,EAAEC,KAAM,CAAC;IACxB;EACD,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","assignRef","ref","value","hasOwnProperty","current","useMergeRefs","refs","element","useRef","isAttachedRef","didElementChangeRef","previousRefsRef","currentRefsRef","useLayoutEffect","forEach","index","previousRef","useCallback","refsToAssign"],"sources":["@wordpress/compose/src/hooks/use-merge-refs/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useCallback, useLayoutEffect } from '@wordpress/element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef\n */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * @template T\n * @param {import('react').Ref<T>} ref\n * @param {T} value\n */\nfunction assignRef( ref, value ) {\n\tif ( typeof ref === 'function' ) {\n\t\tref( value );\n\t} else if ( ref && ref.hasOwnProperty( 'current' ) ) {\n\t\t/* eslint-disable jsdoc/no-undefined-types */\n\t\t/** @type {import('react').MutableRefObject<T>} */ ( ref ).current =\n\t\t\tvalue;\n\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t}\n}\n\n/**\n * Merges refs into one ref callback.\n *\n * It also ensures that the merged ref callbacks are only called when they\n * change (as a result of a `useCallback` dependency update) OR when the ref\n * value changes, just as React does when passing a single ref callback to the\n * component.\n *\n * As expected, if you pass a new function on every render, the ref callback\n * will be called after every render.\n *\n * If you don't wish a ref callback to be called after every render, wrap it\n * with `useCallback( callback, dependencies )`. When a dependency changes, the\n * old ref callback will be called with `null` and the new ref callback will be\n * called with the same value.\n *\n * To make ref callbacks easier to use, you can also pass the result of\n * `useRefEffect`, which makes cleanup easier by allowing you to return a\n * cleanup function instead of handling `null`.\n *\n * It's also possible to _disable_ a ref (and its behaviour) by simply not\n * passing the ref.\n *\n * ```jsx\n * const ref = useRefEffect( ( node ) => {\n * node.addEventListener( ... );\n * return () => {\n * node.removeEventListener( ... );\n * };\n * }, [ ...dependencies ] );\n * const otherRef = useRef();\n * const mergedRefs useMergeRefs( [\n * enabled && ref,\n * otherRef,\n * ] );\n * return <div ref={ mergedRefs } />;\n * ```\n *\n * @template {import('react').Ref<any>} TRef\n * @param {Array<TRef>} refs The refs to be merged.\n *\n * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.\n */\nexport default function useMergeRefs( refs ) {\n\tconst element = useRef();\n\tconst isAttachedRef = useRef( false );\n\tconst didElementChangeRef = useRef( false );\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<TRef[]>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst previousRefsRef = useRef( [] );\n\tconst currentRefsRef = useRef( refs );\n\n\t// Update on render before the ref callback is called, so the ref callback\n\t// always has access to the current refs.\n\tcurrentRefsRef.current = refs;\n\n\t// If any of the refs change, call the previous ref with `null` and the new\n\t// ref with the node, except when the element changes in the same cycle, in\n\t// which case the ref callbacks will already have been called.\n\tuseLayoutEffect( () => {\n\t\tif (\n\t\t\tdidElementChangeRef.current === false &&\n\t\t\tisAttachedRef.current === true\n\t\t) {\n\t\t\trefs.forEach( ( ref, index ) => {\n\t\t\t\tconst previousRef = previousRefsRef.current[ index ];\n\t\t\t\tif ( ref !== previousRef ) {\n\t\t\t\t\tassignRef( previousRef, null );\n\t\t\t\t\tassignRef( ref, element.current );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tpreviousRefsRef.current = refs;\n\t}, refs );\n\n\t// No dependencies, must be reset after every render so ref callbacks are\n\t// correctly called after a ref change.\n\tuseLayoutEffect( () => {\n\t\tdidElementChangeRef.current = false;\n\t} );\n\n\t// There should be no dependencies so that `callback` is only called when\n\t// the node changes.\n\treturn useCallback( ( value ) => {\n\t\t// Update the element so it can be used when calling ref callbacks on a\n\t\t// dependency change.\n\t\tassignRef( element, value );\n\n\t\tdidElementChangeRef.current = true;\n\t\tisAttachedRef.current = value !== null;\n\n\t\t// When an element changes, the current ref callback should be called\n\t\t// with the new element and the previous one with `null`.\n\t\tconst refsToAssign = value\n\t\t\t? currentRefsRef.current\n\t\t\t: previousRefsRef.current;\n\n\t\t// Update the latest refs.\n\t\tfor ( const ref of refsToAssign ) {\n\t\t\tassignRef( ref, value );\n\t\t}\n\t}, [] );\n}\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA,SAASC,SAASA,CAAEC,GAAG,EAAEC,KAAK,EAAG;EAChC,IAAK,OAAOD,GAAG,KAAK,UAAU,EAAG;IAChCA,GAAG,CAAEC,KAAM,CAAC;EACb,CAAC,MAAM,IAAKD,GAAG,IAAIA,GAAG,CAACE,cAAc,CAAE,SAAU,CAAC,EAAG;IACpD;IACA,kDAAqDF,GAAG,CAAGG,OAAO,GACjEF,KAAK;IACN;EACD;AACD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,YAAYA,CAAEC,IAAI,EAAG;EAC5C,MAAMC,OAAO,GAAG,IAAAC,eAAM,EAAC,CAAC;EACxB,MAAMC,aAAa,GAAG,IAAAD,eAAM,EAAE,KAAM,CAAC;EACrC,MAAME,mBAAmB,GAAG,IAAAF,eAAM,EAAE,KAAM,CAAC;EAC3C;EACA;EACA;EACA,MAAMG,eAAe,GAAG,IAAAH,eAAM,EAAE,EAAG,CAAC;EACpC,MAAMI,cAAc,GAAG,IAAAJ,eAAM,EAAEF,IAAK,CAAC;;EAErC;EACA;EACAM,cAAc,CAACR,OAAO,GAAGE,IAAI;;EAE7B;EACA;EACA;EACA,IAAAO,wBAAe,EAAE,MAAM;IACtB,IACCH,mBAAmB,CAACN,OAAO,KAAK,KAAK,IACrCK,aAAa,CAACL,OAAO,KAAK,IAAI,EAC7B;MACDE,IAAI,CAACQ,OAAO,CAAE,CAAEb,GAAG,EAAEc,KAAK,KAAM;QAC/B,MAAMC,WAAW,GAAGL,eAAe,CAACP,OAAO,CAAEW,KAAK,CAAE;QACpD,IAAKd,GAAG,KAAKe,WAAW,EAAG;UAC1BhB,SAAS,CAAEgB,WAAW,EAAE,IAAK,CAAC;UAC9BhB,SAAS,CAAEC,GAAG,EAAEM,OAAO,CAACH,OAAQ,CAAC;QAClC;MACD,CAAE,CAAC;IACJ;IAEAO,eAAe,CAACP,OAAO,GAAGE,IAAI;EAC/B,CAAC,EAAEA,IAAK,CAAC;;EAET;EACA;EACA,IAAAO,wBAAe,EAAE,MAAM;IACtBH,mBAAmB,CAACN,OAAO,GAAG,KAAK;EACpC,CAAE,CAAC;;EAEH;EACA;EACA,OAAO,IAAAa,oBAAW,EAAIf,KAAK,IAAM;IAChC;IACA;IACAF,SAAS,CAAEO,OAAO,EAAEL,KAAM,CAAC;IAE3BQ,mBAAmB,CAACN,OAAO,GAAG,IAAI;IAClCK,aAAa,CAACL,OAAO,GAAGF,KAAK,KAAK,IAAI;;IAEtC;IACA;IACA,MAAMgB,YAAY,GAAGhB,KAAK,GACvBU,cAAc,CAACR,OAAO,GACtBO,eAAe,CAACP,OAAO;;IAE1B;IACA,KAAM,MAAMH,GAAG,IAAIiB,YAAY,EAAG;MACjClB,SAAS,CAAEC,GAAG,EAAEC,KAAM,CAAC;IACxB;EACD,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
@@ -33,12 +33,12 @@ var _element = require("@wordpress/element");
33
33
  * @return Ref callback.
34
34
  */
35
35
  function useRefEffect(callback, dependencies) {
36
- const cleanup = (0, _element.useRef)();
36
+ const cleanupRef = (0, _element.useRef)();
37
37
  return (0, _element.useCallback)(node => {
38
38
  if (node) {
39
- cleanup.current = callback(node);
40
- } else if (cleanup.current) {
41
- cleanup.current();
39
+ cleanupRef.current = callback(node);
40
+ } else if (cleanupRef.current) {
41
+ cleanupRef.current();
42
42
  }
43
43
  }, dependencies);
44
44
  }
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","useRefEffect","callback","dependencies","cleanup","useRef","useCallback","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 cleanup = useRef< ( () => void ) | void >();\n\treturn useCallback( ( node: TElement | null ) => {\n\t\tif ( node ) {\n\t\t\tcleanup.current = callback( node );\n\t\t} else if ( cleanup.current ) {\n\t\t\tcleanup.current();\n\t\t}\n\t}, dependencies );\n}\n"],"mappings":";;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,YAAYA,CACnCC,QAAqD,EACrDC,YAA4B,EACK;EACjC,MAAMC,OAAO,GAAG,IAAAC,eAAM,EAA0B,CAAC;EACjD,OAAO,IAAAC,oBAAW,EAAIC,IAAqB,IAAM;IAChD,IAAKA,IAAI,EAAG;MACXH,OAAO,CAACI,OAAO,GAAGN,QAAQ,CAAEK,IAAK,CAAC;IACnC,CAAC,MAAM,IAAKH,OAAO,CAACI,OAAO,EAAG;MAC7BJ,OAAO,CAACI,OAAO,CAAC,CAAC;IAClB;EACD,CAAC,EAAEL,YAAa,CAAC;AAClB","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","useRefEffect","callback","dependencies","cleanupRef","useRef","useCallback","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":";;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AARA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASC,YAAYA,CACnCC,QAAqD,EACrDC,YAA4B,EACK;EACjC,MAAMC,UAAU,GAAG,IAAAC,eAAM,EAA0B,CAAC;EACpD,OAAO,IAAAC,oBAAW,EAAIC,IAAqB,IAAM;IAChD,IAAKA,IAAI,EAAG;MACXH,UAAU,CAACI,OAAO,GAAGN,QAAQ,CAAEK,IAAK,CAAC;IACtC,CAAC,MAAM,IAAKH,UAAU,CAACI,OAAO,EAAG;MAChCJ,UAAU,CAACI,OAAO,CAAC,CAAC;IACrB;EACD,CAAC,EAAEL,YAAa,CAAC;AAClB","ignoreList":[]}
@@ -0,0 +1,139 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.default = useLegacyResizeObserver;
8
+ var _element = require("@wordpress/element");
9
+ var _index = _interopRequireDefault(require("../index"));
10
+ var _jsxRuntime = require("react/jsx-runtime");
11
+ /**
12
+ * External dependencies
13
+ */
14
+
15
+ /**
16
+ * WordPress dependencies
17
+ */
18
+
19
+ /**
20
+ * Internal dependencies
21
+ */
22
+
23
+ // We're only using the first element of the size sequences, until future versions of the spec solidify on how
24
+ // exactly it'll be used for fragments in multi-column scenarios:
25
+ // From the spec:
26
+ // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,
27
+ // > which occur in multi-column scenarios. However the current definitions of content rect and border box do not
28
+ // > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single
29
+ // > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.
30
+ // > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.
31
+ // (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)
32
+ //
33
+ // Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,
34
+ // regardless of the "box" option.
35
+ // The spec states the following on this:
36
+ // > This does not have any impact on which box dimensions are returned to the defined callback when the event
37
+ // > is fired, it solely defines which box the author wishes to observe layout changes on.
38
+ // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
39
+ // I'm not exactly clear on what this means, especially when you consider a later section stating the following:
40
+ // > This section is non-normative. An author may desire to observe more than one CSS box.
41
+ // > In this case, author will need to use multiple ResizeObservers.
42
+ // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
43
+ // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.
44
+ // For this reason I decided to only return the requested size,
45
+ // even though it seems we have access to results for all box types.
46
+ // This also means that we get to keep the current api, being able to return a simple { width, height } pair,
47
+ // regardless of box option.
48
+ const extractSize = entry => {
49
+ let entrySize;
50
+ if (!entry.contentBoxSize) {
51
+ // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.
52
+ // See the 6th step in the description for the RO algorithm:
53
+ // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h
54
+ // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box".
55
+ // In real browser implementations of course these objects differ, but the width/height values should be equivalent.
56
+ entrySize = [entry.contentRect.width, entry.contentRect.height];
57
+ } else if (entry.contentBoxSize[0]) {
58
+ const contentBoxSize = entry.contentBoxSize[0];
59
+ entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
60
+ } else {
61
+ // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy
62
+ // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.
63
+ const contentBoxSize = entry.contentBoxSize;
64
+ entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
65
+ }
66
+ const [width, height] = entrySize.map(d => Math.round(d));
67
+ return {
68
+ width,
69
+ height
70
+ };
71
+ };
72
+ const RESIZE_ELEMENT_STYLES = {
73
+ position: 'absolute',
74
+ top: 0,
75
+ left: 0,
76
+ right: 0,
77
+ bottom: 0,
78
+ pointerEvents: 'none',
79
+ opacity: 0,
80
+ overflow: 'hidden',
81
+ zIndex: -1
82
+ };
83
+ function ResizeElement({
84
+ onResize
85
+ }) {
86
+ const resizeElementRef = (0, _index.default)(entries => {
87
+ const newSize = extractSize(entries.at(-1)); // Entries are never empty.
88
+ onResize(newSize);
89
+ });
90
+ return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
91
+ ref: resizeElementRef,
92
+ style: RESIZE_ELEMENT_STYLES,
93
+ "aria-hidden": "true"
94
+ });
95
+ }
96
+ function sizeEquals(a, b) {
97
+ return a.width === b.width && a.height === b.height;
98
+ }
99
+ const NULL_SIZE = {
100
+ width: null,
101
+ height: null
102
+ };
103
+
104
+ /**
105
+ * Hook which allows to listen to the resize event of any target element when it changes size.
106
+ * _Note: `useResizeObserver` will report `null` sizes until after first render.
107
+ *
108
+ * @example
109
+ *
110
+ * ```js
111
+ * const App = () => {
112
+ * const [ resizeListener, sizes ] = useResizeObserver();
113
+ *
114
+ * return (
115
+ * <div>
116
+ * { resizeListener }
117
+ * Your content here
118
+ * </div>
119
+ * );
120
+ * };
121
+ * ```
122
+ */
123
+ function useLegacyResizeObserver() {
124
+ const [size, setSize] = (0, _element.useState)(NULL_SIZE);
125
+
126
+ // Using a ref to track the previous width / height to avoid unnecessary renders.
127
+ const previousSizeRef = (0, _element.useRef)(NULL_SIZE);
128
+ const handleResize = (0, _element.useCallback)(newSize => {
129
+ if (!sizeEquals(previousSizeRef.current, newSize)) {
130
+ previousSizeRef.current = newSize;
131
+ setSize(newSize);
132
+ }
133
+ }, []);
134
+ const resizeElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(ResizeElement, {
135
+ onResize: handleResize
136
+ });
137
+ return [resizeElement, size];
138
+ }
139
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_element","require","_index","_interopRequireDefault","_jsxRuntime","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","useResizeObserver","entries","newSize","at","jsx","ref","style","sizeEquals","a","b","NULL_SIZE","useLegacyResizeObserver","size","setSize","useState","previousSizeRef","useRef","handleResize","useCallback","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 '../index';\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":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AAIA,IAAAC,MAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAyC,IAAAG,WAAA,GAAAH,OAAA;AAZzC;AACA;AACA;;AAGA;AACA;AACA;;AAEA;AACA;AACA;;AAQA;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,MAAMI,WAAW,GAAKC,KAA0B,IAAoB;EACnE,IAAIC,SAAS;EACb,IAAK,CAAED,KAAK,CAACE,cAAc,EAAG;IAC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A,CAAA+B,GAAA;IACCC,GAAG,EAAGN,gBAAkB;IACxBO,KAAK,EAAGnB,qBAAuB;IAC/B,eAAY;EAAM,CAClB,CAAC;AAEJ;AAEA,SAASoB,UAAUA,CAAEC,CAAe,EAAEC,CAAe,EAAG;EACvD,OAAOD,CAAC,CAAC7B,KAAK,KAAK8B,CAAC,CAAC9B,KAAK,IAAI6B,CAAC,CAAC5B,MAAM,KAAK6B,CAAC,CAAC7B,MAAM;AACpD;AAEA,MAAM8B,SAAuB,GAAG;EAAE/B,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;AACe,SAAS+B,uBAAuBA,CAAA,EAG7C;EACD,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAAG,IAAAC,iBAAQ,EAAEJ,SAAU,CAAC;;EAE/C;EACA,MAAMK,eAAe,GAAG,IAAAC,eAAM,EAAEN,SAAU,CAAC;EAE3C,MAAMO,YAAY,GAAG,IAAAC,oBAAW,EAAIhB,OAAqB,IAAM;IAC9D,IAAK,CAAEK,UAAU,CAAEQ,eAAe,CAACI,OAAO,EAAEjB,OAAQ,CAAC,EAAG;MACvDa,eAAe,CAACI,OAAO,GAAGjB,OAAO;MACjCW,OAAO,CAAEX,OAAQ,CAAC;IACnB;EACD,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMkB,aAAa,gBAAG,IAAA/C,WAAA,CAAA+B,GAAA,EAACP,aAAa;IAACC,QAAQ,EAAGmB;EAAc,CAAE,CAAC;EACjE,OAAO,CAAEG,aAAa,EAAER,IAAI,CAAE;AAC/B","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_reactNative","require","_element","_jsxRuntime","useResizeObserver","measurements","setMeasurements","useState","onLayout","useCallback","nativeEvent","width","height","layout","prevState","Math","floor","observer","jsx","View","testID","style","StyleSheet","absoluteFill","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/_legacy/index.native.js"],"sourcesContent":["/**\n * External dependencies\n */\nimport { View, StyleSheet } from 'react-native';\n/**\n * WordPress dependencies\n */\nimport { useState, useCallback } from '@wordpress/element';\n\n/**\n * Hook which allows to listen the resize event of any target element when it changes sizes.\n *\n * @example\n *\n * ```js\n * const App = () => {\n * \tconst [ resizeListener, sizes ] = useResizeObserver();\n *\n * \treturn (\n * \t\t<View>\n * \t\t\t{ resizeListener }\n * \t\t\tYour content here\n * \t\t</View>\n * \t);\n * };\n * ```\n */\nconst useResizeObserver = () => {\n\tconst [ measurements, setMeasurements ] = useState( null );\n\n\tconst onLayout = useCallback( ( { nativeEvent } ) => {\n\t\tconst { width, height } = nativeEvent.layout;\n\t\tsetMeasurements( ( prevState ) => {\n\t\t\tif (\n\t\t\t\t! prevState ||\n\t\t\t\tprevState.width !== width ||\n\t\t\t\tprevState.height !== height\n\t\t\t) {\n\t\t\t\treturn {\n\t\t\t\t\twidth: Math.floor( width ),\n\t\t\t\t\theight: Math.floor( height ),\n\t\t\t\t};\n\t\t\t}\n\t\t\treturn prevState;\n\t\t} );\n\t}, [] );\n\n\tconst observer = (\n\t\t<View\n\t\t\ttestID=\"resize-observer\"\n\t\t\tstyle={ StyleSheet.absoluteFill }\n\t\t\tonLayout={ onLayout }\n\t\t/>\n\t);\n\n\treturn [ observer, measurements ];\n};\n\nexport default useResizeObserver;\n"],"mappings":";;;;;;AAGA,IAAAA,YAAA,GAAAC,OAAA;AAIA,IAAAC,QAAA,GAAAD,OAAA;AAA2D,IAAAE,WAAA,GAAAF,OAAA;AAP3D;AACA;AACA;;AAEA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACA,MAAMG,iBAAiB,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAAEC,YAAY,EAAEC,eAAe,CAAE,GAAG,IAAAC,iBAAQ,EAAE,IAAK,CAAC;EAE1D,MAAMC,QAAQ,GAAG,IAAAC,oBAAW,EAAE,CAAE;IAAEC;EAAY,CAAC,KAAM;IACpD,MAAM;MAAEC,KAAK;MAAEC;IAAO,CAAC,GAAGF,WAAW,CAACG,MAAM;IAC5CP,eAAe,CAAIQ,SAAS,IAAM;MACjC,IACC,CAAEA,SAAS,IACXA,SAAS,CAACH,KAAK,KAAKA,KAAK,IACzBG,SAAS,CAACF,MAAM,KAAKA,MAAM,EAC1B;QACD,OAAO;UACND,KAAK,EAAEI,IAAI,CAACC,KAAK,CAAEL,KAAM,CAAC;UAC1BC,MAAM,EAAEG,IAAI,CAACC,KAAK,CAAEJ,MAAO;QAC5B,CAAC;MACF;MACA,OAAOE,SAAS;IACjB,CAAE,CAAC;EACJ,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMG,QAAQ,gBACb,IAAAd,WAAA,CAAAe,GAAA,EAAClB,YAAA,CAAAmB,IAAI;IACJC,MAAM,EAAC,iBAAiB;IACxBC,KAAK,EAAGC,uBAAU,CAACC,YAAc;IACjCf,QAAQ,EAAGA;EAAU,CACrB,CACD;EAED,OAAO,CAAES,QAAQ,EAAEZ,YAAY,CAAE;AAClC,CAAC;AAAC,IAAAmB,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEatB,iBAAiB","ignoreList":[]}
@@ -1,209 +1,92 @@
1
1
  "use strict";
2
2
 
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
3
4
  Object.defineProperty(exports, "__esModule", {
4
5
  value: true
5
6
  });
6
- exports.default = useResizeAware;
7
+ exports.default = useResizeObserver;
7
8
  var _element = require("@wordpress/element");
8
- var _jsxRuntime = require("react/jsx-runtime");
9
+ var _useEvent = _interopRequireDefault(require("../use-event"));
10
+ var _legacy = _interopRequireDefault(require("./_legacy"));
9
11
  /**
10
- * External dependencies
12
+ * WordPress dependencies
11
13
  */
12
14
 
13
15
  /**
14
- * WordPress dependencies
16
+ * Internal dependencies
15
17
  */
16
18
 
17
- // This of course could've been more streamlined with internal state instead of
18
- // refs, but then host hooks / components could not opt out of renders.
19
- // This could've been exported to its own module, but the current build doesn't
20
- // seem to work with module imports and I had no more time to spend on this...
21
- function useResolvedElement(subscriber, refOrElement) {
22
- const callbackRefElement = (0, _element.useRef)(null);
23
- const lastReportRef = (0, _element.useRef)(null);
24
- const cleanupRef = (0, _element.useRef)();
25
- const callSubscriber = (0, _element.useCallback)(() => {
26
- let element = null;
27
- if (callbackRefElement.current) {
28
- element = callbackRefElement.current;
29
- } else if (refOrElement) {
30
- if (refOrElement instanceof HTMLElement) {
31
- element = refOrElement;
32
- } else {
33
- element = refOrElement.current;
34
- }
35
- }
36
- if (lastReportRef.current && lastReportRef.current.element === element && lastReportRef.current.reporter === callSubscriber) {
37
- return;
38
- }
39
- if (cleanupRef.current) {
40
- cleanupRef.current();
41
- // Making sure the cleanup is not called accidentally multiple times.
42
- cleanupRef.current = null;
43
- }
44
- lastReportRef.current = {
45
- reporter: callSubscriber,
46
- element
47
- };
48
-
49
- // Only calling the subscriber, if there's an actual element to report.
50
- if (element) {
51
- cleanupRef.current = subscriber(element);
52
- }
53
- }, [refOrElement, subscriber]);
54
-
55
- // On each render, we check whether a ref changed, or if we got a new raw
56
- // element.
57
- (0, _element.useEffect)(() => {
58
- // With this we're *technically* supporting cases where ref objects' current value changes, but only if there's a
59
- // render accompanying that change as well.
60
- // To guarantee we always have the right element, one must use the ref callback provided instead, but we support
61
- // RefObjects to make the hook API more convenient in certain cases.
62
- callSubscriber();
63
- }, [callSubscriber]);
64
- return (0, _element.useCallback)(element => {
65
- callbackRefElement.current = element;
66
- callSubscriber();
67
- }, [callSubscriber]);
68
- }
69
-
70
- // Declaring my own type here instead of using the one provided by TS (available since 4.2.2), because this way I'm not
71
- // forcing consumers to use a specific TS version.
19
+ /**
20
+ * External dependencies
21
+ */
72
22
 
73
- // We're only using the first element of the size sequences, until future versions of the spec solidify on how
74
- // exactly it'll be used for fragments in multi-column scenarios:
75
- // From the spec:
76
- // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,
77
- // > which occur in multi-column scenarios. However the current definitions of content rect and border box do not
78
- // > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single
79
- // > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.
80
- // > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.
81
- // (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)
23
+ // This is the current implementation of `useResizeObserver`.
82
24
  //
83
- // Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,
84
- // regardless of the "box" option.
85
- // The spec states the following on this:
86
- // > This does not have any impact on which box dimensions are returned to the defined callback when the event
87
- // > is fired, it solely defines which box the author wishes to observe layout changes on.
88
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
89
- // I'm not exactly clear on what this means, especially when you consider a later section stating the following:
90
- // > This section is non-normative. An author may desire to observe more than one CSS box.
91
- // > In this case, author will need to use multiple ResizeObservers.
92
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
93
- // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.
94
- // For this reason I decided to only return the requested size,
95
- // even though it seems we have access to results for all box types.
96
- // This also means that we get to keep the current api, being able to return a simple { width, height } pair,
97
- // regardless of box option.
98
- const extractSize = (entry, boxProp, sizeType) => {
99
- if (!entry[boxProp]) {
100
- if (boxProp === 'contentBoxSize') {
101
- // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.
102
- // See the 6th step in the description for the RO algorithm:
103
- // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h
104
- // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box".
105
- // In real browser implementations of course these objects differ, but the width/height values should be equivalent.
106
- return entry.contentRect[sizeType === 'inlineSize' ? 'width' : 'height'];
107
- }
108
- return undefined;
109
- }
110
-
111
- // A couple bytes smaller than calling Array.isArray() and just as effective here.
112
- return entry[boxProp][0] ? entry[boxProp][0][sizeType] :
113
- // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's current
114
- // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.
115
- // @ts-ignore
116
- entry[boxProp][sizeType];
117
- };
118
- function useResizeObserver(opts = {}) {
119
- // Saving the callback as a ref. With this, I don't need to put onResize in the
120
- // effect dep array, and just passing in an anonymous function without memoising
121
- // will not reinstantiate the hook's ResizeObserver.
122
- const onResize = opts.onResize;
123
- const onResizeRef = (0, _element.useRef)(undefined);
124
- onResizeRef.current = onResize;
125
- const round = opts.round || Math.round;
126
-
127
- // Using a single instance throughout the hook's lifetime
25
+ // The legacy implementation is still supported for backwards compatibility.
26
+ // This is achieved by overloading the exported function with both signatures,
27
+ // and detecting which API is being used at runtime.
28
+ function _useResizeObserver(callback, resizeObserverOptions = {}) {
29
+ const callbackEvent = (0, _useEvent.default)(callback);
30
+ const observedElementRef = (0, _element.useRef)();
128
31
  const resizeObserverRef = (0, _element.useRef)();
129
- const [size, setSize] = (0, _element.useState)({
130
- width: undefined,
131
- height: undefined
132
- });
32
+ return (0, _useEvent.default)(element => {
33
+ var _resizeObserverRef$cu;
34
+ if (element === observedElementRef.current) {
35
+ return;
36
+ }
37
+ observedElementRef.current = element;
133
38
 
134
- // In certain edge cases the RO might want to report a size change just after
135
- // the component unmounted.
136
- const didUnmount = (0, _element.useRef)(false);
137
- (0, _element.useEffect)(() => {
138
- didUnmount.current = false;
139
- return () => {
140
- didUnmount.current = true;
141
- };
142
- }, []);
39
+ // Set up `ResizeObserver`.
40
+ (_resizeObserverRef$cu = resizeObserverRef.current) !== null && _resizeObserverRef$cu !== void 0 ? _resizeObserverRef$cu : resizeObserverRef.current = new ResizeObserver(callbackEvent);
41
+ const {
42
+ current: resizeObserver
43
+ } = resizeObserverRef;
143
44
 
144
- // Using a ref to track the previous width / height to avoid unnecessary renders.
145
- const previous = (0, _element.useRef)({
146
- width: undefined,
147
- height: undefined
148
- });
45
+ // Unobserve previous element.
46
+ if (observedElementRef.current) {
47
+ resizeObserver.unobserve(observedElementRef.current);
48
+ }
149
49
 
150
- // This block is kinda like a useEffect, only it's called whenever a new
151
- // element could be resolved based on the ref option. It also has a cleanup
152
- // function.
153
- const refCallback = useResolvedElement((0, _element.useCallback)(element => {
154
- // We only use a single Resize Observer instance, and we're instantiating it on demand, only once there's something to observe.
155
- // This instance is also recreated when the `box` option changes, so that a new observation is fired if there was a previously observed element with a different box option.
156
- if (!resizeObserverRef.current || resizeObserverRef.current.box !== opts.box || resizeObserverRef.current.round !== round) {
157
- resizeObserverRef.current = {
158
- box: opts.box,
159
- round,
160
- instance: new ResizeObserver(entries => {
161
- const entry = entries[0];
162
- let boxProp = 'borderBoxSize';
163
- if (opts.box === 'border-box') {
164
- boxProp = 'borderBoxSize';
165
- } else {
166
- boxProp = opts.box === 'device-pixel-content-box' ? 'devicePixelContentBoxSize' : 'contentBoxSize';
167
- }
168
- const reportedWidth = extractSize(entry, boxProp, 'inlineSize');
169
- const reportedHeight = extractSize(entry, boxProp, 'blockSize');
170
- const newWidth = reportedWidth ? round(reportedWidth) : undefined;
171
- const newHeight = reportedHeight ? round(reportedHeight) : undefined;
172
- if (previous.current.width !== newWidth || previous.current.height !== newHeight) {
173
- const newSize = {
174
- width: newWidth,
175
- height: newHeight
176
- };
177
- previous.current.width = newWidth;
178
- previous.current.height = newHeight;
179
- if (onResizeRef.current) {
180
- onResizeRef.current(newSize);
181
- } else if (!didUnmount.current) {
182
- setSize(newSize);
183
- }
184
- }
185
- })
186
- };
50
+ // Observe new element.
51
+ if (element) {
52
+ resizeObserver.observe(element, resizeObserverOptions);
187
53
  }
188
- resizeObserverRef.current.instance.observe(element, {
189
- box: opts.box
190
- });
191
- return () => {
192
- if (resizeObserverRef.current) {
193
- resizeObserverRef.current.instance.unobserve(element);
194
- }
195
- };
196
- }, [opts.box, round]), opts.ref);
197
- return (0, _element.useMemo)(() => ({
198
- ref: refCallback,
199
- width: size.width,
200
- height: size.height
201
- }), [refCallback, size ? size.width : null, size ? size.height : null]);
54
+ });
202
55
  }
203
56
 
204
57
  /**
205
- * Hook which allows to listen the resize event of any target element when it changes sizes.
206
- * _Note: `useResizeObserver` will report `null` until after first render.
58
+ * Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API)
59
+ * for an HTML or SVG element.
60
+ *
61
+ * Pass the returned setter as a callback ref to the React element you want
62
+ * to observe, or use it in layout effects for advanced use cases.
63
+ *
64
+ * @example
65
+ *
66
+ * ```tsx
67
+ * const setElement = useResizeObserver(
68
+ * ( resizeObserverEntries ) => console.log( resizeObserverEntries ),
69
+ * { box: 'border-box' }
70
+ * );
71
+ * <div ref={ setElement } />;
72
+ *
73
+ * // The setter can be used in other ways, for example:
74
+ * useLayoutEffect( () => {
75
+ * setElement( document.querySelector( `data-element-id="${ elementId }"` ) );
76
+ * }, [ elementId ] );
77
+ * ```
78
+ *
79
+ * @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).
80
+ * @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.
81
+ */
82
+
83
+ /**
84
+ * **This is a legacy API and should not be used.**
85
+ *
86
+ * @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`.
87
+ *
88
+ * Hook which allows to listen to the resize event of any target element when it changes size.
89
+ * _Note: `useResizeObserver` will report `null` sizes until after first render.
207
90
  *
208
91
  * @example
209
92
  *
@@ -220,33 +103,8 @@ function useResizeObserver(opts = {}) {
220
103
  * };
221
104
  * ```
222
105
  */
223
- function useResizeAware() {
224
- const {
225
- ref,
226
- width,
227
- height
228
- } = useResizeObserver();
229
- const sizes = (0, _element.useMemo)(() => {
230
- return {
231
- width: width !== null && width !== void 0 ? width : null,
232
- height: height !== null && height !== void 0 ? height : null
233
- };
234
- }, [width, height]);
235
- const resizeListener = /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
236
- style: {
237
- position: 'absolute',
238
- top: 0,
239
- left: 0,
240
- right: 0,
241
- bottom: 0,
242
- pointerEvents: 'none',
243
- opacity: 0,
244
- overflow: 'hidden',
245
- zIndex: -1
246
- },
247
- "aria-hidden": "true",
248
- ref: ref
249
- });
250
- return [resizeListener, sizes];
106
+
107
+ function useResizeObserver(callback, options = {}) {
108
+ return callback ? _useResizeObserver(callback, options) : (0, _legacy.default)();
251
109
  }
252
110
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_jsxRuntime","useResolvedElement","subscriber","refOrElement","callbackRefElement","useRef","lastReportRef","cleanupRef","callSubscriber","useCallback","element","current","HTMLElement","reporter","useEffect","extractSize","entry","boxProp","sizeType","contentRect","undefined","useResizeObserver","opts","onResize","onResizeRef","round","Math","resizeObserverRef","size","setSize","useState","width","height","didUnmount","previous","refCallback","box","instance","ResizeObserver","entries","reportedWidth","reportedHeight","newWidth","newHeight","newSize","observe","unobserve","ref","useMemo","useResizeAware","sizes","resizeListener","jsx","style","position","top","left","right","bottom","pointerEvents","opacity","overflow","zIndex"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement, RefCallback, RefObject } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseMemo,\n\tuseRef,\n\tuseCallback,\n\tuseEffect,\n\tuseState,\n} from '@wordpress/element';\n\ntype SubscriberCleanup = () => void;\ntype SubscriberResponse = SubscriberCleanup | void;\n\n// This of course could've been more streamlined with internal state instead of\n// refs, but then host hooks / components could not opt out of renders.\n// This could've been exported to its own module, but the current build doesn't\n// seem to work with module imports and I had no more time to spend on this...\nfunction useResolvedElement< T extends HTMLElement >(\n\tsubscriber: ( element: T ) => SubscriberResponse,\n\trefOrElement?: T | RefObject< T > | null\n): RefCallback< T > {\n\tconst callbackRefElement = useRef< T | null >( null );\n\tconst lastReportRef = useRef< {\n\t\treporter: () => void;\n\t\telement: T | null;\n\t} | null >( null );\n\tconst cleanupRef = useRef< SubscriberResponse | null >();\n\n\tconst callSubscriber = useCallback( () => {\n\t\tlet element = null;\n\t\tif ( callbackRefElement.current ) {\n\t\t\telement = callbackRefElement.current;\n\t\t} else if ( refOrElement ) {\n\t\t\tif ( refOrElement instanceof HTMLElement ) {\n\t\t\t\telement = refOrElement;\n\t\t\t} else {\n\t\t\t\telement = refOrElement.current;\n\t\t\t}\n\t\t}\n\n\t\tif (\n\t\t\tlastReportRef.current &&\n\t\t\tlastReportRef.current.element === element &&\n\t\t\tlastReportRef.current.reporter === callSubscriber\n\t\t) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( cleanupRef.current ) {\n\t\t\tcleanupRef.current();\n\t\t\t// Making sure the cleanup is not called accidentally multiple times.\n\t\t\tcleanupRef.current = null;\n\t\t}\n\t\tlastReportRef.current = {\n\t\t\treporter: callSubscriber,\n\t\t\telement,\n\t\t};\n\n\t\t// Only calling the subscriber, if there's an actual element to report.\n\t\tif ( element ) {\n\t\t\tcleanupRef.current = subscriber( element );\n\t\t}\n\t}, [ refOrElement, subscriber ] );\n\n\t// On each render, we check whether a ref changed, or if we got a new raw\n\t// element.\n\tuseEffect( () => {\n\t\t// With this we're *technically* supporting cases where ref objects' current value changes, but only if there's a\n\t\t// render accompanying that change as well.\n\t\t// To guarantee we always have the right element, one must use the ref callback provided instead, but we support\n\t\t// RefObjects to make the hook API more convenient in certain cases.\n\t\tcallSubscriber();\n\t}, [ callSubscriber ] );\n\n\treturn useCallback< RefCallback< T > >(\n\t\t( element ) => {\n\t\t\tcallbackRefElement.current = element;\n\t\t\tcallSubscriber();\n\t\t},\n\t\t[ callSubscriber ]\n\t);\n}\n\ntype ObservedSize = {\n\twidth: number | undefined;\n\theight: number | undefined;\n};\n\ntype ResizeHandler = ( size: ObservedSize ) => void;\n\ntype HookResponse< T extends HTMLElement > = {\n\tref: RefCallback< T >;\n} & ObservedSize;\n\n// Declaring my own type here instead of using the one provided by TS (available since 4.2.2), because this way I'm not\n// forcing consumers to use a specific TS version.\ntype ResizeObserverBoxOptions =\n\t| 'border-box'\n\t| 'content-box'\n\t| 'device-pixel-content-box';\n\ndeclare global {\n\tinterface ResizeObserverEntry {\n\t\treadonly devicePixelContentBoxSize: ReadonlyArray< ResizeObserverSize >;\n\t}\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 = (\n\tentry: ResizeObserverEntry,\n\tboxProp: 'borderBoxSize' | 'contentBoxSize' | 'devicePixelContentBoxSize',\n\tsizeType: keyof ResizeObserverSize\n): number | undefined => {\n\tif ( ! entry[ boxProp ] ) {\n\t\tif ( boxProp === 'contentBoxSize' ) {\n\t\t\t// The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.\n\t\t\t// See the 6th step in the description for the RO algorithm:\n\t\t\t// https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h\n\t\t\t// > Set this.contentRect to logical this.contentBoxSize given target and observedBox of \"content-box\".\n\t\t\t// In real browser implementations of course these objects differ, but the width/height values should be equivalent.\n\t\t\treturn entry.contentRect[\n\t\t\t\tsizeType === 'inlineSize' ? 'width' : 'height'\n\t\t\t];\n\t\t}\n\n\t\treturn undefined;\n\t}\n\n\t// A couple bytes smaller than calling Array.isArray() and just as effective here.\n\treturn entry[ boxProp ][ 0 ]\n\t\t? entry[ boxProp ][ 0 ][ sizeType ]\n\t\t: // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's current\n\t\t // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.\n\t\t // @ts-ignore\n\t\t entry[ boxProp ][ sizeType ];\n};\n\ntype RoundingFunction = ( n: number ) => number;\n\nfunction useResizeObserver< T extends HTMLElement >(\n\topts: {\n\t\tref?: RefObject< T > | T | null | undefined;\n\t\tonResize?: ResizeHandler;\n\t\tbox?: ResizeObserverBoxOptions;\n\t\tround?: RoundingFunction;\n\t} = {}\n): HookResponse< T > {\n\t// Saving the callback as a ref. With this, I don't need to put onResize in the\n\t// effect dep array, and just passing in an anonymous function without memoising\n\t// will not reinstantiate the hook's ResizeObserver.\n\tconst onResize = opts.onResize;\n\tconst onResizeRef = useRef< ResizeHandler | undefined >( undefined );\n\tonResizeRef.current = onResize;\n\tconst round = opts.round || Math.round;\n\n\t// Using a single instance throughout the hook's lifetime\n\tconst resizeObserverRef = useRef< {\n\t\tbox?: ResizeObserverBoxOptions;\n\t\tround?: RoundingFunction;\n\t\tinstance: ResizeObserver;\n\t} >();\n\n\tconst [ size, setSize ] = useState< {\n\t\twidth?: number;\n\t\theight?: number;\n\t} >( {\n\t\twidth: undefined,\n\t\theight: undefined,\n\t} );\n\n\t// In certain edge cases the RO might want to report a size change just after\n\t// the component unmounted.\n\tconst didUnmount = useRef( false );\n\tuseEffect( () => {\n\t\tdidUnmount.current = false;\n\t\treturn () => {\n\t\t\tdidUnmount.current = true;\n\t\t};\n\t}, [] );\n\n\t// Using a ref to track the previous width / height to avoid unnecessary renders.\n\tconst previous: {\n\t\tcurrent: {\n\t\t\twidth?: number;\n\t\t\theight?: number;\n\t\t};\n\t} = useRef( {\n\t\twidth: undefined,\n\t\theight: undefined,\n\t} );\n\n\t// This block is kinda like a useEffect, only it's called whenever a new\n\t// element could be resolved based on the ref option. It also has a cleanup\n\t// function.\n\tconst refCallback = useResolvedElement< T >(\n\t\tuseCallback(\n\t\t\t( element ) => {\n\t\t\t\t// We only use a single Resize Observer instance, and we're instantiating it on demand, only once there's something to observe.\n\t\t\t\t// This instance is also recreated when the `box` option changes, so that a new observation is fired if there was a previously observed element with a different box option.\n\t\t\t\tif (\n\t\t\t\t\t! resizeObserverRef.current ||\n\t\t\t\t\tresizeObserverRef.current.box !== opts.box ||\n\t\t\t\t\tresizeObserverRef.current.round !== round\n\t\t\t\t) {\n\t\t\t\t\tresizeObserverRef.current = {\n\t\t\t\t\t\tbox: opts.box,\n\t\t\t\t\t\tround,\n\t\t\t\t\t\tinstance: new ResizeObserver( ( entries ) => {\n\t\t\t\t\t\t\tconst entry = entries[ 0 ];\n\n\t\t\t\t\t\t\tlet boxProp:\n\t\t\t\t\t\t\t\t| 'borderBoxSize'\n\t\t\t\t\t\t\t\t| 'contentBoxSize'\n\t\t\t\t\t\t\t\t| 'devicePixelContentBoxSize' = 'borderBoxSize';\n\t\t\t\t\t\t\tif ( opts.box === 'border-box' ) {\n\t\t\t\t\t\t\t\tboxProp = 'borderBoxSize';\n\t\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\t\tboxProp =\n\t\t\t\t\t\t\t\t\topts.box === 'device-pixel-content-box'\n\t\t\t\t\t\t\t\t\t\t? 'devicePixelContentBoxSize'\n\t\t\t\t\t\t\t\t\t\t: 'contentBoxSize';\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\tconst reportedWidth = extractSize(\n\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\tboxProp,\n\t\t\t\t\t\t\t\t'inlineSize'\n\t\t\t\t\t\t\t);\n\t\t\t\t\t\t\tconst reportedHeight = extractSize(\n\t\t\t\t\t\t\t\tentry,\n\t\t\t\t\t\t\t\tboxProp,\n\t\t\t\t\t\t\t\t'blockSize'\n\t\t\t\t\t\t\t);\n\n\t\t\t\t\t\t\tconst newWidth = reportedWidth\n\t\t\t\t\t\t\t\t? round( reportedWidth )\n\t\t\t\t\t\t\t\t: undefined;\n\t\t\t\t\t\t\tconst newHeight = reportedHeight\n\t\t\t\t\t\t\t\t? round( reportedHeight )\n\t\t\t\t\t\t\t\t: undefined;\n\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tprevious.current.width !== newWidth ||\n\t\t\t\t\t\t\t\tprevious.current.height !== newHeight\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\tconst newSize = {\n\t\t\t\t\t\t\t\t\twidth: newWidth,\n\t\t\t\t\t\t\t\t\theight: newHeight,\n\t\t\t\t\t\t\t\t};\n\t\t\t\t\t\t\t\tprevious.current.width = newWidth;\n\t\t\t\t\t\t\t\tprevious.current.height = newHeight;\n\t\t\t\t\t\t\t\tif ( onResizeRef.current ) {\n\t\t\t\t\t\t\t\t\tonResizeRef.current( newSize );\n\t\t\t\t\t\t\t\t} else if ( ! didUnmount.current ) {\n\t\t\t\t\t\t\t\t\tsetSize( newSize );\n\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t} ),\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\tresizeObserverRef.current.instance.observe( element, {\n\t\t\t\t\tbox: opts.box,\n\t\t\t\t} );\n\n\t\t\t\treturn () => {\n\t\t\t\t\tif ( resizeObserverRef.current ) {\n\t\t\t\t\t\tresizeObserverRef.current.instance.unobserve( element );\n\t\t\t\t\t}\n\t\t\t\t};\n\t\t\t},\n\t\t\t[ opts.box, round ]\n\t\t),\n\t\topts.ref\n\t);\n\n\treturn useMemo(\n\t\t() => ( {\n\t\t\tref: refCallback,\n\t\t\twidth: size.width,\n\t\t\theight: size.height,\n\t\t} ),\n\t\t[ refCallback, size ? size.width : null, size ? size.height : null ]\n\t);\n}\n\n/**\n * Hook which allows to listen the resize event of any target element when it changes sizes.\n * _Note: `useResizeObserver` will report `null` 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 useResizeAware(): [\n\tReactElement,\n\t{ width: number | null; height: number | null },\n] {\n\tconst { ref, width, height } = useResizeObserver();\n\tconst sizes = useMemo( () => {\n\t\treturn { width: width ?? null, height: height ?? null };\n\t}, [ width, height ] );\n\tconst resizeListener = (\n\t\t<div\n\t\t\tstyle={ {\n\t\t\t\tposition: 'absolute',\n\t\t\t\ttop: 0,\n\t\t\t\tleft: 0,\n\t\t\t\tright: 0,\n\t\t\t\tbottom: 0,\n\t\t\t\tpointerEvents: 'none',\n\t\t\t\topacity: 0,\n\t\t\t\toverflow: 'hidden',\n\t\t\t\tzIndex: -1,\n\t\t\t} }\n\t\t\taria-hidden=\"true\"\n\t\t\tref={ ref }\n\t\t/>\n\t);\n\treturn [ resizeListener, sizes ];\n}\n"],"mappings":";;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AAM4B,IAAAC,WAAA,GAAAD,OAAA;AAd5B;AACA;AACA;;AAGA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA,SAASE,kBAAkBA,CAC1BC,UAAgD,EAChDC,YAAwC,EACrB;EACnB,MAAMC,kBAAkB,GAAG,IAAAC,eAAM,EAAc,IAAK,CAAC;EACrD,MAAMC,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EA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASiB,cAAcA,CAAA,EAGpC;EACD,MAAM;IAAEF,GAAG;IAAEhB,KAAK;IAAEC;EAAO,CAAC,GAAGX,iBAAiB,CAAC,CAAC;EAClD,MAAM6B,KAAK,GAAG,IAAAF,gBAAO,EAAE,MAAM;IAC5B,OAAO;MAAEjB,KAAK,EAAEA,KAAK,aAALA,KAAK,cAALA,KAAK,GAAI,IAAI;MAAEC,MAAM,EAAEA,MAAM,aAANA,MAAM,cAANA,MAAM,GAAI;IAAK,CAAC;EACxD,CAAC,EAAE,CAAED,KAAK,EAAEC,MAAM,CAAG,CAAC;EACtB,MAAMmB,cAAc,gBACnB,IAAAnD,WAAA,CAAAoD,GAAA;IACCC,KAAK,EAAG;MACPC,QAAQ,EAAE,UAAU;MACpBC,GAAG,EAAE,CAAC;MACNC,IAAI,EAAE,CAAC;MACPC,KAAK,EAAE,CAAC;MACRC,MAAM,EAAE,CAAC;MACTC,aAAa,EAAE,MAAM;MACrBC,OAAO,EAAE,CAAC;MACVC,QAAQ,EAAE,QAAQ;MAClBC,MAAM,EAAE,CAAC;IACV,CAAG;IACH,eAAY,MAAM;IAClBf,GAAG,EAAGA;EAAK,CACX,CACD;EACD,OAAO,CAAEI,cAAc,EAAED,KAAK,CAAE;AACjC","ignoreList":[]}
1
+ {"version":3,"names":["_element","require","_useEvent","_interopRequireDefault","_legacy","_useResizeObserver","callback","resizeObserverOptions","callbackEvent","useEvent","observedElementRef","useRef","resizeObserverRef","element","_resizeObserverRef$cu","current","ResizeObserver","resizeObserver","unobserve","observe","useResizeObserver","options","_useLegacyResizeObserver"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport useEvent from '../use-event';\nimport type { ObservedSize } from './_legacy';\nimport _useLegacyResizeObserver from './_legacy';\n/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\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.\nfunction _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\t\tobservedElementRef.current = element;\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\tif ( element ) {\n\t\t\tresizeObserver.observe( element, resizeObserverOptions );\n\t\t}\n\t} );\n}\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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAIA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,OAAA,GAAAD,sBAAA,CAAAF,OAAA;AATA;AACA;AACA;;AAEA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASI,kBAAkBA,CAC1BC,QAAgC,EAChCC,qBAA4C,GAAG,CAAC,CAAC,EAChB;EACjC,MAAMC,aA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