@wordpress/compose 5.15.2 → 5.16.1-next.4d3b314fd5.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 (86) hide show
  1. package/CHANGELOG.md +11 -0
  2. package/README.md +86 -8
  3. package/build/higher-order/compose.js +5 -4
  4. package/build/higher-order/compose.js.map +1 -1
  5. package/build/higher-order/pipe.js +93 -0
  6. package/build/higher-order/pipe.js.map +1 -0
  7. package/build/hooks/use-debounce/index.js +11 -10
  8. package/build/hooks/use-debounce/index.js.map +1 -1
  9. package/build/hooks/use-disabled/index.js +3 -1
  10. package/build/hooks/use-disabled/index.js.map +1 -1
  11. package/build/hooks/use-drop-zone/index.js +4 -10
  12. package/build/hooks/use-drop-zone/index.js.map +1 -1
  13. package/build/hooks/use-fixed-window-list/index.js +5 -5
  14. package/build/hooks/use-fixed-window-list/index.js.map +1 -1
  15. package/build/hooks/use-instance-id/index.js +22 -20
  16. package/build/hooks/use-instance-id/index.js.map +1 -1
  17. package/build/hooks/use-throttle/index.js +12 -8
  18. package/build/hooks/use-throttle/index.js.map +1 -1
  19. package/build/index.js +37 -0
  20. package/build/index.js.map +1 -1
  21. package/build/index.native.js +37 -0
  22. package/build/index.native.js.map +1 -1
  23. package/build/utils/debounce/index.js +230 -0
  24. package/build/utils/debounce/index.js.map +1 -0
  25. package/build/utils/throttle/index.js +98 -0
  26. package/build/utils/throttle/index.js.map +1 -0
  27. package/build-module/higher-order/compose.js +4 -3
  28. package/build-module/higher-order/compose.js.map +1 -1
  29. package/build-module/higher-order/pipe.js +85 -0
  30. package/build-module/higher-order/pipe.js.map +1 -0
  31. package/build-module/hooks/use-debounce/index.js +10 -9
  32. package/build-module/hooks/use-debounce/index.js.map +1 -1
  33. package/build-module/hooks/use-disabled/index.js +3 -2
  34. package/build-module/hooks/use-disabled/index.js.map +1 -1
  35. package/build-module/hooks/use-drop-zone/index.js +4 -10
  36. package/build-module/hooks/use-drop-zone/index.js.map +1 -1
  37. package/build-module/hooks/use-fixed-window-list/index.js +5 -5
  38. package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
  39. package/build-module/hooks/use-instance-id/index.js +20 -19
  40. package/build-module/hooks/use-instance-id/index.js.map +1 -1
  41. package/build-module/hooks/use-throttle/index.js +11 -7
  42. package/build-module/hooks/use-throttle/index.js.map +1 -1
  43. package/build-module/index.js +7 -2
  44. package/build-module/index.js.map +1 -1
  45. package/build-module/index.native.js +7 -2
  46. package/build-module/index.native.js.map +1 -1
  47. package/build-module/utils/debounce/index.js +221 -0
  48. package/build-module/utils/debounce/index.js.map +1 -0
  49. package/build-module/utils/throttle/index.js +88 -0
  50. package/build-module/utils/throttle/index.js.map +1 -0
  51. package/build-types/higher-order/compose.d.ts +2 -5
  52. package/build-types/higher-order/compose.d.ts.map +1 -1
  53. package/build-types/higher-order/pipe.d.ts +61 -0
  54. package/build-types/higher-order/pipe.d.ts.map +1 -0
  55. package/build-types/hooks/use-debounce/index.d.ts +6 -6
  56. package/build-types/hooks/use-debounce/index.d.ts.map +1 -1
  57. package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
  58. package/build-types/hooks/use-drop-zone/index.d.ts.map +1 -1
  59. package/build-types/hooks/use-instance-id/index.d.ts +11 -6
  60. package/build-types/hooks/use-instance-id/index.d.ts.map +1 -1
  61. package/build-types/hooks/use-throttle/index.d.ts +6 -6
  62. package/build-types/hooks/use-throttle/index.d.ts.map +1 -1
  63. package/build-types/index.d.ts +3 -0
  64. package/build-types/utils/debounce/index.d.ts +104 -0
  65. package/build-types/utils/debounce/index.d.ts.map +1 -0
  66. package/build-types/utils/throttle/index.d.ts +77 -0
  67. package/build-types/utils/throttle/index.d.ts.map +1 -0
  68. package/package.json +8 -8
  69. package/src/higher-order/compose.ts +5 -3
  70. package/src/higher-order/pipe.ts +76 -0
  71. package/src/higher-order/test/compose.ts +39 -0
  72. package/src/higher-order/test/pipe.ts +37 -0
  73. package/src/hooks/use-debounce/index.js +11 -9
  74. package/src/hooks/use-disabled/index.js +3 -2
  75. package/src/hooks/use-drop-zone/index.js +6 -13
  76. package/src/hooks/use-fixed-window-list/index.js +5 -5
  77. package/src/hooks/use-instance-id/index.ts +59 -0
  78. package/src/hooks/use-throttle/index.js +11 -7
  79. package/src/index.js +6 -1
  80. package/src/index.native.js +6 -1
  81. package/src/utils/debounce/index.ts +260 -0
  82. package/src/utils/debounce/test/index.ts +367 -0
  83. package/src/utils/throttle/index.ts +95 -0
  84. package/src/utils/throttle/test/index.ts +256 -0
  85. package/tsconfig.tsbuildinfo +1 -1
  86. package/src/hooks/use-instance-id/index.js +0 -42
