lkd-web-kit 0.3.20 → 0.4.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.
package/dist/index.cjs CHANGED
@@ -52,8 +52,9 @@ const addBodyJsonHook = require('./utils/ky/addBodyJsonHook.cjs');
52
52
  const parseJson = require('./utils/ky/parseJson.cjs');
53
53
  const groupBy = require('./utils/array/groupBy.cjs');
54
54
  const shuffleArray = require('./utils/array/shuffleArray.cjs');
55
- const newHref = require('./utils/newHref.cjs');
56
55
  const isInfinityEmpty = require('./utils/isInfinityEmpty.cjs');
56
+ const queryStringify = require('./utils/query-stringify.cjs');
57
+ const newRoute = require('./utils/new-route.cjs');
57
58
 
58
59
 
59
60
 
@@ -113,5 +114,7 @@ exports.parseJSON = parseJson.parseJSON;
113
114
  exports.groupBy = groupBy.groupBy;
114
115
  exports.indexBy = groupBy.indexBy;
115
116
  exports.shuffleArray = shuffleArray.shuffleArray;
116
- exports.newHref = newHref.newHref;
117
117
  exports.isInfinityEmpty = isInfinityEmpty.isInfinityEmpty;
118
+ exports.queryStringify = queryStringify.queryStringify;
119
+ exports.createNewRoute = newRoute.createNewRoute;
120
+ exports.newRoute = newRoute.newRoute;
package/dist/index.d.ts CHANGED
@@ -56,13 +56,6 @@ export declare interface ApiPagination<T> {
56
56
  data: T[];
57
57
  }
58
58
 
