@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
package/CHANGELOG.md
ADDED
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
The MIT License (MIT)
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2019 Material-UI SAS
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const isWebKit: boolean;
|
|
2
|
+
export declare const isIOS: boolean;
|
|
3
|
+
export declare const isFirefox: boolean;
|
|
4
|
+
export declare const isSafari: boolean;
|
|
5
|
+
export declare const isEdge: boolean;
|
|
6
|
+
export declare const isAndroid: boolean;
|
|
7
|
+
export declare const isMac: boolean;
|
|
8
|
+
export declare const isJSDOM: boolean;
|
package/detectBrowser.js
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isWebKit = exports.isSafari = exports.isMac = exports.isJSDOM = exports.isIOS = exports.isFirefox = exports.isEdge = exports.isAndroid = void 0;
|
|
7
|
+
const hasNavigator = typeof navigator !== 'undefined';
|
|
8
|
+
const nav = getNavigatorData();
|
|
9
|
+
const platform = getPlatform();
|
|
10
|
+
const userAgent = getUserAgent();
|
|
11
|
+
const isWebKit = exports.isWebKit = typeof CSS === 'undefined' || !CSS.supports ? false : CSS.supports('-webkit-backdrop-filter:none');
|
|
12
|
+
const isIOS = exports.isIOS =
|
|
13
|
+
// iPads can claim to be MacIntel
|
|
14
|
+
nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 ? true : /iP(hone|ad|od)|iOS/.test(nav.platform);
|
|
15
|
+
const isFirefox = exports.isFirefox = hasNavigator && /firefox/i.test(userAgent);
|
|
16
|
+
const isSafari = exports.isSafari = hasNavigator && /apple/i.test(navigator.vendor);
|
|
17
|
+
const isEdge = exports.isEdge = hasNavigator && /Edg/i.test(userAgent);
|
|
18
|
+
const isAndroid = exports.isAndroid = hasNavigator && /android/i.test(platform) || /android/i.test(userAgent);
|
|
19
|
+
const isMac = exports.isMac = hasNavigator && platform.toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;
|
|
20
|
+
const isJSDOM = exports.isJSDOM = userAgent.includes('jsdom/');
|
|
21
|
+
|
|
22
|
+
// Avoid Chrome DevTools blue warning.
|
|
23
|
+
function getNavigatorData() {
|
|
24
|
+
if (!hasNavigator) {
|
|
25
|
+
return {
|
|
26
|
+
platform: '',
|
|
27
|
+
maxTouchPoints: -1
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const uaData = navigator.userAgentData;
|
|
31
|
+
if (uaData?.platform) {
|
|
32
|
+
return {
|
|
33
|
+
platform: uaData.platform,
|
|
34
|
+
maxTouchPoints: navigator.maxTouchPoints
|
|
35
|
+
};
|
|
36
|
+
}
|
|
37
|
+
return {
|
|
38
|
+
platform: navigator.platform ?? '',
|
|
39
|
+
maxTouchPoints: navigator.maxTouchPoints ?? -1
|
|
40
|
+
};
|
|
41
|
+
}
|
|
42
|
+
function getUserAgent() {
|
|
43
|
+
if (!hasNavigator) {
|
|
44
|
+
return '';
|
|
45
|
+
}
|
|
46
|
+
const uaData = navigator.userAgentData;
|
|
47
|
+
if (uaData && Array.isArray(uaData.brands)) {
|
|
48
|
+
return uaData.brands.map(({
|
|
49
|
+
brand,
|
|
50
|
+
version
|
|
51
|
+
}) => `${brand}/${version}`).join(' ');
|
|
52
|
+
}
|
|
53
|
+
return navigator.userAgent;
|
|
54
|
+
}
|
|
55
|
+
function getPlatform() {
|
|
56
|
+
if (!hasNavigator) {
|
|
57
|
+
return '';
|
|
58
|
+
}
|
|
59
|
+
const uaData = navigator.userAgentData;
|
|
60
|
+
if (uaData?.platform) {
|
|
61
|
+
return uaData.platform;
|
|
62
|
+
}
|
|
63
|
+
return navigator.platform ?? '';
|
|
64
|
+
}
|
package/empty.d.ts
ADDED
package/empty.js
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.EMPTY_OBJECT = exports.EMPTY_ARRAY = void 0;
|
|
7
|
+
exports.NOOP = NOOP;
|
|
8
|
+
function NOOP() {}
|
|
9
|
+
const EMPTY_ARRAY = exports.EMPTY_ARRAY = Object.freeze([]);
|
|
10
|
+
const EMPTY_OBJECT = exports.EMPTY_OBJECT = Object.freeze({});
|
package/error.d.ts
ADDED
package/error.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.error = error;
|
|
7
|
+
exports.reset = reset;
|
|
8
|
+
let set;
|
|
9
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
10
|
+
set = new Set();
|
|
11
|
+
}
|
|
12
|
+
function error(...messages) {
|
|
13
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
14
|
+
const messageKey = messages.join(' ');
|
|
15
|
+
if (!set.has(messageKey)) {
|
|
16
|
+
set.add(messageKey);
|
|
17
|
+
console.error(`Tale UI: ${messageKey}`);
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
function reset() {
|
|
22
|
+
set?.clear();
|
|
23
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export declare const isWebKit: boolean;
|
|
2
|
+
export declare const isIOS: boolean;
|
|
3
|
+
export declare const isFirefox: boolean;
|
|
4
|
+
export declare const isSafari: boolean;
|
|
5
|
+
export declare const isEdge: boolean;
|
|
6
|
+
export declare const isAndroid: boolean;
|
|
7
|
+
export declare const isMac: boolean;
|
|
8
|
+
export declare const isJSDOM: boolean;
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
const hasNavigator = typeof navigator !== 'undefined';
|
|
2
|
+
const nav = getNavigatorData();
|
|
3
|
+
const platform = getPlatform();
|
|
4
|
+
const userAgent = getUserAgent();
|
|
5
|
+
export const isWebKit = typeof CSS === 'undefined' || !CSS.supports ? false : CSS.supports('-webkit-backdrop-filter:none');
|
|
6
|
+
export const isIOS =
|
|
7
|
+
// iPads can claim to be MacIntel
|
|
8
|
+
nav.platform === 'MacIntel' && nav.maxTouchPoints > 1 ? true : /iP(hone|ad|od)|iOS/.test(nav.platform);
|
|
9
|
+
export const isFirefox = hasNavigator && /firefox/i.test(userAgent);
|
|
10
|
+
export const isSafari = hasNavigator && /apple/i.test(navigator.vendor);
|
|
11
|
+
export const isEdge = hasNavigator && /Edg/i.test(userAgent);
|
|
12
|
+
export const isAndroid = hasNavigator && /android/i.test(platform) || /android/i.test(userAgent);
|
|
13
|
+
export const isMac = hasNavigator && platform.toLowerCase().startsWith('mac') && !navigator.maxTouchPoints;
|
|
14
|
+
export const isJSDOM = userAgent.includes('jsdom/');
|
|
15
|
+
|
|
16
|
+
// Avoid Chrome DevTools blue warning.
|
|
17
|
+
function getNavigatorData() {
|
|
18
|
+
if (!hasNavigator) {
|
|
19
|
+
return {
|
|
20
|
+
platform: '',
|
|
21
|
+
maxTouchPoints: -1
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
const uaData = navigator.userAgentData;
|
|
25
|
+
if (uaData?.platform) {
|
|
26
|
+
return {
|
|
27
|
+
platform: uaData.platform,
|
|
28
|
+
maxTouchPoints: navigator.maxTouchPoints
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
return {
|
|
32
|
+
platform: navigator.platform ?? '',
|
|
33
|
+
maxTouchPoints: navigator.maxTouchPoints ?? -1
|
|
34
|
+
};
|
|
35
|
+
}
|
|
36
|
+
function getUserAgent() {
|
|
37
|
+
if (!hasNavigator) {
|
|
38
|
+
return '';
|
|
39
|
+
}
|
|
40
|
+
const uaData = navigator.userAgentData;
|
|
41
|
+
if (uaData && Array.isArray(uaData.brands)) {
|
|
42
|
+
return uaData.brands.map(({
|
|
43
|
+
brand,
|
|
44
|
+
version
|
|
45
|
+
}) => `${brand}/${version}`).join(' ');
|
|
46
|
+
}
|
|
47
|
+
return navigator.userAgent;
|
|
48
|
+
}
|
|
49
|
+
function getPlatform() {
|
|
50
|
+
if (!hasNavigator) {
|
|
51
|
+
return '';
|
|
52
|
+
}
|
|
53
|
+
const uaData = navigator.userAgentData;
|
|
54
|
+
if (uaData?.platform) {
|
|
55
|
+
return uaData.platform;
|
|
56
|
+
}
|
|
57
|
+
return navigator.platform ?? '';
|
|
58
|
+
}
|
package/esm/empty.d.ts
ADDED
package/esm/empty.js
ADDED
package/esm/error.d.ts
ADDED
package/esm/error.js
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
let set;
|
|
2
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
3
|
+
set = new Set();
|
|
4
|
+
}
|
|
5
|
+
export function error(...messages) {
|
|
6
|
+
if (process.env.NODE_ENV !== 'production') {
|
|
7
|
+
const messageKey = messages.join(' ');
|
|
8
|
+
if (!set.has(messageKey)) {
|
|
9
|
+
set.add(messageKey);
|
|
10
|
+
console.error(`Tale UI: ${messageKey}`);
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
}
|
|
14
|
+
export function reset() {
|
|
15
|
+
set?.clear();
|
|
16
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
export type Instance = {
|
|
3
|
+
didInitialize: boolean;
|
|
4
|
+
};
|
|
5
|
+
type HookType = {
|
|
6
|
+
before: (instance: any) => void;
|
|
7
|
+
after: (instance: any) => void;
|
|
8
|
+
};
|
|
9
|
+
export declare function getInstance(): Instance | undefined;
|
|
10
|
+
export declare function setInstance(instance: Instance | undefined): void;
|
|
11
|
+
export declare function register(hook: HookType): void;
|
|
12
|
+
export declare function fastComponent<P extends object, E extends HTMLElement, R extends React.ReactNode>(fn: (props: P) => R): typeof fn;
|
|
13
|
+
export declare function fastComponentRef<P extends object, E extends Element, R extends React.ReactNode>(fn: (props: React.PropsWithoutRef<P>, forwardedRef: React.Ref<E>) => R): React.ForwardRefExoticComponent<React.PropsWithoutRef<P> & React.RefAttributes<E>>;
|
|
14
|
+
export {};
|
package/esm/fastHooks.js
ADDED
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { useRefWithInit } from "./useRefWithInit.js";
|
|
3
|
+
const hooks = [];
|
|
4
|
+
let currentInstance = undefined;
|
|
5
|
+
export function getInstance() {
|
|
6
|
+
return currentInstance;
|
|
7
|
+
}
|
|
8
|
+
export function setInstance(instance) {
|
|
9
|
+
currentInstance = instance;
|
|
10
|
+
}
|
|
11
|
+
export function register(hook) {
|
|
12
|
+
hooks.push(hook);
|
|
13
|
+
}
|
|
14
|
+
export function fastComponent(fn) {
|
|
15
|
+
const FastComponent = (props, forwardedRef) => {
|
|
16
|
+
const instance = useRefWithInit(createInstance).current;
|
|
17
|
+
let result;
|
|
18
|
+
try {
|
|
19
|
+
currentInstance = instance;
|
|
20
|
+
for (const hook of hooks) {
|
|
21
|
+
hook.before(instance);
|
|
22
|
+
}
|
|
23
|
+
result = fn(props, forwardedRef);
|
|
24
|
+
for (const hook of hooks) {
|
|
25
|
+
hook.after(instance);
|
|
26
|
+
}
|
|
27
|
+
instance.didInitialize = true;
|
|
28
|
+
} finally {
|
|
29
|
+
currentInstance = undefined;
|
|
30
|
+
}
|
|
31
|
+
return result;
|
|
32
|
+
};
|
|
33
|
+
FastComponent.displayName = fn.displayName || fn.name;
|
|
34
|
+
return FastComponent;
|
|
35
|
+
}
|
|
36
|
+
export function fastComponentRef(fn) {
|
|
37
|
+
return /*#__PURE__*/React.forwardRef(fastComponent(fn));
|
|
38
|
+
}
|
|
39
|
+
function createInstance() {
|
|
40
|
+
return {
|
|
41
|
+
didInitialize: false
|
|
42
|
+
};
|
|
43
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function fastObjectShallowCompare<T extends Record<string, any> | null>(a: T, b: T): boolean;
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// https://github.com/mui/mui-x/blob/master/packages/x-internals/src/fastObjectShallowCompare/fastObjectShallowCompare.ts
|
|
2
|
+
const is = Object.is;
|
|
3
|
+
export function fastObjectShallowCompare(a, b) {
|
|
4
|
+
if (a === b) {
|
|
5
|
+
return true;
|
|
6
|
+
}
|
|
7
|
+
if (!(a instanceof Object) || !(b instanceof Object)) {
|
|
8
|
+
return false;
|
|
9
|
+
}
|
|
10
|
+
let aLength = 0;
|
|
11
|
+
let bLength = 0;
|
|
12
|
+
|
|
13
|
+
/* eslint-disable guard-for-in */
|
|
14
|
+
for (const key in a) {
|
|
15
|
+
aLength += 1;
|
|
16
|
+
if (!is(a[key], b[key])) {
|
|
17
|
+
return false;
|
|
18
|
+
}
|
|
19
|
+
if (!(key in b)) {
|
|
20
|
+
return false;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/* eslint-disable-next-line @typescript-eslint/naming-convention, @typescript-eslint/no-unused-vars */
|
|
25
|
+
for (const _ in b) {
|
|
26
|
+
bLength += 1;
|
|
27
|
+
}
|
|
28
|
+
return aLength === bLength;
|
|
29
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a formatErrorMessage function with a custom URL and prefix.
|
|
3
|
+
* @param baseUrl - The base URL for the error page (e.g., 'https://tale-ui.com/production-error')
|
|
4
|
+
* @param prefix - The prefix for the error message (e.g., 'Tale UI')
|
|
5
|
+
* @returns A function that formats error messages with the given URL and prefix
|
|
6
|
+
*/
|
|
7
|
+
export declare function createFormatErrorMessage(baseUrl: string, prefix: string): (code: number, ...args: string[]) => string;
|
|
8
|
+
/**
|
|
9
|
+
* WARNING: Don't import this directly. It's imported by the code generated by
|
|
10
|
+
* `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
|
|
11
|
+
* constructors to ensure the plugin works as expected. Supported patterns include:
|
|
12
|
+
* throw new Error('My message');
|
|
13
|
+
* throw new Error(`My message: ${foo}`);
|
|
14
|
+
* throw new Error(`My message: ${foo}` + 'another string');
|
|
15
|
+
* ...
|
|
16
|
+
*/
|
|
17
|
+
declare const formatErrorMessage: (code: number, ...args: string[]) => string;
|
|
18
|
+
export default formatErrorMessage;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Creates a formatErrorMessage function with a custom URL and prefix.
|
|
3
|
+
* @param baseUrl - The base URL for the error page (e.g., 'https://tale-ui.com/production-error')
|
|
4
|
+
* @param prefix - The prefix for the error message (e.g., 'Tale UI')
|
|
5
|
+
* @returns A function that formats error messages with the given URL and prefix
|
|
6
|
+
*/
|
|
7
|
+
export function createFormatErrorMessage(baseUrl, prefix) {
|
|
8
|
+
return function formatErrorMessage(code, ...args) {
|
|
9
|
+
const url = new URL(baseUrl);
|
|
10
|
+
url.searchParams.set('code', code.toString());
|
|
11
|
+
args.forEach(arg => url.searchParams.append('args[]', arg));
|
|
12
|
+
return `${prefix} error #${code}; visit ${url} for the full message.`;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* WARNING: Don't import this directly. It's imported by the code generated by
|
|
18
|
+
* `@mui/interal-babel-plugin-minify-errors`. Make sure to always use string literals in `Error`
|
|
19
|
+
* constructors to ensure the plugin works as expected. Supported patterns include:
|
|
20
|
+
* throw new Error('My message');
|
|
21
|
+
* throw new Error(`My message: ${foo}`);
|
|
22
|
+
* throw new Error(`My message: ${foo}` + 'another string');
|
|
23
|
+
* ...
|
|
24
|
+
*/
|
|
25
|
+
const formatErrorMessage = createFormatErrorMessage('https://base-ui.com/production-error', 'Tale UI');
|
|
26
|
+
export default formatErrorMessage;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function generateId(prefix: string): string;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
import { isReactVersionAtLeast } from "./reactVersion.js";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Extracts the `ref` from a React element, handling different React versions.
|
|
6
|
+
*/
|
|
7
|
+
export function getReactElementRef(element) {
|
|
8
|
+
if (! /*#__PURE__*/React.isValidElement(element)) {
|
|
9
|
+
return null;
|
|
10
|
+
}
|
|
11
|
+
const reactElement = element;
|
|
12
|
+
const propsWithRef = reactElement.props;
|
|
13
|
+
return (isReactVersionAtLeast(19) ? propsWithRef?.ref : reactElement.ref) ?? null;
|
|
14
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function inertValue(value?: boolean): boolean | undefined;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isElementDisabled(element: HTMLElement | null): boolean;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function isMouseWithinBounds(event: React.MouseEvent): boolean;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export function isMouseWithinBounds(event) {
|
|
2
|
+
const targetRect = event.currentTarget.getBoundingClientRect();
|
|
3
|
+
|
|
4
|
+
// Safari randomly fires `mouseleave` incorrectly when the item is
|
|
5
|
+
// aligned to the trigger. This is a workaround to prevent the highlight
|
|
6
|
+
// from being removed while the cursor is still within the bounds of the item.
|
|
7
|
+
// https://github.com/mui/base-ui/issues/869
|
|
8
|
+
const isWithinBounds = targetRect.top + 1 <= event.clientY && event.clientY <= targetRect.bottom - 1 && targetRect.left + 1 <= event.clientX && event.clientX <= targetRect.right - 1;
|
|
9
|
+
return isWithinBounds;
|
|
10
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare function mergeObjects<A extends object | undefined, B extends object | undefined>(a: A, b: B): NonNullable<A> | NonNullable<B> | (A & B) | undefined;
|
package/esm/owner.d.ts
ADDED
package/esm/owner.js
ADDED
package/esm/package.json
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module","sideEffects":false}
|
package/esm/safeReact.js
ADDED
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Store } from "./Store.js";
|
|
2
|
+
/**
|
|
3
|
+
* A Store that supports controlled state keys, non-reactive values and provides utility methods for React.
|
|
4
|
+
*/
|
|
5
|
+
export declare class ReactStore<State extends object, Context = Record<string, never>, Selectors extends Record<string, SelectorFunction<State>> = Record<string, never>> extends Store<State> {
|
|
6
|
+
/**
|
|
7
|
+
* Creates a new ReactStore instance.
|
|
8
|
+
*
|
|
9
|
+
* @param state Initial state of the store.
|
|
10
|
+
* @param context Non-reactive context values.
|
|
11
|
+
* @param selectors Optional selectors for use with `useState`.
|
|
12
|
+
*/
|
|
13
|
+
constructor(state: State, context?: Context, selectors?: Selectors);
|
|
14
|
+
/**
|
|
15
|
+
* Non-reactive values such as refs, callbacks, etc.
|
|
16
|
+
*/
|
|
17
|
+
readonly context: Context;
|
|
18
|
+
private selectors;
|
|
19
|
+
/**
|
|
20
|
+
* Synchronizes a single external value into the store.
|
|
21
|
+
*
|
|
22
|
+
* Note that the while the value in `state` is updated immediately, the value returned
|
|
23
|
+
* by `useState` is updated before the next render (similarly to React's `useState`).
|
|
24
|
+
*/
|
|
25
|
+
useSyncedValue<Key extends keyof State, Value extends State[Key]>(key: keyof State, value: Value): void;
|
|
26
|
+
/**
|
|
27
|
+
* Synchronizes a single external value into the store and
|
|
28
|
+
* cleans it up (sets to `undefined`) on unmount.
|
|
29
|
+
*
|
|
30
|
+
* Note that the while the value in `state` is updated immediately, the value returned
|
|
31
|
+
* by `useState` is updated before the next render (similarly to React's `useState`).
|
|
32
|
+
*/
|
|
33
|
+
useSyncedValueWithCleanup<Key extends KeysAllowingUndefined<State>>(key: Key, value: State[Key]): void;
|
|
34
|
+
/**
|
|
35
|
+
* Synchronizes multiple external values into the store.
|
|
36
|
+
*
|
|
37
|
+
* Note that the while the values in `state` are updated immediately, the values returned
|
|
38
|
+
* by `useState` are updated before the next render (similarly to React's `useState`).
|
|
39
|
+
*/
|
|
40
|
+
useSyncedValues(statePart: Partial<State>): void;
|
|
41
|
+
/**
|
|
42
|
+
* Registers a controllable prop pair (`controlled`, `defaultValue`) for a specific key. If `controlled`
|
|
43
|
+
* is non-undefined, the store's state at `key` is updated to match `controlled`.
|
|
44
|
+
*/
|
|
45
|
+
useControlledProp<Key extends keyof State, Value extends State[Key]>(key: keyof State, controlled: Value | undefined): void;
|
|
46
|
+
/** Gets the current value from the store using a selector with the provided key.
|
|
47
|
+
*
|
|
48
|
+
* @param key Key of the selector to use.
|
|
49
|
+
*/
|
|
50
|
+
select<Key extends keyof Selectors>(key: Key, ...args: SelectorArgs<Selectors[Key]>): ReturnType<Selectors[Key]>;
|
|
51
|
+
/**
|
|
52
|
+
* Returns a value from the store's state using a selector function.
|
|
53
|
+
* Used to subscribe to specific parts of the state.
|
|
54
|
+
* This methods causes a rerender whenever the selected state changes.
|
|
55
|
+
*
|
|
56
|
+
* @param key Key of the selector to use.
|
|
57
|
+
*/
|
|
58
|
+
useState<Key extends keyof Selectors>(key: Key, ...args: SelectorArgs<Selectors[Key]>): ReturnType<Selectors[Key]>;
|
|
59
|
+
/**
|
|
60
|
+
* Wraps a function with `useStableCallback` to ensure it has a stable reference
|
|
61
|
+
* and assigns it to the context.
|
|
62
|
+
*
|
|
63
|
+
* @param key Key of the event callback. Must be a function in the context.
|
|
64
|
+
* @param fn Function to assign.
|
|
65
|
+
*/
|
|
66
|
+
useContextCallback<Key extends ContextFunctionKeys<Context>>(key: Key, fn: ContextFunction<Context, Key> | undefined): void;
|
|
67
|
+
/**
|
|
68
|
+
* Returns a stable setter function for a specific key in the store's state.
|
|
69
|
+
* It's commonly used to pass as a ref callback to React elements.
|
|
70
|
+
*
|
|
71
|
+
* @param key Key of the state to set.
|
|
72
|
+
*/
|
|
73
|
+
useStateSetter<const Key extends keyof State, Value extends State[Key]>(key: keyof State): (v: Value) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Observes changes derived from the store's selectors and calls the listener when the selected value changes.
|
|
76
|
+
*
|
|
77
|
+
* @param key Key of the selector to observe.
|
|
78
|
+
* @param listener Listener function called when the selector result changes.
|
|
79
|
+
*/
|
|
80
|
+
observe<Key extends keyof Selectors>(selector: Key, listener: (newValue: ReturnType<Selectors[Key]>, oldValue: ReturnType<Selectors[Key]>, store: this) => void): () => void;
|
|
81
|
+
observe<Selector extends ObserveSelector<State>>(selector: Selector, listener: (newValue: ReturnType<Selector>, oldValue: ReturnType<Selector>, store: this) => void): () => void;
|
|
82
|
+
}
|
|
83
|
+
type MaybeCallable = (...args: any[]) => any;
|
|
84
|
+
type ContextFunctionKeys<Context> = { [Key in keyof Context]-?: Extract<Context[Key], MaybeCallable> extends never ? never : Key }[keyof Context];
|
|
85
|
+
type ContextFunction<Context, Key extends keyof Context> = Extract<Context[Key], MaybeCallable>;
|
|
86
|
+
type KeysAllowingUndefined<State> = { [Key in keyof State]-?: undefined extends State[Key] ? Key : never }[keyof State];
|
|
87
|
+
type ObserveSelector<State> = (state: State) => any;
|
|
88
|
+
type SelectorFunction<State> = (state: State, ...args: any[]) => any;
|
|
89
|
+
type Tail<T extends readonly any[]> = T extends readonly [any, ...infer Rest] ? Rest : [];
|
|
90
|
+
type SelectorArgs<Selector> = Selector extends ((...params: infer Params) => any) ? Tail<Params> : never;
|
|
91
|
+
export {};
|