@wordpress/compose 7.46.0 → 8.1.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/CHANGELOG.md +13 -0
- package/README.md +4 -0
- package/build/hooks/use-copy-on-click/index.cjs +1 -1
- package/build/hooks/use-copy-on-click/index.cjs.map +2 -2
- package/build/hooks/use-copy-to-clipboard/index.cjs +8 -10
- package/build/hooks/use-copy-to-clipboard/index.cjs.map +2 -2
- package/build/hooks/use-dialog/index.cjs +8 -13
- package/build/hooks/use-dialog/index.cjs.map +2 -2
- package/build/hooks/use-media-query/index.cjs +42 -36
- package/build/hooks/use-media-query/index.cjs.map +2 -2
- package/build/index.cjs +3 -0
- package/build/index.cjs.map +2 -2
- package/build/lock-unlock.cjs +37 -0
- package/build/lock-unlock.cjs.map +7 -0
- package/build/private-apis.cjs +46 -0
- package/build/private-apis.cjs.map +7 -0
- package/build/utils/subscribe-delegated-listener/index.cjs +101 -0
- package/build/utils/subscribe-delegated-listener/index.cjs.map +7 -0
- package/build-module/hooks/use-copy-on-click/index.mjs +2 -2
- package/build-module/hooks/use-copy-on-click/index.mjs.map +2 -2
- package/build-module/hooks/use-copy-to-clipboard/index.mjs +6 -8
- package/build-module/hooks/use-copy-to-clipboard/index.mjs.map +2 -2
- package/build-module/hooks/use-dialog/index.mjs +8 -13
- package/build-module/hooks/use-dialog/index.mjs.map +2 -2
- package/build-module/hooks/use-media-query/index.mjs +43 -37
- package/build-module/hooks/use-media-query/index.mjs.map +2 -2
- package/build-module/index.mjs +2 -0
- package/build-module/index.mjs.map +2 -2
- package/build-module/lock-unlock.mjs +11 -0
- package/build-module/lock-unlock.mjs.map +7 -0
- package/build-module/private-apis.mjs +11 -0
- package/build-module/private-apis.mjs.map +7 -0
- package/build-module/utils/subscribe-delegated-listener/index.mjs +80 -0
- package/build-module/utils/subscribe-delegated-listener/index.mjs.map +7 -0
- package/build-types/hooks/use-copy-to-clipboard/index.d.ts +2 -2
- package/build-types/hooks/use-copy-to-clipboard/index.d.ts.map +1 -1
- package/build-types/hooks/use-dialog/index.d.ts +8 -2
- package/build-types/hooks/use-dialog/index.d.ts.map +1 -1
- package/build-types/hooks/use-media-query/index.d.ts.map +1 -1
- package/build-types/index.d.ts +1 -0
- package/build-types/index.d.ts.map +1 -1
- package/build-types/lock-unlock.d.ts +2 -0
- package/build-types/lock-unlock.d.ts.map +1 -0
- package/build-types/private-apis.d.ts +5 -0
- package/build-types/private-apis.d.ts.map +1 -0
- package/build-types/utils/subscribe-delegated-listener/index.d.ts +27 -0
- package/build-types/utils/subscribe-delegated-listener/index.d.ts.map +1 -0
- package/package.json +10 -9
- package/src/hooks/use-copy-on-click/index.ts +2 -2
- package/src/hooks/use-copy-to-clipboard/index.ts +8 -8
- package/src/hooks/use-copy-to-clipboard/test/index.tsx +33 -5
- package/src/hooks/use-dialog/README.md +52 -18
- package/src/hooks/use-dialog/index.ts +30 -20
- package/src/hooks/use-dialog/test/index.tsx +162 -34
- package/src/hooks/use-media-query/index.ts +54 -52
- package/src/index.js +3 -0
- package/src/lock-unlock.ts +10 -0
- package/src/private-apis.ts +13 -0
- package/src/utils/subscribe-delegated-listener/index.ts +128 -0
- package/src/utils/subscribe-delegated-listener/test/index.js +170 -0
|
@@ -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": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;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,IAAK,MAAM,OAAQ;AAAA,EAC/B;AACA,QAAM,MAAM,UAAU,GAAI,SAAU,aAAa;AACjD,MAAI,WAAW,QAAQ,IAAK,GAAI;AAChC,MAAK,CAAE,UAAW;AACjB,eAAW,oBAAI,QAA6C;AAC5D,YAAQ,IAAK,KAAK,QAAS;AAC3B,UAAM,cAAc;AACpB,SAAK;AAAA,MACJ;AAAA,MACA,CAAE,UAAW;AACZ,YAAK,UAAW;AAGf,gBAAMA,OAAM,YAAY,IAAK,IAAK;AAClC,cAAKA,MAAM;AACV,uBAAY,MAAMA,MAAM;AACvB,iBAAI,KAAM;AAAA,YACX;AAAA,UACD;AACA;AAAA,QACD;AAKA,YAAK,SAAU;AACd,gBAAM,OAAiC,CAAC;AACxC,cAAI,UAAuB,MAAM;AACjC,iBAAQ,SAAU;AACjB,iBAAK,KAAM,OAAQ;AACnB,gBAAK,YAAY,MAAO;AACvB;AAAA,YACD;AACA,sBAAU,QAAQ;AAAA,UACnB;AACA,mBAAU,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG,KAAM;AAC5C,kBAAMA,OAAM,YAAY,IAAK,KAAM,CAAE,CAAE;AACvC,gBAAKA,MAAM;AACV,yBAAY,MAAMA,MAAM;AACvB,mBAAI,KAAM;AAAA,cACX;AAAA,YACD;AAAA,UACD;AAAA,QACD,OAAO;AACN,cAAI,UAAuB,MAAM;AACjC,iBAAQ,SAAU;AACjB,kBAAMA,OAAM,YAAY,IAAK,OAAQ;AACrC,gBAAKA,MAAM;AACV,yBAAY,MAAMA,MAAM;AACvB,mBAAI,KAAM;AAAA,cACX;AAAA,YACD;AACA,gBAAK,YAAY,MAAO;AACvB;AAAA,YACD;AACA,sBAAU,QAAQ;AAAA,UACnB;AAAA,QACD;AAAA,MACD;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,MAAI,MAAM,SAAS,IAAK,MAAO;AAC/B,MAAK,CAAE,KAAM;AACZ,UAAM,oBAAI,IAAI;AACd,aAAS,IAAK,QAAQ,GAAI;AAAA,EAC3B;AACA,MAAI,IAAK,QAAS;AAClB,SAAO,MAAM;AACZ,QAAI,OAAQ,QAAS;AAAA,EACtB;AACD;",
|
|
6
|
+
"names": ["set"]
|
|
7
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
// packages/compose/src/hooks/use-copy-on-click/index.ts
|
|
2
2
|
import { useEffect, useState } from "@wordpress/element";
|
|
3
3
|
import deprecated from "@wordpress/deprecated";
|
|
4
|
-
import {
|
|
4
|
+
import { restoreFocus, copyToClipboard } from "../use-copy-to-clipboard/index.mjs";
|
|
5
5
|
function useCopyOnClick(ref, text, timeout = 4e3) {
|
|
6
6
|
deprecated("wp.compose.useCopyOnClick", {
|
|
7
7
|
since: "5.8",
|
|
@@ -38,7 +38,7 @@ function useCopyOnClick(ref, text, timeout = 4e3) {
|
|
|
38
38
|
return;
|
|
39
39
|
}
|
|
40
40
|
if (success) {
|
|
41
|
-
|
|
41
|
+
restoreFocus(trigger);
|
|
42
42
|
if (timeout) {
|
|
43
43
|
setHasCopied(true);
|
|
44
44
|
clearTimeout(timeoutId);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/use-copy-on-click/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport type { RefObject } from 'react';\n\n/**\n * Internal dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA,SAAS,WAAW,gBAAgB;AACpC,OAAO,gBAAgB;AAMvB,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useState } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\nimport type { RefObject } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { restoreFocus, copyToClipboard } from '../use-copy-to-clipboard';\n\n/**\n * Copies the text to the clipboard when the element is clicked.\n *\n * @deprecated\n * @param ref Reference with the element.\n * @param text The text to copy.\n * @param timeout Optional timeout to reset the returned\n * state. 4 seconds by default.\n * @return Whether or not the text has been copied. Resets after the\n * timeout.\n */\nexport default function useCopyOnClick(\n\tref: RefObject< string | Element | NodeListOf< Element > >,\n\ttext: string | ( () => string ),\n\ttimeout: number = 4000\n): boolean {\n\tdeprecated( 'wp.compose.useCopyOnClick', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.compose.useCopyToClipboard',\n\t} );\n\n\tconst [ hasCopied, setHasCopied ] = useState( false );\n\n\tuseEffect( () => {\n\t\t// Flag to prevent state updates after unmount when the Promise resolves.\n\t\tlet isActive = true;\n\t\tlet timeoutId: ReturnType< typeof setTimeout > | undefined;\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\tlet targets: Element[];\n\t\tif ( typeof ref.current === 'string' ) {\n\t\t\ttargets =\n\t\t\t\ttypeof document !== 'undefined'\n\t\t\t\t\t? Array.from( document.querySelectorAll( ref.current ) )\n\t\t\t\t\t: [];\n\t\t} else if (\n\t\t\t'length' in ref.current &&\n\t\t\ttypeof ref.current.length === 'number'\n\t\t) {\n\t\t\ttargets = Array.from( ref.current );\n\t\t} else {\n\t\t\ttargets = [ ref.current as Element ];\n\t\t}\n\n\t\tif ( targets.length === 0 ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst handleClick = async ( event: Event ) => {\n\t\t\tconst trigger = event.currentTarget as Element;\n\t\t\tif ( ! trigger ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tconst success = await copyToClipboard(\n\t\t\t\ttypeof text === 'function' ? text() : text || '',\n\t\t\t\ttrigger\n\t\t\t);\n\t\t\tif ( ! isActive ) {\n\t\t\t\treturn;\n\t\t\t}\n\t\t\tif ( success ) {\n\t\t\t\trestoreFocus( trigger );\n\t\t\t\tif ( timeout ) {\n\t\t\t\t\tsetHasCopied( true );\n\t\t\t\t\tclearTimeout( timeoutId );\n\t\t\t\t\ttimeoutId = setTimeout(\n\t\t\t\t\t\t() => setHasCopied( false ),\n\t\t\t\t\t\ttimeout\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t}\n\t\t};\n\n\t\tfor ( const target of targets ) {\n\t\t\ttarget.addEventListener( 'click', handleClick );\n\t\t}\n\t\treturn () => {\n\t\t\tisActive = false;\n\t\t\tfor ( const target of targets ) {\n\t\t\t\ttarget.removeEventListener( 'click', handleClick );\n\t\t\t}\n\t\t\tclearTimeout( timeoutId );\n\t\t};\n\t}, [ ref, text, timeout ] );\n\n\treturn hasCopied;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,WAAW,gBAAgB;AACpC,OAAO,gBAAgB;AAMvB,SAAS,cAAc,uBAAuB;AAa/B,SAAR,eACN,KACA,MACA,UAAkB,KACR;AACV,aAAY,6BAA6B;AAAA,IACxC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AAEpD,YAAW,MAAM;AAEhB,QAAI,WAAW;AACf,QAAI;AACJ,QAAK,CAAE,IAAI,SAAU;AACpB;AAAA,IACD;AAEA,QAAI;AACJ,QAAK,OAAO,IAAI,YAAY,UAAW;AACtC,gBACC,OAAO,aAAa,cACjB,MAAM,KAAM,SAAS,iBAAkB,IAAI,OAAQ,CAAE,IACrD,CAAC;AAAA,IACN,WACC,YAAY,IAAI,WAChB,OAAO,IAAI,QAAQ,WAAW,UAC7B;AACD,gBAAU,MAAM,KAAM,IAAI,OAAQ;AAAA,IACnC,OAAO;AACN,gBAAU,CAAE,IAAI,OAAmB;AAAA,IACpC;AAEA,QAAK,QAAQ,WAAW,GAAI;AAC3B;AAAA,IACD;AAEA,UAAM,cAAc,OAAQ,UAAkB;AAC7C,YAAM,UAAU,MAAM;AACtB,UAAK,CAAE,SAAU;AAChB;AAAA,MACD;AACA,YAAM,UAAU,MAAM;AAAA,QACrB,OAAO,SAAS,aAAa,KAAK,IAAI,QAAQ;AAAA,QAC9C;AAAA,MACD;AACA,UAAK,CAAE,UAAW;AACjB;AAAA,MACD;AACA,UAAK,SAAU;AACd,qBAAc,OAAQ;AACtB,YAAK,SAAU;AACd,uBAAc,IAAK;AACnB,uBAAc,SAAU;AACxB,sBAAY;AAAA,YACX,MAAM,aAAc,KAAM;AAAA,YAC1B;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,IACD;AAEA,eAAY,UAAU,SAAU;AAC/B,aAAO,iBAAkB,SAAS,WAAY;AAAA,IAC/C;AACA,WAAO,MAAM;AACZ,iBAAW;AACX,iBAAY,UAAU,SAAU;AAC/B,eAAO,oBAAqB,SAAS,WAAY;AAAA,MAClD;AACA,mBAAc,SAAU;AAAA,IACzB;AAAA,EACD,GAAG,CAAE,KAAK,MAAM,OAAQ,CAAE;AAE1B,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -30,11 +30,10 @@ async function copyToClipboard(text, trigger) {
|
|
|
30
30
|
return false;
|
|
31
31
|
}
|
|
32
32
|
}
|
|
33
|
-
function
|
|
33
|
+
function restoreFocus(trigger) {
|
|
34
34
|
if ("focus" in trigger && typeof trigger.focus === "function") {
|
|
35
35
|
trigger.focus();
|
|
36
36
|
}
|
|
37
|
-
trigger.ownerDocument?.defaultView?.getSelection()?.removeAllRanges();
|
|
38
37
|
}
|
|
39
38
|
function useUpdatedRef(value) {
|
|
40
39
|
const ref = useRef(value);
|
|
@@ -51,11 +50,10 @@ function useCopyToClipboard(text, onSuccess) {
|
|
|
51
50
|
const handleClick = async () => {
|
|
52
51
|
const textToCopy = typeof textRef.current === "function" ? textRef.current() : textRef.current || "";
|
|
53
52
|
const success = await copyToClipboard(textToCopy, node);
|
|
54
|
-
if (!isActive) {
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
53
|
if (success) {
|
|
58
|
-
|
|
54
|
+
if (isActive) {
|
|
55
|
+
restoreFocus(node);
|
|
56
|
+
}
|
|
59
57
|
if (onSuccessRef.current) {
|
|
60
58
|
onSuccessRef.current();
|
|
61
59
|
}
|
|
@@ -69,8 +67,8 @@ function useCopyToClipboard(text, onSuccess) {
|
|
|
69
67
|
}, []);
|
|
70
68
|
}
|
|
71
69
|
export {
|
|
72
|
-
clearSelection,
|
|
73
70
|
copyToClipboard,
|
|
74
|
-
useCopyToClipboard as default
|
|
71
|
+
useCopyToClipboard as default,
|
|
72
|
+
restoreFocus
|
|
75
73
|
};
|
|
76
74
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
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 *
|
|
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,
|
|
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 * Restores focus to the trigger element.\n *\n * @param trigger The element that triggered the copy.\n */\nexport function restoreFocus( trigger: Element ): void {\n\tif ( 'focus' in trigger && typeof trigger.focus === 'function' ) {\n\t\ttrigger.focus();\n\t}\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// Tracks whether the node is still mounted 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 ( success ) {\n\t\t\t\t// Restoring focus only matters while the node is mounted.\n\t\t\t\tif ( isActive ) {\n\t\t\t\t\trestoreFocus( node );\n\t\t\t\t}\n\t\t\t\t// Always run, even after unmount, to allow updating other UI.\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,aAAc,SAAyB;AACtD,MAAK,WAAW,WAAW,OAAO,QAAQ,UAAU,YAAa;AAChE,YAAQ,MAAM;AAAA,EACf;AACD;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,SAAU;AAEd,YAAK,UAAW;AACf,uBAAc,IAAK;AAAA,QACpB;AAEA,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,6 +1,5 @@
|
|
|
1
1
|
// packages/compose/src/hooks/use-dialog/index.ts
|
|
2
2
|
import { useRef, useEffect, useCallback } from "@wordpress/element";
|
|
3
|
-
import { ESCAPE } from "@wordpress/keycodes";
|
|
4
3
|
import useConstrainedTabbing from "../use-constrained-tabbing/index.mjs";
|
|
5
4
|
import { useFocusOnMount } from "../use-focus-on-mount/index.mjs";
|
|
6
5
|
import useFocusReturn from "../use-focus-return/index.mjs";
|
|
@@ -22,27 +21,23 @@ function useDialog(options) {
|
|
|
22
21
|
currentOptions.current.onClose();
|
|
23
22
|
}
|
|
24
23
|
});
|
|
25
|
-
const
|
|
26
|
-
|
|
27
|
-
|
|
24
|
+
const onKeyDown = useCallback((event) => {
|
|
25
|
+
currentOptions.current?.onKeyDown?.(event);
|
|
26
|
+
if (event.key === "Escape" && !event.defaultPrevented && currentOptions.current?.onClose) {
|
|
27
|
+
event.preventDefault();
|
|
28
|
+
event.stopPropagation();
|
|
29
|
+
currentOptions.current.onClose();
|
|
28
30
|
}
|
|
29
|
-
node.addEventListener("keydown", (event) => {
|
|
30
|
-
if (event.keyCode === ESCAPE && !event.defaultPrevented && currentOptions.current?.onClose) {
|
|
31
|
-
event.preventDefault();
|
|
32
|
-
event.stopPropagation();
|
|
33
|
-
currentOptions.current.onClose();
|
|
34
|
-
}
|
|
35
|
-
});
|
|
36
31
|
}, []);
|
|
37
32
|
return [
|
|
38
33
|
useMergeRefs([
|
|
39
34
|
constrainTabbing ? constrainedTabbingRef : null,
|
|
40
35
|
options.focusOnMount !== false ? focusReturnRef : null,
|
|
41
|
-
options.focusOnMount !== false ? focusOnMountRef : null
|
|
42
|
-
closeOnEscapeRef
|
|
36
|
+
options.focusOnMount !== false ? focusOnMountRef : null
|
|
43
37
|
]),
|
|
44
38
|
{
|
|
45
39
|
...focusOutsideProps,
|
|
40
|
+
onKeyDown,
|
|
46
41
|
tabIndex: -1
|
|
47
42
|
}
|
|
48
43
|
];
|
|
@@ -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 {
|
|
5
|
-
"mappings": ";
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type {\n\tKeyboardEvent,\n\tKeyboardEventHandler,\n\tRefCallback,\n\tSyntheticEvent,\n} from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\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 * Optional `onKeyDown` handler, merged with the built-in one.\n\t */\n\tonKeyDown?: KeyboardEventHandler< HTMLElement >;\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 > & {\n\t\tonKeyDown: ( event: KeyboardEvent< HTMLElement > ) => void;\n\t} & 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\t// Close on Escape via a React `onKeyDown` (rather than a native listener)\n\t// so portaled descendants that handle Escape and call\n\t// `event.stopPropagation()` correctly prevent the dialog from closing.\n\t// See https://github.com/WordPress/gutenberg/issues/78432.\n\tconst onKeyDown = useCallback( ( event: KeyboardEvent< HTMLElement > ) => {\n\t\t// Let the consumer-provided handler (if any) run first so it can\n\t\t// call `preventDefault()` to opt out of close-on-Escape.\n\t\tcurrentOptions.current?.onKeyDown?.( event );\n\t\tif (\n\t\t\tevent.key === 'Escape' &&\n\t\t\t! event.defaultPrevented &&\n\t\t\tcurrentOptions.current?.onClose\n\t\t) {\n\t\t\tevent.preventDefault();\n\t\t\tevent.stopPropagation();\n\t\t\tcurrentOptions.current.onClose();\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] ),\n\t\t{\n\t\t\t...focusOutsideProps,\n\t\t\tonKeyDown,\n\t\t\ttabIndex: -1,\n\t\t},\n\t];\n}\n\nexport default useDialog;\n"],
|
|
5
|
+
"mappings": ";AAaA,SAAS,QAAQ,WAAW,mBAAmB;AAK/C,OAAO,2BAA2B;AAClC,SAAS,uBAAuB;AAChC,OAAO,oBAAoB;AAC3B,OAAO,qBAAqB;AAC5B,OAAO,kBAAkB;AA0DzB,SAAS,UAAW,SAA0C;AAC7D,QAAM,iBAAiB,OAAyB,MAAU;AAC1D,QAAM,EAAE,mBAAmB,QAAQ,iBAAiB,MAAM,IAAI;AAC9D,YAAW,MAAM;AAChB,mBAAe,UAAU;AAAA,EAC1B,GAAG,OAAO,OAAQ,OAAQ,CAAE;AAC5B,QAAM,wBAAwB,sBAAsB;AACpD,QAAM,kBAAkB,gBAAiB,QAAQ,YAAa;AAC9D,QAAM,iBAAiB,eAAe;AACtC,QAAM,oBAAoB,gBAAiB,CAAE,UAAW;AAGvD,QAAK,eAAe,SAAS,mBAAoB;AAChD,qBAAe,QAAQ,kBAAmB,iBAAiB,KAAM;AAAA,IAClE,WAAY,eAAe,SAAS,SAAU;AAC7C,qBAAe,QAAQ,QAAQ;AAAA,IAChC;AAAA,EACD,CAAE;AAKF,QAAM,YAAY,YAAa,CAAE,UAAyC;AAGzE,mBAAe,SAAS,YAAa,KAAM;AAC3C,QACC,MAAM,QAAQ,YACd,CAAE,MAAM,oBACR,eAAe,SAAS,SACvB;AACD,YAAM,eAAe;AACrB,YAAM,gBAAgB;AACtB,qBAAe,QAAQ,QAAQ;AAAA,IAChC;AAAA,EACD,GAAG,CAAC,CAAE;AAEN,SAAO;AAAA,IACN,aAAc;AAAA,MACb,mBAAmB,wBAAwB;AAAA,MAC3C,QAAQ,iBAAiB,QAAQ,iBAAiB;AAAA,MAClD,QAAQ,iBAAiB,QAAQ,kBAAkB;AAAA,IACpD,CAAE;AAAA,IACF;AAAA,MACC,GAAG;AAAA,MACH;AAAA,MACA,UAAU;AAAA,IACX;AAAA,EACD;AACD;AAEA,IAAO,qBAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,47 +1,53 @@
|
|
|
1
1
|
// packages/compose/src/hooks/use-media-query/index.ts
|
|
2
|
-
import {
|
|
2
|
+
import { useSyncExternalStore } from "@wordpress/element";
|
|
3
3
|
var perWindowCache = /* @__PURE__ */ new WeakMap();
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
4
|
+
var EMPTY_SUBSCRIBER = {
|
|
5
|
+
subscribe: () => () => {
|
|
6
|
+
},
|
|
7
|
+
getValue: () => false
|
|
8
|
+
};
|
|
9
|
+
function getMQLSubscriber(view, query) {
|
|
10
|
+
if (!query || typeof view?.matchMedia !== "function") {
|
|
11
|
+
return EMPTY_SUBSCRIBER;
|
|
11
12
|
}
|
|
12
|
-
let
|
|
13
|
-
if (
|
|
14
|
-
|
|
13
|
+
let queryCache = perWindowCache.get(view);
|
|
14
|
+
if (!queryCache) {
|
|
15
|
+
queryCache = /* @__PURE__ */ new Map();
|
|
16
|
+
perWindowCache.set(view, queryCache);
|
|
15
17
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
return match;
|
|
18
|
+
const cached = queryCache.get(query);
|
|
19
|
+
if (cached) {
|
|
20
|
+
return cached;
|
|
20
21
|
}
|
|
21
|
-
|
|
22
|
+
const mediaQueryList = view.matchMedia(query);
|
|
23
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
24
|
+
const notify = () => {
|
|
25
|
+
for (const listener of listeners) {
|
|
26
|
+
listener();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
const subscriber = {
|
|
30
|
+
subscribe(onStoreChange) {
|
|
31
|
+
if (listeners.size === 0) {
|
|
32
|
+
mediaQueryList.addEventListener?.("change", notify);
|
|
33
|
+
}
|
|
34
|
+
listeners.add(onStoreChange);
|
|
35
|
+
return () => {
|
|
36
|
+
listeners.delete(onStoreChange);
|
|
37
|
+
if (listeners.size === 0) {
|
|
38
|
+
mediaQueryList.removeEventListener?.("change", notify);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
41
|
+
},
|
|
42
|
+
getValue() {
|
|
43
|
+
return mediaQueryList.matches;
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
queryCache.set(query, subscriber);
|
|
47
|
+
return subscriber;
|
|
22
48
|
}
|
|
23
49
|
function useMediaQuery(query, view = window) {
|
|
24
|
-
const source =
|
|
25
|
-
const mediaQueryList = getMediaQueryList(view, query);
|
|
26
|
-
return {
|
|
27
|
-
subscribe(onStoreChange) {
|
|
28
|
-
if (!mediaQueryList) {
|
|
29
|
-
return () => {
|
|
30
|
-
};
|
|
31
|
-
}
|
|
32
|
-
mediaQueryList.addEventListener?.("change", onStoreChange);
|
|
33
|
-
return () => {
|
|
34
|
-
mediaQueryList.removeEventListener?.(
|
|
35
|
-
"change",
|
|
36
|
-
onStoreChange
|
|
37
|
-
);
|
|
38
|
-
};
|
|
39
|
-
},
|
|
40
|
-
getValue() {
|
|
41
|
-
return mediaQueryList?.matches ?? false;
|
|
42
|
-
}
|
|
43
|
-
};
|
|
44
|
-
}, [view, query]);
|
|
50
|
+
const source = getMQLSubscriber(view, query);
|
|
45
51
|
return useSyncExternalStore(
|
|
46
52
|
source.subscribe,
|
|
47
53
|
source.getValue,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/use-media-query/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport {
|
|
5
|
-
"mappings": ";AAGA,SAAS,
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useSyncExternalStore } from '@wordpress/element';\n\ntype MQLSubscriber = {\n\tsubscribe: ( onStoreChange: () => void ) => () => void;\n\tgetValue: () => boolean;\n};\n\n// One subscriber per (window, query). The underlying MediaQueryList lives\n// inside the subscriber's closure; a single `change` listener fans out to\n// every React consumer via an in-JS `Set` to avoid the per-consumer\n// `addEventListener` cost (~85 ms during a large-post editor mount).\nconst perWindowCache = new WeakMap< Window, Map< string, MQLSubscriber > >();\n\nconst EMPTY_SUBSCRIBER: MQLSubscriber = {\n\tsubscribe: () => () => {},\n\tgetValue: () => false,\n};\n\nfunction getMQLSubscriber( view: Window, query?: string ): MQLSubscriber {\n\tif ( ! query || typeof view?.matchMedia !== 'function' ) {\n\t\treturn EMPTY_SUBSCRIBER;\n\t}\n\n\tlet queryCache = perWindowCache.get( view );\n\tif ( ! queryCache ) {\n\t\tqueryCache = new Map();\n\t\tperWindowCache.set( view, queryCache );\n\t}\n\n\tconst cached = queryCache.get( query );\n\tif ( cached ) {\n\t\treturn cached;\n\t}\n\n\tconst mediaQueryList = view.matchMedia( query );\n\tconst listeners = new Set< () => void >();\n\tconst notify = () => {\n\t\tfor ( const listener of listeners ) {\n\t\t\tlistener();\n\t\t}\n\t};\n\n\tconst subscriber: MQLSubscriber = {\n\t\tsubscribe( onStoreChange ) {\n\t\t\tif ( listeners.size === 0 ) {\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', notify );\n\t\t\t}\n\t\t\tlisteners.add( onStoreChange );\n\t\t\treturn () => {\n\t\t\t\tlisteners.delete( onStoreChange );\n\t\t\t\tif ( listeners.size === 0 ) {\n\t\t\t\t\tmediaQueryList.removeEventListener?.( 'change', notify );\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t\tgetValue() {\n\t\t\treturn mediaQueryList.matches;\n\t\t},\n\t};\n\n\tqueryCache.set( query, subscriber );\n\treturn subscriber;\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 = getMQLSubscriber( 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,4BAA4B;AAWrC,IAAM,iBAAiB,oBAAI,QAAgD;AAE3E,IAAM,mBAAkC;AAAA,EACvC,WAAW,MAAM,MAAM;AAAA,EAAC;AAAA,EACxB,UAAU,MAAM;AACjB;AAEA,SAAS,iBAAkB,MAAc,OAAgC;AACxE,MAAK,CAAE,SAAS,OAAO,MAAM,eAAe,YAAa;AACxD,WAAO;AAAA,EACR;AAEA,MAAI,aAAa,eAAe,IAAK,IAAK;AAC1C,MAAK,CAAE,YAAa;AACnB,iBAAa,oBAAI,IAAI;AACrB,mBAAe,IAAK,MAAM,UAAW;AAAA,EACtC;AAEA,QAAM,SAAS,WAAW,IAAK,KAAM;AACrC,MAAK,QAAS;AACb,WAAO;AAAA,EACR;AAEA,QAAM,iBAAiB,KAAK,WAAY,KAAM;AAC9C,QAAM,YAAY,oBAAI,IAAkB;AACxC,QAAM,SAAS,MAAM;AACpB,eAAY,YAAY,WAAY;AACnC,eAAS;AAAA,IACV;AAAA,EACD;AAEA,QAAM,aAA4B;AAAA,IACjC,UAAW,eAAgB;AAC1B,UAAK,UAAU,SAAS,GAAI;AAE3B,uBAAe,mBAAoB,UAAU,MAAO;AAAA,MACrD;AACA,gBAAU,IAAK,aAAc;AAC7B,aAAO,MAAM;AACZ,kBAAU,OAAQ,aAAc;AAChC,YAAK,UAAU,SAAS,GAAI;AAC3B,yBAAe,sBAAuB,UAAU,MAAO;AAAA,QACxD;AAAA,MACD;AAAA,IACD;AAAA,IACA,WAAW;AACV,aAAO,eAAe;AAAA,IACvB;AAAA,EACD;AAEA,aAAW,IAAK,OAAO,UAAW;AAClC,SAAO;AACR;AASe,SAAR,cACN,OACA,OAAe,QACL;AACV,QAAM,SAAS,iBAAkB,MAAM,KAAM;AAE7C,SAAO;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,MAAM;AAAA,EACP;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/build-module/index.mjs
CHANGED
|
@@ -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 './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,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;",
|
|
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// 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,IAAK,MAAM,OAAQ;AAAA,EAC/B;AACA,QAAM,MAAM,UAAU,GAAI,SAAU,aAAa;AACjD,MAAI,WAAW,QAAQ,IAAK,GAAI;AAChC,MAAK,CAAE,UAAW;AACjB,eAAW,oBAAI,QAA6C;AAC5D,YAAQ,IAAK,KAAK,QAAS;AAC3B,UAAM,cAAc;AACpB,SAAK;AAAA,MACJ;AAAA,MACA,CAAE,UAAW;AACZ,YAAK,UAAW;AAGf,gBAAMA,OAAM,YAAY,IAAK,IAAK;AAClC,cAAKA,MAAM;AACV,uBAAY,MAAMA,MAAM;AACvB,iBAAI,KAAM;AAAA,YACX;AAAA,UACD;AACA;AAAA,QACD;AAKA,YAAK,SAAU;AACd,gBAAM,OAAiC,CAAC;AACxC,cAAI,UAAuB,MAAM;AACjC,iBAAQ,SAAU;AACjB,iBAAK,KAAM,OAAQ;AACnB,gBAAK,YAAY,MAAO;AACvB;AAAA,YACD;AACA,sBAAU,QAAQ;AAAA,UACnB;AACA,mBAAU,IAAI,KAAK,SAAS,GAAG,KAAK,GAAG,KAAM;AAC5C,kBAAMA,OAAM,YAAY,IAAK,KAAM,CAAE,CAAE;AACvC,gBAAKA,MAAM;AACV,yBAAY,MAAMA,MAAM;AACvB,mBAAI,KAAM;AAAA,cACX;AAAA,YACD;AAAA,UACD;AAAA,QACD,OAAO;AACN,cAAI,UAAuB,MAAM;AACjC,iBAAQ,SAAU;AACjB,kBAAMA,OAAM,YAAY,IAAK,OAAQ;AACrC,gBAAKA,MAAM;AACV,yBAAY,MAAMA,MAAM;AACvB,mBAAI,KAAM;AAAA,cACX;AAAA,YACD;AACA,gBAAK,YAAY,MAAO;AACvB;AAAA,YACD;AACA,sBAAU,QAAQ;AAAA,UACnB;AAAA,QACD;AAAA,MACD;AAAA,MACA;AAAA,IACD;AAAA,EACD;AACA,MAAI,MAAM,SAAS,IAAK,MAAO;AAC/B,MAAK,CAAE,KAAM;AACZ,UAAM,oBAAI,IAAI;AACd,aAAS,IAAK,QAAQ,GAAI;AAAA,EAC3B;AACA,MAAI,IAAK,QAAS;AAClB,SAAO,MAAM;AACZ,QAAI,OAAQ,QAAS;AAAA,EACtB;AACD;",
|
|
6
|
+
"names": ["set"]
|
|
7
|
+
}
|
|
@@ -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
|
-
*
|
|
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
|
|
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,
|
|
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> &
|
|
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,
|
|
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":"
|
|
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"}
|
package/build-types/index.d.ts
CHANGED
|
@@ -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';
|