@wordpress/compose 7.7.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 (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
@@ -1,115 +1,90 @@
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
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
17
+ */
18
+
19
+ /**
20
+ * External dependencies
15
21
  */
16
22
 
17
- // We're only using the first element of the size sequences, until future versions of the spec solidify on how
18
- // exactly it'll be used for fragments in multi-column scenarios:
19
- // From the spec:
20
- // > The box size properties are exposed as FrozenArray in order to support elements that have multiple fragments,
21
- // > which occur in multi-column scenarios. However the current definitions of content rect and border box do not
22
- // > mention how those boxes are affected by multi-column layout. In this spec, there will only be a single
23
- // > ResizeObserverSize returned in the FrozenArray, which will correspond to the dimensions of the first column.
24
- // > A future version of this spec will extend the returned FrozenArray to contain the per-fragment size information.
25
- // (https://drafts.csswg.org/resize-observer/#resize-observer-entry-interface)
23
+ // This is the current implementation of `useResizeObserver`.
26
24
  //
27
- // Also, testing these new box options revealed that in both Chrome and FF everything is returned in the callback,
28
- // regardless of the "box" option.
29
- // The spec states the following on this:
30
- // > This does not have any impact on which box dimensions are returned to the defined callback when the event
31
- // > is fired, it solely defines which box the author wishes to observe layout changes on.
32
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
33
- // I'm not exactly clear on what this means, especially when you consider a later section stating the following:
34
- // > This section is non-normative. An author may desire to observe more than one CSS box.
35
- // > In this case, author will need to use multiple ResizeObservers.
36
- // (https://drafts.csswg.org/resize-observer/#resize-observer-interface)
37
- // Which is clearly not how current browser implementations behave, and seems to contradict the previous quote.
38
- // For this reason I decided to only return the requested size,
39
- // even though it seems we have access to results for all box types.
40
- // This also means that we get to keep the current api, being able to return a simple { width, height } pair,
41
- // regardless of box option.
42
- const extractSize = entry => {
43
- let entrySize;
44
- if (!entry.contentBoxSize) {
45
- // The dimensions in `contentBoxSize` and `contentRect` are equivalent according to the spec.
46
- // See the 6th step in the description for the RO algorithm:
47
- // https://drafts.csswg.org/resize-observer/#create-and-populate-resizeobserverentry-h
48
- // > Set this.contentRect to logical this.contentBoxSize given target and observedBox of "content-box".
49
- // In real browser implementations of course these objects differ, but the width/height values should be equivalent.
50
- entrySize = [entry.contentRect.width, entry.contentRect.height];
51
- } else if (entry.contentBoxSize[0]) {
52
- const contentBoxSize = entry.contentBoxSize[0];
53
- entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
54
- } else {
55
- // TS complains about this, because the RO entry type follows the spec and does not reflect Firefox's buggy
56
- // behaviour of returning objects instead of arrays for `borderBoxSize` and `contentBoxSize`.
57
- const contentBoxSize = entry.contentBoxSize;
58
- entrySize = [contentBoxSize.inlineSize, contentBoxSize.blockSize];
59
- }
60
- const [width, height] = entrySize.map(d => Math.round(d));
61
- return {
62
- width,
63
- height
64
- };
65
- };
66
- const RESIZE_ELEMENT_STYLES = {
67
- position: 'absolute',
68
- top: 0,
69
- left: 0,
70
- right: 0,
71
- bottom: 0,
72
- pointerEvents: 'none',
73
- opacity: 0,
74
- overflow: 'hidden',
75
- zIndex: -1
76
- };
77
- function ResizeElement({
78
- onResize
79
- }) {
80
- const resizeElementRef = (0, _element.useRef)(null);
81
- const resizeCallbackRef = (0, _element.useRef)(onResize);
82
- (0, _element.useLayoutEffect)(() => {
83
- resizeCallbackRef.current = onResize;
84
- }, [onResize]);
85
- (0, _element.useLayoutEffect)(() => {
86
- const resizeElement = resizeElementRef.current;
87
- const resizeObserver = new ResizeObserver(entries => {
88
- for (const entry of entries) {
89
- const newSize = extractSize(entry);
90
- resizeCallbackRef.current(newSize);
91
- }
92
- });
93
- resizeObserver.observe(resizeElement);
94
- return () => {
95
- resizeObserver.unobserve(resizeElement);
96
- };
97
- }, []);
98
- return /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
99
- ref: resizeElementRef,
100
- style: RESIZE_ELEMENT_STYLES,
101
- "aria-hidden": "true"
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)();
31
+ const resizeObserverRef = (0, _element.useRef)();
32
+ return (0, _useEvent.default)(element => {
33
+ var _resizeObserverRef$cu;
34
+ if (element === observedElementRef.current) {
35
+ return;
36
+ }
37
+ observedElementRef.current = element;
38
+
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;
44
+
45
+ // Unobserve previous element.
46
+ if (observedElementRef.current) {
47
+ resizeObserver.unobserve(observedElementRef.current);
48
+ }
49
+
50
+ // Observe new element.
51
+ if (element) {
52
+ resizeObserver.observe(element, resizeObserverOptions);
53
+ }
102
54
  });
103
55
  }
104
- function sizeEquals(a, b) {
105
- return a.width === b.width && a.height === b.height;
106
- }
107
- const NULL_SIZE = {
108
- width: null,
109
- height: null
110
- };
111
56
 
112
57
  /**
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
+ *
113
88
  * Hook which allows to listen to the resize event of any target element when it changes size.
114
89
  * _Note: `useResizeObserver` will report `null` sizes until after first render.
115
90
  *
@@ -128,20 +103,8 @@ const NULL_SIZE = {
128
103
  * };
129
104
  * ```
130
105
  */
