@udecode/react-utils 44.0.1 → 46.0.9
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.mts +13 -2
- package/dist/index.d.ts +13 -2
- package/dist/index.js +19 -9
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +18 -9
- package/dist/index.mjs.map +1 -1
- package/package.json +1 -1
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { JSX } from 'react';
|
|
1
|
+
import React, { JSX, DependencyList } from 'react';
|
|
2
2
|
|
|
3
3
|
declare const Box: React.ForwardRefExoticComponent<{
|
|
4
4
|
as?: React.ElementType;
|
|
@@ -120,6 +120,17 @@ type El = HTMLElement;
|
|
|
120
120
|
type Refs = React.RefObject<El | null>[];
|
|
121
121
|
declare const useOnClickOutside: (callback: UseOnClickOutsideCallback, { detectIFrame, disabled, eventTypes, excludeScrollbar, ignoreClass, refs: refsOpt, }?: UseOnClickOutsideOptions) => UseOnClickOutsideReturn;
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Create a stable version of a function that can be used in dependency arrays
|
|
125
|
+
* without causing hooks like useEffect to re-run if the function changes.
|
|
126
|
+
* Calling the returned function always calls the most recent version of the
|
|
127
|
+
* function that was passed to useStableFn.
|
|
128
|
+
*
|
|
129
|
+
* If you do want the function to be replaced when certain dependency values
|
|
130
|
+
* change, include those values in the dependency array of useStableFn.
|
|
131
|
+
*/
|
|
132
|
+
declare const useStableFn: <A extends unknown[], R>(fn: (...args: A) => R, deps?: DependencyList) => (...args: A) => R;
|
|
133
|
+
|
|
123
134
|
declare const useStableMemo: <T>(producer: () => T, deps?: React.DependencyList) => T;
|
|
124
135
|
|
|
125
136
|
/**
|
|
@@ -141,4 +152,4 @@ type InferElementRef<T> = T extends ElementType<any> ? T extends keyof JSX.Intri
|
|
|
141
152
|
*/
|
|
142
153
|
declare function withRef<T extends ElementType, P = {}>(renderFunction: React.ForwardRefRenderFunction<InferElementRef<T>, React.ComponentPropsWithoutRef<T> & P>): ForwardRefComponent<InferElementRef<T>, React.ComponentPropsWithoutRef<T> & P>;
|
|
143
154
|
|
|
144
|
-
export { Box, type BoxProps, CAN_USE_DOM, DEFAULT_IGNORE_CLASS, MemoizedChildren, PortalBody, type PortalBodyProps, Text, type TextProps, type UseOnClickOutsideCallback, type UseOnClickOutsideOptions, type UseOnClickOutsideReturn, composeEventHandlers, composeRefs, createPrimitiveComponent, createPrimitiveElement, createSlotComponent, useComposedRef, useEffectOnce, useIsomorphicLayoutEffect, useMemoOnce, useMemoizedSelector, useOnClickOutside, useStableMemo, withProviders, withRef };
|
|
155
|
+
export { Box, type BoxProps, CAN_USE_DOM, DEFAULT_IGNORE_CLASS, MemoizedChildren, PortalBody, type PortalBodyProps, Text, type TextProps, type UseOnClickOutsideCallback, type UseOnClickOutsideOptions, type UseOnClickOutsideReturn, composeEventHandlers, composeRefs, createPrimitiveComponent, createPrimitiveElement, createSlotComponent, useComposedRef, useEffectOnce, useIsomorphicLayoutEffect, useMemoOnce, useMemoizedSelector, useOnClickOutside, useStableFn, useStableMemo, withProviders, withRef };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { JSX } from 'react';
|
|
1
|
+
import React, { JSX, DependencyList } from 'react';
|
|
2
2
|
|
|
3
3
|
declare const Box: React.ForwardRefExoticComponent<{
|
|
4
4
|
as?: React.ElementType;
|
|
@@ -120,6 +120,17 @@ type El = HTMLElement;
|
|
|
120
120
|
type Refs = React.RefObject<El | null>[];
|
|
121
121
|
declare const useOnClickOutside: (callback: UseOnClickOutsideCallback, { detectIFrame, disabled, eventTypes, excludeScrollbar, ignoreClass, refs: refsOpt, }?: UseOnClickOutsideOptions) => UseOnClickOutsideReturn;
|
|
122
122
|
|
|
123
|
+
/**
|
|
124
|
+
* Create a stable version of a function that can be used in dependency arrays
|
|
125
|
+
* without causing hooks like useEffect to re-run if the function changes.
|
|
126
|
+
* Calling the returned function always calls the most recent version of the
|
|
127
|
+
* function that was passed to useStableFn.
|
|
128
|
+
*
|
|
129
|
+
* If you do want the function to be replaced when certain dependency values
|
|
130
|
+
* change, include those values in the dependency array of useStableFn.
|
|
131
|
+
*/
|
|
132
|
+
declare const useStableFn: <A extends unknown[], R>(fn: (...args: A) => R, deps?: DependencyList) => (...args: A) => R;
|
|
133
|
+
|
|
123
134
|
declare const useStableMemo: <T>(producer: () => T, deps?: React.DependencyList) => T;
|
|
124
135
|
|
|
125
136
|
/**
|
|
@@ -141,4 +152,4 @@ type InferElementRef<T> = T extends ElementType<any> ? T extends keyof JSX.Intri
|
|
|
141
152
|
*/
|
|
142
153
|
declare function withRef<T extends ElementType, P = {}>(renderFunction: React.ForwardRefRenderFunction<InferElementRef<T>, React.ComponentPropsWithoutRef<T> & P>): ForwardRefComponent<InferElementRef<T>, React.ComponentPropsWithoutRef<T> & P>;
|
|
143
154
|
|
|
144
|
-
export { Box, type BoxProps, CAN_USE_DOM, DEFAULT_IGNORE_CLASS, MemoizedChildren, PortalBody, type PortalBodyProps, Text, type TextProps, type UseOnClickOutsideCallback, type UseOnClickOutsideOptions, type UseOnClickOutsideReturn, composeEventHandlers, composeRefs, createPrimitiveComponent, createPrimitiveElement, createSlotComponent, useComposedRef, useEffectOnce, useIsomorphicLayoutEffect, useMemoOnce, useMemoizedSelector, useOnClickOutside, useStableMemo, withProviders, withRef };
|
|
155
|
+
export { Box, type BoxProps, CAN_USE_DOM, DEFAULT_IGNORE_CLASS, MemoizedChildren, PortalBody, type PortalBodyProps, Text, type TextProps, type UseOnClickOutsideCallback, type UseOnClickOutsideOptions, type UseOnClickOutsideReturn, composeEventHandlers, composeRefs, createPrimitiveComponent, createPrimitiveElement, createSlotComponent, useComposedRef, useEffectOnce, useIsomorphicLayoutEffect, useMemoOnce, useMemoizedSelector, useOnClickOutside, useStableFn, useStableMemo, withProviders, withRef };
|
package/dist/index.js
CHANGED
|
@@ -47,6 +47,7 @@ __export(index_exports, {
|
|
|
47
47
|
useMemoOnce: () => useMemoOnce,
|
|
48
48
|
useMemoizedSelector: () => useMemoizedSelector,
|
|
49
49
|
useOnClickOutside: () => useOnClickOutside,
|
|
50
|
+
useStableFn: () => useStableFn,
|
|
50
51
|
useStableMemo: () => useStableMemo,
|
|
51
52
|
withProviders: () => withProviders,
|
|
52
53
|
withRef: () => withRef
|
|
@@ -319,34 +320,42 @@ var useOnClickOutside = (callback, {
|
|
|
319
320
|
return ref;
|
|
320
321
|
};
|
|
321
322
|
|
|
322
|
-
// src/
|
|
323
|
+
// src/useStableFn.ts
|
|
323
324
|
var import_react12 = __toESM(require("react"));
|
|
325
|
+
var useStableFn = (fn, deps = []) => {
|
|
326
|
+
const fnRef = import_react12.default.useRef(fn);
|
|
327
|
+
fnRef.current = fn;
|
|
328
|
+
return import_react12.default.useCallback((...args) => fnRef.current(...args), deps);
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
// src/useStableMemo.ts
|
|
332
|
+
var import_react13 = __toESM(require("react"));
|
|
324
333
|
var useStableMemo = (producer, deps) => {
|
|
325
|
-
const [value, setValue] =
|
|
326
|
-
|
|
334
|
+
const [value, setValue] = import_react13.default.useState(producer);
|
|
335
|
+
import_react13.default.useLayoutEffect(() => {
|
|
327
336
|
setValue(producer);
|
|
328
337
|
}, deps);
|
|
329
338
|
return value;
|
|
330
339
|
};
|
|
331
340
|
|
|
332
341
|
// src/withProviders.tsx
|
|
333
|
-
var
|
|
342
|
+
var import_react14 = __toESM(require("react"));
|
|
334
343
|
var withProviders = (...providers) => (WrappedComponent) => (props) => providers.reduceRight(
|
|
335
344
|
(acc, prov) => {
|
|
336
345
|
let Provider = prov;
|
|
337
346
|
if (Array.isArray(prov)) {
|
|
338
347
|
[Provider] = prov;
|
|
339
|
-
return /* @__PURE__ */
|
|
348
|
+
return /* @__PURE__ */ import_react14.default.createElement(Provider, { ...prov[1] }, acc);
|
|
340
349
|
}
|
|
341
|
-
return /* @__PURE__ */
|
|
350
|
+
return /* @__PURE__ */ import_react14.default.createElement(Provider, null, acc);
|
|
342
351
|
},
|
|
343
|
-
/* @__PURE__ */
|
|
352
|
+
/* @__PURE__ */ import_react14.default.createElement(WrappedComponent, { ...props })
|
|
344
353
|
);
|
|
345
354
|
|
|
346
355
|
// src/withRef.tsx
|
|
347
|
-
var
|
|
356
|
+
var import_react15 = __toESM(require("react"));
|
|
348
357
|
function withRef(renderFunction) {
|
|
349
|
-
return
|
|
358
|
+
return import_react15.default.forwardRef(renderFunction);
|
|
350
359
|
}
|
|
351
360
|
// Annotate the CommonJS export names for ESM import in node:
|
|
352
361
|
0 && (module.exports = {
|
|
@@ -367,6 +376,7 @@ function withRef(renderFunction) {
|
|
|
367
376
|
useMemoOnce,
|
|
368
377
|
useMemoizedSelector,
|
|
369
378
|
useOnClickOutside,
|
|
379
|
+
useStableFn,
|
|
370
380
|
useStableMemo,
|
|
371
381
|
withProviders,
|
|
372
382
|
withRef
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/index.ts","../src/createSlotComponent.tsx","../src/Box.tsx","../src/MemoizedChildren.tsx","../src/PortalBody.tsx","../src/Text.tsx","../src/composeEventHandlers.ts","../src/createPrimitiveComponent.tsx","../src/useComposedRef.ts","../src/createPrimitiveElement.tsx","../src/useEffectOnce.ts","../src/useIsomorphicLayoutEffect.ts","../src/useMemoOnce.ts","../src/useMemoizedSelector.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 './MemoizedChildren';\nexport * from './PortalBody';\nexport * from './Text';\nexport * from './composeEventHandlers';\nexport * from './createPrimitiveComponent';\nexport * from './createPrimitiveElement';\nexport * from './createSlotComponent';\nexport * from './useComposedRef';\nexport * from './useEffectOnce';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMemoOnce';\nexport * from './useMemoizedSelector';\nexport * from './useOnClickOutside';\nexport * from './useStableMemo';\nexport * from './withProviders';\nexport * from './withRef';\n","import React from 'react';\n\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 React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n } & P\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 type 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';\n\nexport const MemoizedChildren = React.memo(\n ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n }\n);\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\n if (!container) return (<>{children}</>) as any;\n\n return ReactDOM.createPortal(children, element || document.body);\n};\n","import type React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Text = createSlotComponent('span');\n\nexport type TextProps = React.ComponentPropsWithRef<typeof Text>;\n","/** @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1 */\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","import React from 'react';\n\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 state and props, and\n * forwards references to child components. Component props:\n *\n * - `asChild`: If true, the component will be rendered as a `Slot`\n * {@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. 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 * @example\n * const MyButton = createPrimitiveComponent(Button)({\n * stateHook: useButtonState,\n * propsHook: useButton,\n * });\n *\n * @param {React.ElementType} element The base component or native HTML element.\n * @returns {function} A primitive component.\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 propsHook?: PH;\n stateHook?: SH;\n } = {}) => {\n return React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n className?: string;\n options?: Parameters<SH>[0];\n state?: Parameters<PH>[0];\n style?: React.CSSProperties;\n setProps?: (hookProps: NonNullable<ReturnType<PH>['props']>) => P;\n } & P\n >(\n (\n {\n asChild,\n className: classNameProp,\n getClassName,\n options,\n state: stateProp,\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 hidden,\n props: hookProps,\n ref: hookRef,\n } = propsHook\n ? propsHook(state)\n : { hidden: false, props: {}, 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 This utility takes care of different types\n * 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 Accepts callback refs and\n * 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 Accepts callback refs and\n * 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, { type JSX } 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 function useEffectOnce(\n effect: React.EffectCallback,\n deps: React.DependencyList\n) {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n\n React.useEffect(() => {\n const depsChanged = deps.some((dep, i) => dep !== prevDepsRef.current[i]);\n\n if (!initialized.current || depsChanged) {\n initialized.current = true;\n prevDepsRef.current = deps;\n effect();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n","import React from 'react';\n\nexport const CAN_USE_DOM =\n typeof window !== 'undefined' && window.document?.createElement !== undefined;\n\n/**\n * Prevent warning on SSR by falling back to React.useEffect when DOM isn't\n * available\n */\nexport const useIsomorphicLayoutEffect = CAN_USE_DOM\n ? React.useLayoutEffect\n : React.useEffect;\n","import React from 'react';\n\nexport function useMemoOnce<T>(\n factory: () => T,\n deps: React.DependencyList\n): T {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n const memoizedValueRef = React.useRef<T>(undefined);\n\n if (\n !initialized.current ||\n deps.some((dep, i) => dep !== prevDepsRef.current[i])\n ) {\n initialized.current = true;\n prevDepsRef.current = deps;\n memoizedValueRef.current = factory();\n }\n\n return memoizedValueRef.current!;\n}\n","import React from 'react';\n\n/**\n * Re-render only when the selector result changes.\n *\n * @param selector A function that derives a value from deps\n * @param deps Dependencies on which to run the selector\n * @param equalityFn Optional comparison function to detect changes in the\n * derived value\n */\nexport function useMemoizedSelector<R>(\n selector: () => R,\n deps: React.DependencyList,\n equalityFn: (a: R, b: R) => boolean = (a, b) => a === b\n) {\n // Initialize our state with the initial \"selected\" value.\n const [memoizedValue, setMemoizedValue] = React.useState<R>(() => selector());\n\n // Keep a ref of the previous value so we can compare in an effect.\n const previousValueRef = React.useRef<R>(memoizedValue);\n\n React.useEffect(() => {\n // Compute a new value by calling the selector.\n const newValue = selector();\n\n // If different, update state and the ref.\n if (!equalityFn(previousValueRef.current, newValue)) {\n setMemoizedValue(newValue);\n previousValueRef.current = newValue;\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return memoizedValue;\n}\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 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 type UseOnClickOutsideCallback<T extends Event = Event> = (\n event: T\n) => void;\n\nexport interface UseOnClickOutsideOptions {\n detectIFrame?: boolean;\n disabled?: boolean;\n eventTypes?: string[];\n excludeScrollbar?: boolean;\n ignoreClass?: string[] | string;\n refs?: Refs;\n}\n\nexport type UseOnClickOutsideReturn = (element: El | null) => void;\n\ntype El = HTMLElement;\n\ntype Refs = React.RefObject<El | null>[];\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 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 detectIFrame = true,\n disabled,\n eventTypes = ['mousedown', 'touchstart'],\n excludeScrollbar,\n ignoreClass = DEFAULT_IGNORE_CLASS,\n refs: refsOpt,\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\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 document.removeEventListener(\n type,\n handler,\n getEventOptions(type) as any\n )\n );\n\n if (detectIFrame) window.removeEventListener('blur', blurHandler);\n };\n\n if (disabled) {\n removeEventListener();\n\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 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. If there are any props that you\n * want a provider to receive, 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\n if (Array.isArray(prov)) {\n [Provider] = prov;\n\n return <Provider {...prov[1]}>{acc}</Provider>;\n }\n\n return <Provider>{acc}</Provider>;\n },\n <WrappedComponent {...(props as any)} />\n );\n","import React, { type JSX } from 'react';\n\ntype ElementType<P = any> =\n | React.ComponentType<P>\n | {\n [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K]\n ? K\n : never;\n }[keyof JSX.IntrinsicElements];\n\ntype ForwardRefComponent<T, P = {}> = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<P> & React.RefAttributes<T>\n>;\n\ntype InferElementRef<T> =\n T extends ElementType<any>\n ? T extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[T] extends React.DetailedHTMLProps<\n React.HTMLAttributes<infer R>,\n any\n >\n ? R\n : never\n : T extends React.ComponentType<any>\n ? T extends React.ComponentClass<any>\n ? InstanceType<T>\n : T extends React.ForwardRefExoticComponent<any>\n ? React.ComponentPropsWithRef<T>['ref'] extends React.Ref<infer R>\n ? R\n : never\n : never\n : never\n : never;\n\n/**\n * Shorter alternative to `React.forwardRef`.\n *\n * @generic1 Component type or element type\n * @generic2 Extended prop types\n */\nexport function withRef<T extends ElementType, P = {}>(\n renderFunction: React.ForwardRefRenderFunction<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n >\n): ForwardRefComponent<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n> {\n return React.forwardRef(renderFunction as any) as any;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAElB,wBAAqB;AAEd,IAAM,sBAAsB,CAIjC,YAEA,aAAAA,QAAM,WAMJ,CAAC,EAAE,IAAI,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AAC5C,QAAM,OAAO,UAAU,yBAAQ,MAAY;AAE3C,SAAO,6BAAAA,QAAA,cAAC,QAAK,KAAW,GAAG,OAAO;AACpC,CAAC;;;AChBI,IAAM,M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,QAAO,iBAAiB,QAAQ,WAAW;AAE7D,aAAO,MAAM,oBAAoB;AAAA,IACnC;AAAA;AAAA,IAEA;AAAA,MACE;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,MAEA,KAAK,UAAU,UAAU;AAAA,IAC3B;AAAA,EACF;AAEA,SAAO;AACT;;;ACpKA,IAAAC,iBAAkB;AAEX,IAAM,gBAAgB,CAC3B,UACA,SACM;AACN,QAAM,CAAC,OAAO,QAAQ,IAAI,eAAAC,QAAM,SAAS,QAAQ;AAEjD,iBAAAA,QAAM,gBAAgB,MAAM;AAC1B,aAAS,QAAQ;AAAA,EAEnB,GAAG,IAAI;AAEP,SAAO;AACT;;;ACdA,IAAAC,iBAAkB;AAMX,IAAM,gBACX,IAAI,cACJ,CAAK,qBACL,CAAC,UACC,UAAU;AAAA,EACR,CAAC,KAAK,SAAS;AACb,QAAI,WAAW;AAEf,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,OAAC,QAAQ,IAAI;AAEb,aAAO,+BAAAC,QAAA,cAAC,YAAU,GAAG,KAAK,CAAC,KAAI,GAAI;AAAA,IACrC;AAEA,WAAO,+BAAAA,QAAA,cAAC,gBAAU,GAAI;AAAA,EACxB;AAAA,EACA,+BAAAA,QAAA,cAAC,oBAAkB,GAAI,OAAe;AACxC;;;ACvBJ,IAAAC,iBAAgC;AAwCzB,SAAS,QACd,gBAOA;AACA,SAAO,eAAAC,QAAM,WAAW,cAAqB;AAC/C;","names":["React","import_react","React","import_react","React","ReactDOM","import_react","import_react","React","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React"]}
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/createSlotComponent.tsx","../src/Box.tsx","../src/MemoizedChildren.tsx","../src/PortalBody.tsx","../src/Text.tsx","../src/composeEventHandlers.ts","../src/createPrimitiveComponent.tsx","../src/useComposedRef.ts","../src/createPrimitiveElement.tsx","../src/useEffectOnce.ts","../src/useIsomorphicLayoutEffect.ts","../src/useMemoOnce.ts","../src/useMemoizedSelector.ts","../src/useOnClickOutside.ts","../src/useStableFn.ts","../src/useStableMemo.ts","../src/withProviders.tsx","../src/withRef.tsx"],"sourcesContent":["/**\n * @file Automatically generated by barrelsby.\n */\n\nexport * from './Box';\nexport * from './MemoizedChildren';\nexport * from './PortalBody';\nexport * from './Text';\nexport * from './composeEventHandlers';\nexport * from './createPrimitiveComponent';\nexport * from './createPrimitiveElement';\nexport * from './createSlotComponent';\nexport * from './useComposedRef';\nexport * from './useEffectOnce';\nexport * from './useIsomorphicLayoutEffect';\nexport * from './useMemoOnce';\nexport * from './useMemoizedSelector';\nexport * from './useOnClickOutside';\nexport * from './useStableFn';\nexport * from './useStableMemo';\nexport * from './withProviders';\nexport * from './withRef';\n","import React from 'react';\n\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 React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n } & P\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 type 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';\n\nexport const MemoizedChildren = React.memo(\n ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n }\n);\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\n if (!container) return (<>{children}</>) as any;\n\n return ReactDOM.createPortal(children, element || document.body);\n};\n","import type React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Text = createSlotComponent('span');\n\nexport type TextProps = React.ComponentPropsWithRef<typeof Text>;\n","/** @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1 */\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","import React from 'react';\n\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 state and props, and\n * forwards references to child components. Component props:\n *\n * - `asChild`: If true, the component will be rendered as a `Slot`\n * {@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. 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 * @example\n * const MyButton = createPrimitiveComponent(Button)({\n * stateHook: useButtonState,\n * propsHook: useButton,\n * });\n *\n * @param {React.ElementType} element The base component or native HTML element.\n * @returns {function} A primitive component.\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 propsHook?: PH;\n stateHook?: SH;\n } = {}) => {\n return React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n className?: string;\n options?: Parameters<SH>[0];\n state?: Parameters<PH>[0];\n style?: React.CSSProperties;\n setProps?: (hookProps: NonNullable<ReturnType<PH>['props']>) => P;\n } & P\n >(\n (\n {\n asChild,\n className: classNameProp,\n getClassName,\n options,\n state: stateProp,\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 hidden,\n props: hookProps,\n ref: hookRef,\n } = propsHook\n ? propsHook(state)\n : { hidden: false, props: {}, 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 This utility takes care of different types\n * 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 Accepts callback refs and\n * 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 Accepts callback refs and\n * 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, { type JSX } 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 function useEffectOnce(\n effect: React.EffectCallback,\n deps: React.DependencyList\n) {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n\n React.useEffect(() => {\n const depsChanged = deps.some((dep, i) => dep !== prevDepsRef.current[i]);\n\n if (!initialized.current || depsChanged) {\n initialized.current = true;\n prevDepsRef.current = deps;\n effect();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n","import React from 'react';\n\nexport const CAN_USE_DOM =\n typeof window !== 'undefined' && window.document?.createElement !== undefined;\n\n/**\n * Prevent warning on SSR by falling back to React.useEffect when DOM isn't\n * available\n */\nexport const useIsomorphicLayoutEffect = CAN_USE_DOM\n ? React.useLayoutEffect\n : React.useEffect;\n","import React from 'react';\n\nexport function useMemoOnce<T>(\n factory: () => T,\n deps: React.DependencyList\n): T {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n const memoizedValueRef = React.useRef<T>(undefined);\n\n if (\n !initialized.current ||\n deps.some((dep, i) => dep !== prevDepsRef.current[i])\n ) {\n initialized.current = true;\n prevDepsRef.current = deps;\n memoizedValueRef.current = factory();\n }\n\n return memoizedValueRef.current!;\n}\n","import React from 'react';\n\n/**\n * Re-render only when the selector result changes.\n *\n * @param selector A function that derives a value from deps\n * @param deps Dependencies on which to run the selector\n * @param equalityFn Optional comparison function to detect changes in the\n * derived value\n */\nexport function useMemoizedSelector<R>(\n selector: () => R,\n deps: React.DependencyList,\n equalityFn: (a: R, b: R) => boolean = (a, b) => a === b\n) {\n // Initialize our state with the initial \"selected\" value.\n const [memoizedValue, setMemoizedValue] = React.useState<R>(() => selector());\n\n // Keep a ref of the previous value so we can compare in an effect.\n const previousValueRef = React.useRef<R>(memoizedValue);\n\n React.useEffect(() => {\n // Compute a new value by calling the selector.\n const newValue = selector();\n\n // If different, update state and the ref.\n if (!equalityFn(previousValueRef.current, newValue)) {\n setMemoizedValue(newValue);\n previousValueRef.current = newValue;\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return memoizedValue;\n}\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 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 type UseOnClickOutsideCallback<T extends Event = Event> = (\n event: T\n) => void;\n\nexport interface UseOnClickOutsideOptions {\n detectIFrame?: boolean;\n disabled?: boolean;\n eventTypes?: string[];\n excludeScrollbar?: boolean;\n ignoreClass?: string[] | string;\n refs?: Refs;\n}\n\nexport type UseOnClickOutsideReturn = (element: El | null) => void;\n\ntype El = HTMLElement;\n\ntype Refs = React.RefObject<El | null>[];\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 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 detectIFrame = true,\n disabled,\n eventTypes = ['mousedown', 'touchstart'],\n excludeScrollbar,\n ignoreClass = DEFAULT_IGNORE_CLASS,\n refs: refsOpt,\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\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 document.removeEventListener(\n type,\n handler,\n getEventOptions(type) as any\n )\n );\n\n if (detectIFrame) window.removeEventListener('blur', blurHandler);\n };\n\n if (disabled) {\n removeEventListener();\n\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 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, { type DependencyList } from 'react';\n\n/**\n * Create a stable version of a function that can be used in dependency arrays\n * without causing hooks like useEffect to re-run if the function changes.\n * Calling the returned function always calls the most recent version of the\n * function that was passed to useStableFn.\n *\n * If you do want the function to be replaced when certain dependency values\n * change, include those values in the dependency array of useStableFn.\n */\nexport const useStableFn = <A extends unknown[], R>(\n fn: (...args: A) => R,\n deps: DependencyList = []\n) => {\n const fnRef = React.useRef(fn);\n fnRef.current = fn;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback((...args: A) => fnRef.current(...args), deps);\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. If there are any props that you\n * want a provider to receive, 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\n if (Array.isArray(prov)) {\n [Provider] = prov;\n\n return <Provider {...prov[1]}>{acc}</Provider>;\n }\n\n return <Provider>{acc}</Provider>;\n },\n <WrappedComponent {...(props as any)} />\n );\n","import React, { type JSX } from 'react';\n\ntype ElementType<P = any> =\n | React.ComponentType<P>\n | {\n [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K]\n ? K\n : never;\n }[keyof JSX.IntrinsicElements];\n\ntype ForwardRefComponent<T, P = {}> = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<P> & React.RefAttributes<T>\n>;\n\ntype InferElementRef<T> =\n T extends ElementType<any>\n ? T extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[T] extends React.DetailedHTMLProps<\n React.HTMLAttributes<infer R>,\n any\n >\n ? R\n : never\n : T extends React.ComponentType<any>\n ? T extends React.ComponentClass<any>\n ? InstanceType<T>\n : T extends React.ForwardRefExoticComponent<any>\n ? React.ComponentPropsWithRef<T>['ref'] extends React.Ref<infer R>\n ? R\n : never\n : never\n : never\n : never;\n\n/**\n * Shorter alternative to `React.forwardRef`.\n *\n * @generic1 Component type or element type\n * @generic2 Extended prop types\n */\nexport function withRef<T extends ElementType, P = {}>(\n renderFunction: React.ForwardRefRenderFunction<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n >\n): ForwardRefComponent<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n> {\n return React.forwardRef(renderFunction as any) as any;\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBAAkB;AAElB,wBAAqB;AAEd,IAAM,sBAAsB,CAIjC,YAEA,aAAAA,QAAM,WAMJ,CAAC,EAAE,IAAI,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AAC5C,QAAM,OAAO,UAAU,yBAAQ,MAAY;AAE3C,SAAO,6BAAAA,QAAA,cAAC,QAAK,KAAW,GAAG,OAAO;AACpC,CAAC;;;AChBI,IAAM,MAAM,oBAAoB,KAAK;;;ACJ5C,IAAAC,gBAAkB;AAEX,IAAM,mBAAmB,cAAAC,QAAM;AAAA,EACpC,CAAC,EAAE,SAAS,MAAqC;AAC/C,WAAO,8BAAAA,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AAAA,EACrB;AACF;;;ACNA,IAAAC,gBAAkB;AAClB,uBAAqB;AAId,IAAM,aAG8B,CAAC;AAAA,EAC1C;AAAA,EACA;AACF,MAAuB;AACrB,QAAM,YACJ,WAAW,OAAO,WAAW,cAAc,SAAS,OAAO;AAE7D,MAAI,CAAC,UAAW,QAAQ,8BAAAC,QAAA,4BAAAA,QAAA,gBAAG,QAAS;AAEpC,SAAO,iBAAAC,QAAS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;;ACnBA,IAAAC,iBAAkB;AAEX,IAAM,gBAAgB,CAC3B,UACA,SACM;AACN,QAAM,CAAC,OAAO,QAAQ,IAAI,eAAAC,QAAM,SAAS,QAAQ;AAEjD,iBAAAA,QAAM,gBAAgB,MAAM;AAC1B,aAAS,QAAQ;AAAA,EAEnB,GAAG,IAAI;AAEP,SAAO;AACT;;;ACdA,IAAAC,iBAAkB;AAMX,IAAM,gBACX,IAAI,cACJ,CAAK,qBACL,CAAC,UACC,UAAU;AAAA,EACR,CAAC,KAAK,SAAS;AACb,QAAI,WAAW;AAEf,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,OAAC,QAAQ,IAAI;AAEb,aAAO,+BAAAC,QAAA,cAAC,YAAU,GAAG,KAAK,CAAC,KAAI,GAAI;AAAA,IACrC;AAEA,WAAO,+BAAAA,QAAA,cAAC,gBAAU,GAAI;AAAA,EACxB;AAAA,EACA,+BAAAA,QAAA,cAAC,oBAAkB,GAAI,OAAe;AACxC;;;ACvBJ,IAAAC,iBAAgC;AAwCzB,SAAS,QACd,gBAOA;AACA,SAAO,eAAAC,QAAM,WAAW,cAAqB;AAC/C;","names":["React","import_react","React","import_react","React","ReactDOM","import_react","import_react","React","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React","import_react","React"]}
|
package/dist/index.mjs
CHANGED
|
@@ -264,34 +264,42 @@ var useOnClickOutside = (callback, {
|
|
|
264
264
|
return ref;
|
|
265
265
|
};
|
|
266
266
|
|
|
267
|
-
// src/
|
|
267
|
+
// src/useStableFn.ts
|
|
268
268
|
import React12 from "react";
|
|
269
|
+
var useStableFn = (fn, deps = []) => {
|
|
270
|
+
const fnRef = React12.useRef(fn);
|
|
271
|
+
fnRef.current = fn;
|
|
272
|
+
return React12.useCallback((...args) => fnRef.current(...args), deps);
|
|
273
|
+
};
|
|
274
|
+
|
|
275
|
+
// src/useStableMemo.ts
|
|
276
|
+
import React13 from "react";
|
|
269
277
|
var useStableMemo = (producer, deps) => {
|
|
270
|
-
const [value, setValue] =
|
|
271
|
-
|
|
278
|
+
const [value, setValue] = React13.useState(producer);
|
|
279
|
+
React13.useLayoutEffect(() => {
|
|
272
280
|
setValue(producer);
|
|
273
281
|
}, deps);
|
|
274
282
|
return value;
|
|
275
283
|
};
|
|
276
284
|
|
|
277
285
|
// src/withProviders.tsx
|
|
278
|
-
import
|
|
286
|
+
import React14 from "react";
|
|
279
287
|
var withProviders = (...providers) => (WrappedComponent) => (props) => providers.reduceRight(
|
|
280
288
|
(acc, prov) => {
|
|
281
289
|
let Provider = prov;
|
|
282
290
|
if (Array.isArray(prov)) {
|
|
283
291
|
[Provider] = prov;
|
|
284
|
-
return /* @__PURE__ */
|
|
292
|
+
return /* @__PURE__ */ React14.createElement(Provider, { ...prov[1] }, acc);
|
|
285
293
|
}
|
|
286
|
-
return /* @__PURE__ */
|
|
294
|
+
return /* @__PURE__ */ React14.createElement(Provider, null, acc);
|
|
287
295
|
},
|
|
288
|
-
/* @__PURE__ */
|
|
296
|
+
/* @__PURE__ */ React14.createElement(WrappedComponent, { ...props })
|
|
289
297
|
);
|
|
290
298
|
|
|
291
299
|
// src/withRef.tsx
|
|
292
|
-
import
|
|
300
|
+
import React15 from "react";
|
|
293
301
|
function withRef(renderFunction) {
|
|
294
|
-
return
|
|
302
|
+
return React15.forwardRef(renderFunction);
|
|
295
303
|
}
|
|
296
304
|
export {
|
|
297
305
|
Box,
|
|
@@ -311,6 +319,7 @@ export {
|
|
|
311
319
|
useMemoOnce,
|
|
312
320
|
useMemoizedSelector,
|
|
313
321
|
useOnClickOutside,
|
|
322
|
+
useStableFn,
|
|
314
323
|
useStableMemo,
|
|
315
324
|
withProviders,
|
|
316
325
|
withRef
|
package/dist/index.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/createSlotComponent.tsx","../src/Box.tsx","../src/MemoizedChildren.tsx","../src/PortalBody.tsx","../src/Text.tsx","../src/composeEventHandlers.ts","../src/createPrimitiveComponent.tsx","../src/useComposedRef.ts","../src/createPrimitiveElement.tsx","../src/useEffectOnce.ts","../src/useIsomorphicLayoutEffect.ts","../src/useMemoOnce.ts","../src/useMemoizedSelector.ts","../src/useOnClickOutside.ts","../src/useStableMemo.ts","../src/withProviders.tsx","../src/withRef.tsx"],"sourcesContent":["import React from 'react';\n\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 React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n } & P\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 type 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';\n\nexport const MemoizedChildren = React.memo(\n ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n }\n);\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\n if (!container) return (<>{children}</>) as any;\n\n return ReactDOM.createPortal(children, element || document.body);\n};\n","import type React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Text = createSlotComponent('span');\n\nexport type TextProps = React.ComponentPropsWithRef<typeof Text>;\n","/** @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1 */\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","import React from 'react';\n\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 state and props, and\n * forwards references to child components. Component props:\n *\n * - `asChild`: If true, the component will be rendered as a `Slot`\n * {@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. 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 * @example\n * const MyButton = createPrimitiveComponent(Button)({\n * stateHook: useButtonState,\n * propsHook: useButton,\n * });\n *\n * @param {React.ElementType} element The base component or native HTML element.\n * @returns {function} A primitive component.\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 propsHook?: PH;\n stateHook?: SH;\n } = {}) => {\n return React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n className?: string;\n options?: Parameters<SH>[0];\n state?: Parameters<PH>[0];\n style?: React.CSSProperties;\n setProps?: (hookProps: NonNullable<ReturnType<PH>['props']>) => P;\n } & P\n >(\n (\n {\n asChild,\n className: classNameProp,\n getClassName,\n options,\n state: stateProp,\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 hidden,\n props: hookProps,\n ref: hookRef,\n } = propsHook\n ? propsHook(state)\n : { hidden: false, props: {}, 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 This utility takes care of different types\n * 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 Accepts callback refs and\n * 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 Accepts callback refs and\n * 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, { type JSX } 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 function useEffectOnce(\n effect: React.EffectCallback,\n deps: React.DependencyList\n) {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n\n React.useEffect(() => {\n const depsChanged = deps.some((dep, i) => dep !== prevDepsRef.current[i]);\n\n if (!initialized.current || depsChanged) {\n initialized.current = true;\n prevDepsRef.current = deps;\n effect();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n","import React from 'react';\n\nexport const CAN_USE_DOM =\n typeof window !== 'undefined' && window.document?.createElement !== undefined;\n\n/**\n * Prevent warning on SSR by falling back to React.useEffect when DOM isn't\n * available\n */\nexport const useIsomorphicLayoutEffect = CAN_USE_DOM\n ? React.useLayoutEffect\n : React.useEffect;\n","import React from 'react';\n\nexport function useMemoOnce<T>(\n factory: () => T,\n deps: React.DependencyList\n): T {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n const memoizedValueRef = React.useRef<T>(undefined);\n\n if (\n !initialized.current ||\n deps.some((dep, i) => dep !== prevDepsRef.current[i])\n ) {\n initialized.current = true;\n prevDepsRef.current = deps;\n memoizedValueRef.current = factory();\n }\n\n return memoizedValueRef.current!;\n}\n","import React from 'react';\n\n/**\n * Re-render only when the selector result changes.\n *\n * @param selector A function that derives a value from deps\n * @param deps Dependencies on which to run the selector\n * @param equalityFn Optional comparison function to detect changes in the\n * derived value\n */\nexport function useMemoizedSelector<R>(\n selector: () => R,\n deps: React.DependencyList,\n equalityFn: (a: R, b: R) => boolean = (a, b) => a === b\n) {\n // Initialize our state with the initial \"selected\" value.\n const [memoizedValue, setMemoizedValue] = React.useState<R>(() => selector());\n\n // Keep a ref of the previous value so we can compare in an effect.\n const previousValueRef = React.useRef<R>(memoizedValue);\n\n React.useEffect(() => {\n // Compute a new value by calling the selector.\n const newValue = selector();\n\n // If different, update state and the ref.\n if (!equalityFn(previousValueRef.current, newValue)) {\n setMemoizedValue(newValue);\n previousValueRef.current = newValue;\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return memoizedValue;\n}\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 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 type UseOnClickOutsideCallback<T extends Event = Event> = (\n event: T\n) => void;\n\nexport interface UseOnClickOutsideOptions {\n detectIFrame?: boolean;\n disabled?: boolean;\n eventTypes?: string[];\n excludeScrollbar?: boolean;\n ignoreClass?: string[] | string;\n refs?: Refs;\n}\n\nexport type UseOnClickOutsideReturn = (element: El | null) => void;\n\ntype El = HTMLElement;\n\ntype Refs = React.RefObject<El | null>[];\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 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 detectIFrame = true,\n disabled,\n eventTypes = ['mousedown', 'touchstart'],\n excludeScrollbar,\n ignoreClass = DEFAULT_IGNORE_CLASS,\n refs: refsOpt,\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\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 document.removeEventListener(\n type,\n handler,\n getEventOptions(type) as any\n )\n );\n\n if (detectIFrame) window.removeEventListener('blur', blurHandler);\n };\n\n if (disabled) {\n removeEventListener();\n\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 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. If there are any props that you\n * want a provider to receive, 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\n if (Array.isArray(prov)) {\n [Provider] = prov;\n\n return <Provider {...prov[1]}>{acc}</Provider>;\n }\n\n return <Provider>{acc}</Provider>;\n },\n <WrappedComponent {...(props as any)} />\n );\n","import React, { type JSX } from 'react';\n\ntype ElementType<P = any> =\n | React.ComponentType<P>\n | {\n [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K]\n ? K\n : never;\n }[keyof JSX.IntrinsicElements];\n\ntype ForwardRefComponent<T, P = {}> = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<P> & React.RefAttributes<T>\n>;\n\ntype InferElementRef<T> =\n T extends ElementType<any>\n ? T extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[T] extends React.DetailedHTMLProps<\n React.HTMLAttributes<infer R>,\n any\n >\n ? R\n : never\n : T extends React.ComponentType<any>\n ? T extends React.ComponentClass<any>\n ? InstanceType<T>\n : T extends React.ForwardRefExoticComponent<any>\n ? React.ComponentPropsWithRef<T>['ref'] extends React.Ref<infer R>\n ? R\n : never\n : never\n : never\n : never;\n\n/**\n * Shorter alternative to `React.forwardRef`.\n *\n * @generic1 Component type or element type\n * @generic2 Extended prop types\n */\nexport function withRef<T extends ElementType, P = {}>(\n renderFunction: React.ForwardRefRenderFunction<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n >\n): ForwardRefComponent<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n> {\n return React.forwardRef(renderFunction as any) as any;\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAElB,SAAS,YAAY;AAEd,IAAM,sBAAsB,CAIjC,YAEA,MAAM,WAMJ,CAAC,EAAE,IAAI,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AAC5C,QAAM,OAAO,UAAU,OAAQ,MAAY;AAE3C,SAAO,oCAAC,QAAK,KAAW,GAAG,OAAO;AACpC,CAAC;;;AChBI,IAAM,MAAM,oBAAoB,KAAK;;;ACJ5C,OAAOA,YAAW;AAEX,IAAM,mBAA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AA,EACF;AAEA,SAAO;AACT;;;ACpKA,OAAOC,aAAW;AAEX,IAAM,gBAAgB,CAC3B,UACA,SACM;AACN,QAAM,CAAC,OAAO,QAAQ,IAAIA,QAAM,SAAS,QAAQ;AAEjD,EAAAA,QAAM,gBAAgB,MAAM;AAC1B,aAAS,QAAQ;AAAA,EAEnB,GAAG,IAAI;AAEP,SAAO;AACT;;;ACdA,OAAOC,aAAW;AAMX,IAAM,gBACX,IAAI,cACJ,CAAK,qBACL,CAAC,UACC,UAAU;AAAA,EACR,CAAC,KAAK,SAAS;AACb,QAAI,WAAW;AAEf,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,OAAC,QAAQ,IAAI;AAEb,aAAO,gBAAAA,QAAA,cAAC,YAAU,GAAG,KAAK,CAAC,KAAI,GAAI;AAAA,IACrC;AAEA,WAAO,gBAAAA,QAAA,cAAC,gBAAU,GAAI;AAAA,EACxB;AAAA,EACA,gBAAAA,QAAA,cAAC,oBAAkB,GAAI,OAAe;AACxC;;;ACvBJ,OAAOC,aAAyB;AAwCzB,SAAS,QACd,gBAOA;AACA,SAAOA,QAAM,WAAW,cAAqB;AAC/C;","names":["React","React","React","React","React","React","React","React","React","React","React","React","React","React"]}
|
|
1
|
+
{"version":3,"sources":["../src/createSlotComponent.tsx","../src/Box.tsx","../src/MemoizedChildren.tsx","../src/PortalBody.tsx","../src/Text.tsx","../src/composeEventHandlers.ts","../src/createPrimitiveComponent.tsx","../src/useComposedRef.ts","../src/createPrimitiveElement.tsx","../src/useEffectOnce.ts","../src/useIsomorphicLayoutEffect.ts","../src/useMemoOnce.ts","../src/useMemoizedSelector.ts","../src/useOnClickOutside.ts","../src/useStableFn.ts","../src/useStableMemo.ts","../src/withProviders.tsx","../src/withRef.tsx"],"sourcesContent":["import React from 'react';\n\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 React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n } & P\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 type 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';\n\nexport const MemoizedChildren = React.memo(\n ({ children }: { children: React.ReactNode }) => {\n return <>{children}</>;\n }\n);\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\n if (!container) return (<>{children}</>) as any;\n\n return ReactDOM.createPortal(children, element || document.body);\n};\n","import type React from 'react';\n\nimport { createSlotComponent } from './createSlotComponent';\n\nexport const Text = createSlotComponent('span');\n\nexport type TextProps = React.ComponentPropsWithRef<typeof Text>;\n","/** @see https://github.com/radix-ui/primitives/blob/b324ec2d7ddf13a2a115cb5b11478e24d2f45b87/packages/core/primitive/src/primitive.tsx#L1 */\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","import React from 'react';\n\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 state and props, and\n * forwards references to child components. Component props:\n *\n * - `asChild`: If true, the component will be rendered as a `Slot`\n * {@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. 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 * @example\n * const MyButton = createPrimitiveComponent(Button)({\n * stateHook: useButtonState,\n * propsHook: useButton,\n * });\n *\n * @param {React.ElementType} element The base component or native HTML element.\n * @returns {function} A primitive component.\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 propsHook?: PH;\n stateHook?: SH;\n } = {}) => {\n return React.forwardRef<\n any,\n {\n as?: React.ElementType;\n asChild?: boolean;\n className?: string;\n options?: Parameters<SH>[0];\n state?: Parameters<PH>[0];\n style?: React.CSSProperties;\n setProps?: (hookProps: NonNullable<ReturnType<PH>['props']>) => P;\n } & P\n >(\n (\n {\n asChild,\n className: classNameProp,\n getClassName,\n options,\n state: stateProp,\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 hidden,\n props: hookProps,\n ref: hookRef,\n } = propsHook\n ? propsHook(state)\n : { hidden: false, props: {}, 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 This utility takes care of different types\n * 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 Accepts callback refs and\n * 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 Accepts callback refs and\n * 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, { type JSX } 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 function useEffectOnce(\n effect: React.EffectCallback,\n deps: React.DependencyList\n) {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n\n React.useEffect(() => {\n const depsChanged = deps.some((dep, i) => dep !== prevDepsRef.current[i]);\n\n if (!initialized.current || depsChanged) {\n initialized.current = true;\n prevDepsRef.current = deps;\n effect();\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n}\n","import React from 'react';\n\nexport const CAN_USE_DOM =\n typeof window !== 'undefined' && window.document?.createElement !== undefined;\n\n/**\n * Prevent warning on SSR by falling back to React.useEffect when DOM isn't\n * available\n */\nexport const useIsomorphicLayoutEffect = CAN_USE_DOM\n ? React.useLayoutEffect\n : React.useEffect;\n","import React from 'react';\n\nexport function useMemoOnce<T>(\n factory: () => T,\n deps: React.DependencyList\n): T {\n const initialized = React.useRef(false);\n const prevDepsRef = React.useRef(deps);\n const memoizedValueRef = React.useRef<T>(undefined);\n\n if (\n !initialized.current ||\n deps.some((dep, i) => dep !== prevDepsRef.current[i])\n ) {\n initialized.current = true;\n prevDepsRef.current = deps;\n memoizedValueRef.current = factory();\n }\n\n return memoizedValueRef.current!;\n}\n","import React from 'react';\n\n/**\n * Re-render only when the selector result changes.\n *\n * @param selector A function that derives a value from deps\n * @param deps Dependencies on which to run the selector\n * @param equalityFn Optional comparison function to detect changes in the\n * derived value\n */\nexport function useMemoizedSelector<R>(\n selector: () => R,\n deps: React.DependencyList,\n equalityFn: (a: R, b: R) => boolean = (a, b) => a === b\n) {\n // Initialize our state with the initial \"selected\" value.\n const [memoizedValue, setMemoizedValue] = React.useState<R>(() => selector());\n\n // Keep a ref of the previous value so we can compare in an effect.\n const previousValueRef = React.useRef<R>(memoizedValue);\n\n React.useEffect(() => {\n // Compute a new value by calling the selector.\n const newValue = selector();\n\n // If different, update state and the ref.\n if (!equalityFn(previousValueRef.current, newValue)) {\n setMemoizedValue(newValue);\n previousValueRef.current = newValue;\n }\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, deps);\n\n return memoizedValue;\n}\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 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 type UseOnClickOutsideCallback<T extends Event = Event> = (\n event: T\n) => void;\n\nexport interface UseOnClickOutsideOptions {\n detectIFrame?: boolean;\n disabled?: boolean;\n eventTypes?: string[];\n excludeScrollbar?: boolean;\n ignoreClass?: string[] | string;\n refs?: Refs;\n}\n\nexport type UseOnClickOutsideReturn = (element: El | null) => void;\n\ntype El = HTMLElement;\n\ntype Refs = React.RefObject<El | null>[];\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 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 detectIFrame = true,\n disabled,\n eventTypes = ['mousedown', 'touchstart'],\n excludeScrollbar,\n ignoreClass = DEFAULT_IGNORE_CLASS,\n refs: refsOpt,\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\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 document.removeEventListener(\n type,\n handler,\n getEventOptions(type) as any\n )\n );\n\n if (detectIFrame) window.removeEventListener('blur', blurHandler);\n };\n\n if (disabled) {\n removeEventListener();\n\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 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, { type DependencyList } from 'react';\n\n/**\n * Create a stable version of a function that can be used in dependency arrays\n * without causing hooks like useEffect to re-run if the function changes.\n * Calling the returned function always calls the most recent version of the\n * function that was passed to useStableFn.\n *\n * If you do want the function to be replaced when certain dependency values\n * change, include those values in the dependency array of useStableFn.\n */\nexport const useStableFn = <A extends unknown[], R>(\n fn: (...args: A) => R,\n deps: DependencyList = []\n) => {\n const fnRef = React.useRef(fn);\n fnRef.current = fn;\n // eslint-disable-next-line react-hooks/exhaustive-deps\n return React.useCallback((...args: A) => fnRef.current(...args), deps);\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. If there are any props that you\n * want a provider to receive, 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\n if (Array.isArray(prov)) {\n [Provider] = prov;\n\n return <Provider {...prov[1]}>{acc}</Provider>;\n }\n\n return <Provider>{acc}</Provider>;\n },\n <WrappedComponent {...(props as any)} />\n );\n","import React, { type JSX } from 'react';\n\ntype ElementType<P = any> =\n | React.ComponentType<P>\n | {\n [K in keyof JSX.IntrinsicElements]: P extends JSX.IntrinsicElements[K]\n ? K\n : never;\n }[keyof JSX.IntrinsicElements];\n\ntype ForwardRefComponent<T, P = {}> = React.ForwardRefExoticComponent<\n React.PropsWithoutRef<P> & React.RefAttributes<T>\n>;\n\ntype InferElementRef<T> =\n T extends ElementType<any>\n ? T extends keyof JSX.IntrinsicElements\n ? JSX.IntrinsicElements[T] extends React.DetailedHTMLProps<\n React.HTMLAttributes<infer R>,\n any\n >\n ? R\n : never\n : T extends React.ComponentType<any>\n ? T extends React.ComponentClass<any>\n ? InstanceType<T>\n : T extends React.ForwardRefExoticComponent<any>\n ? React.ComponentPropsWithRef<T>['ref'] extends React.Ref<infer R>\n ? R\n : never\n : never\n : never\n : never;\n\n/**\n * Shorter alternative to `React.forwardRef`.\n *\n * @generic1 Component type or element type\n * @generic2 Extended prop types\n */\nexport function withRef<T extends ElementType, P = {}>(\n renderFunction: React.ForwardRefRenderFunction<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n >\n): ForwardRefComponent<\n InferElementRef<T>,\n React.ComponentPropsWithoutRef<T> & P\n> {\n return React.forwardRef(renderFunction as any) as any;\n}\n"],"mappings":";AAAA,OAAO,WAAW;AAElB,SAAS,YAAY;AAEd,IAAM,sBAAsB,CAIjC,YAEA,MAAM,WAMJ,CAAC,EAAE,IAAI,UAAU,OAAO,GAAG,MAAM,GAAG,QAAQ;AAC5C,QAAM,OAAO,UAAU,OAAQ,MAAY;AAE3C,SAAO,oCAAC,QAAK,KAAW,GAAG,OAAO;AACpC,CAAC;;;AChBI,IAAM,MAAM,oBAAoB,KAAK;;;ACJ5C,OAAOA,YAAW;AAEX,IAAM,m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;AAAA,EACF;AAEA,SAAO;AACT;;;ACpKA,OAAOC,aAAoC;AAWpC,IAAM,cAAc,CACzB,IACA,OAAuB,CAAC,MACrB;AACH,QAAM,QAAQA,QAAM,OAAO,EAAE;AAC7B,QAAM,UAAU;AAEhB,SAAOA,QAAM,YAAY,IAAI,SAAY,MAAM,QAAQ,GAAG,IAAI,GAAG,IAAI;AACvE;;;ACnBA,OAAOC,aAAW;AAEX,IAAM,gBAAgB,CAC3B,UACA,SACM;AACN,QAAM,CAAC,OAAO,QAAQ,IAAIA,QAAM,SAAS,QAAQ;AAEjD,EAAAA,QAAM,gBAAgB,MAAM;AAC1B,aAAS,QAAQ;AAAA,EAEnB,GAAG,IAAI;AAEP,SAAO;AACT;;;ACdA,OAAOC,aAAW;AAMX,IAAM,gBACX,IAAI,cACJ,CAAK,qBACL,CAAC,UACC,UAAU;AAAA,EACR,CAAC,KAAK,SAAS;AACb,QAAI,WAAW;AAEf,QAAI,MAAM,QAAQ,IAAI,GAAG;AACvB,OAAC,QAAQ,IAAI;AAEb,aAAO,gBAAAA,QAAA,cAAC,YAAU,GAAG,KAAK,CAAC,KAAI,GAAI;AAAA,IACrC;AAEA,WAAO,gBAAAA,QAAA,cAAC,gBAAU,GAAI;AAAA,EACxB;AAAA,EACA,gBAAAA,QAAA,cAAC,oBAAkB,GAAI,OAAe;AACxC;;;ACvBJ,OAAOC,aAAyB;AAwCzB,SAAS,QACd,gBAOA;AACA,SAAOA,QAAM,WAAW,cAAqB;AAC/C;","names":["React","React","React","React","React","React","React","React","React","React","React","React","React","React","React"]}
|