extra-react-hooks 0.1.4 → 0.1.8
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 +61 -0
- package/README.md +32 -0
- package/dist/es2015/index.min.mjs +2 -2
- package/dist/es2015/index.min.mjs.map +1 -1
- package/dist/es2015/index.mjs +103 -66
- package/dist/es2015/index.mjs.map +1 -1
- package/dist/es2015/index.umd.js +108 -67
- package/dist/es2015/index.umd.js.map +1 -1
- package/dist/es2015/index.umd.min.js +2 -2
- package/dist/es2015/index.umd.min.js.map +1 -1
- package/dist/es2018/index.min.mjs +2 -2
- package/dist/es2018/index.min.mjs.map +1 -1
- package/dist/es2018/index.mjs +103 -66
- package/dist/es2018/index.mjs.map +1 -1
- package/dist/es2018/index.umd.js +108 -67
- package/dist/es2018/index.umd.js.map +1 -1
- package/dist/es2018/index.umd.min.js +2 -2
- package/dist/es2018/index.umd.min.js.map +1 -1
- package/lib/es2015/index.d.ts +4 -0
- package/lib/es2015/index.js +4 -0
- package/lib/es2015/index.js.map +1 -1
- package/lib/es2015/use-force-update.d.ts +1 -0
- package/lib/es2015/use-force-update.js +10 -0
- package/lib/es2015/use-force-update.js.map +1 -0
- package/lib/es2015/use-increment.d.ts +1 -0
- package/lib/es2015/use-increment.js +16 -0
- package/lib/es2015/use-increment.js.map +1 -0
- package/lib/es2015/use-is-mounted.js +2 -2
- package/lib/es2015/use-is-mounted.js.map +1 -1
- package/lib/es2015/use-mount.js +1 -1
- package/lib/es2015/use-mount.js.map +1 -1
- package/lib/es2015/use-resize-observer.d.ts +2 -0
- package/lib/es2015/use-resize-observer.js +18 -0
- package/lib/es2015/use-resize-observer.js.map +1 -0
- package/lib/es2015/use-single-selection.js +5 -5
- package/lib/es2015/use-single-selection.js.map +1 -1
- package/lib/es2015/use-state-cycle.js +8 -5
- package/lib/es2015/use-state-cycle.js.map +1 -1
- package/lib/es2015/use-step.d.ts +1 -0
- package/lib/es2015/use-step.js +32 -0
- package/lib/es2015/use-step.js.map +1 -0
- package/lib/es2015/use-toggle.js +1 -1
- package/lib/es2015/use-toggle.js.map +1 -1
- package/lib/es2018/index.d.ts +4 -0
- package/lib/es2018/index.js +4 -0
- package/lib/es2018/index.js.map +1 -1
- package/lib/es2018/use-force-update.d.ts +1 -0
- package/lib/es2018/use-force-update.js +10 -0
- package/lib/es2018/use-force-update.js.map +1 -0
- package/lib/es2018/use-increment.d.ts +1 -0
- package/lib/es2018/use-increment.js +16 -0
- package/lib/es2018/use-increment.js.map +1 -0
- package/lib/es2018/use-is-mounted.js +2 -2
- package/lib/es2018/use-is-mounted.js.map +1 -1
- package/lib/es2018/use-mount.js +1 -1
- package/lib/es2018/use-mount.js.map +1 -1
- package/lib/es2018/use-resize-observer.d.ts +2 -0
- package/lib/es2018/use-resize-observer.js +18 -0
- package/lib/es2018/use-resize-observer.js.map +1 -0
- package/lib/es2018/use-single-selection.js +5 -5
- package/lib/es2018/use-single-selection.js.map +1 -1
- package/lib/es2018/use-state-cycle.js +8 -5
- package/lib/es2018/use-state-cycle.js.map +1 -1
- package/lib/es2018/use-step.d.ts +1 -0
- package/lib/es2018/use-step.js +32 -0
- package/lib/es2018/use-step.js.map +1 -0
- package/lib/es2018/use-toggle.js +1 -1
- package/lib/es2018/use-toggle.js.map +1 -1
- package/package.json +28 -22
package/dist/es2018/index.mjs
CHANGED
|
@@ -2456,6 +2456,17 @@ if (process.env.NODE_ENV === 'production') {
|
|
|
2456
2456
|
react.exports = react_development;
|
|
2457
2457
|
}
|
|
2458
2458
|
|
|
2459
|
+
function useIncrement(initialValue) {
|
|
2460
|
+
const [value, setValue] = react.exports.useState(initialValue);
|
|
2461
|
+
const increment = react.exports.useCallback((step = 1) => {
|
|
2462
|
+
setValue(value => value + step);
|
|
2463
|
+
}, []);
|
|
2464
|
+
const reset = react.exports.useCallback(() => {
|
|
2465
|
+
setValue(initialValue);
|
|
2466
|
+
}, []);
|
|
2467
|
+
return [value, increment, reset];
|
|
2468
|
+
}
|
|
2469
|
+
|
|
2459
2470
|
function useMount(effect) {
|
|
2460
2471
|
react.exports.useEffect(effect, []);
|
|
2461
2472
|
}
|
|
@@ -2523,8 +2534,8 @@ asyncIterable.isntAsyncIterable = asyncIterable.isAsyncIterable = void 0;
|
|
|
2523
2534
|
const null_1$1 = _null;
|
|
2524
2535
|
const undefined_1$2 = _undefined;
|
|
2525
2536
|
function isAsyncIterable(val) {
|
|
2526
|
-
return null_1$1.isntNull(val)
|
|
2527
|
-
&& undefined_1$2.isntUndefined(val)
|
|
2537
|
+
return (0, null_1$1.isntNull)(val)
|
|
2538
|
+
&& (0, undefined_1$2.isntUndefined)(val)
|
|
2528
2539
|
&& typeof val[Symbol.asyncIterator] === 'function';
|
|
2529
2540
|
}
|
|
2530
2541
|
asyncIterable.isAsyncIterable = isAsyncIterable;
|
|
@@ -2561,36 +2572,20 @@ var char = {};
|
|
|
2561
2572
|
|
|
2562
2573
|
var string = {};
|
|
2563
2574
|
|
|
2564
|
-
string.
|
|
2575
|
+
string.isntString = string.isString = void 0;
|
|
2565
2576
|
function isString(val) {
|
|
2566
|
-
return
|
|
2577
|
+
return typeof val === 'string';
|
|
2567
2578
|
}
|
|
2568
2579
|
string.isString = isString;
|
|
2569
2580
|
function isntString(val) {
|
|
2570
2581
|
return !isString(val);
|
|
2571
2582
|
}
|
|
2572
2583
|
string.isntString = isntString;
|
|
2573
|
-
function isStringPrimitive(val) {
|
|
2574
|
-
return typeof val === 'string';
|
|
2575
|
-
}
|
|
2576
|
-
string.isStringPrimitive = isStringPrimitive;
|
|
2577
|
-
function isntStringPrimitive(val) {
|
|
2578
|
-
return !isStringPrimitive(val);
|
|
2579
|
-
}
|
|
2580
|
-
string.isntStringPrimitive = isntStringPrimitive;
|
|
2581
|
-
function isStringObject(val) {
|
|
2582
|
-
return typeof val === 'object' && val instanceof String;
|
|
2583
|
-
}
|
|
2584
|
-
string.isStringObject = isStringObject;
|
|
2585
|
-
function isntStringObject(val) {
|
|
2586
|
-
return !isStringObject(val);
|
|
2587
|
-
}
|
|
2588
|
-
string.isntStringObject = isntStringObject;
|
|
2589
2584
|
|
|
2590
|
-
char.
|
|
2585
|
+
char.isntChar = char.isChar = void 0;
|
|
2591
2586
|
const string_1$1 = string;
|
|
2592
2587
|
function isChar(val) {
|
|
2593
|
-
return (string_1$1.isString
|
|
2588
|
+
return (0, string_1$1.isString)(val)
|
|
2594
2589
|
&& val.length === 1;
|
|
2595
2590
|
}
|
|
2596
2591
|
char.isChar = isChar;
|
|
@@ -2598,24 +2593,6 @@ function isntChar(val) {
|
|
|
2598
2593
|
return !isChar(val);
|
|
2599
2594
|
}
|
|
2600
2595
|
char.isntChar = isntChar;
|
|
2601
|
-
function isCharPrimitive(val) {
|
|
2602
|
-
return string_1$1.isString(val)
|
|
2603
|
-
&& val.length === 1;
|
|
2604
|
-
}
|
|
2605
|
-
char.isCharPrimitive = isCharPrimitive;
|
|
2606
|
-
function isntCharPrimitive(val) {
|
|
2607
|
-
return !isCharPrimitive(val);
|
|
2608
|
-
}
|
|
2609
|
-
char.isntCharPrimitive = isntCharPrimitive;
|
|
2610
|
-
function isCharObject(val) {
|
|
2611
|
-
return string_1$1.isStringObject(val)
|
|
2612
|
-
&& val.length === 1;
|
|
2613
|
-
}
|
|
2614
|
-
char.isCharObject = isCharObject;
|
|
2615
|
-
function isntCharObject(val) {
|
|
2616
|
-
return !isCharObject(val);
|
|
2617
|
-
}
|
|
2618
|
-
char.isntCharObject = isntCharObject;
|
|
2619
2596
|
|
|
2620
2597
|
var date = {};
|
|
2621
2598
|
|
|
@@ -2637,6 +2614,18 @@ function inEnum(val, _enum) {
|
|
|
2637
2614
|
}
|
|
2638
2615
|
_enum.inEnum = inEnum;
|
|
2639
2616
|
|
|
2617
|
+
var error = {};
|
|
2618
|
+
|
|
2619
|
+
error.isntError = error.isError = void 0;
|
|
2620
|
+
function isError(val) {
|
|
2621
|
+
return val instanceof Error;
|
|
2622
|
+
}
|
|
2623
|
+
error.isError = isError;
|
|
2624
|
+
function isntError(val) {
|
|
2625
|
+
return !isError(val);
|
|
2626
|
+
}
|
|
2627
|
+
error.isntError = isntError;
|
|
2628
|
+
|
|
2640
2629
|
var falsy = {};
|
|
2641
2630
|
|
|
2642
2631
|
falsy.isntFalsy = falsy.isFalsy = void 0;
|
|
@@ -2667,8 +2656,8 @@ iterable.isntIterable = iterable.isIterable = void 0;
|
|
|
2667
2656
|
const null_1 = _null;
|
|
2668
2657
|
const undefined_1$1 = _undefined;
|
|
2669
2658
|
function isIterable(val) {
|
|
2670
|
-
return null_1.isntNull(val)
|
|
2671
|
-
&& undefined_1$1.isntUndefined(val)
|
|
2659
|
+
return (0, null_1.isntNull)(val)
|
|
2660
|
+
&& (0, undefined_1$1.isntUndefined)(val)
|
|
2672
2661
|
&& typeof val[Symbol.iterator] === 'function';
|
|
2673
2662
|
}
|
|
2674
2663
|
iterable.isIterable = isIterable;
|
|
@@ -2722,16 +2711,16 @@ const string_1 = string;
|
|
|
2722
2711
|
const number_1 = number;
|
|
2723
2712
|
const undefined_1 = _undefined;
|
|
2724
2713
|
function isJsonRpcId(val) {
|
|
2725
|
-
return string_1.isString(val) || number_1.isNumber(val);
|
|
2714
|
+
return (0, string_1.isString)(val) || (0, number_1.isNumber)(val);
|
|
2726
2715
|
}
|
|
2727
2716
|
function isJsonRpcParams(val) {
|
|
2728
|
-
return array_1.isArray(val) || object_1.isObject(val);
|
|
2717
|
+
return (0, array_1.isArray)(val) || (0, object_1.isObject)(val);
|
|
2729
2718
|
}
|
|
2730
2719
|
function isJsonRpcNotification(val) {
|
|
2731
|
-
return object_1.isRecord(val)
|
|
2732
|
-
&& string_1.isString(val.jsonrpc)
|
|
2733
|
-
&& string_1.isString(val.method)
|
|
2734
|
-
&& undefined_1.isUndefined(val.id)
|
|
2720
|
+
return (0, object_1.isRecord)(val)
|
|
2721
|
+
&& (0, string_1.isString)(val.jsonrpc)
|
|
2722
|
+
&& (0, string_1.isString)(val.method)
|
|
2723
|
+
&& (0, undefined_1.isUndefined)(val.id)
|
|
2735
2724
|
&& isJsonRpcParams(val.params);
|
|
2736
2725
|
}
|
|
2737
2726
|
jsonRpc.isJsonRpcNotification = isJsonRpcNotification;
|
|
@@ -2740,9 +2729,9 @@ function isntJsonRpcNotification(val) {
|
|
|
2740
2729
|
}
|
|
2741
2730
|
jsonRpc.isntJsonRpcNotification = isntJsonRpcNotification;
|
|
2742
2731
|
function isJsonRpcRequest(val) {
|
|
2743
|
-
return object_1.isRecord(val)
|
|
2744
|
-
&& string_1.isString(val.jsonrpc)
|
|
2745
|
-
&& string_1.isString(val.method)
|
|
2732
|
+
return (0, object_1.isRecord)(val)
|
|
2733
|
+
&& (0, string_1.isString)(val.jsonrpc)
|
|
2734
|
+
&& (0, string_1.isString)(val.method)
|
|
2746
2735
|
&& isJsonRpcId(val.id)
|
|
2747
2736
|
&& isJsonRpcParams(val.params);
|
|
2748
2737
|
}
|
|
@@ -2752,10 +2741,10 @@ function isntJsonRpcRequest(val) {
|
|
|
2752
2741
|
}
|
|
2753
2742
|
jsonRpc.isntJsonRpcRequest = isntJsonRpcRequest;
|
|
2754
2743
|
function isJsonRpcSuccess(val) {
|
|
2755
|
-
return object_1.isRecord(val)
|
|
2756
|
-
&& string_1.isString(val.jsonrpc)
|
|
2757
|
-
&& string_1.isString(val.id)
|
|
2758
|
-
&&
|
|
2744
|
+
return (0, object_1.isRecord)(val)
|
|
2745
|
+
&& (0, string_1.isString)(val.jsonrpc)
|
|
2746
|
+
&& (0, string_1.isString)(val.id)
|
|
2747
|
+
&& 'result' in val;
|
|
2759
2748
|
}
|
|
2760
2749
|
jsonRpc.isJsonRpcSuccess = isJsonRpcSuccess;
|
|
2761
2750
|
function isntJsonRpcSuccess(val) {
|
|
@@ -2763,8 +2752,8 @@ function isntJsonRpcSuccess(val) {
|
|
|
2763
2752
|
}
|
|
2764
2753
|
jsonRpc.isntJsonRpcSuccess = isntJsonRpcSuccess;
|
|
2765
2754
|
function isJsonRpcError(val) {
|
|
2766
|
-
return object_1.isRecord(val)
|
|
2767
|
-
&& string_1.isString(val.jsonrpc)
|
|
2755
|
+
return (0, object_1.isRecord)(val)
|
|
2756
|
+
&& (0, string_1.isString)(val.jsonrpc)
|
|
2768
2757
|
&& isJsonRpcId(val.id)
|
|
2769
2758
|
&& isJsonRpcErrorObject(val.error);
|
|
2770
2759
|
}
|
|
@@ -2774,10 +2763,10 @@ function isntJsonRpcError(val) {
|
|
|
2774
2763
|
}
|
|
2775
2764
|
jsonRpc.isntJsonRpcError = isntJsonRpcError;
|
|
2776
2765
|
function isJsonRpcErrorObject(val) {
|
|
2777
|
-
return object_1.isRecord(val)
|
|
2778
|
-
&& number_1.isNumber(val.code)
|
|
2779
|
-
&& string_1.isString(val.message)
|
|
2780
|
-
&& (undefined_1.isUndefined(val.data) || object_1.isObject(val.data));
|
|
2766
|
+
return (0, object_1.isRecord)(val)
|
|
2767
|
+
&& (0, number_1.isNumber)(val.code)
|
|
2768
|
+
&& (0, string_1.isString)(val.message)
|
|
2769
|
+
&& ((0, undefined_1.isUndefined)(val.data) || (0, object_1.isObject)(val.data));
|
|
2781
2770
|
}
|
|
2782
2771
|
|
|
2783
2772
|
var json = {};
|
|
@@ -2829,6 +2818,7 @@ __exportStar(boolean, exports);
|
|
|
2829
2818
|
__exportStar(char, exports);
|
|
2830
2819
|
__exportStar(date, exports);
|
|
2831
2820
|
__exportStar(_enum, exports);
|
|
2821
|
+
__exportStar(error, exports);
|
|
2832
2822
|
__exportStar(falsy, exports);
|
|
2833
2823
|
__exportStar(_function, exports);
|
|
2834
2824
|
__exportStar(iterable, exports);
|
|
@@ -2942,14 +2932,17 @@ function useSingleSelection(values, defaultIndex) {
|
|
|
2942
2932
|
|
|
2943
2933
|
function useStateCycle(stateList, initialStateIndex = 0) {
|
|
2944
2934
|
const [index, setIndex] = react.exports.useState(initialStateIndex);
|
|
2945
|
-
return [
|
|
2935
|
+
return [
|
|
2936
|
+
stateList[index],
|
|
2937
|
+
() => setIndex(index => {
|
|
2946
2938
|
if (index + 1 < stateList.length) {
|
|
2947
|
-
|
|
2939
|
+
return index + 1;
|
|
2948
2940
|
}
|
|
2949
2941
|
else {
|
|
2950
|
-
|
|
2942
|
+
return 0;
|
|
2951
2943
|
}
|
|
2952
|
-
}
|
|
2944
|
+
})
|
|
2945
|
+
];
|
|
2953
2946
|
}
|
|
2954
2947
|
|
|
2955
2948
|
function useToggle(initialState = false) {
|
|
@@ -2958,5 +2951,49 @@ function useToggle(initialState = false) {
|
|
|
2958
2951
|
return [state, toggle];
|
|
2959
2952
|
}
|
|
2960
2953
|
|
|
2961
|
-
|
|
2954
|
+
function useResizeObserver(callback, refs) {
|
|
2955
|
+
const deps = refs.map(x => x.current);
|
|
2956
|
+
react.exports.useEffect(() => {
|
|
2957
|
+
const observer = new ResizeObserver(callback);
|
|
2958
|
+
refs
|
|
2959
|
+
.map(x => x.current)
|
|
2960
|
+
.filter(es2018$1.isntNull)
|
|
2961
|
+
.forEach(x => observer.observe(x));
|
|
2962
|
+
return () => observer.disconnect();
|
|
2963
|
+
}, deps);
|
|
2964
|
+
}
|
|
2965
|
+
|
|
2966
|
+
function useStep(steps, initialStepIndex = 0) {
|
|
2967
|
+
const [index, setIndex] = react.exports.useState(initialStepIndex);
|
|
2968
|
+
return [
|
|
2969
|
+
steps[index],
|
|
2970
|
+
() => {
|
|
2971
|
+
setIndex(index => {
|
|
2972
|
+
if (index === steps.length - 1) {
|
|
2973
|
+
return index;
|
|
2974
|
+
}
|
|
2975
|
+
else {
|
|
2976
|
+
return index + 1;
|
|
2977
|
+
}
|
|
2978
|
+
});
|
|
2979
|
+
},
|
|
2980
|
+
() => {
|
|
2981
|
+
setIndex(index => {
|
|
2982
|
+
if (index === 0) {
|
|
2983
|
+
return index;
|
|
2984
|
+
}
|
|
2985
|
+
else {
|
|
2986
|
+
return index - 1;
|
|
2987
|
+
}
|
|
2988
|
+
});
|
|
2989
|
+
}
|
|
2990
|
+
];
|
|
2991
|
+
}
|
|
2992
|
+
|
|
2993
|
+
function useForceUpdate() {
|
|
2994
|
+
const [, setState] = react.exports.useState({});
|
|
2995
|
+
return () => setState({});
|
|
2996
|
+
}
|
|
2997
|
+
|
|
2998
|
+
export { useForceUpdate, useIncrement, useIsMounted, useMount, useResizeObserver, useSingleSelection, useStateCycle, useStep, useToggle };
|
|
2962
2999
|
//# sourceMappingURL=index.mjs.map
|