@koine/react 1.0.104 → 1.1.0

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 (178) hide show
  1. package/Alert/Alert.d.ts +1 -1
  2. package/Animations/Reveal.d.ts +1 -1
  3. package/Animations/useReveal.d.ts +1 -1
  4. package/Autocomplete/AutocompleteMui.d.ts +4 -4
  5. package/Autocomplete/helpers.d.ts +1 -1
  6. package/Bg/BgColor.d.ts +1 -1
  7. package/Bg/BgPhoto.d.ts +2 -2
  8. package/Bg/BgSvg.d.ts +1 -1
  9. package/Breadcrumbs/Breadcrumbs.d.ts +3 -3
  10. package/Buttons/Button.d.ts +2 -2
  11. package/Buttons/ButtonComposite.d.ts +3 -3
  12. package/Buttons/ButtonFab.d.ts +1 -1
  13. package/Buttons/ButtonLink.d.ts +2 -2
  14. package/Buttons/IconButton.d.ts +2 -2
  15. package/Calendar/CalendarDaygridCell.d.ts +6 -6
  16. package/Calendar/CalendarDaygridNav.d.ts +3 -3
  17. package/Calendar/CalendarDaygridTable.d.ts +4 -4
  18. package/Calendar/CalendarLegend.d.ts +3 -3
  19. package/Calendar/calendar-api-google.d.ts +1 -1
  20. package/Calendar/types.d.ts +13 -13
  21. package/Calendar/useCalendar.d.ts +5 -5
  22. package/Carousel/CarouselCss.d.ts +2 -2
  23. package/Collapsable/CollapsableReach.js +1 -2
  24. package/Debug/Debug.d.ts +1 -1
  25. package/Details/Details.d.ts +6 -6
  26. package/Dialog/DialogMui.d.ts +8 -8
  27. package/Dialog/DialogMui.js +1 -1
  28. package/Dialog/css/bare.d.ts +1 -1
  29. package/Dialog/m/bare.d.ts +1 -1
  30. package/Dialog/m/bare.js +1 -1
  31. package/Dialog/sc/bare.d.ts +1 -1
  32. package/Dialog/sc/framer.d.ts +1 -1
  33. package/Dialog/sc/framerMaterial.d.ts +1 -1
  34. package/Dialog/sc/material.d.ts +1 -1
  35. package/Dialog/tw/bare.d.ts +7 -7
  36. package/Dialog/tw/elegant.d.ts +7 -7
  37. package/Dialog/tw/framer.d.ts +3 -3
  38. package/Dialog/tw/framerMaterial.d.ts +5 -5
  39. package/Dialog/tw/material.d.ts +7 -7
  40. package/Editor/Editor--tiptap.d.ts +2 -2
  41. package/Favicon/FaviconTags.d.ts +1 -1
  42. package/Favicon/FaviconTags.js +1 -1
  43. package/Form/Form.d.ts +7 -7
  44. package/Forms/Checkbox/Checkbox.d.ts +2 -2
  45. package/Forms/Feedback/Feedback.d.ts +1 -1
  46. package/Forms/Field/Field.d.ts +3 -3
  47. package/Forms/Field/FieldControl.d.ts +2 -2
  48. package/Forms/Input/Input.d.ts +2 -2
  49. package/Forms/InputGroup/InputGroup.d.ts +1 -1
  50. package/Forms/Password/Password.d.ts +2 -2
  51. package/Forms/Radio/Radio.d.ts +3 -3
  52. package/Forms/Switch/Switch.d.ts +2 -2
  53. package/Forms/Textarea/Textarea.d.ts +2 -2
  54. package/Forms/Textarea/TextareaRich.d.ts +2 -2
  55. package/Forms/Toggle/Toggle.d.ts +3 -3
  56. package/Forms/Toggle/useToggle.d.ts +1 -1
  57. package/Forms/antispam.d.ts +18 -1
  58. package/Forms/helpers.d.ts +5 -5
  59. package/Gauge/Gauge.d.ts +1 -1
  60. package/Grid/Grid.d.ts +6 -6
  61. package/Hamburger/Hamburger.d.ts +1 -1
  62. package/Header/useHeader.d.ts +5 -5
  63. package/Hidden/Hidden.d.ts +1 -1
  64. package/Img/sc/bare.d.ts +1 -1
  65. package/Img/types.d.ts +2 -2
  66. package/Link/Link.d.ts +1 -1
  67. package/Link/LinkBlank.d.ts +1 -1
  68. package/Menu/MenuMui.d.ts +5 -5
  69. package/Menu/MenuMui.js +1 -1
  70. package/MenuItem/MenuItemMui.d.ts +1 -1
  71. package/Meta/Meta.d.ts +1 -1
  72. package/NoJs/NoJs.d.ts +1 -1
  73. package/Pagination/PaginationNav.d.ts +2 -2
  74. package/Pagination/PaginationResults.d.ts +1 -1
  75. package/Pill/Pill.d.ts +1 -1
  76. package/Progress/ProgressCircular.d.ts +1 -1
  77. package/Progress/ProgressLinear.d.ts +1 -1
  78. package/Progress/ProgressOverlay.d.ts +1 -1
  79. package/Rating/Rating.d.ts +3 -3
  80. package/Select/SelectDownshift.d.ts +1 -1
  81. package/Select/components.d.ts +1 -1
  82. package/Sidebar/Sidebar.d.ts +1 -1
  83. package/Spacing/Spacing.d.ts +6 -6
  84. package/Sticky/Sticky.d.ts +1 -1
  85. package/Sticky/StickyCss.d.ts +1 -1
  86. package/Tabs/TabsMui.d.ts +11 -11
  87. package/Tabs/TabsMui.js +1 -1
  88. package/Tabs/tw/bare.d.ts +4 -4
  89. package/Tabs/tw/material.d.ts +10 -10
  90. package/Typography/ReadMore.d.ts +1 -1
  91. package/Typography/TextLoop.d.ts +2 -2
  92. package/Typography/TypeStairs.d.ts +1 -1
  93. package/helpers/classed.d.ts +3 -3
  94. package/helpers/classed.js +1 -0
  95. package/helpers/createUseMediaQueryWidth.d.ts +3 -3
  96. package/helpers/extend-component.d.ts +4 -4
  97. package/helpers/extend-component.js +1 -0
  98. package/hooks/index.d.ts +4 -1
  99. package/hooks/index.js +4 -1
  100. package/hooks/types.d.ts +2 -2
  101. package/hooks/useAsyncFn.d.ts +4 -4
  102. package/hooks/useAsyncFn.js +1 -0
  103. package/hooks/useDateLocale.d.ts +1 -0
  104. package/hooks/useDateLocale.js +1 -0
  105. package/hooks/useEffectOnce.d.ts +1 -0
  106. package/hooks/useEffectOnce.js +1 -0
  107. package/hooks/useFirstMountState.d.ts +1 -0
  108. package/hooks/useFirstMountState.js +1 -0
  109. package/hooks/useFocus.d.ts +1 -0
  110. package/hooks/useFocus.js +1 -0
  111. package/hooks/useId.d.ts +1 -0
  112. package/hooks/useId.js +1 -0
  113. package/hooks/useInterval.d.ts +7 -0
  114. package/hooks/useInterval.js +28 -0
  115. package/hooks/useIsomorphicLayoutEffect.d.ts +1 -0
  116. package/hooks/useIsomorphicLayoutEffect.js +1 -0
  117. package/hooks/useKeyUp.d.ts +2 -0
  118. package/hooks/useKeyUp.js +23 -0
  119. package/hooks/useMeasure.d.ts +3 -3
  120. package/hooks/useMount.d.ts +1 -0
  121. package/hooks/useMount.js +1 -0
  122. package/hooks/useMountedState.d.ts +1 -0
  123. package/hooks/useMountedState.js +1 -0
  124. package/hooks/useNavigateAway.d.ts +32 -0
  125. package/hooks/useNavigateAway.js +68 -0
  126. package/hooks/usePrevious.d.ts +5 -1
  127. package/hooks/usePrevious.js +11 -7
  128. package/hooks/usePreviousRef.d.ts +2 -0
  129. package/hooks/usePreviousRef.js +9 -0
  130. package/hooks/useScrollPosition.d.ts +3 -3
  131. package/hooks/useScrollPosition.js +1 -0
  132. package/hooks/useScrollTo.d.ts +1 -0
  133. package/hooks/useScrollTo.js +1 -0
  134. package/hooks/useTraceUpdate.d.ts +1 -0
  135. package/hooks/useTraceUpdate.js +1 -0
  136. package/hooks/useUpdateEffect.d.ts +1 -0
  137. package/hooks/useUpdateEffect.js +1 -0
  138. package/hooks/useWindowSize.d.ts +1 -0
  139. package/hooks/useWindowSize.js +4 -2
  140. package/m/MotionProvider.d.ts +2 -2
  141. package/node/Collapsable/CollapsableReach.js +1 -2
  142. package/node/Dialog/DialogMui.js +1 -1
  143. package/node/Dialog/m/bare.js +1 -1
  144. package/node/Favicon/FaviconTags.js +1 -1
  145. package/node/Menu/MenuMui.js +1 -1
  146. package/node/Tabs/TabsMui.js +1 -1
  147. package/node/helpers/classed.js +1 -0
  148. package/node/helpers/extend-component.js +1 -0
  149. package/node/hooks/index.js +4 -1
  150. package/node/hooks/useAsyncFn.js +1 -0
  151. package/node/hooks/useDateLocale.js +4 -2
  152. package/node/hooks/useEffectOnce.js +1 -0
  153. package/node/hooks/useFirstMountState.js +1 -0
  154. package/node/hooks/useFocus.js +1 -0
  155. package/node/hooks/useInterval.js +32 -0
  156. package/node/hooks/useIsomorphicLayoutEffect.js +1 -0
  157. package/node/hooks/useKeyUp.js +27 -0
  158. package/node/hooks/useMount.js +1 -0
  159. package/node/hooks/useMountedState.js +1 -0
  160. package/node/hooks/useNavigateAway.js +72 -0
  161. package/node/hooks/usePrevious.js +10 -6
  162. package/node/hooks/usePreviousRef.js +13 -0
  163. package/node/hooks/useScrollPosition.js +1 -0
  164. package/node/hooks/useScrollTo.js +1 -0
  165. package/node/hooks/useTraceUpdate.js +1 -0
  166. package/node/hooks/useUpdateEffect.js +1 -0
  167. package/node/hooks/useWindowSize.js +4 -2
  168. package/package.json +35 -23
  169. package/styles/media.d.ts +3 -3
  170. package/styles/spacing.d.ts +7 -7
  171. package/styles/theme--vanilla.d.ts +4 -4
  172. package/styles/theme.d.ts +4 -4
  173. package/types.d.ts +4 -4
  174. package/hooks/useMediaQueryWidthCreator.d.ts +0 -6
  175. package/hooks/useMediaQueryWidthCreator.js +0 -169
  176. package/hooks/useMqWidthCreator.d.ts +0 -3
  177. package/hooks/useMqWidthCreator.js +0 -225
  178. package/node/hooks/useId.js +0 -12
