@wordpress/compose 7.32.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.
Files changed (235) hide show
  1. package/build/higher-order/compose.js +25 -20
  2. package/build/higher-order/compose.js.map +7 -1
  3. package/build/higher-order/if-condition/index.js +35 -41
  4. package/build/higher-order/if-condition/index.js.map +7 -1
  5. package/build/higher-order/pipe.js +32 -66
  6. package/build/higher-order/pipe.js.map +7 -1
  7. package/build/higher-order/pure/index.js +44 -37
  8. package/build/higher-order/pure/index.js.map +7 -1
  9. package/build/higher-order/with-global-events/index.js +64 -73
  10. package/build/higher-order/with-global-events/index.js.map +7 -1
  11. package/build/higher-order/with-global-events/listener.js +34 -21
  12. package/build/higher-order/with-global-events/listener.js.map +7 -1
  13. package/build/higher-order/with-instance-id/index.js +45 -27
  14. package/build/higher-order/with-instance-id/index.js.map +7 -1
  15. package/build/higher-order/with-safe-timeout/index.js +70 -66
  16. package/build/higher-order/with-safe-timeout/index.js.map +7 -1
  17. package/build/higher-order/with-state/index.js +52 -40
  18. package/build/higher-order/with-state/index.js.map +7 -1
  19. package/build/hooks/use-async-list/index.js +38 -42
  20. package/build/hooks/use-async-list/index.js.map +7 -1
  21. package/build/hooks/use-constrained-tabbing/index.js +54 -75
  22. package/build/hooks/use-constrained-tabbing/index.js.map +7 -1
  23. package/build/hooks/use-copy-on-click/index.js +46 -56
  24. package/build/hooks/use-copy-on-click/index.js.map +7 -1
  25. package/build/hooks/use-copy-to-clipboard/index.js +41 -51
  26. package/build/hooks/use-copy-to-clipboard/index.js.map +7 -1
  27. package/build/hooks/use-debounce/index.js +30 -37
  28. package/build/hooks/use-debounce/index.js.map +7 -1
  29. package/build/hooks/use-debounced-input/index.js +39 -27
  30. package/build/hooks/use-debounced-input/index.js.map +7 -1
  31. package/build/hooks/use-dialog/index.js +63 -55
  32. package/build/hooks/use-dialog/index.js.map +7 -1
  33. package/build/hooks/use-disabled/index.js +74 -82
  34. package/build/hooks/use-disabled/index.js.map +7 -1
  35. package/build/hooks/use-dragging/index.js +51 -48
  36. package/build/hooks/use-dragging/index.js.map +7 -1
  37. package/build/hooks/use-drop-zone/index.js +133 -168
  38. package/build/hooks/use-drop-zone/index.js.map +7 -1
  39. package/build/hooks/use-event/index.js +33 -45
  40. package/build/hooks/use-event/index.js.map +7 -1
  41. package/build/hooks/use-fixed-window-list/index.js +109 -97
  42. package/build/hooks/use-fixed-window-list/index.js.map +7 -1
  43. package/build/hooks/use-focus-on-mount/index.js +44 -57
  44. package/build/hooks/use-focus-on-mount/index.js.map +7 -1
  45. package/build/hooks/use-focus-outside/index.js +44 -102
  46. package/build/hooks/use-focus-outside/index.js.map +7 -1
  47. package/build/hooks/use-focus-return/index.js +35 -56
  48. package/build/hooks/use-focus-return/index.js.map +7 -1
  49. package/build/hooks/use-focusable-iframe/index.js +38 -35
  50. package/build/hooks/use-focusable-iframe/index.js.map +7 -1
  51. package/build/hooks/use-instance-id/index.js +26 -42
  52. package/build/hooks/use-instance-id/index.js.map +7 -1
  53. package/build/hooks/use-isomorphic-layout-effect/index.js +25 -17
  54. package/build/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  55. package/build/hooks/use-keyboard-shortcut/index.js +72 -69
  56. package/build/hooks/use-keyboard-shortcut/index.js.map +7 -1
  57. package/build/hooks/use-media-query/index.js +39 -35
  58. package/build/hooks/use-media-query/index.js.map +7 -1
  59. package/build/hooks/use-merge-refs/index.js +34 -102
  60. package/build/hooks/use-merge-refs/index.js.map +7 -1
  61. package/build/hooks/use-observable-value/index.js +31 -28
  62. package/build/hooks/use-observable-value/index.js.map +7 -1
  63. package/build/hooks/use-preferred-color-scheme/index.android.js +31 -23
  64. package/build/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  65. package/build/hooks/use-preferred-color-scheme/index.ios.js +25 -17
  66. package/build/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  67. package/build/hooks/use-previous/index.js +26 -25
  68. package/build/hooks/use-previous/index.js.map +7 -1
  69. package/build/hooks/use-reduced-motion/index.js +35 -18
  70. package/build/hooks/use-reduced-motion/index.js.map +7 -1
  71. package/build/hooks/use-ref-effect/index.js +25 -35
  72. package/build/hooks/use-ref-effect/index.js.map +7 -1
  73. package/build/hooks/use-resize-observer/index.js +35 -67
  74. package/build/hooks/use-resize-observer/index.js.map +7 -1
  75. package/build/hooks/use-resize-observer/legacy/index.js +47 -103
  76. package/build/hooks/use-resize-observer/legacy/index.js.map +7 -1
  77. package/build/hooks/use-resize-observer/use-resize-observer.js +44 -36
  78. package/build/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  79. package/build/hooks/use-state-with-history/index.js +68 -63
  80. package/build/hooks/use-state-with-history/index.js.map +7 -1
  81. package/build/hooks/use-throttle/index.js +30 -37
  82. package/build/hooks/use-throttle/index.js.map +7 -1
  83. package/build/hooks/use-viewport-match/index.js +51 -70
  84. package/build/hooks/use-viewport-match/index.js.map +7 -1
  85. package/build/hooks/use-warn-on-change/index.js +50 -40
  86. package/build/hooks/use-warn-on-change/index.js.map +7 -1
  87. package/build/index.js +156 -358
  88. package/build/index.js.map +7 -1
  89. package/build/utils/create-higher-order-component/index.js +30 -34
  90. package/build/utils/create-higher-order-component/index.js.map +7 -1
  91. package/build/utils/debounce/index.js +38 -99
  92. package/build/utils/debounce/index.js.map +7 -1
  93. package/build/utils/observable-map/index.js +29 -19
  94. package/build/utils/observable-map/index.js.map +7 -1
  95. package/build/utils/throttle/index.js +30 -81
  96. package/build/utils/throttle/index.js.map +7 -1
  97. package/build-module/higher-order/compose.js +6 -15
  98. package/build-module/higher-order/compose.js.map +7 -1
  99. package/build-module/higher-order/if-condition/index.js +16 -37
  100. package/build-module/higher-order/if-condition/index.js.map +7 -1
  101. package/build-module/higher-order/pipe.js +10 -62
  102. package/build-module/higher-order/pipe.js.map +7 -1
  103. package/build-module/higher-order/pure/index.js +12 -29
  104. package/build-module/higher-order/pure/index.js.map +7 -1
  105. package/build-module/higher-order/with-global-events/index.js +34 -67
  106. package/build-module/higher-order/with-global-events/index.js.map +7 -1
  107. package/build-module/higher-order/with-global-events/listener.js +16 -17
  108. package/build-module/higher-order/with-global-events/listener.js.map +7 -1
  109. package/build-module/higher-order/with-instance-id/index.js +17 -22
  110. package/build-module/higher-order/with-instance-id/index.js.map +7 -1
  111. package/build-module/higher-order/with-safe-timeout/index.js +52 -62
  112. package/build-module/higher-order/with-safe-timeout/index.js.map +7 -1
  113. package/build-module/higher-order/with-state/index.js +23 -35
  114. package/build-module/higher-order/with-state/index.js.map +7 -1
  115. package/build-module/hooks/use-async-list/index.js +16 -33
  116. package/build-module/hooks/use-async-list/index.js.map +7 -1
  117. package/build-module/hooks/use-constrained-tabbing/index.js +26 -70
  118. package/build-module/hooks/use-constrained-tabbing/index.js.map +7 -1
  119. package/build-module/hooks/use-copy-on-click/index.js +14 -47
  120. package/build-module/hooks/use-copy-on-click/index.js.map +7 -1
  121. package/build-module/hooks/use-copy-to-clipboard/index.js +11 -44
  122. package/build-module/hooks/use-copy-to-clipboard/index.js.map +7 -1
  123. package/build-module/hooks/use-debounce/index.js +12 -33
  124. package/build-module/hooks/use-debounce/index.js.map +7 -1
  125. package/build-module/hooks/use-debounced-input/index.js +7 -18
  126. package/build-module/hooks/use-debounced-input/index.js.map +7 -1
  127. package/build-module/hooks/use-dialog/index.js +29 -43
  128. package/build-module/hooks/use-dialog/index.js.map +7 -1
  129. package/build-module/hooks/use-disabled/index.js +47 -78
  130. package/build-module/hooks/use-disabled/index.js.map +7 -1
  131. package/build-module/hooks/use-dragging/index.js +19 -39
  132. package/build-module/hooks/use-dragging/index.js.map +7 -1
  133. package/build-module/hooks/use-drop-zone/index.js +100 -158
  134. package/build-module/hooks/use-drop-zone/index.js.map +7 -1
  135. package/build-module/hooks/use-event/index.js +13 -39
  136. package/build-module/hooks/use-event/index.js.map +7 -1
  137. package/build-module/hooks/use-fixed-window-list/index.js +86 -87
  138. package/build-module/hooks/use-fixed-window-list/index.js.map +7 -1
  139. package/build-module/hooks/use-focus-on-mount/index.js +12 -48
  140. package/build-module/hooks/use-focus-on-mount/index.js.map +7 -1
  141. package/build-module/hooks/use-focus-outside/index.js +21 -93
  142. package/build-module/hooks/use-focus-outside/index.js.map +7 -1
  143. package/build-module/hooks/use-focus-return/index.js +13 -48
  144. package/build-module/hooks/use-focus-return/index.js.map +7 -1
  145. package/build-module/hooks/use-focusable-iframe/index.js +11 -31
  146. package/build-module/hooks/use-focusable-iframe/index.js.map +7 -1
  147. package/build-module/hooks/use-instance-id/index.js +7 -36
  148. package/build-module/hooks/use-instance-id/index.js.map +7 -1
  149. package/build-module/hooks/use-isomorphic-layout-effect/index.js +7 -13
  150. package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  151. package/build-module/hooks/use-keyboard-shortcut/index.js +40 -60
  152. package/build-module/hooks/use-keyboard-shortcut/index.js.map +7 -1
  153. package/build-module/hooks/use-media-query/index.js +21 -30
  154. package/build-module/hooks/use-media-query/index.js.map +7 -1
  155. package/build-module/hooks/use-merge-refs/index.js +10 -92
  156. package/build-module/hooks/use-merge-refs/index.js.map +7 -1
  157. package/build-module/hooks/use-observable-value/index.js +13 -24
  158. package/build-module/hooks/use-observable-value/index.js.map +7 -1
  159. package/build-module/hooks/use-preferred-color-scheme/index.android.js +15 -18
  160. package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  161. package/build-module/hooks/use-preferred-color-scheme/index.ios.js +6 -12
  162. package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  163. package/build-module/hooks/use-previous/index.js +7 -20
  164. package/build-module/hooks/use-previous/index.js.map +7 -1
  165. package/build-module/hooks/use-reduced-motion/index.js +7 -13
  166. package/build-module/hooks/use-reduced-motion/index.js.map +7 -1
  167. package/build-module/hooks/use-ref-effect/index.js +7 -31
  168. package/build-module/hooks/use-ref-effect/index.js.map +7 -1
  169. package/build-module/hooks/use-resize-observer/index.js +7 -61
  170. package/build-module/hooks/use-resize-observer/index.js.map +7 -1
  171. package/build-module/hooks/use-resize-observer/legacy/index.js +28 -96
  172. package/build-module/hooks/use-resize-observer/legacy/index.js.map +7 -1
  173. package/build-module/hooks/use-resize-observer/use-resize-observer.js +10 -28
  174. package/build-module/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  175. package/build-module/hooks/use-state-with-history/index.js +47 -55
  176. package/build-module/hooks/use-state-with-history/index.js.map +7 -1
  177. package/build-module/hooks/use-throttle/index.js +12 -33
  178. package/build-module/hooks/use-throttle/index.js.map +7 -1
  179. package/build-module/hooks/use-viewport-match/index.js +22 -64
  180. package/build-module/hooks/use-viewport-match/index.js.map +7 -1
  181. package/build-module/hooks/use-warn-on-change/index.js +21 -34
  182. package/build-module/hooks/use-warn-on-change/index.js.map +7 -1
  183. package/build-module/index.js +83 -53
  184. package/build-module/index.js.map +7 -1
  185. package/build-module/utils/create-higher-order-component/index.js +9 -30
  186. package/build-module/utils/create-higher-order-component/index.js.map +7 -1
  187. package/build-module/utils/debounce/index.js +17 -95
  188. package/build-module/utils/debounce/index.js.map +7 -1
  189. package/build-module/utils/observable-map/index.js +8 -16
  190. package/build-module/utils/observable-map/index.js.map +7 -1
  191. package/build-module/utils/throttle/index.js +8 -75
  192. package/build-module/utils/throttle/index.js.map +7 -1
  193. package/package.json +17 -10
  194. package/src/hooks/use-debounce/index.js +1 -1
  195. package/tsconfig.tsbuildinfo +1 -1
  196. package/build/higher-order/with-network-connectivity/index.native.js +0 -27
  197. package/build/higher-order/with-network-connectivity/index.native.js.map +0 -1
  198. package/build/higher-order/with-preferred-color-scheme/index.native.js +0 -37
  199. package/build/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  200. package/build/hooks/use-constrained-tabbing/index.native.js +0 -20
  201. package/build/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  202. package/build/hooks/use-focus-outside/index.native.js +0 -175
  203. package/build/hooks/use-focus-outside/index.native.js.map +0 -1
  204. package/build/hooks/use-keyboard-shortcut/index.native.js +0 -9
  205. package/build/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  206. package/build/hooks/use-network-connectivity/index.native.js +0 -58
  207. package/build/hooks/use-network-connectivity/index.native.js.map +0 -1
  208. package/build/hooks/use-preferred-color-scheme-style/index.native.js +0 -42
  209. package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  210. package/build/hooks/use-resize-observer/index.native.js +0 -14
  211. package/build/hooks/use-resize-observer/index.native.js.map +0 -1
  212. package/build/hooks/use-resize-observer/legacy/index.native.js +0 -62
  213. package/build/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  214. package/build/index.native.js +0 -297
  215. package/build/index.native.js.map +0 -1
  216. package/build-module/higher-order/with-network-connectivity/index.native.js +0 -19
  217. package/build-module/higher-order/with-network-connectivity/index.native.js.map +0 -1
  218. package/build-module/higher-order/with-preferred-color-scheme/index.native.js +0 -29
  219. package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  220. package/build-module/hooks/use-constrained-tabbing/index.native.js +0 -13
  221. package/build-module/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  222. package/build-module/hooks/use-focus-outside/index.native.js +0 -169
  223. package/build-module/hooks/use-focus-outside/index.native.js.map +0 -1
  224. package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -3
  225. package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  226. package/build-module/hooks/use-network-connectivity/index.native.js +0 -52
  227. package/build-module/hooks/use-network-connectivity/index.native.js.map +0 -1
  228. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +0 -35
  229. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  230. package/build-module/hooks/use-resize-observer/index.native.js +0 -2
  231. package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
  232. package/build-module/hooks/use-resize-observer/legacy/index.native.js +0 -56
  233. package/build-module/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  234. package/build-module/index.native.js +0 -45
  235. package/build-module/index.native.js.map +0 -1
