@wordpress/compose 8.1.1 → 8.1.2-next.v.202606191442.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +42 -38
- package/build/hooks/use-constrained-tabbing/index.cjs +3 -9
- package/build/hooks/use-constrained-tabbing/index.cjs.map +3 -3
- package/build/hooks/use-debounce/index.cjs +1 -1
- package/build/hooks/use-debounce/index.cjs.map +3 -3
- package/build/hooks/use-disabled/index.cjs.map +2 -2
- package/build/hooks/use-dragging/index.cjs +27 -22
- package/build/hooks/use-dragging/index.cjs.map +4 -4
- package/build/hooks/use-dragging/types.cjs +19 -0
- package/build/hooks/use-dragging/types.cjs.map +7 -0
- package/build/hooks/use-drop-zone/index.cjs +2 -5
- package/build/hooks/use-drop-zone/index.cjs.map +3 -3
- package/build/hooks/use-drop-zone/types.cjs +19 -0
- package/build/hooks/use-drop-zone/types.cjs.map +7 -0
- package/build/hooks/use-fixed-window-list/index.cjs +10 -8
- package/build/hooks/use-fixed-window-list/index.cjs.map +3 -3
- package/build/hooks/use-focus-return/index.cjs +12 -9
- package/build/hooks/use-focus-return/index.cjs.map +3 -3
- package/build/hooks/use-isomorphic-layout-effect/index.cjs +1 -1
- package/build/hooks/use-isomorphic-layout-effect/index.cjs.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.cjs +1 -4
- package/build/hooks/use-keyboard-shortcut/index.cjs.map +3 -3
- package/build/hooks/use-reduced-motion/index.cjs +1 -1
- package/build/hooks/use-reduced-motion/index.cjs.map +2 -2
- package/build/hooks/use-throttle/index.cjs +1 -1
- package/build/hooks/use-throttle/index.cjs.map +3 -3
- package/build/hooks/use-viewport-match/index.cjs +2 -5
- package/build/hooks/use-viewport-match/index.cjs.map +3 -3
- package/build/hooks/use-warn-on-change/index.cjs +3 -10
- package/build/hooks/use-warn-on-change/index.cjs.map +3 -3
- package/build/utils/subscribe-delegated-listener/index.cjs.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.mjs +3 -9
- package/build-module/hooks/use-constrained-tabbing/index.mjs.map +3 -3
- package/build-module/hooks/use-debounce/index.mjs +1 -1
- package/build-module/hooks/use-debounce/index.mjs.map +3 -3
- package/build-module/hooks/use-disabled/index.mjs.map +2 -2
- package/build-module/hooks/use-dragging/index.mjs +27 -22
- package/build-module/hooks/use-dragging/index.mjs.map +4 -4
- package/build-module/hooks/use-dragging/types.mjs +1 -0
- package/build-module/hooks/use-dragging/types.mjs.map +7 -0
- package/build-module/hooks/use-drop-zone/index.mjs +2 -5
- package/build-module/hooks/use-drop-zone/index.mjs.map +3 -3
- package/build-module/hooks/use-drop-zone/types.mjs +1 -0
- package/build-module/hooks/use-drop-zone/types.mjs.map +7 -0
- package/build-module/hooks/use-fixed-window-list/index.mjs +10 -8
- package/build-module/hooks/use-fixed-window-list/index.mjs.map +3 -3
- package/build-module/hooks/use-focus-return/index.mjs +12 -9
- package/build-module/hooks/use-focus-return/index.mjs.map +3 -3
- package/build-module/hooks/use-isomorphic-layout-effect/index.mjs +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.mjs.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.mjs +1 -4
- package/build-module/hooks/use-keyboard-shortcut/index.mjs.map +3 -3
- package/build-module/hooks/use-reduced-motion/index.mjs +1 -1
- package/build-module/hooks/use-reduced-motion/index.mjs.map +2 -2
- package/build-module/hooks/use-throttle/index.mjs +1 -1
- package/build-module/hooks/use-throttle/index.mjs.map +3 -3
- package/build-module/hooks/use-viewport-match/index.mjs +2 -5
- package/build-module/hooks/use-viewport-match/index.mjs.map +3 -3
- package/build-module/hooks/use-warn-on-change/index.mjs +3 -10
- package/build-module/hooks/use-warn-on-change/index.mjs.map +3 -3
- package/build-module/utils/subscribe-delegated-listener/index.mjs.map +1 -1
- package/build-types/hooks/use-constrained-tabbing/index.d.ts +2 -2
- package/build-types/hooks/use-constrained-tabbing/index.d.ts.map +1 -1
- package/build-types/hooks/use-debounce/index.d.ts +7 -6
- package/build-types/hooks/use-debounce/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +1 -1
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-dragging/index.d.ts +9 -13
- package/build-types/hooks/use-dragging/index.d.ts.map +1 -1
- package/build-types/hooks/use-dragging/types.d.ts +11 -0
- package/build-types/hooks/use-dragging/types.d.ts.map +1 -0
- package/build-types/hooks/use-drop-zone/index.d.ts +4 -21
- package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
- package/build-types/hooks/use-drop-zone/types.d.ts +35 -0
- package/build-types/hooks/use-drop-zone/types.d.ts.map +1 -0
- package/build-types/hooks/use-fixed-window-list/index.d.ts +22 -26
- package/build-types/hooks/use-fixed-window-list/index.d.ts.map +1 -1
- package/build-types/hooks/use-focus-return/index.d.ts +3 -3
- package/build-types/hooks/use-focus-return/index.d.ts.map +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts +29 -23
- package/build-types/hooks/use-keyboard-shortcut/index.d.ts.map +1 -1
- package/build-types/hooks/use-reduced-motion/index.d.ts +1 -1
- package/build-types/hooks/use-reduced-motion/index.d.ts.map +1 -1
- package/build-types/hooks/use-throttle/index.d.ts +8 -6
- package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
- package/build-types/hooks/use-viewport-match/index.d.ts +3 -3
- package/build-types/hooks/use-viewport-match/index.d.ts.map +1 -1
- package/build-types/hooks/use-warn-on-change/index.d.ts +7 -7
- package/build-types/hooks/use-warn-on-change/index.d.ts.map +1 -1
- package/package.json +16 -11
- package/src/hooks/use-constrained-tabbing/{index.js → index.ts} +7 -11
- package/src/hooks/use-debounce/{index.js → index.ts} +11 -6
- package/src/hooks/use-disabled/index.ts +3 -1
- package/src/hooks/use-dragging/index.ts +78 -0
- package/src/hooks/use-dragging/types.ts +11 -0
- package/src/hooks/use-drop-zone/{index.js → index.ts} +17 -31
- package/src/hooks/use-drop-zone/types.ts +34 -0
- package/src/hooks/use-fixed-window-list/{index.js → index.ts} +46 -37
- package/src/hooks/use-focus-return/{index.js → index.ts} +26 -21
- package/src/hooks/use-keyboard-shortcut/{index.js → index.ts} +43 -28
- package/src/hooks/use-reduced-motion/{index.js → index.ts} +2 -2
- package/src/hooks/use-throttle/{index.js → index.ts} +12 -6
- package/src/hooks/use-viewport-match/{index.js → index.ts} +30 -29
- package/src/hooks/use-warn-on-change/index.ts +42 -0
- package/src/hooks/use-dragging/index.js +0 -74
- package/src/hooks/use-warn-on-change/index.js +0 -43
- /package/src/hooks/use-isomorphic-layout-effect/{index.js → index.ts} +0 -0
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// packages/compose/src/hooks/use-focus-return/index.
|
|
20
|
+
// packages/compose/src/hooks/use-focus-return/index.ts
|
|
21
21
|
var use_focus_return_exports = {};
|
|
22
22
|
__export(use_focus_return_exports, {
|
|
23
23
|
default: () => use_focus_return_default
|
|
@@ -27,31 +27,34 @@ var import_element = require("@wordpress/element");
|
|
|
27
27
|
var origin = null;
|
|
28
28
|
function useFocusReturn(onFocusReturn) {
|
|
29
29
|
const ref = (0, import_element.useRef)(null);
|
|
30
|
-
const
|
|
31
|
-
const onFocusReturnRef = (0, import_element.useRef)(
|
|
30
|
+
const focusedBeforeMountRef = (0, import_element.useRef)(null);
|
|
31
|
+
const onFocusReturnRef = (0, import_element.useRef)(
|
|
32
|
+
onFocusReturn
|
|
33
|
+
);
|
|
32
34
|
(0, import_element.useEffect)(() => {
|
|
33
35
|
onFocusReturnRef.current = onFocusReturn;
|
|
34
36
|
}, [onFocusReturn]);
|
|
35
37
|
return (0, import_element.useCallback)((node) => {
|
|
36
38
|
if (node) {
|
|
37
39
|
ref.current = node;
|
|
38
|
-
if (
|
|
40
|
+
if (focusedBeforeMountRef.current) {
|
|
39
41
|
return;
|
|
40
42
|
}
|
|
41
43
|
const activeDocument = node.ownerDocument.activeElement instanceof window.HTMLIFrameElement ? node.ownerDocument.activeElement.contentDocument : node.ownerDocument;
|
|
42
|
-
|
|
43
|
-
} else if (
|
|
44
|
+
focusedBeforeMountRef.current = activeDocument?.activeElement ?? null;
|
|
45
|
+
} else if (focusedBeforeMountRef.current) {
|
|
44
46
|
const isFocused = ref.current?.contains(
|
|
45
|
-
ref.current?.ownerDocument.activeElement
|
|
47
|
+
ref.current?.ownerDocument.activeElement ?? null
|
|
46
48
|
);
|
|
47
49
|
if (ref.current?.isConnected && !isFocused) {
|
|
48
|
-
origin ??=
|
|
50
|
+
origin ??= focusedBeforeMountRef.current;
|
|
49
51
|
return;
|
|
50
52
|
}
|
|
51
53
|
if (onFocusReturnRef.current) {
|
|
52
54
|
onFocusReturnRef.current();
|
|
53
55
|
} else {
|
|
54
|
-
|
|
56
|
+
const elementToFocus = !focusedBeforeMountRef.current.isConnected ? origin : focusedBeforeMountRef.current;
|
|
57
|
+
elementToFocus?.focus();
|
|
55
58
|
}
|
|
56
59
|
origin = null;
|
|
57
60
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-focus-return/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;
|
|
3
|
+
"sources": ["../../../src/hooks/use-focus-return/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\n\nlet origin: Element | null = null;\n\n/**\n * Adds the unmount behavior of returning focus to the element which had it\n * previously as is expected for roles like menus or dialogs.\n *\n * @param onFocusReturn Overrides the default return behavior.\n * @return Element Ref.\n *\n * @example\n * ```ts\n * import { useFocusReturn } from '@wordpress/compose';\n *\n * const WithFocusReturn = () => {\n * const ref = useFocusReturn()\n * return (\n * <div ref={ ref }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useFocusReturn(\n\tonFocusReturn?: () => void\n): React.RefCallback< HTMLElement > {\n\tconst ref = useRef< HTMLElement | null >( null );\n\tconst focusedBeforeMountRef = useRef< Element | null >( null );\n\tconst onFocusReturnRef = useRef< ( () => void ) | undefined >(\n\t\tonFocusReturn\n\t);\n\n\tuseEffect( () => {\n\t\tonFocusReturnRef.current = onFocusReturn;\n\t}, [ onFocusReturn ] );\n\n\treturn useCallback( ( node: HTMLElement | null ) => {\n\t\tif ( node ) {\n\t\t\t// Set ref to be used when unmounting.\n\t\t\tref.current = node;\n\n\t\t\t// Only set when the node mounts.\n\t\t\tif ( focusedBeforeMountRef.current ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst activeDocument =\n\t\t\t\tnode.ownerDocument.activeElement instanceof\n\t\t\t\twindow.HTMLIFrameElement\n\t\t\t\t\t? node.ownerDocument.activeElement.contentDocument\n\t\t\t\t\t: node.ownerDocument;\n\n\t\t\tfocusedBeforeMountRef.current =\n\t\t\t\tactiveDocument?.activeElement ?? null;\n\t\t} else if ( focusedBeforeMountRef.current ) {\n\t\t\tconst isFocused = ref.current?.contains(\n\t\t\t\tref.current?.ownerDocument.activeElement ?? null\n\t\t\t);\n\n\t\t\tif ( ref.current?.isConnected && ! isFocused ) {\n\t\t\t\torigin ??= focusedBeforeMountRef.current;\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// Defer to the component's own explicit focus return behavior, if\n\t\t\t// specified. This allows for support that the `onFocusReturn`\n\t\t\t// decides to allow the default behavior to occur under some\n\t\t\t// conditions.\n\t\t\tif ( onFocusReturnRef.current ) {\n\t\t\t\tonFocusReturnRef.current();\n\t\t\t} else {\n\t\t\t\tconst elementToFocus = (\n\t\t\t\t\t! focusedBeforeMountRef.current.isConnected\n\t\t\t\t\t\t? origin\n\t\t\t\t\t\t: focusedBeforeMountRef.current\n\t\t\t\t) as HTMLElement | SVGElement | null;\n\n\t\t\t\telementToFocus?.focus();\n\t\t\t}\n\t\t\torigin = null;\n\t\t}\n\t}, [] );\n}\n\nexport default useFocusReturn;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAE/C,IAAI,SAAyB;AAwB7B,SAAS,eACR,eACmC;AACnC,QAAM,UAAM,uBAA8B,IAAK;AAC/C,QAAM,4BAAwB,uBAA0B,IAAK;AAC7D,QAAM,uBAAmB;AAAA,IACxB;AAAA,EACD;AAEA,gCAAW,MAAM;AAChB,qBAAiB,UAAU;AAAA,EAC5B,GAAG,CAAE,aAAc,CAAE;AAErB,aAAO,4BAAa,CAAE,SAA8B;AACnD,QAAK,MAAO;AAEX,UAAI,UAAU;AAGd,UAAK,sBAAsB,SAAU;AACpC;AAAA,MACD;AAEA,YAAM,iBACL,KAAK,cAAc,yBACnB,OAAO,oBACJ,KAAK,cAAc,cAAc,kBACjC,KAAK;AAET,4BAAsB,UACrB,gBAAgB,iBAAiB;AAAA,IACnC,WAAY,sBAAsB,SAAU;AAC3C,YAAM,YAAY,IAAI,SAAS;AAAA,QAC9B,IAAI,SAAS,cAAc,iBAAiB;AAAA,MAC7C;AAEA,UAAK,IAAI,SAAS,eAAe,CAAE,WAAY;AAC9C,mBAAW,sBAAsB;AACjC;AAAA,MACD;AAMA,UAAK,iBAAiB,SAAU;AAC/B,yBAAiB,QAAQ;AAAA,MAC1B,OAAO;AACN,cAAM,iBACL,CAAE,sBAAsB,QAAQ,cAC7B,SACA,sBAAsB;AAG1B,wBAAgB,MAAM;AAAA,MACvB;AACA,eAAS;AAAA,IACV;AAAA,EACD,GAAG,CAAC,CAAE;AACP;AAEA,IAAO,2BAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// packages/compose/src/hooks/use-isomorphic-layout-effect/index.
|
|
20
|
+
// packages/compose/src/hooks/use-isomorphic-layout-effect/index.ts
|
|
21
21
|
var use_isomorphic_layout_effect_exports = {};
|
|
22
22
|
__export(use_isomorphic_layout_effect_exports, {
|
|
23
23
|
default: () => use_isomorphic_layout_effect_default
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-isomorphic-layout-effect/index.
|
|
3
|
+
"sources": ["../../../src/hooks/use-isomorphic-layout-effect/index.ts"],
|
|
4
4
|
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useEffect, useLayoutEffect } from '@wordpress/element';\n\n/**\n * Preferred over direct usage of `useLayoutEffect` when supporting\n * server rendered components (SSR) because currently React\n * throws a warning when using useLayoutEffect in that environment.\n */\nconst useIsomorphicLayoutEffect =\n\ttypeof window !== 'undefined' ? useLayoutEffect : useEffect;\n\nexport default useIsomorphicLayoutEffect;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA2C;AAO3C,IAAM,4BACL,OAAO,WAAW,cAAc,iCAAkB;AAEnD,IAAO,uCAAQ;",
|
|
6
6
|
"names": []
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/compose/src/hooks/use-keyboard-shortcut/index.
|
|
30
|
+
// packages/compose/src/hooks/use-keyboard-shortcut/index.ts
|
|
31
31
|
var use_keyboard_shortcut_exports = {};
|
|
32
32
|
__export(use_keyboard_shortcut_exports, {
|
|
33
33
|
default: () => use_keyboard_shortcut_default
|
|
@@ -41,7 +41,6 @@ function useKeyboardShortcut(shortcuts, callback, {
|
|
|
41
41
|
bindGlobal = false,
|
|
42
42
|
eventName = "keydown",
|
|
43
43
|
isDisabled = false,
|
|
44
|
-
// This is important for performance considerations.
|
|
45
44
|
target
|
|
46
45
|
} = {}) {
|
|
47
46
|
const currentCallbackRef = (0, import_element.useRef)(callback);
|
|
@@ -57,8 +56,6 @@ function useKeyboardShortcut(shortcuts, callback, {
|
|
|
57
56
|
// We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
|
|
58
57
|
// Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's
|
|
59
58
|
// necessary to maintain the existing behavior.
|
|
60
|
-
/** @type {Element} */
|
|
61
|
-
/** @type {unknown} */
|
|
62
59
|
document
|
|
63
60
|
)
|
|
64
61
|
);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-keyboard-shortcut/index.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport Mousetrap from 'mousetrap';\nimport 'mousetrap/plugins/global-bind/mousetrap-global-bind.js';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAsB;AACtB,mCAAO;
|
|
3
|
+
"sources": ["../../../src/hooks/use-keyboard-shortcut/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport Mousetrap from 'mousetrap';\nimport 'mousetrap/plugins/global-bind/mousetrap-global-bind.js';\nimport type { ExtendedKeyboardEvent } from 'mousetrap';\n\n/**\n * WordPress dependencies\n */\nimport type { RefObject } from '@wordpress/element';\nimport { useEffect, useRef } from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\ntype KeyboardShortcutConfig = {\n\t/**\n\t * Handle keyboard events anywhere including inside textarea/input fields.\n\t */\n\tbindGlobal: boolean;\n\t/**\n\t * Event name used to trigger the handler, defaults to keydown.\n\t */\n\teventName: string;\n\t/**\n\t * Disables the keyboard handler if the value is true.\n\t */\n\tisDisabled: boolean;\n\t/**\n\t * React reference to the DOM element used to catch the keyboard event.\n\t */\n\ttarget: RefObject< HTMLElement >;\n};\n\n/**\n * Attach a keyboard shortcut handler.\n *\n * @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.\n *\n * @param shortcuts Keyboard Shortcuts.\n * @param callback Shortcut callback.\n * @param options Shortcut options.\n * @param options.bindGlobal\n * @param options.eventName\n * @param options.isDisabled\n * @param options.target\n */\nfunction useKeyboardShortcut(\n\tshortcuts: string[] | string,\n\tcallback: ( e: ExtendedKeyboardEvent, combo: string ) => void,\n\t{\n\t\tbindGlobal = false,\n\t\teventName = 'keydown',\n\t\tisDisabled = false,\n\t\ttarget,\n\t}: Partial< KeyboardShortcutConfig > = {}\n) {\n\tconst currentCallbackRef = useRef( callback );\n\n\tuseEffect( () => {\n\t\tcurrentCallbackRef.current = callback;\n\t}, [ callback ] );\n\n\tuseEffect( () => {\n\t\tif ( isDisabled ) {\n\t\t\treturn;\n\t\t}\n\n\t\tconst mousetrap = new Mousetrap(\n\t\t\ttarget && target.current\n\t\t\t\t? target.current\n\t\t\t\t: // We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.\n\t\t\t\t // Not sure if this is a mistake but it was the behavior previous to the addition of types so we're just doing what's\n\t\t\t\t // necessary to maintain the existing behavior.\n\t\t\t\t ( document as unknown as Element )\n\t\t);\n\n\t\tconst shortcutsArray = Array.isArray( shortcuts )\n\t\t\t? shortcuts\n\t\t\t: [ shortcuts ];\n\n\t\tshortcutsArray.forEach( ( shortcut: string ) => {\n\t\t\tconst keys = shortcut.split( '+' );\n\t\t\tconst modifiers = new Set(\n\t\t\t\tkeys.filter( ( value ) => value.length > 1 )\n\t\t\t);\n\t\t\tconst hasAlt = modifiers.has( 'alt' );\n\t\t\tconst hasShift = modifiers.has( 'shift' );\n\n\t\t\tif (\n\t\t\t\tisAppleOS() &&\n\t\t\t\t( ( modifiers.size === 1 && hasAlt ) ||\n\t\t\t\t\t( modifiers.size === 2 && hasAlt && hasShift ) )\n\t\t\t) {\n\t\t\t\tthrow new Error(\n\t\t\t\t\t`Cannot bind ${ shortcut }. Alt and Shift+Alt modifiers are reserved for character input.`\n\t\t\t\t);\n\t\t\t}\n\n\t\t\tconst bindFn = bindGlobal ? 'bindGlobal' : 'bind';\n\t\t\t// `@ts-expect-error` Mousetrap typings don’t include `bindGlobal`\n\t\t\t// It exists at runtime via the plugin\n\t\t\t// `any` is used here to allow dynamic access via `bindFn`\n\t\t\t( mousetrap as any )[ bindFn ](\n\t\t\t\tshortcut,\n\t\t\t\t( ...args: [ Mousetrap.ExtendedKeyboardEvent, string ] ) =>\n\t\t\t\t\tcurrentCallbackRef.current( ...args ),\n\t\t\t\teventName\n\t\t\t);\n\t\t} );\n\n\t\treturn () => {\n\t\t\tmousetrap.reset();\n\t\t};\n\t}, [ shortcuts, bindGlobal, eventName, target, isDisabled ] );\n}\n\nexport default useKeyboardShortcut;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,uBAAsB;AACtB,mCAAO;AAOP,qBAAkC;AAClC,sBAA0B;AAkC1B,SAAS,oBACR,WACA,UACA;AAAA,EACC,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA,EACb;AACD,IAAuC,CAAC,GACvC;AACD,QAAM,yBAAqB,uBAAQ,QAAS;AAE5C,gCAAW,MAAM;AAChB,uBAAmB,UAAU;AAAA,EAC9B,GAAG,CAAE,QAAS,CAAE;AAEhB,gCAAW,MAAM;AAChB,QAAK,YAAa;AACjB;AAAA,IACD;AAEA,UAAM,YAAY,IAAI,iBAAAA;AAAA,MACrB,UAAU,OAAO,UACd,OAAO;AAAA;AAAA;AAAA;AAAA,QAIL;AAAA;AAAA,IACN;AAEA,UAAM,iBAAiB,MAAM,QAAS,SAAU,IAC7C,YACA,CAAE,SAAU;AAEf,mBAAe,QAAS,CAAE,aAAsB;AAC/C,YAAM,OAAO,SAAS,MAAO,GAAI;AACjC,YAAM,YAAY,IAAI;AAAA,QACrB,KAAK,OAAQ,CAAE,UAAW,MAAM,SAAS,CAAE;AAAA,MAC5C;AACA,YAAM,SAAS,UAAU,IAAK,KAAM;AACpC,YAAM,WAAW,UAAU,IAAK,OAAQ;AAExC,cACC,2BAAU,MACN,UAAU,SAAS,KAAK,UACzB,UAAU,SAAS,KAAK,UAAU,WACpC;AACD,cAAM,IAAI;AAAA,UACT,eAAgB,QAAS;AAAA,QAC1B;AAAA,MACD;AAEA,YAAM,SAAS,aAAa,eAAe;AAI3C,MAAE,UAAoB,MAAO;AAAA,QAC5B;AAAA,QACA,IAAK,SACJ,mBAAmB,QAAS,GAAG,IAAK;AAAA,QACrC;AAAA,MACD;AAAA,IACD,CAAE;AAEF,WAAO,MAAM;AACZ,gBAAU,MAAM;AAAA,IACjB;AAAA,EACD,GAAG,CAAE,WAAW,YAAY,WAAW,QAAQ,UAAW,CAAE;AAC7D;AAEA,IAAO,gCAAQ;",
|
|
6
6
|
"names": ["Mousetrap"]
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/compose/src/hooks/use-reduced-motion/index.
|
|
30
|
+
// packages/compose/src/hooks/use-reduced-motion/index.ts
|
|
31
31
|
var use_reduced_motion_exports = {};
|
|
32
32
|
__export(use_reduced_motion_exports, {
|
|
33
33
|
default: () => use_reduced_motion_default
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-reduced-motion/index.
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * Hook returning whether the user has a preference for reduced motion.\n *\n * @return
|
|
3
|
+
"sources": ["../../../src/hooks/use-reduced-motion/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport useMediaQuery from '../use-media-query';\n\n/**\n * Hook returning whether the user has a preference for reduced motion.\n *\n * @return Reduced motion preference value.\n */\nconst useReducedMotion = (): boolean =>\n\tuseMediaQuery( '(prefers-reduced-motion: reduce)' );\n\nexport default useReducedMotion;\n"],
|
|
5
5
|
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,6BAA0B;AAO1B,IAAM,mBAAmB,UACxB,uBAAAA,SAAe,kCAAmC;AAEnD,IAAO,6BAAQ;",
|
|
6
6
|
"names": ["useMediaQuery"]
|
|
7
7
|
}
|
|
@@ -17,7 +17,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
17
17
|
};
|
|
18
18
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
19
|
|
|
20
|
-
// packages/compose/src/hooks/use-throttle/index.
|
|
20
|
+
// packages/compose/src/hooks/use-throttle/index.ts
|
|
21
21
|
var use_throttle_exports = {};
|
|
22
22
|
__export(use_throttle_exports, {
|
|
23
23
|
default: () => useThrottle
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-throttle/index.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { throttle } from '../../utils/throttle';\n\n/**\n * Throttles a function similar to Lodash's `throttle`. A new throttled function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to throttle, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#throttle\n *\n * @template
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA2B;AAK3B,qBAA0B;AAK1B,sBAAyB;
|
|
3
|
+
"sources": ["../../../src/hooks/use-throttle/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { throttle } from '../../utils/throttle';\nimport type { ThrottleOptions } from '../../utils/throttle';\nimport type { DebouncedFunc } from '../../utils/debounce';\n\n/**\n * Throttles a function similar to Lodash's `throttle`. A new throttled function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to throttle, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#throttle\n *\n * @template TFunc\n *\n * @param fn The function to throttle.\n * @param wait The number of milliseconds to throttle invocations to.\n * @param options The options object.\n * @return Throttled function.\n */\nexport default function useThrottle< TFunc extends ( ...args: any[] ) => void >(\n\tfn: TFunc,\n\twait?: number,\n\toptions?: ThrottleOptions\n): DebouncedFunc< TFunc > {\n\tconst throttled = useMemoOne(\n\t\t() => throttle( fn, wait ?? 0, options ),\n\t\t[ fn, wait, options ]\n\t);\n\tuseEffect( () => () => throttled.cancel(), [ throttled ] );\n\treturn throttled;\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAA2B;AAK3B,qBAA0B;AAK1B,sBAAyB;AAmBV,SAAR,YACN,IACA,MACA,SACyB;AACzB,QAAM,gBAAY;AAAA,IACjB,UAAM,0BAAU,IAAI,QAAQ,GAAG,OAAQ;AAAA,IACvC,CAAE,IAAI,MAAM,OAAQ;AAAA,EACrB;AACA,gCAAW,MAAM,MAAM,UAAU,OAAO,GAAG,CAAE,SAAU,CAAE;AACzD,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/compose/src/hooks/use-viewport-match/index.
|
|
30
|
+
// packages/compose/src/hooks/use-viewport-match/index.ts
|
|
31
31
|
var use_viewport_match_exports = {};
|
|
32
32
|
__export(use_viewport_match_exports, {
|
|
33
33
|
default: () => use_viewport_match_default
|
|
@@ -53,10 +53,7 @@ var OPERATOR_EVALUATORS = {
|
|
|
53
53
|
">=": (breakpointValue, width) => width >= breakpointValue,
|
|
54
54
|
"<": (breakpointValue, width) => width < breakpointValue
|
|
55
55
|
};
|
|
56
|
-
var ViewportMatchWidthContext = (0, import_element.createContext)(
|
|
57
|
-
/** @type {null | number} */
|
|
58
|
-
null
|
|
59
|
-
);
|
|
56
|
+
var ViewportMatchWidthContext = (0, import_element.createContext)(null);
|
|
60
57
|
ViewportMatchWidthContext.displayName = "ViewportMatchWidthContext";
|
|
61
58
|
var useViewportMatch = (breakpoint, operator = ">=", view = typeof window !== "undefined" ? window : void 0) => {
|
|
62
59
|
const simulatedWidth = (0, import_element.useContext)(ViewportMatchWidthContext);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-viewport-match/index.
|
|
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\
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0C;AAK1C,6BAA0B;
|
|
3
|
+
"sources": ["../../../src/hooks/use-viewport-match/index.ts"],
|
|
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\ntype Breakpoint =\n\t| 'xhuge'\n\t| 'huge'\n\t| 'wide'\n\t| 'xlarge'\n\t| 'large'\n\t| 'medium'\n\t| 'small'\n\t| 'mobile';\ntype ViewportOperator = '>=' | '<';\n\n/**\n * Hash of breakpoint names with pixel width at which it becomes effective.\n *\n * @see _breakpoints.scss\n */\nconst BREAKPOINTS: Record< Breakpoint, number > = {\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 * Object mapping media query operators to the condition to be used.\n */\nconst CONDITIONS: Record< ViewportOperator, string > = {\n\t'>=': 'min-width',\n\t'<': 'max-width',\n};\n\n/**\n * Object mapping media query operators to a function that evaluates if the operator matches.\n */\nconst OPERATOR_EVALUATORS: Record<\n\tViewportOperator,\n\t( breakpointValue: number, width: number ) => boolean\n> = {\n\t'>=': ( breakpointValue, width ) => width >= breakpointValue,\n\t'<': ( breakpointValue, width ) => width < breakpointValue,\n};\n\nconst ViewportMatchWidthContext = createContext< number | null >( null );\nViewportMatchWidthContext.displayName = 'ViewportMatchWidthContext';\n\n/**\n * Returns true if the viewport matches the given query, or false otherwise.\n *\n * @param breakpoint Breakpoint size name.\n * @param operator Viewport operator.\n * @param view Window instance in which to perform viewport matching.\n *\n * @example\n *\n * ```ts\n * useViewportMatch( 'huge', '<' );\n * useViewportMatch( 'medium' );\n * ```\n *\n * @return Whether viewport matches query.\n */\nconst useViewportMatch = (\n\tbreakpoint: Breakpoint,\n\toperator: ViewportOperator = '>=',\n\t// Resolve the default lazily so SSR (where `window` is undeclared) does not\n\t// throw a ReferenceError when this default expression is evaluated.\n\tview: Window | undefined = typeof window !== 'undefined'\n\t\t? window\n\t\t: undefined\n): boolean => {\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\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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA0C;AAK1C,6BAA0B;AAkB1B,IAAM,cAA4C;AAAA,EACjD,OAAO;AAAA,EACP,MAAM;AAAA,EACN,MAAM;AAAA,EACN,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,QAAQ;AACT;AAKA,IAAM,aAAiD;AAAA,EACtD,MAAM;AAAA,EACN,KAAK;AACN;AAKA,IAAM,sBAGF;AAAA,EACH,MAAM,CAAE,iBAAiB,UAAW,SAAS;AAAA,EAC7C,KAAK,CAAE,iBAAiB,UAAW,QAAQ;AAC5C;AAEA,IAAM,gCAA4B,8BAAgC,IAAK;AACvE,0BAA0B,cAAc;AAkBxC,IAAM,mBAAmB,CACxB,YACA,WAA6B,MAG7B,OAA2B,OAAO,WAAW,cAC1C,SACA,WACU;AACb,QAAM,qBAAiB,2BAAY,yBAA0B;AAC7D,QAAM,aACL,CAAE,kBACF,IAAK,WAAY,QAAS,CAAE,KAAM,YAAa,UAAW,CAAE;AAC7D,QAAM,uBAAmB,uBAAAA,SAAe,cAAc,QAAW,IAAK;AAEtE,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": ["useMediaQuery"]
|
|
7
7
|
}
|
|
@@ -27,7 +27,7 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
27
27
|
));
|
|
28
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
29
|
|
|
30
|
-
// packages/compose/src/hooks/use-warn-on-change/index.
|
|
30
|
+
// packages/compose/src/hooks/use-warn-on-change/index.ts
|
|
31
31
|
var use_warn_on_change_exports = {};
|
|
32
32
|
__export(use_warn_on_change_exports, {
|
|
33
33
|
default: () => use_warn_on_change_default
|
|
@@ -37,18 +37,11 @@ var import_use_previous = __toESM(require("../use-previous/index.cjs"));
|
|
|
37
37
|
function useWarnOnChange(object, prefix = "Change detection") {
|
|
38
38
|
const previousValues = (0, import_use_previous.default)(object);
|
|
39
39
|
Object.entries(previousValues ?? []).forEach(([key, value]) => {
|
|
40
|
-
if (value !== object[
|
|
41
|
-
/** @type {keyof typeof object} */
|
|
42
|
-
key
|
|
43
|
-
]) {
|
|
40
|
+
if (value !== object[key]) {
|
|
44
41
|
console.warn(
|
|
45
42
|
`${prefix}: ${key} key changed:`,
|
|
46
43
|
value,
|
|
47
|
-
object[
|
|
48
|
-
/** @type {keyof typeof object} */
|
|
49
|
-
key
|
|
50
|
-
]
|
|
51
|
-
/* eslint-enable jsdoc/check-types */
|
|
44
|
+
object[key]
|
|
52
45
|
);
|
|
53
46
|
}
|
|
54
47
|
});
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-warn-on-change/index.
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n
|
|
5
|
-
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAwB;
|
|
3
|
+
"sources": ["../../../src/hooks/use-warn-on-change/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport usePrevious from '../use-previous';\n\n/**\n * Hook that performs a shallow comparison between the previous value of an object\n * and the new one, if there's a difference, it prints it to the console.\n * This is useful in performance related work, to check why a component re-renders.\n *\n * @example\n *\n * ```tsx\n * function MyComponent(props: Record<string, any>) {\n * useWarnOnChange(props);\n *\n * return \"Something\";\n * }\n * ```\n *\n * @param object Object which changes to compare.\n * @param prefix Just a prefix to show when console logging.\n */\nfunction useWarnOnChange(\n\tobject: Record< string, any > | any[],\n\tprefix: string = 'Change detection'\n): void {\n\tconst previousValues = usePrevious( object );\n\n\tObject.entries( previousValues ?? [] ).forEach( ( [ key, value ] ) => {\n\t\tif ( value !== object[ key as keyof typeof object ] ) {\n\t\t\t// eslint-disable-next-line no-console\n\t\t\tconsole.warn(\n\t\t\t\t`${ prefix }: ${ key } key changed:`,\n\t\t\t\tvalue,\n\t\t\t\tobject[ key as keyof typeof object ]\n\t\t\t);\n\t\t}\n\t} );\n}\n\nexport default useWarnOnChange;\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,0BAAwB;AAoBxB,SAAS,gBACR,QACA,SAAiB,oBACV;AACP,QAAM,qBAAiB,oBAAAA,SAAa,MAAO;AAE3C,SAAO,QAAS,kBAAkB,CAAC,CAAE,EAAE,QAAS,CAAE,CAAE,KAAK,KAAM,MAAO;AACrE,QAAK,UAAU,OAAQ,GAA2B,GAAI;AAErD,cAAQ;AAAA,QACP,GAAI,MAAO,KAAM,GAAI;AAAA,QACrB;AAAA,QACA,OAAQ,GAA2B;AAAA,MACpC;AAAA,IACD;AAAA,EACD,CAAE;AACH;AAEA,IAAO,6BAAQ;",
|
|
6
6
|
"names": ["usePrevious"]
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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
|
|
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 → its `ownerDocument`\n\t// Document → itself (own `ownerDocument` is `null`)\n\t// Window → itself (no `ownerDocument` property)\n\t// `undefined` (Window) → 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 — 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 → 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
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
6
|
"names": ["set"]
|
|
7
7
|
}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-constrained-tabbing/index.
|
|
1
|
+
// packages/compose/src/hooks/use-constrained-tabbing/index.ts
|
|
2
2
|
import { focus } from "@wordpress/dom";
|
|
3
3
|
import useRefEffect from "../use-ref-effect/index.mjs";
|
|
4
4
|
function useConstrainedTabbing() {
|
|
@@ -9,14 +9,8 @@ function useConstrainedTabbing() {
|
|
|
9
9
|
return;
|
|
10
10
|
}
|
|
11
11
|
const action = shiftKey ? "findPrevious" : "findNext";
|
|
12
|
-
const nextElement = focus.tabbable[action](
|
|
13
|
-
|
|
14
|
-
target
|
|
15
|
-
) || null;
|
|
16
|
-
if (
|
|
17
|
-
/** @type {HTMLElement} */
|
|
18
|
-
target.contains(nextElement)
|
|
19
|
-
) {
|
|
12
|
+
const nextElement = focus.tabbable[action](target) || null;
|
|
13
|
+
if (target.contains(nextElement)) {
|
|
20
14
|
event.preventDefault();
|
|
21
15
|
nextElement?.focus();
|
|
22
16
|
return;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-constrained-tabbing/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In Dialogs/modals, the tabbing must be constrained to the content of\n * the wrapper element. This hook adds the behavior to the returned ref.\n *\n * @return
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa;AAKtB,OAAO,kBAAkB;AAuBzB,SAAS,
|
|
3
|
+
"sources": ["../../../src/hooks/use-constrained-tabbing/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { focus } from '@wordpress/dom';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In Dialogs/modals, the tabbing must be constrained to the content of\n * the wrapper element. This hook adds the behavior to the returned ref.\n *\n * @return Element Ref.\n *\n * @example\n * ```ts\n * import { useConstrainedTabbing } from '@wordpress/compose';\n *\n * const ConstrainedTabbingExample = () => {\n * const constrainedTabbingRef = useConstrainedTabbing()\n * return (\n * <div ref={ constrainedTabbingRef }>\n * <Button />\n * <Button />\n * </div>\n * );\n * }\n * ```\n */\nfunction useConstrainedTabbing(): React.RefCallback< Element > {\n\treturn useRefEffect( ( node: HTMLElement ) => {\n\t\tfunction onKeyDown( event: KeyboardEvent ): void {\n\t\t\tconst { key, shiftKey, target } = event;\n\n\t\t\tif ( key !== 'Tab' ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst action = shiftKey ? 'findPrevious' : 'findNext';\n\t\t\tconst nextElement =\n\t\t\t\tfocus.tabbable[ action ]( target as HTMLElement ) || null;\n\n\t\t\t// When the target element contains the element that is about to\n\t\t\t// receive focus, for example when the target is a tabbable\n\t\t\t// container, browsers may disagree on where to move focus next.\n\t\t\t// In this case we can't rely on native browsers behavior. We need\n\t\t\t// to manage focus instead.\n\t\t\t// See https://github.com/WordPress/gutenberg/issues/46041.\n\t\t\tif ( ( target as HTMLElement ).contains( nextElement ) ) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tnextElement?.focus();\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the element that is about to receive focus is inside the\n\t\t\t// area, rely on native browsers behavior and let tabbing follow\n\t\t\t// the native tab sequence.\n\t\t\tif ( node.contains( nextElement ) ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t// If the element that is about to receive focus is outside the\n\t\t\t// area, move focus to a div and insert it at the start or end of\n\t\t\t// the area, depending on the direction. Without preventing default\n\t\t\t// behaviour, the browser will then move focus to the next element.\n\t\t\tconst domAction = shiftKey ? 'append' : 'prepend';\n\t\t\tconst { ownerDocument } = node;\n\t\t\tconst trap = ownerDocument.createElement( 'div' );\n\n\t\t\ttrap.tabIndex = -1;\n\t\t\tnode[ domAction ]( trap );\n\n\t\t\t// Remove itself when the trap loses focus.\n\t\t\ttrap.addEventListener( 'blur', () => node.removeChild( trap ) );\n\n\t\t\ttrap.focus();\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', onKeyDown );\n\t\treturn () => {\n\t\t\tnode.removeEventListener( 'keydown', onKeyDown );\n\t\t};\n\t}, [] );\n}\n\nexport default useConstrainedTabbing;\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa;AAKtB,OAAO,kBAAkB;AAuBzB,SAAS,wBAAsD;AAC9D,SAAO,aAAc,CAAE,SAAuB;AAC7C,aAAS,UAAW,OAA6B;AAChD,YAAM,EAAE,KAAK,UAAU,OAAO,IAAI;AAElC,UAAK,QAAQ,OAAQ;AACpB;AAAA,MACD;AAEA,YAAM,SAAS,WAAW,iBAAiB;AAC3C,YAAM,cACL,MAAM,SAAU,MAAO,EAAG,MAAsB,KAAK;AAQtD,UAAO,OAAwB,SAAU,WAAY,GAAI;AACxD,cAAM,eAAe;AACrB,qBAAa,MAAM;AACnB;AAAA,MACD;AAKA,UAAK,KAAK,SAAU,WAAY,GAAI;AACnC;AAAA,MACD;AAMA,YAAM,YAAY,WAAW,WAAW;AACxC,YAAM,EAAE,cAAc,IAAI;AAC1B,YAAM,OAAO,cAAc,cAAe,KAAM;AAEhD,WAAK,WAAW;AAChB,WAAM,SAAU,EAAG,IAAK;AAGxB,WAAK,iBAAkB,QAAQ,MAAM,KAAK,YAAa,IAAK,CAAE;AAE9D,WAAK,MAAM;AAAA,IACZ;AAEA,SAAK,iBAAkB,WAAW,SAAU;AAC5C,WAAO,MAAM;AACZ,WAAK,oBAAqB,WAAW,SAAU;AAAA,IAChD;AAAA,EACD,GAAG,CAAC,CAAE;AACP;AAEA,IAAO,kCAAQ;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-debounce/index.
|
|
4
|
-
"sourcesContent": ["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\n\n/**\n * Debounces a function similar to Lodash's `debounce`. A new debounced function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to debounce, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#debounce\n *\n * @template
|
|
5
|
-
"mappings": ";AAGA,SAAS,kBAAkB;AAK3B,SAAS,iBAAiB;AAK1B,SAAS,gBAAgB;
|
|
3
|
+
"sources": ["../../../src/hooks/use-debounce/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { useMemoOne } from 'use-memo-one';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport type { DebounceOptions, DebouncedFunc } from '../../utils/debounce';\n\n/**\n * Debounces a function similar to Lodash's `debounce`. A new debounced function will\n * be returned and any scheduled calls cancelled if any of the arguments change,\n * including the function to debounce, so please wrap functions created on\n * render in components in `useCallback`.\n *\n * @see https://lodash.com/docs/4#debounce\n *\n * @template TFunc\n *\n * @param fn The function to debounce.\n * @param wait The number of milliseconds to delay.\n * @param options The options object.\n * @return Debounced function.\n */\nexport default function useDebounce< TFunc extends ( ...args: any[] ) => void >(\n\tfn: TFunc,\n\twait?: number,\n\toptions?: DebounceOptions\n): DebouncedFunc< TFunc > {\n\tconst debounced = useMemoOne(\n\t\t() => debounce( fn, wait ?? 0, options ),\n\t\t[ fn, wait, options?.leading, options?.trailing, options?.maxWait ]\n\t);\n\tuseEffect( () => () => debounced.cancel(), [ debounced ] );\n\treturn debounced;\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,kBAAkB;AAK3B,SAAS,iBAAiB;AAK1B,SAAS,gBAAgB;AAkBV,SAAR,YACN,IACA,MACA,SACyB;AACzB,QAAM,YAAY;AAAA,IACjB,MAAM,SAAU,IAAI,QAAQ,GAAG,OAAQ;AAAA,IACvC,CAAE,IAAI,MAAM,SAAS,SAAS,SAAS,UAAU,SAAS,OAAQ;AAAA,EACnE;AACA,YAAW,MAAM,MAAM,UAAU,OAAO,GAAG,CAAE,SAAU,CAAE;AACzD,SAAO;AACR;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/hooks/use-disabled/index.ts"],
|
|
4
|
-
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * If you can, prefer the use of the inert HTML attribute.\n *\n * @param {Object} config Configuration object.\n * @param {boolean=} config.isDisabled Whether the element should be disabled.\n * @return {React.RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useDisabled } from '@wordpress/compose';\n *\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled( {\n\tisDisabled: isDisabledProp = false,\n} = {} ) {\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isDisabledProp ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultView = node?.ownerDocument?.defaultView;\n\t\t\tif ( ! defaultView ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/** A variable keeping track of the previous updates in order to restore them. */\n\t\t\tconst updates:
|
|
5
|
-
"mappings": ";AAGA,SAAS,gBAAgB;AACzB,OAAO,kBAAkB;AA4BV,SAAR,YAA8B;AAAA,EACpC,YAAY,iBAAiB;AAC9B,
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { debounce } from '../../utils/debounce';\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * In some circumstances, such as block previews, all focusable DOM elements\n * (input fields, links, buttons, etc.) need to be disabled. This hook adds the\n * behavior to disable nested DOM elements to the returned ref.\n *\n * If you can, prefer the use of the inert HTML attribute.\n *\n * @param {Object} config Configuration object.\n * @param {boolean=} config.isDisabled Whether the element should be disabled.\n * @return {React.RefCallback<HTMLElement>} Element Ref.\n *\n * @example\n * ```js\n * import { useDisabled } from '@wordpress/compose';\n *\n * const DisabledExample = () => {\n * \tconst disabledRef = useDisabled();\n *\treturn (\n *\t\t<div ref={ disabledRef }>\n *\t\t\t<a href=\"#\">This link will have tabindex set to -1</a>\n *\t\t\t<input placeholder=\"This input will have the disabled attribute added to it.\" type=\"text\" />\n *\t\t</div>\n *\t);\n * };\n * ```\n */\nexport default function useDisabled( {\n\tisDisabled: isDisabledProp = false,\n}: {\n\tisDisabled?: boolean;\n} = {} ) {\n\treturn useRefEffect(\n\t\t( node ) => {\n\t\t\tif ( isDisabledProp ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tconst defaultView = node?.ownerDocument?.defaultView;\n\t\t\tif ( ! defaultView ) {\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\t/** A variable keeping track of the previous updates in order to restore them. */\n\t\t\tconst updates: ( () => void )[] = [];\n\t\t\tconst disable = () => {\n\t\t\t\tnode.childNodes.forEach( ( child ) => {\n\t\t\t\t\tif ( ! ( child instanceof defaultView.HTMLElement ) ) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\t\t\t\t\tif ( ! child.getAttribute( 'inert' ) ) {\n\t\t\t\t\t\tchild.setAttribute( 'inert', 'true' );\n\t\t\t\t\t\tupdates.push( () => {\n\t\t\t\t\t\t\tchild.removeAttribute( 'inert' );\n\t\t\t\t\t\t} );\n\t\t\t\t\t}\n\t\t\t\t} );\n\t\t\t};\n\n\t\t\t// Debounce re-disable since disabling process itself will incur\n\t\t\t// additional mutations which should be ignored.\n\t\t\tconst debouncedDisable = debounce( disable, 0, {\n\t\t\t\tleading: true,\n\t\t\t} );\n\t\t\tdisable();\n\n\t\t\t/** @type {MutationObserver | undefined} */\n\t\t\tconst observer = new window.MutationObserver( debouncedDisable );\n\t\t\tobserver.observe( node, {\n\t\t\t\tchildList: true,\n\t\t\t} );\n\n\t\t\treturn () => {\n\t\t\t\tif ( observer ) {\n\t\t\t\t\tobserver.disconnect();\n\t\t\t\t}\n\t\t\t\tdebouncedDisable.cancel();\n\t\t\t\tupdates.forEach( ( update ) => update() );\n\t\t\t};\n\t\t},\n\t\t[ isDisabledProp ]\n\t);\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,gBAAgB;AACzB,OAAO,kBAAkB;AA4BV,SAAR,YAA8B;AAAA,EACpC,YAAY,iBAAiB;AAC9B,IAEI,CAAC,GAAI;AACR,SAAO;AAAA,IACN,CAAE,SAAU;AACX,UAAK,gBAAiB;AACrB;AAAA,MACD;AAEA,YAAM,cAAc,MAAM,eAAe;AACzC,UAAK,CAAE,aAAc;AACpB;AAAA,MACD;AAGA,YAAM,UAA4B,CAAC;AACnC,YAAM,UAAU,MAAM;AACrB,aAAK,WAAW,QAAS,CAAE,UAAW;AACrC,cAAK,EAAI,iBAAiB,YAAY,cAAgB;AACrD;AAAA,UACD;AACA,cAAK,CAAE,MAAM,aAAc,OAAQ,GAAI;AACtC,kBAAM,aAAc,SAAS,MAAO;AACpC,oBAAQ,KAAM,MAAM;AACnB,oBAAM,gBAAiB,OAAQ;AAAA,YAChC,CAAE;AAAA,UACH;AAAA,QACD,CAAE;AAAA,MACH;AAIA,YAAM,mBAAmB,SAAU,SAAS,GAAG;AAAA,QAC9C,SAAS;AAAA,MACV,CAAE;AACF,cAAQ;AAGR,YAAM,WAAW,IAAI,OAAO,iBAAkB,gBAAiB;AAC/D,eAAS,QAAS,MAAM;AAAA,QACvB,WAAW;AAAA,MACZ,CAAE;AAEF,aAAO,MAAM;AACZ,YAAK,UAAW;AACf,mBAAS,WAAW;AAAA,QACrB;AACA,yBAAiB,OAAO;AACxB,gBAAQ,QAAS,CAAE,WAAY,OAAO,CAAE;AAAA,MACzC;AAAA,IACD;AAAA,IACA,CAAE,cAAe;AAAA,EAClB;AACD;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,11 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-dragging/index.
|
|
1
|
+
// packages/compose/src/hooks/use-dragging/index.ts
|
|
2
2
|
import { useCallback, useEffect, useRef, useState } from "@wordpress/element";
|
|
3
3
|
import useIsomorphicLayoutEffect from "../use-isomorphic-layout-effect/index.mjs";
|
|
4
|
-
function useDragging({
|
|
4
|
+
function useDragging({
|
|
5
|
+
onDragStart,
|
|
6
|
+
onDragMove,
|
|
7
|
+
onDragEnd
|
|
8
|
+
}) {
|
|
5
9
|
const [isDragging, setIsDragging] = useState(false);
|
|
6
10
|
const eventsRef = useRef({
|
|
7
11
|
onDragStart,
|
|
@@ -13,26 +17,27 @@ function useDragging({ onDragStart, onDragMove, onDragEnd }) {
|
|
|
13
17
|
eventsRef.current.onDragMove = onDragMove;
|
|
14
18
|
eventsRef.current.onDragEnd = onDragEnd;
|
|
15
19
|
}, [onDragStart, onDragMove, onDragEnd]);
|
|
16
|
-
const onMouseMove = useCallback(
|
|
17
|
-
|
|
18
|
-
[]
|
|
19
|
-
);
|
|
20
|
-
const endDrag = useCallback((event) => {
|
|
21
|
-
if (eventsRef.current.onDragEnd) {
|
|
22
|
-
eventsRef.current.onDragEnd(event);
|
|
23
|
-
}
|
|
24
|
-
document.removeEventListener("mousemove", onMouseMove);
|
|
25
|
-
document.removeEventListener("mouseup", endDrag);
|
|
26
|
-
setIsDragging(false);
|
|
27
|
-
}, []);
|
|
28
|
-
const startDrag = useCallback((event) => {
|
|
29
|
-
if (eventsRef.current.onDragStart) {
|
|
30
|
-
eventsRef.current.onDragStart(event);
|
|
31
|
-
}
|
|
32
|
-
document.addEventListener("mousemove", onMouseMove);
|
|
33
|
-
document.addEventListener("mouseup", endDrag);
|
|
34
|
-
setIsDragging(true);
|
|
20
|
+
const onMouseMove = useCallback((event) => {
|
|
21
|
+
eventsRef.current.onDragMove?.(event);
|
|
35
22
|
}, []);
|
|
23
|
+
const endDrag = useCallback(
|
|
24
|
+
function endDrag2(event) {
|
|
25
|
+
eventsRef.current.onDragEnd?.(event);
|
|
26
|
+
document.removeEventListener("mousemove", onMouseMove);
|
|
27
|
+
document.removeEventListener("mouseup", endDrag2);
|
|
28
|
+
setIsDragging(false);
|
|
29
|
+
},
|
|
30
|
+
[onMouseMove]
|
|
31
|
+
);
|
|
32
|
+
const startDrag = useCallback(
|
|
33
|
+
(event) => {
|
|
34
|
+
eventsRef.current.onDragStart?.(event);
|
|
35
|
+
document.addEventListener("mousemove", onMouseMove);
|
|
36
|
+
document.addEventListener("mouseup", endDrag);
|
|
37
|
+
setIsDragging(true);
|
|
38
|
+
},
|
|
39
|
+
[onMouseMove, endDrag]
|
|
40
|
+
);
|
|
36
41
|
useEffect(() => {
|
|
37
42
|
return () => {
|
|
38
43
|
if (isDragging) {
|
|
@@ -40,7 +45,7 @@ function useDragging({ onDragStart, onDragMove, onDragEnd }) {
|
|
|
40
45
|
document.removeEventListener("mouseup", endDrag);
|
|
41
46
|
}
|
|
42
47
|
};
|
|
43
|
-
}, [isDragging]);
|
|
48
|
+
}, [isDragging, onMouseMove, endDrag]);
|
|
44
49
|
return {
|
|
45
50
|
startDrag,
|
|
46
51
|
endDrag,
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
|
-
"sources": ["../../../src/hooks/use-dragging/index.
|
|
4
|
-
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';\
|
|
5
|
-
"mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAKzD,OAAO,+BAA+B;
|
|
6
|
-
"names": []
|
|
3
|
+
"sources": ["../../../src/hooks/use-dragging/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useCallback, useEffect, useRef, useState } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useIsomorphicLayoutEffect from '../use-isomorphic-layout-effect';\nimport type { DraggingProps, DraggingReturn } from './types';\n\n/**\n * Hook to manage drag events with proper event handling\n *\n * @param props Drag handlers\n * @param props.onDragStart\n * @param props.onDragMove\n * @param props.onDragEnd\n * @return Drag state and handlers\n */\nexport default function useDragging( {\n\tonDragStart,\n\tonDragMove,\n\tonDragEnd,\n}: DraggingProps ): DraggingReturn {\n\tconst [ isDragging, setIsDragging ] = useState( false );\n\n\tconst eventsRef = useRef< DraggingProps >( {\n\t\tonDragStart,\n\t\tonDragMove,\n\t\tonDragEnd,\n\t} );\n\tuseIsomorphicLayoutEffect( () => {\n\t\teventsRef.current.onDragStart = onDragStart;\n\t\teventsRef.current.onDragMove = onDragMove;\n\t\teventsRef.current.onDragEnd = onDragEnd;\n\t}, [ onDragStart, onDragMove, onDragEnd ] );\n\n\tconst onMouseMove = useCallback( ( event: MouseEvent ): void => {\n\t\teventsRef.current.onDragMove?.( event );\n\t}, [] );\n\n\tconst endDrag = useCallback(\n\t\tfunction endDrag( event?: MouseEvent ): void {\n\t\t\teventsRef.current.onDragEnd?.( event );\n\t\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\t\tsetIsDragging( false );\n\t\t},\n\t\t[ onMouseMove ]\n\t);\n\n\tconst startDrag = useCallback(\n\t\t( event: React.MouseEvent ): void => {\n\t\t\teventsRef.current.onDragStart?.( event );\n\t\t\tdocument.addEventListener( 'mousemove', onMouseMove );\n\t\t\tdocument.addEventListener( 'mouseup', endDrag );\n\t\t\tsetIsDragging( true );\n\t\t},\n\t\t[ onMouseMove, endDrag ]\n\t);\n\n\t// Remove the global events when unmounting if needed.\n\tuseEffect( () => {\n\t\treturn () => {\n\t\t\tif ( isDragging ) {\n\t\t\t\tdocument.removeEventListener( 'mousemove', onMouseMove );\n\t\t\t\tdocument.removeEventListener( 'mouseup', endDrag );\n\t\t\t}\n\t\t};\n\t}, [ isDragging, onMouseMove, endDrag ] );\n\n\treturn {\n\t\tstartDrag,\n\t\tendDrag,\n\t\tisDragging,\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";AAGA,SAAS,aAAa,WAAW,QAAQ,gBAAgB;AAKzD,OAAO,+BAA+B;AAYvB,SAAR,YAA8B;AAAA,EACpC;AAAA,EACA;AAAA,EACA;AACD,GAAmC;AAClC,QAAM,CAAE,YAAY,aAAc,IAAI,SAAU,KAAM;AAEtD,QAAM,YAAY,OAAyB;AAAA,IAC1C;AAAA,IACA;AAAA,IACA;AAAA,EACD,CAAE;AACF,4BAA2B,MAAM;AAChC,cAAU,QAAQ,cAAc;AAChC,cAAU,QAAQ,aAAa;AAC/B,cAAU,QAAQ,YAAY;AAAA,EAC/B,GAAG,CAAE,aAAa,YAAY,SAAU,CAAE;AAE1C,QAAM,cAAc,YAAa,CAAE,UAA6B;AAC/D,cAAU,QAAQ,aAAc,KAAM;AAAA,EACvC,GAAG,CAAC,CAAE;AAEN,QAAM,UAAU;AAAA,IACf,SAASA,SAAS,OAA2B;AAC5C,gBAAU,QAAQ,YAAa,KAAM;AACrC,eAAS,oBAAqB,aAAa,WAAY;AACvD,eAAS,oBAAqB,WAAWA,QAAQ;AACjD,oBAAe,KAAM;AAAA,IACtB;AAAA,IACA,CAAE,WAAY;AAAA,EACf;AAEA,QAAM,YAAY;AAAA,IACjB,CAAE,UAAmC;AACpC,gBAAU,QAAQ,cAAe,KAAM;AACvC,eAAS,iBAAkB,aAAa,WAAY;AACpD,eAAS,iBAAkB,WAAW,OAAQ;AAC9C,oBAAe,IAAK;AAAA,IACrB;AAAA,IACA,CAAE,aAAa,OAAQ;AAAA,EACxB;AAGA,YAAW,MAAM;AAChB,WAAO,MAAM;AACZ,UAAK,YAAa;AACjB,iBAAS,oBAAqB,aAAa,WAAY;AACvD,iBAAS,oBAAqB,WAAW,OAAQ;AAAA,MAClD;AAAA,IACD;AAAA,EACD,GAAG,CAAE,YAAY,aAAa,OAAQ,CAAE;AAExC,SAAO;AAAA,IACN;AAAA,IACA;AAAA,IACA;AAAA,EACD;AACD;",
|
|
6
|
+
"names": ["endDrag"]
|
|
7
7
|
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
//# sourceMappingURL=types.mjs.map
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
// packages/compose/src/hooks/use-drop-zone/index.
|
|
1
|
+
// packages/compose/src/hooks/use-drop-zone/index.ts
|
|
2
2
|
import useRefEffect from "../use-ref-effect/index.mjs";
|
|
3
3
|
import useEvent from "../use-event/index.mjs";
|
|
4
4
|
function useDropZone({
|
|
@@ -51,10 +51,7 @@ function useDropZone({
|
|
|
51
51
|
}
|
|
52
52
|
function onDragEnter(event) {
|
|
53
53
|
event.preventDefault();
|
|
54
|
-
if (element.contains(
|
|
55
|
-
/** @type {Node} */
|
|
56
|
-
event.relatedTarget
|
|
57
|
-
)) {
|
|
54
|
+
if (element.contains(event.relatedTarget)) {
|
|
58
55
|
return;
|
|
59
56
|
}
|
|
60
57
|
if (_onDragEnter) {
|