@@ -0,0 +1,61 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+ /**
41
+ * Creates a pipe function.
42
+ *
43
+ * Allows to choose whether to perform left-to-right or right-to-left composition.
44
+ *
45
+ * @see https://docs-lodash.com/v4/flow/
46
+ *
47
+ * @param {boolean} reverse True if right-to-left, false for left-to-right composition.
48
+ */
49
+ declare const basePipe: (reverse?: boolean) => (...funcs: Function[]) => (...args: unknown[]) => unknown;
50
+ /**
51
+ * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
52
+ * composition, where each successive invocation is supplied the return value of the previous.
53
+ *
54
+ * This is inspired by `lodash`'s `flow` function.
55
+ *
56
+ * @see https://docs-lodash.com/v4/flow/
57
+ */
58
+ declare const pipe: (...funcs: Function[]) => (...args: unknown[]) => unknown;
59
+ export { basePipe };
60
+ export default pipe;
61
+ //# sourceMappingURL=pipe.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"pipe.d.ts","sourceRoot":"","sources":["../../src/higher-order/pipe.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH;;;;;;;;GAQG;AACH,QAAA,MAAM,QAAQ,aACF,OAAO,gBACN,QAAQ,EAAE,eACX,OAAO,EAAE,YASnB,CAAC;AAEH;;;;;;;GAOG;AACH,QAAA,MAAM,IAAI,aApBG,QAAQ,EAAE,eACX,OAAO,EAAE,YAmBE,CAAC;AAExB,OAAO,EAAE,QAAQ,EAAE,CAAC;AAEpB,eAAe,IAAI,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Debounces a function with Lodash's `debounce`. A new debounced function will
2
+ * Debounces a function similar to Lodash's `debounce`. A new debounced function will
3
3
  * be returned and any scheduled calls cancelled if any of the arguments change,
4
4
  * including the function to debounce, so please wrap functions created on
5
5
  * render in components in `useCallback`.
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * @template {(...args: any[]) => void} TFunc
10
10
  *
11
- * @param {TFunc} fn The function to debounce.
12
- * @param {number} [wait] The number of milliseconds to delay.
13
- * @param {import('lodash').DebounceSettings} [options] The options object.
14
- * @return {import('lodash').DebouncedFunc<TFunc>} Debounced function.
11
+ * @param {TFunc} fn The function to debounce.
12
+ * @param {number} [wait] The number of milliseconds to delay.
13
+ * @param {import('../../utils/debounce').DebounceOptions} [options] The options object.
14
+ * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function.
15
15
  */
