-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqtext.tsx
99 lines (88 loc) · 2.41 KB
/
qtext.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import * as React from "react";
import * as ReactDOM from "react-dom";
import registerServiceWorker from "./registerServiceWorker";
import { QText } from "../src/index";
import "./../assets/index.less";
import "./App.css";
const initValue = require("./test.json");
const d = {
token:
"LljRgfC0Wlx7ScBAhP_g78WXTYOiuGViAiCMw76V:TPEmRFAbZMWakPqUj4C-u9I28GQ=:eyJzY29wZSI6ImRhb2dvdSIsImRlYWRsaW5lIjoxNTE2OTU2NTI5LCJ1cGhvc3RzIjpbImh0dHA6Ly91cC5xaW5pdS5jb20iLCJodHRwOi8vdXBsb2FkLnFpbml1LmNvbSIsIi1IIHVwLnFpbml1LmNvbSBodHRwOi8vMTgzLjEzMS43LjE4Il19",
baseUrl: "https://i.ezbuy.sg/"
};
function url(hash: string) {
return `${d.baseUrl}${hash}`;
}
const TOKEN = d.token;
class App extends React.Component {
editor: QText | null;
editorView: QText | null;
state = {
value: undefined
};
render() {
return (
<div className="App">
<h2>Qtext: React editor base on Draft-js</h2>
<p>
<button
onClick={() => {
console.log(
JSON.stringify(
this.editor ? this.editor.getEditData() : {},
null,
4
)
);
}}
>
log editor data
</button>
</p>
<div>
<QText
ref={r => (this.editor = r)}
disabled={[]}
value={this.state.value}
onChange={s => {
// use setData change view
if (s && s.data && this.editorView) {
this.editorView.setData(s.data);
}
}}
rcSuccess={data => {
return url(data.hash);
}}
rcUploadProps={{
data: {
token: TOKEN
},
action:
location.protocol === "https:"
? "https://up.qbox.me"
: "http://upload.qiniu.com/"
}}
/>
<h2>Test qtext view</h2>
<QText
ref={r => (this.editorView = r)}
value={this.state.value}
readOnly={true}
/>
</div>
<p className="App-intro">Qtext</p>
</div>
);
}
componentDidMount() {
setTimeout(() => {
this.setState({
value: initValue
});
}, 3000);
}
}
ReactDOM.render(<App />, document.getElementById(
"__react-content"
) as HTMLElement);
registerServiceWorker();