@sanity/ui 2.1.2 → 2.1.3-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 +3 -2
- package/dist/index.d.ts +3 -2
- package/dist/index.esm.js +27 -32
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +27 -32
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +27 -32
- package/dist/index.mjs.map +1 -1
- package/package.json +43 -47
- package/src/core/components/dialog/dialogContext.ts +4 -5
- package/src/core/components/menu/menuContext.ts +2 -5
- package/src/core/components/toast/toastContext.ts +2 -5
- package/src/core/components/tree/treeContext.ts +2 -5
- package/src/core/lib/createGlobalScopedContext.ts +24 -0
- package/src/core/primitives/tooltip/tooltipDelayGroup/tooltipDelayGroupContext.tsx +3 -6
- package/src/core/theme/themeContext.ts +2 -5
- package/src/core/theme/themeProvider.tsx +4 -4
- package/src/core/utils/boundaryElement/boundaryElementContext.ts +5 -6
- package/src/core/utils/layer/layerContext.ts +2 -5
- package/src/core/utils/portal/portalContext.ts +2 -4
- package/src/core/utils/portal/portalProvider.tsx +10 -5
package/dist/index.js
CHANGED
|
@@ -514,9 +514,11 @@ function getGlobalScope() {
|
|
|
514
514
|
return global;
|
|
515
515
|
throw new Error("@sanity/ui: could not locate global scope");
|
|
516
516
|
}
|
|
517
|
-
const globalScope = getGlobalScope()
|
|
518
|
-
|
|
519
|
-
|
|
517
|
+
const globalScope = getGlobalScope();
|
|
518
|
+
function createGlobalScopedContext(key2, defaultValue) {
|
|
519
|
+
return typeof document > "u" ? react.createContext(defaultValue) : (globalScope[key2] = globalScope[key2] || react.createContext(defaultValue), globalScope[key2]);
|
|
520
|
+
}
|
|
521
|
+
const key$8 = Symbol.for("@sanity/ui/context/theme"), ThemeContext = createGlobalScopedContext(key$8, null);
|
|
520
522
|
function ThemeProvider(props) {
|
|
521
523
|
const parentTheme = react.useContext(ThemeContext), {
|
|
522
524
|
children,
|
|
@@ -2816,9 +2818,10 @@ const Root$k = styledComponents.styled.div(
|
|
|
2816
2818
|
/* @__PURE__ */ jsxRuntime.jsx(StrokePath, { d: strokePath, mask: "url(#stroke-mask)", strokeWidth: strokeWidth * 2 }),
|
|
2817
2819
|
/* @__PURE__ */ jsxRuntime.jsx(ShapePath, { d: fillPath })
|
|
2818
2820
|
] }) });
|
|
2819
|
-
}), key$7 = Symbol.for("@sanity/ui/context/boundaryElement")
|
|
2820
|
-
|
|
2821
|
-
|
|
2821
|
+
}), key$7 = Symbol.for("@sanity/ui/context/boundaryElement"), BoundaryElementContext = createGlobalScopedContext(
|
|
2822
|
+
key$7,
|
|
2823
|
+
null
|
|
2824
|
+
);
|
|
2822
2825
|
function BoundaryElementProvider(props) {
|
|
2823
2826
|
const { children, element } = props, value = react.useMemo(() => ({ version: 0, element }), [element]);
|
|
2824
2827
|
return /* @__PURE__ */ jsxRuntime.jsx(BoundaryElementContext.Provider, { value, children });
|
|
@@ -2906,9 +2909,7 @@ function getLayerContext(contextValue) {
|
|
|
2906
2909
|
return contextValue;
|
|
2907
2910
|
throw new Error("could not get layer context");
|
|
2908
2911
|
}
|
|
2909
|
-
const key$6 = Symbol.for("@sanity/ui/context/layer");
|
|
2910
|
-
globalScope[key$6] = globalScope[key$6] || react.createContext(null);
|
|
2911
|
-
const LayerContext = globalScope[key$6];
|
|
2912
|
+
const key$6 = Symbol.for("@sanity/ui/context/layer"), LayerContext = createGlobalScopedContext(key$6, null);
|
|
2912
2913
|
function useLayer() {
|
|
2913
2914
|
const value = react.useContext(LayerContext);
|
|
2914
2915
|
if (!value)
|
|
@@ -3062,9 +3063,7 @@ const defaultContextValue = {
|
|
|
3062
3063
|
get element() {
|
|
3063
3064
|
return typeof document > "u" ? null : (globalScope[elementKey] || (globalScope[elementKey] = document.createElement("div"), globalScope[elementKey].setAttribute("data-portal", ""), document.body.appendChild(globalScope[elementKey])), globalScope[elementKey]);
|
|
3064
3065
|
}
|
|
3065
|
-
};
|
|
3066
|
-
globalScope[key$5] = globalScope[key$5] || react.createContext(defaultContextValue);
|
|
3067
|
-
const PortalContext = globalScope[key$5];
|
|
3066
|
+
}, PortalContext = createGlobalScopedContext(key$5, defaultContextValue);
|
|
3068
3067
|
function usePortal() {
|
|
3069
3068
|
const value = react.useContext(PortalContext);
|
|
3070
3069
|
if (!value)
|
|
@@ -3088,17 +3087,21 @@ function _isEqual(objA, objB) {
|
|
|
3088
3087
|
const keysA = Object.keys(objA), keysB = Object.keys(objB);
|
|
3089
3088
|
return keysA.length !== keysB.length ? !1 : keysA.every((key2) => objA[key2] === objB[key2]);
|
|
3090
3089
|
}
|
|
3091
|
-
const __BROWSER__ = typeof document < "u";
|
|
3092
3090
|
function PortalProvider(props) {
|
|
3093
|
-
const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp),
|
|
3091
|
+
const { boundaryElement, children, element, __unstable_elements: elementsProp } = props, elements = useUnique(elementsProp), fallbackElement = react.useSyncExternalStore(
|
|
3092
|
+
emptySubscribe$1,
|
|
3093
|
+
() => document.body,
|
|
3094
|
+
() => null
|
|
3095
|
+
), value = react.useMemo(() => ({
|
|
3094
3096
|
version: 0,
|
|
3095
3097
|
boundaryElement: boundaryElement || null,
|
|
3096
|
-
element: element ||
|
|
3098
|
+
element: element || fallbackElement,
|
|
3097
3099
|
elements
|
|
3098
|
-
}), [boundaryElement, element, elements]);
|
|
3100
|
+
}), [boundaryElement, element, elements, fallbackElement]);
|
|
3099
3101
|
return /* @__PURE__ */ jsxRuntime.jsx(PortalContext.Provider, { value, children });
|
|
3100
3102
|
}
|
|
3101
|
-
const
|
|
3103
|
+
const emptySubscribe$1 = () => () => {
|
|
3104
|
+
}, Root$i = styledComponents.styled.div`
|
|
3102
3105
|
display: block;
|
|
3103
3106
|
width: 0;
|
|
3104
3107
|
height: 0;
|
|
@@ -4315,9 +4318,7 @@ const DEFAULT_TOOLTIP_ARROW_WIDTH = 15, DEFAULT_TOOLTIP_ARROW_HEIGHT = 6, DEFAUL
|
|
|
4315
4318
|
})
|
|
4316
4319
|
);
|
|
4317
4320
|
TooltipCard.displayName = "TooltipCard";
|
|
4318
|
-
const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup");
|
|
4319
|
-
globalScope[key$4] = globalScope[key$4] || react.createContext(null);
|
|
4320
|
-
const TooltipDelayGroupContext = globalScope[key$4];
|
|
4321
|
+
const key$4 = Symbol.for("@sanity/ui/context/tooltipDelayGroup"), TooltipDelayGroupContext = createGlobalScopedContext(key$4, null);
|
|
4321
4322
|
function useTooltipDelayGroup() {
|
|
4322
4323
|
return react.useContext(TooltipDelayGroupContext);
|
|
4323
4324
|
}
|
|
@@ -5054,9 +5055,9 @@ function animationDialogStyle(props) {
|
|
|
5054
5055
|
}
|
|
5055
5056
|
` : styledComponents.css``;
|
|
5056
5057
|
}
|
|
5057
|
-
const key$3 = Symbol.for("@sanity/ui/context/dialog")
|
|
5058
|
-
|
|
5059
|
-
|
|
5058
|
+
const key$3 = Symbol.for("@sanity/ui/context/dialog"), DialogContext = createGlobalScopedContext(key$3, {
|
|
5059
|
+
version: 0
|
|
5060
|
+
});
|
|
5060
5061
|
function useDialog() {
|
|
5061
5062
|
return react.useContext(DialogContext);
|
|
5062
5063
|
}
|
|
@@ -5289,9 +5290,7 @@ const Root$6 = styledComponents.styled.kbd`
|
|
|
5289
5290
|
`, Hotkeys = react.forwardRef(function(props, ref) {
|
|
5290
5291
|
const { fontSize: fontSize2, keys, padding, radius, space: spaceProp = 0.5, ...restProps } = props, space = useArrayProp(spaceProp);
|
|
5291
5292
|
return !keys || keys.length === 0 ? /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {}) : /* @__PURE__ */ jsxRuntime.jsx(Root$6, { "data-ui": "Hotkeys", ...restProps, ref, children: /* @__PURE__ */ jsxRuntime.jsx(Inline, { as: "span", space, children: keys.map((key2, i) => /* @__PURE__ */ jsxRuntime.jsx(Key, { fontSize: fontSize2, padding, radius, children: key2 }, i)) }) });
|
|
5292
|
-
}), key$2 = Symbol.for("@sanity/ui/context/menu");
|
|
5293
|
-
globalScope[key$2] = globalScope[key$2] || react.createContext(null);
|
|
5294
|
-
const MenuContext = globalScope[key$2];
|
|
5293
|
+
}), key$2 = Symbol.for("@sanity/ui/context/menu"), MenuContext = createGlobalScopedContext(key$2, null);
|
|
5295
5294
|
function _isFocusable(element) {
|
|
5296
5295
|
return isHTMLAnchorElement(element) && element.getAttribute("data-disabled") !== "true" || isHTMLButtonElement(element) && !element.disabled;
|
|
5297
5296
|
}
|
|
@@ -6228,9 +6227,7 @@ function useMounted() {
|
|
|
6228
6227
|
);
|
|
6229
6228
|
}
|
|
6230
6229
|
const subscribe = () => () => {
|
|
6231
|
-
}, key$1 = Symbol.for("@sanity/ui/context/toast")
|
|
6232
|
-
globalScope[key$1] = globalScope[key$1] || react.createContext(null);
|
|
6233
|
-
const ToastContext = globalScope[key$1], Root$1 = styledComponents.styled(Layer)`
|
|
6230
|
+
}, key$1 = Symbol.for("@sanity/ui/context/toast"), ToastContext = createGlobalScopedContext(key$1, null), Root$1 = styledComponents.styled(Layer)`
|
|
6234
6231
|
position: fixed;
|
|
6235
6232
|
top: 0;
|
|
6236
6233
|
left: 0;
|
|
@@ -6388,9 +6385,7 @@ function _focusItemElement(el) {
|
|
|
6388
6385
|
firstChild && firstChild instanceof HTMLElement && firstChild.focus();
|
|
6389
6386
|
}
|
|
6390
6387
|
}
|
|
6391
|
-
const key = Symbol.for("@sanity/ui/context/tree")
|
|
6392
|
-
globalScope[key] = globalScope[key] || react.createContext(null);
|
|
6393
|
-
const TreeContext = globalScope[key], Tree = react.memo(
|
|
6388
|
+
const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalScopedContext(key, null), Tree = react.memo(
|
|
6394
6389
|
react.forwardRef(function(props, ref) {
|
|
6395
6390
|
const { children, space = 1, onFocus, ...restProps } = props, forwardedRef = useForwardedRef(ref), [focusedElement, setFocusedElement] = react.useState(null), focusedElementRef = react.useRef(focusedElement), path = react.useMemo(() => [], []), [itemElements, setItemElements] = react.useState([]), [state, setState] = react.useState({}), stateRef = react.useRef(state);
|
|
6396
6391
|
react.useEffect(() => {
|