dnde
v 07,2021)
拖放电子邮件编辑器
# Yarn
yarn add dnd-email-editor
# NPM
npm install dnd-email-editor
可以传递给组件的道具:
| 支柱 | 类型 | 默认 | 选修的 | 描述 |
|---|---|---|---|---|
preview | 布尔 | true | 真的 | 显示/隐藏内置的预览按钮。 |
showUndoRedo | 布尔 | true | 真的 | 显示/隐藏内置的撤消/重做按钮。 您可以使用下面的API方法的 undoredo创建自己的底座功能 |
编辑器公开这些API方法
getHtml将设计导出为HTML内容getJson导出为JSON字符串,然后可以与loadJson一起使用此字符串loadJson加载JSON String的现有设计undoredo - 撤消和重做动作 import Editor from 'dnd-email-editor' ;
return < Editor / >;useRef设置ref并将其传递给编辑器 const ref = React . useRef ( null ) ;
return < Editor ref = { ref } / > ;getHtml() , getJson() , loadJson() , undoredo const logValues = ( ) => {
if ( ref . current ) {
const html = ref . current . getHtml ( ) ;
const json = ref . current . getJson ( ) ;
console . log ( html , json ) ;
}
} ;
const loadJson = ( json : string ) => {
if ( ref . current ) {
ref . current . loadJson ( json ) ;
}
} ;
const performUndoAction = ( ) => {
if ( ref . current ) {
ref . current . undoActionCallback ( ) ;
// to check if undo is possible
console . log ( 'is undo empty: ' , ref . current . isUndoEmpty ( ) ) ;
}
} ;
const performRedoAction = ( ) => {
if ( ref . current ) {
ref . current . redoActionCallback ( ) ;
// to check if redo is possible
console . log ( 'is redo empty: ' , ref . current . isRedoEmpty ( ) ) ;
}
} ;在使用打字稿并获取凉爽定义的订单中,只需将类型传递给参考
import Editor from 'dnd-email-editor';
const ExampleComponent = () => {
- const ref = useRef(null);
+ const ref = useRef<Editor>(null);
return (
<Editor ref={ref}/>
);
}有很多拖放编辑器有助于创建网站,但没有邮件,因为邮件与a normal html webpage有很大不同
mail editors ,它们也会获得付费而不是open-source 。一个这样的例子将是unlayer ,它声称是开源的,但事实并非如此。
open-source上述原因,我也受到一般而言的Drag-n-Drop编辑的启发,因此我决定做一个。
Undo / Redo来回走动