@topconsultnpm/sdkui-react 6.20.0-dev1.31 → 6.20.0-dev1.32
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.
|
@@ -7,26 +7,74 @@ import * as S from './styles';
|
|
|
7
7
|
import { IconApply, IconMenuKebab, IconMenuVertical, IconPencil, IconPin, SDKUI_Globals } from '../../../helper';
|
|
8
8
|
const IconDraggableDots = (props) => (_jsx("svg", { fontSize: 18, viewBox: "0 0 24 24", fill: "currentColor", height: "1em", width: "1em", ...props, children: _jsx("path", { d: "M9 3a2 2 0 11-4 0 2 2 0 014 0zm0 9a2 2 0 11-4 0 2 2 0 014 0zm0 9a2 2 0 11-4 0 2 2 0 014 0zm10-18a2 2 0 11-4 0 2 2 0 014 0zm0 9a2 2 0 11-4 0 2 2 0 014 0zm0 9a2 2 0 11-4 0 2 2 0 014 0z" }) }));
|
|
9
9
|
const TMFloatingMenuBar = ({ containerRef, contextMenuItems = [], isConstrained = false, defaultPosition = { x: 100, y: 100 }, maxItems = 8, }) => {
|
|
10
|
+
const getDefaultConfig = () => ({
|
|
11
|
+
orientation: 'horizontal',
|
|
12
|
+
savedItemIds: [],
|
|
13
|
+
position: defaultPosition,
|
|
14
|
+
});
|
|
15
|
+
const resetFloatingBarSettings = () => {
|
|
16
|
+
// Reset the floatingMenuBar settings in SDKUI_Globals to trigger save to localStorage
|
|
17
|
+
SDKUI_Globals.userSettings.searchSettings.floatingMenuBar = {
|
|
18
|
+
orientation: 'horizontal',
|
|
19
|
+
itemIds: [],
|
|
20
|
+
position: defaultPosition,
|
|
21
|
+
};
|
|
22
|
+
};
|
|
10
23
|
const loadConfig = () => {
|
|
11
24
|
try {
|
|
12
25
|
const settings = SDKUI_Globals.userSettings.searchSettings.floatingMenuBar;
|
|
26
|
+
// Validate that settings object exists and has required properties with correct types
|
|
27
|
+
if (!settings || typeof settings !== 'object') {
|
|
28
|
+
console.warn('FloatingMenuBar: Invalid settings object, resetting to defaults');
|
|
29
|
+
resetFloatingBarSettings();
|
|
30
|
+
return getDefaultConfig();
|
|
31
|
+
}
|
|
32
|
+
// Validate position
|
|
33
|
+
const hasValidPosition = settings.position &&
|
|
34
|
+
typeof settings.position.x === 'number' &&
|
|
35
|
+
typeof settings.position.y === 'number' &&
|
|
36
|
+
!isNaN(settings.position.x) &&
|
|
37
|
+
!isNaN(settings.position.y) &&
|
|
38
|
+
isFinite(settings.position.x) &&
|
|
39
|
+
isFinite(settings.position.y);
|
|
40
|
+
if (!hasValidPosition) {
|
|
41
|
+
console.warn('FloatingMenuBar: Invalid position, resetting to defaults');
|
|
42
|
+
resetFloatingBarSettings();
|
|
43
|
+
return getDefaultConfig();
|
|
44
|
+
}
|
|
45
|
+
// Ensure position is within reasonable viewport bounds
|
|
46
|
+
const maxX = globalThis.window?.innerWidth ? globalThis.window.innerWidth - 50 : 1000;
|
|
47
|
+
const maxY = globalThis.window?.innerHeight ? globalThis.window.innerHeight - 50 : 800;
|
|
48
|
+
if (settings.position.x < 0 || settings.position.x > maxX ||
|
|
49
|
+
settings.position.y < 0 || settings.position.y > maxY) {
|
|
50
|
+
console.warn('FloatingMenuBar: Position out of bounds, resetting to defaults');
|
|
51
|
+
resetFloatingBarSettings();
|
|
52
|
+
return getDefaultConfig();
|
|
53
|
+
}
|
|
54
|
+
// Validate orientation
|
|
55
|
+
const validOrientation = (settings.orientation === 'horizontal' || settings.orientation === 'vertical')
|
|
56
|
+
? settings.orientation
|
|
57
|
+
: 'horizontal';
|
|
58
|
+
// Validate itemIds
|
|
59
|
+
const validItemIds = Array.isArray(settings.itemIds) ? settings.itemIds : [];
|
|
13
60
|
// Check if position was actually saved (not just the default class value)
|
|
14
|
-
const hasSavedPosition = settings.position
|
|
15
|
-
(settings.position.x !== 100 || settings.position.y !== 100 ||
|
|
16
|
-
(settings.itemIds && settings.itemIds.length > 0));
|
|
61
|
+
const hasSavedPosition = settings.position.x !== 100 || settings.position.y !== 100 || validItemIds.length > 0;
|
|
17
62
|
return {
|
|
18
|
-
orientation:
|
|
19
|
-
savedItemIds:
|
|
63
|
+
orientation: validOrientation,
|
|
64
|
+
savedItemIds: validItemIds,
|
|
20
65
|
position: hasSavedPosition ? settings.position : defaultPosition,
|
|
21
66
|
};
|
|
22
67
|
}
|
|
23
68
|
catch (error) {
|
|
24
69
|
console.error('Failed to load FloatingMenuBar config:', error);
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
70
|
+
// Reset to defaults on any error
|
|
71
|
+
try {
|
|
72
|
+
resetFloatingBarSettings();
|
|
73
|
+
}
|
|
74
|
+
catch (e) {
|
|
75
|
+
console.error('Failed to reset FloatingMenuBar settings:', e);
|
|
76
|
+
}
|
|
77
|
+
return getDefaultConfig();
|
|
30
78
|
}
|
|
31
79
|
};
|
|
32
80
|
const initialConfig = loadConfig();
|