package/hooks/index.d.ts CHANGED
@@ -4,12 +4,15 @@ export * from "./useEffectOnce";
4
4
  export * from "./useFirstMountState";
5
5
  export * from "./useFixedOffset";
6
6
  export * from "./useFocus";
7
- export * from "./useId";
7
+ export * from "./useInterval";
8
8
  export * from "./useIsomorphicLayoutEffect";
9
+ export * from "./useKeyUp";
9
10
  export * from "./useMeasure";
10
11
  export * from "./useMount";
11
12
  export * from "./useMountedState";
13
+ export * from "./useNavigateAway";
12
14
  export * from "./usePrevious";
15
+ export * from "./usePreviousRef";
13
16
  export * from "./useScrollPosition";
14
17
  export * from "./useSmoothScroll";
15
18
  export * from "./useTraceUpdate";
package/hooks/index.js CHANGED
@@ -4,12 +4,15 @@ export * from "./useEffectOnce";
4
4
  export * from "./useFirstMountState";
5
5
  export * from "./useFixedOffset";
6
6
  export * from "./useFocus";
7
- export * from "./useId";
7
+ export * from "./useInterval";
8
8
  export * from "./useIsomorphicLayoutEffect";
9
+ export * from "./useKeyUp";
9
10
  export * from "./useMeasure";
