lkd-web-kit 0.4.0 → 0.4.2

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.
Files changed (29) hide show
  1. package/dist/components/InfinityLoader/index.cjs +3 -3
  2. package/dist/components/SelectInfinity/index.cjs +118 -74
  3. package/dist/components/SelectInfinity/index.js +119 -75
  4. package/dist/contexts/NavigationHistoryContext/index.cjs +5 -5
  5. package/dist/contexts/PageDataContext/index.cjs +3 -3
  6. package/dist/dist/components/InfinityLoader/index.cjs +46 -0
  7. package/dist/dist/components/InfinityLoader/index.js +42 -0
  8. package/dist/dist/form/utils/zodValidator.cjs +15 -0
  9. package/dist/dist/form/utils/zodValidator.js +11 -0
  10. package/dist/dist/hocs/withForm.cjs +51 -0
  11. package/dist/dist/hocs/withForm.js +47 -0
  12. package/dist/form/FormButtonSubmit.cjs +3 -2
  13. package/dist/form/FormButtonSubmit.js +3 -2
  14. package/dist/form/base/FormSelectInfinity.cjs +15 -9
  15. package/dist/form/base/FormSelectInfinity.js +16 -10
  16. package/dist/hocs/withModalManager.cjs +3 -3
  17. package/dist/hooks/useOnScrollProgress.cjs +2 -2
  18. package/dist/index.cjs +5 -2
  19. package/dist/index.d.ts +48 -25
  20. package/dist/index.js +3 -2
  21. package/dist/node_modules/@tanstack/react-virtual/dist/esm/index.cjs +71 -0
  22. package/dist/node_modules/@tanstack/react-virtual/dist/esm/index.js +42 -0
  23. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.cjs +744 -0
  24. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.js +730 -0
  25. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.cjs +71 -0
  26. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.js +64 -0
  27. package/dist/utils/virtual-styles.cjs +30 -0
  28. package/dist/utils/virtual-styles.js +25 -0
  29. package/package.json +4 -1
@@ -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 };
@@ -7,13 +7,14 @@ const jsxRuntime = require('react/jsx-runtime');
7
7
  const core = require('@mantine/core');
8
8
  const reactHookForm = require('react-hook-form');
9
9
 
