lkd-web-kit 0.3.20 → 0.3.21
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 +5 -0
- package/dist/index.d.ts +35 -0
- package/dist/index.js +2 -0
- package/dist/utils/new-route.cjs +45 -0
- package/dist/utils/new-route.js +40 -0
- package/dist/utils/query-stringify.cjs +10 -0
- package/dist/utils/query-stringify.js +6 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -54,6 +54,8 @@ const groupBy = require('./utils/array/groupBy.cjs');
|
|
|
54
54
|
const shuffleArray = require('./utils/array/shuffleArray.cjs');
|
|
55
55
|
const newHref = require('./utils/newHref.cjs');
|
|
56
56
|
const isInfinityEmpty = require('./utils/isInfinityEmpty.cjs');
|
|
57
|
+
const queryStringify = require('./utils/query-stringify.cjs');
|
|
58
|
+
const newRoute = require('./utils/new-route.cjs');
|
|
57
59
|
|
|
58
60
|
|
|
59
61
|
|
|
@@ -115,3 +117,6 @@ exports.indexBy = groupBy.indexBy;
|
|
|
115
117
|
exports.shuffleArray = shuffleArray.shuffleArray;
|
|
116
118
|
exports.newHref = newHref.newHref;
|
|
117
119
|
exports.isInfinityEmpty = isInfinityEmpty.isInfinityEmpty;
|
|
120
|
+
exports.queryStringify = queryStringify.queryStringify;
|
|
121
|
+
exports.createNewRoute = newRoute.createNewRoute;
|
|
122
|
+
exports.newRoute = newRoute.newRoute;
|
package/dist/index.d.ts
CHANGED
|
@@ -72,6 +72,14 @@ export declare const breakpointsWithPx: {
|
|
|
72
72
|
"2xl": string;
|
|
73
73
|
};
|
|
74
74
|
|
|
75
|
+
export declare function createNewRoute<GlobalQuery extends object = {}>(config?: {
|
|
76
|
+
queryBuilder?: (query: GlobalQuery) => string;
|
|
77
|
+
}): {
|
|
78
|
+
<LocalQuery extends object = {}, Path extends string = string>(path: Path, options?: RouteOptions<LocalQuery, ExtractPathParams<Path>>): (params?: RouteInput<ExtractPathParams<Path>, GlobalQuery & LocalQuery>) => string;
|
|
79
|
+
<LocalQuery extends object = {}, PathParams extends Params = {}>(path: string, options?: RouteOptions<LocalQuery, PathParams>): (params?: RouteInput<PathParams, GlobalQuery & LocalQuery>) => string;
|
|
80
|
+
<LocalQuery extends object = {}, PathParams extends Params = {}>(pathBuilder: (params: PathParams) => string, options?: RouteOptions<LocalQuery, PathParams>): (params?: RouteInput<PathParams, GlobalQuery & LocalQuery>) => string;
|
|
81
|
+
};
|
|
82
|
+
|
|
75
83
|
export declare type DeepPartial<T> = {
|
|
76
84
|
[P in keyof T]?: DeepPartial<T[P]>;
|
|
77
85
|
};
|
|
@@ -85,6 +93,12 @@ export declare interface EmptyProps extends ComponentProps<'div'> {
|
|
|
85
93
|
|
|
86
94
|
export declare const EmptyState: ({ label, action, icon, className, size, ...props }: EmptyProps) => JSX.Element;
|
|
87
95
|
|
|
96
|
+
declare type ExtractPathParams<T extends string> = T extends `${string}:${infer Param}/${infer Rest}` ? {
|
|
97
|
+
[K in Param | keyof ExtractPathParams<`/${Rest}`>]: string | number;
|
|
98
|
+
} : T extends `${string}:${infer Param}` ? {
|
|
99
|
+
[K in Param]: string | number;
|
|
100
|
+
} : {};
|
|
101
|
+
|
|
88
102
|
export declare type FetchNextPageOnScrollOptions = {
|
|
89
103
|
infinity: InfiniteQueryHookResult<InfiniteData<{
|
|
90
104
|
data: unknown[];
|
|
@@ -373,6 +387,12 @@ export declare interface NavItemsProps {
|
|
|
373
387
|
|
|
374
388
|
export declare const newHref: <T extends TParams, S extends TSearchParams = TSearchParams>(fn: string | ((args: Args<T, S>) => string)) => (args?: Args<T, S>) => string;
|
|
375
389
|
|
|
390
|
+
export declare const newRoute: {
|
|
391
|
+
<LocalQuery extends object = {}, Path extends string = string>(path: Path, options?: RouteOptions<LocalQuery, ExtractPathParams<Path>> | undefined): (params?: RouteInput<ExtractPathParams<Path>, LocalQuery> | undefined) => string;
|
|
392
|
+
<LocalQuery extends object = {}, PathParams extends Params = {}>(path: string, options?: RouteOptions<LocalQuery, PathParams> | undefined): (params?: RouteInput<PathParams, LocalQuery> | undefined) => string;
|
|
393
|
+
<LocalQuery extends object = {}, PathParams extends Params = {}>(pathBuilder: (params: PathParams) => string, options?: RouteOptions<LocalQuery, PathParams> | undefined): (params?: RouteInput<PathParams, LocalQuery> | undefined) => string;
|
|
394
|
+
};
|
|
395
|
+
|
|
376
396
|
export declare const nullableButRequired: <T extends ZodTypeAny>(schema: T, message?: string) => z.ZodEffects<z.ZodNullable<T>, T["_output"] | null, T["_input"] | null>;
|
|
377
397
|
|
|
378
398
|
export declare const numberToTimeInput: (number: number) => string;
|
|
@@ -403,8 +423,12 @@ export declare interface PageProps {
|
|
|
403
423
|
}>;
|
|
404
424
|
}
|
|
405
425
|
|
|
426
|
+
declare type Params = Record<string, Primitive>;
|
|
427
|
+
|
|
406
428
|
export declare const parseJSON: (response: KyResponse) => Promise<any>;
|
|
407
429
|
|
|
430
|
+
declare type Primitive = string | number | boolean | undefined;
|
|
431
|
+
|
|
408
432
|
declare const pxBySize: {
|
|
409
433
|
sm: number;
|
|
410
434
|
md: number;
|
|
@@ -413,6 +437,8 @@ declare const pxBySize: {
|
|
|
413
437
|
|
|
414
438
|
export declare const QP_BACK_URL_NAME = "backUrl";
|
|
415
439
|
|
|
440
|
+
export declare const queryStringify: (query?: Record<string, unknown>) => string;
|
|
441
|
+
|
|
416
442
|
export declare enum Revalidate {
|
|
417
443
|
OneHour = 3600,
|
|
418
444
|
OneDay = 86400,
|
|
@@ -421,6 +447,15 @@ export declare enum Revalidate {
|
|
|
421
447
|
OneYear = 31536000
|
|
422
448
|
}
|
|
423
449
|
|
|
450
|
+
declare type RouteInput<PathParams extends Params, Query> = PathParams & {
|
|
451
|
+
query?: Query;
|
|
452
|
+
};
|
|
453
|
+
|
|
454
|
+
declare type RouteOptions<Query, PathParams> = {
|
|
455
|
+
queryBuilder?: (query: Query) => string;
|
|
456
|
+
pathBuilder?: (params: PathParams) => string;
|
|
457
|
+
};
|
|
458
|
+
|
|
424
459
|
export declare function SelectInfinity({ value, onChange, data, searchValue, onSearchChange, renderOption, onOptionSubmit, nothingFoundMessage, infinity, placeholder, ...props }: SelectInfinityProps): JSX.Element;
|
|
425
460
|
|
|
426
461
|
export declare interface SelectInfinityProps extends InputBaseProps, ElementProps<'button', keyof InputBaseProps | 'value' | 'onChange'> {
|
package/dist/index.js
CHANGED
|
@@ -50,3 +50,5 @@ export { groupBy, indexBy } from './utils/array/groupBy.js';
|
|
|
50
50
|
export { shuffleArray } from './utils/array/shuffleArray.js';
|
|
51
51
|
export { newHref } from './utils/newHref.js';
|
|
52
52
|
export { isInfinityEmpty } from './utils/isInfinityEmpty.js';
|
|
53
|
+
export { queryStringify } from './utils/query-stringify.js';
|
|
54
|
+
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 };
|