@siberiacancode/reactuse 0.2.14 → 0.2.16

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 +1 @@
1
- {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"index.mjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -0,0 +1,18 @@
1
+ /**
2
+ * @name createEventEmitter
3
+ * @description - Creates a type-safe event emitter
4
+ * @category Helpers
5
+ *
6
+ * @template Events - The type of events and their data
7
+ * @returns {Events} - Object containing event emitter methods and hook
8
+ *
9
+ * @example
10
+ * const { instance, push, subscribe, unsubscribe, useSubscribe } = createEventEmitter<{ foo: number }>();
11
+ */
12
+ export declare const createEventEmitter: <Events extends Record<string, any> = Record<string, any>>() => {
13
+ instance: EventTarget;
14
+ push: <Event extends keyof Events>(event: Event, data: Events[Event]) => boolean;
15
+ subscribe: <Key extends keyof Events>(event: Key, listener: (data: Events[Key]) => void) => () => void;
16
+ unsubscribe: <Key extends keyof Events>(event: Key, listener: (data: Events[Key]) => void) => void;
17
+ useSubscribe: <Event extends keyof Events>(event: Event, listener?: (data: Events[Event]) => void) => Events[Event] | undefined;
18
+ };
@@ -12,7 +12,6 @@ export interface StoreApi<Value> {
12
12
  * @category Helpers
13
13
  *
14
14
  * @template Value - The type of the store state
15
- *
16
15
  * @param {StateCreator<Value>} createState - Function that initializes the store state
17
16
  * @returns {StoreApi<Value>} - Object containing store methods and hook for accessing state
18
17
  *
@@ -1,3 +1,4 @@
1
1
  export * from './createContext/createContext';
2
+ export * from './createEventEmitter/createEventEmitter';
2
3
  export * from './createReactiveContext/createReactiveContext';
3
4
  export * from './createStore/createStore';
@@ -16,6 +16,10 @@ export interface UseIntersectionObserver {
16
16
  ref: StateRef<Target>;
17
17
  };
18
18
  (target: HookTarget, options?: UseIntersectionObserverOptions): UseIntersectionObserverReturn;
19
+ <Target extends Element>(callback: (entry: IntersectionObserverEntry) => void, target?: never): UseIntersectionObserverReturn & {
20
+ ref: StateRef<Target>;
21
+ };
22
+ (callback: (entry: IntersectionObserverEntry) => void, target: HookTarget): UseIntersectionObserverReturn;
19
23
  }
20
24
  /**
21
25
  * @name useIntersectionObserver
@@ -28,7 +32,7 @@ export interface UseIntersectionObserver {
28
32
  * @param {HookTarget} target The target element to detect intersection
29
33
  * @param {boolean} [options.enabled=true] The IntersectionObserver options
30
34
  * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected
31
- * @param {HookTarget} [options.root] The root element to observe
35
+ * @param {HookTarget} [options.root=document] The root element to observe
32
36
  * @returns {UseIntersectionObserverReturn} An object containing the state
33
37
  *
34
38
  * @example
@@ -38,10 +42,26 @@ export interface UseIntersectionObserver {
38
42
  * @template Target The target element
39
43
  * @param {boolean} [options.enabled=true] The IntersectionObserver options
40
44
  * @param {((entries: IntersectionObserverEntry[], observer: IntersectionObserver) => void) | undefined} [options.onChange] The callback to execute when intersection is detected
41
- * @param {HookTarget} [options.root] The root element to observe
45
+ * @param {HookTarget} [options.root=document] The root element to observe
42
46
  * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element
43
47
  *
44
48
  * @example
45
49
  * const { entry, inView } = useIntersectionObserver(ref);
50
+ *
51
+ * @overload
52
+ * @template Target The target element
53
+ * @param {(entry: IntersectionObserverEntry) => void} callback The callback to execute when intersection is detected
54
+ * @returns {UseIntersectionObserverReturn & { ref: StateRef<Target> }} A React ref to attach to the target element
55
+ *
56
+ * @example
57
+ * const { ref, entry, inView } = useIntersectionObserver(() => console.log('callback'));
58
+ *
59
+ * @overload
60
+ * @param {(entry: IntersectionObserverEntry) => void} callback The callback to execute when intersection is detected
61
+ * @param {HookTarget} target The target element to detect intersection
62
+ * @returns {UseIntersectionObserverReturn} An object containing the state
63
+ *
64
+ * @example
65
+ * const { entry, inView } = useIntersectionObserver(() => console.log('callback'), ref);
46
66
  */
47
67
  export declare const useIntersectionObserver: UseIntersectionObserver;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@siberiacancode/reactuse",
3
- "version": "0.2.14",
3
+ "version": "0.2.16",
4
4
  "description": "The ultimate collection of react hooks",
5
5
  "author": {
6
6
  "name": "SIBERIA CAN CODE 🧊",
@@ -51,9 +51,9 @@
51
51
  "lint-staged": "lint-staged"
52
52
  },
53
53
  "peerDependencies": {
54
- "@types/react": "^17 || ^18 || ^19",
55
- "react": "^17 || ^18 || ^19",
56
- "react-dom": "^17 || ^18 || ^19"
54
+ "@types/react": "^18 || ^19",
55
+ "react": "^18 || ^19",
56
+ "react-dom": "^18 || ^19"
57
57
  },
58
58
  "peerDependenciesMeta": {
59
59
  "@types/react": {
@@ -76,7 +76,7 @@
76
76
  "react": "^19.1.0",
77
77
  "react-dom": "^19.1.0",
78
78
  "shx": "^0.4.0",
79
- "vite": "^7.0.0",
79
+ "vite": "^7.0.2",
80
80
  "vite-plugin-dts": "^4.5.4",
81
81
  "vitest": "^3.2.4"
82
82
  },