1.1.219 • Published 4 years ago

eigen-editor v1.1.219

Weekly downloads
3
License
MIT
Repository
github
Last release
4 years ago

eigen-editor

The editor-eigen export EigenEditor component for eigen business.

Installation

$ npm i eigen-editor --save
$ yarn add eigen-editor

Importing

import EigenEditor from "eigen-editor";

Props

<EigenEditor 
    tools={array} 
    online={boolean} 
    content={object} 
    getSkuData={fn}
    editorStyle={object}
    toolBarStyle={object}
    contentStyle={object}
    uploadUrl={string}
    cropImageUrl={string}
    insertImageChange={fn}
    onChange={fn} />
  • onChange 编辑器中内容改变时执行的回调事件,可以拿到变化后的数据对象。
  • content 要传入编辑器中的数据对象 注意:这个数据对象有一定的格式要求。
  • getSkuData 添加SKU图片连接要调用事件,事件的参数就是添加的图片url,可以在这个事件中去请求服务,将返回数据格式为插件需求的格式。
  • tools 要添加的编辑器工具
  • online 是否更新编辑器内容
  • toolBarStyle 工具栏样式对象
  • editorStyle 编辑器样式对象
  • contentStyle 编辑区样式对象
  • uploadUrl 插入图片时上传图片的地址
  • cropImageUrl 裁剪图片的接口地址
  • insertImageChange 上传图片成功或切换选中图片事件

tools 可选值

  • BOLD
  • ITALIC
  • UNDERLINE
  • UNDO
  • REDO
  • FONTSIZEMODIFY
  • BLOCKQUOTE
  • SPLITLINE
  • CLEARALLSTYLES
  • ADDLINK
  • ADDEMOJI
  • COLORSMOdDIFY
  • BACKGROUNDCOLORMODIFY
  • FIRSTINTENT
  • ALIGNCENTER
  • ALIGNLEFT
  • ALIGNRIGHT
  • ALIGNJUSTIFY
  • ADDIMG
  • ADDSKU
  • LINEHEIGHT
  • LETTERWIDTH
  • TOPMARGIN
  • LEFTRIGHTMARGIN
  • BOTTOMMARGI

Example

import React from "react";
import ReactDOM from "react-dom";
import request from "@utils/request";
import qs from "qs";

import EigenEditor from "../src";
import Draft from './draft_func'

function setText(editorState){
    let draft = new Draft(editorState)
    let newEditorState = draft.insertText('hello world')
    return newEditorState
}

function setImage(editorState) {
    let draft = new Draft(editorState)
    let newEditorState = draft.setMedia('image', {
        src: 'http://autoimg.15feng.cn/spark-auto/c_fill/cpk/3998/24968/20170708082438670-4599-m8d3-k5ck-n190.jpg',
        type: 'image'
    })
    console.log(newEditorState)
    return newEditorState
}

class Demo extends React.Component {
    constructor(props) {
        super(props)
        this.state = {
            // content: 
            editorState: null,
            event: null
        }
        this.getSkuData = this.getSkuData.bind(this)
        this.focus = this.focus.bind(this)
    }

    handleChange(content, editorState) {
        console.log(content)
        // 同步编辑器里新生成的editorState
        this.setState({
            content: content,
            editorState: editorState,
            event: null
        })
    }

    focus(key) {
        console.log(key)
    }

    componentDidMount() {
        let { editorState } = this.state
        this.setState({
            event: {
                params: editorState,
                func: setImage
            }
        })
    }

    insertImageChange(imageList, setLink){
        console.log(imageList, setLink, "insertImage")
    }

    pictureRecommend(callback){
        let param = {
            query: {
                type: 'picture',
               // page: 10,
              //  size: 2,
              //  sku_version: "3.0.0"
            },
            data:[{
                intent: 44,
               // outline_type:'',
               // outline: 2,
                topic_tags: "",
                category_tags: "",
               image_shape: "all",
                query: "",
                id: "44",
                context: ""
            }]
        };
       request(`proxy/hepburn/api/v4/writing/recommend?` + qs.stringify(param.query), {
            method: 'post',
            headers: {
                'Accept': 'application/json',
                'Content-Type': 'application/json'
            },
            body: JSON.stringify(param.data)
        }).then(result => {
            callback(result);
        }).catch( err => {
            console.log(err, "err")
        })
    }
    
    getSkuData(url) {
        return new Promise((resolve, reject) => {
            window.setTimeout(() => {
                resolve({
                    'price': '398.00',
                    'sku_images': '//img.alicdn.com/imgextra/i2/TB1PB8paXYM8KJjSZFuYXIf7FXa_M2.SS2',
                    'title': '小P良品铺 整张牛皮的精致 短靴女2017新款平底真皮铆钉牛皮靴子',
                    'type': 'sku2',
                    'url': 'https://item.taobao.com/item.htm?spm=a230r.1.14.22.34d544d20SAHVe&id=560966390234&ns=1&abbucket=11#detail'
                })
            }, 2) 
        }) 
    }

