@sanity/ui 2.1.5 → 2.1.7

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.js CHANGED
@@ -151,8 +151,7 @@ function useClickOutside(listener, elementsArg = EMPTY_ARRAY, boundaryElement) {
151
151
  return;
152
152
  }
153
153
  }, [element, elementsArg]), react.useEffect(() => {
154
- if (!listener)
155
- return;
154
+ if (!listener) return;
156
155
  const handleWindowMouseDown = (evt) => {
157
156
  const target = evt.target;
158
157
  if (target instanceof Node && !(boundaryElement && !boundaryElement.contains(target))) {
@@ -504,14 +503,10 @@ function useGlobalKeyDown(onKeyDown) {
504
503
  return react.useEffect(() => (addEventListener("keydown", onKeyDown), () => removeEventListener("keydown", onKeyDown)), [onKeyDown]);
505
504
  }
506
505
  function getGlobalScope() {
507
- if (typeof globalThis < "u")
508
- return globalThis;
509
- if (typeof window < "u")
510
- return window;
511
- if (typeof self < "u")
512
- return self;
513
- if (typeof global < "u")
514
- return global;
506
+ if (typeof globalThis < "u") return globalThis;
507
+ if (typeof window < "u") return window;
508
+ if (typeof self < "u") return self;
509
+ if (typeof global < "u") return global;
515
510
  throw new Error("@sanity/ui: could not locate global scope");
516
511
  }
517
512
  const globalScope = getGlobalScope();
@@ -568,8 +563,7 @@ function _createMediaStore(media) {
568
563
  };
569
564
  return { getSnapshot: () => {
570
565
  for (const { index, mq } of getSizes())
571
- if (mq.matches)
572
- return index;
566
+ if (mq.matches) return index;
573
567
  return 0;
574
568
  }, subscribe: (onStoreChange) => {
575
569
  const disposeFns = [];
@@ -1187,8 +1181,7 @@ function toBoxShadow(shadow, color) {
1187
1181
  return `${shadow.map(rem).join(" ")} ${color}`;
1188
1182
  }
1189
1183
  function shadowStyle(shadow, outlineWidth = 1) {
1190
- if (!shadow)
1191
- return EMPTY_RECORD;
1184
+ if (!shadow) return EMPTY_RECORD;
1192
1185
  const outline = `0 0 0 ${rem(outlineWidth)} var(--card-shadow-outline-color)`, umbra = toBoxShadow(shadow.umbra, "var(--card-shadow-umbra-color)"), penumbra = toBoxShadow(shadow.penumbra, "var(--card-shadow-penumbra-color)"), ambient = toBoxShadow(shadow.ambient, "var(--card-shadow-ambient-color)");
1193
1186
  return { boxShadow: `${outline}, ${umbra}, ${penumbra}, ${ambient}` };
1194
1187
  }
@@ -1423,8 +1416,7 @@ const Root$B = styledComponents.styled.div(
1423
1416
  animateArrowFrom || arrowPositionProp || "inside"
1424
1417
  ), [imageFailed, setImageFailed] = react.useState(!1), imageId = `avatar-image-${elementId}`;
1425
1418
  react.useEffect(() => {
1426
- if (arrowPosition === arrowPositionProp)
1427
- return;
1419
+ if (arrowPosition === arrowPositionProp) return;
1428
1420
  const raf = requestAnimationFrame(() => setArrowPosition(arrowPositionProp));
1429
1421
  return () => cancelAnimationFrame(raf);
1430
1422
  }, [arrowPosition, arrowPositionProp]), react.useEffect(() => {
@@ -2880,7 +2872,7 @@ const ElementQuery = react.forwardRef(function(props, ref) {
2880
2872
  }
2881
2873
  );
2882
2874
  });
2883
- var __defProp = Object.defineProperty, __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value, __publicField = (obj, key2, value) => (__defNormalProp(obj, key2 + "", value), value);
2875
+ var __defProp = Object.defineProperty, __defNormalProp = (obj, key2, value) => key2 in obj ? __defProp(obj, key2, { enumerable: !0, configurable: !0, writable: !0, value }) : obj[key2] = value, __publicField = (obj, key2, value) => __defNormalProp(obj, key2 + "", value);
2884
2876
  class ErrorBoundary extends react.Component {
2885
2877
  constructor() {
2886
2878
  super(...arguments), __publicField(this, "state", { error: null });
@@ -2991,8 +2983,7 @@ function focusLastDescendant(element) {
2991
2983
  return !1;
2992
2984
  }
2993
2985
  function _isScrollable(el) {
2994
- if (!(el instanceof Element))
2995
- return !1;
2986
+ if (!(el instanceof Element)) return !1;
2996
2987
  const style = window.getComputedStyle(el);
2997
2988
  return style.overflowX.includes("auto") || style.overflowX.includes("scroll") || style.overflowY.includes("auto") || style.overflowY.includes("scroll");
2998
2989
  }
@@ -3120,20 +3111,17 @@ const emptySubscribe$1 = () => () => {
3120
3111
  `, VirtualList = react.forwardRef(function(props, ref) {
3121
3112
  const { as = "div", gap = 0, getItemKey, items = [], onChange, renderItem, ...restProps } = props, { space } = useTheme_v2(), forwardedRef = useForwardedRef(ref), wrapperRef = react.useRef(null), [scrollTop, setScrollTop] = react.useState(0), [scrollHeight, setScrollHeight] = react.useState(0), [itemHeight, setItemHeight] = react.useState(-1);
3122
3113
  react.useEffect(() => {
3123
- if (!wrapperRef.current)
3124
- return;
3114
+ if (!wrapperRef.current) return;
3125
3115
  const firstElement = wrapperRef.current.firstChild;
3126
3116
  firstElement instanceof HTMLElement && setItemHeight(firstElement.offsetHeight);
3127
3117
  }, [renderItem]), react.useEffect(() => {
3128
- if (!forwardedRef.current)
3129
- return;
3118
+ if (!forwardedRef.current) return;
3130
3119
  let _scrollEl = forwardedRef.current.parentNode;
3131
3120
  for (; _scrollEl && !_isScrollable(_scrollEl); )
3132
3121
  _scrollEl = _scrollEl.parentNode;
3133
3122
  if (_scrollEl) {
3134
3123
  const scrollEl = _scrollEl;
3135
- if (!(scrollEl instanceof HTMLElement))
3136
- return;
3124
+ if (!(scrollEl instanceof HTMLElement)) return;
3137
3125
  const handleScroll2 = () => {
3138
3126
  setScrollTop(scrollEl.scrollTop);
3139
3127
  };
@@ -3355,8 +3343,7 @@ const Popover = react.memo(
3355
3343
  const referenceWidthRef = react.useRef();
3356
3344
  react.useEffect(() => {
3357
3345
  const floatingElement = forwardedRef.current;
3358
- if (!open || !floatingElement)
3359
- return;
3346
+ if (!open || !floatingElement) return;
3360
3347
  const referenceWidth = referenceWidthRef.current;
3361
3348
  matchReferenceWidth ? referenceWidth !== void 0 && (floatingElement.style.width = `${referenceWidth}px`) : width !== void 0 && (floatingElement.style.width = `${width}px`), typeof maxWidth == "number" && (floatingElement.style.maxWidth = `${maxWidth}px`);
3362
3349
  }, [width, forwardedRef, matchReferenceWidth, maxWidth, open]);
@@ -4228,8 +4215,7 @@ function useDelayedState(initialState) {
4228
4215
  const action = () => {
4229
4216
  setState(nextState);
4230
4217
  };
4231
- if (delayedAction.current && (clearTimeout(delayedAction.current), delayedAction.current = void 0), !delay)
4232
- return action();
4218
+ if (delayedAction.current && (clearTimeout(delayedAction.current), delayedAction.current = void 0), !delay) return action();
4233
4219
  delayedAction.current = setTimeout(action, delay);
4234
4220
  }, []);
4235
4221
  return [state, onStateChange];
@@ -4442,8 +4428,7 @@ const Root$a = styledComponents.styled(Layer)`
4442
4428
  [childProp == null ? void 0 : childProp.props, handleIsOpenChange]
4443
4429
  );
4444
4430
  react.useEffect(() => {
4445
- if (!showTooltip)
4446
- return;
4431
+ if (!showTooltip) return;
4447
4432
  function handleWindowMouseMove(event) {
4448
4433
  referenceElement && (referenceElement === event.target || event.target instanceof Node && referenceElement.contains(event.target) || (handleIsOpenChange(!1), window.removeEventListener("mousemove", handleWindowMouseMove)));
4449
4434
  }
@@ -4455,8 +4440,7 @@ const Root$a = styledComponents.styled(Layer)`
4455
4440
  }, [disabled, handleIsOpenChange, showTooltip]), react.useEffect(() => {
4456
4441
  !content && showTooltip && handleIsOpenChange(!1);
4457
4442
  }, [content, handleIsOpenChange, showTooltip]), react.useEffect(() => refs.setReference(referenceElement), [referenceElement, refs]), react.useEffect(() => {
4458
- if (!showTooltip)
4459
- return;
4443
+ if (!showTooltip) return;
4460
4444
  function handleWindowKeyDown(event) {
4461
4445
  event.key === "Escape" && handleIsOpenChange(!1, !0);
4462
4446
  }
@@ -4497,10 +4481,8 @@ const Root$a = styledComponents.styled(Layer)`
4497
4481
  handleMouseLeave,
4498
4482
  setReference
4499
4483
  ]);
4500
- if (!child)
4501
- return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
4502
- if (disabled)
4503
- return child;
4484
+ if (!child) return /* @__PURE__ */ jsxRuntime.jsx(jsxRuntime.Fragment, {});
4485
+ if (disabled) return child;
4504
4486
  const tooltip = /* @__PURE__ */ jsxRuntime.jsx(
4505
4487
  Root$a,
4506
4488
  {
@@ -4688,15 +4670,13 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4688
4670
  (event) => {
4689
4671
  var _a, _b;
4690
4672
  if (event.key === "ArrowDown") {
4691
- if (event.preventDefault(), !filteredOptionsLen)
4692
- return;
4673
+ if (event.preventDefault(), !filteredOptionsLen) return;
4693
4674
  const activeOption = filteredOptions.find((o) => o.value === activeValue), activeIndex = activeOption ? filteredOptions.indexOf(activeOption) : -1, nextActiveOption = filteredOptions[(activeIndex + 1) % filteredOptionsLen];
4694
4675
  nextActiveOption && dispatch({ type: "root/setActiveValue", value: nextActiveOption.value, listFocused: !0 });
4695
4676
  return;
4696
4677
  }
4697
4678
  if (event.key === "ArrowUp") {
4698
- if (event.preventDefault(), !filteredOptionsLen)
4699
- return;
4679
+ if (event.preventDefault(), !filteredOptionsLen) return;
4700
4680
  const activeOption = filteredOptions.find((o) => o.value === activeValue), activeIndex = activeOption ? filteredOptions.indexOf(activeOption) : -1, nextActiveOption = filteredOptions[activeIndex === -1 ? filteredOptionsLen - 1 : (filteredOptionsLen + activeIndex - 1) % filteredOptionsLen];
4701
4681
  nextActiveOption && dispatch({ type: "root/setActiveValue", value: nextActiveOption.value, listFocused: !0 });
4702
4682
  return;
@@ -4743,8 +4723,7 @@ const AUTOCOMPLETE_LISTBOX_IGNORE_KEYS = [
4743
4723
  !focused && valueRef.current && dispatch({ type: "root/setActiveValue", value: valueRef.current });
4744
4724
  }, [focused]), react.useEffect(() => {
4745
4725
  const listElement = listBoxElementRef.current;
4746
- if (!listElement)
4747
- return;
4726
+ if (!listElement) return;
4748
4727
  const activeOption = filteredOptions.find((o) => o.value === activeValue);
4749
4728
  if (activeOption) {
4750
4729
  const activeIndex = filteredOptions.indexOf(activeOption), activeItemElement = listElement.childNodes[activeIndex];
@@ -5120,8 +5099,7 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5120
5099
  }, [autoFocus, forwardedRef]), useGlobalKeyDown(
5121
5100
  react.useCallback(
5122
5101
  (event) => {
5123
- if (!isTopLayer || !onClose)
5124
- return;
5102
+ if (!isTopLayer || !onClose) return;
5125
5103
  const target = document.activeElement;
5126
5104
  target && !isTargetWithinScope(boundaryElement, portalElement, target) || event.key === "Escape" && (event.preventDefault(), event.stopPropagation(), onClose());
5127
5105
  },
@@ -5130,8 +5108,7 @@ const Root$7 = styledComponents.styled(Layer)(responsivePaddingStyle, dialogStyl
5130
5108
  ), useClickOutside(
5131
5109
  react.useCallback(
5132
5110
  (event) => {
5133
- if (!isTopLayer || !onClickOutside)
5134
- return;
5111
+ if (!isTopLayer || !onClickOutside) return;
5135
5112
  const target = event.target;
5136
5113
  target && !isTargetWithinScope(boundaryElement, portalElement, target) || onClickOutside();
5137
5114
  },
@@ -5302,8 +5279,7 @@ function _getDOMPath(rootElement, el) {
5302
5279
  let e = el;
5303
5280
  for (; e !== rootElement; ) {
5304
5281
  const parentElement = e.parentElement;
5305
- if (!parentElement)
5306
- return path;
5282
+ if (!parentElement) return path;
5307
5283
  const index = Array.from(parentElement.childNodes).indexOf(e);
5308
5284
  if (path.unshift(index), parentElement === rootElement)
5309
5285
  return path;
@@ -5313,8 +5289,7 @@ function _getDOMPath(rootElement, el) {
5313
5289
  }
5314
5290
  const EMPTY_PATH = [];
5315
5291
  function _sortElements(rootElement, elements) {
5316
- if (!rootElement)
5317
- return;
5292
+ if (!rootElement) return;
5318
5293
  const map = /* @__PURE__ */ new WeakMap();
5319
5294
  for (const el of elements)
5320
5295
  map.set(el, _getDOMPath(rootElement, el));
@@ -5334,9 +5309,8 @@ function useMenuController(props) {
5334
5309
  _setActiveIndex(nextActiveIndex), activeIndexRef.current = nextActiveIndex;
5335
5310
  }, []), mount = react.useCallback(
5336
5311
  (element, selected) => {
5337
- if (!element)
5338
- return () => {
5339
- };
5312
+ if (!element) return () => {
5313
+ };
5340
5314
  if (elementsRef.current.indexOf(element) === -1 && (elementsRef.current.push(element), _sortElements(rootElement, elementsRef.current)), selected) {
5341
5315
  const selectedIndex = elementsRef.current.indexOf(element);
5342
5316
  setActiveIndex(selectedIndex);
@@ -5356,8 +5330,7 @@ function useMenuController(props) {
5356
5330
  if (event.key === "Home") {
5357
5331
  event.preventDefault(), event.stopPropagation();
5358
5332
  const el = _getFocusableElements(elementsRef.current)[0];
5359
- if (!el)
5360
- return;
5333
+ if (!el) return;
5361
5334
  const currentIndex = elementsRef.current.indexOf(el);
5362
5335
  setActiveIndex(currentIndex);
5363
5336
  return;
@@ -5365,8 +5338,7 @@ function useMenuController(props) {
5365
5338
  if (event.key === "End") {
5366
5339
  event.preventDefault(), event.stopPropagation();
5367
5340
  const focusableElements = _getFocusableElements(elementsRef.current), el = focusableElements[focusableElements.length - 1];
5368
- if (!el)
5369
- return;
5341
+ if (!el) return;
5370
5342
  const currentIndex = elementsRef.current.indexOf(el);
5371
5343
  setActiveIndex(currentIndex);
5372
5344
  return;
@@ -5374,8 +5346,7 @@ function useMenuController(props) {
5374
5346
  if (event.key === "ArrowUp") {
5375
5347
  event.preventDefault(), event.stopPropagation();
5376
5348
  const focusableElements = _getFocusableElements(elementsRef.current), focusableLen = focusableElements.length;
5377
- if (focusableLen === 0)
5378
- return;
5349
+ if (focusableLen === 0) return;
5379
5350
  const focusedElement = elementsRef.current[activeIndexRef.current];
5380
5351
  let focusedIndex = focusableElements.indexOf(focusedElement);
5381
5352
  focusedIndex = (focusedIndex - 1 + focusableLen) % focusableLen;
@@ -5386,8 +5357,7 @@ function useMenuController(props) {
5386
5357
  if (event.key === "ArrowDown") {
5387
5358
  event.preventDefault(), event.stopPropagation();
5388
5359
  const focusableElements = _getFocusableElements(elementsRef.current), focusableLen = focusableElements.length;
5389
- if (focusableLen === 0)
5390
- return;
5360
+ if (focusableLen === 0) return;
5391
5361
  const focusedElement = elementsRef.current[activeIndexRef.current];
5392
5362
  let focusedIndex = focusableElements.indexOf(focusedElement);
5393
5363
  focusedIndex = (focusedIndex + 1) % focusableLen;
@@ -5408,8 +5378,7 @@ function useMenuController(props) {
5408
5378
  setActiveIndex(-2), rootElement == null || rootElement.focus();
5409
5379
  }, [setActiveIndex, rootElement]);
5410
5380
  return react.useEffect(() => {
5411
- if (!mounted)
5412
- return;
5381
+ if (!mounted) return;
5413
5382
  const rafId = window.requestAnimationFrame(() => {
5414
5383
  const _activeIndex = activeIndexRef.current;
5415
5384
  if (_activeIndex === -1) {
@@ -5630,13 +5599,13 @@ const Root$5 = styledComponents.styled(Box)`
5630
5599
  registerElement,
5631
5600
  shouldFocus
5632
5601
  ]
5633
- ), menu = ReactIs.isElement(menuProp) ? react.cloneElement(menuProp, menuProps) : null, setButtonRef = react.useCallback(
5602
+ ), menu = menuProp && react.cloneElement(menuProp, menuProps), setButtonRef = react.useCallback(
5634
5603
  (el) => {
5635
5604
  typeof ref == "function" ? ref(el) : ref && (ref.current = el), setButtonElement(el);
5636
5605
  },
5637
5606
  [ref]
5638
5607
  ), button = react.useMemo(
5639
- () => ReactIs.isElement(buttonProp) ? react.cloneElement(buttonProp, {
5608
+ () => buttonProp && react.cloneElement(buttonProp, {
5640
5609
  "data-ui": "MenuButton",
5641
5610
  id,
5642
5611
  onClick: handleButtonClick,
@@ -5646,7 +5615,7 @@ const Root$5 = styledComponents.styled(Box)`
5646
5615
  "aria-expanded": open,
5647
5616
  ref: setButtonRef,
5648
5617
  selected: open
5649
- }) : null,
5618
+ }),
5650
5619
  [buttonProp, handleButtonClick, handleButtonKeyDown, handleMouseDown, id, open, setButtonRef]
5651
5620
  ), popoverProps = react.useMemo(
5652
5621
  () => ({
@@ -6446,11 +6415,9 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6446
6415
  if (event.key === "ArrowLeft") {
6447
6416
  event.preventDefault();
6448
6417
  const itemKey = focusedElementRef.current.getAttribute("data-tree-key");
6449
- if (!itemKey)
6450
- return;
6418
+ if (!itemKey) return;
6451
6419
  const itemState = stateRef.current[itemKey];
6452
- if (!itemState)
6453
- return;
6420
+ if (!itemState) return;
6454
6421
  if (itemState.expanded)
6455
6422
  setState((s) => {
6456
6423
  const itemState2 = s[itemKey];
@@ -6467,8 +6434,7 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6467
6434
  if (event.key === "ArrowRight") {
6468
6435
  event.preventDefault();
6469
6436
  const focusedKey = focusedElementRef.current.getAttribute("data-tree-key");
6470
- if (!focusedKey)
6471
- return;
6437
+ if (!focusedKey) return;
6472
6438
  (_a = stateRef.current[focusedKey]) != null && _a.expanded || setState((s) => {
6473
6439
  const itemState = s[focusedKey];
6474
6440
  return itemState ? { ...s, [focusedKey]: { ...itemState, expanded: !0 } } : s;
@@ -6485,8 +6451,7 @@ const key = Symbol.for("@sanity/ui/context/tree"), TreeContext = createGlobalSco
6485
6451
  [onFocus]
6486
6452
  );
6487
6453
  return react.useEffect(() => {
6488
- if (!forwardedRef.current)
6489
- return;
6454
+ if (!forwardedRef.current) return;
6490
6455
  const _itemElements = Array.from(
6491
6456
  forwardedRef.current.querySelectorAll('[data-ui="TreeItem"]')
6492
6457
  );