-
Notifications
You must be signed in to change notification settings - Fork 154
/
test.jsx
209 lines (204 loc) · 10 KB
/
test.jsx
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
import React from 'react';
import ReactDOM from 'react-dom';
// import {LzEditor} from './index'
import hmacsha1 from "hmacsha1";
import {Base64} from "js-base64";
import md5 from "md5";
import findIndex from "lodash/findIndex";
import uniqBy from "lodash/uniqBy";
import LzEditor from './editor/index.jsx'
class Test extends React.Component {
constructor(props) {
super(props);
this.state = {
readOnlyContent: `<h1> Read Only Editor</h1>`,
htmlContent: `<h1> Head level 1</h1>
<p style='text-align:center;'><span style="color:#ED5565">red text</span>,center ,<strong>bold</strong>,<em>italic</em></p>
<blockquote style='text-align:left;'><span style="color:#967adc">C</span> <span style="color:#a0d468">O</span><span style="color:#48cfad">L</span><span style="color:#4a89dc">O</span><span style="color:#967adc">R</span><span style="color:#434a54">S</span></blockquote>
<p>Note that the upload feature cannot be uploaded in this demo page because of server configuration. Here only the code demos are available.</p>
<p><br></p>
<ul>
<li><span style="color:#434a54">list 1</span></li>
<li><span style="color:#434a54">list 2</span></li>
<li><span style="color:#434a54">list 3</span></li>
</ul>
<pre><code>Block here.Block here.Block here.Block here.</code></pre>
<pre><code>Block here.Block here.Block here.Block here.Block here.</code></pre>
<pre><code>Block here.Block here.Block here.Block here.Block here.</code></pre>
<p><img src="https://image.qiluyidian.mobi/43053508139910678747.jpg"/></p>
<p><br></p>
<h2>Yankees, Peeking at the Red Sox, Will Soon Get an Eyeful</h2>
<p>Leaning over the railing from his perch on the top step of the first-base dugout this past weekend in Cleveland, Yankees Manager Joe Girardi did not have to divert his gaze to catch glimpses of the out-of-town scoreboard./p>
<p>It was all there on the left-field wall.</p>
<p>“You’re going to look — it’s impossible not to,” Girardi said. “I haven’t seen a ballpark where they put it behind you. You pay attention, of course.”</p>
<p>Whenever Girardi stole a glance, there was rarely any good news for the Yankees. While Girardi’s charges were clawing their way to a split of their four-game series against the formidable Indians, the Boston Red Sox were plowing past the rebuilding Chicago White Sox, sweeping four games at Fenway Park.</p>`,
markdownContent: "## HEAD 2 \n markdown examples \n ``` welcome ```",
rawContent: '{"entityMap":{"0":{"type":"image","mutability":"IMMUTABLE","data":{"src":"https://image.qiluyidian.mobi/4305350813991067' +
'8747.jpg"}},"1":{"type":"image","mutability":"IMMUTABLE","data":{"src":"https://image.qiluyidian.mobi/430535081399106787' +
'47.jpg"}}},"blocks":[{"key":"fr2lj","text":"Yankees, Peeking at the Red Sox, Will Soon Get an Eyeful","type":"header-one","depth":0,"inlineStyleRanges":[],"entityRanges":[]' +
',"data":{}},{"key":"90kdv","text":"Leaning over the railing from his perch on the top step of the first-base dugout this past weekend in Cleveland, Yankees Manager Joe Girardi did not have to divert his gaze to catch glimpses of the out-of-town scoreboard.","type":"unstyled","depth":0,"inlin' +
'eStyleRanges":[],"entityRanges":[],"data":{}},{"key":"b60ni","text":"Whenever Girardi stole a glance, there was rarely any good news for the Yankees. While Girardi’s charges were clawing their way to a split of their four-game series against the formidable Indians, the Boston Red Sox were plowing past the rebuilding Chicago White Sox, sweeping four games at Fenway Park.","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],"data":{}},{"key":"eui4h","text' +
'":"The Yankees, who trail the Red Sox by three games in the American League East, will have their rivals right in front of them on three of the next four weekends, beginning Friday night at Yankee Stadium.","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],' +
'"data":{}},{"key":"29t6l","text":" ","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"lengt' +
'h":1,"key":0}],"data":{}},{"key":"7ujeo","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],' +
'"data":{}},{"key":"3n9d4","text":" ","type":"atomic","depth":0,"inlineStyleRanges":[],"entityRanges":[{"offset":0,"lengt' +
'h":1,"key":1}],"data":{}},{"key":"9r0k2","text":"","type":"unstyled","depth":0,"inlineStyleRanges":[],"entityRanges":[],' +
'"data":{}}]}',
responseList: []
}
this.receiveHtml = this.receiveHtml.bind(this);
this.receiveMarkdown = this.receiveMarkdown.bind(this);
this.receiveRaw = this.receiveRaw.bind(this);
this.onChange = this.onChange.bind(this);
this.beforeUpload = this.beforeUpload.bind(this);
this.getSignature = this.getSignature.bind(this);
this.getPolicy = this.getPolicy.bind(this);
}
receiveHtml(content) {
console.log("recieved HTML content", content);
//清空responseList
this.setState({responseList:[]});
}
componentDidMount() {}
receiveMarkdown(content) {
console.log("recieved markdown content", content);
}
receiveRaw(content) {
console.log("recieved Raw content", content);
}
onChange(info) {
let currFileList = info.fileList;
currFileList = currFileList.filter((f) => (!f.length));
let url = "http://devopee.b0.upaiyun.com";
//Read remote address and display.
//读取远程路径并显示链接
currFileList = currFileList.map((file) => {
if (file.response) {
// concat url
// 组件会将 file.url 作为链接进行展示
file.url = url + file.response.url;
}
if (!file.length) {
return file;
}
});
let _this = this;
// filtering successed files
//按照服务器返回信息筛选成功上传的文件
currFileList = currFileList.filter((file) => {
//multiple uploading?
//根据多选选项更新添加内容
let hasNoExistCurrFileInUploadedList = !~findIndex(_this.state.responseList, item => item.name === file.name)
if (hasNoExistCurrFileInUploadedList) {
if (!!_this.props.isMultiple == true) {
_this.state.responseList.push(file);
} else {
_this.state.responseList = [file];
}
}
return !!file.response || (!!file.url && file.status == "done") || file.status == "uploading";
});
currFileList = uniqBy(currFileList, "name");
if (!!currFileList && currFileList.length != 0) {
this.setState({responseList: currFileList});
}
_this.forceUpdate();
}
beforeUpload(file) {
console.log("beforeUpload like", file);
}
getSignature(fileName) {
let now = new Date();
let h = hmacsha1('19931944122b23f77681b6ab765648f8', 'POST&/upyun-temp/' + fileName + '&' + now);
let Signature = Base64.encode(h);
return Signature;
}
getPolicy(fileName) {
let now = new Date();
let afterHour = new Date(now.getTime() + 1 * 60 * 60 * 1000); //expiration date time
let policy = Base64.encode(JSON.stringify({
"bucket": "devopee",
"save-key": "/" + fileName,
"expiration": Math.round(afterHour.getTime() / 1000),
"date": now
}));
return policy;
}
render() {
let policy = "";
//uploadProps configration: https://ant.design/components/upload/
//uploadProps 配置方法见 https://ant.design/components/upload-cn/
const uploadProps = {
action: "http://v0.api.upyun.com/devopee",
onChange: this.onChange,
listType: 'picture',
fileList: this.state.responseList,
data: (file) => {
// customize uploading parameters, code example use UPYUN(https://www.upyun.com/)
//自定义上传参数,这里使用UPYUN
return {
Authorization: "UPYUN reactlzeditor:" + this.getSignature(file.name),
policy: (() => {
policy = this.getPolicy(file.name);
return policy;
})(),
signature: md5(policy + '&pLv/J4I6vfpeznxtwU+g/dsUcEY=')
}
},
multiple: true,
beforeUpload: this.beforeUpload,
showUploadList: true
}
let watermarkImage=[
{
type: "white_small",
tip: "white small",
value: "http://7xjl1j.com1.z0.glb.clouddn.com/white_small.png",
valuebase64: "aHR0cDovLzd4amwxai5jb20xLnowLmdsYi5jbG91ZGRuLmNvbS93aGl0ZV9zbWFsbC5wbmc="
}, {
type: "white_big",
tip: "white big",
value: "http://7xjl1j.com1.z0.glb.clouddn.com/white_big.png",
valuebase64: "aHR0cDovLzd4amwxai5jb20xLnowLmdsYi5jbG91ZGRuLmNvbS93aGl0ZV9iaWcucG5n"
}
]
return (
<div>
<div>Editor demo 1 (use default html format ):
</div>
<LzEditor active={true} importContent={this.state.htmlContent} cbReceiver={this.receiveHtml} uploadProps={uploadProps}/>
<br/>
<br/>
<div>Editor demo 2 (use markdown format ):
</div>
<LzEditor
active={true}
importContent={this.state.markdownContent}
cbReceiver={this.receiveMarkdown}
image={false}
video={false}
audio={false}
convertFormat="markdown"/>
<br/>
<br/>
<div>Editor demo 3 (use Raw format ):
</div>
<LzEditor
active={true}
importContent={this.state.rawContent}
cbReceiver={this.receiveRaw}
image={false}
video={false}
disabled
audio={false}
convertFormat="raw"
lang="zh-CN"/>
<div>Readonly demo (use default html format ):
</div>
<LzEditor readOnly={true} active={true} importContent={this.state.readOnlyContent} cbReceiver={this.receiveHtml} uploadProps={uploadProps}/>
</div>
);
}
}
ReactDOM.render(
<Test/>, document.getElementById('test'));