16
- export default function useDebounce<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("lodash").DebounceSettings | undefined): import("lodash").DebouncedFunc<TFunc>;
16
+ export default function useDebounce<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("../../utils/debounce").DebounceOptions | undefined): import("../../utils/debounce").DebouncedFunc<TFunc>;
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-debounce/index.js"],"names":[],"mappings":"AAYA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,wIAerC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-debounce/index.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,mKAcrC"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.js"],"names":[],"mappings":"AAkCA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IAjB4B,UAAU,GAA3B,OAAO;IACN,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAgKnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-disabled/index.js"],"names":[],"mappings":"AAmCA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH;IAjB4B,UAAU,GAA3B,OAAO;IACN,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAgKnD"}
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;IAV2C,UAAU;IACV,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,UAAU,QAAtC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,SAAS,QAArC,UAAU,KAAK,IAAI;IACS,MAAM,QAAlC,SAAS,KAAK,IAAI;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CAmMnD"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-drop-zone/index.js"],"names":[],"mappings":"AAgCA;;;;;;;;;;;;;GAaG;AACH;IAV2C,UAAU;IACV,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,UAAU,QAAtC,SAAS,KAAK,IAAI;IACU,WAAW,QAAvC,SAAS,KAAK,IAAI;IACU,SAAS,QAArC,UAAU,KAAK,IAAI;IACS,MAAM,QAAlC,SAAS,KAAK,IAAI;IAErB,OAAO,OAAO,EAAE,WAAW,CAAC,WAAW,CAAC,CA4LnD"}
@@ -1,10 +1,15 @@
1
1
  /**
2
- * Provides a unique instance ID.
2
+ * Specify the useInstanceId *function* signatures.
3
3
  *
4
- * @param {object} object Object reference to create an id for.
5
- * @param {string} [prefix] Prefix for the unique id.
6
- * @param {string | number} [preferredId=''] Default ID to use.
7
- * @return {string | number} The unique instance id.
4
+ * More accurately, useInstanceId distinguishes between three different
5
+ * signatures:
6
+ *
7
+ * 1. When only object is given, the returned value is a number
8
+ * 2. When object and prefix is given, the returned value is a string
9
+ * 3. When preferredId is given, the returned value is the type of preferredId
8
10
  */
9
- export default function useInstanceId(object: object, prefix?: string | undefined, preferredId?: string | number | undefined): string | number;
11
+ declare function useInstanceId(object: object): number;
12
+ declare function useInstanceId(object: object, prefix: string): string;
13
+ declare function useInstanceId<T extends string | number>(object: object, prefix: string, preferredId?: T): T;
14
+ export default useInstanceId;
10
15
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-instance-id/index.js"],"names":[],"mappings":"AAyBA;;;;;;;GAOG;AACH,8CALW,MAAM,2EAGL,MAAM,GAAG,MAAM,CAS1B"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-instance-id/index.ts"],"names":[],"mappings":"AAmBA;;;;;;;;;GASG;AACH,iBAAS,aAAa,CAAE,MAAM,EAAE,MAAM,GAAI,MAAM,CAAC;AACjD,iBAAS,aAAa,CAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAI,MAAM,CAAC;AACjE,iBAAS,aAAa,CAAE,CAAC,SAAS,MAAM,GAAG,MAAM,EAChD,MAAM,EAAE,MAAM,EACd,MAAM,EAAE,MAAM,EACd,WAAW,CAAC,EAAE,CAAC,GACb,CAAC,CAAC;AAuBL,eAAe,aAAa,CAAC"}
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Throttles a function with Lodash's `throttle`. A new throttled function will
2
+ * Throttles a function similar to Lodash's `throttle`. A new throttled function will
3
3
  * be returned and any scheduled calls cancelled if any of the arguments change,
4
4
  * including the function to throttle, so please wrap functions created on
