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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@feat/feat-editor

v0.1.32

Published

在项目中引入时,可能需要添加alias,将第三方库引用的`draft-js`指向`@feat/draft-js`;  webpack配置示例:

Readme

NOTE:

在项目中引入时,可能需要添加alias,将第三方库引用的draft-js指向@feat/draft-js;  webpack配置示例:

// webpack.config.js
{
  // entry ...
  // plugins ...
  resolve: {
    alias: {
      'draft-js': '@feat/draft-js'
    }
  }
}

使用

Storybook: Feat Editor;

import React from 'react';
import { Editor, Toolbar, createFromRawData } from '@feat/feat-editor';

import 'draft-js/dist/Draft.css';
import '@feat/feat-editor/dist/FeatEditor.css';

const raw = {
    blocks: [{type: 'unstyled', text: 'Demo Content'}],
    entityMap: {}
}

class App extends Component {
  constructor(props) {
    super(props);
    this.state = {
      editorState: createFromRawData(raw),
    };
  }
  onChange = (editorState) => {
    this.setState({
      editorState,
    });
  }
  render() {
    return (
      <div className="demo">
        <Toolbar
          editorState={this.state.editorState}
          onChange={this.onChange}
        />
        <Editor
          placeholder="Title"
          editorState={this.state.editorState}
          onChange={this.onChange}
          />
      </div>
    )
  }
}

处理文件上传

设置 props uploadFiles, 激活处理上传功能,需要 uploadFiles 方法返回promise,resolve 的数据格式为: { url: 'path/to/image'}

Annotation

  1. 使用 Annotation 相关的handler
import React, { Component } from "react";
import PropTypes from "prop-types";
import Editor from "@feat/feat-editor/lib/components/Editor";
import handleBeforeCut from "@feat/feat-editor/lib/plugins/Annotation/handlers/handleBeforeCut";
import handleBeforeInput from "@feat/feat-editor/lib/plugins/Annotation/handlers/handleBeforeInput";
import handleKeyCommand from "@feat/feat-editor/lib/plugins/Annotation/handlers/handleKeyCommand";
import handlePastedText from "@feat/feat-editor/lib/plugins/Annotation/handlers/handlePastedText";
import handleReturn from
"@feat/feat-editor/lib/plugins/Annotation/handlers/handleReturn";
import handleToggleBlockType from
"@feat/feat-editor/lib/plugins/Annotation/handlers/handleToggleBlockType";
import handleToggleInlineStyle from
"@feat/feat-editor/lib/plugins/Annotation/handlers/handleToggleInlineStyle";

const AuditEditor = ({ userInfo, ...props }) => (
  <Editor
    {...props}
    handleBeforeCut={(...args) => handleBeforeCut(...args, userInfo)}
    handleBeforeInput={(...args) => handleBeforeInput(...args, userInfo)}
    handlePastedText={(...args) => handlePastedText(...args, userInfo)}
    handleKeyCommand={(...args) => handleKeyCommand(...args, userInfo)}
    handleReturn={(...args) => handleReturn(...args, userInfo)}
    handleToggleBlockType={(...args) => handleToggleBlockType(...args, userInfo)}
    handleToggleInlineStyle={(...args) => handleToggleInlineStyle(...args, userInfo)}
  />
);

AuditEditor.propTypes = {
  userInfo: PropTypes.shape({
    userId: PropTypes.oneOfType([PropTypes.string, PropTypes.number]),
    username: PropTypes.string
  }).isRequired
};

export default AuditEditor;
  1. 使用 Annotation 的配置导出 HTML
import stateToHTMLConfig from '@feat/feat-editor/lib/plugins/Annotation/helpers/stateToHTMLConfig';
import contentStateToHTML from '@feat/feat-editor/lib/helpers/contentStateToHTML';

const annotationHTML = (contentState) => contentStateToHTML(contentState, stateToHTMLConfig)
  1. 使用 Annotation 的配置生成
import stateFromHTMLConfig from '@feat/feat-editor/lib/plugins/Annotation/helpers/stateFromHTMLConfig';
import contentStateFromHTML from '@feat/feat-editor/lib/helpers/contentStateFromHTML';
import { EditorState } from "@feat/draft-js";

import MultiDecorator from '@feat/feat-editor/lib/libs/MultiDecorator';
import PrismDecorator from '@feat/feat-editor/lib/plugins/PrismDecorator';
import AnnotationDecorator from '@feat/feat-editor/lib/plugins/Annotation/AnnotationDecorator';

// decorator
const decorator = new MultiDecorator([
  new PrismDecorator(),
  new AnnotationDecorator(),
]);

// content state
const contentState = stateFromHTML(html, stateFromHTMLConfig);
const editorState = EditorState.createWithContent(contentState, decorator);

TODOs

  • [x] CodeBlock Syntax highlight
    • 需要自行引入 prismjs 样式
  • [x] Export HTML
    • [x] CodeBlock syntax data