@tale-ui/utils 0.0.3
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/CHANGELOG.md +14 -0
- package/LICENSE +21 -0
- package/README.md +3 -0
- package/detectBrowser.d.ts +8 -0
- package/detectBrowser.js +64 -0
- package/empty.d.ts +3 -0
- package/empty.js +10 -0
- package/error.d.ts +2 -0
- package/error.js +23 -0
- package/esm/detectBrowser.d.ts +8 -0
- package/esm/detectBrowser.js +58 -0
- package/esm/empty.d.ts +3 -0
- package/esm/empty.js +3 -0
- package/esm/error.d.ts +2 -0
- package/esm/error.js +16 -0
- package/esm/fastHooks.d.ts +14 -0
- package/esm/fastHooks.js +43 -0
- package/esm/fastObjectShallowCompare.d.ts +1 -0
- package/esm/fastObjectShallowCompare.js +29 -0
- package/esm/formatErrorMessage.d.ts +18 -0
- package/esm/formatErrorMessage.js +26 -0
- package/esm/generateId.d.ts +1 -0
- package/esm/generateId.js +5 -0
- package/esm/getReactElementRef.d.ts +5 -0
- package/esm/getReactElementRef.js +14 -0
- package/esm/inertValue.d.ts +1 -0
- package/esm/inertValue.js +8 -0
- package/esm/isElementDisabled.d.ts +1 -0
- package/esm/isElementDisabled.js +3 -0
- package/esm/isMouseWithinBounds.d.ts +1 -0
- package/esm/isMouseWithinBounds.js +10 -0
- package/esm/mergeObjects.d.ts +1 -0
- package/esm/mergeObjects.js +15 -0
- package/esm/owner.d.ts +2 -0
- package/esm/owner.js +4 -0
- package/esm/package.json +1 -0
- package/esm/reactVersion.d.ts +3 -0
- package/esm/reactVersion.js +5 -0
- package/esm/safeReact.d.ts +2 -0
- package/esm/safeReact.js +6 -0
- package/esm/store/ReactStore.d.ts +91 -0
- package/esm/store/ReactStore.js +199 -0
- package/esm/store/Store.d.ts +58 -0
- package/esm/store/Store.js +111 -0
- package/esm/store/StoreInspector.d.ts +41 -0
- package/esm/store/StoreInspector.js +537 -0
- package/esm/store/createSelector.d.ts +30 -0
- package/esm/store/createSelector.js +148 -0
- package/esm/store/index.d.ts +5 -0
- package/esm/store/index.js +5 -0
- package/esm/store/useStore.d.ts +22 -0
- package/esm/store/useStore.js +107 -0
- package/esm/testUtils.d.ts +17 -0
- package/esm/testUtils.js +19 -0
- package/esm/useAnimationFrame.d.ts +18 -0
- package/esm/useAnimationFrame.js +106 -0
- package/esm/useControlled.d.ts +24 -0
- package/esm/useControlled.js +40 -0
- package/esm/useEnhancedClickHandler.d.ts +13 -0
- package/esm/useEnhancedClickHandler.js +38 -0
- package/esm/useForcedRerendering.d.ts +4 -0
- package/esm/useForcedRerendering.js +13 -0
- package/esm/useId.d.ts +7 -0
- package/esm/useId.js +41 -0
- package/esm/useInterval.d.ts +13 -0
- package/esm/useInterval.js +36 -0
- package/esm/useIsoLayoutEffect.d.ts +2 -0
- package/esm/useIsoLayoutEffect.js +5 -0
- package/esm/useMergedRefs.d.ts +21 -0
- package/esm/useMergedRefs.js +108 -0
- package/esm/useOnFirstRender.d.ts +1 -0
- package/esm/useOnFirstRender.js +10 -0
- package/esm/useOnMount.d.ts +5 -0
- package/esm/useOnMount.js +14 -0
- package/esm/usePreviousValue.d.ts +6 -0
- package/esm/usePreviousValue.js +22 -0
- package/esm/useRefWithInit.d.ts +10 -0
- package/esm/useRefWithInit.js +20 -0
- package/esm/useScrollLock.d.ts +7 -0
- package/esm/useScrollLock.js +244 -0
- package/esm/useStableCallback.d.ts +13 -0
- package/esm/useStableCallback.js +44 -0
- package/esm/useTimeout.d.ts +17 -0
- package/esm/useTimeout.js +43 -0
- package/esm/useValueAsRef.d.ts +10 -0
- package/esm/useValueAsRef.js +28 -0
- package/esm/visuallyHidden.d.ts +3 -0
- package/esm/visuallyHidden.js +20 -0
- package/esm/warn.d.ts +1 -0
- package/esm/warn.js +13 -0
- package/fastHooks.d.ts +14 -0
- package/fastHooks.js +54 -0
- package/fastObjectShallowCompare.d.ts +1 -0
- package/fastObjectShallowCompare.js +35 -0
- package/formatErrorMessage.d.ts +18 -0
- package/formatErrorMessage.js +33 -0
- package/generateId.d.ts +1 -0
- package/generateId.js +11 -0
- package/getReactElementRef.d.ts +5 -0
- package/getReactElementRef.js +20 -0
- package/inertValue.d.ts +1 -0
- package/inertValue.js +14 -0
- package/isElementDisabled.d.ts +1 -0
- package/isElementDisabled.js +9 -0
- package/isMouseWithinBounds.d.ts +1 -0
- package/isMouseWithinBounds.js +16 -0
- package/mergeObjects.d.ts +1 -0
- package/mergeObjects.js +21 -0
- package/owner.d.ts +2 -0
- package/owner.js +16 -0
- package/package.json +64 -0
- package/reactVersion.d.ts +3 -0
- package/reactVersion.js +12 -0
- package/safeReact.d.ts +2 -0
- package/safeReact.js +12 -0
- package/store/ReactStore.d.ts +91 -0
- package/store/ReactStore.js +205 -0
- package/store/Store.d.ts +58 -0
- package/store/Store.js +118 -0
- package/store/StoreInspector.d.ts +41 -0
- package/store/StoreInspector.js +544 -0
- package/store/createSelector.d.ts +30 -0
- package/store/createSelector.js +154 -0
- package/store/index.d.ts +5 -0
- package/store/index.js +60 -0
- package/store/useStore.d.ts +22 -0
- package/store/useStore.js +115 -0
- package/testUtils.d.ts +17 -0
- package/testUtils.js +26 -0
- package/useAnimationFrame.d.ts +18 -0
- package/useAnimationFrame.js +113 -0
- package/useControlled.d.ts +24 -0
- package/useControlled.js +46 -0
- package/useEnhancedClickHandler.d.ts +13 -0
- package/useEnhancedClickHandler.js +44 -0
- package/useForcedRerendering.d.ts +4 -0
- package/useForcedRerendering.js +18 -0
- package/useId.d.ts +7 -0
- package/useId.js +47 -0
- package/useInterval.d.ts +13 -0
- package/useInterval.js +43 -0
- package/useIsoLayoutEffect.d.ts +2 -0
- package/useIsoLayoutEffect.js +11 -0
- package/useMergedRefs.d.ts +21 -0
- package/useMergedRefs.js +114 -0
- package/useOnFirstRender.d.ts +1 -0
- package/useOnFirstRender.js +16 -0
- package/useOnMount.d.ts +5 -0
- package/useOnMount.js +20 -0
- package/usePreviousValue.d.ts +6 -0
- package/usePreviousValue.js +27 -0
- package/useRefWithInit.d.ts +10 -0
- package/useRefWithInit.js +26 -0
- package/useScrollLock.d.ts +7 -0
- package/useScrollLock.js +249 -0
- package/useStableCallback.d.ts +13 -0
- package/useStableCallback.js +49 -0
- package/useTimeout.d.ts +17 -0
- package/useTimeout.js +50 -0
- package/useValueAsRef.d.ts +10 -0
- package/useValueAsRef.js +32 -0
- package/visuallyHidden.d.ts +3 -0
- package/visuallyHidden.js +26 -0
- package/warn.d.ts +1 -0
- package/warn.js +19 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.useStableCallback = useStableCallback;
|
|
9
|
+
var React = _interopRequireWildcard(require("react"));
|
|
10
|
+
var _useRefWithInit = require("./useRefWithInit");
|
|
11
|
+
// https://github.com/mui/material-ui/issues/41190#issuecomment-2040873379
|
|
12
|
+
const useInsertionEffect = React[`useInsertionEffect${Math.random().toFixed(1)}`.slice(0, -3)];
|
|
13
|
+
const useSafeInsertionEffect =
|
|
14
|
+
// React 17 doesn't have useInsertionEffect.
|
|
15
|
+
useInsertionEffect &&
|
|
16
|
+
// Preact replaces useInsertionEffect with useLayoutEffect and fires too late.
|
|
17
|
+
useInsertionEffect !== React.useLayoutEffect ? useInsertionEffect : fn => fn();
|
|
18
|
+
/**
|
|
19
|
+
* Stabilizes the function passed so it's always the same between renders.
|
|
20
|
+
*
|
|
21
|
+
* The function becomes non-reactive to any values it captures.
|
|
22
|
+
* It can safely be passed as a dependency of `React.useMemo` and `React.useEffect` without re-triggering them if its captured values change.
|
|
23
|
+
*
|
|
24
|
+
* The function must only be called inside effects and event handlers, never during render (which throws an error).
|
|
25
|
+
*
|
|
26
|
+
* This hook is a more permissive version of React 19.2's `React.useEffectEvent` in that it can be passed through contexts and called in event handler props, not just effects.
|
|
27
|
+
*/
|
|
28
|
+
function useStableCallback(callback) {
|
|
29
|
+
const stable = (0, _useRefWithInit.useRefWithInit)(createStableCallback).current;
|
|
30
|
+
stable.next = callback;
|
|
31
|
+
useSafeInsertionEffect(stable.effect);
|
|
32
|
+
return stable.trampoline;
|
|
33
|
+
}
|
|
34
|
+
function createStableCallback() {
|
|
35
|
+
const stable = {
|
|
36
|
+
next: undefined,
|
|
37
|
+
callback: assertNotCalled,
|
|
38
|
+
trampoline: (...args) => stable.callback?.(...args),
|
|
39
|
+
effect: () => {
|
|
40
|
+
stable.callback = stable.next;
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
return stable;
|
|
44
|
+
}
|
|
45
|
+
function assertNotCalled() {
|
|
46
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
47
|
+
throw /* minify-error-disabled */new Error('Tale UI: Cannot call an event handler while rendering.');
|
|
48
|
+
}
|
|
49
|
+
}
|
package/useTimeout.d.ts
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
type TimeoutId = number;
|
|
2
|
+
export declare class Timeout {
|
|
3
|
+
static create(): Timeout;
|
|
4
|
+
currentId: TimeoutId;
|
|
5
|
+
/**
|
|
6
|
+
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
7
|
+
*/
|
|
8
|
+
start(delay: number, fn: Function): void;
|
|
9
|
+
isStarted(): boolean;
|
|
10
|
+
clear: () => void;
|
|
11
|
+
disposeEffect: () => () => void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* A `setTimeout` with automatic cleanup and guard.
|
|
15
|
+
*/
|
|
16
|
+
export declare function useTimeout(): Timeout;
|
|
17
|
+
export {};
|
package/useTimeout.js
ADDED
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.Timeout = void 0;
|
|
8
|
+
exports.useTimeout = useTimeout;
|
|
9
|
+
var _useRefWithInit = require("./useRefWithInit");
|
|
10
|
+
var _useOnMount = require("./useOnMount");
|
|
11
|
+
const EMPTY = 0;
|
|
12
|
+
class Timeout {
|
|
13
|
+
static create() {
|
|
14
|
+
return new Timeout();
|
|
15
|
+
}
|
|
16
|
+
currentId = EMPTY;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Executes `fn` after `delay`, clearing any previously scheduled call.
|
|
20
|
+
*/
|
|
21
|
+
start(delay, fn) {
|
|
22
|
+
this.clear();
|
|
23
|
+
this.currentId = setTimeout(() => {
|
|
24
|
+
this.currentId = EMPTY;
|
|
25
|
+
fn();
|
|
26
|
+
}, delay); /* Node.js types are enabled in development */
|
|
27
|
+
}
|
|
28
|
+
isStarted() {
|
|
29
|
+
return this.currentId !== EMPTY;
|
|
30
|
+
}
|
|
31
|
+
clear = () => {
|
|
32
|
+
if (this.currentId !== EMPTY) {
|
|
33
|
+
clearTimeout(this.currentId);
|
|
34
|
+
this.currentId = EMPTY;
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
disposeEffect = () => {
|
|
38
|
+
return this.clear;
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* A `setTimeout` with automatic cleanup and guard.
|
|
44
|
+
*/
|
|
45
|
+
exports.Timeout = Timeout;
|
|
46
|
+
function useTimeout() {
|
|
47
|
+
const timeout = (0, _useRefWithInit.useRefWithInit)(Timeout.create).current;
|
|
48
|
+
(0, _useOnMount.useOnMount)(timeout.disposeEffect);
|
|
49
|
+
return timeout;
|
|
50
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Untracks the provided value by turning it into a ref to remove its reactivity.
|
|
3
|
+
*
|
|
4
|
+
* Used to access the passed value inside `React.useEffect` without causing the effect to re-run when the value changes.
|
|
5
|
+
*/
|
|
6
|
+
export declare function useValueAsRef<T>(value: T): {
|
|
7
|
+
current: T;
|
|
8
|
+
next: T;
|
|
9
|
+
effect: () => void;
|
|
10
|
+
};
|
package/useValueAsRef.js
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
'use client';
|
|
3
|
+
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.useValueAsRef = useValueAsRef;
|
|
8
|
+
var _useIsoLayoutEffect = require("./useIsoLayoutEffect");
|
|
9
|
+
var _useRefWithInit = require("./useRefWithInit");
|
|
10
|
+
/**
|
|
11
|
+
* Untracks the provided value by turning it into a ref to remove its reactivity.
|
|
12
|
+
*
|
|
13
|
+
* Used to access the passed value inside `React.useEffect` without causing the effect to re-run when the value changes.
|
|
14
|
+
*/
|
|
15
|
+
function useValueAsRef(value) {
|
|
16
|
+
const latest = (0, _useRefWithInit.useRefWithInit)(createLatestRef, value).current;
|
|
17
|
+
latest.next = value;
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
20
|
+
(0, _useIsoLayoutEffect.useIsoLayoutEffect)(latest.effect);
|
|
21
|
+
return latest;
|
|
22
|
+
}
|
|
23
|
+
function createLatestRef(value) {
|
|
24
|
+
const latest = {
|
|
25
|
+
current: value,
|
|
26
|
+
next: value,
|
|
27
|
+
effect: () => {
|
|
28
|
+
latest.current = latest.next;
|
|
29
|
+
}
|
|
30
|
+
};
|
|
31
|
+
return latest;
|
|
32
|
+
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.visuallyHiddenInput = exports.visuallyHidden = void 0;
|
|
7
|
+
const visuallyHiddenBase = {
|
|
8
|
+
clipPath: 'inset(50%)',
|
|
9
|
+
overflow: 'hidden',
|
|
10
|
+
whiteSpace: 'nowrap',
|
|
11
|
+
border: 0,
|
|
12
|
+
padding: 0,
|
|
13
|
+
width: 1,
|
|
14
|
+
height: 1,
|
|
15
|
+
margin: -1
|
|
16
|
+
};
|
|
17
|
+
const visuallyHidden = exports.visuallyHidden = {
|
|
18
|
+
...visuallyHiddenBase,
|
|
19
|
+
position: 'fixed',
|
|
20
|
+
top: 0,
|
|
21
|
+
left: 0
|
|
22
|
+
};
|
|
23
|
+
const visuallyHiddenInput = exports.visuallyHiddenInput = {
|
|
24
|
+
...visuallyHiddenBase,
|
|
25
|
+
position: 'absolute'
|
|
26
|
+
};
|
package/warn.d.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function warn(...messages: string[]): void;
|
package/warn.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.warn = warn;
|
|
7
|
+
let set;
|
|
8
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
9
|
+
set = new Set();
|
|
10
|
+
}
|
|
11
|
+
function warn(...messages) {
|
|
12
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
13
|
+
const messageKey = messages.join(' ');
|
|
14
|
+
if (!set.has(messageKey)) {
|
|
15
|
+
set.add(messageKey);
|
|
16
|
+
console.warn(`Tale UI: ${messageKey}`);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
}
|