@wordpress/compose 7.45.1-next.v.202605131032.0 → 8.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (79) hide show
  1. package/CHANGELOG.md +13 -0
  2. package/README.md +4 -0
  3. package/build/hooks/use-copy-on-click/index.cjs +1 -1
  4. package/build/hooks/use-copy-on-click/index.cjs.map +2 -2
  5. package/build/hooks/use-copy-to-clipboard/index.cjs +8 -10
  6. package/build/hooks/use-copy-to-clipboard/index.cjs.map +2 -2
  7. package/build/hooks/use-dialog/index.cjs +8 -13
  8. package/build/hooks/use-dialog/index.cjs.map +2 -2
  9. package/build/hooks/use-disabled/index.cjs +2 -2
  10. package/build/hooks/use-disabled/index.cjs.map +2 -2
  11. package/build/hooks/use-focus-return/index.cjs.map +1 -1
  12. package/build/hooks/use-media-query/index.cjs +42 -36
  13. package/build/hooks/use-media-query/index.cjs.map +2 -2
  14. package/build/hooks/use-merge-refs/index.cjs.map +2 -2
  15. package/build/hooks/use-resize-observer/use-resize-observer.cjs.map +2 -2
  16. package/build/index.cjs +3 -0
  17. package/build/index.cjs.map +2 -2
  18. package/build/lock-unlock.cjs +37 -0
  19. package/build/lock-unlock.cjs.map +7 -0
  20. package/build/private-apis.cjs +46 -0
  21. package/build/private-apis.cjs.map +7 -0
  22. package/build/utils/subscribe-delegated-listener/index.cjs +101 -0
  23. package/build/utils/subscribe-delegated-listener/index.cjs.map +7 -0
  24. package/build-module/hooks/use-copy-on-click/index.mjs +2 -2
  25. package/build-module/hooks/use-copy-on-click/index.mjs.map +2 -2
  26. package/build-module/hooks/use-copy-to-clipboard/index.mjs +6 -8
  27. package/build-module/hooks/use-copy-to-clipboard/index.mjs.map +2 -2
  28. package/build-module/hooks/use-dialog/index.mjs +8 -13
  29. package/build-module/hooks/use-dialog/index.mjs.map +2 -2
  30. package/build-module/hooks/use-disabled/index.mjs +2 -2
  31. package/build-module/hooks/use-disabled/index.mjs.map +2 -2
  32. package/build-module/hooks/use-focus-return/index.mjs.map +1 -1
  33. package/build-module/hooks/use-media-query/index.mjs +43 -37
  34. package/build-module/hooks/use-media-query/index.mjs.map +2 -2
  35. package/build-module/hooks/use-merge-refs/index.mjs.map +2 -2
  36. package/build-module/hooks/use-resize-observer/use-resize-observer.mjs.map +2 -2
  37. package/build-module/index.mjs +2 -0
  38. package/build-module/index.mjs.map +2 -2
  39. package/build-module/lock-unlock.mjs +11 -0
  40. package/build-module/lock-unlock.mjs.map +7 -0
  41. package/build-module/private-apis.mjs +11 -0
  42. package/build-module/private-apis.mjs.map +7 -0
  43. package/build-module/utils/subscribe-delegated-listener/index.mjs +80 -0
  44. package/build-module/utils/subscribe-delegated-listener/index.mjs.map +7 -0
  45. package/build-types/higher-order/with-safe-timeout/index.d.ts +1 -3
  46. package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
  47. package/build-types/hooks/use-copy-to-clipboard/index.d.ts +2 -2
  48. package/build-types/hooks/use-copy-to-clipboard/index.d.ts.map +1 -1
  49. package/build-types/hooks/use-dialog/index.d.ts +8 -2
  50. package/build-types/hooks/use-dialog/index.d.ts.map +1 -1
  51. package/build-types/hooks/use-media-query/index.d.ts.map +1 -1
  52. package/build-types/hooks/use-merge-refs/index.d.ts.map +1 -1
  53. package/build-types/index.d.ts +1 -0
  54. package/build-types/index.d.ts.map +1 -1
  55. package/build-types/lock-unlock.d.ts +2 -0
  56. package/build-types/lock-unlock.d.ts.map +1 -0
  57. package/build-types/private-apis.d.ts +5 -0
  58. package/build-types/private-apis.d.ts.map +1 -0
  59. package/build-types/utils/subscribe-delegated-listener/index.d.ts +27 -0
  60. package/build-types/utils/subscribe-delegated-listener/index.d.ts.map +1 -0
  61. package/package.json +11 -10
  62. package/src/hooks/use-copy-on-click/index.ts +2 -2
  63. package/src/hooks/use-copy-to-clipboard/index.ts +8 -8
  64. package/src/hooks/use-copy-to-clipboard/test/index.tsx +33 -5
  65. package/src/hooks/use-dialog/README.md +52 -18
  66. package/src/hooks/use-dialog/index.ts +30 -20
  67. package/src/hooks/use-dialog/test/index.tsx +162 -34
  68. package/src/hooks/use-disabled/index.ts +3 -3
  69. package/src/hooks/use-disabled/test/index.js +4 -4
  70. package/src/hooks/use-focus-outside/index.native.js +2 -2
  71. package/src/hooks/use-focus-return/index.js +2 -2
  72. package/src/hooks/use-media-query/index.ts +54 -52
  73. package/src/hooks/use-merge-refs/index.ts +2 -2
  74. package/src/hooks/use-resize-observer/use-resize-observer.ts +1 -1
  75. package/src/index.js +3 -0
  76. package/src/lock-unlock.ts +10 -0
  77. package/src/private-apis.ts +13 -0
  78. package/src/utils/subscribe-delegated-listener/index.ts +128 -0
  79. package/src/utils/subscribe-delegated-listener/test/index.js +170 -0
