Try add wals and split

This commit is contained in:
Халимов Рустам
2026-01-10 22:51:47 +03:00
parent 9249b424fe
commit 81d9e8e920
3 changed files with 188 additions and 114 deletions

View File

@@ -1,6 +1,6 @@
import React, { useRef, useState, useMemo } from 'react';
import { AppConfig, LayoutSplits, Partition } from '../types';
import { Grid, MousePointer2, RotateCcw, X, Move } from 'lucide-react';
import { Grid, MousePointer2, Trash2, RotateCcw, X, Move, Settings2 } from 'lucide-react';
interface Props {
config: AppConfig;
@@ -18,22 +18,25 @@ type DragTarget =
export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
const svgRef = useRef<SVGSVGElement>(null);
// --- 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);
const [dragging, setDragging] = useState<DragTarget | null>(null);
// Main Grid
// Main Grid Interactions
const [phantomMainAxis, setPhantomMainAxis] = useState<Axis | null>(null);
const [hoveredMainSplit, setHoveredMainSplit] = useState<{ axis: Axis; index: number } | null>(null);
// Partitions
// Partition Interactions
const [hoveredCell, setHoveredCell] = useState<{ i: number; j: number } | null>(null);
const [hoveredPartition, setHoveredPartition] = useState<{ id: string; cellKey: string } | null>(null);
// phantomPartition теперь хранит min/max для T-соединений
const [phantomPartition, setPhantomPartition] = useState<{ axis: Axis; offset: number; min: number; max: number } | null>(null);
const [selectedPartitionId, setSelectedPartitionId] = useState<string | null>(null);
// --- Safe Data ---
// --- DATA ---
const safeX = Array.isArray(splits?.x) ? splits.x : [];
const safeY = Array.isArray(splits?.y) ? splits.y : [];
const safePartitions = splits?.partitions || {};
@@ -48,8 +51,8 @@ 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 ---
const getSelectedPartition = () => {
// --- HELPER: Find Selected Partition ---
const getSelectedPartitionData = () => {
if (!selectedPartitionId) return null;
for (const key in safePartitions) {
const part = safePartitions[key].find(p => p.id === selectedPartitionId);
@@ -57,45 +60,35 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
}
return null;
};
const selectedData = getSelectedPartition();
const selectedData = getSelectedPartitionData();
// --- Logic: Find Sub-Area Bounds ---
// Определяет границы прямоугольника под мышкой внутри ячейки, учитывая существующие стенки
// --- LOGIC: Calculate Boundaries for T-Junctions ---
const getHoveredBoundaries = (lx: number, ly: number, parts: Partition[]) => {
let minX = 0, maxX = 1;
let minY = 0, maxY = 1;
// Сужаем границы на основе существующих стенок
parts.forEach(p => {
const pMin = p.min ?? 0;
const pMax = p.max ?? 1;
if (p.axis === 'x') {
// Вертикальная стенка. Проверяем, пересекаемся ли мы с ней по Y
// (то есть мышь находится в диапазоне min/max этой стенки)
if (ly >= p.min && ly <= p.max) {
// Вертикальная стенка. Если мышь в ее диапазоне по Y...
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 >= p.min && lx <= p.max) {
// Горизонтальная стенка. Если мышь в ее диапазоне по X...
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);
}
}
});
return { minX, maxX, minY, maxY };
};
// --- Actions ---
const removeMainSplit = (axis: Axis, index: number) => {
const newSplits = { ...splits, x: [...safeX], y: [...safeY] };
newSplits[axis] = newSplits[axis].filter((_, i) => i !== index);
onChange(newSplits);
setHoveredMainSplit(null);
setDragging(null);
setIsButtonHovered(false);
};
// --- ACTIONS ---
const createPartition = (i: number, j: number, axis: Axis, offset: number, min: number, max: number) => {
const key = `${i}-${j}`;
const current = safePartitions[key] || [];
@@ -110,6 +103,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
};
onChange({ ...splits, partitions: { ...safePartitions, [key]: [...current, newPart] } });
setSelectedPartitionId(newPart.id);
// ВАЖНО: Не меняем setMode, остаемся в 'cells'
};
const updatePartition = (key: string, id: string, updates: Partial<Partition>) => {
@@ -125,7 +119,15 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
setHoveredPartition(null);
};
// --- Handlers ---
const removeMainSplit = (axis: Axis, index: number) => {
const newSplits = { ...splits, x: [...safeX], y: [...safeY] };
newSplits[axis] = newSplits[axis].filter((_, i) => i !== index);
onChange(newSplits);
setHoveredMainSplit(null);
setDragging(null);
};
// --- MOUSE HANDLERS ---
const handleMouseMove = (e: React.MouseEvent) => {
if (!svgRef.current) return;
const rect = svgRef.current.getBoundingClientRect();
@@ -142,7 +144,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
newSplits[dragging.axis][dragging.index] = val;
onChange(newSplits);
} else {
// Drag Partition
// Dragging Partition
const [iStr, jStr] = dragging.cellKey.split('-');
const i = parseInt(iStr); const j = parseInt(jStr);
const cellX1 = sortedX[i]; const cellX2 = sortedX[i+1];
@@ -154,11 +156,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
} else {
newOffset = (ny - cellY1) / (cellY2 - cellY1);
}
// Ограничиваем перетаскивание пределами "родительской" зоны (чтобы не наехать на соседей)
// Для простоты пока ограничиваем 0.05-0.95 всей ячейки, но в идеале нужно проверять bounds
newOffset = Math.max(0.02, Math.min(0.98, newOffset));
if (!isNaN(newOffset)) {
updatePartition(dragging.cellKey, dragging.id, { offset: newOffset });
}
@@ -177,7 +175,9 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
if (!closeToX && !closeToY) {
const distRight = 1 - nx; const distBottom = 1 - ny;
setPhantomMainAxis(Math.min(nx, distRight) < Math.min(ny, distBottom) ? 'y' : 'x');
} else { setPhantomMainAxis(null); }
} else {
setPhantomMainAxis(null);
}
}
} else {
// Cells Mode
@@ -185,7 +185,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
setPhantomPartition(null);
setHoveredCell(null);
// 1. Находим ячейку
// 1. Find Cell
let cellIdx = null;
for (let i = 0; i < sortedX.length - 1; i++) {
if (nx >= sortedX[i] && nx <= sortedX[i+1]) {
@@ -209,43 +209,38 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
const lx = (nx - cx1) / cw;
const ly = (ny - cy1) / ch;
// 2. Проверяем наведение на существующие (для удаления/выделения)
// 2. Check Existing Partitions
let found = null;
const SNAP = 0.05;
for (const p of parts) {
// Учитываем min/max при наведении
const pMin = p.min ?? 0; const pMax = p.max ?? 1;
if (p.axis === 'x') {
if (ly >= p.min && ly <= p.max && Math.abs(lx - p.offset) < SNAP * (aspectRatio > 1 ? 1 : aspectRatio)) found = p;
if (ly >= pMin && ly <= pMax && Math.abs(lx - p.offset) < SNAP * (aspectRatio > 1 ? 1 : aspectRatio)) found = p;
} else {
if (lx >= p.min && lx <= p.max && Math.abs(ly - p.offset) < SNAP * (aspectRatio < 1 ? 1 : 1/aspectRatio)) found = p;
if (lx >= pMin && lx <= pMax && Math.abs(ly - p.offset) < SNAP * (aspectRatio < 1 ? 1 : 1/aspectRatio)) found = p;
}
}
if (found) {
setHoveredPartition({ id: found.id, cellKey: key });
} else {
// 3. Вычисляем границы для новой фантомной стенки
// 3. Calc Phantom
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;
const distL = lx - bounds.minX; const distR = bounds.maxX - lx;
const distT = ly - bounds.minY; const distB = bounds.maxY - ly;
const minX = Math.min(distL, distR);
const minY = Math.min(distT, distB);
const axis = minX < minY ? 'y' : 'x'; // Перпендикулярно ближайшему краю
// Проверяем, чтобы было место
const axis = minX < minY ? 'y' : 'x';
const width = bounds.maxX - bounds.minX;
const height = bounds.maxY - bounds.minY;
// Проверяем, достаточно ли места
if ((axis === 'y' && height > 0.1) || (axis === 'x' && width > 0.1)) {
const offset = axis === 'x' ? lx : ly;
const min = axis === 'x' ? bounds.minY : bounds.minX;
const max = axis === 'x' ? bounds.maxY : bounds.maxX;
setPhantomPartition({ axis, offset, min, max });
}
}
@@ -268,6 +263,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
setDragging({ type: 'main', axis: phantomMainAxis, index: newSplits[phantomMainAxis].length - 1 });
}
} else {
// MODE: CELLS
if (hoveredPartition) {
const key = hoveredPartition.cellKey;
const parts = safePartitions[key] || [];
@@ -275,7 +271,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
if (part) {
if (e.button === 0) {
setDragging({ type: 'partition', cellKey: key, id: part.id, axis: part.axis });
setSelectedPartitionId(part.id);
setSelectedPartitionId(part.id); // Выбираем для редактирования
} else if (e.button === 2) {
removePartition(key, part.id);
}
@@ -292,19 +288,21 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
);
}
} else {
// Клик в пустоту - снимаем выделение
setSelectedPartitionId(null);
}
}
};
// --- Render ---
const renderCells = () => {
// --- RENDER HELPERS ---
const renderCellsAndPartitions = () => {
const elements = [];
for (let i = 0; i < sortedX.length - 1; i++) {
for (let j = 0; j < sortedY.length - 1; j++) {
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;
@@ -313,65 +311,52 @@ 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);
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"/>
)}
{/* Cell Highlight */}
{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"/>}
{/* Partitions */}
{parts.map(p => {
// Рендер с учетом min/max
const pMin = p.min ?? 0;
const pMax = p.max ?? 1;
const pMin = p.min ?? 0; const pMax = p.max ?? 1;
let lx1, ly1, lx2, ly2;
if (p.axis === 'x') {
const px = cellX + (cellW * p.offset);
lx1 = px;
lx2 = px;
ly1 = cellY + (cellH * pMin);
ly2 = cellY + (cellH * pMax);
lx1 = px; lx2 = px;
ly1 = cellY + (cellH * pMin); ly2 = cellY + (cellH * pMax);
} else {
const py = cellY + (cellH * p.offset);
ly1 = py;
ly2 = py;
lx1 = cellX + (cellW * pMin);
lx2 = cellX + (cellW * pMax);
ly1 = py; ly2 = py;
lx1 = cellX + (cellW * pMin); lx2 = cellX + (cellW * pMax);
}
const isSel = selectedPartitionId === p.id;
const isHov = hoveredPartition?.id === p.id;
const isPSelected = selectedPartitionId === p.id;
const isPHovered = hoveredPartition?.id === p.id;
const stroke = isPSelected ? "#a855f7" : (isPHovered ? "#d8b4fe" : "#7e22ce");
return (
<g key={p.id} onDoubleClick={(e) => { e.stopPropagation(); removePartition(key, p.id); }}>
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} stroke="transparent" strokeWidth="30" />
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} stroke={stroke} strokeWidth={isPSelected ? 6 : 4} strokeLinecap="round" />
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} stroke={isSel ? "#a855f7" : (isHov ? "#d8b4fe" : "#7e22ce")} strokeWidth={isSel ? 6 : 4} strokeLinecap="round" />
</g>
);
})}
{/* Phantom */}
{isHovered && phantomPartition && !hoveredPartition && !dragging && (
<g className="pointer-events-none opacity-60">
{(() => {
// Рендер фантома с учетом min/max
const pMin = phantomPartition.min;
const pMax = phantomPartition.max;
const pMin = phantomPartition.min; const pMax = phantomPartition.max;
let fx1, fy1, fx2, fy2;
if (phantomPartition.axis === 'x') {
const px = cellX + (cellW * phantomPartition.offset);
fx1 = px; fx2 = px;
fy1 = cellY + (cellH * pMin);
fy2 = cellY + (cellH * pMax);
fy1 = cellY + (cellH * pMin); fy2 = cellY + (cellH * pMax);
} else {
const py = cellY + (cellH * phantomPartition.offset);
fy1 = py; fy2 = py;
fx1 = cellX + (cellW * pMin);
fx2 = cellX + (cellW * pMax);
fx1 = cellX + (cellW * pMin); fx2 = cellX + (cellW * pMax);
}
return <line x1={fx1} y1={fy1} x2={fx2} y2={fy2} stroke="#34d399" strokeWidth="3" strokeDasharray="6,6"/>;
})()}
@@ -386,61 +371,138 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
return (
<div className="bg-slate-900 p-4 rounded-xl shadow-lg border border-slate-800 h-full flex flex-col relative overflow-hidden">
{/* TOOLBAR */}
<div className="flex justify-between items-center mb-2 z-20 shrink-0">
<h2 className="text-lg font-bold flex items-center gap-2 text-primary"><Grid size={20} /> 2. Редактор</h2>
<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 BAR */}
<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">2КМ:</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">2КМ:</b> Удалить</span>
</div>
)}
</div>
{/* WORKSPACE */}
<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' ? 'crosshair' : 'default' }}>
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={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)" />
{renderCells()}
{/* CELLS & PARTITIONS */}
{renderCellsAndPartitions()}
{/* 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 */}
{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>
))}
{mode === 'lines' && !hoveredMainSplit && !dragging && phantomMainAxis && (
<line x1={phantomMainAxis === 'x' ? mousePos.x * viewBoxW : 0} y1={phantomMainAxis === 'y' ? mousePos.y * viewBoxH : 0} x2={phantomMainAxis === 'x' ? mousePos.x * viewBoxW : '100%'} y2={phantomMainAxis === 'y' ? mousePos.y * viewBoxH : '100%'} stroke="#3b82f6" strokeWidth="4" strokeDasharray="8,8" className="pointer-events-none opacity-50"/>
)}
{/* MAIN 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>
</div>
</div>
{/* --- SIDEBAR FOR EDITING --- */}
{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">
<Settings2 size={16} className="text-purple-400"/> Настройки стенки
</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><input type="range" min="5" max={config.drawer.height || 100} step="1" value={selectedData.part.height} onChange={(e) => updatePartition(selectedData.key, selectedData.part.id, { height: parseFloat(e.target.value) })} className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-purple-500"/></div>
<div className="flex items-center justify-between"><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>
{/* Height */}
<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>
<input type="range" min="5" max={config.drawer.height || 100} step="1" value={selectedData.part.height}
onChange={(e) => updatePartition(selectedData.key, selectedData.part.id, { height: parseFloat(e.target.value) })}
className="w-full h-1 bg-slate-600 rounded-lg appearance-none cursor-pointer accent-purple-500"
/>
</div>
{/* Rounded */}
<div className="flex items-center justify-between">
<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>
{/* Delete */}
<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>
)}

