@sanity/ui 2.6.8 → 2.7.1-canary.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.mts +29 -2
- package/dist/index.d.ts +29 -2
- package/dist/index.esm.js +87 -73
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +86 -72
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +87 -73
- package/dist/index.mjs.map +1 -1
- package/package.json +50 -58
- package/src/core/components/dialog/dialogContext.ts +4 -5
- package/src/core/components/menu/menuContext.ts +4 -3
- package/src/core/components/toast/toastContext.ts +4 -3
- package/src/core/components/tree/treeContext.ts +4 -3
- package/src/core/hooks/index.ts +3 -2
- package/src/core/hooks/useMatchMedia.ts +52 -0
- package/src/core/hooks/useMediaIndex/useMediaIndex.ts +2 -10
- package/src/core/hooks/usePrefersDark.ts +10 -55
- package/src/core/hooks/usePrefersReducedMotion.ts +10 -56
- package/src/core/lib/createGlobalScopedContext.ts +15 -6
- package/src/core/primitives/tooltip/__workshop__/customPortal.tsx +8 -6
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupContext.tsx +4 -3
- package/src/core/theme/themeContext.ts +4 -3
- package/src/core/utils/boundaryElement/boundaryElementContext.ts +1 -3
- package/src/core/utils/layer/layerContext.ts +4 -3
- package/src/core/utils/portal/__workshop__/named.tsx +10 -8
- package/src/core/utils/portal/portalContext.ts +2 -2
- package/src/core/utils/portal/portalProvider.tsx +32 -2
- package/src/core/hooks/_internal/index.ts +0 -1
- package/src/core/hooks/_internal/useUnique.ts +0 -34
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {useMemo, useSyncExternalStore} from 'react'
|
|
2
|
-
import {useUnique} from '../../hooks/_internal'
|
|
1
|
+
import {useMemo, useRef, useSyncExternalStore} from 'react'
|
|
3
2
|
import {PortalContext} from './portalContext'
|
|
4
3
|
import {PortalContextValue} from './types'
|
|
5
4
|
|
|
@@ -44,3 +43,34 @@ export function PortalProvider(props: PortalProviderProps): React.ReactElement {
|
|
|
44
43
|
}
|
|
45
44
|
|
|
46
45
|
const emptySubscribe = () => () => {}
|
|
46
|
+
|
|
47
|
+
/**
|
|
48
|
+
* This is a React hook to make sure that a record identity is the same on every render. Uses strict
|
|
49
|
+
* equality comparison (eg by identity), and only goes one level deep.
|
|
50
|
+
*/
|
|
51
|
+
function useUnique<ValueType extends Comparable = Comparable>(value: ValueType): ValueType {
|
|
52
|
+
const valueRef = useRef<ValueType>(value)
|
|
53
|
+
|
|
54
|
+
if (!_isEqual(valueRef.current, value)) {
|
|
55
|
+
valueRef.current = value
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return valueRef.current
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
function _isEqual(objA: Comparable, objB: Comparable): boolean {
|
|
62
|
+
if (!objA || !objB) {
|
|
63
|
+
return objA === objB
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
const keysA = Object.keys(objA)
|
|
67
|
+
const keysB = Object.keys(objB)
|
|
68
|
+
|
|
69
|
+
if (keysA.length !== keysB.length) {
|
|
70
|
+
return false
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return keysA.every((key) => objA[key] === objB[key])
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
type Comparable = Record<string | number | symbol, unknown> | undefined | null
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './useUnique'
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import {useRef} from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* This is a React hook to make sure that a record identity is the same on every render. Uses strict
|
|
5
|
-
* equality comparison (eg by identity), and only goes one level deep.
|
|
6
|
-
*
|
|
7
|
-
* @internal
|
|
8
|
-
*/
|
|
9
|
-
type Comparable = Record<string | number | symbol, unknown> | undefined | null
|
|
10
|
-
|
|
11
|
-
export function useUnique<ValueType extends Comparable = Comparable>(value: ValueType): ValueType {
|
|
12
|
-
const valueRef = useRef<ValueType>(value)
|
|
13
|
-
|
|
14
|
-
if (!_isEqual(valueRef.current, value)) {
|
|
15
|
-
valueRef.current = value
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return valueRef.current
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
function _isEqual(objA: Comparable, objB: Comparable): boolean {
|
|
22
|
-
if (!objA || !objB) {
|
|
23
|
-
return objA === objB
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
const keysA = Object.keys(objA)
|
|
27
|
-
const keysB = Object.keys(objB)
|
|
28
|
-
|
|
29
|
-
if (keysA.length !== keysB.length) {
|
|
30
|
-
return false
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
return keysA.every((key) => objA[key] === objB[key])
|
|
34
|
-
}
|