@sanity/ui 3.0.11 → 3.0.12-canary.1
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/_chunks-cjs/_visual-editing.js +1124 -628
- package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
- package/dist/_chunks-es/_visual-editing.mjs +1127 -631
- package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
- package/dist/_visual-editing.d.mts +3 -7
- package/dist/_visual-editing.d.ts +3 -7
- package/dist/index.d.mts +11 -12
- package/dist/index.d.ts +11 -12
- package/dist/index.js +252 -295
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +254 -297
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -40
- package/src/core/components/autocomplete/autocomplete.tsx +2 -2
- package/src/core/components/breadcrumbs/breadcrumbs.tsx +70 -40
- package/src/core/components/dialog/dialog.tsx +10 -14
- package/src/core/components/hotkeys/hotkeys.tsx +2 -2
- package/src/core/components/menu/menuGroup.tsx +2 -2
- package/src/core/components/menu/menuItem.tsx +4 -4
- package/src/core/components/skeleton/skeleton.tsx +2 -2
- package/src/core/components/skeleton/textSkeleton.tsx +5 -5
- package/src/core/components/tree/tree.tsx +176 -182
- package/src/core/components/tree/treeGroup.tsx +2 -4
- package/src/core/components/tree/treeItem.tsx +5 -5
- package/src/core/hooks/index.ts +1 -1
- package/src/core/hooks/useArrayProp.ts +5 -17
- package/src/core/primitives/avatar/avatar.tsx +14 -16
- package/src/core/primitives/avatar/avatarCounter.tsx +14 -16
- package/src/core/primitives/avatar/avatarStack.tsx +2 -2
- package/src/core/primitives/badge/badge.tsx +3 -3
- package/src/core/primitives/box/box.tsx +26 -26
- package/src/core/primitives/button/button.tsx +11 -11
- package/src/core/primitives/card/card.tsx +8 -8
- package/src/core/primitives/code/code.tsx +2 -2
- package/src/core/primitives/container/container.tsx +2 -2
- package/src/core/primitives/flex/flex.tsx +6 -6
- package/src/core/primitives/grid/grid.tsx +9 -9
- package/src/core/primitives/heading/heading.tsx +3 -3
- package/src/core/primitives/inline/inline.tsx +2 -2
- package/src/core/primitives/kbd/kbd.tsx +2 -2
- package/src/core/primitives/label/label.tsx +3 -3
- package/src/core/primitives/popover/floating-ui/size.ts +32 -16
- package/src/core/primitives/popover/popover.tsx +355 -328
- package/src/core/primitives/popover/popoverCard.tsx +123 -125
- package/src/core/primitives/select/select.tsx +6 -5
- package/src/core/primitives/stack/stack.tsx +2 -2
- package/src/core/primitives/text/text.tsx +3 -3
- package/src/core/primitives/textArea/textArea.tsx +6 -5
- package/src/core/primitives/textInput/textInput.tsx +6 -5
- package/src/core/primitives/tooltip/tooltip.tsx +73 -44
- package/src/core/primitives/tooltip/tooltipCard.tsx +83 -85
- package/src/core/utils/layer/layerProvider.tsx +3 -2
- package/src/core/utils/virtualList/virtualList.tsx +48 -23
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {ThemeColorSchemeKey} from '@sanity/ui/theme'
|
|
2
2
|
import {motion, type MotionProps} from 'framer-motion'
|
|
3
|
-
import React, {CSSProperties, forwardRef,
|
|
3
|
+
import React, {CSSProperties, forwardRef, useMemo} from 'react'
|
|
4
4
|
import {styled} from 'styled-components'
|
|
5
5
|
|
|
6
6
|
import {POPOVER_MOTION_PROPS} from '../../constants'
|
|
@@ -20,92 +20,90 @@ const MotionCard = styled(motion.create(Card))`
|
|
|
20
20
|
/**
|
|
21
21
|
* @internal
|
|
22
22
|
*/
|
|
23
|
-
export const TooltipCard =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
23
|
+
export const TooltipCard = forwardRef(function TooltipCard(
|
|
24
|
+
props: {
|
|
25
|
+
animate?: boolean
|
|
26
|
+
arrow: boolean
|
|
27
|
+
arrowRef: React.Ref<HTMLDivElement>
|
|
28
|
+
arrowX?: number
|
|
29
|
+
arrowY?: number
|
|
30
|
+
originX?: number
|
|
31
|
+
originY?: number
|
|
32
|
+
padding?: number | number[]
|
|
33
|
+
placement?: Placement
|
|
34
|
+
radius?: Radius | Radius[]
|
|
35
|
+
scheme?: ThemeColorSchemeKey
|
|
36
|
+
shadow?: number | number[]
|
|
37
|
+
} & Omit<React.HTMLProps<HTMLDivElement>, 'as' | 'height' | 'width'>,
|
|
38
|
+
ref: React.ForwardedRef<HTMLDivElement>,
|
|
39
|
+
) {
|
|
40
|
+
const {
|
|
41
|
+
animate,
|
|
42
|
+
arrow,
|
|
43
|
+
arrowRef,
|
|
44
|
+
arrowX,
|
|
45
|
+
arrowY,
|
|
46
|
+
children,
|
|
47
|
+
originX,
|
|
48
|
+
originY,
|
|
49
|
+
padding,
|
|
50
|
+
placement,
|
|
51
|
+
radius,
|
|
52
|
+
scheme,
|
|
53
|
+
shadow,
|
|
54
|
+
style,
|
|
55
|
+
...restProps
|
|
56
|
+
} = props
|
|
57
|
+
|
|
58
|
+
const rootStyle: CSSProperties = useMemo(
|
|
59
|
+
() => ({
|
|
48
60
|
originX,
|
|
49
61
|
originY,
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
style,
|
|
56
|
-
...restProps
|
|
57
|
-
} = props
|
|
58
|
-
|
|
59
|
-
const rootStyle: CSSProperties = useMemo(
|
|
60
|
-
() => ({
|
|
61
|
-
originX,
|
|
62
|
-
originY,
|
|
63
|
-
willChange: animate ? 'transform' : undefined,
|
|
64
|
-
...style,
|
|
65
|
-
}),
|
|
66
|
-
[animate, originX, originY, style],
|
|
67
|
-
)
|
|
62
|
+
willChange: animate ? 'transform' : undefined,
|
|
63
|
+
...style,
|
|
64
|
+
}),
|
|
65
|
+
[animate, originX, originY, style],
|
|
66
|
+
)
|
|
68
67
|
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
68
|
+
const arrowStyle: CSSProperties = useMemo(
|
|
69
|
+
() => ({
|
|
70
|
+
left: arrowX !== null ? arrowX : undefined,
|
|
71
|
+
top: arrowY !== null ? arrowY : undefined,
|
|
72
|
+
right: undefined,
|
|
73
|
+
bottom: undefined,
|
|
74
|
+
}),
|
|
75
|
+
[arrowX, arrowY],
|
|
76
|
+
)
|
|
78
77
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
return (
|
|
79
|
+
<MotionCard
|
|
80
|
+
data-ui="Tooltip__card"
|
|
81
|
+
{...(restProps as CardProps & MotionProps)}
|
|
82
|
+
data-placement={placement}
|
|
83
|
+
padding={padding}
|
|
84
|
+
radius={radius}
|
|
85
|
+
ref={ref}
|
|
86
|
+
scheme={scheme}
|
|
87
|
+
shadow={shadow}
|
|
88
|
+
style={rootStyle}
|
|
89
|
+
variants={POPOVER_MOTION_PROPS.card}
|
|
90
|
+
transition={POPOVER_MOTION_PROPS.transition}
|
|
91
|
+
initial={animate ? ['hidden', 'initial'] : undefined}
|
|
92
|
+
animate={animate ? ['visible', 'scaleIn'] : undefined}
|
|
93
|
+
exit={animate ? ['hidden', 'scaleOut'] : undefined}
|
|
94
|
+
>
|
|
95
|
+
{children}
|
|
97
96
|
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
)
|
|
111
|
-
TooltipCard.displayName = 'Memo(ForwardRef(TooltipCard))'
|
|
97
|
+
{arrow && (
|
|
98
|
+
<Arrow
|
|
99
|
+
ref={arrowRef}
|
|
100
|
+
style={arrowStyle}
|
|
101
|
+
width={DEFAULT_TOOLTIP_ARROW_WIDTH}
|
|
102
|
+
height={DEFAULT_TOOLTIP_ARROW_HEIGHT}
|
|
103
|
+
radius={DEFAULT_TOOLTIP_ARROW_RADIUS}
|
|
104
|
+
/>
|
|
105
|
+
)}
|
|
106
|
+
</MotionCard>
|
|
107
|
+
)
|
|
108
|
+
})
|
|
109
|
+
TooltipCard.displayName = 'ForwardRef(TooltipCard)'
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {useCallback, useContext, useEffect, useMemo, useState} from 'react'
|
|
2
2
|
|
|
3
|
-
import {
|
|
3
|
+
import {useMediaIndex} from '../../hooks'
|
|
4
|
+
import {getArrayProp} from '../../hooks/useArrayProp'
|
|
4
5
|
import {getLayerContext} from './getLayerContext'
|
|
5
6
|
import {LayerContext} from './layerContext'
|
|
6
7
|
import {LayerContextValue} from './types'
|
|
@@ -29,7 +30,7 @@ export function LayerProvider(props: LayerProviderProps): React.JSX.Element {
|
|
|
29
30
|
const level = parentLevel + 1
|
|
30
31
|
|
|
31
32
|
// Get z-index offset
|
|
32
|
-
const zOffset =
|
|
33
|
+
const zOffset = getArrayProp(zOffsetProp)
|
|
33
34
|
|
|
34
35
|
// Get responsive z-index value
|
|
35
36
|
const maxMediaIndex = zOffset.length - 1
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {forwardRef, useEffect, useImperativeHandle,
|
|
1
|
+
import {forwardRef, useEffect, useImperativeHandle, useRef, useState} from 'react'
|
|
2
2
|
import {styled} from 'styled-components'
|
|
3
3
|
|
|
4
4
|
import {_isScrollable} from '../../helpers'
|
|
@@ -131,31 +131,20 @@ export const VirtualList = forwardRef(function VirtualList(
|
|
|
131
131
|
onChange({fromIndex, gap: space[gap], itemHeight, scrollHeight, scrollTop, toIndex})
|
|
132
132
|
}, [fromIndex, gap, itemHeight, onChange, scrollHeight, scrollTop, space, toIndex])
|
|
133
133
|
|
|
134
|
-
const children =
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
const key = getItemKey ? getItemKey(item, itemIndex) : itemIndex
|
|
145
|
-
|
|
146
|
-
return (
|
|
147
|
-
<ItemWrapper key={key} style={{top: itemIndex * (itemHeight + space[gap])}}>
|
|
148
|
-
{node}
|
|
149
|
-
</ItemWrapper>
|
|
150
|
-
)
|
|
151
|
-
})
|
|
152
|
-
}, [fromIndex, gap, getItemKey, itemHeight, items, renderItem, space, toIndex])
|
|
153
|
-
|
|
154
|
-
const wrapperStyle = useMemo(() => ({height}), [height])
|
|
134
|
+
const children = useChildren({
|
|
135
|
+
fromIndex,
|
|
136
|
+
gap,
|
|
137
|
+
itemHeight,
|
|
138
|
+
space,
|
|
139
|
+
toIndex,
|
|
140
|
+
getItemKey,
|
|
141
|
+
items,
|
|
142
|
+
renderItem,
|
|
143
|
+
})
|
|
155
144
|
|
|
156
145
|
return (
|
|
157
146
|
<StyledVirtualList as={as} data-ui="VirtualList" {...restProps} ref={ref}>
|
|
158
|
-
<div ref={wrapperRef} style={
|
|
147
|
+
<div ref={wrapperRef} style={{height}}>
|
|
159
148
|
{children}
|
|
160
149
|
</div>
|
|
161
150
|
</StyledVirtualList>
|
|
@@ -163,6 +152,42 @@ export const VirtualList = forwardRef(function VirtualList(
|
|
|
163
152
|
})
|
|
164
153
|
VirtualList.displayName = 'ForwardRef(VirtualList)'
|
|
165
154
|
|
|
155
|
+
function useChildren({
|
|
156
|
+
fromIndex,
|
|
157
|
+
gap,
|
|
158
|
+
getItemKey,
|
|
159
|
+
itemHeight,
|
|
160
|
+
items,
|
|
161
|
+
renderItem,
|
|
162
|
+
space,
|
|
163
|
+
toIndex,
|
|
164
|
+
}: Pick<VirtualListProps, 'getItemKey' | 'renderItem'> &
|
|
165
|
+
Required<Pick<VirtualListProps, 'items'>> & {
|
|
166
|
+
fromIndex: number
|
|
167
|
+
gap: number
|
|
168
|
+
itemHeight: number
|
|
169
|
+
space: number[]
|
|
170
|
+
toIndex: number
|
|
171
|
+
}) {
|
|
172
|
+
if (!renderItem || items.length === 0) return null
|
|
173
|
+
|
|
174
|
+
if (itemHeight === -1) {
|
|
175
|
+
return [<ItemWrapper key={0}>{renderItem(items[0])}</ItemWrapper>]
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
return items.slice(fromIndex, toIndex).map((item, _itemIndex) => {
|
|
179
|
+
const itemIndex = fromIndex + _itemIndex
|
|
180
|
+
const node = renderItem(item)
|
|
181
|
+
const key = getItemKey ? getItemKey(item, itemIndex) : itemIndex
|
|
182
|
+
|
|
183
|
+
return (
|
|
184
|
+
<ItemWrapper key={key} style={{top: itemIndex * (itemHeight + space[gap])}}>
|
|
185
|
+
{node}
|
|
186
|
+
</ItemWrapper>
|
|
187
|
+
)
|
|
188
|
+
})
|
|
189
|
+
}
|
|
190
|
+
|
|
166
191
|
function findScrollable(parentNode: ParentNode | null) {
|
|
167
192
|
let _scrollEl = parentNode
|
|
168
193
|
|