@udecode/react-utils 49.0.15 → 52.0.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.d.ts +88 -58
- package/dist/index.js +275 -360
- package/package.json +9 -12
- package/dist/index.d.mts +0 -155
- package/dist/index.js.map +0 -1
- package/dist/index.mjs +0 -340
- package/dist/index.mjs.map +0 -1
package/dist/index.d.ts
CHANGED
|
@@ -1,32 +1,45 @@
|
|
|
1
|
-
import React, {
|
|
1
|
+
import React, { DependencyList, JSX } from "react";
|
|
2
2
|
|
|
3
|
+
//#region src/Box.d.ts
|
|
3
4
|
declare const Box: React.ForwardRefExoticComponent<{
|
|
4
|
-
|
|
5
|
-
|
|
5
|
+
as?: React.ElementType;
|
|
6
|
+
asChild?: boolean;
|
|
6
7
|
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & React.RefAttributes<any>>;
|
|
7
8
|
type BoxProps = React.ComponentPropsWithRef<typeof Box>;
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
//#endregion
|
|
10
|
+
//#region src/MemoizedChildren.d.ts
|
|
11
|
+
declare const MemoizedChildren: React.MemoExoticComponent<({
|
|
12
|
+
children
|
|
13
|
+
}: {
|
|
14
|
+
children: React.ReactNode;
|
|
11
15
|
}) => React.JSX.Element>;
|
|
12
|
-
|
|
16
|
+
//#endregion
|
|
17
|
+
//#region src/PortalBody.d.ts
|
|
13
18
|
type PortalBodyProps = {
|
|
14
|
-
|
|
15
|
-
|
|
19
|
+
children: React.ReactNode;
|
|
20
|
+
element?: Element;
|
|
16
21
|
};
|
|
17
|
-
declare const PortalBody: ({
|
|
18
|
-
|
|
22
|
+
declare const PortalBody: ({
|
|
23
|
+
children,
|
|
24
|
+
element
|
|
25
|
+
}: PortalBodyProps) => React.ReactPortal;
|
|
26
|
+
//#endregion
|
|
27
|
+
//#region src/Text.d.ts
|
|
19
28
|
declare const Text: React.ForwardRefExoticComponent<{
|
|
20
|
-
|
|
21
|
-
|
|
29
|
+
as?: React.ElementType;
|
|
30
|
+
asChild?: boolean;
|
|
22
31
|
} & Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & React.RefAttributes<any>>;
|
|
23
32
|
type TextProps = React.ComponentPropsWithRef<typeof Text>;
|
|
24
|
-
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region src/composeEventHandlers.d.ts
|
|
25
35
|
/** @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1 */
|
|
26
|
-
declare const composeEventHandlers: <E>(originalEventHandler?: (event: E) => void, ourEventHandler?: (event: E) => void, {
|
|
27
|
-
|
|
36
|
+
declare const composeEventHandlers: <E>(originalEventHandler?: (event: E) => void, ourEventHandler?: (event: E) => void, {
|
|
37
|
+
checkForDefaultPrevented
|
|
38
|
+
}?: {
|
|
39
|
+
checkForDefaultPrevented?: boolean | undefined;
|
|
28
40
|
}) => (event: E) => void;
|
|
29
|
-
|
|
41
|
+
//#endregion
|
|
42
|
+
//#region src/createPrimitiveComponent.d.ts
|
|
30
43
|
/**
|
|
31
44
|
* Primitive component factory. It uses hooks for managing state and props, and
|
|
32
45
|
* forwards references to child components. Component props:
|
|
@@ -52,26 +65,32 @@ declare const composeEventHandlers: <E>(originalEventHandler?: (event: E) => voi
|
|
|
52
65
|
* @param {React.ElementType} element The base component or native HTML element.
|
|
53
66
|
* @returns {function} A primitive component.
|
|
54
67
|
*/
|
|
55
|
-
declare const createPrimitiveComponent: <T extends React.ElementType, P extends React.ComponentPropsWithoutRef<T>>(element: T) => <SH extends (options: any) => any, PH extends (state: any) => any>({
|
|
56
|
-
|
|
57
|
-
|
|
68
|
+
declare const createPrimitiveComponent: <T extends React.ElementType, P extends React.ComponentPropsWithoutRef<T>>(element: T) => <SH extends (options: any) => any, PH extends (state: any) => any>({
|
|
69
|
+
propsHook,
|
|
70
|
+
stateHook
|
|
71
|
+
}?: {
|
|
72
|
+
propsHook?: PH;
|
|
73
|
+
stateHook?: SH;
|
|
58
74
|
}) => React.ForwardRefExoticComponent<React.PropsWithoutRef<{
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
75
|
+
as?: React.ElementType;
|
|
76
|
+
asChild?: boolean;
|
|
77
|
+
className?: string;
|
|
78
|
+
options?: Parameters<SH>[0];
|
|
79
|
+
state?: Parameters<PH>[0];
|
|
80
|
+
style?: React.CSSProperties;
|
|
81
|
+
setProps?: (hookProps: NonNullable<ReturnType<PH>["props"]>) => P;
|
|
66
82
|
} & P> & React.RefAttributes<any>>;
|
|
67
|
-
|
|
83
|
+
//#endregion
|
|
84
|
+
//#region src/createPrimitiveElement.d.ts
|
|
68
85
|
declare function createPrimitiveElement<T extends keyof HTMLElementTagNameMap>(tag: T): React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.IntrinsicElements[T]> & React.RefAttributes<HTMLElementTagNameMap[T]>>;
|
|
69
|
-
|
|
86
|
+
//#endregion
|
|
87
|
+
//#region src/createSlotComponent.d.ts
|
|
70
88
|
declare const createSlotComponent: <T extends React.ElementType, P extends React.ComponentPropsWithoutRef<T>>(element: T) => React.ForwardRefExoticComponent<React.PropsWithoutRef<{
|
|
71
|
-
|
|
72
|
-
|
|
89
|
+
as?: React.ElementType;
|
|
90
|
+
asChild?: boolean;
|
|
73
91
|
} & P> & React.RefAttributes<any>>;
|
|
74
|
-
|
|
92
|
+
//#endregion
|
|
93
|
+
//#region src/useComposedRef.d.ts
|
|
75
94
|
type PossibleRef<T> = React.Ref<T> | undefined;
|
|
76
95
|
/**
|
|
77
96
|
* A utility to compose multiple refs together Accepts callback refs and
|
|
@@ -83,18 +102,19 @@ declare const composeRefs: <T>(...refs: PossibleRef<T>[]) => (node: T) => (() =>
|
|
|
83
102
|
* React.RefObject(s)
|
|
84
103
|
*/
|
|
85
104
|
declare const useComposedRef: <T>(...refs: PossibleRef<T>[]) => (node: T) => (() => void) | undefined;
|
|
86
|
-
|
|
105
|
+
//#endregion
|
|
106
|
+
//#region src/useEffectOnce.d.ts
|
|
87
107
|
declare function useEffectOnce(effect: React.EffectCallback, deps: React.DependencyList): void;
|
|
88
|
-
|
|
108
|
+
//#endregion
|
|
109
|
+
//#region src/useIsomorphicLayoutEffect.d.ts
|
|
89
110
|
declare const CAN_USE_DOM: boolean;
|
|
90
111
|
/**
|
|
91
112
|
* Prevent warning on SSR by falling back to React.useEffect when DOM isn't
|
|
92
113
|
* available
|
|
93
114
|
*/
|
|
94
115
|
declare const useIsomorphicLayoutEffect: typeof React.useEffect;
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
116
|
+
//#endregion
|
|
117
|
+
//#region src/useMemoizedSelector.d.ts
|
|
98
118
|
/**
|
|
99
119
|
* Re-render only when the selector result changes.
|
|
100
120
|
*
|
|
@@ -103,23 +123,32 @@ declare function useMemoOnce<T>(factory: () => T, deps: React.DependencyList): T
|
|
|
103
123
|
* @param equalityFn Optional comparison function to detect changes in the
|
|
104
124
|
* derived value
|
|
105
125
|
*/
|
|
106
|
-
declare function useMemoizedSelector<R>(selector: () => R, deps: React.DependencyList, equalityFn?: (a: R, b: R) => boolean): R;
|
|
107
|
-
|
|
126
|
+
declare function useMemoizedSelector<R$1>(selector: () => R$1, deps: React.DependencyList, equalityFn?: (a: R$1, b: R$1) => boolean): R$1;
|
|
127
|
+
//#endregion
|
|
128
|
+
//#region src/useOnClickOutside.d.ts
|
|
108
129
|
declare const DEFAULT_IGNORE_CLASS = "ignore-onclickoutside";
|
|
109
130
|
type UseOnClickOutsideCallback<T extends Event = Event> = (event: T) => void;
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
131
|
+
type UseOnClickOutsideOptions = {
|
|
132
|
+
detectIFrame?: boolean;
|
|
133
|
+
disabled?: boolean;
|
|
134
|
+
eventTypes?: string[];
|
|
135
|
+
excludeScrollbar?: boolean;
|
|
136
|
+
ignoreClass?: string[] | string;
|
|
137
|
+
refs?: Refs;
|
|
138
|
+
};
|
|
118
139
|
type UseOnClickOutsideReturn = (element: El | null) => void;
|
|
119
140
|
type El = HTMLElement;
|
|
120
141
|
type Refs = React.RefObject<El | null>[];
|
|
121
|
-
declare const useOnClickOutside: (callback: UseOnClickOutsideCallback, {
|
|
122
|
-
|
|
142
|
+
declare const useOnClickOutside: (callback: UseOnClickOutsideCallback, {
|
|
143
|
+
detectIFrame,
|
|
144
|
+
disabled,
|
|
145
|
+
eventTypes,
|
|
146
|
+
excludeScrollbar,
|
|
147
|
+
ignoreClass,
|
|
148
|
+
refs: refsOpt
|
|
149
|
+
}?: UseOnClickOutsideOptions) => UseOnClickOutsideReturn;
|
|
150
|
+
//#endregion
|
|
151
|
+
//#region src/useStableFn.d.ts
|
|
123
152
|
/**
|
|
124
153
|
* Create a stable version of a function that can be used in dependency arrays
|
|
125
154
|
* without causing hooks like useEffect to re-run if the function changes.
|
|
@@ -129,19 +158,20 @@ declare const useOnClickOutside: (callback: UseOnClickOutsideCallback, { detectI
|
|
|
129
158
|
* If you do want the function to be replaced when certain dependency values
|
|
130
159
|
* change, include those values in the dependency array of useStableFn.
|
|
131
160
|
*/
|
|
132
|
-
declare const useStableFn: <A extends unknown[], R>(fn: (...args: A) => R, deps?: DependencyList) => (...args: A) => R;
|
|
133
|
-
|
|
161
|
+
declare const useStableFn: <A extends unknown[], R$1>(fn: (...args: A) => R$1, deps?: DependencyList) => (...args: A) => R$1;
|
|
162
|
+
//#endregion
|
|
163
|
+
//#region src/useStableMemo.d.ts
|
|
134
164
|
declare const useStableMemo: <T>(producer: () => T, deps?: React.DependencyList) => T;
|
|
135
|
-
|
|
165
|
+
//#endregion
|
|
166
|
+
//#region src/withProviders.d.ts
|
|
136
167
|
/**
|
|
137
168
|
* Wrap a component into multiple providers. If there are any props that you
|
|
138
169
|
* want a provider to receive, you can simply pass an array.
|
|
139
170
|
*/
|
|
140
171
|
declare const withProviders: (...providers: any[]) => <T>(WrappedComponent: React.FC<T>) => (props: T) => any;
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
}[keyof JSX.IntrinsicElements];
|
|
172
|
+
//#endregion
|
|
173
|
+
//#region src/withRef.d.ts
|
|
174
|
+
type ElementType<P = any> = React.ComponentType<P> | { [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K] ? K : never }[keyof JSX.IntrinsicElements];
|
|
145
175
|
type ForwardRefComponent<T, P = {}> = React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<T>>;
|
|
146
176
|
type InferElementRef<T> = T extends ElementType<any> ? T extends keyof JSX.IntrinsicElements ? JSX.IntrinsicElements[T] extends React.DetailedHTMLProps<React.HTMLAttributes<infer R>, any> ? R : never : T extends React.ComponentType<any> ? T extends React.ComponentClass<any> ? InstanceType<T> : T extends React.ForwardRefExoticComponent<any> ? React.ComponentPropsWithRef<T>['ref'] extends React.Ref<infer R> ? R : never : never : never : never;
|
|
147
177
|
/**
|
|
@@ -151,5 +181,5 @@ type InferElementRef<T> = T extends ElementType<any> ? T extends keyof JSX.Intri
|
|
|
151
181
|
* @generic2 Extended prop types
|
|
152
182
|
*/
|
|
153
183
|
declare function withRef<T extends ElementType, P = {}>(renderFunction: React.ForwardRefRenderFunction<InferElementRef<T>, React.ComponentPropsWithoutRef<T> & P>): ForwardRefComponent<InferElementRef<T>, React.ComponentPropsWithoutRef<T> & P>;
|
|
154
|
-
|
|
155
|
-
export { Box,
|
|
184
|
+
//#endregion
|
|
185
|
+
export { Box, BoxProps, CAN_USE_DOM, DEFAULT_IGNORE_CLASS, MemoizedChildren, PortalBody, PortalBodyProps, Text, TextProps, UseOnClickOutsideCallback, UseOnClickOutsideOptions, UseOnClickOutsideReturn, composeEventHandlers, composeRefs, createPrimitiveComponent, createPrimitiveElement, createSlotComponent, useComposedRef, useEffectOnce, useIsomorphicLayoutEffect, useMemoizedSelector, useOnClickOutside, useStableFn, useStableMemo, withProviders, withRef };
|