@sanity/ui 1.3.3 → 1.4.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.cjs.mjs +2 -0
- package/dist/index.d.ts +27 -0
- package/dist/index.esm.js +70 -25
- package/dist/index.esm.js.map +1 -1
- package/dist/index.js +71 -24
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/primitives/popover/__workshop__/PositionStory.tsx +103 -0
- package/src/primitives/popover/__workshop__/index.ts +5 -0
- package/src/primitives/popover/index.ts +3 -0
- package/src/primitives/popover/popover.test.tsx +164 -0
- package/src/primitives/popover/popover.tsx +8 -0
- package/src/primitives/popover/popoverContext.tsx +9 -0
- package/src/primitives/popover/popoverProvider.tsx +29 -0
- package/src/primitives/popover/types.ts +8 -0
- package/src/primitives/popover/useOnForcedUpdate.ts +15 -0
- package/src/primitives/popover/usePopover.ts +24 -0
package/dist/index.js
CHANGED
|
@@ -3076,9 +3076,9 @@ function getGlobalScope() {
|
|
|
3076
3076
|
throw new Error("@sanity/ui: could not locate global scope");
|
|
3077
3077
|
}
|
|
3078
3078
|
const globalScope = getGlobalScope();
|
|
3079
|
-
const key$
|
|
3080
|
-
globalScope[key$
|
|
3081
|
-
const ThemeContext = globalScope[key$
|
|
3079
|
+
const key$8 = Symbol.for("@sanity/ui/context/theme");
|
|
3080
|
+
globalScope[key$8] = globalScope[key$8] || react.createContext(null);
|
|
3081
|
+
const ThemeContext = globalScope[key$8];
|
|
3082
3082
|
function ThemeProvider(props) {
|
|
3083
3083
|
const parentTheme = react.useContext(ThemeContext);
|
|
3084
3084
|
const {
|
|
@@ -5168,9 +5168,9 @@ const KBD = react.forwardRef(function KBD2(props, ref) {
|
|
|
5168
5168
|
})
|
|
5169
5169
|
});
|
|
5170
5170
|
});
|
|
5171
|
-
const key$
|
|
5172
|
-
globalScope[key$
|
|
5173
|
-
const BoundaryElementContext = globalScope[key$
|
|
5171
|
+
const key$7 = Symbol.for("@sanity/ui/context/boundaryElement");
|
|
5172
|
+
globalScope[key$7] = globalScope[key$7] || react.createContext(null);
|
|
5173
|
+
const BoundaryElementContext = globalScope[key$7];
|
|
5174
5174
|
function BoundaryElementProvider(props) {
|
|
5175
5175
|
const {
|
|
5176
5176
|
children,
|
|
@@ -5288,9 +5288,9 @@ function getLayerContext(contextValue) {
|
|
|
5288
5288
|
}
|
|
5289
5289
|
throw new Error("could not get layer context");
|
|
5290
5290
|
}
|
|
5291
|
-
const key$
|
|
5292
|
-
globalScope[key$
|
|
5293
|
-
const LayerContext = globalScope[key$
|
|
5291
|
+
const key$6 = Symbol.for("@sanity/ui/context/layer");
|
|
5292
|
+
globalScope[key$6] = globalScope[key$6] || react.createContext(null);
|
|
5293
|
+
const LayerContext = globalScope[key$6];
|
|
5294
5294
|
function useLayer() {
|
|
5295
5295
|
const value = react.useContext(LayerContext);
|
|
5296
5296
|
if (!value) {
|
|
@@ -5527,7 +5527,7 @@ const Layer = react.forwardRef(function Layer2(props, ref) {
|
|
|
5527
5527
|
})
|
|
5528
5528
|
});
|
|
5529
5529
|
});
|
|
5530
|
-
const key$
|
|
5530
|
+
const key$5 = Symbol.for("@sanity/ui/context/portal");
|
|
5531
5531
|
const elementKey = Symbol.for("@sanity/ui/context/portal/element");
|
|
5532
5532
|
globalScope[elementKey] = null;
|
|
5533
5533
|
const defaultContextValue = {
|
|
@@ -5546,8 +5546,8 @@ const defaultContextValue = {
|
|
|
5546
5546
|
return globalScope[elementKey];
|
|
5547
5547
|
}
|
|
5548
5548
|
};
|
|
5549
|
-
globalScope[key$
|
|
5550
|
-
const PortalContext = globalScope[key$
|
|
5549
|
+
globalScope[key$5] = globalScope[key$5] || react.createContext(defaultContextValue);
|
|
5550
|
+
const PortalContext = globalScope[key$5];
|
|
5551
5551
|
function usePortal() {
|
|
5552
5552
|
const value = react.useContext(PortalContext);
|
|
5553
5553
|
if (!value) {
|
|
@@ -5927,6 +5927,17 @@ const PopoverCard = react.memo(react.forwardRef(function PopoverCard2(props, ref
|
|
|
5927
5927
|
});
|
|
5928
5928
|
}));
|
|
5929
5929
|
PopoverCard.displayName = "PopoverCard";
|
|
5930
|
+
const key$4 = Symbol.for("@sanity/ui/context/popover");
|
|
5931
|
+
globalScope[key$4] = globalScope[key$4] || react.createContext(null);
|
|
5932
|
+
const PopoverContext = globalScope[key$4];
|
|
5933
|
+
const useOnForcedUpdate = eventHandler => {
|
|
5934
|
+
const contextValue = react.useContext(PopoverContext);
|
|
5935
|
+
react.useEffect(() => {
|
|
5936
|
+
if ((contextValue == null ? void 0 : contextValue.lastUpdateId) !== null) {
|
|
5937
|
+
eventHandler == null ? void 0 : eventHandler();
|
|
5938
|
+
}
|
|
5939
|
+
}, [contextValue == null ? void 0 : contextValue.lastUpdateId]);
|
|
5940
|
+
};
|
|
5930
5941
|
const Popover = react.memo(react.forwardRef(function Popover2(props, ref) {
|
|
5931
5942
|
var _a, _b, _c, _d, _e;
|
|
5932
5943
|
const theme = useTheme();
|
|
@@ -6033,9 +6044,13 @@ const Popover = react.memo(react.forwardRef(function Popover2(props, ref) {
|
|
|
6033
6044
|
placement,
|
|
6034
6045
|
reference: referenceRef,
|
|
6035
6046
|
floating: floatingRef,
|
|
6047
|
+
update: floatingUpdate,
|
|
6036
6048
|
middlewareData,
|
|
6037
6049
|
strategy
|
|
6038
6050
|
} = reactDom$1.useFloating(floatingProps);
|
|
6051
|
+
const handleForcedUpdate = react.useCallback(() => {
|
|
6052
|
+
floatingUpdate();
|
|
6053
|
+
}, [floatingUpdate]);
|
|
6039
6054
|
const referenceHidden = (_c = middlewareData.hide) == null ? void 0 : _c.referenceHidden;
|
|
6040
6055
|
const arrowX = (_d = middlewareData.arrow) == null ? void 0 : _d.x;
|
|
6041
6056
|
const arrowY = (_e = middlewareData.arrow) == null ? void 0 : _e.y;
|
|
@@ -6064,6 +6079,7 @@ const Popover = react.memo(react.forwardRef(function Popover2(props, ref) {
|
|
|
6064
6079
|
react.useEffect(() => {
|
|
6065
6080
|
referenceRef(referenceElement || null);
|
|
6066
6081
|
}, [referenceRef, referenceElement]);
|
|
6082
|
+
useOnForcedUpdate(handleForcedUpdate);
|
|
6067
6083
|
if (disabled) {
|
|
6068
6084
|
return childProp || /* @__PURE__ */jsxRuntime.jsx(jsxRuntime.Fragment, {});
|
|
6069
6085
|
}
|
|
@@ -6103,6 +6119,35 @@ const Popover = react.memo(react.forwardRef(function Popover2(props, ref) {
|
|
|
6103
6119
|
});
|
|
6104
6120
|
}));
|
|
6105
6121
|
Popover.displayName = "Popover";
|
|
6122
|
+
const PopoverProvider = _ref22 => {
|
|
6123
|
+
let {
|
|
6124
|
+
children
|
|
6125
|
+
} = _ref22;
|
|
6126
|
+
const [lastUpdateId, setUpdateId] = react.useState(null);
|
|
6127
|
+
const forceUpdate = react.useCallback(() => {
|
|
6128
|
+
const newId = Math.random().toString(36).substr(2, 9);
|
|
6129
|
+
setUpdateId(newId);
|
|
6130
|
+
}, []);
|
|
6131
|
+
const value = react.useMemo(() => ({
|
|
6132
|
+
version: 0,
|
|
6133
|
+
lastUpdateId,
|
|
6134
|
+
forceUpdate
|
|
6135
|
+
}), [lastUpdateId, forceUpdate]);
|
|
6136
|
+
return /* @__PURE__ */jsxRuntime.jsx(PopoverContext.Provider, {
|
|
6137
|
+
value,
|
|
6138
|
+
children
|
|
6139
|
+
});
|
|
6140
|
+
};
|
|
6141
|
+
function usePopover() {
|
|
6142
|
+
const value = react.useContext(PopoverContext);
|
|
6143
|
+
if (!value) {
|
|
6144
|
+
throw new Error("usePopover(): missing context value");
|
|
6145
|
+
}
|
|
6146
|
+
if (!isRecord(value) || value.version !== 0) {
|
|
6147
|
+
throw new Error("usePopover(): the context value is not compatible");
|
|
6148
|
+
}
|
|
6149
|
+
return value;
|
|
6150
|
+
}
|
|
6106
6151
|
function radioBaseStyle() {
|
|
6107
6152
|
return styled.css(_templateObject36 || (_templateObject36 = _taggedTemplateLiteral(["\n position: relative;\n\n &:not([hidden]) {\n display: inline-block;\n }\n\n &[data-read-only] {\n outline: 1px solid red;\n }\n "])));
|
|
6108
6153
|
}
|
|
@@ -6934,10 +6979,10 @@ const InnerAutocomplete = react.forwardRef(function InnerAutocomplete2(props, re
|
|
|
6934
6979
|
query,
|
|
6935
6980
|
value
|
|
6936
6981
|
} = state;
|
|
6937
|
-
const defaultRenderOption = react.useCallback(
|
|
6982
|
+
const defaultRenderOption = react.useCallback(_ref23 => {
|
|
6938
6983
|
let {
|
|
6939
6984
|
value: value2
|
|
6940
|
-
} =
|
|
6985
|
+
} = _ref23;
|
|
6941
6986
|
return /* @__PURE__ */jsxRuntime.jsx(Card, {
|
|
6942
6987
|
"data-as": "button",
|
|
6943
6988
|
padding: paddingProp,
|
|
@@ -7384,10 +7429,10 @@ const Breadcrumbs = react.forwardRef(function Breadcrumbs2(props, ref) {
|
|
|
7384
7429
|
}, itemIndex))
|
|
7385
7430
|
});
|
|
7386
7431
|
});
|
|
7387
|
-
function dialogStyle(
|
|
7432
|
+
function dialogStyle(_ref24) {
|
|
7388
7433
|
let {
|
|
7389
7434
|
theme
|
|
7390
|
-
} =
|
|
7435
|
+
} = _ref24;
|
|
7391
7436
|
const color = theme.sanity.color.base;
|
|
7392
7437
|
return {
|
|
7393
7438
|
"&:not([hidden])": {
|
|
@@ -8407,15 +8452,15 @@ const MenuItem = react.forwardRef(function MenuItem2(props, forwardedRef) {
|
|
|
8407
8452
|
});
|
|
8408
8453
|
const keyframe = styled.keyframes(_templateObject78 || (_templateObject78 = _taggedTemplateLiteral(["\n 0% {\n background-position: 100%;\n }\n 100% {\n background-position: -100%;\n }\n"])));
|
|
8409
8454
|
const animation = styled.css(_templateObject79 || (_templateObject79 = _taggedTemplateLiteral(["\n background-image: linear-gradient(\n to right,\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-to),\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-from),\n var(--card-skeleton-color-from)\n );\n background-position: 100%;\n background-size: 200% 100%;\n background-attachment: fixed;\n animation-name: ", ";\n animation-timing-function: ease-in-out;\n animation-iteration-count: infinite;\n animation-duration: 2000ms;\n"])), keyframe);
|
|
8410
|
-
const skeletonStyle = styled.css(_templateObject80 || (_templateObject80 = _taggedTemplateLiteral(["\n opacity: ", ";\n transition: opacity 200ms ease-in;\n\n @media screen and (prefers-reduced-motion: no-preference) {\n ", "\n }\n\n @media screen and (prefers-reduced-motion: reduce) {\n background-color: var(--card-skeleton-color-from);\n }\n"])),
|
|
8455
|
+
const skeletonStyle = styled.css(_templateObject80 || (_templateObject80 = _taggedTemplateLiteral(["\n opacity: ", ";\n transition: opacity 200ms ease-in;\n\n @media screen and (prefers-reduced-motion: no-preference) {\n ", "\n }\n\n @media screen and (prefers-reduced-motion: reduce) {\n background-color: var(--card-skeleton-color-from);\n }\n"])), _ref25 => {
|
|
8411
8456
|
let {
|
|
8412
8457
|
$visible
|
|
8413
|
-
} =
|
|
8458
|
+
} = _ref25;
|
|
8414
8459
|
return $visible ? 1 : 0;
|
|
8415
|
-
},
|
|
8460
|
+
}, _ref26 => {
|
|
8416
8461
|
let {
|
|
8417
8462
|
$animated
|
|
8418
|
-
} =
|
|
8463
|
+
} = _ref26;
|
|
8419
8464
|
return $animated ? animation : styled.css(_templateObject81 || (_templateObject81 = _taggedTemplateLiteral(["\n background-color: var(--card-skeleton-color-from);\n "])));
|
|
8420
8465
|
});
|
|
8421
8466
|
const Root$4 = styled__default.default(Box)(responsiveRadiusStyle, skeletonStyle);
|
|
@@ -8446,12 +8491,12 @@ const Skeleton = react.forwardRef(function Skeleton2(props, ref) {
|
|
|
8446
8491
|
ref
|
|
8447
8492
|
});
|
|
8448
8493
|
});
|
|
8449
|
-
const Root$3 = styled__default.default(Skeleton)(
|
|
8494
|
+
const Root$3 = styled__default.default(Skeleton)(_ref27 => {
|
|
8450
8495
|
let {
|
|
8451
8496
|
$size,
|
|
8452
8497
|
$style,
|
|
8453
8498
|
theme
|
|
8454
|
-
} =
|
|
8499
|
+
} = _ref27;
|
|
8455
8500
|
const {
|
|
8456
8501
|
media
|
|
8457
8502
|
} = theme.sanity;
|
|
@@ -8772,12 +8817,12 @@ function ToastProvider(props) {
|
|
|
8772
8817
|
paddingY,
|
|
8773
8818
|
children: /* @__PURE__ */jsxRuntime.jsx(framerMotion.AnimatePresence, {
|
|
8774
8819
|
initial: false,
|
|
8775
|
-
children: state.map(
|
|
8820
|
+
children: state.map(_ref28 => {
|
|
8776
8821
|
let {
|
|
8777
8822
|
dismiss,
|
|
8778
8823
|
id,
|
|
8779
8824
|
params
|
|
8780
|
-
} =
|
|
8825
|
+
} = _ref28;
|
|
8781
8826
|
return /* @__PURE__ */jsxRuntime.jsx(framerMotion.motion.div, {
|
|
8782
8827
|
animate: {
|
|
8783
8828
|
opacity: 1,
|
|
@@ -9293,6 +9338,7 @@ exports.MenuDivider = MenuDivider;
|
|
|
9293
9338
|
exports.MenuGroup = MenuGroup;
|
|
9294
9339
|
exports.MenuItem = MenuItem;
|
|
9295
9340
|
exports.Popover = Popover;
|
|
9341
|
+
exports.PopoverProvider = PopoverProvider;
|
|
9296
9342
|
exports.Portal = Portal;
|
|
9297
9343
|
exports.PortalProvider = PortalProvider;
|
|
9298
9344
|
exports.Radio = Radio;
|
|
@@ -9366,6 +9412,7 @@ exports.useForwardedRef = useForwardedRef;
|
|
|
9366
9412
|
exports.useGlobalKeyDown = useGlobalKeyDown;
|
|
9367
9413
|
exports.useLayer = useLayer;
|
|
9368
9414
|
exports.useMediaIndex = useMediaIndex;
|
|
9415
|
+
exports.usePopover = usePopover;
|
|
9369
9416
|
exports.usePortal = usePortal;
|
|
9370
9417
|
exports.usePrefersDark = usePrefersDark;
|
|
9371
9418
|
exports.usePrefersReducedMotion = usePrefersReducedMotion;
|