Coder Social home page Coder Social logo

braft-utils's People

Contributors

bwencke avatar margox avatar tomision avatar v-zhzhou avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

braft-utils's Issues

antd-form+braft-editor+antd-upload一起使用,图片上传成功后无法正确在编辑器内显示

import 'braft-editor/dist/index.css'
import React, { PureComponent } from 'react'
import BraftEditor from 'braft-editor'
import { ContentUtils } from 'braft-utils'
import { ImageUtils } from 'braft-finder'
import { Divider, Button, Form, Input, Select, Spin, Upload, Icon, message, InputNumber } from 'antd'

const FormItem = Form.Item

@Form.create()
class Operate extends PureComponent {
  state = {
    controls: ['bold', 'italic', 'underline', 'text-color', 'fullscreen'],
    editorState: BraftEditor.createEditorState(null),
  }

  handleChange = (editorState) => {
    this.setState({ editorState })
  }

  uploadHandler = (param) => {

    if (!param.file) {
      return false
    }
    const { editorState } = this.state
    const url = 'https://zos.alipayobjects.com/rmsportal/jkjgkEfvpUPVyRjUImniVslZfWPnJuuZ.png'
    this.setState({
      editorState: ContentUtils.insertMedias(editorState, [{
        type: 'IMAGE',
        url: url,
      }]),
    })

  }

  render() {
    const { getFieldDecorator } = this.props.form
    const formItemLayout = { labelCol: { span: 5 }, wrapperCol: { span: 17 } }
    const extendControls = [
      {
        key: 'antd-uploader',
        type: 'component',
        component: (
          <Upload accept="image/*" showUploadList={false} customRequest={this.uploadHandler}>
            <button type="button" className="control-item button upload-button" data-title="插入图片">
              <Icon type="picture" theme="filled"/>
            </button>
          </Upload>
        ),
      },
    ]
    const { controls, editorState } = this.state
    return (
      <div style={{ width: '720px' }}>
        <Form onSubmit={this.handleSubmit}>
          <FormItem {...formItemLayout} label="操作说明">
            {getFieldDecorator('content', {
              initialValue: editorState,
              validateTrigger: 'onBlur',
              rules: [{
                required: true,
                validator: (_, value, callback) => {if (value.isEmpty()) {callback('请输入操作说明')} else {callback()}}, }],
            })(
              <BraftEditor
                style={{ border: '1px solid #e5e5e5', borderRadius: '3px' }}
                onChange={this.handleChange}
                onFullscreen={this.handleFullscreen}
                controls={controls}
                extendControls={extendControls}
              />,
            )}
          </FormItem>
        </Form>
      </div>
    )
  }
}

export default Operate

图片需要携带token

我这里在上传图片的时候,需要携带token才能拿到图片。

请问编辑器是否有中间方法,可以让我设置图片请求的token?
如果没有是否有必要加一个中间方法。

不通过控件controls去改变选区的大小颜色或者背景颜色怎么实现?

不通过控件controls去改变选区的大小颜色或者背景颜色怎么实现?

我获取的编辑器实例里面有一个方法是handleKeyCommand

可以通过
this.editorInstance.handleKeyCommand('bold',this.state.editorState)实现选择加粗

但是选择区域的字体大小或者添加背景色怎么去操作,希望作者可以解惑。

怎么不通过控件清除样式?

我的业务是:将复制粘贴过来的东西清除样式。通过以下方法ContentUtils.handleKeyCommand(this.state.editorState,'removeSelectionInlineStyles'),这样子没法清除。

inserHTML带样式

insertHTML这个方法可以带入自定义带样式或者class什么的嘛

如何清空内容,但保留设定的样式

如果通过ContentUtils.clear(this.state.editorState),或者clearEditorContent(),则设定的样式都恢复成默认的了,请教如何清空文字,但保留工具栏的样式设定?

toggleSelectionColor 如何使用?

 const editorState = BraftEditor.createEditorState(`<div>${props.value}</div` || '<div></div>');
    <BraftEditor
      ref={ref}
      controls={[]}
      extendControls={[
        {
          key: 'custom-button',
          type: 'button',
          text: '按钮',
          onClick: () => {
            console.log(editorState);
            const newEditorState = ContentUtils.toggleSelectionColor(editorState, '#f39c12');
            console.log(newEditorState.toHTML());
            // ref.current.refs.toggleSelectionColor('#ffffff')
            // ref.current?.handleKeyCommand('blob')
          },
        },
      ]}
```

通过ContentUtils 方法没办法进行颜色的修改,是调用的方式不对吗?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.