@sanity/ui 4.0.0-static.30 → 4.0.0-static.32

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 (47) hide show
  1. package/dist/index.d.ts +8 -1
  2. package/dist/index.js +1076 -510
  3. package/dist/index.js.map +1 -1
  4. package/package.json +10 -11
  5. package/src/core/components/autocomplete/Autocomplete.tsx +80 -48
  6. package/src/core/components/breadcrumbs/Breadcrumbs.tsx +74 -41
  7. package/src/core/components/dialog/DialogContext.ts +1 -1
  8. package/src/core/components/dialog/__workshop__/Panes.tsx +5 -21
  9. package/src/core/components/dialog/__workshop__/styles.css.ts +18 -0
  10. package/src/core/components/menu/Menu.test.tsx +2 -6
  11. package/src/core/components/menu/Menu.tsx +13 -14
  12. package/src/core/components/menu/MenuContext.ts +2 -3
  13. package/src/core/components/menu/MenuGroup.tsx +2 -0
  14. package/src/core/components/menu/useMenu.ts +2 -2
  15. package/src/core/components/menu/useMenuController.ts +5 -5
  16. package/src/core/components/toast/ToastContext.ts +1 -1
  17. package/src/core/components/tree/Tree.tsx +1 -0
  18. package/src/core/components/tree/TreeContext.ts +1 -1
  19. package/src/core/components/tree/TreeItem.tsx +17 -14
  20. package/src/core/components/virtualList/VirtualList.tsx +86 -44
  21. package/src/core/hooks/useGlobalKeyDown.ts +11 -4
  22. package/src/core/lib/createGlobalScopedContext.ts +2 -2
  23. package/src/core/primitives/avatar/Avatar.tsx +1 -0
  24. package/src/core/primitives/button/Button.tsx +2 -1
  25. package/src/core/primitives/button/__workshop__/SanityUploadButton.tsx +10 -25
  26. package/src/core/primitives/button/__workshop__/Styled1.tsx +2 -8
  27. package/src/core/primitives/button/__workshop__/index.ts +0 -5
  28. package/src/core/primitives/button/__workshop__/styles.css.ts +30 -0
  29. package/src/core/primitives/card/CardContext.ts +1 -1
  30. package/src/core/primitives/card/__workshop__/Styled.tsx +2 -5
  31. package/src/core/primitives/flex/__workshop__/Example.tsx +7 -15
  32. package/src/core/primitives/flex/__workshop__/styles.css.ts +12 -0
  33. package/src/core/primitives/inline/Inline.tsx +1 -0
  34. package/src/core/primitives/layer/LayerContext.ts +1 -1
  35. package/src/core/primitives/popover/Popover.tsx +146 -130
  36. package/src/core/primitives/popover/floating-ui/size.ts +17 -16
  37. package/src/core/primitives/skeleton/Skeleton.tsx +2 -2
  38. package/src/core/primitives/text/__workshop__/Colored.tsx +5 -10
  39. package/src/core/primitives/tooltip/Tooltip.tsx +69 -41
  40. package/src/core/primitives/tooltip/tooltipDelayGroup/TooltipDelayGroupContext.tsx +1 -1
  41. package/src/core/utils/boundaryElement/BoundaryElementContext.ts +1 -1
  42. package/src/core/utils/elementQuery/__workshop__/CustomMedia.tsx +3 -25
  43. package/src/core/utils/elementQuery/__workshop__/styles.css.ts +31 -0
  44. package/src/core/utils/portal/Portal.test.tsx +6 -6
  45. package/src/core/utils/portal/PortalContext.ts +1 -1
  46. package/src/core/utils/portal/PortalProvider.tsx +5 -37
  47. package/src/core/primitives/button/__workshop__/Styled2.tsx +0 -19
@@ -27,9 +27,9 @@ describe('utils/portal', () => {
27
27
  }
28
28
 
29
29
  return (
30
- <PortalContext.Provider value={value}>
30
+ <PortalContext value={value}>
31
31
  <Debug />
32
- </PortalContext.Provider>
32
+ </PortalContext>
33
33
  )
34
34
  }
35
35
 
