@sanity/ui 2.7.0 → 2.7.1-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.esm.js +10 -2
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +10 -2
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +10 -2
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -34
- package/src/core/hooks/useMatchMedia.ts +9 -3
package/dist/index.esm.js
CHANGED
|
@@ -520,13 +520,21 @@ function useGlobalKeyDown(onKeyDown) {
|
|
|
520
520
|
function useMatchMedia(mediaQueryString, getServerSnapshot2) {
|
|
521
521
|
const { subscribe: subscribe2, getSnapshot } = useMemo(() => {
|
|
522
522
|
let MEDIA_QUERY_CACHE;
|
|
523
|
-
|
|
523
|
+
function getMatchMedia() {
|
|
524
|
+
return MEDIA_QUERY_CACHE === void 0 && (MEDIA_QUERY_CACHE = window.matchMedia(mediaQueryString)), MEDIA_QUERY_CACHE;
|
|
525
|
+
}
|
|
524
526
|
return {
|
|
525
527
|
subscribe: (onStoreChange) => {
|
|
526
528
|
const matchMedia = getMatchMedia();
|
|
527
529
|
return matchMedia.addEventListener("change", onStoreChange), () => matchMedia.removeEventListener("change", onStoreChange);
|
|
528
530
|
},
|
|
529
|
-
getSnapshot: () =>
|
|
531
|
+
getSnapshot: () => {
|
|
532
|
+
try {
|
|
533
|
+
return getMatchMedia().matches;
|
|
534
|
+
} catch (err) {
|
|
535
|
+
throw new Error(`Failed to match media query: ${mediaQueryString}`, { cause: err });
|
|
536
|
+
}
|
|
537
|
+
}
|
|
530
538
|
};
|
|
531
539
|
}, [mediaQueryString]);
|
|
532
540
|
return useDebugValue(mediaQueryString), useSyncExternalStore(subscribe2, getSnapshot, getServerSnapshot2);
|