@react-md/core 6.3.4 → 6.4.0
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/CoreProviders.d.ts +1 -0
- package/dist/CoreProviders.js.map +1 -1
- package/dist/_base.scss +3 -0
- package/dist/_core.scss +1 -0
- package/dist/_utils.scss +15 -7
- package/dist/app-bar/AppBar.js.map +1 -1
- package/dist/app-bar/AppBarTitle.js.map +1 -1
- package/dist/autocomplete/AutocompleteListboxChildren.js.map +1 -1
- package/dist/autocomplete/types.js.map +1 -1
- package/dist/autocomplete/utils.js.map +1 -1
- package/dist/avatar/Avatar.js.map +1 -1
- package/dist/button/Button.js.map +1 -1
- package/dist/button/FloatingActionButton.js.map +1 -1
- package/dist/card/Card.js.map +1 -1
- package/dist/card/CardContent.js.map +1 -1
- package/dist/card/ClickableCard.js.map +1 -1
- package/dist/chip/Chip.js.map +1 -1
- package/dist/datetime/NativeDateField.js.map +1 -1
- package/dist/datetime/NativeTimeField.js.map +1 -1
- package/dist/datetime/useDateField.js.map +1 -1
- package/dist/datetime/useTimeField.js.map +1 -1
- package/dist/dialog/Dialog.js.map +1 -1
- package/dist/dialog/DialogContainer.js.map +1 -1
- package/dist/dialog/DialogContent.js.map +1 -1
- package/dist/dialog/DialogFooter.js.map +1 -1
- package/dist/divider/Divider.js.map +1 -1
- package/dist/draggable/useDraggable.js.map +1 -1
- package/dist/draggable/utils.js.map +1 -1
- package/dist/expansion-panel/ExpansionPanelHeader.js.map +1 -1
- package/dist/files/FileInput.js.map +1 -1
- package/dist/files/useFileUpload.js.map +1 -1
- package/dist/files/validation.js.map +1 -1
- package/dist/focus/useFocusContainer.js.map +1 -1
- package/dist/form/Fieldset.d.ts +19 -0
- package/dist/form/Fieldset.js +22 -2
- package/dist/form/Fieldset.js.map +1 -1
- package/dist/form/FormMessageContainer.js.map +1 -1
- package/dist/form/FormMessageCounter.js.map +1 -1
- package/dist/form/InputToggle.js.map +1 -1
- package/dist/form/Legend.d.ts +27 -5
- package/dist/form/Legend.js +39 -6
- package/dist/form/Legend.js.map +1 -1
- package/dist/form/Listbox.js.map +1 -1
- package/dist/form/ListboxProvider.js.map +1 -1
- package/dist/form/NativeSelect.js.map +1 -1
- package/dist/form/Password.js.map +1 -1
- package/dist/form/ResizingTextAreaWrapper.js.map +1 -1
- package/dist/form/Select.js.map +1 -1
- package/dist/form/Slider.js.map +1 -1
- package/dist/form/SliderContainer.js.map +1 -1
- package/dist/form/SliderThumb.js.map +1 -1
- package/dist/form/SliderTrack.js.map +1 -1
- package/dist/form/SliderValueMarks.js.map +1 -1
- package/dist/form/Switch.js.map +1 -1
- package/dist/form/TextArea.js.map +1 -1
- package/dist/form/TextField.js.map +1 -1
- package/dist/form/TextFieldContainer.js.map +1 -1
- package/dist/form/_fieldset.scss +7 -0
- package/dist/form/_legend.scss +68 -0
- package/dist/form/_text-field.scss +39 -4
- package/dist/form/fieldsetStyles.d.ts +6 -1
- package/dist/form/fieldsetStyles.js +3 -2
- package/dist/form/fieldsetStyles.js.map +1 -1
- package/dist/form/inputToggleStyles.js.map +1 -1
- package/dist/form/labelStyles.d.ts +1 -1
- package/dist/form/labelStyles.js +1 -1
- package/dist/form/labelStyles.js.map +1 -1
- package/dist/form/legendStyles.d.ts +83 -0
- package/dist/form/legendStyles.js +25 -0
- package/dist/form/legendStyles.js.map +1 -0
- package/dist/form/selectUtils.js.map +1 -1
- package/dist/form/textFieldContainerStyles.js.map +1 -1
- package/dist/form/types.d.ts +28 -6
- package/dist/form/types.js.map +1 -1
- package/dist/form/useCheckboxGroup.js.map +1 -1
- package/dist/form/useCombobox.js.map +1 -1
- package/dist/form/useNumberField.js +16 -19
- package/dist/form/useNumberField.js.map +1 -1
- package/dist/form/useRangeSlider.js.map +1 -1
- package/dist/form/useSlider.js.map +1 -1
- package/dist/form/useTextField.js.map +1 -1
- package/dist/hoverMode/useHoverMode.js.map +1 -1
- package/dist/icon/FontIcon.js.map +1 -1
- package/dist/icon/IconRotator.js.map +1 -1
- package/dist/icon/MaterialIcon.js.map +1 -1
- package/dist/icon/MaterialSymbol.js.map +1 -1
- package/dist/icon/SVGIcon.js.map +1 -1
- package/dist/icon/config.d.ts +0 -1
- package/dist/icon/config.js +10 -7
- package/dist/icon/config.js.map +1 -1
- package/dist/icon/materialConfig.js.map +1 -1
- package/dist/icon/styles.js.map +1 -1
- package/dist/interaction/UserInteractionModeProvider.js +6 -4
- package/dist/interaction/UserInteractionModeProvider.js.map +1 -1
- package/dist/interaction/types.js.map +1 -1
- package/dist/interaction/useElementInteraction.js.map +1 -1
- package/dist/layout/LayoutAppBar.d.ts +6 -6
- package/dist/layout/LayoutAppBar.js +6 -6
- package/dist/layout/LayoutAppBar.js.map +1 -1
- package/dist/layout/LayoutNav.js.map +1 -1
- package/dist/layout/LayoutWindowSplitter.js.map +1 -1
- package/dist/layout/Main.js.map +1 -1
- package/dist/layout/useExpandableLayout.js +43 -0
- package/dist/layout/useExpandableLayout.js.map +1 -1
- package/dist/layout/useHorizontalLayoutTransition.js.map +1 -1
- package/dist/layout/useLayoutTree.js.map +1 -1
- package/dist/layout/useLayoutWindowSplitter.js.map +1 -1
- package/dist/layout/useResizableLayout.js.map +1 -1
- package/dist/link/Link.js.map +1 -1
- package/dist/link/SkipToMainContent.js +19 -21
- package/dist/link/SkipToMainContent.js.map +1 -1
- package/dist/list/List.js.map +1 -1
- package/dist/list/ListItem.js.map +1 -1
- package/dist/list/ListItemAddon.js.map +1 -1
- package/dist/list/ListItemLink.js.map +1 -1
- package/dist/list/ListSubheader.js.map +1 -1
- package/dist/list/getListItemHeight.js.map +1 -1
- package/dist/list/listItemStyles.js.map +1 -1
- package/dist/list/types.js.map +1 -1
- package/dist/media-queries/AppSizeProvider.d.ts +2 -0
- package/dist/media-queries/AppSizeProvider.js +3 -2
- package/dist/media-queries/AppSizeProvider.js.map +1 -1
- package/dist/media-queries/appSize.d.ts +3 -0
- package/dist/media-queries/appSize.js +3 -1
- package/dist/media-queries/appSize.js.map +1 -1
- package/dist/media-queries/config.d.ts +11 -0
- package/dist/media-queries/config.js +26 -0
- package/dist/media-queries/config.js.map +1 -0
- package/dist/menu/DropdownMenu.js.map +1 -1
- package/dist/menu/Menu.js.map +1 -1
- package/dist/menu/MenuItemButton.js.map +1 -1
- package/dist/menu/MenuItemFileInput.js.map +1 -1
- package/dist/menu/MenuItemInputToggle.js.map +1 -1
- package/dist/menu/MenuItemSeparator.js.map +1 -1
- package/dist/menu/MenuVisibilityProvider.js.map +1 -1
- package/dist/menu/MenuWidget.js.map +1 -1
- package/dist/menu/useContextMenu.js.map +1 -1
- package/dist/movement/types.d.ts +28 -3
- package/dist/movement/types.js.map +1 -1
- package/dist/movement/useKeyboardMovementProvider.js +96 -47
- package/dist/movement/useKeyboardMovementProvider.js.map +1 -1
- package/dist/navigation/CollapsibleNavGroup.js.map +1 -1
- package/dist/navigation/NavItem.js.map +1 -1
- package/dist/navigation/NavItemButton.js.map +1 -1
- package/dist/navigation/NavItemLink.js.map +1 -1
- package/dist/navigation/getTableOfContentsHeadings.js.map +1 -1
- package/dist/navigation/types.js.map +1 -1
- package/dist/overlay/Overlay.js.map +1 -1
- package/dist/positioning/createHorizontalPosition.js.map +1 -1
- package/dist/positioning/createVerticalPosition.js.map +1 -1
- package/dist/positioning/useFixedPositioning.js.map +1 -1
- package/dist/progress/CircularProgress.js.map +1 -1
- package/dist/progress/LinearProgress.js.map +1 -1
- package/dist/progress/linearProgressStyles.js.map +1 -1
- package/dist/responsive-item/ResponsiveItem.js.map +1 -1
- package/dist/responsive-item/ResponsiveItemOverlay.js.map +1 -1
- package/dist/searching/caseInsensitive.js.map +1 -1
- package/dist/segmented-button/SegmentedButton.js.map +1 -1
- package/dist/segmented-button/SegmentedButtonContainer.js.map +1 -1
- package/dist/segmented-button/segmentedButtonStyles.js.map +1 -1
- package/dist/sheet/Sheet.js.map +1 -1
- package/dist/snackbar/Toast.js.map +1 -1
- package/dist/spinbutton/SpinButton.d.ts +16 -0
- package/dist/spinbutton/SpinButton.js +55 -0
- package/dist/spinbutton/SpinButton.js.map +1 -0
- package/dist/spinbutton/SpinButtonGroupProvider.d.ts +17 -0
- package/dist/spinbutton/SpinButtonGroupProvider.js +19 -0
- package/dist/spinbutton/SpinButtonGroupProvider.js.map +1 -0
- package/dist/spinbutton/defaults.d.ts +9 -0
- package/dist/spinbutton/defaults.js +25 -0
- package/dist/spinbutton/defaults.js.map +1 -0
- package/dist/spinbutton/types.d.ts +324 -0
- package/dist/spinbutton/types.js +5 -0
- package/dist/spinbutton/types.js.map +1 -0
- package/dist/spinbutton/useSpinButton.d.ts +5 -0
- package/dist/spinbutton/useSpinButton.js +260 -0
- package/dist/spinbutton/useSpinButton.js.map +1 -0
- package/dist/spinbutton/useSpinButtonGroupProvider.d.ts +27 -0
- package/dist/spinbutton/useSpinButtonGroupProvider.js +49 -0
- package/dist/spinbutton/useSpinButtonGroupProvider.js.map +1 -0
- package/dist/spinbutton/utils/deselectNode.d.ts +5 -0
- package/dist/spinbutton/utils/deselectNode.js +17 -0
- package/dist/spinbutton/utils/deselectNode.js.map +1 -0
- package/dist/spinbutton/utils/resolveInputEvent.d.ts +30 -0
- package/dist/spinbutton/utils/resolveInputEvent.js +53 -0
- package/dist/spinbutton/utils/resolveInputEvent.js.map +1 -0
- package/dist/spinbutton/utils/selectNode.d.ts +5 -0
- package/dist/spinbutton/utils/selectNode.js +15 -0
- package/dist/spinbutton/utils/selectNode.js.map +1 -0
- package/dist/table/StickyTableSection.js.map +1 -1
- package/dist/table/Table.js.map +1 -1
- package/dist/table/TableBody.js.map +1 -1
- package/dist/table/TableCellContent.js.map +1 -1
- package/dist/table/TableCheckbox.js.map +1 -1
- package/dist/table/TableFooter.js.map +1 -1
- package/dist/table/TableHeader.js.map +1 -1
- package/dist/table/TableRadio.js.map +1 -1
- package/dist/table/TableRow.js.map +1 -1
- package/dist/table/useStickyTableSection.js.map +1 -1
- package/dist/tabs/SimpleTabPanel.js.map +1 -1
- package/dist/tabs/SimpleTabPanels.js.map +1 -1
- package/dist/tabs/Tab.js.map +1 -1
- package/dist/tabs/TabList.js.map +1 -1
- package/dist/tabs/TabListScrollButton.js.map +1 -1
- package/dist/tabs/useMaxTabPanelHeight.js.map +1 -1
- package/dist/test-utils/data-testid.js.map +1 -1
- package/dist/test-utils/mocks/match-media.js +5 -5
- package/dist/test-utils/mocks/match-media.js.map +1 -1
- package/dist/test-utils/vitest/timers.d.ts +1 -1
- package/dist/test-utils/vitest/timers.js +1 -1
- package/dist/test-utils/vitest/timers.js.map +1 -1
- package/dist/tooltip/Tooltip.js.map +1 -1
- package/dist/tooltip/TooltipHoverModeProvider.js.map +1 -1
- package/dist/tooltip/useTooltip.js.map +1 -1
- package/dist/transition/CSSTransition.js.map +1 -1
- package/dist/transition/Collapse.js.map +1 -1
- package/dist/transition/CrossFade.js.map +1 -1
- package/dist/transition/ScaleTransition.js.map +1 -1
- package/dist/transition/SkeletonPlaceholder.js.map +1 -1
- package/dist/transition/Slide.js.map +1 -1
- package/dist/transition/SlideContainer.js.map +1 -1
- package/dist/transition/types.js.map +1 -1
- package/dist/transition/useCollapseTransition.js.map +1 -1
- package/dist/transition/useCrossFadeTransition.js.map +1 -1
- package/dist/transition/useMaxWidthTransition.js.map +1 -1
- package/dist/transition/useScaleTransition.js.map +1 -1
- package/dist/transition/useSkeletonPlaceholder.js.map +1 -1
- package/dist/tree/Tree.js.map +1 -1
- package/dist/tree/TreeItem.js.map +1 -1
- package/dist/tree/TreeProvider.js.map +1 -1
- package/dist/tree/styles.js.map +1 -1
- package/dist/tree/types.js.map +1 -1
- package/dist/tree/useTreeMovement.js.map +1 -1
- package/dist/typography/HighlightTextMark.js.map +1 -1
- package/dist/typography/Mark.js.map +1 -1
- package/dist/typography/TextContainer.js.map +1 -1
- package/dist/typography/Typography.js.map +1 -1
- package/dist/typography/_typography.scss +0 -1
- package/dist/useElementSize.js.map +1 -1
- package/dist/useIntersectionObserver.js.map +1 -1
- package/dist/useMutationObserver.js.map +1 -1
- package/dist/useWindowSize.js.map +1 -1
- package/dist/utils/getNumberOfDigits.d.ts +7 -0
- package/dist/utils/getNumberOfDigits.js +11 -0
- package/dist/utils/getNumberOfDigits.js.map +1 -0
- package/dist/utils/nearest.js +2 -1
- package/dist/utils/nearest.js.map +1 -1
- package/dist/utils/useDevEffect.d.ts +7 -0
- package/dist/utils/useDevEffect.js +8 -0
- package/dist/utils/useDevEffect.js.map +1 -0
- package/dist/window-splitter/WindowSplitter.js +3 -2
- package/dist/window-splitter/WindowSplitter.js.map +1 -1
- package/dist/window-splitter/_window-splitter.scss +60 -12
- package/dist/window-splitter/styles.d.ts +9 -0
- package/dist/window-splitter/styles.js +3 -2
- package/dist/window-splitter/styles.js.map +1 -1
- package/dist/window-splitter/useWindowSplitter.js.map +1 -1
- package/package.json +37 -29
- package/src/CoreProviders.tsx +1 -0
- package/src/app-bar/AppBar.tsx +1 -2
- package/src/app-bar/AppBarTitle.tsx +1 -2
- package/src/autocomplete/AutocompleteListboxChildren.tsx +3 -1
- package/src/autocomplete/types.ts +24 -19
- package/src/autocomplete/utils.ts +9 -6
- package/src/avatar/Avatar.tsx +2 -1
- package/src/button/Button.tsx +2 -1
- package/src/button/FloatingActionButton.tsx +2 -1
- package/src/card/Card.tsx +2 -1
- package/src/card/CardContent.tsx +1 -2
- package/src/card/ClickableCard.tsx +1 -2
- package/src/chip/Chip.tsx +2 -1
- package/src/datetime/NativeDateField.tsx +2 -1
- package/src/datetime/NativeTimeField.tsx +2 -1
- package/src/datetime/useDateField.ts +13 -8
- package/src/datetime/useTimeField.ts +13 -8
- package/src/dialog/Dialog.tsx +2 -1
- package/src/dialog/DialogContainer.tsx +1 -2
- package/src/dialog/DialogContent.tsx +1 -2
- package/src/dialog/DialogFooter.tsx +1 -2
- package/src/divider/Divider.tsx +1 -2
- package/src/draggable/useDraggable.ts +4 -4
- package/src/draggable/utils.ts +4 -2
- package/src/expansion-panel/ExpansionPanelHeader.tsx +1 -2
- package/src/files/FileInput.tsx +2 -1
- package/src/files/useFileUpload.ts +6 -6
- package/src/files/validation.ts +1 -2
- package/src/focus/useFocusContainer.ts +4 -4
- package/src/form/Fieldset.tsx +25 -3
- package/src/form/FormMessageContainer.tsx +1 -2
- package/src/form/FormMessageCounter.tsx +1 -2
- package/src/form/InputToggle.tsx +3 -3
- package/src/form/Legend.tsx +55 -10
- package/src/form/Listbox.tsx +1 -2
- package/src/form/ListboxProvider.ts +3 -2
- package/src/form/NativeSelect.tsx +2 -1
- package/src/form/Password.tsx +4 -2
- package/src/form/ResizingTextAreaWrapper.tsx +1 -2
- package/src/form/Select.tsx +2 -1
- package/src/form/Slider.tsx +2 -1
- package/src/form/SliderContainer.tsx +1 -2
- package/src/form/SliderThumb.tsx +6 -3
- package/src/form/SliderTrack.tsx +2 -1
- package/src/form/SliderValueMarks.tsx +1 -2
- package/src/form/Switch.tsx +2 -1
- package/src/form/TextArea.tsx +1 -2
- package/src/form/TextField.tsx +2 -1
- package/src/form/TextFieldContainer.tsx +1 -2
- package/src/form/fieldsetStyles.ts +18 -3
- package/src/form/inputToggleStyles.ts +4 -2
- package/src/form/labelStyles.ts +1 -1
- package/src/form/legendStyles.ts +132 -0
- package/src/form/selectUtils.ts +3 -2
- package/src/form/textFieldContainerStyles.ts +1 -2
- package/src/form/types.ts +35 -17
- package/src/form/useCheckboxGroup.ts +3 -2
- package/src/form/useCombobox.ts +8 -3
- package/src/form/useNumberField.ts +36 -35
- package/src/form/useRangeSlider.ts +1 -2
- package/src/form/useSlider.ts +1 -2
- package/src/form/useTextField.ts +8 -3
- package/src/hoverMode/useHoverMode.ts +4 -8
- package/src/icon/FontIcon.tsx +1 -2
- package/src/icon/IconRotator.tsx +1 -2
- package/src/icon/MaterialIcon.tsx +2 -1
- package/src/icon/MaterialSymbol.tsx +2 -1
- package/src/icon/SVGIcon.tsx +1 -2
- package/src/icon/config.tsx +10 -7
- package/src/icon/materialConfig.ts +1 -2
- package/src/icon/styles.ts +1 -2
- package/src/interaction/UserInteractionModeProvider.tsx +9 -4
- package/src/interaction/types.ts +1 -2
- package/src/interaction/useElementInteraction.tsx +3 -2
- package/src/layout/LayoutAppBar.tsx +6 -6
- package/src/layout/LayoutNav.tsx +2 -1
- package/src/layout/LayoutWindowSplitter.tsx +2 -1
- package/src/layout/Main.tsx +1 -2
- package/src/layout/useExpandableLayout.ts +63 -5
- package/src/layout/useHorizontalLayoutTransition.ts +1 -2
- package/src/layout/useLayoutTree.ts +2 -2
- package/src/layout/useLayoutWindowSplitter.ts +6 -6
- package/src/layout/useResizableLayout.ts +3 -6
- package/src/link/Link.tsx +1 -2
- package/src/link/SkipToMainContent.tsx +20 -23
- package/src/list/List.tsx +1 -2
- package/src/list/ListItem.tsx +2 -1
- package/src/list/ListItemAddon.tsx +2 -1
- package/src/list/ListItemLink.tsx +2 -1
- package/src/list/ListSubheader.tsx +1 -2
- package/src/list/getListItemHeight.ts +8 -9
- package/src/list/listItemStyles.ts +1 -2
- package/src/list/types.ts +1 -2
- package/src/media-queries/AppSizeProvider.tsx +8 -10
- package/src/media-queries/appSize.ts +3 -0
- package/src/media-queries/config.ts +41 -0
- package/src/menu/DropdownMenu.tsx +4 -5
- package/src/menu/Menu.tsx +2 -1
- package/src/menu/MenuItemButton.tsx +1 -2
- package/src/menu/MenuItemFileInput.tsx +2 -1
- package/src/menu/MenuItemInputToggle.tsx +3 -3
- package/src/menu/MenuItemSeparator.tsx +2 -1
- package/src/menu/MenuVisibilityProvider.tsx +4 -2
- package/src/menu/MenuWidget.tsx +1 -2
- package/src/menu/useContextMenu.ts +4 -2
- package/src/movement/types.ts +52 -13
- package/src/movement/useKeyboardMovementProvider.ts +77 -38
- package/src/navigation/CollapsibleNavGroup.tsx +1 -2
- package/src/navigation/NavItem.tsx +1 -2
- package/src/navigation/NavItemButton.tsx +2 -1
- package/src/navigation/NavItemLink.tsx +2 -1
- package/src/navigation/getTableOfContentsHeadings.ts +1 -2
- package/src/navigation/types.ts +1 -2
- package/src/overlay/Overlay.tsx +2 -1
- package/src/positioning/createHorizontalPosition.ts +10 -12
- package/src/positioning/createVerticalPosition.ts +10 -11
- package/src/positioning/useFixedPositioning.ts +6 -3
- package/src/progress/CircularProgress.tsx +2 -1
- package/src/progress/LinearProgress.tsx +2 -1
- package/src/progress/linearProgressStyles.ts +1 -2
- package/src/responsive-item/ResponsiveItem.tsx +1 -2
- package/src/responsive-item/ResponsiveItemOverlay.tsx +2 -1
- package/src/searching/caseInsensitive.ts +2 -4
- package/src/segmented-button/SegmentedButton.tsx +2 -1
- package/src/segmented-button/SegmentedButtonContainer.tsx +2 -1
- package/src/segmented-button/segmentedButtonStyles.ts +1 -2
- package/src/sheet/Sheet.tsx +1 -2
- package/src/snackbar/Toast.tsx +2 -1
- package/src/spinbutton/SpinButton.tsx +98 -0
- package/src/spinbutton/SpinButtonGroupProvider.tsx +32 -0
- package/src/spinbutton/defaults.ts +45 -0
- package/src/spinbutton/types.ts +413 -0
- package/src/spinbutton/useSpinButton.ts +311 -0
- package/src/spinbutton/useSpinButtonGroupProvider.ts +104 -0
- package/src/spinbutton/utils/deselectNode.ts +17 -0
- package/src/spinbutton/utils/resolveInputEvent.ts +112 -0
- package/src/spinbutton/utils/selectNode.ts +15 -0
- package/src/table/StickyTableSection.tsx +2 -1
- package/src/table/Table.tsx +1 -2
- package/src/table/TableBody.tsx +2 -1
- package/src/table/TableCellContent.tsx +1 -2
- package/src/table/TableCheckbox.tsx +1 -2
- package/src/table/TableFooter.tsx +1 -2
- package/src/table/TableHeader.tsx +1 -2
- package/src/table/TableRadio.tsx +1 -2
- package/src/table/TableRow.tsx +1 -2
- package/src/table/useStickyTableSection.tsx +1 -2
- package/src/tabs/SimpleTabPanel.tsx +2 -1
- package/src/tabs/SimpleTabPanels.tsx +2 -1
- package/src/tabs/Tab.tsx +3 -6
- package/src/tabs/TabList.tsx +2 -1
- package/src/tabs/TabListScrollButton.tsx +1 -2
- package/src/tabs/useMaxTabPanelHeight.ts +7 -4
- package/src/test-utils/data-testid.ts +1 -2
- package/src/test-utils/mocks/match-media.ts +5 -10
- package/src/test-utils/vitest/timers.ts +1 -1
- package/src/tooltip/Tooltip.tsx +2 -1
- package/src/tooltip/TooltipHoverModeProvider.tsx +1 -2
- package/src/tooltip/useTooltip.ts +9 -5
- package/src/transition/CSSTransition.tsx +2 -1
- package/src/transition/Collapse.tsx +4 -2
- package/src/transition/CrossFade.tsx +2 -1
- package/src/transition/ScaleTransition.tsx +2 -1
- package/src/transition/SkeletonPlaceholder.tsx +1 -2
- package/src/transition/Slide.tsx +2 -1
- package/src/transition/SlideContainer.tsx +1 -2
- package/src/transition/types.ts +15 -16
- package/src/transition/useCollapseTransition.ts +6 -5
- package/src/transition/useCrossFadeTransition.ts +3 -2
- package/src/transition/useMaxWidthTransition.ts +1 -2
- package/src/transition/useScaleTransition.ts +3 -2
- package/src/transition/useSkeletonPlaceholder.ts +1 -2
- package/src/tree/Tree.tsx +2 -1
- package/src/tree/TreeItem.tsx +2 -1
- package/src/tree/TreeProvider.tsx +4 -4
- package/src/tree/styles.ts +1 -2
- package/src/tree/types.ts +1 -2
- package/src/tree/useTreeMovement.ts +1 -2
- package/src/typography/HighlightTextMark.tsx +1 -2
- package/src/typography/Mark.tsx +1 -2
- package/src/typography/TextContainer.tsx +1 -2
- package/src/typography/Typography.tsx +1 -2
- package/src/useElementSize.ts +7 -4
- package/src/useIntersectionObserver.ts +3 -2
- package/src/useMutationObserver.ts +3 -2
- package/src/useWindowSize.ts +4 -2
- package/src/utils/getNumberOfDigits.ts +18 -0
- package/src/utils/nearest.ts +2 -1
- package/src/utils/useDevEffect.ts +9 -0
- package/src/window-splitter/WindowSplitter.tsx +5 -2
- package/src/window-splitter/styles.ts +13 -2
- package/src/window-splitter/useWindowSplitter.ts +3 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/transition/useSkeletonPlaceholder.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type CSSProperties, useEffect, useState } from \"react\";\n\nimport { useSsr } from \"../SsrProvider.js\";\nimport {\n type SkeletonPlaceholderRandomOptions,\n randomSkeletonPlaceholder,\n skeletonPlaceholder,\n} from \"./skeletonPlaceholderUtils.js\";\n\n/** @since 6.0.0 */\nexport interface SkeletonPlaceholderOptions\n extends SkeletonPlaceholderRandomOptions {\n style?: CSSProperties;\n className?: string;\n\n /**\n * Set this to a custom `animation-delay` value (should be in milliseconds).\n *\n * @example\n * ```ts\n * delay=\"200ms\"\n * ```\n */\n delay?: string;\n\n /**\n * Set this value to a number or length unit string to set the height with\n * inline styles.\n *\n * If this is `undefined`, it will use the skeleton placeholder CSS variable\n * value instead which defaults to `1.125em`\n *\n * @defaultValue `undefined`\n */\n height?: string | number;\n\n /**\n * A custom width to apply to the skeleton placeholder.\n *\n * Set this value to an empty string if you want to control the width through\n * SCSS.\n *\n * @example No Inline Width CSS\n * ```scss\n * @use \"@react-md/core\";\n *\n * .customStyles {\n * // You could use these mixins on a parent element instead which would\n * // set the height and width to all skeleton placeholders that appear as a\n * // child instead\n * // @include core.transition-set-var(skeleton-placeholder-height, 1.5rem);\n * // @include core.transition-set-var(skeleton-placeholder-width, 40%);\n *\n * height: 1,5rem;\n * width: 40%;\n * }\n * ```\n *\n * @example No Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * import styles from \"./MyComponent.module.scss\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * width: null,\n * className: styles.customStyles,\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n *\n * Set this value to a number or length unit string to set the width with\n * inline styles.\n *\n * @example Custom Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * // any of these are valid\n * // width: 40,\n * // width: \"1rem\",\n * // width: \"1vh\",\n * // width: \"40%\",\n * width: \"1rem\",\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n * If this value is `undefined`, a random percentage will be generated instead\n * using the {@link minPercentage} and {@link maxPercentage} options.\n *\n * Set this value to `null` if the size should be derived from the provided\n * `className` instead.\n *\n * @defaultValue `randomInt({ min: minPercentage, max: maxPercentage })%`\n */\n width?: number | string | null;\n\n /**\n * Settings this to `true` will prevent any of the skeleton placeholder styles\n * to be applied. This is really only useful if you can prerender parts of\n * your layout while waiting for the data to load.\n *\n * @example Pre-rendered Layout\n * ```tsx\n * import type { ReactElement } from \"@react\";\n * import { SkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * interface Data {\n * id: string;\n * name: string;\n * createdBy: string\n * createdOn: string;\n * modifiedBy: string;\n * modifiedOn: string;\n * }\n *\n * function ShowData({\n * id,\n * name,\n * createdBy,\n * createdOn,\n * modifiedBy,\n * modifiedOn,\n * }: Partial<Data>:: ReactElement {\n * const loading =\n * !name &&\n * !createdBy &&\n * !createdOn &&\n * !modifiedBy &&\n * !modifiedOn;\n *\n * return (\n * <Box grid gridClassName=\"custom-class-name\">\n * <SkeletonPlaceholder disabled={!loading}>\n * {id}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {name}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdBy}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedBy}\n * </SkeletonPlaceholder>\n * </Box>\n * );\n * }\n *\n * export function Example(): ReactElement {\n * const { data } = useLoadSomeDataQuery();\n *\n * const items = useMemo(() => {\n * // if the data has been fetched, just return the data\n * if (data) {\n * return data;\n * }\n *\n * // if the data does not exist, set up a skeleton of your layout by\n * // rendering a random number of items.\n * //\n * // NOTE: This is memoized so you don't create a random length each\n * // render\n * const length = randomInt({ min: 3, max: 10 })\n * return Array.from({ length }, (_, i) => ({ id: `placeholder-${i}` }));\n * }, [data])\n *\n * return (\n * <List>\n * {items.map((item) => <ShowData {...item} />)}\n * </List>\n * );\n * }\n * ```\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface SkeletonPlaceholderStylingProps {\n style?: CSSProperties;\n className: string;\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n * import { type ReactElement } from \"react\";\n *\n * export default function UsingTheHookExample(): ReactElement {\n * const { style, className } = useSkeletonPlaceholder();\n * return <div style={style} className={className} />;\n * }\n * ```\n *\n * @see {@link https://react-md.dev/hooks/use-skeleton-placeholder-transition | useSkeletonPlaceholder Demos}\n * @see {@link https://react-md.dev/components/skeleton-placeholder | SkeletonPlaceholder Demos}\n * @since 6.0.0\n */\nexport function useSkeletonPlaceholder(\n options: SkeletonPlaceholderOptions = {}\n): SkeletonPlaceholderStylingProps {\n const {\n style: propStyle,\n className,\n height,\n width: propWidth,\n disabled = false,\n delay: propDelay,\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n } = options;\n const ssr = useSsr();\n\n const isDefinedWidth = typeof propWidth !== \"undefined\";\n const isDefinedDelay = typeof propDelay !== \"undefined\";\n const [randomStyles, setRandomStyles] = useState<CSSProperties>(() => {\n if (typeof window === \"undefined\" || ssr || disabled) {\n return {};\n }\n\n return randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n });\n });\n\n useEffect(() => {\n if (!ssr || disabled || (isDefinedDelay && isDefinedWidth)) {\n return;\n }\n\n setRandomStyles(\n randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n })\n );\n }, [\n disabled,\n isDefinedDelay,\n isDefinedWidth,\n maxDelay,\n maxPercentage,\n minDelay,\n minPercentage,\n ssr,\n ]);\n\n let width = propWidth;\n let animationDelay = propDelay;\n if (!disabled) {\n if (!isDefinedDelay) {\n ({ animationDelay } = randomStyles);\n }\n if (!isDefinedWidth) {\n ({ width } = randomStyles);\n }\n }\n\n let style: CSSProperties | undefined = propStyle;\n if (!!width || !!animationDelay || typeof height !== \"undefined\") {\n style = {\n ...style,\n height: height ?? style?.height,\n width: width ?? style?.width,\n // Note: not including MozAnimationDelay and WebkitAnimationDelay since\n // they weren't applied when they were set. Probably no longer required?\n animationDelay: animationDelay ?? style?.animationDelay,\n };\n }\n\n return {\n style,\n className: cnb(className, !disabled && skeletonPlaceholder()),\n };\n}\n"],"names":["cnb","useEffect","useState","useSsr","randomSkeletonPlaceholder","skeletonPlaceholder","useSkeletonPlaceholder","options","style","propStyle","className","height","width","propWidth","disabled","delay","propDelay","minDelay","maxDelay","minPercentage","maxPercentage","ssr","isDefinedWidth","isDefinedDelay","randomStyles","setRandomStyles","window","animationDelay"],"mappings":"AAAA;AAEA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAA6BC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAEhE,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAEEC,yBAAyB,EACzBC,mBAAmB,QACd,gCAAgC;AAsMvC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASC,uBACdC,UAAsC,CAAC,CAAC;IAExC,MAAM,EACJC,OAAOC,SAAS,EAChBC,SAAS,EACTC,MAAM,EACNC,OAAOC,SAAS,EAChBC,WAAW,KAAK,EAChBC,OAAOC,SAAS,EAChBC,QAAQ,EACRC,QAAQ,EACRC,aAAa,EACbC,aAAa,EACd,GAAGb;IACJ,MAAMc,MAAMlB;IAEZ,MAAMmB,iBAAiB,OAAOT,cAAc;IAC5C,MAAMU,iBAAiB,OAAOP,cAAc;IAC5C,MAAM,CAACQ,cAAcC,gBAAgB,GAAGvB,SAAwB;QAC9D,IAAI,OAAOwB,WAAW,eAAeL,OAAOP,UAAU;YACpD,OAAO,CAAC;QACV;QAEA,OAAOV,0BAA0B;YAC/Ba;YACAC;YACAC;YACAC;QACF;IACF;IAEAnB,UAAU;QACR,IAAI,CAACoB,OAAOP,YAAaS,kBAAkBD,gBAAiB;YAC1D;QACF;QAEAG,gBACErB,0BAA0B;YACxBa;YACAC;YACAC;YACAC;QACF;IAEJ,GAAG;QACDN;QACAS;QACAD;QACAJ;QACAE;QACAH;QACAE;QACAE;KACD;IAED,IAAIT,QAAQC;IACZ,IAAIc,iBAAiBX;IACrB,IAAI,CAACF,UAAU;QACb,IAAI,CAACS,gBAAgB;YAClB,CAAA,EAAEI,cAAc,EAAE,GAAGH,YAAW;QACnC;QACA,IAAI,CAACF,gBAAgB;YAClB,CAAA,EAAEV,KAAK,EAAE,GAAGY,YAAW;QAC1B;IACF;IAEA,IAAIhB,QAAmCC;IACvC,IAAI,CAAC,CAACG,SAAS,CAAC,CAACe,kBAAkB,OAAOhB,WAAW,aAAa;QAChEH,QAAQ;YACN,GAAGA,KAAK;YACRG,QAAQA,UAAUH,OAAOG;YACzBC,OAAOA,SAASJ,OAAOI;YACvB,uEAAuE;YACvE,wEAAwE;YACxEe,gBAAgBA,kBAAkBnB,OAAOmB;QAC3C;IACF;IAEA,OAAO;QACLnB;QACAE,WAAWV,IAAIU,WAAW,CAACI,YAAYT;IACzC;AACF"}
|
|
1
|
+
{"version":3,"sources":["../../src/transition/useSkeletonPlaceholder.ts"],"sourcesContent":["\"use client\";\n\nimport { cnb } from \"cnbuilder\";\nimport { type CSSProperties, useEffect, useState } from \"react\";\n\nimport { useSsr } from \"../SsrProvider.js\";\nimport {\n type SkeletonPlaceholderRandomOptions,\n randomSkeletonPlaceholder,\n skeletonPlaceholder,\n} from \"./skeletonPlaceholderUtils.js\";\n\n/** @since 6.0.0 */\nexport interface SkeletonPlaceholderOptions extends SkeletonPlaceholderRandomOptions {\n style?: CSSProperties;\n className?: string;\n\n /**\n * Set this to a custom `animation-delay` value (should be in milliseconds).\n *\n * @example\n * ```ts\n * delay=\"200ms\"\n * ```\n */\n delay?: string;\n\n /**\n * Set this value to a number or length unit string to set the height with\n * inline styles.\n *\n * If this is `undefined`, it will use the skeleton placeholder CSS variable\n * value instead which defaults to `1.125em`\n *\n * @defaultValue `undefined`\n */\n height?: string | number;\n\n /**\n * A custom width to apply to the skeleton placeholder.\n *\n * Set this value to an empty string if you want to control the width through\n * SCSS.\n *\n * @example No Inline Width CSS\n * ```scss\n * @use \"@react-md/core\";\n *\n * .customStyles {\n * // You could use these mixins on a parent element instead which would\n * // set the height and width to all skeleton placeholders that appear as a\n * // child instead\n * // @include core.transition-set-var(skeleton-placeholder-height, 1.5rem);\n * // @include core.transition-set-var(skeleton-placeholder-width, 40%);\n *\n * height: 1,5rem;\n * width: 40%;\n * }\n * ```\n *\n * @example No Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * import styles from \"./MyComponent.module.scss\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * width: null,\n * className: styles.customStyles,\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n *\n * Set this value to a number or length unit string to set the width with\n * inline styles.\n *\n * @example Custom Inline Width\n * ```ts\n * import type { ReactElement } from \"@react\";\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * export function Example(): ReactElement {\n * const skeletonProps = useSkeletonPlaceholder({\n * // any of these are valid\n * // width: 40,\n * // width: \"1rem\",\n * // width: \"1vh\",\n * // width: \"40%\",\n * width: \"1rem\",\n * });\n *\n * return <div {...skeletonProps} />;\n * }\n * ```\n *\n * If this value is `undefined`, a random percentage will be generated instead\n * using the {@link minPercentage} and {@link maxPercentage} options.\n *\n * Set this value to `null` if the size should be derived from the provided\n * `className` instead.\n *\n * @defaultValue `randomInt({ min: minPercentage, max: maxPercentage })%`\n */\n width?: number | string | null;\n\n /**\n * Settings this to `true` will prevent any of the skeleton placeholder styles\n * to be applied. This is really only useful if you can prerender parts of\n * your layout while waiting for the data to load.\n *\n * @example Pre-rendered Layout\n * ```tsx\n * import type { ReactElement } from \"@react\";\n * import { SkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n *\n * interface Data {\n * id: string;\n * name: string;\n * createdBy: string\n * createdOn: string;\n * modifiedBy: string;\n * modifiedOn: string;\n * }\n *\n * function ShowData({\n * id,\n * name,\n * createdBy,\n * createdOn,\n * modifiedBy,\n * modifiedOn,\n * }: Partial<Data>:: ReactElement {\n * const loading =\n * !name &&\n * !createdBy &&\n * !createdOn &&\n * !modifiedBy &&\n * !modifiedOn;\n *\n * return (\n * <Box grid gridClassName=\"custom-class-name\">\n * <SkeletonPlaceholder disabled={!loading}>\n * {id}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {name}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {createdBy}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedOn}\n * </SkeletonPlaceholder>\n * <SkeletonPlaceholder disabled={!loading}>\n * {modifiedBy}\n * </SkeletonPlaceholder>\n * </Box>\n * );\n * }\n *\n * export function Example(): ReactElement {\n * const { data } = useLoadSomeDataQuery();\n *\n * const items = useMemo(() => {\n * // if the data has been fetched, just return the data\n * if (data) {\n * return data;\n * }\n *\n * // if the data does not exist, set up a skeleton of your layout by\n * // rendering a random number of items.\n * //\n * // NOTE: This is memoized so you don't create a random length each\n * // render\n * const length = randomInt({ min: 3, max: 10 })\n * return Array.from({ length }, (_, i) => ({ id: `placeholder-${i}` }));\n * }, [data])\n *\n * return (\n * <List>\n * {items.map((item) => <ShowData {...item} />)}\n * </List>\n * );\n * }\n * ```\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface SkeletonPlaceholderStylingProps {\n style?: CSSProperties;\n className: string;\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * import { useSkeletonPlaceholder } from \"@react-md/core/transition/useSkeletonPlaceholder\";\n * import { type ReactElement } from \"react\";\n *\n * export default function UsingTheHookExample(): ReactElement {\n * const { style, className } = useSkeletonPlaceholder();\n * return <div style={style} className={className} />;\n * }\n * ```\n *\n * @see {@link https://react-md.dev/hooks/use-skeleton-placeholder-transition | useSkeletonPlaceholder Demos}\n * @see {@link https://react-md.dev/components/skeleton-placeholder | SkeletonPlaceholder Demos}\n * @since 6.0.0\n */\nexport function useSkeletonPlaceholder(\n options: SkeletonPlaceholderOptions = {}\n): SkeletonPlaceholderStylingProps {\n const {\n style: propStyle,\n className,\n height,\n width: propWidth,\n disabled = false,\n delay: propDelay,\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n } = options;\n const ssr = useSsr();\n\n const isDefinedWidth = typeof propWidth !== \"undefined\";\n const isDefinedDelay = typeof propDelay !== \"undefined\";\n const [randomStyles, setRandomStyles] = useState<CSSProperties>(() => {\n if (typeof window === \"undefined\" || ssr || disabled) {\n return {};\n }\n\n return randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n });\n });\n\n useEffect(() => {\n if (!ssr || disabled || (isDefinedDelay && isDefinedWidth)) {\n return;\n }\n\n setRandomStyles(\n randomSkeletonPlaceholder({\n minDelay,\n maxDelay,\n minPercentage,\n maxPercentage,\n })\n );\n }, [\n disabled,\n isDefinedDelay,\n isDefinedWidth,\n maxDelay,\n maxPercentage,\n minDelay,\n minPercentage,\n ssr,\n ]);\n\n let width = propWidth;\n let animationDelay = propDelay;\n if (!disabled) {\n if (!isDefinedDelay) {\n ({ animationDelay } = randomStyles);\n }\n if (!isDefinedWidth) {\n ({ width } = randomStyles);\n }\n }\n\n let style: CSSProperties | undefined = propStyle;\n if (!!width || !!animationDelay || typeof height !== \"undefined\") {\n style = {\n ...style,\n height: height ?? style?.height,\n width: width ?? style?.width,\n // Note: not including MozAnimationDelay and WebkitAnimationDelay since\n // they weren't applied when they were set. Probably no longer required?\n animationDelay: animationDelay ?? style?.animationDelay,\n };\n }\n\n return {\n style,\n className: cnb(className, !disabled && skeletonPlaceholder()),\n };\n}\n"],"names":["cnb","useEffect","useState","useSsr","randomSkeletonPlaceholder","skeletonPlaceholder","useSkeletonPlaceholder","options","style","propStyle","className","height","width","propWidth","disabled","delay","propDelay","minDelay","maxDelay","minPercentage","maxPercentage","ssr","isDefinedWidth","isDefinedDelay","randomStyles","setRandomStyles","window","animationDelay"],"mappings":"AAAA;AAEA,SAASA,GAAG,QAAQ,YAAY;AAChC,SAA6BC,SAAS,EAAEC,QAAQ,QAAQ,QAAQ;AAEhE,SAASC,MAAM,QAAQ,oBAAoB;AAC3C,SAEEC,yBAAyB,EACzBC,mBAAmB,QACd,gCAAgC;AAqMvC;;;;;;;;;;;;;;;CAeC,GACD,OAAO,SAASC,uBACdC,UAAsC,CAAC,CAAC;IAExC,MAAM,EACJC,OAAOC,SAAS,EAChBC,SAAS,EACTC,MAAM,EACNC,OAAOC,SAAS,EAChBC,WAAW,KAAK,EAChBC,OAAOC,SAAS,EAChBC,QAAQ,EACRC,QAAQ,EACRC,aAAa,EACbC,aAAa,EACd,GAAGb;IACJ,MAAMc,MAAMlB;IAEZ,MAAMmB,iBAAiB,OAAOT,cAAc;IAC5C,MAAMU,iBAAiB,OAAOP,cAAc;IAC5C,MAAM,CAACQ,cAAcC,gBAAgB,GAAGvB,SAAwB;QAC9D,IAAI,OAAOwB,WAAW,eAAeL,OAAOP,UAAU;YACpD,OAAO,CAAC;QACV;QAEA,OAAOV,0BAA0B;YAC/Ba;YACAC;YACAC;YACAC;QACF;IACF;IAEAnB,UAAU;QACR,IAAI,CAACoB,OAAOP,YAAaS,kBAAkBD,gBAAiB;YAC1D;QACF;QAEAG,gBACErB,0BAA0B;YACxBa;YACAC;YACAC;YACAC;QACF;IAEJ,GAAG;QACDN;QACAS;QACAD;QACAJ;QACAE;QACAH;QACAE;QACAE;KACD;IAED,IAAIT,QAAQC;IACZ,IAAIc,iBAAiBX;IACrB,IAAI,CAACF,UAAU;QACb,IAAI,CAACS,gBAAgB;YAClB,CAAA,EAAEI,cAAc,EAAE,GAAGH,YAAW;QACnC;QACA,IAAI,CAACF,gBAAgB;YAClB,CAAA,EAAEV,KAAK,EAAE,GAAGY,YAAW;QAC1B;IACF;IAEA,IAAIhB,QAAmCC;IACvC,IAAI,CAAC,CAACG,SAAS,CAAC,CAACe,kBAAkB,OAAOhB,WAAW,aAAa;QAChEH,QAAQ;YACN,GAAGA,KAAK;YACRG,QAAQA,UAAUH,OAAOG;YACzBC,OAAOA,SAASJ,OAAOI;YACvB,uEAAuE;YACvE,wEAAwE;YACxEe,gBAAgBA,kBAAkBnB,OAAOmB;QAC3C;IACF;IAEA,OAAO;QACLnB;QACAE,WAAWV,IAAIU,WAAW,CAACI,YAAYT;IACzC;AACF"}
|
package/dist/tree/Tree.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/Tree.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { List } from \"../list/List.js\";\nimport { KeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type LabelRequiredForA11y } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { RenderRecursively } from \"../utils/RenderRecursively.js\";\nimport { identity } from \"../utils/identity.js\";\nimport { DefaultTreeItemRenderer } from \"./DefaultTreeItemRenderer.js\";\nimport { type TreeExpansionMode, TreeProvider } from \"./TreeProvider.js\";\nimport { type TreeClassNameOptions, tree } from \"./styles.js\";\nimport {\n type TreeData,\n type TreeItemNode,\n type TreeItemRendererProps,\n type TreeItemSorter,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { useTreeItems } from \"./useTreeItems.js\";\nimport { useTreeMovement } from \"./useTreeMovement.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * @since 6.0.0\n */\nexport type TreeHTMLAttributes = Omit<\n HTMLAttributes<HTMLUListElement>,\n \"role\" | \"tabIndex\" | \"children\"\n>;\n\n/**\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n *\n * @since 6.3.1 Extends TreeClassNameOptions for CSSProperties module\n * augmentation.\n */\nexport interface TreeProps<T extends TreeItemNode>\n extends TreeHTMLAttributes,\n TreeClassNameOptions,\n TreeExpansion,\n TreeSelection {\n /** @see {@link TreeData} */\n data: TreeData<T>;\n\n /**\n * An optional ref to pass to the tree element.\n *\n * @since 6.0.0\n */\n treeRef?: Ref<HTMLUListElement>;\n\n /** @defaultValue `identity` */\n sort?: TreeItemSorter<T>;\n\n /**\n * Any nodes in the {@link data} that have a `parentId` set to this value will\n * appear at the root of the tree.\n *\n * @defaultValue `null`\n */\n rootId?: string | null;\n\n /**\n * @defaultValue `\"auto\"`\n * @see {@link TreeExpansionMode}\n */\n expansionMode?: TreeExpansionMode;\n\n /**\n * Set this to `true` to display the expander icon to the left instead of the\n * right. This will also update the styles slightly so you can still provide a\n * `leftAddon`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n\n /**\n * @defaultValue `getIcon(\"expander\")`\n */\n expanderIcon?: ReactNode;\n\n /**\n * Set this to `true` to disable the collapse transition for all tree items.\n *\n * @defaultValue `false`\n */\n disableTransition?: boolean;\n\n /**\n * Set this to `true` if the collapsed tree items should be removed from the\n * DOM instead of hidden using `display: none`. This _might_ improve\n * performance for large trees.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n\n /**\n * @example Custom Tree Item Renderer\n * ```tsx\n * import { useTreeContext } from \"@react-md/core/movement/TreeProvider\"\n * import { useKeyboardMovementContext } from \"@react-md/core/movement/useKeyboardMovementProvider\"\n * import { TreeItem } from \"@react-md/core/tree/TreeItem\";\n * import { type TreeItemRendererProps } from \"@react-md/core/tree/types\";\n * import FolderIcon from \"@react-md/material-icons/FolderIcon\";\n * import FolderOpenIcon from \"@react-md/material-icons/FolderOpenIcon\";\n * import { type ReactElement } from \"react\";\n *\n * export function CustomTreeItem(props: TreeItemRendererProps): ReactElement {\n * const { item, ...remaining } = props;\n * const id = useId();\n * const { itemId } = item;\n * const {\n * data,\n * expandedIds,\n * selectedIds,\n * toggleTreeItemExpansion,\n * toggleTreeItemSelection,\n * } = useTreeContext()\n * const { activeDescendantId } = useKeyboardMovementContext();\n *\n * const focused = id === activeDescendantId;\n * const expanded = expandedIds.has(itemId);\n * const selected = selectedIds.has(itemId);\n * const children = ...; // do whatever\n *\n * return (\n * <TreeItem\n * {...remaining}\n * id={id}\n * itemId={itemId}\n * leftAddon={expanded ? <FolderOpenIcon /> : <FolderIcon />}\n * >\n * {children}\n * </TreeItem>\n * );\n * }\n * ```\n *\n * @see {@link DefaultTreeItemRenderer}\n * @defaultValue `DefaultTreeItemRenderer`\n */\n renderer?: ComponentType<TreeItemRendererProps<T>>;\n\n /**\n * The link component to use for any tree item nodes that have a `to` or\n * `href`.\n *\n * @see {@link CustomLinkComponent}\n * @defaultValue `Link`\n */\n linkComponent?: CustomLinkComponent;\n}\n\n/**\n * **Client Component**\n *\n * @example Simple Tree\n * ```tsx\n * import { Tree } from \"@react-md/core/tree/Tree\";\n * import { type TreeData } from \"@react-md/core/tree/types\";\n * import { useTree } from \"@react-md/core/tree/useTree\";\n * import type { ReactElement } from \"react\";\n *\n * const data: TreeData = {\n * \"item-1\": {\n * itemId: \"item-1\",\n * parentId: null,\n * name: \"Root Level Item 1\",\n * },\n * \"item-2\": {\n * itemId: \"item-2\",\n * parentId: \"item-1\",\n * name: \"A child for the first item\",\n * },\n * \"item-3\": {\n * itemId: \"item-3\",\n * parentId: \"item-1\",\n * children: \"Another child for the first item\",\n * },\n * };\n *\n * function Example(): ReactElement {\n * const tree = useTree({\n * // can enable multiple selected items\n * // multiSelect: true,\n *\n * // can set default expanded and selected items\n * // defaultSelectedIds: [\"item-1\"],\n * // defaultExpandedIds: [\"item-1\"],\n * });\n *\n * return (\n * <Tree\n * {...tree}\n * aria-label=\"Tree\"\n * data={data}\n * />\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link TreeProps.renderer} for a custom tree item example.\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n */\nexport function Tree<T extends TreeItemNode>(\n props: LabelRequiredForA11y<TreeProps<T>>\n): ReactElement {\n const {\n id,\n data,\n sort = identity,\n rootId = null,\n treeRef,\n className,\n expandedIds,\n selectedIds,\n toggleTreeItemSelection,\n selectMultipleTreeItems,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n onClick,\n onFocus,\n onKeyDown,\n renderer: TreeItemRenderer = DefaultTreeItemRenderer,\n multiSelect = false,\n expansionMode = \"auto\",\n expanderIcon,\n expanderLeft = false,\n linkComponent = \"a\",\n disableTransition = false,\n temporaryChildItems = false,\n ...remaining\n } = props;\n const treeId = useEnsuredId(id, \"tree\");\n const { items, treeItemChildIds } = useTreeItems({\n data,\n sort,\n rootId,\n });\n\n const { metadataLookup, movementContext, movementProps } = useTreeMovement({\n ref: treeRef,\n onClick,\n onFocus,\n onKeyDown,\n data,\n expandedIds,\n selectedIds,\n treeItemChildIds,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n });\n\n return (\n <TreeProvider\n data={data}\n rootId={rootId}\n multiSelect={multiSelect}\n linkComponent={linkComponent}\n selectedIds={selectedIds}\n expandedIds={expandedIds}\n expanderIcon={expanderIcon}\n expanderLeft={expanderLeft}\n expansionMode={expansionMode}\n metadataLookup={metadataLookup}\n disableTransition={disableTransition}\n temporaryChildItems={temporaryChildItems}\n toggleTreeItemSelection={toggleTreeItemSelection}\n toggleTreeItemExpansion={toggleTreeItemExpansion}\n selectMultipleTreeItems={selectMultipleTreeItems}\n expandMultipleTreeItems={expandMultipleTreeItems}\n >\n <KeyboardMovementProvider value={movementContext}>\n <List\n {...remaining}\n {...movementProps}\n id={treeId}\n role=\"tree\"\n tabIndex={0}\n className={tree({ className })}\n >\n <RenderRecursively\n items={items}\n render={TreeItemRenderer}\n getItemKey={(options) => options.item.itemId}\n />\n </List>\n </KeyboardMovementProvider>\n </TreeProvider>\n );\n}\n"],"names":["List","KeyboardMovementProvider","useEnsuredId","RenderRecursively","identity","DefaultTreeItemRenderer","TreeProvider","tree","useTreeItems","useTreeMovement","Tree","props","id","data","sort","rootId","treeRef","className","expandedIds","selectedIds","toggleTreeItemSelection","selectMultipleTreeItems","toggleTreeItemExpansion","expandMultipleTreeItems","onClick","onFocus","onKeyDown","renderer","TreeItemRenderer","multiSelect","expansionMode","expanderIcon","expanderLeft","linkComponent","disableTransition","temporaryChildItems","remaining","treeId","items","treeItemChildIds","metadataLookup","movementContext","movementProps","ref","value","role","tabIndex","render","getItemKey","options","item","itemId"],"mappings":"AAAA;;AAWA,SAASA,IAAI,QAAQ,kBAAkB;AACvC,SAASC,wBAAwB,QAAQ,6CAA6C;AAEtF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAAiCC,YAAY,QAAQ,oBAAoB;AACzE,SAAoCC,IAAI,QAAQ,cAAc;AAQ9D,SAASC,YAAY,QA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B;gBACJQ,MAAK;gBACLC,UAAU;gBACV7B,WAAWV,KAAK;oBAAEU;gBAAU;0BAE5B,cAAA,KAACd;oBACCmC,OAAOA;oBACPS,QAAQnB;oBACRoB,YAAY,CAACC,UAAYA,QAAQC,IAAI,CAACC,MAAM;;;;;AAMxD"}
|
|
1
|
+
{"version":3,"sources":["../../src/tree/Tree.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ComponentType,\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { List } from \"../list/List.js\";\nimport { KeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type LabelRequiredForA11y } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { RenderRecursively } from \"../utils/RenderRecursively.js\";\nimport { identity } from \"../utils/identity.js\";\nimport { DefaultTreeItemRenderer } from \"./DefaultTreeItemRenderer.js\";\nimport { type TreeExpansionMode, TreeProvider } from \"./TreeProvider.js\";\nimport { type TreeClassNameOptions, tree } from \"./styles.js\";\nimport {\n type TreeData,\n type TreeItemNode,\n type TreeItemRendererProps,\n type TreeItemSorter,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { useTreeItems } from \"./useTreeItems.js\";\nimport { useTreeMovement } from \"./useTreeMovement.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * @since 6.0.0\n */\nexport type TreeHTMLAttributes = Omit<\n HTMLAttributes<HTMLUListElement>,\n \"role\" | \"tabIndex\" | \"children\"\n>;\n\n/**\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n *\n * @since 6.3.1 Extends TreeClassNameOptions for CSSProperties module\n * augmentation.\n */\nexport interface TreeProps<T extends TreeItemNode>\n extends\n TreeHTMLAttributes,\n TreeClassNameOptions,\n TreeExpansion,\n TreeSelection {\n /** @see {@link TreeData} */\n data: TreeData<T>;\n\n /**\n * An optional ref to pass to the tree element.\n *\n * @since 6.0.0\n */\n treeRef?: Ref<HTMLUListElement>;\n\n /** @defaultValue `identity` */\n sort?: TreeItemSorter<T>;\n\n /**\n * Any nodes in the {@link data} that have a `parentId` set to this value will\n * appear at the root of the tree.\n *\n * @defaultValue `null`\n */\n rootId?: string | null;\n\n /**\n * @defaultValue `\"auto\"`\n * @see {@link TreeExpansionMode}\n */\n expansionMode?: TreeExpansionMode;\n\n /**\n * Set this to `true` to display the expander icon to the left instead of the\n * right. This will also update the styles slightly so you can still provide a\n * `leftAddon`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n\n /**\n * @defaultValue `getIcon(\"expander\")`\n */\n expanderIcon?: ReactNode;\n\n /**\n * Set this to `true` to disable the collapse transition for all tree items.\n *\n * @defaultValue `false`\n */\n disableTransition?: boolean;\n\n /**\n * Set this to `true` if the collapsed tree items should be removed from the\n * DOM instead of hidden using `display: none`. This _might_ improve\n * performance for large trees.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n\n /**\n * @example Custom Tree Item Renderer\n * ```tsx\n * import { useTreeContext } from \"@react-md/core/movement/TreeProvider\"\n * import { useKeyboardMovementContext } from \"@react-md/core/movement/useKeyboardMovementProvider\"\n * import { TreeItem } from \"@react-md/core/tree/TreeItem\";\n * import { type TreeItemRendererProps } from \"@react-md/core/tree/types\";\n * import FolderIcon from \"@react-md/material-icons/FolderIcon\";\n * import FolderOpenIcon from \"@react-md/material-icons/FolderOpenIcon\";\n * import { type ReactElement } from \"react\";\n *\n * export function CustomTreeItem(props: TreeItemRendererProps): ReactElement {\n * const { item, ...remaining } = props;\n * const id = useId();\n * const { itemId } = item;\n * const {\n * data,\n * expandedIds,\n * selectedIds,\n * toggleTreeItemExpansion,\n * toggleTreeItemSelection,\n * } = useTreeContext()\n * const { activeDescendantId } = useKeyboardMovementContext();\n *\n * const focused = id === activeDescendantId;\n * const expanded = expandedIds.has(itemId);\n * const selected = selectedIds.has(itemId);\n * const children = ...; // do whatever\n *\n * return (\n * <TreeItem\n * {...remaining}\n * id={id}\n * itemId={itemId}\n * leftAddon={expanded ? <FolderOpenIcon /> : <FolderIcon />}\n * >\n * {children}\n * </TreeItem>\n * );\n * }\n * ```\n *\n * @see {@link DefaultTreeItemRenderer}\n * @defaultValue `DefaultTreeItemRenderer`\n */\n renderer?: ComponentType<TreeItemRendererProps<T>>;\n\n /**\n * The link component to use for any tree item nodes that have a `to` or\n * `href`.\n *\n * @see {@link CustomLinkComponent}\n * @defaultValue `Link`\n */\n linkComponent?: CustomLinkComponent;\n}\n\n/**\n * **Client Component**\n *\n * @example Simple Tree\n * ```tsx\n * import { Tree } from \"@react-md/core/tree/Tree\";\n * import { type TreeData } from \"@react-md/core/tree/types\";\n * import { useTree } from \"@react-md/core/tree/useTree\";\n * import type { ReactElement } from \"react\";\n *\n * const data: TreeData = {\n * \"item-1\": {\n * itemId: \"item-1\",\n * parentId: null,\n * name: \"Root Level Item 1\",\n * },\n * \"item-2\": {\n * itemId: \"item-2\",\n * parentId: \"item-1\",\n * name: \"A child for the first item\",\n * },\n * \"item-3\": {\n * itemId: \"item-3\",\n * parentId: \"item-1\",\n * children: \"Another child for the first item\",\n * },\n * };\n *\n * function Example(): ReactElement {\n * const tree = useTree({\n * // can enable multiple selected items\n * // multiSelect: true,\n *\n * // can set default expanded and selected items\n * // defaultSelectedIds: [\"item-1\"],\n * // defaultExpandedIds: [\"item-1\"],\n * });\n *\n * return (\n * <Tree\n * {...tree}\n * aria-label=\"Tree\"\n * data={data}\n * />\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link TreeProps.renderer} for a custom tree item example.\n * @since 6.0.0 There was a major API change and the `id` is now `optional`.\n * In addition, the following props were removed:\n * - `itemRenderer`\n * - `labelKey`\n * - `valueKey`\n * - `getItemLabel`\n * - `getItemValue`\n * - `getItemProps`\n */\nexport function Tree<T extends TreeItemNode>(\n props: LabelRequiredForA11y<TreeProps<T>>\n): ReactElement {\n const {\n id,\n data,\n sort = identity,\n rootId = null,\n treeRef,\n className,\n expandedIds,\n selectedIds,\n toggleTreeItemSelection,\n selectMultipleTreeItems,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n onClick,\n onFocus,\n onKeyDown,\n renderer: TreeItemRenderer = DefaultTreeItemRenderer,\n multiSelect = false,\n expansionMode = \"auto\",\n expanderIcon,\n expanderLeft = false,\n linkComponent = \"a\",\n disableTransition = false,\n temporaryChildItems = false,\n ...remaining\n } = props;\n const treeId = useEnsuredId(id, \"tree\");\n const { items, treeItemChildIds } = useTreeItems({\n data,\n sort,\n rootId,\n });\n\n const { metadataLookup, movementContext, movementProps } = useTreeMovement({\n ref: treeRef,\n onClick,\n onFocus,\n onKeyDown,\n data,\n expandedIds,\n selectedIds,\n treeItemChildIds,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n });\n\n return (\n <TreeProvider\n data={data}\n rootId={rootId}\n multiSelect={multiSelect}\n linkComponent={linkComponent}\n selectedIds={selectedIds}\n expandedIds={expandedIds}\n expanderIcon={expanderIcon}\n expanderLeft={expanderLeft}\n expansionMode={expansionMode}\n metadataLookup={metadataLookup}\n disableTransition={disableTransition}\n temporaryChildItems={temporaryChildItems}\n toggleTreeItemSelection={toggleTreeItemSelection}\n toggleTreeItemExpansion={toggleTreeItemExpansion}\n selectMultipleTreeItems={selectMultipleTreeItems}\n expandMultipleTreeItems={expandMultipleTreeItems}\n >\n <KeyboardMovementProvider value={movementContext}>\n <List\n {...remaining}\n {...movementProps}\n id={treeId}\n role=\"tree\"\n tabIndex={0}\n className={tree({ className })}\n >\n <RenderRecursively\n items={items}\n render={TreeItemRenderer}\n getItemKey={(options) => options.item.itemId}\n />\n </List>\n </KeyboardMovementProvider>\n </TreeProvider>\n );\n}\n"],"names":["List","KeyboardMovementProvider","useEnsuredId","RenderRecursively","identity","DefaultTreeItemRenderer","TreeProvider","tree","useTreeItems","useTreeMovement","Tree","props","id","data","sort","rootId","treeRef","className","expandedIds","selectedIds","toggleTreeItemSelection","selectMultipleTreeItems","toggleTreeItemExpansion","expandMultipleTreeItems","onClick","onFocus","onKeyDown","renderer","TreeItemRenderer","multiSelect","expansionMode","expanderIcon","expanderLeft","linkComponent","disableTransition","temporaryChildItems","remaining","treeId","items","treeItemChildIds","metadataLookup","movementContext","movementProps","ref","value","role","tabIndex","render","getItemKey","options","item","itemId"],"mappings":"AAAA;;AAWA,SAASA,IAAI,QAAQ,kBAAkB;AACvC,SAASC,wBAAwB,QAAQ,6CAA6C;AAEtF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAASC,iBAAiB,QAAQ,gCAAgC;AAClE,SAASC,QAAQ,QAAQ,uBAAuB;AAChD,SAASC,uBAAuB,QAAQ,+BAA+B;AACvE,SAAiCC,YAAY,QAAQ,oBAAoB;AACzE,SAAoCC,IAAI,QAAQ,cAAc;AAQ9D,SAASC,YAAY,QAAQ,oBAAoB;AACjD,SAASC,eAAe,QAAQ,uBAAuB;AAgJvD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0DC,GACD,OAAO,SAASC,KACdC,KAAyC;IAEzC,MAAM,EACJC,EAAE,EACFC,IAAI,EACJC,OAAOV,QAAQ,EACfW,SAAS,IAAI,EACbC,OAAO,EACPC,SAAS,EACTC,WAAW,EACXC,WAAW,EACXC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,OAAO,EACPC,OAAO,EACPC,SAAS,EACTC,UAAUC,mBAAmBvB,uBAAuB,EACpDwB,cAAc,KAAK,EACnBC,gBAAgB,MAAM,EACtBC,YAAY,EACZC,eAAe,KAAK,EACpBC,gBAAgB,GAAG,EACnBC,oBAAoB,KAAK,EACzBC,sBAAsB,KAAK,EAC3B,GAAGC,WACJ,GAAGzB;IACJ,MAAM0B,SAASnC,aAAaU,IAAI;IAChC,MAAM,EAAE0B,KAAK,EAAEC,gBAAgB,EAAE,GAAG/B,aAAa;QAC/CK;QACAC;QACAC;IACF;IAEA,MAAM,EAAEyB,cAAc,EAAEC,eAAe,EAAEC,aAAa,EAAE,GAAGjC,gBAAgB;QACzEkC,KAAK3B;QACLQ;QACAC;QACAC;QACAb;QACAK;QACAC;QACAoB;QACAjB;QACAC;IACF;IAEA,qBACE,KAACjB;QACCO,MAAMA;QACNE,QAAQA;QACRc,aAAaA;QACbI,eAAeA;QACfd,aAAaA;QACbD,aAAaA;QACba,cAAcA;QACdC,cAAcA;QACdF,eAAeA;QACfU,gBAAgBA;QAChBN,mBAAmBA;QACnBC,qBAAqBA;QACrBf,yBAAyBA;QACzBE,yBAAyBA;QACzBD,yBAAyBA;QACzBE,yBAAyBA;kBAEzB,cAAA,KAACtB;YAAyB2C,OAAOH;sBAC/B,cAAA,KAACzC;gBACE,GAAGoC,SAAS;gBACZ,GAAGM,aAAa;gBACjB9B,IAAIyB;gBACJQ,MAAK;gBACLC,UAAU;gBACV7B,WAAWV,KAAK;oBAAEU;gBAAU;0BAE5B,cAAA,KAACd;oBACCmC,OAAOA;oBACPS,QAAQnB;oBACRoB,YAAY,CAACC,UAAYA,QAAQC,IAAI,CAACC,MAAM;;;;;AAMxD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/TreeItem.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n useEffect,\n} from \"react\";\n\nimport { type ComponentWithRippleProps } from \"../interaction/types.js\";\nimport { useElementInteraction } from \"../interaction/useElementInteraction.js\";\nimport { useHigherContrastChildren } from \"../interaction/useHigherContrastChildren.js\";\nimport { ListItemChildren } from \"../list/ListItemChildren.js\";\nimport { useKeyboardMovementContext } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { type OverridableTreeGroupProps, TreeGroup } from \"./TreeGroup.js\";\nimport { TreeItemExpander } from \"./TreeItemExpander.js\";\nimport { useTreeContext } from \"./TreeProvider.js\";\nimport { treeItem, treeItemContent, treeItemMedia } from \"./styles.js\";\nimport { type DefaultTreeItemNode } from \"./types.js\";\n\n/**\n * @since 6.0.0 Added `liProps` and `groupProps`.\n * @since 6.0.0 The `liRef`, `liStyle`, and `liClassName` props were removed in\n * favor of `liProps={{ ref, style, className }}`.\n * @since 6.0.0 The `itemIndex`, `listSize`, `renderChildItems`, `isLink`,\n * `contentComponent`, and `readOnly` props were removed.\n */\nexport interface TreeItemProps\n extends Omit<DefaultTreeItemNode, \"parentId\">,\n HTMLAttributes<HTMLLIElement>,\n ComponentWithRippleProps {\n /**\n * @defaultValue `\"tree-item-\" + useId()`\n */\n id?: string;\n\n /**\n * This is used to set the `--rmd-tree-depth` CSS variable which allows the\n * padding to increase for each nested tree.\n */\n depth: number;\n\n /**\n * Any additional props that should be passed to the surrounding `<li>`\n * element. The top-level props are passed to the `<span>` or `<a>` element\n * instead.\n */\n liProps?: PropsWithRef<HTMLAttributes<HTMLLIElement>>;\n\n /**\n * Any additional props to pass to the `TreeGroup` component.\n */\n groupProps?: PropsWithRef<OverridableTreeGroupProps>;\n\n /**\n * This should normally be the text/content to display within the tree item\n * and should **not** include nested trees.\n */\n children?: ReactNode;\n\n /**\n * The nested tree items to render within a `TreeGroup`.\n */\n childItems?: ReactNode;\n\n /** @defaultValue `false` */\n disableTransition?: boolean;\n\n /**\n * This ref is applied to the `<span>` or `<a>` element and can be used to\n * implement drag and drop behavior.\n */\n contentRef?: Ref<HTMLElement>;\n\n /**\n * Set this to `true` if the {@link childItems} should not be rendered while\n * collapsed.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n}\n\n/**\n * **Client Component**\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/treeview/}\n * @since 6.0.0 No longer forwards refs. The ref must be provided using\n * `contentRef` instead.\n * @since 6.0.0 The `liRef` was removed in favor of `liProps={{ ref }}`.\n * @since 6.0.0 The wrapping `<li>` element will always be `role=\"none\"` and the\n * `<span>` or `<a>` will gain the `role=\"treeitem\"` instead. This makes it\n * easier to pass event handlers because of the nested behavior of tree items.\n * @since 6.0.0 No longer provides the `aria-level`, `aria-setsize` and\n * `aria-posinset` attributes and allows the browser to compute them instead.\n */\nexport function TreeItem(props: TreeItemProps): ReactElement {\n const {\n id: propId,\n depth,\n liProps,\n disabled = false,\n disabledOpacity = false,\n groupProps,\n children: propChildren,\n className,\n itemId,\n leftAddon,\n leftAddonType: propLeftAddonType,\n leftAddonPosition,\n leftAddonClassName,\n leftAddonForceWrap,\n rightAddon,\n rightAddonType,\n rightAddonPosition,\n rightAddonClassName,\n rightAddonForceWrap,\n disableTextChildren,\n disableLeftAddonCenteredMedia: propDisableLeftAddonCenteredMedia,\n disableRightAddonCenteredMedia,\n textProps,\n textClassName,\n primaryText,\n secondaryText,\n secondaryTextProps,\n secondaryTextClassName,\n multiline,\n childItems,\n contentClassName,\n temporaryChildItems,\n disableTransition: propDisableTransition,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n contentRef,\n disableRipple,\n ...remaining\n } = props;\n\n const id = useEnsuredId(propId, \"tree-item\");\n const children = useHigherContrastChildren(propChildren);\n if (disabled) {\n // you can't really disable a link other than removing the href, so\n // unset these props\n remaining.to = undefined;\n remaining.href = undefined;\n }\n\n const {\n expandedIds,\n selectedIds,\n expanderLeft,\n expansionMode,\n metadataLookup,\n linkComponent: Link,\n toggleTreeItemSelection,\n toggleTreeItemExpansion,\n disableTransition: contextDisableTransition,\n } = useTreeContext();\n const { activeDescendantId } = useKeyboardMovementContext();\n\n const isLeafNode = !childItems;\n const focused = activeDescendantId === id;\n const expanded = expandedIds.has(itemId);\n const selected = selectedIds.has(itemId);\n const disableTransition = propDisableTransition ?? contextDisableTransition;\n\n useEffect(() => {\n const lookup = metadataLookup.current;\n lookup.expandable[itemId] = !isLeafNode;\n lookup.disabledItems[itemId] = disabled;\n lookup.elementToItem[id] = itemId;\n lookup.itemToElement[itemId] = id;\n\n return () => {\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete lookup.disabledItems[itemId];\n delete lookup.expandable[itemId];\n delete lookup.elementToItem[id];\n delete lookup.itemToElement[itemId];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n };\n }, [id, metadataLookup, itemId, isLeafNode, disabled, depth]);\n\n const { pressedClassName, ripples, handlers } =\n useElementInteraction<HTMLLIElement>({\n mode: disableRipple ? \"none\" : undefined,\n onBlur,\n onClick(event) {\n onClick?.(event);\n toggleTreeItemSelection(itemId);\n if (!isLeafNode && expansionMode !== \"manual\") {\n toggleTreeItemExpansion(itemId);\n }\n },\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n disabled,\n });\n\n const isLink = !!(remaining.to || remaining.href);\n\n // cheating a bit so there are type errors around the event handlers\n const ContentComponent = (isLink ? Link : \"span\") as \"span\";\n const leftAddonType =\n (propLeftAddonType ?? (expanderLeft && leftAddon)) ? \"media\" : undefined;\n const isMediaLeftAddon =\n typeof propLeftAddonType === \"undefined\" && leftAddonType === \"media\";\n const disableLeftAddonCenteredMedia =\n propDisableLeftAddonCenteredMedia ?? isMediaLeftAddon;\n\n return (\n <li\n {...liProps}\n role=\"none\"\n className={treeItem({\n className,\n expander: !!childItems,\n expanderLeft,\n })}\n >\n <ContentComponent\n {...remaining}\n // nodes with children should always apply the `aria-expanded` to show\n // that it is expandable while leaf nodes should remain omitted\n aria-expanded={isLeafNode ? undefined : expanded}\n aria-selected={selected}\n aria-disabled={disabled || undefined}\n id={id}\n ref={contentRef}\n role=\"treeitem\"\n tabIndex={-1}\n {...handlers}\n className={treeItemContent({\n link: isLink,\n focused,\n selected,\n disabled,\n disabledOpacity,\n className: contentClassName,\n pressedClassName,\n })}\n >\n <ListItemChildren\n multiline={multiline}\n textClassName={textClassName}\n secondaryTextClassName={secondaryTextClassName}\n disableTextChildren={disableTextChildren}\n primaryText={primaryText}\n textProps={textProps}\n secondaryText={secondaryText}\n secondaryTextProps={secondaryTextProps}\n leftAddon={\n <TreeItemExpander\n isLeft\n itemId={itemId}\n addon={leftAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n leftAddonType={leftAddonType}\n leftAddonPosition={leftAddonPosition}\n leftAddonClassName={treeItemMedia({\n isLeafNode,\n isMediaLeftAddon,\n className: leftAddonClassName,\n })}\n leftAddonForceWrap={leftAddonForceWrap}\n rightAddon={\n <TreeItemExpander\n itemId={itemId}\n addon={rightAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n rightAddonType={rightAddonType}\n rightAddonPosition={rightAddonPosition}\n rightAddonClassName={rightAddonClassName}\n rightAddonForceWrap={rightAddonForceWrap}\n disableLeftAddonCenteredMedia={disableLeftAddonCenteredMedia}\n disableRightAddonCenteredMedia={disableRightAddonCenteredMedia}\n >\n {children}\n </ListItemChildren>\n {ripples}\n </ContentComponent>\n <TreeGroup\n id={`${id}-group`}\n temporary={temporaryChildItems}\n disableTransition={disableTransition}\n {...groupProps}\n depth={depth + 1}\n collapsed={isLeafNode || !expanded}\n >\n {childItems}\n </TreeGroup>\n </li>\n );\n}\n"],"names":["useEffect","useElementInteraction","useHigherContrastChildren","ListItemChildren","useKeyboardMovementContext","useEnsuredId","TreeGroup","TreeItemExpander","useTreeContext","treeItem","treeItemContent","treeItemMedia","TreeItem","props","id","propId","depth","liProps","disabled","disabledOpacity","groupProps","children","propChildren","className","itemId","leftAddon","leftAddonType","propLeftAddonType","leftAddonPosition","leftAddonClassName","leftAddonForceWrap","rightAddon","rightAddonType","rightAddonPosition","rightAddonClassName","rightAddonForceWrap","disableTextChildren","disableLeftAddonCenteredMedia","propDisableLeftAddonCenteredMedia","disableRightAddonCenteredMedia","textProps","textClassName","primaryText","secondaryText","secondaryTextProps","secondaryTextClassName","multiline","childItems","contentClassName","temporaryChildItems","disableTransition","propDisableTransition","onBlur","onClick","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave","onDragStart","onTouchStart","onTouchEnd","onTouchMove","contentRef","disableRipple","remaining","to","undefined","href","expandedIds","selectedIds","expanderLeft","expansionMode","metadataLookup","linkComponent","Link","toggleTreeItemSelection","toggleTreeItemExpansion","contextDisableTransition","activeDescendantId","isLeafNode","focused","expanded","has","selected","lookup","current","expandable","disabledItems","elementToItem","itemToElement","pressedClassName","ripples","handlers","mode","event","isLink","ContentComponent","isMediaLeftAddon","li","role","expander","aria-expanded","aria-selected","aria-disabled","ref","tabIndex","link","isLeft","addon","temporary","collapsed"],"mappings":"AAAA;;AAEA,SAKEA,SAAS,QACJ,QAAQ;AAGf,SAASC,qBAAqB,QAAQ,0CAA0C;AAChF,SAASC,yBAAyB,QAAQ,8CAA8C;AACxF,SAASC,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,0BAA0B,QAAQ,6CAA6C;AAExF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAAyCC,SAAS,QAAQ,iBAAiB;AAC3E,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,QAAQ,EAAEC,eAAe,EAAEC,aAAa,QAAQ,cAAc;AAkEvE;;;;;;;;;;;;;CAaC,GACD,OAAO,SAASC,SAASC,KAAoB;IAC3C,MAAM,EACJC,IAAIC,MAAM,EACVC,KAAK,EACLC,OAAO,EACPC,WAAW,KAAK,EAChBC,kBAAkB,KAAK,EACvBC,UAAU,EACVC,UAAUC,YAAY,EACtBC,SAAS,EACTC,MAA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AYe;gBACxCqB,iBAAenB;gBACfoB,iBAAetF,YAAYiD;gBAC3BrD,IAAIA;gBACJ2F,KAAK1C;gBACLqC,MAAK;gBACLM,UAAU,CAAC;gBACV,GAAGb,QAAQ;gBACZtE,WAAWb,gBAAgB;oBACzBiG,MAAMX;oBACNf;oBACAG;oBACAlE;oBACAC;oBACAI,WAAWyB;oBACX2C;gBACF;;kCAEA,KAACxF;wBACC2C,WAAWA;wBACXL,eAAeA;wBACfI,wBAAwBA;wBACxBT,qBAAqBA;wBACrBM,aAAaA;wBACbF,WAAWA;wBACXG,eAAeA;wBACfC,oBAAoBA;wBACpBnB,yBACE,KAAClB;4BACCqG,MAAM;4BACNpF,QAAQA;4BACRqF,OAAOpF;4BACPyD,UAAUA;4BACVhE,UAAUA;4BACV8D,YAAYA;;wBAGhBtD,eAAeA;wBACfE,mBAAmBA;wBACnBC,oBAAoBlB,cAAc;4BAChCqE;4BACAkB;4BACA3E,WAAWM;wBACb;wBACAC,oBAAoBA;wBACpBC,0BACE,KAACxB;4BACCiB,QAAQA;4BACRqF,OAAO9E;4BACPmD,UAAUA;4BACVhE,UAAUA;4BACV8D,YAAYA;;wBAGhBhD,gBAAgBA;wBAChBC,oBAAoBA;wBACpBC,qBAAqBA;wBACrBC,qBAAqBA;wBACrBE,+BAA+BA;wBAC/BE,gCAAgCA;kCAE/BlB;;oBAEFuE;;;0BAEH,KAACtF;gBACCQ,IAAI,GAAGA,GAAG,MAAM,CAAC;gBACjBgG,WAAW7D;gBACXC,mBAAmBA;gBAClB,GAAG9B,UAAU;gBACdJ,OAAOA,QAAQ;gBACf+F,WAAW/B,cAAc,CAACE;0BAEzBnC;;;;AAIT"}
|
|
1
|
+
{"version":3,"sources":["../../src/tree/TreeItem.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type HTMLAttributes,\n type ReactElement,\n type ReactNode,\n type Ref,\n useEffect,\n} from \"react\";\n\nimport { type ComponentWithRippleProps } from \"../interaction/types.js\";\nimport { useElementInteraction } from \"../interaction/useElementInteraction.js\";\nimport { useHigherContrastChildren } from \"../interaction/useHigherContrastChildren.js\";\nimport { ListItemChildren } from \"../list/ListItemChildren.js\";\nimport { useKeyboardMovementContext } from \"../movement/useKeyboardMovementProvider.js\";\nimport { type PropsWithRef } from \"../types.js\";\nimport { useEnsuredId } from \"../useEnsuredId.js\";\nimport { type OverridableTreeGroupProps, TreeGroup } from \"./TreeGroup.js\";\nimport { TreeItemExpander } from \"./TreeItemExpander.js\";\nimport { useTreeContext } from \"./TreeProvider.js\";\nimport { treeItem, treeItemContent, treeItemMedia } from \"./styles.js\";\nimport { type DefaultTreeItemNode } from \"./types.js\";\n\n/**\n * @since 6.0.0 Added `liProps` and `groupProps`.\n * @since 6.0.0 The `liRef`, `liStyle`, and `liClassName` props were removed in\n * favor of `liProps={{ ref, style, className }}`.\n * @since 6.0.0 The `itemIndex`, `listSize`, `renderChildItems`, `isLink`,\n * `contentComponent`, and `readOnly` props were removed.\n */\nexport interface TreeItemProps\n extends\n Omit<DefaultTreeItemNode, \"parentId\">,\n HTMLAttributes<HTMLLIElement>,\n ComponentWithRippleProps {\n /**\n * @defaultValue `\"tree-item-\" + useId()`\n */\n id?: string;\n\n /**\n * This is used to set the `--rmd-tree-depth` CSS variable which allows the\n * padding to increase for each nested tree.\n */\n depth: number;\n\n /**\n * Any additional props that should be passed to the surrounding `<li>`\n * element. The top-level props are passed to the `<span>` or `<a>` element\n * instead.\n */\n liProps?: PropsWithRef<HTMLAttributes<HTMLLIElement>>;\n\n /**\n * Any additional props to pass to the `TreeGroup` component.\n */\n groupProps?: PropsWithRef<OverridableTreeGroupProps>;\n\n /**\n * This should normally be the text/content to display within the tree item\n * and should **not** include nested trees.\n */\n children?: ReactNode;\n\n /**\n * The nested tree items to render within a `TreeGroup`.\n */\n childItems?: ReactNode;\n\n /** @defaultValue `false` */\n disableTransition?: boolean;\n\n /**\n * This ref is applied to the `<span>` or `<a>` element and can be used to\n * implement drag and drop behavior.\n */\n contentRef?: Ref<HTMLElement>;\n\n /**\n * Set this to `true` if the {@link childItems} should not be rendered while\n * collapsed.\n *\n * @defaultValue `false`\n */\n temporaryChildItems?: boolean;\n}\n\n/**\n * **Client Component**\n *\n * @see {@link https://react-md.dev/components/tree | Tree Demos}\n * @see {@link https://www.w3.org/WAI/ARIA/apg/patterns/treeview/}\n * @since 6.0.0 No longer forwards refs. The ref must be provided using\n * `contentRef` instead.\n * @since 6.0.0 The `liRef` was removed in favor of `liProps={{ ref }}`.\n * @since 6.0.0 The wrapping `<li>` element will always be `role=\"none\"` and the\n * `<span>` or `<a>` will gain the `role=\"treeitem\"` instead. This makes it\n * easier to pass event handlers because of the nested behavior of tree items.\n * @since 6.0.0 No longer provides the `aria-level`, `aria-setsize` and\n * `aria-posinset` attributes and allows the browser to compute them instead.\n */\nexport function TreeItem(props: TreeItemProps): ReactElement {\n const {\n id: propId,\n depth,\n liProps,\n disabled = false,\n disabledOpacity = false,\n groupProps,\n children: propChildren,\n className,\n itemId,\n leftAddon,\n leftAddonType: propLeftAddonType,\n leftAddonPosition,\n leftAddonClassName,\n leftAddonForceWrap,\n rightAddon,\n rightAddonType,\n rightAddonPosition,\n rightAddonClassName,\n rightAddonForceWrap,\n disableTextChildren,\n disableLeftAddonCenteredMedia: propDisableLeftAddonCenteredMedia,\n disableRightAddonCenteredMedia,\n textProps,\n textClassName,\n primaryText,\n secondaryText,\n secondaryTextProps,\n secondaryTextClassName,\n multiline,\n childItems,\n contentClassName,\n temporaryChildItems,\n disableTransition: propDisableTransition,\n onBlur,\n onClick,\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n contentRef,\n disableRipple,\n ...remaining\n } = props;\n\n const id = useEnsuredId(propId, \"tree-item\");\n const children = useHigherContrastChildren(propChildren);\n if (disabled) {\n // you can't really disable a link other than removing the href, so\n // unset these props\n remaining.to = undefined;\n remaining.href = undefined;\n }\n\n const {\n expandedIds,\n selectedIds,\n expanderLeft,\n expansionMode,\n metadataLookup,\n linkComponent: Link,\n toggleTreeItemSelection,\n toggleTreeItemExpansion,\n disableTransition: contextDisableTransition,\n } = useTreeContext();\n const { activeDescendantId } = useKeyboardMovementContext();\n\n const isLeafNode = !childItems;\n const focused = activeDescendantId === id;\n const expanded = expandedIds.has(itemId);\n const selected = selectedIds.has(itemId);\n const disableTransition = propDisableTransition ?? contextDisableTransition;\n\n useEffect(() => {\n const lookup = metadataLookup.current;\n lookup.expandable[itemId] = !isLeafNode;\n lookup.disabledItems[itemId] = disabled;\n lookup.elementToItem[id] = itemId;\n lookup.itemToElement[itemId] = id;\n\n return () => {\n /* eslint-disable @typescript-eslint/no-dynamic-delete */\n delete lookup.disabledItems[itemId];\n delete lookup.expandable[itemId];\n delete lookup.elementToItem[id];\n delete lookup.itemToElement[itemId];\n /* eslint-enable @typescript-eslint/no-dynamic-delete */\n };\n }, [id, metadataLookup, itemId, isLeafNode, disabled, depth]);\n\n const { pressedClassName, ripples, handlers } =\n useElementInteraction<HTMLLIElement>({\n mode: disableRipple ? \"none\" : undefined,\n onBlur,\n onClick(event) {\n onClick?.(event);\n toggleTreeItemSelection(itemId);\n if (!isLeafNode && expansionMode !== \"manual\") {\n toggleTreeItemExpansion(itemId);\n }\n },\n onKeyDown,\n onKeyUp,\n onMouseDown,\n onMouseUp,\n onMouseLeave,\n onDragStart,\n onTouchStart,\n onTouchEnd,\n onTouchMove,\n disabled,\n });\n\n const isLink = !!(remaining.to || remaining.href);\n\n // cheating a bit so there are type errors around the event handlers\n const ContentComponent = (isLink ? Link : \"span\") as \"span\";\n const leftAddonType =\n (propLeftAddonType ?? (expanderLeft && leftAddon)) ? \"media\" : undefined;\n const isMediaLeftAddon =\n typeof propLeftAddonType === \"undefined\" && leftAddonType === \"media\";\n const disableLeftAddonCenteredMedia =\n propDisableLeftAddonCenteredMedia ?? isMediaLeftAddon;\n\n return (\n <li\n {...liProps}\n role=\"none\"\n className={treeItem({\n className,\n expander: !!childItems,\n expanderLeft,\n })}\n >\n <ContentComponent\n {...remaining}\n // nodes with children should always apply the `aria-expanded` to show\n // that it is expandable while leaf nodes should remain omitted\n aria-expanded={isLeafNode ? undefined : expanded}\n aria-selected={selected}\n aria-disabled={disabled || undefined}\n id={id}\n ref={contentRef}\n role=\"treeitem\"\n tabIndex={-1}\n {...handlers}\n className={treeItemContent({\n link: isLink,\n focused,\n selected,\n disabled,\n disabledOpacity,\n className: contentClassName,\n pressedClassName,\n })}\n >\n <ListItemChildren\n multiline={multiline}\n textClassName={textClassName}\n secondaryTextClassName={secondaryTextClassName}\n disableTextChildren={disableTextChildren}\n primaryText={primaryText}\n textProps={textProps}\n secondaryText={secondaryText}\n secondaryTextProps={secondaryTextProps}\n leftAddon={\n <TreeItemExpander\n isLeft\n itemId={itemId}\n addon={leftAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n leftAddonType={leftAddonType}\n leftAddonPosition={leftAddonPosition}\n leftAddonClassName={treeItemMedia({\n isLeafNode,\n isMediaLeftAddon,\n className: leftAddonClassName,\n })}\n leftAddonForceWrap={leftAddonForceWrap}\n rightAddon={\n <TreeItemExpander\n itemId={itemId}\n addon={rightAddon}\n expanded={expanded}\n disabled={disabled}\n isLeafNode={isLeafNode}\n />\n }\n rightAddonType={rightAddonType}\n rightAddonPosition={rightAddonPosition}\n rightAddonClassName={rightAddonClassName}\n rightAddonForceWrap={rightAddonForceWrap}\n disableLeftAddonCenteredMedia={disableLeftAddonCenteredMedia}\n disableRightAddonCenteredMedia={disableRightAddonCenteredMedia}\n >\n {children}\n </ListItemChildren>\n {ripples}\n </ContentComponent>\n <TreeGroup\n id={`${id}-group`}\n temporary={temporaryChildItems}\n disableTransition={disableTransition}\n {...groupProps}\n depth={depth + 1}\n collapsed={isLeafNode || !expanded}\n >\n {childItems}\n </TreeGroup>\n </li>\n );\n}\n"],"names":["useEffect","useElementInteraction","useHigherContrastChildren","ListItemChildren","useKeyboardMovementContext","useEnsuredId","TreeGroup","TreeItemExpander","useTreeContext","treeItem","treeItemContent","treeItemMedia","TreeItem","props","id","propId","depth","liProps","disabled","disabledOpacity","groupProps","children","propChildren","className","itemId","leftAddon","leftAddonType","propLeftAddonType","leftAddonPosition","leftAddonClassName","leftAddonForceWrap","rightAddon","rightAddonType","rightAddonPosition","rightAddonClassName","rightAddonForceWrap","disableTextChildren","disableLeftAddonCenteredMedia","propDisableLeftAddonCenteredMedia","disableRightAddonCenteredMedia","textProps","textClassName","primaryText","secondaryText","secondaryTextProps","secondaryTextClassName","multiline","childItems","contentClassName","temporaryChildItems","disableTransition","propDisableTransition","onBlur","onClick","onKeyDown","onKeyUp","onMouseDown","onMouseUp","onMouseLeave","onDragStart","onTouchStart","onTouchEnd","onTouchMove","contentRef","disableRipple","remaining","to","undefined","href","expandedIds","selectedIds","expanderLeft","expansionMode","metadataLookup","linkComponent","Link","toggleTreeItemSelection","toggleTreeItemExpansion","contextDisableTransition","activeDescendantId","isLeafNode","focused","expanded","has","selected","lookup","current","expandable","disabledItems","elementToItem","itemToElement","pressedClassName","ripples","handlers","mode","event","isLink","ContentComponent","isMediaLeftAddon","li","role","expander","aria-expanded","aria-selected","aria-disabled","ref","tabIndex","link","isLeft","addon","temporary","collapsed"],"mappings":"AAAA;;AAEA,SAKEA,SAAS,QACJ,QAAQ;AAGf,SAASC,qBAAqB,QAAQ,0CAA0C;AAChF,SAASC,yBAAyB,QAAQ,8CAA8C;AACxF,SAASC,gBAAgB,QAAQ,8BAA8B;AAC/D,SAASC,0BAA0B,QAAQ,6CAA6C;AAExF,SAASC,YAAY,QAAQ,qBAAqB;AAClD,SAAyCC,SAAS,QAAQ,iBAAiB;AAC3E,SAASC,gBAAgB,QAAQ,wBAAwB;AACzD,SAASC,cAAc,QAAQ,oBAAoB;AACnD,SAASC,QAAQ,EAAEC,eAAe,EAAEC,aAAa,QAAQ,cAAc;AAmEvE;;;;;;;;;;;;;CAaC,GACD,OAAO,SAAS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
1
|
-
{"version":3,"sources":["../../src/tree/TreeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactElement,\n type ReactNode,\n createContext,\n useContext,\n useMemo,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { type NonNullRef } from \"../types.js\";\nimport {\n type DefaultTreeItemNode,\n type TreeData,\n type TreeItemNode,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * When this is set to `\"auto\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will select and expand/collapse the tree item. The user\n * can still use the ArrowLeft and ArrowRight keys to expand/collapse nested\n * tree items.\n *\n * When this is set to `\"manual\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will only select that tree item. The user must use the\n * ArrowLeft and ArrowRight keys to expand/collapse nested tree items.\n *\n * The main use-case for the `\"manual\"` setting is creating a navigation tree\n * that requires the user to click on an icon or a button to expand the child\n * items.\n *\n * @since 6.0.0\n */\nexport type TreeExpansionMode = \"auto\" | \"manual\";\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface TreeItemMetadataLookup {\n /**\n * This is used for the keyboard movement behavior for trees that allow the\n * `ArrowRight` key for tree items that have children.\n */\n expandable: Record<string, boolean>;\n\n /**\n * This is a quick lookup if a tree item is disabled since it's possible the\n * custom `renderer` sets the `disabled` state and not the `TreeData`.\n */\n disabledItems: Record<string, boolean>;\n\n /**\n * A lookup of element `id` (DOM id) for each tree item to the `itemId`. This\n * is a quick way to figure out which item is being interacted with from a\n * keyboard event without needed to add `data-*` attributes.\n */\n elementToItem: Record<string, string>;\n\n /**\n * A lookup of tree item `itemId` to the element `id` (DOM id). This is used\n * to be able to find a parent tree item when the `ArrowLeft` key is pressed\n * to focus that parent item.\n */\n itemToElement: Record<string, string>;\n}\n\n/**\n * The tree context is mostly a convenience API for implementing a custom tree\n * item that requires the {@link TreeExpansion}, {@link TreeSelection} and\n * {@link TreeData} to work.\n *\n * The other properties on the context are most likely for internal use only.\n *\n * @since 6.0.0\n */\nexport interface TreeContext<T extends TreeItemNode = DefaultTreeItemNode>\n extends TreeExpansion
|
|
1
|
+
{"version":3,"sources":["../../src/tree/TreeProvider.tsx"],"sourcesContent":["\"use client\";\n\nimport {\n type ReactElement,\n type ReactNode,\n createContext,\n useContext,\n useMemo,\n} from \"react\";\n\nimport { type CustomLinkComponent } from \"../link/Link.js\";\nimport { type NonNullRef } from \"../types.js\";\nimport {\n type DefaultTreeItemNode,\n type TreeData,\n type TreeItemNode,\n} from \"./types.js\";\nimport { type TreeExpansion } from \"./useTreeExpansion.js\";\nimport { type TreeSelection } from \"./useTreeSelection.js\";\n\n/**\n * When this is set to `\"auto\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will select and expand/collapse the tree item. The user\n * can still use the ArrowLeft and ArrowRight keys to expand/collapse nested\n * tree items.\n *\n * When this is set to `\"manual\"`, clicking on a tree item with a mouse or with\n * the Enter/Space keys will only select that tree item. The user must use the\n * ArrowLeft and ArrowRight keys to expand/collapse nested tree items.\n *\n * The main use-case for the `\"manual\"` setting is creating a navigation tree\n * that requires the user to click on an icon or a button to expand the child\n * items.\n *\n * @since 6.0.0\n */\nexport type TreeExpansionMode = \"auto\" | \"manual\";\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface TreeItemMetadataLookup {\n /**\n * This is used for the keyboard movement behavior for trees that allow the\n * `ArrowRight` key for tree items that have children.\n */\n expandable: Record<string, boolean>;\n\n /**\n * This is a quick lookup if a tree item is disabled since it's possible the\n * custom `renderer` sets the `disabled` state and not the `TreeData`.\n */\n disabledItems: Record<string, boolean>;\n\n /**\n * A lookup of element `id` (DOM id) for each tree item to the `itemId`. This\n * is a quick way to figure out which item is being interacted with from a\n * keyboard event without needed to add `data-*` attributes.\n */\n elementToItem: Record<string, string>;\n\n /**\n * A lookup of tree item `itemId` to the element `id` (DOM id). This is used\n * to be able to find a parent tree item when the `ArrowLeft` key is pressed\n * to focus that parent item.\n */\n itemToElement: Record<string, string>;\n}\n\n/**\n * The tree context is mostly a convenience API for implementing a custom tree\n * item that requires the {@link TreeExpansion}, {@link TreeSelection} and\n * {@link TreeData} to work.\n *\n * The other properties on the context are most likely for internal use only.\n *\n * @since 6.0.0\n */\nexport interface TreeContext<T extends TreeItemNode = DefaultTreeItemNode>\n extends TreeExpansion, TreeSelection {\n data: TreeData<T>;\n rootId: string | null;\n disableTransition: boolean;\n temporaryChildItems: boolean;\n\n linkComponent: CustomLinkComponent;\n\n /** @internal */\n expanderLeft: boolean;\n /** @internal */\n expanderIcon: ReactNode;\n /** @internal */\n expansionMode: TreeExpansionMode;\n /** @internal */\n metadataLookup: NonNullRef<TreeItemMetadataLookup>;\n}\n\n// Allow the hook to correct typecast this instead\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nconst context = createContext<TreeContext<any> | undefined>(undefined);\ncontext.displayName = \"Tree\";\nconst { Provider } = context;\n\n/**\n * This can be used for a custom tree item renderer.\n *\n * @see The `Tree` component for an example.\n * @since 6.0.0\n */\nexport function useTreeContext<\n T extends TreeItemNode = DefaultTreeItemNode,\n>(): TreeContext<T> {\n const value = useContext(context);\n if (!value) {\n throw new Error(\"Cannot find a parent Tree component\");\n }\n\n return value;\n}\n\n/**\n * @internal\n * @since 6.0.0\n */\nexport interface TreeProviderProps<\n T extends TreeItemNode = DefaultTreeItemNode,\n> extends TreeContext<T> {\n children: ReactNode;\n}\n\n/**\n * **Client Component**\n *\n * @internal\n * @since 6.0.0\n */\nexport function TreeProvider<T extends TreeItemNode = DefaultTreeItemNode>(\n props: TreeProviderProps<T>\n): ReactElement {\n const {\n children,\n data,\n rootId,\n multiSelect,\n expanderIcon,\n expanderLeft,\n expansionMode,\n metadataLookup,\n disableTransition,\n temporaryChildItems,\n linkComponent,\n expandedIds,\n selectedIds,\n expandMultipleTreeItems,\n toggleTreeItemExpansion,\n selectMultipleTreeItems,\n toggleTreeItemSelection,\n } = props;\n const value = useMemo<TreeContext<T>>(\n () => ({\n data,\n rootId,\n multiSelect,\n expanderIcon,\n expanderLeft,\n expansionMode,\n metadataLookup,\n disableTransition,\n temporaryChildItems,\n linkComponent,\n expandedIds,\n selectedIds,\n expandMultipleTreeItems,\n toggleTreeItemExpansion,\n selectMultipleTreeItems,\n toggleTreeItemSelection,\n }),\n [\n data,\n disableTransition,\n expandMultipleTreeItems,\n expandedIds,\n expanderIcon,\n expanderLeft,\n expansionMode,\n linkComponent,\n metadataLookup,\n multiSelect,\n rootId,\n selectMultipleTreeItems,\n selectedIds,\n temporaryChildItems,\n toggleTreeItemExpansion,\n toggleTreeItemSelection,\n ]\n );\n\n return <Provider value={value}>{children}</Provider>;\n}\n"],"names":["createContext","useContext","useMemo","context","undefined","displayName","Provider","useTreeContext","value","Error","TreeProvider","props","children","data","rootId","multiSelect","expanderIcon","expanderLeft","expansionMode","metadataLookup","disableTransition","temporaryChildItems","linkComponent","expandedIds","selectedIds","expandMultipleTreeItems","toggleTreeItemExpansion","selectMultipleTreeItems","toggleTreeItemSelection"],"mappings":"AAAA;;AAEA,SAGEA,aAAa,EACbC,UAAU,EACVC,OAAO,QACF,QAAQ;AA0Ff,kDAAkD;AAClD,8DAA8D;AAC9D,MAAMC,wBAAUH,cAA4CI;AAC5DD,QAAQE,WAAW,GAAG;AACtB,MAAM,EAAEC,QAAQ,EAAE,GAAGH;AAErB;;;;;CAKC,GACD,OAAO,SAASI;IAGd,MAAMC,QAAQP,WAAWE;IACzB,IAAI,CAACK,OAAO;QACV,MAAM,IAAIC,MAAM;IAClB;IAEA,OAAOD;AACT;AAYA;;;;;CAKC,GACD,OAAO,SAASE,aACdC,KAA2B;IAE3B,MAAM,EACJC,QAAQ,EACRC,IAAI,EACJC,MAAM,EACNC,WAAW,EACXC,YAAY,EACZC,YAAY,EACZC,aAAa,EACbC,cAAc,EACdC,iBAAiB,EACjBC,mBAAmB,EACnBC,aAAa,EACbC,WAAW,EACXC,WAAW,EACXC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACvBC,uBAAuB,EACxB,GAAGjB;IACJ,MAAMH,QAAQN,QACZ,IAAO,CAAA;YACLW;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;QACF,CAAA,GACA;QACEf;QACAO;QACAK;QACAF;QACAP;QACAC;QACAC;QACAI;QACAH;QACAJ;QACAD;QACAa;QACAH;QACAH;QACAK;QACAE;KACD;IAGH,qBAAO,KAACtB;QAASE,OAAOA;kBAAQI;;AAClC"}
|
package/dist/tree/styles.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/styles.ts"],"sourcesContent":["import { cnb } from \"cnbuilder\";\n\nimport { type InternalListItemClassNameOptions } from \"../list/listItemStyles.js\";\nimport { listItem } from \"../list/listItemStyles.js\";\nimport { bem } from \"../utils/bem.js\";\n\nconst treeStyles = bem(\"rmd-tree\");\nconst treeItemStyles = bem(\"rmd-tree-item\");\nconst treeGroupStyles = bem(\"rmd-tree-group\");\n\ndeclare module \"react\" {\n interface CSSProperties {\n \"--rmd-tree-depth\"?: number;\n \"--rmd-tree-item-padding\"?: string | number;\n \"--rmd-tree-item-padding-base\"?: string | number;\n \"--rmd-tree-item-padding-incrementor\"?: string | number;\n }\n}\n\n/** @since 6.0.0 */\nexport interface TreeClassNameOptions {\n className?: string;\n}\n\n/**\n * Apply the `className`s for a tree component. This will be type-safe if using\n * typescript.\n *\n * @since 6.0.0\n */\nexport function tree(options: TreeClassNameOptions = {}): string {\n const { className } = options;\n\n return cnb(treeStyles(), className);\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemClassNameOptions {\n className?: string;\n expander?: boolean;\n\n /**\n * Settings this to `true` will update the styles for the expander icon within\n * the tree item to rotate `down -> right` instead of `down -> left`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n}\n\n/**\n * Apply the `className`s for a tree item component. This will be type-safe if\n * using typescript.\n *\n * @since 6.0.0\n */\nexport function treeItem(options: TreeItemClassNameOptions = {}): string {\n const { className, expander = false, expanderLeft = false } = options;\n\n return cnb(\n treeItemStyles({\n \"expander-left\": expander && expanderLeft,\n \"expander-right\": expander && !expanderLeft,\n }),\n className\n );\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemContentClassNameOptions
|
|
1
|
+
{"version":3,"sources":["../../src/tree/styles.ts"],"sourcesContent":["import { cnb } from \"cnbuilder\";\n\nimport { type InternalListItemClassNameOptions } from \"../list/listItemStyles.js\";\nimport { listItem } from \"../list/listItemStyles.js\";\nimport { bem } from \"../utils/bem.js\";\n\nconst treeStyles = bem(\"rmd-tree\");\nconst treeItemStyles = bem(\"rmd-tree-item\");\nconst treeGroupStyles = bem(\"rmd-tree-group\");\n\ndeclare module \"react\" {\n interface CSSProperties {\n \"--rmd-tree-depth\"?: number;\n \"--rmd-tree-item-padding\"?: string | number;\n \"--rmd-tree-item-padding-base\"?: string | number;\n \"--rmd-tree-item-padding-incrementor\"?: string | number;\n }\n}\n\n/** @since 6.0.0 */\nexport interface TreeClassNameOptions {\n className?: string;\n}\n\n/**\n * Apply the `className`s for a tree component. This will be type-safe if using\n * typescript.\n *\n * @since 6.0.0\n */\nexport function tree(options: TreeClassNameOptions = {}): string {\n const { className } = options;\n\n return cnb(treeStyles(), className);\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemClassNameOptions {\n className?: string;\n expander?: boolean;\n\n /**\n * Settings this to `true` will update the styles for the expander icon within\n * the tree item to rotate `down -> right` instead of `down -> left`.\n *\n * @defaultValue `false`\n */\n expanderLeft?: boolean;\n}\n\n/**\n * Apply the `className`s for a tree item component. This will be type-safe if\n * using typescript.\n *\n * @since 6.0.0\n */\nexport function treeItem(options: TreeItemClassNameOptions = {}): string {\n const { className, expander = false, expanderLeft = false } = options;\n\n return cnb(\n treeItemStyles({\n \"expander-left\": expander && expanderLeft,\n \"expander-right\": expander && !expanderLeft,\n }),\n className\n );\n}\n\n/** @since 6.0.0 */\nexport interface TreeItemContentClassNameOptions extends InternalListItemClassNameOptions {\n /**\n * Set this\n *\n * @defaultValue `false`\n */\n link?: boolean;\n\n /**\n * Set this to `true` when the tree item is the current keyboard focus with\n * `aria-activedescendant`. This will apply the focus styles only while the\n * parent tree component is focused and the user is in keyboard mode.\n *\n *\n * @defaultValue `false`\n */\n focused?: boolean;\n\n /**\n * Set this to `true` hen the tree item has been selected by the user. The\n * default styles just\n *\n * @defaultValue `false`\n */\n selected?: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport function treeItemContent(\n options: TreeItemContentClassNameOptions = {}\n): string {\n const {\n className,\n link = false,\n focused,\n selected,\n disabled = false,\n ...remaining\n } = options;\n\n return cnb(\n treeItemStyles(\"content\", {\n link,\n focused,\n selected,\n disabled,\n }),\n listItem({\n className,\n disabled,\n ...remaining,\n })\n );\n}\n\n/**\n * @since 6.0.0\n */\nexport interface TreeItemMediaClassNameOptions {\n className?: string;\n isLeafNode: boolean;\n isMediaLeftAddon: boolean;\n}\n\n/**\n * @since 6.0.0\n */\nexport function treeItemMedia(options: TreeItemMediaClassNameOptions): string {\n const { isLeafNode, isMediaLeftAddon, className } = options;\n\n return cnb(\n isMediaLeftAddon && treeItemStyles(\"media\", { single: isLeafNode }),\n className\n );\n}\n\n/** @since 6.0.0 */\nexport interface TreeGroupClassNameOptions {\n className?: string;\n}\n\n/**\n * @since 6.0.0\n */\nexport function treeGroup(options: TreeGroupClassNameOptions = {}): string {\n const { className } = options;\n\n return cnb(treeGroupStyles(), className);\n}\n"],"names":["cnb","listItem","bem","treeStyles","treeItemStyles","treeGroupStyles","tree","options","className","treeItem","expander","expanderLeft","treeItemContent","link","focused","selected","disabled","remaining","treeItemMedia","isLeafNode","isMediaLeftAddon","single","treeGroup"],"mappings":"AAAA,SAASA,GAAG,QAAQ,YAAY;AAGhC,SAASC,QAAQ,QAAQ,4BAA4B;AACrD,SAASC,GAAG,QAAQ,kBAAkB;AAEtC,MAAMC,aAAaD,IAAI;AACvB,MAAME,iBAAiBF,IAAI;AAC3B,MAAMG,kBAAkBH,IAAI;AAgB5B;;;;;CAKC,GACD,OAAO,SAASI,KAAKC,UAAgC,CAAC,CAAC;IACrD,MAAM,EAAEC,SAAS,EAAE,GAAGD;IAEtB,OAAOP,IAAIG,cAAcK;AAC3B;AAgBA;;;;;CAKC,GACD,OAAO,SAASC,SAASF,UAAoC,CAAC,CAAC;IAC7D,MAAM,EAAEC,SAAS,EAAEE,WAAW,KAAK,EAAEC,eAAe,KAAK,EAAE,GAAGJ;IAE9D,OAAOP,IACLI,eAAe;QACb,iBAAiBM,YAAYC;QAC7B,kBAAkBD,YAAY,CAACC;IACjC,IACAH;AAEJ;AA8BA;;CAEC,GACD,OAAO,SAASI,gBACdL,UAA2C,CAAC,CAAC;IAE7C,MAAM,EACJC,SAAS,EACTK,OAAO,KAAK,EACZC,OAAO,EACPC,QAAQ,EACRC,WAAW,KAAK,EAChB,GAAGC,WACJ,GAAGV;IAEJ,OAAOP,IACLI,eAAe,WAAW;QACxBS;QACAC;QACAC;QACAC;IACF,IACAf,SAAS;QACPO;QACAQ;QACA,GAAGC,SAAS;IACd;AAEJ;AAWA;;CAEC,GACD,OAAO,SAASC,cAAcX,OAAsC;IAClE,MAAM,EAAEY,UAAU,EAAEC,gBAAgB,EAAEZ,SAAS,EAAE,GAAGD;IAEpD,OAAOP,IACLoB,oBAAoBhB,eAAe,SAAS;QAAEiB,QAAQF;IAAW,IACjEX;AAEJ;AAOA;;CAEC,GACD,OAAO,SAASc,UAAUf,UAAqC,CAAC,CAAC;IAC/D,MAAM,EAAEC,SAAS,EAAE,GAAGD;IAEtB,OAAOP,IAAIK,mBAAmBG;AAChC"}
|
package/dist/tree/types.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/types.ts"],"sourcesContent":["import { type ReactNode } from \"react\";\n\nimport { type ListItemChildrenProps } from \"../list/types.js\";\nimport { type UseStateInitializer } from \"../types.js\";\nimport { type RenderRecursiveItemsProps } from \"../utils/RenderRecursively.js\";\n\n/**\n * @since 6.0.0 This was renamed from `TreeItemIds`\n */\nexport interface TreeItemNode {\n itemId: string;\n parentId: string | null;\n}\n\n/**\n * The default tree item node allows for any props for rendering children within\n * list items and rendering links.\n *\n * @since 6.0.0\n */\nexport interface DefaultTreeItemNode\n extends TreeItemNode
|
|
1
|
+
{"version":3,"sources":["../../src/tree/types.ts"],"sourcesContent":["import { type ReactNode } from \"react\";\n\nimport { type ListItemChildrenProps } from \"../list/types.js\";\nimport { type UseStateInitializer } from \"../types.js\";\nimport { type RenderRecursiveItemsProps } from \"../utils/RenderRecursively.js\";\n\n/**\n * @since 6.0.0 This was renamed from `TreeItemIds`\n */\nexport interface TreeItemNode {\n itemId: string;\n parentId: string | null;\n}\n\n/**\n * The default tree item node allows for any props for rendering children within\n * list items and rendering links.\n *\n * @since 6.0.0\n */\nexport interface DefaultTreeItemNode\n extends TreeItemNode, ListItemChildrenProps {\n /**\n * If this is defined, the `TreeItem` will render the content within a `Link`\n * instead of a `<span>`.\n */\n to?: string;\n\n /**\n * If this is defined, the `TreeItem` will render the content within a `Link`\n * instead of a `<span>`.\n */\n href?: string;\n\n /**\n * This should only be provided if {@link to} or {@link href} exist on the\n * node.\n */\n rel?: string;\n\n /**\n * This should only be provided if {@link to} or {@link href} exist on the\n * node.\n */\n target?: string;\n\n /**\n * An alias for the {@link children} within a tree item. This will be used\n * over the {@link children} if both exist.\n */\n name?: ReactNode;\n\n /**\n * The children to display in the tree item.\n *\n * @see {@link name}\n */\n children?: ReactNode;\n\n /** @see {@link ListItemProps.disabled} */\n disabled?: boolean;\n\n /** @see {@link ListItemProps.disabledOpacity} */\n disabledOpacity?: boolean;\n\n className?: string;\n contentClassName?: string;\n}\n\n/**\n * @example Default Structure\n * ```tsx\n * import { type TreeData } from \"@react-md/core/tree/types\";\n * import FolderIcon from \"@react-md/material-icons/FolderIcon\";\n *\n * export const MY_DATA: TreeData = {\n * \"item-1\": {\n * itemId: \"item-1\",\n * parentId: null,\n * name: \"Root Level Item 1\",\n * },\n * \"item-2\": {\n * itemId: \"item-2\",\n * parentId: \"item-1\",\n * name: \"A child for the first item\",\n * leftAddon: <FolderIcon />,\n * },\n * \"item-3\": {\n * itemId: \"item-3\",\n * parentId: \"item-1\",\n * children: \"Another child for the first item\",\n * leftAddon: <FolderIcon />,\n * rightAddon: <span>Something custom</span>,\n * },\n * };\n * ```\n *\n * @since 6.0.0 Updated the default types\n * @see {@link DefaultTreeItemNode}\n */\nexport type TreeData<T extends TreeItemNode = DefaultTreeItemNode> = Record<\n string,\n T\n>;\n\n/**\n * @since 6.0.0 This used to be `ExpandedIds`/`SelectedIds` but was converted to\n * a `Set` to increase performance for large trees.\n */\nexport type TreeItemIdSet = ReadonlySet<string>;\n\n/**\n * @since 6.0.0\n */\nexport type TreeDefaultIds = UseStateInitializer<\n readonly string[] | ReadonlySet<string>\n>;\n\n/**\n * A function to call that will sort the items within the tree for each unique\n * `parentId`. If you have a tree like:\n *\n * ```\n * a\n * ├── a1\n * b\n * ├── b1\n * ├── b2\n * │ └── b2.1\n * c\n * ├── c1\n * ├── c2\n * └── c3\n * ```\n *\n * This function will be called with:\n *\n * - `[a1]`\n * - `[b2.1]`\n * - `[b1, b2]`\n * - `[c1, c2, c3]`\n * - `[a, b, c]`\n *\n * Note: This **should be memoized** to prevent rerendering the entire tree each\n * render.\n */\nexport type TreeItemSorter<T extends TreeItemNode = DefaultTreeItemNode> = (\n items: readonly T[]\n) => readonly T[];\n\n/**\n * @since 6.0.0\n */\nexport type TreeItemRendererProps<\n T extends TreeItemNode = DefaultTreeItemNode,\n> = RenderRecursiveItemsProps<T, TreeData<T>>;\n"],"names":[],"mappings":"AAsJA;;CAEC,GACD,WAE8C"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/tree/useTreeMovement.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n FocusEventHandler,\n KeyboardEventHandler,\n MouseEventHandler,\n Ref,\n} from \"react\";\nimport { useRef } from \"react\";\n\nimport type { KeyboardMovementProviderImplementation } from \"../movement/types.js\";\nimport { useKeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { getNextFocusableIndex } from \"../movement/utils.js\";\nimport type { NonNullMutableRef } from \"../types.js\";\nimport type { TreeItemMetadataLookup } from \"./TreeProvider.js\";\nimport type { TreeData, TreeItemNode } from \"./types.js\";\nimport type { TreeExpansion } from \"./useTreeExpansion.js\";\nimport type { TreeItemChildIds } from \"./useTreeItems.js\";\n\n/**\n * This helps catch the edge case where the collapse transition has occurred for\n * a tree item group, but the user uses the `ArrowDown` key before it has\n * finished. So to do this:\n *\n * - find the parent group of the tree item\n * - find the tree item that controls the group (the element before the group)\n * - check if the `aria-expanded` state is `\"false\"` meaning it is considered\n * closed\n *\n * @internal\n * @since 6.0.0\n */\nconst isParentItemCollapsing = (item: HTMLElement): boolean =>\n item\n .closest(\"[role='group']\")\n ?.previousElementSibling?.getAttribute(\"aria-expanded\") === \"false\";\n\n/**\n * @since 6.0.0\n * @internal\n */\nconst getVisibleTreeItems = (\n container: HTMLElement\n): readonly HTMLElement[] => {\n const items = [\n ...container.querySelectorAll<HTMLElement>('[role=\"treeitem\"]'),\n ];\n\n return items.filter(\n (item) =>\n // do not include items that have a `hidden` parent group\n item.offsetParent &&\n // do not include items that are about to become hidden\n !isParentItemCollapsing(item)\n );\n};\n\n/**\n * @since 6.0.0\n * @internal\n */\ninterface TreeMovementOptions<T extends TreeItemNode> extends TreeExpansion {\n ref?: Ref<HTMLUListElement>;\n data: TreeData<T>;\n onClick: MouseEventHandler<HTMLUListElement> | undefined;\n onFocus: FocusEventHandler<HTMLUListElement> | undefined;\n onKeyDown: KeyboardEventHandler<HTMLUListElement> | undefined;\n selectedIds: ReadonlySet<string>;\n treeItemChildIds: TreeItemChildIds;\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\ninterface TreeMovement
|
|
1
|
+
{"version":3,"sources":["../../src/tree/useTreeMovement.ts"],"sourcesContent":["\"use client\";\n\nimport type {\n FocusEventHandler,\n KeyboardEventHandler,\n MouseEventHandler,\n Ref,\n} from \"react\";\nimport { useRef } from \"react\";\n\nimport type { KeyboardMovementProviderImplementation } from \"../movement/types.js\";\nimport { useKeyboardMovementProvider } from \"../movement/useKeyboardMovementProvider.js\";\nimport { getNextFocusableIndex } from \"../movement/utils.js\";\nimport type { NonNullMutableRef } from \"../types.js\";\nimport type { TreeItemMetadataLookup } from \"./TreeProvider.js\";\nimport type { TreeData, TreeItemNode } from \"./types.js\";\nimport type { TreeExpansion } from \"./useTreeExpansion.js\";\nimport type { TreeItemChildIds } from \"./useTreeItems.js\";\n\n/**\n * This helps catch the edge case where the collapse transition has occurred for\n * a tree item group, but the user uses the `ArrowDown` key before it has\n * finished. So to do this:\n *\n * - find the parent group of the tree item\n * - find the tree item that controls the group (the element before the group)\n * - check if the `aria-expanded` state is `\"false\"` meaning it is considered\n * closed\n *\n * @internal\n * @since 6.0.0\n */\nconst isParentItemCollapsing = (item: HTMLElement): boolean =>\n item\n .closest(\"[role='group']\")\n ?.previousElementSibling?.getAttribute(\"aria-expanded\") === \"false\";\n\n/**\n * @since 6.0.0\n * @internal\n */\nconst getVisibleTreeItems = (\n container: HTMLElement\n): readonly HTMLElement[] => {\n const items = [\n ...container.querySelectorAll<HTMLElement>('[role=\"treeitem\"]'),\n ];\n\n return items.filter(\n (item) =>\n // do not include items that have a `hidden` parent group\n item.offsetParent &&\n // do not include items that are about to become hidden\n !isParentItemCollapsing(item)\n );\n};\n\n/**\n * @since 6.0.0\n * @internal\n */\ninterface TreeMovementOptions<T extends TreeItemNode> extends TreeExpansion {\n ref?: Ref<HTMLUListElement>;\n data: TreeData<T>;\n onClick: MouseEventHandler<HTMLUListElement> | undefined;\n onFocus: FocusEventHandler<HTMLUListElement> | undefined;\n onKeyDown: KeyboardEventHandler<HTMLUListElement> | undefined;\n selectedIds: ReadonlySet<string>;\n treeItemChildIds: TreeItemChildIds;\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\ninterface TreeMovement extends KeyboardMovementProviderImplementation<HTMLUListElement> {\n /**\n * This will be mutated by the `TreeItem` component and used to handle\n * keyboard movement.\n */\n metadataLookup: NonNullMutableRef<TreeItemMetadataLookup>;\n}\n\n/**\n * @since 6.0.0\n * @internal\n */\nexport function useTreeMovement<T extends TreeItemNode>(\n options: TreeMovementOptions<T>\n): TreeMovement {\n const {\n ref,\n onClick,\n onFocus,\n onKeyDown,\n data,\n expandedIds,\n selectedIds,\n treeItemChildIds,\n toggleTreeItemExpansion,\n expandMultipleTreeItems,\n } = options;\n\n const metadataLookup = useRef<TreeItemMetadataLookup>({\n expandable: {},\n disabledItems: {},\n elementToItem: {},\n itemToElement: {},\n });\n const movement = useKeyboardMovementProvider({\n ref,\n onClick,\n onFocus,\n onKeyDown,\n extendKeyDown(movementData) {\n const { event, activeDescendantId, currentFocusIndex, setFocusIndex } =\n movementData;\n const { expandable, disabledItems, elementToItem, itemToElement } =\n metadataLookup.current;\n const itemId = elementToItem[activeDescendantId];\n const item = data[itemId];\n\n /* c8 ignore start */\n if (!item) {\n return;\n }\n /* c8 ignore stop */\n\n const disabled = disabledItems[itemId];\n const expanded = expandedIds.has(itemId);\n\n let flagged = false;\n switch (event.key) {\n case \"ArrowLeft\":\n if (expanded && !disabled) {\n flagged = true;\n toggleTreeItemExpansion(itemId);\n } else if (item.parentId) {\n // do not flag for this case since setFocusIndex already does this\n const parentId = itemToElement[item.parentId];\n const focusables = getVisibleTreeItems(event.currentTarget);\n const index = focusables.findIndex(\n (element) => element.id === parentId\n );\n setFocusIndex(index, focusables);\n }\n\n break;\n case \"ArrowRight\":\n if (expandable[itemId] && !disabled) {\n if (!expanded) {\n flagged = true;\n toggleTreeItemExpansion(itemId);\n } else {\n // do not flag for this case since setFocusIndex already does this\n const focusables = getVisibleTreeItems(event.currentTarget);\n const index = getNextFocusableIndex({\n loopable: false,\n increment: true,\n focusables,\n includeDisabled: true,\n currentFocusIndex: currentFocusIndex.current,\n });\n\n setFocusIndex(index, focusables);\n }\n }\n\n break;\n case \"*\": {\n flagged = true;\n const itemIds = treeItemChildIds.get(item.parentId);\n if (itemIds) {\n const expandableIds = [...itemIds].filter(\n (itemId) => expandable[itemId]\n );\n if (expandableIds.length) {\n expandMultipleTreeItems(\n (prev) => new Set([...prev, ...expandableIds])\n );\n currentFocusIndex.current = -1;\n }\n }\n break;\n }\n }\n\n if (flagged) {\n event.stopPropagation();\n event.preventDefault();\n }\n },\n searchable: true,\n tabIndexBehavior: \"virtual\",\n getFocusableElements: getVisibleTreeItems,\n getDefaultFocusedIndex(options) {\n const { focusables } = options;\n const { elementToItem } = metadataLookup.current;\n\n return focusables.findIndex((element) =>\n selectedIds.has(elementToItem[element.id])\n );\n },\n });\n\n return {\n metadataLookup,\n ...movement,\n };\n}\n"],"names":["useRef","useKeyboardMovementProvider","getNextFocusableIndex","isParentItemCollapsing","item","closest","previousElementSibling","getAttribute","getVisibleTreeItems","container","items","querySelectorAll","filter","offsetParent","useTreeMovement","options","ref","onClick","onFocus","onKeyDown","data","expandedIds","selectedIds","treeItemChildIds","toggleTreeItemExpansion","expandMultipleTreeItems","metadataLookup","expandable","disabledItems","elementToItem","itemToElement","movement","extendKeyDown","movementData","event","activeDescendantId","currentFocusIndex","setFocusIndex","current","itemId","disabled","expanded","has","flagged","key","parentId","focusables","currentTarget","index","findIndex","element","id","loopable","increment","includeDisabled","itemIds","get","expandableIds","length","prev","Set","stopPropagation","preventDefault","searchable","tabIndexBehavior","getFocusableElements","getDefaultFocusedIndex"],"mappings":"AAAA;AAQA,SAASA,MAAM,QAAQ,QAAQ;AAG/B,SAASC,2BAA2B,QAAQ,6CAA6C;AACzF,SAASC,qBAAqB,QAAQ,uBAAuB;AAO7D;;;;;;;;;;;;CAYC,GACD,MAAMC,yBAAyB,CAACC,OAC9BA,KACGC,OAAO,CAAC,mBACPC,wBAAwBC,aAAa,qBA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AACb,aAAa,CAACqB,QAAQC,EAAE,CAAC;QAE7C;IACF;IAEA,OAAO;QACLzB;QACA,GAAGK,QAAQ;IACb;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typography/HighlightTextMark.tsx"],"sourcesContent":["import { type ReactElement } from \"react\";\n\nimport { type HighlightTextComponentProps } from \"./HighlightText.js\";\nimport { Mark, type MarkProps } from \"./Mark.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface HighlightTextMarkProps\n extends HighlightTextComponentProps
|
|
1
|
+
{"version":3,"sources":["../../src/typography/HighlightTextMark.tsx"],"sourcesContent":["import { type ReactElement } from \"react\";\n\nimport { type HighlightTextComponentProps } from \"./HighlightText.js\";\nimport { Mark, type MarkProps } from \"./Mark.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface HighlightTextMarkProps\n extends HighlightTextComponentProps, Omit<MarkProps, \"children\"> {}\n\n/**\n * This is the default implementation for the `HighlightText` component that\n * just omits the `match` prop from {@link HighlightTextComponentProps} and\n * passes the rest to the {@link Mark}.\n *\n * @since 6.0.0\n */\nexport function HighlightTextMark(\n props: Readonly<HighlightTextMarkProps>\n): ReactElement {\n const { match: _match, ...remaining } = props;\n return <Mark {...remaining} />;\n}\n"],"names":["Mark","HighlightTextMark","props","match","_match","remaining"],"mappings":";AAGA,SAASA,IAAI,QAAwB,YAAY;AAQjD;;;;;;CAMC,GACD,OAAO,SAASC,kBACdC,KAAuC;IAEvC,MAAM,EAAEC,OAAOC,MAAM,EAAE,GAAGC,WAAW,GAAGH;IACxC,qBAAO,KAACF;QAAM,GAAGK,SAAS;;AAC5B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typography/Mark.tsx"],"sourcesContent":["import { type HTMLAttributes, type ReactNode, forwardRef } from \"react\";\n\nimport { type MarkClassNameOptions, mark } from \"./markStyles.js\";\n\n/**\n * @since 6.0.0\n * @since 6.3.1 Extends MarkClassNameOptions for CSSProperties module\n * augmentation.\n */\nexport interface MarkProps\n extends HTMLAttributes<HTMLElement
|
|
1
|
+
{"version":3,"sources":["../../src/typography/Mark.tsx"],"sourcesContent":["import { type HTMLAttributes, type ReactNode, forwardRef } from \"react\";\n\nimport { type MarkClassNameOptions, mark } from \"./markStyles.js\";\n\n/**\n * @since 6.0.0\n * @since 6.3.1 Extends MarkClassNameOptions for CSSProperties module\n * augmentation.\n */\nexport interface MarkProps\n extends HTMLAttributes<HTMLElement>, MarkClassNameOptions {\n children: ReactNode;\n}\n\n/**\n * The `Mark` component can be used in place of the `mark` HTMLElement with\n * some default styles.\n *\n * @example Simple Example\n * ```tsx\n * import { Mark } from \"@react-md/core/typography/Mark\";\n *\n * export function Example() {\n * return (\n * <>\n * Some text <Mark>that has highlights</Mark> and some other text.\n * </>\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/mark | Mark Demos}\n * @since 6.0.0\n */\nexport const Mark = forwardRef<HTMLElement, MarkProps>(\n function Mark(props, ref) {\n const { children, className, ...remaining } = props;\n return (\n <mark {...remaining} ref={ref} className={mark({ className })}>\n {children}\n </mark>\n );\n }\n);\n"],"names":["forwardRef","mark","Mark","props","ref","children","className","remaining"],"mappings":";AAAA,SAA8CA,UAAU,QAAQ,QAAQ;AAExE,SAAoCC,IAAI,QAAQ,kBAAkB;AAYlE;;;;;;;;;;;;;;;;;;;CAmBC,GACD,OAAO,MAAMC,qBAAOF,WAClB,SAASE,KAAKC,KAAK,EAAEC,GAAG;IACtB,MAAM,EAAEC,QAAQ,EAAEC,SAAS,EAAE,GAAGC,WAAW,GAAGJ;IAC9C,qBACE,KAACF;QAAM,GAAGM,SAAS;QAAEH,KAAKA;QAAKE,WAAWL,KAAK;YAAEK;QAAU;kBACxDD;;AAGP,GACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typography/TextContainer.tsx"],"sourcesContent":["import { type HTMLAttributes, forwardRef } from \"react\";\n\nimport {\n type TextContainerClassNameOptions,\n textContainer,\n} from \"./textContainerStyles.js\";\n\n/**\n * @since 6.0.0 Removed the `size` option since there is no longer a\n * different line-length for mobile and desktop.\n * @since 6.0.0 Removed the `clone` prop and the children render function\n * behavior. Use the `textContainer` class name utility instead.\n */\nexport interface TextContainerProps\n extends HTMLAttributes<HTMLDivElement
|
|
1
|
+
{"version":3,"sources":["../../src/typography/TextContainer.tsx"],"sourcesContent":["import { type HTMLAttributes, forwardRef } from \"react\";\n\nimport {\n type TextContainerClassNameOptions,\n textContainer,\n} from \"./textContainerStyles.js\";\n\n/**\n * @since 6.0.0 Removed the `size` option since there is no longer a\n * different line-length for mobile and desktop.\n * @since 6.0.0 Removed the `clone` prop and the children render function\n * behavior. Use the `textContainer` class name utility instead.\n */\nexport interface TextContainerProps\n extends HTMLAttributes<HTMLDivElement>, TextContainerClassNameOptions {}\n\n/**\n * This component should be used to render text based content with an\n * appropriate max line length to optimize legibility.\n *\n * @example Simple Example\n * ```tsx\n * import { TextContainer } from \"@react-md/core/typography/TextContainer\";\n * import { Typography } from \"@react-md/core/typography/Typography\";\n *\n * function Example() {\n * return (\n * <TextContainer>\n * <Typography type=\"headline-1\">Heading</Typography>\n * <Typography>\n * Pretend this is a giant paragraph of text that wraps multiple lines.\n * </Typography>\n * <Typography>\n * Pretend this is another giant paragraph of text that wraps multiple\n * lines.\n * </Typography>\n * </TextContainer>\n * );\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/text-container | TextContainer Demos}\n * @see {@link textContainer} If you only want to apply this class to an\n * element.\n * @since 6.0.0 Removed the `size` option since there is no longer a\n * different line-length for mobile and desktop.\n * @since 6.0.0 Removed the `clone` prop and the children render function\n * behavior. Use the `textContainer` class name utility instead.\n */\nexport const TextContainer = forwardRef<HTMLDivElement, TextContainerProps>(\n function TextContainer(props, ref) {\n const { className, children, ...remaining } = props;\n\n return (\n <div {...remaining} ref={ref} className={textContainer({ className })}>\n {children}\n </div>\n );\n }\n);\n"],"names":["forwardRef","textContainer","TextContainer","props","ref","className","children","remaining","div"],"mappings":";AAAA,SAA8BA,UAAU,QAAQ,QAAQ;AAExD,SAEEC,aAAa,QACR,2BAA2B;AAWlC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAgCC,GACD,OAAO,MAAMC,8BAAgBF,WAC3B,SAASE,cAAcC,KAAK,EAAEC,GAAG;IAC/B,MAAM,EAAEC,SAAS,EAAEC,QAAQ,EAAE,GAAGC,WAAW,GAAGJ;IAE9C,qBACE,KAACK;QAAK,GAAGD,SAAS;QAAEH,KAAKA;QAAKC,WAAWJ,cAAc;YAAEI;QAAU;kBAChEC;;AAGP,GACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/typography/Typography.tsx"],"sourcesContent":["import {\n type ElementType,\n type HTMLAttributes,\n type ReactElement,\n forwardRef,\n} from \"react\";\n\nimport {\n type TypographyClassNameOptions,\n type TypographyType,\n typography,\n} from \"./typographyStyles.js\";\n\n/**\n * A union of the default supported elements that the `Typography` component can\n * be rendered as. This is mostly used for adding the correct `HTMLAttributes`\n * and enabling the forward ref.\n *\n * @since 4.0.0\n */\nexport type TypographyHTMLElement =\n | HTMLHeadingElement\n | HTMLParagraphElement\n | HTMLSpanElement\n | HTMLDivElement\n | HTMLAnchorElement\n | HTMLBodyElement\n | HTMLHtmlElement;\n\n/** @since 6.0.0 */\nexport type CustomTypographyComponent = ElementType<\n HTMLAttributes<TypographyHTMLElement> & { className: string }\n>;\n\n/** @internal */\nfunction getComponent(\n as: CustomTypographyComponent | undefined,\n type: TypographyType\n): ElementType {\n if (as) {\n return as;\n }\n\n switch (type) {\n case \"headline-1\":\n return \"h1\";\n case \"headline-2\":\n return \"h2\";\n case \"headline-3\":\n return \"h3\";\n case \"headline-4\":\n return \"h4\";\n case \"headline-5\":\n return \"h5\";\n case \"headline-6\":\n case \"subtitle-1\":\n case \"subtitle-2\":\n return \"h6\";\n case \"body-1\":\n case \"body-2\":\n return \"p\";\n case \"caption\":\n return \"caption\";\n default:\n return \"span\";\n }\n}\n\n/**\n * @since 6.0.0 Renamed `component` to `as`.\n * @since 6.0.0 Removed the children render function behavior. Use the\n * `typography` class name utility instead.\n */\nexport interface TypographyProps\n extends HTMLAttributes<TypographyHTMLElement
|
|
1
|
+
{"version":3,"sources":["../../src/typography/Typography.tsx"],"sourcesContent":["import {\n type ElementType,\n type HTMLAttributes,\n type ReactElement,\n forwardRef,\n} from \"react\";\n\nimport {\n type TypographyClassNameOptions,\n type TypographyType,\n typography,\n} from \"./typographyStyles.js\";\n\n/**\n * A union of the default supported elements that the `Typography` component can\n * be rendered as. This is mostly used for adding the correct `HTMLAttributes`\n * and enabling the forward ref.\n *\n * @since 4.0.0\n */\nexport type TypographyHTMLElement =\n | HTMLHeadingElement\n | HTMLParagraphElement\n | HTMLSpanElement\n | HTMLDivElement\n | HTMLAnchorElement\n | HTMLBodyElement\n | HTMLHtmlElement;\n\n/** @since 6.0.0 */\nexport type CustomTypographyComponent = ElementType<\n HTMLAttributes<TypographyHTMLElement> & { className: string }\n>;\n\n/** @internal */\nfunction getComponent(\n as: CustomTypographyComponent | undefined,\n type: TypographyType\n): ElementType {\n if (as) {\n return as;\n }\n\n switch (type) {\n case \"headline-1\":\n return \"h1\";\n case \"headline-2\":\n return \"h2\";\n case \"headline-3\":\n return \"h3\";\n case \"headline-4\":\n return \"h4\";\n case \"headline-5\":\n return \"h5\";\n case \"headline-6\":\n case \"subtitle-1\":\n case \"subtitle-2\":\n return \"h6\";\n case \"body-1\":\n case \"body-2\":\n return \"p\";\n case \"caption\":\n return \"caption\";\n default:\n return \"span\";\n }\n}\n\n/**\n * @since 6.0.0 Renamed `component` to `as`.\n * @since 6.0.0 Removed the children render function behavior. Use the\n * `typography` class name utility instead.\n */\nexport interface TypographyProps\n extends HTMLAttributes<TypographyHTMLElement>, TypographyClassNameOptions {\n /**\n * The component to render as when the children are not a render function. If\n * this prop is omitted, the component will be determined by the `type` prop\n * where:\n *\n * - `\"headline-1\" -> <h1>`\n * - `\"headline-2\" -> <h2>`\n * - `\"headline-3\" -> <h3>`\n * - `\"headline-4\" -> <h4>`\n * - `\"headline-5\" -> <h5>`\n * - `\"headline-6\" -> <h6>`\n * - `\"subtitle-1\" -> <h5>`\n * - `\"subtitle-2\" -> <h6>`\n * - `\"body-1\" -> <p>`\n * - `\"body-2\" -> <p>`\n * - `\"caption\" -> <caption>`\n * - `\"overline\" -> <span>`\n *\n * @since 6.0.0 Renamed from `component`\n */\n as?: CustomTypographyComponent;\n}\n\n/**\n * Render text with one of the material design typography styles applied and\n * optional styles like font-weight, font-style, text color, etc.\n *\n * @example All Example\n * ```tsx\n * import { Typography } from \"@react-md/core/typography/Typography\":\n *\n * export function Example() {\n * return (\n * <>\n * <Typography type=\"headline-1\">Headline 1</Typography>\n * <Typography type=\"headline-2\">Headline 2</Typography>\n * <Typography type=\"headline-3\">Headline 3</Typography>\n * <Typography type=\"headline-4\">Headline 4</Typography>\n * <Typography type=\"headline-5\">Headline 5</Typography>\n * <Typography type=\"headline-6\">Headline 6</Typography>\n * <Typography type=\"subtitle-1\">Subtitle 1</Typography>\n * <Typography type=\"subtitle-2\">Subtitle 2</Typography>\n * <Typography>\n * A paragraph of text.\n * </Typography>\n * <Typography type=\"body-1\">\n * A paragraph of text.\n * </Typography>\n * <Typography type=\"body-2\">\n * Another paragraph of text.\n * </Typography>\n * <Typography type=\"caption\" component=\"h5\">\n * Caption text\n * </Typography>\n * <Typography type=\"overline\" component=\"h5\">\n * Overline text\n * </Typography>\n * </>\n * ):\n * }\n * ```\n *\n * @see {@link https://react-md.dev/components/typography | Typography Demos}\n * @since 6.0.0 Removed the children render function behavior . Use the\n * `typography` class name utility instead.\n */\nexport const Typography = forwardRef<TypographyHTMLElement, TypographyProps>(\n function Typography(props, ref): ReactElement {\n const {\n as,\n type = \"body-1\",\n className,\n margin,\n fontStyle,\n fontWeight,\n textAlign,\n textColor,\n textDecoration,\n textTransform,\n textOverflow,\n children,\n ...remaining\n } = props;\n\n const Component = getComponent(as, type);\n return (\n <Component\n {...remaining}\n ref={ref}\n className={typography({\n type,\n margin,\n fontStyle,\n fontWeight,\n textAlign,\n textColor,\n textDecoration,\n textTransform,\n textOverflow,\n className,\n })}\n >\n {children}\n </Component>\n );\n }\n);\n"],"names":["forwardRef","typography","getComponent","as","type","Typography","props","ref","className","margin","fontStyle","fontWeight","textAlign","textColor","textDecoration","textTransform","textOverflow","children","remaining","Component"],"mappings":";AAAA,SAIEA,UAAU,QACL,QAAQ;AAEf,SAGEC,UAAU,QACL,wBAAwB;AAuB/B,cAAc,GACd,SAASC,aACPC,EAAyC,EACzCC,IAAoB;IAEpB,IAAID,IAAI;QACN,OAAOA;IACT;IAEA,OAAQC;QACN,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT,KAAK;QACL,KAAK;QACL,KAAK;YACH,OAAO;QACT,KAAK;QACL,KAAK;YACH,OAAO;QACT,KAAK;YACH,OAAO;QACT;YACE,OAAO;IACX;AACF;AAgCA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA0CC,GACD,OAAO,MAAMC,2BAAaL,WACxB,SAASK,WAAWC,KAAK,EAAEC,GAAG;IAC5B,MAAM,EACJJ,EAAE,EACFC,OAAO,QAAQ,EACfI,SAAS,EACTC,MAAM,EACNC,SAAS,EACTC,UAAU,EACVC,SAAS,EACTC,SAAS,EACTC,cAAc,EACdC,aAAa,EACbC,YAAY,EACZC,QAAQ,EACR,GAAGC,WACJ,GAAGZ;IAEJ,MAAMa,YAAYjB,aAAaC,IAAIC;IACnC,qBACE,KAACe;QACE,GAAGD,SAAS;QACbX,KAAKA;QACLC,WAAWP,WAAW;YACpBG;YACAK;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;YACAR;QACF;kBAECS;;AAGP,GACA"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useElementSize.ts"],"sourcesContent":["\"use client\";\n\nimport { type RefCallback, useCallback, useRef, useState } from \"react\";\n\nimport { type ElementSize, type UseStateInitializer } from \"./types.js\";\nimport {\n type ResizeObserverHookOptions,\n useResizeObserver,\n} from \"./useResizeObserver.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface ElementSizeOptions<E extends HTMLElement
|
|
1
|
+
{"version":3,"sources":["../src/useElementSize.ts"],"sourcesContent":["\"use client\";\n\nimport { type RefCallback, useCallback, useRef, useState } from \"react\";\n\nimport { type ElementSize, type UseStateInitializer } from \"./types.js\";\nimport {\n type ResizeObserverHookOptions,\n useResizeObserver,\n} from \"./useResizeObserver.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface ElementSizeOptions<E extends HTMLElement> extends Omit<\n ResizeObserverHookOptions<E>,\n \"onUpdate\"\n> {\n /** @defaultValue `{ height: 0, width: 0 }` */\n defaultValue?: UseStateInitializer<ElementSize>;\n}\n\n/**\n * @since 6.0.0\n */\nexport interface ElementSizeImplementation<\n E extends HTMLElement,\n> extends ElementSize {\n elementRef: RefCallback<E>;\n\n /**\n * This will be `true` once the resize observer's callback is triggered at\n * least once.\n *\n * This was added so that generating custom properties that have a reasonable\n * default value set in css don't cause major layout shifts when a default\n * value cannot be provided.\n *\n * @example\n * ```tsx\n * const { height, width, observedOnce } = useElementSize();\n * useCSSVariables(useMemo(() => {\n * if (!observedOnce) {\n * return []\n * }\n *\n * // something that uses the element's height, width, or both\n * return [{ var: \"--something\", value: height / width * 0.5 }];\n * }, [height, width, observedOnce]));\n * ```\n */\n observedOnce: boolean;\n}\n\n/**\n * A small wrapper around the {@link useResizeObserver} hook to calculate the\n * element's size.\n *\n * @example Simple Example\n * ```tsx\n * import { useElementSize } from \"@react-md/core/useElementSize\";\n * import { type ReactElement } from \"react\";\n *\n * function Example(): ReactElement {\n * const { height, width, elementRef } = useElementSize();\n *\n * return (\n * <div ref={elementRef}>\n * {`height: ${height}, width: ${width}`}\n * </div>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useElementSize<E extends HTMLElement>(\n options: ElementSizeOptions<E> = {}\n): ElementSizeImplementation<E> {\n const { defaultValue } = options;\n\n const observedOnce = useRef(false);\n const [size, setSize] = useState<ElementSize>(() => {\n if (typeof defaultValue === \"function\") {\n return defaultValue();\n }\n\n return (\n defaultValue ?? {\n height: 0,\n width: 0,\n }\n );\n });\n\n const elementRef = useResizeObserver({\n ...options,\n onUpdate: useCallback((entry) => {\n observedOnce.current = true;\n const size = entry.borderBoxSize[0];\n\n setSize({\n height: size.blockSize,\n width: size.inlineSize,\n });\n }, []),\n });\n\n return {\n ...size,\n elementRef,\n observedOnce: observedOnce.current,\n };\n}\n"],"names":["useCallback","useRef","useState","useResizeObserver","useElementSize","options","defaultValue","observedOnce","size","setSize","height","width","elementRef","onUpdate","entry","current","borderBoxSize","blockSize","inlineSize"],"mappings":"AAAA;AAEA,SAA2BA,WAAW,EAAEC,MAAM,EAAEC,QAAQ,QAAQ,QAAQ;AAGxE,SAEEC,iBAAiB,QACZ,yBAAyB;AA6ChC;;;;;;;;;;;;;;;;;;;;;CAqBC,GACD,OAAO,SAASC,eACdC,UAAiC,CAAC,CAAC;IAEnC,MAAM,EAAEC,YAAY,EAAE,GAAGD;IAEzB,MAAME,eAAeN,OAAO;IAC5B,MAAM,CAACO,MAAMC,QAAQ,GAAGP,SAAsB;QAC5C,IAAI,OAAOI,iBAAiB,YAAY;YACtC,OAAOA;QACT;QAEA,OACEA,gBAAgB;YACdI,QAAQ;YACRC,OAAO;QACT;IAEJ;IAEA,MAAMC,aAAaT,kBAAkB;QACnC,GAAGE,OAAO;QACVQ,UAAUb,YAAY,CAACc;YACrBP,aAAaQ,OAAO,GAAG;YACvB,MAAMP,OAAOM,MAAME,aAAa,CAAC,EAAE;YAEnCP,QAAQ;gBACNC,QAAQF,KAAKS,SAAS;gBACtBN,OAAOH,KAAKU,UAAU;YACxB;QACF,GAAG,EAAE;IACP;IAEA,OAAO;QACL,GAAGV,IAAI;QACPI;QACAL,cAAcA,aAAaQ,OAAO;IACpC;AACF"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useIntersectionObserver.ts"],"sourcesContent":["\"use client\";\n\nimport { type Ref, type RefCallback, type RefObject } from \"react\";\nimport { useEffect } from \"react\";\n\nimport { useEnsuredRef } from \"./useEnsuredRef.js\";\n\n/** @since 6.0.0 */\nexport type IntersectionObserverRoot = IntersectionObserverInit[\"root\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverThreshold =\n IntersectionObserverInit[\"threshold\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverRootMargin =\n IntersectionObserverInit[\"rootMargin\"];\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface BaseIntersectionObserverHookOptions {\n /**\n * This is the same as the normal `root` for an IntersectionObserverInit, but\n * also supports refs.\n */\n root?: RefObject<IntersectionObserverRoot> | IntersectionObserverRoot;\n\n /**\n * Set this to `true` if the intersection observer behavior should be\n * disabled.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n\n /**\n * **When using a list of thresholds, they must either be defined outside of\n * the component or wrapped in a `useMemo` to prevent the IntersectionObserver\n * from being re-created each render.**\n *\n * @example Moving Out of Render\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example() {\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * })\n * }\n * ```\n *\n * @example Wrapping in useMemo\n * ```tsx\n * interface ExampleProps {\n * min: number;\n * max: number;\n * }\n *\n * function Example({ min, max }: ExampleProps): ReactElement {\n * const targetRef = useIntersectionObserver({\n * threshold: useMemo(() => [min, max], [min, max]),\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * });\n * }\n * ```\n *\n * @see {@link getThreshold}\n */\n threshold?: IntersectionObserverThreshold;\n\n /** @see {@link getRootMargin} */\n rootMargin?: IntersectionObserverRootMargin;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link threshold} which is\n * generally useful if you need access to the DOM or do some expensive\n * computation.\n *\n * @example Simple Example\n * ```tsx\n * const targetRef = useIntersectionObserver({\n * getThreshold: useCallback(() => {\n * // pretend some expensive computation\n * return [0, 0.25, 0.5, 0.75, 1];\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * If this option is provided, {@link threshold}'s value will be ignored.\n */\n getThreshold?: () => IntersectionObserverThreshold;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link rootMargin} which is\n * generally useful if you need access to the DOM.\n *\n * @example Simple Example\n * ```tsx\n * const nodeRef = useRef<HTMLElement>();\n * const targetRef = useIntersectionObserver({\n * getRootMargin: useCallback(() => {\n * return `-${nodeRef.current.offsetHeight - 1}px 0px 0px`;\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * Note: If this option is provided, {@link rootMargin} will be ignored.\n */\n getRootMargin?: () => IntersectionObserverRootMargin;\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface IntersectionObserverHookOptions<E extends HTMLElement>\n extends BaseIntersectionObserverHookOptions {\n /**\n * An optional ref to merge with the ref returned by this hook.\n */\n ref?: Ref<E>;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * @example Simple Example\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example(): ReactElement {\n * const [intersecting, setIntersecting] = useState(false);\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) {\n * setIntersecting(entry.isIntersecting);\n * }, []),\n * });\n *\n * // implementation\n * }\n * ```\n */\n onUpdate: (entries: readonly IntersectionObserverEntry[]) => void;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * If this is defined, the {@link ref} will be ignored along with the returned\n * ref.\n *\n * @example Watching Queried Elements\n * ```tsx\n * function Example(): ReactElement {\n * useIntersectionObserver({\n * onUpdate: useCallback((entries) => {\n * entries.forEach((entry) => {\n * // do stuff\n * });\n *\n * setIntersectingIds(intersecting);\n * }, []),\n * getTargets: useCallback(() => {\n * return document.querySelectorAll('h1, h2, h3, h4, h5, h6');\n * }, []),\n * }),\n *\n * return <div {...props} />;\n * }\n * ```\n */\n getTargets?: () => readonly Element[];\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#a_simple_example\n *\n * import { useIntersectionObserver } from \"@react-md/core/useIntersectionObserver\";\n * import { type ReactElement } from \"react\";\n * import { useState } from \"react\";\n *\n * import styles from \"./Example.module.scss\";\n *\n * const numSteps = 20;\n * const thresholds = Array.from({ length: numSteps }, (_, i) => i / numSteps);\n * thresholds.push(0);\n *\n * const INCREASING = \"rgba(40, 40, 190, ratio)\";\n * const DECREASING = \"rgba(190, 40, 40, ratio)\";\n *\n * export default function Example(): ReactElement {\n * const [{ ratio, increasing }, setState] = useState({\n * ratio: 0.0,\n * increasing: true,\n * });\n *\n * const targetRef = useIntersectionObserver({\n * threshold: thresholds,\n * rootMargin: \"0px\",\n * onUpdate: useCallback(([entry]) => {\n * const { intersectionRatio } = entry;\n * setState((prevState) => {\n * return {\n * ratio: intersectionRatio,\n * increasing: intersectionRatio > prevState.ratio,\n * };\n * });\n * }, []),\n * });\n *\n * return (\n * <div\n * ref={targetRef}\n * className={styles.box}\n * style={{\n * backgroundColor: (increasing ? INCREASING : DECREASING).replace(\n * \"ratio\",\n * `${ratio}`\n * ),\n * }}\n * >\n * <div className={styles.vertical}>\n * Welcome to <strong>The Box!</strong>\n * </div>\n * </div>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API\n */\nexport function useIntersectionObserver<E extends HTMLElement>(\n options: IntersectionObserverHookOptions<E>\n): RefCallback<E> {\n const {\n ref,\n root,\n disabled = false,\n onUpdate,\n threshold,\n rootMargin,\n getTargets,\n getThreshold,\n getRootMargin,\n } = options;\n\n const [targetNodeRef, targetRef] = useEnsuredRef(ref);\n\n useEffect(() => {\n const element = targetNodeRef.current;\n let targets: readonly Element[] = [];\n if (getTargets) {\n targets = getTargets();\n } else if (element) {\n targets = [element];\n }\n\n if (disabled || !targets.length) {\n return;\n }\n\n let resolvedRoot: IntersectionObserverRoot;\n if (root && \"current\" in root) {\n resolvedRoot = root.current;\n } else {\n resolvedRoot = root;\n }\n\n const options: IntersectionObserverInit = {\n root: resolvedRoot,\n threshold: (getThreshold || (() => threshold))(),\n rootMargin: (getRootMargin || (() => rootMargin))(),\n };\n\n // Just like the ResizeObserver, you can see performance improvements by\n // sharing a single intersection observer but I don't think it's worth the\n // effort to implement here since I'd need to:\n // - check if there is an observer with the same options\n // - if there is, add the callback to that existing observer\n // - if there isn't, create a new observer\n // - when cleaning up, check if there are any other existing callbacks\n // - disconnect and remove the observer if there are none left\n const observer = new IntersectionObserver(onUpdate, options);\n targets.forEach((target) => {\n observer.observe(target);\n });\n\n return () => {\n observer.disconnect();\n };\n }, [\n disabled,\n getRootMargin,\n getTargets,\n getThreshold,\n onUpdate,\n root,\n rootMargin,\n targetNodeRef,\n threshold,\n ]);\n\n return targetRef;\n}\n"],"names":["useEffect","useEnsuredRef","useIntersectionObserver","options","ref","root","disabled","onUpdate","threshold","rootMargin","getTargets","getThreshold","getRootMargin","targetNodeRef","targetRef","element","current","targets","length","resolvedRoot","observer","IntersectionObserver","forEach","target","observe","disconnect"],"mappings":"AAAA;AAGA,SAASA,SAAS,QAAQ,QAAQ;AAElC,SAASC,a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client\";\n\nimport { type Ref, type RefCallback, type RefObject } from \"react\";\nimport { useEffect } from \"react\";\n\nimport { useEnsuredRef } from \"./useEnsuredRef.js\";\n\n/** @since 6.0.0 */\nexport type IntersectionObserverRoot = IntersectionObserverInit[\"root\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverThreshold =\n IntersectionObserverInit[\"threshold\"];\n/** @since 6.0.0 */\nexport type IntersectionObserverRootMargin =\n IntersectionObserverInit[\"rootMargin\"];\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface BaseIntersectionObserverHookOptions {\n /**\n * This is the same as the normal `root` for an IntersectionObserverInit, but\n * also supports refs.\n */\n root?: RefObject<IntersectionObserverRoot> | IntersectionObserverRoot;\n\n /**\n * Set this to `true` if the intersection observer behavior should be\n * disabled.\n *\n * @defaultValue `false`\n */\n disabled?: boolean;\n\n /**\n * **When using a list of thresholds, they must either be defined outside of\n * the component or wrapped in a `useMemo` to prevent the IntersectionObserver\n * from being re-created each render.**\n *\n * @example Moving Out of Render\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example() {\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * })\n * }\n * ```\n *\n * @example Wrapping in useMemo\n * ```tsx\n * interface ExampleProps {\n * min: number;\n * max: number;\n * }\n *\n * function Example({ min, max }: ExampleProps): ReactElement {\n * const targetRef = useIntersectionObserver({\n * threshold: useMemo(() => [min, max], [min, max]),\n * onUpdate: useCallback(([entry]) => {\n * // do something\n * }, []),\n * });\n * }\n * ```\n *\n * @see {@link getThreshold}\n */\n threshold?: IntersectionObserverThreshold;\n\n /** @see {@link getRootMargin} */\n rootMargin?: IntersectionObserverRootMargin;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link threshold} which is\n * generally useful if you need access to the DOM or do some expensive\n * computation.\n *\n * @example Simple Example\n * ```tsx\n * const targetRef = useIntersectionObserver({\n * getThreshold: useCallback(() => {\n * // pretend some expensive computation\n * return [0, 0.25, 0.5, 0.75, 1];\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * If this option is provided, {@link threshold}'s value will be ignored.\n */\n getThreshold?: () => IntersectionObserverThreshold;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * This can be used to dynamically generate the {@link rootMargin} which is\n * generally useful if you need access to the DOM.\n *\n * @example Simple Example\n * ```tsx\n * const nodeRef = useRef<HTMLElement>();\n * const targetRef = useIntersectionObserver({\n * getRootMargin: useCallback(() => {\n * return `-${nodeRef.current.offsetHeight - 1}px 0px 0px`;\n * }, []),\n * onUpdate: useCallback(() => {\n * // do something\n * }, []),\n * });\n * ```\n *\n * Note: If this option is provided, {@link rootMargin} will be ignored.\n */\n getRootMargin?: () => IntersectionObserverRootMargin;\n}\n\n/**\n * @see {@link https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#intersection_observer_options}\n * @since 6.0.0\n */\nexport interface IntersectionObserverHookOptions<\n E extends HTMLElement,\n> extends BaseIntersectionObserverHookOptions {\n /**\n * An optional ref to merge with the ref returned by this hook.\n */\n ref?: Ref<E>;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * @example Simple Example\n * ```tsx\n * const threshold = [0, 0.25, 0.5, 0.75, 1];\n *\n * function Example(): ReactElement {\n * const [intersecting, setIntersecting] = useState(false);\n * const targetRef = useIntersectionObserver({\n * threshold,\n * onUpdate: useCallback(([entry]) {\n * setIntersecting(entry.isIntersecting);\n * }, []),\n * });\n *\n * // implementation\n * }\n * ```\n */\n onUpdate: (entries: readonly IntersectionObserverEntry[]) => void;\n\n /**\n * **Must be wrapped in `useCallback` to prevent re-creating the\n * IntersectionObserver each render.**\n *\n * If this is defined, the {@link ref} will be ignored along with the returned\n * ref.\n *\n * @example Watching Queried Elements\n * ```tsx\n * function Example(): ReactElement {\n * useIntersectionObserver({\n * onUpdate: useCallback((entries) => {\n * entries.forEach((entry) => {\n * // do stuff\n * });\n *\n * setIntersectingIds(intersecting);\n * }, []),\n * getTargets: useCallback(() => {\n * return document.querySelectorAll('h1, h2, h3, h4, h5, h6');\n * }, []),\n * }),\n *\n * return <div {...props} />;\n * }\n * ```\n */\n getTargets?: () => readonly Element[];\n}\n\n/**\n * @example Simple Example\n * ```tsx\n * // https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API#a_simple_example\n *\n * import { useIntersectionObserver } from \"@react-md/core/useIntersectionObserver\";\n * import { type ReactElement } from \"react\";\n * import { useState } from \"react\";\n *\n * import styles from \"./Example.module.scss\";\n *\n * const numSteps = 20;\n * const thresholds = Array.from({ length: numSteps }, (_, i) => i / numSteps);\n * thresholds.push(0);\n *\n * const INCREASING = \"rgba(40, 40, 190, ratio)\";\n * const DECREASING = \"rgba(190, 40, 40, ratio)\";\n *\n * export default function Example(): ReactElement {\n * const [{ ratio, increasing }, setState] = useState({\n * ratio: 0.0,\n * increasing: true,\n * });\n *\n * const targetRef = useIntersectionObserver({\n * threshold: thresholds,\n * rootMargin: \"0px\",\n * onUpdate: useCallback(([entry]) => {\n * const { intersectionRatio } = entry;\n * setState((prevState) => {\n * return {\n * ratio: intersectionRatio,\n * increasing: intersectionRatio > prevState.ratio,\n * };\n * });\n * }, []),\n * });\n *\n * return (\n * <div\n * ref={targetRef}\n * className={styles.box}\n * style={{\n * backgroundColor: (increasing ? INCREASING : DECREASING).replace(\n * \"ratio\",\n * `${ratio}`\n * ),\n * }}\n * >\n * <div className={styles.vertical}>\n * Welcome to <strong>The Box!</strong>\n * </div>\n * </div>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n * @see https://developer.mozilla.org/en-US/docs/Web/API/Intersection_Observer_API\n */\nexport function useIntersectionObserver<E extends HTMLElement>(\n options: IntersectionObserverHookOptions<E>\n): RefCallback<E> {\n const {\n ref,\n root,\n disabled = false,\n onUpdate,\n threshold,\n rootMargin,\n getTargets,\n getThreshold,\n getRootMargin,\n } = options;\n\n const [targetNodeRef, targetRef] = useEnsuredRef(ref);\n\n useEffect(() => {\n const element = targetNodeRef.current;\n let targets: readonly Element[] = [];\n if (getTargets) {\n targets = getTargets();\n } else if (element) {\n targets = [element];\n }\n\n if (disabled || !targets.length) {\n return;\n }\n\n let resolvedRoot: IntersectionObserverRoot;\n if (root && \"current\" in root) {\n resolvedRoot = root.current;\n } else {\n resolvedRoot = root;\n }\n\n const options: IntersectionObserverInit = {\n root: resolvedRoot,\n threshold: (getThreshold || (() => threshold))(),\n rootMargin: (getRootMargin || (() => rootMargin))(),\n };\n\n // Just like the ResizeObserver, you can see performance improvements by\n // sharing a single intersection observer but I don't think it's worth the\n // effort to implement here since I'd need to:\n // - check if there is an observer with the same options\n // - if there is, add the callback to that existing observer\n // - if there isn't, create a new observer\n // - when cleaning up, check if there are any other existing callbacks\n // - disconnect and remove the observer if there are none left\n const observer = new IntersectionObserver(onUpdate, options);\n targets.forEach((target) => {\n observer.observe(target);\n });\n\n return () => {\n observer.disconnect();\n };\n }, [\n disabled,\n getRootMargin,\n getTargets,\n getThreshold,\n onUpdate,\n root,\n rootMargin,\n targetNodeRef,\n threshold,\n ]);\n\n return targetRef;\n}\n"],"names":["useEffect","useEnsuredRef","useIntersectionObserver","options","ref","root","disabled","onUpdate","threshold","rootMargin","getTargets","getThreshold","getRootMargin","targetNodeRef","targetRef","element","current","targets","length","resolvedRoot","observer","IntersectionObserver","forEach","target","observe","disconnect"],"mappings":"AAAA;AAGA,SAASA,SAAS,QAAQ,QAAQ;AAElC,SAASC,aAAa,QAAQ,qBAAqB;AA4LnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA2DC,GACD,OAAO,SAASC,wBACdC,OAA2C;IAE3C,MAAM,EACJC,GAAG,EACHC,IAAI,EACJC,WAAW,KAAK,EAChBC,QAAQ,EACRC,SAAS,EACTC,UAAU,EACVC,UAAU,EACVC,YAAY,EACZC,aAAa,EACd,GAAGT;IAEJ,MAAM,CAACU,eAAeC,UAAU,GAAGb,cAAcG;IAEjDJ,UAAU;QACR,MAAMe,UAAUF,cAAcG,OAAO;QACrC,IAAIC,UAA8B,EAAE;QACpC,IAAIP,YAAY;YACdO,UAAUP;QACZ,OAAO,IAAIK,SAAS;YAClBE,UAAU;gBAACF;aAAQ;QACrB;QAEA,IAAIT,YAAY,CAACW,QAAQC,MAAM,EAAE;YAC/B;QACF;QAEA,IAAIC;QACJ,IAAId,QAAQ,aAAaA,MAAM;YAC7Bc,eAAed,KAAKW,OAAO;QAC7B,OAAO;YACLG,eAAed;QACjB;QAEA,MAAMF,UAAoC;YACxCE,MAAMc;YACNX,WAAW,AAACG,CAAAA,gBAAiB,CAAA,IAAMH,SAAQ,CAAC;YAC5CC,YAAY,AAACG,CAAAA,iBAAkB,CAAA,IAAMH,UAAS,CAAC;QACjD;QAEA,wEAAwE;QACxE,0EAA0E;QAC1E,8CAA8C;QAC9C,wDAAwD;QACxD,8DAA8D;QAC9D,4CAA4C;QAC5C,sEAAsE;QACtE,gEAAgE;QAChE,MAAMW,WAAW,IAAIC,qBAAqBd,UAAUJ;QACpDc,QAAQK,OAAO,CAAC,CAACC;YACfH,SAASI,OAAO,CAACD;QACnB;QAEA,OAAO;YACLH,SAASK,UAAU;QACrB;IACF,GAAG;QACDnB;QACAM;QACAF;QACAC;QACAJ;QACAF;QACAI;QACAI;QACAL;KACD;IAED,OAAOM;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useMutationObserver.ts"],"sourcesContent":["import { type Ref, type RefCallback, useEffect } from \"react\";\n\nimport { useEnsuredRef } from \"./useEnsuredRef.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface MutationObserverHookOptions
|
|
1
|
+
{"version":3,"sources":["../src/useMutationObserver.ts"],"sourcesContent":["import { type Ref, type RefCallback, useEffect } from \"react\";\n\nimport { useEnsuredRef } from \"./useEnsuredRef.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface MutationObserverHookOptions<\n E extends HTMLElement,\n> extends MutationObserverInit {\n ref?: Ref<E>;\n\n /**\n * @see https://developer.mozilla.org/en-US/docs/Web/API/MutationObserver/observe#options\n * @defaultValue `!childList && !attributes && !characterData`\n */\n disabled?: boolean;\n\n onUpdate: (mutation: MutationRecord) => void;\n}\n\n/**\n * The mutation observer is used to track the changes made to the DOM tree.\n *\n * @example Simple Example\n * ```tsx\n * import { useMutationObserver } from \"@react-md/core/useMutationObserver\";\n * import { useCallback, type HTMLAttributes, type ReactElement } from \"react\";\n *\n * function Example(props: HTMLAttributes<HTMLDivElement>): ReactElement {\n * const { children, ...remaining } = props;\n *\n * const targetRef = useMutationObserver({\n * subtree: true,\n * attributes: true,\n * childList: true,\n * onUpdate: useCallback((mutation) => {\n * switch (mutation.type) {\n * case \"childList\":\n * console.log(\"A child node has been added or removed\");\n * break;\n * case \"attributes\":\n * console.log(`The ${mutation.attributeName} attribute was modified`);\n * break\n * }\n *\n * }, []),\n * });\n *\n * return (\n * <div {...remaining} ref={targetRef}>\n * {children}\n * </div>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useMutationObserver<E extends HTMLElement>(\n options: MutationObserverHookOptions<E>\n): RefCallback<E> {\n const {\n ref,\n onUpdate,\n attributes,\n attributeFilter,\n attributeOldValue,\n subtree,\n childList,\n characterData,\n characterDataOldValue,\n disabled = !childList && !attributes && !characterData,\n } = options;\n\n const [targetNodeRef, refCallback] = useEnsuredRef(ref);\n useEffect(() => {\n if (disabled) {\n return;\n }\n\n const observerTarget = targetNodeRef.current;\n if (!observerTarget) {\n return;\n }\n\n const observer = new MutationObserver((records) => {\n const [entry] = records;\n if (entry) {\n onUpdate(entry);\n }\n });\n\n observer.observe(observerTarget, {\n attributes,\n attributeFilter,\n attributeOldValue,\n subtree,\n childList,\n characterData,\n characterDataOldValue,\n });\n return () => {\n observer.disconnect();\n };\n }, [\n attributeFilter,\n attributeOldValue,\n attributes,\n characterData,\n characterDataOldValue,\n childList,\n disabled,\n onUpdate,\n subtree,\n targetNodeRef,\n ]);\n\n return refCallback;\n}\n"],"names":["useEffect","useEnsuredRef","useMutationObserver","options","ref","onUpdate","attributes","attributeFilter","attributeOldValue","subtree","childList","characterData","characterDataOldValue","disabled","targetNodeRef","refCallback","observerTarget","current","observer","MutationObserver","records","entry","observe","disconnect"],"mappings":"AAAA,SAAqCA,SAAS,QAAQ,QAAQ;AAE9D,SAASC,aAAa,QAAQ,qBAAqB;AAmBnD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAqCC,GACD,OAAO,SAASC,oBACdC,OAAuC;IAEvC,MAAM,EACJC,GAAG,EACHC,QAAQ,EACRC,UAAU,EACVC,eAAe,EACfC,iBAAiB,EACjBC,OAAO,EACPC,SAAS,EACTC,aAAa,EACbC,qBAAqB,EACrBC,WAAW,CAACH,aAAa,CAACJ,cAAc,CAACK,aAAa,EACvD,GAAGR;IAEJ,MAAM,CAACW,eAAeC,YAAY,GAAGd,cAAcG;IACnDJ,UAAU;QACR,IAAIa,UAAU;YACZ;QACF;QAEA,MAAMG,iBAAiBF,cAAcG,OAAO;QAC5C,IAAI,CAACD,gBAAgB;YACnB;QACF;QAEA,MAAME,WAAW,IAAIC,iBAAiB,CAACC;YACrC,MAAM,CAACC,MAAM,GAAGD;YAChB,IAAIC,OAAO;gBACThB,SAASgB;YACX;QACF;QAEAH,SAASI,OAAO,CAACN,gBAAgB;YAC/BV;YACAC;YACAC;YACAC;YACAC;YACAC;YACAC;QACF;QACA,OAAO;YACLM,SAASK,UAAU;QACrB;IACF,GAAG;QACDhB;QACAC;QACAF;QACAK;QACAC;QACAF;QACAG;QACAR;QACAI;QACAK;KACD;IAED,OAAOC;AACT"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/useWindowSize.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\n\nimport { useSsr } from \"./SsrProvider.js\";\nimport { type ElementSize } from \"./types.js\";\nimport {\n type ResizeListenerOptions,\n useResizeListener,\n} from \"./useResizeListener.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface WindowSizeOptions
|
|
1
|
+
{"version":3,"sources":["../src/useWindowSize.ts"],"sourcesContent":["\"use client\";\n\nimport { useCallback, useState } from \"react\";\n\nimport { useSsr } from \"./SsrProvider.js\";\nimport { type ElementSize } from \"./types.js\";\nimport {\n type ResizeListenerOptions,\n useResizeListener,\n} from \"./useResizeListener.js\";\n\n/**\n * @since 6.0.0\n */\nexport interface WindowSizeOptions extends Omit<\n ResizeListenerOptions,\n \"disabled\" | \"onUpdate\"\n> {\n /**\n * The default value to use in SSR environments for the window's height.\n *\n * @defaultValue `0`\n */\n ssrHeight?: number;\n\n /**\n * The default value to use in SSR environments for the window's width.\n *\n * @defaultValue `0`\n */\n ssrWidth?: number;\n\n /**\n * Set this to `true` to ignore resize events that only updated the height.\n * The hook can be disabled by setting this and {@link disableWidth} to\n * `true`.\n *\n * @defaultValue `false`\n */\n disableHeight?: boolean;\n\n /**\n * Set this to `true` to ignore resize events that only updated the width.\n * The hook can be disabled by setting this and {@link disableHeight} to\n * `true`.\n *\n * @defaultValue `false`\n */\n disableWidth?: boolean;\n}\n\n/**\n * This is just a convenience wrapper around the {@link useResizeListener}.\n *\n * @example Simple Example\n * ```tsx\n * import { useWindowSize } from \"@react-md/core/useWindowSize\";\n * import type { ReactElement } from \"react\";\n * import { useState } from \"react\";\n *\n * function Example(): ReactElement {\n * const { height, width } = useWindowSize();\n *\n * return (\n * <>\n * The current window size:\n * <pre><code>{JSON.stringify(size, null, 2)}</code></pre>\n * </>\n * );\n * }\n * ```\n *\n * @since 6.0.0\n */\nexport function useWindowSize(options: WindowSizeOptions = {}): ElementSize {\n const {\n once,\n signal,\n capture,\n passive,\n throttle,\n ssrHeight = 0,\n ssrWidth = 0,\n disableWidth,\n disableHeight,\n } = options;\n\n const ssr = useSsr();\n const [size, setSize] = useState(() => {\n if (typeof window === \"undefined\" || ssr) {\n return {\n height: ssrHeight,\n width: ssrWidth,\n };\n }\n\n return {\n height: window.innerHeight,\n width: window.innerWidth,\n };\n });\n\n useResizeListener({\n once,\n signal,\n capture,\n passive,\n throttle,\n disabled: disableHeight && disableWidth,\n onUpdate: useCallback(() => {\n setSize((prevSize) => {\n const nextSize: ElementSize = {\n height: window.innerHeight,\n width: window.innerWidth,\n };\n\n const isHeightChange =\n !disableHeight && prevSize.height !== nextSize.height;\n const isWidthChange =\n !disableWidth && prevSize.width !== nextSize.width;\n\n return isHeightChange || isWidthChange ? nextSize : prevSize;\n });\n }, [disableHeight, disableWidth]),\n });\n\n return size;\n}\n"],"names":["useCallback","useState","useSsr","useResizeListener","useWindowSize","options","once","signal","capture","passive","throttle","ssrHeight","ssrWidth","disableWidth","disableHeight","ssr","size","setSize","window","height","width","innerHeight","innerWidth","disabled","onUpdate","prevSize","nextSize","isHeightChange","isWidthChange"],"mappings":"AAAA;AAEA,SAASA,WAAW,EAAEC,QAAQ,QAAQ,QAAQ;AAE9C,SAASC,MAAM,QAAQ,mBAAmB;AAE1C,SAEEC,iBAAiB,QACZ,yBAAyB;AA0ChC;;;;;;;;;;;;;;;;;;;;;;CAsBC,GACD,OAAO,SAASC,cAAcC,UAA6B,CAAC,CAAC;IAC3D,MAAM,EACJC,IAAI,EACJC,MAAM,EACNC,OAAO,EACPC,OAAO,EACPC,QAAQ,EACRC,YAAY,CAAC,EACbC,WAAW,CAAC,EACZC,YAAY,EACZC,aAAa,EACd,GAAGT;IAEJ,MAAMU,MAAMb;IACZ,MAAM,CAACc,MAAMC,QAAQ,GAAGhB,SAAS;QAC/B,IAAI,OAAOiB,WAAW,eAAeH,KAAK;YACxC,OAAO;gBACLI,QAAQR;gBACRS,OAAOR;YACT;QACF;QAEA,OAAO;YACLO,QAAQD,OAAOG,WAAW;YAC1BD,OAAOF,OAAOI,UAAU;QAC1B;IACF;IAEAnB,kBAAkB;QAChBG;QACAC;QACAC;QACAC;QACAC;QACAa,UAAUT,iBAAiBD;QAC3BW,UAAUxB,YAAY;YACpBiB,QAAQ,CAACQ;gBACP,MAAMC,WAAwB;oBAC5BP,QAAQD,OAAOG,WAAW;oBAC1BD,OAAOF,OAAOI,UAAU;gBAC1B;gBAEA,MAAMK,iBACJ,CAACb,iBAAiBW,SAASN,MAAM,KAAKO,SAASP,MAAM;gBACvD,MAAMS,gBACJ,CAACf,gBAAgBY,SAASL,KAAK,KAAKM,SAASN,KAAK;gBAEpD,OAAOO,kBAAkBC,gBAAgBF,WAAWD;YACtD;QACF,GAAG;YAACX;YAAeD;SAAa;IAClC;IAEA,OAAOG;AACT"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @since 6.4.0
|
|
3
|
+
* @see {@link https://stackoverflow.com/a/28203456}
|
|
4
|
+
*/
|
|
5
|
+
export declare function getNumberOfDigits(value: number): number;
|
|
6
|
+
export declare function getNumberOfDigits(value: undefined): undefined;
|
|
7
|
+
export declare function getNumberOfDigits(value: number | undefined): number | undefined;
|