@koine/react 2.0.0-beta.80 → 2.0.0-beta.83

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 (63) hide show
  1. package/FaviconTags.cjs.js +10 -3
  2. package/FaviconTags.esm.js +10 -3
  3. package/Meta.cjs.js +10 -3
  4. package/Meta.esm.js +10 -3
  5. package/NoJs.cjs.js +1 -5
  6. package/NoJs.esm.js +1 -5
  7. package/calendar.cjs.js +97 -534
  8. package/calendar.esm.js +97 -534
  9. package/classed.cjs.js +42 -39
  10. package/classed.esm.js +42 -39
  11. package/createUseMediaQueryWidth.cjs.js +15 -34
  12. package/createUseMediaQueryWidth.d.ts +1 -1
  13. package/createUseMediaQueryWidth.esm.js +15 -34
  14. package/extendComponent.cjs.js +5 -7
  15. package/extendComponent.d.ts +1 -1
  16. package/extendComponent.esm.js +5 -7
  17. package/forms/antispam.d.ts +1 -1
  18. package/forms.cjs.js +27 -27
  19. package/forms.esm.js +27 -27
  20. package/mergeRefs.cjs.js +1 -12
  21. package/mergeRefs.d.ts +1 -1
  22. package/mergeRefs.esm.js +1 -12
  23. package/package.json +3 -3
  24. package/useAsyncFn.cjs.js +4 -23
  25. package/useAsyncFn.esm.js +4 -23
  26. package/useFirstMountState.cjs.js +3 -8
  27. package/useFirstMountState.esm.js +3 -8
  28. package/useFixedOffset.cjs.js +12 -37
  29. package/useFixedOffset.esm.js +13 -38
  30. package/useFocus.cjs.js +3 -7
  31. package/useFocus.esm.js +3 -7
  32. package/useInterval.cjs.js +6 -17
  33. package/useInterval.esm.js +6 -17
  34. package/useIsomorphicLayoutEffect.cjs.js +3 -1
  35. package/useIsomorphicLayoutEffect.esm.js +3 -1
  36. package/useKeyUp.cjs.js +6 -13
  37. package/useKeyUp.esm.js +6 -13
  38. package/useMeasure.cjs.js +33 -115
  39. package/useMeasure.esm.js +33 -115
  40. package/useMountedState.cjs.js +3 -11
  41. package/useMountedState.esm.js +3 -11
  42. package/useNavigateAway.cjs.js +47 -22
  43. package/useNavigateAway.esm.js +47 -22
  44. package/usePrevious.cjs.js +1 -7
  45. package/usePrevious.esm.js +1 -7
  46. package/usePreviousRef.cjs.js +1 -7
  47. package/usePreviousRef.esm.js +1 -7
  48. package/useScrollPosition.cjs.js +7 -53
  49. package/useScrollPosition.esm.js +7 -53
  50. package/useScrollThreshold.cjs.js +4 -22
  51. package/useScrollThreshold.esm.js +4 -22
  52. package/useScrollTo.cjs.js +3 -16
  53. package/useScrollTo.esm.js +3 -16
  54. package/useSmoothScroll.cjs.js +6 -27
  55. package/useSmoothScroll.esm.js +6 -27
  56. package/useSpinDelay.cjs.js +12 -34
  57. package/useSpinDelay.esm.js +12 -34
  58. package/useTraceUpdate.cjs.js +4 -15
  59. package/useTraceUpdate.esm.js +4 -15
  60. package/useUpdateEffect.cjs.js +4 -8
  61. package/useUpdateEffect.esm.js +4 -8
  62. package/useWindowSize.cjs.js +9 -17
  63. package/useWindowSize.esm.js +9 -17
@@ -4,17 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
6
 
7
- let useMountedState = () => {
8
- const mountedRef = react.useRef(false);
9
- const get = react.useCallback(() => mountedRef.current, []);
10
- react.useEffect(() => {
11
- mountedRef.current = true;
12
- return () => {
13
- mountedRef.current = false;
14
- };
15
- }, []);
16
- return get;
17
- };
7
+ /**
8
+ * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useMountedState.ts)
9
+ */let useMountedState=()=>{let u=react.useRef(!1),n=react.useCallback(()=>u.current,[]);return react.useEffect(()=>(u.current=!0,()=>{u.current=!1;}),[]),n};
18
10
 
