Skip to content
This repository was archived by the owner on Mar 13, 2025. It is now read-only.

Commit 54faf19

Browse files
committed
fix: markdown editor styles and code improvements
ref issue #100
1 parent ced2d16 commit 54faf19

File tree

7 files changed

+50
-10
lines changed

7 files changed

+50
-10
lines changed

src/components/DataItem/index.jsx

+7-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,13 @@ const DataItem = ({ icon, title, children }) => {
1313
{icon}
1414
<div styleName="data">
1515
<div styleName="title">{title}</div>
16-
<div styleName="value">{children}</div>
16+
{/* if `children` is pure text, then we apply styling to it
17+
but otherwise with don't apply styling */}
18+
{_.isString(children) ? (
19+
<div styleName="value">{children}</div>
20+
) : (
21+
<div styleName="value-component">{children}</div>
22+
)}
1723
</div>
1824
</div>
1925
);

src/components/DataItem/styles.module.scss

+4
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,7 @@
3232
text-align: left;
3333
word-break: break-all;
3434
}
35+
36+
.value-component {
37+
margin-top: 2px;
38+
}

src/components/MarkdownEditor/index.jsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* MarkdownEditor
33
*/
44

5-
import React, { useState, useCallback, useRef } from "react";
5+
import React, { useCallback, useRef } from "react";
66
import PropTypes from "prop-types";
77
import cn from "classnames";
88
import TuiEditor from "../TuiEditor";
@@ -12,9 +12,9 @@ const MarkdownEditor = (props) => {
1212
const editorElement = useRef(null);
1313

1414
const onChange = useCallback(() => {
15-
const mk = editorElement.current.editorInst.getMarkdown();
16-
props.onChange(mk);
17-
}, []);
15+
const markdown = editorElement.current.editorInst.getMarkdown();
16+
props.onChange(markdown);
17+
}, [props.onChange]);
1818

1919
return (
2020
<div className={cn(styles["editor-container"], props.className)}>

src/components/MarkdownEditor/styles.module.scss

+7-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,13 @@
1010
font-weight: revert;
1111
line-height: revert;
1212
}
13-
}
13+
}
14+
15+
.tui-editor-contents {
16+
b {
17+
font-weight: bold;
18+
}
19+
}
1420

1521
// reset border color
1622
.tui-editor-defaultUI {

src/components/MarkdownEditorViewer/index.jsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
* MarkdownViewer
33
*/
44

5-
import React, { useState } from "react";
5+
import React from "react";
66
import PropTypes from "prop-types";
77
import TuiEditorViewer from "../TuiEditorViewer";
88

src/components/TuiEditor/index.jsx

+14-2
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ class TuiEditor extends React.Component {
2828
const eventName = key[2].toLowerCase() + key.slice(3);
2929
// off function has issue
3030
// when add `onFocus` function, the headings popup will not hide automatically
31-
// this.editorInst.off(eventName, props[key]);
31+
// this.editorInst.off(eventName);
3232
this.editorInst.on(eventName, props[key]);
3333
});
3434
}
@@ -42,6 +42,15 @@ class TuiEditor extends React.Component {
4242
this.bindEventHandlers(this.props);
4343
}
4444

45+
componentWillUnmount() {
46+
Object.keys(this.props)
47+
.filter((key) => /^on[A-Z][a-zA-Z]+/.test(key))
48+
.forEach((key) => {
49+
const eventName = key[2].toLowerCase() + key.slice(3);
50+
this.editorInst.off(eventName);
51+
});
52+
}
53+
4554
shouldComponentUpdate(nextProps) {
4655
const instance = this.getInstance();
4756
const { height, previewStyle } = nextProps;
@@ -54,7 +63,10 @@ class TuiEditor extends React.Component {
5463
instance.changePreviewStyle(previewStyle);
5564
}
5665

57-
this.bindEventHandlers(nextProps, this.props);
66+
// this looks like a bed idea to re-subscribe all the event on each re-render
67+
// also, note, that we had to disable this.editorInst.off(eventName);
68+
// otherwise popup for choosing Headings never closes
69+
// this.bindEventHandlers(nextProps, this.props);
5870

5971
return false;
6072
}

src/components/TuiEditorViewer/index.jsx

+13-1
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,20 @@ class TuiViewer extends React.Component {
4141
this.bindEventHandlers(this.props);
4242
}
4343

44+
componentWillUnmount() {
45+
Object.keys(this.props)
46+
.filter((key) => /^on[A-Z][a-zA-Z]+/.test(key))
47+
.forEach((key) => {
48+
const eventName = key[2].toLowerCase() + key.slice(3);
49+
this.editorInst.off(eventName);
50+
});
51+
}
52+
4453
shouldComponentUpdate(nextProps) {
45-
this.bindEventHandlers(nextProps, this.props);
54+
// this looks like a bed idea to re-subscribe all the event on each re-render
55+
// also, note, that we had to disable this.editorInst.off(eventName);
56+
// otherwise popup for choosing Headings never closes
57+
// this.bindEventHandlers(nextProps, this.props);
4658

4759
return false;
4860
}

0 commit comments

Comments
 (0)