Skip to content

Commit 0f838f1

Browse files
committed
feat: initial implementation
1 parent 8038ab8 commit 0f838f1

22 files changed

+708
-138
lines changed

README.md

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,25 @@
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)
55

6-
# Template Add-on
6+
# Markdown Editor Add-on
77

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

1010
## Features
1111

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

1416
## Online demo
1517

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

1820
## Download release
1921

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

2224
### Maven install
2325

@@ -26,7 +28,7 @@ Add the following dependencies in your pom.xml file:
2628
```xml
2729
<dependency>
2830
<groupId>com.flowingcode.vaadin.addons</groupId>
29-
<artifactId>template-addon</artifactId>
31+
<artifactId>markdown-editor-addon</artifactId>
3032
<version>X.Y.Z</version>
3133
</dependency>
3234
```
@@ -43,7 +45,7 @@ To see the demo, navigate to http://localhost:8080/
4345

4446
## Release notes
4547

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

4850
## Issue tracking
4951

@@ -68,7 +70,7 @@ Then, follow these steps for creating a contribution:
6870

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

71-
TEMPLATE_ADDON is written by Flowing Code S.A.
73+
Markdown Editor is written by Flowing Code S.A.
7274

7375
# Developer Guide
7476

pom.xml

Lines changed: 6 additions & 6 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

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
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.react.ReactAdapterComponent;
25+
26+
/**
27+
* Base class for Markdown based Components
28+
*/
29+
@SuppressWarnings("serial")
30+
@CssImport("./styles/markdown-editor-styles.css")
31+
public class BaseMarkdownComponent extends ReactAdapterComponent implements HasSize {
32+
33+
/**
34+
* Colors schemes for the Markdown component
35+
*/
36+
public enum DATA_COLOR_MODE {DARK,LIGTH,AUTO};
37+
38+
/**
39+
* Base constructor that receives the content of the markdown component.
40+
*
41+
* @param content content to be used in the Markdown component
42+
*/
43+
public BaseMarkdownComponent(String content) {
44+
setContent(content);
45+
}
46+
47+
/**
48+
* Sets the content of the Markdown component.
49+
* @return
50+
*/
51+
public String getContent() {
52+
return getState("content", String.class);
53+
}
54+
55+
/**
56+
* Gets the content of the Markdown component.
57+
*
58+
* @param content retrieved from the state of the component
59+
*/
60+
public void setContent(String content) {
61+
setState("content", content);
62+
}
63+
64+
/**
65+
* Sets the color mode of the Markdown component
66+
*
67+
* @param mode the color mode of the component
68+
*/
69+
public void setDataColorMode(DATA_COLOR_MODE mode) {
70+
switch (mode) {
71+
case DARK:
72+
getElement().setAttribute("data-color-mode", "dark");
73+
break;
74+
case LIGTH:
75+
getElement().setAttribute("data-color-mode", "light");
76+
break;
77+
case AUTO:
78+
getElement().removeAttribute("data-color-mode");
79+
break;
80+
}
81+
}
82+
83+
}
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
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 = "@uiw/react-md-editor", version = "4.0.4")
32+
@NpmPackage(value = "rehype-sanitize", version = "6.0.0")
33+
@JsModule("./markdown-editor.tsx")
34+
@Tag("markdown-editor")
35+
public class MarkdownEditor extends BaseMarkdownComponent {
36+
37+
/**
38+
* Default constructor with empty content
39+
*/
40+
public MarkdownEditor() {
41+
super("");
42+
}
43+
44+
/**
45+
* Constructor with default content.
46+
*
47+
* @param content default content for the Markdown editor
48+
*/
49+
public MarkdownEditor(String content) {
50+
super(content);
51+
}
52+
53+
/**
54+
* Returns the placeholder text for the Markdown editor.
55+
*
56+
* @return the placeholder text
57+
*/
58+
public String getPlaceholder() {
59+
return getState("placeholder", String.class);
60+
}
61+
62+
/**
63+
* Sets the placeholder text for the Markdown editor.
64+
*
65+
* @param placeholder the placeholder text
66+
*/
67+
public void setPlaceholder(String placeholder) {
68+
setState("placeholder", placeholder);
69+
}
70+
71+
/**
72+
* Returns the configured maximum length for the Markdown editor.
73+
*
74+
* @return the configured maximum length
75+
*/
76+
public int getMaxLength() {
77+
return getState("maxLength", Integer.class);
78+
}
79+
80+
/**
81+
* Sets the maximum length for the Markdown editor.
82+
*
83+
* @param maxlength the maximum length
84+
*/
85+
public void setMaxLength(int maxlength) {
86+
setState("maxLength", maxlength);
87+
}
88+
89+
}
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
/*-
22
* #%L
3-
* Template Add-on
3+
* Markdown Editor Add-on
44
* %%
55
* Copyright (C) 2024 Flowing Code
66
* %%
77
* Licensed under the Apache License, Version 2.0 (the "License");
88
* you may not use this file except in compliance with the License.
99
* You may obtain a copy of the License at
10-
*
10+
*
1111
* http://www.apache.org/licenses/LICENSE-2.0
12-
*
12+
*
1313
* Unless required by applicable law or agreed to in writing, software
1414
* distributed under the License is distributed on an "AS IS" BASIS,
1515
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
@@ -18,15 +18,33 @@
1818
* #L%
1919
*/
2020

