@sanity/ui 3.0.0-static.11 → 3.0.0-static.13
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/_chunks-cjs/_visual-editing.js +1293 -1215
- package/dist/_chunks-cjs/_visual-editing.js.map +1 -1
- package/dist/_chunks-cjs/buildCommand.js +28 -10
- package/dist/_chunks-cjs/buildCommand.js.map +1 -1
- package/dist/_chunks-es/_visual-editing.mjs +1284 -1202
- package/dist/_chunks-es/_visual-editing.mjs.map +1 -1
- package/dist/_visual-editing.d.mts +528 -358
- package/dist/_visual-editing.d.ts +528 -358
- package/dist/cli.js +1 -1
- package/dist/css.d.mts +143 -73
- package/dist/css.d.ts +143 -73
- package/dist/css.js +329 -472
- package/dist/css.js.map +1 -1
- package/dist/css.mjs +330 -473
- package/dist/css.mjs.map +1 -1
- package/dist/index.d.mts +1362 -869
- package/dist/index.d.ts +1362 -869
- package/dist/index.js +383 -308
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +387 -312
- package/dist/index.mjs.map +1 -1
- package/dist/sanity-palette.css +105 -1
- package/dist/sanity-palette.min.css +1 -0
- package/dist/sanity-theme.css +4571 -1
- package/dist/sanity-theme.min.css +1 -0
- package/dist/system.css +22053 -21946
- package/dist/system.min.css +1 -0
- package/dist/theme.d.mts +51 -106
- package/dist/theme.d.ts +51 -106
- package/dist/theme.js +9 -9
- package/dist/theme.js.map +1 -1
- package/dist/theme.mjs +9 -9
- package/dist/theme.mjs.map +1 -1
- package/package.json +10 -5
- package/src/cli/buildCommand.ts +46 -19
- package/src/css/_comp.ts +2 -2
- package/src/css/{compile/compileStyle.ts → _compileStyle.ts} +7 -7
- package/src/css/{system.style.ts → _system.style.ts} +3 -2
- package/src/css/aspects/display/display.ts +1 -0
- package/src/css/aspects/display/types.ts +2 -3
- package/src/css/aspects/flex/types.ts +4 -12
- package/src/css/aspects/flexItem/types.ts +1 -3
- package/src/css/aspects/font/types.ts +1 -3
- package/src/css/aspects/grid/grid.ts +1 -0
- package/src/css/aspects/grid/types.ts +5 -9
- package/src/css/aspects/gridItem/gridItem.ts +1 -1
- package/src/css/aspects/gridItem/types.ts +7 -18
- package/src/css/aspects/height/height.ts +3 -4
- package/src/css/aspects/inset/inset.ts +1 -0
- package/src/css/aspects/margin/margin.ts +1 -0
- package/src/css/aspects/margin/types.ts +1 -0
- package/src/css/aspects/maxWidth/maxWidth.ts +1 -0
- package/src/css/aspects/maxWidth/types.ts +1 -0
- package/src/css/aspects/minWidth/minWidth.ts +1 -0
- package/src/css/aspects/minWidth/types.ts +2 -0
- package/src/css/aspects/overflow/overflow.ts +1 -0
- package/src/css/aspects/padding/padding.ts +1 -0
- package/src/css/aspects/pointerEvents/pointerEvents.ts +1 -0
- package/src/css/aspects/position/position.ts +1 -0
- package/src/css/aspects/shadow/shadow.ts +1 -0
- package/src/css/aspects/textOverflow/textOverflow.ts +1 -0
- package/src/css/aspects/textOverflow/types.ts +1 -0
- package/src/css/aspects/width/types.ts +2 -0
- package/src/css/aspects/width/width.ts +1 -0
- package/src/css/{compile/compilePalette.ts → compilePalette.ts} +14 -10
- package/src/css/compileSystem.ts +7 -0
- package/src/css/{compile/compileTheme.ts → compileTheme.ts} +1 -0
- package/src/css/{compile/compileTheme_v3.ts → compileTheme_v3.ts} +123 -104
- package/src/css/components/breadcrumbs/breadcrumbs.ts +1 -0
- package/src/css/components/dialog/dialog.ts +7 -0
- package/src/css/components/menu/menu.ts +2 -0
- package/src/css/components/skeleton/skeleton.ts +4 -0
- package/src/css/components/skeleton/types.ts +4 -0
- package/src/css/components/toast/toast.ts +5 -0
- package/src/css/components/tree/tree.ts +1 -0
- package/src/css/composeClassNames.ts +4 -2
- package/src/css/constants.ts +2 -0
- package/src/css/index.ts +3 -3
- package/src/css/primitives/_arrow/_arrow.ts +3 -0
- package/src/css/primitives/_input/input.ts +2 -0
- package/src/css/primitives/_selectable/_selectable.style.ts +1 -2
- package/src/css/primitives/_selectable/selectable.ts +1 -2
- package/src/css/primitives/avatar/avatar.style.ts +5 -8
- package/src/css/primitives/avatar/avatar.ts +6 -0
- package/src/css/primitives/avatar/types.ts +1 -0
- package/src/css/primitives/box/types.ts +1 -3
- package/src/css/primitives/button/button.ts +4 -21
- package/src/css/primitives/button/index.ts +1 -0
- package/src/css/primitives/button/types.ts +18 -0
- package/src/css/primitives/card/card.style.ts +3 -6
- package/src/css/primitives/card/card.ts +2 -2
- package/src/css/primitives/card/types.ts +2 -2
- package/src/css/primitives/checkbox/checkbox.ts +2 -0
- package/src/css/primitives/container/container.ts +1 -0
- package/src/css/primitives/container/types.ts +1 -0
- package/src/css/primitives/kbd/kbd.ts +1 -0
- package/src/css/primitives/label/types.ts +7 -2
- package/src/css/primitives/popover/popover.ts +2 -0
- package/src/css/primitives/radio/radio.ts +1 -0
- package/src/css/primitives/select/select.ts +2 -0
- package/src/css/primitives/spinner/spinner.ts +2 -0
- package/src/css/primitives/switch/switch.ts +5 -0
- package/src/css/primitives/text/types.ts +4 -0
- package/src/css/primitives/textArea/textArea.ts +1 -0
- package/src/css/primitives/textInput/textInput.ts +1 -0
- package/src/css/primitives/tooltip/tooltip.ts +2 -0
- package/src/css/scopeClassName.ts +1 -0
- package/src/css/types.ts +9 -12
- package/src/css/util.ts +5 -0
- package/src/css/utils/srOnly/srOnly.ts +3 -1
- package/src/css/varNames.ts +131 -141
- package/src/css/vars.ts +1 -6
- package/src/theme/palette/constants.ts +2 -0
- package/src/theme/palette/types.ts +3 -0
- package/src/theme/types.ts +2 -6
- package/src/theme/v0/focusRing.ts +1 -3
- package/src/theme/v0/font.ts +6 -18
- package/src/theme/v0/layer.ts +1 -3
- package/src/theme/v0/shadow.ts +2 -6
- package/src/theme/v2/avatar.ts +1 -3
- package/src/theme/v2/color/_system.ts +1 -3
- package/src/theme/v2/color/avatar.ts +2 -6
- package/src/theme/v2/color/badge.ts +2 -6
- package/src/theme/v2/color/button.ts +3 -9
- package/src/theme/v2/color/color.ts +3 -9
- package/src/theme/v2/color/input.ts +3 -9
- package/src/theme/v2/color/kbd.ts +1 -3
- package/src/theme/v2/color/selectable.ts +2 -6
- package/src/theme/v2/color/state.ts +1 -3
- package/src/theme/v2/color/syntax.ts +1 -3
- package/src/theme/v2/input.ts +1 -3
- package/src/theme/v2/theme.ts +2 -6
- package/src/theme/v3/buildTheme_v3.ts +1 -0
- package/src/theme/v3/color/color.ts +6 -4
- package/src/theme/v3/color/renderColor.ts +4 -1
- package/src/theme/v3/defaultTokens.ts +1 -0
- package/src/theme/v3/resolveTokens.ts +9 -9
- package/src/ui/RootClassNames.tsx +3 -0
- package/src/ui/StyleTags.tsx +3 -1
- package/src/ui/_compat/theme/themeColorProvider.tsx +2 -6
- package/src/ui/_compat/theme/themeProvider.tsx +2 -6
- package/src/ui/_compat/theme/types.ts +1 -3
- package/src/ui/_compat/theme/useRootTheme.ts +1 -3
- package/src/ui/_compat/theme/useTheme.ts +2 -6
- package/src/ui/components/autocomplete/__workshop__/constrainedHeight.tsx +2 -2
- package/src/ui/components/autocomplete/autocomplete.tsx +86 -114
- package/src/ui/components/autocomplete/autocompleteOption.tsx +2 -0
- package/src/ui/components/autocomplete/types.ts +3 -8
- package/src/ui/components/breadcrumbs/breadcrumbs.tsx +27 -21
- package/src/ui/components/dialog/dialog.tsx +89 -291
- package/src/ui/components/dialog/dialogCard.tsx +183 -0
- package/src/ui/components/dialog/isTargetWithinScope.ts +14 -0
- package/src/ui/components/hotkeys/hotkeys.tsx +33 -15
- package/src/ui/components/menu/__workshop__/asComponent.tsx +6 -6
- package/src/ui/components/menu/menu.tsx +27 -33
- package/src/ui/components/menu/menuButton.tsx +10 -14
- package/src/ui/components/menu/menuDivider.tsx +25 -13
- package/src/ui/components/menu/menuGroup.tsx +34 -26
- package/src/ui/components/menu/menuItem.tsx +51 -40
- package/src/ui/components/skeleton/codeSkeleton.tsx +53 -0
- package/src/ui/components/skeleton/headingSkeleton.tsx +52 -0
- package/src/ui/components/skeleton/index.ts +3 -0
- package/src/ui/components/skeleton/labelSkeleton.tsx +51 -0
- package/src/ui/components/skeleton/skeleton.tsx +39 -16
- package/src/ui/components/skeleton/textSkeleton.tsx +31 -110
- package/src/ui/components/tab/tab.tsx +23 -19
- package/src/ui/components/tab/tabList.tsx +34 -33
- package/src/ui/components/tab/tabPanel.tsx +25 -19
- package/src/ui/components/toast/toast.tsx +21 -16
- package/src/ui/components/toast/toastLayer.tsx +28 -10
- package/src/ui/components/toast/toastProvider.tsx +2 -6
- package/src/ui/components/toast/types.ts +2 -6
- package/src/ui/components/toast/useToast.ts +1 -3
- package/src/ui/components/tree/tree.tsx +194 -187
- package/src/ui/components/tree/treeGroup.tsx +25 -5
- package/src/ui/components/tree/treeItem.tsx +35 -23
- package/src/ui/hooks/useClickOutside.ts +2 -6
- package/src/ui/hooks/useClickOutsideEvent.ts +3 -9
- package/src/ui/primitives/_selectable/selectable.tsx +33 -20
- package/src/ui/primitives/avatar/avatar.tsx +28 -31
- package/src/ui/primitives/avatar/avatarCounter.tsx +33 -25
- package/src/ui/primitives/avatar/avatarStack.tsx +31 -24
- package/src/ui/primitives/avatar/types.ts +2 -0
- package/src/ui/primitives/badge/__workshop__/props.tsx +1 -9
- package/src/ui/primitives/badge/__workshop__/tones.tsx +1 -6
- package/src/ui/primitives/badge/badge.tsx +33 -32
- package/src/ui/primitives/badge/types.ts +2 -1
- package/src/ui/primitives/box/box.tsx +59 -29
- package/src/ui/primitives/button/__workshop__/sanityUploadButton.tsx +3 -3
- package/src/ui/primitives/button/__workshop__/uploadButton.tsx +2 -1
- package/src/ui/primitives/button/button.test.tsx +1 -15
- package/src/ui/primitives/button/button.tsx +64 -70
- package/src/ui/primitives/card/__workshop__/asComponent.tsx +3 -3
- package/src/ui/primitives/card/card.tsx +22 -22
- package/src/ui/primitives/card/cardProvider.tsx +2 -0
- package/src/ui/primitives/checkbox/checkbox.tsx +26 -15
- package/src/ui/primitives/code/code.tsx +24 -22
- package/src/ui/primitives/container/container.tsx +26 -15
- package/src/ui/primitives/flex/flex.tsx +21 -19
- package/src/ui/primitives/grid/grid.tsx +21 -16
- package/src/ui/primitives/heading/heading.tsx +42 -19
- package/src/ui/primitives/inline/inline.tsx +26 -23
- package/src/ui/primitives/kbd/kbd.tsx +25 -23
- package/src/ui/primitives/label/label.tsx +41 -26
- package/src/ui/primitives/popover/popover.tsx +281 -277
- package/src/ui/primitives/popover/popoverCard.tsx +119 -118
- package/src/ui/primitives/radio/radio.tsx +30 -14
- package/src/ui/primitives/select/select.tsx +24 -16
- package/src/ui/primitives/spinner/animatedSpinnerIcon.tsx +4 -2
- package/src/ui/primitives/spinner/spinner.tsx +24 -12
- package/src/ui/primitives/stack/stack.tsx +27 -18
- package/src/ui/primitives/switch/switch.tsx +31 -14
- package/src/ui/primitives/text/text.tsx +42 -24
- package/src/ui/primitives/textArea/textArea.tsx +33 -18
- package/src/ui/primitives/textInput/textInput.tsx +28 -40
- package/src/ui/primitives/tooltip/constants.ts +1 -1
- package/src/ui/primitives/tooltip/tooltip.tsx +76 -59
- package/src/ui/primitives/tooltip/tooltipCard.tsx +89 -82
- package/src/ui/primitives/types.ts +1 -3
- package/src/ui/types/avatar.ts +3 -6
- package/src/ui/types/badge.ts +1 -3
- package/src/ui/types/button.ts +1 -3
- package/src/ui/types/card.ts +1 -3
- package/src/ui/types/dialog.ts +1 -3
- package/src/ui/types/props.ts +20 -10
- package/src/ui/utils/arrow/arrow.tsx +40 -14
- package/src/ui/utils/boundaryElement/boundaryElementProvider.tsx +2 -6
- package/src/ui/utils/boundaryElement/types.ts +1 -3
- package/src/ui/utils/boundaryElement/useBoundaryElement.ts +1 -3
- package/src/ui/utils/elementQuery/elementQuery.tsx +36 -14
- package/src/ui/utils/errorBoundary.tsx +2 -0
- package/src/ui/utils/index.ts +0 -1
- package/src/ui/utils/layer/layer.tsx +23 -93
- package/src/ui/utils/layer/layerCard.tsx +92 -0
- package/src/ui/utils/layer/layerProvider.tsx +2 -6
- package/src/ui/utils/layer/useLayer.ts +1 -3
- package/src/ui/utils/portal/portal.ts +2 -6
- package/src/ui/utils/portal/portalProvider.tsx +2 -6
- package/src/ui/utils/portal/types.ts +1 -3
- package/src/ui/utils/portal/usePortal.ts +1 -3
- package/src/ui/utils/srOnly/srOnly.tsx +25 -20
- package/src/ui/utils/virtualList/virtualList.tsx +36 -24
- package/src/css/compile/compileRule.ts +0 -97
- package/src/css/compile/compileRules.test.ts +0 -36
- package/src/css/compile/compileRules.ts +0 -43
- package/src/css/compile/compileSystem.ts +0 -7
- package/src/css/compile/types.ts +0 -6
- package/src/css/primitives/_selectable/_contants.ts +0 -11
- package/src/css/primitives/card/_constants.ts +0 -13
- package/src/ui/utils/conditionalWrapper/conditionalWrapper.tsx +0 -23
- package/src/ui/utils/conditionalWrapper/index.ts +0 -1
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import {type FocusEvent, useCallback, useEffect, useImperativeHandle, useRef} from 'react'
|
|
2
|
+
|
|
3
|
+
import {EMPTY_RECORD} from '../../constants'
|
|
4
|
+
import {containsOrEqualsElement, isHTMLElement} from '../../helpers'
|
|
5
|
+
import {Card, CardElementType} from '../../primitives'
|
|
6
|
+
import {Props} from '../../types'
|
|
7
|
+
import {LayerElementType, LayerOwnProps} from './layer'
|
|
8
|
+
import {useLayer} from './useLayer'
|
|
9
|
+
|
|
10
|
+
/** @internal */
|
|
11
|
+
export const DEFAULT_LAYER_CARD_ELEMENT = 'div'
|
|
12
|
+
|
|
13
|
+
/** @internal */
|
|
14
|
+
export type LayerCardOwnProps = Omit<LayerOwnProps, 'zOffset'>
|
|
15
|
+
|
|
16
|
+
/** @internal */
|
|
17
|
+
export type LayerCardElementType = LayerElementType
|
|
18
|
+
|
|
19
|
+
/** @internal */
|
|
20
|
+
export type LayerCardProps<E extends LayerCardElementType = LayerCardElementType> = Props<
|
|
21
|
+
LayerCardOwnProps,
|
|
22
|
+
E
|
|
23
|
+
>
|
|
24
|
+
|
|
25
|
+
/** @internal */
|
|
26
|
+
export function LayerCard<E extends LayerCardElementType = typeof DEFAULT_LAYER_CARD_ELEMENT>(
|
|
27
|
+
props: LayerCardProps<E>,
|
|
28
|
+
) {
|
|
29
|
+
const {
|
|
30
|
+
as = DEFAULT_LAYER_CARD_ELEMENT,
|
|
31
|
+
children,
|
|
32
|
+
onActivate,
|
|
33
|
+
onFocus,
|
|
34
|
+
position = 'relative',
|
|
35
|
+
ref: forwardedRef,
|
|
36
|
+
style = EMPTY_RECORD,
|
|
37
|
+
...rest
|
|
38
|
+
} = props as LayerCardProps<typeof DEFAULT_LAYER_CARD_ELEMENT>
|
|
39
|
+
|
|
40
|
+
const {zIndex, isTopLayer} = useLayer()
|
|
41
|
+
const lastFocusedRef = useRef<HTMLElement | null>(null)
|
|
42
|
+
const ref = useRef<HTMLDivElement | null>(null)
|
|
43
|
+
const isTopLayerRef = useRef<boolean>(isTopLayer)
|
|
44
|
+
|
|
45
|
+
useImperativeHandle<HTMLDivElement | null, HTMLDivElement | null>(forwardedRef, () => ref.current)
|
|
46
|
+
|
|
47
|
+
// When the layer very first mounts, it will be the top layer, but we don't want to fire
|
|
48
|
+
// the callback in that case. We use a ref to track the previous value of isTopLayer to
|
|
49
|
+
// determine if the layer has become the top layer since the last render.
|
|
50
|
+
useEffect(() => {
|
|
51
|
+
const becameTopLayer = isTopLayerRef.current !== isTopLayer && isTopLayer
|
|
52
|
+
|
|
53
|
+
if (becameTopLayer) {
|
|
54
|
+
onActivate?.({activeElement: lastFocusedRef.current})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
isTopLayerRef.current = isTopLayer
|
|
58
|
+
}, [isTopLayer, onActivate])
|
|
59
|
+
|
|
60
|
+
const handleFocus = useCallback(
|
|
61
|
+
(event: FocusEvent<HTMLDivElement, Element>) => {
|
|
62
|
+
// Call the user-provided onFocus handler if any
|
|
63
|
+
onFocus?.(event)
|
|
64
|
+
|
|
65
|
+
const rootElement = ref.current
|
|
66
|
+
const target = document.activeElement
|
|
67
|
+
|
|
68
|
+
if (!isTopLayer || !rootElement || !target) return
|
|
69
|
+
|
|
70
|
+
if (isHTMLElement(target) && containsOrEqualsElement(rootElement, target)) {
|
|
71
|
+
lastFocusedRef.current = target
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
[isTopLayer, onFocus],
|
|
75
|
+
)
|
|
76
|
+
|
|
77
|
+
return (
|
|
78
|
+
<Card
|
|
79
|
+
data-ui="Layer"
|
|
80
|
+
{...rest}
|
|
81
|
+
as={as as CardElementType}
|
|
82
|
+
onFocus={handleFocus}
|
|
83
|
+
position={position}
|
|
84
|
+
ref={ref}
|
|
85
|
+
style={{...style, zIndex}}
|
|
86
|
+
>
|
|
87
|
+
{children}
|
|
88
|
+
</Card>
|
|
89
|
+
)
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
LayerCard.displayName = 'LayerCard'
|
|
@@ -5,17 +5,13 @@ import {getLayerContext} from './getLayerContext'
|
|
|
5
5
|
import {LayerContext} from './layerContext'
|
|
6
6
|
import {LayerContextValue} from './types'
|
|
7
7
|
|
|
8
|
-
/**
|
|
9
|
-
* @public
|
|
10
|
-
*/
|
|
8
|
+
/** @public */
|
|
11
9
|
export interface LayerProviderProps {
|
|
12
10
|
children?: ReactNode
|
|
13
11
|
zOffset?: number | number[]
|
|
14
12
|
}
|
|
15
13
|
|
|
16
|
-
/**
|
|
17
|
-
* @public
|
|
18
|
-
*/
|
|
14
|
+
/** @public */
|
|
19
15
|
export function LayerProvider(props: LayerProviderProps): ReactElement {
|
|
20
16
|
const {children, zOffset: zOffsetProp = 0} = props
|
|
21
17
|
|
|
@@ -4,9 +4,7 @@ import {getLayerContext} from './getLayerContext'
|
|
|
4
4
|
import {LayerContext} from './layerContext'
|
|
5
5
|
import {LayerContextValue} from './types'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
7
|
+
/** @public */
|
|
10
8
|
export function useLayer(): LayerContextValue {
|
|
11
9
|
const value = useContext(LayerContext)
|
|
12
10
|
|
|
@@ -4,9 +4,7 @@ import {createPortal} from 'react-dom'
|
|
|
4
4
|
import {CardProvider, useCard} from '../../primitives'
|
|
5
5
|
import {usePortal} from './usePortal'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
7
|
+
/** @public */
|
|
10
8
|
export interface PortalProps {
|
|
11
9
|
children: ReactNode
|
|
12
10
|
/**
|
|
@@ -15,9 +13,7 @@ export interface PortalProps {
|
|
|
15
13
|
__unstable_name?: string
|
|
16
14
|
}
|
|
17
15
|
|
|
18
|
-
/**
|
|
19
|
-
* @public
|
|
20
|
-
*/
|
|
16
|
+
/** @public */
|
|
21
17
|
export function Portal(props: PortalProps): ReactPortal | null {
|
|
22
18
|
const {children, __unstable_name: name} = props
|
|
23
19
|
const card = useCard()
|
|
@@ -3,9 +3,7 @@ import {ReactElement, ReactNode, useMemo, useRef, useSyncExternalStore} from 're
|
|
|
3
3
|
import {PortalContext} from './portalContext'
|
|
4
4
|
import {PortalContextValue} from './types'
|
|
5
5
|
|
|
6
|
-
/**
|
|
7
|
-
* @public
|
|
8
|
-
*/
|
|
6
|
+
/** @public */
|
|
9
7
|
export interface PortalProviderProps {
|
|
10
8
|
/**
|
|
11
9
|
* @deprecated Use `<BoundaryElementProvider element={...} />` instead
|
|
@@ -19,9 +17,7 @@ export interface PortalProviderProps {
|
|
|
19
17
|
__unstable_elements?: Record<string, HTMLElement | null | undefined>
|
|
20
18
|
}
|
|
21
19
|
|
|
22
|
-
/**
|
|
23
|
-
* @public
|
|
24
|
-
*/
|
|
20
|
+
/** @public */
|
|
25
21
|
export function PortalProvider(props: PortalProviderProps): ReactElement {
|
|
26
22
|
const {boundaryElement, children, element, __unstable_elements: elementsProp} = props
|
|
27
23
|
const elements = useUnique(elementsProp)
|
|
@@ -4,9 +4,7 @@ import {isRecord} from '../../lib/isRecord'
|
|
|
4
4
|
import {PortalContext} from './portalContext'
|
|
5
5
|
import {PortalContextValue} from './types'
|
|
6
6
|
|
|
7
|
-
/**
|
|
8
|
-
* @public
|
|
9
|
-
*/
|
|
7
|
+
/** @public */
|
|
10
8
|
export function usePortal(): PortalContextValue {
|
|
11
9
|
const value = useContext(PortalContext)
|
|
12
10
|
|
|
@@ -1,35 +1,40 @@
|
|
|
1
1
|
import {composeClassNames, srOnly} from '@sanity/ui/css'
|
|
2
|
-
import {ForwardedRef, forwardRef, ReactNode} from 'react'
|
|
3
2
|
|
|
4
|
-
import {Props} from '../../types'
|
|
3
|
+
import {ComponentType, Props} from '../../types'
|
|
5
4
|
|
|
6
|
-
/**
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
5
|
+
/** @public */
|
|
6
|
+
export const DEFAULT_SR_ONLY_ELEMENT = 'span'
|
|
7
|
+
|
|
8
|
+
/** @public */
|
|
9
|
+
export type SrOnlyOwnProps = {} // eslint-disable-line @typescript-eslint/no-empty-object-type
|
|
10
|
+
|
|
11
|
+
/** @public */
|
|
12
|
+
export type SrOnlyElementType = 'span' | ComponentType
|
|
12
13
|
|
|
13
|
-
/**
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
14
|
+
/** @public */
|
|
15
|
+
export type SrOnlyProps<E extends SrOnlyElementType = SrOnlyElementType> = Props<SrOnlyOwnProps, E>
|
|
16
|
+
|
|
17
|
+
/** @public */
|
|
18
|
+
export function SrOnly<E extends SrOnlyElementType = typeof DEFAULT_SR_ONLY_ELEMENT>(
|
|
19
|
+
props: SrOnlyProps<E>,
|
|
19
20
|
) {
|
|
20
|
-
const {
|
|
21
|
+
const {
|
|
22
|
+
as: Element = DEFAULT_SR_ONLY_ELEMENT,
|
|
23
|
+
children,
|
|
24
|
+
className,
|
|
25
|
+
...rest
|
|
26
|
+
} = props as SrOnlyProps<typeof DEFAULT_SR_ONLY_ELEMENT>
|
|
21
27
|
|
|
22
28
|
return (
|
|
23
|
-
<
|
|
29
|
+
<Element
|
|
24
30
|
data-ui="SrOnly"
|
|
25
31
|
{...rest}
|
|
26
32
|
aria-hidden
|
|
27
33
|
className={composeClassNames(className, srOnly())}
|
|
28
|
-
ref={ref}
|
|
29
34
|
>
|
|
30
35
|
{children}
|
|
31
|
-
</
|
|
36
|
+
</Element>
|
|
32
37
|
)
|
|
33
|
-
}
|
|
38
|
+
}
|
|
34
39
|
|
|
35
|
-
SrOnly.displayName = '
|
|
40
|
+
SrOnly.displayName = 'SrOnly'
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
import {vars} from '@sanity/ui/css'
|
|
2
2
|
import {Space} from '@sanity/ui/theme'
|
|
3
3
|
import {
|
|
4
|
-
CSSProperties,
|
|
5
|
-
ForwardedRef,
|
|
6
|
-
forwardRef,
|
|
7
|
-
ReactElement,
|
|
4
|
+
type CSSProperties,
|
|
8
5
|
ReactNode,
|
|
9
6
|
useEffect,
|
|
10
7
|
useImperativeHandle,
|
|
@@ -15,12 +12,13 @@ import {
|
|
|
15
12
|
|
|
16
13
|
import {_isScrollable} from '../../helpers'
|
|
17
14
|
import {_ResizeObserver} from '../../observers'
|
|
18
|
-
import {Box
|
|
19
|
-
import {Props} from '../../types'
|
|
15
|
+
import {Box} from '../../primitives'
|
|
16
|
+
import {ComponentType, Props} from '../../types'
|
|
20
17
|
|
|
21
|
-
/**
|
|
22
|
-
|
|
23
|
-
|
|
18
|
+
/** @beta */
|
|
19
|
+
export const DEFAULT_VIRTUAL_LIST_ELEMENT = 'div'
|
|
20
|
+
|
|
21
|
+
/** @beta */
|
|
24
22
|
export interface VirtualListChangeOpts {
|
|
25
23
|
fromIndex: number
|
|
26
24
|
gap: number
|
|
@@ -30,10 +28,8 @@ export interface VirtualListChangeOpts {
|
|
|
30
28
|
toIndex: number
|
|
31
29
|
}
|
|
32
30
|
|
|
33
|
-
/**
|
|
34
|
-
|
|
35
|
-
*/
|
|
36
|
-
export interface VirtualListProps<Item = any> extends Omit<StackProps, 'gap'> {
|
|
31
|
+
/** @beta */
|
|
32
|
+
export type VirtualListOwnProps<Item = any> = {
|
|
37
33
|
gap?: Space
|
|
38
34
|
getItemKey?: (item: Item, itemIndex: number) => string
|
|
39
35
|
items?: Item[]
|
|
@@ -41,14 +37,30 @@ export interface VirtualListProps<Item = any> extends Omit<StackProps, 'gap'> {
|
|
|
41
37
|
renderItem?: (item: Item) => ReactNode
|
|
42
38
|
}
|
|
43
39
|
|
|
44
|
-
/**
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
40
|
+
/** @beta */
|
|
41
|
+
export type VirtualListElementType = 'div' | ComponentType
|
|
42
|
+
|
|
43
|
+
/** @beta */
|
|
44
|
+
export type VirtualListProps<E extends VirtualListElementType = VirtualListElementType> = Props<
|
|
45
|
+
VirtualListOwnProps,
|
|
46
|
+
E
|
|
47
|
+
>
|
|
48
|
+
|
|
49
|
+
/** @beta */
|
|
50
|
+
export function VirtualList<E extends VirtualListElementType = typeof DEFAULT_VIRTUAL_LIST_ELEMENT>(
|
|
51
|
+
props: VirtualListProps<E>,
|
|
52
|
+
) {
|
|
53
|
+
const {
|
|
54
|
+
as = DEFAULT_VIRTUAL_LIST_ELEMENT,
|
|
55
|
+
gap = 0,
|
|
56
|
+
getItemKey,
|
|
57
|
+
items = [],
|
|
58
|
+
onChange,
|
|
59
|
+
renderItem,
|
|
60
|
+
ref: forwardedRef,
|
|
61
|
+
...rest
|
|
62
|
+
} = props as VirtualListProps<typeof DEFAULT_VIRTUAL_LIST_ELEMENT>
|
|
63
|
+
|
|
52
64
|
const ref = useRef<HTMLDivElement | null>(null)
|
|
53
65
|
const wrapperRef = useRef<HTMLDivElement | null>(null)
|
|
54
66
|
const [scrollTop, setScrollTop] = useState(0)
|
|
@@ -173,15 +185,15 @@ export const VirtualList = forwardRef(function VirtualList(
|
|
|
173
185
|
const wrapperStyle: CSSProperties = useMemo(() => ({height}), [height])
|
|
174
186
|
|
|
175
187
|
return (
|
|
176
|
-
<Box data-ui="VirtualList" {...
|
|
188
|
+
<Box data-ui="VirtualList" {...rest} as={as} position="relative" ref={ref}>
|
|
177
189
|
<div ref={wrapperRef} style={wrapperStyle}>
|
|
178
190
|
{children}
|
|
179
191
|
</div>
|
|
180
192
|
</Box>
|
|
181
193
|
)
|
|
182
|
-
}
|
|
194
|
+
}
|
|
183
195
|
|
|
184
|
-
VirtualList.displayName = '
|
|
196
|
+
VirtualList.displayName = 'VirtualList'
|
|
185
197
|
|
|
186
198
|
function findScrollable(parentNode: ParentNode | null) {
|
|
187
199
|
let _scrollEl = parentNode
|
|
@@ -1,97 +0,0 @@
|
|
|
1
|
-
import {PREFIX} from '../constants'
|
|
2
|
-
import {type Properties} from '../types'
|
|
3
|
-
import {CompileRulesContext} from './types'
|
|
4
|
-
|
|
5
|
-
// TODO: remove this
|
|
6
|
-
export function compileRule(
|
|
7
|
-
selector: string,
|
|
8
|
-
props: Properties,
|
|
9
|
-
context: CompileRulesContext,
|
|
10
|
-
): string {
|
|
11
|
-
let css = compileProperties(selector, props)
|
|
12
|
-
|
|
13
|
-
if (props['@nest']) {
|
|
14
|
-
css += compileNestedRules(selector, props['@nest'], context)
|
|
15
|
-
}
|
|
16
|
-
|
|
17
|
-
// @ts-expect-error - TODO: fix this
|
|
18
|
-
if (props['@keyframes']) {
|
|
19
|
-
// @ts-expect-error - TODO: fix this
|
|
20
|
-
for (const name in props['@keyframes']) {
|
|
21
|
-
// @ts-expect-error - TODO: fix this
|
|
22
|
-
context.keyframes[name] = props['@keyframes'][name]
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
if (props['@media']) {
|
|
27
|
-
for (const key in props['@media']) {
|
|
28
|
-
if (!context.media[key]) {
|
|
29
|
-
context.media[key] = {}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
context.media[key][selector] = props['@media'][key]
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
return css
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
function compileProperties(selector: string, props: Properties) {
|
|
40
|
-
let css = '{'
|
|
41
|
-
|
|
42
|
-
for (const key in props) {
|
|
43
|
-
if (key === '@keyframes') continue // ignore
|
|
44
|
-
if (key === '@media') continue // ignore
|
|
45
|
-
if (key === '@nest') continue // ignore
|
|
46
|
-
|
|
47
|
-
const value = (props as Record<string, string>)[key]
|
|
48
|
-
|
|
49
|
-
const valueArr = Array.isArray(value) ? value : [value]
|
|
50
|
-
|
|
51
|
-
for (const v of valueArr) {
|
|
52
|
-
css += toSnakeCase(key) + ':' + v + ';'
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
if (css === '{') return ''
|
|
57
|
-
|
|
58
|
-
return selector + css + '}'
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
function compileNestedRules(
|
|
62
|
-
selector: string,
|
|
63
|
-
props: Record<string, Properties>,
|
|
64
|
-
context: CompileRulesContext,
|
|
65
|
-
) {
|
|
66
|
-
if (!props) return ''
|
|
67
|
-
|
|
68
|
-
let css = ''
|
|
69
|
-
|
|
70
|
-
for (const [_selector, _props] of Object.entries(props)) {
|
|
71
|
-
css +=
|
|
72
|
-
'\n' +
|
|
73
|
-
compileRule(_selector.replace(/\./g, `.${PREFIX}`).replace(/&/g, selector), _props, context)
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return css
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
export function compileMediaQueryRule(query: string, rules: Record<string, Properties>): string {
|
|
80
|
-
let css = `@media ${query}{`
|
|
81
|
-
|
|
82
|
-
for (const [selector, props] of Object.entries(rules)) {
|
|
83
|
-
// console.log('compileMediaQueryRule', {selector, props})
|
|
84
|
-
|
|
85
|
-
css += '\n ' + compileProperties(selector, props)
|
|
86
|
-
|
|
87
|
-
if (props['@nest']) {
|
|
88
|
-
css += compileNestedRules(selector, props['@nest'], {keyframes: {}, media: {}})
|
|
89
|
-
}
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
return css + '\n}'
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
function toSnakeCase(value: string) {
|
|
96
|
-
return value.replace(/[A-Z]/g, (match) => '-' + match.toLowerCase())
|
|
97
|
-
}
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import {responsiveRules} from '../responsiveRules'
|
|
2
|
-
import {Rules} from '../types'
|
|
3
|
-
import {compileRules} from './compileRules'
|
|
4
|
-
|
|
5
|
-
it('should compile deeply nested rules', () => {
|
|
6
|
-
const rules: Rules = {
|
|
7
|
-
card: {
|
|
8
|
-
'@nest': {
|
|
9
|
-
'&:is(a)': {
|
|
10
|
-
// @ts-expect-error - TODO: fix this
|
|
11
|
-
'@media': {
|
|
12
|
-
'(hover: hover)': {
|
|
13
|
-
background: 'red',
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
},
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
// eslint-disable-next-line no-console
|
|
22
|
-
console.log(compileRules(rules))
|
|
23
|
-
})
|
|
24
|
-
|
|
25
|
-
it.only('should compile responsive rules', () => {
|
|
26
|
-
const rules = responsiveRules('block', {
|
|
27
|
-
'@nest': {
|
|
28
|
-
'&:not([hidden])': {
|
|
29
|
-
display: 'block',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
})
|
|
33
|
-
|
|
34
|
-
// eslint-disable-next-line no-console
|
|
35
|
-
console.log(compileRules(rules))
|
|
36
|
-
})
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import {scopeClassName} from '../scopeClassName'
|
|
2
|
-
import {type Rules} from '../types'
|
|
3
|
-
import {compileMediaQueryRule, compileRule} from './compileRule'
|
|
4
|
-
import {CompileRulesContext} from './types'
|
|
5
|
-
|
|
6
|
-
/** @public */
|
|
7
|
-
export function compileRules(rules: Rules): string {
|
|
8
|
-
let css = ''
|
|
9
|
-
|
|
10
|
-
const context: CompileRulesContext = {
|
|
11
|
-
keyframes: {},
|
|
12
|
-
media: {},
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
for (const [className, props] of Object.entries(rules)) {
|
|
16
|
-
const ruleCss = compileRule(
|
|
17
|
-
`.${scopeClassName(className)}`.replace(/:/g, '\\:'),
|
|
18
|
-
props,
|
|
19
|
-
context,
|
|
20
|
-
)
|
|
21
|
-
|
|
22
|
-
css += ruleCss ? `${ruleCss}\n` : ''
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
for (const [name, value] of Object.entries(context.keyframes)) {
|
|
26
|
-
let keyframesCss = `@keyframes ${name} {\n`
|
|
27
|
-
|
|
28
|
-
for (const [key, props] of Object.entries(value)) {
|
|
29
|
-
keyframesCss += ` ${key}`
|
|
30
|
-
keyframesCss += compileRule('', props, context).replace(/\n/g, '\n ') + '\n'
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
keyframesCss += `\n}\n`
|
|
34
|
-
|
|
35
|
-
css += keyframesCss
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
for (const [query, queryRules] of Object.entries(context.media)) {
|
|
39
|
-
css += compileMediaQueryRule(query, queryRules) + '\n'
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return css.replace(/\n{2,}/g, '\n').trimStart()
|
|
43
|
-
}
|
package/src/css/compile/types.ts
DELETED
|
@@ -1,11 +0,0 @@
|
|
|
1
|
-
import {ThemeColorStateToneKey} from '@sanity/ui/theme'
|
|
2
|
-
|
|
3
|
-
export const toneMap: Record<ThemeColorStateToneKey, string | undefined> = {
|
|
4
|
-
default: 'default',
|
|
5
|
-
neutral: 'neutral',
|
|
6
|
-
suggest: 'suggest',
|
|
7
|
-
primary: 'accent',
|
|
8
|
-
positive: 'positive',
|
|
9
|
-
caution: 'caution',
|
|
10
|
-
critical: 'critical',
|
|
11
|
-
} as const
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import {ThemeColorCardToneKey} from '@sanity/ui/theme'
|
|
2
|
-
|
|
3
|
-
export const toneMap: Record<ThemeColorCardToneKey | 'inherit', string | undefined> = {
|
|
4
|
-
transparent: 'transparent',
|
|
5
|
-
default: 'default',
|
|
6
|
-
neutral: 'neutral',
|
|
7
|
-
suggest: 'suggest',
|
|
8
|
-
primary: 'accent',
|
|
9
|
-
positive: 'positive',
|
|
10
|
-
caution: 'caution',
|
|
11
|
-
critical: 'critical',
|
|
12
|
-
inherit: undefined,
|
|
13
|
-
} as const
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import {ReactNode} from 'react'
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @internal
|
|
5
|
-
* @deprecated this component will be removed in the next major release
|
|
6
|
-
*/
|
|
7
|
-
export function ConditionalWrapper({
|
|
8
|
-
children,
|
|
9
|
-
condition,
|
|
10
|
-
wrapper,
|
|
11
|
-
}: {
|
|
12
|
-
children: ReactNode
|
|
13
|
-
condition: boolean
|
|
14
|
-
wrapper: (children: ReactNode) => ReactNode
|
|
15
|
-
}): ReactNode {
|
|
16
|
-
if (!condition) {
|
|
17
|
-
return children
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
return wrapper(children)
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
ConditionalWrapper.displayName = 'ConditionalWrapper'
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
export * from './conditionalWrapper'
|