@udecode/react-utils 29.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/README.md +11 -0
- package/dist/index.d.mts +127 -0
- package/dist/index.d.ts +127 -0
- package/dist/index.js +361 -0
- package/dist/index.js.map +1 -0
- package/dist/index.mjs +312 -0
- package/dist/index.mjs.map +1 -0
- package/package.json +55 -0
package/README.md
ADDED
package/dist/index.d.mts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
declare const Box: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
4
|
+
as?: React.ElementType<any> | undefined;
|
|
5
|
+
asChild?: boolean | undefined;
|
|
6
|
+
} & React.RefAttributes<any>>;
|
|
7
|
+
type BoxProps = React.ComponentPropsWithRef<typeof Box>;
|
|
8
|
+
|
|
9
|
+
type PortalBodyProps = {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
element?: Element;
|
|
12
|
+
};
|
|
13
|
+
declare const PortalBody: ({ children, element, }: PortalBodyProps) => React.ReactPortal;
|
|
14
|
+
|
|
15
|
+
declare const Text: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
16
|
+
as?: React.ElementType<any> | undefined;
|
|
17
|
+
asChild?: boolean | undefined;
|
|
18
|
+
} & React.RefAttributes<any>>;
|
|
19
|
+
type TextProps = React.ComponentPropsWithRef<typeof Text>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1
|
|
23
|
+
*/
|
|
24
|
+
declare const composeEventHandlers: <E>(originalEventHandler?: ((event: E) => void) | undefined, ourEventHandler?: ((event: E) => void) | undefined, { checkForDefaultPrevented }?: {
|
|
25
|
+
checkForDefaultPrevented?: boolean | undefined;
|
|
26
|
+
}) => (event: E) => void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Primitive component factory. It uses hooks for managing
|
|
30
|
+
* state and props, and forwards references to child components.
|
|
31
|
+
* Component props:
|
|
32
|
+
* - `asChild`: If true, the component will be rendered as a `Slot` {@link https://www.radix-ui.com/docs/primitives/utilities/slot}.
|
|
33
|
+
* - `options`: Options passed to the state hook.
|
|
34
|
+
* - `state`: Provide your state instead of using the state hook.
|
|
35
|
+
* - `className`: Class name to be merged to the component.
|
|
36
|
+
* - `style`: Style object to be merged to the component.
|
|
37
|
+
* - `setProps`: Function to set props from the props hook.
|
|
38
|
+
* - `...props`: Props to be passed to the component.
|
|
39
|
+
* Props hook return value:
|
|
40
|
+
* - `ref`: Reference to be forwarded to the component.
|
|
41
|
+
* - `props`: Props to be passed to the component.
|
|
42
|
+
* - `hidden`: If true, the component will not be rendered.
|
|
43
|
+
*
|
|
44
|
+
* @param {React.ElementType} element The base component or native HTML element.
|
|
45
|
+
* @returns {function} A primitive component.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
*
|
|
49
|
+
* const MyButton = createPrimitiveComponent(Button)({
|
|
50
|
+
* stateHook: useButtonState,
|
|
51
|
+
* propsHook: useButton
|
|
52
|
+
* });
|
|
53
|
+
*/
|
|
54
|
+
declare const createPrimitiveComponent: <T extends React.ElementType<any>, P extends React.PropsWithoutRef<React.ComponentProps<T>>>(element: T) => <SH extends (options: any) => any, PH extends (state: any) => any>({ propsHook, stateHook, }?: {
|
|
55
|
+
stateHook?: SH | undefined;
|
|
56
|
+
propsHook?: PH | undefined;
|
|
57
|
+
}) => React.ForwardRefExoticComponent<React.PropsWithoutRef<{
|
|
58
|
+
as?: React.ElementType<any> | undefined;
|
|
59
|
+
asChild?: boolean | undefined;
|
|
60
|
+
className?: string | undefined;
|
|
61
|
+
style?: React.CSSProperties | undefined;
|
|
62
|
+
options?: Parameters<SH>[0] | undefined;
|
|
63
|
+
state?: Parameters<PH>[0] | undefined;
|
|
64
|
+
setProps?: ((hookProps: NonNullable<ReturnType<PH>["props"]>) => P) | undefined;
|
|
65
|
+
} & P> & React.RefAttributes<any>>;
|
|
66
|
+
|
|
67
|
+
declare function createPrimitiveElement<T extends keyof HTMLElementTagNameMap>(tag: T): React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.IntrinsicElements[T]> & React.RefAttributes<HTMLElementTagNameMap[T]>>;
|
|
68
|
+
|
|
69
|
+
declare const createSlotComponent: <T extends React.ElementType<any>, P extends React.PropsWithoutRef<React.ComponentProps<T>>>(element: T) => React.ForwardRefExoticComponent<React.PropsWithoutRef<P & {
|
|
70
|
+
as?: React.ElementType<any> | undefined;
|
|
71
|
+
asChild?: boolean | undefined;
|
|
72
|
+
}> & React.RefAttributes<any>>;
|
|
73
|
+
|
|
74
|
+
type PossibleRef<T> = React.Ref<T> | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* A utility to compose multiple refs together
|
|
77
|
+
* Accepts callback refs and React.RefObject(s)
|
|
78
|
+
*/
|
|
79
|
+
declare const composeRefs: <T>(...refs: PossibleRef<T>[]) => (node: T) => void;
|
|
80
|
+
/**
|
|
81
|
+
* A custom hook that composes multiple refs
|
|
82
|
+
* Accepts callback refs and React.RefObject(s)
|
|
83
|
+
*/
|
|
84
|
+
declare const useComposedRef: <T>(...refs: PossibleRef<T>[]) => (node: T) => void;
|
|
85
|
+
|
|
86
|
+
declare const CAN_USE_DOM: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Prevent warning on SSR by falling back to React.useEffect when DOM isn't available
|
|
89
|
+
*/
|
|
90
|
+
declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
91
|
+
|
|
92
|
+
declare const DEFAULT_IGNORE_CLASS = "ignore-onclickoutside";
|
|
93
|
+
interface UseOnClickOutsideCallback<T extends Event = Event> {
|
|
94
|
+
(event: T): void;
|
|
95
|
+
}
|
|
96
|
+
type El = HTMLElement;
|
|
97
|
+
type Refs = React.RefObject<El>[];
|
|
98
|
+
interface UseOnClickOutsideOptions {
|
|
99
|
+
refs?: Refs;
|
|
100
|
+
disabled?: boolean;
|
|
101
|
+
eventTypes?: string[];
|
|
102
|
+
excludeScrollbar?: boolean;
|
|
103
|
+
ignoreClass?: string | string[];
|
|
104
|
+
detectIFrame?: boolean;
|
|
105
|
+
}
|
|
106
|
+
interface UseOnClickOutsideReturn {
|
|
107
|
+
(element: El | null): void;
|
|
108
|
+
}
|
|
109
|
+
declare const useOnClickOutside: (callback: UseOnClickOutsideCallback, { refs: refsOpt, disabled, eventTypes, excludeScrollbar, ignoreClass, detectIFrame, }?: UseOnClickOutsideOptions) => UseOnClickOutsideReturn;
|
|
110
|
+
|
|
111
|
+
declare const useStableMemo: <T>(producer: () => T, deps?: React.DependencyList) => T;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Wrap a component into multiple providers.
|
|
115
|
+
* If there are any props that you want a provider to receive,
|
|
116
|
+
* you can simply pass an array.
|
|
117
|
+
*/
|
|
118
|
+
declare const withProviders: (...providers: any[]) => <T>(WrappedComponent: React.FC<T>) => (props: T) => any;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Shorter alternative to `React.forwardRef`.
|
|
122
|
+
* @generic1 Component type or element type
|
|
123
|
+
* @generic2 Extended prop types
|
|
124
|
+
*/
|
|
125
|
+
declare function withRef<T extends keyof HTMLElementTagNameMap | React.ComponentType<object>, E = {}>(renderFunction: React.ForwardRefRenderFunction<React.ElementRef<T>, React.ComponentPropsWithoutRef<T> & E>): React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.ComponentProps<T>> & E> & React.RefAttributes<React.ElementRef<T>>>;
|
|
126
|
+
|
|
127
|
+
export { Box, BoxProps, CAN_USE_DOM, DEFAULT_IGNORE_CLASS, PortalBody, PortalBodyProps, Text, TextProps, UseOnClickOutsideCallback, UseOnClickOutsideOptions, UseOnClickOutsideReturn, composeEventHandlers, composeRefs, createPrimitiveComponent, createPrimitiveElement, createSlotComponent, useComposedRef, useIsomorphicLayoutEffect, useOnClickOutside, useStableMemo, withProviders, withRef };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
|
|
3
|
+
declare const Box: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLDivElement>, HTMLDivElement>, "ref"> & {
|
|
4
|
+
as?: React.ElementType<any> | undefined;
|
|
5
|
+
asChild?: boolean | undefined;
|
|
6
|
+
} & React.RefAttributes<any>>;
|
|
7
|
+
type BoxProps = React.ComponentPropsWithRef<typeof Box>;
|
|
8
|
+
|
|
9
|
+
type PortalBodyProps = {
|
|
10
|
+
children: React.ReactNode;
|
|
11
|
+
element?: Element;
|
|
12
|
+
};
|
|
13
|
+
declare const PortalBody: ({ children, element, }: PortalBodyProps) => React.ReactPortal;
|
|
14
|
+
|
|
15
|
+
declare const Text: React.ForwardRefExoticComponent<Omit<React.DetailedHTMLProps<React.HTMLAttributes<HTMLSpanElement>, HTMLSpanElement>, "ref"> & {
|
|
16
|
+
as?: React.ElementType<any> | undefined;
|
|
17
|
+
asChild?: boolean | undefined;
|
|
18
|
+
} & React.RefAttributes<any>>;
|
|
19
|
+
type TextProps = React.ComponentPropsWithRef<typeof Text>;
|
|
20
|
+
|
|
21
|
+
/**
|
|
22
|
+
* @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1
|
|
23
|
+
*/
|
|
24
|
+
declare const composeEventHandlers: <E>(originalEventHandler?: ((event: E) => void) | undefined, ourEventHandler?: ((event: E) => void) | undefined, { checkForDefaultPrevented }?: {
|
|
25
|
+
checkForDefaultPrevented?: boolean | undefined;
|
|
26
|
+
}) => (event: E) => void;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Primitive component factory. It uses hooks for managing
|
|
30
|
+
* state and props, and forwards references to child components.
|
|
31
|
+
* Component props:
|
|
32
|
+
* - `asChild`: If true, the component will be rendered as a `Slot` {@link https://www.radix-ui.com/docs/primitives/utilities/slot}.
|
|
33
|
+
* - `options`: Options passed to the state hook.
|
|
34
|
+
* - `state`: Provide your state instead of using the state hook.
|
|
35
|
+
* - `className`: Class name to be merged to the component.
|
|
36
|
+
* - `style`: Style object to be merged to the component.
|
|
37
|
+
* - `setProps`: Function to set props from the props hook.
|
|
38
|
+
* - `...props`: Props to be passed to the component.
|
|
39
|
+
* Props hook return value:
|
|
40
|
+
* - `ref`: Reference to be forwarded to the component.
|
|
41
|
+
* - `props`: Props to be passed to the component.
|
|
42
|
+
* - `hidden`: If true, the component will not be rendered.
|
|
43
|
+
*
|
|
44
|
+
* @param {React.ElementType} element The base component or native HTML element.
|
|
45
|
+
* @returns {function} A primitive component.
|
|
46
|
+
*
|
|
47
|
+
* @example
|
|
48
|
+
*
|
|
49
|
+
* const MyButton = createPrimitiveComponent(Button)({
|
|
50
|
+
* stateHook: useButtonState,
|
|
51
|
+
* propsHook: useButton
|
|
52
|
+
* });
|
|
53
|
+
*/
|
|
54
|
+
declare const createPrimitiveComponent: <T extends React.ElementType<any>, P extends React.PropsWithoutRef<React.ComponentProps<T>>>(element: T) => <SH extends (options: any) => any, PH extends (state: any) => any>({ propsHook, stateHook, }?: {
|
|
55
|
+
stateHook?: SH | undefined;
|
|
56
|
+
propsHook?: PH | undefined;
|
|
57
|
+
}) => React.ForwardRefExoticComponent<React.PropsWithoutRef<{
|
|
58
|
+
as?: React.ElementType<any> | undefined;
|
|
59
|
+
asChild?: boolean | undefined;
|
|
60
|
+
className?: string | undefined;
|
|
61
|
+
style?: React.CSSProperties | undefined;
|
|
62
|
+
options?: Parameters<SH>[0] | undefined;
|
|
63
|
+
state?: Parameters<PH>[0] | undefined;
|
|
64
|
+
setProps?: ((hookProps: NonNullable<ReturnType<PH>["props"]>) => P) | undefined;
|
|
65
|
+
} & P> & React.RefAttributes<any>>;
|
|
66
|
+
|
|
67
|
+
declare function createPrimitiveElement<T extends keyof HTMLElementTagNameMap>(tag: T): React.ForwardRefExoticComponent<React.PropsWithoutRef<JSX.IntrinsicElements[T]> & React.RefAttributes<HTMLElementTagNameMap[T]>>;
|
|
68
|
+
|
|
69
|
+
declare const createSlotComponent: <T extends React.ElementType<any>, P extends React.PropsWithoutRef<React.ComponentProps<T>>>(element: T) => React.ForwardRefExoticComponent<React.PropsWithoutRef<P & {
|
|
70
|
+
as?: React.ElementType<any> | undefined;
|
|
71
|
+
asChild?: boolean | undefined;
|
|
72
|
+
}> & React.RefAttributes<any>>;
|
|
73
|
+
|
|
74
|
+
type PossibleRef<T> = React.Ref<T> | undefined;
|
|
75
|
+
/**
|
|
76
|
+
* A utility to compose multiple refs together
|
|
77
|
+
* Accepts callback refs and React.RefObject(s)
|
|
78
|
+
*/
|
|
79
|
+
declare const composeRefs: <T>(...refs: PossibleRef<T>[]) => (node: T) => void;
|
|
80
|
+
/**
|
|
81
|
+
* A custom hook that composes multiple refs
|
|
82
|
+
* Accepts callback refs and React.RefObject(s)
|
|
83
|
+
*/
|
|
84
|
+
declare const useComposedRef: <T>(...refs: PossibleRef<T>[]) => (node: T) => void;
|
|
85
|
+
|
|
86
|
+
declare const CAN_USE_DOM: boolean;
|
|
87
|
+
/**
|
|
88
|
+
* Prevent warning on SSR by falling back to React.useEffect when DOM isn't available
|
|
89
|
+
*/
|
|
90
|
+
declare const useIsomorphicLayoutEffect: typeof React.useLayoutEffect;
|
|
91
|
+
|
|
92
|
+
declare const DEFAULT_IGNORE_CLASS = "ignore-onclickoutside";
|
|
93
|
+
interface UseOnClickOutsideCallback<T extends Event = Event> {
|
|
94
|
+
(event: T): void;
|
|
95
|
+
}
|
|
96
|
+
type El = HTMLElement;
|
|
97
|
+
type Refs = React.RefObject<El>[];
|
|
98
|
+
interface UseOnClickOutsideOptions {
|
|
99
|
+
refs?: Refs;
|
|
100
|
+
disabled?: boolean;
|
|
101
|
+
eventTypes?: string[];
|
|
102
|
+
excludeScrollbar?: boolean;
|
|
103
|
+
ignoreClass?: string | string[];
|
|
104
|
+
detectIFrame?: boolean;
|
|
105
|
+
}
|
|
106
|
+
interface UseOnClickOutsideReturn {
|
|
107
|
+
(element: El | null): void;
|
|
108
|
+
}
|
|
109
|
+
declare const useOnClickOutside: (callback: UseOnClickOutsideCallback, { refs: refsOpt, disabled, eventTypes, excludeScrollbar, ignoreClass, detectIFrame, }?: UseOnClickOutsideOptions) => UseOnClickOutsideReturn;
|
|
110
|
+
|
|
111
|
+
declare const useStableMemo: <T>(producer: () => T, deps?: React.DependencyList) => T;
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Wrap a component into multiple providers.
|
|
115
|
+
* If there are any props that you want a provider to receive,
|
|
116
|
+
* you can simply pass an array.
|
|
117
|
+
*/
|
|
118
|
+
declare const withProviders: (...providers: any[]) => <T>(WrappedComponent: React.FC<T>) => (props: T) => any;
|
|
119
|
+
|
|
120
|
+
/**
|
|
121
|
+
* Shorter alternative to `React.forwardRef`.
|
|
122
|
+
* @generic1 Component type or element type
|
|
123
|
+
* @generic2 Extended prop types
|
|
124
|
+
*/
|
|
125
|
+
declare function withRef<T extends keyof HTMLElementTagNameMap | React.ComponentType<object>, E = {}>(renderFunction: React.ForwardRefRenderFunction<React.ElementRef<T>, React.ComponentPropsWithoutRef<T> & E>): React.ForwardRefExoticComponent<React.PropsWithoutRef<React.PropsWithoutRef<React.ComponentProps<T>> & E> & React.RefAttributes<React.ElementRef<T>>>;
|
|
126
|
+
|
|
127
|
+
export { Box, BoxProps, CAN_USE_DOM, DEFAULT_IGNORE_CLASS, PortalBody, PortalBodyProps, Text, TextProps, UseOnClickOutsideCallback, UseOnClickOutsideOptions, UseOnClickOutsideReturn, composeEventHandlers, composeRefs, createPrimitiveComponent, createPrimitiveElement, createSlotComponent, useComposedRef, useIsomorphicLayoutEffect, useOnClickOutside, useStableMemo, withProviders, withRef };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,361 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __defProps = Object.defineProperties;
|
|
5
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
6
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
7
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
8
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
9
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
10
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
11
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
12
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
13
|
+
var __spreadValues = (a, b) => {
|
|
14
|
+
for (var prop in b || (b = {}))
|
|
15
|
+
if (__hasOwnProp.call(b, prop))
|
|
16
|
+
__defNormalProp(a, prop, b[prop]);
|
|
17
|
+
if (__getOwnPropSymbols)
|
|
18
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
19
|
+
if (__propIsEnum.call(b, prop))
|
|
20
|
+
__defNormalProp(a, prop, b[prop]);
|
|
21
|
+
}
|
|
22
|
+
return a;
|
|
23
|
+
};
|
|
24
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
25
|
+
var __objRest = (source, exclude) => {
|
|
26
|
+
var target = {};
|
|
27
|
+
for (var prop in source)
|
|
28
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
29
|
+
target[prop] = source[prop];
|
|
30
|
+
if (source != null && __getOwnPropSymbols)
|
|
31
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
32
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
33
|
+
target[prop] = source[prop];
|
|
34
|
+
}
|
|
35
|
+
return target;
|
|
36
|
+
};
|
|
37
|
+
var __export = (target, all) => {
|
|
38
|
+
for (var name in all)
|
|
39
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
40
|
+
};
|
|
41
|
+
var __copyProps = (to, from, except, desc) => {
|
|
42
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
43
|
+
for (let key of __getOwnPropNames(from))
|
|
44
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
45
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
46
|
+
}
|
|
47
|
+
return to;
|
|
48
|
+
};
|
|
49
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
50
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
51
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
52
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
53
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
54
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
55
|
+
mod
|
|
56
|
+
));
|
|
57
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
58
|
+
|
|
59
|
+
// src/index.ts
|
|
60
|
+
var src_exports = {};
|
|
61
|
+
__export(src_exports, {
|
|
62
|
+
Box: () => Box,
|
|
63
|
+
CAN_USE_DOM: () => CAN_USE_DOM,
|
|
64
|
+
DEFAULT_IGNORE_CLASS: () => DEFAULT_IGNORE_CLASS,
|
|
65
|
+
PortalBody: () => PortalBody,
|
|
66
|
+
Text: () => Text,
|
|
67
|
+
composeEventHandlers: () => composeEventHandlers,
|
|
68
|
+
composeRefs: () => composeRefs,
|
|
69
|
+
createPrimitiveComponent: () => createPrimitiveComponent,
|
|
70
|
+
createPrimitiveElement: () => createPrimitiveElement,
|
|
71
|
+
createSlotComponent: () => createSlotComponent,
|
|
72
|
+
useComposedRef: () => useComposedRef,
|
|
73
|
+
useIsomorphicLayoutEffect: () => useIsomorphicLayoutEffect,
|
|
74
|
+
useOnClickOutside: () => useOnClickOutside,
|
|
75
|
+
useStableMemo: () => useStableMemo,
|
|
76
|
+
withProviders: () => withProviders,
|
|
77
|
+
withRef: () => withRef
|
|
78
|
+
});
|
|
79
|
+
module.exports = __toCommonJS(src_exports);
|
|
80
|
+
|
|
81
|
+
// src/createSlotComponent.tsx
|
|
82
|
+
var import_react = __toESM(require("react"));
|
|
83
|
+
var import_react_slot = require("@radix-ui/react-slot");
|
|
84
|
+
var createSlotComponent = (element) => (
|
|
85
|
+
// eslint-disable-next-line react/display-name
|
|
86
|
+
import_react.default.forwardRef((_a, ref) => {
|
|
87
|
+
var _b = _a, { as, asChild = false } = _b, props = __objRest(_b, ["as", "asChild"]);
|
|
88
|
+
const Comp = asChild ? import_react_slot.Slot : as || element;
|
|
89
|
+
return /* @__PURE__ */ import_react.default.createElement(Comp, __spreadValues({ ref }, props));
|
|
90
|
+
})
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
// src/Box.tsx
|
|
94
|
+
var Box = createSlotComponent("div");
|
|
95
|
+
|
|
96
|
+
// src/PortalBody.tsx
|
|
97
|
+
var import_react2 = __toESM(require("react"));
|
|
98
|
+
var import_react_dom = __toESM(require("react-dom"));
|
|
99
|
+
var PortalBody = ({
|
|
100
|
+
children,
|
|
101
|
+
element
|
|
102
|
+
}) => {
|
|
103
|
+
const container = element || typeof window !== "undefined" ? document.body : void 0;
|
|
104
|
+
if (!container)
|
|
105
|
+
return /* @__PURE__ */ import_react2.default.createElement(import_react2.default.Fragment, null, children);
|
|
106
|
+
return import_react_dom.default.createPortal(children, element || document.body);
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
// src/Text.tsx
|
|
110
|
+
var Text = createSlotComponent("span");
|
|
111
|
+
|
|
112
|
+
// src/composeEventHandlers.ts
|
|
113
|
+
var composeEventHandlers = (originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) => (event) => {
|
|
114
|
+
originalEventHandler == null ? void 0 : originalEventHandler(event);
|
|
115
|
+
if (checkForDefaultPrevented === false || !event.defaultPrevented) {
|
|
116
|
+
return ourEventHandler == null ? void 0 : ourEventHandler(event);
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
// src/createPrimitiveComponent.tsx
|
|
121
|
+
var import_react4 = __toESM(require("react"));
|
|
122
|
+
var import_utils = require("@udecode/utils");
|
|
123
|
+
var import_clsx = require("clsx");
|
|
124
|
+
|
|
125
|
+
// src/useComposedRef.ts
|
|
126
|
+
var import_react3 = __toESM(require("react"));
|
|
127
|
+
var setRef = (ref, value) => {
|
|
128
|
+
if (typeof ref === "function") {
|
|
129
|
+
ref(value);
|
|
130
|
+
} else if (ref !== null && ref !== void 0) {
|
|
131
|
+
ref.current = value;
|
|
132
|
+
}
|
|
133
|
+
};
|
|
134
|
+
var composeRefs = (...refs) => (node) => refs.forEach((ref) => setRef(ref, node));
|
|
135
|
+
var useComposedRef = (...refs) => {
|
|
136
|
+
return import_react3.default.useCallback(composeRefs(...refs), refs);
|
|
137
|
+
};
|
|
138
|
+
|
|
139
|
+
// src/createPrimitiveComponent.tsx
|
|
140
|
+
var createPrimitiveComponent = (element) => {
|
|
141
|
+
const Comp = createSlotComponent(element);
|
|
142
|
+
return ({
|
|
143
|
+
propsHook,
|
|
144
|
+
stateHook
|
|
145
|
+
} = {}) => {
|
|
146
|
+
return import_react4.default.forwardRef(
|
|
147
|
+
(_a, ref) => {
|
|
148
|
+
var _b = _a, {
|
|
149
|
+
asChild,
|
|
150
|
+
options,
|
|
151
|
+
state: stateProp,
|
|
152
|
+
className: classNameProp,
|
|
153
|
+
getClassName
|
|
154
|
+
} = _b, props = __objRest(_b, [
|
|
155
|
+
"asChild",
|
|
156
|
+
"options",
|
|
157
|
+
"state",
|
|
158
|
+
"className",
|
|
159
|
+
"getClassName"
|
|
160
|
+
]);
|
|
161
|
+
var _a2, _b2;
|
|
162
|
+
const state = (0, import_utils.isDefined)(stateProp) ? stateProp : stateHook ? stateHook(options) : void 0;
|
|
163
|
+
const {
|
|
164
|
+
ref: hookRef,
|
|
165
|
+
props: hookProps,
|
|
166
|
+
hidden
|
|
167
|
+
} = propsHook ? propsHook(state) : { props: {}, hidden: false, ref: null };
|
|
168
|
+
const _ref = useComposedRef(ref, hookRef);
|
|
169
|
+
const className = (0, import_utils.isDefined)(hookProps == null ? void 0 : hookProps.className) || (0, import_utils.isDefined)(classNameProp) ? (0, import_clsx.clsx)(hookProps == null ? void 0 : hookProps.className, classNameProp) : void 0;
|
|
170
|
+
const style = (hookProps == null ? void 0 : hookProps.style) || props.style ? __spreadValues(__spreadValues({}, hookProps == null ? void 0 : hookProps.style), props.style) : void 0;
|
|
171
|
+
if (!asChild && hidden)
|
|
172
|
+
return null;
|
|
173
|
+
return /* @__PURE__ */ import_react4.default.createElement(
|
|
174
|
+
Comp,
|
|
175
|
+
__spreadValues(__spreadValues(__spreadProps(__spreadValues({
|
|
176
|
+
ref: _ref,
|
|
177
|
+
asChild
|
|
178
|
+
}, hookProps), {
|
|
179
|
+
className,
|
|
180
|
+
style
|
|
181
|
+
}), props), (_b2 = (_a2 = props.setProps) == null ? void 0 : _a2.call(props, hookProps != null ? hookProps : {})) != null ? _b2 : {})
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
);
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
// src/createPrimitiveElement.tsx
|
|
189
|
+
var import_react5 = __toESM(require("react"));
|
|
190
|
+
function createPrimitiveElement(tag) {
|
|
191
|
+
return import_react5.default.forwardRef(
|
|
192
|
+
function CreateComponent(props, ref) {
|
|
193
|
+
return import_react5.default.createElement(tag, __spreadProps(__spreadValues({}, props), { ref }));
|
|
194
|
+
}
|
|
195
|
+
);
|
|
196
|
+
}
|
|
197
|
+
|
|
198
|
+
// src/useIsomorphicLayoutEffect.ts
|
|
199
|
+
var import_react6 = __toESM(require("react"));
|
|
200
|
+
var CAN_USE_DOM = typeof window !== "undefined" && window.document !== void 0 && window.document.createElement !== void 0;
|
|
201
|
+
var useIsomorphicLayoutEffect = CAN_USE_DOM ? import_react6.default.useLayoutEffect : import_react6.default.useEffect;
|
|
202
|
+
|
|
203
|
+
// src/useOnClickOutside.ts
|
|
204
|
+
var import_react7 = __toESM(require("react"));
|
|
205
|
+
var canUsePassiveEvents = () => {
|
|
206
|
+
if (typeof window === "undefined" || typeof window.addEventListener !== "function")
|
|
207
|
+
return false;
|
|
208
|
+
let passive = false;
|
|
209
|
+
const options = Object.defineProperty({}, "passive", {
|
|
210
|
+
// eslint-disable-next-line getter-return
|
|
211
|
+
get() {
|
|
212
|
+
passive = true;
|
|
213
|
+
}
|
|
214
|
+
});
|
|
215
|
+
const noop = () => null;
|
|
216
|
+
window.addEventListener("test", noop, options);
|
|
217
|
+
window.removeEventListener("test", noop, options);
|
|
218
|
+
return passive;
|
|
219
|
+
};
|
|
220
|
+
var DEFAULT_IGNORE_CLASS = "ignore-onclickoutside";
|
|
221
|
+
var checkClass = (el, cl) => {
|
|
222
|
+
var _a;
|
|
223
|
+
return (_a = el.classList) == null ? void 0 : _a.contains(cl);
|
|
224
|
+
};
|
|
225
|
+
var hasIgnoreClass = (e, ignoreClass) => {
|
|
226
|
+
let el = e.target || e;
|
|
227
|
+
while (el) {
|
|
228
|
+
if (Array.isArray(ignoreClass)) {
|
|
229
|
+
if (ignoreClass.some((c) => checkClass(el, c)))
|
|
230
|
+
return true;
|
|
231
|
+
} else if (checkClass(el, ignoreClass)) {
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
el = el.parentElement;
|
|
235
|
+
}
|
|
236
|
+
return false;
|
|
237
|
+
};
|
|
238
|
+
var clickedOnScrollbar = (e) => document.documentElement.clientWidth <= e.clientX || document.documentElement.clientHeight <= e.clientY;
|
|
239
|
+
var getEventOptions = (type) => type.includes("touch") && canUsePassiveEvents() ? { passive: true } : false;
|
|
240
|
+
var useOnClickOutside = (callback, {
|
|
241
|
+
refs: refsOpt,
|
|
242
|
+
disabled,
|
|
243
|
+
eventTypes = ["mousedown", "touchstart"],
|
|
244
|
+
excludeScrollbar,
|
|
245
|
+
ignoreClass = DEFAULT_IGNORE_CLASS,
|
|
246
|
+
detectIFrame = true
|
|
247
|
+
} = {}) => {
|
|
248
|
+
const [refsState, setRefsState] = import_react7.default.useState([]);
|
|
249
|
+
const callbackRef = import_react7.default.useRef(callback);
|
|
250
|
+
callbackRef.current = callback;
|
|
251
|
+
const ref = import_react7.default.useCallback(
|
|
252
|
+
(el) => setRefsState((prevState) => [...prevState, { current: el }]),
|
|
253
|
+
[]
|
|
254
|
+
);
|
|
255
|
+
import_react7.default.useEffect(
|
|
256
|
+
() => {
|
|
257
|
+
if (!(refsOpt == null ? void 0 : refsOpt.length) && refsState.length === 0)
|
|
258
|
+
return;
|
|
259
|
+
const getEls = () => {
|
|
260
|
+
const els = [];
|
|
261
|
+
(refsOpt || refsState).forEach(
|
|
262
|
+
({ current }) => current && els.push(current)
|
|
263
|
+
);
|
|
264
|
+
return els;
|
|
265
|
+
};
|
|
266
|
+
const handler = (e) => {
|
|
267
|
+
if (!hasIgnoreClass(e, ignoreClass) && !(excludeScrollbar && clickedOnScrollbar(e)) && getEls().every((el) => !el.contains(e.target)))
|
|
268
|
+
callbackRef.current(e);
|
|
269
|
+
};
|
|
270
|
+
const blurHandler = (e) => (
|
|
271
|
+
// On firefox the iframe becomes document.activeElement in the next event loop
|
|
272
|
+
setTimeout(() => {
|
|
273
|
+
const { activeElement } = document;
|
|
274
|
+
if ((activeElement == null ? void 0 : activeElement.tagName) === "IFRAME" && !hasIgnoreClass(activeElement, ignoreClass) && !getEls().includes(activeElement))
|
|
275
|
+
callbackRef.current(e);
|
|
276
|
+
}, 0)
|
|
277
|
+
);
|
|
278
|
+
const removeEventListener = () => {
|
|
279
|
+
eventTypes.forEach(
|
|
280
|
+
(type) => (
|
|
281
|
+
// @ts-ignore
|
|
282
|
+
document.removeEventListener(type, handler, getEventOptions(type))
|
|
283
|
+
)
|
|
284
|
+
);
|
|
285
|
+
if (detectIFrame)
|
|
286
|
+
window.removeEventListener("blur", blurHandler);
|
|
287
|
+
};
|
|
288
|
+
if (disabled) {
|
|
289
|
+
removeEventListener();
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
eventTypes.forEach(
|
|
293
|
+
(type) => document.addEventListener(type, handler, getEventOptions(type))
|
|
294
|
+
);
|
|
295
|
+
if (detectIFrame)
|
|
296
|
+
window.addEventListener("blur", blurHandler);
|
|
297
|
+
return () => removeEventListener();
|
|
298
|
+
},
|
|
299
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
300
|
+
[
|
|
301
|
+
refsState,
|
|
302
|
+
ignoreClass,
|
|
303
|
+
excludeScrollbar,
|
|
304
|
+
disabled,
|
|
305
|
+
detectIFrame,
|
|
306
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
307
|
+
JSON.stringify(eventTypes)
|
|
308
|
+
]
|
|
309
|
+
);
|
|
310
|
+
return ref;
|
|
311
|
+
};
|
|
312
|
+
|
|
313
|
+
// src/useStableMemo.ts
|
|
314
|
+
var import_react8 = __toESM(require("react"));
|
|
315
|
+
var useStableMemo = (producer, deps) => {
|
|
316
|
+
const [value, setValue] = import_react8.default.useState(producer);
|
|
317
|
+
import_react8.default.useLayoutEffect(() => {
|
|
318
|
+
setValue(producer);
|
|
319
|
+
}, deps);
|
|
320
|
+
return value;
|
|
321
|
+
};
|
|
322
|
+
|
|
323
|
+
// src/withProviders.tsx
|
|
324
|
+
var import_react9 = __toESM(require("react"));
|
|
325
|
+
var withProviders = (...providers) => (WrappedComponent) => (props) => providers.reduceRight(
|
|
326
|
+
(acc, prov) => {
|
|
327
|
+
let Provider = prov;
|
|
328
|
+
if (Array.isArray(prov)) {
|
|
329
|
+
[Provider] = prov;
|
|
330
|
+
return /* @__PURE__ */ import_react9.default.createElement(Provider, __spreadValues({}, prov[1]), acc);
|
|
331
|
+
}
|
|
332
|
+
return /* @__PURE__ */ import_react9.default.createElement(Provider, null, acc);
|
|
333
|
+
},
|
|
334
|
+
/* @__PURE__ */ import_react9.default.createElement(WrappedComponent, __spreadValues({}, props))
|
|
335
|
+
);
|
|
336
|
+
|
|
337
|
+
// src/withRef.tsx
|
|
338
|
+
var import_react10 = __toESM(require("react"));
|
|
339
|
+
function withRef(renderFunction) {
|
|
340
|
+
return import_react10.default.forwardRef(renderFunction);
|
|
341
|
+
}
|
|
342
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
343
|
+
0 && (module.exports = {
|
|
344
|
+
Box,
|
|
345
|
+
CAN_USE_DOM,
|
|
346
|
+
DEFAULT_IGNORE_CLASS,
|
|
347
|
+
PortalBody,
|
|
348
|
+
Text,
|
|
349
|
+
composeEventHandlers,
|
|
350
|
+
composeRefs,
|
|
351
|
+
createPrimitiveComponent,
|
|
352
|
+
createPrimitiveElement,
|
|
353
|
+
createSlotComponent,
|
|
354
|
+
useComposedRef,
|
|
355
|
+
useIsomorphicLayoutEffect,
|
|
356
|
+
useOnClickOutside,
|
|
357
|
+
useStableMemo,
|
|
358
|
+
withProviders,
|
|
359
|
+
withRef
|
|
360
|
+
});
|
|
361
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/createSlotComponent.tsx","../src/Box.tsx","../src/PortalBody.tsx","../src/Text.tsx","../src/composeEventHandlers.ts","../src/createPrimitiveComponent.tsx","../src/useComposedRef.ts","../src/createPrimitiveElement.tsx","../src/useIsomorphicLayoutEffect.ts","../src/useOnClickOutside.ts","../src/useStableMemo.ts","../src/withProviders.tsx","../src/withRef.tsx"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './Box';\nexport * from './PortalBody';\nexport * from './Text';\nexport * from './composeEventHandlers';\nexport * from './createPrimitiveComponent';\nexport * from './createPrimitiveElement';\nexport * from './createSlotComponent';\nexport * from './useComposedRef';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useOnClickOutside';\nexport * from './useStableMemo';\nexport * from './withProviders';\nexport * from './withRef';\n","import React from 'react';\nimport { Slot } from '@radix-ui/react-slot';\n\nexport const createSlotComponent = <\n T extends React.ElementType,\n P extends React.ComponentPropsWithoutRef<T>,\n>(\n element: T\n) =>\n // eslint-disable-next-line react/display-name\n React.forwardRef<\n any,\n P & {\n as?: React.ElementType;\n asChild?: boolean;\n }\n >(({ as, asChild = false, ...props }, ref) => {\n const Comp = asChild ? Slot : (as as T) || element;\n\n return <Comp ref={ref} {...props} />;\n });\n","import React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Box = createSlotComponent('div');\n\nexport type BoxProps = React.ComponentPropsWithRef<typeof Box>;\n","import React from 'react';\nimport ReactDOM from 'react-dom';\n\nexport type PortalBodyProps = { children: React.ReactNode; element?: Element };\n\nexport const PortalBody: ({\n children,\n element,\n}: PortalBodyProps) => React.ReactPortal = ({\n children,\n element,\n}: PortalBodyProps) => {\n const container =\n element || typeof window !== 'undefined' ? document.body : undefined;\n if (!container) return (<>{children}</>) as any;\n\n return ReactDOM.createPortal(children, element || document.body);\n};\n","import React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Text = createSlotComponent('span');\n\nexport type TextProps = React.ComponentPropsWithRef<typeof Text>;\n","/**\n * @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1\n */\nexport const composeEventHandlers =\n <E>(\n originalEventHandler?: (event: E) => void,\n ourEventHandler?: (event: E) => void,\n { checkForDefaultPrevented = true } = {}\n ) =>\n (event: E) => {\n originalEventHandler?.(event);\n\n if (\n checkForDefaultPrevented === false ||\n !(event as unknown as Event).defaultPrevented\n ) {\n return ourEventHandler?.(event);\n }\n };\n","/* eslint-disable react/display-name */\n\nimport React from 'react';\nimport { isDefined } from '@udecode/utils';\nimport { clsx } from 'clsx';\n\nimport { createSlotComponent } from './createSlotComponent';\nimport { useComposedRef } from './useComposedRef';\n\n/**\n * Primitive component factory. It uses hooks for managing\n * state and props, and forwards references to child components.\n * Component props:\n * - `asChild`: If true, the component will be rendered as a `Slot` {@link https://www.radix-ui.com/docs/primitives/utilities/slot}.\n * - `options`: Options passed to the state hook.\n * - `state`: Provide your state instead of using the state hook.\n * - `className`: Class name to be merged to the component.\n * - `style`: Style object to be merged to the component.\n * - `setProps`: Function to set props from the props hook.\n * - `...props`: Props to be passed to the component.\n * Props hook return value:\n * - `ref`: Reference to be forwarded to the component.\n * - `props`: Props to be passed to the component.\n * - `hidden`: If true, the component will not be rendered.\n *\n * @param {React.ElementType} element The base component or native HTML element.\n * @returns {function} A primitive component.\n *\n * @example\n *\n * const MyButton = createPrimitiveComponent(Button)({\n * stateHook: useButtonState,\n * propsHook: useButton\n * });\n */\nexport const createPrimitiveComponent = <\n T extends React.ElementType,\n P extends React.ComponentPropsWithoutRef<T>,\n>(\n element: T\n) => {\n const Comp = createSlotComponent<T, P>(element);\n\n return <SH extends (options: any) => any, PH extends (state: any) => any>({\n propsHook,\n stateHook,\n }: {\n stateHook?: SH;\n propsHook?: PH;\n } = {}) => {\n return React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n className?: string;\n style?: React.CSSProperties;\n options?: Parameters<SH>[0];\n state?: Parameters<PH>[0];\n setProps?: (hookProps: NonNullable<ReturnType<PH>['props']>) => P;\n } & P\n >(\n (\n {\n asChild,\n options,\n state: stateProp,\n className: classNameProp,\n getClassName,\n ...props\n },\n ref\n ) => {\n const state = isDefined(stateProp)\n ? stateProp\n : stateHook\n ? stateHook(options as any)\n : undefined;\n const {\n ref: hookRef,\n props: hookProps,\n hidden,\n } = propsHook\n ? propsHook(state)\n : { props: {}, hidden: false, ref: null };\n\n const _ref = useComposedRef(ref, hookRef);\n const className =\n isDefined(hookProps?.className) || isDefined(classNameProp)\n ? clsx(hookProps?.className, classNameProp)\n : undefined;\n const style =\n hookProps?.style || props.style\n ? { ...hookProps?.style, ...props.style }\n : undefined;\n\n if (!asChild && hidden) return null;\n\n return (\n <Comp\n ref={_ref}\n asChild={asChild}\n {...hookProps}\n className={className}\n style={style}\n {...props}\n {...(props.setProps?.(hookProps ?? {}) ?? {})}\n />\n );\n }\n );\n };\n};\n","import React from 'react';\n\ntype PossibleRef<T> = React.Ref<T> | undefined;\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and React.RefObject(s)\n */\nconst setRef = <T>(ref: PossibleRef<T>, value: T) => {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref !== null && ref !== undefined) {\n (ref as React.MutableRefObject<T>).current = value;\n }\n};\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and React.RefObject(s)\n */\nexport const composeRefs =\n <T>(...refs: PossibleRef<T>[]) =>\n (node: T) =>\n refs.forEach((ref) => setRef(ref, node));\n\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and React.RefObject(s)\n */\nexport const useComposedRef = <T>(...refs: PossibleRef<T>[]) => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback(composeRefs(...refs), refs);\n};\n","import React from 'react';\n\nexport function createPrimitiveElement<T extends keyof HTMLElementTagNameMap>(\n tag: T\n) {\n return React.forwardRef<HTMLElementTagNameMap[T], JSX.IntrinsicElements[T]>(\n function CreateComponent(props, ref) {\n return React.createElement(tag, { ...props, ref });\n }\n );\n}\n","import React from 'react';\n\nexport const CAN_USE_DOM =\n typeof window !== 'undefined' &&\n window.document !== undefined &&\n window.document.createElement !== undefined;\n\n/**\n * Prevent warning on SSR by falling back to React.useEffect when DOM isn't available\n */\nexport const useIsomorphicLayoutEffect = CAN_USE_DOM\n ? React.useLayoutEffect\n : React.useEffect;\n","import React from 'react';\n\nconst canUsePassiveEvents = (): boolean => {\n if (\n typeof window === 'undefined' ||\n typeof window.addEventListener !== 'function'\n )\n return false;\n\n let passive = false;\n const options = Object.defineProperty({}, 'passive', {\n // eslint-disable-next-line getter-return\n get() {\n passive = true;\n },\n });\n const noop = () => null;\n\n window.addEventListener('test', noop, options);\n window.removeEventListener('test', noop, options);\n\n return passive;\n};\n\nexport const DEFAULT_IGNORE_CLASS = 'ignore-onclickoutside';\n\nexport interface UseOnClickOutsideCallback<T extends Event = Event> {\n (event: T): void;\n}\ntype El = HTMLElement;\ntype Refs = React.RefObject<El>[];\nexport interface UseOnClickOutsideOptions {\n refs?: Refs;\n disabled?: boolean;\n eventTypes?: string[];\n excludeScrollbar?: boolean;\n ignoreClass?: string | string[];\n detectIFrame?: boolean;\n}\n\nexport interface UseOnClickOutsideReturn {\n (element: El | null): void;\n}\n\nconst checkClass = (el: HTMLElement, cl: string): boolean =>\n el.classList?.contains(cl);\n\nconst hasIgnoreClass = (e: any, ignoreClass: string | string[]): boolean => {\n let el = e.target || e;\n\n while (el) {\n if (Array.isArray(ignoreClass)) {\n // eslint-disable-next-line no-loop-func\n if (ignoreClass.some((c) => checkClass(el, c))) return true;\n } else if (checkClass(el, ignoreClass)) {\n return true;\n }\n\n el = el.parentElement;\n }\n\n return false;\n};\n\nconst clickedOnScrollbar = (e: MouseEvent): boolean =>\n document.documentElement.clientWidth <= e.clientX ||\n document.documentElement.clientHeight <= e.clientY;\n\nconst getEventOptions = (type: string): { passive: boolean } | boolean =>\n type.includes('touch') && canUsePassiveEvents() ? { passive: true } : false;\n\nexport const useOnClickOutside = (\n callback: UseOnClickOutsideCallback,\n {\n refs: refsOpt,\n disabled,\n eventTypes = ['mousedown', 'touchstart'],\n excludeScrollbar,\n ignoreClass = DEFAULT_IGNORE_CLASS,\n detectIFrame = true,\n }: UseOnClickOutsideOptions = {}\n): UseOnClickOutsideReturn => {\n const [refsState, setRefsState] = React.useState<Refs>([]);\n const callbackRef = React.useRef(callback);\n callbackRef.current = callback;\n\n const ref: UseOnClickOutsideReturn = React.useCallback(\n (el) => setRefsState((prevState) => [...prevState, { current: el }]),\n []\n );\n\n React.useEffect(\n () => {\n if (!refsOpt?.length && refsState.length === 0) return;\n\n const getEls = () => {\n const els: El[] = [];\n (refsOpt || refsState).forEach(\n ({ current }) => current && els.push(current)\n );\n return els;\n };\n\n const handler = (e: any) => {\n if (\n !hasIgnoreClass(e, ignoreClass) &&\n !(excludeScrollbar && clickedOnScrollbar(e)) &&\n getEls().every((el) => !el.contains(e.target))\n )\n callbackRef.current(e);\n };\n\n const blurHandler = (e: FocusEvent) =>\n // On firefox the iframe becomes document.activeElement in the next event loop\n setTimeout(() => {\n const { activeElement } = document;\n\n if (\n activeElement?.tagName === 'IFRAME' &&\n !hasIgnoreClass(activeElement, ignoreClass) &&\n !getEls().includes(activeElement as HTMLIFrameElement)\n )\n callbackRef.current(e);\n }, 0);\n\n const removeEventListener = () => {\n eventTypes.forEach((type) =>\n // @ts-ignore\n document.removeEventListener(type, handler, getEventOptions(type))\n );\n\n if (detectIFrame) window.removeEventListener('blur', blurHandler);\n };\n\n if (disabled) {\n removeEventListener();\n return;\n }\n\n eventTypes.forEach((type) =>\n document.addEventListener(type, handler, getEventOptions(type))\n );\n\n if (detectIFrame) window.addEventListener('blur', blurHandler);\n\n // eslint-disable-next-line consistent-return\n return () => removeEventListener();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n refsState,\n ignoreClass,\n excludeScrollbar,\n disabled,\n detectIFrame,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n JSON.stringify(eventTypes),\n ]\n );\n\n return ref;\n};\n","import React from 'react';\n\nexport const useStableMemo = <T>(\n producer: () => T,\n deps?: React.DependencyList\n): T => {\n const [value, setValue] = React.useState(producer);\n\n React.useLayoutEffect(() => {\n setValue(producer);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return value;\n};\n","import React from 'react';\n\n/**\n * Wrap a component into multiple providers.\n * If there are any props that you want a provider to receive,\n * you can simply pass an array.\n */\nexport const withProviders =\n (...providers: any[]) =>\n <T,>(WrappedComponent: React.FC<T>) =>\n (props: T) =>\n providers.reduceRight(\n (acc, prov) => {\n let Provider = prov;\n if (Array.isArray(prov)) {\n [Provider] = prov;\n return <Provider {...prov[1]}>{acc}</Provider>;\n }\n\n return <Provider>{acc}</Provider>;\n },\n <WrappedComponent {...(props as any)} />\n );\n","import React from 'react';\n\n/**\n * Shorter alternative to `React.forwardRef`.\n * @generic1 Component type or element type\n * @generic2 Extended prop types\n */\nexport function withRef<\n T extends keyof HTMLElementTagNameMap | React.ComponentType<object>,\n E = {},\n>(\n renderFunction: React.ForwardRefRenderFunction<\n React.ElementRef<T>,\n React.ComponentPropsWithoutRef<T> & E\n >\n) {\n return React.forwardRef(renderFunction);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAClB,wBAAqB;AAEd,IAAM,sBAAsB,CAIjC;AAAA;AAAA,EAGA,aAAAA,QAAM,WAMJ,CAAC,IAAmC,QAAQ;AAA3C,iBAAE,MAAI,UAAU,MAhBrB,IAgBK,IAA0B,kBAA1B,IAA0B,CAAxB,MAAI;AACP,UAAM,OAAO,UAAU,yBAAQ,MAAY;AAE3C,WAAO,6BAAAA,QAAA,cAAC,uBAAK,OAAc,MAAO;AAAA,EACpC,CAAC;AAAA;;;AChBI,IAAM,MAAM,oBAAoB,KAAK;;;ACJ5C,IAAAC,gBAAkB;AAClB,uBAAqB;AAId,IAAM,aAG8B,CAAC;AAAA,EAC1C;AAAA,EACA;AACF,MAAuB;AACrB,QAAM,YACJ,WAAW,OAAO,WAAW,cAAc,SAAS,OAAO;AAC7D,MAAI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A;AAAA,MAEA,KAAK,UAAU,UAAU;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO;AACT;;;ACjKA,IAAAC,gBAAkB;AAEX,IAAM,gBAAgB,CAC3B,UACA,SACM;AACN,QAAM,CAAC,OAAO,QAAQ,IAAI,cAAAC,QAAM,SAAS,QAAQ;AAEjD,gBAAAA,QAAM,gBAAgB,MAAM;AAC1B,aAAS,QAAQ;AAAA,EAEnB,GAAG,IAAI;AAEP,SAAO;AACT;;;ACdA,IAAAC,gBAAkB;AAOX,IAAM,gBACX,IAAI,cACJ,CAAK,qBACL,CAAC,UACC,UAAU;AAAA,EACR,CAAC,KAAK,SAAS;AACb,QAAI,WAAW;AACf,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,OAAC,QAAQ,IAAI;AACb,aAAO,8BAAAC,QAAA,cAAC,6BAAa,KAAK,CAAC,IAAI,GAAI;AAAA,IACrC;AAEA,WAAO,8BAAAA,QAAA,cAAC,gBAAU,GAAI;AAAA,EACxB;AAAA,EACA,8BAAAA,QAAA,cAAC,qCAAsB,MAAe;AACxC;;;ACtBJ,IAAAC,iBAAkB;AAOX,SAAS,QAId,gBAIA;AACA,SAAO,eAAAC,QAAM,WAAW,cAAc;AACxC;","names":["React","import_react","React","ReactDOM","import_react","import_react","React","React","_a","_b","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React"]}
|
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,312 @@
|
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __defProps = Object.defineProperties;
|
|
3
|
+
var __getOwnPropDescs = Object.getOwnPropertyDescriptors;
|
|
4
|
+
var __getOwnPropSymbols = Object.getOwnPropertySymbols;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __propIsEnum = Object.prototype.propertyIsEnumerable;
|
|
7
|
+
var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
|
|
8
|
+
var __spreadValues = (a, b) => {
|
|
9
|
+
for (var prop in b || (b = {}))
|
|
10
|
+
if (__hasOwnProp.call(b, prop))
|
|
11
|
+
__defNormalProp(a, prop, b[prop]);
|
|
12
|
+
if (__getOwnPropSymbols)
|
|
13
|
+
for (var prop of __getOwnPropSymbols(b)) {
|
|
14
|
+
if (__propIsEnum.call(b, prop))
|
|
15
|
+
__defNormalProp(a, prop, b[prop]);
|
|
16
|
+
}
|
|
17
|
+
return a;
|
|
18
|
+
};
|
|
19
|
+
var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
|
|
20
|
+
var __objRest = (source, exclude) => {
|
|
21
|
+
var target = {};
|
|
22
|
+
for (var prop in source)
|
|
23
|
+
if (__hasOwnProp.call(source, prop) && exclude.indexOf(prop) < 0)
|
|
24
|
+
target[prop] = source[prop];
|
|
25
|
+
if (source != null && __getOwnPropSymbols)
|
|
26
|
+
for (var prop of __getOwnPropSymbols(source)) {
|
|
27
|
+
if (exclude.indexOf(prop) < 0 && __propIsEnum.call(source, prop))
|
|
28
|
+
target[prop] = source[prop];
|
|
29
|
+
}
|
|
30
|
+
return target;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
// src/createSlotComponent.tsx
|
|
34
|
+
import React from "react";
|
|
35
|
+
import { Slot } from "@radix-ui/react-slot";
|
|
36
|
+
var createSlotComponent = (element) => (
|
|
37
|
+
// eslint-disable-next-line react/display-name
|
|
38
|
+
React.forwardRef((_a, ref) => {
|
|
39
|
+
var _b = _a, { as, asChild = false } = _b, props = __objRest(_b, ["as", "asChild"]);
|
|
40
|
+
const Comp = asChild ? Slot : as || element;
|
|
41
|
+
return /* @__PURE__ */ React.createElement(Comp, __spreadValues({ ref }, props));
|
|
42
|
+
})
|
|
43
|
+
);
|
|
44
|
+
|
|
45
|
+
// src/Box.tsx
|
|
46
|
+
var Box = createSlotComponent("div");
|
|
47
|
+
|
|
48
|
+
// src/PortalBody.tsx
|
|
49
|
+
import React2 from "react";
|
|
50
|
+
import ReactDOM from "react-dom";
|
|
51
|
+
var PortalBody = ({
|
|
52
|
+
children,
|
|
53
|
+
element
|
|
54
|
+
}) => {
|
|
55
|
+
const container = element || typeof window !== "undefined" ? document.body : void 0;
|
|
56
|
+
if (!container)
|
|
57
|
+
return /* @__PURE__ */ React2.createElement(React2.Fragment, null, children);
|
|
58
|
+
return ReactDOM.createPortal(children, element || document.body);
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
// src/Text.tsx
|
|
62
|
+
var Text = createSlotComponent("span");
|
|
63
|
+
|
|
64
|
+
// src/composeEventHandlers.ts
|
|
65
|
+
var composeEventHandlers = (originalEventHandler, ourEventHandler, { checkForDefaultPrevented = true } = {}) => (event) => {
|
|
66
|
+
originalEventHandler == null ? void 0 : originalEventHandler(event);
|
|
67
|
+
if (checkForDefaultPrevented === false || !event.defaultPrevented) {
|
|
68
|
+
return ourEventHandler == null ? void 0 : ourEventHandler(event);
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
// src/createPrimitiveComponent.tsx
|
|
73
|
+
import React4 from "react";
|
|
74
|
+
import { isDefined } from "@udecode/utils";
|
|
75
|
+
import { clsx } from "clsx";
|
|
76
|
+
|
|
77
|
+
// src/useComposedRef.ts
|
|
78
|
+
import React3 from "react";
|
|
79
|
+
var setRef = (ref, value) => {
|
|
80
|
+
if (typeof ref === "function") {
|
|
81
|
+
ref(value);
|
|
82
|
+
} else if (ref !== null && ref !== void 0) {
|
|
83
|
+
ref.current = value;
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
var composeRefs = (...refs) => (node) => refs.forEach((ref) => setRef(ref, node));
|
|
87
|
+
var useComposedRef = (...refs) => {
|
|
88
|
+
return React3.useCallback(composeRefs(...refs), refs);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/createPrimitiveComponent.tsx
|
|
92
|
+
var createPrimitiveComponent = (element) => {
|
|
93
|
+
const Comp = createSlotComponent(element);
|
|
94
|
+
return ({
|
|
95
|
+
propsHook,
|
|
96
|
+
stateHook
|
|
97
|
+
} = {}) => {
|
|
98
|
+
return React4.forwardRef(
|
|
99
|
+
(_a, ref) => {
|
|
100
|
+
var _b = _a, {
|
|
101
|
+
asChild,
|
|
102
|
+
options,
|
|
103
|
+
state: stateProp,
|
|
104
|
+
className: classNameProp,
|
|
105
|
+
getClassName
|
|
106
|
+
} = _b, props = __objRest(_b, [
|
|
107
|
+
"asChild",
|
|
108
|
+
"options",
|
|
109
|
+
"state",
|
|
110
|
+
"className",
|
|
111
|
+
"getClassName"
|
|
112
|
+
]);
|
|
113
|
+
var _a2, _b2;
|
|
114
|
+
const state = isDefined(stateProp) ? stateProp : stateHook ? stateHook(options) : void 0;
|
|
115
|
+
const {
|
|
116
|
+
ref: hookRef,
|
|
117
|
+
props: hookProps,
|
|
118
|
+
hidden
|
|
119
|
+
} = propsHook ? propsHook(state) : { props: {}, hidden: false, ref: null };
|
|
120
|
+
const _ref = useComposedRef(ref, hookRef);
|
|
121
|
+
const className = isDefined(hookProps == null ? void 0 : hookProps.className) || isDefined(classNameProp) ? clsx(hookProps == null ? void 0 : hookProps.className, classNameProp) : void 0;
|
|
122
|
+
const style = (hookProps == null ? void 0 : hookProps.style) || props.style ? __spreadValues(__spreadValues({}, hookProps == null ? void 0 : hookProps.style), props.style) : void 0;
|
|
123
|
+
if (!asChild && hidden)
|
|
124
|
+
return null;
|
|
125
|
+
return /* @__PURE__ */ React4.createElement(
|
|
126
|
+
Comp,
|
|
127
|
+
__spreadValues(__spreadValues(__spreadProps(__spreadValues({
|
|
128
|
+
ref: _ref,
|
|
129
|
+
asChild
|
|
130
|
+
}, hookProps), {
|
|
131
|
+
className,
|
|
132
|
+
style
|
|
133
|
+
}), props), (_b2 = (_a2 = props.setProps) == null ? void 0 : _a2.call(props, hookProps != null ? hookProps : {})) != null ? _b2 : {})
|
|
134
|
+
);
|
|
135
|
+
}
|
|
136
|
+
);
|
|
137
|
+
};
|
|
138
|
+
};
|
|
139
|
+
|
|
140
|
+
// src/createPrimitiveElement.tsx
|
|
141
|
+
import React5 from "react";
|
|
142
|
+
function createPrimitiveElement(tag) {
|
|
143
|
+
return React5.forwardRef(
|
|
144
|
+
function CreateComponent(props, ref) {
|
|
145
|
+
return React5.createElement(tag, __spreadProps(__spreadValues({}, props), { ref }));
|
|
146
|
+
}
|
|
147
|
+
);
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
// src/useIsomorphicLayoutEffect.ts
|
|
151
|
+
import React6 from "react";
|
|
152
|
+
var CAN_USE_DOM = typeof window !== "undefined" && window.document !== void 0 && window.document.createElement !== void 0;
|
|
153
|
+
var useIsomorphicLayoutEffect = CAN_USE_DOM ? React6.useLayoutEffect : React6.useEffect;
|
|
154
|
+
|
|
155
|
+
// src/useOnClickOutside.ts
|
|
156
|
+
import React7 from "react";
|
|
157
|
+
var canUsePassiveEvents = () => {
|
|
158
|
+
if (typeof window === "undefined" || typeof window.addEventListener !== "function")
|
|
159
|
+
return false;
|
|
160
|
+
let passive = false;
|
|
161
|
+
const options = Object.defineProperty({}, "passive", {
|
|
162
|
+
// eslint-disable-next-line getter-return
|
|
163
|
+
get() {
|
|
164
|
+
passive = true;
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
const noop = () => null;
|
|
168
|
+
window.addEventListener("test", noop, options);
|
|
169
|
+
window.removeEventListener("test", noop, options);
|
|
170
|
+
return passive;
|
|
171
|
+
};
|
|
172
|
+
var DEFAULT_IGNORE_CLASS = "ignore-onclickoutside";
|
|
173
|
+
var checkClass = (el, cl) => {
|
|
174
|
+
var _a;
|
|
175
|
+
return (_a = el.classList) == null ? void 0 : _a.contains(cl);
|
|
176
|
+
};
|
|
177
|
+
var hasIgnoreClass = (e, ignoreClass) => {
|
|
178
|
+
let el = e.target || e;
|
|
179
|
+
while (el) {
|
|
180
|
+
if (Array.isArray(ignoreClass)) {
|
|
181
|
+
if (ignoreClass.some((c) => checkClass(el, c)))
|
|
182
|
+
return true;
|
|
183
|
+
} else if (checkClass(el, ignoreClass)) {
|
|
184
|
+
return true;
|
|
185
|
+
}
|
|
186
|
+
el = el.parentElement;
|
|
187
|
+
}
|
|
188
|
+
return false;
|
|
189
|
+
};
|
|
190
|
+
var clickedOnScrollbar = (e) => document.documentElement.clientWidth <= e.clientX || document.documentElement.clientHeight <= e.clientY;
|
|
191
|
+
var getEventOptions = (type) => type.includes("touch") && canUsePassiveEvents() ? { passive: true } : false;
|
|
192
|
+
var useOnClickOutside = (callback, {
|
|
193
|
+
refs: refsOpt,
|
|
194
|
+
disabled,
|
|
195
|
+
eventTypes = ["mousedown", "touchstart"],
|
|
196
|
+
excludeScrollbar,
|
|
197
|
+
ignoreClass = DEFAULT_IGNORE_CLASS,
|
|
198
|
+
detectIFrame = true
|
|
199
|
+
} = {}) => {
|
|
200
|
+
const [refsState, setRefsState] = React7.useState([]);
|
|
201
|
+
const callbackRef = React7.useRef(callback);
|
|
202
|
+
callbackRef.current = callback;
|
|
203
|
+
const ref = React7.useCallback(
|
|
204
|
+
(el) => setRefsState((prevState) => [...prevState, { current: el }]),
|
|
205
|
+
[]
|
|
206
|
+
);
|
|
207
|
+
React7.useEffect(
|
|
208
|
+
() => {
|
|
209
|
+
if (!(refsOpt == null ? void 0 : refsOpt.length) && refsState.length === 0)
|
|
210
|
+
return;
|
|
211
|
+
const getEls = () => {
|
|
212
|
+
const els = [];
|
|
213
|
+
(refsOpt || refsState).forEach(
|
|
214
|
+
({ current }) => current && els.push(current)
|
|
215
|
+
);
|
|
216
|
+
return els;
|
|
217
|
+
};
|
|
218
|
+
const handler = (e) => {
|
|
219
|
+
if (!hasIgnoreClass(e, ignoreClass) && !(excludeScrollbar && clickedOnScrollbar(e)) && getEls().every((el) => !el.contains(e.target)))
|
|
220
|
+
callbackRef.current(e);
|
|
221
|
+
};
|
|
222
|
+
const blurHandler = (e) => (
|
|
223
|
+
// On firefox the iframe becomes document.activeElement in the next event loop
|
|
224
|
+
setTimeout(() => {
|
|
225
|
+
const { activeElement } = document;
|
|
226
|
+
if ((activeElement == null ? void 0 : activeElement.tagName) === "IFRAME" && !hasIgnoreClass(activeElement, ignoreClass) && !getEls().includes(activeElement))
|
|
227
|
+
callbackRef.current(e);
|
|
228
|
+
}, 0)
|
|
229
|
+
);
|
|
230
|
+
const removeEventListener = () => {
|
|
231
|
+
eventTypes.forEach(
|
|
232
|
+
(type) => (
|
|
233
|
+
// @ts-ignore
|
|
234
|
+
document.removeEventListener(type, handler, getEventOptions(type))
|
|
235
|
+
)
|
|
236
|
+
);
|
|
237
|
+
if (detectIFrame)
|
|
238
|
+
window.removeEventListener("blur", blurHandler);
|
|
239
|
+
};
|
|
240
|
+
if (disabled) {
|
|
241
|
+
removeEventListener();
|
|
242
|
+
return;
|
|
243
|
+
}
|
|
244
|
+
eventTypes.forEach(
|
|
245
|
+
(type) => document.addEventListener(type, handler, getEventOptions(type))
|
|
246
|
+
);
|
|
247
|
+
if (detectIFrame)
|
|
248
|
+
window.addEventListener("blur", blurHandler);
|
|
249
|
+
return () => removeEventListener();
|
|
250
|
+
},
|
|
251
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
252
|
+
[
|
|
253
|
+
refsState,
|
|
254
|
+
ignoreClass,
|
|
255
|
+
excludeScrollbar,
|
|
256
|
+
disabled,
|
|
257
|
+
detectIFrame,
|
|
258
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
259
|
+
JSON.stringify(eventTypes)
|
|
260
|
+
]
|
|
261
|
+
);
|
|
262
|
+
return ref;
|
|
263
|
+
};
|
|
264
|
+
|
|
265
|
+
// src/useStableMemo.ts
|
|
266
|
+
import React8 from "react";
|
|
267
|
+
var useStableMemo = (producer, deps) => {
|
|
268
|
+
const [value, setValue] = React8.useState(producer);
|
|
269
|
+
React8.useLayoutEffect(() => {
|
|
270
|
+
setValue(producer);
|
|
271
|
+
}, deps);
|
|
272
|
+
return value;
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/withProviders.tsx
|
|
276
|
+
import React9 from "react";
|
|
277
|
+
var withProviders = (...providers) => (WrappedComponent) => (props) => providers.reduceRight(
|
|
278
|
+
(acc, prov) => {
|
|
279
|
+
let Provider = prov;
|
|
280
|
+
if (Array.isArray(prov)) {
|
|
281
|
+
[Provider] = prov;
|
|
282
|
+
return /* @__PURE__ */ React9.createElement(Provider, __spreadValues({}, prov[1]), acc);
|
|
283
|
+
}
|
|
284
|
+
return /* @__PURE__ */ React9.createElement(Provider, null, acc);
|
|
285
|
+
},
|
|
286
|
+
/* @__PURE__ */ React9.createElement(WrappedComponent, __spreadValues({}, props))
|
|
287
|
+
);
|
|
288
|
+
|
|
289
|
+
// src/withRef.tsx
|
|
290
|
+
import React10 from "react";
|
|
291
|
+
function withRef(renderFunction) {
|
|
292
|
+
return React10.forwardRef(renderFunction);
|
|
293
|
+
}
|
|
294
|
+
export {
|
|
295
|
+
Box,
|
|
296
|
+
CAN_USE_DOM,
|
|
297
|
+
DEFAULT_IGNORE_CLASS,
|
|
298
|
+
PortalBody,
|
|
299
|
+
Text,
|
|
300
|
+
composeEventHandlers,
|
|
301
|
+
composeRefs,
|
|
302
|
+
createPrimitiveComponent,
|
|
303
|
+
createPrimitiveElement,
|
|
304
|
+
createSlotComponent,
|
|
305
|
+
useComposedRef,
|
|
306
|
+
useIsomorphicLayoutEffect,
|
|
307
|
+
useOnClickOutside,
|
|
308
|
+
useStableMemo,
|
|
309
|
+
withProviders,
|
|
310
|
+
withRef
|
|
311
|
+
};
|
|
312
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/createSlotComponent.tsx","../src/Box.tsx","../src/PortalBody.tsx","../src/Text.tsx","../src/composeEventHandlers.ts","../src/createPrimitiveComponent.tsx","../src/useComposedRef.ts","../src/createPrimitiveElement.tsx","../src/useIsomorphicLayoutEffect.ts","../src/useOnClickOutside.ts","../src/useStableMemo.ts","../src/withProviders.tsx","../src/withRef.tsx"],"sourcesContent":["import React from 'react';\nimport { Slot } from '@radix-ui/react-slot';\n\nexport const createSlotComponent = <\n T extends React.ElementType,\n P extends React.ComponentPropsWithoutRef<T>,\n>(\n element: T\n) =>\n // eslint-disable-next-line react/display-name\n React.forwardRef<\n any,\n P & {\n as?: React.ElementType;\n asChild?: boolean;\n }\n >(({ as, asChild = false, ...props }, ref) => {\n const Comp = asChild ? Slot : (as as T) || element;\n\n return <Comp ref={ref} {...props} />;\n });\n","import React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Box = createSlotComponent('div');\n\nexport type BoxProps = React.ComponentPropsWithRef<typeof Box>;\n","import React from 'react';\nimport ReactDOM from 'react-dom';\n\nexport type PortalBodyProps = { children: React.ReactNode; element?: Element };\n\nexport const PortalBody: ({\n children,\n element,\n}: PortalBodyProps) => React.ReactPortal = ({\n children,\n element,\n}: PortalBodyProps) => {\n const container =\n element || typeof window !== 'undefined' ? document.body : undefined;\n if (!container) return (<>{children}</>) as any;\n\n return ReactDOM.createPortal(children, element || document.body);\n};\n","import React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Text = createSlotComponent('span');\n\nexport type TextProps = React.ComponentPropsWithRef<typeof Text>;\n","/**\n * @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1\n */\nexport const composeEventHandlers =\n <E>(\n originalEventHandler?: (event: E) => void,\n ourEventHandler?: (event: E) => void,\n { checkForDefaultPrevented = true } = {}\n ) =>\n (event: E) => {\n originalEventHandler?.(event);\n\n if (\n checkForDefaultPrevented === false ||\n !(event as unknown as Event).defaultPrevented\n ) {\n return ourEventHandler?.(event);\n }\n };\n","/* eslint-disable react/display-name */\n\nimport React from 'react';\nimport { isDefined } from '@udecode/utils';\nimport { clsx } from 'clsx';\n\nimport { createSlotComponent } from './createSlotComponent';\nimport { useComposedRef } from './useComposedRef';\n\n/**\n * Primitive component factory. It uses hooks for managing\n * state and props, and forwards references to child components.\n * Component props:\n * - `asChild`: If true, the component will be rendered as a `Slot` {@link https://www.radix-ui.com/docs/primitives/utilities/slot}.\n * - `options`: Options passed to the state hook.\n * - `state`: Provide your state instead of using the state hook.\n * - `className`: Class name to be merged to the component.\n * - `style`: Style object to be merged to the component.\n * - `setProps`: Function to set props from the props hook.\n * - `...props`: Props to be passed to the component.\n * Props hook return value:\n * - `ref`: Reference to be forwarded to the component.\n * - `props`: Props to be passed to the component.\n * - `hidden`: If true, the component will not be rendered.\n *\n * @param {React.ElementType} element The base component or native HTML element.\n * @returns {function} A primitive component.\n *\n * @example\n *\n * const MyButton = createPrimitiveComponent(Button)({\n * stateHook: useButtonState,\n * propsHook: useButton\n * });\n */\nexport const createPrimitiveComponent = <\n T extends React.ElementType,\n P extends React.ComponentPropsWithoutRef<T>,\n>(\n element: T\n) => {\n const Comp = createSlotComponent<T, P>(element);\n\n return <SH extends (options: any) => any, PH extends (state: any) => any>({\n propsHook,\n stateHook,\n }: {\n stateHook?: SH;\n propsHook?: PH;\n } = {}) => {\n return React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n className?: string;\n style?: React.CSSProperties;\n options?: Parameters<SH>[0];\n state?: Parameters<PH>[0];\n setProps?: (hookProps: NonNullable<ReturnType<PH>['props']>) => P;\n } & P\n >(\n (\n {\n asChild,\n options,\n state: stateProp,\n className: classNameProp,\n getClassName,\n ...props\n },\n ref\n ) => {\n const state = isDefined(stateProp)\n ? stateProp\n : stateHook\n ? stateHook(options as any)\n : undefined;\n const {\n ref: hookRef,\n props: hookProps,\n hidden,\n } = propsHook\n ? propsHook(state)\n : { props: {}, hidden: false, ref: null };\n\n const _ref = useComposedRef(ref, hookRef);\n const className =\n isDefined(hookProps?.className) || isDefined(classNameProp)\n ? clsx(hookProps?.className, classNameProp)\n : undefined;\n const style =\n hookProps?.style || props.style\n ? { ...hookProps?.style, ...props.style }\n : undefined;\n\n if (!asChild && hidden) return null;\n\n return (\n <Comp\n ref={_ref}\n asChild={asChild}\n {...hookProps}\n className={className}\n style={style}\n {...props}\n {...(props.setProps?.(hookProps ?? {}) ?? {})}\n />\n );\n }\n );\n };\n};\n","import React from 'react';\n\ntype PossibleRef<T> = React.Ref<T> | undefined;\n\n/**\n * Set a given ref to a given value\n * This utility takes care of different types of refs: callback refs and React.RefObject(s)\n */\nconst setRef = <T>(ref: PossibleRef<T>, value: T) => {\n if (typeof ref === 'function') {\n ref(value);\n } else if (ref !== null && ref !== undefined) {\n (ref as React.MutableRefObject<T>).current = value;\n }\n};\n\n/**\n * A utility to compose multiple refs together\n * Accepts callback refs and React.RefObject(s)\n */\nexport const composeRefs =\n <T>(...refs: PossibleRef<T>[]) =>\n (node: T) =>\n refs.forEach((ref) => setRef(ref, node));\n\n/**\n * A custom hook that composes multiple refs\n * Accepts callback refs and React.RefObject(s)\n */\nexport const useComposedRef = <T>(...refs: PossibleRef<T>[]) => {\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback(composeRefs(...refs), refs);\n};\n","import React from 'react';\n\nexport function createPrimitiveElement<T extends keyof HTMLElementTagNameMap>(\n tag: T\n) {\n return React.forwardRef<HTMLElementTagNameMap[T], JSX.IntrinsicElements[T]>(\n function CreateComponent(props, ref) {\n return React.createElement(tag, { ...props, ref });\n }\n );\n}\n","import React from 'react';\n\nexport const CAN_USE_DOM =\n typeof window !== 'undefined' &&\n window.document !== undefined &&\n window.document.createElement !== undefined;\n\n/**\n * Prevent warning on SSR by falling back to React.useEffect when DOM isn't available\n */\nexport const useIsomorphicLayoutEffect = CAN_USE_DOM\n ? React.useLayoutEffect\n : React.useEffect;\n","import React from 'react';\n\nconst canUsePassiveEvents = (): boolean => {\n if (\n typeof window === 'undefined' ||\n typeof window.addEventListener !== 'function'\n )\n return false;\n\n let passive = false;\n const options = Object.defineProperty({}, 'passive', {\n // eslint-disable-next-line getter-return\n get() {\n passive = true;\n },\n });\n const noop = () => null;\n\n window.addEventListener('test', noop, options);\n window.removeEventListener('test', noop, options);\n\n return passive;\n};\n\nexport const DEFAULT_IGNORE_CLASS = 'ignore-onclickoutside';\n\nexport interface UseOnClickOutsideCallback<T extends Event = Event> {\n (event: T): void;\n}\ntype El = HTMLElement;\ntype Refs = React.RefObject<El>[];\nexport interface UseOnClickOutsideOptions {\n refs?: Refs;\n disabled?: boolean;\n eventTypes?: string[];\n excludeScrollbar?: boolean;\n ignoreClass?: string | string[];\n detectIFrame?: boolean;\n}\n\nexport interface UseOnClickOutsideReturn {\n (element: El | null): void;\n}\n\nconst checkClass = (el: HTMLElement, cl: string): boolean =>\n el.classList?.contains(cl);\n\nconst hasIgnoreClass = (e: any, ignoreClass: string | string[]): boolean => {\n let el = e.target || e;\n\n while (el) {\n if (Array.isArray(ignoreClass)) {\n // eslint-disable-next-line no-loop-func\n if (ignoreClass.some((c) => checkClass(el, c))) return true;\n } else if (checkClass(el, ignoreClass)) {\n return true;\n }\n\n el = el.parentElement;\n }\n\n return false;\n};\n\nconst clickedOnScrollbar = (e: MouseEvent): boolean =>\n document.documentElement.clientWidth <= e.clientX ||\n document.documentElement.clientHeight <= e.clientY;\n\nconst getEventOptions = (type: string): { passive: boolean } | boolean =>\n type.includes('touch') && canUsePassiveEvents() ? { passive: true } : false;\n\nexport const useOnClickOutside = (\n callback: UseOnClickOutsideCallback,\n {\n refs: refsOpt,\n disabled,\n eventTypes = ['mousedown', 'touchstart'],\n excludeScrollbar,\n ignoreClass = DEFAULT_IGNORE_CLASS,\n detectIFrame = true,\n }: UseOnClickOutsideOptions = {}\n): UseOnClickOutsideReturn => {\n const [refsState, setRefsState] = React.useState<Refs>([]);\n const callbackRef = React.useRef(callback);\n callbackRef.current = callback;\n\n const ref: UseOnClickOutsideReturn = React.useCallback(\n (el) => setRefsState((prevState) => [...prevState, { current: el }]),\n []\n );\n\n React.useEffect(\n () => {\n if (!refsOpt?.length && refsState.length === 0) return;\n\n const getEls = () => {\n const els: El[] = [];\n (refsOpt || refsState).forEach(\n ({ current }) => current && els.push(current)\n );\n return els;\n };\n\n const handler = (e: any) => {\n if (\n !hasIgnoreClass(e, ignoreClass) &&\n !(excludeScrollbar && clickedOnScrollbar(e)) &&\n getEls().every((el) => !el.contains(e.target))\n )\n callbackRef.current(e);\n };\n\n const blurHandler = (e: FocusEvent) =>\n // On firefox the iframe becomes document.activeElement in the next event loop\n setTimeout(() => {\n const { activeElement } = document;\n\n if (\n activeElement?.tagName === 'IFRAME' &&\n !hasIgnoreClass(activeElement, ignoreClass) &&\n !getEls().includes(activeElement as HTMLIFrameElement)\n )\n callbackRef.current(e);\n }, 0);\n\n const removeEventListener = () => {\n eventTypes.forEach((type) =>\n // @ts-ignore\n document.removeEventListener(type, handler, getEventOptions(type))\n );\n\n if (detectIFrame) window.removeEventListener('blur', blurHandler);\n };\n\n if (disabled) {\n removeEventListener();\n return;\n }\n\n eventTypes.forEach((type) =>\n document.addEventListener(type, handler, getEventOptions(type))\n );\n\n if (detectIFrame) window.addEventListener('blur', blurHandler);\n\n // eslint-disable-next-line consistent-return\n return () => removeEventListener();\n },\n // eslint-disable-next-line react-hooks/exhaustive-deps\n [\n refsState,\n ignoreClass,\n excludeScrollbar,\n disabled,\n detectIFrame,\n // eslint-disable-next-line react-hooks/exhaustive-deps\n JSON.stringify(eventTypes),\n ]\n );\n\n return ref;\n};\n","import React from 'react';\n\nexport const useStableMemo = <T>(\n producer: () => T,\n deps?: React.DependencyList\n): T => {\n const [value, setValue] = React.useState(producer);\n\n React.useLayoutEffect(() => {\n setValue(producer);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return value;\n};\n","import React from 'react';\n\n/**\n * Wrap a component into multiple providers.\n * If there are any props that you want a provider to receive,\n * you can simply pass an array.\n */\nexport const withProviders =\n (...providers: any[]) =>\n <T,>(WrappedComponent: React.FC<T>) =>\n (props: T) =>\n providers.reduceRight(\n (acc, prov) => {\n let Provider = prov;\n if (Array.isArray(prov)) {\n [Provider] = prov;\n return <Provider {...prov[1]}>{acc}</Provider>;\n }\n\n return <Provider>{acc}</Provider>;\n },\n <WrappedComponent {...(props as any)} />\n );\n","import React from 'react';\n\n/**\n * Shorter alternative to `React.forwardRef`.\n * @generic1 Component type or element type\n * @generic2 Extended prop types\n */\nexport function withRef<\n T extends keyof HTMLElementTagNameMap | React.ComponentType<object>,\n E = {},\n>(\n renderFunction: React.ForwardRefRenderFunction<\n React.ElementRef<T>,\n React.ComponentPropsWithoutRef<T> & E\n >\n) {\n return React.forwardRef(renderFunction);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,OAAO,WAAW;AAClB,SAAS,YAAY;AAEd,IAAM,sBAAsB,CAIjC;AAAA;AAAA,EAGA,MAAM,WAMJ,CAAC,IAAmC,QAAQ;AAA3C,iBAAE,MAAI,UAAU,MAhBrB,IAgBK,IAA0B,kBAA1B,IAA0B,CAAxB,MAAI;AACP,UAAM,OAAO,UAAU,OAAQ,MAAY;AAE3C,WAAO,oCAAC,uBAAK,OAAc,MAAO;AAAA,EACpC,CAAC;AAAA;;;AChBI,IAAM,MAAM,oBAAoB,KAAK;;;ACJ5C,OAAOA,YAAW;AAClB,OAAO,cAAc;AAId,IAAM,aAG8B,CAAC;AAAA,EAC1C;AAAA,EACA;AACF,MAAuB;AACrB,QAAM,YACJ,WAAW,OAAO,WAAW,cAAc,SAAS,OAAO;AAC7D,MAAI,CAAC;AAAW,WAAQ,gBAAAA,OAAA,cAAAA,OAAA,gBAAG,QAAS;AAEpC,SAAO,SAAS,aAAa,UAAU,WAAW,SAAS,IAAI;AACjE;;;ACbO,IAAM,OAAO,oBAAoB,MAAM;;;ACDvC,IAAM,uBACX,CACE,sBACA,iBACA,EAAE,2BAA2B,KAAK,IAAI,CAAC,MAEzC,CAAC,UAAa;AACZ,+DAAuB;AAEvB,MACE,6BAA6B,SAC7B,CAAE,MAA2B,kBAC7B;AACA,WAAO,mDAAkB;AAAA,EAC3B;AACF;;;AChBF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,MAAM,QAAQ,IAAI,GAAG;AACvB,OAAC,QAAQ,IAAI;AACb,aAAO,gBAAAC,OAAA,cAAC,6BAAa,KAAK,CAAC,IAAI,GAAI;AAAA,IACrC;AAEA,WAAO,gBAAAA,OAAA,cAAC,gBAAU,GAAI;AAAA,EACxB;AAAA,EACA,gBAAAA,OAAA,cAAC,qCAAsB,MAAe;AACxC;;;ACtBJ,OAAOC,aAAW;AAOX,SAAS,QAId,gBAIA;AACA,SAAOA,QAAM,WAAW,cAAc;AACxC;","names":["React","React","React","React","_a","_b","React","React","React","React","React","React","React","React"]}
|
package/package.json
ADDED
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@udecode/react-utils",
|
|
3
|
+
"version": "29.0.0",
|
|
4
|
+
"description": "Udecode React utils",
|
|
5
|
+
"license": "MIT",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/udecode/plate.git",
|
|
9
|
+
"directory": "packages/react-utils"
|
|
10
|
+
},
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/udecode/plate/issues"
|
|
13
|
+
},
|
|
14
|
+
"sideEffects": false,
|
|
15
|
+
"main": "dist/index.js",
|
|
16
|
+
"module": "dist/index.mjs",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist/**/*"
|
|
20
|
+
],
|
|
21
|
+
"exports": {
|
|
22
|
+
".": {
|
|
23
|
+
"types": "./dist/index.d.ts",
|
|
24
|
+
"import": "./dist/index.mjs",
|
|
25
|
+
"module": "./dist/index.mjs",
|
|
26
|
+
"require": "./dist/index.js"
|
|
27
|
+
}
|
|
28
|
+
},
|
|
29
|
+
"scripts": {
|
|
30
|
+
"build": "yarn p:build",
|
|
31
|
+
"build:watch": "yarn p:build:watch",
|
|
32
|
+
"brl": "yarn p:brl",
|
|
33
|
+
"clean": "yarn p:clean",
|
|
34
|
+
"lint": "yarn p:lint",
|
|
35
|
+
"lint:fix": "yarn p:lint:fix",
|
|
36
|
+
"test": "yarn p:test",
|
|
37
|
+
"test:watch": "yarn p:test:watch",
|
|
38
|
+
"typecheck": "yarn p:typecheck"
|
|
39
|
+
},
|
|
40
|
+
"dependencies": {
|
|
41
|
+
"@radix-ui/react-slot": "^1.0.2",
|
|
42
|
+
"@udecode/utils": "24.3.0",
|
|
43
|
+
"clsx": "^1.2.1"
|
|
44
|
+
},
|
|
45
|
+
"peerDependencies": {
|
|
46
|
+
"react": ">=16.8.0",
|
|
47
|
+
"react-dom": ">=16.8.0"
|
|
48
|
+
},
|
|
49
|
+
"keywords": [
|
|
50
|
+
"utils"
|
|
51
|
+
],
|
|
52
|
+
"publishConfig": {
|
|
53
|
+
"access": "public"
|
|
54
|
+
}
|
|
55
|
+
}
|