@wordpress/compose 5.14.1-next.957ca95e4c.0 → 5.15.1

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 (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/build/higher-order/with-global-events/index.js +2 -8
  3. package/build/higher-order/with-global-events/index.js.map +1 -1
  4. package/build/higher-order/with-global-events/listener.js +5 -1
  5. package/build/higher-order/with-global-events/listener.js.map +1 -1
  6. package/build/hooks/use-dialog/index.js +6 -19
  7. package/build/hooks/use-dialog/index.js.map +1 -1
  8. package/build/hooks/use-dragging/index.js +15 -13
  9. package/build/hooks/use-dragging/index.js.map +1 -1
  10. package/build/hooks/use-drop-zone/index.js +8 -8
  11. package/build/hooks/use-drop-zone/index.js.map +1 -1
  12. package/build-module/higher-order/with-global-events/index.js +2 -7
  13. package/build-module/higher-order/with-global-events/index.js.map +1 -1
  14. package/build-module/higher-order/with-global-events/listener.js +6 -2
  15. package/build-module/higher-order/with-global-events/listener.js.map +1 -1
  16. package/build-module/hooks/use-dialog/index.js +7 -20
  17. package/build-module/hooks/use-dialog/index.js.map +1 -1
  18. package/build-module/hooks/use-dragging/index.js +16 -14
  19. package/build-module/hooks/use-dragging/index.js.map +1 -1
  20. package/build-module/hooks/use-drop-zone/index.js +8 -8
  21. package/build-module/hooks/use-drop-zone/index.js.map +1 -1
  22. package/build-types/higher-order/with-global-events/index.d.ts.map +1 -1
  23. package/build-types/higher-order/with-global-events/listener.d.ts.map +1 -1
  24. package/build-types/hooks/use-dialog/index.d.ts +21 -47
  25. package/build-types/hooks/use-dialog/index.d.ts.map +1 -1
  26. package/build-types/hooks/use-dragging/index.d.ts +8 -8
  27. package/build-types/hooks/use-dragging/index.d.ts.map +1 -1
  28. package/build-types/hooks/use-drop-zone/index.d.ts +15 -15
  29. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  30. package/package.json +8 -8
  31. package/src/higher-order/pure/test/index.js +71 -27
  32. package/src/higher-order/with-global-events/index.js +2 -7
  33. package/src/higher-order/with-global-events/listener.js +6 -4
  34. package/src/higher-order/with-instance-id/test/index.js +10 -6
  35. package/src/hooks/use-dialog/{index.js → index.ts} +38 -30
  36. package/src/hooks/use-dragging/index.js +12 -7
  37. package/src/hooks/use-drop-zone/index.js +8 -8
  38. package/tsconfig.tsbuildinfo +1 -1
@@ -6,12 +6,14 @@ import { useCallback, useEffect, useRef, useState } from '@wordpress/element';
6
6
  * Internal dependencies
7
7
  */
8
8
 
9
- import useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';
9
+ import useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect'; // Event handlers that are triggered from `document` listeners accept a MouseEvent,
10
+ // while those triggered from React listeners accept a React.MouseEvent.
11
+
10
12
  /**
11
- * @param {Object} props
12
- * @param {(e: MouseEvent) => void} props.onDragStart
13
- * @param {(e: MouseEvent) => void} props.onDragMove
14
- * @param {(e: MouseEvent) => void} props.onDragEnd
13
+ * @param {Object} props
14
+ * @param {(e: import('react').MouseEvent) => void} props.onDragStart
15
+ * @param {(e: MouseEvent) => void} props.onDragMove
16
+ * @param {(e?: MouseEvent) => void} props.onDragEnd
15
17
  */
16
18
 
17
19
  export default function useDragging(_ref) {
@@ -31,12 +33,12 @@ export default function useDragging(_ref) {
31
33
  eventsRef.current.onDragMove = onDragMove;
32
34
  eventsRef.current.onDragEnd = onDragEnd;
33
35
  }, [onDragStart, onDragMove, onDragEnd]);
34
- const onMouseMove = useCallback((
35
- /** @type {MouseEvent} */
36
- event) => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), []);
37
- const endDrag = useCallback((
38
- /** @type {MouseEvent} */
39
- event) => {
36
+ /** @type {(e: MouseEvent) => void} */
37
+
38
+ const onMouseMove = useCallback(event => eventsRef.current.onDragMove && eventsRef.current.onDragMove(event), []);
39
+ /** @type {(e?: MouseEvent) => void} */
40
+
41
+ const endDrag = useCallback(event => {
40
42
  if (eventsRef.current.onDragEnd) {
41
43
  eventsRef.current.onDragEnd(event);
42
44
  }
@@ -45,9 +47,9 @@ export default function useDragging(_ref) {
45
47
  document.removeEventListener('mouseup', endDrag);
46
48
  setIsDragging(false);
47
49
  }, []);
48
- const startDrag = useCallback((
49
- /** @type {MouseEvent} */
50
- event) => {
50
+ /** @type {(e: import('react').MouseEvent) => void} */
51
+
52
+ const startDrag = useCallback(event => {
51
53
  if (eventsRef.current.onDragStart) {
52
54
  eventsRef.current.onDragStart(event);
53
55
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-dragging/index.js"],"names":["useCallback","useEffect","useRef","useState","useIsomorphicLayoutEffect","useDragging","onDragStart","onDragMove","onDragEnd","isDragging","setIsDragging","eventsRef","current","onMouseMove","event","endDrag","document","removeEventListener","startDrag","addEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,EAAyCC,QAAzC,QAAyD,oBAAzD;AAEA;AACA;AACA;;AACA,OAAOC,yBAAP,MAAsC,iCAAtC;AAEA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,WAAT,OAA+D;AAAA,MAAzC;AAAEC,IAAAA,WAAF;AAAeC,IAAAA,UAAf;AAA2BC,IAAAA;AAA3B,GAAyC;AAC7E,QAAM,CAAEC,UAAF,EAAcC,aAAd,IAAgCP,QAAQ,CAAE,KAAF,CAA9C;AAEA,QAAMQ,SAAS,GAAGT,MAAM,CAAE;AACzBI,IAAAA,WADyB;AAEzBC,IAAAA,UAFyB;AAGzBC,IAAAA;AAHyB,GAAF,CAAxB;AAKAJ,EAAAA,yBAAyB,CAAE,MAAM;AAChCO,IAAAA,SAAS,CAACC,OAAV,CAAkBN,WAAlB,GAAgCA,WAAhC;AACAK,IAAAA,SAAS,CAACC,OAAV,CAAkBL,UAAlB,GAA+BA,UAA/B;AACAI,IAAAA,SAAS,CAACC,OAAV,CAAkBJ,SAAlB,GAA8BA,SAA9B;AACA,GAJwB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AAAA,QAAQ,CAACC,mBAAT,CAA8B,SAA9B,EAAyCF,OAAzC;AACA;AACD,KALD;AAMA,GAPQ,EAON,CAAEN,UAAF,CAPM,CAAT;AASA,SAAO;AACNS,IAAAA,SADM;AAENH,IAAAA,OAFM;AAGNN,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';\n\n/**\n * @param {Object} props\n * @param {(e: MouseEvent) => void} props.onDragStart\n * @param {(e: MouseEvent) => void} props.onDragMove\n * @param {(e: MouseEvent) => void} props.onDragEnd\n */\nexport default function useDragging( { onDragStart, onDragMove, onDragEnd } ) {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\n\tconst eventsRef = useRef( {\n\t\tonDragStart,\n\t\tonDragMove,\n\t\tonDragEnd,\n\t} );\n\tuseIsomorphicLayoutEffect( () => {\n\t\teventsRef.current.onDragStart = onDragStart;\n\t\teventsRef.current.onDragMove = onDragMove;\n\t\teventsRef.current.onDragEnd = onDragEnd;\n\t}, [ onDragStart, onDragMove, onDragEnd ] );\n\n\tconst onMouseMove = useCallback(\n\t\t( /** @type {MouseEvent} */ event ) =>\n\t\t\teventsRef.current.onDragMove &&\n\t\t\teventsRef.current.onDragMove( event ),\n\t\t[]\n\t);\n\tconst endDrag = useCallback( ( /** @type {MouseEvent} */ event ) => {\n\t\tif ( eventsRef.current.onDragEnd ) {\n\t\t\teventsRef.current.onDragEnd( event );\n\t\t}\n\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\tsetIsDragging( false );\n\t}, [] );\n\tconst startDrag = useCallback( ( /** @type {MouseEvent} */ event ) => {\n\t\tif ( eventsRef.current.onDragStart ) {\n\t\t\teventsRef.current.onDragStart( event );\n\t\t}\n\t\tdocument.addEventListener( 'mousemove', onMouseMove );\n\t\tdocument.addEventListener( 'mouseup', endDrag );\n\t\tsetIsDragging( true );\n\t}, [] );\n\n\t// Remove the global events when unmounting if needed.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( isDragging ) {\n\t\t\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\t\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\t\t}\n\t\t};\n\t}, [ isDragging ] );\n\n\treturn {\n\t\tstartDrag,\n\t\tendDrag,\n\t\tisDragging,\n\t};\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-dragging/index.js"],"names":["useCallback","useEffect","useRef","useState","useIsomorphicLayoutEffect","useDragging","onDragStart","onDragMove","onDragEnd","isDragging","setIsDragging","eventsRef","current","onMouseMove","event","endDrag","document","removeEventListener","startDrag","addEventListener"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,WAAT,EAAsBC,SAAtB,EAAiCC,MAAjC,EAAyCC,QAAzC,QAAyD,oBAAzD;AAEA;AACA;AACA;;AACA,OAAOC,yBAAP,MAAsC,iCAAtC,C,CAEA;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;;AACA,eAAe,SAASC,WAAT,OAA+D;AAAA,MAAzC;AAAEC,IAAAA,WAAF;AAAeC,IAAAA,UAAf;AAA2BC,IAAAA;AAA3B,GAAyC;AAC7E,QAAM,CAAEC,UAAF,EAAcC,aAAd,IAAgCP,QAAQ,CAAE,KAAF,CAA9C;AAEA,QAAMQ,SAAS,GAAGT,MAAM,CAAE;AACzBI,IAAAA,WADyB;AAEzBC,IAAAA,UAFyB;AAGzBC,IAAAA;AAHyB,GAAF,CAAxB;AAKAJ,EAAAA,yBAAyB,CAAE,MAAM;AAChCO,IAAAA,SAAS,CAACC,OAAV,CAAkBN,WAAlB,GAAgCA,WAAhC;AACAK,IAAAA,SAAS,CAACC,OAAV,CAAkBL,UAAlB,GAA+BA,UAA/B;AACAI,IAAAA,SAAS,CAACC,OAAV,CAAkBJ,S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,mBAAT,CAA8B,SAA9B,EAAyCF,OAAzC;AACA;AACD,KALD;AAMA,GAPQ,EAON,CAAEN,UAAF,CAPM,CAAT;AASA,SAAO;AACNS,IAAAA,SADM;AAENH,IAAAA,OAFM;AAGNN,IAAAA;AAHM,GAAP;AAKA","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';\n\n// Event handlers that are triggered from `document` listeners accept a MouseEvent,\n// while those triggered from React listeners accept a React.MouseEvent.\n/**\n * @param {Object} props\n * @param {(e: import('react').MouseEvent) => void} props.onDragStart\n * @param {(e: MouseEvent) => void} props.onDragMove\n * @param {(e?: MouseEvent) => void} props.onDragEnd\n */\nexport default function useDragging( { onDragStart, onDragMove, onDragEnd } ) {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\n\tconst eventsRef = useRef( {\n\t\tonDragStart,\n\t\tonDragMove,\n\t\tonDragEnd,\n\t} );\n\tuseIsomorphicLayoutEffect( () => {\n\t\teventsRef.current.onDragStart = onDragStart;\n\t\teventsRef.current.onDragMove = onDragMove;\n\t\teventsRef.current.onDragEnd = onDragEnd;\n\t}, [ onDragStart, onDragMove, onDragEnd ] );\n\n\t/** @type {(e: MouseEvent) => void} */\n\tconst onMouseMove = useCallback(\n\t\t( event ) =>\n\t\t\teventsRef.current.onDragMove &&\n\t\t\teventsRef.current.onDragMove( event ),\n\t\t[]\n\t);\n\t/** @type {(e?: MouseEvent) => void} */\n\tconst endDrag = useCallback( ( event ) => {\n\t\tif ( eventsRef.current.onDragEnd ) {\n\t\t\teventsRef.current.onDragEnd( event );\n\t\t}\n\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\tsetIsDragging( false );\n\t}, [] );\n\t/** @type {(e: import('react').MouseEvent) => void} */\n\tconst startDrag = useCallback( ( event ) => {\n\t\tif ( eventsRef.current.onDragStart ) {\n\t\t\teventsRef.current.onDragStart( event );\n\t\t}\n\t\tdocument.addEventListener( 'mousemove', onMouseMove );\n\t\tdocument.addEventListener( 'mouseup', endDrag );\n\t\tsetIsDragging( true );\n\t}, [] );\n\n\t// Remove the global events when unmounting if needed.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( isDragging ) {\n\t\t\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\t\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\t\t}\n\t\t};\n\t}, [ isDragging ] );\n\n\treturn {\n\t\tstartDrag,\n\t\tendDrag,\n\t\tisDragging,\n\t};\n}\n"]}
@@ -36,14 +36,14 @@ function useFreshRef(value) {
36
36
  /**
37
37
  * A hook to facilitate drag and drop handling.
38
38
  *
39
- * @param {Object} props Named parameters.
40
- * @param {boolean} props.isDisabled Whether or not to disable the drop zone.
41
- * @param {(e: DragEvent) => void} props.onDragStart Called when dragging has started.
42
- * @param {(e: DragEvent) => void} props.onDragEnter Called when the zone is entered.
43
- * @param {(e: DragEvent) => void} props.onDragOver Called when the zone is moved within.
44
- * @param {(e: DragEvent) => void} props.onDragLeave Called when the zone is left.
45
- * @param {(e: MouseEvent) => void} props.onDragEnd Called when dragging has ended.
46
- * @param {(e: DragEvent) => void} props.onDrop Called when dropping in the zone.
39
+ * @param {Object} props Named parameters.
40
+ * @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.
41
+ * @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.
42
+ * @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.
43
+ * @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.
44
+ * @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.
45
+ * @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.
46
+ * @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.
47
47
  *
48
48
  * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.
49
49
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-drop-zone/index.js"],"names":["useRef","useRefEffect","useFreshRef","value","ref","current","useDropZone","isDisabled","onDrop","_onDrop","onDragStart","_onDragStart","onDragEnter","_onDragEnter","onDragLeave","_onDragLeave","onDragEnd","_onDragEnd","onDragOver","_onDragOver","onDropRef","onDragStartRef","onDragEnterRef","onDragLeaveRef","onDragEndRef","onDragOverRef","element","isDragging","ownerDocument","isElementInZone","targetToCheck","defaultView","HTMLElement","contains","elementToCheck","dataset","isDropZone","parentElement","maybeDragStart","event","removeEventListener","addEventListener","maybeDragEnd","preventDefault","relatedTarget","defaultPrevented","dataTransfer","files","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,mBAAzB;AAEA;;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAMC,GAAG,GAAGJ,MAAM,EAAlB;AACAI,EAAAA,GAAG,CAACC,OAAJ,GAAcF,KAAd;AACA,SAAOC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASE,WAAT,OAQX;AAAA,MARiC;AACpCC,IAAAA,UADoC;AAEpCC,IAAAA,MAAM,EAAEC,OAF4B;AAGpCC,IAAAA,WAAW,EAAEC,YAHuB;AAIpCC,IAAAA,WAAW,EAAEC,YAJuB;AAKpCC,IAAAA,WAAW,EAAEC,YALuB;AAMpCC,IAAAA,SAAS,EAAEC,UANyB;AAOpCC,IAAAA,UAAU,EAAEC;AAPwB,GAQjC;AACH,QAAMC,SAAS,GAAGlB,WAAW,CAAEO,OAAF,CAA7B;AACA,QAAMY,cAAc,GAAG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AAvB;AACAoB,MAAAA,aAAa,CAACpB,OAAd,GAAwB,IAAxB;AACA,aAAOqB,OAAO,CAACS,OAAR,CAAgBC,UAAvB;AACAV,MAAAA,OAAO,CAACc,mBAAR,CAA6B,MAA7B,EAAqChC,MAArC;AACAkB,MAAAA,OAAO,CAACc,mBAAR,CAA6B,WAA7B,EAA0C5B,WAA1C;AACAc,MAAAA,OAAO,CAACc,mBAAR,CAA6B,UAA7B,EAAyCtB,UAAzC;AACAQ,MAAAA,OAAO,CAACc,mBAAR,CAA6B,WAA7B,EAA0C1B,WAA1C;AACAc,MAAAA,aAAa,CAACY,mBAAd,CAAmC,SAAnC,EAA8CE,YAA9C;AACAd,MAAAA,aAAa,CAACY,mBAAd,CAAmC,WAAnC,EAAgDE,YAAhD;AACAd,MAAAA,aAAa,CAACa,gBAAd,CAAgC,WAAhC,EAA6CH,cAA7C;AACA,KAfD;AAgBA,GA9KiB,EA+KlB,CAAE/B,UAAF,CA/KkB,CAAnB;AAiLA","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 {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\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( element ) => {\n\t\t\tif ( isDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\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\townerDocument.removeEventListener(\n\t\t\t\t\t'dragenter',\n\t\t\t\t\tmaybeDragStart\n\t\t\t\t);\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\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.addEventListener( 'dragenter', maybeDragStart );\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\tonDropRef.current = null;\n\t\t\t\tonDragStartRef.current = null;\n\t\t\t\tonDragEnterRef.current = null;\n\t\t\t\tonDragLeaveRef.current = null;\n\t\t\t\tonDragEndRef.current = null;\n\t\t\t\tonDragOverRef.current = null;\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.addEventListener( 'dragenter', maybeDragStart );\n\t\t\t};\n\t\t},\n\t\t[ isDisabled ]\n\t);\n}\n"]}
1
+ {"version":3,"sources":["@wordpress/compose/src/hooks/use-drop-zone/index.js"],"names":["useRef","useRefEffect","useFreshRef","value","ref","current","useDropZone","isDisabled","onDrop","_onDrop","onDragStart","_onDragStart","onDragEnter","_onDragEnter","onDragLeave","_onDragLeave","onDragEnd","_onDragEnd","onDragOver","_onDragOver","onDropRef","onDragStartRef","onDragEnterRef","onDragLeaveRef","onDragEndRef","onDragOverRef","element","isDragging","ownerDocument","isElementInZone","targetToCheck","defaultView","HTMLElement","contains","elementToCheck","dataset","isDropZone","parentElement","maybeDragStart","event","removeEventListener","addEventListener","maybeDragEnd","preventDefault","relatedTarget","defaultPrevented","dataTransfer","files","length"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,MAAT,QAAuB,oBAAvB;AAEA;AACA;AACA;;AACA,OAAOC,YAAP,MAAyB,mBAAzB;AAEA;;AACA;AACA;AACA;AACA;AACA;;AACA,SAASC,WAAT,CAAsBC,KAAtB,EAA8B;AAC7B;;AACA;;AACA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,QAAMC,GAAG,GAAGJ,MAAM,EAAlB;AACAI,EAAAA,GAAG,CAACC,OAAJ,GAAcF,KAAd;AACA,SAAOC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,eAAe,SAASE,WAAT,OAQX;AAAA,MARiC;AACpCC,IAAAA,UADoC;AAEpCC,IAAAA,MAAM,EAAEC,OAF4B;AAGpCC,IAAAA,WAAW,EAAEC,YAHuB;AAIpCC,IAAAA,WAAW,EAAEC,YAJuB;AAKpCC,IAAAA,WAAW,EAAEC,YALuB;AAMpCC,IAAAA,SAAS,EAAEC,UANyB;AAOpCC,IAAAA,UAAU,EAAEC;AAPwB,GAQjC;AACH,QAAMC,SAAS,GAAGlB,WAAW,CAAEO,OAAF,CAA7B;AACA,QAAMY,cAAc,GAAGnB,WAAW,CAAES,YAAF,CAAlC;AACA,QAAMW,cAAc,GAAGpB,WAAW,CAAEW,YAAF,CAAlC;AACA,QAAMU,cAAc,GAAGrB,WAAW,CAAEa,YAAF,CAAlC;AACA,QAAMS,YAAY,GAAGtB,WAAW,CAAEe,UAAF,CAAhC;AACA,QAAMQ,aAAa,GAAGvB,WAAW,CAAEiB,WAAF,CAAjC;AAEA,SAAOlB,YAAY,CAChByB,OAAF,IAAe;AACd,QA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;AACAQ,MAAAA,OAAO,CAACc,mBAAR,CAA6B,WAA7B,EAA0C1B,WAA1C;AACAc,MAAAA,aAAa,CAACY,mBAAd,CAAmC,SAAnC,EAA8CE,YAA9C;AACAd,MAAAA,aAAa,CAACY,mBAAd,CAAmC,WAAnC,EAAgDE,YAAhD;AACAd,MAAAA,aAAa,CAACa,gBAAd,CAAgC,WAAhC,EAA6CH,cAA7C;AACA,KAfD;AAgBA,GA9KiB,EA+KlB,CAAE/B,UAAF,CA/KkB,CAAnB;AAiLA","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 {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\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( element ) => {\n\t\t\tif ( isDisabled ) {\n\t\t\t\treturn;\n\t\t\t}\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\townerDocument.removeEventListener(\n\t\t\t\t\t'dragenter',\n\t\t\t\t\tmaybeDragStart\n\t\t\t\t);\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\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.addEventListener( 'dragenter', maybeDragStart );\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\tonDropRef.current = null;\n\t\t\t\tonDragStartRef.current = null;\n\t\t\t\tonDragEnterRef.current = null;\n\t\t\t\tonDragLeaveRef.current = null;\n\t\t\t\tonDragEndRef.current = null;\n\t\t\t\tonDragOverRef.current = null;\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.addEventListener( 'dragenter', maybeDragStart );\n\t\t\t};\n\t\t},\n\t\t[ isDisabled ]\n\t);\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/index.js"],"names":[],"mappings":"AAuBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,+DATW,OAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,GAOhD,GAAG,CAmEd"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/index.js"],"names":[],"mappings":"AAkBA;;;;;;;;;;;;;;;;;;GAkBG;AACH,+DATW,OAAO,MAAM,2BAA2B,EAAE,MAAM,CAAC,GAOhD,GAAG,CAmEd"}
@@ -1 +1 @@
1
- {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/listener.js"],"names":[],"mappings":";AAKA;;;;GAIG;AACH;IAEE,kBAAkB;IAClB,WADW,GAAG,CACK;IA4BpB,mBAAwB,GAAG,QAI1B;IA3BD,eAAgB,GAAG,YAA2B,GAAG,QAQhD;IAED,kBAAmB,GAAG,YAA2B,GAAG,QAWnD;CAOD"}
1
+ {"version":3,"file":"listener.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-global-events/listener.js"],"names":[],"mappings":";AAKA;;;;GAIG;AACH;IAEE,kBAAkB;IAClB,WADW,GAAG,CACK;IA4BpB,mBAAwB,GAAG,QAM1B;IA7BD,eAAgB,GAAG,YAA2B,GAAG,QAQhD;IAED,kBAAmB,GAAG,YAA2B,GAAG,QAWnD;CASD"}
@@ -1,23 +1,23 @@
1
- export default useDialog;
2
- export type useFocusOnMount = typeof useFocusOnMount;
3
- export type DialogOptions = {
4
- /**
5
- * Focus on mount arguments.
6
- */
7
- focusOnMount: Parameters<useFocusOnMount>[0];
8
- /**
9
- * Function to call when the dialog is closed.
10
- */
11
- onClose: () => void;
12
- };
13
1
  /**
14
- * @typedef {import('../use-focus-on-mount').default} useFocusOnMount
15
- */
16
- /**
17
- * @typedef DialogOptions
18
- * @property {Parameters<useFocusOnMount>[0]} focusOnMount Focus on mount arguments.
19
- * @property {() => void} onClose Function to call when the dialog is closed.
2
+ * External dependencies
20
3
  */
4
+ import type { RefCallback, SyntheticEvent } from 'react';
5
+ import useFocusOnMount from '../use-focus-on-mount';
6
+ import type { FocusOutsideReturnValue } from '../use-focus-outside';
7
+ declare type DialogOptions = {
8
+ focusOnMount?: Parameters<typeof useFocusOnMount>[0];
9
+ onClose?: () => void;
10
+ /**
11
+ * Use the `onClose` prop instead.
12
+ *
13
+ * @deprecated
14
+ */
15
+ __unstableOnClose?: (type: string | undefined, event: SyntheticEvent) => void;
16
+ };
17
+ declare type useDialogReturn = [
18
+ RefCallback<HTMLElement>,
19
+ FocusOutsideReturnValue & Pick<HTMLElement, 'tabIndex'>
20
+ ];
21
21
  /**
22
22
  * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:
23
23
  * - constrained tabbing.
@@ -25,34 +25,8 @@ export type DialogOptions = {
25
25
  * - return focus on unmount.
26
26
  * - focus outside.
27
27
  *
28
- * @param {DialogOptions} options Dialog Options.
28
+ * @param options Dialog Options.
29
29
  */
30
- declare function useDialog(options: DialogOptions): (((instance: unknown) => void) | {
31
- tabIndex: string;
32
- /**
33
- * An event handler for focus events.
34
- */
35
- onFocus: import("../use-focus-outside").EventCallback;
36
- /**
37
- * An event handler for blur events.
38
- */
39
- onBlur: import("../use-focus-outside").EventCallback;
40
- /**
41
- * An event handler for mouse down events.
42
- */
43
- onMouseDown: import("../use-focus-outside").EventCallback;
44
- /**
45
- * An event handler for mouse up events.
46
- */
47
- onMouseUp: import("../use-focus-outside").EventCallback;
48
- /**
49
- * An event handler for touch start events.
50
- */
51
- onTouchStart: import("../use-focus-outside").EventCallback;
52
- /**
53
- * An event handler for touch end events.
54
- */
55
- onTouchEnd: import("../use-focus-outside").EventCallback;
56
- })[];
57
- import useFocusOnMount from "../use-focus-on-mount";
30
+ declare function useDialog(options: DialogOptions): useDialogReturn;
31
+ export default useDialog;
58
32
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.js"],"names":[],"mappings":";;;;;;kBAoBc,WAAW,eAAe,CAAC,CAAC,CAAC,CAAC;;;;aAC9B,MAAM,IAAI;;AANxB;;GAEG;AACH;;;;GAIG;AAEH;;;;;;;;GAQG;AACH,oCAFW,aAAa;;;;;;;;;;;;;;;;;;;;;;;;;;KAyDvB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAiB,WAAW,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAYxE,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAIpD,OAAO,KAAK,EAAE,uBAAuB,EAAE,MAAM,sBAAsB,CAAC;AAEpE,aAAK,aAAa,GAAG;IACpB,YAAY,CAAC,EAAE,UAAU,CAAE,OAAO,eAAe,CAAE,CAAE,CAAC,CAAE,CAAC;IACzD,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;IACrB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CACnB,IAAI,EAAE,MAAM,GAAG,SAAS,EACxB,KAAK,EAAE,cAAc,KACjB,IAAI,CAAC;CACV,CAAC;AAEF,aAAK,eAAe,GAAG;IACtB,WAAW,CAAE,WAAW,CAAE;IAC1B,uBAAuB,GAAG,IAAI,CAAE,WAAW,EAAE,UAAU,CAAE;CACzD,CAAC;AAEF;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAE,OAAO,EAAE,aAAa,GAAI,eAAe,CA+C5D;AAED,eAAe,SAAS,CAAC"}
@@ -1,16 +1,16 @@
1
1
  /**
2
- * @param {Object} props
3
- * @param {(e: MouseEvent) => void} props.onDragStart
4
- * @param {(e: MouseEvent) => void} props.onDragMove
5
- * @param {(e: MouseEvent) => void} props.onDragEnd
2
+ * @param {Object} props
3
+ * @param {(e: import('react').MouseEvent) => void} props.onDragStart
4
+ * @param {(e: MouseEvent) => void} props.onDragMove
5
+ * @param {(e?: MouseEvent) => void} props.onDragEnd
6
6
  */
7
7
  export default function useDragging({ onDragStart, onDragMove, onDragEnd }: {
8
- onDragStart: (e: MouseEvent) => void;
8
+ onDragStart: (e: import('react').MouseEvent) => void;
9
9
  onDragMove: (e: MouseEvent) => void;
10
- onDragEnd: (e: MouseEvent) => void;
10
+ onDragEnd: (e?: MouseEvent | undefined) => void;
11
11
  }): {
12
- startDrag: (event: MouseEvent) => void;
13
- endDrag: (event: MouseEvent) => void;
12
+ startDrag: (e: import('react').MouseEvent) => void;
13
+ endDrag: (e?: MouseEvent | undefined) => void;
14
14
  isDragging: boolean;
15
15
  };
16
16
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dragging/index.js"],"names":[],"mappings":"AAUA;;;;;GAKG;AACH;qBAJe,UAAU,KAAK,IAAI;oBACnB,UAAU,KAAK,IAAI;mBACnB,UAAU,KAAK,IAAI;;uBA8BW,UAAU;qBARZ,UAAU;;EAgCpD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dragging/index.js"],"names":[],"mappings":"AAYA;;;;;GAKG;AACH;qBAJe,OAAO,OAAO,EAAE,UAAU,KAAK,IAAI;oBACnC,UAAU,KAAK,IAAI;+CACH,IAAI;;mBAgCnB,OAAO,OAAO,EAAE,UAAU,KAAK,IAAI;6CATnB,IAAI;;EAkCnC"}
@@ -1,24 +1,24 @@
1
1
  /**
2
2
  * A hook to facilitate drag and drop handling.
3
3
  *
4
- * @param {Object} props Named parameters.
5
- * @param {boolean} props.isDisabled Whether or not to disable the drop zone.
6
- * @param {(e: DragEvent) => void} props.onDragStart Called when dragging has started.
7
- * @param {(e: DragEvent) => void} props.onDragEnter Called when the zone is entered.
8
- * @param {(e: DragEvent) => void} props.onDragOver Called when the zone is moved within.
9
- * @param {(e: DragEvent) => void} props.onDragLeave Called when the zone is left.
10
- * @param {(e: MouseEvent) => void} props.onDragEnd Called when dragging has ended.
11
- * @param {(e: DragEvent) => void} props.onDrop Called when dropping in the zone.
4
+ * @param {Object} props Named parameters.
5
+ * @param {boolean} [props.isDisabled] Whether or not to disable the drop zone.
6
+ * @param {(e: DragEvent) => void} [props.onDragStart] Called when dragging has started.
7
+ * @param {(e: DragEvent) => void} [props.onDragEnter] Called when the zone is entered.
8
+ * @param {(e: DragEvent) => void} [props.onDragOver] Called when the zone is moved within.
9
+ * @param {(e: DragEvent) => void} [props.onDragLeave] Called when the zone is left.
10
+ * @param {(e: MouseEvent) => void} [props.onDragEnd] Called when dragging has ended.
11
+ * @param {(e: DragEvent) => void} [props.onDrop] Called when dropping in the zone.
12
12
  *
13
13
  * @return {import('react').RefCallback<HTMLElement>} Ref callback to be passed to the drop zone element.
14
14
  */
15
15
  export default function useDropZone({ isDisabled, onDrop: _onDrop, onDragStart: _onDragStart, onDragEnter: _onDragEnter, onDragLeave: _onDragLeave, onDragEnd: _onDragEnd, onDragOver: _onDragOver, }: {
16
- isDisabled: boolean;
17
- onDragStart: (e: DragEvent) => void;
18
- onDragEnter: (e: DragEvent) => void;
19
- onDragOver: (e: DragEvent) => void;
20
- onDragLeave: (e: DragEvent) => void;
21
- onDragEnd: (e: MouseEvent) => void;
22
- onDrop: (e: DragEvent) => void;
16
+ isDisabled?: boolean | undefined;
17
+ onDragStart?: ((e: DragEvent) => void) | undefined;
18
+ onDragEnter?: ((e: DragEvent) => void) | undefined;
19
+ onDragOver?: ((e: DragEvent) => void) | undefined;
20
+ onDragLeave?: ((e: DragEvent) => void) | undefined;
21
+ onDragEnd?: ((e: MouseEvent) => void) | undefined;
22
+ onDrop?: ((e: DragEvent) => void) | undefined;
23
23
  }): import('react').RefCallback<HTMLElement>;
24
24
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;gBAVW,OAAO;qBACH,SAAS,KAAK,IAAI;qBAClB,SAAS,KAAK,IAAI;oBAClB,SAAS,KAAK,IAAI;qBAClB,SAAS,KAAK,IAAI;mBAClB,UAAU,KAAK,IAAI;gBACnB,SAAS,KAAK,IAAI;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAmMnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;IAV2C,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;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAmMnD"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/compose",
3
- "version": "5.14.1-next.957ca95e4c.0",
3
+ "version": "5.15.1",
4
4
  "description": "WordPress higher-order components (HOCs).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,12 +32,12 @@
32
32
  "@babel/runtime": "^7.16.0",
33
33
  "@types/lodash": "^4.14.172",
34
34
  "@types/mousetrap": "^1.6.8",
35
- "@wordpress/deprecated": "^3.16.1-next.957ca95e4c.0",
36
- "@wordpress/dom": "^3.16.1-next.957ca95e4c.0",
37
- "@wordpress/element": "^4.14.1-next.957ca95e4c.0",
38
- "@wordpress/is-shallow-equal": "^4.16.1-next.957ca95e4c.0",
39
- "@wordpress/keycodes": "^3.16.1-next.957ca95e4c.0",
40
- "@wordpress/priority-queue": "^2.16.1-next.957ca95e4c.0",
35
+ "@wordpress/deprecated": "^3.17.0",
36
+ "@wordpress/dom": "^3.17.1",
37
+ "@wordpress/element": "^4.15.0",
38
+ "@wordpress/is-shallow-equal": "^4.17.0",
39
+ "@wordpress/keycodes": "^3.17.0",
40
+ "@wordpress/priority-queue": "^2.17.1",
41
41
  "change-case": "^4.1.2",
42
42
  "clipboard": "^2.0.8",
43
43
  "lodash": "^4.17.21",
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "272a74bbbaab10ee24424eafe9578e705fbfbbb4"
53
+ "gitHead": "56ef3f5a754e44155ee79e827c7a1d0efc1ee5aa"
54
54
  }
@@ -1,7 +1,8 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { mount } from 'enzyme';
4
+ import { render, screen } from '@testing-library/react';
5
+ import userEvent from '@testing-library/user-event';
5
6
 
6
7
  /**
7
8
  * WordPress dependencies
@@ -17,44 +18,87 @@ describe( 'pure', () => {
17
18
  it( 'functional component should rerender only when props change', () => {
18
19
  let i = 0;
19
20
  const MyComp = pure( () => {
20
- return <p>{ ++i }</p>;
21
+ return <p data-testid="counter">{ ++i }</p>;
21
22
  } );
22
- const wrapper = mount( <MyComp /> );
23
- wrapper.update(); // Updating with same props doesn't rerender.
24
- expect( wrapper.html() ).toBe( '<p>1</p>' );
25
- wrapper.setProps( { prop: 'a' } ); // New prop should trigger a rerender.
26
- expect( wrapper.html() ).toBe( '<p>2</p>' );
27
- wrapper.setProps( { prop: 'a' } ); // Keeping the same prop value should not rerender.
28
- expect( wrapper.html() ).toBe( '<p>2</p>' );
29
- wrapper.setProps( { prop: 'b' } ); // Changing the prop value should rerender.
30
- expect( wrapper.html() ).toBe( '<p>3</p>' );
23
+ const { rerender } = render( <MyComp /> );
24
+
25
+ // Updating with same props doesn't rerender.
26
+ rerender( <MyComp /> );
27
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '1' );
28
+
29
+ // New prop should trigger a rerender.
30
+ rerender( <MyComp { ...{ prop: 'a' } } /> );
31
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
32
+
33
+ // Keeping the same prop value should not rerender.
34
+ rerender( <MyComp { ...{ prop: 'a' } } /> );
35
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
36
+
37
+ // Changing the prop value should rerender.
38
+ rerender( <MyComp { ...{ prop: 'b' } } /> );
39
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '3' );
31
40
  } );
32
41
 
33
- it( 'class component should rerender if the props or state change', () => {
42
+ it( 'class component should rerender if the props or state change', async () => {
43
+ const user = userEvent.setup( {
44
+ advanceTimers: jest.advanceTimersByTime,
45
+ } );
34
46
  let i = 0;
35
47
  const MyComp = pure(
36
48
  class extends Component {
37
49
  constructor() {
38
50
  super( ...arguments );
39
- this.state = {};
51
+ this.state = {
52
+ val: '',
53
+ };
40
54
  }
41
55
  render() {
42
- return <p>{ ++i }</p>;
56
+ return (
57
+ <>
58
+ <p data-testid="counter">{ ++i }</p>
59
+ <input
60
+ type="text"
61
+ value={ this.state.val }
62
+ onChange={ ( e ) =>
63
+ this.setState( { val: e.target.value } )
64
+ }
65
+ />
66
+ <input
67
+ type="button"
68
+ onClick={ () =>
69
+ this.setState( { val: this.state.val } )
70
+ }
71
+ />
72
+ </>
73
+ );
43
74
  }
44
75
  }
45
76
  );
46
- const wrapper = mount( <MyComp /> );
47
- wrapper.update(); // Updating with same props doesn't rerender.
48
- expect( wrapper.html() ).toBe( '<p>1</p>' );
49
- wrapper.setProps( { prop: 'a' } ); // New prop should trigger a rerender.
50
- expect( wrapper.html() ).toBe( '<p>2</p>' );
51
- wrapper.setProps( { prop: 'a' } ); // Keeping the same prop value should not rerender.
52
- expect( wrapper.html() ).toBe( '<p>2</p>' );
53
- wrapper.setProps( { prop: 'b' } ); // Changing the prop value should rerender.
54
- expect( wrapper.html() ).toBe( '<p>3</p>' );
55
- wrapper.setState( { state: 'a' } ); // New state value should trigger a rerender.
56
- expect( wrapper.html() ).toBe( '<p>4</p>' );
57
- wrapper.setState( { state: 'a' } ); // Keeping the same state value should not trigger a rerender.
58
- expect( wrapper.html() ).toBe( '<p>4</p>' );
77
+
78
+ const { rerender } = render( <MyComp /> );
79
+
80
+ // Updating with same props doesn't rerender.
81
+ rerender( <MyComp /> );
82
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '1' );
83
+
84
+ // New prop should trigger a rerender.
85
+ rerender( <MyComp { ...{ prop: 'a' } } /> );
86
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
87
+
88
+ // Keeping the same prop value should not rerender.
89
+ rerender( <MyComp { ...{ prop: 'a' } } /> );
90
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '2' );
91
+
92
+ // Changing the prop value should rerender.
93
+ rerender( <MyComp { ...{ prop: 'b' } } /> );
94
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '3' );
95
+
96
+ // New state value should trigger a rerender.
97
+ await user.type( screen.getByRole( 'textbox' ), 'a' );
98
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '4' );
99
+
100
+ // Keeping the same state value should not trigger a rerender.
101
+ await user.click( screen.getByRole( 'button' ) );
102
+ expect( screen.getByTestId( 'counter' ) ).toHaveTextContent( '4' );
59
103
  } );
60
104
  } );
@@ -1,8 +1,3 @@
1
- /**
2
- * External dependencies
3
- */
4
- import { forEach } from 'lodash';
5
-
6
1
  /**
7
2
  * WordPress dependencies
8
3
  */
@@ -57,13 +52,13 @@ export default function withGlobalEvents( eventTypesToHandlers ) {
57
52
  }
58
53
 
59
54
  componentDidMount() {
60
- forEach( eventTypesToHandlers, ( _, eventType ) => {
55
+ Object.keys( eventTypesToHandlers ).forEach( ( eventType ) => {
61
56
  listener.add( eventType, this );
62
57
  } );
63
58
  }
64
59
 
65
60
  componentWillUnmount() {
66
- forEach( eventTypesToHandlers, ( _, eventType ) => {
61
+ Object.keys( eventTypesToHandlers ).forEach( ( eventType ) => {
67
62
  listener.remove( eventType, this );
68
63
  } );
69
64
  }
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { forEach, without } from 'lodash';
4
+ import { without } from 'lodash';
5
5
 
6
6
  /**
7
7
  * Class responsible for orchestrating event handling on the global window,
@@ -40,9 +40,11 @@ class Listener {
40
40
  }
41
41
 
42
42
  handleEvent( /** @type {any} */ event ) {
43
- forEach( this.listeners[ event.type ], ( instance ) => {
44
- instance.handleEvent( event );
45
- } );
43
+ this.listeners[ event.type ]?.forEach(
44
+ ( /** @type {any} */ instance ) => {
45
+ instance.handleEvent( event );
46
+ }
47
+ );
46
48
  }
47
49
  }
48
50
 
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { render } from 'enzyme';
4
+ import { render, screen } from '@testing-library/react';
5
5
 
6
6
  /**
7
7
  * Internal dependencies
@@ -10,13 +10,17 @@ import withInstanceId from '../';
10
10
 
11
11
  describe( 'withInstanceId', () => {
12
12
  const DumpComponent = withInstanceId( ( { instanceId } ) => {
13
- return <div>{ instanceId }</div>;
13
+ return <div data-testid="wrapper">{ instanceId }</div>;
14
14
  } );
15
15
 
16
16
  it( 'should generate a new instanceId for each instance', () => {
17
- const dumb1 = render( <DumpComponent /> );
18
- const dumb2 = render( <DumpComponent /> );
19
- // Unrendered element.
20
- expect( dumb1.text() ).not.toBe( dumb2.text() );
17
+ render( <DumpComponent /> );
18
+ render( <DumpComponent /> );
19
+
20
+ const elements = screen.getAllByTestId( 'wrapper' );
21
+
22
+ expect( elements[ 0 ] ).not.toHaveTextContent(
23
+ elements[ 1 ].textContent
24
+ );
21
25
  } );
22
26
  } );