@sanity/ui 0.37.5 → 0.37.6-next.18

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.
Files changed (41) hide show
  1. package/lib/dts/components/autocomplete/autocomplete.d.ts.map +1 -1
  2. package/lib/dts/components/autocomplete/autocomplete.styles.d.ts.map +1 -1
  3. package/lib/dts/components/menu/useMenuController.d.ts.map +1 -1
  4. package/lib/dts/components/tab/tab.d.ts +1 -1
  5. package/lib/dts/components/tab/tab.d.ts.map +1 -1
  6. package/lib/dts/components/tree/tree.d.ts +1 -1
  7. package/lib/dts/components/tree/tree.d.ts.map +1 -1
  8. package/lib/dts/components/tree/treeGroup.d.ts +1 -1
  9. package/lib/dts/components/tree/treeGroup.d.ts.map +1 -1
  10. package/lib/dts/components/tree/treeItem.d.ts +1 -1
  11. package/lib/dts/components/tree/treeItem.d.ts.map +1 -1
  12. package/lib/dts/hooks/usePrefersDark.d.ts.map +1 -1
  13. package/lib/dts/primitives/textInput/textInput.d.ts.map +1 -1
  14. package/lib/dts/styles/input/textInputStyle.d.ts.map +1 -1
  15. package/lib/dts/utils/errorBoundary.d.ts.map +1 -1
  16. package/lib/sanity-ui.js +60 -35
  17. package/lib/sanity-ui.js.map +1 -1
  18. package/lib/sanity-ui.modern.js +73 -36
  19. package/lib/sanity-ui.modern.js.map +1 -1
  20. package/lib/sanity-ui.module.js +61 -36
  21. package/lib/sanity-ui.module.js.map +1 -1
  22. package/package.json +9 -9
  23. package/src/components/autocomplete/__workshop__/custom.tsx +10 -4
  24. package/src/components/autocomplete/__workshop__/example.tsx +38 -15
  25. package/src/components/autocomplete/__workshop__/fullscreen.tsx +31 -30
  26. package/src/components/autocomplete/autocomplete.styles.tsx +1 -0
  27. package/src/components/autocomplete/autocomplete.tsx +24 -3
  28. package/src/components/menu/useMenuController.ts +4 -8
  29. package/src/components/tab/tab.tsx +1 -1
  30. package/src/components/tree/__workshop__/basic.perf.ts +32 -0
  31. package/src/components/tree/__workshop__/basic.tsx +92 -56
  32. package/src/components/tree/__workshop__/index.ts +6 -1
  33. package/src/components/tree/tree.tsx +168 -144
  34. package/src/components/tree/treeGroup.tsx +3 -3
  35. package/src/components/tree/treeItem.tsx +4 -4
  36. package/src/hooks/usePrefersDark.ts +5 -1
  37. package/src/primitives/textInput/__workshop__/plain.tsx +49 -18
  38. package/src/primitives/textInput/textInput.tsx +23 -3
  39. package/src/styles/input/textInputStyle.ts +2 -0
  40. package/src/theme/{themeContext.ts → ThemeContext.ts} +0 -0
  41. package/src/utils/errorBoundary.tsx +3 -1
@@ -1,5 +1,5 @@
1
1
  import { useId } from '@reach/auto-id';
2
- import React, { useState, useRef, useEffect, createContext, useContext, useMemo, useLayoutEffect, forwardRef, useCallback, cloneElement, isValidElement, createElement, useReducer, Children, Fragment } from 'react';
2
+ import React, { useState, useRef, useEffect, createContext, useContext, useMemo, useLayoutEffect, forwardRef, useCallback, cloneElement, isValidElement, createElement, useReducer, Children, Fragment, memo } from 'react';
3
3
  import ReactIs, { isElement, isFragment, isValidElementType } from 'react-is';
4
4
  import styled, { ThemeProvider as ThemeProvider$1, useTheme as useTheme$1, css, keyframes } from 'styled-components';
5
5
  import { white as white$1, black as black$1, hues } from '@sanity/color';