    getTheText = (text) =>{
        return request('/proxy/hepburn/api/v4/writing/recommend?type=prev', {
          method: 'post',
          headers: {
            'Accept': 'application/json',
            'Content-Type': 'application/json'
          },
          body: JSON.stringify([{
            intent:45,
            category_tags: [],
            topic_tags: [],
            id:1,
            context: text,
          }])
        })
      }
    
    fomate = (res) =>{
    return res[0].prev.map((item,index)=>{
        if(index < 5){
            return item.text
        }
    })
    }

    render() {
        const editorStyle = {
            overflow: "scroll",
            width: "100%",
            display: "block",
            margin: "20px auto",
            padding: 20
        }
        return <EigenEditor tools={[
            'BOLD',
            'ITALIC',
            'UNDERLINE',
            'UNDO',
            'REDO',
            'FONTSIZEMODIFY',
            'BLOCKQUOTE',
            'SPLITLINE',
            'CLEARALLSTYLES',
            'ADDLINK',
            'ADDEMOJI',
            'COLORSMODIFY',
            'BACKGROUNDCOLORMODIFY',
            'FIRSTINTENT',
            'ALIGNCENTER',
            'ALIGNLEFT',
            'ALIGNRIGHT',
            'ALIGNJUSTIFY',
            'ADDIMG',
            'ADDSKU',
            'LINEHEIGHT',
            'LETTERWIDTH',
            'TOPMARGIN',
            'LEFTRIGHTMARGIN',
            'BOTTOMMARGIN',
            'ADDTABLE',
            'RLINK',
            'LTITLE'
        ]}
        online={true} 
        autoFocus={true}
        editorStyle={editorStyle}
        // 通过传event,给编辑器插入数据
        // event是一个对象,有params和func(返回一个新的editorState)这两个属性
        // 编辑器通过执行event.func(params)来得到新的editorState
        event={this.state.event}
        focusKey={'1'}
        focus={this.focus}
        getTheText={this.getTheText}
        autocomplete={true}
        fomate={this.fomate}
        toolBarStyle={{margin: 4}}
        contentStyle={{ padding: 4, minHeight: 150 }}
        // 已废弃
        // content={this.state.content}
        getSkuData={this.getSkuData}
        pictureRecommend={this.pictureRecommend}
        uploadUrl={'/proxy/api/v1/upload/images'}
        cropImageUrl={'/proxy/api/v1/image/crop'}
        insertImageChange= {this.insertImageChange.bind(this)}
        onChange={this.handleChange.bind(this)} />
    }
}

const root = document.createElement("div");
document.body.appendChild(root);
ReactDOM.render(<Demo />, root)
1.1.219

4 years ago

1.1.218

4 years ago

1.1.217

4 years ago

1.1.216

4 years ago

1.1.215

4 years ago

1.1.214

4 years ago

1.1.213

4 years ago

1.1.212

4 years ago

1.1.211

4 years ago

1.1.210

4 years ago

1.1.209

4 years ago

1.1.208

4 years ago

1.1.207

4 years ago

1.1.206

4 years ago

1.1.205

4 years ago

1.1.204

4 years ago

1.1.203

4 years ago

1.1.202

4 years ago

1.1.201

4 years ago

1.1.200

4 years ago

1.1.199

4 years ago

1.1.198

4 years ago

1.1.197

4 years ago

1.1.196

4 years ago

1.1.195

4 years ago

1.1.194

4 years ago

1.1.193

4 years ago

1.1.192

4 years ago

1.1.191

4 years ago

1.1.189

4 years ago

1.1.190

4 years ago

1.1.188

4 years ago

1.1.187

4 years ago

1.1.186

4 years ago

1.1.185

4 years ago

1.1.184

4 years ago

1.1.183

4 years ago

1.1.182

4 years ago

1.1.181

4 years ago

1.1.180

4 years ago

1.1.179

4 years ago

1.1.178

4 years ago

1.1.177

4 years ago

1.1.176

4 years ago

1.1.175

4 years ago

1.1.174

4 years ago

1.1.173

4 years ago

1.1.172

4 years ago

1.1.171

4 years ago

1.1.170

4 years ago

1.1.169

4 years ago

1.1.168

4 years ago

1.1.167

4 years ago

1.1.166

4 years ago

1.1.164

4 years ago

1.1.163

4 years ago

1.1.162

4 years ago

1.1.161

4 years ago

1.1.160

4 years ago

1.1.159

4 years ago

1.1.158

5 years ago

1.1.157

5 years ago

1.1.156

5 years ago

1.1.155

5 years ago

1.1.154

5 years ago

1.1.153

5 years ago

1.1.152

5 years ago

1.1.151