5
5
  * render in components in `useCallback`.
@@ -8,10 +8,10 @@
8
8
  *
9
9
  * @template {(...args: any[]) => void} TFunc
10
10
  *
11
- * @param {TFunc} fn The function to throttle.
12
- * @param {number} [wait] The number of milliseconds to throttle invocations to.
13
- * @param {import('lodash').ThrottleSettings} [options] The options object. See linked documentation for details.
14
- * @return {import('lodash').DebouncedFunc<TFunc>} Throttled function.
11
+ * @param {TFunc} fn The function to throttle.
12
+ * @param {number} [wait] The number of milliseconds to throttle invocations to.
13
+ * @param {import('../../utils/throttle').ThrottleOptions} [options] The options object. See linked documentation for details.
14
+ * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Throttled function.
15
15
  */
16
- export default function useThrottle<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("lodash").ThrottleSettings | undefined): import("lodash").DebouncedFunc<TFunc>;
16
+ export default function useThrottle<TFunc extends (...args: any[]) => void>(fn: TFunc, wait?: number | undefined, options?: import("../../utils/throttle").ThrottleOptions | undefined): import("../../utils/debounce").DebouncedFunc<TFunc>;
17
17
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.js"],"names":[],"mappings":"AAWA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,wIAcrC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/hooks/use-throttle/index.js"],"names":[],"mappings":"AAeA;;;;;;;;;;;;;;GAcG;AACH,4DAPwB,GAAG,EAAE,KAAK,IAAI,mKAcrC"}
@@ -1,5 +1,8 @@
1
1
  export * from "./utils/create-higher-order-component";
2
+ export * from "./utils/debounce";
3
+ export * from "./utils/throttle";
2
4
  export { default as compose } from "./higher-order/compose";
5
+ export { default as pipe } from "./higher-order/pipe";
3
6
  export { default as ifCondition } from "./higher-order/if-condition";
4
7
  export { default as pure } from "./higher-order/pure";
5
8
  export { default as withGlobalEvents } from "./higher-order/with-global-events";
