@sanity/ui 2.7.0 → 2.7.1-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/dist/index.d.mts +43 -4
- package/dist/index.d.ts +43 -4
- package/dist/index.esm.js +16 -36
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +15 -35
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +16 -36
- package/dist/index.mjs.map +1 -1
- package/package.json +26 -34
- package/src/core/components/dialog/dialog.tsx +1 -1
- package/src/core/components/menu/menu.tsx +1 -1
- 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 +70 -0
- package/src/core/hooks/useClickOutside.ts +90 -65
package/dist/index.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { buildTheme, createColorTheme as createColorTheme$1, hexToRgb as hexToRgb$1, hslToRgb as hslToRgb$1, multiply as multiply$1, parseColor as parseColor$1, rgbToHex as rgbToHex$1, rgbToHsl as rgbToHsl$1, rgba as rgba$1, screen as screen$1, getTheme_v2, getScopedTheme } from "@sanity/ui/theme";
|
|
2
2
|
import { jsx, jsxs, Fragment } from "react/jsx-runtime";
|
|
3
|
-
import { useMemo, useState,
|
|
3
|
+
import { useMemo, useState, useEffect, useRef, useImperativeHandle, useDebugValue, useSyncExternalStore, createContext, useContext, forwardRef, useId, useCallback, Children, isValidElement, cloneElement, Component, memo, useLayoutEffect, useReducer, Fragment as Fragment$1, startTransition } from "react";
|
|
4
4
|
import ReactIs, { isValidElementType } from "react-is";
|
|
5
5
|
import { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css, styled, keyframes } from "styled-components";
|
|
6
6
|
import { SpinnerIcon, CheckmarkIcon, RemoveIcon, ChevronDownIcon, CloseIcon, ChevronRightIcon, ToggleArrowRightIcon } from "@sanity/icons";
|
|
@@ -131,45 +131,25 @@ function useArrayProp(val, defaultVal) {
|
|
|
131
131
|
[__perf_hash__]
|
|
132
132
|
);
|
|
133
133
|
}
|
|
134
|
-
function _getElements(element, elementsArg) {
|
|
135
|
-
const ret = [element];
|
|
136
|
-
for (const el of elementsArg)
|
|
137
|
-
Array.isArray(el) ? ret.push(...el) : ret.push(el);
|
|
138
|
-
return ret.filter(Boolean);
|
|
139
|
-
}
|
|
140
134
|
function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
|
|
141
|
-
const [
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if (prevElements.length !== nextElements.length) {
|
|
145
|
-
setElements(nextElements), elementsRef.current = nextElements;
|
|
135
|
+
const [legacyElement, setLegacyElement] = useState(null), onEvent = useEffectEvent((evt) => {
|
|
136
|
+
const target = evt.target;
|
|
137
|
+
if (!(target instanceof Node) || boundaryElement && !boundaryElement.contains(target))
|
|
146
138
|
return;
|
|
147
|
-
|
|
148
|
-
for (const el of
|
|
149
|
-
if (
|
|
150
|
-
setElements(nextElements), elementsRef.current = nextElements;
|
|
139
|
+
const elements = (Array.isArray(elementsArg) ? [legacyElement, ...elementsArg] : elementsArg()).flat();
|
|
140
|
+
for (const el of elements)
|
|
141
|
+
if (el && (target === el || el.contains(target)))
|
|
151
142
|
return;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
if (!listener) return;
|
|
160
|
-
const handleWindowMouseDown = (evt) => {
|
|
161
|
-
const target = evt.target;
|
|
162
|
-
if (target instanceof Node && !(boundaryElement && !boundaryElement.contains(target))) {
|
|
163
|
-
for (const el of elements)
|
|
164
|
-
if (target === el || el.contains(target))
|
|
165
|
-
return;
|
|
166
|
-
listener(evt);
|
|
167
|
-
}
|
|
168
|
-
};
|
|
169
|
-
return window.addEventListener("mousedown", handleWindowMouseDown), () => {
|
|
170
|
-
window.removeEventListener("mousedown", handleWindowMouseDown);
|
|
143
|
+
listener(evt);
|
|
144
|
+
}), hasListener = !!listener;
|
|
145
|
+
if (useEffect(() => {
|
|
146
|
+
if (!hasListener) return;
|
|
147
|
+
const handleEvent = (evt) => onEvent(evt);
|
|
148
|
+
return document.addEventListener("mousedown", handleEvent), document.addEventListener("touchstart", handleEvent), () => {
|
|
149
|
+
document.removeEventListener("mousedown", handleEvent), document.removeEventListener("touchstart", handleEvent);
|
|
171
150
|
};
|
|
172
|
-
}, [
|
|
151
|
+
}, [hasListener, onEvent]), Array.isArray(elementsArg))
|
|
152
|
+
return setLegacyElement;
|
|
173
153
|
}
|
|
174
154
|
function useCustomValidity(ref, customValidity) {
|
|
175
155
|
useEffect(() => {
|