lkd-web-kit 0.0.0 → 0.0.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.
- package/README.md +6 -11
- package/dist/components.d.ts +116 -0
- package/dist/consts.d.ts +73 -0
- package/dist/contexts.d.ts +39 -0
- package/dist/{index.d.ts → form.d.ts} +6 -0
- package/dist/hocs.d.ts +34 -0
- package/dist/hooks.d.ts +11 -0
- package/dist/index.cjs +3 -33
- package/dist/index.js +1 -35
- package/dist/index2.cjs +2 -0
- package/dist/index2.js +1 -0
- package/dist/index3.cjs +80 -0
- package/dist/index3.js +75 -0
- package/dist/index4.cjs +78 -0
- package/dist/index4.js +70 -0
- package/dist/index5.cjs +74 -0
- package/dist/index5.js +69 -0
- package/dist/index6.cjs +29 -0
- package/dist/index6.js +24 -0
- package/dist/index7.cjs +58 -0
- package/dist/index7.js +51 -0
- package/dist/index8.cjs +83 -0
- package/dist/index8.js +74 -0
- package/dist/index9.cjs +3402 -0
- package/dist/index9.js +3395 -0
- package/dist/mantine.d.ts +16 -0
- package/dist/navigation-DnFkn_t2.cjs +2518 -0
- package/dist/navigation-sZaWnl2V.js +2513 -0
- package/dist/types.d.ts +33 -0
- package/dist/useFetchNextPageOnScroll-08q9N5OE.js +49 -0
- package/dist/useFetchNextPageOnScroll-Fqj7Vp-O.cjs +52 -0
- package/dist/utils.d.ts +29 -0
- package/dist/zodValidator-Bx6RMGoL.cjs +13 -0
- package/dist/zodValidator-ChEQ3cmF.js +11 -0
- package/package.json +91 -7
package/dist/types.d.ts
ADDED
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { Dispatch } from 'react';
|
|
2
|
+
import { SetStateAction } from 'react';
|
|
3
|
+
|
|
4
|
+
export declare interface ApiList<T = unknown> {
|
|
5
|
+
data: T[];
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
export declare interface ApiPagination<T> {
|
|
9
|
+
data: T[];
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export declare type DeepPartial<T> = {
|
|
13
|
+
[P in keyof T]?: DeepPartial<T[P]>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
export declare interface LayoutProps {
|
|
17
|
+
children: React.ReactNode;
|
|
18
|
+
params: Promise<PageParams>;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
declare interface PageParams extends Record<string, string | string[] | undefined> {
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export declare interface PageProps {
|
|
25
|
+
params: Promise<PageParams>;
|
|
26
|
+
searchParams: Promise<{
|
|
27
|
+
[key: string]: string | string[] | undefined;
|
|
28
|
+
}>;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
export declare type Setter<T> = Dispatch<SetStateAction<T>>;
|
|
32
|
+
|
|
33
|
+
export { }
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { useEffect } from 'react';
|
|
2
|
+
|
|
3
|
+
const useOnScrollProgress = (triggerPercentage, callback, elementRef) => {
|
|
4
|
+
if (triggerPercentage < 0 || triggerPercentage > 1) {
|
|
5
|
+
throw new Error("El porcentaje debe estar entre 0 y 1");
|
|
6
|
+
}
|
|
7
|
+
useEffect(() => {
|
|
8
|
+
let hasTriggered = false;
|
|
9
|
+
const handleScroll = () => {
|
|
10
|
+
const el = elementRef?.current;
|
|
11
|
+
const target = el ?? document.documentElement;
|
|
12
|
+
const scrollHeight = target.scrollHeight - target.clientHeight;
|
|
13
|
+
const scrollTop = el ? target.scrollTop : window.scrollY;
|
|
14
|
+
const scrollProgress = scrollHeight > 0 ? Math.min(1, scrollTop / scrollHeight) : 0;
|
|
15
|
+
if (!hasTriggered && scrollProgress >= triggerPercentage) {
|
|
16
|
+
callback();
|
|
17
|
+
hasTriggered = true;
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
const scrollTarget = elementRef?.current ?? window;
|
|
21
|
+
scrollTarget.addEventListener("scroll", handleScroll);
|
|
22
|
+
handleScroll();
|
|
23
|
+
return () => {
|
|
24
|
+
scrollTarget.removeEventListener("scroll", handleScroll);
|
|
25
|
+
};
|
|
26
|
+
}, [triggerPercentage, callback, elementRef]);
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
const useFetchNextPageOnScroll = (infinity, elementRef) => {
|
|
30
|
+
useOnScrollProgress(
|
|
31
|
+
0.9,
|
|
32
|
+
() => {
|
|
33
|
+
if (infinity.hasNextPage) {
|
|
34
|
+
infinity.fetchNextPage();
|
|
35
|
+
}
|
|
36
|
+
},
|
|
37
|
+
elementRef
|
|
38
|
+
);
|
|
39
|
+
useEffect(() => {
|
|
40
|
+
const el = elementRef?.current;
|
|
41
|
+
const scrollTarget = el ?? document.documentElement;
|
|
42
|
+
const hasScroll = scrollTarget.scrollHeight > scrollTarget.clientHeight;
|
|
43
|
+
if (!hasScroll && infinity.hasNextPage) {
|
|
44
|
+
infinity.fetchNextPage();
|
|
45
|
+
}
|
|
46
|
+
}, [infinity.data, elementRef]);
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
export { useOnScrollProgress as a, useFetchNextPageOnScroll as u };
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const require$$0 = require('react');
|
|
4
|
+
|
|
5
|
+
const useOnScrollProgress = (triggerPercentage, callback, elementRef) => {
|
|
6
|
+
if (triggerPercentage < 0 || triggerPercentage > 1) {
|
|
7
|
+
throw new Error("El porcentaje debe estar entre 0 y 1");
|
|
8
|
+
}
|
|
9
|
+
require$$0.useEffect(() => {
|
|
10
|
+
let hasTriggered = false;
|
|
11
|
+
const handleScroll = () => {
|
|
12
|
+
const el = elementRef?.current;
|
|
13
|
+
const target = el ?? document.documentElement;
|
|
14
|
+
const scrollHeight = target.scrollHeight - target.clientHeight;
|
|
15
|
+
const scrollTop = el ? target.scrollTop : window.scrollY;
|
|
16
|
+
const scrollProgress = scrollHeight > 0 ? Math.min(1, scrollTop / scrollHeight) : 0;
|
|
17
|
+
if (!hasTriggered && scrollProgress >= triggerPercentage) {
|
|
18
|
+
callback();
|
|
19
|
+
hasTriggered = true;
|
|
20
|
+
}
|
|
21
|
+
};
|
|
22
|
+
const scrollTarget = elementRef?.current ?? window;
|
|
23
|
+
scrollTarget.addEventListener("scroll", handleScroll);
|
|
24
|
+
handleScroll();
|
|
25
|
+
return () => {
|
|
26
|
+
scrollTarget.removeEventListener("scroll", handleScroll);
|
|
27
|
+
};
|
|
28
|
+
}, [triggerPercentage, callback, elementRef]);
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const useFetchNextPageOnScroll = (infinity, elementRef) => {
|
|
32
|
+
useOnScrollProgress(
|
|
33
|
+
0.9,
|
|
34
|
+
() => {
|
|
35
|
+
if (infinity.hasNextPage) {
|
|
36
|
+
infinity.fetchNextPage();
|
|
37
|
+
}
|
|
38
|
+
},
|
|
39
|
+
elementRef
|
|
40
|
+
);
|
|
41
|
+
require$$0.useEffect(() => {
|
|
42
|
+
const el = elementRef?.current;
|
|
43
|
+
const scrollTarget = el ?? document.documentElement;
|
|
44
|
+
const hasScroll = scrollTarget.scrollHeight > scrollTarget.clientHeight;
|
|
45
|
+
if (!hasScroll && infinity.hasNextPage) {
|
|
46
|
+
infinity.fetchNextPage();
|
|
47
|
+
}
|
|
48
|
+
}, [infinity.data, elementRef]);
|
|
49
|
+
};
|
|
50
|
+
|
|
51
|
+
exports.useFetchNextPageOnScroll = useFetchNextPageOnScroll;
|
|
52
|
+
exports.useOnScrollProgress = useOnScrollProgress;
|
package/dist/utils.d.ts
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { BeforeErrorHook } from 'ky';
|
|
2
|
+
import { HTTPError } from 'ky';
|
|
3
|
+
import { KyResponse } from 'ky';
|
|
4
|
+
|
|
5
|
+
export declare const addBodyJsonHook: BeforeErrorHook;
|
|
6
|
+
|
|
7
|
+
export declare function formatBytes(bytes: number, decimals?: number): string;
|
|
8
|
+
|
|
9
|
+
export declare const groupBy: <T extends any>(arr: T[], getKey: (item: T) => string | string[] | null) => Record<string, T[] | undefined>;
|
|
10
|
+
|
|
11
|
+
export declare type GroupByResult<T> = Record<string, T[] | undefined>;
|
|
12
|
+
|
|
13
|
+
export declare function indexBy<T, K, C extends string>(arr: T[], getKey: (item: T) => C | undefined): Record<C, T | undefined>;
|
|
14
|
+
|
|
15
|
+
export declare function indexBy<T, K, C extends string>(arr: T[], getKey: (item: T) => C | undefined, getValue: (item: T) => K): Record<C, K | undefined>;
|
|
16
|
+
|
|
17
|
+
export declare type IndexByResult<T> = Record<string, T | undefined>;
|
|
18
|
+
|
|
19
|
+
export declare type KyError<T = unknown> = HTTPError<T> & {
|
|
20
|
+
response: {
|
|
21
|
+
bodyJson?: T;
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
export declare const parseJSON: (response: KyResponse) => Promise<any>;
|
|
26
|
+
|
|
27
|
+
export declare const shuffleArray: <T>(array: T[]) => T[];
|
|
28
|
+
|
|
29
|
+
export { }
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
const zodValidator = (schema) => {
|
|
4
|
+
return (values) => {
|
|
5
|
+
const result = schema.safeParse(values);
|
|
6
|
+
if (result.success) return;
|
|
7
|
+
const { error } = result;
|
|
8
|
+
const firstError = error.issues[0];
|
|
9
|
+
return firstError?.message;
|
|
10
|
+
};
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
exports.zodValidator = zodValidator;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
const zodValidator = (schema) => {
|
|
2
|
+
return (values) => {
|
|
3
|
+
const result = schema.safeParse(values);
|
|
4
|
+
if (result.success) return;
|
|
5
|
+
const { error } = result;
|
|
6
|
+
const firstError = error.issues[0];
|
|
7
|
+
return firstError?.message;
|
|
8
|
+
};
|
|
9
|
+
};
|
|
10
|
+
|
|
11
|
+
export { zodValidator as z };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lkd-web-kit",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.1",
|
|
4
4
|
"description": "A template for creating React component libraries with Vite.",
|
|
5
5
|
"author": "LKD",
|
|
6
6
|
"license": "MIT",
|
|
@@ -15,14 +15,95 @@
|
|
|
15
15
|
"module": "./dist/index.js",
|
|
16
16
|
"types": "./dist/index.d.ts",
|
|
17
17
|
"exports": {
|
|
18
|
-
"
|
|
18
|
+
"./components": {
|
|
19
19
|
"import": {
|
|
20
|
-
"types": "./dist/index.d.ts",
|
|
21
|
-
"default": "./dist/index.js"
|
|
20
|
+
"types": "./dist/components/index.d.ts",
|
|
21
|
+
"default": "./dist/components/index.js"
|
|
22
22
|
},
|
|
23
23
|
"require": {
|
|
24
|
-
"types": "./dist/index.d.ts",
|
|
25
|
-
"default": "./dist/index.cjs"
|
|
24
|
+
"types": "./dist/components/index.d.ts",
|
|
25
|
+
"default": "./dist/components/index.cjs"
|
|
26
|
+
}
|
|
27
|
+
},
|
|
28
|
+
"./consts": {
|
|
29
|
+
"import": {
|
|
30
|
+
"types": "./dist/consts/index.d.ts",
|
|
31
|
+
"default": "./dist/consts/index.js"
|
|
32
|
+
},
|
|
33
|
+
"require": {
|
|
34
|
+
"types": "./dist/consts/index.d.ts",
|
|
35
|
+
"default": "./dist/consts/index.cjs"
|
|
36
|
+
}
|
|
37
|
+
},
|
|
38
|
+
"./contexts" :{
|
|
39
|
+
"import": {
|
|
40
|
+
"types": "./dist/contexts/index.d.ts",
|
|
41
|
+
"default": "./dist/contexts/index.js"
|
|
42
|
+
},
|
|
43
|
+
"require": {
|
|
44
|
+
"types": "./dist/contexts/index.d.ts",
|
|
45
|
+
"default": "./dist/contexts/index.cjs"
|
|
46
|
+
}
|
|
47
|
+
},
|
|
48
|
+
"./form": {
|
|
49
|
+
"import": {
|
|
50
|
+
"types": "./dist/form/index.d.ts",
|
|
51
|
+
"default": "./dist/form/index.js"
|
|
52
|
+
},
|
|
53
|
+
"require": {
|
|
54
|
+
"types": "./dist/form/index.d.ts",
|
|
55
|
+
"default": "./dist/form/index.cjs"
|
|
56
|
+
}
|
|
57
|
+
},
|
|
58
|
+
"./hocs": {
|
|
59
|
+
"import": {
|
|
60
|
+
"types": "./dist/hocs/index.d.ts",
|
|
61
|
+
"default": "./dist/hocs/index.js"
|
|
62
|
+
},
|
|
63
|
+
"require": {
|
|
64
|
+
"types": "./dist/hocs/index.d.ts",
|
|
65
|
+
"default": "./dist/hocs/index.cjs"
|
|
66
|
+
}
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
"./hooks": {
|
|
70
|
+
"import": {
|
|
71
|
+
"types": "./dist/hooks/index.d.ts",
|
|
72
|
+
"default": "./dist/hooks/index.js"
|
|
73
|
+
},
|
|
74
|
+
"require": {
|
|
75
|
+
"types": "./dist/hooks/index.d.ts",
|
|
76
|
+
"default": "./dist/hooks/index.cjs"
|
|
77
|
+
}
|
|
78
|
+
},
|
|
79
|
+
"./mantine":{
|
|
80
|
+
"import": {
|
|
81
|
+
"types": "./dist/mantine/index.d.ts",
|
|
82
|
+
"default": "./dist/mantine/index.js"
|
|
83
|
+
},
|
|
84
|
+
"require": {
|
|
85
|
+
"types": "./dist/mantine/index.d.ts",
|
|
86
|
+
"default": "./dist/mantine/index.cjs"
|
|
87
|
+
}
|
|
88
|
+
},
|
|
89
|
+
"./utils": {
|
|
90
|
+
"import": {
|
|
91
|
+
"types": "./dist/utils/index.d.ts",
|
|
92
|
+
"default": "./dist/utils/index.js"
|
|
93
|
+
},
|
|
94
|
+
"require": {
|
|
95
|
+
"types": "./dist/utils/index.d.ts",
|
|
96
|
+
"default": "./dist/utils/index.cjs"
|
|
97
|
+
}
|
|
98
|
+
},
|
|
99
|
+
"./types": {
|
|
100
|
+
"import": {
|
|
101
|
+
"types": "./dist/types/index.d.ts",
|
|
102
|
+
"default": "./dist/types/index.js"
|
|
103
|
+
},
|
|
104
|
+
"require": {
|
|
105
|
+
"types": "./dist/types/index.d.ts",
|
|
106
|
+
"default": "./dist/types/index.cjs"
|
|
26
107
|
}
|
|
27
108
|
}
|
|
28
109
|
},
|
|
@@ -61,10 +142,13 @@
|
|
|
61
142
|
"peerDependencies": {
|
|
62
143
|
"@mantine/core": "^7.17.4",
|
|
63
144
|
"@mantine/hooks": "^7.17.4",
|
|
64
|
-
"
|
|
145
|
+
"@tanstack/react-query": "^5.72.2",
|
|
146
|
+
"ky": "^1.8.0",
|
|
147
|
+
"next": "^15.3.0",
|
|
65
148
|
"react": "^19.1.0",
|
|
66
149
|
"react-dom": "^19.1.0",
|
|
67
150
|
"react-hook-form": "^7.55.0",
|
|
151
|
+
"react-query-kit": "^3.3.1",
|
|
68
152
|
"zod": "^3.24.2"
|
|
69
153
|
}
|
|
70
154
|
}
|