@@ -55,12 +55,12 @@ describe('utils/portal', () => {
55
55
 
56
56
  function Root() {
57
57
  return (
58
- <PortalContext.Provider
58
+ <PortalContext
59
59
  // @ts-expect-error - we want to test the error case
60
60
  value={undefined}
61
61
  >
62
62
  <Debug />
63
- </PortalContext.Provider>
63
+ </PortalContext>
64
64
  )
65
65
  }
66
66
 
@@ -86,12 +86,12 @@ describe('utils/portal', () => {
86
86
  // NOTE: we’re testing this because the context value may be a function in the future
87
87
 
88
88
  return (
89
- <PortalContext.Provider
89
+ <PortalContext
90
90
  // @ts-expect-error - we want to test the error case
91
91
  value={() => ({version: 1})}
92
92
  >
93
93
  <Debug />
94
- </PortalContext.Provider>
94
+ </PortalContext>
95
95
  )
96
96
  }
97
97
 
@@ -4,7 +4,7 @@ import {createGlobalScopedContext} from '../../lib/createGlobalScopedContext'
4
4
  import {globalScope} from '../../lib/globalScope'
5
5
  import type {PortalContextValue} from './types'
6
6
 
7
- const key = '@sanity/ui/v3/portal'
7
+ const key = '@sanity/ui/v4/portal'
8
8
  const elementKey = Symbol.for(`${key}/element`)
9
9
 
10
10
  // Use the global scope as a map of symbols to elements
@@ -1,4 +1,4 @@
1
- import {type ReactNode, use, useMemo, useRef, useSyncExternalStore} from 'react'
1
+ import {type ReactNode, use, useMemo, useSyncExternalStore} from 'react'
2
2
 
3
3
  import {PortalContext} from './PortalContext'
4
4
  import type {PortalContextValue} from './types'
@@ -15,8 +15,7 @@ export interface PortalProviderProps {
15
15
 
16
16
  /** @public */
17
17
  export function PortalProvider(props: PortalProviderProps): React.JSX.Element {
18
- const {children, element, __unstable_elements: elementsProp} = props
19
- const elements = useUnique(elementsProp)
18
+ const {children, element, __unstable_elements: elements} = props
20
19
  const parentPortal = use(PortalContext)
21
20
  const fallbackElement = useSyncExternalStore(
22
21
  emptySubscribe,
@@ -24,47 +23,16 @@ export function PortalProvider(props: PortalProviderProps): React.JSX.Element {
24
23
  () => null,
25
24
  )
26
25
 
27
- const value: PortalContextValue = useMemo(() => {
26
+ const value = useMemo(() => {
28
27
  return {
29
28
  version: 0.0,
30
29
  boundaryElement: null,
31
30
  element: element || fallbackElement,
32
31
  elements,
33
- }
32
+ } satisfies PortalContextValue
34
33
  }, [element, elements, fallbackElement])
35
34
 
36
- return <PortalContext.Provider value={value}>{children}</PortalContext.Provider>
35
+ return <PortalContext value={value}>{children}</PortalContext>
37
36
  }
38
37
 
39
38
  const emptySubscribe = () => () => {}
40
-
41
- /**
42
- * This is a React hook to make sure that a record identity is the same on every render. Uses strict
43
- * equality comparison (eg by identity), and only goes one level deep.
44
- */
45
- function useUnique<ValueType extends Comparable = Comparable>(value: ValueType): ValueType {
46
- const valueRef = useRef<ValueType>(value)
47
-
48
- if (!_isEqual(valueRef.current, value)) {
49
- valueRef.current = value
50
- }
51
-
52
- return valueRef.current
53
- }
54
-
55
- function _isEqual(objA: Comparable, objB: Comparable): boolean {
56
- if (!objA || !objB) {
57
- return objA === objB
58
- }
59
-
60
- const keysA = Object.keys(objA)
61
- const keysB = Object.keys(objB)
62
-
63
- if (keysA.length !== keysB.length) {
64
- return false
65
- }
66
-
67
- return keysA.every((key) => objA[key] === objB[key])
68
- }
69
-
70
- type Comparable = Record<string | number | symbol, unknown> | undefined | null
@@ -1,19 +0,0 @@
1
- import {Button, Flex} from '@sanity/ui'
2
- import {styled} from 'styled-components'
3
-
4
- const StyledButton2 = styled(Button)<{$color?: boolean}>`
5
- &:hover {
6
- background-color: red;
7
- box-shadow: none;
8
- }
9
- `
10
-
11
- export default function StyledButton2Story(): React.JSX.Element {
12
- const props = {href: '#', text: 'Test'}
13
-
14
- return (
15
- <Flex align="center" height="fill" justify="center">
16
- <StyledButton2 $color forwardedAs="a" {...props} />
17
- </Flex>
18
- )
19
- }