react-panel-layout 0.5.1 → 0.6.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/{FloatingPanelFrame-D9Cp2al1.cjs → FloatingPanelFrame-CEmXDvUA.cjs} +2 -2
- package/dist/FloatingPanelFrame-CEmXDvUA.cjs.map +1 -0
- package/dist/{FloatingPanelFrame-6W5OexYe.js → FloatingPanelFrame-SgYLc6Ud.js} +12 -15
- package/dist/FloatingPanelFrame-SgYLc6Ud.js.map +1 -0
- package/dist/FloatingWindow-BpdOpg_L.js +400 -0
- package/dist/FloatingWindow-BpdOpg_L.js.map +1 -0
- package/dist/FloatingWindow-TCDNY5gE.cjs +2 -0
- package/dist/FloatingWindow-TCDNY5gE.cjs.map +1 -0
- package/dist/GridLayout-B4VRsC0r.cjs +2 -0
- package/dist/GridLayout-B4VRsC0r.cjs.map +1 -0
- package/dist/GridLayout-BltqeCPK.js +927 -0
- package/dist/GridLayout-BltqeCPK.js.map +1 -0
- package/dist/HorizontalDivider-B5Z-KZLk.cjs +2 -0
- package/dist/HorizontalDivider-B5Z-KZLk.cjs.map +1 -0
- package/dist/HorizontalDivider-WF1k_qND.js +30 -0
- package/dist/HorizontalDivider-WF1k_qND.js.map +1 -0
- package/dist/PanelSystem-Bs8bQwQF.cjs +3 -0
- package/dist/PanelSystem-Bs8bQwQF.cjs.map +1 -0
- package/dist/PanelSystem-Dr1TBhxM.js +1946 -0
- package/dist/PanelSystem-Dr1TBhxM.js.map +1 -0
- package/dist/ResizeHandle-CScipO5l.cjs +2 -0
- package/dist/ResizeHandle-CScipO5l.cjs.map +1 -0
- package/dist/ResizeHandle-CdA_JYfN.js +120 -0
- package/dist/ResizeHandle-CdA_JYfN.js.map +1 -0
- package/dist/SwipePivotTabBar-BGO9X94m.js +407 -0
- package/dist/SwipePivotTabBar-BGO9X94m.js.map +1 -0
- package/dist/SwipePivotTabBar-BrQismcZ.cjs +2 -0
- package/dist/SwipePivotTabBar-BrQismcZ.cjs.map +1 -0
- package/dist/config.cjs +1 -1
- package/dist/config.cjs.map +1 -1
- package/dist/config.js +11 -9
- package/dist/config.js.map +1 -1
- package/dist/constants/styles.d.ts +18 -4
- package/dist/floating.cjs +1 -1
- package/dist/floating.js +1 -1
- package/dist/grid/index.d.ts +58 -0
- package/dist/grid.cjs +2 -0
- package/dist/grid.cjs.map +1 -0
- package/dist/grid.js +13 -0
- package/dist/grid.js.map +1 -0
- package/dist/hooks/gesture/presets.d.ts +33 -0
- package/dist/hooks/gesture/testing/createGestureSimulator.d.ts +110 -0
- package/dist/hooks/gesture/thresholdValue.d.ts +44 -0
- package/dist/hooks/gesture/types.d.ts +254 -0
- package/dist/hooks/gesture/useDirectionalLock.d.ts +20 -0
- package/dist/hooks/gesture/useEdgeSwipeInput.d.ts +23 -0
- package/dist/hooks/gesture/useNativeGestureGuard.d.ts +23 -0
- package/dist/hooks/gesture/usePointerTracking.d.ts +22 -0
- package/dist/hooks/gesture/useScrollBoundary.d.ts +23 -0
- package/dist/hooks/gesture/useSwipeInput.d.ts +5 -0
- package/dist/hooks/gesture/utils.d.ts +40 -0
- package/dist/hooks/useAnimatedVisibility.d.ts +58 -0
- package/dist/hooks/useAnimationFrame.d.ts +84 -0
- package/dist/hooks/useSnapAnimation.d.ts +54 -0
- package/dist/hooks/useSwipeContentTransform.d.ts +79 -0
- package/dist/index.cjs +1 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +0 -1
- package/dist/index.js +25 -2006
- package/dist/index.js.map +1 -1
- package/dist/modules/pivot/PivotContent.d.ts +1 -1
- package/dist/modules/pivot/SwipePivotContent.d.ts +39 -0
- package/dist/modules/pivot/SwipePivotContent.debug.tmp.d.ts +25 -0
- package/dist/modules/pivot/SwipePivotContent.test.d.ts +1 -0
- package/dist/modules/pivot/SwipePivotTabBar.d.ts +89 -0
- package/dist/modules/pivot/index.d.ts +3 -0
- package/dist/modules/pivot/scaleInputState.d.ts +37 -0
- package/dist/modules/pivot/types.d.ts +73 -2
- package/dist/modules/pivot/usePivotSwipeInput.d.ts +68 -0
- package/dist/modules/stack/StackContent.d.ts +15 -0
- package/dist/modules/stack/SwipeStackContent.d.ts +63 -0
- package/dist/modules/stack/SwipeStackOutlet.d.ts +80 -0
- package/dist/modules/stack/computeStackContentState.d.ts +99 -0
- package/dist/modules/stack/computeSwipeStackTransform.d.ts +76 -0
- package/dist/modules/stack/types.d.ts +194 -0
- package/dist/modules/stack/useStackAnimationState.d.ts +32 -0
- package/dist/modules/stack/useStackNavigation.d.ts +23 -0
- package/dist/modules/stack/useStackSwipeInput.d.ts +27 -0
- package/dist/panels/index.d.ts +67 -0
- package/dist/panels.cjs +2 -0
- package/dist/panels.cjs.map +1 -0
- package/dist/panels.js +28 -0
- package/dist/panels.js.map +1 -0
- package/dist/pivot/index.d.ts +3 -0
- package/dist/pivot.cjs +1 -1
- package/dist/pivot.cjs.map +1 -1
- package/dist/pivot.js +20 -2
- package/dist/pivot.js.map +1 -1
- package/dist/resizer/index.d.ts +57 -0
- package/dist/resizer.cjs +2 -0
- package/dist/resizer.cjs.map +1 -0
- package/dist/resizer.js +8 -0
- package/dist/resizer.js.map +1 -0
- package/dist/stack/index.d.ts +72 -0
- package/dist/stack.cjs +2 -0
- package/dist/stack.cjs.map +1 -0
- package/dist/stack.js +980 -0
- package/dist/stack.js.map +1 -0
- package/dist/sticky-header/StickyArea.d.ts +38 -0
- package/dist/sticky-header/index.d.ts +4 -4
- package/dist/sticky-header/types.d.ts +35 -22
- package/dist/sticky-header.cjs +1 -1
- package/dist/sticky-header.cjs.map +1 -1
- package/dist/sticky-header.js +65 -174
- package/dist/sticky-header.js.map +1 -1
- package/dist/styles-DPPuJ0sf.js +57 -0
- package/dist/styles-DPPuJ0sf.js.map +1 -0
- package/dist/styles-qf6ptVLD.cjs +2 -0
- package/dist/styles-qf6ptVLD.cjs.map +1 -0
- package/dist/types.d.ts +12 -0
- package/dist/useContentCache-CO3LYNmz.js +24 -0
- package/dist/useContentCache-CO3LYNmz.js.map +1 -0
- package/dist/useContentCache-DqXtLrLs.cjs +2 -0
- package/dist/useContentCache-DqXtLrLs.cjs.map +1 -0
- package/dist/useDocumentPointerEvents-CKdhGXd0.js +46 -0
- package/dist/useDocumentPointerEvents-CKdhGXd0.js.map +1 -0
- package/dist/useDocumentPointerEvents-ChqrKXDk.cjs +2 -0
- package/dist/useDocumentPointerEvents-ChqrKXDk.cjs.map +1 -0
- package/dist/useEffectEvent-Dp7HLCf0.js +13 -0
- package/dist/useEffectEvent-Dp7HLCf0.js.map +1 -0
- package/dist/useEffectEvent-huSsGUnl.cjs +2 -0
- package/dist/useEffectEvent-huSsGUnl.cjs.map +1 -0
- package/dist/useFloatingState-C4kRaW_R.cjs +2 -0
- package/dist/useFloatingState-C4kRaW_R.cjs.map +1 -0
- package/dist/useFloatingState-tEfA_wbc.js +74 -0
- package/dist/useFloatingState-tEfA_wbc.js.map +1 -0
- package/dist/window/index.d.ts +61 -0
- package/dist/window.cjs +2 -0
- package/dist/window.cjs.map +1 -0
- package/dist/window.js +149 -0
- package/dist/window.js.map +1 -0
- package/docs/design-tokens.md +405 -0
- package/package.json +29 -4
- package/src/PanelSystemContext.tsx +88 -0
- package/src/components/grid/GridLayerList.tsx +172 -0
- package/src/components/grid/GridLayerResizeHandles.tsx +145 -0
- package/src/components/grid/GridLayout.spec.tsx +743 -0
- package/src/components/grid/GridLayout.tsx +130 -0
- package/src/components/grid/GridTrackResizeHandle.tsx +87 -0
- package/src/components/paneling/FloatingPanelFrame.tsx +203 -0
- package/src/components/panels/DropSuggestOverlay.tsx +131 -0
- package/src/components/panels/PanelGroupView.tsx +112 -0
- package/src/components/pivot/PivotLayer.tsx +27 -0
- package/src/components/resizer/HorizontalDivider.tsx +52 -0
- package/src/components/resizer/ResizeHandle.tsx +118 -0
- package/src/components/tabs/TabBar.tsx +223 -0
- package/src/components/tabs/TabBarTab.tsx +133 -0
- package/src/components/tabs/TabDragOverlay.tsx +92 -0
- package/src/components/window/DialogOverlay.tsx +180 -0
- package/src/components/window/Drawer.tsx +282 -0
- package/src/components/window/DrawerLayers.tsx +58 -0
- package/src/components/window/FloatingWindow.tsx +95 -0
- package/src/components/window/PopupLayerPortal.tsx +218 -0
- package/src/config/PanelContentDeclaration.tsx +427 -0
- package/src/config/index.tsx +52 -0
- package/src/config/panelJsx.spec.tsx +54 -0
- package/src/config/panelJsxConfig.spec.tsx +54 -0
- package/src/config/panelJsxDrawer.spec.tsx +33 -0
- package/src/config/panelRouter.spec.ts +68 -0
- package/src/config/panelRouter.tsx +155 -0
- package/src/constants/styles.ts +261 -0
- package/src/demo/Layout.module.css +258 -0
- package/src/demo/Layout.tsx +176 -0
- package/src/demo/components/CodeBlock.module.css +54 -0
- package/src/demo/components/CodeBlock.tsx +34 -0
- package/src/demo/components/CodePreview.module.css +37 -0
- package/src/demo/components/CodePreview.tsx +31 -0
- package/src/demo/components/DataPreview.module.css +177 -0
- package/src/demo/components/DataPreview.tsx +115 -0
- package/src/demo/components/Story.module.css +68 -0
- package/src/demo/components/Story.tsx +54 -0
- package/src/demo/components/layout/CodePanel.module.css +183 -0
- package/src/demo/components/layout/CodePanel.tsx +149 -0
- package/src/demo/components/layout/DemoPage.module.css +60 -0
- package/src/demo/components/layout/DemoPage.tsx +56 -0
- package/src/demo/components/layout/SingleSamplePage.module.css +11 -0
- package/src/demo/components/layout/SingleSamplePage.tsx +35 -0
- package/src/demo/components/layout/SplitDemoLayout.module.css +107 -0
- package/src/demo/components/layout/SplitDemoLayout.tsx +218 -0
- package/src/demo/components/layout/index.ts +11 -0
- package/src/demo/components/tab-styles/ChromeTabBar.module.css +75 -0
- package/src/demo/components/tab-styles/ChromeTabBar.tsx +111 -0
- package/src/demo/components/tab-styles/GitHubTabBar.module.css +81 -0
- package/src/demo/components/tab-styles/GitHubTabBar.tsx +109 -0
- package/src/demo/components/tab-styles/VSCodeTabBar.module.css +78 -0
- package/src/demo/components/tab-styles/VSCodeTabBar.tsx +109 -0
- package/src/demo/components/tab-styles/index.ts +6 -0
- package/src/demo/components/ui/DemoButton.module.css +63 -0
- package/src/demo/components/ui/DemoButton.tsx +32 -0
- package/src/demo/components/ui/DemoCard.module.css +15 -0
- package/src/demo/components/ui/DemoCard.tsx +30 -0
- package/src/demo/components/ui/DemoContainer.module.css +17 -0
- package/src/demo/components/ui/DemoContainer.tsx +30 -0
- package/src/demo/components/ui/DemoPanel.module.css +23 -0
- package/src/demo/components/ui/DemoPanel.tsx +33 -0
- package/src/demo/components/ui/PanelText.module.css +18 -0
- package/src/demo/components/ui/PanelText.tsx +29 -0
- package/src/demo/components/ui/PanelTitle.module.css +18 -0
- package/src/demo/components/ui/PanelTitle.tsx +31 -0
- package/src/demo/contexts/TabbarDemoConfig.tsx +218 -0
- package/src/demo/demo.css +172 -0
- package/src/demo/hooks/useMedia.ts +41 -0
- package/src/demo/hooks/useShikiHighlight.ts +55 -0
- package/src/demo/index.tsx +293 -0
- package/src/demo/pages/Drawer/animations/index.tsx +22 -0
- package/src/demo/pages/Drawer/basics/index.tsx +17 -0
- package/src/demo/pages/Drawer/components/DrawerAnimations.module.css +125 -0
- package/src/demo/pages/Drawer/components/DrawerAnimations.tsx +118 -0
- package/src/demo/pages/Drawer/components/DrawerBasics.module.css +55 -0
- package/src/demo/pages/Drawer/components/DrawerBasics.tsx +76 -0
- package/src/demo/pages/Drawer/components/DrawerMenuLayout.module.css +332 -0
- package/src/demo/pages/Drawer/components/DrawerMenuLayout.tsx +199 -0
- package/src/demo/pages/Drawer/menu/index.tsx +17 -0
- package/src/demo/pages/FloatingPanelFrame/ResizableFloatingPanelsPreview.module.css +163 -0
- package/src/demo/pages/FloatingPanelFrame/ResizableFloatingPanelsPreview.tsx +234 -0
- package/src/demo/pages/FloatingPanelFrame/basic/index.tsx +17 -0
- package/src/demo/pages/FloatingPanelFrame/complex/index.tsx +26 -0
- package/src/demo/pages/FloatingPanelFrame/components/BasicPanel.module.css +16 -0
- package/src/demo/pages/FloatingPanelFrame/components/BasicPanel.tsx +24 -0
- package/src/demo/pages/FloatingPanelFrame/components/ComplexPanel.module.css +54 -0
- package/src/demo/pages/FloatingPanelFrame/components/ComplexPanel.tsx +67 -0
- package/src/demo/pages/FloatingPanelFrame/components/PanelWithControls.module.css +21 -0
- package/src/demo/pages/FloatingPanelFrame/components/PanelWithControls.tsx +41 -0
- package/src/demo/pages/FloatingPanelFrame/components/PanelWithMeta.module.css +5 -0
- package/src/demo/pages/FloatingPanelFrame/components/PanelWithMeta.tsx +43 -0
- package/src/demo/pages/FloatingPanelFrame/components/ScrollablePanel.module.css +11 -0
- package/src/demo/pages/FloatingPanelFrame/components/ScrollablePanel.tsx +42 -0
- package/src/demo/pages/FloatingPanelFrame/index.tsx +80 -0
- package/src/demo/pages/FloatingPanelFrame/scrollable/index.tsx +30 -0
- package/src/demo/pages/FloatingPanelFrame/with-controls/index.tsx +30 -0
- package/src/demo/pages/FloatingPanelFrame/with-meta/index.tsx +17 -0
- package/src/demo/pages/HorizontalDivider/components/PanelsWithRichContent.module.css +112 -0
- package/src/demo/pages/HorizontalDivider/components/PanelsWithRichContent.tsx +56 -0
- package/src/demo/pages/HorizontalDivider/components/SimpleResizablePanels.module.css +46 -0
- package/src/demo/pages/HorizontalDivider/components/SimpleResizablePanels.tsx +29 -0
- package/src/demo/pages/HorizontalDivider/components/ThreePanelLayout.module.css +54 -0
- package/src/demo/pages/HorizontalDivider/components/ThreePanelLayout.tsx +30 -0
- package/src/demo/pages/HorizontalDivider/index.module.css +14 -0
- package/src/demo/pages/HorizontalDivider/index.tsx +64 -0
- package/src/demo/pages/HorizontalDivider/panels-with-rich-content/index.tsx +21 -0
- package/src/demo/pages/HorizontalDivider/simple-resizable-panels/index.tsx +21 -0
- package/src/demo/pages/HorizontalDivider/three-panel-layout/index.tsx +21 -0
- package/src/demo/pages/PanelLayout/PanelLayoutDemo.module.css +174 -0
- package/src/demo/pages/PanelLayout/PanelLayoutDemo.tsx +248 -0
- package/src/demo/pages/PanelLayout/components/DashboardLayout.module.css +115 -0
- package/src/demo/pages/PanelLayout/components/DashboardLayout.tsx +124 -0
- package/src/demo/pages/PanelLayout/components/DraggableOverlays.module.css +101 -0
- package/src/demo/pages/PanelLayout/components/DraggableOverlays.tsx +122 -0
- package/src/demo/pages/PanelLayout/components/IDELayout.module.css +104 -0
- package/src/demo/pages/PanelLayout/components/IDELayout.tsx +143 -0
- package/src/demo/pages/PanelLayout/components/SimpleGrid.module.css +19 -0
- package/src/demo/pages/PanelLayout/components/SimpleGrid.tsx +62 -0
- package/src/demo/pages/PanelLayout/dashboard/index.tsx +22 -0
- package/src/demo/pages/PanelLayout/draggable-overlays/index.tsx +22 -0
- package/src/demo/pages/PanelLayout/ide-layout/index.tsx +22 -0
- package/src/demo/pages/PanelLayout/index.tsx +94 -0
- package/src/demo/pages/PanelLayout/simple-grid/index.tsx +22 -0
- package/src/demo/pages/PanelSystem/PanelSystemPreview.module.css +20 -0
- package/src/demo/pages/PanelSystem/PanelSystemPreview.tsx +101 -0
- package/src/demo/pages/PanelSystem/preview/index.tsx +18 -0
- package/src/demo/pages/PanelSystem/tabbar/index.tsx +129 -0
- package/src/demo/pages/Pivot/basics/index.tsx +17 -0
- package/src/demo/pages/Pivot/components/Pivot.module.css +278 -0
- package/src/demo/pages/Pivot/components/PivotBasics.tsx +103 -0
- package/src/demo/pages/Pivot/components/PivotSidebar.tsx +168 -0
- package/src/demo/pages/Pivot/components/PivotTabs.tsx +129 -0
- package/src/demo/pages/Pivot/components/PivotTransitions.tsx +120 -0
- package/src/demo/pages/Pivot/components/SwipePivot.module.css +114 -0
- package/src/demo/pages/Pivot/components/SwipePivot.tsx +193 -0
- package/src/demo/pages/Pivot/components/SwipeTabsPivot.module.css +203 -0
- package/src/demo/pages/Pivot/components/SwipeTabsPivot.tsx +289 -0
- package/src/demo/pages/Pivot/sidebar/index.tsx +17 -0
- package/src/demo/pages/Pivot/swipe/index.tsx +16 -0
- package/src/demo/pages/Pivot/swipe-debug/index.tsx +287 -0
- package/src/demo/pages/Pivot/swipe-tabs/index.tsx +15 -0
- package/src/demo/pages/Pivot/tabs/index.tsx +17 -0
- package/src/demo/pages/Pivot/transitions/index.tsx +17 -0
- package/src/demo/pages/ResizeHandle/both-directions/index.tsx +17 -0
- package/src/demo/pages/ResizeHandle/components/BothDirectionsDemo.module.css +72 -0
- package/src/demo/pages/ResizeHandle/components/BothDirectionsDemo.tsx +41 -0
- package/src/demo/pages/ResizeHandle/components/HorizontalResizeDemo.module.css +61 -0
- package/src/demo/pages/ResizeHandle/components/HorizontalResizeDemo.tsx +33 -0
- package/src/demo/pages/ResizeHandle/components/NestedPanelsDemo.module.css +83 -0
- package/src/demo/pages/ResizeHandle/components/NestedPanelsDemo.tsx +53 -0
- package/src/demo/pages/ResizeHandle/components/VerticalResizeDemo.module.css +68 -0
- package/src/demo/pages/ResizeHandle/components/VerticalResizeDemo.tsx +33 -0
- package/src/demo/pages/ResizeHandle/horizontal/index.tsx +17 -0
- package/src/demo/pages/ResizeHandle/index.module.css +11 -0
- package/src/demo/pages/ResizeHandle/index.tsx +71 -0
- package/src/demo/pages/ResizeHandle/nested-panels/index.tsx +17 -0
- package/src/demo/pages/ResizeHandle/vertical/index.tsx +17 -0
- package/src/demo/pages/ResponsiveLayout/adaptive-workspace/index.tsx +22 -0
- package/src/demo/pages/ResponsiveLayout/components/ResponsiveWorkspace.module.css +423 -0
- package/src/demo/pages/ResponsiveLayout/components/ResponsiveWorkspace.tsx +398 -0
- package/src/demo/pages/Stack/basics/index.tsx +22 -0
- package/src/demo/pages/Stack/components/Stack.module.css +234 -0
- package/src/demo/pages/Stack/components/StackBasics.tsx +217 -0
- package/src/demo/pages/Stack/components/StackTablet.module.css +299 -0
- package/src/demo/pages/Stack/components/StackTablet.tsx +401 -0
- package/src/demo/pages/Stack/tablet/index.tsx +22 -0
- package/src/demo/pages/StickyHeader/basics/index.tsx +17 -0
- package/src/demo/pages/StickyHeader/components/StickyHeader.module.css +219 -0
- package/src/demo/pages/StickyHeader/components/StickyHeaderBasics.tsx +103 -0
- package/src/demo/routes.tsx +193 -0
- package/src/demo/styles/animations.css +68 -0
- package/src/demo/styles/stack-themes.css +35 -0
- package/src/demo/utils/createPanelView.tsx +58 -0
- package/src/floating/index.ts +24 -0
- package/src/grid/index.ts +75 -0
- package/src/hooks/ContentCacheContext.tsx +87 -0
- package/src/hooks/gesture/presets.spec.ts +86 -0
- package/src/hooks/gesture/presets.ts +95 -0
- package/src/hooks/gesture/testing/createGestureSimulator.spec.ts +237 -0
- package/src/hooks/gesture/testing/createGestureSimulator.ts +310 -0
- package/src/hooks/gesture/thresholdValue.spec.ts +103 -0
- package/src/hooks/gesture/thresholdValue.ts +77 -0
- package/src/hooks/gesture/types.ts +290 -0
- package/src/hooks/gesture/useDirectionalLock.spec.ts +271 -0
- package/src/hooks/gesture/useDirectionalLock.ts +115 -0
- package/src/hooks/gesture/useEdgeSwipeInput.spec.ts +454 -0
- package/src/hooks/gesture/useEdgeSwipeInput.ts +131 -0
- package/src/hooks/gesture/useNativeGestureGuard.spec.ts +413 -0
- package/src/hooks/gesture/useNativeGestureGuard.ts +133 -0
- package/src/hooks/gesture/usePointerTracking.spec.ts +364 -0
- package/src/hooks/gesture/usePointerTracking.ts +134 -0
- package/src/hooks/gesture/useScrollBoundary.spec.ts +249 -0
- package/src/hooks/gesture/useScrollBoundary.ts +113 -0
- package/src/hooks/gesture/useSwipeInput.spec.ts +592 -0
- package/src/hooks/gesture/useSwipeInput.ts +310 -0
- package/src/hooks/gesture/utils.spec.ts +152 -0
- package/src/hooks/gesture/utils.ts +87 -0
- package/src/hooks/useAnimatedVisibility.spec.ts +257 -0
- package/src/hooks/useAnimatedVisibility.ts +146 -0
- package/src/hooks/useAnimationFrame.ts +200 -0
- package/src/hooks/useCSSMatrix.spec.ts +214 -0
- package/src/hooks/useCSSMatrix.ts +262 -0
- package/src/hooks/useClonedElementPreview.ts +28 -0
- package/src/hooks/useContainerScroll.ts +78 -0
- package/src/hooks/useContentCache.spec.tsx +232 -0
- package/src/hooks/useContentCache.tsx +127 -0
- package/src/hooks/useDocumentPointerEvents.ts +137 -0
- package/src/hooks/useDocumentScroll.ts +41 -0
- package/src/hooks/useEffectEvent.ts +40 -0
- package/src/hooks/useElementComponentWrapper.tsx +63 -0
- package/src/hooks/useIntersectionObserver.tsx +125 -0
- package/src/hooks/useIsomorphicLayoutEffect.ts +29 -0
- package/src/hooks/useResizeObserver.tsx +81 -0
- package/src/hooks/useScrollContainer.ts +79 -0
- package/src/hooks/useSnapAnimation.ts +128 -0
- package/src/hooks/useSwipeContentTransform.spec.ts +133 -0
- package/src/hooks/useSwipeContentTransform.ts +235 -0
- package/src/hooks/useTransitionState.ts +95 -0
- package/src/index.tsx +88 -0
- package/src/modules/grid/GridLayoutContext.tsx +57 -0
- package/src/modules/grid/LayerInstanceContext.tsx +56 -0
- package/src/modules/grid/resizeHandles.ts +157 -0
- package/src/modules/grid/trackUtils.ts +146 -0
- package/src/modules/grid/useGridPlacements.ts +143 -0
- package/src/modules/grid/useGridTracks.ts +156 -0
- package/src/modules/grid/useLayerDragHandle.ts +16 -0
- package/src/modules/grid/useLayerInteractions.tsx +850 -0
- package/src/modules/keybindings/KeybindingsProvider.tsx +111 -0
- package/src/modules/panels/dom/DomRegistry.tsx +94 -0
- package/src/modules/panels/index.ts +45 -0
- package/src/modules/panels/interactions/InteractionsContext.test.tsx +330 -0
- package/src/modules/panels/interactions/InteractionsContext.tsx +394 -0
- package/src/modules/panels/interactions/dnd.ts +28 -0
- package/src/modules/panels/keybindings/KeybindingsInstaller.tsx +15 -0
- package/src/modules/panels/layout/adapter.ts +124 -0
- package/src/modules/panels/rendering/ContentRegistry.spec.tsx +304 -0
- package/src/modules/panels/rendering/ContentRegistry.tsx +205 -0
- package/src/modules/panels/rendering/GroupContainer.tsx +65 -0
- package/src/modules/panels/rendering/RenderBridge.tsx +115 -0
- package/src/modules/panels/rendering/RenderContext.tsx +31 -0
- package/src/modules/panels/state/PanelSplitHandles.tsx +147 -0
- package/src/modules/panels/state/PanelSystemContext.splitLimits.spec.tsx +50 -0
- package/src/modules/panels/state/PanelSystemContext.tsx +289 -0
- package/src/modules/panels/state/StateContext.tsx +12 -0
- package/src/modules/panels/state/cleanup.ts +37 -0
- package/src/modules/panels/state/commands.ts +53 -0
- package/src/modules/panels/state/focus/Context.tsx +25 -0
- package/src/modules/panels/state/focus/logic.ts +57 -0
- package/src/modules/panels/state/groups/Context.tsx +25 -0
- package/src/modules/panels/state/groups/logic.ts +105 -0
- package/src/modules/panels/state/splitLimits.spec.ts +46 -0
- package/src/modules/panels/state/splitLimits.ts +90 -0
- package/src/modules/panels/state/state.spec.ts +49 -0
- package/src/modules/panels/state/tree/Context.tsx +24 -0
- package/src/modules/panels/state/tree/logic.spec.ts +34 -0
- package/src/modules/panels/state/tree/logic.ts +138 -0
- package/src/modules/panels/state/types.ts +142 -0
- package/src/modules/panels/system/PanelSystem.empty-tabbar.spec.tsx +53 -0
- package/src/modules/panels/system/PanelSystem.tab-click-activates.spec.tsx +44 -0
- package/src/modules/panels/system/PanelSystem.tab-reorder.spec.tsx +64 -0
- package/src/modules/panels/system/PanelSystem.tabs-no-dup.spec.tsx +57 -0
- package/src/modules/panels/system/PanelSystem.tsx +206 -0
- package/src/modules/pivot/PivotContent.spec.tsx +179 -0
- package/src/modules/pivot/PivotContent.tsx +77 -0
- package/src/modules/pivot/SwipePivotContent.debug.tmp.tsx +237 -0
- package/src/modules/pivot/SwipePivotContent.position.spec.tsx +167 -0
- package/src/modules/pivot/SwipePivotContent.spec.tsx +464 -0
- package/src/modules/pivot/SwipePivotContent.test.tsx +502 -0
- package/src/modules/pivot/SwipePivotContent.tsx +197 -0
- package/src/modules/pivot/SwipePivotTabBar.spec.tsx +865 -0
- package/src/modules/pivot/SwipePivotTabBar.tsx +523 -0
- package/src/modules/pivot/index.ts +8 -0
- package/src/modules/pivot/scaleInputState.spec.ts +210 -0
- package/src/modules/pivot/scaleInputState.ts +66 -0
- package/src/modules/pivot/types.ts +139 -0
- package/src/modules/pivot/usePivot.spec.ts +621 -0
- package/src/modules/pivot/usePivot.spec.tsx +186 -0
- package/src/modules/pivot/usePivot.tsx +345 -0
- package/src/modules/pivot/usePivotSwipeInput.spec.ts +649 -0
- package/src/modules/pivot/usePivotSwipeInput.ts +136 -0
- package/src/modules/resizer/useResizeDrag.ts +94 -0
- package/src/modules/stack/StackContent.spec.tsx +264 -0
- package/src/modules/stack/StackContent.tsx +111 -0
- package/src/modules/stack/SwipeStackContent.spec.tsx +1277 -0
- package/src/modules/stack/SwipeStackContent.tsx +356 -0
- package/src/modules/stack/SwipeStackOutlet.spec.tsx +252 -0
- package/src/modules/stack/SwipeStackOutlet.tsx +221 -0
- package/src/modules/stack/computeStackContentState.spec.ts +281 -0
- package/src/modules/stack/computeStackContentState.ts +304 -0
- package/src/modules/stack/computeSwipeStackTransform.spec.ts +186 -0
- package/src/modules/stack/computeSwipeStackTransform.ts +145 -0
- package/src/modules/stack/types.ts +226 -0
- package/src/modules/stack/useStackAnimationState.spec.ts +186 -0
- package/src/modules/stack/useStackAnimationState.ts +138 -0
- package/src/modules/stack/useStackNavigation.spec.ts +477 -0
- package/src/modules/stack/useStackNavigation.tsx +336 -0
- package/src/modules/stack/useStackSwipeInput.spec.ts +276 -0
- package/src/modules/stack/useStackSwipeInput.ts +139 -0
- package/src/modules/window/useDrawerState.ts +81 -0
- package/src/modules/window/useFloatingState.spec.ts +252 -0
- package/src/modules/window/useFloatingState.ts +141 -0
- package/src/panels/index.ts +119 -0
- package/src/pivot/index.ts +19 -0
- package/src/resizer/index.ts +68 -0
- package/src/stack/index.ts +91 -0
- package/src/sticky-header/StickyArea.tsx +221 -0
- package/src/sticky-header/index.ts +18 -0
- package/src/sticky-header/types.ts +68 -0
- package/src/types.ts +323 -0
- package/src/utils/CSSMatrix.ts +321 -0
- package/src/utils/css.ts +65 -0
- package/src/utils/dialogUtils.ts +43 -0
- package/src/utils/math.ts +18 -0
- package/src/utils/polyfills/createDialogPolyfill.ts +18 -0
- package/src/utils/typedActions.ts +103 -0
- package/src/vite-env.d.ts +6 -0
- package/src/window/index.ts +67 -0
- package/dist/FloatingPanelFrame-6W5OexYe.js.map +0 -1
- package/dist/FloatingPanelFrame-D9Cp2al1.cjs.map +0 -1
- package/dist/GridLayout-BzrIDrC9.js +0 -1465
- package/dist/GridLayout-BzrIDrC9.js.map +0 -1
- package/dist/GridLayout-ZrOhoLLB.cjs +0 -2
- package/dist/GridLayout-ZrOhoLLB.cjs.map +0 -1
- package/dist/sticky-header/StickyHeader.d.ts +0 -53
- package/dist/styles-CA2_zLZt.js +0 -52
- package/dist/styles-CA2_zLZt.js.map +0 -1
- package/dist/styles-PsqGOEJP.cjs +0 -2
- package/dist/styles-PsqGOEJP.cjs.map +0 -1
- package/dist/usePivot-BS-DGfwd.cjs +0 -2
- package/dist/usePivot-BS-DGfwd.cjs.map +0 -1
- package/dist/usePivot-BvOGxLQQ.js +0 -124
- package/dist/usePivot-BvOGxLQQ.js.map +0 -1
|
@@ -0,0 +1,621 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @file Tests for usePivot hook - navigation methods.
|
|
3
|
+
*/
|
|
4
|
+
import { renderHook, act } from "@testing-library/react";
|
|
5
|
+
import { usePivot } from "./usePivot.js";
|
|
6
|
+
import type { PivotItem } from "./types.js";
|
|
7
|
+
|
|
8
|
+
describe("usePivot", () => {
|
|
9
|
+
const createItems = (): ReadonlyArray<PivotItem<"a" | "b" | "c">> => [
|
|
10
|
+
{ id: "a", label: "Item A", content: "Content A" },
|
|
11
|
+
{ id: "b", label: "Item B", content: "Content B" },
|
|
12
|
+
{ id: "c", label: "Item C", content: "Content C" },
|
|
13
|
+
];
|
|
14
|
+
|
|
15
|
+
describe("go navigation", () => {
|
|
16
|
+
it("navigates to next item with go(1)", () => {
|
|
17
|
+
const items = createItems();
|
|
18
|
+
const { result } = renderHook(() =>
|
|
19
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
20
|
+
);
|
|
21
|
+
|
|
22
|
+
expect(result.current.activeId).toBe("a");
|
|
23
|
+
|
|
24
|
+
act(() => {
|
|
25
|
+
result.current.go(1);
|
|
26
|
+
});
|
|
27
|
+
|
|
28
|
+
expect(result.current.activeId).toBe("b");
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("navigates to previous item with go(-1)", () => {
|
|
32
|
+
const items = createItems();
|
|
33
|
+
const { result } = renderHook(() =>
|
|
34
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
expect(result.current.activeId).toBe("b");
|
|
38
|
+
|
|
39
|
+
act(() => {
|
|
40
|
+
result.current.go(-1);
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
expect(result.current.activeId).toBe("a");
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("navigates multiple steps with go(2)", () => {
|
|
47
|
+
const items = createItems();
|
|
48
|
+
const { result } = renderHook(() =>
|
|
49
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
50
|
+
);
|
|
51
|
+
|
|
52
|
+
act(() => {
|
|
53
|
+
result.current.go(2);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
expect(result.current.activeId).toBe("c");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("does not navigate beyond first item", () => {
|
|
60
|
+
const items = createItems();
|
|
61
|
+
const { result } = renderHook(() =>
|
|
62
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
act(() => {
|
|
66
|
+
result.current.go(-1);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
expect(result.current.activeId).toBe("a");
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("does not navigate beyond last item", () => {
|
|
73
|
+
const items = createItems();
|
|
74
|
+
const { result } = renderHook(() =>
|
|
75
|
+
usePivot({ items, defaultActiveId: "c" }),
|
|
76
|
+
);
|
|
77
|
+
|
|
78
|
+
act(() => {
|
|
79
|
+
result.current.go(1);
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(result.current.activeId).toBe("c");
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("does nothing with go(0)", () => {
|
|
86
|
+
const items = createItems();
|
|
87
|
+
const { result } = renderHook(() =>
|
|
88
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
act(() => {
|
|
92
|
+
result.current.go(0);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
expect(result.current.activeId).toBe("b");
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("skips disabled items in navigation", () => {
|
|
99
|
+
const items: ReadonlyArray<PivotItem<"a" | "b" | "c">> = [
|
|
100
|
+
{ id: "a", label: "Item A", content: "Content A" },
|
|
101
|
+
{ id: "b", label: "Item B", content: "Content B", disabled: true },
|
|
102
|
+
{ id: "c", label: "Item C", content: "Content C" },
|
|
103
|
+
];
|
|
104
|
+
|
|
105
|
+
const { result } = renderHook(() =>
|
|
106
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// go(1) should go to 'c' since 'b' is disabled and not in enabledItems
|
|
110
|
+
act(() => {
|
|
111
|
+
result.current.go(1);
|
|
112
|
+
});
|
|
113
|
+
|
|
114
|
+
expect(result.current.activeId).toBe("c");
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
describe("canGo", () => {
|
|
119
|
+
it("returns true when can navigate forward", () => {
|
|
120
|
+
const items = createItems();
|
|
121
|
+
const { result } = renderHook(() =>
|
|
122
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
expect(result.current.canGo(1)).toBe(true);
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("returns false when at last item", () => {
|
|
129
|
+
const items = createItems();
|
|
130
|
+
const { result } = renderHook(() =>
|
|
131
|
+
usePivot({ items, defaultActiveId: "c" }),
|
|
132
|
+
);
|
|
133
|
+
|
|
134
|
+
expect(result.current.canGo(1)).toBe(false);
|
|
135
|
+
});
|
|
136
|
+
|
|
137
|
+
it("returns true when can navigate backward", () => {
|
|
138
|
+
const items = createItems();
|
|
139
|
+
const { result } = renderHook(() =>
|
|
140
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
141
|
+
);
|
|
142
|
+
|
|
143
|
+
expect(result.current.canGo(-1)).toBe(true);
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("returns false when at first item", () => {
|
|
147
|
+
const items = createItems();
|
|
148
|
+
const { result } = renderHook(() =>
|
|
149
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
150
|
+
);
|
|
151
|
+
|
|
152
|
+
expect(result.current.canGo(-1)).toBe(false);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("returns false for go(0)", () => {
|
|
156
|
+
const items = createItems();
|
|
157
|
+
const { result } = renderHook(() =>
|
|
158
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
159
|
+
);
|
|
160
|
+
|
|
161
|
+
expect(result.current.canGo(0)).toBe(false);
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
it("returns correct value for multi-step navigation", () => {
|
|
165
|
+
const items = createItems();
|
|
166
|
+
const { result } = renderHook(() =>
|
|
167
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
168
|
+
);
|
|
169
|
+
|
|
170
|
+
expect(result.current.canGo(2)).toBe(true); // Can go to 'c'
|
|
171
|
+
expect(result.current.canGo(3)).toBe(false); // Would go beyond 'c'
|
|
172
|
+
});
|
|
173
|
+
});
|
|
174
|
+
|
|
175
|
+
describe("activeIndex", () => {
|
|
176
|
+
it("returns correct index for first item", () => {
|
|
177
|
+
const items = createItems();
|
|
178
|
+
const { result } = renderHook(() =>
|
|
179
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
180
|
+
);
|
|
181
|
+
|
|
182
|
+
expect(result.current.activeIndex).toBe(0);
|
|
183
|
+
});
|
|
184
|
+
|
|
185
|
+
it("returns correct index for middle item", () => {
|
|
186
|
+
const items = createItems();
|
|
187
|
+
const { result } = renderHook(() =>
|
|
188
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
189
|
+
);
|
|
190
|
+
|
|
191
|
+
expect(result.current.activeIndex).toBe(1);
|
|
192
|
+
});
|
|
193
|
+
|
|
194
|
+
it("returns correct index for last item", () => {
|
|
195
|
+
const items = createItems();
|
|
196
|
+
const { result } = renderHook(() =>
|
|
197
|
+
usePivot({ items, defaultActiveId: "c" }),
|
|
198
|
+
);
|
|
199
|
+
|
|
200
|
+
expect(result.current.activeIndex).toBe(2);
|
|
201
|
+
});
|
|
202
|
+
|
|
203
|
+
it("updates when active item changes", () => {
|
|
204
|
+
const items = createItems();
|
|
205
|
+
const { result } = renderHook(() =>
|
|
206
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
207
|
+
);
|
|
208
|
+
|
|
209
|
+
expect(result.current.activeIndex).toBe(0);
|
|
210
|
+
|
|
211
|
+
act(() => {
|
|
212
|
+
result.current.setActiveId("c");
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
expect(result.current.activeIndex).toBe(2);
|
|
216
|
+
});
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
describe("itemCount", () => {
|
|
220
|
+
it("returns total count of enabled items", () => {
|
|
221
|
+
const items = createItems();
|
|
222
|
+
const { result } = renderHook(() =>
|
|
223
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
expect(result.current.itemCount).toBe(3);
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("excludes disabled items from count", () => {
|
|
230
|
+
const items: ReadonlyArray<PivotItem<"a" | "b" | "c">> = [
|
|
231
|
+
{ id: "a", label: "Item A", content: "Content A" },
|
|
232
|
+
{ id: "b", label: "Item B", content: "Content B", disabled: true },
|
|
233
|
+
{ id: "c", label: "Item C", content: "Content C" },
|
|
234
|
+
];
|
|
235
|
+
|
|
236
|
+
const { result } = renderHook(() =>
|
|
237
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
238
|
+
);
|
|
239
|
+
|
|
240
|
+
expect(result.current.itemCount).toBe(2);
|
|
241
|
+
});
|
|
242
|
+
});
|
|
243
|
+
|
|
244
|
+
describe("onActiveChange callback", () => {
|
|
245
|
+
it("calls onActiveChange when navigating with go", () => {
|
|
246
|
+
const items = createItems();
|
|
247
|
+
const onActiveChange = vi.fn();
|
|
248
|
+
const { result } = renderHook(() =>
|
|
249
|
+
usePivot({ items, defaultActiveId: "a", onActiveChange }),
|
|
250
|
+
);
|
|
251
|
+
|
|
252
|
+
act(() => {
|
|
253
|
+
result.current.go(1);
|
|
254
|
+
});
|
|
255
|
+
|
|
256
|
+
expect(onActiveChange).toHaveBeenCalledWith("b");
|
|
257
|
+
});
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
describe("go with animation options", () => {
|
|
261
|
+
it("go() supports animated option", () => {
|
|
262
|
+
// Previous/Nextの操作は、アニメーション込みで移動するかどうかを設定できるようにしたい
|
|
263
|
+
const items = createItems();
|
|
264
|
+
const { result } = renderHook(() =>
|
|
265
|
+
usePivot({ items, defaultActiveId: "a", transitionMode: "css" }),
|
|
266
|
+
);
|
|
267
|
+
|
|
268
|
+
// go(direction, { animated: false }) でアニメーションなしに移動できる
|
|
269
|
+
act(() => {
|
|
270
|
+
result.current.go(1, { animated: false });
|
|
271
|
+
});
|
|
272
|
+
|
|
273
|
+
expect(result.current.activeId).toBe("b");
|
|
274
|
+
// isAnimating should be false when animated: false
|
|
275
|
+
expect(result.current.isAnimating).toBe(false);
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
it("go() defaults to animated based on transitionMode", () => {
|
|
279
|
+
const items = createItems();
|
|
280
|
+
const { result } = renderHook(() =>
|
|
281
|
+
usePivot({ items, defaultActiveId: "a", transitionMode: "css" }),
|
|
282
|
+
);
|
|
283
|
+
|
|
284
|
+
act(() => {
|
|
285
|
+
result.current.go(1); // デフォルトはtransitionModeに従う
|
|
286
|
+
});
|
|
287
|
+
|
|
288
|
+
expect(result.current.activeId).toBe("b");
|
|
289
|
+
// Should be animating when transitionMode is "css" and no animated option
|
|
290
|
+
expect(result.current.isAnimating).toBe(true);
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
it("setActiveId() also supports animated option", () => {
|
|
294
|
+
const items = createItems();
|
|
295
|
+
const { result } = renderHook(() =>
|
|
296
|
+
usePivot({ items, defaultActiveId: "a", transitionMode: "css" }),
|
|
297
|
+
);
|
|
298
|
+
|
|
299
|
+
act(() => {
|
|
300
|
+
result.current.setActiveId("c", { animated: false });
|
|
301
|
+
});
|
|
302
|
+
|
|
303
|
+
expect(result.current.activeId).toBe("c");
|
|
304
|
+
expect(result.current.isAnimating).toBe(false);
|
|
305
|
+
});
|
|
306
|
+
|
|
307
|
+
it("isAnimating becomes false after animation completes", async () => {
|
|
308
|
+
const items = createItems();
|
|
309
|
+
const { result } = renderHook(() =>
|
|
310
|
+
usePivot({ items, defaultActiveId: "a", transitionMode: "css" }),
|
|
311
|
+
);
|
|
312
|
+
|
|
313
|
+
act(() => {
|
|
314
|
+
result.current.go(1);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
expect(result.current.isAnimating).toBe(true);
|
|
318
|
+
|
|
319
|
+
// Animation ends via endAnimation callback
|
|
320
|
+
act(() => {
|
|
321
|
+
result.current.endAnimation();
|
|
322
|
+
});
|
|
323
|
+
|
|
324
|
+
expect(result.current.isAnimating).toBe(false);
|
|
325
|
+
});
|
|
326
|
+
});
|
|
327
|
+
|
|
328
|
+
describe("loop navigation mode", () => {
|
|
329
|
+
it("returns loop navigationMode when set", () => {
|
|
330
|
+
const items = createItems();
|
|
331
|
+
const { result } = renderHook(() =>
|
|
332
|
+
usePivot({ items, defaultActiveId: "a", navigationMode: "loop" }),
|
|
333
|
+
);
|
|
334
|
+
|
|
335
|
+
expect(result.current.navigationMode).toBe("loop");
|
|
336
|
+
});
|
|
337
|
+
|
|
338
|
+
it("returns linear navigationMode by default", () => {
|
|
339
|
+
const items = createItems();
|
|
340
|
+
const { result } = renderHook(() =>
|
|
341
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
342
|
+
);
|
|
343
|
+
|
|
344
|
+
expect(result.current.navigationMode).toBe("linear");
|
|
345
|
+
});
|
|
346
|
+
|
|
347
|
+
it("canGo returns true in both directions when in loop mode", () => {
|
|
348
|
+
const items = createItems();
|
|
349
|
+
const { result } = renderHook(() =>
|
|
350
|
+
usePivot({ items, defaultActiveId: "a", navigationMode: "loop" }),
|
|
351
|
+
);
|
|
352
|
+
|
|
353
|
+
// At first item, can still go backward in loop mode
|
|
354
|
+
expect(result.current.canGo(-1)).toBe(true);
|
|
355
|
+
expect(result.current.canGo(1)).toBe(true);
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("canGo returns true at last item in loop mode", () => {
|
|
359
|
+
const items = createItems();
|
|
360
|
+
const { result } = renderHook(() =>
|
|
361
|
+
usePivot({ items, defaultActiveId: "c", navigationMode: "loop" }),
|
|
362
|
+
);
|
|
363
|
+
|
|
364
|
+
// At last item, can still go forward in loop mode
|
|
365
|
+
expect(result.current.canGo(1)).toBe(true);
|
|
366
|
+
expect(result.current.canGo(-1)).toBe(true);
|
|
367
|
+
});
|
|
368
|
+
|
|
369
|
+
it("canGo returns false for single item in loop mode", () => {
|
|
370
|
+
const items: ReadonlyArray<PivotItem<"a">> = [
|
|
371
|
+
{ id: "a", label: "Item A", content: "Content A" },
|
|
372
|
+
];
|
|
373
|
+
const { result } = renderHook(() =>
|
|
374
|
+
usePivot({ items, defaultActiveId: "a", navigationMode: "loop" }),
|
|
375
|
+
);
|
|
376
|
+
|
|
377
|
+
expect(result.current.canGo(1)).toBe(false);
|
|
378
|
+
expect(result.current.canGo(-1)).toBe(false);
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("go(1) wraps from last to first in loop mode", () => {
|
|
382
|
+
const items = createItems();
|
|
383
|
+
const { result } = renderHook(() =>
|
|
384
|
+
usePivot({ items, defaultActiveId: "c", navigationMode: "loop" }),
|
|
385
|
+
);
|
|
386
|
+
|
|
387
|
+
expect(result.current.activeId).toBe("c");
|
|
388
|
+
|
|
389
|
+
act(() => {
|
|
390
|
+
result.current.go(1);
|
|
391
|
+
});
|
|
392
|
+
|
|
393
|
+
expect(result.current.activeId).toBe("a");
|
|
394
|
+
});
|
|
395
|
+
|
|
396
|
+
it("go(-1) wraps from first to last in loop mode", () => {
|
|
397
|
+
const items = createItems();
|
|
398
|
+
const { result } = renderHook(() =>
|
|
399
|
+
usePivot({ items, defaultActiveId: "a", navigationMode: "loop" }),
|
|
400
|
+
);
|
|
401
|
+
|
|
402
|
+
expect(result.current.activeId).toBe("a");
|
|
403
|
+
|
|
404
|
+
act(() => {
|
|
405
|
+
result.current.go(-1);
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
expect(result.current.activeId).toBe("c");
|
|
409
|
+
});
|
|
410
|
+
|
|
411
|
+
it("go(2) wraps correctly in loop mode", () => {
|
|
412
|
+
const items = createItems();
|
|
413
|
+
const { result } = renderHook(() =>
|
|
414
|
+
usePivot({ items, defaultActiveId: "b", navigationMode: "loop" }),
|
|
415
|
+
);
|
|
416
|
+
|
|
417
|
+
// b(1) + 2 = 3 % 3 = 0 -> a
|
|
418
|
+
act(() => {
|
|
419
|
+
result.current.go(2);
|
|
420
|
+
});
|
|
421
|
+
|
|
422
|
+
expect(result.current.activeId).toBe("a");
|
|
423
|
+
});
|
|
424
|
+
});
|
|
425
|
+
|
|
426
|
+
describe("getVirtualPosition", () => {
|
|
427
|
+
it("returns 0 for active item in linear mode", () => {
|
|
428
|
+
const items = createItems();
|
|
429
|
+
const { result } = renderHook(() =>
|
|
430
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
431
|
+
);
|
|
432
|
+
|
|
433
|
+
expect(result.current.getVirtualPosition("b")).toBe(0);
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("returns -1 for previous item in linear mode", () => {
|
|
437
|
+
const items = createItems();
|
|
438
|
+
const { result } = renderHook(() =>
|
|
439
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
440
|
+
);
|
|
441
|
+
|
|
442
|
+
expect(result.current.getVirtualPosition("a")).toBe(-1);
|
|
443
|
+
});
|
|
444
|
+
|
|
445
|
+
it("returns 1 for next item in linear mode", () => {
|
|
446
|
+
const items = createItems();
|
|
447
|
+
const { result } = renderHook(() =>
|
|
448
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
449
|
+
);
|
|
450
|
+
|
|
451
|
+
expect(result.current.getVirtualPosition("c")).toBe(1);
|
|
452
|
+
});
|
|
453
|
+
|
|
454
|
+
it("returns null for non-adjacent items in linear mode", () => {
|
|
455
|
+
const items: ReadonlyArray<PivotItem<"a" | "b" | "c" | "d">> = [
|
|
456
|
+
{ id: "a", label: "Item A", content: "Content A" },
|
|
457
|
+
{ id: "b", label: "Item B", content: "Content B" },
|
|
458
|
+
{ id: "c", label: "Item C", content: "Content C" },
|
|
459
|
+
{ id: "d", label: "Item D", content: "Content D" },
|
|
460
|
+
];
|
|
461
|
+
const { result } = renderHook(() =>
|
|
462
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
463
|
+
);
|
|
464
|
+
|
|
465
|
+
// 'c' and 'd' are not adjacent to 'a'
|
|
466
|
+
expect(result.current.getVirtualPosition("c")).toBe(null);
|
|
467
|
+
expect(result.current.getVirtualPosition("d")).toBe(null);
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
it("returns 0 for active item in loop mode", () => {
|
|
471
|
+
const items = createItems();
|
|
472
|
+
const { result } = renderHook(() =>
|
|
473
|
+
usePivot({ items, defaultActiveId: "b", navigationMode: "loop" }),
|
|
474
|
+
);
|
|
475
|
+
|
|
476
|
+
expect(result.current.getVirtualPosition("b")).toBe(0);
|
|
477
|
+
});
|
|
478
|
+
|
|
479
|
+
it("returns 1 for first item when last is active in loop mode", () => {
|
|
480
|
+
const items = createItems();
|
|
481
|
+
const { result } = renderHook(() =>
|
|
482
|
+
usePivot({ items, defaultActiveId: "c", navigationMode: "loop" }),
|
|
483
|
+
);
|
|
484
|
+
|
|
485
|
+
// When 'c' (last) is active, 'a' (first) should be at position 1 (next)
|
|
486
|
+
expect(result.current.getVirtualPosition("a")).toBe(1);
|
|
487
|
+
});
|
|
488
|
+
|
|
489
|
+
it("returns -1 for last item when first is active in loop mode", () => {
|
|
490
|
+
const items = createItems();
|
|
491
|
+
const { result } = renderHook(() =>
|
|
492
|
+
usePivot({ items, defaultActiveId: "a", navigationMode: "loop" }),
|
|
493
|
+
);
|
|
494
|
+
|
|
495
|
+
// When 'a' (first) is active, 'c' (last) should be at position -1 (prev)
|
|
496
|
+
expect(result.current.getVirtualPosition("c")).toBe(-1);
|
|
497
|
+
});
|
|
498
|
+
|
|
499
|
+
it("returns null for non-adjacent items in loop mode with 4+ items", () => {
|
|
500
|
+
const items: ReadonlyArray<PivotItem<"a" | "b" | "c" | "d">> = [
|
|
501
|
+
{ id: "a", label: "Item A", content: "Content A" },
|
|
502
|
+
{ id: "b", label: "Item B", content: "Content B" },
|
|
503
|
+
{ id: "c", label: "Item C", content: "Content C" },
|
|
504
|
+
{ id: "d", label: "Item D", content: "Content D" },
|
|
505
|
+
];
|
|
506
|
+
const { result } = renderHook(() =>
|
|
507
|
+
usePivot({ items, defaultActiveId: "a", navigationMode: "loop" }),
|
|
508
|
+
);
|
|
509
|
+
|
|
510
|
+
// 'a' is active, adjacent are 'd' (-1) and 'b' (1)
|
|
511
|
+
// 'c' is not adjacent
|
|
512
|
+
expect(result.current.getVirtualPosition("c")).toBe(null);
|
|
513
|
+
});
|
|
514
|
+
|
|
515
|
+
it("returns null for non-existent item", () => {
|
|
516
|
+
const items = createItems();
|
|
517
|
+
const { result } = renderHook(() =>
|
|
518
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
519
|
+
);
|
|
520
|
+
|
|
521
|
+
expect(result.current.getVirtualPosition("nonexistent" as "a")).toBe(null);
|
|
522
|
+
});
|
|
523
|
+
});
|
|
524
|
+
|
|
525
|
+
describe("getItemPosition", () => {
|
|
526
|
+
it("returns 0 for active item in linear mode", () => {
|
|
527
|
+
const items = createItems();
|
|
528
|
+
const { result } = renderHook(() =>
|
|
529
|
+
usePivot({ items, defaultActiveId: "b" }),
|
|
530
|
+
);
|
|
531
|
+
|
|
532
|
+
expect(result.current.getItemPosition("b")).toBe(0);
|
|
533
|
+
});
|
|
534
|
+
|
|
535
|
+
it("returns correct positions for all items in linear mode", () => {
|
|
536
|
+
const items: ReadonlyArray<PivotItem<"a" | "b" | "c" | "d" | "e">> = [
|
|
537
|
+
{ id: "a", label: "A", content: "A" },
|
|
538
|
+
{ id: "b", label: "B", content: "B" },
|
|
539
|
+
{ id: "c", label: "C", content: "C" },
|
|
540
|
+
{ id: "d", label: "D", content: "D" },
|
|
541
|
+
{ id: "e", label: "E", content: "E" },
|
|
542
|
+
];
|
|
543
|
+
const { result } = renderHook(() =>
|
|
544
|
+
usePivot({ items, defaultActiveId: "c" }),
|
|
545
|
+
);
|
|
546
|
+
|
|
547
|
+
// c is at index 2, so:
|
|
548
|
+
// a(0) -> -2, b(1) -> -1, c(2) -> 0, d(3) -> 1, e(4) -> 2
|
|
549
|
+
expect(result.current.getItemPosition("a")).toBe(-2);
|
|
550
|
+
expect(result.current.getItemPosition("b")).toBe(-1);
|
|
551
|
+
expect(result.current.getItemPosition("c")).toBe(0);
|
|
552
|
+
expect(result.current.getItemPosition("d")).toBe(1);
|
|
553
|
+
expect(result.current.getItemPosition("e")).toBe(2);
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it("returns 0 for active item in loop mode", () => {
|
|
557
|
+
const items = createItems();
|
|
558
|
+
const { result } = renderHook(() =>
|
|
559
|
+
usePivot({ items, defaultActiveId: "b", navigationMode: "loop" }),
|
|
560
|
+
);
|
|
561
|
+
|
|
562
|
+
expect(result.current.getItemPosition("b")).toBe(0);
|
|
563
|
+
});
|
|
564
|
+
|
|
565
|
+
it("returns shortest path position in loop mode (5 items)", () => {
|
|
566
|
+
const items: ReadonlyArray<PivotItem<"a" | "b" | "c" | "d" | "e">> = [
|
|
567
|
+
{ id: "a", label: "A", content: "A" },
|
|
568
|
+
{ id: "b", label: "B", content: "B" },
|
|
569
|
+
{ id: "c", label: "C", content: "C" },
|
|
570
|
+
{ id: "d", label: "D", content: "D" },
|
|
571
|
+
{ id: "e", label: "E", content: "E" },
|
|
572
|
+
];
|
|
573
|
+
const { result } = renderHook(() =>
|
|
574
|
+
usePivot({ items, defaultActiveId: "c", navigationMode: "loop" }),
|
|
575
|
+
);
|
|
576
|
+
|
|
577
|
+
// c is active (index 2). 5 items total.
|
|
578
|
+
// a(0): forward=3, backward=2 -> -2
|
|
579
|
+
// b(1): forward=4, backward=1 -> -1
|
|
580
|
+
// c(2): 0
|
|
581
|
+
// d(3): forward=1, backward=4 -> 1
|
|
582
|
+
// e(4): forward=2, backward=3 -> 2
|
|
583
|
+
expect(result.current.getItemPosition("a")).toBe(-2);
|
|
584
|
+
expect(result.current.getItemPosition("b")).toBe(-1);
|
|
585
|
+
expect(result.current.getItemPosition("c")).toBe(0);
|
|
586
|
+
expect(result.current.getItemPosition("d")).toBe(1);
|
|
587
|
+
expect(result.current.getItemPosition("e")).toBe(2);
|
|
588
|
+
});
|
|
589
|
+
|
|
590
|
+
it("returns 1 for first item when last is active in loop mode", () => {
|
|
591
|
+
const items = createItems();
|
|
592
|
+
const { result } = renderHook(() =>
|
|
593
|
+
usePivot({ items, defaultActiveId: "c", navigationMode: "loop" }),
|
|
594
|
+
);
|
|
595
|
+
|
|
596
|
+
// c(2) is active. 3 items.
|
|
597
|
+
// a(0): forward=1, backward=2 -> 1
|
|
598
|
+
expect(result.current.getItemPosition("a")).toBe(1);
|
|
599
|
+
});
|
|
600
|
+
|
|
601
|
+
it("returns -1 for last item when first is active in loop mode", () => {
|
|
602
|
+
const items = createItems();
|
|
603
|
+
const { result } = renderHook(() =>
|
|
604
|
+
usePivot({ items, defaultActiveId: "a", navigationMode: "loop" }),
|
|
605
|
+
);
|
|
606
|
+
|
|
607
|
+
// a(0) is active. 3 items.
|
|
608
|
+
// c(2): forward=2, backward=1 -> -1
|
|
609
|
+
expect(result.current.getItemPosition("c")).toBe(-1);
|
|
610
|
+
});
|
|
611
|
+
|
|
612
|
+
it("returns null for non-existent item", () => {
|
|
613
|
+
const items = createItems();
|
|
614
|
+
const { result } = renderHook(() =>
|
|
615
|
+
usePivot({ items, defaultActiveId: "a" }),
|
|
616
|
+
);
|
|
617
|
+
|
|
618
|
+
expect(result.current.getItemPosition("nonexistent" as "a")).toBe(null);
|
|
619
|
+
});
|
|
620
|
+
});
|
|
621
|
+
});
|