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.
Files changed (69) hide show
  1. package/CHANGELOG.md +61 -0
  2. package/README.md +32 -0
  3. package/dist/es2015/index.min.mjs +2 -2
  4. package/dist/es2015/index.min.mjs.map +1 -1
  5. package/dist/es2015/index.mjs +103 -66
  6. package/dist/es2015/index.mjs.map +1 -1
  7. package/dist/es2015/index.umd.js +108 -67
  8. package/dist/es2015/index.umd.js.map +1 -1
  9. package/dist/es2015/index.umd.min.js +2 -2
  10. package/dist/es2015/index.umd.min.js.map +1 -1
  11. package/dist/es2018/index.min.mjs +2 -2
  12. package/dist/es2018/index.min.mjs.map +1 -1
  13. package/dist/es2018/index.mjs +103 -66
  14. package/dist/es2018/index.mjs.map +1 -1
  15. package/dist/es2018/index.umd.js +108 -67
  16. package/dist/es2018/index.umd.js.map +1 -1
  17. package/dist/es2018/index.umd.min.js +2 -2
  18. package/dist/es2018/index.umd.min.js.map +1 -1
  19. package/lib/es2015/index.d.ts +4 -0
  20. package/lib/es2015/index.js +4 -0
  21. package/lib/es2015/index.js.map +1 -1
  22. package/lib/es2015/use-force-update.d.ts +1 -0
  23. package/lib/es2015/use-force-update.js +10 -0
  24. package/lib/es2015/use-force-update.js.map +1 -0
  25. package/lib/es2015/use-increment.d.ts +1 -0
  26. package/lib/es2015/use-increment.js +16 -0
  27. package/lib/es2015/use-increment.js.map +1 -0
  28. package/lib/es2015/use-is-mounted.js +2 -2
  29. package/lib/es2015/use-is-mounted.js.map +1 -1
  30. package/lib/es2015/use-mount.js +1 -1
  31. package/lib/es2015/use-mount.js.map +1 -1
  32. package/lib/es2015/use-resize-observer.d.ts +2 -0
  33. package/lib/es2015/use-resize-observer.js +18 -0
  34. package/lib/es2015/use-resize-observer.js.map +1 -0
  35. package/lib/es2015/use-single-selection.js +5 -5
  36. package/lib/es2015/use-single-selection.js.map +1 -1
  37. package/lib/es2015/use-state-cycle.js +8 -5
  38. package/lib/es2015/use-state-cycle.js.map +1 -1
  39. package/lib/es2015/use-step.d.ts +1 -0
  40. package/lib/es2015/use-step.js +32 -0
  41. package/lib/es2015/use-step.js.map +1 -0
  42. package/lib/es2015/use-toggle.js +1 -1
  43. package/lib/es2015/use-toggle.js.map +1 -1
  44. package/lib/es2018/index.d.ts +4 -0
  45. package/lib/es2018/index.js +4 -0
  46. package/lib/es2018/index.js.map +1 -1
  47. package/lib/es2018/use-force-update.d.ts +1 -0
  48. package/lib/es2018/use-force-update.js +10 -0
  49. package/lib/es2018/use-force-update.js.map +1 -0
  50. package/lib/es2018/use-increment.d.ts +1 -0
  51. package/lib/es2018/use-increment.js +16 -0
  52. package/lib/es2018/use-increment.js.map +1 -0
  53. package/lib/es2018/use-is-mounted.js +2 -2
  54. package/lib/es2018/use-is-mounted.js.map +1 -1
  55. package/lib/es2018/use-mount.js +1 -1
  56. package/lib/es2018/use-mount.js.map +1 -1
  57. package/lib/es2018/use-resize-observer.d.ts +2 -0
  58. package/lib/es2018/use-resize-observer.js +18 -0
  59. package/lib/es2018/use-resize-observer.js.map +1 -0
  60. package/lib/es2018/use-single-selection.js +5 -5
  61. package/lib/es2018/use-single-selection.js.map +1 -1
  62. package/lib/es2018/use-state-cycle.js +8 -5
  63. package/lib/es2018/use-state-cycle.js.map +1 -1
  64. package/lib/es2018/use-step.d.ts +1 -0
  65. package/lib/es2018/use-step.js +32 -0
  66. package/lib/es2018/use-step.js.map +1 -0
  67. package/lib/es2018/use-toggle.js +1 -1
  68. package/lib/es2018/use-toggle.js.map +1 -1
  69. package/package.json +28 -22