5 years ago

1.1.150

5 years ago

1.1.149

5 years ago

1.1.148

5 years ago

1.1.147

5 years ago

1.1.146

5 years ago

1.1.145

5 years ago

1.1.144

5 years ago

1.1.143

5 years ago

1.1.142

5 years ago

1.1.141

5 years ago

1.1.140

5 years ago

1.1.139

5 years ago

1.1.138

5 years ago

1.1.137

5 years ago

1.1.136

5 years ago

1.1.135

5 years ago

1.1.134

5 years ago

1.1.133

5 years ago

1.1.131

5 years ago

1.1.130

5 years ago

1.1.129

5 years ago

1.1.128

5 years ago

1.1.127

5 years ago

1.1.126

5 years ago

1.1.125

5 years ago

1.1.124

5 years ago

1.1.123

5 years ago

1.1.122

5 years ago

1.1.121

5 years ago

1.1.120

5 years ago

1.1.119

5 years ago

1.1.118

5 years ago

1.1.117

5 years ago

1.1.116

5 years ago

1.1.115

5 years ago

1.1.114

5 years ago

1.1.113

5 years ago

1.1.112

5 years ago

1.1.111

5 years ago

1.1.110

5 years ago

1.1.109

5 years ago

1.1.108

5 years ago

1.1.107

5 years ago

1.1.106

5 years ago

1.1.105

5 years ago

1.1.104

5 years ago

1.1.103

5 years ago

1.1.102

5 years ago

1.1.101

5 years ago

1.1.100

5 years ago

1.1.99

5 years ago

1.1.98

5 years ago

1.1.97

5 years ago

1.1.96

5 years ago

1.1.95

5 years ago

1.1.94

5 years ago

1.1.93

5 years ago

1.1.92

5 years ago

1.1.88

5 years ago

1.1.87

5 years ago

1.1.86

5 years ago

1.1.85

5 years ago

1.1.84

5 years ago

1.1.83

5 years ago

1.1.82

5 years ago

1.1.81

5 years ago

1.1.80

5 years ago

1.1.79

5 years ago

1.1.78

5 years ago

1.1.77

5 years ago

1.1.76

5 years ago

1.1.75

5 years ago

1.1.74

5 years ago

1.1.73

5 years ago

1.1.72

5 years ago

1.1.71

5 years ago

1.1.70

5 years ago

1.1.69

5 years ago

1.1.68

5 years ago

1.1.67

5 years ago

1.1.66

5 years ago

1.1.65

5 years ago

1.1.64

5 years ago

1.1.63

5 years ago

1.1.62

5 years ago

1.1.61

5 years ago

1.1.60

5 years ago

1.1.59

5 years ago

1.1.58

5 years ago

1.1.57

5 years ago

1.1.56

5 years ago

1.1.55

5 years ago

1.1.54

5 years ago

1.1.53

5 years ago

1.1.52

5 years ago

1.1.51

5 years ago

1.1.50

5 years ago

1.1.49

5 years ago

1.1.48

5 years ago

1.1.47

5 years ago

1.1.46

5 years ago

1.1.45

5 years ago

1.1.44

5 years ago

1.1.43

5 years ago

1.1.42

5 years ago

1.1.41

5 years ago

1.1.40

5 years ago

1.1.39

5 years ago

1.1.38

5 years ago

1.1.37

5 years ago

1.1.36

5 years ago

1.1.35

5 years ago

1.1.34

5 years ago

1.1.33

5 years ago

1.1.32

5 years ago

1.1.31

5 years ago

1.1.30

5 years ago

1.1.29

5 years ago

1.1.28

5 years ago

1.1.26

5 years ago

1.1.25

5 years ago

1.1.24

5 years ago

1.1.23

5 years ago

1.1.22

5 years ago

1.1.21

5 years ago

1.1.20

5 years ago

1.1.19

5 years ago

1.1.18

5 years ago

1.1.17

5 years ago

1.1.16

5 years ago

1.1.15

5 years ago

1.1.14

5 years ago

1.1.13

5 years ago

1.1.12

5 years ago

1.1.11

5 years ago

1.1.10

5 years ago

1.1.9

5 years ago

1.1.8

5 years ago

1.1.7

5 years ago

1.1.6

5 years ago

1.1.5

5 years ago

1.1.4

5 years ago

1.1.3

5 years ago

1.1.2

5 years ago

1.1.1

5 years ago

1.1.0

6 years ago

1.0.26

6 years ago

1.0.25

6 years ago

1.0.24

6 years ago

1.0.23

6 years ago

1.0.22

6 years ago

1.0.21

6 years ago

1.0.20

6 years ago

1.0.19

6 years ago

1.0.18

6 years ago

1.0.17

6 years ago

1.0.16

6 years ago

1.0.15

6 years ago

1.0.14

6 years ago

1.0.13

6 years ago