@topconsultnpm/sdkui-react 6.20.0-dev1.111 → 6.20.0-dev1.112
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/lib/components/NewComponents/FloatingMenuBar/TMFloatingMenuBar.js +76 -3
- package/lib/components/NewComponents/FloatingMenuBar/styles.d.ts +4 -0
- package/lib/components/NewComponents/FloatingMenuBar/styles.js +2 -1
- package/lib/components/NewComponents/FloatingMenuBar/types.d.ts +1 -0
- package/package.json +1 -1
|
@@ -131,6 +131,7 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
131
131
|
isDragging: false,
|
|
132
132
|
isConfigMode: false,
|
|
133
133
|
orientation: initialConfig.orientation,
|
|
134
|
+
verticalDirection: 'down',
|
|
134
135
|
items: [],
|
|
135
136
|
draggedItemIndex: null,
|
|
136
137
|
});
|
|
@@ -138,8 +139,10 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
138
139
|
const dragOffset = useRef({ x: 0, y: 0 });
|
|
139
140
|
const [dragOverIndex, setDragOverIndex] = useState(null);
|
|
140
141
|
const [pixelPosition, setPixelPosition] = useState({ x: 0, y: 0 }); // Calculated pixel position
|
|
142
|
+
const [isOrientationChanging, setIsOrientationChanging] = useState(false); // Hide bar during orientation transition
|
|
141
143
|
const containerSizeRef = useRef({ width: 0, height: 0 });
|
|
142
144
|
const stateSnapshot = useRef(null);
|
|
145
|
+
const positionBeforeOrientationChange = useRef(null);
|
|
143
146
|
const floatingBarItemIds = useRef(new Set());
|
|
144
147
|
const floatingBarItemNames = useRef(new Set());
|
|
145
148
|
useEffect(() => {
|
|
@@ -549,6 +552,7 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
549
552
|
stateSnapshot.current = {
|
|
550
553
|
items: [...s.items],
|
|
551
554
|
orientation: s.orientation,
|
|
555
|
+
verticalDirection: s.verticalDirection,
|
|
552
556
|
position: { ...s.position },
|
|
553
557
|
};
|
|
554
558
|
return { ...s, isConfigMode: true };
|
|
@@ -617,6 +621,7 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
617
621
|
...s,
|
|
618
622
|
items: [...stateSnapshot.current.items],
|
|
619
623
|
orientation: stateSnapshot.current.orientation,
|
|
624
|
+
verticalDirection: stateSnapshot.current.verticalDirection,
|
|
620
625
|
position: { ...stateSnapshot.current.position },
|
|
621
626
|
isConfigMode: true,
|
|
622
627
|
}));
|
|
@@ -638,6 +643,7 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
638
643
|
...s,
|
|
639
644
|
items: [...stateSnapshot.current.items],
|
|
640
645
|
orientation: stateSnapshot.current.orientation,
|
|
646
|
+
verticalDirection: stateSnapshot.current.verticalDirection,
|
|
641
647
|
position: { ...stateSnapshot.current.position },
|
|
642
648
|
isConfigMode: false,
|
|
643
649
|
}));
|
|
@@ -662,6 +668,7 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
662
668
|
...s,
|
|
663
669
|
items: [...stateSnapshot.current.items],
|
|
664
670
|
orientation: stateSnapshot.current.orientation,
|
|
671
|
+
verticalDirection: stateSnapshot.current.verticalDirection,
|
|
665
672
|
position: { ...stateSnapshot.current.position },
|
|
666
673
|
isConfigMode: false,
|
|
667
674
|
}));
|
|
@@ -672,24 +679,89 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
672
679
|
};
|
|
673
680
|
const toggleOrientation = () => {
|
|
674
681
|
const newOrientation = state.orientation === 'horizontal' ? 'vertical' : 'horizontal';
|
|
682
|
+
// Hide the bar during transition to prevent flicker
|
|
683
|
+
setIsOrientationChanging(true);
|
|
684
|
+
// When switching from vertical back to horizontal, restore the original position
|
|
685
|
+
if (state.orientation === 'vertical' && newOrientation === 'horizontal') {
|
|
686
|
+
if (positionBeforeOrientationChange.current) {
|
|
687
|
+
const savedPosition = positionBeforeOrientationChange.current.position;
|
|
688
|
+
const savedPixelPosition = positionBeforeOrientationChange.current.pixelPosition;
|
|
689
|
+
setPixelPosition(savedPixelPosition);
|
|
690
|
+
setState(s => ({
|
|
691
|
+
...s,
|
|
692
|
+
orientation: newOrientation,
|
|
693
|
+
verticalDirection: 'down',
|
|
694
|
+
position: savedPosition,
|
|
695
|
+
}));
|
|
696
|
+
positionBeforeOrientationChange.current = null;
|
|
697
|
+
// Show the bar after the state has been applied
|
|
698
|
+
requestAnimationFrame(() => {
|
|
699
|
+
setIsOrientationChanging(false);
|
|
700
|
+
});
|
|
701
|
+
return;
|
|
702
|
+
}
|
|
703
|
+
}
|
|
704
|
+
// When switching to vertical, save current position and check if we need to expand upward
|
|
675
705
|
if (state.orientation === 'horizontal' && newOrientation === 'vertical') {
|
|
706
|
+
// Save the current position before changing orientation
|
|
707
|
+
positionBeforeOrientationChange.current = {
|
|
708
|
+
position: { ...state.position },
|
|
709
|
+
pixelPosition: { ...pixelPosition },
|
|
710
|
+
};
|
|
676
711
|
if (floatingRef.current) {
|
|
677
712
|
const floating = floatingRef.current.getBoundingClientRect();
|
|
678
|
-
const
|
|
679
|
-
|
|
713
|
+
const containerHeight = isConstrained && containerRef.current
|
|
714
|
+
? containerRef.current.getBoundingClientRect().height
|
|
715
|
+
: window.innerHeight;
|
|
716
|
+
// Estimate vertical height (horizontal width becomes vertical height)
|
|
717
|
+
const estimatedVerticalHeight = floating.width;
|
|
718
|
+
if (estimatedVerticalHeight > containerHeight - 70) {
|
|
680
719
|
ShowAlert({
|
|
681
720
|
mode: 'warning',
|
|
682
721
|
title: 'Troppi elementi',
|
|
683
722
|
message: 'Ci sono troppi elementi nella barra mobile per la modalità verticale.',
|
|
684
723
|
duration: 4000,
|
|
685
724
|
});
|
|
725
|
+
positionBeforeOrientationChange.current = null; // Clear saved position since we're not changing
|
|
726
|
+
setIsOrientationChanging(false); // Show bar again since we're not changing
|
|
727
|
+
return;
|
|
728
|
+
}
|
|
729
|
+
// Check if we're in the bottom part of the screen and don't have enough space below
|
|
730
|
+
const spaceBelow = containerHeight - floating.bottom;
|
|
731
|
+
const spaceAbove = floating.top;
|
|
732
|
+
const needsVerticalSpace = estimatedVerticalHeight - floating.height; // Additional space needed
|
|
733
|
+
// If not enough space below but enough space above, expand upward
|
|
734
|
+
if (spaceBelow < needsVerticalSpace && spaceAbove >= needsVerticalSpace) {
|
|
735
|
+
// Calculate the new Y position so the bottom of the bar stays at the same place
|
|
736
|
+
const currentBottom = pixelPosition.y + floating.height;
|
|
737
|
+
const newPixelY = currentBottom - estimatedVerticalHeight;
|
|
738
|
+
setState(s => ({
|
|
739
|
+
...s,
|
|
740
|
+
orientation: newOrientation,
|
|
741
|
+
verticalDirection: 'up',
|
|
742
|
+
}));
|
|
743
|
+
// Update pixel position and percentage after orientation change
|
|
744
|
+
requestAnimationFrame(() => {
|
|
745
|
+
requestAnimationFrame(() => {
|
|
746
|
+
const newY = Math.max(0, newPixelY);
|
|
747
|
+
setPixelPosition(prev => ({ ...prev, y: newY }));
|
|
748
|
+
const newPercentY = pixelsToPercent(newY, containerHeight);
|
|
749
|
+
setState(s => ({
|
|
750
|
+
...s,
|
|
751
|
+
position: { ...s.position, y: newPercentY },
|
|
752
|
+
}));
|
|
753
|
+
setIsOrientationChanging(false); // Show bar after position is set
|
|
754
|
+
});
|
|
755
|
+
});
|
|
686
756
|
return;
|
|
687
757
|
}
|
|
688
758
|
}
|
|
689
759
|
}
|
|
760
|
+
// Default case: just change orientation without special positioning
|
|
690
761
|
setState(s => ({
|
|
691
762
|
...s,
|
|
692
763
|
orientation: newOrientation,
|
|
764
|
+
verticalDirection: 'down',
|
|
693
765
|
}));
|
|
694
766
|
requestAnimationFrame(() => {
|
|
695
767
|
requestAnimationFrame(() => {
|
|
@@ -715,6 +787,7 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
715
787
|
}));
|
|
716
788
|
}
|
|
717
789
|
}
|
|
790
|
+
setIsOrientationChanging(false); // Show bar after position is set
|
|
718
791
|
});
|
|
719
792
|
});
|
|
720
793
|
};
|
|
@@ -778,7 +851,7 @@ const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained
|
|
|
778
851
|
setState(s => ({ ...s, draggedItemIndex: null }));
|
|
779
852
|
setDragOverIndex(null);
|
|
780
853
|
};
|
|
781
|
-
return (_jsxs(_Fragment, { children: [_jsx(S.Overlay, { "$visible": state.isConfigMode }), _jsxs(S.FloatingContainer, { ref: floatingRef, "$x": pixelPosition.x, "$y": pixelPosition.y, "$orientation": state.orientation, "$isDragging": state.isDragging, "$isConfigMode": state.isConfigMode, "$isConstrained": isConstrained, "$bgColor": bgColor, onContextMenu: (e) => e.preventDefault(), children: [!state.isConfigMode ? (_jsx(ContextMenu, { items: [
|
|
854
|
+
return (_jsxs(_Fragment, { children: [_jsx(S.Overlay, { "$visible": state.isConfigMode }), _jsxs(S.FloatingContainer, { ref: floatingRef, "$x": pixelPosition.x, "$y": pixelPosition.y, "$orientation": state.orientation, "$verticalDirection": state.verticalDirection, "$isDragging": state.isDragging, "$isConfigMode": state.isConfigMode, "$isConstrained": isConstrained, "$isHidden": isOrientationChanging, "$bgColor": bgColor, onContextMenu: (e) => e.preventDefault(), children: [!state.isConfigMode ? (_jsx(ContextMenu, { items: [
|
|
782
855
|
...(!disbaleConfigMode ? [{
|
|
783
856
|
name: SDKUI_Localizator.Configure,
|
|
784
857
|
onClick: () => {
|
|
@@ -7,17 +7,21 @@ export declare const FloatingContainer: import("styled-components/dist/types").I
|
|
|
7
7
|
$x: number;
|
|
8
8
|
$y: number;
|
|
9
9
|
$orientation: "horizontal" | "vertical";
|
|
10
|
+
$verticalDirection: "down" | "up";
|
|
10
11
|
$isDragging: boolean;
|
|
11
12
|
$isConfigMode: boolean;
|
|
12
13
|
$isConstrained?: boolean;
|
|
14
|
+
$isHidden?: boolean;
|
|
13
15
|
$bgColor?: string;
|
|
14
16
|
}>, {
|
|
15
17
|
$x: number;
|
|
16
18
|
$y: number;
|
|
17
19
|
$orientation: "horizontal" | "vertical";
|
|
20
|
+
$verticalDirection: "down" | "up";
|
|
18
21
|
$isDragging: boolean;
|
|
19
22
|
$isConfigMode: boolean;
|
|
20
23
|
$isConstrained?: boolean;
|
|
24
|
+
$isHidden?: boolean;
|
|
21
25
|
$bgColor?: string;
|
|
22
26
|
}>> & string;
|
|
23
27
|
export declare const GripHandle: import("styled-components/dist/types").IStyledComponentBase<"web", import("styled-components/dist/types").Substitute<import("react").DetailedHTMLProps<import("react").HTMLAttributes<HTMLDivElement>, HTMLDivElement>, {
|
|
@@ -39,7 +39,8 @@ export const FloatingContainer = styled.div.attrs(props => ({
|
|
|
39
39
|
position: ${props => props.$isConstrained ? 'absolute' : 'fixed'};
|
|
40
40
|
z-index: ${props => props.$isConfigMode ? 9999 : 1500};
|
|
41
41
|
display: flex;
|
|
42
|
-
|
|
42
|
+
visibility: ${props => props.$isHidden ? 'hidden' : 'visible'};
|
|
43
|
+
flex-direction: ${props => props.$orientation === 'horizontal' ? 'row' : (props.$verticalDirection === 'up' ? 'column-reverse' : 'column')};
|
|
43
44
|
align-items: center;
|
|
44
45
|
background: ${props => props.$bgColor || 'linear-gradient(135deg, #0071BC 0%, #1B1464 100%)'};
|
|
45
46
|
border: 1px solid #667eea;
|