@wordpress/compose 7.7.0 → 7.8.1-next.1f6eadc42.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 (51) hide show
  1. package/CHANGELOG.md +9 -2
  2. package/README.md +41 -11
  3. package/build/hooks/use-drop-zone/index.js +1 -0
  4. package/build/hooks/use-drop-zone/index.js.map +1 -1
  5. package/build/hooks/use-event/index.js +51 -0
  6. package/build/hooks/use-event/index.js.map +1 -0
  7. package/build/hooks/use-focus-on-mount/index.js +8 -8
  8. package/build/hooks/use-focus-on-mount/index.js.map +1 -1
  9. package/build/hooks/use-resize-observer/_legacy/index.js +139 -0
  10. package/build/hooks/use-resize-observer/_legacy/index.js.map +1 -0
  11. package/build/hooks/use-resize-observer/_legacy/index.native.js.map +1 -0
  12. package/build/hooks/use-resize-observer/index.js +71 -108
  13. package/build/hooks/use-resize-observer/index.js.map +1 -1
  14. package/build/index.js +8 -0
  15. package/build/index.js.map +1 -1
  16. package/build-module/hooks/use-drop-zone/index.js +1 -0
  17. package/build-module/hooks/use-drop-zone/index.js.map +1 -1
  18. package/build-module/hooks/use-event/index.js +45 -0
  19. package/build-module/hooks/use-event/index.js.map +1 -0
  20. package/build-module/hooks/use-focus-on-mount/index.js +8 -8
  21. package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
  22. package/build-module/hooks/use-resize-observer/_legacy/index.js +130 -0
  23. package/build-module/hooks/use-resize-observer/_legacy/index.js.map +1 -0
  24. package/build-module/hooks/use-resize-observer/_legacy/index.native.js.map +1 -0
  25. package/build-module/hooks/use-resize-observer/index.js +71 -110
  26. package/build-module/hooks/use-resize-observer/index.js.map +1 -1
  27. package/build-module/index.js +1 -0
  28. package/build-module/index.js.map +1 -1
  29. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  30. package/build-types/hooks/use-event/index.d.ts +32 -0
  31. package/build-types/hooks/use-event/index.d.ts.map +1 -0
  32. package/build-types/hooks/use-focus-on-mount/index.d.ts.map +1 -1
  33. package/build-types/hooks/use-resize-observer/_legacy/index.d.ts +32 -0
  34. package/build-types/hooks/use-resize-observer/_legacy/index.d.ts.map +1 -0
  35. package/build-types/hooks/use-resize-observer/index.d.ts +39 -5
  36. package/build-types/hooks/use-resize-observer/index.d.ts.map +1 -1
  37. package/build-types/index.d.ts +1 -0
  38. package/package.json +9 -9
  39. package/src/hooks/use-drop-zone/index.js +2 -0
  40. package/src/hooks/use-event/index.ts +51 -0
  41. package/src/hooks/use-focus-on-mount/index.js +8 -10
  42. package/src/hooks/use-resize-observer/{index.tsx → _legacy/index.tsx} +14 -30
  43. package/src/hooks/use-resize-observer/{test → _legacy/test}/index.native.js +1 -1
  44. package/src/hooks/use-resize-observer/index.ts +119 -0
  45. package/src/index.js +1 -0
  46. package/tsconfig.tsbuildinfo +1 -1
  47. package/build/hooks/use-resize-observer/index.native.js.map +0 -1
  48. package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
  49. /package/build/hooks/use-resize-observer/{index.native.js → _legacy/index.native.js} +0 -0
  50. /package/build-module/hooks/use-resize-observer/{index.native.js → _legacy/index.native.js} +0 -0
  51. /package/src/hooks/use-resize-observer/{index.native.js → _legacy/index.native.js} +0 -0
