This repository was archived by the owner on Mar 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 24
feat: add tui editor #109
Merged
Merged
feat: add tui editor #109
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* | ||
* TuiEditor | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import cn from "classnames"; | ||
import { Editor } from "@toast-ui/react-editor"; | ||
import styles from "./styles.module.scss"; | ||
|
||
const TuiEditor = (props) => { | ||
const [editorElement, setEditorElement] = useState(null); | ||
maxceem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
const onChange = () => { | ||
const mk = editorElement.editorInst.getMarkdown(); | ||
props.onChange(mk); | ||
}; | ||
maxceem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
return ( | ||
<div className={cn(styles["editor-container"], props.className)}> | ||
<Editor | ||
{...props} | ||
ref={setEditorElement} | ||
onChange={onChange} | ||
initialValue={props.value} | ||
/> | ||
</div> | ||
); | ||
}; | ||
|
||
TuiEditor.defaultProps = { | ||
height: "320px", | ||
minHeight: "320px", | ||
initialValue: "", | ||
previewStyle: "", | ||
initialEditType: "wysiwyg", | ||
language: "en-US", | ||
useCommandShortcut: true, | ||
customHTMLSanitizer: null, | ||
frontMatter: false, | ||
hideModeSwitch: true, | ||
referenceDefinition: false, | ||
usageStatistics: false, | ||
useDefaultHTMLSanitizer: true, | ||
}; | ||
|
||
TuiEditor.propTypes = { | ||
// Editor's initial value | ||
value: PropTypes.string, | ||
className: PropTypes.string, | ||
// Markdown editor's preview style (tab, vertical) | ||
previewStyle: PropTypes.string.isRequired, | ||
// Editor's height style value. Height is applied as border-box ex) '300px', '100%', 'auto' | ||
height: PropTypes.string, | ||
// Initial editor type (markdown, wysiwyg) | ||
initialEditType: PropTypes.string, | ||
// Editor's min-height style value in pixel ex) '300px' | ||
minHeight: PropTypes.string, | ||
// The placeholder text of the editable element. | ||
placeholder: PropTypes.string, | ||
// hide mode switch tab bar | ||
hideModeSwitch: PropTypes.bool, | ||
// language, 'en-US' | ||
language: PropTypes.string, | ||
// whether use keyboard shortcuts to perform commands | ||
useCommandShortcut: PropTypes.bool, | ||
// It would be emitted when editor fully load1 | ||
onLoad: PropTypes.func, | ||
// It would be emitted when content changed | ||
onChange: PropTypes.func, | ||
// It would be emitted when format change by cursor position | ||
onStateChange: PropTypes.func, | ||
// It would be emitted when editor get focus | ||
onFocus: PropTypes.func, | ||
// It would be emitted when editor loose focus | ||
onBlur: PropTypes.func, | ||
// hooks | ||
hooks: PropTypes.arrayOf(PropTypes.object), | ||
// send hostname to google analytics | ||
usageStatistics: PropTypes.bool, | ||
// use default htmlSanitizer | ||
useDefaultHTMLSanitizer: PropTypes.bool, | ||
// toolbar items. | ||
toolbarItems: PropTypes.arrayOf(PropTypes.object), | ||
// Array of plugins. A plugin can be either a function or an array in the form of [function, options]. | ||
plugins: PropTypes.arrayOf(PropTypes.object), | ||
// Using extended Autolinks specified in GFM spec | ||
extendedAutolinks: PropTypes.object, | ||
// convertor extention | ||
customConvertor: PropTypes.object, | ||
// Attributes of anchor element that should be rel, target, contenteditable, hreflang, type | ||
linkAttribute: PropTypes.object, | ||
// Object containing custom renderer functions correspond to markdown node | ||
customHTMLRenderer: PropTypes.object, | ||
// whether use the specification of link reference definition | ||
referenceDefinition: PropTypes.bool, | ||
// custom HTML sanitizer | ||
customHTMLSanitizer: PropTypes.func, | ||
// whether use the front matter | ||
frontMatter: PropTypes.bool, | ||
}; | ||
|
||
export default TuiEditor; |
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,37 @@ | ||
@import "styles/include"; | ||
|
||
.editor-container { | ||
margin-top: 10px; | ||
|
||
:global { | ||
// reset style for heading list in headings selection popup | ||
.tui-popup-body { | ||
h1,h2,h3,h4,h4,h5,h6 { | ||
font-weight: revert; | ||
line-height: revert; | ||
} | ||
} | ||
|
||
// reset border color | ||
.tui-editor-defaultUI { | ||
border: 1px solid #aaaaab | ||
} | ||
|
||
.te-toolbar-section { | ||
border-bottom: 1px solid #aaaaab | ||
} | ||
|
||
// hide uplodd file | ||
.tui-editor-popup{ | ||
box-shadow: 0px 0px 15px 5px rgba(0,0,0,0.26); | ||
} | ||
|
||
.te-popup-add-image .te-tab button, .te-popup-add-image .te-file-type{ | ||
display: none !important; | ||
} | ||
|
||
.te-popup-add-image .te-url-type{ | ||
display: block !important; | ||
} | ||
} | ||
} |
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,15 @@ | ||
/* | ||
* TuiEditorViewer | ||
*/ | ||
|
||
import React, { useState } from "react"; | ||
import PropTypes from "prop-types"; | ||
import { Viewer } from "@toast-ui/react-editor"; | ||
|
||
const TuiEditorViewer = (props) => <Viewer initialValue={props.value} />; | ||
|
||
TuiEditorViewer.propTypes = { | ||
value: PropTypes.string, | ||
}; | ||
|
||
export default TuiEditorViewer; |
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
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.
Uh oh!
There was an error while loading. Please reload this page.