131
- function useResizeObserver() {
132
- const [size, setSize] = (0, _element.useState)(NULL_SIZE);
133
106
 
134
- // Using a ref to track the previous width / height to avoid unnecessary renders.
135
- const previousSizeRef = (0, _element.useRef)(NULL_SIZE);
136
- const handleResize = (0, _element.useCallback)(newSize => {
137
- if (!sizeEquals(previousSizeRef.current, newSize)) {
138
- previousSizeRef.current = newSize;
139
- setSize(newSize);
140
- }
141
- }, []);
142
- const resizeElement = /*#__PURE__*/(0, _jsxRuntime.jsx)(ResizeElement, {
143
- onResize: handleResize
144
- });
145
- return [resizeElement, size];
107
+ function useResizeObserver(callback, options = {}) {
108
+ return callback ? _useResizeObserver(callback, options) : (0, _legacy.default)();
146
109
  }
147
110
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_element","require","_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","useRef","resizeCallbackRef","useLayoutEffect","current","resizeElement","resizeObserver","ResizeObserver","entries","newSize","observe","unobserve","jsx","ref","style","sizeEquals","a","b","NULL_SIZE","useResizeObserver","size","setSize","useState","previousSizeRef","handleResize","useCallback"],"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":";;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AAK4B,IAAAC,WAAA,GAAAD,OAAA;AAb5B;AACA;AACA;;AAGA;AACA;AACA;;AAaA;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,MAAME,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,GAC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ault","_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"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A;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAGe,SAASa,iBAAiBA,CACxCd,QAAiC,EACjCe,OAA8B,GAAG,CAAC,CAAC,EACmC;EACtE,OAAOf,QAAQ,GACZD,kBAAkB,CAAEC,QAAQ,EAAEe,OAAQ,CAAC,GACvC,IAAAC,eAAwB,EAAC,CAAC;AAC9B","ignoreList":[]}
package/build/index.js CHANGED
@@ -18,6 +18,7 @@ var _exportNames = {
18
18
  useCopyToClipboard: true,
19
19
  __experimentalUseDialog: true,
20
20
  useDisabled: true,
21
+ useEvent: true,
21
22
  __experimentalUseDragging: true,
22
23
  useFocusOnMount: true,
23
24
  __experimentalUseFocusOutside: true,
@@ -139,6 +140,12 @@ Object.defineProperty(exports, "useDisabled", {
139
140
  return _useDisabled.default;
140
141
  }
141
142
  });
