@sanity/ui 2.11.6 → 2.11.7-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.11.6",
3
+ "version": "2.11.7-canary.0",
4
4
  "keywords": [
5
5
  "sanity",
6
6
  "ui",
@@ -51,32 +51,6 @@
51
51
  "src",
52
52
  "theme.js"
53
53
  ],
54
- "scripts": {
55
- "build": "run-s clean pkg:build pkg:check figma:pkg:build",
56
- "clean": "rimraf .workshop dist",
57
- "commit": "cz",
58
- "cypress:dev": "run-p dev cypress:open",
59
- "cypress:open": "cypress open",
60
- "cypress:run": "cypress run",
61
- "dev": "run-p storybook:dev workshop:dev",
62
- "figma:pkg:build": "cd figma && pnpm build",
63
- "format": "prettier --write --cache --ignore-unknown .",
64
- "lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
65
- "pkg:build": "pkg build --strict",
66
- "pkg:check": "pkg --strict",
67
- "prepare": "husky install",
68
- "prepack": "pnpm build",
69
- "release": "semantic-release",
70
- "storybook:build": "storybook build",
71
- "storybook:dev": "storybook dev -p 6006",
72
- "test": "jest",
73
- "test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
74
- "ts:check": "tsc",
75
- "watch": "pkg watch --strict",
76
- "workshop:build": "workshop build",
77
- "workshop:dev": "workshop dev",
78
- "workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
79
- },
80
54
  "commitlint": {
81
55
  "extends": [
82
56
  "@commitlint/config-conventional"
@@ -122,28 +96,28 @@
122
96
  "@commitlint/cli": "^19.6.1",
123
97
  "@commitlint/config-conventional": "^19.6.0",
124
98
  "@juggle/resize-observer": "^3.4.0",
125
- "@sanity/pkg-utils": "^6.13.1",
99
+ "@sanity/pkg-utils": "^6.13.4",
126
100
  "@sanity/prettier-config": "^1.0.3",
127
101
  "@sanity/semantic-release-preset": "^5.0.0",
128
102
  "@sanity/ui-workshop": "^2.0.25",
129
- "@storybook/addon-a11y": "^8.4.7",
130
- "@storybook/addon-docs": "^8.4.7",
131
- "@storybook/addon-essentials": "^8.4.7",
132
- "@storybook/addon-interactions": "^8.4.7",
133
- "@storybook/addon-links": "^8.4.7",
134
- "@storybook/addon-mdx-gfm": "^8.4.7",
135
- "@storybook/addon-storysource": "^8.4.7",
136
- "@storybook/addon-themes": "^8.4.7",
137
- "@storybook/blocks": "^8.4.7",
138
- "@storybook/manager-api": "^8.4.7",
139
- "@storybook/react": "^8.4.7",
140
- "@storybook/react-vite": "^8.4.7",
141
- "@storybook/test": "^8.4.7",
142
- "@storybook/theming": "^8.4.7",
103
+ "@storybook/addon-a11y": "^8.5.2",
104
+ "@storybook/addon-docs": "^8.5.2",
105
+ "@storybook/addon-essentials": "^8.5.2",
106
+ "@storybook/addon-interactions": "^8.5.2",
107
+ "@storybook/addon-links": "^8.5.2",
108
+ "@storybook/addon-mdx-gfm": "^8.5.2",
109
+ "@storybook/addon-storysource": "^8.5.2",
110
+ "@storybook/addon-themes": "^8.5.2",
111
+ "@storybook/blocks": "^8.5.2",
112
+ "@storybook/manager-api": "^8.5.2",
113
+ "@storybook/react": "^8.5.2",
114
+ "@storybook/react-vite": "^8.5.2",
115
+ "@storybook/test": "^8.5.2",
116
+ "@storybook/theming": "^8.5.2",
143
117
  "@testing-library/dom": "^10.4.0",
144
118
  "@testing-library/jest-dom": "^6.6.3",
145
- "@testing-library/react": "^16.1.0",
146
- "@testing-library/user-event": "^14.5.2",
119
+ "@testing-library/react": "^16.2.0",
120
+ "@testing-library/user-event": "^14.6.1",
147
121
  "@types/jest": "^29.5.14",
148
122
  "@types/jest-axe": "^3.5.9",
149
123
  "@types/node": "^20.12.7",
@@ -185,7 +159,7 @@
185
159
  "rimraf": "^5.0.5",
186
160
  "semantic-release": "^24.2.1",
187
161
  "start-server-and-test": "^2.0.10",
188
- "storybook": "^8.4.7",
162
+ "storybook": "^8.5.2",
189
163
  "styled-components": "^6.1.14",
190
164
  "tsconfig-paths": "^4.2.0",
191
165
  "typescript": "5.7.3",
@@ -198,25 +172,37 @@
198
172
  "react-is": "^18 || >=19.0.0-0",
199
173
  "styled-components": "^5.2 || ^6"
200
174
  },
201
- "packageManager": "pnpm@9.15.4",
202
175
  "engines": {
203
176
  "node": ">=14.0.0"
204
177
  },
205
178
  "publishConfig": {
206
179
  "access": "public"
207
180
  },
208
- "pnpm": {
209
- "overrides": {
210
- "@types/react": "$@types/react",
211
- "@types/react-dom": "$@types/react-dom",
212
- "@types/react-is": "$@types/react-is",
213
- "conventional-changelog-conventionalcommits": ">= 8.0.0",
214
- "react": "$react",
215
- "react-dom": "$react-dom",
216
- "react-is": "$react-is"
217
- }
218
- },
219
181
  "esm.sh": {
220
182
  "bundle": false
183
+ },
184
+ "scripts": {
185
+ "build": "run-s clean pkg:build pkg:check figma:pkg:build",
186
+ "clean": "rimraf .workshop dist",
187
+ "commit": "cz",
188
+ "cypress:dev": "run-p dev cypress:open",
189
+ "cypress:open": "cypress open",
190
+ "cypress:run": "cypress run",
191
+ "dev": "run-p storybook:dev workshop:dev",
192
+ "figma:pkg:build": "cd figma && pnpm build",
193
+ "format": "prettier --write --cache --ignore-unknown .",
194
+ "lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
195
+ "pkg:build": "pkg build --strict",
196
+ "pkg:check": "pkg --strict",
197
+ "release": "semantic-release",
198
+ "storybook:build": "storybook build",
199
+ "storybook:dev": "storybook dev -p 6006",
200
+ "test": "jest",
201
+ "test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
202
+ "ts:check": "tsc",
203
+ "watch": "pkg watch --strict",
204
+ "workshop:build": "workshop build",
205
+ "workshop:dev": "workshop dev",
206
+ "workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
221
207
  }
222
- }
208
+ }
@@ -28,6 +28,7 @@ import {origin} from '../../middleware/origin'
28
28
  import {useTheme_v2} from '../../theme'
