@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
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "3.0.11",
3
+ "version": "3.0.12-canary.1",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -60,32 +60,6 @@
60
60
  "exports",
61
61
  "src"
62
62
  ],
63
- "scripts": {
64
- "build": "run-s clean pkg:build pkg:check figma:pkg:build",
65
- "clean": "rimraf .workshop dist",
66
- "commit": "cz",
67
- "cypress:dev": "run-p dev cypress:open",
68
- "cypress:open": "cypress open",
69
- "cypress:run": "cypress run",
70
- "dev": "run-p storybook:dev workshop:dev",
71
- "figma:pkg:build": "cd figma && pnpm build",
72
- "format": "prettier --write --cache --ignore-unknown .",
73
- "lint": "eslint --cache .",
74
- "prepack": "pnpm build",
75
- "pkg:build": "pkg build --strict",
76
- "pkg:check": "pkg --strict",
77
- "prepare": "husky install",
78
- "release": "semantic-release",
79
- "storybook:build": "storybook build",
80
- "storybook:dev": "storybook dev -p 6006",
81
- "test": "jest",
82
- "test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
83
- "ts:check": "tsc",
84
- "watch": "pkg watch --strict",
85
- "workshop:build": "workshop build",
86
- "workshop:dev": "workshop dev",
87
- "workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
88
- },
89
63
  "commitlint": {
90
64
  "extends": [
91
65
  "@commitlint/config-conventional"
@@ -210,25 +184,37 @@
210
184
  "react-is": "^18 || >=19.0.0-0",
211
185
  "styled-components": "^5.2 || ^6"
212
186
  },
213
- "packageManager": "pnpm@9.15.9",
214
187
  "engines": {
215
188
  "node": ">=20.19 <22 || >=22.12"
216
189
  },
217
190
  "publishConfig": {
218
191
  "access": "public"
219
192
  },
220
- "pnpm": {
221
- "overrides": {
222
- "@types/react": "$@types/react",
223
- "@types/react-dom": "$@types/react-dom",
224
- "@types/react-is": "$@types/react-is",
225
- "conventional-changelog-conventionalcommits": ">= 8.0.0",
226
- "react": "$react",
227
- "react-dom": "$react-dom",
228
- "react-is": "$react-is"
229
- }
230
- },
231
193
  "esm.sh": {
232
194
  "bundle": false
195
+ },
196
+ "scripts": {
197
+ "build": "run-s clean pkg:build pkg:check figma:pkg:build",
198
+ "clean": "rimraf .workshop dist",
199
+ "commit": "cz",
200
+ "cypress:dev": "run-p dev cypress:open",
201
+ "cypress:open": "cypress open",
202
+ "cypress:run": "cypress run",
203
+ "dev": "run-p storybook:dev workshop:dev",
204
+ "figma:pkg:build": "cd figma && pnpm build",
205
+ "format": "prettier --write --cache --ignore-unknown .",
206
+ "lint": "eslint .",
207
+ "pkg:build": "pkg build --strict",
208
+ "pkg:check": "pkg --strict",
209
+ "release": "semantic-release",
210
+ "storybook:build": "storybook build",
211
+ "storybook:dev": "storybook dev -p 6006",
212
+ "test": "jest",
213
+ "test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
214
+ "ts:check": "tsc",
215
+ "watch": "pkg watch --strict",
216
+ "workshop:build": "workshop build",
217
+ "workshop:dev": "workshop dev",
218
+ "workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
233
219
  }
234
- }
220
+ }
@@ -21,7 +21,6 @@ import {
21
21
 
22
22
  import {EMPTY_ARRAY, EMPTY_RECORD} from '../../constants'
23
23
  import {_hasFocus, _raf, focusFirstDescendant} from '../../helpers'
24
- import {useArrayProp} from '../../hooks'
25
24
  import {
26
25
  Box,
27
26
  BoxProps,
@@ -33,6 +32,7 @@ import {
33
32
  Text,
34
33
  TextInput,
35
34
  } from '../../primitives'
35
+ import {_getArrayProp} from '../../styles'
36
36
  import {Radius} from '../../types'
37
37
  import {AnimatedSpinnerIcon, ListBox, StyledAutocomplete} from './autocomplete.styles'
38
38
  import {AutocompleteOption} from './autocompleteOption'
@@ -214,7 +214,7 @@ const InnerAutocomplete = forwardRef(function InnerAutocomplete<
214
214
 
215
215
  const listBoxId = `${id}-listbox`
216
216
  const options = Array.isArray(optionsProp) ? optionsProp : EMPTY_ARRAY
217
- const padding = useArrayProp(paddingProp)
217
+ const padding = _getArrayProp(paddingProp)
218
218
  const currentOption = useMemo(
219
219
  () => (value !== null ? options.find((o) => o.value === value) : undefined),
220
220
  [options, value],
@@ -9,8 +9,9 @@ import {
9
9
  useState,
10
10
  } from 'react'
11
11
 
12
- import {useArrayProp, useClickOutsideEvent} from '../../hooks'
12
+ import {useClickOutsideEvent} from '../../hooks'
13
13
  import {Box, Popover, Stack, Text} from '../../primitives'
14
+ import {_getArrayProp} from '../../styles'
14
15
  import {ExpandButton, StyledBreadcrumbs} from './breadcrumbs.styles'
15
16
 
16
17
  /**
@@ -30,7 +31,7 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
30
31
  ref: React.ForwardedRef<HTMLOListElement>,
31
32
  ) {
32
33
  const {children, maxLength, separator, space: spaceRaw = 2, ...restProps} = props
33
- const space = useArrayProp(spaceRaw)
34
+ const space = _getArrayProp(spaceRaw)
34
35
  const [open, setOpen] = useState(false)
35
36
  const expandElementRef = useRef<HTMLButtonElement | null>(null)
36
37
  const popoverElementRef = useRef<HTMLDivElement | null>(null)
@@ -42,44 +43,16 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
42
43
 
43
44
  const rawItems = useMemo(() => Children.toArray(children).filter(isValidElement), [children])
44
45
 
45
- const items = useMemo(() => {
46
- const len = rawItems.length
47
-
48
- if (maxLength && len > maxLength) {
49
- const beforeLength = Math.ceil(maxLength / 2)
50
- const afterLength = Math.floor(maxLength / 2)
51
-
52
- return [
53
- ...rawItems.slice(0, beforeLength - 1),
54
- <Popover
55
- constrainSize
56
- content={
57
- <Stack as="ol" overflow="auto" padding={space} space={space}>
58
- {rawItems.slice(beforeLength - 1, len - afterLength)}
59
- </Stack>
60
- }
61
- key="button"
62
- open={open}
63
- placement="top"
64
- portal
65
- ref={popoverElementRef}
66
- >
67
- <ExpandButton
68
- fontSize={1}
69
- mode="bleed"
70
- onClick={open ? collapse : expand}
71
- padding={1}
72
- ref={expandElementRef}
73
- selected={open}
74
- text="…"
75
- />
76
- </Popover>,
77
- ...rawItems.slice(len - afterLength),
78
- ]
79
- }
80
-
81
- return rawItems
82
- }, [collapse, expand, maxLength, open, rawItems, space])
46
+ const items = useItems({
47
+ collapse,
48
+ expand,
49
+ expandElementRef,
50
+ maxLength,
51
+ open,
52
+ popoverElementRef,
53
+ rawItems,
54
+ space,
55
+ })
83
56
 
84
57
  return (
85
58
  <StyledBreadcrumbs data-ui="Breadcrumbs" {...restProps} ref={ref}>
@@ -97,3 +70,60 @@ export const Breadcrumbs = forwardRef(function Breadcrumbs(
97
70
  )
98
71
  })
99
72
  Breadcrumbs.displayName = 'ForwardRef(Breadcrumbs)'
73
+
74
+ function useItems({
75
+ collapse,
76
+ expand,
77
+ expandElementRef,
78
+ maxLength,
79
+ open,
80
+ popoverElementRef,
81
+ rawItems,
82
+ space,
83
+ }: {
84
+ collapse: () => void
85
+ expand: () => void
86
+ expandElementRef: React.RefObject<HTMLButtonElement | null>
87
+ maxLength: number | undefined
88
+ open: boolean
89
+ popoverElementRef: React.RefObject<HTMLDivElement | null>
90
+ rawItems: React.ReactElement<unknown, string | React.JSXElementConstructor<any>>[]
91
+ space: number[]
92
+ }) {
93
+ const len = rawItems.length
94
+
95
+ if (maxLength && len > maxLength) {
96
+ const beforeLength = Math.ceil(maxLength / 2)
97
+ const afterLength = Math.floor(maxLength / 2)
98
+
99
+ return [
100
+ ...rawItems.slice(0, beforeLength - 1),
101
+ <Popover
102
+ constrainSize
103
+ content={
104
+ <Stack as="ol" overflow="auto" padding={space} space={space}>
105
+ {rawItems.slice(beforeLength - 1, len - afterLength)}
106
+ </Stack>
107
+ }
108
+ key="button"
109
+ open={open}
110
+ placement="top"
111
+ portal
112
+ ref={popoverElementRef}
113
+ >
114
+ <ExpandButton
115
+ fontSize={1}
116
+ mode="bleed"
117
+ onClick={open ? collapse : expand}
118
+ padding={1}
119
+ ref={expandElementRef}
120
+ selected={open}
121
+ text="…"
122
+ />
123
+ </Popover>,
124
+ ...rawItems.slice(len - afterLength),
125
+ ]
126
+ }
127
+
128
+ return rawItems
129
+ }
@@ -9,14 +9,10 @@ import {
9
9
  focusLastDescendant,
10
10
  isHTMLElement,
11
11
  } from '../../helpers'
12
- import {
13
- useArrayProp,
14
- useClickOutsideEvent,
15
- useGlobalKeyDown,
16
- usePrefersReducedMotion,
17
- } from '../../hooks'
12
+ import {useClickOutsideEvent, useGlobalKeyDown, usePrefersReducedMotion} from '../../hooks'
18
13
  import {Box, Button, Card, Container, Flex, Text} from '../../primitives'
19
14
  import {ResponsivePaddingProps, ResponsiveWidthProps} from '../../primitives/types'
15
+ import {_getArrayProp} from '../../styles'
20
16
  import {responsivePaddingStyle, ResponsivePaddingStyleProps} from '../../styles/internal'
21
17
  import {useTheme_v2} from '../../theme'
22
18
  import {DialogPosition, Radius} from '../../types'
@@ -172,9 +168,9 @@ const DialogCard = forwardRef(function DialogCard(
172
168
  const portal = usePortal()
173
169
  const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
174
170
  const boundaryElement = useBoundaryElement().element
175
- const radius = useArrayProp(radiusProp)
176
- const shadow = useArrayProp(shadowProp)
177
- const width = useArrayProp(widthProp)
171
+ const radius = _getArrayProp(radiusProp)
172
+ const shadow = _getArrayProp(shadowProp)
173
+ const width = _getArrayProp(widthProp)
178
174
  const ref = useRef<HTMLDivElement | null>(null)
179
175
  const contentRef = useRef<HTMLDivElement | null>(null)
180
176
  const layer = useLayer()
@@ -320,11 +316,11 @@ export const Dialog = forwardRef(function Dialog(
320
316
  const portal = usePortal()
321
317
  const portalElement = portalProp ? portal.elements?.[portalProp] || null : portal.element
322
318
  const boundaryElement = useBoundaryElement().element
323
- const cardRadius = useArrayProp(cardRadiusProp)
324
- const padding = useArrayProp(paddingProp)
325
- const position = useArrayProp(positionProp)
326
- const width = useArrayProp(widthProp)
327
- const zOffset = useArrayProp(zOffsetProp)
319
+ const cardRadius = _getArrayProp(cardRadiusProp)
320
+ const padding = _getArrayProp(paddingProp)
321
+ const position = _getArrayProp(positionProp)
322
+ const width = _getArrayProp(widthProp)
323
+ const zOffset = _getArrayProp(zOffsetProp)
328
324
  const preDivRef = useRef<HTMLDivElement | null>(null)
329
325
  const postDivRef = useRef<HTMLDivElement | null>(null)
330
326
  const cardRef = useRef<HTMLDivElement | null>(null)
@@ -1,8 +1,8 @@
1
1
  import {forwardRef} from 'react'
2
2
  import {styled} from 'styled-components'
3
3
 
4
- import {useArrayProp} from '../../hooks'
5
4
  import {Inline, KBD} from '../../primitives'
5
+ import {_getArrayProp} from '../../styles'
6
6
  import {Radius} from '../../types'
7
7
 
8
8
  /**
@@ -41,7 +41,7 @@ export const Hotkeys = forwardRef(function Hotkeys(
41
41
  ref: React.Ref<HTMLElement>,
42
42
  ) {
43
43
  const {fontSize, keys, padding, radius, space: spaceProp = 0.5, ...restProps} = props
44
- const space = useArrayProp(spaceProp)
44
+ const space = _getArrayProp(spaceProp)
45
45
 
46
46
  if (!keys || keys.length === 0) {
47
47
  return <></>
@@ -2,9 +2,9 @@ import {ChevronRightIcon} from '@sanity/icons'
2
2
  import {isValidElement, useCallback, useEffect, useState} from 'react'
3
3
  import {isValidElementType} from 'react-is'
4
4
 
5
- import {useArrayProp} from '../../hooks'
6
5
  import {Box, Flex, Popover, PopoverProps, Text} from '../../primitives'
7
6
  import {Selectable} from '../../primitives/_selectable'
7
+ import {_getArrayProp} from '../../styles'
8
8
  import {useRootTheme} from '../../theme'
9
9
  import {Radius, SelectableTone} from '../../types'
10
10
  import {Menu, MenuProps} from './menu'
@@ -181,7 +181,7 @@ export function MenuGroup(
181
181
  aria-pressed={as === 'button' ? withinMenu : undefined}
182
182
  data-pressed={as !== 'button' ? withinMenu : undefined}
183
183
  data-selected={!withinMenu && active ? '' : undefined}
184
- $radius={useArrayProp(radius)}
184
+ $radius={_getArrayProp(radius)}
185
185
  $tone={tone}
186
186
  $scheme={scheme}
187
187
  onClick={handleClick}
@@ -10,7 +10,7 @@ import {
10
10
  } from 'react'
11
11
  import {isValidElementType} from 'react-is'
12
12
 
13
- import {useArrayProp} from '../../hooks'
13
+ import {getArrayProp} from '../../hooks/useArrayProp'
14
14
  import {Box, Flex, Text} from '../../primitives'
15
15
  import {Selectable} from '../../primitives/_selectable'
16
16
  import {ResponsivePaddingProps, ResponsiveRadiusProps} from '../../primitives/types'
@@ -108,7 +108,7 @@ export const MenuItem = forwardRef(function MenuItem(
108
108
  [padding, paddingX, paddingY, paddingTop, paddingRight, paddingBottom, paddingLeft],
109
109
  )
110
110
 
111
- const hotkeysFontSize = useArrayProp(fontSize).map((s) => s - 1)
111
+ const hotkeysFontSize = getArrayProp(fontSize).map((s) => s - 1)
112
112
 
113
113
  const setRef = useCallback((el: HTMLDivElement | null) => {
114
114
  ref.current = el
@@ -124,8 +124,8 @@ export const MenuItem = forwardRef(function MenuItem(
124
124
  data-selected={active ? '' : undefined}
125
125
  data-disabled={disabled ? '' : undefined}
126
126
  forwardedAs={as}
127
- $radius={useArrayProp(radius)}
128
- $padding={useArrayProp(0)}
127
+ $radius={getArrayProp(radius)}
128
+ $padding={getArrayProp(0)}
129
129
  $tone={disabled ? 'default' : tone}
130
130
  $scheme={scheme}
131
131
  disabled={disabled}
@@ -1,7 +1,7 @@
1
1
  import {forwardRef, useEffect, useState} 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, ResponsiveRadiusProps} from '../../primitives'
6
6
  import {responsiveRadiusStyle, ResponsiveRadiusStyleProps} from '../../styles/internal'
7
7
  import {skeletonStyle} from './styles'
@@ -48,7 +48,7 @@ export const Skeleton = forwardRef(function Skeleton(
48
48
  <StyledSkeleton
49
49
  {...restProps}
50
50
  $animated={animated}
51
- $radius={useArrayProp(radius)}
51
+ $radius={getArrayProp(radius)}
52
52
  $visible={visible}
53
53
  ref={ref}
54
54
  />
@@ -2,7 +2,7 @@ import {getTheme_v2, ThemeFontKey} 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 {_responsive, ThemeProps} from '../../styles'
7
7
  import {Skeleton, SkeletonProps} from './skeleton'
8
8
 
@@ -68,7 +68,7 @@ export const TextSkeleton = forwardRef(function TextSkeleton(
68
68
  ref: React.Ref<HTMLDivElement>,
69
69
  ) {
70
70
  const {size = 2, ...restProps} = props
71
- const $size = useArrayProp(size)
71
+ const $size = getArrayProp(size)
72
72
 
73
73
  return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="text" />
74
74
  })
@@ -84,7 +84,7 @@ export const LabelSkeleton = forwardRef(function TextSkeleton(
84
84
  ref: React.Ref<HTMLDivElement>,
85
85
  ) {
86
86
  const {size = 2, ...restProps} = props
87
- const $size = useArrayProp(size)
87
+ const $size = getArrayProp(size)
88
88
 
89
89
  return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="label" />
90
90
  })
@@ -100,7 +100,7 @@ export const HeadingSkeleton = forwardRef(function TextSkeleton(
100
100
  ref: React.Ref<HTMLDivElement>,
101
101
  ) {
102
102
  const {size = 2, ...restProps} = props
103
- const $size = useArrayProp(size)
103
+ const $size = getArrayProp(size)
104
104
 
105
105
  return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="heading" />
106
106
  })
@@ -116,7 +116,7 @@ export const CodeSkeleton = forwardRef(function TextSkeleton(
116
116
  ref: React.Ref<HTMLDivElement>,
117
117
  ) {
118
118
  const {size = 2, ...restProps} = props
119
- const $size = useArrayProp(size)
119
+ const $size = getArrayProp(size)
120
120
 
121
121
  return <StyledSkeleton {...restProps} $size={$size} ref={ref} $style="code" />
122
122
  })