Добавление перегородок в ячейки и их скругления #6
+13
-17
@@ -37,7 +37,7 @@ const App = () => {
|
|||||||
window.history.replaceState({}, '', window.location.pathname);
|
window.history.replaceState({}, '', window.location.pathname);
|
||||||
}
|
}
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("URL load error", e);
|
console.error("URL error", e);
|
||||||
}
|
}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -45,7 +45,6 @@ const App = () => {
|
|||||||
try {
|
try {
|
||||||
return calculateParts(config, splits);
|
return calculateParts(config, splits);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error("Geometry calculation failed", e);
|
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
}, [config, splits]);
|
}, [config, splits]);
|
||||||
@@ -56,12 +55,10 @@ const App = () => {
|
|||||||
static getDerivedStateFromError() { return { hasError: true }; }
|
static getDerivedStateFromError() { return { hasError: true }; }
|
||||||
render() {
|
render() {
|
||||||
if (this.state.hasError) return (
|
if (this.state.hasError) return (
|
||||||
<div className="h-full flex flex-col items-center justify-center text-red-400 p-8 border border-red-900 bg-red-900/20 rounded-xl">
|
<div className="flex flex-col items-center justify-center h-full text-red-400">
|
||||||
<AlertTriangle size={48} className="mb-4"/>
|
<AlertTriangle className="mb-2" size={32}/>
|
||||||
<h2 className="text-xl font-bold mb-2">Произошла ошибка отрисовки</h2>
|
<p>Ошибка отрисовки.</p>
|
||||||
<button onClick={() => window.location.reload()} className="px-4 py-2 bg-red-600 hover:bg-red-500 text-white rounded-lg font-medium transition-colors">
|
<button onClick={() => window.location.reload()} className="mt-4 px-4 py-2 bg-slate-800 rounded">Перезагрузить</button>
|
||||||
Перезагрузить страницу
|
|
||||||
</button>
|
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
return this.props.children;
|
return this.props.children;
|
||||||
@@ -69,7 +66,7 @@ const App = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="min-h-screen flex flex-col font-sans text-gray-100 bg-slate-950 overflow-hidden">
|
<div className="h-screen flex flex-col font-sans text-gray-100 bg-slate-950 overflow-hidden">
|
||||||
{/* Header */}
|
{/* Header */}
|
||||||
<header className="bg-slate-900 border-b border-slate-800 p-4 shadow-md shrink-0 z-50">
|
<header className="bg-slate-900 border-b border-slate-800 p-4 shadow-md shrink-0 z-50">
|
||||||
<div className="max-w-7xl mx-auto flex items-center justify-between">
|
<div className="max-w-7xl mx-auto flex items-center justify-between">
|
||||||
@@ -88,26 +85,25 @@ const App = () => {
|
|||||||
</div>
|
</div>
|
||||||
</header>
|
</header>
|
||||||
|
|
||||||
{/* Main Content */}
|
{/* Main Content: flex-1 ensures it fills space, overflow-hidden prevents body scroll */}
|
||||||
<main className="flex-1 max-w-7xl mx-auto w-full p-4 md:p-6 overflow-hidden flex flex-col">
|
<main className="flex-1 w-full max-w-7xl mx-auto p-4 md:p-6 overflow-hidden flex flex-col min-h-0">
|
||||||
{step === 1 && (
|
{step === 1 && (
|
||||||
<div className="max-w-4xl mx-auto w-full animate-fade-in overflow-y-auto">
|
<div className="h-full overflow-y-auto animate-fade-in">
|
||||||
<ConfigStep config={config} onChange={setConfig} />
|
<ConfigStep config={config} onChange={setConfig} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{step === 2 && (
|
{step === 2 && (
|
||||||
// ВЕРНУЛИ ЯВНУЮ ВЫСОТУ: h-[calc(100vh-180px)]
|
<div className="h-full flex flex-col animate-fade-in">
|
||||||
<div className="w-full h-[calc(100vh-180px)] animate-fade-in">
|
|
||||||
<ErrorBoundary>
|
<ErrorBoundary>
|
||||||
<LayoutStep key="layout-final" config={config} splits={splits} onChange={setSplits} />
|
{/* УБРАН KEY, чтобы компонент не пересоздавался при каждом чихе */}
|
||||||
|
<LayoutStep config={config} splits={splits} onChange={setSplits} />
|
||||||
</ErrorBoundary>
|
</ErrorBoundary>
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|
||||||
{step === 3 && (
|
{step === 3 && (
|
||||||
// ТАКЖЕ ДЛЯ ШАГА 3
|
<div className="h-full flex flex-col animate-fade-in">
|
||||||
<div className="w-full h-[calc(100vh-180px)] animate-fade-in">
|
|
||||||
<PreviewStep parts={parts} config={config} splits={splits} />
|
<PreviewStep parts={parts} config={config} splits={splits} />
|
||||||
</div>
|
</div>
|
||||||
)}
|
)}
|
||||||
|
|||||||
@@ -18,25 +18,23 @@ type DragTarget =
|
|||||||
export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
||||||
const svgRef = useRef<SVGSVGElement>(null);
|
const svgRef = useRef<SVGSVGElement>(null);
|
||||||
|
|
||||||
// --- STATE ---
|
// -- STATE --
|
||||||
const [mode, setMode] = useState<EditMode>('lines');
|
const [mode, setMode] = useState<EditMode>('lines');
|
||||||
const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
|
const [mousePos, setMousePos] = useState({ x: 0, y: 0 });
|
||||||
const [isButtonHovered, setIsButtonHovered] = useState(false);
|
|
||||||
const [dragging, setDragging] = useState<DragTarget | null>(null);
|
const [dragging, setDragging] = useState<DragTarget | null>(null);
|
||||||
|
const [isButtonHovered, setIsButtonHovered] = useState(false);
|
||||||
|
|
||||||
// Main Grid Interactions
|
// Main Grid
|
||||||
const [phantomMainAxis, setPhantomMainAxis] = useState<Axis | null>(null);
|
const [phantomMainAxis, setPhantomMainAxis] = useState<Axis | null>(null);
|
||||||
const [hoveredMainSplit, setHoveredMainSplit] = useState<{ axis: Axis; index: number } | null>(null);
|
const [hoveredMainSplit, setHoveredMainSplit] = useState<{ axis: Axis; index: number } | null>(null);
|
||||||
|
|
||||||
// Partition Interactions
|
// Partitions
|
||||||
const [hoveredCell, setHoveredCell] = useState<{ i: number; j: number } | null>(null);
|
const [hoveredCell, setHoveredCell] = useState<{ i: number; j: number } | null>(null);
|
||||||
const [hoveredPartition, setHoveredPartition] = useState<{ id: string; cellKey: string } | 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 [phantomPartition, setPhantomPartition] = useState<{ axis: Axis; offset: number; min: number; max: number } | null>(null);
|
||||||
|
|
||||||
const [selectedPartitionId, setSelectedPartitionId] = useState<string | null>(null);
|
const [selectedPartitionId, setSelectedPartitionId] = useState<string | null>(null);
|
||||||
|
|
||||||
// --- DATA ---
|
// -- SAFE DATA --
|
||||||
const safeX = Array.isArray(splits?.x) ? splits.x : [];
|
const safeX = Array.isArray(splits?.x) ? splits.x : [];
|
||||||
const safeY = Array.isArray(splits?.y) ? splits.y : [];
|
const safeY = Array.isArray(splits?.y) ? splits.y : [];
|
||||||
const safePartitions = splits?.partitions || {};
|
const safePartitions = splits?.partitions || {};
|
||||||
@@ -51,8 +49,8 @@ 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: Find Selected Partition ---
|
// -- HELPER: Get Selected --
|
||||||
const getSelectedPartitionData = () => {
|
const getSelectedPartition = () => {
|
||||||
if (!selectedPartitionId) return null;
|
if (!selectedPartitionId) return null;
|
||||||
for (const key in safePartitions) {
|
for (const key in safePartitions) {
|
||||||
const part = safePartitions[key].find(p => p.id === selectedPartitionId);
|
const part = safePartitions[key].find(p => p.id === selectedPartitionId);
|
||||||
@@ -60,35 +58,44 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
};
|
};
|
||||||
const selectedData = getSelectedPartitionData();
|
const selectedData = getSelectedPartition();
|
||||||
|
|
||||||
// --- LOGIC: Calculate Boundaries for T-Junctions ---
|
// -- LOGIC: Calculate T-Junction Limits --
|
||||||
const getHoveredBoundaries = (lx: number, ly: number, parts: Partition[]) => {
|
// Вычисляет min/max для линии, чтобы она упиралась в ближайшие соседи
|
||||||
let minX = 0, maxX = 1;
|
const calculateLimits = (lx: number, ly: number, axis: Axis, parts: Partition[]) => {
|
||||||
let minY = 0, maxY = 1;
|
let min = 0;
|
||||||
|
let max = 1;
|
||||||
|
|
||||||
|
// Ищем ближайшие перпендикулярные стенки
|
||||||
parts.forEach(p => {
|
parts.forEach(p => {
|
||||||
|
if (p.axis === axis) return; // Нас интересуют только перпендикулярные
|
||||||
|
|
||||||
const pMin = p.min ?? 0;
|
const pMin = p.min ?? 0;
|
||||||
const pMax = p.max ?? 1;
|
const pMax = p.max ?? 1;
|
||||||
|
|
||||||
if (p.axis === 'x') {
|
if (axis === 'x') {
|
||||||
// Вертикальная стенка. Если мышь в ее диапазоне по Y...
|
// Мы рисуем Вертикальную (X). Ищем Горизонтальные (Y), которые мы пересекаем по X
|
||||||
if (ly >= pMin && ly <= pMax) {
|
// Горизонтальная стенка находится на высоте p.offset.
|
||||||
if (p.offset < lx) minX = Math.max(minX, p.offset);
|
// Она занимает по ширине от pMin до pMax.
|
||||||
if (p.offset > lx) maxX = Math.min(maxX, p.offset);
|
// Попадаем ли мы в ее ширину?
|
||||||
|
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); // Стенка снизу
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Горизонтальная стенка. Если мышь в ее диапазоне по X...
|
// Мы рисуем Горизонтальную (Y). Ищем Вертикальные (X)
|
||||||
if (lx >= pMin && lx <= pMax) {
|
// Вертикальная на p.offset
|
||||||
if (p.offset < ly) minY = Math.max(minY, p.offset);
|
// Занимает высоту pMin..pMax
|
||||||
if (p.offset > ly) maxY = Math.min(maxY, p.offset);
|
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); // Стенка справа
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return { minX, maxX, minY, maxY };
|
return { min, max };
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- ACTIONS ---
|
// -- ACTIONS --
|
||||||
const createPartition = (i: number, j: number, axis: Axis, offset: number, min: number, max: number) => {
|
const createPartition = (i: number, j: number, axis: Axis, offset: number, min: number, max: number) => {
|
||||||
const key = `${i}-${j}`;
|
const key = `${i}-${j}`;
|
||||||
const current = safePartitions[key] || [];
|
const current = safePartitions[key] || [];
|
||||||
@@ -103,7 +110,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
};
|
};
|
||||||
onChange({ ...splits, partitions: { ...safePartitions, [key]: [...current, newPart] } });
|
onChange({ ...splits, partitions: { ...safePartitions, [key]: [...current, newPart] } });
|
||||||
setSelectedPartitionId(newPart.id);
|
setSelectedPartitionId(newPart.id);
|
||||||
// ВАЖНО: Не меняем setMode, остаемся в 'cells'
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const updatePartition = (key: string, id: string, updates: Partial<Partition>) => {
|
const updatePartition = (key: string, id: string, updates: Partial<Partition>) => {
|
||||||
@@ -127,7 +133,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
setDragging(null);
|
setDragging(null);
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- MOUSE HANDLERS ---
|
// -- MOUSE HANDLER --
|
||||||
const handleMouseMove = (e: React.MouseEvent) => {
|
const handleMouseMove = (e: React.MouseEvent) => {
|
||||||
if (!svgRef.current) return;
|
if (!svgRef.current) return;
|
||||||
const rect = svgRef.current.getBoundingClientRect();
|
const rect = svgRef.current.getBoundingClientRect();
|
||||||
@@ -144,7 +150,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
newSplits[dragging.axis][dragging.index] = val;
|
newSplits[dragging.axis][dragging.index] = val;
|
||||||
onChange(newSplits);
|
onChange(newSplits);
|
||||||
} else {
|
} else {
|
||||||
// Dragging Partition
|
|
||||||
const [iStr, jStr] = dragging.cellKey.split('-');
|
const [iStr, jStr] = dragging.cellKey.split('-');
|
||||||
const i = parseInt(iStr); const j = parseInt(jStr);
|
const i = parseInt(iStr); const j = parseInt(jStr);
|
||||||
const cellX1 = sortedX[i]; const cellX2 = sortedX[i+1];
|
const cellX1 = sortedX[i]; const cellX2 = sortedX[i+1];
|
||||||
@@ -156,7 +161,8 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
} else {
|
} else {
|
||||||
newOffset = (ny - cellY1) / (cellY2 - cellY1);
|
newOffset = (ny - cellY1) / (cellY2 - cellY1);
|
||||||
}
|
}
|
||||||
newOffset = Math.max(0.02, Math.min(0.98, newOffset));
|
// Ограничитель, чтобы не вытащить за границы
|
||||||
|
newOffset = Math.max(0.01, Math.min(0.99, newOffset));
|
||||||
if (!isNaN(newOffset)) {
|
if (!isNaN(newOffset)) {
|
||||||
updatePartition(dragging.cellKey, dragging.id, { offset: newOffset });
|
updatePartition(dragging.cellKey, dragging.id, { offset: newOffset });
|
||||||
}
|
}
|
||||||
@@ -175,9 +181,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
if (!closeToX && !closeToY) {
|
if (!closeToX && !closeToY) {
|
||||||
const distRight = 1 - nx; const distBottom = 1 - ny;
|
const distRight = 1 - nx; const distBottom = 1 - ny;
|
||||||
setPhantomMainAxis(Math.min(nx, distRight) < Math.min(ny, distBottom) ? 'y' : 'x');
|
setPhantomMainAxis(Math.min(nx, distRight) < Math.min(ny, distBottom) ? 'y' : 'x');
|
||||||
} else {
|
} else { setPhantomMainAxis(null); }
|
||||||
setPhantomMainAxis(null);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Cells Mode
|
// Cells Mode
|
||||||
@@ -206,10 +210,12 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const cx1 = sortedX[cellIdx.i]; const cx2 = sortedX[cellIdx.i+1];
|
const cx1 = sortedX[cellIdx.i]; const cx2 = sortedX[cellIdx.i+1];
|
||||||
const cy1 = sortedY[cellIdx.j]; const cy2 = sortedY[cellIdx.j+1];
|
const cy1 = sortedY[cellIdx.j]; const cy2 = sortedY[cellIdx.j+1];
|
||||||
const cw = cx2 - cx1; const ch = cy2 - cy1;
|
const cw = cx2 - cx1; const ch = cy2 - cy1;
|
||||||
|
|
||||||
|
// Local coordinates
|
||||||
const lx = (nx - cx1) / cw;
|
const lx = (nx - cx1) / cw;
|
||||||
const ly = (ny - cy1) / ch;
|
const ly = (ny - cy1) / ch;
|
||||||
|
|
||||||
// 2. Check Existing Partitions
|
// 2. Check Hover Existing
|
||||||
let found = null;
|
let found = null;
|
||||||
const SNAP = 0.05;
|
const SNAP = 0.05;
|
||||||
for (const p of parts) {
|
for (const p of parts) {
|
||||||
@@ -224,23 +230,20 @@ 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. Calc Phantom
|
// 3. Calc Phantom with T-Junctions
|
||||||
const bounds = getHoveredBoundaries(lx, ly, parts);
|
const distL = lx; const distR = 1 - lx;
|
||||||
const distL = lx - bounds.minX; const distR = bounds.maxX - lx;
|
const distT = ly; const distB = 1 - ly;
|
||||||
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 height = bounds.maxY - bounds.minY;
|
|
||||||
|
|
||||||
// Проверяем, достаточно ли места
|
// Рассчитываем min/max на основе пересечений
|
||||||
if ((axis === 'y' && height > 0.1) || (axis === 'x' && width > 0.1)) {
|
const { min, max } = calculateLimits(lx, ly, axis, parts);
|
||||||
|
|
||||||
|
// Проверяем, есть ли место
|
||||||
|
if (max - min > 0.1) {
|
||||||
const offset = axis === 'x' ? lx : ly;
|
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 });
|
setPhantomPartition({ axis, offset, min, max });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -263,7 +266,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
setDragging({ type: 'main', axis: phantomMainAxis, index: newSplits[phantomMainAxis].length - 1 });
|
setDragging({ type: 'main', axis: phantomMainAxis, index: newSplits[phantomMainAxis].length - 1 });
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// MODE: CELLS
|
|
||||||
if (hoveredPartition) {
|
if (hoveredPartition) {
|
||||||
const key = hoveredPartition.cellKey;
|
const key = hoveredPartition.cellKey;
|
||||||
const parts = safePartitions[key] || [];
|
const parts = safePartitions[key] || [];
|
||||||
@@ -271,7 +273,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
if (part) {
|
if (part) {
|
||||||
if (e.button === 0) {
|
if (e.button === 0) {
|
||||||
setDragging({ type: 'partition', cellKey: key, id: part.id, axis: part.axis });
|
setDragging({ type: 'partition', cellKey: key, id: part.id, axis: part.axis });
|
||||||
setSelectedPartitionId(part.id); // Выбираем для редактирования
|
setSelectedPartitionId(part.id);
|
||||||
} else if (e.button === 2) {
|
} else if (e.button === 2) {
|
||||||
removePartition(key, part.id);
|
removePartition(key, part.id);
|
||||||
}
|
}
|
||||||
@@ -288,13 +290,12 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// Клик в пустоту - снимаем выделение
|
|
||||||
setSelectedPartitionId(null);
|
setSelectedPartitionId(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
// --- RENDER HELPERS ---
|
// --- RENDER ---
|
||||||
const renderCellsAndPartitions = () => {
|
const renderCellsAndPartitions = () => {
|
||||||
const elements = [];
|
const elements = [];
|
||||||
for (let i = 0; i < sortedX.length - 1; i++) {
|
for (let i = 0; i < sortedX.length - 1; i++) {
|
||||||
@@ -302,7 +303,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
const x1 = sortedX[i]; const x2 = sortedX[i + 1];
|
const x1 = sortedX[i]; const x2 = sortedX[i + 1];
|
||||||
const y1 = sortedY[j]; const y2 = sortedY[j + 1];
|
const y1 = sortedY[j]; const y2 = sortedY[j + 1];
|
||||||
|
|
||||||
// !!! FIX: Проверка y2
|
|
||||||
if (y2 === undefined || x2 === undefined) continue;
|
if (y2 === undefined || x2 === undefined) continue;
|
||||||
|
|
||||||
const cellX = x1 * viewBoxW; const cellY = y1 * viewBoxH;
|
const cellX = x1 * viewBoxW; const cellY = y1 * viewBoxH;
|
||||||
@@ -315,14 +315,13 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
|
|
||||||
elements.push(
|
elements.push(
|
||||||
<g key={key}>
|
<g key={key}>
|
||||||
{/* 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"/>}
|
{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"/>}
|
{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 => {
|
{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;
|
||||||
|
|
||||||
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;
|
||||||
@@ -337,13 +336,12 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<g key={p.id} onDoubleClick={(e) => { e.stopPropagation(); removePartition(key, p.id); }}>
|
<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="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>
|
||||||
);
|
);
|
||||||
})}
|
})}
|
||||||
|
|
||||||
{/* Phantom */}
|
|
||||||
{isHovered && phantomPartition && !hoveredPartition && !dragging && (
|
{isHovered && phantomPartition && !hoveredPartition && !dragging && (
|
||||||
<g className="pointer-events-none opacity-60">
|
<g className="pointer-events-none opacity-60">
|
||||||
{(() => {
|
{(() => {
|
||||||
@@ -372,7 +370,7 @@ 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. Редактор макета
|
||||||
@@ -404,7 +402,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
</div>
|
</div>
|
||||||
) : (
|
) : (
|
||||||
<div className="flex gap-3">
|
<div className="flex gap-3">
|
||||||
<span><b className="text-green-400">ЛКМ:</b> Стенка</span>
|
<span><b className="text-green-400">ЛКМ в ячейке:</b> Стенка (T-соединения)</span>
|
||||||
<span><b className="text-purple-400">Драг:</b> Двигать</span>
|
<span><b className="text-purple-400">Драг:</b> Двигать</span>
|
||||||
<span><b className="text-red-400">2xЛКМ:</b> Удалить</span>
|
<span><b className="text-red-400">2xЛКМ:</b> Удалить</span>
|
||||||
</div>
|
</div>
|
||||||
@@ -435,7 +433,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
</defs>
|
</defs>
|
||||||
<rect width="100%" height="100%" fill="url(#grid)" />
|
<rect width="100%" height="100%" fill="url(#grid)" />
|
||||||
|
|
||||||
{/* CELLS & PARTITIONS */}
|
|
||||||
{renderCellsAndPartitions()}
|
{renderCellsAndPartitions()}
|
||||||
|
|
||||||
{/* MAIN GRID X */}
|
{/* MAIN GRID X */}
|
||||||
@@ -461,7 +458,7 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
</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">
|
||||||
@@ -472,7 +469,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
</div>
|
</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>
|
<span>Высота</span> <span className="font-mono bg-slate-900 px-1.5 py-0.5 rounded text-xs">{selectedData.part.height} мм</span>
|
||||||
@@ -483,7 +479,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</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}
|
||||||
@@ -492,7 +487,6 @@ export const LayoutStep: React.FC<Props> = ({ config, splits, onChange }) => {
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Delete */}
|
|
||||||
<button
|
<button
|
||||||
onClick={() => removePartition(selectedData.key, selectedData.part.id)}
|
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"
|
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"
|
||||||
|
|||||||
@@ -99,40 +99,23 @@ export const createBinGeometry = (
|
|||||||
geometries.push(wallGeo);
|
geometries.push(wallGeo);
|
||||||
|
|
||||||
partitions.forEach(p => {
|
partitions.forEach(p => {
|
||||||
// Поддержка T-junctions: учитываем min и max
|
|
||||||
const pMin = p.min ?? 0;
|
const pMin = p.min ?? 0;
|
||||||
const pMax = p.max ?? 1;
|
const pMax = p.max ?? 1;
|
||||||
|
|
||||||
|
const lengthRatio = pMax - pMin;
|
||||||
|
const midRatio = pMin + (lengthRatio / 2);
|
||||||
|
|
||||||
let pWidth = 0, pDepth = 0, pX = 0, pY = 0;
|
let pWidth = 0, pDepth = 0, pX = 0, pY = 0;
|
||||||
|
|
||||||
if (p.axis === 'x') {
|
if (p.axis === 'x') {
|
||||||
// Вертикальная перегородка
|
|
||||||
pWidth = thickness;
|
pWidth = thickness;
|
||||||
// Длина зависит от max-min
|
pDepth = lengthRatio * innerDepth;
|
||||||
const length = (pMax - pMin) * innerDepth;
|
|
||||||
pDepth = length;
|
|
||||||
|
|
||||||
pX = (-innerWidth / 2) + (innerWidth * p.offset);
|
pX = (-innerWidth / 2) + (innerWidth * p.offset);
|
||||||
|
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 {
|
} else {
|
||||||
// Горизонтальная перегородка
|
pWidth = lengthRatio * innerWidth;
|
||||||
const length = (pMax - pMin) * innerWidth;
|
|
||||||
pWidth = length;
|
|
||||||
pDepth = thickness;
|
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);
|
pY = (-innerDepth / 2) + (innerDepth * p.offset);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user