Skip to content

Commit b6fe5e6

Browse files
Merge pull request #5139 from topcoder-platform/fix_for_job_description
fix for job description new PR
2 parents f2bdeb6 + b9e43aa commit b6fe5e6

21 files changed

+1012
-49
lines changed

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
"supertest": "^3.1.0",
141141
"tc-core-library-js": "github:appirio-tech/tc-core-library-js#v2.6.3",
142142
"tc-ui": "^1.0.12",
143-
"topcoder-react-lib": "1000.25.7",
143+
"topcoder-react-lib": "1000.25.8",
144144
"topcoder-react-ui-kit": "2.0.1",
145145
"topcoder-react-utils": "0.7.8",
146146
"turndown": "^4.0.2",
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading
Loading

src/shared/components/Editor/index.jsx

+59-18
Original file line numberDiff line numberDiff line change
@@ -46,37 +46,69 @@ export default class EditorWrapper extends React.Component {
4646
this.customPlugin = createCustomPlugin({
4747
editor: this,
4848
});
49+
50+
this.onBeforeInput = this.onBeforeInput.bind(this);
51+
this.onPasteText = this.onPasteText.bind(this);
4952
}
5053

5154
componentDidMount() {
5255
const { connector, initialContent } = this.props;
5356
connector.addEditor(this);
54-
if (initialContent) {
55-
let editorState = convertFromHTML(initialContent);
56-
editorState = ContentState.createFromBlockArray(
57-
editorState.contentBlocks,
58-
editorState.entityMap,
59-
);
60-
editorState = EditorState.createWithContent(editorState);
61-
this.initialContent = editorState.getCurrentContent();
62-
setImmediate(() => this.setState({ editor: editorState }));
63-
}
57+
this.setInitialContent(initialContent);
6458
}
6559

66-
componentWillReceiveProps({ connector, id }) {
67-
const { connector: prevConnector } = this.props;
60+
componentWillReceiveProps({ connector, id, initialContent }) {
61+
const { connector: prevConnector, initialContent: prevInitialContent } = this.props;
6862
this.id = id;
6963
if (connector !== prevConnector) {
7064
if (prevConnector) prevConnector.removeEditor(this);
7165
if (connector) connector.addEditor(this);
7266
}
67+
if (initialContent !== prevInitialContent) {
68+
this.setInitialContent(initialContent);
69+
}
7370
}
7471

7572
componentWillUnmount() {
7673
const { connector } = this.props;
7774
connector.removeEditor(this);
7875
}
7976

77+
onBeforeInput() { // eslint-disable-line consistent-return
78+
const { maxLength } = this.props;
79+
const { editor: editorState } = this.state;
80+
if (maxLength !== -1 && maxLength <= editorState.getCurrentContent().getPlainText('').length) {
81+
return 'handled';
82+
}
83+
}
84+
85+
onPasteText(text) { // eslint-disable-line consistent-return
86+
const { maxLength } = this.props;
87+
const { editor: editorState } = this.state;
88+
if (maxLength !== -1 && maxLength <= text.length + editorState.getCurrentContent().getPlainText('').length) {
89+
return 'handled';
90+
}
91+
}
92+
93+
setInitialContent(content) {
94+
if (content) {
95+
let editorState = convertFromHTML(content);
96+
if (editorState.contentBlocks) {
97+
editorState = ContentState.createFromBlockArray(
98+
editorState.contentBlocks,
99+
editorState.entityMap,
100+
);
101+
editorState = EditorState.createWithContent(editorState);
102+
this.initialContent = editorState.getCurrentContent();
103+
setImmediate(() => this.setState({ editor: editorState }));
104+
}
105+
} else {
106+
let { editor: editorState } = this.state;
107+
editorState = EditorState.push(editorState, ContentState.createFromText(''));
108+
this.setState({ editor: editorState });
109+
}
110+
}
111+
80112
getHtml() {
81113
const { editor } = this.state;
82114
return editorStateToHTML(editor.getCurrentContent());
@@ -98,10 +130,9 @@ export default class EditorWrapper extends React.Component {
98130
* @param {String} type The new block style
99131
*/
100132
applyBlockStyle(type) {
101-
const { editor } = this.state;
102-
let editorState = editor;
133+
let { editor: editorState } = this.state;
103134
editorState = RichUtils.toggleBlockType(editorState, type);
104-
this.setState({ editorState }); // eslint-disable-line
135+
this.setState({ editor: editorState }); // eslint-disable-line
105136
}
106137

107138
/**
@@ -231,13 +262,16 @@ export default class EditorWrapper extends React.Component {
231262
}
232263

233264
render() {
234-
const { connector, theme } = this.props;
265+
const { connector, theme, placeholder } = this.props;
235266

236267
const st = this.state;
237268

238269
let containerStyles = style.container;
239270
if (st.editor.getSelection().getHasFocus()) {
240-
containerStyles += ` ${style.focused}`;
271+
containerStyles += ` ${style.focused} is-focused`;
272+
}
273+
if (st.editor.getCurrentContent().hasText() || /<ol>|<ul>/.test(this.getHtml())) {
274+
containerStyles += ' has-user-input';
241275
}
242276
if (theme.container) {
243277
containerStyles += ` ${theme.container}`;
@@ -253,6 +287,7 @@ export default class EditorWrapper extends React.Component {
253287
tabIndex={0}
254288
>
255289
<Editor
290+
placeholder={placeholder}
256291
editorState={st.editor}
257292
handleKeyCommand={(command, state) => {
258293
const editorState = RichUtils.handleKeyCommand(state, command);
@@ -283,6 +318,8 @@ export default class EditorWrapper extends React.Component {
283318
]}
284319
ref={(node) => { this.node = node; }}
285320
spellCheck
321+
handleBeforeInput={this.onBeforeInput}
322+
handlePastedText={this.onPasteText}
286323
/>
287324
</div>
288325
);
@@ -292,13 +329,17 @@ export default class EditorWrapper extends React.Component {
292329
EditorWrapper.defaultProps = {
293330
connector: new Connector(),
294331
id: null,
295-
initialContent: null,
332+
initialContent: '',
296333
theme: {},
334+
placeholder: '',
335+
maxLength: -1,
297336
};
298337

299338
EditorWrapper.propTypes = {
300339
connector: PT.instanceOf(Connector),
301340
id: PT.string,
302341
initialContent: PT.string,
303342
theme: PT.shape(),
343+
placeholder: PT.string,
344+
maxLength: PT.number,
304345
};
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
@import "~styles/mixins";
2+
3+
@mixin html-content-style() {
4+
@include roboto-regular;
5+
6+
font-size: 15px;
7+
color: #262628;
8+
9+
em {
10+
font-style: italic;
11+
}
12+
13+
p {
14+
margin: 6px 0 10px;
15+
line-height: 20px;
16+
}
17+
18+
ul {
19+
list-style-type: disc;
20+
}
21+
22+
ol {
23+
list-style-type: decimal;
24+
}
25+
26+
ul,
27+
ol {
28+
margin: 0 0 0 25px;
29+
30+
li {
31+
min-height: auto;
32+
line-height: 20px;
33+
padding: 0 0 0 12px;
34+
35+
&:last-child {
36+
border: 0;
37+
}
38+
}
39+
}
40+
41+
@content;
42+
}

0 commit comments

Comments
 (0)