@@ -2,7 +2,7 @@
2
2
  typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
3
  typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
4
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.ExtraReactHooks = {}));
5
- }(this, (function (exports) { 'use strict';
5
+ })(this, (function (exports) { 'use strict';
6
6
 
7
7
  var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {};
8
8
 
@@ -2462,6 +2462,17 @@
2462
2462
  react.exports = react_development;
2463
2463
  }
2464
2464
 
2465
+ function useIncrement(initialValue) {
2466
+ const [value, setValue] = react.exports.useState(initialValue);
2467
+ const increment = react.exports.useCallback((step = 1) => {
2468
+ setValue(value => value + step);
2469
+ }, []);
2470
+ const reset = react.exports.useCallback(() => {
2471
+ setValue(initialValue);
2472
+ }, []);
2473
+ return [value, increment, reset];
2474
+ }
2475
+
2465
2476
  function useMount(effect) {
2466
2477
  react.exports.useEffect(effect, []);
2467
2478
  }
@@ -2529,8 +2540,8 @@
2529
2540
  const null_1$1 = _null;
2530
2541
  const undefined_1$2 = _undefined;
2531
2542
  function isAsyncIterable(val) {
2532
- return null_1$1.isntNull(val)
2533
- && undefined_1$2.isntUndefined(val)
2543
+ return (0, null_1$1.isntNull)(val)
2544
+ && (0, undefined_1$2.isntUndefined)(val)
2534
2545
  && typeof val[Symbol.asyncIterator] === 'function';
2535
2546
  }
2536
2547
  asyncIterable.isAsyncIterable = isAsyncIterable;
@@ -2567,36 +2578,20 @@
2567
2578
 
2568
2579
  var string = {};
2569
2580
 
2570
- string.isntStringObject = string.isStringObject = string.isntStringPrimitive = string.isStringPrimitive = string.isntString = string.isString = void 0;
2581
+ string.isntString = string.isString = void 0;
2571
2582
  function isString(val) {
2572
- return isStringPrimitive(val) || isStringObject(val);
2583
+ return typeof val === 'string';
2573
2584
  }
2574
2585
  string.isString = isString;
2575
2586
  function isntString(val) {
2576
2587
  return !isString(val);
2577
2588
  }
2578
2589
  string.isntString = isntString;
2579
- function isStringPrimitive(val) {
2580
- return typeof val === 'string';
2581
- }
2582
- string.isStringPrimitive = isStringPrimitive;
2583
- function isntStringPrimitive(val) {
2584
- return !isStringPrimitive(val);
2585
- }
2586
- string.isntStringPrimitive = isntStringPrimitive;
2587
- function isStringObject(val) {
2588
- return typeof val === 'object' && val instanceof String;
2589
- }
2590
- string.isStringObject = isStringObject;
2591
- function isntStringObject(val) {
2592
- return !isStringObject(val);
2593
- }
2594
- string.isntStringObject = isntStringObject;
2595
2590
 
2596
- char.isntCharObject = char.isCharObject = char.isntCharPrimitive = char.isCharPrimitive = char.isntChar = char.isChar = void 0;
2591
+ char.isntChar = char.isChar = void 0;
2597
2592
  const string_1$1 = string;
2598
2593
  function isChar(val) {
2599
- return (string_1$1.isString(val) || string_1$1.isStringObject(val))
2594
+ return (0, string_1$1.isString)(val)
2600
2595
  && val.length === 1;
2601
2596
  }
2602
2597
  char.isChar = isChar;
@@ -2604,24 +2599,6 @@
2604
2599
  return !isChar(val);
2605
2600
  }
2606
2601
  char.isntChar = isntChar;
2607
- function isCharPrimitive(val) {
2608
- return string_1$1.isString(val)
2609
- && val.length === 1;
2610
- }
2611
- char.isCharPrimitive = isCharPrimitive;
2612
- function isntCharPrimitive(val) {
2613
- return !isCharPrimitive(val);
2614
- }
2615
- char.isntCharPrimitive = isntCharPrimitive;
2616
- function isCharObject(val) {
2617
- return string_1$1.isStringObject(val)
2618
- && val.length === 1;
2619
- }
2620
- char.isCharObject = isCharObject;
2621
- function isntCharObject(val) {
2622
- return !isCharObject(val);
2623
- }
2624
- char.isntCharObject = isntCharObject;
2625
2602
 
2626
2603
  var date = {};
2627
2604
 
@@ -2643,6 +2620,18 @@
2643
2620
  }
2644
2621
  _enum.inEnum = inEnum;
2645
2622
 
2623
+ var error = {};
2624
+
2625
+ error.isntError = error.isError = void 0;
2626
+ function isError(val) {
2627
+ return val instanceof Error;
2628
+ }
2629
+ error.isError = isError;
2630
+ function isntError(val) {
2631
+ return !isError(val);
2632
+ }
2633
+ error.isntError = isntError;
2634
+
2646
2635
  var falsy = {};
2647
2636
 
2648
2637
  falsy.isntFalsy = falsy.isFalsy = void 0;
@@ -2673,8 +2662,8 @@
2673
2662
  const null_1 = _null;
2674
2663
  const undefined_1$1 = _undefined;
2675
2664
  function isIterable(val) {
2676
- return null_1.isntNull(val)
2677
- && undefined_1$1.isntUndefined(val)
2665
+ return (0, null_1.isntNull)(val)
2666
+ && (0, undefined_1$1.isntUndefined)(val)
2678
2667
  && typeof val[Symbol.iterator] === 'function';
2679
2668
  }
2680
2669
  iterable.isIterable = isIterable;
@@ -2728,16 +2717,16 @@
2728
2717
  const number_1 = number;
2729
2718
  const undefined_1 = _undefined;
2730
2719
  function isJsonRpcId(val) {
2731
- return string_1.isString(val) || number_1.isNumber(val);
2720
+ return (0, string_1.isString)(val) || (0, number_1.isNumber)(val);
2732
2721
  }
2733
2722
  function isJsonRpcParams(val) {
2734
- return array_1.isArray(val) || object_1.isObject(val);
2723
+ return (0, array_1.isArray)(val) || (0, object_1.isObject)(val);
2735
2724
  }
2736
2725
  function isJsonRpcNotification(val) {
2737
- return object_1.isRecord(val)
2738
- && string_1.isString(val.jsonrpc)
2739
- && string_1.isString(val.method)
2740
- && undefined_1.isUndefined(val.id)
2726
+ return (0, object_1.isRecord)(val)
2727
+ && (0, string_1.isString)(val.jsonrpc)
2728
+ && (0, string_1.isString)(val.method)
2729
+ && (0, undefined_1.isUndefined)(val.id)
2741
2730
  && isJsonRpcParams(val.params);
2742
2731
  }
2743
2732
  jsonRpc.isJsonRpcNotification = isJsonRpcNotification;
@@ -2746,9 +2735,9 @@
2746
2735
  }