@@ -3,6 +3,7 @@ export * from "./utils/create-higher-order-component/index.mjs";
3
3
  export * from "./utils/debounce/index.mjs";
4
4
  export * from "./utils/throttle/index.mjs";
5
5
  export * from "./utils/observable-map/index.mjs";
6
+ import { privateApis } from "./private-apis.mjs";
6
7
  import { default as default2 } from "./higher-order/compose.mjs";
7
8
  import { default as default3 } from "./higher-order/pipe.mjs";
8
9
  import { default as default4 } from "./higher-order/if-condition/index.mjs";
@@ -50,6 +51,7 @@ export {
50
51
  default2 as compose,
51
52
  default4 as ifCondition,
52
53
  default3 as pipe,
54
+ privateApis,
53
55
  default5 as pure,
54
56
  default28 as useAsyncList,
55
57
  default10 as useConstrainedTabbing,
@@ -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 { 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 './hoo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cesContent": ["// 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// Private APIs.\nexport { privateApis } from './private-apis';\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;AAEd,cAAc;AAEd,cAAc;AAEd,cAAc;AAGd,SAAS,mBAAmB;AAG5B,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,SAAS,uBAAuB;AAChC,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;",
6
6
  "names": ["default"]
7
7
  }
@@ -0,0 +1,11 @@
1
+ // packages/compose/src/lock-unlock.ts
2
+ import { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from "@wordpress/private-apis";
3
+ var { lock, unlock } = __dangerousOptInToUnstableAPIsOnlyForCoreModules(
4
+ "I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.",
5
+ "@wordpress/compose"
6
+ );
7
+ export {
8
+ lock,
9
+ unlock
10
+ };
11
+ //# sourceMappingURL=lock-unlock.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/lock-unlock.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { __dangerousOptInToUnstableAPIsOnlyForCoreModules } from '@wordpress/private-apis';\n\nexport const { lock, unlock } =\n\t__dangerousOptInToUnstableAPIsOnlyForCoreModules(\n\t\t'I acknowledge private features are not for use in themes or plugins and doing so will break in the next version of WordPress.',\n\t\t'@wordpress/compose'\n\t);\n"],
5
+ "mappings": ";AAGA,SAAS,wDAAwD;AAE1D,IAAM,EAAE,MAAM,OAAO,IAC3B;AAAA,EACC;AAAA,EACA;AACD;",
6
+ "names": []
7
+ }
@@ -0,0 +1,11 @@
1
+ // packages/compose/src/private-apis.ts
2
+ import { lock } from "./lock-unlock.mjs";
3
+ import subscribeDelegatedListener from "./utils/subscribe-delegated-listener/index.mjs";
4
+ var privateApis = {};
5
+ lock(privateApis, {
6
+ subscribeDelegatedListener
7
+ });
8
+ export {
9
+ privateApis
10
+ };
11
+ //# sourceMappingURL=private-apis.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/private-apis.ts"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport { lock } from './lock-unlock';\nimport subscribeDelegatedListener from './utils/subscribe-delegated-listener';\n\n/**\n * Private @wordpress/compose APIs.\n */\nexport const privateApis = {};\nlock( privateApis, {\n\tsubscribeDelegatedListener,\n} );\n"],
5
+ "mappings": ";AAGA,SAAS,YAAY;AACrB,OAAO,gCAAgC;AAKhC,IAAM,cAAc,CAAC;AAC5B,KAAM,aAAa;AAAA,EAClB;AACD,CAAE;",
6
+ "names": []
7
+ }
@@ -0,0 +1,80 @@
1
+ // packages/compose/src/utils/subscribe-delegated-listener/index.ts
2
+ var registries = /* @__PURE__ */ new WeakMap();
3
+ function subscribeDelegatedListener(target, eventType, callback, capture = false) {
4
+ const ownerDoc = target.ownerDocument;
5
+ const root = ownerDoc ?? target;
6
+ const isWindow = ownerDoc === void 0;
7
+ let perRoot = registries.get(root);
8
+ if (!perRoot) {
9
+ perRoot = /* @__PURE__ */ new Map();
10
+ registries.set(root, perRoot);
11
+ }
12
+ const key = capture ? `${eventType}:capture` : eventType;
13
+ let perEvent = perRoot.get(key);
14
+ if (!perEvent) {
15
+ perEvent = /* @__PURE__ */ new WeakMap();
16
+ perRoot.set(key, perEvent);
17
+ const subscribers = perEvent;
18
+ root.addEventListener(
19
+ eventType,
20
+ (event) => {
21
+ if (isWindow) {
22
+ const set2 = subscribers.get(root);
23
+ if (set2) {
24
+ for (const cb of set2) {
25
+ cb(event);
26
+ }
27
+ }
28
+ return;
29
+ }
30
+ if (capture) {
31
+ const path = [];
32
+ let current = event.target;
33
+ while (current) {
34
+ path.push(current);
35
+ if (current === root) {
36
+ break;
37
+ }
38
+ current = current.parentNode;
39
+ }
40
+ for (let i = path.length - 1; i >= 0; i--) {
41
+ const set2 = subscribers.get(path[i]);
42
+ if (set2) {
43
+ for (const cb of set2) {
44
+ cb(event);
45
+ }
46
+ }
47
+ }
48
+ } else {
49
+ let current = event.target;
50
+ while (current) {
51
+ const set2 = subscribers.get(current);
52
+ if (set2) {
53
+ for (const cb of set2) {
54
+ cb(event);
55
+ }
56
+ }
57
+ if (current === root) {
58
+ break;
59
+ }
60
+ current = current.parentNode;
61
+ }
62
+ }
63
+ },
64
+ capture
65
+ );
66
+ }
67
+ let set = perEvent.get(target);
68
+ if (!set) {
69
+ set = /* @__PURE__ */ new Set();
70
+ perEvent.set(target, set);
71
+ }
72
+ set.add(callback);
73
+ return () => {
74
+ set.delete(callback);
75
+ };
76
+ }
77
+ export {
78
+ subscribeDelegatedListener as default
79
+ };
80
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/utils/subscribe-delegated-listener/index.ts"],
4
+ "sourcesContent": ["/**\n * Adds a callback to a shared `addEventListener`. Only one underlying\n * native listener is attached per (root, event type, phase); subscribers\n * join an in-JS registry that dispatches events along the DOM ancestry\n * of `event.target`.\n *\n * The model mirrors React's synthetic event system: a single root\n * listener handles every event of a given type, and callbacks bound to\n * an `Element` only fire when that element is on the target's path.\n * Callbacks bound to a `Document` always fire (document is the root of\n * every event in that document); callbacks bound to a `Window` always\n * fire as a flat fan-out, since `window` isn't on the DOM tree.\n *\n * @param target `Element`, `Document`, or `Window` to bind the\n * callback to. For `Element`, the callback only fires\n * when the event happens on the element or a\n * descendant.\n * @param eventType DOM event name.\n * @param callback Listener to be invoked with the event.\n * @param capture Use the capture phase. Required when ancestor\n * listeners gate on `event.defaultPrevented`, since a\n * bubble-phase root listener fires after them. Defaults\n * to `false`.\n * @return Unsubscribe function.\n */\n// root -> eventTypeKey -> subscribedTarget -> Set<callback>\n//\n// Inner registry is a `WeakMap`: element subscribers are held weakly so\n// an iframe removal lets the iframe's Elements (and through them, its\n// `ownerDocument`) be garbage-collected. The native listener is\n// attached to the document itself, so it goes when the document goes.\nconst registries = new WeakMap<\n\tEventTarget,\n\tMap< string, WeakMap< EventTarget, Set< EventListener > > >\n>();\n\nexport default function subscribeDelegatedListener(\n\ttarget: EventTarget,\n\teventType: string,\n\tcallback: EventListener,\n\tcapture: boolean = false\n): () => void {\n\t// Where the native listener is attached:\n\t// Element \u2192 its `ownerDocument`\n\t// Document \u2192 itself (own `ownerDocument` is `null`)\n\t// Window \u2192 itself (no `ownerDocument` property)\n\t// `undefined` (Window) \u2192 use a fan-out branch on dispatch since\n\t// events bubble *to* window but never *from* it via `parentNode`.\n\tconst ownerDoc = ( target as Node ).ownerDocument;\n\tconst root = ownerDoc ?? target;\n\tconst isWindow = ownerDoc === undefined;\n\n\tlet perRoot = registries.get( root );\n\tif ( ! perRoot ) {\n\t\tperRoot = new Map();\n\t\tregistries.set( root, perRoot );\n\t}\n\tconst key = capture ? `${ eventType }:capture` : eventType;\n\tlet perEvent = perRoot.get( key );\n\tif ( ! perEvent ) {\n\t\tperEvent = new WeakMap< EventTarget, Set< EventListener > >();\n\t\tperRoot.set( key, perEvent );\n\t\tconst subscribers = perEvent;\n\t\troot.addEventListener(\n\t\t\teventType,\n\t\t\t( event ) => {\n\t\t\t\tif ( isWindow ) {\n\t\t\t\t\t// Window has no DOM ancestry \u2014 all subscribers share\n\t\t\t\t\t// the window key; fetch its set and fan out.\n\t\t\t\t\tconst set = subscribers.get( root );\n\t\t\t\t\tif ( set ) {\n\t\t\t\t\t\tfor ( const cb of set ) {\n\t\t\t\t\t\t\tcb( event );\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\treturn;\n\t\t\t\t}\n\t\t\t\t// Walk the target \u2192 root ancestry, dispatching callbacks\n\t\t\t\t// for any node in the path. Bubble order matches the walk\n\t\t\t\t// direction, so dispatch inline (no path array). Capture\n\t\t\t\t// has to materialise the path to iterate in reverse.\n\t\t\t\tif ( capture ) {\n\t\t\t\t\tconst path: Array< Node | Document > = [];\n\t\t\t\t\tlet current: Node | null = event.target as Node | null;\n\t\t\t\t\twhile ( current ) {\n\t\t\t\t\t\tpath.push( current );\n\t\t\t\t\t\tif ( current === root ) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrent = current.parentNode;\n\t\t\t\t\t}\n\t\t\t\t\tfor ( let i = path.length - 1; i >= 0; i-- ) {\n\t\t\t\t\t\tconst set = subscribers.get( path[ i ] );\n\t\t\t\t\t\tif ( set ) {\n\t\t\t\t\t\t\tfor ( const cb of set ) {\n\t\t\t\t\t\t\t\tcb( event );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\tlet current: Node | null = event.target as Node | null;\n\t\t\t\t\twhile ( current ) {\n\t\t\t\t\t\tconst set = subscribers.get( current );\n\t\t\t\t\t\tif ( set ) {\n\t\t\t\t\t\t\tfor ( const cb of set ) {\n\t\t\t\t\t\t\t\tcb( event );\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t}\n\t\t\t\t\t\tif ( current === root ) {\n\t\t\t\t\t\t\tbreak;\n\t\t\t\t\t\t}\n\t\t\t\t\t\tcurrent = current.parentNode;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t},\n\t\t\tcapture\n\t\t);\n\t}\n\tlet set = perEvent.get( target );\n\tif ( ! set ) {\n\t\tset = new Set();\n\t\tperEvent.set( target, set );\n\t}\n\tset.add( callback );\n\treturn () => {\n\t\tset.delete( callback );\n\t};\n}\n"],
5
+ "mappings": ";AA+BA,IAAM,aAAa,oBAAI,QAGrB;AAEa,SAAR,2BACN,QACA,WACA,UACA,UAAmB,OACN;AAOb,QAAM,WAAa,OAAiB;AACpC,QAAM,OAAO,YAAY;AACzB,QAAM,WAAW,aAAa;AAE9B,MAAI,UAAU,WAAW,IAAK,IAAK;AACnC,MAAK,CAAE,SAAU;AAChB,cAAU,oBAAI,IAAI;AAClB,eAAW,I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GAAI;AAAA,EAC3B;AACA,MAAI,IAAK,QAAS;AAClB,SAAO,MAAM;AACZ,QAAI,OAAQ,QAAS;AAAA,EACtB;AACD;",
6
+ "names": ["set"]
7
+ }
@@ -30,9 +30,6 @@ declare const withSafeTimeout: <C extends WithInjectedProps<C, TimeoutProps>>(In
30
30
  forceUpdate(callback?: (() => void) | undefined): void;
31
31
  readonly props: Readonly<WithoutInjectedProps<C, TimeoutProps>>;
32
32
  state: Readonly<{}>;
33
- refs: {
34
- [key: string]: import("react").ReactInstance;
35
- };
36
33
  componentDidMount?(): void;
37
34
  shouldComponentUpdate?(nextProps: Readonly<WithoutInjectedProps<C, TimeoutProps>>, nextState: Readonly<{}>, nextContext: any): boolean;
38
35
  componentDidCatch?(error: Error, errorInfo: import("react").ErrorInfo): void;
@@ -46,6 +43,7 @@ declare const withSafeTimeout: <C extends WithInjectedProps<C, TimeoutProps>>(In
46
43
  UNSAFE_componentWillUpdate?(nextProps: Readonly<WithoutInjectedProps<C, TimeoutProps>>, nextState: Readonly<{}>, nextContext: any): void;
47
44
  };
48
45
  contextType?: import("react").Context<any> | undefined;
46
+ propTypes?: any;
49
47
  };