@@ -0,0 +1,130 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+
5
+ /**
6
+ * WordPress dependencies
7
+ */
8
+ import { useCallback, useRef, useState } from '@wordpress/element';
9
+ /**
10
+ * Internal dependencies
11
+ */
12
+ import useResizeObserver from '../index';
13
+ import { jsx as _jsx } from "react/jsx-runtime";
14
+ // We're only using the first element of the size sequences, until future versions of the spec solidify on how
15
+ // exactly it'll be used for fragments in multi-column scenarios:
16
+ // From the spec:
17
+ // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,
18
+ // > which occur in multi-column scenarios. However the current definitions of content rect and border box do not
19
+ // > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single
20
+ // > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.
21
+ // > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.
22
+ // (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)
23
+ //
24
+ // Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,
25
+ // regardless of the "box" option.
26
+ // The spec states the following on this:
27
+ // > This does not have any impact on which box dimensions are returned to the defined callback when the event
28
+ // > is fired, it solely defines which box the author wishes to observe layout changes on.
29
+ // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
30
+ // I'm not exactly clear on what this means, especially when you consider a later section stating the following:
31
+ // > This section is non-normative. An author may desire to observe more than one CSS box.
32
+ // > In this case, author will need to use multiple ResizeObservers.
33
+ // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
34
+ // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.
35
+ // For this reason I decided to only return the requested size,
36
+ // even though it seems we have access to results for all box types.
37
+ // This also means that we get to keep the current api, being able to return a simple { width, height } pair,
38
+ // regardless of box option.
39
+ const extractSize = entry => {
40
+ let entrySize;
41
+ if (!entry.contentBoxSize) {
42
+ // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.
43
+ // See the 6th step in the description for the RO algorithm:
44
+ // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h
45
+ // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box".
46
+ // In real browser implementations of course these objects differ, but the width/height values should be equivalent.
47
+ entrySize = [entry.contentRect.width, entry.contentRect.height];
48
+ } else if (entry.contentBoxSize[0]) {
49
+ const contentBoxSize = entry.contentBoxSize[0];
50
+ entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
51
+ } else {
52
+ // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy
53
+ // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.
54
+ const contentBoxSize = entry.contentBoxSize;
55
+ entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
56
+ }
57
+ const [width, height] = entrySize.map(d => Math.round(d));
58
+ return {
59
+ width,
60
+ height
61
+ };
62
+ };
63
+ const RESIZE_ELEMENT_STYLES = {
64
+ position: 'absolute',
65
+ top: 0,
66
+ left: 0,
67
+ right: 0,
68
+ bottom: 0,
69
+ pointerEvents: 'none',
70
+ opacity: 0,
71
+ overflow: 'hidden',
72
+ zIndex: -1
73
+ };
74
+ function ResizeElement({
75
+ onResize
76
+ }) {
77
+ const resizeElementRef = useResizeObserver(entries => {
78
+ const newSize = extractSize(entries.at(-1)); // Entries are never empty.
79
+ onResize(newSize);
80
+ });
81
+ return /*#__PURE__*/_jsx("div", {
82
+ ref: resizeElementRef,
83
+ style: RESIZE_ELEMENT_STYLES,
84
+ "aria-hidden": "true"
85
+ });
86
+ }
87
+ function sizeEquals(a, b) {
88
+ return a.width === b.width && a.height === b.height;
89
+ }
90
+ const NULL_SIZE = {
91
+ width: null,
92
+ height: null
93
+ };
94
+
95
+ /**
96
+ * Hook which allows to listen to the resize event of any target element when it changes size.
97
+ * _Note: `useResizeObserver` will report `null` sizes until after first render.
98
+ *
99
+ * @example
100
+ *
101
+ * ```js
102
+ * const App = () => {
103
+ * const [ resizeListener, sizes ] = useResizeObserver();
104
+ *
105
+ * return (
106
+ * <div>
107
+ * { resizeListener }
108
+ * Your content here
109
+ * </div>
110
+ * );
111
+ * };
112
+ * ```
113
+ */
114
+ export default function useLegacyResizeObserver() {
115
+ const [size, setSize] = useState(NULL_SIZE);
116
+
117
+ // Using a ref to track the previous width / height to avoid unnecessary renders.
118
+ const previousSizeRef = useRef(NULL_SIZE);
119
+ const handleResize = useCallback(newSize => {
120
+ if (!sizeEquals(previousSizeRef.current, newSize)) {
121
+ previousSizeRef.current = newSize;
122
+ setSize(newSize);
123
+ }
124
+ }, []);
125
+ const resizeElement = /*#__PURE__*/_jsx(ResizeElement, {
126
+ onResize: handleResize
127
+ });
128
+ return [resizeElement, size];
129
+ }
130
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useCallback","useRef","useState","useResizeObserver","jsx","_jsx","extractSize","entry","entrySize","contentBoxSize","contentRect","width","height","inlineSize","blockSize","map","d","Math","round","RESIZE_ELEMENT_STYLES","position","top","left","right","bottom","pointerEvents","opacity","overflow","zIndex","ResizeElement","onResize","resizeElementRef","entries","newSize","at","ref","style","sizeEquals","a","b","NULL_SIZE","useLegacyResizeObserver","size","setSize","previousSizeRef","handleResize","current","resizeElement"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/_legacy/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useCallback, useRef, useState } from '@wordpress/element';\n/**\n * Internal dependencies\n */\nimport useResizeObserver from '../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":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,oBAAoB;AAClE;AACA;AACA;AACA,OAAOC,iBAAiB,MAAM,UAAU;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAOzC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAKC,KAA0B,IAAoB;EACnE,IAAIC,SAAS;EACb,IAAK,CAAED,KAAK,CAACE,cAAc,EAAG;IAC7B;IACA;IACA;IACA;IACA;IACAD,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BK,KAAK,EAAGjB,qBAAuB;IAC/B,eAAY;EAAM,CAClB,CAAC;AAEJ;AAEA,SAASkB,UAAUA,CAAEC,CAAe,EAAEC,CAAe,EAAG;EACvD,OAAOD,CAAC,CAAC3B,KAAK,KAAK4B,CAAC,CAAC5B,KAAK,IAAI2B,CAAC,CAAC1B,MAAM,KAAK2B,CAAC,CAAC3B,MAAM;AACpD;AAEA,MAAM4B,SAAuB,GAAG;EAAE7B,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE;AAAK,CAAC;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAAS6B,uBAAuBA,CAAA,EAG7C;EACD,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAAGzC,QAAQ,CAAEsC,SAAU,CAAC;;EAE/C;EACA,MAAMI,eAAe,GAAG3C,MAAM,CAAEuC,SAAU,CAAC;EAE3C,MAAMK,YAAY,GAAG7C,WAAW,CAAIiC,OAAqB,IAAM;IAC9D,IAAK,CAAEI,UAAU,CAAEO,eAAe,CAACE,OAAO,EAAEb,OAAQ,CAAC,EAAG;MACvDW,eAAe,CAACE,OAAO,GAAGb,OAAO;MACjCU,OAAO,CAAEV,OAAQ,CAAC;IACnB;EACD,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMc,aAAa,gBAAG1C,IAAA,CAACwB,aAAa;IAACC,QAAQ,EAAGe;EAAc,CAAE,CAAC;EACjE,OAAO,CAAEE,aAAa,EAAEL,IAAI,CAAE;AAC/B","ignoreList":[]}
@@ -0,0 +1 @@
1
+ {"version":3,"names":["View","StyleSheet","useState","useCallback","jsx","_jsx","useResizeObserver","measurements","setMeasurements","onLayout","nativeEvent","width","height","layout","prevState","Math","floor","observer","testID","style","absoluteFill"],"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":"AAAA;AACA;AACA;AACA,SAASA,IAAI,EAAEC,UAAU,QAAQ,cAAc;AAC/C;AACA;AACA;AACA,SAASC,QAAQ,EAAEC,WAAW,QAAQ,oBAAoB;;AAE1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AAjBA,SAAAC,GAAA,IAAAC,IAAA;AAkBA,MAAMC,iBAAiB,GAAGA,CAAA,KAAM;EAC/B,MAAM,CAAEC,YAAY,EAAEC,eAAe,CAAE,GAAGN,QAAQ,CAAE,IAAK,CAAC;EAE1D,MAAMO,QAAQ,GAAGN,WAAW,CAAE,CAAE;IAAEO;EAAY,CAAC,KAAM;IACpD,MAAM;MAAEC,KAAK;MAAEC;IAAO,CAAC,GAAGF,WAAW,CAACG,MAAM;IAC5CL,eAAe,CAAIM,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,gBACbZ,IAAA,CAACL,IAAI;IACJkB,MAAM,EAAC,iBAAiB;IACxBC,KAAK,EAAGlB,UAAU,CAACmB,YAAc;IACjCX,QAAQ,EAAGA;EAAU,CACrB,CACD;EAED,OAAO,CAAEQ,QAAQ,EAAEV,YAAY,CAAE;AAClC,CAAC;AAED,eAAeD,iBAAiB","ignoreList":[]}
@@ -1,108 +1,81 @@
1
1
  /**
2
- * External dependencies
2
+ * WordPress dependencies
3
3
  */
