@sanity/ui 2.8.23 → 2.8.24-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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@sanity/ui",
3
- "version": "2.8.23",
3
+ "version": "2.8.24-canary.1",
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,7 +96,7 @@
122
96
  "@commitlint/cli": "^19.4.0",
123
97
  "@commitlint/config-conventional": "^19.2.2",
124
98
  "@juggle/resize-observer": "^3.4.0",
125
- "@sanity/pkg-utils": "^6.11.9",
99
+ "@sanity/pkg-utils": "^6.11.10",
126
100
  "@sanity/prettier-config": "^1.0.3",
127
101
  "@sanity/semantic-release-preset": "^5.0.0",
128
102
  "@sanity/ui-workshop": "^2.0.16",
@@ -198,19 +172,37 @@
198
172
  "react-is": "^18 || >=19.0.0-0",
199
173
  "styled-components": "^5.2 || ^6"
200
174
  },
201
- "packageManager": "pnpm@9.12.3",
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
- "conventional-changelog-conventionalcommits": ">= 8.0.0"
211
- }
212
- },
213
181
  "esm.sh": {
214
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"
215
207
  }
216
- }
208
+ }
@@ -10,21 +10,23 @@ export type ArrayPropPrimitive = string | number | boolean | undefined | null
10
10
  */
11
11
  export function useArrayProp<T extends ArrayPropPrimitive = ArrayPropPrimitive>(
12
12
  val: T | T[] | undefined,
13
- defaultVal?: T[],
14
13
  ): T[] {
15
14
  const [[cachedVal, cachedHash], setCache] = useState<[T[], string]>(() => [
16
- _getArrayProp(val, defaultVal),
17
- JSON.stringify(val ?? defaultVal),
15
+ _getArrayProp(val),
16
+ JSON.stringify(val),
18
17
  ])
18
+ let result = cachedVal
19
19
 
20
- const hash = JSON.stringify(val ?? defaultVal)
20
+ const hash = JSON.stringify(val)
21
21
 
22
22
  if (hash !== cachedHash) {
23
+ const current = _getArrayProp(val)
23
24
  // If the cached hash has changed, update the cache right away.
24
25
  // Calling setState during render is fine in this case, and preferred over a useEffect loop
25
26
  // https://19.react.dev/learn/you-might-not-need-an-effect#adjusting-some-state-when-a-prop-changes
26
- setCache([_getArrayProp(val, defaultVal), hash])
27
+ setCache([current, hash])
28
+ result = current
27
29
  }
28
30
 
29
- return cachedVal
31
+ return result
30
32
  }
@@ -42,8 +42,8 @@ export function _responsive<T>(
42
42
  /**
43
43
  * @internal
44
44
  */
45
- export function _getArrayProp<T = number>(val: T | T[] | undefined, defaultVal?: T[]): T[] {
46
- if (val === undefined) return defaultVal || EMPTY_ARRAY
45
+ export function _getArrayProp<T = number>(val: T | T[] | undefined): T[] {
46
+ if (val === undefined) return EMPTY_ARRAY
47
47
 
48
48
  return Array.isArray(val) ? val : [val]
49
49
  }
@@ -1,4 +1,4 @@
1
- import {useMemo, useRef, useSyncExternalStore} from 'react'
1
+ import {useMemo, useState, useSyncExternalStore} from 'react'
2
2
  import {PortalContext} from './portalContext'
3
3
  import {PortalContextValue} from './types'
4
4
 
@@ -22,8 +22,8 @@ export interface PortalProviderProps {
22
22
  * @public
23
23
  */
24
24
  export function PortalProvider(props: PortalProviderProps): React.ReactElement {
25
- const {boundaryElement, children, element, __unstable_elements: elementsProp} = props
26
- const elements = useUnique(elementsProp)
25
+ const {boundaryElement, children, element} = props
26
+ const elements = useUnique(props.__unstable_elements)
27
27
  const fallbackElement = useSyncExternalStore(
28
28
  emptySubscribe,
29
29
  () => document.body,
@@ -51,16 +51,18 @@ const emptySubscribe = () => () => {}
51
51
  * equality comparison (eg by identity), and only goes one level deep.
52
52
  */
53
53
  function useUnique<ValueType extends Comparable = Comparable>(value: ValueType): ValueType {
54
- const valueRef = useRef<ValueType>(value)
54
+ const [cachedValue, setCachedValue] = useState(value)
55
+ let result = cachedValue
55
56
 
56
- if (!_isEqual(valueRef.current, value)) {
57
- valueRef.current = value
57
+ if (!isEqual(cachedValue, value)) {
58
+ setCachedValue(value)
59
+ result = value
58
60
  }
59
61
 
60
- return valueRef.current
62
+ return result
61
63
  }
62
64
 
63
- function _isEqual(objA: Comparable, objB: Comparable): boolean {
65
+ function isEqual(objA: Comparable, objB: Comparable): boolean {
64
66
  if (!objA || !objB) {
65
67
  return objA === objB
66
68
  }