19
11
  exports["default"] = useMountedState;
20
12
  exports.useMountedState = useMountedState;
@@ -1,15 +1,7 @@
1
1
  import { useRef, useCallback, useEffect } from 'react';
2
2
 
3
- let useMountedState = () => {
4
- const mountedRef = useRef(false);
5
- const get = useCallback(() => mountedRef.current, []);
6
- useEffect(() => {
7
- mountedRef.current = true;
8
- return () => {
9
- mountedRef.current = false;
10
- };
11
- }, []);
12
- return get;
13
- };
3
+ /**
4
+ * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useMountedState.ts)
5
+ */let useMountedState=()=>{let u=useRef(!1),n=useCallback(()=>u.current,[]);return useEffect(()=>(u.current=!0,()=>{u.current=!1;}),[]),n};
14
6
 
15
7
  export { useMountedState as default, useMountedState };
@@ -5,28 +5,53 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var react = require('react');
6
6
  var dom = require('@koine/dom');
7
7
 
8
- let useNavigateAway = (handler) => {
9
- const beforeUnloadHandlerRef = react.useRef();
10
- react.useEffect(() => {
11
- beforeUnloadHandlerRef.current = (event) => {
12
- const customMessageOrCondition = handler(event);
13
- if (customMessageOrCondition) {
14
- event.preventDefault();
15
- }
16
- if (typeof customMessageOrCondition === "string") {
17
- return (event.returnValue = customMessageOrCondition);
18
- }
19
- if (event.defaultPrevented) {
20
- return (event.returnValue = "");
21
- }
22
- return;
23
- };
24
- }, [handler]);
25
- react.useEffect(() => {
26
- const listenerBeforeunload = dom.on(window, "beforeunload", (event) => beforeUnloadHandlerRef.current?.(event));
27
- return listenerBeforeunload;
28
- }, []);
29
- };
8
+ // string | boolean,
9
+ // (() => unknown) | undefined,
10
+ // (() => unknown) | undefined,
11
+ // ];
12
+ // type UseNavigateAwayPagehideHandler = (event: PageTransitionEvent) => unknown;
13
+ /**
14
+ * @resources
15
+ *
16
+ * About browser's specs see:
17
+ * - https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
18
+ * - https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
19
+ * - https://stackoverflow.com/questions/58009424/pagehide-event-on-google-chrome
20
+ *
21
+ * About react see:
22
+ * - https://github.com/jacobbuck/react-beforeunload
23
+ * - https://github.com/dioscarey/react-beforeunload-component
24
+ *
25
+ * About next.js see:
26
+ * - https://github.com/vercel/next.js/issues/2476
27
+ * - https://github.com/vercel/next.js/issues/2694
28
+ *
29
+ * For the callback technique see:
30
+ * - https://stackoverflow.com/a/11835394/1938970
31
+ */let useNavigateAway=a=>{let o=react.useRef();// const pagehideHandlerRef = useRef<UseNavigateAwayPagehideHandler | undefined>();
32
+ react.useEffect(()=>{o.current=e=>{let t=a(e);return(// Handle legacy `event.returnValue` property
33
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
34
+ (t&&e.preventDefault(),"string"==typeof t)?e.returnValue=t:// Chrome doesn't support `event.preventDefault()` on `BeforeUnloadEvent`,
35
+ // instead it requires `event.returnValue` to be set
36
+ // https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#browser_compatibility
37
+ e.defaultPrevented?e.returnValue="":void 0)};},// pagehideHandlerRef.current = (event) => {
38
+ // const returnValue = handler?.(event);
39
+ // if (event.persisted) {
40
+ // // If the event's persisted property is `true` the page is about
41
+ // // to enter the Back-Forward Cache, which is also in the frozen state.
42
+ // } else {
43
+ // // If the event's persisted property is not `true` the page is
44
+ // // about to be unloaded.
45
+ // }
46
+ // };
47
+ [a]),react.useEffect(()=>dom.on(window,"beforeunload",e=>o.current?.(e)),// const listenerPagehide = on(window, "pagehide", (event) =>
48
+ // pagehideHandlerRef.current?.(event)
49
+ // );
50
+ // return () => {
51
+ // listenerBeforeunload();
52
+ // // listenerPagehide();
53
+ // };
54
+ []);};
30
55
 