@@ -1,45 +1,33 @@
1
- /**
2
- * WordPress dependencies
3
- */
4
- import { Component } from '@wordpress/element';
5
- import deprecated from '@wordpress/deprecated';
6
-
7
- /**
8
- * Internal dependencies
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(/** @type {any} */props) {
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 /*#__PURE__*/_jsx(OriginalComponent, {
37
- ...this.props,
38
- ...this.state,
39
- setState: this.setState
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
- }, 'withState');
28
+ }, "withState");
44
29
  }
45
- //# sourceMappingURL=index.js.map
30
+ export {
31
+ withState as default
32
+ };
33
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["Component","deprecated","createHigherOrderComponent","jsx","_jsx","withState","initialState","since","alternative","OriginalComponent","WrappedComponent","constructor","props","setState","bind","state","render"],"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,QAAQ,oBAAoB;AAC9C,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA,SAASC,0BAA0B,QAAQ,2CAA2C;;AAEtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AATA,SAAAC,GAAA,IAAAC,IAAA;AAUA,eAAe,SAASC,SAASA,CAAEC,YAAY,GAAG,CAAC,CAAC,EAAG;EACtDL,UAAU,CAAE,sBAAsB,EAAE;IACnCM,KAAK,EAAE,KAAK;IACZC,WAAW,EAAE;EACd,CAAE,CAAC;EAEH,OAAON,0BAA0B,CAAIO,iBAAiB,IAAM;IAC3D,OAAO,MAAMC,gBAAgB,SAASV,SAAS,CAAC;MAC/CW,WAAWA,CAAE,kBAAmBC,KAAK,EAAG;QACvC,KAAK,CAAEA,KAAM,CAAC;QAEd,IAAI,CAACC,QAAQ,GAAG,IAAI,CAACA,QAAQ,CAACC,IAAI,CAAE,IAAK,CAAC;QAE1C,IAAI,CAACC,KAAK,GAAGT,YAAY;MAC1B;MAEAU,MAAMA,CAAA,EAAG;QACR,oBACCZ,IAAA,CAACK,iBAAiB;UAAA,GACZ,IAAI,CAACG,KAAK;UAAA,GACV,IAAI,CAACG,KAAK;UACfF,QAAQ,EAAG,IAAI,CAACA;QAAU,CAC1B,CAAC;MAEJ;IACD,CAAC;EACF,CAAC,EAAE,WAAY,CAAC;AACjB","ignoreList":[]}
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
- * WordPress dependencies
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(list.slice(firstItems.length, step));
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 => [...state, ...list.slice(i, i + step)]);
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
- export default useAsyncList;
61
- //# sourceMappingURL=index.js.map
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
- {"version":3,"names":["flushSync","useEffect","useState","createQueue","getFirstItemsPresentInState","list","state","firstItems","i","length","item","includes","push","useAsyncList","config","step","current","setCurrent","concat","slice","asyncQueue","add","reset"],"sources":["@wordpress/compose/src/hooks/use-async-list/index.ts"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,SAAS,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;AACnE,SAASC,WAAW,QAAQ,2BAA2B;AAMvD;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,2BAA2BA,CAAOC,IAAS,EAAEC,KAAU,EAAQ;EACvE,MAAMC,UAAU,GAAG,EAAE;EAErB,KAAM,IAAIC,CAAC,GAAG,CAAC,EAAEA,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,EAAE,EAAG;IACvC,MAAME,IAAI,GAAGL,IAAI,CAAEG,CAAC,CAAE;IACtB,IAAK,CAAEF,KAAK,CAACK,QAAQ,CAAED,IAAK,CAAC,EAAG;MAC/B;IACD;IAEAH,UAAU,CAACK,IAAI,CAAEF,IAAK,CAAC;EACxB;EAEA,OAAOH,UAAU;AAClB;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASM,YAAYA,CACpBR,IAAS,EACTS,MAAuB,GAAG;EAAEC,IAAI,EAAE;AAAE,CAAC,EAC/B;EACN,MAAM;IAAEA,IAAI,GAAG;EAAE,CAAC,GAAGD,MAAM;EAC3B,MAAM,CAAEE,OAAO,EAAEC,UAAU,CAAE,GAAGf,QAAQ,CAAS,EAAG,CAAC;EAErDD,SAAS,CAAE,MAAM;IAChB;IACA,IAAIM,UAAU,GAAGH,2BAA2B,CAAEC,IAAI,EAAEW,OAAQ,CAAC;IAC7D,IAAKT,UAAU,CAACE,MAAM,GAAGM,IAAI,EAAG;MAC/BR,UAAU,GAAGA,UAAU,CAACW,MAAM,CAC7Bb,IAAI,CAACc,KAAK,CAAEZ,UAAU,CAACE,MAAM,EAAEM,IAAK,CACrC,CAAC;IACF;IACAE,UAAU,CAAEV,UAAW,CAAC;IAExB,MAAMa,UAAU,GAAGjB,WAAW,CAAC,CAAC;IAChC,KAAM,IAAIK,CAAC,GAAGD,UAAU,CAACE,MAAM,EAAED,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,IAAIO,IAAI,EAAG;MAC7DK,UAAU,CAACC,GAAG,CAAE,CAAC,CAAC,EAAE,MAAM;QACzBrB,SAAS,CAAE,MAAM;UAChBiB,UAAU,CAAIX,KAAK,IAAM,CACxB,GAAGA,KAAK,EACR,GAAGD,IAAI,CAACc,KAAK,CAAEX,CAAC,EAAEA,CAAC,GAAGO,IAAK,CAAC,CAC3B,CAAC;QACJ,CAAE,CAAC;MACJ,CAAE,CAAC;IACJ;IAEA,OAAO,MAAMK,UAAU,CAACE,KAAK,CAAC,CAAC;EAChC,CAAC,EAAE,CAAEjB,IAAI,CAAG,CAAC;EAEb,OAAOW,OAAO;AACf;AAEA,eAAeH,YAAY","ignoreList":[]}
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
- * WordPress dependencies
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((/** @type {HTMLElement} */node) => {
34
- function onKeyDown(/** @type {KeyboardEvent} */event) {
35
- const {
36
- key,
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 ? 'findPrevious' : 'findNext';
44
- const nextElement = focus.tabbable[action](/** @type {HTMLElement} */target) || null;
45
-
46
- // When the target element contains the element that is about to
47
- // receive focus, for example when the target is a tabbable
48
- // container, browsers may disagree on where to move focus next.
49
- // In this case we can't rely on native browsers behavior. We need
50
- // to manage focus instead.
51
- // See https://github.com/WordPress/gutenberg/issues/46041.
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
- // If the element that is about to receive focus is outside the
66
- // area, move focus to a div and insert it at the start or end of
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('keydown', onKeyDown);
34
+ node.addEventListener("keydown", onKeyDown);
82
35
  return () => {
83
- node.removeEventListener('keydown', onKeyDown);
36
+ node.removeEventListener("keydown", onKeyDown);
84
37
  };
85
38
  }, []);
86
39
  }
87
- export default useConstrainedTabbing;
88
- //# sourceMappingURL=index.js.map
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
- {"version":3,"names":["focus","useRefEffect","useConstrainedTabbing","node","onKeyDown","event","key","shiftKey","target","action","nextElement","tabbable","contains","preventDefault","domAction","ownerDocument","trap","createElement","tabIndex","addEventListener","removeChild","removeEventListener"],"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,KAAK,QAAQ,gBAAgB;;AAEtC;AACA;AACA;AACA,OAAOC,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,qBAAqBA,CAAA,EAAG;EAChC,OAAOD,YAAY,CAAE,CAAE,0BAA2BE,IAAI,KAAM;IAC3D,SAASC,SAASA,CAAE,4BAA6BC,KAAK,EAAG;MACxD,MAAM;QAAEC,GAAG;QAAEC,QAAQ;QAAEC;MAAO,CAAC,GAAGH,KAAK;MAEvC,IAAKC,GAAG,KAAK,KAAK,EAAG;QACpB;MACD;MAEA,MAAMG,MAAM,GAAGF,QAAQ,GAAG,cAAc,GAAG,UAAU;MACrD,MAAMG,WAAW,GAChBV,KAAK,CAACW,QAAQ,CAAEF,MAAM,CAAE,CACvB,0BAA6BD,MAC9B,CAAC,IAAI,IAAI;;MAEV;MACA;MACA;MACA;MACA;MACA;MACA,IACC,0BAA6BA,MAAM,CAAGI,QAAQ,CAAEF,WAAY,CAAC,EAC5D;QACDL,KAAK,CAACQ,cAAc,CAAC,CAAC;QACtBH,WAAW,EAAEV,KAAK,CAAC,CAAC;QACpB;MACD;;MAEA;MACA;MACA;MACA,IAAKG,IAAI,CAACS,QAAQ,CAAEF,WAAY,CAAC,EAAG;QACnC;MACD;;MAEA;MACA;MACA;MACA;MACA,MAAMI,SAAS,GAAGP,QAAQ,GAAG,QAAQ,GAAG,SAAS;MACjD,MAAM;QAAEQ;MAAc,CAAC,GAAGZ,IAAI;MAC9B,MAAMa,IAAI,GAAGD,aAAa,CAACE,aAAa,CAAE,KAAM,CAAC;MAEjDD,IAAI,CAACE,QAAQ,GAAG,CAAC,CAAC;MAClBf,IAAI,CAAEW,SAAS,CAAE,CAAEE,IAAK,CAAC;;MAEzB;MACAA,IAAI,CAACG,gBAAgB,CAAE,MAAM,EAAE,MAAMhB,IAAI,CAACiB,WAAW,CAAEJ,IAAK,CAAE,CAAC;MAE/DA,IAAI,CAAChB,KAAK,CAAC,CAAC;IACb;IAEAG,IAAI,CAACgB,gBAAgB,CAAE,SAAS,EAAEf,SAAU,CAAC;IAC7C,OAAO,MAAM;MACZD,IAAI,CAACkB,mBAAmB,CAAE,SAAS,EAAEjB,SAAU,CAAC;IACjD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR;AAEA,eAAeF,qBAAqB","ignoreList":[]}
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
- * External dependencies
3
- */
4
- import Clipboard from 'clipboard';
5
-
6
- /**
7
- * WordPress dependencies
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 === 'function' ? text() : text
17
+ text: () => typeof text === "function" ? text() : text
46
18
  });
47
- clipboardRef.current.on('success', ({
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
- /** @type {HTMLElement} */trigger.focus();
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
- //# sourceMappingURL=index.js.map
39
+ export {
40
+ useCopyOnClick as default
41
+ };
42
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["Clipboard","useRef","useEffect","useState","deprecated","useCopyOnClick","ref","text","timeout","since","alternative","clipboardRef","hasCopied","setHasCopied","timeoutId","current","on","clearSelection","trigger","focus","clearTimeout","setTimeout","destroy"],"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,SAASC,MAAM,EAAEC,SAAS,EAAEC,QAAQ,QAAQ,oBAAoB;AAChE,OAAOC,UAAU,MAAM,uBAAuB;;AAE9C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,cAAcA,CAAEC,GAAG,EAAEC,IAAI,EAAEC,OAAO,GAAG,IAAI,EAAG;EACnE;EACAJ,UAAU,CAAE,2BAA2B,EAAE;IACxCK,KAAK,EAAE,KAAK;IACZC,WAAW,EAAE;EACd,CAAE,CAAC;;EAEH;EACA,MAAMC,YAAY,GAAGV,MAAM,CAAC,CAAC;EAC7B,MAAM,CAAEW,SAAS,EAAEC,YAAY,CAAE,GAAGV,QAAQ,CAAE,KAAM,CAAC;EAErDD,SAAS,CAAE,MAAM;IAChB;IACA,IAAIY,SAAS;IAEb,IAAK,CAAER,GAAG,CAACS,OAAO,EAAG;MACpB;IACD;;IAEA;IACAJ,YAAY,CAACI,OAAO,GAAG,IAAIf,SAAS,CAAEM,GAAG,CAACS,OAAO,EAAE;MAClDR,IAAI,EAAEA,CAAA,KAAQ,OAAOA,IAAI,KAAK,UAAU,GAAGA,IAAI,CAAC,CAAC,GAAGA;IACrD,CAAE,CAAC;IAEHI,YAAY,CAACI,OAAO,CAACC,EAAE,CAAE,SAAS,EAAE,CAAE;MAAEC,cAAc;MAAEC;IAAQ,CAAC,KAAM;MACtE;MACA;MACA;MACAD,cAAc,CAAC,CAAC;;MAEhB;MACA,IAAKC,OAAO,EAAG;QACd,0BAA6BA,OAAO,CAAGC,KAAK,CAAC,CAAC;MAC/C;MAEA,IAAKX,OAAO,EAAG;QACdK,YAAY,CAAE,IAAK,CAAC;QACpBO,YAAY,CAAEN,SAAU,CAAC;QACzBA,SAAS,GAAGO,UAAU,CAAE,MAAMR,YAAY,CAAE,KAAM,CAAC,EAAEL,OAAQ,CAAC;MAC/D;IACD,CAAE,CAAC;IAEH,OAAO,MAAM;MACZ,IAAKG,YAAY,CAACI,OAAO,EAAG;QAC3BJ,YAAY,CAACI,OAAO,CAACO,OAAO,CAAC,CAAC;MAC/B;MACAF,YAAY,CAAEN,SAAU,CAAC;IAC1B,CAAC;EACF,CAAC,EAAE,CAAEP,IAAI,EAAEC,OAAO,EAAEK,YAAY,CAAG,CAAC;EAEpC,OAAOD,SAAS;AACjB","ignoreList":[]}
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
- * External dependencies
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 === 'function' ? textRef.current() : textRef.current || '';
17
+ return typeof textRef.current === "function" ? textRef.current() : textRef.current || "";
49
18
  }
50
19
  });
