Skip to content

Commit 2b4bb14

Browse files
authored
Merge pull request #680 from Lemoncode/dev
to production
2 parents 3d1f70f + fb9e063 commit 2b4bb14

File tree

10 files changed

+153
-5
lines changed

10 files changed

+153
-5
lines changed

public/shapes/cilinder.svg

Lines changed: 5 additions & 0 deletions
Loading
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
import { ShapeSizeRestrictions } from '@/core/model';
2+
import { forwardRef } from 'react';
3+
import { ShapeProps } from '../shape.model';
4+
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
5+
import { Group, Rect, Ellipse, Line } from 'react-konva';
6+
import { BASIC_SHAPE } from '../front-components/shape.const';
7+
import { useShapeProps } from '../../shapes/use-shape-props.hook';
8+
import { useGroupShapeProps } from '../mock-components.utils';
9+
10+
const cilinderShapeRestrictions: ShapeSizeRestrictions = {
11+
minWidth: 10,
12+
minHeight: 10,
13+
maxWidth: -1,
14+
maxHeight: -1,
15+
defaultWidth: 160,
16+
defaultHeight: 110,
17+
};
18+
19+
export const getCilinderShapeSizeRestrictions = (): ShapeSizeRestrictions =>
20+
cilinderShapeRestrictions;
21+
22+
const shapeType = 'cilinder';
23+
24+
export const CilinderShape = forwardRef<any, ShapeProps>((props, ref) => {
25+
const {
26+
x,
27+
y,
28+
width,
29+
height,
30+
id,
31+
onSelected,
32+
text,
33+
otherProps,
34+
...shapeProps
35+
} = props;
36+
37+
const restrictedSize = fitSizeToShapeSizeRestrictions(
38+
cilinderShapeRestrictions,
39+
width,
40+
height
41+
);
42+
43+
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
44+
45+
const { strokeStyle } = useShapeProps(otherProps, BASIC_SHAPE);
46+
47+
const commonGroupProps = useGroupShapeProps(
48+
props,
49+
restrictedSize,
50+
shapeType,
51+
ref
52+
);
53+
54+
return (
55+
<Group {...commonGroupProps} {...shapeProps}>
56+
<Ellipse
57+
x={restrictedWidth / 2}
58+
y={restrictedHeight}
59+
radiusX={restrictedWidth / 2}
60+
radiusY={restrictedWidth / 8}
61+
fill="#B0B0B0"
62+
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
63+
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
64+
/>
65+
<Rect
66+
x={0}
67+
y={0}
68+
width={restrictedWidth}
69+
height={restrictedHeight}
70+
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
71+
fill="#B0B0B0"
72+
dash={strokeStyle}
73+
/>
74+
<Line
75+
points={[0, 0, 0, restrictedHeight]}
76+
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
77+
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
78+
/>
79+
<Line
80+
points={[restrictedWidth, 0, restrictedWidth, restrictedHeight]}
81+
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
82+
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
83+
/>
84+
<Ellipse
85+
x={restrictedWidth / 2}
86+
y={0}
87+
radiusX={restrictedWidth / 2}
88+
radiusY={restrictedWidth / 8}
89+
fill="#CFCFCF"
90+
stroke={BASIC_SHAPE.DEFAULT_STROKE_COLOR}
91+
strokeWidth={BASIC_SHAPE.DEFAULT_STROKE_WIDTH}
92+
/>
93+
</Group>
94+
);
95+
});

src/common/components/mock-components/front-basic-shapes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,4 @@ export * from './star-shape';
99
export * from './large-arrow-shape';
1010
export * from './image-shape';
1111
export * from './modal-cover-shape';
12+
export * from './cilinder-basic-shape';

