@wordpress/compose 6.16.0 → 6.17.1

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 (207) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/higher-order/compose.js +0 -2
  3. package/build/higher-order/compose.js.map +1 -1
  4. package/build/higher-order/if-condition/index.js +2 -6
  5. package/build/higher-order/if-condition/index.js.map +1 -1
  6. package/build/higher-order/pipe.js +1 -5
  7. package/build/higher-order/pipe.js.map +1 -1
  8. package/build/higher-order/pure/index.js +2 -10
  9. package/build/higher-order/pure/index.js.map +1 -1
  10. package/build/higher-order/with-global-events/index.js +13 -32
  11. package/build/higher-order/with-global-events/index.js.map +1 -1
  12. package/build/higher-order/with-global-events/listener.js +5 -28
  13. package/build/higher-order/with-global-events/listener.js.map +1 -1
  14. package/build/higher-order/with-instance-id/index.js +4 -8
  15. package/build/higher-order/with-instance-id/index.js.map +1 -1
  16. package/build/higher-order/with-preferred-color-scheme/index.native.js +3 -6
  17. package/build/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
  18. package/build/higher-order/with-safe-timeout/index.js +4 -14
  19. package/build/higher-order/with-safe-timeout/index.js.map +1 -1
  20. package/build/higher-order/with-state/index.js +3 -11
  21. package/build/higher-order/with-state/index.js.map +1 -1
  22. package/build/hooks/use-async-list/index.js +1 -14
  23. package/build/hooks/use-async-list/index.js.map +1 -1
  24. package/build/hooks/use-constrained-tabbing/index.js +14 -30
  25. package/build/hooks/use-constrained-tabbing/index.js.map +1 -1
  26. package/build/hooks/use-constrained-tabbing/index.native.js +4 -4
  27. package/build/hooks/use-constrained-tabbing/index.native.js.map +1 -1
  28. package/build/hooks/use-copy-on-click/index.js +6 -15
  29. package/build/hooks/use-copy-on-click/index.js.map +1 -1
  30. package/build/hooks/use-copy-to-clipboard/index.js +3 -11
  31. package/build/hooks/use-copy-to-clipboard/index.js.map +1 -1
  32. package/build/hooks/use-debounce/index.js +0 -4
  33. package/build/hooks/use-debounce/index.js.map +1 -1
  34. package/build/hooks/use-dialog/index.js +2 -12
  35. package/build/hooks/use-dialog/index.js.map +1 -1
  36. package/build/hooks/use-disabled/index.js +5 -15
  37. package/build/hooks/use-disabled/index.js.map +1 -1
  38. package/build/hooks/use-dragging/index.js +4 -11
  39. package/build/hooks/use-dragging/index.js.map +1 -1
  40. package/build/hooks/use-drop-zone/index.js +27 -66
  41. package/build/hooks/use-drop-zone/index.js.map +1 -1
  42. package/build/hooks/use-fixed-window-list/index.js +8 -34
  43. package/build/hooks/use-fixed-window-list/index.js.map +1 -1
  44. package/build/hooks/use-focus-on-mount/index.js +3 -14
  45. package/build/hooks/use-focus-on-mount/index.js.map +1 -1
  46. package/build/hooks/use-focus-outside/index.js +13 -19
  47. package/build/hooks/use-focus-outside/index.js.map +1 -1
  48. package/build/hooks/use-focus-outside/index.native.js +13 -21
  49. package/build/hooks/use-focus-outside/index.native.js.map +1 -1
  50. package/build/hooks/use-focus-return/index.js +7 -15
  51. package/build/hooks/use-focus-return/index.js.map +1 -1
  52. package/build/hooks/use-focusable-iframe/index.js +1 -5
  53. package/build/hooks/use-focusable-iframe/index.js.map +1 -1
  54. package/build/hooks/use-instance-id/index.js +3 -5
  55. package/build/hooks/use-instance-id/index.js.map +1 -1
  56. package/build/hooks/use-isomorphic-layout-effect/index.js +0 -2
  57. package/build/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
  58. package/build/hooks/use-keyboard-shortcut/index.js +12 -28
  59. package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
  60. package/build/hooks/use-keyboard-shortcut/index.native.js +0 -2
  61. package/build/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
  62. package/build/hooks/use-media-query/index.js +1 -9
  63. package/build/hooks/use-media-query/index.js.map +1 -1
  64. package/build/hooks/use-merge-refs/index.js +18 -24
  65. package/build/hooks/use-merge-refs/index.js.map +1 -1
  66. package/build/hooks/use-preferred-color-scheme/index.android.js +0 -5
  67. package/build/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
  68. package/build/hooks/use-preferred-color-scheme/index.ios.js +0 -2
  69. package/build/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
  70. package/build/hooks/use-preferred-color-scheme-style/index.native.js +2 -5
  71. package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
  72. package/build/hooks/use-previous/index.js +3 -4
  73. package/build/hooks/use-previous/index.js.map +1 -1
  74. package/build/hooks/use-reduced-motion/index.js +0 -4
  75. package/build/hooks/use-reduced-motion/index.js.map +1 -1
  76. package/build/hooks/use-ref-effect/index.js +0 -2
  77. package/build/hooks/use-ref-effect/index.js.map +1 -1
  78. package/build/hooks/use-resize-observer/index.js +23 -30
  79. package/build/hooks/use-resize-observer/index.js.map +1 -1
  80. package/build/hooks/use-resize-observer/index.native.js +0 -6
  81. package/build/hooks/use-resize-observer/index.native.js.map +1 -1
  82. package/build/hooks/use-throttle/index.js +0 -4
  83. package/build/hooks/use-throttle/index.js.map +1 -1
  84. package/build/hooks/use-viewport-match/index.js +4 -13
  85. package/build/hooks/use-viewport-match/index.js.map +1 -1
  86. package/build/hooks/use-warn-on-change/index.js +4 -14
  87. package/build/hooks/use-warn-on-change/index.js.map +1 -1
  88. package/build/index.js +0 -41
  89. package/build/index.js.map +1 -1
  90. package/build/index.native.js +0 -33
  91. package/build/index.native.js.map +1 -1
  92. package/build/utils/create-higher-order-component/index.js +1 -4
  93. package/build/utils/create-higher-order-component/index.js.map +1 -1
  94. package/build/utils/debounce/index.js +12 -37
  95. package/build/utils/debounce/index.js.map +1 -1
  96. package/build/utils/throttle/index.js +0 -5
  97. package/build/utils/throttle/index.js.map +1 -1
  98. package/build-module/higher-order/compose.js +1 -1
  99. package/build-module/higher-order/compose.js.map +1 -1
  100. package/build-module/higher-order/if-condition/index.js +3 -5
  101. package/build-module/higher-order/if-condition/index.js.map +1 -1
  102. package/build-module/higher-order/pipe.js +1 -4
  103. package/build-module/higher-order/pipe.js.map +1 -1
  104. package/build-module/higher-order/pure/index.js +4 -8
  105. package/build-module/higher-order/pure/index.js.map +1 -1
  106. package/build-module/higher-order/with-global-events/index.js +15 -29
  107. package/build-module/higher-order/with-global-events/index.js.map +1 -1
  108. package/build-module/higher-order/with-global-events/listener.js +5 -27
  109. package/build-module/higher-order/with-global-events/listener.js.map +1 -1
  110. package/build-module/higher-order/with-instance-id/index.js +5 -5
  111. package/build-module/higher-order/with-instance-id/index.js.map +1 -1
  112. package/build-module/higher-order/with-preferred-color-scheme/index.native.js +3 -3
  113. package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
  114. package/build-module/higher-order/with-safe-timeout/index.js +6 -8
  115. package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
  116. package/build-module/higher-order/with-state/index.js +5 -9
  117. package/build-module/higher-order/with-state/index.js.map +1 -1
  118. package/build-module/hooks/use-async-list/index.js +1 -12
  119. package/build-module/hooks/use-async-list/index.js.map +1 -1
  120. package/build-module/hooks/use-constrained-tabbing/index.js +16 -27
  121. package/build-module/hooks/use-constrained-tabbing/index.js.map +1 -1
  122. package/build-module/hooks/use-constrained-tabbing/index.native.js +3 -3
  123. package/build-module/hooks/use-constrained-tabbing/index.native.js.map +1 -1
  124. package/build-module/hooks/use-copy-on-click/index.js +8 -12
  125. package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
  126. package/build-module/hooks/use-copy-to-clipboard/index.js +6 -9
  127. package/build-module/hooks/use-copy-to-clipboard/index.js.map +1 -1
  128. package/build-module/hooks/use-debounce/index.js +3 -3
  129. package/build-module/hooks/use-debounce/index.js.map +1 -1
  130. package/build-module/hooks/use-dialog/index.js +3 -5
  131. package/build-module/hooks/use-dialog/index.js.map +1 -1
  132. package/build-module/hooks/use-disabled/index.js +6 -12
  133. package/build-module/hooks/use-disabled/index.js.map +1 -1
  134. package/build-module/hooks/use-dragging/index.js +6 -9
  135. package/build-module/hooks/use-dragging/index.js.map +1 -1
  136. package/build-module/hooks/use-drop-zone/index.js +29 -64
  137. package/build-module/hooks/use-drop-zone/index.js.map +1 -1
  138. package/build-module/hooks/use-fixed-window-list/index.js +8 -30
  139. package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
  140. package/build-module/hooks/use-focus-on-mount/index.js +4 -12
  141. package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
  142. package/build-module/hooks/use-focus-outside/index.js +14 -18
  143. package/build-module/hooks/use-focus-outside/index.js.map +1 -1
  144. package/build-module/hooks/use-focus-outside/index.native.js +14 -20
  145. package/build-module/hooks/use-focus-outside/index.native.js.map +1 -1
  146. package/build-module/hooks/use-focus-return/index.js +8 -14
  147. package/build-module/hooks/use-focus-return/index.js.map +1 -1
  148. package/build-module/hooks/use-focusable-iframe/index.js +2 -3
  149. package/build-module/hooks/use-focusable-iframe/index.js.map +1 -1
  150. package/build-module/hooks/use-instance-id/index.js +2 -3
  151. package/build-module/hooks/use-instance-id/index.js.map +1 -1
  152. package/build-module/hooks/use-isomorphic-layout-effect/index.js +1 -1
  153. package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
  154. package/build-module/hooks/use-keyboard-shortcut/index.js +14 -24
  155. package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
  156. package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -1
  157. package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
  158. package/build-module/hooks/use-media-query/index.js +2 -8
  159. package/build-module/hooks/use-media-query/index.js.map +1 -1
  160. package/build-module/hooks/use-merge-refs/index.js +19 -23
  161. package/build-module/hooks/use-merge-refs/index.js.map +1 -1
  162. package/build-module/hooks/use-preferred-color-scheme/index.android.js +1 -3
  163. package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
  164. package/build-module/hooks/use-preferred-color-scheme/index.ios.js +1 -1
  165. package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
  166. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +3 -3
  167. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
  168. package/build-module/hooks/use-previous/index.js +4 -3
  169. package/build-module/hooks/use-previous/index.js.map +1 -1
  170. package/build-module/hooks/use-reduced-motion/index.js +1 -2
  171. package/build-module/hooks/use-reduced-motion/index.js.map +1 -1
  172. package/build-module/hooks/use-ref-effect/index.js +1 -1
  173. package/build-module/hooks/use-ref-effect/index.js.map +1 -1
  174. package/build-module/hooks/use-resize-observer/index.js +22 -30
  175. package/build-module/hooks/use-resize-observer/index.js.map +1 -1
  176. package/build-module/hooks/use-resize-observer/index.native.js +1 -6
  177. package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
  178. package/build-module/hooks/use-throttle/index.js +3 -3
  179. package/build-module/hooks/use-throttle/index.js.map +1 -1
  180. package/build-module/hooks/use-viewport-match/index.js +6 -11
  181. package/build-module/hooks/use-viewport-match/index.js.map +1 -1
  182. package/build-module/hooks/use-warn-on-change/index.js +6 -12
  183. package/build-module/hooks/use-warn-on-change/index.js.map +1 -1
  184. package/build-module/index.js +10 -7
  185. package/build-module/index.js.map +1 -1
  186. package/build-module/index.native.js +10 -7
  187. package/build-module/index.native.js.map +1 -1
  188. package/build-module/utils/create-higher-order-component/index.js +1 -2
  189. package/build-module/utils/create-higher-order-component/index.js.map +1 -1
  190. package/build-module/utils/debounce/index.js +12 -35
  191. package/build-module/utils/debounce/index.js.map +1 -1
  192. package/build-module/utils/throttle/index.js +0 -3
  193. package/build-module/utils/throttle/index.js.map +1 -1
  194. package/build-types/higher-order/with-instance-id/index.d.ts +1 -1
  195. package/build-types/higher-order/with-instance-id/index.d.ts.map +1 -1
  196. package/build-types/higher-order/with-safe-timeout/index.d.ts +1 -1
  197. package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
  198. package/build-types/hooks/use-disabled/index.d.ts +1 -1
  199. package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
  200. package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts +1 -1
  201. package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
  202. package/build-types/hooks/use-viewport-match/index.d.ts +1 -1
  203. package/package.json +8 -8
  204. package/src/higher-order/with-instance-id/index.tsx +2 -2
  205. package/src/higher-order/with-safe-timeout/index.tsx +2 -2
  206. package/src/hooks/use-resize-observer/index.native.js +0 -1
  207. package/tsconfig.tsbuildinfo +1 -1
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/higher-order/with-state/index.js"],"names":["withState","initialState","since","alternative","OriginalComponent","WrappedComponent","Component","constructor","props","setState","bind","state","render"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,SAAT,CAAoBC,YAAY,GAAG,EAAnC,EAAwC;AACtD,2BAAY,sBAAZ,EAAoC;AACnCC,IAAAA,KAAK,EAAE,KAD4B;AAEnCC,IAAAA,WAAW,EAAE;AAFsB,GAApC;AAKA,SAAO,4DAA8BC,iBAAF,IAAyB;AAC3D,WAAO,MAAMC,gBAAN,SAA+BC,kBAA/B,CAAyC;AAC/CC,MAAAA,WAAW;AAAE;AAAmBC,MAAAA,KAArB,EAA6B;AACvC,cAAOA,KAAP;AAEA,aAAKC,QAAL,GAAgB,KAAKA,QAAL,CAAcC,IAAd,CAAoB,IAApB,CAAhB;AAEA,aAAKC,KAAL,GAAaV,YAAb;AACA;;AAEDW,MAAAA,MAAM,GAAG;AACR,eACC,4BAAC,iBAAD,OACM,KAAKJ,KADX;AAAA,aAEM,KAAKG,KAFX;AAGC,UAAA,QAAQ,EAAG,KAAKF;AAHjB,UADD;AAOA;;AAjB8C,KAAhD;AAmBA,GApBM,EAoBJ,WApBI,CAAP;AAqBA","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"]}
1
+ {"version":3,"names":["_element","require","_deprecated","_interopRequireDefault","_createHigherOrderComponent","withState","initialState","deprecated","since","alternative","createHigherOrderComponent","OriginalComponent","WrappedComponent","Component","constructor","props","setState","bind","state","render","createElement"],"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":";;;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,WAAA,GAAAC,sBAAA,CAAAF,OAAA;AAKA,IAAAG,2BAAA,GAAAH,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASI,SAASA,CAAEC,YAAY,GAAG,CAAC,CAAC,EAAG;EACtD,IAAAC,mBAAU,EAAE,sBAAsB,EAAE;IACnCC,KAAK,EAAE,KAAK;IACZC,WAAW,EAAE;EACd,CAAE,CAAC;EAEH,OAAO,IAAAC,sDAA0B,EAAIC,iBAAiB,IAAM;IAC3D,OAAO,MAAMC,gBAAgB,SAASC,kBAAS,CAAC;MAC/CC,WAAWA,CAAA,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,GAAGZ,YAAY;MAC1B;MAEAa,MAAMA,CAAA,EAAG;QACR,OACC,IAAAnB,QAAA,CAAAoB,aAAA,EAACT,iBAAiB;UAAA,GACZ,IAAI,CAACI,KAAK;UAAA,GACV,IAAI,CAACG,KAAK;UACfF,QAAQ,EAAG,IAAI,CAACA;QAAU,CAC1B,CAAC;MAEJ;IACD,CAAC;EACF,CAAC,EAAE,WAAY,CAAC;AACjB"}
@@ -4,11 +4,8 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _element = require("@wordpress/element");
9
-
10
8
  var _priorityQueue = require("@wordpress/priority-queue");
