1
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import React, { useRef, useState, useMemo } from 'react';
|
||||
import { AppConfig, LayoutSplits, Partition } from '../types';
|
||||
import { Grid, MousePointer2, Trash2, RotateCcw, X, Move, Settings2, Plus } from 'lucide-react';
|
||||
import { Grid, MousePointer2, Trash2, RotateCcw, X, Move, Settings2 } from 'lucide-react';
|
||||
|
||||
interface Props {
|
||||
config: AppConfig;
|
||||
@@ -18,31 +18,31 @@ type DragTarget =
|
||||
export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
|
||||
// -- STATE --
|
||||
// --- STATE ---
|
||||
const [mode, setMode] = useState<EditMode>('lines');
|
||||
const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
|
||||
const [dragging, setDragging] = useState<DragTarget | null>(null);
|
||||
const [isButtonHovered, setIsButtonHovered] = useState(false);
|
||||
|
||||
// Main Grid Hover
|
||||
// Main Grid
|
||||
const [phantomMainAxis, setPhantomMainAxis] = useState<Axis | null>(null);
|
||||
const [hoveredMainSplit, setHoveredMainSplit] = useState<{ axis: Axis; index: number } | null>(null);
|
||||
|
||||
// Partition Hover
|
||||
// Partitions
|
||||
const [hoveredCell, setHoveredCell] = useState<{ i: number; j: number } | null>(null);
|
||||
const [hoveredPartition, setHoveredPartition] = useState<{ id: string; cellKey: string } | null>(null);
|
||||
const [phantomPartition, setPhantomPartition] = useState<{ axis: Axis; offset: number; min: number; max: number } | null>(null);
|
||||
const [selectedPartitionId, setSelectedPartitionId] = useState<string | null>(null);
|
||||
|
||||
// -- SAFE DATA --
|
||||
// --- SAFE DATA ---
|
||||
const safeX = Array.isArray(splits?.x) ? splits.x : [];
|
||||
const safeY = Array.isArray(splits?.y) ? splits.y : [];
|
||||
const safePartitions = splits?.partitions || {};
|
||||
|
||||
const drawerW = Math.max(1, config.drawer.width || 300);
|
||||
const drawerD = Math.max(1, config.drawer.depth || 400);
|
||||
const wallThick = config.wallThickness || 1.2;
|
||||
const aspectRatio = drawerD / drawerW;
|
||||
const thickness = config.wallThickness || 1.2;
|
||||
|
||||
const viewBoxW = 1000;
|
||||
const viewBoxH = viewBoxW * aspectRatio;
|
||||
@@ -50,7 +50,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const sortedX = useMemo(() => [0, ...safeX, 1].sort((a, b) => a - b), [safeX]);
|
||||
const sortedY = useMemo(() => [0, ...safeY, 1].sort((a, b) => a - b), [safeY]);
|
||||
|
||||
// -- HELPERS --
|
||||
// --- HELPERS ---
|
||||
const getSelectedPartition = () => {
|
||||
if (!selectedPartitionId) return null;
|
||||
for (const key in safePartitions) {
|
||||
@@ -61,48 +61,29 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
};
|
||||
const selectedData = getSelectedPartition();
|
||||
|
||||
// --- ИСПРАВЛЕННЫЙ РАСЧЕТ СОСЕДЕЙ ДЛЯ РАЗМЕРОВ ---
|
||||
// targetOffset: позиция стенки (0..1) по её основной оси
|
||||
// crossPos: позиция центра стенки по перпендикулярной оси (чтобы понять, пересекаются ли они)
|
||||
// axis: ось самой стенки ('x' или 'y')
|
||||
const getNearestNeighbors = (targetOffset: number, crossPos: number, axis: Axis, parts: Partition[]) => {
|
||||
let min = 0;
|
||||
let max = 1;
|
||||
// Поиск ближайших соседей для расчета размеров
|
||||
const getNeighborOffsets = (currentOffset: number, crossPos: number, axis: Axis, parts: Partition[]) => {
|
||||
let minLimit = 0;
|
||||
let maxLimit = 1;
|
||||
|
||||
parts.forEach(p => {
|
||||
const pMin = p.min ?? 0;
|
||||
const pMax = p.max ?? 1;
|
||||
|
||||
if (axis === 'x') {
|
||||
// Мы - вертикальная стенка (X). Ищем другие ВЕРТИКАЛЬНЫЕ стенки слева/справа.
|
||||
if (p.axis === 'x') {
|
||||
// Они должны перекрываться с нами по высоте (Y)
|
||||
// Наша "высота" - это точка crossPos (середина).
|
||||
// Стенка P занимает по Y от pMin до pMax.
|
||||
if (crossPos > pMin && crossPos < pMax) {
|
||||
// Стенка P находится слева от нас?
|
||||
if (p.offset < targetOffset) min = Math.max(min, p.offset);
|
||||
// Стенка P находится справа от нас?
|
||||
if (p.offset > targetOffset) max = Math.min(max, p.offset);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Мы - горизонтальная стенка (Y). Ищем другие ГОРИЗОНТАЛЬНЫЕ стенки сверху/снизу.
|
||||
if (p.axis === 'y') {
|
||||
// Они должны перекрываться с нами по ширине (X)
|
||||
// Наша "ширина" - это точка crossPos (середина).
|
||||
// Стенка P занимает по X от pMin до pMax.
|
||||
if (crossPos > pMin && crossPos < pMax) {
|
||||
if (p.offset < targetOffset) min = Math.max(min, p.offset);
|
||||
if (p.offset > targetOffset) max = Math.min(max, p.offset);
|
||||
}
|
||||
}
|
||||
// Если стенка параллельна нашей, мы ищем, не является ли она барьером
|
||||
if (p.axis === axis) {
|
||||
const pMin = p.min ?? 0;
|
||||
const pMax = p.max ?? 1;
|
||||
|
||||
// Проверяем, пересекаются ли они "в проекции"
|
||||
// crossPos - это середина нашей стенки. Попадает ли она в диапазон соседки?
|
||||
if (crossPos > pMin && crossPos < pMax) {
|
||||
if (p.offset < currentOffset) minLimit = Math.max(minLimit, p.offset);
|
||||
if (p.offset > currentOffset) maxLimit = Math.min(maxLimit, p.offset);
|
||||
}
|
||||
}
|
||||
});
|
||||
return { min, max };
|
||||
return { min: minLimit, max: maxLimit };
|
||||
};
|
||||
|
||||
// Расчет границ для НОВОЙ линии (T-соединения)
|
||||
// Поиск границ для НОВОЙ стенки (чтобы обрезать её до T-соединения)
|
||||
const getHoveredBoundaries = (lx: number, ly: number, parts: Partition[]) => {
|
||||
let minX = 0, maxX = 1;
|
||||
let minY = 0, maxY = 1;
|
||||
@@ -112,11 +93,13 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const pMax = p.max ?? 1;
|
||||
|
||||
if (p.axis === 'x') {
|
||||
// Вертикальная стенка. Блокирует горизонтальное движение?
|
||||
if (ly >= pMin && ly <= pMax) {
|
||||
if (p.offset < lx) minX = Math.max(minX, p.offset);
|
||||
if (p.offset > lx) maxX = Math.min(maxX, p.offset);
|
||||
}
|
||||
} else {
|
||||
// Горизонтальная стенка
|
||||
if (lx >= pMin && lx <= pMax) {
|
||||
if (p.offset < ly) minY = Math.max(minY, p.offset);
|
||||
if (p.offset > ly) maxY = Math.min(maxY, p.offset);
|
||||
@@ -126,13 +109,16 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
return { minX, maxX, minY, maxY };
|
||||
};
|
||||
|
||||
// -- ACTIONS --
|
||||
// --- ACTIONS ---
|
||||
const createPartition = (i: number, j: number, axis: Axis, offset: number, min: number, max: number) => {
|
||||
const key = `${i}-${j}`;
|
||||
const current = safePartitions[key] || [];
|
||||
const newPart: Partition = {
|
||||
id: Math.random().toString(36).substr(2, 9),
|
||||
axis, offset, min, max,
|
||||
axis,
|
||||
offset,
|
||||
min,
|
||||
max,
|
||||
height: config.drawer.height || 80,
|
||||
rounded: false
|
||||
};
|
||||
@@ -161,7 +147,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
setDragging(null);
|
||||
};
|
||||
|
||||
// -- MOUSE HANDLER --
|
||||
// --- MOUSE HANDLER ---
|
||||
const handleMouseMove = (e: React.MouseEvent) => {
|
||||
if (!svgRef.current) return;
|
||||
const rect = svgRef.current.getBoundingClientRect();
|
||||
@@ -184,8 +170,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const cellY1 = sortedY[j]; const cellY2 = sortedY[j+1];
|
||||
|
||||
let newOffset = 0;
|
||||
// Ограничиваем перетаскивание пределами "родительской" зоны
|
||||
// Для T-соединений это сложнее, но пока ограничим ячейкой (0-1)
|
||||
if (dragging.axis === 'x') {
|
||||
newOffset = (nx - cellX1) / (cellX2 - cellX1);
|
||||
} else {
|
||||
@@ -241,6 +225,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const lx = (nx - cx1) / cw;
|
||||
const ly = (ny - cy1) / ch;
|
||||
|
||||
// Check Existing Partitions Hover
|
||||
let found = null;
|
||||
const SNAP = 0.05;
|
||||
for (const p of parts) {
|
||||
@@ -255,6 +240,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
if (found) {
|
||||
setHoveredPartition({ id: found.id, cellKey: key });
|
||||
} else {
|
||||
// Calculate Phantom Partition
|
||||
const bounds = getHoveredBoundaries(lx, ly, parts);
|
||||
const distL = lx - bounds.minX; const distR = bounds.maxX - lx;
|
||||
const distT = ly - bounds.minY; const distB = bounds.maxY - ly;
|
||||
@@ -322,6 +308,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const x1 = sortedX[i]; const x2 = sortedX[i + 1];
|
||||
const y1 = sortedY[j]; const y2 = sortedY[j + 1];
|
||||
|
||||
// !!! FIX: Проверка y2
|
||||
if (y2 === undefined || x2 === undefined) continue;
|
||||
|
||||
const cellX = x1 * viewBoxW; const cellY = y1 * viewBoxH;
|
||||
@@ -330,21 +317,20 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
|
||||
const isHovered = hoveredCell?.i === i && hoveredCell?.j === j && mode === 'cells';
|
||||
const parts = safePartitions[key] || [];
|
||||
const isSelected = parts.some(p => p.id === selectedPartitionId);
|
||||
const isAnySelected = parts.some(p => p.id === selectedPartitionId);
|
||||
|
||||
// Реальные размеры
|
||||
const realW = (x2 - x1) * drawerW;
|
||||
const realD = (y2 - y1) * drawerD;
|
||||
|
||||
// Если перегородок нет - размер по центру
|
||||
// Label if empty
|
||||
if (parts.length === 0) {
|
||||
const labelX = cellX + cellW / 2;
|
||||
const labelY = cellY + cellH / 2;
|
||||
const textW = Math.max(0, realW - thickness).toFixed(0);
|
||||
const textD = Math.max(0, realD - thickness).toFixed(0);
|
||||
const textW = Math.max(0, realW - wallThick).toFixed(0);
|
||||
const textD = Math.max(0, realD - wallThick).toFixed(0);
|
||||
if (cellH > 40 && cellW > 60) {
|
||||
elements.push(
|
||||
<text key={`label-${key}`} x={labelX} y={labelY} textAnchor="middle" dominantBaseline="middle" className="fill-slate-300 font-mono text-[12px] font-bold pointer-events-none select-none opacity-80" style={{ textShadow: '1px 1px 2px rgba(0,0,0,0.8)' }}>
|
||||
<text key={`label-${key}`} x={labelX} y={labelY} textAnchor="middle" dominantBaseline="middle" className="fill-slate-300 font-mono text-[14px] font-bold pointer-events-none select-none opacity-80" style={{ textShadow: '1px 1px 2px rgba(0,0,0,0.8)' }}>
|
||||
{textW} × {textD}
|
||||
</text>
|
||||
);
|
||||
@@ -354,6 +340,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
elements.push(
|
||||
<g key={key}>
|
||||
{isHovered && <rect x={cellX} y={cellY} width={cellW} height={cellH} fill="rgba(16, 185, 129, 0.05)" stroke="#10b981" strokeWidth="2" strokeDasharray="4,4" className="pointer-events-none"/>}
|
||||
{isAnySelected && mode === 'cells' && <rect x={cellX} y={cellY} width={cellW} height={cellH} fill="transparent" stroke="#a855f7" strokeWidth="2" className="pointer-events-none opacity-50"/>}
|
||||
|
||||
{parts.map(p => {
|
||||
const pMin = p.min ?? 0; const pMax = p.max ?? 1;
|
||||
@@ -361,21 +348,17 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
let tx, ty;
|
||||
let dist1 = 0, dist2 = 0;
|
||||
|
||||
// Используем правильные координаты для поиска соседей
|
||||
// axis='x' -> offset - это X, center - это Y
|
||||
// axis='y' -> offset - это Y, center - это X
|
||||
const neighbors = getNearestNeighbors(p.offset, (pMin + pMax)/2, p.axis, parts);
|
||||
|
||||
// Ищем границы для размеров
|
||||
const neighbors = getNeighborOffsets(p.offset, (pMin + pMax)/2, p.axis, parts);
|
||||
|
||||
if (p.axis === 'x') {
|
||||
const px = cellX + (cellW * p.offset);
|
||||
lx1 = px; lx2 = px;
|
||||
ly1 = cellY + (cellH * pMin); ly2 = cellY + (cellH * pMax);
|
||||
|
||||
// Distances Left/Right
|
||||
// p.offset is 0..1. neighbor.min is 0..1.
|
||||
// Distance = (current - neighbor) * width
|
||||
dist1 = (p.offset - neighbors.min) * realW - thickness;
|
||||
dist2 = (neighbors.max - p.offset) * realW - thickness;
|
||||
// Дистанция = (Мой Оффсет - Оффсет Соседа) * Ширину Ячейки - Толщина стенки
|
||||
dist1 = Math.abs((p.offset - neighbors.min) * realW) - wallThick;
|
||||
dist2 = Math.abs((neighbors.max - p.offset) * realW) - wallThick;
|
||||
|
||||
tx = px; ty = (ly1 + ly2) / 2;
|
||||
} else {
|
||||
@@ -383,9 +366,8 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
ly1 = py; ly2 = py;
|
||||
lx1 = cellX + (cellW * pMin); lx2 = cellX + (cellW * pMax);
|
||||
|
||||
// Distances Top/Bottom
|
||||
dist1 = (p.offset - neighbors.min) * realD - thickness;
|
||||
dist2 = (neighbors.max - p.offset) * realD - thickness;
|
||||
dist1 = Math.abs((p.offset - neighbors.min) * realD) - wallThick;
|
||||
dist2 = Math.abs((neighbors.max - p.offset) * realD) - wallThick;
|
||||
|
||||
tx = (lx1 + lx2) / 2; ty = py;
|
||||
}
|
||||
@@ -400,17 +382,17 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} stroke={isSel ? "#a855f7" : (isHov ? "#d8b4fe" : "#7e22ce")} strokeWidth={isSel ? 6 : 4} strokeLinecap="round" />
|
||||
</g>
|
||||
|
||||
{/* Размеры (только если есть место) */}
|
||||
<text x={tx} y={ty} className="pointer-events-none select-none font-mono text-[11px] font-bold fill-white" textAnchor="middle" dominantBaseline="middle" style={{ textShadow: '0px 0px 4px #000' }}>
|
||||
{/* DIMENSIONS */}
|
||||
<text x={tx} y={ty} className="pointer-events-none select-none font-mono text-[12px] font-bold fill-white" textAnchor="middle" dominantBaseline="middle" style={{ textShadow: '0px 0px 3px #000' }}>
|
||||
{p.axis === 'x' ? (
|
||||
<>
|
||||
<tspan dx="-16" fill="#cbd5e1">{Math.max(0, dist1).toFixed(0)}</tspan>
|
||||
<tspan dx="32" fill="#cbd5e1">{Math.max(0, dist2).toFixed(0)}</tspan>
|
||||
<tspan dx="-18" fill="#e2e8f0">{Math.max(0, dist1).toFixed(0)}</tspan>
|
||||
<tspan dx="36" fill="#e2e8f0">{Math.max(0, dist2).toFixed(0)}</tspan>
|
||||
</>
|
||||
) : (
|
||||
<>
|
||||
<tspan x={tx} dy="-10" fill="#cbd5e1">{Math.max(0, dist1).toFixed(0)}</tspan>
|
||||
<tspan x={tx} dy="20" fill="#cbd5e1">{Math.max(0, dist2).toFixed(0)}</tspan>
|
||||
<tspan x={tx} dy="-12" fill="#e2e8f0">{Math.max(0, dist1).toFixed(0)}</tspan>
|
||||
<tspan x={tx} dy="24" fill="#e2e8f0">{Math.max(0, dist2).toFixed(0)}</tspan>
|
||||
</>
|
||||
)}
|
||||
</text>
|
||||
@@ -449,51 +431,82 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
<h2 className="text-lg font-bold flex items-center gap-2 text-primary">
|
||||
<Grid size={20} /> 2. Редактор макета
|
||||
</h2>
|
||||
|
||||
<div className="flex bg-slate-800 p-1 rounded-lg border border-slate-700">
|
||||
<button onClick={() => { setMode('lines'); setSelectedPartitionId(null); }} className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-bold transition-all ${mode === 'lines' ? 'bg-primary text-white shadow' : 'text-gray-400 hover:text-gray-200'}`}><Move size={14}/> Границы</button>
|
||||
<button onClick={() => setMode('cells')} className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-bold transition-all ${mode === 'cells' ? 'bg-primary text-white shadow' : 'text-gray-400 hover:text-gray-200'}`}><Grid size={14}/> Внутри ячеек</button>
|
||||
<button onClick={() => { setMode('lines'); setSelectedPartitionId(null); }} className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-bold transition-all ${mode === 'lines' ? 'bg-primary text-white shadow' : 'text-gray-400 hover:text-gray-200'}`}>
|
||||
<Move size={14}/> Границы
|
||||
</button>
|
||||
<button onClick={() => setMode('cells')} className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-xs font-bold transition-all ${mode === 'cells' ? 'bg-primary text-white shadow' : 'text-gray-400 hover:text-gray-200'}`}>
|
||||
<Grid size={14}/> Внутри ячеек
|
||||
</button>
|
||||
</div>
|
||||
<button onClick={() => onChange({ x: [], y: [], partitions: {} })} className="px-3 py-1.5 text-xs text-red-400 border border-slate-700 rounded hover:bg-slate-800 transition-colors flex items-center gap-1"><RotateCcw size={14} /> Сброс</button>
|
||||
|
||||
<button onClick={() => onChange({ x: [], y: [], partitions: {} })} className="px-3 py-1.5 text-xs text-red-400 border border-slate-700 rounded hover:bg-slate-800 transition-colors flex items-center gap-1">
|
||||
<RotateCcw size={14} /> Сброс
|
||||
</button>
|
||||
</div>
|
||||
|
||||
{/* INFO */}
|
||||
<div className="bg-slate-800/50 rounded-lg px-3 py-2 mb-2 flex items-center gap-3 text-[11px] text-gray-300 border border-slate-700/50 shrink-0">
|
||||
<MousePointer2 size={14} className="text-primary" />
|
||||
{mode === 'lines' ? (
|
||||
<div className="flex gap-3"><span><b className="text-blue-400">ЛКМ:</b> Линия</span><span><b className="text-red-400">ПКМ:</b> Удалить</span></div>
|
||||
<div className="flex gap-3">
|
||||
<span><b className="text-blue-400">ЛКМ:</b> Линия</span>
|
||||
<span><b className="text-red-400">ПКМ:</b> Удалить</span>
|
||||
</div>
|
||||
) : (
|
||||
<div className="flex gap-3"><span><b className="text-green-400">ЛКМ в ячейке:</b> Стенка</span><span><b className="text-purple-400">Драг:</b> Двигать</span><span><b className="text-red-400">2xЛКМ:</b> Удалить</span></div>
|
||||
<div className="flex gap-3">
|
||||
<span><b className="text-green-400">ЛКМ в ячейке:</b> Стенка</span>
|
||||
<span><b className="text-purple-400">Драг:</b> Двигать</span>
|
||||
<span><b className="text-red-400">2xЛКМ:</b> Удалить</span>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
{/* CANVAS */}
|
||||
<div className="flex-1 bg-slate-800/30 rounded-lg flex flex-col items-center justify-center relative overflow-hidden border border-slate-700/50 min-h-0 w-full">
|
||||
<div className="relative w-full h-full flex items-center justify-center p-4">
|
||||
<div className="relative shadow-2xl bg-[#1e293b] border border-slate-600 rounded-sm overflow-hidden"
|
||||
style={{ width: aspectRatio > 1 ? 'auto' : '100%', height: aspectRatio > 1 ? '100%' : 'auto', aspectRatio: `${1/aspectRatio}`, maxHeight: '100%', maxWidth: '100%', cursor: mode === 'lines' ? (dragging ? 'grabbing' : hoveredMainSplit ? 'col-resize' : 'crosshair') : (dragging ? 'grabbing' : hoveredPartition ? 'grab' : hoveredCell ? 'crosshair' : 'default') }}
|
||||
<div
|
||||
className="relative shadow-2xl bg-[#1e293b] border border-slate-600 rounded-sm overflow-hidden"
|
||||
style={{
|
||||
width: aspectRatio > 1 ? 'auto' : '100%',
|
||||
height: aspectRatio > 1 ? '100%' : 'auto',
|
||||
aspectRatio: `${1/aspectRatio}`,
|
||||
maxHeight: '100%', maxWidth: '100%',
|
||||
cursor: mode === 'lines' ? (dragging ? 'grabbing' : hoveredMainSplit ? 'col-resize' : 'crosshair')
|
||||
: (dragging ? 'grabbing' : hoveredPartition ? 'grab' : hoveredCell ? 'crosshair' : 'default'),
|
||||
}}
|
||||
>
|
||||
<svg ref={svgRef} viewBox={`0 0 ${viewBoxW} ${viewBoxH}`} className="w-full h-full touch-none block"
|
||||
preserveAspectRatio="none"
|
||||
onMouseMove={handleGlobalMouseMove} onMouseDown={handleMouseDown} onMouseUp={() => setDragging(null)} onMouseLeave={() => setDragging(null)} onContextMenu={(e) => e.preventDefault()}
|
||||
onMouseMove={handleMouseMove} onMouseDown={handleMouseDown} onMouseUp={() => setDragging(null)} onMouseLeave={() => setDragging(null)} onContextMenu={(e) => e.preventDefault()}
|
||||
>
|
||||
<defs><pattern id="grid" width="50" height="50" patternUnits="userSpaceOnUse"><path d="M 50 0 L 0 0 0 50" fill="none" stroke="rgba(255,255,255,0.03)" strokeWidth="1"/></pattern></defs>
|
||||
<defs>
|
||||
<pattern id="grid" width="50" height="50" patternUnits="userSpaceOnUse">
|
||||
<path d="M 50 0 L 0 0 0 50" fill="none" stroke="rgba(255,255,255,0.03)" strokeWidth="1"/>
|
||||
</pattern>
|
||||
</defs>
|
||||
<rect width="100%" height="100%" fill="url(#grid)" />
|
||||
|
||||
{renderCellsAndPartitions()}
|
||||
{/* Main Grid X */}
|
||||
|
||||
{/* MAIN GRID X */}
|
||||
{safeX.map((x, i) => (
|
||||
<g key={`x-${i}`} onMouseMove={(e) => { if(mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredMainSplit({axis: 'x', index: i}); setPhantomMainAxis(null); }}} onDoubleClick={(e) => { e.stopPropagation(); removeMainSplit('x', i); }}>
|
||||
<line x1={x * viewBoxW} y1="0" x2={x * viewBoxW} y2="100%" stroke="transparent" strokeWidth="40" className={mode === 'lines' ? "cursor-col-resize" : ""} />
|
||||
<line x1={x * viewBoxW} y1="0" x2={x * viewBoxW} y2="100%" stroke={hoveredMainSplit?.axis === 'x' && hoveredMainSplit.index === i ? "#f59e0b" : "#64748b"} strokeWidth={hoveredMainSplit?.axis === 'x' && hoveredMainSplit.index === i ? 6 : 4} className="pointer-events-none" />
|
||||
</g>
|
||||
))}
|
||||
{/* Main Grid Y */}
|
||||
|
||||
{/* MAIN GRID Y */}
|
||||
{safeY.map((y, i) => (
|
||||
<g key={`y-${i}`} onMouseMove={(e) => { if(mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredMainSplit({axis: 'y', index: i}); setPhantomMainAxis(null); }}} onDoubleClick={(e) => { e.stopPropagation(); removeMainSplit('y', i); }}>
|
||||
<line x1="0" y1={y * viewBoxH} x2="100%" y2={y * viewBoxH} stroke="transparent" strokeWidth="40" className={mode === 'lines' ? "cursor-row-resize" : ""} />
|
||||
<line x1="0" y1={y * viewBoxH} x2="100%" y2={y * viewBoxH} stroke={hoveredMainSplit?.axis === 'y' && hoveredMainSplit.index === i ? "#f59e0b" : "#64748b"} strokeWidth={hoveredMainSplit?.axis === 'y' && hoveredMainSplit.index === i ? 6 : 4} className="pointer-events-none" />
|
||||
</g>
|
||||
))}
|
||||
{/* Phantoms */}
|
||||
|
||||
{/* PHANTOMS */}
|
||||
{mode === 'lines' && !hoveredMainSplit && !dragging && phantomMainAxis === 'x' && <line x1={mousePos.x * viewBoxW} y1="0" x2={mousePos.x * viewBoxW} y2="100%" stroke="#3b82f6" strokeWidth="4" strokeDasharray="8,8" className="pointer-events-none opacity-50"/>}
|
||||
{mode === 'lines' && !hoveredMainSplit && !dragging && phantomMainAxis === 'y' && <line x1="0" y1={mousePos.y * viewBoxH} x2="100%" y2={mousePos.y * viewBoxH} stroke="#3b82f6" strokeWidth="4" strokeDasharray="8,8" className="pointer-events-none opacity-50"/>}
|
||||
</svg>
|
||||
@@ -503,7 +516,10 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
{/* SIDEBAR */}
|
||||
{mode === 'cells' && selectedData && (
|
||||
<div className="absolute top-0 right-0 bottom-0 w-72 bg-slate-900 border-l border-slate-700 p-4 shadow-2xl flex flex-col z-30 animate-in slide-in-from-right duration-200">
|
||||
<div className="flex justify-between items-center mb-6"><h3 className="text-sm font-bold text-white flex items-center gap-2">Настройки стенки</h3><button onClick={() => setSelectedPartitionId(null)} className="text-gray-400 hover:text-white"><X size={20}/></button></div>
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<h3 className="text-sm font-bold text-white flex items-center gap-2">Настройки стенки</h3>
|
||||
<button onClick={() => setSelectedPartitionId(null)} className="text-gray-400 hover:text-white"><X size={20}/></button>
|
||||
</div>
|
||||
<div className="bg-slate-800 p-4 rounded border border-slate-700 space-y-6">
|
||||
<div>
|
||||
<div className="flex justify-between text-xs text-gray-300 mb-2"><span>Высота</span> <span className="font-mono bg-slate-900 px-1.5 py-0.5 rounded text-xs">{selectedData.part.height} мм</span></div>
|
||||
@@ -513,7 +529,9 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
<label htmlFor="rounded-check" className="text-xs text-gray-300 cursor-pointer select-none">Скруглить края</label>
|
||||
<input type="checkbox" id="rounded-check" checked={selectedData.part.rounded} onChange={(e) => updatePartition(selectedData.key, selectedData.part.id, { rounded: e.target.checked })} className="w-4 h-4 rounded bg-slate-700 border-slate-600 text-purple-500 focus:ring-0 cursor-pointer"/>
|
||||
</div>
|
||||
<button onClick={() => removePartition(selectedData.key, selectedData.part.id)} className="w-full py-2 bg-red-500/10 hover:bg-red-500/20 text-red-400 border border-red-500/30 rounded text-xs flex items-center justify-center gap-2 transition-colors mt-4"><Trash2 size={14}/> Удалить</button>
|
||||
<button onClick={() => removePartition(selectedData.key, selectedData.part.id)} className="w-full py-2 bg-red-500/10 hover:bg-red-500/20 text-red-400 border border-red-500/30 rounded text-xs flex items-center justify-center gap-2 transition-colors mt-4">
|
||||
<Trash2 size={14}/> Удалить
|
||||
</button>
|
||||
</div>
|
||||
<div className="mt-auto text-[10px] text-gray-500 text-center leading-relaxed">Выделите стенку для настройки.<br/>Двойной клик удаляет её.</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user