@jbpark/use-hooks 2.5.0 → 2.6.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.
@@ -3,6 +3,7 @@ import { useBodyScrollLock } from "./use-body-scroll-lock.mjs";
3
3
  import { useClickOutside } from "./use-click-outside.mjs";
4
4
  import { useElementPosition } from "./use-element-position.mjs";
5
5
  import { useElementScroll } from "./use-element-scroll.mjs";
6
+ import { useFileToDataUrl } from "./use-file-to-data-url.mjs";
6
7
  import { useHistoryState } from "./use-history-state.mjs";
7
8
  import { useIntersectionObserver } from "./use-intersection-observer.mjs";
8
9
  import { useResponsiveSize } from "./use-responsive-size.mjs";
@@ -3,6 +3,7 @@ import useBodyScrollLock from "./use-body-scroll-lock.mjs";
3
3
  import useClickOutside from "./use-click-outside.mjs";
4
4
  import useElementPosition from "./use-element-position.mjs";
5
5
  import useElementScroll from "./use-element-scroll.mjs";
6
+ import useFileToDataUrl from "./use-file-to-data-url.mjs";
6
7
  import useHistoryState from "./use-history-state.mjs";
7
8
  import useIntersectionObserver from "./use-intersection-observer.mjs";
8
9
  import useResponsiveSize from "./use-responsive-size.mjs";
@@ -0,0 +1,5 @@
1
+ //#region src/hooks/use-file-to-data-url.d.ts
2
+ declare const useFileToDataUrl: () => (file: File) => Promise<string>;
3
+ //#endregion
4
+ export { useFileToDataUrl };
5
+ //# sourceMappingURL=use-file-to-data-url.d.mts.map
@@ -0,0 +1,22 @@
1
+ import { useCallback } from "react";
2
+
3
+ //#region src/hooks/use-file-to-data-url.ts
4
+ const useFileToDataUrl = () => {
5
+ return useCallback((file) => {
6
+ return new Promise((resolve, reject) => {
7
+ const reader = new FileReader();
8
+ reader.onload = () => {
9
+ if (typeof reader.result === "string") resolve(reader.result);
10
+ else reject(/* @__PURE__ */ new Error("Failed to read file as a data URL."));
11
+ };
12
+ reader.onerror = () => {
13
+ reject(reader.error ?? /* @__PURE__ */ new Error("Failed to read file."));
14
+ };
15
+ reader.readAsDataURL(file);
16
+ });
17
+ }, []);
18
+ };
19
+
20
+ //#endregion
21
+ export { useFileToDataUrl as default };
22
+ //# sourceMappingURL=use-file-to-data-url.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-file-to-data-url.mjs","names":[],"sources":["../../src/hooks/use-file-to-data-url.ts"],"sourcesContent":["import { useCallback } from 'react';\n\nconst useFileToDataUrl = () => {\n const readAsDataUrl = useCallback((file: File): Promise<string> => {\n return new Promise((resolve, reject) => {\n const reader = new FileReader();\n\n reader.onload = () => {\n if (typeof reader.result === 'string') {\n resolve(reader.result);\n } else {\n reject(new Error('Failed to read file as a data URL.'));\n }\n };\n\n reader.onerror = () => {\n reject(reader.error ?? new Error('Failed to read file.'));\n };\n\n reader.readAsDataURL(file);\n });\n }, []);\n\n return readAsDataUrl;\n};\n\nexport default useFileToDataUrl;\n"],"mappings":";;;AAEA,MAAM,yBAAyB;AAqB7B,QApBsB,aAAa,SAAgC;AACjE,SAAO,IAAI,SAAS,SAAS,WAAW;GACtC,MAAM,SAAS,IAAI,YAAY;AAE/B,UAAO,eAAe;AACpB,QAAI,OAAO,OAAO,WAAW,SAC3B,SAAQ,OAAO,OAAO;QAEtB,wBAAO,IAAI,MAAM,qCAAqC,CAAC;;AAI3D,UAAO,gBAAgB;AACrB,WAAO,OAAO,yBAAS,IAAI,MAAM,uBAAuB,CAAC;;AAG3D,UAAO,cAAc,KAAK;IAC1B;IACD,EAAE,CAAC"}
package/dist/index.d.mts CHANGED
@@ -3,6 +3,7 @@ import { useBodyScrollLock } from "./hooks/use-body-scroll-lock.mjs";
3
3
  import { useClickOutside } from "./hooks/use-click-outside.mjs";
