update
This commit is contained in:
+98
-38
@@ -1,6 +1,9 @@
|
||||
<!DOCTYPE html>
|
||||
|
||||
<!-- CANVAS v22: per-page instance counter — reserveComponentDisplayNamesFromPages only scans active page, not whole project -->
|
||||
<!-- CANVAS v6: marquee-selection — drag-to-pan, Shift+drag marquee, button at bottom-left above zoom -->
|
||||
<!-- CANVAS v5: inverse-label-scale — instance name only, exponent 1.3 -->
|
||||
<!-- CANVAS v7: marquee button auto-stacked above Controls via flex container (no hardcoded offset) -->
|
||||
<!--
|
||||
Description: Main MXPIC EDA canvas UI with React Flow editing, project pages, routing, layout build controls, and inspector panels.
|
||||
Inside functions: fetchIcon, RotatableNode, PortNode, AnchorNode, RightPanel, findComponentPath, loadProject, handleBasicConnection, buildElementNodesFromYaml.
|
||||
@@ -1509,6 +1512,39 @@ Organization : OptiHK Limited
|
||||
display: none;
|
||||
}
|
||||
|
||||
.react-flow__controls-button.marquee-active {
|
||||
background: var(--accent);
|
||||
color: #05080f;
|
||||
box-shadow: 0 0 10px rgba(69, 214, 200, 0.45);
|
||||
}
|
||||
|
||||
.marquee-btn-normal {
|
||||
background: #0b1320;
|
||||
color: #f5f7fa;
|
||||
border-color: rgba(163, 186, 212, 0.16);
|
||||
}
|
||||
|
||||
.marquee-btn-normal:hover {
|
||||
background: #101a29;
|
||||
color: #f5f7fa;
|
||||
}
|
||||
|
||||
body.light-mode .react-flow__controls-button.marquee-active {
|
||||
color: #ffffff;
|
||||
box-shadow: 0 0 10px rgba(8, 127, 115, 0.45);
|
||||
}
|
||||
|
||||
body.light-mode .marquee-btn-normal {
|
||||
background: #ffffff;
|
||||
color: #122033;
|
||||
border-color: rgba(30, 48, 69, 0.18);
|
||||
}
|
||||
|
||||
body.light-mode .marquee-btn-normal:hover {
|
||||
background: #f0f4f8;
|
||||
color: #122033;
|
||||
}
|
||||
|
||||
body.light-mode .port-name-label {
|
||||
background: var(--port-label-bg);
|
||||
border-color: var(--floating-label-border);
|
||||
@@ -1793,6 +1829,8 @@ Organization : OptiHK Limited
|
||||
};
|
||||
|
||||
const iconPromiseCache = {};
|
||||
// Global fetch guard for component data — survives component remounts
|
||||
const globalComponentFetchGuard = {};
|
||||
// Loads and caches category icons so repeated library renders do not refetch the same image.
|
||||
function fetchIcon(category) {
|
||||
if (!iconPromiseCache[category]) {
|
||||
@@ -1891,6 +1929,8 @@ Organization : OptiHK Limited
|
||||
// Renders PDK and primitive component instances with transformed ports and selection styling.
|
||||
const RotatableNode = memo(({ id, data, selected }) => {
|
||||
const updateNodeInternals = useUpdateNodeInternals();
|
||||
const zoom = useStore(state => state.transform[2]);
|
||||
const inverseScale = zoom ? Math.max(1, Math.pow(1 / zoom, 1.3)) : 1;
|
||||
const prevTransformRef = useRef(`${data.rotation || 0}:${data.flip ? 1 : 0}:${data.flop ? 1 : 0}`);
|
||||
const updateNodeInternalsRef = useRef(updateNodeInternals);
|
||||
|
||||
@@ -2003,7 +2043,7 @@ Organization : OptiHK Limited
|
||||
className="component-node-shell"
|
||||
style={{ width: visualSize.width, minWidth: visualSize.width, maxWidth: visualSize.width, minHeight: visualSize.height }}
|
||||
>
|
||||
<div className="component-floating-label" title={data.componentDisplayName} style={hasTopHandles ? { bottom: 'calc(100% + 27px)' } : undefined}>
|
||||
<div className="component-floating-label" title={data.componentDisplayName} style={{ ...(hasTopHandles ? { bottom: 'calc(100% + 27px)' } : {}), transform: `translateX(-50%) scale(${inverseScale})`, transformOrigin: 'center bottom' }}>
|
||||
<strong>{data.componentDisplayName}</strong>
|
||||
</div>
|
||||
<div
|
||||
@@ -2120,6 +2160,8 @@ Organization : OptiHK Limited
|
||||
};
|
||||
|
||||
const PortNode = ({ id, data, selected }) => {
|
||||
const zoom = useStore(state => state.transform[2]);
|
||||
const inverseScale = zoom ? Math.max(1, Math.pow(1 / zoom, 1.3)) : 1;
|
||||
const angle = data.angle ?? 0;
|
||||
const canvasAngle = -Number(angle || 0);
|
||||
const portDisplayName = data.portName || data.componentDisplayName || data.label || 'port';
|
||||
@@ -2172,7 +2214,7 @@ Organization : OptiHK Limited
|
||||
background: 'rgba(239,68,68,0.08)',
|
||||
boxShadow: 'none'
|
||||
}}>
|
||||
<div className="component-floating-label" title={portDisplayName}>
|
||||
<div className="component-floating-label" title={portDisplayName} style={{ transform: `translateX(-50%) scale(${inverseScale})`, transformOrigin: 'center bottom' }}>
|
||||
<strong>{portDisplayName}</strong>
|
||||
</div>
|
||||
{portHandles.map((portHandle) => (
|
||||
@@ -2203,6 +2245,8 @@ Organization : OptiHK Limited
|
||||
// Renders anchor elements with split visual handles while keeping paired layout ports connected.
|
||||
const AnchorNode = memo(({ id, data, selected }) => {
|
||||
const updateNodeInternals = useUpdateNodeInternals();
|
||||
const zoom = useStore(state => state.transform[2]);
|
||||
const inverseScale = zoom ? Math.max(1, Math.pow(1 / zoom, 1.3)) : 1;
|
||||
const anchorRotation = data.rotation || 0;
|
||||
const anchorVisualRotation = -Number(anchorRotation || 0);
|
||||
const anchorDisplayName = data.componentDisplayName || data.label || 'anchor';
|
||||
@@ -2267,7 +2311,7 @@ Organization : OptiHK Limited
|
||||
return (
|
||||
<>
|
||||
<div className="anchor-node-shell" style={{ width: elementSize.width, height: elementSize.height }}>
|
||||
<div className="component-floating-label" title={anchorDisplayName}>
|
||||
<div className="component-floating-label" title={anchorDisplayName} style={{ transform: `translateX(-50%) scale(${inverseScale})`, transformOrigin: 'center bottom' }}>
|
||||
<strong>{anchorDisplayName}</strong>
|
||||
</div>
|
||||
<div className="anchor-visual-body" style={{
|
||||
@@ -2707,7 +2751,7 @@ Organization : OptiHK Limited
|
||||
setValue(page.name);
|
||||
}, [page.name, page.id]);
|
||||
|
||||
if (!active || page.type === 'project') {
|
||||
if (!active) {
|
||||
return <span>{page.name}</span>;
|
||||
}
|
||||
|
||||
@@ -3326,50 +3370,46 @@ Organization : OptiHK Limited
|
||||
|
||||
useEffect(() => {
|
||||
const nodeId = selectedNode?.id;
|
||||
if (!nodeId || isMultiNodeSelection) {
|
||||
setComponentData(null);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
const compName = selectedNode?.data?.componentName;
|
||||
const selectedIsComposite = selectedNode?.data?.type === 'composite' || compositeNames.includes(compName);
|
||||
if (selectedNode?.data?.elementType || selectedIsComposite || isBasicComponent(compName)) {
|
||||
const fetchKey = (nodeId && compName) ? `${nodeId}:${compName}` : null;
|
||||
|
||||
// Restore from global cache if previously fetched
|
||||
if (fetchKey && globalComponentFetchGuard[fetchKey]) {
|
||||
setComponentData(globalComponentFetchGuard[fetchKey]);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
|
||||
// Selection cleared or not a fetchable component — clear data
|
||||
if (!nodeId || isMultiNodeSelection || !compName ||
|
||||
selectedNode?.data?.elementType ||
|
||||
selectedNode?.data?.type === 'composite' ||
|
||||
compositeNames.includes(compName) ||
|
||||
isBasicComponent(compName) ||
|
||||
isForgeComponent(compName)) {
|
||||
setComponentData(null);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (!compName) {
|
||||
setComponentData(null);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (isForgeComponent(compName)) {
|
||||
setComponentData(null);
|
||||
setLoading(false);
|
||||
return;
|
||||
}
|
||||
if (componentData && componentData.name === compName && componentData.nodeId === nodeId) return;
|
||||
|
||||
setLoading(true);
|
||||
fetch(`/api/component/${encodeURIComponent(compName)}?project=${encodeURIComponent(projectName || '')}`)
|
||||
const controller = new AbortController();
|
||||
fetch(`/api/component/${encodeURIComponent(compName)}?project=${encodeURIComponent(projectName || '')}`, { signal: controller.signal })
|
||||
.then(r => {
|
||||
if (!r.ok) throw new Error('Component metadata not found');
|
||||
return r.json();
|
||||
})
|
||||
.then(data => {
|
||||
setComponentData({ ...data, nodeId: nodeId, componentDisplayName: selectedNode.data.componentDisplayName || data.name });
|
||||
onUpdateNode(nodeId, {
|
||||
data: {
|
||||
ports: data.ports || {},
|
||||
boxSize: normalizeBoxSize(data),
|
||||
foundry: data.foundry || '',
|
||||
process: data.process || ''
|
||||
}
|
||||
});
|
||||
const result = { ...data, nodeId: nodeId, componentDisplayName: selectedNode.data.componentDisplayName || data.name };
|
||||
globalComponentFetchGuard[fetchKey] = result;
|
||||
setComponentData(result);
|
||||
setLoading(false);
|
||||
})
|
||||
.catch(() => setLoading(false));
|
||||
}, [selectedNode?.id, selectedNode?.data?.componentName, selectedNode?.data?.componentDisplayName, isMultiNodeSelection, compositeNames, projectName, onUpdateNode]);
|
||||
.catch(err => {
|
||||
if (err.name !== 'AbortError') setLoading(false);
|
||||
});
|
||||
return () => controller.abort();
|
||||
}, [selectedNode?.id, selectedNode?.data?.componentName, selectedNode?.data?.componentDisplayName, isMultiNodeSelection, projectName]);
|
||||
|
||||
useEffect(() => {
|
||||
if (editingTransformField) return;
|
||||
@@ -4143,7 +4183,7 @@ Organization : OptiHK Limited
|
||||
))}
|
||||
</ul>
|
||||
|
||||
<p style={{ color: 'var(--text-main)', fontWeight: '500', marginBottom: '4px' }}>Preview:</p>
|
||||
{/* <p style={{ color: 'var(--text-main)', fontWeight: '500', marginBottom: '4px' }}>Preview:</p>
|
||||
<div style={{
|
||||
border: '1px solid var(--border)', width: '100%', height: 100,
|
||||
display: 'flex', alignItems: 'center', justifyContent: 'center',
|
||||
@@ -4161,7 +4201,7 @@ Organization : OptiHK Limited
|
||||
e.currentTarget.parentElement.innerHTML = '<span style="color:var(--text-muted)">No preview</span>';
|
||||
}}
|
||||
/>
|
||||
</div>
|
||||
</div> */}
|
||||
</>
|
||||
) : (
|
||||
<p style={{ color: 'var(--text-muted)' }}>No data available</p>
|
||||
@@ -4643,6 +4683,7 @@ Organization : OptiHK Limited
|
||||
const [projectCompositeMap, setProjectCompositeMap] = useState({});
|
||||
const [standaloneComposites, setStandaloneComposites] = useState([]);
|
||||
const [compositeTrees, setCompositeTrees] = useState({});
|
||||
const [marqueeMode, setMarqueeMode] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
document.body.classList.toggle('light-mode', themeMode === 'light');
|
||||
@@ -6717,6 +6758,11 @@ Organization : OptiHK Limited
|
||||
};
|
||||
}, [dragging]);
|
||||
|
||||
// Toggle marquee selection mode (drag to select, Shift+drag to pan).
|
||||
const toggleMarqueeMode = useCallback(() => {
|
||||
setMarqueeMode(prev => !prev);
|
||||
}, []);
|
||||
|
||||
// Toggle snap-to-grid movement in the editor.
|
||||
const toggleGridSnap = useCallback(() => {
|
||||
setGridSnap(prev => !prev);
|
||||
@@ -7626,12 +7672,26 @@ ${bundlesBlock}`;
|
||||
maxZoom={4}
|
||||
defaultViewport={{ x: 80, y: 80, zoom: 0.12 }}
|
||||
onMoveEnd={handleCanvasViewportMoveEnd}
|
||||
panOnDrag={false}
|
||||
selectionOnDrag={true}
|
||||
panOnDrag={!marqueeMode}
|
||||
selectionOnDrag={marqueeMode}
|
||||
selectionMode={FULL_SELECTION_MODE}
|
||||
multiSelectionKeyCode="Shift"
|
||||
selectionKeyCode="Shift"
|
||||
panActivationKeyCode="Shift"
|
||||
deleteKeyCode={['Backspace', 'Delete']}
|
||||
>
|
||||
<div style={{ position: 'absolute', bottom: 140, left: 30, zIndex: 5 }}>
|
||||
<button
|
||||
onClick={toggleMarqueeMode}
|
||||
className={`react-flow__controls-button ${marqueeMode ? 'marquee-active' : 'marquee-btn-normal'}`}
|
||||
style={{ borderBottom: 'none', borderRadius: '4px 4px 0 0' }}
|
||||
title={marqueeMode ? 'Marquee Selection: drag to select, Shift+drag to pan' : 'Pan Mode: drag to pan, Shift+drag to marquee select'}
|
||||
>
|
||||
<svg width="20" height="18" viewBox="0 0 20 18" fill="none">
|
||||
<rect x="1.5" y="0.5" width="17" height="17" rx="1.5" stroke="currentColor" strokeWidth="1.5" strokeDasharray="3.6 1.8" />
|
||||
</svg>
|
||||
</button>
|
||||
</div>
|
||||
<Controls style={{ bottom: 15, left: 15 }} />
|
||||
<Background color="#334155" gap={10} size={1} />
|
||||
</ReactFlow>
|
||||
|
||||
Reference in New Issue
Block a user