Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './large-arrow-shape';
export * from './image-shape';
export * from './modal-cover-shape';
export * from './cilinder-basic-shape';
export * from './mouse-cursor/mouse-cursor-basic-shape';
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { IconSize } from '@/core/model';

export const returnIconSize = (iconSize: IconSize): number[] => {
switch (iconSize) {
case 'XS':
return [25, 25];
case 'S':
return [50, 50];
case 'M':
return [100, 100];
case 'L':
return [125, 125];
case 'XL':
return [150, 150];
default:
return [50, 50];
}
};
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export * from './mouse-cursor-basic-shape';
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import { ShapeSizeRestrictions, ShapeType, BASE_ICONS_URL } from '@/core/model';
import { forwardRef, useEffect, useState } from 'react';
import { ShapeProps } from '../../shape.model';
import { loadSvgWithFill } from '@/common/utils/svg.utils';
import { Group, Image } from 'react-konva';
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes/shape-restrictions';
import { returnIconSize } from './icon-shape.business';
import { useGroupShapeProps } from '../../mock-components.utils';
import { useShapeProps } from '../../../shapes/use-shape-props.hook';
import { BASIC_SHAPE } from '../../front-components/shape.const';

const MouseCursorSizeRestrictions: ShapeSizeRestrictions = {
minWidth: 25,
minHeight: 25,
maxWidth: -1,
maxHeight: -1,
defaultWidth: 150,
defaultHeight: 150,
};

export const getMouseCursorShapeSizeRestrictions = (): ShapeSizeRestrictions =>
MouseCursorSizeRestrictions;

const shapeType: ShapeType = 'mouseCursor';

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

const [iconWidth, iconHeight] = returnIconSize(iconSize);
const restrictedSize = fitSizeToShapeSizeRestrictions(
MouseCursorSizeRestrictions,
iconWidth,
iconHeight
);

const { width: restrictedWidth, height: restrictedHeight } = restrictedSize;
const { stroke } = useShapeProps(otherProps, BASIC_SHAPE);
const commonGroupProps = useGroupShapeProps(
props,
restrictedSize,
shapeType,
ref
);

const [image, setImage] = useState<HTMLImageElement | null>(null);
//const imgRef = useRef(null);
const fileName = 'cursor.svg';
useEffect(() => {
loadSvgWithFill(`${BASE_ICONS_URL}${fileName}`, `${stroke}`).then(img => {
setImage(img);
});
}, [stroke]);
return (
<Group {...commonGroupProps} {...shapeProps}>
{image && (
<Image
image={image}
x={0}
y={0}
width={restrictedWidth}
height={restrictedHeight}
//ref={imageRef}
/>
)}
</Group>
);
});
4 changes: 3 additions & 1 deletion src/core/model/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export type ShapeType =
| 'textScribbled'
| 'paragraphScribbled'
| 'fabButton'
| 'fileTree';
| 'fileTree'
| 'mouseCursor';

export const ShapeDisplayName: Record<ShapeType, string> = {
multiple: 'multiple',
Expand Down Expand Up @@ -164,6 +165,7 @@ export const ShapeDisplayName: Record<ShapeType, string> = {
paragraphScribbled: 'Paragraph Scribbled',
fabButton: 'Fab Button',
fileTree: 'File Tree',
mouseCursor: 'Mouse Cursor',
};

export type EditType = 'input' | 'textarea' | 'imageupload';
Expand Down
5 changes: 5 additions & 0 deletions src/pods/canvas/model/shape-other-props.utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,11 @@ export const generateDefaultOtherProps = (
iconSize: 'M',
stroke: BASIC_SHAPE.DEFAULT_STROKE_COLOR,
};
case 'mouseCursor':
return {
stroke: BASIC_SHAPE.DEFAULT_STROKE_COLOR,
iconSize: 'M',
};
case 'image':
return {
imageSrc: '',
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 @@ -42,6 +42,7 @@ import {
getStarShapeSizeRestrictions,
getModalCoverShapeSizeRestrictions,
getCilinderShapeSizeRestrictions,
getMouseCursorShapeSizeRestrictions,
// other imports
} from '@/common/components/mock-components/front-basic-shapes';
import {
Expand Down Expand Up @@ -177,6 +178,7 @@ const shapeSizeMap: Record<ShapeType, () => ShapeSizeRestrictions> = {
fabButton: getFabButtonShapeSizeRestrictions,
fileTree: getFileTreeShapeSizeRestrictions,
paragraphScribbled: getParagraphScribbledShapeRestrictions,
mouseCursor: getMouseCursorShapeSizeRestrictions,
};

export default shapeSizeMap;
1 change: 1 addition & 0 deletions src/pods/canvas/model/transformer.model.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ export const generateTypeOfTransformer = (shapeType: ShapeType): string[] => {
'bottom-center',
];
case 'icon':
case 'mouseCursor':
case 'multiple':
return [];
case 'image':
Expand Down
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 @@ -65,6 +65,7 @@ import {
renderLargeArrowShape,
renderCilinder,
renderImage,
renderMouseCursor,
} from './simple-basic-shapes';
import {
renderHeading1,
Expand Down Expand Up @@ -238,6 +239,8 @@ export const renderShapeComponent = (
return renderTextScribbled(shape, shapeRenderedProps);
case 'paragraphScribbled':
return renderParagraphScribbled(shape, shapeRenderedProps);
case 'mouseCursor':
return renderMouseCursor(shape, shapeRenderedProps);
default:
return renderNotFound(shape, shapeRenderedProps);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,4 @@ export * from './large-arrow.renderer';
export * from './modal-cover.rerender';
export * from './cilinder.renderer';
export * from './image.renderer';
export * from './mouse-cursor.renderer';
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
import { MouseCursorShape } from '@/common/components/mock-components/front-basic-shapes';
import { ShapeModel } from '@/core/model';
import { ShapeRendererProps } from '../model';

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

return (
<MouseCursorShape
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}
iconSize={shape.otherProps?.iconSize}
/>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ export const mockBasicShapesCollection: ItemInfo[] = [
{ thumbnailSrc: '/shapes/triangle.svg', type: 'triangle' },
{ thumbnailSrc: '/shapes/verticalLine.svg', type: 'verticalLine' },
{ thumbnailSrc: '/shapes/cilinder.svg', type: 'cilinder' },
{ thumbnailSrc: '/icons/cursor.svg', type: 'mouseCursor' },
];