GithubHelp home page GithubHelp logo

kkfor / for-editor Goto Github PK

View Code? Open in Web Editor NEW
401.0 6.0 78.0 303 KB

for-editor - A markdown editor based on React

Home Page: https://md.kkfor.com/

License: MIT License

JavaScript 14.42% HTML 0.98% CSS 10.19% TypeScript 57.06% SCSS 17.35%
react markdown editor javascript markdown-editor component

for-editor's Introduction

for-editor

for-editor 是一个基于 react 的 markdown 语法编辑器

安装

npm install for-editor -S

使用

import React, { Component } from 'react'
import ReactDOM from 'react-dom'
import Editor from 'for-editor'

class App extends Component {
  constructor() {
    super()
    this.state = {
      value: ''
    }
  }

  handleChange(value) {
    this.setState({
      value
    })
  }

  render() {
    const { value } = this.state
    return <Editor value={value} onChange={() => this.handleChange()} />
  }
}

ReactDOM.render(<App />, document.getElementById('root'))

Api

属性

name type default description
value String - 输入框内容
placeholder String 开始编辑... 占位文本
lineNum Boolean true 是否显示行号
style Object - 编辑器样式
height String 600px 编辑器高度
preview Boolean false 预览模式
expand Boolean false 全屏模式
subfield Boolean false 双栏模式(预览模式激活下有效)
language String zh-CN 语言(支持 zh-CN:中文简体, en:英文)
toolbar Object 如下 自定义工具栏
/*
  默认工具栏按钮全部开启, 传入自定义对象
  例如: {
    h1: true, // h1
    code: true, // 代码块
    preview: true, // 预览
  }
  此时, 仅仅显示此三个功能键
  注:传入空对象则不显示工具栏
 */

toolbar: {
  h1: true, // h1
  h2: true, // h2
  h3: true, // h3
  h4: true, // h4
  img: true, // 图片
  link: true, // 链接
  code: true, // 代码块
  preview: true, // 预览
  expand: true, // 全屏
  /* v0.0.9 */
  undo: true, // 撤销
  redo: true, // 重做
  save: true, // 保存
  /* v0.2.3 */
  subfield: true, // 单双栏模式
}

事件

name params 参数 default description
onChange String: value - 内容改变时回调
onSave String: value - 保存时回调
addImg File: file - 添加图片时回调
图片上传
class App extends Component {
  constructor() {
    super()
    this.state = {
      value: '',
    }
    this.$vm = React.createRef()
  }

  handleChange(value) {
    this.setState({
      value
    })
  }

  addImg($file) {
    this.$vm.current.$img2Url($file.name, 'file_url')
    console.log($file)
  }

  render() {
    const { value } = this.state

    return (
      <Editor
        ref={this.$vm}
        value={value}
        addImg={($file) => this.addImg($file)}
        onChange={value => this.handleChange(value)}
      />
    )
  }
}

快捷键

name description
tab 两个空格缩进
ctrl+s 保存
ctrl+z 上一步
ctrl+y 下一步

更新

Licence

for-editor is MIT Licence.

for-editor's People

Contributors

2fps avatar dependabot[bot] avatar kkfor avatar luca-simonetti avatar luhaopeng 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  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  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

for-editor's Issues

onSave 方法在什么时候会执行?

按道理来讲,onSave 的回调只有我在按下ctrl+s的时候,才会触发,但实际上,我发现只要是 组件的状态发生变化,就回执行,如下图所示:

image

当我输入文章标题的时候,会不断的执行 onSave 中指定的回调,只要把 onSave 回调去除就正常了。

这是我自己代码有问题,还是有 BUG ?

使用TS,onChange的事件传入类型报错!

  1. React Hook + TS。onChange事件无法传入,会有类型报错,我的解决方法在下图。不知您这边是怎么处理的。
    img1
  2. 看了下源码,onChange事件是可选,所以会出现这个问题是不是因为打包的时候出了什么意外状况?
    img2

换行无效问题

image
如图输入回车无法正常换行
游览器采用 谷歌游览器 73.0.3683.75

Link title doesn't accept more than one word

Link title doesn't accept more than one word even between quotation marks.

Issue reproduction

image

Link para o artigo: [Quer Viajar para Argentina - Medium.com][1]

[1]: https://medium.com/bestamericas-travel/quer-viajar-para-argentina-a340ce764413 "Quer Viajar para Argentina"

Expected

Link para o artigo: Quer Viajar para Argentina - Medium.com

References

It should follow the most common Markdown guide lines:

组件unmount时报错

在组件被卸载时(例如路由),报如下错误
Uncaught TypeError: Cannot read property 'value' of null

暂时不敢用在生产环境

默认subfield模式不生效

感谢分享~

            <ForEditor
              height="300px"
              subfield={true}
              toolbar={{
                h1: true, // h1
                h2: true, // h2
                h3: true, // h3
                h4: true, // h4
                img: true, // 图片
                link: true, // 链接
                code: true, // 代码块
                undo: true, // 撤销
                redo: true, // 重做
                subfield: true,
              }}
            />

初始时,按钮显示已激活,但并没有开启;
取消后再次点击,恢复正常;

image

window is not defined

环境

node v10.15.0
npm v6.5.0
react ^16.7.0
next ^7.0.2

版本

0.0.11

问题

console打印window is not defined

console输出信息
      
ReferenceError: window is not defined
    at Object. (E:\WebstormProjects\personal-site\node_modules\for-editor\dist\index.js:1:286)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Module.require (internal/modules/cjs/loader.js:637:17)
    at require (internal/modules/cjs/helpers.js:22:18)
    at Object.for-editor (E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:879:18)
    at __webpack_require__ (E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:23:31)
    at Module../pages/manage.js (E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:466:68)
    at __webpack_require__ (E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:23:31)
    at Object.3 (E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:735:18)
    at __webpack_require__ (E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:23:31)
    at E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:91:18
    at Object. (E:\WebstormProjects\personal-site\.next\server\static\development\pages\manage.js:94:10)

可能的原因

dist/index.js是适合web环境而非node环境的代码,其中有window对象,而node环境中没有window对象

可能的解决方式

src/main.js发布到npm仓库,将dist/index.js发布到cdn

单双栏按钮和预览按钮状态问题

打开双栏后,toolbar上同时显示预览按钮处于激活状态,此时再点击预览按钮,编辑区域恢复到了单栏的状态,但是双栏按钮依然处于激活状态。

认为预览按钮和双栏按钮只能同一时间激活一个即可

为何要添加自己的样式?

我用marked解析,预览效果和editor里面完全不一样,然后我又去找editor的样式,居然是打包在js里面的这怎么办?只能放弃使用。不明白自己添加样式的意义何在?

双栏模式

有开关能控制双栏模式自动展开吗

失去焦点事件

可不可以加个失去焦点的事件啊,我想在用户写文档时,失去焦点后做自动保存功能。。目前要手动保存,有点不方便。谢谢。

请问如何添加自定义功能按钮

我们现在遇到一个需求,是需要在工具栏添加一个“发布”按钮,点击以后弹出一个“填写标题等信息”的提示框,填写完后才能发布。

现在这个发布组件已经开发好,那么现在需要在工具栏上怎么添加一个自定义按钮呢?
image

类似这种

dev branch is outdated

Hi @kkfor !
Please could you merge master branch into dev?
I'd like to contribute but seems like the dev branch is outdated.
Best regards!

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.