50
48
  export default withSafeTimeout;
51
49
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-safe-timeout/index.tsx"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,2CAA2C,CAAC;AAGnD;;;;;;;GAOG;AACH,UAAU,YAAY;IACrB,UAAU,EAAE,CAAE,EAAE,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,KAAM,MAAM,CAAC;IACxD,YAAY,EAAE,CAAE,EAAE,EAAE,MAAM,KAAM,IAAI,CAAC;CACrC;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe,GAClB,CAAC,SAAS,iBAAiB,CAAE,CAAC,EAAE,YAAY,CAAE;;kBAKpC,MAAM,EAAE;;uBAaF,MAAM,IAAI,SAAS,MAAM;yBASvB,MAAM;;;;;;;;;;;;;;;;;;;;;;;CAoB1B,CAAC;eAEa,eAAe"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/higher-order/with-safe-timeout/index.tsx"],"names":[],"mappings":"AAKA;;GAEG;AACH,OAAO,KAAK,EACX,iBAAiB,EACjB,oBAAoB,EACpB,MAAM,2CAA2C,CAAC;AAGnD;;;;;;;GAOG;AACH,UAAU,YAAY;IACrB,UAAU,EAAE,CAAE,EAAE,EAAE,MAAM,IAAI,EAAE,KAAK,EAAE,MAAM,KAAM,MAAM,CAAC;IACxD,YAAY,EAAE,CAAE,EAAE,EAAE,MAAM,KAAM,IAAI,CAAC;CACrC;AAED;;;GAGG;AACH,QAAA,MAAM,eAAe,GAClB,CAAC,SAAS,iBAAiB,CAAE,CAAC,EAAE,YAAY,CAAE;;kBAKpC,MAAM,EAAE;;uBAaF,MAAM,IAAI,SAAS,MAAM;yBASvB,MAAM;;;;;;;;;;;;;;;;;;;;;CAoB1B,CAAC;eAEa,eAAe"}
@@ -9,11 +9,11 @@ import type { RefCallback } from 'react';
9
9
  */