10
11
  export * from "./useMount";
11
12
  export * from "./useMountedState";
13
+ export * from "./useNavigateAway";
12
14
  export * from "./usePrevious";
15
+ export * from "./usePreviousRef";
13
16
  export * from "./useScrollPosition";
14
17
  // export * from "./useScrollTo";
15
18
  export * from "./useSmoothScroll";
package/hooks/types.d.ts CHANGED
@@ -1,8 +1,8 @@
1
1
  /**
2
2
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/misc/types.ts)
3
3
  */
4
- export declare type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
4
+ export type PromiseType<P extends Promise<any>> = P extends Promise<infer T> ? T : never;
5
5
  /**
6
6
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/misc/types.ts)
7
7
  */
8
- export declare type FunctionReturningPromise = (...args: any[]) => Promise<any>;
8
+ export type FunctionReturningPromise = (...args: any[]) => Promise<any>;
@@ -1,6 +1,6 @@
1
1
  import React from "react";
2
2
  import type { FunctionReturningPromise, PromiseType } from "./types";
3
- export declare type AsyncState<T> = {
3
+ export type AsyncState<T> = {
4
4
  loading: boolean;
5
5
  error?: undefined;
6
6
  value?: undefined;
@@ -17,10 +17,10 @@ export declare type AsyncState<T> = {
17
17
  error?: undefined;
18
18
  value: T;
19
19
  };
20
- declare type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
21
- export declare type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
20
+ type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = AsyncState<PromiseType<ReturnType<T>>>;
21
+ export type AsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
22
22
  /**
23
23
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useAsyncFn.ts)
24
24
  */
25
25
  export declare function useAsyncFn<T extends FunctionReturningPromise>(fn: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>): AsyncFnReturn<T>;
26
- export {};
26
+ export default useAsyncFn;
@@ -34,3 +34,4 @@ export function useAsyncFn(fn, deps, initialState) {
34
34
  }, deps);
35
35
  return [state, callback];
36
36
  }
37
+ export default useAsyncFn;
@@ -5,3 +5,4 @@
5
5
  * @see https://robertmarshall.dev/blog/dynamically-import-datefns-locale-mui-datepicker-localization/
6
6
  */
7
7
  export declare function useDateLocale(locale?: string, defaultLocale?: string): globalThis.Locale | undefined;
8
+ export default useDateLocale;
@@ -36,3 +36,4 @@ export function useDateLocale(locale, defaultLocale) {
36
36
  }, [locale, current]);
37
37
  return data;
38
38
  }
39
+ export default useDateLocale;
@@ -3,3 +3,4 @@ import React from "react";
3
3
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useEffectOnce.ts)
4
4
  */
5
5
  export declare const useEffectOnce: (effect: React.EffectCallback) => void;
6
+ export default useEffectOnce;
@@ -6,3 +6,4 @@ export var useEffectOnce = function (effect) {
6
6
  // eslint-disable-next-line react-hooks/exhaustive-deps
7
7
  useEffect(effect, []);
8
8
  };
9
+ export default useEffectOnce;
@@ -2,3 +2,4 @@
2
2
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useFirstMountState.ts)
3
3
  */
4
4
  export declare function useFirstMountState(): boolean;
5
+ export default useFirstMountState;
@@ -10,3 +10,4 @@ export function useFirstMountState() {
10
10
  }
11
11
  return isFirst.current;
12
12
  }
13
+ export default useFirstMountState;
@@ -2,3 +2,4 @@
2
2
  * @see https://stackoverflow.com/a/54159564/1938970
3
3
  */
4
4
  export declare const useFocus: () => (import("react").RefObject<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement> | (() => void))[];
5
+ export default useFocus;
package/hooks/useFocus.js CHANGED
@@ -9,3 +9,4 @@ export var useFocus = function () {
9
9
  };
10
10
  return [element, setFocus];
11
11
  };
12
+ export default useFocus;
package/hooks/useId.d.ts CHANGED
@@ -2,3 +2,4 @@
2
2
  * FIXME: once we can move to react 18 just replace this import with `{ useId } from "react";`
3
3
  */
4
4
  export declare function useId(prefix?: string): string;
