@siberiacancode/reactuse 0.1.0 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,80 @@
1
+ import { HookTarget } from '../../utils/helpers';
2
+ import { StateRef } from '../useRefState/useRefState';
3
+ export type DropZoneDataTypes = ((types: string[]) => boolean) | string[];
4
+ export interface UseDropZoneOptions {
5
+ /** The data types for drop zone */
6
+ dataTypes?: DropZoneDataTypes;
7
+ /** The multiple mode for drop zone */
8
+ multiple?: boolean;
9
+ /** The on drop callback */
10
+ onDrop?: (files: File[] | null, event: DragEvent) => void;
11
+ /** The on enter callback */
12
+ onEnter?: (event: DragEvent) => void;
13
+ /** The on leave callback */
14
+ onLeave?: (event: DragEvent) => void;
15
+ /** The on over callback */
16
+ onOver?: (event: DragEvent) => void;
17
+ }
18
+ export interface UseDropZoneReturn {
19
+ /** The files that was dropped in drop zone */
20
+ files: File[] | null;
21
+ /** The over drop zone status */
22
+ overed: boolean;
23
+ }
24
+ export interface UseDropZone {
25
+ (target: HookTarget, callback?: (files: File[] | null, event: DragEvent) => void): UseDropZoneReturn;
26
+ <Target extends Element>(callback?: (files: File[] | null, event: DragEvent) => void, target?: never): UseDropZoneReturn & {
27
+ ref: StateRef<Target>;
28
+ };
29
+ (target: HookTarget, options?: UseDropZoneOptions): UseDropZoneReturn;
30
+ <Target extends Element>(options?: UseDropZoneOptions, target?: never): UseDropZoneReturn & {
31
+ ref: StateRef<Target>;
32
+ };
33
+ }
34
+ /**
35
+ * @name useDropZone
36
+ * @description - Hook that provides drop zone functionality
37
+ * @category Elements
38
+ *
39
+ * @overload
40
+ * @template Target The target element
41
+ * @param {Target} target The target element drop zone's
42
+ * @param {DataTypes} [options.dataTypes] The data types
43
+ * @param {boolean} [options.multiple] The multiple mode
44
+ * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function
45
+ * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function
46
+ * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function
47
+ * @param {(event: DragEvent) => void} [options.onOver] The on over callback function
48
+ * @returns {[boolean, File[] | null]} The object with drop zone states
49
+ *
50
+ * @example
51
+ * const { overed, files } = useDropZone(ref, options);
52
+ *
53
+ * @overload
54
+ * @param {Target} target The target element drop zone's
55
+ * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop
56
+ * @returns {[boolean, File[] | null]} The object with drop zone states
57
+ *
58
+ * @example
59
+ * const { overed, files } = useDropZone(ref, () => console.log('callback'));
60
+ *
61
+ * @overload
62
+ * @param {DataTypes} [options.dataTypes] The data types
63
+ * @param {boolean} [options.multiple] The multiple mode
64
+ * @param {(files: File[] | null, event: DragEvent) => void} [options.onDrop] The on drop callback function
65
+ * @param {(event: DragEvent) => void} [options.onEnter] The on enter callback function
66
+ * @param {(event: DragEvent) => void} [options.onLeave] The on leave callback function
67
+ * @param {(event: DragEvent) => void} [options.onOver] The on over callback function
68
+ * @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref
69
+ *
70
+ * @example
71
+ * const { ref, overed, files } = useDropZone(options);
72
+ *
73
+ * @overload
74
+ * @param {(files: File[] | null, event: DragEvent) => void} [callback] The callback function to be invoked on drop
75
+ * @returns {[StateRef<Target>, boolean, File[] | null]} The object with drop zone states and ref
76
+ *
77
+ * @example
78
+ * const { ref, overed, files } = useDropZone(() => console.log('callback'));
79
+ */
80
+ export declare const useDropZone: UseDropZone;
@@ -0,0 +1,47 @@
1
+ /** The use event source options type */
2
+ export interface UseEventSourceOptions<QueryData, Data> extends EventSourceInit {
3
+ /** Immediately open the connection when calling this hook */
4
+ immediately?: boolean;
5
+ placeholderData?: (() => Data) | Data;
6
+ retry?: boolean | number;
7
+ retryDelay?: ((retry: number, event: Event) => number) | number;
8
+ onError?: (error: Event) => void;
9
+ onMessage?: (event: Event & {
10
+ data?: Data;
11
+ }) => void;
12
+ onOpen?: () => void;
13
+ select?: (data: QueryData) => Data;
14
+ }
15
+ /** The use event source return type */
16
+ interface UseEventSourceReturn<Data = any> {
17
+ /** The latest data received via the EventSource */
18
+ data?: Data;
19
+ /** The current error */
20
+ error?: Event;
21
+ /** The instance of the EventSource */
22
+ instance?: EventSource;
23
+ isConnecting: boolean;
24
+ isError: boolean;
25
+ isOpen: boolean;
26
+ /** Closes the EventSource connection gracefully */
27
+ close: () => void;
28
+ /** Reopen the EventSource connection */
29
+ open: () => void;
30
+ }
31
+ /**
32
+ * @name useEventSource
33
+ * @description - Hook that provides a reactive wrapper for event source
34
+ * @category Browser
35
+ *
36
+ * @browserapi EventSource https://developer.mozilla.org/en-US/docs/Web/API/EventSource
37
+ *
38
+ * @param {string | URL} url The URL of the EventSource
39
+ * @param {string[]} [events=[]] List of events to listen to
40
+ * @param {UseEventSourceOptions} [options={}] Configuration options
41
+ * @returns {UseEventSourceReturn<Data>} The EventSource state and controls
42
+ *
43
+ * @example
44
+ * const { instance, data, isConnecting, isOpen, isError, close, open } = useEventSource('url', ['message']);
45
+ */
46
+ export declare const useEventSource: <QueryData = any, Data = QueryData>(url: string | URL, events?: string[], options?: UseEventSourceOptions<QueryData, Data>) => UseEventSourceReturn<Data>;
47
+ export {};
@@ -7,11 +7,18 @@ export interface UseHoverOptions {
7
7
  /** The on leave callback */
8
8
  onLeave?: (event: Event) => void;
9
9
  }
