npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

wangeditor-for-react2

v1.5.8

Published

Wangeditor component for React.

Downloads

1

Readme

同wangeditor-for-react 只是把react的依赖版本降低

wangeditor-for-react

项目来源:wangEditor

安装

npm install wangeditor-for-react react

使用

事件监听

import ReactWEditor from 'wangeditor-for-react';

<ReactWEditor
  defaultValue={'<h1>标题</h1>'}
  linkImgCallback={(src,alt,href) => {
    // 插入网络图片的回调事件
    console.log('图片 src ', src)
    console.log('图片文字说明',alt)
    console.log('跳转链接',href)
  }}
  onlineVideoCallback={(video) => {
    // 插入网络视频的回调事件
    console.log('插入视频内容', video)
  }}
  onChange={(html) => {
    console.log('onChange html:', html)
  }}
  onBlur={(html) => {
    console.log('onBlur html:', html)
  }}
  onFocus={(html) => {
    console.log('onFocus html:', html)
  }}
/>

自定义配置

import ReactWEditor from 'wangeditor-for-react';

<ReactWEditor
  placeholder="自定义 placeholder"
  config={{
    fontSizes: {
      'x-small': { name: '10px', value: '1' },
      small: { name: '12px', value: '2' },
      normal: { name: '16px', value: '3' },
      large: { name: '18px', value: '4' },
      'x-large': { name: '24px', value: '5' },
      'xx-large': { name: '32px', value: '6' },
      'xxx-large': { name: '48px', value: '7' },
    },
  }}
/>

配置

使用 Ref

通过 Ref 获取所有 API

import React, { useRef } from 'react';
import ReactWEditor from 'wangeditor-for-react';

function App() {
  let editorRef = useRef(null)
  return (
    <ReactWEditor
      ref={editorRef}
      onBlur={(html) => {
        if (editorRef.current) {
          console.log('ref', editorRef.current.editor.txt.append('追加内容'))
        }
      }}
    />
  );
}

export default App;

常用 API

销毁编辑器

import React, { useRef } from 'react';
import ReactWEditor from 'wangeditor-for-react';

function App() {
  let editorRef = useRef(null)
  return (
    <>
    <ReactWEditor ref={editorRef} />
    <a href="#" onClick={() => editorRef.current.destroy()}>click</a>
    </>
  );
}

export default App;

多语言

首先需要安装语言包

npm i -S i18next

使用

import { extend } from 'wangeditor-for-react';
import i18next from 'i18next';

const ReactWEditorOfLang = extend({ i18next })

<ReactWEditorOfLang
  config={{
    lang: 'en',
  }}
/>

自定义语言

import { extend } from 'wangeditor-for-react';
import i18next from 'i18next';

const ReactWEditorOfLang = extend({ i18next })

<ReactWEditorOfLang
  config={{
    lang: 'japan',
  }}
  languages={{
    japan: {
      wangEditor: {
        请输入正文: '本文を入力してください',
      },
    }
  }}
/>

增加 hook

分为全局钩子 globalHook 和实例钩子 instanceHook

globalHook 注册在构造函数上,即 new E() 中的 EinstanceHook 注册在实例后,editor.create() 执行前。

钩子支持分割符,例如 menus.extend 相当于 this.editor.menus.extend

钩子有两种值,一种是数组,一种是函数。

<ReactWEditor
  instanceHook={{
    // 使用数组时,通常 key 代表的钩子是一个方法,此处 menus.extend 是个方法,那么数组就是其参数。
    'menus.extend': ['alertMenuKey', AlertMenu],
    // 使用方法是,通常 key 代表的钩子是一个对象,可以利用方法来绑定。方法的形参第一位是当前实例的 editor,后面依次是 key 分割代表的对象。
    'config.menus': function(editor, config, menus) {
      config.menus = menus.concat("alertMenuKey")
    }
  }}
/>

使用 globalHook 扩展菜单,AlertMenu 参考 Button 菜单

import React from 'react';
import ReactWEditor from 'wangeditor-for-react';
import AlertMenu from './AlertMenu';

function App() {
  return (
    <ReactWEditor
      globalHook={{
         registerMenu: ['alertMenuKey', AlertMenu]
      }}
    />
  );
}

export default App;

使用 instanceHook 扩展菜单。

import React from 'react';
import ReactWEditor from 'wangeditor-for-react';
import AlertMenu from './AlertMenu';

function App() {
  return (
    <ReactWEditor
      instanceHook={{
        'menus.extend': ['alertMenuKey', AlertMenu],
        'config.menus': function(editor, config, menus) {
          config.menus = menus.concat("alertMenuKey")
        }
      }}
    />
  );
}

export default App;

TODO