5
+ export default useId;
package/hooks/useId.js CHANGED
@@ -6,3 +6,4 @@ export function useId(prefix) {
6
6
  if (prefix === void 0) { prefix = "uid"; }
7
7
  return "".concat(prefix, "-").concat(uid());
8
8
  }
9
+ export default useId;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * @borrows [dan abramov](https://overreacted.io/making-setinterval-declarative-with-react-hooks/)
3
+ *
4
+ * We just add `deps` array argument and typescript support
5
+ */
6
+ export declare function useInterval<T extends () => unknown>(callback: T, delay: number, deps?: unknown[]): void;
7
+ export default useInterval;
@@ -0,0 +1,28 @@
1
+ import { __spreadArray } from "tslib";
2
+ import { useEffect, useRef } from "react";
3
+ import { noop } from "@koine/utils";
4
+ /**
5
+ * @borrows [dan abramov](https://overreacted.io/making-setinterval-declarative-with-react-hooks/)
6
+ *
7
+ * We just add `deps` array argument and typescript support
8
+ */
9
+ export function useInterval(callback, delay, deps) {
10
+ if (deps === void 0) { deps = []; }
11
+ var savedCallback = useRef();
12
+ useEffect(function () {
13
+ savedCallback.current = callback;
14
+ // eslint-disable-next-line react-hooks/exhaustive-deps
15
+ }, __spreadArray([callback], deps, true));
16
+ useEffect(function () {
17
+ function tick() {
18
+ if (savedCallback.current)
19
+ savedCallback.current();
20
+ }
21
+ if (delay !== null) {
22
+ var id_1 = setInterval(tick, delay);
23
+ return function () { return clearInterval(id_1); };
24
+ }
25
+ return noop;
26
+ }, [delay]);
27
+ }
28
+ export default useInterval;
@@ -3,3 +3,4 @@ import { useEffect } from "react";
3
3
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useFirstMountState.ts)
4
4
  */
5
5
  export declare const useIsomorphicLayoutEffect: typeof useEffect;
6
+ export default useIsomorphicLayoutEffect;
@@ -6,3 +6,4 @@ import { isBrowser } from "@koine/utils";
6
6
  export var useIsomorphicLayoutEffect = isBrowser
7
7
  ? useLayoutEffect
8
8
  : useEffect;
9
+ export default useIsomorphicLayoutEffect;
@@ -0,0 +1,2 @@
1
+ export declare function useKeyUp(callback: (event: KeyboardEvent) => void, deps?: unknown[]): void;
2
+ export default useKeyUp;
@@ -0,0 +1,23 @@
1
+ import { __spreadArray } from "tslib";
2
+ import { useEffect } from "react";
3
+ import { on } from "@koine/dom";
4
+ export function useKeyUp(callback, deps) {
5
+ if (deps === void 0) { deps = []; }
6
+ useEffect(function () {
7
+ var listener = on(window, "keyup", function (event) {
8
+ // const { key } = event;
9
+ // be sure we do not intercept keys combinations maybe used for other
10
+ // actions like native browser navigation shortcuts
11
+ // @see https://stackoverflow.com/a/37559790/1938970
12
+ if (!event.ctrlKey &&
13
+ !event.altKey &&
14
+ !event.shiftKey &&
15
+ !event.metaKey) {
16
+ callback(event);
17
+ }
18
+ });
19
+ return listener;
20
+ // eslint-disable-next-line react-hooks/exhaustive-deps
21
+ }, __spreadArray([callback], deps, true));
22
+ }
23
+ export default useKeyUp;
@@ -9,11 +9,11 @@ interface RectReadOnly {
9
9
  readonly left: number;
10
10
  [key: string]: number;
11
11
  }
12
- declare type HTMLOrSVGElement = HTMLElement | SVGElement;
13
- export declare type UseMeasureOptions = {
12
+ type HTMLOrSVGElement = HTMLElement | SVGElement;
13
+ export type UseMeasureOptions = {
14
14
  scroll?: boolean;
15
15
  };
16
- export declare type UseMeasureReturn = [
16
+ export type UseMeasureReturn = [
17
17
  (element: HTMLOrSVGElement | null) => void,
18
18
  RectReadOnly,
19
19
  () => void
@@ -2,3 +2,4 @@
2
2
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useMount.ts)
3
3
  */
4
4
  export declare const useMount: (fn: () => void) => void;
5
+ export default useMount;
package/hooks/useMount.js CHANGED
@@ -7,3 +7,4 @@ export var useMount = function (fn) {
7
7
  fn();
8
8
  });
9
9
  };
10
+ export default useMount;
@@ -2,3 +2,4 @@
2
2
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useMountedState.ts)
3
3
  */
4
4
  export declare function useMountedState(): () => boolean;
5
+ export default useMountedState;
@@ -13,3 +13,4 @@ export function useMountedState() {
13
13
  }, []);
14
14
  return get;
15
15
  }
