-
Notifications
You must be signed in to change notification settings - Fork 20
Feature/#754 create scribble paragraph under low mock #763
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
brauliodiez
merged 8 commits into
dev
from
feature/#754-create-scribble-paragraph-under-low-mock
May 6, 2025
Merged
Changes from 7 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
d130b04
Implement renderer for scribbled paragraph shape
gustedeveloper 7352338
Integrate scribbled paragraph into core models and canvas renderer
gustedeveloper d3d802a
Add scribbled paragraph to low wireframe gallery data
gustedeveloper d4c3c71
Implement paragraph scribbled shape logic
gustedeveloper 7fded32
Externalize paragraph paths calculation to business file
gustedeveloper 2a4efaf
Extract scribbled paragraph constant to const file and create barrel …
gustedeveloper 428b891
Create paragraph scribbled svg
gustedeveloper beee89c
Merge branch 'dev' into feature/#754-create-scribble-paragraph-under-…
brauliodiez File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions
1
...onents/mock-components/front-low-wireframes-components/paragraph-scribbled-shape/index.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export * from './paragraph-scribbled-shape'; |
69 changes: 69 additions & 0 deletions
69
...s/front-low-wireframes-components/paragraph-scribbled-shape/paragraph-scribbled-shape.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
import { forwardRef, useMemo } from 'react'; | ||
import { Group, Path, Rect } from 'react-konva'; | ||
import { ShapeSizeRestrictions, ShapeType } from '@/core/model'; | ||
import { ShapeProps } from '../../shape.model'; | ||
import { useShapeProps } from '../../../shapes/use-shape-props.hook'; | ||
import { BASIC_SHAPE } from '../../front-components/shape.const'; | ||
import { useGroupShapeProps } from '../../mock-components.utils'; | ||
import { fitSizeToShapeSizeRestrictions } from '@/common/utils/shapes'; | ||
import { MIN_LINE_HEIGHT } from './paragraph-scribbled.const'; | ||
import { calculateParagraphPaths } from './paragraph-scribbled.business'; | ||
|
||
const paragraphScribbledShapeRestrictions: ShapeSizeRestrictions = { | ||
minWidth: 100, | ||
minHeight: MIN_LINE_HEIGHT, | ||
maxWidth: -1, | ||
maxHeight: -1, | ||
defaultWidth: 300, | ||
defaultHeight: 150, | ||
}; | ||
|
||
export const getParagraphScribbledShapeRestrictions = | ||
(): ShapeSizeRestrictions => paragraphScribbledShapeRestrictions; | ||
|
||
const shapeType: ShapeType = 'paragraphScribbled'; | ||
|
||
export const ParagraphScribbled = forwardRef<any, ShapeProps>((props, ref) => { | ||
const { width, height, id, otherProps, ...shapeProps } = props; | ||
|
||
const { stroke } = useShapeProps(otherProps, BASIC_SHAPE); | ||
const commonGroupProps = useGroupShapeProps( | ||
props, | ||
{ width, height }, | ||
shapeType, | ||
ref | ||
); | ||
|
||
const restrictedSize = fitSizeToShapeSizeRestrictions( | ||
paragraphScribbledShapeRestrictions, | ||
width, | ||
height | ||
); | ||
|
||
const { width: restrictedWidth, height: restrictedHeight } = restrictedSize; | ||
|
||
const paths = useMemo(() => { | ||
return calculateParagraphPaths(restrictedWidth, restrictedHeight, id); | ||
}, [restrictedWidth, restrictedHeight, id]); | ||
|
||
return ( | ||
<Group {...commonGroupProps} {...shapeProps}> | ||
{paths.map((path, idx) => ( | ||
<Path | ||
key={idx} | ||
data={path} | ||
stroke={stroke} | ||
strokeWidth={3} | ||
lineCap="round" | ||
lineJoin="round" | ||
/> | ||
))} | ||
<Rect | ||
width={restrictedSize.width} | ||
height={restrictedSize.height} | ||
stroke={stroke} | ||
strokeWidth={0} | ||
/> | ||
</Group> | ||
); | ||
}); |
36 changes: 36 additions & 0 deletions
36
...front-low-wireframes-components/paragraph-scribbled-shape/paragraph-scribbled.business.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
import { calculatePath } from '../text-scribbled-shape/text-scribbled.business'; | ||
import { MIN_LINE_HEIGHT } from './paragraph-scribbled.const'; | ||
|
||
export const calculateParagraphPaths = ( | ||
restrictedWidth: number, | ||
restrictedHeight: number, | ||
id: string | ||
): string[] => { | ||
// Calculate how many lines fit based on the height | ||
const numLines = Math.max(1, Math.trunc(restrictedHeight / MIN_LINE_HEIGHT)); | ||
|
||
return Array.from({ length: numLines }).map((_, i) => { | ||
const lineY = i * MIN_LINE_HEIGHT; | ||
const lineId = `${id}-${i}`; | ||
const rawPath = calculatePath(restrictedWidth, MIN_LINE_HEIGHT, lineId); | ||
|
||
// Adjust the path to shift Y coordinate for each line | ||
// 🔍 Step by step: | ||
// The path assumes the text is vertically centered in a block of given height (e.g., 25px). | ||
// If you just drew this path multiple times, all lines would overlap. | ||
// To fix that, we shift the Y coordinate for each point in the path. | ||
// | ||
// Regular expression: /\d+,\d+/g | ||
// Finds all x,y coordinates in the path string (e.g., "10,12", "15,11"). | ||
// We split each coordinate, convert y to number, add vertical offset (lineY), | ||
// then reassemble the coordinate string. | ||
const shiftedPath = rawPath.replace(/\d+,\d+/g, match => { | ||
const [xStr, yStr] = match.split(','); | ||
const x = parseFloat(xStr); | ||
const y = parseFloat(yStr) + lineY; | ||
return `${x},${y}`; | ||
}); | ||
|
||
return shiftedPath; | ||
}); | ||
}; | ||
1 change: 1 addition & 0 deletions
1
...ts/front-low-wireframes-components/paragraph-scribbled-shape/paragraph-scribbled.const.ts
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export const MIN_LINE_HEIGHT = 25; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...s/canvas/shape-renderer/simple-low-wireframes-components/paragraph-scribbled.renderer.tsx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { ShapeRendererProps } from '../model'; | ||
import { ShapeModel } from '@/core/model'; | ||
import { ParagraphScribbled } from '@/common/components/mock-components/front-low-wireframes-components/paragraph-scribbled-shape'; | ||
|
||
export const renderParagraphScribbled = ( | ||
shape: ShapeModel, | ||
shapeRenderedProps: ShapeRendererProps | ||
) => { | ||
const { handleSelected, shapeRefs, handleDragEnd, handleTransform } = | ||
shapeRenderedProps; | ||
|
||
return ( | ||
<ParagraphScribbled | ||
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} | ||
text={shape.text || 'Scribbled Paragraph'} | ||
otherProps={shape.otherProps} | ||
/> | ||
); | ||
}; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that its a good idea create a units to this function