51
- clipboard.on('success', ({
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
- //# sourceMappingURL=index.js.map
31
+ export {
32
+ useCopyToClipboard as default
33
+ };
34
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["Clipboard","useRef","useLayoutEffect","useRefEffect","useUpdatedRef","value","ref","current","useCopyToClipboard","text","onSuccess","textRef","onSuccessRef","node","clipboard","on","clearSelection","destroy"],"sources":["@wordpress/compose/src/hooks/use-copy-to-clipboard/index.js"],"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"],"mappings":"AAAA;AACA;AACA;AACA,OAAOA,SAAS,MAAM,WAAW;;AAEjC;AACA;AACA;AACA,SAASC,MAAM,EAAEC,eAAe,QAAQ,oBAAoB;;AAE5D;AACA;AACA;AACA,OAAOC,YAAY,MAAM,mBAAmB;;AAE5C;AACA;AACA;AACA;AACA;AACA,SAASC,aAAaA,CAAEC,KAAK,EAAG;EAC/B,MAAMC,GAAG,GAAGL,MAAM,CAAEI,KAAM,CAAC;EAC3BH,eAAe,CAAE,MAAM;IACtBI,GAAG,CAACC,OAAO,GAAGF,KAAK;EACpB,CAAC,EAAE,CAAEA,KAAK,CAAG,CAAC;EACd,OAAOC,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASE,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,EAAG;EAC7D;EACA;EACA,MAAMC,OAAO,GAAGP,aAAa,CAAEK,IAAK,CAAC;EACrC,MAAMG,YAAY,GAAGR,aAAa,CAAEM,SAAU,CAAC;EAC/C,OAAOP,YAAY,CAAIU,IAAI,IAAM;IAChC;IACA,MAAMC,SAAS,GAAG,IAAId,SAAS,CAAEa,IAAI,EAAE;MACtCJ,IAAIA,CAAA,EAAG;QACN,OAAO,OAAOE,OAAO,CAACJ,OAAO,KAAK,UAAU,GACzCI,OAAO,CAACJ,OAAO,CAAC,CAAC,GACjBI,OAAO,CAACJ,OAAO,IAAI,EAAE;MACzB;IACD,CAAE,CAAC;IAEHO,SAAS,CAACC,EAAE,CAAE,SAAS,EAAE,CAAE;MAAEC;IAAe,CAAC,KAAM;MAClD;MACA;MACA;MACAA,cAAc,CAAC,CAAC;MAEhB,IAAKJ,YAAY,CAACL,OAAO,EAAG;QAC3BK,YAAY,CAACL,OAAO,CAAC,CAAC;MACvB;IACD,CAAE,CAAC;IAEH,OAAO,MAAM;MACZO,SAAS,CAACG,OAAO,CAAC,CAAC;IACpB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR","ignoreList":[]}
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
- * External dependencies
3
- */
4
- import { useMemoOne } from 'use-memo-one';
5
-
6
- /**
7
- * WordPress dependencies
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
- //# sourceMappingURL=index.js.map
12
+ export {
13
+ useDebounce as default
14
+ };
15
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["useMemoOne","useEffect","debounce","useDebounce","fn","wait","options","debounced","cancel"],"sources":["@wordpress/compose/src/hooks/use-debounce/index.js"],"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 ]\n\t);\n\tuseEffect( () => () => debounced.cancel(), [ debounced ] );\n\treturn debounced;\n}\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,UAAU,QAAQ,cAAc;;AAEzC;AACA;AACA;AACA,SAASC,SAAS,QAAQ,oBAAoB;;AAE9C;AACA;AACA;AACA,SAASC,QAAQ,QAAQ,sBAAsB;;AAE/C;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,eAAe,SAASC,WAAWA,CAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAO,EAAG;EACxD,MAAMC,SAAS,GAAGP,UAAU,CAC3B,MAAME,QAAQ,CAAEE,EAAE,EAAEC,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAI,CAAC,EAAEC,OAAQ,CAAC,EACxC,CAAEF,EAAE,EAAEC,IAAI,EAAEC,OAAO,CACpB,CAAC;EACDL,SAAS,CAAE,MAAM,MAAMM,SAAS,CAACC,MAAM,CAAC,CAAC,EAAE,CAAED,SAAS,CAAG,CAAC;EAC1D,OAAOA,SAAS;AACjB","ignoreList":[]}
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
- * WordPress dependencies
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
- //# sourceMappingURL=index.js.map
12
+ export {
13
+ useDebouncedInput as default
14
+ };
15
+ //# sourceMappingURL=index.js.map