@wordpress/compose 7.31.1-next.f56bd8138.0 → 7.32.1-next.47f435fc9.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (236) hide show
  1. package/CHANGELOG.md +2 -0
  2. package/build/higher-order/compose.js +25 -20
  3. package/build/higher-order/compose.js.map +7 -1
  4. package/build/higher-order/if-condition/index.js +35 -41
  5. package/build/higher-order/if-condition/index.js.map +7 -1
  6. package/build/higher-order/pipe.js +32 -66
  7. package/build/higher-order/pipe.js.map +7 -1
  8. package/build/higher-order/pure/index.js +44 -37
  9. package/build/higher-order/pure/index.js.map +7 -1
  10. package/build/higher-order/with-global-events/index.js +64 -73
  11. package/build/higher-order/with-global-events/index.js.map +7 -1
  12. package/build/higher-order/with-global-events/listener.js +34 -21
  13. package/build/higher-order/with-global-events/listener.js.map +7 -1
  14. package/build/higher-order/with-instance-id/index.js +45 -27
  15. package/build/higher-order/with-instance-id/index.js.map +7 -1
  16. package/build/higher-order/with-safe-timeout/index.js +70 -66
  17. package/build/higher-order/with-safe-timeout/index.js.map +7 -1
  18. package/build/higher-order/with-state/index.js +52 -40
  19. package/build/higher-order/with-state/index.js.map +7 -1
  20. package/build/hooks/use-async-list/index.js +38 -42
  21. package/build/hooks/use-async-list/index.js.map +7 -1
  22. package/build/hooks/use-constrained-tabbing/index.js +54 -75
  23. package/build/hooks/use-constrained-tabbing/index.js.map +7 -1
  24. package/build/hooks/use-copy-on-click/index.js +46 -56
  25. package/build/hooks/use-copy-on-click/index.js.map +7 -1
  26. package/build/hooks/use-copy-to-clipboard/index.js +41 -51
  27. package/build/hooks/use-copy-to-clipboard/index.js.map +7 -1
  28. package/build/hooks/use-debounce/index.js +30 -37
  29. package/build/hooks/use-debounce/index.js.map +7 -1
  30. package/build/hooks/use-debounced-input/index.js +39 -27
  31. package/build/hooks/use-debounced-input/index.js.map +7 -1
  32. package/build/hooks/use-dialog/index.js +63 -55
  33. package/build/hooks/use-dialog/index.js.map +7 -1
  34. package/build/hooks/use-disabled/index.js +74 -82
  35. package/build/hooks/use-disabled/index.js.map +7 -1
  36. package/build/hooks/use-dragging/index.js +51 -48
  37. package/build/hooks/use-dragging/index.js.map +7 -1
  38. package/build/hooks/use-drop-zone/index.js +133 -168
  39. package/build/hooks/use-drop-zone/index.js.map +7 -1
  40. package/build/hooks/use-event/index.js +33 -45
  41. package/build/hooks/use-event/index.js.map +7 -1
  42. package/build/hooks/use-fixed-window-list/index.js +109 -97
  43. package/build/hooks/use-fixed-window-list/index.js.map +7 -1
  44. package/build/hooks/use-focus-on-mount/index.js +44 -57
  45. package/build/hooks/use-focus-on-mount/index.js.map +7 -1
  46. package/build/hooks/use-focus-outside/index.js +44 -102
  47. package/build/hooks/use-focus-outside/index.js.map +7 -1
  48. package/build/hooks/use-focus-return/index.js +35 -56
  49. package/build/hooks/use-focus-return/index.js.map +7 -1
  50. package/build/hooks/use-focusable-iframe/index.js +38 -35
  51. package/build/hooks/use-focusable-iframe/index.js.map +7 -1
  52. package/build/hooks/use-instance-id/index.js +26 -42
  53. package/build/hooks/use-instance-id/index.js.map +7 -1
  54. package/build/hooks/use-isomorphic-layout-effect/index.js +25 -17
  55. package/build/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  56. package/build/hooks/use-keyboard-shortcut/index.js +72 -69
  57. package/build/hooks/use-keyboard-shortcut/index.js.map +7 -1
  58. package/build/hooks/use-media-query/index.js +39 -35
  59. package/build/hooks/use-media-query/index.js.map +7 -1
  60. package/build/hooks/use-merge-refs/index.js +34 -102
  61. package/build/hooks/use-merge-refs/index.js.map +7 -1
  62. package/build/hooks/use-observable-value/index.js +31 -28
  63. package/build/hooks/use-observable-value/index.js.map +7 -1
  64. package/build/hooks/use-preferred-color-scheme/index.android.js +31 -23
  65. package/build/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  66. package/build/hooks/use-preferred-color-scheme/index.ios.js +25 -17
  67. package/build/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  68. package/build/hooks/use-previous/index.js +26 -25
  69. package/build/hooks/use-previous/index.js.map +7 -1
  70. package/build/hooks/use-reduced-motion/index.js +35 -18
  71. package/build/hooks/use-reduced-motion/index.js.map +7 -1
  72. package/build/hooks/use-ref-effect/index.js +25 -35
  73. package/build/hooks/use-ref-effect/index.js.map +7 -1
  74. package/build/hooks/use-resize-observer/index.js +35 -67
  75. package/build/hooks/use-resize-observer/index.js.map +7 -1
  76. package/build/hooks/use-resize-observer/legacy/index.js +47 -103
  77. package/build/hooks/use-resize-observer/legacy/index.js.map +7 -1
  78. package/build/hooks/use-resize-observer/use-resize-observer.js +44 -36
  79. package/build/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  80. package/build/hooks/use-state-with-history/index.js +68 -63
  81. package/build/hooks/use-state-with-history/index.js.map +7 -1
  82. package/build/hooks/use-throttle/index.js +30 -37
  83. package/build/hooks/use-throttle/index.js.map +7 -1
  84. package/build/hooks/use-viewport-match/index.js +51 -70
  85. package/build/hooks/use-viewport-match/index.js.map +7 -1
  86. package/build/hooks/use-warn-on-change/index.js +50 -40
  87. package/build/hooks/use-warn-on-change/index.js.map +7 -1
  88. package/build/index.js +156 -358
  89. package/build/index.js.map +7 -1
  90. package/build/utils/create-higher-order-component/index.js +30 -34
  91. package/build/utils/create-higher-order-component/index.js.map +7 -1
  92. package/build/utils/debounce/index.js +38 -99
  93. package/build/utils/debounce/index.js.map +7 -1
  94. package/build/utils/observable-map/index.js +29 -19
  95. package/build/utils/observable-map/index.js.map +7 -1
  96. package/build/utils/throttle/index.js +30 -81
  97. package/build/utils/throttle/index.js.map +7 -1
  98. package/build-module/higher-order/compose.js +6 -15
  99. package/build-module/higher-order/compose.js.map +7 -1
  100. package/build-module/higher-order/if-condition/index.js +16 -37
  101. package/build-module/higher-order/if-condition/index.js.map +7 -1
  102. package/build-module/higher-order/pipe.js +10 -62
  103. package/build-module/higher-order/pipe.js.map +7 -1
  104. package/build-module/higher-order/pure/index.js +12 -29
  105. package/build-module/higher-order/pure/index.js.map +7 -1
  106. package/build-module/higher-order/with-global-events/index.js +34 -67
  107. package/build-module/higher-order/with-global-events/index.js.map +7 -1
  108. package/build-module/higher-order/with-global-events/listener.js +16 -17
  109. package/build-module/higher-order/with-global-events/listener.js.map +7 -1
  110. package/build-module/higher-order/with-instance-id/index.js +17 -22
  111. package/build-module/higher-order/with-instance-id/index.js.map +7 -1
  112. package/build-module/higher-order/with-safe-timeout/index.js +52 -62
  113. package/build-module/higher-order/with-safe-timeout/index.js.map +7 -1
  114. package/build-module/higher-order/with-state/index.js +23 -35
  115. package/build-module/higher-order/with-state/index.js.map +7 -1
  116. package/build-module/hooks/use-async-list/index.js +16 -33
  117. package/build-module/hooks/use-async-list/index.js.map +7 -1
  118. package/build-module/hooks/use-constrained-tabbing/index.js +26 -70
  119. package/build-module/hooks/use-constrained-tabbing/index.js.map +7 -1
  120. package/build-module/hooks/use-copy-on-click/index.js +14 -47
  121. package/build-module/hooks/use-copy-on-click/index.js.map +7 -1
  122. package/build-module/hooks/use-copy-to-clipboard/index.js +11 -44
  123. package/build-module/hooks/use-copy-to-clipboard/index.js.map +7 -1
  124. package/build-module/hooks/use-debounce/index.js +12 -33
  125. package/build-module/hooks/use-debounce/index.js.map +7 -1
  126. package/build-module/hooks/use-debounced-input/index.js +7 -18
  127. package/build-module/hooks/use-debounced-input/index.js.map +7 -1
  128. package/build-module/hooks/use-dialog/index.js +29 -43
  129. package/build-module/hooks/use-dialog/index.js.map +7 -1
  130. package/build-module/hooks/use-disabled/index.js +47 -78
  131. package/build-module/hooks/use-disabled/index.js.map +7 -1
  132. package/build-module/hooks/use-dragging/index.js +19 -39
  133. package/build-module/hooks/use-dragging/index.js.map +7 -1
  134. package/build-module/hooks/use-drop-zone/index.js +100 -158
  135. package/build-module/hooks/use-drop-zone/index.js.map +7 -1
  136. package/build-module/hooks/use-event/index.js +13 -39
  137. package/build-module/hooks/use-event/index.js.map +7 -1
  138. package/build-module/hooks/use-fixed-window-list/index.js +86 -87
  139. package/build-module/hooks/use-fixed-window-list/index.js.map +7 -1
  140. package/build-module/hooks/use-focus-on-mount/index.js +12 -48
  141. package/build-module/hooks/use-focus-on-mount/index.js.map +7 -1
  142. package/build-module/hooks/use-focus-outside/index.js +21 -93
  143. package/build-module/hooks/use-focus-outside/index.js.map +7 -1
  144. package/build-module/hooks/use-focus-return/index.js +13 -48
  145. package/build-module/hooks/use-focus-return/index.js.map +7 -1
  146. package/build-module/hooks/use-focusable-iframe/index.js +11 -31
  147. package/build-module/hooks/use-focusable-iframe/index.js.map +7 -1
  148. package/build-module/hooks/use-instance-id/index.js +7 -36
  149. package/build-module/hooks/use-instance-id/index.js.map +7 -1
  150. package/build-module/hooks/use-isomorphic-layout-effect/index.js +7 -13
  151. package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
  152. package/build-module/hooks/use-keyboard-shortcut/index.js +40 -60
  153. package/build-module/hooks/use-keyboard-shortcut/index.js.map +7 -1
  154. package/build-module/hooks/use-media-query/index.js +21 -30
  155. package/build-module/hooks/use-media-query/index.js.map +7 -1
  156. package/build-module/hooks/use-merge-refs/index.js +10 -92
  157. package/build-module/hooks/use-merge-refs/index.js.map +7 -1
  158. package/build-module/hooks/use-observable-value/index.js +13 -24
  159. package/build-module/hooks/use-observable-value/index.js.map +7 -1
  160. package/build-module/hooks/use-preferred-color-scheme/index.android.js +15 -18
  161. package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
  162. package/build-module/hooks/use-preferred-color-scheme/index.ios.js +6 -12
  163. package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
  164. package/build-module/hooks/use-previous/index.js +7 -20
  165. package/build-module/hooks/use-previous/index.js.map +7 -1
  166. package/build-module/hooks/use-reduced-motion/index.js +7 -13
  167. package/build-module/hooks/use-reduced-motion/index.js.map +7 -1
  168. package/build-module/hooks/use-ref-effect/index.js +7 -31
  169. package/build-module/hooks/use-ref-effect/index.js.map +7 -1
  170. package/build-module/hooks/use-resize-observer/index.js +7 -61
  171. package/build-module/hooks/use-resize-observer/index.js.map +7 -1
  172. package/build-module/hooks/use-resize-observer/legacy/index.js +28 -96
  173. package/build-module/hooks/use-resize-observer/legacy/index.js.map +7 -1
  174. package/build-module/hooks/use-resize-observer/use-resize-observer.js +10 -28
  175. package/build-module/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
  176. package/build-module/hooks/use-state-with-history/index.js +47 -55
  177. package/build-module/hooks/use-state-with-history/index.js.map +7 -1
  178. package/build-module/hooks/use-throttle/index.js +12 -33
  179. package/build-module/hooks/use-throttle/index.js.map +7 -1
  180. package/build-module/hooks/use-viewport-match/index.js +22 -64
  181. package/build-module/hooks/use-viewport-match/index.js.map +7 -1
  182. package/build-module/hooks/use-warn-on-change/index.js +21 -34
  183. package/build-module/hooks/use-warn-on-change/index.js.map +7 -1
  184. package/build-module/index.js +83 -53
  185. package/build-module/index.js.map +7 -1
  186. package/build-module/utils/create-higher-order-component/index.js +9 -30
  187. package/build-module/utils/create-higher-order-component/index.js.map +7 -1
  188. package/build-module/utils/debounce/index.js +17 -95
  189. package/build-module/utils/debounce/index.js.map +7 -1
  190. package/build-module/utils/observable-map/index.js +8 -16
  191. package/build-module/utils/observable-map/index.js.map +7 -1
  192. package/build-module/utils/throttle/index.js +8 -75
  193. package/build-module/utils/throttle/index.js.map +7 -1
  194. package/package.json +17 -10
  195. package/src/hooks/use-debounce/index.js +1 -1
  196. package/tsconfig.tsbuildinfo +1 -1
  197. package/build/higher-order/with-network-connectivity/index.native.js +0 -27
  198. package/build/higher-order/with-network-connectivity/index.native.js.map +0 -1
  199. package/build/higher-order/with-preferred-color-scheme/index.native.js +0 -37
  200. package/build/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  201. package/build/hooks/use-constrained-tabbing/index.native.js +0 -20
  202. package/build/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  203. package/build/hooks/use-focus-outside/index.native.js +0 -175
  204. package/build/hooks/use-focus-outside/index.native.js.map +0 -1
  205. package/build/hooks/use-keyboard-shortcut/index.native.js +0 -9
  206. package/build/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  207. package/build/hooks/use-network-connectivity/index.native.js +0 -58
  208. package/build/hooks/use-network-connectivity/index.native.js.map +0 -1
  209. package/build/hooks/use-preferred-color-scheme-style/index.native.js +0 -42
  210. package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  211. package/build/hooks/use-resize-observer/index.native.js +0 -14
  212. package/build/hooks/use-resize-observer/index.native.js.map +0 -1
  213. package/build/hooks/use-resize-observer/legacy/index.native.js +0 -62
  214. package/build/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  215. package/build/index.native.js +0 -297
  216. package/build/index.native.js.map +0 -1
  217. package/build-module/higher-order/with-network-connectivity/index.native.js +0 -19
  218. package/build-module/higher-order/with-network-connectivity/index.native.js.map +0 -1
  219. package/build-module/higher-order/with-preferred-color-scheme/index.native.js +0 -29
  220. package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
  221. package/build-module/hooks/use-constrained-tabbing/index.native.js +0 -13
  222. package/build-module/hooks/use-constrained-tabbing/index.native.js.map +0 -1
  223. package/build-module/hooks/use-focus-outside/index.native.js +0 -169
  224. package/build-module/hooks/use-focus-outside/index.native.js.map +0 -1
  225. package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -3
  226. package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
  227. package/build-module/hooks/use-network-connectivity/index.native.js +0 -52
  228. package/build-module/hooks/use-network-connectivity/index.native.js.map +0 -1
  229. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +0 -35
  230. package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
  231. package/build-module/hooks/use-resize-observer/index.native.js +0 -2
  232. package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
  233. package/build-module/hooks/use-resize-observer/legacy/index.native.js +0 -56
  234. package/build-module/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
  235. package/build-module/index.native.js +0 -45
  236. package/build-module/index.native.js.map +0 -1
