View Javadoc
1   /*
2    * Copyright (c) 2011-2024 PrimeFaces Extensions
3    *
4    *  Permission is hereby granted, free of charge, to any person obtaining a copy
5    *  of this software and associated documentation files (the "Software"), to deal
6    *  in the Software without restriction, including without limitation the rights
7    *  to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8    *  copies of the Software, and to permit persons to whom the Software is
9    *  furnished to do so, subject to the following conditions:
10   *
11   *  The above copyright notice and this permission notice shall be included in
12   *  all copies or substantial portions of the Software.
13   *
14   *  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15   *  IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16   *  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17   *  AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18   *  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19   *  OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20   *  THE SOFTWARE.
21   */
22  package org.primefaces.extensions.component.markdowneditor;
23  
24  import javax.faces.application.ResourceDependency;
25  
26  import org.primefaces.extensions.component.base.AbstractEditorInputTextArea;
27  import org.primefaces.extensions.util.Constants;
28  
29  /**
30   * Markdown Editor.
31   *
32   * @since 14.0.0
33   */
34  @ResourceDependency(library = "primefaces", name = "components.css")
35  @ResourceDependency(library = "primefaces", name = "jquery/jquery.js")
36  @ResourceDependency(library = "primefaces", name = "jquery/jquery-plugins.js")
37  @ResourceDependency(library = "primefaces", name = "core.js")
38  @ResourceDependency(library = Constants.LIBRARY, name = "markdowneditor/markdowneditor.css")
39  @ResourceDependency(library = Constants.LIBRARY, name = "markdowneditor/markdowneditor.js")
40  public class MarkdownEditor extends AbstractEditorInputTextArea {
41  
42      public static final String COMPONENT_TYPE = "org.primefaces.extensions.component.MarkdownEditor";
43      public static final String COMPONENT_FAMILY = "org.primefaces.extensions.component";
44      public static final String DEFAULT_RENDERER = "org.primefaces.extensions.component.MarkdownEditorRenderer";
45  
46      // @formatter:off
47      @SuppressWarnings("java:S115")
48      public enum PropertyKeys {
49          indentWithTabs,
50          lineNumbers,
51          maxHeight,
52          minHeight,
53          mode,
54          placeholder,
55          promptURLs,
56          sideBySideFullscreen,
57          tabSize,
58      }
59      // @formatter:on
60  
61      public MarkdownEditor() {
62          setRendererType(DEFAULT_RENDERER);
63      }
64  
65      @Override
66      public String getFamily() {
67          return COMPONENT_FAMILY;
68      }
69  
70      public String getPlaceholder() {
71          return (String) getStateHelper().eval(PropertyKeys.placeholder, null);
72      }
73  
74      public void setPlaceholder(String placeholder) {
75          getStateHelper().put(PropertyKeys.placeholder, placeholder);
76      }
77  
78      public String getMode() {
79          return (String) getStateHelper().eval(PropertyKeys.mode, "wysiwyg");
80      }
81  
82      public void setMode(String mode) {
83          getStateHelper().put(PropertyKeys.mode, mode);
84      }
85  
86      public String getMinHeight() {
87          return (String) getStateHelper().eval(PropertyKeys.minHeight, "300px");
88      }
89  
90      public void setMinHeight(String minHeight) {
91          getStateHelper().put(PropertyKeys.minHeight, minHeight);
92      }
93  
94      public String getMaxHeight() {
95          return (String) getStateHelper().eval(PropertyKeys.maxHeight, null);
96      }
97  
98      public void setMaxHeight(String maxHeight) {
99          getStateHelper().put(PropertyKeys.maxHeight, maxHeight);
100     }
101 
102     public boolean getSideBySideFullscreen() {
103         return (boolean) getStateHelper().eval(PropertyKeys.sideBySideFullscreen, true);
104     }
105 
106     public void setSideBySideFullscreen(boolean sideBySideFullscreen) {
107         getStateHelper().put(PropertyKeys.sideBySideFullscreen, sideBySideFullscreen);
108     }
109 
110     public boolean getIndentWithTabs() {
111         return (boolean) getStateHelper().eval(PropertyKeys.indentWithTabs, true);
112     }
113 
114     public void setIndentWithTabs(boolean indentWithTabs) {
115         getStateHelper().put(PropertyKeys.indentWithTabs, indentWithTabs);
116     }
117 
118     public boolean getLineNumbers() {
119         return (boolean) getStateHelper().eval(PropertyKeys.lineNumbers, false);
120     }
121 
122     public void setLineNumbers(boolean lineNumbers) {
123         getStateHelper().put(PropertyKeys.lineNumbers, lineNumbers);
124     }
125 
126     public boolean getPromptURLs() {
127         return (boolean) getStateHelper().eval(PropertyKeys.promptURLs, false);
128     }
129 
130     public void setPromptURLs(boolean promptURLs) {
131         getStateHelper().put(PropertyKeys.promptURLs, promptURLs);
132     }
133 
134     public int getTabSize() {
135         return (int) getStateHelper().eval(PropertyKeys.tabSize, 2);
136     }
137 
138     public void setTabSize(boolean tabSize) {
139         getStateHelper().put(PropertyKeys.tabSize, tabSize);
140     }
141 }