@cognitap/radiant 0.0.78 → 0.0.79
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/CHANGELOG.md +11 -0
- package/README.md +6 -3
- package/RELEASE_POLICY.md +8 -19
- package/dist/library/charts/Charts.js +1 -1
- package/dist/library/charts/Charts.js.map +1 -1
- package/dist/library/components/Accordion/Accordion.js +1 -1
- package/dist/library/components/Accordion/Accordion.js.map +1 -1
- package/dist/library/components/Alert/Alert.js +1 -1
- package/dist/library/components/Alert/Alert.js.map +1 -1
- package/dist/library/components/AppShell/AppShell.js +1 -1
- package/dist/library/components/AppShell/AppShell.js.map +1 -1
- package/dist/library/components/AspectRatio/AspectRatio.js +1 -1
- package/dist/library/components/AspectRatio/AspectRatio.js.map +1 -1
- package/dist/library/components/Avatar/Avatar.js +1 -1
- package/dist/library/components/Avatar/Avatar.js.map +1 -1
- package/dist/library/components/Badge/Badge.js +1 -1
- package/dist/library/components/Badge/Badge.js.map +1 -1
- package/dist/library/components/Breadcrumb/Breadcrumb.js +1 -1
- package/dist/library/components/Breadcrumb/Breadcrumb.js.map +1 -1
- package/dist/library/components/Button/Button.js +1 -1
- package/dist/library/components/Button/Button.js.map +1 -1
- package/dist/library/components/ButtonGroup/ButtonGroup.js +1 -1
- package/dist/library/components/ButtonGroup/ButtonGroup.js.map +1 -1
- package/dist/library/components/Card/Card.js +1 -1
- package/dist/library/components/Card/Card.js.map +1 -1
- package/dist/library/components/Carousel/Carousel.js +6 -6
- package/dist/library/components/Carousel/Carousel.js.map +1 -1
- package/dist/library/components/Checkbox/Checkbox.js +1 -1
- package/dist/library/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/library/components/CheckboxGroup/CheckboxGroup.js +1 -1
- package/dist/library/components/CheckboxGroup/CheckboxGroup.js.map +1 -1
- package/dist/library/components/CodeBlock/CodeBlock.js +1 -1
- package/dist/library/components/CodeBlock/CodeBlock.js.map +1 -1
- package/dist/library/components/Collapsible/Collapsible.js +1 -1
- package/dist/library/components/Collapsible/Collapsible.js.map +1 -1
- package/dist/library/components/Combobox/Combobox.js +1 -1
- package/dist/library/components/Combobox/Combobox.js.map +1 -1
- package/dist/library/components/Command/Command.js +1 -1
- package/dist/library/components/Command/Command.js.map +1 -1
- package/dist/library/components/ContextMenu/ContextMenu.js +1 -1
- package/dist/library/components/ContextMenu/ContextMenu.js.map +1 -1
- package/dist/library/components/Dialog/Dialog.js +1 -1
- package/dist/library/components/Dialog/Dialog.js.map +1 -1
- package/dist/library/components/Drawer/Drawer.js +1 -1
- package/dist/library/components/Drawer/Drawer.js.map +1 -1
- package/dist/library/components/EmptyState/EmptyState.js +1 -1
- package/dist/library/components/EmptyState/EmptyState.js.map +1 -1
- package/dist/library/components/Field/Field.js +1 -1
- package/dist/library/components/Field/Field.js.map +1 -1
- package/dist/library/components/Fieldset/Fieldset.js +1 -1
- package/dist/library/components/Fieldset/Fieldset.js.map +1 -1
- package/dist/library/components/FileInput/FileInput.js +1 -1
- package/dist/library/components/FileInput/FileInput.js.map +1 -1
- package/dist/library/components/Form/Form.js +4 -4
- package/dist/library/components/Form/Form.js.map +1 -1
- package/dist/library/components/HoverCard/HoverCard.js +1 -1
- package/dist/library/components/HoverCard/HoverCard.js.map +1 -1
- package/dist/library/components/InlineCode/InlineCode.js +1 -1
- package/dist/library/components/InlineCode/InlineCode.js.map +1 -1
- package/dist/library/components/Input/Input.js +1 -1
- package/dist/library/components/Input/Input.js.map +1 -1
- package/dist/library/components/InputGroup/InputGroup.js +1 -1
- package/dist/library/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/library/components/Kbd/Kbd.js +1 -1
- package/dist/library/components/Kbd/Kbd.js.map +1 -1
- package/dist/library/components/Link/Link.js +1 -1
- package/dist/library/components/Link/Link.js.map +1 -1
- package/dist/library/components/Menu/Menu.js +1 -1
- package/dist/library/components/Menu/Menu.js.map +1 -1
- package/dist/library/components/Menubar/Menubar.js +1 -1
- package/dist/library/components/Menubar/Menubar.js.map +1 -1
- package/dist/library/components/Meter/Meter.js +1 -1
- package/dist/library/components/Meter/Meter.js.map +1 -1
- package/dist/library/components/NativeSelect/NativeSelect.js +1 -1
- package/dist/library/components/NativeSelect/NativeSelect.js.map +1 -1
- package/dist/library/components/NavLink/NavLink.js +1 -1
- package/dist/library/components/NavLink/NavLink.js.map +1 -1
- package/dist/library/components/NavigationMenu/NavigationMenu.js +1 -1
- package/dist/library/components/NavigationMenu/NavigationMenu.js.map +1 -1
- package/dist/library/components/NumberField/NumberField.js +1 -1
- package/dist/library/components/NumberField/NumberField.js.map +1 -1
- package/dist/library/components/OTPField/OTPField.js +1 -1
- package/dist/library/components/OTPField/OTPField.js.map +1 -1
- package/dist/library/components/Pagination/Pagination.js +1 -1
- package/dist/library/components/Pagination/Pagination.js.map +1 -1
- package/dist/library/components/PasswordInput/PasswordInput.js +1 -1
- package/dist/library/components/PasswordInput/PasswordInput.js.map +1 -1
- package/dist/library/components/Popover/Popover.js +1 -1
- package/dist/library/components/Popover/Popover.js.map +1 -1
- package/dist/library/components/Progress/Progress.js +1 -1
- package/dist/library/components/Progress/Progress.js.map +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.js +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/library/components/Resizable/Resizable.js +1 -1
- package/dist/library/components/Resizable/Resizable.js.map +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.js +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.js.map +1 -1
- package/dist/library/components/Select/Select.js +1 -1
- package/dist/library/components/Select/Select.js.map +1 -1
- package/dist/library/components/Separator/Separator.js +1 -1
- package/dist/library/components/Separator/Separator.js.map +1 -1
- package/dist/library/components/Skeleton/Skeleton.js +1 -1
- package/dist/library/components/Skeleton/Skeleton.js.map +1 -1
- package/dist/library/components/Slider/Slider.js +1 -1
- package/dist/library/components/Slider/Slider.js.map +1 -1
- package/dist/library/components/Spinner/Spinner.js +1 -1
- package/dist/library/components/Spinner/Spinner.js.map +1 -1
- package/dist/library/components/Switch/Switch.js +1 -1
- package/dist/library/components/Switch/Switch.js.map +1 -1
- package/dist/library/components/Table/Table.js +1 -1
- package/dist/library/components/Table/Table.js.map +1 -1
- package/dist/library/components/Tabs/Tabs.js +1 -1
- package/dist/library/components/Tabs/Tabs.js.map +1 -1
- package/dist/library/components/Tag/Tag.js +1 -1
- package/dist/library/components/Tag/Tag.js.map +1 -1
- package/dist/library/components/TagsInput/TagsInput.js +1 -1
- package/dist/library/components/TagsInput/TagsInput.js.map +1 -1
- package/dist/library/components/Textarea/Textarea.js +1 -1
- package/dist/library/components/Textarea/Textarea.js.map +1 -1
- package/dist/library/components/ThemeScope/ThemeScope.js +1 -1
- package/dist/library/components/ThemeScope/ThemeScope.js.map +1 -1
- package/dist/library/components/Toast/Toast.js +1 -1
- package/dist/library/components/Toast/Toast.js.map +1 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js +3 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js.map +1 -1
- package/dist/library/components/Toolbar/Toolbar.js +1 -1
- package/dist/library/components/Toolbar/Toolbar.js.map +1 -1
- package/dist/library/components/Tooltip/Tooltip.js +1 -1
- package/dist/library/components/Tooltip/Tooltip.js.map +1 -1
- package/dist/library/motion/MotionLink.js +1 -1
- package/dist/library/motion/MotionLink.js.map +1 -1
- package/dist/library/react/useComboboxPopup.d.ts.map +1 -1
- package/dist/library/react/useComboboxPopup.js +45 -6
- package/dist/library/react/useComboboxPopup.js.map +1 -1
- package/dist/library/react/useRovingFocus.d.ts.map +1 -1
- package/dist/library/react/useRovingFocus.js +76 -11
- package/dist/library/react/useRovingFocus.js.map +1 -1
- package/dist/library/react/useToastTimer.d.ts.map +1 -1
- package/dist/library/react/useToastTimer.js +28 -9
- package/dist/library/react/useToastTimer.js.map +1 -1
- package/dist/library/styles.css +1 -1
- package/docs/accessibility.md +23 -111
- package/docs/architecture.md +48 -242
- package/docs/motion.md +65 -130
- package/docs/theming.md +51 -427
- package/package.json +21 -13
- package/src/charts/Charts.tsx +1 -1
- package/src/components/Accordion/Accordion.tsx +1 -1
- package/src/components/Alert/Alert.tsx +1 -1
- package/src/components/AppShell/AppShell.tsx +1 -1
- package/src/components/AspectRatio/AspectRatio.tsx +1 -1
- package/src/components/Avatar/Avatar.tsx +1 -1
- package/src/components/Badge/Badge.tsx +1 -1
- package/src/components/Breadcrumb/Breadcrumb.tsx +1 -1
- package/src/components/Button/Button.tsx +1 -1
- package/src/components/ButtonGroup/ButtonGroup.tsx +1 -1
- package/src/components/Card/Card.tsx +1 -1
- package/src/components/Carousel/Carousel.tsx +6 -6
- package/src/components/Checkbox/Checkbox.tsx +1 -1
- package/src/components/CheckboxGroup/CheckboxGroup.tsx +1 -1
- package/src/components/CodeBlock/CodeBlock.tsx +1 -1
- package/src/components/Collapsible/Collapsible.tsx +1 -1
- package/src/components/Combobox/Combobox.tsx +1 -1
- package/src/components/Command/Command.tsx +1 -1
- package/src/components/ContextMenu/ContextMenu.tsx +1 -1
- package/src/components/Dialog/Dialog.tsx +1 -1
- package/src/components/Drawer/Drawer.tsx +1 -1
- package/src/components/EmptyState/EmptyState.tsx +1 -1
- package/src/components/Field/Field.tsx +1 -1
- package/src/components/Fieldset/Fieldset.tsx +1 -1
- package/src/components/FileInput/FileInput.tsx +1 -1
- package/src/components/Form/Form.tsx +4 -4
- package/src/components/HoverCard/HoverCard.tsx +1 -1
- package/src/components/InlineCode/InlineCode.tsx +1 -1
- package/src/components/Input/Input.tsx +1 -1
- package/src/components/InputGroup/InputGroup.tsx +1 -1
- package/src/components/Kbd/Kbd.tsx +1 -1
- package/src/components/Link/Link.tsx +1 -1
- package/src/components/Menu/Menu.tsx +1 -1
- package/src/components/Menubar/Menubar.tsx +1 -1
- package/src/components/Meter/Meter.tsx +1 -1
- package/src/components/NativeSelect/NativeSelect.tsx +1 -1
- package/src/components/NavLink/NavLink.tsx +1 -1
- package/src/components/NavigationMenu/NavigationMenu.tsx +1 -1
- package/src/components/NumberField/NumberField.tsx +1 -1
- package/src/components/OTPField/OTPField.tsx +1 -1
- package/src/components/Pagination/Pagination.tsx +1 -1
- package/src/components/PasswordInput/PasswordInput.tsx +1 -1
- package/src/components/Popover/Popover.tsx +1 -1
- package/src/components/Progress/Progress.tsx +1 -1
- package/src/components/RadioGroup/RadioGroup.tsx +1 -1
- package/src/components/Resizable/Resizable.tsx +1 -1
- package/src/components/ScrollArea/ScrollArea.tsx +1 -1
- package/src/components/Select/Select.tsx +1 -1
- package/src/components/Separator/Separator.tsx +1 -1
- package/src/components/Skeleton/Skeleton.tsx +1 -1
- package/src/components/Slider/Slider.tsx +1 -1
- package/src/components/Spinner/Spinner.tsx +1 -1
- package/src/components/Switch/Switch.tsx +1 -1
- package/src/components/Table/Table.tsx +1 -1
- package/src/components/Tabs/Tabs.tsx +1 -1
- package/src/components/Tag/Tag.tsx +1 -1
- package/src/components/TagsInput/TagsInput.tsx +1 -1
- package/src/components/Textarea/Textarea.tsx +1 -1
- package/src/components/ThemeScope/ThemeScope.tsx +1 -1
- package/src/components/Toast/Toast.tsx +1 -1
- package/src/components/ToggleGroup/ToggleGroup.tsx +3 -1
- package/src/components/Toolbar/Toolbar.tsx +1 -1
- package/src/components/Tooltip/Tooltip.tsx +1 -1
- package/src/css.d.ts +2 -0
- package/src/motion/MotionLink.tsx +1 -1
- package/src/react/useComboboxPopup.ts +38 -6
- package/src/react/useRovingFocus.ts +73 -8
- package/src/react/useToastTimer.ts +24 -9
- package/src/styles.d.ts +1 -0
- package/src/themes/baseline.css +1 -1
- package/src/typography.css +17 -12
- package/dist/library/cn.d.ts +0 -3
- package/dist/library/cn.d.ts.map +0 -1
- package/dist/library/cn.js +0 -370
- package/dist/library/cn.js.map +0 -1
- package/src/cn.ts +0 -372
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
|
|
3
3
|
import type { ComponentProps } from 'react'
|
|
4
4
|
import { cva } from 'class-variance-authority'
|
|
5
|
-
import { cn } from '
|
|
5
|
+
import { cn } from 'cn'
|
|
6
6
|
import { joinIds } from '../../internal/ids.js'
|
|
7
7
|
import { controlBorderClass, controlMetrics } from '../shared/controlStyles.js'
|
|
8
8
|
import { useNativeOwner, type ValueOwner } from '../../react/useNativeOwner.js'
|
|
@@ -4,7 +4,7 @@ import { MotionProfileContext } from '../../motion/context.js'
|
|
|
4
4
|
|
|
5
5
|
import { createContext, useContext } from 'react'
|
|
6
6
|
import type { ComponentProps } from 'react'
|
|
7
|
-
import { cn } from '
|
|
7
|
+
import { cn } from 'cn'
|
|
8
8
|
import { defaultTheme } from '../../themes/default.js'
|
|
9
9
|
import { modeStyle } from '../../themes/tokens.js'
|
|
10
10
|
import type { Theme, ThemeMode, ThemeStyle } from '../../themes/defineTheme.js'
|
|
@@ -21,7 +21,7 @@ import {
|
|
|
21
21
|
type AlertDescriptionProps
|
|
22
22
|
} from '../Alert/Alert.js'
|
|
23
23
|
import { Button, type ButtonProps, type ButtonRenderProps } from '../Button/Button.js'
|
|
24
|
-
import { cn } from '
|
|
24
|
+
import { cn } from 'cn'
|
|
25
25
|
import { joinIds } from '../../internal/ids.js'
|
|
26
26
|
import { requireAccessibleName, type AccessibleName } from '../../internal/accessibleName.js'
|
|
27
27
|
import type { WithoutToggle } from '../../internal/types.js'
|
|
@@ -11,7 +11,7 @@ import {
|
|
|
11
11
|
} from 'react'
|
|
12
12
|
import { Button, type ButtonProps, type ButtonRenderProps } from '../Button/Button.js'
|
|
13
13
|
import { requireAccessibleName, type AccessibleName } from '../../internal/accessibleName.js'
|
|
14
|
-
import { cn } from '
|
|
14
|
+
import { cn } from 'cn'
|
|
15
15
|
import { joinIds } from '../../internal/ids.js'
|
|
16
16
|
import {
|
|
17
17
|
isItemOpen,
|
|
@@ -330,6 +330,8 @@ function Indicator({
|
|
|
330
330
|
attributes: true,
|
|
331
331
|
attributeFilter: ['aria-pressed', 'class', 'style', 'hidden', 'dir']
|
|
332
332
|
})
|
|
333
|
+
for (let parent = root.parentElement; parent; parent = parent.parentElement)
|
|
334
|
+
changes.observe(parent, { attributes: true, attributeFilter: ['dir'] })
|
|
333
335
|
observe()
|
|
334
336
|
measure()
|
|
335
337
|
view.addEventListener('resize', schedule)
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { useRef, type ComponentProps } from 'react'
|
|
3
|
-
import { cn } from '
|
|
3
|
+
import { cn } from 'cn'
|
|
4
4
|
import { joinIds } from '../../internal/ids.js'
|
|
5
5
|
import { requireAccessibleName, type AccessibleName } from '../../internal/accessibleName.js'
|
|
6
6
|
import { useComposedRefs } from '../../react/useComposedRefs.js'
|
|
@@ -12,7 +12,7 @@ import {
|
|
|
12
12
|
} from 'react'
|
|
13
13
|
import { createPortal } from 'react-dom'
|
|
14
14
|
import { Button, type ButtonProps, type ButtonRenderProps } from '../Button/Button.js'
|
|
15
|
-
import { cn } from '
|
|
15
|
+
import { cn } from 'cn'
|
|
16
16
|
import { joinIds } from '../../internal/ids.js'
|
|
17
17
|
import { composeAction } from '../../internal/events.js'
|
|
18
18
|
import type { PopoverSide, PopoverAlign } from '../../internal/popover.js'
|
package/src/css.d.ts
ADDED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
import { Link, type LinkProps } from '../components/Link/Link.js'
|
|
3
|
-
import { cn } from '
|
|
3
|
+
import { cn } from 'cn'
|
|
4
4
|
import { usePressHost } from './host.js'
|
|
5
5
|
import { callerOwnsPress, springPressClass, offPressClass } from './pressPolicy.js'
|
|
6
6
|
export type MotionLinkProps = LinkProps & {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
'use client'
|
|
2
2
|
|
|
3
|
-
import { useLayoutEffect, useRef, type RefObject } from 'react'
|
|
3
|
+
import { useLayoutEffect, useRef, useState, type RefObject } from 'react'
|
|
4
4
|
import { positionSelect } from '../internal/select.js'
|
|
5
5
|
|
|
6
6
|
/** Local top-layer popup: preserve theme/modal ancestry and place before its first paint. */
|
|
@@ -12,15 +12,47 @@ export function useComboboxPopup(
|
|
|
12
12
|
sideOffset: number,
|
|
13
13
|
collisionPadding: number
|
|
14
14
|
) {
|
|
15
|
-
const latest = useRef(dismiss)
|
|
15
|
+
const latest = useRef({ dismiss, open })
|
|
16
16
|
const reposition = useRef<() => void>(() => {})
|
|
17
|
+
const [generation, setGeneration] = useState(0)
|
|
17
18
|
useLayoutEffect(() => {
|
|
18
|
-
latest.current = dismiss
|
|
19
|
+
latest.current = { dismiss, open }
|
|
19
20
|
})
|
|
21
|
+
// A manual popup stays in the top layer after an ancestor dialog or popover closes.
|
|
20
22
|
useLayoutEffect(() => {
|
|
21
23
|
const node = nodeRef.current
|
|
22
24
|
if (!node || !input) return
|
|
23
|
-
|
|
25
|
+
const ancestors: HTMLElement[] = []
|
|
26
|
+
for (let parent = input.parentElement; parent; parent = parent.parentElement) {
|
|
27
|
+
if (parent.matches('dialog, [popover]')) ancestors.push(parent)
|
|
28
|
+
}
|
|
29
|
+
const reconcile = () => {
|
|
30
|
+
if (!latest.current.open) return
|
|
31
|
+
const visible = input.checkVisibility()
|
|
32
|
+
if (!visible && node.matches(':popover-open')) {
|
|
33
|
+
latest.current.dismiss()
|
|
34
|
+
node.hidePopover()
|
|
35
|
+
setGeneration(value => value + 1)
|
|
36
|
+
} else if (visible && !node.matches(':popover-open')) setGeneration(value => value + 1)
|
|
37
|
+
}
|
|
38
|
+
const toggle = (event: Event) => {
|
|
39
|
+
if (event.target === event.currentTarget) reconcile()
|
|
40
|
+
}
|
|
41
|
+
const view = input.ownerDocument.defaultView!
|
|
42
|
+
const observer = new view.MutationObserver(reconcile)
|
|
43
|
+
for (const ancestor of ancestors) {
|
|
44
|
+
observer.observe(ancestor, { attributes: true, attributeFilter: ['open', 'data-state'] })
|
|
45
|
+
ancestor.addEventListener('toggle', toggle)
|
|
46
|
+
}
|
|
47
|
+
return () => {
|
|
48
|
+
observer.disconnect()
|
|
49
|
+
for (const ancestor of ancestors) ancestor.removeEventListener('toggle', toggle)
|
|
50
|
+
}
|
|
51
|
+
}, [nodeRef, input])
|
|
52
|
+
useLayoutEffect(() => {
|
|
53
|
+
const node = nodeRef.current
|
|
54
|
+
if (!node || !input) return
|
|
55
|
+
if (!open || !input.checkVisibility()) {
|
|
24
56
|
if (node.matches(':popover-open')) node.hidePopover()
|
|
25
57
|
return
|
|
26
58
|
}
|
|
@@ -103,7 +135,7 @@ export function useComboboxPopup(
|
|
|
103
135
|
!node.contains(target) &&
|
|
104
136
|
!input.parentElement?.contains(target)
|
|
105
137
|
)
|
|
106
|
-
latest.current()
|
|
138
|
+
latest.current.dismiss()
|
|
107
139
|
}
|
|
108
140
|
const observer = new win.ResizeObserver(schedule)
|
|
109
141
|
const mutations = new win.MutationObserver(schedule)
|
|
@@ -129,7 +161,7 @@ export function useComboboxPopup(
|
|
|
129
161
|
win.visualViewport?.removeEventListener('scroll', schedule)
|
|
130
162
|
if (node.matches(':popover-open')) node.hidePopover()
|
|
131
163
|
}
|
|
132
|
-
}, [nodeRef, input, open, sideOffset, collisionPadding])
|
|
164
|
+
}, [nodeRef, input, open, sideOffset, collisionPadding, generation])
|
|
133
165
|
// Selected tags can move an unchanged-size input without a resize event.
|
|
134
166
|
useLayoutEffect(() => {
|
|
135
167
|
reposition.current()
|
|
@@ -3,6 +3,7 @@
|
|
|
3
3
|
import {
|
|
4
4
|
createContext,
|
|
5
5
|
useLayoutEffect,
|
|
6
|
+
useRef,
|
|
6
7
|
type KeyboardEvent,
|
|
7
8
|
type FocusEvent,
|
|
8
9
|
type RefObject
|
|
@@ -35,19 +36,36 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
35
36
|
deferTo,
|
|
36
37
|
includeAriaDisabled = false
|
|
37
38
|
}: Options<Node>) {
|
|
39
|
+
const latest = useRef({
|
|
40
|
+
selector,
|
|
41
|
+
scope,
|
|
42
|
+
preferred,
|
|
43
|
+
orientation,
|
|
44
|
+
loop,
|
|
45
|
+
active,
|
|
46
|
+
deferTo,
|
|
47
|
+
includeAriaDisabled
|
|
48
|
+
})
|
|
49
|
+
const appliedTo = useRef<Node | null>(null)
|
|
50
|
+
const settleRef = useRef<(node: Node) => void>(() => {})
|
|
51
|
+
const binding = useRef<{ node: Node; cleanup: () => void } | null>(null)
|
|
38
52
|
const ownsFocus = (node: Node) => {
|
|
53
|
+
const { active, deferTo } = latest.current
|
|
39
54
|
if (!active) return false
|
|
40
55
|
const parent = deferTo ? node.parentElement?.closest(deferTo) : null
|
|
41
56
|
const surface = node.closest('[popover], dialog')
|
|
42
57
|
// React context crosses portals; native focus ownership stops at a new surface.
|
|
43
58
|
return !parent || !!(surface && parent.contains(surface))
|
|
44
59
|
}
|
|
45
|
-
const items = (node: Node) =>
|
|
46
|
-
|
|
60
|
+
const items = (node: Node) => {
|
|
61
|
+
const { selector, scope } = latest.current
|
|
62
|
+
return Array.from(node.querySelectorAll<HTMLElement>(selector)).filter(item => {
|
|
47
63
|
const surface = item.closest('[popover], dialog')
|
|
48
64
|
return item.closest(scope) === node && (!surface || !node.contains(surface))
|
|
49
65
|
})
|
|
66
|
+
}
|
|
50
67
|
const enabled = (node: Node) => {
|
|
68
|
+
const { includeAriaDisabled } = latest.current
|
|
51
69
|
const view = node.ownerDocument.defaultView!
|
|
52
70
|
return items(node).filter(
|
|
53
71
|
item =>
|
|
@@ -59,6 +77,7 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
59
77
|
)
|
|
60
78
|
}
|
|
61
79
|
const sync = (node: Node, preferFocus = true) => {
|
|
80
|
+
const { preferred } = latest.current
|
|
62
81
|
const all = items(node),
|
|
63
82
|
available = enabled(node)
|
|
64
83
|
const focused = node.ownerDocument.activeElement
|
|
@@ -78,13 +97,47 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
78
97
|
if (item.tabIndex !== index) item.tabIndex = index
|
|
79
98
|
}
|
|
80
99
|
}
|
|
100
|
+
useLayoutEffect(() => {
|
|
101
|
+
latest.current = {
|
|
102
|
+
selector,
|
|
103
|
+
scope,
|
|
104
|
+
preferred,
|
|
105
|
+
orientation,
|
|
106
|
+
loop,
|
|
107
|
+
active,
|
|
108
|
+
deferTo,
|
|
109
|
+
includeAriaDisabled
|
|
110
|
+
}
|
|
111
|
+
settleRef.current = (node: Node) => {
|
|
112
|
+
if (!ownsFocus(node)) {
|
|
113
|
+
if (appliedTo.current !== node) return
|
|
114
|
+
for (const item of items(node)) if (item.tabIndex !== 0) item.tabIndex = 0
|
|
115
|
+
appliedTo.current = null
|
|
116
|
+
return
|
|
117
|
+
}
|
|
118
|
+
sync(node)
|
|
119
|
+
appliedTo.current = node
|
|
120
|
+
}
|
|
121
|
+
})
|
|
122
|
+
useLayoutEffect(() => {
|
|
123
|
+
const node = host.current
|
|
124
|
+
if (node) settleRef.current(node)
|
|
125
|
+
}, [host, selector, scope, preferred, active, deferTo, includeAriaDisabled])
|
|
81
126
|
useLayoutEffect(() => {
|
|
82
127
|
const node = host.current
|
|
83
|
-
if (!node ||
|
|
128
|
+
if (!node || binding.current?.node === node) {
|
|
129
|
+
if (!node && binding.current) {
|
|
130
|
+
binding.current.cleanup()
|
|
131
|
+
binding.current = null
|
|
132
|
+
}
|
|
133
|
+
return
|
|
134
|
+
}
|
|
135
|
+
binding.current?.cleanup()
|
|
136
|
+
binding.current = null
|
|
84
137
|
const view = node.ownerDocument.defaultView!
|
|
85
|
-
const reconcile = () =>
|
|
86
|
-
reconcile()
|
|
138
|
+
const reconcile = () => settleRef.current(node)
|
|
87
139
|
const observer = new view.MutationObserver(records => {
|
|
140
|
+
const selector = latest.current.selector
|
|
88
141
|
if (
|
|
89
142
|
records.some(
|
|
90
143
|
record =>
|
|
@@ -119,11 +172,22 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
119
172
|
})
|
|
120
173
|
const resize = new view.ResizeObserver(reconcile)
|
|
121
174
|
resize.observe(node)
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
175
|
+
binding.current = {
|
|
176
|
+
node,
|
|
177
|
+
cleanup: () => {
|
|
178
|
+
observer.disconnect()
|
|
179
|
+
resize.disconnect()
|
|
180
|
+
}
|
|
125
181
|
}
|
|
182
|
+
settleRef.current(node)
|
|
126
183
|
})
|
|
184
|
+
useLayoutEffect(
|
|
185
|
+
() => () => {
|
|
186
|
+
binding.current?.cleanup()
|
|
187
|
+
binding.current = null
|
|
188
|
+
},
|
|
189
|
+
[]
|
|
190
|
+
)
|
|
127
191
|
return {
|
|
128
192
|
items: enabled,
|
|
129
193
|
onFocus(event: FocusEvent<Node>) {
|
|
@@ -149,6 +213,7 @@ export function useRovingFocus<Node extends HTMLElement>({
|
|
|
149
213
|
event.nativeEvent.isComposing
|
|
150
214
|
)
|
|
151
215
|
return
|
|
216
|
+
const { selector, orientation, loop } = latest.current
|
|
152
217
|
const node = event.currentTarget,
|
|
153
218
|
available = enabled(node),
|
|
154
219
|
current = (event.target as Element).closest(selector),
|
|
@@ -27,36 +27,51 @@ export function useToastTimer(
|
|
|
27
27
|
() => latest.current()
|
|
28
28
|
)
|
|
29
29
|
let hovering = node.matches(':hover')
|
|
30
|
+
let touching = false
|
|
30
31
|
const sync = () => {
|
|
31
|
-
const paused = hovering || node.contains(doc.activeElement) || doc.hidden
|
|
32
|
+
const paused = hovering || touching || node.contains(doc.activeElement) || doc.hidden
|
|
32
33
|
node.toggleAttribute('data-paused', paused)
|
|
33
34
|
if (paused) timer.pause()
|
|
34
35
|
else timer.resume()
|
|
35
36
|
}
|
|
36
37
|
const enter = (event: PointerEvent) => {
|
|
37
|
-
if (event.pointerType
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}
|
|
38
|
+
if (event.pointerType === 'touch') return
|
|
39
|
+
hovering = true
|
|
40
|
+
sync()
|
|
41
41
|
}
|
|
42
42
|
const leave = (event: PointerEvent) => {
|
|
43
|
-
if (event.pointerType
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
43
|
+
if (event.pointerType === 'touch') return
|
|
44
|
+
hovering = false
|
|
45
|
+
sync()
|
|
46
|
+
}
|
|
47
|
+
const press = (event: PointerEvent) => {
|
|
48
|
+
if (event.pointerType !== 'touch') return
|
|
49
|
+
touching = true
|
|
50
|
+
sync()
|
|
51
|
+
}
|
|
52
|
+
const release = (event: PointerEvent) => {
|
|
53
|
+
if (event.pointerType !== 'touch' || !touching) return
|
|
54
|
+
touching = false
|
|
55
|
+
sync()
|
|
47
56
|
}
|
|
48
57
|
node.addEventListener('pointerenter', enter)
|
|
49
58
|
node.addEventListener('pointerleave', leave)
|
|
59
|
+
node.addEventListener('pointerdown', press)
|
|
50
60
|
node.addEventListener('focusin', sync)
|
|
51
61
|
node.addEventListener('focusout', sync)
|
|
62
|
+
doc.addEventListener('pointerup', release)
|
|
63
|
+
doc.addEventListener('pointercancel', release)
|
|
52
64
|
doc.addEventListener('visibilitychange', sync)
|
|
53
65
|
sync()
|
|
54
66
|
return () => {
|
|
55
67
|
timer.destroy()
|
|
56
68
|
node.removeEventListener('pointerenter', enter)
|
|
57
69
|
node.removeEventListener('pointerleave', leave)
|
|
70
|
+
node.removeEventListener('pointerdown', press)
|
|
58
71
|
node.removeEventListener('focusin', sync)
|
|
59
72
|
node.removeEventListener('focusout', sync)
|
|
73
|
+
doc.removeEventListener('pointerup', release)
|
|
74
|
+
doc.removeEventListener('pointercancel', release)
|
|
60
75
|
doc.removeEventListener('visibilitychange', sync)
|
|
61
76
|
delete node.dataset.paused
|
|
62
77
|
}
|
package/src/styles.d.ts
CHANGED
package/src/themes/baseline.css
CHANGED
package/src/typography.css
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
/* Generated by scripts/generate-theme-css.
|
|
1
|
+
/* Generated by scripts/generate-theme-css.ts; same tokens for both CSS routes. */
|
|
2
2
|
@layer components {
|
|
3
3
|
:where([data-rad-type-container]) {
|
|
4
4
|
container-type: inline-size;
|
|
@@ -247,25 +247,30 @@
|
|
|
247
247
|
) {
|
|
248
248
|
margin-block-start: var(--rad-typography-flow-heading-after);
|
|
249
249
|
}
|
|
250
|
-
:where([data-rad-prose]) > :where(ul, ol) {
|
|
250
|
+
:where([data-rad-prose]) > :where(ul, ol):not(:where([data-rad-not-prose], [data-slot])) {
|
|
251
251
|
padding-inline-start: 1.25em;
|
|
252
252
|
}
|
|
253
|
-
:where([data-rad-prose]) > :where(pre),
|
|
253
|
+
:where([data-rad-prose]) > :where(pre):not(:where([data-rad-not-prose], [data-slot])),
|
|
254
254
|
:where([data-rad-text='code']) {
|
|
255
255
|
overflow: auto;
|
|
256
256
|
white-space: pre;
|
|
257
257
|
overflow-wrap: normal;
|
|
258
258
|
}
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
:where(
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
259
|
+
/* The scope ends at opted-out descendants, so code nested inside one keeps its own styles. */
|
|
260
|
+
@scope ([data-rad-prose]) to (:where([data-rad-not-prose], [data-slot])) {
|
|
261
|
+
:where(:scope)
|
|
262
|
+
> :where(p, ul, ol, li, blockquote, h1, h2, h3, h4, h5, h6)
|
|
263
|
+
:where(code):not(:where(pre code)) {
|
|
264
|
+
font-family: var(--rad-typography-roles-code-family);
|
|
265
|
+
font-size: 0.9em;
|
|
266
|
+
font-weight: inherit;
|
|
267
|
+
line-height: inherit;
|
|
268
|
+
letter-spacing: 0;
|
|
269
|
+
}
|
|
267
270
|
}
|
|
268
|
-
:where([data-rad-prose])
|
|
271
|
+
:where([data-rad-prose])
|
|
272
|
+
> :where(pre):not(:where([data-rad-not-prose], [data-slot]))
|
|
273
|
+
> :where(code) {
|
|
269
274
|
font: inherit;
|
|
270
275
|
letter-spacing: inherit;
|
|
271
276
|
}
|
package/dist/library/cn.d.ts
DELETED
package/dist/library/cn.d.ts.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"cn.d.ts","sourceRoot":"","sources":["../../src/cn.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,IAAI,CAAA;AAOpC,eAAO,MAAM,EAAE,EAAE,UA2Wf,CAAA"}
|