4
-
4
+ import { useRef } from '@wordpress/element';
5
5
  /**
6
- * WordPress dependencies
6
+ * Internal dependencies
7
7
  */
8
- import { useCallback, useLayoutEffect, useRef, useState } from '@wordpress/element';
9
- import { jsx as _jsx } from "react/jsx-runtime";
10
- // We're only using the first element of the size sequences, until future versions of the spec solidify on how
11
- // exactly it'll be used for fragments in multi-column scenarios:
12
- // From the spec:
13
- // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,
14
- // > which occur in multi-column scenarios. However the current definitions of content rect and border box do not
15
- // > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single
16
- // > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.
17
- // > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.
18
- // (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)
8
+ import useEvent from '../use-event';
9
+ import _useLegacyResizeObserver from './_legacy';
10
+ /**
11
+ * External dependencies
12
+ */
13
+
14
+ // This is the current implementation of `useResizeObserver`.
19
15
  //
20
- // Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,
21
- // regardless of the "box" option.
22
- // The spec states the following on this:
23
- // > This does not have any impact on which box dimensions are returned to the defined callback when the event
24
- // > is fired, it solely defines which box the author wishes to observe layout changes on.
25
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
26
- // I'm not exactly clear on what this means, especially when you consider a later section stating the following:
27
- // > This section is non-normative. An author may desire to observe more than one CSS box.
28
- // > In this case, author will need to use multiple ResizeObservers.
29
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
30
- // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.
31
- // For this reason I decided to only return the requested size,
32
- // even though it seems we have access to results for all box types.
33
- // This also means that we get to keep the current api, being able to return a simple { width, height } pair,
34
- // regardless of box option.
35
- const extractSize = entry => {
36
- let entrySize;
37
- if (!entry.contentBoxSize) {
38
- // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.
39
- // See the 6th step in the description for the RO algorithm:
40
- // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h
41
- // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box".
42
- // In real browser implementations of course these objects differ, but the width/height values should be equivalent.
43
- entrySize = [entry.contentRect.width, entry.contentRect.height];
44
- } else if (entry.contentBoxSize[0]) {
45
- const contentBoxSize = entry.contentBoxSize[0];
46
- entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
47
- } else {
48
- // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy
49
- // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.
50
- const contentBoxSize = entry.contentBoxSize;
51
- entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
52
- }
53
- const [width, height] = entrySize.map(d => Math.round(d));
54
- return {
55
- width,
56
- height
57
- };
58
- };
59
- const RESIZE_ELEMENT_STYLES = {
60
- position: 'absolute',
61
- top: 0,
62
- left: 0,
63
- right: 0,
64
- bottom: 0,
65
- pointerEvents: 'none',
66
- opacity: 0,
67
- overflow: 'hidden',
68
- zIndex: -1
69
- };
70
- function ResizeElement({
71
- onResize
72
- }) {
73
- const resizeElementRef = useRef(null);
74
- const resizeCallbackRef = useRef(onResize);
75
- useLayoutEffect(() => {
76
- resizeCallbackRef.current = onResize;
77
- }, [onResize]);
78
- useLayoutEffect(() => {
79
- const resizeElement = resizeElementRef.current;
80
- const resizeObserver = new ResizeObserver(entries => {
81
- for (const entry of entries) {
82
- const newSize = extractSize(entry);
83
- resizeCallbackRef.current(newSize);
84
- }
85
- });
86
- resizeObserver.observe(resizeElement);
87
- return () => {
88
- resizeObserver.unobserve(resizeElement);
89
- };
90
- }, []);
91
- return /*#__PURE__*/_jsx("div", {
92
- ref: resizeElementRef,
93
- style: RESIZE_ELEMENT_STYLES,
94
- "aria-hidden": "true"
16
+ // The legacy implementation is still supported for backwards compatibility.
17
+ // This is achieved by overloading the exported function with both signatures,
18
+ // and detecting which API is being used at runtime.
19
+ function _useResizeObserver(callback, resizeObserverOptions = {}) {
20
+ const callbackEvent = useEvent(callback);
21
+ const observedElementRef = useRef();
22
+ const resizeObserverRef = useRef();
23
+ return useEvent(element => {
24
+ var _resizeObserverRef$cu;
25
+ if (element === observedElementRef.current) {
26
+ return;
27
+ }
28
+ observedElementRef.current = element;
29
+
30
+ // Set up `ResizeObserver`.
31
+ (_resizeObserverRef$cu = resizeObserverRef.current) !== null && _resizeObserverRef$cu !== void 0 ? _resizeObserverRef$cu : resizeObserverRef.current = new ResizeObserver(callbackEvent);
32
+ const {
33
+ current: resizeObserver
34
+ } = resizeObserverRef;
35
+
36
+ // Unobserve previous element.
37
+ if (observedElementRef.current) {
38
+ resizeObserver.unobserve(observedElementRef.current);
39
+ }
40
+
41
+ // Observe new element.
42
+ if (element) {
43
+ resizeObserver.observe(element, resizeObserverOptions);
44
+ }
95
45
  });
96
46
  }
97
- function sizeEquals(a, b) {
98
- return a.width === b.width && a.height === b.height;
99
- }
100
- const NULL_SIZE = {
101
- width: null,
102
- height: null
103
- };
104
47
 
105
48
  /**
49
+ * Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API)
50
+ * for an HTML or SVG element.
51
+ *
52
+ * Pass the returned setter as a callback ref to the React element you want
53
+ * to observe, or use it in layout effects for advanced use cases.
54
+ *
55
+ * @example
56
+ *
57
+ * ```tsx
58
+ * const setElement = useResizeObserver(
59
+ * ( resizeObserverEntries ) => console.log( resizeObserverEntries ),
60
+ * { box: 'border-box' }
61
+ * );
62
+ * <div ref={ setElement } />;
63
+ *
64
+ * // The setter can be used in other ways, for example:
65
+ * useLayoutEffect( () => {
66
+ * setElement( document.querySelector( `data-element-id="${ elementId }"` ) );
67
+ * }, [ elementId ] );
68
+ * ```
69
+ *
70
+ * @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).
71
+ * @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.
72
+ */
73
+
74
+ /**
75
+ * **This is a legacy API and should not be used.**
76
+ *
77
+ * @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`.
78
+ *
106
79
  * Hook which allows to listen to the resize event of any target element when it changes size.
107
80
  * _Note: `useResizeObserver` will report `null` sizes until after first render.
108
81
  *
@@ -121,20 +94,8 @@ const NULL_SIZE = {
121
94
  * };
122
95
  * ```
123
96
  */
124
- export default function useResizeObserver() {
125
- const [size, setSize] = useState(NULL_SIZE);
126
97
 
127
- // Using a ref to track the previous width / height to avoid unnecessary renders.
128
- const previousSizeRef = useRef(NULL_SIZE);
129
- const handleResize = useCallback(newSize => {
130
- if (!sizeEquals(previousSizeRef.current, newSize)) {
131
- previousSizeRef.current = newSize;
132
- setSize(newSize);
133
- }
134
- }, []);
135
- const resizeElement = /*#__PURE__*/_jsx(ResizeElement, {
136
- onResize: handleResize
137
- });
138
- return [resizeElement, size];
98
+ export default function useResizeObserver(callback, options = {}) {
99
+ return callback ? _useResizeObserver(callback, options) : _useLegacyResizeObserver();
139
100
  }
140
101
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["useCallback","useLayoutEffect","useRef","useState","jsx","_jsx","extractSize","entry","entrySize","contentBoxSize","contentRect","width","height","inlineSize","blockSize","map","d","Math","round","RESIZE_ELEMENT_STYLES","position","top","left","right","bottom","pointerEvents","opacity","overflow","zIndex","ResizeElement","onResize","resizeElementRef","resizeCallbackRef","current","resizeElement","resizeObserver","ResizeObserver","entries","newSize","observe","unobserve","ref","style","sizeEquals","a","b","NULL_SIZE","useResizeObserver","size","setSize","previousSizeRef","handleResize"],"sources":["@wordpress/compose/src/hooks/use-resize-observer/index.tsx"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { ReactElement } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport {\n\tuseCallback,\n\tuseLayoutEffect,\n\tuseRef,\n\tuseState,\n} from '@wordpress/element';\n\ntype 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 = useRef< HTMLDivElement >( null );\n\tconst resizeCallbackRef = useRef( onResize );\n\n\tuseLayoutEffect( () => {\n\t\tresizeCallbackRef.current = onResize;\n\t}, [ onResize ] );\n\n\tuseLayoutEffect( () => {\n\t\tconst resizeElement = resizeElementRef.current as HTMLDivElement;\n\t\tconst resizeObserver = new ResizeObserver( ( entries ) => {\n\t\t\tfor ( const entry of entries ) {\n\t\t\t\tconst newSize = extractSize( entry );\n\t\t\t\tresizeCallbackRef.current( newSize );\n\t\t\t}\n\t\t} );\n\n\t\tresizeObserver.observe( resizeElement );\n\n\t\treturn () => {\n\t\t\tresizeObserver.unobserve( resizeElement );\n\t\t};\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 useResizeObserver(): [ ReactElement, ObservedSize ] {\n\tconst [ size, setSize ] = useState( NULL_SIZE );\n\n\t// Using a ref to track the previous width / height to avoid unnecessary renders.\n\tconst previousSizeRef = useRef( NULL_SIZE );\n\n\tconst handleResize = useCallback( ( newSize: ObservedSize ) => {\n\t\tif ( ! sizeEquals( previousSizeRef.current, newSize ) ) {\n\t\t\tpreviousSizeRef.current = newSize;\n\t\t\tsetSize( newSize );\n\t\t}\n\t}, [] );\n\n\tconst resizeElement = <ResizeElement onResize={ handleResize } />;\n\treturn [ resizeElement, size ];\n}\n"],"mappings":"AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SACCA,WAAW,EACXC,eAAe,EACfC,MAAM,EACNC,QAAQ,QACF,oBAAoB;AAAC,SAAAC,GAAA,IAAAC,IAAA;AAO5B;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,WAAW,GAAKC,KAA0B,IAAoB;EACnE,IAAIC,SAAS;EACb,IAAK,CAAED,KAAK,CAACE,cAAc,EAAG;IAC7B;IACA;IACA;IACA;IACA;IACAD,SAAS,GAAG,CAAED,KAAK,CAACG,WAAW,CAACC,KAAK,EAAEJ,KAAK,CAACG,WAAW,CAACE,MAAM,CAAE;EAClE,CAAC,MAAM,IAAKL,KAAK,CAACE,cAAc,CAAE,CAAC,CAAE,EAAG;IACvC,MAAMA,cAAc,GAAGF,KAAK,CAACE,cAAc,CAAE,CAAC,CAAE;IAChDD,SAAS,GAAG,CAAEC,cAAc,CAACI,UAAU,EAAEJ,cAAc,CAACK,SAAS,CAAE;EACpE,CAAC,MAAM;IACN;IACA;IACA,MAAML,cAAc,GACnBF,KAAK,CAACE,cAA+C;IACtDD,SAAS,GAAG,CAAEC,cAAc,CAACI,UAAU,EAAEJ,cAAc,CAACK,SAAS,CAAE;EACpE;EAEA,MAAM,CAAEH,KAAK,EAAEC,MAAM,CAAE,GAAGJ,SAAS,CAACO,GAAG,CAAIC,CAAC,IAAMC,IAAI,CAACC,KAAK,CAAEF,CAAE,CAAE,CAAC;EACnE,OAAO;IAAEL,KAAK;IAAEC;EAAO,CAAC;AACzB,CAAC;AA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AIiC,CAAC,CAAChC,MAAM,KAAKiC,CAAC,CAACjC,MAAM;AACpD;AAEA,MAAMkC,SAAuB,GAAG;EAAEnC,KAAK,EAAE,IAAI;EAAEC,MAAM,EAAE;AAAK,CAAC;;AAE7D;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASmC,iBAAiBA,CAAA,EAAmC;EAC3E,MAAM,CAAEC,IAAI,EAAEC,OAAO,CAAE,GAAG9C,QAAQ,CAAE2C,SAAU,CAAC;;EAE/C;EACA,MAAMI,eAAe,GAAGhD,MAAM,CAAE4C,SAAU,CAAC;EAE3C,MAAMK,YAAY,GAAGnD,WAAW,CAAIsC,OAAqB,IAAM;IAC9D,IAAK,CAAEK,UAAU,CAAEO,eAAe,CAACjB,OAAO,EAAEK,OAAQ,CAAC,EAAG;MACvDY,eAAe,CAACjB,OAAO,GAAGK,OAAO;MACjCW,OAAO,CAAEX,OAAQ,CAAC;IACnB;EACD,CAAC,EAAE,EAAG,CAAC;EAEP,MAAMJ,aAAa,gBAAG7B,IAAA,CAACwB,aAAa;IAACC,QAAQ,EAAGqB;EAAc,CAAE,CAAC;EACjE,OAAO,CAAEjB,aAAa,EAAEc,IAAI,CAAE;AAC/B","ignoreList":[]}
1
+ {"version":3,"names":["useRef","useEvent","_useLegacyResizeObserver","_useResizeObserver","callback","resizeObserverOptions","callbackEvent","observedElementRef","resizeObserverRef","element","_resizeObserverRef$cu","current","ResizeObserver","resizeObserver","unobserve","observe","useResizeObserver","options"],"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":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,oBAAoB;AAC3C;AACA;AACA;AACA,OAAOC,QAAQ,MAAM,cAAc;AAEnC,OAAOC,wBAAwB,MAAM,WAAW;AAChD;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASC,kBAAkBA,CAC1BC,QAAgC,EAChCC,qBAA4C,GAAG,CAAC,CAAC,EAChB;EACjC,MAAMC,aAAa,GAAGL,QAAQ,CAAEG,QAAS,CAAC;EAE1C,MAAMG,kBAAkB,GAAGP,MAAM,CAAa,CAAC;EAC/C,MAAMQ,iBAAiB,GAAGR,MAAM,CAAmB,CAAC;EACpD,OAAOC,QAAQ,CAAIQ,OAAkB,IAAM;IAAA,IAAAC,qBAAA;IAC1C,IAAKD,OAAO,KAAKF,kBAAkB,CAACI,OAAO,EAAG;MAC7C;IACD;IACAJ,kBAAkB,CAACI,OAAO,GAAGF,OAAO;;IAEpC;IACA,CAAAC,qBAAA,GAAAF,iBAAiB,CAACG,OAAO,cAAAD,qBAAA,cAAAA,qBAAA,GAAzBF,iBAAiB,CAACG,OAAO,GAAK,IAAIC,cAAc,CAAEN,aAAc,CAAC;IACjE,MAAM;MAAEK,OAAO,EAAEE;IAAe,CAAC,GAAGL,iBAAiB;;IAErD;IACA,IAAKD,kBAAkB,CAACI,OAAO,EAAG;MACjCE,cAAc,CAACC,SAAS,CAAEP,kBAAkB,CAACI,OAAQ,CAAC;IACvD;;IAEA;IACA,IAAKF,OAAO,EAAG;MACdI,cAAc,CAACE,OAAO,CAAEN,OAAO,EAAEJ,qBAAsB,CAAC;IACzD;EACD,CAAE,CAAC;AACJ;;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;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGA,eAAe,SAASW,iBAAiBA,CACxCZ,QAAiC,EACjCa,OAA8B,GAAG,CAAC,CAAC,EACmC;EACtE,OAAOb,QAAQ,GACZD,kBAAkB,CAAEC,QAAQ,EAAEa,OAAQ,CAAC,GACvCf,wBAAwB,CAAC,CAAC;AAC9B","ignoreList":[]}
@@ -25,6 +25,7 @@ export { default as useCopyOnClick } from './hooks/use-copy-on-click';
25
25
  export { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';
26
26
  export { default as __experimentalUseDialog } from './hooks/use-dialog';
27
27
  export { default as useDisabled } from './hooks/use-disabled';
28
+ export { default as useEvent } from './hooks/use-event';
28
29
  export { default as __experimentalUseDragging } from './hooks/use-dragging';
29
30
  export { default as useFocusOnMount } from './hooks/use-focus-on-mount';
30
31
  export { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';
@@ -1 +1 @@
1
- {"version":3,"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","useConstrainedTabbing","useCopyOnClick","useCopyToClipboard","__experimentalUseDialog","useDisabled","__experimentalUseDragging","useFocusOnMount","__experimentalUseFocusOutside","useFocusReturn","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useStateWithHistory","useViewportMatch","useResizeObserver","useAsyncList","useWarnOnChange","useDebounce","useDebouncedInput","useThrottle","useMergeRefs","useRefEffect","__experimentalUseDropZone","useFocusableIframe","__experimentalUseFixedWindowList","useObservableValue"],"sources":["@wordpress/compose/src/index.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n// The `ObservableMap` data structure\nexport * from './utils/observable-map';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useStateWithHistory } from './hooks/use-state-with-history';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\nexport { default as useObservableValue } from './hooks/use-observable-value';\n"],"mappings":"AAAA;AACA,cAAc,uCAAuC;AACrD;AACA,cAAc,kBAAkB;AAChC;AACA,cAAc,kBAAkB;AAChC;AACA,cAAc,wBAAwB;;AAEtC;AACA,SAASA,OAAO,IAAIC,OAAO,QAAQ,wBAAwB;AAC3D,SAASD,OAAO,IAAIE,IAAI,QAAQ,qBAAqB;;AAErD;AACA,SAASF,OAAO,IAAIG,WAAW,QAAQ,6BAA6B;AACpE,SAASH,OAAO,IAAII,IAAI,QAAQ,qBAAqB;AACrD,SAASJ,OAAO,IAAIK,gBAA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C7D,SAAS7B,OAAO,IAAI8B,iBAAiB,QAAQ,6BAA6B;AAC1E,SAAS9B,OAAO,IAAI+B,WAAW,QAAQ,sBAAsB;AAC7D,SAAS/B,OAAO,IAAIgC,YAAY,QAAQ,wBAAwB;AAChE,SAAShC,OAAO,IAAIiC,YAAY,QAAQ,wBAAwB;AAChE,SAASjC,OAAO,IAAIkC,yBAAyB,QAAQ,uBAAuB;AAC5E,SAASlC,OAAO,IAAImC,kBAAkB,QAAQ,8BAA8B;AAC5E,SAASnC,OAAO,IAAIoC,gCAAgC,QAAQ,+BAA+B;AAC3F,SAASpC,OAAO,IAAIqC,kBAAkB,QAAQ,8BAA8B","ignoreList":[]}
1
+ {"version":3,"names":["default","compose","pipe","ifCondition","pure","withGlobalEvents","withInstanceId","withSafeTimeout","withState","useConstrainedTabbing","useCopyOnClick","useCopyToClipboard","__experimentalUseDialog","useDisabled","useEvent","__experimentalUseDragging","useFocusOnMount","__experimentalUseFocusOutside","useFocusReturn","useInstanceId","useIsomorphicLayoutEffect","useKeyboardShortcut","useMediaQuery","usePrevious","useReducedMotion","useStateWithHistory","useViewportMatch","useResizeObserver","useAsyncList","useWarnOnChange","useDebounce","useDebouncedInput","useThrottle","useMergeRefs","useRefEffect","__experimentalUseDropZone","useFocusableIframe","__experimentalUseFixedWindowList","useObservableValue"],"sources":["@wordpress/compose/src/index.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n// The `ObservableMap` data structure\nexport * from './utils/observable-map';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as useEvent } from './hooks/use-event';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useStateWithHistory } from './hooks/use-state-with-history';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useDebouncedInput } from './hooks/use-debounced-input';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\nexport { default as useObservableValue } from './hooks/use-observable-value';\n"],"mappings":"AAAA;AACA,cAAc,uCAAuC;AACrD;AACA,cAAc,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","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;;GAcG;AACH,wNAXG;IAAwC,eAAe;IACf,UAAU;IACV,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,UAAU,QAAtC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,SAAS,QAArC,UAAU,KAAK,IAAI;IACS,MAAM,QAAlC,SAAS,KAAK,IAAI;CAE9B,GAAS,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAoMnD"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * Any function.
3
+ */
4
+ export type AnyFunction = (...args: any) => any;
5
+ /**
6
+ * Creates a stable callback function that has access to the latest state and
7
+ * can be used within event handlers and effect callbacks. Throws when used in
8
+ * the render phase.
9
+ *
10
+ * @param callback The callback function to wrap.
11
+ *
12
+ * @example
13
+ *
14
+ * ```tsx
15
+ * function Component( props ) {
16
+ * const onClick = useEvent( props.onClick );
17
+ * useEffect( () => {
18
+ * onClick();
19
+ * // Won't trigger the effect again when props.onClick is updated.
20
+ * }, [ onClick ] );
21
+ * // Won't re-render Button when props.onClick is updated (if `Button` is
22
+ * // wrapped in `React.memo`).
23
+ * return <Button onClick={ onClick } />;
24
+ * }
25
+ * ```
26
+ */
27
+ export default function useEvent<T extends AnyFunction>(
28
+ /**
29
+ * The callback function to wrap.
30
+ */
31
+ callback?: T): T;
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-event/index.ts"],"names":[],"mappings":"AAKA;;GAEG;AACH,MAAM,MAAM,WAAW,GAAG,CAAE,GAAG,IAAI,EAAE,GAAG,KAAM,GAAG,CAAC;AAElD;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,MAAM,CAAC,OAAO,UAAU,QAAQ,CAAE,CAAC,SAAS,WAAW;AACtD;;GAEG;AACH,QAAQ,CAAC,EAAE,CAAC,GAaP,CAAC,CACN"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-on-mount/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uDAlBW,OAAO,GAAG,cAAc,GACvB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAuEnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-on-mount/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uDAlBW,OAAO,GAAG,cAAc,GACvB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAqEnD"}
@@ -0,0 +1,32 @@
1
+ /**
2
+ * External dependencies
3
+ */
4
+ import type { ReactElement } from 'react';
5
+ export type ObservedSize = {
6
+ width: number | null;
7
+ height: number | null;
8
+ };
9
+ /**
10
+ * Hook which allows to listen to the resize event of any target element when it changes size.
11
+ * _Note: `useResizeObserver` will report `null` sizes until after first render.
12
+ *
13
+ * @example
14
+ *
15
+ * ```js
16
+ * const App = () => {
17
+ * const [ resizeListener, sizes ] = useResizeObserver();
18
+ *
19
+ * return (
20
+ * <div>
21
+ * { resizeListener }
22
+ * Your content here
23
+ * </div>
24
+ * );
25
+ * };
26
+ * ```
27
+ */
28
+ export default function useLegacyResizeObserver(): [
29
+ ReactElement,
30
+ ObservedSize
31
+ ];
32
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/hooks/use-resize-observer/_legacy/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAW1C,MAAM,MAAM,YAAY,GAAG;IAC1B,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AAwFF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,uBAAuB,IAAI;IAClD,YAAY;IACZ,YAAY;CACZ,CAeA"}
@@ -1,12 +1,47 @@
1
+ import type { ObservedSize } from './_legacy';
1
2
  /**
2
3
  * External dependencies
3
4
  */
4
5
  import type { ReactElement } from 'react';
5
- type ObservedSize = {
6
- width: number | null;
7
- height: number | null;
8
- };
9
6
  /**
7
+ * Sets up a [`ResizeObserver`](https://developer.mozilla.org/en-US/docs/Web/API/Resize_Observer_API)
8
+ * for an HTML or SVG element.
9
+ *
10
+ * Pass the returned setter as a callback ref to the React element you want
11
+ * to observe, or use it in layout effects for advanced use cases.
12
+ *
13
+ * @example
14
+ *
15
+ * ```tsx
16
+ * const setElement = useResizeObserver(
17
+ * ( resizeObserverEntries ) => console.log( resizeObserverEntries ),
18
+ * { box: 'border-box' }
19
+ * );
20
+ * <div ref={ setElement } />;
21
+ *
22
+ * // The setter can be used in other ways, for example:
23
+ * useLayoutEffect( () => {
24
+ * setElement( document.querySelector( `data-element-id="${ elementId }"` ) );
25
+ * }, [ elementId ] );
26
+ * ```
27
+ *
28
+ * @param callback The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).
29
+ * @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.
30
+ */
31
+ export default function useResizeObserver<T extends Element>(
32
+ /**
33
+ * The `ResizeObserver` callback - [MDN docs](https://developer.mozilla.org/en-US/docs/Web/API/ResizeObserver/ResizeObserver#callback).
34
+ */
35
+ callback: ResizeObserverCallback,
36
+ /**
37
+ * 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.
38
+ */
39
+ options?: ResizeObserverOptions): (element?: T | null) => void;
40
+ /**
41
+ * **This is a legacy API and should not be used.**
42
+ *
43
+ * @deprecated Use the other `useResizeObserver` API instead: `const ref = useResizeObserver( ( entries ) => { ... } )`.
44
+ *
10
45
  * Hook which allows to listen to the resize event of any target element when it changes size.
11
46
  * _Note: `useResizeObserver` will report `null` sizes until after first render.
12
47
  *
@@ -26,5 +61,4 @@ type ObservedSize = {
26
61
  * ```
27
62
  */
28
63
  export default function useResizeObserver(): [ReactElement, ObservedSize];
29
- export {};
30
64
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-resize-observer/index.tsx"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAY1C,KAAK,YAAY,GAAG;IACnB,KAAK,EAAE,MAAM,GAAG,IAAI,CAAC;IACrB,MAAM,EAAE,MAAM,GAAG,IAAI,CAAC;CACtB,CAAC;AA0GF;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,IAAI,CAAE,YAAY,EAAE,YAAY,CAAE,CAe1E"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-resize-observer/index.ts"],"names":[],"mappings":"AAQA,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,WAAW,CAAC;AAE9C;;GAEG;AACH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,OAAO,CAAC;AAqC1C;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAE,CAAC,SAAS,OAAO;AAC3D;;GAEG;AACH,QAAQ,EAAE,sBAAsB;AAChC;;GAEG;AACH,OAAO,CAAC,EAAE,qBAAqB,GAC7B,CAAE,OAAO,CAAC,EAAE,CAAC,GAAG,IAAI,KAAM,IAAI,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,IAAI,CAAE,YAAY,EAAE,YAAY,CAAE,CAAC"}