Fix
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import React, { useRef, useState, useMemo } from 'react';
|
||||
import { AppConfig, LayoutSplits, Partition } from '../types';
|
||||
// Используем только безопасные, стандартные иконки
|
||||
import { Grid, MousePointer2, Trash2, RotateCcw, X, Plus, Move, Ban } from 'lucide-react';
|
||||
// ИСПОЛЬЗУЕМ ТОЛЬКО БАЗОВЫЕ ИКОНКИ (чтобы не крашилось из-за версий)
|
||||
import { Grid, MousePointer2, Trash2, RotateCcw, X, Plus, Check } from 'lucide-react';
|
||||
|
||||
interface Props {
|
||||
config: AppConfig;
|
||||
@@ -16,40 +16,39 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
const svgRef = useRef<SVGSVGElement>(null);
|
||||
|
||||
const [mode, setMode] = useState<EditMode>('lines');
|
||||
|
||||
// SVG State
|
||||
const [phantomAxis, setPhantomAxis] = useState<Axis | null>(null);
|
||||
const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
|
||||
const [hoveredSplit, setHoveredSplit] = useState<{ axis: Axis; index: number } | null>(null);
|
||||
const [dragging, setDragging] = useState<{ axis: Axis; index: number } | null>(null);
|
||||
const [isButtonHovered, setIsButtonHovered] = useState(false);
|
||||
|
||||
// Редактор ячеек
|
||||
|
||||
// Editor State
|
||||
const [editingCell, setEditingCell] = useState<{ i: number, j: number } | null>(null);
|
||||
|
||||
// --- SAFETY FIRST ---
|
||||
const safeX = splits?.x || [];
|
||||
const safeY = splits?.y || [];
|
||||
// --- ЗАЩИТА ДАННЫХ (ОТ БЕЛОГО ЭКРАНА) ---
|
||||
const safeX = Array.isArray(splits?.x) ? splits.x : [];
|
||||
const safeY = Array.isArray(splits?.y) ? splits.y : [];
|
||||
const safePartitions = splits?.partitions || {};
|
||||
|
||||
// Расчет размеров SVG с защитой от деления на ноль
|
||||
const width = Math.max(1, config.drawer.width || 100);
|
||||
const depth = Math.max(1, config.drawer.depth || 100);
|
||||
const viewBoxW = 1000;
|
||||
const aspectRatio = (config.drawer.depth || 1) / (config.drawer.width || 1);
|
||||
const aspectRatio = depth / width;
|
||||
const viewBoxH = viewBoxW * aspectRatio;
|
||||
|
||||
const sortedX = useMemo(() => [0, ...safeX, 1].sort((a, b) => a - b), [safeX]);
|
||||
const sortedY = useMemo(() => [0, ...safeY, 1].sort((a, b) => a - b), [safeY]);
|
||||
|
||||
// --- Логика перегородок ---
|
||||
const getCurrentPartitions = () => {
|
||||
if (!editingCell) return [];
|
||||
const key = `${editingCell.i}-${editingCell.j}`;
|
||||
return safePartitions[key] || [];
|
||||
};
|
||||
|
||||
// --- ЛОГИКА ПЕРЕГОРОДОК ---
|
||||
const addPartition = (axis: 'x' | 'y') => {
|
||||
if (!editingCell) return;
|
||||
const key = `${editingCell.i}-${editingCell.j}`;
|
||||
const current = safePartitions[key] || [];
|
||||
const newPart: Partition = {
|
||||
id: Date.now().toString(),
|
||||
id: Math.random().toString(36).substr(2, 9),
|
||||
axis,
|
||||
offset: 0.5,
|
||||
height: config.drawer.height,
|
||||
@@ -84,9 +83,12 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
});
|
||||
};
|
||||
|
||||
// --- UI HANDLERS ---
|
||||
const handleGlobalMouseMove = (e: React.MouseEvent) => {
|
||||
if (!svgRef.current) return;
|
||||
const rect = svgRef.current.getBoundingClientRect();
|
||||
if (rect.width === 0 || rect.height === 0) return; // Защита
|
||||
|
||||
const nx = Math.max(0, Math.min(1, (e.clientX - rect.left) / rect.width));
|
||||
const ny = Math.max(0, Math.min(1, (e.clientY - rect.top) / rect.height));
|
||||
|
||||
@@ -100,16 +102,16 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
onChange(newSplits);
|
||||
return;
|
||||
}
|
||||
|
||||
if (isButtonHovered) return;
|
||||
setHoveredSplit(null);
|
||||
|
||||
// Фантомная линия
|
||||
const SNAP = 0.02;
|
||||
const closeToX = safeX.some(val => Math.abs(nx - val) < SNAP);
|
||||
const closeToY = safeY.some(val => Math.abs(ny - val) < SNAP);
|
||||
const closeToEdgeX = nx < SNAP || nx > (1 - SNAP);
|
||||
const closeToEdgeY = ny < SNAP || ny > (1 - SNAP);
|
||||
|
||||
if (!closeToX && !closeToY && !closeToEdgeX && !closeToEdgeY) {
|
||||
|
||||
if (!closeToX && !closeToY && nx > SNAP && nx < 1-SNAP && ny > SNAP && ny < 1-SNAP) {
|
||||
const distRight = 1 - nx; const distBottom = 1 - ny;
|
||||
setPhantomAxis(Math.min(nx, distRight) < Math.min(ny, distBottom) ? 'y' : 'x');
|
||||
} else {
|
||||
@@ -131,6 +133,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
setDragging({ axis: phantomAxis, index: newSplits[phantomAxis].length - 1 });
|
||||
}
|
||||
} else {
|
||||
// Режим ячеек: клик обрабатывается на самих rect'ах, здесь только сброс
|
||||
if (e.target === svgRef.current) setEditingCell(null);
|
||||
}
|
||||
};
|
||||
@@ -146,212 +149,202 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||
|
||||
return (
|
||||
<div className="bg-slate-900 p-6 rounded-xl shadow-lg border border-slate-800 h-full flex flex-col relative">
|
||||
|
||||
{/* HEADER */}
|
||||
<div className="flex justify-between items-center mb-4 z-20">
|
||||
<h2 className="text-xl font-bold flex items-center gap-2 text-primary">
|
||||
<Grid size={24} /> 2. Редактор макета
|
||||
<Grid size={24} /> 2. Редактор
|
||||
</h2>
|
||||
|
||||
<div className="flex bg-slate-800 p-1 rounded-lg border border-slate-700">
|
||||
<button onClick={() => { setMode('lines'); setEditingCell(null); }} className={`flex items-center gap-2 px-4 py-2 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 onClick={() => { setMode('lines'); setEditingCell(null); }} className={`px-4 py-2 rounded-md text-xs font-bold transition-all ${mode === 'lines' ? 'bg-primary text-white shadow' : 'text-gray-400 hover:text-gray-200'}`}>
|
||||
Границы
|
||||
</button>
|
||||
<button onClick={() => setMode('cells')} className={`flex items-center gap-2 px-4 py-2 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 onClick={() => setMode('cells')} className={`px-4 py-2 rounded-md text-xs font-bold transition-all ${mode === 'cells' ? 'bg-primary text-white shadow' : 'text-gray-400 hover:text-gray-200'}`}>
|
||||
Внутри ячеек
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<button onClick={() => onChange({ x: [], y: [], partitions: {} })} className="px-3 py-1 text-xs bg-slate-800 text-red-400 hover:text-red-300 rounded hover:bg-slate-700 border border-slate-700 flex items-center gap-1 transition-colors">
|
||||
<RotateCcw size={14} /> Сбросить
|
||||
<button onClick={() => onChange({ x: [], y: [], partitions: {} })} className="px-3 py-1 text-xs bg-slate-800 text-red-400 hover:text-red-300 rounded border border-slate-700 flex items-center gap-1">
|
||||
<RotateCcw size={14} /> Сброс
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex flex-col h-full select-none relative">
|
||||
<div className="flex-1 bg-slate-800/30 rounded-lg p-6 flex flex-col items-center justify-center relative overflow-hidden border border-slate-700/50">
|
||||
|
||||
{/* Instructions */}
|
||||
<div className="absolute top-4 left-4 z-10 bg-slate-900/90 p-3 rounded-lg backdrop-blur border border-slate-700 shadow-xl max-w-[200px] pointer-events-none">
|
||||
{/* Instruction Overlay */}
|
||||
<div className="absolute top-4 left-4 z-10 bg-slate-900/90 p-3 rounded-lg backdrop-blur border border-slate-700 shadow-xl max-w-[200px] pointer-events-none">
|
||||
<div className="flex items-center gap-2 font-bold text-gray-100 mb-2 text-sm">
|
||||
<MousePointer2 size={14} className="text-primary"/>
|
||||
{mode === 'lines' ? 'Режим: Границы' : 'Режим: Ячейки'}
|
||||
</div>
|
||||
{mode === 'lines' ? (
|
||||
<ul className="space-y-1 text-[10px] text-gray-400 leading-tight">
|
||||
<li><b className="text-blue-400">Клик:</b> Новая линия</li>
|
||||
<li><b className="text-orange-400">Драг:</b> Двигать</li>
|
||||
</ul>
|
||||
) : (
|
||||
<ul className="space-y-1 text-[10px] text-gray-400 leading-tight">
|
||||
<li><b className="text-green-400">Клик по ячейке:</b> Настройка</li>
|
||||
</ul>
|
||||
)}
|
||||
<p className="text-[10px] text-gray-400">
|
||||
{mode === 'lines' ? 'Клик: создать. Драг: двигать. ПКМ: удалить.' : 'Кликни по ячейке, чтобы добавить стенки внутри.'}
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<div className="w-full flex justify-between px-8 mb-1 max-w-[900px]">
|
||||
<span className="text-xs text-slate-500 font-mono">0</span>
|
||||
<span className="text-xs text-slate-500 font-mono">{config.drawer.width} мм</span>
|
||||
</div>
|
||||
{/* Canvas Container */}
|
||||
<div className="relative shadow-2xl bg-[#1e293b] border border-slate-600 rounded-sm overflow-hidden group"
|
||||
style={{
|
||||
width: '100%', maxWidth: '900px',
|
||||
aspectRatio: `${1/aspectRatio}`,
|
||||
cursor: mode === 'lines' ? (dragging ? 'grabbing' : hoveredSplit ? 'grab' : 'crosshair') : 'default',
|
||||
maxHeight: '75vh'
|
||||
}}
|
||||
>
|
||||
<svg ref={svgRef} viewBox={`0 0 ${viewBoxW} ${viewBoxH}`} className="w-full h-full touch-none"
|
||||
onMouseMove={handleGlobalMouseMove} onMouseDown={handleMouseDown} onMouseUp={() => 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>
|
||||
<rect width="100%" height="100%" fill="url(#grid)" />
|
||||
|
||||
<div className="relative flex items-center justify-center w-full h-full">
|
||||
<div className="h-full max-h-[90%] flex flex-col justify-between py-2 mr-2">
|
||||
<span className="text-xs text-slate-500 font-mono">0</span>
|
||||
<span className="text-xs text-slate-500 font-mono" style={{writingMode: 'vertical-rl'}}>{config.drawer.depth} мм</span>
|
||||
</div>
|
||||
{/* Ячейки и перегородки */}
|
||||
{sortedX.slice(0, -1).map((x1, i) => {
|
||||
const x2 = sortedX[i + 1];
|
||||
return sortedY.slice(0, -1).map((y1, j) => {
|
||||
const cellX = x1 * viewBoxW;
|
||||
const cellY = y1 * viewBoxH;
|
||||
const cellW = (x2 - x1) * viewBoxW;
|
||||
const cellH = (y2 - y1) * viewBoxH;
|
||||
const isSelected = editingCell?.i === i && editingCell?.j === j;
|
||||
const parts = safePartitions[`${i}-${j}`] || [];
|
||||
|
||||
<div className="relative shadow-2xl bg-[#1e293b] border border-slate-600 rounded-sm overflow-hidden group"
|
||||
style={{
|
||||
width: '100%', maxWidth: '900px',
|
||||
aspectRatio: `${1/aspectRatio}`,
|
||||
cursor: mode === 'lines' ? (dragging ? 'grabbing' : hoveredSplit ? 'grab' : 'crosshair') : 'default',
|
||||
maxHeight: '75vh'
|
||||
}}
|
||||
>
|
||||
<svg ref={svgRef} viewBox={`0 0 ${viewBoxW} ${viewBoxH}`} className="w-full h-full touch-none"
|
||||
onMouseMove={handleGlobalMouseMove} onMouseDown={handleMouseDown} onMouseUp={() => 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>
|
||||
<rect width="100%" height="100%" fill="url(#grid)" />
|
||||
return (
|
||||
<g key={`cell-${i}-${j}`}>
|
||||
{/* Прямоугольник для клика */}
|
||||
<rect x={cellX} y={cellY} width={cellW} height={cellH}
|
||||
fill={isSelected ? "rgba(59, 130, 246, 0.2)" : "transparent"}
|
||||
stroke={isSelected ? "#3b82f6" : "transparent"} strokeWidth="4"
|
||||
className={mode === 'cells' ? "cursor-pointer hover:fill-white/5 transition-all" : ""}
|
||||
onClick={(e) => { if (mode === 'cells') { e.stopPropagation(); setEditingCell({ i, j }); } }}
|
||||
/>
|
||||
{/* Перегородки */}
|
||||
{parts.map(p => {
|
||||
if (p.axis === 'x') {
|
||||
const px = cellX + (cellW * p.offset);
|
||||
return <line key={p.id} x1={px} y1={cellY} x2={px} y2={cellY + cellH} stroke="#a855f7" strokeWidth="4" className="pointer-events-none"/>;
|
||||
} else {
|
||||
const py = cellY + (cellH * p.offset);
|
||||
return <line key={p.id} x1={cellX} y1={py} x2={cellX + cellW} y2={py} stroke="#a855f7" strokeWidth="4" className="pointer-events-none"/>;
|
||||
}
|
||||
})}
|
||||
</g>
|
||||
);
|
||||
});
|
||||
})}
|
||||
|
||||
{/* --- Ячейки и перегородки --- */}
|
||||
{sortedX.slice(0, -1).map((x1, i) => {
|
||||
const x2 = sortedX[i + 1];
|
||||
return sortedY.slice(0, -1).map((y1, j) => {
|
||||
const cellX = x1 * viewBoxW;
|
||||
const cellY = y1 * viewBoxH;
|
||||
const cellW = (x2 - x1) * viewBoxW;
|
||||
const cellH = (y2 - y1) * viewBoxH;
|
||||
const isSelected = editingCell?.i === i && editingCell?.j === j;
|
||||
const parts = safePartitions[`${i}-${j}`] || [];
|
||||
|
||||
return (
|
||||
<g key={`cell-${i}-${j}`}>
|
||||
<rect x={cellX} y={cellY} width={cellW} height={cellH}
|
||||
fill={isSelected ? "rgba(59, 130, 246, 0.2)" : "transparent"}
|
||||
stroke={isSelected ? "#3b82f6" : "transparent"} strokeWidth="4"
|
||||
className={mode === 'cells' ? "cursor-pointer hover:fill-white/5 transition-all" : ""}
|
||||
onClick={(e) => { if (mode === 'cells') { e.stopPropagation(); setEditingCell({ i, j }); } }}
|
||||
/>
|
||||
{/* Рисуем внутренние стенки */}
|
||||
{parts.map(p => {
|
||||
if (p.axis === 'x') {
|
||||
const px = cellX + (cellW * p.offset);
|
||||
return <line key={p.id} x1={px} y1={cellY} x2={px} y2={cellY + cellH} stroke="#a855f7" strokeWidth="4" />;
|
||||
} else {
|
||||
const py = cellY + (cellH * p.offset);
|
||||
return <line key={p.id} x1={cellX} y1={py} x2={cellX + cellW} y2={py} stroke="#a855f7" strokeWidth="4" />;
|
||||
}
|
||||
})}
|
||||
</g>
|
||||
);
|
||||
});
|
||||
})}
|
||||
|
||||
{/* --- Основные линии сетки (Границы) --- */}
|
||||
{safeX.map((x, i) => (
|
||||
<g key={`x-${i}`} onMouseMove={(e) => { if (mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredSplit({ axis: 'x', index: i }); setPhantomAxis(null); } }}>
|
||||
<line x1={x * viewBoxW} y1={0} x2={x * viewBoxW} y2={viewBoxH} stroke="transparent" strokeWidth="60" className={mode === 'lines' ? "cursor-col-resize" : ""} />
|
||||
<line x1={x * viewBoxW} y1={0} x2={x * viewBoxW} y2={viewBoxH} stroke="#f59e0b" strokeWidth="4" className="pointer-events-none" />
|
||||
{mode === 'lines' && hoveredSplit?.axis === 'x' && hoveredSplit.index === i && (
|
||||
<g transform={`translate(${x * viewBoxW}, 40)`} onClick={(e) => { e.stopPropagation(); removeMainSplit('x', i); }} onMouseEnter={() => setIsButtonHovered(true)} onMouseLeave={() => setIsButtonHovered(false)}>
|
||||
<circle r="14" fill="#ef4444" className="cursor-pointer hover:scale-110 shadow-lg"/>
|
||||
<Trash2 size={14} color="white" x={-7} y={-7} className="pointer-events-none"/>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
))}
|
||||
|
||||
{safeY.map((y, i) => (
|
||||
<g key={`y-${i}`} onMouseMove={(e) => { if (mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredSplit({ axis: 'y', index: i }); setPhantomAxis(null); } }}>
|
||||
<line x1={0} y1={y * viewBoxH} x2={viewBoxW} y2={y * viewBoxH} stroke="transparent" strokeWidth="60" className={mode === 'lines' ? "cursor-row-resize" : ""} />
|
||||
<line x1={0} y1={y * viewBoxH} x2={viewBoxW} y2={y * viewBoxH} stroke="#f59e0b" strokeWidth="4" className="pointer-events-none" />
|
||||
{mode === 'lines' && hoveredSplit?.axis === 'y' && hoveredSplit.index === i && (
|
||||
<g transform={`translate(40, ${y * viewBoxH})`} onClick={(e) => { e.stopPropagation(); removeMainSplit('y', i); }} onMouseEnter={() => setIsButtonHovered(true)} onMouseLeave={() => setIsButtonHovered(false)}>
|
||||
<circle r="14" fill="#ef4444" className="cursor-pointer hover:scale-110 shadow-lg"/>
|
||||
<Trash2 size={14} color="white" x={-7} y={-7} className="pointer-events-none"/>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
))}
|
||||
|
||||
{mode === 'lines' && !hoveredSplit && !dragging && phantomAxis === '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' && !hoveredSplit && !dragging && phantomAxis === '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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* --- ПАНЕЛЬ РЕДАКТОРА (Справа) --- */}
|
||||
{mode === 'cells' && editingCell && (
|
||||
<div className="absolute top-0 right-0 bottom-0 w-80 bg-slate-900 border-l border-slate-700 p-4 shadow-2xl flex flex-col z-30">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<h3 className="text-lg font-bold text-white flex items-center gap-2">
|
||||
<Grid size={18} className="text-primary"/> Редактор ячейки
|
||||
</h3>
|
||||
<button onClick={() => setEditingCell(null)} className="text-gray-400 hover:text-white"><X size={20}/></button>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 mb-6">
|
||||
<button onClick={() => addPartition('x')} className="flex-1 bg-slate-800 hover:bg-slate-700 border border-slate-600 text-white text-xs py-2 px-3 rounded flex items-center justify-center gap-2 transition-colors">
|
||||
<Plus size={14} className="text-green-400"/> + Верт.
|
||||
</button>
|
||||
<button onClick={() => addPartition('y')} className="flex-1 bg-slate-800 hover:bg-slate-700 border border-slate-600 text-white text-xs py-2 px-3 rounded flex items-center justify-center gap-2 transition-colors">
|
||||
<Plus size={14} className="text-green-400"/> + Гориз.
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto space-y-4 pr-1">
|
||||
{getCurrentPartitions().map((p, idx) => (
|
||||
<div key={p.id} className="bg-slate-800 p-3 rounded border border-slate-700 group">
|
||||
<div className="flex justify-between items-center mb-2">
|
||||
<span className="text-xs font-bold text-purple-300">
|
||||
#{idx+1} {p.axis === 'x' ? 'Вертикальная' : 'Горизонтальная'}
|
||||
</span>
|
||||
<button onClick={() => removePartition(p.id)} className="text-red-400 opacity-50 hover:opacity-100"><Trash2 size={14}/></button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<div className="flex justify-between text-[10px] text-gray-400 mb-1">
|
||||
<span>Позиция</span> <span>{(p.offset * 100).toFixed(0)}%</span>
|
||||
</div>
|
||||
<input type="range" min="0.1" max="0.9" step="0.05" value={p.offset}
|
||||
onChange={(e) => updatePartition(p.id, { offset: parseFloat(e.target.value) })}
|
||||
className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-purple-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="flex justify-between text-[10px] text-gray-400 mb-1">
|
||||
<span>Высота</span> <span>{p.height} мм</span>
|
||||
</div>
|
||||
<input type="range" min="5" max={config.drawer.height} step="1" value={p.height}
|
||||
onChange={(e) => updatePartition(p.id, { height: parseFloat(e.target.value) })}
|
||||
className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-blue-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<input type="checkbox" id={`rounded-${p.id}`} checked={p.rounded}
|
||||
onChange={(e) => updatePartition(p.id, { rounded: e.target.checked })}
|
||||
className="rounded bg-slate-700 border-slate-600 text-purple-500 focus:ring-0"
|
||||
/>
|
||||
<label htmlFor={`rounded-${p.id}`} className="text-xs text-gray-300 cursor-pointer select-none">Скругление краев</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{getCurrentPartitions().length === 0 && (
|
||||
<div className="text-center text-gray-500 text-xs py-4 border border-dashed border-slate-700 rounded flex flex-col items-center gap-2">
|
||||
<Ban size={20} />
|
||||
Нет перегородок
|
||||
</div>
|
||||
{/* Линии сетки (X) */}
|
||||
{safeX.map((x, i) => (
|
||||
<g key={`x-${i}`} onMouseMove={(e) => { if (mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredSplit({ axis: 'x', index: i }); setPhantomAxis(null); } }}>
|
||||
<line x1={x * viewBoxW} y1={0} x2={x * viewBoxW} y2={viewBoxH} stroke="transparent" strokeWidth="60" className={mode === 'lines' ? "cursor-col-resize" : ""} />
|
||||
<line x1={x * viewBoxW} y1={0} x2={x * viewBoxW} y2={viewBoxH} stroke="#f59e0b" strokeWidth="4" className="pointer-events-none" />
|
||||
{mode === 'lines' && hoveredSplit?.axis === 'x' && hoveredSplit.index === i && (
|
||||
<g transform={`translate(${x * viewBoxW}, 40)`} onClick={(e) => { e.stopPropagation(); removeMainSplit('x', i); }} onMouseEnter={() => setIsButtonHovered(true)} onMouseLeave={() => setIsButtonHovered(false)}>
|
||||
<circle r="14" fill="#ef4444" className="cursor-pointer"/>
|
||||
<Trash2 size={14} color="white" x={-7} y={-7} className="pointer-events-none"/>
|
||||
</g>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</g>
|
||||
))}
|
||||
|
||||
{/* Линии сетки (Y) */}
|
||||
{safeY.map((y, i) => (
|
||||
<g key={`y-${i}`} onMouseMove={(e) => { if (mode === 'lines' && !dragging) { e.stopPropagation(); setHoveredSplit({ axis: 'y', index: i }); setPhantomAxis(null); } }}>
|
||||
<line x1={0} y1={y * viewBoxH} x2={viewBoxW} y2={y * viewBoxH} stroke="transparent" strokeWidth="60" className={mode === 'lines' ? "cursor-row-resize" : ""} />
|
||||
<line x1={0} y1={y * viewBoxH} x2={viewBoxW} y2={y * viewBoxH} stroke="#f59e0b" strokeWidth="4" className="pointer-events-none" />
|
||||
{mode === 'lines' && hoveredSplit?.axis === 'y' && hoveredSplit.index === i && (
|
||||
<g transform={`translate(40, ${y * viewBoxH})`} onClick={(e) => { e.stopPropagation(); removeMainSplit('y', i); }} onMouseEnter={() => setIsButtonHovered(true)} onMouseLeave={() => setIsButtonHovered(false)}>
|
||||
<circle r="14" fill="#ef4444" className="cursor-pointer"/>
|
||||
<Trash2 size={14} color="white" x={-7} y={-7} className="pointer-events-none"/>
|
||||
</g>
|
||||
)}
|
||||
</g>
|
||||
))}
|
||||
|
||||
{/* Фантомная линия */}
|
||||
{mode === 'lines' && !hoveredSplit && !dragging && phantomAxis === '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' && !hoveredSplit && !dragging && phantomAxis === '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>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* --- ПАНЕЛЬ РЕДАКТОРА (Справа) --- */}
|
||||
{mode === 'cells' && editingCell && (
|
||||
<div className="absolute top-0 right-0 bottom-0 w-80 bg-slate-900 border-l border-slate-700 p-4 shadow-2xl flex flex-col z-30">
|
||||
<div className="flex justify-between items-center mb-6">
|
||||
<h3 className="text-lg font-bold text-white flex items-center gap-2">
|
||||
<Grid size={18} className="text-primary"/> Редактор ячейки
|
||||
</h3>
|
||||
<button onClick={() => setEditingCell(null)} className="text-gray-400 hover:text-white"><X size={20}/></button>
|
||||
</div>
|
||||
|
||||
<div className="flex gap-2 mb-6">
|
||||
<button onClick={() => addPartition('x')} className="flex-1 bg-slate-800 hover:bg-slate-700 border border-slate-600 text-white text-xs py-2 px-3 rounded flex items-center justify-center gap-2 transition-colors">
|
||||
<Plus size={14} className="text-green-400"/> + Верт.
|
||||
</button>
|
||||
<button onClick={() => addPartition('y')} className="flex-1 bg-slate-800 hover:bg-slate-700 border border-slate-600 text-white text-xs py-2 px-3 rounded flex items-center justify-center gap-2 transition-colors">
|
||||
<Plus size={14} className="text-green-400"/> + Гориз.
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div className="flex-1 overflow-y-auto space-y-4 pr-1">
|
||||
{(safePartitions[`${editingCell.i}-${editingCell.j}`] || []).map((p, idx) => (
|
||||
<div key={p.id} className="bg-slate-800 p-3 rounded border border-slate-700 group">
|
||||
<div className="flex justify-between items-center mb-2">
|
||||
<span className="text-xs font-bold text-purple-300">
|
||||
#{idx+1} {p.axis === 'x' ? 'Вертикальная' : 'Горизонтальная'}
|
||||
</span>
|
||||
<button onClick={() => removePartition(p.id)} className="text-red-400 opacity-50 hover:opacity-100"><Trash2 size={14}/></button>
|
||||
</div>
|
||||
|
||||
<div className="space-y-3">
|
||||
<div>
|
||||
<div className="flex justify-between text-[10px] text-gray-400 mb-1">
|
||||
<span>Позиция</span> <span>{(p.offset * 100).toFixed(0)}%</span>
|
||||
</div>
|
||||
<input type="range" min="0.1" max="0.9" step="0.05" value={p.offset}
|
||||
onChange={(e) => updatePartition(p.id, { offset: parseFloat(e.target.value) })}
|
||||
className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-purple-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<div className="flex justify-between text-[10px] text-gray-400 mb-1">
|
||||
<span>Высота</span> <span>{p.height} мм</span>
|
||||
</div>
|
||||
<input type="range" min="5" max={config.drawer.height} step="1" value={p.height}
|
||||
onChange={(e) => updatePartition(p.id, { height: parseFloat(e.target.value) })}
|
||||
className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-blue-500"
|
||||
/>
|
||||
</div>
|
||||
|
||||
<div className="flex items-center gap-2">
|
||||
<input type="checkbox" id={`rounded-${p.id}`} checked={p.rounded}
|
||||
onChange={(e) => updatePartition(p.id, { rounded: e.target.checked })}
|
||||
className="rounded bg-slate-700 border-slate-600 text-purple-500 focus:ring-0"
|
||||
/>
|
||||
<label htmlFor={`rounded-${p.id}`} className="text-xs text-gray-300 cursor-pointer select-none">Скругление краев</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
))}
|
||||
{(safePartitions[`${editingCell.i}-${editingCell.j}`] || []).length === 0 && (
|
||||
<div className="text-center text-gray-500 text-xs py-4 border border-dashed border-slate-700 rounded">
|
||||
Нет перегородок
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button onClick={() => setEditingCell(null)} className="mt-4 w-full bg-primary hover:bg-blue-600 text-white py-2 rounded text-sm font-bold flex items-center justify-center gap-2">
|
||||
<Check size={16}/> Готово
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user