Skip to content
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
1811c48
feat: add fileTree shape type with inline editing and size restrictions
gustedeveloper Sep 23, 2025
1aad314
feat: integrate FileTree into canvas rendering and gallery
gustedeveloper Sep 23, 2025
0ab0526
feat: implement FileTree component
gustedeveloper Sep 23, 2025
997b8a0
fix(file-tree): Fix selection box size by constraining text elements …
gustedeveloper Sep 24, 2025
1cc1bd9
fix(file-tree): Add right padding to prevent text overflow
gustedeveloper Sep 24, 2025
7e17f3a
feat(file-tree): Add file-tree component to shape other props configu…
gustedeveloper Sep 24, 2025
9f44b4c
feat(file-tree): Sync icon colors with stroke color for visual consis…
gustedeveloper Sep 24, 2025
f5f3b80
feat(file-tree): Enable dynamic addition of file tree elements via sy…
gustedeveloper Sep 24, 2025
fffa03c
update(file-tree): update file tree default text to meet with dynamic…
gustedeveloper Sep 24, 2025
4a020ad
feat(file-tree): Implement dynamic height adaptation based on content
gustedeveloper Sep 24, 2025
d6fb800
create file tree svg
gustedeveloper Sep 24, 2025
0c5abc0
update file tree svg
gustedeveloper Sep 26, 2025
933ff76
update default file tree text to multiline format with indentation
gustedeveloper Sep 26, 2025
2394d44
feat(file-tree): implement multiline parsing with indentation support…
gustedeveloper Sep 26, 2025
e12cb2d
feat(file-tree): improve visual spacing in default text, 1 extra spac…
gustedeveloper Sep 29, 2025
4c24737
feat(file-tree): update level calculation to match new spacing and ad…
gustedeveloper Sep 29, 2025
f7c6f0e
feat: add generic size types and core model updates
gustedeveloper Sep 29, 2025
13ae182
feat: add size configuration system for icon and fileTree shapes
gustedeveloper Sep 29, 2025
47c3667
feat: create generic SelectSizeV2 component that manages both icon an…
gustedeveloper Sep 29, 2025
4e65c89
feat(file-tree): adjust shape restrictions, implement size property t…
gustedeveloper Sep 29, 2025
ac87418
feat(file-tree): refine sizing system for both available sizes
gustedeveloper Sep 30, 2025
8f8b05a
feat(file-tree): implement hook to get dynamic text editor height bas…
gustedeveloper Sep 30, 2025
736f35a
feat(file-tree): implement hook to get default width adjustment based…
gustedeveloper Sep 30, 2025
f748eed
update file tree svg
gustedeveloper Sep 30, 2025
feda3dc
chore(docs): document why SelectSize v2 exists and link to migration …
gustedeveloper Oct 2, 2025
31c8e40
refactor(file-tree): extract file tree resize hooks into hook file, w…
gustedeveloper Oct 2, 2025
f49e6bb
feat(file-tree): add dynamic width calculation to prevent icon overflow
gustedeveloper Oct 2, 2025
8a93fa9
feat(file-tree): improve resize behavior for content and ElementSize …
gustedeveloper Oct 2, 2025
efb9f20
fix(file-tree): remove restrictive minHeight to enable width resizing…
gustedeveloper Oct 2, 2025
5f0cbb9
fix(file-tree): correctly parse symbols with space but no text content
gustedeveloper Oct 3, 2025
3b08933
perf(file-tree): add memoization to optimize component re-renders
gustedeveloper Oct 3, 2025
13430d7
test(file-tree): add unit tests for parseFileTreeText
gustedeveloper Oct 3, 2025
0f02295
refactor(file-tree): extract interfaces to dedicated model file
gustedeveloper Oct 4, 2025
e32bb77
feat(file-tree): enable manual height resizing while preserving conte…
gustedeveloper Oct 4, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions public/rich-components/file-tree.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes';
import { ElementSize, ShapeSizeRestrictions, Size } from '@/core/model';
import { FONT_SIZE_VALUES } from '../../front-components/shape.const';
import { useCanvasContext } from '@/core/providers';
import { useEffect, useRef } from 'react';

interface FileTreeSizeValues {
fontSize: number;
iconDimension: number;
elementHeight: number;
paddingX: number;
paddingY: number;
extraTextTopPadding: number;
iconTextSpacing: number;
indentationStep: number;
}

