@koine/react 2.0.0-beta.132 → 2.0.0-beta.133

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/FaviconTags.d.ts CHANGED
@@ -5,5 +5,15 @@ export type FaviconTagsProps = {
5
5
  tileColor?: string;
6
6
  themeColor?: string;
7
7
  };
8
+ /**
9
+ * Favicon tags.
10
+ *
11
+ * This component is meant to be wrapped in a `<head>` manager component.
12
+ *
13
+ * These tags have been produced by [realfavicongenerator.net](https://realfavicongenerator.net/)
14
+ * on _**16 Feb 2022**_.
15
+ *
16
+ * @see https://realfavicongenerator.net/
17
+ */
8
18
  export declare let FaviconTags: ({ name, color, safariTabColor, tileColor, themeColor, }: FaviconTagsProps) => import("react/jsx-runtime").JSX.Element;
9
19
  export default FaviconTags;
package/Meta.d.ts CHANGED
@@ -1,4 +1,14 @@
1
1
  export type MetaProps = {
2
+ /**
3
+ * Determines whether `user-scalable=0` is add to the `meta->viewport` content
4
+ *
5
+ * This is an opt in instead of the default browser behaviour as it helps prevent
6
+ * weird zooming on input fields on iPhone iOS devices.
7
+ * @see https://www.warrenchandler.com/2019/04/02/stop-iphones-from-zooming-in-on-form-fields/
8
+ * @see https://css-tricks.com/16px-or-larger-text-prevents-ios-form-zoom/
9
+ *
10
+ * @default false
11
+ */
2
12
  zoom?: boolean;
3
13
  };
4
14
  export declare let Meta: ({ zoom }: MetaProps) => import("react/jsx-runtime").JSX.Element;