16
+ export default useMountedState;
@@ -0,0 +1,32 @@
1
+ /**
2
+ * @return A custom error message (most browser will ignore it), or just a
3
+ * boolean to signal whether we want to prompt the user
4
+ *
5
+ * We might instead return an array with the above as first element and two
6
+ * callbacks, but the callback technique is too cumbersome and unreliable
7
+ * probably:
8
+ * 2) A callback on confirmed leaving
9
+ * 3) A callback on cancel, user stays on page
10
+ */
11
+ export type UseNavigateAwayHandler = (event: BeforeUnloadEvent) => string | boolean;
12
+ /**
13
+ * @resources
14
+ *
15
+ * About browser's specs see:
16
+ * - https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
17
+ * - https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
18
+ * - https://stackoverflow.com/questions/58009424/pagehide-event-on-google-chrome
19
+ *
20
+ * About react see:
21
+ * - https://github.com/jacobbuck/react-beforeunload
22
+ * - https://github.com/dioscarey/react-beforeunload-component
23
+ *
24
+ * About next.js see:
25
+ * - https://github.com/vercel/next.js/issues/2476
26
+ * - https://github.com/vercel/next.js/issues/2694
27
+ *
28
+ * For the callback technique see:
29
+ * - https://stackoverflow.com/a/11835394/1938970
30
+ */
31
+ export declare const useNavigateAway: (handler: UseNavigateAwayHandler) => void;
32
+ export default useNavigateAway;
@@ -0,0 +1,68 @@
1
+ import { useEffect, useRef } from "react";
2
+ import { on } from "@koine/dom";
3
+ // type UseNavigateAwayPagehideHandler = (event: PageTransitionEvent) => unknown;
4
+ /**
5
+ * @resources
6
+ *
7
+ * About browser's specs see:
8
+ * - https://developer.mozilla.org/en-US/docs/Web/API/Window/pagehide_event
9
+ * - https://developer.apple.com/library/archive/documentation/AppleApplications/Reference/SafariWebContent/HandlingEvents/HandlingEvents.html#//apple_ref/doc/uid/TP40006511-SW5
10
+ * - https://stackoverflow.com/questions/58009424/pagehide-event-on-google-chrome
11
+ *
12
+ * About react see:
13
+ * - https://github.com/jacobbuck/react-beforeunload
14
+ * - https://github.com/dioscarey/react-beforeunload-component
15
+ *
16
+ * About next.js see:
17
+ * - https://github.com/vercel/next.js/issues/2476
18
+ * - https://github.com/vercel/next.js/issues/2694
19
+ *
20
+ * For the callback technique see:
21
+ * - https://stackoverflow.com/a/11835394/1938970
22
+ */
23
+ export var useNavigateAway = function (handler) {
24
+ var beforeUnloadHandlerRef = useRef();
25
+ // const pagehideHandlerRef = useRef<UseNavigateAwayPagehideHandler | undefined>();
26
+ useEffect(function () {
27
+ beforeUnloadHandlerRef.current = function (event) {
28
+ var customMessageOrCondition = handler(event);
29
+ if (customMessageOrCondition) {
30
+ event.preventDefault();
31
+ }
32
+ // Handle legacy `event.returnValue` property
33
+ // https://developer.mozilla.org/en-US/docs/Web/API/Window/beforeunload_event
34
+ if (typeof customMessageOrCondition === "string") {
35
+ return (event.returnValue = customMessageOrCondition);
36
+ }
37
+ // Chrome doesn't support `event.preventDefault()` on `BeforeUnloadEvent`,
38
+ // instead it requires `event.returnValue` to be set
39
+ // https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload#browser_compatibility
40
+ if (event.defaultPrevented) {
41
+ return (event.returnValue = "");
42
+ }
43
+ return;
44
+ };
45
+ // pagehideHandlerRef.current = (event) => {
46
+ // const returnValue = handler?.(event);
47
+ // if (event.persisted) {
48
+ // // If the event's persisted property is `true` the page is about
49
+ // // to enter the Back-Forward Cache, which is also in the frozen state.
50
+ // } else {
51
+ // // If the event's persisted property is not `true` the page is
52
+ // // about to be unloaded.
53
+ // }
54
+ // };
55
+ }, [handler]);
56
+ useEffect(function () {
57
+ var listenerBeforeunload = on(window, "beforeunload", function (event) { var _a; return (_a = beforeUnloadHandlerRef.current) === null || _a === void 0 ? void 0 : _a.call(beforeUnloadHandlerRef, event); });
58
+ // const listenerPagehide = on(window, "pagehide", (event) =>
59
+ // pagehideHandlerRef.current?.(event)
60
+ // );
61
+ return listenerBeforeunload;
62
+ // return () => {
63
+ // listenerBeforeunload();
64
+ // // listenerPagehide();
65
+ // };
66
+ }, []);
67
+ };
68
+ export default useNavigateAway;
@@ -1 +1,5 @@
1
- export declare function usePrevious<T>(value: T): T | undefined;
1
+ /**
2
+ * @borrows [samselikoff/animated-carousel](https://github.com/samselikoff/2022-06-02-animated-carousel/blob/main/pages/final.jsx)
3
+ */
4
+ export declare function usePrevious<T>(state: T, defaulValue: T): T;
5
+ export default usePrevious;
@@ -1,8 +1,12 @@
1
- import { useEffect, useRef } from "react";
2
- export function usePrevious(value) {
3
- var ref = useRef();
4
- useEffect(function () {
5
- ref.current = value;
6
- });
7
- return ref.current;
1
+ import { useState } from "react";
2
+ /**
3
+ * @borrows [samselikoff/animated-carousel](https://github.com/samselikoff/2022-06-02-animated-carousel/blob/main/pages/final.jsx)
4
+ */
5
+ export function usePrevious(state, defaulValue) {
6
+ var _a = useState([state, defaulValue]), tuple = _a[0], setTuple = _a[1];
7
+ if (tuple[1] !== state) {
8
+ setTuple([tuple[1], state]);
9
+ }
10
+ return tuple[0];
8
11
  }
12
+ export default usePrevious;
@@ -0,0 +1,2 @@
1
+ export declare function usePreviousRef<T>(value: T): T | undefined;
2
+ export default usePreviousRef;
@@ -0,0 +1,9 @@
1
+ import { useEffect, useRef } from "react";
2
+ export function usePreviousRef(value) {
3
+ var ref = useRef();
4
+ useEffect(function () {
5
+ ref.current = value;
6
+ });
7
+ return ref.current;
8
+ }
9
+ export default usePreviousRef;
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- declare type Position = {
2
+ type Position = {
3
3
  x: number;
4
4
  y: number;
5
5
  };
6
- declare type ElementRef = React.MutableRefObject<HTMLElement | undefined>;
6
+ type ElementRef = React.MutableRefObject<HTMLElement | undefined>;
7
7
  /**
8
8
  * @borrows [@n8tb1t/use-scroll-position@2.0.3](https://github.com/n8tb1t/use-scroll-position) by `n8tb1t <n8tb1t@gmail.com>`
9
9
  *
@@ -12,4 +12,4 @@ declare type ElementRef = React.MutableRefObject<HTMLElement | undefined>;
12
12
  * - compacted object arguments in functions as plain argument list to improve compression
13
13
  */
14
14
  export declare const useScrollPosition: (effect: (currentPosition: Position, prevPosition: Position) => void, deps?: import("react").DependencyList, element?: ElementRef, useWindow?: boolean, wait?: number, boundingElement?: ElementRef) => void;
15
- export {};
15
+ export default useScrollPosition;
@@ -78,3 +78,4 @@ export var useScrollPosition = function (effect, deps, element, useWindow, wait,
78
78
  };
79
79
  }, deps);
