main repo

This commit is contained in:
Basilosaurusrex
2025-11-24 18:09:40 +01:00
parent b636ee5e70
commit f027651f9b
34146 changed files with 4436636 additions and 0 deletions

View File

@@ -0,0 +1,15 @@
import { ReactRef } from './types';
/**
* Assigns a value for a given ref, no matter of the ref format
* @param {RefObject} ref - a callback function or ref object
* @param value - a new value
*
* @see https://github.com/theKashey/use-callback-ref#assignref
* @example
* const refObject = useRef();
* const refFn = (ref) => {....}
*
* assignRef(refObject, "refValue");
* assignRef(refFn, "refValue");
*/
export declare function assignRef<T>(ref: ReactRef<T>, value: T | null): ReactRef<T>;

22
node_modules/use-callback-ref/dist/es2019/assignRef.js generated vendored Normal file
View File

@@ -0,0 +1,22 @@
/**
* Assigns a value for a given ref, no matter of the ref format
* @param {RefObject} ref - a callback function or ref object
* @param value - a new value
*
* @see https://github.com/theKashey/use-callback-ref#assignref
* @example
* const refObject = useRef();
* const refFn = (ref) => {....}
*
* assignRef(refObject, "refValue");
* assignRef(refFn, "refValue");
*/
export function assignRef(ref, value) {
if (typeof ref === 'function') {
ref(value);
}
else if (ref) {
ref.current = value;
}
return ref;
}

View File

@@ -0,0 +1,10 @@
import { RefObject } from 'react';
/**
* creates a Ref object with on change callback
* @param callback
* @returns {RefObject}
*
* @see {@link useCallbackRef}
* @see https://reactjs.org/docs/refs-and-the-dom.html#creating-refs
*/
export declare function createCallbackRef<T>(callback: (newValue: T | null, lastValue: T | null) => any): RefObject<T>;

23
node_modules/use-callback-ref/dist/es2019/createRef.js generated vendored Normal file
View File

@@ -0,0 +1,23 @@
/**
* creates a Ref object with on change callback
* @param callback
* @returns {RefObject}
*
* @see {@link useCallbackRef}
* @see https://reactjs.org/docs/refs-and-the-dom.html#creating-refs
*/
export function createCallbackRef(callback) {
let current = null;
return {
get current() {
return current;
},
set current(value) {
const last = current;
if (last !== value) {
current = value;
callback(value, last);
}
},
};
}

8
node_modules/use-callback-ref/dist/es2019/index.d.ts generated vendored Normal file
View File

@@ -0,0 +1,8 @@
export { assignRef } from './assignRef';
export { useCallbackRef } from './useRef';
export { createCallbackRef } from './createRef';
export { mergeRefs } from './mergeRef';
export { useMergeRefs } from './useMergeRef';
export { useTransformRef } from './useTransformRef';
export { transformRef } from './transformRef';
export { refToCallback, useRefToCallback } from './refToCallback';

12
node_modules/use-callback-ref/dist/es2019/index.js generated vendored Normal file
View File

@@ -0,0 +1,12 @@
export { assignRef } from './assignRef';
// callback ref
export { useCallbackRef } from './useRef';
export { createCallbackRef } from './createRef';
// merge ref
export { mergeRefs } from './mergeRef';
export { useMergeRefs } from './useMergeRef';
// transform ref
export { useTransformRef } from './useTransformRef';
export { transformRef } from './transformRef';
// refToCallback
export { refToCallback, useRefToCallback } from './refToCallback';

View File

@@ -0,0 +1,16 @@
import { MutableRefObject } from 'react';
import { ReactRef } from './types';
/**
* Merges two or more refs together providing a single interface to set their value
* @param {RefObject|Ref} refs
* @returns {MutableRefObject} - a new ref, which translates all changes to {refs}
*
* @see {@link useMergeRefs} to be used in ReactComponents
* @example
* const Component = React.forwardRef((props, ref) => {
* const ownRef = useRef();
* const domRef = mergeRefs([ref, ownRef]); // 👈 merge together
* return <div ref={domRef}>...</div>
* }
*/
export declare function mergeRefs<T>(refs: ReactRef<T>[]): MutableRefObject<T | null>;

18
node_modules/use-callback-ref/dist/es2019/mergeRef.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
import { assignRef } from './assignRef';
import { createCallbackRef } from './createRef';
/**
* Merges two or more refs together providing a single interface to set their value
* @param {RefObject|Ref} refs
* @returns {MutableRefObject} - a new ref, which translates all changes to {refs}
*
* @see {@link useMergeRefs} to be used in ReactComponents
* @example
* const Component = React.forwardRef((props, ref) => {
* const ownRef = useRef();
* const domRef = mergeRefs([ref, ownRef]); // 👈 merge together
* return <div ref={domRef}>...</div>
* }
*/
export function mergeRefs(refs) {
return createCallbackRef((newValue) => refs.forEach((ref) => assignRef(ref, newValue)));
}

