lkd-web-kit 0.4.0 → 0.4.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.
@@ -0,0 +1,51 @@
1
+ 'use client';
2
+ 'use strict';
3
+
4
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
+
6
+ const jsxRuntime = require('react/jsx-runtime');
7
+ const reactHookForm = require('react-hook-form');
8
+ const zodValidator = require('../form/utils/zodValidator.cjs');
9
+
10
+ const withForm = (WrappedComponent, getControllerProps) => {
11
+ const FormField = (props) => {
12
+ const { validate, name = "", placeholder, label, description, ...withFormRestProps } = props;
13
+ return /* @__PURE__ */ jsxRuntime.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: { 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__ */ jsxRuntime.jsx(WrappedComponent, { ...fieldProps });
43
+ }
44
+ }
45
+ );
46
+ };
47
+ FormField.displayName = `WithForm(${WrappedComponent.displayName})`;
48
+ return FormField;
49
+ };
50
+
51
+ exports.withForm = withForm;
@@ -0,0 +1,47 @@
1
+ 'use client';
2
+ import { jsx } from 'react/jsx-runtime';
3
+ import { Controller } from 'react-hook-form';
4
+ import { zodValidator } from '../form/utils/zodValidator.js';
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: { 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
+ export { withForm };
@@ -3,15 +3,21 @@
3
3
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
4
 
5
5
  const jsxRuntime = require('react/jsx-runtime');
6
+ const withForm = require('../../dist/hocs/withForm.cjs');
6
7
  const index = require('../../components/SelectInfinity/index.cjs');
7
- const withForm = require('../../hocs/withForm.cjs');
8
8
 
9
- const FormSelectInfinity = withForm.withForm(({ field, props }) => /* @__PURE__ */ jsxRuntime.jsx(
10
- index.SelectInfinity,
11
- {
12
- ...field,
13
- ...props
14
- }
15
- ));
9
+ const FormInfinitySelect = withForm.withForm(({ field, props }) => {
10
+ return /* @__PURE__ */ jsxRuntime.jsx(
11
+ index.InfinitySelect,
12
+ {
13
+ ...field,
14
+ ...props,
15
+ onChange: (e) => {
16
+ field.onChange(e);
17
+ props.onChange?.(e);
18
+ }
19
+ }
20
+ );
21
+ });
16
22
 
17
- exports.FormSelectInfinity = FormSelectInfinity;
23
+ exports.FormInfinitySelect = FormInfinitySelect;
@@ -1,13 +1,19 @@
1
1
  import { jsx } from 'react/jsx-runtime';
2
- import { SelectInfinity } from '../../components/SelectInfinity/index.js';
3
- import { withForm } from '../../hocs/withForm.js';
2
+ import { withForm } from '../../dist/hocs/withForm.js';
3
+ import { InfinitySelect } from '../../components/SelectInfinity/index.js';
4
4
 
5
- const FormSelectInfinity = withForm(({ field, props }) => /* @__PURE__ */ jsx(
6
- SelectInfinity,
7
- {
8
- ...field,
9
- ...props
10
- }
11
- ));
5
+ const FormInfinitySelect = withForm(({ field, props }) => {
6
+ return /* @__PURE__ */ jsx(
7
+ InfinitySelect,
8
+ {
9
+ ...field,
10
+ ...props,
11
+ onChange: (e) => {
12
+ field.onChange(e);
13
+ props.onChange?.(e);
14
+ }
15
+ }
16
+ );
17
+ });
12
18
 
13
- export { FormSelectInfinity };
19
+ export { FormInfinitySelect };
@@ -4,7 +4,7 @@
4
4
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
 
6
6
  const jsxRuntime = require('react/jsx-runtime');
7
- const react = require('react');
7
+ const React = require('react');
8
8
 
9
9
  const withModalManager = (WrappedComponent) => {
10
10
  const Component = ({
@@ -12,13 +12,13 @@ const withModalManager = (WrappedComponent) => {
12
12
  opened,
13
13
  ...props
14
14
  }) => {
15
- const [isOpen, setIsOpen] = react.useState(false);
15
+ const [isOpen, setIsOpen] = React.useState(false);
16
16
  const onClose = () => {
17
17
  setIsOpen(false);
18
18
  setTimeout(() => removeModal(), 200);
19
19
  props.onClose?.();
20
20
  };
21
- react.useEffect(() => {
21
+ React.useEffect(() => {
22
22
  if (opened) setTimeout(() => setIsOpen(true), 0);
23
23
  else onClose();
24
24
  }, [opened]);
@@ -3,7 +3,7 @@
3
3
 
4
4
  Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
5
5
 
6
- const react = require('react');
6
+ const React = require('react');
7
7
 
8
8
  const useOnScrollProgress = ({
9
9
  triggerPercentage,
@@ -13,7 +13,7 @@ const useOnScrollProgress = ({
13
13
  }) => {
14
14
  if (triggerPercentage < 0 || triggerPercentage > 1)
15
15
  throw new Error("El porcentaje debe estar entre 0 y 1");
16
- react.useEffect(() => {
16
+ React.useEffect(() => {
17
17
  if (disabled || scrollRef && scrollRef.current === null) return;
18
18
  let hasTriggered = false;
19
19
  const handleScroll = () => {
package/dist/index.cjs CHANGED
@@ -55,6 +55,7 @@ const shuffleArray = require('./utils/array/shuffleArray.cjs');
55
55
  const isInfinityEmpty = require('./utils/isInfinityEmpty.cjs');
56
56
  const queryStringify = require('./utils/query-stringify.cjs');
57
57
  const newRoute = require('./utils/new-route.cjs');
58
+ const virtualStyles = require('./utils/virtual-styles.cjs');
58
59
 
59
60
 
60
61
 
@@ -70,7 +71,7 @@ exports.MySelect = index$6.MySelect;
70
71
  exports.MyTextarea = index$7.MyTextarea;
71
72
  exports.MyTextInput = index$8.MyTextInput;
72
73
  exports.MyTimeInput = index$9.MyTimeInput;
73
- exports.SelectInfinity = index$a.SelectInfinity;
74
+ exports.InfinitySelect = index$a.InfinitySelect;
74
75
  exports.MyMultiSelect = index$b.MyMultiSelect;
75
76
  exports.MyMonthPickerInput = index$c.MyMonthPickerInput;
76
77
  exports.HttpStatus = httpStatus.HttpStatus;
@@ -91,7 +92,7 @@ exports.FormDateTimePicker = FormDateTimePicker.FormDateTimePicker;
91
92
  exports.FormNumberInput = FormNumberInput.FormNumberInput;
92
93
  exports.FormRadioGroup = FormRadioGroup.FormRadioGroup;
93
94
  exports.FormSelect = FormSelect.FormSelect;
94
- exports.FormSelectInfinity = FormSelectInfinity.FormSelectInfinity;
95
+ exports.FormInfinitySelect = FormSelectInfinity.FormInfinitySelect;
95
96
  exports.FormTextarea = FormTextarea.FormTextarea;
96
97
  exports.FormTextInput = FormTextInput.FormTextInput;
97
98
  exports.FormTimeInput = FormTimeInput.FormTimeInput;
@@ -118,3 +119,5 @@ exports.isInfinityEmpty = isInfinityEmpty.isInfinityEmpty;
118
119
  exports.queryStringify = queryStringify.queryStringify;
119
120
  exports.createNewRoute = newRoute.createNewRoute;
120
121
  exports.newRoute = newRoute.newRoute;
122
+ exports.getVirtualContainerProps = virtualStyles.getVirtualContainerProps;
123
+ exports.getVirtualItemProps = virtualStyles.getVirtualItemProps;
package/dist/index.d.ts CHANGED
@@ -3,7 +3,8 @@ import { BoxProps } from '@mantine/core';
3
3
  import { ButtonProps } from '@mantine/core';
4
4
  import { CenterProps } from '@mantine/core';
5
5
  import { CheckboxProps } from '@mantine/core';
6
- import { ComboboxItem } from '@mantine/core';
6
+ import { ComboboxProps } from '@mantine/core';
7
+ import { ComboboxStore } from '@mantine/core';
7
8
  import { ComponentProps } from 'react';
8
9
  import { ComponentPropsWithoutRef } from 'react';
9
10
  import { ControllerProps } from 'react-hook-form';
@@ -43,6 +44,7 @@ import { TextareaProps } from '@mantine/core';
43
44
  import { TextInputProps } from '@mantine/core';
44
45
  import { TimeInputProps } from '@mantine/dates';
45
46
  import { UseFormReturn } from 'react-hook-form';
47
+ import { VirtualItem } from '@tanstack/react-virtual';
46
48
  import { z } from 'zod';
47
49
  import { ZodTypeAny } from 'zod';
48
50
 
@@ -131,6 +133,10 @@ export declare type FormFieldProps<T = unknown> = Parameters<ControllerProps['re
131
133
  };
132
134
  };
133
135
 
136
+ export declare const FormInfinitySelect: <T>(props: FormInfinitySelectProps<T>) => ReactNode;
137
+
138
+ export declare type FormInfinitySelectProps<T = unknown> = InfinitySelectProps<T> & WithFormProps;
139
+
134
140
  export declare const FormMonthPickerInput: FC<MyMonthPickerInputProps & WithFormProps>;
135
141
 
136
142
  export declare type FormMonthPickerInputProps = WithFormProps & MyMonthPickerInputProps;
@@ -155,10 +161,6 @@ export declare type FormRadioGroupProps = RadioGroupProps & WithFormProps;
155
161
 
156
162
  export declare const FormSelect: FC<MySelectProps & WithFormProps>;
157
163
 
158
- export declare const FormSelectInfinity: FC<SelectInfinityProps & WithFormProps>;
159
-
160
- export declare type FormSelectInfinityProps = SelectInfinityProps & WithFormProps;
161
-
162
164
  export declare type FormSelectProps = MySelectProps & WithFormProps;
163
165
 
164
166
  export declare const FormTextarea: FC<TextareaProps & WithFormProps>;
@@ -173,6 +175,19 @@ export declare type FormTimeInput = MyTimeInputProps & WithFormProps;
173
175
 
174
176
  export declare const FormTimeInput: FC<TimeInputProps & WithFormProps>;
175
177
 
178
+ export declare const getVirtualContainerProps: (virtualizer: {
179
+ getTotalSize: () => number;
180
+ }) => ComponentProps<"div">;
181
+
182
+ export declare const getVirtualItemProps: (item: VirtualItem, virtualizer: {
183
+ options: {
184
+ scrollMargin: number;
185
+ };
186
+ measureElement: (element: Element | null) => void;
187
+ }) => ComponentProps<"div"> & {
188
+ ["data-index"]: number;
189
+ };
190
+
176
191
  export declare const groupBy: <T extends any>(arr: T[], getKey: (item: T) => string | string[] | null) => Record<string, T[] | undefined>;
177
192
 
178
193
  export declare type GroupByResult<T> = Record<string, T[] | undefined>;
@@ -276,6 +291,32 @@ export declare interface InfinityLoaderProps extends CenterProps {
276
291
  loaderProps?: LoaderProps;
277
292
  }
278
293
 
294
+ export declare function InfinitySelect<T = unknown>({ value, searchValue, defaultSearchValue, nothingFoundMessage, infinity, defaultValue, onChange, onSearchChange, renderOption, onOptionSubmit, getOptionLabel, getOptionValue, onSelectedOptionChange, selectedOption, comboboxProps, ...props }: InfinitySelectProps<T>): JSX.Element;
295
+
296
+ export declare interface InfinitySelectProps<T = unknown> extends InputBaseProps, ElementProps<'input', keyof InputBaseProps | 'value' | 'onChange'> {
297
+ value?: string | null;
298
+ defaultValue?: string;
299
+ searchValue?: string;
300
+ defaultSearchValue?: string;
301
+ nothingFoundMessage?: ReactNode | ((data: {
302
+ combobox: ComboboxStore;
303
+ }) => ReactNode);
304
+ infinity: InfiniteQueryHookResult<InfiniteData<{
305
+ data: T[];
306
+ }, number>, Error>;
307
+ selectedOption?: T | null;
308
+ onSelectedOptionChange?: (option: T | null) => void;
309
+ onSearchChange?: (value: string) => void;
310
+ onChange?: (value: string | null) => void;
311
+ renderOption?: (args: {
312
+ option: T;
313
+ }) => React.ReactNode;
314
+ onOptionSubmit?: (value: string, option: T) => void;
315
+ getOptionLabel: (option: T) => string;
316
+ getOptionValue: (option: T) => string;
317
+ comboboxProps?: ComboboxProps;
318
+ }
319
+
279
320
  export declare const isInfinityEmpty: (data: InfiniteData<{
280
321
  data: unknown[];
281
322
  }> | undefined) => boolean;
@@ -447,25 +488,6 @@ declare type RouteOptions<Query, PathParams> = {
447
488
  pathBuilder?: (params: PathParams) => string;
448
489
  };
449
490
 
450
- export declare function SelectInfinity({ value, onChange, data, searchValue, onSearchChange, renderOption, onOptionSubmit, nothingFoundMessage, infinity, placeholder, ...props }: SelectInfinityProps): JSX.Element;
451
-
452
- export declare interface SelectInfinityProps extends InputBaseProps, ElementProps<'button', keyof InputBaseProps | 'value' | 'onChange'> {
453
- value?: string | null;
454
- onChange?: (value: string | null) => void;
455
- data?: ComboboxItem[];
456
- searchValue?: string;
457
- onSearchChange?: (value: string) => void;
458
- renderOption?: (args: {
459
- option: ComboboxItem;
460
- }) => React.ReactNode;
461
- onOptionSubmit?: (value: string) => void;
462
- nothingFoundMessage?: ReactNode;
463
- infinity: InfiniteQueryHookResult<InfiniteData<{
464
- data: unknown[];
465
- }, number>, Error>;
466
- placeholder?: string;
467
- }
468
-
469
491
  export declare type Setter<T> = Dispatch<SetStateAction<T>>;
470
492
 
471
493
  export declare const shuffleArray: <T>(array: T[]) => T[];
package/dist/index.js CHANGED
@@ -10,7 +10,7 @@ export { MySelect } from './components/MySelect/index.js';
10
10
  export { MyTextarea } from './components/MyTextarea/index.js';
11
11
  export { MyTextInput } from './components/MyTextInput/index.js';
12
12
  export { MyTimeInput } from './components/MyTimeInput/index.js';
13
- export { SelectInfinity } from './components/SelectInfinity/index.js';
13
+ export { InfinitySelect } from './components/SelectInfinity/index.js';
14
14
  export { MyMultiSelect } from './components/MyMultiSelect/index.js';
15
15
  export { MyMonthPickerInput } from './components/MyMonthPickerInput/index.js';
16
16
  export { HttpStatus } from './consts/http-status.js';
@@ -28,7 +28,7 @@ export { FormDateTimePicker } from './form/base/FormDateTimePicker.js';
28
28
  export { FormNumberInput } from './form/base/FormNumberInput.js';
29
29
  export { FormRadioGroup } from './form/base/FormRadioGroup.js';
30
30
  export { FormSelect } from './form/base/FormSelect.js';
31
- export { FormSelectInfinity } from './form/base/FormSelectInfinity.js';
31
+ export { FormInfinitySelect } from './form/base/FormSelectInfinity.js';
32
32
  export { FormTextarea } from './form/base/FormTextarea.js';
33
33
  export { FormTextInput } from './form/base/FormTextInput.js';
34
34
  export { FormTimeInput, numberToTimeInput, timeInputToNumber } from './form/base/FormTimeInput.js';
@@ -51,3 +51,4 @@ export { shuffleArray } from './utils/array/shuffleArray.js';
51
51
  export { isInfinityEmpty } from './utils/isInfinityEmpty.js';
52
52
  export { queryStringify } from './utils/query-stringify.js';
53
53
  export { createNewRoute, newRoute } from './utils/new-route.js';
54
+ export { getVirtualContainerProps, getVirtualItemProps } from './utils/virtual-styles.js';
@@ -0,0 +1,71 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
+
5
+ const React = require('react');
6
+ const reactDom = require('react-dom');
7
+ const index = require('../../../virtual-core/dist/esm/index.cjs');
8
+
9
+ function _interopNamespaceDefault(e) {
10
+ const n = Object.create(null, { [Symbol.toStringTag]: { value: 'Module' } });
11
+ if (e) {
12
+ for (const k in e) {
13
+ if (k !== 'default') {
14
+ const d = Object.getOwnPropertyDescriptor(e, k);
15
+ Object.defineProperty(n, k, d.get ? d : {
16
+ enumerable: true,
17
+ get: () => e[k]
18
+ });
19
+ }
20
+ }
21
+ }
22
+ n.default = e;
23
+ return Object.freeze(n);
24
+ }
25
+
26
+ const React__namespace = /*#__PURE__*/_interopNamespaceDefault(React);
27
+
28
+ const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React__namespace.useLayoutEffect : React__namespace.useEffect;
29
+ function useVirtualizerBase(options) {
30
+ const rerender = React__namespace.useReducer(() => ({}), {})[1];
31
+ const resolvedOptions = {
32
+ ...options,
33
+ onChange: (instance2, sync) => {
34
+ var _a;
35
+ if (sync) {
36
+ reactDom.flushSync(rerender);
37
+ } else {
38
+ rerender();
39
+ }
40
+ (_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
41
+ }
42
+ };
43
+ const [instance] = React__namespace.useState(
44
+ () => new index.Virtualizer(resolvedOptions)
45
+ );
46
+ instance.setOptions(resolvedOptions);
47
+ useIsomorphicLayoutEffect(() => {
48
+ return instance._didMount();
49
+ }, []);
50
+ useIsomorphicLayoutEffect(() => {
51
+ return instance._willUpdate();
52
+ });
53
+ return instance;
54
+ }
55
+ function useVirtualizer(options) {
56
+ return useVirtualizerBase({
57
+ observeElementRect: index.observeElementRect,
58
+ observeElementOffset: index.observeElementOffset,
59
+ scrollToFn: index.elementScroll,
60
+ ...options
61
+ });
62
+ }
63
+
64
+ exports.Virtualizer = index.Virtualizer;
65
+ exports.defaultKeyExtractor = index.defaultKeyExtractor;
66
+ exports.defaultRangeExtractor = index.defaultRangeExtractor;
67
+ exports.elementScroll = index.elementScroll;
68
+ exports.measureElement = index.measureElement;
69
+ exports.observeElementOffset = index.observeElementOffset;
70
+ exports.observeElementRect = index.observeElementRect;
71
+ exports.useVirtualizer = useVirtualizer;
@@ -0,0 +1,42 @@
1
+ import * as React from 'react';
2
+ import { flushSync } from 'react-dom';
3
+ import { Virtualizer, elementScroll, observeElementOffset, observeElementRect } from '../../../virtual-core/dist/esm/index.js';
4
+ export { defaultKeyExtractor, defaultRangeExtractor, measureElement } from '../../../virtual-core/dist/esm/index.js';
5
+
6
+ const useIsomorphicLayoutEffect = typeof document !== "undefined" ? React.useLayoutEffect : React.useEffect;
7
+ function useVirtualizerBase(options) {
8
+ const rerender = React.useReducer(() => ({}), {})[1];
9
+ const resolvedOptions = {
10
+ ...options,
11
+ onChange: (instance2, sync) => {
12
+ var _a;
13
+ if (sync) {
14
+ flushSync(rerender);
15
+ } else {
16
+ rerender();
17
+ }
18
+ (_a = options.onChange) == null ? void 0 : _a.call(options, instance2, sync);
19
+ }
20
+ };
21
+ const [instance] = React.useState(
22
+ () => new Virtualizer(resolvedOptions)
23
+ );
24
+ instance.setOptions(resolvedOptions);
25
+ useIsomorphicLayoutEffect(() => {
26
+ return instance._didMount();
27
+ }, []);
28
+ useIsomorphicLayoutEffect(() => {
29
+ return instance._willUpdate();
30
+ });
31
+ return instance;
32
+ }
33
+ function useVirtualizer(options) {
34
+ return useVirtualizerBase({
35
+ observeElementRect,
36
+ observeElementOffset,
37
+ scrollToFn: elementScroll,
38
+ ...options
39
+ });
40
+ }
41
+
42
+ export { Virtualizer, elementScroll, observeElementOffset, observeElementRect, useVirtualizer };