View File

@@ -99,28 +99,40 @@ export const createBinGeometry = (
geometries.push(wallGeo);
partitions.forEach(p => {
let pWidth = 0, pDepth = 0, pX = 0, pY = 0;
// Поддержка T-junctions: учитываем min и max
const pMin = p.min ?? 0;
const pMax = p.max ?? 1;
const lengthRatio = pMax - pMin;
const midRatio = pMin + (lengthRatio / 2);
let pWidth = 0, pDepth = 0, pX = 0, pY = 0;
if (p.axis === 'x') {
// Вертикальная стенка
// Вертикальная перегородка
pWidth = thickness;
pDepth = lengthRatio * innerDepth;
// Длина зависит от max-min
const length = (pMax - pMin) * innerDepth;
pDepth = length;
pX = (-innerWidth / 2) + (innerWidth * p.offset);
// Центр по Z (Y в 2D) зависит от min/max
// innerTop = -innerDepth/2. Позиция = innerTop + (innerDepth * midRatio)
pY = (-innerDepth / 2) + (innerDepth * midRatio);
// Центр перегородки по Y (Z в 3D) смещен
// Полный диапазон от -innerDepth/2 до +innerDepth/2
// Начало: -innerDepth/2 + (innerDepth * pMin)
// Конец: -innerDepth/2 + (innerDepth * pMax)
// Центр: (Начало + Конец) / 2
const startY = (-innerDepth / 2) + (innerDepth * pMin);
const endY = (-innerDepth / 2) + (innerDepth * pMax);
pY = (startY + endY) / 2;
} else {
// Горизонтальная стенка
pWidth = lengthRatio * innerWidth;
// Горизонтальная перегородка
const length = (pMax - pMin) * innerWidth;
pWidth = length;
pDepth = thickness;
pX = (-innerWidth / 2) + (innerWidth * midRatio);
const startX = (-innerWidth / 2) + (innerWidth * pMin);
const endX = (-innerWidth / 2) + (innerWidth * pMax);
pX = (startX + endX) / 2;
pY = (-innerDepth / 2) + (innerDepth * p.offset);
}

View File

@@ -14,9 +14,9 @@ export interface AppConfig {
export interface Partition {
id: string;
axis: 'x' | 'y';
offset: number; // Положение (0.0 - 1.0)
min: number; // Начало линии (0.0 - 1.0)
max: number; // Конец линии (0.0 - 1.0)
offset: number; // Позиция (0.0 - 1.0)
min: number; // Начало стенки (0.0 - 1.0)
max: number; // Конец стенки (0.0 - 1.0)
height: number;
rounded: boolean;
}