OpenMind v1 : cartes mentales libres, local-first et dockerisees
Premiere version fonctionnelle, demarrable avec `docker compose up -d --build` sur http://localhost:8080. Architecture - Frontend React 18 / TypeScript strict / Vite / Tailwind, canvas @xyflow/react, etat Zustand, persistance IndexedDB via Dexie, auto-layout dagre. - Backend FastAPI / SQLAlchemy 2 / Pydantic v2 / SQLite, qui sert aussi les fichiers statiques du frontend compile. - Image Docker multi-stage, un seul service, bind mount ./data pour SQLite. Local-first Les cartes restent dans le navigateur. Le serveur ne recoit une carte que sur demande explicite de partage. Partage Deux secrets distincts : share_token public en lecture seule dans l'URL, et management_token conserve uniquement cote client, transmis en en-tete pour les modifications et stocke hashe en base. Fonctionnalites Tableau de bord, editeur complet (undo/redo, copier/coller, raccourcis, branches repliables, recherche), 9 themes, 4 dispositions automatiques, panneau de proprietes, import/export .mmap, export PNG/SVG/PDF, impression, page publique en lecture seule, PWA. Qualite 25 tests pytest et 43 tests vitest au vert, ruff et ESLint sans erreur, TypeScript strict sans erreur. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
46
frontend/src/utils/nodeSize.ts
Normal file
46
frontend/src/utils/nodeSize.ts
Normal file
@@ -0,0 +1,46 @@
|
||||
import { type MindMapNode } from '@/types/map';
|
||||
|
||||
export const NODE_MIN_WIDTH = 96;
|
||||
export const NODE_MAX_WIDTH = 260;
|
||||
export const NODE_LINE_HEIGHT = 20;
|
||||
export const NODE_VERTICAL_PADDING = 20;
|
||||
|
||||
export interface NodeSize {
|
||||
width: number;
|
||||
height: number;
|
||||
}
|
||||
|
||||
/**
|
||||
* Estimation de la taille d'un noeud, utilisee tant que le DOM n'a pas encore
|
||||
* mesure le noeud (premier layout, export sur une carte importee).
|
||||
*/
|
||||
export function estimateNodeSize(node: MindMapNode): NodeSize {
|
||||
const fontSize = node.style?.fontSize ?? 14;
|
||||
const charWidth = fontSize * 0.58;
|
||||
const text = node.text || ' ';
|
||||
const iconWidth = node.icon ? fontSize + 8 : 0;
|
||||
|
||||
const longestLine = text
|
||||
.split('\n')
|
||||
.reduce((longest, line) => Math.max(longest, line.length), 0);
|
||||
|
||||
const rawWidth = longestLine * charWidth + 32 + iconWidth;
|
||||
const width = node.style?.width
|
||||
? node.style.width
|
||||
: Math.min(NODE_MAX_WIDTH, Math.max(NODE_MIN_WIDTH, Math.round(rawWidth)));
|
||||
|
||||
const charsPerLine = Math.max(1, Math.floor((width - 32 - iconWidth) / charWidth));
|
||||
const lines = text
|
||||
.split('\n')
|
||||
.reduce((total, line) => total + Math.max(1, Math.ceil(line.length / charsPerLine)), 0);
|
||||
|
||||
const height = Math.max(38, lines * (fontSize + 6) + NODE_VERTICAL_PADDING);
|
||||
return { width, height: Math.round(height) };
|
||||
}
|
||||
|
||||
/** Taille reelle si elle a ete mesuree, sinon estimation. */
|
||||
export function resolveNodeSize(node: MindMapNode, measured?: Map<string, NodeSize>): NodeSize {
|
||||
const known = measured?.get(node.id);
|
||||
if (known && known.width > 0 && known.height > 0) return known;
|
||||
return estimateNodeSize(node);
|
||||
}
|
||||
Reference in New Issue
Block a user