10
10
  export declare function copyToClipboard(text: string, trigger: Element | null): Promise<boolean>;
11
11
  /**
12
- * Clears the current selection and restores focus to the trigger element.
12
+ * Restores focus to the trigger element.
13
13
  *
14
14
  * @param trigger The element that triggered the copy.
15
15
  */
16
- export declare function clearSelection(trigger: Element): void;
16
+ export declare function restoreFocus(trigger: Element): void;
17
17
  /**
18
18
  * Copies the given text to the clipboard when the element is clicked.
19
19
  *
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-copy-to-clipboard/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,WAAW,EAAE,MAAM,OAAO,CAAC;AAO3D;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GAAG,IAAI,GACrB,OAAO,CAAE,OAAO,CAAE,CA6BpB;AAED;;;;GAIG;AACH,wBAAgB,cAAc,CAAE,OAAO,EAAE,OAAO,GAAI,IAAI,CAKvD;AAeD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAE,CAAC,SAAS,WAAW,EAChE,IAAI,EAAE,MAAM,GAAG,CAAE,MAAM,MAAM,CAAE,EAC/B,SAAS,CAAC,EAAE,MAAM,IAAI,GACpB,WAAW,CAAE,CAAC,CAAE,CA4BlB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-copy-to-clipboard/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,WAAW,EAAE,MAAM,OAAO,CAAC;AAO3D;;;;;;;GAOG;AACH,wBAAsB,eAAe,CACpC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,OAAO,GAAG,IAAI,GACrB,OAAO,CAAE,OAAO,CAAE,CA6BpB;AAED;;;;GAIG;AACH,wBAAgB,YAAY,CAAE,OAAO,EAAE,OAAO,GAAI,IAAI,CAIrD;AAeD;;;;;;;;;GASG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CAAE,CAAC,SAAS,WAAW,EAChE,IAAI,EAAE,MAAM,GAAG,CAAE,MAAM,MAAM,CAAE,EAC/B,SAAS,CAAC,EAAE,MAAM,IAAI,GACpB,WAAW,CAAE,CAAC,CAAE,CA6BlB"}
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import type { RefCallback, SyntheticEvent } from 'react';
4
+ import type { KeyboardEvent, KeyboardEventHandler, RefCallback, SyntheticEvent } from 'react';
5
5
  import { useFocusOnMount } from '../use-focus-on-mount';
6
6
  import useFocusOutside from '../use-focus-outside';
7
7
  type DialogOptions = {
@@ -29,6 +29,10 @@ type DialogOptions = {
29
29
  */