29
29
  import {BoxOverflow, CardTone, Placement, PopoverMargins} from '../../types'
30
30
  import {LayerProps, LayerProvider, Portal, useBoundaryElement} from '../../utils'
31
+ import {getElementRef} from '../../utils/getElementRef'
31
32
  import {ResponsiveRadiusProps, ResponsiveShadowProps} from '../types'
32
33
  import {
33
34
  DEFAULT_POPOVER_DISTANCE,
@@ -443,29 +444,3 @@ export const Popover = memo(
443
444
  }),
444
445
  )
445
446
  Popover.displayName = 'Memo(ForwardRef(Popover))'
446
-
447
- // Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`
448
- // After React 19 accessing `element.ref` does the opposite.
449
- // https://github.com/facebook/react/pull/28348
450
- //
451
- // Access the ref using the method that doesn't yield a warning.
452
- function getElementRef(element: React.JSX.Element) {
453
- // React <=18 in DEV
454
- let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get
455
- let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning
456
-
457
- if (mayWarn) {
458
- return (element as any).ref
459
- }
460
-
461
- // React 19 in DEV
462
- getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get
463
- mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning
464
-
465
- if (mayWarn) {
466
- return element.props.ref
467
- }
468
-
469
- // Not DEV
470
- return element.props.ref || (element as any).ref
471
- }
@@ -30,6 +30,7 @@ import {origin} from '../../middleware/origin'
30
30
  import {useTheme_v2} from '../../theme'
