@wordpress/compose 7.40.1-next.v.202602241322.0 → 7.40.1-next.v.202602271551.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.
package/README.md CHANGED
@@ -338,7 +338,7 @@ _Returns_
338
338
 
339
339
  ### useFocusOnMount
340
340
 
341
- Hook used to focus the first tabbable element on mount.
341
+ Determines focus behavior when the element mounts.
342
342
 
343
343
  _Usage_
344
344
 
@@ -358,11 +358,11 @@ const WithFocusOnMount = () => {
358
358
 
359
359
  _Parameters_
360
360
 
361
- - _focusOnMount_ `boolean | 'firstElement' | 'firstInputElement'`: Focus on mount mode.
361
+ - _focusOnMount_ `useFocusOnMount.Mode`: Behavioral mode. Defaults to `"firstElement"` which focuses the first tabbable element within; `"firstInputElement"` focuses the first value control within; `true` focuses the element itself; `false` does nothing.
362
362
 
363
363
  _Returns_
364
364
 
365
- - `React.RefCallback<HTMLElement>`: Ref callback.
365
+ - Ref callback.
366
366
 
367
367
  ### useFocusReturn
368
368
 
@@ -36,7 +36,7 @@ module.exports = __toCommonJS(use_dialog_exports);
36
36
  var import_element = require("@wordpress/element");
37
37
  var import_keycodes = require("@wordpress/keycodes");
38
38
  var import_use_constrained_tabbing = __toESM(require("../use-constrained-tabbing/index.cjs"));
39
- var import_use_focus_on_mount = __toESM(require("../use-focus-on-mount/index.cjs"));
39
+ var import_use_focus_on_mount = require("../use-focus-on-mount/index.cjs");
40
40
  var import_use_focus_return = __toESM(require("../use-focus-return/index.cjs"));
41
41
  var import_use_focus_outside = __toESM(require("../use-focus-outside/index.cjs"));
42
42
  var import_use_merge_refs = __toESM(require("../use-merge-refs/index.cjs"));
@@ -47,7 +47,7 @@ function useDialog(options) {
47
47
  currentOptions.current = options;
48
48
  }, Object.values(options));
49
49
  const constrainedTabbingRef = (0, import_use_constrained_tabbing.default)();
50
- const focusOnMountRef = (0, import_use_focus_on_mount.default)(options.focusOnMount);
50
+ const focusOnMountRef = (0, import_use_focus_on_mount.useFocusOnMount)(options.focusOnMount);
51
51
  const focusReturnRef = (0, import_use_focus_return.default)();
