@wordpress/compose 7.40.1-next.v.202602241322.0 → 7.40.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. package/CHANGELOG.md +4 -0
  2. package/README.md +8 -6
  3. package/build/hooks/use-copy-on-click/index.cjs +43 -18
  4. package/build/hooks/use-copy-on-click/index.cjs.map +4 -4
  5. package/build/hooks/use-copy-to-clipboard/index.cjs +58 -12
  6. package/build/hooks/use-copy-to-clipboard/index.cjs.map +4 -4
  7. package/build/hooks/use-media-query/index.cjs +12 -9
  8. package/build/hooks/use-media-query/index.cjs.map +3 -3
  9. package/build/hooks/use-viewport-match/index.cjs +2 -2
  10. package/build/hooks/use-viewport-match/index.cjs.map +2 -2
  11. package/build-module/hooks/use-copy-on-click/index.mjs +44 -19
  12. package/build-module/hooks/use-copy-on-click/index.mjs.map +3 -3
  13. package/build-module/hooks/use-copy-to-clipboard/index.mjs +53 -12
  14. package/build-module/hooks/use-copy-to-clipboard/index.mjs.map +3 -3
  15. package/build-module/hooks/use-media-query/index.mjs +12 -9
  16. package/build-module/hooks/use-media-query/index.mjs.map +3 -3
  17. package/build-module/hooks/use-viewport-match/index.mjs +2 -2
  18. package/build-module/hooks/use-viewport-match/index.mjs.map +2 -2
  19. package/build-types/hooks/use-copy-on-click/index.d.ts +8 -9
  20. package/build-types/hooks/use-copy-on-click/index.d.ts.map +1 -1
  21. package/build-types/hooks/use-copy-to-clipboard/index.d.ts +22 -6
  22. package/build-types/hooks/use-copy-to-clipboard/index.d.ts.map +1 -1
  23. package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts +2 -2
  24. package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
  25. package/build-types/hooks/use-media-query/index.d.ts +4 -3
  26. package/build-types/hooks/use-media-query/index.d.ts.map +1 -1
  27. package/build-types/hooks/use-viewport-match/index.d.ts +2 -1
  28. package/build-types/hooks/use-viewport-match/index.d.ts.map +1 -1
  29. package/build-types/lock-unlock.d.ts +2 -0
  30. package/build-types/lock-unlock.d.ts.map +1 -0
  31. package/build-types/private-apis.d.ts +5 -0
  32. package/build-types/private-apis.d.ts.map +1 -0
  33. package/build-types/utils/subscribe-delegated-listener/index.d.ts +27 -0
  34. package/build-types/utils/subscribe-delegated-listener/index.d.ts.map +1 -0
  35. package/package.json +9 -10
  36. package/src/hooks/use-copy-on-click/index.ts +101 -0
  37. package/src/hooks/use-copy-on-click/test/index.tsx +162 -0
  38. package/src/hooks/use-copy-to-clipboard/index.ts +120 -0
  39. package/src/hooks/use-copy-to-clipboard/test/index.tsx +144 -0
  40. package/src/hooks/use-media-query/{index.js → index.ts} +27 -16
  41. package/src/hooks/use-viewport-match/index.js +3 -2
  42. package/src/hooks/use-viewport-match/test/index.js +32 -10
  43. package/src/hooks/use-copy-on-click/index.js +0 -75
  44. package/src/hooks/use-copy-to-clipboard/index.js +0 -69
@@ -1,7 +1,41 @@
1
- // packages/compose/src/hooks/use-copy-to-clipboard/index.js
2
- import Clipboard from "clipboard";
1
+ // packages/compose/src/hooks/use-copy-to-clipboard/index.ts
3
2
  import { useRef, useLayoutEffect } from "@wordpress/element";
4
3
  import useRefEffect from "../use-ref-effect/index.mjs";