31
31
  import type {Placement} from '../../types'
32
32
  import {Layer, type LayerProps, Portal, useBoundaryElement, usePortal} from '../../utils'
33
+ import {getElementRef} from '../../utils/getElementRef'
33
34
  import type {Delay} from '../types'
34
35
  import {
35
36
  DEFAULT_FALLBACK_PLACEMENTS,
@@ -320,11 +321,6 @@ export const Tooltip = forwardRef(function Tooltip(
320
321
  [refs],
321
322
  )
322
323
 
323
- const childRef = useRef<HTMLElement | null>(null)
324
-
325
- // Merge refs so that any ref we are overriding is called as well
326
- useImperativeHandle((childProp as any)?.ref, () => childRef.current)
327
-
328
324
  const child = useMemo(() => {
329
325
  if (!childProp) return null
330
326
 
@@ -335,7 +331,7 @@ export const Tooltip = forwardRef(function Tooltip(
335
331
  onMouseLeave: handleMouseLeave,
336
332
  onClick: handleClick,
337
333
  onContextMenu: handleContextMenu,
338
- ref: childRef,
334
+ ref: setReferenceElement,
339
335
  })
340
336
  }, [
341
337
  childProp,
@@ -349,13 +345,9 @@ export const Tooltip = forwardRef(function Tooltip(
349
345
 
350
346
  // If there's a child then we need to set the reference element to the cloned child ref
351
347
  // and if child changes we make sure to update or remove the reference element.
352
- useEffect(() => {
353
- if (!child) return undefined
354
-
355
- setReferenceElement(childRef.current)
356
-
357
- return () => setReferenceElement(null)
358
- }, [child])
348
+ useImperativeHandle(childProp ? getElementRef(childProp) : null, () => referenceElement, [
349
+ referenceElement,
350
+ ])
359
351
 
360
352
  if (!child) return <></>
361
353
 
@@ -0,0 +1,26 @@
1
+ // Based on https://github.com/radix-ui/primitives/blob/0bade6a704e5821b90a6da0f3d8cfa8a7711127d/packages/react/slot/src/Slot.tsx#L128-L150
2
+ // Before React 19 accessing `element.props.ref` will throw a warning and suggest using `element.ref`
3
+ // After React 19 accessing `element.ref` does the opposite.
4
+ // https://github.com/facebook/react/pull/28348
5
+ //
6
+ // Access the ref using the method that doesn't yield a warning.
7
+ export function getElementRef(element: React.ReactElement) {
8
+ // React <=18 in DEV
9
+ let getter = Object.getOwnPropertyDescriptor(element.props, 'ref')?.get
10
+ let mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning
11
+
12
+ if (mayWarn) {
13
+ return (element as any).ref
14
+ }
15
+
16
+ // React 19 in DEV
17
+ getter = Object.getOwnPropertyDescriptor(element, 'ref')?.get
18
+ mayWarn = getter && 'isReactWarning' in getter && getter.isReactWarning
19
+
20
+ if (mayWarn) {
21
+ return (element.props as {ref?: React.Ref<unknown>}).ref
22
+ }
23
+
24
+ // Not DEV
25
+ return (element.props as {ref?: React.Ref<unknown>}).ref || (element as any).ref
26
+ }