export const getFileTreeSizeValues = (
size?: ElementSize
): FileTreeSizeValues => {
switch (size) {
case 'XS':
return {
fontSize: 12,
iconDimension: 25,
elementHeight: 30,
paddingX: 25,
paddingY: 15,
extraTextTopPadding: 9,
iconTextSpacing: 8,
indentationStep: 15,
};
case 'S':
return {
fontSize: FONT_SIZE_VALUES.NORMALTEXT,
iconDimension: 50,
elementHeight: 60,
paddingX: 30,
paddingY: 20,
extraTextTopPadding: 20,
iconTextSpacing: 10,
indentationStep: 27,
};
default:
return {
fontSize: FONT_SIZE_VALUES.NORMALTEXT,
iconDimension: 50,
elementHeight: 60,
paddingX: 30,
paddingY: 20,
extraTextTopPadding: 20,
iconTextSpacing: 10,
indentationStep: 25,
};
}
};

export const joinTextContent = (text: string): string[] => {
return text.split(', ');
};

// Symbol -> + Folder - Subfolder * File
// Level -> Level 0: no indentation in Folder / Level 1: 1 indentation (3 spaces) in Subfolder / Level 2: 2 indentations (6 spaces) in File
export interface FileTreeItem {
type: 'folder' | 'subfolder' | 'file';
text: string;
level: number;
}

interface FileTreeDynamicSizeParams {
width: number;
elementHeight: number;
paddingY: number;
baseRestrictions: ShapeSizeRestrictions;
}

export const parseFileTreeText = (text: string): FileTreeItem[] => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be a good idea to add unit tests to this method, including corner cases

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unit tests done!

return text
.split('\n')
.map(line => {
// First detect indentation
const indentMatch = line.match(/^(\s*)/);
const level = indentMatch ? Math.floor(indentMatch[1].length / 3) : 0;
const trimmed = line.trim();

if (trimmed === '') return null;

// Detect symbol
if (trimmed.startsWith('+ ')) {
return {
type: 'folder',
text: trimmed.substring(2).trim(),
level: level,
};
}

if (trimmed.startsWith('- ')) {
return {
type: 'subfolder',
text: trimmed.substring(2).trim(),
level: level,
};
}

if (trimmed.startsWith('* ')) {
return {
type: 'file',
text: trimmed.substring(2).trim(),
level: level,
};
}

// No symbol: will be treated as a folder
return {
type: 'folder',
text: trimmed,
level: level,
};
})
.filter((item): item is FileTreeItem => item !== null);
};

export const calculateFileTreeDynamicSize = (
treeItems: FileTreeItem[],
params: FileTreeDynamicSizeParams
): Size => {
const { width, elementHeight, paddingY, baseRestrictions } = params;

// Calculate minimum height required based on content
const minContentHeight = treeItems.length * elementHeight + paddingY * 2;

// Create dynamic constraints with adaptive minimum height
const dynamicRestrictions: ShapeSizeRestrictions = {
...baseRestrictions,
minHeight: minContentHeight,
defaultHeight: Math.max(
baseRestrictions.defaultHeight || 200,
minContentHeight
),
};

const finalHeight = minContentHeight;

return fitSizeToShapeSizeRestrictions(
dynamicRestrictions,
width,
finalHeight
);
};

// Hook to resize edition text area based on content
export const useFileTreeResizeOnContentChange = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I use to keep business just for plain vainilla ts code, it would be good idea to place hooks on a diferent file, e.g. file-tree-resize.hook.ts

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created file-tree-resize.hook.ts and moved both hooks to the new file

id: string,
coords: { x: number; y: number },
text: string,
currentSize: Size,
calculatedSize: Size,
minHeight: number
) => {
const previousText = useRef(text);
const { updateShapeSizeAndPosition } = useCanvasContext();

useEffect(() => {
// Only update if the text has changed AND the height is different
const textChanged = previousText.current !== text;

const finalHeight = Math.max(calculatedSize.height, minHeight);
const finalSize = { ...calculatedSize, height: finalHeight };

const heightChanged = finalHeight !== currentSize.height;

if (textChanged && heightChanged) {
previousText.current = text;
updateShapeSizeAndPosition(id, coords, finalSize, false);
}
}, [
text,
calculatedSize.height,
currentSize.height,
id,
coords.x,
coords.y,
updateShapeSizeAndPosition,
]);
};

export const useFileTreeResizeOnSizeChange = (
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe you can keep this two hooks private and create a third hook that wraps this two, something like

useFilteTreeResize

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Both private hooks wrapped into useFileTreeResize hook

id: string,
coords: { x: number; y: number },
currentWidth: number,
size?: ElementSize
) => {
const previousSize = useRef(size);
const { updateShapeSizeAndPosition } = useCanvasContext();

useEffect(() => {
// Only update if the size has changed
if (previousSize.current !== size) {
previousSize.current = size;

const newWidth = size === 'XS' ? 150 : 230;

if (currentWidth !== newWidth) {
updateShapeSizeAndPosition(
id,
coords,
{ width: newWidth, height: currentWidth },
false
);
}
}
}, [size, currentWidth, id, coords.x, coords.y, updateShapeSizeAndPosition]);
};
Loading