@@ -1,44 +1,57 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var listener_exports = {};
20
+ __export(listener_exports, {
21
+ default: () => listener_default
5
22
  });
6
- exports.default = void 0;
7
- /**
8
- * Class responsible for orchestrating event handling on the global window,
9
- * binding a single event to be shared across all handling instances, and
10
- * removing the handler when no instances are listening for the event.
11
- */
23
+ module.exports = __toCommonJS(listener_exports);
12
24
  class Listener {
13
25
  constructor() {
14
- /** @type {any} */
15
26
  this.listeners = {};
16
27
  this.handleEvent = this.handleEvent.bind(this);
17
28
  }
18
- add(/** @type {any} */eventType, /** @type {any} */instance) {
29
+ add(eventType, instance) {
19
30
  if (!this.listeners[eventType]) {
20
- // Adding first listener for this type, so bind event.
21
31
  window.addEventListener(eventType, this.handleEvent);
22
32
  this.listeners[eventType] = [];
23
33
  }
24
34
  this.listeners[eventType].push(instance);
25
35
  }
26
- remove(/** @type {any} */eventType, /** @type {any} */instance) {
36
+ remove(eventType, instance) {
27
37
  if (!this.listeners[eventType]) {
28
38
  return;
29
39
  }
30
- this.listeners[eventType] = this.listeners[eventType].filter((/** @type {any} */listener) => listener !== instance);
40
+ this.listeners[eventType] = this.listeners[eventType].filter(
41
+ (listener) => listener !== instance
42
+ );
31
43
  if (!this.listeners[eventType].length) {
32
- // Removing last listener for this type, so unbind event.
33
44
  window.removeEventListener(eventType, this.handleEvent);
34
45
  delete this.listeners[eventType];
35
46
  }
36
47
  }
37
- handleEvent(/** @type {any} */event) {
38
- this.listeners[event.type]?.forEach((/** @type {any} */instance) => {
39
- instance.handleEvent(event);
40
- });
48
+ handleEvent(event) {
49
+ this.listeners[event.type]?.forEach(
50
+ (instance) => {
51
+ instance.handleEvent(event);
52
+ }
53
+ );
41
54
  }
42
55
  }
43
- var _default = exports.default = Listener;
44
- //# sourceMappingURL=listener.js.map
56
+ var listener_default = Listener;
57
+ //# sourceMappingURL=listener.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["Listener","constructor","listeners","handleEvent","bind","add","eventType","instance","window","addEventListener","push","remove","filter","listener","length","removeEventListener","event","type","forEach","_default","exports","default"],"sources":["@wordpress/compose/src/higher-order/with-global-events/listener.js"],"sourcesContent":["/**\n * Class responsible for orchestrating event handling on the global window,\n * binding a single event to be shared across all handling instances, and\n * removing the handler when no instances are listening for the event.\n */\nclass Listener {\n\tconstructor() {\n\t\t/** @type {any} */\n\t\tthis.listeners = {};\n\n\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t}\n\n\tadd( /** @type {any} */ eventType, /** @type {any} */ instance ) {\n\t\tif ( ! this.listeners[ eventType ] ) {\n\t\t\t// Adding first listener for this type, so bind event.\n\t\t\twindow.addEventListener( eventType, this.handleEvent );\n\t\t\tthis.listeners[ eventType ] = [];\n\t\t}\n\n\t\tthis.listeners[ eventType ].push( instance );\n\t}\n\n\tremove( /** @type {any} */ eventType, /** @type {any} */ instance ) {\n\t\tif ( ! this.listeners[ eventType ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.listeners[ eventType ] = this.listeners[ eventType ].filter(\n\t\t\t( /** @type {any} */ listener ) => listener !== instance\n\t\t);\n\n\t\tif ( ! this.listeners[ eventType ].length ) {\n\t\t\t// Removing last listener for this type, so unbind event.\n\t\t\twindow.removeEventListener( eventType, this.handleEvent );\n\t\t\tdelete this.listeners[ eventType ];\n\t\t}\n\t}\n\n\thandleEvent( /** @type {any} */ event ) {\n\t\tthis.listeners[ event.type ]?.forEach(\n\t\t\t( /** @type {any} */ instance ) => {\n\t\t\t\tinstance.handleEvent( event );\n\t\t\t}\n\t\t);\n\t}\n}\n\nexport default Listener;\n"],"mappings":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAQ,CAAC;EACdC,WAAWA,CAAA,EAAG;IACb;IACA,IAAI,CAACC,SAAS,GAAG,CAAC,CAAC;IAEnB,IAAI,CAACC,WAAW,GAAG,IAAI,CAACA,WAAW,CAACC,IAAI,CAAE,IAAK,CAAC;EACjD;EAEAC,GAAGA,CAAE,kBAAmBC,SAAS,EAAE,kBAAmBC,QAAQ,EAAG;IAChE,IAAK,CAAE,IAAI,CAACL,SAAS,CAAEI,SAAS,CAAE,EAAG;MACpC;MACAE,MAAM,CAACC,gBAAgB,CAAEH,SAAS,EAAE,IAAI,CAACH,WAAY,CAAC;MACtD,IAAI,CAACD,SAAS,CAAEI,SAAS,CAAE,GAAG,EAAE;IACjC;IAEA,IAAI,CAACJ,SAAS,CAAEI,SAAS,CAAE,CAACI,IAAI,CAAEH,QAAS,CAAC;EAC7C;EAEAI,MAAMA,CAAE,kBAAmBL,SAAS,EAAE,kBAAmBC,QAAQ,EAAG;IACnE,IAAK,CAAE,IAAI,CAACL,SAAS,CAAEI,SAAS,CAAE,EAAG;MACpC;IACD;IAEA,IAAI,CAACJ,SAAS,CAAEI,SAAS,CAAE,GAAG,IAAI,CAACJ,SAAS,CAAEI,SAAS,CAAE,CAACM,MAAM,CAC/D,CAAE,kBAAmBC,QAAQ,KAAMA,QAAQ,KAAKN,QACjD,CAAC;IAED,IAAK,CAAE,IAAI,CAACL,SAAS,CAAEI,SAAS,CAAE,CAACQ,MAAM,EAAG;MAC3C;MACAN,MAAM,CAACO,mBAAmB,CAAET,SAAS,EAAE,IAAI,CAACH,WAAY,CAAC;MACzD,OAAO,IAAI,CAACD,SAAS,CAAEI,SAAS,CAAE;IACnC;EACD;EAEAH,WAAWA,CAAE,kBAAmBa,KAAK,EAAG;IACvC,IAAI,CAACd,SAAS,CAAEc,KAAK,CAACC,IAAI,CAAE,EAAEC,OAAO,CACpC,CAAE,kBAAmBX,QAAQ,KAAM;MAClCA,QAAQ,CAACJ,WAAW,CAAEa,KAAM,CAAC;IAC9B,CACD,CAAC;EACF;AACD;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEcrB,QAAQ","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/higher-order/with-global-events/listener.js"],
4
+ "sourcesContent": ["/**\n * Class responsible for orchestrating event handling on the global window,\n * binding a single event to be shared across all handling instances, and\n * removing the handler when no instances are listening for the event.\n */\nclass Listener {\n\tconstructor() {\n\t\t/** @type {any} */\n\t\tthis.listeners = {};\n\n\t\tthis.handleEvent = this.handleEvent.bind( this );\n\t}\n\n\tadd( /** @type {any} */ eventType, /** @type {any} */ instance ) {\n\t\tif ( ! this.listeners[ eventType ] ) {\n\t\t\t// Adding first listener for this type, so bind event.\n\t\t\twindow.addEventListener( eventType, this.handleEvent );\n\t\t\tthis.listeners[ eventType ] = [];\n\t\t}\n\n\t\tthis.listeners[ eventType ].push( instance );\n\t}\n\n\tremove( /** @type {any} */ eventType, /** @type {any} */ instance ) {\n\t\tif ( ! this.listeners[ eventType ] ) {\n\t\t\treturn;\n\t\t}\n\n\t\tthis.listeners[ eventType ] = this.listeners[ eventType ].filter(\n\t\t\t( /** @type {any} */ listener ) => listener !== instance\n\t\t);\n\n\t\tif ( ! this.listeners[ eventType ].length ) {\n\t\t\t// Removing last listener for this type, so unbind event.\n\t\t\twindow.removeEventListener( eventType, this.handleEvent );\n\t\t\tdelete this.listeners[ eventType ];\n\t\t}\n\t}\n\n\thandleEvent( /** @type {any} */ event ) {\n\t\tthis.listeners[ event.type ]?.forEach(\n\t\t\t( /** @type {any} */ instance ) => {\n\t\t\t\tinstance.handleEvent( event );\n\t\t\t}\n\t\t);\n\t}\n}\n\nexport default Listener;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAKA,MAAM,SAAS;AAAA,EACd,cAAc;AAEb,SAAK,YAAY,CAAC;AAElB,SAAK,cAAc,KAAK,YAAY,KAAM,IAAK;AAAA,EAChD;AAAA,EAEA,IAAwB,WAA8B,UAAW;AAChE,QAAK,CAAE,KAAK,UAAW,SAAU,GAAI;AAEpC,aAAO,iBAAkB,WAAW,KAAK,WAAY;AACrD,WAAK,UAAW,SAAU,IAAI,CAAC;AAAA,IAChC;AAEA,SAAK,UAAW,SAAU,EAAE,KAAM,QAAS;AAAA,EAC5C;AAAA,EAEA,OAA2B,WAA8B,UAAW;AACnE,QAAK,CAAE,KAAK,UAAW,SAAU,GAAI;AACpC;AAAA,IACD;AAEA,SAAK,UAAW,SAAU,IAAI,KAAK,UAAW,SAAU,EAAE;AAAA,MACzD,CAAqB,aAAc,aAAa;AAAA,IACjD;AAEA,QAAK,CAAE,KAAK,UAAW,SAAU,EAAE,QAAS;AAE3C,aAAO,oBAAqB,WAAW,KAAK,WAAY;AACxD,aAAO,KAAK,UAAW,SAAU;AAAA,IAClC;AAAA,EACD;AAAA,EAEA,YAAgC,OAAQ;AACvC,SAAK,UAAW,MAAM,IAAK,GAAG;AAAA,MAC7B,CAAqB,aAAc;AAClC,iBAAS,YAAa,KAAM;AAAA,MAC7B;AAAA,IACD;AAAA,EACD;AACD;AAEA,IAAO,mBAAQ;",
6
+ "names": []
7
+ }
@@ -1,29 +1,47 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var with_instance_id_exports = {};
30
+ __export(with_instance_id_exports, {
31
+ default: () => with_instance_id_default
6
32
  });
7
- exports.default = void 0;
8
- var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
9
- var _useInstanceId = _interopRequireDefault(require("../../hooks/use-instance-id"));
10
- var _jsxRuntime = require("react/jsx-runtime");
11
- /**
12
- * Internal dependencies
13
- */
14
-
15
- /**
16
- * A Higher Order Component used to provide a unique instance ID by component.
17
- */
18
- const withInstanceId = (0, _createHigherOrderComponent.createHigherOrderComponent)(WrappedComponent => {
19
- return props => {
20
- const instanceId = (0, _useInstanceId.default)(WrappedComponent);
21
- // @ts-ignore
22
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(WrappedComponent, {
23
- ...props,
24
- instanceId: instanceId
25
- });
26
- };
27
- }, 'instanceId');
28
- var _default = exports.default = withInstanceId;
29
- //# sourceMappingURL=index.js.map
33
+ module.exports = __toCommonJS(with_instance_id_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_create_higher_order_component = require("../../utils/create-higher-order-component");
36
+ var import_use_instance_id = __toESM(require("../../hooks/use-instance-id"));
37
+ const withInstanceId = (0, import_create_higher_order_component.createHigherOrderComponent)(
38
+ (WrappedComponent) => {
39
+ return (props) => {
40
+ const instanceId = (0, import_use_instance_id.default)(WrappedComponent);
41
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(WrappedComponent, { ...props, instanceId });
42
+ };
43
+ },
44
+ "instanceId"
45
+ );
46
+ var with_instance_id_default = withInstanceId;
47
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_createHigherOrderComponent","require","_useInstanceId","_interopRequireDefault","_jsxRuntime","withInstanceId","createHigherOrderComponent","WrappedComponent","props","instanceId","useInstanceId","jsx","_default","exports","default"],"sources":["@wordpress/compose/src/higher-order/with-instance-id/index.tsx"],"sourcesContent":["/**\n * Internal dependencies\n */\nimport type {\n\tWithInjectedProps,\n\tWithoutInjectedProps,\n} from '../../utils/create-higher-order-component';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport useInstanceId from '../../hooks/use-instance-id';\n\ntype InstanceIdProps = { instanceId: string | number };\n\n/**\n * A Higher Order Component used to provide a unique instance ID by component.\n */\nconst withInstanceId = createHigherOrderComponent(\n\t< C extends WithInjectedProps< C, InstanceIdProps > >(\n\t\tWrappedComponent: C\n\t) => {\n\t\treturn ( props: WithoutInjectedProps< C, InstanceIdProps > ) => {\n\t\t\tconst instanceId = useInstanceId( WrappedComponent );\n\t\t\t// @ts-ignore\n\t\t\treturn <WrappedComponent { ...props } instanceId={ instanceId } />;\n\t\t};\n\t},\n\t'instanceId'\n);\n\nexport default withInstanceId;\n"],"mappings":";;;;;;;AAOA,IAAAA,2BAAA,GAAAC,OAAA;AACA,IAAAC,cAAA,GAAAC,sBAAA,CAAAF,OAAA;AAAwD,IAAAG,WAAA,GAAAH,OAAA;AARxD;AACA;AACA;;AAUA;AACA;AACA;AACA,MAAMI,cAAc,GAAG,IAAAC,sDAA0B,EAE/CC,gBAAmB,IACf;EACJ,OAASC,KAAiD,IAAM;IAC/D,MAAMC,UAAU,GAAG,IAAAC,sBAAa,EAAEH,gBAAiB,CAAC;IACpD;IACA,oBAAO,IAAAH,WAAA,CAAAO,GAAA,EAACJ,gBAAgB;MAAA,GAAMC,KAAK;MAAGC,UAAU,EAAGA;IAAY,CAAE,CAAC;EACnE,CAAC;AACF,CAAC,EACD,YACD,CAAC;AAAC,IAAAG,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEaT,cAAc","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/higher-order/with-instance-id/index.tsx"],
4
+ "sourcesContent": ["/**\n * Internal dependencies\n */\nimport type {\n\tWithInjectedProps,\n\tWithoutInjectedProps,\n} from '../../utils/create-higher-order-component';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\nimport useInstanceId from '../../hooks/use-instance-id';\n\ntype InstanceIdProps = { instanceId: string | number };\n\n/**\n * A Higher Order Component used to provide a unique instance ID by component.\n */\nconst withInstanceId = createHigherOrderComponent(\n\t< C extends WithInjectedProps< C, InstanceIdProps > >(\n\t\tWrappedComponent: C\n\t) => {\n\t\treturn ( props: WithoutInjectedProps< C, InstanceIdProps > ) => {\n\t\t\tconst instanceId = useInstanceId( WrappedComponent );\n\t\t\t// @ts-ignore\n\t\t\treturn <WrappedComponent { ...props } instanceId={ instanceId } />;\n\t\t};\n\t},\n\t'instanceId'\n);\n\nexport default withInstanceId;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAsBU;AAfV,2CAA2C;AAC3C,6BAA0B;AAO1B,MAAM,qBAAiB;AAAA,EACtB,CACC,qBACI;AACJ,WAAO,CAAE,UAAuD;AAC/D,YAAM,iBAAa,uBAAAA,SAAe,gBAAiB;AAEnD,aAAO,4CAAC,oBAAmB,GAAG,OAAQ,YAA0B;AAAA,IACjE;AAAA,EACD;AAAA,EACA;AACD;AAEA,IAAO,2BAAQ;",
6
+ "names": ["useInstanceId"]
7
+ }
@@ -1,68 +1,72 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var with_safe_timeout_exports = {};
20
+ __export(with_safe_timeout_exports, {
21
+ default: () => with_safe_timeout_default
5
22
  });
6
- exports.default = void 0;
7
- var _element = require("@wordpress/element");
8
- var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
9
- var _jsxRuntime = require("react/jsx-runtime");
10
- /**
11
- * WordPress dependencies
12
- */
13
-
14
- /**
15
- * Internal dependencies
16
- */
17
-
18
- /**
19
- * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`
20
- * types here because those functions include functionality that is not handled
21
- * by this component, like the ability to pass extra arguments.
22
- *
23
- * In the case of this component, we only handle the simplest case where
24
- * `setTimeout` only accepts a function (not a string) and an optional delay.
25
- */
26
-
27
- /**
28
- * A higher-order component used to provide and manage delayed function calls
29
- * that ought to be bound to a component's lifecycle.
30
- */
31
- const withSafeTimeout = (0, _createHigherOrderComponent.createHigherOrderComponent)(OriginalComponent => {
32
- return class WrappedComponent extends _element.Component {
33
- constructor(props) {
34
- super(props);
35
- this.timeouts = [];
36
- this.setTimeout = this.setTimeout.bind(this);
37
- this.clearTimeout = this.clearTimeout.bind(this);
38
- }
39
- componentWillUnmount() {
40
- this.timeouts.forEach(clearTimeout);
41
- }
42
- setTimeout(fn, delay) {
43
- const id = setTimeout(() => {
44
- fn();
45
- this.clearTimeout(id);
46
- }, delay);
47
- this.timeouts.push(id);
48
- return id;
49
- }
50
- clearTimeout(id) {
51
- clearTimeout(id);
52
- this.timeouts = this.timeouts.filter(timeoutId => timeoutId !== id);
53
- }
54
- render() {
55
- return (
56
- /*#__PURE__*/
57
- // @ts-ignore
58
- (0, _jsxRuntime.jsx)(OriginalComponent, {
59
- ...this.props,
60
- setTimeout: this.setTimeout,
61
- clearTimeout: this.clearTimeout
62
- })
63
- );
64
- }
65
- };
66
- }, 'withSafeTimeout');
67
- var _default = exports.default = withSafeTimeout;
68
- //# sourceMappingURL=index.js.map
23
+ module.exports = __toCommonJS(with_safe_timeout_exports);
24
+ var import_jsx_runtime = (
25
+ // @ts-ignore
26
+ require("react/jsx-runtime")
27
+ );
28
+ var import_element = require("@wordpress/element");
29
+ var import_create_higher_order_component = require("../../utils/create-higher-order-component");
30
+ const withSafeTimeout = (0, import_create_higher_order_component.createHigherOrderComponent)(
31
+ (OriginalComponent) => {
32
+ return class WrappedComponent extends import_element.Component {
33
+ timeouts;
34
+ constructor(props) {
35
+ super(props);
36
+ this.timeouts = [];
37
+ this.setTimeout = this.setTimeout.bind(this);
38
+ this.clearTimeout = this.clearTimeout.bind(this);
39
+ }
40
+ componentWillUnmount() {
41
+ this.timeouts.forEach(clearTimeout);
42
+ }
43
+ setTimeout(fn, delay) {
44
+ const id = setTimeout(() => {
45
+ fn();
46
+ this.clearTimeout(id);
47
+ }, delay);
48
+ this.timeouts.push(id);
49
+ return id;
50
+ }
51
+ clearTimeout(id) {
52
+ clearTimeout(id);
53
+ this.timeouts = this.timeouts.filter(
54
+ (timeoutId) => timeoutId !== id
55
+ );
56
+ }
57
+ render() {
58
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
59
+ OriginalComponent,
60
+ {
61
+ ...this.props,
62
+ setTimeout: this.setTimeout,
63
+ clearTimeout: this.clearTimeout
64
+ }
65
+ );
66
+ }
67
+ };
68
+ },
69
+ "withSafeTimeout"
70
+ );
71
+ var with_safe_timeout_default = withSafeTimeout;
72
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_createHigherOrderComponent","_jsxRuntime","withSafeTimeout","createHigherOrderComponent","OriginalComponent","WrappedComponent","Component","constructor","props","timeouts","setTimeout","bind","clearTimeout","componentWillUnmount","forEach","fn","delay","id","push","filter","timeoutId","render","jsx","_default","exports","default"],"sources":["@wordpress/compose/src/higher-order/with-safe-timeout/index.tsx"],"sourcesContent":["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tWithInjectedProps,\n\tWithoutInjectedProps,\n} from '../../utils/create-higher-order-component';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`\n * types here because those functions include functionality that is not handled\n * by this component, like the ability to pass extra arguments.\n *\n * In the case of this component, we only handle the simplest case where\n * `setTimeout` only accepts a function (not a string) and an optional delay.\n */\ninterface TimeoutProps {\n\tsetTimeout: ( fn: () => void, delay: number ) => number;\n\tclearTimeout: ( id: number ) => void;\n}\n\n/**\n * A higher-order component used to provide and manage delayed function calls\n * that ought to be bound to a component's lifecycle.\n */\nconst withSafeTimeout = createHigherOrderComponent(\n\t< C extends WithInjectedProps< C, TimeoutProps > >(\n\t\tOriginalComponent: C\n\t) => {\n\t\ttype WrappedProps = WithoutInjectedProps< C, TimeoutProps >;\n\t\treturn class WrappedComponent extends Component< WrappedProps > {\n\t\t\ttimeouts: number[];\n\n\t\t\tconstructor( props: WrappedProps ) {\n\t\t\t\tsuper( props );\n\t\t\t\tthis.timeouts = [];\n\t\t\t\tthis.setTimeout = this.setTimeout.bind( this );\n\t\t\t\tthis.clearTimeout = this.clearTimeout.bind( this );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tthis.timeouts.forEach( clearTimeout );\n\t\t\t}\n\n\t\t\tsetTimeout( fn: () => void, delay: number ) {\n\t\t\t\tconst id = setTimeout( () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tthis.clearTimeout( id );\n\t\t\t\t}, delay );\n\t\t\t\tthis.timeouts.push( id );\n\t\t\t\treturn id;\n\t\t\t}\n\n\t\t\tclearTimeout( id: number ) {\n\t\t\t\tclearTimeout( id );\n\t\t\t\tthis.timeouts = this.timeouts.filter(\n\t\t\t\t\t( timeoutId ) => timeoutId !== id\n\t\t\t\t);\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\tsetTimeout={ this.setTimeout }\n\t\t\t\t\t\tclearTimeout={ this.clearTimeout }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t},\n\t'withSafeTimeout'\n);\n\nexport default withSafeTimeout;\n"],"mappings":";;;;;;AAGA,IAAAA,QAAA,GAAAC,OAAA;AASA,IAAAC,2BAAA,GAAAD,OAAA;AAAuF,IAAAE,WAAA,GAAAF,OAAA;AAZvF;AACA;AACA;;AAGA;AACA;AACA;;AAOA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAMA;AACA;AACA;AACA;AACA,MAAMG,eAAe,GAAG,IAAAC,sDAA0B,EAEhDC,iBAAoB,IAChB;EAEJ,OAAO,MAAMC,gBAAgB,SAASC,kBAAS,CAAiB;IAG/DC,WAAWA,CAAEC,KAAmB,EAAG;MAClC,KAAK,CAAEA,KAAM,CAAC;MACd,IAAI,CAACC,QAAQ,GAAG,EAAE;MAClB,IAAI,CAACC,UAAU,GAAG,IAAI,CAACA,UAAU,CAACC,IAAI,CAAE,IAAK,CAAC;MAC9C,IAAI,CAACC,YAAY,GAAG,IAAI,CAACA,YAAY,CAACD,IAAI,CAAE,IAAK,CAAC;IACnD;IAEAE,oBAAoBA,CAAA,EAAG;MACtB,IAAI,CAACJ,QAAQ,CAACK,OAAO,CAAEF,YAAa,CAAC;IACtC;IAEAF,UAAUA,CAAEK,EAAc,EAAEC,KAAa,EAAG;MAC3C,MAAMC,EAAE,GAAGP,UAAU,CAAE,MAAM;QAC5BK,EAAE,CAAC,CAAC;QACJ,IAAI,CAACH,YAAY,CAAEK,EAAG,CAAC;MACxB,CAAC,EAAED,KAAM,CAAC;MACV,IAAI,CAACP,QAAQ,CAACS,IAAI,CAAED,EAAG,CAAC;MACxB,OAAOA,EAAE;IACV;IAEAL,YAAYA,CAAEK,EAAU,EAAG;MAC1BL,YAAY,CAAEK,EAAG,CAAC;MAClB,IAAI,CAACR,QAAQ,GAAG,IAAI,CAACA,QAAQ,CAACU,MAAM,CACjCC,SAAS,IAAMA,SAAS,KAAKH,EAChC,CAAC;IACF;IAEAI,MAAMA,CAAA,EAAG;MACR;QAAA;QACC;QACA,IAAApB,WAAA,CAAAqB,GAAA,EAAClB,iBAAiB;UAAA,GACZ,IAAI,CAACI,KAAK;UACfE,UAAU,EAAG,IAAI,CAACA,UAAY;UAC9BE,YAAY,EAAG,IAAI,CAACA;QAAc,CAClC;MAAC;IAEJ;EACD,CAAC;AACF,CAAC,EACD,iBACD,CAAC;AAAC,IAAAW,QAAA,GAAAC,OAAA,CAAAC,OAAA,GAEavB,eAAe","ignoreList":[]}
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/higher-order/with-safe-timeout/index.tsx"],
4
+ "sourcesContent": ["/**\n * WordPress dependencies\n */\nimport { Component } from '@wordpress/element';\n\n/**\n * Internal dependencies\n */\nimport type {\n\tWithInjectedProps,\n\tWithoutInjectedProps,\n} from '../../utils/create-higher-order-component';\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * We cannot use the `Window['setTimeout']` and `Window['clearTimeout']`\n * types here because those functions include functionality that is not handled\n * by this component, like the ability to pass extra arguments.\n *\n * In the case of this component, we only handle the simplest case where\n * `setTimeout` only accepts a function (not a string) and an optional delay.\n */\ninterface TimeoutProps {\n\tsetTimeout: ( fn: () => void, delay: number ) => number;\n\tclearTimeout: ( id: number ) => void;\n}\n\n/**\n * A higher-order component used to provide and manage delayed function calls\n * that ought to be bound to a component's lifecycle.\n */\nconst withSafeTimeout = createHigherOrderComponent(\n\t< C extends WithInjectedProps< C, TimeoutProps > >(\n\t\tOriginalComponent: C\n\t) => {\n\t\ttype WrappedProps = WithoutInjectedProps< C, TimeoutProps >;\n\t\treturn class WrappedComponent extends Component< WrappedProps > {\n\t\t\ttimeouts: number[];\n\n\t\t\tconstructor( props: WrappedProps ) {\n\t\t\t\tsuper( props );\n\t\t\t\tthis.timeouts = [];\n\t\t\t\tthis.setTimeout = this.setTimeout.bind( this );\n\t\t\t\tthis.clearTimeout = this.clearTimeout.bind( this );\n\t\t\t}\n\n\t\t\tcomponentWillUnmount() {\n\t\t\t\tthis.timeouts.forEach( clearTimeout );\n\t\t\t}\n\n\t\t\tsetTimeout( fn: () => void, delay: number ) {\n\t\t\t\tconst id = setTimeout( () => {\n\t\t\t\t\tfn();\n\t\t\t\t\tthis.clearTimeout( id );\n\t\t\t\t}, delay );\n\t\t\t\tthis.timeouts.push( id );\n\t\t\t\treturn id;\n\t\t\t}\n\n\t\t\tclearTimeout( id: number ) {\n\t\t\t\tclearTimeout( id );\n\t\t\t\tthis.timeouts = this.timeouts.filter(\n\t\t\t\t\t( timeoutId ) => timeoutId !== id\n\t\t\t\t);\n\t\t\t}\n\n\t\t\trender() {\n\t\t\t\treturn (\n\t\t\t\t\t// @ts-ignore\n\t\t\t\t\t<OriginalComponent\n\t\t\t\t\t\t{ ...this.props }\n\t\t\t\t\t\tsetTimeout={ this.setTimeout }\n\t\t\t\t\t\tclearTimeout={ this.clearTimeout }\n\t\t\t\t\t/>\n\t\t\t\t);\n\t\t\t}\n\t\t};\n\t},\n\t'withSafeTimeout'\n);\n\nexport default withSafeTimeout;\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAqEK;AAAA;AAAA;AAAA;AAlEL,qBAA0B;AAS1B,2CAA2C;AAmB3C,MAAM,sBAAkB;AAAA,EACvB,CACC,sBACI;AAEJ,WAAO,MAAM,yBAAyB,yBAA0B;AAAA,MAC/D;AAAA,MAEA,YAAa,OAAsB;AAClC,cAAO,KAAM;AACb,aAAK,WAAW,CAAC;AACjB,aAAK,aAAa,KAAK,WAAW,KAAM,IAAK;AAC7C,aAAK,eAAe,KAAK,aAAa,KAAM,IAAK;AAAA,MAClD;AAAA,MAEA,uBAAuB;AACtB,aAAK,SAAS,QAAS,YAAa;AAAA,MACrC;AAAA,MAEA,WAAY,IAAgB,OAAgB;AAC3C,cAAM,KAAK,WAAY,MAAM;AAC5B,aAAG;AACH,eAAK,aAAc,EAAG;AAAA,QACvB,GAAG,KAAM;AACT,aAAK,SAAS,KAAM,EAAG;AACvB,eAAO;AAAA,MACR;AAAA,MAEA,aAAc,IAAa;AAC1B,qBAAc,EAAG;AACjB,aAAK,WAAW,KAAK,SAAS;AAAA,UAC7B,CAAE,cAAe,cAAc;AAAA,QAChC;AAAA,MACD;AAAA,MAEA,SAAS;AACR,eAEC;AAAA,UAAC;AAAA;AAAA,YACE,GAAG,KAAK;AAAA,YACV,YAAa,KAAK;AAAA,YAClB,cAAe,KAAK;AAAA;AAAA,QACrB;AAAA,MAEF;AAAA,IACD;AAAA,EACD;AAAA,EACA;AACD;AAEA,IAAO,4BAAQ;",
6
+ "names": []
7
+ }
@@ -1,51 +1,63 @@
1
1
  "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+ var with_state_exports = {};
30
+ __export(with_state_exports, {
31
+ default: () => withState
6
32
  });
7
- exports.default = withState;
8
- var _element = require("@wordpress/element");
9
- var _deprecated = _interopRequireDefault(require("@wordpress/deprecated"));
10
- var _createHigherOrderComponent = require("../../utils/create-higher-order-component");
11
- var _jsxRuntime = require("react/jsx-runtime");
12
- /**
13
- * WordPress dependencies
14
- */
15
-
16
- /**
17
- * Internal dependencies
18
- */
19
-
20
- /**
21
- * A Higher Order Component used to provide and manage internal component state
22
- * via props.
23
- *
24
- * @deprecated Use `useState` instead.
25
- *
26
- * @param {any} initialState Optional initial state of the component.
27
- *
28
- * @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.
29
- */function withState(initialState = {}) {
30
- (0, _deprecated.default)('wp.compose.withState', {
31
- since: '5.8',
32
- alternative: 'wp.element.useState'
33
+ module.exports = __toCommonJS(with_state_exports);
34
+ var import_jsx_runtime = require("react/jsx-runtime");
35
+ var import_element = require("@wordpress/element");
36
+ var import_deprecated = __toESM(require("@wordpress/deprecated"));
37
+ var import_create_higher_order_component = require("../../utils/create-higher-order-component");
38
+ function withState(initialState = {}) {
39
+ (0, import_deprecated.default)("wp.compose.withState", {
40
+ since: "5.8",
41
+ alternative: "wp.element.useState"
33
42
  });
34
- return (0, _createHigherOrderComponent.createHigherOrderComponent)(OriginalComponent => {
35
- return class WrappedComponent extends _element.Component {
36
- constructor(/** @type {any} */props) {
43
+ return (0, import_create_higher_order_component.createHigherOrderComponent)((OriginalComponent) => {
44
+ return class WrappedComponent extends import_element.Component {
45
+ constructor(props) {
37
46
  super(props);
38
47
  this.setState = this.setState.bind(this);
39
48
  this.state = initialState;
40
49
  }
41
50
  render() {
42
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(OriginalComponent, {
43
- ...this.props,
44
- ...this.state,
45
- setState: this.setState
46
- });
51
+ return /* @__PURE__ */ (0, import_jsx_runtime.jsx)(
52
+ OriginalComponent,
53
+ {
54
+ ...this.props,
55
+ ...this.state,
56
+ setState: this.setState
57
+ }
58
+ );
47
59
  }
48
60
  };
49
- }, 'withState');
61
+ }, "withState");
50
62
  }
51
- //# sourceMappingURL=index.js.map
63
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
1
- {"version":3,"names":["_element","require","_deprecated","_interopRequireDefault","_createHigherOrderComponent","_jsxRuntime","withState","initialState","deprecated","since","alternative","createHigherOrderComponent","OriginalComponent","WrappedComponent","Component","constructor","props","setState","bind","state","render","jsx"],"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;AAAuF,IAAAI,WAAA,GAAAJ,OAAA;AATvF;AACA;AACA;;AAIA;AACA;AACA;;AAGA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,GACe,SAASK,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,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,oBACC,IAAAf,WAAA,CAAAgB,GAAA,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","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": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAuCK;AApCL,qBAA0B;AAC1B,wBAAuB;AAKvB,2CAA2C;AAY5B,SAAR,UAA4B,eAAe,CAAC,GAAI;AACtD,wBAAAA,SAAY,wBAAwB;AAAA,IACnC,OAAO;AAAA,IACP,aAAa;AAAA,EACd,CAAE;AAEF,aAAO,iEAA4B,CAAE,sBAAuB;AAC3D,WAAO,MAAM,yBAAyB,yBAAU;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": ["deprecated"]
7
+ }
@@ -1,22 +1,28 @@
1
1
  "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
6
+ var __export = (target, all) => {
7
+ for (var name in all)
8
+ __defProp(target, name, { get: all[name], enumerable: true });
9
+ };
10
+ var __copyProps = (to, from, except, desc) => {
11
+ if (from && typeof from === "object" || typeof from === "function") {
12
+ for (let key of __getOwnPropNames(from))
13
+ if (!__hasOwnProp.call(to, key) && key !== except)
14
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
15
+ }
16
+ return to;
17
+ };
18
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
19
+ var use_async_list_exports = {};
20
+ __export(use_async_list_exports, {
21
+ default: () => use_async_list_default
5
22
  });
6
- exports.default = void 0;
7
- var _element = require("@wordpress/element");
8
- var _priorityQueue = require("@wordpress/priority-queue");
9
- /**
10
- * WordPress dependencies
11
- */
12
-
13
- /**
14
- * Returns the first items from list that are present on state.
15
- *
16
- * @param list New array.
17
- * @param state Current state.
18
- * @return First items present in state.
19
- */
23
+ module.exports = __toCommonJS(use_async_list_exports);
24
+ var import_element = require("@wordpress/element");
25
+ var import_priority_queue = require("@wordpress/priority-queue");
20
26
  function getFirstItemsPresentInState(list, state) {
21
27
  const firstItems = [];
22
28
  for (let i = 0; i < list.length; i++) {
@@ -28,35 +34,25 @@ function getFirstItemsPresentInState(list, state) {
28
34
  }
29
35
  return firstItems;
30
36
  }
31
-
32
- /**
33
- * React hook returns an array which items get asynchronously appended from a source array.
34
- * This behavior is useful if we want to render a list of items asynchronously for performance reasons.
35
- *
36
- * @param list Source array.
37
- * @param config Configuration object.
38
- *
39
- * @return Async array.
40
- */
41
- function useAsyncList(list, config = {
42
- step: 1
43
- }) {
44
- const {
45
- step = 1
46
- } = config;
47
- const [current, setCurrent] = (0, _element.useState)([]);
48
- (0, _element.useEffect)(() => {
49
- // On reset, we keep the first items that were previously rendered.
37
+ function useAsyncList(list, config = { step: 1 }) {
38
+ const { step = 1 } = config;
39
+ const [current, setCurrent] = (0, import_element.useState)([]);
40
+ (0, import_element.useEffect)(() => {
50
41
  let firstItems = getFirstItemsPresentInState(list, current);
51
42
  if (firstItems.length < step) {
52
- firstItems = firstItems.concat(list.slice(firstItems.length, step));
43
+ firstItems = firstItems.concat(
44
+ list.slice(firstItems.length, step)
45
+ );
53
46
  }
54
47
  setCurrent(firstItems);
55
- const asyncQueue = (0, _priorityQueue.createQueue)();
48
+ const asyncQueue = (0, import_priority_queue.createQueue)();
56
49
  for (let i = firstItems.length; i < list.length; i += step) {
57
50
  asyncQueue.add({}, () => {
58
- (0, _element.flushSync)(() => {
59
- setCurrent(state => [...state, ...list.slice(i, i + step)]);
51
+ (0, import_element.flushSync)(() => {
52
+ setCurrent((state) => [
53
+ ...state,
54
+ ...list.slice(i, i + step)
55
+ ]);
60
56
  });
61
57
  });
62
58
  }
@@ -64,5 +60,5 @@ function useAsyncList(list, config = {
64
60
  }, [list]);
65
61
  return current;
66
62
  }
67
- var _default = exports.default = useAsyncList;
68
- //# sourceMappingURL=index.js.map
63
+ var use_async_list_default = useAsyncList;
64
+ //# sourceMappingURL=index.js.map
@@ -1 +1,7 @@
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 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":";;;;;;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,GAAAC,OAAA,CAAAC,OAAA,GAEchB,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": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,qBAA+C;AAC/C,4BAA4B;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,QAAI,yBAAiB,CAAC,CAAE;AAEpD,gCAAW,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,iBAAa,mCAAY;AAC/B,aAAU,IAAI,WAAW,QAAQ,IAAI,KAAK,QAAQ,KAAK,MAAO;AAC7D,iBAAW,IAAK,CAAC,GAAG,MAAM;AACzB,sCAAW,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
+ }