80
80
  };
81
+ export default useScrollPosition;
@@ -1 +1,2 @@
1
1
  export declare function useScrollTo(id?: string, offset?: number): void;
2
+ export default useScrollTo;
@@ -19,3 +19,4 @@ export function useScrollTo(id, offset) {
19
19
  top -= headerOffset;
20
20
  window.scroll(0, top);
21
21
  }
22
+ export default useScrollTo;
@@ -2,3 +2,4 @@
2
2
  * @see https://stackoverflow.com/a/51082563/9122820
3
3
  */
4
4
  export declare function useTraceUpdate(props: any): void;
5
+ export default useTraceUpdate;
@@ -19,3 +19,4 @@ export function useTraceUpdate(props) {
19
19
  prev.current = props;
20
20
  });
21
21
  }
22
+ export default useTraceUpdate;
@@ -3,3 +3,4 @@ import { useEffect } from "react";
3
3
  * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useUpdateEffect.ts)
4
4
  */
5
5
  export declare const useUpdateEffect: typeof useEffect;
6
+ export default useUpdateEffect;
@@ -12,3 +12,4 @@ export var useUpdateEffect = function (effect, deps) {
12
12
  // eslint-disable-next-line react-hooks/exhaustive-deps
13
13
  }, deps);
14
14
  };
15
+ export default useUpdateEffect;
@@ -1 +1,2 @@
1
1
  export declare function useWindowSize(): number[];
2
+ export default useWindowSize;
@@ -1,13 +1,15 @@
1
1
  import { useEffect, useState } from "react";
2
+ import { on } from "@koine/dom";
2
3
  export function useWindowSize() {
3
4
  var _a = useState([0, 0]), size = _a[0], setSize = _a[1];
4
5
  useEffect(function () {
5
6
  function updateSize() {
6
7
  setSize([window.innerWidth, window.innerHeight]);
7
8
  }
8
- window.addEventListener("resize", updateSize);
9
+ var listener = on(window, "resize", updateSize);
9
10
  updateSize();
10
- return function () { return window.removeEventListener("resize", updateSize); };
11
+ return listener;
11
12
  }, []);
12
13
  return size;
13
14
  }
15
+ export default useWindowSize;
@@ -1,7 +1,7 @@
1
1
  /// <reference types="react" />
2
2
  import { LazyProps } from "framer-motion";
3
- export declare type MotionProviderFeatures = LazyProps["features"];
4
- export declare type MotionProviderProps = LazyProps & React.PropsWithChildren<{}>;
3
+ export type MotionProviderFeatures = LazyProps["features"];
4
+ export type MotionProviderProps = LazyProps & React.PropsWithChildren<{}>;
5
5
  /**
6
6
  * `<LazyMotion />` provider wrapper from `framer-motion`
7
7
  *
@@ -5,7 +5,7 @@
5
5
  * Maybe do a simplified version following this example:
6
6
  * https://codesandbox.io/s/framer-motion-accordion-qx958?file=/src/Example.tsx
7
7
  */
8
- // import { forwardRef, useCallback, useEffect, /* useId, */ useRef, useState } from "react";
8
+ // import { forwardRef, useCallback, useEffect, useId, useRef, useState } from "react";
9
9
  // import styled from "styled-components";
10
10
  // import { MotionProps, m } from "framer-motion";
11
11
  // import {
@@ -17,7 +17,6 @@
17
17
  // import { btnStyleReset } from "../Buttons";
18
18
  // import { useWindowSize } from "../hooks/useWindowSize";
19
19
  // import { InputInvisible } from "../Forms/styles";
20
- // import { useId } from "../hooks/useId";
21
20
  // export type CollapsableStyledProps = {
22
21
  // $expanded?: boolean;
23
22
  // };
@@ -70,7 +70,7 @@ var DialogWithRef = (0, react_1.forwardRef)(function Dialog(_a, ref) {
70
70
  onClose(event, "backdropClick");
71
71
  }
72
72
  };