View File

@@ -0,0 +1,24 @@
import { ReactRef, RefCallback } from './types';
/**
* Unmemoized version of {@link useRefToCallback}
* @see {@link useRefToCallback}
* @param ref
*/
export declare function refToCallback<T>(ref: ReactRef<T>): RefCallback<T>;
/**
* Transforms a given `ref` into `callback`.
*
* To transform `callback` into ref use {@link useCallbackRef|useCallbackRef(undefined, callback)}
*
* @param {ReactRef} ref
* @returns {Function}
*
* @see https://github.com/theKashey/use-callback-ref#reftocallback
*
* @example
* const ref = useRef(0);
* const setRef = useRefToCallback(ref);
* 👉 setRef(10);
* ✅ ref.current === 10
*/
export declare function useRefToCallback<T>(ref: ReactRef<T>): RefCallback<T>;

View File

@@ -0,0 +1,48 @@
/**
* Unmemoized version of {@link useRefToCallback}
* @see {@link useRefToCallback}
* @param ref
*/
export function refToCallback(ref) {
return (newValue) => {
if (typeof ref === 'function') {
ref(newValue);
}
else if (ref) {
ref.current = newValue;
}
};
}
const nullCallback = () => null;
// lets maintain a weak ref to, well, ref :)
// not using `kashe` to keep this package small
const weakMem = new WeakMap();
const weakMemoize = (ref) => {
const usedRef = ref || nullCallback;
const storedRef = weakMem.get(usedRef);
if (storedRef) {
return storedRef;
}
const cb = refToCallback(usedRef);
weakMem.set(usedRef, cb);
return cb;
};
/**
* Transforms a given `ref` into `callback`.
*
* To transform `callback` into ref use {@link useCallbackRef|useCallbackRef(undefined, callback)}
*
* @param {ReactRef} ref
* @returns {Function}
*
* @see https://github.com/theKashey/use-callback-ref#reftocallback
*
* @example
* const ref = useRef(0);
* const setRef = useRefToCallback(ref);
* 👉 setRef(10);
* ✅ ref.current === 10
*/
export function useRefToCallback(ref) {
return weakMemoize(ref);
}

View File

@@ -0,0 +1,11 @@
import { ReactRef, RefObject } from './types';
/**
* Transforms one ref to another
* @example
* ```tsx
* const ResizableWithRef = forwardRef((props, ref) =>
* <Resizable {...props} ref={transformRef(ref, i => i ? i.resizable : null)}/>
* );
* ```
*/
export declare function transformRef<T, K>(ref: ReactRef<K>, transformer: (original: T | null) => K): RefObject<T>;

View File

@@ -0,0 +1,14 @@
import { assignRef } from './assignRef';
import { createCallbackRef } from './createRef';
/**
* Transforms one ref to another
* @example
* ```tsx
* const ResizableWithRef = forwardRef((props, ref) =>
* <Resizable {...props} ref={transformRef(ref, i => i ? i.resizable : null)}/>
* );
* ```
*/
export function transformRef(ref, transformer) {
return createCallbackRef((value) => assignRef(ref, transformer(value)));
}

5
node_modules/use-callback-ref/dist/es2019/types.d.ts generated vendored Normal file
View File

@@ -0,0 +1,5 @@
import * as React from 'react';
export declare type RefCallback<T> = (newValue: T | null) => void;
export declare type RefObject<T> = React.MutableRefObject<T | null>;
export declare type DefinedReactRef<T> = RefCallback<T> | RefObject<T>;
export declare type ReactRef<T> = DefinedReactRef<T> | null;

1
node_modules/use-callback-ref/dist/es2019/types.js generated vendored Normal file
View File

@@ -0,0 +1 @@
export {};

View File

@@ -0,0 +1,17 @@
import * as React from 'react';
import { ReactRef } from './types';
/**
* Merges two or more refs together providing a single interface to set their value
* @param {RefObject|Ref} refs
* @returns {MutableRefObject} - a new ref, which translates all changes to {refs}
*
* @see {@link mergeRefs} a version without buit-in memoization
* @see https://github.com/theKashey/use-callback-ref#usemergerefs
* @example
* const Component = React.forwardRef((props, ref) => {
* const ownRef = useRef();
* const domRef = useMergeRefs([ref, ownRef]); // 👈 merge together
* return <div ref={domRef}>...</div>
* }
*/
export declare function useMergeRefs<T>(refs: ReactRef<T>[], defaultValue?: T): React.MutableRefObject<T | null>;

View File