@@ -0,0 +1,104 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+ export interface DebounceOptions {
41
+ leading: boolean;
42
+ maxWait: number;
43
+ trailing: boolean;
44
+ }
45
+ export interface DebouncedFunc<T extends (...args: any[]) => any> {
46
+ /**
47
+ * Call the original function, but applying the debounce rules.
48
+ *
49
+ * If the debounced function can be run immediately, this calls it and returns its return
50
+ * value.
51
+ *
52
+ * Otherwise, it returns the return value of the last invocation, or undefined if the debounced
53
+ * function was not invoked yet.
54
+ */
55
+ (...args: Parameters<T>): ReturnType<T> | undefined;
56
+ /**
57
+ * Throw away any pending invocation of the debounced function.
58
+ */
59
+ cancel(): void;
60
+ /**
61
+ * If there is a pending invocation of the debounced function, invoke it immediately and return
62
+ * its return value.
63
+ *
64
+ * Otherwise, return the value from the last invocation, or undefined if the debounced function
65
+ * was never invoked.
66
+ */
67
+ flush(): ReturnType<T> | undefined;
68
+ }
69
+ /**
70
+ * A simplified and properly typed version of lodash's `debounce`, that
71
+ * always uses timers instead of sometimes using rAF.
72
+ *
73
+ * Creates a debounced function that delays invoking `func` until after `wait`
74
+ * milliseconds have elapsed since the last time the debounced function was
75
+ * invoked. The debounced function comes with a `cancel` method to cancel delayed
76
+ * `func` invocations and a `flush` method to immediately invoke them. Provide
77
+ * `options` to indicate whether `func` should be invoked on the leading and/or
78
+ * trailing edge of the `wait` timeout. The `func` is invoked with the last
79
+ * arguments provided to the debounced function. Subsequent calls to the debounced
80
+ * function return the result of the last `func` invocation.
81
+ *
82
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
83
+ * invoked on the trailing edge of the timeout only if the debounced function
84
+ * is invoked more than once during the `wait` timeout.
85
+ *
86
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
87
+ * until the next tick, similar to `setTimeout` with a timeout of `0`.
88
+ *
89
+ * @param {Function} func The function to debounce.
90
+ * @param {number} wait The number of milliseconds to delay.
91
+ * @param {Partial< DebounceOptions >} options The options object.
92
+ * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
93
+ * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.
94
+ * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
95
+ *
96
+ * @return Returns the new debounced function.
97
+ */
98
+ export declare const debounce: <FunctionT extends (...args: unknown[]) => unknown>(func: FunctionT, wait: number, options?: Partial<DebounceOptions> | undefined) => {
99
+ (this: unknown, ...args: Parameters<FunctionT>): ReturnType<FunctionT>;
100
+ cancel: () => void;
101
+ flush: () => ReturnType<FunctionT>;
102
+ pending: () => boolean;
103
+ };
104
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/debounce/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAEH,MAAM,WAAW,eAAe;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,OAAO,CAAC;CAClB;AAED,MAAM,WAAW,aAAa,CAAE,CAAC,SAAS,CAAE,GAAG,IAAI,EAAE,GAAG,EAAE,KAAM,GAAG;IAClE;;;;;;;;OAQG;IACH,CAAE,GAAG,IAAI,EAAE,UAAU,CAAE,CAAC,CAAE,GAAI,UAAU,CAAE,CAAC,CAAE,GAAG,SAAS,CAAC;IAE1D;;OAEG;IACH,MAAM,IAAI,IAAI,CAAC;IAEf;;;;;;OAMG;IACH,KAAK,IAAI,UAAU,CAAE,CAAC,CAAE,GAAG,SAAS,CAAC;CACrC;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,eAAO,MAAM,QAAQ,+BAAkC,OAAO,EAAE,KAAM,OAAO,yBAEtE,MAAM;WAgIc,OAAO;;;;CA2BjC,CAAC"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+ export interface ThrottleOptions {
41
+ leading?: boolean;
42
+ trailing?: boolean;
43
+ }
44
+ /**
45
+ * A simplified and properly typed version of lodash's `throttle`, that
46
+ * always uses timers instead of sometimes using rAF.
47
+ *
48
+ * Creates a throttled function that only invokes `func` at most once per
49
+ * every `wait` milliseconds. The throttled function comes with a `cancel`
50
+ * method to cancel delayed `func` invocations and a `flush` method to
51
+ * immediately invoke them. Provide `options` to indicate whether `func`
52
+ * should be invoked on the leading and/or trailing edge of the `wait`
53
+ * timeout. The `func` is invoked with the last arguments provided to the
54
+ * throttled function. Subsequent calls to the throttled function return
55
+ * the result of the last `func` invocation.
56
+ *
57
+ * **Note:** If `leading` and `trailing` options are `true`, `func` is
58
+ * invoked on the trailing edge of the timeout only if the throttled function
59
+ * is invoked more than once during the `wait` timeout.
60
+ *
61
+ * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
62
+ * until the next tick, similar to `setTimeout` with a timeout of `0`.
63
+ *
64
+ * @param {Function} func The function to throttle.
65
+ * @param {number} wait The number of milliseconds to throttle invocations to.
66
+ * @param {Partial< ThrottleOptions >} options The options object.
67
+ * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
68
+ * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
69
+ * @return Returns the new throttled function.
70
+ */
71
+ export declare const throttle: <FunctionT extends (...args: unknown[]) => unknown>(func: FunctionT, wait: number, options?: ThrottleOptions | undefined) => {
72
+ (this: unknown, ...args: Parameters<FunctionT>): ReturnType<FunctionT>;
73
+ cancel: () => void;
74
+ flush: () => ReturnType<FunctionT>;
75
+ pending: () => boolean;
76
+ };
77
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/utils/throttle/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAsCG;AAOH,MAAM,WAAW,eAAe;IAC/B,OAAO,CAAC,EAAE,OAAO,CAAC;IAClB,QAAQ,CAAC,EAAE,OAAO,CAAC;CACnB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,eAAO,MAAM,QAAQ,+BAAkC,OAAO,EAAE,KAAM,OAAO,yBAEtE,MAAM;;;;;CAeZ,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@wordpress/compose",
3
- "version": "5.15.2",
3
+ "version": "5.16.1-next.4d3b314fd5.0",
4
4
  "description": "WordPress higher-order components (HOCs).",