31
56
  exports["default"] = useNavigateAway;
32
57
  exports.useNavigateAway = useNavigateAway;
@@ -1,27 +1,52 @@
1
1
  import { useRef, useEffect } from 'react';
2
2
  import { on } from '@koine/dom';
3
3
 
4
- let useNavigateAway = (handler) => {
5
- const beforeUnloadHandlerRef = useRef();
6
- useEffect(() => {
7
- beforeUnloadHandlerRef.current = (event) => {
8
- const customMessageOrCondition = handler(event);
9
- if (customMessageOrCondition) {
10
- event.preventDefault();
11
- }
12
- if (typeof customMessageOrCondition === "string") {
13
- return (event.returnValue = customMessageOrCondition);
14
- }
15
- if (event.defaultPrevented) {
16
- return (event.returnValue = "");
17
- }
18
- return;
19
- };
20
- }, [handler]);
21
- useEffect(() => {
22
- const listenerBeforeunload = on(window, "beforeunload", (event) => beforeUnloadHandlerRef.current?.(event));
23
- return listenerBeforeunload;
24
- }, []);
25
- };
4
+ // string | boolean,
5
+ // (() => unknown) | undefined,
6
+ // (() => unknown) | undefined,
7
+ // ];
8
+ // type UseNavigateAwayPagehideHandler = (event: PageTransitionEvent) => unknown;
9
+ /**
10
+ * @resources
11
+ *
12
+ * About browser's specs see:
13
+ * - https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
14
+ * - https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
15
+ * - https://stackoverflow.com/questions/58009424/pagehide-event-on-google-chrome
16
+ *
17
+ * About react see:
18
+ * - https://github.com/jacobbuck/react-beforeunload
19
+ * - https://github.com/dioscarey/react-beforeunload-component
20
+ *
21
+ * About next.js see:
22
+ * - https://github.com/vercel/next.js/issues/2476
23
+ * - https://github.com/vercel/next.js/issues/2694
24
+ *
25
+ * For the callback technique see:
26
+ * - https://stackoverflow.com/a/11835394/1938970
27
+ */let useNavigateAway=a=>{let o=useRef();// const pagehideHandlerRef = useRef<UseNavigateAwayPagehideHandler | undefined>();
28
+ useEffect(()=>{o.current=e=>{let t=a(e);return(// Handle legacy `event.returnValue` property
29
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
30
+ (t&&e.preventDefault(),"string"==typeof t)?e.returnValue=t:// Chrome doesn't support `event.preventDefault()` on `BeforeUnloadEvent`,
31
+ // instead it requires `event.returnValue` to be set
32
+ // https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#browser_compatibility
33
+ e.defaultPrevented?e.returnValue="":void 0)};},// pagehideHandlerRef.current = (event) => {
34
+ // const returnValue = handler?.(event);
35
+ // if (event.persisted) {
36
+ // // If the event's persisted property is `true` the page is about
37
+ // // to enter the Back-Forward Cache, which is also in the frozen state.
38
+ // } else {
39
+ // // If the event's persisted property is not `true` the page is
40
+ // // about to be unloaded.
41
+ // }
42
+ // };
43
+ [a]),useEffect(()=>on(window,"beforeunload",e=>o.current?.(e)),// const listenerPagehide = on(window, "pagehide", (event) =>
44
+ // pagehideHandlerRef.current?.(event)
45
+ // );
46
+ // return () => {
47
+ // listenerBeforeunload();
48
+ // // listenerPagehide();
49
+ // };
50
+ []);};
26
51
 
27
52
  export { useNavigateAway as default, useNavigateAway };
@@ -4,13 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
6
 
7
- let usePrevious = (state, defaulValue) => {
8
- const [tuple, setTuple] = react.useState([state, defaulValue]);
9
- if (tuple[1] !== state) {
10
- setTuple([tuple[1], state]);
11
- }
12
- return tuple[0];
13
- };
7
+ let usePrevious=(r,t)=>{let[o,u]=react.useState([r,t]);return o[1]!==r&&u([o[1],r]),o[0]};
14
8
 
