Skip to content

Commit 1e1da73

Browse files
mlopezFCjavier-godoy
authored andcommitted
feat: initial implementation
1 parent 8038ab8 commit 1e1da73

24 files changed

+931
-149
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 Markdown Editor 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 Markdown Editor add-on here.
33
body:
44
- type: textarea
55
id: feature-proposal

README.md

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,26 @@
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/markdown-editor-add-on)
2+
[![Stars on vaadin.com/directory](https://img.shields.io/vaadin-directory/star/markdown-editor-addon.svg)](https://vaadin.com/directory/component/markdown-editor-add-on)
3+
[![Build Status](https://jenkins.flowingcode.com/job/markdown-editor-addon/badge/icon)](https://jenkins.flowingcode.com/job/MarkdownEditor-addon)
4+
[![Maven Central](https://img.shields.io/maven-central/v/com.flowingcode.vaadin.addons/markdown-editor-addon)](https://mvnrepository.com/artifact/com.flowingcode.vaadin.addons/markdown-editor-addon)
5+
[![Javadoc](https://img.shields.io/badge/javadoc-00b4f0)](https://javadoc.flowingcode.com/artifact/com.flowingcode.vaadin.addons/markdown-editor-addon)
56

6-
# Template Add-on
7+
# Markdown Editor Add-on
78

8-
This is a template project for building new Vaadin 24 add-ons
9+
This is a wrapper around [the React Markdown Editor component](https://github.com/uiwjs/react-md-editor).
910

1011
## Features
1112

12-
* List the features of your add-on in here
13+
* Supports both visual editing of markdown and also just viewing markdown content
14+
* Support for dark and light themes
15+
* Built in support for sanitization
1316

1417
## Online demo
1518

16-
[Online demo here](http://addonsv24.flowingcode.com/template)
19+
[Online demo here](http://addonsv24.flowingcode.com/markdown-editor)
1720

1821
## Download release
1922

20-
[Available in Vaadin Directory](https://vaadin.com/directory/component/template-addon)
23+
[Available in Vaadin Directory](https://vaadin.com/directory/component/markdown-editor-add-on)
2124

2225
### Maven install
2326

@@ -26,7 +29,7 @@ Add the following dependencies in your pom.xml file:
2629
```xml
2730
<dependency>
2831
<groupId>com.flowingcode.vaadin.addons</groupId>
29-
<artifactId>template-addon</artifactId>
32+
<artifactId>markdown-editor-addon</artifactId>
3033
<version>X.Y.Z</version>
3134
</dependency>
3235
```
@@ -43,7 +46,7 @@ To see the demo, navigate to http://localhost:8080/
4346

4447
## Release notes
4548

46-
See [here](https://github.com/FlowingCode/TemplateAddon/releases)
49+
See [here](https://github.com/FlowingCode/MarkdownEditor/releases)
4750

4851
## Issue tracking
4952

@@ -68,13 +71,33 @@ Then, follow these steps for creating a contribution:
6871

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

71-
TEMPLATE_ADDON is written by Flowing Code S.A.
74+
Markdown Editor Add-on is written by Flowing Code S.A.
7275

7376
# Developer Guide
7477

7578
## Getting started
7679

77-
Add your code samples in this section
80+
### Markdown Viewer
81+
82+
To use the viewer, instantiate it and add it to a view like this:
83+
84+
MarkdownViewer mdv = new MarkdownViewer();
85+
mdv.setSizeFull();
86+
mdv.setDataColorMode(DataColorMode.LIGTH);
87+
mdv.setContent("# h1 Heading");
88+
add(mdv);
89+
90+
### Markdown Editor
91+
92+
To use the editor, similar to the viewer, instantiate it and add it to a view like this:
93+
94+
MarkdownEditor mde = new MarkdownEditor();
95+
mde.setSizeFull();
96+
mde.setPlaceholder("Enter Markdown here");
97+
mde.setMaxLength(500);
98+
mde.setDataColorMode(DataColorMode.LIGTH);
99+
100+
To obtain the edited value, call `getContent()`
78101

79102
## Special configuration when using Spring
80103

pom.xml

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
<modelVersion>4.0.0</modelVersion>
66

77
<groupId>com.flowingcode.vaadin.addons</groupId>
8-
<artifactId>template-addon</artifactId>
8+
<artifactId>markdown-editor-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>Markdown Editor Add-on</name>
11+
<description>Markdown Editor for Vaadin Flow</description>
1212
<url>https://www.flowingcode.com/en/open-source/</url>
1313

1414
<properties>
@@ -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/MarkdownEditor</url>
43+
<connection>scm:git:git://github.com/FlowingCode/MarkdownEditor.git</connection>
44+
<developerConnection>scm:git:ssh://git@github.com:/FlowingCode/MarkdownEditor.git</developerConnection>
4545
<tag>master</tag>
4646
</scm>
4747

@@ -126,6 +126,7 @@
126126
<groupId>com.flowingcode.vaadin.addons.demo</groupId>
127127
<artifactId>commons-demo</artifactId>
128128
<version>${flowingcode.commons.demo.version}</version>
129+
<scope>test</scope>
129130
</dependency>
130131
<dependency>
131132
<groupId>org.slf4j</groupId>
@@ -226,8 +227,14 @@
226227
<licenseName>apache_v2</licenseName>
227228
<addJavaLicenseAfterPackage>false</addJavaLicenseAfterPackage>
228229
<excludes>
229-
<exclude>**/dev-bundle/**</exclude>
230+
<exclude>**/main/dev-bundle/**</exclude>
231+
<exclude>**/main/bundles/**</exclude>
232+
<exclude>**/main/frontend/**</exclude>
233+
<exclude>**/main/frontend/**</exclude>
230234
</excludes>
235+
<extraExtensions>
236+
<tsx>java</tsx>
237+
</extraExtensions>
231238
</configuration>
232239
</plugin>
233240
<plugin>
@@ -293,7 +300,7 @@
293300
<plugin>
294301
<groupId>org.apache.maven.plugins</groupId>
295302
<artifactId>maven-javadoc-plugin</artifactId>
296-
<version>3.0.1</version>
303+
<version>3.10.0</version>
297304
<executions>
298305
<execution>
299306
<id>attach-javadocs</id>
@@ -306,7 +313,10 @@
306313
<configuration>
307314
<quiet>true</quiet>
308315
<doclint>none</doclint>
309-
<additionalparam>-Xdoclint:none</additionalparam>
316+
<failOnWarnings>true</failOnWarnings>
317+
<links>
318+
<link>https://javadoc.io/doc/com.vaadin/vaadin-platform-javadoc/${vaadin.version}</link>
319+
</links>
310320
</configuration>
311321
</plugin>
312322
<plugin>
Lines changed: 96 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/*-
2+
* #%L
3+
* Markdown Editor 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+
package com.flowingcode.vaadin.addons.markdown;
21+
22+
import com.vaadin.flow.component.HasSize;
23+
import com.vaadin.flow.component.dependency.CssImport;
24+
import com.vaadin.flow.component.dependency.NpmPackage;
25+
import com.vaadin.flow.component.react.ReactAdapterComponent;
26+
27+
/**
28+
* Base class for Markdown based Components.
29+
*/
30+
@SuppressWarnings("serial")
31+
@CssImport("./styles/markdown-editor-styles.css")
32+
@NpmPackage(value = "mermaid", version = "11.2.1")
33+
@NpmPackage(value = "@uiw/react-md-editor", version = "4.0.4")
34+
@NpmPackage(value = "dompurify", version = "3.1.6")
35+
public class BaseMarkdownComponent extends ReactAdapterComponent implements HasSize {
36+
37+
/**
38+
* Defines the color schemes for the Markdown component.
39+
*
40+
* The color mode can be set using the {@link #setDataColorMode(DataColorMode)} method.
41+
*
42+
* <ul>
43+
* <li>{@link #DARK}: Dark color scheme.
44+
* <li>{@link #LIGTH}: Light color scheme.
45+
* <li>{@link #AUTO}: Automatically detects the color scheme based on the user's system settings.
46+
* </ul>
47+
*/
48+
public enum DataColorMode {DARK,LIGTH,AUTO};
49+
50+
/**
51+
* Base constructor that receives the content of the markdown component.
52+
*
53+
* @param content content to be used in the Markdown component
54+
*/
55+
public BaseMarkdownComponent(String content) {
56+
setContent(content);
57+
}
58+
59+
/**
60+
* Sets the content of the Markdown component.
61+
*
62+
* @return the content of the Markdown component
63+
*/
64+
public String getContent() {
65+
return getState("content", String.class);
66+
}
67+
68+
/**
69+
* Gets the content of the Markdown component.
70+
*
71+
* @param content retrieved from the state of the component
72+
*/
73+
public void setContent(String content) {
74+
setState("content", content);
75+
}
76+
77+
/**
78+
* Sets the color mode of the Markdown component.
79+
*
80+
* @param mode the color mode of the component
81+
*/
82+
public void setDataColorMode(DataColorMode mode) {
83+
switch (mode) {
84+
case DARK:
85+
getElement().setAttribute("data-color-mode", "dark");
86+
break;
87+
case LIGTH:
88+
getElement().setAttribute("data-color-mode", "light");
89+
break;
90+
case AUTO:
91+
getElement().removeAttribute("data-color-mode");
92+
break;
93+
}
94+
}
95+
96+
}
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*-
2+
* #%L
3+
* Markdown Editor 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.markdown;
22+
23+
import com.vaadin.flow.component.Tag;
24+
import com.vaadin.flow.component.dependency.JsModule;
25+
import com.vaadin.flow.component.dependency.NpmPackage;
26+
27+
/**
28+
* Markdown component that allows editing the contents.
29+
*/
30+
@SuppressWarnings("serial")
31+
@NpmPackage(value = "rehype-sanitize", version = "6.0.0")
32+
@JsModule("./markdown-editor.tsx")
33+
@Tag("markdown-editor")
34+
public class MarkdownEditor extends BaseMarkdownComponent {
35+
36+
/**
37+
* Constructor with empty content.
38+
*/
39+
public MarkdownEditor() {
40+
super(null);
41+
}
42+
43+
/**
44+
* Constructor with default content.
45+
*
46+
* @param content default content for the Markdown editor
47+
*/
48+
public MarkdownEditor(String content) {
49+
super(content);
50+
}
51+
52+
/**
53+
* Returns the placeholder text for the Markdown editor.
54+
*
55+
* @return the placeholder text
56+
*/
57+
public String getPlaceholder() {
58+
return getState("placeholder", String.class);
59+
}
60+
61+
/**
62+
* Sets the placeholder text for the Markdown editor.
63+
*
64+
* @param placeholder the placeholder text
65+
*/
66+
public void setPlaceholder(String placeholder) {
67+
setState("placeholder", placeholder);
68+
}
69+
70+
/**
71+
* Returns the configured maximum character count for the Markdown editor.
72+
*
73+
* @return the configured maximum character count
74+
*/
75+
public int getMaxLength() {
76+
return getState("maxLength", Integer.class);
77+
}
78+
79+
/**
80+
* Sets the maximum character count for the Markdown editor.
81+
*
82+
* @param maxlength the maximum character count
83+
*/
84+
public void setMaxLength(int maxlength) {
85+
setState("maxLength", maxlength);
86+
}
87+
88+
}

0 commit comments

Comments
 (0)