tawuniya 0.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.
@@ -0,0 +1,94 @@
1
+ import { Options } from 'nuqs';
2
+ import { useQueryState } from 'nuqs';
3
+
4
+ declare interface AlertState {
5
+ visible: boolean;
6
+ message: string;
7
+ type: AlertType;
8
+ }
9
+
10
+ declare type AlertType = "default" | "destructive" | "info" | "primary" | "success" | "warning";
11
+
12
+ declare interface FileData {
13
+ id: string;
14
+ file: string;
15
+ fileName: string;
16
+ fileType: string;
17
+ size: number;
18
+ }
19
+
20
+ declare type Language = "ar" | "en";
21
+
22
+ declare interface MainContextType {
23
+ openSidebar: boolean;
24
+ sidebarCollapsed: boolean;
25
+ settings: AccessibilityDefaultSettings;
26
+ onSidebarOpenChange: (open: boolean) => void;
27
+ onSidebarCollapsedChange: (collapsed: boolean) => void;
28
+ toggle: (key: AccessibilityDefaultSettingsType) => void;
29
+ cycleTextAlign: () => void;
30
+ cycleBigText: () => void;
31
+ reset: () => void;
32
+ }
33
+
34
+ declare interface ShowAlert {
35
+ message: string;
36
+ type?: AlertType;
37
+ duration?: number;
38
+ }
39
+
40
+ export declare const useClickOutside: <T extends HTMLElement>(ref: React.RefObject<T>, callback: () => void) => void;
41
+
42
+ export declare const useDebounce: (value: string, delay: number) => string;
43
+
44
+ export declare const useFileUpload: (maxSize: number, maxFiles: number) => {
45
+ selectedFiles: FileData[];
46
+ internalError: string | undefined;
47
+ maxSizeInBytes: number;
48
+ onFileChange: (e: React.ChangeEvent<HTMLInputElement>, onChange: (files: FileData[]) => void) => Promise<void>;
49
+ removeFile: (fileId: string, onChange: (files: FileData[]) => void) => void;
50
+ formatBytes: (bytes: number, decimals?: number) => string;
51
+ formatFileSize: (size: number) => string;
52
+ getPreviewImage: (file: FileData) => string;
53
+ };
54
+
55
+ declare type UseFormErrorScrollerParams<T> = {
56
+ fields: (keyof T)[];
57
+ errors: Partial<Record<keyof T, any>>;
58
+ setFocus?: (field: keyof T) => void;
59
+ };
60
+
61
+ export declare const useLanguage: () => Language;
62
+
63
+ export declare const useMainContext: () => MainContextType;
64
+
65
+ export declare function useMediaQuery(query: string): boolean;
66
+
67
+ export declare const useMessage: (initialDuration?: number) => {
68
+ alert: AlertState;
69
+ showAlert: ({ message, type, duration }: ShowAlert) => void;
70
+ hideAlert: () => void;
71
+ };
72
+
73
+ export declare const useMobile: (breakpoint?: number) => boolean;
74
+
75
+ export declare function useMounted(): boolean;
76
+
77
+ export declare const usePaginationQuery: (paginationTotal?: number) => {
78
+ page: number;
79
+ pageSize: number;
80
+ totalPages: number;
81
+ isMobile: boolean;
82
+ setPage: (value: number | ((old: number) => number | null) | null, options?: Options) => Promise<URLSearchParams>;
83
+ setPageSize: (value: number | ((old: number) => number | null) | null, options?: Options) => Promise<URLSearchParams>;
84
+ resetPagination: () => void;
85
+ generatePageNumbers: () => (string | number)[];
86
+ };
87
+
88
+ export { useQueryState }
89
+
90
+ export declare function useScrollTo<T>({ fields, errors, setFocus, }: UseFormErrorScrollerParams<T>): {
91
+ registerRef: <K extends keyof T>(field: K) => (el: HTMLElement | null) => void;
92
+ };
93
+
94
+ export { }
@@ -0,0 +1,116 @@
1
+ import { c as L, u as V, f as k, e as P, d as x, p as A } from "./use-main-context-BwmCW_Ze.js";
2
+ import * as T from "react";
3
+ import { useCallback as h, useEffect as m, useState as g, useRef as f } from "react";
4
+ const S = (e, r) => {
5
+ const n = h(
6
+ (t) => {
7
+ e.current && !e.current.contains(t.target) && r();
8
+ },
9
+ [e, r]
10
+ );
11
+ m(() => (document.addEventListener("mousedown", n), () => {
12
+ document.removeEventListener("mousedown", n);
13
+ }), []);
14
+ }, C = (e, r) => {
15
+ const [n, t] = g(e);
16
+ return m(() => {
17
+ const s = setTimeout(() => t(e), r);
18
+ return () => {
19
+ clearTimeout(s);
20
+ };
21
+ }, [e, r]), n;
22
+ };
23
+ function O(e) {
24
+ const [r, n] = T.useState(!1);
25
+ return T.useEffect(() => {
26
+ function t(o) {
27
+ n(o.matches);
28
+ }
29
+ const s = matchMedia(e);
30
+ return s.addEventListener("change", t), n(s.matches), () => s.removeEventListener("change", t);
31
+ }, [e]), r;
32
+ }
33
+ function D() {
34
+ const [e, r] = g(!1);
35
+ return m(() => {
36
+ r(!0);
37
+ }, []), e;
38
+ }
39
+ function N({
40
+ fields: e,
41
+ errors: r,
42
+ setFocus: n
43
+ }) {
44
+ const t = f(
45
+ {}
46
+ ), s = f(!1), o = f([]), a = (c) => (i) => {
47
+ i && (t.current[c] = i);
48
+ };
49
+ return m(() => {
50
+ const c = Object.keys(r).filter((u) => !!r[u]).map((u) => u);
51
+ if (c.length === 0) {
52
+ s.current = !1, o.current = [];
53
+ return;
54
+ }
55
+ const i = c.length === o.current.length && c.every((u, d) => u === o.current[d]);
56
+ if (o.current = c, !i) {
57
+ s.current = !0;
58
+ return;
59
+ }
60
+ if (!s.current) return;
61
+ const l = e.filter(
62
+ (u) => r[u] && t.current[u]
63
+ );
64
+ if (l.length === 0) return;
65
+ const b = l.sort((u, d) => {
66
+ const v = t.current[u], p = t.current[d];
67
+ return v === p ? 0 : v.compareDocumentPosition(p) & Node.DOCUMENT_POSITION_PRECEDING ? 1 : -1;
68
+ })[0], E = t.current[b];
69
+ E?.scrollIntoView ? E.scrollIntoView({ behavior: "smooth", block: "nearest" }) : n?.(b);
70
+ }, [r, e, n]), { registerRef: a };
71
+ }
72
+ const R = (e = 3e3) => {
73
+ const [r, n] = g({
74
+ visible: !1,
75
+ message: "",
76
+ type: "default"
77
+ }), t = f(null), s = h(
78
+ ({ message: a, type: c = "default", duration: i = e }) => {
79
+ t.current && clearTimeout(t.current), n({
80
+ visible: !0,
81
+ message: a,
82
+ type: c
83
+ }), t.current = setTimeout(() => {
84
+ n((l) => ({
85
+ ...l,
86
+ visible: !1
87
+ }));
88
+ }, i);
89
+ },
90
+ [e]
91
+ ), o = h(() => {
92
+ t.current && clearTimeout(t.current), n((a) => ({
93
+ ...a,
94
+ visible: !1
95
+ }));
96
+ }, []);
97
+ return {
98
+ alert: r,
99
+ showAlert: s,
100
+ hideAlert: o
101
+ };
102
+ };
103
+ export {
104
+ S as useClickOutside,
105
+ C as useDebounce,
106
+ L as useFileUpload,
107
+ V as useLanguage,
108
+ k as useMainContext,
109
+ O as useMediaQuery,
110
+ R as useMessage,
111
+ P as useMobile,
112
+ D as useMounted,
113
+ x as usePaginationQuery,
114
+ A as useQueryState,
115
+ N as useScrollTo
116
+ };