15
9
  exports["default"] = usePrevious;
16
10
  exports.usePrevious = usePrevious;
@@ -1,11 +1,5 @@
1
1
  import { useState } from 'react';
2
2
 
3
- let usePrevious = (state, defaulValue) => {
4
- const [tuple, setTuple] = useState([state, defaulValue]);
5
- if (tuple[1] !== state) {
6
- setTuple([tuple[1], state]);
7
- }
8
- return tuple[0];
9
- };
3
+ let usePrevious=(r,t)=>{let[o,u]=useState([r,t]);return o[1]!==r&&u([o[1],r]),o[0]};
10
4
 
11
5
  export { usePrevious as default, usePrevious };
@@ -4,13 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
6
 
7
- let usePreviousRef = (value) => {
8
- const ref = react.useRef();
9
- react.useEffect(() => {
10
- ref.current = value;
11
- });
12
- return ref.current;
13
- };
7
+ let usePreviousRef=t=>{let u=react.useRef();return react.useEffect(()=>{u.current=t;}),u.current};
14
8
 
15
9
  exports["default"] = usePreviousRef;
16
10
  exports.usePreviousRef = usePreviousRef;
@@ -1,11 +1,5 @@
1
1
  import { useRef, useEffect } from 'react';
2
2
 
3
- let usePreviousRef = (value) => {
4
- const ref = useRef();
5
- useEffect(() => {
6
- ref.current = value;
7
- });
8
- return ref.current;
9
- };
3
+ let usePreviousRef=t=>{let u=useRef();return useEffect(()=>{u.current=t;}),u.current};
10
4
 
11
5
  export { usePreviousRef as default, usePreviousRef };
@@ -7,59 +7,13 @@ var utils = require('@koine/utils');
7
7
  var dom = require('@koine/dom');
8
8
  var useIsomorphicLayoutEffect = require('./useIsomorphicLayoutEffect.cjs.js');
9
9
 
10
- const zeroPosition = { x: 0, y: 0 };
11
- const getClientRect = (element) => element?.getBoundingClientRect();
12
- const getScrollPosition = (element, boundingElement) => {
13
- if (!utils.isBrowser) {
14
- return zeroPosition;
15
- }
16
- if (!boundingElement) {
17
- return { x: window.scrollX, y: window.scrollY };
18
- }
19
- const targetPosition = getClientRect(element?.current || document.body);
20
- const containerPosition = getClientRect(boundingElement.current);
21
- if (!targetPosition) {
22
- return zeroPosition;
23
- }
24
- return containerPosition
25
- ? {
26
- x: (containerPosition.x || 0) - (targetPosition.x || 0),
27
- y: (containerPosition.y || 0) - (targetPosition.y || 0),
28
- }
29
- : { x: targetPosition.left, y: targetPosition.top };
30
- };
31
- let useScrollPosition = (effect, deps = [], element, boundingElement, wait) => {
32
- const position = react.useRef(getScrollPosition(null, boundingElement));
33
- let throttleTimeout = null;
34
- const callBack = () => {
35
- const current = getScrollPosition(element, boundingElement);
36
- effect(current, position.current);
37
- position.current = current;
38
- throttleTimeout = null;
39
- };
40
- useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(() => {
41
- if (!utils.isBrowser) {
42
- return undefined;
43
- }
44
- const handleScroll = () => {
45
- if (wait) {
46
- if (throttleTimeout === null) {
47
- throttleTimeout = window.setTimeout(callBack, wait);
48
- }
49
- }
50
- else {
51
- callBack();
52
- }
53
- };
54
- const listener = dom.listenScroll(handleScroll, boundingElement?.current);
55
- return () => {
56
- listener();
57
- if (throttleTimeout) {
58
- clearTimeout(throttleTimeout);
59
- }
60
- };
61
- }, deps);
62
- };
10
+ let l={x:0,y:0},n=t=>t?.getBoundingClientRect(),u=(t,e)=>{if(!utils.isBrowser)return l;if(!e)return {x:window.scrollX,y:window.scrollY};let o=n(t?.current||document.body),u=n(e.current);return o?u?{x:(u.x||0)-(o.x||0),y:(u.y||0)-(o.y||0)}:{x:o.left,y:o.top}:l};/**
11
+ * @borrows [@n8tb1t/use-scroll-position@2.0.3](https://github.com/n8tb1t/use-scroll-position) by `n8tb1t <n8tb1t@gmail.com>`
12
+ *
13
+ * We've just:
14
+ * - reused internal helper functions
15
+ * - compacted object arguments in functions as plain argument list to improve compression
16
+ */let useScrollPosition=(l,n=[],i,c,m)=>{let f=react.useRef(u(null,c)),s=null,d=()=>{let t=u(i,c);l(t,f.current),f.current=t,s=null;};useIsomorphicLayoutEffect.useIsomorphicLayoutEffect(()=>{if(!utils.isBrowser)return;let t=dom.listenScroll(()=>{m?null===s&&(s=window.setTimeout(d,m)):d();},c?.current);return ()=>{t(),s&&clearTimeout(s);}},n);};
63
17
 
