@sanity/ui 2.1.2 → 2.1.3-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/dist/index.d.mts +2 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.esm.js +17 -11
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +17 -11
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +17 -11
- package/dist/index.mjs.map +1 -1
- package/package.json +43 -47
- package/src/core/components/dialog/dialogContext.ts +4 -5
- package/src/core/lib/createGlobalScopedContext.ts +24 -0
- package/src/core/theme/themeContext.ts +2 -5
- package/src/core/theme/themeProvider.tsx +4 -4
- package/src/core/utils/portal/portalProvider.tsx +10 -5
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.3-canary.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"sanity",
|
|
6
6
|
"ui",
|
|
@@ -37,7 +37,6 @@
|
|
|
37
37
|
},
|
|
38
38
|
"main": "./dist/index.js",
|
|
39
39
|
"module": "./dist/index.esm.js",
|
|
40
|
-
"source": "./exports/index.ts",
|
|
41
40
|
"types": "./dist/index.d.ts",
|
|
42
41
|
"typesVersions": {
|
|
43
42
|
"*": {
|
|
@@ -52,32 +51,6 @@
|
|
|
52
51
|
"src",
|
|
53
52
|
"theme.js"
|
|
54
53
|
],
|
|
55
|
-
"scripts": {
|
|
56
|
-
"build": "run-s clean pkg:build pkg:check figma:pkg:build",
|
|
57
|
-
"clean": "rimraf .workshop dist",
|
|
58
|
-
"commit": "cz",
|
|
59
|
-
"cypress:dev": "run-p dev cypress:open",
|
|
60
|
-
"cypress:open": "cypress open",
|
|
61
|
-
"cypress:run": "cypress run",
|
|
62
|
-
"dev": "run-p storybook:dev workshop:dev",
|
|
63
|
-
"figma:pkg:build": "cd figma && pnpm build",
|
|
64
|
-
"format": "prettier --write --cache --ignore-unknown .",
|
|
65
|
-
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx --quiet",
|
|
66
|
-
"pkg:build": "pkg build --strict",
|
|
67
|
-
"pkg:check": "pkg --strict",
|
|
68
|
-
"prepare": "husky install",
|
|
69
|
-
"prepublishOnly": "pnpm build",
|
|
70
|
-
"release": "semantic-release",
|
|
71
|
-
"storybook:build": "storybook build",
|
|
72
|
-
"storybook:dev": "storybook dev -p 6006",
|
|
73
|
-
"test": "jest",
|
|
74
|
-
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
75
|
-
"ts:check": "tsc",
|
|
76
|
-
"watch": "pkg watch --strict",
|
|
77
|
-
"workshop:build": "workshop build",
|
|
78
|
-
"workshop:dev": "workshop dev",
|
|
79
|
-
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
80
|
-
},
|
|
81
54
|
"commitlint": {
|
|
82
55
|
"extends": [
|
|
83
56
|
"@commitlint/config-conventional"
|
|
@@ -120,23 +93,23 @@
|
|
|
120
93
|
"@commitlint/cli": "^19.2.1",
|
|
121
94
|
"@commitlint/config-conventional": "^19.1.0",
|
|
122
95
|
"@juggle/resize-observer": "^3.4.0",
|
|
123
|
-
"@sanity/pkg-utils": "^6.1
|
|
96
|
+
"@sanity/pkg-utils": "^6.4.1",
|
|
124
97
|
"@sanity/semantic-release-preset": "^4.1.7",
|
|
125
98
|
"@sanity/ui-workshop": "^2.0.12",
|
|
126
|
-
"@storybook/addon-a11y": "^8.0.
|
|
127
|
-
"@storybook/addon-docs": "^8.0.
|
|
128
|
-
"@storybook/addon-essentials": "^8.0.
|
|
129
|
-
"@storybook/addon-interactions": "^8.0.
|
|
130
|
-
"@storybook/addon-links": "^8.0.
|
|
131
|
-
"@storybook/addon-storysource": "^8.0.
|
|
132
|
-
"@storybook/addon-themes": "^8.0.
|
|
133
|
-
"@storybook/blocks": "^8.0.
|
|
99
|
+
"@storybook/addon-a11y": "^8.0.7",
|
|
100
|
+
"@storybook/addon-docs": "^8.0.7",
|
|
101
|
+
"@storybook/addon-essentials": "^8.0.7",
|
|
102
|
+
"@storybook/addon-interactions": "^8.0.7",
|
|
103
|
+
"@storybook/addon-links": "^8.0.7",
|
|
104
|
+
"@storybook/addon-storysource": "^8.0.7",
|
|
105
|
+
"@storybook/addon-themes": "^8.0.7",
|
|
106
|
+
"@storybook/blocks": "^8.0.7",
|
|
134
107
|
"@storybook/jest": "^0.2.3",
|
|
135
|
-
"@storybook/manager-api": "^8.0.
|
|
136
|
-
"@storybook/react": "^8.0.
|
|
137
|
-
"@storybook/react-vite": "^8.0.
|
|
108
|
+
"@storybook/manager-api": "^8.0.7",
|
|
109
|
+
"@storybook/react": "^8.0.7",
|
|
110
|
+
"@storybook/react-vite": "^8.0.7",
|
|
138
111
|
"@storybook/testing-library": "^0.2.2",
|
|
139
|
-
"@storybook/theming": "^8.0.
|
|
112
|
+
"@storybook/theming": "^8.0.7",
|
|
140
113
|
"@testing-library/dom": "^9.3.4",
|
|
141
114
|
"@testing-library/jest-dom": "^5.17.0",
|
|
142
115
|
"@testing-library/react": "^14.3.0",
|
|
@@ -172,7 +145,7 @@
|
|
|
172
145
|
"module-alias": "^2.2.3",
|
|
173
146
|
"npm-run-all2": "^5.0.2",
|
|
174
147
|
"prettier": "^3.2.5",
|
|
175
|
-
"prettier-plugin-packagejson": "^2.
|
|
148
|
+
"prettier-plugin-packagejson": "^2.5.0",
|
|
176
149
|
"react": "^18.2.0",
|
|
177
150
|
"react-dom": "^18.2.0",
|
|
178
151
|
"react-is": "^18.2.0",
|
|
@@ -180,10 +153,10 @@
|
|
|
180
153
|
"rimraf": "^5.0.1",
|
|
181
154
|
"semantic-release": "^23.0.8",
|
|
182
155
|
"start-server-and-test": "^2.0.3",
|
|
183
|
-
"storybook": "^8.0.
|
|
156
|
+
"storybook": "^8.0.7",
|
|
184
157
|
"styled-components": "^6.1.8",
|
|
185
158
|
"tsconfig-paths": "^4.2.0",
|
|
186
|
-
"typescript": "5.4.
|
|
159
|
+
"typescript": "5.4.5",
|
|
187
160
|
"vite": "^5.2.8",
|
|
188
161
|
"vite-tsconfig-paths": "^4.3.2"
|
|
189
162
|
},
|
|
@@ -198,10 +171,33 @@
|
|
|
198
171
|
"node": ">=14.0.0"
|
|
199
172
|
},
|
|
200
173
|
"publishConfig": {
|
|
201
|
-
"access": "public"
|
|
202
|
-
"provenance": true
|
|
174
|
+
"access": "public"
|
|
203
175
|
},
|
|
204
176
|
"esm.sh": {
|
|
205
177
|
"bundle": false
|
|
178
|
+
},
|
|
179
|
+
"scripts": {
|
|
180
|
+
"build": "run-s clean pkg:build pkg:check figma:pkg:build",
|
|
181
|
+
"clean": "rimraf .workshop dist",
|
|
182
|
+
"commit": "cz",
|
|
183
|
+
"cypress:dev": "run-p dev cypress:open",
|
|
184
|
+
"cypress:open": "cypress open",
|
|
185
|
+
"cypress:run": "cypress run",
|
|
186
|
+
"dev": "run-p storybook:dev workshop:dev",
|
|
187
|
+
"figma:pkg:build": "cd figma && pnpm build",
|
|
188
|
+
"format": "prettier --write --cache --ignore-unknown .",
|
|
189
|
+
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx --quiet",
|
|
190
|
+
"pkg:build": "pkg build --strict",
|
|
191
|
+
"pkg:check": "pkg --strict",
|
|
192
|
+
"release": "semantic-release",
|
|
193
|
+
"storybook:build": "storybook build",
|
|
194
|
+
"storybook:dev": "storybook dev -p 6006",
|
|
195
|
+
"test": "jest",
|
|
196
|
+
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
197
|
+
"ts:check": "tsc",
|
|
198
|
+
"watch": "pkg watch --strict",
|
|
199
|
+
"workshop:build": "workshop build",
|
|
200
|
+
"workshop:dev": "workshop dev",
|
|
201
|
+
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
206
202
|
}
|
|
207
|
-
}
|
|
203
|
+
}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {globalScope} from '../../lib/globalScope'
|
|
1
|
+
import {createGlobalScopedContext} from '../../lib/createGlobalScopedContext'
|
|
3
2
|
import {DialogPosition} from '../../types'
|
|
4
3
|
|
|
5
4
|
/**
|
|
@@ -14,9 +13,9 @@ export interface DialogContextValue {
|
|
|
14
13
|
|
|
15
14
|
const key = Symbol.for('@sanity/ui/context/dialog')
|
|
16
15
|
|
|
17
|
-
globalScope[key] = globalScope[key] || createContext<DialogContextValue>({version: 0.0})
|
|
18
|
-
|
|
19
16
|
/**
|
|
20
17
|
* @internal
|
|
21
18
|
*/
|
|
22
|
-
export const DialogContext
|
|
19
|
+
export const DialogContext = createGlobalScopedContext<DialogContextValue>(key, {
|
|
20
|
+
version: 0.0,
|
|
21
|
+
})
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* To improve performance and DevEx for things such as Hot Module Replacement,
|
|
3
|
+
* we want to preserve created contexts between reloads.
|
|
4
|
+
* It also helps with module duplication and other issues.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import {createContext, type Context} from 'react'
|
|
8
|
+
import {globalScope} from './globalScope'
|
|
9
|
+
|
|
10
|
+
export function createGlobalScopedContext<ContextType, const T extends ContextType = ContextType>(
|
|
11
|
+
key: symbol,
|
|
12
|
+
defaultValue: T,
|
|
13
|
+
): Context<ContextType> {
|
|
14
|
+
/**
|
|
15
|
+
* Prevent errors about re-renders on React SSR on Next.js App Router
|
|
16
|
+
*/
|
|
17
|
+
if (typeof document === 'undefined') {
|
|
18
|
+
return createContext<ContextType>(defaultValue)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
globalScope[key] = globalScope[key] || createContext<T>(defaultValue)
|
|
22
|
+
|
|
23
|
+
return globalScope[key]
|
|
24
|
+
}
|
|
@@ -1,12 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {globalScope} from '../lib/globalScope'
|
|
1
|
+
import {createGlobalScopedContext} from '../lib/createGlobalScopedContext'
|
|
3
2
|
import {ThemeContextValue} from './types'
|
|
4
3
|
|
|
5
4
|
const key = Symbol.for('@sanity/ui/context/theme')
|
|
6
5
|
|
|
7
|
-
globalScope[key] = globalScope[key] || createContext<ThemeContextValue | null>(null)
|
|
8
|
-
|
|
9
6
|
/**
|
|
10
7
|
* @internal
|
|
11
8
|
*/
|
|
12
|
-
export const ThemeContext
|
|
9
|
+
export const ThemeContext = createGlobalScopedContext<ThemeContextValue | null>(key, null)
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import {
|
|
2
|
-
RootTheme,
|
|
3
|
-
ThemeColorCardToneKey,
|
|
4
|
-
ThemeColorSchemeKey,
|
|
5
|
-
Theme,
|
|
2
|
+
type RootTheme,
|
|
3
|
+
type ThemeColorCardToneKey,
|
|
4
|
+
type ThemeColorSchemeKey,
|
|
5
|
+
type Theme,
|
|
6
6
|
getScopedTheme,
|
|
7
7
|
} from '@sanity/ui/theme'
|
|
8
8
|
import {useContext, useMemo} from 'react'
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {useMemo} from 'react'
|
|
1
|
+
import {useMemo, useSyncExternalStore} from 'react'
|
|
2
2
|
import {useUnique} from '../../hooks/_internal'
|
|
3
3
|
import {PortalContext} from './portalContext'
|
|
4
4
|
import {PortalContextValue} from './types'
|
|
@@ -19,23 +19,28 @@ export interface PortalProviderProps {
|
|
|
19
19
|
__unstable_elements?: Record<string, HTMLElement | null | undefined>
|
|
20
20
|
}
|
|
21
21
|
|
|
22
|
-
const __BROWSER__ = typeof document !== 'undefined'
|
|
23
|
-
|
|
24
22
|
/**
|
|
25
23
|
* @public
|
|
26
24
|
*/
|
|
27
25
|
export function PortalProvider(props: PortalProviderProps): React.ReactElement {
|
|
28
26
|
const {boundaryElement, children, element, __unstable_elements: elementsProp} = props
|
|
29
27
|
const elements = useUnique(elementsProp)
|
|
28
|
+
const fallbackElement = useSyncExternalStore(
|
|
29
|
+
emptySubscribe,
|
|
30
|
+
() => document.body,
|
|
31
|
+
() => null,
|
|
32
|
+
)
|
|
30
33
|
|
|
31
34
|
const value: PortalContextValue = useMemo(() => {
|
|
32
35
|
return {
|
|
33
36
|
version: 0.0,
|
|
34
37
|
boundaryElement: boundaryElement || null,
|
|
35
|
-
element: element ||
|
|
38
|
+
element: element || fallbackElement,
|
|
36
39
|
elements,
|
|
37
40
|
}
|
|
38
|
-
}, [boundaryElement, element, elements])
|
|
41
|
+
}, [boundaryElement, element, elements, fallbackElement])
|
|
39
42
|
|
|
40
43
|
return <PortalContext.Provider value={value}>{children}</PortalContext.Provider>
|
|
41
44
|
}
|
|
45
|
+
|
|
46
|
+
const emptySubscribe = () => () => {}
|