59
- export declare type Args<T, S> = {
60
- params?: T;
61
- searchParams?: S & {
62
- [QP_BACK_URL_NAME]?: string;
63
- };
64
- };
65
-
66
59
  export declare const breakpointsWithPx: {
67
60
  xs: string;
68
61
  sm: string;
@@ -72,6 +65,14 @@ export declare const breakpointsWithPx: {
72
65
  "2xl": string;
73
66
  };
74
67
 
68
+ export declare function createNewRoute<GlobalQuery extends object = {}>(config?: {
69
+ queryBuilder?: (query: GlobalQuery) => string;
70
+ }): {
71
+ <LocalQuery extends object = {}, Path extends string = string>(path: Path, options?: RouteOptions<LocalQuery, ExtractPathParams<Path>>): (params?: RouteInput<ExtractPathParams<Path>, GlobalQuery & LocalQuery>) => string;
72
+ <LocalQuery extends object = {}, PathParams extends Params = {}>(path: string, options?: RouteOptions<LocalQuery, PathParams>): (params?: RouteInput<PathParams, GlobalQuery & LocalQuery>) => string;
73
+ <LocalQuery extends object = {}, PathParams extends Params = {}>(pathBuilder: (params: PathParams) => string, options?: RouteOptions<LocalQuery, PathParams>): (params?: RouteInput<PathParams, GlobalQuery & LocalQuery>) => string;
74
+ };
75
+
75
76
  export declare type DeepPartial<T> = {
76
77
  [P in keyof T]?: DeepPartial<T[P]>;
77
78
  };
@@ -85,6 +86,12 @@ export declare interface EmptyProps extends ComponentProps<'div'> {
85
86
 
86
87
  export declare const EmptyState: ({ label, action, icon, className, size, ...props }: EmptyProps) => JSX.Element;
87
88
 
89
+ declare type ExtractPathParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
90
+ [K in Param | keyof ExtractPathParams<`/${Rest}`>]: string | number;
91
+ } : T extends `${string}:${infer Param}` ? {
92
+ [K in Param]: string | number;
93
+ } : {};
94
+
88
95
  export declare type FetchNextPageOnScrollOptions = {
89
96
  infinity: InfiniteQueryHookResult<InfiniteData<{
90
97
  data: unknown[];
@@ -371,7 +378,11 @@ export declare interface NavItemsProps {
371
378
  activeStrategy?: 'equals' | 'includes';
372
379
  }
373
380
 
374
- export declare const newHref: <T extends TParams, S extends TSearchParams = TSearchParams>(fn: string | ((args: Args<T, S>) => string)) => (args?: Args<T, S>) => string;
381
+ export declare const newRoute: {
382
+ <LocalQuery extends object = {}, Path extends string = string>(path: Path, options?: RouteOptions<LocalQuery, ExtractPathParams<Path>> | undefined): (params?: RouteInput<ExtractPathParams<Path>, LocalQuery> | undefined) => string;
383
+ <LocalQuery extends object = {}, PathParams extends Params = {}>(path: string, options?: RouteOptions<LocalQuery, PathParams> | undefined): (params?: RouteInput<PathParams, LocalQuery> | undefined) => string;
384
+ <LocalQuery extends object = {}, PathParams extends Params = {}>(pathBuilder: (params: PathParams) => string, options?: RouteOptions<LocalQuery, PathParams> | undefined): (params?: RouteInput<PathParams, LocalQuery> | undefined) => string;
385
+ };
375
386
 
376
387
  export declare const nullableButRequired: <T extends ZodTypeAny>(schema: T, message?: string) => z.ZodEffects<z.ZodNullable<T>, T["_output"] | null, T["_input"] | null>;
377
388
 
@@ -403,8 +414,12 @@ export declare interface PageProps {
403
414
  }>;
404
415
  }
405
416
 
417
+ declare type Params = Record<string, Primitive>;
418
+
406
419
  export declare const parseJSON: (response: KyResponse) => Promise<any>;
407
420
 
421
+ declare type Primitive = string | number | boolean | undefined;
422
+
408
423
  declare const pxBySize: {
409
424
  sm: number;
410
425
  md: number;
@@ -413,6 +428,8 @@ declare const pxBySize: {
413
428
 
414
429
  export declare const QP_BACK_URL_NAME = "backUrl";
415
430
 
431
+ export declare const queryStringify: (query?: Record<string, unknown>) => string;
432
+
416
433
  export declare enum Revalidate {
417
434
  OneHour = 3600,
418
435
  OneDay = 86400,
@@ -421,6 +438,15 @@ export declare enum Revalidate {
421
438
  OneYear = 31536000
422
439
  }
423
440
 
441
+ declare type RouteInput<PathParams extends Params, Query> = PathParams & {
442
+ query?: Query;
443
+ };
444
+
445
+ declare type RouteOptions<Query, PathParams> = {
446
+ queryBuilder?: (query: Query) => string;
447
+ pathBuilder?: (params: PathParams) => string;
448
+ };
449
+
424
450
  export declare function SelectInfinity({ value, onChange, data, searchValue, onSearchChange, renderOption, onOptionSubmit, nothingFoundMessage, infinity, placeholder, ...props }: SelectInfinityProps): JSX.Element;
425
451
 
426
452
  export declare interface SelectInfinityProps extends InputBaseProps, ElementProps<'button', keyof InputBaseProps | 'value' | 'onChange'> {
@@ -475,12 +501,6 @@ export declare const timeInputToNumber: (timeInput: string) => number;
475
501
 
476
502
  export declare const toTailwindColors: (colors: MantineThemeColors) => Record<DefaultMantineColor, Record<MantineColorShade, string>>;
477
503
 
478
- export declare type TParams = Record<string, any> | unknown;
479
-
480
- export declare type TSearchParams = {
481
- [x: string]: any;
482
- };
483
-
484
504
  export declare const useBreakpoint: (breakpoint: keyof typeof breakpointsWithPx) => boolean;
485
505
 
486
506
  export declare const useFetchNextPageOnScroll: ({ infinity, scrollRef, disabled, }: FetchNextPageOnScrollOptions) => void;
package/dist/index.js CHANGED
@@ -48,5 +48,6 @@ export { addBodyJsonHook } from './utils/ky/addBodyJsonHook.js';
48
48
  export { parseJSON } from './utils/ky/parseJson.js';
49
49
  export { groupBy, indexBy } from './utils/array/groupBy.js';
50
50
  export { shuffleArray } from './utils/array/shuffleArray.js';
51
- export { newHref } from './utils/newHref.js';
52
51
  export { isInfinityEmpty } from './utils/isInfinityEmpty.js';
52
+ export { queryStringify } from './utils/query-stringify.js';
53
+ export { createNewRoute, newRoute } from './utils/new-route.js';
@@ -0,0 +1,45 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const queryStringify = require('./query-stringify.cjs');
6
+
7
+ function buildPathFromTemplate(path, params) {
8
+ return path.replace(/:([a-zA-Z0-9_]+)/g, (_, key) => {
9
+ const value = params[key];
10
+ if (value === void 0) {
11
+ throw new Error(`Falta el parámetro de ruta: ${key}`);
12
+ }
13
+ return encodeURIComponent(String(value));
14
+ });
15
+ }
16
+ function createNewRoute(config) {
17
+ const globalQueryBuilder = config?.queryBuilder;
18
+ function getPathStrategy(arg, options) {
19
+ if (options?.pathBuilder) {
20
+ return (params) => options.pathBuilder(params);
21
+ } else if (typeof arg === "string") {
22
+ const template = arg;
23
+ return (params) => buildPathFromTemplate(template, params);
24
+ } else {
25
+ const fn = arg;
26
+ return (params) => fn(params);
27
+ }
28
+ }
29
+ function newRoute2(arg, options) {
30
+ const pathStrategy = getPathStrategy(arg, options);
31
+ const queryBuilder = options?.queryBuilder || globalQueryBuilder;
32
+ const queryStrategy = queryBuilder ? (query) => queryBuilder(query) : queryStringify.queryStringify;
33
+ return (params = {}) => {
34
+ const { query = {}, ...pathParams } = params;
35
+ const path = pathStrategy(pathParams);
36
+ const queryString = queryStrategy(query);
37
+ return path + queryString;
38
+ };
39
+ }
40
+ return newRoute2;
41
+ }
42
+ const newRoute = createNewRoute();
43
+
44
+ exports.createNewRoute = createNewRoute;
45
+ exports.newRoute = newRoute;
@@ -0,0 +1,40 @@
1
+ import { queryStringify } from './query-stringify.js';
2
+
3
+ function buildPathFromTemplate(path, params) {
4
+ return path.replace(/:([a-zA-Z0-9_]+)/g, (_, key) => {
5
+ const value = params[key];
6
+ if (value === void 0) {
7
+ throw new Error(`Falta el parámetro de ruta: ${key}`);
8
+ }
9
+ return encodeURIComponent(String(value));
10
+ });
11
+ }
12
+ function createNewRoute(config) {
13
+ const globalQueryBuilder = config?.queryBuilder;
14
+ function getPathStrategy(arg, options) {
15
+ if (options?.pathBuilder) {
16
+ return (params) => options.pathBuilder(params);
17
+ } else if (typeof arg === "string") {
18
+ const template = arg;
19
+ return (params) => buildPathFromTemplate(template, params);
20
+ } else {
21
+ const fn = arg;
22
+ return (params) => fn(params);
23
+ }
24
+ }
25
+ function newRoute2(arg, options) {
26
+ const pathStrategy = getPathStrategy(arg, options);
27
+ const queryBuilder = options?.queryBuilder || globalQueryBuilder;
28
+ const queryStrategy = queryBuilder ? (query) => queryBuilder(query) : queryStringify;
29
+ return (params = {}) => {
30
+ const { query = {}, ...pathParams } = params;
31
+ const path = pathStrategy(pathParams);
32
+ const queryString = queryStrategy(query);
33
+ return path + queryString;
34
+ };
35
+ }
36
+ return newRoute2;
37
+ }
38
+ const newRoute = createNewRoute();
39
+
40
+ export { createNewRoute, newRoute };
@@ -0,0 +1,10 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const queryStringify = (query = {}) => {
6
+ const entries = Object.entries(query).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => [key, String(value)]);
7
+ return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
8
+ };
9
+
10
+ exports.queryStringify = queryStringify;
@@ -0,0 +1,6 @@
1
+ const queryStringify = (query = {}) => {
2
+ const entries = Object.entries(query).filter(([, value]) => value !== void 0 && value !== null).map(([key, value]) => [key, String(value)]);
3
+ return entries.length ? `?${new URLSearchParams(entries).toString()}` : "";
4
+ };
5
+
6
+ export { queryStringify };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "lkd-web-kit",
3
- "version": "0.3.20",
3
+ "version": "0.4.0",
4
4
  "description": "A template for creating React component libraries with Vite.",
5
5
  "author": "LKD",
6
6
  "license": "MIT",
@@ -31,38 +31,36 @@
31
31
  "@testing-library/jest-dom": "^6.6.3",
32
32
  "@testing-library/react": "^16.3.0",
33
33
  "@testing-library/user-event": "^14.6.1",
34
- "@types/node": "^22.15.21",
35
- "@types/qs": "^6.14.0",
36
- "@types/react": "^19.1.5",
37
- "@types/react-dom": "^19.1.5",
38
- "@typescript-eslint/eslint-plugin": "^8.32.1",
39
- "@typescript-eslint/parser": "^8.32.1",
40
- "@vitejs/plugin-react-swc": "^3.9.0",
41
- "@vitest/coverage-v8": "^3.1.4",
42
- "eslint": "^9.27.0",
34
+ "@types/node": "^22.15.33",
35
+ "@types/react": "^19.1.8",
36
+ "@types/react-dom": "^19.1.6",
37
+ "@typescript-eslint/eslint-plugin": "^8.35.0",
38
+ "@typescript-eslint/parser": "^8.35.0",
39
+ "@vitejs/plugin-react-swc": "^3.10.2",
40
+ "@vitest/coverage-v8": "^3.2.4",
41
+ "eslint": "^9.29.0",
43
42
  "eslint-config-prettier": "^10.1.5",
44
43
  "eslint-plugin-jest-dom": "^5.5.0",
45
44
  "eslint-plugin-react": "^7.37.5",
46
45
  "eslint-plugin-react-hooks": "^5.2.0",
47
46
  "eslint-plugin-react-refresh": "^0.4.20",
48
47
  "jsdom": "^26.1.0",
49
- "prettier": "^3.5.3",
48
+ "prettier": "^3.6.1",
50
49
  "rollup-preserve-directives": "^1.1.3",
51
50
  "typescript": "^5.8.3",
52
- "vite": "^6.3.5",
51
+ "vite": "^7.0.0",
53
52
  "vite-plugin-dts": "^4.5.4",
54
- "vitest": "^3.1.4"
53
+ "vitest": "^3.2.4"
55
54
  },
56
55
  "peerDependencies": {
57
- "@mantine/core": "^8.1.1",
58
- "@mantine/dates": "^8.1.1",
59
- "@mantine/hooks": "^8.1.1",
60
- "@mantine/notifications": "^8.1.1",
61
- "@tanstack/react-query": "^5.80.7",
56
+ "@mantine/core": "^8.1.2",
57
+ "@mantine/dates": "^8.1.2",
58
+ "@mantine/hooks": "^8.1.2",
59
+ "@mantine/notifications": "^8.1.2",
60
+ "@tanstack/react-query": "^5.81.2",
62
61
  "clsx": "^2.1.1",
63
62
  "ky": "^1.8.1",
64
- "next": "^15.3.3",
65
- "qs": "^6.14.0",
63
+ "next": "^15.3.4",
66
64
  "react": "^19.1.0",
67
65
  "react-dom": "^19.1.0",
68
66
  "react-hook-form": "^7.58.1",
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const qs = require('qs');
6
-
7
- const newHref = (fn) => (args) => {
8
- const href = typeof fn === "string" ? fn : fn(
9
- args ?? {
10
- params: {},
11
- searchParams: {}
12
- }
13
- );
14
- if (args?.searchParams) {
15
- const stringify = qs.stringify(args.searchParams, {
16
- skipNulls: true
17
- });
18
- return `${href}${stringify ? `?${stringify}` : ""}`;
19
- }
20
- return href;
21
- };
22
-
23
- exports.newHref = newHref;
@@ -1,19 +0,0 @@
1
- import qs from 'qs';
2
-
3
- const newHref = (fn) => (args) => {
4
- const href = typeof fn === "string" ? fn : fn(
5
- args ?? {
6
- params: {},
7
- searchParams: {}
8
- }
9
- );
10
- if (args?.searchParams) {
11
- const stringify = qs.stringify(args.searchParams, {
12
- skipNulls: true
13
- });
14
- return `${href}${stringify ? `?${stringify}` : ""}`;
15
- }
16
- return href;
17
- };
18
-
19
- export { newHref };