react-kanca 1.2.0 → 1.3.1
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/README.md +35 -21
- package/dist/index.js +229 -32
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +221 -32
- package/dist/index.modern.js.map +1 -1
- package/package.json +6 -6
package/dist/index.modern.js
CHANGED
|
@@ -40,19 +40,23 @@ var useWindowSize = function useWindowSize() {
|
|
|
40
40
|
return size;
|
|
41
41
|
};
|
|
42
42
|
|
|
43
|
-
var useDebounce = function useDebounce(
|
|
44
|
-
var _useState = useState(
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
43
|
+
var useDebounce = function useDebounce() {
|
|
44
|
+
var _useState = useState(null),
|
|
45
|
+
debouncedValue = _useState[0],
|
|
46
|
+
setDebouncedValue = _useState[1];
|
|
47
|
+
var debounce = function debounce(value, delay) {
|
|
48
48
|
var handler = setTimeout(function () {
|
|
49
|
-
|
|
49
|
+
if (typeof value === 'function') {
|
|
50
|
+
value();
|
|
51
|
+
} else {
|
|
52
|
+
setDebouncedValue(value);
|
|
53
|
+
}
|
|
50
54
|
}, delay);
|
|
51
55
|
return function () {
|
|
52
56
|
clearTimeout(handler);
|
|
53
57
|
};
|
|
54
|
-
}
|
|
55
|
-
return debounce;
|
|
58
|
+
};
|
|
59
|
+
return [debouncedValue, debounce];
|
|
56
60
|
};
|
|
57
61
|
|
|
58
62
|
var usePrevious = function usePrevious(value) {
|
|
@@ -186,16 +190,16 @@ var useThrottle = function useThrottle(value, ms) {
|
|
|
186
190
|
useEffect(function () {
|
|
187
191
|
if (!timeout.current) {
|
|
188
192
|
setState(value);
|
|
189
|
-
var
|
|
193
|
+
var _timeoutCallback = function timeoutCallback() {
|
|
190
194
|
if (hasNextValue.current) {
|
|
191
195
|
hasNextValue.current = false;
|
|
192
196
|
setState(nextValue.current);
|
|
193
|
-
timeout.current = setTimeout(
|
|
197
|
+
timeout.current = setTimeout(_timeoutCallback, ms);
|
|
194
198
|
} else {
|
|
195
199
|
timeout.current = undefined;
|
|
196
200
|
}
|
|
197
201
|
};
|
|
198
|
-
timeout.current = setTimeout(
|
|
202
|
+
timeout.current = setTimeout(_timeoutCallback, ms);
|
|
199
203
|
} else {
|
|
200
204
|
nextValue.current = value;
|
|
201
205
|
hasNextValue.current = true;
|
|
@@ -262,7 +266,7 @@ var useLocalStorage = function useLocalStorage(key, initialValue, options) {
|
|
|
262
266
|
return [state, set, remove];
|
|
263
267
|
};
|
|
264
268
|
|
|
265
|
-
var
|
|
269
|
+
var _useEqualObject = function useEqualObject(obj1, obj2) {
|
|
266
270
|
if (obj1 === obj2) return true;
|
|
267
271
|
if (typeof obj1 !== 'object' || typeof obj2 !== 'object' || obj1 === null || obj2 === null) return false;
|
|
268
272
|
var keys1 = Object.keys(obj1);
|
|
@@ -270,7 +274,7 @@ var useEqualObject = function useEqualObject(obj1, obj2) {
|
|
|
270
274
|
if (keys1.length !== keys2.length) return false;
|
|
271
275
|
for (var _i = 0, _keys = keys1; _i < _keys.length; _i++) {
|
|
272
276
|
var key = _keys[_i];
|
|
273
|
-
if (!keys2.includes(key) || !
|
|
277
|
+
if (!keys2.includes(key) || !_useEqualObject(obj1[key], obj2[key])) return false;
|
|
274
278
|
}
|
|
275
279
|
return true;
|
|
276
280
|
};
|
|
@@ -293,18 +297,13 @@ var useCookie = function useCookie(cookieName) {
|
|
|
293
297
|
};
|
|
294
298
|
|
|
295
299
|
function _extends() {
|
|
296
|
-
_extends = Object.assign ? Object.assign.bind() : function (
|
|
297
|
-
for (var
|
|
298
|
-
var
|
|
299
|
-
for (var
|
|
300
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
301
|
-
target[key] = source[key];
|
|
302
|
-
}
|
|
303
|
-
}
|
|
300
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
301
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
302
|
+
var t = arguments[e];
|
|
303
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
304
304
|
}
|
|
305
|
-
return
|
|
306
|
-
};
|
|
307
|
-
return _extends.apply(this, arguments);
|
|
305
|
+
return n;
|
|
306
|
+
}, _extends.apply(null, arguments);
|
|
308
307
|
}
|
|
309
308
|
|
|
310
309
|
var useGeolocation = function useGeolocation(options) {
|
|
@@ -415,11 +414,8 @@ var useBatteryInfo = function useBatteryInfo() {
|
|
|
415
414
|
isCharging = _useState2[0],
|
|
416
415
|
setIsCharging = _useState2[1];
|
|
417
416
|
var _useState3 = useState(null),
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
var _useState4 = useState(null),
|
|
421
|
-
dischargingTime = _useState4[0],
|
|
422
|
-
setDischargingTime = _useState4[1];
|
|
417
|
+
dischargingTime = _useState3[0],
|
|
418
|
+
setDischargingTime = _useState3[1];
|
|
423
419
|
useEffect(function () {
|
|
424
420
|
var getBatteryInfo = function getBatteryInfo() {
|
|
425
421
|
try {
|
|
@@ -428,7 +424,6 @@ var useBatteryInfo = function useBatteryInfo() {
|
|
|
428
424
|
var updateBatteryInfo = function updateBatteryInfo() {
|
|
429
425
|
setBatteryLevel(Math.round(battery.level * 100));
|
|
430
426
|
setIsCharging(battery.charging);
|
|
431
|
-
setChargingTime(battery.chargingTime);
|
|
432
427
|
setDischargingTime(battery.dischargingTime);
|
|
433
428
|
};
|
|
434
429
|
updateBatteryInfo();
|
|
@@ -456,7 +451,6 @@ var useBatteryInfo = function useBatteryInfo() {
|
|
|
456
451
|
return {
|
|
457
452
|
batteryLevel: batteryLevel,
|
|
458
453
|
isCharging: isCharging,
|
|
459
|
-
chargingTime: chargingTime,
|
|
460
454
|
dischargingTime: dischargingTime
|
|
461
455
|
};
|
|
462
456
|
};
|
|
@@ -654,5 +648,200 @@ var useForceUpdate = function useForceUpdate() {
|
|
|
654
648
|
return update;
|
|
655
649
|
};
|
|
656
650
|
|
|
657
|
-
|
|
651
|
+
var useInterval = function useInterval(callback, delay) {
|
|
652
|
+
var savedCallback = useRef(function () {});
|
|
653
|
+
useEffect(function () {
|
|
654
|
+
savedCallback.current = callback;
|
|
655
|
+
});
|
|
656
|
+
useEffect(function () {
|
|
657
|
+
if (delay !== null) {
|
|
658
|
+
var interval = setInterval(function () {
|
|
659
|
+
return savedCallback.current();
|
|
660
|
+
}, delay || 0);
|
|
661
|
+
return function () {
|
|
662
|
+
return clearInterval(interval);
|
|
663
|
+
};
|
|
664
|
+
}
|
|
665
|
+
return undefined;
|
|
666
|
+
}, [delay]);
|
|
667
|
+
};
|
|
668
|
+
|
|
669
|
+
var useIntersectionObserver = function useIntersectionObserver(targetRef, options) {
|
|
670
|
+
var _useState = useState(false),
|
|
671
|
+
isIntersecting = _useState[0],
|
|
672
|
+
setIsIntersecting = _useState[1];
|
|
673
|
+
useEffect(function () {
|
|
674
|
+
var observer = new IntersectionObserver(function (_ref) {
|
|
675
|
+
var entry = _ref[0];
|
|
676
|
+
setIsIntersecting(entry.isIntersecting);
|
|
677
|
+
}, options);
|
|
678
|
+
if (targetRef.current) {
|
|
679
|
+
observer.observe(targetRef.current);
|
|
680
|
+
}
|
|
681
|
+
return function () {
|
|
682
|
+
if (targetRef.current) {
|
|
683
|
+
observer.unobserve(targetRef.current);
|
|
684
|
+
}
|
|
685
|
+
};
|
|
686
|
+
}, [targetRef, options]);
|
|
687
|
+
return isIntersecting;
|
|
688
|
+
};
|
|
689
|
+
|
|
690
|
+
var useMobileLandscape = function useMobileLandscape() {
|
|
691
|
+
var _useState = useState(false),
|
|
692
|
+
isLandscape = _useState[0],
|
|
693
|
+
setIsLandscape = _useState[1];
|
|
694
|
+
var _useState2 = useState(false),
|
|
695
|
+
isMobile = _useState2[0],
|
|
696
|
+
setIsMobile = _useState2[1];
|
|
697
|
+
var _useState3 = useState(false),
|
|
698
|
+
isMobileLandscape = _useState3[0],
|
|
699
|
+
setIsMobileLandscape = _useState3[1];
|
|
700
|
+
var handleResize = function handleResize() {
|
|
701
|
+
var landscape = window.innerWidth > window.innerHeight;
|
|
702
|
+
var mobile = window.innerWidth <= 996;
|
|
703
|
+
setIsLandscape(landscape);
|
|
704
|
+
setIsMobile(mobile);
|
|
705
|
+
setIsMobileLandscape(landscape && mobile);
|
|
706
|
+
};
|
|
707
|
+
useEffect(function () {
|
|
708
|
+
handleResize();
|
|
709
|
+
window.addEventListener('resize', handleResize);
|
|
710
|
+
return function () {
|
|
711
|
+
window.removeEventListener('resize', handleResize);
|
|
712
|
+
};
|
|
713
|
+
}, []);
|
|
714
|
+
return {
|
|
715
|
+
isMobileLandscape: isMobileLandscape,
|
|
716
|
+
isLandscape: isLandscape,
|
|
717
|
+
isMobile: isMobile
|
|
718
|
+
};
|
|
719
|
+
};
|
|
720
|
+
|
|
721
|
+
var useOnlineStatus = function useOnlineStatus() {
|
|
722
|
+
var _useState = useState(navigator.onLine),
|
|
723
|
+
isOnline = _useState[0],
|
|
724
|
+
setIsOnline = _useState[1];
|
|
725
|
+
useEffect(function () {
|
|
726
|
+
var handleOnline = function handleOnline() {
|
|
727
|
+
return setIsOnline(true);
|
|
728
|
+
};
|
|
729
|
+
var handleOffline = function handleOffline() {
|
|
730
|
+
return setIsOnline(false);
|
|
731
|
+
};
|
|
732
|
+
window.addEventListener('online', handleOnline);
|
|
733
|
+
window.addEventListener('offline', handleOffline);
|
|
734
|
+
return function () {
|
|
735
|
+
window.removeEventListener('online', handleOnline);
|
|
736
|
+
window.removeEventListener('offline', handleOffline);
|
|
737
|
+
};
|
|
738
|
+
}, []);
|
|
739
|
+
return isOnline;
|
|
740
|
+
};
|
|
741
|
+
|
|
742
|
+
var useScrollToElement = function useScrollToElement() {
|
|
743
|
+
var scrollToElement = useCallback(function (selectorOrRef, options) {
|
|
744
|
+
if (options === void 0) {
|
|
745
|
+
options = {};
|
|
746
|
+
}
|
|
747
|
+
var element;
|
|
748
|
+
if (typeof selectorOrRef === 'string') {
|
|
749
|
+
element = document.querySelector(selectorOrRef);
|
|
750
|
+
} else if (selectorOrRef.current) {
|
|
751
|
+
element = selectorOrRef.current;
|
|
752
|
+
}
|
|
753
|
+
if (element) {
|
|
754
|
+
element.scrollIntoView(_extends({
|
|
755
|
+
behavior: 'smooth'
|
|
756
|
+
}, options));
|
|
757
|
+
}
|
|
758
|
+
}, []);
|
|
759
|
+
return scrollToElement;
|
|
760
|
+
};
|
|
761
|
+
|
|
762
|
+
var useStateValidator = function useStateValidator(state, validator, initialState) {
|
|
763
|
+
if (initialState === void 0) {
|
|
764
|
+
initialState = [undefined];
|
|
765
|
+
}
|
|
766
|
+
var validatorInner = useRef(validator);
|
|
767
|
+
var stateInner = useRef(state);
|
|
768
|
+
validatorInner.current = validator;
|
|
769
|
+
stateInner.current = state;
|
|
770
|
+
var _useState = useState(initialState),
|
|
771
|
+
validity = _useState[0],
|
|
772
|
+
setValidity = _useState[1];
|
|
773
|
+
var validate = useCallback(function () {
|
|
774
|
+
if (validatorInner.current.length >= 2) {
|
|
775
|
+
validatorInner.current(stateInner.current, setValidity);
|
|
776
|
+
} else {
|
|
777
|
+
setValidity(validatorInner.current(stateInner.current));
|
|
778
|
+
}
|
|
779
|
+
}, [setValidity]);
|
|
780
|
+
useEffect(function () {
|
|
781
|
+
validate();
|
|
782
|
+
}, [state]);
|
|
783
|
+
return [validity, validate];
|
|
784
|
+
};
|
|
785
|
+
|
|
786
|
+
var useMultiStateValidator = function useMultiStateValidator(states, validator, initialValidity) {
|
|
787
|
+
if (initialValidity === void 0) {
|
|
788
|
+
initialValidity = [undefined];
|
|
789
|
+
}
|
|
790
|
+
if (typeof states !== 'object') {
|
|
791
|
+
throw new Error("state'in bir nesne ya da dizi olması beklenirken -> " + typeof states);
|
|
792
|
+
}
|
|
793
|
+
var validatorInner = useRef(validator);
|
|
794
|
+
var statesInner = useRef(states);
|
|
795
|
+
validatorInner.current = validator;
|
|
796
|
+
statesInner.current = states;
|
|
797
|
+
var _useState = useState(initialValidity),
|
|
798
|
+
validity = _useState[0],
|
|
799
|
+
setValidity = _useState[1];
|
|
800
|
+
var validate = useCallback(function () {
|
|
801
|
+
if (validatorInner.current.length >= 2) {
|
|
802
|
+
validatorInner.current(statesInner.current, setValidity);
|
|
803
|
+
} else {
|
|
804
|
+
setValidity(validatorInner.current(statesInner.current));
|
|
805
|
+
}
|
|
806
|
+
}, [setValidity]);
|
|
807
|
+
useEffect(function () {
|
|
808
|
+
validate();
|
|
809
|
+
}, Object.values(states));
|
|
810
|
+
return [validity, validate];
|
|
811
|
+
};
|
|
812
|
+
|
|
813
|
+
var useWindowScroll = function useWindowScroll() {
|
|
814
|
+
var _useState = useState(function () {
|
|
815
|
+
return {
|
|
816
|
+
x: isBrowser ? window.pageXOffset : 0,
|
|
817
|
+
y: isBrowser ? window.pageYOffset : 0
|
|
818
|
+
};
|
|
819
|
+
}),
|
|
820
|
+
state = _useState[0],
|
|
821
|
+
setState = _useState[1];
|
|
822
|
+
useEffect(function () {
|
|
823
|
+
var handler = function handler() {
|
|
824
|
+
setState(function (state) {
|
|
825
|
+
var _window = window,
|
|
826
|
+
pageXOffset = _window.pageXOffset,
|
|
827
|
+
pageYOffset = _window.pageYOffset;
|
|
828
|
+
return state.x !== pageXOffset || state.y !== pageYOffset ? {
|
|
829
|
+
x: pageXOffset,
|
|
830
|
+
y: pageYOffset
|
|
831
|
+
} : state;
|
|
832
|
+
});
|
|
833
|
+
};
|
|
834
|
+
handler();
|
|
835
|
+
on(window, 'scroll', handler, {
|
|
836
|
+
capture: false,
|
|
837
|
+
passive: true
|
|
838
|
+
});
|
|
839
|
+
return function () {
|
|
840
|
+
off(window, 'scroll', handler);
|
|
841
|
+
};
|
|
842
|
+
}, []);
|
|
843
|
+
return state;
|
|
844
|
+
};
|
|
845
|
+
|
|
846
|
+
export { useBatteryInfo, useBeforeUnload, useClickOutside, useColorScheme, useConnection, useCookie, useCopyToClipboard, useDebounce, _useEqualObject as useEqualObject, useForceUpdate, useFullScreen, useGeolocation, useHover, useIntersectionObserver, useInterval, useIsFirstRender, useLocalStorage, useMedia, useMobileLandscape, useMousePageLeave, useMultiStateValidator, useOnlineStatus, usePageLeave, usePageVisible, usePreferredLanguage, usePrevious, useScrollLock, useScrollToElement, useScrolling, useSessionStorage, useStateValidator, useThrottle, useWindowScroll, useWindowSize };
|
|
658
847
|
//# sourceMappingURL=index.modern.js.map
|