5
5
  "author": "The WordPress Contributors",
6
6
  "license": "GPL-2.0-or-later",
@@ -32,12 +32,12 @@
32
32
  "@babel/runtime": "^7.16.0",
33
33
  "@types/lodash": "^4.14.172",
34
34
  "@types/mousetrap": "^1.6.8",
35
- "@wordpress/deprecated": "^3.17.1",
36
- "@wordpress/dom": "^3.17.2",
37
- "@wordpress/element": "^4.15.1",
38
- "@wordpress/is-shallow-equal": "^4.17.1",
39
- "@wordpress/keycodes": "^3.17.1",
40
- "@wordpress/priority-queue": "^2.17.2",
35
+ "@wordpress/deprecated": "^3.18.1-next.4d3b314fd5.0",
36
+ "@wordpress/dom": "^3.18.1-next.4d3b314fd5.0",
37
+ "@wordpress/element": "^4.16.1-next.4d3b314fd5.0",
38
+ "@wordpress/is-shallow-equal": "^4.18.1-next.4d3b314fd5.0",
39
+ "@wordpress/keycodes": "^3.18.1-next.4d3b314fd5.0",
40
+ "@wordpress/priority-queue": "^2.18.1-next.4d3b314fd5.0",
41
41
  "change-case": "^4.1.2",
42
42
  "clipboard": "^2.0.8",
43
43
  "lodash": "^4.17.21",
@@ -50,5 +50,5 @@
50
50
  "publishConfig": {
51
51
  "access": "public"
52
52
  },
53
- "gitHead": "f6021282457317c7e12dcc3a3f02c9ac28e16a30"
53
+ "gitHead": "25054766423cb49d959eb656c2533530073ff5c2"
54
54
  }
@@ -1,14 +1,16 @@
1
1
  /**
2
- * External dependencies
2
+ * Internal dependencies
3
3
  */
4
- import { flowRight as compose } from 'lodash';
4
+ import { basePipe } from './pipe';
5
5
 
6
6
  /**
7
7
  * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
8
8
  * composition, where each successive invocation is supplied the return value of the previous.
9
9
  *
10
- * This is just a re-export of `lodash`'s `flowRight` function.
10
+ * This is inspired by `lodash`'s `flowRight` function.
11
11
  *
12
12
  * @see https://docs-lodash.com/v4/flow-right/
13
13
  */
14
+ const compose = basePipe( true );
15
+
14
16
  export default compose;