4
+ async function copyToClipboard(text, trigger) {
5
+ if (!trigger) {
6
+ return false;
7
+ }
8
+ const { ownerDocument } = trigger;
9
+ if (!ownerDocument) {
10
+ return false;
11
+ }
12
+ const { defaultView } = ownerDocument;
13
+ try {
14
+ if (defaultView?.navigator?.clipboard?.writeText) {
15
+ await defaultView.navigator.clipboard.writeText(text);
16
+ return true;
17
+ }
18
+ const textarea = ownerDocument.createElement("textarea");
19
+ textarea.value = text;
20
+ textarea.setAttribute("readonly", "");
21
+ textarea.style.position = "fixed";
22
+ textarea.style.left = "-9999px";
23
+ textarea.style.top = "-9999px";
24
+ ownerDocument.body.appendChild(textarea);
25
+ textarea.select();
26
+ const success = ownerDocument.execCommand("copy");
27
+ textarea.remove();
28
+ return success;
29
+ } catch {
30
+ return false;
31
+ }
32
+ }
33
+ function clearSelection(trigger) {
34
+ if ("focus" in trigger && typeof trigger.focus === "function") {
35
+ trigger.focus();
36
+ }
37
+ trigger.ownerDocument?.defaultView?.getSelection()?.removeAllRanges();
38
+ }
5
39
  function useUpdatedRef(value) {
6
40
  const ref = useRef(value);
7
41
  useLayoutEffect(() => {
@@ -13,23 +47,30 @@ function useCopyToClipboard(text, onSuccess) {
13
47
  const textRef = useUpdatedRef(text);
14
48
  const onSuccessRef = useUpdatedRef(onSuccess);
15
49
  return useRefEffect((node) => {
16
- const clipboard = new Clipboard(node, {
17
- text() {
18
- return typeof textRef.current === "function" ? textRef.current() : textRef.current || "";
50
+ let isActive = true;
51
+ const handleClick = async () => {
52
+ const textToCopy = typeof textRef.current === "function" ? textRef.current() : textRef.current || "";
53
+ const success = await copyToClipboard(textToCopy, node);
54
+ if (!isActive) {
55
+ return;
19
56
  }
20
- });
21
- clipboard.on("success", ({ clearSelection }) => {
22
- clearSelection();
23
- if (onSuccessRef.current) {
24
- onSuccessRef.current();
57
+ if (success) {
58
+ clearSelection(node);
59
+ if (onSuccessRef.current) {
60
+ onSuccessRef.current();
61
+ }
25
62
  }
26
- });
63
+ };
64
+ node.addEventListener("click", handleClick);
27
65
  return () => {
28
- clipboard.destroy();
66
+ isActive = false;
67
+ node.removeEventListener("click", handleClick);
29
68
  };
30
69
  }, []);
31
70
  }
32
71
  export {
72
+ clearSelection,
73
+ copyToClipboard,
33
74
  useCopyToClipboard as default
34
75
  };
35
76
  //# sourceMappingURL=index.mjs.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/hooks/use-copy-to-clipboard/index.js"],
4
- "sourcesContent": ["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useLayoutEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * @template T\n * @param {T} value\n * @return {React.RefObject<T>} The updated ref\n */\nfunction useUpdatedRef( value ) {\n\tconst ref = useRef( value );\n\tuseLayoutEffect( () => {\n\t\tref.current = value;\n\t}, [ value ] );\n\treturn ref;\n}\n\n/**\n * Copies the given text to the clipboard when the element is clicked.\n *\n * @template {HTMLElement} TElementType\n * @param {string | (() => string)} text The text to copy. Use a function if not\n * already available and expensive to compute.\n * @param {Function} onSuccess Called when to text is copied.\n *\n * @return {React.Ref<TElementType>} A ref to assign to the target element.\n */\nexport default function useCopyToClipboard( text, onSuccess ) {\n\t// Store the dependencies as refs and continuously update them so they're\n\t// fresh when the callback is called.\n\tconst textRef = useUpdatedRef( text );\n\tconst onSuccessRef = useUpdatedRef( onSuccess );\n\treturn useRefEffect( ( node ) => {\n\t\t// Clipboard listens to click events.\n\t\tconst clipboard = new Clipboard( node, {\n\t\t\ttext() {\n\t\t\t\treturn typeof textRef.current === 'function'\n\t\t\t\t\t? textRef.current()\n\t\t\t\t\t: textRef.current || '';\n\t\t\t},\n\t\t} );\n\n\t\tclipboard.on( 'success', ( { clearSelection } ) => {\n\t\t\t// Clearing selection will move focus back to the triggering\n\t\t\t// button, ensuring that it is not reset to the body, and\n\t\t\t// further that it is kept within the rendered node.\n\t\t\tclearSelection();\n\n\t\t\tif ( onSuccessRef.current ) {\n\t\t\t\tonSuccessRef.current();\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tclipboard.destroy();\n\t\t};\n\t}, [] );\n}\n"],
5
- "mappings": ";AAGA,OAAO,eAAe;AAKtB,SAAS,QAAQ,uBAAuB;AAKxC,OAAO,kBAAkB;AAOzB,SAAS,cAAe,OAAQ;AAC/B,QAAM,MAAM,OAAQ,KAAM;AAC1B,kBAAiB,MAAM;AACtB,QAAI,UAAU;AAAA,EACf,GAAG,CAAE,KAAM,CAAE;AACb,SAAO;AACR;AAYe,SAAR,mBAAqC,MAAM,WAAY;AAG7D,QAAM,UAAU,cAAe,IAAK;AACpC,QAAM,eAAe,cAAe,SAAU;AAC9C,SAAO,aAAc,CAAE,SAAU;AAEhC,UAAM,YAAY,IAAI,UAAW,MAAM;AAAA,MACtC,OAAO;AACN,eAAO,OAAO,QAAQ,YAAY,aAC/B,QAAQ,QAAQ,IAChB,QAAQ,WAAW;AAAA,MACvB;AAAA,IACD,CAAE;AAEF,cAAU,GAAI,WAAW,CAAE,EAAE,eAAe,MAAO;AAIlD,qBAAe;AAEf,UAAK,aAAa,SAAU;AAC3B,qBAAa,QAAQ;AAAA,MACtB;AAAA,IACD,CAAE;AAEF,WAAO,MAAM;AACZ,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
3
+ "sources": ["../../../src/hooks/use-copy-to-clipboard/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useLayoutEffect } from '@wordpress/element';\nimport type { MutableRefObject, RefCallback } from 'react';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * Copies text to the clipboard using the Clipboard API when available,\n * with a fallback for non-secure contexts (e.g. HTTP) and older browsers.\n *\n * @param text The text to copy.\n * @param trigger The element that triggered the copy.\n * @return Resolves to true if successful, false otherwise.\n */\nexport async function copyToClipboard(\n\ttext: string,\n\ttrigger: Element | null\n): Promise< boolean > {\n\tif ( ! trigger ) {\n\t\treturn false;\n\t}\n\tconst { ownerDocument } = trigger;\n\tif ( ! ownerDocument ) {\n\t\treturn false;\n\t}\n\tconst { defaultView } = ownerDocument;\n\ttry {\n\t\tif ( defaultView?.navigator?.clipboard?.writeText ) {\n\t\t\tawait defaultView.navigator.clipboard.writeText( text );\n\t\t\treturn true;\n\t\t}\n\t\t// Fallback for non-secure contexts (HTTP) and older browsers.\n\t\tconst textarea = ownerDocument.createElement( 'textarea' );\n\t\ttextarea.value = text;\n\t\ttextarea.setAttribute( 'readonly', '' );\n\t\ttextarea.style.position = 'fixed';\n\t\ttextarea.style.left = '-9999px';\n\t\ttextarea.style.top = '-9999px';\n\t\townerDocument.body.appendChild( textarea );\n\t\ttextarea.select();\n\t\tconst success = ownerDocument.execCommand( 'copy' );\n\t\ttextarea.remove();\n\t\treturn success;\n\t} catch {\n\t\treturn false;\n\t}\n}\n\n/**\n * Clears the current selection and restores focus to the trigger element.\n *\n * @param trigger The element that triggered the copy.\n */\nexport function clearSelection( trigger: Element ): void {\n\tif ( 'focus' in trigger && typeof trigger.focus === 'function' ) {\n\t\ttrigger.focus();\n\t}\n\ttrigger.ownerDocument?.defaultView?.getSelection()?.removeAllRanges();\n}\n\n/**\n * @template T\n * @param value\n * @return A ref to assign to the target element.\n */\nfunction useUpdatedRef< T >( value: T ): MutableRefObject< T > {\n\tconst ref = useRef< T >( value );\n\tuseLayoutEffect( () => {\n\t\tref.current = value;\n\t}, [ value ] );\n\treturn ref;\n}\n\n/**\n * Copies the given text to the clipboard when the element is clicked.\n *\n * @template T\n * @param text The text to copy. Use a function if not\n * already available and expensive to compute.\n * @param onSuccess Called when to text is copied.\n *\n * @return A ref to assign to the target element.\n */\nexport default function useCopyToClipboard< T extends HTMLElement >(\n\ttext: string | ( () => string ),\n\tonSuccess?: () => void\n): RefCallback< T > {\n\tconst textRef = useUpdatedRef( text );\n\tconst onSuccessRef = useUpdatedRef( onSuccess );\n\treturn useRefEffect( ( node ) => {\n\t\t// Flag to prevent callbacks after unmount when the Promise resolves.\n\t\tlet isActive = true;\n\t\tconst handleClick = async () => {\n\t\t\tconst textToCopy =\n\t\t\t\ttypeof textRef.current === 'function'\n\t\t\t\t\t? textRef.current()\n\t\t\t\t\t: textRef.current || '';\n\t\t\tconst success = await copyToClipboard( textToCopy, node );\n\t\t\tif ( ! isActive ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( success ) {\n\t\t\t\tclearSelection( node );\n\t\t\t\tif ( onSuccessRef.current ) {\n\t\t\t\t\tonSuccessRef.current();\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\t\tnode.addEventListener( 'click', handleClick );\n\t\treturn () => {\n\t\t\tisActive = false;\n\t\t\tnode.removeEventListener( 'click', handleClick );\n\t\t};\n\t}, [] );\n}\n"],
5
+ "mappings": ";AAGA,SAAS,QAAQ,uBAAuB;AAMxC,OAAO,kBAAkB;AAUzB,eAAsB,gBACrB,MACA,SACqB;AACrB,MAAK,CAAE,SAAU;AAChB,WAAO;AAAA,EACR;AACA,QAAM,EAAE,cAAc,IAAI;AAC1B,MAAK,CAAE,eAAgB;AACtB,WAAO;AAAA,EACR;AACA,QAAM,EAAE,YAAY,IAAI;AACxB,MAAI;AACH,QAAK,aAAa,WAAW,WAAW,WAAY;AACnD,YAAM,YAAY,UAAU,UAAU,UAAW,IAAK;AACtD,aAAO;AAAA,IACR;AAEA,UAAM,WAAW,cAAc,cAAe,UAAW;AACzD,aAAS,QAAQ;AACjB,aAAS,aAAc,YAAY,EAAG;AACtC,aAAS,MAAM,WAAW;AAC1B,aAAS,MAAM,OAAO;AACtB,aAAS,MAAM,MAAM;AACrB,kBAAc,KAAK,YAAa,QAAS;AACzC,aAAS,OAAO;AAChB,UAAM,UAAU,cAAc,YAAa,MAAO;AAClD,aAAS,OAAO;AAChB,WAAO;AAAA,EACR,QAAQ;AACP,WAAO;AAAA,EACR;AACD;AAOO,SAAS,eAAgB,SAAyB;AACxD,MAAK,WAAW,WAAW,OAAO,QAAQ,UAAU,YAAa;AAChE,YAAQ,MAAM;AAAA,EACf;AACA,UAAQ,eAAe,aAAa,aAAa,GAAG,gBAAgB;AACrE;AAOA,SAAS,cAAoB,OAAkC;AAC9D,QAAM,MAAM,OAAa,KAAM;AAC/B,kBAAiB,MAAM;AACtB,QAAI,UAAU;AAAA,EACf,GAAG,CAAE,KAAM,CAAE;AACb,SAAO;AACR;AAYe,SAAR,mBACN,MACA,WACmB;AACnB,QAAM,UAAU,cAAe,IAAK;AACpC,QAAM,eAAe,cAAe,SAAU;AAC9C,SAAO,aAAc,CAAE,SAAU;AAEhC,QAAI,WAAW;AACf,UAAM,cAAc,YAAY;AAC/B,YAAM,aACL,OAAO,QAAQ,YAAY,aACxB,QAAQ,QAAQ,IAChB,QAAQ,WAAW;AACvB,YAAM,UAAU,MAAM,gBAAiB,YAAY,IAAK;AACxD,UAAK,CAAE,UAAW;AACjB;AAAA,MACD;AACA,UAAK,SAAU;AACd,uBAAgB,IAAK;AACrB,YAAK,aAAa,SAAU;AAC3B,uBAAa,QAAQ;AAAA,QACtB;AAAA,MACD;AAAA,IACD;AACA,SAAK,iBAAkB,SAAS,WAAY;AAC5C,WAAO,MAAM;AACZ,iBAAW;AACX,WAAK,oBAAqB,SAAS,WAAY;AAAA,IAChD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
6
6
  "names": []
7
7
  }
@@ -1,26 +1,29 @@
1
- // packages/compose/src/hooks/use-media-query/index.js
1
+ // packages/compose/src/hooks/use-media-query/index.ts
2
2
  import { useMemo, useSyncExternalStore } from "@wordpress/element";
3
- var matchMediaCache = /* @__PURE__ */ new Map();
4
- function getMediaQueryList(query) {
3
+ var perWindowCache = /* @__PURE__ */ new WeakMap();
4
+ function getMediaQueryList(view, query) {
5
5
  if (!query) {
6
6
  return null;
7
7
  }
8
+ const matchMediaCache = perWindowCache.get(view) ?? /* @__PURE__ */ new Map();
9
+ if (!perWindowCache.has(view)) {
10
+ perWindowCache.set(view, matchMediaCache);
11
+ }
8
12
  let match = matchMediaCache.get(query);
9
13
  if (match) {
10
14
  return match;
11
15
  }
12
- if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
13
- match = window.matchMedia(query);
16
+ if (typeof view?.matchMedia === "function") {
17
+ match = view.matchMedia(query);
14
18
  matchMediaCache.set(query, match);
15
19
  return match;
16
20
  }
17
21
  return null;
18
22
  }
19
- function useMediaQuery(query) {
23
+ function useMediaQuery(query, view = window) {
20
24
  const source = useMemo(() => {
21
- const mediaQueryList = getMediaQueryList(query);
25
+ const mediaQueryList = getMediaQueryList(view, query);
22
26
  return {
23
- /** @type {(onStoreChange: () => void) => () => void} */
24
27
  subscribe(onStoreChange) {
25
28
  if (!mediaQueryList) {
26
29
  return () => {
@@ -38,7 +41,7 @@ function useMediaQuery(query) {
38
41
  return mediaQueryList?.matches ?? false;
39
42
  }
40
43
  };
41
- }, [query]);
44
+ }, [view, query]);
42
45
  return useSyncExternalStore(
43
46
  source.subscribe,
44
47
  source.getValue,
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
- "sources": ["../../../src/hooks/use-media-query/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\nconst matchMediaCache = new Map();\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif ( ! query ) {\n\t\treturn null;\n\t}\n\n\tlet match = matchMediaCache.get( query );\n\n\tif ( match ) {\n\t\treturn match;\n\t}\n\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\tmatch = window.matchMedia( query );\n\t\tmatchMediaCache.set( query, match );\n\t\treturn match;\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],
5
- "mappings": ";AAGA,SAAS,SAAS,4BAA4B;AAE9C,IAAM,kBAAkB,oBAAI,IAAI;AAQhC,SAAS,kBAAmB,OAAQ;AACnC,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,MAAI,QAAQ,gBAAgB,IAAK,KAAM;AAEvC,MAAK,OAAQ;AACZ,WAAO;AAAA,EACR;AAEA,MACC,OAAO,WAAW,eAClB,OAAO,OAAO,eAAe,YAC5B;AACD,YAAQ,OAAO,WAAY,KAAM;AACjC,oBAAgB,IAAK,OAAO,KAAM;AAClC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAQe,SAAR,cAAgC,OAAQ;AAC9C,QAAM,SAAS,QAAS,MAAM;AAC7B,UAAM,iBAAiB,kBAAmB,KAAM;AAEhD,WAAO;AAAA;AAAA,MAEN,UAAW,eAAgB;AAC1B,YAAK,CAAE,gBAAiB;AACvB,iBAAO,MAAM;AAAA,UAAC;AAAA,QACf;AAGA,uBAAe,mBAAoB,UAAU,aAAc;AAC3D,eAAO,MAAM;AACZ,yBAAe;AAAA,YACd;AAAA,YACA;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,WAAW;AACV,eAAO,gBAAgB,WAAW;AAAA,MACnC;AAAA,IACD;AAAA,EACD,GAAG,CAAE,KAAM,CAAE;AAEb,SAAO;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,MAAM;AAAA,EACP;AACD;",
3
+ "sources": ["../../../src/hooks/use-media-query/index.ts"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\ntype MQLCache = Map< string, MediaQueryList >;\n\nconst perWindowCache = new WeakMap< Window, MQLCache >();\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param view Window.\n * @param [query] Media Query.\n */\nfunction getMediaQueryList(\n\tview: Window,\n\tquery?: string\n): MediaQueryList | null {\n\tif ( ! query ) {\n\t\treturn null;\n\t}\n\n\tconst matchMediaCache: MQLCache = perWindowCache.get( view ) ?? new Map();\n\n\tif ( ! perWindowCache.has( view ) ) {\n\t\tperWindowCache.set( view, matchMediaCache );\n\t}\n\n\tlet match = matchMediaCache.get( query );\n\n\tif ( match ) {\n\t\treturn match;\n\t}\n\n\tif ( typeof view?.matchMedia === 'function' ) {\n\t\tmatch = view.matchMedia( query );\n\t\tmatchMediaCache.set( query, match );\n\t\treturn match;\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param [query] Media Query.\n * @param [view] Window instance, else default to global window\n * @return return value of the media query.\n */\nexport default function useMediaQuery(\n\tquery?: string,\n\tview: Window = window\n): boolean {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( view, query );\n\n\t\treturn {\n\t\t\tsubscribe( onStoreChange: any ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ view, query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],
5
+ "mappings": ";AAGA,SAAS,SAAS,4BAA4B;AAI9C,IAAM,iBAAiB,oBAAI,QAA4B;AAQvD,SAAS,kBACR,MACA,OACwB;AACxB,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,QAAM,kBAA4B,eAAe,IAAK,IAAK,KAAK,oBAAI,IAAI;AAExE,MAAK,CAAE,eAAe,IAAK,IAAK,GAAI;AACnC,mBAAe,IAAK,MAAM,eAAgB;AAAA,EAC3C;AAEA,MAAI,QAAQ,gBAAgB,IAAK,KAAM;AAEvC,MAAK,OAAQ;AACZ,WAAO;AAAA,EACR;AAEA,MAAK,OAAO,MAAM,eAAe,YAAa;AAC7C,YAAQ,KAAK,WAAY,KAAM;AAC/B,oBAAgB,IAAK,OAAO,KAAM;AAClC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AASe,SAAR,cACN,OACA,OAAe,QACL;AACV,QAAM,SAAS,QAAS,MAAM;AAC7B,UAAM,iBAAiB,kBAAmB,MAAM,KAAM;AAEtD,WAAO;AAAA,MACN,UAAW,eAAqB;AAC/B,YAAK,CAAE,gBAAiB;AACvB,iBAAO,MAAM;AAAA,UAAC;AAAA,QACf;AAGA,uBAAe,mBAAoB,UAAU,aAAc;AAC3D,eAAO,MAAM;AACZ,yBAAe;AAAA,YACd;AAAA,YACA;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,WAAW;AACV,eAAO,gBAAgB,WAAW;AAAA,MACnC;AAAA,IACD;AAAA,EACD,GAAG,CAAE,MAAM,KAAM,CAAE;AAEnB,SAAO;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,MAAM;AAAA,EACP;AACD;",
6
6
  "names": []
7
7
  }
@@ -24,10 +24,10 @@ var ViewportMatchWidthContext = createContext(
24
24
  null
25
25
  );
26
26
  ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext";
27
- var useViewportMatch = (breakpoint, operator = ">=") => {
27
+ var useViewportMatch = (breakpoint, operator = ">=", view = window) => {
28
28
  const simulatedWidth = useContext(ViewportMatchWidthContext);
29
29
  const mediaQuery = !simulatedWidth && `(${CONDITIONS[operator]}: ${BREAKPOINTS[breakpoint]}px)`;
30
- const mediaQueryResult = useMediaQuery(mediaQuery || void 0);
30
+ const mediaQueryResult = useMediaQuery(mediaQuery || void 0, view);
31
31
  if (simulatedWidth) {
32
32
  return OPERATOR_EVALUATORS[operator](
33
33
  BREAKPOINTS[breakpoint],
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../../../src/hooks/use-viewport-match/index.js"],
4
- "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * @typedef {\"xhuge\" | \"huge\" | \"wide\" | \"xlarge\" | \"large\" | \"medium\" | \"small\" | \"mobile\"} WPBreakpoint\n */\n\n/**\n * Hash of breakpoint names with pixel width at which it becomes effective.\n *\n * @see _breakpoints.scss\n *\n * @type {Record<WPBreakpoint, number>}\n */\nconst BREAKPOINTS = {\n\txhuge: 1920,\n\thuge: 1440,\n\twide: 1280,\n\txlarge: 1080,\n\tlarge: 960,\n\tmedium: 782,\n\tsmall: 600,\n\tmobile: 480,\n};\n\n/**\n * @typedef {\">=\" | \"<\"} WPViewportOperator\n */\n\n/**\n * Object mapping media query operators to the condition to be used.\n *\n * @type {Record<WPViewportOperator, string>}\n */\nconst CONDITIONS = {\n\t'>=': 'min-width',\n\t'<': 'max-width',\n};\n\n/**\n * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.\n *\n * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}\n */\nconst OPERATOR_EVALUATORS = {\n\t'>=': ( breakpointValue, width ) => width >= breakpointValue,\n\t'<': ( breakpointValue, width ) => width < breakpointValue,\n};\n\nconst ViewportMatchWidthContext = createContext(\n\t/** @type {null | number} */ ( null )\n);\nViewportMatchWidthContext.displayName = 'ViewportMatchWidthContext';\n\n/**\n * Returns true if the viewport matches the given query, or false otherwise.\n *\n * @param {WPBreakpoint} breakpoint Breakpoint size name.\n * @param {WPViewportOperator} [operator=\">=\"] Viewport operator.\n *\n * @example\n *\n * ```js\n * useViewportMatch( 'huge', '<' );\n * useViewportMatch( 'medium' );\n * ```\n *\n * @return {boolean} Whether viewport matches query.\n */\nconst useViewportMatch = ( breakpoint, operator = '>=' ) => {\n\tconst simulatedWidth = useContext( ViewportMatchWidthContext );\n\tconst mediaQuery =\n\t\t! simulatedWidth &&\n\t\t`(${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;\n\tconst mediaQueryResult = useMediaQuery( mediaQuery || undefined );\n\tif ( simulatedWidth ) {\n\t\treturn OPERATOR_EVALUATORS[ operator ](\n\t\t\tBREAKPOINTS[ breakpoint ],\n\t\t\tsimulatedWidth\n\t\t);\n\t}\n\treturn mediaQueryResult;\n};\n\nuseViewportMatch.__experimentalWidthProvider =\n\tViewportMatchWidthContext.Provider;\n\nexport default useViewportMatch;\n"],
5
- "mappings": ";AAGA,SAAS,eAAe,kBAAkB;AAK1C,OAAO,mBAAmB;AAa1B,IAAM,cAAc;AAAA,EACnB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AACT;AAWA,IAAM,aAAa;AAAA,EAClB,MAAM;AAAA,EACN,KAAK;AACN;AAOA,IAAM,sBAAsB;AAAA,EAC3B,MAAM,CAAE,iBAAiB,UAAW,SAAS;AAAA,EAC7C,KAAK,CAAE,iBAAiB,UAAW,QAAQ;AAC5C;AAEA,IAAM,4BAA4B;AAAA;AAAA,EACF;AAChC;AACA,0BAA0B,cAAc;AAiBxC,IAAM,mBAAmB,CAAE,YAAY,WAAW,SAAU;AAC3D,QAAM,iBAAiB,WAAY,yBAA0B;AAC7D,QAAM,aACL,CAAE,kBACF,IAAK,WAAY,QAAS,CAAE,KAAM,YAAa,UAAW,CAAE;AAC7D,QAAM,mBAAmB,cAAe,cAAc,MAAU;AAChE,MAAK,gBAAiB;AACrB,WAAO,oBAAqB,QAAS;AAAA,MACpC,YAAa,UAAW;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA,iBAAiB,8BAChB,0BAA0B;AAE3B,IAAO,6BAAQ;",
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { createContext, useContext } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * @typedef {\"xhuge\" | \"huge\" | \"wide\" | \"xlarge\" | \"large\" | \"medium\" | \"small\" | \"mobile\"} WPBreakpoint\n */\n\n/**\n * Hash of breakpoint names with pixel width at which it becomes effective.\n *\n * @see _breakpoints.scss\n *\n * @type {Record<WPBreakpoint, number>}\n */\nconst BREAKPOINTS = {\n\txhuge: 1920,\n\thuge: 1440,\n\twide: 1280,\n\txlarge: 1080,\n\tlarge: 960,\n\tmedium: 782,\n\tsmall: 600,\n\tmobile: 480,\n};\n\n/**\n * @typedef {\">=\" | \"<\"} WPViewportOperator\n */\n\n/**\n * Object mapping media query operators to the condition to be used.\n *\n * @type {Record<WPViewportOperator, string>}\n */\nconst CONDITIONS = {\n\t'>=': 'min-width',\n\t'<': 'max-width',\n};\n\n/**\n * Object mapping media query operators to a function that given a breakpointValue and a width evaluates if the operator matches the values.\n *\n * @type {Record<WPViewportOperator, (breakpointValue: number, width: number) => boolean>}\n */\nconst OPERATOR_EVALUATORS = {\n\t'>=': ( breakpointValue, width ) => width >= breakpointValue,\n\t'<': ( breakpointValue, width ) => width < breakpointValue,\n};\n\nconst ViewportMatchWidthContext = createContext(\n\t/** @type {null | number} */ ( null )\n);\nViewportMatchWidthContext.displayName = 'ViewportMatchWidthContext';\n\n/**\n * Returns true if the viewport matches the given query, or false otherwise.\n *\n * @param {WPBreakpoint} breakpoint Breakpoint size name.\n * @param {WPViewportOperator} [operator=\">=\"] Viewport operator.\n * @param {Window} [view=window] Window instance in which to perform viewport matching.\n *\n * @example\n *\n * ```js\n * useViewportMatch( 'huge', '<' );\n * useViewportMatch( 'medium' );\n * ```\n *\n * @return {boolean} Whether viewport matches query.\n */\nconst useViewportMatch = ( breakpoint, operator = '>=', view = window ) => {\n\tconst simulatedWidth = useContext( ViewportMatchWidthContext );\n\tconst mediaQuery =\n\t\t! simulatedWidth &&\n\t\t`(${ CONDITIONS[ operator ] }: ${ BREAKPOINTS[ breakpoint ] }px)`;\n\tconst mediaQueryResult = useMediaQuery( mediaQuery || undefined, view );\n\tif ( simulatedWidth ) {\n\t\treturn OPERATOR_EVALUATORS[ operator ](\n\t\t\tBREAKPOINTS[ breakpoint ],\n\t\t\tsimulatedWidth\n\t\t);\n\t}\n\treturn mediaQueryResult;\n};\n\nuseViewportMatch.__experimentalWidthProvider =\n\tViewportMatchWidthContext.Provider;\n\nexport default useViewportMatch;\n"],
5
+ "mappings": ";AAGA,SAAS,eAAe,kBAAkB;AAK1C,OAAO,mBAAmB;AAa1B,IAAM,cAAc;AAAA,EACnB,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AACT;AAWA,IAAM,aAAa;AAAA,EAClB,MAAM;AAAA,EACN,KAAK;AACN;AAOA,IAAM,sBAAsB;AAAA,EAC3B,MAAM,CAAE,iBAAiB,UAAW,SAAS;AAAA,EAC7C,KAAK,CAAE,iBAAiB,UAAW,QAAQ;AAC5C;AAEA,IAAM,4BAA4B;AAAA;AAAA,EACF;AAChC;AACA,0BAA0B,cAAc;AAkBxC,IAAM,mBAAmB,CAAE,YAAY,WAAW,MAAM,OAAO,WAAY;AAC1E,QAAM,iBAAiB,WAAY,yBAA0B;AAC7D,QAAM,aACL,CAAE,kBACF,IAAK,WAAY,QAAS,CAAE,KAAM,YAAa,UAAW,CAAE;AAC7D,QAAM,mBAAmB,cAAe,cAAc,QAAW,IAAK;AACtE,MAAK,gBAAiB;AACrB,WAAO,oBAAqB,QAAS;AAAA,MACpC,YAAa,UAAW;AAAA,MACxB;AAAA,IACD;AAAA,EACD;AACA,SAAO;AACR;AAEA,iBAAiB,8BAChB,0BAA0B;AAE3B,IAAO,6BAAQ;",
6
6
  "names": []
7
7
  }
@@ -1,15 +1,14 @@
1
+ import type { RefObject } from 'react';
1
2
  /**
2
3
  * Copies the text to the clipboard when the element is clicked.
3
4
  *
4
5
  * @deprecated
5
- *
6
- * @param {React.RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.
7
- * @param {string|Function} text The text to copy.
8
- * @param {number} [timeout] Optional timeout to reset the returned
9
- * state. 4 seconds by default.
10
- *
11
- * @return {boolean} Whether or not the text has been copied. Resets after the
12
- * timeout.
6
+ * @param ref Reference with the element.
7
+ * @param text The text to copy.
8
+ * @param timeout Optional timeout to reset the returned
9
+ * state. 4 seconds by default.
10
+ * @return Whether or not the text has been copied. Resets after the
11
+ * timeout.
13
12
  */
14
- export default function useCopyOnClick(ref: React.RefObject<string | Element | NodeListOf<Element>>, text: string | Function, timeout?: number): boolean;
13
+ export default function useCopyOnClick(ref: RefObject<string | Element | NodeListOf<Element>>, text: string | (() => string), timeout?: number): boolean;
15
14
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-copy-on-click/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;GAYG;AACH,4CARW,KAAK,CAAC,SAAS,CAAC,MAAM,GAAG,OAAO,GAAG,UAAU,CAAC,OAAO,CAAC,CAAC,QACvD,MAAM,WAAS,YACf,MAAM,GAGL,OAAO,CAqDlB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-copy-on-click/index.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,OAAO,CAAC;AAOvC;;;;;;;;;;GAUG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CACrC,GAAG,EAAE,SAAS,CAAE,MAAM,GAAG,OAAO,GAAG,UAAU,CAAE,OAAO,CAAE,CAAE,EAC1D,IAAI,EAAE,MAAM,GAAG,CAAE,MAAM,MAAM,CAAE,EAC/B,OAAO,GAAE,MAAa,GACpB,OAAO,CAyET"}
@@ -1,12 +1,28 @@
1
+ import type { RefCallback } from 'react';
2
+ /**
3
+ * Copies text to the clipboard using the Clipboard API when available,
4
+ * with a fallback for non-secure contexts (e.g. HTTP) and older browsers.
5
+ *
6
+ * @param text The text to copy.
7
+ * @param trigger The element that triggered the copy.
8
+ * @return Resolves to true if successful, false otherwise.
9
+ */
10
+ export declare function copyToClipboard(text: string, trigger: Element | null): Promise<boolean>;
11
+ /**
12
+ * Clears the current selection and restores focus to the trigger element.
13
+ *
14
+ * @param trigger The element that triggered the copy.
15
+ */
16
+ export declare function clearSelection(trigger: Element): void;
1
17
  /**
2
18
  * Copies the given text to the clipboard when the element is clicked.
3
19
  *
4
- * @template {HTMLElement} TElementType
5
- * @param {string | (() => string)} text The text to copy. Use a function if not
6
- * already available and expensive to compute.
7
- * @param {Function} onSuccess Called when to text is copied.
20
+ * @template T
21
+ * @param text The text to copy. Use a function if not
22
+ * already available and expensive to compute.
23
+ * @param onSuccess Called when to text is copied.
8
24
  *
9
- * @return {React.Ref<TElementType>} A ref to assign to the target element.
25
+ * @return A ref to assign to the target element.
10
26
  */
11
- export default function useCopyToClipboard<TElementType extends HTMLElement>(text: string | (() => string), onSuccess: Function): React.Ref<TElementType>;
27
+ export default function useCopyToClipboard<T extends HTMLElement>(text: string | (() => string), onSuccess?: () => void): RefCallback<T>;
12
28
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-copy-to-clipboard/index.js"],"names":[],"mappings":"AA4BA;;;;;;;;;GASG;AACH,2CAP2B,YAAY,SAAzB,WAAY,QACf,MAAM,GAAG,CAAC,MAAM,MAAM,CAAC,wBAItB,KAAK,CAAC,GAAG,CAAC,YAAY,CAAC,CAgClC"}
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"}
@@ -4,6 +4,6 @@ export default useIsomorphicLayoutEffect;
4
4
  * server rendered components (SSR) because currently React
5
5
  * throws a warning when using useLayoutEffect in that environment.
6
6
  */
7
- declare const useIsomorphicLayoutEffect: typeof useEffect;
8
- import { useEffect } from '@wordpress/element';
7
+ declare const useIsomorphicLayoutEffect: typeof useLayoutEffect;
8
+ import { useLayoutEffect } from '@wordpress/element';
9
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-isomorphic-layout-effect/index.js"],"names":[],"mappings":";AAKA;;;;GAIG;AACH,0DAC6D;0BARlB,oBAAoB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-isomorphic-layout-effect/index.js"],"names":[],"mappings":";AAKA;;;;GAIG;AACH,gEAC6D;gCARlB,oBAAoB"}
@@ -1,8 +1,9 @@
1
1
  /**
2
2
  * Runs a media query and returns its value when it changes.
3
3
  *
4
- * @param {string} [query] Media Query.
5
- * @return {boolean} return value of the media query.
4
+ * @param [query] Media Query.
5
+ * @param [view] Window instance, else default to global window
6
+ * @return return value of the media query.
6
7
  */
7
- export default function useMediaQuery(query?: string): boolean;
8
+ export default function useMediaQuery(query?: string, view?: Window): boolean;
8
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-media-query/index.js"],"names":[],"mappings":"AAoCA;;;;;GAKG;AACH,8CAHW,MAAM,GACL,OAAO,CAiClB"}
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"}
@@ -6,6 +6,7 @@ export type WPViewportOperator = ">=" | "<";
6
6
  *
7
7
  * @param {WPBreakpoint} breakpoint Breakpoint size name.
8
8
  * @param {WPViewportOperator} [operator=">="] Viewport operator.
9
+ * @param {Window} [view=window] Window instance in which to perform viewport matching.
9
10
  *
10
11
  * @example
11
12
  *
@@ -16,7 +17,7 @@ export type WPViewportOperator = ">=" | "<";
16
17
  *
17
18
  * @return {boolean} Whether viewport matches query.
18
19
  */
19
- declare function useViewportMatch(breakpoint: WPBreakpoint, operator?: WPViewportOperator): boolean;
20
+ declare function useViewportMatch(breakpoint: WPBreakpoint, operator?: WPViewportOperator, view?: Window): boolean;
20
21
  declare namespace useViewportMatch {
21
22
  let __experimentalWidthProvider: import("react").Provider<number | null>;
22
23
  }
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-viewport-match/index.js"],"names":[],"mappings":";2BAWa,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ;iCAsB9E,IAAI,GAAG,GAAG;AA4BvB;;;;;;;;;;;;;;GAcG;AACH,8CAZW,YAAY,aACZ,kBAAkB,GASjB,OAAO,CAelB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-viewport-match/index.js"],"names":[],"mappings":";2BAWa,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ,GAAG,OAAO,GAAG,QAAQ;iCAsB9E,IAAI,GAAG,GAAG;AA4BvB;;;;;;;;;;;;;;;GAeG;AACH,8CAbW,YAAY,aACZ,kBAAkB,SAClB,MAAM,GASL,OAAO,CAelB"}
@@ -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.40.1-next.v.202602241322.0+bce7cff88",
3
+ "version": "7.40.1",
4
4
  "description": "WordPress higher-order components (HOCs).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -47,15 +47,14 @@
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",
51
+ "@wordpress/dom": "^4.40.1",
52
+ "@wordpress/element": "^6.40.1",
53
+ "@wordpress/is-shallow-equal": "^5.40.1",
54
+ "@wordpress/keycodes": "^4.40.1",
55
+ "@wordpress/priority-queue": "^3.40.1",
56
+ "@wordpress/undo-manager": "^1.40.1",
57
57
  "change-case": "^4.1.2",
58
- "clipboard": "^2.0.11",
59
58
  "mousetrap": "^1.6.5",
60
59
  "use-memo-one": "^1.1.1"
61
60
  },
@@ -68,5 +67,5 @@
68
67
  "publishConfig": {
69
68
  "access": "public"
70
69
  },
71
- "gitHead": "943dde7f0b600ce238726c36284bc9f70ce0ffa4"
70
+ "gitHead": "adb6623c9f32490cfc73c7ac7f122578c1f10c65"
72
71
  }
@@ -0,0 +1,101 @@
1
+ /**
2
+ * WordPress dependencies
3
+ */
4
+ import { useEffect, useState } from '@wordpress/element';
5
+ import deprecated from '@wordpress/deprecated';
6
+ import type { RefObject } from 'react';
7
+
8
+ /**
9
+ * Internal dependencies
10
+ */
11
+ import { clearSelection, copyToClipboard } from '../use-copy-to-clipboard';
12
+
13
+ /**
14
+ * Copies the text to the clipboard when the element is clicked.
15
+ *
16
+ * @deprecated
17
+ * @param ref Reference with the element.
18
+ * @param text The text to copy.
19
+ * @param timeout Optional timeout to reset the returned
20
+ * state. 4 seconds by default.
21
+ * @return Whether or not the text has been copied. Resets after the
22
+ * timeout.
23
+ */
24
+ export default function useCopyOnClick(
25
+ ref: RefObject< string | Element | NodeListOf< Element > >,
26
+ text: string | ( () => string ),
27
+ timeout: number = 4000
28
+ ): boolean {
29
+ deprecated( 'wp.compose.useCopyOnClick', {
30
+ since: '5.8',
31
+ alternative: 'wp.compose.useCopyToClipboard',
32
+ } );
33
+
34
+ const [ hasCopied, setHasCopied ] = useState( false );
35
+
36
+ useEffect( () => {
37
+ // Flag to prevent state updates after unmount when the Promise resolves.
38
+ let isActive = true;
39
+ let timeoutId: ReturnType< typeof setTimeout > | undefined;
40
+ if ( ! ref.current ) {
41
+ return;
42
+ }
43
+
44
+ let targets: Element[];
45
+ if ( typeof ref.current === 'string' ) {
46
+ targets =
47
+ typeof document !== 'undefined'
48
+ ? Array.from( document.querySelectorAll( ref.current ) )
49
+ : [];
50
+ } else if (
51
+ 'length' in ref.current &&
52
+ typeof ref.current.length === 'number'
53
+ ) {
54
+ targets = Array.from( ref.current );
55
+ } else {
56
+ targets = [ ref.current as Element ];
57
+ }
58
+
59
+ if ( targets.length === 0 ) {
60
+ return;
61
+ }
62
+
63
+ const handleClick = async ( event: Event ) => {
64
+ const trigger = event.currentTarget as Element;
65
+ if ( ! trigger ) {
66
+ return;
67
+ }
68
+ const success = await copyToClipboard(
69
+ typeof text === 'function' ? text() : text || '',
70
+ trigger
71
+ );
72
+ if ( ! isActive ) {
73
+ return;
74
+ }
75
+ if ( success ) {
76
+ clearSelection( trigger );
77
+ if ( timeout ) {
78
+ setHasCopied( true );
79
+ clearTimeout( timeoutId );
80
+ timeoutId = setTimeout(
81
+ () => setHasCopied( false ),
82
+ timeout
83
+ );
84
+ }
85
+ }
86
+ };
87
+
88
+ for ( const target of targets ) {
89
+ target.addEventListener( 'click', handleClick );
90
+ }
91
+ return () => {
92
+ isActive = false;
93
+ for ( const target of targets ) {
94
+ target.removeEventListener( 'click', handleClick );
95
+ }
96
+ clearTimeout( timeoutId );
97
+ };
98
+ }, [ ref, text, timeout ] );
99
+
100
+ return hasCopied;
101
+ }