@@ -2764,7 +2764,10 @@ function useMediaIndex() {
2764
2764
  */
2765
2765
 
2766
2766
  function usePrefersDark() {
2767
- const [dark, setDark] = useState(false);
2767
+ const [dark, setDark] = useState(() => {
2768
+ if (typeof window === 'undefined') return false;
2769
+ return window.matchMedia('(prefers-color-scheme: dark)').matches;
2770
+ });
2768
2771
  useEffect(() => {
2769
2772
  const mq = window.matchMedia('(prefers-color-scheme: dark)');
2770
2773
  setDark(mq.matches);
@@ -3576,6 +3579,8 @@ const ROOT_STYLE = css(_t$D || (_t$D = _$C`
3576
3579
  &:not([hidden]) {
3577
3580
  display: flex;
3578
3581
  }
3582
+
3583
+ align-items: center;
3579
3584
  `));
3580
3585
  function textInputRootStyle() {
3581
3586
  return ROOT_STYLE;
@@ -5779,7 +5784,8 @@ class ErrorBoundary extends React.Component {
5779
5784
  } = this.state;
5780
5785
 
5781
5786
  if (error) {
5782
- return /*#__PURE__*/React.createElement(Code, null, error.message);
5787
+ const message = typeof (error == null ? void 0 : error.message) === 'string' ? error.message : 'Error';
5788
+ return /*#__PURE__*/React.createElement(Code, null, message);
5783
5789
  }
5784
5790
 
5785
5791
  return this.props.children;
@@ -7557,8 +7563,18 @@ const TextInput = /*#__PURE__*/forwardRef(function TextInput(props, forwardedRef
7557
7563
  size: fontSize
7558
7564
  }, /*#__PURE__*/isValidElement(iconRight) && iconRight, isValidElementType(iconRight) && /*#__PURE__*/createElement(iconRight)))), [border, fontSize, icon, iconRight, padding, radius, $hasClearButton, $hasPrefix, $hasSuffix]); // Render clear button (memoized)
7559
7565
 
7560
- const clearButtonBoxPadding = useMemo(() => padding.map(v => v - 2), [padding]);
7561
- const clearButtonPadding = useMemo(() => padding.map(v => v - 1), [padding]);
7566
+ const clearButtonBoxPadding = useMemo(() => padding.map(v => {
7567
+ if (v === 0) return 0;
7568
+ if (v === 1) return 1;
7569
+ if (v === 2) return 1;
7570
+ return v - 2;
7571
+ }), [padding]);
7572
+ const clearButtonPadding = useMemo(() => padding.map(v => {
7573
+ if (v === 0) return 0;
7574
+ if (v === 1) return 0;
7575
+ if (v === 2) return 1;
7576
+ return v - 1;
7577
+ }), [padding]);
7562
7578
  const clearButtonProps = useMemo(() => typeof clearButton === 'object' ? clearButton : EMPTY_RECORD$1, [clearButton]);
7563
7579
  const clearButtonNode = useMemo(() => !disabled && !readOnly && clearButton && /*#__PURE__*/React.createElement(RightCard, {
7564
7580
  forwardedAs: "span",
@@ -7571,7 +7587,7 @@ const TextInput = /*#__PURE__*/forwardRef(function TextInput(props, forwardedRef
7571
7587
  icon: CloseIcon,
7572
7588
  mode: "bleed",
7573
7589
  padding: clearButtonPadding,
7574
- radius: radius.map(r => r - 1)
7590
+ radius: radius
7575
7591
  }, clearButtonProps, {
7576
7592
  onClick: handleClearClick,
7577
7593
  onMouseDown: handleClearMouseDown
@@ -7823,6 +7839,7 @@ let _$b = t => t,
7823
7839
 
7824
7840
  const Root$9 = styled.div(_t$b || (_t$b = _$b`
7825
7841
  /* position: relative; */
7842
+ line-height: 0;
7826
7843
  `));
7827
7844
  /**
7828
7845
  * @internal
@@ -7993,7 +8010,7 @@ const AUTOCOMPLETE_POPOVER_PLACEMENT = 'bottom-start';
7993
8010
 
7994
8011
  const AUTOCOMPLETE_POPOVER_FALLBACK_PLACEMENTS = ['top-start'];
7995
8012
 
7996
- const _excluded$f = ["border", "customValidity", "disabled", "filterOption", "fontSize", "icon", "id", "listBox", "loading", "onBlur", "onChange", "onFocus", "onQueryChange", "onSelect", "openButton", "options", "padding", "popover", "prefix", "radius", "readOnly", "relatedElements", "renderOption", "renderPopover", "renderValue", "value"];
8013
+ const _excluded$f = ["border", "customValidity", "disabled", "filterOption", "fontSize", "icon", "id", "listBox", "loading", "onBlur", "onChange", "onFocus", "onQueryChange", "onSelect", "openButton", "options", "padding", "popover", "prefix", "radius", "readOnly", "relatedElements", "renderOption", "renderPopover", "renderValue", "suffix", "value"];
7997
8014
 
7998
8015
  const defaultRenderValue = (value, option) => option ? option.value : value;
7999
8016
 
@@ -8026,6 +8043,7 @@ const InnerAutocomplete = /*#__PURE__*/forwardRef(function InnerAutocomplete(pro
8026
8043
  renderOption: renderOptionProp,
8027
8044
  renderPopover,
8028
8045
  renderValue = defaultRenderValue,
8046
+ suffix,
8029
8047
  value: valueProp
8030
8048
  } = props,
8031
8049
  restProps = _objectWithoutPropertiesLoose(props, _excluded$f);
@@ -8294,8 +8312,18 @@ const InnerAutocomplete = /*#__PURE__*/forwardRef(function InnerAutocomplete(pro
8294
8312
 
8295
8313
  return undefined;
8296
8314
  }, [disabled, handleClearButtonFocus, loading, value]);
8297
- const openButtonBoxPadding = useMemo(() => padding.map(v => v - 2), [padding]);
8298
- const openButtonPadding = useMemo(() => padding.map(v => v - 1), [padding]);
8315
+ const openButtonBoxPadding = useMemo(() => padding.map(v => {
8316
+ if (v === 0) return 0;
8317
+ if (v === 1) return 1;
8318
+ if (v === 2) return 1;
8319
+ return v - 2;
8320
+ }), [padding]);
8321
+ const openButtonPadding = useMemo(() => padding.map(v => {
8322
+ if (v === 0) return 0;
8323
+ if (v === 1) return 0;
8324
+ if (v === 2) return 1;
8325
+ return v - 1;
8326
+ }), [padding]);
8299
8327
  const openButtonProps = useMemo(() => typeof openButton === 'object' ? openButton : EMPTY_RECORD, [openButton]);
8300
8328
  const handleOpenClick = useCallback(event => {
8301
8329
  dispatch({
@@ -8361,7 +8389,7 @@ const InnerAutocomplete = /*#__PURE__*/forwardRef(function InnerAutocomplete(pro
8361
8389
  ref: setRef,
8362
8390
  role: "combobox",
8363
8391
  spellCheck: false,
8364
- suffix: openButtonNode,
8392
+ suffix: suffix || openButtonNode,
8365
8393
  value: inputValue
8366
8394
  }));
8367
8395
  const handleListBoxKeyDown = useCallback(event => {
@@ -8983,8 +9011,8 @@ function useMenuController(props) {
8983
9011
  const elementsRef = useRef([]);
8984
9012
  const [rootElement, setRootElement] = useState(null);
8985
9013
  const [activeIndex, _setActiveIndex] = useState(-1);
8986
- const activeElement = elementsRef.current[activeIndex] || null;
8987
9014
  const activeIndexRef = useRef(activeIndex);
9015
+ const activeElement = elementsRef.current[activeIndex] || null;
8988
9016
  const mounted = Boolean(rootElement);
8989
9017
  const setActiveIndex = useCallback(nextActiveIndex => {
8990
9018
  _setActiveIndex(nextActiveIndex);
@@ -9059,7 +9087,7 @@ function useMenuController(props) {
9059
9087
 
9060
9088
  const focusableLen = focusableElements.length;
9061
9089
  if (focusableLen === 0) return;
9062
- const focusedElement = elementsRef.current[activeIndex];
9090
+ const focusedElement = elementsRef.current[activeIndexRef.current];
9063
9091
  let focusedIndex = focusableElements.indexOf(focusedElement);
9064
9092
  focusedIndex = (focusedIndex - 1 + focusableLen) % focusableLen;
9065
9093
  const el = focusableElements[focusedIndex];
@@ -9076,7 +9104,7 @@ function useMenuController(props) {
9076
9104
 
9077
9105
  const focusableLen = focusableElements.length;
9078
9106
  if (focusableLen === 0) return;
9079
- const focusedElement = elementsRef.current[activeIndex];
9107
+ const focusedElement = elementsRef.current[activeIndexRef.current];
9080
9108
  let focusedIndex = focusableElements.indexOf(focusedElement);
9081
9109
  focusedIndex = (focusedIndex + 1) % focusableLen;
9082
9110
  const el = focusableElements[focusedIndex];
@@ -9088,7 +9116,7 @@ function useMenuController(props) {
9088
9116
  if (onKeyDown) {
9089
9117
  onKeyDown(event);
9090
9118
  }
9091
- }, [activeIndex, onKeyDown, originElement, setActiveIndex]);
9119
+ }, [onKeyDown, originElement, setActiveIndex]);
9092
9120
  const handleItemMouseEnter = useCallback(event => {
9093
9121
  const element = event.currentTarget;
9094
9122
  const currentIndex = elementsRef.current.indexOf(element);
@@ -10459,18 +10487,26 @@ const _excluded$2 = ["children", "space"];
10459
10487
  * @beta
10460
10488
  */
10461
10489
 
10462
- function Tree(props) {
10490
+ const Tree = /*#__PURE__*/memo( /*#__PURE__*/forwardRef(function Tree(props, ref) {
10463
10491
  const {
10464
10492
  children,
10465
10493
  space = 1
10466
10494
  } = props,
10467
10495
  restProps = _objectWithoutPropertiesLoose(props, _excluded$2);
10468
10496
 
10497
+ const forwardedRef = useForwardedRef(ref);
10469
10498
  const [focusedElement, setFocusedElement] = useState(null);
10499
+ const focusedElementRef = useRef(focusedElement);
10470
10500
  const path = useMemo(() => [], []);
10471
- const rootRef = useRef(null);
10472
10501
  const [itemElements, setItemElements] = useState([]);
10473
10502
  const [state, setState] = useState({});
10503
+ const stateRef = useRef(state);
10504
+ useEffect(() => {
10505
+ focusedElementRef.current = focusedElement;
10506
+ }, [focusedElement]);
10507
+ useEffect(() => {
10508
+ stateRef.current = state;
10509
+ }, [state]);
10474
10510
  const registerItem = useCallback((element, path, expanded, selected) => {
10475
10511
  setState(s => _extends({}, s, {
10476
10512
  [path]: {
@@ -10515,12 +10551,12 @@ function Tree(props) {
10515
10551
  state
10516
10552
  }), [focusedElement, itemElements, path, registerItem, setExpanded, space, state]);
10517
10553
  const handleKeyDown = useCallback(event => {
10518
- if (!focusedElement) return;
10554
+ if (!focusedElementRef.current) return;
10519
10555
 
10520
10556
  if (event.key === 'ArrowDown') {
10521
10557
  event.preventDefault();
10522
10558
 
10523
- const nextEl = _findNextItemElement(state, itemElements, focusedElement);
10559
+ const nextEl = _findNextItemElement(stateRef.current, itemElements, focusedElementRef.current);
10524
10560
 
10525
10561
  if (nextEl) {
10526
10562
  _focusItemElement(nextEl);
@@ -10534,7 +10570,7 @@ function Tree(props) {
10534
10570
  if (event.key === 'ArrowUp') {
10535
10571
  event.preventDefault();
10536
10572
 
10537
- const prevEl = _findPrevItemElement(state, itemElements, focusedElement);
10573
+ const prevEl = _findPrevItemElement(stateRef.current, itemElements, focusedElementRef.current);
10538
10574
 
10539
10575
  if (prevEl) {
10540
10576
  _focusItemElement(prevEl);
@@ -10547,9 +10583,9 @@ function Tree(props) {
10547
10583
 
10548
10584
  if (event.key === 'ArrowLeft') {
10549
10585
  event.preventDefault();
10550
- const itemKey = focusedElement.getAttribute('data-tree-key');
10586
+ const itemKey = focusedElementRef.current.getAttribute('data-tree-key');
10551
10587
  if (!itemKey) return;
10552
- const itemState = state[itemKey];
10588
+ const itemState = stateRef.current[itemKey];
10553
10589
  if (!itemState) return;
10554
10590
 
10555
10591
  if (itemState.expanded) {
@@ -10566,7 +10602,7 @@ function Tree(props) {
10566
10602
  const itemPath = itemKey.split('/');
10567
10603
  itemPath.pop();
10568
10604
  const parentKey = itemPath.join('/');
10569
- const parentState = parentKey && state[parentKey];
10605
+ const parentState = parentKey && stateRef.current[parentKey];
10570
10606
 
10571
10607
  if (parentState) {
10572
10608
  parentState.element.focus();
@@ -10578,13 +10614,13 @@ function Tree(props) {
10578
10614
  }
10579
10615
 
10580
10616
  if (event.key === 'ArrowRight') {
10581
- var _state$focusedKey;
10617
+ var _stateRef$current$foc;
10582
10618
 
10583
10619
  event.preventDefault();
10584
- const focusedKey = focusedElement.getAttribute('data-tree-key');
10620
+ const focusedKey = focusedElementRef.current.getAttribute('data-tree-key');
10585
10621
  if (!focusedKey) return;
10586
10622
 
10587
- if (!((_state$focusedKey = state[focusedKey]) != null && _state$focusedKey.expanded)) {
10623
+ if (!((_stateRef$current$foc = stateRef.current[focusedKey]) != null && _stateRef$current$foc.expanded)) {
10588
10624
  setState(s => {
10589
10625
  const itemState = s[focusedKey];
10590
10626
  if (!itemState) return s;
@@ -10598,14 +10634,14 @@ function Tree(props) {
10598
10634
 
10599
10635
  return;
10600
10636
  }
10601
- }, [focusedElement, itemElements, state]);
10637
+ }, [itemElements]);
10602
10638
  useEffect(() => {
10603
- if (!rootRef.current) return;
10639
+ if (!forwardedRef.current) return;
10604
10640
 
10605
- const _itemElements = Array.from(rootRef.current.querySelectorAll('[data-ui="TreeItem"]'));
10641
+ const _itemElements = Array.from(forwardedRef.current.querySelectorAll('[data-ui="TreeItem"]'));
10606
10642
 
10607
10643
  setItemElements(_itemElements);
10608
- }, [children]);
10644
+ }, [children, forwardedRef]);
10609
10645
  return /*#__PURE__*/React.createElement(TreeContext.Provider, {
10610
10646
  value: contextValue
10611
10647
  }, /*#__PURE__*/React.createElement(Stack, _extends({
@@ -10613,11 +10649,12 @@ function Tree(props) {
10613
10649
  "data-ui": "Tree"
10614
10650
  }, restProps, {
10615
10651
  onKeyDown: handleKeyDown,
10616
- ref: rootRef,
10652
+ ref: forwardedRef,
10617
10653
  role: "tree",
10618
10654
  space: space
10619
10655
  }), children));
10620
- }
10656
+ }));
10657
+ Tree.displayName = 'Tree';
10621
10658
 
10622
10659
  let _$1 = t => t,
10623
10660
  _t$1,
@@ -10743,7 +10780,7 @@ function useTree() {
10743
10780
  }
10744
10781
 
10745
10782
  const _excluded$1 = ["children", "expanded"];
10746
- function TreeGroup(props) {
10783
+ const TreeGroup = /*#__PURE__*/memo(function TreeGroup(props) {
10747
10784
  const {
10748
10785
  children,
10749
10786
  expanded = false
@@ -10760,13 +10797,13 @@ function TreeGroup(props) {
10760
10797
  role: "group",
10761
10798
  space: tree.space
10762
10799
  }), children);
10763
- }
10800
+ });
10764
10801
 
10765
10802
  const _excluded = ["children", "expanded", "fontSize", "href", "icon", "id", "muted", "onClick", "padding", "selected", "space", "text", "weight"];
10766
10803
 
10767
10804
  let _ = t => t,
10768
10805
  _t;
10769
- const Root = styled.li(treeItemRootStyle, treeItemRootColorStyle);
10806
+ const Root = /*#__PURE__*/memo(styled.li(treeItemRootStyle, treeItemRootColorStyle));
10770
10807
  const TreeItemBox = styled(Box).attrs({
10771
10808
  forwardedAs: 'a'
10772
10809
  })(treeItemBoxStyle);
@@ -10780,7 +10817,7 @@ const ToggleArrowText = styled(Text)(_t || (_t = _`
10780
10817
  * @beta
10781
10818
  */
10782
10819
 
10783
- function TreeItem(props) {
10820
+ const TreeItem = /*#__PURE__*/memo(function TreeItem(props) {
10784
10821
  const {
10785
10822
  children,
10786
10823
  expanded: expandedProp = false,
@@ -10913,7 +10950,7 @@ function TreeItem(props) {
10913
10950
  }, children && /*#__PURE__*/React.createElement(TreeGroup, {
10914
10951
  expanded: expanded
10915
10952
  }, children)));
10916
- }
10953
+ });
10917
10954
 
10918
10955
  export { Autocomplete, Avatar, AvatarCounter, AvatarStack, Badge, BoundaryElementProvider, Box, Breadcrumbs, Button, Card, Checkbox, Code, CodeSkeleton, Container, Dialog, DialogContext, DialogProvider, ElementQuery, ErrorBoundary, Flex, Grid, Heading, HeadingSkeleton, Hotkeys, Inline, KBD, Label, LabelSkeleton, Layer, LayerProvider, Menu, MenuButton, MenuDivider, MenuGroup, MenuItem, Popover, Portal, PortalProvider, Radio, RO as ResizeObserver, Select, Skeleton, Spinner, SrOnly, Stack, Switch, Tab, TabList, TabPanel, Text, TextArea, TextInput, TextSkeleton, ThemeColorProvider, ThemeProvider, Toast, ToastProvider, Tooltip, Tree, TreeItem, VirtualList, _hasFocus, _isEnterToClickElement, _isScrollable, _raf, _raf2, attemptFocus, createColorTheme, fillCSSObject, focusFirstDescendant, focusLastDescendant, getResponsiveProp, getResponsiveSpace, hexToRgb, hslToRgb, isFocusable, isHTMLAnchorElement, isHTMLButtonElement, isHTMLElement, isHTMLInputElement, isHTMLSelectElement, isHTMLTextAreaElement, multiply$1 as multiply, parseColor, rem, responsive, responsiveCodeFontStyle, responsiveHeadingFont, responsiveLabelFont, responsiveTextAlignStyle, responsiveTextFont, rgbToHex, rgbToHsl, rgba, screen$1 as screen, studioTheme, useBoundaryElement, useClickOutside, useCustomValidity, useDialog, useElementRect, useForwardedRef, useGlobalKeyDown, useLayer, useMediaIndex, usePortal, usePrefersDark, useResponsiveProp, useRootTheme, useTheme, useToast, useTree };
10919
10956
  //# sourceMappingURL=sanity-ui.modern.js.map