64
18
  exports["default"] = useScrollPosition;
65
19
  exports.useScrollPosition = useScrollPosition;
@@ -3,58 +3,12 @@ import { isBrowser } from '@koine/utils';
3
3
  import { listenScroll } from '@koine/dom';
4
4
  import { useIsomorphicLayoutEffect } from './useIsomorphicLayoutEffect.esm.js';
5
5
 
6
- const zeroPosition = { x: 0, y: 0 };
7
- const getClientRect = (element) => element?.getBoundingClientRect();
8
- const getScrollPosition = (element, boundingElement) => {
9
- if (!isBrowser) {
10
- return zeroPosition;
11
- }
12
- if (!boundingElement) {
13
- return { x: window.scrollX, y: window.scrollY };
14
- }
15
- const targetPosition = getClientRect(element?.current || document.body);
16
- const containerPosition = getClientRect(boundingElement.current);
17
- if (!targetPosition) {
18
- return zeroPosition;
19
- }
20
- return containerPosition
21
- ? {
22
- x: (containerPosition.x || 0) - (targetPosition.x || 0),
23
- y: (containerPosition.y || 0) - (targetPosition.y || 0),
24
- }
25
- : { x: targetPosition.left, y: targetPosition.top };
26
- };
27
- let useScrollPosition = (effect, deps = [], element, boundingElement, wait) => {
28
- const position = useRef(getScrollPosition(null, boundingElement));
29
- let throttleTimeout = null;
30
- const callBack = () => {
31
- const current = getScrollPosition(element, boundingElement);
32
- effect(current, position.current);
33
- position.current = current;
34
- throttleTimeout = null;
35
- };
36
- useIsomorphicLayoutEffect(() => {
37
- if (!isBrowser) {
38
- return undefined;
39
- }
40
- const handleScroll = () => {
41
- if (wait) {
42
- if (throttleTimeout === null) {
43
- throttleTimeout = window.setTimeout(callBack, wait);
44
- }
45
- }
46
- else {
47
- callBack();
48
- }
49
- };
50
- const listener = listenScroll(handleScroll, boundingElement?.current);
51
- return () => {
52
- listener();
53
- if (throttleTimeout) {
54
- clearTimeout(throttleTimeout);
55
- }
56
- };
57
- }, deps);
58
- };
6
+ let l={x:0,y:0},n=t=>t?.getBoundingClientRect(),u=(t,e)=>{if(!isBrowser)return l;if(!e)return {x:window.scrollX,y:window.scrollY};let o=n(t?.current||document.body),u=n(e.current);return o?u?{x:(u.x||0)-(o.x||0),y:(u.y||0)-(o.y||0)}:{x:o.left,y:o.top}:l};/**
7
+ * @borrows [@n8tb1t/use-scroll-position@2.0.3](https://github.com/n8tb1t/use-scroll-position) by `n8tb1t <n8tb1t@gmail.com>`
8
+ *
9
+ * We've just:
10
+ * - reused internal helper functions
11
+ * - compacted object arguments in functions as plain argument list to improve compression
12
+ */let useScrollPosition=(l,n=[],i,c,m)=>{let f=useRef(u(null,c)),s=null,d=()=>{let t=u(i,c);l(t,f.current),f.current=t,s=null;};useIsomorphicLayoutEffect(()=>{if(!isBrowser)return;let t=listenScroll(()=>{m?null===s&&(s=window.setTimeout(d,m)):d();},c?.current);return ()=>{t(),s&&clearTimeout(s);}},n);};
59
13
 