52
52
  const focusOutsideProps = (0, import_use_focus_outside.default)((event) => {
53
53
  if (currentOptions.current?.__unstableOnClose) {
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/use-dialog/index.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { RefCallback, SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport useConstrainedTabbing from '../use-constrained-tabbing';\nimport useFocusOnMount from '../use-focus-on-mount';\nimport useFocusReturn from '../use-focus-return';\nimport useFocusOutside from '../use-focus-outside';\nimport useMergeRefs from '../use-merge-refs';\n\ntype DialogOptions = {\n\t/**\n\t * Determines whether focus should be automatically moved to the popover\n\t * when it mounts. `false` causes no focus shift, `true` causes the popover\n\t * itself to gain focus, and `firstElement` focuses the first focusable\n\t * element within the popover.\n\t *\n\t * @default 'firstElement'\n\t */\n\tfocusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];\n\t/**\n\t * Determines whether tabbing is constrained to within the popover,\n\t * preventing keyboard focus from leaving the popover content without\n\t * explicit focus elsewhere, or whether the popover remains part of the\n\t * wider tab order.\n\t * If no value is passed, it will be derived from `focusOnMount`.\n\t *\n\t * @see focusOnMount\n\t * @default `focusOnMount` !== false\n\t */\n\tconstrainTabbing?: boolean;\n\tonClose?: () => void;\n\t/**\n\t * Use the `onClose` prop instead.\n\t *\n\t * @deprecated\n\t */\n\t__unstableOnClose?: (\n\t\ttype: string | undefined,\n\t\tevent: SyntheticEvent\n\t) => void;\n};\n\ntype useDialogReturn = [\n\tRefCallback< HTMLElement >,\n\tReturnType< typeof useFocusOutside > & Pick< HTMLElement, 'tabIndex' >,\n];\n\n/**\n * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:\n * - constrained tabbing.\n * - focus on mount.\n * - return focus on unmount.\n * - focus outside.\n *\n * @param options Dialog Options.\n */\nfunction useDialog( options: DialogOptions ): useDialogReturn {\n\tconst currentOptions = useRef< DialogOptions >( undefined );\n\tconst { constrainTabbing = options.focusOnMount !== false } = options;\n\tuseEffect( () => {\n\t\tcurrentOptions.current = options;\n\t}, Object.values( options ) );\n\tconst constrainedTabbingRef = useConstrainedTabbing();\n\tconst focusOnMountRef = useFocusOnMount( options.focusOnMount );\n\tconst focusReturnRef = useFocusReturn();\n\tconst focusOutsideProps = useFocusOutside( ( event ) => {\n\t\t// This unstable prop is here only to manage backward compatibility\n\t\t// for the Popover component otherwise, the onClose should be enough.\n\t\tif ( currentOptions.current?.__unstableOnClose ) {\n\t\t\tcurrentOptions.current.__unstableOnClose( 'focus-outside', event );\n\t\t} else if ( currentOptions.current?.onClose ) {\n\t\t\tcurrentOptions.current.onClose();\n\t\t}\n\t} );\n\tconst closeOnEscapeRef = useCallback( ( node: HTMLElement ) => {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', ( event: KeyboardEvent ) => {\n\t\t\t// Close on escape.\n\t\t\tif (\n\t\t\t\tevent.keyCode === ESCAPE &&\n\t\t\t\t! event.defaultPrevented &&\n\t\t\t\tcurrentOptions.current?.onClose\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcurrentOptions.current.onClose();\n\t\t\t}\n\t\t} );\n\t}, [] );\n\n\treturn [\n\t\tuseMergeRefs( [\n\t\t\tconstrainTabbing ? constrainedTabbingRef : null,\n\t\t\toptions.focusOnMount !== false ? focusReturnRef : null,\n\t\t\toptions.focusOnMount !== false ? focusOnMountRef : null,\n\t\t\tcloseOnEscapeRef,\n\t\t] ),\n\t\t{\n\t\t\t...focusOutsideProps,\n\t\t\ttabIndex: -1,\n\t\t},\n\t];\n}\n\nexport default useDialog;\n"],
5
- "mappings": ";;;;;;;;;;;;;;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AA,EACD;AACD;AAEA,IAAO,qBAAQ;",
6
- "names": ["useConstrainedTabbing", "useFocusOnMount", "useFocusReturn", "useFocusOutside", "useMergeRefs"]
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { RefCallback, SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport useConstrainedTabbing from '../use-constrained-tabbing';\nimport { useFocusOnMount } from '../use-focus-on-mount';\nimport useFocusReturn from '../use-focus-return';\nimport useFocusOutside from '../use-focus-outside';\nimport useMergeRefs from '../use-merge-refs';\n\ntype DialogOptions = {\n\t/**\n\t * Determines focus behavior when the dialog mounts.\n\t *\n\t * - `\"firstElement\"` focuses the first tabbable element within.\n\t * - `\"firstInputElement\"` focuses the first value control within.\n\t * - `true` focuses the element itself.\n\t * - `false` does nothing and _should not be used unless an accessible\n\t * substitute behavior is implemented_.\n\t *\n\t * @default 'firstElement'\n\t */\n\tfocusOnMount?: useFocusOnMount.Mode;\n\t/**\n\t * Determines whether tabbing is constrained to within the popover,\n\t * preventing keyboard focus from leaving the popover content without\n\t * explicit focus elsewhere, or whether the popover remains part of the\n\t * wider tab order.\n\t * If no value is passed, it will be derived from `focusOnMount`.\n\t *\n\t * @see focusOnMount\n\t * @default `focusOnMount` !== false\n\t */\n\tconstrainTabbing?: boolean;\n\tonClose?: () => void;\n\t/**\n\t * Use the `onClose` prop instead.\n\t *\n\t * @deprecated\n\t */\n\t__unstableOnClose?: (\n\t\ttype: string | undefined,\n\t\tevent: SyntheticEvent\n\t) => void;\n};\n\ntype useDialogReturn = [\n\tRefCallback< HTMLElement >,\n\tReturnType< typeof useFocusOutside > & Pick< HTMLElement, 'tabIndex' >,\n];\n\n/**\n * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:\n * - constrained tabbing.\n * - focus on mount.\n * - return focus on unmount.\n * - focus outside.\n *\n * @param options Dialog Options.\n */\nfunction useDialog( options: DialogOptions ): useDialogReturn {\n\tconst currentOptions = useRef< DialogOptions >( undefined );\n\tconst { constrainTabbing = options.focusOnMount !== false } = options;\n\tuseEffect( () => {\n\t\tcurrentOptions.current = options;\n\t}, Object.values( options ) );\n\tconst constrainedTabbingRef = useConstrainedTabbing();\n\tconst focusOnMountRef = useFocusOnMount( options.focusOnMount );\n\tconst focusReturnRef = useFocusReturn();\n\tconst focusOutsideProps = useFocusOutside( ( event ) => {\n\t\t// This unstable prop is here only to manage backward compatibility\n\t\t// for the Popover component otherwise, the onClose should be enough.\n\t\tif ( currentOptions.current?.__unstableOnClose ) {\n\t\t\tcurrentOptions.current.__unstableOnClose( 'focus-outside', event );\n\t\t} else if ( currentOptions.current?.onClose ) {\n\t\t\tcurrentOptions.current.onClose();\n\t\t}\n\t} );\n\tconst closeOnEscapeRef = useCallback( ( node: HTMLElement ) => {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', ( event: KeyboardEvent ) => {\n\t\t\t// Close on escape.\n\t\t\tif (\n\t\t\t\tevent.keyCode === ESCAPE &&\n\t\t\t\t! event.defaultPrevented &&\n\t\t\t\tcurrentOptions.current?.onClose\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcurrentOptions.current.onClose();\n\t\t\t}\n\t\t} );\n\t}, [] );\n\n\treturn [\n\t\tuseMergeRefs( [\n\t\t\tconstrainTabbing ? constrainedTabbingRef : null,\n\t\t\toptions.focusOnMount !== false ? focusReturnRef : null,\n\t\t\toptions.focusOnMount !== false ? focusOnMountRef : null,\n\t\t\tcloseOnEscapeRef,\n\t\t] ),\n\t\t{\n\t\t\t...focusOutsideProps,\n\t\t\ttabIndex: -1,\n\t\t},\n\t];\n}\n\nexport default useDialog;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA,qBAA+C;AAC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usOutside", "useMergeRefs"]
7
7
  }
@@ -27,14 +27,14 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
27
27
  ));
28
28
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
29
 
30
- // packages/compose/src/hooks/use-focus-on-mount/index.js
30
+ // packages/compose/src/hooks/use-focus-on-mount/index.ts
31
31
  var use_focus_on_mount_exports = {};
32
32
  __export(use_focus_on_mount_exports, {
33
- default: () => useFocusOnMount
33
+ useFocusOnMount: () => useFocusOnMount
34
34
  });
35
35
  module.exports = __toCommonJS(use_focus_on_mount_exports);
36
- var import_element = require("@wordpress/element");
37
36
  var import_dom = require("@wordpress/dom");
37
+ var import_element = require("@wordpress/element");
38
38
  var import_use_ref_effect = __toESM(require("../use-ref-effect/index.cjs"));
39
39
  function useFocusOnMount(focusOnMount = "firstElement") {
40
40
  const focusOnMountRef = (0, import_element.useRef)(focusOnMount);
@@ -46,12 +46,11 @@ function useFocusOnMount(focusOnMount = "firstElement") {
46
46
  preventScroll: true
47
47
  });
48
48
  };
49
- const timerIdRef = (0, import_element.useRef)(void 0);
50
49
  (0, import_element.useEffect)(() => {
51
50
  focusOnMountRef.current = focusOnMount;
52
51
  }, [focusOnMount]);
53
52
  return (0, import_use_ref_effect.default)((node) => {
54
- if (!node || focusOnMountRef.current === false) {
53
+ if (focusOnMountRef.current === false) {
55
54
  return;
56
55
  }
57
56
  if (node.contains(node.ownerDocument?.activeElement ?? null)) {
@@ -61,14 +60,11 @@ function useFocusOnMount(focusOnMount = "firstElement") {
61
60
  setFocus(node);
62
61
  return;
63
62
  }
64
- timerIdRef.current = setTimeout(() => {
63
+ const timerId = setTimeout(() => {
65
64
  if (focusOnMountRef.current === "firstInputElement") {
66
- let formInput = null;
67
- if (typeof window !== "undefined" && node instanceof window.Element) {
68
- formInput = node.querySelector(
69
- 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
70
- );
71
- }
65
+ const formInput = node.querySelector(
66
+ 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
67
+ );
72
68
  if (formInput) {
73
69
  setFocus(formInput);
74
70
  return;
@@ -80,10 +76,12 @@ function useFocusOnMount(focusOnMount = "firstElement") {
80
76
  }
81
77
  }, 0);
82
78
  return () => {
83
- if (timerIdRef.current) {
84
- clearTimeout(timerIdRef.current);
85
- }
79
+ clearTimeout(timerId);
86
80
  };
87
81
  }, []);
88
82
  }
83
+ // Annotate the CommonJS export names for ESM import in node:
84
+ 0 && (module.exports = {
85
+ useFocusOnMount
86
+ });
89
87
  //# sourceMappingURL=index.cjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/hooks/use-focus-on-mount/index.js"],
4
- "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' | 'firstInputElement'} focusOnMount Focus on mount mode.\n * @return {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 {React.MutableRefObject<ReturnType<setTimeout> | undefined>} */\n\tconst timerIdRef = useRef( undefined );\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 (\n\t\t\tfocusOnMountRef.current !== 'firstElement' &&\n\t\t\tfocusOnMountRef.current !== 'firstInputElement'\n\t\t) {\n\t\t\tsetFocus( node );\n\t\t\treturn;\n\t\t}\n\n\t\ttimerIdRef.current = setTimeout( () => {\n\t\t\t// For 'firstInputElement' mode, try to find a form input element first\n\t\t\tif ( focusOnMountRef.current === 'firstInputElement' ) {\n\t\t\t\t/** @type {HTMLElement | null} */\n\t\t\t\tlet formInput = null;\n\t\t\t\tif (\n\t\t\t\t\ttypeof window !== 'undefined' &&\n\t\t\t\t\tnode instanceof window.Element\n\t\t\t\t) {\n\t\t\t\t\tformInput = node.querySelector(\n\t\t\t\t\t\t'input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif ( formInput ) {\n\t\t\t\t\tsetFocus( formInput );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Fallback to the first tabbable element\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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAAkC;AAClC,iBAAsB;AAKtB,4BAAyB;AAuBV,SAAR,gBAAkC,eAAe,gBAAiB;AACxE,QAAM,sBAAkB,uBAAQ,YAAa;AAQ7C,QAAM,WAAW,CAAE,WAAY;AAC9B,WAAO,MAAO;AAAA;AAAA;AAAA;AAAA,MAIb,eAAe;AAAA,IAChB,CAAE;AAAA,EACH;AAGA,QAAM,iBAAa,uBAAQ,MAAU;AAErC,gCAAW,MAAM;AAChB,oBAAgB,UAAU;AAAA,EAC3B,GAAG,CAAE,YAAa,CAAE;AAEpB,aAAO,sBAAAA,SAAc,CAAE,SAAU;AAChC,QAAK,CAAE,QAAQ,gBAAgB,YAAY,OAAQ;AAClD;AAAA,IACD;AAEA,QAAK,KAAK,SAAU,KAAK,eAAe,iBAAiB,IAAK,GAAI;AACjE;AAAA,IACD;AAEA,QACC,gBAAgB,YAAY,kBAC5B,gBAAgB,YAAY,qBAC3B;AACD,eAAU,IAAK;AACf;AAAA,IACD;AAEA,eAAW,UAAU,WAAY,MAAM;AAEtC,UAAK,gBAAgB,YAAY,qBAAsB;AAEtD,YAAI,YAAY;AAChB,YACC,OAAO,WAAW,eAClB,gBAAgB,OAAO,SACtB;AACD,sBAAY,KAAK;AAAA,YAChB;AAAA,UACD;AAAA,QACD;AAEA,YAAK,WAAY;AAChB,mBAAU,SAAU;AACpB;AAAA,QACD;AAAA,MACD;AAGA,YAAM,gBAAgB,iBAAM,SAAS,KAAM,IAAK,EAAG,CAAE;AACrD,UAAK,eAAgB;AACpB,iBAAU,aAAc;AAAA,MACzB;AAAA,IACD,GAAG,CAAE;AAEL,WAAO,MAAM;AACZ,UAAK,WAAW,SAAU;AACzB,qBAAc,WAAW,OAAQ;AAAA,MAClC;AAAA,IACD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
3
+ "sources": ["../../../src/hooks/use-focus-on-mount/index.ts"],
4
+ "sourcesContent": ["import { focus } from '@wordpress/dom';\nimport { useEffect, useRef } from '@wordpress/element';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Determines focus behavior when the element mounts.\n *\n * @param focusOnMount Behavioral mode. Defaults to `\"firstElement\"` which focuses the\n * first tabbable element within; `\"firstInputElement\"` focuses the\n * first value control within; `true` focuses the element itself;\n * `false` does nothing.\n * @return 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 function useFocusOnMount(\n\tfocusOnMount: useFocusOnMount.Mode = 'firstElement'\n) {\n\tconst focusOnMountRef = useRef( focusOnMount );\n\n\t/**\n\t * Sets focus on a DOM element.\n\t *\n\t * @param target The DOM element to set focus to.\n\t */\n\tconst setFocus = ( target: HTMLElement ): void => {\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\tuseEffect( () => {\n\t\tfocusOnMountRef.current = focusOnMount;\n\t}, [ focusOnMount ] );\n\n\treturn useRefEffect< HTMLElement >( ( node ) => {\n\t\tif ( 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 (\n\t\t\tfocusOnMountRef.current !== 'firstElement' &&\n\t\t\tfocusOnMountRef.current !== 'firstInputElement'\n\t\t) {\n\t\t\tsetFocus( node );\n\t\t\treturn;\n\t\t}\n\n\t\tconst timerId = setTimeout( () => {\n\t\t\t// For 'firstInputElement' mode, try to find a form input element first\n\t\t\tif ( focusOnMountRef.current === 'firstInputElement' ) {\n\t\t\t\tconst formInput = node.querySelector< HTMLElement >(\n\t\t\t\t\t'input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'\n\t\t\t\t);\n\n\t\t\t\tif ( formInput ) {\n\t\t\t\t\tsetFocus( formInput );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Fallback to the first tabbable element\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\tclearTimeout( timerId );\n\t\t};\n\t}, [] );\n}\n\nexport namespace useFocusOnMount {\n\texport type Mode = boolean | 'firstElement' | 'firstInputElement';\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,iBAAsB;AACtB,qBAAkC;AAClC,4BAAyB;AA0BlB,SAAS,gBACf,eAAqC,gBACpC;AACD,QAAM,sBAAkB,uBAAQ,YAAa;AAO7C,QAAM,WAAW,CAAE,WAA+B;AACjD,WAAO,MAAO;AAAA;AAAA;AAAA;AAAA,MAIb,eAAe;AAAA,IAChB,CAAE;AAAA,EACH;AAEA,gCAAW,MAAM;AAChB,oBAAgB,UAAU;AAAA,EAC3B,GAAG,CAAE,YAAa,CAAE;AAEpB,aAAO,sBAAAA,SAA6B,CAAE,SAAU;AAC/C,QAAK,gBAAgB,YAAY,OAAQ;AACxC;AAAA,IACD;AAEA,QAAK,KAAK,SAAU,KAAK,eAAe,iBAAiB,IAAK,GAAI;AACjE;AAAA,IACD;AAEA,QACC,gBAAgB,YAAY,kBAC5B,gBAAgB,YAAY,qBAC3B;AACD,eAAU,IAAK;AACf;AAAA,IACD;AAEA,UAAM,UAAU,WAAY,MAAM;AAEjC,UAAK,gBAAgB,YAAY,qBAAsB;AACtD,cAAM,YAAY,KAAK;AAAA,UACtB;AAAA,QACD;AAEA,YAAK,WAAY;AAChB,mBAAU,SAAU;AACpB;AAAA,QACD;AAAA,MACD;AAGA,YAAM,gBAAgB,iBAAM,SAAS,KAAM,IAAK,EAAG,CAAE;AACrD,UAAK,eAAgB;AACpB,iBAAU,aAAc;AAAA,MACzB;AAAA,IACD,GAAG,CAAE;AAEL,WAAO,MAAM;AACZ,mBAAc,OAAQ;AAAA,IACvB;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
6
6
  "names": ["useRefEffect"]
7
7
  }
package/build/index.cjs CHANGED
@@ -48,7 +48,7 @@ __export(index_exports, {
48
48
  useDebouncedInput: () => import_use_debounced_input.default,
49
49
  useDisabled: () => import_use_disabled.default,
50
50
  useEvent: () => import_use_event.default,
51
- useFocusOnMount: () => import_use_focus_on_mount.default,
51
+ useFocusOnMount: () => import_use_focus_on_mount.useFocusOnMount,
52
52
  useFocusReturn: () => import_use_focus_return.default,
53
53
  useFocusableIframe: () => import_use_focusable_iframe.default,
54
54
  useInstanceId: () => import_use_instance_id.default,
@@ -90,7 +90,7 @@ var import_use_dialog = __toESM(require("./hooks/use-dialog/index.cjs"));
90
90
  var import_use_disabled = __toESM(require("./hooks/use-disabled/index.cjs"));
91
91
  var import_use_event = __toESM(require("./hooks/use-event/index.cjs"));
92
92
  var import_use_dragging = __toESM(require("./hooks/use-dragging/index.cjs"));
93
- var import_use_focus_on_mount = __toESM(require("./hooks/use-focus-on-mount/index.cjs"));
93
+ var import_use_focus_on_mount = require("./hooks/use-focus-on-mount/index.cjs");
94
94
  var import_use_focus_outside = __toESM(require("./hooks/use-focus-outside/index.cjs"));
95
95
  var import_use_focus_return = __toESM(require("./hooks/use-focus-return/index.cjs"));
96
96
  var import_use_instance_id = __toESM(require("./hooks/use-instance-id/index.cjs"));
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.js"],
4
- "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"],
5
- "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAc,4DADd;AAGA,0BAAc,uCAHd;AAKA,0BAAc,uCALd;AAOA,0BAAc,6CAPd;AAUA,qBAAmC;AACnC,kBAAgC;AAGhC,0BAAuC;AACvC,kBAAgC;AAChC,gCAA4C;AAC5C,8BAA0C;AAC1C,+BAA2C;AAC3C,wBAAqC;AAGrC,qCAAiD;AACjD,+BAA0C;AAC1C,mCAA8C;AAC9C,wBAAmD;AACnD,0BAAuC;AACvC,uBAAoC;AACpC,0BAAqD;AACrD,gCAA2C;AAC3C,+BAAyD;AACzD,8BAA0C;AAC1C,6BAAyC;AACzC,0CAAqD;AACrD,mCAA+C;AAC/C,6BAAyC;AACzC,0BAAuC;AACvC,gCAA4C;AAC5C,oCAA+C;AAC/C,gCAA4C;AAC5C,iCAA6C;AAC7C,4BAAwC;AACxC,gCAA2C;AAC3C,0BAAuC;AACvC,iCAA6C;AAC7C,0BAAuC;AACvC,4BAAwC;AACxC,4BAAwC;AACxC,2BAAqD;AACrD,kCAA8C;AAC9C,mCAA4D;AAC5D,kCAA8C;",
4
+ "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 { 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"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,0BAAc,4DADd;AAGA,0BAAc,uCAHd;AAKA,0BAAc,uCALd;AAOA,0BAAc,6CAPd;AAUA,qBAAmC;AACnC,kBAAgC;AAGhC,0BAAuC;AACvC,kBAAgC;AAChC,gCAA4C;AAC5C,8BAA0C;AAC1C,+BAA2C;AAC3C,wBAAqC;AAGrC,qCAAiD;AACjD,+BAA0C;AAC1C,mCAA8C;AAC9C,wBAAmD;AACnD,0BAAuC;AACvC,uBAAoC;AACpC,0BAAqD;AACrD,gCAAgC;AAChC,+BAAyD;AACzD,8BAA0C;AAC1C,6BAAyC;AACzC,0CAAqD;AACrD,mCAA+C;AAC/C,6BAAyC;AACzC,0BAAuC;AACvC,gCAA4C;AAC5C,oCAA+C;AAC/C,gCAA4C;AAC5C,iCAA6C;AAC7C,4BAAwC;AACxC,gCAA2C;AAC3C,0BAAuC;AACvC,iCAA6C;AAC7C,0BAAuC;AACvC,4BAAwC;AACxC,4BAAwC;AACxC,2BAAqD;AACrD,kCAA8C;AAC9C,mCAA4D;AAC5D,kCAA8C;",
6
6
  "names": []
7
7
  }
@@ -2,7 +2,7 @@
2
2
  import { useRef, useEffect, useCallback } from "@wordpress/element";
3
3
  import { ESCAPE } from "@wordpress/keycodes";
4
4
  import useConstrainedTabbing from "../use-constrained-tabbing/index.mjs";
5
- import useFocusOnMount from "../use-focus-on-mount/index.mjs";
5
+ import { useFocusOnMount } from "../use-focus-on-mount/index.mjs";
6
6
  import useFocusReturn from "../use-focus-return/index.mjs";
7
7
  import useFocusOutside from "../use-focus-outside/index.mjs";
8
8
  import useMergeRefs from "../use-merge-refs/index.mjs";
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/use-dialog/index.ts"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport type { RefCallback, SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport useConstrainedTabbing from '../use-constrained-tabbing';\nimport useFocusOnMount from '../use-focus-on-mount';\nimport useFocusReturn from '../use-focus-return';\nimport useFocusOutside from '../use-focus-outside';\nimport useMergeRefs from '../use-merge-refs';\n\ntype DialogOptions = {\n\t/**\n\t * Determines whether focus should be automatically moved to the popover\n\t * when it mounts. `false` causes no focus shift, `true` causes the popover\n\t * itself to gain focus, and `firstElement` focuses the first focusable\n\t * element within the popover.\n\t *\n\t * @default 'firstElement'\n\t */\n\tfocusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];\n\t/**\n\t * Determines whether tabbing is constrained to within the popover,\n\t * preventing keyboard focus from leaving the popover content without\n\t * explicit focus elsewhere, or whether the popover remains part of the\n\t * wider tab order.\n\t * If no value is passed, it will be derived from `focusOnMount`.\n\t *\n\t * @see focusOnMount\n\t * @default `focusOnMount` !== false\n\t */\n\tconstrainTabbing?: boolean;\n\tonClose?: () => void;\n\t/**\n\t * Use the `onClose` prop instead.\n\t *\n\t * @deprecated\n\t */\n\t__unstableOnClose?: (\n\t\ttype: string | undefined,\n\t\tevent: SyntheticEvent\n\t) => void;\n};\n\ntype useDialogReturn = [\n\tRefCallback< HTMLElement >,\n\tReturnType< typeof useFocusOutside > & Pick< HTMLElement, 'tabIndex' >,\n];\n\n/**\n * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:\n * - constrained tabbing.\n * - focus on mount.\n * - return focus on unmount.\n * - focus outside.\n *\n * @param options Dialog Options.\n */\nfunction useDialog( options: DialogOptions ): useDialogReturn {\n\tconst currentOptions = useRef< DialogOptions >( undefined );\n\tconst { constrainTabbing = options.focusOnMount !== false } = options;\n\tuseEffect( () => {\n\t\tcurrentOptions.current = options;\n\t}, Object.values( options ) );\n\tconst constrainedTabbingRef = useConstrainedTabbing();\n\tconst focusOnMountRef = useFocusOnMount( options.focusOnMount );\n\tconst focusReturnRef = useFocusReturn();\n\tconst focusOutsideProps = useFocusOutside( ( event ) => {\n\t\t// This unstable prop is here only to manage backward compatibility\n\t\t// for the Popover component otherwise, the onClose should be enough.\n\t\tif ( currentOptions.current?.__unstableOnClose ) {\n\t\t\tcurrentOptions.current.__unstableOnClose( 'focus-outside', event );\n\t\t} else if ( currentOptions.current?.onClose ) {\n\t\t\tcurrentOptions.current.onClose();\n\t\t}\n\t} );\n\tconst closeOnEscapeRef = useCallback( ( node: HTMLElement ) => {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', ( event: KeyboardEvent ) => {\n\t\t\t// Close on escape.\n\t\t\tif (\n\t\t\t\tevent.keyCode === ESCAPE &&\n\t\t\t\t! event.defaultPrevented &&\n\t\t\t\tcurrentOptions.current?.onClose\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcurrentOptions.current.onClose();\n\t\t\t}\n\t\t} );\n\t}, [] );\n\n\treturn [\n\t\tuseMergeRefs( [\n\t\t\tconstrainTabbing ? constrainedTabbingRef : null,\n\t\t\toptions.focusOnMount !== false ? focusReturnRef : null,\n\t\t\toptions.focusOnMount !== false ? focusOnMountRef : null,\n\t\t\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;AAAA,MACnD;AAAA,IACD,CAAE;AAAA,IACF;AAAA,MACC,GAAG;AAAA,MACH,UAAU;AAAA,IACX;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
4
+ "sourcesContent": ["/**\n * External dependencies\n */\nimport type { RefCallback, SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport useConstrainedTabbing from '../use-constrained-tabbing';\nimport { useFocusOnMount } from '../use-focus-on-mount';\nimport useFocusReturn from '../use-focus-return';\nimport useFocusOutside from '../use-focus-outside';\nimport useMergeRefs from '../use-merge-refs';\n\ntype DialogOptions = {\n\t/**\n\t * Determines focus behavior when the dialog mounts.\n\t *\n\t * - `\"firstElement\"` focuses the first tabbable element within.\n\t * - `\"firstInputElement\"` focuses the first value control within.\n\t * - `true` focuses the element itself.\n\t * - `false` does nothing and _should not be used unless an accessible\n\t * substitute behavior is implemented_.\n\t *\n\t * @default 'firstElement'\n\t */\n\tfocusOnMount?: useFocusOnMount.Mode;\n\t/**\n\t * Determines whether tabbing is constrained to within the popover,\n\t * preventing keyboard focus from leaving the popover content without\n\t * explicit focus elsewhere, or whether the popover remains part of the\n\t * wider tab order.\n\t * If no value is passed, it will be derived from `focusOnMount`.\n\t *\n\t * @see focusOnMount\n\t * @default `focusOnMount` !== false\n\t */\n\tconstrainTabbing?: boolean;\n\tonClose?: () => void;\n\t/**\n\t * Use the `onClose` prop instead.\n\t *\n\t * @deprecated\n\t */\n\t__unstableOnClose?: (\n\t\ttype: string | undefined,\n\t\tevent: SyntheticEvent\n\t) => void;\n};\n\ntype useDialogReturn = [\n\tRefCallback< HTMLElement >,\n\tReturnType< typeof useFocusOutside > & Pick< HTMLElement, 'tabIndex' >,\n];\n\n/**\n * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:\n * - constrained tabbing.\n * - focus on mount.\n * - return focus on unmount.\n * - focus outside.\n *\n * @param options Dialog Options.\n */\nfunction useDialog( options: DialogOptions ): useDialogReturn {\n\tconst currentOptions = useRef< DialogOptions >( undefined );\n\tconst { constrainTabbing = options.focusOnMount !== false } = options;\n\tuseEffect( () => {\n\t\tcurrentOptions.current = options;\n\t}, Object.values( options ) );\n\tconst constrainedTabbingRef = useConstrainedTabbing();\n\tconst focusOnMountRef = useFocusOnMount( options.focusOnMount );\n\tconst focusReturnRef = useFocusReturn();\n\tconst focusOutsideProps = useFocusOutside( ( event ) => {\n\t\t// This unstable prop is here only to manage backward compatibility\n\t\t// for the Popover component otherwise, the onClose should be enough.\n\t\tif ( currentOptions.current?.__unstableOnClose ) {\n\t\t\tcurrentOptions.current.__unstableOnClose( 'focus-outside', event );\n\t\t} else if ( currentOptions.current?.onClose ) {\n\t\t\tcurrentOptions.current.onClose();\n\t\t}\n\t} );\n\tconst closeOnEscapeRef = useCallback( ( node: HTMLElement ) => {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', ( event: KeyboardEvent ) => {\n\t\t\t// Close on escape.\n\t\t\tif (\n\t\t\t\tevent.keyCode === ESCAPE &&\n\t\t\t\t! event.defaultPrevented &&\n\t\t\t\tcurrentOptions.current?.onClose\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcurrentOptions.current.onClose();\n\t\t\t}\n\t\t} );\n\t}, [] );\n\n\treturn [\n\t\tuseMergeRefs( [\n\t\t\tconstrainTabbing ? constrainedTabbingRef : null,\n\t\t\toptions.focusOnMount !== false ? focusReturnRef : null,\n\t\t\toptions.focusOnMount !== false ? focusOnMountRef : null,\n\t\t\tcloseOnEscapeRef,\n\t\t] ),\n\t\t{\n\t\t\t...focusOutsideProps,\n\t\t\ttabIndex: -1,\n\t\t},\n\t];\n}\n\nexport default useDialog;\n"],
5
+ "mappings": ";AAQA,SAAS,QAAQ,WAAW,mBAAmB;AAC/C,SAAS,cAAc;AAKvB,OAAO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/index.js
2
- import { useRef, useEffect } from "@wordpress/element";
1
+ // packages/compose/src/hooks/use-focus-on-mount/index.ts
3
2
  import { focus } from "@wordpress/dom";
3
+ import { useEffect, useRef } from "@wordpress/element";
4
4
  import useRefEffect from "../use-ref-effect/index.mjs";
5
5
  function useFocusOnMount(focusOnMount = "firstElement") {
6
6
  const focusOnMountRef = useRef(focusOnMount);
@@ -12,12 +12,11 @@ function useFocusOnMount(focusOnMount = "firstElement") {
12
12
  preventScroll: true
13
13
  });
14
14
  };
15
- const timerIdRef = useRef(void 0);
16
15
  useEffect(() => {
17
16
  focusOnMountRef.current = focusOnMount;
18
17
  }, [focusOnMount]);
19
18
  return useRefEffect((node) => {
20
- if (!node || focusOnMountRef.current === false) {
19
+ if (focusOnMountRef.current === false) {
21
20
  return;
22
21
  }
23
22
  if (node.contains(node.ownerDocument?.activeElement ?? null)) {
@@ -27,14 +26,11 @@ function useFocusOnMount(focusOnMount = "firstElement") {
27
26
  setFocus(node);
28
27
  return;
29
28
  }
30
- timerIdRef.current = setTimeout(() => {
29
+ const timerId = setTimeout(() => {
31
30
  if (focusOnMountRef.current === "firstInputElement") {
32
- let formInput = null;
33
- if (typeof window !== "undefined" && node instanceof window.Element) {
34
- formInput = node.querySelector(
35
- 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
36
- );
37
- }
31
+ const formInput = node.querySelector(
32
+ 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
33
+ );
38
34
  if (formInput) {
39
35
  setFocus(formInput);
40
36
  return;
@@ -46,13 +42,11 @@ function useFocusOnMount(focusOnMount = "firstElement") {
46
42
  }
47
43
  }, 0);
48
44
  return () => {
49
- if (timerIdRef.current) {
50
- clearTimeout(timerIdRef.current);
51
- }
45
+ clearTimeout(timerId);
52
46
  };
53
47
  }, []);
54
48
  }
55
49
  export {
56
- useFocusOnMount as default
50
+ useFocusOnMount
57
51
  };
58
52
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/hooks/use-focus-on-mount/index.js"],
4
- "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' | 'firstInputElement'} focusOnMount Focus on mount mode.\n * @return {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 {React.MutableRefObject<ReturnType<setTimeout> | undefined>} */\n\tconst timerIdRef = useRef( undefined );\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 (\n\t\t\tfocusOnMountRef.current !== 'firstElement' &&\n\t\t\tfocusOnMountRef.current !== 'firstInputElement'\n\t\t) {\n\t\t\tsetFocus( node );\n\t\t\treturn;\n\t\t}\n\n\t\ttimerIdRef.current = setTimeout( () => {\n\t\t\t// For 'firstInputElement' mode, try to find a form input element first\n\t\t\tif ( focusOnMountRef.current === 'firstInputElement' ) {\n\t\t\t\t/** @type {HTMLElement | null} */\n\t\t\t\tlet formInput = null;\n\t\t\t\tif (\n\t\t\t\t\ttypeof window !== 'undefined' &&\n\t\t\t\t\tnode instanceof window.Element\n\t\t\t\t) {\n\t\t\t\t\tformInput = node.querySelector(\n\t\t\t\t\t\t'input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'\n\t\t\t\t\t);\n\t\t\t\t}\n\n\t\t\t\tif ( formInput ) {\n\t\t\t\t\tsetFocus( formInput );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Fallback to the first tabbable element\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"],
5
- "mappings": ";AAGA,SAAS,QAAQ,iBAAiB;AAClC,SAAS,aAAa;AAKtB,OAAO,kBAAkB;AAuBV,SAAR,gBAAkC,eAAe,gBAAiB;AACxE,QAAM,kBAAkB,OAAQ,YAAa;AAQ7C,QAAM,WAAW,CAAE,WAAY;AAC9B,WAAO,MAAO;AAAA;AAAA;AAAA;AAAA,MAIb,eAAe;AAAA,IAChB,CAAE;AAAA,EACH;AAGA,QAAM,aAAa,OAAQ,MAAU;AAErC,YAAW,MAAM;AAChB,oBAAgB,UAAU;AAAA,EAC3B,GAAG,CAAE,YAAa,CAAE;AAEpB,SAAO,aAAc,CAAE,SAAU;AAChC,QAAK,CAAE,QAAQ,gBAAgB,YAAY,OAAQ;AAClD;AAAA,IACD;AAEA,QAAK,KAAK,SAAU,KAAK,eAAe,iBAAiB,IAAK,GAAI;AACjE;AAAA,IACD;AAEA,QACC,gBAAgB,YAAY,kBAC5B,gBAAgB,YAAY,qBAC3B;AACD,eAAU,IAAK;AACf;AAAA,IACD;AAEA,eAAW,UAAU,WAAY,MAAM;AAEtC,UAAK,gBAAgB,YAAY,qBAAsB;AAEtD,YAAI,YAAY;AAChB,YACC,OAAO,WAAW,eAClB,gBAAgB,OAAO,SACtB;AACD,sBAAY,KAAK;AAAA,YAChB;AAAA,UACD;AAAA,QACD;AAEA,YAAK,WAAY;AAChB,mBAAU,SAAU;AACpB;AAAA,QACD;AAAA,MACD;AAGA,YAAM,gBAAgB,MAAM,SAAS,KAAM,IAAK,EAAG,CAAE;AACrD,UAAK,eAAgB;AACpB,iBAAU,aAAc;AAAA,MACzB;AAAA,IACD,GAAG,CAAE;AAEL,WAAO,MAAM;AACZ,UAAK,WAAW,SAAU;AACzB,qBAAc,WAAW,OAAQ;AAAA,MAClC;AAAA,IACD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
3
+ "sources": ["../../../src/hooks/use-focus-on-mount/index.ts"],
4
+ "sourcesContent": ["import { focus } from '@wordpress/dom';\nimport { useEffect, useRef } from '@wordpress/element';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Determines focus behavior when the element mounts.\n *\n * @param focusOnMount Behavioral mode. Defaults to `\"firstElement\"` which focuses the\n * first tabbable element within; `\"firstInputElement\"` focuses the\n * first value control within; `true` focuses the element itself;\n * `false` does nothing.\n * @return 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 function useFocusOnMount(\n\tfocusOnMount: useFocusOnMount.Mode = 'firstElement'\n) {\n\tconst focusOnMountRef = useRef( focusOnMount );\n\n\t/**\n\t * Sets focus on a DOM element.\n\t *\n\t * @param target The DOM element to set focus to.\n\t */\n\tconst setFocus = ( target: HTMLElement ): void => {\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\tuseEffect( () => {\n\t\tfocusOnMountRef.current = focusOnMount;\n\t}, [ focusOnMount ] );\n\n\treturn useRefEffect< HTMLElement >( ( node ) => {\n\t\tif ( 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 (\n\t\t\tfocusOnMountRef.current !== 'firstElement' &&\n\t\t\tfocusOnMountRef.current !== 'firstInputElement'\n\t\t) {\n\t\t\tsetFocus( node );\n\t\t\treturn;\n\t\t}\n\n\t\tconst timerId = setTimeout( () => {\n\t\t\t// For 'firstInputElement' mode, try to find a form input element first\n\t\t\tif ( focusOnMountRef.current === 'firstInputElement' ) {\n\t\t\t\tconst formInput = node.querySelector< HTMLElement >(\n\t\t\t\t\t'input:not([type=\"hidden\"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'\n\t\t\t\t);\n\n\t\t\t\tif ( formInput ) {\n\t\t\t\t\tsetFocus( formInput );\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t}\n\n\t\t\t// Fallback to the first tabbable element\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\tclearTimeout( timerId );\n\t\t};\n\t}, [] );\n}\n\nexport namespace useFocusOnMount {\n\texport type Mode = boolean | 'firstElement' | 'firstInputElement';\n}\n"],
5
+ "mappings": ";AAAA,SAAS,aAAa;AACtB,SAAS,WAAW,cAAc;AAClC,OAAO,kBAAkB;AA0BlB,SAAS,gBACf,eAAqC,gBACpC;AACD,QAAM,kBAAkB,OAAQ,YAAa;AAO7C,QAAM,WAAW,CAAE,WAA+B;AACjD,WAAO,MAAO;AAAA;AAAA;AAAA;AAAA,MAIb,eAAe;AAAA,IAChB,CAAE;AAAA,EACH;AAEA,YAAW,MAAM;AAChB,oBAAgB,UAAU;AAAA,EAC3B,GAAG,CAAE,YAAa,CAAE;AAEpB,SAAO,aAA6B,CAAE,SAAU;AAC/C,QAAK,gBAAgB,YAAY,OAAQ;AACxC;AAAA,IACD;AAEA,QAAK,KAAK,SAAU,KAAK,eAAe,iBAAiB,IAAK,GAAI;AACjE;AAAA,IACD;AAEA,QACC,gBAAgB,YAAY,kBAC5B,gBAAgB,YAAY,qBAC3B;AACD,eAAU,IAAK;AACf;AAAA,IACD;AAEA,UAAM,UAAU,WAAY,MAAM;AAEjC,UAAK,gBAAgB,YAAY,qBAAsB;AACtD,cAAM,YAAY,KAAK;AAAA,UACtB;AAAA,QACD;AAEA,YAAK,WAAY;AAChB,mBAAU,SAAU;AACpB;AAAA,QACD;AAAA,MACD;AAGA,YAAM,gBAAgB,MAAM,SAAS,KAAM,IAAK,EAAG,CAAE;AACrD,UAAK,eAAgB;AACpB,iBAAU,aAAc;AAAA,MACzB;AAAA,IACD,GAAG,CAAE;AAEL,WAAO,MAAM;AACZ,mBAAc,OAAQ;AAAA,IACvB;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
6
6
  "names": []
7
7
  }
@@ -18,64 +18,64 @@ import { default as default13 } from "./hooks/use-dialog/index.mjs";
18
18
  import { default as default14 } from "./hooks/use-disabled/index.mjs";
19
19
  import { default as default15 } from "./hooks/use-event/index.mjs";
20
20
  import { default as default16 } from "./hooks/use-dragging/index.mjs";
21
- import { default as default17 } from "./hooks/use-focus-on-mount/index.mjs";
22
- import { default as default18 } from "./hooks/use-focus-outside/index.mjs";
23
- import { default as default19 } from "./hooks/use-focus-return/index.mjs";
24
- import { default as default20 } from "./hooks/use-instance-id/index.mjs";
25
- import { default as default21 } from "./hooks/use-isomorphic-layout-effect/index.mjs";
26
- import { default as default22 } from "./hooks/use-keyboard-shortcut/index.mjs";
27
- import { default as default23 } from "./hooks/use-media-query/index.mjs";
28
- import { default as default24 } from "./hooks/use-previous/index.mjs";
29
- import { default as default25 } from "./hooks/use-reduced-motion/index.mjs";
30
- import { default as default26 } from "./hooks/use-state-with-history/index.mjs";
31
- import { default as default27 } from "./hooks/use-viewport-match/index.mjs";
32
- import { default as default28 } from "./hooks/use-resize-observer/index.mjs";
33
- import { default as default29 } from "./hooks/use-async-list/index.mjs";
34
- import { default as default30 } from "./hooks/use-warn-on-change/index.mjs";
35
- import { default as default31 } from "./hooks/use-debounce/index.mjs";
36
- import { default as default32 } from "./hooks/use-debounced-input/index.mjs";
37
- import { default as default33 } from "./hooks/use-throttle/index.mjs";
38
- import { default as default34 } from "./hooks/use-merge-refs/index.mjs";
39
- import { default as default35 } from "./hooks/use-ref-effect/index.mjs";
40
- import { default as default36 } from "./hooks/use-drop-zone/index.mjs";
41
- import { default as default37 } from "./hooks/use-focusable-iframe/index.mjs";
42
- import { default as default38 } from "./hooks/use-fixed-window-list/index.mjs";
43
- import { default as default39 } from "./hooks/use-observable-value/index.mjs";
21
+ import { useFocusOnMount } from "./hooks/use-focus-on-mount/index.mjs";
22
+ import { default as default17 } from "./hooks/use-focus-outside/index.mjs";
23
+ import { default as default18 } from "./hooks/use-focus-return/index.mjs";
24
+ import { default as default19 } from "./hooks/use-instance-id/index.mjs";
25
+ import { default as default20 } from "./hooks/use-isomorphic-layout-effect/index.mjs";
26
+ import { default as default21 } from "./hooks/use-keyboard-shortcut/index.mjs";
27
+ import { default as default22 } from "./hooks/use-media-query/index.mjs";
28
+ import { default as default23 } from "./hooks/use-previous/index.mjs";
29
+ import { default as default24 } from "./hooks/use-reduced-motion/index.mjs";
30
+ import { default as default25 } from "./hooks/use-state-with-history/index.mjs";
31
+ import { default as default26 } from "./hooks/use-viewport-match/index.mjs";
32
+ import { default as default27 } from "./hooks/use-resize-observer/index.mjs";
33
+ import { default as default28 } from "./hooks/use-async-list/index.mjs";
34
+ import { default as default29 } from "./hooks/use-warn-on-change/index.mjs";
35
+ import { default as default30 } from "./hooks/use-debounce/index.mjs";
36
+ import { default as default31 } from "./hooks/use-debounced-input/index.mjs";
37
+ import { default as default32 } from "./hooks/use-throttle/index.mjs";
38
+ import { default as default33 } from "./hooks/use-merge-refs/index.mjs";
39
+ import { default as default34 } from "./hooks/use-ref-effect/index.mjs";
40
+ import { default as default35 } from "./hooks/use-drop-zone/index.mjs";
41
+ import { default as default36 } from "./hooks/use-focusable-iframe/index.mjs";
42
+ import { default as default37 } from "./hooks/use-fixed-window-list/index.mjs";
43
+ import { default as default38 } from "./hooks/use-observable-value/index.mjs";
44
44
  export {
45
45
  default13 as __experimentalUseDialog,
46
46
  default16 as __experimentalUseDragging,
47
- default36 as __experimentalUseDropZone,
48
- default38 as __experimentalUseFixedWindowList,
49
- default18 as __experimentalUseFocusOutside,
47
+ default35 as __experimentalUseDropZone,
48
+ default37 as __experimentalUseFixedWindowList,
49
+ default17 as __experimentalUseFocusOutside,
50
50
  default2 as compose,
51
51
  default4 as ifCondition,
52
52
  default3 as pipe,
53
53
  default5 as pure,
54
- default29 as useAsyncList,
54
+ default28 as useAsyncList,
55
55
  default10 as useConstrainedTabbing,
56
56
  default11 as useCopyOnClick,
57
57
  default12 as useCopyToClipboard,
58
- default31 as useDebounce,
59
- default32 as useDebouncedInput,
58
+ default30 as useDebounce,
59
+ default31 as useDebouncedInput,
60
60
  default14 as useDisabled,
61
61
  default15 as useEvent,
62
- default17 as useFocusOnMount,
63
- default19 as useFocusReturn,
64
- default37 as useFocusableIframe,
65
- default20 as useInstanceId,
66
- default21 as useIsomorphicLayoutEffect,
67
- default22 as useKeyboardShortcut,
68
- default23 as useMediaQuery,
69
- default34 as useMergeRefs,
70
- default39 as useObservableValue,
71
- default24 as usePrevious,
72
- default25 as useReducedMotion,
73
- default35 as useRefEffect,
74
- default28 as useResizeObserver,
75
- default26 as useStateWithHistory,
76
- default33 as useThrottle,
77
- default27 as useViewportMatch,
78
- default30 as useWarnOnChange,
62
+ useFocusOnMount,
63
+ default18 as useFocusReturn,
64
+ default36 as useFocusableIframe,
65
+ default19 as useInstanceId,
66
+ default20 as useIsomorphicLayoutEffect,
67
+ default21 as useKeyboardShortcut,
68
+ default22 as useMediaQuery,
69
+ default33 as useMergeRefs,
70
+ default38 as useObservableValue,
71
+ default23 as usePrevious,
72
+ default24 as useReducedMotion,
73
+ default34 as useRefEffect,
74
+ default27 as useResizeObserver,
75
+ default25 as useStateWithHistory,
76
+ default32 as useThrottle,
77
+ default26 as useViewportMatch,
78
+ default29 as useWarnOnChange,
79
79
  default6 as withGlobalEvents,
80
80
  default7 as withInstanceId,
81
81
  default8 as withSafeTimeout,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/index.js"],
4
- "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"],
5
- "mappings": ";AACA,cAAc;AAEd,cAAc;AAEd,cAAc;AAEd,cAAc;AAGd,SAAoB,WAAXA,gBAA0B;AACnC,SAAoB,WAAXA,gBAAuB;AAGhC,SAAoB,WAAXA,gBAA8B;AACvC,SAAoB,WAAXA,gBAAuB;AAChC,SAAoB,WAAXA,gBAAmC;AAC5C,SAAoB,WAAXA,gBAAiC;AAC1C,SAAoB,WAAXA,gBAAkC;AAC3C,SAAoB,WAAXA,gBAA4B;AAGrC,SAAoB,WAAXA,iBAAwC;AACjD,SAAoB,WAAXA,iBAAiC;AAC1C,SAAoB,WAAXA,iBAAqC;AAC9C,SAAoB,WAAXA,iBAA0C;AACnD,SAAoB,WAAXA,iBAA8B;AACvC,SAAoB,WAAXA,iBAA2B;AACpC,SAAoB,WAAXA,iBAA4C;AACrD,SAAoB,WAAXA,iBAAkC;AAC3C,SAAoB,WAAXA,iBAAgD;AACzD,SAAoB,WAAXA,iBAAiC;AAC1C,SAAoB,WAAXA,iBAAgC;AACzC,SAAoB,WAAXA,iBAA4C;AACrD,SAAoB,WAAXA,iBAAsC;AAC/C,SAAoB,WAAXA,iBAAgC;AACzC,SAAoB,WAAXA,iBAA8B;AACvC,SAAoB,WAAXA,iBAAmC;AAC5C,SAAoB,WAAXA,iBAAsC;AAC/C,SAAoB,WAAXA,iBAAmC;AAC5C,SAAoB,WAAXA,iBAAoC;AAC7C,SAAoB,WAAXA,iBAA+B;AACxC,SAAoB,WAAXA,iBAAkC;AAC3C,SAAoB,WAAXA,iBAA8B;AACvC,SAAoB,WAAXA,iBAAoC;AAC7C,SAAoB,WAAXA,iBAA8B;AACvC,SAAoB,WAAXA,iBAA+B;AACxC,SAAoB,WAAXA,iBAA+B;AACxC,SAAoB,WAAXA,iBAA4C;AACrD,SAAoB,WAAXA,iBAAqC;AAC9C,SAAoB,WAAXA,iBAAmD;AAC5D,SAAoB,WAAXA,iBAAqC;",
4
+ "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 { 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"],
5
+ "mappings": ";AACA,cAAc;A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yntheticEvent } from 'react';
5
- import useFocusOnMount from '../use-focus-on-mount';
5
+ import { useFocusOnMount } from '../use-focus-on-mount';
6
6
  import useFocusOutside from '../use-focus-outside';
7
7
  type DialogOptions = {
8
8
  /**
9
- * Determines whether focus should be automatically moved to the popover
10
- * when it mounts. `false` causes no focus shift, `true` causes the popover
11
- * itself to gain focus, and `firstElement` focuses the first focusable
12
- * element within the popover.
9
+ * Determines focus behavior when the dialog mounts.
10
+ *
11
+ * - `"firstElement"` focuses the first tabbable element within.
12
+ * - `"firstInputElement"` focuses the first value control within.
13
+ * - `true` focuses the element itself.
14
+ * - `false` does nothing and _should not be used unless an accessible
15
+ * substitute behavior is implemented_.
13
16
  *
14
17
  * @default 'firstElement'
15
18
  */
16
- focusOnMount?: Parameters<typeof useFocusOnMount>[0];
19
+ focusOnMount?: useFocusOnMount.Mode;
17
20
  /**
18
21
  * Determines whether tabbing is constrained to within the popover,
19
22
  * preventing keyboard focus from leaving the popover content without
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAYzD,OAAO,eAAe,MAAM,uBAAuB,CAAC;AAEpD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAGnD,KAAK,aAAa,GAAG;IACpB;;;;;;;OAOG;IACH,YAAY,CAAC,EAAE,UAAU,CAAE,OAAO,eAAe,CAAE,CAAE,CAAC,CAAE,CAAC;IACzD;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,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,KAAK,eAAe,GAAG;IACtB,WAAW,CAAE,WAAW,CAAE;IAC1B,UAAU,CAAE,OAAO,eAAe,CAAE,GAAG,IAAI,CAAE,WAAW,EAAE,UAAU,CAAE;CACtE,CAAC;AAEF;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAE,OAAO,EAAE,aAAa,GAAI,eAAe,CAgD5D;AAED,eAAe,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EAAE,WAAW,EAAE,cAAc,EAAE,MAAM,OAAO,CAAC;AAYzD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AAExD,OAAO,eAAe,MAAM,sBAAsB,CAAC;AAGnD,KAAK,aAAa,GAAG;IACpB;;;;;;;;;;OAUG;IACH,YAAY,CAAC,EAAE,eAAe,CAAC,IAAI,CAAC;IACpC;;;;;;;;;OASG;IACH,gBAAgB,CAAC,EAAE,OAAO,CAAC;IAC3B,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,KAAK,eAAe,GAAG;IACtB,WAAW,CAAE,WAAW,CAAE;IAC1B,UAAU,CAAE,OAAO,eAAe,CAAE,GAAG,IAAI,CAAE,WAAW,EAAE,UAAU,CAAE;CACtE,CAAC;AAEF;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAE,OAAO,EAAE,aAAa,GAAI,eAAe,CAgD5D;AAED,eAAe,SAAS,CAAC"}
@@ -1,8 +1,11 @@
1
1
  /**
2
- * Hook used to focus the first tabbable element on mount.
2
+ * Determines focus behavior when the element mounts.
3
3
  *
4
- * @param {boolean | 'firstElement' | 'firstInputElement'} focusOnMount Focus on mount mode.
5
- * @return {React.RefCallback<HTMLElement>} Ref callback.
4
+ * @param focusOnMount Behavioral mode. Defaults to `"firstElement"` which focuses the
5
+ * first tabbable element within; `"firstInputElement"` focuses the
6
+ * first value control within; `true` focuses the element itself;
7
+ * `false` does nothing.
8
+ * @return Ref callback.
6
9
  *
7
10
  * @example
8
11
  * ```js
@@ -19,5 +22,8 @@
19
22
  * }
20
23
  * ```
21
24
  */
22
- export default function useFocusOnMount(focusOnMount?: boolean | "firstElement" | "firstInputElement"): React.RefCallback<HTMLElement>;
25
+ export declare function useFocusOnMount(focusOnMount?: useFocusOnMount.Mode): import("react").RefCallback<HTMLElement | null>;
26
+ export declare namespace useFocusOnMount {
27
+ type Mode = boolean | 'firstElement' | 'firstInputElement';
28
+ }
23
29
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-on-mount/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;;;;;;;GAoBG;AACH,uDAlBW,OAAO,GAAG,cAAc,GAAG,mBAAmB,GAC7C,KAAK,CAAC,WAAW,CAAC,WAAW,CAAC,CA4FzC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-focus-on-mount/index.ts"],"names":[],"mappings":"AAIA;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,eAAe,CAC9B,YAAY,GAAE,eAAe,CAAC,IAAqB,mDA+DnD;AAED,yBAAiB,eAAe,CAAC;IAChC,KAAY,IAAI,GAAG,OAAO,GAAG,cAAc,GAAG,mBAAmB,CAAC;CAClE"}
@@ -17,7 +17,7 @@ export { default as __experimentalUseDialog } from "./hooks/use-dialog";
17
17
  export { default as useDisabled } from "./hooks/use-disabled";
18
18
  export { default as useEvent } from "./hooks/use-event";
19
19
  export { default as __experimentalUseDragging } from "./hooks/use-dragging";
20
- export { default as useFocusOnMount } from "./hooks/use-focus-on-mount";
20
+ export { useFocusOnMount } from "./hooks/use-focus-on-mount";
21
21
  export { default as __experimentalUseFocusOutside } from "./hooks/use-focus-outside";
22
22
  export { default as useFocusReturn } from "./hooks/use-focus-return";
23
23
  export { default as useInstanceId } from "./hooks/use-instance-id";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/compose",
3
- "version": "7.40.1-next.v.202602241322.0+bce7cff88",
3
+ "version": "7.40.1-next.v.202602271551.0+464abe399",
4
4
  "description": "WordPress higher-order components (HOCs).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -47,13 +47,13 @@
47
47
  "sideEffects": false,
48
48
  "dependencies": {
49
49
  "@types/mousetrap": "^1.6.8",
50
- "@wordpress/deprecated": "^4.40.1-next.v.202602241322.0+bce7cff88",
51
- "@wordpress/dom": "^4.40.1-next.v.202602241322.0+bce7cff88",
52
- "@wordpress/element": "^6.40.1-next.v.202602241322.0+bce7cff88",
53
- "@wordpress/is-shallow-equal": "^5.40.1-next.v.202602241322.0+bce7cff88",
54
- "@wordpress/keycodes": "^4.40.1-next.v.202602241322.0+bce7cff88",
55
- "@wordpress/priority-queue": "^3.40.1-next.v.202602241322.0+bce7cff88",
56
- "@wordpress/undo-manager": "^1.40.1-next.v.202602241322.0+bce7cff88",
50
+ "@wordpress/deprecated": "^4.40.1-next.v.202602271551.0+464abe399",
51
+ "@wordpress/dom": "^4.40.1-next.v.202602271551.0+464abe399",
52
+ "@wordpress/element": "^6.40.1-next.v.202602271551.0+464abe399",
53
+ "@wordpress/is-shallow-equal": "^5.40.1-next.v.202602271551.0+464abe399",
54
+ "@wordpress/keycodes": "^4.40.1-next.v.202602271551.0+464abe399",
55
+ "@wordpress/priority-queue": "^3.40.1-next.v.202602271551.0+464abe399",
56
+ "@wordpress/undo-manager": "^1.40.1-next.v.202602271551.0+464abe399",
57
57
  "change-case": "^4.1.2",
58
58
  "clipboard": "^2.0.11",
59
59
  "mousetrap": "^1.6.5",
@@ -68,5 +68,5 @@
68
68
  "publishConfig": {
69
69
  "access": "public"
70
70
  },
71
- "gitHead": "943dde7f0b600ce238726c36284bc9f70ce0ffa4"
71
+ "gitHead": "95aa7055a5757219e2d96a91efc69f7dd1b2d4c3"
72
72
  }
@@ -13,21 +13,24 @@ import { ESCAPE } from '@wordpress/keycodes';
13
13
  * Internal dependencies
14
14
  */
15
15
  import useConstrainedTabbing from '../use-constrained-tabbing';
16
- import useFocusOnMount from '../use-focus-on-mount';
16
+ import { useFocusOnMount } from '../use-focus-on-mount';
17
17
  import useFocusReturn from '../use-focus-return';
18
18
  import useFocusOutside from '../use-focus-outside';
19
19
  import useMergeRefs from '../use-merge-refs';
20
20
 
21
21
  type DialogOptions = {
22
22
  /**
23
- * Determines whether focus should be automatically moved to the popover
24
- * when it mounts. `false` causes no focus shift, `true` causes the popover
25
- * itself to gain focus, and `firstElement` focuses the first focusable
26
- * element within the popover.
23
+ * Determines focus behavior when the dialog mounts.
24
+ *
25
+ * - `"firstElement"` focuses the first tabbable element within.
26
+ * - `"firstInputElement"` focuses the first value control within.
27
+ * - `true` focuses the element itself.
28
+ * - `false` does nothing and _should not be used unless an accessible
29
+ * substitute behavior is implemented_.
27
30
  *
28
31
  * @default 'firstElement'
29
32
  */
30
- focusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];
33
+ focusOnMount?: useFocusOnMount.Mode;
31
34
  /**
32
35
  * Determines whether tabbing is constrained to within the popover,
33
36
  * preventing keyboard focus from leaving the popover content without
@@ -1,19 +1,15 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { useRef, useEffect } from '@wordpress/element';
5
1
  import { focus } from '@wordpress/dom';
6
-
7
- /**
8
- * Internal dependencies
9
- */
2
+ import { useEffect, useRef } from '@wordpress/element';
10
3
  import useRefEffect from '../use-ref-effect';
11
4
 
12
5
  /**
13
- * Hook used to focus the first tabbable element on mount.
6
+ * Determines focus behavior when the element mounts.
14
7
  *
15
- * @param {boolean | 'firstElement' | 'firstInputElement'} focusOnMount Focus on mount mode.
16
- * @return {React.RefCallback<HTMLElement>} Ref callback.
8
+ * @param focusOnMount Behavioral mode. Defaults to `"firstElement"` which focuses the
9
+ * first tabbable element within; `"firstInputElement"` focuses the
10
+ * first value control within; `true` focuses the element itself;
11
+ * `false` does nothing.
12
+ * @return Ref callback.
17
13
  *
18
14
  * @example
19
15
  * ```js
@@ -30,16 +26,17 @@ import useRefEffect from '../use-ref-effect';
30
26
  * }
31
27
  * ```
32
28
  */
33
- export default function useFocusOnMount( focusOnMount = 'firstElement' ) {
29
+ export function useFocusOnMount(
30
+ focusOnMount: useFocusOnMount.Mode = 'firstElement'
31
+ ) {
34
32
  const focusOnMountRef = useRef( focusOnMount );
35
33
 
36
34
  /**
37
35
  * Sets focus on a DOM element.
38
36
  *
39
- * @param {HTMLElement} target The DOM element to set focus to.
40
- * @return {void}
37
+ * @param target The DOM element to set focus to.
41
38
  */
42
- const setFocus = ( target ) => {
39
+ const setFocus = ( target: HTMLElement ): void => {
43
40
  target.focus( {
44
41
  // When focusing newly mounted dialogs,
45
42
  // the position of the popover is often not right on the first render
@@ -48,15 +45,12 @@ export default function useFocusOnMount( focusOnMount = 'firstElement' ) {
48
45
  } );
49
46
  };
50
47
 
51
- /** @type {React.MutableRefObject<ReturnType<setTimeout> | undefined>} */
52
- const timerIdRef = useRef( undefined );
53
-
54
48
  useEffect( () => {
55
49
  focusOnMountRef.current = focusOnMount;
56
50
  }, [ focusOnMount ] );
57
51
 
58
- return useRefEffect( ( node ) => {
59
- if ( ! node || focusOnMountRef.current === false ) {
52
+ return useRefEffect< HTMLElement >( ( node ) => {
53
+ if ( focusOnMountRef.current === false ) {
60
54
  return;
61
55
  }
62
56
 
@@ -72,19 +66,12 @@ export default function useFocusOnMount( focusOnMount = 'firstElement' ) {
72
66
  return;
73
67
  }
74
68
 
75
- timerIdRef.current = setTimeout( () => {
69
+ const timerId = setTimeout( () => {
76
70
  // For 'firstInputElement' mode, try to find a form input element first
77
71
  if ( focusOnMountRef.current === 'firstInputElement' ) {
78
- /** @type {HTMLElement | null} */
79
- let formInput = null;
80
- if (
81
- typeof window !== 'undefined' &&
82
- node instanceof window.Element
83
- ) {
84
- formInput = node.querySelector(
85
- 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
86
- );
87
- }
72
+ const formInput = node.querySelector< HTMLElement >(
73
+ 'input:not([type="hidden"]):not([disabled]), select:not([disabled]), textarea:not([disabled])'
74
+ );
88
75
 
89
76
  if ( formInput ) {
90
77
  setFocus( formInput );
@@ -100,9 +87,11 @@ export default function useFocusOnMount( focusOnMount = 'firstElement' ) {
100
87
  }, 0 );
101
88
 
102
89
  return () => {
103
- if ( timerIdRef.current ) {
104
- clearTimeout( timerIdRef.current );
105
- }
90
+ clearTimeout( timerId );
106
91
  };
107
92
  }, [] );
108
93
  }
94
+
95
+ export namespace useFocusOnMount {
96
+ export type Mode = boolean | 'firstElement' | 'firstInputElement';
97
+ }
package/src/index.js CHANGED
@@ -27,7 +27,7 @@ export { default as __experimentalUseDialog } from './hooks/use-dialog';
27
27
  export { default as useDisabled } from './hooks/use-disabled';
28
28
  export { default as useEvent } from './hooks/use-event';
29
29
  export { default as __experimentalUseDragging } from './hooks/use-dragging';
30
- export { default as useFocusOnMount } from './hooks/use-focus-on-mount';
30
+ export { useFocusOnMount } from './hooks/use-focus-on-mount';
31
31
  export { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';
32
32
  export { default as useFocusReturn } from './hooks/use-focus-return';
33
33
  export { default as useInstanceId } from './hooks/use-instance-id';