-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from ifanrx/more-extension
Add more extensions
- Loading branch information
Showing
50 changed files
with
2,075 additions
and
1,005 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"presets": ["@babel/env", "@babel/preset-react"], | ||
"presets": ["@babel/preset-env", "@babel/preset-react"], | ||
"plugins": [ | ||
["transform-class-properties"] | ||
["@babel/proposal-class-properties"] | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
import React from 'react' | ||
import ReactUeditor from '../src' | ||
|
||
class AsyncExample extends React.Component { | ||
constructor() { | ||
super() | ||
this.editorResult = '' | ||
this.state = { | ||
content: '', | ||
} | ||
this.timer = null | ||
} | ||
|
||
componentDidMount() { | ||
this.timer = setTimeout(() => { | ||
this.setState({ | ||
content: '我是异步加载回来的数据', | ||
}) | ||
}, 2000) | ||
} | ||
|
||
componentWillUnmount() { | ||
clearTimeout(this.timer) | ||
} | ||
|
||
updateEditorContent = content => { | ||
// 通过 editroResult 获取编辑器最新内容,而不是对 content 进行 setState(因为 ueditor 不是一个受控组件) | ||
this.editorResult = content | ||
} | ||
|
||
render() { | ||
let {content} = this.state | ||
return ( | ||
<div> | ||
<ReactUeditor | ||
debug | ||
getRef={this.getUeditor} | ||
ueditorPath='../vendor/ueditor' | ||
value={content} | ||
onChange={this.updateEditorContent} | ||
/> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default AsyncExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import React from 'react' | ||
import ReactUeditor from '../src' | ||
|
||
class EditorRefExample extends React.Component { | ||
constructor() { | ||
super() | ||
this.ueditorRef = null | ||
this.state = { | ||
content: '', | ||
} | ||
} | ||
|
||
getUeditor = ref => { | ||
this.ueditorRef = ref | ||
} | ||
|
||
getUeditorContent = ref => { | ||
this.setState({ | ||
content: this.ueditorRef.getContent(), | ||
}) | ||
} | ||
|
||
handleReady = () => { | ||
this.ueditorRef.setHeight(200) | ||
} | ||
|
||
render() { | ||
let {content} = this.state | ||
|
||
return ( | ||
<div> | ||
<ReactUeditor | ||
debug | ||
ueditorPath='../vendor/ueditor' | ||
getRef={this.getUeditor} | ||
onChange={this.updateEditorContent} | ||
onReady={this.handleReady} | ||
/> | ||
<button onClick={this.getUeditorContent}>获取内容</button> | ||
<p>{content}</p> | ||
</div> | ||
) | ||
} | ||
} | ||
|
||
export default EditorRefExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
import React from 'react' | ||
import ReactUeditor from '../src' | ||
|
||
const testIcon = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAABd0lEQVQ4T82SMUsDQ' + | ||
'RCFZ+64IlaxsEgpEQULGxsrLUTQLv4CsZCA3XnJ7AWJnKAkuyuk0CYKFpYimFKwsktlIVYKoo2WpotwYUcuEDkTNUnnFgszb+bj7c4' + | ||
'gdB2t9SoAzBhjMC5ZlsUAcJfP5y/j+W9FkSClzADAHCKOMvNblEPEFDO/A0BdCFH7ExCJSqk0ACwS0XEUa62zrVbrulAoPHU77nHwP' + | ||
'wBSyilmnvd9/yRyVC6XNxzHufE872HQJ+w7jnPkum77EyuVSioMw00iKvYFlEqlCdu2M0R0EC+WUnq2bV/kcrmXfmM8TCaTW9lsNow' + | ||
'XVqtVp9FoKCGE+ytAKbXAzCuWZV11W41iY8wyANSEEPWO/jVGZkat9T0ATP/UHMvdEtFsD0BKuY6Ip32aO/IaEZ21tzS6giAYSSQSz' + | ||
'4g4NgiAmV+bzWY6CIKPNkAptQsAO4M0x2qKRLTXAUQ7Pj4k4JGIJtsAKeU2Ii4NAQiNMSe+759/AhPYnxETEdJoAAAAAElFTkSuQmCC' | ||
|
||
class App extends React.Component { | ||
constructor(props) { | ||
super(props) | ||
this.state = { | ||
inputValue: '', | ||
} | ||
} | ||
|
||
getUeditor = ref => { | ||
this.ueditorRef = ref | ||
} | ||
|
||
handleInputChange = e => { | ||
this.setState({ | ||
inputValue: e.target.value, | ||
}) | ||
} | ||
|
||
render() { | ||
return ( | ||
<ReactUeditor | ||
debug | ||
ueditorPath='../vendor/ueditor' | ||
getRef={this.getUeditor} | ||
extendControls={[ | ||
{ | ||
name: 'test', | ||
menuText: 'test', | ||
title: '测试模态框', | ||
// 图标定义,遵循 ueditor 的格式 | ||
cssRules: 'background: url(' + testIcon + ') !important; background-size: 20px 20px !important;', | ||
zIndex: 1, | ||
alignStyle: 'middle', | ||
component: <input onChange={this.handleInputChange} />, | ||
onConfirm: () => { | ||
this.ueditorRef.execCommand('inserthtml', this.state.inputValue, true) | ||
}, | ||
}, | ||
]} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import React from 'react' | ||
import ReactUeditor from '../src' | ||
|
||
class MediaExample extends React.Component { | ||
constructor() { | ||
super() | ||
this.state = { | ||
progress: -1, | ||
} | ||
} | ||
|
||
updateEditorContent = content => { | ||
this.editorResult = content | ||
} | ||
|
||
uploadImage = e => { | ||
return new Promise(function(resolve, reject) { | ||
resolve(window.URL.createObjectURL(e.target.files[0])) | ||
}) | ||
} | ||
|
||
uploadVideo = e => { | ||
let _this = this | ||
return new Promise(function(resolve, reject) { | ||
let i = 0 | ||
let instance = setInterval(() => { | ||
if (i !== 100) { | ||
_this.setState({progress: ++i}) | ||
} | ||
}, 50) | ||
setTimeout(() => { | ||
resolve('https://cloud-minapp-1131.cloud.ifanrusercontent.com/1eBb1SeNlayvGEKT.mp4') | ||
_this.setState({progress: -1}) | ||
clearInterval(instance) | ||
}, 5100) | ||
}) | ||
} | ||
|
||
uploadAudio = e => { | ||
return new Promise(function(resolve, reject) { | ||
resolve('https://cloud-minapp-1131.cloud.ifanrusercontent.com/1eEUtZNsjiOiHbWW.mp3') | ||
}) | ||
} | ||
|
||
render() { | ||
let {progress} = this.state | ||
|
||
return ( | ||
<ReactUeditor | ||
debug | ||
ueditorPath='../vendor/ueditor' | ||
plugins={['uploadImage', 'insertCode', 'uploadVideo', 'uploadAudio', 'insertLink']} | ||
uploadImage={this.uploadImage} | ||
uploadVideo={this.uploadVideo} | ||
uploadAudio={this.uploadAudio} | ||
onChange={this.updateEditorContent} | ||
progress={progress} | ||
multipleImagesUpload={false} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default MediaExample |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import React from 'react' | ||
import ReactUeditor from '../src' | ||
|
||
class PasteImageExample extends React.Component { | ||
handlePasteImage = src => { | ||
return new Promise(function(resolve) { | ||
setTimeout(() => { | ||
resolve('https://s3.ifanr.com/wp-content/uploads/2019/01/WechatIMG974.jpeg!720') | ||
}, 1000) | ||
}) | ||
} | ||
|
||
updateEditorContent = newContent => { | ||
console.log('newContent', newContent) | ||
} | ||
|
||
render() { | ||
return ( | ||
<ReactUeditor | ||
ueditorPath='../vendor/ueditor' | ||
handlePasteImage={this.handlePasteImage} | ||
onChange={this.updateEditorContent} | ||
/> | ||
) | ||
} | ||
} | ||
|
||
export default PasteImageExample |
Oops, something went wrong.