10
+ export interface UseHoverReturn {
11
+ value: boolean;
12
+ }
10
13
  export interface UseHover {
11
14
  (target: HookTarget, callback?: (event: Event) => void): boolean;
12
15
  (target: HookTarget, options?: UseHoverOptions): boolean;
13
- <Target extends Element>(callback?: (event: Event) => void, target?: never): [StateRef<Target>, boolean];
14
- <Target extends Element>(options?: UseHoverOptions, target?: never): [StateRef<Target>, boolean];
16
+ <Target extends Element>(callback?: (event: Event) => void, target?: never): {
17
+ ref: StateRef<Target>;
18
+ } & UseHoverReturn;
19
+ <Target extends Element>(options?: UseHoverOptions, target?: never): {
20
+ ref: StateRef<Target>;
21
+ } & UseHoverReturn;
15
22
  }
16
23
  /**
17
24
  * @name useHover
@@ -38,7 +45,7 @@ export interface UseHover {
38
45
  * @overload
39
46
  * @template Target The target element
40
47
  * @param {(event: Event) => void} [callback] The callback function to be invoked on mouse enter
41
- * @returns {UseHoverReturn<Target>} The state of the hover
48
+ * @returns {{ ref: StateRef<Target> } & UseHoverReturn} The state of the hover
42
49
  *
43
50
  * @example
44
51
  * const [ref, hovering] = useHover(() => console.log('callback'));
@@ -47,7 +54,7 @@ export interface UseHover {
47
54
  * @template Target The target element
48
55
  * @param {(event: Event) => void} [options.onEntry] The callback function to be invoked on mouse enter
49
56
  * @param {(event: Event) => void} [options.onLeave] The callback function to be invoked on mouse leave
50
- * @returns {UseHoverReturn<Target>} The state of the hover
57
+ * @returns {{ ref: StateRef<Target> } & UseHoverReturn} The state of the hover
51
58
  *
52
59
  * @example
53
60
  * const [ref, hovering] = useHover(options);
@@ -1,7 +1,6 @@
1
1
  import { DependencyList } from 'react';
2
2
  export interface UseQueryOptions<QueryData, Data> {
3
3
  enabled?: boolean;
4
- initialData?: (() => Data) | Data;
5
4
  keys?: DependencyList;
6
5
  placeholderData?: (() => Data) | Data;
7
6
  refetchInterval?: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",
@@ -81,11 +81,7 @@
81
81
  "vitest": "^3.1.2"
82
82
  },
83
83
  "lint-staged": {
84
- "*.js": [
85
- "eslint --fix",
86
- "prettier --write"
87
- ],
88
- "*.ts": [
84
+ "*.{js,ts,tsx}": [
89
85
  "eslint --fix",
90
86
  "prettier --write"
91
87
  ]