@@ -0,0 +1,43 @@
import * as React from 'react';
import { assignRef } from './assignRef';
import { useCallbackRef } from './useRef';
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? React.useLayoutEffect : React.useEffect;
const currentValues = new WeakMap();
/**
* Merges two or more refs together providing a single interface to set their value
* @param {RefObject|Ref} refs
* @returns {MutableRefObject} - a new ref, which translates all changes to {refs}
*
* @see {@link mergeRefs} a version without buit-in memoization
* @see https://github.com/theKashey/use-callback-ref#usemergerefs
* @example
* const Component = React.forwardRef((props, ref) => {
* const ownRef = useRef();
* const domRef = useMergeRefs([ref, ownRef]); // 👈 merge together
* return <div ref={domRef}>...</div>
* }
*/
export function useMergeRefs(refs, defaultValue) {
const callbackRef = useCallbackRef(defaultValue || null, (newValue) => refs.forEach((ref) => assignRef(ref, newValue)));
// handle refs changes - added or removed
useIsomorphicLayoutEffect(() => {
const oldValue = currentValues.get(callbackRef);
if (oldValue) {
const prevRefs = new Set(oldValue);
const nextRefs = new Set(refs);
const current = callbackRef.current;
prevRefs.forEach((ref) => {
if (!nextRefs.has(ref)) {
assignRef(ref, null);
}
});
nextRefs.forEach((ref) => {
if (!prevRefs.has(ref)) {
assignRef(ref, current);
}
});
}
currentValues.set(callbackRef, refs);
}, [refs]);
return callbackRef;
}

16
node_modules/use-callback-ref/dist/es2019/useRef.d.ts generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import { MutableRefObject } from 'react';
/**
* creates a MutableRef with ref change callback
* @param initialValue - initial ref value
* @param {Function} callback - a callback to run when value changes
*
* @example
* const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
* ref.current = 1;
* // prints 0 -> 1
*
* @see https://reactjs.org/docs/hooks-reference.html#useref
* @see https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref
* @returns {MutableRefObject}
*/
export declare function useCallbackRef<T>(initialValue: T | null, callback: (newValue: T | null, lastValue: T | null) => void): MutableRefObject<T | null>;

39
node_modules/use-callback-ref/dist/es2019/useRef.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import { useState } from 'react';
/**
* creates a MutableRef with ref change callback
* @param initialValue - initial ref value
* @param {Function} callback - a callback to run when value changes
*
* @example
* const ref = useCallbackRef(0, (newValue, oldValue) => console.log(oldValue, '->', newValue);
* ref.current = 1;
* // prints 0 -> 1
*
* @see https://reactjs.org/docs/hooks-reference.html#useref
* @see https://github.com/theKashey/use-callback-ref#usecallbackref---to-replace-reactuseref
* @returns {MutableRefObject}
*/
export function useCallbackRef(initialValue, callback) {
const [ref] = useState(() => ({
// value
value: initialValue,
// last callback
callback,
// "memoized" public interface
facade: {
get current() {
return ref.value;
},
set current(value) {
const last = ref.value;
if (last !== value) {
ref.value = value;
ref.callback(value, last);
}
},
},
}));
// update callback
ref.callback = callback;
return ref.facade;
}

View File

@@ -0,0 +1,15 @@
import { ReactRef, RefObject } from './types';
/**
* Create a _lense_ on Ref, making it possible to transform ref value
* @param {ReactRef} ref
* @param {Function} transformer. 👉 Ref would be __NOT updated__ on `transformer` update.
* @returns {RefObject}
*
* @see https://github.com/theKashey/use-callback-ref#usetransformref-to-replace-reactuseimperativehandle
* @example
*
* const ResizableWithRef = forwardRef((props, ref) =>
* <Resizable {...props} ref={useTransformRef(ref, i => i ? i.resizable : null)}/>
* );
*/
export declare function useTransformRef<T, K>(ref: ReactRef<K>, transformer: (original: T | null) => K): RefObject<T>;

View File

@@ -0,0 +1,18 @@
import { assignRef } from './assignRef';
import { useCallbackRef } from './useRef';
/**
* Create a _lense_ on Ref, making it possible to transform ref value
* @param {ReactRef} ref
* @param {Function} transformer. 👉 Ref would be __NOT updated__ on `transformer` update.
* @returns {RefObject}
*
* @see https://github.com/theKashey/use-callback-ref#usetransformref-to-replace-reactuseimperativehandle
* @example
*
* const ResizableWithRef = forwardRef((props, ref) =>
* <Resizable {...props} ref={useTransformRef(ref, i => i ? i.resizable : null)}/>
* );
*/
export function useTransformRef(ref, transformer) {
return useCallbackRef(null, (value) => assignRef(ref, transformer(value)));
}