30
30
  constrainTabbing?: boolean;
31
31
  onClose?: () => void;
32
+ /**
33
+ * Optional `onKeyDown` handler, merged with the built-in one.
34
+ */
35
+ onKeyDown?: KeyboardEventHandler<HTMLElement>;
32
36
  /**
33
37
  * Use the `onClose` prop instead.
34
38
  *
@@ -38,7 +42,9 @@ type DialogOptions = {
38
42
  };
39
43
  type useDialogReturn = [
40
44
  RefCallback<HTMLElement>,
41
- ReturnType<typeof useFocusOutside> & Pick<HTMLElement, 'tabIndex'>
45
+ ReturnType<typeof useFocusOutside> & {
46
+ onKeyDown: (event: KeyboardEvent<HTMLElement>) => void;
47
+ } & Pick<HTMLElement, 'tabIndex'>
42
48
  ];
43
49
  /**
44
50
  * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:
@@ -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,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,CAiD5D;eAEc,SAAS"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-dialog/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,KAAK,EACX,aAAa,EACb,oBAAoB,EACpB,WAAW,EACX,cAAc,EACd,MAAM,OAAO,CAAC;AAWf,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;;OAEG;IACH,SAAS,CAAC,EAAE,oBAAoB,CAAE,WAAW,CAAE,CAAC;IAChD;;;;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;QACtC,SAAS,EAAE,CAAE,KAAK,EAAE,aAAa,CAAE,WAAW,CAAE,KAAM,IAAI,CAAC;KAC3D,GAAG,IAAI,CAAE,WAAW,EAAE,UAAU,CAAE;CACnC,CAAC;AAEF;;;;;;;;GAQG;AACH,iBAAS,SAAS,CAAE,OAAO,EAAE,aAAa,GAAI,eAAe,CAiD5D;eAEc,SAAS"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-media-query/index.ts"],"names":[],"mappings":"AA4CA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACpC,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,GAAE,MAAe,GACnB,OAAO,CA8BT"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-media-query/index.ts"],"names":[],"mappings":"AAoEA;;;;;;GAMG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CACpC,KAAK,CAAC,EAAE,MAAM,EACd,IAAI,GAAE,MAAe,GACnB,OAAO,CAQT"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-merge-refs/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAoB,GAAG,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAUhE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAE,CAAC,EACtC,IAAI,EAAE,GAAG,CAAE,CAAC,CAAE,EAAE,GACd,WAAW,CAAE,CAAC,CAAE,CA0DlB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-merge-refs/index.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,GAAG,EAAE,WAAW,EAAE,MAAM,OAAO,CAAC;AAU9C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAE,CAAC,EACtC,IAAI,EAAE,GAAG,CAAE,CAAC,CAAE,EAAE,GACd,WAAW,CAAE,CAAC,CAAE,CA0DlB"}
@@ -2,6 +2,7 @@ export * from './utils/create-higher-order-component';
2
2
  export * from './utils/debounce';
3
3
  export * from './utils/throttle';
4
4
  export * from './utils/observable-map';
5
+ export { privateApis } from './private-apis';
5
6
  export { default as compose } from './higher-order/compose';
6
7
  export { default as pipe } from './higher-order/pipe';
7
8
  export { default as ifCondition } from './higher-order/if-condition';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AAC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AC;AACjE,OAAO,EAAE,OAAO,IAAI,yBAAyB,EAAE,MAAM,uBAAuB,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,8BAA8B,CAAC;AAC7E,OAAO,EAAE,OAAO,IAAI,gCAAgC,EAAE,MAAM,+BAA+B,CAAC;AAC5F,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,2 @@
1
+ export declare const lock: (object: unknown, privateData: unknown) => void, unlock: <T = any>(object: unknown) => T;
2
+ //# sourceMappingURL=lock-unlock.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"lock-unlock.d.ts","sourceRoot":"","sources":["../src/lock-unlock.ts"],"names":[],"mappings":"AAKA,eAAO,MAAQ,IAAI,mDAAE,MAAM,iCAIzB,CAAC"}
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Private @wordpress/compose APIs.
3
+ */
4
+ export declare const privateApis: {};
5
+ //# sourceMappingURL=private-apis.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"private-apis.d.ts","sourceRoot":"","sources":["../src/private-apis.ts"],"names":[],"mappings":"AAMA;;GAEG;AACH,eAAO,MAAM,WAAW,IAAK,CAAC"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Adds a callback to a shared `addEventListener`. Only one underlying
3
+ * native listener is attached per (root, event type, phase); subscribers
4
+ * join an in-JS registry that dispatches events along the DOM ancestry
5
+ * of `event.target`.
6
+ *
7
+ * The model mirrors React's synthetic event system: a single root
8
+ * listener handles every event of a given type, and callbacks bound to
9
+ * an `Element` only fire when that element is on the target's path.
10
+ * Callbacks bound to a `Document` always fire (document is the root of
11
+ * every event in that document); callbacks bound to a `Window` always
12
+ * fire as a flat fan-out, since `window` isn't on the DOM tree.
13
+ *
14
+ * @param target `Element`, `Document`, or `Window` to bind the
15
+ * callback to. For `Element`, the callback only fires
16
+ * when the event happens on the element or a
17
+ * descendant.
18
+ * @param eventType DOM event name.
19
+ * @param callback Listener to be invoked with the event.
20
+ * @param capture Use the capture phase. Required when ancestor
21
+ * listeners gate on `event.defaultPrevented`, since a
22
+ * bubble-phase root listener fires after them. Defaults
23
+ * to `false`.
24
+ * @return Unsubscribe function.
25
+ */
26
+ export default function subscribeDelegatedListener(target: EventTarget, eventType: string, callback: EventListener, capture?: boolean): () => void;
27
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/subscribe-delegated-listener/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAYH,MAAM,CAAC,OAAO,UAAU,0BAA0B,CACjD,MAAM,EAAE,WAAW,EACnB,SAAS,EAAE,MAAM,EACjB,QAAQ,EAAE,aAAa,EACvB,OAAO,GAAE,OAAe,GACtB,MAAM,IAAI,CAsFZ"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/compose",
3
- "version": "7.45.1-next.v.202605131032.0+f6d6e7149",
3
+ "version": "8.0.0",
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,14 @@
47
47
  "sideEffects": false,