src/common/components/mock-components/front-rich-components/table/table.utils.ts

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
1+
//Example:'"Adri, Doe", "24,4", Paraguay' => ['"Adri, Doe"','"24,4"',' Paraguay']
2+
const divideIntoColumns = (row: string): string[] =>
3+
row.match(/\s*"([^"]*)"|\s*([^,]+)/g) || [];
14
export const knowMaxColumns = (rows: string[]): number => {
25
return rows.reduce((maxColumns, row) => {
3-
const columns = row.split(',').length;
6+
const columns = divideIntoColumns(row).length;
47
return columns > maxColumns ? columns : maxColumns;
58
}, 0);
69
};
@@ -10,7 +13,7 @@ export const parseCSVRowsIntoArray = (csvContent: string): string[] => {
1013
const maxColumns = knowMaxColumns(arrayRows);
1114

1215
arrayRows = arrayRows.map(row => {
13-
const currentColumnCount = row.split(',').length;
16+
const currentColumnCount = divideIntoColumns(row).length;
1417

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

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

@@ -71,10 +74,14 @@ export const extractDataRows = (
7174
return widthRow
7275
? rows
7376
.slice(1, rows.length - 1)
74-
.map(row => row.split(',').map(cell => cell.trim()))
77+
.map(row =>
78+
divideIntoColumns(row).map(value => value.replace(/"/g, '').trim())
79+
)
7580
: rows
7681
.slice(1, rows.length)
77-
.map(row => row.split(',').map(cell => cell.trim()));
82+
.map(row =>
83+
divideIntoColumns(row).map(value => value.replace(/"/g, '').trim())
84+
);
7885
};
7986

8087
export const extractWidthRow = (

src/core/model/index.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ export type ShapeType =
6969
| 'tooltip'
7070
| 'slider'
7171
| 'link'
72+
| 'cilinder'
7273
| 'richtext';
7374

7475
export const ShapeDisplayName: Record<ShapeType, string> = {
@@ -129,6 +130,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
129130
tooltip: 'Tooltip',
130131
slider: 'Slider',
131132
richtext: 'Rich Text',
133+
cilinder: 'Cilinder',
132134
};
133135

134136
export type EditType = 'input' | 'textarea' | 'imageupload';

src/pods/canvas/model/shape-size.mapper.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import {
3939
getRectangleShapeSizeRestrictions,
4040
getStarShapeSizeRestrictions,
4141
getModalCoverShapeSizeRestrictions,
42+
getCilinderShapeSizeRestrictions,
4243
// other imports
4344
} from '@/common/components/mock-components/front-basic-shapes';
4445
import {
@@ -140,6 +141,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
140141
tooltip: getTooltipShapeSizeRestrictions,
141142
slider: getSliderShapeSizeRestrictions,
142143
audioPlayer: getAudioPlayerShapeSizeRestrictions,
144+
cilinder: getCilinderShapeSizeRestrictions,
143145
};
144146

145147
export default shapeSizeMap;

src/pods/canvas/shape-renderer/index.tsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,7 @@ import {
5353
renderStar,
5454
renderPostit,
5555
renderLargeArrowShape,
56+
renderCilinder,
5657
} from './simple-basic-shapes';
5758
import {
5859
renderHeading1,
@@ -185,6 +186,8 @@ export const renderShapeComponent = (
185186
return renderTooltip(shape, shapeRenderedProps);
186187
case 'slider':
187188
return renderSlider(shape, shapeRenderedProps);
189+
case 'cilinder':
190+
return renderCilinder(shape, shapeRenderedProps);
188191
default:
189192
return renderNotFound(shape, shapeRenderedProps);
190193
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import { CilinderShape } from '@/common/components/mock-components/front-basic-shapes';
2+
import { ShapeRendererProps } from '../model';
3+
import { ShapeModel } from '@/core/model';
4+
5+
export const renderCilinder = (
6+
shape: ShapeModel,
7+
shapeRenderedProps: ShapeRendererProps
8+
) => {
9+
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } =
10+
shapeRenderedProps;
11+
12+
return (
13+
<CilinderShape
14+
id={shape.id}
15+
key={shape.id}
16+
ref={shapeRefs.current[shape.id]}
17+
x={shape.x}
18+
y={shape.y}
19+
name="shape"
20+
width={shape.width}
21+
height={shape.height}
22+
draggable
23+
typeOfTransformer={shape.typeOfTransformer}
24+
onSelected={handleSelected}
25+
onDragEnd={handleDragEnd(shape.id)}
26+
onTransform={handleTransform}
27+
onTransformEnd={handleTransform}
28+
otherProps={shape.otherProps}
29+
/>
30+
);
31+
};

src/pods/canvas/shape-renderer/simple-basic-shapes/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ export * from './circle.renderer';
88
export * from './star.renderer';
99
export * from './large-arrow.renderer';
1010
export * from './modal-cover.rerender';
11+
export * from './cilinder.renderer';

src/pods/galleries/basic-shapes-gallery/basic-gallery-data/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,4 +12,5 @@ export const mockBasicShapesCollection: ItemInfo[] = [
1212
{ thumbnailSrc: '/shapes/star.svg', type: 'star' },
1313
{ thumbnailSrc: '/shapes/triangle.svg', type: 'triangle' },
1414
{ thumbnailSrc: '/shapes/verticalLine.svg', type: 'verticalLine' },
15+
{ thumbnailSrc: '/shapes/cilinder.svg', type: 'cilinder' },
1516
];

0 commit comments

Comments
 (0)