@wordpress/compose 6.16.0 → 6.17.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 +0 -2
- package/build/higher-order/compose.js.map +1 -1
- package/build/higher-order/if-condition/index.js +2 -6
- package/build/higher-order/if-condition/index.js.map +1 -1
- package/build/higher-order/pipe.js +1 -5
- package/build/higher-order/pipe.js.map +1 -1
- package/build/higher-order/pure/index.js +2 -10
- package/build/higher-order/pure/index.js.map +1 -1
- package/build/higher-order/with-global-events/index.js +13 -32
- package/build/higher-order/with-global-events/index.js.map +1 -1
- package/build/higher-order/with-global-events/listener.js +5 -28
- package/build/higher-order/with-global-events/listener.js.map +1 -1
- package/build/higher-order/with-instance-id/index.js +4 -8
- package/build/higher-order/with-instance-id/index.js.map +1 -1
- package/build/higher-order/with-preferred-color-scheme/index.native.js +3 -6
- package/build/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build/higher-order/with-safe-timeout/index.js +4 -14
- package/build/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build/higher-order/with-state/index.js +3 -11
- package/build/higher-order/with-state/index.js.map +1 -1
- package/build/hooks/use-async-list/index.js +1 -14
- package/build/hooks/use-async-list/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.js +14 -30
- package/build/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build/hooks/use-constrained-tabbing/index.native.js +4 -4
- package/build/hooks/use-constrained-tabbing/index.native.js.map +1 -1
- package/build/hooks/use-copy-on-click/index.js +6 -15
- package/build/hooks/use-copy-on-click/index.js.map +1 -1
- package/build/hooks/use-copy-to-clipboard/index.js +3 -11
- package/build/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build/hooks/use-debounce/index.js +0 -4
- package/build/hooks/use-debounce/index.js.map +1 -1
- package/build/hooks/use-dialog/index.js +2 -12
- package/build/hooks/use-dialog/index.js.map +1 -1
- package/build/hooks/use-disabled/index.js +5 -15
- package/build/hooks/use-disabled/index.js.map +1 -1
- package/build/hooks/use-dragging/index.js +4 -11
- package/build/hooks/use-dragging/index.js.map +1 -1
- package/build/hooks/use-drop-zone/index.js +27 -66
- package/build/hooks/use-drop-zone/index.js.map +1 -1
- package/build/hooks/use-fixed-window-list/index.js +8 -34
- package/build/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build/hooks/use-focus-on-mount/index.js +3 -14
- package/build/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.js +13 -19
- package/build/hooks/use-focus-outside/index.js.map +1 -1
- package/build/hooks/use-focus-outside/index.native.js +13 -21
- package/build/hooks/use-focus-outside/index.native.js.map +1 -1
- package/build/hooks/use-focus-return/index.js +7 -15
- package/build/hooks/use-focus-return/index.js.map +1 -1
- package/build/hooks/use-focusable-iframe/index.js +1 -5
- package/build/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build/hooks/use-instance-id/index.js +3 -5
- package/build/hooks/use-instance-id/index.js.map +1 -1
- package/build/hooks/use-isomorphic-layout-effect/index.js +0 -2
- package/build/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.js +12 -28
- package/build/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build/hooks/use-keyboard-shortcut/index.native.js +0 -2
- package/build/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
- package/build/hooks/use-media-query/index.js +1 -9
- package/build/hooks/use-media-query/index.js.map +1 -1
- package/build/hooks/use-merge-refs/index.js +18 -24
- package/build/hooks/use-merge-refs/index.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.android.js +0 -5
- package/build/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme/index.ios.js +0 -2
- package/build/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
- package/build/hooks/use-preferred-color-scheme-style/index.native.js +2 -5
- package/build/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
- package/build/hooks/use-previous/index.js +3 -4
- package/build/hooks/use-previous/index.js.map +1 -1
- package/build/hooks/use-reduced-motion/index.js +0 -4
- package/build/hooks/use-reduced-motion/index.js.map +1 -1
- package/build/hooks/use-ref-effect/index.js +0 -2
- package/build/hooks/use-ref-effect/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.js +23 -30
- package/build/hooks/use-resize-observer/index.js.map +1 -1
- package/build/hooks/use-resize-observer/index.native.js +0 -6
- package/build/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build/hooks/use-throttle/index.js +0 -4
- package/build/hooks/use-throttle/index.js.map +1 -1
- package/build/hooks/use-viewport-match/index.js +4 -13
- package/build/hooks/use-viewport-match/index.js.map +1 -1
- package/build/hooks/use-warn-on-change/index.js +4 -14
- package/build/hooks/use-warn-on-change/index.js.map +1 -1
- package/build/index.js +0 -41
- package/build/index.js.map +1 -1
- package/build/index.native.js +0 -33
- package/build/index.native.js.map +1 -1
- package/build/utils/create-higher-order-component/index.js +1 -4
- package/build/utils/create-higher-order-component/index.js.map +1 -1
- package/build/utils/debounce/index.js +12 -37
- package/build/utils/debounce/index.js.map +1 -1
- package/build/utils/throttle/index.js +0 -5
- package/build/utils/throttle/index.js.map +1 -1
- package/build-module/higher-order/compose.js +1 -1
- package/build-module/higher-order/compose.js.map +1 -1
- package/build-module/higher-order/if-condition/index.js +3 -5
- package/build-module/higher-order/if-condition/index.js.map +1 -1
- package/build-module/higher-order/pipe.js +1 -4
- package/build-module/higher-order/pipe.js.map +1 -1
- package/build-module/higher-order/pure/index.js +4 -8
- package/build-module/higher-order/pure/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/index.js +15 -29
- package/build-module/higher-order/with-global-events/index.js.map +1 -1
- package/build-module/higher-order/with-global-events/listener.js +5 -27
- package/build-module/higher-order/with-global-events/listener.js.map +1 -1
- package/build-module/higher-order/with-instance-id/index.js +5 -5
- package/build-module/higher-order/with-instance-id/index.js.map +1 -1
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js +3 -3
- package/build-module/higher-order/with-preferred-color-scheme/index.native.js.map +1 -1
- package/build-module/higher-order/with-safe-timeout/index.js +6 -8
- package/build-module/higher-order/with-safe-timeout/index.js.map +1 -1
- package/build-module/higher-order/with-state/index.js +5 -9
- package/build-module/higher-order/with-state/index.js.map +1 -1
- package/build-module/hooks/use-async-list/index.js +1 -12
- package/build-module/hooks/use-async-list/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.js +16 -27
- package/build-module/hooks/use-constrained-tabbing/index.js.map +1 -1
- package/build-module/hooks/use-constrained-tabbing/index.native.js +3 -3
- package/build-module/hooks/use-constrained-tabbing/index.native.js.map +1 -1
- package/build-module/hooks/use-copy-on-click/index.js +8 -12
- package/build-module/hooks/use-copy-on-click/index.js.map +1 -1
- package/build-module/hooks/use-copy-to-clipboard/index.js +6 -9
- package/build-module/hooks/use-copy-to-clipboard/index.js.map +1 -1
- package/build-module/hooks/use-debounce/index.js +3 -3
- package/build-module/hooks/use-debounce/index.js.map +1 -1
- package/build-module/hooks/use-dialog/index.js +3 -5
- package/build-module/hooks/use-dialog/index.js.map +1 -1
- package/build-module/hooks/use-disabled/index.js +6 -12
- package/build-module/hooks/use-disabled/index.js.map +1 -1
- package/build-module/hooks/use-dragging/index.js +6 -9
- package/build-module/hooks/use-dragging/index.js.map +1 -1
- package/build-module/hooks/use-drop-zone/index.js +29 -64
- package/build-module/hooks/use-drop-zone/index.js.map +1 -1
- package/build-module/hooks/use-fixed-window-list/index.js +8 -30
- package/build-module/hooks/use-fixed-window-list/index.js.map +1 -1
- package/build-module/hooks/use-focus-on-mount/index.js +4 -12
- package/build-module/hooks/use-focus-on-mount/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.js +14 -18
- package/build-module/hooks/use-focus-outside/index.js.map +1 -1
- package/build-module/hooks/use-focus-outside/index.native.js +14 -20
- package/build-module/hooks/use-focus-outside/index.native.js.map +1 -1
- package/build-module/hooks/use-focus-return/index.js +8 -14
- package/build-module/hooks/use-focus-return/index.js.map +1 -1
- package/build-module/hooks/use-focusable-iframe/index.js +2 -3
- package/build-module/hooks/use-focusable-iframe/index.js.map +1 -1
- package/build-module/hooks/use-instance-id/index.js +2 -3
- package/build-module/hooks/use-instance-id/index.js.map +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js +1 -1
- package/build-module/hooks/use-isomorphic-layout-effect/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.js +14 -24
- package/build-module/hooks/use-keyboard-shortcut/index.js.map +1 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js +0 -1
- package/build-module/hooks/use-keyboard-shortcut/index.native.js.map +1 -1
- package/build-module/hooks/use-media-query/index.js +2 -8
- package/build-module/hooks/use-media-query/index.js.map +1 -1
- package/build-module/hooks/use-merge-refs/index.js +19 -23
- package/build-module/hooks/use-merge-refs/index.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.android.js +1 -3
- package/build-module/hooks/use-preferred-color-scheme/index.android.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js +1 -1
- package/build-module/hooks/use-preferred-color-scheme/index.ios.js.map +1 -1
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js +3 -3
- package/build-module/hooks/use-preferred-color-scheme-style/index.native.js.map +1 -1
- package/build-module/hooks/use-previous/index.js +4 -3
- package/build-module/hooks/use-previous/index.js.map +1 -1
- package/build-module/hooks/use-reduced-motion/index.js +1 -2
- package/build-module/hooks/use-reduced-motion/index.js.map +1 -1
- package/build-module/hooks/use-ref-effect/index.js +1 -1
- package/build-module/hooks/use-ref-effect/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.js +22 -30
- package/build-module/hooks/use-resize-observer/index.js.map +1 -1
- package/build-module/hooks/use-resize-observer/index.native.js +1 -6
- package/build-module/hooks/use-resize-observer/index.native.js.map +1 -1
- package/build-module/hooks/use-throttle/index.js +3 -3
- package/build-module/hooks/use-throttle/index.js.map +1 -1
- package/build-module/hooks/use-viewport-match/index.js +6 -11
- package/build-module/hooks/use-viewport-match/index.js.map +1 -1
- package/build-module/hooks/use-warn-on-change/index.js +6 -12
- package/build-module/hooks/use-warn-on-change/index.js.map +1 -1
- package/build-module/index.js +10 -7
- package/build-module/index.js.map +1 -1
- package/build-module/index.native.js +10 -7
- package/build-module/index.native.js.map +1 -1
- package/build-module/utils/create-higher-order-component/index.js +1 -2
- package/build-module/utils/create-higher-order-component/index.js.map +1 -1
- package/build-module/utils/debounce/index.js +12 -35
- package/build-module/utils/debounce/index.js.map +1 -1
- package/build-module/utils/throttle/index.js +0 -3
- package/build-module/utils/throttle/index.js.map +1 -1
- package/build-types/higher-order/with-instance-id/index.d.ts +1 -1
- package/build-types/higher-order/with-instance-id/index.d.ts.map +1 -1
- package/build-types/higher-order/with-safe-timeout/index.d.ts +1 -1
- package/build-types/higher-order/with-safe-timeout/index.d.ts.map +1 -1
- package/build-types/hooks/use-disabled/index.d.ts +1 -1
- package/build-types/hooks/use-disabled/index.d.ts.map +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts +1 -1
- package/build-types/hooks/use-isomorphic-layout-effect/index.d.ts.map +1 -1
- package/build-types/hooks/use-viewport-match/index.d.ts +1 -1
- package/package.json +8 -8
- package/src/higher-order/with-instance-id/index.tsx +2 -2
- package/src/higher-order/with-safe-timeout/index.tsx +2 -2
- package/src/hooks/use-resize-observer/index.native.js +0 -1
- package/tsconfig.tsbuildinfo +1 -1
package/build/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/index.js"],"
|
|
1
|
+
{"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_useConstrainedTabbing","_useCopyOnClick","_useCopyToClipboard","_useDialog","_useDisabled","_useDragging","_useFocusOnMount","_useFocusOutside","_useFocusReturn","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useViewportMatch","_useResizeObserver","_useAsyncList","_useWarnOnChange","_useDebounce","_useThrottle","_useMergeRefs","_useRefEffect","_useDropZone","_useFocusableIframe","_useFixedWindowList"],"sources":["@wordpress/compose/src/index.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as useCopyOnClick } from './hooks/use-copy-on-click';\nexport { default as useCopyToClipboard } from './hooks/use-copy-to-clipboard';\nexport { default as __experimentalUseDialog } from './hooks/use-dialog';\nexport { default as useDisabled } from './hooks/use-disabled';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as useFocusOnMount } from './hooks/use-focus-on-mount';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useFocusReturn } from './hooks/use-focus-return';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useAsyncList } from './hooks/use-async-list';\nexport { default as useWarnOnChange } from './hooks/use-warn-on-change';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\nexport { default as __experimentalUseDropZone } from './hooks/use-drop-zone';\nexport { default as useFocusableIframe } from './hooks/use-focusable-iframe';\nexport { default as __experimentalUseFixedWindowList } from './hooks/use-fixed-window-list';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA,IAAAA,2BAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,2BAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAC,YAAA,EAAAJ,GAAA;EAAA,IAAAA,GAAA,IAAAK,OAAA,IAAAA,OAAA,CAAAL,GAAA,MAAAL,2BAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAS,cAAA,CAAAD,OAAA,EAAAL,GAAA;IAAAO,UAAA;IAAAC,GAAA,WAAAA,CAAA;MAAA,OAAAb,2BAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AAEA,IAAAS,SAAA,GA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BAAA,GAAAhC,sBAAA,CAAAhB,OAAA;AACA,IAAAiD,mBAAA,GAAAjC,sBAAA,CAAAhB,OAAA"}
|
package/build/index.native.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
@@ -189,9 +188,7 @@ Object.defineProperty(exports, "withState", {
|
|
|
189
188
|
return _withState.default;
|
|
190
189
|
}
|
|
191
190
|
});
|
|
192
|
-
|
|
193
191
|
var _createHigherOrderComponent = require("./utils/create-higher-order-component");
|
|
194
|
-
|
|
195
192
|
Object.keys(_createHigherOrderComponent).forEach(function (key) {
|
|
196
193
|
if (key === "default" || key === "__esModule") return;
|
|
197
194
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -203,9 +200,7 @@ Object.keys(_createHigherOrderComponent).forEach(function (key) {
|
|
|
203
200
|
}
|
|
204
201
|
});
|
|
205
202
|
});
|
|
206
|
-
|
|
207
203
|
var _debounce = require("./utils/debounce");
|
|
208
|
-
|
|
209
204
|
Object.keys(_debounce).forEach(function (key) {
|
|
210
205
|
if (key === "default" || key === "__esModule") return;
|
|
211
206
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -217,9 +212,7 @@ Object.keys(_debounce).forEach(function (key) {
|
|
|
217
212
|
}
|
|
218
213
|
});
|
|
219
214
|
});
|
|
220
|
-
|
|
221
215
|
var _throttle = require("./utils/throttle");
|
|
222
|
-
|
|
223
216
|
Object.keys(_throttle).forEach(function (key) {
|
|
224
217
|
if (key === "default" || key === "__esModule") return;
|
|
225
218
|
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
|
|
@@ -231,56 +224,30 @@ Object.keys(_throttle).forEach(function (key) {
|
|
|
231
224
|
}
|
|
232
225
|
});
|
|
233
226
|
});
|
|
234
|
-
|
|
235
227
|
var _compose = _interopRequireDefault(require("./higher-order/compose"));
|
|
236
|
-
|
|
237
228
|
var _pipe = _interopRequireDefault(require("./higher-order/pipe"));
|
|
238
|
-
|
|
239
229
|
var _ifCondition = _interopRequireDefault(require("./higher-order/if-condition"));
|
|
240
|
-
|
|
241
230
|
var _pure = _interopRequireDefault(require("./higher-order/pure"));
|
|
242
|
-
|
|
243
231
|
var _withGlobalEvents = _interopRequireDefault(require("./higher-order/with-global-events"));
|
|
244
|
-
|
|
245
232
|
var _withInstanceId = _interopRequireDefault(require("./higher-order/with-instance-id"));
|
|
246
|
-
|
|
247
233
|
var _withSafeTimeout = _interopRequireDefault(require("./higher-order/with-safe-timeout"));
|
|
248
|
-
|
|
249
234
|
var _withState = _interopRequireDefault(require("./higher-order/with-state"));
|
|
250
|
-
|
|
251
235
|
var _withPreferredColorScheme = _interopRequireDefault(require("./higher-order/with-preferred-color-scheme"));
|
|
252
|
-
|
|
253
236
|
var _useConstrainedTabbing = _interopRequireDefault(require("./hooks/use-constrained-tabbing"));
|
|
254
|
-
|
|
255
237
|
var _useDragging = _interopRequireDefault(require("./hooks/use-dragging"));
|
|
256
|
-
|
|
257
238
|
var _useFocusOutside = _interopRequireDefault(require("./hooks/use-focus-outside"));
|
|
258
|
-
|
|
259
239
|
var _useInstanceId = _interopRequireDefault(require("./hooks/use-instance-id"));
|
|
260
|
-
|
|
261
240
|
var _useIsomorphicLayoutEffect = _interopRequireDefault(require("./hooks/use-isomorphic-layout-effect"));
|
|
262
|
-
|
|
263
241
|
var _useKeyboardShortcut = _interopRequireDefault(require("./hooks/use-keyboard-shortcut"));
|
|
264
|
-
|
|
265
242
|
var _useMediaQuery = _interopRequireDefault(require("./hooks/use-media-query"));
|
|
266
|
-
|
|
267
243
|
var _usePrevious = _interopRequireDefault(require("./hooks/use-previous"));
|
|
268
|
-
|
|
269
244
|
var _useReducedMotion = _interopRequireDefault(require("./hooks/use-reduced-motion"));
|
|
270
|
-
|
|
271
245
|
var _useViewportMatch = _interopRequireDefault(require("./hooks/use-viewport-match"));
|
|
272
|
-
|
|
273
246
|
var _usePreferredColorScheme = _interopRequireDefault(require("./hooks/use-preferred-color-scheme"));
|
|
274
|
-
|
|
275
247
|
var _usePreferredColorSchemeStyle = _interopRequireDefault(require("./hooks/use-preferred-color-scheme-style"));
|
|
276
|
-
|
|
277
248
|
var _useResizeObserver = _interopRequireDefault(require("./hooks/use-resize-observer"));
|
|
278
|
-
|
|
279
249
|
var _useDebounce = _interopRequireDefault(require("./hooks/use-debounce"));
|
|
280
|
-
|
|
281
250
|
var _useThrottle = _interopRequireDefault(require("./hooks/use-throttle"));
|
|
282
|
-
|
|
283
251
|
var _useMergeRefs = _interopRequireDefault(require("./hooks/use-merge-refs"));
|
|
284
|
-
|
|
285
252
|
var _useRefEffect = _interopRequireDefault(require("./hooks/use-ref-effect"));
|
|
286
253
|
//# sourceMappingURL=index.native.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/index.native.js"],"
|
|
1
|
+
{"version":3,"names":["_createHigherOrderComponent","require","Object","keys","forEach","key","prototype","hasOwnProperty","call","_exportNames","exports","defineProperty","enumerable","get","_debounce","_throttle","_compose","_interopRequireDefault","_pipe","_ifCondition","_pure","_withGlobalEvents","_withInstanceId","_withSafeTimeout","_withState","_withPreferredColorScheme","_useConstrainedTabbing","_useDragging","_useFocusOutside","_useInstanceId","_useIsomorphicLayoutEffect","_useKeyboardShortcut","_useMediaQuery","_usePrevious","_useReducedMotion","_useViewportMatch","_usePreferredColorScheme","_usePreferredColorSchemeStyle","_useResizeObserver","_useDebounce","_useThrottle","_useMergeRefs","_useRefEffect"],"sources":["@wordpress/compose/src/index.native.js"],"sourcesContent":["// The `createHigherOrderComponent` helper and helper types.\nexport * from './utils/create-higher-order-component';\n// The `debounce` helper and its types.\nexport * from './utils/debounce';\n// The `throttle` helper and its types.\nexport * from './utils/throttle';\n\n// The `compose` and `pipe` helpers (inspired by `flowRight` and `flow` from Lodash).\nexport { default as compose } from './higher-order/compose';\nexport { default as pipe } from './higher-order/pipe';\n\n// Higher-order components.\nexport { default as ifCondition } from './higher-order/if-condition';\nexport { default as pure } from './higher-order/pure';\nexport { default as withGlobalEvents } from './higher-order/with-global-events';\nexport { default as withInstanceId } from './higher-order/with-instance-id';\nexport { default as withSafeTimeout } from './higher-order/with-safe-timeout';\nexport { default as withState } from './higher-order/with-state';\nexport { default as withPreferredColorScheme } from './higher-order/with-preferred-color-scheme';\n\n// Hooks.\nexport { default as useConstrainedTabbing } from './hooks/use-constrained-tabbing';\nexport { default as __experimentalUseDragging } from './hooks/use-dragging';\nexport { default as __experimentalUseFocusOutside } from './hooks/use-focus-outside';\nexport { default as useInstanceId } from './hooks/use-instance-id';\nexport { default as useIsomorphicLayoutEffect } from './hooks/use-isomorphic-layout-effect';\nexport { default as useKeyboardShortcut } from './hooks/use-keyboard-shortcut';\nexport { default as useMediaQuery } from './hooks/use-media-query';\nexport { default as usePrevious } from './hooks/use-previous';\nexport { default as useReducedMotion } from './hooks/use-reduced-motion';\nexport { default as useViewportMatch } from './hooks/use-viewport-match';\nexport { default as usePreferredColorScheme } from './hooks/use-preferred-color-scheme';\nexport { default as usePreferredColorSchemeStyle } from './hooks/use-preferred-color-scheme-style';\nexport { default as useResizeObserver } from './hooks/use-resize-observer';\nexport { default as useDebounce } from './hooks/use-debounce';\nexport { default as useThrottle } from './hooks/use-throttle';\nexport { default as useMergeRefs } from './hooks/use-merge-refs';\nexport { default as useRefEffect } from './hooks/use-ref-effect';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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CAAAhB,OAAA;AACA,IAAAuC,YAAA,GAAAvB,sBAAA,CAAAhB,OAAA;AACA,IAAAwC,aAAA,GAAAxB,sBAAA,CAAAhB,OAAA;AACA,IAAAyC,aAAA,GAAAzB,sBAAA,CAAAhB,OAAA"}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.createHigherOrderComponent = createHigherOrderComponent;
|
|
7
|
-
|
|
8
7
|
var _changeCase = require("change-case");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* External dependencies
|
|
12
10
|
*/
|
|
@@ -27,6 +25,7 @@ function createHigherOrderComponent(mapComponent, modifierName) {
|
|
|
27
25
|
return Outer;
|
|
28
26
|
};
|
|
29
27
|
}
|
|
28
|
+
|
|
30
29
|
/**
|
|
31
30
|
* Returns a displayName for a higher-order component, given a wrapper name.
|
|
32
31
|
*
|
|
@@ -38,8 +37,6 @@ function createHigherOrderComponent(mapComponent, modifierName) {
|
|
|
38
37
|
* @param Inner Wrapped component inside higher-order component.
|
|
39
38
|
* @return Wrapped name of higher-order component.
|
|
40
39
|
*/
|
|
41
|
-
|
|
42
|
-
|
|
43
40
|
const hocName = (name, Inner) => {
|
|
44
41
|
const inner = Inner.displayName || Inner.name || 'Component';
|
|
45
42
|
const outer = (0, _changeCase.pascalCase)(name !== null && name !== void 0 ? name : '');
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_changeCase","require","createHigherOrderComponent","mapComponent","modifierName","Inner","Outer","displayName","hocName","name","inner","outer","pascalCase"],"sources":["@wordpress/compose/src/utils/create-higher-order-component/index.ts"],"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"],"mappings":";;;;;;AAGA,IAAAA,WAAA,GAAAC,OAAA;AAHA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,SAASC,0BAA0BA,CAGvCC,YAAyC,EAAEC,YAAoB,EAAG;EACpE,OAASC,KAAa,IAAM;IAC3B,MAAMC,KAAK,GAAGH,YAAY,CAAEE,KAAM,CAAC;IACnCC,KAAK,CAACC,WAAW,GAAGC,OAAO,CAAEJ,YAAY,EAAEC,KAAM,CAAC;IAClD,OAAOC,KAAK;EACb,CAAC;AACF;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAME,OAAO,GAAGA,CAAEC,IAAY,EAAEJ,KAA2B,KAAM;EAChE,MAAMK,KAAK,GAAGL,KAAK,CAACE,WAAW,IAAIF,KAAK,CAACI,IAAI,IAAI,WAAW;EAC5D,MAAME,KAAK,GAAG,IAAAC,sBAAU,EAAEH,IAAI,aAAJA,IAAI,cAAJA,IAAI,GAAI,EAAG,CAAC;EAEtC,OAAQ,GAAGE,KAAO,IAAID,KAAO,GAAE;AAChC,CAAC"}
|
|
@@ -4,7 +4,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.debounce = void 0;
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* Parts of this source were derived and modified from lodash,
|
|
10
9
|
* released under the MIT license.
|
|
@@ -85,18 +84,14 @@ const debounce = (func, wait, options) => {
|
|
|
85
84
|
let leading = false;
|
|
86
85
|
let maxing = false;
|
|
87
86
|
let trailing = true;
|
|
88
|
-
|
|
89
87
|
if (options) {
|
|
90
88
|
leading = !!options.leading;
|
|
91
89
|
maxing = 'maxWait' in options;
|
|
92
|
-
|
|
93
90
|
if (options.maxWait !== undefined) {
|
|
94
91
|
maxWait = Math.max(options.maxWait, wait);
|
|
95
92
|
}
|
|
96
|
-
|
|
97
93
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
98
94
|
}
|
|
99
|
-
|
|
100
95
|
function invokeFunc(time) {
|
|
101
96
|
const args = lastArgs;
|
|
102
97
|
const thisArg = lastThis;
|
|
@@ -106,120 +101,100 @@ const debounce = (func, wait, options) => {
|
|
|
106
101
|
result = func.apply(thisArg, args);
|
|
107
102
|
return result;
|
|
108
103
|
}
|
|
109
|
-
|
|
110
104
|
function startTimer(pendingFunc, waitTime) {
|
|
111
105
|
timerId = setTimeout(pendingFunc, waitTime);
|
|
112
106
|
}
|
|
113
|
-
|
|
114
107
|
function cancelTimer() {
|
|
115
108
|
if (timerId !== undefined) {
|
|
116
109
|
clearTimeout(timerId);
|
|
117
110
|
}
|
|
118
111
|
}
|
|
119
|
-
|
|
120
112
|
function leadingEdge(time) {
|
|
121
113
|
// Reset any `maxWait` timer.
|
|
122
|
-
lastInvokeTime = time;
|
|
123
|
-
|
|
124
|
-
startTimer(timerExpired, wait);
|
|
125
|
-
|
|
114
|
+
lastInvokeTime = time;
|
|
115
|
+
// Start the timer for the trailing edge.
|
|
116
|
+
startTimer(timerExpired, wait);
|
|
117
|
+
// Invoke the leading edge.
|
|
126
118
|
return leading ? invokeFunc(time) : result;
|
|
127
119
|
}
|
|
128
|
-
|
|
129
120
|
function getTimeSinceLastCall(time) {
|
|
130
121
|
return time - (lastCallTime || 0);
|
|
131
122
|
}
|
|
132
|
-
|
|
133
123
|
function remainingWait(time) {
|
|
134
124
|
const timeSinceLastCall = getTimeSinceLastCall(time);
|
|
135
125
|
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
136
126
|
const timeWaiting = wait - timeSinceLastCall;
|
|
137
127
|
return maxing ? Math.min(timeWaiting, maxWait - timeSinceLastInvoke) : timeWaiting;
|
|
138
128
|
}
|
|
139
|
-
|
|
140
129
|
function shouldInvoke(time) {
|
|
141
130
|
const timeSinceLastCall = getTimeSinceLastCall(time);
|
|
142
|
-
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
131
|
+
const timeSinceLastInvoke = time - lastInvokeTime;
|
|
132
|
+
|
|
133
|
+
// Either this is the first call, activity has stopped and we're at the
|
|
143
134
|
// trailing edge, the system time has gone backwards and we're treating
|
|
144
135
|
// it as the trailing edge, or we've hit the `maxWait` limit.
|
|
145
|
-
|
|
146
136
|
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait;
|
|
147
137
|
}
|
|
148
|
-
|
|
149
138
|
function timerExpired() {
|
|
150
139
|
const time = Date.now();
|
|
151
|
-
|
|
152
140
|
if (shouldInvoke(time)) {
|
|
153
141
|
return trailingEdge(time);
|
|
154
|
-
}
|
|
155
|
-
|
|
156
|
-
|
|
142
|
+
}
|
|
143
|
+
// Restart the timer.
|
|
157
144
|
startTimer(timerExpired, remainingWait(time));
|
|
158
145
|
return undefined;
|
|
159
146
|
}
|
|
160
|
-
|
|
161
147
|
function clearTimer() {
|
|
162
148
|
timerId = undefined;
|
|
163
149
|
}
|
|
164
|
-
|
|
165
150
|
function trailingEdge(time) {
|
|
166
|
-
clearTimer();
|
|
167
|
-
// debounced at least once.
|
|
151
|
+
clearTimer();
|
|
168
152
|
|
|
153
|
+
// Only invoke if we have `lastArgs` which means `func` has been
|
|
154
|
+
// debounced at least once.
|
|
169
155
|
if (trailing && lastArgs) {
|
|
170
156
|
return invokeFunc(time);
|
|
171
157
|
}
|
|
172
|
-
|
|
173
158
|
lastArgs = lastThis = undefined;
|
|
174
159
|
return result;
|
|
175
160
|
}
|
|
176
|
-
|
|
177
161
|
function cancel() {
|
|
178
162
|
cancelTimer();
|
|
179
163
|
lastInvokeTime = 0;
|
|
180
164
|
clearTimer();
|
|
181
165
|
lastArgs = lastCallTime = lastThis = undefined;
|
|
182
166
|
}
|
|
183
|
-
|
|
184
167
|
function flush() {
|
|
185
168
|
return pending() ? trailingEdge(Date.now()) : result;
|
|
186
169
|
}
|
|
187
|
-
|
|
188
170
|
function pending() {
|
|
189
171
|
return timerId !== undefined;
|
|
190
172
|
}
|
|
191
|
-
|
|
192
173
|
function debounced(...args) {
|
|
193
174
|
const time = Date.now();
|
|
194
175
|
const isInvoking = shouldInvoke(time);
|
|
195
176
|
lastArgs = args;
|
|
196
177
|
lastThis = this;
|
|
197
178
|
lastCallTime = time;
|
|
198
|
-
|
|
199
179
|
if (isInvoking) {
|
|
200
180
|
if (!pending()) {
|
|
201
181
|
return leadingEdge(lastCallTime);
|
|
202
182
|
}
|
|
203
|
-
|
|
204
183
|
if (maxing) {
|
|
205
184
|
// Handle invocations in a tight loop.
|
|
206
185
|
startTimer(timerExpired, wait);
|
|
207
186
|
return invokeFunc(lastCallTime);
|
|
208
187
|
}
|
|
209
188
|
}
|
|
210
|
-
|
|
211
189
|
if (!pending()) {
|
|
212
190
|
startTimer(timerExpired, wait);
|
|
213
191
|
}
|
|
214
|
-
|
|
215
192
|
return result;
|
|
216
193
|
}
|
|
217
|
-
|
|
218
194
|
debounced.cancel = cancel;
|
|
219
195
|
debounced.flush = flush;
|
|
220
196
|
debounced.pending = pending;
|
|
221
197
|
return debounced;
|
|
222
198
|
};
|
|
223
|
-
|
|
224
199
|
exports.debounce = debounce;
|
|
225
200
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/utils/debounce/index.ts"],"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"],"mappings":";;;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAG,CACvBC,IADuB,EAEvBC,IAFuB,EAGvBC,OAHuB,KAInB;AACJ,MAAIC,QAAJ;AACA,MAAIC,QAAJ;AACA,MAAIC,OAAO,GAAG,CAAd;AACA,MAAIC,MAAJ;AACA,MAAIC,OAAJ;AACA,MAAIC,YAAJ;AAEA,MAAIC,cAAc,GAAG,CAArB;AACA,MAAIC,OAAO,G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GAAoBA,OAApB;AACA,SAAOC,SAAP;AACA,CA7JM","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"]}
|
|
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":";;;;;;AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAmCA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMA,QAAQ,GAAGA,CACvBC,IAAe,EACfC,IAAY,EACZC,OAAoC,KAChC;EACJ,IAAIC,QAA6C;EACjD,IAAIC,QAA6B;EACjC,IAAIC,OAAO,GAAG,CAAC;EACf,IAAIC,MAA+B;EACnC,IAAIC,OAAoD;EACxD,IAAIC,YAAgC;EAEpC,IAAIC,cAAc,GAAG,CAAC;EACtB,IAAIC,OAAO,GAAG,KAAK;EACnB,IAAIC,MAAM,GAAG,KAAK;EAClB,IAAIC,QAAQ,GAAG,IAAI;EAEnB,IAAKV,OAAO,EAAG;IACdQ,OAAO,GAAG,CAAC,CAAER,OAAO,CAACQ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AAQ,GAAGS,SAAS;EAC/C;EAEA,SAAS4B,KAAKA,CAAA,EAAG;IAChB,OAAOC,OAAO,CAAC,CAAC,GAAGJ,YAAY,CAAEF,IAAI,CAACC,GAAG,CAAC,CAAE,CAAC,GAAG/B,MAAM;EACvD;EAEA,SAASoC,OAAOA,CAAA,EAAG;IAClB,OAAOnC,OAAO,KAAKM,SAAS;EAC7B;EAEA,SAAS8B,SAASA,CAAiB,GAAGzB,IAA6B,EAAG;IACrE,MAAMD,IAAI,GAAGmB,IAAI,CAACC,GAAG,CAAC,CAAC;IACvB,MAAMO,UAAU,GAAGT,YAAY,CAAElB,IAAK,CAAC;IAEvCd,QAAQ,GAAGe,IAAI;IACfd,QAAQ,GAAG,IAAI;IACfI,YAAY,GAAGS,IAAI;IAEnB,IAAK2B,UAAU,EAAG;MACjB,IAAK,CAAEF,OAAO,CAAC,CAAC,EAAG;QAClB,OAAOf,WAAW,CAAEnB,YAAa,CAAC;MACnC;MACA,IAAKG,MAAM,EAAG;QACb;QACAU,UAAU,CAAEO,YAAY,EAAE3B,IAAK,CAAC;QAChC,OAAOe,UAAU,CAAER,YAAa,CAAC;MAClC;IACD;IACA,IAAK,CAAEkC,OAAO,CAAC,CAAC,EAAG;MAClBrB,UAAU,CAAEO,YAAY,EAAE3B,IAAK,CAAC;IACjC;IACA,OAAOK,MAAM;EACd;EACAqC,SAAS,CAACH,MAAM,GAAGA,MAAM;EACzBG,SAAS,CAACF,KAAK,GAAGA,KAAK;EACvBE,SAAS,CAACD,OAAO,GAAGA,OAAO;EAC3B,OAAOC,SAAS;AACjB,CAAC;AAACE,OAAA,CAAA9C,QAAA,GAAAA,QAAA"}
|
|
@@ -4,9 +4,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.throttle = void 0;
|
|
7
|
-
|
|
8
7
|
var _debounce = require("../debounce");
|
|
9
|
-
|
|
10
8
|
/**
|
|
11
9
|
* Parts of this source were derived and modified from lodash,
|
|
12
10
|
* released under the MIT license.
|
|
@@ -81,18 +79,15 @@ var _debounce = require("../debounce");
|
|
|
81
79
|
const throttle = (func, wait, options) => {
|
|
82
80
|
let leading = true;
|
|
83
81
|
let trailing = true;
|
|
84
|
-
|
|
85
82
|
if (options) {
|
|
86
83
|
leading = 'leading' in options ? !!options.leading : leading;
|
|
87
84
|
trailing = 'trailing' in options ? !!options.trailing : trailing;
|
|
88
85
|
}
|
|
89
|
-
|
|
90
86
|
return (0, _debounce.debounce)(func, wait, {
|
|
91
87
|
leading,
|
|
92
88
|
trailing,
|
|
93
89
|
maxWait: wait
|
|
94
90
|
});
|
|
95
91
|
};
|
|
96
|
-
|
|
97
92
|
exports.throttle = throttle;
|
|
98
93
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["_debounce","require","throttle","func","wait","options","leading","trailing","debounce","maxWait","exports"],"sources":["@wordpress/compose/src/utils/throttle/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\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"],"mappings":";;;;;;AA2CA,IAAAA,SAAA,GAAAC,OAAA;AA3CA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;;AAQA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMC,QAAQ,GAAGA,CACvBC,IAAe,EACfC,IAAY,EACZC,OAAyB,KACrB;EACJ,IAAIC,OAAO,GAAG,IAAI;EAClB,IAAIC,QAAQ,GAAG,IAAI;EAEnB,IAAKF,OAAO,EAAG;IACdC,OAAO,GAAG,SAAS,IAAID,OAAO,GAAG,CAAC,CAAEA,OAAO,CAACC,OAAO,GAAGA,OAAO;IAC7DC,QAAQ,GAAG,UAAU,IAAIF,OAAO,GAAG,CAAC,CAAEA,OAAO,CAACE,QAAQ,GAAGA,QAAQ;EAClE;EACA,OAAO,IAAAC,kBAAQ,EAAEL,IAAI,EAAEC,IAAI,EAAE;IAC5BE,OAAO;IACPC,QAAQ;IACRE,OAAO,EAAEL;EACV,CAAE,CAAC;AACJ,CAAC;AAACM,OAAA,CAAAR,QAAA,GAAAA,QAAA"}
|
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
* Internal dependencies
|
|
3
3
|
*/
|
|
4
4
|
import { basePipe } from './pipe';
|
|
5
|
+
|
|
5
6
|
/**
|
|
6
7
|
* Composes multiple higher-order components into a single higher-order component. Performs right-to-left function
|
|
7
8
|
* composition, where each successive invocation is supplied the return value of the previous.
|
|
@@ -10,7 +11,6 @@ import { basePipe } from './pipe';
|
|
|
10
11
|
*
|
|
11
12
|
* @see https://docs-lodash.com/v4/flow-right/
|
|
12
13
|
*/
|
|
13
|
-
|
|
14
14
|
const compose = basePipe(true);
|
|
15
15
|
export default compose;
|
|
16
16
|
//# sourceMappingURL=compose.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["@wordpress/compose/src/higher-order/compose.ts"],"
|
|
1
|
+
{"version":3,"names":["basePipe","compose"],"sources":["@wordpress/compose/src/higher-order/compose.ts"],"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://docs-lodash.com/v4/flow-right/\n */\nconst compose = basePipe( true );\n\nexport default compose;\n"],"mappings":"AAAA;AACA;AACA;AACA,SAASA,QAAQ,QAAQ,QAAQ;;AAEjC;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMC,OAAO,GAAGD,QAAQ,CAAE,IAAK,CAAC;AAEhC,eAAeC,OAAO"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* External dependencies
|
|
5
4
|
*/
|
|
@@ -8,6 +7,7 @@ import { createElement } from "@wordpress/element";
|
|
|
8
7
|
* Internal dependencies
|
|
9
8
|
*/
|
|
10
9
|
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
10
|
+
|
|
11
11
|
/**
|
|
12
12
|
* Higher-order component creator, creating a new component which renders if
|
|
13
13
|
* the given condition is satisfied or with the given optional prop name.
|
|
@@ -25,17 +25,15 @@ import { createHigherOrderComponent } from '../../utils/create-higher-order-comp
|
|
|
25
25
|
*
|
|
26
26
|
* @return Higher-order component.
|
|
27
27
|
*/
|
|
28
|
-
|
|
29
28
|
function ifCondition(predicate) {
|
|
30
29
|
return createHigherOrderComponent(WrappedComponent => props => {
|
|
31
30
|
if (!predicate(props)) {
|
|
32
31
|
return null;
|
|
33
32
|
}
|
|
34
|
-
|
|
35
|
-
|
|
33
|
+
return createElement(WrappedComponent, {
|
|
34
|
+
...props
|
|
36
35
|
});
|
|
37
36
|
}, 'ifCondition');
|
|
38
37
|
}
|
|
39
|
-
|
|
40
38
|
export default ifCondition;
|
|
41
39
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["createHigherOrderComponent","ifCondition","predicate","WrappedComponent","props","createElement"],"sources":["@wordpress/compose/src/higher-order/if-condition/index.tsx"],"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"],"mappings":";AAAA;AACA;AACA;;AAGA;AACA;AACA;AACA,SAASA,0BAA0B,QAAQ,2CAA2C;;AAEtF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,SAASC,WAAWA,CACnBC,SAAsC,EACrC;EACD,OAAOF,0BAA0B,CAC9BG,gBAAwC,IAAQC,KAAY,IAAM;IACnE,IAAK,CAAEF,SAAS,CAAEE,KAAM,CAAC,EAAG;MAC3B,OAAO,IAAI;IACZ;IAEA,OAAOC,aAAA,CAACF,gBAAgB;MAAA,GAAMC;IAAK,CAAI,CAAC;EACzC,CAAC,EACD,aACD,CAAC;AACF;AAEA,eAAeH,WAAW"}
|
|
@@ -49,13 +49,12 @@
|
|
|
49
49
|
*/
|
|
50
50
|
const basePipe = (reverse = false) => (...funcs) => (...args) => {
|
|
51
51
|
const functions = funcs.flat();
|
|
52
|
-
|
|
53
52
|
if (reverse) {
|
|
54
53
|
functions.reverse();
|
|
55
54
|
}
|
|
56
|
-
|
|
57
55
|
return functions.reduce((prev, func) => [func(...prev)], args)[0];
|
|
58
56
|
};
|
|
57
|
+
|
|
59
58
|
/**
|
|
60
59
|
* Composes multiple higher-order components into a single higher-order component. Performs left-to-right function
|
|
61
60
|
* composition, where each successive invocation is supplied the return value of the previous.
|
|
@@ -64,8 +63,6 @@ const basePipe = (reverse = false) => (...funcs) => (...args) => {
|
|
|
64
63
|
*
|
|
65
64
|
* @see https://docs-lodash.com/v4/flow/
|
|
66
65
|
*/
|
|
67
|
-
|
|
68
|
-
|
|
69
66
|
const pipe = basePipe();
|
|
70
67
|
export { basePipe };
|
|
71
68
|
export default pipe;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"
|
|
1
|
+
{"version":3,"names":["basePipe","reverse","funcs","args","functions","flat","reduce","prev","func","pipe"],"sources":["@wordpress/compose/src/higher-order/pipe.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\n/**\n * Creates a pipe function.\n *\n * Allows to choose whether to perform left-to-right or right-to-left composition.\n *\n * @see https://docs-lodash.com/v4/flow/\n *\n * @param {boolean} reverse True if right-to-left, false for left-to-right composition.\n */\nconst basePipe =\n\t( reverse: boolean = false ) =>\n\t( ...funcs: Function[] ) =>\n\t( ...args: unknown[] ) => {\n\t\tconst functions = funcs.flat();\n\t\tif ( reverse ) {\n\t\t\tfunctions.reverse();\n\t\t}\n\t\treturn functions.reduce(\n\t\t\t( prev, func ) => [ func( ...prev ) ],\n\t\t\targs\n\t\t)[ 0 ];\n\t};\n\n/**\n * Composes multiple higher-order components into a single higher-order component. Performs left-to-right function\n * composition, where each successive invocation is supplied the return value of the previous.\n *\n * This is inspired by `lodash`'s `flow` function.\n *\n * @see https://docs-lodash.com/v4/flow/\n */\nconst pipe = basePipe();\n\nexport { basePipe };\n\nexport default pipe;\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMA,QAAQ,GACbA,CAAEC,OAAgB,GAAG,KAAK,KAC1B,CAAE,GAAGC,KAAiB,KACtB,CAAE,GAAGC,IAAe,KAAM;EACzB,MAAMC,SAAS,GAAGF,KAAK,CAACG,IAAI,CAAC,CAAC;EAC9B,IAAKJ,OAAO,EAAG;IACdG,SAAS,CAACH,OAAO,CAAC,CAAC;EACpB;EACA,OAAOG,SAAS,CAACE,MAAM,CACtB,CAAEC,IAAI,EAAEC,IAAI,KAAM,CAAEA,IAAI,CAAE,GAAGD,IAAK,CAAC,CAAE,EACrCJ,IACD,CAAC,CAAE,CAAC,CAAE;AACP,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,MAAMM,IAAI,GAAGT,QAAQ,CAAC,CAAC;AAEvB,SAASA,QAAQ;AAEjB,eAAeS,IAAI"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { createElement } from "@wordpress/element";
|
|
2
|
-
|
|
3
2
|
/**
|
|
4
3
|
* External dependencies
|
|
5
4
|
*/
|
|
@@ -9,36 +8,33 @@ import { createElement } from "@wordpress/element";
|
|
|
9
8
|
*/
|
|
10
9
|
import isShallowEqual from '@wordpress/is-shallow-equal';
|
|
11
10
|
import { Component } from '@wordpress/element';
|
|
11
|
+
|
|
12
12
|
/**
|
|
13
13
|
* Internal dependencies
|
|
14
14
|
*/
|
|
15
|
-
|
|
16
15
|
import { createHigherOrderComponent } from '../../utils/create-higher-order-component';
|
|
16
|
+
|
|
17
17
|
/**
|
|
18
18
|
* Given a component returns the enhanced component augmented with a component
|
|
19
19
|
* only re-rendering when its props/state change
|
|
20
20
|
*/
|
|
21
|
-
|
|
22
21
|
const pure = createHigherOrderComponent(function (WrappedComponent) {
|
|
23
22
|
if (WrappedComponent.prototype instanceof Component) {
|
|
24
23
|
return class extends WrappedComponent {
|
|
25
24
|
shouldComponentUpdate(nextProps, nextState) {
|
|
26
25
|
return !isShallowEqual(nextProps, this.props) || !isShallowEqual(nextState, this.state);
|
|
27
26
|
}
|
|
28
|
-
|
|
29
27
|
};
|
|
30
28
|
}
|
|
31
|
-
|
|
32
29
|
return class extends Component {
|
|
33
30
|
shouldComponentUpdate(nextProps) {
|
|
34
31
|
return !isShallowEqual(nextProps, this.props);
|
|
35
32
|
}
|
|
36
|
-
|
|
37
33
|
render() {
|
|
38
|
-
return createElement(WrappedComponent, {
|
|
34
|
+
return createElement(WrappedComponent, {
|
|
35
|
+
...this.props
|
|
39
36
|
});
|
|
40
37
|
}
|
|
41
|
-
|
|
42
38
|
};
|
|
43
39
|
}, 'pure');
|
|
44
40
|
export default pure;
|