Updating Rich Text editor x 2
This commit is contained in:
parent
2387c3314a
commit
65f4cbe0dc
|
@ -67,7 +67,7 @@ export default class AutosuggestTextbox extends ImmutablePureComponent {
|
||||||
this.props.onSuggestionsClearRequested();
|
this.props.onSuggestionsClearRequested();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.props.onChange(e);
|
this.props.onChange(e, e.target.selectionStart);
|
||||||
}
|
}
|
||||||
|
|
||||||
onKeyDown = (e) => {
|
onKeyDown = (e) => {
|
||||||
|
|
|
@ -74,6 +74,15 @@ const compositeDecorator = new CompositeDecorator([
|
||||||
}
|
}
|
||||||
])
|
])
|
||||||
|
|
||||||
|
const styleMap = {
|
||||||
|
'CODE': {
|
||||||
|
padding: '0.25em 0.5em',
|
||||||
|
backgroundColor: 'var(--border_color_secondary)',
|
||||||
|
color: 'var(--text_color_secondary)',
|
||||||
|
fontSize: 'var(--fs_n)',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
const HANDLE_REGEX = /\@[\w]+/g
|
const HANDLE_REGEX = /\@[\w]+/g
|
||||||
const HASHTAG_REGEX = /\#[\w\u0590-\u05ff]+/g
|
const HASHTAG_REGEX = /\#[\w\u0590-\u05ff]+/g
|
||||||
|
|
||||||
|
@ -104,12 +113,13 @@ export default class Composer extends PureComponent {
|
||||||
const rawData = markdownToDraft(this.props.valueMarkdown)
|
const rawData = markdownToDraft(this.props.valueMarkdown)
|
||||||
const contentState = convertFromRaw(rawData)
|
const contentState = convertFromRaw(rawData)
|
||||||
const editorState = EditorState.createWithContent(contentState)
|
const editorState = EditorState.createWithContent(contentState)
|
||||||
|
|
||||||
this.setState({
|
this.setState({
|
||||||
editorState,
|
editorState,
|
||||||
plainText: this.props.value,
|
plainText: this.props.value,
|
||||||
})
|
})
|
||||||
} else if (this.props.value) {
|
} else if (this.props.value) {
|
||||||
editorState = EditorState.push(this.state.editorState, ContentState.createFromText(this.props.value))
|
const editorState = EditorState.push(this.state.editorState, ContentState.createFromText(this.props.value))
|
||||||
this.setState({
|
this.setState({
|
||||||
editorState,
|
editorState,
|
||||||
plainText: this.props.value,
|
plainText: this.props.value,
|
||||||
|
@ -123,7 +133,9 @@ export default class Composer extends PureComponent {
|
||||||
if (!this.props.value) {
|
if (!this.props.value) {
|
||||||
editorState = EditorState.createEmpty(compositeDecorator)
|
editorState = EditorState.createEmpty(compositeDecorator)
|
||||||
} else {
|
} else {
|
||||||
editorState = EditorState.push(this.state.editorState, ContentState.createFromText(this.props.value))
|
editorState = EditorState.moveFocusToEnd(
|
||||||
|
EditorState.push(this.state.editorState, ContentState.createFromText(this.props.value))
|
||||||
|
)
|
||||||
}
|
}
|
||||||
this.setState({
|
this.setState({
|
||||||
editorState,
|
editorState,
|
||||||
|
@ -201,11 +213,6 @@ export default class Composer extends PureComponent {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
onTab = (e) => {
|
|
||||||
const maxDepth = 4
|
|
||||||
this.onChange(RichUtils.onTab(e, this.state.editorState, maxDepth))
|
|
||||||
}
|
|
||||||
|
|
||||||
setRef = (n) => {
|
setRef = (n) => {
|
||||||
try {
|
try {
|
||||||
this.textbox = n
|
this.textbox = n
|
||||||
|
@ -219,10 +226,6 @@ export default class Composer extends PureComponent {
|
||||||
const {
|
const {
|
||||||
disabled,
|
disabled,
|
||||||
placeholder,
|
placeholder,
|
||||||
onKeyDown,
|
|
||||||
onFocus,
|
|
||||||
onBlur,
|
|
||||||
onPaste,
|
|
||||||
small,
|
small,
|
||||||
} = this.props
|
} = this.props
|
||||||
const { editorState } = this.state
|
const { editorState } = this.state
|
||||||
|
@ -252,15 +255,15 @@ export default class Composer extends PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
<div
|
<div
|
||||||
onClick={this.focus}
|
|
||||||
className={editorContainerClasses}
|
className={editorContainerClasses}
|
||||||
|
onClick={this.handleOnFocus}
|
||||||
>
|
>
|
||||||
<Editor
|
<Editor
|
||||||
blockStyleFn={getBlockStyle}
|
blockStyleFn={getBlockStyle}
|
||||||
editorState={editorState}
|
editorState={editorState}
|
||||||
|
customStyleMap={styleMap}
|
||||||
handleKeyCommand={this.handleKeyCommand}
|
handleKeyCommand={this.handleKeyCommand}
|
||||||
onChange={this.onChange}
|
onChange={this.onChange}
|
||||||
onTab={this.onTab}
|
|
||||||
placeholder={placeholder}
|
placeholder={placeholder}
|
||||||
ref={this.setRef}
|
ref={this.setRef}
|
||||||
readOnly={disabled}
|
readOnly={disabled}
|
||||||
|
|
|
@ -2,7 +2,7 @@ import { RichUtils } from 'draft-js'
|
||||||
import classNames from 'classnames/bind'
|
import classNames from 'classnames/bind'
|
||||||
import { me } from '../initial_state'
|
import { me } from '../initial_state'
|
||||||
import { makeGetAccount } from '../selectors'
|
import { makeGetAccount } from '../selectors'
|
||||||
import Button from './button'
|
import Icon from './icon'
|
||||||
|
|
||||||
const cx = classNames.bind(_s)
|
const cx = classNames.bind(_s)
|
||||||
|
|
||||||
|
@ -31,19 +31,19 @@ const RTE_ITEMS = [
|
||||||
type: 'style',
|
type: 'style',
|
||||||
icon: 'strikethrough',
|
icon: 'strikethrough',
|
||||||
},
|
},
|
||||||
// {
|
|
||||||
// label: 'Monospace',
|
|
||||||
// style: 'CODE',
|
|
||||||
// type: 'style',
|
|
||||||
// icon: 'circle',
|
|
||||||
// },
|
|
||||||
{
|
{
|
||||||
label: 'Title',
|
label: 'Monospace',
|
||||||
style: 'header-one',
|
style: 'CODE',
|
||||||
type: 'block',
|
type: 'style',
|
||||||
icon: 'text-size',
|
icon: 'code',
|
||||||
},
|
},
|
||||||
// {
|
// {
|
||||||
|
// label: 'Title',
|
||||||
|
// style: 'header-one',
|
||||||
|
// type: 'block',
|
||||||
|
// icon: 'text-size',
|
||||||
|
// },
|
||||||
|
// {
|
||||||
// label: 'Blockquote',
|
// label: 'Blockquote',
|
||||||
// style: 'blockquote',
|
// style: 'blockquote',
|
||||||
// type: 'block',
|
// type: 'block',
|
||||||
|
@ -138,6 +138,7 @@ class RichTextEditorBar extends PureComponent {
|
||||||
}
|
}
|
||||||
|
|
||||||
class StyleButton extends PureComponent {
|
class StyleButton extends PureComponent {
|
||||||
|
|
||||||
static propTypes = {
|
static propTypes = {
|
||||||
onClick: PropTypes.func,
|
onClick: PropTypes.func,
|
||||||
label: PropTypes.string,
|
label: PropTypes.string,
|
||||||
|
@ -161,37 +162,37 @@ class StyleButton extends PureComponent {
|
||||||
} = this.props
|
} = this.props
|
||||||
|
|
||||||
const selection = editorState.getSelection()
|
const selection = editorState.getSelection()
|
||||||
|
|
||||||
const currentStyle = editorState.getCurrentInlineStyle()
|
const currentStyle = editorState.getCurrentInlineStyle()
|
||||||
const blockType = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType()
|
const blockType = editorState.getCurrentContent().getBlockForKey(selection.getStartKey()).getType()
|
||||||
|
|
||||||
const active = type === 'block' ? style === blockType : currentStyle.has(style)
|
const active = type === 'block' ? style === blockType : currentStyle.has(style)
|
||||||
const color = active ? 'white' : 'secondary'
|
const fillColor = active ? 'fillWhite' : 'fillSecondary'
|
||||||
|
|
||||||
const btnClasses = cx({
|
const btnClasses = cx({
|
||||||
|
default: 1,
|
||||||
|
noUnderline: 1,
|
||||||
|
cursorPointer: 1,
|
||||||
px10: 1,
|
px10: 1,
|
||||||
mr5: 1,
|
mr5: 1,
|
||||||
noSelect: 1,
|
noSelect: 1,
|
||||||
bgSecondaryDark_onHover: 1,
|
bgSecondaryDark_onHover: 1,
|
||||||
bgBrandLight: active,
|
bgBrandLight: active,
|
||||||
// py10: !small,
|
bgTransparent: 1,
|
||||||
// py5: small,
|
radiusSmall: 1,
|
||||||
// px5: small,
|
outlineNone: 1,
|
||||||
|
py10: 1,
|
||||||
})
|
})
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Button
|
<button
|
||||||
className={btnClasses}
|
className={btnClasses}
|
||||||
backgroundColor='none'
|
onMouseDown={this.handleOnClick}
|
||||||
color={color}
|
|
||||||
onClick={this.handleOnClick}
|
|
||||||
title={label}
|
title={label}
|
||||||
icon={icon}
|
>
|
||||||
iconClassName={_s.inheritFill}
|
<Icon id={icon} size='12px' className={_s[fillColor]} />
|
||||||
iconSize='12px'
|
</button>
|
||||||
radiusSmall
|
|
||||||
/>
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@ class HTMLRenderer < Redcarpet::Render::HTML
|
||||||
end
|
end
|
||||||
|
|
||||||
def codespan(code)
|
def codespan(code)
|
||||||
"<code>#{code}</code>"
|
"<code>#{encode(code).gsub("\n", "<br/>")}</code>"
|
||||||
end
|
end
|
||||||
|
|
||||||
def double_emphasis(text)
|
def double_emphasis(text)
|
||||||
|
|
Loading…
Reference in New Issue