@koobiq/react-core 0.0.1-beta.2 → 0.0.1-beta.20

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.
@@ -1,13 +1,15 @@
1
- export * from './usePrevious/index.js';
2
- export * from './useMultiRef/index.js';
3
- export * from './useIsomorphicEffect/index.js';
1
+ export * from './usePrevious';
2
+ export * from './useMultiRef';
3
+ export * from './useIsomorphicEffect';
4
4
  export * from './useMediaQuery';
5
- export * from './useSsr/index.js';
6
- export * from './useDOMRef/index.js';
7
- export * from './useBoolean/index.js';
8
- export * from './useMutableRef/index.js';
9
- export * from './useInterval/index.js';
10
- export * from './useIsFirstRender/index.js';
11
- export * from './useEventListener/index.js';
12
- export * from './useResizeObserver/index.js';
13
- export * from './useElementSize/index.js';
5
+ export * from './useSsr';
6
+ export * from './useDOMRef';
7
+ export * from './useBoolean';
8
+ export * from './useMutableRef';
9
+ export * from './useInterval';
10
+ export * from './useIsFirstRender';
11
+ export * from './useEventListener';
12
+ export * from './useResizeObserver';
13
+ export * from './useElementSize';
14
+ export * from './useRefs';
15
+ export * from './useDebounceCallback';
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useState, useCallback } from "react";
2
3
  function useBoolean(defaultValue = false) {
3
4
  const [value, setValue] = useState(defaultValue);
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useRef, useImperativeHandle } from "react";
2
3
  function useDOMRef(ref) {
3
4
  const domRef = useRef(null);
@@ -0,0 +1 @@
1
+ export * from './useDebounceCallback';
@@ -0,0 +1,29 @@
1
+ type FunctionCallback = (...args: any[]) => void;
2
+ export type UseDebounceCallbackReturnValue<CB extends FunctionCallback> = [
3
+ CB,
4
+ () => void
5
+ ];
6
+ export type UseDebounceCallbackPropOptions = {
7
+ /**
8
+ * If `true`, the first call runs without delay.
9
+ * @default false
10
+ * */
11
+ firstCallWithoutDelay: boolean;
12
+ };
13
+ export type UseDebounceCallbackProps<CB> = {
14
+ /**
15
+ * The function to be debounced.
16
+ * It will only run after the specified delay has passed without new calls.
17
+ */
18
+ callback: CB;
19
+ /**
20
+ * Delay in milliseconds to wait before calling the callback.
21
+ * @default 300
22
+ */
23
+ delay?: number;
24
+ /** Additional debounce options. */
25
+ options?: UseDebounceCallbackPropOptions;
26
+ };
27
+ /** A hook that waits some time before running a function. */
28
+ export declare function useDebounceCallback<CB extends FunctionCallback>({ callback, delay, options, }: UseDebounceCallbackProps<CB>): UseDebounceCallbackReturnValue<CB>;
29
+ export {};
@@ -0,0 +1,39 @@
1
+ "use client";
2
+ import { useRef, useCallback, useEffect } from "react";
3
+ function useDebounceCallback({
4
+ callback,
5
+ delay = 300,
6
+ options = { firstCallWithoutDelay: false }
7
+ }) {
8
+ const { firstCallWithoutDelay } = options;
9
+ const timeoutRef = useRef(null);
10
+ const debouncedHandler = useCallback(
11
+ (...args) => {
12
+ if (!timeoutRef.current && firstCallWithoutDelay) {
13
+ callback(...args);
14
+ timeoutRef.current = setTimeout(() => {
15
+ timeoutRef.current = null;
16
+ }, delay);
17
+ return;
18
+ }
19
+ if (timeoutRef.current) {
20
+ clearTimeout(timeoutRef.current);
21
+ }
22
+ timeoutRef.current = setTimeout(() => {
23
+ callback(...args);
24
+ timeoutRef.current = null;
25
+ }, delay);
26
+ },
27
+ [callback, delay, options.firstCallWithoutDelay]
28
+ );
29
+ const cancel = useCallback(() => {
30
+ if (timeoutRef.current) {
31
+ clearTimeout(timeoutRef.current);
32
+ }
33
+ }, []);
34
+ useEffect(() => () => cancel(), []);
35
+ return [debouncedHandler, cancel];
36
+ }
37
+ export {
38
+ useDebounceCallback
39
+ };
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useLayoutEffect, useEffect } from "react";
2
3
  import { isBrowser } from "../../utils/isBrowser.js";
