-
Notifications
You must be signed in to change notification settings - Fork 136
feat: add tui.editor #4307
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
feat: add tui.editor #4307
Changes from all commits
Commits
Show all changes
3 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| @import '~tc-ui/src/styles/tc-includes'; | ||
|
|
||
| .editor { | ||
| background: red; | ||
|
|
||
| > div { | ||
| h1 { | ||
| all: revert; | ||
| font-size: 24px; | ||
| } | ||
| } | ||
|
|
||
| b, | ||
| i, | ||
| s, | ||
| hr, | ||
| blockquote, | ||
| ul, | ||
| li, | ||
| ol, | ||
| table, | ||
| thead, | ||
| tr, | ||
| th, | ||
| img, | ||
| a, | ||
| code, | ||
| pre { | ||
| all: revert; | ||
| } | ||
|
|
||
| :global { | ||
| // add style for heading list in headings selection popup, because 'all:revert' has been setted before | ||
| .te-heading-add ul { | ||
| list-style: none; | ||
| } | ||
|
|
||
| // 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,154 @@ | ||
| /* | ||
| * TuiEditor | ||
| * wrap toast-ui editor with react and support react 15 | ||
| */ | ||
|
|
||
| import React from 'react' | ||
| import PropTypes from 'prop-types' | ||
| import Editor from '@toast-ui/editor' | ||
| import styles from './TuiEditor.scss' | ||
| import cn from 'classnames' | ||
| import 'codemirror/lib/codemirror.css' | ||
| import '@toast-ui/editor/dist/toastui-editor.css' | ||
|
|
||
| class TuiEditor extends React.Component { | ||
| constructor(props) { | ||
| super(props) | ||
| this.handleValueChange = this.handleValueChange.bind(this) | ||
| } | ||
|
|
||
| getRootElement() { | ||
| return this.refs.rootEl | ||
| } | ||
|
|
||
| getInstance() { | ||
| return this.editorInst | ||
| } | ||
|
|
||
| bindEventHandlers(props) { | ||
| Object.keys(props) | ||
| .filter(key => /^on[A-Z][a-zA-Z]+/.test(key)) | ||
| .forEach(key => { | ||
| const eventName = key[2].toLowerCase() + key.slice(3) | ||
| this.editorInst.off(eventName) | ||
| this.editorInst.on(eventName, props[key]) | ||
| }) | ||
| } | ||
|
|
||
| componentDidMount() { | ||
| const props = { | ||
| ...this.props, | ||
| onChange: this.handleValueChange | ||
| } | ||
| this.editorInst = new Editor({ | ||
| el: this.refs.rootEl, | ||
| ...props | ||
| }) | ||
| this.bindEventHandlers(props) | ||
| } | ||
|
|
||
| handleValueChange(){ | ||
| if (this.props.onChange) { | ||
| this.props.onChange(this.getInstance().getMarkdown()) | ||
| } | ||
| } | ||
|
|
||
| shouldComponentUpdate(nextProps) { | ||
| const instance = this.getInstance() | ||
| const { height, previewStyle, className } = nextProps | ||
|
|
||
| if (this.props.height !== height) { | ||
| instance.height(height) | ||
| } | ||
|
|
||
| if (this.props.previewStyle !== previewStyle) { | ||
| instance.changePreviewStyle(previewStyle) | ||
| } | ||
|
|
||
| if (this.props.className !== className) { | ||
| return true | ||
| } | ||
| // this.bindEventHandlers(nextProps, this.props) | ||
|
|
||
| return false | ||
| } | ||
|
|
||
| render() { | ||
| return <div ref="rootEl" className={cn(styles.editor, this.props.className)} /> | ||
| } | ||
| } | ||
maxceem marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
|
|
||
| TuiEditor.defaultProps = { | ||
| height: '300px', | ||
| minHeight: '300px', | ||
| initialValue: '', | ||
| previewStyle: '', | ||
| initialEditType: 'wysiwyg', | ||
| language: 'en-US', | ||
| useCommandShortcut: true, | ||
| customHTMLSanitizer: null, | ||
| frontMatter: false, | ||
| hideModeSwitch: false, | ||
| referenceDefinition:false, | ||
| usageStatistics: false, | ||
| useDefaultHTMLSanitizer: true | ||
| } | ||
|
|
||
| TuiEditor.propTypes = { | ||
| 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 initial value | ||
| initialValue: 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,29 @@ | ||
| /* | ||
| * DescriptionField | ||
| */ | ||
|
|
||
| import React from 'react' | ||
| import PropTypes from 'prop-types' | ||
|
|
||
| import TuiEditor from '../../../../components/TuiEditor' | ||
|
|
||
| const DescriptionField = (props) => ( | ||
| <TuiEditor | ||
| {...props} | ||
| previewStyle="vertical" | ||
| height="400px" | ||
| hideModeSwitch | ||
| initialEditType="wysiwyg" | ||
| initialValue={props.value} | ||
| /> | ||
| ) | ||
|
|
||
|
|
||
| DescriptionField.propTypes = { | ||
| onChange: PropTypes.func.isRequired, | ||
| className: PropTypes.string, | ||
| placeholder: PropTypes.string, | ||
| value: PropTypes.string, | ||
| } | ||
|
|
||
| export default DescriptionField |
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.