lkd-web-kit 0.0.1 → 0.0.3

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/index4.cjs DELETED
@@ -1,78 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const require$$1 = require('react/jsx-runtime');
6
- const navigation = require('./navigation-DnFkn_t2.cjs');
7
- const require$$0 = require('react');
8
-
9
- const NavigationHistoryContext = require$$0.createContext(null);
10
- function NavigationHistoryProvider({ children }) {
11
- const pathname = navigation.navigationExports.usePathname();
12
- const searchParams = navigation.navigationExports.useSearchParams();
13
- const [history, setHistory] = require$$0.useState([]);
14
- require$$0.useEffect(() => {
15
- const fullPath = searchParams?.size ? `${pathname}?${searchParams.toString()}` : pathname;
16
- if (fullPath) {
17
- setHistory((prev) => {
18
- if (prev.length > 0 && prev[prev.length - 1] === fullPath) {
19
- return prev;
20
- }
21
- return [...prev, fullPath];
22
- });
23
- }
24
- }, [pathname, searchParams]);
25
- return /* @__PURE__ */ require$$1.jsx(NavigationHistoryContext.Provider, { value: { history }, children });
26
- }
27
- const QP_BACK_URL_NAME = "backUrl";
28
- function useNavigationHistory() {
29
- const context = require$$0.useContext(NavigationHistoryContext);
30
- const router = navigation.navigationExports.useRouter();
31
- if (!context) {
32
- throw new Error("useNavigationHistory debe usarse dentro de un NavigationHistoryProvider");
33
- }
34
- const searchParams = navigation.navigationExports.useSearchParams();
35
- const { history } = context;
36
- const goBack = (fallback) => {
37
- const returnUrl = searchParams.get(QP_BACK_URL_NAME);
38
- if (returnUrl) {
39
- router.push(returnUrl);
40
- return;
41
- }
42
- if (history.length <= 1) {
43
- router.push(fallback ?? "/");
44
- return;
45
- }
46
- const previousRoute = history[history.length - 2];
47
- const currentRoute = history[history.length - 1];
48
- if (history.length >= 3 && history[history.length - 3] === currentRoute) {
49
- router.push(fallback ?? "/");
50
- return;
51
- }
52
- router.push(previousRoute ?? "/");
53
- };
54
- return {
55
- history,
56
- goBack,
57
- currentRoute: history.length > 0 ? history[history.length - 1] : null,
58
- hasPreviousRoute: history.length > 1,
59
- getPreviousRoute: () => history.length >= 2 ? history[history.length - 2] : null
60
- };
61
- }
62
-
63
- const PageData = require$$0.createContext(void 0);
64
- const PageDataProvider = ({
65
- value,
66
- children
67
- }) => /* @__PURE__ */ require$$1.jsx(PageData.Provider, { value, children });
68
- const usePageData = () => {
69
- const data = require$$0.useContext(PageData);
70
- if (data === void 0) throw new Error("Out of context: usePageData");
71
- return data;
72
- };
73
-
74
- exports.NavigationHistoryProvider = NavigationHistoryProvider;
75
- exports.PageDataProvider = PageDataProvider;
76
- exports.QP_BACK_URL_NAME = QP_BACK_URL_NAME;
77
- exports.useNavigationHistory = useNavigationHistory;
78
- exports.usePageData = usePageData;
package/dist/index4.js DELETED
@@ -1,70 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { n as navigationExports } from './navigation-sZaWnl2V.js';
3
- import { useState, useEffect, createContext, useContext } from 'react';
4
-
5
- const NavigationHistoryContext = createContext(null);
6
- function NavigationHistoryProvider({ children }) {
7
- const pathname = navigationExports.usePathname();
8
- const searchParams = navigationExports.useSearchParams();
9
- const [history, setHistory] = useState([]);
10
- useEffect(() => {
11
- const fullPath = searchParams?.size ? `${pathname}?${searchParams.toString()}` : pathname;
12
- if (fullPath) {
13
- setHistory((prev) => {
14
- if (prev.length > 0 && prev[prev.length - 1] === fullPath) {
15
- return prev;
16
- }
17
- return [...prev, fullPath];
18
- });
19
- }
20
- }, [pathname, searchParams]);
21
- return /* @__PURE__ */ jsx(NavigationHistoryContext.Provider, { value: { history }, children });
22
- }
23
- const QP_BACK_URL_NAME = "backUrl";
24
- function useNavigationHistory() {
25
- const context = useContext(NavigationHistoryContext);
26
- const router = navigationExports.useRouter();
27
- if (!context) {
28
- throw new Error("useNavigationHistory debe usarse dentro de un NavigationHistoryProvider");
29
- }
30
- const searchParams = navigationExports.useSearchParams();
31
- const { history } = context;
32
- const goBack = (fallback) => {
33
- const returnUrl = searchParams.get(QP_BACK_URL_NAME);
34
- if (returnUrl) {
35
- router.push(returnUrl);
36
- return;
37
- }
38
- if (history.length <= 1) {
39
- router.push(fallback ?? "/");
40
- return;
41
- }
42
- const previousRoute = history[history.length - 2];
43
- const currentRoute = history[history.length - 1];
44
- if (history.length >= 3 && history[history.length - 3] === currentRoute) {
45
- router.push(fallback ?? "/");
46
- return;
47
- }
48
- router.push(previousRoute ?? "/");
49
- };
50
- return {
51
- history,
52
- goBack,
53
- currentRoute: history.length > 0 ? history[history.length - 1] : null,
54
- hasPreviousRoute: history.length > 1,
55
- getPreviousRoute: () => history.length >= 2 ? history[history.length - 2] : null
56
- };
57
- }
58
-
59
- const PageData = createContext(void 0);
60
- const PageDataProvider = ({
61
- value,
62
- children
63
- }) => /* @__PURE__ */ jsx(PageData.Provider, { value, children });
64
- const usePageData = () => {
65
- const data = useContext(PageData);
66
- if (data === void 0) throw new Error("Out of context: usePageData");
67
- return data;
68
- };
69
-
70
- export { NavigationHistoryProvider, PageDataProvider, QP_BACK_URL_NAME, useNavigationHistory, usePageData };
package/dist/index5.cjs DELETED
@@ -1,74 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const require$$1 = require('react/jsx-runtime');
6
- const reactHookForm = require('react-hook-form');
7
- const zodValidator = require('./zodValidator-Bx6RMGoL.cjs');
8
- const require$$0 = require('react');
9
-
10
- const withForm = (WrappedComponent, getControllerProps) => {
11
- const FormField = (props) => {
12
- const { validate, name = "", placeholder, label, description, ...withFormRestProps } = props;
13
- return /* @__PURE__ */ require$$1.jsx(
14
- reactHookForm.Controller,
15
- {
16
- name,
17
- defaultValue: "",
18
- rules: {
19
- validate: validate && !props.disabled ? zodValidator.zodValidator(validate) : void 0
20
- },
21
- disabled: props.disabled,
22
- ...getControllerProps?.(props),
23
- render: (renderProps) => {
24
- const {
25
- fieldState: { isTouched, error }
26
- } = renderProps;
27
- const fieldProps = {
28
- ...renderProps,
29
- props: {
30
- ...props,
31
- validate: void 0
32
- },
33
- field: {
34
- ...renderProps.field,
35
- label,
36
- placeholder,
37
- description,
38
- error: error?.message
39
- },
40
- ...withFormRestProps
41
- };
42
- return /* @__PURE__ */ require$$1.jsx(WrappedComponent, { ...fieldProps });
43
- }
44
- }
45
- );
46
- };
47
- FormField.displayName = `withForm(${WrappedComponent.displayName})`;
48
- return FormField;
49
- };
50
-
51
- const withModalManager = (WrappedComponent) => {
52
- const Component = ({
53
- removeModal,
54
- opened,
55
- ...props
56
- }) => {
57
- const [isOpen, setIsOpen] = require$$0.useState(false);
58
- const onClose = () => {
59
- setIsOpen(false);
60
- setTimeout(() => removeModal(), 200);
61
- props.onClose?.();
62
- };
63
- require$$0.useEffect(() => {
64
- if (opened) setTimeout(() => setIsOpen(true), 0);
65
- else onClose();
66
- }, [opened]);
67
- return /* @__PURE__ */ require$$1.jsx(WrappedComponent, { ...props, opened: isOpen, onClose });
68
- };
69
- Component.displayName = `withModalManager(${WrappedComponent.displayName})`;
70
- return Component;
71
- };
72
-
73
- exports.withForm = withForm;
74
- exports.withModalManager = withModalManager;
package/dist/index5.js DELETED
@@ -1,69 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { Controller } from 'react-hook-form';
3
- import { z as zodValidator } from './zodValidator-ChEQ3cmF.js';
4
- import { useState, useEffect } from 'react';
5
-
6
- const withForm = (WrappedComponent, getControllerProps) => {
7
- const FormField = (props) => {
8
- const { validate, name = "", placeholder, label, description, ...withFormRestProps } = props;
9
- return /* @__PURE__ */ jsx(
10
- Controller,
11
- {
12
- name,
13
- defaultValue: "",
14
- rules: {
15
- validate: validate && !props.disabled ? zodValidator(validate) : void 0
16
- },
17
- disabled: props.disabled,
18
- ...getControllerProps?.(props),
19
- render: (renderProps) => {
20
- const {
21
- fieldState: { isTouched, error }
22
- } = renderProps;
23
- const fieldProps = {
24
- ...renderProps,
25
- props: {
26
- ...props,
27
- validate: void 0
28
- },
29
- field: {
30
- ...renderProps.field,
31
- label,
32
- placeholder,
33
- description,
34
- error: error?.message
35
- },
36
- ...withFormRestProps
37
- };
38
- return /* @__PURE__ */ jsx(WrappedComponent, { ...fieldProps });
39
- }
40
- }
41
- );
42
- };
43
- FormField.displayName = `withForm(${WrappedComponent.displayName})`;
44
- return FormField;
45
- };
46
-
47
- const withModalManager = (WrappedComponent) => {
48
- const Component = ({
49
- removeModal,
50
- opened,
51
- ...props
52
- }) => {
53
- const [isOpen, setIsOpen] = useState(false);
54
- const onClose = () => {
55
- setIsOpen(false);
56
- setTimeout(() => removeModal(), 200);
57
- props.onClose?.();
58
- };
59
- useEffect(() => {
60
- if (opened) setTimeout(() => setIsOpen(true), 0);
61
- else onClose();
62
- }, [opened]);
63
- return /* @__PURE__ */ jsx(WrappedComponent, { ...props, opened: isOpen, onClose });
64
- };
65
- Component.displayName = `withModalManager(${WrappedComponent.displayName})`;
66
- return Component;
67
- };
68
-
69
- export { withForm, withModalManager };
package/dist/index6.cjs DELETED
@@ -1,29 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const breakpointsWithPx = {
6
- xs: "576px",
7
- sm: "640px",
8
- md: "768px",
9
- lg: "1024px",
10
- xl: "1280px",
11
- ["2xl"]: "1536px"
12
- };
13
-
14
- const toTailwindColors = (colors) => Object.entries(colors).reduce(
15
- (acc, [key, value]) => {
16
- acc[key] = value.reduce(
17
- (acc2, color, index) => {
18
- acc2[index] = color;
19
- return acc2;
20
- },
21
- {}
22
- );
23
- return acc;
24
- },
25
- {}
26
- );
27
-
28
- exports.breakpointsWithPx = breakpointsWithPx;
29
- exports.toTailwindColors = toTailwindColors;
package/dist/index6.js DELETED
@@ -1,24 +0,0 @@
1
- const breakpointsWithPx = {
2
- xs: "576px",
3
- sm: "640px",
4
- md: "768px",
5
- lg: "1024px",
6
- xl: "1280px",
7
- ["2xl"]: "1536px"
8
- };
9
-
10
- const toTailwindColors = (colors) => Object.entries(colors).reduce(
11
- (acc, [key, value]) => {
12
- acc[key] = value.reduce(
13
- (acc2, color, index) => {
14
- acc2[index] = color;
15
- return acc2;
16
- },
17
- {}
18
- );
19
- return acc;
20
- },
21
- {}
22
- );
23
-
24
- export { breakpointsWithPx, toTailwindColors };
package/dist/index7.cjs DELETED
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const require$$1 = require('react/jsx-runtime');
6
- const core = require('@mantine/core');
7
- const reactHookForm = require('react-hook-form');
8
- const zodValidator = require('./zodValidator-Bx6RMGoL.cjs');
9
- const zod = require('zod');
10
-
11
- const Form = ({
12
- methods,
13
- onSubmit = () => {
14
- },
15
- onSubmitError,
16
- ...rest
17
- }) => {
18
- return /* @__PURE__ */ require$$1.jsx(reactHookForm.FormProvider, { ...methods, children: /* @__PURE__ */ require$$1.jsx(
19
- core.Box,
20
- {
21
- component: "form",
22
- onSubmit: methods.handleSubmit(onSubmit, onSubmitError),
23
- ...rest
24
- }
25
- ) });
26
- };
27
-
28
- const FormButtonSubmit = (props) => {
29
- const { formState } = reactHookForm.useFormContext();
30
- const { isSubmitting } = formState;
31
- return /* @__PURE__ */ require$$1.jsx(
32
- core.Button,
33
- {
34
- loading: isSubmitting,
35
- type: "submit",
36
- ...props
37
- }
38
- );
39
- };
40
-
41
- const nullableInput = (schema, message = "Campo requerido") => {
42
- return schema.nullable().transform((val, ctx) => {
43
- if (val === null) {
44
- ctx.addIssue({
45
- code: zod.z.ZodIssueCode.custom,
46
- fatal: true,
47
- message
48
- });
49
- return zod.z.NEVER;
50
- }
51
- return val;
52
- });
53
- };
54
-
55
- exports.zodValidator = zodValidator.zodValidator;
56
- exports.Form = Form;
57
- exports.FormButtonSubmit = FormButtonSubmit;
58
- exports.nullableInput = nullableInput;
package/dist/index7.js DELETED
@@ -1,51 +0,0 @@
1
- import { jsx } from 'react/jsx-runtime';
2
- import { Box, Button } from '@mantine/core';
3
- import { FormProvider, useFormContext } from 'react-hook-form';
4
- export { z as zodValidator } from './zodValidator-ChEQ3cmF.js';
5
- import { z } from 'zod';
6
-
7
- const Form = ({
8
- methods,
9
- onSubmit = () => {
10
- },
11
- onSubmitError,
12
- ...rest
13
- }) => {
14
- return /* @__PURE__ */ jsx(FormProvider, { ...methods, children: /* @__PURE__ */ jsx(
15
- Box,
16
- {
17
- component: "form",
18
- onSubmit: methods.handleSubmit(onSubmit, onSubmitError),
19
- ...rest
20
- }
21
- ) });
22
- };
23
-
24
- const FormButtonSubmit = (props) => {
25
- const { formState } = useFormContext();
26
- const { isSubmitting } = formState;
27
- return /* @__PURE__ */ jsx(
28
- Button,
29
- {
30
- loading: isSubmitting,
31
- type: "submit",
32
- ...props
33
- }
34
- );
35
- };
36
-
37
- const nullableInput = (schema, message = "Campo requerido") => {
38
- return schema.nullable().transform((val, ctx) => {
39
- if (val === null) {
40
- ctx.addIssue({
41
- code: z.ZodIssueCode.custom,
42
- fatal: true,
43
- message
44
- });
45
- return z.NEVER;
46
- }
47
- return val;
48
- });
49
- };
50
-
51
- export { Form, FormButtonSubmit, nullableInput };
package/dist/index8.cjs DELETED
@@ -1,83 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- function formatBytes(bytes, decimals = 2) {
6
- if (!+bytes) return "0 Bytes";
7
- const k = 1024;
8
- const dm = decimals < 0 ? 0 : decimals;
9
- const sizes = ["Bytes", "KB", "MB"];
10
- const i = Math.floor(Math.log(bytes) / Math.log(k));
11
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
12
- }
13
-
14
- const parseJSON = async (response) => {
15
- return response.text().then(function(text) {
16
- return text ? JSON.parse(text) : {};
17
- });
18
- };
19
-
20
- const addBodyJsonHook = async (error) => {
21
- error.response.bodyJson = await parseJSON(error.response);
22
- return error;
23
- };
24
-
25
- function indexBy(arr, getKey, getValue) {
26
- if (getValue)
27
- return arr.reduce(
28
- (acc, item) => {
29
- const key = getKey(item);
30
- if (key === void 0) return acc;
31
- acc[key] = getValue(item);
32
- return acc;
33
- },
34
- {}
35
- );
36
- return arr.reduce(
37
- (acc, item) => {
38
- const key = getKey(item);
39
- if (key === void 0) return acc;
40
- acc[key] = item;
41
- return acc;
42
- },
43
- {}
44
- );
45
- }
46
- const groupBy = (arr, getKey) => {
47
- const groups = {};
48
- arr?.forEach((item) => {
49
- const key = getKey(item);
50
- if (key === null) return;
51
- if (Array.isArray(key)) {
52
- key.forEach((k) => {
53
- if (!groups[k]) groups[k] = [];
54
- groups[k]?.push(item);
55
- });
56
- return;
57
- }
58
- if (!groups[key]) groups[key] = [];
59
- groups[key]?.push(item);
60
- });
61
- return groups;
62
- };
63
-
64
- const shuffleArray = (array) => {
65
- const shuffledArray = [...array];
66
- let currentIndex = shuffledArray.length, randomIndex;
67
- while (currentIndex > 0) {
68
- randomIndex = Math.floor(Math.random() * currentIndex);
69
- currentIndex--;
70
- [shuffledArray[currentIndex], shuffledArray[randomIndex]] = [
71
- shuffledArray[randomIndex],
72
- shuffledArray[currentIndex]
73
- ];
74
- }
75
- return shuffledArray;
76
- };
77
-
78
- exports.addBodyJsonHook = addBodyJsonHook;
79
- exports.formatBytes = formatBytes;
80
- exports.groupBy = groupBy;
81
- exports.indexBy = indexBy;
82
- exports.parseJSON = parseJSON;
83
- exports.shuffleArray = shuffleArray;
package/dist/index8.js DELETED
@@ -1,74 +0,0 @@
1
- function formatBytes(bytes, decimals = 2) {
2
- if (!+bytes) return "0 Bytes";
3
- const k = 1024;
4
- const dm = decimals < 0 ? 0 : decimals;
5
- const sizes = ["Bytes", "KB", "MB"];
6
- const i = Math.floor(Math.log(bytes) / Math.log(k));
7
- return `${parseFloat((bytes / Math.pow(k, i)).toFixed(dm))} ${sizes[i]}`;
8
- }
9
-
10
- const parseJSON = async (response) => {
11
- return response.text().then(function(text) {
12
- return text ? JSON.parse(text) : {};
13
- });
14
- };
15
-
16
- const addBodyJsonHook = async (error) => {
17
- error.response.bodyJson = await parseJSON(error.response);
18
- return error;
19
- };
20
-
21
- function indexBy(arr, getKey, getValue) {
22
- if (getValue)
23
- return arr.reduce(
24
- (acc, item) => {
25
- const key = getKey(item);
26
- if (key === void 0) return acc;
27
- acc[key] = getValue(item);
28
- return acc;
29
- },
30
- {}
31
- );
32
- return arr.reduce(
33
- (acc, item) => {
34
- const key = getKey(item);
35
- if (key === void 0) return acc;
36
- acc[key] = item;
37
- return acc;
38
- },
39
- {}
40
- );
41
- }
42
- const groupBy = (arr, getKey) => {
43
- const groups = {};
44
- arr?.forEach((item) => {
45
- const key = getKey(item);
46
- if (key === null) return;
47
- if (Array.isArray(key)) {
48
- key.forEach((k) => {
49
- if (!groups[k]) groups[k] = [];
50
- groups[k]?.push(item);
51
- });
52
- return;
53
- }
54
- if (!groups[key]) groups[key] = [];
55
- groups[key]?.push(item);
56
- });
57
- return groups;
58
- };
59
-
60
- const shuffleArray = (array) => {
61
- const shuffledArray = [...array];
62
- let currentIndex = shuffledArray.length, randomIndex;
63
- while (currentIndex > 0) {
64
- randomIndex = Math.floor(Math.random() * currentIndex);
65
- currentIndex--;
66
- [shuffledArray[currentIndex], shuffledArray[randomIndex]] = [
67
- shuffledArray[randomIndex],
68
- shuffledArray[currentIndex]
69
- ];
70
- }
71
- return shuffledArray;
72
- };
73
-
74
- export { addBodyJsonHook, formatBytes, groupBy, indexBy, parseJSON, shuffleArray };
package/dist/mantine.d.ts DELETED
@@ -1,16 +0,0 @@
1
- import { DefaultMantineColor } from '@mantine/core';
2
- import { MantineColorShade } from '@mantine/core';
3
- import { MantineThemeColors } from '@mantine/core';
4
-
5
- export declare const breakpointsWithPx: {
6
- xs: string;
7
- sm: string;
8
- md: string;
9
- lg: string;
10
- xl: string;
11
- "2xl": string;
12
- };
13
-
14
- export declare const toTailwindColors: (colors: MantineThemeColors) => Record<DefaultMantineColor, Record<MantineColorShade, string>>;
15
-
16
- export { }