2747
2736
  jsonRpc.isntJsonRpcNotification = isntJsonRpcNotification;
2748
2737
  function isJsonRpcRequest(val) {
2749
- return object_1.isRecord(val)
2750
- && string_1.isString(val.jsonrpc)
2751
- && string_1.isString(val.method)
2738
+ return (0, object_1.isRecord)(val)
2739
+ && (0, string_1.isString)(val.jsonrpc)
2740
+ && (0, string_1.isString)(val.method)
2752
2741
  && isJsonRpcId(val.id)
2753
2742
  && isJsonRpcParams(val.params);
2754
2743
  }
@@ -2758,10 +2747,10 @@
2758
2747
  }
2759
2748
  jsonRpc.isntJsonRpcRequest = isntJsonRpcRequest;
2760
2749
  function isJsonRpcSuccess(val) {
2761
- return object_1.isRecord(val)
2762
- && string_1.isString(val.jsonrpc)
2763
- && string_1.isString(val.id)
2764
- && undefined_1.isntUndefined(val.result);
2750
+ return (0, object_1.isRecord)(val)
2751
+ && (0, string_1.isString)(val.jsonrpc)
2752
+ && (0, string_1.isString)(val.id)
2753
+ && 'result' in val;
2765
2754
  }
2766
2755
  jsonRpc.isJsonRpcSuccess = isJsonRpcSuccess;
2767
2756
  function isntJsonRpcSuccess(val) {
@@ -2769,8 +2758,8 @@
2769
2758
  }
2770
2759
  jsonRpc.isntJsonRpcSuccess = isntJsonRpcSuccess;
