machinaos 0.0.1
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/.env.template +71 -0
- package/LICENSE +21 -0
- package/README.md +87 -0
- package/bin/cli.js +159 -0
- package/client/.dockerignore +45 -0
- package/client/Dockerfile +68 -0
- package/client/eslint.config.js +29 -0
- package/client/index.html +13 -0
- package/client/nginx.conf +66 -0
- package/client/package.json +48 -0
- package/client/src/App.tsx +27 -0
- package/client/src/Dashboard.tsx +1173 -0
- package/client/src/ParameterPanel.tsx +301 -0
- package/client/src/components/AIAgentNode.tsx +321 -0
- package/client/src/components/APIKeyValidator.tsx +118 -0
- package/client/src/components/ClaudeChatModelNode.tsx +18 -0
- package/client/src/components/ConditionalEdge.tsx +189 -0
- package/client/src/components/CredentialsModal.tsx +306 -0
- package/client/src/components/EdgeConditionEditor.tsx +443 -0
- package/client/src/components/GeminiChatModelNode.tsx +18 -0
- package/client/src/components/GenericNode.tsx +357 -0
- package/client/src/components/LocationParameterPanel.tsx +154 -0
- package/client/src/components/ModelNode.tsx +286 -0
- package/client/src/components/OpenAIChatModelNode.tsx +18 -0
- package/client/src/components/OutputPanel.tsx +471 -0
- package/client/src/components/ParameterRenderer.tsx +1874 -0
- package/client/src/components/SkillEditorModal.tsx +417 -0
- package/client/src/components/SquareNode.tsx +797 -0
- package/client/src/components/StartNode.tsx +250 -0
- package/client/src/components/ToolkitNode.tsx +365 -0
- package/client/src/components/TriggerNode.tsx +463 -0
- package/client/src/components/auth/LoginPage.tsx +247 -0
- package/client/src/components/auth/ProtectedRoute.tsx +59 -0
- package/client/src/components/base/BaseChatModelNode.tsx +271 -0
- package/client/src/components/icons/AIProviderIcons.tsx +50 -0
- package/client/src/components/maps/GoogleMapsPicker.tsx +137 -0
- package/client/src/components/maps/MapsPreviewPanel.tsx +110 -0
- package/client/src/components/maps/index.ts +26 -0
- package/client/src/components/parameterPanel/InputSection.tsx +1094 -0
- package/client/src/components/parameterPanel/LocationPanelLayout.tsx +65 -0
- package/client/src/components/parameterPanel/MapsSection.tsx +92 -0
- package/client/src/components/parameterPanel/MiddleSection.tsx +571 -0
- package/client/src/components/parameterPanel/OutputSection.tsx +81 -0
- package/client/src/components/parameterPanel/ParameterPanelLayout.tsx +82 -0
- package/client/src/components/parameterPanel/ToolSchemaEditor.tsx +436 -0
- package/client/src/components/parameterPanel/index.ts +42 -0
- package/client/src/components/shared/DataPanel.tsx +142 -0
- package/client/src/components/shared/JSONTreeRenderer.tsx +106 -0
- package/client/src/components/ui/AIResultModal.tsx +204 -0
- package/client/src/components/ui/AndroidSettingsPanel.tsx +401 -0
- package/client/src/components/ui/CodeEditor.tsx +81 -0
- package/client/src/components/ui/CollapsibleSection.tsx +88 -0
- package/client/src/components/ui/ComponentItem.tsx +154 -0
- package/client/src/components/ui/ComponentPalette.tsx +321 -0
- package/client/src/components/ui/ConsolePanel.tsx +1074 -0
- package/client/src/components/ui/ErrorBoundary.tsx +196 -0
- package/client/src/components/ui/InputNodesPanel.tsx +204 -0
- package/client/src/components/ui/MapSelector.tsx +314 -0
- package/client/src/components/ui/Modal.tsx +149 -0
- package/client/src/components/ui/NodeContextMenu.tsx +192 -0
- package/client/src/components/ui/NodeOutputPanel.tsx +1150 -0
- package/client/src/components/ui/OutputDisplayPanel.tsx +381 -0
- package/client/src/components/ui/SettingsPanel.tsx +243 -0
- package/client/src/components/ui/TopToolbar.tsx +736 -0
- package/client/src/components/ui/WhatsAppSettingsPanel.tsx +345 -0
- package/client/src/components/ui/WorkflowSidebar.tsx +294 -0
- package/client/src/config/antdTheme.ts +186 -0
- package/client/src/config/api.ts +54 -0
- package/client/src/contexts/AuthContext.tsx +221 -0
- package/client/src/contexts/ThemeContext.tsx +42 -0
- package/client/src/contexts/WebSocketContext.tsx +1971 -0
- package/client/src/factories/baseChatModelFactory.ts +256 -0
- package/client/src/hooks/useAndroidOperations.ts +164 -0
- package/client/src/hooks/useApiKeyValidation.ts +107 -0
- package/client/src/hooks/useApiKeys.ts +238 -0
- package/client/src/hooks/useAppTheme.ts +17 -0
- package/client/src/hooks/useComponentPalette.ts +51 -0
- package/client/src/hooks/useCopyPaste.ts +155 -0
- package/client/src/hooks/useDragAndDrop.ts +124 -0
- package/client/src/hooks/useDragVariable.ts +88 -0
- package/client/src/hooks/useExecution.ts +313 -0
- package/client/src/hooks/useParameterPanel.ts +176 -0
- package/client/src/hooks/useReactFlowNodes.ts +189 -0
- package/client/src/hooks/useToolSchema.ts +209 -0
- package/client/src/hooks/useWhatsApp.ts +196 -0
- package/client/src/hooks/useWorkflowManagement.ts +46 -0
- package/client/src/index.css +315 -0
- package/client/src/main.tsx +19 -0
- package/client/src/nodeDefinitions/aiAgentNodes.ts +336 -0
- package/client/src/nodeDefinitions/aiModelNodes.ts +340 -0
- package/client/src/nodeDefinitions/androidDeviceNodes.ts +140 -0
- package/client/src/nodeDefinitions/androidServiceNodes.ts +383 -0
- package/client/src/nodeDefinitions/chatNodes.ts +135 -0
- package/client/src/nodeDefinitions/codeNodes.ts +54 -0
- package/client/src/nodeDefinitions/documentNodes.ts +379 -0
- package/client/src/nodeDefinitions/index.ts +15 -0
- package/client/src/nodeDefinitions/locationNodes.ts +463 -0
- package/client/src/nodeDefinitions/schedulerNodes.ts +220 -0
- package/client/src/nodeDefinitions/skillNodes.ts +211 -0
- package/client/src/nodeDefinitions/toolNodes.ts +198 -0
- package/client/src/nodeDefinitions/utilityNodes.ts +284 -0
- package/client/src/nodeDefinitions/whatsappNodes.ts +865 -0
- package/client/src/nodeDefinitions/workflowNodes.ts +41 -0
- package/client/src/nodeDefinitions.ts +104 -0
- package/client/src/schemas/workflowSchema.ts +264 -0
- package/client/src/services/dynamicParameterService.ts +96 -0
- package/client/src/services/execution/aiAgentExecutionService.ts +35 -0
- package/client/src/services/executionService.ts +232 -0
- package/client/src/services/workflowApi.ts +91 -0
- package/client/src/store/useAppStore.ts +582 -0
- package/client/src/styles/theme.ts +508 -0
- package/client/src/styles/zIndex.ts +17 -0
- package/client/src/types/ComponentTypes.ts +39 -0
- package/client/src/types/EdgeCondition.ts +231 -0
- package/client/src/types/INodeProperties.ts +288 -0
- package/client/src/types/NodeTypes.ts +28 -0
- package/client/src/utils/formatters.ts +33 -0
- package/client/src/utils/googleMapsLoader.ts +140 -0
- package/client/src/utils/locationUtils.ts +85 -0
- package/client/src/utils/nodeUtils.ts +31 -0
- package/client/src/utils/workflow.ts +30 -0
- package/client/src/utils/workflowExport.ts +120 -0
- package/client/src/vite-env.d.ts +12 -0
- package/client/tailwind.config.js +60 -0
- package/client/tsconfig.json +25 -0
- package/client/tsconfig.node.json +11 -0
- package/client/vite.config.js +35 -0
- package/docker-compose.prod.yml +107 -0
- package/docker-compose.yml +104 -0
- package/docs-MachinaOs/README.md +85 -0
- package/docs-MachinaOs/deployment/docker.mdx +228 -0
- package/docs-MachinaOs/deployment/production.mdx +345 -0
- package/docs-MachinaOs/docs.json +75 -0
- package/docs-MachinaOs/faq.mdx +309 -0
- package/docs-MachinaOs/favicon.svg +5 -0
- package/docs-MachinaOs/installation.mdx +160 -0
- package/docs-MachinaOs/introduction.mdx +114 -0
- package/docs-MachinaOs/logo/dark.svg +6 -0
- package/docs-MachinaOs/logo/light.svg +6 -0
- package/docs-MachinaOs/nodes/ai-agent.mdx +216 -0
- package/docs-MachinaOs/nodes/ai-models.mdx +240 -0
- package/docs-MachinaOs/nodes/android.mdx +411 -0
- package/docs-MachinaOs/nodes/overview.mdx +181 -0
- package/docs-MachinaOs/nodes/schedulers.mdx +316 -0
- package/docs-MachinaOs/nodes/webhooks.mdx +330 -0
- package/docs-MachinaOs/nodes/whatsapp.mdx +305 -0
- package/docs-MachinaOs/quickstart.mdx +119 -0
- package/docs-MachinaOs/tutorials/ai-agent-workflow.mdx +177 -0
- package/docs-MachinaOs/tutorials/android-automation.mdx +242 -0
- package/docs-MachinaOs/tutorials/first-workflow.mdx +134 -0
- package/docs-MachinaOs/tutorials/whatsapp-automation.mdx +185 -0
- package/nul +0 -0
- package/package.json +70 -0
- package/scripts/build.js +158 -0
- package/scripts/check-ports.ps1 +33 -0
- package/scripts/clean.js +40 -0
- package/scripts/docker.js +93 -0
- package/scripts/kill-port.ps1 +154 -0
- package/scripts/start.js +210 -0
- package/scripts/stop.js +325 -0
- package/server/.dockerignore +44 -0
- package/server/Dockerfile +45 -0
- package/server/constants.py +249 -0
- package/server/core/__init__.py +1 -0
- package/server/core/cache.py +461 -0
- package/server/core/config.py +128 -0
- package/server/core/container.py +99 -0
- package/server/core/database.py +1211 -0
- package/server/core/logging.py +314 -0
- package/server/main.py +289 -0
- package/server/middleware/__init__.py +5 -0
- package/server/middleware/auth.py +89 -0
- package/server/models/__init__.py +1 -0
- package/server/models/auth.py +52 -0
- package/server/models/cache.py +24 -0
- package/server/models/database.py +211 -0
- package/server/models/nodes.py +455 -0
- package/server/package.json +9 -0
- package/server/pyproject.toml +72 -0
- package/server/requirements.txt +83 -0
- package/server/routers/__init__.py +1 -0
- package/server/routers/android.py +294 -0
- package/server/routers/auth.py +203 -0
- package/server/routers/database.py +151 -0
- package/server/routers/maps.py +142 -0
- package/server/routers/nodejs_compat.py +289 -0
- package/server/routers/webhook.py +90 -0
- package/server/routers/websocket.py +2127 -0
- package/server/routers/whatsapp.py +761 -0
- package/server/routers/workflow.py +200 -0
- package/server/services/__init__.py +1 -0
- package/server/services/ai.py +2415 -0
- package/server/services/android/__init__.py +27 -0
- package/server/services/android/broadcaster.py +114 -0
- package/server/services/android/client.py +608 -0
- package/server/services/android/manager.py +78 -0
- package/server/services/android/protocol.py +165 -0
- package/server/services/android_service.py +588 -0
- package/server/services/auth.py +131 -0
- package/server/services/chat_client.py +160 -0
- package/server/services/deployment/__init__.py +12 -0
- package/server/services/deployment/manager.py +706 -0
- package/server/services/deployment/state.py +47 -0
- package/server/services/deployment/triggers.py +275 -0
- package/server/services/event_waiter.py +785 -0
- package/server/services/execution/__init__.py +77 -0
- package/server/services/execution/cache.py +769 -0
- package/server/services/execution/conditions.py +373 -0
- package/server/services/execution/dlq.py +132 -0
- package/server/services/execution/executor.py +1351 -0
- package/server/services/execution/models.py +531 -0
- package/server/services/execution/recovery.py +235 -0
- package/server/services/handlers/__init__.py +126 -0
- package/server/services/handlers/ai.py +355 -0
- package/server/services/handlers/android.py +260 -0
- package/server/services/handlers/code.py +278 -0
- package/server/services/handlers/document.py +598 -0
- package/server/services/handlers/http.py +193 -0
- package/server/services/handlers/polyglot.py +105 -0
- package/server/services/handlers/tools.py +845 -0
- package/server/services/handlers/triggers.py +107 -0
- package/server/services/handlers/utility.py +822 -0
- package/server/services/handlers/whatsapp.py +476 -0
- package/server/services/maps.py +289 -0
- package/server/services/memory_store.py +103 -0
- package/server/services/node_executor.py +375 -0
- package/server/services/parameter_resolver.py +218 -0
- package/server/services/polyglot_client.py +169 -0
- package/server/services/scheduler.py +155 -0
- package/server/services/skill_loader.py +417 -0
- package/server/services/status_broadcaster.py +826 -0
- package/server/services/temporal/__init__.py +23 -0
- package/server/services/temporal/activities.py +344 -0
- package/server/services/temporal/client.py +76 -0
- package/server/services/temporal/executor.py +147 -0
- package/server/services/temporal/worker.py +251 -0
- package/server/services/temporal/workflow.py +355 -0
- package/server/services/temporal/ws_client.py +236 -0
- package/server/services/text.py +111 -0
- package/server/services/user_auth.py +172 -0
- package/server/services/websocket_client.py +29 -0
- package/server/services/workflow.py +597 -0
- package/server/skills/android-skill/SKILL.md +82 -0
- package/server/skills/assistant-personality/SKILL.md +45 -0
- package/server/skills/code-skill/SKILL.md +140 -0
- package/server/skills/http-skill/SKILL.md +161 -0
- package/server/skills/maps-skill/SKILL.md +170 -0
- package/server/skills/memory-skill/SKILL.md +154 -0
- package/server/skills/scheduler-skill/SKILL.md +84 -0
- package/server/skills/whatsapp-skill/SKILL.md +283 -0
- package/server/uv.lock +2916 -0
- package/server/whatsapp-rpc/.dockerignore +30 -0
- package/server/whatsapp-rpc/Dockerfile +44 -0
- package/server/whatsapp-rpc/Dockerfile.web +17 -0
- package/server/whatsapp-rpc/README.md +139 -0
- package/server/whatsapp-rpc/cli.js +95 -0
- package/server/whatsapp-rpc/configs/config.yaml +7 -0
- package/server/whatsapp-rpc/docker-compose.yml +35 -0
- package/server/whatsapp-rpc/docs/API.md +410 -0
- package/server/whatsapp-rpc/go.mod +67 -0
- package/server/whatsapp-rpc/go.sum +203 -0
- package/server/whatsapp-rpc/package.json +30 -0
- package/server/whatsapp-rpc/schema.json +1294 -0
- package/server/whatsapp-rpc/scripts/clean.cjs +66 -0
- package/server/whatsapp-rpc/scripts/cli.js +162 -0
- package/server/whatsapp-rpc/src/go/cmd/server/main.go +91 -0
- package/server/whatsapp-rpc/src/go/config/config.go +49 -0
- package/server/whatsapp-rpc/src/go/rpc/rpc.go +446 -0
- package/server/whatsapp-rpc/src/go/rpc/server.go +112 -0
- package/server/whatsapp-rpc/src/go/whatsapp/history.go +166 -0
- package/server/whatsapp-rpc/src/go/whatsapp/messages.go +390 -0
- package/server/whatsapp-rpc/src/go/whatsapp/service.go +2130 -0
- package/server/whatsapp-rpc/src/go/whatsapp/types.go +261 -0
- package/server/whatsapp-rpc/src/python/pyproject.toml +15 -0
- package/server/whatsapp-rpc/src/python/whatsapp_rpc/__init__.py +4 -0
- package/server/whatsapp-rpc/src/python/whatsapp_rpc/client.py +427 -0
- package/server/whatsapp-rpc/web/app.py +609 -0
- package/server/whatsapp-rpc/web/requirements.txt +6 -0
- package/server/whatsapp-rpc/web/rpc_client.py +427 -0
- package/server/whatsapp-rpc/web/static/openapi.yaml +59 -0
- package/server/whatsapp-rpc/web/templates/base.html +150 -0
- package/server/whatsapp-rpc/web/templates/contacts.html +240 -0
- package/server/whatsapp-rpc/web/templates/dashboard.html +320 -0
- package/server/whatsapp-rpc/web/templates/groups.html +328 -0
- package/server/whatsapp-rpc/web/templates/messages.html +465 -0
- package/server/whatsapp-rpc/web/templates/messaging.html +681 -0
- package/server/whatsapp-rpc/web/templates/send.html +259 -0
- package/server/whatsapp-rpc/web/templates/settings.html +459 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
import React, { useState, useCallback, useEffect, useRef } from 'react';
|
|
2
|
+
import { loadGoogleMaps } from '../../utils/googleMapsLoader';
|
|
3
|
+
import { useAppTheme } from '../../hooks/useAppTheme';
|
|
4
|
+
import { useTheme } from '../../contexts/ThemeContext';
|
|
5
|
+
|
|
6
|
+
// Google Maps API Key from environment variable
|
|
7
|
+
const GOOGLE_MAPS_API_KEY = (import.meta as any).env?.VITE_GOOGLE_MAPS_API_KEY || 'YOUR_API_KEY_HERE';
|
|
8
|
+
|
|
9
|
+
interface MapSelectorProps {
|
|
10
|
+
initialLatitude?: number;
|
|
11
|
+
initialLongitude?: number;
|
|
12
|
+
onLocationSelect: (latitude: number, longitude: number) => void;
|
|
13
|
+
onClose: () => void;
|
|
14
|
+
apiKey?: string;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Dark mode styles for Google Maps (Dracula-inspired)
|
|
18
|
+
const darkMapStyles: google.maps.MapTypeStyle[] = [
|
|
19
|
+
{ elementType: 'geometry', stylers: [{ color: '#242f3e' }] },
|
|
20
|
+
{ elementType: 'labels.text.stroke', stylers: [{ color: '#242f3e' }] },
|
|
21
|
+
{ elementType: 'labels.text.fill', stylers: [{ color: '#746855' }] },
|
|
22
|
+
{ featureType: 'administrative.locality', elementType: 'labels.text.fill', stylers: [{ color: '#d59563' }] },
|
|
23
|
+
{ featureType: 'poi', elementType: 'labels.text.fill', stylers: [{ color: '#d59563' }] },
|
|
24
|
+
{ featureType: 'poi.park', elementType: 'geometry', stylers: [{ color: '#263c3f' }] },
|
|
25
|
+
{ featureType: 'poi.park', elementType: 'labels.text.fill', stylers: [{ color: '#6b9a76' }] },
|
|
26
|
+
{ featureType: 'road', elementType: 'geometry', stylers: [{ color: '#38414e' }] },
|
|
27
|
+
{ featureType: 'road', elementType: 'geometry.stroke', stylers: [{ color: '#212a37' }] },
|
|
28
|
+
{ featureType: 'road', elementType: 'labels.text.fill', stylers: [{ color: '#9ca5b3' }] },
|
|
29
|
+
{ featureType: 'road.highway', elementType: 'geometry', stylers: [{ color: '#746855' }] },
|
|
30
|
+
{ featureType: 'road.highway', elementType: 'geometry.stroke', stylers: [{ color: '#1f2835' }] },
|
|
31
|
+
{ featureType: 'road.highway', elementType: 'labels.text.fill', stylers: [{ color: '#f3d19c' }] },
|
|
32
|
+
{ featureType: 'transit', elementType: 'geometry', stylers: [{ color: '#2f3948' }] },
|
|
33
|
+
{ featureType: 'transit.station', elementType: 'labels.text.fill', stylers: [{ color: '#d59563' }] },
|
|
34
|
+
{ featureType: 'water', elementType: 'geometry', stylers: [{ color: '#17263c' }] },
|
|
35
|
+
{ featureType: 'water', elementType: 'labels.text.fill', stylers: [{ color: '#515c6d' }] },
|
|
36
|
+
{ featureType: 'water', elementType: 'labels.text.stroke', stylers: [{ color: '#17263c' }] }
|
|
37
|
+
];
|
|
38
|
+
|
|
39
|
+
// Google Maps Component for Location Selection
|
|
40
|
+
const GoogleMapsLocationPicker: React.FC<{
|
|
41
|
+
lat: number;
|
|
42
|
+
lng: number;
|
|
43
|
+
onLocationClick: (lat: number, lng: number) => void;
|
|
44
|
+
apiKey?: string;
|
|
45
|
+
isDarkMode: boolean;
|
|
46
|
+
theme: ReturnType<typeof useAppTheme>;
|
|
47
|
+
}> = ({ lat, lng, onLocationClick, apiKey, isDarkMode, theme }) => {
|
|
48
|
+
const mapRef = useRef<HTMLDivElement>(null);
|
|
49
|
+
const mapInstanceRef = useRef<google.maps.Map | null>(null);
|
|
50
|
+
const markerRef = useRef<google.maps.Marker | null>(null);
|
|
51
|
+
|
|
52
|
+
useEffect(() => {
|
|
53
|
+
if (!mapRef.current || !apiKey || apiKey === 'YOUR_API_KEY_HERE') return;
|
|
54
|
+
|
|
55
|
+
// Load Google Maps API using centralized loader
|
|
56
|
+
const loadAndInitialize = async () => {
|
|
57
|
+
try {
|
|
58
|
+
await loadGoogleMaps({
|
|
59
|
+
apiKey,
|
|
60
|
+
libraries: ['geometry']
|
|
61
|
+
});
|
|
62
|
+
initializeMap();
|
|
63
|
+
} catch (error) {
|
|
64
|
+
console.error('Failed to load Google Maps API:', error);
|
|
65
|
+
}
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
loadAndInitialize();
|
|
69
|
+
|
|
70
|
+
function initializeMap() {
|
|
71
|
+
if (!mapRef.current) return;
|
|
72
|
+
|
|
73
|
+
const mapOptions: google.maps.MapOptions = {
|
|
74
|
+
center: { lat, lng },
|
|
75
|
+
zoom: 15,
|
|
76
|
+
mapTypeId: google.maps.MapTypeId.ROADMAP,
|
|
77
|
+
clickableIcons: false,
|
|
78
|
+
disableDefaultUI: false,
|
|
79
|
+
zoomControl: true,
|
|
80
|
+
mapTypeControl: true,
|
|
81
|
+
streetViewControl: true,
|
|
82
|
+
fullscreenControl: true,
|
|
83
|
+
// Apply dark mode styles when in dark mode
|
|
84
|
+
styles: isDarkMode ? darkMapStyles : undefined
|
|
85
|
+
};
|
|
86
|
+
|
|
87
|
+
mapInstanceRef.current = new google.maps.Map(mapRef.current, mapOptions);
|
|
88
|
+
|
|
89
|
+
// Create marker
|
|
90
|
+
markerRef.current = new google.maps.Marker({
|
|
91
|
+
position: { lat, lng },
|
|
92
|
+
map: mapInstanceRef.current,
|
|
93
|
+
draggable: true,
|
|
94
|
+
title: 'Selected Location - Click or drag to change'
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
// Add click listeners
|
|
98
|
+
mapInstanceRef.current.addListener('click', (e: google.maps.MapMouseEvent) => {
|
|
99
|
+
if (e.latLng) {
|
|
100
|
+
const newLat = e.latLng.lat();
|
|
101
|
+
const newLng = e.latLng.lng();
|
|
102
|
+
onLocationClick(newLat, newLng);
|
|
103
|
+
}
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
// Add marker drag listener
|
|
107
|
+
markerRef.current.addListener('dragend', (e: google.maps.MapMouseEvent) => {
|
|
108
|
+
if (e.latLng) {
|
|
109
|
+
const newLat = e.latLng.lat();
|
|
110
|
+
const newLng = e.latLng.lng();
|
|
111
|
+
onLocationClick(newLat, newLng);
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
}, [apiKey, isDarkMode]);
|
|
116
|
+
|
|
117
|
+
// Update marker position when coordinates change
|
|
118
|
+
useEffect(() => {
|
|
119
|
+
if (markerRef.current && mapInstanceRef.current) {
|
|
120
|
+
const newPosition = { lat, lng };
|
|
121
|
+
markerRef.current.setPosition(newPosition);
|
|
122
|
+
mapInstanceRef.current.setCenter(newPosition);
|
|
123
|
+
}
|
|
124
|
+
}, [lat, lng]);
|
|
125
|
+
|
|
126
|
+
if (!apiKey || apiKey === 'YOUR_API_KEY_HERE') {
|
|
127
|
+
return (
|
|
128
|
+
<div style={{
|
|
129
|
+
height: '100%',
|
|
130
|
+
display: 'flex',
|
|
131
|
+
alignItems: 'center',
|
|
132
|
+
justifyContent: 'center',
|
|
133
|
+
backgroundColor: theme.colors.backgroundAlt,
|
|
134
|
+
color: theme.colors.textSecondary,
|
|
135
|
+
fontSize: theme.fontSize.sm,
|
|
136
|
+
textAlign: 'center',
|
|
137
|
+
padding: theme.spacing.lg
|
|
138
|
+
}}>
|
|
139
|
+
Google Maps API key required for map display
|
|
140
|
+
</div>
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return (
|
|
145
|
+
<div
|
|
146
|
+
ref={mapRef}
|
|
147
|
+
style={{
|
|
148
|
+
height: '100%',
|
|
149
|
+
width: '100%'
|
|
150
|
+
}}
|
|
151
|
+
/>
|
|
152
|
+
);
|
|
153
|
+
};
|
|
154
|
+
|
|
155
|
+
const MapSelector: React.FC<MapSelectorProps> = ({
|
|
156
|
+
initialLatitude = 37.7749,
|
|
157
|
+
initialLongitude = -122.4194,
|
|
158
|
+
onLocationSelect,
|
|
159
|
+
onClose,
|
|
160
|
+
apiKey = GOOGLE_MAPS_API_KEY
|
|
161
|
+
}) => {
|
|
162
|
+
const theme = useAppTheme();
|
|
163
|
+
const { isDarkMode } = useTheme();
|
|
164
|
+
const [selectedPosition, setSelectedPosition] = useState<[number, number]>([
|
|
165
|
+
initialLatitude,
|
|
166
|
+
initialLongitude
|
|
167
|
+
]);
|
|
168
|
+
|
|
169
|
+
const handleMapClick = useCallback((lat: number, lng: number) => {
|
|
170
|
+
setSelectedPosition([lat, lng]);
|
|
171
|
+
onLocationSelect(lat, lng);
|
|
172
|
+
}, [onLocationSelect]);
|
|
173
|
+
|
|
174
|
+
return (
|
|
175
|
+
<>
|
|
176
|
+
{/* Backdrop */}
|
|
177
|
+
<div
|
|
178
|
+
style={{
|
|
179
|
+
position: 'fixed',
|
|
180
|
+
top: 0,
|
|
181
|
+
left: 0,
|
|
182
|
+
right: 0,
|
|
183
|
+
bottom: 0,
|
|
184
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
185
|
+
zIndex: 2000,
|
|
186
|
+
pointerEvents: 'none',
|
|
187
|
+
}}
|
|
188
|
+
/>
|
|
189
|
+
|
|
190
|
+
{/* Close Button */}
|
|
191
|
+
<button
|
|
192
|
+
onClick={(e) => {
|
|
193
|
+
e.preventDefault();
|
|
194
|
+
e.stopPropagation();
|
|
195
|
+
onClose();
|
|
196
|
+
}}
|
|
197
|
+
onMouseEnter={(e) => {
|
|
198
|
+
e.currentTarget.style.backgroundColor = theme.dracula.red;
|
|
199
|
+
e.currentTarget.style.transform = 'scale(1.1)';
|
|
200
|
+
}}
|
|
201
|
+
onMouseLeave={(e) => {
|
|
202
|
+
e.currentTarget.style.backgroundColor = theme.dracula.pink;
|
|
203
|
+
e.currentTarget.style.transform = 'scale(1)';
|
|
204
|
+
}}
|
|
205
|
+
style={{
|
|
206
|
+
position: 'fixed',
|
|
207
|
+
top: 'calc(50% - 40vh + 10px)',
|
|
208
|
+
right: '60px',
|
|
209
|
+
width: '44px',
|
|
210
|
+
height: '44px',
|
|
211
|
+
borderRadius: '50%',
|
|
212
|
+
backgroundColor: theme.dracula.pink,
|
|
213
|
+
color: 'white',
|
|
214
|
+
border: 'none',
|
|
215
|
+
fontSize: '20px',
|
|
216
|
+
fontWeight: 'bold',
|
|
217
|
+
cursor: 'pointer',
|
|
218
|
+
boxShadow: `0 6px 16px ${theme.dracula.pink}60`,
|
|
219
|
+
zIndex: 2002,
|
|
220
|
+
display: 'flex',
|
|
221
|
+
alignItems: 'center',
|
|
222
|
+
justifyContent: 'center',
|
|
223
|
+
transition: 'all 0.2s ease',
|
|
224
|
+
}}
|
|
225
|
+
title="Close Map Selector"
|
|
226
|
+
>
|
|
227
|
+
✕
|
|
228
|
+
</button>
|
|
229
|
+
|
|
230
|
+
{/* Map Window */}
|
|
231
|
+
<div
|
|
232
|
+
style={{
|
|
233
|
+
position: 'fixed',
|
|
234
|
+
top: '50%',
|
|
235
|
+
left: '490px',
|
|
236
|
+
right: '50px',
|
|
237
|
+
transform: 'translateY(-50%)',
|
|
238
|
+
height: '80vh',
|
|
239
|
+
backgroundColor: theme.colors.backgroundPanel,
|
|
240
|
+
borderRadius: theme.borderRadius.lg,
|
|
241
|
+
boxShadow: theme.colors.shadowNode,
|
|
242
|
+
display: 'flex',
|
|
243
|
+
flexDirection: 'column',
|
|
244
|
+
overflow: 'hidden',
|
|
245
|
+
zIndex: 2001,
|
|
246
|
+
border: `1px solid ${theme.colors.border}`,
|
|
247
|
+
}}
|
|
248
|
+
>
|
|
249
|
+
{/* Header */}
|
|
250
|
+
<div style={{
|
|
251
|
+
padding: theme.spacing.md,
|
|
252
|
+
borderBottom: `1px solid ${theme.colors.border}`,
|
|
253
|
+
backgroundColor: theme.colors.backgroundAlt,
|
|
254
|
+
}}>
|
|
255
|
+
<h3 style={{
|
|
256
|
+
margin: 0,
|
|
257
|
+
fontSize: theme.fontSize.lg,
|
|
258
|
+
fontWeight: theme.fontWeight.semibold,
|
|
259
|
+
color: theme.colors.text
|
|
260
|
+
}}>
|
|
261
|
+
Select Location
|
|
262
|
+
</h3>
|
|
263
|
+
<p style={{
|
|
264
|
+
margin: `${theme.spacing.xs} 0 0 0`,
|
|
265
|
+
fontSize: theme.fontSize.sm,
|
|
266
|
+
color: theme.colors.textSecondary
|
|
267
|
+
}}>
|
|
268
|
+
Click on the map or drag the marker to select coordinates
|
|
269
|
+
</p>
|
|
270
|
+
</div>
|
|
271
|
+
|
|
272
|
+
{/* Coordinates Display */}
|
|
273
|
+
<div style={{
|
|
274
|
+
padding: theme.spacing.sm,
|
|
275
|
+
backgroundColor: theme.colors.background,
|
|
276
|
+
borderBottom: `1px solid ${theme.colors.border}`,
|
|
277
|
+
display: 'flex',
|
|
278
|
+
justifyContent: 'space-between',
|
|
279
|
+
alignItems: 'center'
|
|
280
|
+
}}>
|
|
281
|
+
<div style={{
|
|
282
|
+
fontSize: theme.fontSize.sm,
|
|
283
|
+
fontFamily: 'monospace',
|
|
284
|
+
color: theme.colors.text,
|
|
285
|
+
fontWeight: theme.fontWeight.medium
|
|
286
|
+
}}>
|
|
287
|
+
{selectedPosition[0].toFixed(6)}, {selectedPosition[1].toFixed(6)}
|
|
288
|
+
</div>
|
|
289
|
+
<div style={{
|
|
290
|
+
fontSize: theme.fontSize.xs,
|
|
291
|
+
color: theme.colors.textSecondary,
|
|
292
|
+
fontStyle: 'italic'
|
|
293
|
+
}}>
|
|
294
|
+
Google Maps
|
|
295
|
+
</div>
|
|
296
|
+
</div>
|
|
297
|
+
|
|
298
|
+
{/* Map */}
|
|
299
|
+
<div style={{ flex: 1, position: 'relative' }}>
|
|
300
|
+
<GoogleMapsLocationPicker
|
|
301
|
+
lat={selectedPosition[0]}
|
|
302
|
+
lng={selectedPosition[1]}
|
|
303
|
+
onLocationClick={handleMapClick}
|
|
304
|
+
apiKey={apiKey}
|
|
305
|
+
isDarkMode={isDarkMode}
|
|
306
|
+
theme={theme}
|
|
307
|
+
/>
|
|
308
|
+
</div>
|
|
309
|
+
</div>
|
|
310
|
+
</>
|
|
311
|
+
);
|
|
312
|
+
};
|
|
313
|
+
|
|
314
|
+
export default MapSelector;
|
|
@@ -0,0 +1,149 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import * as Dialog from '@radix-ui/react-dialog';
|
|
3
|
+
import { useAppTheme } from '../../hooks/useAppTheme';
|
|
4
|
+
|
|
5
|
+
interface ModalProps {
|
|
6
|
+
isOpen: boolean;
|
|
7
|
+
onClose: () => void;
|
|
8
|
+
children: React.ReactNode;
|
|
9
|
+
title?: string;
|
|
10
|
+
maxWidth?: string;
|
|
11
|
+
maxHeight?: string;
|
|
12
|
+
headerActions?: React.ReactNode;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
const Modal: React.FC<ModalProps> = ({
|
|
16
|
+
isOpen,
|
|
17
|
+
onClose,
|
|
18
|
+
children,
|
|
19
|
+
title,
|
|
20
|
+
maxWidth = '500px',
|
|
21
|
+
maxHeight = '80vh',
|
|
22
|
+
headerActions,
|
|
23
|
+
}) => {
|
|
24
|
+
const theme = useAppTheme();
|
|
25
|
+
return (
|
|
26
|
+
<Dialog.Root open={isOpen}>
|
|
27
|
+
<Dialog.Portal>
|
|
28
|
+
<Dialog.Overlay
|
|
29
|
+
style={{
|
|
30
|
+
position: 'fixed',
|
|
31
|
+
inset: 0,
|
|
32
|
+
backgroundColor: 'rgba(0, 0, 0, 0.5)',
|
|
33
|
+
backdropFilter: 'blur(2px)',
|
|
34
|
+
zIndex: 1000,
|
|
35
|
+
}}
|
|
36
|
+
/>
|
|
37
|
+
<Dialog.Content
|
|
38
|
+
style={{
|
|
39
|
+
position: 'fixed',
|
|
40
|
+
top: '2.5vh',
|
|
41
|
+
left: '2.5vw',
|
|
42
|
+
backgroundColor: theme.colors.background,
|
|
43
|
+
borderRadius: theme.borderRadius.lg,
|
|
44
|
+
boxShadow: '0 25px 50px -12px rgba(0, 0, 0, 0.25)',
|
|
45
|
+
width: maxWidth,
|
|
46
|
+
height: maxHeight,
|
|
47
|
+
display: 'flex',
|
|
48
|
+
flexDirection: 'column',
|
|
49
|
+
overflow: 'hidden',
|
|
50
|
+
zIndex: 1001,
|
|
51
|
+
}}
|
|
52
|
+
>
|
|
53
|
+
{title && (
|
|
54
|
+
<div
|
|
55
|
+
style={{
|
|
56
|
+
padding: `${theme.spacing.lg} ${theme.spacing.xl}`,
|
|
57
|
+
borderBottom: `1px solid ${theme.colors.border}`,
|
|
58
|
+
backgroundColor: theme.colors.backgroundPanel,
|
|
59
|
+
display: 'flex',
|
|
60
|
+
alignItems: 'center',
|
|
61
|
+
position: 'relative',
|
|
62
|
+
width: '100%'
|
|
63
|
+
}}
|
|
64
|
+
>
|
|
65
|
+
<Dialog.Title
|
|
66
|
+
style={{
|
|
67
|
+
margin: 0,
|
|
68
|
+
fontSize: theme.fontSize.lg,
|
|
69
|
+
fontWeight: theme.fontWeight.semibold,
|
|
70
|
+
color: theme.colors.textSecondary,
|
|
71
|
+
position: 'absolute',
|
|
72
|
+
left: theme.spacing.xl,
|
|
73
|
+
display: 'flex',
|
|
74
|
+
alignItems: 'center',
|
|
75
|
+
gap: '8px',
|
|
76
|
+
}}
|
|
77
|
+
>
|
|
78
|
+
<svg width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round" style={{ opacity: 0.7 }}>
|
|
79
|
+
<circle cx="12" cy="12" r="3"/>
|
|
80
|
+
<path d="M19.4 15a1.65 1.65 0 0 0 .33 1.82l.06.06a2 2 0 0 1 0 2.83 2 2 0 0 1-2.83 0l-.06-.06a1.65 1.65 0 0 0-1.82-.33 1.65 1.65 0 0 0-1 1.51V21a2 2 0 0 1-2 2 2 2 0 0 1-2-2v-.09A1.65 1.65 0 0 0 9 19.4a1.65 1.65 0 0 0-1.82.33l-.06.06a2 2 0 0 1-2.83 0 2 2 0 0 1 0-2.83l.06-.06a1.65 1.65 0 0 0 .33-1.82 1.65 1.65 0 0 0-1.51-1H3a2 2 0 0 1-2-2 2 2 0 0 1 2-2h.09A1.65 1.65 0 0 0 4.6 9a1.65 1.65 0 0 0-.33-1.82l-.06-.06a2 2 0 0 1 0-2.83 2 2 0 0 1 2.83 0l.06.06a1.65 1.65 0 0 0 1.82.33H9a1.65 1.65 0 0 0 1-1.51V3a2 2 0 0 1 2-2 2 2 0 0 1 2 2v.09a1.65 1.65 0 0 0 1 1.51 1.65 1.65 0 0 0 1.82-.33l.06-.06a2 2 0 0 1 2.83 0 2 2 0 0 1 0 2.83l-.06.06a1.65 1.65 0 0 0-.33 1.82V9a1.65 1.65 0 0 0 1.51 1H21a2 2 0 0 1 2 2 2 2 0 0 1-2 2h-.09a1.65 1.65 0 0 0-1.51 1z"/>
|
|
81
|
+
</svg>
|
|
82
|
+
{title}
|
|
83
|
+
</Dialog.Title>
|
|
84
|
+
|
|
85
|
+
{/* Centered header actions */}
|
|
86
|
+
<div style={{
|
|
87
|
+
flex: 1,
|
|
88
|
+
display: 'flex',
|
|
89
|
+
justifyContent: 'center',
|
|
90
|
+
alignItems: 'center'
|
|
91
|
+
}}>
|
|
92
|
+
{headerActions}
|
|
93
|
+
</div>
|
|
94
|
+
|
|
95
|
+
<Dialog.Close
|
|
96
|
+
onClick={onClose}
|
|
97
|
+
style={{
|
|
98
|
+
background: 'transparent',
|
|
99
|
+
border: 'none',
|
|
100
|
+
fontSize: '20px',
|
|
101
|
+
cursor: 'pointer',
|
|
102
|
+
color: theme.colors.textSecondary,
|
|
103
|
+
padding: theme.spacing.xs,
|
|
104
|
+
borderRadius: theme.borderRadius.sm,
|
|
105
|
+
display: 'flex',
|
|
106
|
+
alignItems: 'center',
|
|
107
|
+
justifyContent: 'center',
|
|
108
|
+
width: '32px',
|
|
109
|
+
height: '32px',
|
|
110
|
+
position: 'absolute',
|
|
111
|
+
right: theme.spacing.xl,
|
|
112
|
+
transition: `all ${theme.transitions.fast}`,
|
|
113
|
+
}}
|
|
114
|
+
onMouseEnter={(e) => {
|
|
115
|
+
e.currentTarget.style.backgroundColor = theme.colors.backgroundHover;
|
|
116
|
+
e.currentTarget.style.color = theme.colors.text;
|
|
117
|
+
}}
|
|
118
|
+
onMouseLeave={(e) => {
|
|
119
|
+
e.currentTarget.style.backgroundColor = 'transparent';
|
|
120
|
+
e.currentTarget.style.color = theme.colors.textSecondary;
|
|
121
|
+
}}
|
|
122
|
+
>
|
|
123
|
+
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" strokeWidth="2" strokeLinecap="round" strokeLinejoin="round">
|
|
124
|
+
<line x1="18" y1="6" x2="6" y2="18"/>
|
|
125
|
+
<line x1="6" y1="6" x2="18" y2="18"/>
|
|
126
|
+
</svg>
|
|
127
|
+
</Dialog.Close>
|
|
128
|
+
</div>
|
|
129
|
+
)}
|
|
130
|
+
<Dialog.Description style={{ display: 'none' }}>
|
|
131
|
+
{title || 'Modal dialog'}
|
|
132
|
+
</Dialog.Description>
|
|
133
|
+
<div
|
|
134
|
+
style={{
|
|
135
|
+
flex: 1,
|
|
136
|
+
height: '100%',
|
|
137
|
+
overflowY: 'auto',
|
|
138
|
+
padding: 0,
|
|
139
|
+
}}
|
|
140
|
+
>
|
|
141
|
+
{children}
|
|
142
|
+
</div>
|
|
143
|
+
</Dialog.Content>
|
|
144
|
+
</Dialog.Portal>
|
|
145
|
+
</Dialog.Root>
|
|
146
|
+
);
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
export default Modal;
|
|
@@ -0,0 +1,192 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodeContextMenu - Right-click context menu for nodes
|
|
3
|
+
*
|
|
4
|
+
* Provides actions: Rename, Copy, Delete
|
|
5
|
+
* Follows n8n-style UX patterns with keyboard shortcuts displayed
|
|
6
|
+
*/
|
|
7
|
+
import React, { useEffect, useRef, useCallback } from 'react';
|
|
8
|
+
import { useAppTheme } from '../../hooks/useAppTheme';
|
|
9
|
+
|
|
10
|
+
interface NodeContextMenuProps {
|
|
11
|
+
nodeId: string;
|
|
12
|
+
x: number;
|
|
13
|
+
y: number;
|
|
14
|
+
onClose: () => void;
|
|
15
|
+
onRename: () => void;
|
|
16
|
+
onCopy: () => void;
|
|
17
|
+
onDelete: () => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface MenuItem {
|
|
21
|
+
label: string;
|
|
22
|
+
shortcut: string;
|
|
23
|
+
action: () => void;
|
|
24
|
+
icon: string;
|
|
25
|
+
danger?: boolean;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
const NodeContextMenu: React.FC<NodeContextMenuProps> = ({
|
|
29
|
+
nodeId: _nodeId,
|
|
30
|
+
x,
|
|
31
|
+
y,
|
|
32
|
+
onClose,
|
|
33
|
+
onRename,
|
|
34
|
+
onCopy,
|
|
35
|
+
onDelete,
|
|
36
|
+
}) => {
|
|
37
|
+
const theme = useAppTheme();
|
|
38
|
+
const menuRef = useRef<HTMLDivElement>(null);
|
|
39
|
+
const [focusedIndex, setFocusedIndex] = React.useState(0);
|
|
40
|
+
|
|
41
|
+
const menuItems: MenuItem[] = [
|
|
42
|
+
{ label: 'Rename', shortcut: 'F2', action: onRename, icon: '✏️' },
|
|
43
|
+
{ label: 'Copy', shortcut: 'Ctrl+C', action: onCopy, icon: '📋' },
|
|
44
|
+
{ label: 'Delete', shortcut: 'Del', action: onDelete, icon: '🗑️', danger: true },
|
|
45
|
+
];
|
|
46
|
+
|
|
47
|
+
// Calculate menu position to avoid overflow
|
|
48
|
+
const getMenuPosition = useCallback(() => {
|
|
49
|
+
const menuWidth = 180;
|
|
50
|
+
const menuHeight = menuItems.length * 36 + 16; // items + padding
|
|
51
|
+
const viewportWidth = window.innerWidth;
|
|
52
|
+
const viewportHeight = window.innerHeight;
|
|
53
|
+
|
|
54
|
+
let left = x;
|
|
55
|
+
let top = y;
|
|
56
|
+
|
|
57
|
+
// Prevent overflow on right
|
|
58
|
+
if (x + menuWidth > viewportWidth) {
|
|
59
|
+
left = viewportWidth - menuWidth - 8;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
// Prevent overflow on bottom
|
|
63
|
+
if (y + menuHeight > viewportHeight) {
|
|
64
|
+
top = viewportHeight - menuHeight - 8;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
return { left, top };
|
|
68
|
+
}, [x, y, menuItems.length]);
|
|
69
|
+
|
|
70
|
+
const position = getMenuPosition();
|
|
71
|
+
|
|
72
|
+
// Handle click outside to close
|
|
73
|
+
useEffect(() => {
|
|
74
|
+
const handleClickOutside = (event: MouseEvent) => {
|
|
75
|
+
if (menuRef.current && !menuRef.current.contains(event.target as Node)) {
|
|
76
|
+
onClose();
|
|
77
|
+
}
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
const handleEscape = (event: KeyboardEvent) => {
|
|
81
|
+
if (event.key === 'Escape') {
|
|
82
|
+
onClose();
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// Add listeners with small delay to avoid immediate close
|
|
87
|
+
const timeoutId = setTimeout(() => {
|
|
88
|
+
document.addEventListener('mousedown', handleClickOutside);
|
|
89
|
+
document.addEventListener('keydown', handleEscape);
|
|
90
|
+
}, 0);
|
|
91
|
+
|
|
92
|
+
return () => {
|
|
93
|
+
clearTimeout(timeoutId);
|
|
94
|
+
document.removeEventListener('mousedown', handleClickOutside);
|
|
95
|
+
document.removeEventListener('keydown', handleEscape);
|
|
96
|
+
};
|
|
97
|
+
}, [onClose]);
|
|
98
|
+
|
|
99
|
+
// Handle keyboard navigation
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
102
|
+
switch (event.key) {
|
|
103
|
+
case 'ArrowDown':
|
|
104
|
+
event.preventDefault();
|
|
105
|
+
setFocusedIndex((prev) => (prev + 1) % menuItems.length);
|
|
106
|
+
break;
|
|
107
|
+
case 'ArrowUp':
|
|
108
|
+
event.preventDefault();
|
|
109
|
+
setFocusedIndex((prev) => (prev - 1 + menuItems.length) % menuItems.length);
|
|
110
|
+
break;
|
|
111
|
+
case 'Enter':
|
|
112
|
+
event.preventDefault();
|
|
113
|
+
menuItems[focusedIndex].action();
|
|
114
|
+
onClose();
|
|
115
|
+
break;
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
document.addEventListener('keydown', handleKeyDown);
|
|
120
|
+
return () => document.removeEventListener('keydown', handleKeyDown);
|
|
121
|
+
}, [focusedIndex, menuItems, onClose]);
|
|
122
|
+
|
|
123
|
+
// Focus the menu on mount
|
|
124
|
+
useEffect(() => {
|
|
125
|
+
menuRef.current?.focus();
|
|
126
|
+
}, []);
|
|
127
|
+
|
|
128
|
+
const handleItemClick = (item: MenuItem) => {
|
|
129
|
+
item.action();
|
|
130
|
+
onClose();
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
return (
|
|
134
|
+
<div
|
|
135
|
+
ref={menuRef}
|
|
136
|
+
tabIndex={-1}
|
|
137
|
+
style={{
|
|
138
|
+
position: 'fixed',
|
|
139
|
+
left: position.left,
|
|
140
|
+
top: position.top,
|
|
141
|
+
backgroundColor: theme.colors.backgroundElevated,
|
|
142
|
+
border: `1px solid ${theme.isDarkMode ? theme.colors.border : '#d1d5db'}`,
|
|
143
|
+
borderRadius: theme.borderRadius.lg,
|
|
144
|
+
boxShadow: theme.isDarkMode
|
|
145
|
+
? `0 4px 12px ${theme.colors.shadow}`
|
|
146
|
+
: '0 4px 16px rgba(0,0,0,0.12), 0 2px 8px rgba(0,0,0,0.08)',
|
|
147
|
+
padding: theme.spacing.xs,
|
|
148
|
+
zIndex: 10000,
|
|
149
|
+
minWidth: '160px',
|
|
150
|
+
outline: 'none',
|
|
151
|
+
}}
|
|
152
|
+
>
|
|
153
|
+
{menuItems.map((item, index) => (
|
|
154
|
+
<div
|
|
155
|
+
key={item.label}
|
|
156
|
+
onClick={() => handleItemClick(item)}
|
|
157
|
+
onMouseEnter={() => setFocusedIndex(index)}
|
|
158
|
+
style={{
|
|
159
|
+
display: 'flex',
|
|
160
|
+
alignItems: 'center',
|
|
161
|
+
justifyContent: 'space-between',
|
|
162
|
+
padding: `${theme.spacing.sm} ${theme.spacing.md}`,
|
|
163
|
+
borderRadius: theme.borderRadius.md,
|
|
164
|
+
cursor: 'pointer',
|
|
165
|
+
backgroundColor: focusedIndex === index
|
|
166
|
+
? theme.colors.backgroundHover
|
|
167
|
+
: 'transparent',
|
|
168
|
+
color: item.danger ? theme.dracula.red : theme.colors.text,
|
|
169
|
+
fontSize: theme.fontSize.sm,
|
|
170
|
+
transition: theme.transitions.fast,
|
|
171
|
+
}}
|
|
172
|
+
>
|
|
173
|
+
<div style={{ display: 'flex', alignItems: 'center', gap: theme.spacing.sm }}>
|
|
174
|
+
<span style={{ fontSize: theme.fontSize.sm }}>{item.icon}</span>
|
|
175
|
+
<span style={{ fontWeight: theme.fontWeight.medium }}>{item.label}</span>
|
|
176
|
+
</div>
|
|
177
|
+
<span
|
|
178
|
+
style={{
|
|
179
|
+
fontSize: theme.fontSize.xs,
|
|
180
|
+
color: theme.colors.textMuted,
|
|
181
|
+
fontFamily: 'monospace',
|
|
182
|
+
}}
|
|
183
|
+
>
|
|
184
|
+
{item.shortcut}
|
|
185
|
+
</span>
|
|
186
|
+
</div>
|
|
187
|
+
))}
|
|
188
|
+
</div>
|
|
189
|
+
);
|
|
190
|
+
};
|
|
191
|
+
|
|
192
|
+
export default NodeContextMenu;
|