11
-
12
9
  /**
13
10
  * WordPress dependencies
14
11
  */
@@ -22,19 +19,16 @@ var _priorityQueue = require("@wordpress/priority-queue");
22
19
  */
23
20
  function getFirstItemsPresentInState(list, state) {
24
21
  const firstItems = [];
25
-
26
22
  for (let i = 0; i < list.length; i++) {
27
23
  const item = list[i];
28
-
29
24
  if (!state.includes(item)) {
30
25
  break;
31
26
  }
32
-
33
27
  firstItems.push(item);
34
28
  }
35
-
36
29
  return firstItems;
37
30
  }
31
+
38
32
  /**
39
33
  * React hook returns an array which items get asynchronously appended from a source array.
40
34
  * This behavior is useful if we want to render a list of items asynchronously for performance reasons.
@@ -44,8 +38,6 @@ function getFirstItemsPresentInState(list, state) {
44
38
  *
45
39
  * @return Async array.
46
40
  */
47
-
48
-
49
41
  function useAsyncList(list, config = {
50
42
  step: 1
51
43
  }) {
@@ -56,14 +48,11 @@ function useAsyncList(list, config = {
56
48
  (0, _element.useEffect)(() => {
57
49
  // On reset, we keep the first items that were previously rendered.
58
50
  let firstItems = getFirstItemsPresentInState(list, current);
59
-
60
51
  if (firstItems.length < step) {
61
52
  firstItems = firstItems.concat(list.slice(firstItems.length, step));
62
53
  }
63
-
64
54
  setCurrent(firstItems);
65
55
  const asyncQueue = (0, _priorityQueue.createQueue)();
66
-
67
56
  for (let i = firstItems.length; i < list.length; i += step) {
68
57
  asyncQueue.add({}, () => {
69
58
  (0, _element.flushSync)(() => {
@@ -71,12 +60,10 @@ function useAsyncList(list, config = {
71
60
  });
72
61
  });
73
62
  }
74
-
75
63
  return () => asyncQueue.reset();
76
64
  }, [list]);
77
65
  return current;
78
66
  }
79
-
80
67
  var _default = useAsyncList;
81
68
  exports.default = _default;
82
69
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-async-list/index.ts"],"names":["getFirstItemsPresentInState","list","state","firstItems","i","length","item","includes","push","useAsyncList","config","step","current","setCurrent","concat","slice","asyncQueue","add","reset"],"mappings":";;;;;;;AAGA;;AACA;;AAJA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,2BAAT,CAA2CC,IAA3C,EAAsDC,KAAtD,EAAwE;AACvE,QAAMC,UAAU,GAAG,EAAnB;;AAEA,OAAM,IAAIC,CAAC,GAAG,CAAd,EAAiBA,CAAC,GAAGH,IAAI,CAACI,MAA1B,EAAkCD,CAAC,EAAnC,EAAwC;AACvC,UAAME,IAAI,GAAGL,IAAI,CAAEG,CAAF,CAAjB;;AACA,QAAK,CAAEF,KAAK,CAACK,QAAN,CAAgBD,IAAhB,CAAP,EAAgC;AAC/B;AACA;;AAEDH,IAAAA,UAAU,CAACK,IAAX,CAAiBF,IAAjB;AACA;;AAED,SAAOH,UAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACA,SAASM,YAAT,CACCR,IADD,EAECS,MAAuB,GAAG;AAAEC,EAAAA,IAAI,EAAE;AAAR,CAF3B,EAGO;AACN,QAAM;AAAEA,IAAAA,IAAI,GAAG;AAAT,MAAeD,MAArB;AACA,QAAM,CAAEE,OAAF,EAAWC,UAAX,IAA0B,uBAAiB,EAAjB,CAAhC;AAEA,0BAAW,MAAM;AAChB;AACA,QAAIV,UAAU,GAAGH,2BAA2B,CAAEC,IAAF,EAAQW,OAAR,CAA5C;;AACA,QAAKT,UAAU,CAACE,MAAX,GAAoBM,IAAzB,EAAgC;AAC/BR,MAAAA,UAAU,GAAGA,UAAU,CAACW,MAAX,CACZb,IAAI,CAACc,KAAL,CAAYZ,UAAU,CAACE,MAAvB,EAA+BM,IAA/B,CADY,CAAb;AAGA;;AACDE,IAAAA,UAAU,CAAEV,UAAF,CAAV;AAEA,UAAMa,UAAU,GAAG,iCAAnB;;AACA,SAAM,IAAIZ,CAAC,GAAGD,UAAU,CAACE,MAAzB,EAAiCD,CAAC,GAAGH,IAAI,CAACI,MAA1C,EAAkDD,CAAC,IAAIO,IAAvD,EAA8D;AAC7DK,MAAAA,UAAU,CAACC,GAAX,CAAgB,EAAhB,EAAoB,MAAM;AACzB,gCAAW,MAAM;AAChBJ,UAAAA,UAAU,CAAIX,KAAF,IAAa,CACxB,GAAGA,KADqB,EAExB,GAAGD,IAAI,CAACc,KAAL,CAAYX,CAAZ,EAAeA,CAAC,GAAGO,IAAnB,CAFqB,CAAf,CAAV;AAIA,SALD;AAMA,OAPD;AAQA;;AAED,WAAO,MAAMK,UAAU,CAACE,KAAX,EAAb;AACA,GAvBD,EAuBG,CAAEjB,IAAF,CAvBH;AAyBA,SAAOW,OAAP;AACA;;eAEcH,Y","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 iin 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"]}
1
+ {"version":3,"names":["_element","require","_priorityQueue","getFirstItemsPresentInState","list","state","firstItems","i","length","item","includes","push","useAsyncList","config","step","current","setCurrent","useState","useEffect","concat","slice","asyncQueue","createQueue","add","flushSync","reset","_default","exports","default"],"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 iin 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":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAD,OAAA;AAJA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASE,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,GAAG,IAAAC,iBAAQ,EAAS,EAAG,CAAC;EAErD,IAAAC,kBAAS,EAAE,MAAM;IAChB;IACA,IAAIZ,UAAU,GAAGH,2BAA2B,CAAEC,IAAI,EAAEW,OAAQ,CAAC;IAC7D,IAAKT,UAAU,CAACE,MAAM,GAAGM,IAAI,EAAG;MAC/BR,UAAU,GAAGA,UAAU,CAACa,MAAM,CAC7Bf,IAAI,CAACgB,KAAK,CAAEd,UAAU,CAACE,MAAM,EAAEM,IAAK,CACrC,CAAC;IACF;IACAE,UAAU,CAAEV,UAAW,CAAC;IAExB,MAAMe,UAAU,GAAG,IAAAC,0BAAW,EAAC,CAAC;IAChC,KAAM,IAAIf,CAAC,GAAGD,UAAU,CAACE,MAAM,EAAED,CAAC,GAAGH,IAAI,CAACI,MAAM,EAAED,CAAC,IAAIO,IAAI,EAAG;MAC7DO,UAAU,CAACE,GAAG,CAAE,CAAC,CAAC,EAAE,MAAM;QACzB,IAAAC,kBAAS,EAAE,MAAM;UAChBR,UAAU,CAAIX,KAAK,IAAM,CACxB,GAAGA,KAAK,EACR,GAAGD,IAAI,CAACgB,KAAK,CAAEb,CAAC,EAAEA,CAAC,GAAGO,IAAK,CAAC,CAC3B,CAAC;QACJ,CAAE,CAAC;MACJ,CAAE,CAAC;IACJ;IAEA,OAAO,MAAMO,UAAU,CAACI,KAAK,CAAC,CAAC;EAChC,CAAC,EAAE,CAAErB,IAAI,CAAG,CAAC;EAEb,OAAOW,OAAO;AACf;AAAC,IAAAW,QAAA,GAEcd,YAAY;AAAAe,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _keycodes = require("@wordpress/keycodes");
11
-
12
9
  var _dom = require("@wordpress/dom");
13
-
14
10
  var _useRefEffect = _interopRequireDefault(require("../use-ref-effect"));
15
-
16
11
  /**
17
12
  * WordPress dependencies
18
13
  */
@@ -43,72 +38,61 @@ var _useRefEffect = _interopRequireDefault(require("../use-ref-effect"));
43
38
  * ```
44
39
  */
45
40
  function useConstrainedTabbing() {
46
- return (0, _useRefEffect.default)((
47
- /** @type {HTMLElement} */
48
- node) => {
49
- function onKeyDown(
50
- /** @type {KeyboardEvent} */
51
- event) {
41
+ return (0, _useRefEffect.default)(( /** @type {HTMLElement} */node) => {
42
+ function onKeyDown( /** @type {KeyboardEvent} */event) {
52
43
  const {
53
44
  keyCode,
54
45
  shiftKey,
55
46
  target
56
47
  } = event;
57
-
58
48
  if (keyCode !== _keycodes.TAB) {
59
49
  return;
60
50
  }
61
-
62
51
  const action = shiftKey ? 'findPrevious' : 'findNext';
63
- const nextElement = _dom.focus.tabbable[action](
64
- /** @type {HTMLElement} */
65
- target) || null; // When the target element contains the element that is about to
52
+ const nextElement = _dom.focus.tabbable[action]( /** @type {HTMLElement} */target) || null;
53
+
54
+ // When the target element contains the element that is about to
66
55
  // receive focus, for example when the target is a tabbable
67
56
  // container, browsers may disagree on where to move focus next.
68
57
  // In this case we can't rely on native browsers behavior. We need
69
58
  // to manage focus instead.
70
59
  // See https://github.com/WordPress/gutenberg/issues/46041.
71
-
72
- if (
73
- /** @type {HTMLElement} */
74
- target.contains(nextElement)) {
60
+ if ( /** @type {HTMLElement} */target.contains(nextElement)) {
75
61
  event.preventDefault();
76
62
  /** @type {HTMLElement} */
77
-
78
63
  nextElement?.focus();
79
64
  return;
80
- } // If the element that is about to receive focus is inside the
65
+ }
66
+
67
+ // If the element that is about to receive focus is inside the
81
68
  // area, rely on native browsers behavior and let tabbing follow
82
69
  // the native tab sequence.
83
-
84
-
85
70
  if (node.contains(nextElement)) {
86
71
  return;
87
- } // If the element that is about to receive focus is outside the
72
+ }
73
+
74
+ // If the element that is about to receive focus is outside the
88
75
  // area, move focus to a div and insert it at the start or end of
89
76
  // the area, depending on the direction. Without preventing default
90
77
  // behaviour, the browser will then move focus to the next element.
91
-
92
-
93
78
  const domAction = shiftKey ? 'append' : 'prepend';
94
79
  const {
95
80
  ownerDocument
96
81
  } = node;
97
82
  const trap = ownerDocument.createElement('div');
98
83
  trap.tabIndex = -1;
99
- node[domAction](trap); // Remove itself when the trap loses focus.
84
+ node[domAction](trap);
100
85
 
86
+ // Remove itself when the trap loses focus.
101
87
  trap.addEventListener('blur', () => node.removeChild(trap));
102
88
  trap.focus();
103
89
  }
104
-
105
90
  node.addEventListener('keydown', onKeyDown);
106
91
  return () => {
107
92
  node.removeEventListener('keydown', onKeyDown);
108
93
  };
109
94
  }, []);
110
95
  }
111
-
112
96
  var _default = useConstrainedTabbing;
113
97
  exports.default = _default;
114
98
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.js"],"names":["useConstrainedTabbing","node","onKeyDown","event","keyCode","shiftKey","target","TAB","action","nextElement","focus","tabbable","contains","preventDefault","domAction","ownerDocument","trap","createElement","tabIndex","addEventListener","removeChild","removeEventListener"],"mappings":";;;;;;;;;AAGA;;AACA;;AAKA;;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,qBAAT,GAAiC;AAChC,SAAO,2BAAc;AAAE;AAA2BC,EAAAA,IAA7B,KAAuC;AAC3D,aAASC,SAAT;AAAoB;AAA6BC,IAAAA,KAAjD,EAAyD;AACxD,YAAM;AAAEC,QAAAA,OAAF;AAAWC,QAAAA,QAAX;AAAqBC,QAAAA;AAArB,UAAgCH,KAAtC;;AAEA,UAAKC,OAAO,KAAKG,aAAjB,EAAuB;AACtB;AACA;;AAED,YAAMC,MAAM,GAAGH,QAAQ,GAAG,cAAH,GAAoB,UAA3C;AACA,YAAMI,WAAW,GAChBC,WAAMC,QAAN,CAAgBH,MAAhB;AACC;AAA6BF,MAAAA,MAD9B,KAEK,IAHN,CARwD,CAaxD;AACA;AACA;AACA;AACA;AACA;;AACA;AACC;AAA6BA,MAAAA,MAAF,CAAWM,QAAX,CAAqBH,WAArB,CAD5B,EAEE;AACDN,QAAAA,KAAK,CAACU,cAAN;AACA;;AAA6BJ,QAAAA,WAAF,EAAiBC,KAAjB;AAC3B;AACA,OAzBuD,CA2BxD;AACA;AACA;;;AACA,UAAKT,IAAI,CAACW,QAAL,CAAeH,WAAf,CAAL,EAAoC;AACnC;AACA,OAhCuD,CAkCxD;AACA;AACA;AACA;;;AACA,YAAMK,SAAS,GAAGT,QAAQ,GAAG,QAAH,GAAc,SAAxC;AACA,YAAM;AAAEU,QAAAA;AAAF,UAAoBd,IAA1B;AACA,YAAMe,IAAI,GAAGD,aAAa,CAACE,aAAd,CAA6B,KAA7B,CAAb;AAEAD,MAAAA,IAAI,CAACE,QAAL,GAAgB,CAAC,CAAjB;AACAjB,MAAAA,IAAI,CAAEa,SAAF,CAAJ,CAAmBE,IAAnB,EA3CwD,CA6CxD;;AACAA,MAAAA,IAAI,CAACG,gBAAL,CAAuB,MAAvB,EAA+B,MAAMlB,IAAI,CAACmB,WAAL,CAAkBJ,IAAlB,CAArC;AAEAA,MAAAA,IAAI,CAACN,KAAL;AACA;;AAEDT,IAAAA,IAAI,CAACkB,gBAAL,CAAuB,SAAvB,EAAkCjB,SAAlC;AACA,WAAO,MAAM;AACZD,MAAAA,IAAI,CAACoB,mBAAL,CAA0B,SAA1B,EAAqCnB,SAArC;AACA,KAFD;AAGA,GAxDM,EAwDJ,EAxDI,CAAP;AAyDA;;eAEcF,qB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { TAB } from '@wordpress/keycodes';\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 { keyCode, shiftKey, target } = event;\n\n\t\t\tif ( keyCode !== 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\t/** @type {HTMLElement} */ ( nextElement )?.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"]}
1
+ {"version":3,"names":["_keycodes","require","_dom","_useRefEffect","_interopRequireDefault","useConstrainedTabbing","useRefEffect","node","onKeyDown","event","keyCode","shiftKey","target","TAB","action","nextElement","focus","tabbable","contains","preventDefault","domAction","ownerDocument","trap","createElement","tabIndex","addEventListener","removeChild","removeEventListener","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { TAB } from '@wordpress/keycodes';\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 { keyCode, shiftKey, target } = event;\n\n\t\t\tif ( keyCode !== 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\t/** @type {HTMLElement} */ ( nextElement )?.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":";;;;;;;AAGA,IAAAA,SAAA,GAAAC,OAAA;AACA,IAAAC,IAAA,GAAAD,OAAA;AAKA,IAAAE,aAAA,GAAAC,sBAAA,CAAAH,OAAA;AATA;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASI,qBAAqBA,CAAA,EAAG;EAChC,OAAO,IAAAC,qBAAY,EAAE,EAAE,0BAA2BC,IAAI,KAAM;IAC3D,SAASC,SAASA,CAAA,CAAE,4BAA6BC,KAAK,EAAG;MACxD,MAAM;QAAEC,OAAO;QAAEC,QAAQ;QAAEC;MAAO,CAAC,GAAGH,KAAK;MAE3C,IAAKC,OAAO,KAAKG,aAAG,EAAG;QACtB;MACD;MAEA,MAAMC,MAAM,GAAGH,QAAQ,GAAG,cAAc,GAAG,UAAU;MACrD,MAAMI,WAAW,GAChBC,UAAK,CAACC,QAAQ,CAAEH,MAAM,CAAE,EACvB,0BAA6BF,MAC9B,CAAC,IAAI,IAAI;;MAEV;MACA;MACA;MACA;MACA;MACA;MACA,KACC,0BAA6BA,MAAM,CAAGM,QAAQ,CAAEH,WAAY,CAAC,EAC5D;QACDN,KAAK,CAACU,cAAc,CAAC,CAAC;QACtB;QAA6BJ,WAAW,EAAIC,KAAK,CAAC,CAAC;QACnD;MACD;;MAEA;MACA;MACA;MACA,IAAKT,IAAI,CAACW,QAAQ,CAAEH,WAAY,CAAC,EAAG;QACnC;MACD;;MAEA;MACA;MACA;MACA;MACA,MAAMK,SAAS,GAAGT,QAAQ,GAAG,QAAQ,GAAG,SAAS;MACjD,MAAM;QAAEU;MAAc,CAAC,GAAGd,IAAI;MAC9B,MAAMe,IAAI,GAAGD,aAAa,CAACE,aAAa,CAAE,KAAM,CAAC;MAEjDD,IAAI,CAACE,QAAQ,GAAG,CAAC,CAAC;MAClBjB,IAAI,CAAEa,SAAS,CAAE,CAAEE,IAAK,CAAC;;MAEzB;MACAA,IAAI,CAACG,gBAAgB,CAAE,MAAM,EAAE,MAAMlB,IAAI,CAACmB,WAAW,CAAEJ,IAAK,CAAE,CAAC;MAE/DA,IAAI,CAACN,KAAK,CAAC,CAAC;IACb;IAEAT,IAAI,CAACkB,gBAAgB,CAAE,SAAS,EAAEjB,SAAU,CAAC;IAC7C,OAAO,MAAM;MACZD,IAAI,CAACoB,mBAAmB,CAAE,SAAS,EAAEnB,SAAU,CAAC;IACjD,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR;AAAC,IAAAoB,QAAA,GAEcvB,qBAAqB;AAAAwB,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -4,18 +4,18 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
-
8
7
  var _element = require("@wordpress/element");
9
-
10
8
  /**
11
9
  * WordPress dependencies
12
10
  */
11
+
13
12
  function useConstrainedTabbing() {
14
- const ref = (0, _element.useRef)(); // Do nothing on mobile as tabbing is not a mobile behavior.
13
+ const ref = (0, _element.useRef)();
14
+
15
+ // Do nothing on mobile as tabbing is not a mobile behavior.
15
16
 
16
17
  return ref;
17
18
  }
18
-
19
19
  var _default = useConstrainedTabbing;
20
20
  exports.default = _default;
21
21
  //# sourceMappingURL=index.native.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.native.js"],"names":["useConstrainedTabbing","ref"],"mappings":";;;;;;;AAGA;;AAHA;AACA;AACA;AAGA,SAASA,qBAAT,GAAiC;AAChC,QAAMC,GAAG,GAAG,sBAAZ,CADgC,CAGhC;;AAEA,SAAOA,GAAP;AACA;;eAEcD,qB","sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\nfunction useConstrainedTabbing() {\n\tconst ref = useRef();\n\n\t// Do nothing on mobile as tabbing is not a mobile behavior.\n\n\treturn ref;\n}\n\nexport default useConstrainedTabbing;\n"]}
1
+ {"version":3,"names":["_element","require","useConstrainedTabbing","ref","useRef","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-constrained-tabbing/index.native.js"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { useRef } from '@wordpress/element';\n\nfunction useConstrainedTabbing() {\n\tconst ref = useRef();\n\n\t// Do nothing on mobile as tabbing is not a mobile behavior.\n\n\treturn ref;\n}\n\nexport default useConstrainedTabbing;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAGA,SAASC,qBAAqBA,CAAA,EAAG;EAChC,MAAMC,GAAG,GAAG,IAAAC,eAAM,EAAC,CAAC;;EAEpB;;EAEA,OAAOD,GAAG;AACX;AAAC,IAAAE,QAAA,GAEcH,qBAAqB;AAAAI,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = useCopyOnClick;
9
-
10
8
  var _clipboard = _interopRequireDefault(require("clipboard"));
11
-
12
9
  var _element = require("@wordpress/element");
13
-
14
10
  var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
15
-
16
11
  /**
17
12
  * External dependencies
18
13
  */
@@ -22,7 +17,6 @@ var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
22
17
  */
23
18
 
24
19
  /* eslint-disable jsdoc/no-undefined-types */
25
-
26
20
  /**
27
21
  * Copies the text to the clipboard when the element is clicked.
28
22
  *
@@ -42,19 +36,18 @@ function useCopyOnClick(ref, text, timeout = 4000) {
42
36
  since: '5.8',
43
37
  alternative: 'wp.compose.useCopyToClipboard'
44
38
  });
45
- /** @type {import('react').MutableRefObject<Clipboard | undefined>} */
46
39
 
40
+ /** @type {import('react').MutableRefObject<Clipboard | undefined>} */
47
41
  const clipboard = (0, _element.useRef)();
48
42
  const [hasCopied, setHasCopied] = (0, _element.useState)(false);
49
43
  (0, _element.useEffect)(() => {
50
44
  /** @type {number | undefined} */
51
45
  let timeoutId;
52
-
53
46
  if (!ref.current) {
54
47
  return;
55
- } // Clipboard listens to click events.
56
-
48
+ }
57
49
 
50
+ // Clipboard listens to click events.
58
51
  clipboard.current = new _clipboard.default(ref.current, {
59
52
  text: () => typeof text === 'function' ? text() : text
60
53
  });
@@ -65,13 +58,12 @@ function useCopyOnClick(ref, text, timeout = 4000) {
65
58
  // Clearing selection will move focus back to the triggering button,
66
59
  // ensuring that it is not reset to the body, and further that it is
67
60
  // kept within the rendered node.
68
- clearSelection(); // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
61
+ clearSelection();
69
62
 
63
+ // Handle ClipboardJS focus bug, see https://github.com/zenorocha/clipboard.js/issues/680
70
64
  if (trigger) {
71
- /** @type {HTMLElement} */
72
- trigger.focus();
65
+ /** @type {HTMLElement} */trigger.focus();
73
66
  }
74
-
75
67
  if (timeout) {
76
68
  setHasCopied(true);
77
69
  clearTimeout(timeoutId);
@@ -82,7 +74,6 @@ function useCopyOnClick(ref, text, timeout = 4000) {
82
74
  if (clipboard.current) {
83
75
  clipboard.current.destroy();
84
76
  }
85
-
86
77
  clearTimeout(timeoutId);
87
78
  };
88
79
  }, [text, timeout, setHasCopied]);
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-on-click/index.js"],"names":["useCopyOnClick","ref","text","timeout","since","alternative","clipboard","hasCopied","setHasCopied","timeoutId","current","Clipboard","on","clearSelection","trigger","focus","clearTimeout","setTimeout","destroy"],"mappings":";;;;;;;;;AAGA;;AAKA;;AACA;;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,cAAT,CAAyBC,GAAzB,EAA8BC,IAA9B,EAAoCC,OAAO,GAAG,IAA9C,EAAqD;AACnE;AACA,2BAAY,2BAAZ,EAAyC;AACxCC,IAAAA,KAAK,EAAE,KADiC;AAExCC,IAAAA,WAAW,EAAE;AAF2B,GAAzC;AAKA;;AACA,QAAMC,SAAS,GAAG,sBAAlB;AACA,QAAM,CAAEC,SAAF,EAAaC,YAAb,IAA8B,uBAAU,KAAV,CAApC;AAEA,0BAAW,MAAM;AAChB;AACA,QAAIC,SAAJ;;AAEA,QAAK,CAAER,GAAG,CAACS,OAAX,EAAqB;AACpB;AACA,KANe,CAQhB;;;AACAJ,IAAAA,SAAS,CAACI,OAAV,GAAoB,IAAIC,kBAAJ,CAAeV,GAAG,CAACS,OAAnB,EAA4B;AAC/CR,MAAAA,IAAI,EAAE,MAAQ,OAAOA,IAAP,KAAgB,UAAhB,GAA6BA,IAAI,EAAjC,GAAsCA;AADL,KAA5B,CAApB;AAIAI,IAAAA,SAAS,CAACI,OAAV,CAAkBE,EAAlB,CAAsB,SAAtB,EAAiC,CAAE;AAAEC,MAAAA,cAAF;AAAkBC,MAAAA;AAAlB,KAAF,KAAmC;AACnE;AACA;AACA;AACAD,MAAAA,cAAc,GAJqD,CAMnE;;AACA,UAAKC,OAAL,EAAe;AACd;AAA6BA,QAAAA,OAAF,CAAYC,KAAZ;AAC3B;;AAED,UAAKZ,OAAL,EAAe;AACdK,QAAAA,YAAY,CAAE,IAAF,CAAZ;AACAQ,QAAAA,YAAY,CAAEP,SAAF,CAAZ;AACAA,QAAAA,SAAS,GAAGQ,UAAU,CAAE,MAAMT,YAAY,CAAE,KAAF,CAApB,EAA+BL,OAA/B,CAAtB;AACA;AACD,KAhBD;AAkBA,WAAO,MAAM;AACZ,UAAKG,SAAS,CAACI,OAAf,EAAyB;AACxBJ,QAAAA,SAAS,CAACI,OAAV,CAAkBQ,OAAlB;AACA;;AACDF,MAAAA,YAAY,CAAEP,SAAF,CAAZ;AACA,KALD;AAMA,GArCD,EAqCG,CAAEP,IAAF,EAAQC,OAAR,EAAiBK,YAAjB,CArCH;AAuCA,SAAOD,SAAP;AACA","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 clipboard = 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\tclipboard.current = new Clipboard( ref.current, {\n\t\t\ttext: () => ( typeof text === 'function' ? text() : text ),\n\t\t} );\n\n\t\tclipboard.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 ( clipboard.current ) {\n\t\t\t\tclipboard.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"]}
1
+ {"version":3,"names":["_clipboard","_interopRequireDefault","require","_element","_deprecated","useCopyOnClick","ref","text","timeout","deprecated","since","alternative","clipboard","useRef","hasCopied","setHasCopied","useState","useEffect","timeoutId","current","Clipboard","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 clipboard = 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\tclipboard.current = new Clipboard( ref.current, {\n\t\t\ttext: () => ( typeof text === 'function' ? text() : text ),\n\t\t} );\n\n\t\tclipboard.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 ( clipboard.current ) {\n\t\t\t\tclipboard.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":";;;;;;;AAGA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,WAAA,GAAAH,sBAAA,CAAAC,OAAA;AATA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,cAAcA,CAAEC,GAAG,EAAEC,IAAI,EAAEC,OAAO,GAAG,IAAI,EAAG;EACnE;EACA,IAAAC,mBAAU,EAAE,2BAA2B,EAAE;IACxCC,KAAK,EAAE,KAAK;IACZC,WAAW,EAAE;EACd,CAAE,CAAC;;EAEH;EACA,MAAMC,SAAS,GAAG,IAAAC,eAAM,EAAC,CAAC;EAC1B,MAAM,CAAEC,SAAS,EAAEC,YAAY,CAAE,GAAG,IAAAC,iBAAQ,EAAE,KAAM,CAAC;EAErD,IAAAC,kBAAS,EAAE,MAAM;IAChB;IACA,IAAIC,SAAS;IAEb,IAAK,CAAEZ,GAAG,CAACa,OAAO,EAAG;MACpB;IACD;;IAEA;IACAP,SAAS,CAACO,OAAO,GAAG,IAAIC,kBAAS,CAAEd,GAAG,CAACa,OAAO,EAAE;MAC/CZ,IAAI,EAAEA,CAAA,KAAQ,OAAOA,IAAI,KAAK,UAAU,GAAGA,IAAI,CAAC,CAAC,GAAGA;IACrD,CAAE,CAAC;IAEHK,SAAS,CAACO,OAAO,CAACE,EAAE,CAAE,SAAS,EAAE,CAAE;MAAEC,cAAc;MAAEC;IAAQ,CAAC,KAAM;MACnE;MACA;MACA;MACAD,cAAc,CAAC,CAAC;;MAEhB;MACA,IAAKC,OAAO,EAAG;QACd,0BAA6BA,OAAO,CAAGC,KAAK,CAAC,CAAC;MAC/C;MAEA,IAAKhB,OAAO,EAAG;QACdO,YAAY,CAAE,IAAK,CAAC;QACpBU,YAAY,CAAEP,SAAU,CAAC;QACzBA,SAAS,GAAGQ,UAAU,CAAE,MAAMX,YAAY,CAAE,KAAM,CAAC,EAAEP,OAAQ,CAAC;MAC/D;IACD,CAAE,CAAC;IAEH,OAAO,MAAM;MACZ,IAAKI,SAAS,CAACO,OAAO,EAAG;QACxBP,SAAS,CAACO,OAAO,CAACQ,OAAO,CAAC,CAAC;MAC5B;MACAF,YAAY,CAAEP,SAAU,CAAC;IAC1B,CAAC;EACF,CAAC,EAAE,CAAEX,IAAI,EAAEC,OAAO,EAAEO,YAAY,CAAG,CAAC;EAEpC,OAAOD,SAAS;AACjB"}
@@ -1,18 +1,13 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = useCopyToClipboard;
9
-
10
8
  var _clipboard = _interopRequireDefault(require("clipboard"));
11
-
12
9
  var _element = require("@wordpress/element");
13
-
14
10
  var _useRefEffect = _interopRequireDefault(require("../use-ref-effect"));
15
-
16
11
  /**
17
12
  * External dependencies
18
13
  */
@@ -35,6 +30,7 @@ function useUpdatedRef(value) {
35
30
  ref.current = value;
36
31
  return ref;
37
32
  }
33
+
38
34
  /**
39
35
  * Copies the given text to the clipboard when the element is clicked.
40
36
  *
@@ -45,8 +41,6 @@ function useUpdatedRef(value) {
45
41
  *
46
42
  * @return {import('react').Ref<TElementType>} A ref to assign to the target element.
47
43
  */
48
-
49
-
50
44
  function useCopyToClipboard(text, onSuccess) {
51
45
  // Store the dependencies as refs and continuously update them so they're
52
46
  // fresh when the callback is called.
@@ -58,7 +52,6 @@ function useCopyToClipboard(text, onSuccess) {
58
52
  text() {
59
53
  return typeof textRef.current === 'function' ? textRef.current() : textRef.current || '';
60
54
  }
61
-
62
55
  });
63
56
  clipboard.on('success', ({
64
57
  clearSelection
@@ -66,11 +59,10 @@ function useCopyToClipboard(text, onSuccess) {
66
59
  // Clearing selection will move focus back to the triggering
67
60
  // button, ensuring that it is not reset to the body, and
68
61
  // further that it is kept within the rendered node.
69
- clearSelection(); // Handle ClipboardJS focus bug, see
62
+ clearSelection();
63
+ // Handle ClipboardJS focus bug, see
70
64
  // https://github.com/zenorocha/clipboard.js/issues/680
71
-
72
65
  node.focus();
73
-
74
66
  if (onSuccessRef.current) {
75
67
  onSuccessRef.current();
76
68
  }
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-copy-to-clipboard/index.js"],"names":["useUpdatedRef","value","ref","current","useCopyToClipboard","text","onSuccess","textRef","onSuccessRef","node","clipboard","Clipboard","on","clearSelection","focus","destroy"],"mappings":";;;;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASA,aAAT,CAAwBC,KAAxB,EAAgC;AAC/B,QAAMC,GAAG,GAAG,qBAAQD,KAAR,CAAZ;AACAC,EAAAA,GAAG,CAACC,OAAJ,GAAcF,KAAd;AACA,SAAOC,GAAP;AACA;AAED;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;;AACe,SAASE,kBAAT,CAA6BC,IAA7B,EAAmCC,SAAnC,EAA+C;AAC7D;AACA;AACA,QAAMC,OAAO,GAAGP,aAAa,CAAEK,IAAF,CAA7B;AACA,QAAMG,YAAY,GAAGR,aAAa,CAAEM,SAAF,CAAlC;AACA,SAAO,2BAAgBG,IAAF,IAAY;AAChC;AACA,UAAMC,SAAS,GAAG,IAAIC,kBAAJ,CAAeF,IAAf,EAAqB;AACtCJ,MAAAA,IAAI,GAAG;AACN,eAAO,OAAOE,OAAO,CAACJ,OAAf,KAA2B,UAA3B,GACJI,OAAO,CAACJ,OAAR,EADI,GAEJI,OAAO,CAACJ,OAAR,IAAmB,EAFtB;AAGA;;AALqC,KAArB,CAAlB;AAQAO,IAAAA,SAAS,CAACE,EAAV,CAAc,SAAd,EAAyB,CAAE;AAAEC,MAAAA;AAAF,KAAF,KAA0B;AAClD;AACA;AACA;AACAA,MAAAA,cAAc,GAJoC,CAKlD;AACA;;AACAJ,MAAAA,IAAI,CAACK,KAAL;;AAEA,UAAKN,YAAY,CAACL,OAAlB,EAA4B;AAC3BK,QAAAA,YAAY,CAACL,OAAb;AACA;AACD,KAZD;AAcA,WAAO,MAAM;AACZO,MAAAA,SAAS,CAACK,OAAV;AACA,KAFD;AAGA,GA3BM,EA2BJ,EA3BI,CAAP;AA4BA","sourcesContent":["/**\n * External dependencies\n */\nimport Clipboard from 'clipboard';\n\n/**\n * WordPress dependencies\n */\nimport { useRef } 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\tref.current = 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\t\t\t// Handle ClipboardJS focus bug, see\n\t\t\t// https://github.com/zenorocha/clipboard.js/issues/680\n\t\t\tnode.focus();\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"]}
1
+ {"version":3,"names":["_clipboard","_interopRequireDefault","require","_element","_useRefEffect","useUpdatedRef","value","ref","useRef","current","useCopyToClipboard","text","onSuccess","textRef","onSuccessRef","useRefEffect","node","clipboard","Clipboard","on","clearSelection","focus","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 } 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\tref.current = 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\t\t\t// Handle ClipboardJS focus bug, see\n\t\t\t// https://github.com/zenorocha/clipboard.js/issues/680\n\t\t\tnode.focus();\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":";;;;;;;AAGA,IAAAA,UAAA,GAAAC,sBAAA,CAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,aAAA,GAAAH,sBAAA,CAAAC,OAAA;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA,SAASG,aAAaA,CAAEC,KAAK,EAAG;EAC/B,MAAMC,GAAG,GAAG,IAAAC,eAAM,EAAEF,KAAM,CAAC;EAC3BC,GAAG,CAACE,OAAO,GAAGH,KAAK;EACnB,OAAOC,GAAG;AACX;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,kBAAkBA,CAAEC,IAAI,EAAEC,SAAS,EAAG;EAC7D;EACA;EACA,MAAMC,OAAO,GAAGR,aAAa,CAAEM,IAAK,CAAC;EACrC,MAAMG,YAAY,GAAGT,aAAa,CAAEO,SAAU,CAAC;EAC/C,OAAO,IAAAG,qBAAY,EAAIC,IAAI,IAAM;IAChC;IACA,MAAMC,SAAS,GAAG,IAAIC,kBAAS,CAAEF,IAAI,EAAE;MACtCL,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;IAEHQ,SAAS,CAACE,EAAE,CAAE,SAAS,EAAE,CAAE;MAAEC;IAAe,CAAC,KAAM;MAClD;MACA;MACA;MACAA,cAAc,CAAC,CAAC;MAChB;MACA;MACAJ,IAAI,CAACK,KAAK,CAAC,CAAC;MAEZ,IAAKP,YAAY,CAACL,OAAO,EAAG;QAC3BK,YAAY,CAACL,OAAO,CAAC,CAAC;MACvB;IACD,CAAE,CAAC;IAEH,OAAO,MAAM;MACZQ,SAAS,CAACK,OAAO,CAAC,CAAC;IACpB,CAAC;EACF,CAAC,EAAE,EAAG,CAAC;AACR"}
@@ -4,13 +4,9 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = useDebounce;
7
-
8
7
  var _useMemoOne = require("use-memo-one");
9
-
10
8
  var _element = require("@wordpress/element");
11
-
12
9
  var _debounce = require("../../utils/debounce");
13
-
14
10
  /**
15
11
  * External dependencies
16
12
  */
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-debounce/index.js"],"names":["useDebounce","fn","wait","options","debounced","cancel"],"mappings":";;;;;;;AAGA;;AAKA;;AAKA;;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASA,WAAT,CAAsBC,EAAtB,EAA0BC,IAA1B,EAAgCC,OAAhC,EAA0C;AACxD,QAAMC,SAAS,GAAG,4BACjB,MAAM,wBAAUH,EAAV,EAAcC,IAAd,aAAcA,IAAd,cAAcA,IAAd,GAAsB,CAAtB,EAAyBC,OAAzB,CADW,EAEjB,CAAEF,EAAF,EAAMC,IAAN,EAAYC,OAAZ,CAFiB,CAAlB;AAIA,0BAAW,MAAM,MAAMC,SAAS,CAACC,MAAV,EAAvB,EAA2C,CAAED,SAAF,CAA3C;AACA,SAAOA,SAAP;AACA","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://docs-lodash.com/v4/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"]}
1
+ {"version":3,"names":["_useMemoOne","require","_element","_debounce","useDebounce","fn","wait","options","debounced","useMemoOne","debounce","useEffect","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://docs-lodash.com/v4/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":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAKA,IAAAC,QAAA,GAAAD,OAAA;AAKA,IAAAE,SAAA,GAAAF,OAAA;AAbA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACe,SAASG,WAAWA,CAAEC,EAAE,EAAEC,IAAI,EAAEC,OAAO,EAAG;EACxD,MAAMC,SAAS,GAAG,IAAAC,sBAAU,EAC3B,MAAM,IAAAC,kBAAQ,EAAEL,EAAE,EAAEC,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAI,CAAC,EAAEC,OAAQ,CAAC,EACxC,CAAEF,EAAE,EAAEC,IAAI,EAAEC,OAAO,CACpB,CAAC;EACD,IAAAI,kBAAS,EAAE,MAAM,MAAMH,SAAS,CAACI,MAAM,CAAC,CAAC,EAAE,CAAEJ,SAAS,CAAG,CAAC;EAC1D,OAAOA,SAAS;AACjB"}
@@ -1,26 +1,17 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = void 0;
9
-
10
8
  var _element = require("@wordpress/element");
11
-
12
9
  var _keycodes = require("@wordpress/keycodes");
13
-
14
10
  var _useConstrainedTabbing = _interopRequireDefault(require("../use-constrained-tabbing"));
15
-
16
11
  var _useFocusOnMount = _interopRequireDefault(require("../use-focus-on-mount"));
17
-
18
12
  var _useFocusReturn = _interopRequireDefault(require("../use-focus-return"));
19
-
20
13
  var _useFocusOutside = _interopRequireDefault(require("../use-focus-outside"));
21
-
22
14
  var _useMergeRefs = _interopRequireDefault(require("../use-merge-refs"));
23
-
24
15
  /**
25
16
  * External dependencies
26
17
  */
@@ -63,7 +54,6 @@ function useDialog(options) {
63
54
  if (!node) {
64
55
  return;
65
56
  }
66
-
67
57
  node.addEventListener('keydown', event => {
68
58
  // Close on escape.
69
59
  if (event.keyCode === _keycodes.ESCAPE && !event.defaultPrevented && currentOptions.current?.onClose) {
@@ -72,11 +62,11 @@ function useDialog(options) {
72
62
  }
73
63
  });
74
64
  }, []);
75
- return [(0, _useMergeRefs.default)([options.focusOnMount !== false ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), { ...focusOutsideProps,
65
+ return [(0, _useMergeRefs.default)([options.focusOnMount !== false ? constrainedTabbingRef : null, options.focusOnMount !== false ? focusReturnRef : null, options.focusOnMount !== false ? focusOnMountRef : null, closeOnEscapeRef]), {
66
+ ...focusOutsideProps,
76
67
  tabIndex: -1
77
68
  }];
78
69
  }
79
-
80
70
  var _default = useDialog;
81
71
  exports.default = _default;
82
72
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["@wordpress/compose/src/hooks/use-dialog/index.ts"],"names":["useDialog","options","currentOptions","current","Object","values","constrainedTabbingRef","focusOnMountRef","focusOnMount","focusReturnRef","focusOutsideProps","event","__unstableOnClose","onClose","closeOnEscapeRef","node","addEventListener","keyCode","ESCAPE","defaultPrevented","preventDefault","tabIndex"],"mappings":";;;;;;;;;AAQA;;AACA;;AAKA;;AACA;;AACA;;AACA;;AACA;;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASA,SAAT,CAAoBC,OAApB,EAA8D;AAC7D,QAAMC,cAAc,GAAG,sBAAvB;AACA,0BAAW,MAAM;AAChBA,IAAAA,cAAc,CAACC,OAAf,GAAyBF,OAAzB;AACA,GAFD,EAEGG,MAAM,CAACC,MAAP,CAAeJ,OAAf,CAFH;AAGA,QAAMK,qBAAqB,GAAG,qCAA9B;AACA,QAAMC,eAAe,GAAG,8BAAiBN,OAAO,CAACO,YAAzB,CAAxB;AACA,QAAMC,cAAc,GAAG,8BAAvB;AACA,QAAMC,iBAAiB,GAAG,8BAAmBC,KAAF,IAAa;AACvD;AACA;AACA,QAAKT,cAAc,CAACC,OAAf,EAAwBS,iBAA7B,EAAiD;AAChDV,MAAAA,cAAc,CAACC,OAAf,CAAuBS,iBAAvB,CAA0C,eAA1C,EAA2DD,KAA3D;AACA,KAFD,MAEO,IAAKT,cAAc,CAACC,OAAf,EAAwBU,OAA7B,EAAuC;AAC7CX,MAAAA,cAAc,CAACC,OAAf,CAAuBU,OAAvB;AACA;AACD,GARyB,CAA1B;AASA,QAAMC,gBAAgB,GAAG,0BAAeC,IAAF,IAAyB;AAC9D,QAAK,CAAEA,IAAP,EAAc;AACb;AACA;;AAEDA,IAAAA,IAAI,CAACC,gBAAL,CAAuB,SAAvB,EAAoCL,KAAF,IAA4B;AAC7D;AACA,UACCA,KAAK,CAACM,OAAN,KAAkBC,gBAAlB,IACA,CAAEP,KAAK,CAACQ,gBADR,IAEAjB,cAAc,CAACC,OAAf,EAAwBU,OAHzB,EAIE;AACDF,QAAAA,KAAK,CAACS,cAAN;AACAlB,QAAAA,cAAc,CAACC,OAAf,CAAuBU,OAAvB;AACA;AACD,KAVD;AAWA,GAhBwB,EAgBtB,EAhBsB,CAAzB;AAkBA,SAAO,CACN,2BAAc,CACbZ,OAAO,CAACO,YAAR,KAAyB,KAAzB,GAAiCF,qBAAjC,GAAyD,IAD5C,EAEbL,OAAO,CAACO,YAAR,KAAyB,KAAzB,GAAiCC,cAAjC,GAAkD,IAFrC,EAGbR,OAAO,CAACO,YAAR,KAAyB,KAAzB,GAAiCD,eAAjC,GAAmD,IAHtC,EAIbO,gBAJa,CAAd,CADM,EAON,EACC,GAAGJ,iBADJ;AAECW,IAAAA,QAAQ,EAAE,CAAC;AAFZ,GAPM,CAAP;AAYA;;eAEcrB,S","sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback, SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport useConstrainedTabbing from '../use-constrained-tabbing';\nimport useFocusOnMount from '../use-focus-on-mount';\nimport useFocusReturn from '../use-focus-return';\nimport useFocusOutside from '../use-focus-outside';\nimport useMergeRefs from '../use-merge-refs';\n\ntype DialogOptions = {\n\tfocusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];\n\tonClose?: () => void;\n\t/**\n\t * Use the `onClose` prop instead.\n\t *\n\t * @deprecated\n\t */\n\t__unstableOnClose?: (\n\t\ttype: string | undefined,\n\t\tevent: SyntheticEvent\n\t) => void;\n};\n\ntype useDialogReturn = [\n\tRefCallback< HTMLElement >,\n\tReturnType< typeof useFocusOutside > & Pick< HTMLElement, 'tabIndex' >\n];\n\n/**\n * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:\n * - constrained tabbing.\n * - focus on mount.\n * - return focus on unmount.\n * - focus outside.\n *\n * @param options Dialog Options.\n */\nfunction useDialog( options: DialogOptions ): useDialogReturn {\n\tconst currentOptions = useRef< DialogOptions | undefined >();\n\tuseEffect( () => {\n\t\tcurrentOptions.current = options;\n\t}, Object.values( options ) );\n\tconst constrainedTabbingRef = useConstrainedTabbing();\n\tconst focusOnMountRef = useFocusOnMount( options.focusOnMount );\n\tconst focusReturnRef = useFocusReturn();\n\tconst focusOutsideProps = useFocusOutside( ( event ) => {\n\t\t// This unstable prop is here only to manage backward compatibility\n\t\t// for the Popover component otherwise, the onClose should be enough.\n\t\tif ( currentOptions.current?.__unstableOnClose ) {\n\t\t\tcurrentOptions.current.__unstableOnClose( 'focus-outside', event );\n\t\t} else if ( currentOptions.current?.onClose ) {\n\t\t\tcurrentOptions.current.onClose();\n\t\t}\n\t} );\n\tconst closeOnEscapeRef = useCallback( ( node: HTMLElement ) => {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', ( event: KeyboardEvent ) => {\n\t\t\t// Close on escape.\n\t\t\tif (\n\t\t\t\tevent.keyCode === ESCAPE &&\n\t\t\t\t! event.defaultPrevented &&\n\t\t\t\tcurrentOptions.current?.onClose\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcurrentOptions.current.onClose();\n\t\t\t}\n\t\t} );\n\t}, [] );\n\n\treturn [\n\t\tuseMergeRefs( [\n\t\t\toptions.focusOnMount !== false ? constrainedTabbingRef : null,\n\t\t\toptions.focusOnMount !== false ? focusReturnRef : null,\n\t\t\toptions.focusOnMount !== false ? focusOnMountRef : null,\n\t\t\tcloseOnEscapeRef,\n\t\t] ),\n\t\t{\n\t\t\t...focusOutsideProps,\n\t\t\ttabIndex: -1,\n\t\t},\n\t];\n}\n\nexport default useDialog;\n"]}
1
+ {"version":3,"names":["_element","require","_keycodes","_useConstrainedTabbing","_interopRequireDefault","_useFocusOnMount","_useFocusReturn","_useFocusOutside","_useMergeRefs","useDialog","options","currentOptions","useRef","useEffect","current","Object","values","constrainedTabbingRef","useConstrainedTabbing","focusOnMountRef","useFocusOnMount","focusOnMount","focusReturnRef","useFocusReturn","focusOutsideProps","useFocusOutside","event","__unstableOnClose","onClose","closeOnEscapeRef","useCallback","node","addEventListener","keyCode","ESCAPE","defaultPrevented","preventDefault","useMergeRefs","tabIndex","_default","exports","default"],"sources":["@wordpress/compose/src/hooks/use-dialog/index.ts"],"sourcesContent":["/**\n * External dependencies\n */\nimport type { RefCallback, SyntheticEvent } from 'react';\n\n/**\n * WordPress dependencies\n */\nimport { useRef, useEffect, useCallback } from '@wordpress/element';\nimport { ESCAPE } from '@wordpress/keycodes';\n\n/**\n * Internal dependencies\n */\nimport useConstrainedTabbing from '../use-constrained-tabbing';\nimport useFocusOnMount from '../use-focus-on-mount';\nimport useFocusReturn from '../use-focus-return';\nimport useFocusOutside from '../use-focus-outside';\nimport useMergeRefs from '../use-merge-refs';\n\ntype DialogOptions = {\n\tfocusOnMount?: Parameters< typeof useFocusOnMount >[ 0 ];\n\tonClose?: () => void;\n\t/**\n\t * Use the `onClose` prop instead.\n\t *\n\t * @deprecated\n\t */\n\t__unstableOnClose?: (\n\t\ttype: string | undefined,\n\t\tevent: SyntheticEvent\n\t) => void;\n};\n\ntype useDialogReturn = [\n\tRefCallback< HTMLElement >,\n\tReturnType< typeof useFocusOutside > & Pick< HTMLElement, 'tabIndex' >\n];\n\n/**\n * Returns a ref and props to apply to a dialog wrapper to enable the following behaviors:\n * - constrained tabbing.\n * - focus on mount.\n * - return focus on unmount.\n * - focus outside.\n *\n * @param options Dialog Options.\n */\nfunction useDialog( options: DialogOptions ): useDialogReturn {\n\tconst currentOptions = useRef< DialogOptions | undefined >();\n\tuseEffect( () => {\n\t\tcurrentOptions.current = options;\n\t}, Object.values( options ) );\n\tconst constrainedTabbingRef = useConstrainedTabbing();\n\tconst focusOnMountRef = useFocusOnMount( options.focusOnMount );\n\tconst focusReturnRef = useFocusReturn();\n\tconst focusOutsideProps = useFocusOutside( ( event ) => {\n\t\t// This unstable prop is here only to manage backward compatibility\n\t\t// for the Popover component otherwise, the onClose should be enough.\n\t\tif ( currentOptions.current?.__unstableOnClose ) {\n\t\t\tcurrentOptions.current.__unstableOnClose( 'focus-outside', event );\n\t\t} else if ( currentOptions.current?.onClose ) {\n\t\t\tcurrentOptions.current.onClose();\n\t\t}\n\t} );\n\tconst closeOnEscapeRef = useCallback( ( node: HTMLElement ) => {\n\t\tif ( ! node ) {\n\t\t\treturn;\n\t\t}\n\n\t\tnode.addEventListener( 'keydown', ( event: KeyboardEvent ) => {\n\t\t\t// Close on escape.\n\t\t\tif (\n\t\t\t\tevent.keyCode === ESCAPE &&\n\t\t\t\t! event.defaultPrevented &&\n\t\t\t\tcurrentOptions.current?.onClose\n\t\t\t) {\n\t\t\t\tevent.preventDefault();\n\t\t\t\tcurrentOptions.current.onClose();\n\t\t\t}\n\t\t} );\n\t}, [] );\n\n\treturn [\n\t\tuseMergeRefs( [\n\t\t\toptions.focusOnMount !== false ? constrainedTabbingRef : null,\n\t\t\toptions.focusOnMount !== false ? focusReturnRef : null,\n\t\t\toptions.focusOnMount !== false ? focusOnMountRef : null,\n\t\t\tcloseOnEscapeRef,\n\t\t] ),\n\t\t{\n\t\t\t...focusOutsideProps,\n\t\t\ttabIndex: -1,\n\t\t},\n\t];\n}\n\nexport default useDialog;\n"],"mappings":";;;;;;;AAQA,IAAAA,QAAA,GAAAC,OAAA;AACA,IAAAC,SAAA,GAAAD,OAAA;AAKA,IAAAE,sBAAA,GAAAC,sBAAA,CAAAH,OAAA;AACA,IAAAI,gBAAA,GAAAD,sBAAA,CAAAH,OAAA;AACA,IAAAK,eAAA,GAAAF,sBAAA,CAAAH,OAAA;AACA,IAAAM,gBAAA,GAAAH,sBAAA,CAAAH,OAAA;AACA,IAAAO,aAAA,GAAAJ,sBAAA,CAAAH,OAAA;AAlBA;AACA;AACA;;AAGA;AACA;AACA;;AAIA;AACA;AACA;;AA0BA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASQ,SAASA,CAAEC,OAAsB,EAAoB;EAC7D,MAAMC,cAAc,GAAG,IAAAC,eAAM,EAA8B,CAAC;EAC5D,IAAAC,kBAAS,EAAE,MAAM;IAChBF,cAAc,CAACG,OAAO,GAAGJ,OAAO;EACjC,CAAC,EAAEK,MAAM,CAACC,MAAM,CAAEN,OAAQ,CAAE,CAAC;EAC7B,MAAMO,qBAAqB,GAAG,IAAAC,8BAAqB,EAAC,CAAC;EACrD,MAAMC,eAAe,GAAG,IAAAC,wBAAe,EAAEV,OAAO,CAACW,YAAa,CAAC;EAC/D,MAAMC,cAAc,GAAG,IAAAC,uBAAc,EAAC,CAAC;EACvC,MAAMC,iBAAiB,GAAG,IAAAC,wBAAe,EAAIC,KAAK,IAAM;IACvD;IACA;IACA,IAAKf,cAAc,CAACG,OAAO,EAAEa,iBAAiB,EAAG;MAChDhB,cAAc,CAACG,OAAO,CAACa,iBAAiB,CAAE,eAAe,EAAED,KAAM,CAAC;IACnE,CAAC,MAAM,IAAKf,cAAc,CAACG,OAAO,EAAEc,OAAO,EAAG;MAC7CjB,cAAc,CAACG,OAAO,CAACc,OAAO,CAAC,CAAC;IACjC;EACD,CAAE,CAAC;EACH,MAAMC,gBAAgB,GAAG,IAAAC,oBAAW,EAAIC,IAAiB,IAAM;IAC9D,IAAK,CAAEA,IAAI,EAAG;MACb;IACD;IAEAA,IAAI,CAACC,gBAAgB,CAAE,SAAS,EAAIN,KAAoB,IAAM;MAC7D;MACA,IACCA,KAAK,CAACO,OAAO,KAAKC,gBAAM,IACxB,CAAER,KAAK,CAACS,gBAAgB,IACxBxB,cAAc,CAACG,OAAO,EAAEc,OAAO,EAC9B;QACDF,KAAK,CAACU,cAAc,CAAC,CAAC;QACtBzB,cAAc,CAACG,OAAO,CAACc,OAAO,CAAC,CAAC;MACjC;IACD,CAAE,CAAC;EACJ,CAAC,EAAE,EAAG,CAAC;EAEP,OAAO,CACN,IAAAS,qBAAY,EAAE,CACb3B,OAAO,CAACW,YAAY,KAAK,KAAK,GAAGJ,qBAAqB,GAAG,IAAI,EAC7DP,OAAO,CAACW,YAAY,KAAK,KAAK,GAAGC,cAAc,GAAG,IAAI,EACtDZ,OAAO,CAACW,YAAY,KAAK,KAAK,GAAGF,eAAe,GAAG,IAAI,EACvDU,gBAAgB,CACf,CAAC,EACH;IACC,GAAGL,iBAAiB;IACpBc,QAAQ,EAAE,CAAC;EACZ,CAAC,CACD;AACF;AAAC,IAAAC,QAAA,GAEc9B,SAAS;AAAA+B,OAAA,CAAAC,OAAA,GAAAF,QAAA"}
@@ -1,16 +1,12 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
4
  Object.defineProperty(exports, "__esModule", {
6
5
  value: true
7
6
  });
8
7
  exports.default = useDisabled;
9
-
10
8
  var _debounce = require("../../utils/debounce");
11
-
12
9
  var _useRefEffect = _interopRequireDefault(require("../use-ref-effect"));
13
-
14
10
  /**
15
11
  * Internal dependencies
16
12
  */
@@ -48,23 +44,18 @@ function useDisabled({
48
44
  if (isDisabledProp) {
49
45
  return;
50
46
  }
51
-
52
47
  const defaultView = node?.ownerDocument?.defaultView;
53
-
54
48
  if (!defaultView) {
55
49
  return;
56
50
  }
57
- /** A variable keeping track of the previous updates in order to restore them. */
58
-
59
51
 
52
+ /** A variable keeping track of the previous updates in order to restore them. */
60
53
  const updates = [];
61
-
62
54
  const disable = () => {
63
55
  node.childNodes.forEach(child => {
64
56
  if (!(child instanceof defaultView.HTMLElement)) {
65
57
  return;
66
58
  }
67
-
68
59
  if (!child.getAttribute('inert')) {
69
60
  child.setAttribute('inert', 'true');
70
61
  updates.push(() => {
@@ -72,16 +63,16 @@ function useDisabled({
72
63
  });
73
64
  }
74
65
  });
75
- }; // Debounce re-disable since disabling process itself will incur
76
- // additional mutations which should be ignored.
77
-
66
+ };
78
67
 
68
+ // Debounce re-disable since disabling process itself will incur
69
+ // additional mutations which should be ignored.
79
70
  const debouncedDisable = (0, _debounce.debounce)(disable, 0, {
80
71
  leading: true
81
72
  });
82
73
  disable();
83
- /** @type {MutationObserver | undefined} */
84
74
 
75
+ /** @type {MutationObserver | undefined} */
85
76
  const observer = new window.MutationObserver(debouncedDisable);
86
77
  observer.observe(node, {
87
78
  childList: true
@@ -90,7 +81,6 @@ function useDisabled({
90
81
  if (observer) {
91
82
  observer.disconnect();
92
83
  }
93
-
94
84
  debouncedDisable.cancel();
95
85
  updates.forEach(update => update());
96
86
  };