4
4
  import { useElementPosition } from "./hooks/use-element-position.mjs";
5
5
  import { useElementScroll } from "./hooks/use-element-scroll.mjs";
6
+ import { useFileToDataUrl } from "./hooks/use-file-to-data-url.mjs";
6
7
  import { useHistoryState } from "./hooks/use-history-state.mjs";
7
8
  import { useIntersectionObserver } from "./hooks/use-intersection-observer.mjs";
8
9
  import { useResponsiveSize } from "./hooks/use-responsive-size.mjs";
@@ -15,4 +16,4 @@ import { useTimeline } from "./hooks/use-timeline.mjs";
15
16
  import { useWindowScroll } from "./hooks/use-window-scroll.mjs";
16
17
  import { useViewport } from "./hooks/use-viewport.mjs";
17
18
  import "./hooks/index.mjs";
18
- export { useBodyScrollLock, useClickOutside, useDebounce, useElementPosition, useElementScroll, useHistoryState, useImage, useIntersectionObserver, useLocalStorage, useRecursiveTimeout, useResponsiveSize, useScrollToElements, useThrottle, useTimeline, useViewport, useWindowScroll };
19
+ export { useBodyScrollLock, useClickOutside, useDebounce, useElementPosition, useElementScroll, useFileToDataUrl, useHistoryState, useImage, useIntersectionObserver, useLocalStorage, useRecursiveTimeout, useResponsiveSize, useScrollToElements, useThrottle, useTimeline, useViewport, useWindowScroll };
package/dist/index.mjs CHANGED
@@ -3,6 +3,7 @@ import useBodyScrollLock from "./hooks/use-body-scroll-lock.mjs";
3
3
  import useClickOutside from "./hooks/use-click-outside.mjs";
4
4
  import useElementPosition from "./hooks/use-element-position.mjs";
5
5
  import useElementScroll from "./hooks/use-element-scroll.mjs";
6
+ import useFileToDataUrl from "./hooks/use-file-to-data-url.mjs";
6
7
  import useHistoryState from "./hooks/use-history-state.mjs";
7
8
  import useIntersectionObserver from "./hooks/use-intersection-observer.mjs";
8
9
  import useResponsiveSize from "./hooks/use-responsive-size.mjs";
@@ -16,4 +17,4 @@ import useWindowScroll from "./hooks/use-window-scroll.mjs";
16
17
  import useViewport from "./hooks/use-viewport.mjs";
17
18
  import "./hooks/index.mjs";
18
19
 
19
- export { useBodyScrollLock, useClickOutside, useDebounce, useElementPosition, useElementScroll, useHistoryState, useImage, useIntersectionObserver, useLocalStorage, useRecursiveTimeout, useResponsiveSize, useScrollToElements, useThrottle, useTimeline, useViewport, useWindowScroll };
20
+ export { useBodyScrollLock, useClickOutside, useDebounce, useElementPosition, useElementScroll, useFileToDataUrl, useHistoryState, useImage, useIntersectionObserver, useLocalStorage, useRecursiveTimeout, useResponsiveSize, useScrollToElements, useThrottle, useTimeline, useViewport, useWindowScroll };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jbpark/use-hooks",
3
- "version": "2.5.0",
3
+ "version": "2.6.0",
4
4
  "description": "A collection of reusable React 19 hooks for common UI and interaction patterns",
5
5
  "keywords": [
6
6
  "react",
@@ -54,7 +54,7 @@
54
54
  "devDependencies": {
55
55
  "@changesets/cli": "^2.31.1",
56
56
  "@eslint/js": "^9.33.0",
57
- "@jbpark/ui-kit": "^2.7.0",
57
+ "@jbpark/ui-kit": "^3.0.0",
58
58
  "@radix-ui/react-icons": "^1.3.2",
59
59
  "@trivago/prettier-plugin-sort-imports": "^5.2.2",
60
60
  "@types/node": "^24.5.2",