@wordpress/compose 7.32.0 → 7.32.1-next.b8c8708f3.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/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,45 +1,33 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
*/
|
|
10
|
-
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A Higher Order Component used to provide and manage internal component state
|
|
14
|
-
* via props.
|
|
15
|
-
*
|
|
16
|
-
* @deprecated Use `useState` instead.
|
|
17
|
-
*
|
|
18
|
-
* @param {any} initialState Optional initial state of the component.
|
|
19
|
-
*
|
|
20
|
-
* @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.
|
|
21
|
-
*/
|
|
22
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
23
|
-
export default function withState(initialState = {}) {
|
|
24
|
-
deprecated('wp.compose.withState', {
|
|
25
|
-
since: '5.8',
|
|
26
|
-
alternative: 'wp.element.useState'
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { Component } from "@wordpress/element";
|
|
3
|
+
import deprecated from "@wordpress/deprecated";
|
|
4
|
+
import { createHigherOrderComponent } from "../../utils/create-higher-order-component";
|
|
5
|
+
function withState(initialState = {}) {
|
|
6
|
+
deprecated("wp.compose.withState", {
|
|
7
|
+
since: "5.8",
|
|
8
|
+
alternative: "wp.element.useState"
|
|
27
9
|
});
|
|
28
|
-
return createHigherOrderComponent(OriginalComponent => {
|
|
10
|
+
return createHigherOrderComponent((OriginalComponent) => {
|
|
29
11
|
return class WrappedComponent extends Component {
|
|
30
|
-
constructor(
|
|
12
|
+
constructor(props) {
|
|
31
13
|
super(props);
|
|
32
14
|
this.setState = this.setState.bind(this);
|
|
33
15
|
this.state = initialState;
|
|
34
16
|
}
|
|
35
17
|
render() {
|
|
36
|
-
return
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
18
|
+
return /* @__PURE__ */ jsx(
|
|
19
|
+
OriginalComponent,
|
|
20
|
+
{
|
|
21
|
+
...this.props,
|
|
22
|
+
...this.state,
|
|
23
|
+
setState: this.setState
|
|
24
|
+
}
|
|
25
|
+
);
|
|
41
26
|
}
|
|
42
27
|
};
|
|
43
|
-
},
|
|
28
|
+
}, "withState");
|
|
44
29
|
}
|
|
45
|
-
|
|
30
|
+
export {
|
|
31
|
+
withState as default
|
|
32
|
+
};
|
|
33
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/higher-order/with-state/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * A Higher Order Component used to provide and manage internal component state\n * via props.\n *\n * @deprecated Use `useState` instead.\n *\n * @param {any} initialState Optional initial state of the component.\n *\n * @return {any} A higher order component wrapper accepting a component that takes the state props + its own props + `setState` and returning a component that only accepts the own props.\n */\nexport default function withState( initialState = {} ) {\n\tdeprecated( 'wp.compose.withState', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.element.useState',\n\t} );\n\n\treturn createHigherOrderComponent( ( OriginalComponent ) => {\n\t\treturn class WrappedComponent extends Component {\n\t\t\tconstructor( /** @type {any} */ props ) {\n\t\t\t\tsuper( props );\n\n\t\t\t\tthis.setState = this.setState.bind( this );\n\n\t\t\t\tthis.state = initialState;\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\t{ ...this.state }\n\t\t\t\t\t\tsetState={ this.setState }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t}, 'withState' );\n}\n"],
|
|
5
|
+
"mappings": "AAuCK;AApCL,SAAS,iBAAiB;AAC1B,OAAO,gBAAgB;AAKvB,SAAS,kCAAkC;AAY5B,SAAR,UAA4B,eAAe,CAAC,GAAI;AACtD,aAAY,wBAAwB;AAAA,IACnC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,SAAO,2BAA4B,CAAE,sBAAuB;AAC3D,WAAO,MAAM,yBAAyB,UAAU;AAAA,MAC/C,YAAgC,OAAQ;AACvC,cAAO,KAAM;AAEb,aAAK,WAAW,KAAK,SAAS,KAAM,IAAK;AAEzC,aAAK,QAAQ;AAAA,MACd;AAAA,MAEA,SAAS;AACR,eACC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG,KAAK;AAAA,YACR,GAAG,KAAK;AAAA,YACV,UAAW,KAAK;AAAA;AAAA,QACjB;AAAA,MAEF;AAAA,IACD;AAAA,EACD,GAAG,WAAY;AAChB;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,15 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { flushSync, useEffect, useState } from '@wordpress/element';
|
|
5
|
-
import { createQueue } from '@wordpress/priority-queue';
|
|
6
|
-
/**
|
|
7
|
-
* Returns the first items from list that are present on state.
|
|
8
|
-
*
|
|
9
|
-
* @param list New array.
|
|
10
|
-
* @param state Current state.
|
|
11
|
-
* @return First items present in state.
|
|
12
|
-
*/
|
|
1
|
+
import { flushSync, useEffect, useState } from "@wordpress/element";
|
|
2
|
+
import { createQueue } from "@wordpress/priority-queue";
|
|
13
3
|
function getFirstItemsPresentInState(list, state) {
|
|
14
4
|
const firstItems = [];
|
|
15
5
|
for (let i = 0; i < list.length; i++) {
|
|
@@ -21,35 +11,25 @@ function getFirstItemsPresentInState(list, state) {
|
|
|
21
11
|
}
|
|
22
12
|
return firstItems;
|
|
23
13
|
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
* React hook returns an array which items get asynchronously appended from a source array.
|
|
27
|
-
* This behavior is useful if we want to render a list of items asynchronously for performance reasons.
|
|
28
|
-
*
|
|
29
|
-
* @param list Source array.
|
|
30
|
-
* @param config Configuration object.
|
|
31
|
-
*
|
|
32
|
-
* @return Async array.
|
|
33
|
-
*/
|
|
34
|
-
function useAsyncList(list, config = {
|
|
35
|
-
step: 1
|
|
36
|
-
}) {
|
|
37
|
-
const {
|
|
38
|
-
step = 1
|
|
39
|
-
} = config;
|
|
14
|
+
function useAsyncList(list, config = { step: 1 }) {
|
|
15
|
+
const { step = 1 } = config;
|
|
40
16
|
const [current, setCurrent] = useState([]);
|
|
41
17
|
useEffect(() => {
|
|
42
|
-
// On reset, we keep the first items that were previously rendered.
|
|
43
18
|
let firstItems = getFirstItemsPresentInState(list, current);
|
|
44
19
|
if (firstItems.length < step) {
|
|
45
|
-
firstItems = firstItems.concat(
|
|
20
|
+
firstItems = firstItems.concat(
|
|
21
|
+
list.slice(firstItems.length, step)
|
|
22
|
+
);
|
|
46
23
|
}
|
|
47
24
|
setCurrent(firstItems);
|
|
48
25
|
const asyncQueue = createQueue();
|
|
49
26
|
for (let i = firstItems.length; i < list.length; i += step) {
|
|
50
27
|
asyncQueue.add({}, () => {
|
|
51
28
|
flushSync(() => {
|
|
52
|
-
setCurrent(state => [
|
|
29
|
+
setCurrent((state) => [
|
|
30
|
+
...state,
|
|
31
|
+
...list.slice(i, i + step)
|
|
32
|
+
]);
|
|
53
33
|
});
|
|
54
34
|
});
|
|
55
35
|
}
|
|
@@ -57,5 +37,8 @@ function useAsyncList(list, config = {
|
|
|
57
37
|
}, [list]);
|
|
58
38
|
return current;
|
|
59
39
|
}
|
|
60
|
-
|
|
61
|
-
|
|
40
|
+
var use_async_list_default = useAsyncList;
|
|
41
|
+
export {
|
|
42
|
+
use_async_list_default as default
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-async-list/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { flushSync, useEffect, useState } from '@wordpress/element';\nimport { createQueue } from '@wordpress/priority-queue';\n\ntype AsyncListConfig = {\n\tstep: number;\n};\n\n/**\n * Returns the first items from list that are present on state.\n *\n * @param list New array.\n * @param state Current state.\n * @return First items present in state.\n */\nfunction getFirstItemsPresentInState< T >( list: T[], state: T[] ): T[] {\n\tconst firstItems = [];\n\n\tfor ( let i = 0; i < list.length; i++ ) {\n\t\tconst item = list[ i ];\n\t\tif ( ! state.includes( item ) ) {\n\t\t\tbreak;\n\t\t}\n\n\t\tfirstItems.push( item );\n\t}\n\n\treturn firstItems;\n}\n\n/**\n * React hook returns an array which items get asynchronously appended from a source array.\n * This behavior is useful if we want to render a list of items asynchronously for performance reasons.\n *\n * @param list Source array.\n * @param config Configuration object.\n *\n * @return Async array.\n */\nfunction useAsyncList< T >(\n\tlist: T[],\n\tconfig: AsyncListConfig = { step: 1 }\n): T[] {\n\tconst { step = 1 } = config;\n\tconst [ current, setCurrent ] = useState< T[] >( [] );\n\n\tuseEffect( () => {\n\t\t// On reset, we keep the first items that were previously rendered.\n\t\tlet firstItems = getFirstItemsPresentInState( list, current );\n\t\tif ( firstItems.length < step ) {\n\t\t\tfirstItems = firstItems.concat(\n\t\t\t\tlist.slice( firstItems.length, step )\n\t\t\t);\n\t\t}\n\t\tsetCurrent( firstItems );\n\n\t\tconst asyncQueue = createQueue();\n\t\tfor ( let i = firstItems.length; i < list.length; i += step ) {\n\t\t\tasyncQueue.add( {}, () => {\n\t\t\t\tflushSync( () => {\n\t\t\t\t\tsetCurrent( ( state ) => [\n\t\t\t\t\t\t...state,\n\t\t\t\t\t\t...list.slice( i, i + step ),\n\t\t\t\t\t] );\n\t\t\t\t} );\n\t\t\t} );\n\t\t}\n\n\t\treturn () => asyncQueue.reset();\n\t}, [ list ] );\n\n\treturn current;\n}\n\nexport default useAsyncList;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,WAAW,WAAW,gBAAgB;AAC/C,SAAS,mBAAmB;AAa5B,SAAS,4BAAkC,MAAW,OAAkB;AACvE,QAAM,aAAa,CAAC;AAEpB,WAAU,IAAI,GAAG,IAAI,KAAK,QAAQ,KAAM;AACvC,UAAM,OAAO,KAAM,CAAE;AACrB,QAAK,CAAE,MAAM,SAAU,IAAK,GAAI;AAC/B;AAAA,IACD;AAEA,eAAW,KAAM,IAAK;AAAA,EACvB;AAEA,SAAO;AACR;AAWA,SAAS,aACR,MACA,SAA0B,EAAE,MAAM,EAAE,GAC9B;AACN,QAAM,EAAE,OAAO,EAAE,IAAI;AACrB,QAAM,CAAE,SAAS,UAAW,IAAI,SAAiB,CAAC,CAAE;AAEpD,YAAW,MAAM;AAEhB,QAAI,aAAa,4BAA6B,MAAM,OAAQ;AAC5D,QAAK,WAAW,SAAS,MAAO;AAC/B,mBAAa,WAAW;AAAA,QACvB,KAAK,MAAO,WAAW,QAAQ,IAAK;AAAA,MACrC;AAAA,IACD;AACA,eAAY,UAAW;AAEvB,UAAM,aAAa,YAAY;AAC/B,aAAU,IAAI,WAAW,QAAQ,IAAI,KAAK,QAAQ,KAAK,MAAO;AAC7D,iBAAW,IAAK,CAAC,GAAG,MAAM;AACzB,kBAAW,MAAM;AAChB,qBAAY,CAAE,UAAW;AAAA,YACxB,GAAG;AAAA,YACH,GAAG,KAAK,MAAO,GAAG,IAAI,IAAK;AAAA,UAC5B,CAAE;AAAA,QACH,CAAE;AAAA,MACH,CAAE;AAAA,IACH;AAEA,WAAO,MAAM,WAAW,MAAM;AAAA,EAC/B,GAAG,CAAE,IAAK,CAAE;AAEZ,SAAO;AACR;AAEA,IAAO,yBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,88 +1,44 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
import { focus } from '@wordpress/dom';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import useRefEffect from '../use-ref-effect';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* In Dialogs/modals, the tabbing must be constrained to the content of
|
|
13
|
-
* the wrapper element. This hook adds the behavior to the returned ref.
|
|
14
|
-
*
|
|
15
|
-
* @return {import('react').RefCallback<Element>} Element Ref.
|
|
16
|
-
*
|
|
17
|
-
* @example
|
|
18
|
-
* ```js
|
|
19
|
-
* import { useConstrainedTabbing } from '@wordpress/compose';
|
|
20
|
-
*
|
|
21
|
-
* const ConstrainedTabbingExample = () => {
|
|
22
|
-
* const constrainedTabbingRef = useConstrainedTabbing()
|
|
23
|
-
* return (
|
|
24
|
-
* <div ref={ constrainedTabbingRef }>
|
|
25
|
-
* <Button />
|
|
26
|
-
* <Button />
|
|
27
|
-
* </div>
|
|
28
|
-
* );
|
|
29
|
-
* }
|
|
30
|
-
* ```
|
|
31
|
-
*/
|
|
1
|
+
import { focus } from "@wordpress/dom";
|
|
2
|
+
import useRefEffect from "../use-ref-effect";
|
|
32
3
|
function useConstrainedTabbing() {
|
|
33
|
-
return useRefEffect((
|
|
34
|
-
function onKeyDown(
|
|
35
|
-
const {
|
|
36
|
-
|
|
37
|
-
shiftKey,
|
|
38
|
-
target
|
|
39
|
-
} = event;
|
|
40
|
-
if (key !== 'Tab') {
|
|
4
|
+
return useRefEffect((node) => {
|
|
5
|
+
function onKeyDown(event) {
|
|
6
|
+
const { key, shiftKey, target } = event;
|
|
7
|
+
if (key !== "Tab") {
|
|
41
8
|
return;
|
|
42
9
|
}
|
|
43
|
-
const action = shiftKey ?
|
|
44
|
-
const nextElement = focus.tabbable[action](
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (/** @type {HTMLElement} */target.contains(nextElement)) {
|
|
10
|
+
const action = shiftKey ? "findPrevious" : "findNext";
|
|
11
|
+
const nextElement = focus.tabbable[action](
|
|
12
|
+
/** @type {HTMLElement} */
|
|
13
|
+
target
|
|
14
|
+
) || null;
|
|
15
|
+
if (
|
|
16
|
+
/** @type {HTMLElement} */
|
|
17
|
+
target.contains(nextElement)
|
|
18
|
+
) {
|
|
53
19
|
event.preventDefault();
|
|
54
20
|
nextElement?.focus();
|
|
55
21
|
return;
|
|
56
22
|
}
|
|
57
|
-
|
|
58
|
-
// If the element that is about to receive focus is inside the
|
|
59
|
-
// area, rely on native browsers behavior and let tabbing follow
|
|
60
|
-
// the native tab sequence.
|
|
61
23
|
if (node.contains(nextElement)) {
|
|
62
24
|
return;
|
|
63
25
|
}
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
// the area, depending on the direction. Without preventing default
|
|
68
|
-
// behaviour, the browser will then move focus to the next element.
|
|
69
|
-
const domAction = shiftKey ? 'append' : 'prepend';
|
|
70
|
-
const {
|
|
71
|
-
ownerDocument
|
|
72
|
-
} = node;
|
|
73
|
-
const trap = ownerDocument.createElement('div');
|
|
26
|
+
const domAction = shiftKey ? "append" : "prepend";
|
|
27
|
+
const { ownerDocument } = node;
|
|
28
|
+
const trap = ownerDocument.createElement("div");
|
|
74
29
|
trap.tabIndex = -1;
|
|
75
30
|
node[domAction](trap);
|
|
76
|
-
|
|
77
|
-
// Remove itself when the trap loses focus.
|
|
78
|
-
trap.addEventListener('blur', () => node.removeChild(trap));
|
|
31
|
+
trap.addEventListener("blur", () => node.removeChild(trap));
|
|
79
32
|
trap.focus();
|
|
80
33
|
}
|
|
81
|
-
node.addEventListener(
|
|
34
|
+
node.addEventListener("keydown", onKeyDown);
|
|
82
35
|
return () => {
|
|
83
|
-
node.removeEventListener(
|
|
36
|
+
node.removeEventListener("keydown", onKeyDown);
|
|
84
37
|
};
|
|
85
38
|
}, []);
|
|
86
39
|
}
|
|
87
|
-
|
|
88
|
-
|
|
40
|
+
var use_constrained_tabbing_default = useConstrainedTabbing;
|
|
41
|
+
export {
|
|
42
|
+
use_constrained_tabbing_default as default
|
|
43
|
+
};
|
|
44
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-constrained-tabbing/index.js"],
|
|
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 {import('react').RefCallback<Element>} Element Ref.\n *\n * @example\n * ```js\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() {\n\treturn useRefEffect( ( /** @type {HTMLElement} */ node ) => {\n\t\tfunction onKeyDown( /** @type {KeyboardEvent} */ event ) {\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 ](\n\t\t\t\t\t/** @type {HTMLElement} */ ( target )\n\t\t\t\t) || 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 (\n\t\t\t\t/** @type {HTMLElement} */ ( target ).contains( nextElement )\n\t\t\t) {\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,wBAAwB;AAChC,SAAO,aAAc,CAA6B,SAAU;AAC3D,aAAS,UAAwC,OAAQ;AACxD,YAAM,EAAE,KAAK,UAAU,OAAO,IAAI;AAElC,UAAK,QAAQ,OAAQ;AACpB;AAAA,MACD;AAEA,YAAM,SAAS,WAAW,iBAAiB;AAC3C,YAAM,cACL,MAAM,SAAU,MAAO;AAAA;AAAA,QACO;AAAA,MAC9B,KAAK;AAQN;AAAA;AAAA,QAC8B,OAAS,SAAU,WAAY;AAAA,QAC3D;AACD,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,61 +1,25 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
*/
|
|
9
|
-
import { useRef, useEffect, useState } from '@wordpress/element';
|
|
10
|
-
import deprecated from '@wordpress/deprecated';
|
|
11
|
-
|
|
12
|
-
/* eslint-disable jsdoc/no-undefined-types */
|
|
13
|
-
/**
|
|
14
|
-
* Copies the text to the clipboard when the element is clicked.
|
|
15
|
-
*
|
|
16
|
-
* @deprecated
|
|
17
|
-
*
|
|
18
|
-
* @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.
|
|
19
|
-
* @param {string|Function} text The text to copy.
|
|
20
|
-
* @param {number} [timeout] Optional timeout to reset the returned
|
|
21
|
-
* state. 4 seconds by default.
|
|
22
|
-
*
|
|
23
|
-
* @return {boolean} Whether or not the text has been copied. Resets after the
|
|
24
|
-
* timeout.
|
|
25
|
-
*/
|
|
26
|
-
export default function useCopyOnClick(ref, text, timeout = 4000) {
|
|
27
|
-
/* eslint-enable jsdoc/no-undefined-types */
|
|
28
|
-
deprecated('wp.compose.useCopyOnClick', {
|
|
29
|
-
since: '5.8',
|
|
30
|
-
alternative: 'wp.compose.useCopyToClipboard'
|
|
1
|
+
import Clipboard from "clipboard";
|
|
2
|
+
import { useRef, useEffect, useState } from "@wordpress/element";
|
|
3
|
+
import deprecated from "@wordpress/deprecated";
|
|
4
|
+
function useCopyOnClick(ref, text, timeout = 4e3) {
|
|
5
|
+
deprecated("wp.compose.useCopyOnClick", {
|
|
6
|
+
since: "5.8",
|
|
7
|
+
alternative: "wp.compose.useCopyToClipboard"
|
|
31
8
|
});
|
|
32
|
-
|
|
33
|
-
/** @type {import('react').MutableRefObject<Clipboard | undefined>} */
|
|
34
9
|
const clipboardRef = useRef();
|
|
35
10
|
const [hasCopied, setHasCopied] = useState(false);
|
|
36
11
|
useEffect(() => {
|
|
37
|
-
/** @type {number | undefined} */
|
|
38
12
|
let timeoutId;
|
|
39
13
|
if (!ref.current) {
|
|
40
14
|
return;
|
|
41
15
|
}
|
|
42
|
-
|
|
43
|
-
// Clipboard listens to click events.
|
|
44
16
|
clipboardRef.current = new Clipboard(ref.current, {
|
|
45
|
-
text: () => typeof text ===
|
|
17
|
+
text: () => typeof text === "function" ? text() : text
|
|
46
18
|
});
|
|
47
|
-
clipboardRef.current.on(
|
|
48
|
-
clearSelection,
|
|
49
|
-
trigger
|
|
50
|
-
}) => {
|
|
51
|
-
// Clearing selection will move focus back to the triggering button,
|
|
52
|
-
// ensuring that it is not reset to the body, and further that it is
|
|
53
|
-
// kept within the rendered node.
|
|
19
|
+
clipboardRef.current.on("success", ({ clearSelection, trigger }) => {
|
|
54
20
|
clearSelection();
|
|
55
|
-
|
|
56
|
-
// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
|
|
57
21
|
if (trigger) {
|
|
58
|
-
|
|
22
|
+
trigger.focus();
|
|
59
23
|
}
|
|
60
24
|
if (timeout) {
|
|
61
25
|
setHasCopied(true);
|
|
@@ -72,4 +36,7 @@ export default function useCopyOnClick(ref, text, timeout = 4000) {
|
|
|
72
36
|
}, [text, timeout, setHasCopied]);
|
|
73
37
|
return hasCopied;
|
|
74
38
|
}
|
|
75
|
-
|
|
39
|
+
export {
|
|
40
|
+
useCopyOnClick as default
|
|
41
|
+
};
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-copy-on-click/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useState } from '@wordpress/element';\nimport deprecated from '@wordpress/deprecated';\n\n/* eslint-disable jsdoc/no-undefined-types */\n/**\n * Copies the text to the clipboard when the element is clicked.\n *\n * @deprecated\n *\n * @param {import('react').RefObject<string | Element | NodeListOf<Element>>} ref Reference with the element.\n * @param {string|Function} text The text to copy.\n * @param {number} [timeout] Optional timeout to reset the returned\n * state. 4 seconds by default.\n *\n * @return {boolean} Whether or not the text has been copied. Resets after the\n * timeout.\n */\nexport default function useCopyOnClick( ref, text, timeout = 4000 ) {\n\t/* eslint-enable jsdoc/no-undefined-types */\n\tdeprecated( 'wp.compose.useCopyOnClick', {\n\t\tsince: '5.8',\n\t\talternative: 'wp.compose.useCopyToClipboard',\n\t} );\n\n\t/** @type {import('react').MutableRefObject<Clipboard | undefined>} */\n\tconst clipboardRef = useRef();\n\tconst [ hasCopied, setHasCopied ] = useState( false );\n\n\tuseEffect( () => {\n\t\t/** @type {number | undefined} */\n\t\tlet timeoutId;\n\n\t\tif ( ! ref.current ) {\n\t\t\treturn;\n\t\t}\n\n\t\t// Clipboard listens to click events.\n\t\tclipboardRef.current = new Clipboard( ref.current, {\n\t\t\ttext: () => ( typeof text === 'function' ? text() : text ),\n\t\t} );\n\n\t\tclipboardRef.current.on( 'success', ( { clearSelection, trigger } ) => {\n\t\t\t// Clearing selection will move focus back to the triggering button,\n\t\t\t// ensuring that it is not reset to the body, and further that it is\n\t\t\t// kept within the rendered node.\n\t\t\tclearSelection();\n\n\t\t\t// Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680\n\t\t\tif ( trigger ) {\n\t\t\t\t/** @type {HTMLElement} */ ( trigger ).focus();\n\t\t\t}\n\n\t\t\tif ( timeout ) {\n\t\t\t\tsetHasCopied( true );\n\t\t\t\tclearTimeout( timeoutId );\n\t\t\t\ttimeoutId = setTimeout( () => setHasCopied( false ), timeout );\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tif ( clipboardRef.current ) {\n\t\t\t\tclipboardRef.current.destroy();\n\t\t\t}\n\t\t\tclearTimeout( timeoutId );\n\t\t};\n\t}, [ text, timeout, setHasCopied ] );\n\n\treturn hasCopied;\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,eAAe;AAKtB,SAAS,QAAQ,WAAW,gBAAgB;AAC5C,OAAO,gBAAgB;AAgBR,SAAR,eAAiC,KAAK,MAAM,UAAU,KAAO;AAEnE,aAAY,6BAA6B;AAAA,IACxC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAGF,QAAM,eAAe,OAAO;AAC5B,QAAM,CAAE,WAAW,YAAa,IAAI,SAAU,KAAM;AAEpD,YAAW,MAAM;AAEhB,QAAI;AAEJ,QAAK,CAAE,IAAI,SAAU;AACpB;AAAA,IACD;AAGA,iBAAa,UAAU,IAAI,UAAW,IAAI,SAAS;AAAA,MAClD,MAAM,MAAQ,OAAO,SAAS,aAAa,KAAK,IAAI;AAAA,IACrD,CAAE;AAEF,iBAAa,QAAQ,GAAI,WAAW,CAAE,EAAE,gBAAgB,QAAQ,MAAO;AAItE,qBAAe;AAGf,UAAK,SAAU;AACa,QAAE,QAAU,MAAM;AAAA,MAC9C;AAEA,UAAK,SAAU;AACd,qBAAc,IAAK;AACnB,qBAAc,SAAU;AACxB,oBAAY,WAAY,MAAM,aAAc,KAAM,GAAG,OAAQ;AAAA,MAC9D;AAAA,IACD,CAAE;AAEF,WAAO,MAAM;AACZ,UAAK,aAAa,SAAU;AAC3B,qBAAa,QAAQ,QAAQ;AAAA,MAC9B;AACA,mBAAc,SAAU;AAAA,IACzB;AAAA,EACD,GAAG,CAAE,MAAM,SAAS,YAAa,CAAE;AAEnC,SAAO;AACR;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,23 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import Clipboard from 'clipboard';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* WordPress dependencies
|
|
8
|
-
*/
|
|
9
|
-
import { useRef, useLayoutEffect } from '@wordpress/element';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import useRefEffect from '../use-ref-effect';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* @template T
|
|
18
|
-
* @param {T} value
|
|
19
|
-
* @return {import('react').RefObject<T>} The updated ref
|
|
20
|
-
*/
|
|
1
|
+
import Clipboard from "clipboard";
|
|
2
|
+
import { useRef, useLayoutEffect } from "@wordpress/element";
|
|
3
|
+
import useRefEffect from "../use-ref-effect";
|
|
21
4
|
function useUpdatedRef(value) {
|
|
22
5
|
const ref = useRef(value);
|
|
23
6
|
useLayoutEffect(() => {
|
|
@@ -25,35 +8,16 @@ function useUpdatedRef(value) {
|
|
|
25
8
|
}, [value]);
|
|
26
9
|
return ref;
|
|
27
10
|
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* Copies the given text to the clipboard when the element is clicked.
|
|
31
|
-
*
|
|
32
|
-
* @template {HTMLElement} TElementType
|
|
33
|
-
* @param {string | (() => string)} text The text to copy. Use a function if not
|
|
34
|
-
* already available and expensive to compute.
|
|
35
|
-
* @param {Function} onSuccess Called when to text is copied.
|
|
36
|
-
*
|
|
37
|
-
* @return {import('react').Ref<TElementType>} A ref to assign to the target element.
|
|
38
|
-
*/
|
|
39
|
-
export default function useCopyToClipboard(text, onSuccess) {
|
|
40
|
-
// Store the dependencies as refs and continuously update them so they're
|
|
41
|
-
// fresh when the callback is called.
|
|
11
|
+
function useCopyToClipboard(text, onSuccess) {
|
|
42
12
|
const textRef = useUpdatedRef(text);
|
|
43
13
|
const onSuccessRef = useUpdatedRef(onSuccess);
|
|
44
|
-
return useRefEffect(node => {
|
|
45
|
-
// Clipboard listens to click events.
|
|
14
|
+
return useRefEffect((node) => {
|
|
46
15
|
const clipboard = new Clipboard(node, {
|
|
47
16
|
text() {
|
|
48
|
-
return typeof textRef.current ===
|
|
17
|
+
return typeof textRef.current === "function" ? textRef.current() : textRef.current || "";
|
|
49
18
|
}
|
|
50
19
|
});
|
|
51
|
-
clipboard.on(
|
|
52
|
-
clearSelection
|
|
53
|
-
}) => {
|
|
54
|
-
// Clearing selection will move focus back to the triggering
|
|
55
|
-
// button, ensuring that it is not reset to the body, and
|
|
56
|
-
// further that it is kept within the rendered node.
|
|
20
|
+
clipboard.on("success", ({ clearSelection }) => {
|
|
57
21
|
clearSelection();
|
|
58
22
|
if (onSuccessRef.current) {
|
|
59
23
|
onSuccessRef.current();
|
|
@@ -64,4 +28,7 @@ export default function useCopyToClipboard(text, onSuccess) {
|
|
|
64
28
|
};
|
|
65
29
|
}, []);
|
|
66
30
|
}
|
|
67
|
-
|
|
31
|
+
export {
|
|
32
|
+
useCopyToClipboard as default
|
|
33
|
+
};
|
|
34
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-copy-to-clipboard/index.js"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useLayoutEffect } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport useRefEffect from '../use-ref-effect';\n\n/**\n * @template T\n * @param {T} value\n * @return {import('react').RefObject<T>} The updated ref\n */\nfunction useUpdatedRef( value ) {\n\tconst ref = useRef( value );\n\tuseLayoutEffect( () => {\n\t\tref.current = value;\n\t}, [ value ] );\n\treturn ref;\n}\n\n/**\n * Copies the given text to the clipboard when the element is clicked.\n *\n * @template {HTMLElement} TElementType\n * @param {string | (() => string)} text The text to copy. Use a function if not\n * already available and expensive to compute.\n * @param {Function} onSuccess Called when to text is copied.\n *\n * @return {import('react').Ref<TElementType>} A ref to assign to the target element.\n */\nexport default function useCopyToClipboard( text, onSuccess ) {\n\t// Store the dependencies as refs and continuously update them so they're\n\t// fresh when the callback is called.\n\tconst textRef = useUpdatedRef( text );\n\tconst onSuccessRef = useUpdatedRef( onSuccess );\n\treturn useRefEffect( ( node ) => {\n\t\t// Clipboard listens to click events.\n\t\tconst clipboard = new Clipboard( node, {\n\t\t\ttext() {\n\t\t\t\treturn typeof textRef.current === 'function'\n\t\t\t\t\t? textRef.current()\n\t\t\t\t\t: textRef.current || '';\n\t\t\t},\n\t\t} );\n\n\t\tclipboard.on( 'success', ( { clearSelection } ) => {\n\t\t\t// Clearing selection will move focus back to the triggering\n\t\t\t// button, ensuring that it is not reset to the body, and\n\t\t\t// further that it is kept within the rendered node.\n\t\t\tclearSelection();\n\n\t\t\tif ( onSuccessRef.current ) {\n\t\t\t\tonSuccessRef.current();\n\t\t\t}\n\t\t} );\n\n\t\treturn () => {\n\t\t\tclipboard.destroy();\n\t\t};\n\t}, [] );\n}\n"],
|
|
5
|
+
"mappings": "AAGA,OAAO,eAAe;AAKtB,SAAS,QAAQ,uBAAuB;AAKxC,OAAO,kBAAkB;AAOzB,SAAS,cAAe,OAAQ;AAC/B,QAAM,MAAM,OAAQ,KAAM;AAC1B,kBAAiB,MAAM;AACtB,QAAI,UAAU;AAAA,EACf,GAAG,CAAE,KAAM,CAAE;AACb,SAAO;AACR;AAYe,SAAR,mBAAqC,MAAM,WAAY;AAG7D,QAAM,UAAU,cAAe,IAAK;AACpC,QAAM,eAAe,cAAe,SAAU;AAC9C,SAAO,aAAc,CAAE,SAAU;AAEhC,UAAM,YAAY,IAAI,UAAW,MAAM;AAAA,MACtC,OAAO;AACN,eAAO,OAAO,QAAQ,YAAY,aAC/B,QAAQ,QAAQ,IAChB,QAAQ,WAAW;AAAA,MACvB;AAAA,IACD,CAAE;AAEF,cAAU,GAAI,WAAW,CAAE,EAAE,eAAe,MAAO;AAIlD,qBAAe;AAEf,UAAK,aAAa,SAAU;AAC3B,qBAAa,QAAQ;AAAA,MACtB;AAAA,IACD,CAAE;AAEF,WAAO,MAAM;AACZ,gBAAU,QAAQ;AAAA,IACnB;AAAA,EACD,GAAG,CAAC,CAAE;AACP;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,36 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
import { useEffect } from '@wordpress/element';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Internal dependencies
|
|
13
|
-
*/
|
|
14
|
-
import { debounce } from '../../utils/debounce';
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* Debounces a function similar to Lodash's `debounce`. A new debounced function will
|
|
18
|
-
* be returned and any scheduled calls cancelled if any of the arguments change,
|
|
19
|
-
* including the function to debounce, so please wrap functions created on
|
|
20
|
-
* render in components in `useCallback`.
|
|
21
|
-
*
|
|
22
|
-
* @see https://lodash.com/docs/4#debounce
|
|
23
|
-
*
|
|
24
|
-
* @template {(...args: any[]) => void} TFunc
|
|
25
|
-
*
|
|
26
|
-
* @param {TFunc} fn The function to debounce.
|
|
27
|
-
* @param {number} [wait] The number of milliseconds to delay.
|
|
28
|
-
* @param {import('../../utils/debounce').DebounceOptions} [options] The options object.
|
|
29
|
-
* @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function.
|
|
30
|
-
*/
|
|
31
|
-
export default function useDebounce(fn, wait, options) {
|
|
32
|
-
const debounced = useMemoOne(() => debounce(fn, wait !== null && wait !== void 0 ? wait : 0, options), [fn, wait, options]);
|
|
1
|
+
import { useMemoOne } from "use-memo-one";
|
|
2
|
+
import { useEffect } from "@wordpress/element";
|
|
3
|
+
import { debounce } from "../../utils/debounce";
|
|
4
|
+
function useDebounce(fn, wait, options) {
|
|
5
|
+
const debounced = useMemoOne(
|
|
6
|
+
() => debounce(fn, wait ?? 0, options),
|
|
7
|
+
[fn, wait, options?.leading, options?.trailing, options?.maxWait]
|
|
8
|
+
);
|
|
33
9
|
useEffect(() => () => debounced.cancel(), [debounced]);
|
|
34
10
|
return debounced;
|
|
35
11
|
}
|
|
36
|
-
|
|
12
|
+
export {
|
|
13
|
+
useDebounce as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/hooks/use-debounce/index.js"],
|
|
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 {(...args: any[]) => void} TFunc\n *\n * @param {TFunc} fn The function to debounce.\n * @param {number} [wait] The number of milliseconds to delay.\n * @param {import('../../utils/debounce').DebounceOptions} [options] The options object.\n * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function.\n */\nexport default function useDebounce( fn, wait, options ) {\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;AAiBV,SAAR,YAA8B,IAAI,MAAM,SAAU;AACxD,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
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,20 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
import { useEffect, useState } from '@wordpress/element';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Internal dependencies
|
|
8
|
-
*/
|
|
9
|
-
import useDebounce from '../use-debounce';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* Helper hook for input fields that need to debounce the value before using it.
|
|
13
|
-
*
|
|
14
|
-
* @param defaultValue The default value to use.
|
|
15
|
-
* @return The input value, the setter and the debounced input value.
|
|
16
|
-
*/
|
|
17
|
-
export default function useDebouncedInput(defaultValue = '') {
|
|
1
|
+
import { useEffect, useState } from "@wordpress/element";
|
|
2
|
+
import useDebounce from "../use-debounce";
|
|
3
|
+
function useDebouncedInput(defaultValue = "") {
|
|
18
4
|
const [input, setInput] = useState(defaultValue);
|
|
19
5
|
const [debouncedInput, setDebouncedState] = useState(defaultValue);
|
|
20
6
|
const setDebouncedInput = useDebounce(setDebouncedState, 250);
|
|
@@ -23,4 +9,7 @@ export default function useDebouncedInput(defaultValue = '') {
|
|
|
23
9
|
}, [input, setDebouncedInput]);
|
|
24
10
|
return [input, setInput, debouncedInput];
|
|
25
11
|
}
|
|
26
|
-
|
|
12
|
+
export {
|
|
13
|
+
useDebouncedInput as default
|
|
14
|
+
};
|
|
15
|
+
//# sourceMappingURL=index.js.map
|