@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.
- package/CHANGELOG.md +2 -0
- package/build/higher-order/compose.js +25 -20
- package/build/higher-order/compose.js.map +7 -1
- package/build/higher-order/if-condition/index.js +35 -41
- package/build/higher-order/if-condition/index.js.map +7 -1
- package/build/higher-order/pipe.js +32 -66
- package/build/higher-order/pipe.js.map +7 -1
- package/build/higher-order/pure/index.js +44 -37
- package/build/higher-order/pure/index.js.map +7 -1
- package/build/higher-order/with-global-events/index.js +64 -73
- package/build/higher-order/with-global-events/index.js.map +7 -1
- package/build/higher-order/with-global-events/listener.js +34 -21
- package/build/higher-order/with-global-events/listener.js.map +7 -1
- package/build/higher-order/with-instance-id/index.js +45 -27
- package/build/higher-order/with-instance-id/index.js.map +7 -1
- package/build/higher-order/with-safe-timeout/index.js +70 -66
- package/build/higher-order/with-safe-timeout/index.js.map +7 -1
- package/build/higher-order/with-state/index.js +52 -40
- package/build/higher-order/with-state/index.js.map +7 -1
- package/build/hooks/use-async-list/index.js +38 -42
- package/build/hooks/use-async-list/index.js.map +7 -1
- package/build/hooks/use-constrained-tabbing/index.js +54 -75
- package/build/hooks/use-constrained-tabbing/index.js.map +7 -1
- package/build/hooks/use-copy-on-click/index.js +46 -56
- package/build/hooks/use-copy-on-click/index.js.map +7 -1
- package/build/hooks/use-copy-to-clipboard/index.js +41 -51
- package/build/hooks/use-copy-to-clipboard/index.js.map +7 -1
- package/build/hooks/use-debounce/index.js +30 -37
- package/build/hooks/use-debounce/index.js.map +7 -1
- package/build/hooks/use-debounced-input/index.js +39 -27
- package/build/hooks/use-debounced-input/index.js.map +7 -1
- package/build/hooks/use-dialog/index.js +63 -55
- package/build/hooks/use-dialog/index.js.map +7 -1
- package/build/hooks/use-disabled/index.js +74 -82
- package/build/hooks/use-disabled/index.js.map +7 -1
- package/build/hooks/use-dragging/index.js +51 -48
- package/build/hooks/use-dragging/index.js.map +7 -1
- package/build/hooks/use-drop-zone/index.js +133 -168
- package/build/hooks/use-drop-zone/index.js.map +7 -1
- package/build/hooks/use-event/index.js +33 -45
- package/build/hooks/use-event/index.js.map +7 -1
- package/build/hooks/use-fixed-window-list/index.js +109 -97
- package/build/hooks/use-fixed-window-list/index.js.map +7 -1
- package/build/hooks/use-focus-on-mount/index.js +44 -57
- package/build/hooks/use-focus-on-mount/index.js.map +7 -1
- package/build/hooks/use-focus-outside/index.js +44 -102
- package/build/hooks/use-focus-outside/index.js.map +7 -1
- package/build/hooks/use-focus-return/index.js +35 -56
- package/build/hooks/use-focus-return/index.js.map +7 -1
- package/build/hooks/use-focusable-iframe/index.js +38 -35
- package/build/hooks/use-focusable-iframe/index.js.map +7 -1
- package/build/hooks/use-instance-id/index.js +26 -42
- package/build/hooks/use-instance-id/index.js.map +7 -1
- package/build/hooks/use-isomorphic-layout-effect/index.js +25 -17
- package/build/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
- package/build/hooks/use-keyboard-shortcut/index.js +72 -69
- package/build/hooks/use-keyboard-shortcut/index.js.map +7 -1
- package/build/hooks/use-media-query/index.js +39 -35
- package/build/hooks/use-media-query/index.js.map +7 -1
- package/build/hooks/use-merge-refs/index.js +34 -102
- package/build/hooks/use-merge-refs/index.js.map +7 -1
- package/build/hooks/use-observable-value/index.js +31 -28
- package/build/hooks/use-observable-value/index.js.map +7 -1
- package/build/hooks/use-preferred-color-scheme/index.android.js +31 -23
- package/build/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
- package/build/hooks/use-preferred-color-scheme/index.ios.js +25 -17
- package/build/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
- package/build/hooks/use-previous/index.js +26 -25
- package/build/hooks/use-previous/index.js.map +7 -1
- package/build/hooks/use-reduced-motion/index.js +35 -18
- package/build/hooks/use-reduced-motion/index.js.map +7 -1
- package/build/hooks/use-ref-effect/index.js +25 -35
- package/build/hooks/use-ref-effect/index.js.map +7 -1
- package/build/hooks/use-resize-observer/index.js +35 -67
- package/build/hooks/use-resize-observer/index.js.map +7 -1
- package/build/hooks/use-resize-observer/legacy/index.js +47 -103
- package/build/hooks/use-resize-observer/legacy/index.js.map +7 -1
- package/build/hooks/use-resize-observer/use-resize-observer.js +44 -36
- package/build/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
- package/build/hooks/use-state-with-history/index.js +68 -63
- package/build/hooks/use-state-with-history/index.js.map +7 -1
- package/build/hooks/use-throttle/index.js +30 -37
- package/build/hooks/use-throttle/index.js.map +7 -1
- package/build/hooks/use-viewport-match/index.js +51 -70
- package/build/hooks/use-viewport-match/index.js.map +7 -1
- package/build/hooks/use-warn-on-change/index.js +50 -40
- package/build/hooks/use-warn-on-change/index.js.map +7 -1
- package/build/index.js +156 -358
- package/build/index.js.map +7 -1
- package/build/utils/create-higher-order-component/index.js +30 -34
- package/build/utils/create-higher-order-component/index.js.map +7 -1
- package/build/utils/debounce/index.js +38 -99
- package/build/utils/debounce/index.js.map +7 -1
- package/build/utils/observable-map/index.js +29 -19
- package/build/utils/observable-map/index.js.map +7 -1
- package/build/utils/throttle/index.js +30 -81
- package/build/utils/throttle/index.js.map +7 -1
- package/build-module/higher-order/compose.js +6 -15
- package/build-module/higher-order/compose.js.map +7 -1
- package/build-module/higher-order/if-condition/index.js +16 -37
- package/build-module/higher-order/if-condition/index.js.map +7 -1
- package/build-module/higher-order/pipe.js +10 -62
- package/build-module/higher-order/pipe.js.map +7 -1
- package/build-module/higher-order/pure/index.js +12 -29
- package/build-module/higher-order/pure/index.js.map +7 -1
- package/build-module/higher-order/with-global-events/index.js +34 -67
- package/build-module/higher-order/with-global-events/index.js.map +7 -1
- package/build-module/higher-order/with-global-events/listener.js +16 -17
- package/build-module/higher-order/with-global-events/listener.js.map +7 -1
- package/build-module/higher-order/with-instance-id/index.js +17 -22
- package/build-module/higher-order/with-instance-id/index.js.map +7 -1
- package/build-module/higher-order/with-safe-timeout/index.js +52 -62
- package/build-module/higher-order/with-safe-timeout/index.js.map +7 -1
- package/build-module/higher-order/with-state/index.js +23 -35
- package/build-module/higher-order/with-state/index.js.map +7 -1
- package/build-module/hooks/use-async-list/index.js +16 -33
- package/build-module/hooks/use-async-list/index.js.map +7 -1
- package/build-module/hooks/use-constrained-tabbing/index.js +26 -70
- package/build-module/hooks/use-constrained-tabbing/index.js.map +7 -1
- package/build-module/hooks/use-copy-on-click/index.js +14 -47
- package/build-module/hooks/use-copy-on-click/index.js.map +7 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js +11 -44
- package/build-module/hooks/use-copy-to-clipboard/index.js.map +7 -1
- package/build-module/hooks/use-debounce/index.js +12 -33
- package/build-module/hooks/use-debounce/index.js.map +7 -1
- package/build-module/hooks/use-debounced-input/index.js +7 -18
- package/build-module/hooks/use-debounced-input/index.js.map +7 -1
- package/build-module/hooks/use-dialog/index.js +29 -43
- package/build-module/hooks/use-dialog/index.js.map +7 -1
- package/build-module/hooks/use-disabled/index.js +47 -78
- package/build-module/hooks/use-disabled/index.js.map +7 -1
- package/build-module/hooks/use-dragging/index.js +19 -39
- package/build-module/hooks/use-dragging/index.js.map +7 -1
- package/build-module/hooks/use-drop-zone/index.js +100 -158
- package/build-module/hooks/use-drop-zone/index.js.map +7 -1
- package/build-module/hooks/use-event/index.js +13 -39
- package/build-module/hooks/use-event/index.js.map +7 -1
- package/build-module/hooks/use-fixed-window-list/index.js +86 -87
- package/build-module/hooks/use-fixed-window-list/index.js.map +7 -1
- package/build-module/hooks/use-focus-on-mount/index.js +12 -48
- package/build-module/hooks/use-focus-on-mount/index.js.map +7 -1
- package/build-module/hooks/use-focus-outside/index.js +21 -93
- package/build-module/hooks/use-focus-outside/index.js.map +7 -1
- package/build-module/hooks/use-focus-return/index.js +13 -48
- package/build-module/hooks/use-focus-return/index.js.map +7 -1
- package/build-module/hooks/use-focusable-iframe/index.js +11 -31
- package/build-module/hooks/use-focusable-iframe/index.js.map +7 -1
- package/build-module/hooks/use-instance-id/index.js +7 -36
- package/build-module/hooks/use-instance-id/index.js.map +7 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js +7 -13
- package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +7 -1
- package/build-module/hooks/use-keyboard-shortcut/index.js +40 -60
- package/build-module/hooks/use-keyboard-shortcut/index.js.map +7 -1
- package/build-module/hooks/use-media-query/index.js +21 -30
- package/build-module/hooks/use-media-query/index.js.map +7 -1
- package/build-module/hooks/use-merge-refs/index.js +10 -92
- package/build-module/hooks/use-merge-refs/index.js.map +7 -1
- package/build-module/hooks/use-observable-value/index.js +13 -24
- package/build-module/hooks/use-observable-value/index.js.map +7 -1
- package/build-module/hooks/use-preferred-color-scheme/index.android.js +15 -18
- package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +7 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js +6 -12
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +7 -1
- package/build-module/hooks/use-previous/index.js +7 -20
- package/build-module/hooks/use-previous/index.js.map +7 -1
- package/build-module/hooks/use-reduced-motion/index.js +7 -13
- package/build-module/hooks/use-reduced-motion/index.js.map +7 -1
- package/build-module/hooks/use-ref-effect/index.js +7 -31
- package/build-module/hooks/use-ref-effect/index.js.map +7 -1
- package/build-module/hooks/use-resize-observer/index.js +7 -61
- package/build-module/hooks/use-resize-observer/index.js.map +7 -1
- package/build-module/hooks/use-resize-observer/legacy/index.js +28 -96
- package/build-module/hooks/use-resize-observer/legacy/index.js.map +7 -1
- package/build-module/hooks/use-resize-observer/use-resize-observer.js +10 -28
- package/build-module/hooks/use-resize-observer/use-resize-observer.js.map +7 -1
- package/build-module/hooks/use-state-with-history/index.js +47 -55
- package/build-module/hooks/use-state-with-history/index.js.map +7 -1
- package/build-module/hooks/use-throttle/index.js +12 -33
- package/build-module/hooks/use-throttle/index.js.map +7 -1
- package/build-module/hooks/use-viewport-match/index.js +22 -64
- package/build-module/hooks/use-viewport-match/index.js.map +7 -1
- package/build-module/hooks/use-warn-on-change/index.js +21 -34
- package/build-module/hooks/use-warn-on-change/index.js.map +7 -1
- package/build-module/index.js +83 -53
- package/build-module/index.js.map +7 -1
- package/build-module/utils/create-higher-order-component/index.js +9 -30
- package/build-module/utils/create-higher-order-component/index.js.map +7 -1
- package/build-module/utils/debounce/index.js +17 -95
- package/build-module/utils/debounce/index.js.map +7 -1
- package/build-module/utils/observable-map/index.js +8 -16
- package/build-module/utils/observable-map/index.js.map +7 -1
- package/build-module/utils/throttle/index.js +8 -75
- package/build-module/utils/throttle/index.js.map +7 -1
- package/package.json +17 -10
- package/src/hooks/use-debounce/index.js +1 -1
- package/tsconfig.tsbuildinfo +1 -1
- package/build/higher-order/with-network-connectivity/index.native.js +0 -27
- package/build/higher-order/with-network-connectivity/index.native.js.map +0 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +0 -37
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
- package/build/hooks/use-constrained-tabbing/index.native.js +0 -20
- package/build/hooks/use-constrained-tabbing/index.native.js.map +0 -1
- package/build/hooks/use-focus-outside/index.native.js +0 -175
- package/build/hooks/use-focus-outside/index.native.js.map +0 -1
- package/build/hooks/use-keyboard-shortcut/index.native.js +0 -9
- package/build/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
- package/build/hooks/use-network-connectivity/index.native.js +0 -58
- package/build/hooks/use-network-connectivity/index.native.js.map +0 -1
- package/build/hooks/use-preferred-color-scheme-style/index.native.js +0 -42
- package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
- package/build/hooks/use-resize-observer/index.native.js +0 -14
- package/build/hooks/use-resize-observer/index.native.js.map +0 -1
- package/build/hooks/use-resize-observer/legacy/index.native.js +0 -62
- package/build/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
- package/build/index.native.js +0 -297
- package/build/index.native.js.map +0 -1
- package/build-module/higher-order/with-network-connectivity/index.native.js +0 -19
- package/build-module/higher-order/with-network-connectivity/index.native.js.map +0 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js +0 -29
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +0 -1
- package/build-module/hooks/use-constrained-tabbing/index.native.js +0 -13
- package/build-module/hooks/use-constrained-tabbing/index.native.js.map +0 -1
- package/build-module/hooks/use-focus-outside/index.native.js +0 -169
- package/build-module/hooks/use-focus-outside/index.native.js.map +0 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -3
- package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +0 -1
- package/build-module/hooks/use-network-connectivity/index.native.js +0 -52
- package/build-module/hooks/use-network-connectivity/index.native.js.map +0 -1
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +0 -35
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +0 -1
- package/build-module/hooks/use-resize-observer/index.native.js +0 -2
- package/build-module/hooks/use-resize-observer/index.native.js.map +0 -1
- package/build-module/hooks/use-resize-observer/legacy/index.native.js +0 -56
- package/build-module/hooks/use-resize-observer/legacy/index.native.js.map +0 -1
- package/build-module/index.native.js +0 -45
- package/build-module/index.native.js.map +0 -1
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/create-higher-order-component/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport { pascalCase } from 'change-case';\nimport type { ComponentType } from 'react';\n\ntype GetProps< C > = C extends ComponentType< infer P > ? P : never;\n\nexport type WithoutInjectedProps< C, I > = Omit< GetProps< C >, keyof I >;\n\nexport type WithInjectedProps< C, I > = ComponentType<\n\tWithoutInjectedProps< C, I > & I\n>;\n\n/**\n * Given a function mapping a component to an enhanced component and modifier\n * name, returns the enhanced component augmented with a generated displayName.\n *\n * @param mapComponent Function mapping component to enhanced component.\n * @param modifierName Seed name from which to generated display name.\n *\n * @return Component class with generated display name assigned.\n */\nexport function createHigherOrderComponent<\n\tTInner extends ComponentType< any >,\n\tTOuter extends ComponentType< any >,\n>( mapComponent: ( Inner: TInner ) => TOuter, modifierName: string ) {\n\treturn ( Inner: TInner ) => {\n\t\tconst Outer = mapComponent( Inner );\n\t\tOuter.displayName = hocName( modifierName, Inner );\n\t\treturn Outer;\n\t};\n}\n\n/**\n * Returns a displayName for a higher-order component, given a wrapper name.\n *\n * @example\n * hocName( 'MyMemo', Widget ) === 'MyMemo(Widget)';\n * hocName( 'MyMemo', <div /> ) === 'MyMemo(Component)';\n *\n * @param name Name assigned to higher-order component's wrapper component.\n * @param Inner Wrapped component inside higher-order component.\n * @return Wrapped name of higher-order component.\n */\nconst hocName = ( name: string, Inner: ComponentType< any > ) => {\n\tconst inner = Inner.displayName || Inner.name || 'Component';\n\tconst outer = pascalCase( name ?? '' );\n\n\treturn `${ outer }(${ inner })`;\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAGA,yBAA2B;AAoBpB,SAAS,2BAGb,cAA2C,cAAuB;AACpE,SAAO,CAAE,UAAmB;AAC3B,UAAM,QAAQ,aAAc,KAAM;AAClC,UAAM,cAAc,QAAS,cAAc,KAAM;AACjD,WAAO;AAAA,EACR;AACD;AAaA,MAAM,UAAU,CAAE,MAAc,UAAiC;AAChE,QAAM,QAAQ,MAAM,eAAe,MAAM,QAAQ;AACjD,QAAM,YAAQ,+BAAY,QAAQ,EAAG;AAErC,SAAO,GAAI,KAAM,IAAK,KAAM;AAC7B;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,78 +1,26 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 debounce_exports = {};
|
|
20
|
+
__export(debounce_exports, {
|
|
21
|
+
debounce: () => debounce
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* Parts of this source were derived and modified from lodash,
|
|
9
|
-
* released under the MIT license.
|
|
10
|
-
*
|
|
11
|
-
* https://github.com/lodash/lodash
|
|
12
|
-
*
|
|
13
|
-
* Copyright JS Foundation and other contributors <https://js.foundation/>
|
|
14
|
-
*
|
|
15
|
-
* Based on Underscore.js, copyright Jeremy Ashkenas,
|
|
16
|
-
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
|
17
|
-
*
|
|
18
|
-
* This software consists of voluntary contributions made by many
|
|
19
|
-
* individuals. For exact contribution history, see the revision history
|
|
20
|
-
* available at https://github.com/lodash/lodash
|
|
21
|
-
*
|
|
22
|
-
* The following license applies to all parts of this software except as
|
|
23
|
-
* documented below:
|
|
24
|
-
*
|
|
25
|
-
* ====
|
|
26
|
-
*
|
|
27
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
28
|
-
* a copy of this software and associated documentation files (the
|
|
29
|
-
* "Software"), to deal in the Software without restriction, including
|
|
30
|
-
* without limitation the rights to use, copy, modify, merge, publish,
|
|
31
|
-
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
32
|
-
* permit persons to whom the Software is furnished to do so, subject to
|
|
33
|
-
* the following conditions:
|
|
34
|
-
*
|
|
35
|
-
* The above copyright notice and this permission notice shall be
|
|
36
|
-
* included in all copies or substantial portions of the Software.
|
|
37
|
-
*
|
|
38
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
39
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
40
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
41
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
42
|
-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
43
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
44
|
-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
45
|
-
*/
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* A simplified and properly typed version of lodash's `debounce`, that
|
|
49
|
-
* always uses timers instead of sometimes using rAF.
|
|
50
|
-
*
|
|
51
|
-
* Creates a debounced function that delays invoking `func` until after `wait`
|
|
52
|
-
* milliseconds have elapsed since the last time the debounced function was
|
|
53
|
-
* invoked. The debounced function comes with a `cancel` method to cancel delayed
|
|
54
|
-
* `func` invocations and a `flush` method to immediately invoke them. Provide
|
|
55
|
-
* `options` to indicate whether `func` should be invoked on the leading and/or
|
|
56
|
-
* trailing edge of the `wait` timeout. The `func` is invoked with the last
|
|
57
|
-
* arguments provided to the debounced function. Subsequent calls to the debounced
|
|
58
|
-
* function return the result of the last `func` invocation.
|
|
59
|
-
*
|
|
60
|
-
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
61
|
-
* invoked on the trailing edge of the timeout only if the debounced function
|
|
62
|
-
* is invoked more than once during the `wait` timeout.
|
|
63
|
-
*
|
|
64
|
-
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
65
|
-
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
66
|
-
*
|
|
67
|
-
* @param {Function} func The function to debounce.
|
|
68
|
-
* @param {number} wait The number of milliseconds to delay.
|
|
69
|
-
* @param {Partial< DebounceOptions >} options The options object.
|
|
70
|
-
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
|
|
71
|
-
* @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.
|
|
72
|
-
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
|
|
73
|
-
*
|
|
74
|
-
* @return Returns the new debounced function.
|
|
75
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(debounce_exports);
|
|
76
24
|
const debounce = (func, wait, options) => {
|
|
77
25
|
let lastArgs;
|
|
78
26
|
let lastThis;
|
|
@@ -86,17 +34,17 @@ const debounce = (func, wait, options) => {
|
|
|
86
34
|
let trailing = true;
|
|
87
35
|
if (options) {
|
|
88
36
|
leading = !!options.leading;
|
|
89
|
-
maxing =
|
|
90
|
-
if (options.maxWait !==
|
|
37
|
+
maxing = "maxWait" in options;
|
|
38
|
+
if (options.maxWait !== void 0) {
|
|
91
39
|
maxWait = Math.max(options.maxWait, wait);
|
|
92
40
|
}
|
|
93
|
-
trailing =
|
|
41
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
94
42
|
}
|
|
95
43
|
function invokeFunc(time) {
|
|
96
44
|
const args = lastArgs;
|
|
97
45
|
const thisArg = lastThis;
|
|
98
|
-
lastArgs =
|
|
99
|
-
lastThis =
|
|
46
|
+
lastArgs = void 0;
|
|
47
|
+
lastThis = void 0;
|
|
100
48
|
lastInvokeTime = time;
|
|
101
49
|
result = func.apply(thisArg, args);
|
|
102
50
|
return result;
|
|
@@ -105,16 +53,13 @@ const debounce = (func, wait, options) => {
|
|
|
105
53
|
timerId = setTimeout(pendingFunc, waitTime);
|
|
106
54
|
}
|
|
107
55
|
function cancelTimer() {
|
|
108
|
-
if (timerId !==
|
|
56
|
+
if (timerId !== void 0) {
|
|
109
57
|
clearTimeout(timerId);
|
|
110
58
|
}
|
|
111
59
|
}
|
|
112
60
|
function leadingEdge(time) {
|
|
113
|
-
// Reset any `maxWait` timer.
|
|
114
61
|
lastInvokeTime = time;
|
|
115
|
-
// Start the timer for the trailing edge.
|
|
116
62
|
startTimer(timerExpired, wait);
|
|
117
|
-
// Invoke the leading edge.
|
|
118
63
|
return leading ? invokeFunc(time) : result;
|
|
119
64
|
}
|
|
120
65
|
function getTimeSinceLastCall(time) {
|
|
@@ -129,46 +74,38 @@ const debounce = (func, wait, options) => {
|
|
|
129
74
|
function shouldInvoke(time) {
|
|
130
75
|
const timeSinceLastCall = getTimeSinceLastCall(time);
|
|
131
76
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
132
|
-
|
|
133
|
-
// Either this is the first call, activity has stopped and we're at the
|
|
134
|
-
// trailing edge, the system time has gone backwards and we're treating
|
|
135
|
-
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
136
|
-
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
77
|
+
return lastCallTime === void 0 || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
137
78
|
}
|
|
138
79
|
function timerExpired() {
|
|
139
80
|
const time = Date.now();
|
|
140
81
|
if (shouldInvoke(time)) {
|
|
141
82
|
return trailingEdge(time);
|
|
142
83
|
}
|
|
143
|
-
// Restart the timer.
|
|
144
84
|
startTimer(timerExpired, remainingWait(time));
|
|
145
|
-
return
|
|
85
|
+
return void 0;
|
|
146
86
|
}
|
|
147
87
|
function clearTimer() {
|
|
148
|
-
timerId =
|
|
88
|
+
timerId = void 0;
|
|
149
89
|
}
|
|
150
90
|
function trailingEdge(time) {
|
|
151
91
|
clearTimer();
|
|
152
|
-
|
|
153
|
-
// Only invoke if we have `lastArgs` which means `func` has been
|
|
154
|
-
// debounced at least once.
|
|
155
92
|
if (trailing && lastArgs) {
|
|
156
93
|
return invokeFunc(time);
|
|
157
94
|
}
|
|
158
|
-
lastArgs = lastThis =
|
|
95
|
+
lastArgs = lastThis = void 0;
|
|
159
96
|
return result;
|
|
160
97
|
}
|
|
161
98
|
function cancel() {
|
|
162
99
|
cancelTimer();
|
|
163
100
|
lastInvokeTime = 0;
|
|
164
101
|
clearTimer();
|
|
165
|
-
lastArgs = lastCallTime = lastThis =
|
|
102
|
+
lastArgs = lastCallTime = lastThis = void 0;
|
|
166
103
|
}
|
|
167
104
|
function flush() {
|
|
168
105
|
return pending() ? trailingEdge(Date.now()) : result;
|
|
169
106
|
}
|
|
170
107
|
function pending() {
|
|
171
|
-
return timerId !==
|
|
108
|
+
return timerId !== void 0;
|
|
172
109
|
}
|
|
173
110
|
function debounced(...args) {
|
|
174
111
|
const time = Date.now();
|
|
@@ -181,7 +118,6 @@ const debounce = (func, wait, options) => {
|
|
|
181
118
|
return leadingEdge(lastCallTime);
|
|
182
119
|
}
|
|
183
120
|
if (maxing) {
|
|
184
|
-
// Handle invocations in a tight loop.
|
|
185
121
|
startTimer(timerExpired, wait);
|
|
186
122
|
return invokeFunc(lastCallTime);
|
|
187
123
|
}
|
|
@@ -196,5 +132,8 @@ const debounce = (func, wait, options) => {
|
|
|
196
132
|
debounced.pending = pending;
|
|
197
133
|
return debounced;
|
|
198
134
|
};
|
|
199
|
-
|
|
200
|
-
|
|
135
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
136
|
+
0 && (module.exports = {
|
|
137
|
+
debounce
|
|
138
|
+
});
|
|
139
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{"version":3,"names":["debounce","func","wait","options","lastArgs","lastThis","maxWait","result","timerId","lastCallTime","lastInvokeTime","leading","maxing","trailing","undefined","Math","max","invokeFunc","time","args","thisArg","apply","startTimer","pendingFunc","waitTime","setTimeout","cancelTimer","clearTimeout","leadingEdge","timerExpired","getTimeSinceLastCall","remainingWait","timeSinceLastCall","timeSinceLastInvoke","timeWaiting","min","shouldInvoke","Date","now","trailingEdge","clearTimer","cancel","flush","pending","debounced","isInvoking","exports"],"sources":["@wordpress/compose/src/utils/debounce/index.ts"],"sourcesContent":["/**\n * Parts of this source were derived and modified from lodash,\n * released under the MIT license.\n *\n * https://github.com/lodash/lodash\n *\n * Copyright JS Foundation and other contributors <https://js.foundation/>\n *\n * Based on Underscore.js, copyright Jeremy Ashkenas,\n * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>\n *\n * This software consists of voluntary contributions made by many\n * individuals. For exact contribution history, see the revision history\n * available at https://github.com/lodash/lodash\n *\n * The following license applies to all parts of this software except as\n * documented below:\n *\n * ====\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nexport interface DebounceOptions {\n\tleading: boolean;\n\tmaxWait: number;\n\ttrailing: boolean;\n}\n\nexport interface DebouncedFunc< T extends ( ...args: any[] ) => any > {\n\t/**\n\t * Call the original function, but applying the debounce rules.\n\t *\n\t * If the debounced function can be run immediately, this calls it and returns its return\n\t * value.\n\t *\n\t * Otherwise, it returns the return value of the last invocation, or undefined if the debounced\n\t * function was not invoked yet.\n\t */\n\t( ...args: Parameters< T > ): ReturnType< T > | undefined;\n\n\t/**\n\t * Throw away any pending invocation of the debounced function.\n\t */\n\tcancel: () => void;\n\n\t/**\n\t * If there is a pending invocation of the debounced function, invoke it immediately and return\n\t * its return value.\n\t *\n\t * Otherwise, return the value from the last invocation, or undefined if the debounced function\n\t * was never invoked.\n\t */\n\tflush: () => ReturnType< T > | undefined;\n}\n\n/**\n * A simplified and properly typed version of lodash's `debounce`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel delayed\n * `func` invocations and a `flush` method to immediately invoke them. Provide\n * `options` to indicate whether `func` should be invoked on the leading and/or\n * trailing edge of the `wait` timeout. The `func` is invoked with the last\n * arguments provided to the debounced function. Subsequent calls to the debounced\n * function return the result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} wait The number of milliseconds to delay.\n * @param {Partial< DebounceOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n *\n * @return Returns the new debounced function.\n */\nexport const debounce = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: Partial< DebounceOptions >\n) => {\n\tlet lastArgs: Parameters< FunctionT > | undefined;\n\tlet lastThis: unknown | undefined;\n\tlet maxWait = 0;\n\tlet result: ReturnType< FunctionT >;\n\tlet timerId: ReturnType< typeof setTimeout > | undefined;\n\tlet lastCallTime: number | undefined;\n\n\tlet lastInvokeTime = 0;\n\tlet leading = false;\n\tlet maxing = false;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = !! options.leading;\n\t\tmaxing = 'maxWait' in options;\n\t\tif ( options.maxWait !== undefined ) {\n\t\t\tmaxWait = Math.max( options.maxWait, wait );\n\t\t}\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\n\tfunction invokeFunc( time: number ) {\n\t\tconst args = lastArgs;\n\t\tconst thisArg = lastThis;\n\n\t\tlastArgs = undefined;\n\t\tlastThis = undefined;\n\t\tlastInvokeTime = time;\n\n\t\tresult = func.apply( thisArg, args! ) as ReturnType< FunctionT >;\n\t\treturn result;\n\t}\n\n\tfunction startTimer(\n\t\tpendingFunc: () => void,\n\t\twaitTime: number | undefined\n\t) {\n\t\ttimerId = setTimeout( pendingFunc, waitTime );\n\t}\n\n\tfunction cancelTimer() {\n\t\tif ( timerId !== undefined ) {\n\t\t\tclearTimeout( timerId );\n\t\t}\n\t}\n\n\tfunction leadingEdge( time: number ) {\n\t\t// Reset any `maxWait` timer.\n\t\tlastInvokeTime = time;\n\t\t// Start the timer for the trailing edge.\n\t\tstartTimer( timerExpired, wait );\n\t\t// Invoke the leading edge.\n\t\treturn leading ? invokeFunc( time ) : result;\n\t}\n\n\tfunction getTimeSinceLastCall( time: number ) {\n\t\treturn time - ( lastCallTime || 0 );\n\t}\n\n\tfunction remainingWait( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\t\tconst timeWaiting = wait - timeSinceLastCall;\n\n\t\treturn maxing\n\t\t\t? Math.min( timeWaiting, maxWait - timeSinceLastInvoke )\n\t\t\t: timeWaiting;\n\t}\n\n\tfunction shouldInvoke( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\n\t\t// Either this is the first call, activity has stopped and we're at the\n\t\t// trailing edge, the system time has gone backwards and we're treating\n\t\t// it as the trailing edge, or we've hit the `maxWait` limit.\n\t\treturn (\n\t\t\tlastCallTime === undefined ||\n\t\t\ttimeSinceLastCall >= wait ||\n\t\t\ttimeSinceLastCall < 0 ||\n\t\t\t( maxing && timeSinceLastInvoke >= maxWait )\n\t\t);\n\t}\n\n\tfunction timerExpired() {\n\t\tconst time = Date.now();\n\t\tif ( shouldInvoke( time ) ) {\n\t\t\treturn trailingEdge( time );\n\t\t}\n\t\t// Restart the timer.\n\t\tstartTimer( timerExpired, remainingWait( time ) );\n\t\treturn undefined;\n\t}\n\n\tfunction clearTimer() {\n\t\ttimerId = undefined;\n\t}\n\n\tfunction trailingEdge( time: number ) {\n\t\tclearTimer();\n\n\t\t// Only invoke if we have `lastArgs` which means `func` has been\n\t\t// debounced at least once.\n\t\tif ( trailing && lastArgs ) {\n\t\t\treturn invokeFunc( time );\n\t\t}\n\t\tlastArgs = lastThis = undefined;\n\t\treturn result;\n\t}\n\n\tfunction cancel() {\n\t\tcancelTimer();\n\t\tlastInvokeTime = 0;\n\t\tclearTimer();\n\t\tlastArgs = lastCallTime = lastThis = undefined;\n\t}\n\n\tfunction flush() {\n\t\treturn pending() ? trailingEdge( Date.now() ) : result;\n\t}\n\n\tfunction pending() {\n\t\treturn timerId !== undefined;\n\t}\n\n\tfunction debounced( this: unknown, ...args: Parameters< FunctionT > ) {\n\t\tconst time = Date.now();\n\t\tconst isInvoking = shouldInvoke( time );\n\n\t\tlastArgs = args;\n\t\tlastThis = this;\n\t\tlastCallTime = time;\n\n\t\tif ( isInvoking ) {\n\t\t\tif ( ! pending() ) {\n\t\t\t\treturn leadingEdge( lastCallTime );\n\t\t\t}\n\t\t\tif ( maxing ) {\n\t\t\t\t// Handle invocations in a tight loop.\n\t\t\t\tstartTimer( timerExpired, wait );\n\t\t\t\treturn invokeFunc( lastCallTime );\n\t\t\t}\n\t\t}\n\t\tif ( ! pending() ) {\n\t\t\tstartTimer( timerExpired, wait );\n\t\t}\n\t\treturn result;\n\t}\n\tdebounced.cancel = cancel;\n\tdebounced.flush = flush;\n\tdebounced.pending = pending;\n\treturn debounced;\n};\n"],"mappings":"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","ignoreList":[]}
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/debounce/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Parts of this source were derived and modified from lodash,\n * released under the MIT license.\n *\n * https://github.com/lodash/lodash\n *\n * Copyright JS Foundation and other contributors <https://js.foundation/>\n *\n * Based on Underscore.js, copyright Jeremy Ashkenas,\n * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>\n *\n * This software consists of voluntary contributions made by many\n * individuals. For exact contribution history, see the revision history\n * available at https://github.com/lodash/lodash\n *\n * The following license applies to all parts of this software except as\n * documented below:\n *\n * ====\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\nexport interface DebounceOptions {\n\tleading: boolean;\n\tmaxWait: number;\n\ttrailing: boolean;\n}\n\nexport interface DebouncedFunc< T extends ( ...args: any[] ) => any > {\n\t/**\n\t * Call the original function, but applying the debounce rules.\n\t *\n\t * If the debounced function can be run immediately, this calls it and returns its return\n\t * value.\n\t *\n\t * Otherwise, it returns the return value of the last invocation, or undefined if the debounced\n\t * function was not invoked yet.\n\t */\n\t( ...args: Parameters< T > ): ReturnType< T > | undefined;\n\n\t/**\n\t * Throw away any pending invocation of the debounced function.\n\t */\n\tcancel: () => void;\n\n\t/**\n\t * If there is a pending invocation of the debounced function, invoke it immediately and return\n\t * its return value.\n\t *\n\t * Otherwise, return the value from the last invocation, or undefined if the debounced function\n\t * was never invoked.\n\t */\n\tflush: () => ReturnType< T > | undefined;\n}\n\n/**\n * A simplified and properly typed version of lodash's `debounce`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a debounced function that delays invoking `func` until after `wait`\n * milliseconds have elapsed since the last time the debounced function was\n * invoked. The debounced function comes with a `cancel` method to cancel delayed\n * `func` invocations and a `flush` method to immediately invoke them. Provide\n * `options` to indicate whether `func` should be invoked on the leading and/or\n * trailing edge of the `wait` timeout. The `func` is invoked with the last\n * arguments provided to the debounced function. Subsequent calls to the debounced\n * function return the result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the debounced function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * @param {Function} func The function to debounce.\n * @param {number} wait The number of milliseconds to delay.\n * @param {Partial< DebounceOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {number} options.maxWait The maximum time `func` is allowed to be delayed before it's invoked.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n *\n * @return Returns the new debounced function.\n */\nexport const debounce = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: Partial< DebounceOptions >\n) => {\n\tlet lastArgs: Parameters< FunctionT > | undefined;\n\tlet lastThis: unknown | undefined;\n\tlet maxWait = 0;\n\tlet result: ReturnType< FunctionT >;\n\tlet timerId: ReturnType< typeof setTimeout > | undefined;\n\tlet lastCallTime: number | undefined;\n\n\tlet lastInvokeTime = 0;\n\tlet leading = false;\n\tlet maxing = false;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = !! options.leading;\n\t\tmaxing = 'maxWait' in options;\n\t\tif ( options.maxWait !== undefined ) {\n\t\t\tmaxWait = Math.max( options.maxWait, wait );\n\t\t}\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\n\tfunction invokeFunc( time: number ) {\n\t\tconst args = lastArgs;\n\t\tconst thisArg = lastThis;\n\n\t\tlastArgs = undefined;\n\t\tlastThis = undefined;\n\t\tlastInvokeTime = time;\n\n\t\tresult = func.apply( thisArg, args! ) as ReturnType< FunctionT >;\n\t\treturn result;\n\t}\n\n\tfunction startTimer(\n\t\tpendingFunc: () => void,\n\t\twaitTime: number | undefined\n\t) {\n\t\ttimerId = setTimeout( pendingFunc, waitTime );\n\t}\n\n\tfunction cancelTimer() {\n\t\tif ( timerId !== undefined ) {\n\t\t\tclearTimeout( timerId );\n\t\t}\n\t}\n\n\tfunction leadingEdge( time: number ) {\n\t\t// Reset any `maxWait` timer.\n\t\tlastInvokeTime = time;\n\t\t// Start the timer for the trailing edge.\n\t\tstartTimer( timerExpired, wait );\n\t\t// Invoke the leading edge.\n\t\treturn leading ? invokeFunc( time ) : result;\n\t}\n\n\tfunction getTimeSinceLastCall( time: number ) {\n\t\treturn time - ( lastCallTime || 0 );\n\t}\n\n\tfunction remainingWait( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\t\tconst timeWaiting = wait - timeSinceLastCall;\n\n\t\treturn maxing\n\t\t\t? Math.min( timeWaiting, maxWait - timeSinceLastInvoke )\n\t\t\t: timeWaiting;\n\t}\n\n\tfunction shouldInvoke( time: number ) {\n\t\tconst timeSinceLastCall = getTimeSinceLastCall( time );\n\t\tconst timeSinceLastInvoke = time - lastInvokeTime;\n\n\t\t// Either this is the first call, activity has stopped and we're at the\n\t\t// trailing edge, the system time has gone backwards and we're treating\n\t\t// it as the trailing edge, or we've hit the `maxWait` limit.\n\t\treturn (\n\t\t\tlastCallTime === undefined ||\n\t\t\ttimeSinceLastCall >= wait ||\n\t\t\ttimeSinceLastCall < 0 ||\n\t\t\t( maxing && timeSinceLastInvoke >= maxWait )\n\t\t);\n\t}\n\n\tfunction timerExpired() {\n\t\tconst time = Date.now();\n\t\tif ( shouldInvoke( time ) ) {\n\t\t\treturn trailingEdge( time );\n\t\t}\n\t\t// Restart the timer.\n\t\tstartTimer( timerExpired, remainingWait( time ) );\n\t\treturn undefined;\n\t}\n\n\tfunction clearTimer() {\n\t\ttimerId = undefined;\n\t}\n\n\tfunction trailingEdge( time: number ) {\n\t\tclearTimer();\n\n\t\t// Only invoke if we have `lastArgs` which means `func` has been\n\t\t// debounced at least once.\n\t\tif ( trailing && lastArgs ) {\n\t\t\treturn invokeFunc( time );\n\t\t}\n\t\tlastArgs = lastThis = undefined;\n\t\treturn result;\n\t}\n\n\tfunction cancel() {\n\t\tcancelTimer();\n\t\tlastInvokeTime = 0;\n\t\tclearTimer();\n\t\tlastArgs = lastCallTime = lastThis = undefined;\n\t}\n\n\tfunction flush() {\n\t\treturn pending() ? trailingEdge( Date.now() ) : result;\n\t}\n\n\tfunction pending() {\n\t\treturn timerId !== undefined;\n\t}\n\n\tfunction debounced( this: unknown, ...args: Parameters< FunctionT > ) {\n\t\tconst time = Date.now();\n\t\tconst isInvoking = shouldInvoke( time );\n\n\t\tlastArgs = args;\n\t\tlastThis = this;\n\t\tlastCallTime = time;\n\n\t\tif ( isInvoking ) {\n\t\t\tif ( ! pending() ) {\n\t\t\t\treturn leadingEdge( lastCallTime );\n\t\t\t}\n\t\t\tif ( maxing ) {\n\t\t\t\t// Handle invocations in a tight loop.\n\t\t\t\tstartTimer( timerExpired, wait );\n\t\t\t\treturn invokeFunc( lastCallTime );\n\t\t\t}\n\t\t}\n\t\tif ( ! pending() ) {\n\t\t\tstartTimer( timerExpired, wait );\n\t\t}\n\t\treturn result;\n\t}\n\tdebounced.cancel = cancel;\n\tdebounced.flush = flush;\n\tdebounced.pending = pending;\n\treturn debounced;\n};\n"],
|
|
5
|
+
"mappings": "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",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,23 +1,29 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 observable_map_exports = {};
|
|
20
|
+
__export(observable_map_exports, {
|
|
21
|
+
observableMap: () => observableMap
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
/**
|
|
8
|
-
* A constructor (factory) for `ObservableMap`, a map-like key/value data structure
|
|
9
|
-
* where the individual entries are observable: using the `subscribe` method, you can
|
|
10
|
-
* subscribe to updates for a particular keys. Each subscriber always observes one
|
|
11
|
-
* specific key and is not notified about any unrelated changes (for different keys)
|
|
12
|
-
* in the `ObservableMap`.
|
|
13
|
-
*
|
|
14
|
-
* @template K The type of the keys in the map.
|
|
15
|
-
* @template V The type of the values in the map.
|
|
16
|
-
* @return A new instance of the `ObservableMap` type.
|
|
17
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(observable_map_exports);
|
|
18
24
|
function observableMap() {
|
|
19
|
-
const map = new Map();
|
|
20
|
-
const listeners = new Map();
|
|
25
|
+
const map = /* @__PURE__ */ new Map();
|
|
26
|
+
const listeners = /* @__PURE__ */ new Map();
|
|
21
27
|
function callListeners(name) {
|
|
22
28
|
const list = listeners.get(name);
|
|
23
29
|
if (!list) {
|
|
@@ -42,7 +48,7 @@ function observableMap() {
|
|
|
42
48
|
subscribe(name, listener) {
|
|
43
49
|
let list = listeners.get(name);
|
|
44
50
|
if (!list) {
|
|
45
|
-
list = new Set();
|
|
51
|
+
list = /* @__PURE__ */ new Set();
|
|
46
52
|
listeners.set(name, list);
|
|
47
53
|
}
|
|
48
54
|
list.add(listener);
|
|
@@ -55,4 +61,8 @@ function observableMap() {
|
|
|
55
61
|
}
|
|
56
62
|
};
|
|
57
63
|
}
|
|
58
|
-
|
|
64
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
65
|
+
0 && (module.exports = {
|
|
66
|
+
observableMap
|
|
67
|
+
});
|
|
68
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/observable-map/index.ts"],
|
|
4
|
+
"sourcesContent": ["export type ObservableMap< K, V > = {\n\tget: ( name: K ) => V | undefined;\n\tset: ( name: K, value: V ) => void;\n\tdelete: ( name: K ) => void;\n\tsubscribe: ( name: K, listener: () => void ) => () => void;\n};\n\n/**\n * A constructor (factory) for `ObservableMap`, a map-like key/value data structure\n * where the individual entries are observable: using the `subscribe` method, you can\n * subscribe to updates for a particular keys. Each subscriber always observes one\n * specific key and is not notified about any unrelated changes (for different keys)\n * in the `ObservableMap`.\n *\n * @template K The type of the keys in the map.\n * @template V The type of the values in the map.\n * @return A new instance of the `ObservableMap` type.\n */\nexport function observableMap< K, V >(): ObservableMap< K, V > {\n\tconst map = new Map< K, V >();\n\tconst listeners = new Map< K, Set< () => void > >();\n\n\tfunction callListeners( name: K ) {\n\t\tconst list = listeners.get( name );\n\t\tif ( ! list ) {\n\t\t\treturn;\n\t\t}\n\t\tfor ( const listener of list ) {\n\t\t\tlistener();\n\t\t}\n\t}\n\n\treturn {\n\t\tget( name ) {\n\t\t\treturn map.get( name );\n\t\t},\n\t\tset( name, value ) {\n\t\t\tmap.set( name, value );\n\t\t\tcallListeners( name );\n\t\t},\n\t\tdelete( name ) {\n\t\t\tmap.delete( name );\n\t\t\tcallListeners( name );\n\t\t},\n\t\tsubscribe( name, listener ) {\n\t\t\tlet list = listeners.get( name );\n\t\t\tif ( ! list ) {\n\t\t\t\tlist = new Set();\n\t\t\t\tlisteners.set( name, list );\n\t\t\t}\n\t\t\tlist.add( listener );\n\n\t\t\treturn () => {\n\t\t\t\tlist.delete( listener );\n\t\t\t\tif ( list.size === 0 ) {\n\t\t\t\t\tlisteners.delete( name );\n\t\t\t\t}\n\t\t\t};\n\t\t},\n\t};\n}\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAkBO,SAAS,gBAA+C;AAC9D,QAAM,MAAM,oBAAI,IAAY;AAC5B,QAAM,YAAY,oBAAI,IAA4B;AAElD,WAAS,cAAe,MAAU;AACjC,UAAM,OAAO,UAAU,IAAK,IAAK;AACjC,QAAK,CAAE,MAAO;AACb;AAAA,IACD;AACA,eAAY,YAAY,MAAO;AAC9B,eAAS;AAAA,IACV;AAAA,EACD;AAEA,SAAO;AAAA,IACN,IAAK,MAAO;AACX,aAAO,IAAI,IAAK,IAAK;AAAA,IACtB;AAAA,IACA,IAAK,MAAM,OAAQ;AAClB,UAAI,IAAK,MAAM,KAAM;AACrB,oBAAe,IAAK;AAAA,IACrB;AAAA,IACA,OAAQ,MAAO;AACd,UAAI,OAAQ,IAAK;AACjB,oBAAe,IAAK;AAAA,IACrB;AAAA,IACA,UAAW,MAAM,UAAW;AAC3B,UAAI,OAAO,UAAU,IAAK,IAAK;AAC/B,UAAK,CAAE,MAAO;AACb,eAAO,oBAAI,IAAI;AACf,kBAAU,IAAK,MAAM,IAAK;AAAA,MAC3B;AACA,WAAK,IAAK,QAAS;AAEnB,aAAO,MAAM;AACZ,aAAK,OAAQ,QAAS;AACtB,YAAK,KAAK,SAAS,GAAI;AACtB,oBAAU,OAAQ,IAAK;AAAA,QACxB;AAAA,MACD;AAAA,IACD;AAAA,EACD;AACD;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,93 +1,42 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.
|
|
4
|
-
|
|
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 throttle_exports = {};
|
|
20
|
+
__export(throttle_exports, {
|
|
21
|
+
throttle: () => throttle
|
|
5
22
|
});
|
|
6
|
-
exports
|
|
7
|
-
var
|
|
8
|
-
/**
|
|
9
|
-
* Parts of this source were derived and modified from lodash,
|
|
10
|
-
* released under the MIT license.
|
|
11
|
-
*
|
|
12
|
-
* https://github.com/lodash/lodash
|
|
13
|
-
*
|
|
14
|
-
* Copyright JS Foundation and other contributors <https://js.foundation/>
|
|
15
|
-
*
|
|
16
|
-
* Based on Underscore.js, copyright Jeremy Ashkenas,
|
|
17
|
-
* DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>
|
|
18
|
-
*
|
|
19
|
-
* This software consists of voluntary contributions made by many
|
|
20
|
-
* individuals. For exact contribution history, see the revision history
|
|
21
|
-
* available at https://github.com/lodash/lodash
|
|
22
|
-
*
|
|
23
|
-
* The following license applies to all parts of this software except as
|
|
24
|
-
* documented below:
|
|
25
|
-
*
|
|
26
|
-
* ====
|
|
27
|
-
*
|
|
28
|
-
* Permission is hereby granted, free of charge, to any person obtaining
|
|
29
|
-
* a copy of this software and associated documentation files (the
|
|
30
|
-
* "Software"), to deal in the Software without restriction, including
|
|
31
|
-
* without limitation the rights to use, copy, modify, merge, publish,
|
|
32
|
-
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
33
|
-
* permit persons to whom the Software is furnished to do so, subject to
|
|
34
|
-
* the following conditions:
|
|
35
|
-
*
|
|
36
|
-
* The above copyright notice and this permission notice shall be
|
|
37
|
-
* included in all copies or substantial portions of the Software.
|
|
38
|
-
*
|
|
39
|
-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
40
|
-
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
41
|
-
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
|
42
|
-
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
|
43
|
-
* LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
|
44
|
-
* OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
|
45
|
-
* WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
|
46
|
-
*/
|
|
47
|
-
|
|
48
|
-
/**
|
|
49
|
-
* Internal dependencies
|
|
50
|
-
*/
|
|
51
|
-
|
|
52
|
-
/**
|
|
53
|
-
* A simplified and properly typed version of lodash's `throttle`, that
|
|
54
|
-
* always uses timers instead of sometimes using rAF.
|
|
55
|
-
*
|
|
56
|
-
* Creates a throttled function that only invokes `func` at most once per
|
|
57
|
-
* every `wait` milliseconds. The throttled function comes with a `cancel`
|
|
58
|
-
* method to cancel delayed `func` invocations and a `flush` method to
|
|
59
|
-
* immediately invoke them. Provide `options` to indicate whether `func`
|
|
60
|
-
* should be invoked on the leading and/or trailing edge of the `wait`
|
|
61
|
-
* timeout. The `func` is invoked with the last arguments provided to the
|
|
62
|
-
* throttled function. Subsequent calls to the throttled function return
|
|
63
|
-
* the result of the last `func` invocation.
|
|
64
|
-
*
|
|
65
|
-
* **Note:** If `leading` and `trailing` options are `true`, `func` is
|
|
66
|
-
* invoked on the trailing edge of the timeout only if the throttled function
|
|
67
|
-
* is invoked more than once during the `wait` timeout.
|
|
68
|
-
*
|
|
69
|
-
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred
|
|
70
|
-
* until the next tick, similar to `setTimeout` with a timeout of `0`.
|
|
71
|
-
*
|
|
72
|
-
* @param {Function} func The function to throttle.
|
|
73
|
-
* @param {number} wait The number of milliseconds to throttle invocations to.
|
|
74
|
-
* @param {Partial< ThrottleOptions >} options The options object.
|
|
75
|
-
* @param {boolean} options.leading Specify invoking on the leading edge of the timeout.
|
|
76
|
-
* @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.
|
|
77
|
-
* @return Returns the new throttled function.
|
|
78
|
-
*/
|
|
23
|
+
module.exports = __toCommonJS(throttle_exports);
|
|
24
|
+
var import_debounce = require("../debounce");
|
|
79
25
|
const throttle = (func, wait, options) => {
|
|
80
26
|
let leading = true;
|
|
81
27
|
let trailing = true;
|
|
82
28
|
if (options) {
|
|
83
|
-
leading =
|
|
84
|
-
trailing =
|
|
29
|
+
leading = "leading" in options ? !!options.leading : leading;
|
|
30
|
+
trailing = "trailing" in options ? !!options.trailing : trailing;
|
|
85
31
|
}
|
|
86
|
-
return (0,
|
|
32
|
+
return (0, import_debounce.debounce)(func, wait, {
|
|
87
33
|
leading,
|
|
88
34
|
trailing,
|
|
89
35
|
maxWait: wait
|
|
90
36
|
});
|
|
91
37
|
};
|
|
92
|
-
|
|
93
|
-
|
|
38
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
39
|
+
0 && (module.exports = {
|
|
40
|
+
throttle
|
|
41
|
+
});
|
|
42
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/utils/throttle/index.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Parts of this source were derived and modified from lodash,\n * released under the MIT license.\n *\n * https://github.com/lodash/lodash\n *\n * Copyright JS Foundation and other contributors <https://js.foundation/>\n *\n * Based on Underscore.js, copyright Jeremy Ashkenas,\n * DocumentCloud and Investigative Reporters & Editors <http://underscorejs.org/>\n *\n * This software consists of voluntary contributions made by many\n * individuals. For exact contribution history, see the revision history\n * available at https://github.com/lodash/lodash\n *\n * The following license applies to all parts of this software except as\n * documented below:\n *\n * ====\n *\n * Permission is hereby granted, free of charge, to any person obtaining\n * a copy of this software and associated documentation files (the\n * \"Software\"), to deal in the Software without restriction, including\n * without limitation the rights to use, copy, modify, merge, publish,\n * distribute, sublicense, and/or sell copies of the Software, and to\n * permit persons to whom the Software is furnished to do so, subject to\n * the following conditions:\n *\n * The above copyright notice and this permission notice shall be\n * included in all copies or substantial portions of the Software.\n *\n * THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\n * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\n * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\n * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\n * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\n * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\n * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\n */\n\n/**\n * Internal dependencies\n */\nimport { debounce } from '../debounce';\n\nexport interface ThrottleOptions {\n\tleading?: boolean;\n\ttrailing?: boolean;\n}\n\n/**\n * A simplified and properly typed version of lodash's `throttle`, that\n * always uses timers instead of sometimes using rAF.\n *\n * Creates a throttled function that only invokes `func` at most once per\n * every `wait` milliseconds. The throttled function comes with a `cancel`\n * method to cancel delayed `func` invocations and a `flush` method to\n * immediately invoke them. Provide `options` to indicate whether `func`\n * should be invoked on the leading and/or trailing edge of the `wait`\n * timeout. The `func` is invoked with the last arguments provided to the\n * throttled function. Subsequent calls to the throttled function return\n * the result of the last `func` invocation.\n *\n * **Note:** If `leading` and `trailing` options are `true`, `func` is\n * invoked on the trailing edge of the timeout only if the throttled function\n * is invoked more than once during the `wait` timeout.\n *\n * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred\n * until the next tick, similar to `setTimeout` with a timeout of `0`.\n *\n * @param {Function} func The function to throttle.\n * @param {number} wait The number of milliseconds to throttle invocations to.\n * @param {Partial< ThrottleOptions >} options The options object.\n * @param {boolean} options.leading Specify invoking on the leading edge of the timeout.\n * @param {boolean} options.trailing Specify invoking on the trailing edge of the timeout.\n * @return Returns the new throttled function.\n */\nexport const throttle = < FunctionT extends ( ...args: unknown[] ) => unknown >(\n\tfunc: FunctionT,\n\twait: number,\n\toptions?: ThrottleOptions\n) => {\n\tlet leading = true;\n\tlet trailing = true;\n\n\tif ( options ) {\n\t\tleading = 'leading' in options ? !! options.leading : leading;\n\t\ttrailing = 'trailing' in options ? !! options.trailing : trailing;\n\t}\n\treturn debounce( func, wait, {\n\t\tleading,\n\t\ttrailing,\n\t\tmaxWait: wait,\n\t} );\n};\n"],
|
|
5
|
+
"mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AA2CA,sBAAyB;AAkClB,MAAM,WAAW,CACvB,MACA,MACA,YACI;AACJ,MAAI,UAAU;AACd,MAAI,WAAW;AAEf,MAAK,SAAU;AACd,cAAU,aAAa,UAAU,CAAC,CAAE,QAAQ,UAAU;AACtD,eAAW,cAAc,UAAU,CAAC,CAAE,QAAQ,WAAW;AAAA,EAC1D;AACA,aAAO,0BAAU,MAAM,MAAM;AAAA,IAC5B;AAAA,IACA;AAAA,IACA,SAAS;AAAA,EACV,CAAE;AACH;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
* Internal dependencies
|
|
3
|
-
*/
|
|
4
|
-
import { basePipe } from './pipe';
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
|
|
8
|
-
* composition, where each successive invocation is supplied the return value of the previous.
|
|
9
|
-
*
|
|
10
|
-
* This is inspired by `lodash`'s `flowRight` function.
|
|
11
|
-
*
|
|
12
|
-
* @see https://lodash.com/docs/4#flow-right
|
|
13
|
-
*/
|
|
1
|
+
import { basePipe } from "./pipe";
|
|
14
2
|
const compose = basePipe(true);
|
|
15
|
-
|
|
16
|
-
|
|
3
|
+
var compose_default = compose;
|
|
4
|
+
export {
|
|
5
|
+
compose_default as default
|
|
6
|
+
};
|
|
7
|
+
//# sourceMappingURL=compose.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../src/higher-order/compose.ts"],
|
|
4
|
+
"sourcesContent": ["/**\n * Internal dependencies\n */\nimport { basePipe } from './pipe';\n\n/**\n * Composes multiple higher-order components into a single higher-order component. Performs right-to-left function\n * composition, where each successive invocation is supplied the return value of the previous.\n *\n * This is inspired by `lodash`'s `flowRight` function.\n *\n * @see https://lodash.com/docs/4#flow-right\n */\nconst compose = basePipe( true );\n\nexport default compose;\n"],
|
|
5
|
+
"mappings": "AAGA,SAAS,gBAAgB;AAUzB,MAAM,UAAU,SAAU,IAAK;AAE/B,IAAO,kBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|
|
@@ -1,39 +1,18 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* Internal dependencies
|
|
7
|
-
*/
|
|
8
|
-
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* Higher-order component creator, creating a new component which renders if
|
|
12
|
-
* the given condition is satisfied or with the given optional prop name.
|
|
13
|
-
*
|
|
14
|
-
* @example
|
|
15
|
-
* ```ts
|
|
16
|
-
* type Props = { foo: string };
|
|
17
|
-
* const Component = ( props: Props ) => <div>{ props.foo }</div>;
|
|
18
|
-
* const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );
|
|
19
|
-
* <ConditionalComponent foo="" />; // => null
|
|
20
|
-
* <ConditionalComponent foo="bar" />; // => <div>bar</div>;
|
|
21
|
-
* ```
|
|
22
|
-
*
|
|
23
|
-
* @param predicate Function to test condition.
|
|
24
|
-
*
|
|
25
|
-
* @return Higher-order component.
|
|
26
|
-
*/
|
|
27
|
-
import { jsx as _jsx } from "react/jsx-runtime";
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { createHigherOrderComponent } from "../../utils/create-higher-order-component";
|
|
28
3
|
function ifCondition(predicate) {
|
|
29
|
-
return createHigherOrderComponent(
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
...props
|
|
35
|
-
}
|
|
36
|
-
|
|
4
|
+
return createHigherOrderComponent(
|
|
5
|
+
(WrappedComponent) => (props) => {
|
|
6
|
+
if (!predicate(props)) {
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
return /* @__PURE__ */ jsx(WrappedComponent, { ...props });
|
|
10
|
+
},
|
|
11
|
+
"ifCondition"
|
|
12
|
+
);
|
|
37
13
|
}
|
|
38
|
-
|
|
39
|
-
|
|
14
|
+
var if_condition_default = ifCondition;
|
|
15
|
+
export {
|
|
16
|
+
if_condition_default as default
|
|
17
|
+
};
|
|
18
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
{
|
|
1
|
+
{
|
|
2
|
+
"version": 3,
|
|
3
|
+
"sources": ["../../../src/higher-order/if-condition/index.tsx"],
|
|
4
|
+
"sourcesContent": ["/**\n * External dependencies\n */\nimport type { ComponentType } from 'react';\n\n/**\n * Internal dependencies\n */\nimport { createHigherOrderComponent } from '../../utils/create-higher-order-component';\n\n/**\n * Higher-order component creator, creating a new component which renders if\n * the given condition is satisfied or with the given optional prop name.\n *\n * @example\n * ```ts\n * type Props = { foo: string };\n * const Component = ( props: Props ) => <div>{ props.foo }</div>;\n * const ConditionalComponent = ifCondition( ( props: Props ) => props.foo.length !== 0 )( Component );\n * <ConditionalComponent foo=\"\" />; // => null\n * <ConditionalComponent foo=\"bar\" />; // => <div>bar</div>;\n * ```\n *\n * @param predicate Function to test condition.\n *\n * @return Higher-order component.\n */\nfunction ifCondition< Props extends {} >(\n\tpredicate: ( props: Props ) => boolean\n) {\n\treturn createHigherOrderComponent(\n\t\t( WrappedComponent: ComponentType< Props > ) => ( props: Props ) => {\n\t\t\tif ( ! predicate( props ) ) {\n\t\t\t\treturn null;\n\t\t\t}\n\n\t\t\treturn <WrappedComponent { ...props } />;\n\t\t},\n\t\t'ifCondition'\n\t);\n}\n\nexport default ifCondition;\n"],
|
|
5
|
+
"mappings": "AAoCU;AA5BV,SAAS,kCAAkC;AAmB3C,SAAS,YACR,WACC;AACD,SAAO;AAAA,IACN,CAAE,qBAA8C,CAAE,UAAkB;AACnE,UAAK,CAAE,UAAW,KAAM,GAAI;AAC3B,eAAO;AAAA,MACR;AAEA,aAAO,oBAAC,oBAAmB,GAAG,OAAQ;AAAA,IACvC;AAAA,IACA;AAAA,EACD;AACD;AAEA,IAAO,uBAAQ;",
|
|
6
|
+
"names": []
|
|
7
|
+
}
|