@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.
Files changed (53) hide show
  1. package/dist/_chunks-cjs/_visual-editing.js +1124 -628
  2. package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
  3. package/dist/_chunks-es/_visual-editing.mjs +1127 -631
  4. package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
  5. package/dist/_visual-editing.d.mts +3 -7
  6. package/dist/_visual-editing.d.ts +3 -7
  7. package/dist/index.d.mts +11 -12
  8. package/dist/index.d.ts +11 -12
  9. package/dist/index.js +252 -295
  10. package/dist/index.js.map +1 -1
  11. package/dist/index.mjs +254 -297
  12. package/dist/index.mjs.map +1 -1
  13. package/package.json +26 -40
  14. package/src/core/components/autocomplete/autocomplete.tsx +2 -2
  15. package/src/core/components/breadcrumbs/breadcrumbs.tsx +70 -40
  16. package/src/core/components/dialog/dialog.tsx +10 -14
  17. package/src/core/components/hotkeys/hotkeys.tsx +2 -2
  18. package/src/core/components/menu/menuGroup.tsx +2 -2
  19. package/src/core/components/menu/menuItem.tsx +4 -4
  20. package/src/core/components/skeleton/skeleton.tsx +2 -2
  21. package/src/core/components/skeleton/textSkeleton.tsx +5 -5
  22. package/src/core/components/tree/tree.tsx +176 -182
  23. package/src/core/components/tree/treeGroup.tsx +2 -4
  24. package/src/core/components/tree/treeItem.tsx +5 -5
  25. package/src/core/hooks/index.ts +1 -1
  26. package/src/core/hooks/useArrayProp.ts +5 -17
  27. package/src/core/primitives/avatar/avatar.tsx +14 -16
  28. package/src/core/primitives/avatar/avatarCounter.tsx +14 -16
  29. package/src/core/primitives/avatar/avatarStack.tsx +2 -2
  30. package/src/core/primitives/badge/badge.tsx +3 -3
  31. package/src/core/primitives/box/box.tsx +26 -26
  32. package/src/core/primitives/button/button.tsx +11 -11
  33. package/src/core/primitives/card/card.tsx +8 -8
  34. package/src/core/primitives/code/code.tsx +2 -2
  35. package/src/core/primitives/container/container.tsx +2 -2
  36. package/src/core/primitives/flex/flex.tsx +6 -6
  37. package/src/core/primitives/grid/grid.tsx +9 -9
  38. package/src/core/primitives/heading/heading.tsx +3 -3
  39. package/src/core/primitives/inline/inline.tsx +2 -2
  40. package/src/core/primitives/kbd/kbd.tsx +2 -2
  41. package/src/core/primitives/label/label.tsx +3 -3
  42. package/src/core/primitives/popover/floating-ui/size.ts +32 -16
  43. package/src/core/primitives/popover/popover.tsx +355 -328
  44. package/src/core/primitives/popover/popoverCard.tsx +123 -125
  45. package/src/core/primitives/select/select.tsx +6 -5
  46. package/src/core/primitives/stack/stack.tsx +2 -2
  47. package/src/core/primitives/text/text.tsx +3 -3
  48. package/src/core/primitives/textArea/textArea.tsx +6 -5
  49. package/src/core/primitives/textInput/textInput.tsx +6 -5
  50. package/src/core/primitives/tooltip/tooltip.tsx +73 -44
  51. package/src/core/primitives/tooltip/tooltipCard.tsx +83 -85
  52. package/src/core/utils/layer/layerProvider.tsx +3 -2
  53. package/src/core/utils/virtualList/virtualList.tsx +48 -23
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {getArrayProp} from '../../hooks/useArrayProp'
5
5
  import {
6
6
  boxStyle,
7
7
  flexItemStyle,
@@ -96,31 +96,31 @@ export const Box = forwardRef(function Box(
96
96
  data-as={typeof asProp === 'string' ? asProp : undefined}
97
97
  data-ui="Box"
98
98
  {...restProps}
99
- $column={useArrayProp(column)}
100
- $columnStart={useArrayProp(columnStart)}
101
- $columnEnd={useArrayProp(columnEnd)}
102
- $display={useArrayProp(display)}
103
- $flex={useArrayProp(flex)}
104
- $height={useArrayProp(height)}
105
- $margin={useArrayProp(margin)}
106
- $marginX={useArrayProp(marginX)}
107
- $marginY={useArrayProp(marginY)}
108
- $marginTop={useArrayProp(marginTop)}
109
- $marginRight={useArrayProp(marginRight)}
110
- $marginBottom={useArrayProp(marginBottom)}
111
- $marginLeft={useArrayProp(marginLeft)}
112
- $overflow={useArrayProp(overflow)}
113
- $padding={useArrayProp(padding)}
114
- $paddingX={useArrayProp(paddingX)}
115
- $paddingY={useArrayProp(paddingY)}
116
- $paddingTop={useArrayProp(paddingTop)}
117
- $paddingRight={useArrayProp(paddingRight)}
118
- $paddingBottom={useArrayProp(paddingBottom)}
119
- $paddingLeft={useArrayProp(paddingLeft)}
120
- $row={useArrayProp(row)}
121
- $rowStart={useArrayProp(rowStart)}
122
- $rowEnd={useArrayProp(rowEnd)}
123
- $sizing={useArrayProp(sizing)}
99
+ $column={getArrayProp(column)}
100
+ $columnStart={getArrayProp(columnStart)}
101
+ $columnEnd={getArrayProp(columnEnd)}
102
+ $display={getArrayProp(display)}
103
+ $flex={getArrayProp(flex)}
104
+ $height={getArrayProp(height)}
105
+ $margin={getArrayProp(margin)}
106
+ $marginX={getArrayProp(marginX)}
107
+ $marginY={getArrayProp(marginY)}
108
+ $marginTop={getArrayProp(marginTop)}
109
+ $marginRight={getArrayProp(marginRight)}
110
+ $marginBottom={getArrayProp(marginBottom)}
111
+ $marginLeft={getArrayProp(marginLeft)}
112
+ $overflow={getArrayProp(overflow)}
113
+ $padding={getArrayProp(padding)}
114
+ $paddingX={getArrayProp(paddingX)}
115
+ $paddingY={getArrayProp(paddingY)}
116
+ $paddingTop={getArrayProp(paddingTop)}
117
+ $paddingRight={getArrayProp(paddingRight)}
118
+ $paddingBottom={getArrayProp(paddingBottom)}
119
+ $paddingLeft={getArrayProp(paddingLeft)}
120
+ $row={getArrayProp(row)}
121
+ $rowStart={getArrayProp(rowStart)}
122
+ $rowEnd={getArrayProp(rowEnd)}
123
+ $sizing={getArrayProp(sizing)}
124
124
  as={asProp}
125
125
  ref={ref}
126
126
  >
@@ -3,7 +3,7 @@ import {forwardRef, isValidElement, useMemo} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
4
  import {styled} from 'styled-components'
5
5
 
6
- import {useArrayProp} from '../../hooks'
6
+ import {getArrayProp} from '../../hooks/useArrayProp'
7
7
  import {ThemeProps} from '../../styles'
8
8
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
9
9
  import {useTheme_v2} from '../../theme'
@@ -97,16 +97,16 @@ export const Button = forwardRef(function Button(
97
97
  } = props
98
98
  const {button} = useTheme_v2()
99
99
 
100
- const justify = useArrayProp(justifyProp)
101
- const padding = useArrayProp(paddingProp)
102
- const paddingX = useArrayProp(paddingXProp)
103
- const paddingY = useArrayProp(paddingYProp)
104
- const paddingTop = useArrayProp(paddingTopProp)
105
- const paddingBottom = useArrayProp(paddingBottomProp)
106
- const paddingLeft = useArrayProp(paddingLeftProp)
107
- const paddingRight = useArrayProp(paddingRightProp)
108
- const radius = useArrayProp(radiusProp)
109
- const space = useArrayProp(spaceProp)
100
+ const justify = getArrayProp(justifyProp)
101
+ const padding = getArrayProp(paddingProp)
102
+ const paddingX = getArrayProp(paddingXProp)
103
+ const paddingY = getArrayProp(paddingYProp)
104
+ const paddingTop = getArrayProp(paddingTopProp)
105
+ const paddingBottom = getArrayProp(paddingBottomProp)
106
+ const paddingLeft = getArrayProp(paddingLeftProp)
107
+ const paddingRight = getArrayProp(paddingRightProp)
108
+ const radius = getArrayProp(radiusProp)
109
+ const space = getArrayProp(spaceProp)
110
110
 
111
111
  const boxProps = useMemo(
112
112
  () => ({
@@ -3,7 +3,7 @@ import {forwardRef} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
4
  import {styled} from 'styled-components'
5
5
 
6
- import {useArrayProp} from '../../hooks'
6
+ import {getArrayProp} from '../../hooks/useArrayProp'
7
7
  import {
8
8
  responsiveBorderStyle,
9
9
  ResponsiveBorderStyleProps,
@@ -93,16 +93,16 @@ export const Card = forwardRef(function Card(
93
93
  data-ui="Card"
94
94
  data-tone={tone}
95
95
  {...restProps}
96
- $border={useArrayProp(border)}
97
- $borderTop={useArrayProp(borderTop)}
98
- $borderRight={useArrayProp(borderRight)}
99
- $borderBottom={useArrayProp(borderBottom)}
100
- $borderLeft={useArrayProp(borderLeft)}
96
+ $border={getArrayProp(border)}
97
+ $borderTop={getArrayProp(borderTop)}
98
+ $borderRight={getArrayProp(borderRight)}
99
+ $borderBottom={getArrayProp(borderBottom)}
100
+ $borderLeft={getArrayProp(borderLeft)}
101
101
  $checkered={checkered}
102
102
  $focusRing={focusRing}
103
103
  $muted={muted}
104
- $radius={useArrayProp(radius)}
105
- $shadow={useArrayProp(shadow)}
104
+ $radius={getArrayProp(radius)}
105
+ $shadow={getArrayProp(shadow)}
106
106
  $tone={tone}
107
107
  data-checkered={checkered ? '' : undefined}
108
108
  data-pressed={pressed ? '' : undefined}
@@ -1,7 +1,7 @@
1
1
  import {forwardRef, lazy, Suspense} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {getArrayProp} from '../../hooks/useArrayProp'
5
5
  import {responsiveCodeFontStyle, ResponsiveFontStyleProps} from '../../styles/internal'
6
6
  import {codeBaseStyle} from './styles'
7
7
 
@@ -30,7 +30,7 @@ export const Code = forwardRef(function Code(
30
30
  const {children, language, size = 2, weight, ...restProps} = props
31
31
 
32
32
  return (
33
- <StyledCode data-ui="Code" {...restProps} $size={useArrayProp(size)} $weight={weight} ref={ref}>
33
+ <StyledCode data-ui="Code" {...restProps} $size={getArrayProp(size)} $weight={weight} ref={ref}>
34
34
  <Suspense fallback={<code>{children}</code>}>
35
35
  <LazyRefractor language={language} value={children} />
36
36
  </Suspense>
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {getArrayProp} from '../../hooks/useArrayProp'
5
5
  import {Box, BoxProps} from '../box'
6
6
  import {ResponsiveWidthProps} from '../types'
7
7
  import {containerBaseStyle, responsiveContainerWidthStyle} from './styles'
@@ -32,7 +32,7 @@ export const Container = forwardRef(function Container(
32
32
  <StyledContainer
33
33
  data-ui="Container"
34
34
  {...restProps}
35
- $width={useArrayProp(width)}
35
+ $width={getArrayProp(width)}
36
36
  forwardedAs={as}
37
37
  ref={ref}
38
38
  />
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {getArrayProp} from '../../hooks/useArrayProp'
5
5
  import {
6
6
  flexItemStyle,
7
7
  FlexItemStyleProps,
@@ -41,11 +41,11 @@ export const Flex = forwardRef(function Flex(
41
41
  <StyledFlex
42
42
  data-ui="Flex"
43
43
  {...restProps}
44
- $align={useArrayProp(align)}
45
- $direction={useArrayProp(direction)}
46
- $gap={useArrayProp(gap)}
47
- $justify={useArrayProp(justify)}
48
- $wrap={useArrayProp(wrap)}
44
+ $align={getArrayProp(align)}
45
+ $direction={getArrayProp(direction)}
46
+ $gap={getArrayProp(gap)}
47
+ $justify={getArrayProp(justify)}
48
+ $wrap={getArrayProp(wrap)}
49
49
  forwardedAs={as}
50
50
  ref={ref}
51
51
  />
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {getArrayProp} from '../../hooks/useArrayProp'
5
5
  import {responsiveGridStyle, ResponsiveGridStyleProps} from '../../styles/internal'
6
6
  import {Box, BoxProps} from '../box'
7
7
  import {ResponsiveGridProps} from '../types'
@@ -30,14 +30,14 @@ export const Grid = forwardRef(function Grid(
30
30
  data-as={typeof as === 'string' ? as : undefined}
31
31
  data-ui="Grid"
32
32
  {...restProps}
33
- $autoRows={useArrayProp(autoRows)}
34
- $autoCols={useArrayProp(autoCols)}
35
- $autoFlow={useArrayProp(autoFlow)}
36
- $columns={useArrayProp(columns)}
37
- $gap={useArrayProp(gap)}
38
- $gapX={useArrayProp(gapX)}
39
- $gapY={useArrayProp(gapY)}
40
- $rows={useArrayProp(rows)}
33
+ $autoRows={getArrayProp(autoRows)}
34
+ $autoCols={getArrayProp(autoCols)}
35
+ $autoFlow={getArrayProp(autoFlow)}
36
+ $columns={getArrayProp(columns)}
37
+ $gap={getArrayProp(gap)}
38
+ $gapX={getArrayProp(gapX)}
39
+ $gapY={getArrayProp(gapY)}
40
+ $rows={getArrayProp(rows)}
41
41
  forwardedAs={as}
42
42
  ref={ref}
43
43
  >
@@ -2,7 +2,7 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
4
 
5
- import {useArrayProp} from '../../hooks'
5
+ import {getArrayProp} from '../../hooks/useArrayProp'
6
6
  import {
7
7
  ResponsiveFontStyleProps,
8
8
  responsiveHeadingFont,
@@ -67,9 +67,9 @@ export const Heading = forwardRef(function Heading(
67
67
  data-ui="Heading"
68
68
  {...restProps}
69
69
  $accent={accent}
70
- $align={useArrayProp(align)}
70
+ $align={getArrayProp(align)}
71
71
  $muted={muted}
72
- $size={useArrayProp(size)}
72
+ $size={getArrayProp(size)}
73
73
  $weight={weight}
74
74
  ref={ref}
75
75
  >
@@ -1,7 +1,7 @@
1
1
  import {Children, forwardRef, useMemo} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {getArrayProp} from '../../hooks/useArrayProp'
5
5
  import {Box, BoxProps} from '../box'
6
6
  import {inlineBaseStyle, inlineSpaceStyle} from './styles'
7
7
  import {ResponsiveInlineSpaceStyleProps} from './types'
@@ -36,7 +36,7 @@ export const Inline = forwardRef(function Inline(
36
36
  <StyledInline
37
37
  data-ui="Inline"
38
38
  {...restProps}
39
- $space={useArrayProp(space)}
39
+ $space={getArrayProp(space)}
40
40
  forwardedAs={as}
41
41
  ref={ref as any}
42
42
  >
@@ -1,7 +1,7 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {css, styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
4
+ import {getArrayProp} from '../../hooks/useArrayProp'
5
5
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
6
6
  import {Radius} from '../../types'
7
7
  import {Box} from '../box'
@@ -49,7 +49,7 @@ export const KBD = forwardRef(function KBD(
49
49
  const {children, fontSize = 0, padding = 1, radius = 2, ...restProps} = props
50
50
 
51
51
  return (
52
- <StyledKBD data-ui="KBD" {...restProps} $radius={useArrayProp(radius)} ref={ref}>
52
+ <StyledKBD data-ui="KBD" {...restProps} $radius={getArrayProp(radius)} ref={ref}>
53
53
  <Box as="span" padding={padding}>
54
54
  <Text as="span" size={fontSize} weight="semibold">
55
55
  {children}
@@ -2,7 +2,7 @@ import {ThemeFontWeightKey} from '@sanity/ui/theme'
2
2
  import {forwardRef} from 'react'
3
3
  import {styled} from 'styled-components'
4
4
 
5
- import {useArrayProp} from '../../hooks'
5
+ import {getArrayProp} from '../../hooks/useArrayProp'
6
6
  import {responsiveLabelFont, responsiveTextAlignStyle} from '../../styles/internal'
7
7
  import {TextAlign} from '../../types'
8
8
  import {SpanWithTextOverflow} from '../../utils/spanWithTextOverflow'
@@ -66,9 +66,9 @@ export const Label = forwardRef(function Label(
66
66
  data-ui="Label"
67
67
  {...restProps}
68
68
  $accent={accent}
69
- $align={useArrayProp(align)}
69
+ $align={getArrayProp(align)}
70
70
  $muted={muted}
71
- $size={useArrayProp(size)}
71
+ $size={getArrayProp(size)}
72
72
  $weight={weight}
73
73
  ref={ref}
74
74
  >
@@ -1,23 +1,28 @@
1
- import {detectOverflow, Elements, Middleware} from '@floating-ui/react-dom'
1
+ import {detectOverflow, Middleware} from '@floating-ui/react-dom'
2
2
 
3
3
  import {PopoverMargins} from '../../../types'
4
4
 
5
- export interface SizeMiddlewareApplyOptions {
6
- availableWidth: number
7
- availableHeight: number
8
- elements: Elements
9
- referenceWidth: number
10
- }
11
-
12
5
  export function size(options: {
13
- apply: (args: SizeMiddlewareApplyOptions) => void
14
6
  boundaryElement?: HTMLElement | null
15
7
  constrainSize: boolean
16
8
  margins: PopoverMargins
17
9
  matchReferenceWidth?: boolean
10
+ maxWidthRef: React.RefObject<number | undefined>
18
11
  padding?: number
12
+ referenceWidthRef: React.RefObject<number | undefined>
13
+ setReferenceWidth: (referenceWidth: number) => void
14
+ widthRef: React.RefObject<number | undefined>
19
15
  }): Middleware {
20
- const {apply, margins, padding = 0} = options
16
+ const {
17
+ constrainSize,
18
+ margins,
19
+ matchReferenceWidth,
20
+ maxWidthRef,
21
+ padding = 0,
22
+ referenceWidthRef,
23
+ setReferenceWidth,
24
+ widthRef,
25
+ } = options
21
26
 
22
27
  return {
23
28
  name: '@sanity/ui/size',
@@ -61,12 +66,23 @@ export function size(options: {
61
66
 
62
67
  // IMPORTANT – APPLY ELEMENT STYLES HERE
63
68
  // Elements need to be resized BEFORE the `platform.getDimensions` call below
64
- apply({
65
- availableWidth: maxWidth - margins[1] - margins[3],
66
- availableHeight: maxHeight - margins[0] - margins[2],
67
- elements,
68
- referenceWidth: reference.width - margins[1] - margins[3],
69
- })
69
+ const availableWidth = maxWidth - margins[1] - margins[3]
70
+ const availableHeight = maxHeight - margins[0] - margins[2]
71
+ const referenceWidth = reference.width - margins[1] - margins[3]
72
+ referenceWidthRef.current = referenceWidth
73
+ setReferenceWidth(referenceWidth)
74
+
75
+ if (matchReferenceWidth) {
76
+ elements.floating.style.width = `${referenceWidth}px`
77
+ } else if (widthRef.current !== undefined) {
78
+ elements.floating.style.width = `${widthRef.current}px`
79
+ }
80
+
81
+ if (constrainSize) {
82
+ elements.floating.style.maxWidth = `${Math.min(availableWidth, maxWidthRef.current ?? Infinity)}px`
83
+
84
+ elements.floating.style.maxHeight = `${availableHeight}px`
85
+ }
70
86
 
71
87
  const nextDimensions = await platform.getDimensions(elements.floating)
72
88