3
4
  const useIsomorphicEffect = isBrowser() ? useLayoutEffect : useEffect;
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useRef, useEffect } from "react";
2
3
  function usePrevious(value) {
3
4
  const ref = useRef(null);
@@ -0,0 +1 @@
1
+ export * from './useRefs';
@@ -0,0 +1,3 @@
1
+ import { type RefObject } from 'react';
2
+ export type UseRefsReturn<T, Keys extends number | readonly string[]> = Keys extends readonly string[] ? Record<Keys[number], RefObject<T>> : Array<RefObject<T>>;
3
+ export declare const useRefs: <T, Keys extends number | readonly string[] = number>(keys: Keys, deps?: unknown[]) => UseRefsReturn<T, Keys>;
@@ -0,0 +1,14 @@
1
+ "use client";
2
+ import { useMemo, createRef } from "react";
3
+ import { isNumber } from "../../utils/typeGuards/isNumber.js";
4
+ const useRefs = (keys, deps = []) => useMemo(() => {
5
+ if (!isNumber(keys)) {
6
+ return Object.fromEntries(
7
+ keys.map((key) => [key, createRef()])
8
+ );
9
+ }
10
+ return new Array(keys).fill(0).map(() => createRef());
11
+ }, [isNumber(keys) ? keys : keys.join("-"), ...deps]);
12
+ export {
13
+ useRefs
14
+ };
@@ -1,3 +1,4 @@
1
+ "use client";
1
2
  import { useState, useEffect } from "react";
2
3
  import { isBrowser } from "../../utils/isBrowser.js";
3
4
  const useSsr = () => {
package/dist/index.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  import { useFocusRing, FocusableProvider } from '@react-aria/focus';
2
- import { useHover, usePress } from '@react-aria/interactions';
2
+ import { useHover, usePress, Pressable } from '@react-aria/interactions';
3
3
  import { mergeProps, filterDOMProps } from '@react-aria/utils';
4
4
  import { useToggleState } from '@react-stately/toggle';
5
5
  export * from './types/index.js';
6
6
  export * from './styles/index.js';
7
7
  export * from './hooks/index.js';
8
8
  export * from './utils/index.js';
9
- export { FocusableProvider, mergeProps, useFocusRing, useHover, usePress, useToggleState, filterDOMProps, };
9
+ export { FocusableProvider, Pressable, mergeProps, useFocusRing, useHover, usePress, useToggleState, filterDOMProps, };
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  import { FocusableProvider, useFocusRing } from "@react-aria/focus";
2
- import { useHover, usePress } from "@react-aria/interactions";
2
+ import { Pressable, useHover, usePress } from "@react-aria/interactions";
3
3
  import { filterDOMProps, mergeProps } from "@react-aria/utils";
4
4
  import { useToggleState } from "@react-stately/toggle";
5
5
  import { clsx } from "./styles/clsx.js";
@@ -16,6 +16,8 @@ import { useIsFirstRender } from "./hooks/useIsFirstRender/useIsFirstRender.js";
16
16
  import { useEventListener } from "./hooks/useEventListener/useEventListener.js";
17
17
  import { useResizeObserver } from "./hooks/useResizeObserver/useResizeObserver.js";
18
18
  import { useElementSize } from "./hooks/useElementSize/useElementSize.js";
19
+ import { useRefs } from "./hooks/useRefs/useRefs.js";
20
+ import { useDebounceCallback } from "./hooks/useDebounceCallback/useDebounceCallback.js";
19
21
  import { polymorphicForwardRef } from "./utils/polymorphicForwardRef.js";
20
22
  import { isNotNil } from "./utils/typeGuards/isNotNil.js";
21
23
  import { isString } from "./utils/typeGuards/isString.js";
@@ -25,6 +27,7 @@ import { isBrowser } from "./utils/isBrowser.js";
25
27
  import { capitalizeFirstLetter } from "./utils/capitalizeFirstLetter/capitalizeFirstLetter.js";
26
28
  export {
27
29
  FocusableProvider,
30
+ Pressable,
28
31
  capitalizeFirstLetter,
29
32
  clsx,
30
33
  filterDOMProps,
@@ -37,6 +40,7 @@ export {
37
40
  setRef,
38
41
  useBoolean,
39
42
  useDOMRef,
43
+ useDebounceCallback,
40
44
  useElementSize,
41
45
  useEventListener,
42
46
  useFocusRing,
@@ -49,6 +53,7 @@ export {
49
53
  useMutableRef,
50
54
  usePress,
51
55
  usePrevious,
56
+ useRefs,
52
57
  useResizeObserver,
53
58
  useSsr,
54
59
  useToggleState
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@koobiq/react-core",
3
- "version": "0.0.1-beta.2",
3
+ "version": "0.0.1-beta.20",
4
4
  "main": "./dist/index.js",
5
5
  "types": "./dist/index.d.ts",
6
6
  "exports": {
@@ -16,6 +16,11 @@
16
16
  "publishConfig": {
17
17
  "access": "public"
18
18
  },
19
+ "repository": {
20
+ "type": "git",
21
+ "directory": "packages/core",
22
+ "url": "git+https://github.com/koobiq/react-components.git"
23
+ },
19
24
  "sideEffects": false,
20
25
  "dependencies": {
21
26
  "@react-aria/focus": "^3.18.0",