21-
package com.flowingcode.vaadin.addons.template;
21+
package com.flowingcode.vaadin.addons.markdown;
2222

2323
import com.vaadin.flow.component.Tag;
2424
import com.vaadin.flow.component.dependency.JsModule;
2525
import com.vaadin.flow.component.dependency.NpmPackage;
26-
import com.vaadin.flow.component.html.Div;
26+
import com.vaadin.flow.component.react.ReactAdapterComponent;
2727

2828
@SuppressWarnings("serial")
29-
@NpmPackage(value = "@polymer/paper-input", version = "3.2.1")
30-
@JsModule("@polymer/paper-input/paper-input.js")
31-
@Tag("paper-input")
32-
public class TemplateAddon extends Div {}
29+
@NpmPackage(value = "@uiw/react-md-editor", version = "4.0.4")
30+
@JsModule("./markdown-viewer.tsx")
31+
@Tag("markdown-viewer")
32+
public class MarkdownViewer extends BaseMarkdownComponent {
33+
34+
/**
35+
* Default constructor with empty content
36+
*/
37+
public MarkdownViewer() {
38+
super("");
39+
}
40+
41+
/**
42+
* Constructor that receives the default content
43+
*
44+
* @param string
45+
*/
46+
public MarkdownViewer(String content) {
47+
super(content);
48+
}
49+
50+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
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+
.w-md-editor-text {
21+
height:100%;
22+
}
23+
.w-md-editor-text textarea {
24+
height:100%;
25+
}
26+
27+
.w-md-editor {
28+
height: calc(100% - 3px) !important;
29+
width: calc(100% - 2px) !important;
30+
top: 1px;
31+
left: 1px;
32+
}
33+
34+
.wmde-markdown {
35+
overflow: auto;
36+
height: 100%;
37+
}

src/main/resources/META-INF/frontend/styles/static_addon_styles

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import {type ReactElement} from 'react';
2+
import MDEditor from '@uiw/react-md-editor/nohighlight';
3+
import {ReactAdapterElement, type RenderHooks} from "Frontend/generated/flow/ReactAdapter";
4+
import React from 'react';
5+
import "@uiw/react-md-editor/markdown-editor.css";
6+
import "@uiw/react-markdown-preview/markdown.css";
7+
import rehypeSanitize from "rehype-sanitize";
8+
9+
class MarkdownEditorElement extends ReactAdapterElement {
10+
11+
protected override render(hooks: RenderHooks): ReactElement | null {
12+
const [content, setContent] = hooks.useState<string>("content");
13+
const [placeholder] = hooks.useState<string>("placeholder");
14+
const [maxLength] = hooks.useState<number>("maxLength");
15+
16+
return <MDEditor visibleDragbar={false}
17+
value={content}
18+
onChange={setContent}
19+
textareaProps={{
20+
placeholder: placeholder,
21+
maxLength: maxLength
22+
}}
23+
previewOptions={{
24+
rehypePlugins: [[rehypeSanitize]],
25+
}}
26+
/>;
27+
}
28+
}
29+
30+
customElements.define("markdown-editor",MarkdownEditorElement);

0 commit comments

Comments
 (0)