73
- return ((0, jsx_runtime_1.jsx)(exports.Root, tslib_1.__assign({ components: { Backdrop: exports.Backdrop }, onClick: handleBackdropClick, onClose: onClose, ref: ref }, props, { children: (0, jsx_runtime_1.jsx)(exports.Container, tslib_1.__assign({ "$scrollPaper": $scrollPaper, onMouseDown: handleMouseDown }, { children: (0, jsx_runtime_1.jsxs)(exports.Paper, tslib_1.__assign({ "aria-label": title || "", "$scrollPaper": $scrollPaper }, { children: [title && (0, jsx_runtime_1.jsx)(exports.Header, { children: title }), (0, jsx_runtime_1.jsx)(exports.Close, tslib_1.__assign({ onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(md_1.MdClear, {}) })), (0, jsx_runtime_1.jsx)(exports.Body, { children: children })] })) })) })));
73
+ return ((0, jsx_runtime_1.jsx)(exports.Root, tslib_1.__assign({ slots: { backdrop: exports.Backdrop }, onClick: handleBackdropClick, onClose: onClose, ref: ref }, props, { children: (0, jsx_runtime_1.jsx)(exports.Container, tslib_1.__assign({ "$scrollPaper": $scrollPaper, onMouseDown: handleMouseDown }, { children: (0, jsx_runtime_1.jsxs)(exports.Paper, tslib_1.__assign({ "aria-label": title || "", "$scrollPaper": $scrollPaper }, { children: [title && (0, jsx_runtime_1.jsx)(exports.Header, { children: title }), (0, jsx_runtime_1.jsx)(exports.Close, tslib_1.__assign({ onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(md_1.MdClear, {}) })), (0, jsx_runtime_1.jsx)(exports.Body, { children: children })] })) })) })));
74
74
  });
