@highlight-ui/utils-hooks
Advanced tools
Comparing version 3.0.9 to 3.1.0
@@ -5,1 +5,2 @@ export { default as useAutoPositioner } from './src/useAutoPositioner'; | ||
export { default as useScrollObserver } from './src/useScrollObserver'; | ||
export { default as useId } from './src/useId'; |
@@ -13,4 +13,6 @@ 'use strict'; | ||
var debounce$2 = require('lodash/debounce'); | ||
var debounce$1 = require('lodash.debounce'); | ||
var utilsCommons = require('@highlight-ui/utils-commons'); | ||
function _interopDefaultLegacy(e) { | ||
@@ -46,3 +48,3 @@ return e && typeof e === 'object' && 'default' in e ? e : { | ||
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce$2); | ||
var debounce__default = /*#__PURE__*/_interopDefaultLegacy(debounce$1); | ||
/*! ***************************************************************************** | ||
@@ -341,390 +343,2 @@ Copyright (c) Microsoft Corporation. | ||
var FUNC_ERROR_TEXT$1 = 'Expected a function'; | ||
/** Used as references for various `Number` constants. */ | ||
var NAN$1 = 0 / 0; | ||
/** `Object#toString` result references. */ | ||
var symbolTag$1 = '[object Symbol]'; | ||
/** Used to match leading and trailing whitespace. */ | ||
var reTrim$1 = /^\s+|\s+$/g; | ||
/** Used to detect bad signed hexadecimal string values. */ | ||
var reIsBadHex$1 = /^[-+]0x[0-9a-f]+$/i; | ||
/** Used to detect binary string values. */ | ||
var reIsBinary$1 = /^0b[01]+$/i; | ||
/** Used to detect octal string values. */ | ||
var reIsOctal$1 = /^0o[0-7]+$/i; | ||
/** Built-in method references without a dependency on `root`. */ | ||
var freeParseInt$1 = parseInt; | ||
/** Detect free variable `global` from Node.js. */ | ||
var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; | ||
/** Detect free variable `self`. */ | ||
var freeSelf$1 = typeof self == 'object' && self && self.Object === Object && self; | ||
/** Used as a reference to the global object. */ | ||
var root$1 = freeGlobal$1 || freeSelf$1 || Function('return this')(); | ||
/** Used for built-in method references. */ | ||
var objectProto$1 = Object.prototype; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString$1 = objectProto$1.toString; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeMax$1 = Math.max, | ||
nativeMin$1 = Math.min; | ||
/** | ||
* Gets the timestamp of the number of milliseconds that have elapsed since | ||
* the Unix epoch (1 January 1970 00:00:00 UTC). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 2.4.0 | ||
* @category Date | ||
* @returns {number} Returns the timestamp. | ||
* @example | ||
* | ||
* _.defer(function(stamp) { | ||
* console.log(_.now() - stamp); | ||
* }, _.now()); | ||
* // => Logs the number of milliseconds it took for the deferred invocation. | ||
*/ | ||
var now$1 = function () { | ||
return root$1.Date.now(); | ||
}; | ||
/** | ||
* Creates a debounced function that delays invoking `func` until after `wait` | ||
* milliseconds have elapsed since the last time the debounced function was | ||
* invoked. The debounced function comes with a `cancel` method to cancel | ||
* delayed `func` invocations and a `flush` method to immediately invoke them. | ||
* Provide `options` to indicate whether `func` should be invoked on the | ||
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked | ||
* with the last arguments provided to the debounced function. Subsequent | ||
* calls to the debounced function return the result of the last `func` | ||
* invocation. | ||
* | ||
* **Note:** If `leading` and `trailing` options are `true`, `func` is | ||
* invoked on the trailing edge of the timeout only if the debounced function | ||
* is invoked more than once during the `wait` timeout. | ||
* | ||
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred | ||
* until to the next tick, similar to `setTimeout` with a timeout of `0`. | ||
* | ||
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) | ||
* for details over the differences between `_.debounce` and `_.throttle`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Function | ||
* @param {Function} func The function to debounce. | ||
* @param {number} [wait=0] The number of milliseconds to delay. | ||
* @param {Object} [options={}] The options object. | ||
* @param {boolean} [options.leading=false] | ||
* Specify invoking on the leading edge of the timeout. | ||
* @param {number} [options.maxWait] | ||
* The maximum time `func` is allowed to be delayed before it's invoked. | ||
* @param {boolean} [options.trailing=true] | ||
* Specify invoking on the trailing edge of the timeout. | ||
* @returns {Function} Returns the new debounced function. | ||
* @example | ||
* | ||
* // Avoid costly calculations while the window size is in flux. | ||
* jQuery(window).on('resize', _.debounce(calculateLayout, 150)); | ||
* | ||
* // Invoke `sendMail` when clicked, debouncing subsequent calls. | ||
* jQuery(element).on('click', _.debounce(sendMail, 300, { | ||
* 'leading': true, | ||
* 'trailing': false | ||
* })); | ||
* | ||
* // Ensure `batchLog` is invoked once after 1 second of debounced calls. | ||
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); | ||
* var source = new EventSource('/stream'); | ||
* jQuery(source).on('message', debounced); | ||
* | ||
* // Cancel the trailing debounced invocation. | ||
* jQuery(window).on('popstate', debounced.cancel); | ||
*/ | ||
function debounce$1(func, wait, options) { | ||
var lastArgs, | ||
lastThis, | ||
maxWait, | ||
result, | ||
timerId, | ||
lastCallTime, | ||
lastInvokeTime = 0, | ||
leading = false, | ||
maxing = false, | ||
trailing = true; | ||
if (typeof func != 'function') { | ||
throw new TypeError(FUNC_ERROR_TEXT$1); | ||
} | ||
wait = toNumber$1(wait) || 0; | ||
if (isObject$1(options)) { | ||
leading = !!options.leading; | ||
maxing = 'maxWait' in options; | ||
maxWait = maxing ? nativeMax$1(toNumber$1(options.maxWait) || 0, wait) : maxWait; | ||
trailing = 'trailing' in options ? !!options.trailing : trailing; | ||
} | ||
function invokeFunc(time) { | ||
var args = lastArgs, | ||
thisArg = lastThis; | ||
lastArgs = lastThis = undefined; | ||
lastInvokeTime = time; | ||
result = func.apply(thisArg, args); | ||
return result; | ||
} | ||
function leadingEdge(time) { | ||
// Reset any `maxWait` timer. | ||
lastInvokeTime = time; // Start the timer for the trailing edge. | ||
timerId = setTimeout(timerExpired, wait); // Invoke the leading edge. | ||
return leading ? invokeFunc(time) : result; | ||
} | ||
function remainingWait(time) { | ||
var timeSinceLastCall = time - lastCallTime, | ||
timeSinceLastInvoke = time - lastInvokeTime, | ||
result = wait - timeSinceLastCall; | ||
return maxing ? nativeMin$1(result, maxWait - timeSinceLastInvoke) : result; | ||
} | ||
function shouldInvoke(time) { | ||
var timeSinceLastCall = time - lastCallTime, | ||
timeSinceLastInvoke = time - lastInvokeTime; // Either this is the first call, activity has stopped and we're at the | ||
// trailing edge, the system time has gone backwards and we're treating | ||
// it as the trailing edge, or we've hit the `maxWait` limit. | ||
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; | ||
} | ||
function timerExpired() { | ||
var time = now$1(); | ||
if (shouldInvoke(time)) { | ||
return trailingEdge(time); | ||
} // Restart the timer. | ||
timerId = setTimeout(timerExpired, remainingWait(time)); | ||
} | ||
function trailingEdge(time) { | ||
timerId = undefined; // Only invoke if we have `lastArgs` which means `func` has been | ||
// debounced at least once. | ||
if (trailing && lastArgs) { | ||
return invokeFunc(time); | ||
} | ||
lastArgs = lastThis = undefined; | ||
return result; | ||
} | ||
function cancel() { | ||
if (timerId !== undefined) { | ||
clearTimeout(timerId); | ||
} | ||
lastInvokeTime = 0; | ||
lastArgs = lastCallTime = lastThis = timerId = undefined; | ||
} | ||
function flush() { | ||
return timerId === undefined ? result : trailingEdge(now$1()); | ||
} | ||
function debounced() { | ||
var time = now$1(), | ||
isInvoking = shouldInvoke(time); | ||
lastArgs = arguments; | ||
lastThis = this; | ||
lastCallTime = time; | ||
if (isInvoking) { | ||
if (timerId === undefined) { | ||
return leadingEdge(lastCallTime); | ||
} | ||
if (maxing) { | ||
// Handle invocations in a tight loop. | ||
timerId = setTimeout(timerExpired, wait); | ||
return invokeFunc(lastCallTime); | ||
} | ||
} | ||
if (timerId === undefined) { | ||
timerId = setTimeout(timerExpired, wait); | ||
} | ||
return result; | ||
} | ||
debounced.cancel = cancel; | ||
debounced.flush = flush; | ||
return debounced; | ||
} | ||
/** | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject$1(value) { | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike$1(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Symbol` primitive or object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`. | ||
* @example | ||
* | ||
* _.isSymbol(Symbol.iterator); | ||
* // => true | ||
* | ||
* _.isSymbol('abc'); | ||
* // => false | ||
*/ | ||
function isSymbol$1(value) { | ||
return typeof value == 'symbol' || isObjectLike$1(value) && objectToString$1.call(value) == symbolTag$1; | ||
} | ||
/** | ||
* Converts `value` to a number. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to process. | ||
* @returns {number} Returns the number. | ||
* @example | ||
* | ||
* _.toNumber(3.2); | ||
* // => 3.2 | ||
* | ||
* _.toNumber(Number.MIN_VALUE); | ||
* // => 5e-324 | ||
* | ||
* _.toNumber(Infinity); | ||
* // => Infinity | ||
* | ||
* _.toNumber('3.2'); | ||
* // => 3.2 | ||
*/ | ||
function toNumber$1(value) { | ||
if (typeof value == 'number') { | ||
return value; | ||
} | ||
if (isSymbol$1(value)) { | ||
return NAN$1; | ||
} | ||
if (isObject$1(value)) { | ||
var other = typeof value.valueOf == 'function' ? value.valueOf() : value; | ||
value = isObject$1(other) ? other + '' : other; | ||
} | ||
if (typeof value != 'string') { | ||
return value === 0 ? value : +value; | ||
} | ||
value = value.replace(reTrim$1, ''); | ||
var isBinary = reIsBinary$1.test(value); | ||
return isBinary || reIsOctal$1.test(value) ? freeParseInt$1(value.slice(2), isBinary ? 2 : 8) : reIsBadHex$1.test(value) ? NAN$1 : +value; | ||
} | ||
var lodash_debounce = debounce$1; | ||
/** | ||
* lodash (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright jQuery Foundation and other contributors <https://jquery.org/> | ||
* Released under MIT license <https://lodash.com/license> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
*/ | ||
/** Used as the `TypeError` message for "Functions" methods. */ | ||
var FUNC_ERROR_TEXT = 'Expected a function'; | ||
@@ -1224,3 +838,3 @@ /** Used as references for various `Number` constants. */ | ||
case 'debounce': | ||
return lodash_debounce(resizeCallback, refreshRate, refreshOptions); | ||
return debounce__default["default"](resizeCallback, refreshRate, refreshOptions); | ||
@@ -1586,2 +1200,19 @@ case 'throttle': | ||
function setRef(ref, value) { | ||
if (typeof ref === 'function') { | ||
ref(value); | ||
} else if (ref) { | ||
// eslint-disable-next-line no-param-reassign | ||
ref.current = value; | ||
} | ||
} | ||
function useForkRef(refs) { | ||
return React.useCallback(function (refValue) { | ||
refs.forEach(function (ref) { | ||
return setRef(ref, refValue); | ||
}); | ||
}, refs); | ||
} | ||
var createPopper = core.popperGenerator({ | ||
@@ -1641,19 +1272,2 @@ defaultModifiers: [core.preventOverflow, core.popperOffsets, core.eventListeners, core.computeStyles, core.applyStyles, __assign$1(__assign$1({}, core.offset), { | ||
function setRef(ref, value) { | ||
if (typeof ref === 'function') { | ||
ref(value); | ||
} else if (ref) { | ||
// eslint-disable-next-line no-param-reassign | ||
ref.current = value; | ||
} | ||
} | ||
function useForkRef(refs) { | ||
return React.useCallback(function (refValue) { | ||
refs.forEach(function (ref) { | ||
return setRef(ref, refValue); | ||
}); | ||
}, refs); | ||
} | ||
function useEventListener(t, r, i, o) { | ||
@@ -1737,6 +1351,13 @@ void 0 === i && (i = global), void 0 === o && (o = {}); | ||
var useId = function (prefix) { | ||
return React.useMemo(function () { | ||
return utilsCommons.uniqueId(prefix); | ||
}, [prefix]); | ||
}; | ||
exports.useAutoPositioner = useAutoPositioner; | ||
exports.useClickOutside = useClickOutside; | ||
exports.useForkRef = useForkRef; | ||
exports.useId = useId; | ||
exports.useScrollObserver = useScrollObserver; | ||
//# sourceMappingURL=index.js.map |
@@ -5,1 +5,2 @@ export { default as useAutoPositioner } from './src/useAutoPositioner'; | ||
export { default as useScrollObserver } from './src/useScrollObserver'; | ||
export { default as useId } from './src/useId'; |
import * as React from 'react'; | ||
import { cloneElement, useRef, useState, isValidElement, createRef, PureComponent, useEffect, useLayoutEffect, useCallback } from 'react'; | ||
import { cloneElement, useRef, useState, isValidElement, createRef, PureComponent, useEffect, useLayoutEffect, useCallback, useMemo } from 'react'; | ||
import { createPopper as createPopper$1, popperGenerator, preventOverflow, popperOffsets, eventListeners, computeStyles, applyStyles, offset, flip } from '@popperjs/core'; | ||
import { findDOMNode } from 'react-dom'; | ||
import debounce$2 from 'lodash/debounce'; | ||
import debounce$1 from 'lodash.debounce'; | ||
import { uniqueId } from '@highlight-ui/utils-commons'; | ||
/*! ***************************************************************************** | ||
@@ -298,390 +299,2 @@ Copyright (c) Microsoft Corporation. | ||
var FUNC_ERROR_TEXT$1 = 'Expected a function'; | ||
/** Used as references for various `Number` constants. */ | ||
var NAN$1 = 0 / 0; | ||
/** `Object#toString` result references. */ | ||
var symbolTag$1 = '[object Symbol]'; | ||
/** Used to match leading and trailing whitespace. */ | ||
var reTrim$1 = /^\s+|\s+$/g; | ||
/** Used to detect bad signed hexadecimal string values. */ | ||
var reIsBadHex$1 = /^[-+]0x[0-9a-f]+$/i; | ||
/** Used to detect binary string values. */ | ||
var reIsBinary$1 = /^0b[01]+$/i; | ||
/** Used to detect octal string values. */ | ||
var reIsOctal$1 = /^0o[0-7]+$/i; | ||
/** Built-in method references without a dependency on `root`. */ | ||
var freeParseInt$1 = parseInt; | ||
/** Detect free variable `global` from Node.js. */ | ||
var freeGlobal$1 = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; | ||
/** Detect free variable `self`. */ | ||
var freeSelf$1 = typeof self == 'object' && self && self.Object === Object && self; | ||
/** Used as a reference to the global object. */ | ||
var root$1 = freeGlobal$1 || freeSelf$1 || Function('return this')(); | ||
/** Used for built-in method references. */ | ||
var objectProto$1 = Object.prototype; | ||
/** | ||
* Used to resolve the | ||
* [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) | ||
* of values. | ||
*/ | ||
var objectToString$1 = objectProto$1.toString; | ||
/* Built-in method references for those with the same name as other `lodash` methods. */ | ||
var nativeMax$1 = Math.max, | ||
nativeMin$1 = Math.min; | ||
/** | ||
* Gets the timestamp of the number of milliseconds that have elapsed since | ||
* the Unix epoch (1 January 1970 00:00:00 UTC). | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 2.4.0 | ||
* @category Date | ||
* @returns {number} Returns the timestamp. | ||
* @example | ||
* | ||
* _.defer(function(stamp) { | ||
* console.log(_.now() - stamp); | ||
* }, _.now()); | ||
* // => Logs the number of milliseconds it took for the deferred invocation. | ||
*/ | ||
var now$1 = function () { | ||
return root$1.Date.now(); | ||
}; | ||
/** | ||
* Creates a debounced function that delays invoking `func` until after `wait` | ||
* milliseconds have elapsed since the last time the debounced function was | ||
* invoked. The debounced function comes with a `cancel` method to cancel | ||
* delayed `func` invocations and a `flush` method to immediately invoke them. | ||
* Provide `options` to indicate whether `func` should be invoked on the | ||
* leading and/or trailing edge of the `wait` timeout. The `func` is invoked | ||
* with the last arguments provided to the debounced function. Subsequent | ||
* calls to the debounced function return the result of the last `func` | ||
* invocation. | ||
* | ||
* **Note:** If `leading` and `trailing` options are `true`, `func` is | ||
* invoked on the trailing edge of the timeout only if the debounced function | ||
* is invoked more than once during the `wait` timeout. | ||
* | ||
* If `wait` is `0` and `leading` is `false`, `func` invocation is deferred | ||
* until to the next tick, similar to `setTimeout` with a timeout of `0`. | ||
* | ||
* See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) | ||
* for details over the differences between `_.debounce` and `_.throttle`. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Function | ||
* @param {Function} func The function to debounce. | ||
* @param {number} [wait=0] The number of milliseconds to delay. | ||
* @param {Object} [options={}] The options object. | ||
* @param {boolean} [options.leading=false] | ||
* Specify invoking on the leading edge of the timeout. | ||
* @param {number} [options.maxWait] | ||
* The maximum time `func` is allowed to be delayed before it's invoked. | ||
* @param {boolean} [options.trailing=true] | ||
* Specify invoking on the trailing edge of the timeout. | ||
* @returns {Function} Returns the new debounced function. | ||
* @example | ||
* | ||
* // Avoid costly calculations while the window size is in flux. | ||
* jQuery(window).on('resize', _.debounce(calculateLayout, 150)); | ||
* | ||
* // Invoke `sendMail` when clicked, debouncing subsequent calls. | ||
* jQuery(element).on('click', _.debounce(sendMail, 300, { | ||
* 'leading': true, | ||
* 'trailing': false | ||
* })); | ||
* | ||
* // Ensure `batchLog` is invoked once after 1 second of debounced calls. | ||
* var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); | ||
* var source = new EventSource('/stream'); | ||
* jQuery(source).on('message', debounced); | ||
* | ||
* // Cancel the trailing debounced invocation. | ||
* jQuery(window).on('popstate', debounced.cancel); | ||
*/ | ||
function debounce$1(func, wait, options) { | ||
var lastArgs, | ||
lastThis, | ||
maxWait, | ||
result, | ||
timerId, | ||
lastCallTime, | ||
lastInvokeTime = 0, | ||
leading = false, | ||
maxing = false, | ||
trailing = true; | ||
if (typeof func != 'function') { | ||
throw new TypeError(FUNC_ERROR_TEXT$1); | ||
} | ||
wait = toNumber$1(wait) || 0; | ||
if (isObject$1(options)) { | ||
leading = !!options.leading; | ||
maxing = 'maxWait' in options; | ||
maxWait = maxing ? nativeMax$1(toNumber$1(options.maxWait) || 0, wait) : maxWait; | ||
trailing = 'trailing' in options ? !!options.trailing : trailing; | ||
} | ||
function invokeFunc(time) { | ||
var args = lastArgs, | ||
thisArg = lastThis; | ||
lastArgs = lastThis = undefined; | ||
lastInvokeTime = time; | ||
result = func.apply(thisArg, args); | ||
return result; | ||
} | ||
function leadingEdge(time) { | ||
// Reset any `maxWait` timer. | ||
lastInvokeTime = time; // Start the timer for the trailing edge. | ||
timerId = setTimeout(timerExpired, wait); // Invoke the leading edge. | ||
return leading ? invokeFunc(time) : result; | ||
} | ||
function remainingWait(time) { | ||
var timeSinceLastCall = time - lastCallTime, | ||
timeSinceLastInvoke = time - lastInvokeTime, | ||
result = wait - timeSinceLastCall; | ||
return maxing ? nativeMin$1(result, maxWait - timeSinceLastInvoke) : result; | ||
} | ||
function shouldInvoke(time) { | ||
var timeSinceLastCall = time - lastCallTime, | ||
timeSinceLastInvoke = time - lastInvokeTime; // Either this is the first call, activity has stopped and we're at the | ||
// trailing edge, the system time has gone backwards and we're treating | ||
// it as the trailing edge, or we've hit the `maxWait` limit. | ||
return lastCallTime === undefined || timeSinceLastCall >= wait || timeSinceLastCall < 0 || maxing && timeSinceLastInvoke >= maxWait; | ||
} | ||
function timerExpired() { | ||
var time = now$1(); | ||
if (shouldInvoke(time)) { | ||
return trailingEdge(time); | ||
} // Restart the timer. | ||
timerId = setTimeout(timerExpired, remainingWait(time)); | ||
} | ||
function trailingEdge(time) { | ||
timerId = undefined; // Only invoke if we have `lastArgs` which means `func` has been | ||
// debounced at least once. | ||
if (trailing && lastArgs) { | ||
return invokeFunc(time); | ||
} | ||
lastArgs = lastThis = undefined; | ||
return result; | ||
} | ||
function cancel() { | ||
if (timerId !== undefined) { | ||
clearTimeout(timerId); | ||
} | ||
lastInvokeTime = 0; | ||
lastArgs = lastCallTime = lastThis = timerId = undefined; | ||
} | ||
function flush() { | ||
return timerId === undefined ? result : trailingEdge(now$1()); | ||
} | ||
function debounced() { | ||
var time = now$1(), | ||
isInvoking = shouldInvoke(time); | ||
lastArgs = arguments; | ||
lastThis = this; | ||
lastCallTime = time; | ||
if (isInvoking) { | ||
if (timerId === undefined) { | ||
return leadingEdge(lastCallTime); | ||
} | ||
if (maxing) { | ||
// Handle invocations in a tight loop. | ||
timerId = setTimeout(timerExpired, wait); | ||
return invokeFunc(lastCallTime); | ||
} | ||
} | ||
if (timerId === undefined) { | ||
timerId = setTimeout(timerExpired, wait); | ||
} | ||
return result; | ||
} | ||
debounced.cancel = cancel; | ||
debounced.flush = flush; | ||
return debounced; | ||
} | ||
/** | ||
* Checks if `value` is the | ||
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) | ||
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 0.1.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is an object, else `false`. | ||
* @example | ||
* | ||
* _.isObject({}); | ||
* // => true | ||
* | ||
* _.isObject([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObject(_.noop); | ||
* // => true | ||
* | ||
* _.isObject(null); | ||
* // => false | ||
*/ | ||
function isObject$1(value) { | ||
var type = typeof value; | ||
return !!value && (type == 'object' || type == 'function'); | ||
} | ||
/** | ||
* Checks if `value` is object-like. A value is object-like if it's not `null` | ||
* and has a `typeof` result of "object". | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is object-like, else `false`. | ||
* @example | ||
* | ||
* _.isObjectLike({}); | ||
* // => true | ||
* | ||
* _.isObjectLike([1, 2, 3]); | ||
* // => true | ||
* | ||
* _.isObjectLike(_.noop); | ||
* // => false | ||
* | ||
* _.isObjectLike(null); | ||
* // => false | ||
*/ | ||
function isObjectLike$1(value) { | ||
return !!value && typeof value == 'object'; | ||
} | ||
/** | ||
* Checks if `value` is classified as a `Symbol` primitive or object. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to check. | ||
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`. | ||
* @example | ||
* | ||
* _.isSymbol(Symbol.iterator); | ||
* // => true | ||
* | ||
* _.isSymbol('abc'); | ||
* // => false | ||
*/ | ||
function isSymbol$1(value) { | ||
return typeof value == 'symbol' || isObjectLike$1(value) && objectToString$1.call(value) == symbolTag$1; | ||
} | ||
/** | ||
* Converts `value` to a number. | ||
* | ||
* @static | ||
* @memberOf _ | ||
* @since 4.0.0 | ||
* @category Lang | ||
* @param {*} value The value to process. | ||
* @returns {number} Returns the number. | ||
* @example | ||
* | ||
* _.toNumber(3.2); | ||
* // => 3.2 | ||
* | ||
* _.toNumber(Number.MIN_VALUE); | ||
* // => 5e-324 | ||
* | ||
* _.toNumber(Infinity); | ||
* // => Infinity | ||
* | ||
* _.toNumber('3.2'); | ||
* // => 3.2 | ||
*/ | ||
function toNumber$1(value) { | ||
if (typeof value == 'number') { | ||
return value; | ||
} | ||
if (isSymbol$1(value)) { | ||
return NAN$1; | ||
} | ||
if (isObject$1(value)) { | ||
var other = typeof value.valueOf == 'function' ? value.valueOf() : value; | ||
value = isObject$1(other) ? other + '' : other; | ||
} | ||
if (typeof value != 'string') { | ||
return value === 0 ? value : +value; | ||
} | ||
value = value.replace(reTrim$1, ''); | ||
var isBinary = reIsBinary$1.test(value); | ||
return isBinary || reIsOctal$1.test(value) ? freeParseInt$1(value.slice(2), isBinary ? 2 : 8) : reIsBadHex$1.test(value) ? NAN$1 : +value; | ||
} | ||
var lodash_debounce = debounce$1; | ||
/** | ||
* lodash (Custom Build) <https://lodash.com/> | ||
* Build: `lodash modularize exports="npm" -o ./` | ||
* Copyright jQuery Foundation and other contributors <https://jquery.org/> | ||
* Released under MIT license <https://lodash.com/license> | ||
* Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE> | ||
* Copyright Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors | ||
*/ | ||
/** Used as the `TypeError` message for "Functions" methods. */ | ||
var FUNC_ERROR_TEXT = 'Expected a function'; | ||
@@ -1181,3 +794,3 @@ /** Used as references for various `Number` constants. */ | ||
case 'debounce': | ||
return lodash_debounce(resizeCallback, refreshRate, refreshOptions); | ||
return debounce$1(resizeCallback, refreshRate, refreshOptions); | ||
@@ -1543,2 +1156,19 @@ case 'throttle': | ||
function setRef(ref, value) { | ||
if (typeof ref === 'function') { | ||
ref(value); | ||
} else if (ref) { | ||
// eslint-disable-next-line no-param-reassign | ||
ref.current = value; | ||
} | ||
} | ||
function useForkRef(refs) { | ||
return useCallback(function (refValue) { | ||
refs.forEach(function (ref) { | ||
return setRef(ref, refValue); | ||
}); | ||
}, refs); | ||
} | ||
var createPopper = popperGenerator({ | ||
@@ -1598,19 +1228,2 @@ defaultModifiers: [preventOverflow, popperOffsets, eventListeners, computeStyles, applyStyles, __assign$1(__assign$1({}, offset), { | ||
function setRef(ref, value) { | ||
if (typeof ref === 'function') { | ||
ref(value); | ||
} else if (ref) { | ||
// eslint-disable-next-line no-param-reassign | ||
ref.current = value; | ||
} | ||
} | ||
function useForkRef(refs) { | ||
return useCallback(function (refValue) { | ||
refs.forEach(function (ref) { | ||
return setRef(ref, refValue); | ||
}); | ||
}, refs); | ||
} | ||
function useEventListener(t, r, i, o) { | ||
@@ -1678,3 +1291,3 @@ void 0 === i && (i = global), void 0 === o && (o = {}); | ||
if (!isScrollable(element)) return; | ||
var debouncedHandler = debounce$2(scrollHandler(onScroll), 50, { | ||
var debouncedHandler = debounce$1(scrollHandler(onScroll), 50, { | ||
leading: true, | ||
@@ -1695,3 +1308,9 @@ trailing: true | ||
export { useAutoPositioner, useClickOutside, useForkRef, useScrollObserver }; | ||
var useId = function (prefix) { | ||
return useMemo(function () { | ||
return uniqueId(prefix); | ||
}, [prefix]); | ||
}; | ||
export { useAutoPositioner, useClickOutside, useForkRef, useId, useScrollObserver }; | ||
//# sourceMappingURL=index.js.map |
{ | ||
"name": "@highlight-ui/utils-hooks", | ||
"version": "3.0.9", | ||
"version": "3.1.0", | ||
"author": "Personio GmbH & Co. KG", | ||
@@ -27,2 +27,3 @@ "main": "dist/cjs/index.js", | ||
"@highlight-ui/configs-scripts": "^3.1.1", | ||
"@highlight-ui/utils-commons": "^2.1.0", | ||
"@popperjs/core": "^2.9.2", | ||
@@ -33,5 +34,5 @@ "@testing-library/dom": "^8.6.0", | ||
"@testing-library/user-event": "^13.2.1", | ||
"@types/lodash": "^4.14.175", | ||
"@types/lodash.debounce": "4.0.7", | ||
"jest": "^27.2.3", | ||
"lodash": "^4.17.21", | ||
"lodash.debounce": "4.0.8", | ||
"react": "^17.0.2", | ||
@@ -42,2 +43,3 @@ "react-dom": "^17.0.2", | ||
"peerDependencies": { | ||
"@highlight-ui/utils-commons": "workspace:^", | ||
"react": "^17.0.2" | ||
@@ -51,3 +53,3 @@ }, | ||
}, | ||
"gitHead": "0df23a84d538f2df9716b9d6eb4ac920619788cf" | ||
"gitHead": "1f06de33d227dce759a0097cc60e24680c79cfda" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19
2
269429
6
15
2271