Skip to content

Commit 3930a03

Browse files
paodbjavier-godoy
authored andcommitted
feat: initial implementation
1 parent 9f0e073 commit 3930a03

File tree

22 files changed

+1004
-109
lines changed

22 files changed

+1004
-109
lines changed

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Bug Report
2-
description: Please report issues related to TEMPLATE_ADDON here.
2+
description: Please report issues related to Image Crop add-on here.
33
body:
44
- type: textarea
55
id: problem-description

.github/ISSUE_TEMPLATE/feature-request.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
name: Feature Request
2-
description: Please add feature suggestions related to TEMPLATE_ADDON here.
2+
description: Please add feature suggestions related to Image Crop add-on here.
33
body:
44
- type: textarea
55
id: feature-proposal

.gitignore

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ drivers
1313
tsconfig.json
1414
.idea
1515
types.d.ts
16-
/frontend/generated
17-
/frontend/index.html
1816
vite.generated.ts
1917
vite.config.ts
20-
/src/main/dev-bundle
18+
/src/main/dev-bundle
19+
/src/main/bundles
20+
/src/main/frontend/generated
21+
/src/main/frontend/index.html

README.md

Lines changed: 41 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,37 @@
1-
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/template-addon)
2-
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/template-addon.svg)](https://vaadin.com/directory/component/template-addon)
3-
[![Build Status](https://jenkins.flowingcode.com/job/template-addon/badge/icon)](https://jenkins.flowingcode.com/job/template-addon)
4-
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/template-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/template-addon)
1+
[![Published on Vaadin Directory](https://img.shields.io/badge/Vaadin%20Directory-published-00b4f0.svg)](https://vaadin.com/directory/component/image-crop-add-on)
2+
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/image-crop-add-on.svg)](https://vaadin.com/directory/component/image-crop-add-on)
3+
[![Build Status](https://jenkins.flowingcode.com/job/ImageCrop-addon/badge/icon)](https://jenkins.flowingcode.com/job/ImageCrop-addon)
4+
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/image-crop-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/image-crop-addon)
55

6-
# Template Add-on
6+
# Image Crop Add-on
77

8-
This is a template project for building new Vaadin 24 add-ons
8+
Component for cropping images. Wrapper for React component [react-image-crop](https://www.npmjs.com/package/react-image-crop).
99

1010
## Features
1111

12-
* List the features of your add-on in here
12+
The component allows to crop images and configure the following properties for a customized crop:
13+
* crop dimensions (unit, x and y coordinates, width, and height)
14+
* aspect ratio (for example, 1 for a square or 16/9 for landscape)
15+
* circular crop (selection are has circular shape)
16+
* keep selection (selection can't be disabled if the user clicks outside the selection area)
17+
* disabled (cannot resize or draw a new crop)
18+
* locked (cannot create or resize a crop, but can still drag the existing crop around)
19+
* min width (minimum crop width)
20+
* min height (minimum crop height)
21+
* max width (maximum crop width)
22+
* max height (maximum crop height)
23+
* rule of thirds (to show rule of thirds lines in the cropped area)
24+
25+
The cropped image result can be obtain as a URI using `getCroppedImageDataUri` method
26+
or as a Base64 encoded byte array by using `getCroppedImageBase64` method.
1327

1428
## Online demo
1529

16-
[Online demo here](http://addonsv24.flowingcode.com/template)
30+
[Online demo here](http://addonsv24.flowingcode.com/image-crop)
1731

1832
## Download release
1933

20-
[Available in Vaadin Directory](https://vaadin.com/directory/component/template-addon)
34+
[Available in Vaadin Directory](https://vaadin.com/directory/component/image-crop-add-on)
2135

2236
### Maven install
2337

@@ -26,7 +40,7 @@ Add the following dependencies in your pom.xml file:
2640
```xml
2741
<dependency>
2842
<groupId>com.flowingcode.vaadin.addons</groupId>
29-
<artifactId>template-addon</artifactId>
43+
<artifactId>image-crop-addon</artifactId>
3044
<version>X.Y.Z</version>
3145
</dependency>
3246
```
@@ -50,7 +64,7 @@ To see the demo, navigate to http://localhost:8080/
5064

5165
## Release notes
5266

53-
See [here](https://github.com/FlowingCode/TemplateAddon/releases)
67+
See [here](https://github.com/FlowingCode/ImageCrop/releases)
5468

5569
## Issue tracking
5670

@@ -75,20 +89,32 @@ Then, follow these steps for creating a contribution:
7589

7690
This add-on is distributed under Apache License 2.0. For license terms, see LICENSE.txt.
7791

78-
TEMPLATE_ADDON is written by Flowing Code S.A.
92+
Image Crop Add-on is written by Flowing Code S.A.
7993

8094
# Developer Guide
8195

8296
## Getting started
8397

84-
Add your code samples in this section
98+
* Basic use
99+
100+
```java
101+
Image image = new Image("images/empty-plant.png", "image to crop");
102+
ImageCrop imageCrop = new ImageCrop(image);
103+
add(imageCrop);
104+
```
105+
106+
* Get cropped image
107+
108+
```java
109+
Image croppedImage = new Image(imageCrop.getCroppedImageDataUri(), "cropped image")
110+
```
85111

86112
## Special configuration when using Spring
87113

88114
By default, Vaadin Flow only includes ```com/vaadin/flow/component``` to be always scanned for UI components and views. For this reason, the add-on might need to be whitelisted in order to display correctly.
89115

90-
To do so, just add ```com.flowingcode``` to the ```vaadin.whitelisted-packages``` property in ```src/main/resources/application.properties```, like:
116+
To do so, just add ```com.flowingcode``` to the ```vaadin.allowed-packages``` property in ```src/main/resources/application.properties```, like:
91117

92-
```vaadin.whitelisted-packages = com.vaadin,org.vaadin,dev.hilla,com.flowingcode```
118+
```vaadin.allowed-packages = com.vaadin,org.vaadin,dev.hilla,com.flowingcode```
93119

94120
More information on Spring whitelisted configuration [here](https://vaadin.com/docs/latest/integrations/spring/configuration/#configure-the-scanning-of-packages).

pom.xml

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,22 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.flowingcode.vaadin.addons</groupId>
8-
<artifactId>template-addon</artifactId>
8+
<artifactId>image-crop-addon</artifactId>
99
<version>1.0.0-SNAPSHOT</version>
10-
<name>Template Add-on</name>
11-
<description>Template Add-on for Vaadin Flow</description>
10+
<name>Image Crop Add-on</name>
11+
<description>Image Crop Add-on for Vaadin Flow</description>
1212
<url>https://www.flowingcode.com/en/open-source/</url>
1313

1414
<properties>
15-
<vaadin.version>24.3.0</vaadin.version>
15+
<vaadin.version>24.4.6</vaadin.version>
1616
<selenium.version>4.10.0</selenium.version>
1717
<maven.compiler.source>17</maven.compiler.source>
1818
<maven.compiler.target>17</maven.compiler.target>
1919
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
2020
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
2121
<drivers.dir>${project.basedir}/drivers</drivers.dir>
22-
<jetty.version>11.0.12</jetty.version>
23-
<flowingcode.commons.demo.version>3.9.0</flowingcode.commons.demo.version>
22+
<jetty.version>11.0.21</jetty.version>
23+
<flowingcode.commons.demo.version>4.1.0</flowingcode.commons.demo.version>
2424
<frontend.hotdeploy>true</frontend.hotdeploy>
2525
</properties>
2626

@@ -29,7 +29,7 @@
2929
<url>https://www.flowingcode.com</url>
3030
</organization>
3131

32-
<inceptionYear>2023</inceptionYear>
32+
<inceptionYear>2024</inceptionYear>
3333
<licenses>
3434
<license>
3535
<name>Apache 2</name>
@@ -39,9 +39,9 @@
3939
</licenses>
4040

4141
<scm>
42-
<url>https://github.com/FlowingCode/AddonStarter24</url>
43-
<connection>scm:git:git://github.com/FlowingCode/AddonStarter24.git</connection>
44-
<developerConnection>scm:git:ssh://git@github.com:/FlowingCode/AddonStarter24.git</developerConnection>
42+
<url>https://github.com/FlowingCode/ImageCrop</url>
43+
<connection>scm:git:git://github.com/FlowingCode/ImageCrop.git</connection>
44+
<developerConnection>scm:git:ssh://git@github.com:/FlowingCode/ImageCrop.git</developerConnection>
4545
<tag>master</tag>
4646
</scm>
4747

@@ -156,6 +156,12 @@
156156
<version>5.1.1</version>
157157
<scope>test</scope>
158158
</dependency>
159+
<dependency>
160+
<groupId>org.mockito</groupId>
161+
<artifactId>mockito-core</artifactId>
162+
<version>3.12.4</version>
163+
<scope>test</scope>
164+
</dependency>
159165
</dependencies>
160166

161167
<build>
@@ -254,7 +260,7 @@
254260
<artifactId>jetty-maven-plugin</artifactId>
255261
<version>${jetty.version}</version>
256262
<configuration>
257-
<scanIntervalSeconds>3</scanIntervalSeconds>
263+
<scan>3</scan>
258264
<!-- Use test scope because the UI/demo classes are in the test package. -->
259265
<useTestScope>true</useTestScope>
260266
<webApp>
@@ -363,7 +369,7 @@
363369
<artifactId>jetty-maven-plugin</artifactId>
364370
<version>${jetty.version}</version>
365371
<configuration>
366-
<scanIntervalSeconds>0</scanIntervalSeconds>
372+
<scan>0</scan>
367373
<supportedPackagings>
368374
<supportedPackaging>jar</supportedPackaging>
369375
</supportedPackagings>
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*-
2+
* #%L
3+
* Image Crop Add-on
4+
* %%
5+
* Copyright (C) 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package com.flowingcode.vaadin.addons.imagecrop;
22+
23+
/**
24+
* Represents crop dimensions.
25+
* <p>
26+
* The crop dimensions are defined by the unit, x and y coordinates, width, and
27+
* height.
28+
*
29+
* @param unit the unit of the crop dimensions, can be 'px' (pixels) or '%'
30+
* (percentage).
31+
* @param x the x-coordinate of the cropped area.
32+
* @param y the y-coordinate of the cropped area.
33+
* @param width the width of the cropped area
34+
* @param height the height of the cropped area
35+
*/
36+
public record Crop(String unit, int x, int y, int width, int height) {
37+
38+
/**
39+
* Returns a string representation of the Crop object.
40+
*
41+
* @return A string representing the crop dimensions in the format:
42+
* "{ unit: %s, x: %s, y: %s, width: %s, height: %s }"
43+
* where %s is replaced by the corresponding value.
44+
*/
45+
@Override
46+
public final String toString() {
47+
return "{ unit: %s, x: %s, y: %s, width: %s, height: %s }".formatted(unit, x, y, width, height);
48+
}
49+
50+
}
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/*-
2+
* #%L
3+
* Image Crop Add-on
4+
* %%
5+
* Copyright (C) 2024 Flowing Code
6+
* %%
7+
* Licensed under the Apache License, Version 2.0 (the "License");
8+
* you may not use this file except in compliance with the License.
9+
* You may obtain a copy of the License at
10+
*
11+
* http://www.apache.org/licenses/LICENSE-2.0
12+
*
13+
* Unless required by applicable law or agreed to in writing, software
14+
* distributed under the License is distributed on an "AS IS" BASIS,
15+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
* See the License for the specific language governing permissions and
17+
* limitations under the License.
18+
* #L%
19+
*/
20+
21+
package com.flowingcode.vaadin.addons.imagecrop;
22+
23+
import com.vaadin.flow.component.ComponentEvent;
24+
import com.vaadin.flow.component.DomEvent;
25+
import com.vaadin.flow.component.EventData;
26+
27+
/**
28+
* Represents an event triggered when an image is cropped and encoded.
29+
*/
30+
@DomEvent("cropped-image")
31+
public class CroppedImageEvent extends ComponentEvent<ImageCrop> {
32+
33+
private String croppedImageDataUri;
34+
35+
/**
36+
* Constructs a new CroppedImageEvent.
37+
*
38+
* @param source the source of the event
39+
* @param fromClient <code>true</code> if the event originated from the client-side,
40+
* <code>false</code> otherwise
41+
* @param croppedImageDataUri the data URL of the cropped image
42+
*/
43+
public CroppedImageEvent(ImageCrop source, boolean fromClient,
44+
@EventData("event.detail.croppedImageDataUri") String croppedImageDataUri) {
45+
super(source, fromClient);
46+
this.croppedImageDataUri = croppedImageDataUri;
47+
}
48+
49+
/**
50+
* Returns the cropped image data URL.
51+
*
52+
* @return the cropped image data URL
53+
*/
54+
public String getCroppedImageDataUri() {
55+
return this.croppedImageDataUri;
56+
}
57+
}

0 commit comments

Comments
 (0)