48
48
  "dependencies": {
49
49
  "@types/mousetrap": "^1.6.8",
50
- "@wordpress/deprecated": "^4.45.1-next.v.202605131032.0+f6d6e7149",
51
- "@wordpress/dom": "^4.45.1-next.v.202605131032.0+f6d6e7149",
52
- "@wordpress/element": "^6.45.1-next.v.202605131032.0+f6d6e7149",
53
- "@wordpress/is-shallow-equal": "^5.45.1-next.v.202605131032.0+f6d6e7149",
54
- "@wordpress/keycodes": "^4.45.1-next.v.202605131032.0+f6d6e7149",
55
- "@wordpress/priority-queue": "^3.45.1-next.v.202605131032.0+f6d6e7149",
56
- "@wordpress/undo-manager": "^1.45.1-next.v.202605131032.0+f6d6e7149",
50
+ "@wordpress/deprecated": "^4.47.0",
51
+ "@wordpress/dom": "^4.47.0",
52
+ "@wordpress/element": "^7.0.0",
53
+ "@wordpress/is-shallow-equal": "^5.47.0",
54
+ "@wordpress/keycodes": "^4.47.0",
55
+ "@wordpress/priority-queue": "^3.47.0",
56
+ "@wordpress/private-apis": "^1.47.0",
57
+ "@wordpress/undo-manager": "^1.47.0",
57
58
  "change-case": "^4.1.2",
58
59
  "mousetrap": "^1.6.5",
59
60
  "use-memo-one": "^1.1.1"
@@ -62,10 +63,10 @@
62
63
  "mock-match-media": "0.4.2"
63
64
  },
