Coder Social home page Coder Social logo

yaokailun / react-ueditor Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ifanrx/react-ueditor

1.0 2.0 0.0 9.07 MB

a ueditor component for react

License: MIT License

JavaScript 86.76% HTML 5.00% ASP 0.91% Java 1.02% PHP 2.13% CSS 3.33% Shell 0.01% Python 0.35% C# 0.47%

react-ueditor's Introduction

react-ueditor

react-ueditor

使用 react 框架对 ueditor 进行封装和扩展

✨ 特性

  • 支持更灵活的图片和音视频资源上传
  • 支持同个页面存在多个编辑器实例
  • 支持对复制进来的图片进行操作
  • 允许扩展工具栏,支持在扩展中使用已有的 react 组件

📦 下载

# 使用 npm 安装
npm install ifanrx-react-ueditor --save

# 使用 yarn 安装
yarn add ifanrx-react-ueditor

🔨 使用

import ReactUeditor from 'ifanrx-react-ueditor'

<ReactUeditor
  ueditorPath={`${window.YOUR_PATH}/ueditor`}"
/>

🔌 插件

extendControls 已不推荐使用,请直接使用 plugins,指定插件。

插件分为两种,一种是内置的插件,一种是自定义的插件。现支持内置插件如下:

  1. insertCode 插入代码块
  2. uploadImage 上传图片
  3. uploadVideo 上传视频
  4. uploadAudio 上传音频
  5. insertLink 添加链接

内置插件,直接传入插件的名称即可。自定义插件则是传入一个 Function,类型定义(使用 typescript 只为了说明类型)为:

interface IPlugin {
  (ueditor: UEditor): IPluginConfig
}

interface IPluginConfig {
  cssRules: String
  menuText: String
  onIconClick?: () => void
  render: (visible: Boolean, closeModal: () => void) => React.ReactElement<any>
  title?: String
}

UEditor 为 UEditor 实例。详细内容,请参考官方文档

插件使用示例

  1. 内置插件

    <ReactUeditor
      ...
      plugins={[
        'insertCode',
        'uploadImage',
        'uploadVideo',
        'uploadAudio',
        'insertLink',
      ]}
      ...
    />
  2. 自定义插件

    const uploadImagePlugin = ueditor => {
      return {
        menuText: '图片上传',
        cssRules: 'background-position: -726px -77px;',
        render: (visible, closeModal) => {
          const handleSelectImage = (url) => {
            ueditor.focus()
            ueditor.execCommand('inserthtml', `<img src="${url}" />`)
            closeModal()
          }
          return <Modal visible={visible} onSelectImage={handleSelectImage} />
        }
      }
    }
    
    <ReactUeditor
      ...
      plugins={[uploadImagePlugin]}
      ...
    />

更多功能请移步到 react-ueditor 的 wiki 页面

🤝 贡献


kailunyao

larry011

PRs Welcome

如果你希望为这个项目贡献代码,需要了解以下情况:

  • 在根目录下执行 yarn start 会启动开发服务器,此时会在浏览器中展示 ReactUeditor 的真实效果,在 ReactUeditor/ 下的修改都会进行热更新

  • example.js, index.html, dist/ 都只是为了展示 ReactUeditor 的真实效果,主要代码在 ReactUeditor/ 中

  • 需要修改 ueditor 源码时,直接修改 ueditor 目录下的文件,修改完执行:cd ueditoryarn grunt 命令,此时会重新生成 ueditor 构建成功的文件到 vendor/ueditor

react-ueditor's People

Contributors

arcturus011 avatar heshiyou avatar luckystar12 avatar yaokailun avatar zzzze avatar

Stargazers

 avatar

Watchers

 avatar  avatar

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.