@wordpress/compose 7.31.1-next.f56bd8138.0 → 7.32.1-next.47f435fc9.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 +2 -0
- package/build/higher-order/compose.js +25 -20
- package/build/higher-order/compose.js.map +7 -1
- package/build/higher-order/if-condition/index.js +35 -41
- package/build/higher-order/if-condition/index.js.map +7 -1
- package/build/higher-order/pipe.js +32 -66
- package/build/higher-order/pipe.js.map +7 -1
- package/build/higher-order/pure/index.js +44 -37
- package/build/higher-order/pure/index.js.map +7 -1
- package/build/higher-order/with-global-events/index.js +64 -73
- package/build/higher-order/with-global-events/index.js.map +7 -1
- package/build/higher-order/with-global-events/listener.js +34 -21
- package/build/higher-order/with-global-events/listener.js.map +7 -1
- package/build/higher-order/with-instance-id/index.js +45 -27
- package/build/higher-order/with-instance-id/index.js.map +7 -1
- package/build/higher-order/with-safe-timeout/index.js +70 -66
- package/build/higher-order/with-safe-timeout/index.js.map +7 -1
- package/build/higher-order/with-state/index.js +52 -40
- package/build/higher-order/with-state/index.js.map +7 -1
- package/build/hooks/use-async-list/index.js +38 -42
- package/build/hooks/use-async-list/index.js.map +7 -1
- package/build/hooks/use-constrained-tabbing/index.js +54 -75
- package/build/hooks/use-constrained-tabbing/index.js.map +7 -1
- package/build/hooks/use-copy-on-click/index.js +46 -56
- package/build/hooks/use-copy-on-click/index.js.map +7 -1
- package/build/hooks/use-copy-to-clipboard/index.js +41 -51
- package/build/hooks/use-copy-to-clipboard/index.js.map +7 -1
- package/build/hooks/use-debounce/index.js +30 -37
- package/build/hooks/use-debounce/index.js.map +7 -1
- package/build/hooks/use-debounced-input/index.js +39 -27
- package/build/hooks/use-debounced-input/index.js.map +7 -1
- package/build/hooks/use-dialog/index.js +63 -55
- package/build/hooks/use-dialog/index.js.map +7 -1
- package/build/hooks/use-disabled/index.js +74 -82
- package/build/hooks/use-disabled/index.js.map +7 -1
- package/build/hooks/use-dragging/index.js +51 -48
- package/build/hooks/use-dragging/index.js.map +7 -1
- package/build/hooks/use-drop-zone/index.js +133 -168
- package/build/hooks/use-drop-zone/index.js.map +7 -1
- package/build/hooks/use-event/index.js +33 -45
- package/build/hooks/use-event/index.js.map +7 -1
- package/build/hooks/use-fixed-window-list/index.js +109 -97
- package/build/hooks/use-fixed-window-list/index.js.map +7 -1
- package/build/hooks/use-focus-on-mount/index.js +44 -57
- package/build/hooks/use-focus-on-mount/index.js.map +7 -1
- package/build/hooks/use-focus-outside/index.js +44 -102
- package/build/hooks/use-focus-outside/index.js.map +7 -1
- package/build/hooks/use-focus-return/index.js +35 -56
- package/build/hooks/use-focus-return/index.js.map +7 -1
- package/build/hooks/use-focusable-iframe/index.js +38 -35
- package/build/hooks/use-focusable-iframe/index.js.map +7 -1
- package/build/hooks/use-instance-id/index.js +26 -42
- package/build/hooks/use-instance-id/index.js.map +7 -1
- package/build/hooks/use-isomorphic-layout-effect/index.js +25 -17
- package/build/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
- package/build/hooks/use-keyboard-shortcut/index.js +72 -69
- package/build/hooks/use-keyboard-shortcut/index.js.map +7 -1
- package/build/hooks/use-media-query/index.js +39 -35
- package/build/hooks/use-media-query/index.js.map +7 -1
- package/build/hooks/use-merge-refs/index.js +34 -102
- package/build/hooks/use-merge-refs/index.js.map +7 -1
- package/build/hooks/use-observable-value/index.js +31 -28
- package/build/hooks/use-observable-value/index.js.map +7 -1
- package/build/hooks/use-preferred-color-scheme/index.android.js +31 -23
- package/build/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
- package/build/hooks/use-preferred-color-scheme/index.ios.js +25 -17
- package/build/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
- package/build/hooks/use-previous/index.js +26 -25
- package/build/hooks/use-previous/index.js.map +7 -1
- package/build/hooks/use-reduced-motion/index.js +35 -18
- package/build/hooks/use-reduced-motion/index.js.map +7 -1
- package/build/hooks/use-ref-effect/index.js +25 -35
- package/build/hooks/use-ref-effect/index.js.map +7 -1
- package/build/hooks/use-resize-observer/index.js +35 -67
- package/build/hooks/use-resize-observer/index.js.map +7 -1
- package/build/hooks/use-resize-observer/legacy/index.js +47 -103
- package/build/hooks/use-resize-observer/legacy/index.js.map +7 -1
- package/build/hooks/use-resize-observer/use-resize-observer.js +44 -36
- package/build/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
- package/build/hooks/use-state-with-history/index.js +68 -63
- package/build/hooks/use-state-with-history/index.js.map +7 -1
- package/build/hooks/use-throttle/index.js +30 -37
- package/build/hooks/use-throttle/index.js.map +7 -1
- package/build/hooks/use-viewport-match/index.js +51 -70
- package/build/hooks/use-viewport-match/index.js.map +7 -1
- package/build/hooks/use-warn-on-change/index.js +50 -40
- package/build/hooks/use-warn-on-change/index.js.map +7 -1
- package/build/index.js +156 -358
- package/build/index.js.map +7 -1
- package/build/utils/create-higher-order-component/index.js +30 -34
- package/build/utils/create-higher-order-component/index.js.map +7 -1
- package/build/utils/debounce/index.js +38 -99
- package/build/utils/debounce/index.js.map +7 -1
- package/build/utils/observable-map/index.js +29 -19
- package/build/utils/observable-map/index.js.map +7 -1
- package/build/utils/throttle/index.js +30 -81
- package/build/utils/throttle/index.js.map +7 -1
- package/build-module/higher-order/compose.js +6 -15
- package/build-module/higher-order/compose.js.map +7 -1
- package/build-module/higher-order/if-condition/index.js +16 -37
- package/build-module/higher-order/if-condition/index.js.map +7 -1
- package/build-module/higher-order/pipe.js +10 -62
- package/build-module/higher-order/pipe.js.map +7 -1
- package/build-module/higher-order/pure/index.js +12 -29
- package/build-module/higher-order/pure/index.js.map +7 -1
- package/build-module/higher-order/with-global-events/index.js +34 -67
- package/build-module/higher-order/with-global-events/index.js.map +7 -1
- package/build-module/higher-order/with-global-events/listener.js +16 -17
- package/build-module/higher-order/with-global-events/listener.js.map +7 -1
- package/build-module/higher-order/with-instance-id/index.js +17 -22
- package/build-module/higher-order/with-instance-id/index.js.map +7 -1
- package/build-module/higher-order/with-safe-timeout/index.js +52 -62
- package/build-module/higher-order/with-safe-timeout/index.js.map +7 -1
- package/build-module/higher-order/with-state/index.js +23 -35
- package/build-module/higher-order/with-state/index.js.map +7 -1
- package/build-module/hooks/use-async-list/index.js +16 -33
- package/build-module/hooks/use-async-list/index.js.map +7 -1
- package/build-module/hooks/use-constrained-tabbing/index.js +26 -70
- package/build-module/hooks/use-constrained-tabbing/index.js.map +7 -1
- package/build-module/hooks/use-copy-on-click/index.js +14 -47
- package/build-module/hooks/use-copy-on-click/index.js.map +7 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js +11 -44
- package/build-module/hooks/use-copy-to-clipboard/index.js.map +7 -1
- package/build-module/hooks/use-debounce/index.js +12 -33
- package/build-module/hooks/use-debounce/index.js.map +7 -1
- package/build-module/hooks/use-debounced-input/index.js +7 -18
- package/build-module/hooks/use-debounced-input/index.js.map +7 -1
- package/build-module/hooks/use-dialog/index.js +29 -43
- package/build-module/hooks/use-dialog/index.js.map +7 -1
- package/build-module/hooks/use-disabled/index.js +47 -78
- package/build-module/hooks/use-disabled/index.js.map +7 -1
- package/build-module/hooks/use-dragging/index.js +19 -39
- package/build-module/hooks/use-dragging/index.js.map +7 -1
- package/build-module/hooks/use-drop-zone/index.js +100 -158
- package/build-module/hooks/use-drop-zone/index.js.map +7 -1
- package/build-module/hooks/use-event/index.js +13 -39
- package/build-module/hooks/use-event/index.js.map +7 -1
- package/build-module/hooks/use-fixed-window-list/index.js +86 -87
- package/build-module/hooks/use-fixed-window-list/index.js.map +7 -1
- package/build-module/hooks/use-focus-on-mount/index.js +12 -48
- package/build-module/hooks/use-focus-on-mount/index.js.map +7 -1
- package/build-module/hooks/use-focus-outside/index.js +21 -93
- package/build-module/hooks/use-focus-outside/index.js.map +7 -1
- package/build-module/hooks/use-focus-return/index.js +13 -48
- package/build-module/hooks/use-focus-return/index.js.map +7 -1
- package/build-module/hooks/use-focusable-iframe/index.js +11 -31
- package/build-module/hooks/use-focusable-iframe/index.js.map +7 -1
- package/build-module/hooks/use-instance-id/index.js +7 -36
- package/build-module/hooks/use-instance-id/index.js.map +7 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js +7 -13
- package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
- package/build-module/hooks/use-keyboard-shortcut/index.js +40 -60
- package/build-module/hooks/use-keyboard-shortcut/index.js.map +7 -1
- package/build-module/hooks/use-media-query/index.js +21 -30
- package/build-module/hooks/use-media-query/index.js.map +7 -1
- package/build-module/hooks/use-merge-refs/index.js +10 -92
- package/build-module/hooks/use-merge-refs/index.js.map +7 -1
- package/build-module/hooks/use-observable-value/index.js +13 -24
- package/build-module/hooks/use-observable-value/index.js.map +7 -1
- package/build-module/hooks/use-preferred-color-scheme/index.android.js +15 -18
- package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js +6 -12
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
- package/build-module/hooks/use-previous/index.js +7 -20
- package/build-module/hooks/use-previous/index.js.map +7 -1
- package/build-module/hooks/use-reduced-motion/index.js +7 -13
- package/build-module/hooks/use-reduced-motion/index.js.map +7 -1
- package/build-module/hooks/use-ref-effect/index.js +7 -31
- package/build-module/hooks/use-ref-effect/index.js.map +7 -1
- package/build-module/hooks/use-resize-observer/index.js +7 -61
- package/build-module/hooks/use-resize-observer/index.js.map +7 -1
- package/build-module/hooks/use-resize-observer/legacy/index.js +28 -96
- package/build-module/hooks/use-resize-observer/legacy/index.js.map +7 -1
- package/build-module/hooks/use-resize-observer/use-resize-observer.js +10 -28
- package/build-module/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
- package/build-module/hooks/use-state-with-history/index.js +47 -55
- package/build-module/hooks/use-state-with-history/index.js.map +7 -1
- package/build-module/hooks/use-throttle/index.js +12 -33
- package/build-module/hooks/use-throttle/index.js.map +7 -1
- package/build-module/hooks/use-viewport-match/index.js +22 -64
- package/build-module/hooks/use-viewport-match/index.js.map +7 -1
- package/build-module/hooks/use-warn-on-change/index.js +21 -34
- package/build-module/hooks/use-warn-on-change/index.js.map +7 -1
- package/build-module/index.js +83 -53
- package/build-module/index.js.map +7 -1
- package/build-module/utils/create-higher-order-component/index.js +9 -30
- package/build-module/utils/create-higher-order-component/index.js.map +7 -1
- package/build-module/utils/debounce/index.js +17 -95
- package/build-module/utils/debounce/index.js.map +7 -1
- package/build-module/utils/observable-map/index.js +8 -16
- package/build-module/utils/observable-map/index.js.map +7 -1
- package/build-module/utils/throttle/index.js +8 -75
- package/build-module/utils/throttle/index.js.map +7 -1
- package/package.json +17 -10
- package/src/hooks/use-debounce/index.js +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/higher-order/with-network-connectivity/index.native.js +0 -27
- package/build/higher-order/with-network-connectivity/index.native.js.map +0 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +0 -37
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
- package/build/hooks/use-constrained-tabbing/index.native.js +0 -20
- package/build/hooks/use-constrained-tabbing/index.native.js.map +0 -1
- package/build/hooks/use-focus-outside/index.native.js +0 -175
- package/build/hooks/use-focus-outside/index.native.js.map +0 -1
- package/build/hooks/use-keyboard-shortcut/index.native.js +0 -9
- package/build/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
- package/build/hooks/use-network-connectivity/index.native.js +0 -58
- package/build/hooks/use-network-connectivity/index.native.js.map +0 -1
- package/build/hooks/use-preferred-color-scheme-style/index.native.js +0 -42
- package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
- package/build/hooks/use-resize-observer/index.native.js +0 -14
- package/build/hooks/use-resize-observer/index.native.js.map +0 -1
- package/build/hooks/use-resize-observer/legacy/index.native.js +0 -62
- package/build/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
- package/build/index.native.js +0 -297
- package/build/index.native.js.map +0 -1
- package/build-module/higher-order/with-network-connectivity/index.native.js +0 -19
- package/build-module/higher-order/with-network-connectivity/index.native.js.map +0 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js +0 -29
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
- package/build-module/hooks/use-constrained-tabbing/index.native.js +0 -13
- package/build-module/hooks/use-constrained-tabbing/index.native.js.map +0 -1
- package/build-module/hooks/use-focus-outside/index.native.js +0 -169
- package/build-module/hooks/use-focus-outside/index.native.js.map +0 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -3
- package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
- package/build-module/hooks/use-network-connectivity/index.native.js +0 -52
- package/build-module/hooks/use-network-connectivity/index.native.js.map +0 -1
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +0 -35
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
- package/build-module/hooks/use-resize-observer/index.native.js +0 -2
- package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
- package/build-module/hooks/use-resize-observer/legacy/index.native.js +0 -56
- package/build-module/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -45
- package/build-module/index.native.js.map +0 -1
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
* server rendered components (SSR) because currently React
|
|
9
|
-
* throws a warning when using useLayoutEffect in that environment.
|
|
10
|
-
*/
|
|
11
|
-
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect;
|
|
12
|
-
export default useIsomorphicLayoutEffect;
|
|
13
|
-
//# sourceMappingURL=index.js.map
|
|
1
|
+
import { useEffect, useLayoutEffect } from "@wordpress/element";
|
|
2
|
+
const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
3
|
+
var use_isomorphic_layout_effect_default = useIsomorphicLayoutEffect;
|
|
4
|
+
export {
|
|
5
|
+
use_isomorphic_layout_effect_default as default
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-isomorphic-layout-effect/index.js"],
|
|
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
|
+
"mappings": "AAGA,SAAS,WAAW,uBAAuB;AAO3C,MAAM,4BACL,OAAO,WAAW,cAAc,kBAAkB;AAEnD,IAAO,uCAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,40 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* WordPress dependencies
|
|
9
|
-
*/
|
|
10
|
-
import { useEffect, useRef } from '@wordpress/element';
|
|
11
|
-
import { isAppleOS } from '@wordpress/keycodes';
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* A block selection object.
|
|
15
|
-
*
|
|
16
|
-
* @typedef {Object} WPKeyboardShortcutConfig
|
|
17
|
-
*
|
|
18
|
-
* @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.
|
|
19
|
-
* @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.
|
|
20
|
-
* @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.
|
|
21
|
-
* @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.
|
|
22
|
-
*/
|
|
23
|
-
|
|
24
|
-
/* eslint-disable jsdoc/valid-types */
|
|
25
|
-
/**
|
|
26
|
-
* Attach a keyboard shortcut handler.
|
|
27
|
-
*
|
|
28
|
-
* @see https://craig.is/killing/mice#api.bind for information about the `callback` parameter.
|
|
29
|
-
*
|
|
30
|
-
* @param {string[]|string} shortcuts Keyboard Shortcuts.
|
|
31
|
-
* @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.
|
|
32
|
-
* @param {WPKeyboardShortcutConfig} options Shortcut options.
|
|
33
|
-
*/
|
|
34
|
-
function useKeyboardShortcut(/* eslint-enable jsdoc/valid-types */
|
|
35
|
-
shortcuts, callback, {
|
|
1
|
+
import Mousetrap from "mousetrap";
|
|
2
|
+
import "mousetrap/plugins/global-bind/mousetrap-global-bind";
|
|
3
|
+
import { useEffect, useRef } from "@wordpress/element";
|
|
4
|
+
import { isAppleOS } from "@wordpress/keycodes";
|
|
5
|
+
function useKeyboardShortcut(shortcuts, callback, {
|
|
36
6
|
bindGlobal = false,
|
|
37
|
-
eventName =
|
|
7
|
+
eventName = "keydown",
|
|
38
8
|
isDisabled = false,
|
|
39
9
|
// This is important for performance considerations.
|
|
40
10
|
target
|
|
@@ -47,36 +17,46 @@ shortcuts, callback, {
|
|
|
47
17
|
if (isDisabled) {
|
|
48
18
|
return;
|
|
49
19
|
}
|
|
50
|
-
const mousetrap = new Mousetrap(
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
20
|
+
const mousetrap = new Mousetrap(
|
|
21
|
+
target && target.current ? target.current : (
|
|
22
|
+
// We were passing `document` here previously, so to successfully cast it to Element we must cast it first to `unknown`.
|
|
23
|
+
// 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
|
|
24
|
+
// necessary to maintain the existing behavior.
|
|
25
|
+
/** @type {Element} */
|
|
26
|
+
/** @type {unknown} */
|
|
27
|
+
document
|
|
28
|
+
)
|
|
29
|
+
);
|
|
56
30
|
const shortcutsArray = Array.isArray(shortcuts) ? shortcuts : [shortcuts];
|
|
57
|
-
shortcutsArray.forEach(shortcut => {
|
|
58
|
-
const keys = shortcut.split(
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
const
|
|
63
|
-
const
|
|
64
|
-
const hasShift = modifiers.has('shift');
|
|
65
|
-
|
|
66
|
-
// This should be better moved to the shortcut registration instead.
|
|
31
|
+
shortcutsArray.forEach((shortcut) => {
|
|
32
|
+
const keys = shortcut.split("+");
|
|
33
|
+
const modifiers = new Set(
|
|
34
|
+
keys.filter((value) => value.length > 1)
|
|
35
|
+
);
|
|
36
|
+
const hasAlt = modifiers.has("alt");
|
|
37
|
+
const hasShift = modifiers.has("shift");
|
|
67
38
|
if (isAppleOS() && (modifiers.size === 1 && hasAlt || modifiers.size === 2 && hasAlt && hasShift)) {
|
|
68
|
-
throw new Error(
|
|
39
|
+
throw new Error(
|
|
40
|
+
`Cannot bind ${shortcut}. Alt and Shift+Alt modifiers are reserved for character input.`
|
|
41
|
+
);
|
|
69
42
|
}
|
|
70
|
-
const bindFn = bindGlobal ?
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
43
|
+
const bindFn = bindGlobal ? "bindGlobal" : "bind";
|
|
44
|
+
mousetrap[bindFn](
|
|
45
|
+
shortcut,
|
|
46
|
+
(...args) => (
|
|
47
|
+
/* eslint-enable jsdoc/valid-types */
|
|
48
|
+
currentCallbackRef.current(...args)
|
|
49
|
+
),
|
|
50
|
+
eventName
|
|
51
|
+
);
|
|
75
52
|
});
|
|
76
53
|
return () => {
|
|
77
54
|
mousetrap.reset();
|
|
78
55
|
};
|
|
79
56
|
}, [shortcuts, bindGlobal, eventName, target, isDisabled]);
|
|
80
57
|
}
|
|
81
|
-
|
|
82
|
-
|
|
58
|
+
var use_keyboard_shortcut_default = useKeyboardShortcut;
|
|
59
|
+
export {
|
|
60
|
+
use_keyboard_shortcut_default as default
|
|
61
|
+
};
|
|
62
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-keyboard-shortcut/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport Mousetrap from 'mousetrap';\nimport 'mousetrap/plugins/global-bind/mousetrap-global-bind';\n\n/**\n * WordPress dependencies\n */\nimport { useEffect, useRef } from '@wordpress/element';\nimport { isAppleOS } from '@wordpress/keycodes';\n\n/**\n * A block selection object.\n *\n * @typedef {Object} WPKeyboardShortcutConfig\n *\n * @property {boolean} [bindGlobal] Handle keyboard events anywhere including inside textarea/input fields.\n * @property {string} [eventName] Event name used to trigger the handler, defaults to keydown.\n * @property {boolean} [isDisabled] Disables the keyboard handler if the value is true.\n * @property {import('react').RefObject<HTMLElement>} [target] React reference to the DOM element used to catch the keyboard event.\n */\n\n/* eslint-disable jsdoc/valid-types */\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 {string[]|string} shortcuts Keyboard Shortcuts.\n * @param {(e: import('mousetrap').ExtendedKeyboardEvent, combo: string) => void} callback Shortcut callback.\n * @param {WPKeyboardShortcutConfig} options Shortcut options.\n */\nfunction useKeyboardShortcut(\n\t/* eslint-enable jsdoc/valid-types */\n\tshortcuts,\n\tcallback,\n\t{\n\t\tbindGlobal = false,\n\t\teventName = 'keydown',\n\t\tisDisabled = false, // This is important for performance considerations.\n\t\ttarget,\n\t} = {}\n) {\n\tconst currentCallbackRef = useRef( callback );\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\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 /** @type {Element} */ ( /** @type {unknown} */ ( document ) )\n\t\t);\n\t\tconst shortcutsArray = Array.isArray( shortcuts )\n\t\t\t? shortcuts\n\t\t\t: [ shortcuts ];\n\t\tshortcutsArray.forEach( ( shortcut ) => {\n\t\t\tconst keys = shortcut.split( '+' );\n\t\t\t// Determines whether a key is a modifier by the length of the string.\n\t\t\t// E.g. if I add a pass a shortcut Shift+Cmd+M, it'll determine that\n\t\t\t// the modifiers are Shift and Cmd because they're not a single character.\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\t// This should be better moved to the shortcut registration instead.\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-ignore `bindGlobal` is an undocumented property\n\t\t\tmousetrap[ bindFn ](\n\t\t\t\tshortcut,\n\t\t\t\t(\n\t\t\t\t\t/* eslint-disable jsdoc/valid-types */\n\t\t\t\t\t/** @type {[e: import('mousetrap').ExtendedKeyboardEvent, combo: string]} */ ...args\n\t\t\t\t) =>\n\t\t\t\t\t/* eslint-enable jsdoc/valid-types */\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": "AAGA,OAAO,eAAe;AACtB,OAAO;AAKP,SAAS,WAAW,cAAc;AAClC,SAAS,iBAAiB;AAuB1B,SAAS,oBAER,WACA,UACA;AAAA,EACC,aAAa;AAAA,EACb,YAAY;AAAA,EACZ,aAAa;AAAA;AAAA,EACb;AACD,IAAI,CAAC,GACJ;AACD,QAAM,qBAAqB,OAAQ,QAAS;AAC5C,YAAW,MAAM;AAChB,uBAAmB,UAAU;AAAA,EAC9B,GAAG,CAAE,QAAS,CAAE;AAEhB,YAAW,MAAM;AAChB,QAAK,YAAa;AACjB;AAAA,IACD;AACA,UAAM,YAAY,IAAI;AAAA,MACrB,UAAU,OAAO,UACd,OAAO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,QAI2C;AAAA;AAAA,IACtD;AACA,UAAM,iBAAiB,MAAM,QAAS,SAAU,IAC7C,YACA,CAAE,SAAU;AACf,mBAAe,QAAS,CAAE,aAAc;AACvC,YAAM,OAAO,SAAS,MAAO,GAAI;AAIjC,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;AAGxC,UACC,UAAU,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;AAE3C,gBAAW,MAAO;AAAA,QACjB;AAAA,QACA,IAEiF;AAAA;AAAA,UAGhF,mBAAmB,QAAS,GAAG,IAAK;AAAA;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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { useMemo, useSyncExternalStore } from '@wordpress/element';
|
|
5
|
-
const matchMediaCache = new Map();
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* A new MediaQueryList object for the media query
|
|
9
|
-
*
|
|
10
|
-
* @param {string} [query] Media Query.
|
|
11
|
-
* @return {MediaQueryList|null} A new object for the media query
|
|
12
|
-
*/
|
|
1
|
+
import { useMemo, useSyncExternalStore } from "@wordpress/element";
|
|
2
|
+
const matchMediaCache = /* @__PURE__ */ new Map();
|
|
13
3
|
function getMediaQueryList(query) {
|
|
14
4
|
if (!query) {
|
|
15
5
|
return null;
|
|
@@ -18,42 +8,43 @@ function getMediaQueryList(query) {
|
|
|
18
8
|
if (match) {
|
|
19
9
|
return match;
|
|
20
10
|
}
|
|
21
|
-
if (typeof window !==
|
|
11
|
+
if (typeof window !== "undefined" && typeof window.matchMedia === "function") {
|
|
22
12
|
match = window.matchMedia(query);
|
|
23
13
|
matchMediaCache.set(query, match);
|
|
24
14
|
return match;
|
|
25
15
|
}
|
|
26
16
|
return null;
|
|
27
17
|
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Runs a media query and returns its value when it changes.
|
|
31
|
-
*
|
|
32
|
-
* @param {string} [query] Media Query.
|
|
33
|
-
* @return {boolean} return value of the media query.
|
|
34
|
-
*/
|
|
35
|
-
export default function useMediaQuery(query) {
|
|
18
|
+
function useMediaQuery(query) {
|
|
36
19
|
const source = useMemo(() => {
|
|
37
20
|
const mediaQueryList = getMediaQueryList(query);
|
|
38
21
|
return {
|
|
39
22
|
/** @type {(onStoreChange: () => void) => () => void} */
|
|
40
23
|
subscribe(onStoreChange) {
|
|
41
24
|
if (!mediaQueryList) {
|
|
42
|
-
return () => {
|
|
25
|
+
return () => {
|
|
26
|
+
};
|
|
43
27
|
}
|
|
44
|
-
|
|
45
|
-
// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.
|
|
46
|
-
mediaQueryList.addEventListener?.('change', onStoreChange);
|
|
28
|
+
mediaQueryList.addEventListener?.("change", onStoreChange);
|
|
47
29
|
return () => {
|
|
48
|
-
mediaQueryList.removeEventListener?.(
|
|
30
|
+
mediaQueryList.removeEventListener?.(
|
|
31
|
+
"change",
|
|
32
|
+
onStoreChange
|
|
33
|
+
);
|
|
49
34
|
};
|
|
50
35
|
},
|
|
51
36
|
getValue() {
|
|
52
|
-
|
|
53
|
-
return (_mediaQueryList$match = mediaQueryList?.matches) !== null && _mediaQueryList$match !== void 0 ? _mediaQueryList$match : false;
|
|
37
|
+
return mediaQueryList?.matches ?? false;
|
|
54
38
|
}
|
|
55
39
|
};
|
|
56
40
|
}, [query]);
|
|
57
|
-
return useSyncExternalStore(
|
|
41
|
+
return useSyncExternalStore(
|
|
42
|
+
source.subscribe,
|
|
43
|
+
source.getValue,
|
|
44
|
+
() => false
|
|
45
|
+
);
|
|
58
46
|
}
|
|
59
|
-
|
|
47
|
+
export {
|
|
48
|
+
useMediaQuery as default
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-media-query/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\nconst matchMediaCache = new Map();\n\n/**\n * A new MediaQueryList object for the media query\n *\n * @param {string} [query] Media Query.\n * @return {MediaQueryList|null} A new object for the media query\n */\nfunction getMediaQueryList( query ) {\n\tif ( ! query ) {\n\t\treturn null;\n\t}\n\n\tlet match = matchMediaCache.get( query );\n\n\tif ( match ) {\n\t\treturn match;\n\t}\n\n\tif (\n\t\ttypeof window !== 'undefined' &&\n\t\ttypeof window.matchMedia === 'function'\n\t) {\n\t\tmatch = window.matchMedia( query );\n\t\tmatchMediaCache.set( query, match );\n\t\treturn match;\n\t}\n\n\treturn null;\n}\n\n/**\n * Runs a media query and returns its value when it changes.\n *\n * @param {string} [query] Media Query.\n * @return {boolean} return value of the media query.\n */\nexport default function useMediaQuery( query ) {\n\tconst source = useMemo( () => {\n\t\tconst mediaQueryList = getMediaQueryList( query );\n\n\t\treturn {\n\t\t\t/** @type {(onStoreChange: () => void) => () => void} */\n\t\t\tsubscribe( onStoreChange ) {\n\t\t\t\tif ( ! mediaQueryList ) {\n\t\t\t\t\treturn () => {};\n\t\t\t\t}\n\n\t\t\t\t// Avoid a fatal error when browsers don't support `addEventListener` on MediaQueryList.\n\t\t\t\tmediaQueryList.addEventListener?.( 'change', onStoreChange );\n\t\t\t\treturn () => {\n\t\t\t\t\tmediaQueryList.removeEventListener?.(\n\t\t\t\t\t\t'change',\n\t\t\t\t\t\tonStoreChange\n\t\t\t\t\t);\n\t\t\t\t};\n\t\t\t},\n\t\t\tgetValue() {\n\t\t\t\treturn mediaQueryList?.matches ?? false;\n\t\t\t},\n\t\t};\n\t}, [ query ] );\n\n\treturn useSyncExternalStore(\n\t\tsource.subscribe,\n\t\tsource.getValue,\n\t\t() => false\n\t);\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,SAAS,4BAA4B;AAE9C,MAAM,kBAAkB,oBAAI,IAAI;AAQhC,SAAS,kBAAmB,OAAQ;AACnC,MAAK,CAAE,OAAQ;AACd,WAAO;AAAA,EACR;AAEA,MAAI,QAAQ,gBAAgB,IAAK,KAAM;AAEvC,MAAK,OAAQ;AACZ,WAAO;AAAA,EACR;AAEA,MACC,OAAO,WAAW,eAClB,OAAO,OAAO,eAAe,YAC5B;AACD,YAAQ,OAAO,WAAY,KAAM;AACjC,oBAAgB,IAAK,OAAO,KAAM;AAClC,WAAO;AAAA,EACR;AAEA,SAAO;AACR;AAQe,SAAR,cAAgC,OAAQ;AAC9C,QAAM,SAAS,QAAS,MAAM;AAC7B,UAAM,iBAAiB,kBAAmB,KAAM;AAEhD,WAAO;AAAA;AAAA,MAEN,UAAW,eAAgB;AAC1B,YAAK,CAAE,gBAAiB;AACvB,iBAAO,MAAM;AAAA,UAAC;AAAA,QACf;AAGA,uBAAe,mBAAoB,UAAU,aAAc;AAC3D,eAAO,MAAM;AACZ,yBAAe;AAAA,YACd;AAAA,YACA;AAAA,UACD;AAAA,QACD;AAAA,MACD;AAAA,MACA,WAAW;AACV,eAAO,gBAAgB,WAAW;AAAA,MACnC;AAAA,IACD;AAAA,EACD,GAAG,CAAE,KAAM,CAAE;AAEb,SAAO;AAAA,IACN,OAAO;AAAA,IACP,OAAO;AAAA,IACP,MAAM;AAAA,EACP;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,90 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
* WordPress dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useRef, useCallback, useLayoutEffect } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
/* eslint-disable jsdoc/valid-types */
|
|
7
|
-
/**
|
|
8
|
-
* @template T
|
|
9
|
-
* @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef
|
|
10
|
-
*/
|
|
11
|
-
/* eslint-enable jsdoc/valid-types */
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @template T
|
|
15
|
-
* @param {import('react').Ref<T>} ref
|
|
16
|
-
* @param {T} value
|
|
17
|
-
*/
|
|
1
|
+
import { useRef, useCallback, useLayoutEffect } from "@wordpress/element";
|
|
18
2
|
function assignRef(ref, value) {
|
|
19
|
-
if (typeof ref ===
|
|
3
|
+
if (typeof ref === "function") {
|
|
20
4
|
ref(value);
|
|
21
|
-
} else if (ref && ref.hasOwnProperty(
|
|
22
|
-
|
|
23
|
-
/** @type {import('react').MutableRefObject<T>} */ref.current = value;
|
|
24
|
-
/* eslint-enable jsdoc/no-undefined-types */
|
|
5
|
+
} else if (ref && ref.hasOwnProperty("current")) {
|
|
6
|
+
ref.current = value;
|
|
25
7
|
}
|
|
26
8
|
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* Merges refs into one ref callback.
|
|
30
|
-
*
|
|
31
|
-
* It also ensures that the merged ref callbacks are only called when they
|
|
32
|
-
* change (as a result of a `useCallback` dependency update) OR when the ref
|
|
33
|
-
* value changes, just as React does when passing a single ref callback to the
|
|
34
|
-
* component.
|
|
35
|
-
*
|
|
36
|
-
* As expected, if you pass a new function on every render, the ref callback
|
|
37
|
-
* will be called after every render.
|
|
38
|
-
*
|
|
39
|
-
* If you don't wish a ref callback to be called after every render, wrap it
|
|
40
|
-
* with `useCallback( callback, dependencies )`. When a dependency changes, the
|
|
41
|
-
* old ref callback will be called with `null` and the new ref callback will be
|
|
42
|
-
* called with the same value.
|
|
43
|
-
*
|
|
44
|
-
* To make ref callbacks easier to use, you can also pass the result of
|
|
45
|
-
* `useRefEffect`, which makes cleanup easier by allowing you to return a
|
|
46
|
-
* cleanup function instead of handling `null`.
|
|
47
|
-
*
|
|
48
|
-
* It's also possible to _disable_ a ref (and its behaviour) by simply not
|
|
49
|
-
* passing the ref.
|
|
50
|
-
*
|
|
51
|
-
* ```jsx
|
|
52
|
-
* const ref = useRefEffect( ( node ) => {
|
|
53
|
-
* node.addEventListener( ... );
|
|
54
|
-
* return () => {
|
|
55
|
-
* node.removeEventListener( ... );
|
|
56
|
-
* };
|
|
57
|
-
* }, [ ...dependencies ] );
|
|
58
|
-
* const otherRef = useRef();
|
|
59
|
-
* const mergedRefs useMergeRefs( [
|
|
60
|
-
* enabled && ref,
|
|
61
|
-
* otherRef,
|
|
62
|
-
* ] );
|
|
63
|
-
* return <div ref={ mergedRefs } />;
|
|
64
|
-
* ```
|
|
65
|
-
*
|
|
66
|
-
* @template {import('react').Ref<any>} TRef
|
|
67
|
-
* @param {Array<TRef>} refs The refs to be merged.
|
|
68
|
-
*
|
|
69
|
-
* @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.
|
|
70
|
-
*/
|
|
71
|
-
export default function useMergeRefs(refs) {
|
|
9
|
+
function useMergeRefs(refs) {
|
|
72
10
|
const element = useRef();
|
|
73
11
|
const isAttachedRef = useRef(false);
|
|
74
12
|
const didElementChangeRef = useRef(false);
|
|
75
|
-
/* eslint-disable jsdoc/no-undefined-types */
|
|
76
|
-
/** @type {import('react').MutableRefObject<TRef[]>} */
|
|
77
|
-
/* eslint-enable jsdoc/no-undefined-types */
|
|
78
13
|
const previousRefsRef = useRef([]);
|
|
79
14
|
const currentRefsRef = useRef(refs);
|
|
80
|
-
|
|
81
|
-
// Update on render before the ref callback is called, so the ref callback
|
|
82
|
-
// always has access to the current refs.
|
|
83
15
|
currentRefsRef.current = refs;
|
|
84
|
-
|
|
85
|
-
// If any of the refs change, call the previous ref with `null` and the new
|
|
86
|
-
// ref with the node, except when the element changes in the same cycle, in
|
|
87
|
-
// which case the ref callbacks will already have been called.
|
|
88
16
|
useLayoutEffect(() => {
|
|
89
17
|
if (didElementChangeRef.current === false && isAttachedRef.current === true) {
|
|
90
18
|
refs.forEach((ref, index) => {
|
|
@@ -97,30 +25,20 @@ export default function useMergeRefs(refs) {
|
|
|
97
25
|
}
|
|
98
26
|
previousRefsRef.current = refs;
|
|
99
27
|
}, refs);
|
|
100
|
-
|
|
101
|
-
// No dependencies, must be reset after every render so ref callbacks are
|
|
102
|
-
// correctly called after a ref change.
|
|
103
28
|
useLayoutEffect(() => {
|
|
104
29
|
didElementChangeRef.current = false;
|
|
105
30
|
});
|
|
106
|
-
|
|
107
|
-
// There should be no dependencies so that `callback` is only called when
|
|
108
|
-
// the node changes.
|
|
109
|
-
return useCallback(value => {
|
|
110
|
-
// Update the element so it can be used when calling ref callbacks on a
|
|
111
|
-
// dependency change.
|
|
31
|
+
return useCallback((value) => {
|
|
112
32
|
assignRef(element, value);
|
|
113
33
|
didElementChangeRef.current = true;
|
|
114
34
|
isAttachedRef.current = value !== null;
|
|
115
|
-
|
|
116
|
-
// When an element changes, the current ref callback should be called
|
|
117
|
-
// with the new element and the previous one with `null`.
|
|
118
35
|
const refsToAssign = value ? currentRefsRef.current : previousRefsRef.current;
|
|
119
|
-
|
|
120
|
-
// Update the latest refs.
|
|
121
36
|
for (const ref of refsToAssign) {
|
|
122
37
|
assignRef(ref, value);
|
|
123
38
|
}
|
|
124
39
|
}, []);
|
|
125
40
|
}
|
|
126
|
-
|
|
41
|
+
export {
|
|
42
|
+
useMergeRefs as default
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-merge-refs/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useRef, useCallback, useLayoutEffect } from '@wordpress/element';\n\n/* eslint-disable jsdoc/valid-types */\n/**\n * @template T\n * @typedef {T extends import('react').Ref<infer R> ? R : never} TypeFromRef\n */\n/* eslint-enable jsdoc/valid-types */\n\n/**\n * @template T\n * @param {import('react').Ref<T>} ref\n * @param {T} value\n */\nfunction assignRef( ref, value ) {\n\tif ( typeof ref === 'function' ) {\n\t\tref( value );\n\t} else if ( ref && ref.hasOwnProperty( 'current' ) ) {\n\t\t/* eslint-disable jsdoc/no-undefined-types */\n\t\t/** @type {import('react').MutableRefObject<T>} */ ( ref ).current =\n\t\t\tvalue;\n\t\t/* eslint-enable jsdoc/no-undefined-types */\n\t}\n}\n\n/**\n * Merges refs into one ref callback.\n *\n * It also ensures that the merged ref callbacks are only called when they\n * change (as a result of a `useCallback` dependency update) OR when the ref\n * value changes, just as React does when passing a single ref callback to the\n * component.\n *\n * As expected, if you pass a new function on every render, the ref callback\n * will be called after every render.\n *\n * If you don't wish a ref callback to be called after every render, wrap it\n * with `useCallback( callback, dependencies )`. When a dependency changes, the\n * old ref callback will be called with `null` and the new ref callback will be\n * called with the same value.\n *\n * To make ref callbacks easier to use, you can also pass the result of\n * `useRefEffect`, which makes cleanup easier by allowing you to return a\n * cleanup function instead of handling `null`.\n *\n * It's also possible to _disable_ a ref (and its behaviour) by simply not\n * passing the ref.\n *\n * ```jsx\n * const ref = useRefEffect( ( node ) => {\n * node.addEventListener( ... );\n * return () => {\n * node.removeEventListener( ... );\n * };\n * }, [ ...dependencies ] );\n * const otherRef = useRef();\n * const mergedRefs useMergeRefs( [\n * enabled && ref,\n * otherRef,\n * ] );\n * return <div ref={ mergedRefs } />;\n * ```\n *\n * @template {import('react').Ref<any>} TRef\n * @param {Array<TRef>} refs The refs to be merged.\n *\n * @return {import('react').RefCallback<TypeFromRef<TRef>>} The merged ref callback.\n */\nexport default function useMergeRefs( refs ) {\n\tconst element = useRef();\n\tconst isAttachedRef = useRef( false );\n\tconst didElementChangeRef = useRef( false );\n\t/* eslint-disable jsdoc/no-undefined-types */\n\t/** @type {import('react').MutableRefObject<TRef[]>} */\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tconst previousRefsRef = useRef( [] );\n\tconst currentRefsRef = useRef( refs );\n\n\t// Update on render before the ref callback is called, so the ref callback\n\t// always has access to the current refs.\n\tcurrentRefsRef.current = refs;\n\n\t// If any of the refs change, call the previous ref with `null` and the new\n\t// ref with the node, except when the element changes in the same cycle, in\n\t// which case the ref callbacks will already have been called.\n\tuseLayoutEffect( () => {\n\t\tif (\n\t\t\tdidElementChangeRef.current === false &&\n\t\t\tisAttachedRef.current === true\n\t\t) {\n\t\t\trefs.forEach( ( ref, index ) => {\n\t\t\t\tconst previousRef = previousRefsRef.current[ index ];\n\t\t\t\tif ( ref !== previousRef ) {\n\t\t\t\t\tassignRef( previousRef, null );\n\t\t\t\t\tassignRef( ref, element.current );\n\t\t\t\t}\n\t\t\t} );\n\t\t}\n\n\t\tpreviousRefsRef.current = refs;\n\t}, refs );\n\n\t// No dependencies, must be reset after every render so ref callbacks are\n\t// correctly called after a ref change.\n\tuseLayoutEffect( () => {\n\t\tdidElementChangeRef.current = false;\n\t} );\n\n\t// There should be no dependencies so that `callback` is only called when\n\t// the node changes.\n\treturn useCallback( ( value ) => {\n\t\t// Update the element so it can be used when calling ref callbacks on a\n\t\t// dependency change.\n\t\tassignRef( element, value );\n\n\t\tdidElementChangeRef.current = true;\n\t\tisAttachedRef.current = value !== null;\n\n\t\t// When an element changes, the current ref callback should be called\n\t\t// with the new element and the previous one with `null`.\n\t\tconst refsToAssign = value\n\t\t\t? currentRefsRef.current\n\t\t\t: previousRefsRef.current;\n\n\t\t// Update the latest refs.\n\t\tfor ( const ref of refsToAssign ) {\n\t\t\tassignRef( ref, value );\n\t\t}\n\t}, [] );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,QAAQ,aAAa,uBAAuB;AAcrD,SAAS,UAAW,KAAK,OAAQ;AAChC,MAAK,OAAO,QAAQ,YAAa;AAChC,QAAK,KAAM;AAAA,EACZ,WAAY,OAAO,IAAI,eAAgB,SAAU,GAAI;AAED,IAAE,IAAM,UAC1D;AAAA,EAEF;AACD;AA6Ce,SAAR,aAA+B,MAAO;AAC5C,QAAM,UAAU,OAAO;AACvB,QAAM,gBAAgB,OAAQ,KAAM;AACpC,QAAM,sBAAsB,OAAQ,KAAM;AAI1C,QAAM,kBAAkB,OAAQ,CAAC,CAAE;AACnC,QAAM,iBAAiB,OAAQ,IAAK;AAIpC,iBAAe,UAAU;AAKzB,kBAAiB,MAAM;AACtB,QACC,oBAAoB,YAAY,SAChC,cAAc,YAAY,MACzB;AACD,WAAK,QAAS,CAAE,KAAK,UAAW;AAC/B,cAAM,cAAc,gBAAgB,QAAS,KAAM;AACnD,YAAK,QAAQ,aAAc;AAC1B,oBAAW,aAAa,IAAK;AAC7B,oBAAW,KAAK,QAAQ,OAAQ;AAAA,QACjC;AAAA,MACD,CAAE;AAAA,IACH;AAEA,oBAAgB,UAAU;AAAA,EAC3B,GAAG,IAAK;AAIR,kBAAiB,MAAM;AACtB,wBAAoB,UAAU;AAAA,EAC/B,CAAE;AAIF,SAAO,YAAa,CAAE,UAAW;AAGhC,cAAW,SAAS,KAAM;AAE1B,wBAAoB,UAAU;AAC9B,kBAAc,UAAU,UAAU;AAIlC,UAAM,eAAe,QAClB,eAAe,UACf,gBAAgB;AAGnB,eAAY,OAAO,cAAe;AACjC,gBAAW,KAAK,KAAM;AAAA,IACvB;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* React hook that lets you observe an entry in an `ObservableMap`. The hook returns the
|
|
12
|
-
* current value corresponding to the key, or `undefined` when there is no value stored.
|
|
13
|
-
* It also observes changes to the value and triggers an update of the calling component
|
|
14
|
-
* in case the value changes.
|
|
15
|
-
*
|
|
16
|
-
* @template K The type of the keys in the map.
|
|
17
|
-
* @template V The type of the values in the map.
|
|
18
|
-
* @param map The `ObservableMap` to observe.
|
|
19
|
-
* @param name The map key to observe.
|
|
20
|
-
* @return The value corresponding to the map key requested.
|
|
21
|
-
*/
|
|
22
|
-
export default function useObservableValue(map, name) {
|
|
23
|
-
const [subscribe, getValue] = useMemo(() => [listener => map.subscribe(name, listener), () => map.get(name)], [map, name]);
|
|
1
|
+
import { useMemo, useSyncExternalStore } from "@wordpress/element";
|
|
2
|
+
function useObservableValue(map, name) {
|
|
3
|
+
const [subscribe, getValue] = useMemo(
|
|
4
|
+
() => [
|
|
5
|
+
(listener) => map.subscribe(name, listener),
|
|
6
|
+
() => map.get(name)
|
|
7
|
+
],
|
|
8
|
+
[map, name]
|
|
9
|
+
);
|
|
24
10
|
return useSyncExternalStore(subscribe, getValue, getValue);
|
|
25
11
|
}
|
|
26
|
-
|
|
12
|
+
export {
|
|
13
|
+
useObservableValue as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-observable-value/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useMemo, useSyncExternalStore } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type { ObservableMap } from '../../utils/observable-map';\n\n/**\n * React hook that lets you observe an entry in an `ObservableMap`. The hook returns the\n * current value corresponding to the key, or `undefined` when there is no value stored.\n * It also observes changes to the value and triggers an update of the calling component\n * in case the value changes.\n *\n * @template K The type of the keys in the map.\n * @template V The type of the values in the map.\n * @param map The `ObservableMap` to observe.\n * @param name The map key to observe.\n * @return The value corresponding to the map key requested.\n */\nexport default function useObservableValue< K, V >(\n\tmap: ObservableMap< K, V >,\n\tname: K\n): V | undefined {\n\tconst [ subscribe, getValue ] = useMemo(\n\t\t() => [\n\t\t\t( listener: () => void ) => map.subscribe( name, listener ),\n\t\t\t() => map.get( name ),\n\t\t],\n\t\t[ map, name ]\n\t);\n\treturn useSyncExternalStore( subscribe, getValue, getValue );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,SAAS,4BAA4B;AAmB/B,SAAR,mBACN,KACA,MACgB;AAChB,QAAM,CAAE,WAAW,QAAS,IAAI;AAAA,IAC/B,MAAM;AAAA,MACL,CAAE,aAA0B,IAAI,UAAW,MAAM,QAAS;AAAA,MAC1D,MAAM,IAAI,IAAK,IAAK;AAAA,IACrB;AAAA,IACA,CAAE,KAAK,IAAK;AAAA,EACb;AACA,SAAO,qBAAsB,WAAW,UAAU,QAAS;AAC5D;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,21 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
/**
|
|
8
|
-
* Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]
|
|
9
|
-
*
|
|
10
|
-
* @return {string} return current color scheme.
|
|
11
|
-
*/
|
|
1
|
+
import { useState, useEffect } from "@wordpress/element";
|
|
2
|
+
import {
|
|
3
|
+
subscribePreferredColorScheme,
|
|
4
|
+
isInitialColorSchemeDark
|
|
5
|
+
} from "@wordpress/react-native-bridge";
|
|
12
6
|
function usePreferredColorScheme() {
|
|
13
|
-
const [currentColorScheme, setCurrentColorScheme] = useState(
|
|
7
|
+
const [currentColorScheme, setCurrentColorScheme] = useState(
|
|
8
|
+
isInitialColorSchemeDark ? "dark" : "light"
|
|
9
|
+
);
|
|
14
10
|
useEffect(() => {
|
|
15
|
-
subscribePreferredColorScheme(({
|
|
16
|
-
isPreferredColorSchemeDark
|
|
17
|
-
}) => {
|
|
18
|
-
const colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';
|
|
11
|
+
subscribePreferredColorScheme(({ isPreferredColorSchemeDark }) => {
|
|
12
|
+
const colorScheme = isPreferredColorSchemeDark ? "dark" : "light";
|
|
19
13
|
if (colorScheme !== currentColorScheme) {
|
|
20
14
|
setCurrentColorScheme(colorScheme);
|
|
21
15
|
}
|
|
@@ -23,5 +17,8 @@ function usePreferredColorScheme() {
|
|
|
23
17
|
});
|
|
24
18
|
return currentColorScheme;
|
|
25
19
|
}
|
|
26
|
-
|
|
27
|
-
|
|
20
|
+
var index_android_default = usePreferredColorScheme;
|
|
21
|
+
export {
|
|
22
|
+
index_android_default as default
|
|
23
|
+
};
|
|
24
|
+
//# sourceMappingURL=index.android.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-preferred-color-scheme/index.android.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { useState, useEffect } from '@wordpress/element';\nimport {\n\tsubscribePreferredColorScheme,\n\tisInitialColorSchemeDark,\n} from '@wordpress/react-native-bridge';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nfunction usePreferredColorScheme() {\n\tconst [ currentColorScheme, setCurrentColorScheme ] = useState(\n\t\tisInitialColorSchemeDark ? 'dark' : 'light'\n\t);\n\tuseEffect( () => {\n\t\tsubscribePreferredColorScheme( ( { isPreferredColorSchemeDark } ) => {\n\t\t\tconst colorScheme = isPreferredColorSchemeDark ? 'dark' : 'light';\n\t\t\tif ( colorScheme !== currentColorScheme ) {\n\t\t\t\tsetCurrentColorScheme( colorScheme );\n\t\t\t}\n\t\t} );\n\t} );\n\treturn currentColorScheme;\n}\n\nexport default usePreferredColorScheme;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,UAAU,iBAAiB;AACpC;AAAA,EACC;AAAA,EACA;AAAA,OACM;AAOP,SAAS,0BAA0B;AAClC,QAAM,CAAE,oBAAoB,qBAAsB,IAAI;AAAA,IACrD,2BAA2B,SAAS;AAAA,EACrC;AACA,YAAW,MAAM;AAChB,kCAA+B,CAAE,EAAE,2BAA2B,MAAO;AACpE,YAAM,cAAc,6BAA6B,SAAS;AAC1D,UAAK,gBAAgB,oBAAqB;AACzC,8BAAuB,WAAY;AAAA,MACpC;AAAA,IACD,CAAE;AAAA,EACH,CAAE;AACF,SAAO;AACR;AAEA,IAAO,wBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
* External dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { useColorScheme } from 'react-native';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]
|
|
8
|
-
*
|
|
9
|
-
* @return {string} return current color scheme.
|
|
10
|
-
*/
|
|
1
|
+
import { useColorScheme } from "react-native";
|
|
11
2
|
const usePreferredColorScheme = useColorScheme;
|
|
12
|
-
|
|
13
|
-
|
|
3
|
+
var index_ios_default = usePreferredColorScheme;
|
|
4
|
+
export {
|
|
5
|
+
index_ios_default as default
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=index.ios.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-preferred-color-scheme/index.ios.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { useColorScheme } from 'react-native';\n\n/**\n * Returns the color scheme value when it changes. Possible values: [ 'light', 'dark' ]\n *\n * @return {string} return current color scheme.\n */\nconst usePreferredColorScheme = useColorScheme;\n\nexport default usePreferredColorScheme;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,sBAAsB;AAO/B,MAAM,0BAA0B;AAEhC,IAAO,oBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|