75
75
  exports.KoineDialog = (0, helpers_1.extendComponent)(DialogWithRef, {
76
76
  Root: exports.Root,
@@ -40,7 +40,7 @@ var Dialog = (0, react_1.forwardRef)(function Dialog(_a, ref) {
40
40
  onClose(event, "backdropClick");
41
41
  }
42
42
  };
43
- return ((0, jsx_runtime_1.jsx)(Root, tslib_1.__assign({ keepMounted: true, components: { Backdrop: BackdropMotion }, onClick: handleBackdropClick, onClose: onClose, ref: ref }, props, { style: (0, index_1.mRootStyle)(props) }, { children: (0, jsx_runtime_1.jsx)(Container, tslib_1.__assign({ "$scrollPaper": $scrollPaper, onMouseDown: handleMouseDown }, { children: (0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: props.open && (
43
+ return ((0, jsx_runtime_1.jsx)(Root, tslib_1.__assign({ keepMounted: true, slots: { backdrop: BackdropMotion }, onClick: handleBackdropClick, onClose: onClose, ref: ref }, props, { style: (0, index_1.mRootStyle)(props) }, { children: (0, jsx_runtime_1.jsx)(Container, tslib_1.__assign({ "$scrollPaper": $scrollPaper, onMouseDown: handleMouseDown }, { children: (0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: props.open && (
44
44
  // @ts-expect-error framer props collision...
45
45
  (0, jsx_runtime_1.jsxs)(Paper, tslib_1.__assign({}, mPaper, { "aria-label": title || "", "$scrollPaper": $scrollPaper }, { children: [title && (0, jsx_runtime_1.jsx)(Header, { children: title }), (0, jsx_runtime_1.jsx)(Close, tslib_1.__assign({ onClick: onClose }, { children: (0, jsx_runtime_1.jsx)(md_1.MdClear, {}) })), (0, jsx_runtime_1.jsx)(Body, { children: children })] }))) }) })) })));
46
46
  });
@@ -14,6 +14,6 @@ var jsx_runtime_1 = require("react/jsx-runtime");
14
14
  */
15
15
  var FaviconTags = function (_a) {
16
16
  var name = _a.name, color = _a.color, safariTabColor = _a.safariTabColor, tileColor = _a.tileColor, themeColor = _a.themeColor;
17
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("link", { rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png" }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png" }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", type: "image/png", sizes: "16x16", href: "/favicon-16x16.png" }), (0, jsx_runtime_1.jsx)("link", { rel: "manifest", href: "/site.webmanifest" }), (0, jsx_runtime_1.jsx)("link", { rel: "mask-icon", href: "/safari-pinned-tab.svg", color: safariTabColor || color }), (0, jsx_runtime_1.jsx)("meta", { name: "apple-mobile-web-app-title", content: name }), (0, jsx_runtime_1.jsx)("meta", { name: "application-name", content: name }), (0, jsx_runtime_1.jsx)("meta", { name: "msapplication-TileColor", content: tileColor || color }), (0, jsx_runtime_1.jsx)("meta", { name: "theme-color", content: themeColor || color })] }));
17
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)("link", { rel: "shortcut icon", href: "/favicon.ico", type: "image/x-icon" }), (0, jsx_runtime_1.jsx)("link", { rel: "apple-touch-icon", sizes: "180x180", href: "/apple-touch-icon.png" }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", type: "image/png", sizes: "32x32", href: "/favicon-32x32.png" }), (0, jsx_runtime_1.jsx)("link", { rel: "icon", type: "image/png", sizes: "16x16", href: "/favicon-16x16.png" }), (0, jsx_runtime_1.jsx)("link", { rel: "manifest", href: "/site.webmanifest" }), (0, jsx_runtime_1.jsx)("link", { rel: "mask-icon", href: "/safari-pinned-tab.svg", color: safariTabColor || color }), (0, jsx_runtime_1.jsx)("meta", { name: "apple-mobile-web-app-title", content: name }), (0, jsx_runtime_1.jsx)("meta", { name: "application-name", content: name }), (0, jsx_runtime_1.jsx)("meta", { name: "msapplication-TileColor", content: tileColor || color }), (0, jsx_runtime_1.jsx)("meta", { name: "theme-color", content: themeColor || color })] }));
18
18
  };
19
19
  exports.FaviconTags = FaviconTags;
@@ -67,7 +67,7 @@ exports.Menu = (0, react_1.forwardRef)(function Menu(props, ref) {
67
67
  var childrenProps = { close: close };
68
68
  return children(childrenProps);
69
69
  }, [children, close]);
70
- return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Button, { ref: buttonRef, id: id, "aria-haspopup": "true", "aria-controls": open ? id : undefined, "aria-expanded": open ? "true" : undefined, onClick: handleButtonClick, onKeyDown: handleButtonKeyDown }), (0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: open && ((0, jsx_runtime_1.jsx)(ModalUnstyled_1.default, tslib_1.__assign({ components: { Backdrop: MenuBackdrop }, onClose: close, onBackdropClick: close, open: open }, { children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(ClickAwayListener_1.default, tslib_1.__assign({ onClickAway: close }, { children: (0, jsx_runtime_1.jsx)(MenuRoot, tslib_1.__assign({ initial: {
70
+ return ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [(0, jsx_runtime_1.jsx)(Button, { ref: buttonRef, id: id, "aria-haspopup": "true", "aria-controls": open ? id : undefined, "aria-expanded": open ? "true" : undefined, onClick: handleButtonClick, onKeyDown: handleButtonKeyDown }), (0, jsx_runtime_1.jsx)(framer_motion_1.AnimatePresence, { children: open && ((0, jsx_runtime_1.jsx)(ModalUnstyled_1.default, tslib_1.__assign({ slots: { backdrop: MenuBackdrop }, onClose: close, onBackdropClick: close, open: open }, { children: (0, jsx_runtime_1.jsx)("div", { children: (0, jsx_runtime_1.jsx)(ClickAwayListener_1.default, tslib_1.__assign({ onClickAway: close }, { children: (0, jsx_runtime_1.jsx)(MenuRoot, tslib_1.__assign({ initial: {
71
71
  opacity: 0,
72
72
  }, animate: {
73
73
  opacity: 1,
@@ -15,7 +15,7 @@ exports.List = TabsListUnstyled_1.default;
15
15
  exports.Indicator = "span";
16
16
  exports.Panel = TabPanelUnstyled_1.default;
17
17
  exports.Tab = (0, react_1.forwardRef)(function Tab(_a, ref) {
18
- var children = _a.children, component = _a.component, componentsProps = _a.componentsProps, components = _a.components, Indicator = _a.Indicator, props = tslib_1.__rest(_a, ["children", "component", "componentsProps", "components", "Indicator"]);
18
+ var children = _a.children, component = _a.component, slotProps = _a.slotProps, slots = _a.slots, Indicator = _a.Indicator, props = tslib_1.__rest(_a, ["children", "component", "slotProps", "slots", "Indicator"]);
19
19
  var _b = (0, TabUnstyled_1.useTab)(tslib_1.__assign(tslib_1.__assign({}, props), { ref: ref })), active = _b.active, disabled = _b.disabled, selected = _b.selected;
20
20
  var indicatorProps = { active: active, disabled: disabled, selected: selected };
21
21
  return ((0, jsx_runtime_1.jsxs)(TabUnstyled_1.default /* ref={ref} */, tslib_1.__assign({}, props, { children: [children, Indicator && (0, jsx_runtime_1.jsx)(Indicator, tslib_1.__assign({}, indicatorProps))] })));
@@ -70,3 +70,4 @@ function classed(component) {
70
70
  };
71
71
  }
72
72
  exports.classed = classed;
73
+ exports.default = classed;
@@ -14,3 +14,4 @@ var extendComponent = function (component, defaultProps) {
14
14
  return Object.assign(NewComponent, tslib_1.__assign(tslib_1.__assign({}, defaultProps), { defaultProps: defaultProps }));
15
15
  };
16
16
  exports.extendComponent = extendComponent;
17
+ exports.default = exports.extendComponent;
@@ -7,12 +7,15 @@ tslib_1.__exportStar(require("./useEffectOnce"), exports);
7
7
  tslib_1.__exportStar(require("./useFirstMountState"), exports);
8
8
  tslib_1.__exportStar(require("./useFixedOffset"), exports);
9
9
  tslib_1.__exportStar(require("./useFocus"), exports);
10
- tslib_1.__exportStar(require("./useId"), exports);
10
+ tslib_1.__exportStar(require("./useInterval"), exports);
11
11
  tslib_1.__exportStar(require("./useIsomorphicLayoutEffect"), exports);
12
+ tslib_1.__exportStar(require("./useKeyUp"), exports);
12
13
  tslib_1.__exportStar(require("./useMeasure"), exports);
13
14
  tslib_1.__exportStar(require("./useMount"), exports);
14
15
  tslib_1.__exportStar(require("./useMountedState"), exports);
16
+ tslib_1.__exportStar(require("./useNavigateAway"), exports);
15
17
  tslib_1.__exportStar(require("./usePrevious"), exports);
18
+ tslib_1.__exportStar(require("./usePreviousRef"), exports);
16
19
  tslib_1.__exportStar(require("./useScrollPosition"), exports);
17
20
  // export * from "./useScrollTo";
18
21
  tslib_1.__exportStar(require("./useSmoothScroll"), exports);
@@ -38,3 +38,4 @@ function useAsyncFn(fn, deps, initialState) {
38
38
  return [state, callback];
39
39
  }
40
40
  exports.useAsyncFn = useAsyncFn;
41
+ exports.default = useAsyncFn;