60
14
  export { useScrollPosition as default, useScrollPosition };
@@ -6,28 +6,10 @@ var react = require('react');
6
6
  var utils = require('@koine/utils');
7
7
  var dom = require('@koine/dom');
8
8
 
9
- let useScrollThreshold = (threshold, callback) => {
10
- const [isBelow, setIsBelow] = react.useState(false);
11
- const handler = react.useCallback(() => {
12
- if (threshold) {
13
- const posY = window.scrollY;
14
- const isAbove = posY < threshold;
15
- const isBelow = posY > threshold;
16
- setIsBelow(isBelow);
17
- if (callback)
18
- callback(isAbove, isBelow);
19
- }
20
- }, [threshold, callback]);
21
- react.useEffect(() => {
22
- if (threshold) {
23
- const listener = dom.listenScroll(handler);
24
- handler();
25
- return listener;
26
- }
27
- return utils.noop;
28
- }, [threshold, handler]);
29
- return isBelow;
30
- };
9
+ let useScrollThreshold=(i,m)=>{let[u,f]=react.useState(!1),n=react.useCallback(()=>{if(i){let r=window.scrollY,// * -1;
10
+ e=r<i,o=r>i;// console.log("useScrollThreshold setIsBelow", isBelow, posY, threshold);
11
+ f(o),m&&m(e,o);}},[i,m]);return react.useEffect(()=>{if(i){// const listener = listenScrollThrottled(0, handler, 50);
12
+ let r=dom.listenScroll(n);return n(),r}return utils.noop},[i,n]),u};
31
13
 
32
14
  exports["default"] = useScrollThreshold;
33
15
  exports.useScrollThreshold = useScrollThreshold;
@@ -2,27 +2,9 @@ import { useState, useCallback, useEffect } from 'react';
2
2
  import { noop } from '@koine/utils';
3
3
  import { listenScroll } from '@koine/dom';
4
4
 
5
- let useScrollThreshold = (threshold, callback) => {
6
- const [isBelow, setIsBelow] = useState(false);
7
- const handler = useCallback(() => {
8
- if (threshold) {
9
- const posY = window.scrollY;
10
- const isAbove = posY < threshold;
11
- const isBelow = posY > threshold;
12
- setIsBelow(isBelow);
13
- if (callback)
14
- callback(isAbove, isBelow);
15
- }
16
- }, [threshold, callback]);
17
- useEffect(() => {
18
- if (threshold) {
19
- const listener = listenScroll(handler);
20
- handler();
21
- return listener;
22
- }
23
- return noop;
24
- }, [threshold, handler]);
25
- return isBelow;
26
- };
5
+ let useScrollThreshold=(i,m)=>{let[u,f]=useState(!1),n=useCallback(()=>{if(i){let r=window.scrollY,// * -1;
6
+ e=r<i,o=r>i;// console.log("useScrollThreshold setIsBelow", isBelow, posY, threshold);
7
+ f(o),m&&m(e,o);}},[i,m]);return useEffect(()=>{if(i){// const listener = listenScrollThrottled(0, handler, 50);
8
+ let r=listenScroll(n);return n(),r}return noop},[i,n]),u};
27
9
 
28
10
  export { useScrollThreshold as default, useScrollThreshold };
@@ -4,22 +4,9 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var utils = require('@koine/utils');
6
6
 