2771
2760
  function isJsonRpcError(val) {
2772
- return object_1.isRecord(val)
2773
- && string_1.isString(val.jsonrpc)
2761
+ return (0, object_1.isRecord)(val)
2762
+ && (0, string_1.isString)(val.jsonrpc)
2774
2763
  && isJsonRpcId(val.id)
2775
2764
  && isJsonRpcErrorObject(val.error);
2776
2765
  }
@@ -2780,10 +2769,10 @@
2780
2769
  }
2781
2770
  jsonRpc.isntJsonRpcError = isntJsonRpcError;
2782
2771
  function isJsonRpcErrorObject(val) {
2783
- return object_1.isRecord(val)
2784
- && number_1.isNumber(val.code)
2785
- && string_1.isString(val.message)
2786
- && (undefined_1.isUndefined(val.data) || object_1.isObject(val.data));
2772
+ return (0, object_1.isRecord)(val)
2773
+ && (0, number_1.isNumber)(val.code)
2774
+ && (0, string_1.isString)(val.message)
2775
+ && ((0, undefined_1.isUndefined)(val.data) || (0, object_1.isObject)(val.data));
2787
2776
  }
2788
2777
 
2789
2778
  var json = {};
@@ -2835,6 +2824,7 @@
2835
2824
  __exportStar(char, exports);
2836
2825
  __exportStar(date, exports);
2837
2826
  __exportStar(_enum, exports);
2827
+ __exportStar(error, exports);
2838
2828
  __exportStar(falsy, exports);
2839
2829
  __exportStar(_function, exports);
2840
2830
  __exportStar(iterable, exports);
@@ -2948,14 +2938,17 @@
2948
2938
 
2949
2939
  function useStateCycle(stateList, initialStateIndex = 0) {
2950
2940
  const [index, setIndex] = react.exports.useState(initialStateIndex);
2951
- return [stateList[index], () => {
2941
+ return [
2942
+ stateList[index],
2943
+ () => setIndex(index => {
2952
2944
  if (index + 1 < stateList.length) {
2953
- setIndex(index + 1);
2945
+ return index + 1;
2954
2946
  }
2955
2947
  else {
2956
- setIndex(0);
2948
+ return 0;
2957
2949
  }
2958
- }];
2950
+ })
2951
+ ];
2959
2952
  }
2960
2953
 
2961
2954
  function useToggle(initialState = false) {
@@ -2964,13 +2957,61 @@
2964
2957
  return [state, toggle];
2965
2958
  }
2966
2959
 
2960
+ function useResizeObserver(callback, refs) {
2961
+ const deps = refs.map(x => x.current);
2962
+ react.exports.useEffect(() => {
2963
+ const observer = new ResizeObserver(callback);
2964
+ refs
2965
+ .map(x => x.current)
2966
+ .filter(es2018$1.isntNull)
2967
+ .forEach(x => observer.observe(x));
2968
+ return () => observer.disconnect();
2969
+ }, deps);
2970
+ }
2971
+
2972
+ function useStep(steps, initialStepIndex = 0) {
2973
+ const [index, setIndex] = react.exports.useState(initialStepIndex);
2974
+ return [
2975
+ steps[index],
2976
+ () => {
2977
+ setIndex(index => {
2978
+ if (index === steps.length - 1) {
2979
+ return index;
2980
+ }
2981
+ else {
2982
+ return index + 1;
2983
+ }
2984
+ });
2985
+ },
2986
+ () => {
2987
+ setIndex(index => {
2988
+ if (index === 0) {
2989
+ return index;
2990
+ }
2991
+ else {
2992
+ return index - 1;
2993
+ }
2994
+ });
2995
+ }
2996
+ ];
2997
+ }
2998
+
2999
+ function useForceUpdate() {
3000
+ const [, setState] = react.exports.useState({});
3001
+ return () => setState({});
3002
+ }
3003
+
3004
+ exports.useForceUpdate = useForceUpdate;
3005
+ exports.useIncrement = useIncrement;
2967
3006
  exports.useIsMounted = useIsMounted;
2968
3007
  exports.useMount = useMount;
3008
+ exports.useResizeObserver = useResizeObserver;
2969
3009
  exports.useSingleSelection = useSingleSelection;
2970
3010
  exports.useStateCycle = useStateCycle;
3011
+ exports.useStep = useStep;
2971
3012
  exports.useToggle = useToggle;
2972
3013
 
2973
3014
  Object.defineProperty(exports, '__esModule', { value: true });
2974
3015
 
2975
- })));
3016
+ }));
2976
3017
  //# sourceMappingURL=index.umd.js.map