64
65
  "peerDependencies": {
65
- "react": "^18.0.0"
66
+ "react": "^19.2.4"
66
67
  },
67
68
  "publishConfig": {
68
69
  "access": "public"
69
70
  },
70
- "gitHead": "0e198c7ac7ca634e73ded9220ce048c0302174dd"
71
+ "gitHead": "d653c5fd6161571a0c2ebde28553d6e25624eacc"
71
72
  }
@@ -8,7 +8,7 @@ import type { RefObject } from 'react';
8
8
  /**
9
9
  * Internal dependencies
10
10
  */
11
- import { clearSelection, copyToClipboard } from '../use-copy-to-clipboard';
11
+ import { restoreFocus, copyToClipboard } from '../use-copy-to-clipboard';
12
12
 
13
13
  /**
14
14
  * Copies the text to the clipboard when the element is clicked.
@@ -73,7 +73,7 @@ export default function useCopyOnClick(
73
73
  return;
74
74
  }
75
75
  if ( success ) {
76
- clearSelection( trigger );
76
+ restoreFocus( trigger );
77
77
  if ( timeout ) {
78
78
  setHasCopied( true );
79
79
  clearTimeout( timeoutId );
@@ -52,15 +52,14 @@ export async function copyToClipboard(
52
52
  }
53
53
 
54
54
  /**
55
- * Clears the current selection and restores focus to the trigger element.
55
+ * Restores focus to the trigger element.
56
56
  *
57
57
  * @param trigger The element that triggered the copy.
58
58
  */
