бета настраиваемого интерфейса

This commit is contained in:
2025-07-16 15:00:45 +03:00
parent 75141f5e88
commit b77303fa97
8 changed files with 1226 additions and 130 deletions

View File

@@ -1,6 +1,70 @@
import { type ClassValue, clsx } from "clsx"
import { twMerge } from "tailwind-merge"
import { type ClassValue, clsx } from "clsx";
import { twMerge } from "tailwind-merge";
import { CellTarget, FormLayoutSettings, TemplateElement } from "../types/template";
export function cn(...inputs: ClassValue[]) {
return twMerge(clsx(inputs))
}
// Миграция элементов из старого формата в новый
export function migrateTemplateElement(element: any): TemplateElement {
// Если элемент уже в новом формате
if (element.targetCells && Array.isArray(element.targetCells)) {
return element as TemplateElement;
}
// Миграция из старого формата
const targetCells: CellTarget[] = [];
if (element.targetCell) {
// Парсим старый формат targetCell (например "A1", "B5")
const cellMatch = element.targetCell.match(/^([A-Z]+)(\d+)$/);
if (cellMatch) {
targetCells.push({
sheet: 'Report', // По умолчанию используем Report
cell: element.targetCell,
displayName: `Ячейка ${element.targetCell}`,
});
}
}
return {
...element,
targetCells,
order: element.order || 0,
category: element.category || '',
width: element.width || 'auto',
} as TemplateElement;
}
// Получение настроек отображения по умолчанию
export function getDefaultLayoutSettings(): FormLayoutSettings {
return {
columns: 2,
grouping: 'none',
elementSpacing: 'normal',
showLabels: true,
enableDragDrop: true,
};
}
// Валидация адреса ячейки
export function validateCellAddress(cell: string): boolean {
return /^[A-Z]+\d+$/.test(cell);
}
// Парсинг адреса ячейки в компоненты
export function parseCellAddress(cell: string): { column: string; row: number } | null {
const match = cell.match(/^([A-Z]+)(\d+)$/);
if (!match) return null;
return {
column: match[1],
row: parseInt(match[2], 10),
};
}
// Генерация уникального ID для элемента
export function generateElementId(): string {
return `element_${Date.now()}_${Math.random().toString(36).substr(2, 9)}`;
}