@@ -0,0 +1,76 @@
1
+ /**
2
+ * Parts of this source were derived and modified from lodash,
3
+ * released under the MIT license.
4
+ *
5
+ * https://github.com/lodash/lodash
6
+ *
7
+ * Copyright JS Foundation and other contributors <https://js.foundation/>
8
+ *
9
+ * Based on Underscore.js, copyright Jeremy Ashkenas,
10
+ * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
11
+ *
12
+ * This software consists of voluntary contributions made by many
13
+ * individuals. For exact contribution history, see the revision history
14
+ * available at https://github.com/lodash/lodash
15
+ *
16
+ * The following license applies to all parts of this software except as
17
+ * documented below:
18
+ *
19
+ * ====
20
+ *
21
+ * Permission is hereby granted, free of charge, to any person obtaining
22
+ * a copy of this software and associated documentation files (the
23
+ * "Software"), to deal in the Software without restriction, including
24
+ * without limitation the rights to use, copy, modify, merge, publish,
25
+ * distribute, sublicense, and/or sell copies of the Software, and to
26
+ * permit persons to whom the Software is furnished to do so, subject to
27
+ * the following conditions:
28
+ *
29
+ * The above copyright notice and this permission notice shall be
30
+ * included in all copies or substantial portions of the Software.
31
+ *
32
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33
+ * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
34
+ * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35
+ * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
36
+ * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
37
+ * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
38
+ * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
39
+ */
40
+
41
+ /**
42
+ * Creates a pipe function.
43
+ *
44
+ * Allows to choose whether to perform left-to-right or right-to-left composition.
45
+ *
46
+ * @see https://docs-lodash.com/v4/flow/
47
+ *
48
+ * @param {boolean} reverse True if right-to-left, false for left-to-right composition.
49
+ */
50
+ const basePipe =
51
+ ( reverse: boolean = false ) =>
52
+ ( ...funcs: Function[] ) =>
53
+ ( ...args: unknown[] ) => {
54
+ const functions = funcs.flat();
55
+ if ( reverse ) {
56
+ functions.reverse();
57
+ }
58
+ return functions.reduce(
59
+ ( prev, func ) => [ func( ...prev ) ],
60
+ args
61
+ )[ 0 ];
62
+ };
63
+
64
+ /**
65
+ * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
66
+ * composition, where each successive invocation is supplied the return value of the previous.
67
+ *
68
+ * This is inspired by `lodash`'s `flow` function.
69
+ *
70
+ * @see https://docs-lodash.com/v4/flow/
71
+ */
72
+ const pipe = basePipe();
73
+
74
+ export { basePipe };
75
+
76
+ export default pipe;
@@ -0,0 +1,39 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import compose from '../compose';
5
+
6
+ describe( 'compose', () => {
7
+ it( 'returns the initial value if no functions are specified', () => {
8
+ expect( compose()( 'test' ) ).toBe( 'test' );
9
+ } );
10
+
11
+ it( 'executes functions right-to-left when passed as separate arguments', () => {
12
+ const a = ( value ) => ( value += 'a' );
13
+ const b = ( value ) => ( value += 'b' );
14
+ const c = ( value ) => ( value += 'c' );
15
+
16
+ expect( compose( a, b, c )( 'test' ) ).toBe( 'testcba' );
17
+ } );
18
+
19
+ it( 'executes functions right-to-left when passed as a single array', () => {
20
+ const a = ( value ) => ( value += 'a' );
21
+ const b = ( value ) => ( value += 'b' );
22
+ const c = ( value ) => ( value += 'c' );
23
+
24
+ expect( compose( [ a, b, c ] )( 'test' ) ).toBe( 'testcba' );
25
+ } );
26
+
27
+ it( 'executes functions right-to-left when passed as a mix of separate arguments and arrays', () => {
28
+ const a = ( value ) => ( value += 'a' );
29
+ const b = ( value ) => ( value += 'b' );
30
+ const c = ( value ) => ( value += 'c' );
31
+ const d = ( value ) => ( value += 'd' );
32
+ const e = ( value ) => ( value += 'e' );
33
+ const f = ( value ) => ( value += 'f' );
34
+
35
+ expect( compose( [ a, b ], c, [ d ], e )( 'test' ) ).toBe(
36
+ 'testedcba'
37
+ );
38
+ } );
39
+ } );
@@ -0,0 +1,37 @@
1
+ /**
2
+ * Internal dependencies
3
+ */
4
+ import pipe from '../pipe';
5
+
6
+ describe( 'pipe', () => {
7
+ it( 'returns the initial value if no functions are specified', () => {
8
+ expect( pipe()( 'test' ) ).toBe( 'test' );
9
+ } );
10
+
11
+ it( 'executes functions left-to-right when passed as separate arguments', () => {
12
+ const a = ( value ) => ( value += 'a' );
13
+ const b = ( value ) => ( value += 'b' );
14
+ const c = ( value ) => ( value += 'c' );
15
+
16
+ expect( pipe( a, b, c )( 'test' ) ).toBe( 'testabc' );
17
+ } );
18
+
19
+ it( 'executes functions left-to-right when passed as a single array', () => {
20
+ const a = ( value ) => ( value += 'a' );
21
+ const b = ( value ) => ( value += 'b' );
22
+ const c = ( value ) => ( value += 'c' );
23
+
24
+ expect( pipe( [ a, b, c ] )( 'test' ) ).toBe( 'testabc' );
25
+ } );
26
+
27
+ it( 'executes functions left-to-right when passed as a mix of separate arguments and arrays', () => {
28
+ const a = ( value ) => ( value += 'a' );
29
+ const b = ( value ) => ( value += 'b' );
30
+ const c = ( value ) => ( value += 'c' );
31
+ const d = ( value ) => ( value += 'd' );
32
+ const e = ( value ) => ( value += 'e' );
33
+ const f = ( value ) => ( value += 'f' );
34
+
35
+ expect( pipe( [ a, b ], c, [ d ], e )( 'test' ) ).toBe( 'testabcde' );
36
+ } );
37
+ } );
@@ -1,7 +1,6 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { debounce } from 'lodash';
5
4
  import { useMemoOne } from 'use-memo-one';