10
- const FormButtonSubmit = (props) => {
10
+ const FormButtonSubmit = ({ disabled, ...props }) => {
11
11
  const {
12
- formState: { isSubmitting }
12
+ formState: { isSubmitting, isSubmitSuccessful }
13
13
  } = reactHookForm.useFormContext();
14
14
  return /* @__PURE__ */ jsxRuntime.jsx(
15
15
  core.Button,
16
16
  {
17
+ disabled: disabled ?? (isSubmitSuccessful && props.disabledWhenSuccess),
17
18
  loading: isSubmitting,
18
19
  type: "submit",
19
20
  ...props
@@ -3,13 +3,14 @@ import { jsx } from 'react/jsx-runtime';
3
3
  import { Button } from '@mantine/core';
4
4
  import { useFormContext } from 'react-hook-form';
5
5
 
6
- const FormButtonSubmit = (props) => {
6
+ const FormButtonSubmit = ({ disabled, ...props }) => {
7
7
  const {
8
- formState: { isSubmitting }
8
+ formState: { isSubmitting, isSubmitSuccessful }
9
9
  } = useFormContext();
10
10
  return /* @__PURE__ */ jsx(
11
11
  Button,
12
12
  {
13
+ disabled: disabled ?? (isSubmitSuccessful && props.disabledWhenSuccess),
13
14
  loading: isSubmitting,
14
15
  type: "submit",
15
16
  ...props
@@ -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
 
@@ -104,9 +106,10 @@ export declare const Form: <T extends FieldValues, TContext = any, TT extends T
104
106
 
105
107
  export declare function formatBytes(bytes: number, decimals?: number): string;
106
108
 
107
- export declare const FormButtonSubmit: (props: FormButtonSubmitProps) => JSX.Element;
109
+ export declare const FormButtonSubmit: ({ disabled, ...props }: FormButtonSubmitProps) => JSX.Element;
108
110
 
109
111
  export declare interface FormButtonSubmitProps extends ButtonProps, ElementProps<'button', keyof ButtonProps> {
112
+ disabledWhenSuccess?: boolean;
110
113
  }
111
114
 
112
115
  export declare const FormCheckbox: FC<CheckboxProps & WithFormProps>;
@@ -131,6 +134,10 @@ export declare type FormFieldProps<T = unknown> = Parameters<ControllerProps['re
131
134
  };
132
135
  };
133
136
 
137
+ export declare const FormInfinitySelect: <T>(props: FormInfinitySelectProps<T>) => ReactNode;
138
+
139
+ export declare type FormInfinitySelectProps<T = unknown> = InfinitySelectProps<T> & WithFormProps;
140
+
134
141
  export declare const FormMonthPickerInput: FC<MyMonthPickerInputProps & WithFormProps>;
135
142
 
136
143
  export declare type FormMonthPickerInputProps = WithFormProps & MyMonthPickerInputProps;
@@ -155,10 +162,6 @@ export declare type FormRadioGroupProps = RadioGroupProps & WithFormProps;
155
162
 
156
163
  export declare const FormSelect: FC<MySelectProps & WithFormProps>;
157
164
 
158
- export declare const FormSelectInfinity: FC<SelectInfinityProps & WithFormProps>;
159
-
160
- export declare type FormSelectInfinityProps = SelectInfinityProps & WithFormProps;
161
-
162
165
  export declare type FormSelectProps = MySelectProps & WithFormProps;
163
166
 
164
167
  export declare const FormTextarea: FC<TextareaProps & WithFormProps>;
@@ -173,6 +176,19 @@ export declare type FormTimeInput = MyTimeInputProps & WithFormProps;
173
176
 
174
177
  export declare const FormTimeInput: FC<TimeInputProps & WithFormProps>;
175
178
 
179
+ export declare const getVirtualContainerProps: (virtualizer: {
180
+ getTotalSize: () => number;
181
+ }) => ComponentProps<"div">;
182
+
183
+ export declare const getVirtualItemProps: (item: VirtualItem, virtualizer: {
184
+ options: {
185
+ scrollMargin: number;
186
+ };
187
+ measureElement: (element: Element | null) => void;
188
+ }) => ComponentProps<"div"> & {
189
+ ["data-index"]: number;
190
+ };
191
+
176
192
  export declare const groupBy: <T extends any>(arr: T[], getKey: (item: T) => string | string[] | null) => Record<string, T[] | undefined>;
177
193
 
178
194
  export declare type GroupByResult<T> = Record<string, T[] | undefined>;
@@ -276,6 +292,32 @@ export declare interface InfinityLoaderProps extends CenterProps {
276
292
  loaderProps?: LoaderProps;
277
293
  }
278
294
 
295
+ 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;
296
+
297
+ export declare interface InfinitySelectProps<T = unknown> extends InputBaseProps, ElementProps<'input', keyof InputBaseProps | 'value' | 'onChange'> {
298
+ value?: string | null;
299
+ defaultValue?: string;
300
+ searchValue?: string;
301
+ defaultSearchValue?: string;
302
+ nothingFoundMessage?: ReactNode | ((data: {
303
+ combobox: ComboboxStore;
304
+ }) => ReactNode);
305
+ infinity: InfiniteQueryHookResult<InfiniteData<{
306
+ data: T[];
307
+ }, number>, Error>;
308
+ selectedOption?: T | null;
309
+ onSelectedOptionChange?: (option: T | null) => void;
310
+ onSearchChange?: (value: string) => void;
311
+ onChange?: (value: string | null) => void;
312
+ renderOption?: (args: {
313
+ option: T;
314
+ }) => React.ReactNode;
315
+ onOptionSubmit?: (value: string, option: T) => void;
316
+ getOptionLabel: (option: T) => string;
317
+ getOptionValue: (option: T) => string;
318
+ comboboxProps?: ComboboxProps;
319
+ }
320
+
279
321
  export declare const isInfinityEmpty: (data: InfiniteData<{
280
322
  data: unknown[];
281
323
  }> | undefined) => boolean;
@@ -447,25 +489,6 @@ declare type RouteOptions<Query, PathParams> = {
447
489
  pathBuilder?: (params: PathParams) => string;
448
490
  };
449
491
 
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
492
  export declare type Setter<T> = Dispatch<SetStateAction<T>>;
470
493
 
471
494
  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 };