7
- let useScrollTo = (id = "", offset = 0) => {
8
- if (!utils.isBrowser) {
9
- return;
10
- }
11
- const headerOffset = 0;
12
- let element = document.getElementById(id);
13
- let top = 0;
14
- if (element && element.offsetParent) {
15
- do {
16
- top += element.offsetTop;
17
- } while ((element = element.offsetParent));
18
- }
19
- top -= offset;
20
- top -= headerOffset;
21
- window.scroll(0, top);
22
- };
7
+ let useScrollTo=(o="",t=0)=>{// FIXME: is the useHeader still needed?
8
+ // const [, , headerHeight] = useHeader();
9
+ if(!utils.isBrowser)return;let l=document.getElementById(o),r=0;if(l&&l.offsetParent)do r+=l.offsetTop;while(l=l.offsetParent)r-=t,r-=/* headerHeight || */0,window.scroll(0,r);};
23
10
 
24
11
  exports["default"] = useScrollTo;
25
12
  exports.useScrollTo = useScrollTo;
@@ -1,20 +1,7 @@
1
1
  import { isBrowser } from '@koine/utils';
2
2
 
3
- let useScrollTo = (id = "", offset = 0) => {
4
- if (!isBrowser) {
5
- return;
6
- }
7
- const headerOffset = 0;
8
- let element = document.getElementById(id);
9
- let top = 0;
10
- if (element && element.offsetParent) {
11
- do {
12
- top += element.offsetTop;
13
- } while ((element = element.offsetParent));
14
- }
15
- top -= offset;
16
- top -= headerOffset;
17
- window.scroll(0, top);
18
- };
3
+ let useScrollTo=(o="",t=0)=>{// FIXME: is the useHeader still needed?
4
+ // const [, , headerHeight] = useHeader();
5
+ if(!isBrowser)return;let l=document.getElementById(o),r=0;if(l&&l.offsetParent)do r+=l.offsetTop;while(l=l.offsetParent)r-=t,r-=/* headerHeight || */0,window.scroll(0,r);};
19
6
 
20
7
  export { useScrollTo as default, useScrollTo };
@@ -8,33 +8,12 @@ var dom = require('@koine/dom');
8
8
  var useFixedOffset = require('./useFixedOffset.cjs.js');
9
9
  require('./useIsomorphicLayoutEffect.cjs.js');
10
10
 
11
- let useSmoothScroll = (disregardAutomaticFixedOffset) => {
12
- const fixedOffset = useFixedOffset.useFixedOffset();
13
- const scroll = react.useCallback((to, customOffset, callback, fallbackTimeout, behavior) => {
14
- let top = undefined;
15
- let toIsElement = false;
16
- if (utils.isNumber(to)) {
17
- top = to;
18
- }
19
- else if (to) {
20
- const el = document.getElementById(to);
21
- if (el) {
22
- top = dom.getOffsetTopSlim(el) - fixedOffset.current;
23
- toIsElement = true;
24
- }
25
- }
26
- if (utils.isNumber(top)) {
27
- top =
28
- top +
29
- (customOffset || 0) +
30
- (disregardAutomaticFixedOffset || toIsElement
31
- ? 0
32
- : fixedOffset.current);
33
- dom.scrollTo(top, callback, fallbackTimeout, behavior);
34
- }
35
- }, [disregardAutomaticFixedOffset, fixedOffset]);
36
- return scroll;
37
- };
11
+ /**
12
+ *
13
+ * @param disregardAutomaticFixedOffset When the `to` scroll argument is a DOM
14
+ * selector we will keep into account the _fixedOffset_ despite this option.
15
+ * @returns
16
+ */let useSmoothScroll=m=>{let i=useFixedOffset.useFixedOffset();return react.useCallback((e,l,f,u,n)=>{let c;let p=!1;if(utils.isNumber(e))c=e;else if(e){let t=document.getElementById(e);t&&(c=dom.getOffsetTopSlim(t)-i.current,p=!0);}utils.isNumber(c)&&dom.scrollTo(c=c+(l||0)+(m||p?0:i.current),f,u,n);},[m,i])};
38
17
 
39
18
  exports["default"] = useSmoothScroll;
40
19
  exports.useSmoothScroll = useSmoothScroll;
@@ -4,32 +4,11 @@ import { getOffsetTopSlim, scrollTo } from '@koine/dom';
4
4
  import { useFixedOffset } from './useFixedOffset.esm.js';
5
5
  import './useIsomorphicLayoutEffect.esm.js';
6
6
 