6
5
 
7
6
  /**
@@ -9,9 +8,13 @@ import { useMemoOne } from 'use-memo-one';
9
8
  */
10
9
  import { useEffect } from '@wordpress/element';
11
10
 
12
- /* eslint-disable jsdoc/valid-types */
13
11
  /**
14
- * Debounces a function with Lodash's `debounce`. A new debounced function will
12
+ * Internal dependencies
13
+ */
14
+ import { debounce } from '../../utils/debounce';
15
+
16
+ /**
17
+ * Debounces a function similar to Lodash's `debounce`. A new debounced function will
15
18
  * be returned and any scheduled calls cancelled if any of the arguments change,
16
19
  * including the function to debounce, so please wrap functions created on
17
20
  * render in components in `useCallback`.
@@ -20,15 +23,14 @@ import { useEffect } from '@wordpress/element';
20
23
  *
21
24
  * @template {(...args: any[]) => void} TFunc
22
25
  *
23
- * @param {TFunc} fn The function to debounce.
24
- * @param {number} [wait] The number of milliseconds to delay.
25
- * @param {import('lodash').DebounceSettings} [options] The options object.
26
- * @return {import('lodash').DebouncedFunc<TFunc>} Debounced function.
26
+ * @param {TFunc} fn The function to debounce.
27
+ * @param {number} [wait] The number of milliseconds to delay.
28
+ * @param {import('../../utils/debounce').DebounceOptions} [options] The options object.
29
+ * @return {import('../../utils/debounce').DebouncedFunc<TFunc>} Debounced function.
27
30
  */
28
31
  export default function useDebounce( fn, wait, options ) {
29
- /* eslint-enable jsdoc/valid-types */
30
32
  const debounced = useMemoOne(
31
- () => debounce( fn, wait, options ),
33
+ () => debounce( fn, wait ?? 0, options ),
32
34
  [ fn, wait, options ]
33
35
  );
34
36
  useEffect( () => () => debounced.cancel(), [ debounced ] );
@@ -1,7 +1,7 @@
1
1
  /**
2
2
  * External dependencies
3
3
  */
4
- import { includes, debounce } from 'lodash';
4
+ import { includes } from 'lodash';
5
5
 
6
6
  /**
7
7
  * WordPress dependencies
@@ -11,6 +11,7 @@ import { focus } from '@wordpress/dom';
11
11
  /**
12
12
  * Internal dependencies
13
13
  */
14
+ import { debounce } from '../../utils/debounce';
14
15
  import useRefEffect from '../use-ref-effect';
15
16
 
16
17
  /**
@@ -176,7 +177,7 @@ export default function useDisabled( {
176
177
 
177
178
  // Debounce re-disable since disabling process itself will incur
178
179
  // additional mutations which should be ignored.
179
- const debouncedDisable = debounce( disable, undefined, {
180
+ const debouncedDisable = debounce( disable, 0, {
180
181
  leading: true,
181
182
  } );
182
183
  disable();