59
- export function clearSelection( trigger: Element ): void {
59
+ export function restoreFocus( trigger: Element ): void {
60
60
  if ( 'focus' in trigger && typeof trigger.focus === 'function' ) {
61
61
  trigger.focus();
62
62
  }
63
- trigger.ownerDocument?.defaultView?.getSelection()?.removeAllRanges();
64
63
  }
65
64
 
66
65
  /**
@@ -93,7 +92,7 @@ export default function useCopyToClipboard< T extends HTMLElement >(
93
92
  const textRef = useUpdatedRef( text );
94
93
  const onSuccessRef = useUpdatedRef( onSuccess );
95
94
  return useRefEffect( ( node ) => {
96
- // Flag to prevent callbacks after unmount when the Promise resolves.
95
+ // Tracks whether the node is still mounted when the Promise resolves.
97
96
  let isActive = true;
98
97
  const handleClick = async () => {
99
98
  const textToCopy =
@@ -101,11 +100,12 @@ export default function useCopyToClipboard< T extends HTMLElement >(
101
100
  ? textRef.current()
102
101
  : textRef.current || '';
103
102
  const success = await copyToClipboard( textToCopy, node );
104
- if ( ! isActive ) {
105
- return;
106
- }
107
103
  if ( success ) {
108
- clearSelection( node );
104
+ // Restoring focus only matters while the node is mounted.
105
+ if ( isActive ) {
106
+ restoreFocus( node );
107
+ }
108
+ // Always run, even after unmount, to allow updating other UI.
109
109
  if ( onSuccessRef.current ) {
110
110
  onSuccessRef.current();
111
111
  }
@@ -7,7 +7,7 @@ import userEvent from '@testing-library/user-event';
7
7
  /**
8
8
  * Internal dependencies
9
9
  */
10
- import useCopyToClipboard, { copyToClipboard, clearSelection } from '../';
10
+ import useCopyToClipboard, { copyToClipboard, restoreFocus } from '../';
11
11
 
12
12
  interface TestComponentProps {
13
13
  text: string | ( () => string );
@@ -68,7 +68,7 @@ describe( 'useCopyToClipboard', () => {
68
68
  expect( onSuccess ).not.toHaveBeenCalled();
69
69
  } );
70
70
 
71
- it( 'should not call onSuccess after unmount', async () => {
71
+ it( 'should call onSuccess after the node unmounts', async () => {
72
72
  let resolvePromise: () => void;
73
73
  const delayedPromise = new Promise< void >( ( resolve ) => {
74
74
  resolvePromise = resolve;
@@ -91,7 +91,35 @@ describe( 'useCopyToClipboard', () => {
91
91
  await new Promise( ( resolve ) => setTimeout( resolve, 0 ) );
92
92
  } );
93
93
 
94
- expect( onSuccess ).not.toHaveBeenCalled();
94
+ expect( onSuccess ).toHaveBeenCalledTimes( 1 );
95
+ } );
96
+
97
+ it( 'should not restore focus after the node unmounts', async () => {
98
+ let resolvePromise: () => void;
99
+ const delayedPromise = new Promise< void >( ( resolve ) => {
100
+ resolvePromise = resolve;
101
+ } );
102
+ jest.spyOn( navigator.clipboard, 'writeText' ).mockReturnValue(
103
+ delayedPromise
104
+ );
105
+
106
+ const user = userEvent.setup();
107
+ const { unmount } = render( <TestComponent text="test" /> );
108
+
109
+ const button = screen.getByRole( 'button' );
110
+ const focusSpy = jest.spyOn( button, 'focus' );
111
+
112
+ await user.click( button );
113
+ unmount();
114
+ // Discard focus calls from the initial click; we only care about post-unmount calls.
115
+ focusSpy.mockClear();
116
+
117
+ await act( async () => {
118
+ resolvePromise();
119
+ await new Promise( ( resolve ) => setTimeout( resolve, 0 ) );
120
+ } );
121
+
122
+ expect( focusSpy ).not.toHaveBeenCalled();
95
123
  } );
96
124
  } );
97
125
 
@@ -129,13 +157,13 @@ describe( 'copyToClipboard', () => {
129
157
  } );
130
158
  } );
131
159
 
132
- describe( 'clearSelection', () => {
160
+ describe( 'restoreFocus', () => {
133
161
  it( 'should focus the trigger element', () => {
134
162
  const trigger = document.createElement( 'button' );
135
163
  document.body.appendChild( trigger );
136
164
  const focusMock = jest.spyOn( trigger, 'focus' );
137
165
 
138
- clearSelection( trigger );
166
+ restoreFocus( trigger );
139
167
 
140
168
  expect( focusMock ).toHaveBeenCalledTimes( 1 );
141
169
 
@@ -6,22 +6,7 @@ React hook to be used on a dialog wrapper to enable the following behaviors:
6
6
  - focus on mount.
7
7
  - return focus on unmount.
8
8
  - focus outside.
9
-
10
- ## Returned value
11
-
12
- The hooks returns an array composed of the two following values:
13
-
14
- ### `ref`
15
-
16
- - Type: `Object|Function`
17
-
18
- A React ref that must be passed to the DOM element where the behavior should be attached.
19
-
20
- ### `props`
21
-
22
- - Type: `Object`
23
-
24
- Extra props to apply to the wrapper.
9
+ - close on Escape.
25
10
 
26
11
  ## Usage
27
12
 
@@ -29,15 +14,64 @@ Extra props to apply to the wrapper.
29
14
  import { __experimentalUseDialog as useDialog } from '@wordpress/compose';
30
15
 
31
16
  const MyDialog = () => {
32
- const [ ref, extraProps ] = useDialog( {
17
+ const [ ref, dialogProps ] = useDialog( {
33
18
  onClose: () => console.log( 'do something to close the dialog' ),
34
19
  } );
35
20
 
36
21
  return (
37
- <div ref={ ref } { ...extraProps }>
22
+ <div ref={ ref } { ...dialogProps }>
38
23
  <Button />
39
24
  <Button />
40
25
  </div>
41
26
  );
42
27
  };
43
28
  ```
29
+
30
+ ## Options
31
+
32
+ ### `focusOnMount`
33
+
34
+ - Type: `'firstElement' | 'firstInputElement' | boolean`
35
+ - Default: `'firstElement'`
36
+
37
+ Determines focus behavior when the dialog mounts:
38
+
39
+ - `'firstElement'` focuses the first tabbable element within the dialog.
40
+ - `'firstInputElement'` focuses the first value control within the dialog.
41
+ - `true` focuses the dialog wrapper itself.
42
+ - `false` does nothing, and _should not be used unless an accessible substitute behavior is implemented_.
43
+
44
+ ### `constrainTabbing`
45
+
46
+ - Type: `boolean`
47
+ - Default: `focusOnMount !== false`
48
+
49
+ Whether tabbing is constrained within the dialog (preventing keyboard focus from leaving without explicit focus elsewhere), or whether the dialog remains part of the wider tab order.
50
+
51
+ ### `onClose`
52
+
53
+ - Type: `() => void`
54
+
55
+ Called when the dialog should close, e.g. when the user presses Escape or focus moves outside.
56
+
57
+ ### `onKeyDown`
58
+
59
+ - Type: `KeyboardEventHandler<HTMLElement>`
60
+
61
+ Optional `onKeyDown` handler, merged with the built-in close-on-Escape handler. Provided to keep things working when the dialog wrapper already has its own `onKeyDown`. The provided handler runs first and can call `event.preventDefault()` to opt out of close-on-Escape.
62
+
63
+ ## Returned value
64
+
65
+ A tuple of:
66
+
67
+ ### `ref`
68
+
69
+ - Type: `RefCallback<HTMLElement>`
70
+
71
+ A React ref to attach to the dialog wrapper DOM element.
72
+
73
+ ### `dialogProps`
74
+
75
+ - Type: `object`
76
+
77
+ Extra props (`onFocus`, `onBlur`, `onKeyDown`, `tabIndex`, …) to spread onto the same wrapper element.