143
+ Object.defineProperty(exports, "useEvent", {
144
+ enumerable: true,
145
+ get: function () {
146
+ return _useEvent.default;
147
+ }
148
+ });
142
149
  Object.defineProperty(exports, "useFocusOnMount", {
143
150
  enumerable: true,
144
151
  get: function () {
@@ -326,6 +333,7 @@ var _useCopyOnClick = _interopRequireDefault(require("./hooks/use-copy-on-click"
326
333
  var _useCopyToClipboard = _interopRequireDefault(require("./hooks/use-copy-to-clipboard"));
327
334
  var _useDialog = _interopRequireDefault(require("./hooks/use-dialog"));
328
335
  var _useDisabled = _interopRequireDefault(require("./hooks/use-disabled"));
336
+ var _useEvent = _interopRequireDefault(require("./hooks/use-event"));
329
337
  var _useDragging = _interopRequireDefault(require("./hooks/use-dragging"));
330
338
  var _useFocusOnMount = _interopRequireDefault(require("./hooks/use-focus-on-mount"));
331
339
  var _useFocusOutside = _interopRequireDefault(require("./hooks/use-focus-outside"));
@@ -1 +1 @@
1
- {"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_observableMap","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_useConstrainedTabbing","_useCopyOnClick","_useCopyToClipboard","_useDialog","_useDisabled","_useDragging","_useFocusOnMount","_useFocusOutside","_useFocusReturn","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useStateWithHistory","_useViewportMatch","_useResizeObserver","_useAsyncList","_useWarnOnChange","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect","_useDropZone","_useFocusableIframe","_useFixedWindowList","_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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,2BAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,2BAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAA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AAjB,sBAAA,CAAAjB,OAAA;AACA,IAAAmC,0BAAA,GAAAlB,sBAAA,CAAAjB,OAAA;AACA,IAAAoC,oBAAA,GAAAnB,sBAAA,CAAAjB,OAAA;AACA,IAAAqC,cAAA,GAAApB,sBAAA,CAAAjB,OAAA;AACA,IAAAsC,YAAA,GAAArB,sBAAA,CAAAjB,OAAA;AACA,IAAAuC,iBAAA,GAAAtB,sBAAA,CAAAjB,OAAA;AACA,IAAAwC,oBAAA,GAAAvB,sBAAA,CAAAjB,OAAA;AACA,IAAAyC,iBAAA,GAAAxB,sBAAA,CAAAjB,OAAA;AACA,IAAA0C,kBAAA,GAAAzB,sBAAA,CAAAjB,OAAA;AACA,IAAA2C,aAAA,GAAA1B,sBAAA,CAAAjB,OAAA;AACA,IAAA4C,gBAAA,GAAA3B,sBAAA,CAAAjB,OAAA;AACA,IAAA6C,YAAA,GAAA5B,sBAAA,CAAAjB,OAAA;AACA,IAAA8C,kBAAA,GAAA7B,sBAAA,CAAAjB,OAAA;AACA,IAAA+C,YAAA,GAAA9B,sBAAA,CAAAjB,OAAA;AACA,IAAAgD,aAAA,GAAA/B,sBAAA,CAAAjB,OAAA;AACA,IAAAiD,aAAA,GAAAhC,sBAAA,CAAAjB,OAAA;AACA,IAAAkD,YAAA,GAAAjC,sBAAA,CAAAjB,OAAA;AACA,IAAAmD,mBAAA,GAAAlC,sBAAA,CAAAjB,OAAA;AACA,IAAAoD,mBAAA,GAAAnC,sBAAA,CAAAjB,OAAA;AACA,IAAAqD,mBAAA,GAAApC,sBAAA,CAAAjB,OAAA","ignoreList":[]}
1
+ {"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_observableMap","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_useConstrainedTabbing","_useCopyOnClick","_useCopyToClipboard","_useDialog","_useDisabled","_useEvent","_useDragging","_useFocusOnMount","_useFocusOutside","_useFocusReturn","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useStateWithHistory","_useViewportMatch","_useResizeObserver","_useAsyncList","_useWarnOnChange","_useDebounce","_useDebouncedInput","_useThrottle","_useMergeRefs","_useRefEffect","_useDropZone","_useFocusableIframe","_useFixedWindowList","_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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,2BAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,2BAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAA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oC,0BAAA,GAAAnB,sBAAA,CAAAjB,OAAA;AACA,IAAAqC,oBAAA,GAAApB,sBAAA,CAAAjB,OAAA;AACA,IAAAsC,cAAA,GAAArB,sBAAA,CAAAjB,OAAA;AACA,IAAAuC,YAAA,GAAAtB,sBAAA,CAAAjB,OAAA;AACA,IAAAwC,iBAAA,GAAAvB,sBAAA,CAAAjB,OAAA;AACA,IAAAyC,oBAAA,GAAAxB,sBAAA,CAAAjB,OAAA;AACA,IAAA0C,iBAAA,GAAAzB,sBAAA,CAAAjB,OAAA;AACA,IAAA2C,kBAAA,GAAA1B,sBAAA,CAAAjB,OAAA;AACA,IAAA4C,aAAA,GAAA3B,sBAAA,CAAAjB,OAAA;AACA,IAAA6C,gBAAA,GAAA5B,sBAAA,CAAAjB,OAAA;AACA,IAAA8C,YAAA,GAAA7B,sBAAA,CAAAjB,OAAA;AACA,IAAA+C,kBAAA,GAAA9B,sBAAA,CAAAjB,OAAA;AACA,IAAAgD,YAAA,GAAA/B,sBAAA,CAAAjB,OAAA;AACA,IAAAiD,aAAA,GAAAhC,sBAAA,CAAAjB,OAAA;AACA,IAAAkD,aAAA,GAAAjC,sBAAA,CAAAjB,OAAA;AACA,IAAAmD,YAAA,GAAAlC,sBAAA,CAAAjB,OAAA;AACA,IAAAoD,mBAAA,GAAAnC,sBAAA,CAAAjB,OAAA;AACA,IAAAqD,mBAAA,GAAApC,sBAAA,CAAAjB,OAAA;AACA,IAAAsD,mBAAA,GAAArC,sBAAA,CAAAjB,OAAA","ignoreList":[]}
@@ -147,6 +147,7 @@ export default function useDropZone({
147
147
  // zone.
148
148
  // Note: This is not entirely reliable in Safari due to this bug
149
149
  // https://bugs.webkit.org/show_bug.cgi?id=66547
150
+
150
151
  if (isElementInZone(event.relatedTarget)) {
151
152
  return;
152
153
  }
@@ -1 +1 @@
1
- {"version":3,"names":["useRef","useRefEffect","useFreshRef","value","ref","current","useDropZone","dropZoneElement","isDisabled","onDrop","_onDrop","onDragStart","_onDragStart","onDragEnter","_onDragEnter","onDragLeave","_onDragLeave","onDragEnd","_onDragEnd","onDragOver","_onDragOver","onDropRef","onDragStartRef","onDragEnterRef","onDragLeaveRef","onDragEndRef","onDragOverRef","elem","element","isDragging","ownerDocument","isElementInZone","targetToCheck","defaultView","HTMLElement","contains","elementToCheck","dataset","isDropZone","parentElement","maybeDragStart","event","addEventListener","maybeDragEnd","preventDefault","relatedTarget","defaultPrevented","dataTransfer","files","length","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-drop-zone/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @param {T} value\n * @return {import('react').MutableRefObject<T|null>} A ref with the value.\n */\nfunction useFreshRef( value ) {\n\t/* eslint-enable jsdoc/valid-types */\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<T>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\t// Disable reason: We're doing something pretty JavaScript-y here where the\n\t// ref will always have a current value that is not null or undefined but it\n\t// needs to start as undefined. We don't want to change the return type so\n\t// it's easier to just ts-ignore this specific line that's complaining about\n\t// undefined not being part of T.\n\t// @ts-ignore\n\tconst ref = useRef();\n\tref.current = value;\n\treturn ref;\n}\n\n/**\n * A hook to facilitate drag and drop handling.\n *\n * @param {Object} props Named parameters.\n * @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone.\n * @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.\n * @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.\n * @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.\n * @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.\n * @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.\n * @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.\n * @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.\n *\n * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.\n */\nexport default function useDropZone( {\n\tdropZoneElement,\n\tisDisabled,\n\tonDrop: _onDrop,\n\tonDragStart: _onDragStart,\n\tonDragEnter: _onDragEnter,\n\tonDragLeave: _onDragLeave,\n\tonDragEnd: _onDragEnd,\n\tonDragOver: _onDragOver,\n} ) {\n\tconst onDropRef = useFreshRef( _onDrop );\n\tconst onDragStartRef = useFreshRef( _onDragStart );\n\tconst onDragEnterRef = useFreshRef( _onDragEnter );\n\tconst onDragLeaveRef = useFreshRef( _onDragLeave );\n\tconst onDragEndRef = useFreshRef( _onDragEnd );\n\tconst onDragOverRef = useFreshRef( _onDragOver );\n\n\treturn useRefEffect(\n\t\t( elem ) => {\n\t\t\tif ( isDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If a custom dropZoneRef is passed, use that instead of the element.\n\t\t\t// This allows the dropzone to cover an expanded area, rather than\n\t\t\t// be restricted to the area of the ref returned by this hook.\n\t\t\tconst element = dropZoneElement ?? elem;\n\n\t\t\tlet isDragging = false;\n\n\t\t\tconst { ownerDocument } = element;\n\n\t\t\t/**\n\t\t\t * Checks if an element is in the drop zone.\n\t\t\t *\n\t\t\t * @param {EventTarget|null} targetToCheck\n\t\t\t *\n\t\t\t * @return {boolean} True if in drop zone, false if not.\n\t\t\t */\n\t\t\tfunction isElementInZone( targetToCheck ) {\n\t\t\t\tconst { defaultView } = ownerDocument;\n\t\t\t\tif (\n\t\t\t\t\t! targetToCheck ||\n\t\t\t\t\t! defaultView ||\n\t\t\t\t\t! ( targetToCheck instanceof defaultView.HTMLElement ) ||\n\t\t\t\t\t! element.contains( targetToCheck )\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t/** @type {HTMLElement|null} */\n\t\t\t\tlet elementToCheck = targetToCheck;\n\n\t\t\t\tdo {\n\t\t\t\t\tif ( elementToCheck.dataset.isDropZone ) {\n\t\t\t\t\t\treturn elementToCheck === element;\n\t\t\t\t\t}\n\t\t\t\t} while ( ( elementToCheck = elementToCheck.parentElement ) );\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfunction maybeDragStart( /** @type {DragEvent} */ event ) {\n\t\t\t\tif ( isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = true;\n\n\t\t\t\t// Note that `dragend` doesn't fire consistently for file and\n\t\t\t\t// HTML drag events where the drag origin is outside the browser\n\t\t\t\t// window. In Firefox it may also not fire if the originating\n\t\t\t\t// node is removed.\n\t\t\t\townerDocument.addEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.addEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragStartRef.current ) {\n\t\t\t\t\tonDragStartRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragEnter( /** @type {DragEvent} */ event ) {\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// The `dragenter` event will also fire when entering child\n\t\t\t\t// elements, but we only want to call `onDragEnter` when\n\t\t\t\t// entering the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been left) should be outside the drop zone.\n\t\t\t\tif (\n\t\t\t\t\telement.contains(\n\t\t\t\t\t\t/** @type {Node} */ ( event.relatedTarget )\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragEnterRef.current ) {\n\t\t\t\t\tonDragEnterRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragOver( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Only call onDragOver for the innermost hovered drop zones.\n\t\t\t\tif ( ! event.defaultPrevented && onDragOverRef.current ) {\n\t\t\t\t\tonDragOverRef.current( event );\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDragOver` is already handled.\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\tfunction onDragLeave( /** @type {DragEvent} */ event ) {\n\t\t\t\t// The `dragleave` event will also fire when leaving child\n\t\t\t\t// elements, but we only want to call `onDragLeave` when\n\t\t\t\t// leaving the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been entered) should be outside the drop\n\t\t\t\t// zone.\n\t\t\t\t// Note: This is not entirely reliable in Safari due to this bug\n\t\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=66547\n\t\t\t\tif ( isElementInZone( event.relatedTarget ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragLeaveRef.current ) {\n\t\t\t\t\tonDragLeaveRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDrop( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Don't handle drop if an inner drop zone already handled it.\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDrop` is already handled.\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// This seemingly useless line has been shown to resolve a\n\t\t\t\t// Safari issue where files dragged directly from the dock are\n\t\t\t\t// not recognized.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tevent.dataTransfer && event.dataTransfer.files.length;\n\n\t\t\t\tif ( onDropRef.current ) {\n\t\t\t\t\tonDropRef.current( event );\n\t\t\t\t}\n\n\t\t\t\tmaybeDragEnd( event );\n\t\t\t}\n\n\t\t\tfunction maybeDragEnd( /** @type {MouseEvent} */ event ) {\n\t\t\t\tif ( ! isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = false;\n\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragEndRef.current ) {\n\t\t\t\t\tonDragEndRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telement.dataset.isDropZone = 'true';\n\t\t\telement.addEventListener( 'drop', onDrop );\n\t\t\telement.addEventListener( 'dragenter', onDragEnter );\n\t\t\telement.addEventListener( 'dragover', onDragOver );\n\t\t\telement.addEventListener( 'dragleave', onDragLeave );\n\t\t\t// The `dragstart` event doesn't fire if the drag started outside\n\t\t\t// the document.\n\t\t\townerDocument.addEventListener( 'dragenter', maybeDragStart );\n\n\t\t\treturn () => {\n\t\t\t\tdelete element.dataset.isDropZone;\n\t\t\t\telement.removeEventListener( 'drop', onDrop );\n\t\t\t\telement.removeEventListener( 'dragenter', onDragEnter );\n\t\t\t\telement.removeEventListener( 'dragover', onDragOver );\n\t\t\t\telement.removeEventListener( 'dragleave', onDragLeave );\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'dragenter',\n\t\t\t\t\tmaybeDragStart\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t\t[ isDisabled, dropZoneElement ] // Refresh when the passed in dropZoneElement changes.\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,oBAAoB;;AAE3C;AACA;AACA;AACA,OAAOC,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAAEC,KAAK,EAAG;EAC7B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,GAAG,GAAGJ,MAAM,CAAC,CAAC;EACpBI,GAAG,CAACC,OAAO,GAAGF,KAAK;EACnB,OAAOC,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASE,WAAWA,CAAE;EACpCC,eA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;MACvDe,OAAO,CAACsB,mBAAmB,CAAE,UAAU,EAAE/B,UAAW,CAAC;MACrDS,OAAO,CAACsB,mBAAmB,CAAE,WAAW,EAAEnC,WAAY,CAAC;MACvDe,aAAa,CAACoB,mBAAmB,CAAE,SAAS,EAAEP,YAAa,CAAC;MAC5Db,aAAa,CAACoB,mBAAmB,CAAE,WAAW,EAAEP,YAAa,CAAC;MAC9Db,aAAa,CAACoB,mBAAmB,CAChC,WAAW,EACXV,cACD,CAAC;IACF,CAAC;EACF,CAAC,EACD,CAAEhC,UAAU,EAAED,eAAe,CAAE,CAAC;EACjC,CAAC;AACF","ignoreList":[]}
1
+ {"version":3,"names":["useRef","useRefEffect","useFreshRef","value","ref","current","useDropZone","dropZoneElement","isDisabled","onDrop","_onDrop","onDragStart","_onDragStart","onDragEnter","_onDragEnter","onDragLeave","_onDragLeave","onDragEnd","_onDragEnd","onDragOver","_onDragOver","onDropRef","onDragStartRef","onDragEnterRef","onDragLeaveRef","onDragEndRef","onDragOverRef","elem","element","isDragging","ownerDocument","isElementInZone","targetToCheck","defaultView","HTMLElement","contains","elementToCheck","dataset","isDropZone","parentElement","maybeDragStart","event","addEventListener","maybeDragEnd","preventDefault","relatedTarget","defaultPrevented","dataTransfer","files","length","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-drop-zone/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @param {T} value\n * @return {import('react').MutableRefObject<T|null>} A ref with the value.\n */\nfunction useFreshRef( value ) {\n\t/* eslint-enable jsdoc/valid-types */\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<T>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\t// Disable reason: We're doing something pretty JavaScript-y here where the\n\t// ref will always have a current value that is not null or undefined but it\n\t// needs to start as undefined. We don't want to change the return type so\n\t// it's easier to just ts-ignore this specific line that's complaining about\n\t// undefined not being part of T.\n\t// @ts-ignore\n\tconst ref = useRef();\n\tref.current = value;\n\treturn ref;\n}\n\n/**\n * A hook to facilitate drag and drop handling.\n *\n * @param {Object} props Named parameters.\n * @param {?HTMLElement} [props.dropZoneElement] Optional element to be used as the drop zone.\n * @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.\n * @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.\n * @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.\n * @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.\n * @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.\n * @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.\n * @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.\n *\n * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.\n */\nexport default function useDropZone( {\n\tdropZoneElement,\n\tisDisabled,\n\tonDrop: _onDrop,\n\tonDragStart: _onDragStart,\n\tonDragEnter: _onDragEnter,\n\tonDragLeave: _onDragLeave,\n\tonDragEnd: _onDragEnd,\n\tonDragOver: _onDragOver,\n} ) {\n\tconst onDropRef = useFreshRef( _onDrop );\n\tconst onDragStartRef = useFreshRef( _onDragStart );\n\tconst onDragEnterRef = useFreshRef( _onDragEnter );\n\tconst onDragLeaveRef = useFreshRef( _onDragLeave );\n\tconst onDragEndRef = useFreshRef( _onDragEnd );\n\tconst onDragOverRef = useFreshRef( _onDragOver );\n\n\treturn useRefEffect(\n\t\t( elem ) => {\n\t\t\tif ( isDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If a custom dropZoneRef is passed, use that instead of the element.\n\t\t\t// This allows the dropzone to cover an expanded area, rather than\n\t\t\t// be restricted to the area of the ref returned by this hook.\n\t\t\tconst element = dropZoneElement ?? elem;\n\n\t\t\tlet isDragging = false;\n\n\t\t\tconst { ownerDocument } = element;\n\n\t\t\t/**\n\t\t\t * Checks if an element is in the drop zone.\n\t\t\t *\n\t\t\t * @param {EventTarget|null} targetToCheck\n\t\t\t *\n\t\t\t * @return {boolean} True if in drop zone, false if not.\n\t\t\t */\n\t\t\tfunction isElementInZone( targetToCheck ) {\n\t\t\t\tconst { defaultView } = ownerDocument;\n\n\t\t\t\tif (\n\t\t\t\t\t! targetToCheck ||\n\t\t\t\t\t! defaultView ||\n\t\t\t\t\t! ( targetToCheck instanceof defaultView.HTMLElement ) ||\n\t\t\t\t\t! element.contains( targetToCheck )\n\t\t\t\t) {\n\t\t\t\t\treturn false;\n\t\t\t\t}\n\n\t\t\t\t/** @type {HTMLElement|null} */\n\t\t\t\tlet elementToCheck = targetToCheck;\n\n\t\t\t\tdo {\n\t\t\t\t\tif ( elementToCheck.dataset.isDropZone ) {\n\t\t\t\t\t\treturn elementToCheck === element;\n\t\t\t\t\t}\n\t\t\t\t} while ( ( elementToCheck = elementToCheck.parentElement ) );\n\n\t\t\t\treturn false;\n\t\t\t}\n\n\t\t\tfunction maybeDragStart( /** @type {DragEvent} */ event ) {\n\t\t\t\tif ( isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = true;\n\n\t\t\t\t// Note that `dragend` doesn't fire consistently for file and\n\t\t\t\t// HTML drag events where the drag origin is outside the browser\n\t\t\t\t// window. In Firefox it may also not fire if the originating\n\t\t\t\t// node is removed.\n\t\t\t\townerDocument.addEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.addEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragStartRef.current ) {\n\t\t\t\t\tonDragStartRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragEnter( /** @type {DragEvent} */ event ) {\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// The `dragenter` event will also fire when entering child\n\t\t\t\t// elements, but we only want to call `onDragEnter` when\n\t\t\t\t// entering the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been left) should be outside the drop zone.\n\t\t\t\tif (\n\t\t\t\t\telement.contains(\n\t\t\t\t\t\t/** @type {Node} */ ( event.relatedTarget )\n\t\t\t\t\t)\n\t\t\t\t) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragEnterRef.current ) {\n\t\t\t\t\tonDragEnterRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDragOver( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Only call onDragOver for the innermost hovered drop zones.\n\t\t\t\tif ( ! event.defaultPrevented && onDragOverRef.current ) {\n\t\t\t\t\tonDragOverRef.current( event );\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDragOver` is already handled.\n\t\t\t\tevent.preventDefault();\n\t\t\t}\n\n\t\t\tfunction onDragLeave( /** @type {DragEvent} */ event ) {\n\t\t\t\t// The `dragleave` event will also fire when leaving child\n\t\t\t\t// elements, but we only want to call `onDragLeave` when\n\t\t\t\t// leaving the drop zone, which means the `relatedTarget`\n\t\t\t\t// (element that has been entered) should be outside the drop\n\t\t\t\t// zone.\n\t\t\t\t// Note: This is not entirely reliable in Safari due to this bug\n\t\t\t\t// https://bugs.webkit.org/show_bug.cgi?id=66547\n\n\t\t\t\tif ( isElementInZone( event.relatedTarget ) ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tif ( onDragLeaveRef.current ) {\n\t\t\t\t\tonDragLeaveRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\tfunction onDrop( /** @type {DragEvent} */ event ) {\n\t\t\t\t// Don't handle drop if an inner drop zone already handled it.\n\t\t\t\tif ( event.defaultPrevented ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\t// Prevent the browser default while also signalling to parent\n\t\t\t\t// drop zones that `onDrop` is already handled.\n\t\t\t\tevent.preventDefault();\n\n\t\t\t\t// This seemingly useless line has been shown to resolve a\n\t\t\t\t// Safari issue where files dragged directly from the dock are\n\t\t\t\t// not recognized.\n\t\t\t\t// eslint-disable-next-line no-unused-expressions\n\t\t\t\tevent.dataTransfer && event.dataTransfer.files.length;\n\n\t\t\t\tif ( onDropRef.current ) {\n\t\t\t\t\tonDropRef.current( event );\n\t\t\t\t}\n\n\t\t\t\tmaybeDragEnd( event );\n\t\t\t}\n\n\t\t\tfunction maybeDragEnd( /** @type {MouseEvent} */ event ) {\n\t\t\t\tif ( ! isDragging ) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tisDragging = false;\n\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\n\t\t\t\tif ( onDragEndRef.current ) {\n\t\t\t\t\tonDragEndRef.current( event );\n\t\t\t\t}\n\t\t\t}\n\n\t\t\telement.dataset.isDropZone = 'true';\n\t\t\telement.addEventListener( 'drop', onDrop );\n\t\t\telement.addEventListener( 'dragenter', onDragEnter );\n\t\t\telement.addEventListener( 'dragover', onDragOver );\n\t\t\telement.addEventListener( 'dragleave', onDragLeave );\n\t\t\t// The `dragstart` event doesn't fire if the drag started outside\n\t\t\t// the document.\n\t\t\townerDocument.addEventListener( 'dragenter', maybeDragStart );\n\n\t\t\treturn () => {\n\t\t\t\tdelete element.dataset.isDropZone;\n\t\t\t\telement.removeEventListener( 'drop', onDrop );\n\t\t\t\telement.removeEventListener( 'dragenter', onDragEnter );\n\t\t\t\telement.removeEventListener( 'dragover', onDragOver );\n\t\t\t\telement.removeEventListener( 'dragleave', onDragLeave );\n\t\t\t\townerDocument.removeEventListener( 'dragend', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener( 'mousemove', maybeDragEnd );\n\t\t\t\townerDocument.removeEventListener(\n\t\t\t\t\t'dragenter',\n\t\t\t\t\tmaybeDragStart\n\t\t\t\t);\n\t\t\t};\n\t\t},\n\t\t[ isDisabled, dropZoneElement ] // Refresh when the passed in dropZoneElement changes.\n\t);\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,QAAQ,oBAAoB;;AAE3C;AACA;AACA;AACA,OAAOC,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CAAEC,KAAK,EAAG;EAC7B;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA;EACA,MAAMC,GAAG,GAAGJ,MAAM,CAAC,CAAC;EACpBI,GAAG,CAACC,OAAO,GAAGF,KAAK;EACnB,OAAOC,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASE,WAAWA,CAAE;EACpCC,eAAe;EACfC,UAAU;EACVC,MAAM,EAAEC,OAAO;EACfC,WAAW,EAAEC,YAAY;EACzBC,WAAW,EAAEC,YAAY;EACzBC,WAAW,EAAEC,YAAY;EACzBC,SAAS,EAAEC,UAAU;EACrBC,UAAU,EAAEC;AACb,CAAC,EAAG;EACH,MAAMC,SAAS,GAAGnB,WAAW,CAAEQ,OAAQ,CAAC;EACxC,MAAMY,cAAc,GAAGpB,WAAW,CAAEU,YAAa,CAAC;EAClD,MAAMW,cAAc,GAAGrB,WAAW,CAAEY,YAAa,CAAC;EAClD,MAAMU,cAAc,GAAGtB,WAAW,CAAEc,YAAa,CAAC;EAClD,MAAMS,YAAY,GAAGvB,WAAW,CAAEgB,UAAW,CAAC;EAC9C,MAAMQ,aAAa,GAAGxB,WAAW,CAAEkB,WAAY,CAAC;EAEhD,OAAOnB,YAAY,CAChB0B,IAAI,IAAM;IACX,IAAKnB,UAAU,EAAG;MACjB;IACD;;IAEA;IACA;IACA;IACA,MAAMoB,OAAO,GAAGrB,eAAe,aAAfA,eAAe,cAAfA,eAAe,GAAIoB,IAAI;IAEvC,IAAIE,UAAU,GAAG,KAAK;IAEtB,MAAM;MAAEC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G,MAAM;IACnCV,OAAO,CAACc,gBAAgB,CAAE,MAAM,EAAEjC,MAAO,CAAC;IAC1CmB,OAAO,CAACc,gBAAgB,CAAE,WAAW,EAAE7B,WAAY,CAAC;IACpDe,OAAO,CAACc,gBAAgB,CAAE,UAAU,EAAEvB,UAAW,CAAC;IAClDS,OAAO,CAACc,gBAAgB,CAAE,WAAW,EAAE3B,WAAY,CAAC;IACpD;IACA;IACAe,aAAa,CAACY,gBAAgB,CAAE,WAAW,EAAEF,cAAe,CAAC;IAE7D,OAAO,MAAM;MACZ,OAAOZ,OAAO,CAACS,OAAO,CAACC,UAAU;MACjCV,OAAO,CAACsB,mBAAmB,CAAE,MAAM,EAAEzC,MAAO,CAAC;MAC7CmB,OAAO,CAACsB,mBAAmB,CAAE,WAAW,EAAErC,WAAY,CAAC;MACvDe,OAAO,CAACsB,mBAAmB,CAAE,UAAU,EAAE/B,UAAW,CAAC;MACrDS,OAAO,CAACsB,mBAAmB,CAAE,WAAW,EAAEnC,WAAY,CAAC;MACvDe,aAAa,CAACoB,mBAAmB,CAAE,SAAS,EAAEP,YAAa,CAAC;MAC5Db,aAAa,CAACoB,mBAAmB,CAAE,WAAW,EAAEP,YAAa,CAAC;MAC9Db,aAAa,CAACoB,mBAAmB,CAChC,WAAW,EACXV,cACD,CAAC;IACF,CAAC;EACF,CAAC,EACD,CAAEhC,UAAU,EAAED,eAAe,CAAE,CAAC;EACjC,CAAC;AACF","ignoreList":[]}
@@ -0,0 +1,45 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useRef, useInsertionEffect, useCallback } from '@wordpress/element';
5
+
6
+ /**
7
+ * Any function.
8
+ */
9
+
10
+ /**
11
+ * Creates a stable callback function that has access to the latest state and
12
+ * can be used within event handlers and effect callbacks. Throws when used in
13
+ * the render phase.
14
+ *
15
+ * @param callback The callback function to wrap.
16
+ *
17
+ * @example
18
+ *
19
+ * ```tsx
20
+ * function Component( props ) {
21
+ * const onClick = useEvent( props.onClick );
22
+ * useEffect( () => {
23
+ * onClick();
24
+ * // Won't trigger the effect again when props.onClick is updated.
25
+ * }, [ onClick ] );
26
+ * // Won't re-render Button when props.onClick is updated (if `Button` is
27
+ * // wrapped in `React.memo`).
28
+ * return <Button onClick={ onClick } />;
29
+ * }
30
+ * ```
31
+ */
32
+ export default function useEvent(
33
+ /**
34
+ * The callback function to wrap.
35
+ */
36
+ callback) {
37
+ const ref = useRef(() => {
38
+ throw new Error('Callbacks created with `useEvent` cannot be called during rendering.');
39
+ });
40
+ useInsertionEffect(() => {
41
+ ref.current = callback;
42
+ });
43
+ return useCallback((...args) => ref.current?.(...args), []);
44
+ }
45
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["useRef","useInsertionEffect","useCallback","useEvent","callback","ref","Error","current","args"],"sources":["@wordpress/compose/src/hooks/use-event/index.ts"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useInsertionEffect, useCallback } from '@wordpress/element';\n\n/**\n * Any function.\n */\nexport type AnyFunction = ( ...args: any ) => any;\n\n/**\n * Creates a stable callback function that has access to the latest state and\n * can be used within event handlers and effect callbacks. Throws when used in\n * the render phase.\n *\n * @param callback The callback function to wrap.\n *\n * @example\n *\n * ```tsx\n * function Component( props ) {\n * const onClick = useEvent( props.onClick );\n * useEffect( () => {\n * onClick();\n * // Won't trigger the effect again when props.onClick is updated.\n * }, [ onClick ] );\n * // Won't re-render Button when props.onClick is updated (if `Button` is\n * // wrapped in `React.memo`).\n * return <Button onClick={ onClick } />;\n * }\n * ```\n */\nexport default function useEvent< T extends AnyFunction >(\n\t/**\n\t * The callback function to wrap.\n\t */\n\tcallback?: T\n) {\n\tconst ref = useRef< AnyFunction | undefined >( () => {\n\t\tthrow new Error(\n\t\t\t'Callbacks created with `useEvent` cannot be called during rendering.'\n\t\t);\n\t} );\n\tuseInsertionEffect( () => {\n\t\tref.current = callback;\n\t} );\n\treturn useCallback< AnyFunction >(\n\t\t( ...args ) => ref.current?.( ...args ),\n\t\t[]\n\t) as T;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,kBAAkB,EAAEC,WAAW,QAAQ,oBAAoB;;AAE5E;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,QAAQA;AAC/B;AACD;AACA;AACCC,QAAY,EACX;EACD,MAAMC,GAAG,GAAGL,MAAM,CAA6B,MAAM;IACpD,MAAM,IAAIM,KAAK,CACd,sEACD,CAAC;EACF,CAAE,CAAC;EACHL,kBAAkB,CAAE,MAAM;IACzBI,GAAG,CAACE,OAAO,GAAGH,QAAQ;EACvB,CAAE,CAAC;EACH,OAAOF,WAAW,CACjB,CAAE,GAAGM,IAAI,KAAMH,GAAG,CAACE,OAAO,GAAI,GAAGC,IAAK,CAAC,EACvC,EACD,CAAC;AACF","ignoreList":[]}
@@ -61,16 +61,16 @@ export default function useFocusOnMount(focusOnMount = 'firstElement') {
61
61
  if (node.contains((_node$ownerDocument$a = node.ownerDocument?.activeElement) !== null && _node$ownerDocument$a !== void 0 ? _node$ownerDocument$a : null)) {
62
62
  return;
63
63
  }
64
- if (focusOnMountRef.current === 'firstElement') {
65
- timerIdRef.current = setTimeout(() => {
66
- const firstTabbable = focus.tabbable.find(node)[0];
67
- if (firstTabbable) {
68
- setFocus(firstTabbable);
69
- }
70
- }, 0);
64
+ if (focusOnMountRef.current !== 'firstElement') {
65
+ setFocus(node);
71
66
  return;
72
67
  }
73
- setFocus(node);
68
+ timerIdRef.current = setTimeout(() => {
69
+ const firstTabbable = focus.tabbable.find(node)[0];
70
+ if (firstTabbable) {
71
+ setFocus(firstTabbable);
72
+ }
73
+ }, 0);
74
74
  return () => {
75
75
  if (timerIdRef.current) {
76
76
  clearTimeout(timerIdRef.current);
@@ -1 +1 @@
1
- {"version":3,"names":["useRef","useEffect","focus","useRefEffect","useFocusOnMount","focusOnMount","focusOnMountRef","setFocus","target","preventScroll","timerIdRef","current","node","_node$ownerDocument$a","contains","ownerDocument","activeElement","setTimeout","firstTabbable","tabbable","find","clearTimeout"],"sources":["@wordpress/compose/src/hooks/use-focus-on-mount/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Hook used to focus the first tabbable element on mount.\n *\n * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode.\n * @return {import('react').RefCallback<HTMLElement>} Ref callback.\n *\n * @example\n * ```js\n * import { useFocusOnMount } from '@wordpress/compose';\n *\n * const WithFocusOnMount = () => {\n * const ref = useFocusOnMount()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nexport default function useFocusOnMount( focusOnMount = 'firstElement' ) {\n\tconst focusOnMountRef = useRef( focusOnMount );\n\n\t/**\n\t * Sets focus on a DOM element.\n\t *\n\t * @param {HTMLElement} target The DOM element to set focus to.\n\t * @return {void}\n\t */\n\tconst setFocus = ( target ) => {\n\t\ttarget.focus( {\n\t\t\t// When focusing newly mounted dialogs,\n\t\t\t// the position of the popover is often not right on the first render\n\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\tpreventScroll: true,\n\t\t} );\n\t};\n\n\t/** @type {import('react').MutableRefObject<ReturnType<setTimeout> | undefined>} */\n\tconst timerIdRef = useRef();\n\n\tuseEffect( () => {\n\t\tfocusOnMountRef.current = focusOnMount;\n\t}, [ focusOnMount ] );\n\n\treturn useRefEffect( ( node ) => {\n\t\tif ( ! node || focusOnMountRef.current === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( node.contains( node.ownerDocument?.activeElement ?? null ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( focusOnMountRef.current === 'firstElement' ) {\n\t\t\ttimerIdRef.current = setTimeout( () => {\n\t\t\t\tconst firstTabbable = focus.tabbable.find( node )[ 0 ];\n\n\t\t\t\tif ( firstTabbable ) {\n\t\t\t\t\tsetFocus( firstTabbable );\n\t\t\t\t}\n\t\t\t}, 0 );\n\n\t\t\treturn;\n\t\t}\n\n\t\tsetFocus( node );\n\n\t\treturn () => {\n\t\t\tif ( timerIdRef.current ) {\n\t\t\t\tclearTimeout( timerIdRef.current );\n\t\t\t}\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,SAAS,QAAQ,oBAAoB;AACtD,SAASC,KAAK,QAAQ,gBAAgB;;AAEtC;AACA;AACA;AACA,OAAOC,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAAEC,YAAY,GAAG,cAAc,EAAG;EACxE,MAAMC,eAAe,GAAGN,MAAM,CAAEK,YAAa,CAAC;;EAE9C;AACD;AACA;AACA;AACA;AACA;EACC,MAAME,QAAQ,GAAKC,MAAM,IAAM;IAC9BA,MAAM,CAACN,KAAK,CAAE;MACb;MACA;MACA;MACAO,aAAa,EAAE;IAChB,CAAE,CAAC;EACJ,CAAC;;EAED;EACA,MAAMC,UAAU,GAAGV,MAAM,CAAC,CAAC;EAE3BC,SAAS,CAAE,MAAM;IAChBK,eAAe,CAACK,OAAO,GAAGN,YAAY;EACvC,CAAC,EAAE,CAAEA,YAAY,CAAG,CAAC;EAErB,OAAOF,YAAY,CAAIS,IAAI,IAAM;IAAA,IAAAC,qBAAA;IAChC,IAAK,CAAED,IAAI,IAAIN,eAAe,CAACK,OAAO,KAAK,KAAK,EAAG;MAClD;IACD;IAEA,IAAKC,IAAI,CAACE,QAAQ,EAAAD,qBAAA,GAAED,IAAI,CAACG,aAAa,EAAEC,aAAa,cAAAH,qBAAA,cAAAA,qBAAA,GAAI,IAAK,CAAC,EAAG;MACjE;IACD;IAEA,IAAKP,eAAe,CAACK,OAAO,KAAK,cAAc,EAAG;MACjDD,UAAU,CAACC,OAAO,GAAGM,UAAU,CAAE,MAAM;QACtC,MAAMC,aAAa,GAAGhB,KAAK,CAACiB,QAAQ,CAACC,IAAI,CAAER,IAAK,CAAC,CAAE,CAAC,CAAE;QAEtD,IAAKM,aAAa,EAAG;UACpBX,QAAQ,CAAEW,aAAc,CAAC;QAC1B;MACD,CAAC,EAAE,CAAE,CAAC;MAEN;IACD;IAEAX,QAAQ,CAAEK,IAAK,CAAC;IAEhB,OAAO,MAAM;MACZ,IAAKF,UAAU,CAACC,OAAO,EAAG;QACzBU,YAAY,CAAEX,UAAU,CAACC,OAAQ,CAAC;MACnC;IACD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
1
+ {"version":3,"names":["useRef","useEffect","focus","useRefEffect","useFocusOnMount","focusOnMount","focusOnMountRef","setFocus","target","preventScroll","timerIdRef","current","node","_node$ownerDocument$a","contains","ownerDocument","activeElement","setTimeout","firstTabbable","tabbable","find","clearTimeout"],"sources":["@wordpress/compose/src/hooks/use-focus-on-mount/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect } from '@wordpress/element';\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Hook used to focus the first tabbable element on mount.\n *\n * @param {boolean | 'firstElement'} focusOnMount Focus on mount mode.\n * @return {import('react').RefCallback<HTMLElement>} Ref callback.\n *\n * @example\n * ```js\n * import { useFocusOnMount } from '@wordpress/compose';\n *\n * const WithFocusOnMount = () => {\n * const ref = useFocusOnMount()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nexport default function useFocusOnMount( focusOnMount = 'firstElement' ) {\n\tconst focusOnMountRef = useRef( focusOnMount );\n\n\t/**\n\t * Sets focus on a DOM element.\n\t *\n\t * @param {HTMLElement} target The DOM element to set focus to.\n\t * @return {void}\n\t */\n\tconst setFocus = ( target ) => {\n\t\ttarget.focus( {\n\t\t\t// When focusing newly mounted dialogs,\n\t\t\t// the position of the popover is often not right on the first render\n\t\t\t// This prevents the layout shifts when focusing the dialogs.\n\t\t\tpreventScroll: true,\n\t\t} );\n\t};\n\n\t/** @type {import('react').MutableRefObject<ReturnType<setTimeout> | undefined>} */\n\tconst timerIdRef = useRef();\n\n\tuseEffect( () => {\n\t\tfocusOnMountRef.current = focusOnMount;\n\t}, [ focusOnMount ] );\n\n\treturn useRefEffect( ( node ) => {\n\t\tif ( ! node || focusOnMountRef.current === false ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( node.contains( node.ownerDocument?.activeElement ?? null ) ) {\n\t\t\treturn;\n\t\t}\n\n\t\tif ( focusOnMountRef.current !== 'firstElement' ) {\n\t\t\tsetFocus( node );\n\t\t\treturn;\n\t\t}\n\n\t\ttimerIdRef.current = setTimeout( () => {\n\t\t\tconst firstTabbable = focus.tabbable.find( node )[ 0 ];\n\t\t\tif ( firstTabbable ) {\n\t\t\t\tsetFocus( firstTabbable );\n\t\t\t}\n\t\t}, 0 );\n\n\t\treturn () => {\n\t\t\tif ( timerIdRef.current ) {\n\t\t\t\tclearTimeout( timerIdRef.current );\n\t\t\t}\n\t\t};\n\t}, [] );\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAM,EAAEC,SAAS,QAAQ,oBAAoB;AACtD,SAASC,KAAK,QAAQ,gBAAgB;;AAEtC;AACA;AACA;AACA,OAAOC,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,eAAeA,CAAEC,YAAY,GAAG,cAAc,EAAG;EACxE,MAAMC,eAAe,GAAGN,MAAM,CAA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