7
- let useSmoothScroll = (disregardAutomaticFixedOffset) => {
8
- const fixedOffset = useFixedOffset();
9
- const scroll = useCallback((to, customOffset, callback, fallbackTimeout, behavior) => {
10
- let top = undefined;
11
- let toIsElement = false;
12
- if (isNumber(to)) {
13
- top = to;
14
- }
15
- else if (to) {
16
- const el = document.getElementById(to);
17
- if (el) {
18
- top = getOffsetTopSlim(el) - fixedOffset.current;
19
- toIsElement = true;
20
- }
21
- }
22
- if (isNumber(top)) {
23
- top =
24
- top +
25
- (customOffset || 0) +
26
- (disregardAutomaticFixedOffset || toIsElement
27
- ? 0
28
- : fixedOffset.current);
29
- scrollTo(top, callback, fallbackTimeout, behavior);
30
- }
31
- }, [disregardAutomaticFixedOffset, fixedOffset]);
32
- return scroll;
33
- };
7
+ /**
8
+ *
9
+ * @param disregardAutomaticFixedOffset When the `to` scroll argument is a DOM
10
+ * selector we will keep into account the _fixedOffset_ despite this option.
11
+ * @returns
12
+ */let useSmoothScroll=m=>{let i=useFixedOffset();return useCallback((e,l,f,u,n)=>{let c;let p=!1;if(isNumber(e))c=e;else if(e){let t=document.getElementById(e);t&&(c=getOffsetTopSlim(t)-i.current,p=!0);}isNumber(c)&&scrollTo(c=c+(l||0)+(m||p?0:i.current),f,u,n);},[m,i])};
34
13
 
35
14
  export { useSmoothScroll as default, useSmoothScroll };
@@ -4,40 +4,18 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var react = require('react');
6
6
 
7
- var State;
8
- (function (State) {
9
- State[State["IDLE"] = 0] = "IDLE";
10
- State[State["DELAY"] = 1] = "DELAY";
11
- State[State["DISPLAY"] = 2] = "DISPLAY";
12
- State[State["EXPIRE"] = 3] = "EXPIRE";
13
- })(State || (State = {}));
14
- let useSpinDelay = (loading, delay = 500, minDuration = 200) => {
15
- const [state, setState] = react.useState(State.IDLE);
16
- const timeout = react.useRef();
17
- react.useEffect(() => {
18
- if (loading && state === State.IDLE) {
19
- clearTimeout(timeout.current);
20
- timeout.current = setTimeout(() => {
21
- if (!loading) {
22
- return setState(State.IDLE);
23
- }
24
- timeout.current = setTimeout(() => {
25
- setState(State.EXPIRE);
26
- }, minDuration);
27
- setState(State.DISPLAY);
28
- }, delay);
29
- setState(State.DELAY);
30
- }
31
- if (!loading && state !== State.DISPLAY) {
32
- clearTimeout(timeout.current);
33
- setState(State.IDLE);
34
- }
35
- }, [loading, state, delay, minDuration]);
36
- react.useEffect(() => {
37
- return () => clearTimeout(timeout.current);
38
- }, []);
39
- return state === State.DISPLAY || state === State.EXPIRE;
40
- };
7
+ /**
8
+ * Wraps your booleans only returning true after the `delay`, and for a minimum
9
+ * time of `minDuration`. This way you're sure that you don't show unnecessary
10
+ * or very short living spinners.
11
+ *
12
+ * @borrows [smeijer/spin-delay](https://github.com/smeijer/spin-delay)
13
+ *
14
+ * - Smaller footprint and options object as argument
15
+ *
16
+ * @param delay [500]
17
+ * @param minDuration [200]
18
+ */let useSpinDelay=(u,c=500,i=200)=>{let[n,o]=react.useState(0),l=react.useRef();return react.useEffect(()=>{u&&0===n&&(clearTimeout(l.current),l.current=setTimeout(()=>{if(!u)return o(0);l.current=setTimeout(()=>{o(3);},i),o(2);},c),o(1)),u||2===n||(clearTimeout(l.current),o(0));},[u,n,c,i]),react.useEffect(()=>()=>clearTimeout(l.current),[]),2===n||3===n};
41
19
 
42
20
  exports["default"] = useSpinDelay;
43
21
  exports.useSpinDelay = useSpinDelay;