@sanity/ui 2.7.1-canary.1 → 2.8.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 +33 -8
- package/dist/index.d.ts +33 -8
- package/dist/index.esm.js +14 -18
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +14 -18
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +14 -18
- package/dist/index.mjs.map +1 -1
- package/package.json +36 -27
- package/src/core/components/dialog/dialog.tsx +9 -12
- package/src/core/components/menu/menu.tsx +2 -8
- package/src/core/components/menu/menuButton.tsx +1 -1
- package/src/core/components/menu/menuContext.ts +1 -1
- package/src/core/hooks/useClickOutside.test.tsx +568 -46
- package/src/core/hooks/useClickOutside.ts +43 -18
- package/src/core/primitives/popover/__workshop__/AlignedStory.tsx +9 -7
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sanity/ui",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"keywords": [
|
|
5
5
|
"sanity",
|
|
6
6
|
"ui",
|
|
@@ -51,6 +51,32 @@
|
|
|
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
|
+
},
|
|
54
80
|
"commitlint": {
|
|
55
81
|
"extends": [
|
|
56
82
|
"@commitlint/config-conventional"
|
|
@@ -116,6 +142,7 @@
|
|
|
116
142
|
"@testing-library/dom": "^10.3.2",
|
|
117
143
|
"@testing-library/jest-dom": "^6.4.6",
|
|
118
144
|
"@testing-library/react": "^16.0.0",
|
|
145
|
+
"@testing-library/user-event": "^14.5.2",
|
|
119
146
|
"@types/jest": "^29.5.12",
|
|
120
147
|
"@types/jest-axe": "^3.5.9",
|
|
121
148
|
"@types/node": "^20.12.7",
|
|
@@ -126,7 +153,7 @@
|
|
|
126
153
|
"@typescript-eslint/eslint-plugin": "^7.16.1",
|
|
127
154
|
"@typescript-eslint/parser": "^7.16.1",
|
|
128
155
|
"commitizen": "^4.3.0",
|
|
129
|
-
"cypress": "^13.13.
|
|
156
|
+
"cypress": "^13.13.1",
|
|
130
157
|
"cypress-real-events": "^1.13.0",
|
|
131
158
|
"cz-conventional-changelog": "^3.3.0",
|
|
132
159
|
"eslint": "^8.57.0",
|
|
@@ -168,37 +195,19 @@
|
|
|
168
195
|
"react-is": "^18",
|
|
169
196
|
"styled-components": "^5.2 || ^6"
|
|
170
197
|
},
|
|
198
|
+
"packageManager": "pnpm@9.5.0",
|
|
171
199
|
"engines": {
|
|
172
200
|
"node": ">=14.0.0"
|
|
173
201
|
},
|
|
174
202
|
"publishConfig": {
|
|
175
203
|
"access": "public"
|
|
176
204
|
},
|
|
205
|
+
"pnpm": {
|
|
206
|
+
"overrides": {
|
|
207
|
+
"conventional-changelog-conventionalcommits": ">= 8.0.0"
|
|
208
|
+
}
|
|
209
|
+
},
|
|
177
210
|
"esm.sh": {
|
|
178
211
|
"bundle": false
|
|
179
|
-
},
|
|
180
|
-
"scripts": {
|
|
181
|
-
"build": "run-s clean pkg:build pkg:check figma:pkg:build",
|
|
182
|
-
"clean": "rimraf .workshop dist",
|
|
183
|
-
"commit": "cz",
|
|
184
|
-
"cypress:dev": "run-p dev cypress:open",
|
|
185
|
-
"cypress:open": "cypress open",
|
|
186
|
-
"cypress:run": "cypress run",
|
|
187
|
-
"dev": "run-p storybook:dev workshop:dev",
|
|
188
|
-
"figma:pkg:build": "cd figma && pnpm build",
|
|
189
|
-
"format": "prettier --write --cache --ignore-unknown .",
|
|
190
|
-
"lint": "eslint . --ext .cjs,.js,.jsx,.mjs,.ts,.tsx",
|
|
191
|
-
"pkg:build": "pkg build --strict",
|
|
192
|
-
"pkg:check": "pkg --strict",
|
|
193
|
-
"release": "semantic-release",
|
|
194
|
-
"storybook:build": "storybook build",
|
|
195
|
-
"storybook:dev": "storybook dev -p 6006",
|
|
196
|
-
"test": "jest",
|
|
197
|
-
"test:browser": "start-server-and-test 'run-s workshop:build workshop:start' http://localhost:1337 'run-s cypress:run'",
|
|
198
|
-
"ts:check": "tsc",
|
|
199
|
-
"watch": "pkg watch --strict",
|
|
200
|
-
"workshop:build": "workshop build",
|
|
201
|
-
"workshop:dev": "workshop dev",
|
|
202
|
-
"workshop:start": "http-server -a localhost -c-0 -p 1337 -s -P http://localhost:1337/index.html? dist"
|
|
203
212
|
}
|
|
204
|
-
}
|
|
213
|
+
}
|
|
@@ -216,21 +216,18 @@ const DialogCard = forwardRef(function DialogCard(
|
|
|
216
216
|
)
|
|
217
217
|
|
|
218
218
|
useClickOutside(
|
|
219
|
-
|
|
220
|
-
(
|
|
221
|
-
if (!isTopLayer || !onClickOutside) return
|
|
219
|
+
(event: MouseEvent) => {
|
|
220
|
+
if (!isTopLayer || !onClickOutside) return
|
|
222
221
|
|
|
223
|
-
|
|
222
|
+
const target = event.target as Node | null
|
|
224
223
|
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
224
|
+
if (target && !isTargetWithinScope(boundaryElement, portalElement, target)) {
|
|
225
|
+
// Ignore clicks outside of the scope
|
|
226
|
+
return
|
|
227
|
+
}
|
|
229
228
|
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
[boundaryElement, isTopLayer, onClickOutside, portalElement],
|
|
233
|
-
),
|
|
229
|
+
onClickOutside()
|
|
230
|
+
},
|
|
234
231
|
[rootElement],
|
|
235
232
|
)
|
|
236
233
|
|
|
@@ -19,7 +19,7 @@ export interface MenuProps extends ResponsivePaddingProps {
|
|
|
19
19
|
* @deprecated Use `shouldFocus="last"` instead.
|
|
20
20
|
*/
|
|
21
21
|
focusLast?: boolean
|
|
22
|
-
onClickOutside?: (event: MouseEvent
|
|
22
|
+
onClickOutside?: (event: MouseEvent) => void
|
|
23
23
|
onEscape?: () => void
|
|
24
24
|
onItemClick?: () => void
|
|
25
25
|
onItemSelect?: (index: number) => void
|
|
@@ -93,13 +93,7 @@ export const Menu = forwardRef(function Menu(
|
|
|
93
93
|
}, [activeIndex, onItemSelect])
|
|
94
94
|
|
|
95
95
|
// Close menu when clicking outside
|
|
96
|
-
useClickOutside(
|
|
97
|
-
useCallback(
|
|
98
|
-
(event) => isTopLayer && onClickOutside && onClickOutside(event),
|
|
99
|
-
[isTopLayer, onClickOutside],
|
|
100
|
-
),
|
|
101
|
-
[rootElement],
|
|
102
|
-
)
|
|
96
|
+
useClickOutside((event) => isTopLayer && onClickOutside && onClickOutside(event), [rootElement])
|
|
103
97
|
|
|
104
98
|
// Close menu when pressing Escape
|
|
105
99
|
useGlobalKeyDown(
|
|
@@ -140,7 +140,7 @@ export const MenuButton = forwardRef(function MenuButton(
|
|
|
140
140
|
}, [])
|
|
141
141
|
|
|
142
142
|
const handleMenuClickOutside = useCallback(
|
|
143
|
-
(event: MouseEvent
|
|
143
|
+
(event: MouseEvent) => {
|
|
144
144
|
const target = event.target
|
|
145
145
|
|
|
146
146
|
if (!(target instanceof Node)) {
|
|
@@ -5,7 +5,7 @@ export interface MenuContextValue {
|
|
|
5
5
|
activeElement: HTMLElement | null
|
|
6
6
|
activeIndex: number
|
|
7
7
|
mount: (element: HTMLElement | null, selected?: boolean) => () => void
|
|
8
|
-
onClickOutside?: (event: MouseEvent
|
|
8
|
+
onClickOutside?: (event: MouseEvent) => void
|
|
9
9
|
onEscape?: () => void
|
|
10
10
|
onItemClick?: () => void
|
|
11
11
|
onItemMouseEnter?: (event: React.MouseEvent<HTMLElement>) => void
|