package/Polymorphic.d.ts CHANGED
@@ -1,3 +1,16 @@
1
+ /**
2
+ * React Polymorphic components type utilities
3
+ *
4
+ * @resources
5
+ * - [Polymorphic types from Radix UI in Wanda System](https://github.com/wonderflow-bv/wanda/blob/main/packages/react-components/src/types/polymorphic/index.ts)
6
+ * - [TypeScript + React: Typing Generic forwardRefs](https://fettblog.eu/typescript-react-generic-forward-refs/)
7
+ * - [React with Typescript -- Generics while using React.forwardRef](https://stackoverflow.com/a/58473012/1938970)
8
+ * - [How to write a generic that extracts the prop types of the component that passed in](https://stackoverflow.com/a/57846897/1938970)
9
+ * - [React TS Generic component to pass generic props to children](https://stackoverflow.com/a/68442669/1938970)
10
+ * - [About custom ref prop](https://gist.github.com/gaearon/1a018a023347fe1c2476073330cc5509)
11
+ * - [forwardRef performance](https://github.com/facebook/react/issues/13456)
12
+ * - [React docs: Exposing DOM Refs to Parent Components](https://github.com/facebook/react/issues/13456)
13
+ */
1
14
  export declare namespace Polymorphic {
2
15
  type Merge<P1 = Record<string, never>, P2 = Record<string, never>> = Omit<P1, keyof P2> & P2;
3
16
  type ComponentTypes = React.ComponentClass<any> | React.FunctionComponent<any> | keyof JSX.IntrinsicElements;
@@ -1,9 +1,17 @@
1
1
  import type { CalendarEventsMap, Calendars } from "./types";
2
2
  type GetCalendarsEventsFromGoogleOptions = {
3
+ /** Fall back to `process.env.GOOGLE_CALENDAR_API_KEY */
3
4
  apiKey?: string;
5
+ /** Start gethering events from date */
4
6
  start: Date;
7
+ /** End gethering events at date */
5
8
  end: Date;
9
+ /**
10
+ * The default is the time zone of the calendar
11
+ * @see https://developers.google.com/calendar/api/v3/reference/events/list
12
+ */
6
13
  timeZone?: string;
14
+ /** The calendars settings */
7
15
  calendars: Calendars;
8
16
  };
9
17
  export declare let getCalendarsEventsFromGoogle: ({ calendars, ...options }: GetCalendarsEventsFromGoogleOptions) => Promise<CalendarEventsMap>;
@@ -1,6 +1,10 @@
1
1
  export type Calendar = {
2
2
  id: string;
3
3
  color: string;
4
+ /**
5
+ * If not defined the name is gathered from the remote calendar response,
6
+ * for google calendars that comes from the `summary` value.
7
+ */
4
8
  name?: string;
5
9
  };
6
10
  export type Calendars = Calendar[];
@@ -12,8 +16,17 @@ export type CalendarRange = [Date, Date];
12
16
  export type CalendarView = "month" | "week";
13
17
  export type CalendarEvent = {
14
18
  calendar: Calendar;
19
+ /**
20
+ * List of day timestamps across which the event spans
21
+ */
15
22
  days: number[];
23
+ /**
24
+ * Lookup object for day timestamps across which the event spans
25
+ */
16
26
  daysMap: Record<number, 1>;
27
+ /**
28
+ * Flag for events that spans across multiple days
29
+ */
17
30
  multi: boolean;
18
31
  allDay: boolean;
19
32
  link: string;
@@ -27,7 +40,13 @@ export type CalendarEvent = {
27
40
  description: string;
28
41
  uid: string;
29
42
  };
43
+ /**
44
+ * Calendar events mapped by day `timestamp` number
45
+ */
30
46
  export type CalendarEventsByTimestamp = Record<number, CalendarEventsMap>;
47
+ /**
48
+ * Calendar events map by `uid`
49
+ */
31
50
  export type CalendarEventsMap = Record<CalendarEvent["uid"], CalendarEvent>;
32
51
  export type CalendarViewWeeks = CalendarViewWeek[];
33
52
  export type CalendarViewWeek = {
@@ -3,13 +3,27 @@ import type { KoineCalendarDaygridTableProps } from "./CalendarDaygridTable";
3
3
  import type { KoineCalendarLegendProps } from "./CalendarLegend";
4
4
  import type { CalendarEvent, CalendarEventsMap, CalendarView, Calendars } from "./types";
5
5
  export type UseCalendarProps = {
6
+ /** The locale to format with `date-fns` */
6
7
  locale: string;
8
+ /** Calendars infos to use */
7
9
  calendars: Calendars;
10
+ /** Fall back to `process.env.GOOGLE_CALENDAR_API_KEY */
8
11
  apiKey?: string;
12
+ /** The key is the event `uid` */
9
13
  events?: CalendarEventsMap;
14
+ /** It defaults to the first of the current month */
10
15
  start?: Date;
16
+ /** It defaults to the last day of the current month */
11
17
  end?: Date;
18
+ /**
19
+ * The calendar view
20
+ * @default "month"
21
+ */
12
22
  view?: CalendarView;
23
+ /**
24
+ * The default is the time zone of the calendar
25
+ * @see https://developers.google.com/calendar/api/v3/reference/events/list
26
+ */
13
27
  timeZone?: string;
14
28
  onError?: (e: any) => void;
15
29
  };
@@ -1,2 +1,8 @@
1
1
  import type { Locale } from "date-fns";
2
+ /**
3
+ * Dynamically import the date-fns correct locale
4
+ *
5
+ * Inspired by:
6
+ * @see https://robertmarshall.dev/blog/dynamically-import-datefns-locale-mui-datepicker-localization/
7
+ */
2
8
  export declare let useDateLocale: (locale?: string, defaultLocale?: string) => Locale | undefined;
package/classed.d.ts CHANGED
@@ -4,5 +4,24 @@ type ClassedAugmentedProps<Props> = Props & {
4
4
  ref?: React.Ref<any>;
5
5
  };
6
6
  type ClassedFinalProps<Props, Component> = Component extends React.ReactHTML ? React.HTMLProps<Component> & ClassedAugmentedProps<Props> : ClassedAugmentedProps<Props>;
7
+ /**
8
+ * This utility allows to extend a component a là `styled-components` but for
9
+ * a className based styling solution like Tailwind,
10
+ *
11
+ * It also plays nicely with tailwind intellisense:
12
+ * - https://github.com/tailwindlabs/tailwindcss-intellisense#tailwindcssclassattributes
13
+ *
14
+ * For references about tagged functions:
15
+ * - https://javascript.plainenglish.io/how-css-in-js-libraries-work-da4145b1b6c7
16
+ * - https://makersden.io/blog/reverse-engineering-styled-components
17
+ * - https://typesafe.blog/article/the-logic-behind-javascript-tag-functions
18
+ * - https://flaming.codes/posts/typescript-and-javascript-tagged-template-strings
19
+ *
20
+ * Similar projects:
21
+ * - https://reactjsexample.com/style-radix-ui-components-with-tailwindcss/
22
+ *
23
+ * Discussions and Q/A:
24
+ * - https://stackoverflow.com/q/73055695/1938970
25
+ */
7
26
  export declare let classed: <Props, Component extends React.ElementType = any>(component: Component) => (strings: TemplateStringsArray, ...args: ((props: Props) => string)[] | string[]) => React.ForwardRefExoticComponent<React.PropsWithoutRef<ClassedFinalProps<Props, Component>> & React.RefAttributes<Component>>;
8
27
  export default classed;
@@ -2,5 +2,11 @@ import { type GetMediaQueryWidthResolversBreakpoints } from "@koine/utils";
2
2
  type _MediaQuerWidthDefExplicit<TBreakpoint extends string> = `min-${TBreakpoint}` | `max-${TBreakpoint}` | `up-${TBreakpoint}` | `down-${TBreakpoint}` | `between-${TBreakpoint}_${TBreakpoint}` | `only-${TBreakpoint}`;
3
3
  export type MediaQuerWidthDef<TBreakpoint extends string> = `${TBreakpoint}` | _MediaQuerWidthDefExplicit<TBreakpoint>;
4
4
  export type MediaQueryWidth<TBreakpoint extends string> = `@${MediaQuerWidthDef<TBreakpoint>}`;
5
+ /**
6
+ * Use `null` instead of `false` as default value, @see https://observablehq.com/@werehamster/avoiding-hydration-mismatch-when-using-react-hooks
7
+ *
8
+ * @param customBreakpoints
9
+ * @returns
10
+ */
5
11
  export declare let createUseMediaQueryWidth: <TBreakpointsConfig extends GetMediaQueryWidthResolversBreakpoints>(customBreakpoints: TBreakpointsConfig) => <TBreakpoints extends Extract<keyof TBreakpointsConfig, string>>(media: MediaQueryWidth<TBreakpoints>, serverValue?: null | boolean) => boolean | null;
6
12
  export default createUseMediaQueryWidth;
@@ -9,6 +9,17 @@ export interface OverridableComponents {
9
9
  motionable?: boolean;
10
10
  };
11
11
  }
12
+ /**
13
+ * Type to define a component that has overridable components.
14
+ *
15
+ * Each of them can define its:
16
+ * - `type`: either as a native HTMLElement (the props for that element will be
17
+ * automatically inferred) or as a custom React component
18
+ * - `props`: any additional custom props
19
+ * - `motionable`: if that component has a possible implementation with `framer-motion`,
20
+ * in that case we remove some HTMLAttributes props which collides with
21
+ * `MotionProps` from framer.
22
+ */
12
23
  export type WithComponents<Props, Components extends OverridableComponents> = Props & {
13
24
  [Name in keyof Components]: NonNullable<Components[Name]["type"] extends keyof JSX.IntrinsicElements ? React.ElementType<Components[Name]["motionable"] extends true ? Omit<React.ComponentPropsWithoutRef<Components[Name]["type"]>, HtmlAttributesCollidingWithMotionProps> & Components[Name]["props"] : React.ComponentPropsWithoutRef<Components[Name]["type"]> & Components[Name]["props"]> : Components[Name]["type"]>;
14
25
  };
@@ -1,4 +1,15 @@
1
1
  import { type ObjectShape } from "@kuus/yup";
2
+ /**
3
+ * Encode form
4
+ *
5
+ * Takes a record of yup validations and outputs a `yup` schema with encoded
6
+ * names (antispam technique) and a record of the encoded/decoded input `name`s.
7
+ *
8
+ * We skip the names prefixed wth an underscore which are considered programmatic
9
+ * form data not created by user input.
10
+ *
11
+ * FIXME: types https://github.com/jquense/yup/issues/1700
12
+ */
2
13
  export declare let encodeForm: <T extends ObjectShape = {}>(validationRules: T) => {
3
14
  encodedSchema: import("@kuus/yup").ObjectSchema<{
4
15
  [x: string]: T[keyof T] extends import("@kuus/yup").ISchema<any, any, any, any> ? T[keyof T]["__outputType"] : T[keyof T] extends {
@@ -24,4 +35,13 @@ export declare let encodeForm: <T extends ObjectShape = {}>(validationRules: T)
24
35
  }, "">;
25
36
  encodedNames: Record<keyof T, string>;
26
37
  };
38
+ /**
39
+ * Decode form data
40
+ *
41
+ * This function is meant to be used inside an api endpoint to gather an encoded
42
+ * form submit data and transform it to the decoded desired json data.
43
+ *
44
+ * Here too we skip encoding/decoding process for names prefixed wth an underscore
45
+ * which are considered programmatic form data not created by user input.
46
+ */
27
47
  export declare let decodeForm: <ReturnAs extends Record<string, unknown> = {}, FormData extends Record<string, unknown> = {}>(formData: FormData) => ReturnAs;
package/package.json CHANGED
@@ -2,8 +2,8 @@
2
2
  "name": "@koine/react",
3
3
  "sideEffects": false,
4
4
  "dependencies": {
5
- "@koine/dom": "2.0.0-beta.132",
6
- "@koine/utils": "2.0.0-beta.132"
5
+ "@koine/dom": "2.0.0-beta.133",
6
+ "@koine/utils": "2.0.0-beta.133"
7
7
  },
8
8
  "peerDependencies": {
9
9
  "@kuus/yup": "1.0.0-beta.7",
@@ -223,5 +223,5 @@
223
223
  "module": "./index.esm.js",
224
224
  "main": "./index.cjs.js",
225
225
  "types": "./index.esm.d.ts",
226
- "version": "2.0.0-beta.132"
226
+ "version": "2.0.0-beta.133"
227
227
  }
package/useAsyncFn.d.ts CHANGED
@@ -20,5 +20,8 @@ export type UseAsyncState<T> = {
20
20
  };
21
21
  type StateFromFunctionReturningPromise<T extends FunctionReturningPromise> = UseAsyncState<PromiseType<ReturnType<T>>>;
22
22
  export type UseAsyncFnReturn<T extends FunctionReturningPromise = FunctionReturningPromise> = [StateFromFunctionReturningPromise<T>, T];
23
+ /**
24
+ * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useAsyncFn.ts)
25
+ */
23
26
  export declare let useAsyncFn: <T extends FunctionReturningPromise>(fn: T, deps?: React.DependencyList, initialState?: StateFromFunctionReturningPromise<T>) => UseAsyncFnReturn<T>;
24
27
  export default useAsyncFn;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useFirstMountState.ts)
3
+ */
1
4
  export declare let useFirstMountState: () => boolean;
2
5
  export default useFirstMountState;
@@ -1,2 +1,11 @@
1
+ /**
2
+ * # Use fixed offset
3
+ *
4
+ * Maybe use [ResizeObserver polyfill](https://github.com/juggle/resize-observer)
5
+ *
6
+ * @see https://web.dev/resize-observer/
7
+ *
8
+ * @param selector By default `[data-fixed]`: anyhting with the data attribute `data-fixed`
9
+ */
1
10
  export declare let useFixedOffset: (selector?: string) => import("react").MutableRefObject<number>;
2
11
  export default useFixedOffset;
package/useFocus.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @see https://stackoverflow.com/a/54159564/1938970
3
+ */
1
4
  export declare let useFocus: () => (import("react").RefObject<HTMLInputElement | HTMLSelectElement | HTMLTextAreaElement> | (() => void))[];
2
5
  export default useFocus;
package/useInterval.d.ts CHANGED
@@ -1,2 +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
+ */
1
6
  export declare let useInterval: <T extends () => unknown>(callback: T, delay: number, deps?: unknown[]) => void;
2
7
  export default useInterval;
@@ -1,3 +1,6 @@
1
1
  import { useLayoutEffect } from "react";
2
+ /**
3
+ * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useIsomorphicLayoutEffect.ts)
4
+ */
2
5
  export declare let useIsomorphicLayoutEffect: typeof useLayoutEffect;
3
6
  export default useIsomorphicLayoutEffect;
package/useMeasure.d.ts CHANGED
@@ -18,5 +18,10 @@ export type UseMeasureReturn = [
18
18
  RectReadOnly,
19
19
  () => void
20
20
  ];
21
+ /**
22
+ * Use measure hook
23
+ *
24
+ * @borrows [pmndrs/react-use-measure](https://github.com/pmndrs/react-use-measure)
25
+ */
21
26
  export declare let useMeasure: (options?: UseMeasureOptions) => UseMeasureReturn;
22
27
  export default useMeasure;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useMountedState.ts)
3
+ */
1
4
  export declare let useMountedState: () => (() => boolean);
2
5
  export default useMountedState;
@@ -1,3 +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
+ */
1
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
+ */
2
31
  export declare let useNavigateAway: (handler: UseNavigateAwayHandler) => void;
3
32
  export default useNavigateAway;
package/usePrevious.d.ts CHANGED
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @borrows [samselikoff/animated-carousel](https://github.com/samselikoff/2022-06-02-animated-carousel/blob/main/pages/final.jsx)
3
+ */
1
4
  export declare let usePrevious: <T extends unknown>(state: T, defaulValue: T) => T;
2
5
  export default usePrevious;
package/useReveal.d.ts CHANGED
@@ -1,7 +1,28 @@
1
1
  export type UseRevealOptions = {
2
+ /**
3
+ * @default "left"
4
+ */
2
5
  direction?: "left" | "right";
6
+ /**
7
+ * A number that represents the offset to start the animations, giving `-1`
8
+ * means that the animation will start when the scroll position is at
9
+ * 100% higher than the given element. Giving `2` the animation will starts
10
+ * when the scroll reached two times the height of the given element below
11
+ * the top edge of the element itself
12
+ *
13
+ * @default -2
14
+ */
3
15
  offsetStartY?: number;
16
+ /**
17
+ * When 0 it defaults to the same as the offsetStartY
18
+ * @default 0
19
+ */
4
20
  offsetEndY?: number;
21
+ /**
22
+ * A value from `0` to `1` representing a proportion of the element width
23
+ * or "all" to make it completely out of the viewport
24
+ * @default "all"
25
+ * */
5
26
  offsetStartX?: number | "all";
6
27
  };
7
28
  export declare let useReveal: <T extends HTMLElement = HTMLDivElement>({ direction, offsetStartY, offsetEndY, offsetStartX, }: UseRevealOptions) => {
@@ -3,5 +3,12 @@ type Position = {
3
3
  y: number;
4
4
  };
5
5
  type ElementRef = React.MutableRefObject<HTMLElement | undefined>;
6
+ /**
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
+ */
6
13
  export declare let useScrollPosition: (effect: (currentPosition: Position, prevPosition: Position) => void, deps?: React.DependencyList, element?: ElementRef, boundingElement?: ElementRef, wait?: number) => void;
7
14
  export default useScrollPosition;
@@ -1,2 +1,8 @@
1
+ /**
2
+ *
3
+ * @param disregardAutomaticFixedOffset When the `to` scroll argument is a DOM
4
+ * selector we will keep into account the _fixedOffset_ despite this option.
5
+ * @returns
6
+ */
1
7
  export declare let useSmoothScroll: (disregardAutomaticFixedOffset?: boolean) => (to?: number | string, customOffset?: number, callback?: () => void, fallbackTimeout?: number, behavior?: ScrollBehavior) => void;
2
8
  export default useSmoothScroll;
package/useSpinDelay.d.ts CHANGED
@@ -1,2 +1,14 @@
1
+ /**
2
+ * Wraps your booleans only returning true after the `delay`, and for a minimum
3
+ * time of `minDuration`. This way you're sure that you don't show unnecessary
4
+ * or very short living spinners.
5
+ *
6
+ * @borrows [smeijer/spin-delay](https://github.com/smeijer/spin-delay)
7
+ *
8
+ * - Smaller footprint and options object as argument
9
+ *
10
+ * @param delay [500]
11
+ * @param minDuration [200]
12
+ */
1
13
  export declare let useSpinDelay: (loading: boolean, delay?: number, minDuration?: number) => boolean;
2
14
  export default useSpinDelay;
@@ -1,2 +1,5 @@
1
+ /**
2
+ * @see https://stackoverflow.com/a/51082563/9122820
3
+ */
1
4
  export declare let useTraceUpdate: (props: any) => void;
2
5
  export default useTraceUpdate;
@@ -1,3 +1,6 @@
1
1
  import { useEffect } from "react";
2
+ /**
3
+ * @borrows [streamich/react-use](https://github.com/streamich/react-use/blob/master/src/useUpdateEffect.ts)
4
+ */
2
5
  export declare let useUpdateEffect: typeof useEffect;
3
6
  export default useUpdateEffect;
@@ -1,3 +1,12 @@
1
1
  import { debounce } from "@koine/utils";
2
+ /**
3
+ * # Use `window` size
4
+ *
5
+ * @param args Optionally pass {@link debounce} arguments (`wait` and `immediate`)
6
+ *
7
+ * @returns An array with:
8
+ * 1) _width_: using `window.innerWidth`
9
+ * 2) _height_: using `window.innerHeight`
10
+ */
2
11
  export declare let useWindowSize: (wait?: Parameters<typeof debounce>[1], immediate?: Parameters<typeof debounce>[2]) => readonly [number, number];
3
12
  export default useWindowSize;