Skip to content

Commit

Permalink
Merge pull request #680 from Lemoncode/dev
Browse files Browse the repository at this point in the history
to production
  • Loading branch information
brauliodiez authored Feb 2, 2025
2 parents 3d1f70f + fb9e063 commit 2b4bb14
Show file tree
Hide file tree
Showing 10 changed files with 153 additions and 5 deletions.
5 changes: 5 additions & 0 deletions public/shapes/cilinder.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,95 @@
import { ShapeSizeRestrictions } from '@/core/model';
import { forwardRef } from 'react';
import { ShapeProps } from '../shape.model';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { Group, Rect, Ellipse, Line } from 'react-konva';
import { BASIC_SHAPE } from '../front-components/shape.const';
import { useShapeProps } from '../../shapes/use-shape-props.hook';
import { useGroupShapeProps } from '../mock-components.utils';

const cilinderShapeRestrictions: ShapeSizeRestrictions = {
minWidth: 10,
minHeight: 10,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 160,
defaultHeight: 110,
};

export const getCilinderShapeSizeRestrictions = (): ShapeSizeRestrictions =>
cilinderShapeRestrictions;

const shapeType = 'cilinder';

export const CilinderShape = forwardRef<any, ShapeProps>((props, ref) => {
const {
x,
y,
width,
height,
id,
onSelected,
text,
otherProps,
...shapeProps
} = props;

const restrictedSize = fitSizeToShapeSizeRestrictions(
cilinderShapeRestrictions,
width,
height
);

const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;

const { strokeStyle } = useShapeProps(otherProps, BASIC_SHAPE);

const commonGroupProps = useGroupShapeProps(
props,
restrictedSize,
shapeType,
ref
);

return (
<Group {...commonGroupProps} {...shapeProps}>
<Ellipse
x={restrictedWidth / 2}
y={restrictedHeight}
radiusX={restrictedWidth / 2}
radiusY={restrictedWidth / 8}
fill="#B0B0B0"
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
<Rect
x={0}
y={0}
width={restrictedWidth}
height={restrictedHeight}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
fill="#B0B0B0"
dash={strokeStyle}
/>
<Line
points={[0, 0, 0, restrictedHeight]}
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
<Line
points={[restrictedWidth, 0, restrictedWidth, restrictedHeight]}
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
<Ellipse
x={restrictedWidth / 2}
y={0}
radiusX={restrictedWidth / 2}
radiusY={restrictedWidth / 8}
fill="#CFCFCF"
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
/>
</Group>
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@ export * from './star-shape';
export * from './large-arrow-shape';
export * from './image-shape';
export * from './modal-cover-shape';
export * from './cilinder-basic-shape';
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
//Example:'"Adri, Doe", "24,4", Paraguay' => ['"Adri, Doe"','"24,4"',' Paraguay']
const divideIntoColumns = (row: string): string[] =>
row.match(/\s*"([^"]*)"|\s*([^,]+)/g) || [];
export const knowMaxColumns = (rows: string[]): number => {
return rows.reduce((maxColumns, row) => {
const columns = row.split(',').length;
const columns = divideIntoColumns(row).length;
return columns > maxColumns ? columns : maxColumns;
}, 0);
};
Expand All @@ -10,7 +13,7 @@ export const parseCSVRowsIntoArray = (csvContent: string): string[] => {
const maxColumns = knowMaxColumns(arrayRows);

arrayRows = arrayRows.map(row => {
const currentColumnCount = row.split(',').length;
const currentColumnCount = divideIntoColumns(row).length;

// If a row is empty, return a string of commas
if (currentColumnCount === 0) {
Expand All @@ -23,7 +26,7 @@ export const parseCSVRowsIntoArray = (csvContent: string): string[] => {
}

// If a row has less columns than maxColumns, add commas at the end
if (currentColumnCount < maxColumns) {
if (currentColumnCount <= maxColumns) {
return row + ','.repeat(maxColumns - currentColumnCount); // Añadir comas al final
}

Expand Down Expand Up @@ -71,10 +74,14 @@ export const extractDataRows = (
return widthRow
? rows
.slice(1, rows.length - 1)
.map(row => row.split(',').map(cell => cell.trim()))
.map(row =>
divideIntoColumns(row).map(value => value.replace(/"/g, '').trim())
)
: rows
.slice(1, rows.length)
.map(row => row.split(',').map(cell => cell.trim()));
.map(row =>
divideIntoColumns(row).map(value => value.replace(/"/g, '').trim())
);
};

export const extractWidthRow = (
Expand Down
2 changes: 2 additions & 0 deletions src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ export type ShapeType =
| 'tooltip'
| 'slider'
| 'link'
| 'cilinder'
| 'richtext';

export const ShapeDisplayName: Record<ShapeType, string> = {
Expand Down Expand Up @@ -129,6 +130,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
tooltip: 'Tooltip',
slider: 'Slider',
richtext: 'Rich Text',
cilinder: 'Cilinder',
};

export type EditType = 'input' | 'textarea' | 'imageupload';
Expand Down
2 changes: 2 additions & 0 deletions src/pods/canvas/model/shape-size.mapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
getRectangleShapeSizeRestrictions,
getStarShapeSizeRestrictions,
getModalCoverShapeSizeRestrictions,
getCilinderShapeSizeRestrictions,
// other imports
} from '@/common/components/mock-components/front-basic-shapes';
import {
Expand Down Expand Up @@ -140,6 +141,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
tooltip: getTooltipShapeSizeRestrictions,
slider: getSliderShapeSizeRestrictions,
audioPlayer: getAudioPlayerShapeSizeRestrictions,
cilinder: getCilinderShapeSizeRestrictions,
};

export default shapeSizeMap;
3 changes: 3 additions & 0 deletions src/pods/canvas/shape-renderer/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ import {
renderStar,
renderPostit,
renderLargeArrowShape,
renderCilinder,
} from './simple-basic-shapes';
import {
renderHeading1,
Expand Down Expand Up @@ -185,6 +186,8 @@ export const renderShapeComponent = (
return renderTooltip(shape, shapeRenderedProps);
case 'slider':
return renderSlider(shape, shapeRenderedProps);
case 'cilinder':
return renderCilinder(shape, shapeRenderedProps);
default:
return renderNotFound(shape, shapeRenderedProps);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { CilinderShape } from '@/common/components/mock-components/front-basic-shapes';
import { ShapeRendererProps } from '../model';
import { ShapeModel } from '@/core/model';

export const renderCilinder = (
shape: ShapeModel,
shapeRenderedProps: ShapeRendererProps
) => {
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } =
shapeRenderedProps;

return (
<CilinderShape
id={shape.id}
key={shape.id}
ref={shapeRefs.current[shape.id]}
x={shape.x}
y={shape.y}
name="shape"
width={shape.width}
height={shape.height}
draggable
typeOfTransformer={shape.typeOfTransformer}
onSelected={handleSelected}
onDragEnd={handleDragEnd(shape.id)}
onTransform={handleTransform}
onTransformEnd={handleTransform}
otherProps={shape.otherProps}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export * from './circle.renderer';
export * from './star.renderer';
export * from './large-arrow.renderer';
export * from './modal-cover.rerender';
export * from './cilinder.renderer';
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ export const mockBasicShapesCollection: ItemInfo[] = [
{ thumbnailSrc: '/shapes/star.svg', type: 'star' },
{ thumbnailSrc: '/shapes/triangle.svg', type: 'triangle' },
{ thumbnailSrc: '/shapes/verticalLine.svg', type: 'verticalLine' },
{ thumbnailSrc: '/shapes/cilinder.svg', type: 'cilinder' },
];

0 comments on commit 2b4bb14

Please sign in to comment.