Add size
This commit is contained in:
+146
-130
@@ -1,7 +1,6 @@
|
|||||||
import React, { useRef, useState, useMemo } from 'react';
|
import React, { useRef, useState, useMemo } from 'react';
|
||||||
import { AppConfig, LayoutSplits, Partition } from '../types';
|
import { AppConfig, LayoutSplits, Partition } from '../types';
|
||||||
// Добавил Settings, Move и прочее в импорты
|
import { Grid, MousePointer2, Trash2, RotateCcw, X, Move, Settings2, Plus } from 'lucide-react';
|
||||||
import { Grid, MousePointer2, Trash2, RotateCcw, X, Move, Settings, Plus } from 'lucide-react';
|
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
config: AppConfig;
|
config: AppConfig;
|
||||||
@@ -43,6 +42,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const drawerW = Math.max(1, config.drawer.width || 300);
|
const drawerW = Math.max(1, config.drawer.width || 300);
|
||||||
const drawerD = Math.max(1, config.drawer.depth || 400);
|
const drawerD = Math.max(1, config.drawer.depth || 400);
|
||||||
const aspectRatio = drawerD / drawerW;
|
const aspectRatio = drawerD / drawerW;
|
||||||
|
const thickness = config.wallThickness || 1.2;
|
||||||
|
|
||||||
const viewBoxW = 1000;
|
const viewBoxW = 1000;
|
||||||
const viewBoxH = viewBoxW * aspectRatio;
|
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 sortedX = useMemo(() => [0, ...safeX, 1].sort((a, b) => a - b), [safeX]);
|
||||||
const sortedY = useMemo(() => [0, ...safeY, 1].sort((a, b) => a - b), [safeY]);
|
const sortedY = useMemo(() => [0, ...safeY, 1].sort((a, b) => a - b), [safeY]);
|
||||||
|
|
||||||
// -- HELPER: Get Selected --
|
// -- HELPERS --
|
||||||
const getSelectedPartition = () => {
|
const getSelectedPartition = () => {
|
||||||
if (!selectedPartitionId) return null;
|
if (!selectedPartitionId) return null;
|
||||||
for (const key in safePartitions) {
|
for (const key in safePartitions) {
|
||||||
@@ -61,8 +61,45 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
};
|
};
|
||||||
const selectedData = getSelectedPartition();
|
const selectedData = getSelectedPartition();
|
||||||
|
|
||||||
// -- LOGIC: T-Junction Limits --
|
// Найти ближайшие границы для перегородки (или точки)
|
||||||
// Находит ближайшие стенки, чтобы ограничить новую перегородку
|
const getNearestNeighbors = (lx: number, ly: number, axis: Axis, parts: Partition[]) => {
|
||||||
|
let min = 0;
|
||||||
|
let max = 1;
|
||||||
|
|
||||||
|
parts.forEach(p => {
|
||||||
|
// Игнорируем саму себя, если это проверка для существующей стенки (но здесь мы передаем lx/ly точки)
|
||||||
|
|
||||||
|
const pMin = p.min ?? 0;
|
||||||
|
const pMax = p.max ?? 1;
|
||||||
|
|
||||||
|
// Если мы ищем границы по X (для вертикальной стенки или пространства слева/справа)
|
||||||
|
// То нас интересуют другие ВЕРТИКАЛЬНЫЕ стенки (axis === 'x'), которые перекрывают нас по Y
|
||||||
|
if (axis === 'x') {
|
||||||
|
if (p.axis === 'x') {
|
||||||
|
// Перекрываются ли диапазоны высоты?
|
||||||
|
// ly для точки - это просто координата. Для стенки это min-max.
|
||||||
|
// Здесь мы ищем границы для точки (lx, ly).
|
||||||
|
// Стенка P идет от pMin до pMax по Y.
|
||||||
|
if (ly > pMin && ly < pMax) {
|
||||||
|
if (p.offset < lx) min = Math.max(min, p.offset);
|
||||||
|
if (p.offset > lx) max = Math.min(max, p.offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// Ищем границы по Y (для горизонтальной стенки)
|
||||||
|
// Нас интересуют ГОРИЗОНТАЛЬНЫЕ стенки
|
||||||
|
if (p.axis === 'y') {
|
||||||
|
if (lx > pMin && lx < pMax) {
|
||||||
|
if (p.offset < ly) min = Math.max(min, p.offset);
|
||||||
|
if (p.offset > ly) max = Math.min(max, p.offset);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
return { min, max };
|
||||||
|
};
|
||||||
|
|
||||||
|
// Расчет границ для НОВОЙ линии (перпендикулярной)
|
||||||
const getHoveredBoundaries = (lx: number, ly: number, parts: Partition[]) => {
|
const getHoveredBoundaries = (lx: number, ly: number, parts: Partition[]) => {
|
||||||
let minX = 0, maxX = 1;
|
let minX = 0, maxX = 1;
|
||||||
let minY = 0, maxY = 1;
|
let minY = 0, maxY = 1;
|
||||||
@@ -72,15 +109,11 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const pMax = p.max ?? 1;
|
const pMax = p.max ?? 1;
|
||||||
|
|
||||||
if (p.axis === 'x') {
|
if (p.axis === 'x') {
|
||||||
// Вертикальная стенка (x=offset, y=min..max)
|
|
||||||
// Проверяем, находится ли мышь в её диапазоне по Y
|
|
||||||
if (ly >= pMin && ly <= pMax) {
|
if (ly >= pMin && ly <= pMax) {
|
||||||
if (p.offset < lx) minX = Math.max(minX, p.offset);
|
if (p.offset < lx) minX = Math.max(minX, p.offset);
|
||||||
if (p.offset > lx) maxX = Math.min(maxX, p.offset);
|
if (p.offset > lx) maxX = Math.min(maxX, p.offset);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Горизонтальная стенка (y=offset, x=min..max)
|
|
||||||
// Проверяем, находится ли мышь в её диапазоне по X
|
|
||||||
if (lx >= pMin && lx <= pMax) {
|
if (lx >= pMin && lx <= pMax) {
|
||||||
if (p.offset < ly) minY = Math.max(minY, p.offset);
|
if (p.offset < ly) minY = Math.max(minY, p.offset);
|
||||||
if (p.offset > ly) maxY = Math.min(maxY, p.offset);
|
if (p.offset > ly) maxY = Math.min(maxY, p.offset);
|
||||||
@@ -96,14 +129,10 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const current = safePartitions[key] || [];
|
const current = safePartitions[key] || [];
|
||||||
const newPart: Partition = {
|
const newPart: Partition = {
|
||||||
id: Math.random().toString(36).substr(2, 9),
|
id: Math.random().toString(36).substr(2, 9),
|
||||||
axis,
|
axis, offset, min, max,
|
||||||
offset,
|
|
||||||
min,
|
|
||||||
max,
|
|
||||||
height: config.drawer.height || 80,
|
height: config.drawer.height || 80,
|
||||||
rounded: false
|
rounded: false
|
||||||
};
|
};
|
||||||
// Обновляем стейт, но НЕ сбрасываем mode, так как ErrorBoundary теперь снаружи
|
|
||||||
onChange({ ...splits, partitions: { ...safePartitions, [key]: [...current, newPart] } });
|
onChange({ ...splits, partitions: { ...safePartitions, [key]: [...current, newPart] } });
|
||||||
setSelectedPartitionId(newPart.id);
|
setSelectedPartitionId(newPart.id);
|
||||||
};
|
};
|
||||||
@@ -152,16 +181,15 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const cellY1 = sortedY[j]; const cellY2 = sortedY[j+1];
|
const cellY1 = sortedY[j]; const cellY2 = sortedY[j+1];
|
||||||
|
|
||||||
let newOffset = 0;
|
let newOffset = 0;
|
||||||
|
// Текущие границы перетаскиваемой стенки (чтобы не выехать за пределы соседей)
|
||||||
|
// Для простоты пока используем границы ячейки (0-1), так как сложный пересчет соседей в реалтайме - это дорого
|
||||||
|
// Но визуально мы ограничим 2-98%
|
||||||
if (dragging.axis === 'x') {
|
if (dragging.axis === 'x') {
|
||||||
newOffset = (nx - cellX1) / (cellX2 - cellX1);
|
newOffset = (nx - cellX1) / (cellX2 - cellX1);
|
||||||
} else {
|
} else {
|
||||||
newOffset = (ny - cellY1) / (cellY2 - cellY1);
|
newOffset = (ny - cellY1) / (cellY2 - cellY1);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Ограничиваем в пределах "родительской" зоны (0-1) внутри ячейки
|
|
||||||
// В идеале тут тоже надо проверять коллизии, но пока просто границы ячейки
|
|
||||||
newOffset = Math.max(0.02, Math.min(0.98, newOffset));
|
newOffset = Math.max(0.02, Math.min(0.98, newOffset));
|
||||||
|
|
||||||
if (!isNaN(newOffset)) {
|
if (!isNaN(newOffset)) {
|
||||||
updatePartition(dragging.cellKey, dragging.id, { offset: newOffset });
|
updatePartition(dragging.cellKey, dragging.id, { offset: newOffset });
|
||||||
}
|
}
|
||||||
@@ -188,7 +216,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
setPhantomPartition(null);
|
setPhantomPartition(null);
|
||||||
setHoveredCell(null);
|
setHoveredCell(null);
|
||||||
|
|
||||||
// 1. Находим ячейку
|
|
||||||
let cellIdx = null;
|
let cellIdx = null;
|
||||||
for (let i = 0; i < sortedX.length - 1; i++) {
|
for (let i = 0; i < sortedX.length - 1; i++) {
|
||||||
if (nx >= sortedX[i] && nx <= sortedX[i+1]) {
|
if (nx >= sortedX[i] && nx <= sortedX[i+1]) {
|
||||||
@@ -212,7 +239,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const lx = (nx - cx1) / cw;
|
const lx = (nx - cx1) / cw;
|
||||||
const ly = (ny - cy1) / ch;
|
const ly = (ny - cy1) / ch;
|
||||||
|
|
||||||
// 2. Проверяем наведение на существующие (для удаления/выделения)
|
|
||||||
let found = null;
|
let found = null;
|
||||||
const SNAP = 0.05;
|
const SNAP = 0.05;
|
||||||
for (const p of parts) {
|
for (const p of parts) {
|
||||||
@@ -227,21 +253,14 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
if (found) {
|
if (found) {
|
||||||
setHoveredPartition({ id: found.id, cellKey: key });
|
setHoveredPartition({ id: found.id, cellKey: key });
|
||||||
} else {
|
} else {
|
||||||
// 3. Вычисляем T-образные границы
|
|
||||||
const bounds = getHoveredBoundaries(lx, ly, parts);
|
const bounds = getHoveredBoundaries(lx, ly, parts);
|
||||||
|
const distL = lx - bounds.minX; const distR = bounds.maxX - lx;
|
||||||
const distL = lx - bounds.minX;
|
const distT = ly - bounds.minY; const distB = bounds.maxY - ly;
|
||||||
const distR = bounds.maxX - lx;
|
|
||||||
const distT = ly - bounds.minY;
|
|
||||||
const distB = bounds.maxY - ly;
|
|
||||||
|
|
||||||
const minX = Math.min(distL, distR);
|
const minX = Math.min(distL, distR);
|
||||||
const minY = Math.min(distT, distB);
|
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 width = bounds.maxX - bounds.minX;
|
||||||
const height = bounds.maxY - bounds.minY;
|
const height = bounds.maxY - bounds.minY;
|
||||||
|
|
||||||
@@ -285,14 +304,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
}
|
}
|
||||||
} else if (hoveredCell && phantomPartition) {
|
} else if (hoveredCell && phantomPartition) {
|
||||||
if (e.button === 0) {
|
if (e.button === 0) {
|
||||||
createPartition(
|
createPartition(hoveredCell.i, hoveredCell.j, phantomPartition.axis, phantomPartition.offset, phantomPartition.min, phantomPartition.max);
|
||||||
hoveredCell.i,
|
|
||||||
hoveredCell.j,
|
|
||||||
phantomPartition.axis,
|
|
||||||
phantomPartition.offset,
|
|
||||||
phantomPartition.min,
|
|
||||||
phantomPartition.max
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
setSelectedPartitionId(null);
|
setSelectedPartitionId(null);
|
||||||
@@ -316,34 +328,99 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
|
|
||||||
const isHovered = hoveredCell?.i === i && hoveredCell?.j === j && mode === 'cells';
|
const isHovered = hoveredCell?.i === i && hoveredCell?.j === j && mode === 'cells';
|
||||||
const parts = safePartitions[key] || [];
|
const parts = safePartitions[key] || [];
|
||||||
const isAnySelected = parts.some(p => p.id === selectedPartitionId);
|
const isSelected = parts.some(p => p.id === selectedPartitionId);
|
||||||
|
|
||||||
|
// Реальные размеры ячейки в мм
|
||||||
|
const realW = (x2 - x1) * drawerW;
|
||||||
|
const realD = (y2 - y1) * drawerD;
|
||||||
|
|
||||||
|
// --- ЛЕЙБЛ РАЗМЕРА ---
|
||||||
|
// Если перегородок нет, показываем общий размер по центру
|
||||||
|
if (parts.length === 0) {
|
||||||
|
const labelX = cellX + cellW / 2;
|
||||||
|
const labelY = cellY + cellH / 2;
|
||||||
|
// Учитываем толщину внешних стенок (или соседних)
|
||||||
|
// Упрощенно: вычитаем толщину (1 раз, т.к. 0.5 с каждой стороны)
|
||||||
|
const textW = Math.max(0, realW - thickness).toFixed(0);
|
||||||
|
const textD = Math.max(0, realD - thickness).toFixed(0);
|
||||||
|
|
||||||
|
// Рисуем текст только если есть место
|
||||||
|
if (cellH > 40 && cellW > 60) {
|
||||||
|
elements.push(
|
||||||
|
<text key={`label-${key}`} x={labelX} y={labelY} textAnchor="middle" dominantBaseline="middle" className="fill-slate-400 font-mono text-[10px] pointer-events-none select-none opacity-60">
|
||||||
|
{textW} × {textD}
|
||||||
|
</text>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
elements.push(
|
elements.push(
|
||||||
<g key={key}>
|
<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"/>}
|
{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 => {
|
{parts.map(p => {
|
||||||
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;
|
let lx1, ly1, lx2, ly2; // Координаты линии
|
||||||
|
let tx, ty; // Координаты текста
|
||||||
|
let dist1 = 0, dist2 = 0; // Расстояния до соседей (в мм)
|
||||||
|
|
||||||
|
// Находим соседей для расчета размеров
|
||||||
|
const neighbors = getNearestNeighbors(p.offset, (pMin + pMax)/2, p.axis, parts);
|
||||||
|
|
||||||
if (p.axis === 'x') {
|
if (p.axis === 'x') {
|
||||||
const px = cellX + (cellW * p.offset);
|
const px = cellX + (cellW * p.offset);
|
||||||
lx1 = px; lx2 = px;
|
lx1 = px; lx2 = px;
|
||||||
ly1 = cellY + (cellH * pMin); ly2 = cellY + (cellH * pMax);
|
ly1 = cellY + (cellH * pMin); ly2 = cellY + (cellH * pMax);
|
||||||
|
|
||||||
|
// Размеры слева и справа
|
||||||
|
const leftRatio = p.offset - neighbors.min;
|
||||||
|
const rightRatio = neighbors.max - p.offset;
|
||||||
|
dist1 = (leftRatio * realW) - thickness; // Left
|
||||||
|
dist2 = (rightRatio * realW) - thickness; // Right
|
||||||
|
|
||||||
|
tx = px;
|
||||||
|
ty = (ly1 + ly2) / 2;
|
||||||
} else {
|
} else {
|
||||||
const py = cellY + (cellH * p.offset);
|
const py = cellY + (cellH * p.offset);
|
||||||
ly1 = py; ly2 = py;
|
ly1 = py; ly2 = py;
|
||||||
lx1 = cellX + (cellW * pMin); lx2 = cellX + (cellW * pMax);
|
lx1 = cellX + (cellW * pMin); lx2 = cellX + (cellW * pMax);
|
||||||
|
|
||||||
|
// Размеры сверху и снизу
|
||||||
|
const topRatio = p.offset - neighbors.min;
|
||||||
|
const botRatio = neighbors.max - p.offset;
|
||||||
|
dist1 = (topRatio * realD) - thickness; // Top
|
||||||
|
dist2 = (botRatio * realD) - thickness; // Bottom
|
||||||
|
|
||||||
|
tx = (lx1 + lx2) / 2;
|
||||||
|
ty = py;
|
||||||
}
|
}
|
||||||
|
|
||||||
const isSel = selectedPartitionId === p.id;
|
const isSel = selectedPartitionId === p.id;
|
||||||
const isHov = hoveredPartition?.id === p.id;
|
const isHov = hoveredPartition?.id === p.id;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<g key={p.id} onDoubleClick={(e) => { e.stopPropagation(); removePartition(key, p.id); }}>
|
<g key={p.id}>
|
||||||
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} stroke="transparent" strokeWidth="30" />
|
{/* Сама линия */}
|
||||||
|
<g onDoubleClick={(e) => { e.stopPropagation(); removePartition(key, p.id); }}>
|
||||||
|
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} stroke="transparent" strokeWidth="40" />
|
||||||
<line x1={lx1} y1={ly1} x2={lx2} y2={ly2} stroke={isSel ? "#a855f7" : (isHov ? "#d8b4fe" : "#7e22ce")} strokeWidth={isSel ? 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>
|
</g>
|
||||||
|
|
||||||
|
{/* Текст размеров (Слева/Справа или Сверху/Снизу) */}
|
||||||
|
<text x={tx} y={ty} className="pointer-events-none select-none font-mono text-[9px] fill-white font-bold" textAnchor="middle" dominantBaseline="middle">
|
||||||
|
{p.axis === 'x' ? (
|
||||||
|
<>
|
||||||
|
<tspan dx="-12" fill="#94a3b8">{dist1.toFixed(0)}</tspan>
|
||||||
|
<tspan dx="24" fill="#94a3b8">{dist2.toFixed(0)}</tspan>
|
||||||
|
</>
|
||||||
|
) : (
|
||||||
|
<>
|
||||||
|
<tspan x={tx} dy="-8" fill="#94a3b8">{dist1.toFixed(0)}</tspan>
|
||||||
|
<tspan x={tx} dy="16" fill="#94a3b8">{dist2.toFixed(0)}</tspan>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</text>
|
||||||
|
</g>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
@@ -354,12 +431,10 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
let fx1, fy1, fx2, fy2;
|
let fx1, fy1, fx2, fy2;
|
||||||
if (phantomPartition.axis === 'x') {
|
if (phantomPartition.axis === 'x') {
|
||||||
const px = cellX + (cellW * phantomPartition.offset);
|
const px = cellX + (cellW * phantomPartition.offset);
|
||||||
fx1 = px; fx2 = px;
|
fx1 = px; fx2 = px; fy1 = cellY + (cellH * pMin); fy2 = cellY + (cellH * pMax);
|
||||||
fy1 = cellY + (cellH * pMin); fy2 = cellY + (cellH * pMax);
|
|
||||||
} else {
|
} else {
|
||||||
const py = cellY + (cellH * phantomPartition.offset);
|
const py = cellY + (cellH * phantomPartition.offset);
|
||||||
fy1 = py; fy2 = py;
|
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"/>;
|
return <line x1={fx1} y1={fy1} x2={fx2} y2={fy2} stroke="#34d399" strokeWidth="3" strokeDasharray="6,6"/>;
|
||||||
})()}
|
})()}
|
||||||
@@ -375,138 +450,79 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
return (
|
return (
|
||||||
<div className="bg-slate-900 p-4 rounded-xl shadow-lg border border-slate-800 h-full flex flex-col relative overflow-hidden">
|
<div className="bg-slate-900 p-4 rounded-xl shadow-lg border border-slate-800 h-full flex flex-col relative overflow-hidden">
|
||||||
|
|
||||||
{/* TOOLBAR */}
|
{/* HEADER */}
|
||||||
<div className="flex justify-between items-center mb-2 z-20 shrink-0">
|
<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">
|
<h2 className="text-lg font-bold flex items-center gap-2 text-primary">
|
||||||
<Grid size={20} /> 2. Редактор макета
|
<Grid size={20} /> 2. Редактор макета
|
||||||
</h2>
|
</h2>
|
||||||
|
|
||||||
<div className="flex bg-slate-800 p-1 rounded-lg border border-slate-700">
|
<div className="flex bg-slate-800 p-1 rounded-lg border border-slate-700">
|
||||||
<button onClick={() => { setMode('lines'); setSelectedPartitionId(null); }}
|
<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>
|
||||||
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'}`}>
|
<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>
|
||||||
<Move size={14}/> Границы
|
</div>
|
||||||
</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>
|
||||||
<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>
|
</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">
|
{/* INFO */}
|
||||||
<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">
|
<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" />
|
<MousePointer2 size={14} className="text-primary" />
|
||||||
{mode === 'lines' ? (
|
{mode === 'lines' ? (
|
||||||
<div className="flex gap-3">
|
<div className="flex gap-3"><span><b className="text-blue-400">ЛКМ:</b> Линия</span><span><b className="text-red-400">ПКМ:</b> Удалить</span></div>
|
||||||
<span><b className="text-blue-400">ЛКМ:</b> Линия</span>
|
|
||||||
<span><b className="text-red-400">ПКМ:</b> Удалить</span>
|
|
||||||
</div>
|
|
||||||
) : (
|
) : (
|
||||||
<div className="flex gap-3">
|
<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>
|
||||||
<span><b className="text-green-400">ЛКМ в ячейке:</b> Стенка (T-соединения)</span>
|
|
||||||
<span><b className="text-purple-400">Драг:</b> Двигать</span>
|
|
||||||
<span><b className="text-red-400">2xЛКМ:</b> Удалить</span>
|
|
||||||
</div>
|
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* WORKSPACE */}
|
{/* 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="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 w-full h-full flex items-center justify-center p-4">
|
||||||
<div
|
<div className="relative shadow-2xl bg-[#1e293b] border border-slate-600 rounded-sm overflow-hidden"
|
||||||
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') }}
|
||||||
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"
|
<svg ref={svgRef} viewBox={`0 0 ${viewBoxW} ${viewBoxH}`} className="w-full h-full touch-none block"
|
||||||
preserveAspectRatio="none"
|
preserveAspectRatio="none"
|
||||||
onMouseMove={handleMouseMove} 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>
|
<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>
|
||||||
<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)" />
|
<rect width="100%" height="100%" fill="url(#grid)" />
|
||||||
|
|
||||||
{renderCellsAndPartitions()}
|
{renderCellsAndPartitions()}
|
||||||
|
{/* Main Grid X */}
|
||||||
{/* MAIN GRID X */}
|
|
||||||
{safeX.map((x, i) => (
|
{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); }}>
|
<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="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" />
|
<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>
|
</g>
|
||||||
))}
|
))}
|
||||||
|
{/* Main Grid Y */}
|
||||||
{/* MAIN GRID Y */}
|
|
||||||
{safeY.map((y, i) => (
|
{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); }}>
|
<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="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" />
|
<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>
|
</g>
|
||||||
))}
|
))}
|
||||||
|
{/* Phantoms */}
|
||||||
{/* MAIN PHANTOMS */}
|
{mode === 'lines' && !hoveredMainSplit && !dragging && phantomMainAxis && (
|
||||||
{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"/>}
|
<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"/>
|
||||||
{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>
|
</svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* --- SIDEBAR FOR EDITING --- */}
|
{/* SIDEBAR */}
|
||||||
{mode === 'cells' && selectedData && (
|
{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="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">
|
<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>
|
||||||
<h3 className="text-sm font-bold text-white flex items-center gap-2">
|
|
||||||
<Settings 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 className="bg-slate-800 p-4 rounded border border-slate-700 space-y-6">
|
||||||
{/* Height */}
|
|
||||||
<div>
|
<div>
|
||||||
<div className="flex justify-between text-xs text-gray-300 mb-2">
|
<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>
|
||||||
<span>Высота</span> <span className="font-mono bg-slate-900 px-1.5 py-0.5 rounded text-xs">{selectedData.part.height} мм</span>
|
<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>
|
||||||
<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">
|
<div className="flex items-center justify-between">
|
||||||
<label htmlFor="rounded-check" className="text-xs text-gray-300 cursor-pointer select-none">Скруглить края</label>
|
<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}
|
<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"/>
|
||||||
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>
|
</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>
|
||||||
{/* 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>
|
||||||
|
<div className="mt-auto text-[10px] text-gray-500 text-center leading-relaxed">Выделите стенку для настройки.<br/>Двойной клик удаляет её.</div>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user