@vuer-ai/vuer-uikit 0.0.96 → 0.0.98
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/README.md +106 -7
- package/cli/dial-cli.js +49 -7
- package/dist/SyncScroll/SyncScroll.cjs +10 -10
- package/dist/SyncScroll/SyncScroll.mjs +3 -3
- package/dist/SyncScroll/index.cjs +10 -10
- package/dist/SyncScroll/index.mjs +3 -3
- package/dist/chunk-3HEZVWRW.mjs +62 -0
- package/dist/chunk-4KWGGESI.cjs +494 -0
- package/dist/{chunk-CCMKL2OA.cjs → chunk-7GWDO25E.cjs} +2 -2
- package/dist/chunk-A5LCX2UQ.cjs +208 -0
- package/dist/chunk-BEJIZ56L.mjs +300 -0
- package/dist/chunk-C7VGRU3O.mjs +283 -0
- package/dist/{chunk-LONOMMFA.cjs → chunk-LJMNHTTG.cjs} +21 -21
- package/dist/chunk-O66RESRR.cjs +285 -0
- package/dist/{chunk-RINTUFYQ.cjs → chunk-RMK6W774.cjs} +24 -19
- package/dist/{chunk-BFQ2WL5U.mjs → chunk-TTYSYGVE.mjs} +2 -2
- package/dist/chunk-VA3PEYFM.mjs +489 -0
- package/dist/chunk-VBBJSIY7.cjs +308 -0
- package/dist/{chunk-AIINOWEH.mjs → chunk-W4JCKCW7.mjs} +5 -5
- package/dist/chunk-WWGF6TBZ.mjs +206 -0
- package/dist/chunk-ZGN4UEJR.cjs +679 -0
- package/dist/chunk-ZQLRMOUW.mjs +661 -0
- package/dist/dial/DialPanel.cjs +24 -24
- package/dist/dial/DialPanel.mjs +23 -23
- package/dist/dial/DialProvider.cjs +3 -3
- package/dist/dial/DialProvider.d.cts +1 -0
- package/dist/dial/DialProvider.d.ts +1 -0
- package/dist/dial/DialProvider.example.cjs +72 -0
- package/dist/dial/DialProvider.example.d.cts +7 -0
- package/dist/dial/DialProvider.example.d.ts +7 -0
- package/dist/dial/DialProvider.example.mjs +68 -0
- package/dist/dial/DialProvider.mjs +1 -1
- package/dist/dial/index.cjs +42 -42
- package/dist/dial/index.mjs +23 -23
- package/dist/dial/wrapped-inputs/ControlledInputs.cjs +27 -27
- package/dist/dial/wrapped-inputs/ControlledInputs.mjs +23 -23
- package/dist/dial/wrapped-inputs/DialInputs.cjs +34 -34
- package/dist/dial/wrapped-inputs/DialInputs.mjs +23 -23
- package/dist/dial/wrapped-inputs/DialVectorInput.cjs +24 -24
- package/dist/dial/wrapped-inputs/DialVectorInput.mjs +23 -23
- package/dist/dial/wrapped-inputs/index.cjs +39 -39
- package/dist/dial/wrapped-inputs/index.mjs +23 -23
- package/dist/highlight-cursor/cursor-provider.cjs +3 -3
- package/dist/highlight-cursor/cursor-provider.mjs +2 -2
- package/dist/highlight-cursor/enhanced-components.cjs +10 -10
- package/dist/highlight-cursor/enhanced-components.mjs +5 -5
- package/dist/highlight-cursor/index.cjs +16 -16
- package/dist/highlight-cursor/index.mjs +6 -6
- package/dist/hooks/index.cjs +5 -5
- package/dist/hooks/index.mjs +1 -1
- package/dist/index.cjs +190 -190
- package/dist/index.mjs +23 -23
- package/dist/ui/UIKitBadge.cjs +6 -6
- package/dist/ui/UIKitBadge.mjs +2 -2
- package/dist/ui/avatar.cjs +1 -1
- package/dist/ui/avatar.mjs +1 -1
- package/dist/ui/badge.cjs +1 -1
- package/dist/ui/badge.d.cts +1 -1
- package/dist/ui/badge.d.ts +1 -1
- package/dist/ui/badge.mjs +1 -1
- package/dist/ui/button.cjs +1 -1
- package/dist/ui/button.mjs +1 -1
- package/dist/ui/card.cjs +1 -1
- package/dist/ui/card.mjs +1 -1
- package/dist/ui/checkbox.cjs +1 -1
- package/dist/ui/checkbox.mjs +1 -1
- package/dist/ui/collapsible.cjs +1 -1
- package/dist/ui/collapsible.mjs +1 -1
- package/dist/ui/drawer.cjs +1 -1
- package/dist/ui/drawer.mjs +1 -1
- package/dist/ui/dropdown.cjs +1 -1
- package/dist/ui/dropdown.mjs +1 -1
- package/dist/ui/index.cjs +107 -107
- package/dist/ui/index.mjs +17 -17
- package/dist/ui/inputs/color-input.cjs +1 -1
- package/dist/ui/inputs/color-input.mjs +1 -1
- package/dist/ui/inputs/index.cjs +11 -11
- package/dist/ui/inputs/index.mjs +3 -3
- package/dist/ui/inputs/input-numbers.cjs +1 -1
- package/dist/ui/inputs/input-numbers.mjs +1 -1
- package/dist/ui/inputs/input.cjs +1 -1
- package/dist/ui/inputs/input.d.cts +1 -1
- package/dist/ui/inputs/input.d.ts +1 -1
- package/dist/ui/inputs/input.mjs +1 -1
- package/dist/ui/inputs/number-inputs/CmInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/CmInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/DegInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/DegInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerDegInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerDegInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerRadInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/EulerRadInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/InchInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/InchInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/IntInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/IntInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/KVectorInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/KVectorInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/QuaternionInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/QuaternionInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/RadInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/RadInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/TimeInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/TimeInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/Vec3Input.cjs +1 -1
- package/dist/ui/inputs/number-inputs/Vec3Input.mjs +1 -1
- package/dist/ui/inputs/number-inputs/VectorInput.cjs +1 -1
- package/dist/ui/inputs/number-inputs/VectorInput.mjs +1 -1
- package/dist/ui/inputs/number-inputs/index.cjs +11 -11
- package/dist/ui/inputs/number-inputs/index.mjs +3 -3
- package/dist/ui/inputs/presets-input.cjs +1 -1
- package/dist/ui/inputs/presets-input.mjs +1 -1
- package/dist/ui/label.cjs +1 -1
- package/dist/ui/label.mjs +1 -1
- package/dist/ui/layout.cjs +1 -1
- package/dist/ui/layout.mjs +1 -1
- package/dist/ui/layouts/dock-layout/DockLayoutView.cjs +1 -1
- package/dist/ui/layouts/dock-layout/DockLayoutView.mjs +1 -1
- package/dist/ui/layouts/dock-layout/LayoutSlots.cjs +1 -1
- package/dist/ui/layouts/dock-layout/LayoutSlots.mjs +1 -1
- package/dist/ui/layouts/dock-layout/index.cjs +1 -1
- package/dist/ui/layouts/dock-layout/index.mjs +1 -1
- package/dist/ui/layouts/index.cjs +2 -2
- package/dist/ui/layouts/index.mjs +2 -2
- package/dist/ui/layouts/liquid-layout/LayoutSlots.cjs +1 -1
- package/dist/ui/layouts/liquid-layout/LayoutSlots.mjs +1 -1
- package/dist/ui/layouts/liquid-layout/LiquidLayoutView.cjs +1 -1
- package/dist/ui/layouts/liquid-layout/LiquidLayoutView.mjs +1 -1
- package/dist/ui/layouts/liquid-layout/index.cjs +1 -1
- package/dist/ui/layouts/liquid-layout/index.mjs +1 -1
- package/dist/ui/modal.cjs +1 -1
- package/dist/ui/modal.mjs +1 -1
- package/dist/ui/navigation.cjs +1 -1
- package/dist/ui/navigation.mjs +1 -1
- package/dist/ui/pagination.cjs +1 -1
- package/dist/ui/pagination.mjs +1 -1
- package/dist/ui/panel.cjs +1 -1
- package/dist/ui/panel.mjs +1 -1
- package/dist/ui/popover.cjs +1 -1
- package/dist/ui/popover.mjs +1 -1
- package/dist/ui/radio-group.cjs +1 -1
- package/dist/ui/radio-group.mjs +1 -1
- package/dist/ui/resizable.cjs +1 -1
- package/dist/ui/resizable.mjs +1 -1
- package/dist/ui/select.cjs +1 -1
- package/dist/ui/select.d.cts +1 -1
- package/dist/ui/select.d.ts +1 -1
- package/dist/ui/select.mjs +1 -1
- package/dist/ui/separator.cjs +1 -1
- package/dist/ui/separator.mjs +1 -1
- package/dist/ui/sheet.cjs +1 -1
- package/dist/ui/sheet.mjs +1 -1
- package/dist/ui/sidebar.cjs +26 -26
- package/dist/ui/sidebar.mjs +2 -2
- package/dist/ui/simple-tree-view.cjs +1 -1
- package/dist/ui/simple-tree-view.mjs +1 -1
- package/dist/ui/skeleton.cjs +1 -1
- package/dist/ui/skeleton.mjs +1 -1
- package/dist/ui/slider.cjs +1 -1
- package/dist/ui/slider.mjs +1 -1
- package/dist/ui/switch.cjs +1 -1
- package/dist/ui/switch.mjs +1 -1
- package/dist/ui/table.cjs +1 -1
- package/dist/ui/table.mjs +1 -1
- package/dist/ui/tabs.cjs +1 -1
- package/dist/ui/tabs.mjs +1 -1
- package/dist/ui/textarea.cjs +1 -1
- package/dist/ui/textarea.d.cts +1 -1
- package/dist/ui/textarea.d.ts +1 -1
- package/dist/ui/textarea.mjs +1 -1
- package/dist/ui/theme/ThemeToggles.cjs +1 -1
- package/dist/ui/theme/ThemeToggles.mjs +1 -1
- package/dist/ui/theme/index.cjs +1 -1
- package/dist/ui/theme/index.mjs +1 -1
- package/dist/ui/toggle-buttons.cjs +1 -1
- package/dist/ui/toggle-buttons.mjs +1 -1
- package/dist/ui/toggle-group.cjs +1 -1
- package/dist/ui/toggle-group.mjs +1 -1
- package/dist/ui/toggle.cjs +1 -1
- package/dist/ui/toggle.mjs +1 -1
- package/dist/ui/toolbar.cjs +1 -1
- package/dist/ui/toolbar.mjs +1 -1
- package/dist/ui/tooltip.cjs +1 -1
- package/dist/ui/tooltip.mjs +1 -1
- package/dist/ui/tree-view/TreeSearchBar.cjs +1 -1
- package/dist/ui/tree-view/TreeSearchBar.mjs +1 -1
- package/dist/ui/tree-view/TreeView.cjs +1 -1
- package/dist/ui/tree-view/TreeView.mjs +1 -1
- package/dist/ui/tree-view/index.cjs +6 -6
- package/dist/ui/tree-view/index.mjs +2 -2
- package/dist/ui/tree-view-legacy.cjs +9 -9
- package/dist/ui/tree-view-legacy.mjs +5 -5
- package/dist/ui/waterfall/CursorOverlay.cjs +1 -1
- package/dist/ui/waterfall/CursorOverlay.mjs +1 -1
- package/dist/ui/waterfall/TimelineEvent.cjs +1 -1
- package/dist/ui/waterfall/TimelineEvent.mjs +1 -1
- package/dist/ui/waterfall/TimelineProcessBar.cjs +1 -1
- package/dist/ui/waterfall/TimelineProcessBar.mjs +1 -1
- package/dist/ui/waterfall/Wedges.cjs +1 -1
- package/dist/ui/waterfall/Wedges.mjs +1 -1
- package/dist/ui/waterfall/index.cjs +8 -8
- package/dist/ui/waterfall/index.mjs +7 -7
- package/package.json +28 -2
- package/src/SyncScroll/README.md +283 -0
- package/src/SyncScroll/SyncScroll.tsx +361 -0
- package/src/SyncScroll/index.ts +22 -0
- package/src/SyncScroll/useSyncScroll.tsx +226 -0
- package/src/cli/dial-cli.ts +1133 -0
- package/src/dial/DialPanel.tsx +208 -0
- package/src/dial/DialProvider.example.tsx +80 -0
- package/src/dial/DialProvider.tsx +138 -0
- package/src/dial/index.ts +26 -0
- package/src/dial/wrapped-inputs/ControlledInputs.tsx +176 -0
- package/src/dial/wrapped-inputs/DialInputs.tsx +401 -0
- package/src/dial/wrapped-inputs/DialVectorInput.tsx +125 -0
- package/src/dial/wrapped-inputs/index.ts +25 -0
- package/src/highlight-cursor/cursor-context.tsx +23 -0
- package/src/highlight-cursor/cursor-provider.tsx +264 -0
- package/src/highlight-cursor/enhanced-components.tsx +16 -0
- package/src/highlight-cursor/index.ts +21 -0
- package/src/highlight-cursor/tabs-cursor-context.tsx +121 -0
- package/src/highlight-cursor/types.ts +40 -0
- package/src/highlight-cursor/with-cursor.tsx +144 -0
- package/src/hooks/clientOnly.tsx +54 -0
- package/src/hooks/cn.ts +33 -0
- package/src/hooks/index.ts +9 -0
- package/src/hooks/useDocument.tsx +18 -0
- package/src/hooks/useDragSelect.ts +116 -0
- package/src/hooks/useIsMobile.ts +35 -0
- package/src/hooks/useLocalStorage.ts +122 -0
- package/src/hooks/useLocation.tsx +95 -0
- package/src/hooks/useQueryParams.tsx +31 -0
- package/src/hooks/useWindow.tsx +18 -0
- package/src/index.css +5 -0
- package/src/index.ts +5 -0
- package/src/styles/.editorconfig +0 -0
- package/src/styles/theme.css +152 -0
- package/src/styles/toast.css +67 -0
- package/src/styles/variables.css +229 -0
- package/src/ui/UIKitBadge.tsx +171 -0
- package/src/ui/avatar.tsx +221 -0
- package/src/ui/badge.tsx +74 -0
- package/src/ui/button.tsx +143 -0
- package/src/ui/card.tsx +146 -0
- package/src/ui/checkbox.tsx +78 -0
- package/src/ui/collapsible.tsx +43 -0
- package/src/ui/drag-selectable/DragSelectProvider.tsx +178 -0
- package/src/ui/drag-selectable/createSelectable.tsx +43 -0
- package/src/ui/drag-selectable/index.ts +2 -0
- package/src/ui/drawer.tsx +137 -0
- package/src/ui/dropdown.tsx +707 -0
- package/src/ui/icons/MouseCursorIcons.tsx +39 -0
- package/src/ui/icons/cursor.tsx +38 -0
- package/src/ui/icons/index.ts +2 -0
- package/src/ui/index.ts +45 -0
- package/src/ui/inputs/color-input.tsx +61 -0
- package/src/ui/inputs/index.tsx +5 -0
- package/src/ui/inputs/input-numbers.tsx +394 -0
- package/src/ui/inputs/input.tsx +155 -0
- package/src/ui/inputs/number-inputs/CmInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/DegInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/EulerDegInput.tsx +14 -0
- package/src/ui/inputs/number-inputs/EulerInput.tsx +30 -0
- package/src/ui/inputs/number-inputs/EulerRadInput.tsx +14 -0
- package/src/ui/inputs/number-inputs/InchInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/IntInput.tsx +46 -0
- package/src/ui/inputs/number-inputs/KVectorInput.tsx +20 -0
- package/src/ui/inputs/number-inputs/QuaternionInput.tsx +27 -0
- package/src/ui/inputs/number-inputs/RadInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/TimeInput.tsx +26 -0
- package/src/ui/inputs/number-inputs/Vec3Input.tsx +26 -0
- package/src/ui/inputs/number-inputs/VectorInput.tsx +38 -0
- package/src/ui/inputs/number-inputs/index.ts +38 -0
- package/src/ui/inputs/presets-input.tsx +59 -0
- package/src/ui/label.tsx +35 -0
- package/src/ui/layout.tsx +43 -0
- package/src/ui/layouts/dock-layout/DockLayoutView.tsx +128 -0
- package/src/ui/layouts/dock-layout/LayoutSlots.tsx +85 -0
- package/src/ui/layouts/dock-layout/index.tsx +2 -0
- package/src/ui/layouts/index.ts +2 -0
- package/src/ui/layouts/liquid-layout/LayoutSlots.tsx +82 -0
- package/src/ui/layouts/liquid-layout/LiquidLayoutView.tsx +76 -0
- package/src/ui/layouts/liquid-layout/index.ts +1 -0
- package/src/ui/modal.tsx +211 -0
- package/src/ui/navigation.tsx +86 -0
- package/src/ui/pagination.tsx +129 -0
- package/src/ui/panel.tsx +146 -0
- package/src/ui/popover.tsx +112 -0
- package/src/ui/radio-group.tsx +63 -0
- package/src/ui/resizable.tsx +52 -0
- package/src/ui/select.tsx +365 -0
- package/src/ui/separator.tsx +26 -0
- package/src/ui/sheet.tsx +257 -0
- package/src/ui/sidebar.tsx +695 -0
- package/src/ui/simple-tree-view.tsx +604 -0
- package/src/ui/skeleton.tsx +15 -0
- package/src/ui/slider.tsx +204 -0
- package/src/ui/switch.tsx +45 -0
- package/src/ui/table.tsx +99 -0
- package/src/ui/tabs.tsx +192 -0
- package/src/ui/textarea.tsx +55 -0
- package/src/ui/theme/ThemeProvider.tsx +319 -0
- package/src/ui/theme/ThemeToggles.tsx +84 -0
- package/src/ui/theme/index.ts +21 -0
- package/src/ui/theme/themeScript.tsx +179 -0
- package/src/ui/theme/types.ts +61 -0
- package/src/ui/toast.tsx +30 -0
- package/src/ui/toggle-buttons.tsx +290 -0
- package/src/ui/toggle-group.tsx +236 -0
- package/src/ui/toggle.tsx +94 -0
- package/src/ui/toolbar.tsx +54 -0
- package/src/ui/tooltip.tsx +171 -0
- package/src/ui/tree-view/TreeSearchBar.tsx +88 -0
- package/src/ui/tree-view/TreeView.tsx +232 -0
- package/src/ui/tree-view/hooks.tsx +289 -0
- package/src/ui/tree-view/index.ts +4 -0
- package/src/ui/tree-view/types.ts +23 -0
- package/src/ui/tree-view-legacy.tsx +644 -0
- package/src/ui/version-badge.tsx +0 -0
- package/src/ui/waterfall/CursorOverlay.tsx +96 -0
- package/src/ui/waterfall/NavigationControls.tsx +42 -0
- package/src/ui/waterfall/Tick.tsx +51 -0
- package/src/ui/waterfall/TimeRuleEventDot.tsx +19 -0
- package/src/ui/waterfall/TimelineEvent.tsx +60 -0
- package/src/ui/waterfall/TimelineProcessBar.tsx +207 -0
- package/src/ui/waterfall/Wedges.tsx +67 -0
- package/src/ui/waterfall/WheelZoomContext.tsx +128 -0
- package/src/ui/waterfall/hooks/useTimelineState.tsx +134 -0
- package/src/ui/waterfall/hooks/useViewport.tsx +293 -0
- package/src/ui/waterfall/index.tsx +326 -0
- package/src/ui/waterfall/types.ts +20 -0
- package/src/ui/waterfall/utils.ts +91 -0
- package/dist/chunk-W2YAQV5N.mjs +0 -57
- package/dist/{chunk-QLCEHV4Q.mjs → chunk-2OZK5DY5.mjs} +2 -2
- package/dist/{chunk-Z35DNFRZ.cjs → chunk-7IS37C3P.cjs} +2 -2
- package/dist/{chunk-4AOAH77D.mjs → chunk-A2PCEL5S.mjs} +2 -2
- package/dist/{chunk-K4VD5PPY.mjs → chunk-BIUDC66P.mjs} +1 -1
- package/dist/{chunk-RKJR6RZU.cjs → chunk-OYNLQTHW.cjs} +1 -1
- package/dist/{chunk-VE3XLQLO.cjs → chunk-QUFZWF4E.cjs} +2 -2
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
import { useState, useMemo } from "react";
|
|
2
|
+
|
|
3
|
+
import { LogItemType, LogItemWithMeta } from "../types";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Custom hook for managing timeline waterfall state including item expansion, hover interactions, and hierarchical data processing.
|
|
7
|
+
*
|
|
8
|
+
* This hook processes log data into a hierarchical structure with parent-child relationships, manages which items
|
|
9
|
+
* are expanded/collapsed, tracks hover states for visual feedback, and provides utilities for filtering visible items.
|
|
10
|
+
*
|
|
11
|
+
* @param logData - Array of log items representing timeline events. Each item can have:
|
|
12
|
+
* - Basic properties: id, parentId, label, type, color, icon
|
|
13
|
+
* - Timing data: time, createTime, startTime, duration
|
|
14
|
+
* - Hierarchy: parentId (null for root items), isCollapsible flag
|
|
15
|
+
* - Display: indent level for visual nesting
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```typescript
|
|
19
|
+
* const logData = [
|
|
20
|
+
* {
|
|
21
|
+
* id: "1",
|
|
22
|
+
* parentId: null,
|
|
23
|
+
* type: "task",
|
|
24
|
+
* label: "generate-report",
|
|
25
|
+
* startTime: 0,
|
|
26
|
+
* duration: 20,
|
|
27
|
+
* isCollapsible: true
|
|
28
|
+
* },
|
|
29
|
+
* {
|
|
30
|
+
* id: "2",
|
|
31
|
+
* parentId: "1",
|
|
32
|
+
* type: "step",
|
|
33
|
+
* label: "Fetch database records",
|
|
34
|
+
* startTime: 0.5,
|
|
35
|
+
* duration: 3
|
|
36
|
+
* }
|
|
37
|
+
* ];
|
|
38
|
+
*
|
|
39
|
+
* const {
|
|
40
|
+
* expandedItems, // Set of expanded item IDs
|
|
41
|
+
* hoveredId, // Currently hovered item ID
|
|
42
|
+
* toggleItem, // Function to expand/collapse items
|
|
43
|
+
* logDataWithMeta, // Enhanced data with ancestry info
|
|
44
|
+
* getVisibleLogData // Filter function for visible items
|
|
45
|
+
* } = useTimelineState(logData);
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @returns Object containing:
|
|
49
|
+
* - expandedItems: Set of item IDs that are currently expanded
|
|
50
|
+
* - hoveredId: ID of currently hovered item (null if none)
|
|
51
|
+
* - setHoveredId: Function to update hovered item
|
|
52
|
+
* - toggleItem: Function to expand/collapse collapsible items
|
|
53
|
+
* - logDataWithMeta: Enhanced log data with ancestor chain and position metadata
|
|
54
|
+
* - getVisibleLogData: Function that filters data based on parent expansion state
|
|
55
|
+
*/
|
|
56
|
+
export function useTimelineState(logData: LogItemType[]) {
|
|
57
|
+
const [expandedItems, setExpandedItems] = useState(() => {
|
|
58
|
+
const initial = new Set<string>();
|
|
59
|
+
logData.forEach((item) => {
|
|
60
|
+
if (item.isCollapsible) initial.add(item.id);
|
|
61
|
+
});
|
|
62
|
+
return initial;
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const [hoveredId, setHoveredId] = useState<string | null>(null);
|
|
66
|
+
|
|
67
|
+
const toggleItem = (id: string) => {
|
|
68
|
+
setExpandedItems((prev) => {
|
|
69
|
+
const newSet = new Set(prev);
|
|
70
|
+
if (newSet.has(id)) {
|
|
71
|
+
newSet.delete(id);
|
|
72
|
+
} else {
|
|
73
|
+
newSet.add(id);
|
|
74
|
+
}
|
|
75
|
+
return newSet;
|
|
76
|
+
});
|
|
77
|
+
};
|
|
78
|
+
|
|
79
|
+
const childrenMap = useMemo(() => {
|
|
80
|
+
const map = new Map<string | null, LogItemType[]>();
|
|
81
|
+
logData.forEach((item) => {
|
|
82
|
+
if (!map.has(item.parentId)) {
|
|
83
|
+
map.set(item.parentId, []);
|
|
84
|
+
}
|
|
85
|
+
map.get(item.parentId)!.push(item);
|
|
86
|
+
});
|
|
87
|
+
return map;
|
|
88
|
+
}, [logData]);
|
|
89
|
+
|
|
90
|
+
const logDataWithMeta = useMemo(() => {
|
|
91
|
+
const dataMap = new Map(logData.map((item) => [item.id, item]));
|
|
92
|
+
|
|
93
|
+
const getAncestors = (item: LogItemType) => {
|
|
94
|
+
const ancestors: LogItemType[] = [];
|
|
95
|
+
let current = item.parentId;
|
|
96
|
+
while (current) {
|
|
97
|
+
const parent = dataMap.get(current);
|
|
98
|
+
if (parent) {
|
|
99
|
+
ancestors.unshift(parent);
|
|
100
|
+
current = parent.parentId;
|
|
101
|
+
} else {
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
return ancestors;
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
return logData.map((item) => {
|
|
109
|
+
const siblings = childrenMap.get(item.parentId) || [];
|
|
110
|
+
const isLast = siblings.length > 0 && siblings[siblings.length - 1].id === item.id;
|
|
111
|
+
const ancestors = getAncestors(item);
|
|
112
|
+
return { ...item, isLast, ancestors };
|
|
113
|
+
});
|
|
114
|
+
}, [childrenMap, logData]);
|
|
115
|
+
|
|
116
|
+
const isVisible = (item: { ancestors: LogItemType[] }) => {
|
|
117
|
+
return item.ancestors.every(
|
|
118
|
+
(ancestor) => !ancestor.isCollapsible || expandedItems.has(ancestor.id),
|
|
119
|
+
);
|
|
120
|
+
};
|
|
121
|
+
|
|
122
|
+
const getVisibleLogData = (filteredData: LogItemWithMeta[]) => {
|
|
123
|
+
return filteredData.filter(isVisible);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
return {
|
|
127
|
+
expandedItems,
|
|
128
|
+
hoveredId,
|
|
129
|
+
setHoveredId,
|
|
130
|
+
toggleItem,
|
|
131
|
+
logDataWithMeta,
|
|
132
|
+
getVisibleLogData,
|
|
133
|
+
};
|
|
134
|
+
}
|
|
@@ -0,0 +1,293 @@
|
|
|
1
|
+
import { useState, useMemo, useRef, useCallback, useEffect } from "react";
|
|
2
|
+
|
|
3
|
+
import { LogItemWithMeta } from "../types";
|
|
4
|
+
import { formatDuration, TOTAL_DURATION } from "../utils";
|
|
5
|
+
|
|
6
|
+
interface UseViewportProps {
|
|
7
|
+
visibleLogData: LogItemWithMeta[];
|
|
8
|
+
onTemporalCursorChange?: (time: number) => void;
|
|
9
|
+
temporalCursor?: number;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function useViewport({
|
|
13
|
+
visibleLogData,
|
|
14
|
+
onTemporalCursorChange,
|
|
15
|
+
temporalCursor,
|
|
16
|
+
}: UseViewportProps) {
|
|
17
|
+
const [viewStart, setViewStart] = useState(-TOTAL_DURATION * 0.25);
|
|
18
|
+
const [viewDuration, setViewDuration] = useState(TOTAL_DURATION * 1.5);
|
|
19
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
20
|
+
const [internalTemporalCursor, setInternalTemporalCursor] = useState<number | null>(null);
|
|
21
|
+
|
|
22
|
+
const timelineContainerRef = useRef<HTMLDivElement>(null);
|
|
23
|
+
const lastClientX = useRef(0);
|
|
24
|
+
const isMouseOver = useRef(false);
|
|
25
|
+
const animationFrameRef = useRef<number | null>(null);
|
|
26
|
+
|
|
27
|
+
// Cursor state
|
|
28
|
+
const [cursorVisible, setCursorVisible] = useState(false);
|
|
29
|
+
const [cursorPosition, setCursorPosition] = useState(0);
|
|
30
|
+
const [cursorLabel, setCursorLabel] = useState("");
|
|
31
|
+
const [showMagnet, setShowMagnet] = useState(false);
|
|
32
|
+
|
|
33
|
+
const activeTemporalCursor = temporalCursor ?? internalTemporalCursor;
|
|
34
|
+
|
|
35
|
+
const timeToPercent = useCallback(
|
|
36
|
+
(time: number) => ((time - viewStart) / viewDuration) * 100,
|
|
37
|
+
[viewStart, viewDuration],
|
|
38
|
+
);
|
|
39
|
+
|
|
40
|
+
const ticks = useMemo(() => {
|
|
41
|
+
const markers: { time: number; label: string }[] = [];
|
|
42
|
+
const niceIntervals = [
|
|
43
|
+
0.001, 0.002, 0.005, 0.01, 0.02, 0.05, 0.1, 0.2, 0.5, 1, 2, 5, 10, 20, 50, 100,
|
|
44
|
+
];
|
|
45
|
+
const targetMarkerCount = 10;
|
|
46
|
+
const rawInterval = viewDuration / targetMarkerCount;
|
|
47
|
+
const interval =
|
|
48
|
+
niceIntervals.find((i) => i > rawInterval) || niceIntervals[niceIntervals.length - 1];
|
|
49
|
+
|
|
50
|
+
const viewEnd = viewStart + viewDuration;
|
|
51
|
+
const shownSeconds = new Set<number>();
|
|
52
|
+
|
|
53
|
+
const formatTickLabel = (seconds: number) => {
|
|
54
|
+
const sign = seconds < 0 ? "-" : "";
|
|
55
|
+
const absSeconds = Math.abs(seconds);
|
|
56
|
+
|
|
57
|
+
let s = Math.floor(absSeconds);
|
|
58
|
+
let ms = Math.round((absSeconds - s) * 1000);
|
|
59
|
+
|
|
60
|
+
if (ms >= 1000) {
|
|
61
|
+
s += 1;
|
|
62
|
+
ms -= 1000;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (absSeconds < 1 && absSeconds > -1) {
|
|
66
|
+
return `${sign}${ms}ms`;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
const baseSecond = s * (sign === "-" ? -1 : 1);
|
|
70
|
+
if (shownSeconds.has(baseSecond)) {
|
|
71
|
+
return ms > 0 ? `+${ms}ms` : "";
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
shownSeconds.add(baseSecond);
|
|
75
|
+
if (ms === 0) {
|
|
76
|
+
return `${sign}${s}s`;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
return `${sign}${s}s`;
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
const firstMarkerTime = Math.floor(viewStart / interval) * interval;
|
|
83
|
+
const lastMarkerTime = Math.ceil(viewEnd / interval) * interval;
|
|
84
|
+
|
|
85
|
+
for (let time = firstMarkerTime; time <= lastMarkerTime; time += interval) {
|
|
86
|
+
const roundedTime = Number.parseFloat(time.toPrecision(15));
|
|
87
|
+
const label = formatTickLabel(roundedTime);
|
|
88
|
+
if (label) {
|
|
89
|
+
markers.push({ time: roundedTime, label });
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
return markers;
|
|
93
|
+
}, [viewStart, viewDuration]);
|
|
94
|
+
|
|
95
|
+
const eventDots = useMemo(() => {
|
|
96
|
+
const events: { time: number; type: string }[] = [];
|
|
97
|
+
const timeSet = new Set<string>();
|
|
98
|
+
|
|
99
|
+
const addEvent = (time: number, type: string) => {
|
|
100
|
+
const key = `${time.toFixed(6)}-${type}`;
|
|
101
|
+
if (!timeSet.has(key)) {
|
|
102
|
+
events.push({ time, type });
|
|
103
|
+
timeSet.add(key);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
visibleLogData.forEach((item) => {
|
|
108
|
+
if (item.createTime !== undefined) addEvent(item.createTime, "create");
|
|
109
|
+
if (item.startTime !== undefined) addEvent(item.startTime, "start");
|
|
110
|
+
if (item.startTime !== undefined && item.duration !== undefined) {
|
|
111
|
+
addEvent(item.startTime + item.duration, "end");
|
|
112
|
+
}
|
|
113
|
+
if (item.time !== undefined) addEvent(item.time, "event");
|
|
114
|
+
});
|
|
115
|
+
return events.sort((a, b) => a.time - b.time);
|
|
116
|
+
}, [visibleLogData]);
|
|
117
|
+
|
|
118
|
+
const updateCursor = useCallback(() => {
|
|
119
|
+
if (!isMouseOver.current) return;
|
|
120
|
+
|
|
121
|
+
const timelineEl = timelineContainerRef.current;
|
|
122
|
+
if (!timelineEl) return;
|
|
123
|
+
|
|
124
|
+
const rect = timelineEl.getBoundingClientRect();
|
|
125
|
+
const cursorX = lastClientX.current - rect.left;
|
|
126
|
+
const rawHoverTime = viewStart + (cursorX / timelineEl.offsetWidth) * viewDuration;
|
|
127
|
+
|
|
128
|
+
// Snapping logic
|
|
129
|
+
const snapThresholdInPixels = 8;
|
|
130
|
+
const snapThresholdInTime = (snapThresholdInPixels / timelineEl.offsetWidth) * viewDuration;
|
|
131
|
+
|
|
132
|
+
let closestSnap: { time: number; type: string } | null = null;
|
|
133
|
+
let minDistance = Number.POSITIVE_INFINITY;
|
|
134
|
+
|
|
135
|
+
for (const event of eventDots) {
|
|
136
|
+
const distance = Math.abs(event.time - rawHoverTime);
|
|
137
|
+
if (distance < minDistance && distance < snapThresholdInTime) {
|
|
138
|
+
minDistance = distance;
|
|
139
|
+
closestSnap = event;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const displayTime = closestSnap?.time ?? rawHoverTime;
|
|
144
|
+
const percent = timeToPercent(displayTime);
|
|
145
|
+
|
|
146
|
+
setCursorPosition(percent);
|
|
147
|
+
setCursorLabel(formatDuration(displayTime));
|
|
148
|
+
setShowMagnet(!!closestSnap);
|
|
149
|
+
setCursorVisible(true);
|
|
150
|
+
}, [viewStart, viewDuration, eventDots, timeToPercent]);
|
|
151
|
+
|
|
152
|
+
const handlePan = (direction: "left" | "right") => {
|
|
153
|
+
const panAmount = viewDuration * 0.1;
|
|
154
|
+
if (direction === "left") {
|
|
155
|
+
setViewStart((s) => s - panAmount);
|
|
156
|
+
} else {
|
|
157
|
+
setViewStart((s) => s + panAmount);
|
|
158
|
+
}
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const handleZoomDragStart = (e: React.MouseEvent) => {
|
|
162
|
+
e.preventDefault();
|
|
163
|
+
e.stopPropagation();
|
|
164
|
+
|
|
165
|
+
const startX = e.clientX;
|
|
166
|
+
const startDuration = viewDuration;
|
|
167
|
+
const centerTime = viewStart + viewDuration / 2;
|
|
168
|
+
let isDraggingLocal = true;
|
|
169
|
+
|
|
170
|
+
setIsDragging(true);
|
|
171
|
+
|
|
172
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
173
|
+
if (!isDraggingLocal) return;
|
|
174
|
+
|
|
175
|
+
const deltaX = e.clientX - startX;
|
|
176
|
+
const sensitivity = 0.05;
|
|
177
|
+
const zoomFactor = Math.pow(1.1, deltaX * sensitivity);
|
|
178
|
+
const newDuration = startDuration * zoomFactor;
|
|
179
|
+
|
|
180
|
+
const minDuration = 0.01;
|
|
181
|
+
const maxDuration = TOTAL_DURATION * 10;
|
|
182
|
+
|
|
183
|
+
if (newDuration >= minDuration && newDuration <= maxDuration) {
|
|
184
|
+
const newViewStart = centerTime - newDuration / 2;
|
|
185
|
+
setViewDuration(newDuration);
|
|
186
|
+
setViewStart(newViewStart);
|
|
187
|
+
}
|
|
188
|
+
};
|
|
189
|
+
|
|
190
|
+
const handleMouseUp = () => {
|
|
191
|
+
isDraggingLocal = false;
|
|
192
|
+
setIsDragging(false);
|
|
193
|
+
document.removeEventListener("mousemove", handleMouseMove);
|
|
194
|
+
document.removeEventListener("mouseup", handleMouseUp);
|
|
195
|
+
};
|
|
196
|
+
|
|
197
|
+
document.addEventListener("mousemove", handleMouseMove);
|
|
198
|
+
document.addEventListener("mouseup", handleMouseUp);
|
|
199
|
+
};
|
|
200
|
+
|
|
201
|
+
const handleTimelineClick = (e: React.MouseEvent) => {
|
|
202
|
+
const container = timelineContainerRef.current;
|
|
203
|
+
if (!container) return;
|
|
204
|
+
|
|
205
|
+
const rect = container.getBoundingClientRect();
|
|
206
|
+
const clickX = e.clientX - rect.left;
|
|
207
|
+
const clickedTime = viewStart + (clickX / container.offsetWidth) * viewDuration;
|
|
208
|
+
|
|
209
|
+
// Snap to nearest key event if close enough
|
|
210
|
+
const snapThresholdInPixels = 8;
|
|
211
|
+
const snapThresholdInTime = (snapThresholdInPixels / container.offsetWidth) * viewDuration;
|
|
212
|
+
|
|
213
|
+
let closestSnap: { time: number; type: string } | null = null;
|
|
214
|
+
let minDistance = Number.POSITIVE_INFINITY;
|
|
215
|
+
|
|
216
|
+
for (const event of eventDots) {
|
|
217
|
+
const distance = Math.abs(event.time - clickedTime);
|
|
218
|
+
if (distance < minDistance && distance < snapThresholdInTime) {
|
|
219
|
+
minDistance = distance;
|
|
220
|
+
closestSnap = event;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
const finalTime = closestSnap?.time ?? clickedTime;
|
|
225
|
+
|
|
226
|
+
if (onTemporalCursorChange) {
|
|
227
|
+
onTemporalCursorChange(finalTime);
|
|
228
|
+
} else {
|
|
229
|
+
setInternalTemporalCursor(finalTime);
|
|
230
|
+
}
|
|
231
|
+
};
|
|
232
|
+
|
|
233
|
+
useEffect(() => {
|
|
234
|
+
const timelineEl = timelineContainerRef.current;
|
|
235
|
+
if (!timelineEl) return;
|
|
236
|
+
|
|
237
|
+
const handleMouseMove = (e: MouseEvent) => {
|
|
238
|
+
if (isDragging) return;
|
|
239
|
+
|
|
240
|
+
lastClientX.current = e.clientX;
|
|
241
|
+
if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
|
|
242
|
+
animationFrameRef.current = requestAnimationFrame(updateCursor);
|
|
243
|
+
};
|
|
244
|
+
|
|
245
|
+
const handleMouseEnter = () => {
|
|
246
|
+
isMouseOver.current = true;
|
|
247
|
+
};
|
|
248
|
+
|
|
249
|
+
const handleMouseLeave = () => {
|
|
250
|
+
isMouseOver.current = false;
|
|
251
|
+
if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
|
|
252
|
+
setCursorVisible(false);
|
|
253
|
+
};
|
|
254
|
+
|
|
255
|
+
timelineEl.addEventListener("mousemove", handleMouseMove);
|
|
256
|
+
timelineEl.addEventListener("mouseenter", handleMouseEnter);
|
|
257
|
+
timelineEl.addEventListener("mouseleave", handleMouseLeave);
|
|
258
|
+
|
|
259
|
+
return () => {
|
|
260
|
+
timelineEl.removeEventListener("mousemove", handleMouseMove);
|
|
261
|
+
timelineEl.removeEventListener("mouseenter", handleMouseEnter);
|
|
262
|
+
timelineEl.removeEventListener("mouseleave", handleMouseLeave);
|
|
263
|
+
if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
|
|
264
|
+
};
|
|
265
|
+
}, [updateCursor, isDragging]);
|
|
266
|
+
|
|
267
|
+
useEffect(() => {
|
|
268
|
+
if (isMouseOver.current) {
|
|
269
|
+
if (animationFrameRef.current) cancelAnimationFrame(animationFrameRef.current);
|
|
270
|
+
animationFrameRef.current = requestAnimationFrame(updateCursor);
|
|
271
|
+
}
|
|
272
|
+
}, [viewStart, viewDuration, updateCursor]);
|
|
273
|
+
|
|
274
|
+
return {
|
|
275
|
+
viewStart,
|
|
276
|
+
viewDuration,
|
|
277
|
+
timelineContainerRef,
|
|
278
|
+
activeTemporalCursor,
|
|
279
|
+
timeToPercent,
|
|
280
|
+
ticks,
|
|
281
|
+
eventDots,
|
|
282
|
+
handlePan,
|
|
283
|
+
handleZoomDragStart,
|
|
284
|
+
handleTimelineClick,
|
|
285
|
+
setViewStart,
|
|
286
|
+
setViewDuration,
|
|
287
|
+
// Cursor state
|
|
288
|
+
cursorVisible,
|
|
289
|
+
cursorPosition,
|
|
290
|
+
cursorLabel,
|
|
291
|
+
showMagnet,
|
|
292
|
+
};
|
|
293
|
+
}
|